blob: 061d7dfebbf3006a6eb56ba3d652f4b64e5f0c60 [file] [log] [blame]
Pavel Machekd480ace2009-09-22 16:47:03 -07001/* drivers/video/msm_fb/mddi_client_toshiba.c
2 *
3 * Support for Toshiba TC358720XBG mddi client devices which require no
4 * special initialization code.
5 *
6 * Copyright (C) 2007 Google Incorporated
7 *
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.
11 *
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.
16 */
17
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>
Pavel Machek69fd8d22009-11-11 14:26:51 -080023#include <linux/sched.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
Arnd Bergmann1ef21f62012-08-24 15:14:41 +020025#include <linux/platform_data/video-msm_fb.h>
Pavel Machekd480ace2009-09-22 16:47:03 -070026
27
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)
38
39#define BASE5 0x150000
40#define BASE6 0x160000
41#define BASE7 0x170000
42
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)
48
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)
54
55static DECLARE_WAIT_QUEUE_HEAD(toshiba_vsync_wait);
56
57struct panel_info {
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;
62 int toshiba_got_int;
63};
64
65
66static void toshiba_request_vsync(struct msm_panel_data *panel_data,
67 struct msmfb_callback *callback)
68{
69 struct panel_info *panel = container_of(panel_data, struct panel_info,
70 panel_data);
71 struct msm_mddi_client_data *client_data = panel->client_data;
72
73 panel->toshiba_callback = callback;
74 if (panel->toshiba_got_int) {
75 panel->toshiba_got_int = 0;
76 client_data->activate_link(client_data);
77 }
78}
79
80static void toshiba_clear_vsync(struct msm_panel_data *panel_data)
81{
82 struct panel_info *panel = container_of(panel_data, struct panel_info,
83 panel_data);
84 struct msm_mddi_client_data *client_data = panel->client_data;
85
86 client_data->activate_link(client_data);
87}
88
89static void toshiba_wait_vsync(struct msm_panel_data *panel_data)
90{
91 struct panel_info *panel = container_of(panel_data, struct panel_info,
92 panel_data);
93 struct msm_mddi_client_data *client_data = panel->client_data;
94
95 if (panel->toshiba_got_int) {
96 panel->toshiba_got_int = 0;
97 client_data->activate_link(client_data); /* clears interrupt */
98 }
99 if (wait_event_timeout(toshiba_vsync_wait, panel->toshiba_got_int,
100 HZ/2) == 0)
101 printk(KERN_ERR "timeout waiting for VSYNC\n");
102 panel->toshiba_got_int = 0;
103 /* interrupt clears when screen dma starts */
104}
105
106static int toshiba_suspend(struct msm_panel_data *panel_data)
107{
108 struct panel_info *panel = container_of(panel_data, struct panel_info,
109 panel_data);
110 struct msm_mddi_client_data *client_data = panel->client_data;
111
112 struct msm_mddi_bridge_platform_data *bridge_data =
113 client_data->private_client_data;
114 int ret;
115
116 ret = bridge_data->uninit(bridge_data, client_data);
117 if (ret) {
118 printk(KERN_INFO "mddi toshiba client: non zero return from "
119 "uninit\n");
120 return ret;
121 }
122 client_data->suspend(client_data);
123 return 0;
124}
125
126static int toshiba_resume(struct msm_panel_data *panel_data)
127{
128 struct panel_info *panel = container_of(panel_data, struct panel_info,
129 panel_data);
130 struct msm_mddi_client_data *client_data = panel->client_data;
131
132 struct msm_mddi_bridge_platform_data *bridge_data =
133 client_data->private_client_data;
134 int ret;
135
136 client_data->resume(client_data);
137 ret = bridge_data->init(bridge_data, client_data);
138 if (ret)
139 return ret;
140 return 0;
141}
142
143static int toshiba_blank(struct msm_panel_data *panel_data)
144{
145 struct panel_info *panel = container_of(panel_data, struct panel_info,
146 panel_data);
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;
150
151 return bridge_data->blank(bridge_data, client_data);
152}
153
154static int toshiba_unblank(struct msm_panel_data *panel_data)
155{
156 struct panel_info *panel = container_of(panel_data, struct panel_info,
157 panel_data);
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;
161
162 return bridge_data->unblank(bridge_data, client_data);
163}
164
165irqreturn_t toshiba_vsync_interrupt(int irq, void *data)
166{
167 struct panel_info *panel = data;
168
169 panel->toshiba_got_int = 1;
170 if (panel->toshiba_callback) {
171 panel->toshiba_callback->func(panel->toshiba_callback);
172 panel->toshiba_callback = 0;
173 }
174 wake_up(&toshiba_vsync_wait);
175 return IRQ_HANDLED;
176}
177
178static int setup_vsync(struct panel_info *panel,
179 int init)
180{
181 int ret;
182 int gpio = 97;
183 unsigned int irq;
184
185 if (!init) {
186 ret = 0;
187 goto uninit;
188 }
Jingoo Hanf8bd4932012-01-26 19:32:34 +0900189 ret = gpio_request_one(gpio, GPIOF_IN, "vsync");
Pavel Machekd480ace2009-09-22 16:47:03 -0700190 if (ret)
191 goto err_request_gpio_failed;
192
Pavel Machekd480ace2009-09-22 16:47:03 -0700193 ret = irq = gpio_to_irq(gpio);
194 if (ret < 0)
195 goto err_get_irq_num_failed;
196
197 ret = request_irq(irq, toshiba_vsync_interrupt, IRQF_TRIGGER_RISING,
198 "vsync", panel);
199 if (ret)
200 goto err_request_irq_failed;
201 printk(KERN_INFO "vsync on gpio %d now %d\n",
202 gpio, gpio_get_value(gpio));
203 return 0;
204
205uninit:
206 free_irq(gpio_to_irq(gpio), panel);
207err_request_irq_failed:
208err_get_irq_num_failed:
Pavel Machekd480ace2009-09-22 16:47:03 -0700209 gpio_free(gpio);
210err_request_gpio_failed:
211 return ret;
212}
213
214static int mddi_toshiba_probe(struct platform_device *pdev)
215{
216 int ret;
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);
222 if (!panel)
223 return -ENOMEM;
224 platform_set_drvdata(pdev, panel);
225
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);
229
230 ret = setup_vsync(panel, 1);
231 if (ret) {
232 dev_err(&pdev->dev, "mddi_bridge_setup_vsync failed\n");
233 return ret;
234 }
235
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;
246
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);
254
255 return 0;
256}
257
258static int mddi_toshiba_remove(struct platform_device *pdev)
259{
260 struct panel_info *panel = platform_get_drvdata(pdev);
261
262 setup_vsync(panel, 0);
263 kfree(panel);
264 return 0;
265}
266
267static struct platform_driver mddi_client_d263_0000 = {
268 .probe = mddi_toshiba_probe,
269 .remove = mddi_toshiba_remove,
270 .driver = { .name = "mddi_c_d263_0000" },
271};
272
273static int __init mddi_client_toshiba_init(void)
274{
275 platform_driver_register(&mddi_client_d263_0000);
276 return 0;
277}
278
279module_init(mddi_client_toshiba_init);
280