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 <mach/msm_fb.h>
26 static DECLARE_WAIT_QUEUE_HEAD(nt35399_vsync_wait
);
29 struct msm_mddi_client_data
*client_data
;
30 struct platform_device pdev
;
31 struct msm_panel_data panel_data
;
32 struct msmfb_callback
*fb_callback
;
33 struct work_struct panel_work
;
34 struct workqueue_struct
*fb_wq
;
39 nt35399_request_vsync(struct msm_panel_data
*panel_data
,
40 struct msmfb_callback
*callback
)
42 struct panel_info
*panel
= container_of(panel_data
, struct panel_info
,
44 struct msm_mddi_client_data
*client_data
= panel
->client_data
;
46 panel
->fb_callback
= callback
;
47 if (panel
->nt35399_got_int
) {
48 panel
->nt35399_got_int
= 0;
49 client_data
->activate_link(client_data
); /* clears interrupt */
53 static void nt35399_wait_vsync(struct msm_panel_data
*panel_data
)
55 struct panel_info
*panel
= container_of(panel_data
, struct panel_info
,
57 struct msm_mddi_client_data
*client_data
= panel
->client_data
;
59 if (panel
->nt35399_got_int
) {
60 panel
->nt35399_got_int
= 0;
61 client_data
->activate_link(client_data
); /* clears interrupt */
64 if (wait_event_timeout(nt35399_vsync_wait
, panel
->nt35399_got_int
,
66 printk(KERN_ERR
"timeout waiting for VSYNC\n");
68 panel
->nt35399_got_int
= 0;
69 /* interrupt clears when screen dma starts */
72 static int nt35399_suspend(struct msm_panel_data
*panel_data
)
74 struct panel_info
*panel
= container_of(panel_data
, struct panel_info
,
76 struct msm_mddi_client_data
*client_data
= panel
->client_data
;
78 struct msm_mddi_bridge_platform_data
*bridge_data
=
79 client_data
->private_client_data
;
82 ret
= bridge_data
->uninit(bridge_data
, client_data
);
84 printk(KERN_INFO
"mddi nt35399 client: non zero return from "
88 client_data
->suspend(client_data
);
92 static int nt35399_resume(struct msm_panel_data
*panel_data
)
94 struct panel_info
*panel
= container_of(panel_data
, struct panel_info
,
96 struct msm_mddi_client_data
*client_data
= panel
->client_data
;
98 struct msm_mddi_bridge_platform_data
*bridge_data
=
99 client_data
->private_client_data
;
102 client_data
->resume(client_data
);
103 ret
= bridge_data
->init(bridge_data
, client_data
);
109 static int nt35399_blank(struct msm_panel_data
*panel_data
)
111 struct panel_info
*panel
= container_of(panel_data
, struct panel_info
,
113 struct msm_mddi_client_data
*client_data
= panel
->client_data
;
114 struct msm_mddi_bridge_platform_data
*bridge_data
=
115 client_data
->private_client_data
;
117 return bridge_data
->blank(bridge_data
, client_data
);
120 static int nt35399_unblank(struct msm_panel_data
*panel_data
)
122 struct panel_info
*panel
= container_of(panel_data
, struct panel_info
,
124 struct msm_mddi_client_data
*client_data
= panel
->client_data
;
125 struct msm_mddi_bridge_platform_data
*bridge_data
=
126 client_data
->private_client_data
;
128 return bridge_data
->unblank(bridge_data
, client_data
);
131 irqreturn_t
nt35399_vsync_interrupt(int irq
, void *data
)
133 struct panel_info
*panel
= data
;
135 panel
->nt35399_got_int
= 1;
137 if (panel
->fb_callback
) {
138 panel
->fb_callback
->func(panel
->fb_callback
);
139 panel
->fb_callback
= NULL
;
142 wake_up(&nt35399_vsync_wait
);
147 static int setup_vsync(struct panel_info
*panel
, int init
)
157 ret
= gpio_request(gpio
, "vsync");
159 goto err_request_gpio_failed
;
161 ret
= gpio_direction_input(gpio
);
163 goto err_gpio_direction_input_failed
;
165 ret
= irq
= gpio_to_irq(gpio
);
167 goto err_get_irq_num_failed
;
169 ret
= request_irq(irq
, nt35399_vsync_interrupt
, IRQF_TRIGGER_RISING
,
172 goto err_request_irq_failed
;
174 printk(KERN_INFO
"vsync on gpio %d now %d\n",
175 gpio
, gpio_get_value(gpio
));
179 free_irq(gpio_to_irq(gpio
), panel
->client_data
);
180 err_request_irq_failed
:
181 err_get_irq_num_failed
:
182 err_gpio_direction_input_failed
:
184 err_request_gpio_failed
:
188 static int mddi_nt35399_probe(struct platform_device
*pdev
)
190 struct msm_mddi_client_data
*client_data
= pdev
->dev
.platform_data
;
191 struct msm_mddi_bridge_platform_data
*bridge_data
=
192 client_data
->private_client_data
;
196 struct panel_info
*panel
= kzalloc(sizeof(struct panel_info
),
199 printk(KERN_DEBUG
"%s: enter.\n", __func__
);
203 platform_set_drvdata(pdev
, panel
);
205 ret
= setup_vsync(panel
, 1);
207 dev_err(&pdev
->dev
, "mddi_nt35399_setup_vsync failed\n");
211 panel
->client_data
= client_data
;
212 panel
->panel_data
.suspend
= nt35399_suspend
;
213 panel
->panel_data
.resume
= nt35399_resume
;
214 panel
->panel_data
.wait_vsync
= nt35399_wait_vsync
;
215 panel
->panel_data
.request_vsync
= nt35399_request_vsync
;
216 panel
->panel_data
.blank
= nt35399_blank
;
217 panel
->panel_data
.unblank
= nt35399_unblank
;
218 panel
->panel_data
.fb_data
= &bridge_data
->fb_data
;
219 panel
->panel_data
.caps
= 0;
221 panel
->pdev
.name
= "msm_panel";
222 panel
->pdev
.id
= pdev
->id
;
223 panel
->pdev
.resource
= client_data
->fb_resource
;
224 panel
->pdev
.num_resources
= 1;
225 panel
->pdev
.dev
.platform_data
= &panel
->panel_data
;
227 if (bridge_data
->init
)
228 bridge_data
->init(bridge_data
, client_data
);
230 platform_device_register(&panel
->pdev
);
235 static int mddi_nt35399_remove(struct platform_device
*pdev
)
237 struct panel_info
*panel
= platform_get_drvdata(pdev
);
239 setup_vsync(panel
, 0);
244 static struct platform_driver mddi_client_0bda_8a47
= {
245 .probe
= mddi_nt35399_probe
,
246 .remove
= mddi_nt35399_remove
,
247 .driver
= { .name
= "mddi_c_0bda_8a47" },
250 static int __init
mddi_client_nt35399_init(void)
252 return platform_driver_register(&mddi_client_0bda_8a47
);
255 module_init(mddi_client_nt35399_init
);