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 <mach/msm_fb.h>
27 #define LCD_CONTROL_BLOCK_BASE 0x110000
28 #define CMN (LCD_CONTROL_BLOCK_BASE|0x10)
29 #define INTFLG (LCD_CONTROL_BLOCK_BASE|0x18)
30 #define HCYCLE (LCD_CONTROL_BLOCK_BASE|0x34)
31 #define HDE_START (LCD_CONTROL_BLOCK_BASE|0x3C)
32 #define VPOS (LCD_CONTROL_BLOCK_BASE|0xC0)
33 #define MPLFBUF (LCD_CONTROL_BLOCK_BASE|0x20)
34 #define WAKEUP (LCD_CONTROL_BLOCK_BASE|0x54)
35 #define WSYN_DLY (LCD_CONTROL_BLOCK_BASE|0x58)
36 #define REGENB (LCD_CONTROL_BLOCK_BASE|0x5C)
38 #define BASE5 0x150000
39 #define BASE6 0x160000
40 #define BASE7 0x170000
42 #define GPIOIEV (BASE5 + 0x10)
43 #define GPIOIE (BASE5 + 0x14)
44 #define GPIORIS (BASE5 + 0x18)
45 #define GPIOMIS (BASE5 + 0x1C)
46 #define GPIOIC (BASE5 + 0x20)
48 #define INTMASK (BASE6 + 0x0C)
49 #define INTMASK_VWAKEOUT (1U << 0)
50 #define INTMASK_VWAKEOUT_ACTIVE_LOW (1U << 8)
51 #define GPIOSEL (BASE7 + 0x00)
52 #define GPIOSEL_VWAKEINT (1U << 0)
54 static DECLARE_WAIT_QUEUE_HEAD(toshiba_vsync_wait
);
57 struct msm_mddi_client_data
*client_data
;
58 struct platform_device pdev
;
59 struct msm_panel_data panel_data
;
60 struct msmfb_callback
*toshiba_callback
;
65 static void toshiba_request_vsync(struct msm_panel_data
*panel_data
,
66 struct msmfb_callback
*callback
)
68 struct panel_info
*panel
= container_of(panel_data
, struct panel_info
,
70 struct msm_mddi_client_data
*client_data
= panel
->client_data
;
72 panel
->toshiba_callback
= callback
;
73 if (panel
->toshiba_got_int
) {
74 panel
->toshiba_got_int
= 0;
75 client_data
->activate_link(client_data
);
79 static void toshiba_clear_vsync(struct msm_panel_data
*panel_data
)
81 struct panel_info
*panel
= container_of(panel_data
, struct panel_info
,
83 struct msm_mddi_client_data
*client_data
= panel
->client_data
;
85 client_data
->activate_link(client_data
);
88 static void toshiba_wait_vsync(struct msm_panel_data
*panel_data
)
90 struct panel_info
*panel
= container_of(panel_data
, struct panel_info
,
92 struct msm_mddi_client_data
*client_data
= panel
->client_data
;
94 if (panel
->toshiba_got_int
) {
95 panel
->toshiba_got_int
= 0;
96 client_data
->activate_link(client_data
); /* clears interrupt */
98 if (wait_event_timeout(toshiba_vsync_wait
, panel
->toshiba_got_int
,
100 printk(KERN_ERR
"timeout waiting for VSYNC\n");
101 panel
->toshiba_got_int
= 0;
102 /* interrupt clears when screen dma starts */
105 static int toshiba_suspend(struct msm_panel_data
*panel_data
)
107 struct panel_info
*panel
= container_of(panel_data
, struct panel_info
,
109 struct msm_mddi_client_data
*client_data
= panel
->client_data
;
111 struct msm_mddi_bridge_platform_data
*bridge_data
=
112 client_data
->private_client_data
;
115 ret
= bridge_data
->uninit(bridge_data
, client_data
);
117 printk(KERN_INFO
"mddi toshiba client: non zero return from "
121 client_data
->suspend(client_data
);
125 static int toshiba_resume(struct msm_panel_data
*panel_data
)
127 struct panel_info
*panel
= container_of(panel_data
, struct panel_info
,
129 struct msm_mddi_client_data
*client_data
= panel
->client_data
;
131 struct msm_mddi_bridge_platform_data
*bridge_data
=
132 client_data
->private_client_data
;
135 client_data
->resume(client_data
);
136 ret
= bridge_data
->init(bridge_data
, client_data
);
142 static int toshiba_blank(struct msm_panel_data
*panel_data
)
144 struct panel_info
*panel
= container_of(panel_data
, struct panel_info
,
146 struct msm_mddi_client_data
*client_data
= panel
->client_data
;
147 struct msm_mddi_bridge_platform_data
*bridge_data
=
148 client_data
->private_client_data
;
150 return bridge_data
->blank(bridge_data
, client_data
);
153 static int toshiba_unblank(struct msm_panel_data
*panel_data
)
155 struct panel_info
*panel
= container_of(panel_data
, struct panel_info
,
157 struct msm_mddi_client_data
*client_data
= panel
->client_data
;
158 struct msm_mddi_bridge_platform_data
*bridge_data
=
159 client_data
->private_client_data
;
161 return bridge_data
->unblank(bridge_data
, client_data
);
164 irqreturn_t
toshiba_vsync_interrupt(int irq
, void *data
)
166 struct panel_info
*panel
= data
;
168 panel
->toshiba_got_int
= 1;
169 if (panel
->toshiba_callback
) {
170 panel
->toshiba_callback
->func(panel
->toshiba_callback
);
171 panel
->toshiba_callback
= 0;
173 wake_up(&toshiba_vsync_wait
);
177 static int setup_vsync(struct panel_info
*panel
,
188 ret
= gpio_request(gpio
, "vsync");
190 goto err_request_gpio_failed
;
192 ret
= gpio_direction_input(gpio
);
194 goto err_gpio_direction_input_failed
;
196 ret
= irq
= gpio_to_irq(gpio
);
198 goto err_get_irq_num_failed
;
200 ret
= request_irq(irq
, toshiba_vsync_interrupt
, IRQF_TRIGGER_RISING
,
203 goto err_request_irq_failed
;
204 printk(KERN_INFO
"vsync on gpio %d now %d\n",
205 gpio
, gpio_get_value(gpio
));
209 free_irq(gpio_to_irq(gpio
), panel
);
210 err_request_irq_failed
:
211 err_get_irq_num_failed
:
212 err_gpio_direction_input_failed
:
214 err_request_gpio_failed
:
218 static int mddi_toshiba_probe(struct platform_device
*pdev
)
221 struct msm_mddi_client_data
*client_data
= pdev
->dev
.platform_data
;
222 struct msm_mddi_bridge_platform_data
*bridge_data
=
223 client_data
->private_client_data
;
224 struct panel_info
*panel
=
225 kzalloc(sizeof(struct panel_info
), GFP_KERNEL
);
228 platform_set_drvdata(pdev
, panel
);
230 /* mddi_remote_write(mddi, 0, WAKEUP); */
231 client_data
->remote_write(client_data
, GPIOSEL_VWAKEINT
, GPIOSEL
);
232 client_data
->remote_write(client_data
, INTMASK_VWAKEOUT
, INTMASK
);
234 ret
= setup_vsync(panel
, 1);
236 dev_err(&pdev
->dev
, "mddi_bridge_setup_vsync failed\n");
240 panel
->client_data
= client_data
;
241 panel
->panel_data
.suspend
= toshiba_suspend
;
242 panel
->panel_data
.resume
= toshiba_resume
;
243 panel
->panel_data
.wait_vsync
= toshiba_wait_vsync
;
244 panel
->panel_data
.request_vsync
= toshiba_request_vsync
;
245 panel
->panel_data
.clear_vsync
= toshiba_clear_vsync
;
246 panel
->panel_data
.blank
= toshiba_blank
;
247 panel
->panel_data
.unblank
= toshiba_unblank
;
248 panel
->panel_data
.fb_data
= &bridge_data
->fb_data
;
249 panel
->panel_data
.caps
= MSMFB_CAP_PARTIAL_UPDATES
;
251 panel
->pdev
.name
= "msm_panel";
252 panel
->pdev
.id
= pdev
->id
;
253 panel
->pdev
.resource
= client_data
->fb_resource
;
254 panel
->pdev
.num_resources
= 1;
255 panel
->pdev
.dev
.platform_data
= &panel
->panel_data
;
256 bridge_data
->init(bridge_data
, client_data
);
257 platform_device_register(&panel
->pdev
);
262 static int mddi_toshiba_remove(struct platform_device
*pdev
)
264 struct panel_info
*panel
= platform_get_drvdata(pdev
);
266 setup_vsync(panel
, 0);
271 static struct platform_driver mddi_client_d263_0000
= {
272 .probe
= mddi_toshiba_probe
,
273 .remove
= mddi_toshiba_remove
,
274 .driver
= { .name
= "mddi_c_d263_0000" },
277 static int __init
mddi_client_toshiba_init(void)
279 platform_driver_register(&mddi_client_d263_0000
);
283 module_init(mddi_client_toshiba_init
);