Jonathan McDowell | 92e0ed0 | 2009-09-22 16:46:44 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Based on drivers/video/omap/lcd_inn1510.c |
| 3 | * |
| 4 | * LCD panel support for the Amstrad E3 (Delta) videophone. |
| 5 | * |
| 6 | * Copyright (C) 2006 Jonathan McDowell <noodles@earth.li> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License as published by the |
| 10 | * Free Software Foundation; either version 2 of the License, or (at your |
| 11 | * option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 21 | */ |
| 22 | |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/platform_device.h> |
| 25 | #include <linux/io.h> |
| 26 | #include <linux/delay.h> |
Janusz Krzysztofik | e721032 | 2009-12-11 13:21:46 +0000 | [diff] [blame] | 27 | #include <linux/lcd.h> |
Janusz Krzysztofik | a218d19 | 2011-12-20 00:08:56 +0100 | [diff] [blame] | 28 | #include <linux/gpio.h> |
Jonathan McDowell | 92e0ed0 | 2009-09-22 16:46:44 -0700 | [diff] [blame] | 29 | |
Tony Lindgren | 0adcbaf | 2013-02-11 14:46:00 -0800 | [diff] [blame] | 30 | #include <mach/hardware.h> |
Tony Lindgren | e27e35e | 2012-09-19 10:33:43 -0700 | [diff] [blame] | 31 | #include <mach/board-ams-delta.h> |
Tomi Valkeinen | 91773a0 | 2009-08-03 15:06:36 +0300 | [diff] [blame] | 32 | |
| 33 | #include "omapfb.h" |
Jonathan McDowell | 92e0ed0 | 2009-09-22 16:46:44 -0700 | [diff] [blame] | 34 | |
| 35 | #define AMS_DELTA_DEFAULT_CONTRAST 112 |
| 36 | |
Janusz Krzysztofik | e721032 | 2009-12-11 13:21:46 +0000 | [diff] [blame] | 37 | #define AMS_DELTA_MAX_CONTRAST 0x00FF |
| 38 | #define AMS_DELTA_LCD_POWER 0x0100 |
| 39 | |
| 40 | |
| 41 | /* LCD class device section */ |
| 42 | |
| 43 | static int ams_delta_lcd; |
| 44 | |
| 45 | static int ams_delta_lcd_set_power(struct lcd_device *dev, int power) |
| 46 | { |
| 47 | if (power == FB_BLANK_UNBLANK) { |
| 48 | if (!(ams_delta_lcd & AMS_DELTA_LCD_POWER)) { |
| 49 | omap_writeb(ams_delta_lcd & AMS_DELTA_MAX_CONTRAST, |
| 50 | OMAP_PWL_ENABLE); |
| 51 | omap_writeb(1, OMAP_PWL_CLK_ENABLE); |
| 52 | ams_delta_lcd |= AMS_DELTA_LCD_POWER; |
| 53 | } |
| 54 | } else { |
| 55 | if (ams_delta_lcd & AMS_DELTA_LCD_POWER) { |
| 56 | omap_writeb(0, OMAP_PWL_ENABLE); |
| 57 | omap_writeb(0, OMAP_PWL_CLK_ENABLE); |
| 58 | ams_delta_lcd &= ~AMS_DELTA_LCD_POWER; |
| 59 | } |
| 60 | } |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | static int ams_delta_lcd_set_contrast(struct lcd_device *dev, int value) |
| 65 | { |
| 66 | if ((value >= 0) && (value <= AMS_DELTA_MAX_CONTRAST)) { |
| 67 | omap_writeb(value, OMAP_PWL_ENABLE); |
| 68 | ams_delta_lcd &= ~AMS_DELTA_MAX_CONTRAST; |
| 69 | ams_delta_lcd |= value; |
| 70 | } |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | #ifdef CONFIG_LCD_CLASS_DEVICE |
| 75 | static int ams_delta_lcd_get_power(struct lcd_device *dev) |
| 76 | { |
| 77 | if (ams_delta_lcd & AMS_DELTA_LCD_POWER) |
| 78 | return FB_BLANK_UNBLANK; |
| 79 | else |
| 80 | return FB_BLANK_POWERDOWN; |
| 81 | } |
| 82 | |
| 83 | static int ams_delta_lcd_get_contrast(struct lcd_device *dev) |
| 84 | { |
| 85 | if (!(ams_delta_lcd & AMS_DELTA_LCD_POWER)) |
| 86 | return 0; |
| 87 | |
| 88 | return ams_delta_lcd & AMS_DELTA_MAX_CONTRAST; |
| 89 | } |
| 90 | |
| 91 | static struct lcd_ops ams_delta_lcd_ops = { |
| 92 | .get_power = ams_delta_lcd_get_power, |
| 93 | .set_power = ams_delta_lcd_set_power, |
| 94 | .get_contrast = ams_delta_lcd_get_contrast, |
| 95 | .set_contrast = ams_delta_lcd_set_contrast, |
| 96 | }; |
| 97 | #endif |
| 98 | |
| 99 | |
| 100 | /* omapfb panel section */ |
| 101 | |
Janusz Krzysztofik | da564a0 | 2012-02-10 17:48:43 +0100 | [diff] [blame] | 102 | static const struct gpio _gpios[] = { |
Janusz Krzysztofik | a218d19 | 2011-12-20 00:08:56 +0100 | [diff] [blame] | 103 | { |
| 104 | .gpio = AMS_DELTA_GPIO_PIN_LCD_VBLEN, |
| 105 | .flags = GPIOF_OUT_INIT_LOW, |
| 106 | .label = "lcd_vblen", |
| 107 | }, |
| 108 | { |
| 109 | .gpio = AMS_DELTA_GPIO_PIN_LCD_NDISP, |
| 110 | .flags = GPIOF_OUT_INIT_LOW, |
| 111 | .label = "lcd_ndisp", |
| 112 | }, |
| 113 | }; |
| 114 | |
Jonathan McDowell | 92e0ed0 | 2009-09-22 16:46:44 -0700 | [diff] [blame] | 115 | static int ams_delta_panel_init(struct lcd_panel *panel, |
| 116 | struct omapfb_device *fbdev) |
| 117 | { |
Janusz Krzysztofik | a218d19 | 2011-12-20 00:08:56 +0100 | [diff] [blame] | 118 | return gpio_request_array(_gpios, ARRAY_SIZE(_gpios)); |
Jonathan McDowell | 92e0ed0 | 2009-09-22 16:46:44 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | static void ams_delta_panel_cleanup(struct lcd_panel *panel) |
| 122 | { |
Janusz Krzysztofik | a218d19 | 2011-12-20 00:08:56 +0100 | [diff] [blame] | 123 | gpio_free_array(_gpios, ARRAY_SIZE(_gpios)); |
Jonathan McDowell | 92e0ed0 | 2009-09-22 16:46:44 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | static int ams_delta_panel_enable(struct lcd_panel *panel) |
| 127 | { |
Janusz Krzysztofik | a218d19 | 2011-12-20 00:08:56 +0100 | [diff] [blame] | 128 | gpio_set_value(AMS_DELTA_GPIO_PIN_LCD_NDISP, 1); |
| 129 | gpio_set_value(AMS_DELTA_GPIO_PIN_LCD_VBLEN, 1); |
Jonathan McDowell | 92e0ed0 | 2009-09-22 16:46:44 -0700 | [diff] [blame] | 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | static void ams_delta_panel_disable(struct lcd_panel *panel) |
| 134 | { |
Janusz Krzysztofik | a218d19 | 2011-12-20 00:08:56 +0100 | [diff] [blame] | 135 | gpio_set_value(AMS_DELTA_GPIO_PIN_LCD_VBLEN, 0); |
| 136 | gpio_set_value(AMS_DELTA_GPIO_PIN_LCD_NDISP, 0); |
Jonathan McDowell | 92e0ed0 | 2009-09-22 16:46:44 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | static unsigned long ams_delta_panel_get_caps(struct lcd_panel *panel) |
| 140 | { |
| 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | static struct lcd_panel ams_delta_panel = { |
| 145 | .name = "ams-delta", |
| 146 | .config = 0, |
| 147 | |
| 148 | .bpp = 12, |
| 149 | .data_lines = 16, |
| 150 | .x_res = 480, |
| 151 | .y_res = 320, |
| 152 | .pixel_clock = 4687, |
| 153 | .hsw = 3, |
| 154 | .hfp = 1, |
| 155 | .hbp = 1, |
| 156 | .vsw = 1, |
| 157 | .vfp = 0, |
| 158 | .vbp = 0, |
| 159 | .pcd = 0, |
| 160 | .acb = 37, |
| 161 | |
| 162 | .init = ams_delta_panel_init, |
| 163 | .cleanup = ams_delta_panel_cleanup, |
| 164 | .enable = ams_delta_panel_enable, |
| 165 | .disable = ams_delta_panel_disable, |
| 166 | .get_caps = ams_delta_panel_get_caps, |
| 167 | }; |
| 168 | |
Janusz Krzysztofik | e721032 | 2009-12-11 13:21:46 +0000 | [diff] [blame] | 169 | |
| 170 | /* platform driver section */ |
| 171 | |
Jonathan McDowell | 92e0ed0 | 2009-09-22 16:46:44 -0700 | [diff] [blame] | 172 | static int ams_delta_panel_probe(struct platform_device *pdev) |
| 173 | { |
Janusz Krzysztofik | e721032 | 2009-12-11 13:21:46 +0000 | [diff] [blame] | 174 | struct lcd_device *lcd_device = NULL; |
| 175 | #ifdef CONFIG_LCD_CLASS_DEVICE |
| 176 | int ret; |
| 177 | |
| 178 | lcd_device = lcd_device_register("omapfb", &pdev->dev, NULL, |
| 179 | &ams_delta_lcd_ops); |
| 180 | |
| 181 | if (IS_ERR(lcd_device)) { |
| 182 | ret = PTR_ERR(lcd_device); |
| 183 | dev_err(&pdev->dev, "failed to register device\n"); |
| 184 | return ret; |
| 185 | } |
| 186 | |
| 187 | platform_set_drvdata(pdev, lcd_device); |
| 188 | lcd_device->props.max_contrast = AMS_DELTA_MAX_CONTRAST; |
| 189 | #endif |
| 190 | |
| 191 | ams_delta_lcd_set_contrast(lcd_device, AMS_DELTA_DEFAULT_CONTRAST); |
| 192 | ams_delta_lcd_set_power(lcd_device, FB_BLANK_UNBLANK); |
| 193 | |
Jonathan McDowell | 92e0ed0 | 2009-09-22 16:46:44 -0700 | [diff] [blame] | 194 | omapfb_register_panel(&ams_delta_panel); |
| 195 | return 0; |
| 196 | } |
| 197 | |
| 198 | static int ams_delta_panel_remove(struct platform_device *pdev) |
| 199 | { |
| 200 | return 0; |
| 201 | } |
| 202 | |
| 203 | static int ams_delta_panel_suspend(struct platform_device *pdev, |
| 204 | pm_message_t mesg) |
| 205 | { |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | static int ams_delta_panel_resume(struct platform_device *pdev) |
| 210 | { |
| 211 | return 0; |
| 212 | } |
| 213 | |
Axel Lin | f990544 | 2011-12-09 09:37:57 +0800 | [diff] [blame] | 214 | static struct platform_driver ams_delta_panel_driver = { |
Jonathan McDowell | 92e0ed0 | 2009-09-22 16:46:44 -0700 | [diff] [blame] | 215 | .probe = ams_delta_panel_probe, |
| 216 | .remove = ams_delta_panel_remove, |
| 217 | .suspend = ams_delta_panel_suspend, |
| 218 | .resume = ams_delta_panel_resume, |
| 219 | .driver = { |
| 220 | .name = "lcd_ams_delta", |
Jonathan McDowell | 92e0ed0 | 2009-09-22 16:46:44 -0700 | [diff] [blame] | 221 | }, |
| 222 | }; |
| 223 | |
Axel Lin | f806f9b | 2011-12-09 09:59:56 +0800 | [diff] [blame] | 224 | module_platform_driver(ams_delta_panel_driver); |