Pavel Machek | d480ace | 2009-09-22 16:47:03 -0700 | [diff] [blame] | 1 | /* 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 Machek | 69fd8d2 | 2009-11-11 14:26:51 -0800 | [diff] [blame] | 23 | #include <linux/sched.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 24 | #include <linux/slab.h> |
Pavel Machek | d480ace | 2009-09-22 16:47:03 -0700 | [diff] [blame] | 25 | #include <mach/msm_fb.h> |
| 26 | |
| 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 | |
| 55 | static DECLARE_WAIT_QUEUE_HEAD(toshiba_vsync_wait); |
| 56 | |
| 57 | struct 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 | |
| 66 | static 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 | |
| 80 | static 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 | |
| 89 | static 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 | |
| 106 | static 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 | |
| 126 | static 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 | |
| 143 | static 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 | |
| 154 | static 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 | |
| 165 | irqreturn_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 | |
| 178 | static 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 | } |
| 189 | ret = gpio_request(gpio, "vsync"); |
| 190 | if (ret) |
| 191 | goto err_request_gpio_failed; |
| 192 | |
| 193 | ret = gpio_direction_input(gpio); |
| 194 | if (ret) |
| 195 | goto err_gpio_direction_input_failed; |
| 196 | |
| 197 | ret = irq = gpio_to_irq(gpio); |
| 198 | if (ret < 0) |
| 199 | goto err_get_irq_num_failed; |
| 200 | |
| 201 | ret = request_irq(irq, toshiba_vsync_interrupt, IRQF_TRIGGER_RISING, |
| 202 | "vsync", panel); |
| 203 | if (ret) |
| 204 | goto err_request_irq_failed; |
| 205 | printk(KERN_INFO "vsync on gpio %d now %d\n", |
| 206 | gpio, gpio_get_value(gpio)); |
| 207 | return 0; |
| 208 | |
| 209 | uninit: |
| 210 | free_irq(gpio_to_irq(gpio), panel); |
| 211 | err_request_irq_failed: |
| 212 | err_get_irq_num_failed: |
| 213 | err_gpio_direction_input_failed: |
| 214 | gpio_free(gpio); |
| 215 | err_request_gpio_failed: |
| 216 | return ret; |
| 217 | } |
| 218 | |
| 219 | static int mddi_toshiba_probe(struct platform_device *pdev) |
| 220 | { |
| 221 | int ret; |
| 222 | struct msm_mddi_client_data *client_data = pdev->dev.platform_data; |
| 223 | struct msm_mddi_bridge_platform_data *bridge_data = |
| 224 | client_data->private_client_data; |
| 225 | struct panel_info *panel = |
| 226 | kzalloc(sizeof(struct panel_info), GFP_KERNEL); |
| 227 | if (!panel) |
| 228 | return -ENOMEM; |
| 229 | platform_set_drvdata(pdev, panel); |
| 230 | |
| 231 | /* mddi_remote_write(mddi, 0, WAKEUP); */ |
| 232 | client_data->remote_write(client_data, GPIOSEL_VWAKEINT, GPIOSEL); |
| 233 | client_data->remote_write(client_data, INTMASK_VWAKEOUT, INTMASK); |
| 234 | |
| 235 | ret = setup_vsync(panel, 1); |
| 236 | if (ret) { |
| 237 | dev_err(&pdev->dev, "mddi_bridge_setup_vsync failed\n"); |
| 238 | return ret; |
| 239 | } |
| 240 | |
| 241 | panel->client_data = client_data; |
| 242 | panel->panel_data.suspend = toshiba_suspend; |
| 243 | panel->panel_data.resume = toshiba_resume; |
| 244 | panel->panel_data.wait_vsync = toshiba_wait_vsync; |
| 245 | panel->panel_data.request_vsync = toshiba_request_vsync; |
| 246 | panel->panel_data.clear_vsync = toshiba_clear_vsync; |
| 247 | panel->panel_data.blank = toshiba_blank; |
| 248 | panel->panel_data.unblank = toshiba_unblank; |
| 249 | panel->panel_data.fb_data = &bridge_data->fb_data; |
| 250 | panel->panel_data.caps = MSMFB_CAP_PARTIAL_UPDATES; |
| 251 | |
| 252 | panel->pdev.name = "msm_panel"; |
| 253 | panel->pdev.id = pdev->id; |
| 254 | panel->pdev.resource = client_data->fb_resource; |
| 255 | panel->pdev.num_resources = 1; |
| 256 | panel->pdev.dev.platform_data = &panel->panel_data; |
| 257 | bridge_data->init(bridge_data, client_data); |
| 258 | platform_device_register(&panel->pdev); |
| 259 | |
| 260 | return 0; |
| 261 | } |
| 262 | |
| 263 | static int mddi_toshiba_remove(struct platform_device *pdev) |
| 264 | { |
| 265 | struct panel_info *panel = platform_get_drvdata(pdev); |
| 266 | |
| 267 | setup_vsync(panel, 0); |
| 268 | kfree(panel); |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | static struct platform_driver mddi_client_d263_0000 = { |
| 273 | .probe = mddi_toshiba_probe, |
| 274 | .remove = mddi_toshiba_remove, |
| 275 | .driver = { .name = "mddi_c_d263_0000" }, |
| 276 | }; |
| 277 | |
| 278 | static int __init mddi_client_toshiba_init(void) |
| 279 | { |
| 280 | platform_driver_register(&mddi_client_d263_0000); |
| 281 | return 0; |
| 282 | } |
| 283 | |
| 284 | module_init(mddi_client_toshiba_init); |
| 285 | |