12 #include <linux/module.h>
18 #include <linux/slab.h>
22 #define TPO_R02_MODE(x) ((x) & 7)
23 #define TPO_R02_MODE_800x480 7
24 #define TPO_R02_NCLK_RISING BIT(3)
25 #define TPO_R02_HSYNC_HIGH BIT(4)
26 #define TPO_R02_VSYNC_HIGH BIT(5)
28 #define TPO_R03_NSTANDBY BIT(0)
29 #define TPO_R03_EN_CP_CLK BIT(1)
30 #define TPO_R03_EN_VGL_PUMP BIT(2)
31 #define TPO_R03_EN_PWM BIT(3)
32 #define TPO_R03_DRIVING_CAP_100 BIT(4)
33 #define TPO_R03_EN_PRE_CHARGE BIT(6)
34 #define TPO_R03_SOFTWARE_CTL BIT(7)
36 #define TPO_R04_NFLIP_H BIT(0)
37 #define TPO_R04_NFLIP_V BIT(1)
38 #define TPO_R04_CP_CLK_FREQ_1H BIT(2)
39 #define TPO_R04_VGL_FREQ_1H BIT(4)
41 #define TPO_R03_VAL_NORMAL (TPO_R03_NSTANDBY | TPO_R03_EN_CP_CLK | \
42 TPO_R03_EN_VGL_PUMP | TPO_R03_EN_PWM | \
43 TPO_R03_DRIVING_CAP_100 | TPO_R03_EN_PRE_CHARGE | \
46 #define TPO_R03_VAL_STANDBY (TPO_R03_DRIVING_CAP_100 | \
47 TPO_R03_EN_PRE_CHARGE | TPO_R03_SOFTWARE_CTL)
49 static const u16 tpo_td043_def_gamma[12] = {
50 105, 315, 381, 431, 490, 537, 579, 686, 780, 837, 880, 1023
75 memset(&xfer, 0,
sizeof(xfer));
77 w = ((
u16)addr << 10) | (1 << 8) | data;
81 spi_message_add_tail(&xfer, &m);
85 dev_warn(&spi->
dev,
"failed to write to LCD reg (%d)\n", r);
94 for (val = i = 0; i < 4; i++)
95 val |= (gamma[i] & 0x300) >> ((i + 1) * 2);
96 tpo_td043_write(spi, 0x11, val);
98 for (val = i = 0; i < 4; i++)
99 val |= (gamma[i+4] & 0x300) >> ((i + 1) * 2);
100 tpo_td043_write(spi, 0x12, val);
102 for (val = i = 0; i < 4; i++)
103 val |= (gamma[i+8] & 0x300) >> ((i + 1) * 2);
104 tpo_td043_write(spi, 0x13, val);
107 for (val = i = 0; i < 12; i++)
108 tpo_td043_write(spi, 0x14 + i, gamma[i] & 0xff);
111 static int tpo_td043_write_mirror(
struct spi_device *spi,
bool h,
bool v)
120 return tpo_td043_write(spi, 4, reg4);
128 return tpo_td043_write_mirror(tpo_td043->
spi, tpo_td043->
hmirror,
160 ret = tpo_td043_write_mirror(tpo_td043->
spi, tpo_td043->
hmirror, val);
184 ret = kstrtol(buf, 0, &val);
185 if (ret != 0 || val & ~7)
191 tpo_td043_write(tpo_td043->
spi, 2, val);
206 tpo_td043->
gamma[i]);
224 ret =
sscanf(buf,
"%u %u %u %u %u %u %u %u %u %u %u %u",
225 &g[0], &g[1], &g[2], &g[3], &g[4], &g[5],
226 &g[6], &g[7], &g[8], &g[9], &g[10], &g[11]);
231 for (i = 0; i < 12; i++)
232 tpo_td043->
gamma[i] = g[i];
234 tpo_td043_write_gamma(tpo_td043->
spi, tpo_td043->
gamma);
240 tpo_td043_vmirror_show, tpo_td043_vmirror_store);
242 tpo_td043_mode_show, tpo_td043_mode_store);
244 tpo_td043_gamma_show, tpo_td043_gamma_store);
246 static struct attribute *tpo_td043_attrs[] = {
247 &dev_attr_vmirror.attr,
249 &dev_attr_gamma.attr,
254 .attrs = tpo_td043_attrs,
261 .pixel_clock = 36000,
293 if (gpio_is_valid(nreset_gpio))
296 tpo_td043_write(tpo_td043->
spi, 2,
299 tpo_td043_write(tpo_td043->
spi, 0x20, 0xf0);
300 tpo_td043_write(tpo_td043->
spi, 0x21, 0xf0);
301 tpo_td043_write_mirror(tpo_td043->
spi, tpo_td043->
hmirror,
303 tpo_td043_write_gamma(tpo_td043->
spi, tpo_td043->
gamma);
316 tpo_td043_write(tpo_td043->
spi, 3,
319 if (gpio_is_valid(nreset_gpio))
358 r = tpo_td043_power_on(tpo_td043);
385 tpo_td043_power_off(tpo_td043);
392 return tpo_td043_enable_dss(dssdev);
399 tpo_td043_disable_dss(dssdev);
408 tpo_td043_disable_dss(dssdev);
419 return tpo_td043_enable_dss(dssdev);
430 if (tpo_td043 ==
NULL) {
431 dev_err(&dssdev->
dev,
"missing tpo_td043_device\n");
435 dssdev->
panel.timings = tpo_td043_timings;
436 dssdev->
ctrl.pixel_size = 24;
442 if (IS_ERR(tpo_td043->
vcc_reg)) {
443 dev_err(&dssdev->
dev,
"failed to get LCD VCC regulator\n");
444 ret = PTR_ERR(tpo_td043->
vcc_reg);
448 if (gpio_is_valid(nreset_gpio)) {
452 dev_err(&dssdev->
dev,
"couldn't request reset GPIO\n");
459 dev_warn(&dssdev->
dev,
"failed to create sysfs files\n");
479 if (gpio_is_valid(nreset_gpio))
488 dssdev->
panel.timings = *timings;
498 .probe = tpo_td043_probe,
499 .remove = tpo_td043_remove,
501 .enable = tpo_td043_enable,
502 .disable = tpo_td043_disable,
503 .suspend = tpo_td043_suspend,
504 .resume = tpo_td043_resume,
505 .set_mirror = tpo_td043_set_hmirror,
506 .get_mirror = tpo_td043_get_hmirror,
508 .set_timings = tpo_td043_set_timings,
509 .check_timings = tpo_td043_check_timings,
512 .name =
"tpo_td043mtea1_panel",
517 static int tpo_td043_spi_probe(
struct spi_device *spi)
523 if (dssdev ==
NULL) {
533 dev_err(&spi->
dev,
"spi_setup failed: %d\n", ret);
537 tpo_td043 = kzalloc(
sizeof(*tpo_td043),
GFP_KERNEL);
538 if (tpo_td043 ==
NULL)
561 #ifdef CONFIG_PM_SLEEP
562 static int tpo_td043_spi_suspend(
struct device *dev)
566 dev_dbg(dev,
"tpo_td043_spi_suspend, tpo %p\n", tpo_td043);
569 tpo_td043_power_off(tpo_td043);
575 static int tpo_td043_spi_resume(
struct device *dev)
580 dev_dbg(dev,
"tpo_td043_spi_resume\n");
583 ret = tpo_td043_power_on(tpo_td043);
594 tpo_td043_spi_suspend, tpo_td043_spi_resume);
596 static struct spi_driver tpo_td043_spi_driver = {
598 .name =
"tpo_td043mtea1_panel_spi",
600 .pm = &tpo_td043_spi_pm,
602 .probe = tpo_td043_spi_probe,