Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 2 | /* |
| 3 | * l4f00242t03.c -- support for Epson L4F00242T03 LCD |
| 4 | * |
| 5 | * Copyright 2007-2009 Freescale Semiconductor, Inc. All Rights Reserved. |
| 6 | * |
| 7 | * Copyright (c) 2009 Alberto Panizzo <maramaopercheseimorto@gmail.com> |
Jingoo Han | e4f8ae7 | 2012-12-17 16:00:23 -0800 | [diff] [blame] | 8 | * Inspired by Marek Vasut work in l4f00242t03.c |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 9 | */ |
| 10 | |
Jingoo Han | 6677110 | 2012-05-29 15:07:20 -0700 | [diff] [blame] | 11 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 12 | |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 13 | #include <linux/device.h> |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/delay.h> |
Paul Gortmaker | 355b200 | 2011-07-03 16:17:28 -0400 | [diff] [blame] | 16 | #include <linux/module.h> |
Linus Walleij | 61365ca | 2020-04-15 14:14:49 +0200 | [diff] [blame] | 17 | #include <linux/gpio/consumer.h> |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 18 | #include <linux/lcd.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 19 | #include <linux/slab.h> |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 20 | #include <linux/regulator/consumer.h> |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 21 | #include <linux/spi/spi.h> |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 22 | |
| 23 | struct l4f00242t03_priv { |
| 24 | struct spi_device *spi; |
| 25 | struct lcd_device *ld; |
Alberto Panizzo | 95558ad | 2011-01-12 16:59:22 -0800 | [diff] [blame] | 26 | int lcd_state; |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 27 | struct regulator *io_reg; |
| 28 | struct regulator *core_reg; |
Linus Walleij | 61365ca | 2020-04-15 14:14:49 +0200 | [diff] [blame] | 29 | struct gpio_desc *reset; |
| 30 | struct gpio_desc *enable; |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 31 | }; |
| 32 | |
Linus Walleij | 61365ca | 2020-04-15 14:14:49 +0200 | [diff] [blame] | 33 | static void l4f00242t03_reset(struct gpio_desc *gpiod) |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 34 | { |
| 35 | pr_debug("l4f00242t03_reset.\n"); |
Linus Walleij | 61365ca | 2020-04-15 14:14:49 +0200 | [diff] [blame] | 36 | gpiod_set_value(gpiod, 1); |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 37 | mdelay(100); |
Linus Walleij | 61365ca | 2020-04-15 14:14:49 +0200 | [diff] [blame] | 38 | gpiod_set_value(gpiod, 0); |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 39 | mdelay(10); /* tRES >= 100us */ |
Linus Walleij | 61365ca | 2020-04-15 14:14:49 +0200 | [diff] [blame] | 40 | gpiod_set_value(gpiod, 1); |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 41 | mdelay(20); |
| 42 | } |
| 43 | |
| 44 | #define param(x) ((x) | 0x100) |
| 45 | |
| 46 | static void l4f00242t03_lcd_init(struct spi_device *spi) |
| 47 | { |
Jingoo Han | 6006607 | 2013-02-21 16:43:32 -0800 | [diff] [blame] | 48 | struct l4f00242t03_priv *priv = spi_get_drvdata(spi); |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 49 | const u16 cmd[] = { 0x36, param(0), 0x3A, param(0x60) }; |
Jingoo Han | ef73e63 | 2013-04-29 16:17:34 -0700 | [diff] [blame] | 50 | int ret; |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 51 | |
| 52 | dev_dbg(&spi->dev, "initializing LCD\n"); |
| 53 | |
Jingoo Han | ef73e63 | 2013-04-29 16:17:34 -0700 | [diff] [blame] | 54 | ret = regulator_set_voltage(priv->io_reg, 1800000, 1800000); |
| 55 | if (ret) { |
| 56 | dev_err(&spi->dev, "failed to set the IO regulator voltage.\n"); |
| 57 | return; |
| 58 | } |
| 59 | ret = regulator_enable(priv->io_reg); |
| 60 | if (ret) { |
| 61 | dev_err(&spi->dev, "failed to enable the IO regulator.\n"); |
| 62 | return; |
| 63 | } |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 64 | |
Jingoo Han | ef73e63 | 2013-04-29 16:17:34 -0700 | [diff] [blame] | 65 | ret = regulator_set_voltage(priv->core_reg, 2800000, 2800000); |
| 66 | if (ret) { |
| 67 | dev_err(&spi->dev, "failed to set the core regulator voltage.\n"); |
| 68 | regulator_disable(priv->io_reg); |
| 69 | return; |
| 70 | } |
| 71 | ret = regulator_enable(priv->core_reg); |
| 72 | if (ret) { |
| 73 | dev_err(&spi->dev, "failed to enable the core regulator.\n"); |
| 74 | regulator_disable(priv->io_reg); |
| 75 | return; |
| 76 | } |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 77 | |
Linus Walleij | 61365ca | 2020-04-15 14:14:49 +0200 | [diff] [blame] | 78 | l4f00242t03_reset(priv->reset); |
Alberto Panizzo | aff5ce6 | 2011-01-12 16:59:24 -0800 | [diff] [blame] | 79 | |
Linus Walleij | 61365ca | 2020-04-15 14:14:49 +0200 | [diff] [blame] | 80 | gpiod_set_value(priv->enable, 1); |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 81 | msleep(60); |
| 82 | spi_write(spi, (const u8 *)cmd, ARRAY_SIZE(cmd) * sizeof(u16)); |
| 83 | } |
| 84 | |
Alberto Panizzo | 95558ad | 2011-01-12 16:59:22 -0800 | [diff] [blame] | 85 | static void l4f00242t03_lcd_powerdown(struct spi_device *spi) |
| 86 | { |
Jingoo Han | 6006607 | 2013-02-21 16:43:32 -0800 | [diff] [blame] | 87 | struct l4f00242t03_priv *priv = spi_get_drvdata(spi); |
Alberto Panizzo | 95558ad | 2011-01-12 16:59:22 -0800 | [diff] [blame] | 88 | |
| 89 | dev_dbg(&spi->dev, "Powering down LCD\n"); |
| 90 | |
Linus Walleij | 61365ca | 2020-04-15 14:14:49 +0200 | [diff] [blame] | 91 | gpiod_set_value(priv->enable, 0); |
Alberto Panizzo | 95558ad | 2011-01-12 16:59:22 -0800 | [diff] [blame] | 92 | |
Mark Brown | 0556dc3 | 2011-10-31 17:11:48 -0700 | [diff] [blame] | 93 | regulator_disable(priv->io_reg); |
| 94 | regulator_disable(priv->core_reg); |
Alberto Panizzo | 95558ad | 2011-01-12 16:59:22 -0800 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | static int l4f00242t03_lcd_power_get(struct lcd_device *ld) |
| 98 | { |
| 99 | struct l4f00242t03_priv *priv = lcd_get_data(ld); |
| 100 | |
| 101 | return priv->lcd_state; |
| 102 | } |
| 103 | |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 104 | static int l4f00242t03_lcd_power_set(struct lcd_device *ld, int power) |
| 105 | { |
| 106 | struct l4f00242t03_priv *priv = lcd_get_data(ld); |
| 107 | struct spi_device *spi = priv->spi; |
| 108 | |
| 109 | const u16 slpout = 0x11; |
| 110 | const u16 dison = 0x29; |
| 111 | |
| 112 | const u16 slpin = 0x10; |
| 113 | const u16 disoff = 0x28; |
| 114 | |
Marek Vasut | 4dbdf88 | 2010-11-11 14:05:26 -0800 | [diff] [blame] | 115 | if (power <= FB_BLANK_NORMAL) { |
Alberto Panizzo | 95558ad | 2011-01-12 16:59:22 -0800 | [diff] [blame] | 116 | if (priv->lcd_state <= FB_BLANK_NORMAL) { |
| 117 | /* Do nothing, the LCD is running */ |
| 118 | } else if (priv->lcd_state < FB_BLANK_POWERDOWN) { |
| 119 | dev_dbg(&spi->dev, "Resuming LCD\n"); |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 120 | |
Alberto Panizzo | 95558ad | 2011-01-12 16:59:22 -0800 | [diff] [blame] | 121 | spi_write(spi, (const u8 *)&slpout, sizeof(u16)); |
| 122 | msleep(60); |
| 123 | spi_write(spi, (const u8 *)&dison, sizeof(u16)); |
| 124 | } else { |
| 125 | /* priv->lcd_state == FB_BLANK_POWERDOWN */ |
| 126 | l4f00242t03_lcd_init(spi); |
| 127 | priv->lcd_state = FB_BLANK_VSYNC_SUSPEND; |
| 128 | l4f00242t03_lcd_power_set(priv->ld, power); |
| 129 | } |
| 130 | } else if (power < FB_BLANK_POWERDOWN) { |
| 131 | if (priv->lcd_state <= FB_BLANK_NORMAL) { |
| 132 | /* Send the display in standby */ |
| 133 | dev_dbg(&spi->dev, "Standby the LCD\n"); |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 134 | |
Alberto Panizzo | 95558ad | 2011-01-12 16:59:22 -0800 | [diff] [blame] | 135 | spi_write(spi, (const u8 *)&disoff, sizeof(u16)); |
| 136 | msleep(60); |
| 137 | spi_write(spi, (const u8 *)&slpin, sizeof(u16)); |
| 138 | } else if (priv->lcd_state < FB_BLANK_POWERDOWN) { |
| 139 | /* Do nothing, the LCD is already in standby */ |
| 140 | } else { |
| 141 | /* priv->lcd_state == FB_BLANK_POWERDOWN */ |
| 142 | l4f00242t03_lcd_init(spi); |
| 143 | priv->lcd_state = FB_BLANK_UNBLANK; |
| 144 | l4f00242t03_lcd_power_set(ld, power); |
| 145 | } |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 146 | } else { |
Alberto Panizzo | 95558ad | 2011-01-12 16:59:22 -0800 | [diff] [blame] | 147 | /* power == FB_BLANK_POWERDOWN */ |
Alberto Panizzo | 26bbabc | 2011-01-12 16:59:23 -0800 | [diff] [blame] | 148 | if (priv->lcd_state != FB_BLANK_POWERDOWN) { |
| 149 | /* Clear the screen before shutting down */ |
| 150 | spi_write(spi, (const u8 *)&disoff, sizeof(u16)); |
| 151 | msleep(60); |
| 152 | l4f00242t03_lcd_powerdown(spi); |
| 153 | } |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 154 | } |
| 155 | |
Alberto Panizzo | 95558ad | 2011-01-12 16:59:22 -0800 | [diff] [blame] | 156 | priv->lcd_state = power; |
| 157 | |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | static struct lcd_ops l4f_ops = { |
| 162 | .set_power = l4f00242t03_lcd_power_set, |
Alberto Panizzo | 95558ad | 2011-01-12 16:59:22 -0800 | [diff] [blame] | 163 | .get_power = l4f00242t03_lcd_power_get, |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 164 | }; |
| 165 | |
Bill Pemberton | 1b9e450 | 2012-11-19 13:21:46 -0500 | [diff] [blame] | 166 | static int l4f00242t03_probe(struct spi_device *spi) |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 167 | { |
| 168 | struct l4f00242t03_priv *priv; |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 169 | |
Jingoo Han | ba4a887 | 2012-05-29 15:07:23 -0700 | [diff] [blame] | 170 | priv = devm_kzalloc(&spi->dev, sizeof(struct l4f00242t03_priv), |
| 171 | GFP_KERNEL); |
Jingoo Han | 1bd0482 | 2014-04-03 14:49:02 -0700 | [diff] [blame] | 172 | if (priv == NULL) |
Axel Lin | beb0a43 | 2010-05-03 14:42:44 +0800 | [diff] [blame] | 173 | return -ENOMEM; |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 174 | |
Jingoo Han | 6006607 | 2013-02-21 16:43:32 -0800 | [diff] [blame] | 175 | spi_set_drvdata(spi, priv); |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 176 | spi->bits_per_word = 9; |
| 177 | spi_setup(spi); |
| 178 | |
| 179 | priv->spi = spi; |
| 180 | |
Linus Walleij | 61365ca | 2020-04-15 14:14:49 +0200 | [diff] [blame] | 181 | priv->reset = devm_gpiod_get(&spi->dev, "reset", GPIOD_OUT_HIGH); |
| 182 | if (IS_ERR(priv->reset)) { |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 183 | dev_err(&spi->dev, |
| 184 | "Unable to get the lcd l4f00242t03 reset gpio.\n"); |
Linus Walleij | 61365ca | 2020-04-15 14:14:49 +0200 | [diff] [blame] | 185 | return PTR_ERR(priv->reset); |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 186 | } |
Linus Walleij | 61365ca | 2020-04-15 14:14:49 +0200 | [diff] [blame] | 187 | gpiod_set_consumer_name(priv->reset, "lcd l4f00242t03 reset"); |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 188 | |
Linus Walleij | 61365ca | 2020-04-15 14:14:49 +0200 | [diff] [blame] | 189 | priv->enable = devm_gpiod_get(&spi->dev, "enable", GPIOD_OUT_LOW); |
| 190 | if (IS_ERR(priv->enable)) { |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 191 | dev_err(&spi->dev, |
| 192 | "Unable to get the lcd l4f00242t03 data en gpio.\n"); |
Linus Walleij | 61365ca | 2020-04-15 14:14:49 +0200 | [diff] [blame] | 193 | return PTR_ERR(priv->enable); |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 194 | } |
Linus Walleij | 61365ca | 2020-04-15 14:14:49 +0200 | [diff] [blame] | 195 | gpiod_set_consumer_name(priv->enable, "lcd l4f00242t03 data enable"); |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 196 | |
Axel Lin | 610b71a | 2013-02-21 16:43:53 -0800 | [diff] [blame] | 197 | priv->io_reg = devm_regulator_get(&spi->dev, "vdd"); |
Mark Brown | 0556dc3 | 2011-10-31 17:11:48 -0700 | [diff] [blame] | 198 | if (IS_ERR(priv->io_reg)) { |
| 199 | dev_err(&spi->dev, "%s: Unable to get the IO regulator\n", |
| 200 | __func__); |
Jingoo Han | 62a5c07 | 2012-07-30 14:40:47 -0700 | [diff] [blame] | 201 | return PTR_ERR(priv->io_reg); |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 202 | } |
| 203 | |
Axel Lin | 610b71a | 2013-02-21 16:43:53 -0800 | [diff] [blame] | 204 | priv->core_reg = devm_regulator_get(&spi->dev, "vcore"); |
Mark Brown | 0556dc3 | 2011-10-31 17:11:48 -0700 | [diff] [blame] | 205 | if (IS_ERR(priv->core_reg)) { |
| 206 | dev_err(&spi->dev, "%s: Unable to get the core regulator\n", |
| 207 | __func__); |
Axel Lin | 610b71a | 2013-02-21 16:43:53 -0800 | [diff] [blame] | 208 | return PTR_ERR(priv->core_reg); |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 209 | } |
| 210 | |
Jingoo Han | 7dd7807 | 2014-01-23 15:54:30 -0800 | [diff] [blame] | 211 | priv->ld = devm_lcd_device_register(&spi->dev, "l4f00242t03", &spi->dev, |
| 212 | priv, &l4f_ops); |
Axel Lin | 610b71a | 2013-02-21 16:43:53 -0800 | [diff] [blame] | 213 | if (IS_ERR(priv->ld)) |
| 214 | return PTR_ERR(priv->ld); |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 215 | |
| 216 | /* Init the LCD */ |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 217 | l4f00242t03_lcd_init(spi); |
Alberto Panizzo | 95558ad | 2011-01-12 16:59:22 -0800 | [diff] [blame] | 218 | priv->lcd_state = FB_BLANK_VSYNC_SUSPEND; |
| 219 | l4f00242t03_lcd_power_set(priv->ld, FB_BLANK_UNBLANK); |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 220 | |
| 221 | dev_info(&spi->dev, "Epson l4f00242t03 lcd probed.\n"); |
| 222 | |
| 223 | return 0; |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 224 | } |
| 225 | |
Bill Pemberton | 7e4b9d0 | 2012-11-19 13:26:34 -0500 | [diff] [blame] | 226 | static int l4f00242t03_remove(struct spi_device *spi) |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 227 | { |
Jingoo Han | 6006607 | 2013-02-21 16:43:32 -0800 | [diff] [blame] | 228 | struct l4f00242t03_priv *priv = spi_get_drvdata(spi); |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 229 | |
Alberto Panizzo | 95558ad | 2011-01-12 16:59:22 -0800 | [diff] [blame] | 230 | l4f00242t03_lcd_power_set(priv->ld, FB_BLANK_POWERDOWN); |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 231 | return 0; |
| 232 | } |
| 233 | |
Alberto Panizzo | 95558ad | 2011-01-12 16:59:22 -0800 | [diff] [blame] | 234 | static void l4f00242t03_shutdown(struct spi_device *spi) |
| 235 | { |
Jingoo Han | 6006607 | 2013-02-21 16:43:32 -0800 | [diff] [blame] | 236 | struct l4f00242t03_priv *priv = spi_get_drvdata(spi); |
Alberto Panizzo | 95558ad | 2011-01-12 16:59:22 -0800 | [diff] [blame] | 237 | |
| 238 | if (priv) |
| 239 | l4f00242t03_lcd_power_set(priv->ld, FB_BLANK_POWERDOWN); |
| 240 | |
| 241 | } |
| 242 | |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 243 | static struct spi_driver l4f00242t03_driver = { |
| 244 | .driver = { |
| 245 | .name = "l4f00242t03", |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 246 | }, |
| 247 | .probe = l4f00242t03_probe, |
Bill Pemberton | d1723fa | 2012-11-19 13:21:09 -0500 | [diff] [blame] | 248 | .remove = l4f00242t03_remove, |
Alberto Panizzo | 95558ad | 2011-01-12 16:59:22 -0800 | [diff] [blame] | 249 | .shutdown = l4f00242t03_shutdown, |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 250 | }; |
| 251 | |
Axel Lin | 462dd83 | 2012-03-23 15:01:59 -0700 | [diff] [blame] | 252 | module_spi_driver(l4f00242t03_driver); |
Alberto Panizzo | e7fb9c4 | 2009-12-18 16:42:11 +0100 | [diff] [blame] | 253 | |
| 254 | MODULE_AUTHOR("Alberto Panizzo <maramaopercheseimorto@gmail.com>"); |
| 255 | MODULE_DESCRIPTION("EPSON L4F00242T03 LCD"); |
Alberto Panizzo | c3cf2e4 | 2010-01-19 09:30:50 +0100 | [diff] [blame] | 256 | MODULE_LICENSE("GPL v2"); |