2 * Generic DSI Command Mode panel driver
4 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
5 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
14 #include <linux/backlight.h>
15 #include <linux/delay.h>
16 #include <linux/gpio/consumer.h>
17 #include <linux/interrupt.h>
18 #include <linux/jiffies.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>
24 #include <linux/of_device.h>
25 #include <linux/regulator/consumer.h>
27 #include <video/mipi_display.h>
28 #include <video/of_display_timing.h>
30 #include "../dss/omapdss.h"
32 /* DSI Virtual channel. Hardcoded for now. */
35 #define DCS_READ_NUM_ERRORS 0x05
36 #define DCS_BRIGHTNESS 0x51
37 #define DCS_CTRL_DISPLAY 0x53
38 #define DCS_GET_ID1 0xda
39 #define DCS_GET_ID2 0xdb
40 #define DCS_GET_ID3 0xdc
42 struct panel_drv_data
{
43 struct omap_dss_device dssdev
;
44 struct omap_dss_device
*in
;
48 struct platform_device
*pdev
;
52 struct backlight_device
*bldev
;
53 struct backlight_device
*extbldev
;
55 unsigned long hw_guard_end
; /* next value of jiffies when we can
56 * issue the next sleep in/out command
58 unsigned long hw_guard_wait
; /* max guard time in jiffies */
60 /* panel HW configuration from DT or platform data */
61 struct gpio_desc
*reset_gpio
;
62 struct gpio_desc
*ext_te_gpio
;
64 struct regulator
*vpnl
;
65 struct regulator
*vddi
;
67 bool use_dsi_backlight
;
72 struct omap_dsi_pin_config pin_config
;
74 /* runtime variables */
82 struct delayed_work te_timeout_work
;
86 struct workqueue_struct
*workqueue
;
89 unsigned ulps_timeout
;
90 struct delayed_work ulps_work
;
93 #define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
95 static irqreturn_t
dsicm_te_isr(int irq
, void *data
);
96 static void dsicm_te_timeout_work_callback(struct work_struct
*work
);
97 static int _dsicm_enable_te(struct panel_drv_data
*ddata
, bool enable
);
99 static int dsicm_panel_reset(struct panel_drv_data
*ddata
);
101 static void dsicm_ulps_work(struct work_struct
*work
);
103 static void dsicm_bl_power(struct panel_drv_data
*ddata
, bool enable
)
105 struct backlight_device
*backlight
;
108 backlight
= ddata
->bldev
;
109 else if (ddata
->extbldev
)
110 backlight
= ddata
->extbldev
;
115 backlight
->props
.fb_blank
= FB_BLANK_UNBLANK
;
116 backlight
->props
.state
= ~(BL_CORE_FBBLANK
| BL_CORE_SUSPENDED
);
117 backlight
->props
.power
= FB_BLANK_UNBLANK
;
119 backlight
->props
.fb_blank
= FB_BLANK_NORMAL
;
120 backlight
->props
.power
= FB_BLANK_POWERDOWN
;
121 backlight
->props
.state
|= BL_CORE_FBBLANK
| BL_CORE_SUSPENDED
;
124 backlight_update_status(backlight
);
127 static void hw_guard_start(struct panel_drv_data
*ddata
, int guard_msec
)
129 ddata
->hw_guard_wait
= msecs_to_jiffies(guard_msec
);
130 ddata
->hw_guard_end
= jiffies
+ ddata
->hw_guard_wait
;
133 static void hw_guard_wait(struct panel_drv_data
*ddata
)
135 unsigned long wait
= ddata
->hw_guard_end
- jiffies
;
137 if ((long)wait
> 0 && wait
<= ddata
->hw_guard_wait
) {
138 set_current_state(TASK_UNINTERRUPTIBLE
);
139 schedule_timeout(wait
);
143 static int dsicm_dcs_read_1(struct panel_drv_data
*ddata
, u8 dcs_cmd
, u8
*data
)
145 struct omap_dss_device
*in
= ddata
->in
;
149 r
= in
->ops
.dsi
->dcs_read(in
, ddata
->channel
, dcs_cmd
, buf
, 1);
159 static int dsicm_dcs_write_0(struct panel_drv_data
*ddata
, u8 dcs_cmd
)
161 struct omap_dss_device
*in
= ddata
->in
;
162 return in
->ops
.dsi
->dcs_write(in
, 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
*in
= ddata
->in
;
168 u8 buf
[2] = { dcs_cmd
, param
};
170 return in
->ops
.dsi
->dcs_write(in
, ddata
->channel
, buf
, 2);
173 static int dsicm_sleep_in(struct panel_drv_data
*ddata
)
176 struct omap_dss_device
*in
= ddata
->in
;
180 hw_guard_wait(ddata
);
182 cmd
= MIPI_DCS_ENTER_SLEEP_MODE
;
183 r
= in
->ops
.dsi
->dcs_write_nosync(in
, 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
*in
= ddata
->in
;
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
= in
->ops
.dsi
->dcs_write_nosync(in
, 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
= in
->ops
.dsi
->dcs_write_nosync(in
, ddata
->channel
, buf
, sizeof(buf
));
259 in
->ops
.dsi
->bta_sync(in
, 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
*in
= ddata
->in
;
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 in
->ops
.dsi
->disable(in
, 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
*in
= ddata
->in
;
315 if (!ddata
->ulps_enabled
)
318 r
= in
->ops
.dsi
->enable(in
);
320 dev_err(&ddata
->pdev
->dev
, "failed to enable DSI\n");
324 in
->ops
.dsi
->enable_hs(in
, ddata
->channel
, true);
326 r
= _dsicm_enable_te(ddata
, true);
328 dev_err(&ddata
->pdev
->dev
, "failed to re-enable TE");
332 if (ddata
->ext_te_gpio
)
333 enable_irq(gpiod_to_irq(ddata
->ext_te_gpio
));
335 dsicm_queue_ulps_work(ddata
);
337 ddata
->ulps_enabled
= false;
342 dev_err(&ddata
->pdev
->dev
, "failed to exit ULPS");
344 r
= dsicm_panel_reset(ddata
);
346 if (ddata
->ext_te_gpio
)
347 enable_irq(gpiod_to_irq(ddata
->ext_te_gpio
));
348 ddata
->ulps_enabled
= false;
351 dsicm_queue_ulps_work(ddata
);
356 static int dsicm_wake_up(struct panel_drv_data
*ddata
)
358 if (ddata
->ulps_enabled
)
359 return dsicm_exit_ulps(ddata
);
361 dsicm_cancel_ulps_work(ddata
);
362 dsicm_queue_ulps_work(ddata
);
366 static int dsicm_bl_update_status(struct backlight_device
*dev
)
368 struct panel_drv_data
*ddata
= dev_get_drvdata(&dev
->dev
);
369 struct omap_dss_device
*in
= ddata
->in
;
373 if (dev
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
374 dev
->props
.power
== FB_BLANK_UNBLANK
)
375 level
= dev
->props
.brightness
;
379 dev_dbg(&ddata
->pdev
->dev
, "update brightness to %d\n", level
);
381 mutex_lock(&ddata
->lock
);
383 if (ddata
->enabled
) {
384 in
->ops
.dsi
->bus_lock(in
);
386 r
= dsicm_wake_up(ddata
);
388 r
= dsicm_dcs_write_1(ddata
, DCS_BRIGHTNESS
, level
);
390 in
->ops
.dsi
->bus_unlock(in
);
393 mutex_unlock(&ddata
->lock
);
398 static int dsicm_bl_get_intensity(struct backlight_device
*dev
)
400 if (dev
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
401 dev
->props
.power
== FB_BLANK_UNBLANK
)
402 return dev
->props
.brightness
;
407 static const struct backlight_ops dsicm_bl_ops
= {
408 .get_brightness
= dsicm_bl_get_intensity
,
409 .update_status
= dsicm_bl_update_status
,
412 static ssize_t
dsicm_num_errors_show(struct device
*dev
,
413 struct device_attribute
*attr
, char *buf
)
415 struct platform_device
*pdev
= to_platform_device(dev
);
416 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
417 struct omap_dss_device
*in
= ddata
->in
;
421 mutex_lock(&ddata
->lock
);
423 if (ddata
->enabled
) {
424 in
->ops
.dsi
->bus_lock(in
);
426 r
= dsicm_wake_up(ddata
);
428 r
= dsicm_dcs_read_1(ddata
, DCS_READ_NUM_ERRORS
,
431 in
->ops
.dsi
->bus_unlock(in
);
436 mutex_unlock(&ddata
->lock
);
441 return snprintf(buf
, PAGE_SIZE
, "%d\n", errors
);
444 static ssize_t
dsicm_hw_revision_show(struct device
*dev
,
445 struct device_attribute
*attr
, char *buf
)
447 struct platform_device
*pdev
= to_platform_device(dev
);
448 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
449 struct omap_dss_device
*in
= ddata
->in
;
453 mutex_lock(&ddata
->lock
);
455 if (ddata
->enabled
) {
456 in
->ops
.dsi
->bus_lock(in
);
458 r
= dsicm_wake_up(ddata
);
460 r
= dsicm_get_id(ddata
, &id1
, &id2
, &id3
);
462 in
->ops
.dsi
->bus_unlock(in
);
467 mutex_unlock(&ddata
->lock
);
472 return snprintf(buf
, PAGE_SIZE
, "%02x.%02x.%02x\n", id1
, id2
, id3
);
475 static ssize_t
dsicm_store_ulps(struct device
*dev
,
476 struct device_attribute
*attr
,
477 const char *buf
, size_t count
)
479 struct platform_device
*pdev
= to_platform_device(dev
);
480 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
481 struct omap_dss_device
*in
= ddata
->in
;
485 r
= kstrtoul(buf
, 0, &t
);
489 mutex_lock(&ddata
->lock
);
491 if (ddata
->enabled
) {
492 in
->ops
.dsi
->bus_lock(in
);
495 r
= dsicm_enter_ulps(ddata
);
497 r
= dsicm_wake_up(ddata
);
499 in
->ops
.dsi
->bus_unlock(in
);
502 mutex_unlock(&ddata
->lock
);
510 static ssize_t
dsicm_show_ulps(struct device
*dev
,
511 struct device_attribute
*attr
,
514 struct platform_device
*pdev
= to_platform_device(dev
);
515 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
518 mutex_lock(&ddata
->lock
);
519 t
= ddata
->ulps_enabled
;
520 mutex_unlock(&ddata
->lock
);
522 return snprintf(buf
, PAGE_SIZE
, "%u\n", t
);
525 static ssize_t
dsicm_store_ulps_timeout(struct device
*dev
,
526 struct device_attribute
*attr
,
527 const char *buf
, size_t count
)
529 struct platform_device
*pdev
= to_platform_device(dev
);
530 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
531 struct omap_dss_device
*in
= ddata
->in
;
535 r
= kstrtoul(buf
, 0, &t
);
539 mutex_lock(&ddata
->lock
);
540 ddata
->ulps_timeout
= t
;
542 if (ddata
->enabled
) {
543 /* dsicm_wake_up will restart the timer */
544 in
->ops
.dsi
->bus_lock(in
);
545 r
= dsicm_wake_up(ddata
);
546 in
->ops
.dsi
->bus_unlock(in
);
549 mutex_unlock(&ddata
->lock
);
557 static ssize_t
dsicm_show_ulps_timeout(struct device
*dev
,
558 struct device_attribute
*attr
,
561 struct platform_device
*pdev
= to_platform_device(dev
);
562 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
565 mutex_lock(&ddata
->lock
);
566 t
= ddata
->ulps_timeout
;
567 mutex_unlock(&ddata
->lock
);
569 return snprintf(buf
, PAGE_SIZE
, "%u\n", t
);
572 static DEVICE_ATTR(num_dsi_errors
, S_IRUGO
, dsicm_num_errors_show
, NULL
);
573 static DEVICE_ATTR(hw_revision
, S_IRUGO
, dsicm_hw_revision_show
, NULL
);
574 static DEVICE_ATTR(ulps
, S_IRUGO
| S_IWUSR
,
575 dsicm_show_ulps
, dsicm_store_ulps
);
576 static DEVICE_ATTR(ulps_timeout
, S_IRUGO
| S_IWUSR
,
577 dsicm_show_ulps_timeout
, dsicm_store_ulps_timeout
);
579 static struct attribute
*dsicm_attrs
[] = {
580 &dev_attr_num_dsi_errors
.attr
,
581 &dev_attr_hw_revision
.attr
,
583 &dev_attr_ulps_timeout
.attr
,
587 static const struct attribute_group dsicm_attr_group
= {
588 .attrs
= dsicm_attrs
,
591 static void dsicm_hw_reset(struct panel_drv_data
*ddata
)
593 gpiod_set_value(ddata
->reset_gpio
, 1);
595 /* reset the panel */
596 gpiod_set_value(ddata
->reset_gpio
, 0);
599 gpiod_set_value(ddata
->reset_gpio
, 1);
600 /* wait after releasing reset */
601 usleep_range(5000, 10000);
604 static int dsicm_power_on(struct panel_drv_data
*ddata
)
606 struct omap_dss_device
*in
= ddata
->in
;
609 struct omap_dss_dsi_config dsi_config
= {
610 .mode
= OMAP_DSS_DSI_CMD_MODE
,
611 .pixel_format
= OMAP_DSS_DSI_FMT_RGB888
,
613 .hs_clk_min
= 150000000,
614 .hs_clk_max
= 300000000,
615 .lp_clk_min
= 7000000,
616 .lp_clk_max
= 10000000,
620 r
= regulator_enable(ddata
->vpnl
);
622 dev_err(&ddata
->pdev
->dev
,
623 "failed to enable VPNL: %d\n", r
);
629 r
= regulator_enable(ddata
->vddi
);
631 dev_err(&ddata
->pdev
->dev
,
632 "failed to enable VDDI: %d\n", r
);
637 if (ddata
->pin_config
.num_pins
> 0) {
638 r
= in
->ops
.dsi
->configure_pins(in
, &ddata
->pin_config
);
640 dev_err(&ddata
->pdev
->dev
,
641 "failed to configure DSI pins\n");
646 r
= in
->ops
.dsi
->set_config(in
, &dsi_config
);
648 dev_err(&ddata
->pdev
->dev
, "failed to configure DSI\n");
652 r
= in
->ops
.dsi
->enable(in
);
654 dev_err(&ddata
->pdev
->dev
, "failed to enable DSI\n");
658 dsicm_hw_reset(ddata
);
660 in
->ops
.dsi
->enable_hs(in
, ddata
->channel
, false);
662 r
= dsicm_sleep_out(ddata
);
666 r
= dsicm_get_id(ddata
, &id1
, &id2
, &id3
);
670 r
= dsicm_dcs_write_1(ddata
, DCS_BRIGHTNESS
, 0xff);
674 r
= dsicm_dcs_write_1(ddata
, DCS_CTRL_DISPLAY
,
675 (1<<2) | (1<<5)); /* BL | BCTRL */
679 r
= dsicm_dcs_write_1(ddata
, MIPI_DCS_SET_PIXEL_FORMAT
,
680 MIPI_DCS_PIXEL_FMT_24BIT
);
684 r
= dsicm_dcs_write_0(ddata
, MIPI_DCS_SET_DISPLAY_ON
);
688 r
= _dsicm_enable_te(ddata
, ddata
->te_enabled
);
692 r
= in
->ops
.dsi
->enable_video_output(in
, ddata
->channel
);
698 if (!ddata
->intro_printed
) {
699 dev_info(&ddata
->pdev
->dev
, "panel revision %02x.%02x.%02x\n",
701 ddata
->intro_printed
= true;
704 in
->ops
.dsi
->enable_hs(in
, ddata
->channel
, true);
708 dev_err(&ddata
->pdev
->dev
, "error while enabling panel, issuing HW reset\n");
710 dsicm_hw_reset(ddata
);
712 in
->ops
.dsi
->disable(in
, true, false);
715 regulator_disable(ddata
->vddi
);
718 regulator_disable(ddata
->vpnl
);
723 static void dsicm_power_off(struct panel_drv_data
*ddata
)
725 struct omap_dss_device
*in
= ddata
->in
;
728 in
->ops
.dsi
->disable_video_output(in
, ddata
->channel
);
730 r
= dsicm_dcs_write_0(ddata
, MIPI_DCS_SET_DISPLAY_OFF
);
732 r
= dsicm_sleep_in(ddata
);
735 dev_err(&ddata
->pdev
->dev
,
736 "error disabling panel, issuing HW reset\n");
737 dsicm_hw_reset(ddata
);
740 in
->ops
.dsi
->disable(in
, true, false);
743 regulator_disable(ddata
->vddi
);
745 regulator_disable(ddata
->vpnl
);
750 static int dsicm_panel_reset(struct panel_drv_data
*ddata
)
752 dev_err(&ddata
->pdev
->dev
, "performing LCD reset\n");
754 dsicm_power_off(ddata
);
755 dsicm_hw_reset(ddata
);
756 return dsicm_power_on(ddata
);
759 static int dsicm_connect(struct omap_dss_device
*dssdev
)
761 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
762 struct omap_dss_device
*in
= ddata
->in
;
763 struct device
*dev
= &ddata
->pdev
->dev
;
766 if (omapdss_device_is_connected(dssdev
))
769 r
= in
->ops
.dsi
->connect(in
, dssdev
);
771 dev_err(dev
, "Failed to connect to video source\n");
775 r
= in
->ops
.dsi
->request_vc(ddata
->in
, &ddata
->channel
);
777 dev_err(dev
, "failed to get virtual channel\n");
781 r
= in
->ops
.dsi
->set_vc_id(ddata
->in
, ddata
->channel
, TCH
);
783 dev_err(dev
, "failed to set VC_ID\n");
790 in
->ops
.dsi
->release_vc(ddata
->in
, ddata
->channel
);
792 in
->ops
.dsi
->disconnect(in
, dssdev
);
796 static void dsicm_disconnect(struct omap_dss_device
*dssdev
)
798 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
799 struct omap_dss_device
*in
= ddata
->in
;
801 if (!omapdss_device_is_connected(dssdev
))
804 in
->ops
.dsi
->release_vc(in
, ddata
->channel
);
805 in
->ops
.dsi
->disconnect(in
, dssdev
);
808 static int dsicm_enable(struct omap_dss_device
*dssdev
)
810 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
811 struct omap_dss_device
*in
= ddata
->in
;
814 dev_dbg(&ddata
->pdev
->dev
, "enable\n");
816 mutex_lock(&ddata
->lock
);
818 if (!omapdss_device_is_connected(dssdev
)) {
823 if (omapdss_device_is_enabled(dssdev
)) {
828 in
->ops
.dsi
->bus_lock(in
);
830 r
= dsicm_power_on(ddata
);
832 in
->ops
.dsi
->bus_unlock(in
);
837 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
839 mutex_unlock(&ddata
->lock
);
841 dsicm_bl_power(ddata
, true);
845 dev_dbg(&ddata
->pdev
->dev
, "enable failed\n");
846 mutex_unlock(&ddata
->lock
);
850 static void dsicm_disable(struct omap_dss_device
*dssdev
)
852 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
853 struct omap_dss_device
*in
= ddata
->in
;
856 dev_dbg(&ddata
->pdev
->dev
, "disable\n");
858 dsicm_bl_power(ddata
, false);
860 mutex_lock(&ddata
->lock
);
862 dsicm_cancel_ulps_work(ddata
);
864 in
->ops
.dsi
->bus_lock(in
);
866 if (omapdss_device_is_enabled(dssdev
)) {
867 r
= dsicm_wake_up(ddata
);
869 dsicm_power_off(ddata
);
872 in
->ops
.dsi
->bus_unlock(in
);
874 dssdev
->state
= OMAP_DSS_DISPLAY_DISABLED
;
876 mutex_unlock(&ddata
->lock
);
879 static void dsicm_framedone_cb(int err
, void *data
)
881 struct panel_drv_data
*ddata
= data
;
882 struct omap_dss_device
*in
= ddata
->in
;
884 dev_dbg(&ddata
->pdev
->dev
, "framedone, err %d\n", err
);
885 in
->ops
.dsi
->bus_unlock(ddata
->in
);
888 static irqreturn_t
dsicm_te_isr(int irq
, void *data
)
890 struct panel_drv_data
*ddata
= data
;
891 struct omap_dss_device
*in
= ddata
->in
;
895 old
= atomic_cmpxchg(&ddata
->do_update
, 1, 0);
898 cancel_delayed_work(&ddata
->te_timeout_work
);
900 r
= in
->ops
.dsi
->update(in
, ddata
->channel
, dsicm_framedone_cb
,
908 dev_err(&ddata
->pdev
->dev
, "start update failed\n");
909 in
->ops
.dsi
->bus_unlock(in
);
913 static void dsicm_te_timeout_work_callback(struct work_struct
*work
)
915 struct panel_drv_data
*ddata
= container_of(work
, struct panel_drv_data
,
916 te_timeout_work
.work
);
917 struct omap_dss_device
*in
= ddata
->in
;
919 dev_err(&ddata
->pdev
->dev
, "TE not received for 250ms!\n");
921 atomic_set(&ddata
->do_update
, 0);
922 in
->ops
.dsi
->bus_unlock(in
);
925 static int dsicm_update(struct omap_dss_device
*dssdev
,
926 u16 x
, u16 y
, u16 w
, u16 h
)
928 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
929 struct omap_dss_device
*in
= ddata
->in
;
932 dev_dbg(&ddata
->pdev
->dev
, "update %d, %d, %d x %d\n", x
, y
, w
, h
);
934 mutex_lock(&ddata
->lock
);
935 in
->ops
.dsi
->bus_lock(in
);
937 r
= dsicm_wake_up(ddata
);
941 if (!ddata
->enabled
) {
946 /* XXX no need to send this every frame, but dsi break if not done */
947 r
= dsicm_set_update_window(ddata
, 0, 0,
948 dssdev
->panel
.vm
.hactive
,
949 dssdev
->panel
.vm
.vactive
);
953 if (ddata
->te_enabled
&& ddata
->ext_te_gpio
) {
954 schedule_delayed_work(&ddata
->te_timeout_work
,
955 msecs_to_jiffies(250));
956 atomic_set(&ddata
->do_update
, 1);
958 r
= in
->ops
.dsi
->update(in
, ddata
->channel
, dsicm_framedone_cb
,
964 /* note: no bus_unlock here. unlock is in framedone_cb */
965 mutex_unlock(&ddata
->lock
);
968 in
->ops
.dsi
->bus_unlock(in
);
969 mutex_unlock(&ddata
->lock
);
973 static int dsicm_sync(struct omap_dss_device
*dssdev
)
975 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
976 struct omap_dss_device
*in
= ddata
->in
;
978 dev_dbg(&ddata
->pdev
->dev
, "sync\n");
980 mutex_lock(&ddata
->lock
);
981 in
->ops
.dsi
->bus_lock(in
);
982 in
->ops
.dsi
->bus_unlock(in
);
983 mutex_unlock(&ddata
->lock
);
985 dev_dbg(&ddata
->pdev
->dev
, "sync done\n");
990 static int _dsicm_enable_te(struct panel_drv_data
*ddata
, bool enable
)
992 struct omap_dss_device
*in
= ddata
->in
;
996 r
= dsicm_dcs_write_1(ddata
, MIPI_DCS_SET_TEAR_ON
, 0);
998 r
= dsicm_dcs_write_0(ddata
, MIPI_DCS_SET_TEAR_OFF
);
1000 if (!ddata
->ext_te_gpio
)
1001 in
->ops
.dsi
->enable_te(in
, enable
);
1003 /* possible panel bug */
1009 static int dsicm_enable_te(struct omap_dss_device
*dssdev
, bool enable
)
1011 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
1012 struct omap_dss_device
*in
= ddata
->in
;
1015 mutex_lock(&ddata
->lock
);
1017 if (ddata
->te_enabled
== enable
)
1020 in
->ops
.dsi
->bus_lock(in
);
1022 if (ddata
->enabled
) {
1023 r
= dsicm_wake_up(ddata
);
1027 r
= _dsicm_enable_te(ddata
, enable
);
1032 ddata
->te_enabled
= enable
;
1034 in
->ops
.dsi
->bus_unlock(in
);
1036 mutex_unlock(&ddata
->lock
);
1040 in
->ops
.dsi
->bus_unlock(in
);
1041 mutex_unlock(&ddata
->lock
);
1046 static int dsicm_get_te(struct omap_dss_device
*dssdev
)
1048 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
1051 mutex_lock(&ddata
->lock
);
1052 r
= ddata
->te_enabled
;
1053 mutex_unlock(&ddata
->lock
);
1058 static int dsicm_memory_read(struct omap_dss_device
*dssdev
,
1059 void *buf
, size_t size
,
1060 u16 x
, u16 y
, u16 w
, u16 h
)
1062 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
1063 struct omap_dss_device
*in
= ddata
->in
;
1067 unsigned buf_used
= 0;
1069 if (size
< w
* h
* 3)
1072 mutex_lock(&ddata
->lock
);
1074 if (!ddata
->enabled
) {
1079 size
= min((u32
)w
* h
* 3,
1080 dssdev
->panel
.vm
.hactive
* dssdev
->panel
.vm
.vactive
* 3);
1082 in
->ops
.dsi
->bus_lock(in
);
1084 r
= dsicm_wake_up(ddata
);
1088 /* plen 1 or 2 goes into short packet. until checksum error is fixed,
1089 * use short packets. plen 32 works, but bigger packets seem to cause
1096 dsicm_set_update_window(ddata
, x
, y
, w
, h
);
1098 r
= in
->ops
.dsi
->set_max_rx_packet_size(in
, ddata
->channel
, plen
);
1102 while (buf_used
< size
) {
1103 u8 dcs_cmd
= first
? 0x2e : 0x3e;
1106 r
= in
->ops
.dsi
->dcs_read(in
, ddata
->channel
, dcs_cmd
,
1107 buf
+ buf_used
, size
- buf_used
);
1110 dev_err(dssdev
->dev
, "read error\n");
1117 dev_err(&ddata
->pdev
->dev
, "short read\n");
1121 if (signal_pending(current
)) {
1122 dev_err(&ddata
->pdev
->dev
, "signal pending, "
1123 "aborting memory read\n");
1132 in
->ops
.dsi
->set_max_rx_packet_size(in
, ddata
->channel
, 1);
1134 in
->ops
.dsi
->bus_unlock(in
);
1136 mutex_unlock(&ddata
->lock
);
1140 static void dsicm_ulps_work(struct work_struct
*work
)
1142 struct panel_drv_data
*ddata
= container_of(work
, struct panel_drv_data
,
1144 struct omap_dss_device
*dssdev
= &ddata
->dssdev
;
1145 struct omap_dss_device
*in
= ddata
->in
;
1147 mutex_lock(&ddata
->lock
);
1149 if (dssdev
->state
!= OMAP_DSS_DISPLAY_ACTIVE
|| !ddata
->enabled
) {
1150 mutex_unlock(&ddata
->lock
);
1154 in
->ops
.dsi
->bus_lock(in
);
1156 dsicm_enter_ulps(ddata
);
1158 in
->ops
.dsi
->bus_unlock(in
);
1159 mutex_unlock(&ddata
->lock
);
1162 static void dsicm_get_timings(struct omap_dss_device
*dssdev
,
1163 struct videomode
*vm
)
1165 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
1170 static int dsicm_check_timings(struct omap_dss_device
*dssdev
,
1171 struct videomode
*vm
)
1173 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
1176 if (vm
->hactive
!= ddata
->vm
.hactive
)
1179 if (vm
->vactive
!= ddata
->vm
.vactive
)
1183 dev_warn(dssdev
->dev
, "wrong resolution: %d x %d",
1184 vm
->hactive
, vm
->vactive
);
1185 dev_warn(dssdev
->dev
, "panel resolution: %d x %d",
1186 ddata
->vm
.hactive
, ddata
->vm
.vactive
);
1192 static void dsicm_get_size(struct omap_dss_device
*dssdev
,
1193 unsigned int *width
, unsigned int *height
)
1195 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
1197 *width
= ddata
->width_mm
;
1198 *height
= ddata
->height_mm
;
1201 static struct omap_dss_driver dsicm_ops
= {
1202 .connect
= dsicm_connect
,
1203 .disconnect
= dsicm_disconnect
,
1205 .enable
= dsicm_enable
,
1206 .disable
= dsicm_disable
,
1208 .update
= dsicm_update
,
1211 .get_timings
= dsicm_get_timings
,
1212 .check_timings
= dsicm_check_timings
,
1213 .get_size
= dsicm_get_size
,
1215 .enable_te
= dsicm_enable_te
,
1216 .get_te
= dsicm_get_te
,
1218 .memory_read
= dsicm_memory_read
,
1221 static int dsicm_probe_of(struct platform_device
*pdev
)
1223 struct device_node
*node
= pdev
->dev
.of_node
;
1224 struct device_node
*backlight
;
1225 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
1226 struct omap_dss_device
*in
;
1227 struct display_timing timing
;
1230 ddata
->reset_gpio
= devm_gpiod_get(&pdev
->dev
, "reset", GPIOD_OUT_LOW
);
1231 if (IS_ERR(ddata
->reset_gpio
)) {
1232 err
= PTR_ERR(ddata
->reset_gpio
);
1233 dev_err(&pdev
->dev
, "reset gpio request failed: %d", err
);
1237 ddata
->ext_te_gpio
= devm_gpiod_get_optional(&pdev
->dev
, "te",
1239 if (IS_ERR(ddata
->ext_te_gpio
)) {
1240 err
= PTR_ERR(ddata
->ext_te_gpio
);
1241 dev_err(&pdev
->dev
, "TE gpio request failed: %d", err
);
1245 err
= of_get_display_timing(node
, "panel-timing", &timing
);
1247 videomode_from_timing(&timing
, &ddata
->vm
);
1248 if (!ddata
->vm
.pixelclock
)
1249 ddata
->vm
.pixelclock
=
1250 ddata
->vm
.hactive
* ddata
->vm
.vactive
* 60;
1252 dev_warn(&pdev
->dev
,
1253 "failed to get video timing, using defaults\n");
1256 ddata
->width_mm
= 0;
1257 of_property_read_u32(node
, "width-mm", &ddata
->width_mm
);
1259 ddata
->height_mm
= 0;
1260 of_property_read_u32(node
, "height-mm", &ddata
->height_mm
);
1262 in
= omapdss_of_find_source_for_first_ep(node
);
1264 dev_err(&pdev
->dev
, "failed to find video source\n");
1268 ddata
->vpnl
= devm_regulator_get_optional(&pdev
->dev
, "vpnl");
1269 if (IS_ERR(ddata
->vpnl
)) {
1270 err
= PTR_ERR(ddata
->vpnl
);
1271 if (err
== -EPROBE_DEFER
)
1276 ddata
->vddi
= devm_regulator_get_optional(&pdev
->dev
, "vddi");
1277 if (IS_ERR(ddata
->vddi
)) {
1278 err
= PTR_ERR(ddata
->vddi
);
1279 if (err
== -EPROBE_DEFER
)
1286 backlight
= of_parse_phandle(node
, "backlight", 0);
1288 ddata
->extbldev
= of_find_backlight_by_node(backlight
);
1289 of_node_put(backlight
);
1291 if (!ddata
->extbldev
)
1292 return -EPROBE_DEFER
;
1294 /* assume native backlight support */
1295 ddata
->use_dsi_backlight
= true;
1303 static int dsicm_probe(struct platform_device
*pdev
)
1305 struct panel_drv_data
*ddata
;
1306 struct backlight_device
*bldev
= NULL
;
1307 struct device
*dev
= &pdev
->dev
;
1308 struct omap_dss_device
*dssdev
;
1311 dev_dbg(dev
, "probe\n");
1313 ddata
= devm_kzalloc(dev
, sizeof(*ddata
), GFP_KERNEL
);
1317 platform_set_drvdata(pdev
, ddata
);
1320 if (!pdev
->dev
.of_node
)
1323 ddata
->vm
.hactive
= 864;
1324 ddata
->vm
.vactive
= 480;
1325 ddata
->vm
.pixelclock
= 864 * 480 * 60;
1327 r
= dsicm_probe_of(pdev
);
1331 dssdev
= &ddata
->dssdev
;
1333 dssdev
->driver
= &dsicm_ops
;
1334 dssdev
->panel
.vm
= ddata
->vm
;
1335 dssdev
->type
= OMAP_DISPLAY_TYPE_DSI
;
1336 dssdev
->owner
= THIS_MODULE
;
1338 dssdev
->panel
.dsi_pix_fmt
= OMAP_DSS_DSI_FMT_RGB888
;
1339 dssdev
->caps
= OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE
|
1340 OMAP_DSS_DISPLAY_CAP_TEAR_ELIM
;
1342 r
= omapdss_register_display(dssdev
);
1344 dev_err(dev
, "Failed to register panel\n");
1348 mutex_init(&ddata
->lock
);
1350 atomic_set(&ddata
->do_update
, 0);
1352 if (ddata
->ext_te_gpio
) {
1353 r
= devm_request_irq(dev
, gpiod_to_irq(ddata
->ext_te_gpio
),
1355 IRQF_TRIGGER_RISING
,
1356 "taal vsync", ddata
);
1359 dev_err(dev
, "IRQ request failed\n");
1363 INIT_DEFERRABLE_WORK(&ddata
->te_timeout_work
,
1364 dsicm_te_timeout_work_callback
);
1366 dev_dbg(dev
, "Using GPIO TE\n");
1369 ddata
->workqueue
= create_singlethread_workqueue("dsicm_wq");
1370 if (!ddata
->workqueue
) {
1374 INIT_DELAYED_WORK(&ddata
->ulps_work
, dsicm_ulps_work
);
1376 dsicm_hw_reset(ddata
);
1378 if (ddata
->use_dsi_backlight
) {
1379 struct backlight_properties props
= { 0 };
1380 props
.max_brightness
= 255;
1381 props
.type
= BACKLIGHT_RAW
;
1383 bldev
= devm_backlight_device_register(dev
, dev_name(dev
),
1384 dev
, ddata
, &dsicm_bl_ops
, &props
);
1385 if (IS_ERR(bldev
)) {
1390 ddata
->bldev
= bldev
;
1393 r
= sysfs_create_group(&dev
->kobj
, &dsicm_attr_group
);
1395 dev_err(dev
, "failed to create sysfs files\n");
1402 destroy_workqueue(ddata
->workqueue
);
1404 if (ddata
->extbldev
)
1405 put_device(&ddata
->extbldev
->dev
);
1410 static int __exit
dsicm_remove(struct platform_device
*pdev
)
1412 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
1413 struct omap_dss_device
*dssdev
= &ddata
->dssdev
;
1415 dev_dbg(&pdev
->dev
, "remove\n");
1417 omapdss_unregister_display(dssdev
);
1419 dsicm_disable(dssdev
);
1420 dsicm_disconnect(dssdev
);
1422 sysfs_remove_group(&pdev
->dev
.kobj
, &dsicm_attr_group
);
1424 if (ddata
->extbldev
)
1425 put_device(&ddata
->extbldev
->dev
);
1427 omap_dss_put_device(ddata
->in
);
1429 dsicm_cancel_ulps_work(ddata
);
1430 destroy_workqueue(ddata
->workqueue
);
1432 /* reset, to be sure that the panel is in a valid state */
1433 dsicm_hw_reset(ddata
);
1438 static const struct of_device_id dsicm_of_match
[] = {
1439 { .compatible
= "omapdss,panel-dsi-cm", },
1443 MODULE_DEVICE_TABLE(of
, dsicm_of_match
);
1445 static struct platform_driver dsicm_driver
= {
1446 .probe
= dsicm_probe
,
1447 .remove
= __exit_p(dsicm_remove
),
1449 .name
= "panel-dsi-cm",
1450 .of_match_table
= dsicm_of_match
,
1451 .suppress_bind_attrs
= true,
1455 module_platform_driver(dsicm_driver
);
1457 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
1458 MODULE_DESCRIPTION("Generic DSI Command Mode Panel Driver");
1459 MODULE_LICENSE("GPL");