2 * Generic DSI Command Mode panel driver
4 * Copyright (C) 2013 Texas Instruments
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>
17 #include <linux/gpio.h>
18 #include <linux/interrupt.h>
19 #include <linux/jiffies.h>
20 #include <linux/module.h>
21 #include <linux/platform_device.h>
22 #include <linux/sched.h>
23 #include <linux/slab.h>
24 #include <linux/workqueue.h>
25 #include <linux/of_device.h>
26 #include <linux/of_gpio.h>
28 #include <video/omapdss.h>
29 #include <video/omap-panel-data.h>
30 #include <video/mipi_display.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
;
46 struct omap_video_timings timings
;
48 struct platform_device
*pdev
;
52 struct backlight_device
*bldev
;
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 */
63 bool use_dsi_backlight
;
65 struct omap_dsi_pin_config pin_config
;
67 /* runtime variables */
75 struct delayed_work te_timeout_work
;
79 struct workqueue_struct
*workqueue
;
82 unsigned ulps_timeout
;
83 struct delayed_work ulps_work
;
86 #define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
88 static irqreturn_t
dsicm_te_isr(int irq
, void *data
);
89 static void dsicm_te_timeout_work_callback(struct work_struct
*work
);
90 static int _dsicm_enable_te(struct panel_drv_data
*ddata
, bool enable
);
92 static int dsicm_panel_reset(struct panel_drv_data
*ddata
);
94 static void dsicm_ulps_work(struct work_struct
*work
);
96 static void hw_guard_start(struct panel_drv_data
*ddata
, int guard_msec
)
98 ddata
->hw_guard_wait
= msecs_to_jiffies(guard_msec
);
99 ddata
->hw_guard_end
= jiffies
+ ddata
->hw_guard_wait
;
102 static void hw_guard_wait(struct panel_drv_data
*ddata
)
104 unsigned long wait
= ddata
->hw_guard_end
- jiffies
;
106 if ((long)wait
> 0 && wait
<= ddata
->hw_guard_wait
) {
107 set_current_state(TASK_UNINTERRUPTIBLE
);
108 schedule_timeout(wait
);
112 static int dsicm_dcs_read_1(struct panel_drv_data
*ddata
, u8 dcs_cmd
, u8
*data
)
114 struct omap_dss_device
*in
= ddata
->in
;
118 r
= in
->ops
.dsi
->dcs_read(in
, ddata
->channel
, dcs_cmd
, buf
, 1);
128 static int dsicm_dcs_write_0(struct panel_drv_data
*ddata
, u8 dcs_cmd
)
130 struct omap_dss_device
*in
= ddata
->in
;
131 return in
->ops
.dsi
->dcs_write(in
, ddata
->channel
, &dcs_cmd
, 1);
134 static int dsicm_dcs_write_1(struct panel_drv_data
*ddata
, u8 dcs_cmd
, u8 param
)
136 struct omap_dss_device
*in
= ddata
->in
;
137 u8 buf
[2] = { dcs_cmd
, param
};
139 return in
->ops
.dsi
->dcs_write(in
, ddata
->channel
, buf
, 2);
142 static int dsicm_sleep_in(struct panel_drv_data
*ddata
)
145 struct omap_dss_device
*in
= ddata
->in
;
149 hw_guard_wait(ddata
);
151 cmd
= MIPI_DCS_ENTER_SLEEP_MODE
;
152 r
= in
->ops
.dsi
->dcs_write_nosync(in
, ddata
->channel
, &cmd
, 1);
156 hw_guard_start(ddata
, 120);
158 usleep_range(5000, 10000);
163 static int dsicm_sleep_out(struct panel_drv_data
*ddata
)
167 hw_guard_wait(ddata
);
169 r
= dsicm_dcs_write_0(ddata
, MIPI_DCS_EXIT_SLEEP_MODE
);
173 hw_guard_start(ddata
, 120);
175 usleep_range(5000, 10000);
180 static int dsicm_get_id(struct panel_drv_data
*ddata
, u8
*id1
, u8
*id2
, u8
*id3
)
184 r
= dsicm_dcs_read_1(ddata
, DCS_GET_ID1
, id1
);
187 r
= dsicm_dcs_read_1(ddata
, DCS_GET_ID2
, id2
);
190 r
= dsicm_dcs_read_1(ddata
, DCS_GET_ID3
, id3
);
197 static int dsicm_set_update_window(struct panel_drv_data
*ddata
,
198 u16 x
, u16 y
, u16 w
, u16 h
)
200 struct omap_dss_device
*in
= ddata
->in
;
208 buf
[0] = MIPI_DCS_SET_COLUMN_ADDRESS
;
209 buf
[1] = (x1
>> 8) & 0xff;
210 buf
[2] = (x1
>> 0) & 0xff;
211 buf
[3] = (x2
>> 8) & 0xff;
212 buf
[4] = (x2
>> 0) & 0xff;
214 r
= in
->ops
.dsi
->dcs_write_nosync(in
, ddata
->channel
, buf
, sizeof(buf
));
218 buf
[0] = MIPI_DCS_SET_PAGE_ADDRESS
;
219 buf
[1] = (y1
>> 8) & 0xff;
220 buf
[2] = (y1
>> 0) & 0xff;
221 buf
[3] = (y2
>> 8) & 0xff;
222 buf
[4] = (y2
>> 0) & 0xff;
224 r
= in
->ops
.dsi
->dcs_write_nosync(in
, ddata
->channel
, buf
, sizeof(buf
));
228 in
->ops
.dsi
->bta_sync(in
, ddata
->channel
);
233 static void dsicm_queue_ulps_work(struct panel_drv_data
*ddata
)
235 if (ddata
->ulps_timeout
> 0)
236 queue_delayed_work(ddata
->workqueue
, &ddata
->ulps_work
,
237 msecs_to_jiffies(ddata
->ulps_timeout
));
240 static void dsicm_cancel_ulps_work(struct panel_drv_data
*ddata
)
242 cancel_delayed_work(&ddata
->ulps_work
);
245 static int dsicm_enter_ulps(struct panel_drv_data
*ddata
)
247 struct omap_dss_device
*in
= ddata
->in
;
250 if (ddata
->ulps_enabled
)
253 dsicm_cancel_ulps_work(ddata
);
255 r
= _dsicm_enable_te(ddata
, false);
259 if (gpio_is_valid(ddata
->ext_te_gpio
))
260 disable_irq(gpio_to_irq(ddata
->ext_te_gpio
));
262 in
->ops
.dsi
->disable(in
, false, true);
264 ddata
->ulps_enabled
= true;
269 dev_err(&ddata
->pdev
->dev
, "enter ULPS failed");
270 dsicm_panel_reset(ddata
);
272 ddata
->ulps_enabled
= false;
274 dsicm_queue_ulps_work(ddata
);
279 static int dsicm_exit_ulps(struct panel_drv_data
*ddata
)
281 struct omap_dss_device
*in
= ddata
->in
;
284 if (!ddata
->ulps_enabled
)
287 r
= in
->ops
.dsi
->enable(in
);
289 dev_err(&ddata
->pdev
->dev
, "failed to enable DSI\n");
293 in
->ops
.dsi
->enable_hs(in
, ddata
->channel
, true);
295 r
= _dsicm_enable_te(ddata
, true);
297 dev_err(&ddata
->pdev
->dev
, "failed to re-enable TE");
301 if (gpio_is_valid(ddata
->ext_te_gpio
))
302 enable_irq(gpio_to_irq(ddata
->ext_te_gpio
));
304 dsicm_queue_ulps_work(ddata
);
306 ddata
->ulps_enabled
= false;
311 dev_err(&ddata
->pdev
->dev
, "failed to exit ULPS");
313 r
= dsicm_panel_reset(ddata
);
315 if (gpio_is_valid(ddata
->ext_te_gpio
))
316 enable_irq(gpio_to_irq(ddata
->ext_te_gpio
));
317 ddata
->ulps_enabled
= false;
320 dsicm_queue_ulps_work(ddata
);
325 static int dsicm_wake_up(struct panel_drv_data
*ddata
)
327 if (ddata
->ulps_enabled
)
328 return dsicm_exit_ulps(ddata
);
330 dsicm_cancel_ulps_work(ddata
);
331 dsicm_queue_ulps_work(ddata
);
335 static int dsicm_bl_update_status(struct backlight_device
*dev
)
337 struct panel_drv_data
*ddata
= dev_get_drvdata(&dev
->dev
);
338 struct omap_dss_device
*in
= ddata
->in
;
342 if (dev
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
343 dev
->props
.power
== FB_BLANK_UNBLANK
)
344 level
= dev
->props
.brightness
;
348 dev_dbg(&ddata
->pdev
->dev
, "update brightness to %d\n", level
);
350 mutex_lock(&ddata
->lock
);
352 if (ddata
->enabled
) {
353 in
->ops
.dsi
->bus_lock(in
);
355 r
= dsicm_wake_up(ddata
);
357 r
= dsicm_dcs_write_1(ddata
, DCS_BRIGHTNESS
, level
);
359 in
->ops
.dsi
->bus_unlock(in
);
364 mutex_unlock(&ddata
->lock
);
369 static int dsicm_bl_get_intensity(struct backlight_device
*dev
)
371 if (dev
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
372 dev
->props
.power
== FB_BLANK_UNBLANK
)
373 return dev
->props
.brightness
;
378 static const struct backlight_ops dsicm_bl_ops
= {
379 .get_brightness
= dsicm_bl_get_intensity
,
380 .update_status
= dsicm_bl_update_status
,
383 static void dsicm_get_resolution(struct omap_dss_device
*dssdev
,
384 u16
*xres
, u16
*yres
)
386 *xres
= dssdev
->panel
.timings
.x_res
;
387 *yres
= dssdev
->panel
.timings
.y_res
;
390 static ssize_t
dsicm_num_errors_show(struct device
*dev
,
391 struct device_attribute
*attr
, char *buf
)
393 struct platform_device
*pdev
= to_platform_device(dev
);
394 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
395 struct omap_dss_device
*in
= ddata
->in
;
399 mutex_lock(&ddata
->lock
);
401 if (ddata
->enabled
) {
402 in
->ops
.dsi
->bus_lock(in
);
404 r
= dsicm_wake_up(ddata
);
406 r
= dsicm_dcs_read_1(ddata
, DCS_READ_NUM_ERRORS
,
409 in
->ops
.dsi
->bus_unlock(in
);
414 mutex_unlock(&ddata
->lock
);
419 return snprintf(buf
, PAGE_SIZE
, "%d\n", errors
);
422 static ssize_t
dsicm_hw_revision_show(struct device
*dev
,
423 struct device_attribute
*attr
, char *buf
)
425 struct platform_device
*pdev
= to_platform_device(dev
);
426 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
427 struct omap_dss_device
*in
= ddata
->in
;
431 mutex_lock(&ddata
->lock
);
433 if (ddata
->enabled
) {
434 in
->ops
.dsi
->bus_lock(in
);
436 r
= dsicm_wake_up(ddata
);
438 r
= dsicm_get_id(ddata
, &id1
, &id2
, &id3
);
440 in
->ops
.dsi
->bus_unlock(in
);
445 mutex_unlock(&ddata
->lock
);
450 return snprintf(buf
, PAGE_SIZE
, "%02x.%02x.%02x\n", id1
, id2
, id3
);
453 static ssize_t
dsicm_store_ulps(struct device
*dev
,
454 struct device_attribute
*attr
,
455 const char *buf
, size_t count
)
457 struct platform_device
*pdev
= to_platform_device(dev
);
458 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
459 struct omap_dss_device
*in
= ddata
->in
;
463 r
= kstrtoul(buf
, 0, &t
);
467 mutex_lock(&ddata
->lock
);
469 if (ddata
->enabled
) {
470 in
->ops
.dsi
->bus_lock(in
);
473 r
= dsicm_enter_ulps(ddata
);
475 r
= dsicm_wake_up(ddata
);
477 in
->ops
.dsi
->bus_unlock(in
);
480 mutex_unlock(&ddata
->lock
);
488 static ssize_t
dsicm_show_ulps(struct device
*dev
,
489 struct device_attribute
*attr
,
492 struct platform_device
*pdev
= to_platform_device(dev
);
493 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
496 mutex_lock(&ddata
->lock
);
497 t
= ddata
->ulps_enabled
;
498 mutex_unlock(&ddata
->lock
);
500 return snprintf(buf
, PAGE_SIZE
, "%u\n", t
);
503 static ssize_t
dsicm_store_ulps_timeout(struct device
*dev
,
504 struct device_attribute
*attr
,
505 const char *buf
, size_t count
)
507 struct platform_device
*pdev
= to_platform_device(dev
);
508 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
509 struct omap_dss_device
*in
= ddata
->in
;
513 r
= kstrtoul(buf
, 0, &t
);
517 mutex_lock(&ddata
->lock
);
518 ddata
->ulps_timeout
= t
;
520 if (ddata
->enabled
) {
521 /* dsicm_wake_up will restart the timer */
522 in
->ops
.dsi
->bus_lock(in
);
523 r
= dsicm_wake_up(ddata
);
524 in
->ops
.dsi
->bus_unlock(in
);
527 mutex_unlock(&ddata
->lock
);
535 static ssize_t
dsicm_show_ulps_timeout(struct device
*dev
,
536 struct device_attribute
*attr
,
539 struct platform_device
*pdev
= to_platform_device(dev
);
540 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
543 mutex_lock(&ddata
->lock
);
544 t
= ddata
->ulps_timeout
;
545 mutex_unlock(&ddata
->lock
);
547 return snprintf(buf
, PAGE_SIZE
, "%u\n", t
);
550 static DEVICE_ATTR(num_dsi_errors
, S_IRUGO
, dsicm_num_errors_show
, NULL
);
551 static DEVICE_ATTR(hw_revision
, S_IRUGO
, dsicm_hw_revision_show
, NULL
);
552 static DEVICE_ATTR(ulps
, S_IRUGO
| S_IWUSR
,
553 dsicm_show_ulps
, dsicm_store_ulps
);
554 static DEVICE_ATTR(ulps_timeout
, S_IRUGO
| S_IWUSR
,
555 dsicm_show_ulps_timeout
, dsicm_store_ulps_timeout
);
557 static struct attribute
*dsicm_attrs
[] = {
558 &dev_attr_num_dsi_errors
.attr
,
559 &dev_attr_hw_revision
.attr
,
561 &dev_attr_ulps_timeout
.attr
,
565 static struct attribute_group dsicm_attr_group
= {
566 .attrs
= dsicm_attrs
,
569 static void dsicm_hw_reset(struct panel_drv_data
*ddata
)
571 if (!gpio_is_valid(ddata
->reset_gpio
))
574 gpio_set_value(ddata
->reset_gpio
, 1);
576 /* reset the panel */
577 gpio_set_value(ddata
->reset_gpio
, 0);
580 gpio_set_value(ddata
->reset_gpio
, 1);
581 /* wait after releasing reset */
582 usleep_range(5000, 10000);
585 static int dsicm_power_on(struct panel_drv_data
*ddata
)
587 struct omap_dss_device
*in
= ddata
->in
;
590 struct omap_dss_dsi_config dsi_config
= {
591 .mode
= OMAP_DSS_DSI_CMD_MODE
,
592 .pixel_format
= OMAP_DSS_DSI_FMT_RGB888
,
593 .timings
= &ddata
->timings
,
594 .hs_clk_min
= 150000000,
595 .hs_clk_max
= 300000000,
596 .lp_clk_min
= 7000000,
597 .lp_clk_max
= 10000000,
600 if (ddata
->pin_config
.num_pins
> 0) {
601 r
= in
->ops
.dsi
->configure_pins(in
, &ddata
->pin_config
);
603 dev_err(&ddata
->pdev
->dev
,
604 "failed to configure DSI pins\n");
609 r
= in
->ops
.dsi
->set_config(in
, &dsi_config
);
611 dev_err(&ddata
->pdev
->dev
, "failed to configure DSI\n");
615 r
= in
->ops
.dsi
->enable(in
);
617 dev_err(&ddata
->pdev
->dev
, "failed to enable DSI\n");
621 dsicm_hw_reset(ddata
);
623 in
->ops
.dsi
->enable_hs(in
, ddata
->channel
, false);
625 r
= dsicm_sleep_out(ddata
);
629 r
= dsicm_get_id(ddata
, &id1
, &id2
, &id3
);
633 r
= dsicm_dcs_write_1(ddata
, DCS_BRIGHTNESS
, 0xff);
637 r
= dsicm_dcs_write_1(ddata
, DCS_CTRL_DISPLAY
,
638 (1<<2) | (1<<5)); /* BL | BCTRL */
642 r
= dsicm_dcs_write_1(ddata
, MIPI_DCS_SET_PIXEL_FORMAT
,
643 MIPI_DCS_PIXEL_FMT_24BIT
);
647 r
= dsicm_dcs_write_0(ddata
, MIPI_DCS_SET_DISPLAY_ON
);
651 r
= _dsicm_enable_te(ddata
, ddata
->te_enabled
);
655 r
= in
->ops
.dsi
->enable_video_output(in
, ddata
->channel
);
661 if (!ddata
->intro_printed
) {
662 dev_info(&ddata
->pdev
->dev
, "panel revision %02x.%02x.%02x\n",
664 ddata
->intro_printed
= true;
667 in
->ops
.dsi
->enable_hs(in
, ddata
->channel
, true);
671 dev_err(&ddata
->pdev
->dev
, "error while enabling panel, issuing HW reset\n");
673 dsicm_hw_reset(ddata
);
675 in
->ops
.dsi
->disable(in
, true, false);
680 static void dsicm_power_off(struct panel_drv_data
*ddata
)
682 struct omap_dss_device
*in
= ddata
->in
;
685 in
->ops
.dsi
->disable_video_output(in
, ddata
->channel
);
687 r
= dsicm_dcs_write_0(ddata
, MIPI_DCS_SET_DISPLAY_OFF
);
689 r
= dsicm_sleep_in(ddata
);
692 dev_err(&ddata
->pdev
->dev
,
693 "error disabling panel, issuing HW reset\n");
694 dsicm_hw_reset(ddata
);
697 in
->ops
.dsi
->disable(in
, true, false);
702 static int dsicm_panel_reset(struct panel_drv_data
*ddata
)
704 dev_err(&ddata
->pdev
->dev
, "performing LCD reset\n");
706 dsicm_power_off(ddata
);
707 dsicm_hw_reset(ddata
);
708 return dsicm_power_on(ddata
);
711 static int dsicm_connect(struct omap_dss_device
*dssdev
)
713 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
714 struct omap_dss_device
*in
= ddata
->in
;
715 struct device
*dev
= &ddata
->pdev
->dev
;
718 if (omapdss_device_is_connected(dssdev
))
721 r
= in
->ops
.dsi
->connect(in
, dssdev
);
723 dev_err(dev
, "Failed to connect to video source\n");
727 r
= in
->ops
.dsi
->request_vc(ddata
->in
, &ddata
->channel
);
729 dev_err(dev
, "failed to get virtual channel\n");
733 r
= in
->ops
.dsi
->set_vc_id(ddata
->in
, ddata
->channel
, TCH
);
735 dev_err(dev
, "failed to set VC_ID\n");
742 in
->ops
.dsi
->release_vc(ddata
->in
, ddata
->channel
);
744 in
->ops
.dsi
->disconnect(in
, dssdev
);
748 static void dsicm_disconnect(struct omap_dss_device
*dssdev
)
750 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
751 struct omap_dss_device
*in
= ddata
->in
;
753 if (!omapdss_device_is_connected(dssdev
))
756 in
->ops
.dsi
->release_vc(in
, ddata
->channel
);
757 in
->ops
.dsi
->disconnect(in
, dssdev
);
760 static int dsicm_enable(struct omap_dss_device
*dssdev
)
762 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
763 struct omap_dss_device
*in
= ddata
->in
;
766 dev_dbg(&ddata
->pdev
->dev
, "enable\n");
768 mutex_lock(&ddata
->lock
);
770 if (!omapdss_device_is_connected(dssdev
)) {
775 if (omapdss_device_is_enabled(dssdev
)) {
780 in
->ops
.dsi
->bus_lock(in
);
782 r
= dsicm_power_on(ddata
);
784 in
->ops
.dsi
->bus_unlock(in
);
789 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
791 mutex_unlock(&ddata
->lock
);
795 dev_dbg(&ddata
->pdev
->dev
, "enable failed\n");
796 mutex_unlock(&ddata
->lock
);
800 static void dsicm_disable(struct omap_dss_device
*dssdev
)
802 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
803 struct omap_dss_device
*in
= ddata
->in
;
806 dev_dbg(&ddata
->pdev
->dev
, "disable\n");
808 mutex_lock(&ddata
->lock
);
810 dsicm_cancel_ulps_work(ddata
);
812 in
->ops
.dsi
->bus_lock(in
);
814 if (omapdss_device_is_enabled(dssdev
)) {
815 r
= dsicm_wake_up(ddata
);
817 dsicm_power_off(ddata
);
820 in
->ops
.dsi
->bus_unlock(in
);
822 dssdev
->state
= OMAP_DSS_DISPLAY_DISABLED
;
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
*in
= ddata
->in
;
832 dev_dbg(&ddata
->pdev
->dev
, "framedone, err %d\n", err
);
833 in
->ops
.dsi
->bus_unlock(ddata
->in
);
836 static irqreturn_t
dsicm_te_isr(int irq
, void *data
)
838 struct panel_drv_data
*ddata
= data
;
839 struct omap_dss_device
*in
= ddata
->in
;
843 old
= atomic_cmpxchg(&ddata
->do_update
, 1, 0);
846 cancel_delayed_work(&ddata
->te_timeout_work
);
848 r
= in
->ops
.dsi
->update(in
, ddata
->channel
, dsicm_framedone_cb
,
856 dev_err(&ddata
->pdev
->dev
, "start update failed\n");
857 in
->ops
.dsi
->bus_unlock(in
);
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
*in
= ddata
->in
;
867 dev_err(&ddata
->pdev
->dev
, "TE not received for 250ms!\n");
869 atomic_set(&ddata
->do_update
, 0);
870 in
->ops
.dsi
->bus_unlock(in
);
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
*in
= ddata
->in
;
880 dev_dbg(&ddata
->pdev
->dev
, "update %d, %d, %d x %d\n", x
, y
, w
, h
);
882 mutex_lock(&ddata
->lock
);
883 in
->ops
.dsi
->bus_lock(in
);
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,
896 dssdev
->panel
.timings
.x_res
,
897 dssdev
->panel
.timings
.y_res
);
901 if (ddata
->te_enabled
&& gpio_is_valid(ddata
->ext_te_gpio
)) {
902 schedule_delayed_work(&ddata
->te_timeout_work
,
903 msecs_to_jiffies(250));
904 atomic_set(&ddata
->do_update
, 1);
906 r
= in
->ops
.dsi
->update(in
, ddata
->channel
, dsicm_framedone_cb
,
912 /* note: no bus_unlock here. unlock is in framedone_cb */
913 mutex_unlock(&ddata
->lock
);
916 in
->ops
.dsi
->bus_unlock(in
);
917 mutex_unlock(&ddata
->lock
);
921 static int dsicm_sync(struct omap_dss_device
*dssdev
)
923 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
924 struct omap_dss_device
*in
= ddata
->in
;
926 dev_dbg(&ddata
->pdev
->dev
, "sync\n");
928 mutex_lock(&ddata
->lock
);
929 in
->ops
.dsi
->bus_lock(in
);
930 in
->ops
.dsi
->bus_unlock(in
);
931 mutex_unlock(&ddata
->lock
);
933 dev_dbg(&ddata
->pdev
->dev
, "sync done\n");
938 static int _dsicm_enable_te(struct panel_drv_data
*ddata
, bool enable
)
940 struct omap_dss_device
*in
= ddata
->in
;
944 r
= dsicm_dcs_write_1(ddata
, MIPI_DCS_SET_TEAR_ON
, 0);
946 r
= dsicm_dcs_write_0(ddata
, MIPI_DCS_SET_TEAR_OFF
);
948 if (!gpio_is_valid(ddata
->ext_te_gpio
))
949 in
->ops
.dsi
->enable_te(in
, enable
);
951 /* possible panel bug */
957 static int dsicm_enable_te(struct omap_dss_device
*dssdev
, bool enable
)
959 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
960 struct omap_dss_device
*in
= ddata
->in
;
963 mutex_lock(&ddata
->lock
);
965 if (ddata
->te_enabled
== enable
)
968 in
->ops
.dsi
->bus_lock(in
);
970 if (ddata
->enabled
) {
971 r
= dsicm_wake_up(ddata
);
975 r
= _dsicm_enable_te(ddata
, enable
);
980 ddata
->te_enabled
= enable
;
982 in
->ops
.dsi
->bus_unlock(in
);
984 mutex_unlock(&ddata
->lock
);
988 in
->ops
.dsi
->bus_unlock(in
);
989 mutex_unlock(&ddata
->lock
);
994 static int dsicm_get_te(struct omap_dss_device
*dssdev
)
996 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
999 mutex_lock(&ddata
->lock
);
1000 r
= ddata
->te_enabled
;
1001 mutex_unlock(&ddata
->lock
);
1006 static int dsicm_memory_read(struct omap_dss_device
*dssdev
,
1007 void *buf
, size_t size
,
1008 u16 x
, u16 y
, u16 w
, u16 h
)
1010 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
1011 struct omap_dss_device
*in
= ddata
->in
;
1015 unsigned buf_used
= 0;
1017 if (size
< w
* h
* 3)
1020 mutex_lock(&ddata
->lock
);
1022 if (!ddata
->enabled
) {
1027 size
= min(w
* h
* 3,
1028 dssdev
->panel
.timings
.x_res
*
1029 dssdev
->panel
.timings
.y_res
* 3);
1031 in
->ops
.dsi
->bus_lock(in
);
1033 r
= dsicm_wake_up(ddata
);
1037 /* plen 1 or 2 goes into short packet. until checksum error is fixed,
1038 * use short packets. plen 32 works, but bigger packets seem to cause
1045 dsicm_set_update_window(ddata
, x
, y
, w
, h
);
1047 r
= in
->ops
.dsi
->set_max_rx_packet_size(in
, ddata
->channel
, plen
);
1051 while (buf_used
< size
) {
1052 u8 dcs_cmd
= first
? 0x2e : 0x3e;
1055 r
= in
->ops
.dsi
->dcs_read(in
, ddata
->channel
, dcs_cmd
,
1056 buf
+ buf_used
, size
- buf_used
);
1059 dev_err(dssdev
->dev
, "read error\n");
1066 dev_err(&ddata
->pdev
->dev
, "short read\n");
1070 if (signal_pending(current
)) {
1071 dev_err(&ddata
->pdev
->dev
, "signal pending, "
1072 "aborting memory read\n");
1081 in
->ops
.dsi
->set_max_rx_packet_size(in
, ddata
->channel
, 1);
1083 in
->ops
.dsi
->bus_unlock(in
);
1085 mutex_unlock(&ddata
->lock
);
1089 static void dsicm_ulps_work(struct work_struct
*work
)
1091 struct panel_drv_data
*ddata
= container_of(work
, struct panel_drv_data
,
1093 struct omap_dss_device
*dssdev
= &ddata
->dssdev
;
1094 struct omap_dss_device
*in
= ddata
->in
;
1096 mutex_lock(&ddata
->lock
);
1098 if (dssdev
->state
!= OMAP_DSS_DISPLAY_ACTIVE
|| !ddata
->enabled
) {
1099 mutex_unlock(&ddata
->lock
);
1103 in
->ops
.dsi
->bus_lock(in
);
1105 dsicm_enter_ulps(ddata
);
1107 in
->ops
.dsi
->bus_unlock(in
);
1108 mutex_unlock(&ddata
->lock
);
1111 static struct omap_dss_driver dsicm_ops
= {
1112 .connect
= dsicm_connect
,
1113 .disconnect
= dsicm_disconnect
,
1115 .enable
= dsicm_enable
,
1116 .disable
= dsicm_disable
,
1118 .update
= dsicm_update
,
1121 .get_resolution
= dsicm_get_resolution
,
1122 .get_recommended_bpp
= omapdss_default_get_recommended_bpp
,
1124 .enable_te
= dsicm_enable_te
,
1125 .get_te
= dsicm_get_te
,
1127 .memory_read
= dsicm_memory_read
,
1130 static int dsicm_probe_pdata(struct platform_device
*pdev
)
1132 const struct panel_dsicm_platform_data
*pdata
;
1133 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
1134 struct omap_dss_device
*dssdev
, *in
;
1136 pdata
= dev_get_platdata(&pdev
->dev
);
1138 in
= omap_dss_find_output(pdata
->source
);
1140 dev_err(&pdev
->dev
, "failed to find video source\n");
1141 return -EPROBE_DEFER
;
1145 ddata
->reset_gpio
= pdata
->reset_gpio
;
1147 if (pdata
->use_ext_te
)
1148 ddata
->ext_te_gpio
= pdata
->ext_te_gpio
;
1150 ddata
->ext_te_gpio
= -1;
1152 ddata
->ulps_timeout
= pdata
->ulps_timeout
;
1154 ddata
->use_dsi_backlight
= pdata
->use_dsi_backlight
;
1156 ddata
->pin_config
= pdata
->pin_config
;
1158 dssdev
= &ddata
->dssdev
;
1159 dssdev
->name
= pdata
->name
;
1164 static int dsicm_probe_of(struct platform_device
*pdev
)
1166 struct device_node
*node
= pdev
->dev
.of_node
;
1167 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
1168 struct omap_dss_device
*in
;
1171 gpio
= of_get_named_gpio(node
, "reset-gpios", 0);
1172 if (!gpio_is_valid(gpio
)) {
1173 dev_err(&pdev
->dev
, "failed to parse reset gpio\n");
1176 ddata
->reset_gpio
= gpio
;
1178 gpio
= of_get_named_gpio(node
, "te-gpios", 0);
1179 if (gpio_is_valid(gpio
) || gpio
== -ENOENT
) {
1180 ddata
->ext_te_gpio
= gpio
;
1182 dev_err(&pdev
->dev
, "failed to parse TE gpio\n");
1186 in
= omapdss_of_find_source_for_first_ep(node
);
1188 dev_err(&pdev
->dev
, "failed to find video source\n");
1194 /* TODO: ulps, backlight */
1199 static int dsicm_probe(struct platform_device
*pdev
)
1201 struct backlight_properties props
;
1202 struct panel_drv_data
*ddata
;
1203 struct backlight_device
*bldev
= NULL
;
1204 struct device
*dev
= &pdev
->dev
;
1205 struct omap_dss_device
*dssdev
;
1208 dev_dbg(dev
, "probe\n");
1210 ddata
= devm_kzalloc(dev
, sizeof(*ddata
), GFP_KERNEL
);
1214 platform_set_drvdata(pdev
, ddata
);
1217 if (dev_get_platdata(dev
)) {
1218 r
= dsicm_probe_pdata(pdev
);
1221 } else if (pdev
->dev
.of_node
) {
1222 r
= dsicm_probe_of(pdev
);
1229 ddata
->timings
.x_res
= 864;
1230 ddata
->timings
.y_res
= 480;
1231 ddata
->timings
.pixelclock
= 864 * 480 * 60;
1233 dssdev
= &ddata
->dssdev
;
1235 dssdev
->driver
= &dsicm_ops
;
1236 dssdev
->panel
.timings
= ddata
->timings
;
1237 dssdev
->type
= OMAP_DISPLAY_TYPE_DSI
;
1238 dssdev
->owner
= THIS_MODULE
;
1240 dssdev
->panel
.dsi_pix_fmt
= OMAP_DSS_DSI_FMT_RGB888
;
1241 dssdev
->caps
= OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE
|
1242 OMAP_DSS_DISPLAY_CAP_TEAR_ELIM
;
1244 r
= omapdss_register_display(dssdev
);
1246 dev_err(dev
, "Failed to register panel\n");
1250 mutex_init(&ddata
->lock
);
1252 atomic_set(&ddata
->do_update
, 0);
1254 if (gpio_is_valid(ddata
->reset_gpio
)) {
1255 r
= devm_gpio_request_one(dev
, ddata
->reset_gpio
,
1256 GPIOF_OUT_INIT_LOW
, "taal rst");
1258 dev_err(dev
, "failed to request reset gpio\n");
1263 if (gpio_is_valid(ddata
->ext_te_gpio
)) {
1264 r
= devm_gpio_request_one(dev
, ddata
->ext_te_gpio
,
1265 GPIOF_IN
, "taal irq");
1267 dev_err(dev
, "GPIO request failed\n");
1271 r
= devm_request_irq(dev
, gpio_to_irq(ddata
->ext_te_gpio
),
1273 IRQF_TRIGGER_RISING
,
1274 "taal vsync", ddata
);
1277 dev_err(dev
, "IRQ request failed\n");
1281 INIT_DEFERRABLE_WORK(&ddata
->te_timeout_work
,
1282 dsicm_te_timeout_work_callback
);
1284 dev_dbg(dev
, "Using GPIO TE\n");
1287 ddata
->workqueue
= create_singlethread_workqueue("dsicm_wq");
1288 if (ddata
->workqueue
== NULL
) {
1289 dev_err(dev
, "can't create workqueue\n");
1292 INIT_DELAYED_WORK(&ddata
->ulps_work
, dsicm_ulps_work
);
1294 dsicm_hw_reset(ddata
);
1296 if (ddata
->use_dsi_backlight
) {
1297 memset(&props
, 0, sizeof(struct backlight_properties
));
1298 props
.max_brightness
= 255;
1300 props
.type
= BACKLIGHT_RAW
;
1301 bldev
= backlight_device_register(dev_name(dev
),
1302 dev
, ddata
, &dsicm_bl_ops
, &props
);
1303 if (IS_ERR(bldev
)) {
1308 ddata
->bldev
= bldev
;
1310 bldev
->props
.fb_blank
= FB_BLANK_UNBLANK
;
1311 bldev
->props
.power
= FB_BLANK_UNBLANK
;
1312 bldev
->props
.brightness
= 255;
1314 dsicm_bl_update_status(bldev
);
1317 r
= sysfs_create_group(&dev
->kobj
, &dsicm_attr_group
);
1319 dev_err(dev
, "failed to create sysfs files\n");
1320 goto err_sysfs_create
;
1327 backlight_device_unregister(bldev
);
1329 destroy_workqueue(ddata
->workqueue
);
1334 static int __exit
dsicm_remove(struct platform_device
*pdev
)
1336 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
1337 struct omap_dss_device
*dssdev
= &ddata
->dssdev
;
1338 struct backlight_device
*bldev
;
1340 dev_dbg(&pdev
->dev
, "remove\n");
1342 omapdss_unregister_display(dssdev
);
1344 dsicm_disable(dssdev
);
1345 dsicm_disconnect(dssdev
);
1347 sysfs_remove_group(&pdev
->dev
.kobj
, &dsicm_attr_group
);
1349 bldev
= ddata
->bldev
;
1350 if (bldev
!= NULL
) {
1351 bldev
->props
.power
= FB_BLANK_POWERDOWN
;
1352 dsicm_bl_update_status(bldev
);
1353 backlight_device_unregister(bldev
);
1356 omap_dss_put_device(ddata
->in
);
1358 dsicm_cancel_ulps_work(ddata
);
1359 destroy_workqueue(ddata
->workqueue
);
1361 /* reset, to be sure that the panel is in a valid state */
1362 dsicm_hw_reset(ddata
);
1367 static const struct of_device_id dsicm_of_match
[] = {
1368 { .compatible
= "omapdss,panel-dsi-cm", },
1372 MODULE_DEVICE_TABLE(of
, dsicm_of_match
);
1374 static struct platform_driver dsicm_driver
= {
1375 .probe
= dsicm_probe
,
1376 .remove
= __exit_p(dsicm_remove
),
1378 .name
= "panel-dsi-cm",
1379 .of_match_table
= dsicm_of_match
,
1380 .suppress_bind_attrs
= true,
1384 module_platform_driver(dsicm_driver
);
1386 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
1387 MODULE_DESCRIPTION("Generic DSI Command Mode Panel Driver");
1388 MODULE_LICENSE("GPL");