blob: 0787dba44faa3f8261ead6e18e03a84cbd2a0c19 [file] [log] [blame]
Tomi Valkeinen2e1def02013-05-31 13:13:44 +03001/*
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 Bergmannd0196c82016-05-11 18:05:39 +020017#include <linux/gpio/consumer.h>
Tomi Valkeinen2e1def02013-05-31 13:13:44 +030018#include <linux/err.h>
19#include <linux/slab.h>
Tomi Valkeinen597cc1e2014-05-16 12:28:36 +030020#include <linux/of_gpio.h>
Tomi Valkeinen2e1def02013-05-31 13:13:44 +030021
Peter Ujfalusi32043da2016-05-27 14:40:49 +030022#include "../dss/omapdss.h"
Tomi Valkeinen2e1def02013-05-31 13:13:44 +030023
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
51static const u16 tpo_td043_def_gamma[12] = {
52 105, 315, 381, 431, 490, 537, 579, 686, 780, 837, 880, 1023
53};
54
55struct panel_drv_data {
56 struct omap_dss_device dssdev;
57 struct omap_dss_device *in;
58
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +030059 struct videomode vm;
Tomi Valkeinen2e1def02013-05-31 13:13:44 +030060
61 int data_lines;
62
63 struct spi_device *spi;
64 struct regulator *vcc_reg;
65 int nreset_gpio;
66 u16 gamma[12];
67 u32 mode;
68 u32 hmirror:1;
69 u32 vmirror:1;
70 u32 powered_on:1;
71 u32 spi_suspended:1;
72 u32 power_on_resume:1;
73};
74
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +030075static const struct videomode tpo_td043_vm = {
Peter Ujfalusi81899062016-09-22 14:06:46 +030076 .hactive = 800,
Peter Ujfalusifb7f3c42016-09-22 14:06:47 +030077 .vactive = 480,
Tomi Valkeinen2e1def02013-05-31 13:13:44 +030078
Tomi Valkeinend8d789412013-04-10 14:12:14 +030079 .pixelclock = 36000000,
Tomi Valkeinen2e1def02013-05-31 13:13:44 +030080
Peter Ujfalusi4dc22502016-09-22 14:06:48 +030081 .hsync_len = 1,
Peter Ujfalusi0a30e152016-09-22 14:06:49 +030082 .hfront_porch = 68,
Peter Ujfalusia85f4a82016-09-22 14:06:50 +030083 .hback_porch = 214,
Tomi Valkeinen2e1def02013-05-31 13:13:44 +030084
Peter Ujfalusid5bcf0a2016-09-22 14:06:51 +030085 .vsync_len = 1,
Peter Ujfalusi0996c682016-09-22 14:06:52 +030086 .vfront_porch = 39,
Peter Ujfalusi458540c2016-09-22 14:06:53 +030087 .vback_porch = 34,
Tomi Valkeinen2e1def02013-05-31 13:13:44 +030088
Peter Ujfalusi3fa3ab42016-09-22 14:06:58 +030089 .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW |
Peter Ujfalusid34afb72016-09-22 14:07:01 +030090 DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_SYNC_POSEDGE |
91 DISPLAY_FLAGS_PIXDATA_NEGEDGE,
Peter Ujfalusi26a8d212016-09-22 14:07:05 +030092 /*
93 * Note: According to the panel documentation:
94 * SYNC needs to be driven on the FALLING edge
95 */
Tomi Valkeinen2e1def02013-05-31 13:13:44 +030096};
97
98#define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
99
100static int tpo_td043_write(struct spi_device *spi, u8 addr, u8 data)
101{
102 struct spi_message m;
103 struct spi_transfer xfer;
104 u16 w;
105 int r;
106
107 spi_message_init(&m);
108
109 memset(&xfer, 0, sizeof(xfer));
110
111 w = ((u16)addr << 10) | (1 << 8) | data;
112 xfer.tx_buf = &w;
113 xfer.bits_per_word = 16;
114 xfer.len = 2;
115 spi_message_add_tail(&xfer, &m);
116
117 r = spi_sync(spi, &m);
118 if (r < 0)
119 dev_warn(&spi->dev, "failed to write to LCD reg (%d)\n", r);
120 return r;
121}
122
123static void tpo_td043_write_gamma(struct spi_device *spi, u16 gamma[12])
124{
125 u8 i, val;
126
127 /* gamma bits [9:8] */
128 for (val = i = 0; i < 4; i++)
129 val |= (gamma[i] & 0x300) >> ((i + 1) * 2);
130 tpo_td043_write(spi, 0x11, val);
131
132 for (val = i = 0; i < 4; i++)
133 val |= (gamma[i+4] & 0x300) >> ((i + 1) * 2);
134 tpo_td043_write(spi, 0x12, val);
135
136 for (val = i = 0; i < 4; i++)
137 val |= (gamma[i+8] & 0x300) >> ((i + 1) * 2);
138 tpo_td043_write(spi, 0x13, val);
139
140 /* gamma bits [7:0] */
141 for (val = i = 0; i < 12; i++)
142 tpo_td043_write(spi, 0x14 + i, gamma[i] & 0xff);
143}
144
145static int tpo_td043_write_mirror(struct spi_device *spi, bool h, bool v)
146{
147 u8 reg4 = TPO_R04_NFLIP_H | TPO_R04_NFLIP_V |
148 TPO_R04_CP_CLK_FREQ_1H | TPO_R04_VGL_FREQ_1H;
149 if (h)
150 reg4 &= ~TPO_R04_NFLIP_H;
151 if (v)
152 reg4 &= ~TPO_R04_NFLIP_V;
153
154 return tpo_td043_write(spi, 4, reg4);
155}
156
157static int tpo_td043_set_hmirror(struct omap_dss_device *dssdev, bool enable)
158{
159 struct panel_drv_data *ddata = dev_get_drvdata(dssdev->dev);
160
161 ddata->hmirror = enable;
162 return tpo_td043_write_mirror(ddata->spi, ddata->hmirror,
163 ddata->vmirror);
164}
165
166static bool tpo_td043_get_hmirror(struct omap_dss_device *dssdev)
167{
168 struct panel_drv_data *ddata = dev_get_drvdata(dssdev->dev);
169
170 return ddata->hmirror;
171}
172
173static ssize_t tpo_td043_vmirror_show(struct device *dev,
174 struct device_attribute *attr, char *buf)
175{
176 struct panel_drv_data *ddata = dev_get_drvdata(dev);
177
178 return snprintf(buf, PAGE_SIZE, "%d\n", ddata->vmirror);
179}
180
181static ssize_t tpo_td043_vmirror_store(struct device *dev,
182 struct device_attribute *attr, const char *buf, size_t count)
183{
184 struct panel_drv_data *ddata = dev_get_drvdata(dev);
185 int val;
186 int ret;
187
188 ret = kstrtoint(buf, 0, &val);
189 if (ret < 0)
190 return ret;
191
192 val = !!val;
193
194 ret = tpo_td043_write_mirror(ddata->spi, ddata->hmirror, val);
195 if (ret < 0)
196 return ret;
197
198 ddata->vmirror = val;
199
200 return count;
201}
202
203static ssize_t tpo_td043_mode_show(struct device *dev,
204 struct device_attribute *attr, char *buf)
205{
206 struct panel_drv_data *ddata = dev_get_drvdata(dev);
207
208 return snprintf(buf, PAGE_SIZE, "%d\n", ddata->mode);
209}
210
211static ssize_t tpo_td043_mode_store(struct device *dev,
212 struct device_attribute *attr, const char *buf, size_t count)
213{
214 struct panel_drv_data *ddata = dev_get_drvdata(dev);
215 long val;
216 int ret;
217
218 ret = kstrtol(buf, 0, &val);
219 if (ret != 0 || val & ~7)
220 return -EINVAL;
221
222 ddata->mode = val;
223
224 val |= TPO_R02_NCLK_RISING;
225 tpo_td043_write(ddata->spi, 2, val);
226
227 return count;
228}
229
230static ssize_t tpo_td043_gamma_show(struct device *dev,
231 struct device_attribute *attr, char *buf)
232{
233 struct panel_drv_data *ddata = dev_get_drvdata(dev);
234 ssize_t len = 0;
235 int ret;
236 int i;
237
238 for (i = 0; i < ARRAY_SIZE(ddata->gamma); i++) {
239 ret = snprintf(buf + len, PAGE_SIZE - len, "%u ",
240 ddata->gamma[i]);
241 if (ret < 0)
242 return ret;
243 len += ret;
244 }
245 buf[len - 1] = '\n';
246
247 return len;
248}
249
250static ssize_t tpo_td043_gamma_store(struct device *dev,
251 struct device_attribute *attr, const char *buf, size_t count)
252{
253 struct panel_drv_data *ddata = dev_get_drvdata(dev);
254 unsigned int g[12];
255 int ret;
256 int i;
257
258 ret = sscanf(buf, "%u %u %u %u %u %u %u %u %u %u %u %u",
259 &g[0], &g[1], &g[2], &g[3], &g[4], &g[5],
260 &g[6], &g[7], &g[8], &g[9], &g[10], &g[11]);
261
262 if (ret != 12)
263 return -EINVAL;
264
265 for (i = 0; i < 12; i++)
266 ddata->gamma[i] = g[i];
267
268 tpo_td043_write_gamma(ddata->spi, ddata->gamma);
269
270 return count;
271}
272
273static DEVICE_ATTR(vmirror, S_IRUGO | S_IWUSR,
274 tpo_td043_vmirror_show, tpo_td043_vmirror_store);
275static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR,
276 tpo_td043_mode_show, tpo_td043_mode_store);
277static DEVICE_ATTR(gamma, S_IRUGO | S_IWUSR,
278 tpo_td043_gamma_show, tpo_td043_gamma_store);
279
280static struct attribute *tpo_td043_attrs[] = {
281 &dev_attr_vmirror.attr,
282 &dev_attr_mode.attr,
283 &dev_attr_gamma.attr,
284 NULL,
285};
286
287static struct attribute_group tpo_td043_attr_group = {
288 .attrs = tpo_td043_attrs,
289};
290
291static int tpo_td043_power_on(struct panel_drv_data *ddata)
292{
293 int r;
294
295 if (ddata->powered_on)
296 return 0;
297
298 r = regulator_enable(ddata->vcc_reg);
299 if (r != 0)
300 return r;
301
302 /* wait for panel to stabilize */
303 msleep(160);
304
305 if (gpio_is_valid(ddata->nreset_gpio))
306 gpio_set_value(ddata->nreset_gpio, 1);
307
308 tpo_td043_write(ddata->spi, 2,
309 TPO_R02_MODE(ddata->mode) | TPO_R02_NCLK_RISING);
310 tpo_td043_write(ddata->spi, 3, TPO_R03_VAL_NORMAL);
311 tpo_td043_write(ddata->spi, 0x20, 0xf0);
312 tpo_td043_write(ddata->spi, 0x21, 0xf0);
313 tpo_td043_write_mirror(ddata->spi, ddata->hmirror,
314 ddata->vmirror);
315 tpo_td043_write_gamma(ddata->spi, ddata->gamma);
316
317 ddata->powered_on = 1;
318 return 0;
319}
320
321static void tpo_td043_power_off(struct panel_drv_data *ddata)
322{
323 if (!ddata->powered_on)
324 return;
325
326 tpo_td043_write(ddata->spi, 3,
327 TPO_R03_VAL_STANDBY | TPO_R03_EN_PWM);
328
329 if (gpio_is_valid(ddata->nreset_gpio))
330 gpio_set_value(ddata->nreset_gpio, 0);
331
332 /* wait for at least 2 vsyncs before cutting off power */
333 msleep(50);
334
335 tpo_td043_write(ddata->spi, 3, TPO_R03_VAL_STANDBY);
336
337 regulator_disable(ddata->vcc_reg);
338
339 ddata->powered_on = 0;
340}
341
342static int tpo_td043_connect(struct omap_dss_device *dssdev)
343{
344 struct panel_drv_data *ddata = to_panel_data(dssdev);
345 struct omap_dss_device *in = ddata->in;
346 int r;
347
348 if (omapdss_device_is_connected(dssdev))
349 return 0;
350
351 r = in->ops.dpi->connect(in, dssdev);
352 if (r)
353 return r;
354
355 return 0;
356}
357
358static void tpo_td043_disconnect(struct omap_dss_device *dssdev)
359{
360 struct panel_drv_data *ddata = to_panel_data(dssdev);
361 struct omap_dss_device *in = ddata->in;
362
363 if (!omapdss_device_is_connected(dssdev))
364 return;
365
366 in->ops.dpi->disconnect(in, dssdev);
367}
368
369static int tpo_td043_enable(struct omap_dss_device *dssdev)
370{
371 struct panel_drv_data *ddata = to_panel_data(dssdev);
372 struct omap_dss_device *in = ddata->in;
373 int r;
374
375 if (!omapdss_device_is_connected(dssdev))
376 return -ENODEV;
377
378 if (omapdss_device_is_enabled(dssdev))
379 return 0;
380
Tomi Valkeinen597cc1e2014-05-16 12:28:36 +0300381 if (ddata->data_lines)
382 in->ops.dpi->set_data_lines(in, ddata->data_lines);
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300383 in->ops.dpi->set_timings(in, &ddata->vm);
Tomi Valkeinen2e1def02013-05-31 13:13:44 +0300384
385 r = in->ops.dpi->enable(in);
386 if (r)
387 return r;
388
389 /*
390 * If we are resuming from system suspend, SPI clocks might not be
391 * enabled yet, so we'll program the LCD from SPI PM resume callback.
392 */
393 if (!ddata->spi_suspended) {
394 r = tpo_td043_power_on(ddata);
395 if (r) {
396 in->ops.dpi->disable(in);
397 return r;
398 }
399 }
400
401 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
402
403 return 0;
404}
405
406static void tpo_td043_disable(struct omap_dss_device *dssdev)
407{
408 struct panel_drv_data *ddata = to_panel_data(dssdev);
409 struct omap_dss_device *in = ddata->in;
410
411 if (!omapdss_device_is_enabled(dssdev))
412 return;
413
414 in->ops.dpi->disable(in);
415
416 if (!ddata->spi_suspended)
417 tpo_td043_power_off(ddata);
418
419 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
420}
421
422static void tpo_td043_set_timings(struct omap_dss_device *dssdev,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300423 struct videomode *vm)
Tomi Valkeinen2e1def02013-05-31 13:13:44 +0300424{
425 struct panel_drv_data *ddata = to_panel_data(dssdev);
426 struct omap_dss_device *in = ddata->in;
427
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300428 ddata->vm = *vm;
429 dssdev->panel.vm = *vm;
Tomi Valkeinen2e1def02013-05-31 13:13:44 +0300430
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300431 in->ops.dpi->set_timings(in, vm);
Tomi Valkeinen2e1def02013-05-31 13:13:44 +0300432}
433
434static void tpo_td043_get_timings(struct omap_dss_device *dssdev,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300435 struct videomode *vm)
Tomi Valkeinen2e1def02013-05-31 13:13:44 +0300436{
437 struct panel_drv_data *ddata = to_panel_data(dssdev);
438
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300439 *vm = ddata->vm;
Tomi Valkeinen2e1def02013-05-31 13:13:44 +0300440}
441
442static int tpo_td043_check_timings(struct omap_dss_device *dssdev,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300443 struct videomode *vm)
Tomi Valkeinen2e1def02013-05-31 13:13:44 +0300444{
445 struct panel_drv_data *ddata = to_panel_data(dssdev);
446 struct omap_dss_device *in = ddata->in;
447
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300448 return in->ops.dpi->check_timings(in, vm);
Tomi Valkeinen2e1def02013-05-31 13:13:44 +0300449}
450
451static struct omap_dss_driver tpo_td043_ops = {
452 .connect = tpo_td043_connect,
453 .disconnect = tpo_td043_disconnect,
454
455 .enable = tpo_td043_enable,
456 .disable = tpo_td043_disable,
457
458 .set_timings = tpo_td043_set_timings,
459 .get_timings = tpo_td043_get_timings,
460 .check_timings = tpo_td043_check_timings,
461
462 .set_mirror = tpo_td043_set_hmirror,
463 .get_mirror = tpo_td043_get_hmirror,
464
465 .get_resolution = omapdss_default_get_resolution,
466};
467
Tomi Valkeinen597cc1e2014-05-16 12:28:36 +0300468static int tpo_td043_probe_of(struct spi_device *spi)
469{
470 struct device_node *node = spi->dev.of_node;
471 struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
472 struct omap_dss_device *in;
473 int gpio;
474
475 gpio = of_get_named_gpio(node, "reset-gpios", 0);
476 if (!gpio_is_valid(gpio)) {
477 dev_err(&spi->dev, "failed to parse enable gpio\n");
478 return gpio;
479 }
480 ddata->nreset_gpio = gpio;
481
482 in = omapdss_of_find_source_for_first_ep(node);
483 if (IS_ERR(in)) {
484 dev_err(&spi->dev, "failed to find video source\n");
485 return PTR_ERR(in);
486 }
487
488 ddata->in = in;
489
490 return 0;
491}
492
Tomi Valkeinen2e1def02013-05-31 13:13:44 +0300493static int tpo_td043_probe(struct spi_device *spi)
494{
495 struct panel_drv_data *ddata;
496 struct omap_dss_device *dssdev;
497 int r;
498
499 dev_dbg(&spi->dev, "%s\n", __func__);
500
501 spi->bits_per_word = 16;
502 spi->mode = SPI_MODE_0;
503
504 r = spi_setup(spi);
505 if (r < 0) {
506 dev_err(&spi->dev, "spi_setup failed: %d\n", r);
507 return r;
508 }
509
510 ddata = devm_kzalloc(&spi->dev, sizeof(*ddata), GFP_KERNEL);
511 if (ddata == NULL)
512 return -ENOMEM;
513
514 dev_set_drvdata(&spi->dev, ddata);
515
516 ddata->spi = spi;
517
Tomi Valkeinen33c06b62016-02-22 18:14:52 +0200518 if (!spi->dev.of_node)
Tomi Valkeinen2e1def02013-05-31 13:13:44 +0300519 return -ENODEV;
Tomi Valkeinen33c06b62016-02-22 18:14:52 +0200520
521 r = tpo_td043_probe_of(spi);
522 if (r)
523 return r;
Tomi Valkeinen2e1def02013-05-31 13:13:44 +0300524
525 ddata->mode = TPO_R02_MODE_800x480;
526 memcpy(ddata->gamma, tpo_td043_def_gamma, sizeof(ddata->gamma));
527
528 ddata->vcc_reg = devm_regulator_get(&spi->dev, "vcc");
529 if (IS_ERR(ddata->vcc_reg)) {
530 dev_err(&spi->dev, "failed to get LCD VCC regulator\n");
531 r = PTR_ERR(ddata->vcc_reg);
532 goto err_regulator;
533 }
534
535 if (gpio_is_valid(ddata->nreset_gpio)) {
536 r = devm_gpio_request_one(&spi->dev,
537 ddata->nreset_gpio, GPIOF_OUT_INIT_LOW,
538 "lcd reset");
539 if (r < 0) {
540 dev_err(&spi->dev, "couldn't request reset GPIO\n");
541 goto err_gpio_req;
542 }
543 }
544
545 r = sysfs_create_group(&spi->dev.kobj, &tpo_td043_attr_group);
546 if (r) {
547 dev_err(&spi->dev, "failed to create sysfs files\n");
548 goto err_sysfs;
549 }
550
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300551 ddata->vm = tpo_td043_vm;
Tomi Valkeinen2e1def02013-05-31 13:13:44 +0300552
553 dssdev = &ddata->dssdev;
554 dssdev->dev = &spi->dev;
555 dssdev->driver = &tpo_td043_ops;
556 dssdev->type = OMAP_DISPLAY_TYPE_DPI;
557 dssdev->owner = THIS_MODULE;
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300558 dssdev->panel.vm = ddata->vm;
Tomi Valkeinen2e1def02013-05-31 13:13:44 +0300559
560 r = omapdss_register_display(dssdev);
561 if (r) {
562 dev_err(&spi->dev, "Failed to register panel\n");
563 goto err_reg;
564 }
565
566 return 0;
567
568err_reg:
569 sysfs_remove_group(&spi->dev.kobj, &tpo_td043_attr_group);
570err_sysfs:
571err_gpio_req:
572err_regulator:
573 omap_dss_put_device(ddata->in);
574 return r;
575}
576
577static int tpo_td043_remove(struct spi_device *spi)
578{
579 struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
580 struct omap_dss_device *dssdev = &ddata->dssdev;
581 struct omap_dss_device *in = ddata->in;
582
583 dev_dbg(&ddata->spi->dev, "%s\n", __func__);
584
585 omapdss_unregister_display(dssdev);
586
587 tpo_td043_disable(dssdev);
588 tpo_td043_disconnect(dssdev);
589
590 omap_dss_put_device(in);
591
592 sysfs_remove_group(&spi->dev.kobj, &tpo_td043_attr_group);
593
594 return 0;
595}
596
597#ifdef CONFIG_PM_SLEEP
598static int tpo_td043_spi_suspend(struct device *dev)
599{
600 struct panel_drv_data *ddata = dev_get_drvdata(dev);
601
602 dev_dbg(dev, "tpo_td043_spi_suspend, tpo %p\n", ddata);
603
604 ddata->power_on_resume = ddata->powered_on;
605 tpo_td043_power_off(ddata);
606 ddata->spi_suspended = 1;
607
608 return 0;
609}
610
611static int tpo_td043_spi_resume(struct device *dev)
612{
613 struct panel_drv_data *ddata = dev_get_drvdata(dev);
614 int ret;
615
616 dev_dbg(dev, "tpo_td043_spi_resume\n");
617
618 if (ddata->power_on_resume) {
619 ret = tpo_td043_power_on(ddata);
620 if (ret)
621 return ret;
622 }
623 ddata->spi_suspended = 0;
624
625 return 0;
626}
627#endif
628
629static SIMPLE_DEV_PM_OPS(tpo_td043_spi_pm,
630 tpo_td043_spi_suspend, tpo_td043_spi_resume);
631
Tomi Valkeinen597cc1e2014-05-16 12:28:36 +0300632static const struct of_device_id tpo_td043_of_match[] = {
633 { .compatible = "omapdss,tpo,td043mtea1", },
634 {},
635};
636
637MODULE_DEVICE_TABLE(of, tpo_td043_of_match);
638
Tomi Valkeinen2e1def02013-05-31 13:13:44 +0300639static struct spi_driver tpo_td043_spi_driver = {
640 .driver = {
641 .name = "panel-tpo-td043mtea1",
Tomi Valkeinen2e1def02013-05-31 13:13:44 +0300642 .pm = &tpo_td043_spi_pm,
Tomi Valkeinen597cc1e2014-05-16 12:28:36 +0300643 .of_match_table = tpo_td043_of_match,
Tomi Valkeinen422ccbd2014-10-16 09:54:25 +0300644 .suppress_bind_attrs = true,
Tomi Valkeinen2e1def02013-05-31 13:13:44 +0300645 },
646 .probe = tpo_td043_probe,
647 .remove = tpo_td043_remove,
648};
649
650module_spi_driver(tpo_td043_spi_driver);
651
Tomi Valkeinen597cc1e2014-05-16 12:28:36 +0300652MODULE_ALIAS("spi:tpo,td043mtea1");
Tomi Valkeinen2e1def02013-05-31 13:13:44 +0300653MODULE_AUTHOR("Gražvydas Ignotas <notasas@gmail.com>");
654MODULE_DESCRIPTION("TPO TD043MTEA1 LCD Driver");
655MODULE_LICENSE("GPL");