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/phy/phy.h>
34 #include <linux/regulator/consumer.h>
35 #include <linux/pm_runtime.h>
36 #include <linux/err.h>
38 #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 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 phy_power_on(dsim
->phy
);
161 clk_enable(dsim
->clock
);
163 exynos_mipi_update_cfg(dsim
);
165 /* set lcd panel sequence commands. */
166 if (client_drv
&& client_drv
->set_sequence
)
167 client_drv
->set_sequence(client_dev
);
169 dsim
->suspended
= false;
172 case FB_BLANK_NORMAL
:
182 int exynos_mipi_dsi_register_lcd_device(struct mipi_dsim_lcd_device
*lcd_dev
)
184 struct mipi_dsim_ddi
*dsim_ddi
;
186 if (!lcd_dev
->name
) {
187 pr_err("dsim_lcd_device name is NULL.\n");
191 dsim_ddi
= kzalloc(sizeof(struct mipi_dsim_ddi
), GFP_KERNEL
);
193 pr_err("failed to allocate dsim_ddi object.\n");
197 dsim_ddi
->dsim_lcd_dev
= lcd_dev
;
199 mutex_lock(&mipi_dsim_lock
);
200 list_add_tail(&dsim_ddi
->list
, &dsim_ddi_list
);
201 mutex_unlock(&mipi_dsim_lock
);
206 static struct mipi_dsim_ddi
*exynos_mipi_dsi_find_lcd_device(
207 struct mipi_dsim_lcd_driver
*lcd_drv
)
209 struct mipi_dsim_ddi
*dsim_ddi
, *next
;
210 struct mipi_dsim_lcd_device
*lcd_dev
;
212 mutex_lock(&mipi_dsim_lock
);
214 list_for_each_entry_safe(dsim_ddi
, next
, &dsim_ddi_list
, list
) {
218 lcd_dev
= dsim_ddi
->dsim_lcd_dev
;
222 if ((strcmp(lcd_drv
->name
, lcd_dev
->name
)) == 0) {
224 * bus_id would be used to identify
227 dsim_ddi
->bus_id
= lcd_dev
->bus_id
;
228 mutex_unlock(&mipi_dsim_lock
);
233 list_del(&dsim_ddi
->list
);
238 mutex_unlock(&mipi_dsim_lock
);
243 int exynos_mipi_dsi_register_lcd_driver(struct mipi_dsim_lcd_driver
*lcd_drv
)
245 struct mipi_dsim_ddi
*dsim_ddi
;
247 if (!lcd_drv
->name
) {
248 pr_err("dsim_lcd_driver name is NULL.\n");
252 dsim_ddi
= exynos_mipi_dsi_find_lcd_device(lcd_drv
);
254 pr_err("mipi_dsim_ddi object not found.\n");
258 dsim_ddi
->dsim_lcd_drv
= lcd_drv
;
260 pr_info("registered panel driver(%s) to mipi-dsi driver.\n",
267 static struct mipi_dsim_ddi
*exynos_mipi_dsi_bind_lcd_ddi(
268 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
= devm_kzalloc(&pdev
->dev
, sizeof(struct mipi_dsim_device
),
342 dev_err(&pdev
->dev
, "failed to allocate dsim object.\n");
346 dsim
->pd
= to_dsim_plat(pdev
);
347 dsim
->dev
= &pdev
->dev
;
350 /* get mipi_dsim_platform_data. */
351 dsim_pd
= (struct mipi_dsim_platform_data
*)dsim
->pd
;
352 if (dsim_pd
== NULL
) {
353 dev_err(&pdev
->dev
, "failed to get platform data for dsim.\n");
356 /* get mipi_dsim_config. */
357 dsim_config
= dsim_pd
->dsim_config
;
358 if (dsim_config
== NULL
) {
359 dev_err(&pdev
->dev
, "failed to get dsim config data.\n");
363 dsim
->dsim_config
= dsim_config
;
364 dsim
->master_ops
= &master_ops
;
366 mutex_init(&dsim
->lock
);
368 ret
= devm_regulator_bulk_get(&pdev
->dev
, ARRAY_SIZE(supplies
),
371 dev_err(&pdev
->dev
, "Failed to get regulators: %d\n", ret
);
375 dsim
->phy
= devm_phy_get(&pdev
->dev
, "dsim");
376 if (IS_ERR(dsim
->phy
))
377 return PTR_ERR(dsim
->phy
);
379 dsim
->clock
= devm_clk_get(&pdev
->dev
, "dsim0");
380 if (IS_ERR(dsim
->clock
)) {
381 dev_err(&pdev
->dev
, "failed to get dsim clock source\n");
385 clk_enable(dsim
->clock
);
387 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
389 dsim
->reg_base
= devm_ioremap_resource(&pdev
->dev
, res
);
390 if (IS_ERR(dsim
->reg_base
)) {
391 ret
= PTR_ERR(dsim
->reg_base
);
395 mutex_init(&dsim
->lock
);
397 /* bind lcd ddi matched with panel name. */
398 dsim_ddi
= exynos_mipi_dsi_bind_lcd_ddi(dsim
, dsim_pd
->lcd_panel_name
);
400 dev_err(&pdev
->dev
, "mipi_dsim_ddi object not found.\n");
405 dsim
->irq
= platform_get_irq(pdev
, 0);
406 if (IS_ERR_VALUE(dsim
->irq
)) {
407 dev_err(&pdev
->dev
, "failed to request dsim irq resource\n");
412 init_completion(&dsim_wr_comp
);
413 init_completion(&dsim_rd_comp
);
414 platform_set_drvdata(pdev
, dsim
);
416 ret
= devm_request_irq(&pdev
->dev
, dsim
->irq
,
417 exynos_mipi_dsi_interrupt_handler
,
418 IRQF_SHARED
, dev_name(&pdev
->dev
), dsim
);
420 dev_err(&pdev
->dev
, "failed to request dsim irq\n");
425 /* enable interrupts */
426 exynos_mipi_dsi_init_interrupt(dsim
);
428 /* initialize mipi-dsi client(lcd panel). */
429 if (dsim_ddi
->dsim_lcd_drv
&& dsim_ddi
->dsim_lcd_drv
->probe
)
430 dsim_ddi
->dsim_lcd_drv
->probe(dsim_ddi
->dsim_lcd_dev
);
432 /* in case mipi-dsi has been enabled by bootloader */
433 if (dsim_pd
->enabled
) {
434 exynos_mipi_regulator_enable(dsim
);
438 /* lcd panel power on. */
439 if (dsim_ddi
->dsim_lcd_drv
&& dsim_ddi
->dsim_lcd_drv
->power_on
)
440 dsim_ddi
->dsim_lcd_drv
->power_on(dsim_ddi
->dsim_lcd_dev
, 1);
442 exynos_mipi_regulator_enable(dsim
);
444 /* enable MIPI-DSI PHY. */
445 phy_power_on(dsim
->phy
);
447 exynos_mipi_update_cfg(dsim
);
449 /* set lcd panel sequence commands. */
450 if (dsim_ddi
->dsim_lcd_drv
&& dsim_ddi
->dsim_lcd_drv
->set_sequence
)
451 dsim_ddi
->dsim_lcd_drv
->set_sequence(dsim_ddi
->dsim_lcd_dev
);
453 dsim
->suspended
= false;
456 platform_set_drvdata(pdev
, dsim
);
458 dev_dbg(&pdev
->dev
, "%s() completed successfully (%s mode)\n", __func__
,
459 dsim_config
->e_interface
== DSIM_COMMAND
? "CPU" : "RGB");
464 clk_disable(dsim
->clock
);
468 static int exynos_mipi_dsi_remove(struct platform_device
*pdev
)
470 struct mipi_dsim_device
*dsim
= platform_get_drvdata(pdev
);
471 struct mipi_dsim_ddi
*dsim_ddi
, *next
;
472 struct mipi_dsim_lcd_driver
*dsim_lcd_drv
;
474 clk_disable(dsim
->clock
);
476 list_for_each_entry_safe(dsim_ddi
, next
, &dsim_ddi_list
, list
) {
478 if (dsim
->id
!= dsim_ddi
->bus_id
)
481 dsim_lcd_drv
= dsim_ddi
->dsim_lcd_drv
;
483 if (dsim_lcd_drv
->remove
)
484 dsim_lcd_drv
->remove(dsim_ddi
->dsim_lcd_dev
);
493 #ifdef CONFIG_PM_SLEEP
494 static int exynos_mipi_dsi_suspend(struct device
*dev
)
496 struct platform_device
*pdev
= to_platform_device(dev
);
497 struct mipi_dsim_device
*dsim
= platform_get_drvdata(pdev
);
498 struct mipi_dsim_lcd_driver
*client_drv
= dsim
->dsim_lcd_drv
;
499 struct mipi_dsim_lcd_device
*client_dev
= dsim
->dsim_lcd_dev
;
501 disable_irq(dsim
->irq
);
506 if (client_drv
&& client_drv
->suspend
)
507 client_drv
->suspend(client_dev
);
509 /* disable MIPI-DSI PHY. */
510 phy_power_off(dsim
->phy
);
512 clk_disable(dsim
->clock
);
514 exynos_mipi_regulator_disable(dsim
);
516 dsim
->suspended
= true;
521 static int exynos_mipi_dsi_resume(struct device
*dev
)
523 struct platform_device
*pdev
= to_platform_device(dev
);
524 struct mipi_dsim_device
*dsim
= platform_get_drvdata(pdev
);
525 struct mipi_dsim_lcd_driver
*client_drv
= dsim
->dsim_lcd_drv
;
526 struct mipi_dsim_lcd_device
*client_dev
= dsim
->dsim_lcd_dev
;
528 enable_irq(dsim
->irq
);
530 if (!dsim
->suspended
)
533 /* lcd panel power on. */
534 if (client_drv
&& client_drv
->power_on
)
535 client_drv
->power_on(client_dev
, 1);
537 exynos_mipi_regulator_enable(dsim
);
539 /* enable MIPI-DSI PHY. */
540 phy_power_on(dsim
->phy
);
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");