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/omapfb_dss.h>
29 #include <video/mipi_display.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 *in;
45 struct omap_video_timings timings;
47 struct platform_device *pdev;
51 struct backlight_device *bldev;
53 unsigned long hw_guard_end; /* next value of jiffies when we can
54 * issue the next sleep in/out command
56 unsigned long hw_guard_wait; /* max guard time in jiffies */
58 /* panel HW configuration from DT or platform data */
62 bool use_dsi_backlight;
64 struct omap_dsi_pin_config pin_config;
66 /* runtime variables */
74 struct delayed_work te_timeout_work;
79 unsigned ulps_timeout;
80 struct delayed_work ulps_work;
83 #define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
85 static irqreturn_t dsicm_te_isr(int irq, void *data);
86 static void dsicm_te_timeout_work_callback(struct work_struct *work);
87 static int _dsicm_enable_te(struct panel_drv_data *ddata, bool enable);
89 static int dsicm_panel_reset(struct panel_drv_data *ddata);
91 static void dsicm_ulps_work(struct work_struct *work);
93 static void hw_guard_start(struct panel_drv_data *ddata, int guard_msec)
95 ddata->hw_guard_wait = msecs_to_jiffies(guard_msec);
96 ddata->hw_guard_end = jiffies + ddata->hw_guard_wait;
99 static void hw_guard_wait(struct panel_drv_data *ddata)
101 unsigned long wait = ddata->hw_guard_end - jiffies;
103 if ((long)wait > 0 && wait <= ddata->hw_guard_wait) {
104 set_current_state(TASK_UNINTERRUPTIBLE);
105 schedule_timeout(wait);
109 static int dsicm_dcs_read_1(struct panel_drv_data *ddata, u8 dcs_cmd, u8 *data)
111 struct omap_dss_device *in = ddata->in;
115 r = in->ops.dsi->dcs_read(in, ddata->channel, dcs_cmd, buf, 1);
125 static int dsicm_dcs_write_0(struct panel_drv_data *ddata, u8 dcs_cmd)
127 struct omap_dss_device *in = ddata->in;
128 return in->ops.dsi->dcs_write(in, ddata->channel, &dcs_cmd, 1);
131 static int dsicm_dcs_write_1(struct panel_drv_data *ddata, u8 dcs_cmd, u8 param)
133 struct omap_dss_device *in = ddata->in;
134 u8 buf[2] = { dcs_cmd, param };
136 return in->ops.dsi->dcs_write(in, ddata->channel, buf, 2);
139 static int dsicm_sleep_in(struct panel_drv_data *ddata)
142 struct omap_dss_device *in = ddata->in;
146 hw_guard_wait(ddata);
148 cmd = MIPI_DCS_ENTER_SLEEP_MODE;
149 r = in->ops.dsi->dcs_write_nosync(in, ddata->channel, &cmd, 1);
153 hw_guard_start(ddata, 120);
155 usleep_range(5000, 10000);
160 static int dsicm_sleep_out(struct panel_drv_data *ddata)
164 hw_guard_wait(ddata);
166 r = dsicm_dcs_write_0(ddata, MIPI_DCS_EXIT_SLEEP_MODE);
170 hw_guard_start(ddata, 120);
172 usleep_range(5000, 10000);
177 static int dsicm_get_id(struct panel_drv_data *ddata, u8 *id1, u8 *id2, u8 *id3)
181 r = dsicm_dcs_read_1(ddata, DCS_GET_ID1, id1);
184 r = dsicm_dcs_read_1(ddata, DCS_GET_ID2, id2);
187 r = dsicm_dcs_read_1(ddata, DCS_GET_ID3, id3);
194 static int dsicm_set_update_window(struct panel_drv_data *ddata,
195 u16 x, u16 y, u16 w, u16 h)
197 struct omap_dss_device *in = ddata->in;
205 buf[0] = MIPI_DCS_SET_COLUMN_ADDRESS;
206 buf[1] = (x1 >> 8) & 0xff;
207 buf[2] = (x1 >> 0) & 0xff;
208 buf[3] = (x2 >> 8) & 0xff;
209 buf[4] = (x2 >> 0) & 0xff;
211 r = in->ops.dsi->dcs_write_nosync(in, ddata->channel, buf, sizeof(buf));
215 buf[0] = MIPI_DCS_SET_PAGE_ADDRESS;
216 buf[1] = (y1 >> 8) & 0xff;
217 buf[2] = (y1 >> 0) & 0xff;
218 buf[3] = (y2 >> 8) & 0xff;
219 buf[4] = (y2 >> 0) & 0xff;
221 r = in->ops.dsi->dcs_write_nosync(in, ddata->channel, buf, sizeof(buf));
225 in->ops.dsi->bta_sync(in, ddata->channel);
230 static void dsicm_queue_ulps_work(struct panel_drv_data *ddata)
232 if (ddata->ulps_timeout > 0)
233 schedule_delayed_work(&ddata->ulps_work,
234 msecs_to_jiffies(ddata->ulps_timeout));
237 static void dsicm_cancel_ulps_work(struct panel_drv_data *ddata)
239 cancel_delayed_work(&ddata->ulps_work);
242 static int dsicm_enter_ulps(struct panel_drv_data *ddata)
244 struct omap_dss_device *in = ddata->in;
247 if (ddata->ulps_enabled)
250 dsicm_cancel_ulps_work(ddata);
252 r = _dsicm_enable_te(ddata, false);
256 if (gpio_is_valid(ddata->ext_te_gpio))
257 disable_irq(gpio_to_irq(ddata->ext_te_gpio));
259 in->ops.dsi->disable(in, false, true);
261 ddata->ulps_enabled = true;
266 dev_err(&ddata->pdev->dev, "enter ULPS failed");
267 dsicm_panel_reset(ddata);
269 ddata->ulps_enabled = false;
271 dsicm_queue_ulps_work(ddata);
276 static int dsicm_exit_ulps(struct panel_drv_data *ddata)
278 struct omap_dss_device *in = ddata->in;
281 if (!ddata->ulps_enabled)
284 r = in->ops.dsi->enable(in);
286 dev_err(&ddata->pdev->dev, "failed to enable DSI\n");
290 in->ops.dsi->enable_hs(in, ddata->channel, true);
292 r = _dsicm_enable_te(ddata, true);
294 dev_err(&ddata->pdev->dev, "failed to re-enable TE");
298 if (gpio_is_valid(ddata->ext_te_gpio))
299 enable_irq(gpio_to_irq(ddata->ext_te_gpio));
301 dsicm_queue_ulps_work(ddata);
303 ddata->ulps_enabled = false;
308 dev_err(&ddata->pdev->dev, "failed to exit ULPS");
310 r = dsicm_panel_reset(ddata);
312 if (gpio_is_valid(ddata->ext_te_gpio))
313 enable_irq(gpio_to_irq(ddata->ext_te_gpio));
314 ddata->ulps_enabled = false;
317 dsicm_queue_ulps_work(ddata);
322 static int dsicm_wake_up(struct panel_drv_data *ddata)
324 if (ddata->ulps_enabled)
325 return dsicm_exit_ulps(ddata);
327 dsicm_cancel_ulps_work(ddata);
328 dsicm_queue_ulps_work(ddata);
332 static int dsicm_bl_update_status(struct backlight_device *dev)
334 struct panel_drv_data *ddata = dev_get_drvdata(&dev->dev);
335 struct omap_dss_device *in = ddata->in;
339 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
340 dev->props.power == FB_BLANK_UNBLANK)
341 level = dev->props.brightness;
345 dev_dbg(&ddata->pdev->dev, "update brightness to %d\n", level);
347 mutex_lock(&ddata->lock);
349 if (ddata->enabled) {
350 in->ops.dsi->bus_lock(in);
352 r = dsicm_wake_up(ddata);
354 r = dsicm_dcs_write_1(ddata, DCS_BRIGHTNESS, level);
356 in->ops.dsi->bus_unlock(in);
361 mutex_unlock(&ddata->lock);
366 static int dsicm_bl_get_intensity(struct backlight_device *dev)
368 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
369 dev->props.power == FB_BLANK_UNBLANK)
370 return dev->props.brightness;
375 static const struct backlight_ops dsicm_bl_ops = {
376 .get_brightness = dsicm_bl_get_intensity,
377 .update_status = dsicm_bl_update_status,
380 static void dsicm_get_resolution(struct omap_dss_device *dssdev,
381 u16 *xres, u16 *yres)
383 *xres = dssdev->panel.timings.x_res;
384 *yres = dssdev->panel.timings.y_res;
387 static ssize_t dsicm_num_errors_show(struct device *dev,
388 struct device_attribute *attr, char *buf)
390 struct platform_device *pdev = to_platform_device(dev);
391 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
392 struct omap_dss_device *in = ddata->in;
396 mutex_lock(&ddata->lock);
398 if (ddata->enabled) {
399 in->ops.dsi->bus_lock(in);
401 r = dsicm_wake_up(ddata);
403 r = dsicm_dcs_read_1(ddata, DCS_READ_NUM_ERRORS,
406 in->ops.dsi->bus_unlock(in);
411 mutex_unlock(&ddata->lock);
416 return sysfs_emit(buf, "%d\n", errors);
419 static ssize_t dsicm_hw_revision_show(struct device *dev,
420 struct device_attribute *attr, char *buf)
422 struct platform_device *pdev = to_platform_device(dev);
423 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
424 struct omap_dss_device *in = ddata->in;
428 mutex_lock(&ddata->lock);
430 if (ddata->enabled) {
431 in->ops.dsi->bus_lock(in);
433 r = dsicm_wake_up(ddata);
435 r = dsicm_get_id(ddata, &id1, &id2, &id3);
437 in->ops.dsi->bus_unlock(in);
442 mutex_unlock(&ddata->lock);
447 return sysfs_emit(buf, "%02x.%02x.%02x\n", id1, id2, id3);
450 static ssize_t dsicm_store_ulps(struct device *dev,
451 struct device_attribute *attr,
452 const char *buf, size_t count)
454 struct platform_device *pdev = to_platform_device(dev);
455 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
456 struct omap_dss_device *in = ddata->in;
460 r = kstrtoul(buf, 0, &t);
464 mutex_lock(&ddata->lock);
466 if (ddata->enabled) {
467 in->ops.dsi->bus_lock(in);
470 r = dsicm_enter_ulps(ddata);
472 r = dsicm_wake_up(ddata);
474 in->ops.dsi->bus_unlock(in);
477 mutex_unlock(&ddata->lock);
485 static ssize_t dsicm_show_ulps(struct device *dev,
486 struct device_attribute *attr,
489 struct platform_device *pdev = to_platform_device(dev);
490 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
493 mutex_lock(&ddata->lock);
494 t = ddata->ulps_enabled;
495 mutex_unlock(&ddata->lock);
497 return sysfs_emit(buf, "%u\n", t);
500 static ssize_t dsicm_store_ulps_timeout(struct device *dev,
501 struct device_attribute *attr,
502 const char *buf, size_t count)
504 struct platform_device *pdev = to_platform_device(dev);
505 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
506 struct omap_dss_device *in = ddata->in;
510 r = kstrtoul(buf, 0, &t);
514 mutex_lock(&ddata->lock);
515 ddata->ulps_timeout = t;
517 if (ddata->enabled) {
518 /* dsicm_wake_up will restart the timer */
519 in->ops.dsi->bus_lock(in);
520 r = dsicm_wake_up(ddata);
521 in->ops.dsi->bus_unlock(in);
524 mutex_unlock(&ddata->lock);
532 static ssize_t dsicm_show_ulps_timeout(struct device *dev,
533 struct device_attribute *attr,
536 struct platform_device *pdev = to_platform_device(dev);
537 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
540 mutex_lock(&ddata->lock);
541 t = ddata->ulps_timeout;
542 mutex_unlock(&ddata->lock);
544 return sysfs_emit(buf, "%u\n", t);
547 static DEVICE_ATTR(num_dsi_errors, S_IRUGO, dsicm_num_errors_show, NULL);
548 static DEVICE_ATTR(hw_revision, S_IRUGO, dsicm_hw_revision_show, NULL);
549 static DEVICE_ATTR(ulps, S_IRUGO | S_IWUSR,
550 dsicm_show_ulps, dsicm_store_ulps);
551 static DEVICE_ATTR(ulps_timeout, S_IRUGO | S_IWUSR,
552 dsicm_show_ulps_timeout, dsicm_store_ulps_timeout);
554 static struct attribute *dsicm_attrs[] = {
555 &dev_attr_num_dsi_errors.attr,
556 &dev_attr_hw_revision.attr,
558 &dev_attr_ulps_timeout.attr,
562 static struct attribute_group dsicm_attr_group = {
563 .attrs = dsicm_attrs,
566 static void dsicm_hw_reset(struct panel_drv_data *ddata)
568 if (!gpio_is_valid(ddata->reset_gpio))
571 gpio_set_value(ddata->reset_gpio, 1);
573 /* reset the panel */
574 gpio_set_value(ddata->reset_gpio, 0);
577 gpio_set_value(ddata->reset_gpio, 1);
578 /* wait after releasing reset */
579 usleep_range(5000, 10000);
582 static int dsicm_power_on(struct panel_drv_data *ddata)
584 struct omap_dss_device *in = ddata->in;
587 struct omap_dss_dsi_config dsi_config = {
588 .mode = OMAP_DSS_DSI_CMD_MODE,
589 .pixel_format = OMAP_DSS_DSI_FMT_RGB888,
590 .timings = &ddata->timings,
591 .hs_clk_min = 150000000,
592 .hs_clk_max = 300000000,
593 .lp_clk_min = 7000000,
594 .lp_clk_max = 10000000,
597 if (ddata->pin_config.num_pins > 0) {
598 r = in->ops.dsi->configure_pins(in, &ddata->pin_config);
600 dev_err(&ddata->pdev->dev,
601 "failed to configure DSI pins\n");
606 r = in->ops.dsi->set_config(in, &dsi_config);
608 dev_err(&ddata->pdev->dev, "failed to configure DSI\n");
612 r = in->ops.dsi->enable(in);
614 dev_err(&ddata->pdev->dev, "failed to enable DSI\n");
618 dsicm_hw_reset(ddata);
620 in->ops.dsi->enable_hs(in, ddata->channel, false);
622 r = dsicm_sleep_out(ddata);
626 r = dsicm_get_id(ddata, &id1, &id2, &id3);
630 r = dsicm_dcs_write_1(ddata, DCS_BRIGHTNESS, 0xff);
634 r = dsicm_dcs_write_1(ddata, DCS_CTRL_DISPLAY,
635 (1<<2) | (1<<5)); /* BL | BCTRL */
639 r = dsicm_dcs_write_1(ddata, MIPI_DCS_SET_PIXEL_FORMAT,
640 MIPI_DCS_PIXEL_FMT_24BIT);
644 r = dsicm_dcs_write_0(ddata, MIPI_DCS_SET_DISPLAY_ON);
648 r = _dsicm_enable_te(ddata, ddata->te_enabled);
652 r = in->ops.dsi->enable_video_output(in, ddata->channel);
658 if (!ddata->intro_printed) {
659 dev_info(&ddata->pdev->dev, "panel revision %02x.%02x.%02x\n",
661 ddata->intro_printed = true;
664 in->ops.dsi->enable_hs(in, ddata->channel, true);
668 dev_err(&ddata->pdev->dev, "error while enabling panel, issuing HW reset\n");
670 dsicm_hw_reset(ddata);
672 in->ops.dsi->disable(in, true, false);
677 static void dsicm_power_off(struct panel_drv_data *ddata)
679 struct omap_dss_device *in = ddata->in;
682 in->ops.dsi->disable_video_output(in, ddata->channel);
684 r = dsicm_dcs_write_0(ddata, MIPI_DCS_SET_DISPLAY_OFF);
686 r = dsicm_sleep_in(ddata);
689 dev_err(&ddata->pdev->dev,
690 "error disabling panel, issuing HW reset\n");
691 dsicm_hw_reset(ddata);
694 in->ops.dsi->disable(in, true, false);
699 static int dsicm_panel_reset(struct panel_drv_data *ddata)
701 dev_err(&ddata->pdev->dev, "performing LCD reset\n");
703 dsicm_power_off(ddata);
704 dsicm_hw_reset(ddata);
705 return dsicm_power_on(ddata);
708 static int dsicm_connect(struct omap_dss_device *dssdev)
710 struct panel_drv_data *ddata = to_panel_data(dssdev);
711 struct omap_dss_device *in = ddata->in;
712 struct device *dev = &ddata->pdev->dev;
715 if (omapdss_device_is_connected(dssdev))
718 r = in->ops.dsi->connect(in, dssdev);
720 dev_err(dev, "Failed to connect to video source\n");
724 r = in->ops.dsi->request_vc(ddata->in, &ddata->channel);
726 dev_err(dev, "failed to get virtual channel\n");
730 r = in->ops.dsi->set_vc_id(ddata->in, ddata->channel, TCH);
732 dev_err(dev, "failed to set VC_ID\n");
739 in->ops.dsi->release_vc(ddata->in, ddata->channel);
741 in->ops.dsi->disconnect(in, dssdev);
745 static void dsicm_disconnect(struct omap_dss_device *dssdev)
747 struct panel_drv_data *ddata = to_panel_data(dssdev);
748 struct omap_dss_device *in = ddata->in;
750 if (!omapdss_device_is_connected(dssdev))
753 in->ops.dsi->release_vc(in, ddata->channel);
754 in->ops.dsi->disconnect(in, dssdev);
757 static int dsicm_enable(struct omap_dss_device *dssdev)
759 struct panel_drv_data *ddata = to_panel_data(dssdev);
760 struct omap_dss_device *in = ddata->in;
763 dev_dbg(&ddata->pdev->dev, "enable\n");
765 mutex_lock(&ddata->lock);
767 if (!omapdss_device_is_connected(dssdev)) {
772 if (omapdss_device_is_enabled(dssdev)) {
777 in->ops.dsi->bus_lock(in);
779 r = dsicm_power_on(ddata);
781 in->ops.dsi->bus_unlock(in);
786 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
788 mutex_unlock(&ddata->lock);
792 dev_dbg(&ddata->pdev->dev, "enable failed\n");
793 mutex_unlock(&ddata->lock);
797 static void dsicm_disable(struct omap_dss_device *dssdev)
799 struct panel_drv_data *ddata = to_panel_data(dssdev);
800 struct omap_dss_device *in = ddata->in;
803 dev_dbg(&ddata->pdev->dev, "disable\n");
805 mutex_lock(&ddata->lock);
807 dsicm_cancel_ulps_work(ddata);
809 in->ops.dsi->bus_lock(in);
811 if (omapdss_device_is_enabled(dssdev)) {
812 r = dsicm_wake_up(ddata);
814 dsicm_power_off(ddata);
817 in->ops.dsi->bus_unlock(in);
819 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
821 mutex_unlock(&ddata->lock);
824 static void dsicm_framedone_cb(int err, void *data)
826 struct panel_drv_data *ddata = data;
827 struct omap_dss_device *in = ddata->in;
829 dev_dbg(&ddata->pdev->dev, "framedone, err %d\n", err);
830 in->ops.dsi->bus_unlock(ddata->in);
833 static irqreturn_t dsicm_te_isr(int irq, void *data)
835 struct panel_drv_data *ddata = data;
836 struct omap_dss_device *in = ddata->in;
840 old = atomic_cmpxchg(&ddata->do_update, 1, 0);
843 cancel_delayed_work(&ddata->te_timeout_work);
845 r = in->ops.dsi->update(in, ddata->channel, dsicm_framedone_cb,
853 dev_err(&ddata->pdev->dev, "start update failed\n");
854 in->ops.dsi->bus_unlock(in);
858 static void dsicm_te_timeout_work_callback(struct work_struct *work)
860 struct panel_drv_data *ddata = container_of(work, struct panel_drv_data,
861 te_timeout_work.work);
862 struct omap_dss_device *in = ddata->in;
864 dev_err(&ddata->pdev->dev, "TE not received for 250ms!\n");
866 atomic_set(&ddata->do_update, 0);
867 in->ops.dsi->bus_unlock(in);
870 static int dsicm_update(struct omap_dss_device *dssdev,
871 u16 x, u16 y, u16 w, u16 h)
873 struct panel_drv_data *ddata = to_panel_data(dssdev);
874 struct omap_dss_device *in = ddata->in;
877 dev_dbg(&ddata->pdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
879 mutex_lock(&ddata->lock);
880 in->ops.dsi->bus_lock(in);
882 r = dsicm_wake_up(ddata);
886 if (!ddata->enabled) {
891 /* XXX no need to send this every frame, but dsi break if not done */
892 r = dsicm_set_update_window(ddata, 0, 0,
893 dssdev->panel.timings.x_res,
894 dssdev->panel.timings.y_res);
898 if (ddata->te_enabled && gpio_is_valid(ddata->ext_te_gpio)) {
899 schedule_delayed_work(&ddata->te_timeout_work,
900 msecs_to_jiffies(250));
901 atomic_set(&ddata->do_update, 1);
903 r = in->ops.dsi->update(in, ddata->channel, dsicm_framedone_cb,
909 /* note: no bus_unlock here. unlock is in framedone_cb */
910 mutex_unlock(&ddata->lock);
913 in->ops.dsi->bus_unlock(in);
914 mutex_unlock(&ddata->lock);
918 static int dsicm_sync(struct omap_dss_device *dssdev)
920 struct panel_drv_data *ddata = to_panel_data(dssdev);
921 struct omap_dss_device *in = ddata->in;
923 dev_dbg(&ddata->pdev->dev, "sync\n");
925 mutex_lock(&ddata->lock);
926 in->ops.dsi->bus_lock(in);
927 in->ops.dsi->bus_unlock(in);
928 mutex_unlock(&ddata->lock);
930 dev_dbg(&ddata->pdev->dev, "sync done\n");
935 static int _dsicm_enable_te(struct panel_drv_data *ddata, bool enable)
937 struct omap_dss_device *in = ddata->in;
941 r = dsicm_dcs_write_1(ddata, MIPI_DCS_SET_TEAR_ON, 0);
943 r = dsicm_dcs_write_0(ddata, MIPI_DCS_SET_TEAR_OFF);
945 if (!gpio_is_valid(ddata->ext_te_gpio))
946 in->ops.dsi->enable_te(in, enable);
948 /* possible panel bug */
954 static int dsicm_enable_te(struct omap_dss_device *dssdev, bool enable)
956 struct panel_drv_data *ddata = to_panel_data(dssdev);
957 struct omap_dss_device *in = ddata->in;
960 mutex_lock(&ddata->lock);
962 if (ddata->te_enabled == enable)
965 in->ops.dsi->bus_lock(in);
967 if (ddata->enabled) {
968 r = dsicm_wake_up(ddata);
972 r = _dsicm_enable_te(ddata, enable);
977 ddata->te_enabled = enable;
979 in->ops.dsi->bus_unlock(in);
981 mutex_unlock(&ddata->lock);
985 in->ops.dsi->bus_unlock(in);
986 mutex_unlock(&ddata->lock);
991 static int dsicm_get_te(struct omap_dss_device *dssdev)
993 struct panel_drv_data *ddata = to_panel_data(dssdev);
996 mutex_lock(&ddata->lock);
997 r = ddata->te_enabled;
998 mutex_unlock(&ddata->lock);
1003 static int dsicm_memory_read(struct omap_dss_device *dssdev,
1004 void *buf, size_t size,
1005 u16 x, u16 y, u16 w, u16 h)
1007 struct panel_drv_data *ddata = to_panel_data(dssdev);
1008 struct omap_dss_device *in = ddata->in;
1012 unsigned buf_used = 0;
1014 if (size < w * h * 3)
1017 mutex_lock(&ddata->lock);
1019 if (!ddata->enabled) {
1024 size = min(w * h * 3,
1025 dssdev->panel.timings.x_res *
1026 dssdev->panel.timings.y_res * 3);
1028 in->ops.dsi->bus_lock(in);
1030 r = dsicm_wake_up(ddata);
1034 /* plen 1 or 2 goes into short packet. until checksum error is fixed,
1035 * use short packets. plen 32 works, but bigger packets seem to cause
1042 dsicm_set_update_window(ddata, x, y, w, h);
1044 r = in->ops.dsi->set_max_rx_packet_size(in, ddata->channel, plen);
1048 while (buf_used < size) {
1049 u8 dcs_cmd = first ? 0x2e : 0x3e;
1052 r = in->ops.dsi->dcs_read(in, ddata->channel, dcs_cmd,
1053 buf + buf_used, size - buf_used);
1056 dev_err(dssdev->dev, "read error\n");
1063 dev_err(&ddata->pdev->dev, "short read\n");
1067 if (signal_pending(current)) {
1068 dev_err(&ddata->pdev->dev, "signal pending, "
1069 "aborting memory read\n");
1078 in->ops.dsi->set_max_rx_packet_size(in, ddata->channel, 1);
1080 in->ops.dsi->bus_unlock(in);
1082 mutex_unlock(&ddata->lock);
1086 static void dsicm_ulps_work(struct work_struct *work)
1088 struct panel_drv_data *ddata = container_of(work, struct panel_drv_data,
1090 struct omap_dss_device *dssdev = &ddata->dssdev;
1091 struct omap_dss_device *in = ddata->in;
1093 mutex_lock(&ddata->lock);
1095 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE || !ddata->enabled) {
1096 mutex_unlock(&ddata->lock);
1100 in->ops.dsi->bus_lock(in);
1102 dsicm_enter_ulps(ddata);
1104 in->ops.dsi->bus_unlock(in);
1105 mutex_unlock(&ddata->lock);
1108 static struct omap_dss_driver dsicm_ops = {
1109 .connect = dsicm_connect,
1110 .disconnect = dsicm_disconnect,
1112 .enable = dsicm_enable,
1113 .disable = dsicm_disable,
1115 .update = dsicm_update,
1118 .get_resolution = dsicm_get_resolution,
1119 .get_recommended_bpp = omapdss_default_get_recommended_bpp,
1121 .enable_te = dsicm_enable_te,
1122 .get_te = dsicm_get_te,
1124 .memory_read = dsicm_memory_read,
1127 static int dsicm_probe_of(struct platform_device *pdev)
1129 struct device_node *node = pdev->dev.of_node;
1130 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
1131 struct omap_dss_device *in;
1134 gpio = of_get_named_gpio(node, "reset-gpios", 0);
1135 if (!gpio_is_valid(gpio)) {
1136 dev_err(&pdev->dev, "failed to parse reset gpio\n");
1139 ddata->reset_gpio = gpio;
1141 gpio = of_get_named_gpio(node, "te-gpios", 0);
1142 if (gpio_is_valid(gpio) || gpio == -ENOENT) {
1143 ddata->ext_te_gpio = gpio;
1145 dev_err(&pdev->dev, "failed to parse TE gpio\n");
1149 in = omapdss_of_find_source_for_first_ep(node);
1151 dev_err(&pdev->dev, "failed to find video source\n");
1157 /* TODO: ulps, backlight */
1162 static int dsicm_probe(struct platform_device *pdev)
1164 struct backlight_properties props;
1165 struct panel_drv_data *ddata;
1166 struct backlight_device *bldev = NULL;
1167 struct device *dev = &pdev->dev;
1168 struct omap_dss_device *dssdev;
1171 dev_dbg(dev, "probe\n");
1173 if (!pdev->dev.of_node)
1176 ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL);
1180 platform_set_drvdata(pdev, ddata);
1183 r = dsicm_probe_of(pdev);
1187 ddata->timings.x_res = 864;
1188 ddata->timings.y_res = 480;
1189 ddata->timings.pixelclock = 864 * 480 * 60;
1191 dssdev = &ddata->dssdev;
1193 dssdev->driver = &dsicm_ops;
1194 dssdev->panel.timings = ddata->timings;
1195 dssdev->type = OMAP_DISPLAY_TYPE_DSI;
1196 dssdev->owner = THIS_MODULE;
1198 dssdev->panel.dsi_pix_fmt = OMAP_DSS_DSI_FMT_RGB888;
1199 dssdev->caps = OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE |
1200 OMAP_DSS_DISPLAY_CAP_TEAR_ELIM;
1202 r = omapdss_register_display(dssdev);
1204 dev_err(dev, "Failed to register panel\n");
1208 mutex_init(&ddata->lock);
1210 atomic_set(&ddata->do_update, 0);
1212 if (gpio_is_valid(ddata->reset_gpio)) {
1213 r = devm_gpio_request_one(dev, ddata->reset_gpio,
1214 GPIOF_OUT_INIT_LOW, "taal rst");
1216 dev_err(dev, "failed to request reset gpio\n");
1221 if (gpio_is_valid(ddata->ext_te_gpio)) {
1222 r = devm_gpio_request_one(dev, ddata->ext_te_gpio,
1223 GPIOF_IN, "taal irq");
1225 dev_err(dev, "GPIO request failed\n");
1229 r = devm_request_irq(dev, gpio_to_irq(ddata->ext_te_gpio),
1231 IRQF_TRIGGER_RISING,
1232 "taal vsync", ddata);
1235 dev_err(dev, "IRQ request failed\n");
1239 INIT_DEFERRABLE_WORK(&ddata->te_timeout_work,
1240 dsicm_te_timeout_work_callback);
1242 dev_dbg(dev, "Using GPIO TE\n");
1245 INIT_DELAYED_WORK(&ddata->ulps_work, dsicm_ulps_work);
1247 dsicm_hw_reset(ddata);
1249 if (ddata->use_dsi_backlight) {
1250 memset(&props, 0, sizeof(struct backlight_properties));
1251 props.max_brightness = 255;
1253 props.type = BACKLIGHT_RAW;
1254 bldev = backlight_device_register(dev_name(dev),
1255 dev, ddata, &dsicm_bl_ops, &props);
1256 if (IS_ERR(bldev)) {
1261 ddata->bldev = bldev;
1263 bldev->props.fb_blank = FB_BLANK_UNBLANK;
1264 bldev->props.power = FB_BLANK_UNBLANK;
1265 bldev->props.brightness = 255;
1267 dsicm_bl_update_status(bldev);
1270 r = sysfs_create_group(&dev->kobj, &dsicm_attr_group);
1272 dev_err(dev, "failed to create sysfs files\n");
1273 goto err_sysfs_create;
1280 backlight_device_unregister(bldev);
1285 static int __exit dsicm_remove(struct platform_device *pdev)
1287 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
1288 struct omap_dss_device *dssdev = &ddata->dssdev;
1289 struct backlight_device *bldev;
1291 dev_dbg(&pdev->dev, "remove\n");
1293 omapdss_unregister_display(dssdev);
1295 dsicm_disable(dssdev);
1296 dsicm_disconnect(dssdev);
1298 sysfs_remove_group(&pdev->dev.kobj, &dsicm_attr_group);
1300 bldev = ddata->bldev;
1301 if (bldev != NULL) {
1302 bldev->props.power = FB_BLANK_POWERDOWN;
1303 dsicm_bl_update_status(bldev);
1304 backlight_device_unregister(bldev);
1307 omap_dss_put_device(ddata->in);
1309 dsicm_cancel_ulps_work(ddata);
1311 /* reset, to be sure that the panel is in a valid state */
1312 dsicm_hw_reset(ddata);
1317 static const struct of_device_id dsicm_of_match[] = {
1318 { .compatible = "omapdss,panel-dsi-cm", },
1322 MODULE_DEVICE_TABLE(of, dsicm_of_match);
1324 static struct platform_driver dsicm_driver = {
1325 .probe = dsicm_probe,
1326 .remove = __exit_p(dsicm_remove),
1328 .name = "panel-dsi-cm",
1329 .of_match_table = dsicm_of_match,
1330 .suppress_bind_attrs = true,
1334 module_platform_driver(dsicm_driver);
1336 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
1337 MODULE_DESCRIPTION("Generic DSI Command Mode Panel Driver");
1338 MODULE_LICENSE("GPL");