Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 1 | /* |
| 2 | * LCD/Backlight Driver for Sharp Zaurus Handhelds (various models) |
| 3 | * |
| 4 | * Copyright (c) 2004-2006 Richard Purdie |
| 5 | * |
| 6 | * Based on Sharp's 2.4 Backlight Driver |
| 7 | * |
| 8 | * Copyright (c) 2008 Marvell International Ltd. |
Jingoo Han | 0885126 | 2012-12-17 16:00:14 -0800 | [diff] [blame] | 9 | * Converted to SPI device based LCD/Backlight device driver |
| 10 | * by Eric Miao <eric.miao@marvell.com> |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License version 2 as |
| 14 | * published by the Free Software Foundation. |
| 15 | * |
| 16 | */ |
| 17 | |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/delay.h> |
Eric Miao | ff7a4c7 | 2008-09-07 11:30:06 +0800 | [diff] [blame] | 22 | #include <linux/gpio.h> |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 23 | #include <linux/fb.h> |
| 24 | #include <linux/lcd.h> |
| 25 | #include <linux/spi/spi.h> |
| 26 | #include <linux/spi/corgi_lcd.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 27 | #include <linux/slab.h> |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 28 | #include <asm/mach/sharpsl_param.h> |
| 29 | |
| 30 | #define POWER_IS_ON(pwr) ((pwr) <= FB_BLANK_NORMAL) |
| 31 | |
| 32 | /* Register Addresses */ |
| 33 | #define RESCTL_ADRS 0x00 |
| 34 | #define PHACTRL_ADRS 0x01 |
| 35 | #define DUTYCTRL_ADRS 0x02 |
| 36 | #define POWERREG0_ADRS 0x03 |
| 37 | #define POWERREG1_ADRS 0x04 |
| 38 | #define GPOR3_ADRS 0x05 |
| 39 | #define PICTRL_ADRS 0x06 |
| 40 | #define POLCTRL_ADRS 0x07 |
| 41 | |
| 42 | /* Register Bit Definitions */ |
| 43 | #define RESCTL_QVGA 0x01 |
| 44 | #define RESCTL_VGA 0x00 |
| 45 | |
| 46 | #define POWER1_VW_ON 0x01 /* VW Supply FET ON */ |
| 47 | #define POWER1_GVSS_ON 0x02 /* GVSS(-8V) Power Supply ON */ |
| 48 | #define POWER1_VDD_ON 0x04 /* VDD(8V),SVSS(-4V) Power Supply ON */ |
| 49 | |
| 50 | #define POWER1_VW_OFF 0x00 /* VW Supply FET OFF */ |
| 51 | #define POWER1_GVSS_OFF 0x00 /* GVSS(-8V) Power Supply OFF */ |
| 52 | #define POWER1_VDD_OFF 0x00 /* VDD(8V),SVSS(-4V) Power Supply OFF */ |
| 53 | |
| 54 | #define POWER0_COM_DCLK 0x01 /* COM Voltage DC Bias DAC Serial Data Clock */ |
| 55 | #define POWER0_COM_DOUT 0x02 /* COM Voltage DC Bias DAC Serial Data Out */ |
| 56 | #define POWER0_DAC_ON 0x04 /* DAC Power Supply ON */ |
| 57 | #define POWER0_COM_ON 0x08 /* COM Power Supply ON */ |
| 58 | #define POWER0_VCC5_ON 0x10 /* VCC5 Power Supply ON */ |
| 59 | |
| 60 | #define POWER0_DAC_OFF 0x00 /* DAC Power Supply OFF */ |
| 61 | #define POWER0_COM_OFF 0x00 /* COM Power Supply OFF */ |
| 62 | #define POWER0_VCC5_OFF 0x00 /* VCC5 Power Supply OFF */ |
| 63 | |
| 64 | #define PICTRL_INIT_STATE 0x01 |
| 65 | #define PICTRL_INIOFF 0x02 |
| 66 | #define PICTRL_POWER_DOWN 0x04 |
| 67 | #define PICTRL_COM_SIGNAL_OFF 0x08 |
| 68 | #define PICTRL_DAC_SIGNAL_OFF 0x10 |
| 69 | |
| 70 | #define POLCTRL_SYNC_POL_FALL 0x01 |
| 71 | #define POLCTRL_EN_POL_FALL 0x02 |
| 72 | #define POLCTRL_DATA_POL_FALL 0x04 |
| 73 | #define POLCTRL_SYNC_ACT_H 0x08 |
| 74 | #define POLCTRL_EN_ACT_L 0x10 |
| 75 | |
| 76 | #define POLCTRL_SYNC_POL_RISE 0x00 |
| 77 | #define POLCTRL_EN_POL_RISE 0x00 |
| 78 | #define POLCTRL_DATA_POL_RISE 0x00 |
| 79 | #define POLCTRL_SYNC_ACT_L 0x00 |
| 80 | #define POLCTRL_EN_ACT_H 0x00 |
| 81 | |
| 82 | #define PHACTRL_PHASE_MANUAL 0x01 |
| 83 | #define DEFAULT_PHAD_QVGA (9) |
| 84 | #define DEFAULT_COMADJ (125) |
| 85 | |
| 86 | struct corgi_lcd { |
| 87 | struct spi_device *spi_dev; |
| 88 | struct lcd_device *lcd_dev; |
| 89 | struct backlight_device *bl_dev; |
| 90 | |
Eric Miao | bfdcaa3 | 2008-08-29 05:57:20 +0800 | [diff] [blame] | 91 | int limit_mask; |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 92 | int intensity; |
| 93 | int power; |
| 94 | int mode; |
| 95 | char buf[2]; |
| 96 | |
Eric Miao | ff7a4c7 | 2008-09-07 11:30:06 +0800 | [diff] [blame] | 97 | int gpio_backlight_on; |
| 98 | int gpio_backlight_cont; |
| 99 | int gpio_backlight_cont_inverted; |
| 100 | |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 101 | void (*kick_battery)(void); |
| 102 | }; |
| 103 | |
| 104 | static int corgi_ssp_lcdtg_send(struct corgi_lcd *lcd, int reg, uint8_t val); |
| 105 | |
Eric Miao | bfdcaa3 | 2008-08-29 05:57:20 +0800 | [diff] [blame] | 106 | static struct corgi_lcd *the_corgi_lcd; |
| 107 | static unsigned long corgibl_flags; |
| 108 | #define CORGIBL_SUSPENDED 0x01 |
| 109 | #define CORGIBL_BATTLOW 0x02 |
| 110 | |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 111 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 112 | * This is only a pseudo I2C interface. We can't use the standard kernel |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 113 | * routines as the interface is write only. We just assume the data is acked... |
| 114 | */ |
| 115 | static void lcdtg_ssp_i2c_send(struct corgi_lcd *lcd, uint8_t data) |
| 116 | { |
| 117 | corgi_ssp_lcdtg_send(lcd, POWERREG0_ADRS, data); |
| 118 | udelay(10); |
| 119 | } |
| 120 | |
| 121 | static void lcdtg_i2c_send_bit(struct corgi_lcd *lcd, uint8_t data) |
| 122 | { |
| 123 | lcdtg_ssp_i2c_send(lcd, data); |
| 124 | lcdtg_ssp_i2c_send(lcd, data | POWER0_COM_DCLK); |
| 125 | lcdtg_ssp_i2c_send(lcd, data); |
| 126 | } |
| 127 | |
| 128 | static void lcdtg_i2c_send_start(struct corgi_lcd *lcd, uint8_t base) |
| 129 | { |
| 130 | lcdtg_ssp_i2c_send(lcd, base | POWER0_COM_DCLK | POWER0_COM_DOUT); |
| 131 | lcdtg_ssp_i2c_send(lcd, base | POWER0_COM_DCLK); |
| 132 | lcdtg_ssp_i2c_send(lcd, base); |
| 133 | } |
| 134 | |
| 135 | static void lcdtg_i2c_send_stop(struct corgi_lcd *lcd, uint8_t base) |
| 136 | { |
| 137 | lcdtg_ssp_i2c_send(lcd, base); |
| 138 | lcdtg_ssp_i2c_send(lcd, base | POWER0_COM_DCLK); |
| 139 | lcdtg_ssp_i2c_send(lcd, base | POWER0_COM_DCLK | POWER0_COM_DOUT); |
| 140 | } |
| 141 | |
| 142 | static void lcdtg_i2c_send_byte(struct corgi_lcd *lcd, |
| 143 | uint8_t base, uint8_t data) |
| 144 | { |
| 145 | int i; |
| 146 | for (i = 0; i < 8; i++) { |
| 147 | if (data & 0x80) |
| 148 | lcdtg_i2c_send_bit(lcd, base | POWER0_COM_DOUT); |
| 149 | else |
| 150 | lcdtg_i2c_send_bit(lcd, base); |
| 151 | data <<= 1; |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | static void lcdtg_i2c_wait_ack(struct corgi_lcd *lcd, uint8_t base) |
| 156 | { |
| 157 | lcdtg_i2c_send_bit(lcd, base); |
| 158 | } |
| 159 | |
| 160 | static void lcdtg_set_common_voltage(struct corgi_lcd *lcd, |
| 161 | uint8_t base_data, uint8_t data) |
| 162 | { |
| 163 | /* Set Common Voltage to M62332FP via I2C */ |
| 164 | lcdtg_i2c_send_start(lcd, base_data); |
| 165 | lcdtg_i2c_send_byte(lcd, base_data, 0x9c); |
| 166 | lcdtg_i2c_wait_ack(lcd, base_data); |
| 167 | lcdtg_i2c_send_byte(lcd, base_data, 0x00); |
| 168 | lcdtg_i2c_wait_ack(lcd, base_data); |
| 169 | lcdtg_i2c_send_byte(lcd, base_data, data); |
| 170 | lcdtg_i2c_wait_ack(lcd, base_data); |
| 171 | lcdtg_i2c_send_stop(lcd, base_data); |
| 172 | } |
| 173 | |
| 174 | static int corgi_ssp_lcdtg_send(struct corgi_lcd *lcd, int adrs, uint8_t data) |
| 175 | { |
| 176 | struct spi_message msg; |
| 177 | struct spi_transfer xfer = { |
| 178 | .len = 1, |
| 179 | .cs_change = 1, |
| 180 | .tx_buf = lcd->buf, |
| 181 | }; |
| 182 | |
| 183 | lcd->buf[0] = ((adrs & 0x07) << 5) | (data & 0x1f); |
| 184 | spi_message_init(&msg); |
| 185 | spi_message_add_tail(&xfer, &msg); |
| 186 | |
| 187 | return spi_sync(lcd->spi_dev, &msg); |
| 188 | } |
| 189 | |
| 190 | /* Set Phase Adjust */ |
| 191 | static void lcdtg_set_phadadj(struct corgi_lcd *lcd, int mode) |
| 192 | { |
| 193 | int adj; |
| 194 | |
Jingoo Han | 0885126 | 2012-12-17 16:00:14 -0800 | [diff] [blame] | 195 | switch (mode) { |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 196 | case CORGI_LCD_MODE_VGA: |
| 197 | /* Setting for VGA */ |
| 198 | adj = sharpsl_param.phadadj; |
| 199 | adj = (adj < 0) ? PHACTRL_PHASE_MANUAL : |
| 200 | PHACTRL_PHASE_MANUAL | ((adj & 0xf) << 1); |
| 201 | break; |
| 202 | case CORGI_LCD_MODE_QVGA: |
| 203 | default: |
| 204 | /* Setting for QVGA */ |
| 205 | adj = (DEFAULT_PHAD_QVGA << 1) | PHACTRL_PHASE_MANUAL; |
| 206 | break; |
| 207 | } |
| 208 | |
| 209 | corgi_ssp_lcdtg_send(lcd, PHACTRL_ADRS, adj); |
| 210 | } |
| 211 | |
| 212 | static void corgi_lcd_power_on(struct corgi_lcd *lcd) |
| 213 | { |
| 214 | int comadj; |
| 215 | |
| 216 | /* Initialize Internal Logic & Port */ |
| 217 | corgi_ssp_lcdtg_send(lcd, PICTRL_ADRS, |
| 218 | PICTRL_POWER_DOWN | PICTRL_INIOFF | |
| 219 | PICTRL_INIT_STATE | PICTRL_COM_SIGNAL_OFF | |
| 220 | PICTRL_DAC_SIGNAL_OFF); |
| 221 | |
| 222 | corgi_ssp_lcdtg_send(lcd, POWERREG0_ADRS, |
| 223 | POWER0_COM_DCLK | POWER0_COM_DOUT | POWER0_DAC_OFF | |
| 224 | POWER0_COM_OFF | POWER0_VCC5_OFF); |
| 225 | |
| 226 | corgi_ssp_lcdtg_send(lcd, POWERREG1_ADRS, |
| 227 | POWER1_VW_OFF | POWER1_GVSS_OFF | POWER1_VDD_OFF); |
| 228 | |
| 229 | /* VDD(+8V), SVSS(-4V) ON */ |
| 230 | corgi_ssp_lcdtg_send(lcd, POWERREG1_ADRS, |
| 231 | POWER1_VW_OFF | POWER1_GVSS_OFF | POWER1_VDD_ON); |
| 232 | mdelay(3); |
| 233 | |
| 234 | /* DAC ON */ |
| 235 | corgi_ssp_lcdtg_send(lcd, POWERREG0_ADRS, |
| 236 | POWER0_COM_DCLK | POWER0_COM_DOUT | POWER0_DAC_ON | |
| 237 | POWER0_COM_OFF | POWER0_VCC5_OFF); |
| 238 | |
| 239 | /* INIB = H, INI = L */ |
| 240 | /* PICTL[0] = H , PICTL[1] = PICTL[2] = PICTL[4] = L */ |
| 241 | corgi_ssp_lcdtg_send(lcd, PICTRL_ADRS, |
| 242 | PICTRL_INIT_STATE | PICTRL_COM_SIGNAL_OFF); |
| 243 | |
| 244 | /* Set Common Voltage */ |
| 245 | comadj = sharpsl_param.comadj; |
| 246 | if (comadj < 0) |
| 247 | comadj = DEFAULT_COMADJ; |
| 248 | |
| 249 | lcdtg_set_common_voltage(lcd, POWER0_DAC_ON | POWER0_COM_OFF | |
| 250 | POWER0_VCC5_OFF, comadj); |
| 251 | |
| 252 | /* VCC5 ON, DAC ON */ |
| 253 | corgi_ssp_lcdtg_send(lcd, POWERREG0_ADRS, |
| 254 | POWER0_COM_DCLK | POWER0_COM_DOUT | POWER0_DAC_ON | |
| 255 | POWER0_COM_OFF | POWER0_VCC5_ON); |
| 256 | |
| 257 | /* GVSS(-8V) ON, VDD ON */ |
| 258 | corgi_ssp_lcdtg_send(lcd, POWERREG1_ADRS, |
| 259 | POWER1_VW_OFF | POWER1_GVSS_ON | POWER1_VDD_ON); |
| 260 | mdelay(2); |
| 261 | |
| 262 | /* COM SIGNAL ON (PICTL[3] = L) */ |
| 263 | corgi_ssp_lcdtg_send(lcd, PICTRL_ADRS, PICTRL_INIT_STATE); |
| 264 | |
| 265 | /* COM ON, DAC ON, VCC5_ON */ |
| 266 | corgi_ssp_lcdtg_send(lcd, POWERREG0_ADRS, |
| 267 | POWER0_COM_DCLK | POWER0_COM_DOUT | POWER0_DAC_ON | |
| 268 | POWER0_COM_ON | POWER0_VCC5_ON); |
| 269 | |
| 270 | /* VW ON, GVSS ON, VDD ON */ |
| 271 | corgi_ssp_lcdtg_send(lcd, POWERREG1_ADRS, |
| 272 | POWER1_VW_ON | POWER1_GVSS_ON | POWER1_VDD_ON); |
| 273 | |
| 274 | /* Signals output enable */ |
| 275 | corgi_ssp_lcdtg_send(lcd, PICTRL_ADRS, 0); |
| 276 | |
| 277 | /* Set Phase Adjust */ |
| 278 | lcdtg_set_phadadj(lcd, lcd->mode); |
| 279 | |
| 280 | /* Initialize for Input Signals from ATI */ |
| 281 | corgi_ssp_lcdtg_send(lcd, POLCTRL_ADRS, |
| 282 | POLCTRL_SYNC_POL_RISE | POLCTRL_EN_POL_RISE | |
| 283 | POLCTRL_DATA_POL_RISE | POLCTRL_SYNC_ACT_L | |
| 284 | POLCTRL_EN_ACT_H); |
| 285 | udelay(1000); |
| 286 | |
| 287 | switch (lcd->mode) { |
| 288 | case CORGI_LCD_MODE_VGA: |
| 289 | corgi_ssp_lcdtg_send(lcd, RESCTL_ADRS, RESCTL_VGA); |
| 290 | break; |
| 291 | case CORGI_LCD_MODE_QVGA: |
| 292 | default: |
| 293 | corgi_ssp_lcdtg_send(lcd, RESCTL_ADRS, RESCTL_QVGA); |
| 294 | break; |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | static void corgi_lcd_power_off(struct corgi_lcd *lcd) |
| 299 | { |
| 300 | /* 60Hz x 2 frame = 16.7msec x 2 = 33.4 msec */ |
| 301 | msleep(34); |
| 302 | |
| 303 | /* (1)VW OFF */ |
| 304 | corgi_ssp_lcdtg_send(lcd, POWERREG1_ADRS, |
| 305 | POWER1_VW_OFF | POWER1_GVSS_ON | POWER1_VDD_ON); |
| 306 | |
| 307 | /* (2)COM OFF */ |
| 308 | corgi_ssp_lcdtg_send(lcd, PICTRL_ADRS, PICTRL_COM_SIGNAL_OFF); |
| 309 | corgi_ssp_lcdtg_send(lcd, POWERREG0_ADRS, |
| 310 | POWER0_DAC_ON | POWER0_COM_OFF | POWER0_VCC5_ON); |
| 311 | |
| 312 | /* (3)Set Common Voltage Bias 0V */ |
| 313 | lcdtg_set_common_voltage(lcd, POWER0_DAC_ON | POWER0_COM_OFF | |
| 314 | POWER0_VCC5_ON, 0); |
| 315 | |
| 316 | /* (4)GVSS OFF */ |
| 317 | corgi_ssp_lcdtg_send(lcd, POWERREG1_ADRS, |
| 318 | POWER1_VW_OFF | POWER1_GVSS_OFF | POWER1_VDD_ON); |
| 319 | |
| 320 | /* (5)VCC5 OFF */ |
| 321 | corgi_ssp_lcdtg_send(lcd, POWERREG0_ADRS, |
| 322 | POWER0_DAC_ON | POWER0_COM_OFF | POWER0_VCC5_OFF); |
| 323 | |
| 324 | /* (6)Set PDWN, INIOFF, DACOFF */ |
| 325 | corgi_ssp_lcdtg_send(lcd, PICTRL_ADRS, |
| 326 | PICTRL_INIOFF | PICTRL_DAC_SIGNAL_OFF | |
| 327 | PICTRL_POWER_DOWN | PICTRL_COM_SIGNAL_OFF); |
| 328 | |
| 329 | /* (7)DAC OFF */ |
| 330 | corgi_ssp_lcdtg_send(lcd, POWERREG0_ADRS, |
| 331 | POWER0_DAC_OFF | POWER0_COM_OFF | POWER0_VCC5_OFF); |
| 332 | |
| 333 | /* (8)VDD OFF */ |
| 334 | corgi_ssp_lcdtg_send(lcd, POWERREG1_ADRS, |
| 335 | POWER1_VW_OFF | POWER1_GVSS_OFF | POWER1_VDD_OFF); |
| 336 | } |
| 337 | |
| 338 | static int corgi_lcd_set_mode(struct lcd_device *ld, struct fb_videomode *m) |
| 339 | { |
Jingoo Han | 47cf076 | 2013-02-21 16:43:51 -0800 | [diff] [blame] | 340 | struct corgi_lcd *lcd = lcd_get_data(ld); |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 341 | int mode = CORGI_LCD_MODE_QVGA; |
| 342 | |
| 343 | if (m->xres == 640 || m->xres == 480) |
| 344 | mode = CORGI_LCD_MODE_VGA; |
| 345 | |
| 346 | if (lcd->mode == mode) |
| 347 | return 0; |
| 348 | |
| 349 | lcdtg_set_phadadj(lcd, mode); |
| 350 | |
| 351 | switch (mode) { |
| 352 | case CORGI_LCD_MODE_VGA: |
| 353 | corgi_ssp_lcdtg_send(lcd, RESCTL_ADRS, RESCTL_VGA); |
| 354 | break; |
| 355 | case CORGI_LCD_MODE_QVGA: |
| 356 | default: |
| 357 | corgi_ssp_lcdtg_send(lcd, RESCTL_ADRS, RESCTL_QVGA); |
| 358 | break; |
| 359 | } |
| 360 | |
| 361 | lcd->mode = mode; |
| 362 | return 0; |
| 363 | } |
| 364 | |
| 365 | static int corgi_lcd_set_power(struct lcd_device *ld, int power) |
| 366 | { |
Jingoo Han | 47cf076 | 2013-02-21 16:43:51 -0800 | [diff] [blame] | 367 | struct corgi_lcd *lcd = lcd_get_data(ld); |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 368 | |
| 369 | if (POWER_IS_ON(power) && !POWER_IS_ON(lcd->power)) |
| 370 | corgi_lcd_power_on(lcd); |
| 371 | |
| 372 | if (!POWER_IS_ON(power) && POWER_IS_ON(lcd->power)) |
| 373 | corgi_lcd_power_off(lcd); |
| 374 | |
| 375 | lcd->power = power; |
| 376 | return 0; |
| 377 | } |
| 378 | |
| 379 | static int corgi_lcd_get_power(struct lcd_device *ld) |
| 380 | { |
Jingoo Han | 47cf076 | 2013-02-21 16:43:51 -0800 | [diff] [blame] | 381 | struct corgi_lcd *lcd = lcd_get_data(ld); |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 382 | |
| 383 | return lcd->power; |
| 384 | } |
| 385 | |
| 386 | static struct lcd_ops corgi_lcd_ops = { |
| 387 | .get_power = corgi_lcd_get_power, |
| 388 | .set_power = corgi_lcd_set_power, |
| 389 | .set_mode = corgi_lcd_set_mode, |
| 390 | }; |
| 391 | |
| 392 | static int corgi_bl_get_intensity(struct backlight_device *bd) |
| 393 | { |
Jingoo Han | 4d89c3b | 2013-02-21 16:43:48 -0800 | [diff] [blame] | 394 | struct corgi_lcd *lcd = bl_get_data(bd); |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 395 | |
| 396 | return lcd->intensity; |
| 397 | } |
| 398 | |
| 399 | static int corgi_bl_set_intensity(struct corgi_lcd *lcd, int intensity) |
| 400 | { |
Eric Miao | ff7a4c7 | 2008-09-07 11:30:06 +0800 | [diff] [blame] | 401 | int cont; |
| 402 | |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 403 | if (intensity > 0x10) |
| 404 | intensity += 0x10; |
| 405 | |
| 406 | corgi_ssp_lcdtg_send(lcd, DUTYCTRL_ADRS, intensity); |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 407 | |
Eric Miao | ff7a4c7 | 2008-09-07 11:30:06 +0800 | [diff] [blame] | 408 | /* Bit 5 via GPIO_BACKLIGHT_CONT */ |
| 409 | cont = !!(intensity & 0x20) ^ lcd->gpio_backlight_cont_inverted; |
| 410 | |
| 411 | if (gpio_is_valid(lcd->gpio_backlight_cont)) |
Marko Katic | 1581b08 | 2012-12-17 16:01:14 -0800 | [diff] [blame] | 412 | gpio_set_value_cansleep(lcd->gpio_backlight_cont, cont); |
Eric Miao | ff7a4c7 | 2008-09-07 11:30:06 +0800 | [diff] [blame] | 413 | |
| 414 | if (gpio_is_valid(lcd->gpio_backlight_on)) |
Marko Katic | 1581b08 | 2012-12-17 16:01:14 -0800 | [diff] [blame] | 415 | gpio_set_value_cansleep(lcd->gpio_backlight_on, intensity); |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 416 | |
| 417 | if (lcd->kick_battery) |
| 418 | lcd->kick_battery(); |
| 419 | |
Eric Miao | ff7a4c7 | 2008-09-07 11:30:06 +0800 | [diff] [blame] | 420 | lcd->intensity = intensity; |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 421 | return 0; |
| 422 | } |
| 423 | |
| 424 | static int corgi_bl_update_status(struct backlight_device *bd) |
| 425 | { |
Jingoo Han | 4d89c3b | 2013-02-21 16:43:48 -0800 | [diff] [blame] | 426 | struct corgi_lcd *lcd = bl_get_data(bd); |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 427 | int intensity = bd->props.brightness; |
| 428 | |
| 429 | if (bd->props.power != FB_BLANK_UNBLANK) |
| 430 | intensity = 0; |
| 431 | |
| 432 | if (bd->props.fb_blank != FB_BLANK_UNBLANK) |
| 433 | intensity = 0; |
| 434 | |
Eric Miao | bfdcaa3 | 2008-08-29 05:57:20 +0800 | [diff] [blame] | 435 | if (corgibl_flags & CORGIBL_SUSPENDED) |
| 436 | intensity = 0; |
Pavel Machek | 716bdf1 | 2009-11-06 15:58:31 +0000 | [diff] [blame] | 437 | |
| 438 | if ((corgibl_flags & CORGIBL_BATTLOW) && intensity > lcd->limit_mask) |
| 439 | intensity = lcd->limit_mask; |
Eric Miao | bfdcaa3 | 2008-08-29 05:57:20 +0800 | [diff] [blame] | 440 | |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 441 | return corgi_bl_set_intensity(lcd, intensity); |
| 442 | } |
| 443 | |
Dmitry Baryshkov | 5cbff96 | 2008-10-28 20:26:40 +0300 | [diff] [blame] | 444 | void corgi_lcd_limit_intensity(int limit) |
Eric Miao | bfdcaa3 | 2008-08-29 05:57:20 +0800 | [diff] [blame] | 445 | { |
| 446 | if (limit) |
| 447 | corgibl_flags |= CORGIBL_BATTLOW; |
| 448 | else |
| 449 | corgibl_flags &= ~CORGIBL_BATTLOW; |
| 450 | |
| 451 | backlight_update_status(the_corgi_lcd->bl_dev); |
| 452 | } |
Dmitry Baryshkov | 5cbff96 | 2008-10-28 20:26:40 +0300 | [diff] [blame] | 453 | EXPORT_SYMBOL(corgi_lcd_limit_intensity); |
Eric Miao | bfdcaa3 | 2008-08-29 05:57:20 +0800 | [diff] [blame] | 454 | |
Emese Revfy | 9905a43 | 2009-12-14 00:58:57 +0100 | [diff] [blame] | 455 | static const struct backlight_ops corgi_bl_ops = { |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 456 | .get_brightness = corgi_bl_get_intensity, |
| 457 | .update_status = corgi_bl_update_status, |
| 458 | }; |
| 459 | |
Jingoo Han | bb07471 | 2013-04-29 16:17:41 -0700 | [diff] [blame] | 460 | #ifdef CONFIG_PM_SLEEP |
| 461 | static int corgi_lcd_suspend(struct device *dev) |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 462 | { |
Jingoo Han | bb07471 | 2013-04-29 16:17:41 -0700 | [diff] [blame] | 463 | struct corgi_lcd *lcd = dev_get_drvdata(dev); |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 464 | |
Eric Miao | bfdcaa3 | 2008-08-29 05:57:20 +0800 | [diff] [blame] | 465 | corgibl_flags |= CORGIBL_SUSPENDED; |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 466 | corgi_bl_set_intensity(lcd, 0); |
| 467 | corgi_lcd_set_power(lcd->lcd_dev, FB_BLANK_POWERDOWN); |
| 468 | return 0; |
| 469 | } |
| 470 | |
Jingoo Han | bb07471 | 2013-04-29 16:17:41 -0700 | [diff] [blame] | 471 | static int corgi_lcd_resume(struct device *dev) |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 472 | { |
Jingoo Han | bb07471 | 2013-04-29 16:17:41 -0700 | [diff] [blame] | 473 | struct corgi_lcd *lcd = dev_get_drvdata(dev); |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 474 | |
Eric Miao | bfdcaa3 | 2008-08-29 05:57:20 +0800 | [diff] [blame] | 475 | corgibl_flags &= ~CORGIBL_SUSPENDED; |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 476 | corgi_lcd_set_power(lcd->lcd_dev, FB_BLANK_UNBLANK); |
| 477 | backlight_update_status(lcd->bl_dev); |
| 478 | return 0; |
| 479 | } |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 480 | #endif |
| 481 | |
Jingoo Han | bb07471 | 2013-04-29 16:17:41 -0700 | [diff] [blame] | 482 | static SIMPLE_DEV_PM_OPS(corgi_lcd_pm_ops, corgi_lcd_suspend, corgi_lcd_resume); |
| 483 | |
Eric Miao | ff7a4c7 | 2008-09-07 11:30:06 +0800 | [diff] [blame] | 484 | static int setup_gpio_backlight(struct corgi_lcd *lcd, |
| 485 | struct corgi_lcd_platform_data *pdata) |
| 486 | { |
| 487 | struct spi_device *spi = lcd->spi_dev; |
| 488 | int err; |
| 489 | |
| 490 | lcd->gpio_backlight_on = -1; |
| 491 | lcd->gpio_backlight_cont = -1; |
| 492 | |
| 493 | if (gpio_is_valid(pdata->gpio_backlight_on)) { |
Jingoo Han | 4405d5d | 2012-07-30 14:40:45 -0700 | [diff] [blame] | 494 | err = devm_gpio_request(&spi->dev, pdata->gpio_backlight_on, |
| 495 | "BL_ON"); |
Eric Miao | ff7a4c7 | 2008-09-07 11:30:06 +0800 | [diff] [blame] | 496 | if (err) { |
Jingoo Han | 0885126 | 2012-12-17 16:00:14 -0800 | [diff] [blame] | 497 | dev_err(&spi->dev, |
| 498 | "failed to request GPIO%d for backlight_on\n", |
| 499 | pdata->gpio_backlight_on); |
Eric Miao | ff7a4c7 | 2008-09-07 11:30:06 +0800 | [diff] [blame] | 500 | return err; |
| 501 | } |
| 502 | |
| 503 | lcd->gpio_backlight_on = pdata->gpio_backlight_on; |
| 504 | gpio_direction_output(lcd->gpio_backlight_on, 0); |
| 505 | } |
| 506 | |
| 507 | if (gpio_is_valid(pdata->gpio_backlight_cont)) { |
Jingoo Han | 4405d5d | 2012-07-30 14:40:45 -0700 | [diff] [blame] | 508 | err = devm_gpio_request(&spi->dev, pdata->gpio_backlight_cont, |
| 509 | "BL_CONT"); |
Eric Miao | ff7a4c7 | 2008-09-07 11:30:06 +0800 | [diff] [blame] | 510 | if (err) { |
Jingoo Han | 0885126 | 2012-12-17 16:00:14 -0800 | [diff] [blame] | 511 | dev_err(&spi->dev, |
| 512 | "failed to request GPIO%d for backlight_cont\n", |
| 513 | pdata->gpio_backlight_cont); |
Jingoo Han | 4405d5d | 2012-07-30 14:40:45 -0700 | [diff] [blame] | 514 | return err; |
Eric Miao | ff7a4c7 | 2008-09-07 11:30:06 +0800 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | lcd->gpio_backlight_cont = pdata->gpio_backlight_cont; |
| 518 | |
| 519 | /* spitz and akita use both GPIOs for backlight, and |
| 520 | * have inverted polarity of GPIO_BACKLIGHT_CONT |
| 521 | */ |
| 522 | if (gpio_is_valid(lcd->gpio_backlight_on)) { |
| 523 | lcd->gpio_backlight_cont_inverted = 1; |
| 524 | gpio_direction_output(lcd->gpio_backlight_cont, 1); |
| 525 | } else { |
| 526 | lcd->gpio_backlight_cont_inverted = 0; |
| 527 | gpio_direction_output(lcd->gpio_backlight_cont, 0); |
| 528 | } |
| 529 | } |
| 530 | return 0; |
Eric Miao | ff7a4c7 | 2008-09-07 11:30:06 +0800 | [diff] [blame] | 531 | } |
| 532 | |
Bill Pemberton | 1b9e450 | 2012-11-19 13:21:46 -0500 | [diff] [blame] | 533 | static int corgi_lcd_probe(struct spi_device *spi) |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 534 | { |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 535 | struct backlight_properties props; |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 536 | struct corgi_lcd_platform_data *pdata = spi->dev.platform_data; |
| 537 | struct corgi_lcd *lcd; |
| 538 | int ret = 0; |
| 539 | |
| 540 | if (pdata == NULL) { |
| 541 | dev_err(&spi->dev, "platform data not available\n"); |
| 542 | return -EINVAL; |
| 543 | } |
| 544 | |
Jingoo Han | 06c96f1 | 2012-05-29 15:07:22 -0700 | [diff] [blame] | 545 | lcd = devm_kzalloc(&spi->dev, sizeof(struct corgi_lcd), GFP_KERNEL); |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 546 | if (!lcd) { |
| 547 | dev_err(&spi->dev, "failed to allocate memory\n"); |
| 548 | return -ENOMEM; |
| 549 | } |
| 550 | |
| 551 | lcd->spi_dev = spi; |
| 552 | |
| 553 | lcd->lcd_dev = lcd_device_register("corgi_lcd", &spi->dev, |
| 554 | lcd, &corgi_lcd_ops); |
Jingoo Han | 06c96f1 | 2012-05-29 15:07:22 -0700 | [diff] [blame] | 555 | if (IS_ERR(lcd->lcd_dev)) |
| 556 | return PTR_ERR(lcd->lcd_dev); |
| 557 | |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 558 | lcd->power = FB_BLANK_POWERDOWN; |
| 559 | lcd->mode = (pdata) ? pdata->init_mode : CORGI_LCD_MODE_VGA; |
| 560 | |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 561 | memset(&props, 0, sizeof(struct backlight_properties)); |
Matthew Garrett | bb7ca74 | 2011-03-22 16:30:21 -0700 | [diff] [blame] | 562 | props.type = BACKLIGHT_RAW; |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 563 | props.max_brightness = pdata->max_intensity; |
| 564 | lcd->bl_dev = backlight_device_register("corgi_bl", &spi->dev, lcd, |
| 565 | &corgi_bl_ops, &props); |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 566 | if (IS_ERR(lcd->bl_dev)) { |
| 567 | ret = PTR_ERR(lcd->bl_dev); |
| 568 | goto err_unregister_lcd; |
| 569 | } |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 570 | lcd->bl_dev->props.brightness = pdata->default_intensity; |
| 571 | lcd->bl_dev->props.power = FB_BLANK_UNBLANK; |
| 572 | |
Eric Miao | ff7a4c7 | 2008-09-07 11:30:06 +0800 | [diff] [blame] | 573 | ret = setup_gpio_backlight(lcd, pdata); |
| 574 | if (ret) |
| 575 | goto err_unregister_bl; |
| 576 | |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 577 | lcd->kick_battery = pdata->kick_battery; |
| 578 | |
Jingoo Han | 9319dfa | 2013-02-21 16:43:42 -0800 | [diff] [blame] | 579 | spi_set_drvdata(spi, lcd); |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 580 | corgi_lcd_set_power(lcd->lcd_dev, FB_BLANK_UNBLANK); |
| 581 | backlight_update_status(lcd->bl_dev); |
Eric Miao | bfdcaa3 | 2008-08-29 05:57:20 +0800 | [diff] [blame] | 582 | |
| 583 | lcd->limit_mask = pdata->limit_mask; |
| 584 | the_corgi_lcd = lcd; |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 585 | return 0; |
| 586 | |
Eric Miao | ff7a4c7 | 2008-09-07 11:30:06 +0800 | [diff] [blame] | 587 | err_unregister_bl: |
| 588 | backlight_device_unregister(lcd->bl_dev); |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 589 | err_unregister_lcd: |
| 590 | lcd_device_unregister(lcd->lcd_dev); |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 591 | return ret; |
| 592 | } |
| 593 | |
Bill Pemberton | 7e4b9d0 | 2012-11-19 13:26:34 -0500 | [diff] [blame] | 594 | static int corgi_lcd_remove(struct spi_device *spi) |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 595 | { |
Jingoo Han | 9319dfa | 2013-02-21 16:43:42 -0800 | [diff] [blame] | 596 | struct corgi_lcd *lcd = spi_get_drvdata(spi); |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 597 | |
| 598 | lcd->bl_dev->props.power = FB_BLANK_UNBLANK; |
| 599 | lcd->bl_dev->props.brightness = 0; |
| 600 | backlight_update_status(lcd->bl_dev); |
| 601 | backlight_device_unregister(lcd->bl_dev); |
| 602 | |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 603 | corgi_lcd_set_power(lcd->lcd_dev, FB_BLANK_POWERDOWN); |
| 604 | lcd_device_unregister(lcd->lcd_dev); |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 605 | |
| 606 | return 0; |
| 607 | } |
| 608 | |
| 609 | static struct spi_driver corgi_lcd_driver = { |
| 610 | .driver = { |
| 611 | .name = "corgi-lcd", |
| 612 | .owner = THIS_MODULE, |
Jingoo Han | bb07471 | 2013-04-29 16:17:41 -0700 | [diff] [blame] | 613 | .pm = &corgi_lcd_pm_ops, |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 614 | }, |
| 615 | .probe = corgi_lcd_probe, |
Bill Pemberton | d1723fa | 2012-11-19 13:21:09 -0500 | [diff] [blame] | 616 | .remove = corgi_lcd_remove, |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 617 | }; |
| 618 | |
Axel Lin | 462dd83 | 2012-03-23 15:01:59 -0700 | [diff] [blame] | 619 | module_spi_driver(corgi_lcd_driver); |
Eric Miao | b18250a | 2008-08-29 04:21:44 +0800 | [diff] [blame] | 620 | |
| 621 | MODULE_DESCRIPTION("LCD and backlight driver for SHARP C7x0/Cxx00"); |
| 622 | MODULE_AUTHOR("Eric Miao <eric.miao@marvell.com>"); |
| 623 | MODULE_LICENSE("GPL"); |
Anton Vorontsov | e0626e3 | 2009-09-22 16:46:08 -0700 | [diff] [blame] | 624 | MODULE_ALIAS("spi:corgi-lcd"); |