1 /* Linux kernel driver for the tpo JBT6K74-AS LCM ASIC
3 * Copyright (C) 2006-2007 by Openmoko, Inc.
4 * Author: Harald Welte <laforge@openmoko.org>,
5 * Stefan Schmidt <stefan@openmoko.org>
6 * Copyright (C) 2008 by Harald Welte <laforge@openmoko.org>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 #include <linux/kernel.h>
27 #include <linux/types.h>
28 #include <linux/module.h>
29 #include <linux/device.h>
30 #include <linux/platform_device.h>
31 #include <linux/delay.h>
32 #include <linux/jbt6k74.h>
36 JBT_REG_SLEEP_IN = 0x10,
37 JBT_REG_SLEEP_OUT = 0x11,
39 JBT_REG_DISPLAY_OFF = 0x28,
40 JBT_REG_DISPLAY_ON = 0x29,
42 JBT_REG_RGB_FORMAT = 0x3a,
43 JBT_REG_QUAD_RATE = 0x3b,
45 JBT_REG_POWER_ON_OFF = 0xb0,
46 JBT_REG_BOOSTER_OP = 0xb1,
47 JBT_REG_BOOSTER_MODE = 0xb2,
48 JBT_REG_BOOSTER_FREQ = 0xb3,
49 JBT_REG_OPAMP_SYSCLK = 0xb4,
50 JBT_REG_VSC_VOLTAGE = 0xb5,
51 JBT_REG_VCOM_VOLTAGE = 0xb6,
52 JBT_REG_EXT_DISPL = 0xb7,
53 JBT_REG_OUTPUT_CONTROL = 0xb8,
54 JBT_REG_DCCLK_DCEV = 0xb9,
55 JBT_REG_DISPLAY_MODE1 = 0xba,
56 JBT_REG_DISPLAY_MODE2 = 0xbb,
57 JBT_REG_DISPLAY_MODE = 0xbc,
58 JBT_REG_ASW_SLEW = 0xbd,
59 JBT_REG_DUMMY_DISPLAY = 0xbe,
60 JBT_REG_DRIVE_SYSTEM = 0xbf,
62 JBT_REG_SLEEP_OUT_FR_A = 0xc0,
63 JBT_REG_SLEEP_OUT_FR_B = 0xc1,
64 JBT_REG_SLEEP_OUT_FR_C = 0xc2,
65 JBT_REG_SLEEP_IN_LCCNT_D = 0xc3,
66 JBT_REG_SLEEP_IN_LCCNT_E = 0xc4,
67 JBT_REG_SLEEP_IN_LCCNT_F = 0xc5,
68 JBT_REG_SLEEP_IN_LCCNT_G = 0xc6,
70 JBT_REG_GAMMA1_FINE_1 = 0xc7,
71 JBT_REG_GAMMA1_FINE_2 = 0xc8,
72 JBT_REG_GAMMA1_INCLINATION = 0xc9,
73 JBT_REG_GAMMA1_BLUE_OFFSET = 0xca,
76 JBT_REG_BLANK_CONTROL = 0xcf,
77 JBT_REG_BLANK_TH_TV = 0xd0,
78 JBT_REG_CKV_ON_OFF = 0xd1,
79 JBT_REG_CKV_1_2 = 0xd2,
80 JBT_REG_OEV_TIMING = 0xd3,
81 JBT_REG_ASW_TIMING_1 = 0xd4,
82 JBT_REG_ASW_TIMING_2 = 0xd5,
85 JBT_REG_BLANK_CONTROL_QVGA = 0xd6,
86 JBT_REG_BLANK_TH_TV_QVGA = 0xd7,
87 JBT_REG_CKV_ON_OFF_QVGA = 0xd8,
88 JBT_REG_CKV_1_2_QVGA = 0xd9,
89 JBT_REG_OEV_TIMING_QVGA = 0xde,
90 JBT_REG_ASW_TIMING_1_QVGA = 0xdf,
91 JBT_REG_ASW_TIMING_2_QVGA = 0xe0,
94 JBT_REG_HCLOCK_VGA = 0xec,
95 JBT_REG_HCLOCK_QVGA = 0xed,
100 JBT_STATE_DEEP_STANDBY,
103 JBT_STATE_QVGA_NORMAL,
106 static const char *jbt_state_names[] = {
107 [JBT_STATE_DEEP_STANDBY] = "deep-standby",
108 [JBT_STATE_SLEEP] = "sleep",
109 [JBT_STATE_NORMAL] = "normal",
110 [JBT_STATE_QVGA_NORMAL] = "qvga-normal",
114 enum jbt_state state, last_state;
115 struct spi_device *spi_dev;
116 struct mutex lock; /* protects tx_buf and reg_cache */
117 struct notifier_block fb_notif;
123 #define JBT_COMMAND 0x000
124 #define JBT_DATA 0x100
127 static int jbt_reg_write_nodata(struct jbt_info *jbt, u8 reg)
131 mutex_lock(&jbt->lock);
133 jbt->tx_buf[0] = JBT_COMMAND | reg;
134 rc = spi_write(jbt->spi_dev, (u8 *)jbt->tx_buf,
137 jbt->reg_cache[reg] = 0;
139 printk(KERN_ERR"jbt_reg_write_nodata spi_write ret %d\n",
142 mutex_unlock(&jbt->lock);
148 static int jbt_reg_write(struct jbt_info *jbt, u8 reg, u8 data)
152 mutex_lock(&jbt->lock);
154 jbt->tx_buf[0] = JBT_COMMAND | reg;
155 jbt->tx_buf[1] = JBT_DATA | data;
156 rc = spi_write(jbt->spi_dev, (u8 *)jbt->tx_buf,
159 jbt->reg_cache[reg] = data;
161 printk(KERN_ERR"jbt_reg_write spi_write ret %d\n", rc);
163 mutex_unlock(&jbt->lock);
168 static int jbt_reg_write16(struct jbt_info *jbt, u8 reg, u16 data)
172 mutex_lock(&jbt->lock);
174 jbt->tx_buf[0] = JBT_COMMAND | reg;
175 jbt->tx_buf[1] = JBT_DATA | (data >> 8);
176 jbt->tx_buf[2] = JBT_DATA | (data & 0xff);
178 rc = spi_write(jbt->spi_dev, (u8 *)jbt->tx_buf,
181 jbt->reg_cache[reg] = data;
183 printk(KERN_ERR"jbt_reg_write16 spi_write ret %d\n", rc);
185 mutex_unlock(&jbt->lock);
190 static int jbt_init_regs(struct jbt_info *jbt, int qvga)
194 dev_dbg(&jbt->spi_dev->dev, "entering %cVGA mode\n", qvga ? 'Q' : ' ');
196 rc = jbt_reg_write(jbt, JBT_REG_DISPLAY_MODE1, 0x01);
197 rc |= jbt_reg_write(jbt, JBT_REG_DISPLAY_MODE2, 0x00);
198 rc |= jbt_reg_write(jbt, JBT_REG_RGB_FORMAT, 0x60);
199 rc |= jbt_reg_write(jbt, JBT_REG_DRIVE_SYSTEM, 0x10);
200 rc |= jbt_reg_write(jbt, JBT_REG_BOOSTER_OP, 0x56);
201 rc |= jbt_reg_write(jbt, JBT_REG_BOOSTER_MODE, 0x33);
202 rc |= jbt_reg_write(jbt, JBT_REG_BOOSTER_FREQ, 0x11);
203 rc |= jbt_reg_write(jbt, JBT_REG_OPAMP_SYSCLK, 0x02);
204 rc |= jbt_reg_write(jbt, JBT_REG_VSC_VOLTAGE, 0x2b);
205 rc |= jbt_reg_write(jbt, JBT_REG_VCOM_VOLTAGE, 0x40);
206 rc |= jbt_reg_write(jbt, JBT_REG_EXT_DISPL, 0x03);
207 rc |= jbt_reg_write(jbt, JBT_REG_DCCLK_DCEV, 0x04);
209 * default of 0x02 in JBT_REG_ASW_SLEW responsible for 72Hz requirement
210 * to avoid red / blue flicker
212 rc |= jbt_reg_write(jbt, JBT_REG_ASW_SLEW, 0x04);
213 rc |= jbt_reg_write(jbt, JBT_REG_DUMMY_DISPLAY, 0x00);
215 rc |= jbt_reg_write(jbt, JBT_REG_SLEEP_OUT_FR_A, 0x11);
216 rc |= jbt_reg_write(jbt, JBT_REG_SLEEP_OUT_FR_B, 0x11);
217 rc |= jbt_reg_write(jbt, JBT_REG_SLEEP_OUT_FR_C, 0x11);
218 rc |= jbt_reg_write16(jbt, JBT_REG_SLEEP_IN_LCCNT_D, 0x2040);
219 rc |= jbt_reg_write16(jbt, JBT_REG_SLEEP_IN_LCCNT_E, 0x60c0);
220 rc |= jbt_reg_write16(jbt, JBT_REG_SLEEP_IN_LCCNT_F, 0x1020);
221 rc |= jbt_reg_write16(jbt, JBT_REG_SLEEP_IN_LCCNT_G, 0x60c0);
223 rc |= jbt_reg_write16(jbt, JBT_REG_GAMMA1_FINE_1, 0x5533);
224 rc |= jbt_reg_write(jbt, JBT_REG_GAMMA1_FINE_2, 0x00);
225 rc |= jbt_reg_write(jbt, JBT_REG_GAMMA1_INCLINATION, 0x00);
226 rc |= jbt_reg_write(jbt, JBT_REG_GAMMA1_BLUE_OFFSET, 0x00);
229 rc |= jbt_reg_write16(jbt, JBT_REG_HCLOCK_VGA, 0x1f0);
230 rc |= jbt_reg_write(jbt, JBT_REG_BLANK_CONTROL, 0x02);
231 rc |= jbt_reg_write16(jbt, JBT_REG_BLANK_TH_TV, 0x0804);
233 rc |= jbt_reg_write(jbt, JBT_REG_CKV_ON_OFF, 0x01);
234 rc |= jbt_reg_write16(jbt, JBT_REG_CKV_1_2, 0x0000);
236 rc |= jbt_reg_write16(jbt, JBT_REG_OEV_TIMING, 0x0d0e);
237 rc |= jbt_reg_write16(jbt, JBT_REG_ASW_TIMING_1, 0x11a4);
238 rc |= jbt_reg_write(jbt, JBT_REG_ASW_TIMING_2, 0x0e);
240 rc |= jbt_reg_write16(jbt, JBT_REG_HCLOCK_QVGA, 0x00ff);
241 rc |= jbt_reg_write(jbt, JBT_REG_BLANK_CONTROL_QVGA, 0x02);
242 rc |= jbt_reg_write16(jbt, JBT_REG_BLANK_TH_TV_QVGA, 0x0804);
244 rc |= jbt_reg_write(jbt, JBT_REG_CKV_ON_OFF_QVGA, 0x01);
245 rc |= jbt_reg_write16(jbt, JBT_REG_CKV_1_2_QVGA, 0x0008);
247 rc |= jbt_reg_write16(jbt, JBT_REG_OEV_TIMING_QVGA, 0x050a);
248 rc |= jbt_reg_write16(jbt, JBT_REG_ASW_TIMING_1_QVGA, 0x0a19);
249 rc |= jbt_reg_write(jbt, JBT_REG_ASW_TIMING_2_QVGA, 0x0a);
252 return rc ? -EIO : 0;
255 int jbt6k74_display_onoff(struct jbt_info *jbt, int on)
258 return jbt_reg_write_nodata(jbt, JBT_REG_DISPLAY_ON);
260 return jbt_reg_write_nodata(jbt, JBT_REG_DISPLAY_OFF);
262 EXPORT_SYMBOL_GPL(jbt6k74_display_onoff);
264 static int standby_to_sleep(struct jbt_info *jbt)
270 /* three times command zero */
271 rc = jbt_reg_write_nodata(jbt, 0x00);
273 rc |= jbt_reg_write_nodata(jbt, 0x00);
275 rc |= jbt_reg_write_nodata(jbt, 0x00);
278 /* deep standby out */
279 rc |= jbt_reg_write(jbt, JBT_REG_POWER_ON_OFF, 0x17);
281 return rc ? -EIO : 0;
287 static int sleep_to_normal(struct jbt_info *jbt)
291 /* RGB I/F on, RAM wirte off, QVGA through, SIGCON enable */
292 rc = jbt_reg_write(jbt, JBT_REG_DISPLAY_MODE, 0x80);
295 rc |= jbt_reg_write(jbt, JBT_REG_QUAD_RATE, 0x00);
297 /* AVDD on, XVDD on */
298 rc |= jbt_reg_write(jbt, JBT_REG_POWER_ON_OFF, 0x16);
301 rc |= jbt_reg_write16(jbt, JBT_REG_OUTPUT_CONTROL, 0xfff9);
304 rc |= jbt_reg_write_nodata(jbt, JBT_REG_SLEEP_OUT);
306 /* initialize register set */
307 rc |= jbt_init_regs(jbt, 0);
309 /* Turn on display */
310 rc |= jbt6k74_display_onoff(jbt, 1);
312 return rc ? -EIO : 0;
315 static int sleep_to_qvga_normal(struct jbt_info *jbt)
319 /* RGB I/F on, RAM wirte off, QVGA through, SIGCON enable */
320 rc = jbt_reg_write(jbt, JBT_REG_DISPLAY_MODE, 0x81);
323 rc |= jbt_reg_write(jbt, JBT_REG_QUAD_RATE, 0x22);
325 /* AVDD on, XVDD on */
326 rc |= jbt_reg_write(jbt, JBT_REG_POWER_ON_OFF, 0x16);
329 rc |= jbt_reg_write16(jbt, JBT_REG_OUTPUT_CONTROL, 0xfff9);
332 rc |= jbt_reg_write_nodata(jbt, JBT_REG_SLEEP_OUT);
334 /* initialize register set for qvga*/
335 rc |= jbt_init_regs(jbt, 1);
337 /* Turn on display */
338 rc |= jbt6k74_display_onoff(jbt, 1);
340 return rc ? -EIO : 0;
343 static int normal_to_sleep(struct jbt_info *jbt)
347 rc = jbt6k74_display_onoff(jbt, 0);
348 rc |= jbt_reg_write_nodata(jbt, JBT_REG_DISPLAY_OFF);
349 rc |= jbt_reg_write16(jbt, JBT_REG_OUTPUT_CONTROL, 0x8002);
350 rc |= jbt_reg_write_nodata(jbt, JBT_REG_SLEEP_IN);
352 return rc ? -EIO : 0;
355 static int sleep_to_standby(struct jbt_info *jbt)
358 return jbt_reg_write(jbt, JBT_REG_POWER_ON_OFF, 0x00);
364 /* frontend function */
365 int jbt6k74_enter_state(struct jbt_info *jbt, enum jbt_state new_state)
369 dev_dbg(&jbt->spi_dev->dev, "entering (old_state=%u, "
370 "new_state=%u)\n", jbt->state, new_state);
372 switch (jbt->state) {
373 case JBT_STATE_DEEP_STANDBY:
375 case JBT_STATE_DEEP_STANDBY:
378 case JBT_STATE_SLEEP:
379 rc = standby_to_sleep(jbt);
381 case JBT_STATE_NORMAL:
382 /* first transition into sleep */
383 rc = standby_to_sleep(jbt);
384 /* then transition into normal */
385 rc |= sleep_to_normal(jbt);
387 case JBT_STATE_QVGA_NORMAL:
388 /* first transition into sleep */
389 rc = standby_to_sleep(jbt);
390 /* then transition into normal */
391 rc |= sleep_to_qvga_normal(jbt);
395 case JBT_STATE_SLEEP:
397 case JBT_STATE_SLEEP:
400 case JBT_STATE_DEEP_STANDBY:
401 rc = sleep_to_standby(jbt);
403 case JBT_STATE_NORMAL:
404 rc = sleep_to_normal(jbt);
406 case JBT_STATE_QVGA_NORMAL:
407 rc = sleep_to_qvga_normal(jbt);
411 case JBT_STATE_NORMAL:
413 case JBT_STATE_NORMAL:
416 case JBT_STATE_DEEP_STANDBY:
417 /* first transition into sleep */
418 rc = normal_to_sleep(jbt);
419 /* then transition into deep standby */
420 rc |= sleep_to_standby(jbt);
422 case JBT_STATE_SLEEP:
423 rc = normal_to_sleep(jbt);
425 case JBT_STATE_QVGA_NORMAL:
426 /* first transition into sleep */
427 rc = normal_to_sleep(jbt);
428 /* second transition into deep standby */
429 rc |= sleep_to_standby(jbt);
430 /* third transition into sleep */
431 rc |= standby_to_sleep(jbt);
432 /* fourth transition into normal */
433 rc |= sleep_to_qvga_normal(jbt);
437 case JBT_STATE_QVGA_NORMAL:
439 case JBT_STATE_QVGA_NORMAL:
442 case JBT_STATE_DEEP_STANDBY:
443 /* first transition into sleep */
444 rc = normal_to_sleep(jbt);
445 /* then transition into deep standby */
446 rc |= sleep_to_standby(jbt);
448 case JBT_STATE_SLEEP:
449 rc = normal_to_sleep(jbt);
451 case JBT_STATE_NORMAL:
452 /* first transition into sleep */
453 rc = normal_to_sleep(jbt);
454 /* second transition into deep standby */
455 rc |= sleep_to_standby(jbt);
456 /* third transition into sleep */
457 rc |= standby_to_sleep(jbt);
458 /* fourth transition into normal */
459 rc |= sleep_to_normal(jbt);
466 jbt->state = new_state;
470 EXPORT_SYMBOL_GPL(jbt6k74_enter_state);
472 static ssize_t state_read(struct device *dev, struct device_attribute *attr,
475 struct jbt_info *jbt = dev_get_drvdata(dev);
477 if (jbt->state >= ARRAY_SIZE(jbt_state_names))
480 return sprintf(buf, "%s\n", jbt_state_names[jbt->state]);
483 static ssize_t state_write(struct device *dev, struct device_attribute *attr,
484 const char *buf, size_t count)
486 struct jbt_info *jbt = dev_get_drvdata(dev);
489 for (i = 0; i < ARRAY_SIZE(jbt_state_names); i++) {
490 if (!strncmp(buf, jbt_state_names[i],
491 strlen(jbt_state_names[i]))) {
492 rc = jbt6k74_enter_state(jbt, i);
502 static DEVICE_ATTR(state, 0644, state_read, state_write);
504 static int reg_by_string(const char *name)
506 if (!strcmp(name, "gamma_fine1"))
507 return JBT_REG_GAMMA1_FINE_1;
508 else if (!strcmp(name, "gamma_fine2"))
509 return JBT_REG_GAMMA1_FINE_2;
510 else if (!strcmp(name, "gamma_inclination"))
511 return JBT_REG_GAMMA1_INCLINATION;
513 return JBT_REG_GAMMA1_BLUE_OFFSET;
516 static ssize_t gamma_read(struct device *dev, struct device_attribute *attr,
519 struct jbt_info *jbt = dev_get_drvdata(dev);
520 int reg = reg_by_string(attr->attr.name);
523 mutex_lock(&jbt->lock);
524 val = jbt->reg_cache[reg];
525 mutex_unlock(&jbt->lock);
527 return sprintf(buf, "0x%04x\n", val);
530 static ssize_t gamma_write(struct device *dev, struct device_attribute *attr,
531 const char *buf, size_t count)
533 struct jbt_info *jbt = dev_get_drvdata(dev);
534 int reg = reg_by_string(attr->attr.name);
535 unsigned long val = simple_strtoul(buf, NULL, 10);
537 dev_info(dev, "**** jbt6k74 writing gama %lu\n", val & 0xff);
539 jbt_reg_write(jbt, reg, val & 0xff);
544 static ssize_t reset_write(struct device *dev, struct device_attribute *attr,
545 const char *buf, size_t count)
547 struct jbt_info *jbt = dev_get_drvdata(dev);
548 struct jbt6k74_platform_data *jbt6k74_pdata = jbt->spi_dev->dev.platform_data;
551 dev_info(dev, "**** jbt6k74 reset\n");
553 /* hard reset the jbt6k74 */
555 (jbt6k74_pdata->reset)(0, 0);
557 (jbt6k74_pdata->reset)(0, 1);
560 rc = jbt_reg_write_nodata(jbt, 0x01);
562 dev_err(dev, "cannot soft reset\n");
566 jbt->state = JBT_STATE_DEEP_STANDBY;
568 switch (jbt->last_state) {
569 case JBT_STATE_QVGA_NORMAL:
570 jbt6k74_enter_state(jbt, JBT_STATE_QVGA_NORMAL);
573 jbt6k74_enter_state(jbt, JBT_STATE_NORMAL);
577 rc = jbt6k74_display_onoff(jbt, 1);
579 dev_err(dev, "cannot switch display on\n");
584 static DEVICE_ATTR(gamma_fine1, 0644, gamma_read, gamma_write);
585 static DEVICE_ATTR(gamma_fine2, 0644, gamma_read, gamma_write);
586 static DEVICE_ATTR(gamma_inclination, 0644, gamma_read, gamma_write);
587 static DEVICE_ATTR(gamma_blue_offset, 0644, gamma_read, gamma_write);
588 static DEVICE_ATTR(reset, 0600, NULL, reset_write);
590 static struct attribute *jbt_sysfs_entries[] = {
591 &dev_attr_state.attr,
592 &dev_attr_gamma_fine1.attr,
593 &dev_attr_gamma_fine2.attr,
594 &dev_attr_gamma_inclination.attr,
595 &dev_attr_gamma_blue_offset.attr,
596 &dev_attr_reset.attr,
600 static struct attribute_group jbt_attr_group = {
602 .attrs = jbt_sysfs_entries,
605 static int fb_notifier_callback(struct notifier_block *self,
606 unsigned long event, void *data)
608 struct jbt_info *jbt;
609 struct fb_event *evdata = data;
612 if (event != FB_EVENT_BLANK && event != FB_EVENT_CONBLANK)
615 fb_blank = *(int *)evdata->data;
616 jbt = container_of(self, struct jbt_info, fb_notif);
619 case FB_BLANK_UNBLANK:
620 dev_info(&jbt->spi_dev->dev, "**** jbt6k74 unblank\n");
622 case FB_BLANK_NORMAL:
623 dev_info(&jbt->spi_dev->dev, "**** jbt6k74 normal\n");
624 /*jbt6k74_enter_state(jbt, JBT_STATE_NORMAL);
625 jbt6k74_display_onoff(jbt, 1); */
627 case FB_BLANK_VSYNC_SUSPEND:
628 dev_info(&jbt->spi_dev->dev, "**** jbt6k74 vsync suspend\n");
630 case FB_BLANK_HSYNC_SUSPEND:
631 dev_info(&jbt->spi_dev->dev, "**** jbt6k74 hsync suspend\n");
632 /* FIXME: we disable SLEEP since it would result in
633 * a visible artefact (white screen) before the backlight
634 * is dimmed to a dark enough level */
635 /* jbt6k74_enter_state(jbt, JBT_STATE_SLEEP); */
636 /*jbt6k74_display_onoff(jbt, 0);*/
638 case FB_BLANK_POWERDOWN:
639 dev_info(&jbt->spi_dev->dev, "**** jbt6k74 powerdown\n");
640 /*jbt6k74_enter_state(jbt, JBT_STATE_DEEP_STANDBY);*/
647 /* linux device model infrastructure */
649 static int __devinit jbt_probe(struct spi_device *spi)
652 struct jbt_info *jbt;
653 struct jbt6k74_platform_data *jbt6k74_pdata = spi->dev.platform_data;
655 /* the controller doesn't have a MISO pin; we can't do detection */
657 spi->mode = SPI_CPOL | SPI_CPHA;
658 spi->bits_per_word = 9;
663 "error during spi_setup of jbt6k74 driver\n");
667 jbt = kzalloc(sizeof(*jbt), GFP_KERNEL);
672 jbt->state = JBT_STATE_DEEP_STANDBY;
673 mutex_init(&jbt->lock);
675 dev_set_drvdata(&spi->dev, jbt);
677 /* hard reset the jbt6k74 */
679 (jbt6k74_pdata->reset)(0, 0);
681 (jbt6k74_pdata->reset)(0, 1);
684 rc = jbt_reg_write_nodata(jbt, 0x01);
686 dev_err(&spi->dev, "cannot soft reset\n");
691 rc = jbt6k74_enter_state(jbt, JBT_STATE_NORMAL);
693 dev_err(&spi->dev, "cannot enter NORMAL state\n");
694 goto err_free_drvdata;
697 rc = sysfs_create_group(&spi->dev.kobj, &jbt_attr_group);
699 dev_err(&spi->dev, "cannot create sysfs group\n");
703 jbt->fb_notif.notifier_call = fb_notifier_callback;
704 rc = fb_register_client(&jbt->fb_notif);
706 dev_err(&spi->dev, "cannot register notifier\n");
713 sysfs_remove_group(&spi->dev.kobj, &jbt_attr_group);
715 jbt6k74_enter_state(jbt, JBT_STATE_DEEP_STANDBY);
717 dev_set_drvdata(&spi->dev, NULL);
723 static int __devexit jbt_remove(struct spi_device *spi)
725 struct jbt_info *jbt = dev_get_drvdata(&spi->dev);
727 /* We don't want to switch off the display in case the user
728 * accidentially onloads the module (whose use count normally is 0) */
730 fb_unregister_client(&jbt->fb_notif);
731 sysfs_remove_group(&spi->dev.kobj, &jbt_attr_group);
732 dev_set_drvdata(&spi->dev, NULL);
739 static int jbt_suspend(struct spi_device *spi, pm_message_t state)
741 struct jbt_info *jbt = dev_get_drvdata(&spi->dev);
743 /* Save mode for resume */
744 jbt->last_state = jbt->state;
746 jbt6k74_enter_state(jbt, JBT_STATE_DEEP_STANDBY);
748 jbt->have_resumed = 0;
750 /* (jbt6k74_pdata->reset)(0, 0); */
752 dev_info(&spi->dev, "**** jbt6k74 suspend end\n");
757 int jbt6k74_resume(struct spi_device *spi)
759 struct jbt_info *jbt = dev_get_drvdata(&spi->dev);
760 struct jbt6k74_platform_data *jbt6k74_pdata = spi->dev.platform_data;
763 dev_info(&spi->dev, "**** jbt6k74 resume start\n");
765 /* hard reset the jbt6k74 */
767 (jbt6k74_pdata->reset)(0, 0);
769 (jbt6k74_pdata->reset)(0, 1);
772 rc = jbt_reg_write_nodata(jbt, 0x01);
774 dev_err(&spi->dev, "cannot soft reset\n");
778 jbt->state = JBT_STATE_DEEP_STANDBY;
780 switch (jbt->last_state) {
781 case JBT_STATE_QVGA_NORMAL:
782 jbt6k74_enter_state(jbt, JBT_STATE_QVGA_NORMAL);
785 jbt6k74_enter_state(jbt, JBT_STATE_NORMAL);
789 rc = jbt6k74_display_onoff(jbt, 1);
791 dev_err(&spi->dev, "cannot switch display on\n");
793 if (jbt6k74_pdata->resuming)
794 (jbt6k74_pdata->resuming)(0);
796 dev_info(&spi->dev, "**** jbt6k74 resume end\n");
800 EXPORT_SYMBOL_GPL(jbt6k74_resume);
803 #define jbt_suspend NULL
804 #define jbt_resume NULL
807 static struct spi_driver jbt6k74_driver = {
810 .owner = THIS_MODULE,
814 .remove = __devexit_p(jbt_remove),
815 .suspend = jbt_suspend,
816 .resume = jbt6k74_resume,
819 static int __init jbt_init(void)
821 return spi_register_driver(&jbt6k74_driver);
824 static void __exit jbt_exit(void)
826 spi_unregister_driver(&jbt6k74_driver);
829 MODULE_DESCRIPTION("SPI driver for tpo JBT6K74-AS LCM control interface");
830 MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
831 MODULE_LICENSE("GPL");
833 module_init(jbt_init);
834 module_exit(jbt_exit);