1 // SPDX-License-Identifier: GPL-2.0-only
3 * Generic DSI Command Mode panel driver
5 * Copyright (C) 2013 Texas Instruments
6 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
11 #include <linux/backlight.h>
12 #include <linux/delay.h>
13 #include <linux/err.h>
15 #include <linux/gpio/consumer.h>
16 #include <linux/interrupt.h>
17 #include <linux/jiffies.h>
18 #include <linux/mod_devicetable.h>
19 #include <linux/module.h>
20 #include <linux/platform_device.h>
21 #include <linux/sched/signal.h>
22 #include <linux/slab.h>
23 #include <linux/workqueue.h>
25 #include <video/omapfb_dss.h>
26 #include <video/mipi_display.h>
28 /* DSI Virtual channel. Hardcoded for now. */
31 #define DCS_READ_NUM_ERRORS 0x05
32 #define DCS_BRIGHTNESS 0x51
33 #define DCS_CTRL_DISPLAY 0x53
34 #define DCS_GET_ID1 0xda
35 #define DCS_GET_ID2 0xdb
36 #define DCS_GET_ID3 0xdc
38 struct panel_drv_data
{
39 struct omap_dss_device dssdev
;
40 struct omap_dss_device
*in
;
42 struct omap_video_timings timings
;
44 struct platform_device
*pdev
;
48 struct backlight_device
*bldev
;
50 unsigned long hw_guard_end
; /* next value of jiffies when we can
51 * issue the next sleep in/out command
53 unsigned long hw_guard_wait
; /* max guard time in jiffies */
55 /* panel HW configuration from DT or platform data */
56 struct gpio_desc
*reset_gpio
;
57 struct gpio_desc
*ext_te_gpio
;
59 bool use_dsi_backlight
;
61 struct omap_dsi_pin_config pin_config
;
63 /* runtime variables */
71 struct delayed_work te_timeout_work
;
76 unsigned ulps_timeout
;
77 struct delayed_work ulps_work
;
80 #define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
82 static irqreturn_t
dsicm_te_isr(int irq
, void *data
);
83 static void dsicm_te_timeout_work_callback(struct work_struct
*work
);
84 static int _dsicm_enable_te(struct panel_drv_data
*ddata
, bool enable
);
86 static int dsicm_panel_reset(struct panel_drv_data
*ddata
);
88 static void dsicm_ulps_work(struct work_struct
*work
);
90 static void hw_guard_start(struct panel_drv_data
*ddata
, int guard_msec
)
92 ddata
->hw_guard_wait
= msecs_to_jiffies(guard_msec
);
93 ddata
->hw_guard_end
= jiffies
+ ddata
->hw_guard_wait
;
96 static void hw_guard_wait(struct panel_drv_data
*ddata
)
98 unsigned long wait
= ddata
->hw_guard_end
- jiffies
;
100 if ((long)wait
> 0 && time_before_eq(wait
, ddata
->hw_guard_wait
)) {
101 set_current_state(TASK_UNINTERRUPTIBLE
);
102 schedule_timeout(wait
);
106 static int dsicm_dcs_read_1(struct panel_drv_data
*ddata
, u8 dcs_cmd
, u8
*data
)
108 struct omap_dss_device
*in
= ddata
->in
;
112 r
= in
->ops
.dsi
->dcs_read(in
, ddata
->channel
, dcs_cmd
, buf
, 1);
122 static int dsicm_dcs_write_0(struct panel_drv_data
*ddata
, u8 dcs_cmd
)
124 struct omap_dss_device
*in
= ddata
->in
;
125 return in
->ops
.dsi
->dcs_write(in
, ddata
->channel
, &dcs_cmd
, 1);
128 static int dsicm_dcs_write_1(struct panel_drv_data
*ddata
, u8 dcs_cmd
, u8 param
)
130 struct omap_dss_device
*in
= ddata
->in
;
131 u8 buf
[2] = { dcs_cmd
, param
};
133 return in
->ops
.dsi
->dcs_write(in
, ddata
->channel
, buf
, 2);
136 static int dsicm_sleep_in(struct panel_drv_data
*ddata
)
139 struct omap_dss_device
*in
= ddata
->in
;
143 hw_guard_wait(ddata
);
145 cmd
= MIPI_DCS_ENTER_SLEEP_MODE
;
146 r
= in
->ops
.dsi
->dcs_write_nosync(in
, ddata
->channel
, &cmd
, 1);
150 hw_guard_start(ddata
, 120);
152 usleep_range(5000, 10000);
157 static int dsicm_sleep_out(struct panel_drv_data
*ddata
)
161 hw_guard_wait(ddata
);
163 r
= dsicm_dcs_write_0(ddata
, MIPI_DCS_EXIT_SLEEP_MODE
);
167 hw_guard_start(ddata
, 120);
169 usleep_range(5000, 10000);
174 static int dsicm_get_id(struct panel_drv_data
*ddata
, u8
*id1
, u8
*id2
, u8
*id3
)
178 r
= dsicm_dcs_read_1(ddata
, DCS_GET_ID1
, id1
);
181 r
= dsicm_dcs_read_1(ddata
, DCS_GET_ID2
, id2
);
184 r
= dsicm_dcs_read_1(ddata
, DCS_GET_ID3
, id3
);
191 static int dsicm_set_update_window(struct panel_drv_data
*ddata
,
192 u16 x
, u16 y
, u16 w
, u16 h
)
194 struct omap_dss_device
*in
= ddata
->in
;
202 buf
[0] = MIPI_DCS_SET_COLUMN_ADDRESS
;
203 buf
[1] = (x1
>> 8) & 0xff;
204 buf
[2] = (x1
>> 0) & 0xff;
205 buf
[3] = (x2
>> 8) & 0xff;
206 buf
[4] = (x2
>> 0) & 0xff;
208 r
= in
->ops
.dsi
->dcs_write_nosync(in
, ddata
->channel
, buf
, sizeof(buf
));
212 buf
[0] = MIPI_DCS_SET_PAGE_ADDRESS
;
213 buf
[1] = (y1
>> 8) & 0xff;
214 buf
[2] = (y1
>> 0) & 0xff;
215 buf
[3] = (y2
>> 8) & 0xff;
216 buf
[4] = (y2
>> 0) & 0xff;
218 r
= in
->ops
.dsi
->dcs_write_nosync(in
, ddata
->channel
, buf
, sizeof(buf
));
222 in
->ops
.dsi
->bta_sync(in
, ddata
->channel
);
227 static void dsicm_queue_ulps_work(struct panel_drv_data
*ddata
)
229 if (ddata
->ulps_timeout
> 0)
230 schedule_delayed_work(&ddata
->ulps_work
,
231 msecs_to_jiffies(ddata
->ulps_timeout
));
234 static void dsicm_cancel_ulps_work(struct panel_drv_data
*ddata
)
236 cancel_delayed_work(&ddata
->ulps_work
);
239 static int dsicm_enter_ulps(struct panel_drv_data
*ddata
)
241 struct omap_dss_device
*in
= ddata
->in
;
244 if (ddata
->ulps_enabled
)
247 dsicm_cancel_ulps_work(ddata
);
249 r
= _dsicm_enable_te(ddata
, false);
253 if (ddata
->ext_te_gpio
)
254 disable_irq(gpiod_to_irq(ddata
->ext_te_gpio
));
256 in
->ops
.dsi
->disable(in
, false, true);
258 ddata
->ulps_enabled
= true;
263 dev_err(&ddata
->pdev
->dev
, "enter ULPS failed");
264 dsicm_panel_reset(ddata
);
266 ddata
->ulps_enabled
= false;
268 dsicm_queue_ulps_work(ddata
);
273 static int dsicm_exit_ulps(struct panel_drv_data
*ddata
)
275 struct omap_dss_device
*in
= ddata
->in
;
278 if (!ddata
->ulps_enabled
)
281 r
= in
->ops
.dsi
->enable(in
);
283 dev_err(&ddata
->pdev
->dev
, "failed to enable DSI\n");
287 in
->ops
.dsi
->enable_hs(in
, ddata
->channel
, true);
289 r
= _dsicm_enable_te(ddata
, true);
291 dev_err(&ddata
->pdev
->dev
, "failed to re-enable TE");
295 if (ddata
->ext_te_gpio
)
296 enable_irq(gpiod_to_irq(ddata
->ext_te_gpio
));
298 dsicm_queue_ulps_work(ddata
);
300 ddata
->ulps_enabled
= false;
305 dev_err(&ddata
->pdev
->dev
, "failed to exit ULPS");
307 r
= dsicm_panel_reset(ddata
);
309 if (ddata
->ext_te_gpio
)
310 enable_irq(gpiod_to_irq(ddata
->ext_te_gpio
));
311 ddata
->ulps_enabled
= false;
314 dsicm_queue_ulps_work(ddata
);
319 static int dsicm_wake_up(struct panel_drv_data
*ddata
)
321 if (ddata
->ulps_enabled
)
322 return dsicm_exit_ulps(ddata
);
324 dsicm_cancel_ulps_work(ddata
);
325 dsicm_queue_ulps_work(ddata
);
329 static int dsicm_bl_update_status(struct backlight_device
*dev
)
331 struct panel_drv_data
*ddata
= dev_get_drvdata(&dev
->dev
);
332 struct omap_dss_device
*in
= ddata
->in
;
334 int level
= backlight_get_brightness(dev
);
336 dev_dbg(&ddata
->pdev
->dev
, "update brightness to %d\n", level
);
338 mutex_lock(&ddata
->lock
);
340 if (ddata
->enabled
) {
341 in
->ops
.dsi
->bus_lock(in
);
343 r
= dsicm_wake_up(ddata
);
345 r
= dsicm_dcs_write_1(ddata
, DCS_BRIGHTNESS
, level
);
347 in
->ops
.dsi
->bus_unlock(in
);
352 mutex_unlock(&ddata
->lock
);
357 static int dsicm_bl_get_intensity(struct backlight_device
*dev
)
359 if (dev
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
360 dev
->props
.power
== FB_BLANK_UNBLANK
)
361 return dev
->props
.brightness
;
366 static const struct backlight_ops dsicm_bl_ops
= {
367 .get_brightness
= dsicm_bl_get_intensity
,
368 .update_status
= dsicm_bl_update_status
,
371 static void dsicm_get_resolution(struct omap_dss_device
*dssdev
,
372 u16
*xres
, u16
*yres
)
374 *xres
= dssdev
->panel
.timings
.x_res
;
375 *yres
= dssdev
->panel
.timings
.y_res
;
378 static ssize_t
dsicm_num_errors_show(struct device
*dev
,
379 struct device_attribute
*attr
, char *buf
)
381 struct panel_drv_data
*ddata
= dev_get_drvdata(dev
);
382 struct omap_dss_device
*in
= ddata
->in
;
386 mutex_lock(&ddata
->lock
);
388 if (ddata
->enabled
) {
389 in
->ops
.dsi
->bus_lock(in
);
391 r
= dsicm_wake_up(ddata
);
393 r
= dsicm_dcs_read_1(ddata
, DCS_READ_NUM_ERRORS
,
396 in
->ops
.dsi
->bus_unlock(in
);
401 mutex_unlock(&ddata
->lock
);
406 return sysfs_emit(buf
, "%d\n", errors
);
409 static ssize_t
dsicm_hw_revision_show(struct device
*dev
,
410 struct device_attribute
*attr
, char *buf
)
412 struct panel_drv_data
*ddata
= dev_get_drvdata(dev
);
413 struct omap_dss_device
*in
= ddata
->in
;
417 mutex_lock(&ddata
->lock
);
419 if (ddata
->enabled
) {
420 in
->ops
.dsi
->bus_lock(in
);
422 r
= dsicm_wake_up(ddata
);
424 r
= dsicm_get_id(ddata
, &id1
, &id2
, &id3
);
426 in
->ops
.dsi
->bus_unlock(in
);
431 mutex_unlock(&ddata
->lock
);
436 return sysfs_emit(buf
, "%02x.%02x.%02x\n", id1
, id2
, id3
);
439 static ssize_t
dsicm_store_ulps(struct device
*dev
,
440 struct device_attribute
*attr
,
441 const char *buf
, size_t count
)
443 struct panel_drv_data
*ddata
= dev_get_drvdata(dev
);
444 struct omap_dss_device
*in
= ddata
->in
;
448 r
= kstrtoul(buf
, 0, &t
);
452 mutex_lock(&ddata
->lock
);
454 if (ddata
->enabled
) {
455 in
->ops
.dsi
->bus_lock(in
);
458 r
= dsicm_enter_ulps(ddata
);
460 r
= dsicm_wake_up(ddata
);
462 in
->ops
.dsi
->bus_unlock(in
);
465 mutex_unlock(&ddata
->lock
);
473 static ssize_t
dsicm_show_ulps(struct device
*dev
,
474 struct device_attribute
*attr
,
477 struct panel_drv_data
*ddata
= dev_get_drvdata(dev
);
480 mutex_lock(&ddata
->lock
);
481 t
= ddata
->ulps_enabled
;
482 mutex_unlock(&ddata
->lock
);
484 return sysfs_emit(buf
, "%u\n", t
);
487 static ssize_t
dsicm_store_ulps_timeout(struct device
*dev
,
488 struct device_attribute
*attr
,
489 const char *buf
, size_t count
)
491 struct panel_drv_data
*ddata
= dev_get_drvdata(dev
);
492 struct omap_dss_device
*in
= ddata
->in
;
496 r
= kstrtoul(buf
, 0, &t
);
500 mutex_lock(&ddata
->lock
);
501 ddata
->ulps_timeout
= t
;
503 if (ddata
->enabled
) {
504 /* dsicm_wake_up will restart the timer */
505 in
->ops
.dsi
->bus_lock(in
);
506 r
= dsicm_wake_up(ddata
);
507 in
->ops
.dsi
->bus_unlock(in
);
510 mutex_unlock(&ddata
->lock
);
518 static ssize_t
dsicm_show_ulps_timeout(struct device
*dev
,
519 struct device_attribute
*attr
,
522 struct panel_drv_data
*ddata
= dev_get_drvdata(dev
);
525 mutex_lock(&ddata
->lock
);
526 t
= ddata
->ulps_timeout
;
527 mutex_unlock(&ddata
->lock
);
529 return sysfs_emit(buf
, "%u\n", t
);
532 static DEVICE_ATTR(num_dsi_errors
, S_IRUGO
, dsicm_num_errors_show
, NULL
);
533 static DEVICE_ATTR(hw_revision
, S_IRUGO
, dsicm_hw_revision_show
, NULL
);
534 static DEVICE_ATTR(ulps
, S_IRUGO
| S_IWUSR
,
535 dsicm_show_ulps
, dsicm_store_ulps
);
536 static DEVICE_ATTR(ulps_timeout
, S_IRUGO
| S_IWUSR
,
537 dsicm_show_ulps_timeout
, dsicm_store_ulps_timeout
);
539 static struct attribute
*dsicm_attrs
[] = {
540 &dev_attr_num_dsi_errors
.attr
,
541 &dev_attr_hw_revision
.attr
,
543 &dev_attr_ulps_timeout
.attr
,
547 static const struct attribute_group dsicm_attr_group
= {
548 .attrs
= dsicm_attrs
,
551 static void dsicm_hw_reset(struct panel_drv_data
*ddata
)
554 * Note that we appear to activate the reset line here. However
555 * existing DTSes specified incorrect polarity for it (active high),
556 * so in fact this deasserts the reset line.
558 gpiod_set_value_cansleep(ddata
->reset_gpio
, 1);
560 /* reset the panel */
561 gpiod_set_value_cansleep(ddata
->reset_gpio
, 0);
562 /* keep reset asserted */
564 /* release reset line */
565 gpiod_set_value_cansleep(ddata
->reset_gpio
, 1);
566 /* wait after releasing reset */
567 usleep_range(5000, 10000);
570 static int dsicm_power_on(struct panel_drv_data
*ddata
)
572 struct omap_dss_device
*in
= ddata
->in
;
575 struct omap_dss_dsi_config dsi_config
= {
576 .mode
= OMAP_DSS_DSI_CMD_MODE
,
577 .pixel_format
= OMAP_DSS_DSI_FMT_RGB888
,
578 .timings
= &ddata
->timings
,
579 .hs_clk_min
= 150000000,
580 .hs_clk_max
= 300000000,
581 .lp_clk_min
= 7000000,
582 .lp_clk_max
= 10000000,
585 if (ddata
->pin_config
.num_pins
> 0) {
586 r
= in
->ops
.dsi
->configure_pins(in
, &ddata
->pin_config
);
588 dev_err(&ddata
->pdev
->dev
,
589 "failed to configure DSI pins\n");
594 r
= in
->ops
.dsi
->set_config(in
, &dsi_config
);
596 dev_err(&ddata
->pdev
->dev
, "failed to configure DSI\n");
600 r
= in
->ops
.dsi
->enable(in
);
602 dev_err(&ddata
->pdev
->dev
, "failed to enable DSI\n");
606 dsicm_hw_reset(ddata
);
608 in
->ops
.dsi
->enable_hs(in
, ddata
->channel
, false);
610 r
= dsicm_sleep_out(ddata
);
614 r
= dsicm_get_id(ddata
, &id1
, &id2
, &id3
);
618 r
= dsicm_dcs_write_1(ddata
, DCS_BRIGHTNESS
, 0xff);
622 r
= dsicm_dcs_write_1(ddata
, DCS_CTRL_DISPLAY
,
623 (1<<2) | (1<<5)); /* BL | BCTRL */
627 r
= dsicm_dcs_write_1(ddata
, MIPI_DCS_SET_PIXEL_FORMAT
,
628 MIPI_DCS_PIXEL_FMT_24BIT
);
632 r
= dsicm_dcs_write_0(ddata
, MIPI_DCS_SET_DISPLAY_ON
);
636 r
= _dsicm_enable_te(ddata
, ddata
->te_enabled
);
640 r
= in
->ops
.dsi
->enable_video_output(in
, ddata
->channel
);
646 if (!ddata
->intro_printed
) {
647 dev_info(&ddata
->pdev
->dev
, "panel revision %02x.%02x.%02x\n",
649 ddata
->intro_printed
= true;
652 in
->ops
.dsi
->enable_hs(in
, ddata
->channel
, true);
656 dev_err(&ddata
->pdev
->dev
, "error while enabling panel, issuing HW reset\n");
658 dsicm_hw_reset(ddata
);
660 in
->ops
.dsi
->disable(in
, true, false);
665 static void dsicm_power_off(struct panel_drv_data
*ddata
)
667 struct omap_dss_device
*in
= ddata
->in
;
670 in
->ops
.dsi
->disable_video_output(in
, ddata
->channel
);
672 r
= dsicm_dcs_write_0(ddata
, MIPI_DCS_SET_DISPLAY_OFF
);
674 r
= dsicm_sleep_in(ddata
);
677 dev_err(&ddata
->pdev
->dev
,
678 "error disabling panel, issuing HW reset\n");
679 dsicm_hw_reset(ddata
);
682 in
->ops
.dsi
->disable(in
, true, false);
687 static int dsicm_panel_reset(struct panel_drv_data
*ddata
)
689 dev_err(&ddata
->pdev
->dev
, "performing LCD reset\n");
691 dsicm_power_off(ddata
);
692 dsicm_hw_reset(ddata
);
693 return dsicm_power_on(ddata
);
696 static int dsicm_connect(struct omap_dss_device
*dssdev
)
698 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
699 struct omap_dss_device
*in
= ddata
->in
;
700 struct device
*dev
= &ddata
->pdev
->dev
;
703 if (omapdss_device_is_connected(dssdev
))
706 r
= in
->ops
.dsi
->connect(in
, dssdev
);
708 dev_err(dev
, "Failed to connect to video source\n");
712 r
= in
->ops
.dsi
->request_vc(ddata
->in
, &ddata
->channel
);
714 dev_err(dev
, "failed to get virtual channel\n");
718 r
= in
->ops
.dsi
->set_vc_id(ddata
->in
, ddata
->channel
, TCH
);
720 dev_err(dev
, "failed to set VC_ID\n");
727 in
->ops
.dsi
->release_vc(ddata
->in
, ddata
->channel
);
729 in
->ops
.dsi
->disconnect(in
, dssdev
);
733 static void dsicm_disconnect(struct omap_dss_device
*dssdev
)
735 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
736 struct omap_dss_device
*in
= ddata
->in
;
738 if (!omapdss_device_is_connected(dssdev
))
741 in
->ops
.dsi
->release_vc(in
, ddata
->channel
);
742 in
->ops
.dsi
->disconnect(in
, dssdev
);
745 static int dsicm_enable(struct omap_dss_device
*dssdev
)
747 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
748 struct omap_dss_device
*in
= ddata
->in
;
751 dev_dbg(&ddata
->pdev
->dev
, "enable\n");
753 mutex_lock(&ddata
->lock
);
755 if (!omapdss_device_is_connected(dssdev
)) {
760 if (omapdss_device_is_enabled(dssdev
)) {
765 in
->ops
.dsi
->bus_lock(in
);
767 r
= dsicm_power_on(ddata
);
769 in
->ops
.dsi
->bus_unlock(in
);
774 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
776 mutex_unlock(&ddata
->lock
);
780 dev_dbg(&ddata
->pdev
->dev
, "enable failed\n");
781 mutex_unlock(&ddata
->lock
);
785 static void dsicm_disable(struct omap_dss_device
*dssdev
)
787 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
788 struct omap_dss_device
*in
= ddata
->in
;
791 dev_dbg(&ddata
->pdev
->dev
, "disable\n");
793 mutex_lock(&ddata
->lock
);
795 dsicm_cancel_ulps_work(ddata
);
797 in
->ops
.dsi
->bus_lock(in
);
799 if (omapdss_device_is_enabled(dssdev
)) {
800 r
= dsicm_wake_up(ddata
);
802 dsicm_power_off(ddata
);
805 in
->ops
.dsi
->bus_unlock(in
);
807 dssdev
->state
= OMAP_DSS_DISPLAY_DISABLED
;
809 mutex_unlock(&ddata
->lock
);
812 static void dsicm_framedone_cb(int err
, void *data
)
814 struct panel_drv_data
*ddata
= data
;
815 struct omap_dss_device
*in
= ddata
->in
;
817 dev_dbg(&ddata
->pdev
->dev
, "framedone, err %d\n", err
);
818 in
->ops
.dsi
->bus_unlock(ddata
->in
);
821 static irqreturn_t
dsicm_te_isr(int irq
, void *data
)
823 struct panel_drv_data
*ddata
= data
;
824 struct omap_dss_device
*in
= ddata
->in
;
828 old
= atomic_cmpxchg(&ddata
->do_update
, 1, 0);
831 cancel_delayed_work(&ddata
->te_timeout_work
);
833 r
= in
->ops
.dsi
->update(in
, ddata
->channel
, dsicm_framedone_cb
,
841 dev_err(&ddata
->pdev
->dev
, "start update failed\n");
842 in
->ops
.dsi
->bus_unlock(in
);
846 static void dsicm_te_timeout_work_callback(struct work_struct
*work
)
848 struct panel_drv_data
*ddata
= container_of(work
, struct panel_drv_data
,
849 te_timeout_work
.work
);
850 struct omap_dss_device
*in
= ddata
->in
;
852 dev_err(&ddata
->pdev
->dev
, "TE not received for 250ms!\n");
854 atomic_set(&ddata
->do_update
, 0);
855 in
->ops
.dsi
->bus_unlock(in
);
858 static int dsicm_update(struct omap_dss_device
*dssdev
,
859 u16 x
, u16 y
, u16 w
, u16 h
)
861 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
862 struct omap_dss_device
*in
= ddata
->in
;
865 dev_dbg(&ddata
->pdev
->dev
, "update %d, %d, %d x %d\n", x
, y
, w
, h
);
867 mutex_lock(&ddata
->lock
);
868 in
->ops
.dsi
->bus_lock(in
);
870 r
= dsicm_wake_up(ddata
);
874 if (!ddata
->enabled
) {
879 /* XXX no need to send this every frame, but dsi break if not done */
880 r
= dsicm_set_update_window(ddata
, 0, 0,
881 dssdev
->panel
.timings
.x_res
,
882 dssdev
->panel
.timings
.y_res
);
886 if (ddata
->te_enabled
&& ddata
->ext_te_gpio
) {
887 schedule_delayed_work(&ddata
->te_timeout_work
,
888 msecs_to_jiffies(250));
889 atomic_set(&ddata
->do_update
, 1);
891 r
= in
->ops
.dsi
->update(in
, ddata
->channel
, dsicm_framedone_cb
,
897 /* note: no bus_unlock here. unlock is in framedone_cb */
898 mutex_unlock(&ddata
->lock
);
901 in
->ops
.dsi
->bus_unlock(in
);
902 mutex_unlock(&ddata
->lock
);
906 static int dsicm_sync(struct omap_dss_device
*dssdev
)
908 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
909 struct omap_dss_device
*in
= ddata
->in
;
911 dev_dbg(&ddata
->pdev
->dev
, "sync\n");
913 mutex_lock(&ddata
->lock
);
914 in
->ops
.dsi
->bus_lock(in
);
915 in
->ops
.dsi
->bus_unlock(in
);
916 mutex_unlock(&ddata
->lock
);
918 dev_dbg(&ddata
->pdev
->dev
, "sync done\n");
923 static int _dsicm_enable_te(struct panel_drv_data
*ddata
, bool enable
)
925 struct omap_dss_device
*in
= ddata
->in
;
929 r
= dsicm_dcs_write_1(ddata
, MIPI_DCS_SET_TEAR_ON
, 0);
931 r
= dsicm_dcs_write_0(ddata
, MIPI_DCS_SET_TEAR_OFF
);
933 if (!ddata
->ext_te_gpio
)
934 in
->ops
.dsi
->enable_te(in
, enable
);
936 /* possible panel bug */
942 static int dsicm_enable_te(struct omap_dss_device
*dssdev
, bool enable
)
944 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
945 struct omap_dss_device
*in
= ddata
->in
;
948 mutex_lock(&ddata
->lock
);
950 if (ddata
->te_enabled
== enable
)
953 in
->ops
.dsi
->bus_lock(in
);
955 if (ddata
->enabled
) {
956 r
= dsicm_wake_up(ddata
);
960 r
= _dsicm_enable_te(ddata
, enable
);
965 ddata
->te_enabled
= enable
;
967 in
->ops
.dsi
->bus_unlock(in
);
969 mutex_unlock(&ddata
->lock
);
973 in
->ops
.dsi
->bus_unlock(in
);
974 mutex_unlock(&ddata
->lock
);
979 static int dsicm_get_te(struct omap_dss_device
*dssdev
)
981 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
984 mutex_lock(&ddata
->lock
);
985 r
= ddata
->te_enabled
;
986 mutex_unlock(&ddata
->lock
);
991 static int dsicm_memory_read(struct omap_dss_device
*dssdev
,
992 void *buf
, size_t size
,
993 u16 x
, u16 y
, u16 w
, u16 h
)
995 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
996 struct omap_dss_device
*in
= ddata
->in
;
1000 unsigned buf_used
= 0;
1002 if (size
< w
* h
* 3)
1005 mutex_lock(&ddata
->lock
);
1007 if (!ddata
->enabled
) {
1012 size
= min(w
* h
* 3,
1013 dssdev
->panel
.timings
.x_res
*
1014 dssdev
->panel
.timings
.y_res
* 3);
1016 in
->ops
.dsi
->bus_lock(in
);
1018 r
= dsicm_wake_up(ddata
);
1022 /* plen 1 or 2 goes into short packet. until checksum error is fixed,
1023 * use short packets. plen 32 works, but bigger packets seem to cause
1030 dsicm_set_update_window(ddata
, x
, y
, w
, h
);
1032 r
= in
->ops
.dsi
->set_max_rx_packet_size(in
, ddata
->channel
, plen
);
1036 while (buf_used
< size
) {
1037 u8 dcs_cmd
= first
? 0x2e : 0x3e;
1040 r
= in
->ops
.dsi
->dcs_read(in
, ddata
->channel
, dcs_cmd
,
1041 buf
+ buf_used
, size
- buf_used
);
1044 dev_err(dssdev
->dev
, "read error\n");
1051 dev_err(&ddata
->pdev
->dev
, "short read\n");
1055 if (signal_pending(current
)) {
1056 dev_err(&ddata
->pdev
->dev
, "signal pending, "
1057 "aborting memory read\n");
1066 in
->ops
.dsi
->set_max_rx_packet_size(in
, ddata
->channel
, 1);
1068 in
->ops
.dsi
->bus_unlock(in
);
1070 mutex_unlock(&ddata
->lock
);
1074 static void dsicm_ulps_work(struct work_struct
*work
)
1076 struct panel_drv_data
*ddata
= container_of(work
, struct panel_drv_data
,
1078 struct omap_dss_device
*dssdev
= &ddata
->dssdev
;
1079 struct omap_dss_device
*in
= ddata
->in
;
1081 mutex_lock(&ddata
->lock
);
1083 if (dssdev
->state
!= OMAP_DSS_DISPLAY_ACTIVE
|| !ddata
->enabled
) {
1084 mutex_unlock(&ddata
->lock
);
1088 in
->ops
.dsi
->bus_lock(in
);
1090 dsicm_enter_ulps(ddata
);
1092 in
->ops
.dsi
->bus_unlock(in
);
1093 mutex_unlock(&ddata
->lock
);
1096 static struct omap_dss_driver dsicm_ops
= {
1097 .connect
= dsicm_connect
,
1098 .disconnect
= dsicm_disconnect
,
1100 .enable
= dsicm_enable
,
1101 .disable
= dsicm_disable
,
1103 .update
= dsicm_update
,
1106 .get_resolution
= dsicm_get_resolution
,
1107 .get_recommended_bpp
= omapdss_default_get_recommended_bpp
,
1109 .enable_te
= dsicm_enable_te
,
1110 .get_te
= dsicm_get_te
,
1112 .memory_read
= dsicm_memory_read
,
1115 static int dsicm_probe(struct platform_device
*pdev
)
1117 struct backlight_properties props
;
1118 struct panel_drv_data
*ddata
;
1119 struct backlight_device
*bldev
= NULL
;
1120 struct device
*dev
= &pdev
->dev
;
1121 struct omap_dss_device
*dssdev
;
1124 dev_dbg(dev
, "probe\n");
1126 if (!pdev
->dev
.of_node
)
1129 ddata
= devm_kzalloc(dev
, sizeof(*ddata
), GFP_KERNEL
);
1133 platform_set_drvdata(pdev
, ddata
);
1136 ddata
->in
= omapdss_of_find_source_for_first_ep(pdev
->dev
.of_node
);
1137 r
= PTR_ERR_OR_ZERO(ddata
->in
);
1139 dev_err(&pdev
->dev
, "failed to find video source: %d\n", r
);
1143 ddata
->timings
.x_res
= 864;
1144 ddata
->timings
.y_res
= 480;
1145 ddata
->timings
.pixelclock
= 864 * 480 * 60;
1147 dssdev
= &ddata
->dssdev
;
1149 dssdev
->driver
= &dsicm_ops
;
1150 dssdev
->panel
.timings
= ddata
->timings
;
1151 dssdev
->type
= OMAP_DISPLAY_TYPE_DSI
;
1152 dssdev
->owner
= THIS_MODULE
;
1154 dssdev
->panel
.dsi_pix_fmt
= OMAP_DSS_DSI_FMT_RGB888
;
1155 dssdev
->caps
= OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE
|
1156 OMAP_DSS_DISPLAY_CAP_TEAR_ELIM
;
1158 r
= omapdss_register_display(dssdev
);
1160 dev_err(dev
, "Failed to register panel\n");
1164 mutex_init(&ddata
->lock
);
1166 atomic_set(&ddata
->do_update
, 0);
1168 ddata
->reset_gpio
= devm_gpiod_get(&pdev
->dev
, "reset", GPIOD_OUT_LOW
);
1169 r
= PTR_ERR_OR_ZERO(ddata
->reset_gpio
);
1171 dev_err(&pdev
->dev
, "Failed to request reset gpio: %d\n", r
);
1175 gpiod_set_consumer_name(ddata
->reset_gpio
, "taal rst");
1177 ddata
->ext_te_gpio
= devm_gpiod_get_optional(&pdev
->dev
, "te",
1179 r
= PTR_ERR_OR_ZERO(ddata
->ext_te_gpio
);
1181 dev_err(&pdev
->dev
, "Failed to request TE gpio: %d\n", r
);
1185 if (ddata
->ext_te_gpio
) {
1186 gpiod_set_consumer_name(ddata
->ext_te_gpio
, "taal irq");
1188 r
= devm_request_irq(dev
, gpiod_to_irq(ddata
->ext_te_gpio
),
1190 IRQF_TRIGGER_RISING
,
1191 "taal vsync", ddata
);
1194 dev_err(dev
, "IRQ request failed\n");
1198 INIT_DEFERRABLE_WORK(&ddata
->te_timeout_work
,
1199 dsicm_te_timeout_work_callback
);
1201 dev_dbg(dev
, "Using GPIO TE\n");
1204 INIT_DELAYED_WORK(&ddata
->ulps_work
, dsicm_ulps_work
);
1206 dsicm_hw_reset(ddata
);
1208 if (ddata
->use_dsi_backlight
) {
1209 memset(&props
, 0, sizeof(struct backlight_properties
));
1210 props
.max_brightness
= 255;
1212 props
.type
= BACKLIGHT_RAW
;
1213 bldev
= backlight_device_register(dev_name(dev
),
1214 dev
, ddata
, &dsicm_bl_ops
, &props
);
1215 if (IS_ERR(bldev
)) {
1220 ddata
->bldev
= bldev
;
1222 bldev
->props
.fb_blank
= FB_BLANK_UNBLANK
;
1223 bldev
->props
.power
= FB_BLANK_UNBLANK
;
1224 bldev
->props
.brightness
= 255;
1226 dsicm_bl_update_status(bldev
);
1229 r
= sysfs_create_group(&dev
->kobj
, &dsicm_attr_group
);
1231 dev_err(dev
, "failed to create sysfs files\n");
1232 goto err_sysfs_create
;
1239 backlight_device_unregister(bldev
);
1244 static int dsicm_remove(struct platform_device
*pdev
)
1246 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
1247 struct omap_dss_device
*dssdev
= &ddata
->dssdev
;
1248 struct backlight_device
*bldev
;
1250 dev_dbg(&pdev
->dev
, "remove\n");
1252 omapdss_unregister_display(dssdev
);
1254 dsicm_disable(dssdev
);
1255 dsicm_disconnect(dssdev
);
1257 sysfs_remove_group(&pdev
->dev
.kobj
, &dsicm_attr_group
);
1259 bldev
= ddata
->bldev
;
1260 if (bldev
!= NULL
) {
1261 bldev
->props
.power
= FB_BLANK_POWERDOWN
;
1262 dsicm_bl_update_status(bldev
);
1263 backlight_device_unregister(bldev
);
1266 omap_dss_put_device(ddata
->in
);
1268 dsicm_cancel_ulps_work(ddata
);
1270 /* reset, to be sure that the panel is in a valid state */
1271 dsicm_hw_reset(ddata
);
1276 static const struct of_device_id dsicm_of_match
[] = {
1277 { .compatible
= "omapdss,panel-dsi-cm", },
1281 MODULE_DEVICE_TABLE(of
, dsicm_of_match
);
1283 static struct platform_driver dsicm_driver
= {
1284 .probe
= dsicm_probe
,
1285 .remove
= dsicm_remove
,
1287 .name
= "panel-dsi-cm",
1288 .of_match_table
= dsicm_of_match
,
1292 module_platform_driver(dsicm_driver
);
1294 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
1295 MODULE_DESCRIPTION("Generic DSI Command Mode Panel Driver");
1296 MODULE_LICENSE("GPL");