Blackfin: bf548-ezkit/bf561-ezkit: update nor flash layout
[zen-stable.git] / drivers / video / msm / mddi_client_nt35399.c
blobf239f4a25e014d5f93b6099c7024a85f5de4f88e
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/sched.h>
23 #include <linux/gpio.h>
24 #include <linux/slab.h>
25 #include <mach/msm_fb.h>
27 static DECLARE_WAIT_QUEUE_HEAD(nt35399_vsync_wait);
29 struct panel_info {
30 struct msm_mddi_client_data *client_data;
31 struct platform_device pdev;
32 struct msm_panel_data panel_data;
33 struct msmfb_callback *fb_callback;
34 struct work_struct panel_work;
35 struct workqueue_struct *fb_wq;
36 int nt35399_got_int;
39 static void
40 nt35399_request_vsync(struct msm_panel_data *panel_data,
41 struct msmfb_callback *callback)
43 struct panel_info *panel = container_of(panel_data, struct panel_info,
44 panel_data);
45 struct msm_mddi_client_data *client_data = panel->client_data;
47 panel->fb_callback = callback;
48 if (panel->nt35399_got_int) {
49 panel->nt35399_got_int = 0;
50 client_data->activate_link(client_data); /* clears interrupt */
54 static void nt35399_wait_vsync(struct msm_panel_data *panel_data)
56 struct panel_info *panel = container_of(panel_data, struct panel_info,
57 panel_data);
58 struct msm_mddi_client_data *client_data = panel->client_data;
60 if (panel->nt35399_got_int) {
61 panel->nt35399_got_int = 0;
62 client_data->activate_link(client_data); /* clears interrupt */
65 if (wait_event_timeout(nt35399_vsync_wait, panel->nt35399_got_int,
66 HZ/2) == 0)
67 printk(KERN_ERR "timeout waiting for VSYNC\n");
69 panel->nt35399_got_int = 0;
70 /* interrupt clears when screen dma starts */
73 static int nt35399_suspend(struct msm_panel_data *panel_data)
75 struct panel_info *panel = container_of(panel_data, struct panel_info,
76 panel_data);
77 struct msm_mddi_client_data *client_data = panel->client_data;
79 struct msm_mddi_bridge_platform_data *bridge_data =
80 client_data->private_client_data;
81 int ret;
83 ret = bridge_data->uninit(bridge_data, client_data);
84 if (ret) {
85 printk(KERN_INFO "mddi nt35399 client: non zero return from "
86 "uninit\n");
87 return ret;
89 client_data->suspend(client_data);
90 return 0;
93 static int nt35399_resume(struct msm_panel_data *panel_data)
95 struct panel_info *panel = container_of(panel_data, struct panel_info,
96 panel_data);
97 struct msm_mddi_client_data *client_data = panel->client_data;
99 struct msm_mddi_bridge_platform_data *bridge_data =
100 client_data->private_client_data;
101 int ret;
103 client_data->resume(client_data);
104 ret = bridge_data->init(bridge_data, client_data);
105 if (ret)
106 return ret;
107 return 0;
110 static int nt35399_blank(struct msm_panel_data *panel_data)
112 struct panel_info *panel = container_of(panel_data, struct panel_info,
113 panel_data);
114 struct msm_mddi_client_data *client_data = panel->client_data;
115 struct msm_mddi_bridge_platform_data *bridge_data =
116 client_data->private_client_data;
118 return bridge_data->blank(bridge_data, client_data);
121 static int nt35399_unblank(struct msm_panel_data *panel_data)
123 struct panel_info *panel = container_of(panel_data, struct panel_info,
124 panel_data);
125 struct msm_mddi_client_data *client_data = panel->client_data;
126 struct msm_mddi_bridge_platform_data *bridge_data =
127 client_data->private_client_data;
129 return bridge_data->unblank(bridge_data, client_data);
132 irqreturn_t nt35399_vsync_interrupt(int irq, void *data)
134 struct panel_info *panel = data;
136 panel->nt35399_got_int = 1;
138 if (panel->fb_callback) {
139 panel->fb_callback->func(panel->fb_callback);
140 panel->fb_callback = NULL;
143 wake_up(&nt35399_vsync_wait);
145 return IRQ_HANDLED;
148 static int setup_vsync(struct panel_info *panel, int init)
150 int ret;
151 int gpio = 97;
152 unsigned int irq;
154 if (!init) {
155 ret = 0;
156 goto uninit;
158 ret = gpio_request(gpio, "vsync");
159 if (ret)
160 goto err_request_gpio_failed;
162 ret = gpio_direction_input(gpio);
163 if (ret)
164 goto err_gpio_direction_input_failed;
166 ret = irq = gpio_to_irq(gpio);
167 if (ret < 0)
168 goto err_get_irq_num_failed;
170 ret = request_irq(irq, nt35399_vsync_interrupt, IRQF_TRIGGER_RISING,
171 "vsync", panel);
172 if (ret)
173 goto err_request_irq_failed;
175 printk(KERN_INFO "vsync on gpio %d now %d\n",
176 gpio, gpio_get_value(gpio));
177 return 0;
179 uninit:
180 free_irq(gpio_to_irq(gpio), panel->client_data);
181 err_request_irq_failed:
182 err_get_irq_num_failed:
183 err_gpio_direction_input_failed:
184 gpio_free(gpio);
185 err_request_gpio_failed:
186 return ret;
189 static int mddi_nt35399_probe(struct platform_device *pdev)
191 struct msm_mddi_client_data *client_data = pdev->dev.platform_data;
192 struct msm_mddi_bridge_platform_data *bridge_data =
193 client_data->private_client_data;
195 int ret;
197 struct panel_info *panel = kzalloc(sizeof(struct panel_info),
198 GFP_KERNEL);
200 printk(KERN_DEBUG "%s: enter.\n", __func__);
202 if (!panel)
203 return -ENOMEM;
204 platform_set_drvdata(pdev, panel);
206 ret = setup_vsync(panel, 1);
207 if (ret) {
208 dev_err(&pdev->dev, "mddi_nt35399_setup_vsync failed\n");
209 return ret;
212 panel->client_data = client_data;
213 panel->panel_data.suspend = nt35399_suspend;
214 panel->panel_data.resume = nt35399_resume;
215 panel->panel_data.wait_vsync = nt35399_wait_vsync;
216 panel->panel_data.request_vsync = nt35399_request_vsync;
217 panel->panel_data.blank = nt35399_blank;
218 panel->panel_data.unblank = nt35399_unblank;
219 panel->panel_data.fb_data = &bridge_data->fb_data;
220 panel->panel_data.caps = 0;
222 panel->pdev.name = "msm_panel";
223 panel->pdev.id = pdev->id;
224 panel->pdev.resource = client_data->fb_resource;
225 panel->pdev.num_resources = 1;
226 panel->pdev.dev.platform_data = &panel->panel_data;
228 if (bridge_data->init)
229 bridge_data->init(bridge_data, client_data);
231 platform_device_register(&panel->pdev);
233 return 0;
236 static int mddi_nt35399_remove(struct platform_device *pdev)
238 struct panel_info *panel = platform_get_drvdata(pdev);
240 setup_vsync(panel, 0);
241 kfree(panel);
242 return 0;
245 static struct platform_driver mddi_client_0bda_8a47 = {
246 .probe = mddi_nt35399_probe,
247 .remove = mddi_nt35399_remove,
248 .driver = { .name = "mddi_c_0bda_8a47" },
251 static int __init mddi_client_nt35399_init(void)
253 return platform_driver_register(&mddi_client_0bda_8a47);
256 module_init(mddi_client_nt35399_init);