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