1 /* linux/drivers/video/exynos/exynos_mipi_dsi.c
3 * Samsung SoC MIPI-DSIM driver.
5 * Copyright (c) 2012 Samsung Electronics Co., Ltd
7 * InKi Dae, <inki.dae@samsung.com>
8 * Donghwa Lee, <dh09.lee@samsung.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/errno.h>
18 #include <linux/clk.h>
19 #include <linux/mutex.h>
20 #include <linux/wait.h>
24 #include <linux/ctype.h>
25 #include <linux/platform_device.h>
27 #include <linux/irq.h>
28 #include <linux/memory.h>
29 #include <linux/delay.h>
30 #include <linux/interrupt.h>
31 #include <linux/kthread.h>
32 #include <linux/notifier.h>
33 #include <linux/regulator/consumer.h>
34 #include <linux/pm_runtime.h>
36 #include <video/exynos_mipi_dsim.h>
40 #include "exynos_mipi_dsi_common.h"
41 #include "exynos_mipi_dsi_lowlevel.h"
43 struct mipi_dsim_ddi
{
45 struct list_head list
;
46 struct mipi_dsim_lcd_device
*dsim_lcd_dev
;
47 struct mipi_dsim_lcd_driver
*dsim_lcd_drv
;
50 static LIST_HEAD(dsim_ddi_list
);
52 static DEFINE_MUTEX(mipi_dsim_lock
);
54 static struct mipi_dsim_platform_data
*to_dsim_plat(struct platform_device
57 return pdev
->dev
.platform_data
;
60 static struct regulator_bulk_data supplies
[] = {
61 { .supply
= "vdd11", },
62 { .supply
= "vdd18", },
65 static int exynos_mipi_regulator_enable(struct mipi_dsim_device
*dsim
)
69 mutex_lock(&dsim
->lock
);
70 ret
= regulator_bulk_enable(ARRAY_SIZE(supplies
), supplies
);
71 mutex_unlock(&dsim
->lock
);
76 static int exynos_mipi_regulator_disable(struct mipi_dsim_device
*dsim
)
80 mutex_lock(&dsim
->lock
);
81 ret
= regulator_bulk_disable(ARRAY_SIZE(supplies
), supplies
);
82 mutex_unlock(&dsim
->lock
);
87 /* update all register settings to MIPI DSI controller. */
88 static void exynos_mipi_update_cfg(struct mipi_dsim_device
*dsim
)
91 * data from Display controller(FIMD) is not transferred in video mode
92 * but in case of command mode, all settings is not updated to
95 exynos_mipi_dsi_stand_by(dsim
, 0);
97 exynos_mipi_dsi_init_dsim(dsim
);
98 exynos_mipi_dsi_init_link(dsim
);
100 exynos_mipi_dsi_set_hs_enable(dsim
);
102 /* set display timing. */
103 exynos_mipi_dsi_set_display_mode(dsim
, dsim
->dsim_config
);
105 exynos_mipi_dsi_init_interrupt(dsim
);
108 * data from Display controller(FIMD) is transferred in video mode
109 * but in case of command mode, all settings are updated to registers.
111 exynos_mipi_dsi_stand_by(dsim
, 1);
114 static int exynos_mipi_dsi_early_blank_mode(struct mipi_dsim_device
*dsim
,
117 struct mipi_dsim_lcd_driver
*client_drv
= dsim
->dsim_lcd_drv
;
118 struct mipi_dsim_lcd_device
*client_dev
= dsim
->dsim_lcd_dev
;
121 case FB_BLANK_POWERDOWN
:
125 if (client_drv
&& client_drv
->suspend
)
126 client_drv
->suspend(client_dev
);
128 clk_disable(dsim
->clock
);
130 exynos_mipi_regulator_disable(dsim
);
132 dsim
->suspended
= true;
142 static int exynos_mipi_dsi_blank_mode(struct mipi_dsim_device
*dsim
, int power
)
144 struct platform_device
*pdev
= to_platform_device(dsim
->dev
);
145 struct mipi_dsim_lcd_driver
*client_drv
= dsim
->dsim_lcd_drv
;
146 struct mipi_dsim_lcd_device
*client_dev
= dsim
->dsim_lcd_dev
;
149 case FB_BLANK_UNBLANK
:
150 if (!dsim
->suspended
)
153 /* lcd panel power on. */
154 if (client_drv
&& client_drv
->power_on
)
155 client_drv
->power_on(client_dev
, 1);
157 exynos_mipi_regulator_enable(dsim
);
159 /* enable MIPI-DSI PHY. */
160 if (dsim
->pd
->phy_enable
)
161 dsim
->pd
->phy_enable(pdev
, true);
163 clk_enable(dsim
->clock
);
165 exynos_mipi_update_cfg(dsim
);
167 /* set lcd panel sequence commands. */
168 if (client_drv
&& client_drv
->set_sequence
)
169 client_drv
->set_sequence(client_dev
);
171 dsim
->suspended
= false;
174 case FB_BLANK_NORMAL
:
184 int exynos_mipi_dsi_register_lcd_device(struct mipi_dsim_lcd_device
*lcd_dev
)
186 struct mipi_dsim_ddi
*dsim_ddi
;
188 if (!lcd_dev
->name
) {
189 pr_err("dsim_lcd_device name is NULL.\n");
193 dsim_ddi
= kzalloc(sizeof(struct mipi_dsim_ddi
), GFP_KERNEL
);
195 pr_err("failed to allocate dsim_ddi object.\n");
199 dsim_ddi
->dsim_lcd_dev
= lcd_dev
;
201 mutex_lock(&mipi_dsim_lock
);
202 list_add_tail(&dsim_ddi
->list
, &dsim_ddi_list
);
203 mutex_unlock(&mipi_dsim_lock
);
208 struct mipi_dsim_ddi
*exynos_mipi_dsi_find_lcd_device(struct mipi_dsim_lcd_driver
*lcd_drv
)
210 struct mipi_dsim_ddi
*dsim_ddi
, *next
;
211 struct mipi_dsim_lcd_device
*lcd_dev
;
213 mutex_lock(&mipi_dsim_lock
);
215 list_for_each_entry_safe(dsim_ddi
, next
, &dsim_ddi_list
, list
) {
219 lcd_dev
= dsim_ddi
->dsim_lcd_dev
;
223 if ((strcmp(lcd_drv
->name
, lcd_dev
->name
)) == 0) {
225 * bus_id would be used to identify
228 dsim_ddi
->bus_id
= lcd_dev
->bus_id
;
229 mutex_unlock(&mipi_dsim_lock
);
234 list_del(&dsim_ddi
->list
);
239 mutex_unlock(&mipi_dsim_lock
);
244 int exynos_mipi_dsi_register_lcd_driver(struct mipi_dsim_lcd_driver
*lcd_drv
)
246 struct mipi_dsim_ddi
*dsim_ddi
;
248 if (!lcd_drv
->name
) {
249 pr_err("dsim_lcd_driver name is NULL.\n");
253 dsim_ddi
= exynos_mipi_dsi_find_lcd_device(lcd_drv
);
255 pr_err("mipi_dsim_ddi object not found.\n");
259 dsim_ddi
->dsim_lcd_drv
= lcd_drv
;
261 pr_info("registered panel driver(%s) to mipi-dsi driver.\n",
268 struct mipi_dsim_ddi
*exynos_mipi_dsi_bind_lcd_ddi(struct mipi_dsim_device
*dsim
,
271 struct mipi_dsim_ddi
*dsim_ddi
, *next
;
272 struct mipi_dsim_lcd_driver
*lcd_drv
;
273 struct mipi_dsim_lcd_device
*lcd_dev
;
276 mutex_lock(&dsim
->lock
);
278 list_for_each_entry_safe(dsim_ddi
, next
, &dsim_ddi_list
, list
) {
279 lcd_drv
= dsim_ddi
->dsim_lcd_drv
;
280 lcd_dev
= dsim_ddi
->dsim_lcd_dev
;
281 if (!lcd_drv
|| !lcd_dev
||
282 (dsim
->id
!= dsim_ddi
->bus_id
))
285 dev_dbg(dsim
->dev
, "lcd_drv->id = %d, lcd_dev->id = %d\n",
286 lcd_drv
->id
, lcd_dev
->id
);
287 dev_dbg(dsim
->dev
, "lcd_dev->bus_id = %d, dsim->id = %d\n",
288 lcd_dev
->bus_id
, dsim
->id
);
290 if ((strcmp(lcd_drv
->name
, name
) == 0)) {
291 lcd_dev
->master
= dsim
;
293 lcd_dev
->dev
.parent
= dsim
->dev
;
294 dev_set_name(&lcd_dev
->dev
, "%s", lcd_drv
->name
);
296 ret
= device_register(&lcd_dev
->dev
);
299 "can't register %s, status %d\n",
300 dev_name(&lcd_dev
->dev
), ret
);
301 mutex_unlock(&dsim
->lock
);
306 dsim
->dsim_lcd_dev
= lcd_dev
;
307 dsim
->dsim_lcd_drv
= lcd_drv
;
309 mutex_unlock(&dsim
->lock
);
315 mutex_unlock(&dsim
->lock
);
320 /* define MIPI-DSI Master operations. */
321 static struct mipi_dsim_master_ops master_ops
= {
322 .cmd_read
= exynos_mipi_dsi_rd_data
,
323 .cmd_write
= exynos_mipi_dsi_wr_data
,
324 .get_dsim_frame_done
= exynos_mipi_dsi_get_frame_done_status
,
325 .clear_dsim_frame_done
= exynos_mipi_dsi_clear_frame_done
,
326 .set_early_blank_mode
= exynos_mipi_dsi_early_blank_mode
,
327 .set_blank_mode
= exynos_mipi_dsi_blank_mode
,
330 static int exynos_mipi_dsi_probe(struct platform_device
*pdev
)
332 struct resource
*res
;
333 struct mipi_dsim_device
*dsim
;
334 struct mipi_dsim_config
*dsim_config
;
335 struct mipi_dsim_platform_data
*dsim_pd
;
336 struct mipi_dsim_ddi
*dsim_ddi
;
339 dsim
= kzalloc(sizeof(struct mipi_dsim_device
), GFP_KERNEL
);
341 dev_err(&pdev
->dev
, "failed to allocate dsim object.\n");
345 dsim
->pd
= to_dsim_plat(pdev
);
346 dsim
->dev
= &pdev
->dev
;
349 /* get mipi_dsim_platform_data. */
350 dsim_pd
= (struct mipi_dsim_platform_data
*)dsim
->pd
;
351 if (dsim_pd
== NULL
) {
352 dev_err(&pdev
->dev
, "failed to get platform data for dsim.\n");
355 /* get mipi_dsim_config. */
356 dsim_config
= dsim_pd
->dsim_config
;
357 if (dsim_config
== NULL
) {
358 dev_err(&pdev
->dev
, "failed to get dsim config data.\n");
362 dsim
->dsim_config
= dsim_config
;
363 dsim
->master_ops
= &master_ops
;
365 mutex_init(&dsim
->lock
);
367 ret
= regulator_bulk_get(&pdev
->dev
, ARRAY_SIZE(supplies
), supplies
);
369 dev_err(&pdev
->dev
, "Failed to get regulators: %d\n", ret
);
373 dsim
->clock
= clk_get(&pdev
->dev
, "dsim0");
374 if (IS_ERR(dsim
->clock
)) {
375 dev_err(&pdev
->dev
, "failed to get dsim clock source\n");
379 clk_enable(dsim
->clock
);
381 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
383 dev_err(&pdev
->dev
, "failed to get io memory region\n");
384 goto err_platform_get
;
387 dsim
->res
= request_mem_region(res
->start
, resource_size(res
),
388 dev_name(&pdev
->dev
));
390 dev_err(&pdev
->dev
, "failed to request io memory region\n");
395 dsim
->reg_base
= ioremap(res
->start
, resource_size(res
));
396 if (!dsim
->reg_base
) {
397 dev_err(&pdev
->dev
, "failed to remap io region\n");
402 mutex_init(&dsim
->lock
);
404 /* bind lcd ddi matched with panel name. */
405 dsim_ddi
= exynos_mipi_dsi_bind_lcd_ddi(dsim
, dsim_pd
->lcd_panel_name
);
407 dev_err(&pdev
->dev
, "mipi_dsim_ddi object not found.\n");
411 dsim
->irq
= platform_get_irq(pdev
, 0);
413 dev_err(&pdev
->dev
, "failed to request dsim irq resource\n");
415 goto err_platform_get_irq
;
418 init_completion(&dsim_wr_comp
);
419 init_completion(&dsim_rd_comp
);
420 platform_set_drvdata(pdev
, dsim
);
422 ret
= request_irq(dsim
->irq
, exynos_mipi_dsi_interrupt_handler
,
423 IRQF_SHARED
, dev_name(&pdev
->dev
), dsim
);
425 dev_err(&pdev
->dev
, "failed to request dsim irq\n");
430 /* enable interrupts */
431 exynos_mipi_dsi_init_interrupt(dsim
);
433 /* initialize mipi-dsi client(lcd panel). */
434 if (dsim_ddi
->dsim_lcd_drv
&& dsim_ddi
->dsim_lcd_drv
->probe
)
435 dsim_ddi
->dsim_lcd_drv
->probe(dsim_ddi
->dsim_lcd_dev
);
437 /* in case mipi-dsi has been enabled by bootloader */
438 if (dsim_pd
->enabled
) {
439 exynos_mipi_regulator_enable(dsim
);
443 /* lcd panel power on. */
444 if (dsim_ddi
->dsim_lcd_drv
&& dsim_ddi
->dsim_lcd_drv
->power_on
)
445 dsim_ddi
->dsim_lcd_drv
->power_on(dsim_ddi
->dsim_lcd_dev
, 1);
447 exynos_mipi_regulator_enable(dsim
);
449 /* enable MIPI-DSI PHY. */
450 if (dsim
->pd
->phy_enable
)
451 dsim
->pd
->phy_enable(pdev
, true);
453 exynos_mipi_update_cfg(dsim
);
455 /* set lcd panel sequence commands. */
456 if (dsim_ddi
->dsim_lcd_drv
&& dsim_ddi
->dsim_lcd_drv
->set_sequence
)
457 dsim_ddi
->dsim_lcd_drv
->set_sequence(dsim_ddi
->dsim_lcd_dev
);
459 dsim
->suspended
= false;
462 platform_set_drvdata(pdev
, dsim
);
464 dev_dbg(&pdev
->dev
, "%s() completed sucessfuly (%s mode)\n", __func__
,
465 dsim_config
->e_interface
== DSIM_COMMAND
? "CPU" : "RGB");
470 iounmap(dsim
->reg_base
);
473 release_mem_region(dsim
->res
->start
, resource_size(dsim
->res
));
476 release_resource(dsim
->res
);
479 clk_disable(dsim
->clock
);
480 clk_put(dsim
->clock
);
484 err_platform_get_irq
:
488 static int __devexit
exynos_mipi_dsi_remove(struct platform_device
*pdev
)
490 struct mipi_dsim_device
*dsim
= platform_get_drvdata(pdev
);
491 struct mipi_dsim_ddi
*dsim_ddi
, *next
;
492 struct mipi_dsim_lcd_driver
*dsim_lcd_drv
;
494 iounmap(dsim
->reg_base
);
496 clk_disable(dsim
->clock
);
497 clk_put(dsim
->clock
);
499 release_resource(dsim
->res
);
500 release_mem_region(dsim
->res
->start
, resource_size(dsim
->res
));
502 list_for_each_entry_safe(dsim_ddi
, next
, &dsim_ddi_list
, list
) {
504 if (dsim
->id
!= dsim_ddi
->bus_id
)
507 dsim_lcd_drv
= dsim_ddi
->dsim_lcd_drv
;
509 if (dsim_lcd_drv
->remove
)
510 dsim_lcd_drv
->remove(dsim_ddi
->dsim_lcd_dev
);
516 regulator_bulk_free(ARRAY_SIZE(supplies
), supplies
);
522 #ifdef CONFIG_PM_SLEEP
523 static int exynos_mipi_dsi_suspend(struct device
*dev
)
525 struct platform_device
*pdev
= to_platform_device(dev
);
526 struct mipi_dsim_device
*dsim
= platform_get_drvdata(pdev
);
527 struct mipi_dsim_lcd_driver
*client_drv
= dsim
->dsim_lcd_drv
;
528 struct mipi_dsim_lcd_device
*client_dev
= dsim
->dsim_lcd_dev
;
530 disable_irq(dsim
->irq
);
535 if (client_drv
&& client_drv
->suspend
)
536 client_drv
->suspend(client_dev
);
538 /* enable MIPI-DSI PHY. */
539 if (dsim
->pd
->phy_enable
)
540 dsim
->pd
->phy_enable(pdev
, false);
542 clk_disable(dsim
->clock
);
544 exynos_mipi_regulator_disable(dsim
);
546 dsim
->suspended
= true;
551 static int exynos_mipi_dsi_resume(struct device
*dev
)
553 struct platform_device
*pdev
= to_platform_device(dev
);
554 struct mipi_dsim_device
*dsim
= platform_get_drvdata(pdev
);
555 struct mipi_dsim_lcd_driver
*client_drv
= dsim
->dsim_lcd_drv
;
556 struct mipi_dsim_lcd_device
*client_dev
= dsim
->dsim_lcd_dev
;
558 enable_irq(dsim
->irq
);
560 if (!dsim
->suspended
)
563 /* lcd panel power on. */
564 if (client_drv
&& client_drv
->power_on
)
565 client_drv
->power_on(client_dev
, 1);
567 exynos_mipi_regulator_enable(dsim
);
569 /* enable MIPI-DSI PHY. */
570 if (dsim
->pd
->phy_enable
)
571 dsim
->pd
->phy_enable(pdev
, true);
573 clk_enable(dsim
->clock
);
575 exynos_mipi_update_cfg(dsim
);
577 /* set lcd panel sequence commands. */
578 if (client_drv
&& client_drv
->set_sequence
)
579 client_drv
->set_sequence(client_dev
);
581 dsim
->suspended
= false;
587 static const struct dev_pm_ops exynos_mipi_dsi_pm_ops
= {
588 SET_SYSTEM_SLEEP_PM_OPS(exynos_mipi_dsi_suspend
, exynos_mipi_dsi_resume
)
591 static struct platform_driver exynos_mipi_dsi_driver
= {
592 .probe
= exynos_mipi_dsi_probe
,
593 .remove
= __devexit_p(exynos_mipi_dsi_remove
),
595 .name
= "exynos-mipi-dsim",
596 .owner
= THIS_MODULE
,
597 .pm
= &exynos_mipi_dsi_pm_ops
,
601 module_platform_driver(exynos_mipi_dsi_driver
);
603 MODULE_AUTHOR("InKi Dae <inki.dae@samsung.com>");
604 MODULE_DESCRIPTION("Samusung SoC MIPI-DSI driver");
605 MODULE_LICENSE("GPL");