Tomi Valkeinen | 2e1def0 | 2013-05-31 13:13:44 +0300 | [diff] [blame] | 1 | /* |
| 2 | * TPO TD043MTEA1 Panel driver |
| 3 | * |
| 4 | * Author: Gražvydas Ignotas <notasas@gmail.com> |
| 5 | * Converted to new DSS device model: Tomi Valkeinen <tomi.valkeinen@ti.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/delay.h> |
| 15 | #include <linux/spi/spi.h> |
| 16 | #include <linux/regulator/consumer.h> |
Arnd Bergmann | d0196c8 | 2016-05-11 18:05:39 +0200 | [diff] [blame] | 17 | #include <linux/gpio/consumer.h> |
Tomi Valkeinen | 2e1def0 | 2013-05-31 13:13:44 +0300 | [diff] [blame] | 18 | #include <linux/err.h> |
| 19 | #include <linux/slab.h> |
Tomi Valkeinen | 597cc1e | 2014-05-16 12:28:36 +0300 | [diff] [blame] | 20 | #include <linux/of_gpio.h> |
Tomi Valkeinen | 2e1def0 | 2013-05-31 13:13:44 +0300 | [diff] [blame] | 21 | |
Peter Ujfalusi | 32043da | 2016-05-27 14:40:49 +0300 | [diff] [blame] | 22 | #include "../dss/omapdss.h" |
Tomi Valkeinen | 2e1def0 | 2013-05-31 13:13:44 +0300 | [diff] [blame] | 23 | |
| 24 | #define TPO_R02_MODE(x) ((x) & 7) |
| 25 | #define TPO_R02_MODE_800x480 7 |
| 26 | #define TPO_R02_NCLK_RISING BIT(3) |
| 27 | #define TPO_R02_HSYNC_HIGH BIT(4) |
| 28 | #define TPO_R02_VSYNC_HIGH BIT(5) |
| 29 | |
| 30 | #define TPO_R03_NSTANDBY BIT(0) |
| 31 | #define TPO_R03_EN_CP_CLK BIT(1) |
| 32 | #define TPO_R03_EN_VGL_PUMP BIT(2) |
| 33 | #define TPO_R03_EN_PWM BIT(3) |
| 34 | #define TPO_R03_DRIVING_CAP_100 BIT(4) |
| 35 | #define TPO_R03_EN_PRE_CHARGE BIT(6) |
| 36 | #define TPO_R03_SOFTWARE_CTL BIT(7) |
| 37 | |
| 38 | #define TPO_R04_NFLIP_H BIT(0) |
| 39 | #define TPO_R04_NFLIP_V BIT(1) |
| 40 | #define TPO_R04_CP_CLK_FREQ_1H BIT(2) |
| 41 | #define TPO_R04_VGL_FREQ_1H BIT(4) |
| 42 | |
| 43 | #define TPO_R03_VAL_NORMAL (TPO_R03_NSTANDBY | TPO_R03_EN_CP_CLK | \ |
| 44 | TPO_R03_EN_VGL_PUMP | TPO_R03_EN_PWM | \ |
| 45 | TPO_R03_DRIVING_CAP_100 | TPO_R03_EN_PRE_CHARGE | \ |
| 46 | TPO_R03_SOFTWARE_CTL) |
| 47 | |
| 48 | #define TPO_R03_VAL_STANDBY (TPO_R03_DRIVING_CAP_100 | \ |
| 49 | TPO_R03_EN_PRE_CHARGE | TPO_R03_SOFTWARE_CTL) |
| 50 | |
| 51 | static const u16 tpo_td043_def_gamma[12] = { |
| 52 | 105, 315, 381, 431, 490, 537, 579, 686, 780, 837, 880, 1023 |
| 53 | }; |
| 54 | |
| 55 | struct panel_drv_data { |
| 56 | struct omap_dss_device dssdev; |
| 57 | struct omap_dss_device *in; |
| 58 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 59 | struct videomode vm; |
Tomi Valkeinen | 2e1def0 | 2013-05-31 13:13:44 +0300 | [diff] [blame] | 60 | |
Tomi Valkeinen | 2e1def0 | 2013-05-31 13:13:44 +0300 | [diff] [blame] | 61 | struct spi_device *spi; |
| 62 | struct regulator *vcc_reg; |
| 63 | int nreset_gpio; |
| 64 | u16 gamma[12]; |
| 65 | u32 mode; |
| 66 | u32 hmirror:1; |
| 67 | u32 vmirror:1; |
| 68 | u32 powered_on:1; |
| 69 | u32 spi_suspended:1; |
| 70 | u32 power_on_resume:1; |
| 71 | }; |
| 72 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 73 | static const struct videomode tpo_td043_vm = { |
Peter Ujfalusi | 8189906 | 2016-09-22 14:06:46 +0300 | [diff] [blame] | 74 | .hactive = 800, |
Peter Ujfalusi | fb7f3c4 | 2016-09-22 14:06:47 +0300 | [diff] [blame] | 75 | .vactive = 480, |
Tomi Valkeinen | 2e1def0 | 2013-05-31 13:13:44 +0300 | [diff] [blame] | 76 | |
Tomi Valkeinen | d8d78941 | 2013-04-10 14:12:14 +0300 | [diff] [blame] | 77 | .pixelclock = 36000000, |
Tomi Valkeinen | 2e1def0 | 2013-05-31 13:13:44 +0300 | [diff] [blame] | 78 | |
Peter Ujfalusi | 4dc2250 | 2016-09-22 14:06:48 +0300 | [diff] [blame] | 79 | .hsync_len = 1, |
Peter Ujfalusi | 0a30e15 | 2016-09-22 14:06:49 +0300 | [diff] [blame] | 80 | .hfront_porch = 68, |
Peter Ujfalusi | a85f4a8 | 2016-09-22 14:06:50 +0300 | [diff] [blame] | 81 | .hback_porch = 214, |
Tomi Valkeinen | 2e1def0 | 2013-05-31 13:13:44 +0300 | [diff] [blame] | 82 | |
Peter Ujfalusi | d5bcf0a | 2016-09-22 14:06:51 +0300 | [diff] [blame] | 83 | .vsync_len = 1, |
Peter Ujfalusi | 0996c68 | 2016-09-22 14:06:52 +0300 | [diff] [blame] | 84 | .vfront_porch = 39, |
Peter Ujfalusi | 458540c | 2016-09-22 14:06:53 +0300 | [diff] [blame] | 85 | .vback_porch = 34, |
Tomi Valkeinen | 2e1def0 | 2013-05-31 13:13:44 +0300 | [diff] [blame] | 86 | |
Peter Ujfalusi | 3fa3ab4 | 2016-09-22 14:06:58 +0300 | [diff] [blame] | 87 | .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW | |
Peter Ujfalusi | d34afb7 | 2016-09-22 14:07:01 +0300 | [diff] [blame] | 88 | DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_SYNC_POSEDGE | |
| 89 | DISPLAY_FLAGS_PIXDATA_NEGEDGE, |
Peter Ujfalusi | 26a8d21 | 2016-09-22 14:07:05 +0300 | [diff] [blame] | 90 | /* |
| 91 | * Note: According to the panel documentation: |
| 92 | * SYNC needs to be driven on the FALLING edge |
| 93 | */ |
Tomi Valkeinen | 2e1def0 | 2013-05-31 13:13:44 +0300 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | #define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev) |
| 97 | |
| 98 | static int tpo_td043_write(struct spi_device *spi, u8 addr, u8 data) |
| 99 | { |
| 100 | struct spi_message m; |
| 101 | struct spi_transfer xfer; |
| 102 | u16 w; |
| 103 | int r; |
| 104 | |
| 105 | spi_message_init(&m); |
| 106 | |
| 107 | memset(&xfer, 0, sizeof(xfer)); |
| 108 | |
| 109 | w = ((u16)addr << 10) | (1 << 8) | data; |
| 110 | xfer.tx_buf = &w; |
| 111 | xfer.bits_per_word = 16; |
| 112 | xfer.len = 2; |
| 113 | spi_message_add_tail(&xfer, &m); |
| 114 | |
| 115 | r = spi_sync(spi, &m); |
| 116 | if (r < 0) |
| 117 | dev_warn(&spi->dev, "failed to write to LCD reg (%d)\n", r); |
| 118 | return r; |
| 119 | } |
| 120 | |
| 121 | static void tpo_td043_write_gamma(struct spi_device *spi, u16 gamma[12]) |
| 122 | { |
| 123 | u8 i, val; |
| 124 | |
| 125 | /* gamma bits [9:8] */ |
| 126 | for (val = i = 0; i < 4; i++) |
| 127 | val |= (gamma[i] & 0x300) >> ((i + 1) * 2); |
| 128 | tpo_td043_write(spi, 0x11, val); |
| 129 | |
| 130 | for (val = i = 0; i < 4; i++) |
| 131 | val |= (gamma[i+4] & 0x300) >> ((i + 1) * 2); |
| 132 | tpo_td043_write(spi, 0x12, val); |
| 133 | |
| 134 | for (val = i = 0; i < 4; i++) |
| 135 | val |= (gamma[i+8] & 0x300) >> ((i + 1) * 2); |
| 136 | tpo_td043_write(spi, 0x13, val); |
| 137 | |
| 138 | /* gamma bits [7:0] */ |
| 139 | for (val = i = 0; i < 12; i++) |
| 140 | tpo_td043_write(spi, 0x14 + i, gamma[i] & 0xff); |
| 141 | } |
| 142 | |
| 143 | static int tpo_td043_write_mirror(struct spi_device *spi, bool h, bool v) |
| 144 | { |
| 145 | u8 reg4 = TPO_R04_NFLIP_H | TPO_R04_NFLIP_V | |
| 146 | TPO_R04_CP_CLK_FREQ_1H | TPO_R04_VGL_FREQ_1H; |
| 147 | if (h) |
| 148 | reg4 &= ~TPO_R04_NFLIP_H; |
| 149 | if (v) |
| 150 | reg4 &= ~TPO_R04_NFLIP_V; |
| 151 | |
| 152 | return tpo_td043_write(spi, 4, reg4); |
| 153 | } |
| 154 | |
| 155 | static int tpo_td043_set_hmirror(struct omap_dss_device *dssdev, bool enable) |
| 156 | { |
| 157 | struct panel_drv_data *ddata = dev_get_drvdata(dssdev->dev); |
| 158 | |
| 159 | ddata->hmirror = enable; |
| 160 | return tpo_td043_write_mirror(ddata->spi, ddata->hmirror, |
| 161 | ddata->vmirror); |
| 162 | } |
| 163 | |
| 164 | static bool tpo_td043_get_hmirror(struct omap_dss_device *dssdev) |
| 165 | { |
| 166 | struct panel_drv_data *ddata = dev_get_drvdata(dssdev->dev); |
| 167 | |
| 168 | return ddata->hmirror; |
| 169 | } |
| 170 | |
| 171 | static ssize_t tpo_td043_vmirror_show(struct device *dev, |
| 172 | struct device_attribute *attr, char *buf) |
| 173 | { |
| 174 | struct panel_drv_data *ddata = dev_get_drvdata(dev); |
| 175 | |
| 176 | return snprintf(buf, PAGE_SIZE, "%d\n", ddata->vmirror); |
| 177 | } |
| 178 | |
| 179 | static ssize_t tpo_td043_vmirror_store(struct device *dev, |
| 180 | struct device_attribute *attr, const char *buf, size_t count) |
| 181 | { |
| 182 | struct panel_drv_data *ddata = dev_get_drvdata(dev); |
| 183 | int val; |
| 184 | int ret; |
| 185 | |
| 186 | ret = kstrtoint(buf, 0, &val); |
| 187 | if (ret < 0) |
| 188 | return ret; |
| 189 | |
| 190 | val = !!val; |
| 191 | |
| 192 | ret = tpo_td043_write_mirror(ddata->spi, ddata->hmirror, val); |
| 193 | if (ret < 0) |
| 194 | return ret; |
| 195 | |
| 196 | ddata->vmirror = val; |
| 197 | |
| 198 | return count; |
| 199 | } |
| 200 | |
| 201 | static ssize_t tpo_td043_mode_show(struct device *dev, |
| 202 | struct device_attribute *attr, char *buf) |
| 203 | { |
| 204 | struct panel_drv_data *ddata = dev_get_drvdata(dev); |
| 205 | |
| 206 | return snprintf(buf, PAGE_SIZE, "%d\n", ddata->mode); |
| 207 | } |
| 208 | |
| 209 | static ssize_t tpo_td043_mode_store(struct device *dev, |
| 210 | struct device_attribute *attr, const char *buf, size_t count) |
| 211 | { |
| 212 | struct panel_drv_data *ddata = dev_get_drvdata(dev); |
| 213 | long val; |
| 214 | int ret; |
| 215 | |
| 216 | ret = kstrtol(buf, 0, &val); |
| 217 | if (ret != 0 || val & ~7) |
| 218 | return -EINVAL; |
| 219 | |
| 220 | ddata->mode = val; |
| 221 | |
| 222 | val |= TPO_R02_NCLK_RISING; |
| 223 | tpo_td043_write(ddata->spi, 2, val); |
| 224 | |
| 225 | return count; |
| 226 | } |
| 227 | |
| 228 | static ssize_t tpo_td043_gamma_show(struct device *dev, |
| 229 | struct device_attribute *attr, char *buf) |
| 230 | { |
| 231 | struct panel_drv_data *ddata = dev_get_drvdata(dev); |
| 232 | ssize_t len = 0; |
| 233 | int ret; |
| 234 | int i; |
| 235 | |
| 236 | for (i = 0; i < ARRAY_SIZE(ddata->gamma); i++) { |
| 237 | ret = snprintf(buf + len, PAGE_SIZE - len, "%u ", |
| 238 | ddata->gamma[i]); |
| 239 | if (ret < 0) |
| 240 | return ret; |
| 241 | len += ret; |
| 242 | } |
| 243 | buf[len - 1] = '\n'; |
| 244 | |
| 245 | return len; |
| 246 | } |
| 247 | |
| 248 | static ssize_t tpo_td043_gamma_store(struct device *dev, |
| 249 | struct device_attribute *attr, const char *buf, size_t count) |
| 250 | { |
| 251 | struct panel_drv_data *ddata = dev_get_drvdata(dev); |
| 252 | unsigned int g[12]; |
| 253 | int ret; |
| 254 | int i; |
| 255 | |
| 256 | ret = sscanf(buf, "%u %u %u %u %u %u %u %u %u %u %u %u", |
| 257 | &g[0], &g[1], &g[2], &g[3], &g[4], &g[5], |
| 258 | &g[6], &g[7], &g[8], &g[9], &g[10], &g[11]); |
| 259 | |
| 260 | if (ret != 12) |
| 261 | return -EINVAL; |
| 262 | |
| 263 | for (i = 0; i < 12; i++) |
| 264 | ddata->gamma[i] = g[i]; |
| 265 | |
| 266 | tpo_td043_write_gamma(ddata->spi, ddata->gamma); |
| 267 | |
| 268 | return count; |
| 269 | } |
| 270 | |
| 271 | static DEVICE_ATTR(vmirror, S_IRUGO | S_IWUSR, |
| 272 | tpo_td043_vmirror_show, tpo_td043_vmirror_store); |
| 273 | static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, |
| 274 | tpo_td043_mode_show, tpo_td043_mode_store); |
| 275 | static DEVICE_ATTR(gamma, S_IRUGO | S_IWUSR, |
| 276 | tpo_td043_gamma_show, tpo_td043_gamma_store); |
| 277 | |
| 278 | static struct attribute *tpo_td043_attrs[] = { |
| 279 | &dev_attr_vmirror.attr, |
| 280 | &dev_attr_mode.attr, |
| 281 | &dev_attr_gamma.attr, |
| 282 | NULL, |
| 283 | }; |
| 284 | |
| 285 | static struct attribute_group tpo_td043_attr_group = { |
| 286 | .attrs = tpo_td043_attrs, |
| 287 | }; |
| 288 | |
| 289 | static int tpo_td043_power_on(struct panel_drv_data *ddata) |
| 290 | { |
| 291 | int r; |
| 292 | |
| 293 | if (ddata->powered_on) |
| 294 | return 0; |
| 295 | |
| 296 | r = regulator_enable(ddata->vcc_reg); |
| 297 | if (r != 0) |
| 298 | return r; |
| 299 | |
| 300 | /* wait for panel to stabilize */ |
| 301 | msleep(160); |
| 302 | |
| 303 | if (gpio_is_valid(ddata->nreset_gpio)) |
| 304 | gpio_set_value(ddata->nreset_gpio, 1); |
| 305 | |
| 306 | tpo_td043_write(ddata->spi, 2, |
| 307 | TPO_R02_MODE(ddata->mode) | TPO_R02_NCLK_RISING); |
| 308 | tpo_td043_write(ddata->spi, 3, TPO_R03_VAL_NORMAL); |
| 309 | tpo_td043_write(ddata->spi, 0x20, 0xf0); |
| 310 | tpo_td043_write(ddata->spi, 0x21, 0xf0); |
| 311 | tpo_td043_write_mirror(ddata->spi, ddata->hmirror, |
| 312 | ddata->vmirror); |
| 313 | tpo_td043_write_gamma(ddata->spi, ddata->gamma); |
| 314 | |
| 315 | ddata->powered_on = 1; |
| 316 | return 0; |
| 317 | } |
| 318 | |
| 319 | static void tpo_td043_power_off(struct panel_drv_data *ddata) |
| 320 | { |
| 321 | if (!ddata->powered_on) |
| 322 | return; |
| 323 | |
| 324 | tpo_td043_write(ddata->spi, 3, |
| 325 | TPO_R03_VAL_STANDBY | TPO_R03_EN_PWM); |
| 326 | |
| 327 | if (gpio_is_valid(ddata->nreset_gpio)) |
| 328 | gpio_set_value(ddata->nreset_gpio, 0); |
| 329 | |
| 330 | /* wait for at least 2 vsyncs before cutting off power */ |
| 331 | msleep(50); |
| 332 | |
| 333 | tpo_td043_write(ddata->spi, 3, TPO_R03_VAL_STANDBY); |
| 334 | |
| 335 | regulator_disable(ddata->vcc_reg); |
| 336 | |
| 337 | ddata->powered_on = 0; |
| 338 | } |
| 339 | |
| 340 | static int tpo_td043_connect(struct omap_dss_device *dssdev) |
| 341 | { |
| 342 | struct panel_drv_data *ddata = to_panel_data(dssdev); |
| 343 | struct omap_dss_device *in = ddata->in; |
| 344 | int r; |
| 345 | |
| 346 | if (omapdss_device_is_connected(dssdev)) |
| 347 | return 0; |
| 348 | |
| 349 | r = in->ops.dpi->connect(in, dssdev); |
| 350 | if (r) |
| 351 | return r; |
| 352 | |
| 353 | return 0; |
| 354 | } |
| 355 | |
| 356 | static void tpo_td043_disconnect(struct omap_dss_device *dssdev) |
| 357 | { |
| 358 | struct panel_drv_data *ddata = to_panel_data(dssdev); |
| 359 | struct omap_dss_device *in = ddata->in; |
| 360 | |
| 361 | if (!omapdss_device_is_connected(dssdev)) |
| 362 | return; |
| 363 | |
| 364 | in->ops.dpi->disconnect(in, dssdev); |
| 365 | } |
| 366 | |
| 367 | static int tpo_td043_enable(struct omap_dss_device *dssdev) |
| 368 | { |
| 369 | struct panel_drv_data *ddata = to_panel_data(dssdev); |
| 370 | struct omap_dss_device *in = ddata->in; |
| 371 | int r; |
| 372 | |
| 373 | if (!omapdss_device_is_connected(dssdev)) |
| 374 | return -ENODEV; |
| 375 | |
| 376 | if (omapdss_device_is_enabled(dssdev)) |
| 377 | return 0; |
| 378 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 379 | in->ops.dpi->set_timings(in, &ddata->vm); |
Tomi Valkeinen | 2e1def0 | 2013-05-31 13:13:44 +0300 | [diff] [blame] | 380 | |
| 381 | r = in->ops.dpi->enable(in); |
| 382 | if (r) |
| 383 | return r; |
| 384 | |
| 385 | /* |
| 386 | * If we are resuming from system suspend, SPI clocks might not be |
| 387 | * enabled yet, so we'll program the LCD from SPI PM resume callback. |
| 388 | */ |
| 389 | if (!ddata->spi_suspended) { |
| 390 | r = tpo_td043_power_on(ddata); |
| 391 | if (r) { |
| 392 | in->ops.dpi->disable(in); |
| 393 | return r; |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | dssdev->state = OMAP_DSS_DISPLAY_ACTIVE; |
| 398 | |
| 399 | return 0; |
| 400 | } |
| 401 | |
| 402 | static void tpo_td043_disable(struct omap_dss_device *dssdev) |
| 403 | { |
| 404 | struct panel_drv_data *ddata = to_panel_data(dssdev); |
| 405 | struct omap_dss_device *in = ddata->in; |
| 406 | |
| 407 | if (!omapdss_device_is_enabled(dssdev)) |
| 408 | return; |
| 409 | |
| 410 | in->ops.dpi->disable(in); |
| 411 | |
| 412 | if (!ddata->spi_suspended) |
| 413 | tpo_td043_power_off(ddata); |
| 414 | |
| 415 | dssdev->state = OMAP_DSS_DISPLAY_DISABLED; |
| 416 | } |
| 417 | |
| 418 | static void tpo_td043_set_timings(struct omap_dss_device *dssdev, |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 419 | struct videomode *vm) |
Tomi Valkeinen | 2e1def0 | 2013-05-31 13:13:44 +0300 | [diff] [blame] | 420 | { |
| 421 | struct panel_drv_data *ddata = to_panel_data(dssdev); |
| 422 | struct omap_dss_device *in = ddata->in; |
| 423 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 424 | ddata->vm = *vm; |
| 425 | dssdev->panel.vm = *vm; |
Tomi Valkeinen | 2e1def0 | 2013-05-31 13:13:44 +0300 | [diff] [blame] | 426 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 427 | in->ops.dpi->set_timings(in, vm); |
Tomi Valkeinen | 2e1def0 | 2013-05-31 13:13:44 +0300 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | static void tpo_td043_get_timings(struct omap_dss_device *dssdev, |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 431 | struct videomode *vm) |
Tomi Valkeinen | 2e1def0 | 2013-05-31 13:13:44 +0300 | [diff] [blame] | 432 | { |
| 433 | struct panel_drv_data *ddata = to_panel_data(dssdev); |
| 434 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 435 | *vm = ddata->vm; |
Tomi Valkeinen | 2e1def0 | 2013-05-31 13:13:44 +0300 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | static int tpo_td043_check_timings(struct omap_dss_device *dssdev, |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 439 | struct videomode *vm) |
Tomi Valkeinen | 2e1def0 | 2013-05-31 13:13:44 +0300 | [diff] [blame] | 440 | { |
| 441 | struct panel_drv_data *ddata = to_panel_data(dssdev); |
| 442 | struct omap_dss_device *in = ddata->in; |
| 443 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 444 | return in->ops.dpi->check_timings(in, vm); |
Tomi Valkeinen | 2e1def0 | 2013-05-31 13:13:44 +0300 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | static struct omap_dss_driver tpo_td043_ops = { |
| 448 | .connect = tpo_td043_connect, |
| 449 | .disconnect = tpo_td043_disconnect, |
| 450 | |
| 451 | .enable = tpo_td043_enable, |
| 452 | .disable = tpo_td043_disable, |
| 453 | |
| 454 | .set_timings = tpo_td043_set_timings, |
| 455 | .get_timings = tpo_td043_get_timings, |
| 456 | .check_timings = tpo_td043_check_timings, |
| 457 | |
| 458 | .set_mirror = tpo_td043_set_hmirror, |
| 459 | .get_mirror = tpo_td043_get_hmirror, |
Tomi Valkeinen | 2e1def0 | 2013-05-31 13:13:44 +0300 | [diff] [blame] | 460 | }; |
| 461 | |
Tomi Valkeinen | 597cc1e | 2014-05-16 12:28:36 +0300 | [diff] [blame] | 462 | static int tpo_td043_probe_of(struct spi_device *spi) |
| 463 | { |
| 464 | struct device_node *node = spi->dev.of_node; |
| 465 | struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev); |
| 466 | struct omap_dss_device *in; |
| 467 | int gpio; |
| 468 | |
| 469 | gpio = of_get_named_gpio(node, "reset-gpios", 0); |
| 470 | if (!gpio_is_valid(gpio)) { |
| 471 | dev_err(&spi->dev, "failed to parse enable gpio\n"); |
| 472 | return gpio; |
| 473 | } |
| 474 | ddata->nreset_gpio = gpio; |
| 475 | |
| 476 | in = omapdss_of_find_source_for_first_ep(node); |
| 477 | if (IS_ERR(in)) { |
| 478 | dev_err(&spi->dev, "failed to find video source\n"); |
| 479 | return PTR_ERR(in); |
| 480 | } |
| 481 | |
| 482 | ddata->in = in; |
| 483 | |
| 484 | return 0; |
| 485 | } |
| 486 | |
Tomi Valkeinen | 2e1def0 | 2013-05-31 13:13:44 +0300 | [diff] [blame] | 487 | static int tpo_td043_probe(struct spi_device *spi) |
| 488 | { |
| 489 | struct panel_drv_data *ddata; |
| 490 | struct omap_dss_device *dssdev; |
| 491 | int r; |
| 492 | |
| 493 | dev_dbg(&spi->dev, "%s\n", __func__); |
| 494 | |
| 495 | spi->bits_per_word = 16; |
| 496 | spi->mode = SPI_MODE_0; |
| 497 | |
| 498 | r = spi_setup(spi); |
| 499 | if (r < 0) { |
| 500 | dev_err(&spi->dev, "spi_setup failed: %d\n", r); |
| 501 | return r; |
| 502 | } |
| 503 | |
| 504 | ddata = devm_kzalloc(&spi->dev, sizeof(*ddata), GFP_KERNEL); |
| 505 | if (ddata == NULL) |
| 506 | return -ENOMEM; |
| 507 | |
| 508 | dev_set_drvdata(&spi->dev, ddata); |
| 509 | |
| 510 | ddata->spi = spi; |
| 511 | |
Tomi Valkeinen | 33c06b6 | 2016-02-22 18:14:52 +0200 | [diff] [blame] | 512 | if (!spi->dev.of_node) |
Tomi Valkeinen | 2e1def0 | 2013-05-31 13:13:44 +0300 | [diff] [blame] | 513 | return -ENODEV; |
Tomi Valkeinen | 33c06b6 | 2016-02-22 18:14:52 +0200 | [diff] [blame] | 514 | |
| 515 | r = tpo_td043_probe_of(spi); |
| 516 | if (r) |
| 517 | return r; |
Tomi Valkeinen | 2e1def0 | 2013-05-31 13:13:44 +0300 | [diff] [blame] | 518 | |
| 519 | ddata->mode = TPO_R02_MODE_800x480; |
| 520 | memcpy(ddata->gamma, tpo_td043_def_gamma, sizeof(ddata->gamma)); |
| 521 | |
| 522 | ddata->vcc_reg = devm_regulator_get(&spi->dev, "vcc"); |
| 523 | if (IS_ERR(ddata->vcc_reg)) { |
| 524 | dev_err(&spi->dev, "failed to get LCD VCC regulator\n"); |
| 525 | r = PTR_ERR(ddata->vcc_reg); |
| 526 | goto err_regulator; |
| 527 | } |
| 528 | |
| 529 | if (gpio_is_valid(ddata->nreset_gpio)) { |
| 530 | r = devm_gpio_request_one(&spi->dev, |
| 531 | ddata->nreset_gpio, GPIOF_OUT_INIT_LOW, |
| 532 | "lcd reset"); |
| 533 | if (r < 0) { |
| 534 | dev_err(&spi->dev, "couldn't request reset GPIO\n"); |
| 535 | goto err_gpio_req; |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | r = sysfs_create_group(&spi->dev.kobj, &tpo_td043_attr_group); |
| 540 | if (r) { |
| 541 | dev_err(&spi->dev, "failed to create sysfs files\n"); |
| 542 | goto err_sysfs; |
| 543 | } |
| 544 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 545 | ddata->vm = tpo_td043_vm; |
Tomi Valkeinen | 2e1def0 | 2013-05-31 13:13:44 +0300 | [diff] [blame] | 546 | |
| 547 | dssdev = &ddata->dssdev; |
| 548 | dssdev->dev = &spi->dev; |
| 549 | dssdev->driver = &tpo_td043_ops; |
| 550 | dssdev->type = OMAP_DISPLAY_TYPE_DPI; |
| 551 | dssdev->owner = THIS_MODULE; |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 552 | dssdev->panel.vm = ddata->vm; |
Tomi Valkeinen | 2e1def0 | 2013-05-31 13:13:44 +0300 | [diff] [blame] | 553 | |
| 554 | r = omapdss_register_display(dssdev); |
| 555 | if (r) { |
| 556 | dev_err(&spi->dev, "Failed to register panel\n"); |
| 557 | goto err_reg; |
| 558 | } |
| 559 | |
| 560 | return 0; |
| 561 | |
| 562 | err_reg: |
| 563 | sysfs_remove_group(&spi->dev.kobj, &tpo_td043_attr_group); |
| 564 | err_sysfs: |
| 565 | err_gpio_req: |
| 566 | err_regulator: |
| 567 | omap_dss_put_device(ddata->in); |
| 568 | return r; |
| 569 | } |
| 570 | |
| 571 | static int tpo_td043_remove(struct spi_device *spi) |
| 572 | { |
| 573 | struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev); |
| 574 | struct omap_dss_device *dssdev = &ddata->dssdev; |
| 575 | struct omap_dss_device *in = ddata->in; |
| 576 | |
| 577 | dev_dbg(&ddata->spi->dev, "%s\n", __func__); |
| 578 | |
| 579 | omapdss_unregister_display(dssdev); |
| 580 | |
| 581 | tpo_td043_disable(dssdev); |
| 582 | tpo_td043_disconnect(dssdev); |
| 583 | |
| 584 | omap_dss_put_device(in); |
| 585 | |
| 586 | sysfs_remove_group(&spi->dev.kobj, &tpo_td043_attr_group); |
| 587 | |
| 588 | return 0; |
| 589 | } |
| 590 | |
| 591 | #ifdef CONFIG_PM_SLEEP |
| 592 | static int tpo_td043_spi_suspend(struct device *dev) |
| 593 | { |
| 594 | struct panel_drv_data *ddata = dev_get_drvdata(dev); |
| 595 | |
| 596 | dev_dbg(dev, "tpo_td043_spi_suspend, tpo %p\n", ddata); |
| 597 | |
| 598 | ddata->power_on_resume = ddata->powered_on; |
| 599 | tpo_td043_power_off(ddata); |
| 600 | ddata->spi_suspended = 1; |
| 601 | |
| 602 | return 0; |
| 603 | } |
| 604 | |
| 605 | static int tpo_td043_spi_resume(struct device *dev) |
| 606 | { |
| 607 | struct panel_drv_data *ddata = dev_get_drvdata(dev); |
| 608 | int ret; |
| 609 | |
| 610 | dev_dbg(dev, "tpo_td043_spi_resume\n"); |
| 611 | |
| 612 | if (ddata->power_on_resume) { |
| 613 | ret = tpo_td043_power_on(ddata); |
| 614 | if (ret) |
| 615 | return ret; |
| 616 | } |
| 617 | ddata->spi_suspended = 0; |
| 618 | |
| 619 | return 0; |
| 620 | } |
| 621 | #endif |
| 622 | |
| 623 | static SIMPLE_DEV_PM_OPS(tpo_td043_spi_pm, |
| 624 | tpo_td043_spi_suspend, tpo_td043_spi_resume); |
| 625 | |
Tomi Valkeinen | 597cc1e | 2014-05-16 12:28:36 +0300 | [diff] [blame] | 626 | static const struct of_device_id tpo_td043_of_match[] = { |
| 627 | { .compatible = "omapdss,tpo,td043mtea1", }, |
| 628 | {}, |
| 629 | }; |
| 630 | |
| 631 | MODULE_DEVICE_TABLE(of, tpo_td043_of_match); |
| 632 | |
Tomi Valkeinen | 2e1def0 | 2013-05-31 13:13:44 +0300 | [diff] [blame] | 633 | static struct spi_driver tpo_td043_spi_driver = { |
| 634 | .driver = { |
| 635 | .name = "panel-tpo-td043mtea1", |
Tomi Valkeinen | 2e1def0 | 2013-05-31 13:13:44 +0300 | [diff] [blame] | 636 | .pm = &tpo_td043_spi_pm, |
Tomi Valkeinen | 597cc1e | 2014-05-16 12:28:36 +0300 | [diff] [blame] | 637 | .of_match_table = tpo_td043_of_match, |
Tomi Valkeinen | 422ccbd | 2014-10-16 09:54:25 +0300 | [diff] [blame] | 638 | .suppress_bind_attrs = true, |
Tomi Valkeinen | 2e1def0 | 2013-05-31 13:13:44 +0300 | [diff] [blame] | 639 | }, |
| 640 | .probe = tpo_td043_probe, |
| 641 | .remove = tpo_td043_remove, |
| 642 | }; |
| 643 | |
| 644 | module_spi_driver(tpo_td043_spi_driver); |
| 645 | |
Tomi Valkeinen | 597cc1e | 2014-05-16 12:28:36 +0300 | [diff] [blame] | 646 | MODULE_ALIAS("spi:tpo,td043mtea1"); |
Tomi Valkeinen | 2e1def0 | 2013-05-31 13:13:44 +0300 | [diff] [blame] | 647 | MODULE_AUTHOR("Gražvydas Ignotas <notasas@gmail.com>"); |
| 648 | MODULE_DESCRIPTION("TPO TD043MTEA1 LCD Driver"); |
| 649 | MODULE_LICENSE("GPL"); |