blob: e3252bf4781ad765d2aadb7ccf6c69817517aee7 [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{
129 struct tpo_td043_device *tpo_td043 = dev_get_drvdata(&dssdev->dev);
130
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{
138 struct tpo_td043_device *tpo_td043 = dev_get_drvdata(&dssdev->dev);
139
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{
Grazvydas Ignotas8df4f5c2012-02-07 02:13:49 +0200341 struct tpo_td043_device *tpo_td043 = dev_get_drvdata(&dssdev->dev);
342 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
354 if (dssdev->platform_enable) {
355 r = dssdev->platform_enable(dssdev);
356 if (r)
357 goto err1;
358 }
359
360 /*
361 * If we are resuming from system suspend, SPI clocks might not be
362 * enabled yet, so we'll program the LCD from SPI PM resume callback.
363 */
364 if (!tpo_td043->spi_suspended) {
365 r = tpo_td043_power_on(tpo_td043);
366 if (r)
367 goto err1;
368 }
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200369
370 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
371
372 return 0;
Grazvydas Ignotas8df4f5c2012-02-07 02:13:49 +0200373err1:
374 omapdss_dpi_display_disable(dssdev);
375err0:
376 return r;
377}
378
379static void tpo_td043_disable_dss(struct omap_dss_device *dssdev)
380{
381 struct tpo_td043_device *tpo_td043 = dev_get_drvdata(&dssdev->dev);
382
383 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
384 return;
385
386 if (dssdev->platform_disable)
387 dssdev->platform_disable(dssdev);
388
389 omapdss_dpi_display_disable(dssdev);
390
391 if (!tpo_td043->spi_suspended)
392 tpo_td043_power_off(tpo_td043);
393}
394
395static int tpo_td043_enable(struct omap_dss_device *dssdev)
396{
397 dev_dbg(&dssdev->dev, "enable\n");
398
399 return tpo_td043_enable_dss(dssdev);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200400}
401
402static void tpo_td043_disable(struct omap_dss_device *dssdev)
403{
404 dev_dbg(&dssdev->dev, "disable\n");
405
Grazvydas Ignotas8df4f5c2012-02-07 02:13:49 +0200406 tpo_td043_disable_dss(dssdev);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200407
408 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200409}
410
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200411static int tpo_td043_probe(struct omap_dss_device *dssdev)
412{
Grazvydas Ignotasa2f9b2a2013-02-17 02:43:12 +0200413 struct tpo_td043_device *tpo_td043 = g_tpo_td043;
Archit Taneja7eab07e42012-11-21 15:39:31 +0530414 struct panel_tpo_td043_data *pdata = get_panel_data(dssdev);
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200415 int ret = 0;
416
417 dev_dbg(&dssdev->dev, "probe\n");
418
419 if (tpo_td043 == NULL) {
420 dev_err(&dssdev->dev, "missing tpo_td043_device\n");
421 return -ENODEV;
422 }
423
Archit Taneja7eab07e42012-11-21 15:39:31 +0530424 if (!pdata)
425 return -EINVAL;
426
427 tpo_td043->nreset_gpio = pdata->nreset_gpio;
428
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200429 dssdev->panel.timings = tpo_td043_timings;
430 dssdev->ctrl.pixel_size = 24;
431
432 tpo_td043->mode = TPO_R02_MODE_800x480;
433 memcpy(tpo_td043->gamma, tpo_td043_def_gamma, sizeof(tpo_td043->gamma));
434
435 tpo_td043->vcc_reg = regulator_get(&dssdev->dev, "vcc");
436 if (IS_ERR(tpo_td043->vcc_reg)) {
437 dev_err(&dssdev->dev, "failed to get LCD VCC regulator\n");
438 ret = PTR_ERR(tpo_td043->vcc_reg);
439 goto fail_regulator;
440 }
441
Archit Taneja7eab07e42012-11-21 15:39:31 +0530442 if (gpio_is_valid(tpo_td043->nreset_gpio)) {
443 ret = devm_gpio_request_one(&dssdev->dev,
444 tpo_td043->nreset_gpio, GPIOF_OUT_INIT_LOW,
445 "lcd reset");
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200446 if (ret < 0) {
447 dev_err(&dssdev->dev, "couldn't request reset GPIO\n");
448 goto fail_gpio_req;
449 }
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200450 }
451
452 ret = sysfs_create_group(&dssdev->dev.kobj, &tpo_td043_attr_group);
453 if (ret)
454 dev_warn(&dssdev->dev, "failed to create sysfs files\n");
455
Grazvydas Ignotasa2f9b2a2013-02-17 02:43:12 +0200456 dev_set_drvdata(&dssdev->dev, tpo_td043);
457
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200458 return 0;
459
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200460fail_gpio_req:
461 regulator_put(tpo_td043->vcc_reg);
462fail_regulator:
463 kfree(tpo_td043);
464 return ret;
465}
466
467static void tpo_td043_remove(struct omap_dss_device *dssdev)
468{
469 struct tpo_td043_device *tpo_td043 = dev_get_drvdata(&dssdev->dev);
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200470
471 dev_dbg(&dssdev->dev, "remove\n");
472
473 sysfs_remove_group(&dssdev->dev.kobj, &tpo_td043_attr_group);
474 regulator_put(tpo_td043->vcc_reg);
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200475}
476
Grazvydas Ignotas31e8dfe2012-03-15 20:00:24 +0200477static void tpo_td043_set_timings(struct omap_dss_device *dssdev,
478 struct omap_video_timings *timings)
479{
Archit Tanejac4991442012-08-08 14:28:54 +0530480 omapdss_dpi_set_timings(dssdev, timings);
Archit Tanejabdcae3c2012-08-08 14:29:48 +0530481
482 dssdev->panel.timings = *timings;
Grazvydas Ignotas31e8dfe2012-03-15 20:00:24 +0200483}
484
485static int tpo_td043_check_timings(struct omap_dss_device *dssdev,
486 struct omap_video_timings *timings)
487{
488 return dpi_check_timings(dssdev, timings);
489}
490
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200491static struct omap_dss_driver tpo_td043_driver = {
492 .probe = tpo_td043_probe,
493 .remove = tpo_td043_remove,
494
495 .enable = tpo_td043_enable,
496 .disable = tpo_td043_disable,
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200497 .set_mirror = tpo_td043_set_hmirror,
498 .get_mirror = tpo_td043_get_hmirror,
499
Grazvydas Ignotas31e8dfe2012-03-15 20:00:24 +0200500 .set_timings = tpo_td043_set_timings,
501 .check_timings = tpo_td043_check_timings,
502
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200503 .driver = {
504 .name = "tpo_td043mtea1_panel",
505 .owner = THIS_MODULE,
506 },
507};
508
509static int tpo_td043_spi_probe(struct spi_device *spi)
510{
511 struct omap_dss_device *dssdev = spi->dev.platform_data;
512 struct tpo_td043_device *tpo_td043;
513 int ret;
514
515 if (dssdev == NULL) {
516 dev_err(&spi->dev, "missing dssdev\n");
517 return -ENODEV;
518 }
519
Grazvydas Ignotasa2f9b2a2013-02-17 02:43:12 +0200520 if (g_tpo_td043 != NULL)
521 return -EBUSY;
522
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200523 spi->bits_per_word = 16;
524 spi->mode = SPI_MODE_0;
525
526 ret = spi_setup(spi);
527 if (ret < 0) {
528 dev_err(&spi->dev, "spi_setup failed: %d\n", ret);
529 return ret;
530 }
531
532 tpo_td043 = kzalloc(sizeof(*tpo_td043), GFP_KERNEL);
533 if (tpo_td043 == NULL)
534 return -ENOMEM;
535
536 tpo_td043->spi = spi;
537 dev_set_drvdata(&spi->dev, tpo_td043);
Grazvydas Ignotasa2f9b2a2013-02-17 02:43:12 +0200538 g_tpo_td043 = tpo_td043;
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200539
540 omap_dss_register_driver(&tpo_td043_driver);
541
542 return 0;
543}
544
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800545static int tpo_td043_spi_remove(struct spi_device *spi)
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200546{
547 struct tpo_td043_device *tpo_td043 = dev_get_drvdata(&spi->dev);
548
549 omap_dss_unregister_driver(&tpo_td043_driver);
550 kfree(tpo_td043);
Grazvydas Ignotasa2f9b2a2013-02-17 02:43:12 +0200551 g_tpo_td043 = NULL;
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200552
553 return 0;
554}
555
Grazvydas Ignotas8df4f5c2012-02-07 02:13:49 +0200556#ifdef CONFIG_PM_SLEEP
557static int tpo_td043_spi_suspend(struct device *dev)
558{
559 struct tpo_td043_device *tpo_td043 = dev_get_drvdata(dev);
560
561 dev_dbg(dev, "tpo_td043_spi_suspend, tpo %p\n", tpo_td043);
562
563 tpo_td043->power_on_resume = tpo_td043->powered_on;
564 tpo_td043_power_off(tpo_td043);
565 tpo_td043->spi_suspended = 1;
566
567 return 0;
568}
569
570static int tpo_td043_spi_resume(struct device *dev)
571{
572 struct tpo_td043_device *tpo_td043 = dev_get_drvdata(dev);
573 int ret;
574
575 dev_dbg(dev, "tpo_td043_spi_resume\n");
576
577 if (tpo_td043->power_on_resume) {
578 ret = tpo_td043_power_on(tpo_td043);
579 if (ret)
580 return ret;
581 }
582 tpo_td043->spi_suspended = 0;
583
584 return 0;
585}
586#endif
587
588static SIMPLE_DEV_PM_OPS(tpo_td043_spi_pm,
589 tpo_td043_spi_suspend, tpo_td043_spi_resume);
590
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200591static struct spi_driver tpo_td043_spi_driver = {
592 .driver = {
593 .name = "tpo_td043mtea1_panel_spi",
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200594 .owner = THIS_MODULE,
Grazvydas Ignotas8df4f5c2012-02-07 02:13:49 +0200595 .pm = &tpo_td043_spi_pm,
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200596 },
597 .probe = tpo_td043_spi_probe,
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800598 .remove = tpo_td043_spi_remove,
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200599};
600
Axel Linc6d242a2012-01-27 16:02:54 +0800601module_spi_driver(tpo_td043_spi_driver);
Grazvydas Ignotas9ce4ad02009-12-11 21:30:14 +0200602
603MODULE_AUTHOR("Gražvydas Ignotas <notasas@gmail.com>");
604MODULE_DESCRIPTION("TPO TD043MTEA1 LCD Driver");
605MODULE_LICENSE("GPL");