1 // SPDX-License-Identifier: GPL-2.0-only
3 * Generic DSI Command Mode panel driver
5 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
6 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
11 #include <linux/backlight.h>
12 #include <linux/delay.h>
13 #include <linux/gpio/consumer.h>
14 #include <linux/interrupt.h>
15 #include <linux/jiffies.h>
16 #include <linux/module.h>
17 #include <linux/platform_device.h>
18 #include <linux/sched/signal.h>
19 #include <linux/slab.h>
20 #include <linux/workqueue.h>
21 #include <linux/of_device.h>
22 #include <linux/regulator/consumer.h>
24 #include <drm/drm_connector.h>
26 #include <video/mipi_display.h>
27 #include <video/of_display_timing.h>
29 #include "../dss/omapdss.h"
31 /* DSI Virtual channel. Hardcoded for now. */
34 #define DCS_READ_NUM_ERRORS 0x05
35 #define DCS_BRIGHTNESS 0x51
36 #define DCS_CTRL_DISPLAY 0x53
37 #define DCS_GET_ID1 0xda
38 #define DCS_GET_ID2 0xdb
39 #define DCS_GET_ID3 0xdc
41 struct panel_drv_data
{
42 struct omap_dss_device dssdev
;
43 struct omap_dss_device
*src
;
47 struct platform_device
*pdev
;
51 struct backlight_device
*bldev
;
52 struct backlight_device
*extbldev
;
54 unsigned long hw_guard_end
; /* next value of jiffies when we can
55 * issue the next sleep in/out command
57 unsigned long hw_guard_wait
; /* max guard time in jiffies */
59 /* panel HW configuration from DT or platform data */
60 struct gpio_desc
*reset_gpio
;
61 struct gpio_desc
*ext_te_gpio
;
63 struct regulator
*vpnl
;
64 struct regulator
*vddi
;
66 bool use_dsi_backlight
;
71 struct omap_dsi_pin_config pin_config
;
73 /* runtime variables */
81 struct delayed_work te_timeout_work
;
85 struct workqueue_struct
*workqueue
;
88 unsigned int ulps_timeout
;
89 struct delayed_work ulps_work
;
92 #define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
94 static irqreturn_t
dsicm_te_isr(int irq
, void *data
);
95 static void dsicm_te_timeout_work_callback(struct work_struct
*work
);
96 static int _dsicm_enable_te(struct panel_drv_data
*ddata
, bool enable
);
98 static int dsicm_panel_reset(struct panel_drv_data
*ddata
);
100 static void dsicm_ulps_work(struct work_struct
*work
);
102 static void dsicm_bl_power(struct panel_drv_data
*ddata
, bool enable
)
104 struct backlight_device
*backlight
;
107 backlight
= ddata
->bldev
;
108 else if (ddata
->extbldev
)
109 backlight
= ddata
->extbldev
;
114 backlight
->props
.fb_blank
= FB_BLANK_UNBLANK
;
115 backlight
->props
.state
= ~(BL_CORE_FBBLANK
| BL_CORE_SUSPENDED
);
116 backlight
->props
.power
= FB_BLANK_UNBLANK
;
118 backlight
->props
.fb_blank
= FB_BLANK_NORMAL
;
119 backlight
->props
.power
= FB_BLANK_POWERDOWN
;
120 backlight
->props
.state
|= BL_CORE_FBBLANK
| BL_CORE_SUSPENDED
;
123 backlight_update_status(backlight
);
126 static void hw_guard_start(struct panel_drv_data
*ddata
, int guard_msec
)
128 ddata
->hw_guard_wait
= msecs_to_jiffies(guard_msec
);
129 ddata
->hw_guard_end
= jiffies
+ ddata
->hw_guard_wait
;
132 static void hw_guard_wait(struct panel_drv_data
*ddata
)
134 unsigned long wait
= ddata
->hw_guard_end
- jiffies
;
136 if ((long)wait
> 0 && wait
<= ddata
->hw_guard_wait
) {
137 set_current_state(TASK_UNINTERRUPTIBLE
);
138 schedule_timeout(wait
);
142 static int dsicm_dcs_read_1(struct panel_drv_data
*ddata
, u8 dcs_cmd
, u8
*data
)
144 struct omap_dss_device
*src
= ddata
->src
;
148 r
= src
->ops
->dsi
.dcs_read(src
, ddata
->channel
, dcs_cmd
, buf
, 1);
158 static int dsicm_dcs_write_0(struct panel_drv_data
*ddata
, u8 dcs_cmd
)
160 struct omap_dss_device
*src
= ddata
->src
;
162 return src
->ops
->dsi
.dcs_write(src
, ddata
->channel
, &dcs_cmd
, 1);
165 static int dsicm_dcs_write_1(struct panel_drv_data
*ddata
, u8 dcs_cmd
, u8 param
)
167 struct omap_dss_device
*src
= ddata
->src
;
168 u8 buf
[2] = { dcs_cmd
, param
};
170 return src
->ops
->dsi
.dcs_write(src
, ddata
->channel
, buf
, 2);
173 static int dsicm_sleep_in(struct panel_drv_data
*ddata
)
176 struct omap_dss_device
*src
= ddata
->src
;
180 hw_guard_wait(ddata
);
182 cmd
= MIPI_DCS_ENTER_SLEEP_MODE
;
183 r
= src
->ops
->dsi
.dcs_write_nosync(src
, ddata
->channel
, &cmd
, 1);
187 hw_guard_start(ddata
, 120);
189 usleep_range(5000, 10000);
194 static int dsicm_sleep_out(struct panel_drv_data
*ddata
)
198 hw_guard_wait(ddata
);
200 r
= dsicm_dcs_write_0(ddata
, MIPI_DCS_EXIT_SLEEP_MODE
);
204 hw_guard_start(ddata
, 120);
206 usleep_range(5000, 10000);
211 static int dsicm_get_id(struct panel_drv_data
*ddata
, u8
*id1
, u8
*id2
, u8
*id3
)
215 r
= dsicm_dcs_read_1(ddata
, DCS_GET_ID1
, id1
);
218 r
= dsicm_dcs_read_1(ddata
, DCS_GET_ID2
, id2
);
221 r
= dsicm_dcs_read_1(ddata
, DCS_GET_ID3
, id3
);
228 static int dsicm_set_update_window(struct panel_drv_data
*ddata
,
229 u16 x
, u16 y
, u16 w
, u16 h
)
231 struct omap_dss_device
*src
= ddata
->src
;
239 buf
[0] = MIPI_DCS_SET_COLUMN_ADDRESS
;
240 buf
[1] = (x1
>> 8) & 0xff;
241 buf
[2] = (x1
>> 0) & 0xff;
242 buf
[3] = (x2
>> 8) & 0xff;
243 buf
[4] = (x2
>> 0) & 0xff;
245 r
= src
->ops
->dsi
.dcs_write_nosync(src
, ddata
->channel
, buf
, sizeof(buf
));
249 buf
[0] = MIPI_DCS_SET_PAGE_ADDRESS
;
250 buf
[1] = (y1
>> 8) & 0xff;
251 buf
[2] = (y1
>> 0) & 0xff;
252 buf
[3] = (y2
>> 8) & 0xff;
253 buf
[4] = (y2
>> 0) & 0xff;
255 r
= src
->ops
->dsi
.dcs_write_nosync(src
, ddata
->channel
, buf
, sizeof(buf
));
259 src
->ops
->dsi
.bta_sync(src
, ddata
->channel
);
264 static void dsicm_queue_ulps_work(struct panel_drv_data
*ddata
)
266 if (ddata
->ulps_timeout
> 0)
267 queue_delayed_work(ddata
->workqueue
, &ddata
->ulps_work
,
268 msecs_to_jiffies(ddata
->ulps_timeout
));
271 static void dsicm_cancel_ulps_work(struct panel_drv_data
*ddata
)
273 cancel_delayed_work(&ddata
->ulps_work
);
276 static int dsicm_enter_ulps(struct panel_drv_data
*ddata
)
278 struct omap_dss_device
*src
= ddata
->src
;
281 if (ddata
->ulps_enabled
)
284 dsicm_cancel_ulps_work(ddata
);
286 r
= _dsicm_enable_te(ddata
, false);
290 if (ddata
->ext_te_gpio
)
291 disable_irq(gpiod_to_irq(ddata
->ext_te_gpio
));
293 src
->ops
->dsi
.disable(src
, false, true);
295 ddata
->ulps_enabled
= true;
300 dev_err(&ddata
->pdev
->dev
, "enter ULPS failed");
301 dsicm_panel_reset(ddata
);
303 ddata
->ulps_enabled
= false;
305 dsicm_queue_ulps_work(ddata
);
310 static int dsicm_exit_ulps(struct panel_drv_data
*ddata
)
312 struct omap_dss_device
*src
= ddata
->src
;
315 if (!ddata
->ulps_enabled
)
318 src
->ops
->enable(src
);
319 src
->ops
->dsi
.enable_hs(src
, ddata
->channel
, true);
321 r
= _dsicm_enable_te(ddata
, true);
323 dev_err(&ddata
->pdev
->dev
, "failed to re-enable TE");
327 if (ddata
->ext_te_gpio
)
328 enable_irq(gpiod_to_irq(ddata
->ext_te_gpio
));
330 dsicm_queue_ulps_work(ddata
);
332 ddata
->ulps_enabled
= false;
337 dev_err(&ddata
->pdev
->dev
, "failed to exit ULPS");
339 r
= dsicm_panel_reset(ddata
);
341 if (ddata
->ext_te_gpio
)
342 enable_irq(gpiod_to_irq(ddata
->ext_te_gpio
));
343 ddata
->ulps_enabled
= false;
346 dsicm_queue_ulps_work(ddata
);
351 static int dsicm_wake_up(struct panel_drv_data
*ddata
)
353 if (ddata
->ulps_enabled
)
354 return dsicm_exit_ulps(ddata
);
356 dsicm_cancel_ulps_work(ddata
);
357 dsicm_queue_ulps_work(ddata
);
361 static int dsicm_bl_update_status(struct backlight_device
*dev
)
363 struct panel_drv_data
*ddata
= dev_get_drvdata(&dev
->dev
);
364 struct omap_dss_device
*src
= ddata
->src
;
368 if (dev
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
369 dev
->props
.power
== FB_BLANK_UNBLANK
)
370 level
= dev
->props
.brightness
;
374 dev_dbg(&ddata
->pdev
->dev
, "update brightness to %d\n", level
);
376 mutex_lock(&ddata
->lock
);
378 if (ddata
->enabled
) {
379 src
->ops
->dsi
.bus_lock(src
);
381 r
= dsicm_wake_up(ddata
);
383 r
= dsicm_dcs_write_1(ddata
, DCS_BRIGHTNESS
, level
);
385 src
->ops
->dsi
.bus_unlock(src
);
388 mutex_unlock(&ddata
->lock
);
393 static int dsicm_bl_get_intensity(struct backlight_device
*dev
)
395 if (dev
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
396 dev
->props
.power
== FB_BLANK_UNBLANK
)
397 return dev
->props
.brightness
;
402 static const struct backlight_ops dsicm_bl_ops
= {
403 .get_brightness
= dsicm_bl_get_intensity
,
404 .update_status
= dsicm_bl_update_status
,
407 static ssize_t
dsicm_num_errors_show(struct device
*dev
,
408 struct device_attribute
*attr
, char *buf
)
410 struct panel_drv_data
*ddata
= dev_get_drvdata(dev
);
411 struct omap_dss_device
*src
= ddata
->src
;
415 mutex_lock(&ddata
->lock
);
417 if (ddata
->enabled
) {
418 src
->ops
->dsi
.bus_lock(src
);
420 r
= dsicm_wake_up(ddata
);
422 r
= dsicm_dcs_read_1(ddata
, DCS_READ_NUM_ERRORS
,
425 src
->ops
->dsi
.bus_unlock(src
);
430 mutex_unlock(&ddata
->lock
);
435 return snprintf(buf
, PAGE_SIZE
, "%d\n", errors
);
438 static ssize_t
dsicm_hw_revision_show(struct device
*dev
,
439 struct device_attribute
*attr
, char *buf
)
441 struct panel_drv_data
*ddata
= dev_get_drvdata(dev
);
442 struct omap_dss_device
*src
= ddata
->src
;
446 mutex_lock(&ddata
->lock
);
448 if (ddata
->enabled
) {
449 src
->ops
->dsi
.bus_lock(src
);
451 r
= dsicm_wake_up(ddata
);
453 r
= dsicm_get_id(ddata
, &id1
, &id2
, &id3
);
455 src
->ops
->dsi
.bus_unlock(src
);
460 mutex_unlock(&ddata
->lock
);
465 return snprintf(buf
, PAGE_SIZE
, "%02x.%02x.%02x\n", id1
, id2
, id3
);
468 static ssize_t
dsicm_store_ulps(struct device
*dev
,
469 struct device_attribute
*attr
,
470 const char *buf
, size_t count
)
472 struct panel_drv_data
*ddata
= dev_get_drvdata(dev
);
473 struct omap_dss_device
*src
= ddata
->src
;
477 r
= kstrtoul(buf
, 0, &t
);
481 mutex_lock(&ddata
->lock
);
483 if (ddata
->enabled
) {
484 src
->ops
->dsi
.bus_lock(src
);
487 r
= dsicm_enter_ulps(ddata
);
489 r
= dsicm_wake_up(ddata
);
491 src
->ops
->dsi
.bus_unlock(src
);
494 mutex_unlock(&ddata
->lock
);
502 static ssize_t
dsicm_show_ulps(struct device
*dev
,
503 struct device_attribute
*attr
,
506 struct panel_drv_data
*ddata
= dev_get_drvdata(dev
);
509 mutex_lock(&ddata
->lock
);
510 t
= ddata
->ulps_enabled
;
511 mutex_unlock(&ddata
->lock
);
513 return snprintf(buf
, PAGE_SIZE
, "%u\n", t
);
516 static ssize_t
dsicm_store_ulps_timeout(struct device
*dev
,
517 struct device_attribute
*attr
,
518 const char *buf
, size_t count
)
520 struct panel_drv_data
*ddata
= dev_get_drvdata(dev
);
521 struct omap_dss_device
*src
= ddata
->src
;
525 r
= kstrtoul(buf
, 0, &t
);
529 mutex_lock(&ddata
->lock
);
530 ddata
->ulps_timeout
= t
;
532 if (ddata
->enabled
) {
533 /* dsicm_wake_up will restart the timer */
534 src
->ops
->dsi
.bus_lock(src
);
535 r
= dsicm_wake_up(ddata
);
536 src
->ops
->dsi
.bus_unlock(src
);
539 mutex_unlock(&ddata
->lock
);
547 static ssize_t
dsicm_show_ulps_timeout(struct device
*dev
,
548 struct device_attribute
*attr
,
551 struct panel_drv_data
*ddata
= dev_get_drvdata(dev
);
554 mutex_lock(&ddata
->lock
);
555 t
= ddata
->ulps_timeout
;
556 mutex_unlock(&ddata
->lock
);
558 return snprintf(buf
, PAGE_SIZE
, "%u\n", t
);
561 static DEVICE_ATTR(num_dsi_errors
, S_IRUGO
, dsicm_num_errors_show
, NULL
);
562 static DEVICE_ATTR(hw_revision
, S_IRUGO
, dsicm_hw_revision_show
, NULL
);
563 static DEVICE_ATTR(ulps
, S_IRUGO
| S_IWUSR
,
564 dsicm_show_ulps
, dsicm_store_ulps
);
565 static DEVICE_ATTR(ulps_timeout
, S_IRUGO
| S_IWUSR
,
566 dsicm_show_ulps_timeout
, dsicm_store_ulps_timeout
);
568 static struct attribute
*dsicm_attrs
[] = {
569 &dev_attr_num_dsi_errors
.attr
,
570 &dev_attr_hw_revision
.attr
,
572 &dev_attr_ulps_timeout
.attr
,
576 static const struct attribute_group dsicm_attr_group
= {
577 .attrs
= dsicm_attrs
,
580 static void dsicm_hw_reset(struct panel_drv_data
*ddata
)
582 gpiod_set_value(ddata
->reset_gpio
, 1);
584 /* reset the panel */
585 gpiod_set_value(ddata
->reset_gpio
, 0);
588 gpiod_set_value(ddata
->reset_gpio
, 1);
589 /* wait after releasing reset */
590 usleep_range(5000, 10000);
593 static int dsicm_power_on(struct panel_drv_data
*ddata
)
595 struct omap_dss_device
*src
= ddata
->src
;
598 struct omap_dss_dsi_config dsi_config
= {
599 .mode
= OMAP_DSS_DSI_CMD_MODE
,
600 .pixel_format
= OMAP_DSS_DSI_FMT_RGB888
,
602 .hs_clk_min
= 150000000,
603 .hs_clk_max
= 300000000,
604 .lp_clk_min
= 7000000,
605 .lp_clk_max
= 10000000,
609 r
= regulator_enable(ddata
->vpnl
);
611 dev_err(&ddata
->pdev
->dev
,
612 "failed to enable VPNL: %d\n", r
);
618 r
= regulator_enable(ddata
->vddi
);
620 dev_err(&ddata
->pdev
->dev
,
621 "failed to enable VDDI: %d\n", r
);
626 if (ddata
->pin_config
.num_pins
> 0) {
627 r
= src
->ops
->dsi
.configure_pins(src
, &ddata
->pin_config
);
629 dev_err(&ddata
->pdev
->dev
,
630 "failed to configure DSI pins\n");
635 r
= src
->ops
->dsi
.set_config(src
, &dsi_config
);
637 dev_err(&ddata
->pdev
->dev
, "failed to configure DSI\n");
641 src
->ops
->enable(src
);
643 dsicm_hw_reset(ddata
);
645 src
->ops
->dsi
.enable_hs(src
, ddata
->channel
, false);
647 r
= dsicm_sleep_out(ddata
);
651 r
= dsicm_get_id(ddata
, &id1
, &id2
, &id3
);
655 r
= dsicm_dcs_write_1(ddata
, DCS_BRIGHTNESS
, 0xff);
659 r
= dsicm_dcs_write_1(ddata
, DCS_CTRL_DISPLAY
,
660 (1<<2) | (1<<5)); /* BL | BCTRL */
664 r
= dsicm_dcs_write_1(ddata
, MIPI_DCS_SET_PIXEL_FORMAT
,
665 MIPI_DCS_PIXEL_FMT_24BIT
);
669 r
= dsicm_dcs_write_0(ddata
, MIPI_DCS_SET_DISPLAY_ON
);
673 r
= _dsicm_enable_te(ddata
, ddata
->te_enabled
);
677 r
= src
->ops
->dsi
.enable_video_output(src
, ddata
->channel
);
683 if (!ddata
->intro_printed
) {
684 dev_info(&ddata
->pdev
->dev
, "panel revision %02x.%02x.%02x\n",
686 ddata
->intro_printed
= true;
689 src
->ops
->dsi
.enable_hs(src
, ddata
->channel
, true);
693 dev_err(&ddata
->pdev
->dev
, "error while enabling panel, issuing HW reset\n");
695 dsicm_hw_reset(ddata
);
697 src
->ops
->dsi
.disable(src
, true, false);
700 regulator_disable(ddata
->vddi
);
703 regulator_disable(ddata
->vpnl
);
708 static void dsicm_power_off(struct panel_drv_data
*ddata
)
710 struct omap_dss_device
*src
= ddata
->src
;
713 src
->ops
->dsi
.disable_video_output(src
, ddata
->channel
);
715 r
= dsicm_dcs_write_0(ddata
, MIPI_DCS_SET_DISPLAY_OFF
);
717 r
= dsicm_sleep_in(ddata
);
720 dev_err(&ddata
->pdev
->dev
,
721 "error disabling panel, issuing HW reset\n");
722 dsicm_hw_reset(ddata
);
725 src
->ops
->dsi
.disable(src
, true, false);
728 regulator_disable(ddata
->vddi
);
730 regulator_disable(ddata
->vpnl
);
735 static int dsicm_panel_reset(struct panel_drv_data
*ddata
)
737 dev_err(&ddata
->pdev
->dev
, "performing LCD reset\n");
739 dsicm_power_off(ddata
);
740 dsicm_hw_reset(ddata
);
741 return dsicm_power_on(ddata
);
744 static int dsicm_connect(struct omap_dss_device
*src
,
745 struct omap_dss_device
*dst
)
747 struct panel_drv_data
*ddata
= to_panel_data(dst
);
748 struct device
*dev
= &ddata
->pdev
->dev
;
751 r
= src
->ops
->dsi
.request_vc(src
, &ddata
->channel
);
753 dev_err(dev
, "failed to get virtual channel\n");
757 r
= src
->ops
->dsi
.set_vc_id(src
, ddata
->channel
, TCH
);
759 dev_err(dev
, "failed to set VC_ID\n");
760 src
->ops
->dsi
.release_vc(src
, ddata
->channel
);
768 static void dsicm_disconnect(struct omap_dss_device
*src
,
769 struct omap_dss_device
*dst
)
771 struct panel_drv_data
*ddata
= to_panel_data(dst
);
773 src
->ops
->dsi
.release_vc(src
, ddata
->channel
);
777 static void dsicm_enable(struct omap_dss_device
*dssdev
)
779 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
780 struct omap_dss_device
*src
= ddata
->src
;
783 mutex_lock(&ddata
->lock
);
785 src
->ops
->dsi
.bus_lock(src
);
787 r
= dsicm_power_on(ddata
);
789 src
->ops
->dsi
.bus_unlock(src
);
794 mutex_unlock(&ddata
->lock
);
796 dsicm_bl_power(ddata
, true);
800 dev_dbg(&ddata
->pdev
->dev
, "enable failed (%d)\n", r
);
801 mutex_unlock(&ddata
->lock
);
804 static void dsicm_disable(struct omap_dss_device
*dssdev
)
806 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
807 struct omap_dss_device
*src
= ddata
->src
;
810 dsicm_bl_power(ddata
, false);
812 mutex_lock(&ddata
->lock
);
814 dsicm_cancel_ulps_work(ddata
);
816 src
->ops
->dsi
.bus_lock(src
);
818 r
= dsicm_wake_up(ddata
);
820 dsicm_power_off(ddata
);
822 src
->ops
->dsi
.bus_unlock(src
);
824 mutex_unlock(&ddata
->lock
);
827 static void dsicm_framedone_cb(int err
, void *data
)
829 struct panel_drv_data
*ddata
= data
;
830 struct omap_dss_device
*src
= ddata
->src
;
832 dev_dbg(&ddata
->pdev
->dev
, "framedone, err %d\n", err
);
833 src
->ops
->dsi
.bus_unlock(src
);
836 static irqreturn_t
dsicm_te_isr(int irq
, void *data
)
838 struct panel_drv_data
*ddata
= data
;
839 struct omap_dss_device
*src
= ddata
->src
;
843 old
= atomic_cmpxchg(&ddata
->do_update
, 1, 0);
846 cancel_delayed_work(&ddata
->te_timeout_work
);
848 r
= src
->ops
->dsi
.update(src
, ddata
->channel
, dsicm_framedone_cb
,
856 dev_err(&ddata
->pdev
->dev
, "start update failed\n");
857 src
->ops
->dsi
.bus_unlock(src
);
861 static void dsicm_te_timeout_work_callback(struct work_struct
*work
)
863 struct panel_drv_data
*ddata
= container_of(work
, struct panel_drv_data
,
864 te_timeout_work
.work
);
865 struct omap_dss_device
*src
= ddata
->src
;
867 dev_err(&ddata
->pdev
->dev
, "TE not received for 250ms!\n");
869 atomic_set(&ddata
->do_update
, 0);
870 src
->ops
->dsi
.bus_unlock(src
);
873 static int dsicm_update(struct omap_dss_device
*dssdev
,
874 u16 x
, u16 y
, u16 w
, u16 h
)
876 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
877 struct omap_dss_device
*src
= ddata
->src
;
880 dev_dbg(&ddata
->pdev
->dev
, "update %d, %d, %d x %d\n", x
, y
, w
, h
);
882 mutex_lock(&ddata
->lock
);
883 src
->ops
->dsi
.bus_lock(src
);
885 r
= dsicm_wake_up(ddata
);
889 if (!ddata
->enabled
) {
894 /* XXX no need to send this every frame, but dsi break if not done */
895 r
= dsicm_set_update_window(ddata
, 0, 0, ddata
->vm
.hactive
,
900 if (ddata
->te_enabled
&& ddata
->ext_te_gpio
) {
901 schedule_delayed_work(&ddata
->te_timeout_work
,
902 msecs_to_jiffies(250));
903 atomic_set(&ddata
->do_update
, 1);
905 r
= src
->ops
->dsi
.update(src
, ddata
->channel
, dsicm_framedone_cb
,
911 /* note: no bus_unlock here. unlock is src framedone_cb */
912 mutex_unlock(&ddata
->lock
);
915 src
->ops
->dsi
.bus_unlock(src
);
916 mutex_unlock(&ddata
->lock
);
920 static int dsicm_sync(struct omap_dss_device
*dssdev
)
922 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
923 struct omap_dss_device
*src
= ddata
->src
;
925 dev_dbg(&ddata
->pdev
->dev
, "sync\n");
927 mutex_lock(&ddata
->lock
);
928 src
->ops
->dsi
.bus_lock(src
);
929 src
->ops
->dsi
.bus_unlock(src
);
930 mutex_unlock(&ddata
->lock
);
932 dev_dbg(&ddata
->pdev
->dev
, "sync done\n");
937 static int _dsicm_enable_te(struct panel_drv_data
*ddata
, bool enable
)
939 struct omap_dss_device
*src
= ddata
->src
;
943 r
= dsicm_dcs_write_1(ddata
, MIPI_DCS_SET_TEAR_ON
, 0);
945 r
= dsicm_dcs_write_0(ddata
, MIPI_DCS_SET_TEAR_OFF
);
947 if (!ddata
->ext_te_gpio
)
948 src
->ops
->dsi
.enable_te(src
, enable
);
950 /* possible panel bug */
956 static int dsicm_enable_te(struct omap_dss_device
*dssdev
, bool enable
)
958 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
959 struct omap_dss_device
*src
= ddata
->src
;
962 mutex_lock(&ddata
->lock
);
964 if (ddata
->te_enabled
== enable
)
967 src
->ops
->dsi
.bus_lock(src
);
969 if (ddata
->enabled
) {
970 r
= dsicm_wake_up(ddata
);
974 r
= _dsicm_enable_te(ddata
, enable
);
979 ddata
->te_enabled
= enable
;
981 src
->ops
->dsi
.bus_unlock(src
);
983 mutex_unlock(&ddata
->lock
);
987 src
->ops
->dsi
.bus_unlock(src
);
988 mutex_unlock(&ddata
->lock
);
993 static int dsicm_get_te(struct omap_dss_device
*dssdev
)
995 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
998 mutex_lock(&ddata
->lock
);
999 r
= ddata
->te_enabled
;
1000 mutex_unlock(&ddata
->lock
);
1005 static int dsicm_memory_read(struct omap_dss_device
*dssdev
,
1006 void *buf
, size_t size
,
1007 u16 x
, u16 y
, u16 w
, u16 h
)
1009 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
1010 struct omap_dss_device
*src
= ddata
->src
;
1014 unsigned int buf_used
= 0;
1016 if (size
< w
* h
* 3)
1019 mutex_lock(&ddata
->lock
);
1021 if (!ddata
->enabled
) {
1026 size
= min((u32
)w
* h
* 3,
1027 ddata
->vm
.hactive
* ddata
->vm
.vactive
* 3);
1029 src
->ops
->dsi
.bus_lock(src
);
1031 r
= dsicm_wake_up(ddata
);
1035 /* plen 1 or 2 goes into short packet. until checksum error is fixed,
1036 * use short packets. plen 32 works, but bigger packets seem to cause
1043 dsicm_set_update_window(ddata
, x
, y
, w
, h
);
1045 r
= src
->ops
->dsi
.set_max_rx_packet_size(src
, ddata
->channel
, plen
);
1049 while (buf_used
< size
) {
1050 u8 dcs_cmd
= first
? 0x2e : 0x3e;
1053 r
= src
->ops
->dsi
.dcs_read(src
, ddata
->channel
, dcs_cmd
,
1054 buf
+ buf_used
, size
- buf_used
);
1057 dev_err(dssdev
->dev
, "read error\n");
1064 dev_err(&ddata
->pdev
->dev
, "short read\n");
1068 if (signal_pending(current
)) {
1069 dev_err(&ddata
->pdev
->dev
, "signal pending, "
1070 "aborting memory read\n");
1079 src
->ops
->dsi
.set_max_rx_packet_size(src
, ddata
->channel
, 1);
1081 src
->ops
->dsi
.bus_unlock(src
);
1083 mutex_unlock(&ddata
->lock
);
1087 static void dsicm_ulps_work(struct work_struct
*work
)
1089 struct panel_drv_data
*ddata
= container_of(work
, struct panel_drv_data
,
1091 struct omap_dss_device
*dssdev
= &ddata
->dssdev
;
1092 struct omap_dss_device
*src
= ddata
->src
;
1094 mutex_lock(&ddata
->lock
);
1096 if (dssdev
->state
!= OMAP_DSS_DISPLAY_ACTIVE
|| !ddata
->enabled
) {
1097 mutex_unlock(&ddata
->lock
);
1101 src
->ops
->dsi
.bus_lock(src
);
1103 dsicm_enter_ulps(ddata
);
1105 src
->ops
->dsi
.bus_unlock(src
);
1106 mutex_unlock(&ddata
->lock
);
1109 static int dsicm_get_modes(struct omap_dss_device
*dssdev
,
1110 struct drm_connector
*connector
)
1112 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
1114 connector
->display_info
.width_mm
= ddata
->width_mm
;
1115 connector
->display_info
.height_mm
= ddata
->height_mm
;
1117 return omapdss_display_get_modes(connector
, &ddata
->vm
);
1120 static int dsicm_check_timings(struct omap_dss_device
*dssdev
,
1121 struct drm_display_mode
*mode
)
1123 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
1126 if (mode
->hdisplay
!= ddata
->vm
.hactive
)
1129 if (mode
->vdisplay
!= ddata
->vm
.vactive
)
1133 dev_warn(dssdev
->dev
, "wrong resolution: %d x %d",
1134 mode
->hdisplay
, mode
->vdisplay
);
1135 dev_warn(dssdev
->dev
, "panel resolution: %d x %d",
1136 ddata
->vm
.hactive
, ddata
->vm
.vactive
);
1142 static const struct omap_dss_device_ops dsicm_ops
= {
1143 .connect
= dsicm_connect
,
1144 .disconnect
= dsicm_disconnect
,
1146 .enable
= dsicm_enable
,
1147 .disable
= dsicm_disable
,
1149 .get_modes
= dsicm_get_modes
,
1150 .check_timings
= dsicm_check_timings
,
1153 static const struct omap_dss_driver dsicm_dss_driver
= {
1154 .update
= dsicm_update
,
1157 .enable_te
= dsicm_enable_te
,
1158 .get_te
= dsicm_get_te
,
1160 .memory_read
= dsicm_memory_read
,
1163 static int dsicm_probe_of(struct platform_device
*pdev
)
1165 struct device_node
*node
= pdev
->dev
.of_node
;
1166 struct device_node
*backlight
;
1167 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
1168 struct display_timing timing
;
1171 ddata
->reset_gpio
= devm_gpiod_get(&pdev
->dev
, "reset", GPIOD_OUT_LOW
);
1172 if (IS_ERR(ddata
->reset_gpio
)) {
1173 err
= PTR_ERR(ddata
->reset_gpio
);
1174 dev_err(&pdev
->dev
, "reset gpio request failed: %d", err
);
1178 ddata
->ext_te_gpio
= devm_gpiod_get_optional(&pdev
->dev
, "te",
1180 if (IS_ERR(ddata
->ext_te_gpio
)) {
1181 err
= PTR_ERR(ddata
->ext_te_gpio
);
1182 dev_err(&pdev
->dev
, "TE gpio request failed: %d", err
);
1186 err
= of_get_display_timing(node
, "panel-timing", &timing
);
1188 videomode_from_timing(&timing
, &ddata
->vm
);
1189 if (!ddata
->vm
.pixelclock
)
1190 ddata
->vm
.pixelclock
=
1191 ddata
->vm
.hactive
* ddata
->vm
.vactive
* 60;
1193 dev_warn(&pdev
->dev
,
1194 "failed to get video timing, using defaults\n");
1197 ddata
->width_mm
= 0;
1198 of_property_read_u32(node
, "width-mm", &ddata
->width_mm
);
1200 ddata
->height_mm
= 0;
1201 of_property_read_u32(node
, "height-mm", &ddata
->height_mm
);
1203 ddata
->vpnl
= devm_regulator_get_optional(&pdev
->dev
, "vpnl");
1204 if (IS_ERR(ddata
->vpnl
)) {
1205 err
= PTR_ERR(ddata
->vpnl
);
1206 if (err
== -EPROBE_DEFER
)
1211 ddata
->vddi
= devm_regulator_get_optional(&pdev
->dev
, "vddi");
1212 if (IS_ERR(ddata
->vddi
)) {
1213 err
= PTR_ERR(ddata
->vddi
);
1214 if (err
== -EPROBE_DEFER
)
1219 backlight
= of_parse_phandle(node
, "backlight", 0);
1221 ddata
->extbldev
= of_find_backlight_by_node(backlight
);
1222 of_node_put(backlight
);
1224 if (!ddata
->extbldev
)
1225 return -EPROBE_DEFER
;
1227 /* assume native backlight support */
1228 ddata
->use_dsi_backlight
= true;
1236 static int dsicm_probe(struct platform_device
*pdev
)
1238 struct panel_drv_data
*ddata
;
1239 struct backlight_device
*bldev
= NULL
;
1240 struct device
*dev
= &pdev
->dev
;
1241 struct omap_dss_device
*dssdev
;
1244 dev_dbg(dev
, "probe\n");
1246 ddata
= devm_kzalloc(dev
, sizeof(*ddata
), GFP_KERNEL
);
1250 platform_set_drvdata(pdev
, ddata
);
1253 ddata
->vm
.hactive
= 864;
1254 ddata
->vm
.vactive
= 480;
1255 ddata
->vm
.pixelclock
= 864 * 480 * 60;
1257 r
= dsicm_probe_of(pdev
);
1261 dssdev
= &ddata
->dssdev
;
1263 dssdev
->ops
= &dsicm_ops
;
1264 dssdev
->driver
= &dsicm_dss_driver
;
1265 dssdev
->type
= OMAP_DISPLAY_TYPE_DSI
;
1266 dssdev
->display
= true;
1267 dssdev
->owner
= THIS_MODULE
;
1268 dssdev
->of_ports
= BIT(0);
1269 dssdev
->ops_flags
= OMAP_DSS_DEVICE_OP_MODES
;
1271 dssdev
->caps
= OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE
|
1272 OMAP_DSS_DISPLAY_CAP_TEAR_ELIM
;
1274 omapdss_display_init(dssdev
);
1275 omapdss_device_register(dssdev
);
1277 mutex_init(&ddata
->lock
);
1279 atomic_set(&ddata
->do_update
, 0);
1281 if (ddata
->ext_te_gpio
) {
1282 r
= devm_request_irq(dev
, gpiod_to_irq(ddata
->ext_te_gpio
),
1284 IRQF_TRIGGER_RISING
,
1285 "taal vsync", ddata
);
1288 dev_err(dev
, "IRQ request failed\n");
1292 INIT_DEFERRABLE_WORK(&ddata
->te_timeout_work
,
1293 dsicm_te_timeout_work_callback
);
1295 dev_dbg(dev
, "Using GPIO TE\n");
1298 ddata
->workqueue
= create_singlethread_workqueue("dsicm_wq");
1299 if (!ddata
->workqueue
) {
1303 INIT_DELAYED_WORK(&ddata
->ulps_work
, dsicm_ulps_work
);
1305 dsicm_hw_reset(ddata
);
1307 if (ddata
->use_dsi_backlight
) {
1308 struct backlight_properties props
= { 0 };
1309 props
.max_brightness
= 255;
1310 props
.type
= BACKLIGHT_RAW
;
1312 bldev
= devm_backlight_device_register(dev
, dev_name(dev
),
1313 dev
, ddata
, &dsicm_bl_ops
, &props
);
1314 if (IS_ERR(bldev
)) {
1319 ddata
->bldev
= bldev
;
1322 r
= sysfs_create_group(&dev
->kobj
, &dsicm_attr_group
);
1324 dev_err(dev
, "failed to create sysfs files\n");
1331 destroy_workqueue(ddata
->workqueue
);
1333 if (ddata
->extbldev
)
1334 put_device(&ddata
->extbldev
->dev
);
1339 static int __exit
dsicm_remove(struct platform_device
*pdev
)
1341 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
1342 struct omap_dss_device
*dssdev
= &ddata
->dssdev
;
1344 dev_dbg(&pdev
->dev
, "remove\n");
1346 omapdss_device_unregister(dssdev
);
1348 if (omapdss_device_is_enabled(dssdev
))
1349 dsicm_disable(dssdev
);
1350 omapdss_device_disconnect(ddata
->src
, dssdev
);
1352 sysfs_remove_group(&pdev
->dev
.kobj
, &dsicm_attr_group
);
1354 if (ddata
->extbldev
)
1355 put_device(&ddata
->extbldev
->dev
);
1357 dsicm_cancel_ulps_work(ddata
);
1358 destroy_workqueue(ddata
->workqueue
);
1360 /* reset, to be sure that the panel is in a valid state */
1361 dsicm_hw_reset(ddata
);
1366 static const struct of_device_id dsicm_of_match
[] = {
1367 { .compatible
= "omapdss,panel-dsi-cm", },
1371 MODULE_DEVICE_TABLE(of
, dsicm_of_match
);
1373 static struct platform_driver dsicm_driver
= {
1374 .probe
= dsicm_probe
,
1375 .remove
= __exit_p(dsicm_remove
),
1377 .name
= "panel-dsi-cm",
1378 .of_match_table
= dsicm_of_match
,
1379 .suppress_bind_attrs
= true,
1383 module_platform_driver(dsicm_driver
);
1385 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
1386 MODULE_DESCRIPTION("Generic DSI Command Mode Panel Driver");
1387 MODULE_LICENSE("GPL");