24 #include <linux/wait.h>
25 #include <linux/module.h>
33 #define SLEEPMSEC 0x1000
35 #define DEFMASK 0xFF00
36 #define COMMAND_ONLY 0xFE
37 #define DATA_ONLY 0xFF
39 #define MAX_GAMMA_LEVEL 5
40 #define GAMMA_TABLE_COUNT 21
42 #define MIN_BRIGHTNESS 0
43 #define MAX_BRIGHTNESS 255
44 #define DEFAULT_BRIGHTNESS 150
55 static const unsigned short seq_display_on[] = {
60 static const unsigned short seq_display_off[] = {
65 static const unsigned short seq_stand_by_on[] = {
71 static const unsigned short seq_stand_by_off[] = {
77 static const unsigned short seq_setting[] = {
130 static const unsigned int ams369fg06_22_250[] = {
131 0x00, 0x3f, 0x2a, 0x27, 0x27, 0x1f, 0x44,
132 0x00, 0x00, 0x17, 0x24, 0x26, 0x1f, 0x43,
133 0x00, 0x3f, 0x2a, 0x25, 0x24, 0x1b, 0x5c,
136 static const unsigned int ams369fg06_22_200[] = {
137 0x00, 0x3f, 0x28, 0x29, 0x27, 0x21, 0x3e,
138 0x00, 0x00, 0x10, 0x25, 0x27, 0x20, 0x3d,
139 0x00, 0x3f, 0x28, 0x27, 0x25, 0x1d, 0x53,
142 static const unsigned int ams369fg06_22_150[] = {
143 0x00, 0x3f, 0x2d, 0x29, 0x28, 0x23, 0x37,
144 0x00, 0x00, 0x0b, 0x25, 0x28, 0x22, 0x36,
145 0x00, 0x3f, 0x2b, 0x28, 0x26, 0x1f, 0x4a,
148 static const unsigned int ams369fg06_22_100[] = {
149 0x00, 0x3f, 0x30, 0x2a, 0x2b, 0x24, 0x2f,
150 0x00, 0x00, 0x00, 0x25, 0x29, 0x24, 0x2e,
151 0x00, 0x3f, 0x2f, 0x29, 0x29, 0x21, 0x3f,
154 static const unsigned int ams369fg06_22_50[] = {
155 0x00, 0x3f, 0x3c, 0x2c, 0x2d, 0x27, 0x24,
156 0x00, 0x00, 0x00, 0x22, 0x2a, 0x27, 0x23,
157 0x00, 0x3f, 0x3b, 0x2c, 0x2b, 0x24, 0x31,
165 .gamma_22_table[0] = (
unsigned int *)&ams369fg06_22_50,
167 .gamma_22_table[2] = (
unsigned int *)&ams369fg06_22_150,
169 .gamma_22_table[4] = (
unsigned int *)&ams369fg06_22_250,
182 buf[0] = (addr << 8) | data;
184 spi_message_init(&msg);
185 spi_message_add_tail(&xfer, &msg);
196 ret = ams369fg06_spi_write_byte(lcd, 0x70, address);
198 ret = ams369fg06_spi_write_byte(lcd, 0x72, command);
203 static int ams369fg06_panel_send_sequence(
struct ams369fg06 *lcd,
204 const unsigned short *wbuf)
210 ret = ams369fg06_spi_write(lcd, wbuf[
i], wbuf[i+1]);
221 static int _ams369fg06_gamma_ctl(
struct ams369fg06 *lcd,
222 const unsigned int *
gamma)
228 ret = ams369fg06_spi_write(lcd, 0x40 + i, gamma[i]);
229 ret = ams369fg06_spi_write(lcd, 0x50 + i, gamma[i+7*1]);
230 ret = ams369fg06_spi_write(lcd, 0x60 + i, gamma[i+7*2]);
232 dev_err(lcd->
dev,
"failed to set gamma table.\n");
246 if ((brightness >= 0) && (brightness <= 50))
248 else if ((brightness > 50) && (brightness <= 100))
250 else if ((brightness > 100) && (brightness <= 150))
252 else if ((brightness > 150) && (brightness <= 200))
254 else if ((brightness > 200) && (brightness <= 255))
257 ret = _ams369fg06_gamma_ctl(lcd, gamma_table.
gamma_22_table[gamma]);
262 static int ams369fg06_ldi_init(
struct ams369fg06 *lcd)
265 static const unsigned short *init_seq[] = {
271 ret = ams369fg06_panel_send_sequence(lcd, init_seq[i]);
279 static int ams369fg06_ldi_enable(
struct ams369fg06 *lcd)
282 static const unsigned short *init_seq[] = {
288 ret = ams369fg06_panel_send_sequence(lcd, init_seq[i]);
296 static int ams369fg06_ldi_disable(
struct ams369fg06 *lcd)
300 static const unsigned short *init_seq[] = {
306 ret = ams369fg06_panel_send_sequence(lcd, init_seq[i]);
314 static int ams369fg06_power_is_on(
int power)
319 static int ams369fg06_power_on(
struct ams369fg06 *lcd)
327 dev_err(lcd->
dev,
"platform data is NULL.\n");
333 dev_err(lcd->
dev,
"backlight device is NULL.\n");
353 ret = ams369fg06_ldi_init(lcd);
355 dev_err(lcd->
dev,
"failed to initialize ldi.\n");
359 ret = ams369fg06_ldi_enable(lcd);
366 ret = ams369fg06_gamma_ctl(lcd, bd->
props.brightness);
368 dev_err(lcd->
dev,
"lcd gamma setting failed.\n");
375 static int ams369fg06_power_off(
struct ams369fg06 *lcd)
386 ret = ams369fg06_ldi_disable(lcd);
403 static int ams369fg06_power(
struct ams369fg06 *lcd,
int power)
407 if (ams369fg06_power_is_on(power) &&
408 !ams369fg06_power_is_on(lcd->
power))
409 ret = ams369fg06_power_on(lcd);
410 else if (!ams369fg06_power_is_on(power) &&
411 ams369fg06_power_is_on(lcd->
power))
412 ret = ams369fg06_power_off(lcd);
427 static int ams369fg06_set_power(
struct lcd_device *
ld,
int power)
433 dev_err(lcd->
dev,
"power value should be 0, 1 or 4.\n");
437 return ams369fg06_power(lcd, power);
442 return bd->
props.brightness;
448 int brightness = bd->
props.brightness;
452 brightness > bd->
props.max_brightness) {
453 dev_err(&bd->
dev,
"lcd brightness should be %d to %d.\n",
458 ret = ams369fg06_gamma_ctl(lcd, bd->
props.brightness);
460 dev_err(&bd->
dev,
"lcd brightness setting failed.\n");
467 static struct lcd_ops ams369fg06_lcd_ops = {
468 .get_power = ams369fg06_get_power,
469 .set_power = ams369fg06_set_power,
472 static const struct backlight_ops ams369fg06_backlight_ops = {
473 .get_brightness = ams369fg06_get_brightness,
474 .update_status = ams369fg06_set_brightness,
499 lcd->dev = &spi->
dev;
501 lcd->lcd_pd = spi->
dev.platform_data;
503 dev_err(&spi->
dev,
"platform data is NULL\n");
508 &ams369fg06_lcd_ops);
519 &ams369fg06_backlight_ops, &props);
522 goto out_lcd_unregister;
528 if (!lcd->lcd_pd->lcd_enabled) {
542 dev_info(&spi->
dev,
"ams369fg06 panel driver has been probed.\n");
562 #if defined(CONFIG_PM)
563 static unsigned int before_power;
572 before_power = lcd->
power;
596 dev_dbg(&spi->
dev,
"before_power = %d\n", before_power);
598 ret = ams369fg06_power(lcd, before_power);
603 #define ams369fg06_suspend NULL
604 #define ams369fg06_resume NULL
607 static void ams369fg06_shutdown(
struct spi_device *spi)
614 static struct spi_driver ams369fg06_driver = {
616 .name =
"ams369fg06",
619 .probe = ams369fg06_probe,
621 .shutdown = ams369fg06_shutdown,