Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015, The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/clk.h> |
| 15 | #include <linux/delay.h> |
| 16 | #include <linux/err.h> |
| 17 | #include <linux/gpio.h> |
Brian Norris | 964a075 | 2015-05-20 15:59:31 -0700 | [diff] [blame] | 18 | #include <linux/gpio/consumer.h> |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 19 | #include <linux/interrupt.h> |
| 20 | #include <linux/of_device.h> |
| 21 | #include <linux/of_gpio.h> |
| 22 | #include <linux/of_irq.h> |
Hai Li | ab8909b | 2015-06-11 10:56:46 -0400 | [diff] [blame] | 23 | #include <linux/pinctrl/consumer.h> |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 24 | #include <linux/regulator/consumer.h> |
| 25 | #include <linux/spinlock.h> |
| 26 | #include <video/mipi_display.h> |
| 27 | |
| 28 | #include "dsi.h" |
| 29 | #include "dsi.xml.h" |
| 30 | |
| 31 | #define MSM_DSI_VER_MAJOR_V2 0x02 |
| 32 | #define MSM_DSI_VER_MAJOR_6G 0x03 |
| 33 | #define MSM_DSI_6G_VER_MINOR_V1_0 0x10000000 |
| 34 | #define MSM_DSI_6G_VER_MINOR_V1_1 0x10010000 |
| 35 | #define MSM_DSI_6G_VER_MINOR_V1_1_1 0x10010001 |
| 36 | #define MSM_DSI_6G_VER_MINOR_V1_2 0x10020000 |
Hai Li | dcefc11 | 2015-06-18 10:14:21 -0400 | [diff] [blame] | 37 | #define MSM_DSI_6G_VER_MINOR_V1_3 0x10030000 |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 38 | #define MSM_DSI_6G_VER_MINOR_V1_3_1 0x10030001 |
| 39 | |
| 40 | #define DSI_6G_REG_SHIFT 4 |
| 41 | |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 42 | struct dsi_config { |
| 43 | u32 major; |
| 44 | u32 minor; |
| 45 | u32 io_offset; |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 46 | struct dsi_reg_config reg_cfg; |
| 47 | }; |
| 48 | |
| 49 | static const struct dsi_config dsi_cfgs[] = { |
Hai Li | ec31abf | 2015-05-15 13:04:06 -0400 | [diff] [blame] | 50 | {MSM_DSI_VER_MAJOR_V2, 0, 0, {0,} }, |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 51 | { /* 8974 v1 */ |
| 52 | .major = MSM_DSI_VER_MAJOR_6G, |
| 53 | .minor = MSM_DSI_6G_VER_MINOR_V1_0, |
| 54 | .io_offset = DSI_6G_REG_SHIFT, |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 55 | .reg_cfg = { |
| 56 | .num = 4, |
| 57 | .regs = { |
| 58 | {"gdsc", -1, -1, -1, -1}, |
| 59 | {"vdd", 3000000, 3000000, 150000, 100}, |
| 60 | {"vdda", 1200000, 1200000, 100000, 100}, |
| 61 | {"vddio", 1800000, 1800000, 100000, 100}, |
| 62 | }, |
| 63 | }, |
| 64 | }, |
| 65 | { /* 8974 v2 */ |
| 66 | .major = MSM_DSI_VER_MAJOR_6G, |
| 67 | .minor = MSM_DSI_6G_VER_MINOR_V1_1, |
| 68 | .io_offset = DSI_6G_REG_SHIFT, |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 69 | .reg_cfg = { |
| 70 | .num = 4, |
| 71 | .regs = { |
| 72 | {"gdsc", -1, -1, -1, -1}, |
| 73 | {"vdd", 3000000, 3000000, 150000, 100}, |
| 74 | {"vdda", 1200000, 1200000, 100000, 100}, |
| 75 | {"vddio", 1800000, 1800000, 100000, 100}, |
| 76 | }, |
| 77 | }, |
| 78 | }, |
| 79 | { /* 8974 v3 */ |
| 80 | .major = MSM_DSI_VER_MAJOR_6G, |
| 81 | .minor = MSM_DSI_6G_VER_MINOR_V1_1_1, |
| 82 | .io_offset = DSI_6G_REG_SHIFT, |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 83 | .reg_cfg = { |
| 84 | .num = 4, |
| 85 | .regs = { |
| 86 | {"gdsc", -1, -1, -1, -1}, |
| 87 | {"vdd", 3000000, 3000000, 150000, 100}, |
| 88 | {"vdda", 1200000, 1200000, 100000, 100}, |
| 89 | {"vddio", 1800000, 1800000, 100000, 100}, |
| 90 | }, |
| 91 | }, |
| 92 | }, |
| 93 | { /* 8084 */ |
| 94 | .major = MSM_DSI_VER_MAJOR_6G, |
| 95 | .minor = MSM_DSI_6G_VER_MINOR_V1_2, |
| 96 | .io_offset = DSI_6G_REG_SHIFT, |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 97 | .reg_cfg = { |
| 98 | .num = 4, |
| 99 | .regs = { |
| 100 | {"gdsc", -1, -1, -1, -1}, |
| 101 | {"vdd", 3000000, 3000000, 150000, 100}, |
| 102 | {"vdda", 1200000, 1200000, 100000, 100}, |
| 103 | {"vddio", 1800000, 1800000, 100000, 100}, |
| 104 | }, |
| 105 | }, |
| 106 | }, |
| 107 | { /* 8916 */ |
| 108 | .major = MSM_DSI_VER_MAJOR_6G, |
| 109 | .minor = MSM_DSI_6G_VER_MINOR_V1_3_1, |
| 110 | .io_offset = DSI_6G_REG_SHIFT, |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 111 | .reg_cfg = { |
| 112 | .num = 4, |
| 113 | .regs = { |
| 114 | {"gdsc", -1, -1, -1, -1}, |
| 115 | {"vdd", 2850000, 2850000, 100000, 100}, |
| 116 | {"vdda", 1200000, 1200000, 100000, 100}, |
| 117 | {"vddio", 1800000, 1800000, 100000, 100}, |
| 118 | }, |
| 119 | }, |
| 120 | }, |
Hai Li | dcefc11 | 2015-06-18 10:14:21 -0400 | [diff] [blame] | 121 | { /* 8x94 */ |
| 122 | .major = MSM_DSI_VER_MAJOR_6G, |
| 123 | .minor = MSM_DSI_6G_VER_MINOR_V1_3, |
| 124 | .io_offset = DSI_6G_REG_SHIFT, |
| 125 | .reg_cfg = { |
| 126 | .num = 7, |
| 127 | .regs = { |
| 128 | {"gdsc", -1, -1, -1, -1}, |
| 129 | {"vdda", 1250000, 1250000, 100000, 100}, |
| 130 | {"vddio", 1800000, 1800000, 100000, 100}, |
| 131 | {"vcca", 1000000, 1000000, 10000, 100}, |
| 132 | {"vdd", 1800000, 1800000, 100000, 100}, |
| 133 | {"lab_reg", -1, -1, -1, -1}, |
| 134 | {"ibb_reg", -1, -1, -1, -1}, |
| 135 | }, |
| 136 | } |
| 137 | }, |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | static int dsi_get_version(const void __iomem *base, u32 *major, u32 *minor) |
| 141 | { |
| 142 | u32 ver; |
| 143 | u32 ver_6g; |
| 144 | |
| 145 | if (!major || !minor) |
| 146 | return -EINVAL; |
| 147 | |
| 148 | /* From DSI6G(v3), addition of a 6G_HW_VERSION register at offset 0 |
| 149 | * makes all other registers 4-byte shifted down. |
| 150 | */ |
| 151 | ver_6g = msm_readl(base + REG_DSI_6G_HW_VERSION); |
| 152 | if (ver_6g == 0) { |
| 153 | ver = msm_readl(base + REG_DSI_VERSION); |
| 154 | ver = FIELD(ver, DSI_VERSION_MAJOR); |
| 155 | if (ver <= MSM_DSI_VER_MAJOR_V2) { |
| 156 | /* old versions */ |
| 157 | *major = ver; |
| 158 | *minor = 0; |
| 159 | return 0; |
| 160 | } else { |
| 161 | return -EINVAL; |
| 162 | } |
| 163 | } else { |
| 164 | ver = msm_readl(base + DSI_6G_REG_SHIFT + REG_DSI_VERSION); |
| 165 | ver = FIELD(ver, DSI_VERSION_MAJOR); |
| 166 | if (ver == MSM_DSI_VER_MAJOR_6G) { |
| 167 | /* 6G version */ |
| 168 | *major = ver; |
| 169 | *minor = ver_6g; |
| 170 | return 0; |
| 171 | } else { |
| 172 | return -EINVAL; |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | #define DSI_ERR_STATE_ACK 0x0000 |
| 178 | #define DSI_ERR_STATE_TIMEOUT 0x0001 |
| 179 | #define DSI_ERR_STATE_DLN0_PHY 0x0002 |
| 180 | #define DSI_ERR_STATE_FIFO 0x0004 |
| 181 | #define DSI_ERR_STATE_MDP_FIFO_UNDERFLOW 0x0008 |
| 182 | #define DSI_ERR_STATE_INTERLEAVE_OP_CONTENTION 0x0010 |
| 183 | #define DSI_ERR_STATE_PLL_UNLOCKED 0x0020 |
| 184 | |
| 185 | #define DSI_CLK_CTRL_ENABLE_CLKS \ |
| 186 | (DSI_CLK_CTRL_AHBS_HCLK_ON | DSI_CLK_CTRL_AHBM_SCLK_ON | \ |
| 187 | DSI_CLK_CTRL_PCLK_ON | DSI_CLK_CTRL_DSICLK_ON | \ |
| 188 | DSI_CLK_CTRL_BYTECLK_ON | DSI_CLK_CTRL_ESCCLK_ON | \ |
| 189 | DSI_CLK_CTRL_FORCE_ON_DYN_AHBM_HCLK) |
| 190 | |
| 191 | struct msm_dsi_host { |
| 192 | struct mipi_dsi_host base; |
| 193 | |
| 194 | struct platform_device *pdev; |
| 195 | struct drm_device *dev; |
| 196 | |
| 197 | int id; |
| 198 | |
| 199 | void __iomem *ctrl_base; |
Hai Li | ec31abf | 2015-05-15 13:04:06 -0400 | [diff] [blame] | 200 | struct regulator_bulk_data supplies[DSI_DEV_REGULATOR_MAX]; |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 201 | struct clk *mdp_core_clk; |
| 202 | struct clk *ahb_clk; |
| 203 | struct clk *axi_clk; |
| 204 | struct clk *mmss_misc_ahb_clk; |
| 205 | struct clk *byte_clk; |
| 206 | struct clk *esc_clk; |
| 207 | struct clk *pixel_clk; |
Hai Li | 9d32c498 | 2015-05-15 13:04:05 -0400 | [diff] [blame] | 208 | struct clk *byte_clk_src; |
| 209 | struct clk *pixel_clk_src; |
| 210 | |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 211 | u32 byte_clk_rate; |
| 212 | |
| 213 | struct gpio_desc *disp_en_gpio; |
| 214 | struct gpio_desc *te_gpio; |
| 215 | |
| 216 | const struct dsi_config *cfg; |
| 217 | |
| 218 | struct completion dma_comp; |
| 219 | struct completion video_comp; |
| 220 | struct mutex dev_mutex; |
| 221 | struct mutex cmd_mutex; |
| 222 | struct mutex clk_mutex; |
| 223 | spinlock_t intr_lock; /* Protect interrupt ctrl register */ |
| 224 | |
| 225 | u32 err_work_state; |
| 226 | struct work_struct err_work; |
| 227 | struct workqueue_struct *workqueue; |
| 228 | |
| 229 | struct drm_gem_object *tx_gem_obj; |
| 230 | u8 *rx_buf; |
| 231 | |
| 232 | struct drm_display_mode *mode; |
| 233 | |
| 234 | /* Panel info */ |
| 235 | struct device_node *panel_node; |
| 236 | unsigned int channel; |
| 237 | unsigned int lanes; |
| 238 | enum mipi_dsi_pixel_format format; |
| 239 | unsigned long mode_flags; |
| 240 | |
| 241 | u32 dma_cmd_ctrl_restore; |
| 242 | |
| 243 | bool registered; |
| 244 | bool power_on; |
| 245 | int irq; |
| 246 | }; |
| 247 | |
| 248 | static u32 dsi_get_bpp(const enum mipi_dsi_pixel_format fmt) |
| 249 | { |
| 250 | switch (fmt) { |
| 251 | case MIPI_DSI_FMT_RGB565: return 16; |
| 252 | case MIPI_DSI_FMT_RGB666_PACKED: return 18; |
| 253 | case MIPI_DSI_FMT_RGB666: |
| 254 | case MIPI_DSI_FMT_RGB888: |
| 255 | default: return 24; |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | static inline u32 dsi_read(struct msm_dsi_host *msm_host, u32 reg) |
| 260 | { |
| 261 | return msm_readl(msm_host->ctrl_base + msm_host->cfg->io_offset + reg); |
| 262 | } |
| 263 | static inline void dsi_write(struct msm_dsi_host *msm_host, u32 reg, u32 data) |
| 264 | { |
| 265 | msm_writel(data, msm_host->ctrl_base + msm_host->cfg->io_offset + reg); |
| 266 | } |
| 267 | |
| 268 | static int dsi_host_regulator_enable(struct msm_dsi_host *msm_host); |
| 269 | static void dsi_host_regulator_disable(struct msm_dsi_host *msm_host); |
| 270 | |
| 271 | static const struct dsi_config *dsi_get_config(struct msm_dsi_host *msm_host) |
| 272 | { |
| 273 | const struct dsi_config *cfg; |
| 274 | struct regulator *gdsc_reg; |
| 275 | int i, ret; |
| 276 | u32 major = 0, minor = 0; |
| 277 | |
| 278 | gdsc_reg = regulator_get(&msm_host->pdev->dev, "gdsc"); |
Fabian Frederick | bdc80de | 2015-05-04 19:03:55 +0200 | [diff] [blame] | 279 | if (IS_ERR(gdsc_reg)) { |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 280 | pr_err("%s: cannot get gdsc\n", __func__); |
| 281 | goto fail; |
| 282 | } |
| 283 | ret = regulator_enable(gdsc_reg); |
| 284 | if (ret) { |
| 285 | pr_err("%s: unable to enable gdsc\n", __func__); |
| 286 | regulator_put(gdsc_reg); |
| 287 | goto fail; |
| 288 | } |
| 289 | ret = clk_prepare_enable(msm_host->ahb_clk); |
| 290 | if (ret) { |
| 291 | pr_err("%s: unable to enable ahb_clk\n", __func__); |
| 292 | regulator_disable(gdsc_reg); |
| 293 | regulator_put(gdsc_reg); |
| 294 | goto fail; |
| 295 | } |
| 296 | |
| 297 | ret = dsi_get_version(msm_host->ctrl_base, &major, &minor); |
| 298 | |
| 299 | clk_disable_unprepare(msm_host->ahb_clk); |
| 300 | regulator_disable(gdsc_reg); |
| 301 | regulator_put(gdsc_reg); |
| 302 | if (ret) { |
| 303 | pr_err("%s: Invalid version\n", __func__); |
| 304 | goto fail; |
| 305 | } |
| 306 | |
| 307 | for (i = 0; i < ARRAY_SIZE(dsi_cfgs); i++) { |
| 308 | cfg = dsi_cfgs + i; |
| 309 | if ((cfg->major == major) && (cfg->minor == minor)) |
| 310 | return cfg; |
| 311 | } |
| 312 | pr_err("%s: Version %x:%x not support\n", __func__, major, minor); |
| 313 | |
| 314 | fail: |
| 315 | return NULL; |
| 316 | } |
| 317 | |
| 318 | static inline struct msm_dsi_host *to_msm_dsi_host(struct mipi_dsi_host *host) |
| 319 | { |
| 320 | return container_of(host, struct msm_dsi_host, base); |
| 321 | } |
| 322 | |
| 323 | static void dsi_host_regulator_disable(struct msm_dsi_host *msm_host) |
| 324 | { |
| 325 | struct regulator_bulk_data *s = msm_host->supplies; |
| 326 | const struct dsi_reg_entry *regs = msm_host->cfg->reg_cfg.regs; |
| 327 | int num = msm_host->cfg->reg_cfg.num; |
| 328 | int i; |
| 329 | |
| 330 | DBG(""); |
| 331 | for (i = num - 1; i >= 0; i--) |
| 332 | if (regs[i].disable_load >= 0) |
Dave Airlie | 2c33ce0 | 2015-04-20 11:32:26 +1000 | [diff] [blame] | 333 | regulator_set_load(s[i].consumer, |
| 334 | regs[i].disable_load); |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 335 | |
| 336 | regulator_bulk_disable(num, s); |
| 337 | } |
| 338 | |
| 339 | static int dsi_host_regulator_enable(struct msm_dsi_host *msm_host) |
| 340 | { |
| 341 | struct regulator_bulk_data *s = msm_host->supplies; |
| 342 | const struct dsi_reg_entry *regs = msm_host->cfg->reg_cfg.regs; |
| 343 | int num = msm_host->cfg->reg_cfg.num; |
| 344 | int ret, i; |
| 345 | |
| 346 | DBG(""); |
| 347 | for (i = 0; i < num; i++) { |
| 348 | if (regs[i].enable_load >= 0) { |
Dave Airlie | 2c33ce0 | 2015-04-20 11:32:26 +1000 | [diff] [blame] | 349 | ret = regulator_set_load(s[i].consumer, |
| 350 | regs[i].enable_load); |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 351 | if (ret < 0) { |
| 352 | pr_err("regulator %d set op mode failed, %d\n", |
| 353 | i, ret); |
| 354 | goto fail; |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | ret = regulator_bulk_enable(num, s); |
| 360 | if (ret < 0) { |
| 361 | pr_err("regulator enable failed, %d\n", ret); |
| 362 | goto fail; |
| 363 | } |
| 364 | |
| 365 | return 0; |
| 366 | |
| 367 | fail: |
| 368 | for (i--; i >= 0; i--) |
Dave Airlie | 2c33ce0 | 2015-04-20 11:32:26 +1000 | [diff] [blame] | 369 | regulator_set_load(s[i].consumer, regs[i].disable_load); |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 370 | return ret; |
| 371 | } |
| 372 | |
| 373 | static int dsi_regulator_init(struct msm_dsi_host *msm_host) |
| 374 | { |
| 375 | struct regulator_bulk_data *s = msm_host->supplies; |
| 376 | const struct dsi_reg_entry *regs = msm_host->cfg->reg_cfg.regs; |
| 377 | int num = msm_host->cfg->reg_cfg.num; |
| 378 | int i, ret; |
| 379 | |
| 380 | for (i = 0; i < num; i++) |
| 381 | s[i].supply = regs[i].name; |
| 382 | |
| 383 | ret = devm_regulator_bulk_get(&msm_host->pdev->dev, num, s); |
| 384 | if (ret < 0) { |
| 385 | pr_err("%s: failed to init regulator, ret=%d\n", |
| 386 | __func__, ret); |
| 387 | return ret; |
| 388 | } |
| 389 | |
| 390 | for (i = 0; i < num; i++) { |
| 391 | if ((regs[i].min_voltage >= 0) && (regs[i].max_voltage >= 0)) { |
| 392 | ret = regulator_set_voltage(s[i].consumer, |
| 393 | regs[i].min_voltage, regs[i].max_voltage); |
| 394 | if (ret < 0) { |
| 395 | pr_err("regulator %d set voltage failed, %d\n", |
| 396 | i, ret); |
| 397 | return ret; |
| 398 | } |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | return 0; |
| 403 | } |
| 404 | |
| 405 | static int dsi_clk_init(struct msm_dsi_host *msm_host) |
| 406 | { |
| 407 | struct device *dev = &msm_host->pdev->dev; |
| 408 | int ret = 0; |
| 409 | |
| 410 | msm_host->mdp_core_clk = devm_clk_get(dev, "mdp_core_clk"); |
| 411 | if (IS_ERR(msm_host->mdp_core_clk)) { |
| 412 | ret = PTR_ERR(msm_host->mdp_core_clk); |
| 413 | pr_err("%s: Unable to get mdp core clk. ret=%d\n", |
| 414 | __func__, ret); |
| 415 | goto exit; |
| 416 | } |
| 417 | |
| 418 | msm_host->ahb_clk = devm_clk_get(dev, "iface_clk"); |
| 419 | if (IS_ERR(msm_host->ahb_clk)) { |
| 420 | ret = PTR_ERR(msm_host->ahb_clk); |
| 421 | pr_err("%s: Unable to get mdss ahb clk. ret=%d\n", |
| 422 | __func__, ret); |
| 423 | goto exit; |
| 424 | } |
| 425 | |
| 426 | msm_host->axi_clk = devm_clk_get(dev, "bus_clk"); |
| 427 | if (IS_ERR(msm_host->axi_clk)) { |
| 428 | ret = PTR_ERR(msm_host->axi_clk); |
| 429 | pr_err("%s: Unable to get axi bus clk. ret=%d\n", |
| 430 | __func__, ret); |
| 431 | goto exit; |
| 432 | } |
| 433 | |
| 434 | msm_host->mmss_misc_ahb_clk = devm_clk_get(dev, "core_mmss_clk"); |
| 435 | if (IS_ERR(msm_host->mmss_misc_ahb_clk)) { |
| 436 | ret = PTR_ERR(msm_host->mmss_misc_ahb_clk); |
| 437 | pr_err("%s: Unable to get mmss misc ahb clk. ret=%d\n", |
| 438 | __func__, ret); |
| 439 | goto exit; |
| 440 | } |
| 441 | |
| 442 | msm_host->byte_clk = devm_clk_get(dev, "byte_clk"); |
| 443 | if (IS_ERR(msm_host->byte_clk)) { |
| 444 | ret = PTR_ERR(msm_host->byte_clk); |
| 445 | pr_err("%s: can't find dsi_byte_clk. ret=%d\n", |
| 446 | __func__, ret); |
| 447 | msm_host->byte_clk = NULL; |
| 448 | goto exit; |
| 449 | } |
| 450 | |
| 451 | msm_host->pixel_clk = devm_clk_get(dev, "pixel_clk"); |
| 452 | if (IS_ERR(msm_host->pixel_clk)) { |
| 453 | ret = PTR_ERR(msm_host->pixel_clk); |
| 454 | pr_err("%s: can't find dsi_pixel_clk. ret=%d\n", |
| 455 | __func__, ret); |
| 456 | msm_host->pixel_clk = NULL; |
| 457 | goto exit; |
| 458 | } |
| 459 | |
| 460 | msm_host->esc_clk = devm_clk_get(dev, "core_clk"); |
| 461 | if (IS_ERR(msm_host->esc_clk)) { |
| 462 | ret = PTR_ERR(msm_host->esc_clk); |
| 463 | pr_err("%s: can't find dsi_esc_clk. ret=%d\n", |
| 464 | __func__, ret); |
| 465 | msm_host->esc_clk = NULL; |
| 466 | goto exit; |
| 467 | } |
| 468 | |
Hai Li | 9d32c498 | 2015-05-15 13:04:05 -0400 | [diff] [blame] | 469 | msm_host->byte_clk_src = devm_clk_get(dev, "byte_clk_src"); |
| 470 | if (IS_ERR(msm_host->byte_clk_src)) { |
| 471 | ret = PTR_ERR(msm_host->byte_clk_src); |
| 472 | pr_err("%s: can't find byte_clk_src. ret=%d\n", __func__, ret); |
| 473 | msm_host->byte_clk_src = NULL; |
| 474 | goto exit; |
| 475 | } |
| 476 | |
| 477 | msm_host->pixel_clk_src = devm_clk_get(dev, "pixel_clk_src"); |
| 478 | if (IS_ERR(msm_host->pixel_clk_src)) { |
| 479 | ret = PTR_ERR(msm_host->pixel_clk_src); |
| 480 | pr_err("%s: can't find pixel_clk_src. ret=%d\n", __func__, ret); |
| 481 | msm_host->pixel_clk_src = NULL; |
| 482 | goto exit; |
| 483 | } |
| 484 | |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 485 | exit: |
| 486 | return ret; |
| 487 | } |
| 488 | |
| 489 | static int dsi_bus_clk_enable(struct msm_dsi_host *msm_host) |
| 490 | { |
| 491 | int ret; |
| 492 | |
| 493 | DBG("id=%d", msm_host->id); |
| 494 | |
| 495 | ret = clk_prepare_enable(msm_host->mdp_core_clk); |
| 496 | if (ret) { |
| 497 | pr_err("%s: failed to enable mdp_core_clock, %d\n", |
| 498 | __func__, ret); |
| 499 | goto core_clk_err; |
| 500 | } |
| 501 | |
| 502 | ret = clk_prepare_enable(msm_host->ahb_clk); |
| 503 | if (ret) { |
| 504 | pr_err("%s: failed to enable ahb clock, %d\n", __func__, ret); |
| 505 | goto ahb_clk_err; |
| 506 | } |
| 507 | |
| 508 | ret = clk_prepare_enable(msm_host->axi_clk); |
| 509 | if (ret) { |
| 510 | pr_err("%s: failed to enable ahb clock, %d\n", __func__, ret); |
| 511 | goto axi_clk_err; |
| 512 | } |
| 513 | |
| 514 | ret = clk_prepare_enable(msm_host->mmss_misc_ahb_clk); |
| 515 | if (ret) { |
| 516 | pr_err("%s: failed to enable mmss misc ahb clk, %d\n", |
| 517 | __func__, ret); |
| 518 | goto misc_ahb_clk_err; |
| 519 | } |
| 520 | |
| 521 | return 0; |
| 522 | |
| 523 | misc_ahb_clk_err: |
| 524 | clk_disable_unprepare(msm_host->axi_clk); |
| 525 | axi_clk_err: |
| 526 | clk_disable_unprepare(msm_host->ahb_clk); |
| 527 | ahb_clk_err: |
| 528 | clk_disable_unprepare(msm_host->mdp_core_clk); |
| 529 | core_clk_err: |
| 530 | return ret; |
| 531 | } |
| 532 | |
| 533 | static void dsi_bus_clk_disable(struct msm_dsi_host *msm_host) |
| 534 | { |
| 535 | DBG(""); |
| 536 | clk_disable_unprepare(msm_host->mmss_misc_ahb_clk); |
| 537 | clk_disable_unprepare(msm_host->axi_clk); |
| 538 | clk_disable_unprepare(msm_host->ahb_clk); |
| 539 | clk_disable_unprepare(msm_host->mdp_core_clk); |
| 540 | } |
| 541 | |
| 542 | static int dsi_link_clk_enable(struct msm_dsi_host *msm_host) |
| 543 | { |
| 544 | int ret; |
| 545 | |
| 546 | DBG("Set clk rates: pclk=%d, byteclk=%d", |
| 547 | msm_host->mode->clock, msm_host->byte_clk_rate); |
| 548 | |
| 549 | ret = clk_set_rate(msm_host->byte_clk, msm_host->byte_clk_rate); |
| 550 | if (ret) { |
| 551 | pr_err("%s: Failed to set rate byte clk, %d\n", __func__, ret); |
| 552 | goto error; |
| 553 | } |
| 554 | |
| 555 | ret = clk_set_rate(msm_host->pixel_clk, msm_host->mode->clock * 1000); |
| 556 | if (ret) { |
| 557 | pr_err("%s: Failed to set rate pixel clk, %d\n", __func__, ret); |
| 558 | goto error; |
| 559 | } |
| 560 | |
| 561 | ret = clk_prepare_enable(msm_host->esc_clk); |
| 562 | if (ret) { |
| 563 | pr_err("%s: Failed to enable dsi esc clk\n", __func__); |
| 564 | goto error; |
| 565 | } |
| 566 | |
| 567 | ret = clk_prepare_enable(msm_host->byte_clk); |
| 568 | if (ret) { |
| 569 | pr_err("%s: Failed to enable dsi byte clk\n", __func__); |
| 570 | goto byte_clk_err; |
| 571 | } |
| 572 | |
| 573 | ret = clk_prepare_enable(msm_host->pixel_clk); |
| 574 | if (ret) { |
| 575 | pr_err("%s: Failed to enable dsi pixel clk\n", __func__); |
| 576 | goto pixel_clk_err; |
| 577 | } |
| 578 | |
| 579 | return 0; |
| 580 | |
| 581 | pixel_clk_err: |
| 582 | clk_disable_unprepare(msm_host->byte_clk); |
| 583 | byte_clk_err: |
| 584 | clk_disable_unprepare(msm_host->esc_clk); |
| 585 | error: |
| 586 | return ret; |
| 587 | } |
| 588 | |
| 589 | static void dsi_link_clk_disable(struct msm_dsi_host *msm_host) |
| 590 | { |
| 591 | clk_disable_unprepare(msm_host->esc_clk); |
| 592 | clk_disable_unprepare(msm_host->pixel_clk); |
| 593 | clk_disable_unprepare(msm_host->byte_clk); |
| 594 | } |
| 595 | |
| 596 | static int dsi_clk_ctrl(struct msm_dsi_host *msm_host, bool enable) |
| 597 | { |
| 598 | int ret = 0; |
| 599 | |
| 600 | mutex_lock(&msm_host->clk_mutex); |
| 601 | if (enable) { |
| 602 | ret = dsi_bus_clk_enable(msm_host); |
| 603 | if (ret) { |
| 604 | pr_err("%s: Can not enable bus clk, %d\n", |
| 605 | __func__, ret); |
| 606 | goto unlock_ret; |
| 607 | } |
| 608 | ret = dsi_link_clk_enable(msm_host); |
| 609 | if (ret) { |
| 610 | pr_err("%s: Can not enable link clk, %d\n", |
| 611 | __func__, ret); |
| 612 | dsi_bus_clk_disable(msm_host); |
| 613 | goto unlock_ret; |
| 614 | } |
| 615 | } else { |
| 616 | dsi_link_clk_disable(msm_host); |
| 617 | dsi_bus_clk_disable(msm_host); |
| 618 | } |
| 619 | |
| 620 | unlock_ret: |
| 621 | mutex_unlock(&msm_host->clk_mutex); |
| 622 | return ret; |
| 623 | } |
| 624 | |
| 625 | static int dsi_calc_clk_rate(struct msm_dsi_host *msm_host) |
| 626 | { |
| 627 | struct drm_display_mode *mode = msm_host->mode; |
| 628 | u8 lanes = msm_host->lanes; |
| 629 | u32 bpp = dsi_get_bpp(msm_host->format); |
| 630 | u32 pclk_rate; |
| 631 | |
| 632 | if (!mode) { |
| 633 | pr_err("%s: mode not set\n", __func__); |
| 634 | return -EINVAL; |
| 635 | } |
| 636 | |
| 637 | pclk_rate = mode->clock * 1000; |
| 638 | if (lanes > 0) { |
| 639 | msm_host->byte_clk_rate = (pclk_rate * bpp) / (8 * lanes); |
| 640 | } else { |
| 641 | pr_err("%s: forcing mdss_dsi lanes to 1\n", __func__); |
| 642 | msm_host->byte_clk_rate = (pclk_rate * bpp) / 8; |
| 643 | } |
| 644 | |
| 645 | DBG("pclk=%d, bclk=%d", pclk_rate, msm_host->byte_clk_rate); |
| 646 | |
| 647 | return 0; |
| 648 | } |
| 649 | |
| 650 | static void dsi_phy_sw_reset(struct msm_dsi_host *msm_host) |
| 651 | { |
| 652 | DBG(""); |
| 653 | dsi_write(msm_host, REG_DSI_PHY_RESET, DSI_PHY_RESET_RESET); |
| 654 | /* Make sure fully reset */ |
| 655 | wmb(); |
| 656 | udelay(1000); |
| 657 | dsi_write(msm_host, REG_DSI_PHY_RESET, 0); |
| 658 | udelay(100); |
| 659 | } |
| 660 | |
| 661 | static void dsi_intr_ctrl(struct msm_dsi_host *msm_host, u32 mask, int enable) |
| 662 | { |
| 663 | u32 intr; |
| 664 | unsigned long flags; |
| 665 | |
| 666 | spin_lock_irqsave(&msm_host->intr_lock, flags); |
| 667 | intr = dsi_read(msm_host, REG_DSI_INTR_CTRL); |
| 668 | |
| 669 | if (enable) |
| 670 | intr |= mask; |
| 671 | else |
| 672 | intr &= ~mask; |
| 673 | |
| 674 | DBG("intr=%x enable=%d", intr, enable); |
| 675 | |
| 676 | dsi_write(msm_host, REG_DSI_INTR_CTRL, intr); |
| 677 | spin_unlock_irqrestore(&msm_host->intr_lock, flags); |
| 678 | } |
| 679 | |
| 680 | static inline enum dsi_traffic_mode dsi_get_traffic_mode(const u32 mode_flags) |
| 681 | { |
| 682 | if (mode_flags & MIPI_DSI_MODE_VIDEO_BURST) |
| 683 | return BURST_MODE; |
| 684 | else if (mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE) |
| 685 | return NON_BURST_SYNCH_PULSE; |
| 686 | |
| 687 | return NON_BURST_SYNCH_EVENT; |
| 688 | } |
| 689 | |
| 690 | static inline enum dsi_vid_dst_format dsi_get_vid_fmt( |
| 691 | const enum mipi_dsi_pixel_format mipi_fmt) |
| 692 | { |
| 693 | switch (mipi_fmt) { |
| 694 | case MIPI_DSI_FMT_RGB888: return VID_DST_FORMAT_RGB888; |
| 695 | case MIPI_DSI_FMT_RGB666: return VID_DST_FORMAT_RGB666_LOOSE; |
| 696 | case MIPI_DSI_FMT_RGB666_PACKED: return VID_DST_FORMAT_RGB666; |
| 697 | case MIPI_DSI_FMT_RGB565: return VID_DST_FORMAT_RGB565; |
| 698 | default: return VID_DST_FORMAT_RGB888; |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | static inline enum dsi_cmd_dst_format dsi_get_cmd_fmt( |
| 703 | const enum mipi_dsi_pixel_format mipi_fmt) |
| 704 | { |
| 705 | switch (mipi_fmt) { |
| 706 | case MIPI_DSI_FMT_RGB888: return CMD_DST_FORMAT_RGB888; |
| 707 | case MIPI_DSI_FMT_RGB666_PACKED: |
| 708 | case MIPI_DSI_FMT_RGB666: return VID_DST_FORMAT_RGB666; |
| 709 | case MIPI_DSI_FMT_RGB565: return CMD_DST_FORMAT_RGB565; |
| 710 | default: return CMD_DST_FORMAT_RGB888; |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | static void dsi_ctrl_config(struct msm_dsi_host *msm_host, bool enable, |
| 715 | u32 clk_pre, u32 clk_post) |
| 716 | { |
| 717 | u32 flags = msm_host->mode_flags; |
| 718 | enum mipi_dsi_pixel_format mipi_fmt = msm_host->format; |
| 719 | u32 data = 0; |
| 720 | |
| 721 | if (!enable) { |
| 722 | dsi_write(msm_host, REG_DSI_CTRL, 0); |
| 723 | return; |
| 724 | } |
| 725 | |
| 726 | if (flags & MIPI_DSI_MODE_VIDEO) { |
| 727 | if (flags & MIPI_DSI_MODE_VIDEO_HSE) |
| 728 | data |= DSI_VID_CFG0_PULSE_MODE_HSA_HE; |
| 729 | if (flags & MIPI_DSI_MODE_VIDEO_HFP) |
| 730 | data |= DSI_VID_CFG0_HFP_POWER_STOP; |
| 731 | if (flags & MIPI_DSI_MODE_VIDEO_HBP) |
| 732 | data |= DSI_VID_CFG0_HBP_POWER_STOP; |
| 733 | if (flags & MIPI_DSI_MODE_VIDEO_HSA) |
| 734 | data |= DSI_VID_CFG0_HSA_POWER_STOP; |
| 735 | /* Always set low power stop mode for BLLP |
| 736 | * to let command engine send packets |
| 737 | */ |
| 738 | data |= DSI_VID_CFG0_EOF_BLLP_POWER_STOP | |
| 739 | DSI_VID_CFG0_BLLP_POWER_STOP; |
| 740 | data |= DSI_VID_CFG0_TRAFFIC_MODE(dsi_get_traffic_mode(flags)); |
| 741 | data |= DSI_VID_CFG0_DST_FORMAT(dsi_get_vid_fmt(mipi_fmt)); |
| 742 | data |= DSI_VID_CFG0_VIRT_CHANNEL(msm_host->channel); |
| 743 | dsi_write(msm_host, REG_DSI_VID_CFG0, data); |
| 744 | |
| 745 | /* Do not swap RGB colors */ |
| 746 | data = DSI_VID_CFG1_RGB_SWAP(SWAP_RGB); |
| 747 | dsi_write(msm_host, REG_DSI_VID_CFG1, 0); |
| 748 | } else { |
| 749 | /* Do not swap RGB colors */ |
| 750 | data = DSI_CMD_CFG0_RGB_SWAP(SWAP_RGB); |
| 751 | data |= DSI_CMD_CFG0_DST_FORMAT(dsi_get_cmd_fmt(mipi_fmt)); |
| 752 | dsi_write(msm_host, REG_DSI_CMD_CFG0, data); |
| 753 | |
| 754 | data = DSI_CMD_CFG1_WR_MEM_START(MIPI_DCS_WRITE_MEMORY_START) | |
| 755 | DSI_CMD_CFG1_WR_MEM_CONTINUE( |
| 756 | MIPI_DCS_WRITE_MEMORY_CONTINUE); |
| 757 | /* Always insert DCS command */ |
| 758 | data |= DSI_CMD_CFG1_INSERT_DCS_COMMAND; |
| 759 | dsi_write(msm_host, REG_DSI_CMD_CFG1, data); |
| 760 | } |
| 761 | |
| 762 | dsi_write(msm_host, REG_DSI_CMD_DMA_CTRL, |
| 763 | DSI_CMD_DMA_CTRL_FROM_FRAME_BUFFER | |
| 764 | DSI_CMD_DMA_CTRL_LOW_POWER); |
| 765 | |
| 766 | data = 0; |
| 767 | /* Always assume dedicated TE pin */ |
| 768 | data |= DSI_TRIG_CTRL_TE; |
| 769 | data |= DSI_TRIG_CTRL_MDP_TRIGGER(TRIGGER_NONE); |
| 770 | data |= DSI_TRIG_CTRL_DMA_TRIGGER(TRIGGER_SW); |
| 771 | data |= DSI_TRIG_CTRL_STREAM(msm_host->channel); |
| 772 | if ((msm_host->cfg->major == MSM_DSI_VER_MAJOR_6G) && |
| 773 | (msm_host->cfg->minor >= MSM_DSI_6G_VER_MINOR_V1_2)) |
| 774 | data |= DSI_TRIG_CTRL_BLOCK_DMA_WITHIN_FRAME; |
| 775 | dsi_write(msm_host, REG_DSI_TRIG_CTRL, data); |
| 776 | |
| 777 | data = DSI_CLKOUT_TIMING_CTRL_T_CLK_POST(clk_post) | |
| 778 | DSI_CLKOUT_TIMING_CTRL_T_CLK_PRE(clk_pre); |
| 779 | dsi_write(msm_host, REG_DSI_CLKOUT_TIMING_CTRL, data); |
| 780 | |
| 781 | data = 0; |
| 782 | if (!(flags & MIPI_DSI_MODE_EOT_PACKET)) |
| 783 | data |= DSI_EOT_PACKET_CTRL_TX_EOT_APPEND; |
| 784 | dsi_write(msm_host, REG_DSI_EOT_PACKET_CTRL, data); |
| 785 | |
| 786 | /* allow only ack-err-status to generate interrupt */ |
| 787 | dsi_write(msm_host, REG_DSI_ERR_INT_MASK0, 0x13ff3fe0); |
| 788 | |
| 789 | dsi_intr_ctrl(msm_host, DSI_IRQ_MASK_ERROR, 1); |
| 790 | |
| 791 | dsi_write(msm_host, REG_DSI_CLK_CTRL, DSI_CLK_CTRL_ENABLE_CLKS); |
| 792 | |
| 793 | data = DSI_CTRL_CLK_EN; |
| 794 | |
| 795 | DBG("lane number=%d", msm_host->lanes); |
| 796 | if (msm_host->lanes == 2) { |
| 797 | data |= DSI_CTRL_LANE1 | DSI_CTRL_LANE2; |
| 798 | /* swap lanes for 2-lane panel for better performance */ |
| 799 | dsi_write(msm_host, REG_DSI_LANE_SWAP_CTRL, |
| 800 | DSI_LANE_SWAP_CTRL_DLN_SWAP_SEL(LANE_SWAP_1230)); |
| 801 | } else { |
| 802 | /* Take 4 lanes as default */ |
| 803 | data |= DSI_CTRL_LANE0 | DSI_CTRL_LANE1 | DSI_CTRL_LANE2 | |
| 804 | DSI_CTRL_LANE3; |
| 805 | /* Do not swap lanes for 4-lane panel */ |
| 806 | dsi_write(msm_host, REG_DSI_LANE_SWAP_CTRL, |
| 807 | DSI_LANE_SWAP_CTRL_DLN_SWAP_SEL(LANE_SWAP_0123)); |
| 808 | } |
Archit Taneja | 65c5e54 | 2015-04-08 11:37:40 +0530 | [diff] [blame] | 809 | |
| 810 | if (!(flags & MIPI_DSI_CLOCK_NON_CONTINUOUS)) |
| 811 | dsi_write(msm_host, REG_DSI_LANE_CTRL, |
| 812 | DSI_LANE_CTRL_CLKLN_HS_FORCE_REQUEST); |
| 813 | |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 814 | data |= DSI_CTRL_ENABLE; |
| 815 | |
| 816 | dsi_write(msm_host, REG_DSI_CTRL, data); |
| 817 | } |
| 818 | |
| 819 | static void dsi_timing_setup(struct msm_dsi_host *msm_host) |
| 820 | { |
| 821 | struct drm_display_mode *mode = msm_host->mode; |
| 822 | u32 hs_start = 0, vs_start = 0; /* take sync start as 0 */ |
| 823 | u32 h_total = mode->htotal; |
| 824 | u32 v_total = mode->vtotal; |
| 825 | u32 hs_end = mode->hsync_end - mode->hsync_start; |
| 826 | u32 vs_end = mode->vsync_end - mode->vsync_start; |
| 827 | u32 ha_start = h_total - mode->hsync_start; |
| 828 | u32 ha_end = ha_start + mode->hdisplay; |
| 829 | u32 va_start = v_total - mode->vsync_start; |
| 830 | u32 va_end = va_start + mode->vdisplay; |
| 831 | u32 wc; |
| 832 | |
| 833 | DBG(""); |
| 834 | |
| 835 | if (msm_host->mode_flags & MIPI_DSI_MODE_VIDEO) { |
| 836 | dsi_write(msm_host, REG_DSI_ACTIVE_H, |
| 837 | DSI_ACTIVE_H_START(ha_start) | |
| 838 | DSI_ACTIVE_H_END(ha_end)); |
| 839 | dsi_write(msm_host, REG_DSI_ACTIVE_V, |
| 840 | DSI_ACTIVE_V_START(va_start) | |
| 841 | DSI_ACTIVE_V_END(va_end)); |
| 842 | dsi_write(msm_host, REG_DSI_TOTAL, |
| 843 | DSI_TOTAL_H_TOTAL(h_total - 1) | |
| 844 | DSI_TOTAL_V_TOTAL(v_total - 1)); |
| 845 | |
| 846 | dsi_write(msm_host, REG_DSI_ACTIVE_HSYNC, |
| 847 | DSI_ACTIVE_HSYNC_START(hs_start) | |
| 848 | DSI_ACTIVE_HSYNC_END(hs_end)); |
| 849 | dsi_write(msm_host, REG_DSI_ACTIVE_VSYNC_HPOS, 0); |
| 850 | dsi_write(msm_host, REG_DSI_ACTIVE_VSYNC_VPOS, |
| 851 | DSI_ACTIVE_VSYNC_VPOS_START(vs_start) | |
| 852 | DSI_ACTIVE_VSYNC_VPOS_END(vs_end)); |
| 853 | } else { /* command mode */ |
| 854 | /* image data and 1 byte write_memory_start cmd */ |
| 855 | wc = mode->hdisplay * dsi_get_bpp(msm_host->format) / 8 + 1; |
| 856 | |
| 857 | dsi_write(msm_host, REG_DSI_CMD_MDP_STREAM_CTRL, |
| 858 | DSI_CMD_MDP_STREAM_CTRL_WORD_COUNT(wc) | |
| 859 | DSI_CMD_MDP_STREAM_CTRL_VIRTUAL_CHANNEL( |
| 860 | msm_host->channel) | |
| 861 | DSI_CMD_MDP_STREAM_CTRL_DATA_TYPE( |
| 862 | MIPI_DSI_DCS_LONG_WRITE)); |
| 863 | |
| 864 | dsi_write(msm_host, REG_DSI_CMD_MDP_STREAM_TOTAL, |
| 865 | DSI_CMD_MDP_STREAM_TOTAL_H_TOTAL(mode->hdisplay) | |
| 866 | DSI_CMD_MDP_STREAM_TOTAL_V_TOTAL(mode->vdisplay)); |
| 867 | } |
| 868 | } |
| 869 | |
| 870 | static void dsi_sw_reset(struct msm_dsi_host *msm_host) |
| 871 | { |
| 872 | dsi_write(msm_host, REG_DSI_CLK_CTRL, DSI_CLK_CTRL_ENABLE_CLKS); |
| 873 | wmb(); /* clocks need to be enabled before reset */ |
| 874 | |
| 875 | dsi_write(msm_host, REG_DSI_RESET, 1); |
| 876 | wmb(); /* make sure reset happen */ |
| 877 | dsi_write(msm_host, REG_DSI_RESET, 0); |
| 878 | } |
| 879 | |
| 880 | static void dsi_op_mode_config(struct msm_dsi_host *msm_host, |
| 881 | bool video_mode, bool enable) |
| 882 | { |
| 883 | u32 dsi_ctrl; |
| 884 | |
| 885 | dsi_ctrl = dsi_read(msm_host, REG_DSI_CTRL); |
| 886 | |
| 887 | if (!enable) { |
| 888 | dsi_ctrl &= ~(DSI_CTRL_ENABLE | DSI_CTRL_VID_MODE_EN | |
| 889 | DSI_CTRL_CMD_MODE_EN); |
| 890 | dsi_intr_ctrl(msm_host, DSI_IRQ_MASK_CMD_MDP_DONE | |
| 891 | DSI_IRQ_MASK_VIDEO_DONE, 0); |
| 892 | } else { |
| 893 | if (video_mode) { |
| 894 | dsi_ctrl |= DSI_CTRL_VID_MODE_EN; |
| 895 | } else { /* command mode */ |
| 896 | dsi_ctrl |= DSI_CTRL_CMD_MODE_EN; |
| 897 | dsi_intr_ctrl(msm_host, DSI_IRQ_MASK_CMD_MDP_DONE, 1); |
| 898 | } |
| 899 | dsi_ctrl |= DSI_CTRL_ENABLE; |
| 900 | } |
| 901 | |
| 902 | dsi_write(msm_host, REG_DSI_CTRL, dsi_ctrl); |
| 903 | } |
| 904 | |
| 905 | static void dsi_set_tx_power_mode(int mode, struct msm_dsi_host *msm_host) |
| 906 | { |
| 907 | u32 data; |
| 908 | |
| 909 | data = dsi_read(msm_host, REG_DSI_CMD_DMA_CTRL); |
| 910 | |
| 911 | if (mode == 0) |
| 912 | data &= ~DSI_CMD_DMA_CTRL_LOW_POWER; |
| 913 | else |
| 914 | data |= DSI_CMD_DMA_CTRL_LOW_POWER; |
| 915 | |
| 916 | dsi_write(msm_host, REG_DSI_CMD_DMA_CTRL, data); |
| 917 | } |
| 918 | |
| 919 | static void dsi_wait4video_done(struct msm_dsi_host *msm_host) |
| 920 | { |
| 921 | dsi_intr_ctrl(msm_host, DSI_IRQ_MASK_VIDEO_DONE, 1); |
| 922 | |
| 923 | reinit_completion(&msm_host->video_comp); |
| 924 | |
| 925 | wait_for_completion_timeout(&msm_host->video_comp, |
| 926 | msecs_to_jiffies(70)); |
| 927 | |
| 928 | dsi_intr_ctrl(msm_host, DSI_IRQ_MASK_VIDEO_DONE, 0); |
| 929 | } |
| 930 | |
| 931 | static void dsi_wait4video_eng_busy(struct msm_dsi_host *msm_host) |
| 932 | { |
| 933 | if (!(msm_host->mode_flags & MIPI_DSI_MODE_VIDEO)) |
| 934 | return; |
| 935 | |
| 936 | if (msm_host->power_on) { |
| 937 | dsi_wait4video_done(msm_host); |
| 938 | /* delay 4 ms to skip BLLP */ |
| 939 | usleep_range(2000, 4000); |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | /* dsi_cmd */ |
| 944 | static int dsi_tx_buf_alloc(struct msm_dsi_host *msm_host, int size) |
| 945 | { |
| 946 | struct drm_device *dev = msm_host->dev; |
| 947 | int ret; |
| 948 | u32 iova; |
| 949 | |
| 950 | mutex_lock(&dev->struct_mutex); |
| 951 | msm_host->tx_gem_obj = msm_gem_new(dev, size, MSM_BO_UNCACHED); |
| 952 | if (IS_ERR(msm_host->tx_gem_obj)) { |
| 953 | ret = PTR_ERR(msm_host->tx_gem_obj); |
| 954 | pr_err("%s: failed to allocate gem, %d\n", __func__, ret); |
| 955 | msm_host->tx_gem_obj = NULL; |
| 956 | mutex_unlock(&dev->struct_mutex); |
| 957 | return ret; |
| 958 | } |
| 959 | |
| 960 | ret = msm_gem_get_iova_locked(msm_host->tx_gem_obj, 0, &iova); |
| 961 | if (ret) { |
| 962 | pr_err("%s: failed to get iova, %d\n", __func__, ret); |
| 963 | return ret; |
| 964 | } |
| 965 | mutex_unlock(&dev->struct_mutex); |
| 966 | |
| 967 | if (iova & 0x07) { |
| 968 | pr_err("%s: buf NOT 8 bytes aligned\n", __func__); |
| 969 | return -EINVAL; |
| 970 | } |
| 971 | |
| 972 | return 0; |
| 973 | } |
| 974 | |
| 975 | static void dsi_tx_buf_free(struct msm_dsi_host *msm_host) |
| 976 | { |
| 977 | struct drm_device *dev = msm_host->dev; |
| 978 | |
| 979 | if (msm_host->tx_gem_obj) { |
| 980 | msm_gem_put_iova(msm_host->tx_gem_obj, 0); |
| 981 | mutex_lock(&dev->struct_mutex); |
| 982 | msm_gem_free_object(msm_host->tx_gem_obj); |
| 983 | msm_host->tx_gem_obj = NULL; |
| 984 | mutex_unlock(&dev->struct_mutex); |
| 985 | } |
| 986 | } |
| 987 | |
| 988 | /* |
| 989 | * prepare cmd buffer to be txed |
| 990 | */ |
| 991 | static int dsi_cmd_dma_add(struct drm_gem_object *tx_gem, |
| 992 | const struct mipi_dsi_msg *msg) |
| 993 | { |
| 994 | struct mipi_dsi_packet packet; |
| 995 | int len; |
| 996 | int ret; |
| 997 | u8 *data; |
| 998 | |
| 999 | ret = mipi_dsi_create_packet(&packet, msg); |
| 1000 | if (ret) { |
| 1001 | pr_err("%s: create packet failed, %d\n", __func__, ret); |
| 1002 | return ret; |
| 1003 | } |
| 1004 | len = (packet.size + 3) & (~0x3); |
| 1005 | |
| 1006 | if (len > tx_gem->size) { |
| 1007 | pr_err("%s: packet size is too big\n", __func__); |
| 1008 | return -EINVAL; |
| 1009 | } |
| 1010 | |
| 1011 | data = msm_gem_vaddr(tx_gem); |
| 1012 | |
| 1013 | if (IS_ERR(data)) { |
| 1014 | ret = PTR_ERR(data); |
| 1015 | pr_err("%s: get vaddr failed, %d\n", __func__, ret); |
| 1016 | return ret; |
| 1017 | } |
| 1018 | |
| 1019 | /* MSM specific command format in memory */ |
| 1020 | data[0] = packet.header[1]; |
| 1021 | data[1] = packet.header[2]; |
| 1022 | data[2] = packet.header[0]; |
| 1023 | data[3] = BIT(7); /* Last packet */ |
| 1024 | if (mipi_dsi_packet_format_is_long(msg->type)) |
| 1025 | data[3] |= BIT(6); |
| 1026 | if (msg->rx_buf && msg->rx_len) |
| 1027 | data[3] |= BIT(5); |
| 1028 | |
| 1029 | /* Long packet */ |
| 1030 | if (packet.payload && packet.payload_length) |
| 1031 | memcpy(data + 4, packet.payload, packet.payload_length); |
| 1032 | |
| 1033 | /* Append 0xff to the end */ |
| 1034 | if (packet.size < len) |
| 1035 | memset(data + packet.size, 0xff, len - packet.size); |
| 1036 | |
| 1037 | return len; |
| 1038 | } |
| 1039 | |
| 1040 | /* |
| 1041 | * dsi_short_read1_resp: 1 parameter |
| 1042 | */ |
| 1043 | static int dsi_short_read1_resp(u8 *buf, const struct mipi_dsi_msg *msg) |
| 1044 | { |
| 1045 | u8 *data = msg->rx_buf; |
| 1046 | if (data && (msg->rx_len >= 1)) { |
| 1047 | *data = buf[1]; /* strip out dcs type */ |
| 1048 | return 1; |
| 1049 | } else { |
Stephane Viau | 981371f | 2015-04-30 10:39:26 -0400 | [diff] [blame] | 1050 | pr_err("%s: read data does not match with rx_buf len %zu\n", |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 1051 | __func__, msg->rx_len); |
| 1052 | return -EINVAL; |
| 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | /* |
| 1057 | * dsi_short_read2_resp: 2 parameter |
| 1058 | */ |
| 1059 | static int dsi_short_read2_resp(u8 *buf, const struct mipi_dsi_msg *msg) |
| 1060 | { |
| 1061 | u8 *data = msg->rx_buf; |
| 1062 | if (data && (msg->rx_len >= 2)) { |
| 1063 | data[0] = buf[1]; /* strip out dcs type */ |
| 1064 | data[1] = buf[2]; |
| 1065 | return 2; |
| 1066 | } else { |
Stephane Viau | 981371f | 2015-04-30 10:39:26 -0400 | [diff] [blame] | 1067 | pr_err("%s: read data does not match with rx_buf len %zu\n", |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 1068 | __func__, msg->rx_len); |
| 1069 | return -EINVAL; |
| 1070 | } |
| 1071 | } |
| 1072 | |
| 1073 | static int dsi_long_read_resp(u8 *buf, const struct mipi_dsi_msg *msg) |
| 1074 | { |
| 1075 | /* strip out 4 byte dcs header */ |
| 1076 | if (msg->rx_buf && msg->rx_len) |
| 1077 | memcpy(msg->rx_buf, buf + 4, msg->rx_len); |
| 1078 | |
| 1079 | return msg->rx_len; |
| 1080 | } |
| 1081 | |
| 1082 | |
| 1083 | static int dsi_cmd_dma_tx(struct msm_dsi_host *msm_host, int len) |
| 1084 | { |
| 1085 | int ret; |
| 1086 | u32 iova; |
| 1087 | bool triggered; |
| 1088 | |
| 1089 | ret = msm_gem_get_iova(msm_host->tx_gem_obj, 0, &iova); |
| 1090 | if (ret) { |
| 1091 | pr_err("%s: failed to get iova: %d\n", __func__, ret); |
| 1092 | return ret; |
| 1093 | } |
| 1094 | |
| 1095 | reinit_completion(&msm_host->dma_comp); |
| 1096 | |
| 1097 | dsi_wait4video_eng_busy(msm_host); |
| 1098 | |
| 1099 | triggered = msm_dsi_manager_cmd_xfer_trigger( |
| 1100 | msm_host->id, iova, len); |
| 1101 | if (triggered) { |
| 1102 | ret = wait_for_completion_timeout(&msm_host->dma_comp, |
| 1103 | msecs_to_jiffies(200)); |
| 1104 | DBG("ret=%d", ret); |
| 1105 | if (ret == 0) |
| 1106 | ret = -ETIMEDOUT; |
| 1107 | else |
| 1108 | ret = len; |
| 1109 | } else |
| 1110 | ret = len; |
| 1111 | |
| 1112 | return ret; |
| 1113 | } |
| 1114 | |
| 1115 | static int dsi_cmd_dma_rx(struct msm_dsi_host *msm_host, |
| 1116 | u8 *buf, int rx_byte, int pkt_size) |
| 1117 | { |
| 1118 | u32 *lp, *temp, data; |
| 1119 | int i, j = 0, cnt; |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 1120 | u32 read_cnt; |
| 1121 | u8 reg[16]; |
| 1122 | int repeated_bytes = 0; |
| 1123 | int buf_offset = buf - msm_host->rx_buf; |
| 1124 | |
| 1125 | lp = (u32 *)buf; |
| 1126 | temp = (u32 *)reg; |
| 1127 | cnt = (rx_byte + 3) >> 2; |
| 1128 | if (cnt > 4) |
| 1129 | cnt = 4; /* 4 x 32 bits registers only */ |
| 1130 | |
Hai Li | ec1936e | 2015-04-29 11:39:00 -0400 | [diff] [blame] | 1131 | if (rx_byte == 4) |
| 1132 | read_cnt = 4; |
| 1133 | else |
| 1134 | read_cnt = pkt_size + 6; |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 1135 | |
| 1136 | /* |
| 1137 | * In case of multiple reads from the panel, after the first read, there |
| 1138 | * is possibility that there are some bytes in the payload repeating in |
| 1139 | * the RDBK_DATA registers. Since we read all the parameters from the |
| 1140 | * panel right from the first byte for every pass. We need to skip the |
| 1141 | * repeating bytes and then append the new parameters to the rx buffer. |
| 1142 | */ |
| 1143 | if (read_cnt > 16) { |
| 1144 | int bytes_shifted; |
| 1145 | /* Any data more than 16 bytes will be shifted out. |
| 1146 | * The temp read buffer should already contain these bytes. |
| 1147 | * The remaining bytes in read buffer are the repeated bytes. |
| 1148 | */ |
| 1149 | bytes_shifted = read_cnt - 16; |
| 1150 | repeated_bytes = buf_offset - bytes_shifted; |
| 1151 | } |
| 1152 | |
| 1153 | for (i = cnt - 1; i >= 0; i--) { |
| 1154 | data = dsi_read(msm_host, REG_DSI_RDBK_DATA(i)); |
| 1155 | *temp++ = ntohl(data); /* to host byte order */ |
| 1156 | DBG("data = 0x%x and ntohl(data) = 0x%x", data, ntohl(data)); |
| 1157 | } |
| 1158 | |
| 1159 | for (i = repeated_bytes; i < 16; i++) |
| 1160 | buf[j++] = reg[i]; |
| 1161 | |
| 1162 | return j; |
| 1163 | } |
| 1164 | |
| 1165 | static int dsi_cmds2buf_tx(struct msm_dsi_host *msm_host, |
| 1166 | const struct mipi_dsi_msg *msg) |
| 1167 | { |
| 1168 | int len, ret; |
| 1169 | int bllp_len = msm_host->mode->hdisplay * |
| 1170 | dsi_get_bpp(msm_host->format) / 8; |
| 1171 | |
| 1172 | len = dsi_cmd_dma_add(msm_host->tx_gem_obj, msg); |
| 1173 | if (!len) { |
| 1174 | pr_err("%s: failed to add cmd type = 0x%x\n", |
| 1175 | __func__, msg->type); |
| 1176 | return -EINVAL; |
| 1177 | } |
| 1178 | |
| 1179 | /* for video mode, do not send cmds more than |
| 1180 | * one pixel line, since it only transmit it |
| 1181 | * during BLLP. |
| 1182 | */ |
| 1183 | /* TODO: if the command is sent in LP mode, the bit rate is only |
| 1184 | * half of esc clk rate. In this case, if the video is already |
| 1185 | * actively streaming, we need to check more carefully if the |
| 1186 | * command can be fit into one BLLP. |
| 1187 | */ |
| 1188 | if ((msm_host->mode_flags & MIPI_DSI_MODE_VIDEO) && (len > bllp_len)) { |
| 1189 | pr_err("%s: cmd cannot fit into BLLP period, len=%d\n", |
| 1190 | __func__, len); |
| 1191 | return -EINVAL; |
| 1192 | } |
| 1193 | |
| 1194 | ret = dsi_cmd_dma_tx(msm_host, len); |
| 1195 | if (ret < len) { |
| 1196 | pr_err("%s: cmd dma tx failed, type=0x%x, data0=0x%x, len=%d\n", |
| 1197 | __func__, msg->type, (*(u8 *)(msg->tx_buf)), len); |
| 1198 | return -ECOMM; |
| 1199 | } |
| 1200 | |
| 1201 | return len; |
| 1202 | } |
| 1203 | |
| 1204 | static void dsi_sw_reset_restore(struct msm_dsi_host *msm_host) |
| 1205 | { |
| 1206 | u32 data0, data1; |
| 1207 | |
| 1208 | data0 = dsi_read(msm_host, REG_DSI_CTRL); |
| 1209 | data1 = data0; |
| 1210 | data1 &= ~DSI_CTRL_ENABLE; |
| 1211 | dsi_write(msm_host, REG_DSI_CTRL, data1); |
| 1212 | /* |
| 1213 | * dsi controller need to be disabled before |
| 1214 | * clocks turned on |
| 1215 | */ |
| 1216 | wmb(); |
| 1217 | |
| 1218 | dsi_write(msm_host, REG_DSI_CLK_CTRL, DSI_CLK_CTRL_ENABLE_CLKS); |
| 1219 | wmb(); /* make sure clocks enabled */ |
| 1220 | |
| 1221 | /* dsi controller can only be reset while clocks are running */ |
| 1222 | dsi_write(msm_host, REG_DSI_RESET, 1); |
| 1223 | wmb(); /* make sure reset happen */ |
| 1224 | dsi_write(msm_host, REG_DSI_RESET, 0); |
| 1225 | wmb(); /* controller out of reset */ |
| 1226 | dsi_write(msm_host, REG_DSI_CTRL, data0); |
| 1227 | wmb(); /* make sure dsi controller enabled again */ |
| 1228 | } |
| 1229 | |
| 1230 | static void dsi_err_worker(struct work_struct *work) |
| 1231 | { |
| 1232 | struct msm_dsi_host *msm_host = |
| 1233 | container_of(work, struct msm_dsi_host, err_work); |
| 1234 | u32 status = msm_host->err_work_state; |
| 1235 | |
Rob Clark | ff431fa | 2015-05-07 15:19:02 -0400 | [diff] [blame] | 1236 | pr_err_ratelimited("%s: status=%x\n", __func__, status); |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 1237 | if (status & DSI_ERR_STATE_MDP_FIFO_UNDERFLOW) |
| 1238 | dsi_sw_reset_restore(msm_host); |
| 1239 | |
| 1240 | /* It is safe to clear here because error irq is disabled. */ |
| 1241 | msm_host->err_work_state = 0; |
| 1242 | |
| 1243 | /* enable dsi error interrupt */ |
| 1244 | dsi_intr_ctrl(msm_host, DSI_IRQ_MASK_ERROR, 1); |
| 1245 | } |
| 1246 | |
| 1247 | static void dsi_ack_err_status(struct msm_dsi_host *msm_host) |
| 1248 | { |
| 1249 | u32 status; |
| 1250 | |
| 1251 | status = dsi_read(msm_host, REG_DSI_ACK_ERR_STATUS); |
| 1252 | |
| 1253 | if (status) { |
| 1254 | dsi_write(msm_host, REG_DSI_ACK_ERR_STATUS, status); |
| 1255 | /* Writing of an extra 0 needed to clear error bits */ |
| 1256 | dsi_write(msm_host, REG_DSI_ACK_ERR_STATUS, 0); |
| 1257 | msm_host->err_work_state |= DSI_ERR_STATE_ACK; |
| 1258 | } |
| 1259 | } |
| 1260 | |
| 1261 | static void dsi_timeout_status(struct msm_dsi_host *msm_host) |
| 1262 | { |
| 1263 | u32 status; |
| 1264 | |
| 1265 | status = dsi_read(msm_host, REG_DSI_TIMEOUT_STATUS); |
| 1266 | |
| 1267 | if (status) { |
| 1268 | dsi_write(msm_host, REG_DSI_TIMEOUT_STATUS, status); |
| 1269 | msm_host->err_work_state |= DSI_ERR_STATE_TIMEOUT; |
| 1270 | } |
| 1271 | } |
| 1272 | |
| 1273 | static void dsi_dln0_phy_err(struct msm_dsi_host *msm_host) |
| 1274 | { |
| 1275 | u32 status; |
| 1276 | |
| 1277 | status = dsi_read(msm_host, REG_DSI_DLN0_PHY_ERR); |
| 1278 | |
Archit Taneja | 0119936 | 2015-06-25 11:29:24 +0530 | [diff] [blame^] | 1279 | if (status & (DSI_DLN0_PHY_ERR_DLN0_ERR_ESC | |
| 1280 | DSI_DLN0_PHY_ERR_DLN0_ERR_SYNC_ESC | |
| 1281 | DSI_DLN0_PHY_ERR_DLN0_ERR_CONTROL | |
| 1282 | DSI_DLN0_PHY_ERR_DLN0_ERR_CONTENTION_LP0 | |
| 1283 | DSI_DLN0_PHY_ERR_DLN0_ERR_CONTENTION_LP1)) { |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 1284 | dsi_write(msm_host, REG_DSI_DLN0_PHY_ERR, status); |
| 1285 | msm_host->err_work_state |= DSI_ERR_STATE_DLN0_PHY; |
| 1286 | } |
| 1287 | } |
| 1288 | |
| 1289 | static void dsi_fifo_status(struct msm_dsi_host *msm_host) |
| 1290 | { |
| 1291 | u32 status; |
| 1292 | |
| 1293 | status = dsi_read(msm_host, REG_DSI_FIFO_STATUS); |
| 1294 | |
| 1295 | /* fifo underflow, overflow */ |
| 1296 | if (status) { |
| 1297 | dsi_write(msm_host, REG_DSI_FIFO_STATUS, status); |
| 1298 | msm_host->err_work_state |= DSI_ERR_STATE_FIFO; |
| 1299 | if (status & DSI_FIFO_STATUS_CMD_MDP_FIFO_UNDERFLOW) |
| 1300 | msm_host->err_work_state |= |
| 1301 | DSI_ERR_STATE_MDP_FIFO_UNDERFLOW; |
| 1302 | } |
| 1303 | } |
| 1304 | |
| 1305 | static void dsi_status(struct msm_dsi_host *msm_host) |
| 1306 | { |
| 1307 | u32 status; |
| 1308 | |
| 1309 | status = dsi_read(msm_host, REG_DSI_STATUS0); |
| 1310 | |
| 1311 | if (status & DSI_STATUS0_INTERLEAVE_OP_CONTENTION) { |
| 1312 | dsi_write(msm_host, REG_DSI_STATUS0, status); |
| 1313 | msm_host->err_work_state |= |
| 1314 | DSI_ERR_STATE_INTERLEAVE_OP_CONTENTION; |
| 1315 | } |
| 1316 | } |
| 1317 | |
| 1318 | static void dsi_clk_status(struct msm_dsi_host *msm_host) |
| 1319 | { |
| 1320 | u32 status; |
| 1321 | |
| 1322 | status = dsi_read(msm_host, REG_DSI_CLK_STATUS); |
| 1323 | |
| 1324 | if (status & DSI_CLK_STATUS_PLL_UNLOCKED) { |
| 1325 | dsi_write(msm_host, REG_DSI_CLK_STATUS, status); |
| 1326 | msm_host->err_work_state |= DSI_ERR_STATE_PLL_UNLOCKED; |
| 1327 | } |
| 1328 | } |
| 1329 | |
| 1330 | static void dsi_error(struct msm_dsi_host *msm_host) |
| 1331 | { |
| 1332 | /* disable dsi error interrupt */ |
| 1333 | dsi_intr_ctrl(msm_host, DSI_IRQ_MASK_ERROR, 0); |
| 1334 | |
| 1335 | dsi_clk_status(msm_host); |
| 1336 | dsi_fifo_status(msm_host); |
| 1337 | dsi_ack_err_status(msm_host); |
| 1338 | dsi_timeout_status(msm_host); |
| 1339 | dsi_status(msm_host); |
| 1340 | dsi_dln0_phy_err(msm_host); |
| 1341 | |
| 1342 | queue_work(msm_host->workqueue, &msm_host->err_work); |
| 1343 | } |
| 1344 | |
| 1345 | static irqreturn_t dsi_host_irq(int irq, void *ptr) |
| 1346 | { |
| 1347 | struct msm_dsi_host *msm_host = ptr; |
| 1348 | u32 isr; |
| 1349 | unsigned long flags; |
| 1350 | |
| 1351 | if (!msm_host->ctrl_base) |
| 1352 | return IRQ_HANDLED; |
| 1353 | |
| 1354 | spin_lock_irqsave(&msm_host->intr_lock, flags); |
| 1355 | isr = dsi_read(msm_host, REG_DSI_INTR_CTRL); |
| 1356 | dsi_write(msm_host, REG_DSI_INTR_CTRL, isr); |
| 1357 | spin_unlock_irqrestore(&msm_host->intr_lock, flags); |
| 1358 | |
| 1359 | DBG("isr=0x%x, id=%d", isr, msm_host->id); |
| 1360 | |
| 1361 | if (isr & DSI_IRQ_ERROR) |
| 1362 | dsi_error(msm_host); |
| 1363 | |
| 1364 | if (isr & DSI_IRQ_VIDEO_DONE) |
| 1365 | complete(&msm_host->video_comp); |
| 1366 | |
| 1367 | if (isr & DSI_IRQ_CMD_DMA_DONE) |
| 1368 | complete(&msm_host->dma_comp); |
| 1369 | |
| 1370 | return IRQ_HANDLED; |
| 1371 | } |
| 1372 | |
| 1373 | static int dsi_host_init_panel_gpios(struct msm_dsi_host *msm_host, |
| 1374 | struct device *panel_device) |
| 1375 | { |
Uwe Kleine-König | 9590e69 | 2015-05-20 09:21:41 +0200 | [diff] [blame] | 1376 | msm_host->disp_en_gpio = devm_gpiod_get_optional(panel_device, |
| 1377 | "disp-enable", |
| 1378 | GPIOD_OUT_LOW); |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 1379 | if (IS_ERR(msm_host->disp_en_gpio)) { |
| 1380 | DBG("cannot get disp-enable-gpios %ld", |
| 1381 | PTR_ERR(msm_host->disp_en_gpio)); |
Uwe Kleine-König | 9590e69 | 2015-05-20 09:21:41 +0200 | [diff] [blame] | 1382 | return PTR_ERR(msm_host->disp_en_gpio); |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 1383 | } |
| 1384 | |
Uwe Kleine-König | 9590e69 | 2015-05-20 09:21:41 +0200 | [diff] [blame] | 1385 | msm_host->te_gpio = devm_gpiod_get(panel_device, "disp-te", GPIOD_IN); |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 1386 | if (IS_ERR(msm_host->te_gpio)) { |
| 1387 | DBG("cannot get disp-te-gpios %ld", PTR_ERR(msm_host->te_gpio)); |
Uwe Kleine-König | 9590e69 | 2015-05-20 09:21:41 +0200 | [diff] [blame] | 1388 | return PTR_ERR(msm_host->te_gpio); |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | return 0; |
| 1392 | } |
| 1393 | |
| 1394 | static int dsi_host_attach(struct mipi_dsi_host *host, |
| 1395 | struct mipi_dsi_device *dsi) |
| 1396 | { |
| 1397 | struct msm_dsi_host *msm_host = to_msm_dsi_host(host); |
| 1398 | int ret; |
| 1399 | |
| 1400 | msm_host->channel = dsi->channel; |
| 1401 | msm_host->lanes = dsi->lanes; |
| 1402 | msm_host->format = dsi->format; |
| 1403 | msm_host->mode_flags = dsi->mode_flags; |
| 1404 | |
| 1405 | msm_host->panel_node = dsi->dev.of_node; |
| 1406 | |
| 1407 | /* Some gpios defined in panel DT need to be controlled by host */ |
| 1408 | ret = dsi_host_init_panel_gpios(msm_host, &dsi->dev); |
| 1409 | if (ret) |
| 1410 | return ret; |
| 1411 | |
| 1412 | DBG("id=%d", msm_host->id); |
| 1413 | if (msm_host->dev) |
| 1414 | drm_helper_hpd_irq_event(msm_host->dev); |
| 1415 | |
| 1416 | return 0; |
| 1417 | } |
| 1418 | |
| 1419 | static int dsi_host_detach(struct mipi_dsi_host *host, |
| 1420 | struct mipi_dsi_device *dsi) |
| 1421 | { |
| 1422 | struct msm_dsi_host *msm_host = to_msm_dsi_host(host); |
| 1423 | |
| 1424 | msm_host->panel_node = NULL; |
| 1425 | |
| 1426 | DBG("id=%d", msm_host->id); |
| 1427 | if (msm_host->dev) |
| 1428 | drm_helper_hpd_irq_event(msm_host->dev); |
| 1429 | |
| 1430 | return 0; |
| 1431 | } |
| 1432 | |
| 1433 | static ssize_t dsi_host_transfer(struct mipi_dsi_host *host, |
| 1434 | const struct mipi_dsi_msg *msg) |
| 1435 | { |
| 1436 | struct msm_dsi_host *msm_host = to_msm_dsi_host(host); |
| 1437 | int ret; |
| 1438 | |
| 1439 | if (!msg || !msm_host->power_on) |
| 1440 | return -EINVAL; |
| 1441 | |
| 1442 | mutex_lock(&msm_host->cmd_mutex); |
| 1443 | ret = msm_dsi_manager_cmd_xfer(msm_host->id, msg); |
| 1444 | mutex_unlock(&msm_host->cmd_mutex); |
| 1445 | |
| 1446 | return ret; |
| 1447 | } |
| 1448 | |
| 1449 | static struct mipi_dsi_host_ops dsi_host_ops = { |
| 1450 | .attach = dsi_host_attach, |
| 1451 | .detach = dsi_host_detach, |
| 1452 | .transfer = dsi_host_transfer, |
| 1453 | }; |
| 1454 | |
| 1455 | int msm_dsi_host_init(struct msm_dsi *msm_dsi) |
| 1456 | { |
| 1457 | struct msm_dsi_host *msm_host = NULL; |
| 1458 | struct platform_device *pdev = msm_dsi->pdev; |
| 1459 | int ret; |
| 1460 | |
| 1461 | msm_host = devm_kzalloc(&pdev->dev, sizeof(*msm_host), GFP_KERNEL); |
| 1462 | if (!msm_host) { |
| 1463 | pr_err("%s: FAILED: cannot alloc dsi host\n", |
| 1464 | __func__); |
| 1465 | ret = -ENOMEM; |
| 1466 | goto fail; |
| 1467 | } |
| 1468 | |
| 1469 | ret = of_property_read_u32(pdev->dev.of_node, |
| 1470 | "qcom,dsi-host-index", &msm_host->id); |
| 1471 | if (ret) { |
| 1472 | dev_err(&pdev->dev, |
| 1473 | "%s: host index not specified, ret=%d\n", |
| 1474 | __func__, ret); |
| 1475 | goto fail; |
| 1476 | } |
| 1477 | msm_host->pdev = pdev; |
| 1478 | |
| 1479 | ret = dsi_clk_init(msm_host); |
| 1480 | if (ret) { |
| 1481 | pr_err("%s: unable to initialize dsi clks\n", __func__); |
| 1482 | goto fail; |
| 1483 | } |
| 1484 | |
| 1485 | msm_host->ctrl_base = msm_ioremap(pdev, "dsi_ctrl", "DSI CTRL"); |
| 1486 | if (IS_ERR(msm_host->ctrl_base)) { |
| 1487 | pr_err("%s: unable to map Dsi ctrl base\n", __func__); |
| 1488 | ret = PTR_ERR(msm_host->ctrl_base); |
| 1489 | goto fail; |
| 1490 | } |
| 1491 | |
| 1492 | msm_host->cfg = dsi_get_config(msm_host); |
| 1493 | if (!msm_host->cfg) { |
| 1494 | ret = -EINVAL; |
| 1495 | pr_err("%s: get config failed\n", __func__); |
| 1496 | goto fail; |
| 1497 | } |
| 1498 | |
| 1499 | ret = dsi_regulator_init(msm_host); |
| 1500 | if (ret) { |
| 1501 | pr_err("%s: regulator init failed\n", __func__); |
| 1502 | goto fail; |
| 1503 | } |
| 1504 | |
| 1505 | msm_host->rx_buf = devm_kzalloc(&pdev->dev, SZ_4K, GFP_KERNEL); |
| 1506 | if (!msm_host->rx_buf) { |
| 1507 | pr_err("%s: alloc rx temp buf failed\n", __func__); |
| 1508 | goto fail; |
| 1509 | } |
| 1510 | |
| 1511 | init_completion(&msm_host->dma_comp); |
| 1512 | init_completion(&msm_host->video_comp); |
| 1513 | mutex_init(&msm_host->dev_mutex); |
| 1514 | mutex_init(&msm_host->cmd_mutex); |
| 1515 | mutex_init(&msm_host->clk_mutex); |
| 1516 | spin_lock_init(&msm_host->intr_lock); |
| 1517 | |
| 1518 | /* setup workqueue */ |
| 1519 | msm_host->workqueue = alloc_ordered_workqueue("dsi_drm_work", 0); |
| 1520 | INIT_WORK(&msm_host->err_work, dsi_err_worker); |
| 1521 | |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 1522 | msm_dsi->host = &msm_host->base; |
| 1523 | msm_dsi->id = msm_host->id; |
| 1524 | |
| 1525 | DBG("Dsi Host %d initialized", msm_host->id); |
| 1526 | return 0; |
| 1527 | |
| 1528 | fail: |
| 1529 | return ret; |
| 1530 | } |
| 1531 | |
| 1532 | void msm_dsi_host_destroy(struct mipi_dsi_host *host) |
| 1533 | { |
| 1534 | struct msm_dsi_host *msm_host = to_msm_dsi_host(host); |
| 1535 | |
| 1536 | DBG(""); |
| 1537 | dsi_tx_buf_free(msm_host); |
| 1538 | if (msm_host->workqueue) { |
| 1539 | flush_workqueue(msm_host->workqueue); |
| 1540 | destroy_workqueue(msm_host->workqueue); |
| 1541 | msm_host->workqueue = NULL; |
| 1542 | } |
| 1543 | |
| 1544 | mutex_destroy(&msm_host->clk_mutex); |
| 1545 | mutex_destroy(&msm_host->cmd_mutex); |
| 1546 | mutex_destroy(&msm_host->dev_mutex); |
| 1547 | } |
| 1548 | |
| 1549 | int msm_dsi_host_modeset_init(struct mipi_dsi_host *host, |
| 1550 | struct drm_device *dev) |
| 1551 | { |
| 1552 | struct msm_dsi_host *msm_host = to_msm_dsi_host(host); |
| 1553 | struct platform_device *pdev = msm_host->pdev; |
| 1554 | int ret; |
| 1555 | |
| 1556 | msm_host->irq = irq_of_parse_and_map(pdev->dev.of_node, 0); |
| 1557 | if (msm_host->irq < 0) { |
| 1558 | ret = msm_host->irq; |
| 1559 | dev_err(dev->dev, "failed to get irq: %d\n", ret); |
| 1560 | return ret; |
| 1561 | } |
| 1562 | |
| 1563 | ret = devm_request_irq(&pdev->dev, msm_host->irq, |
| 1564 | dsi_host_irq, IRQF_TRIGGER_HIGH | IRQF_ONESHOT, |
| 1565 | "dsi_isr", msm_host); |
| 1566 | if (ret < 0) { |
| 1567 | dev_err(&pdev->dev, "failed to request IRQ%u: %d\n", |
| 1568 | msm_host->irq, ret); |
| 1569 | return ret; |
| 1570 | } |
| 1571 | |
| 1572 | msm_host->dev = dev; |
| 1573 | ret = dsi_tx_buf_alloc(msm_host, SZ_4K); |
| 1574 | if (ret) { |
| 1575 | pr_err("%s: alloc tx gem obj failed, %d\n", __func__, ret); |
| 1576 | return ret; |
| 1577 | } |
| 1578 | |
| 1579 | return 0; |
| 1580 | } |
| 1581 | |
| 1582 | int msm_dsi_host_register(struct mipi_dsi_host *host, bool check_defer) |
| 1583 | { |
| 1584 | struct msm_dsi_host *msm_host = to_msm_dsi_host(host); |
| 1585 | struct device_node *node; |
| 1586 | int ret; |
| 1587 | |
| 1588 | /* Register mipi dsi host */ |
| 1589 | if (!msm_host->registered) { |
| 1590 | host->dev = &msm_host->pdev->dev; |
| 1591 | host->ops = &dsi_host_ops; |
| 1592 | ret = mipi_dsi_host_register(host); |
| 1593 | if (ret) |
| 1594 | return ret; |
| 1595 | |
| 1596 | msm_host->registered = true; |
| 1597 | |
| 1598 | /* If the panel driver has not been probed after host register, |
| 1599 | * we should defer the host's probe. |
| 1600 | * It makes sure panel is connected when fbcon detects |
| 1601 | * connector status and gets the proper display mode to |
| 1602 | * create framebuffer. |
| 1603 | */ |
| 1604 | if (check_defer) { |
| 1605 | node = of_get_child_by_name(msm_host->pdev->dev.of_node, |
| 1606 | "panel"); |
| 1607 | if (node) { |
| 1608 | if (!of_drm_find_panel(node)) |
| 1609 | return -EPROBE_DEFER; |
| 1610 | } |
| 1611 | } |
| 1612 | } |
| 1613 | |
| 1614 | return 0; |
| 1615 | } |
| 1616 | |
| 1617 | void msm_dsi_host_unregister(struct mipi_dsi_host *host) |
| 1618 | { |
| 1619 | struct msm_dsi_host *msm_host = to_msm_dsi_host(host); |
| 1620 | |
| 1621 | if (msm_host->registered) { |
| 1622 | mipi_dsi_host_unregister(host); |
| 1623 | host->dev = NULL; |
| 1624 | host->ops = NULL; |
| 1625 | msm_host->registered = false; |
| 1626 | } |
| 1627 | } |
| 1628 | |
| 1629 | int msm_dsi_host_xfer_prepare(struct mipi_dsi_host *host, |
| 1630 | const struct mipi_dsi_msg *msg) |
| 1631 | { |
| 1632 | struct msm_dsi_host *msm_host = to_msm_dsi_host(host); |
| 1633 | |
| 1634 | /* TODO: make sure dsi_cmd_mdp is idle. |
| 1635 | * Since DSI6G v1.2.0, we can set DSI_TRIG_CTRL.BLOCK_DMA_WITHIN_FRAME |
| 1636 | * to ask H/W to wait until cmd mdp is idle. S/W wait is not needed. |
| 1637 | * How to handle the old versions? Wait for mdp cmd done? |
| 1638 | */ |
| 1639 | |
| 1640 | /* |
| 1641 | * mdss interrupt is generated in mdp core clock domain |
| 1642 | * mdp clock need to be enabled to receive dsi interrupt |
| 1643 | */ |
| 1644 | dsi_clk_ctrl(msm_host, 1); |
| 1645 | |
| 1646 | /* TODO: vote for bus bandwidth */ |
| 1647 | |
| 1648 | if (!(msg->flags & MIPI_DSI_MSG_USE_LPM)) |
| 1649 | dsi_set_tx_power_mode(0, msm_host); |
| 1650 | |
| 1651 | msm_host->dma_cmd_ctrl_restore = dsi_read(msm_host, REG_DSI_CTRL); |
| 1652 | dsi_write(msm_host, REG_DSI_CTRL, |
| 1653 | msm_host->dma_cmd_ctrl_restore | |
| 1654 | DSI_CTRL_CMD_MODE_EN | |
| 1655 | DSI_CTRL_ENABLE); |
| 1656 | dsi_intr_ctrl(msm_host, DSI_IRQ_MASK_CMD_DMA_DONE, 1); |
| 1657 | |
| 1658 | return 0; |
| 1659 | } |
| 1660 | |
| 1661 | void msm_dsi_host_xfer_restore(struct mipi_dsi_host *host, |
| 1662 | const struct mipi_dsi_msg *msg) |
| 1663 | { |
| 1664 | struct msm_dsi_host *msm_host = to_msm_dsi_host(host); |
| 1665 | |
| 1666 | dsi_intr_ctrl(msm_host, DSI_IRQ_MASK_CMD_DMA_DONE, 0); |
| 1667 | dsi_write(msm_host, REG_DSI_CTRL, msm_host->dma_cmd_ctrl_restore); |
| 1668 | |
| 1669 | if (!(msg->flags & MIPI_DSI_MSG_USE_LPM)) |
| 1670 | dsi_set_tx_power_mode(1, msm_host); |
| 1671 | |
| 1672 | /* TODO: unvote for bus bandwidth */ |
| 1673 | |
| 1674 | dsi_clk_ctrl(msm_host, 0); |
| 1675 | } |
| 1676 | |
| 1677 | int msm_dsi_host_cmd_tx(struct mipi_dsi_host *host, |
| 1678 | const struct mipi_dsi_msg *msg) |
| 1679 | { |
| 1680 | struct msm_dsi_host *msm_host = to_msm_dsi_host(host); |
| 1681 | |
| 1682 | return dsi_cmds2buf_tx(msm_host, msg); |
| 1683 | } |
| 1684 | |
| 1685 | int msm_dsi_host_cmd_rx(struct mipi_dsi_host *host, |
| 1686 | const struct mipi_dsi_msg *msg) |
| 1687 | { |
| 1688 | struct msm_dsi_host *msm_host = to_msm_dsi_host(host); |
| 1689 | int data_byte, rx_byte, dlen, end; |
| 1690 | int short_response, diff, pkt_size, ret = 0; |
| 1691 | char cmd; |
| 1692 | int rlen = msg->rx_len; |
| 1693 | u8 *buf; |
| 1694 | |
| 1695 | if (rlen <= 2) { |
| 1696 | short_response = 1; |
| 1697 | pkt_size = rlen; |
| 1698 | rx_byte = 4; |
| 1699 | } else { |
| 1700 | short_response = 0; |
| 1701 | data_byte = 10; /* first read */ |
| 1702 | if (rlen < data_byte) |
| 1703 | pkt_size = rlen; |
| 1704 | else |
| 1705 | pkt_size = data_byte; |
| 1706 | rx_byte = data_byte + 6; /* 4 header + 2 crc */ |
| 1707 | } |
| 1708 | |
| 1709 | buf = msm_host->rx_buf; |
| 1710 | end = 0; |
| 1711 | while (!end) { |
| 1712 | u8 tx[2] = {pkt_size & 0xff, pkt_size >> 8}; |
| 1713 | struct mipi_dsi_msg max_pkt_size_msg = { |
| 1714 | .channel = msg->channel, |
| 1715 | .type = MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE, |
| 1716 | .tx_len = 2, |
| 1717 | .tx_buf = tx, |
| 1718 | }; |
| 1719 | |
| 1720 | DBG("rlen=%d pkt_size=%d rx_byte=%d", |
| 1721 | rlen, pkt_size, rx_byte); |
| 1722 | |
| 1723 | ret = dsi_cmds2buf_tx(msm_host, &max_pkt_size_msg); |
| 1724 | if (ret < 2) { |
| 1725 | pr_err("%s: Set max pkt size failed, %d\n", |
| 1726 | __func__, ret); |
| 1727 | return -EINVAL; |
| 1728 | } |
| 1729 | |
| 1730 | if ((msm_host->cfg->major == MSM_DSI_VER_MAJOR_6G) && |
| 1731 | (msm_host->cfg->minor >= MSM_DSI_6G_VER_MINOR_V1_1)) { |
| 1732 | /* Clear the RDBK_DATA registers */ |
| 1733 | dsi_write(msm_host, REG_DSI_RDBK_DATA_CTRL, |
| 1734 | DSI_RDBK_DATA_CTRL_CLR); |
| 1735 | wmb(); /* make sure the RDBK registers are cleared */ |
| 1736 | dsi_write(msm_host, REG_DSI_RDBK_DATA_CTRL, 0); |
| 1737 | wmb(); /* release cleared status before transfer */ |
| 1738 | } |
| 1739 | |
| 1740 | ret = dsi_cmds2buf_tx(msm_host, msg); |
| 1741 | if (ret < msg->tx_len) { |
| 1742 | pr_err("%s: Read cmd Tx failed, %d\n", __func__, ret); |
| 1743 | return ret; |
| 1744 | } |
| 1745 | |
| 1746 | /* |
| 1747 | * once cmd_dma_done interrupt received, |
| 1748 | * return data from client is ready and stored |
| 1749 | * at RDBK_DATA register already |
| 1750 | * since rx fifo is 16 bytes, dcs header is kept at first loop, |
| 1751 | * after that dcs header lost during shift into registers |
| 1752 | */ |
| 1753 | dlen = dsi_cmd_dma_rx(msm_host, buf, rx_byte, pkt_size); |
| 1754 | |
| 1755 | if (dlen <= 0) |
| 1756 | return 0; |
| 1757 | |
| 1758 | if (short_response) |
| 1759 | break; |
| 1760 | |
| 1761 | if (rlen <= data_byte) { |
| 1762 | diff = data_byte - rlen; |
| 1763 | end = 1; |
| 1764 | } else { |
| 1765 | diff = 0; |
| 1766 | rlen -= data_byte; |
| 1767 | } |
| 1768 | |
| 1769 | if (!end) { |
| 1770 | dlen -= 2; /* 2 crc */ |
| 1771 | dlen -= diff; |
| 1772 | buf += dlen; /* next start position */ |
| 1773 | data_byte = 14; /* NOT first read */ |
| 1774 | if (rlen < data_byte) |
| 1775 | pkt_size += rlen; |
| 1776 | else |
| 1777 | pkt_size += data_byte; |
| 1778 | DBG("buf=%p dlen=%d diff=%d", buf, dlen, diff); |
| 1779 | } |
| 1780 | } |
| 1781 | |
| 1782 | /* |
| 1783 | * For single Long read, if the requested rlen < 10, |
| 1784 | * we need to shift the start position of rx |
| 1785 | * data buffer to skip the bytes which are not |
| 1786 | * updated. |
| 1787 | */ |
| 1788 | if (pkt_size < 10 && !short_response) |
| 1789 | buf = msm_host->rx_buf + (10 - rlen); |
| 1790 | else |
| 1791 | buf = msm_host->rx_buf; |
| 1792 | |
| 1793 | cmd = buf[0]; |
| 1794 | switch (cmd) { |
| 1795 | case MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT: |
| 1796 | pr_err("%s: rx ACK_ERR_PACLAGE\n", __func__); |
| 1797 | ret = 0; |
Hai Li | 651ad3f | 2015-04-29 11:38:59 -0400 | [diff] [blame] | 1798 | break; |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 1799 | case MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_1BYTE: |
| 1800 | case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE: |
| 1801 | ret = dsi_short_read1_resp(buf, msg); |
| 1802 | break; |
| 1803 | case MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_2BYTE: |
| 1804 | case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE: |
| 1805 | ret = dsi_short_read2_resp(buf, msg); |
| 1806 | break; |
| 1807 | case MIPI_DSI_RX_GENERIC_LONG_READ_RESPONSE: |
| 1808 | case MIPI_DSI_RX_DCS_LONG_READ_RESPONSE: |
| 1809 | ret = dsi_long_read_resp(buf, msg); |
| 1810 | break; |
| 1811 | default: |
| 1812 | pr_warn("%s:Invalid response cmd\n", __func__); |
| 1813 | ret = 0; |
| 1814 | } |
| 1815 | |
| 1816 | return ret; |
| 1817 | } |
| 1818 | |
| 1819 | void msm_dsi_host_cmd_xfer_commit(struct mipi_dsi_host *host, u32 iova, u32 len) |
| 1820 | { |
| 1821 | struct msm_dsi_host *msm_host = to_msm_dsi_host(host); |
| 1822 | |
| 1823 | dsi_write(msm_host, REG_DSI_DMA_BASE, iova); |
| 1824 | dsi_write(msm_host, REG_DSI_DMA_LEN, len); |
| 1825 | dsi_write(msm_host, REG_DSI_TRIG_DMA, 1); |
| 1826 | |
| 1827 | /* Make sure trigger happens */ |
| 1828 | wmb(); |
| 1829 | } |
| 1830 | |
Hai Li | 9d32c498 | 2015-05-15 13:04:05 -0400 | [diff] [blame] | 1831 | int msm_dsi_host_set_src_pll(struct mipi_dsi_host *host, |
| 1832 | struct msm_dsi_pll *src_pll) |
| 1833 | { |
| 1834 | struct msm_dsi_host *msm_host = to_msm_dsi_host(host); |
| 1835 | struct clk *byte_clk_provider, *pixel_clk_provider; |
| 1836 | int ret; |
| 1837 | |
| 1838 | ret = msm_dsi_pll_get_clk_provider(src_pll, |
| 1839 | &byte_clk_provider, &pixel_clk_provider); |
| 1840 | if (ret) { |
| 1841 | pr_info("%s: can't get provider from pll, don't set parent\n", |
| 1842 | __func__); |
| 1843 | return 0; |
| 1844 | } |
| 1845 | |
| 1846 | ret = clk_set_parent(msm_host->byte_clk_src, byte_clk_provider); |
| 1847 | if (ret) { |
| 1848 | pr_err("%s: can't set parent to byte_clk_src. ret=%d\n", |
| 1849 | __func__, ret); |
| 1850 | goto exit; |
| 1851 | } |
| 1852 | |
| 1853 | ret = clk_set_parent(msm_host->pixel_clk_src, pixel_clk_provider); |
| 1854 | if (ret) { |
| 1855 | pr_err("%s: can't set parent to pixel_clk_src. ret=%d\n", |
| 1856 | __func__, ret); |
| 1857 | goto exit; |
| 1858 | } |
| 1859 | |
| 1860 | exit: |
| 1861 | return ret; |
| 1862 | } |
| 1863 | |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 1864 | int msm_dsi_host_enable(struct mipi_dsi_host *host) |
| 1865 | { |
| 1866 | struct msm_dsi_host *msm_host = to_msm_dsi_host(host); |
| 1867 | |
| 1868 | dsi_op_mode_config(msm_host, |
| 1869 | !!(msm_host->mode_flags & MIPI_DSI_MODE_VIDEO), true); |
| 1870 | |
| 1871 | /* TODO: clock should be turned off for command mode, |
| 1872 | * and only turned on before MDP START. |
| 1873 | * This part of code should be enabled once mdp driver support it. |
| 1874 | */ |
| 1875 | /* if (msm_panel->mode == MSM_DSI_CMD_MODE) |
| 1876 | dsi_clk_ctrl(msm_host, 0); */ |
| 1877 | |
| 1878 | return 0; |
| 1879 | } |
| 1880 | |
| 1881 | int msm_dsi_host_disable(struct mipi_dsi_host *host) |
| 1882 | { |
| 1883 | struct msm_dsi_host *msm_host = to_msm_dsi_host(host); |
| 1884 | |
| 1885 | dsi_op_mode_config(msm_host, |
| 1886 | !!(msm_host->mode_flags & MIPI_DSI_MODE_VIDEO), false); |
| 1887 | |
| 1888 | /* Since we have disabled INTF, the video engine won't stop so that |
| 1889 | * the cmd engine will be blocked. |
| 1890 | * Reset to disable video engine so that we can send off cmd. |
| 1891 | */ |
| 1892 | dsi_sw_reset(msm_host); |
| 1893 | |
| 1894 | return 0; |
| 1895 | } |
| 1896 | |
| 1897 | int msm_dsi_host_power_on(struct mipi_dsi_host *host) |
| 1898 | { |
| 1899 | struct msm_dsi_host *msm_host = to_msm_dsi_host(host); |
| 1900 | u32 clk_pre = 0, clk_post = 0; |
| 1901 | int ret = 0; |
| 1902 | |
| 1903 | mutex_lock(&msm_host->dev_mutex); |
| 1904 | if (msm_host->power_on) { |
| 1905 | DBG("dsi host already on"); |
| 1906 | goto unlock_ret; |
| 1907 | } |
| 1908 | |
| 1909 | ret = dsi_calc_clk_rate(msm_host); |
| 1910 | if (ret) { |
| 1911 | pr_err("%s: unable to calc clk rate, %d\n", __func__, ret); |
| 1912 | goto unlock_ret; |
| 1913 | } |
| 1914 | |
| 1915 | ret = dsi_host_regulator_enable(msm_host); |
| 1916 | if (ret) { |
| 1917 | pr_err("%s:Failed to enable vregs.ret=%d\n", |
| 1918 | __func__, ret); |
| 1919 | goto unlock_ret; |
| 1920 | } |
| 1921 | |
| 1922 | ret = dsi_bus_clk_enable(msm_host); |
| 1923 | if (ret) { |
| 1924 | pr_err("%s: failed to enable bus clocks, %d\n", __func__, ret); |
| 1925 | goto fail_disable_reg; |
| 1926 | } |
| 1927 | |
| 1928 | dsi_phy_sw_reset(msm_host); |
| 1929 | ret = msm_dsi_manager_phy_enable(msm_host->id, |
| 1930 | msm_host->byte_clk_rate * 8, |
| 1931 | clk_get_rate(msm_host->esc_clk), |
| 1932 | &clk_pre, &clk_post); |
| 1933 | dsi_bus_clk_disable(msm_host); |
| 1934 | if (ret) { |
| 1935 | pr_err("%s: failed to enable phy, %d\n", __func__, ret); |
| 1936 | goto fail_disable_reg; |
| 1937 | } |
| 1938 | |
| 1939 | ret = dsi_clk_ctrl(msm_host, 1); |
| 1940 | if (ret) { |
| 1941 | pr_err("%s: failed to enable clocks. ret=%d\n", __func__, ret); |
| 1942 | goto fail_disable_reg; |
| 1943 | } |
| 1944 | |
Hai Li | ab8909b | 2015-06-11 10:56:46 -0400 | [diff] [blame] | 1945 | ret = pinctrl_pm_select_default_state(&msm_host->pdev->dev); |
| 1946 | if (ret) { |
| 1947 | pr_err("%s: failed to set pinctrl default state, %d\n", |
| 1948 | __func__, ret); |
| 1949 | goto fail_disable_clk; |
| 1950 | } |
| 1951 | |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 1952 | dsi_timing_setup(msm_host); |
| 1953 | dsi_sw_reset(msm_host); |
| 1954 | dsi_ctrl_config(msm_host, true, clk_pre, clk_post); |
| 1955 | |
| 1956 | if (msm_host->disp_en_gpio) |
| 1957 | gpiod_set_value(msm_host->disp_en_gpio, 1); |
| 1958 | |
| 1959 | msm_host->power_on = true; |
| 1960 | mutex_unlock(&msm_host->dev_mutex); |
| 1961 | |
| 1962 | return 0; |
| 1963 | |
Hai Li | ab8909b | 2015-06-11 10:56:46 -0400 | [diff] [blame] | 1964 | fail_disable_clk: |
| 1965 | dsi_clk_ctrl(msm_host, 0); |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 1966 | fail_disable_reg: |
| 1967 | dsi_host_regulator_disable(msm_host); |
| 1968 | unlock_ret: |
| 1969 | mutex_unlock(&msm_host->dev_mutex); |
| 1970 | return ret; |
| 1971 | } |
| 1972 | |
| 1973 | int msm_dsi_host_power_off(struct mipi_dsi_host *host) |
| 1974 | { |
| 1975 | struct msm_dsi_host *msm_host = to_msm_dsi_host(host); |
| 1976 | |
| 1977 | mutex_lock(&msm_host->dev_mutex); |
| 1978 | if (!msm_host->power_on) { |
| 1979 | DBG("dsi host already off"); |
| 1980 | goto unlock_ret; |
| 1981 | } |
| 1982 | |
| 1983 | dsi_ctrl_config(msm_host, false, 0, 0); |
| 1984 | |
| 1985 | if (msm_host->disp_en_gpio) |
| 1986 | gpiod_set_value(msm_host->disp_en_gpio, 0); |
| 1987 | |
Hai Li | ab8909b | 2015-06-11 10:56:46 -0400 | [diff] [blame] | 1988 | pinctrl_pm_select_sleep_state(&msm_host->pdev->dev); |
| 1989 | |
Hai Li | a689554 | 2015-03-31 14:36:33 -0400 | [diff] [blame] | 1990 | msm_dsi_manager_phy_disable(msm_host->id); |
| 1991 | |
| 1992 | dsi_clk_ctrl(msm_host, 0); |
| 1993 | |
| 1994 | dsi_host_regulator_disable(msm_host); |
| 1995 | |
| 1996 | DBG("-"); |
| 1997 | |
| 1998 | msm_host->power_on = false; |
| 1999 | |
| 2000 | unlock_ret: |
| 2001 | mutex_unlock(&msm_host->dev_mutex); |
| 2002 | return 0; |
| 2003 | } |
| 2004 | |
| 2005 | int msm_dsi_host_set_display_mode(struct mipi_dsi_host *host, |
| 2006 | struct drm_display_mode *mode) |
| 2007 | { |
| 2008 | struct msm_dsi_host *msm_host = to_msm_dsi_host(host); |
| 2009 | |
| 2010 | if (msm_host->mode) { |
| 2011 | drm_mode_destroy(msm_host->dev, msm_host->mode); |
| 2012 | msm_host->mode = NULL; |
| 2013 | } |
| 2014 | |
| 2015 | msm_host->mode = drm_mode_duplicate(msm_host->dev, mode); |
| 2016 | if (IS_ERR(msm_host->mode)) { |
| 2017 | pr_err("%s: cannot duplicate mode\n", __func__); |
| 2018 | return PTR_ERR(msm_host->mode); |
| 2019 | } |
| 2020 | |
| 2021 | return 0; |
| 2022 | } |
| 2023 | |
| 2024 | struct drm_panel *msm_dsi_host_get_panel(struct mipi_dsi_host *host, |
| 2025 | unsigned long *panel_flags) |
| 2026 | { |
| 2027 | struct msm_dsi_host *msm_host = to_msm_dsi_host(host); |
| 2028 | struct drm_panel *panel; |
| 2029 | |
| 2030 | panel = of_drm_find_panel(msm_host->panel_node); |
| 2031 | if (panel_flags) |
| 2032 | *panel_flags = msm_host->mode_flags; |
| 2033 | |
| 2034 | return panel; |
| 2035 | } |
| 2036 | |