2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2012-04-05 19:36:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Samsung Electronics
|
|
|
|
*
|
|
|
|
* Author: InKi Dae <inki.dae@samsung.com>
|
|
|
|
* Author: Donghwa Lee <dh09.lee@samsung.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2012-04-05 19:36:21 +00:00
|
|
|
#include <malloc.h>
|
2014-03-07 13:59:39 +00:00
|
|
|
#include <fdtdec.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2020-02-03 14:36:15 +00:00
|
|
|
#include <dm/devres.h>
|
2018-03-04 16:20:11 +00:00
|
|
|
#include <linux/libfdt.h>
|
2014-06-24 08:10:03 +00:00
|
|
|
#include <linux/compat.h>
|
2012-04-05 19:36:21 +00:00
|
|
|
#include <linux/err.h>
|
|
|
|
#include <asm/arch/dsim.h>
|
|
|
|
#include <asm/arch/mipi_dsim.h>
|
|
|
|
#include <asm/arch/power.h>
|
|
|
|
#include <asm/arch/cpu.h>
|
|
|
|
#include <asm/arch/clk.h>
|
|
|
|
|
|
|
|
#include "exynos_mipi_dsi_lowlevel.h"
|
|
|
|
#include "exynos_mipi_dsi_common.h"
|
|
|
|
|
|
|
|
#define master_to_driver(a) (a->dsim_lcd_drv)
|
|
|
|
#define master_to_device(a) (a->dsim_lcd_dev)
|
|
|
|
|
2014-03-07 13:59:39 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2012-04-05 19:36:21 +00:00
|
|
|
struct mipi_dsim_ddi {
|
|
|
|
int bus_id;
|
|
|
|
struct list_head list;
|
|
|
|
struct mipi_dsim_lcd_device *dsim_lcd_dev;
|
|
|
|
struct mipi_dsim_lcd_driver *dsim_lcd_drv;
|
|
|
|
};
|
|
|
|
|
|
|
|
static LIST_HEAD(dsim_ddi_list);
|
|
|
|
static LIST_HEAD(dsim_lcd_dev_list);
|
|
|
|
|
|
|
|
int exynos_mipi_dsi_register_lcd_device(struct mipi_dsim_lcd_device *lcd_dev)
|
|
|
|
{
|
|
|
|
struct mipi_dsim_ddi *dsim_ddi;
|
|
|
|
|
|
|
|
if (!lcd_dev) {
|
|
|
|
debug("mipi_dsim_lcd_device is NULL.\n");
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!lcd_dev->name) {
|
|
|
|
debug("dsim_lcd_device name is NULL.\n");
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
dsim_ddi = kzalloc(sizeof(struct mipi_dsim_ddi), GFP_KERNEL);
|
|
|
|
if (!dsim_ddi) {
|
|
|
|
debug("failed to allocate dsim_ddi object.\n");
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
dsim_ddi->dsim_lcd_dev = lcd_dev;
|
|
|
|
|
|
|
|
list_add_tail(&dsim_ddi->list, &dsim_ddi_list);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct mipi_dsim_ddi
|
|
|
|
*exynos_mipi_dsi_find_lcd_device(struct mipi_dsim_lcd_driver *lcd_drv)
|
|
|
|
{
|
|
|
|
struct mipi_dsim_ddi *dsim_ddi;
|
|
|
|
struct mipi_dsim_lcd_device *lcd_dev;
|
|
|
|
|
|
|
|
list_for_each_entry(dsim_ddi, &dsim_ddi_list, list) {
|
|
|
|
lcd_dev = dsim_ddi->dsim_lcd_dev;
|
|
|
|
if (!lcd_dev)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (lcd_drv->id >= 0) {
|
|
|
|
if ((strcmp(lcd_drv->name, lcd_dev->name)) == 0 &&
|
|
|
|
lcd_drv->id == lcd_dev->id) {
|
|
|
|
/**
|
|
|
|
* bus_id would be used to identify
|
|
|
|
* connected bus.
|
|
|
|
*/
|
|
|
|
dsim_ddi->bus_id = lcd_dev->bus_id;
|
|
|
|
|
|
|
|
return dsim_ddi;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ((strcmp(lcd_drv->name, lcd_dev->name)) == 0) {
|
|
|
|
/**
|
|
|
|
* bus_id would be used to identify
|
|
|
|
* connected bus.
|
|
|
|
*/
|
|
|
|
dsim_ddi->bus_id = lcd_dev->bus_id;
|
|
|
|
|
|
|
|
return dsim_ddi;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree(dsim_ddi);
|
|
|
|
list_del(&dsim_ddi_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int exynos_mipi_dsi_register_lcd_driver(struct mipi_dsim_lcd_driver *lcd_drv)
|
|
|
|
{
|
|
|
|
struct mipi_dsim_ddi *dsim_ddi;
|
|
|
|
|
|
|
|
if (!lcd_drv) {
|
|
|
|
debug("mipi_dsim_lcd_driver is NULL.\n");
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!lcd_drv->name) {
|
|
|
|
debug("dsim_lcd_driver name is NULL.\n");
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
dsim_ddi = exynos_mipi_dsi_find_lcd_device(lcd_drv);
|
|
|
|
if (!dsim_ddi) {
|
|
|
|
debug("mipi_dsim_ddi object not found.\n");
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
dsim_ddi->dsim_lcd_drv = lcd_drv;
|
|
|
|
|
|
|
|
debug("registered panel driver(%s) to mipi-dsi driver.\n",
|
|
|
|
lcd_drv->name);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
struct mipi_dsim_ddi
|
|
|
|
*exynos_mipi_dsi_bind_lcd_ddi(struct mipi_dsim_device *dsim,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
struct mipi_dsim_ddi *dsim_ddi;
|
|
|
|
struct mipi_dsim_lcd_driver *lcd_drv;
|
|
|
|
struct mipi_dsim_lcd_device *lcd_dev;
|
|
|
|
|
|
|
|
list_for_each_entry(dsim_ddi, &dsim_ddi_list, list) {
|
|
|
|
lcd_drv = dsim_ddi->dsim_lcd_drv;
|
|
|
|
lcd_dev = dsim_ddi->dsim_lcd_dev;
|
|
|
|
if (!lcd_drv || !lcd_dev)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
debug("lcd_drv->id = %d, lcd_dev->id = %d\n",
|
|
|
|
lcd_drv->id, lcd_dev->id);
|
|
|
|
|
|
|
|
if ((strcmp(lcd_drv->name, name) == 0)) {
|
|
|
|
lcd_dev->master = dsim;
|
|
|
|
|
|
|
|
dsim->dsim_lcd_dev = lcd_dev;
|
|
|
|
dsim->dsim_lcd_drv = lcd_drv;
|
|
|
|
|
|
|
|
return dsim_ddi;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* define MIPI-DSI Master operations. */
|
|
|
|
static struct mipi_dsim_master_ops master_ops = {
|
|
|
|
.cmd_write = exynos_mipi_dsi_wr_data,
|
|
|
|
.get_dsim_frame_done = exynos_mipi_dsi_get_frame_done_status,
|
|
|
|
.clear_dsim_frame_done = exynos_mipi_dsi_clear_frame_done,
|
|
|
|
};
|
|
|
|
|
2016-02-22 04:08:46 +00:00
|
|
|
int exynos_mipi_dsi_init(struct exynos_platform_mipi_dsim *dsim_pd)
|
2012-04-05 19:36:21 +00:00
|
|
|
{
|
|
|
|
struct mipi_dsim_device *dsim;
|
|
|
|
struct mipi_dsim_config *dsim_config;
|
|
|
|
struct mipi_dsim_ddi *dsim_ddi;
|
|
|
|
|
|
|
|
dsim = kzalloc(sizeof(struct mipi_dsim_device), GFP_KERNEL);
|
|
|
|
if (!dsim) {
|
|
|
|
debug("failed to allocate dsim object.\n");
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get mipi_dsim_config. */
|
|
|
|
dsim_config = dsim_pd->dsim_config;
|
|
|
|
if (dsim_config == NULL) {
|
|
|
|
debug("failed to get dsim config data.\n");
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
dsim->pd = dsim_pd;
|
|
|
|
dsim->dsim_config = dsim_config;
|
|
|
|
dsim->master_ops = &master_ops;
|
|
|
|
|
|
|
|
/* bind lcd ddi matched with panel name. */
|
|
|
|
dsim_ddi = exynos_mipi_dsi_bind_lcd_ddi(dsim, dsim_pd->lcd_panel_name);
|
|
|
|
if (!dsim_ddi) {
|
|
|
|
debug("mipi_dsim_ddi object not found.\n");
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
if (dsim_pd->lcd_power)
|
|
|
|
dsim_pd->lcd_power();
|
|
|
|
|
|
|
|
if (dsim_pd->mipi_power)
|
|
|
|
dsim_pd->mipi_power();
|
|
|
|
|
|
|
|
/* phy_enable(unsigned int dev_index, unsigned int enable) */
|
|
|
|
if (dsim_pd->phy_enable)
|
|
|
|
dsim_pd->phy_enable(0, 1);
|
|
|
|
|
|
|
|
set_mipi_clk();
|
|
|
|
|
|
|
|
exynos_mipi_dsi_init_dsim(dsim);
|
|
|
|
exynos_mipi_dsi_init_link(dsim);
|
|
|
|
exynos_mipi_dsi_set_hs_enable(dsim);
|
|
|
|
|
|
|
|
/* set display timing. */
|
|
|
|
exynos_mipi_dsi_set_display_mode(dsim, dsim->dsim_config);
|
|
|
|
|
|
|
|
/* initialize mipi-dsi client(lcd panel). */
|
|
|
|
if (dsim_ddi->dsim_lcd_drv && dsim_ddi->dsim_lcd_drv->mipi_panel_init) {
|
|
|
|
dsim_ddi->dsim_lcd_drv->mipi_panel_init(dsim);
|
|
|
|
dsim_ddi->dsim_lcd_drv->mipi_display_on(dsim);
|
|
|
|
}
|
|
|
|
|
|
|
|
debug("mipi-dsi driver(%s mode) has been probed.\n",
|
|
|
|
(dsim_config->e_interface == DSIM_COMMAND) ?
|
|
|
|
"CPU" : "RGB");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-22 04:08:47 +00:00
|
|
|
int exynos_dsim_config_parse_dt(const void *blob, struct mipi_dsim_config *dt,
|
|
|
|
struct mipi_dsim_lcd_device *lcd_dt)
|
2014-03-07 13:59:39 +00:00
|
|
|
{
|
|
|
|
int node;
|
|
|
|
|
|
|
|
node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS_MIPI_DSI);
|
|
|
|
if (node <= 0) {
|
|
|
|
printf("exynos_mipi_dsi: Can't get device node for mipi dsi\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2016-02-22 04:08:45 +00:00
|
|
|
dt->e_interface = fdtdec_get_int(blob, node,
|
2014-03-07 13:59:39 +00:00
|
|
|
"samsung,dsim-config-e-interface", 0);
|
|
|
|
|
2016-02-22 04:08:45 +00:00
|
|
|
dt->e_virtual_ch = fdtdec_get_int(blob, node,
|
2014-03-07 13:59:39 +00:00
|
|
|
"samsung,dsim-config-e-virtual-ch", 0);
|
|
|
|
|
2016-02-22 04:08:45 +00:00
|
|
|
dt->e_pixel_format = fdtdec_get_int(blob, node,
|
2014-03-07 13:59:39 +00:00
|
|
|
"samsung,dsim-config-e-pixel-format", 0);
|
|
|
|
|
2016-02-22 04:08:45 +00:00
|
|
|
dt->e_burst_mode = fdtdec_get_int(blob, node,
|
2014-03-07 13:59:39 +00:00
|
|
|
"samsung,dsim-config-e-burst-mode", 0);
|
|
|
|
|
2016-02-22 04:08:45 +00:00
|
|
|
dt->e_no_data_lane = fdtdec_get_int(blob, node,
|
2014-03-07 13:59:39 +00:00
|
|
|
"samsung,dsim-config-e-no-data-lane", 0);
|
|
|
|
|
2016-02-22 04:08:45 +00:00
|
|
|
dt->e_byte_clk = fdtdec_get_int(blob, node,
|
2014-03-07 13:59:39 +00:00
|
|
|
"samsung,dsim-config-e-byte-clk", 0);
|
|
|
|
|
2016-02-22 04:08:45 +00:00
|
|
|
dt->hfp = fdtdec_get_int(blob, node,
|
2014-03-07 13:59:39 +00:00
|
|
|
"samsung,dsim-config-hfp", 0);
|
|
|
|
|
2016-02-22 04:08:45 +00:00
|
|
|
dt->p = fdtdec_get_int(blob, node,
|
2014-03-07 13:59:39 +00:00
|
|
|
"samsung,dsim-config-p", 0);
|
2016-02-22 04:08:45 +00:00
|
|
|
dt->m = fdtdec_get_int(blob, node,
|
2014-03-07 13:59:39 +00:00
|
|
|
"samsung,dsim-config-m", 0);
|
2016-02-22 04:08:45 +00:00
|
|
|
dt->s = fdtdec_get_int(blob, node,
|
2014-03-07 13:59:39 +00:00
|
|
|
"samsung,dsim-config-s", 0);
|
|
|
|
|
2016-02-22 04:08:45 +00:00
|
|
|
dt->pll_stable_time = fdtdec_get_int(blob, node,
|
2014-03-07 13:59:39 +00:00
|
|
|
"samsung,dsim-config-pll-stable-time", 0);
|
|
|
|
|
2016-02-22 04:08:45 +00:00
|
|
|
dt->esc_clk = fdtdec_get_int(blob, node,
|
2014-03-07 13:59:39 +00:00
|
|
|
"samsung,dsim-config-esc-clk", 0);
|
|
|
|
|
2016-02-22 04:08:45 +00:00
|
|
|
dt->stop_holding_cnt = fdtdec_get_int(blob, node,
|
2014-03-07 13:59:39 +00:00
|
|
|
"samsung,dsim-config-stop-holding-cnt", 0);
|
|
|
|
|
2016-02-22 04:08:45 +00:00
|
|
|
dt->bta_timeout = fdtdec_get_int(blob, node,
|
2014-03-07 13:59:39 +00:00
|
|
|
"samsung,dsim-config-bta-timeout", 0);
|
|
|
|
|
2016-02-22 04:08:45 +00:00
|
|
|
dt->rx_timeout = fdtdec_get_int(blob, node,
|
2014-03-07 13:59:39 +00:00
|
|
|
"samsung,dsim-config-rx-timeout", 0);
|
|
|
|
|
2021-08-07 13:24:01 +00:00
|
|
|
lcd_dt->name = fdt_getprop(blob, node, "samsung,dsim-device-name",
|
|
|
|
NULL);
|
2014-03-07 13:59:39 +00:00
|
|
|
|
2016-02-22 04:08:47 +00:00
|
|
|
lcd_dt->id = fdtdec_get_int(blob, node,
|
2014-03-07 13:59:39 +00:00
|
|
|
"samsung,dsim-device-id", 0);
|
|
|
|
|
2016-02-22 04:08:47 +00:00
|
|
|
lcd_dt->bus_id = fdtdec_get_int(blob, node,
|
2014-03-07 13:59:39 +00:00
|
|
|
"samsung,dsim-device-bus_id", 0);
|
|
|
|
|
2016-02-22 04:08:47 +00:00
|
|
|
lcd_dt->reverse_panel = fdtdec_get_int(blob, node,
|
2014-03-07 13:59:39 +00:00
|
|
|
"samsung,dsim-device-reverse-panel", 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void exynos_init_dsim_platform_data(vidinfo_t *vid)
|
|
|
|
{
|
2016-02-22 04:08:46 +00:00
|
|
|
static struct mipi_dsim_config dsim_config_dt;
|
|
|
|
static struct exynos_platform_mipi_dsim dsim_platform_data_dt;
|
2016-02-22 04:08:47 +00:00
|
|
|
static struct mipi_dsim_lcd_device mipi_lcd_device_dt;
|
2016-02-22 04:08:45 +00:00
|
|
|
|
2016-02-22 04:08:47 +00:00
|
|
|
if (exynos_dsim_config_parse_dt(gd->fdt_blob, &dsim_config_dt,
|
|
|
|
&mipi_lcd_device_dt))
|
2014-03-07 13:59:39 +00:00
|
|
|
debug("Can't get proper dsim config.\n");
|
|
|
|
|
|
|
|
strcpy(dsim_platform_data_dt.lcd_panel_name, mipi_lcd_device_dt.name);
|
|
|
|
dsim_platform_data_dt.dsim_config = &dsim_config_dt;
|
|
|
|
dsim_platform_data_dt.mipi_power = mipi_power;
|
|
|
|
dsim_platform_data_dt.phy_enable = set_mipi_phy_ctrl;
|
|
|
|
dsim_platform_data_dt.lcd_panel_info = (void *)vid;
|
|
|
|
|
|
|
|
mipi_lcd_device_dt.platform_data = (void *)&dsim_platform_data_dt;
|
|
|
|
exynos_mipi_dsi_register_lcd_device(&mipi_lcd_device_dt);
|
|
|
|
|
2016-02-22 04:08:46 +00:00
|
|
|
vid->dsim_platform_data_dt = &dsim_platform_data_dt;
|
2014-03-07 13:59:39 +00:00
|
|
|
}
|