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