1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#include <linux/module.h>
24#include <linux/platform_device.h>
25#include <linux/io.h>
26#include <linux/delay.h>
27#include <linux/lcd.h>
28#include <linux/gpio.h>
29
30#include <mach/hardware.h>
31#include <mach/board-ams-delta.h>
32
33#include "omapfb.h"
34
35#define AMS_DELTA_DEFAULT_CONTRAST 112
36
37#define AMS_DELTA_MAX_CONTRAST 0x00FF
38#define AMS_DELTA_LCD_POWER 0x0100
39
40
41
42
43static int ams_delta_lcd;
44
45static 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
64static 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
75static 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
83static 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
91static 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
101
102static const struct gpio _gpios[] = {
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
115static int ams_delta_panel_init(struct lcd_panel *panel,
116 struct omapfb_device *fbdev)
117{
118 return gpio_request_array(_gpios, ARRAY_SIZE(_gpios));
119}
120
121static void ams_delta_panel_cleanup(struct lcd_panel *panel)
122{
123 gpio_free_array(_gpios, ARRAY_SIZE(_gpios));
124}
125
126static int ams_delta_panel_enable(struct lcd_panel *panel)
127{
128 gpio_set_value(AMS_DELTA_GPIO_PIN_LCD_NDISP, 1);
129 gpio_set_value(AMS_DELTA_GPIO_PIN_LCD_VBLEN, 1);
130 return 0;
131}
132
133static void ams_delta_panel_disable(struct lcd_panel *panel)
134{
135 gpio_set_value(AMS_DELTA_GPIO_PIN_LCD_VBLEN, 0);
136 gpio_set_value(AMS_DELTA_GPIO_PIN_LCD_NDISP, 0);
137}
138
139static struct lcd_panel ams_delta_panel = {
140 .name = "ams-delta",
141 .config = 0,
142
143 .bpp = 12,
144 .data_lines = 16,
145 .x_res = 480,
146 .y_res = 320,
147 .pixel_clock = 4687,
148 .hsw = 3,
149 .hfp = 1,
150 .hbp = 1,
151 .vsw = 1,
152 .vfp = 0,
153 .vbp = 0,
154 .pcd = 0,
155 .acb = 37,
156
157 .init = ams_delta_panel_init,
158 .cleanup = ams_delta_panel_cleanup,
159 .enable = ams_delta_panel_enable,
160 .disable = ams_delta_panel_disable,
161};
162
163
164
165
166static int ams_delta_panel_probe(struct platform_device *pdev)
167{
168 struct lcd_device *lcd_device = NULL;
169#ifdef CONFIG_LCD_CLASS_DEVICE
170 int ret;
171
172 lcd_device = lcd_device_register("omapfb", &pdev->dev, NULL,
173 &ams_delta_lcd_ops);
174
175 if (IS_ERR(lcd_device)) {
176 ret = PTR_ERR(lcd_device);
177 dev_err(&pdev->dev, "failed to register device\n");
178 return ret;
179 }
180
181 platform_set_drvdata(pdev, lcd_device);
182 lcd_device->props.max_contrast = AMS_DELTA_MAX_CONTRAST;
183#endif
184
185 ams_delta_lcd_set_contrast(lcd_device, AMS_DELTA_DEFAULT_CONTRAST);
186 ams_delta_lcd_set_power(lcd_device, FB_BLANK_UNBLANK);
187
188 omapfb_register_panel(&ams_delta_panel);
189 return 0;
190}
191
192static struct platform_driver ams_delta_panel_driver = {
193 .probe = ams_delta_panel_probe,
194 .driver = {
195 .name = "lcd_ams_delta",
196 },
197};
198
199module_platform_driver(ams_delta_panel_driver);
200