Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 1 | /* |
| 2 | * LCD panel driver for TPO TD043MTEA1 |
| 3 | * |
| 4 | * Author: Gražvydas Ignotas <notasas@gmail.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/delay.h> |
| 14 | #include <linux/spi/spi.h> |
| 15 | #include <linux/regulator/consumer.h> |
| 16 | #include <linux/gpio.h> |
| 17 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 19 | |
Tomi Valkeinen | a0b38cc | 2011-05-11 14:05:07 +0300 | [diff] [blame] | 20 | #include <video/omapdss.h> |
Archit Taneja | 7eab07e4 | 2012-11-21 15:39:31 +0530 | [diff] [blame] | 21 | #include <video/omap-panel-data.h> |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 22 | |
| 23 | #define TPO_R02_MODE(x) ((x) & 7) |
| 24 | #define TPO_R02_MODE_800x480 7 |
| 25 | #define TPO_R02_NCLK_RISING BIT(3) |
| 26 | #define TPO_R02_HSYNC_HIGH BIT(4) |
| 27 | #define TPO_R02_VSYNC_HIGH BIT(5) |
| 28 | |
| 29 | #define TPO_R03_NSTANDBY BIT(0) |
| 30 | #define TPO_R03_EN_CP_CLK BIT(1) |
| 31 | #define TPO_R03_EN_VGL_PUMP BIT(2) |
| 32 | #define TPO_R03_EN_PWM BIT(3) |
| 33 | #define TPO_R03_DRIVING_CAP_100 BIT(4) |
| 34 | #define TPO_R03_EN_PRE_CHARGE BIT(6) |
| 35 | #define TPO_R03_SOFTWARE_CTL BIT(7) |
| 36 | |
| 37 | #define TPO_R04_NFLIP_H BIT(0) |
| 38 | #define TPO_R04_NFLIP_V BIT(1) |
| 39 | #define TPO_R04_CP_CLK_FREQ_1H BIT(2) |
| 40 | #define TPO_R04_VGL_FREQ_1H BIT(4) |
| 41 | |
| 42 | #define TPO_R03_VAL_NORMAL (TPO_R03_NSTANDBY | TPO_R03_EN_CP_CLK | \ |
| 43 | TPO_R03_EN_VGL_PUMP | TPO_R03_EN_PWM | \ |
| 44 | TPO_R03_DRIVING_CAP_100 | TPO_R03_EN_PRE_CHARGE | \ |
| 45 | TPO_R03_SOFTWARE_CTL) |
| 46 | |
| 47 | #define TPO_R03_VAL_STANDBY (TPO_R03_DRIVING_CAP_100 | \ |
| 48 | TPO_R03_EN_PRE_CHARGE | TPO_R03_SOFTWARE_CTL) |
| 49 | |
| 50 | static const u16 tpo_td043_def_gamma[12] = { |
Grazvydas Ignotas | 4306b72 | 2012-02-07 02:13:50 +0200 | [diff] [blame] | 51 | 105, 315, 381, 431, 490, 537, 579, 686, 780, 837, 880, 1023 |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | struct tpo_td043_device { |
| 55 | struct spi_device *spi; |
| 56 | struct regulator *vcc_reg; |
Grazvydas Ignotas | 8df4f5c | 2012-02-07 02:13:49 +0200 | [diff] [blame] | 57 | int nreset_gpio; |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 58 | u16 gamma[12]; |
| 59 | u32 mode; |
| 60 | u32 hmirror:1; |
| 61 | u32 vmirror:1; |
Grazvydas Ignotas | 8df4f5c | 2012-02-07 02:13:49 +0200 | [diff] [blame] | 62 | u32 powered_on:1; |
| 63 | u32 spi_suspended:1; |
| 64 | u32 power_on_resume:1; |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 65 | }; |
| 66 | |
Grazvydas Ignotas | a2f9b2a | 2013-02-17 02:43:12 +0200 | [diff] [blame] | 67 | /* used to pass spi_device from SPI to DSS portion of the driver */ |
| 68 | static struct tpo_td043_device *g_tpo_td043; |
| 69 | |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 70 | static int tpo_td043_write(struct spi_device *spi, u8 addr, u8 data) |
| 71 | { |
| 72 | struct spi_message m; |
| 73 | struct spi_transfer xfer; |
| 74 | u16 w; |
| 75 | int r; |
| 76 | |
| 77 | spi_message_init(&m); |
| 78 | |
| 79 | memset(&xfer, 0, sizeof(xfer)); |
| 80 | |
| 81 | w = ((u16)addr << 10) | (1 << 8) | data; |
| 82 | xfer.tx_buf = &w; |
| 83 | xfer.bits_per_word = 16; |
| 84 | xfer.len = 2; |
| 85 | spi_message_add_tail(&xfer, &m); |
| 86 | |
| 87 | r = spi_sync(spi, &m); |
| 88 | if (r < 0) |
| 89 | dev_warn(&spi->dev, "failed to write to LCD reg (%d)\n", r); |
| 90 | return r; |
| 91 | } |
| 92 | |
| 93 | static void tpo_td043_write_gamma(struct spi_device *spi, u16 gamma[12]) |
| 94 | { |
| 95 | u8 i, val; |
| 96 | |
| 97 | /* gamma bits [9:8] */ |
| 98 | for (val = i = 0; i < 4; i++) |
| 99 | val |= (gamma[i] & 0x300) >> ((i + 1) * 2); |
| 100 | tpo_td043_write(spi, 0x11, val); |
| 101 | |
| 102 | for (val = i = 0; i < 4; i++) |
| 103 | val |= (gamma[i+4] & 0x300) >> ((i + 1) * 2); |
| 104 | tpo_td043_write(spi, 0x12, val); |
| 105 | |
| 106 | for (val = i = 0; i < 4; i++) |
| 107 | val |= (gamma[i+8] & 0x300) >> ((i + 1) * 2); |
| 108 | tpo_td043_write(spi, 0x13, val); |
| 109 | |
| 110 | /* gamma bits [7:0] */ |
| 111 | for (val = i = 0; i < 12; i++) |
| 112 | tpo_td043_write(spi, 0x14 + i, gamma[i] & 0xff); |
| 113 | } |
| 114 | |
| 115 | static int tpo_td043_write_mirror(struct spi_device *spi, bool h, bool v) |
| 116 | { |
| 117 | u8 reg4 = TPO_R04_NFLIP_H | TPO_R04_NFLIP_V | \ |
| 118 | TPO_R04_CP_CLK_FREQ_1H | TPO_R04_VGL_FREQ_1H; |
| 119 | if (h) |
| 120 | reg4 &= ~TPO_R04_NFLIP_H; |
| 121 | if (v) |
| 122 | reg4 &= ~TPO_R04_NFLIP_V; |
| 123 | |
| 124 | return tpo_td043_write(spi, 4, reg4); |
| 125 | } |
| 126 | |
| 127 | static int tpo_td043_set_hmirror(struct omap_dss_device *dssdev, bool enable) |
| 128 | { |
Tomi Valkeinen | ecc8b37 | 2013-02-14 14:17:28 +0200 | [diff] [blame^] | 129 | struct tpo_td043_device *tpo_td043 = dev_get_drvdata(dssdev->dev); |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 130 | |
| 131 | tpo_td043->hmirror = enable; |
| 132 | return tpo_td043_write_mirror(tpo_td043->spi, tpo_td043->hmirror, |
| 133 | tpo_td043->vmirror); |
| 134 | } |
| 135 | |
| 136 | static bool tpo_td043_get_hmirror(struct omap_dss_device *dssdev) |
| 137 | { |
Tomi Valkeinen | ecc8b37 | 2013-02-14 14:17:28 +0200 | [diff] [blame^] | 138 | struct tpo_td043_device *tpo_td043 = dev_get_drvdata(dssdev->dev); |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 139 | |
| 140 | return tpo_td043->hmirror; |
| 141 | } |
| 142 | |
| 143 | static ssize_t tpo_td043_vmirror_show(struct device *dev, |
| 144 | struct device_attribute *attr, char *buf) |
| 145 | { |
| 146 | struct tpo_td043_device *tpo_td043 = dev_get_drvdata(dev); |
| 147 | |
| 148 | return snprintf(buf, PAGE_SIZE, "%d\n", tpo_td043->vmirror); |
| 149 | } |
| 150 | |
| 151 | static ssize_t tpo_td043_vmirror_store(struct device *dev, |
| 152 | struct device_attribute *attr, const char *buf, size_t count) |
| 153 | { |
| 154 | struct tpo_td043_device *tpo_td043 = dev_get_drvdata(dev); |
Tomi Valkeinen | e3502ce | 2011-04-04 15:40:23 +0300 | [diff] [blame] | 155 | int val; |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 156 | int ret; |
| 157 | |
Tomi Valkeinen | e3502ce | 2011-04-04 15:40:23 +0300 | [diff] [blame] | 158 | ret = kstrtoint(buf, 0, &val); |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 159 | if (ret < 0) |
| 160 | return ret; |
| 161 | |
Tomi Valkeinen | e3502ce | 2011-04-04 15:40:23 +0300 | [diff] [blame] | 162 | val = !!val; |
| 163 | |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 164 | ret = tpo_td043_write_mirror(tpo_td043->spi, tpo_td043->hmirror, val); |
| 165 | if (ret < 0) |
| 166 | return ret; |
| 167 | |
| 168 | tpo_td043->vmirror = val; |
| 169 | |
| 170 | return count; |
| 171 | } |
| 172 | |
| 173 | static ssize_t tpo_td043_mode_show(struct device *dev, |
| 174 | struct device_attribute *attr, char *buf) |
| 175 | { |
| 176 | struct tpo_td043_device *tpo_td043 = dev_get_drvdata(dev); |
| 177 | |
| 178 | return snprintf(buf, PAGE_SIZE, "%d\n", tpo_td043->mode); |
| 179 | } |
| 180 | |
| 181 | static ssize_t tpo_td043_mode_store(struct device *dev, |
| 182 | struct device_attribute *attr, const char *buf, size_t count) |
| 183 | { |
| 184 | struct tpo_td043_device *tpo_td043 = dev_get_drvdata(dev); |
| 185 | long val; |
| 186 | int ret; |
| 187 | |
Tomi Valkeinen | e3502ce | 2011-04-04 15:40:23 +0300 | [diff] [blame] | 188 | ret = kstrtol(buf, 0, &val); |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 189 | if (ret != 0 || val & ~7) |
| 190 | return -EINVAL; |
| 191 | |
| 192 | tpo_td043->mode = val; |
| 193 | |
| 194 | val |= TPO_R02_NCLK_RISING; |
| 195 | tpo_td043_write(tpo_td043->spi, 2, val); |
| 196 | |
| 197 | return count; |
| 198 | } |
| 199 | |
| 200 | static ssize_t tpo_td043_gamma_show(struct device *dev, |
| 201 | struct device_attribute *attr, char *buf) |
| 202 | { |
| 203 | struct tpo_td043_device *tpo_td043 = dev_get_drvdata(dev); |
| 204 | ssize_t len = 0; |
| 205 | int ret; |
| 206 | int i; |
| 207 | |
| 208 | for (i = 0; i < ARRAY_SIZE(tpo_td043->gamma); i++) { |
| 209 | ret = snprintf(buf + len, PAGE_SIZE - len, "%u ", |
| 210 | tpo_td043->gamma[i]); |
| 211 | if (ret < 0) |
| 212 | return ret; |
| 213 | len += ret; |
| 214 | } |
| 215 | buf[len - 1] = '\n'; |
| 216 | |
| 217 | return len; |
| 218 | } |
| 219 | |
| 220 | static ssize_t tpo_td043_gamma_store(struct device *dev, |
| 221 | struct device_attribute *attr, const char *buf, size_t count) |
| 222 | { |
| 223 | struct tpo_td043_device *tpo_td043 = dev_get_drvdata(dev); |
| 224 | unsigned int g[12]; |
| 225 | int ret; |
| 226 | int i; |
| 227 | |
| 228 | ret = sscanf(buf, "%u %u %u %u %u %u %u %u %u %u %u %u", |
| 229 | &g[0], &g[1], &g[2], &g[3], &g[4], &g[5], |
| 230 | &g[6], &g[7], &g[8], &g[9], &g[10], &g[11]); |
| 231 | |
| 232 | if (ret != 12) |
| 233 | return -EINVAL; |
| 234 | |
| 235 | for (i = 0; i < 12; i++) |
| 236 | tpo_td043->gamma[i] = g[i]; |
| 237 | |
| 238 | tpo_td043_write_gamma(tpo_td043->spi, tpo_td043->gamma); |
| 239 | |
| 240 | return count; |
| 241 | } |
| 242 | |
| 243 | static DEVICE_ATTR(vmirror, S_IRUGO | S_IWUSR, |
| 244 | tpo_td043_vmirror_show, tpo_td043_vmirror_store); |
| 245 | static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, |
| 246 | tpo_td043_mode_show, tpo_td043_mode_store); |
| 247 | static DEVICE_ATTR(gamma, S_IRUGO | S_IWUSR, |
| 248 | tpo_td043_gamma_show, tpo_td043_gamma_store); |
| 249 | |
| 250 | static struct attribute *tpo_td043_attrs[] = { |
| 251 | &dev_attr_vmirror.attr, |
| 252 | &dev_attr_mode.attr, |
| 253 | &dev_attr_gamma.attr, |
| 254 | NULL, |
| 255 | }; |
| 256 | |
| 257 | static struct attribute_group tpo_td043_attr_group = { |
| 258 | .attrs = tpo_td043_attrs, |
| 259 | }; |
| 260 | |
| 261 | static const struct omap_video_timings tpo_td043_timings = { |
| 262 | .x_res = 800, |
| 263 | .y_res = 480, |
| 264 | |
| 265 | .pixel_clock = 36000, |
| 266 | |
| 267 | .hsw = 1, |
| 268 | .hfp = 68, |
| 269 | .hbp = 214, |
| 270 | |
| 271 | .vsw = 1, |
| 272 | .vfp = 39, |
| 273 | .vbp = 34, |
Archit Taneja | a8d5e41 | 2012-06-25 12:26:38 +0530 | [diff] [blame] | 274 | |
| 275 | .vsync_level = OMAPDSS_SIG_ACTIVE_LOW, |
| 276 | .hsync_level = OMAPDSS_SIG_ACTIVE_LOW, |
| 277 | .data_pclk_edge = OMAPDSS_DRIVE_SIG_FALLING_EDGE, |
| 278 | .de_level = OMAPDSS_SIG_ACTIVE_HIGH, |
| 279 | .sync_pclk_edge = OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES, |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 280 | }; |
| 281 | |
Archit Taneja | 7eab07e4 | 2012-11-21 15:39:31 +0530 | [diff] [blame] | 282 | static inline struct panel_tpo_td043_data |
| 283 | *get_panel_data(const struct omap_dss_device *dssdev) |
| 284 | { |
| 285 | return (struct panel_tpo_td043_data *) dssdev->data; |
| 286 | } |
| 287 | |
Grazvydas Ignotas | 8df4f5c | 2012-02-07 02:13:49 +0200 | [diff] [blame] | 288 | static int tpo_td043_power_on(struct tpo_td043_device *tpo_td043) |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 289 | { |
Mark Brown | 956107e | 2012-03-19 15:02:31 +0000 | [diff] [blame] | 290 | int r; |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 291 | |
Grazvydas Ignotas | 8df4f5c | 2012-02-07 02:13:49 +0200 | [diff] [blame] | 292 | if (tpo_td043->powered_on) |
Stanley.Miao | 18016e3 | 2010-09-03 05:03:48 +0200 | [diff] [blame] | 293 | return 0; |
| 294 | |
Mark Brown | 956107e | 2012-03-19 15:02:31 +0000 | [diff] [blame] | 295 | r = regulator_enable(tpo_td043->vcc_reg); |
| 296 | if (r != 0) |
| 297 | return r; |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 298 | |
Mark Brown | 2c83af4 | 2012-03-19 15:02:32 +0000 | [diff] [blame] | 299 | /* wait for panel to stabilize */ |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 300 | msleep(160); |
| 301 | |
Archit Taneja | 7eab07e4 | 2012-11-21 15:39:31 +0530 | [diff] [blame] | 302 | if (gpio_is_valid(tpo_td043->nreset_gpio)) |
| 303 | gpio_set_value(tpo_td043->nreset_gpio, 1); |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 304 | |
| 305 | tpo_td043_write(tpo_td043->spi, 2, |
| 306 | TPO_R02_MODE(tpo_td043->mode) | TPO_R02_NCLK_RISING); |
| 307 | tpo_td043_write(tpo_td043->spi, 3, TPO_R03_VAL_NORMAL); |
| 308 | tpo_td043_write(tpo_td043->spi, 0x20, 0xf0); |
| 309 | tpo_td043_write(tpo_td043->spi, 0x21, 0xf0); |
| 310 | tpo_td043_write_mirror(tpo_td043->spi, tpo_td043->hmirror, |
| 311 | tpo_td043->vmirror); |
| 312 | tpo_td043_write_gamma(tpo_td043->spi, tpo_td043->gamma); |
| 313 | |
Grazvydas Ignotas | 8df4f5c | 2012-02-07 02:13:49 +0200 | [diff] [blame] | 314 | tpo_td043->powered_on = 1; |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 315 | return 0; |
| 316 | } |
| 317 | |
Grazvydas Ignotas | 8df4f5c | 2012-02-07 02:13:49 +0200 | [diff] [blame] | 318 | static void tpo_td043_power_off(struct tpo_td043_device *tpo_td043) |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 319 | { |
Grazvydas Ignotas | 8df4f5c | 2012-02-07 02:13:49 +0200 | [diff] [blame] | 320 | if (!tpo_td043->powered_on) |
Stanley.Miao | 18016e3 | 2010-09-03 05:03:48 +0200 | [diff] [blame] | 321 | return; |
| 322 | |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 323 | tpo_td043_write(tpo_td043->spi, 3, |
| 324 | TPO_R03_VAL_STANDBY | TPO_R03_EN_PWM); |
| 325 | |
Archit Taneja | 7eab07e4 | 2012-11-21 15:39:31 +0530 | [diff] [blame] | 326 | if (gpio_is_valid(tpo_td043->nreset_gpio)) |
| 327 | gpio_set_value(tpo_td043->nreset_gpio, 0); |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 328 | |
| 329 | /* wait for at least 2 vsyncs before cutting off power */ |
| 330 | msleep(50); |
| 331 | |
| 332 | tpo_td043_write(tpo_td043->spi, 3, TPO_R03_VAL_STANDBY); |
| 333 | |
| 334 | regulator_disable(tpo_td043->vcc_reg); |
| 335 | |
Grazvydas Ignotas | 8df4f5c | 2012-02-07 02:13:49 +0200 | [diff] [blame] | 336 | tpo_td043->powered_on = 0; |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 337 | } |
| 338 | |
Grazvydas Ignotas | 8df4f5c | 2012-02-07 02:13:49 +0200 | [diff] [blame] | 339 | static int tpo_td043_enable_dss(struct omap_dss_device *dssdev) |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 340 | { |
Tomi Valkeinen | ecc8b37 | 2013-02-14 14:17:28 +0200 | [diff] [blame^] | 341 | struct tpo_td043_device *tpo_td043 = dev_get_drvdata(dssdev->dev); |
Grazvydas Ignotas | 8df4f5c | 2012-02-07 02:13:49 +0200 | [diff] [blame] | 342 | int r; |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 343 | |
Grazvydas Ignotas | 8df4f5c | 2012-02-07 02:13:49 +0200 | [diff] [blame] | 344 | if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) |
| 345 | return 0; |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 346 | |
Archit Taneja | c499144 | 2012-08-08 14:28:54 +0530 | [diff] [blame] | 347 | omapdss_dpi_set_timings(dssdev, &dssdev->panel.timings); |
Archit Taneja | c6b393d | 2012-07-06 15:30:52 +0530 | [diff] [blame] | 348 | omapdss_dpi_set_data_lines(dssdev, dssdev->phy.dpi.data_lines); |
Archit Taneja | c499144 | 2012-08-08 14:28:54 +0530 | [diff] [blame] | 349 | |
Grazvydas Ignotas | 8df4f5c | 2012-02-07 02:13:49 +0200 | [diff] [blame] | 350 | r = omapdss_dpi_display_enable(dssdev); |
| 351 | if (r) |
| 352 | goto err0; |
| 353 | |
Grazvydas Ignotas | 8df4f5c | 2012-02-07 02:13:49 +0200 | [diff] [blame] | 354 | /* |
| 355 | * If we are resuming from system suspend, SPI clocks might not be |
| 356 | * enabled yet, so we'll program the LCD from SPI PM resume callback. |
| 357 | */ |
| 358 | if (!tpo_td043->spi_suspended) { |
| 359 | r = tpo_td043_power_on(tpo_td043); |
| 360 | if (r) |
| 361 | goto err1; |
| 362 | } |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 363 | |
| 364 | dssdev->state = OMAP_DSS_DISPLAY_ACTIVE; |
| 365 | |
| 366 | return 0; |
Grazvydas Ignotas | 8df4f5c | 2012-02-07 02:13:49 +0200 | [diff] [blame] | 367 | err1: |
| 368 | omapdss_dpi_display_disable(dssdev); |
| 369 | err0: |
| 370 | return r; |
| 371 | } |
| 372 | |
| 373 | static void tpo_td043_disable_dss(struct omap_dss_device *dssdev) |
| 374 | { |
Tomi Valkeinen | ecc8b37 | 2013-02-14 14:17:28 +0200 | [diff] [blame^] | 375 | struct tpo_td043_device *tpo_td043 = dev_get_drvdata(dssdev->dev); |
Grazvydas Ignotas | 8df4f5c | 2012-02-07 02:13:49 +0200 | [diff] [blame] | 376 | |
| 377 | if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) |
| 378 | return; |
| 379 | |
Grazvydas Ignotas | 8df4f5c | 2012-02-07 02:13:49 +0200 | [diff] [blame] | 380 | omapdss_dpi_display_disable(dssdev); |
| 381 | |
| 382 | if (!tpo_td043->spi_suspended) |
| 383 | tpo_td043_power_off(tpo_td043); |
| 384 | } |
| 385 | |
| 386 | static int tpo_td043_enable(struct omap_dss_device *dssdev) |
| 387 | { |
Tomi Valkeinen | ecc8b37 | 2013-02-14 14:17:28 +0200 | [diff] [blame^] | 388 | dev_dbg(dssdev->dev, "enable\n"); |
Grazvydas Ignotas | 8df4f5c | 2012-02-07 02:13:49 +0200 | [diff] [blame] | 389 | |
| 390 | return tpo_td043_enable_dss(dssdev); |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | static void tpo_td043_disable(struct omap_dss_device *dssdev) |
| 394 | { |
Tomi Valkeinen | ecc8b37 | 2013-02-14 14:17:28 +0200 | [diff] [blame^] | 395 | dev_dbg(dssdev->dev, "disable\n"); |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 396 | |
Grazvydas Ignotas | 8df4f5c | 2012-02-07 02:13:49 +0200 | [diff] [blame] | 397 | tpo_td043_disable_dss(dssdev); |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 398 | |
| 399 | dssdev->state = OMAP_DSS_DISPLAY_DISABLED; |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 400 | } |
| 401 | |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 402 | static int tpo_td043_probe(struct omap_dss_device *dssdev) |
| 403 | { |
Grazvydas Ignotas | a2f9b2a | 2013-02-17 02:43:12 +0200 | [diff] [blame] | 404 | struct tpo_td043_device *tpo_td043 = g_tpo_td043; |
Archit Taneja | 7eab07e4 | 2012-11-21 15:39:31 +0530 | [diff] [blame] | 405 | struct panel_tpo_td043_data *pdata = get_panel_data(dssdev); |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 406 | int ret = 0; |
| 407 | |
Tomi Valkeinen | ecc8b37 | 2013-02-14 14:17:28 +0200 | [diff] [blame^] | 408 | dev_dbg(dssdev->dev, "probe\n"); |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 409 | |
| 410 | if (tpo_td043 == NULL) { |
Tomi Valkeinen | ecc8b37 | 2013-02-14 14:17:28 +0200 | [diff] [blame^] | 411 | dev_err(dssdev->dev, "missing tpo_td043_device\n"); |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 412 | return -ENODEV; |
| 413 | } |
| 414 | |
Archit Taneja | 7eab07e4 | 2012-11-21 15:39:31 +0530 | [diff] [blame] | 415 | if (!pdata) |
| 416 | return -EINVAL; |
| 417 | |
| 418 | tpo_td043->nreset_gpio = pdata->nreset_gpio; |
| 419 | |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 420 | dssdev->panel.timings = tpo_td043_timings; |
| 421 | dssdev->ctrl.pixel_size = 24; |
| 422 | |
| 423 | tpo_td043->mode = TPO_R02_MODE_800x480; |
| 424 | memcpy(tpo_td043->gamma, tpo_td043_def_gamma, sizeof(tpo_td043->gamma)); |
| 425 | |
Tomi Valkeinen | ecc8b37 | 2013-02-14 14:17:28 +0200 | [diff] [blame^] | 426 | tpo_td043->vcc_reg = regulator_get(dssdev->dev, "vcc"); |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 427 | if (IS_ERR(tpo_td043->vcc_reg)) { |
Tomi Valkeinen | ecc8b37 | 2013-02-14 14:17:28 +0200 | [diff] [blame^] | 428 | dev_err(dssdev->dev, "failed to get LCD VCC regulator\n"); |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 429 | ret = PTR_ERR(tpo_td043->vcc_reg); |
| 430 | goto fail_regulator; |
| 431 | } |
| 432 | |
Archit Taneja | 7eab07e4 | 2012-11-21 15:39:31 +0530 | [diff] [blame] | 433 | if (gpio_is_valid(tpo_td043->nreset_gpio)) { |
Tomi Valkeinen | ecc8b37 | 2013-02-14 14:17:28 +0200 | [diff] [blame^] | 434 | ret = devm_gpio_request_one(dssdev->dev, |
Archit Taneja | 7eab07e4 | 2012-11-21 15:39:31 +0530 | [diff] [blame] | 435 | tpo_td043->nreset_gpio, GPIOF_OUT_INIT_LOW, |
| 436 | "lcd reset"); |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 437 | if (ret < 0) { |
Tomi Valkeinen | ecc8b37 | 2013-02-14 14:17:28 +0200 | [diff] [blame^] | 438 | dev_err(dssdev->dev, "couldn't request reset GPIO\n"); |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 439 | goto fail_gpio_req; |
| 440 | } |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 441 | } |
| 442 | |
Tomi Valkeinen | ecc8b37 | 2013-02-14 14:17:28 +0200 | [diff] [blame^] | 443 | ret = sysfs_create_group(&dssdev->dev->kobj, &tpo_td043_attr_group); |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 444 | if (ret) |
Tomi Valkeinen | ecc8b37 | 2013-02-14 14:17:28 +0200 | [diff] [blame^] | 445 | dev_warn(dssdev->dev, "failed to create sysfs files\n"); |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 446 | |
Tomi Valkeinen | ecc8b37 | 2013-02-14 14:17:28 +0200 | [diff] [blame^] | 447 | dev_set_drvdata(dssdev->dev, tpo_td043); |
Grazvydas Ignotas | a2f9b2a | 2013-02-17 02:43:12 +0200 | [diff] [blame] | 448 | |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 449 | return 0; |
| 450 | |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 451 | fail_gpio_req: |
| 452 | regulator_put(tpo_td043->vcc_reg); |
| 453 | fail_regulator: |
| 454 | kfree(tpo_td043); |
| 455 | return ret; |
| 456 | } |
| 457 | |
| 458 | static void tpo_td043_remove(struct omap_dss_device *dssdev) |
| 459 | { |
Tomi Valkeinen | ecc8b37 | 2013-02-14 14:17:28 +0200 | [diff] [blame^] | 460 | struct tpo_td043_device *tpo_td043 = dev_get_drvdata(dssdev->dev); |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 461 | |
Tomi Valkeinen | ecc8b37 | 2013-02-14 14:17:28 +0200 | [diff] [blame^] | 462 | dev_dbg(dssdev->dev, "remove\n"); |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 463 | |
Tomi Valkeinen | ecc8b37 | 2013-02-14 14:17:28 +0200 | [diff] [blame^] | 464 | sysfs_remove_group(&dssdev->dev->kobj, &tpo_td043_attr_group); |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 465 | regulator_put(tpo_td043->vcc_reg); |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 466 | } |
| 467 | |
Grazvydas Ignotas | 31e8dfe | 2012-03-15 20:00:24 +0200 | [diff] [blame] | 468 | static void tpo_td043_set_timings(struct omap_dss_device *dssdev, |
| 469 | struct omap_video_timings *timings) |
| 470 | { |
Archit Taneja | c499144 | 2012-08-08 14:28:54 +0530 | [diff] [blame] | 471 | omapdss_dpi_set_timings(dssdev, timings); |
Archit Taneja | bdcae3c | 2012-08-08 14:29:48 +0530 | [diff] [blame] | 472 | |
| 473 | dssdev->panel.timings = *timings; |
Grazvydas Ignotas | 31e8dfe | 2012-03-15 20:00:24 +0200 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | static int tpo_td043_check_timings(struct omap_dss_device *dssdev, |
| 477 | struct omap_video_timings *timings) |
| 478 | { |
| 479 | return dpi_check_timings(dssdev, timings); |
| 480 | } |
| 481 | |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 482 | static struct omap_dss_driver tpo_td043_driver = { |
| 483 | .probe = tpo_td043_probe, |
| 484 | .remove = tpo_td043_remove, |
| 485 | |
| 486 | .enable = tpo_td043_enable, |
| 487 | .disable = tpo_td043_disable, |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 488 | .set_mirror = tpo_td043_set_hmirror, |
| 489 | .get_mirror = tpo_td043_get_hmirror, |
| 490 | |
Grazvydas Ignotas | 31e8dfe | 2012-03-15 20:00:24 +0200 | [diff] [blame] | 491 | .set_timings = tpo_td043_set_timings, |
| 492 | .check_timings = tpo_td043_check_timings, |
| 493 | |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 494 | .driver = { |
| 495 | .name = "tpo_td043mtea1_panel", |
| 496 | .owner = THIS_MODULE, |
| 497 | }, |
| 498 | }; |
| 499 | |
| 500 | static int tpo_td043_spi_probe(struct spi_device *spi) |
| 501 | { |
| 502 | struct omap_dss_device *dssdev = spi->dev.platform_data; |
| 503 | struct tpo_td043_device *tpo_td043; |
| 504 | int ret; |
| 505 | |
| 506 | if (dssdev == NULL) { |
| 507 | dev_err(&spi->dev, "missing dssdev\n"); |
| 508 | return -ENODEV; |
| 509 | } |
| 510 | |
Grazvydas Ignotas | a2f9b2a | 2013-02-17 02:43:12 +0200 | [diff] [blame] | 511 | if (g_tpo_td043 != NULL) |
| 512 | return -EBUSY; |
| 513 | |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 514 | spi->bits_per_word = 16; |
| 515 | spi->mode = SPI_MODE_0; |
| 516 | |
| 517 | ret = spi_setup(spi); |
| 518 | if (ret < 0) { |
| 519 | dev_err(&spi->dev, "spi_setup failed: %d\n", ret); |
| 520 | return ret; |
| 521 | } |
| 522 | |
| 523 | tpo_td043 = kzalloc(sizeof(*tpo_td043), GFP_KERNEL); |
| 524 | if (tpo_td043 == NULL) |
| 525 | return -ENOMEM; |
| 526 | |
| 527 | tpo_td043->spi = spi; |
| 528 | dev_set_drvdata(&spi->dev, tpo_td043); |
Grazvydas Ignotas | a2f9b2a | 2013-02-17 02:43:12 +0200 | [diff] [blame] | 529 | g_tpo_td043 = tpo_td043; |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 530 | |
| 531 | omap_dss_register_driver(&tpo_td043_driver); |
| 532 | |
| 533 | return 0; |
| 534 | } |
| 535 | |
Greg Kroah-Hartman | 48c68c4 | 2012-12-21 13:07:39 -0800 | [diff] [blame] | 536 | static int tpo_td043_spi_remove(struct spi_device *spi) |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 537 | { |
| 538 | struct tpo_td043_device *tpo_td043 = dev_get_drvdata(&spi->dev); |
| 539 | |
| 540 | omap_dss_unregister_driver(&tpo_td043_driver); |
| 541 | kfree(tpo_td043); |
Grazvydas Ignotas | a2f9b2a | 2013-02-17 02:43:12 +0200 | [diff] [blame] | 542 | g_tpo_td043 = NULL; |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 543 | |
| 544 | return 0; |
| 545 | } |
| 546 | |
Grazvydas Ignotas | 8df4f5c | 2012-02-07 02:13:49 +0200 | [diff] [blame] | 547 | #ifdef CONFIG_PM_SLEEP |
| 548 | static int tpo_td043_spi_suspend(struct device *dev) |
| 549 | { |
| 550 | struct tpo_td043_device *tpo_td043 = dev_get_drvdata(dev); |
| 551 | |
| 552 | dev_dbg(dev, "tpo_td043_spi_suspend, tpo %p\n", tpo_td043); |
| 553 | |
| 554 | tpo_td043->power_on_resume = tpo_td043->powered_on; |
| 555 | tpo_td043_power_off(tpo_td043); |
| 556 | tpo_td043->spi_suspended = 1; |
| 557 | |
| 558 | return 0; |
| 559 | } |
| 560 | |
| 561 | static int tpo_td043_spi_resume(struct device *dev) |
| 562 | { |
| 563 | struct tpo_td043_device *tpo_td043 = dev_get_drvdata(dev); |
| 564 | int ret; |
| 565 | |
| 566 | dev_dbg(dev, "tpo_td043_spi_resume\n"); |
| 567 | |
| 568 | if (tpo_td043->power_on_resume) { |
| 569 | ret = tpo_td043_power_on(tpo_td043); |
| 570 | if (ret) |
| 571 | return ret; |
| 572 | } |
| 573 | tpo_td043->spi_suspended = 0; |
| 574 | |
| 575 | return 0; |
| 576 | } |
| 577 | #endif |
| 578 | |
| 579 | static SIMPLE_DEV_PM_OPS(tpo_td043_spi_pm, |
| 580 | tpo_td043_spi_suspend, tpo_td043_spi_resume); |
| 581 | |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 582 | static struct spi_driver tpo_td043_spi_driver = { |
| 583 | .driver = { |
| 584 | .name = "tpo_td043mtea1_panel_spi", |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 585 | .owner = THIS_MODULE, |
Grazvydas Ignotas | 8df4f5c | 2012-02-07 02:13:49 +0200 | [diff] [blame] | 586 | .pm = &tpo_td043_spi_pm, |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 587 | }, |
| 588 | .probe = tpo_td043_spi_probe, |
Greg Kroah-Hartman | 48c68c4 | 2012-12-21 13:07:39 -0800 | [diff] [blame] | 589 | .remove = tpo_td043_spi_remove, |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 590 | }; |
| 591 | |
Axel Lin | c6d242a | 2012-01-27 16:02:54 +0800 | [diff] [blame] | 592 | module_spi_driver(tpo_td043_spi_driver); |
Grazvydas Ignotas | 9ce4ad0 | 2009-12-11 21:30:14 +0200 | [diff] [blame] | 593 | |
| 594 | MODULE_AUTHOR("Gražvydas Ignotas <notasas@gmail.com>"); |
| 595 | MODULE_DESCRIPTION("TPO TD043MTEA1 LCD Driver"); |
| 596 | MODULE_LICENSE("GPL"); |