Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Donghwa Lee | d84f783 | 2012-04-05 19:36:21 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2012 Samsung Electronics |
| 4 | * |
| 5 | * Author: InKi Dae <inki.dae@samsung.com> |
| 6 | * Author: Donghwa Lee <dh09.lee@samsung.com> |
Donghwa Lee | d84f783 | 2012-04-05 19:36:21 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Donghwa Lee | d84f783 | 2012-04-05 19:36:21 +0000 | [diff] [blame] | 11 | #include <malloc.h> |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 12 | #include <fdtdec.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 13 | #include <dm/devres.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 14 | #include <linux/libfdt.h> |
Heiko Schocher | 4f7a9a3 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 15 | #include <linux/compat.h> |
Donghwa Lee | d84f783 | 2012-04-05 19:36:21 +0000 | [diff] [blame] | 16 | #include <linux/err.h> |
| 17 | #include <asm/arch/dsim.h> |
| 18 | #include <asm/arch/mipi_dsim.h> |
| 19 | #include <asm/arch/power.h> |
| 20 | #include <asm/arch/cpu.h> |
| 21 | #include <asm/arch/clk.h> |
| 22 | |
| 23 | #include "exynos_mipi_dsi_lowlevel.h" |
| 24 | #include "exynos_mipi_dsi_common.h" |
| 25 | |
| 26 | #define master_to_driver(a) (a->dsim_lcd_drv) |
| 27 | #define master_to_device(a) (a->dsim_lcd_dev) |
| 28 | |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 29 | DECLARE_GLOBAL_DATA_PTR; |
| 30 | |
Donghwa Lee | d84f783 | 2012-04-05 19:36:21 +0000 | [diff] [blame] | 31 | struct mipi_dsim_ddi { |
| 32 | int bus_id; |
| 33 | struct list_head list; |
| 34 | struct mipi_dsim_lcd_device *dsim_lcd_dev; |
| 35 | struct mipi_dsim_lcd_driver *dsim_lcd_drv; |
| 36 | }; |
| 37 | |
| 38 | static LIST_HEAD(dsim_ddi_list); |
| 39 | static LIST_HEAD(dsim_lcd_dev_list); |
| 40 | |
| 41 | int exynos_mipi_dsi_register_lcd_device(struct mipi_dsim_lcd_device *lcd_dev) |
| 42 | { |
| 43 | struct mipi_dsim_ddi *dsim_ddi; |
| 44 | |
| 45 | if (!lcd_dev) { |
| 46 | debug("mipi_dsim_lcd_device is NULL.\n"); |
| 47 | return -EFAULT; |
| 48 | } |
| 49 | |
| 50 | if (!lcd_dev->name) { |
| 51 | debug("dsim_lcd_device name is NULL.\n"); |
| 52 | return -EFAULT; |
| 53 | } |
| 54 | |
| 55 | dsim_ddi = kzalloc(sizeof(struct mipi_dsim_ddi), GFP_KERNEL); |
| 56 | if (!dsim_ddi) { |
| 57 | debug("failed to allocate dsim_ddi object.\n"); |
| 58 | return -EFAULT; |
| 59 | } |
| 60 | |
| 61 | dsim_ddi->dsim_lcd_dev = lcd_dev; |
| 62 | |
| 63 | list_add_tail(&dsim_ddi->list, &dsim_ddi_list); |
| 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | struct mipi_dsim_ddi |
| 69 | *exynos_mipi_dsi_find_lcd_device(struct mipi_dsim_lcd_driver *lcd_drv) |
| 70 | { |
| 71 | struct mipi_dsim_ddi *dsim_ddi; |
| 72 | struct mipi_dsim_lcd_device *lcd_dev; |
| 73 | |
| 74 | list_for_each_entry(dsim_ddi, &dsim_ddi_list, list) { |
| 75 | lcd_dev = dsim_ddi->dsim_lcd_dev; |
| 76 | if (!lcd_dev) |
| 77 | continue; |
| 78 | |
| 79 | if (lcd_drv->id >= 0) { |
| 80 | if ((strcmp(lcd_drv->name, lcd_dev->name)) == 0 && |
| 81 | lcd_drv->id == lcd_dev->id) { |
| 82 | /** |
| 83 | * bus_id would be used to identify |
| 84 | * connected bus. |
| 85 | */ |
| 86 | dsim_ddi->bus_id = lcd_dev->bus_id; |
| 87 | |
| 88 | return dsim_ddi; |
| 89 | } |
| 90 | } else { |
| 91 | if ((strcmp(lcd_drv->name, lcd_dev->name)) == 0) { |
| 92 | /** |
| 93 | * bus_id would be used to identify |
| 94 | * connected bus. |
| 95 | */ |
| 96 | dsim_ddi->bus_id = lcd_dev->bus_id; |
| 97 | |
| 98 | return dsim_ddi; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | kfree(dsim_ddi); |
| 103 | list_del(&dsim_ddi_list); |
| 104 | } |
| 105 | |
| 106 | return NULL; |
| 107 | } |
| 108 | |
| 109 | int exynos_mipi_dsi_register_lcd_driver(struct mipi_dsim_lcd_driver *lcd_drv) |
| 110 | { |
| 111 | struct mipi_dsim_ddi *dsim_ddi; |
| 112 | |
| 113 | if (!lcd_drv) { |
| 114 | debug("mipi_dsim_lcd_driver is NULL.\n"); |
| 115 | return -EFAULT; |
| 116 | } |
| 117 | |
| 118 | if (!lcd_drv->name) { |
| 119 | debug("dsim_lcd_driver name is NULL.\n"); |
| 120 | return -EFAULT; |
| 121 | } |
| 122 | |
| 123 | dsim_ddi = exynos_mipi_dsi_find_lcd_device(lcd_drv); |
| 124 | if (!dsim_ddi) { |
| 125 | debug("mipi_dsim_ddi object not found.\n"); |
| 126 | return -EFAULT; |
| 127 | } |
| 128 | |
| 129 | dsim_ddi->dsim_lcd_drv = lcd_drv; |
| 130 | |
| 131 | debug("registered panel driver(%s) to mipi-dsi driver.\n", |
| 132 | lcd_drv->name); |
| 133 | |
| 134 | return 0; |
| 135 | |
| 136 | } |
| 137 | |
| 138 | struct mipi_dsim_ddi |
| 139 | *exynos_mipi_dsi_bind_lcd_ddi(struct mipi_dsim_device *dsim, |
| 140 | const char *name) |
| 141 | { |
| 142 | struct mipi_dsim_ddi *dsim_ddi; |
| 143 | struct mipi_dsim_lcd_driver *lcd_drv; |
| 144 | struct mipi_dsim_lcd_device *lcd_dev; |
| 145 | |
| 146 | list_for_each_entry(dsim_ddi, &dsim_ddi_list, list) { |
| 147 | lcd_drv = dsim_ddi->dsim_lcd_drv; |
| 148 | lcd_dev = dsim_ddi->dsim_lcd_dev; |
| 149 | if (!lcd_drv || !lcd_dev) |
| 150 | continue; |
| 151 | |
| 152 | debug("lcd_drv->id = %d, lcd_dev->id = %d\n", |
| 153 | lcd_drv->id, lcd_dev->id); |
| 154 | |
| 155 | if ((strcmp(lcd_drv->name, name) == 0)) { |
| 156 | lcd_dev->master = dsim; |
| 157 | |
| 158 | dsim->dsim_lcd_dev = lcd_dev; |
| 159 | dsim->dsim_lcd_drv = lcd_drv; |
| 160 | |
| 161 | return dsim_ddi; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | return NULL; |
| 166 | } |
| 167 | |
| 168 | /* define MIPI-DSI Master operations. */ |
| 169 | static struct mipi_dsim_master_ops master_ops = { |
| 170 | .cmd_write = exynos_mipi_dsi_wr_data, |
| 171 | .get_dsim_frame_done = exynos_mipi_dsi_get_frame_done_status, |
| 172 | .clear_dsim_frame_done = exynos_mipi_dsi_clear_frame_done, |
| 173 | }; |
| 174 | |
Simon Glass | ef4e779 | 2016-02-21 21:08:46 -0700 | [diff] [blame] | 175 | int exynos_mipi_dsi_init(struct exynos_platform_mipi_dsim *dsim_pd) |
Donghwa Lee | d84f783 | 2012-04-05 19:36:21 +0000 | [diff] [blame] | 176 | { |
| 177 | struct mipi_dsim_device *dsim; |
| 178 | struct mipi_dsim_config *dsim_config; |
| 179 | struct mipi_dsim_ddi *dsim_ddi; |
| 180 | |
| 181 | dsim = kzalloc(sizeof(struct mipi_dsim_device), GFP_KERNEL); |
| 182 | if (!dsim) { |
| 183 | debug("failed to allocate dsim object.\n"); |
| 184 | return -EFAULT; |
| 185 | } |
| 186 | |
| 187 | /* get mipi_dsim_config. */ |
| 188 | dsim_config = dsim_pd->dsim_config; |
| 189 | if (dsim_config == NULL) { |
| 190 | debug("failed to get dsim config data.\n"); |
| 191 | return -EFAULT; |
| 192 | } |
| 193 | |
| 194 | dsim->pd = dsim_pd; |
| 195 | dsim->dsim_config = dsim_config; |
| 196 | dsim->master_ops = &master_ops; |
| 197 | |
| 198 | /* bind lcd ddi matched with panel name. */ |
| 199 | dsim_ddi = exynos_mipi_dsi_bind_lcd_ddi(dsim, dsim_pd->lcd_panel_name); |
| 200 | if (!dsim_ddi) { |
| 201 | debug("mipi_dsim_ddi object not found.\n"); |
| 202 | return -ENOSYS; |
| 203 | } |
| 204 | if (dsim_pd->lcd_power) |
| 205 | dsim_pd->lcd_power(); |
| 206 | |
| 207 | if (dsim_pd->mipi_power) |
| 208 | dsim_pd->mipi_power(); |
| 209 | |
| 210 | /* phy_enable(unsigned int dev_index, unsigned int enable) */ |
| 211 | if (dsim_pd->phy_enable) |
| 212 | dsim_pd->phy_enable(0, 1); |
| 213 | |
| 214 | set_mipi_clk(); |
| 215 | |
| 216 | exynos_mipi_dsi_init_dsim(dsim); |
| 217 | exynos_mipi_dsi_init_link(dsim); |
| 218 | exynos_mipi_dsi_set_hs_enable(dsim); |
| 219 | |
| 220 | /* set display timing. */ |
| 221 | exynos_mipi_dsi_set_display_mode(dsim, dsim->dsim_config); |
| 222 | |
| 223 | /* initialize mipi-dsi client(lcd panel). */ |
| 224 | if (dsim_ddi->dsim_lcd_drv && dsim_ddi->dsim_lcd_drv->mipi_panel_init) { |
| 225 | dsim_ddi->dsim_lcd_drv->mipi_panel_init(dsim); |
| 226 | dsim_ddi->dsim_lcd_drv->mipi_display_on(dsim); |
| 227 | } |
| 228 | |
| 229 | debug("mipi-dsi driver(%s mode) has been probed.\n", |
| 230 | (dsim_config->e_interface == DSIM_COMMAND) ? |
| 231 | "CPU" : "RGB"); |
| 232 | |
| 233 | return 0; |
| 234 | } |
| 235 | |
Simon Glass | 6d23709 | 2016-02-21 21:08:47 -0700 | [diff] [blame] | 236 | int exynos_dsim_config_parse_dt(const void *blob, struct mipi_dsim_config *dt, |
| 237 | struct mipi_dsim_lcd_device *lcd_dt) |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 238 | { |
| 239 | int node; |
| 240 | |
| 241 | node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS_MIPI_DSI); |
| 242 | if (node <= 0) { |
| 243 | printf("exynos_mipi_dsi: Can't get device node for mipi dsi\n"); |
| 244 | return -ENODEV; |
| 245 | } |
| 246 | |
Simon Glass | f013e7a | 2016-02-21 21:08:45 -0700 | [diff] [blame] | 247 | dt->e_interface = fdtdec_get_int(blob, node, |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 248 | "samsung,dsim-config-e-interface", 0); |
| 249 | |
Simon Glass | f013e7a | 2016-02-21 21:08:45 -0700 | [diff] [blame] | 250 | dt->e_virtual_ch = fdtdec_get_int(blob, node, |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 251 | "samsung,dsim-config-e-virtual-ch", 0); |
| 252 | |
Simon Glass | f013e7a | 2016-02-21 21:08:45 -0700 | [diff] [blame] | 253 | dt->e_pixel_format = fdtdec_get_int(blob, node, |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 254 | "samsung,dsim-config-e-pixel-format", 0); |
| 255 | |
Simon Glass | f013e7a | 2016-02-21 21:08:45 -0700 | [diff] [blame] | 256 | dt->e_burst_mode = fdtdec_get_int(blob, node, |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 257 | "samsung,dsim-config-e-burst-mode", 0); |
| 258 | |
Simon Glass | f013e7a | 2016-02-21 21:08:45 -0700 | [diff] [blame] | 259 | dt->e_no_data_lane = fdtdec_get_int(blob, node, |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 260 | "samsung,dsim-config-e-no-data-lane", 0); |
| 261 | |
Simon Glass | f013e7a | 2016-02-21 21:08:45 -0700 | [diff] [blame] | 262 | dt->e_byte_clk = fdtdec_get_int(blob, node, |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 263 | "samsung,dsim-config-e-byte-clk", 0); |
| 264 | |
Simon Glass | f013e7a | 2016-02-21 21:08:45 -0700 | [diff] [blame] | 265 | dt->hfp = fdtdec_get_int(blob, node, |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 266 | "samsung,dsim-config-hfp", 0); |
| 267 | |
Simon Glass | f013e7a | 2016-02-21 21:08:45 -0700 | [diff] [blame] | 268 | dt->p = fdtdec_get_int(blob, node, |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 269 | "samsung,dsim-config-p", 0); |
Simon Glass | f013e7a | 2016-02-21 21:08:45 -0700 | [diff] [blame] | 270 | dt->m = fdtdec_get_int(blob, node, |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 271 | "samsung,dsim-config-m", 0); |
Simon Glass | f013e7a | 2016-02-21 21:08:45 -0700 | [diff] [blame] | 272 | dt->s = fdtdec_get_int(blob, node, |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 273 | "samsung,dsim-config-s", 0); |
| 274 | |
Simon Glass | f013e7a | 2016-02-21 21:08:45 -0700 | [diff] [blame] | 275 | dt->pll_stable_time = fdtdec_get_int(blob, node, |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 276 | "samsung,dsim-config-pll-stable-time", 0); |
| 277 | |
Simon Glass | f013e7a | 2016-02-21 21:08:45 -0700 | [diff] [blame] | 278 | dt->esc_clk = fdtdec_get_int(blob, node, |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 279 | "samsung,dsim-config-esc-clk", 0); |
| 280 | |
Simon Glass | f013e7a | 2016-02-21 21:08:45 -0700 | [diff] [blame] | 281 | dt->stop_holding_cnt = fdtdec_get_int(blob, node, |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 282 | "samsung,dsim-config-stop-holding-cnt", 0); |
| 283 | |
Simon Glass | f013e7a | 2016-02-21 21:08:45 -0700 | [diff] [blame] | 284 | dt->bta_timeout = fdtdec_get_int(blob, node, |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 285 | "samsung,dsim-config-bta-timeout", 0); |
| 286 | |
Simon Glass | f013e7a | 2016-02-21 21:08:45 -0700 | [diff] [blame] | 287 | dt->rx_timeout = fdtdec_get_int(blob, node, |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 288 | "samsung,dsim-config-rx-timeout", 0); |
| 289 | |
Simon Glass | 6d23709 | 2016-02-21 21:08:47 -0700 | [diff] [blame] | 290 | lcd_dt->name = fdtdec_get_config_string(blob, |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 291 | "samsung,dsim-device-name"); |
| 292 | |
Simon Glass | 6d23709 | 2016-02-21 21:08:47 -0700 | [diff] [blame] | 293 | lcd_dt->id = fdtdec_get_int(blob, node, |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 294 | "samsung,dsim-device-id", 0); |
| 295 | |
Simon Glass | 6d23709 | 2016-02-21 21:08:47 -0700 | [diff] [blame] | 296 | lcd_dt->bus_id = fdtdec_get_int(blob, node, |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 297 | "samsung,dsim-device-bus_id", 0); |
| 298 | |
Simon Glass | 6d23709 | 2016-02-21 21:08:47 -0700 | [diff] [blame] | 299 | lcd_dt->reverse_panel = fdtdec_get_int(blob, node, |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 300 | "samsung,dsim-device-reverse-panel", 0); |
| 301 | |
| 302 | return 0; |
| 303 | } |
| 304 | |
| 305 | void exynos_init_dsim_platform_data(vidinfo_t *vid) |
| 306 | { |
Simon Glass | ef4e779 | 2016-02-21 21:08:46 -0700 | [diff] [blame] | 307 | static struct mipi_dsim_config dsim_config_dt; |
| 308 | static struct exynos_platform_mipi_dsim dsim_platform_data_dt; |
Simon Glass | 6d23709 | 2016-02-21 21:08:47 -0700 | [diff] [blame] | 309 | static struct mipi_dsim_lcd_device mipi_lcd_device_dt; |
Simon Glass | f013e7a | 2016-02-21 21:08:45 -0700 | [diff] [blame] | 310 | |
Simon Glass | 6d23709 | 2016-02-21 21:08:47 -0700 | [diff] [blame] | 311 | if (exynos_dsim_config_parse_dt(gd->fdt_blob, &dsim_config_dt, |
| 312 | &mipi_lcd_device_dt)) |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 313 | debug("Can't get proper dsim config.\n"); |
| 314 | |
| 315 | strcpy(dsim_platform_data_dt.lcd_panel_name, mipi_lcd_device_dt.name); |
| 316 | dsim_platform_data_dt.dsim_config = &dsim_config_dt; |
| 317 | dsim_platform_data_dt.mipi_power = mipi_power; |
| 318 | dsim_platform_data_dt.phy_enable = set_mipi_phy_ctrl; |
| 319 | dsim_platform_data_dt.lcd_panel_info = (void *)vid; |
| 320 | |
| 321 | mipi_lcd_device_dt.platform_data = (void *)&dsim_platform_data_dt; |
| 322 | exynos_mipi_dsi_register_lcd_device(&mipi_lcd_device_dt); |
| 323 | |
Simon Glass | ef4e779 | 2016-02-21 21:08:46 -0700 | [diff] [blame] | 324 | vid->dsim_platform_data_dt = &dsim_platform_data_dt; |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 325 | } |