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