Donghwa Lee | d84f783 | 2012-04-05 19:36:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Samsung Electronics |
| 3 | * |
| 4 | * Author: InKi Dae <inki.dae@samsung.com> |
| 5 | * Author: Donghwa Lee <dh09.lee@samsung.com> |
| 6 | * |
Wolfgang Denk | bd8ec7e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
Donghwa Lee | d84f783 | 2012-04-05 19:36:21 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <malloc.h> |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 12 | #include <fdtdec.h> |
| 13 | #include <libfdt.h> |
Heiko Schocher | 4f7a9a3 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 14 | #include <linux/compat.h> |
Donghwa Lee | d84f783 | 2012-04-05 19:36:21 +0000 | [diff] [blame] | 15 | #include <linux/err.h> |
| 16 | #include <asm/arch/dsim.h> |
| 17 | #include <asm/arch/mipi_dsim.h> |
| 18 | #include <asm/arch/power.h> |
| 19 | #include <asm/arch/cpu.h> |
| 20 | #include <asm/arch/clk.h> |
| 21 | |
| 22 | #include "exynos_mipi_dsi_lowlevel.h" |
| 23 | #include "exynos_mipi_dsi_common.h" |
| 24 | |
| 25 | #define master_to_driver(a) (a->dsim_lcd_drv) |
| 26 | #define master_to_device(a) (a->dsim_lcd_dev) |
| 27 | |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 28 | DECLARE_GLOBAL_DATA_PTR; |
| 29 | |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 30 | static struct mipi_dsim_lcd_device mipi_lcd_device_dt; |
Donghwa Lee | d84f783 | 2012-04-05 19:36:21 +0000 | [diff] [blame] | 31 | |
| 32 | struct mipi_dsim_ddi { |
| 33 | int bus_id; |
| 34 | struct list_head list; |
| 35 | struct mipi_dsim_lcd_device *dsim_lcd_dev; |
| 36 | struct mipi_dsim_lcd_driver *dsim_lcd_drv; |
| 37 | }; |
| 38 | |
| 39 | static LIST_HEAD(dsim_ddi_list); |
| 40 | static LIST_HEAD(dsim_lcd_dev_list); |
| 41 | |
| 42 | int exynos_mipi_dsi_register_lcd_device(struct mipi_dsim_lcd_device *lcd_dev) |
| 43 | { |
| 44 | struct mipi_dsim_ddi *dsim_ddi; |
| 45 | |
| 46 | if (!lcd_dev) { |
| 47 | debug("mipi_dsim_lcd_device is NULL.\n"); |
| 48 | return -EFAULT; |
| 49 | } |
| 50 | |
| 51 | if (!lcd_dev->name) { |
| 52 | debug("dsim_lcd_device name is NULL.\n"); |
| 53 | return -EFAULT; |
| 54 | } |
| 55 | |
| 56 | dsim_ddi = kzalloc(sizeof(struct mipi_dsim_ddi), GFP_KERNEL); |
| 57 | if (!dsim_ddi) { |
| 58 | debug("failed to allocate dsim_ddi object.\n"); |
| 59 | return -EFAULT; |
| 60 | } |
| 61 | |
| 62 | dsim_ddi->dsim_lcd_dev = lcd_dev; |
| 63 | |
| 64 | list_add_tail(&dsim_ddi->list, &dsim_ddi_list); |
| 65 | |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | struct mipi_dsim_ddi |
| 70 | *exynos_mipi_dsi_find_lcd_device(struct mipi_dsim_lcd_driver *lcd_drv) |
| 71 | { |
| 72 | struct mipi_dsim_ddi *dsim_ddi; |
| 73 | struct mipi_dsim_lcd_device *lcd_dev; |
| 74 | |
| 75 | list_for_each_entry(dsim_ddi, &dsim_ddi_list, list) { |
| 76 | lcd_dev = dsim_ddi->dsim_lcd_dev; |
| 77 | if (!lcd_dev) |
| 78 | continue; |
| 79 | |
| 80 | if (lcd_drv->id >= 0) { |
| 81 | if ((strcmp(lcd_drv->name, lcd_dev->name)) == 0 && |
| 82 | lcd_drv->id == lcd_dev->id) { |
| 83 | /** |
| 84 | * bus_id would be used to identify |
| 85 | * connected bus. |
| 86 | */ |
| 87 | dsim_ddi->bus_id = lcd_dev->bus_id; |
| 88 | |
| 89 | return dsim_ddi; |
| 90 | } |
| 91 | } else { |
| 92 | if ((strcmp(lcd_drv->name, lcd_dev->name)) == 0) { |
| 93 | /** |
| 94 | * bus_id would be used to identify |
| 95 | * connected bus. |
| 96 | */ |
| 97 | dsim_ddi->bus_id = lcd_dev->bus_id; |
| 98 | |
| 99 | return dsim_ddi; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | kfree(dsim_ddi); |
| 104 | list_del(&dsim_ddi_list); |
| 105 | } |
| 106 | |
| 107 | return NULL; |
| 108 | } |
| 109 | |
| 110 | int exynos_mipi_dsi_register_lcd_driver(struct mipi_dsim_lcd_driver *lcd_drv) |
| 111 | { |
| 112 | struct mipi_dsim_ddi *dsim_ddi; |
| 113 | |
| 114 | if (!lcd_drv) { |
| 115 | debug("mipi_dsim_lcd_driver is NULL.\n"); |
| 116 | return -EFAULT; |
| 117 | } |
| 118 | |
| 119 | if (!lcd_drv->name) { |
| 120 | debug("dsim_lcd_driver name is NULL.\n"); |
| 121 | return -EFAULT; |
| 122 | } |
| 123 | |
| 124 | dsim_ddi = exynos_mipi_dsi_find_lcd_device(lcd_drv); |
| 125 | if (!dsim_ddi) { |
| 126 | debug("mipi_dsim_ddi object not found.\n"); |
| 127 | return -EFAULT; |
| 128 | } |
| 129 | |
| 130 | dsim_ddi->dsim_lcd_drv = lcd_drv; |
| 131 | |
| 132 | debug("registered panel driver(%s) to mipi-dsi driver.\n", |
| 133 | lcd_drv->name); |
| 134 | |
| 135 | return 0; |
| 136 | |
| 137 | } |
| 138 | |
| 139 | struct mipi_dsim_ddi |
| 140 | *exynos_mipi_dsi_bind_lcd_ddi(struct mipi_dsim_device *dsim, |
| 141 | const char *name) |
| 142 | { |
| 143 | struct mipi_dsim_ddi *dsim_ddi; |
| 144 | struct mipi_dsim_lcd_driver *lcd_drv; |
| 145 | struct mipi_dsim_lcd_device *lcd_dev; |
| 146 | |
| 147 | list_for_each_entry(dsim_ddi, &dsim_ddi_list, list) { |
| 148 | lcd_drv = dsim_ddi->dsim_lcd_drv; |
| 149 | lcd_dev = dsim_ddi->dsim_lcd_dev; |
| 150 | if (!lcd_drv || !lcd_dev) |
| 151 | continue; |
| 152 | |
| 153 | debug("lcd_drv->id = %d, lcd_dev->id = %d\n", |
| 154 | lcd_drv->id, lcd_dev->id); |
| 155 | |
| 156 | if ((strcmp(lcd_drv->name, name) == 0)) { |
| 157 | lcd_dev->master = dsim; |
| 158 | |
| 159 | dsim->dsim_lcd_dev = lcd_dev; |
| 160 | dsim->dsim_lcd_drv = lcd_drv; |
| 161 | |
| 162 | return dsim_ddi; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | return NULL; |
| 167 | } |
| 168 | |
| 169 | /* define MIPI-DSI Master operations. */ |
| 170 | static struct mipi_dsim_master_ops master_ops = { |
| 171 | .cmd_write = exynos_mipi_dsi_wr_data, |
| 172 | .get_dsim_frame_done = exynos_mipi_dsi_get_frame_done_status, |
| 173 | .clear_dsim_frame_done = exynos_mipi_dsi_clear_frame_done, |
| 174 | }; |
| 175 | |
Simon Glass | ef4e779 | 2016-02-21 21:08:46 -0700 | [diff] [blame^] | 176 | int exynos_mipi_dsi_init(struct exynos_platform_mipi_dsim *dsim_pd) |
Donghwa Lee | d84f783 | 2012-04-05 19:36:21 +0000 | [diff] [blame] | 177 | { |
| 178 | struct mipi_dsim_device *dsim; |
| 179 | struct mipi_dsim_config *dsim_config; |
| 180 | struct mipi_dsim_ddi *dsim_ddi; |
| 181 | |
| 182 | dsim = kzalloc(sizeof(struct mipi_dsim_device), GFP_KERNEL); |
| 183 | if (!dsim) { |
| 184 | debug("failed to allocate dsim object.\n"); |
| 185 | return -EFAULT; |
| 186 | } |
| 187 | |
| 188 | /* get mipi_dsim_config. */ |
| 189 | dsim_config = dsim_pd->dsim_config; |
| 190 | if (dsim_config == NULL) { |
| 191 | debug("failed to get dsim config data.\n"); |
| 192 | return -EFAULT; |
| 193 | } |
| 194 | |
| 195 | dsim->pd = dsim_pd; |
| 196 | dsim->dsim_config = dsim_config; |
| 197 | dsim->master_ops = &master_ops; |
| 198 | |
| 199 | /* bind lcd ddi matched with panel name. */ |
| 200 | dsim_ddi = exynos_mipi_dsi_bind_lcd_ddi(dsim, dsim_pd->lcd_panel_name); |
| 201 | if (!dsim_ddi) { |
| 202 | debug("mipi_dsim_ddi object not found.\n"); |
| 203 | return -ENOSYS; |
| 204 | } |
| 205 | if (dsim_pd->lcd_power) |
| 206 | dsim_pd->lcd_power(); |
| 207 | |
| 208 | if (dsim_pd->mipi_power) |
| 209 | dsim_pd->mipi_power(); |
| 210 | |
| 211 | /* phy_enable(unsigned int dev_index, unsigned int enable) */ |
| 212 | if (dsim_pd->phy_enable) |
| 213 | dsim_pd->phy_enable(0, 1); |
| 214 | |
| 215 | set_mipi_clk(); |
| 216 | |
| 217 | exynos_mipi_dsi_init_dsim(dsim); |
| 218 | exynos_mipi_dsi_init_link(dsim); |
| 219 | exynos_mipi_dsi_set_hs_enable(dsim); |
| 220 | |
| 221 | /* set display timing. */ |
| 222 | exynos_mipi_dsi_set_display_mode(dsim, dsim->dsim_config); |
| 223 | |
| 224 | /* initialize mipi-dsi client(lcd panel). */ |
| 225 | if (dsim_ddi->dsim_lcd_drv && dsim_ddi->dsim_lcd_drv->mipi_panel_init) { |
| 226 | dsim_ddi->dsim_lcd_drv->mipi_panel_init(dsim); |
| 227 | dsim_ddi->dsim_lcd_drv->mipi_display_on(dsim); |
| 228 | } |
| 229 | |
| 230 | debug("mipi-dsi driver(%s mode) has been probed.\n", |
| 231 | (dsim_config->e_interface == DSIM_COMMAND) ? |
| 232 | "CPU" : "RGB"); |
| 233 | |
| 234 | return 0; |
| 235 | } |
| 236 | |
Simon Glass | f013e7a | 2016-02-21 21:08:45 -0700 | [diff] [blame] | 237 | int exynos_dsim_config_parse_dt(const void *blob, struct mipi_dsim_config *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 | |
| 290 | mipi_lcd_device_dt.name = fdtdec_get_config_string(blob, |
| 291 | "samsung,dsim-device-name"); |
| 292 | |
| 293 | mipi_lcd_device_dt.id = fdtdec_get_int(blob, node, |
| 294 | "samsung,dsim-device-id", 0); |
| 295 | |
| 296 | mipi_lcd_device_dt.bus_id = fdtdec_get_int(blob, node, |
| 297 | "samsung,dsim-device-bus_id", 0); |
| 298 | |
| 299 | mipi_lcd_device_dt.reverse_panel = fdtdec_get_int(blob, node, |
| 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 | f013e7a | 2016-02-21 21:08:45 -0700 | [diff] [blame] | 309 | |
| 310 | if (exynos_dsim_config_parse_dt(gd->fdt_blob, &dsim_config_dt)) |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 311 | debug("Can't get proper dsim config.\n"); |
| 312 | |
| 313 | strcpy(dsim_platform_data_dt.lcd_panel_name, mipi_lcd_device_dt.name); |
| 314 | dsim_platform_data_dt.dsim_config = &dsim_config_dt; |
| 315 | dsim_platform_data_dt.mipi_power = mipi_power; |
| 316 | dsim_platform_data_dt.phy_enable = set_mipi_phy_ctrl; |
| 317 | dsim_platform_data_dt.lcd_panel_info = (void *)vid; |
| 318 | |
| 319 | mipi_lcd_device_dt.platform_data = (void *)&dsim_platform_data_dt; |
| 320 | exynos_mipi_dsi_register_lcd_device(&mipi_lcd_device_dt); |
| 321 | |
Simon Glass | ef4e779 | 2016-02-21 21:08:46 -0700 | [diff] [blame^] | 322 | vid->dsim_platform_data_dt = &dsim_platform_data_dt; |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 323 | } |