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>
7 * Copyright (C) 2009 by Lars-Peter Clausen <lars@metafoo.de>
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 #include <linux/kernel.h>
28 #include <linux/types.h>
29 #include <linux/module.h>
30 #include <linux/device.h>
31 #include <linux/platform_device.h>
32 #include <linux/delay.h>
33 #include <linux/workqueue.h>
34 #include <linux/jbt6k74.h>
36 #include <linux/lcd.h>
37 #include <linux/time.h>
40 JBT_REG_SLEEP_IN
= 0x10,
41 JBT_REG_SLEEP_OUT
= 0x11,
43 JBT_REG_DISPLAY_OFF
= 0x28,
44 JBT_REG_DISPLAY_ON
= 0x29,
46 JBT_REG_RGB_FORMAT
= 0x3a,
47 JBT_REG_QUAD_RATE
= 0x3b,
49 JBT_REG_POWER_ON_OFF
= 0xb0,
50 JBT_REG_BOOSTER_OP
= 0xb1,
51 JBT_REG_BOOSTER_MODE
= 0xb2,
52 JBT_REG_BOOSTER_FREQ
= 0xb3,
53 JBT_REG_OPAMP_SYSCLK
= 0xb4,
54 JBT_REG_VSC_VOLTAGE
= 0xb5,
55 JBT_REG_VCOM_VOLTAGE
= 0xb6,
56 JBT_REG_EXT_DISPL
= 0xb7,
57 JBT_REG_OUTPUT_CONTROL
= 0xb8,
58 JBT_REG_DCCLK_DCEV
= 0xb9,
59 JBT_REG_DISPLAY_MODE1
= 0xba,
60 JBT_REG_DISPLAY_MODE2
= 0xbb,
61 JBT_REG_DISPLAY_MODE
= 0xbc,
62 JBT_REG_ASW_SLEW
= 0xbd,
63 JBT_REG_DUMMY_DISPLAY
= 0xbe,
64 JBT_REG_DRIVE_SYSTEM
= 0xbf,
66 JBT_REG_SLEEP_OUT_FR_A
= 0xc0,
67 JBT_REG_SLEEP_OUT_FR_B
= 0xc1,
68 JBT_REG_SLEEP_OUT_FR_C
= 0xc2,
69 JBT_REG_SLEEP_IN_LCCNT_D
= 0xc3,
70 JBT_REG_SLEEP_IN_LCCNT_E
= 0xc4,
71 JBT_REG_SLEEP_IN_LCCNT_F
= 0xc5,
72 JBT_REG_SLEEP_IN_LCCNT_G
= 0xc6,
74 JBT_REG_GAMMA1_FINE_1
= 0xc7,
75 JBT_REG_GAMMA1_FINE_2
= 0xc8,
76 JBT_REG_GAMMA1_INCLINATION
= 0xc9,
77 JBT_REG_GAMMA1_BLUE_OFFSET
= 0xca,
80 JBT_REG_BLANK_CONTROL
= 0xcf,
81 JBT_REG_BLANK_TH_TV
= 0xd0,
82 JBT_REG_CKV_ON_OFF
= 0xd1,
83 JBT_REG_CKV_1_2
= 0xd2,
84 JBT_REG_OEV_TIMING
= 0xd3,
85 JBT_REG_ASW_TIMING_1
= 0xd4,
86 JBT_REG_ASW_TIMING_2
= 0xd5,
89 JBT_REG_BLANK_CONTROL_QVGA
= 0xd6,
90 JBT_REG_BLANK_TH_TV_QVGA
= 0xd7,
91 JBT_REG_CKV_ON_OFF_QVGA
= 0xd8,
92 JBT_REG_CKV_1_2_QVGA
= 0xd9,
93 JBT_REG_OEV_TIMING_QVGA
= 0xde,
94 JBT_REG_ASW_TIMING_1_QVGA
= 0xdf,
95 JBT_REG_ASW_TIMING_2_QVGA
= 0xe0,
98 JBT_REG_HCLOCK_VGA
= 0xec,
99 JBT_REG_HCLOCK_QVGA
= 0xed,
103 enum jbt_resolution
{
108 enum jbt_power_mode
{
109 JBT_POWER_MODE_DEEP_STANDBY
,
110 JBT_POWER_MODE_SLEEP
,
111 JBT_POWER_MODE_NORMAL
,
114 static const char *jbt_power_mode_names
[] = {
115 [JBT_POWER_MODE_DEEP_STANDBY
] = "deep-standby",
116 [JBT_POWER_MODE_SLEEP
] = "sleep",
117 [JBT_POWER_MODE_NORMAL
] = "normal",
120 static const char *jbt_resolution_names
[] = {
121 [JBT_RESOLUTION_VGA
] = "vga",
122 [JBT_RESOLUTION_QVGA
] = "qvga",
126 struct mutex lock
; /* protects this structure */
127 enum jbt_resolution resolution
;
128 enum jbt_power_mode power_mode
;
129 enum jbt_power_mode suspend_mode
;
131 struct spi_device
*spi_dev
;
132 struct lcd_device
*lcd_dev
;
133 unsigned long last_sleep
;
134 struct delayed_work blank_work
;
140 #define JBT_COMMAND 0x000
141 #define JBT_DATA 0x100
143 static int jbt_reg_write_nodata(struct jbt_info
*jbt
, u8 reg
)
147 jbt
->tx_buf
[0] = JBT_COMMAND
| reg
;
148 rc
= spi_write(jbt
->spi_dev
, (u8
*)jbt
->tx_buf
,
151 jbt
->reg_cache
[reg
] = 0;
153 dev_err(&jbt
->spi_dev
->dev
, "jbt_reg_write_nodata spi_write ret %d\n",
160 static int jbt_reg_write(struct jbt_info
*jbt
, u8 reg
, u8 data
)
164 jbt
->tx_buf
[0] = JBT_COMMAND
| reg
;
165 jbt
->tx_buf
[1] = JBT_DATA
| data
;
166 rc
= spi_write(jbt
->spi_dev
, (u8
*)jbt
->tx_buf
,
169 jbt
->reg_cache
[reg
] = data
;
171 dev_err(&jbt
->spi_dev
->dev
, "jbt_reg_write spi_write ret %d\n", rc
);
176 static int jbt_reg_write16(struct jbt_info
*jbt
, u8 reg
, u16 data
)
180 jbt
->tx_buf
[0] = JBT_COMMAND
| reg
;
181 jbt
->tx_buf
[1] = JBT_DATA
| (data
>> 8);
182 jbt
->tx_buf
[2] = JBT_DATA
| (data
& 0xff);
184 rc
= spi_write(jbt
->spi_dev
, (u8
*)jbt
->tx_buf
,
187 jbt
->reg_cache
[reg
] = data
;
189 dev_err(&jbt
->spi_dev
->dev
, "jbt_reg_write16 spi_write ret %d\n", rc
);
194 static int jbt_init_regs(struct jbt_info
*jbt
)
198 dev_dbg(&jbt
->spi_dev
->dev
, "entering %cVGA mode\n",
199 jbt
->resolution
== JBT_RESOLUTION_QVGA
? 'Q' : ' ');
201 rc
= jbt_reg_write(jbt
, JBT_REG_DISPLAY_MODE1
, 0x01);
202 rc
|= jbt_reg_write(jbt
, JBT_REG_DISPLAY_MODE2
, 0x00);
203 rc
|= jbt_reg_write(jbt
, JBT_REG_RGB_FORMAT
, 0x60);
204 rc
|= jbt_reg_write(jbt
, JBT_REG_DRIVE_SYSTEM
, 0x10);
205 rc
|= jbt_reg_write(jbt
, JBT_REG_BOOSTER_OP
, 0x56);
206 rc
|= jbt_reg_write(jbt
, JBT_REG_BOOSTER_MODE
, 0x33);
207 rc
|= jbt_reg_write(jbt
, JBT_REG_BOOSTER_FREQ
, 0x11);
208 rc
|= jbt_reg_write(jbt
, JBT_REG_OPAMP_SYSCLK
, 0x02);
209 rc
|= jbt_reg_write(jbt
, JBT_REG_VSC_VOLTAGE
, 0x2b);
210 rc
|= jbt_reg_write(jbt
, JBT_REG_VCOM_VOLTAGE
, 0x40);
211 rc
|= jbt_reg_write(jbt
, JBT_REG_EXT_DISPL
, 0x03);
212 rc
|= jbt_reg_write(jbt
, JBT_REG_DCCLK_DCEV
, 0x04);
214 * default of 0x02 in JBT_REG_ASW_SLEW responsible for 72Hz requirement
215 * to avoid red / blue flicker
217 rc
|= jbt_reg_write(jbt
, JBT_REG_ASW_SLEW
, 0x04 | (1 << 5));
218 rc
|= jbt_reg_write(jbt
, JBT_REG_DUMMY_DISPLAY
, 0x00);
220 rc
|= jbt_reg_write(jbt
, JBT_REG_SLEEP_OUT_FR_A
, 0x11);
221 rc
|= jbt_reg_write(jbt
, JBT_REG_SLEEP_OUT_FR_B
, 0x11);
222 rc
|= jbt_reg_write(jbt
, JBT_REG_SLEEP_OUT_FR_C
, 0x11);
223 rc
|= jbt_reg_write16(jbt
, JBT_REG_SLEEP_IN_LCCNT_D
, 0x2040);
224 rc
|= jbt_reg_write16(jbt
, JBT_REG_SLEEP_IN_LCCNT_E
, 0x60c0);
225 rc
|= jbt_reg_write16(jbt
, JBT_REG_SLEEP_IN_LCCNT_F
, 0x1020);
226 rc
|= jbt_reg_write16(jbt
, JBT_REG_SLEEP_IN_LCCNT_G
, 0x60c0);
228 rc
|= jbt_reg_write16(jbt
, JBT_REG_GAMMA1_FINE_1
, 0x5533);
229 rc
|= jbt_reg_write(jbt
, JBT_REG_GAMMA1_FINE_2
, 0x00);
230 rc
|= jbt_reg_write(jbt
, JBT_REG_GAMMA1_INCLINATION
, 0x00);
231 rc
|= jbt_reg_write(jbt
, JBT_REG_GAMMA1_BLUE_OFFSET
, 0x00);
233 if (jbt
->resolution
!= JBT_RESOLUTION_QVGA
) {
234 rc
|= jbt_reg_write16(jbt
, JBT_REG_HCLOCK_VGA
, 0x1f0);
235 rc
|= jbt_reg_write(jbt
, JBT_REG_BLANK_CONTROL
, 0x02);
236 rc
|= jbt_reg_write16(jbt
, JBT_REG_BLANK_TH_TV
, 0x0804);
238 rc
|= jbt_reg_write(jbt
, JBT_REG_CKV_ON_OFF
, 0x01);
239 rc
|= jbt_reg_write16(jbt
, JBT_REG_CKV_1_2
, 0x0000);
241 rc
|= jbt_reg_write16(jbt
, JBT_REG_OEV_TIMING
, 0x0d0e);
242 rc
|= jbt_reg_write16(jbt
, JBT_REG_ASW_TIMING_1
, 0x11a4);
243 rc
|= jbt_reg_write(jbt
, JBT_REG_ASW_TIMING_2
, 0x0e);
245 rc
|= jbt_reg_write16(jbt
, JBT_REG_HCLOCK_QVGA
, 0x00ff);
246 rc
|= jbt_reg_write(jbt
, JBT_REG_BLANK_CONTROL_QVGA
, 0x02);
247 rc
|= jbt_reg_write16(jbt
, JBT_REG_BLANK_TH_TV_QVGA
, 0x0804);
249 rc
|= jbt_reg_write(jbt
, JBT_REG_CKV_ON_OFF_QVGA
, 0x01);
250 rc
|= jbt_reg_write16(jbt
, JBT_REG_CKV_1_2_QVGA
, 0x0008);
252 rc
|= jbt_reg_write16(jbt
, JBT_REG_OEV_TIMING_QVGA
, 0x050a);
253 rc
|= jbt_reg_write16(jbt
, JBT_REG_ASW_TIMING_1_QVGA
, 0x0a19);
254 rc
|= jbt_reg_write(jbt
, JBT_REG_ASW_TIMING_2_QVGA
, 0x0a);
257 return rc
? -EIO
: 0;
260 static int standby_to_sleep(struct jbt_info
*jbt
)
264 /* three times command zero */
265 rc
= jbt_reg_write_nodata(jbt
, 0x00);
267 rc
|= jbt_reg_write_nodata(jbt
, 0x00);
269 rc
|= jbt_reg_write_nodata(jbt
, 0x00);
272 /* deep standby out */
273 rc
|= jbt_reg_write(jbt
, JBT_REG_POWER_ON_OFF
, 0x11);
275 rc
= jbt_reg_write(jbt
, JBT_REG_DISPLAY_MODE
, 0x28);
277 /* (re)initialize register set */
278 rc
|= jbt_init_regs(jbt
);
280 return rc
? -EIO
: 0;
283 static int sleep_to_normal(struct jbt_info
*jbt
)
287 /* Make sure we are 120 ms after SLEEP_OUT */
288 if (time_before(jiffies
, jbt
->last_sleep
))
289 mdelay(jiffies_to_msecs(jbt
->last_sleep
- jiffies
));
291 if (jbt
->resolution
== JBT_RESOLUTION_VGA
) {
292 /* RGB I/F on, RAM wirte off, QVGA through, SIGCON enable */
293 rc
= jbt_reg_write(jbt
, JBT_REG_DISPLAY_MODE
, 0x80);
296 rc
|= jbt_reg_write(jbt
, JBT_REG_QUAD_RATE
, 0x00);
298 /* RGB I/F on, RAM wirte off, QVGA through, SIGCON enable */
299 rc
= jbt_reg_write(jbt
, JBT_REG_DISPLAY_MODE
, 0x81);
302 rc
|= jbt_reg_write(jbt
, JBT_REG_QUAD_RATE
, 0x22);
305 /* AVDD on, XVDD on */
306 rc
|= jbt_reg_write(jbt
, JBT_REG_POWER_ON_OFF
, 0x16);
309 rc
|= jbt_reg_write16(jbt
, JBT_REG_OUTPUT_CONTROL
, 0xfff9);
311 /* Turn on display */
312 rc
|= jbt_reg_write_nodata(jbt
, JBT_REG_DISPLAY_ON
);
315 rc
|= jbt_reg_write_nodata(jbt
, JBT_REG_SLEEP_OUT
);
316 jbt
->last_sleep
= jiffies
+ msecs_to_jiffies(120);
318 /* Allow the booster and display controller to restart stably */
321 return rc
? -EIO
: 0;
324 static int normal_to_sleep(struct jbt_info
*jbt
)
328 /* Make sure we are 120 ms after SLEEP_OUT */
329 while (time_before(jiffies
, jbt
->last_sleep
))
332 rc
= jbt_reg_write_nodata(jbt
, JBT_REG_DISPLAY_OFF
);
333 rc
|= jbt_reg_write16(jbt
, JBT_REG_OUTPUT_CONTROL
, 0x8000 | 1 << 3);
334 rc
|= jbt_reg_write_nodata(jbt
, JBT_REG_SLEEP_IN
);
335 jbt
->last_sleep
= jiffies
+ msecs_to_jiffies(120);
337 /* Allow the internal circuits to stop automatically */
340 return rc
? -EIO
: 0;
343 static int sleep_to_standby(struct jbt_info
*jbt
)
345 return jbt_reg_write(jbt
, JBT_REG_POWER_ON_OFF
, 0x00);
348 int jbt6k74_enter_power_mode(struct jbt_info
*jbt
, enum jbt_power_mode new_mode
)
350 struct jbt6k74_platform_data
*pdata
= jbt
->spi_dev
->dev
.platform_data
;
353 dev_dbg(&jbt
->spi_dev
->dev
, "entering (old_state=%s, new_state=%s)\n",
354 jbt_power_mode_names
[jbt
->power_mode
],
355 jbt_power_mode_names
[new_mode
]);
357 mutex_lock(&jbt
->lock
);
359 if (jbt
->suspended
) {
361 case JBT_POWER_MODE_DEEP_STANDBY
:
362 case JBT_POWER_MODE_SLEEP
:
363 case JBT_POWER_MODE_NORMAL
:
365 jbt
->suspend_mode
= new_mode
;
370 } else if (new_mode
== JBT_POWER_MODE_NORMAL
&&
371 pdata
->enable_pixel_clock
) {
372 pdata
->enable_pixel_clock(&jbt
->spi_dev
->dev
, 1);
375 switch (jbt
->power_mode
) {
376 case JBT_POWER_MODE_DEEP_STANDBY
:
378 case JBT_POWER_MODE_DEEP_STANDBY
:
381 case JBT_POWER_MODE_SLEEP
:
382 rc
= standby_to_sleep(jbt
);
384 case JBT_POWER_MODE_NORMAL
:
385 /* first transition into sleep */
386 rc
= standby_to_sleep(jbt
);
387 /* then transition into normal */
388 rc
|= sleep_to_normal(jbt
);
392 case JBT_POWER_MODE_SLEEP
:
394 case JBT_POWER_MODE_SLEEP
:
397 case JBT_POWER_MODE_DEEP_STANDBY
:
398 rc
= sleep_to_standby(jbt
);
400 case JBT_POWER_MODE_NORMAL
:
401 rc
= sleep_to_normal(jbt
);
405 case JBT_POWER_MODE_NORMAL
:
407 case JBT_POWER_MODE_NORMAL
:
410 case JBT_POWER_MODE_DEEP_STANDBY
:
411 /* first transition into sleep */
412 rc
= normal_to_sleep(jbt
);
413 /* then transition into deep standby */
414 rc
|= sleep_to_standby(jbt
);
416 case JBT_POWER_MODE_SLEEP
:
417 rc
= normal_to_sleep(jbt
);
423 jbt
->power_mode
= new_mode
;
424 if (new_mode
!= JBT_POWER_MODE_NORMAL
&&
425 pdata
->enable_pixel_clock
)
426 pdata
->enable_pixel_clock(&jbt
->spi_dev
->dev
, 0);
428 dev_err(&jbt
->spi_dev
->dev
, "Failed enter state '%s')\n",
429 jbt_power_mode_names
[new_mode
]);
432 mutex_unlock(&jbt
->lock
);
436 EXPORT_SYMBOL_GPL(jbt6k74_enter_power_mode
);
438 int jbt6k74_set_resolution(struct jbt_info
*jbt
, enum jbt_resolution new_resolution
) {
440 enum jbt_resolution old_resolution
;
442 if (new_resolution
!= JBT_RESOLUTION_VGA
&&
443 new_resolution
!= JBT_RESOLUTION_QVGA
)
446 mutex_lock(&jbt
->lock
);
448 if (jbt
->resolution
== new_resolution
)
451 old_resolution
= jbt
->resolution
;
452 jbt
->resolution
= new_resolution
;
454 if (jbt
->power_mode
== JBT_POWER_MODE_NORMAL
) {
456 /* first transition into sleep */
457 rc
= normal_to_sleep(jbt
);
458 /* second transition into deep standby */
459 /* rc |= sleep_to_standby(jbt);*/
460 /* third transition into sleep */
461 /* rc |= standby_to_sleep(jbt);*/
462 /* fourth transition into normal */
463 rc
|= sleep_to_normal(jbt
);
466 jbt
->resolution
= old_resolution
;
467 dev_err(&jbt
->spi_dev
->dev
, "Failed to set resolution '%s')\n",
468 jbt_resolution_names
[new_resolution
]);
473 mutex_unlock(&jbt
->lock
);
477 EXPORT_SYMBOL_GPL(jbt6k74_set_resolution
);
479 static ssize_t
resolution_read(struct device
*dev
, struct device_attribute
*attr
,
482 struct jbt_info
*jbt
= dev_get_drvdata(dev
);
484 if (jbt
->resolution
>= ARRAY_SIZE(jbt_resolution_names
))
487 return sprintf(buf
, "%s\n", jbt_resolution_names
[jbt
->resolution
]);
490 static ssize_t
resolution_write(struct device
*dev
, struct device_attribute
*attr
,
491 const char *buf
, size_t count
)
493 struct jbt_info
*jbt
= dev_get_drvdata(dev
);
496 for (i
= 0; i
< ARRAY_SIZE(jbt_resolution_names
); i
++) {
497 if (!strncmp(buf
, jbt_resolution_names
[i
],
498 strlen(jbt_resolution_names
[i
]))) {
499 rc
= jbt6k74_set_resolution(jbt
, i
);
509 static DEVICE_ATTR(resolution
, 0644, resolution_read
, resolution_write
);
511 static int reg_by_string(const char *name
)
513 if (!strcmp(name
, "gamma_fine1"))
514 return JBT_REG_GAMMA1_FINE_1
;
515 else if (!strcmp(name
, "gamma_fine2"))
516 return JBT_REG_GAMMA1_FINE_2
;
517 else if (!strcmp(name
, "gamma_inclination"))
518 return JBT_REG_GAMMA1_INCLINATION
;
520 return JBT_REG_GAMMA1_BLUE_OFFSET
;
523 static ssize_t
gamma_read(struct device
*dev
, struct device_attribute
*attr
,
526 struct jbt_info
*jbt
= dev_get_drvdata(dev
);
527 int reg
= reg_by_string(attr
->attr
.name
);
530 mutex_lock(&jbt
->lock
);
531 val
= jbt
->reg_cache
[reg
];
532 mutex_unlock(&jbt
->lock
);
534 return sprintf(buf
, "0x%04x\n", val
);
537 static ssize_t
gamma_write(struct device
*dev
, struct device_attribute
*attr
,
538 const char *buf
, size_t count
)
540 struct jbt_info
*jbt
= dev_get_drvdata(dev
);
541 int reg
= reg_by_string(attr
->attr
.name
);
542 unsigned long val
= simple_strtoul(buf
, NULL
, 10);
544 dev_info(dev
, "writing gama %lu\n", val
& 0xff);
546 mutex_lock(&jbt
->lock
);
547 jbt_reg_write(jbt
, reg
, val
& 0xff);
548 mutex_unlock(&jbt
->lock
);
553 static ssize_t
reset_write(struct device
*dev
, struct device_attribute
*attr
,
554 const char *buf
, size_t count
)
557 struct jbt_info
*jbt
= dev_get_drvdata(dev
);
558 struct jbt6k74_platform_data
*pdata
= jbt
->spi_dev
->dev
.platform_data
;
560 dev_info(dev
, "reset\n");
562 mutex_lock(&jbt
->lock
);
564 /* hard reset the jbt6k74 */
565 (pdata
->reset
)(0, 0);
567 (pdata
->reset
)(0, 1);
570 rc
= jbt_reg_write_nodata(jbt
, 0x01);
572 dev_err(&jbt
->spi_dev
->dev
, "cannot soft reset\n");
575 mutex_unlock(&jbt
->lock
);
577 jbt6k74_enter_power_mode(jbt
, jbt
->power_mode
);
582 static DEVICE_ATTR(gamma_fine1
, 0644, gamma_read
, gamma_write
);
583 static DEVICE_ATTR(gamma_fine2
, 0644, gamma_read
, gamma_write
);
584 static DEVICE_ATTR(gamma_inclination
, 0644, gamma_read
, gamma_write
);
585 static DEVICE_ATTR(gamma_blue_offset
, 0644, gamma_read
, gamma_write
);
586 static DEVICE_ATTR(reset
, 0600, NULL
, reset_write
);
588 static struct attribute
*jbt_sysfs_entries
[] = {
589 &dev_attr_resolution
.attr
,
590 &dev_attr_gamma_fine1
.attr
,
591 &dev_attr_gamma_fine2
.attr
,
592 &dev_attr_gamma_inclination
.attr
,
593 &dev_attr_gamma_blue_offset
.attr
,
594 &dev_attr_reset
.attr
,
598 static struct attribute_group jbt_attr_group
= {
600 .attrs
= jbt_sysfs_entries
,
603 /* FIXME: This in an ugly hack to delay display blanking.
604 When the jbt is in sleep mode it displays an all white screen and thus one
605 will a see a short flash.
606 By delaying the blanking we will give the backlight a chance to turn off and
607 thus avoid getting the flash */
608 static void jbt_blank_worker(struct work_struct
*work
) {
609 struct jbt_info
*jbt
= container_of(work
, struct jbt_info
,
612 switch (jbt
->blank_mode
) {
613 case FB_BLANK_NORMAL
:
614 jbt6k74_enter_power_mode(jbt
, JBT_POWER_MODE_SLEEP
);
616 case FB_BLANK_POWERDOWN
:
617 jbt6k74_enter_power_mode(jbt
, JBT_POWER_MODE_DEEP_STANDBY
);
624 static int jbt6k74_set_mode(struct lcd_device
*ld
, struct fb_videomode
*m
) {
626 struct jbt_info
*jbt
= dev_get_drvdata(&ld
->dev
);
628 if (m
->xres
== 240 && m
->yres
== 320) {
629 rc
= jbt6k74_set_resolution(jbt
, JBT_RESOLUTION_QVGA
);
630 } else if (m
->xres
== 480 && m
->yres
== 640) {
631 rc
= jbt6k74_set_resolution(jbt
, JBT_RESOLUTION_VGA
);
633 dev_err(&jbt
->spi_dev
->dev
, "Unknown resolution. Entering sleep mode.\n");
634 jbt6k74_enter_power_mode(jbt
, JBT_POWER_MODE_SLEEP
);
640 static int jbt6k74_set_power(struct lcd_device
*ld
, int power
) {
642 struct jbt_info
*jbt
= dev_get_drvdata(&ld
->dev
);
644 jbt
->blank_mode
= power
;
645 cancel_rearming_delayed_work(&jbt
->blank_work
);
648 case FB_BLANK_UNBLANK
:
649 dev_dbg(&jbt
->spi_dev
->dev
, "unblank\n");
650 rc
= jbt6k74_enter_power_mode(jbt
, JBT_POWER_MODE_NORMAL
);
652 case FB_BLANK_NORMAL
:
653 dev_dbg(&jbt
->spi_dev
->dev
, "blank\n");
654 rc
= schedule_delayed_work(&jbt
->blank_work
, HZ
);
656 case FB_BLANK_POWERDOWN
:
657 dev_dbg(&jbt
->spi_dev
->dev
, "powerdown\n");
658 rc
= schedule_delayed_work(&jbt
->blank_work
, HZ
);
667 static int jbt6k74_get_power(struct lcd_device
*ld
) {
668 struct jbt_info
*jbt
= dev_get_drvdata(&ld
->dev
);
670 switch (jbt
->power_mode
) {
671 case JBT_POWER_MODE_NORMAL
:
672 return FB_BLANK_UNBLANK
;
673 case JBT_POWER_MODE_SLEEP
:
674 return FB_BLANK_NORMAL
;
676 return JBT_POWER_MODE_DEEP_STANDBY
;
680 struct lcd_ops jbt6k74_lcd_ops
= {
681 .set_power
= jbt6k74_set_power
,
682 .get_power
= jbt6k74_get_power
,
683 .set_mode
= jbt6k74_set_mode
,
686 /* linux device model infrastructure */
688 static int __devinit
jbt_probe(struct spi_device
*spi
)
691 struct jbt_info
*jbt
;
692 struct jbt6k74_platform_data
*pdata
= spi
->dev
.platform_data
;
694 /* the controller doesn't have a MISO pin; we can't do detection */
696 spi
->mode
= SPI_CPOL
| SPI_CPHA
;
697 spi
->bits_per_word
= 9;
702 "error during spi_setup of jbt6k74 driver\n");
706 jbt
= kzalloc(sizeof(*jbt
), GFP_KERNEL
);
712 jbt
->lcd_dev
= lcd_device_register("jbt6k74-lcd", &spi
->dev
,
713 jbt
, &jbt6k74_lcd_ops
);
715 if (IS_ERR(jbt
->lcd_dev
)) {
716 rc
= PTR_ERR(jbt
->lcd_dev
);
717 goto err_free_drvdata
;
720 INIT_DELAYED_WORK(&jbt
->blank_work
, jbt_blank_worker
);
722 jbt
->resolution
= JBT_RESOLUTION_VGA
;
723 jbt
->power_mode
= JBT_POWER_MODE_DEEP_STANDBY
;
724 jbt
->last_sleep
= jiffies
+ msecs_to_jiffies(120);
725 mutex_init(&jbt
->lock
);
727 dev_set_drvdata(&spi
->dev
, jbt
);
729 rc
= jbt6k74_enter_power_mode(jbt
, JBT_POWER_MODE_NORMAL
);
731 dev_err(&spi
->dev
, "cannot enter NORMAL state\n");
732 goto err_unregister_lcd
;
735 rc
= sysfs_create_group(&spi
->dev
.kobj
, &jbt_attr_group
);
737 dev_err(&spi
->dev
, "cannot create sysfs group\n");
741 if (pdata
->probe_completed
)
742 (pdata
->probe_completed
)(&spi
->dev
);
747 jbt6k74_enter_power_mode(jbt
, JBT_POWER_MODE_DEEP_STANDBY
);
749 lcd_device_unregister(jbt
->lcd_dev
);
751 dev_set_drvdata(&spi
->dev
, NULL
);
757 static int __devexit
jbt_remove(struct spi_device
*spi
)
759 struct jbt_info
*jbt
= dev_get_drvdata(&spi
->dev
);
761 /* We don't want to switch off the display in case the user
762 * accidentially unloads the module (whose use count normally is 0) */
763 jbt6k74_enter_power_mode(jbt
, JBT_POWER_MODE_NORMAL
);
765 sysfs_remove_group(&spi
->dev
.kobj
, &jbt_attr_group
);
766 dev_set_drvdata(&spi
->dev
, NULL
);
768 lcd_device_unregister(jbt
->lcd_dev
);
776 static int jbt_suspend(struct spi_device
*spi
, pm_message_t state
)
778 struct jbt_info
*jbt
= dev_get_drvdata(&spi
->dev
);
780 jbt
->suspend_mode
= jbt
->power_mode
;
782 jbt6k74_enter_power_mode(jbt
, JBT_POWER_MODE_DEEP_STANDBY
);
785 dev_info(&spi
->dev
, "suspended\n");
790 int jbt6k74_resume(struct spi_device
*spi
)
792 struct jbt_info
*jbt
= dev_get_drvdata(&spi
->dev
);
795 jbt6k74_enter_power_mode(jbt
, jbt
->suspend_mode
);
797 dev_info(&spi
->dev
, "resumed\n");
801 EXPORT_SYMBOL_GPL(jbt6k74_resume
);
804 #define jbt_suspend NULL
805 #define jbt6k74_resume NULL
808 static struct spi_driver jbt6k74_driver
= {
811 .owner
= THIS_MODULE
,
815 .remove
= __devexit_p(jbt_remove
),
816 .suspend
= jbt_suspend
,
817 .resume
= jbt6k74_resume
,
820 static int __init
jbt_init(void)
822 return spi_register_driver(&jbt6k74_driver
);
825 static void __exit
jbt_exit(void)
827 spi_unregister_driver(&jbt6k74_driver
);
830 MODULE_DESCRIPTION("SPI driver for tpo JBT6K74-AS LCM control interface");
831 MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
832 MODULE_LICENSE("GPL");
834 module_init(jbt_init
);
835 module_exit(jbt_exit
);