Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[ARM] 5184/1: Split ucb1400_ts into core and touchscreen

This patch splits ucb1400_ts into ucb1400_ts and ucb1400_core.
Since this chip supports more features than only touchscreen,
it was necessary to prepare it for feature addition. The
previous functionality is preserved by applying this patch.

[Build fixes for non-ARM by Stephen Rothwell and Takashi Iwai]

Signed-off-by: Marek Vasut <marek.vasut@gmail.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>

authored by

Marek Vašut and committed by
Russell King
d9105c2b 6d341675

+473 -309
+1
drivers/input/touchscreen/Kconfig
··· 220 220 config TOUCHSCREEN_UCB1400 221 221 tristate "Philips UCB1400 touchscreen" 222 222 select AC97_BUS 223 + depends on UCB1400_CORE 223 224 help 224 225 This enables support for the Philips UCB1400 touchscreen interface. 225 226 The UCB1400 is an AC97 audio codec. The touchscreen interface
+195 -309
drivers/input/touchscreen/ucb1400_ts.c
··· 5 5 * Created: September 25, 2006 6 6 * Copyright: MontaVista Software, Inc. 7 7 * 8 + * Spliting done by: Marek Vasut <marek.vasut@gmail.com> 9 + * If something doesnt work and it worked before spliting, e-mail me, 10 + * dont bother Nicolas please ;-) 11 + * 8 12 * This program is free software; you can redistribute it and/or modify 9 13 * it under the terms of the GNU General Public License version 2 as 10 14 * published by the Free Software Foundation. ··· 29 25 #include <linux/slab.h> 30 26 #include <linux/kthread.h> 31 27 #include <linux/freezer.h> 32 - 33 - #include <sound/core.h> 34 - #include <sound/ac97_codec.h> 35 - 36 - 37 - /* 38 - * Interesting UCB1400 AC-link registers 39 - */ 40 - 41 - #define UCB_IE_RIS 0x5e 42 - #define UCB_IE_FAL 0x60 43 - #define UCB_IE_STATUS 0x62 44 - #define UCB_IE_CLEAR 0x62 45 - #define UCB_IE_ADC (1 << 11) 46 - #define UCB_IE_TSPX (1 << 12) 47 - 48 - #define UCB_TS_CR 0x64 49 - #define UCB_TS_CR_TSMX_POW (1 << 0) 50 - #define UCB_TS_CR_TSPX_POW (1 << 1) 51 - #define UCB_TS_CR_TSMY_POW (1 << 2) 52 - #define UCB_TS_CR_TSPY_POW (1 << 3) 53 - #define UCB_TS_CR_TSMX_GND (1 << 4) 54 - #define UCB_TS_CR_TSPX_GND (1 << 5) 55 - #define UCB_TS_CR_TSMY_GND (1 << 6) 56 - #define UCB_TS_CR_TSPY_GND (1 << 7) 57 - #define UCB_TS_CR_MODE_INT (0 << 8) 58 - #define UCB_TS_CR_MODE_PRES (1 << 8) 59 - #define UCB_TS_CR_MODE_POS (2 << 8) 60 - #define UCB_TS_CR_BIAS_ENA (1 << 11) 61 - #define UCB_TS_CR_TSPX_LOW (1 << 12) 62 - #define UCB_TS_CR_TSMX_LOW (1 << 13) 63 - 64 - #define UCB_ADC_CR 0x66 65 - #define UCB_ADC_SYNC_ENA (1 << 0) 66 - #define UCB_ADC_VREFBYP_CON (1 << 1) 67 - #define UCB_ADC_INP_TSPX (0 << 2) 68 - #define UCB_ADC_INP_TSMX (1 << 2) 69 - #define UCB_ADC_INP_TSPY (2 << 2) 70 - #define UCB_ADC_INP_TSMY (3 << 2) 71 - #define UCB_ADC_INP_AD0 (4 << 2) 72 - #define UCB_ADC_INP_AD1 (5 << 2) 73 - #define UCB_ADC_INP_AD2 (6 << 2) 74 - #define UCB_ADC_INP_AD3 (7 << 2) 75 - #define UCB_ADC_EXT_REF (1 << 5) 76 - #define UCB_ADC_START (1 << 7) 77 - #define UCB_ADC_ENA (1 << 15) 78 - 79 - #define UCB_ADC_DATA 0x68 80 - #define UCB_ADC_DAT_VALID (1 << 15) 81 - #define UCB_ADC_DAT_VALUE(x) ((x) & 0x3ff) 82 - 83 - #define UCB_ID 0x7e 84 - #define UCB_ID_1400 0x4304 85 - 86 - 87 - struct ucb1400 { 88 - struct snd_ac97 *ac97; 89 - struct input_dev *ts_idev; 90 - 91 - int irq; 92 - 93 - wait_queue_head_t ts_wait; 94 - struct task_struct *ts_task; 95 - 96 - unsigned int irq_pending; /* not bit field shared */ 97 - unsigned int ts_restart:1; 98 - unsigned int adcsync:1; 99 - }; 28 + #include <linux/ucb1400.h> 100 29 101 30 static int adcsync; 102 31 static int ts_delay = 55; /* us */ 103 32 static int ts_delay_pressure; /* us */ 104 33 105 - static inline u16 ucb1400_reg_read(struct ucb1400 *ucb, u16 reg) 106 - { 107 - return ucb->ac97->bus->ops->read(ucb->ac97, reg); 108 - } 109 - 110 - static inline void ucb1400_reg_write(struct ucb1400 *ucb, u16 reg, u16 val) 111 - { 112 - ucb->ac97->bus->ops->write(ucb->ac97, reg, val); 113 - } 114 - 115 - static inline void ucb1400_adc_enable(struct ucb1400 *ucb) 116 - { 117 - ucb1400_reg_write(ucb, UCB_ADC_CR, UCB_ADC_ENA); 118 - } 119 - 120 - static unsigned int ucb1400_adc_read(struct ucb1400 *ucb, u16 adc_channel) 121 - { 122 - unsigned int val; 123 - 124 - if (ucb->adcsync) 125 - adc_channel |= UCB_ADC_SYNC_ENA; 126 - 127 - ucb1400_reg_write(ucb, UCB_ADC_CR, UCB_ADC_ENA | adc_channel); 128 - ucb1400_reg_write(ucb, UCB_ADC_CR, UCB_ADC_ENA | adc_channel | UCB_ADC_START); 129 - 130 - for (;;) { 131 - val = ucb1400_reg_read(ucb, UCB_ADC_DATA); 132 - if (val & UCB_ADC_DAT_VALID) 133 - break; 134 - /* yield to other processes */ 135 - schedule_timeout_uninterruptible(1); 136 - } 137 - 138 - return UCB_ADC_DAT_VALUE(val); 139 - } 140 - 141 - static inline void ucb1400_adc_disable(struct ucb1400 *ucb) 142 - { 143 - ucb1400_reg_write(ucb, UCB_ADC_CR, 0); 144 - } 145 - 146 34 /* Switch to interrupt mode. */ 147 - static inline void ucb1400_ts_mode_int(struct ucb1400 *ucb) 35 + static inline void ucb1400_ts_mode_int(struct snd_ac97 *ac97) 148 36 { 149 - ucb1400_reg_write(ucb, UCB_TS_CR, 37 + ucb1400_reg_write(ac97, UCB_TS_CR, 150 38 UCB_TS_CR_TSMX_POW | UCB_TS_CR_TSPX_POW | 151 39 UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_GND | 152 40 UCB_TS_CR_MODE_INT); ··· 48 152 * Switch to pressure mode, and read pressure. We don't need to wait 49 153 * here, since both plates are being driven. 50 154 */ 51 - static inline unsigned int ucb1400_ts_read_pressure(struct ucb1400 *ucb) 155 + static inline unsigned int ucb1400_ts_read_pressure(struct ucb1400_ts *ucb) 52 156 { 53 - ucb1400_reg_write(ucb, UCB_TS_CR, 157 + ucb1400_reg_write(ucb->ac97, UCB_TS_CR, 54 158 UCB_TS_CR_TSMX_POW | UCB_TS_CR_TSPX_POW | 55 159 UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_GND | 56 160 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA); 57 161 udelay(ts_delay_pressure); 58 - return ucb1400_adc_read(ucb, UCB_ADC_INP_TSPY); 162 + return ucb1400_adc_read(ucb->ac97, UCB_ADC_INP_TSPY, adcsync); 59 163 } 60 164 61 165 /* ··· 64 168 * gives a faster response time. Even so, we need to wait about 55us 65 169 * for things to stabilise. 66 170 */ 67 - static inline unsigned int ucb1400_ts_read_xpos(struct ucb1400 *ucb) 171 + static inline unsigned int ucb1400_ts_read_xpos(struct ucb1400_ts *ucb) 68 172 { 69 - ucb1400_reg_write(ucb, UCB_TS_CR, 173 + ucb1400_reg_write(ucb->ac97, UCB_TS_CR, 70 174 UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW | 71 175 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA); 72 - ucb1400_reg_write(ucb, UCB_TS_CR, 176 + ucb1400_reg_write(ucb->ac97, UCB_TS_CR, 73 177 UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW | 74 178 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA); 75 - ucb1400_reg_write(ucb, UCB_TS_CR, 179 + ucb1400_reg_write(ucb->ac97, UCB_TS_CR, 76 180 UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW | 77 181 UCB_TS_CR_MODE_POS | UCB_TS_CR_BIAS_ENA); 78 182 79 183 udelay(ts_delay); 80 184 81 - return ucb1400_adc_read(ucb, UCB_ADC_INP_TSPY); 185 + return ucb1400_adc_read(ucb->ac97, UCB_ADC_INP_TSPY, adcsync); 82 186 } 83 187 84 188 /* ··· 87 191 * gives a faster response time. Even so, we need to wait about 55us 88 192 * for things to stabilise. 89 193 */ 90 - static inline unsigned int ucb1400_ts_read_ypos(struct ucb1400 *ucb) 194 + static inline unsigned int ucb1400_ts_read_ypos(struct ucb1400_ts *ucb) 91 195 { 92 - ucb1400_reg_write(ucb, UCB_TS_CR, 196 + ucb1400_reg_write(ucb->ac97, UCB_TS_CR, 93 197 UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_POW | 94 198 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA); 95 - ucb1400_reg_write(ucb, UCB_TS_CR, 199 + ucb1400_reg_write(ucb->ac97, UCB_TS_CR, 96 200 UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_POW | 97 201 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA); 98 - ucb1400_reg_write(ucb, UCB_TS_CR, 202 + ucb1400_reg_write(ucb->ac97, UCB_TS_CR, 99 203 UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_POW | 100 204 UCB_TS_CR_MODE_POS | UCB_TS_CR_BIAS_ENA); 101 205 102 206 udelay(ts_delay); 103 207 104 - return ucb1400_adc_read(ucb, UCB_ADC_INP_TSPX); 208 + return ucb1400_adc_read(ucb->ac97, UCB_ADC_INP_TSPX, adcsync); 105 209 } 106 210 107 211 /* 108 212 * Switch to X plate resistance mode. Set MX to ground, PX to 109 213 * supply. Measure current. 110 214 */ 111 - static inline unsigned int ucb1400_ts_read_xres(struct ucb1400 *ucb) 215 + static inline unsigned int ucb1400_ts_read_xres(struct ucb1400_ts *ucb) 112 216 { 113 - ucb1400_reg_write(ucb, UCB_TS_CR, 217 + ucb1400_reg_write(ucb->ac97, UCB_TS_CR, 114 218 UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW | 115 219 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA); 116 - return ucb1400_adc_read(ucb, 0); 220 + return ucb1400_adc_read(ucb->ac97, 0, adcsync); 117 221 } 118 222 119 223 /* 120 224 * Switch to Y plate resistance mode. Set MY to ground, PY to 121 225 * supply. Measure current. 122 226 */ 123 - static inline unsigned int ucb1400_ts_read_yres(struct ucb1400 *ucb) 227 + static inline unsigned int ucb1400_ts_read_yres(struct ucb1400_ts *ucb) 124 228 { 125 - ucb1400_reg_write(ucb, UCB_TS_CR, 229 + ucb1400_reg_write(ucb->ac97, UCB_TS_CR, 126 230 UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_POW | 127 231 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA); 128 - return ucb1400_adc_read(ucb, 0); 232 + return ucb1400_adc_read(ucb->ac97, 0, adcsync); 129 233 } 130 234 131 - static inline int ucb1400_ts_pen_down(struct ucb1400 *ucb) 235 + static inline int ucb1400_ts_pen_down(struct snd_ac97 *ac97) 132 236 { 133 - unsigned short val = ucb1400_reg_read(ucb, UCB_TS_CR); 134 - return (val & (UCB_TS_CR_TSPX_LOW | UCB_TS_CR_TSMX_LOW)); 237 + unsigned short val = ucb1400_reg_read(ac97, UCB_TS_CR); 238 + return val & (UCB_TS_CR_TSPX_LOW | UCB_TS_CR_TSMX_LOW); 135 239 } 136 240 137 - static inline void ucb1400_ts_irq_enable(struct ucb1400 *ucb) 241 + static inline void ucb1400_ts_irq_enable(struct snd_ac97 *ac97) 138 242 { 139 - ucb1400_reg_write(ucb, UCB_IE_CLEAR, UCB_IE_TSPX); 140 - ucb1400_reg_write(ucb, UCB_IE_CLEAR, 0); 141 - ucb1400_reg_write(ucb, UCB_IE_FAL, UCB_IE_TSPX); 243 + ucb1400_reg_write(ac97, UCB_IE_CLEAR, UCB_IE_TSPX); 244 + ucb1400_reg_write(ac97, UCB_IE_CLEAR, 0); 245 + ucb1400_reg_write(ac97, UCB_IE_FAL, UCB_IE_TSPX); 142 246 } 143 247 144 - static inline void ucb1400_ts_irq_disable(struct ucb1400 *ucb) 248 + static inline void ucb1400_ts_irq_disable(struct snd_ac97 *ac97) 145 249 { 146 - ucb1400_reg_write(ucb, UCB_IE_FAL, 0); 250 + ucb1400_reg_write(ac97, UCB_IE_FAL, 0); 147 251 } 148 252 149 253 static void ucb1400_ts_evt_add(struct input_dev *idev, u16 pressure, u16 x, u16 y) ··· 160 264 input_sync(idev); 161 265 } 162 266 163 - static void ucb1400_handle_pending_irq(struct ucb1400 *ucb) 267 + static void ucb1400_handle_pending_irq(struct ucb1400_ts *ucb) 164 268 { 165 269 unsigned int isr; 166 270 167 - isr = ucb1400_reg_read(ucb, UCB_IE_STATUS); 168 - ucb1400_reg_write(ucb, UCB_IE_CLEAR, isr); 169 - ucb1400_reg_write(ucb, UCB_IE_CLEAR, 0); 271 + isr = ucb1400_reg_read(ucb->ac97, UCB_IE_STATUS); 272 + ucb1400_reg_write(ucb->ac97, UCB_IE_CLEAR, isr); 273 + ucb1400_reg_write(ucb->ac97, UCB_IE_CLEAR, 0); 170 274 171 - if (isr & UCB_IE_TSPX) 172 - ucb1400_ts_irq_disable(ucb); 173 - else 275 + if (isr & UCB_IE_TSPX) { 276 + ucb1400_ts_irq_disable(ucb->ac97); 277 + enable_irq(ucb->irq); 278 + } else 174 279 printk(KERN_ERR "ucb1400: unexpected IE_STATUS = %#x\n", isr); 175 - 176 - enable_irq(ucb->irq); 177 280 } 178 281 179 282 static int ucb1400_ts_thread(void *_ucb) 180 283 { 181 - struct ucb1400 *ucb = _ucb; 284 + struct ucb1400_ts *ucb = _ucb; 182 285 struct task_struct *tsk = current; 183 286 int valid = 0; 184 287 struct sched_param param = { .sched_priority = 1 }; ··· 196 301 ucb1400_handle_pending_irq(ucb); 197 302 } 198 303 199 - ucb1400_adc_enable(ucb); 304 + ucb1400_adc_enable(ucb->ac97); 200 305 x = ucb1400_ts_read_xpos(ucb); 201 306 y = ucb1400_ts_read_ypos(ucb); 202 307 p = ucb1400_ts_read_pressure(ucb); 203 - ucb1400_adc_disable(ucb); 308 + ucb1400_adc_disable(ucb->ac97); 204 309 205 310 /* Switch back to interrupt mode. */ 206 - ucb1400_ts_mode_int(ucb); 311 + ucb1400_ts_mode_int(ucb->ac97); 207 312 208 313 msleep(10); 209 314 210 - if (ucb1400_ts_pen_down(ucb)) { 211 - ucb1400_ts_irq_enable(ucb); 315 + if (ucb1400_ts_pen_down(ucb->ac97)) { 316 + ucb1400_ts_irq_enable(ucb->ac97); 212 317 213 318 /* 214 319 * If we spat out a valid sample set last time, ··· 227 332 } 228 333 229 334 wait_event_freezable_timeout(ucb->ts_wait, 230 - ucb->irq_pending || ucb->ts_restart || kthread_should_stop(), 231 - timeout); 335 + ucb->irq_pending || ucb->ts_restart || 336 + kthread_should_stop(), timeout); 232 337 } 233 338 234 339 /* Send the "pen off" if we are stopping with the pen still active */ ··· 251 356 */ 252 357 static irqreturn_t ucb1400_hard_irq(int irqnr, void *devid) 253 358 { 254 - struct ucb1400 *ucb = devid; 359 + struct ucb1400_ts *ucb = devid; 255 360 256 361 if (irqnr == ucb->irq) { 257 362 disable_irq(ucb->irq); ··· 264 369 265 370 static int ucb1400_ts_open(struct input_dev *idev) 266 371 { 267 - struct ucb1400 *ucb = input_get_drvdata(idev); 372 + struct ucb1400_ts *ucb = input_get_drvdata(idev); 268 373 int ret = 0; 269 374 270 375 BUG_ON(ucb->ts_task); ··· 280 385 281 386 static void ucb1400_ts_close(struct input_dev *idev) 282 387 { 283 - struct ucb1400 *ucb = input_get_drvdata(idev); 388 + struct ucb1400_ts *ucb = input_get_drvdata(idev); 284 389 285 390 if (ucb->ts_task) 286 391 kthread_stop(ucb->ts_task); 287 392 288 - ucb1400_ts_irq_disable(ucb); 289 - ucb1400_reg_write(ucb, UCB_TS_CR, 0); 393 + ucb1400_ts_irq_disable(ucb->ac97); 394 + ucb1400_reg_write(ucb->ac97, UCB_TS_CR, 0); 395 + } 396 + 397 + #ifndef NO_IRQ 398 + #define NO_IRQ 0 399 + #endif 400 + 401 + /* 402 + * Try to probe our interrupt, rather than relying on lots of 403 + * hard-coded machine dependencies. 404 + */ 405 + static int ucb1400_ts_detect_irq(struct ucb1400_ts *ucb) 406 + { 407 + unsigned long mask, timeout; 408 + 409 + mask = probe_irq_on(); 410 + 411 + /* Enable the ADC interrupt. */ 412 + ucb1400_reg_write(ucb->ac97, UCB_IE_RIS, UCB_IE_ADC); 413 + ucb1400_reg_write(ucb->ac97, UCB_IE_FAL, UCB_IE_ADC); 414 + ucb1400_reg_write(ucb->ac97, UCB_IE_CLEAR, 0xffff); 415 + ucb1400_reg_write(ucb->ac97, UCB_IE_CLEAR, 0); 416 + 417 + /* Cause an ADC interrupt. */ 418 + ucb1400_reg_write(ucb->ac97, UCB_ADC_CR, UCB_ADC_ENA); 419 + ucb1400_reg_write(ucb->ac97, UCB_ADC_CR, UCB_ADC_ENA | UCB_ADC_START); 420 + 421 + /* Wait for the conversion to complete. */ 422 + timeout = jiffies + HZ/2; 423 + while (!(ucb1400_reg_read(ucb->ac97, UCB_ADC_DATA) & 424 + UCB_ADC_DAT_VALID)) { 425 + cpu_relax(); 426 + if (time_after(jiffies, timeout)) { 427 + printk(KERN_ERR "ucb1400: timed out in IRQ probe\n"); 428 + probe_irq_off(mask); 429 + return -ENODEV; 430 + } 431 + } 432 + ucb1400_reg_write(ucb->ac97, UCB_ADC_CR, 0); 433 + 434 + /* Disable and clear interrupt. */ 435 + ucb1400_reg_write(ucb->ac97, UCB_IE_RIS, 0); 436 + ucb1400_reg_write(ucb->ac97, UCB_IE_FAL, 0); 437 + ucb1400_reg_write(ucb->ac97, UCB_IE_CLEAR, 0xffff); 438 + ucb1400_reg_write(ucb->ac97, UCB_IE_CLEAR, 0); 439 + 440 + /* Read triggered interrupt. */ 441 + ucb->irq = probe_irq_off(mask); 442 + if (ucb->irq < 0 || ucb->irq == NO_IRQ) 443 + return -ENODEV; 444 + 445 + return 0; 446 + } 447 + 448 + static int ucb1400_ts_probe(struct platform_device *dev) 449 + { 450 + int error, x_res, y_res; 451 + struct ucb1400_ts *ucb = dev->dev.platform_data; 452 + 453 + ucb->ts_idev = input_allocate_device(); 454 + if (!ucb->ts_idev) { 455 + error = -ENOMEM; 456 + goto err; 457 + } 458 + 459 + error = ucb1400_ts_detect_irq(ucb); 460 + if (error) { 461 + printk(KERN_ERR "UCB1400: IRQ probe failed\n"); 462 + goto err_free_devs; 463 + } 464 + 465 + init_waitqueue_head(&ucb->ts_wait); 466 + 467 + error = request_irq(ucb->irq, ucb1400_hard_irq, IRQF_TRIGGER_RISING, 468 + "UCB1400", ucb); 469 + if (error) { 470 + printk(KERN_ERR "ucb1400: unable to grab irq%d: %d\n", 471 + ucb->irq, error); 472 + goto err_free_devs; 473 + } 474 + printk(KERN_DEBUG "UCB1400: found IRQ %d\n", ucb->irq); 475 + 476 + input_set_drvdata(ucb->ts_idev, ucb); 477 + 478 + ucb->ts_idev->dev.parent = &dev->dev; 479 + ucb->ts_idev->name = "UCB1400 touchscreen interface"; 480 + ucb->ts_idev->id.vendor = ucb1400_reg_read(ucb->ac97, 481 + AC97_VENDOR_ID1); 482 + ucb->ts_idev->id.product = ucb->id; 483 + ucb->ts_idev->open = ucb1400_ts_open; 484 + ucb->ts_idev->close = ucb1400_ts_close; 485 + ucb->ts_idev->evbit[0] = BIT_MASK(EV_ABS); 486 + 487 + ucb1400_adc_enable(ucb->ac97); 488 + x_res = ucb1400_ts_read_xres(ucb); 489 + y_res = ucb1400_ts_read_yres(ucb); 490 + ucb1400_adc_disable(ucb->ac97); 491 + printk(KERN_DEBUG "UCB1400: x/y = %d/%d\n", x_res, y_res); 492 + 493 + input_set_abs_params(ucb->ts_idev, ABS_X, 0, x_res, 0, 0); 494 + input_set_abs_params(ucb->ts_idev, ABS_Y, 0, y_res, 0, 0); 495 + input_set_abs_params(ucb->ts_idev, ABS_PRESSURE, 0, 0, 0, 0); 496 + 497 + error = input_register_device(ucb->ts_idev); 498 + if (error) 499 + goto err_free_irq; 500 + 501 + return 0; 502 + 503 + err_free_irq: 504 + free_irq(ucb->irq, ucb); 505 + err_free_devs: 506 + input_free_device(ucb->ts_idev); 507 + err: 508 + return error; 509 + 510 + } 511 + 512 + static int ucb1400_ts_remove(struct platform_device *dev) 513 + { 514 + struct ucb1400_ts *ucb = dev->dev.platform_data; 515 + 516 + free_irq(ucb->irq, ucb); 517 + input_unregister_device(ucb->ts_idev); 518 + return 0; 290 519 } 291 520 292 521 #ifdef CONFIG_PM 293 - static int ucb1400_ts_resume(struct device *dev) 522 + static int ucb1400_ts_resume(struct platform_device *dev) 294 523 { 295 - struct ucb1400 *ucb = dev_get_drvdata(dev); 524 + struct ucb1400_ts *ucb = platform_get_drvdata(dev); 296 525 297 526 if (ucb->ts_task) { 298 527 /* ··· 433 414 #define ucb1400_ts_resume NULL 434 415 #endif 435 416 436 - #ifndef NO_IRQ 437 - #define NO_IRQ 0 438 - #endif 439 - 440 - /* 441 - * Try to probe our interrupt, rather than relying on lots of 442 - * hard-coded machine dependencies. 443 - */ 444 - static int ucb1400_detect_irq(struct ucb1400 *ucb) 445 - { 446 - unsigned long mask, timeout; 447 - 448 - mask = probe_irq_on(); 449 - 450 - /* Enable the ADC interrupt. */ 451 - ucb1400_reg_write(ucb, UCB_IE_RIS, UCB_IE_ADC); 452 - ucb1400_reg_write(ucb, UCB_IE_FAL, UCB_IE_ADC); 453 - ucb1400_reg_write(ucb, UCB_IE_CLEAR, 0xffff); 454 - ucb1400_reg_write(ucb, UCB_IE_CLEAR, 0); 455 - 456 - /* Cause an ADC interrupt. */ 457 - ucb1400_reg_write(ucb, UCB_ADC_CR, UCB_ADC_ENA); 458 - ucb1400_reg_write(ucb, UCB_ADC_CR, UCB_ADC_ENA | UCB_ADC_START); 459 - 460 - /* Wait for the conversion to complete. */ 461 - timeout = jiffies + HZ/2; 462 - while (!(ucb1400_reg_read(ucb, UCB_ADC_DATA) & UCB_ADC_DAT_VALID)) { 463 - cpu_relax(); 464 - if (time_after(jiffies, timeout)) { 465 - printk(KERN_ERR "ucb1400: timed out in IRQ probe\n"); 466 - probe_irq_off(mask); 467 - return -ENODEV; 468 - } 469 - } 470 - ucb1400_reg_write(ucb, UCB_ADC_CR, 0); 471 - 472 - /* Disable and clear interrupt. */ 473 - ucb1400_reg_write(ucb, UCB_IE_RIS, 0); 474 - ucb1400_reg_write(ucb, UCB_IE_FAL, 0); 475 - ucb1400_reg_write(ucb, UCB_IE_CLEAR, 0xffff); 476 - ucb1400_reg_write(ucb, UCB_IE_CLEAR, 0); 477 - 478 - /* Read triggered interrupt. */ 479 - ucb->irq = probe_irq_off(mask); 480 - if (ucb->irq < 0 || ucb->irq == NO_IRQ) 481 - return -ENODEV; 482 - 483 - return 0; 484 - } 485 - 486 - static int ucb1400_ts_probe(struct device *dev) 487 - { 488 - struct ucb1400 *ucb; 489 - struct input_dev *idev; 490 - int error, id, x_res, y_res; 491 - 492 - ucb = kzalloc(sizeof(struct ucb1400), GFP_KERNEL); 493 - idev = input_allocate_device(); 494 - if (!ucb || !idev) { 495 - error = -ENOMEM; 496 - goto err_free_devs; 497 - } 498 - 499 - ucb->ts_idev = idev; 500 - ucb->adcsync = adcsync; 501 - ucb->ac97 = to_ac97_t(dev); 502 - init_waitqueue_head(&ucb->ts_wait); 503 - 504 - id = ucb1400_reg_read(ucb, UCB_ID); 505 - if (id != UCB_ID_1400) { 506 - error = -ENODEV; 507 - goto err_free_devs; 508 - } 509 - 510 - error = ucb1400_detect_irq(ucb); 511 - if (error) { 512 - printk(KERN_ERR "UCB1400: IRQ probe failed\n"); 513 - goto err_free_devs; 514 - } 515 - 516 - error = request_irq(ucb->irq, ucb1400_hard_irq, IRQF_TRIGGER_RISING, 517 - "UCB1400", ucb); 518 - if (error) { 519 - printk(KERN_ERR "ucb1400: unable to grab irq%d: %d\n", 520 - ucb->irq, error); 521 - goto err_free_devs; 522 - } 523 - printk(KERN_DEBUG "UCB1400: found IRQ %d\n", ucb->irq); 524 - 525 - input_set_drvdata(idev, ucb); 526 - 527 - idev->dev.parent = dev; 528 - idev->name = "UCB1400 touchscreen interface"; 529 - idev->id.vendor = ucb1400_reg_read(ucb, AC97_VENDOR_ID1); 530 - idev->id.product = id; 531 - idev->open = ucb1400_ts_open; 532 - idev->close = ucb1400_ts_close; 533 - idev->evbit[0] = BIT_MASK(EV_ABS); 534 - 535 - ucb1400_adc_enable(ucb); 536 - x_res = ucb1400_ts_read_xres(ucb); 537 - y_res = ucb1400_ts_read_yres(ucb); 538 - ucb1400_adc_disable(ucb); 539 - printk(KERN_DEBUG "UCB1400: x/y = %d/%d\n", x_res, y_res); 540 - 541 - input_set_abs_params(idev, ABS_X, 0, x_res, 0, 0); 542 - input_set_abs_params(idev, ABS_Y, 0, y_res, 0, 0); 543 - input_set_abs_params(idev, ABS_PRESSURE, 0, 0, 0, 0); 544 - 545 - error = input_register_device(idev); 546 - if (error) 547 - goto err_free_irq; 548 - 549 - dev_set_drvdata(dev, ucb); 550 - return 0; 551 - 552 - err_free_irq: 553 - free_irq(ucb->irq, ucb); 554 - err_free_devs: 555 - input_free_device(idev); 556 - kfree(ucb); 557 - return error; 558 - } 559 - 560 - static int ucb1400_ts_remove(struct device *dev) 561 - { 562 - struct ucb1400 *ucb = dev_get_drvdata(dev); 563 - 564 - free_irq(ucb->irq, ucb); 565 - input_unregister_device(ucb->ts_idev); 566 - dev_set_drvdata(dev, NULL); 567 - kfree(ucb); 568 - return 0; 569 - } 570 - 571 - static struct device_driver ucb1400_ts_driver = { 572 - .name = "ucb1400_ts", 573 - .owner = THIS_MODULE, 574 - .bus = &ac97_bus_type, 575 - .probe = ucb1400_ts_probe, 576 - .remove = ucb1400_ts_remove, 577 - .resume = ucb1400_ts_resume, 417 + static struct platform_driver ucb1400_ts_driver = { 418 + .probe = ucb1400_ts_probe, 419 + .remove = ucb1400_ts_remove, 420 + .resume = ucb1400_ts_resume, 421 + .driver = { 422 + .name = "ucb1400_ts", 423 + }, 578 424 }; 579 425 580 426 static int __init ucb1400_ts_init(void) 581 427 { 582 - return driver_register(&ucb1400_ts_driver); 428 + return platform_driver_register(&ucb1400_ts_driver); 583 429 } 584 430 585 431 static void __exit ucb1400_ts_exit(void) 586 432 { 587 - driver_unregister(&ucb1400_ts_driver); 433 + platform_driver_unregister(&ucb1400_ts_driver); 588 434 } 589 435 590 436 module_param(adcsync, bool, 0444); 591 437 MODULE_PARM_DESC(adcsync, "Synchronize touch readings with ADCSYNC pin."); 592 438 593 439 module_param(ts_delay, int, 0444); 594 - MODULE_PARM_DESC(ts_delay, "Delay between panel setup and position read. Default = 55us."); 440 + MODULE_PARM_DESC(ts_delay, "Delay between panel setup and" 441 + " position read. Default = 55us."); 595 442 596 443 module_param(ts_delay_pressure, int, 0444); 597 444 MODULE_PARM_DESC(ts_delay_pressure, 598 - "delay between panel setup and pressure read. Default = 0us."); 445 + "delay between panel setup and pressure read." 446 + " Default = 0us."); 599 447 600 448 module_init(ucb1400_ts_init); 601 449 module_exit(ucb1400_ts_exit);
+9
drivers/mfd/Kconfig
··· 50 50 HTC Magician devices, respectively. Actual functionality is 51 51 handled by the leds-pasic3 and ds1wm drivers. 52 52 53 + config UCB1400_CORE 54 + tristate "Philips UCB1400 Core driver" 55 + help 56 + This enables support for the Philips UCB1400 core functions. 57 + The UCB1400 is an AC97 audio codec. 58 + 59 + To compile this driver as a module, choose M here: the 60 + module will be called ucb1400_core. 61 + 53 62 config MFD_TC6393XB 54 63 bool "Support Toshiba TC6393XB" 55 64 depends on GPIOLIB && ARM
+1
drivers/mfd/Makefile
··· 20 20 ifeq ($(CONFIG_SA1100_ASSABET),y) 21 21 obj-$(CONFIG_MCP_UCB1200) += ucb1x00-assabet.o 22 22 endif 23 + obj-$(CONFIG_UCB1400_CORE) += ucb1400_core.o
+106
drivers/mfd/ucb1400_core.c
··· 1 + /* 2 + * Core functions for: 3 + * Philips UCB1400 multifunction chip 4 + * 5 + * Based on ucb1400_ts.c: 6 + * Author: Nicolas Pitre 7 + * Created: September 25, 2006 8 + * Copyright: MontaVista Software, Inc. 9 + * 10 + * Spliting done by: Marek Vasut <marek.vasut@gmail.com> 11 + * If something doesnt work and it worked before spliting, e-mail me, 12 + * dont bother Nicolas please ;-) 13 + * 14 + * This program is free software; you can redistribute it and/or modify 15 + * it under the terms of the GNU General Public License version 2 as 16 + * published by the Free Software Foundation. 17 + * 18 + * This code is heavily based on ucb1x00-*.c copyrighted by Russell King 19 + * covering the UCB1100, UCB1200 and UCB1300.. Support for the UCB1400 has 20 + * been made separate from ucb1x00-core/ucb1x00-ts on Russell's request. 21 + */ 22 + 23 + #include <linux/module.h> 24 + #include <linux/ucb1400.h> 25 + 26 + static int ucb1400_core_probe(struct device *dev) 27 + { 28 + int err; 29 + struct ucb1400 *ucb; 30 + struct ucb1400_ts ucb_ts; 31 + struct snd_ac97 *ac97; 32 + 33 + memset(&ucb_ts, 0, sizeof(ucb_ts)); 34 + 35 + ucb = kzalloc(sizeof(struct ucb1400), GFP_KERNEL); 36 + if (!ucb) { 37 + err = -ENOMEM; 38 + goto err; 39 + } 40 + 41 + dev_set_drvdata(dev, ucb); 42 + 43 + ac97 = to_ac97_t(dev); 44 + 45 + ucb_ts.id = ucb1400_reg_read(ac97, UCB_ID); 46 + if (ucb_ts.id != UCB_ID_1400) { 47 + err = -ENODEV; 48 + goto err0; 49 + } 50 + 51 + /* TOUCHSCREEN */ 52 + ucb_ts.ac97 = ac97; 53 + ucb->ucb1400_ts = platform_device_alloc("ucb1400_ts", -1); 54 + if (!ucb->ucb1400_ts) { 55 + err = -ENOMEM; 56 + goto err0; 57 + } 58 + err = platform_device_add_data(ucb->ucb1400_ts, &ucb_ts, 59 + sizeof(ucb_ts)); 60 + if (err) 61 + goto err1; 62 + err = platform_device_add(ucb->ucb1400_ts); 63 + if (err) 64 + goto err1; 65 + 66 + return 0; 67 + 68 + err1: 69 + platform_device_put(ucb->ucb1400_ts); 70 + err0: 71 + kfree(ucb); 72 + err: 73 + return err; 74 + } 75 + 76 + static int ucb1400_core_remove(struct device *dev) 77 + { 78 + struct ucb1400 *ucb = dev_get_drvdata(dev); 79 + 80 + platform_device_unregister(ucb->ucb1400_ts); 81 + kfree(ucb); 82 + return 0; 83 + } 84 + 85 + static struct device_driver ucb1400_core_driver = { 86 + .name = "ucb1400_core", 87 + .bus = &ac97_bus_type, 88 + .probe = ucb1400_core_probe, 89 + .remove = ucb1400_core_remove, 90 + }; 91 + 92 + static int __init ucb1400_core_init(void) 93 + { 94 + return driver_register(&ucb1400_core_driver); 95 + } 96 + 97 + static void __exit ucb1400_core_exit(void) 98 + { 99 + driver_unregister(&ucb1400_core_driver); 100 + } 101 + 102 + module_init(ucb1400_core_init); 103 + module_exit(ucb1400_core_exit); 104 + 105 + MODULE_DESCRIPTION("Philips UCB1400 driver"); 106 + MODULE_LICENSE("GPL");
+161
include/linux/ucb1400.h
··· 1 + /* 2 + * Register definitions and functions for: 3 + * Philips UCB1400 driver 4 + * 5 + * Based on ucb1400_ts: 6 + * Author: Nicolas Pitre 7 + * Created: September 25, 2006 8 + * Copyright: MontaVista Software, Inc. 9 + * 10 + * Spliting done by: Marek Vasut <marek.vasut@gmail.com> 11 + * If something doesnt work and it worked before spliting, e-mail me, 12 + * dont bother Nicolas please ;-) 13 + * 14 + * This program is free software; you can redistribute it and/or modify 15 + * it under the terms of the GNU General Public License version 2 as 16 + * published by the Free Software Foundation. 17 + * 18 + * This code is heavily based on ucb1x00-*.c copyrighted by Russell King 19 + * covering the UCB1100, UCB1200 and UCB1300.. Support for the UCB1400 has 20 + * been made separate from ucb1x00-core/ucb1x00-ts on Russell's request. 21 + */ 22 + 23 + #ifndef _LINUX__UCB1400_H 24 + #define _LINUX__UCB1400_H 25 + 26 + #include <sound/ac97_codec.h> 27 + #include <linux/mutex.h> 28 + #include <linux/platform_device.h> 29 + 30 + /* 31 + * UCB1400 AC-link registers 32 + */ 33 + 34 + #define UCB_IO_DATA 0x5a 35 + #define UCB_IO_DIR 0x5c 36 + #define UCB_IE_RIS 0x5e 37 + #define UCB_IE_FAL 0x60 38 + #define UCB_IE_STATUS 0x62 39 + #define UCB_IE_CLEAR 0x62 40 + #define UCB_IE_ADC (1 << 11) 41 + #define UCB_IE_TSPX (1 << 12) 42 + 43 + #define UCB_TS_CR 0x64 44 + #define UCB_TS_CR_TSMX_POW (1 << 0) 45 + #define UCB_TS_CR_TSPX_POW (1 << 1) 46 + #define UCB_TS_CR_TSMY_POW (1 << 2) 47 + #define UCB_TS_CR_TSPY_POW (1 << 3) 48 + #define UCB_TS_CR_TSMX_GND (1 << 4) 49 + #define UCB_TS_CR_TSPX_GND (1 << 5) 50 + #define UCB_TS_CR_TSMY_GND (1 << 6) 51 + #define UCB_TS_CR_TSPY_GND (1 << 7) 52 + #define UCB_TS_CR_MODE_INT (0 << 8) 53 + #define UCB_TS_CR_MODE_PRES (1 << 8) 54 + #define UCB_TS_CR_MODE_POS (2 << 8) 55 + #define UCB_TS_CR_BIAS_ENA (1 << 11) 56 + #define UCB_TS_CR_TSPX_LOW (1 << 12) 57 + #define UCB_TS_CR_TSMX_LOW (1 << 13) 58 + 59 + #define UCB_ADC_CR 0x66 60 + #define UCB_ADC_SYNC_ENA (1 << 0) 61 + #define UCB_ADC_VREFBYP_CON (1 << 1) 62 + #define UCB_ADC_INP_TSPX (0 << 2) 63 + #define UCB_ADC_INP_TSMX (1 << 2) 64 + #define UCB_ADC_INP_TSPY (2 << 2) 65 + #define UCB_ADC_INP_TSMY (3 << 2) 66 + #define UCB_ADC_INP_AD0 (4 << 2) 67 + #define UCB_ADC_INP_AD1 (5 << 2) 68 + #define UCB_ADC_INP_AD2 (6 << 2) 69 + #define UCB_ADC_INP_AD3 (7 << 2) 70 + #define UCB_ADC_EXT_REF (1 << 5) 71 + #define UCB_ADC_START (1 << 7) 72 + #define UCB_ADC_ENA (1 << 15) 73 + 74 + #define UCB_ADC_DATA 0x68 75 + #define UCB_ADC_DAT_VALID (1 << 15) 76 + #define UCB_ADC_DAT_MASK 0x3ff 77 + 78 + #define UCB_ID 0x7e 79 + #define UCB_ID_1400 0x4304 80 + 81 + struct ucb1400_ts { 82 + struct input_dev *ts_idev; 83 + struct task_struct *ts_task; 84 + int id; 85 + wait_queue_head_t ts_wait; 86 + unsigned int ts_restart:1; 87 + int irq; 88 + unsigned int irq_pending; /* not bit field shared */ 89 + struct snd_ac97 *ac97; 90 + }; 91 + 92 + struct ucb1400 { 93 + struct platform_device *ucb1400_ts; 94 + }; 95 + 96 + static inline u16 ucb1400_reg_read(struct snd_ac97 *ac97, u16 reg) 97 + { 98 + return ac97->bus->ops->read(ac97, reg); 99 + } 100 + 101 + static inline void ucb1400_reg_write(struct snd_ac97 *ac97, u16 reg, u16 val) 102 + { 103 + ac97->bus->ops->write(ac97, reg, val); 104 + } 105 + 106 + static inline u16 ucb1400_gpio_get_value(struct snd_ac97 *ac97, u16 gpio) 107 + { 108 + return ucb1400_reg_read(ac97, UCB_IO_DATA) & (1 << gpio); 109 + } 110 + 111 + static inline void ucb1400_gpio_set_value(struct snd_ac97 *ac97, u16 gpio, 112 + u16 val) 113 + { 114 + ucb1400_reg_write(ac97, UCB_IO_DATA, val ? 115 + ucb1400_reg_read(ac97, UCB_IO_DATA) | (1 << gpio) : 116 + ucb1400_reg_read(ac97, UCB_IO_DATA) & ~(1 << gpio)); 117 + } 118 + 119 + static inline u16 ucb1400_gpio_get_direction(struct snd_ac97 *ac97, u16 gpio) 120 + { 121 + return ucb1400_reg_read(ac97, UCB_IO_DIR) & (1 << gpio); 122 + } 123 + 124 + static inline void ucb1400_gpio_set_direction(struct snd_ac97 *ac97, u16 gpio, 125 + u16 dir) 126 + { 127 + ucb1400_reg_write(ac97, UCB_IO_DIR, dir ? 128 + ucb1400_reg_read(ac97, UCB_IO_DIR) | (1 << gpio) : 129 + ucb1400_reg_read(ac97, UCB_IO_DIR) & ~(1 << gpio)); 130 + } 131 + 132 + static inline void ucb1400_adc_enable(struct snd_ac97 *ac97) 133 + { 134 + ucb1400_reg_write(ac97, UCB_ADC_CR, UCB_ADC_ENA); 135 + } 136 + 137 + static unsigned int ucb1400_adc_read(struct snd_ac97 *ac97, u16 adc_channel, 138 + int adcsync) 139 + { 140 + unsigned int val; 141 + 142 + if (adcsync) 143 + adc_channel |= UCB_ADC_SYNC_ENA; 144 + 145 + ucb1400_reg_write(ac97, UCB_ADC_CR, UCB_ADC_ENA | adc_channel); 146 + ucb1400_reg_write(ac97, UCB_ADC_CR, UCB_ADC_ENA | adc_channel | 147 + UCB_ADC_START); 148 + 149 + while (!((val = ucb1400_reg_read(ac97, UCB_ADC_DATA)) 150 + & UCB_ADC_DAT_VALID)) 151 + schedule_timeout_uninterruptible(1); 152 + 153 + return val & UCB_ADC_DAT_MASK; 154 + } 155 + 156 + static inline void ucb1400_adc_disable(struct snd_ac97 *ac97) 157 + { 158 + ucb1400_reg_write(ac97, UCB_ADC_CR, 0); 159 + } 160 + 161 + #endif