drivers/video/msm: update to new kernel
[sfrench/cifs-2.6.git] / drivers / video / msm / mddi_client_toshiba.c
1 /* drivers/video/msm_fb/mddi_client_toshiba.c
2  *
3  * Support for Toshiba TC358720XBG mddi client devices which require no
4  * special initialization code.
5  *
6  * Copyright (C) 2007 Google Incorporated
7  *
8  * This software is licensed under the terms of the GNU General Public
9  * License version 2, as published by the Free Software Foundation, and
10  * may be copied, distributed, and modified under those terms.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  */
17
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/platform_device.h>
21 #include <linux/interrupt.h>
22 #include <linux/gpio.h>
23 #include <linux/sched.h>
24 #include <mach/msm_fb.h>
25
26
27 #define LCD_CONTROL_BLOCK_BASE 0x110000
28 #define CMN         (LCD_CONTROL_BLOCK_BASE|0x10)
29 #define INTFLG      (LCD_CONTROL_BLOCK_BASE|0x18)
30 #define HCYCLE      (LCD_CONTROL_BLOCK_BASE|0x34)
31 #define HDE_START   (LCD_CONTROL_BLOCK_BASE|0x3C)
32 #define VPOS        (LCD_CONTROL_BLOCK_BASE|0xC0)
33 #define MPLFBUF     (LCD_CONTROL_BLOCK_BASE|0x20)
34 #define WAKEUP      (LCD_CONTROL_BLOCK_BASE|0x54)
35 #define WSYN_DLY    (LCD_CONTROL_BLOCK_BASE|0x58)
36 #define REGENB      (LCD_CONTROL_BLOCK_BASE|0x5C)
37
38 #define BASE5 0x150000
39 #define BASE6 0x160000
40 #define BASE7 0x170000
41
42 #define GPIOIEV     (BASE5 + 0x10)
43 #define GPIOIE      (BASE5 + 0x14)
44 #define GPIORIS     (BASE5 + 0x18)
45 #define GPIOMIS     (BASE5 + 0x1C)
46 #define GPIOIC      (BASE5 + 0x20)
47
48 #define INTMASK     (BASE6 + 0x0C)
49 #define INTMASK_VWAKEOUT (1U << 0)
50 #define INTMASK_VWAKEOUT_ACTIVE_LOW (1U << 8)
51 #define GPIOSEL     (BASE7 + 0x00)
52 #define GPIOSEL_VWAKEINT (1U << 0)
53
54 static DECLARE_WAIT_QUEUE_HEAD(toshiba_vsync_wait);
55
56 struct panel_info {
57         struct msm_mddi_client_data *client_data;
58         struct platform_device pdev;
59         struct msm_panel_data panel_data;
60         struct msmfb_callback *toshiba_callback;
61         int toshiba_got_int;
62 };
63
64
65 static void toshiba_request_vsync(struct msm_panel_data *panel_data,
66                                   struct msmfb_callback *callback)
67 {
68         struct panel_info *panel = container_of(panel_data, struct panel_info,
69                                                 panel_data);
70         struct msm_mddi_client_data *client_data = panel->client_data;
71
72         panel->toshiba_callback = callback;
73         if (panel->toshiba_got_int) {
74                 panel->toshiba_got_int = 0;
75                 client_data->activate_link(client_data);
76         }
77 }
78
79 static void toshiba_clear_vsync(struct msm_panel_data *panel_data)
80 {
81         struct panel_info *panel = container_of(panel_data, struct panel_info,
82                                                 panel_data);
83         struct msm_mddi_client_data *client_data = panel->client_data;
84
85         client_data->activate_link(client_data);
86 }
87
88 static void toshiba_wait_vsync(struct msm_panel_data *panel_data)
89 {
90         struct panel_info *panel = container_of(panel_data, struct panel_info,
91                                                 panel_data);
92         struct msm_mddi_client_data *client_data = panel->client_data;
93
94         if (panel->toshiba_got_int) {
95                 panel->toshiba_got_int = 0;
96                 client_data->activate_link(client_data); /* clears interrupt */
97         }
98         if (wait_event_timeout(toshiba_vsync_wait, panel->toshiba_got_int,
99                                 HZ/2) == 0)
100                 printk(KERN_ERR "timeout waiting for VSYNC\n");
101         panel->toshiba_got_int = 0;
102         /* interrupt clears when screen dma starts */
103 }
104
105 static int toshiba_suspend(struct msm_panel_data *panel_data)
106 {
107         struct panel_info *panel = container_of(panel_data, struct panel_info,
108                                                 panel_data);
109         struct msm_mddi_client_data *client_data = panel->client_data;
110
111         struct msm_mddi_bridge_platform_data *bridge_data =
112                 client_data->private_client_data;
113         int ret;
114
115         ret = bridge_data->uninit(bridge_data, client_data);
116         if (ret) {
117                 printk(KERN_INFO "mddi toshiba client: non zero return from "
118                         "uninit\n");
119                 return ret;
120         }
121         client_data->suspend(client_data);
122         return 0;
123 }
124
125 static int toshiba_resume(struct msm_panel_data *panel_data)
126 {
127         struct panel_info *panel = container_of(panel_data, struct panel_info,
128                                                 panel_data);
129         struct msm_mddi_client_data *client_data = panel->client_data;
130
131         struct msm_mddi_bridge_platform_data *bridge_data =
132                 client_data->private_client_data;
133         int ret;
134
135         client_data->resume(client_data);
136         ret = bridge_data->init(bridge_data, client_data);
137         if (ret)
138                 return ret;
139         return 0;
140 }
141
142 static int toshiba_blank(struct msm_panel_data *panel_data)
143 {
144         struct panel_info *panel = container_of(panel_data, struct panel_info,
145                                                 panel_data);
146         struct msm_mddi_client_data *client_data = panel->client_data;
147         struct msm_mddi_bridge_platform_data *bridge_data =
148                 client_data->private_client_data;
149
150         return bridge_data->blank(bridge_data, client_data);
151 }
152
153 static int toshiba_unblank(struct msm_panel_data *panel_data)
154 {
155         struct panel_info *panel = container_of(panel_data, struct panel_info,
156                                                 panel_data);
157         struct msm_mddi_client_data *client_data = panel->client_data;
158         struct msm_mddi_bridge_platform_data *bridge_data =
159                 client_data->private_client_data;
160
161         return bridge_data->unblank(bridge_data, client_data);
162 }
163
164 irqreturn_t toshiba_vsync_interrupt(int irq, void *data)
165 {
166         struct panel_info *panel = data;
167
168         panel->toshiba_got_int = 1;
169         if (panel->toshiba_callback) {
170                 panel->toshiba_callback->func(panel->toshiba_callback);
171                 panel->toshiba_callback = 0;
172         }
173         wake_up(&toshiba_vsync_wait);
174         return IRQ_HANDLED;
175 }
176
177 static int setup_vsync(struct panel_info *panel,
178                        int init)
179 {
180         int ret;
181         int gpio = 97;
182         unsigned int irq;
183
184         if (!init) {
185                 ret = 0;
186                 goto uninit;
187         }
188         ret = gpio_request(gpio, "vsync");
189         if (ret)
190                 goto err_request_gpio_failed;
191
192         ret = gpio_direction_input(gpio);
193         if (ret)
194                 goto err_gpio_direction_input_failed;
195
196         ret = irq = gpio_to_irq(gpio);
197         if (ret < 0)
198                 goto err_get_irq_num_failed;
199
200         ret = request_irq(irq, toshiba_vsync_interrupt, IRQF_TRIGGER_RISING,
201                           "vsync", panel);
202         if (ret)
203                 goto err_request_irq_failed;
204         printk(KERN_INFO "vsync on gpio %d now %d\n",
205                gpio, gpio_get_value(gpio));
206         return 0;
207
208 uninit:
209         free_irq(gpio_to_irq(gpio), panel);
210 err_request_irq_failed:
211 err_get_irq_num_failed:
212 err_gpio_direction_input_failed:
213         gpio_free(gpio);
214 err_request_gpio_failed:
215         return ret;
216 }
217
218 static int mddi_toshiba_probe(struct platform_device *pdev)
219 {
220         int ret;
221         struct msm_mddi_client_data *client_data = pdev->dev.platform_data;
222         struct msm_mddi_bridge_platform_data *bridge_data =
223                 client_data->private_client_data;
224         struct panel_info *panel =
225                 kzalloc(sizeof(struct panel_info), GFP_KERNEL);
226         if (!panel)
227                 return -ENOMEM;
228         platform_set_drvdata(pdev, panel);
229
230         /* mddi_remote_write(mddi, 0, WAKEUP); */
231         client_data->remote_write(client_data, GPIOSEL_VWAKEINT, GPIOSEL);
232         client_data->remote_write(client_data, INTMASK_VWAKEOUT, INTMASK);
233
234         ret = setup_vsync(panel, 1);
235         if (ret) {
236                 dev_err(&pdev->dev, "mddi_bridge_setup_vsync failed\n");
237                 return ret;
238         }
239
240         panel->client_data = client_data;
241         panel->panel_data.suspend = toshiba_suspend;
242         panel->panel_data.resume = toshiba_resume;
243         panel->panel_data.wait_vsync = toshiba_wait_vsync;
244         panel->panel_data.request_vsync = toshiba_request_vsync;
245         panel->panel_data.clear_vsync = toshiba_clear_vsync;
246         panel->panel_data.blank = toshiba_blank;
247         panel->panel_data.unblank = toshiba_unblank;
248         panel->panel_data.fb_data =  &bridge_data->fb_data;
249         panel->panel_data.caps = MSMFB_CAP_PARTIAL_UPDATES;
250
251         panel->pdev.name = "msm_panel";
252         panel->pdev.id = pdev->id;
253         panel->pdev.resource = client_data->fb_resource;
254         panel->pdev.num_resources = 1;
255         panel->pdev.dev.platform_data = &panel->panel_data;
256         bridge_data->init(bridge_data, client_data);
257         platform_device_register(&panel->pdev);
258
259         return 0;
260 }
261
262 static int mddi_toshiba_remove(struct platform_device *pdev)
263 {
264         struct panel_info *panel = platform_get_drvdata(pdev);
265
266         setup_vsync(panel, 0);
267         kfree(panel);
268         return 0;
269 }
270
271 static struct platform_driver mddi_client_d263_0000 = {
272         .probe = mddi_toshiba_probe,
273         .remove = mddi_toshiba_remove,
274         .driver = { .name = "mddi_c_d263_0000" },
275 };
276
277 static int __init mddi_client_toshiba_init(void)
278 {
279         platform_driver_register(&mddi_client_d263_0000);
280         return 0;
281 }
282
283 module_init(mddi_client_toshiba_init);
284