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 <mach/msm_fb.h>
26 #define LCD_CONTROL_BLOCK_BASE 0x110000
27 #define CMN (LCD_CONTROL_BLOCK_BASE|0x10)
28 #define INTFLG (LCD_CONTROL_BLOCK_BASE|0x18)
29 #define HCYCLE (LCD_CONTROL_BLOCK_BASE|0x34)
30 #define HDE_START (LCD_CONTROL_BLOCK_BASE|0x3C)
31 #define VPOS (LCD_CONTROL_BLOCK_BASE|0xC0)
32 #define MPLFBUF (LCD_CONTROL_BLOCK_BASE|0x20)
33 #define WAKEUP (LCD_CONTROL_BLOCK_BASE|0x54)
34 #define WSYN_DLY (LCD_CONTROL_BLOCK_BASE|0x58)
35 #define REGENB (LCD_CONTROL_BLOCK_BASE|0x5C)
37 #define BASE5 0x150000
38 #define BASE6 0x160000
39 #define BASE7 0x170000
41 #define GPIOIEV (BASE5 + 0x10)
42 #define GPIOIE (BASE5 + 0x14)
43 #define GPIORIS (BASE5 + 0x18)
44 #define GPIOMIS (BASE5 + 0x1C)
45 #define GPIOIC (BASE5 + 0x20)
47 #define INTMASK (BASE6 + 0x0C)
48 #define INTMASK_VWAKEOUT (1U << 0)
49 #define INTMASK_VWAKEOUT_ACTIVE_LOW (1U << 8)
50 #define GPIOSEL (BASE7 + 0x00)
51 #define GPIOSEL_VWAKEINT (1U << 0)
53 static DECLARE_WAIT_QUEUE_HEAD(toshiba_vsync_wait
);
56 struct msm_mddi_client_data
*client_data
;
57 struct platform_device pdev
;
58 struct msm_panel_data panel_data
;
59 struct msmfb_callback
*toshiba_callback
;
64 static void toshiba_request_vsync(struct msm_panel_data
*panel_data
,
65 struct msmfb_callback
*callback
)
67 struct panel_info
*panel
= container_of(panel_data
, struct panel_info
,
69 struct msm_mddi_client_data
*client_data
= panel
->client_data
;
71 panel
->toshiba_callback
= callback
;
72 if (panel
->toshiba_got_int
) {
73 panel
->toshiba_got_int
= 0;
74 client_data
->activate_link(client_data
);
78 static void toshiba_clear_vsync(struct msm_panel_data
*panel_data
)
80 struct panel_info
*panel
= container_of(panel_data
, struct panel_info
,
82 struct msm_mddi_client_data
*client_data
= panel
->client_data
;
84 client_data
->activate_link(client_data
);
87 static void toshiba_wait_vsync(struct msm_panel_data
*panel_data
)
89 struct panel_info
*panel
= container_of(panel_data
, struct panel_info
,
91 struct msm_mddi_client_data
*client_data
= panel
->client_data
;
93 if (panel
->toshiba_got_int
) {
94 panel
->toshiba_got_int
= 0;
95 client_data
->activate_link(client_data
); /* clears interrupt */
97 if (wait_event_timeout(toshiba_vsync_wait
, panel
->toshiba_got_int
,
99 printk(KERN_ERR
"timeout waiting for VSYNC\n");
100 panel
->toshiba_got_int
= 0;
101 /* interrupt clears when screen dma starts */
104 static int toshiba_suspend(struct msm_panel_data
*panel_data
)
106 struct panel_info
*panel
= container_of(panel_data
, struct panel_info
,
108 struct msm_mddi_client_data
*client_data
= panel
->client_data
;
110 struct msm_mddi_bridge_platform_data
*bridge_data
=
111 client_data
->private_client_data
;
114 ret
= bridge_data
->uninit(bridge_data
, client_data
);
116 printk(KERN_INFO
"mddi toshiba client: non zero return from "
120 client_data
->suspend(client_data
);
124 static int toshiba_resume(struct msm_panel_data
*panel_data
)
126 struct panel_info
*panel
= container_of(panel_data
, struct panel_info
,
128 struct msm_mddi_client_data
*client_data
= panel
->client_data
;
130 struct msm_mddi_bridge_platform_data
*bridge_data
=
131 client_data
->private_client_data
;
134 client_data
->resume(client_data
);
135 ret
= bridge_data
->init(bridge_data
, client_data
);
141 static int toshiba_blank(struct msm_panel_data
*panel_data
)
143 struct panel_info
*panel
= container_of(panel_data
, struct panel_info
,
145 struct msm_mddi_client_data
*client_data
= panel
->client_data
;
146 struct msm_mddi_bridge_platform_data
*bridge_data
=
147 client_data
->private_client_data
;
149 return bridge_data
->blank(bridge_data
, client_data
);
152 static int toshiba_unblank(struct msm_panel_data
*panel_data
)
154 struct panel_info
*panel
= container_of(panel_data
, struct panel_info
,
156 struct msm_mddi_client_data
*client_data
= panel
->client_data
;
157 struct msm_mddi_bridge_platform_data
*bridge_data
=
158 client_data
->private_client_data
;
160 return bridge_data
->unblank(bridge_data
, client_data
);
163 irqreturn_t
toshiba_vsync_interrupt(int irq
, void *data
)
165 struct panel_info
*panel
= data
;
167 panel
->toshiba_got_int
= 1;
168 if (panel
->toshiba_callback
) {
169 panel
->toshiba_callback
->func(panel
->toshiba_callback
);
170 panel
->toshiba_callback
= 0;
172 wake_up(&toshiba_vsync_wait
);
176 static int setup_vsync(struct panel_info
*panel
,
187 ret
= gpio_request(gpio
, "vsync");
189 goto err_request_gpio_failed
;
191 ret
= gpio_direction_input(gpio
);
193 goto err_gpio_direction_input_failed
;
195 ret
= irq
= gpio_to_irq(gpio
);
197 goto err_get_irq_num_failed
;
199 ret
= request_irq(irq
, toshiba_vsync_interrupt
, IRQF_TRIGGER_RISING
,
202 goto err_request_irq_failed
;
203 printk(KERN_INFO
"vsync on gpio %d now %d\n",
204 gpio
, gpio_get_value(gpio
));
208 free_irq(gpio_to_irq(gpio
), panel
);
209 err_request_irq_failed
:
210 err_get_irq_num_failed
:
211 err_gpio_direction_input_failed
:
213 err_request_gpio_failed
:
217 static int mddi_toshiba_probe(struct platform_device
*pdev
)
220 struct msm_mddi_client_data
*client_data
= pdev
->dev
.platform_data
;
221 struct msm_mddi_bridge_platform_data
*bridge_data
=
222 client_data
->private_client_data
;
223 struct panel_info
*panel
=
224 kzalloc(sizeof(struct panel_info
), GFP_KERNEL
);
227 platform_set_drvdata(pdev
, panel
);
229 /* mddi_remote_write(mddi, 0, WAKEUP); */
230 client_data
->remote_write(client_data
, GPIOSEL_VWAKEINT
, GPIOSEL
);
231 client_data
->remote_write(client_data
, INTMASK_VWAKEOUT
, INTMASK
);
233 ret
= setup_vsync(panel
, 1);
235 dev_err(&pdev
->dev
, "mddi_bridge_setup_vsync failed\n");
239 panel
->client_data
= client_data
;
240 panel
->panel_data
.suspend
= toshiba_suspend
;
241 panel
->panel_data
.resume
= toshiba_resume
;
242 panel
->panel_data
.wait_vsync
= toshiba_wait_vsync
;
243 panel
->panel_data
.request_vsync
= toshiba_request_vsync
;
244 panel
->panel_data
.clear_vsync
= toshiba_clear_vsync
;
245 panel
->panel_data
.blank
= toshiba_blank
;
246 panel
->panel_data
.unblank
= toshiba_unblank
;
247 panel
->panel_data
.fb_data
= &bridge_data
->fb_data
;
248 panel
->panel_data
.caps
= MSMFB_CAP_PARTIAL_UPDATES
;
250 panel
->pdev
.name
= "msm_panel";
251 panel
->pdev
.id
= pdev
->id
;
252 panel
->pdev
.resource
= client_data
->fb_resource
;
253 panel
->pdev
.num_resources
= 1;
254 panel
->pdev
.dev
.platform_data
= &panel
->panel_data
;
255 bridge_data
->init(bridge_data
, client_data
);
256 platform_device_register(&panel
->pdev
);
261 static int mddi_toshiba_remove(struct platform_device
*pdev
)
263 struct panel_info
*panel
= platform_get_drvdata(pdev
);
265 setup_vsync(panel
, 0);
270 static struct platform_driver mddi_client_d263_0000
= {
271 .probe
= mddi_toshiba_probe
,
272 .remove
= mddi_toshiba_remove
,
273 .driver
= { .name
= "mddi_c_d263_0000" },
276 static int __init
mddi_client_toshiba_init(void)
278 platform_driver_register(&mddi_client_d263_0000
);
282 module_init(mddi_client_toshiba_init
);