1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * lms283gf05.c -- support for Samsung LMS283GF05 LCD 4 * 5 * Copyright (c) 2009 Marek Vasut <marek.vasut@gmail.com> 6 */ 7 8 #include <linux/device.h> 9 #include <linux/kernel.h> 10 #include <linux/delay.h> 11 #include <linux/slab.h> 12 #include <linux/gpio/consumer.h> 13 #include <linux/lcd.h> 14 15 #include <linux/spi/spi.h> 16 #include <linux/module.h> 17 18 struct lms283gf05_state { 19 struct spi_device *spi; 20 struct lcd_device *ld; 21 struct gpio_desc *reset; 22 }; 23 24 struct lms283gf05_seq { 25 unsigned char reg; 26 unsigned short value; 27 unsigned char delay; 28 }; 29 30 /* Magic sequences supplied by manufacturer, for details refer to datasheet */ 31 static const struct lms283gf05_seq disp_initseq[] = { 32 /* REG, VALUE, DELAY */ 33 { 0x07, 0x0000, 0 }, 34 { 0x13, 0x0000, 10 }, 35 36 { 0x11, 0x3004, 0 }, 37 { 0x14, 0x200F, 0 }, 38 { 0x10, 0x1a20, 0 }, 39 { 0x13, 0x0040, 50 }, 40 41 { 0x13, 0x0060, 0 }, 42 { 0x13, 0x0070, 200 }, 43 44 { 0x01, 0x0127, 0 }, 45 { 0x02, 0x0700, 0 }, 46 { 0x03, 0x1030, 0 }, 47 { 0x08, 0x0208, 0 }, 48 { 0x0B, 0x0620, 0 }, 49 { 0x0C, 0x0110, 0 }, 50 { 0x30, 0x0120, 0 }, 51 { 0x31, 0x0127, 0 }, 52 { 0x32, 0x0000, 0 }, 53 { 0x33, 0x0503, 0 }, 54 { 0x34, 0x0727, 0 }, 55 { 0x35, 0x0124, 0 }, 56 { 0x36, 0x0706, 0 }, 57 { 0x37, 0x0701, 0 }, 58 { 0x38, 0x0F00, 0 }, 59 { 0x39, 0x0F00, 0 }, 60 { 0x40, 0x0000, 0 }, 61 { 0x41, 0x0000, 0 }, 62 { 0x42, 0x013f, 0 }, 63 { 0x43, 0x0000, 0 }, 64 { 0x44, 0x013f, 0 }, 65 { 0x45, 0x0000, 0 }, 66 { 0x46, 0xef00, 0 }, 67 { 0x47, 0x013f, 0 }, 68 { 0x48, 0x0000, 0 }, 69 { 0x07, 0x0015, 30 }, 70 71 { 0x07, 0x0017, 0 }, 72 73 { 0x20, 0x0000, 0 }, 74 { 0x21, 0x0000, 0 }, 75 { 0x22, 0x0000, 0 } 76 }; 77 78 static const struct lms283gf05_seq disp_pdwnseq[] = { 79 { 0x07, 0x0016, 30 }, 80 81 { 0x07, 0x0004, 0 }, 82 { 0x10, 0x0220, 20 }, 83 84 { 0x13, 0x0060, 50 }, 85 86 { 0x13, 0x0040, 50 }, 87 88 { 0x13, 0x0000, 0 }, 89 { 0x10, 0x0000, 0 } 90 }; 91 92 93 static void lms283gf05_reset(struct gpio_desc *gpiod) 94 { 95 gpiod_set_value(gpiod, 0); /* De-asserted */ 96 mdelay(100); 97 gpiod_set_value(gpiod, 1); /* Asserted */ 98 mdelay(20); 99 gpiod_set_value(gpiod, 0); /* De-asserted */ 100 mdelay(20); 101 } 102 103 static void lms283gf05_toggle(struct spi_device *spi, 104 const struct lms283gf05_seq *seq, int sz) 105 { 106 char buf[3]; 107 int i; 108 109 for (i = 0; i < sz; i++) { 110 buf[0] = 0x74; 111 buf[1] = 0x00; 112 buf[2] = seq[i].reg; 113 spi_write(spi, buf, 3); 114 115 buf[0] = 0x76; 116 buf[1] = seq[i].value >> 8; 117 buf[2] = seq[i].value & 0xff; 118 spi_write(spi, buf, 3); 119 120 mdelay(seq[i].delay); 121 } 122 } 123 124 static int lms283gf05_power_set(struct lcd_device *ld, int power) 125 { 126 struct lms283gf05_state *st = lcd_get_data(ld); 127 struct spi_device *spi = st->spi; 128 129 if (power <= FB_BLANK_NORMAL) { 130 if (st->reset) 131 lms283gf05_reset(st->reset); 132 lms283gf05_toggle(spi, disp_initseq, ARRAY_SIZE(disp_initseq)); 133 } else { 134 lms283gf05_toggle(spi, disp_pdwnseq, ARRAY_SIZE(disp_pdwnseq)); 135 if (st->reset) 136 gpiod_set_value(st->reset, 1); /* Asserted */ 137 } 138 139 return 0; 140 } 141 142 static struct lcd_ops lms_ops = { 143 .set_power = lms283gf05_power_set, 144 .get_power = NULL, 145 }; 146 147 static int lms283gf05_probe(struct spi_device *spi) 148 { 149 struct lms283gf05_state *st; 150 struct lcd_device *ld; 151 152 st = devm_kzalloc(&spi->dev, sizeof(struct lms283gf05_state), 153 GFP_KERNEL); 154 if (st == NULL) 155 return -ENOMEM; 156 157 st->reset = gpiod_get_optional(&spi->dev, "reset", GPIOD_OUT_LOW); 158 if (IS_ERR(st->reset)) 159 return PTR_ERR(st->reset); 160 gpiod_set_consumer_name(st->reset, "LMS283GF05 RESET"); 161 162 ld = devm_lcd_device_register(&spi->dev, "lms283gf05", &spi->dev, st, 163 &lms_ops); 164 if (IS_ERR(ld)) 165 return PTR_ERR(ld); 166 167 st->spi = spi; 168 st->ld = ld; 169 170 spi_set_drvdata(spi, st); 171 172 /* kick in the LCD */ 173 if (st->reset) 174 lms283gf05_reset(st->reset); 175 lms283gf05_toggle(spi, disp_initseq, ARRAY_SIZE(disp_initseq)); 176 177 return 0; 178 } 179 180 static struct spi_driver lms283gf05_driver = { 181 .driver = { 182 .name = "lms283gf05", 183 }, 184 .probe = lms283gf05_probe, 185 }; 186 187 module_spi_driver(lms283gf05_driver); 188 189 MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>"); 190 MODULE_DESCRIPTION("LCD283GF05 LCD"); 191 MODULE_LICENSE("GPL v2"); 192