blob: 7729b6fa6f97748bac06ca9e44a94fdae65df74d [file] [log] [blame]
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +02001/*
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 Heo5a0e3ad2010-03-24 17:04:11 +090018#include <linux/slab.h>
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +020019
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030020#include <video/omapdss.h>
Archit Taneja7eab07e42012-11-21 15:39:31 +053021#include <video/omap-panel-data.h>
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +020022
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
50static const u16 tpo_td043_def_gamma[12] = {
Grazvydas Ignotas4306b722012-02-07 02:13:50 +020051 105, 315, 381, 431, 490, 537, 579, 686, 780, 837, 880, 1023
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +020052};
53
54struct tpo_td043_device {
55 struct spi_device *spi;
56 struct regulator *vcc_reg;
Grazvydas Ignotas8df4f5c2012-02-07 02:13:49 +020057 int nreset_gpio;
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +020058 u16 gamma[12];
59 u32 mode;
60 u32 hmirror:1;
61 u32 vmirror:1;
Grazvydas Ignotas8df4f5c2012-02-07 02:13:49 +020062 u32 powered_on:1;
63 u32 spi_suspended:1;
64 u32 power_on_resume:1;
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +020065};
66
Grazvydas Ignotasa2f9b2a2013-02-17 02:43:12 +020067/* used to pass spi_device from SPI to DSS portion of the driver */
68static struct tpo_td043_device *g_tpo_td043;
69
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +020070static 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
93static 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
115static 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
127static int tpo_td043_set_hmirror(struct omap_dss_device *dssdev, bool enable)
128{
Tomi Valkeinenecc8b372013-02-14 14:17:28 +0200129 struct tpo_td043_device *tpo_td043 = dev_get_drvdata(dssdev->dev);
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200130
131 tpo_td043->hmirror = enable;
132 return tpo_td043_write_mirror(tpo_td043->spi, tpo_td043->hmirror,
133 tpo_td043->vmirror);
134}
135
136static bool tpo_td043_get_hmirror(struct omap_dss_device *dssdev)
137{
Tomi Valkeinenecc8b372013-02-14 14:17:28 +0200138 struct tpo_td043_device *tpo_td043 = dev_get_drvdata(dssdev->dev);
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200139
140 return tpo_td043->hmirror;
141}
142
143static 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
151static 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 Valkeinene3502ce2011-04-04 15:40:23 +0300155 int val;
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200156 int ret;
157
Tomi Valkeinene3502ce2011-04-04 15:40:23 +0300158 ret = kstrtoint(buf, 0, &val);
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200159 if (ret < 0)
160 return ret;
161
Tomi Valkeinene3502ce2011-04-04 15:40:23 +0300162 val = !!val;
163
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200164 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
173static 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
181static 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 Valkeinene3502ce2011-04-04 15:40:23 +0300188 ret = kstrtol(buf, 0, &val);
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200189 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
200static 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
220static 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
243static DEVICE_ATTR(vmirror, S_IRUGO | S_IWUSR,
244 tpo_td043_vmirror_show, tpo_td043_vmirror_store);
245static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR,
246 tpo_td043_mode_show, tpo_td043_mode_store);
247static DEVICE_ATTR(gamma, S_IRUGO | S_IWUSR,
248 tpo_td043_gamma_show, tpo_td043_gamma_store);
249
250static struct attribute *tpo_td043_attrs[] = {
251 &dev_attr_vmirror.attr,
252 &dev_attr_mode.attr,
253 &dev_attr_gamma.attr,
254 NULL,
255};
256
257static struct attribute_group tpo_td043_attr_group = {
258 .attrs = tpo_td043_attrs,
259};
260
261static 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 Tanejaa8d5e412012-06-25 12:26:38 +0530274
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 Ignotas9ce4ad02009-12-11 21:30:14 +0200280};
281
Archit Taneja7eab07e42012-11-21 15:39:31 +0530282static 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 Ignotas8df4f5c2012-02-07 02:13:49 +0200288static int tpo_td043_power_on(struct tpo_td043_device *tpo_td043)
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200289{
Mark Brown956107e2012-03-19 15:02:31 +0000290 int r;
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200291
Grazvydas Ignotas8df4f5c2012-02-07 02:13:49 +0200292 if (tpo_td043->powered_on)
Stanley.Miao18016e32010-09-03 05:03:48 +0200293 return 0;
294
Mark Brown956107e2012-03-19 15:02:31 +0000295 r = regulator_enable(tpo_td043->vcc_reg);
296 if (r != 0)
297 return r;
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200298
Mark Brown2c83af42012-03-19 15:02:32 +0000299 /* wait for panel to stabilize */
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200300 msleep(160);
301
Archit Taneja7eab07e42012-11-21 15:39:31 +0530302 if (gpio_is_valid(tpo_td043->nreset_gpio))
303 gpio_set_value(tpo_td043->nreset_gpio, 1);
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200304
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 Ignotas8df4f5c2012-02-07 02:13:49 +0200314 tpo_td043->powered_on = 1;
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200315 return 0;
316}
317
Grazvydas Ignotas8df4f5c2012-02-07 02:13:49 +0200318static void tpo_td043_power_off(struct tpo_td043_device *tpo_td043)
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200319{
Grazvydas Ignotas8df4f5c2012-02-07 02:13:49 +0200320 if (!tpo_td043->powered_on)
Stanley.Miao18016e32010-09-03 05:03:48 +0200321 return;
322
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200323 tpo_td043_write(tpo_td043->spi, 3,
324 TPO_R03_VAL_STANDBY | TPO_R03_EN_PWM);
325
Archit Taneja7eab07e42012-11-21 15:39:31 +0530326 if (gpio_is_valid(tpo_td043->nreset_gpio))
327 gpio_set_value(tpo_td043->nreset_gpio, 0);
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200328
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 Ignotas8df4f5c2012-02-07 02:13:49 +0200336 tpo_td043->powered_on = 0;
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200337}
338
Grazvydas Ignotas8df4f5c2012-02-07 02:13:49 +0200339static int tpo_td043_enable_dss(struct omap_dss_device *dssdev)
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200340{
Tomi Valkeinenecc8b372013-02-14 14:17:28 +0200341 struct tpo_td043_device *tpo_td043 = dev_get_drvdata(dssdev->dev);
Grazvydas Ignotas8df4f5c2012-02-07 02:13:49 +0200342 int r;
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200343
Grazvydas Ignotas8df4f5c2012-02-07 02:13:49 +0200344 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
345 return 0;
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200346
Archit Tanejac4991442012-08-08 14:28:54 +0530347 omapdss_dpi_set_timings(dssdev, &dssdev->panel.timings);
Archit Tanejac6b393d2012-07-06 15:30:52 +0530348 omapdss_dpi_set_data_lines(dssdev, dssdev->phy.dpi.data_lines);
Archit Tanejac4991442012-08-08 14:28:54 +0530349
Grazvydas Ignotas8df4f5c2012-02-07 02:13:49 +0200350 r = omapdss_dpi_display_enable(dssdev);
351 if (r)
352 goto err0;
353
Grazvydas Ignotas8df4f5c2012-02-07 02:13:49 +0200354 /*
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 Valkeinen37ac60e2010-01-12 15:12:07 +0200363
364 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
365
366 return 0;
Grazvydas Ignotas8df4f5c2012-02-07 02:13:49 +0200367err1:
368 omapdss_dpi_display_disable(dssdev);
369err0:
370 return r;
371}
372
373static void tpo_td043_disable_dss(struct omap_dss_device *dssdev)
374{
Tomi Valkeinenecc8b372013-02-14 14:17:28 +0200375 struct tpo_td043_device *tpo_td043 = dev_get_drvdata(dssdev->dev);
Grazvydas Ignotas8df4f5c2012-02-07 02:13:49 +0200376
377 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
378 return;
379
Grazvydas Ignotas8df4f5c2012-02-07 02:13:49 +0200380 omapdss_dpi_display_disable(dssdev);
381
382 if (!tpo_td043->spi_suspended)
383 tpo_td043_power_off(tpo_td043);
384}
385
386static int tpo_td043_enable(struct omap_dss_device *dssdev)
387{
Tomi Valkeinenecc8b372013-02-14 14:17:28 +0200388 dev_dbg(dssdev->dev, "enable\n");
Grazvydas Ignotas8df4f5c2012-02-07 02:13:49 +0200389
390 return tpo_td043_enable_dss(dssdev);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200391}
392
393static void tpo_td043_disable(struct omap_dss_device *dssdev)
394{
Tomi Valkeinenecc8b372013-02-14 14:17:28 +0200395 dev_dbg(dssdev->dev, "disable\n");
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200396
Grazvydas Ignotas8df4f5c2012-02-07 02:13:49 +0200397 tpo_td043_disable_dss(dssdev);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200398
399 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200400}
401
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200402static int tpo_td043_probe(struct omap_dss_device *dssdev)
403{
Grazvydas Ignotasa2f9b2a2013-02-17 02:43:12 +0200404 struct tpo_td043_device *tpo_td043 = g_tpo_td043;
Archit Taneja7eab07e42012-11-21 15:39:31 +0530405 struct panel_tpo_td043_data *pdata = get_panel_data(dssdev);
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200406 int ret = 0;
407
Tomi Valkeinenecc8b372013-02-14 14:17:28 +0200408 dev_dbg(dssdev->dev, "probe\n");
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200409
410 if (tpo_td043 == NULL) {
Tomi Valkeinenecc8b372013-02-14 14:17:28 +0200411 dev_err(dssdev->dev, "missing tpo_td043_device\n");
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200412 return -ENODEV;
413 }
414
Archit Taneja7eab07e42012-11-21 15:39:31 +0530415 if (!pdata)
416 return -EINVAL;
417
418 tpo_td043->nreset_gpio = pdata->nreset_gpio;
419
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200420 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 Valkeinenecc8b372013-02-14 14:17:28 +0200426 tpo_td043->vcc_reg = regulator_get(dssdev->dev, "vcc");
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200427 if (IS_ERR(tpo_td043->vcc_reg)) {
Tomi Valkeinenecc8b372013-02-14 14:17:28 +0200428 dev_err(dssdev->dev, "failed to get LCD VCC regulator\n");
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200429 ret = PTR_ERR(tpo_td043->vcc_reg);
430 goto fail_regulator;
431 }
432
Archit Taneja7eab07e42012-11-21 15:39:31 +0530433 if (gpio_is_valid(tpo_td043->nreset_gpio)) {
Tomi Valkeinenecc8b372013-02-14 14:17:28 +0200434 ret = devm_gpio_request_one(dssdev->dev,
Archit Taneja7eab07e42012-11-21 15:39:31 +0530435 tpo_td043->nreset_gpio, GPIOF_OUT_INIT_LOW,
436 "lcd reset");
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200437 if (ret < 0) {
Tomi Valkeinenecc8b372013-02-14 14:17:28 +0200438 dev_err(dssdev->dev, "couldn't request reset GPIO\n");
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200439 goto fail_gpio_req;
440 }
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200441 }
442
Tomi Valkeinenecc8b372013-02-14 14:17:28 +0200443 ret = sysfs_create_group(&dssdev->dev->kobj, &tpo_td043_attr_group);
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200444 if (ret)
Tomi Valkeinenecc8b372013-02-14 14:17:28 +0200445 dev_warn(dssdev->dev, "failed to create sysfs files\n");
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200446
Tomi Valkeinenecc8b372013-02-14 14:17:28 +0200447 dev_set_drvdata(dssdev->dev, tpo_td043);
Grazvydas Ignotasa2f9b2a2013-02-17 02:43:12 +0200448
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200449 return 0;
450
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200451fail_gpio_req:
452 regulator_put(tpo_td043->vcc_reg);
453fail_regulator:
454 kfree(tpo_td043);
455 return ret;
456}
457
458static void tpo_td043_remove(struct omap_dss_device *dssdev)
459{
Tomi Valkeinenecc8b372013-02-14 14:17:28 +0200460 struct tpo_td043_device *tpo_td043 = dev_get_drvdata(dssdev->dev);
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200461
Tomi Valkeinenecc8b372013-02-14 14:17:28 +0200462 dev_dbg(dssdev->dev, "remove\n");
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200463
Tomi Valkeinenecc8b372013-02-14 14:17:28 +0200464 sysfs_remove_group(&dssdev->dev->kobj, &tpo_td043_attr_group);
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200465 regulator_put(tpo_td043->vcc_reg);
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200466}
467
Grazvydas Ignotas31e8dfe2012-03-15 20:00:24 +0200468static void tpo_td043_set_timings(struct omap_dss_device *dssdev,
469 struct omap_video_timings *timings)
470{
Archit Tanejac4991442012-08-08 14:28:54 +0530471 omapdss_dpi_set_timings(dssdev, timings);
Archit Tanejabdcae3c2012-08-08 14:29:48 +0530472
473 dssdev->panel.timings = *timings;
Grazvydas Ignotas31e8dfe2012-03-15 20:00:24 +0200474}
475
476static 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 Ignotas9ce4ad02009-12-11 21:30:14 +0200482static 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 Ignotas9ce4ad02009-12-11 21:30:14 +0200488 .set_mirror = tpo_td043_set_hmirror,
489 .get_mirror = tpo_td043_get_hmirror,
490
Grazvydas Ignotas31e8dfe2012-03-15 20:00:24 +0200491 .set_timings = tpo_td043_set_timings,
492 .check_timings = tpo_td043_check_timings,
493
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200494 .driver = {
495 .name = "tpo_td043mtea1_panel",
496 .owner = THIS_MODULE,
497 },
498};
499
500static 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 Ignotasa2f9b2a2013-02-17 02:43:12 +0200511 if (g_tpo_td043 != NULL)
512 return -EBUSY;
513
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200514 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 Ignotasa2f9b2a2013-02-17 02:43:12 +0200529 g_tpo_td043 = tpo_td043;
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200530
531 omap_dss_register_driver(&tpo_td043_driver);
532
533 return 0;
534}
535
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800536static int tpo_td043_spi_remove(struct spi_device *spi)
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200537{
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 Ignotasa2f9b2a2013-02-17 02:43:12 +0200542 g_tpo_td043 = NULL;
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200543
544 return 0;
545}
546
Grazvydas Ignotas8df4f5c2012-02-07 02:13:49 +0200547#ifdef CONFIG_PM_SLEEP
548static 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
561static 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
579static SIMPLE_DEV_PM_OPS(tpo_td043_spi_pm,
580 tpo_td043_spi_suspend, tpo_td043_spi_resume);
581
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200582static struct spi_driver tpo_td043_spi_driver = {
583 .driver = {
584 .name = "tpo_td043mtea1_panel_spi",
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200585 .owner = THIS_MODULE,
Grazvydas Ignotas8df4f5c2012-02-07 02:13:49 +0200586 .pm = &tpo_td043_spi_pm,
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200587 },
588 .probe = tpo_td043_spi_probe,
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800589 .remove = tpo_td043_spi_remove,
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200590};
591
Axel Linc6d242a2012-01-27 16:02:54 +0800592module_spi_driver(tpo_td043_spi_driver);
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200593
594MODULE_AUTHOR("Gražvydas Ignotas <notasas@gmail.com>");
595MODULE_DESCRIPTION("TPO TD043MTEA1 LCD Driver");
596MODULE_LICENSE("GPL");