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