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>
26 #include <video/omapdss.h>
27 #include <video/omap-panel-data.h>
28 #include <video/mipi_display.h>
30 /* DSI Virtual channel. Hardcoded for now. */
33 #define DCS_READ_NUM_ERRORS 0x05
34 #define DCS_BRIGHTNESS 0x51
35 #define DCS_CTRL_DISPLAY 0x53
36 #define DCS_GET_ID1 0xda
37 #define DCS_GET_ID2 0xdb
38 #define DCS_GET_ID3 0xdc
40 struct panel_drv_data
{
41 struct omap_dss_device dssdev
;
42 struct omap_dss_device
*in
;
44 struct omap_video_timings timings
;
46 struct platform_device
*pdev
;
50 struct backlight_device
*bldev
;
52 unsigned long hw_guard_end
; /* next value of jiffies when we can
53 * issue the next sleep in/out command
55 unsigned long hw_guard_wait
; /* max guard time in jiffies */
57 /* panel HW configuration from DT or platform data */
61 bool use_dsi_backlight
;
63 struct omap_dsi_pin_config pin_config
;
65 /* runtime variables */
73 struct delayed_work te_timeout_work
;
77 struct workqueue_struct
*workqueue
;
80 unsigned ulps_timeout
;
81 struct delayed_work ulps_work
;
84 #define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
86 static irqreturn_t
dsicm_te_isr(int irq
, void *data
);
87 static void dsicm_te_timeout_work_callback(struct work_struct
*work
);
88 static int _dsicm_enable_te(struct panel_drv_data
*ddata
, bool enable
);
90 static int dsicm_panel_reset(struct panel_drv_data
*ddata
);
92 static void dsicm_ulps_work(struct work_struct
*work
);
94 static void hw_guard_start(struct panel_drv_data
*ddata
, int guard_msec
)
96 ddata
->hw_guard_wait
= msecs_to_jiffies(guard_msec
);
97 ddata
->hw_guard_end
= jiffies
+ ddata
->hw_guard_wait
;
100 static void hw_guard_wait(struct panel_drv_data
*ddata
)
102 unsigned long wait
= ddata
->hw_guard_end
- jiffies
;
104 if ((long)wait
> 0 && wait
<= ddata
->hw_guard_wait
) {
105 set_current_state(TASK_UNINTERRUPTIBLE
);
106 schedule_timeout(wait
);
110 static int dsicm_dcs_read_1(struct panel_drv_data
*ddata
, u8 dcs_cmd
, u8
*data
)
112 struct omap_dss_device
*in
= ddata
->in
;
116 r
= in
->ops
.dsi
->dcs_read(in
, ddata
->channel
, dcs_cmd
, buf
, 1);
126 static int dsicm_dcs_write_0(struct panel_drv_data
*ddata
, u8 dcs_cmd
)
128 struct omap_dss_device
*in
= ddata
->in
;
129 return in
->ops
.dsi
->dcs_write(in
, ddata
->channel
, &dcs_cmd
, 1);
132 static int dsicm_dcs_write_1(struct panel_drv_data
*ddata
, u8 dcs_cmd
, u8 param
)
134 struct omap_dss_device
*in
= ddata
->in
;
135 u8 buf
[2] = { dcs_cmd
, param
};
137 return in
->ops
.dsi
->dcs_write(in
, ddata
->channel
, buf
, 2);
140 static int dsicm_sleep_in(struct panel_drv_data
*ddata
)
143 struct omap_dss_device
*in
= ddata
->in
;
147 hw_guard_wait(ddata
);
149 cmd
= MIPI_DCS_ENTER_SLEEP_MODE
;
150 r
= in
->ops
.dsi
->dcs_write_nosync(in
, ddata
->channel
, &cmd
, 1);
154 hw_guard_start(ddata
, 120);
156 usleep_range(5000, 10000);
161 static int dsicm_sleep_out(struct panel_drv_data
*ddata
)
165 hw_guard_wait(ddata
);
167 r
= dsicm_dcs_write_0(ddata
, MIPI_DCS_EXIT_SLEEP_MODE
);
171 hw_guard_start(ddata
, 120);
173 usleep_range(5000, 10000);
178 static int dsicm_get_id(struct panel_drv_data
*ddata
, u8
*id1
, u8
*id2
, u8
*id3
)
182 r
= dsicm_dcs_read_1(ddata
, DCS_GET_ID1
, id1
);
185 r
= dsicm_dcs_read_1(ddata
, DCS_GET_ID2
, id2
);
188 r
= dsicm_dcs_read_1(ddata
, DCS_GET_ID3
, id3
);
195 static int dsicm_set_update_window(struct panel_drv_data
*ddata
,
196 u16 x
, u16 y
, u16 w
, u16 h
)
198 struct omap_dss_device
*in
= ddata
->in
;
206 buf
[0] = MIPI_DCS_SET_COLUMN_ADDRESS
;
207 buf
[1] = (x1
>> 8) & 0xff;
208 buf
[2] = (x1
>> 0) & 0xff;
209 buf
[3] = (x2
>> 8) & 0xff;
210 buf
[4] = (x2
>> 0) & 0xff;
212 r
= in
->ops
.dsi
->dcs_write_nosync(in
, ddata
->channel
, buf
, sizeof(buf
));
216 buf
[0] = MIPI_DCS_SET_PAGE_ADDRESS
;
217 buf
[1] = (y1
>> 8) & 0xff;
218 buf
[2] = (y1
>> 0) & 0xff;
219 buf
[3] = (y2
>> 8) & 0xff;
220 buf
[4] = (y2
>> 0) & 0xff;
222 r
= in
->ops
.dsi
->dcs_write_nosync(in
, ddata
->channel
, buf
, sizeof(buf
));
226 in
->ops
.dsi
->bta_sync(in
, ddata
->channel
);
231 static void dsicm_queue_ulps_work(struct panel_drv_data
*ddata
)
233 if (ddata
->ulps_timeout
> 0)
234 queue_delayed_work(ddata
->workqueue
, &ddata
->ulps_work
,
235 msecs_to_jiffies(ddata
->ulps_timeout
));
238 static void dsicm_cancel_ulps_work(struct panel_drv_data
*ddata
)
240 cancel_delayed_work(&ddata
->ulps_work
);
243 static int dsicm_enter_ulps(struct panel_drv_data
*ddata
)
245 struct omap_dss_device
*in
= ddata
->in
;
248 if (ddata
->ulps_enabled
)
251 dsicm_cancel_ulps_work(ddata
);
253 r
= _dsicm_enable_te(ddata
, false);
257 if (gpio_is_valid(ddata
->ext_te_gpio
))
258 disable_irq(gpio_to_irq(ddata
->ext_te_gpio
));
260 in
->ops
.dsi
->disable(in
, false, true);
262 ddata
->ulps_enabled
= true;
267 dev_err(&ddata
->pdev
->dev
, "enter ULPS failed");
268 dsicm_panel_reset(ddata
);
270 ddata
->ulps_enabled
= false;
272 dsicm_queue_ulps_work(ddata
);
277 static int dsicm_exit_ulps(struct panel_drv_data
*ddata
)
279 struct omap_dss_device
*in
= ddata
->in
;
282 if (!ddata
->ulps_enabled
)
285 r
= in
->ops
.dsi
->enable(in
);
287 dev_err(&ddata
->pdev
->dev
, "failed to enable DSI\n");
291 in
->ops
.dsi
->enable_hs(in
, ddata
->channel
, true);
293 r
= _dsicm_enable_te(ddata
, true);
295 dev_err(&ddata
->pdev
->dev
, "failed to re-enable TE");
299 if (gpio_is_valid(ddata
->ext_te_gpio
))
300 enable_irq(gpio_to_irq(ddata
->ext_te_gpio
));
302 dsicm_queue_ulps_work(ddata
);
304 ddata
->ulps_enabled
= false;
309 dev_err(&ddata
->pdev
->dev
, "failed to exit ULPS");
311 r
= dsicm_panel_reset(ddata
);
313 if (gpio_is_valid(ddata
->ext_te_gpio
))
314 enable_irq(gpio_to_irq(ddata
->ext_te_gpio
));
315 ddata
->ulps_enabled
= false;
318 dsicm_queue_ulps_work(ddata
);
323 static int dsicm_wake_up(struct panel_drv_data
*ddata
)
325 if (ddata
->ulps_enabled
)
326 return dsicm_exit_ulps(ddata
);
328 dsicm_cancel_ulps_work(ddata
);
329 dsicm_queue_ulps_work(ddata
);
333 static int dsicm_bl_update_status(struct backlight_device
*dev
)
335 struct panel_drv_data
*ddata
= dev_get_drvdata(&dev
->dev
);
336 struct omap_dss_device
*in
= ddata
->in
;
340 if (dev
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
341 dev
->props
.power
== FB_BLANK_UNBLANK
)
342 level
= dev
->props
.brightness
;
346 dev_dbg(&ddata
->pdev
->dev
, "update brightness to %d\n", level
);
348 mutex_lock(&ddata
->lock
);
350 if (ddata
->enabled
) {
351 in
->ops
.dsi
->bus_lock(in
);
353 r
= dsicm_wake_up(ddata
);
355 r
= dsicm_dcs_write_1(ddata
, DCS_BRIGHTNESS
, level
);
357 in
->ops
.dsi
->bus_unlock(in
);
362 mutex_unlock(&ddata
->lock
);
367 static int dsicm_bl_get_intensity(struct backlight_device
*dev
)
369 if (dev
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
370 dev
->props
.power
== FB_BLANK_UNBLANK
)
371 return dev
->props
.brightness
;
376 static const struct backlight_ops dsicm_bl_ops
= {
377 .get_brightness
= dsicm_bl_get_intensity
,
378 .update_status
= dsicm_bl_update_status
,
381 static void dsicm_get_resolution(struct omap_dss_device
*dssdev
,
382 u16
*xres
, u16
*yres
)
384 *xres
= dssdev
->panel
.timings
.x_res
;
385 *yres
= dssdev
->panel
.timings
.y_res
;
388 static ssize_t
dsicm_num_errors_show(struct device
*dev
,
389 struct device_attribute
*attr
, char *buf
)
391 struct platform_device
*pdev
= to_platform_device(dev
);
392 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
393 struct omap_dss_device
*in
= ddata
->in
;
397 mutex_lock(&ddata
->lock
);
399 if (ddata
->enabled
) {
400 in
->ops
.dsi
->bus_lock(in
);
402 r
= dsicm_wake_up(ddata
);
404 r
= dsicm_dcs_read_1(ddata
, DCS_READ_NUM_ERRORS
,
407 in
->ops
.dsi
->bus_unlock(in
);
412 mutex_unlock(&ddata
->lock
);
417 return snprintf(buf
, PAGE_SIZE
, "%d\n", errors
);
420 static ssize_t
dsicm_hw_revision_show(struct device
*dev
,
421 struct device_attribute
*attr
, char *buf
)
423 struct platform_device
*pdev
= to_platform_device(dev
);
424 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
425 struct omap_dss_device
*in
= ddata
->in
;
429 mutex_lock(&ddata
->lock
);
431 if (ddata
->enabled
) {
432 in
->ops
.dsi
->bus_lock(in
);
434 r
= dsicm_wake_up(ddata
);
436 r
= dsicm_get_id(ddata
, &id1
, &id2
, &id3
);
438 in
->ops
.dsi
->bus_unlock(in
);
443 mutex_unlock(&ddata
->lock
);
448 return snprintf(buf
, PAGE_SIZE
, "%02x.%02x.%02x\n", id1
, id2
, id3
);
451 static ssize_t
dsicm_store_ulps(struct device
*dev
,
452 struct device_attribute
*attr
,
453 const char *buf
, size_t count
)
455 struct platform_device
*pdev
= to_platform_device(dev
);
456 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
457 struct omap_dss_device
*in
= ddata
->in
;
461 r
= kstrtoul(buf
, 0, &t
);
465 mutex_lock(&ddata
->lock
);
467 if (ddata
->enabled
) {
468 in
->ops
.dsi
->bus_lock(in
);
471 r
= dsicm_enter_ulps(ddata
);
473 r
= dsicm_wake_up(ddata
);
475 in
->ops
.dsi
->bus_unlock(in
);
478 mutex_unlock(&ddata
->lock
);
486 static ssize_t
dsicm_show_ulps(struct device
*dev
,
487 struct device_attribute
*attr
,
490 struct platform_device
*pdev
= to_platform_device(dev
);
491 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
494 mutex_lock(&ddata
->lock
);
495 t
= ddata
->ulps_enabled
;
496 mutex_unlock(&ddata
->lock
);
498 return snprintf(buf
, PAGE_SIZE
, "%u\n", t
);
501 static ssize_t
dsicm_store_ulps_timeout(struct device
*dev
,
502 struct device_attribute
*attr
,
503 const char *buf
, size_t count
)
505 struct platform_device
*pdev
= to_platform_device(dev
);
506 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
507 struct omap_dss_device
*in
= ddata
->in
;
511 r
= kstrtoul(buf
, 0, &t
);
515 mutex_lock(&ddata
->lock
);
516 ddata
->ulps_timeout
= t
;
518 if (ddata
->enabled
) {
519 /* dsicm_wake_up will restart the timer */
520 in
->ops
.dsi
->bus_lock(in
);
521 r
= dsicm_wake_up(ddata
);
522 in
->ops
.dsi
->bus_unlock(in
);
525 mutex_unlock(&ddata
->lock
);
533 static ssize_t
dsicm_show_ulps_timeout(struct device
*dev
,
534 struct device_attribute
*attr
,
537 struct platform_device
*pdev
= to_platform_device(dev
);
538 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
541 mutex_lock(&ddata
->lock
);
542 t
= ddata
->ulps_timeout
;
543 mutex_unlock(&ddata
->lock
);
545 return snprintf(buf
, PAGE_SIZE
, "%u\n", t
);
548 static DEVICE_ATTR(num_dsi_errors
, S_IRUGO
, dsicm_num_errors_show
, NULL
);
549 static DEVICE_ATTR(hw_revision
, S_IRUGO
, dsicm_hw_revision_show
, NULL
);
550 static DEVICE_ATTR(ulps
, S_IRUGO
| S_IWUSR
,
551 dsicm_show_ulps
, dsicm_store_ulps
);
552 static DEVICE_ATTR(ulps_timeout
, S_IRUGO
| S_IWUSR
,
553 dsicm_show_ulps_timeout
, dsicm_store_ulps_timeout
);
555 static struct attribute
*dsicm_attrs
[] = {
556 &dev_attr_num_dsi_errors
.attr
,
557 &dev_attr_hw_revision
.attr
,
559 &dev_attr_ulps_timeout
.attr
,
563 static struct attribute_group dsicm_attr_group
= {
564 .attrs
= dsicm_attrs
,
567 static void dsicm_hw_reset(struct panel_drv_data
*ddata
)
569 if (!gpio_is_valid(ddata
->reset_gpio
))
572 gpio_set_value(ddata
->reset_gpio
, 1);
574 /* reset the panel */
575 gpio_set_value(ddata
->reset_gpio
, 0);
578 gpio_set_value(ddata
->reset_gpio
, 1);
579 /* wait after releasing reset */
580 usleep_range(5000, 10000);
583 static int dsicm_power_on(struct panel_drv_data
*ddata
)
585 struct omap_dss_device
*in
= ddata
->in
;
588 struct omap_dss_dsi_config dsi_config
= {
589 .mode
= OMAP_DSS_DSI_CMD_MODE
,
590 .pixel_format
= OMAP_DSS_DSI_FMT_RGB888
,
591 .timings
= &ddata
->timings
,
592 .hs_clk_min
= 150000000,
593 .hs_clk_max
= 300000000,
594 .lp_clk_min
= 7000000,
595 .lp_clk_max
= 10000000,
598 r
= in
->ops
.dsi
->configure_pins(in
, &ddata
->pin_config
);
600 dev_err(&ddata
->pdev
->dev
, "failed to configure DSI pins\n");
604 r
= in
->ops
.dsi
->set_config(in
, &dsi_config
);
606 dev_err(&ddata
->pdev
->dev
, "failed to configure DSI\n");
610 r
= in
->ops
.dsi
->enable(in
);
612 dev_err(&ddata
->pdev
->dev
, "failed to enable DSI\n");
616 dsicm_hw_reset(ddata
);
618 in
->ops
.dsi
->enable_hs(in
, ddata
->channel
, false);
620 r
= dsicm_sleep_out(ddata
);
624 r
= dsicm_get_id(ddata
, &id1
, &id2
, &id3
);
628 r
= dsicm_dcs_write_1(ddata
, DCS_BRIGHTNESS
, 0xff);
632 r
= dsicm_dcs_write_1(ddata
, DCS_CTRL_DISPLAY
,
633 (1<<2) | (1<<5)); /* BL | BCTRL */
637 r
= dsicm_dcs_write_1(ddata
, MIPI_DCS_SET_PIXEL_FORMAT
,
638 MIPI_DCS_PIXEL_FMT_24BIT
);
642 r
= dsicm_dcs_write_0(ddata
, MIPI_DCS_SET_DISPLAY_ON
);
646 r
= _dsicm_enable_te(ddata
, ddata
->te_enabled
);
650 r
= in
->ops
.dsi
->enable_video_output(in
, ddata
->channel
);
656 if (!ddata
->intro_printed
) {
657 dev_info(&ddata
->pdev
->dev
, "panel revision %02x.%02x.%02x\n",
659 ddata
->intro_printed
= true;
662 in
->ops
.dsi
->enable_hs(in
, ddata
->channel
, true);
666 dev_err(&ddata
->pdev
->dev
, "error while enabling panel, issuing HW reset\n");
668 dsicm_hw_reset(ddata
);
670 in
->ops
.dsi
->disable(in
, true, false);
675 static void dsicm_power_off(struct panel_drv_data
*ddata
)
677 struct omap_dss_device
*in
= ddata
->in
;
680 in
->ops
.dsi
->disable_video_output(in
, ddata
->channel
);
682 r
= dsicm_dcs_write_0(ddata
, MIPI_DCS_SET_DISPLAY_OFF
);
684 r
= dsicm_sleep_in(ddata
);
687 dev_err(&ddata
->pdev
->dev
,
688 "error disabling panel, issuing HW reset\n");
689 dsicm_hw_reset(ddata
);
692 in
->ops
.dsi
->disable(in
, true, false);
697 static int dsicm_panel_reset(struct panel_drv_data
*ddata
)
699 dev_err(&ddata
->pdev
->dev
, "performing LCD reset\n");
701 dsicm_power_off(ddata
);
702 dsicm_hw_reset(ddata
);
703 return dsicm_power_on(ddata
);
706 static int dsicm_connect(struct omap_dss_device
*dssdev
)
708 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
709 struct omap_dss_device
*in
= ddata
->in
;
710 struct device
*dev
= &ddata
->pdev
->dev
;
713 if (omapdss_device_is_connected(dssdev
))
716 r
= in
->ops
.dsi
->connect(in
, dssdev
);
718 dev_err(dev
, "Failed to connect to video source\n");
722 r
= in
->ops
.dsi
->request_vc(ddata
->in
, &ddata
->channel
);
724 dev_err(dev
, "failed to get virtual channel\n");
728 r
= in
->ops
.dsi
->set_vc_id(ddata
->in
, ddata
->channel
, TCH
);
730 dev_err(dev
, "failed to set VC_ID\n");
737 in
->ops
.dsi
->release_vc(ddata
->in
, ddata
->channel
);
739 in
->ops
.dsi
->disconnect(in
, dssdev
);
743 static void dsicm_disconnect(struct omap_dss_device
*dssdev
)
745 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
746 struct omap_dss_device
*in
= ddata
->in
;
748 if (!omapdss_device_is_connected(dssdev
))
751 in
->ops
.dsi
->release_vc(in
, ddata
->channel
);
752 in
->ops
.dsi
->disconnect(in
, dssdev
);
755 static int dsicm_enable(struct omap_dss_device
*dssdev
)
757 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
758 struct omap_dss_device
*in
= ddata
->in
;
761 dev_dbg(&ddata
->pdev
->dev
, "enable\n");
763 mutex_lock(&ddata
->lock
);
765 if (!omapdss_device_is_connected(dssdev
)) {
770 if (omapdss_device_is_enabled(dssdev
)) {
775 in
->ops
.dsi
->bus_lock(in
);
777 r
= dsicm_power_on(ddata
);
779 in
->ops
.dsi
->bus_unlock(in
);
784 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
786 mutex_unlock(&ddata
->lock
);
790 dev_dbg(&ddata
->pdev
->dev
, "enable failed\n");
791 mutex_unlock(&ddata
->lock
);
795 static void dsicm_disable(struct omap_dss_device
*dssdev
)
797 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
798 struct omap_dss_device
*in
= ddata
->in
;
801 dev_dbg(&ddata
->pdev
->dev
, "disable\n");
803 mutex_lock(&ddata
->lock
);
805 dsicm_cancel_ulps_work(ddata
);
807 in
->ops
.dsi
->bus_lock(in
);
809 if (omapdss_device_is_enabled(dssdev
)) {
810 r
= dsicm_wake_up(ddata
);
812 dsicm_power_off(ddata
);
815 in
->ops
.dsi
->bus_unlock(in
);
817 dssdev
->state
= OMAP_DSS_DISPLAY_DISABLED
;
819 mutex_unlock(&ddata
->lock
);
822 static void dsicm_framedone_cb(int err
, void *data
)
824 struct panel_drv_data
*ddata
= data
;
825 struct omap_dss_device
*in
= ddata
->in
;
827 dev_dbg(&ddata
->pdev
->dev
, "framedone, err %d\n", err
);
828 in
->ops
.dsi
->bus_unlock(ddata
->in
);
831 static irqreturn_t
dsicm_te_isr(int irq
, void *data
)
833 struct panel_drv_data
*ddata
= data
;
834 struct omap_dss_device
*in
= ddata
->in
;
838 old
= atomic_cmpxchg(&ddata
->do_update
, 1, 0);
841 cancel_delayed_work(&ddata
->te_timeout_work
);
843 r
= in
->ops
.dsi
->update(in
, ddata
->channel
, dsicm_framedone_cb
,
851 dev_err(&ddata
->pdev
->dev
, "start update failed\n");
852 in
->ops
.dsi
->bus_unlock(in
);
856 static void dsicm_te_timeout_work_callback(struct work_struct
*work
)
858 struct panel_drv_data
*ddata
= container_of(work
, struct panel_drv_data
,
859 te_timeout_work
.work
);
860 struct omap_dss_device
*in
= ddata
->in
;
862 dev_err(&ddata
->pdev
->dev
, "TE not received for 250ms!\n");
864 atomic_set(&ddata
->do_update
, 0);
865 in
->ops
.dsi
->bus_unlock(in
);
868 static int dsicm_update(struct omap_dss_device
*dssdev
,
869 u16 x
, u16 y
, u16 w
, u16 h
)
871 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
872 struct omap_dss_device
*in
= ddata
->in
;
875 dev_dbg(&ddata
->pdev
->dev
, "update %d, %d, %d x %d\n", x
, y
, w
, h
);
877 mutex_lock(&ddata
->lock
);
878 in
->ops
.dsi
->bus_lock(in
);
880 r
= dsicm_wake_up(ddata
);
884 if (!ddata
->enabled
) {
889 /* XXX no need to send this every frame, but dsi break if not done */
890 r
= dsicm_set_update_window(ddata
, 0, 0,
891 dssdev
->panel
.timings
.x_res
,
892 dssdev
->panel
.timings
.y_res
);
896 if (ddata
->te_enabled
&& gpio_is_valid(ddata
->ext_te_gpio
)) {
897 schedule_delayed_work(&ddata
->te_timeout_work
,
898 msecs_to_jiffies(250));
899 atomic_set(&ddata
->do_update
, 1);
901 r
= in
->ops
.dsi
->update(in
, ddata
->channel
, dsicm_framedone_cb
,
907 /* note: no bus_unlock here. unlock is in framedone_cb */
908 mutex_unlock(&ddata
->lock
);
911 in
->ops
.dsi
->bus_unlock(in
);
912 mutex_unlock(&ddata
->lock
);
916 static int dsicm_sync(struct omap_dss_device
*dssdev
)
918 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
919 struct omap_dss_device
*in
= ddata
->in
;
921 dev_dbg(&ddata
->pdev
->dev
, "sync\n");
923 mutex_lock(&ddata
->lock
);
924 in
->ops
.dsi
->bus_lock(in
);
925 in
->ops
.dsi
->bus_unlock(in
);
926 mutex_unlock(&ddata
->lock
);
928 dev_dbg(&ddata
->pdev
->dev
, "sync done\n");
933 static int _dsicm_enable_te(struct panel_drv_data
*ddata
, bool enable
)
935 struct omap_dss_device
*in
= ddata
->in
;
939 r
= dsicm_dcs_write_1(ddata
, MIPI_DCS_SET_TEAR_ON
, 0);
941 r
= dsicm_dcs_write_0(ddata
, MIPI_DCS_SET_TEAR_OFF
);
943 if (!gpio_is_valid(ddata
->ext_te_gpio
))
944 in
->ops
.dsi
->enable_te(in
, enable
);
946 /* possible panel bug */
952 static int dsicm_enable_te(struct omap_dss_device
*dssdev
, bool enable
)
954 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
955 struct omap_dss_device
*in
= ddata
->in
;
958 mutex_lock(&ddata
->lock
);
960 if (ddata
->te_enabled
== enable
)
963 in
->ops
.dsi
->bus_lock(in
);
965 if (ddata
->enabled
) {
966 r
= dsicm_wake_up(ddata
);
970 r
= _dsicm_enable_te(ddata
, enable
);
975 ddata
->te_enabled
= enable
;
977 in
->ops
.dsi
->bus_unlock(in
);
979 mutex_unlock(&ddata
->lock
);
983 in
->ops
.dsi
->bus_unlock(in
);
984 mutex_unlock(&ddata
->lock
);
989 static int dsicm_get_te(struct omap_dss_device
*dssdev
)
991 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
994 mutex_lock(&ddata
->lock
);
995 r
= ddata
->te_enabled
;
996 mutex_unlock(&ddata
->lock
);
1001 static int dsicm_memory_read(struct omap_dss_device
*dssdev
,
1002 void *buf
, size_t size
,
1003 u16 x
, u16 y
, u16 w
, u16 h
)
1005 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
1006 struct omap_dss_device
*in
= ddata
->in
;
1010 unsigned buf_used
= 0;
1012 if (size
< w
* h
* 3)
1015 mutex_lock(&ddata
->lock
);
1017 if (!ddata
->enabled
) {
1022 size
= min(w
* h
* 3,
1023 dssdev
->panel
.timings
.x_res
*
1024 dssdev
->panel
.timings
.y_res
* 3);
1026 in
->ops
.dsi
->bus_lock(in
);
1028 r
= dsicm_wake_up(ddata
);
1032 /* plen 1 or 2 goes into short packet. until checksum error is fixed,
1033 * use short packets. plen 32 works, but bigger packets seem to cause
1040 dsicm_set_update_window(ddata
, x
, y
, w
, h
);
1042 r
= in
->ops
.dsi
->set_max_rx_packet_size(in
, ddata
->channel
, plen
);
1046 while (buf_used
< size
) {
1047 u8 dcs_cmd
= first
? 0x2e : 0x3e;
1050 r
= in
->ops
.dsi
->dcs_read(in
, ddata
->channel
, dcs_cmd
,
1051 buf
+ buf_used
, size
- buf_used
);
1054 dev_err(dssdev
->dev
, "read error\n");
1061 dev_err(&ddata
->pdev
->dev
, "short read\n");
1065 if (signal_pending(current
)) {
1066 dev_err(&ddata
->pdev
->dev
, "signal pending, "
1067 "aborting memory read\n");
1076 in
->ops
.dsi
->set_max_rx_packet_size(in
, ddata
->channel
, 1);
1078 in
->ops
.dsi
->bus_unlock(in
);
1080 mutex_unlock(&ddata
->lock
);
1084 static void dsicm_ulps_work(struct work_struct
*work
)
1086 struct panel_drv_data
*ddata
= container_of(work
, struct panel_drv_data
,
1088 struct omap_dss_device
*dssdev
= &ddata
->dssdev
;
1089 struct omap_dss_device
*in
= ddata
->in
;
1091 mutex_lock(&ddata
->lock
);
1093 if (dssdev
->state
!= OMAP_DSS_DISPLAY_ACTIVE
|| !ddata
->enabled
) {
1094 mutex_unlock(&ddata
->lock
);
1098 in
->ops
.dsi
->bus_lock(in
);
1100 dsicm_enter_ulps(ddata
);
1102 in
->ops
.dsi
->bus_unlock(in
);
1103 mutex_unlock(&ddata
->lock
);
1106 static struct omap_dss_driver dsicm_ops
= {
1107 .connect
= dsicm_connect
,
1108 .disconnect
= dsicm_disconnect
,
1110 .enable
= dsicm_enable
,
1111 .disable
= dsicm_disable
,
1113 .update
= dsicm_update
,
1116 .get_resolution
= dsicm_get_resolution
,
1117 .get_recommended_bpp
= omapdss_default_get_recommended_bpp
,
1119 .enable_te
= dsicm_enable_te
,
1120 .get_te
= dsicm_get_te
,
1122 .memory_read
= dsicm_memory_read
,
1125 static int dsicm_probe_pdata(struct platform_device
*pdev
)
1127 const struct panel_dsicm_platform_data
*pdata
;
1128 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
1129 struct omap_dss_device
*dssdev
, *in
;
1131 pdata
= dev_get_platdata(&pdev
->dev
);
1133 in
= omap_dss_find_output(pdata
->source
);
1135 dev_err(&pdev
->dev
, "failed to find video source\n");
1136 return -EPROBE_DEFER
;
1140 ddata
->reset_gpio
= pdata
->reset_gpio
;
1142 if (pdata
->use_ext_te
)
1143 ddata
->ext_te_gpio
= pdata
->ext_te_gpio
;
1145 ddata
->ext_te_gpio
= -1;
1147 ddata
->ulps_timeout
= pdata
->ulps_timeout
;
1149 ddata
->use_dsi_backlight
= pdata
->use_dsi_backlight
;
1151 ddata
->pin_config
= pdata
->pin_config
;
1153 dssdev
= &ddata
->dssdev
;
1154 dssdev
->name
= pdata
->name
;
1159 static int dsicm_probe(struct platform_device
*pdev
)
1161 struct backlight_properties props
;
1162 struct panel_drv_data
*ddata
;
1163 struct backlight_device
*bldev
= NULL
;
1164 struct device
*dev
= &pdev
->dev
;
1165 struct omap_dss_device
*dssdev
;
1168 dev_dbg(dev
, "probe\n");
1170 ddata
= devm_kzalloc(dev
, sizeof(*ddata
), GFP_KERNEL
);
1174 platform_set_drvdata(pdev
, ddata
);
1177 if (dev_get_platdata(dev
)) {
1178 r
= dsicm_probe_pdata(pdev
);
1185 ddata
->timings
.x_res
= 864;
1186 ddata
->timings
.y_res
= 480;
1187 ddata
->timings
.pixel_clock
= DIV_ROUND_UP(864 * 480 * 60, 1000);
1189 dssdev
= &ddata
->dssdev
;
1191 dssdev
->driver
= &dsicm_ops
;
1192 dssdev
->panel
.timings
= ddata
->timings
;
1193 dssdev
->type
= OMAP_DISPLAY_TYPE_DSI
;
1194 dssdev
->owner
= THIS_MODULE
;
1196 dssdev
->panel
.dsi_pix_fmt
= OMAP_DSS_DSI_FMT_RGB888
;
1197 dssdev
->caps
= OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE
|
1198 OMAP_DSS_DISPLAY_CAP_TEAR_ELIM
;
1200 r
= omapdss_register_display(dssdev
);
1202 dev_err(dev
, "Failed to register panel\n");
1206 mutex_init(&ddata
->lock
);
1208 atomic_set(&ddata
->do_update
, 0);
1210 if (gpio_is_valid(ddata
->reset_gpio
)) {
1211 r
= devm_gpio_request_one(dev
, ddata
->reset_gpio
,
1212 GPIOF_OUT_INIT_LOW
, "taal rst");
1214 dev_err(dev
, "failed to request reset gpio\n");
1219 if (gpio_is_valid(ddata
->ext_te_gpio
)) {
1220 r
= devm_gpio_request_one(dev
, ddata
->ext_te_gpio
,
1221 GPIOF_IN
, "taal irq");
1223 dev_err(dev
, "GPIO request failed\n");
1227 r
= devm_request_irq(dev
, gpio_to_irq(ddata
->ext_te_gpio
),
1229 IRQF_TRIGGER_RISING
,
1230 "taal vsync", ddata
);
1233 dev_err(dev
, "IRQ request failed\n");
1237 INIT_DEFERRABLE_WORK(&ddata
->te_timeout_work
,
1238 dsicm_te_timeout_work_callback
);
1240 dev_dbg(dev
, "Using GPIO TE\n");
1243 ddata
->workqueue
= create_singlethread_workqueue("dsicm_wq");
1244 if (ddata
->workqueue
== NULL
) {
1245 dev_err(dev
, "can't create workqueue\n");
1248 INIT_DELAYED_WORK(&ddata
->ulps_work
, dsicm_ulps_work
);
1250 dsicm_hw_reset(ddata
);
1252 if (ddata
->use_dsi_backlight
) {
1253 memset(&props
, 0, sizeof(struct backlight_properties
));
1254 props
.max_brightness
= 255;
1256 props
.type
= BACKLIGHT_RAW
;
1257 bldev
= backlight_device_register(dev_name(dev
),
1258 dev
, ddata
, &dsicm_bl_ops
, &props
);
1259 if (IS_ERR(bldev
)) {
1264 ddata
->bldev
= bldev
;
1266 bldev
->props
.fb_blank
= FB_BLANK_UNBLANK
;
1267 bldev
->props
.power
= FB_BLANK_UNBLANK
;
1268 bldev
->props
.brightness
= 255;
1270 dsicm_bl_update_status(bldev
);
1273 r
= sysfs_create_group(&dev
->kobj
, &dsicm_attr_group
);
1275 dev_err(dev
, "failed to create sysfs files\n");
1276 goto err_sysfs_create
;
1283 backlight_device_unregister(bldev
);
1285 destroy_workqueue(ddata
->workqueue
);
1290 static int __exit
dsicm_remove(struct platform_device
*pdev
)
1292 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
1293 struct omap_dss_device
*dssdev
= &ddata
->dssdev
;
1294 struct backlight_device
*bldev
;
1296 dev_dbg(&pdev
->dev
, "remove\n");
1298 omapdss_unregister_display(dssdev
);
1300 dsicm_disable(dssdev
);
1301 dsicm_disconnect(dssdev
);
1303 sysfs_remove_group(&pdev
->dev
.kobj
, &dsicm_attr_group
);
1305 bldev
= ddata
->bldev
;
1306 if (bldev
!= NULL
) {
1307 bldev
->props
.power
= FB_BLANK_POWERDOWN
;
1308 dsicm_bl_update_status(bldev
);
1309 backlight_device_unregister(bldev
);
1312 omap_dss_put_device(ddata
->in
);
1314 dsicm_cancel_ulps_work(ddata
);
1315 destroy_workqueue(ddata
->workqueue
);
1317 /* reset, to be sure that the panel is in a valid state */
1318 dsicm_hw_reset(ddata
);
1323 static struct platform_driver dsicm_driver
= {
1324 .probe
= dsicm_probe
,
1325 .remove
= __exit_p(dsicm_remove
),
1327 .name
= "panel-dsi-cm",
1328 .owner
= THIS_MODULE
,
1332 module_platform_driver(dsicm_driver
);
1334 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
1335 MODULE_DESCRIPTION("Generic DSI Command Mode Panel Driver");
1336 MODULE_LICENSE("GPL");