OMAP3: GPIO: disable GPIO debounce clocks on idle
[linux-ginger.git] / drivers / video / msm / mddi_client_nt35399.c
blob9c78050ac79974df6334114f58d4a83b8f9bc9fc
1 /* drivers/video/msm_fb/mddi_client_nt35399.c
3 * Support for Novatek NT35399 MDDI client of Sapphire
5 * Copyright (C) 2008 HTC Incorporated
6 * Author: Solomon Chiu (solomon_chiu@htc.com)
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 <mach/msm_fb.h>
25 static DECLARE_WAIT_QUEUE_HEAD(nt35399_vsync_wait);
27 struct panel_info {
28 struct msm_mddi_client_data *client_data;
29 struct platform_device pdev;
30 struct msm_panel_data panel_data;
31 struct msmfb_callback *fb_callback;
32 struct work_struct panel_work;
33 struct workqueue_struct *fb_wq;
34 int nt35399_got_int;
37 static void
38 nt35399_request_vsync(struct msm_panel_data *panel_data,
39 struct msmfb_callback *callback)
41 struct panel_info *panel = container_of(panel_data, struct panel_info,
42 panel_data);
43 struct msm_mddi_client_data *client_data = panel->client_data;
45 panel->fb_callback = callback;
46 if (panel->nt35399_got_int) {
47 panel->nt35399_got_int = 0;
48 client_data->activate_link(client_data); /* clears interrupt */
52 static void nt35399_wait_vsync(struct msm_panel_data *panel_data)
54 struct panel_info *panel = container_of(panel_data, struct panel_info,
55 panel_data);
56 struct msm_mddi_client_data *client_data = panel->client_data;
58 if (panel->nt35399_got_int) {
59 panel->nt35399_got_int = 0;
60 client_data->activate_link(client_data); /* clears interrupt */
63 if (wait_event_timeout(nt35399_vsync_wait, panel->nt35399_got_int,
64 HZ/2) == 0)
65 printk(KERN_ERR "timeout waiting for VSYNC\n");
67 panel->nt35399_got_int = 0;
68 /* interrupt clears when screen dma starts */
71 static int nt35399_suspend(struct msm_panel_data *panel_data)
73 struct panel_info *panel = container_of(panel_data, struct panel_info,
74 panel_data);
75 struct msm_mddi_client_data *client_data = panel->client_data;
77 struct msm_mddi_bridge_platform_data *bridge_data =
78 client_data->private_client_data;
79 int ret;
81 ret = bridge_data->uninit(bridge_data, client_data);
82 if (ret) {
83 printk(KERN_INFO "mddi nt35399 client: non zero return from "
84 "uninit\n");
85 return ret;
87 client_data->suspend(client_data);
88 return 0;
91 static int nt35399_resume(struct msm_panel_data *panel_data)
93 struct panel_info *panel = container_of(panel_data, struct panel_info,
94 panel_data);
95 struct msm_mddi_client_data *client_data = panel->client_data;
97 struct msm_mddi_bridge_platform_data *bridge_data =
98 client_data->private_client_data;
99 int ret;
101 client_data->resume(client_data);
102 ret = bridge_data->init(bridge_data, client_data);
103 if (ret)
104 return ret;
105 return 0;
108 static int nt35399_blank(struct msm_panel_data *panel_data)
110 struct panel_info *panel = container_of(panel_data, struct panel_info,
111 panel_data);
112 struct msm_mddi_client_data *client_data = panel->client_data;
113 struct msm_mddi_bridge_platform_data *bridge_data =
114 client_data->private_client_data;
116 return bridge_data->blank(bridge_data, client_data);
119 static int nt35399_unblank(struct msm_panel_data *panel_data)
121 struct panel_info *panel = container_of(panel_data, struct panel_info,
122 panel_data);
123 struct msm_mddi_client_data *client_data = panel->client_data;
124 struct msm_mddi_bridge_platform_data *bridge_data =
125 client_data->private_client_data;
127 return bridge_data->unblank(bridge_data, client_data);
130 irqreturn_t nt35399_vsync_interrupt(int irq, void *data)
132 struct panel_info *panel = data;
134 panel->nt35399_got_int = 1;
136 if (panel->fb_callback) {
137 panel->fb_callback->func(panel->fb_callback);
138 panel->fb_callback = NULL;
141 wake_up(&nt35399_vsync_wait);
143 return IRQ_HANDLED;
146 static int setup_vsync(struct panel_info *panel, int init)
148 int ret;
149 int gpio = 97;
150 unsigned int irq;
152 if (!init) {
153 ret = 0;
154 goto uninit;
156 ret = gpio_request(gpio, "vsync");
157 if (ret)
158 goto err_request_gpio_failed;
160 ret = gpio_direction_input(gpio);
161 if (ret)
162 goto err_gpio_direction_input_failed;
164 ret = irq = gpio_to_irq(gpio);
165 if (ret < 0)
166 goto err_get_irq_num_failed;
168 ret = request_irq(irq, nt35399_vsync_interrupt, IRQF_TRIGGER_RISING,
169 "vsync", panel);
170 if (ret)
171 goto err_request_irq_failed;
173 printk(KERN_INFO "vsync on gpio %d now %d\n",
174 gpio, gpio_get_value(gpio));
175 return 0;
177 uninit:
178 free_irq(gpio_to_irq(gpio), panel->client_data);
179 err_request_irq_failed:
180 err_get_irq_num_failed:
181 err_gpio_direction_input_failed:
182 gpio_free(gpio);
183 err_request_gpio_failed:
184 return ret;
187 static int mddi_nt35399_probe(struct platform_device *pdev)
189 struct msm_mddi_client_data *client_data = pdev->dev.platform_data;
190 struct msm_mddi_bridge_platform_data *bridge_data =
191 client_data->private_client_data;
193 int ret;
195 struct panel_info *panel = kzalloc(sizeof(struct panel_info),
196 GFP_KERNEL);
198 printk(KERN_DEBUG "%s: enter.\n", __func__);
200 if (!panel)
201 return -ENOMEM;
202 platform_set_drvdata(pdev, panel);
204 ret = setup_vsync(panel, 1);
205 if (ret) {
206 dev_err(&pdev->dev, "mddi_nt35399_setup_vsync failed\n");
207 return ret;
210 panel->client_data = client_data;
211 panel->panel_data.suspend = nt35399_suspend;
212 panel->panel_data.resume = nt35399_resume;
213 panel->panel_data.wait_vsync = nt35399_wait_vsync;
214 panel->panel_data.request_vsync = nt35399_request_vsync;
215 panel->panel_data.blank = nt35399_blank;
216 panel->panel_data.unblank = nt35399_unblank;
217 panel->panel_data.fb_data = &bridge_data->fb_data;
218 panel->panel_data.caps = 0;
220 panel->pdev.name = "msm_panel";
221 panel->pdev.id = pdev->id;
222 panel->pdev.resource = client_data->fb_resource;
223 panel->pdev.num_resources = 1;
224 panel->pdev.dev.platform_data = &panel->panel_data;
226 if (bridge_data->init)
227 bridge_data->init(bridge_data, client_data);
229 platform_device_register(&panel->pdev);
231 return 0;
234 static int mddi_nt35399_remove(struct platform_device *pdev)
236 struct panel_info *panel = platform_get_drvdata(pdev);
238 setup_vsync(panel, 0);
239 kfree(panel);
240 return 0;
243 static struct platform_driver mddi_client_0bda_8a47 = {
244 .probe = mddi_nt35399_probe,
245 .remove = mddi_nt35399_remove,
246 .driver = { .name = "mddi_c_0bda_8a47" },
249 static int __init mddi_client_nt35399_init(void)
251 return platform_driver_register(&mddi_client_0bda_8a47);
254 module_init(mddi_client_nt35399_init);