1 /* 2 * lms283gf05.c -- support for Samsung LMS283GF05 LCD 3 * 4 * Copyright (c) 2009 Marek Vasut <marek.vasut@gmail.com> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 2 as 8 * published by the Free Software Foundation. 9 */ 10 11 #include <linux/device.h> 12 #include <linux/kernel.h> 13 #include <linux/delay.h> 14 #include <linux/slab.h> 15 #include <linux/gpio.h> 16 #include <linux/lcd.h> 17 18 #include <linux/spi/spi.h> 19 #include <linux/spi/lms283gf05.h> 20 21 struct lms283gf05_state { 22 struct spi_device *spi; 23 struct lcd_device *ld; 24 }; 25 26 struct lms283gf05_seq { 27 unsigned char reg; 28 unsigned short value; 29 unsigned char delay; 30 }; 31 32 /* Magic sequences supplied by manufacturer, for details refer to datasheet */ 33 static struct lms283gf05_seq disp_initseq[] = { 34 /* REG, VALUE, DELAY */ 35 { 0x07, 0x0000, 0 }, 36 { 0x13, 0x0000, 10 }, 37 38 { 0x11, 0x3004, 0 }, 39 { 0x14, 0x200F, 0 }, 40 { 0x10, 0x1a20, 0 }, 41 { 0x13, 0x0040, 50 }, 42 43 { 0x13, 0x0060, 0 }, 44 { 0x13, 0x0070, 200 }, 45 46 { 0x01, 0x0127, 0 }, 47 { 0x02, 0x0700, 0 }, 48 { 0x03, 0x1030, 0 }, 49 { 0x08, 0x0208, 0 }, 50 { 0x0B, 0x0620, 0 }, 51 { 0x0C, 0x0110, 0 }, 52 { 0x30, 0x0120, 0 }, 53 { 0x31, 0x0127, 0 }, 54 { 0x32, 0x0000, 0 }, 55 { 0x33, 0x0503, 0 }, 56 { 0x34, 0x0727, 0 }, 57 { 0x35, 0x0124, 0 }, 58 { 0x36, 0x0706, 0 }, 59 { 0x37, 0x0701, 0 }, 60 { 0x38, 0x0F00, 0 }, 61 { 0x39, 0x0F00, 0 }, 62 { 0x40, 0x0000, 0 }, 63 { 0x41, 0x0000, 0 }, 64 { 0x42, 0x013f, 0 }, 65 { 0x43, 0x0000, 0 }, 66 { 0x44, 0x013f, 0 }, 67 { 0x45, 0x0000, 0 }, 68 { 0x46, 0xef00, 0 }, 69 { 0x47, 0x013f, 0 }, 70 { 0x48, 0x0000, 0 }, 71 { 0x07, 0x0015, 30 }, 72 73 { 0x07, 0x0017, 0 }, 74 75 { 0x20, 0x0000, 0 }, 76 { 0x21, 0x0000, 0 }, 77 { 0x22, 0x0000, 0 } 78 }; 79 80 static struct lms283gf05_seq disp_pdwnseq[] = { 81 { 0x07, 0x0016, 30 }, 82 83 { 0x07, 0x0004, 0 }, 84 { 0x10, 0x0220, 20 }, 85 86 { 0x13, 0x0060, 50 }, 87 88 { 0x13, 0x0040, 50 }, 89 90 { 0x13, 0x0000, 0 }, 91 { 0x10, 0x0000, 0 } 92 }; 93 94 95 static void lms283gf05_reset(unsigned long gpio, bool inverted) 96 { 97 gpio_set_value(gpio, !inverted); 98 mdelay(100); 99 gpio_set_value(gpio, inverted); 100 mdelay(20); 101 gpio_set_value(gpio, !inverted); 102 mdelay(20); 103 } 104 105 static void lms283gf05_toggle(struct spi_device *spi, 106 struct lms283gf05_seq *seq, int sz) 107 { 108 char buf[3]; 109 int i; 110 111 for (i = 0; i < sz; i++) { 112 buf[0] = 0x74; 113 buf[1] = 0x00; 114 buf[2] = seq[i].reg; 115 spi_write(spi, buf, 3); 116 117 buf[0] = 0x76; 118 buf[1] = seq[i].value >> 8; 119 buf[2] = seq[i].value & 0xff; 120 spi_write(spi, buf, 3); 121 122 mdelay(seq[i].delay); 123 } 124 } 125 126 static int lms283gf05_power_set(struct lcd_device *ld, int power) 127 { 128 struct lms283gf05_state *st = lcd_get_data(ld); 129 struct spi_device *spi = st->spi; 130 struct lms283gf05_pdata *pdata = spi->dev.platform_data; 131 132 if (power <= FB_BLANK_NORMAL) { 133 if (pdata) 134 lms283gf05_reset(pdata->reset_gpio, 135 pdata->reset_inverted); 136 lms283gf05_toggle(spi, disp_initseq, ARRAY_SIZE(disp_initseq)); 137 } else { 138 lms283gf05_toggle(spi, disp_pdwnseq, ARRAY_SIZE(disp_pdwnseq)); 139 if (pdata) 140 gpio_set_value(pdata->reset_gpio, 141 pdata->reset_inverted); 142 } 143 144 return 0; 145 } 146 147 static struct lcd_ops lms_ops = { 148 .set_power = lms283gf05_power_set, 149 .get_power = NULL, 150 }; 151 152 static int __devinit lms283gf05_probe(struct spi_device *spi) 153 { 154 struct lms283gf05_state *st; 155 struct lms283gf05_pdata *pdata = spi->dev.platform_data; 156 struct lcd_device *ld; 157 int ret = 0; 158 159 if (pdata != NULL) { 160 ret = gpio_request(pdata->reset_gpio, "LMS285GF05 RESET"); 161 if (ret) 162 return ret; 163 164 ret = gpio_direction_output(pdata->reset_gpio, 165 !pdata->reset_inverted); 166 if (ret) 167 goto err; 168 } 169 170 st = kzalloc(sizeof(struct lms283gf05_state), GFP_KERNEL); 171 if (st == NULL) { 172 dev_err(&spi->dev, "No memory for device state\n"); 173 ret = -ENOMEM; 174 goto err; 175 } 176 177 ld = lcd_device_register("lms283gf05", &spi->dev, st, &lms_ops); 178 if (IS_ERR(ld)) { 179 ret = PTR_ERR(ld); 180 goto err2; 181 } 182 183 st->spi = spi; 184 st->ld = ld; 185 186 dev_set_drvdata(&spi->dev, st); 187 188 /* kick in the LCD */ 189 if (pdata) 190 lms283gf05_reset(pdata->reset_gpio, pdata->reset_inverted); 191 lms283gf05_toggle(spi, disp_initseq, ARRAY_SIZE(disp_initseq)); 192 193 return 0; 194 195 err2: 196 kfree(st); 197 err: 198 if (pdata != NULL) 199 gpio_free(pdata->reset_gpio); 200 201 return ret; 202 } 203 204 static int __devexit lms283gf05_remove(struct spi_device *spi) 205 { 206 struct lms283gf05_state *st = dev_get_drvdata(&spi->dev); 207 struct lms283gf05_pdata *pdata = st->spi->dev.platform_data; 208 209 lcd_device_unregister(st->ld); 210 211 if (pdata != NULL) 212 gpio_free(pdata->reset_gpio); 213 214 kfree(st); 215 216 return 0; 217 } 218 219 static struct spi_driver lms283gf05_driver = { 220 .driver = { 221 .name = "lms283gf05", 222 .owner = THIS_MODULE, 223 }, 224 .probe = lms283gf05_probe, 225 .remove = __devexit_p(lms283gf05_remove), 226 }; 227 228 static __init int lms283gf05_init(void) 229 { 230 return spi_register_driver(&lms283gf05_driver); 231 } 232 233 static __exit void lms283gf05_exit(void) 234 { 235 spi_unregister_driver(&lms283gf05_driver); 236 } 237 238 module_init(lms283gf05_init); 239 module_exit(lms283gf05_exit); 240 241 MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>"); 242 MODULE_DESCRIPTION("LCD283GF05 LCD"); 243 MODULE_LICENSE("GPL v2"); 244