Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * lms283gf05.c -- support for Samsung LMS283GF05 LCD
0004  *
0005  * Copyright (c) 2009 Marek Vasut <marek.vasut@gmail.com>
0006  */
0007 
0008 #include <linux/device.h>
0009 #include <linux/kernel.h>
0010 #include <linux/delay.h>
0011 #include <linux/slab.h>
0012 #include <linux/gpio/consumer.h>
0013 #include <linux/lcd.h>
0014 
0015 #include <linux/spi/spi.h>
0016 #include <linux/module.h>
0017 
0018 struct lms283gf05_state {
0019     struct spi_device   *spi;
0020     struct lcd_device   *ld;
0021     struct gpio_desc    *reset;
0022 };
0023 
0024 struct lms283gf05_seq {
0025     unsigned char       reg;
0026     unsigned short      value;
0027     unsigned char       delay;
0028 };
0029 
0030 /* Magic sequences supplied by manufacturer, for details refer to datasheet */
0031 static const struct lms283gf05_seq disp_initseq[] = {
0032     /* REG, VALUE, DELAY */
0033     { 0x07, 0x0000, 0 },
0034     { 0x13, 0x0000, 10 },
0035 
0036     { 0x11, 0x3004, 0 },
0037     { 0x14, 0x200F, 0 },
0038     { 0x10, 0x1a20, 0 },
0039     { 0x13, 0x0040, 50 },
0040 
0041     { 0x13, 0x0060, 0 },
0042     { 0x13, 0x0070, 200 },
0043 
0044     { 0x01, 0x0127, 0 },
0045     { 0x02, 0x0700, 0 },
0046     { 0x03, 0x1030, 0 },
0047     { 0x08, 0x0208, 0 },
0048     { 0x0B, 0x0620, 0 },
0049     { 0x0C, 0x0110, 0 },
0050     { 0x30, 0x0120, 0 },
0051     { 0x31, 0x0127, 0 },
0052     { 0x32, 0x0000, 0 },
0053     { 0x33, 0x0503, 0 },
0054     { 0x34, 0x0727, 0 },
0055     { 0x35, 0x0124, 0 },
0056     { 0x36, 0x0706, 0 },
0057     { 0x37, 0x0701, 0 },
0058     { 0x38, 0x0F00, 0 },
0059     { 0x39, 0x0F00, 0 },
0060     { 0x40, 0x0000, 0 },
0061     { 0x41, 0x0000, 0 },
0062     { 0x42, 0x013f, 0 },
0063     { 0x43, 0x0000, 0 },
0064     { 0x44, 0x013f, 0 },
0065     { 0x45, 0x0000, 0 },
0066     { 0x46, 0xef00, 0 },
0067     { 0x47, 0x013f, 0 },
0068     { 0x48, 0x0000, 0 },
0069     { 0x07, 0x0015, 30 },
0070 
0071     { 0x07, 0x0017, 0 },
0072 
0073     { 0x20, 0x0000, 0 },
0074     { 0x21, 0x0000, 0 },
0075     { 0x22, 0x0000, 0 }
0076 };
0077 
0078 static const struct lms283gf05_seq disp_pdwnseq[] = {
0079     { 0x07, 0x0016, 30 },
0080 
0081     { 0x07, 0x0004, 0 },
0082     { 0x10, 0x0220, 20 },
0083 
0084     { 0x13, 0x0060, 50 },
0085 
0086     { 0x13, 0x0040, 50 },
0087 
0088     { 0x13, 0x0000, 0 },
0089     { 0x10, 0x0000, 0 }
0090 };
0091 
0092 
0093 static void lms283gf05_reset(struct gpio_desc *gpiod)
0094 {
0095     gpiod_set_value(gpiod, 0); /* De-asserted */
0096     mdelay(100);
0097     gpiod_set_value(gpiod, 1); /* Asserted */
0098     mdelay(20);
0099     gpiod_set_value(gpiod, 0); /* De-asserted */
0100     mdelay(20);
0101 }
0102 
0103 static void lms283gf05_toggle(struct spi_device *spi,
0104                 const struct lms283gf05_seq *seq, int sz)
0105 {
0106     char buf[3];
0107     int i;
0108 
0109     for (i = 0; i < sz; i++) {
0110         buf[0] = 0x74;
0111         buf[1] = 0x00;
0112         buf[2] = seq[i].reg;
0113         spi_write(spi, buf, 3);
0114 
0115         buf[0] = 0x76;
0116         buf[1] = seq[i].value >> 8;
0117         buf[2] = seq[i].value & 0xff;
0118         spi_write(spi, buf, 3);
0119 
0120         mdelay(seq[i].delay);
0121     }
0122 }
0123 
0124 static int lms283gf05_power_set(struct lcd_device *ld, int power)
0125 {
0126     struct lms283gf05_state *st = lcd_get_data(ld);
0127     struct spi_device *spi = st->spi;
0128 
0129     if (power <= FB_BLANK_NORMAL) {
0130         if (st->reset)
0131             lms283gf05_reset(st->reset);
0132         lms283gf05_toggle(spi, disp_initseq, ARRAY_SIZE(disp_initseq));
0133     } else {
0134         lms283gf05_toggle(spi, disp_pdwnseq, ARRAY_SIZE(disp_pdwnseq));
0135         if (st->reset)
0136             gpiod_set_value(st->reset, 1); /* Asserted */
0137     }
0138 
0139     return 0;
0140 }
0141 
0142 static struct lcd_ops lms_ops = {
0143     .set_power  = lms283gf05_power_set,
0144     .get_power  = NULL,
0145 };
0146 
0147 static int lms283gf05_probe(struct spi_device *spi)
0148 {
0149     struct lms283gf05_state *st;
0150     struct lcd_device *ld;
0151 
0152     st = devm_kzalloc(&spi->dev, sizeof(struct lms283gf05_state),
0153                 GFP_KERNEL);
0154     if (st == NULL)
0155         return -ENOMEM;
0156 
0157     st->reset = gpiod_get_optional(&spi->dev, "reset", GPIOD_OUT_LOW);
0158     if (IS_ERR(st->reset))
0159         return PTR_ERR(st->reset);
0160     gpiod_set_consumer_name(st->reset, "LMS283GF05 RESET");
0161 
0162     ld = devm_lcd_device_register(&spi->dev, "lms283gf05", &spi->dev, st,
0163                     &lms_ops);
0164     if (IS_ERR(ld))
0165         return PTR_ERR(ld);
0166 
0167     st->spi = spi;
0168     st->ld = ld;
0169 
0170     spi_set_drvdata(spi, st);
0171 
0172     /* kick in the LCD */
0173     if (st->reset)
0174         lms283gf05_reset(st->reset);
0175     lms283gf05_toggle(spi, disp_initseq, ARRAY_SIZE(disp_initseq));
0176 
0177     return 0;
0178 }
0179 
0180 static struct spi_driver lms283gf05_driver = {
0181     .driver = {
0182         .name   = "lms283gf05",
0183     },
0184     .probe      = lms283gf05_probe,
0185 };
0186 
0187 module_spi_driver(lms283gf05_driver);
0188 
0189 MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
0190 MODULE_DESCRIPTION("LCD283GF05 LCD");
0191 MODULE_LICENSE("GPL v2");