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>
35 #include <linux/err.h>
37 #include <video/exynos_mipi_dsim.h>
39 #include "exynos_mipi_dsi_common.h"
40 #include "exynos_mipi_dsi_lowlevel.h"
42 struct mipi_dsim_ddi
{
44 struct list_head list
;
45 struct mipi_dsim_lcd_device
*dsim_lcd_dev
;
46 struct mipi_dsim_lcd_driver
*dsim_lcd_drv
;
49 static LIST_HEAD(dsim_ddi_list
);
51 static DEFINE_MUTEX(mipi_dsim_lock
);
53 static struct mipi_dsim_platform_data
*to_dsim_plat(struct platform_device
56 return pdev
->dev
.platform_data
;
59 static struct regulator_bulk_data supplies
[] = {
60 { .supply
= "vdd11", },
61 { .supply
= "vdd18", },
64 static int exynos_mipi_regulator_enable(struct mipi_dsim_device
*dsim
)
68 mutex_lock(&dsim
->lock
);
69 ret
= regulator_bulk_enable(ARRAY_SIZE(supplies
), supplies
);
70 mutex_unlock(&dsim
->lock
);
75 static int exynos_mipi_regulator_disable(struct mipi_dsim_device
*dsim
)
79 mutex_lock(&dsim
->lock
);
80 ret
= regulator_bulk_disable(ARRAY_SIZE(supplies
), supplies
);
81 mutex_unlock(&dsim
->lock
);
86 /* update all register settings to MIPI DSI controller. */
87 static void exynos_mipi_update_cfg(struct mipi_dsim_device
*dsim
)
90 * data from Display controller(FIMD) is not transferred in video mode
91 * but in case of command mode, all settings is not updated to
94 exynos_mipi_dsi_stand_by(dsim
, 0);
96 exynos_mipi_dsi_init_dsim(dsim
);
97 exynos_mipi_dsi_init_link(dsim
);
99 exynos_mipi_dsi_set_hs_enable(dsim
);
101 /* set display timing. */
102 exynos_mipi_dsi_set_display_mode(dsim
, dsim
->dsim_config
);
104 exynos_mipi_dsi_init_interrupt(dsim
);
107 * data from Display controller(FIMD) is transferred in video mode
108 * but in case of command mode, all settings are updated to registers.
110 exynos_mipi_dsi_stand_by(dsim
, 1);
113 static int exynos_mipi_dsi_early_blank_mode(struct mipi_dsim_device
*dsim
,
116 struct mipi_dsim_lcd_driver
*client_drv
= dsim
->dsim_lcd_drv
;
117 struct mipi_dsim_lcd_device
*client_dev
= dsim
->dsim_lcd_dev
;
120 case FB_BLANK_POWERDOWN
:
124 if (client_drv
&& client_drv
->suspend
)
125 client_drv
->suspend(client_dev
);
127 clk_disable(dsim
->clock
);
129 exynos_mipi_regulator_disable(dsim
);
131 dsim
->suspended
= true;
141 static int exynos_mipi_dsi_blank_mode(struct mipi_dsim_device
*dsim
, int power
)
143 struct platform_device
*pdev
= to_platform_device(dsim
->dev
);
144 struct mipi_dsim_lcd_driver
*client_drv
= dsim
->dsim_lcd_drv
;
145 struct mipi_dsim_lcd_device
*client_dev
= dsim
->dsim_lcd_dev
;
148 case FB_BLANK_UNBLANK
:
149 if (!dsim
->suspended
)
152 /* lcd panel power on. */
153 if (client_drv
&& client_drv
->power_on
)
154 client_drv
->power_on(client_dev
, 1);
156 exynos_mipi_regulator_enable(dsim
);
158 /* enable MIPI-DSI PHY. */
159 if (dsim
->pd
->phy_enable
)
160 dsim
->pd
->phy_enable(pdev
, true);
162 clk_enable(dsim
->clock
);
164 exynos_mipi_update_cfg(dsim
);
166 /* set lcd panel sequence commands. */
167 if (client_drv
&& client_drv
->set_sequence
)
168 client_drv
->set_sequence(client_dev
);
170 dsim
->suspended
= false;
173 case FB_BLANK_NORMAL
:
183 int exynos_mipi_dsi_register_lcd_device(struct mipi_dsim_lcd_device
*lcd_dev
)
185 struct mipi_dsim_ddi
*dsim_ddi
;
187 if (!lcd_dev
->name
) {
188 pr_err("dsim_lcd_device name is NULL.\n");
192 dsim_ddi
= kzalloc(sizeof(struct mipi_dsim_ddi
), GFP_KERNEL
);
194 pr_err("failed to allocate dsim_ddi object.\n");
198 dsim_ddi
->dsim_lcd_dev
= lcd_dev
;
200 mutex_lock(&mipi_dsim_lock
);
201 list_add_tail(&dsim_ddi
->list
, &dsim_ddi_list
);
202 mutex_unlock(&mipi_dsim_lock
);
207 static struct mipi_dsim_ddi
*exynos_mipi_dsi_find_lcd_device(
208 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 static struct mipi_dsim_ddi
*exynos_mipi_dsi_bind_lcd_ddi(
269 struct mipi_dsim_device
*dsim
,
272 struct mipi_dsim_ddi
*dsim_ddi
, *next
;
273 struct mipi_dsim_lcd_driver
*lcd_drv
;
274 struct mipi_dsim_lcd_device
*lcd_dev
;
277 mutex_lock(&dsim
->lock
);
279 list_for_each_entry_safe(dsim_ddi
, next
, &dsim_ddi_list
, list
) {
280 lcd_drv
= dsim_ddi
->dsim_lcd_drv
;
281 lcd_dev
= dsim_ddi
->dsim_lcd_dev
;
282 if (!lcd_drv
|| !lcd_dev
||
283 (dsim
->id
!= dsim_ddi
->bus_id
))
286 dev_dbg(dsim
->dev
, "lcd_drv->id = %d, lcd_dev->id = %d\n",
287 lcd_drv
->id
, lcd_dev
->id
);
288 dev_dbg(dsim
->dev
, "lcd_dev->bus_id = %d, dsim->id = %d\n",
289 lcd_dev
->bus_id
, dsim
->id
);
291 if ((strcmp(lcd_drv
->name
, name
) == 0)) {
292 lcd_dev
->master
= dsim
;
294 lcd_dev
->dev
.parent
= dsim
->dev
;
295 dev_set_name(&lcd_dev
->dev
, "%s", lcd_drv
->name
);
297 ret
= device_register(&lcd_dev
->dev
);
300 "can't register %s, status %d\n",
301 dev_name(&lcd_dev
->dev
), ret
);
302 mutex_unlock(&dsim
->lock
);
307 dsim
->dsim_lcd_dev
= lcd_dev
;
308 dsim
->dsim_lcd_drv
= lcd_drv
;
310 mutex_unlock(&dsim
->lock
);
316 mutex_unlock(&dsim
->lock
);
321 /* define MIPI-DSI Master operations. */
322 static struct mipi_dsim_master_ops master_ops
= {
323 .cmd_read
= exynos_mipi_dsi_rd_data
,
324 .cmd_write
= exynos_mipi_dsi_wr_data
,
325 .get_dsim_frame_done
= exynos_mipi_dsi_get_frame_done_status
,
326 .clear_dsim_frame_done
= exynos_mipi_dsi_clear_frame_done
,
327 .set_early_blank_mode
= exynos_mipi_dsi_early_blank_mode
,
328 .set_blank_mode
= exynos_mipi_dsi_blank_mode
,
331 static int exynos_mipi_dsi_probe(struct platform_device
*pdev
)
333 struct resource
*res
;
334 struct mipi_dsim_device
*dsim
;
335 struct mipi_dsim_config
*dsim_config
;
336 struct mipi_dsim_platform_data
*dsim_pd
;
337 struct mipi_dsim_ddi
*dsim_ddi
;
340 dsim
= devm_kzalloc(&pdev
->dev
, sizeof(struct mipi_dsim_device
),
343 dev_err(&pdev
->dev
, "failed to allocate dsim object.\n");
347 dsim
->pd
= to_dsim_plat(pdev
);
348 dsim
->dev
= &pdev
->dev
;
351 /* get mipi_dsim_platform_data. */
352 dsim_pd
= (struct mipi_dsim_platform_data
*)dsim
->pd
;
353 if (dsim_pd
== NULL
) {
354 dev_err(&pdev
->dev
, "failed to get platform data for dsim.\n");
357 /* get mipi_dsim_config. */
358 dsim_config
= dsim_pd
->dsim_config
;
359 if (dsim_config
== NULL
) {
360 dev_err(&pdev
->dev
, "failed to get dsim config data.\n");
364 dsim
->dsim_config
= dsim_config
;
365 dsim
->master_ops
= &master_ops
;
367 mutex_init(&dsim
->lock
);
369 ret
= devm_regulator_bulk_get(&pdev
->dev
, ARRAY_SIZE(supplies
),
372 dev_err(&pdev
->dev
, "Failed to get regulators: %d\n", ret
);
376 dsim
->clock
= devm_clk_get(&pdev
->dev
, "dsim0");
377 if (IS_ERR(dsim
->clock
)) {
378 dev_err(&pdev
->dev
, "failed to get dsim clock source\n");
382 clk_enable(dsim
->clock
);
384 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
386 dsim
->reg_base
= devm_ioremap_resource(&pdev
->dev
, res
);
387 if (IS_ERR(dsim
->reg_base
)) {
388 ret
= PTR_ERR(dsim
->reg_base
);
392 mutex_init(&dsim
->lock
);
394 /* bind lcd ddi matched with panel name. */
395 dsim_ddi
= exynos_mipi_dsi_bind_lcd_ddi(dsim
, dsim_pd
->lcd_panel_name
);
397 dev_err(&pdev
->dev
, "mipi_dsim_ddi object not found.\n");
402 dsim
->irq
= platform_get_irq(pdev
, 0);
403 if (IS_ERR_VALUE(dsim
->irq
)) {
404 dev_err(&pdev
->dev
, "failed to request dsim irq resource\n");
409 init_completion(&dsim_wr_comp
);
410 init_completion(&dsim_rd_comp
);
411 platform_set_drvdata(pdev
, dsim
);
413 ret
= devm_request_irq(&pdev
->dev
, dsim
->irq
,
414 exynos_mipi_dsi_interrupt_handler
,
415 IRQF_SHARED
, dev_name(&pdev
->dev
), dsim
);
417 dev_err(&pdev
->dev
, "failed to request dsim irq\n");
422 /* enable interrupts */
423 exynos_mipi_dsi_init_interrupt(dsim
);
425 /* initialize mipi-dsi client(lcd panel). */
426 if (dsim_ddi
->dsim_lcd_drv
&& dsim_ddi
->dsim_lcd_drv
->probe
)
427 dsim_ddi
->dsim_lcd_drv
->probe(dsim_ddi
->dsim_lcd_dev
);
429 /* in case mipi-dsi has been enabled by bootloader */
430 if (dsim_pd
->enabled
) {
431 exynos_mipi_regulator_enable(dsim
);
435 /* lcd panel power on. */
436 if (dsim_ddi
->dsim_lcd_drv
&& dsim_ddi
->dsim_lcd_drv
->power_on
)
437 dsim_ddi
->dsim_lcd_drv
->power_on(dsim_ddi
->dsim_lcd_dev
, 1);
439 exynos_mipi_regulator_enable(dsim
);
441 /* enable MIPI-DSI PHY. */
442 if (dsim
->pd
->phy_enable
)
443 dsim
->pd
->phy_enable(pdev
, true);
445 exynos_mipi_update_cfg(dsim
);
447 /* set lcd panel sequence commands. */
448 if (dsim_ddi
->dsim_lcd_drv
&& dsim_ddi
->dsim_lcd_drv
->set_sequence
)
449 dsim_ddi
->dsim_lcd_drv
->set_sequence(dsim_ddi
->dsim_lcd_dev
);
451 dsim
->suspended
= false;
454 platform_set_drvdata(pdev
, dsim
);
456 dev_dbg(&pdev
->dev
, "%s() completed successfully (%s mode)\n", __func__
,
457 dsim_config
->e_interface
== DSIM_COMMAND
? "CPU" : "RGB");
462 clk_disable(dsim
->clock
);
466 static int exynos_mipi_dsi_remove(struct platform_device
*pdev
)
468 struct mipi_dsim_device
*dsim
= platform_get_drvdata(pdev
);
469 struct mipi_dsim_ddi
*dsim_ddi
, *next
;
470 struct mipi_dsim_lcd_driver
*dsim_lcd_drv
;
472 clk_disable(dsim
->clock
);
474 list_for_each_entry_safe(dsim_ddi
, next
, &dsim_ddi_list
, list
) {
476 if (dsim
->id
!= dsim_ddi
->bus_id
)
479 dsim_lcd_drv
= dsim_ddi
->dsim_lcd_drv
;
481 if (dsim_lcd_drv
->remove
)
482 dsim_lcd_drv
->remove(dsim_ddi
->dsim_lcd_dev
);
491 #ifdef CONFIG_PM_SLEEP
492 static int exynos_mipi_dsi_suspend(struct device
*dev
)
494 struct platform_device
*pdev
= to_platform_device(dev
);
495 struct mipi_dsim_device
*dsim
= platform_get_drvdata(pdev
);
496 struct mipi_dsim_lcd_driver
*client_drv
= dsim
->dsim_lcd_drv
;
497 struct mipi_dsim_lcd_device
*client_dev
= dsim
->dsim_lcd_dev
;
499 disable_irq(dsim
->irq
);
504 if (client_drv
&& client_drv
->suspend
)
505 client_drv
->suspend(client_dev
);
507 /* enable MIPI-DSI PHY. */
508 if (dsim
->pd
->phy_enable
)
509 dsim
->pd
->phy_enable(pdev
, false);
511 clk_disable(dsim
->clock
);
513 exynos_mipi_regulator_disable(dsim
);
515 dsim
->suspended
= true;
520 static int exynos_mipi_dsi_resume(struct device
*dev
)
522 struct platform_device
*pdev
= to_platform_device(dev
);
523 struct mipi_dsim_device
*dsim
= platform_get_drvdata(pdev
);
524 struct mipi_dsim_lcd_driver
*client_drv
= dsim
->dsim_lcd_drv
;
525 struct mipi_dsim_lcd_device
*client_dev
= dsim
->dsim_lcd_dev
;
527 enable_irq(dsim
->irq
);
529 if (!dsim
->suspended
)
532 /* lcd panel power on. */
533 if (client_drv
&& client_drv
->power_on
)
534 client_drv
->power_on(client_dev
, 1);
536 exynos_mipi_regulator_enable(dsim
);
538 /* enable MIPI-DSI PHY. */
539 if (dsim
->pd
->phy_enable
)
540 dsim
->pd
->phy_enable(pdev
, true);
542 clk_enable(dsim
->clock
);
544 exynos_mipi_update_cfg(dsim
);
546 /* set lcd panel sequence commands. */
547 if (client_drv
&& client_drv
->set_sequence
)
548 client_drv
->set_sequence(client_dev
);
550 dsim
->suspended
= false;
556 static const struct dev_pm_ops exynos_mipi_dsi_pm_ops
= {
557 SET_SYSTEM_SLEEP_PM_OPS(exynos_mipi_dsi_suspend
, exynos_mipi_dsi_resume
)
560 static struct platform_driver exynos_mipi_dsi_driver
= {
561 .probe
= exynos_mipi_dsi_probe
,
562 .remove
= exynos_mipi_dsi_remove
,
564 .name
= "exynos-mipi-dsim",
565 .owner
= THIS_MODULE
,
566 .pm
= &exynos_mipi_dsi_pm_ops
,
570 module_platform_driver(exynos_mipi_dsi_driver
);
572 MODULE_AUTHOR("InKi Dae <inki.dae@samsung.com>");
573 MODULE_DESCRIPTION("Samusung SoC MIPI-DSI driver");
574 MODULE_LICENSE("GPL");