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 <linux/slab.h>
25 #include <linux/platform_data/video-msm_fb.h>
28 #define LCD_CONTROL_BLOCK_BASE 0x110000
29 #define CMN (LCD_CONTROL_BLOCK_BASE|0x10)
30 #define INTFLG (LCD_CONTROL_BLOCK_BASE|0x18)
31 #define HCYCLE (LCD_CONTROL_BLOCK_BASE|0x34)
32 #define HDE_START (LCD_CONTROL_BLOCK_BASE|0x3C)
33 #define VPOS (LCD_CONTROL_BLOCK_BASE|0xC0)
34 #define MPLFBUF (LCD_CONTROL_BLOCK_BASE|0x20)
35 #define WAKEUP (LCD_CONTROL_BLOCK_BASE|0x54)
36 #define WSYN_DLY (LCD_CONTROL_BLOCK_BASE|0x58)
37 #define REGENB (LCD_CONTROL_BLOCK_BASE|0x5C)
39 #define BASE5 0x150000
40 #define BASE6 0x160000
41 #define BASE7 0x170000
43 #define GPIOIEV (BASE5 + 0x10)
44 #define GPIOIE (BASE5 + 0x14)
45 #define GPIORIS (BASE5 + 0x18)
46 #define GPIOMIS (BASE5 + 0x1C)
47 #define GPIOIC (BASE5 + 0x20)
49 #define INTMASK (BASE6 + 0x0C)
50 #define INTMASK_VWAKEOUT (1U << 0)
51 #define INTMASK_VWAKEOUT_ACTIVE_LOW (1U << 8)
52 #define GPIOSEL (BASE7 + 0x00)
53 #define GPIOSEL_VWAKEINT (1U << 0)
55 static DECLARE_WAIT_QUEUE_HEAD(toshiba_vsync_wait
);
58 struct msm_mddi_client_data
*client_data
;
59 struct platform_device pdev
;
60 struct msm_panel_data panel_data
;
61 struct msmfb_callback
*toshiba_callback
;
66 static void toshiba_request_vsync(struct msm_panel_data
*panel_data
,
67 struct msmfb_callback
*callback
)
69 struct panel_info
*panel
= container_of(panel_data
, struct panel_info
,
71 struct msm_mddi_client_data
*client_data
= panel
->client_data
;
73 panel
->toshiba_callback
= callback
;
74 if (panel
->toshiba_got_int
) {
75 panel
->toshiba_got_int
= 0;
76 client_data
->activate_link(client_data
);
80 static void toshiba_clear_vsync(struct msm_panel_data
*panel_data
)
82 struct panel_info
*panel
= container_of(panel_data
, struct panel_info
,
84 struct msm_mddi_client_data
*client_data
= panel
->client_data
;
86 client_data
->activate_link(client_data
);
89 static void toshiba_wait_vsync(struct msm_panel_data
*panel_data
)
91 struct panel_info
*panel
= container_of(panel_data
, struct panel_info
,
93 struct msm_mddi_client_data
*client_data
= panel
->client_data
;
95 if (panel
->toshiba_got_int
) {
96 panel
->toshiba_got_int
= 0;
97 client_data
->activate_link(client_data
); /* clears interrupt */
99 if (wait_event_timeout(toshiba_vsync_wait
, panel
->toshiba_got_int
,
101 printk(KERN_ERR
"timeout waiting for VSYNC\n");
102 panel
->toshiba_got_int
= 0;
103 /* interrupt clears when screen dma starts */
106 static int toshiba_suspend(struct msm_panel_data
*panel_data
)
108 struct panel_info
*panel
= container_of(panel_data
, struct panel_info
,
110 struct msm_mddi_client_data
*client_data
= panel
->client_data
;
112 struct msm_mddi_bridge_platform_data
*bridge_data
=
113 client_data
->private_client_data
;
116 ret
= bridge_data
->uninit(bridge_data
, client_data
);
118 printk(KERN_INFO
"mddi toshiba client: non zero return from "
122 client_data
->suspend(client_data
);
126 static int toshiba_resume(struct msm_panel_data
*panel_data
)
128 struct panel_info
*panel
= container_of(panel_data
, struct panel_info
,
130 struct msm_mddi_client_data
*client_data
= panel
->client_data
;
132 struct msm_mddi_bridge_platform_data
*bridge_data
=
133 client_data
->private_client_data
;
136 client_data
->resume(client_data
);
137 ret
= bridge_data
->init(bridge_data
, client_data
);
143 static int toshiba_blank(struct msm_panel_data
*panel_data
)
145 struct panel_info
*panel
= container_of(panel_data
, struct panel_info
,
147 struct msm_mddi_client_data
*client_data
= panel
->client_data
;
148 struct msm_mddi_bridge_platform_data
*bridge_data
=
149 client_data
->private_client_data
;
151 return bridge_data
->blank(bridge_data
, client_data
);
154 static int toshiba_unblank(struct msm_panel_data
*panel_data
)
156 struct panel_info
*panel
= container_of(panel_data
, struct panel_info
,
158 struct msm_mddi_client_data
*client_data
= panel
->client_data
;
159 struct msm_mddi_bridge_platform_data
*bridge_data
=
160 client_data
->private_client_data
;
162 return bridge_data
->unblank(bridge_data
, client_data
);
165 irqreturn_t
toshiba_vsync_interrupt(int irq
, void *data
)
167 struct panel_info
*panel
= data
;
169 panel
->toshiba_got_int
= 1;
170 if (panel
->toshiba_callback
) {
171 panel
->toshiba_callback
->func(panel
->toshiba_callback
);
172 panel
->toshiba_callback
= 0;
174 wake_up(&toshiba_vsync_wait
);
178 static int setup_vsync(struct panel_info
*panel
,
189 ret
= gpio_request_one(gpio
, GPIOF_IN
, "vsync");
191 goto err_request_gpio_failed
;
193 ret
= irq
= gpio_to_irq(gpio
);
195 goto err_get_irq_num_failed
;
197 ret
= request_irq(irq
, toshiba_vsync_interrupt
, IRQF_TRIGGER_RISING
,
200 goto err_request_irq_failed
;
201 printk(KERN_INFO
"vsync on gpio %d now %d\n",
202 gpio
, gpio_get_value(gpio
));
206 free_irq(gpio_to_irq(gpio
), panel
);
207 err_request_irq_failed
:
208 err_get_irq_num_failed
:
210 err_request_gpio_failed
:
214 static int mddi_toshiba_probe(struct platform_device
*pdev
)
217 struct msm_mddi_client_data
*client_data
= pdev
->dev
.platform_data
;
218 struct msm_mddi_bridge_platform_data
*bridge_data
=
219 client_data
->private_client_data
;
220 struct panel_info
*panel
=
221 kzalloc(sizeof(struct panel_info
), GFP_KERNEL
);
224 platform_set_drvdata(pdev
, panel
);
226 /* mddi_remote_write(mddi, 0, WAKEUP); */
227 client_data
->remote_write(client_data
, GPIOSEL_VWAKEINT
, GPIOSEL
);
228 client_data
->remote_write(client_data
, INTMASK_VWAKEOUT
, INTMASK
);
230 ret
= setup_vsync(panel
, 1);
232 dev_err(&pdev
->dev
, "mddi_bridge_setup_vsync failed\n");
236 panel
->client_data
= client_data
;
237 panel
->panel_data
.suspend
= toshiba_suspend
;
238 panel
->panel_data
.resume
= toshiba_resume
;
239 panel
->panel_data
.wait_vsync
= toshiba_wait_vsync
;
240 panel
->panel_data
.request_vsync
= toshiba_request_vsync
;
241 panel
->panel_data
.clear_vsync
= toshiba_clear_vsync
;
242 panel
->panel_data
.blank
= toshiba_blank
;
243 panel
->panel_data
.unblank
= toshiba_unblank
;
244 panel
->panel_data
.fb_data
= &bridge_data
->fb_data
;
245 panel
->panel_data
.caps
= MSMFB_CAP_PARTIAL_UPDATES
;
247 panel
->pdev
.name
= "msm_panel";
248 panel
->pdev
.id
= pdev
->id
;
249 panel
->pdev
.resource
= client_data
->fb_resource
;
250 panel
->pdev
.num_resources
= 1;
251 panel
->pdev
.dev
.platform_data
= &panel
->panel_data
;
252 bridge_data
->init(bridge_data
, client_data
);
253 platform_device_register(&panel
->pdev
);
258 static int mddi_toshiba_remove(struct platform_device
*pdev
)
260 struct panel_info
*panel
= platform_get_drvdata(pdev
);
262 setup_vsync(panel
, 0);
267 static struct platform_driver mddi_client_d263_0000
= {
268 .probe
= mddi_toshiba_probe
,
269 .remove
= mddi_toshiba_remove
,
270 .driver
= { .name
= "mddi_c_d263_0000" },
273 static int __init
mddi_client_toshiba_init(void)
275 platform_driver_register(&mddi_client_d263_0000
);
279 module_init(mddi_client_toshiba_init
);