Merge branch 'sched-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / video / msm / mddi_client_toshiba.c
blobf9bc932ac46b32809ff3ff4d9b13fe8a4d459b5d
1 /* drivers/video/msm_fb/mddi_client_toshiba.c
3 * Support for Toshiba TC358720XBG mddi client devices which require no
4 * special initialization code.
6 * Copyright (C) 2007 Google Incorporated
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.
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.
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 <linux/slab.h>
25 #include <mach/msm_fb.h>
28 #define LCD_CONTROL_BLOCK_BASE 0x110000
29 #define CMN (LCD_CONTROL_BLOCK_BASE|0x10)
30 #define INTFLG (LCD_CONTROL_BLOCK_BASE|0x18)
31 #define HCYCLE (LCD_CONTROL_BLOCK_BASE|0x34)
32 #define HDE_START (LCD_CONTROL_BLOCK_BASE|0x3C)
33 #define VPOS (LCD_CONTROL_BLOCK_BASE|0xC0)
34 #define MPLFBUF (LCD_CONTROL_BLOCK_BASE|0x20)
35 #define WAKEUP (LCD_CONTROL_BLOCK_BASE|0x54)
36 #define WSYN_DLY (LCD_CONTROL_BLOCK_BASE|0x58)
37 #define REGENB (LCD_CONTROL_BLOCK_BASE|0x5C)
39 #define BASE5 0x150000
40 #define BASE6 0x160000
41 #define BASE7 0x170000
43 #define GPIOIEV (BASE5 + 0x10)
44 #define GPIOIE (BASE5 + 0x14)
45 #define GPIORIS (BASE5 + 0x18)
46 #define GPIOMIS (BASE5 + 0x1C)
47 #define GPIOIC (BASE5 + 0x20)
49 #define INTMASK (BASE6 + 0x0C)
50 #define INTMASK_VWAKEOUT (1U << 0)
51 #define INTMASK_VWAKEOUT_ACTIVE_LOW (1U << 8)
52 #define GPIOSEL (BASE7 + 0x00)
53 #define GPIOSEL_VWAKEINT (1U << 0)
55 static DECLARE_WAIT_QUEUE_HEAD(toshiba_vsync_wait);
57 struct panel_info {
58 struct msm_mddi_client_data *client_data;
59 struct platform_device pdev;
60 struct msm_panel_data panel_data;
61 struct msmfb_callback *toshiba_callback;
62 int toshiba_got_int;
66 static void toshiba_request_vsync(struct msm_panel_data *panel_data,
67 struct msmfb_callback *callback)
69 struct panel_info *panel = container_of(panel_data, struct panel_info,
70 panel_data);
71 struct msm_mddi_client_data *client_data = panel->client_data;
73 panel->toshiba_callback = callback;
74 if (panel->toshiba_got_int) {
75 panel->toshiba_got_int = 0;
76 client_data->activate_link(client_data);
80 static void toshiba_clear_vsync(struct msm_panel_data *panel_data)
82 struct panel_info *panel = container_of(panel_data, struct panel_info,
83 panel_data);
84 struct msm_mddi_client_data *client_data = panel->client_data;
86 client_data->activate_link(client_data);
89 static void toshiba_wait_vsync(struct msm_panel_data *panel_data)
91 struct panel_info *panel = container_of(panel_data, struct panel_info,
92 panel_data);
93 struct msm_mddi_client_data *client_data = panel->client_data;
95 if (panel->toshiba_got_int) {
96 panel->toshiba_got_int = 0;
97 client_data->activate_link(client_data); /* clears interrupt */
99 if (wait_event_timeout(toshiba_vsync_wait, panel->toshiba_got_int,
100 HZ/2) == 0)
101 printk(KERN_ERR "timeout waiting for VSYNC\n");
102 panel->toshiba_got_int = 0;
103 /* interrupt clears when screen dma starts */
106 static int toshiba_suspend(struct msm_panel_data *panel_data)
108 struct panel_info *panel = container_of(panel_data, struct panel_info,
109 panel_data);
110 struct msm_mddi_client_data *client_data = panel->client_data;
112 struct msm_mddi_bridge_platform_data *bridge_data =
113 client_data->private_client_data;
114 int ret;
116 ret = bridge_data->uninit(bridge_data, client_data);
117 if (ret) {
118 printk(KERN_INFO "mddi toshiba client: non zero return from "
119 "uninit\n");
120 return ret;
122 client_data->suspend(client_data);
123 return 0;
126 static int toshiba_resume(struct msm_panel_data *panel_data)
128 struct panel_info *panel = container_of(panel_data, struct panel_info,
129 panel_data);
130 struct msm_mddi_client_data *client_data = panel->client_data;
132 struct msm_mddi_bridge_platform_data *bridge_data =
133 client_data->private_client_data;
134 int ret;
136 client_data->resume(client_data);
137 ret = bridge_data->init(bridge_data, client_data);
138 if (ret)
139 return ret;
140 return 0;
143 static int toshiba_blank(struct msm_panel_data *panel_data)
145 struct panel_info *panel = container_of(panel_data, struct panel_info,
146 panel_data);
147 struct msm_mddi_client_data *client_data = panel->client_data;
148 struct msm_mddi_bridge_platform_data *bridge_data =
149 client_data->private_client_data;
151 return bridge_data->blank(bridge_data, client_data);
154 static int toshiba_unblank(struct msm_panel_data *panel_data)
156 struct panel_info *panel = container_of(panel_data, struct panel_info,
157 panel_data);
158 struct msm_mddi_client_data *client_data = panel->client_data;
159 struct msm_mddi_bridge_platform_data *bridge_data =
160 client_data->private_client_data;
162 return bridge_data->unblank(bridge_data, client_data);
165 irqreturn_t toshiba_vsync_interrupt(int irq, void *data)
167 struct panel_info *panel = data;
169 panel->toshiba_got_int = 1;
170 if (panel->toshiba_callback) {
171 panel->toshiba_callback->func(panel->toshiba_callback);
172 panel->toshiba_callback = 0;
174 wake_up(&toshiba_vsync_wait);
175 return IRQ_HANDLED;
178 static int setup_vsync(struct panel_info *panel,
179 int init)
181 int ret;
182 int gpio = 97;
183 unsigned int irq;
185 if (!init) {
186 ret = 0;
187 goto uninit;
189 ret = gpio_request(gpio, "vsync");
190 if (ret)
191 goto err_request_gpio_failed;
193 ret = gpio_direction_input(gpio);
194 if (ret)
195 goto err_gpio_direction_input_failed;
197 ret = irq = gpio_to_irq(gpio);
198 if (ret < 0)
199 goto err_get_irq_num_failed;
201 ret = request_irq(irq, toshiba_vsync_interrupt, IRQF_TRIGGER_RISING,
202 "vsync", panel);
203 if (ret)
204 goto err_request_irq_failed;
205 printk(KERN_INFO "vsync on gpio %d now %d\n",
206 gpio, gpio_get_value(gpio));
207 return 0;
209 uninit:
210 free_irq(gpio_to_irq(gpio), panel);
211 err_request_irq_failed:
212 err_get_irq_num_failed:
213 err_gpio_direction_input_failed:
214 gpio_free(gpio);
215 err_request_gpio_failed:
216 return ret;
219 static int mddi_toshiba_probe(struct platform_device *pdev)
221 int ret;
222 struct msm_mddi_client_data *client_data = pdev->dev.platform_data;
223 struct msm_mddi_bridge_platform_data *bridge_data =
224 client_data->private_client_data;
225 struct panel_info *panel =
226 kzalloc(sizeof(struct panel_info), GFP_KERNEL);
227 if (!panel)
228 return -ENOMEM;
229 platform_set_drvdata(pdev, panel);
231 /* mddi_remote_write(mddi, 0, WAKEUP); */
232 client_data->remote_write(client_data, GPIOSEL_VWAKEINT, GPIOSEL);
233 client_data->remote_write(client_data, INTMASK_VWAKEOUT, INTMASK);
235 ret = setup_vsync(panel, 1);
236 if (ret) {
237 dev_err(&pdev->dev, "mddi_bridge_setup_vsync failed\n");
238 return ret;
241 panel->client_data = client_data;
242 panel->panel_data.suspend = toshiba_suspend;
243 panel->panel_data.resume = toshiba_resume;
244 panel->panel_data.wait_vsync = toshiba_wait_vsync;
245 panel->panel_data.request_vsync = toshiba_request_vsync;
246 panel->panel_data.clear_vsync = toshiba_clear_vsync;
247 panel->panel_data.blank = toshiba_blank;
248 panel->panel_data.unblank = toshiba_unblank;
249 panel->panel_data.fb_data = &bridge_data->fb_data;
250 panel->panel_data.caps = MSMFB_CAP_PARTIAL_UPDATES;
252 panel->pdev.name = "msm_panel";
253 panel->pdev.id = pdev->id;
254 panel->pdev.resource = client_data->fb_resource;
255 panel->pdev.num_resources = 1;
256 panel->pdev.dev.platform_data = &panel->panel_data;
257 bridge_data->init(bridge_data, client_data);
258 platform_device_register(&panel->pdev);
260 return 0;
263 static int mddi_toshiba_remove(struct platform_device *pdev)
265 struct panel_info *panel = platform_get_drvdata(pdev);
267 setup_vsync(panel, 0);
268 kfree(panel);
269 return 0;
272 static struct platform_driver mddi_client_d263_0000 = {
273 .probe = mddi_toshiba_probe,
274 .remove = mddi_toshiba_remove,
275 .driver = { .name = "mddi_c_d263_0000" },
278 static int __init mddi_client_toshiba_init(void)
280 platform_driver_register(&mddi_client_d263_0000);
281 return 0;
284 module_init(mddi_client_toshiba_init);