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>
34 #include <linux/time.h>
37 JBT_REG_SLEEP_IN = 0x10,
38 JBT_REG_SLEEP_OUT = 0x11,
40 JBT_REG_DISPLAY_OFF = 0x28,
41 JBT_REG_DISPLAY_ON = 0x29,
43 JBT_REG_RGB_FORMAT = 0x3a,
44 JBT_REG_QUAD_RATE = 0x3b,
46 JBT_REG_POWER_ON_OFF = 0xb0,
47 JBT_REG_BOOSTER_OP = 0xb1,
48 JBT_REG_BOOSTER_MODE = 0xb2,
49 JBT_REG_BOOSTER_FREQ = 0xb3,
50 JBT_REG_OPAMP_SYSCLK = 0xb4,
51 JBT_REG_VSC_VOLTAGE = 0xb5,
52 JBT_REG_VCOM_VOLTAGE = 0xb6,
53 JBT_REG_EXT_DISPL = 0xb7,
54 JBT_REG_OUTPUT_CONTROL = 0xb8,
55 JBT_REG_DCCLK_DCEV = 0xb9,
56 JBT_REG_DISPLAY_MODE1 = 0xba,
57 JBT_REG_DISPLAY_MODE2 = 0xbb,
58 JBT_REG_DISPLAY_MODE = 0xbc,
59 JBT_REG_ASW_SLEW = 0xbd,
60 JBT_REG_DUMMY_DISPLAY = 0xbe,
61 JBT_REG_DRIVE_SYSTEM = 0xbf,
63 JBT_REG_SLEEP_OUT_FR_A = 0xc0,
64 JBT_REG_SLEEP_OUT_FR_B = 0xc1,
65 JBT_REG_SLEEP_OUT_FR_C = 0xc2,
66 JBT_REG_SLEEP_IN_LCCNT_D = 0xc3,
67 JBT_REG_SLEEP_IN_LCCNT_E = 0xc4,
68 JBT_REG_SLEEP_IN_LCCNT_F = 0xc5,
69 JBT_REG_SLEEP_IN_LCCNT_G = 0xc6,
71 JBT_REG_GAMMA1_FINE_1 = 0xc7,
72 JBT_REG_GAMMA1_FINE_2 = 0xc8,
73 JBT_REG_GAMMA1_INCLINATION = 0xc9,
74 JBT_REG_GAMMA1_BLUE_OFFSET = 0xca,
77 JBT_REG_BLANK_CONTROL = 0xcf,
78 JBT_REG_BLANK_TH_TV = 0xd0,
79 JBT_REG_CKV_ON_OFF = 0xd1,
80 JBT_REG_CKV_1_2 = 0xd2,
81 JBT_REG_OEV_TIMING = 0xd3,
82 JBT_REG_ASW_TIMING_1 = 0xd4,
83 JBT_REG_ASW_TIMING_2 = 0xd5,
86 JBT_REG_BLANK_CONTROL_QVGA = 0xd6,
87 JBT_REG_BLANK_TH_TV_QVGA = 0xd7,
88 JBT_REG_CKV_ON_OFF_QVGA = 0xd8,
89 JBT_REG_CKV_1_2_QVGA = 0xd9,
90 JBT_REG_OEV_TIMING_QVGA = 0xde,
91 JBT_REG_ASW_TIMING_1_QVGA = 0xdf,
92 JBT_REG_ASW_TIMING_2_QVGA = 0xe0,
95 JBT_REG_HCLOCK_VGA = 0xec,
96 JBT_REG_HCLOCK_QVGA = 0xed,
101 JBT_STATE_DEEP_STANDBY,
104 JBT_STATE_QVGA_NORMAL,
107 static const char *jbt_state_names[] = {
108 [JBT_STATE_DEEP_STANDBY] = "deep-standby",
109 [JBT_STATE_SLEEP] = "sleep",
110 [JBT_STATE_NORMAL] = "normal",
111 [JBT_STATE_QVGA_NORMAL] = "qvga-normal",
115 enum jbt_state state, normal_state;
116 struct spi_device *spi_dev;
117 struct mutex lock; /* protects tx_buf and reg_cache */
118 struct notifier_block fb_notif;
121 struct timespec last_sleep;
124 #define JBT_COMMAND 0x000
125 #define JBT_DATA 0x100
127 static inline unsigned int timespec_sub_ms(struct timespec lhs,
130 struct timespec ts = timespec_sub(lhs, rhs);
131 return (ts.tv_sec * MSEC_PER_SEC) + (ts.tv_nsec / NSEC_PER_MSEC);
134 static int jbt_reg_write_nodata(struct jbt_info *jbt, u8 reg)
138 jbt->tx_buf[0] = JBT_COMMAND | reg;
139 rc = spi_write(jbt->spi_dev, (u8 *)jbt->tx_buf,
142 jbt->reg_cache[reg] = 0;
144 printk(KERN_ERR"jbt_reg_write_nodata spi_write ret %d\n",
151 static int jbt_reg_write(struct jbt_info *jbt, u8 reg, u8 data)
155 jbt->tx_buf[0] = JBT_COMMAND | reg;
156 jbt->tx_buf[1] = JBT_DATA | data;
157 rc = spi_write(jbt->spi_dev, (u8 *)jbt->tx_buf,
160 jbt->reg_cache[reg] = data;
162 printk(KERN_ERR"jbt_reg_write spi_write ret %d\n", rc);
167 static int jbt_reg_write16(struct jbt_info *jbt, u8 reg, u16 data)
171 jbt->tx_buf[0] = JBT_COMMAND | reg;
172 jbt->tx_buf[1] = JBT_DATA | (data >> 8);
173 jbt->tx_buf[2] = JBT_DATA | (data & 0xff);
175 rc = spi_write(jbt->spi_dev, (u8 *)jbt->tx_buf,
178 jbt->reg_cache[reg] = data;
180 printk(KERN_ERR"jbt_reg_write16 spi_write ret %d\n", rc);
185 static int jbt_init_regs(struct jbt_info *jbt)
189 dev_dbg(&jbt->spi_dev->dev, "entering %cVGA mode\n",
190 jbt->normal_state == JBT_STATE_QVGA_NORMAL ? 'Q' : ' ');
192 rc = jbt_reg_write(jbt, JBT_REG_DISPLAY_MODE1, 0x01);
193 rc |= jbt_reg_write(jbt, JBT_REG_DISPLAY_MODE2, 0x00);
194 rc |= jbt_reg_write(jbt, JBT_REG_RGB_FORMAT, 0x60);
195 rc |= jbt_reg_write(jbt, JBT_REG_DRIVE_SYSTEM, 0x10);
196 rc |= jbt_reg_write(jbt, JBT_REG_BOOSTER_OP, 0x56);
197 rc |= jbt_reg_write(jbt, JBT_REG_BOOSTER_MODE, 0x33);
198 rc |= jbt_reg_write(jbt, JBT_REG_BOOSTER_FREQ, 0x11);
199 rc |= jbt_reg_write(jbt, JBT_REG_OPAMP_SYSCLK, 0x02);
200 rc |= jbt_reg_write(jbt, JBT_REG_VSC_VOLTAGE, 0x2b);
201 rc |= jbt_reg_write(jbt, JBT_REG_VCOM_VOLTAGE, 0x40);
202 rc |= jbt_reg_write(jbt, JBT_REG_EXT_DISPL, 0x03);
203 rc |= jbt_reg_write(jbt, JBT_REG_DCCLK_DCEV, 0x04);
205 * default of 0x02 in JBT_REG_ASW_SLEW responsible for 72Hz requirement
206 * to avoid red / blue flicker
208 rc |= jbt_reg_write(jbt, JBT_REG_ASW_SLEW, 0x04);
209 rc |= jbt_reg_write(jbt, JBT_REG_DUMMY_DISPLAY, 0x00);
211 rc |= jbt_reg_write(jbt, JBT_REG_SLEEP_OUT_FR_A, 0x11);
212 rc |= jbt_reg_write(jbt, JBT_REG_SLEEP_OUT_FR_B, 0x11);
213 rc |= jbt_reg_write(jbt, JBT_REG_SLEEP_OUT_FR_C, 0x11);
214 rc |= jbt_reg_write16(jbt, JBT_REG_SLEEP_IN_LCCNT_D, 0x2040);
215 rc |= jbt_reg_write16(jbt, JBT_REG_SLEEP_IN_LCCNT_E, 0x60c0);
216 rc |= jbt_reg_write16(jbt, JBT_REG_SLEEP_IN_LCCNT_F, 0x1020);
217 rc |= jbt_reg_write16(jbt, JBT_REG_SLEEP_IN_LCCNT_G, 0x60c0);
219 rc |= jbt_reg_write16(jbt, JBT_REG_GAMMA1_FINE_1, 0x5533);
220 rc |= jbt_reg_write(jbt, JBT_REG_GAMMA1_FINE_2, 0x00);
221 rc |= jbt_reg_write(jbt, JBT_REG_GAMMA1_INCLINATION, 0x00);
222 rc |= jbt_reg_write(jbt, JBT_REG_GAMMA1_BLUE_OFFSET, 0x00);
224 if (jbt->normal_state != JBT_STATE_QVGA_NORMAL) {
225 rc |= jbt_reg_write16(jbt, JBT_REG_HCLOCK_VGA, 0x1f0);
226 rc |= jbt_reg_write(jbt, JBT_REG_BLANK_CONTROL, 0x02);
227 rc |= jbt_reg_write16(jbt, JBT_REG_BLANK_TH_TV, 0x0804);
229 rc |= jbt_reg_write(jbt, JBT_REG_CKV_ON_OFF, 0x01);
230 rc |= jbt_reg_write16(jbt, JBT_REG_CKV_1_2, 0x0000);
232 rc |= jbt_reg_write16(jbt, JBT_REG_OEV_TIMING, 0x0d0e);
233 rc |= jbt_reg_write16(jbt, JBT_REG_ASW_TIMING_1, 0x11a4);
234 rc |= jbt_reg_write(jbt, JBT_REG_ASW_TIMING_2, 0x0e);
236 rc |= jbt_reg_write16(jbt, JBT_REG_HCLOCK_QVGA, 0x00ff);
237 rc |= jbt_reg_write(jbt, JBT_REG_BLANK_CONTROL_QVGA, 0x02);
238 rc |= jbt_reg_write16(jbt, JBT_REG_BLANK_TH_TV_QVGA, 0x0804);
240 rc |= jbt_reg_write(jbt, JBT_REG_CKV_ON_OFF_QVGA, 0x01);
241 rc |= jbt_reg_write16(jbt, JBT_REG_CKV_1_2_QVGA, 0x0008);
243 rc |= jbt_reg_write16(jbt, JBT_REG_OEV_TIMING_QVGA, 0x050a);
244 rc |= jbt_reg_write16(jbt, JBT_REG_ASW_TIMING_1_QVGA, 0x0a19);
245 rc |= jbt_reg_write(jbt, JBT_REG_ASW_TIMING_2_QVGA, 0x0a);
248 return rc ? -EIO : 0;
251 static int standby_to_sleep(struct jbt_info *jbt)
255 /* three times command zero */
256 rc = jbt_reg_write_nodata(jbt, 0x00);
258 rc |= jbt_reg_write_nodata(jbt, 0x00);
260 rc |= jbt_reg_write_nodata(jbt, 0x00);
263 /* deep standby out */
264 rc |= jbt_reg_write(jbt, JBT_REG_POWER_ON_OFF, 0x11);
266 rc = jbt_reg_write(jbt, JBT_REG_DISPLAY_MODE, 0x28);
268 /* (re)initialize register set */
269 rc |= jbt_init_regs(jbt);
271 return rc ? -EIO : 0;
274 static int sleep_to_normal(struct jbt_info *jbt)
278 /* Make sure we are 120 ms after SLEEP_OUT */
279 unsigned int sleep_time = timespec_sub_ms(current_kernel_time(),
281 if (sleep_time < 120)
282 mdelay(120 - sleep_time);
284 if (jbt->normal_state == JBT_STATE_NORMAL) {
285 /* RGB I/F on, RAM wirte off, QVGA through, SIGCON enable */
286 rc = jbt_reg_write(jbt, JBT_REG_DISPLAY_MODE, 0x80);
289 rc |= jbt_reg_write(jbt, JBT_REG_QUAD_RATE, 0x00);
291 /* RGB I/F on, RAM wirte off, QVGA through, SIGCON enable */
292 rc = jbt_reg_write(jbt, JBT_REG_DISPLAY_MODE, 0x81);
295 rc |= jbt_reg_write(jbt, JBT_REG_QUAD_RATE, 0x22);
298 /* AVDD on, XVDD on */
299 rc |= jbt_reg_write(jbt, JBT_REG_POWER_ON_OFF, 0x16);
302 rc |= jbt_reg_write16(jbt, JBT_REG_OUTPUT_CONTROL, 0xfff9);
304 /* Turn on display */
305 rc |= jbt_reg_write_nodata(jbt, JBT_REG_DISPLAY_ON);
308 rc |= jbt_reg_write_nodata(jbt, JBT_REG_SLEEP_OUT);
309 jbt->last_sleep = current_kernel_time();
311 /* Allow the booster and display controller to restart stably */
314 return rc ? -EIO : 0;
317 static int normal_to_sleep(struct jbt_info *jbt)
321 /* Make sure we are 120 ms after SLEEP_OUT */
322 unsigned int sleep_time = timespec_sub_ms(current_kernel_time(),
324 if (sleep_time < 120)
325 mdelay(120 - sleep_time);
327 rc = jbt_reg_write_nodata(jbt, JBT_REG_DISPLAY_OFF);
328 rc |= jbt_reg_write16(jbt, JBT_REG_OUTPUT_CONTROL, 0x8002);
329 rc |= jbt_reg_write_nodata(jbt, JBT_REG_SLEEP_IN);
330 jbt->last_sleep = current_kernel_time();
332 /* Allow the internal circuits to stop automatically */
335 return rc ? -EIO : 0;
338 static int sleep_to_standby(struct jbt_info *jbt)
340 return jbt_reg_write(jbt, JBT_REG_POWER_ON_OFF, 0x00);
343 /* frontend function */
344 int jbt6k74_enter_state(struct jbt_info *jbt, enum jbt_state new_state)
348 /* dev_dbg(&jbt->spi_dev->dev, "entering (old_state=%s, new_state=%s)\n",
349 jbt_state_names[jbt->state],
350 jbt_state_names[new_state]);*/
352 /* printk("entering (old_state=%s, new_state=%s)\n",
353 jbt_state_names[jbt->state],
354 jbt_state_names[new_state]);*/
356 mutex_lock(&jbt->lock);
358 if (new_state == JBT_STATE_NORMAL ||
359 new_state == JBT_STATE_QVGA_NORMAL)
360 jbt->normal_state = new_state;
362 switch (jbt->state) {
363 case JBT_STATE_DEEP_STANDBY:
365 case JBT_STATE_DEEP_STANDBY:
368 case JBT_STATE_SLEEP:
369 rc = standby_to_sleep(jbt);
371 case JBT_STATE_NORMAL:
372 /* first transition into sleep */
373 rc = standby_to_sleep(jbt);
374 /* then transition into normal */
375 rc |= sleep_to_normal(jbt);
377 case JBT_STATE_QVGA_NORMAL:
378 /* first transition into sleep */
379 rc = standby_to_sleep(jbt);
380 /* then transition into normal */
381 rc |= sleep_to_normal(jbt);
385 case JBT_STATE_SLEEP:
387 case JBT_STATE_SLEEP:
390 case JBT_STATE_DEEP_STANDBY:
391 rc = sleep_to_standby(jbt);
393 case JBT_STATE_NORMAL:
394 case JBT_STATE_QVGA_NORMAL:
395 rc = sleep_to_normal(jbt);
399 case JBT_STATE_NORMAL:
401 case JBT_STATE_NORMAL:
404 case JBT_STATE_DEEP_STANDBY:
405 /* first transition into sleep */
406 rc = normal_to_sleep(jbt);
407 /* then transition into deep standby */
408 rc |= sleep_to_standby(jbt);
410 case JBT_STATE_SLEEP:
411 rc = normal_to_sleep(jbt);
413 case JBT_STATE_QVGA_NORMAL:
414 /* first transition into sleep */
415 rc = normal_to_sleep(jbt);
416 /* second transition into deep standby */
417 rc |= sleep_to_standby(jbt);
418 /* third transition into sleep */
419 rc |= standby_to_sleep(jbt);
420 /* fourth transition into normal */
421 rc |= sleep_to_normal(jbt);
425 case JBT_STATE_QVGA_NORMAL:
427 case JBT_STATE_QVGA_NORMAL:
430 case JBT_STATE_DEEP_STANDBY:
431 /* first transition into sleep */
432 rc = normal_to_sleep(jbt);
433 /* then transition into deep standby */
434 rc |= sleep_to_standby(jbt);
436 case JBT_STATE_SLEEP:
437 rc = normal_to_sleep(jbt);
439 case JBT_STATE_NORMAL:
440 /* first transition into sleep */
441 rc = normal_to_sleep(jbt);
442 /* second transition into deep standby */
443 rc |= sleep_to_standby(jbt);
444 /* third transition into sleep */
445 rc |= standby_to_sleep(jbt);
446 /* fourth transition into normal */
447 rc |= sleep_to_normal(jbt);
454 jbt->state = new_state;
456 dev_err(&jbt->spi_dev->dev, "Failed enter state '%s')\n",
457 jbt_state_names[new_state]);
459 mutex_unlock(&jbt->lock);
463 EXPORT_SYMBOL_GPL(jbt6k74_enter_state);
465 static ssize_t state_read(struct device *dev, struct device_attribute *attr,
468 struct jbt_info *jbt = dev_get_drvdata(dev);
470 if (jbt->state >= ARRAY_SIZE(jbt_state_names))
473 return sprintf(buf, "%s\n", jbt_state_names[jbt->state]);
476 static ssize_t state_write(struct device *dev, struct device_attribute *attr,
477 const char *buf, size_t count)
479 struct jbt_info *jbt = dev_get_drvdata(dev);
482 for (i = 0; i < ARRAY_SIZE(jbt_state_names); i++) {
483 if (!strncmp(buf, jbt_state_names[i],
484 strlen(jbt_state_names[i]))) {
485 rc = jbt6k74_enter_state(jbt, i);
495 static DEVICE_ATTR(state, 0644, state_read, state_write);
497 static int reg_by_string(const char *name)
499 if (!strcmp(name, "gamma_fine1"))
500 return JBT_REG_GAMMA1_FINE_1;
501 else if (!strcmp(name, "gamma_fine2"))
502 return JBT_REG_GAMMA1_FINE_2;
503 else if (!strcmp(name, "gamma_inclination"))
504 return JBT_REG_GAMMA1_INCLINATION;
506 return JBT_REG_GAMMA1_BLUE_OFFSET;
509 static ssize_t gamma_read(struct device *dev, struct device_attribute *attr,
512 struct jbt_info *jbt = dev_get_drvdata(dev);
513 int reg = reg_by_string(attr->attr.name);
516 mutex_lock(&jbt->lock);
517 val = jbt->reg_cache[reg];
518 mutex_unlock(&jbt->lock);
520 return sprintf(buf, "0x%04x\n", val);
523 static ssize_t gamma_write(struct device *dev, struct device_attribute *attr,
524 const char *buf, size_t count)
526 struct jbt_info *jbt = dev_get_drvdata(dev);
527 int reg = reg_by_string(attr->attr.name);
528 unsigned long val = simple_strtoul(buf, NULL, 10);
530 dev_info(dev, "writing gama %lu\n", val & 0xff);
532 mutex_lock(&jbt->lock);
533 jbt_reg_write(jbt, reg, val & 0xff);
534 mutex_unlock(&jbt->lock);
539 static ssize_t reset_write(struct device *dev, struct device_attribute *attr,
540 const char *buf, size_t count)
543 struct jbt_info *jbt = dev_get_drvdata(dev);
544 struct jbt6k74_platform_data *pdata = jbt->spi_dev->dev.platform_data;
546 dev_info(dev, "reset\n");
548 mutex_lock(&jbt->lock);
550 jbt->state = JBT_STATE_DEEP_STANDBY;
552 /* hard reset the jbt6k74 */
553 (pdata->reset)(0, 0);
555 (pdata->reset)(0, 1);
558 rc = jbt_reg_write_nodata(jbt, 0x01);
560 dev_err(&jbt->spi_dev->dev, "cannot soft reset\n");
563 mutex_unlock(&jbt->lock);
565 jbt6k74_enter_state(jbt, jbt->normal_state);
570 static DEVICE_ATTR(gamma_fine1, 0644, gamma_read, gamma_write);
571 static DEVICE_ATTR(gamma_fine2, 0644, gamma_read, gamma_write);
572 static DEVICE_ATTR(gamma_inclination, 0644, gamma_read, gamma_write);
573 static DEVICE_ATTR(gamma_blue_offset, 0644, gamma_read, gamma_write);
574 static DEVICE_ATTR(reset, 0600, NULL, reset_write);
576 static struct attribute *jbt_sysfs_entries[] = {
577 &dev_attr_state.attr,
578 &dev_attr_gamma_fine1.attr,
579 &dev_attr_gamma_fine2.attr,
580 &dev_attr_gamma_inclination.attr,
581 &dev_attr_gamma_blue_offset.attr,
582 &dev_attr_reset.attr,
586 static struct attribute_group jbt_attr_group = {
588 .attrs = jbt_sysfs_entries,
591 static int fb_notifier_callback(struct notifier_block *self,
592 unsigned long event, void *data)
594 struct jbt_info *jbt;
595 struct fb_event *evdata = data;
598 jbt = container_of(self, struct jbt_info, fb_notif);
600 dev_dbg(&jbt->spi_dev->dev, "event=%lu\n", event);
602 if (event != FB_EVENT_BLANK && event != FB_EVENT_CONBLANK)
605 fb_blank = *(int *)evdata->data;
607 case FB_BLANK_UNBLANK:
608 dev_dbg(&jbt->spi_dev->dev, "unblank\n");
609 jbt6k74_enter_state(jbt, jbt->normal_state);
611 case FB_BLANK_NORMAL:
612 dev_dbg(&jbt->spi_dev->dev, "blank\n");
614 case FB_BLANK_VSYNC_SUSPEND:
615 dev_dbg(&jbt->spi_dev->dev, "vsync suspend\n");
617 case FB_BLANK_HSYNC_SUSPEND:
618 dev_dbg(&jbt->spi_dev->dev, "hsync suspend\n");
620 case FB_BLANK_POWERDOWN:
621 dev_dbg(&jbt->spi_dev->dev, "powerdown\n");
622 jbt6k74_enter_state(jbt, JBT_STATE_SLEEP);
629 /* linux device model infrastructure */
631 static int __devinit jbt_probe(struct spi_device *spi)
634 struct jbt_info *jbt;
635 struct jbt6k74_platform_data *pdata = spi->dev.platform_data;
637 /* the controller doesn't have a MISO pin; we can't do detection */
639 spi->mode = SPI_CPOL | SPI_CPHA;
640 spi->bits_per_word = 9;
645 "error during spi_setup of jbt6k74 driver\n");
649 jbt = kzalloc(sizeof(*jbt), GFP_KERNEL);
654 jbt->normal_state = JBT_STATE_NORMAL;
655 jbt->state = JBT_STATE_DEEP_STANDBY;
656 jbt->last_sleep = current_kernel_time();
657 mutex_init(&jbt->lock);
659 dev_set_drvdata(&spi->dev, jbt);
661 rc = jbt6k74_enter_state(jbt, JBT_STATE_NORMAL);
663 dev_err(&spi->dev, "cannot enter NORMAL state\n");
664 goto err_free_drvdata;
667 rc = sysfs_create_group(&spi->dev.kobj, &jbt_attr_group);
669 dev_err(&spi->dev, "cannot create sysfs group\n");
673 jbt->fb_notif.notifier_call = fb_notifier_callback;
674 rc = fb_register_client(&jbt->fb_notif);
676 dev_err(&spi->dev, "cannot register notifier\n");
680 if (pdata->probe_completed)
681 (pdata->probe_completed)(&spi->dev);
686 sysfs_remove_group(&spi->dev.kobj, &jbt_attr_group);
688 jbt6k74_enter_state(jbt, JBT_STATE_DEEP_STANDBY);
690 dev_set_drvdata(&spi->dev, NULL);
696 static int __devexit jbt_remove(struct spi_device *spi)
698 struct jbt_info *jbt = dev_get_drvdata(&spi->dev);
700 /* We don't want to switch off the display in case the user
701 * accidentially onloads the module (whose use count normally is 0) */
702 jbt6k74_enter_state(jbt, jbt->normal_state);
704 fb_unregister_client(&jbt->fb_notif);
705 sysfs_remove_group(&spi->dev.kobj, &jbt_attr_group);
706 dev_set_drvdata(&spi->dev, NULL);
713 static int jbt_suspend(struct spi_device *spi, pm_message_t state)
715 struct jbt_info *jbt = dev_get_drvdata(&spi->dev);
717 jbt6k74_enter_state(jbt, JBT_STATE_DEEP_STANDBY);
719 dev_info(&spi->dev, "suspended\n");
724 int jbt6k74_resume(struct spi_device *spi)
726 struct jbt_info *jbt = dev_get_drvdata(&spi->dev);
727 struct jbt6k74_platform_data *pdata = spi->dev.platform_data;
729 jbt6k74_enter_state(jbt, jbt->normal_state);
732 (pdata->resuming)(0);
734 dev_info(&spi->dev, "resumed\n");
738 EXPORT_SYMBOL_GPL(jbt6k74_resume);
741 #define jbt_suspend NULL
742 #define jbt6k74_resume NULL
745 static struct spi_driver jbt6k74_driver = {
748 .owner = THIS_MODULE,
752 .remove = __devexit_p(jbt_remove),
753 .suspend = jbt_suspend,
754 .resume = jbt6k74_resume,
757 static int __init jbt_init(void)
759 return spi_register_driver(&jbt6k74_driver);
762 static void __exit jbt_exit(void)
764 spi_unregister_driver(&jbt6k74_driver);
767 MODULE_DESCRIPTION("SPI driver for tpo JBT6K74-AS LCM control interface");
768 MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
769 MODULE_LICENSE("GPL");
771 module_init(jbt_init);
772 module_exit(jbt_exit);