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