Marek Vasut | 5036cc4 | 2009-08-06 16:07:10 -0700 | [diff] [blame] | 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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 14 | #include <linux/slab.h> |
Marek Vasut | 5036cc4 | 2009-08-06 16:07:10 -0700 | [diff] [blame] | 15 | #include <linux/gpio.h> |
| 16 | #include <linux/lcd.h> |
| 17 | |
| 18 | #include <linux/spi/spi.h> |
| 19 | #include <linux/spi/lms283gf05.h> |
Paul Gortmaker | 355b200 | 2011-07-03 16:17:28 -0400 | [diff] [blame] | 20 | #include <linux/module.h> |
Marek Vasut | 5036cc4 | 2009-08-06 16:07:10 -0700 | [diff] [blame] | 21 | |
| 22 | struct lms283gf05_state { |
| 23 | struct spi_device *spi; |
| 24 | struct lcd_device *ld; |
| 25 | }; |
| 26 | |
| 27 | struct lms283gf05_seq { |
| 28 | unsigned char reg; |
| 29 | unsigned short value; |
| 30 | unsigned char delay; |
| 31 | }; |
| 32 | |
| 33 | /* Magic sequences supplied by manufacturer, for details refer to datasheet */ |
| 34 | static struct lms283gf05_seq disp_initseq[] = { |
| 35 | /* REG, VALUE, DELAY */ |
| 36 | { 0x07, 0x0000, 0 }, |
| 37 | { 0x13, 0x0000, 10 }, |
| 38 | |
| 39 | { 0x11, 0x3004, 0 }, |
| 40 | { 0x14, 0x200F, 0 }, |
| 41 | { 0x10, 0x1a20, 0 }, |
| 42 | { 0x13, 0x0040, 50 }, |
| 43 | |
| 44 | { 0x13, 0x0060, 0 }, |
| 45 | { 0x13, 0x0070, 200 }, |
| 46 | |
| 47 | { 0x01, 0x0127, 0 }, |
| 48 | { 0x02, 0x0700, 0 }, |
| 49 | { 0x03, 0x1030, 0 }, |
| 50 | { 0x08, 0x0208, 0 }, |
| 51 | { 0x0B, 0x0620, 0 }, |
| 52 | { 0x0C, 0x0110, 0 }, |
| 53 | { 0x30, 0x0120, 0 }, |
| 54 | { 0x31, 0x0127, 0 }, |
| 55 | { 0x32, 0x0000, 0 }, |
| 56 | { 0x33, 0x0503, 0 }, |
| 57 | { 0x34, 0x0727, 0 }, |
| 58 | { 0x35, 0x0124, 0 }, |
| 59 | { 0x36, 0x0706, 0 }, |
| 60 | { 0x37, 0x0701, 0 }, |
| 61 | { 0x38, 0x0F00, 0 }, |
| 62 | { 0x39, 0x0F00, 0 }, |
| 63 | { 0x40, 0x0000, 0 }, |
| 64 | { 0x41, 0x0000, 0 }, |
| 65 | { 0x42, 0x013f, 0 }, |
| 66 | { 0x43, 0x0000, 0 }, |
| 67 | { 0x44, 0x013f, 0 }, |
| 68 | { 0x45, 0x0000, 0 }, |
| 69 | { 0x46, 0xef00, 0 }, |
| 70 | { 0x47, 0x013f, 0 }, |
| 71 | { 0x48, 0x0000, 0 }, |
| 72 | { 0x07, 0x0015, 30 }, |
| 73 | |
| 74 | { 0x07, 0x0017, 0 }, |
| 75 | |
| 76 | { 0x20, 0x0000, 0 }, |
| 77 | { 0x21, 0x0000, 0 }, |
| 78 | { 0x22, 0x0000, 0 } |
| 79 | }; |
| 80 | |
| 81 | static struct lms283gf05_seq disp_pdwnseq[] = { |
| 82 | { 0x07, 0x0016, 30 }, |
| 83 | |
| 84 | { 0x07, 0x0004, 0 }, |
| 85 | { 0x10, 0x0220, 20 }, |
| 86 | |
| 87 | { 0x13, 0x0060, 50 }, |
| 88 | |
| 89 | { 0x13, 0x0040, 50 }, |
| 90 | |
| 91 | { 0x13, 0x0000, 0 }, |
| 92 | { 0x10, 0x0000, 0 } |
| 93 | }; |
| 94 | |
| 95 | |
| 96 | static void lms283gf05_reset(unsigned long gpio, bool inverted) |
| 97 | { |
| 98 | gpio_set_value(gpio, !inverted); |
| 99 | mdelay(100); |
| 100 | gpio_set_value(gpio, inverted); |
| 101 | mdelay(20); |
| 102 | gpio_set_value(gpio, !inverted); |
| 103 | mdelay(20); |
| 104 | } |
| 105 | |
| 106 | static void lms283gf05_toggle(struct spi_device *spi, |
| 107 | struct lms283gf05_seq *seq, int sz) |
| 108 | { |
| 109 | char buf[3]; |
| 110 | int i; |
| 111 | |
| 112 | for (i = 0; i < sz; i++) { |
| 113 | buf[0] = 0x74; |
| 114 | buf[1] = 0x00; |
| 115 | buf[2] = seq[i].reg; |
| 116 | spi_write(spi, buf, 3); |
| 117 | |
| 118 | buf[0] = 0x76; |
| 119 | buf[1] = seq[i].value >> 8; |
| 120 | buf[2] = seq[i].value & 0xff; |
| 121 | spi_write(spi, buf, 3); |
| 122 | |
| 123 | mdelay(seq[i].delay); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | static int lms283gf05_power_set(struct lcd_device *ld, int power) |
| 128 | { |
| 129 | struct lms283gf05_state *st = lcd_get_data(ld); |
| 130 | struct spi_device *spi = st->spi; |
| 131 | struct lms283gf05_pdata *pdata = spi->dev.platform_data; |
| 132 | |
Marek Vasut | 6bde908 | 2010-11-11 14:05:25 -0800 | [diff] [blame] | 133 | if (power <= FB_BLANK_NORMAL) { |
Marek Vasut | 5036cc4 | 2009-08-06 16:07:10 -0700 | [diff] [blame] | 134 | if (pdata) |
| 135 | lms283gf05_reset(pdata->reset_gpio, |
| 136 | pdata->reset_inverted); |
| 137 | lms283gf05_toggle(spi, disp_initseq, ARRAY_SIZE(disp_initseq)); |
| 138 | } else { |
| 139 | lms283gf05_toggle(spi, disp_pdwnseq, ARRAY_SIZE(disp_pdwnseq)); |
| 140 | if (pdata) |
| 141 | gpio_set_value(pdata->reset_gpio, |
| 142 | pdata->reset_inverted); |
| 143 | } |
| 144 | |
| 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | static struct lcd_ops lms_ops = { |
| 149 | .set_power = lms283gf05_power_set, |
| 150 | .get_power = NULL, |
| 151 | }; |
| 152 | |
Bill Pemberton | 1b9e450 | 2012-11-19 13:21:46 -0500 | [diff] [blame] | 153 | static int lms283gf05_probe(struct spi_device *spi) |
Marek Vasut | 5036cc4 | 2009-08-06 16:07:10 -0700 | [diff] [blame] | 154 | { |
| 155 | struct lms283gf05_state *st; |
| 156 | struct lms283gf05_pdata *pdata = spi->dev.platform_data; |
| 157 | struct lcd_device *ld; |
| 158 | int ret = 0; |
| 159 | |
| 160 | if (pdata != NULL) { |
Jingoo Han | 04e961f | 2012-07-30 14:40:43 -0700 | [diff] [blame] | 161 | ret = devm_gpio_request(&spi->dev, pdata->reset_gpio, |
| 162 | "LMS285GF05 RESET"); |
Marek Vasut | 5036cc4 | 2009-08-06 16:07:10 -0700 | [diff] [blame] | 163 | if (ret) |
| 164 | return ret; |
| 165 | |
| 166 | ret = gpio_direction_output(pdata->reset_gpio, |
| 167 | !pdata->reset_inverted); |
| 168 | if (ret) |
Jingoo Han | 04e961f | 2012-07-30 14:40:43 -0700 | [diff] [blame] | 169 | return ret; |
Marek Vasut | 5036cc4 | 2009-08-06 16:07:10 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Jingoo Han | 26f2b35 | 2012-05-29 15:07:23 -0700 | [diff] [blame] | 172 | st = devm_kzalloc(&spi->dev, sizeof(struct lms283gf05_state), |
| 173 | GFP_KERNEL); |
Marek Vasut | 5036cc4 | 2009-08-06 16:07:10 -0700 | [diff] [blame] | 174 | if (st == NULL) { |
| 175 | dev_err(&spi->dev, "No memory for device state\n"); |
Jingoo Han | 04e961f | 2012-07-30 14:40:43 -0700 | [diff] [blame] | 176 | return -ENOMEM; |
Marek Vasut | 5036cc4 | 2009-08-06 16:07:10 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | ld = lcd_device_register("lms283gf05", &spi->dev, st, &lms_ops); |
Jingoo Han | 04e961f | 2012-07-30 14:40:43 -0700 | [diff] [blame] | 180 | if (IS_ERR(ld)) |
| 181 | return PTR_ERR(ld); |
Marek Vasut | 5036cc4 | 2009-08-06 16:07:10 -0700 | [diff] [blame] | 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; |
Marek Vasut | 5036cc4 | 2009-08-06 16:07:10 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Bill Pemberton | 7e4b9d0 | 2012-11-19 13:26:34 -0500 | [diff] [blame^] | 196 | static int lms283gf05_remove(struct spi_device *spi) |
Marek Vasut | 5036cc4 | 2009-08-06 16:07:10 -0700 | [diff] [blame] | 197 | { |
| 198 | struct lms283gf05_state *st = dev_get_drvdata(&spi->dev); |
Marek Vasut | 5036cc4 | 2009-08-06 16:07:10 -0700 | [diff] [blame] | 199 | |
| 200 | lcd_device_unregister(st->ld); |
| 201 | |
Marek Vasut | 5036cc4 | 2009-08-06 16:07:10 -0700 | [diff] [blame] | 202 | return 0; |
| 203 | } |
| 204 | |
| 205 | static struct spi_driver lms283gf05_driver = { |
| 206 | .driver = { |
| 207 | .name = "lms283gf05", |
| 208 | .owner = THIS_MODULE, |
| 209 | }, |
| 210 | .probe = lms283gf05_probe, |
Bill Pemberton | d1723fa | 2012-11-19 13:21:09 -0500 | [diff] [blame] | 211 | .remove = lms283gf05_remove, |
Marek Vasut | 5036cc4 | 2009-08-06 16:07:10 -0700 | [diff] [blame] | 212 | }; |
| 213 | |
Axel Lin | 462dd83 | 2012-03-23 15:01:59 -0700 | [diff] [blame] | 214 | module_spi_driver(lms283gf05_driver); |
Marek Vasut | 5036cc4 | 2009-08-06 16:07:10 -0700 | [diff] [blame] | 215 | |
| 216 | MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>"); |
| 217 | MODULE_DESCRIPTION("LCD283GF05 LCD"); |
| 218 | MODULE_LICENSE("GPL v2"); |