04ab3d2a83953cb5b3b3d9ba2c67b068f7c2e5e6
[openwrt/staging/dedeckeh.git] / target / linux / omap24xx / patches-2.6.35 / 500-cbus.patch
1 ---
2 arch/arm/Kconfig | 4
3 drivers/Makefile | 2
4 drivers/cbus/Kconfig | 89 ++++
5 drivers/cbus/Makefile | 14
6 drivers/cbus/cbus.c | 309 ++++++++++++++++
7 drivers/cbus/cbus.h | 36 +
8 drivers/cbus/retu-headset.c | 355 ++++++++++++++++++
9 drivers/cbus/retu-pwrbutton.c | 118 ++++++
10 drivers/cbus/retu-rtc.c | 477 +++++++++++++++++++++++++
11 drivers/cbus/retu-user.c | 425 ++++++++++++++++++++++
12 drivers/cbus/retu-wdt.c | 388 ++++++++++++++++++++
13 drivers/cbus/retu.c | 468 ++++++++++++++++++++++++
14 drivers/cbus/retu.h | 77 ++++
15 drivers/cbus/tahvo-usb.c | 777 +++++++++++++++++++++++++++++++++++++++++
16 drivers/cbus/tahvo-user.c | 407 +++++++++++++++++++++
17 drivers/cbus/tahvo.c | 443 +++++++++++++++++++++++
18 drivers/cbus/tahvo.h | 61 +++
19 drivers/cbus/user_retu_tahvo.h | 75 +++
20 18 files changed, 4524 insertions(+), 1 deletion(-)
21
22 --- /dev/null
23 +++ linux-2.6.35/drivers/cbus/cbus.c
24 @@ -0,0 +1,309 @@
25 +/*
26 + * drivers/cbus/cbus.c
27 + *
28 + * Support functions for CBUS serial protocol
29 + *
30 + * Copyright (C) 2004, 2005 Nokia Corporation
31 + *
32 + * Written by Juha Yrjölä <juha.yrjola@nokia.com>,
33 + * David Weinehall <david.weinehall@nokia.com>, and
34 + * Mikko Ylinen <mikko.k.ylinen@nokia.com>
35 + *
36 + * This file is subject to the terms and conditions of the GNU General
37 + * Public License. See the file "COPYING" in the main directory of this
38 + * archive for more details.
39 + *
40 + * This program is distributed in the hope that it will be useful,
41 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
42 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43 + * GNU General Public License for more details.
44 + *
45 + * You should have received a copy of the GNU General Public License
46 + * along with this program; if not, write to the Free Software
47 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
48 + */
49 +
50 +#include <linux/device.h>
51 +#include <linux/init.h>
52 +#include <linux/kernel.h>
53 +#include <linux/delay.h>
54 +#include <linux/spinlock.h>
55 +#include <linux/gpio.h>
56 +#include <linux/platform_device.h>
57 +#include <linux/slab.h>
58 +
59 +#include <asm/io.h>
60 +#include <asm/mach-types.h>
61 +
62 +#include <plat/board.h>
63 +#include <plat/cbus.h>
64 +
65 +#include "cbus.h"
66 +
67 +struct cbus_host *cbus_host = NULL;
68 +EXPORT_SYMBOL(cbus_host);
69 +
70 +#ifdef CONFIG_ARCH_OMAP1
71 +/* We use our own MPUIO functions to get closer to 1MHz bus speed */
72 +
73 +static inline void cbus_set_gpio_direction(u32 base, int mpuio, int is_input)
74 +{
75 + u16 w;
76 +
77 + mpuio &= 0x0f;
78 + w = __raw_readw(base + OMAP_MPUIO_IO_CNTL);
79 + if (is_input)
80 + w |= 1 << mpuio;
81 + else
82 + w &= ~(1 << mpuio);
83 + __raw_writew(w, base + OMAP_MPUIO_IO_CNTL);
84 +
85 +}
86 +
87 +static inline void cbus_set_gpio_dataout(u32 base, int mpuio, int enable)
88 +{
89 + u16 w;
90 +
91 + mpuio &= 0x0f;
92 + w = __raw_readw(base + OMAP_MPUIO_OUTPUT);
93 + if (enable)
94 + w |= 1 << mpuio;
95 + else
96 + w &= ~(1 << mpuio);
97 + __raw_writew(w, base + OMAP_MPUIO_OUTPUT);
98 +}
99 +
100 +static inline int cbus_get_gpio_datain(u32 base, int mpuio)
101 +{
102 + mpuio &= 0x0f;
103 +
104 + return (__raw_readw(base + OMAP_MPUIO_INPUT_LATCH) & (1 << mpuio)) != 0;
105 +}
106 +
107 +static void cbus_send_bit(struct cbus_host *host, u32 base, int bit,
108 + int set_to_input)
109 +{
110 + cbus_set_gpio_dataout(base, host->dat_gpio, bit ? 1 : 0);
111 + cbus_set_gpio_dataout(base, host->clk_gpio, 1);
112 +
113 + /* The data bit is read on the rising edge of CLK */
114 + if (set_to_input)
115 + cbus_set_gpio_direction(base, host->dat_gpio, 1);
116 +
117 + cbus_set_gpio_dataout(base, host->clk_gpio, 0);
118 +}
119 +
120 +static u8 cbus_receive_bit(struct cbus_host *host, u32 base)
121 +{
122 + u8 ret;
123 +
124 + cbus_set_gpio_dataout(base, host->clk_gpio, 1);
125 + ret = cbus_get_gpio_datain(base, host->dat_gpio);
126 + cbus_set_gpio_dataout(base, host->clk_gpio, 0);
127 +
128 + return ret;
129 +}
130 +
131 +#define cbus_output(base, gpio, val) cbus_set_gpio_direction(base, gpio, 0)
132 +
133 +#else
134 +
135 +#define cbus_output(base, gpio, val) gpio_direction_output(gpio, val)
136 +#define cbus_set_gpio_dataout(base, gpio, enable) gpio_set_value(gpio, enable)
137 +#define cbus_get_gpio_datain(base, int, gpio) gpio_get_value(gpio)
138 +
139 +static void _cbus_send_bit(struct cbus_host *host, int bit, int set_to_input)
140 +{
141 + gpio_set_value(host->dat_gpio, bit ? 1 : 0);
142 + gpio_set_value(host->clk_gpio, 1);
143 +
144 + /* The data bit is read on the rising edge of CLK */
145 + if (set_to_input)
146 + gpio_direction_input(host->dat_gpio);
147 +
148 + gpio_set_value(host->clk_gpio, 0);
149 +}
150 +
151 +static u8 _cbus_receive_bit(struct cbus_host *host)
152 +{
153 + u8 ret;
154 +
155 + gpio_set_value(host->clk_gpio, 1);
156 + ret = gpio_get_value(host->dat_gpio);
157 + gpio_set_value(host->clk_gpio, 0);
158 +
159 + return ret;
160 +}
161 +
162 +#define cbus_send_bit(host, base, bit, set_to_input) _cbus_send_bit(host, bit, set_to_input)
163 +#define cbus_receive_bit(host, base) _cbus_receive_bit(host)
164 +
165 +#endif
166 +
167 +static int cbus_transfer(struct cbus_host *host, int dev, int reg, int data)
168 +{
169 + int i;
170 + int is_read = 0;
171 + unsigned long flags;
172 + u32 base;
173 +
174 +#ifdef CONFIG_ARCH_OMAP1
175 + base = OMAP1_IO_ADDRESS(OMAP1_MPUIO_BASE);
176 +#else
177 + base = 0;
178 +#endif
179 +
180 + if (data < 0)
181 + is_read = 1;
182 +
183 + /* We don't want interrupts disturbing our transfer */
184 + spin_lock_irqsave(&host->lock, flags);
185 +
186 + /* Reset state and start of transfer, SEL stays down during transfer */
187 + cbus_set_gpio_dataout(base, host->sel_gpio, 0);
188 +
189 + /* Set the DAT pin to output */
190 + cbus_output(base, host->dat_gpio, 1);
191 +
192 + /* Send the device address */
193 + for (i = 3; i > 0; i--)
194 + cbus_send_bit(host, base, dev & (1 << (i - 1)), 0);
195 +
196 + /* Send the rw flag */
197 + cbus_send_bit(host, base, is_read, 0);
198 +
199 + /* Send the register address */
200 + for (i = 5; i > 0; i--) {
201 + int set_to_input = 0;
202 +
203 + if (is_read && i == 1)
204 + set_to_input = 1;
205 +
206 + cbus_send_bit(host, base, reg & (1 << (i - 1)), set_to_input);
207 + }
208 +
209 + if (!is_read) {
210 + for (i = 16; i > 0; i--)
211 + cbus_send_bit(host, base, data & (1 << (i - 1)), 0);
212 + } else {
213 + cbus_set_gpio_dataout(base, host->clk_gpio, 1);
214 + data = 0;
215 +
216 + for (i = 16; i > 0; i--) {
217 + u8 bit = cbus_receive_bit(host, base);
218 +
219 + if (bit)
220 + data |= 1 << (i - 1);
221 + }
222 + }
223 +
224 + /* Indicate end of transfer, SEL goes up until next transfer */
225 + cbus_set_gpio_dataout(base, host->sel_gpio, 1);
226 + cbus_set_gpio_dataout(base, host->clk_gpio, 1);
227 + cbus_set_gpio_dataout(base, host->clk_gpio, 0);
228 +
229 + spin_unlock_irqrestore(&host->lock, flags);
230 +
231 + return is_read ? data : 0;
232 +}
233 +
234 +/*
235 + * Read a given register from the device
236 + */
237 +int cbus_read_reg(struct cbus_host *host, int dev, int reg)
238 +{
239 + return cbus_host ? cbus_transfer(host, dev, reg, -1) : -ENODEV;
240 +}
241 +EXPORT_SYMBOL(cbus_read_reg);
242 +
243 +/*
244 + * Write to a given register of the device
245 + */
246 +int cbus_write_reg(struct cbus_host *host, int dev, int reg, u16 val)
247 +{
248 + return cbus_host ? cbus_transfer(host, dev, reg, (int)val) : -ENODEV;
249 +}
250 +EXPORT_SYMBOL(cbus_write_reg);
251 +
252 +static int __init cbus_bus_probe(struct platform_device *pdev)
253 +{
254 + struct cbus_host *chost;
255 + struct cbus_host_platform_data *pdata = pdev->dev.platform_data;
256 + int ret;
257 +
258 + chost = kzalloc(sizeof (*chost), GFP_KERNEL);
259 + if (chost == NULL)
260 + return -ENOMEM;
261 +
262 + spin_lock_init(&chost->lock);
263 +
264 + chost->clk_gpio = pdata->clk_gpio;
265 + chost->dat_gpio = pdata->dat_gpio;
266 + chost->sel_gpio = pdata->sel_gpio;
267 +
268 + if ((ret = gpio_request(chost->clk_gpio, "CBUS clk")) < 0)
269 + goto exit1;
270 +
271 + if ((ret = gpio_request(chost->dat_gpio, "CBUS data")) < 0)
272 + goto exit2;
273 +
274 + if ((ret = gpio_request(chost->sel_gpio, "CBUS sel")) < 0)
275 + goto exit3;
276 +
277 + gpio_direction_output(chost->clk_gpio, 0);
278 + gpio_direction_input(chost->dat_gpio);
279 + gpio_direction_output(chost->sel_gpio, 1);
280 +
281 + gpio_set_value(chost->clk_gpio, 1);
282 + gpio_set_value(chost->clk_gpio, 0);
283 +
284 + platform_set_drvdata(pdev, chost);
285 +
286 + cbus_host = chost;
287 +
288 + return 0;
289 +exit3:
290 + gpio_free(chost->dat_gpio);
291 +exit2:
292 + gpio_free(chost->clk_gpio);
293 +exit1:
294 + kfree(chost);
295 +
296 + return ret;
297 +}
298 +
299 +static void __exit cbus_bus_remove(struct platform_device *pdev)
300 +{
301 + struct cbus_host *chost = platform_get_drvdata(pdev);
302 +
303 + gpio_free(chost->dat_gpio);
304 + gpio_free(chost->clk_gpio);
305 + kfree(chost);
306 +}
307 +
308 +static struct platform_driver cbus_driver = {
309 + .remove = __exit_p(cbus_bus_remove),
310 + .driver = {
311 + .name = "cbus",
312 + },
313 +};
314 +
315 +static int __init cbus_bus_init(void)
316 +{
317 + return platform_driver_probe(&cbus_driver, cbus_bus_probe);
318 +}
319 +
320 +subsys_initcall(cbus_bus_init);
321 +
322 +static void __exit cbus_bus_exit(void)
323 +{
324 + platform_driver_unregister(&cbus_driver);
325 +}
326 +module_exit(cbus_bus_exit);
327 +
328 +MODULE_DESCRIPTION("CBUS serial protocol");
329 +MODULE_LICENSE("GPL");
330 +MODULE_AUTHOR("Juha Yrjölä");
331 +MODULE_AUTHOR("David Weinehall");
332 +MODULE_AUTHOR("Mikko Ylinen");
333 +
334 --- /dev/null
335 +++ linux-2.6.35/drivers/cbus/cbus.h
336 @@ -0,0 +1,36 @@
337 +/*
338 + * drivers/cbus/cbus.h
339 + *
340 + * Copyright (C) 2004, 2005 Nokia Corporation
341 + *
342 + * Written by Juha Yrjölä <juha.yrjola@nokia.com> and
343 + * David Weinehall <david.weinehall@nokia.com>
344 + *
345 + * This file is subject to the terms and conditions of the GNU General
346 + * Public License. See the file "COPYING" in the main directory of this
347 + * archive for more details.
348 + *
349 + * This program is distributed in the hope that it will be useful,
350 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
351 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
352 + * GNU General Public License for more details.
353 + *
354 + * You should have received a copy of the GNU General Public License
355 + * along with this program; if not, write to the Free Software
356 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
357 + */
358 +
359 +#ifndef __DRIVERS_CBUS_CBUS_H
360 +#define __DRIVERS_CBUS_CBUS_H
361 +
362 +struct cbus_host {
363 + int clk_gpio, dat_gpio, sel_gpio;
364 + spinlock_t lock;
365 +};
366 +
367 +extern struct cbus_host *cbus_host;
368 +
369 +extern int cbus_read_reg(struct cbus_host *host, int dev, int reg);
370 +extern int cbus_write_reg(struct cbus_host *host, int dev, int reg, u16 val);
371 +
372 +#endif /* __DRIVERS_CBUS_CBUS_H */
373 --- /dev/null
374 +++ linux-2.6.35/drivers/cbus/Kconfig
375 @@ -0,0 +1,89 @@
376 +#
377 +# CBUS device configuration
378 +#
379 +
380 +menu "CBUS support"
381 +
382 +config CBUS
383 + depends on ARCH_OMAP
384 + bool "CBUS support on OMAP"
385 + ---help---
386 + CBUS is a proprietary serial protocol by Nokia. It is mainly
387 + used for accessing Energy Management auxiliary chips.
388 +
389 + If you want CBUS support, you should say Y here.
390 +
391 +config CBUS_TAHVO
392 + depends on CBUS
393 + bool "Support for Tahvo"
394 + ---help---
395 + Tahvo is a mixed signal ASIC with some system features
396 +
397 + If you want Tahvo support, you should say Y here.
398 +
399 +config CBUS_TAHVO_USER
400 + depends on CBUS_TAHVO
401 + bool "Support for Tahvo user space functions"
402 + ---help---
403 + If you want support for Tahvo's user space read/write etc. functions,
404 + you should say Y here.
405 +
406 +config CBUS_TAHVO_USB
407 + depends on CBUS_TAHVO && USB
408 + tristate "Support for Tahvo USB transceiver"
409 + ---help---
410 + If you want Tahvo support for USB transceiver, say Y or M here.
411 +
412 +config CBUS_TAHVO_USB_HOST_BY_DEFAULT
413 + depends on CBUS_TAHVO_USB && USB_OTG
414 + boolean "Device in USB host mode by default"
415 + ---help---
416 + Say Y here, if you want the device to enter USB host mode
417 + by default on bootup.
418 +
419 +config CBUS_RETU
420 + depends on CBUS
421 + bool "Support for Retu"
422 + ---help---
423 + Retu is a mixed signal ASIC with some system features
424 +
425 + If you want Retu support, you should say Y here.
426 +
427 +config CBUS_RETU_USER
428 + depends on CBUS_RETU
429 + bool "Support for Retu user space functions"
430 + ---help---
431 + If you want support for Retu's user space read/write etc. functions,
432 + you should say Y here.
433 +
434 +config CBUS_RETU_POWERBUTTON
435 + depends on CBUS_RETU
436 + bool "Support for Retu power button"
437 + ---help---
438 + The power button on Nokia 770 is connected to the Retu ASIC.
439 +
440 + If you want support for the Retu power button, you should say Y here.
441 +
442 +config CBUS_RETU_RTC
443 + depends on CBUS_RETU && SYSFS
444 + tristate "Support for Retu pseudo-RTC"
445 + ---help---
446 + Say Y here if you want support for the device that alleges to be an
447 + RTC in Retu. This will expose a sysfs interface for it.
448 +
449 +config CBUS_RETU_WDT
450 + depends on CBUS_RETU && SYSFS && WATCHDOG
451 + tristate "Support for Retu watchdog timer"
452 + ---help---
453 + Say Y here if you want support for the watchdog in Retu. This will
454 + expose a sysfs interface to grok it.
455 +
456 +config CBUS_RETU_HEADSET
457 + depends on CBUS_RETU && SYSFS
458 + tristate "Support for headset detection with Retu/Vilma"
459 + ---help---
460 + Say Y here if you want support detecting a headset that's connected
461 + to Retu/Vilma. Detection state and events are exposed through
462 + sysfs.
463 +
464 +endmenu
465 --- /dev/null
466 +++ linux-2.6.35/drivers/cbus/Makefile
467 @@ -0,0 +1,14 @@
468 +#
469 +# Makefile for CBUS.
470 +#
471 +
472 +obj-$(CONFIG_CBUS) += cbus.o
473 +obj-$(CONFIG_CBUS_TAHVO) += tahvo.o
474 +obj-$(CONFIG_CBUS_RETU) += retu.o
475 +obj-$(CONFIG_CBUS_TAHVO_USB) += tahvo-usb.o
476 +obj-$(CONFIG_CBUS_RETU_POWERBUTTON) += retu-pwrbutton.o
477 +obj-$(CONFIG_CBUS_RETU_RTC) += retu-rtc.o
478 +obj-$(CONFIG_CBUS_RETU_WDT) += retu-wdt.o
479 +obj-$(CONFIG_CBUS_TAHVO_USER) += tahvo-user.o
480 +obj-$(CONFIG_CBUS_RETU_USER) += retu-user.o
481 +obj-$(CONFIG_CBUS_RETU_HEADSET) += retu-headset.o
482 --- /dev/null
483 +++ linux-2.6.35/drivers/cbus/retu.c
484 @@ -0,0 +1,468 @@
485 +/**
486 + * drivers/cbus/retu.c
487 + *
488 + * Support functions for Retu ASIC
489 + *
490 + * Copyright (C) 2004, 2005 Nokia Corporation
491 + *
492 + * Written by Juha Yrjölä <juha.yrjola@nokia.com>,
493 + * David Weinehall <david.weinehall@nokia.com>, and
494 + * Mikko Ylinen <mikko.k.ylinen@nokia.com>
495 + *
496 + * This file is subject to the terms and conditions of the GNU General
497 + * Public License. See the file "COPYING" in the main directory of this
498 + * archive for more details.
499 + *
500 + * This program is distributed in the hope that it will be useful,
501 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
502 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
503 + * GNU General Public License for more details.
504 + *
505 + * You should have received a copy of the GNU General Public License
506 + * along with this program; if not, write to the Free Software
507 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
508 + */
509 +
510 +#include <linux/module.h>
511 +#include <linux/init.h>
512 +
513 +#include <linux/kernel.h>
514 +#include <linux/errno.h>
515 +#include <linux/device.h>
516 +#include <linux/miscdevice.h>
517 +#include <linux/poll.h>
518 +#include <linux/fs.h>
519 +#include <linux/irq.h>
520 +#include <linux/interrupt.h>
521 +#include <linux/platform_device.h>
522 +#include <linux/gpio.h>
523 +
524 +#include <asm/uaccess.h>
525 +#include <asm/mach-types.h>
526 +
527 +#include <plat/mux.h>
528 +#include <plat/board.h>
529 +
530 +#include "cbus.h"
531 +#include "retu.h"
532 +
533 +#define RETU_ID 0x01
534 +#define PFX "retu: "
535 +
536 +static int retu_initialized;
537 +static int retu_irq_pin;
538 +static int retu_is_vilma;
539 +
540 +static struct tasklet_struct retu_tasklet;
541 +spinlock_t retu_lock = SPIN_LOCK_UNLOCKED;
542 +
543 +static struct completion device_release;
544 +
545 +struct retu_irq_handler_desc {
546 + int (*func)(unsigned long);
547 + unsigned long arg;
548 + char name[8];
549 +};
550 +
551 +static struct retu_irq_handler_desc retu_irq_handlers[MAX_RETU_IRQ_HANDLERS];
552 +
553 +/**
554 + * retu_read_reg - Read a value from a register in Retu
555 + * @reg: the register to read from
556 + *
557 + * This function returns the contents of the specified register
558 + */
559 +int retu_read_reg(int reg)
560 +{
561 + BUG_ON(!retu_initialized);
562 + return cbus_read_reg(cbus_host, RETU_ID, reg);
563 +}
564 +
565 +/**
566 + * retu_write_reg - Write a value to a register in Retu
567 + * @reg: the register to write to
568 + * @reg: the value to write to the register
569 + *
570 + * This function writes a value to the specified register
571 + */
572 +void retu_write_reg(int reg, u16 val)
573 +{
574 + BUG_ON(!retu_initialized);
575 + cbus_write_reg(cbus_host, RETU_ID, reg, val);
576 +}
577 +
578 +void retu_set_clear_reg_bits(int reg, u16 set, u16 clear)
579 +{
580 + unsigned long flags;
581 + u16 w;
582 +
583 + spin_lock_irqsave(&retu_lock, flags);
584 + w = retu_read_reg(reg);
585 + w &= ~clear;
586 + w |= set;
587 + retu_write_reg(reg, w);
588 + spin_unlock_irqrestore(&retu_lock, flags);
589 +}
590 +
591 +#define ADC_MAX_CHAN_NUMBER 13
592 +
593 +int retu_read_adc(int channel)
594 +{
595 + unsigned long flags;
596 + int res;
597 +
598 + if (channel < 0 || channel > ADC_MAX_CHAN_NUMBER)
599 + return -EINVAL;
600 +
601 + spin_lock_irqsave(&retu_lock, flags);
602 +
603 + if ((channel == 8) && retu_is_vilma) {
604 + int scr = retu_read_reg(RETU_REG_ADCSCR);
605 + int ch = (retu_read_reg(RETU_REG_ADCR) >> 10) & 0xf;
606 + if (((scr & 0xff) != 0) && (ch != 8))
607 + retu_write_reg (RETU_REG_ADCSCR, (scr & ~0xff));
608 + }
609 +
610 + /* Select the channel and read result */
611 + retu_write_reg(RETU_REG_ADCR, channel << 10);
612 + res = retu_read_reg(RETU_REG_ADCR) & 0x3ff;
613 +
614 + if (retu_is_vilma)
615 + retu_write_reg(RETU_REG_ADCR, (1 << 13));
616 +
617 + /* Unlock retu */
618 + spin_unlock_irqrestore(&retu_lock, flags);
619 +
620 + return res;
621 +}
622 +
623 +
624 +static u16 retu_disable_bogus_irqs(u16 mask)
625 +{
626 + int i;
627 +
628 + for (i = 0; i < MAX_RETU_IRQ_HANDLERS; i++) {
629 + if (mask & (1 << i))
630 + continue;
631 + if (retu_irq_handlers[i].func != NULL)
632 + continue;
633 + /* an IRQ was enabled but we don't have a handler for it */
634 + printk(KERN_INFO PFX "disabling bogus IRQ %d\n", i);
635 + mask |= (1 << i);
636 + }
637 + return mask;
638 +}
639 +
640 +/*
641 + * Disable given RETU interrupt
642 + */
643 +void retu_disable_irq(int id)
644 +{
645 + unsigned long flags;
646 + u16 mask;
647 +
648 + spin_lock_irqsave(&retu_lock, flags);
649 + mask = retu_read_reg(RETU_REG_IMR);
650 + mask |= 1 << id;
651 + mask = retu_disable_bogus_irqs(mask);
652 + retu_write_reg(RETU_REG_IMR, mask);
653 + spin_unlock_irqrestore(&retu_lock, flags);
654 +}
655 +
656 +/*
657 + * Enable given RETU interrupt
658 + */
659 +void retu_enable_irq(int id)
660 +{
661 + unsigned long flags;
662 + u16 mask;
663 +
664 + if (id == 3) {
665 + printk("Enabling Retu IRQ %d\n", id);
666 + dump_stack();
667 + }
668 + spin_lock_irqsave(&retu_lock, flags);
669 + mask = retu_read_reg(RETU_REG_IMR);
670 + mask &= ~(1 << id);
671 + mask = retu_disable_bogus_irqs(mask);
672 + retu_write_reg(RETU_REG_IMR, mask);
673 + spin_unlock_irqrestore(&retu_lock, flags);
674 +}
675 +
676 +/*
677 + * Acknowledge given RETU interrupt
678 + */
679 +void retu_ack_irq(int id)
680 +{
681 + retu_write_reg(RETU_REG_IDR, 1 << id);
682 +}
683 +
684 +/*
685 + * RETU interrupt handler. Only schedules the tasklet.
686 + */
687 +static irqreturn_t retu_irq_handler(int irq, void *dev_id)
688 +{
689 + tasklet_schedule(&retu_tasklet);
690 + return IRQ_HANDLED;
691 +}
692 +
693 +/*
694 + * Tasklet handler
695 + */
696 +static void retu_tasklet_handler(unsigned long data)
697 +{
698 + struct retu_irq_handler_desc *hnd;
699 + u16 id;
700 + u16 im;
701 + int i;
702 +
703 + for (;;) {
704 + id = retu_read_reg(RETU_REG_IDR);
705 + im = ~retu_read_reg(RETU_REG_IMR);
706 + id &= im;
707 +
708 + if (!id)
709 + break;
710 +
711 + for (i = 0; id != 0; i++, id >>= 1) {
712 + if (!(id & 1))
713 + continue;
714 + hnd = &retu_irq_handlers[i];
715 + if (hnd->func == NULL) {
716 + /* Spurious retu interrupt - disable and ack it */
717 + printk(KERN_INFO "Spurious Retu interrupt "
718 + "(id %d)\n", i);
719 + retu_disable_irq(i);
720 + retu_ack_irq(i);
721 + continue;
722 + }
723 + hnd->func(hnd->arg);
724 + /*
725 + * Don't acknowledge the interrupt here
726 + * It must be done explicitly
727 + */
728 + }
729 + }
730 +}
731 +
732 +/*
733 + * Register the handler for a given RETU interrupt source.
734 + */
735 +int retu_request_irq(int id, void *irq_handler, unsigned long arg, char *name)
736 +{
737 + struct retu_irq_handler_desc *hnd;
738 +
739 + if (irq_handler == NULL || id >= MAX_RETU_IRQ_HANDLERS ||
740 + name == NULL) {
741 + printk(KERN_ERR PFX "Invalid arguments to %s\n",
742 + __FUNCTION__);
743 + return -EINVAL;
744 + }
745 + hnd = &retu_irq_handlers[id];
746 + if (hnd->func != NULL) {
747 + printk(KERN_ERR PFX "IRQ %d already reserved\n", id);
748 + return -EBUSY;
749 + }
750 + printk(KERN_INFO PFX "Registering interrupt %d for device %s\n",
751 + id, name);
752 + hnd->func = irq_handler;
753 + hnd->arg = arg;
754 + strlcpy(hnd->name, name, sizeof(hnd->name));
755 +
756 + retu_ack_irq(id);
757 + retu_enable_irq(id);
758 +
759 + return 0;
760 +}
761 +
762 +/*
763 + * Unregister the handler for a given RETU interrupt source.
764 + */
765 +void retu_free_irq(int id)
766 +{
767 + struct retu_irq_handler_desc *hnd;
768 +
769 + if (id >= MAX_RETU_IRQ_HANDLERS) {
770 + printk(KERN_ERR PFX "Invalid argument to %s\n",
771 + __FUNCTION__);
772 + return;
773 + }
774 + hnd = &retu_irq_handlers[id];
775 + if (hnd->func == NULL) {
776 + printk(KERN_ERR PFX "IRQ %d already freed\n", id);
777 + return;
778 + }
779 +
780 + retu_disable_irq(id);
781 + hnd->func = NULL;
782 +}
783 +
784 +/**
785 + * retu_power_off - Shut down power to system
786 + *
787 + * This function puts the system in power off state
788 + */
789 +static void retu_power_off(void)
790 +{
791 + /* Ignore power button state */
792 + retu_write_reg(RETU_REG_CC1, retu_read_reg(RETU_REG_CC1) | 2);
793 + /* Expire watchdog immediately */
794 + retu_write_reg(RETU_REG_WATCHDOG, 0);
795 + /* Wait for poweroff*/
796 + for (;;);
797 +}
798 +
799 +/**
800 + * retu_probe - Probe for Retu ASIC
801 + * @dev: the Retu device
802 + *
803 + * Probe for the Retu ASIC and allocate memory
804 + * for its device-struct if found
805 + */
806 +static int __devinit retu_probe(struct device *dev)
807 +{
808 + int rev, ret;
809 +
810 + /* Prepare tasklet */
811 + tasklet_init(&retu_tasklet, retu_tasklet_handler, 0);
812 +
813 + /* REVISIT: Pass these from board-*.c files in platform_data */
814 + if (machine_is_nokia770()) {
815 + retu_irq_pin = 62;
816 + } else if (machine_is_nokia_n800() || machine_is_nokia_n810() ||
817 + machine_is_nokia_n810_wimax()) {
818 + retu_irq_pin = 108;
819 + } else {
820 + printk(KERN_ERR "cbus: Unsupported board for tahvo\n");
821 + return -ENODEV;
822 + }
823 +
824 + if ((ret = gpio_request(retu_irq_pin, "RETU irq")) < 0) {
825 + printk(KERN_ERR PFX "Unable to reserve IRQ GPIO\n");
826 + return ret;
827 + }
828 +
829 + /* Set the pin as input */
830 + gpio_direction_input(retu_irq_pin);
831 +
832 + /* Rising edge triggers the IRQ */
833 + set_irq_type(gpio_to_irq(retu_irq_pin), IRQ_TYPE_EDGE_RISING);
834 +
835 + retu_initialized = 1;
836 +
837 + rev = retu_read_reg(RETU_REG_ASICR) & 0xff;
838 + if (rev & (1 << 7))
839 + retu_is_vilma = 1;
840 +
841 + printk(KERN_INFO "%s v%d.%d found\n", retu_is_vilma ? "Vilma" : "Retu",
842 + (rev >> 4) & 0x07, rev & 0x0f);
843 +
844 + /* Mask all RETU interrupts */
845 + retu_write_reg(RETU_REG_IMR, 0xffff);
846 +
847 + ret = request_irq(gpio_to_irq(retu_irq_pin), retu_irq_handler, 0,
848 + "retu", 0);
849 + if (ret < 0) {
850 + printk(KERN_ERR PFX "Unable to register IRQ handler\n");
851 + gpio_free(retu_irq_pin);
852 + return ret;
853 + }
854 + set_irq_wake(gpio_to_irq(retu_irq_pin), 1);
855 +
856 + /* Register power off function */
857 + pm_power_off = retu_power_off;
858 +
859 +#ifdef CONFIG_CBUS_RETU_USER
860 + /* Initialize user-space interface */
861 + if (retu_user_init() < 0) {
862 + printk(KERN_ERR "Unable to initialize driver\n");
863 + free_irq(gpio_to_irq(retu_irq_pin), 0);
864 + gpio_free(retu_irq_pin);
865 + return ret;
866 + }
867 +#endif
868 +
869 + return 0;
870 +}
871 +
872 +static int retu_remove(struct device *dev)
873 +{
874 +#ifdef CONFIG_CBUS_RETU_USER
875 + retu_user_cleanup();
876 +#endif
877 + /* Mask all RETU interrupts */
878 + retu_write_reg(RETU_REG_IMR, 0xffff);
879 + free_irq(gpio_to_irq(retu_irq_pin), 0);
880 + gpio_free(retu_irq_pin);
881 + tasklet_kill(&retu_tasklet);
882 +
883 + return 0;
884 +}
885 +
886 +static void retu_device_release(struct device *dev)
887 +{
888 + complete(&device_release);
889 +}
890 +
891 +static struct device_driver retu_driver = {
892 + .name = "retu",
893 + .bus = &platform_bus_type,
894 + .probe = retu_probe,
895 + .remove = retu_remove,
896 +};
897 +
898 +static struct platform_device retu_device = {
899 + .name = "retu",
900 + .id = -1,
901 + .dev = {
902 + .release = retu_device_release,
903 + }
904 +};
905 +
906 +/**
907 + * retu_init - initialise Retu driver
908 + *
909 + * Initialise the Retu driver and return 0 if everything worked ok
910 + */
911 +static int __init retu_init(void)
912 +{
913 + int ret = 0;
914 +
915 + printk(KERN_INFO "Retu/Vilma driver initialising\n");
916 +
917 + init_completion(&device_release);
918 +
919 + if ((ret = driver_register(&retu_driver)) < 0)
920 + return ret;
921 +
922 + if ((ret = platform_device_register(&retu_device)) < 0) {
923 + driver_unregister(&retu_driver);
924 + return ret;
925 + }
926 + return 0;
927 +}
928 +
929 +/*
930 + * Cleanup
931 + */
932 +static void __exit retu_exit(void)
933 +{
934 + platform_device_unregister(&retu_device);
935 + driver_unregister(&retu_driver);
936 + wait_for_completion(&device_release);
937 +}
938 +
939 +EXPORT_SYMBOL(retu_request_irq);
940 +EXPORT_SYMBOL(retu_free_irq);
941 +EXPORT_SYMBOL(retu_enable_irq);
942 +EXPORT_SYMBOL(retu_disable_irq);
943 +EXPORT_SYMBOL(retu_ack_irq);
944 +EXPORT_SYMBOL(retu_read_reg);
945 +EXPORT_SYMBOL(retu_write_reg);
946 +
947 +subsys_initcall(retu_init);
948 +module_exit(retu_exit);
949 +
950 +MODULE_DESCRIPTION("Retu ASIC control");
951 +MODULE_LICENSE("GPL");
952 +MODULE_AUTHOR("Juha Yrjölä, David Weinehall, and Mikko Ylinen");
953 --- /dev/null
954 +++ linux-2.6.35/drivers/cbus/retu.h
955 @@ -0,0 +1,77 @@
956 +/**
957 + * drivers/cbus/retu.h
958 + *
959 + * Copyright (C) 2004, 2005 Nokia Corporation
960 + *
961 + * Written by Juha Yrjölä <juha.yrjola@nokia.com> and
962 + * David Weinehall <david.weinehall@nokia.com>
963 + *
964 + * This file is subject to the terms and conditions of the GNU General
965 + * Public License. See the file "COPYING" in the main directory of this
966 + * archive for more details.
967 + *
968 + * This program is distributed in the hope that it will be useful,
969 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
970 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
971 + * GNU General Public License for more details.
972 +
973 + * You should have received a copy of the GNU General Public License
974 + * along with this program; if not, write to the Free Software
975 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
976 + */
977 +
978 +#ifndef __DRIVERS_CBUS_RETU_H
979 +#define __DRIVERS_CBUS_RETU_H
980 +
981 +#include <linux/types.h>
982 +
983 +/* Registers */
984 +#define RETU_REG_ASICR 0x00 /* ASIC ID & revision */
985 +#define RETU_REG_IDR 0x01 /* Interrupt ID */
986 +#define RETU_REG_IMR 0x02 /* Interrupt mask */
987 +#define RETU_REG_RTCDSR 0x03 /* RTC seconds register */
988 +#define RETU_REG_RTCHMR 0x04 /* RTC hours and minutes register */
989 +#define RETU_REG_RTCHMAR 0x05 /* RTC hours and minutes alarm and time set register */
990 +#define RETU_REG_RTCCALR 0x06 /* RTC calibration register */
991 +#define RETU_REG_ADCR 0x08 /* ADC result */
992 +#define RETU_REG_ADCSCR 0x09 /* ADC sample ctrl */
993 +#define RETU_REG_CC1 0x0d /* Common control register 1 */
994 +#define RETU_REG_CC2 0x0e /* Common control register 2 */
995 +#define RETU_REG_CTRL_CLR 0x0f /* Regulator clear register */
996 +#define RETU_REG_CTRL_SET 0x10 /* Regulator set register */
997 +#define RETU_REG_STATUS 0x16 /* Status register */
998 +#define RETU_REG_WATCHDOG 0x17 /* Watchdog register */
999 +#define RETU_REG_AUDTXR 0x18 /* Audio Codec Tx register */
1000 +#define RETU_REG_MAX 0x1f
1001 +
1002 +/* Interrupt sources */
1003 +#define RETU_INT_PWR 0
1004 +#define RETU_INT_CHAR 1
1005 +#define RETU_INT_RTCS 2
1006 +#define RETU_INT_RTCM 3
1007 +#define RETU_INT_RTCD 4
1008 +#define RETU_INT_RTCA 5
1009 +#define RETU_INT_HOOK 6
1010 +#define RETU_INT_HEAD 7
1011 +#define RETU_INT_ADCS 8
1012 +
1013 +#define MAX_RETU_IRQ_HANDLERS 16
1014 +
1015 +int retu_read_reg(int reg);
1016 +void retu_write_reg(int reg, u16 val);
1017 +void retu_set_clear_reg_bits(int reg, u16 set, u16 clear);
1018 +int retu_read_adc(int channel);
1019 +int retu_request_irq(int id, void *irq_handler, unsigned long arg, char *name);
1020 +void retu_free_irq(int id);
1021 +void retu_enable_irq(int id);
1022 +void retu_disable_irq(int id);
1023 +void retu_ack_irq(int id);
1024 +
1025 +#ifdef CONFIG_CBUS_RETU_USER
1026 +int retu_user_init(void);
1027 +void retu_user_cleanup(void);
1028 +#endif
1029 +
1030 +extern spinlock_t retu_lock;
1031 +
1032 +#endif /* __DRIVERS_CBUS_RETU_H */
1033 --- /dev/null
1034 +++ linux-2.6.35/drivers/cbus/retu-headset.c
1035 @@ -0,0 +1,355 @@
1036 +/**
1037 + * Retu/Vilma headset detection
1038 + *
1039 + * Copyright (C) 2006 Nokia Corporation
1040 + *
1041 + * Written by Juha Yrjölä
1042 + *
1043 + * This file is subject to the terms and conditions of the GNU General
1044 + * Public License. See the file "COPYING" in the main directory of this
1045 + * archive for more details.
1046 + *
1047 + * This program is distributed in the hope that it will be useful,
1048 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1049 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1050 + * GNU General Public License for more details.
1051 + *
1052 + * You should have received a copy of the GNU General Public License
1053 + * along with this program; if not, write to the Free Software
1054 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1055 + */
1056 +
1057 +#include <linux/module.h>
1058 +#include <linux/init.h>
1059 +#include <linux/kernel.h>
1060 +#include <linux/delay.h>
1061 +#include <linux/input.h>
1062 +#include <linux/platform_device.h>
1063 +
1064 +#include "retu.h"
1065 +
1066 +#define RETU_ADC_CHANNEL_HOOKDET 0x05
1067 +
1068 +#define RETU_HEADSET_KEY KEY_PHONE
1069 +
1070 +struct retu_headset {
1071 + spinlock_t lock;
1072 + struct mutex mutex;
1073 + struct platform_device *pdev;
1074 + struct input_dev *idev;
1075 + unsigned bias_enabled;
1076 + unsigned detection_enabled;
1077 + unsigned pressed;
1078 + struct timer_list enable_timer;
1079 + struct timer_list detect_timer;
1080 +};
1081 +
1082 +static void retu_headset_set_bias(int enable)
1083 +{
1084 + if (enable) {
1085 + retu_set_clear_reg_bits(RETU_REG_AUDTXR,
1086 + (1 << 0) | (1 << 1), 0);
1087 + msleep(2);
1088 + retu_set_clear_reg_bits(RETU_REG_AUDTXR, 1 << 3, 0);
1089 + } else {
1090 + retu_set_clear_reg_bits(RETU_REG_AUDTXR, 0,
1091 + (1 << 0) | (1 << 1) | (1 << 3));
1092 + }
1093 +}
1094 +
1095 +static void retu_headset_enable(struct retu_headset *hs)
1096 +{
1097 + mutex_lock(&hs->mutex);
1098 + if (!hs->bias_enabled) {
1099 + hs->bias_enabled = 1;
1100 + retu_headset_set_bias(1);
1101 + }
1102 + mutex_unlock(&hs->mutex);
1103 +}
1104 +
1105 +static void retu_headset_disable(struct retu_headset *hs)
1106 +{
1107 + mutex_lock(&hs->mutex);
1108 + if (hs->bias_enabled) {
1109 + hs->bias_enabled = 0;
1110 + retu_headset_set_bias(0);
1111 + }
1112 + mutex_unlock(&hs->mutex);
1113 +}
1114 +
1115 +static void retu_headset_det_enable(struct retu_headset *hs)
1116 +{
1117 + mutex_lock(&hs->mutex);
1118 + if (!hs->detection_enabled) {
1119 + hs->detection_enabled = 1;
1120 + retu_set_clear_reg_bits(RETU_REG_CC1, (1 << 10) | (1 << 8), 0);
1121 + retu_enable_irq(RETU_INT_HOOK);
1122 + }
1123 + mutex_unlock(&hs->mutex);
1124 +}
1125 +
1126 +static void retu_headset_det_disable(struct retu_headset *hs)
1127 +{
1128 + unsigned long flags;
1129 +
1130 + mutex_lock(&hs->mutex);
1131 + if (hs->detection_enabled) {
1132 + hs->detection_enabled = 0;
1133 + retu_disable_irq(RETU_INT_HOOK);
1134 + del_timer_sync(&hs->enable_timer);
1135 + del_timer_sync(&hs->detect_timer);
1136 + spin_lock_irqsave(&hs->lock, flags);
1137 + if (hs->pressed)
1138 + input_report_key(hs->idev, RETU_HEADSET_KEY, 0);
1139 + spin_unlock_irqrestore(&hs->lock, flags);
1140 + retu_set_clear_reg_bits(RETU_REG_CC1, 0, (1 << 10) | (1 << 8));
1141 + }
1142 + mutex_unlock(&hs->mutex);
1143 +}
1144 +
1145 +static ssize_t retu_headset_hookdet_show(struct device *dev,
1146 + struct device_attribute *attr,
1147 + char *buf)
1148 +{
1149 + int val;
1150 +
1151 + val = retu_read_adc(RETU_ADC_CHANNEL_HOOKDET);
1152 + return sprintf(buf, "%d\n", val);
1153 +}
1154 +
1155 +static DEVICE_ATTR(hookdet, S_IRUGO, retu_headset_hookdet_show, NULL);
1156 +
1157 +static ssize_t retu_headset_enable_show(struct device *dev,
1158 + struct device_attribute *attr,
1159 + char *buf)
1160 +{
1161 + struct retu_headset *hs = dev_get_drvdata(dev);
1162 +
1163 + return sprintf(buf, "%u\n", hs->bias_enabled);
1164 +}
1165 +
1166 +static ssize_t retu_headset_enable_store(struct device *dev,
1167 + struct device_attribute *attr,
1168 + const char *buf, size_t count)
1169 +{
1170 + struct retu_headset *hs = dev_get_drvdata(dev);
1171 + int enable;
1172 +
1173 + if (sscanf(buf, "%u", &enable) != 1)
1174 + return -EINVAL;
1175 + if (enable)
1176 + retu_headset_enable(hs);
1177 + else
1178 + retu_headset_disable(hs);
1179 + return count;
1180 +}
1181 +
1182 +static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR | S_IWGRP,
1183 + retu_headset_enable_show, retu_headset_enable_store);
1184 +
1185 +static ssize_t retu_headset_enable_det_show(struct device *dev,
1186 + struct device_attribute *attr,
1187 + char *buf)
1188 +{
1189 + struct retu_headset *hs = dev_get_drvdata(dev);
1190 +
1191 + return sprintf(buf, "%u\n", hs->detection_enabled);
1192 +}
1193 +
1194 +static ssize_t retu_headset_enable_det_store(struct device *dev,
1195 + struct device_attribute *attr,
1196 + const char *buf, size_t count)
1197 +{
1198 + struct retu_headset *hs = dev_get_drvdata(dev);
1199 + int enable;
1200 +
1201 + if (sscanf(buf, "%u", &enable) != 1)
1202 + return -EINVAL;
1203 + if (enable)
1204 + retu_headset_det_enable(hs);
1205 + else
1206 + retu_headset_det_disable(hs);
1207 + return count;
1208 +}
1209 +
1210 +static DEVICE_ATTR(enable_det, S_IRUGO | S_IWUSR | S_IWGRP,
1211 + retu_headset_enable_det_show,
1212 + retu_headset_enable_det_store);
1213 +
1214 +static void retu_headset_hook_interrupt(unsigned long arg)
1215 +{
1216 + struct retu_headset *hs = (struct retu_headset *) arg;
1217 + unsigned long flags;
1218 +
1219 + retu_ack_irq(RETU_INT_HOOK);
1220 + spin_lock_irqsave(&hs->lock, flags);
1221 + if (!hs->pressed) {
1222 + /* Headset button was just pressed down. */
1223 + hs->pressed = 1;
1224 + input_report_key(hs->idev, RETU_HEADSET_KEY, 1);
1225 + }
1226 + spin_unlock_irqrestore(&hs->lock, flags);
1227 + retu_set_clear_reg_bits(RETU_REG_CC1, 0, (1 << 10) | (1 << 8));
1228 + mod_timer(&hs->enable_timer, jiffies + msecs_to_jiffies(50));
1229 +}
1230 +
1231 +static void retu_headset_enable_timer(unsigned long arg)
1232 +{
1233 + struct retu_headset *hs = (struct retu_headset *) arg;
1234 +
1235 + retu_set_clear_reg_bits(RETU_REG_CC1, (1 << 10) | (1 << 8), 0);
1236 + mod_timer(&hs->detect_timer, jiffies + msecs_to_jiffies(350));
1237 +}
1238 +
1239 +static void retu_headset_detect_timer(unsigned long arg)
1240 +{
1241 + struct retu_headset *hs = (struct retu_headset *) arg;
1242 + unsigned long flags;
1243 +
1244 + spin_lock_irqsave(&hs->lock, flags);
1245 + if (hs->pressed) {
1246 + hs->pressed = 0;
1247 + input_report_key(hs->idev, RETU_HEADSET_KEY, 0);
1248 + }
1249 + spin_unlock_irqrestore(&hs->lock, flags);
1250 +}
1251 +
1252 +static int __init retu_headset_probe(struct platform_device *pdev)
1253 +{
1254 + struct retu_headset *hs;
1255 + int r;
1256 +
1257 + hs = kzalloc(sizeof(*hs), GFP_KERNEL);
1258 + if (hs == NULL)
1259 + return -ENOMEM;
1260 +
1261 + hs->pdev = pdev;
1262 +
1263 + hs->idev = input_allocate_device();
1264 + if (hs->idev == NULL) {
1265 + r = -ENOMEM;
1266 + goto err1;
1267 + }
1268 + hs->idev->name = "retu-headset";
1269 + hs->idev->dev.parent = &pdev->dev;
1270 + set_bit(EV_KEY, hs->idev->evbit);
1271 + set_bit(RETU_HEADSET_KEY, hs->idev->keybit);
1272 + r = input_register_device(hs->idev);
1273 + if (r < 0)
1274 + goto err2;
1275 +
1276 + r = device_create_file(&pdev->dev, &dev_attr_hookdet);
1277 + if (r < 0)
1278 + goto err3;
1279 + r = device_create_file(&pdev->dev, &dev_attr_enable);
1280 + if (r < 0)
1281 + goto err4;
1282 + r = device_create_file(&pdev->dev, &dev_attr_enable_det);
1283 + if (r < 0)
1284 + goto err5;
1285 + platform_set_drvdata(pdev, hs);
1286 +
1287 + spin_lock_init(&hs->lock);
1288 + mutex_init(&hs->mutex);
1289 + setup_timer(&hs->enable_timer, retu_headset_enable_timer,
1290 + (unsigned long) hs);
1291 + setup_timer(&hs->detect_timer, retu_headset_detect_timer,
1292 + (unsigned long) hs);
1293 +
1294 + r = retu_request_irq(RETU_INT_HOOK, retu_headset_hook_interrupt,
1295 + (unsigned long) hs, "hookdet");
1296 + if (r != 0) {
1297 + dev_err(&pdev->dev, "hookdet IRQ not available\n");
1298 + goto err6;
1299 + }
1300 + retu_disable_irq(RETU_INT_HOOK);
1301 + return 0;
1302 +err6:
1303 + device_remove_file(&pdev->dev, &dev_attr_enable_det);
1304 +err5:
1305 + device_remove_file(&pdev->dev, &dev_attr_enable);
1306 +err4:
1307 + device_remove_file(&pdev->dev, &dev_attr_hookdet);
1308 +err3:
1309 + input_unregister_device(hs->idev);
1310 +err2:
1311 + input_free_device(hs->idev);
1312 +err1:
1313 + kfree(hs);
1314 + return r;
1315 +}
1316 +
1317 +static int retu_headset_remove(struct platform_device *pdev)
1318 +{
1319 + struct retu_headset *hs = platform_get_drvdata(pdev);
1320 +
1321 + device_remove_file(&pdev->dev, &dev_attr_hookdet);
1322 + device_remove_file(&pdev->dev, &dev_attr_enable);
1323 + device_remove_file(&pdev->dev, &dev_attr_enable_det);
1324 + retu_headset_disable(hs);
1325 + retu_headset_det_disable(hs);
1326 + retu_free_irq(RETU_INT_HOOK);
1327 + input_unregister_device(hs->idev);
1328 + input_free_device(hs->idev);
1329 + return 0;
1330 +}
1331 +
1332 +static int retu_headset_suspend(struct platform_device *pdev,
1333 + pm_message_t mesg)
1334 +{
1335 + struct retu_headset *hs = platform_get_drvdata(pdev);
1336 +
1337 + mutex_lock(&hs->mutex);
1338 + if (hs->bias_enabled)
1339 + retu_headset_set_bias(0);
1340 + mutex_unlock(&hs->mutex);
1341 +
1342 + return 0;
1343 +}
1344 +
1345 +static int retu_headset_resume(struct platform_device *pdev)
1346 +{
1347 + struct retu_headset *hs = platform_get_drvdata(pdev);
1348 +
1349 + mutex_lock(&hs->mutex);
1350 + if (hs->bias_enabled)
1351 + retu_headset_set_bias(1);
1352 + mutex_unlock(&hs->mutex);
1353 +
1354 + return 0;
1355 +}
1356 +
1357 +static struct platform_driver retu_headset_driver = {
1358 + .probe = retu_headset_probe,
1359 + .remove = retu_headset_remove,
1360 + .suspend = retu_headset_suspend,
1361 + .resume = retu_headset_resume,
1362 + .driver = {
1363 + .name = "retu-headset",
1364 + },
1365 +};
1366 +
1367 +static int __init retu_headset_init(void)
1368 +{
1369 + int r;
1370 +
1371 + printk(KERN_INFO "Retu/Vilma headset driver initializing\n");
1372 +
1373 + r = platform_driver_register(&retu_headset_driver);
1374 + if (r < 0)
1375 + return r;
1376 +
1377 + return 0;
1378 +}
1379 +
1380 +static void __exit retu_headset_exit(void)
1381 +{
1382 + platform_driver_unregister(&retu_headset_driver);
1383 +}
1384 +
1385 +module_init(retu_headset_init);
1386 +module_exit(retu_headset_exit);
1387 +
1388 +MODULE_DESCRIPTION("Retu/Vilma headset detection");
1389 +MODULE_LICENSE("GPL");
1390 +MODULE_AUTHOR("Juha Yrjölä");
1391 --- /dev/null
1392 +++ linux-2.6.35/drivers/cbus/retu-pwrbutton.c
1393 @@ -0,0 +1,118 @@
1394 +/**
1395 + * drivers/cbus/retu-pwrbutton.c
1396 + *
1397 + * Driver for sending retu power button event to input-layer
1398 + *
1399 + * Copyright (C) 2004 Nokia Corporation
1400 + *
1401 + * Written by Ari Saastamoinen <ari.saastamoinen@elektrobit.com>
1402 + *
1403 + * Contact Juha Yrjölä <juha.yrjola@nokia.com>
1404 + *
1405 + * This file is subject to the terms and conditions of the GNU General
1406 + * Public License. See the file "COPYING" in the main directory of this
1407 + * archive for more details.
1408 + *
1409 + * This program is distributed in the hope that it will be useful,
1410 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1411 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1412 + * GNU General Public License for more details.
1413 + *
1414 + * You should have received a copy of the GNU General Public License
1415 + * along with this program; if not, write to the Free Software
1416 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1417 + */
1418 +
1419 +#include <linux/module.h>
1420 +#include <linux/init.h>
1421 +#include <linux/kernel.h>
1422 +#include <linux/errno.h>
1423 +#include <linux/input.h>
1424 +#include <linux/timer.h>
1425 +#include <linux/jiffies.h>
1426 +#include <linux/bitops.h>
1427 +
1428 +#include "retu.h"
1429 +
1430 +#define RETU_STATUS_PWRONX (1 << 5)
1431 +
1432 +#define PWRBTN_DELAY 20
1433 +#define PWRBTN_UP 0
1434 +#define PWRBTN_PRESSED 1
1435 +
1436 +static int pwrbtn_state;
1437 +static struct input_dev *pwrbtn_dev;
1438 +static struct timer_list pwrbtn_timer;
1439 +
1440 +static void retubutton_timer_func(unsigned long arg)
1441 +{
1442 + int state;
1443 +
1444 + if (retu_read_reg(RETU_REG_STATUS) & RETU_STATUS_PWRONX)
1445 + state = PWRBTN_UP;
1446 + else
1447 + state = PWRBTN_PRESSED;
1448 +
1449 + if (pwrbtn_state != state) {
1450 + input_report_key(pwrbtn_dev, KEY_POWER, state);
1451 + pwrbtn_state = state;
1452 + }
1453 +}
1454 +
1455 +/**
1456 + * Interrupt function is called whenever power button key is pressed
1457 + * or released.
1458 + */
1459 +static void retubutton_irq(unsigned long arg)
1460 +{
1461 + retu_ack_irq(RETU_INT_PWR);
1462 + mod_timer(&pwrbtn_timer, jiffies + msecs_to_jiffies(PWRBTN_DELAY));
1463 +}
1464 +
1465 +/**
1466 + * Init function.
1467 + * Allocates interrupt for power button and registers itself to input layer.
1468 + */
1469 +static int __init retubutton_init(void)
1470 +{
1471 + int irq;
1472 +
1473 + printk(KERN_INFO "Retu power button driver initialized\n");
1474 + irq = RETU_INT_PWR;
1475 +
1476 + init_timer(&pwrbtn_timer);
1477 + pwrbtn_timer.function = retubutton_timer_func;
1478 +
1479 + if (retu_request_irq(irq, &retubutton_irq, 0, "PwrOnX") < 0) {
1480 + printk(KERN_ERR "%s@%s: Cannot allocate irq\n",
1481 + __FUNCTION__, __FILE__);
1482 + return -EBUSY;
1483 + }
1484 +
1485 + pwrbtn_dev = input_allocate_device();
1486 + if (!pwrbtn_dev)
1487 + return -ENOMEM;
1488 +
1489 + pwrbtn_dev->evbit[0] = BIT_MASK(EV_KEY);
1490 + pwrbtn_dev->keybit[BIT_WORD(KEY_POWER)] = BIT_MASK(KEY_POWER);
1491 + pwrbtn_dev->name = "retu-pwrbutton";
1492 +
1493 + return input_register_device(pwrbtn_dev);
1494 +}
1495 +
1496 +/**
1497 + * Cleanup function which is called when driver is unloaded
1498 + */
1499 +static void __exit retubutton_exit(void)
1500 +{
1501 + retu_free_irq(RETU_INT_PWR);
1502 + del_timer_sync(&pwrbtn_timer);
1503 + input_unregister_device(pwrbtn_dev);
1504 +}
1505 +
1506 +module_init(retubutton_init);
1507 +module_exit(retubutton_exit);
1508 +
1509 +MODULE_DESCRIPTION("Retu Power Button");
1510 +MODULE_LICENSE("GPL");
1511 +MODULE_AUTHOR("Ari Saastamoinen");
1512 --- /dev/null
1513 +++ linux-2.6.35/drivers/cbus/retu-rtc.c
1514 @@ -0,0 +1,477 @@
1515 +/**
1516 + * drivers/cbus/retu-rtc.c
1517 + *
1518 + * Support for Retu RTC
1519 + *
1520 + * Copyright (C) 2004, 2005 Nokia Corporation
1521 + *
1522 + * Written by Paul Mundt <paul.mundt@nokia.com> and
1523 + * Igor Stoppa <igor.stoppa@nokia.com>
1524 + *
1525 + * The Retu RTC is essentially a partial read-only RTC that gives us Retu's
1526 + * idea of what time actually is. It's left as a userspace excercise to map
1527 + * this back to time in the real world and ensure that calibration settings
1528 + * are sane to compensate for any horrible drift (on account of not being able
1529 + * to set the clock to anything).
1530 + *
1531 + * Days are semi-writeable. Namely, Retu will only track 255 days for us
1532 + * consecutively, after which the counter is explicitly stuck at 255 until
1533 + * someone comes along and clears it with a write. In the event that no one
1534 + * comes along and clears it, we no longer have any idea what day it is.
1535 + *
1536 + * This file is subject to the terms and conditions of the GNU General
1537 + * Public License. See the file "COPYING" in the main directory of this
1538 + * archive for more details.
1539 + *
1540 + * This program is distributed in the hope that it will be useful,
1541 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1542 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1543 + * GNU General Public License for more details.
1544 + *
1545 + * You should have received a copy of the GNU General Public License
1546 + * along with this program; if not, write to the Free Software
1547 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1548 + */
1549 +
1550 +#include <linux/device.h>
1551 +#include <linux/init.h>
1552 +#include <linux/kernel.h>
1553 +#include <linux/module.h>
1554 +#include <linux/completion.h>
1555 +#include <linux/platform_device.h>
1556 +#include <linux/mutex.h>
1557 +#include <linux/workqueue.h>
1558 +
1559 +#include "cbus.h"
1560 +#include "retu.h"
1561 +
1562 +static struct mutex retu_rtc_mutex;
1563 +static u16 retu_rtc_alarm_expired;
1564 +static u16 retu_rtc_reset_occurred;
1565 +
1566 +static DECLARE_COMPLETION(retu_rtc_exited);
1567 +static DECLARE_COMPLETION(retu_rtc_sync);
1568 +
1569 +static void retu_rtc_barrier(void);
1570 +
1571 +static void retu_rtc_device_release(struct device *dev)
1572 +{
1573 + complete(&retu_rtc_exited);
1574 +}
1575 +
1576 +static ssize_t retu_rtc_time_show(struct device *dev, struct device_attribute *attr,
1577 + char *buf)
1578 +{
1579 + u16 dsr, hmr, dsr2;
1580 +
1581 + mutex_lock(&retu_rtc_mutex);
1582 +
1583 + do {
1584 + u16 dummy;
1585 +
1586 + /*
1587 + * Not being in_interrupt() for a retu rtc IRQ, we need to
1588 + * read twice for consistency..
1589 + */
1590 + dummy = retu_read_reg(RETU_REG_RTCDSR);
1591 + dsr = retu_read_reg(RETU_REG_RTCDSR);
1592 +
1593 + dummy = retu_read_reg(RETU_REG_RTCHMR);
1594 + hmr = retu_read_reg(RETU_REG_RTCHMR);
1595 +
1596 + dummy = retu_read_reg(RETU_REG_RTCDSR);
1597 + dsr2 = retu_read_reg(RETU_REG_RTCDSR);
1598 + } while ((dsr != dsr2));
1599 +
1600 + mutex_unlock(&retu_rtc_mutex);
1601 +
1602 + /*
1603 + * Format a 32-bit date-string for userspace
1604 + *
1605 + * days | hours | minutes | seconds
1606 + *
1607 + * 8 bits for each.
1608 + *
1609 + * This mostly sucks because days and seconds are tracked in RTCDSR
1610 + * while hours and minutes are tracked in RTCHMR. And yes, there
1611 + * really are no words that can describe an 8 bit day register (or
1612 + * rather, none that will be reprinted here).
1613 + */
1614 + return sprintf(buf, "0x%08x\n", (((dsr >> 8) & 0xff) << 24) |
1615 + (((hmr >> 8) & 0x1f) << 16) |
1616 + ((hmr & 0x3f) << 8) | (dsr & 0x3f));
1617 +}
1618 +
1619 +static ssize_t retu_rtc_time_store(struct device *dev, struct device_attribute *attr,
1620 + const char *buf, size_t count)
1621 +{
1622 + mutex_lock(&retu_rtc_mutex);
1623 + /*
1624 + * Writing anything to the day counter forces it to 0
1625 + * The seconds counter would be cleared by resetting the minutes counter,
1626 + * however this won't happen, since we are using the hh:mm counters as
1627 + * a set of free running counters and the day counter as a multiple
1628 + * overflow holder.
1629 + */
1630 +
1631 + /* Reset day counter, but keep Temperature Shutdown state */
1632 + retu_write_reg(RETU_REG_RTCDSR,
1633 + retu_read_reg(RETU_REG_RTCDSR) & (1 << 6));
1634 +
1635 + mutex_unlock(&retu_rtc_mutex);
1636 +
1637 + return count;
1638 +}
1639 +
1640 +static DEVICE_ATTR(time, S_IRUGO | S_IWUSR, retu_rtc_time_show,
1641 + retu_rtc_time_store);
1642 +
1643 +
1644 +static ssize_t retu_rtc_reset_show(struct device *dev, struct device_attribute *attr, char *buf)
1645 +{
1646 + /*
1647 + * Returns the status of the rtc
1648 + *
1649 + * 0: no reset has occurred or the status has been cleared
1650 + * 1: a reset has occurred
1651 + *
1652 + * RTC needs to be reset only when both main battery
1653 + * _AND_ backup battery are discharged
1654 + */
1655 + return sprintf(buf, "%u\n", retu_rtc_reset_occurred);
1656 +}
1657 +
1658 +static void retu_rtc_do_reset(void)
1659 +{
1660 + u16 ccr1;
1661 +
1662 + ccr1 = retu_read_reg(RETU_REG_CC1);
1663 + /* RTC in reset */
1664 + retu_write_reg(RETU_REG_CC1, ccr1 | 0x0001);
1665 + /* RTC in normal operating mode */
1666 + retu_write_reg(RETU_REG_CC1, ccr1 & ~0x0001);
1667 +
1668 + retu_rtc_barrier();
1669 + /* Disable alarm and RTC WD */
1670 + retu_write_reg(RETU_REG_RTCHMAR, 0x7f3f);
1671 + /* Set Calibration register to default value */
1672 + retu_write_reg(RETU_REG_RTCCALR, 0x00c0);
1673 +
1674 + retu_rtc_alarm_expired = 0;
1675 + retu_rtc_reset_occurred = 1;
1676 +}
1677 +
1678 +static ssize_t retu_rtc_reset_store(struct device *dev, struct device_attribute *attr,
1679 + const char *buf, size_t count)
1680 +{
1681 + unsigned choice;
1682 +
1683 + if(sscanf(buf, "%u", &choice) != 1)
1684 + return count;
1685 + mutex_lock(&retu_rtc_mutex);
1686 + if (choice == 0)
1687 + retu_rtc_reset_occurred = 0;
1688 + else if (choice == 1)
1689 + retu_rtc_do_reset();
1690 + mutex_unlock(&retu_rtc_mutex);
1691 + return count;
1692 +}
1693 +
1694 +static DEVICE_ATTR(reset, S_IRUGO | S_IWUSR, retu_rtc_reset_show,
1695 + retu_rtc_reset_store);
1696 +
1697 +static ssize_t retu_rtc_alarm_show(struct device *dev, struct device_attribute *attr,
1698 + char *buf)
1699 +{
1700 + u16 chmar;
1701 + ssize_t retval;
1702 +
1703 + mutex_lock(&retu_rtc_mutex);
1704 + /*
1705 + * Format a 16-bit date-string for userspace
1706 + *
1707 + * hours | minutes
1708 + * 8 bits for each.
1709 + */
1710 + chmar = retu_read_reg(RETU_REG_RTCHMAR);
1711 + /* No shifting needed, only masking unrelated bits */
1712 + retval = sprintf(buf, "0x%04x\n", chmar & 0x1f3f);
1713 + mutex_unlock(&retu_rtc_mutex);
1714 +
1715 + return retval;
1716 +}
1717 +
1718 +static ssize_t retu_rtc_alarm_store(struct device *dev, struct device_attribute *attr,
1719 + const char *buf, size_t count)
1720 +{
1721 + u16 chmar;
1722 + unsigned alrm;
1723 + unsigned hours;
1724 + unsigned minutes;
1725 +
1726 + mutex_lock(&retu_rtc_mutex);
1727 +
1728 + if(sscanf(buf, "%x", &alrm) != 1)
1729 + return count;
1730 + hours = (alrm >> 8) & 0x001f;
1731 + minutes = (alrm >> 0) & 0x003f;
1732 + if ((hours < 24 && minutes < 60) || (hours == 24 && minutes == 60)) {
1733 + /*
1734 + * OK, the time format for the alarm is valid (including the
1735 + * disabling values)
1736 + */
1737 + /* Keeps the RTC watchdog status */
1738 + chmar = retu_read_reg(RETU_REG_RTCHMAR) & 0x6000;
1739 + chmar |= alrm & 0x1f3f; /* Stores the requested alarm */
1740 + retu_rtc_barrier();
1741 + retu_write_reg(RETU_REG_RTCHMAR, chmar);
1742 + /* If the alarm is being disabled */
1743 + if (hours == 24 && minutes == 60) {
1744 + /* disable the interrupt */
1745 + retu_disable_irq(RETU_INT_RTCA);
1746 + retu_rtc_alarm_expired = 0;
1747 + } else
1748 + /* enable the interrupt */
1749 + retu_enable_irq(RETU_INT_RTCA);
1750 + }
1751 + mutex_unlock(&retu_rtc_mutex);
1752 +
1753 + return count;
1754 +}
1755 +
1756 +static DEVICE_ATTR(alarm, S_IRUGO | S_IWUSR, retu_rtc_alarm_show,
1757 + retu_rtc_alarm_store);
1758 +
1759 +static ssize_t retu_rtc_alarm_expired_show(struct device *dev, struct device_attribute *attr,
1760 + char *buf)
1761 +{
1762 + ssize_t retval;
1763 +
1764 + retval = sprintf(buf, "%u\n", retu_rtc_alarm_expired);
1765 +
1766 + return retval;
1767 +}
1768 +
1769 +static ssize_t retu_rtc_alarm_expired_store(struct device *dev, struct device_attribute *attr,
1770 + const char *buf, size_t count)
1771 +{
1772 + retu_rtc_alarm_expired = 0;
1773 +
1774 + return count;
1775 +}
1776 +
1777 +static DEVICE_ATTR(alarm_expired, S_IRUGO | S_IWUSR, retu_rtc_alarm_expired_show,
1778 + retu_rtc_alarm_expired_store);
1779 +
1780 +
1781 +static ssize_t retu_rtc_cal_show(struct device *dev, struct device_attribute *attr,
1782 + char *buf)
1783 +{
1784 + u16 rtccalr1;
1785 +
1786 + mutex_lock(&retu_rtc_mutex);
1787 + rtccalr1 = retu_read_reg(RETU_REG_RTCCALR);
1788 + mutex_unlock(&retu_rtc_mutex);
1789 +
1790 + /*
1791 + * Shows the status of the Calibration Register.
1792 + *
1793 + * Default, after power loss: 0x0000
1794 + * Default, for R&D: 0x00C0
1795 + * Default, for factory: 0x00??
1796 + *
1797 + */
1798 + return sprintf(buf, "0x%04x\n", rtccalr1 & 0x00ff);
1799 +}
1800 +
1801 +static ssize_t retu_rtc_cal_store(struct device *dev, struct device_attribute *attr,
1802 + const char *buf, size_t count)
1803 +{
1804 + unsigned calibration_value;
1805 +
1806 + if (sscanf(buf, "%x", &calibration_value) != 1)
1807 + return count;
1808 +
1809 + mutex_lock(&retu_rtc_mutex);
1810 + retu_rtc_barrier();
1811 + retu_write_reg(RETU_REG_RTCCALR, calibration_value & 0x00ff);
1812 + mutex_unlock(&retu_rtc_mutex);
1813 +
1814 + return count;
1815 +}
1816 +
1817 +static DEVICE_ATTR(cal, S_IRUGO | S_IWUSR, retu_rtc_cal_show,
1818 + retu_rtc_cal_store);
1819 +
1820 +static struct platform_device retu_rtc_device;
1821 +
1822 +static void retu_rtca_disable(void)
1823 +{
1824 + retu_disable_irq(RETU_INT_RTCA);
1825 + retu_rtc_alarm_expired = 1;
1826 + retu_rtc_barrier();
1827 + retu_write_reg(RETU_REG_RTCHMAR, (24 << 8) | 60);
1828 +}
1829 +
1830 +static void retu_rtca_expired(struct work_struct *unused)
1831 +{
1832 + retu_rtca_disable();
1833 + sysfs_notify(&retu_rtc_device.dev.kobj, NULL, "alarm_expired");
1834 +}
1835 +
1836 +DECLARE_WORK(retu_rtca_work, retu_rtca_expired);
1837 +
1838 +/*
1839 + * RTCHMR RTCHMAR RTCCAL must be accessed within 0.9 s since the seconds
1840 + * interrupt has been signaled in the IDR register
1841 + */
1842 +static void retu_rtcs_interrupt(unsigned long unused)
1843 +{
1844 + retu_ack_irq(RETU_INT_RTCS);
1845 + complete_all(&retu_rtc_sync);
1846 +}
1847 +
1848 +static void retu_rtca_interrupt(unsigned long unused)
1849 +{
1850 + retu_ack_irq(RETU_INT_RTCA);
1851 + schedule_work(&retu_rtca_work);
1852 +}
1853 +
1854 +static int retu_rtc_init_irq(void)
1855 +{
1856 + int ret;
1857 +
1858 + ret = retu_request_irq(RETU_INT_RTCS, retu_rtcs_interrupt, 0, "RTCS");
1859 + if (ret != 0)
1860 + return ret;
1861 + /*
1862 + * We will take care of enabling and disabling the interrupt
1863 + * elsewhere, so leave it off by default..
1864 + */
1865 + retu_disable_irq(RETU_INT_RTCS);
1866 +
1867 + ret = retu_request_irq(RETU_INT_RTCA, retu_rtca_interrupt, 0, "RTCA");
1868 + if (ret != 0) {
1869 + retu_free_irq(RETU_INT_RTCS);
1870 + return ret;
1871 + }
1872 + retu_disable_irq(RETU_INT_RTCA);
1873 +
1874 + return 0;
1875 +}
1876 +
1877 +
1878 +static int __devinit retu_rtc_probe(struct device *dev)
1879 +{
1880 + int r;
1881 +
1882 + retu_rtc_alarm_expired = retu_read_reg(RETU_REG_IDR) &
1883 + (0x1 << RETU_INT_RTCA);
1884 +
1885 + if ((r = retu_rtc_init_irq()) != 0)
1886 + return r;
1887 +
1888 + mutex_init(&retu_rtc_mutex);
1889 +
1890 + /* If the calibration register is zero, we've probably lost
1891 + * power */
1892 + if (retu_read_reg(RETU_REG_RTCCALR) & 0x00ff)
1893 + retu_rtc_reset_occurred = 0;
1894 + else
1895 + retu_rtc_do_reset();
1896 +
1897 + if ((r = device_create_file(dev, &dev_attr_time)) != 0)
1898 + return r;
1899 + else if ((r = device_create_file(dev, &dev_attr_reset)) != 0)
1900 + goto err_unregister_time;
1901 + else if ((r = device_create_file(dev, &dev_attr_alarm)) != 0)
1902 + goto err_unregister_reset;
1903 + else if ((r = device_create_file(dev, &dev_attr_alarm_expired)) != 0)
1904 + goto err_unregister_alarm;
1905 + else if ((r = device_create_file(dev, &dev_attr_cal)) != 0)
1906 + goto err_unregister_alarm_expired;
1907 + else
1908 + return r;
1909 +
1910 +err_unregister_alarm_expired:
1911 + device_remove_file(dev, &dev_attr_alarm_expired);
1912 +err_unregister_alarm:
1913 + device_remove_file(dev, &dev_attr_alarm);
1914 +err_unregister_reset:
1915 + device_remove_file(dev, &dev_attr_reset);
1916 +err_unregister_time:
1917 + device_remove_file(dev, &dev_attr_time);
1918 + return r;
1919 +}
1920 +
1921 +static int __devexit retu_rtc_remove(struct device *dev)
1922 +{
1923 + retu_disable_irq(RETU_INT_RTCS);
1924 + retu_free_irq(RETU_INT_RTCS);
1925 + retu_free_irq(RETU_INT_RTCA);
1926 + device_remove_file(dev, &dev_attr_cal);
1927 + device_remove_file(dev, &dev_attr_alarm_expired);
1928 + device_remove_file(dev, &dev_attr_alarm);
1929 + device_remove_file(dev, &dev_attr_reset);
1930 + device_remove_file(dev, &dev_attr_time);
1931 + return 0;
1932 +}
1933 +
1934 +static struct device_driver retu_rtc_driver = {
1935 + .name = "retu-rtc",
1936 + .bus = &platform_bus_type,
1937 + .probe = retu_rtc_probe,
1938 + .remove = __devexit_p(retu_rtc_remove),
1939 +};
1940 +
1941 +static struct platform_device retu_rtc_device = {
1942 + .name = "retu-rtc",
1943 + .id = -1,
1944 + .dev = {
1945 + .release = retu_rtc_device_release,
1946 + },
1947 +};
1948 +
1949 +/* This function provides syncronization with the RTCS interrupt handler */
1950 +static void retu_rtc_barrier(void)
1951 +{
1952 + INIT_COMPLETION(retu_rtc_sync);
1953 + retu_ack_irq(RETU_INT_RTCS);
1954 + retu_enable_irq(RETU_INT_RTCS);
1955 + wait_for_completion(&retu_rtc_sync);
1956 + retu_disable_irq(RETU_INT_RTCS);
1957 +}
1958 +
1959 +static int __init retu_rtc_init(void)
1960 +{
1961 + int ret;
1962 +
1963 + init_completion(&retu_rtc_exited);
1964 +
1965 + if ((ret = driver_register(&retu_rtc_driver)) != 0)
1966 + return ret;
1967 +
1968 + if ((ret = platform_device_register(&retu_rtc_device)) != 0)
1969 + goto err_unregister_driver;
1970 +
1971 + return 0;
1972 +
1973 +err_unregister_driver:
1974 + driver_unregister(&retu_rtc_driver);
1975 + return ret;
1976 +}
1977 +
1978 +static void __exit retu_rtc_exit(void)
1979 +{
1980 + platform_device_unregister(&retu_rtc_device);
1981 + driver_unregister(&retu_rtc_driver);
1982 +
1983 + wait_for_completion(&retu_rtc_exited);
1984 +}
1985 +
1986 +module_init(retu_rtc_init);
1987 +module_exit(retu_rtc_exit);
1988 +
1989 +MODULE_DESCRIPTION("Retu RTC");
1990 +MODULE_LICENSE("GPL");
1991 +MODULE_AUTHOR("Paul Mundt and Igor Stoppa");
1992 --- /dev/null
1993 +++ linux-2.6.35/drivers/cbus/retu-user.c
1994 @@ -0,0 +1,425 @@
1995 +/**
1996 + * drivers/cbus/retu-user.c
1997 + *
1998 + * Retu user space interface functions
1999 + *
2000 + * Copyright (C) 2004, 2005 Nokia Corporation
2001 + *
2002 + * Written by Mikko Ylinen <mikko.k.ylinen@nokia.com>
2003 + *
2004 + * This file is subject to the terms and conditions of the GNU General
2005 + * Public License. See the file "COPYING" in the main directory of this
2006 + * archive for more details.
2007 + *
2008 + * This program is distributed in the hope that it will be useful,
2009 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2010 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2011 + * GNU General Public License for more details.
2012 + *
2013 + * You should have received a copy of the GNU General Public License
2014 + * along with this program; if not, write to the Free Software
2015 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2016 + */
2017 +
2018 +#include <linux/types.h>
2019 +#include <linux/kernel.h>
2020 +#include <linux/interrupt.h>
2021 +#include <linux/module.h>
2022 +#include <linux/init.h>
2023 +#include <linux/fs.h>
2024 +#include <linux/miscdevice.h>
2025 +#include <linux/poll.h>
2026 +#include <linux/list.h>
2027 +#include <linux/spinlock.h>
2028 +#include <linux/sched.h>
2029 +#include <linux/mutex.h>
2030 +#include <linux/slab.h>
2031 +
2032 +#include <asm/uaccess.h>
2033 +
2034 +#include "retu.h"
2035 +
2036 +#include "user_retu_tahvo.h"
2037 +
2038 +/* Maximum size of IRQ node buffer/pool */
2039 +#define RETU_MAX_IRQ_BUF_LEN 16
2040 +
2041 +#define PFX "retu-user: "
2042 +
2043 +/* Bitmap for marking the interrupt sources as having the handlers */
2044 +static u32 retu_irq_bits;
2045 +
2046 +/* For allowing only one user process to subscribe to the retu interrupts */
2047 +static struct file *retu_irq_subscr = NULL;
2048 +
2049 +/* For poll and IRQ passing */
2050 +struct retu_irq {
2051 + u32 id;
2052 + struct list_head node;
2053 +};
2054 +
2055 +static spinlock_t retu_irqs_lock;
2056 +static struct retu_irq *retu_irq_block;
2057 +static LIST_HEAD(retu_irqs);
2058 +static LIST_HEAD(retu_irqs_reserve);
2059 +
2060 +/* Wait queue - used when user wants to read the device */
2061 +DECLARE_WAIT_QUEUE_HEAD(retu_user_waitqueue);
2062 +
2063 +/* Semaphore to protect irq subscription sequence */
2064 +static struct mutex retu_mutex;
2065 +
2066 +/* This array specifies RETU register types (read/write/toggle) */
2067 +static const u8 retu_access_bits[] = {
2068 + 1,
2069 + 4,
2070 + 3,
2071 + 3,
2072 + 1,
2073 + 3,
2074 + 3,
2075 + 0,
2076 + 3,
2077 + 3,
2078 + 3,
2079 + 3,
2080 + 3,
2081 + 3,
2082 + 3,
2083 + 4,
2084 + 4,
2085 + 3,
2086 + 0,
2087 + 0,
2088 + 0,
2089 + 0,
2090 + 1,
2091 + 3,
2092 + 3,
2093 + 3,
2094 + 3,
2095 + 3,
2096 + 3,
2097 + 3,
2098 + 3,
2099 + 3
2100 +};
2101 +
2102 +/*
2103 + * The handler for all RETU interrupts.
2104 + *
2105 + * arg is the interrupt source in RETU.
2106 + */
2107 +static void retu_user_irq_handler(unsigned long arg)
2108 +{
2109 + struct retu_irq *irq;
2110 +
2111 + retu_ack_irq(arg);
2112 +
2113 + spin_lock(&retu_irqs_lock);
2114 + if (list_empty(&retu_irqs_reserve)) {
2115 + spin_unlock(&retu_irqs_lock);
2116 + return;
2117 + }
2118 + irq = list_entry((&retu_irqs_reserve)->next, struct retu_irq, node);
2119 + irq->id = arg;
2120 + list_move_tail(&irq->node, &retu_irqs);
2121 + spin_unlock(&retu_irqs_lock);
2122 +
2123 + /* wake up waiting thread */
2124 + wake_up(&retu_user_waitqueue);
2125 +}
2126 +
2127 +/*
2128 + * This routine sets up the interrupt handler and marks an interrupt source
2129 + * in RETU as a candidate for signal delivery to the user process.
2130 + */
2131 +static int retu_user_subscribe_to_irq(int id, struct file *filp)
2132 +{
2133 + int ret;
2134 +
2135 + mutex_lock(&retu_mutex);
2136 + if ((retu_irq_subscr != NULL) && (retu_irq_subscr != filp)) {
2137 + mutex_unlock(&retu_mutex);
2138 + return -EBUSY;
2139 + }
2140 + /* Store the file pointer of the first user process registering IRQs */
2141 + retu_irq_subscr = filp;
2142 + mutex_unlock(&retu_mutex);
2143 +
2144 + if (retu_irq_bits & (1 << id))
2145 + return 0;
2146 +
2147 + ret = retu_request_irq(id, retu_user_irq_handler, id, "");
2148 + if (ret < 0)
2149 + return ret;
2150 +
2151 + /* Mark that this interrupt has a handler */
2152 + retu_irq_bits |= 1 << id;
2153 +
2154 + return 0;
2155 +}
2156 +
2157 +/*
2158 + * Unregisters all RETU interrupt handlers.
2159 + */
2160 +static void retu_unreg_irq_handlers(void)
2161 +{
2162 + int id;
2163 +
2164 + if (!retu_irq_bits)
2165 + return;
2166 +
2167 + for (id = 0; id < MAX_RETU_IRQ_HANDLERS; id++)
2168 + if (retu_irq_bits & (1 << id))
2169 + retu_free_irq(id);
2170 +
2171 + retu_irq_bits = 0;
2172 +}
2173 +
2174 +/*
2175 + * Write to RETU register.
2176 + * Returns 0 upon success, a negative error value otherwise.
2177 + */
2178 +static int retu_user_write_with_mask(u32 field, u16 value)
2179 +{
2180 + u32 mask;
2181 + u32 reg;
2182 + u_short tmp;
2183 + unsigned long flags;
2184 +
2185 + mask = MASK(field);
2186 + reg = REG(field);
2187 +
2188 + /* Detect bad mask and reg */
2189 + if (mask == 0 || reg > RETU_REG_MAX ||
2190 + retu_access_bits[reg] == READ_ONLY) {
2191 + printk(KERN_ERR PFX "invalid arguments (reg=%#x, mask=%#x)\n",
2192 + reg, mask);
2193 + return -EINVAL;
2194 + }
2195 +
2196 + /* Justify value according to mask */
2197 + while (!(mask & 1)) {
2198 + value = value << 1;
2199 + mask = mask >> 1;
2200 + }
2201 +
2202 + spin_lock_irqsave(&retu_lock, flags);
2203 + if (retu_access_bits[reg] == TOGGLE) {
2204 + /* No need to detect previous content of register */
2205 + tmp = 0;
2206 + } else {
2207 + /* Read current value of register */
2208 + tmp = retu_read_reg(reg);
2209 + }
2210 +
2211 + /* Generate new value */
2212 + tmp = (tmp & ~MASK(field)) | (value & MASK(field));
2213 + /* Write data to RETU */
2214 + retu_write_reg(reg, tmp);
2215 + spin_unlock_irqrestore(&retu_lock, flags);
2216 +
2217 + return 0;
2218 +}
2219 +
2220 +/*
2221 + * Read RETU register.
2222 + */
2223 +static u32 retu_user_read_with_mask(u32 field)
2224 +{
2225 + u_short value;
2226 + u32 mask, reg;
2227 +
2228 + mask = MASK(field);
2229 + reg = REG(field);
2230 +
2231 + /* Detect bad mask and reg */
2232 + if (mask == 0 || reg > RETU_REG_MAX) {
2233 + printk(KERN_ERR PFX "invalid arguments (reg=%#x, mask=%#x)\n",
2234 + reg, mask);
2235 + return -EINVAL;
2236 + }
2237 +
2238 + /* Read the register */
2239 + value = retu_read_reg(reg) & mask;
2240 +
2241 + /* Right justify value */
2242 + while (!(mask & 1)) {
2243 + value = value >> 1;
2244 + mask = mask >> 1;
2245 + }
2246 +
2247 + return value;
2248 +}
2249 +
2250 +/*
2251 + * Close device
2252 + */
2253 +static int retu_close(struct inode *inode, struct file *filp)
2254 +{
2255 + /* Unregister all interrupts that have been registered */
2256 + if (retu_irq_subscr == filp) {
2257 + retu_unreg_irq_handlers();
2258 + retu_irq_subscr = NULL;
2259 + }
2260 +
2261 + return 0;
2262 +}
2263 +
2264 +/*
2265 + * Device control (ioctl)
2266 + */
2267 +static int retu_ioctl(struct inode *inode, struct file *filp,
2268 + unsigned int cmd, unsigned long arg)
2269 +{
2270 + struct retu_tahvo_write_parms par;
2271 + int ret;
2272 +
2273 + switch (cmd) {
2274 + case URT_IOCT_IRQ_SUBSCR:
2275 + return retu_user_subscribe_to_irq(arg, filp);
2276 + case RETU_IOCH_READ:
2277 + return retu_user_read_with_mask(arg);
2278 + case RETU_IOCX_WRITE:
2279 + ret = copy_from_user(&par, (void __user *) arg, sizeof(par));
2280 + if (ret)
2281 + printk(KERN_ERR "copy_from_user failed: %d\n", ret);
2282 + par.result = retu_user_write_with_mask(par.field, par.value);
2283 + ret = copy_to_user((void __user *) arg, &par, sizeof(par));
2284 + if (ret)
2285 + printk(KERN_ERR "copy_to_user failed: %d\n", ret);
2286 + break;
2287 + case RETU_IOCH_ADC_READ:
2288 + return retu_read_adc(arg);
2289 + default:
2290 + return -ENOIOCTLCMD;
2291 + }
2292 + return 0;
2293 +}
2294 +
2295 +/*
2296 + * Read from device
2297 + */
2298 +static ssize_t retu_read(struct file *filp, char *buf, size_t count,
2299 + loff_t * offp)
2300 +{
2301 + struct retu_irq *irq;
2302 +
2303 + u32 nr, i;
2304 +
2305 + /* read not permitted if neither filp nor anyone has registered IRQs */
2306 + if (retu_irq_subscr != filp)
2307 + return -EPERM;
2308 +
2309 + if ((count < sizeof(u32)) || ((count % sizeof(u32)) != 0))
2310 + return -EINVAL;
2311 +
2312 + nr = count / sizeof(u32);
2313 +
2314 + for (i = 0; i < nr; i++) {
2315 + unsigned long flags;
2316 + u32 irq_id;
2317 + int ret;
2318 +
2319 + ret = wait_event_interruptible(retu_user_waitqueue,
2320 + !list_empty(&retu_irqs));
2321 + if (ret < 0)
2322 + return ret;
2323 +
2324 + spin_lock_irqsave(&retu_irqs_lock, flags);
2325 + irq = list_entry((&retu_irqs)->next, struct retu_irq, node);
2326 + irq_id = irq->id;
2327 + list_move(&irq->node, &retu_irqs_reserve);
2328 + spin_unlock_irqrestore(&retu_irqs_lock, flags);
2329 +
2330 + ret = copy_to_user(buf + i * sizeof(irq_id), &irq_id,
2331 + sizeof(irq_id));
2332 + if (ret)
2333 + printk(KERN_ERR "copy_to_user failed: %d\n", ret);
2334 + }
2335 +
2336 + return count;
2337 +}
2338 +
2339 +/*
2340 + * Poll method
2341 + */
2342 +static unsigned retu_poll(struct file *filp, struct poll_table_struct *pt)
2343 +{
2344 + if (!list_empty(&retu_irqs))
2345 + return POLLIN;
2346 +
2347 + poll_wait(filp, &retu_user_waitqueue, pt);
2348 +
2349 + if (!list_empty(&retu_irqs))
2350 + return POLLIN;
2351 + else
2352 + return 0;
2353 +}
2354 +
2355 +static struct file_operations retu_user_fileops = {
2356 + .owner = THIS_MODULE,
2357 + .ioctl = retu_ioctl,
2358 + .read = retu_read,
2359 + .release = retu_close,
2360 + .poll = retu_poll
2361 +};
2362 +
2363 +static struct miscdevice retu_device = {
2364 + .minor = MISC_DYNAMIC_MINOR,
2365 + .name = "retu",
2366 + .fops = &retu_user_fileops
2367 +};
2368 +
2369 +/*
2370 + * Initialization
2371 + *
2372 + * @return 0 if successful, error value otherwise.
2373 + */
2374 +int retu_user_init(void)
2375 +{
2376 + struct retu_irq *irq;
2377 + int res, i;
2378 +
2379 + irq = kmalloc(sizeof(*irq) * RETU_MAX_IRQ_BUF_LEN, GFP_KERNEL);
2380 + if (irq == NULL) {
2381 + printk(KERN_ERR PFX "kmalloc failed\n");
2382 + return -ENOMEM;
2383 + }
2384 + memset(irq, 0, sizeof(*irq) * RETU_MAX_IRQ_BUF_LEN);
2385 + for (i = 0; i < RETU_MAX_IRQ_BUF_LEN; i++)
2386 + list_add(&irq[i].node, &retu_irqs_reserve);
2387 +
2388 + retu_irq_block = irq;
2389 +
2390 + spin_lock_init(&retu_irqs_lock);
2391 + mutex_init(&retu_mutex);
2392 +
2393 + /* Request a misc device */
2394 + res = misc_register(&retu_device);
2395 + if (res < 0) {
2396 + printk(KERN_ERR PFX "unable to register misc device for %s\n",
2397 + retu_device.name);
2398 + kfree(irq);
2399 + return res;
2400 + }
2401 +
2402 + return 0;
2403 +}
2404 +
2405 +/*
2406 + * Cleanup.
2407 + */
2408 +void retu_user_cleanup(void)
2409 +{
2410 + /* Unregister our misc device */
2411 + misc_deregister(&retu_device);
2412 + /* Unregister and disable all RETU interrupts used by this module */
2413 + retu_unreg_irq_handlers();
2414 + kfree(retu_irq_block);
2415 +}
2416 +
2417 +MODULE_DESCRIPTION("Retu ASIC user space functions");
2418 +MODULE_LICENSE("GPL");
2419 +MODULE_AUTHOR("Mikko Ylinen");
2420 --- /dev/null
2421 +++ linux-2.6.35/drivers/cbus/retu-wdt.c
2422 @@ -0,0 +1,388 @@
2423 +/**
2424 + * drivers/cbus/retu-wdt.c
2425 + *
2426 + * Driver for Retu watchdog
2427 + *
2428 + * Copyright (C) 2004, 2005 Nokia Corporation
2429 + *
2430 + * Written by Amit Kucheria <amit.kucheria@nokia.com>
2431 + *
2432 + * This file is subject to the terms and conditions of the GNU General
2433 + * Public License. See the file "COPYING" in the main directory of this
2434 + * archive for more details.
2435 + *
2436 + * This program is distributed in the hope that it will be useful,
2437 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2438 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2439 + * GNU General Public License for more details.
2440 + *
2441 + * You should have received a copy of the GNU General Public License
2442 + * along with this program; if not, write to the Free Software
2443 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2444 + */
2445 +
2446 +#include <linux/kernel.h>
2447 +#include <linux/module.h>
2448 +#include <linux/device.h>
2449 +#include <linux/init.h>
2450 +#include <linux/fs.h>
2451 +#include <linux/io.h>
2452 +#include <linux/platform_device.h>
2453 +#include <linux/slab.h>
2454 +
2455 +#include <linux/completion.h>
2456 +#include <linux/errno.h>
2457 +#include <linux/moduleparam.h>
2458 +#include <linux/platform_device.h>
2459 +#include <linux/miscdevice.h>
2460 +#include <linux/watchdog.h>
2461 +
2462 +#include <asm/uaccess.h>
2463 +
2464 +#include <plat/prcm.h>
2465 +
2466 +#include "cbus.h"
2467 +#include "retu.h"
2468 +
2469 +/* Watchdog timeout in seconds */
2470 +#define RETU_WDT_MIN_TIMER 0
2471 +#define RETU_WDT_DEFAULT_TIMER 32
2472 +#define RETU_WDT_MAX_TIMER 63
2473 +
2474 +static struct completion retu_wdt_completion;
2475 +static DEFINE_MUTEX(retu_wdt_mutex);
2476 +
2477 +/* Current period of watchdog */
2478 +static unsigned int period_val = RETU_WDT_DEFAULT_TIMER;
2479 +static int counter_param = RETU_WDT_MAX_TIMER;
2480 +
2481 +struct retu_wdt_dev {
2482 + struct device *dev;
2483 + int users;
2484 + struct miscdevice retu_wdt_miscdev;
2485 + struct timer_list ping_timer;
2486 +};
2487 +
2488 +static struct retu_wdt_dev *retu_wdt;
2489 +
2490 +static void retu_wdt_set_ping_timer(unsigned long enable);
2491 +
2492 +static int _retu_modify_counter(unsigned int new)
2493 +{
2494 + retu_write_reg(RETU_REG_WATCHDOG, (u16)new);
2495 +
2496 + return 0;
2497 +}
2498 +
2499 +static int retu_modify_counter(unsigned int new)
2500 +{
2501 + if (new < RETU_WDT_MIN_TIMER || new > RETU_WDT_MAX_TIMER)
2502 + return -EINVAL;
2503 +
2504 + mutex_lock(&retu_wdt_mutex);
2505 + period_val = new;
2506 + _retu_modify_counter(period_val);
2507 + mutex_unlock(&retu_wdt_mutex);
2508 +
2509 + return 0;
2510 +}
2511 +
2512 +static ssize_t retu_wdt_period_show(struct device *dev,
2513 + struct device_attribute *attr, char *buf)
2514 +{
2515 + /* Show current max counter */
2516 + return sprintf(buf, "%u\n", (u16)period_val);
2517 +}
2518 +
2519 +/*
2520 + * Note: This inteface is non-standard and likely to disappear!
2521 + * Use /dev/watchdog instead, that's the standard.
2522 + */
2523 +static ssize_t retu_wdt_period_store(struct device *dev,
2524 + struct device_attribute *attr,
2525 + const char *buf, size_t count)
2526 +{
2527 + unsigned int new_period;
2528 + int ret;
2529 +
2530 +#ifdef CONFIG_WATCHDOG_NOWAYOUT
2531 + retu_wdt_set_ping_timer(0);
2532 +#endif
2533 +
2534 + if (sscanf(buf, "%u", &new_period) != 1) {
2535 + printk(KERN_ALERT "retu_wdt_period_store: Invalid input\n");
2536 + return -EINVAL;
2537 + }
2538 +
2539 + ret = retu_modify_counter(new_period);
2540 + if (ret < 0)
2541 + return ret;
2542 +
2543 + return strnlen(buf, count);
2544 +}
2545 +
2546 +static ssize_t retu_wdt_counter_show(struct device *dev,
2547 + struct device_attribute *attr, char *buf)
2548 +{
2549 + u16 counter;
2550 +
2551 + /* Show current value in watchdog counter */
2552 + counter = retu_read_reg(RETU_REG_WATCHDOG);
2553 +
2554 + /* Only the 5 LSB are important */
2555 + return snprintf(buf, PAGE_SIZE, "%u\n", (counter & 0x3F));
2556 +}
2557 +
2558 +static DEVICE_ATTR(period, S_IRUGO | S_IWUSR, retu_wdt_period_show, \
2559 + retu_wdt_period_store);
2560 +static DEVICE_ATTR(counter, S_IRUGO, retu_wdt_counter_show, NULL);
2561 +
2562 +/*----------------------------------------------------------------------------*/
2563 +
2564 +/*
2565 + * Since retu watchdog cannot be disabled in hardware, we must kick it
2566 + * with a timer until userspace watchdog software takes over. Do this
2567 + * unless /dev/watchdog is open or CONFIG_WATCHDOG_NOWAYOUT is set.
2568 + */
2569 +static void retu_wdt_set_ping_timer(unsigned long enable)
2570 +{
2571 + _retu_modify_counter(RETU_WDT_MAX_TIMER);
2572 + if (enable)
2573 + mod_timer(&retu_wdt->ping_timer,
2574 + jiffies + RETU_WDT_DEFAULT_TIMER * HZ);
2575 + else
2576 + del_timer_sync(&retu_wdt->ping_timer);
2577 +}
2578 +
2579 +static int retu_wdt_open(struct inode *inode, struct file *file)
2580 +{
2581 + if (test_and_set_bit(1, (unsigned long *)&(retu_wdt->users)))
2582 + return -EBUSY;
2583 +
2584 + file->private_data = (void *)retu_wdt;
2585 + retu_wdt_set_ping_timer(0);
2586 +
2587 + return nonseekable_open(inode, file);
2588 +}
2589 +
2590 +static int retu_wdt_release(struct inode *inode, struct file *file)
2591 +{
2592 + struct retu_wdt_dev *wdev = file->private_data;
2593 +
2594 +#ifndef CONFIG_WATCHDOG_NOWAYOUT
2595 + retu_wdt_set_ping_timer(1);
2596 +#endif
2597 + wdev->users = 0;
2598 +
2599 + return 0;
2600 +}
2601 +
2602 +static ssize_t retu_wdt_write(struct file *file, const char __user *data,
2603 + size_t len, loff_t *ppos)
2604 +{
2605 + if (len)
2606 + retu_modify_counter(RETU_WDT_MAX_TIMER);
2607 +
2608 + return len;
2609 +}
2610 +
2611 +static int retu_wdt_ioctl(struct inode *inode, struct file *file,
2612 + unsigned int cmd, unsigned long arg)
2613 +{
2614 + int new_margin;
2615 +
2616 + static struct watchdog_info ident = {
2617 + .identity = "Retu Watchdog",
2618 + .options = WDIOF_SETTIMEOUT,
2619 + .firmware_version = 0,
2620 + };
2621 +
2622 + switch (cmd) {
2623 + default:
2624 + return -ENOTTY;
2625 + case WDIOC_GETSUPPORT:
2626 + return copy_to_user((struct watchdog_info __user *)arg, &ident,
2627 + sizeof(ident));
2628 + case WDIOC_GETSTATUS:
2629 + return put_user(0, (int __user *)arg);
2630 + case WDIOC_GETBOOTSTATUS:
2631 + if (cpu_is_omap16xx())
2632 + return put_user(omap_readw(ARM_SYSST),
2633 + (int __user *)arg);
2634 + if (cpu_is_omap24xx())
2635 + return put_user(omap_prcm_get_reset_sources(),
2636 + (int __user *)arg);
2637 + case WDIOC_KEEPALIVE:
2638 + retu_modify_counter(RETU_WDT_MAX_TIMER);
2639 + break;
2640 + case WDIOC_SETTIMEOUT:
2641 + if (get_user(new_margin, (int __user *)arg))
2642 + return -EFAULT;
2643 + retu_modify_counter(new_margin);
2644 + /* Fall through */
2645 + case WDIOC_GETTIMEOUT:
2646 + return put_user(period_val, (int __user *)arg);
2647 + }
2648 +
2649 + return 0;
2650 +}
2651 +
2652 +/* Start kicking retu watchdog until user space starts doing the kicking */
2653 +static int __init retu_wdt_ping(void)
2654 +{
2655 +
2656 +#ifdef CONFIG_WATCHDOG_NOWAYOUT
2657 + retu_modify_counter(RETU_WDT_MAX_TIMER);
2658 +#else
2659 + retu_wdt_set_ping_timer(1);
2660 +#endif
2661 +
2662 + return 0;
2663 +}
2664 +late_initcall(retu_wdt_ping);
2665 +
2666 +static const struct file_operations retu_wdt_fops = {
2667 + .owner = THIS_MODULE,
2668 + .write = retu_wdt_write,
2669 + .ioctl = retu_wdt_ioctl,
2670 + .open = retu_wdt_open,
2671 + .release = retu_wdt_release,
2672 +};
2673 +
2674 +/*----------------------------------------------------------------------------*/
2675 +
2676 +static int __devinit retu_wdt_probe(struct device *dev)
2677 +{
2678 + struct retu_wdt_dev *wdev;
2679 + int ret;
2680 +
2681 + wdev = kzalloc(sizeof(struct retu_wdt_dev), GFP_KERNEL);
2682 + if (!wdev)
2683 + return -ENOMEM;
2684 +
2685 + wdev->users = 0;
2686 +
2687 + ret = device_create_file(dev, &dev_attr_period);
2688 + if (ret) {
2689 + printk(KERN_ERR "retu_wdt_probe: Error creating "
2690 + "sys device file: period\n");
2691 + goto free1;
2692 + }
2693 +
2694 + ret = device_create_file(dev, &dev_attr_counter);
2695 + if (ret) {
2696 + printk(KERN_ERR "retu_wdt_probe: Error creating "
2697 + "sys device file: counter\n");
2698 + goto free2;
2699 + }
2700 +
2701 + dev_set_drvdata(dev, wdev);
2702 + retu_wdt = wdev;
2703 + wdev->retu_wdt_miscdev.parent = dev;
2704 + wdev->retu_wdt_miscdev.minor = WATCHDOG_MINOR;
2705 + wdev->retu_wdt_miscdev.name = "watchdog";
2706 + wdev->retu_wdt_miscdev.fops = &retu_wdt_fops;
2707 +
2708 + ret = misc_register(&(wdev->retu_wdt_miscdev));
2709 + if (ret)
2710 + goto free3;
2711 +
2712 + setup_timer(&wdev->ping_timer, retu_wdt_set_ping_timer, 1);
2713 +
2714 + /* Kick the watchdog for kernel booting to finish */
2715 + retu_modify_counter(RETU_WDT_MAX_TIMER);
2716 +
2717 + return 0;
2718 +
2719 +free3:
2720 + device_remove_file(dev, &dev_attr_counter);
2721 +
2722 +free2:
2723 + device_remove_file(dev, &dev_attr_period);
2724 +free1:
2725 + kfree(wdev);
2726 +
2727 + return ret;
2728 +}
2729 +
2730 +static int __devexit retu_wdt_remove(struct device *dev)
2731 +{
2732 + struct retu_wdt_dev *wdev;
2733 +
2734 + wdev = dev_get_drvdata(dev);
2735 + misc_deregister(&(wdev->retu_wdt_miscdev));
2736 + device_remove_file(dev, &dev_attr_period);
2737 + device_remove_file(dev, &dev_attr_counter);
2738 + kfree(wdev);
2739 +
2740 + return 0;
2741 +}
2742 +
2743 +static void retu_wdt_device_release(struct device *dev)
2744 +{
2745 + complete(&retu_wdt_completion);
2746 +}
2747 +
2748 +static struct platform_device retu_wdt_device = {
2749 + .name = "retu-watchdog",
2750 + .id = -1,
2751 + .dev = {
2752 + .release = retu_wdt_device_release,
2753 + },
2754 +};
2755 +
2756 +static struct device_driver retu_wdt_driver = {
2757 + .name = "retu-watchdog",
2758 + .bus = &platform_bus_type,
2759 + .probe = retu_wdt_probe,
2760 + .remove = __devexit_p(retu_wdt_remove),
2761 +};
2762 +
2763 +static int __init retu_wdt_init(void)
2764 +{
2765 + int ret;
2766 +
2767 + init_completion(&retu_wdt_completion);
2768 +
2769 + ret = driver_register(&retu_wdt_driver);
2770 + if (ret)
2771 + return ret;
2772 +
2773 + ret = platform_device_register(&retu_wdt_device);
2774 + if (ret)
2775 + goto exit1;
2776 +
2777 + /* passed as module parameter? */
2778 + ret = retu_modify_counter(counter_param);
2779 + if (ret == -EINVAL) {
2780 + ret = retu_modify_counter(RETU_WDT_DEFAULT_TIMER);
2781 + printk(KERN_INFO
2782 + "retu_wdt_init: Intializing to default value\n");
2783 + }
2784 +
2785 + printk(KERN_INFO "Retu watchdog driver initialized\n");
2786 + return ret;
2787 +
2788 +exit1:
2789 + driver_unregister(&retu_wdt_driver);
2790 + wait_for_completion(&retu_wdt_completion);
2791 +
2792 + return ret;
2793 +}
2794 +
2795 +static void __exit retu_wdt_exit(void)
2796 +{
2797 + platform_device_unregister(&retu_wdt_device);
2798 + driver_unregister(&retu_wdt_driver);
2799 +
2800 + wait_for_completion(&retu_wdt_completion);
2801 +}
2802 +
2803 +module_init(retu_wdt_init);
2804 +module_exit(retu_wdt_exit);
2805 +module_param(counter_param, int, 0);
2806 +
2807 +MODULE_DESCRIPTION("Retu WatchDog");
2808 +MODULE_AUTHOR("Amit Kucheria");
2809 +MODULE_LICENSE("GPL");
2810 +
2811 --- /dev/null
2812 +++ linux-2.6.35/drivers/cbus/tahvo.c
2813 @@ -0,0 +1,443 @@
2814 +/**
2815 + * drivers/cbus/tahvo.c
2816 + *
2817 + * Support functions for Tahvo ASIC
2818 + *
2819 + * Copyright (C) 2004, 2005 Nokia Corporation
2820 + *
2821 + * Written by Juha Yrjölä <juha.yrjola@nokia.com>,
2822 + * David Weinehall <david.weinehall@nokia.com>, and
2823 + * Mikko Ylinen <mikko.k.ylinen@nokia.com>
2824 + *
2825 + * This file is subject to the terms and conditions of the GNU General
2826 + * Public License. See the file "COPYING" in the main directory of this
2827 + * archive for more details.
2828 + *
2829 + * This program is distributed in the hope that it will be useful,
2830 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2831 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2832 + * GNU General Public License for more details.
2833 + *
2834 + * You should have received a copy of the GNU General Public License
2835 + * along with this program; if not, write to the Free Software
2836 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2837 + */
2838 +
2839 +#include <linux/module.h>
2840 +#include <linux/init.h>
2841 +
2842 +#include <linux/kernel.h>
2843 +#include <linux/errno.h>
2844 +#include <linux/device.h>
2845 +#include <linux/miscdevice.h>
2846 +#include <linux/poll.h>
2847 +#include <linux/fs.h>
2848 +#include <linux/irq.h>
2849 +#include <linux/interrupt.h>
2850 +#include <linux/platform_device.h>
2851 +#include <linux/gpio.h>
2852 +
2853 +#include <asm/uaccess.h>
2854 +#include <asm/mach-types.h>
2855 +
2856 +#include <plat/mux.h>
2857 +#include <plat/board.h>
2858 +
2859 +#include "cbus.h"
2860 +#include "tahvo.h"
2861 +
2862 +#define TAHVO_ID 0x02
2863 +#define PFX "tahvo: "
2864 +
2865 +static int tahvo_initialized;
2866 +static int tahvo_irq_pin;
2867 +static int tahvo_is_betty;
2868 +
2869 +static struct tasklet_struct tahvo_tasklet;
2870 +spinlock_t tahvo_lock = SPIN_LOCK_UNLOCKED;
2871 +
2872 +static struct completion device_release;
2873 +
2874 +struct tahvo_irq_handler_desc {
2875 + int (*func)(unsigned long);
2876 + unsigned long arg;
2877 + char name[8];
2878 +};
2879 +
2880 +static struct tahvo_irq_handler_desc tahvo_irq_handlers[MAX_TAHVO_IRQ_HANDLERS];
2881 +
2882 +/**
2883 + * tahvo_read_reg - Read a value from a register in Tahvo
2884 + * @reg: the register to read from
2885 + *
2886 + * This function returns the contents of the specified register
2887 + */
2888 +int tahvo_read_reg(int reg)
2889 +{
2890 + BUG_ON(!tahvo_initialized);
2891 + return cbus_read_reg(cbus_host, TAHVO_ID, reg);
2892 +}
2893 +
2894 +/**
2895 + * tahvo_write_reg - Write a value to a register in Tahvo
2896 + * @reg: the register to write to
2897 + * @reg: the value to write to the register
2898 + *
2899 + * This function writes a value to the specified register
2900 + */
2901 +void tahvo_write_reg(int reg, u16 val)
2902 +{
2903 + BUG_ON(!tahvo_initialized);
2904 + cbus_write_reg(cbus_host, TAHVO_ID, reg, val);
2905 +}
2906 +
2907 +/**
2908 + * tahvo_set_clear_reg_bits - set and clear register bits atomically
2909 + * @reg: the register to write to
2910 + * @bits: the bits to set
2911 + *
2912 + * This function sets and clears the specified Tahvo register bits atomically
2913 + */
2914 +void tahvo_set_clear_reg_bits(int reg, u16 set, u16 clear)
2915 +{
2916 + unsigned long flags;
2917 + u16 w;
2918 +
2919 + spin_lock_irqsave(&tahvo_lock, flags);
2920 + w = tahvo_read_reg(reg);
2921 + w &= ~clear;
2922 + w |= set;
2923 + tahvo_write_reg(reg, w);
2924 + spin_unlock_irqrestore(&tahvo_lock, flags);
2925 +}
2926 +
2927 +/*
2928 + * Disable given TAHVO interrupt
2929 + */
2930 +void tahvo_disable_irq(int id)
2931 +{
2932 + unsigned long flags;
2933 + u16 mask;
2934 +
2935 + spin_lock_irqsave(&tahvo_lock, flags);
2936 + mask = tahvo_read_reg(TAHVO_REG_IMR);
2937 + mask |= 1 << id;
2938 + tahvo_write_reg(TAHVO_REG_IMR, mask);
2939 + spin_unlock_irqrestore(&tahvo_lock, flags);
2940 +}
2941 +
2942 +/*
2943 + * Enable given TAHVO interrupt
2944 + */
2945 +void tahvo_enable_irq(int id)
2946 +{
2947 + unsigned long flags;
2948 + u16 mask;
2949 +
2950 + spin_lock_irqsave(&tahvo_lock, flags);
2951 + mask = tahvo_read_reg(TAHVO_REG_IMR);
2952 + mask &= ~(1 << id);
2953 + tahvo_write_reg(TAHVO_REG_IMR, mask);
2954 + spin_unlock_irqrestore(&tahvo_lock, flags);
2955 +}
2956 +
2957 +/*
2958 + * Acknowledge given TAHVO interrupt
2959 + */
2960 +void tahvo_ack_irq(int id)
2961 +{
2962 + tahvo_write_reg(TAHVO_REG_IDR, 1 << id);
2963 +}
2964 +
2965 +static int tahvo_7bit_backlight;
2966 +
2967 +int tahvo_get_backlight_level(void)
2968 +{
2969 + int mask;
2970 +
2971 + if (tahvo_7bit_backlight)
2972 + mask = 0x7f;
2973 + else
2974 + mask = 0x0f;
2975 + return tahvo_read_reg(TAHVO_REG_LEDPWMR) & mask;
2976 +}
2977 +
2978 +int tahvo_get_max_backlight_level(void)
2979 +{
2980 + if (tahvo_7bit_backlight)
2981 + return 0x7f;
2982 + else
2983 + return 0x0f;
2984 +}
2985 +
2986 +void tahvo_set_backlight_level(int level)
2987 +{
2988 + int max_level;
2989 +
2990 + max_level = tahvo_get_max_backlight_level();
2991 + if (level > max_level)
2992 + level = max_level;
2993 + tahvo_write_reg(TAHVO_REG_LEDPWMR, level);
2994 +}
2995 +
2996 +/*
2997 + * TAHVO interrupt handler. Only schedules the tasklet.
2998 + */
2999 +static irqreturn_t tahvo_irq_handler(int irq, void *dev_id)
3000 +{
3001 + tasklet_schedule(&tahvo_tasklet);
3002 + return IRQ_HANDLED;
3003 +}
3004 +
3005 +/*
3006 + * Tasklet handler
3007 + */
3008 +static void tahvo_tasklet_handler(unsigned long data)
3009 +{
3010 + struct tahvo_irq_handler_desc *hnd;
3011 + u16 id;
3012 + u16 im;
3013 + int i;
3014 +
3015 + for (;;) {
3016 + id = tahvo_read_reg(TAHVO_REG_IDR);
3017 + im = ~tahvo_read_reg(TAHVO_REG_IMR);
3018 + id &= im;
3019 +
3020 + if (!id)
3021 + break;
3022 +
3023 + for (i = 0; id != 0; i++, id >>= 1) {
3024 + if (!(id & 1))
3025 + continue;
3026 + hnd = &tahvo_irq_handlers[i];
3027 + if (hnd->func == NULL) {
3028 + /* Spurious tahvo interrupt - just ack it */
3029 + printk(KERN_INFO "Spurious Tahvo interrupt "
3030 + "(id %d)\n", i);
3031 + tahvo_disable_irq(i);
3032 + tahvo_ack_irq(i);
3033 + continue;
3034 + }
3035 + hnd->func(hnd->arg);
3036 + /*
3037 + * Don't acknowledge the interrupt here
3038 + * It must be done explicitly
3039 + */
3040 + }
3041 + }
3042 +}
3043 +
3044 +/*
3045 + * Register the handler for a given TAHVO interrupt source.
3046 + */
3047 +int tahvo_request_irq(int id, void *irq_handler, unsigned long arg, char *name)
3048 +{
3049 + struct tahvo_irq_handler_desc *hnd;
3050 +
3051 + if (irq_handler == NULL || id >= MAX_TAHVO_IRQ_HANDLERS ||
3052 + name == NULL) {
3053 + printk(KERN_ERR PFX "Invalid arguments to %s\n",
3054 + __FUNCTION__);
3055 + return -EINVAL;
3056 + }
3057 + hnd = &tahvo_irq_handlers[id];
3058 + if (hnd->func != NULL) {
3059 + printk(KERN_ERR PFX "IRQ %d already reserved\n", id);
3060 + return -EBUSY;
3061 + }
3062 + printk(KERN_INFO PFX "Registering interrupt %d for device %s\n",
3063 + id, name);
3064 + hnd->func = irq_handler;
3065 + hnd->arg = arg;
3066 + strlcpy(hnd->name, name, sizeof(hnd->name));
3067 +
3068 + tahvo_ack_irq(id);
3069 + tahvo_enable_irq(id);
3070 +
3071 + return 0;
3072 +}
3073 +
3074 +/*
3075 + * Unregister the handler for a given TAHVO interrupt source.
3076 + */
3077 +void tahvo_free_irq(int id)
3078 +{
3079 + struct tahvo_irq_handler_desc *hnd;
3080 +
3081 + if (id >= MAX_TAHVO_IRQ_HANDLERS) {
3082 + printk(KERN_ERR PFX "Invalid argument to %s\n",
3083 + __FUNCTION__);
3084 + return;
3085 + }
3086 + hnd = &tahvo_irq_handlers[id];
3087 + if (hnd->func == NULL) {
3088 + printk(KERN_ERR PFX "IRQ %d already freed\n", id);
3089 + return;
3090 + }
3091 +
3092 + tahvo_disable_irq(id);
3093 + hnd->func = NULL;
3094 +}
3095 +
3096 +/**
3097 + * tahvo_probe - Probe for Tahvo ASIC
3098 + * @dev: the Tahvo device
3099 + *
3100 + * Probe for the Tahvo ASIC and allocate memory
3101 + * for its device-struct if found
3102 + */
3103 +static int __devinit tahvo_probe(struct device *dev)
3104 +{
3105 + int rev, id, ret;
3106 +
3107 + /* Prepare tasklet */
3108 + tasklet_init(&tahvo_tasklet, tahvo_tasklet_handler, 0);
3109 +
3110 + tahvo_initialized = 1;
3111 +
3112 + rev = tahvo_read_reg(TAHVO_REG_ASICR);
3113 +
3114 + id = (rev >> 8) & 0xff;
3115 + if (id == 0x03) {
3116 + if ((rev & 0xff) >= 0x50)
3117 + tahvo_7bit_backlight = 1;
3118 + } else if (id == 0x0b) {
3119 + tahvo_is_betty = 1;
3120 + tahvo_7bit_backlight = 1;
3121 + } else {
3122 + printk(KERN_ERR "Tahvo/Betty chip not found");
3123 + return -ENODEV;
3124 + }
3125 +
3126 + printk(KERN_INFO "%s v%d.%d found\n", tahvo_is_betty ? "Betty" : "Tahvo",
3127 + (rev >> 4) & 0x0f, rev & 0x0f);
3128 +
3129 + /* REVISIT: Pass these from board-*.c files in platform_data */
3130 + if (machine_is_nokia770()) {
3131 + tahvo_irq_pin = 40;
3132 + } else if (machine_is_nokia_n800() || machine_is_nokia_n810() ||
3133 + machine_is_nokia_n810_wimax()) {
3134 + tahvo_irq_pin = 111;
3135 + } else {
3136 + printk(KERN_ERR "cbus: Unsupported board for tahvo\n");
3137 + return -ENODEV;
3138 + }
3139 +
3140 + if ((ret = gpio_request(tahvo_irq_pin, "TAHVO irq")) < 0) {
3141 + printk(KERN_ERR PFX "Unable to reserve IRQ GPIO\n");
3142 + return ret;
3143 + }
3144 +
3145 + /* Set the pin as input */
3146 + gpio_direction_input(tahvo_irq_pin);
3147 +
3148 + /* Rising edge triggers the IRQ */
3149 + set_irq_type(gpio_to_irq(tahvo_irq_pin), IRQ_TYPE_EDGE_RISING);
3150 +
3151 + /* Mask all TAHVO interrupts */
3152 + tahvo_write_reg(TAHVO_REG_IMR, 0xffff);
3153 +
3154 + ret = request_irq(gpio_to_irq(tahvo_irq_pin), tahvo_irq_handler, 0,
3155 + "tahvo", 0);
3156 + if (ret < 0) {
3157 + printk(KERN_ERR PFX "Unable to register IRQ handler\n");
3158 + gpio_free(tahvo_irq_pin);
3159 + return ret;
3160 + }
3161 +#ifdef CONFIG_CBUS_TAHVO_USER
3162 + /* Initialize user-space interface */
3163 + if (tahvo_user_init() < 0) {
3164 + printk(KERN_ERR "Unable to initialize driver\n");
3165 + free_irq(gpio_to_irq(tahvo_irq_pin), 0);
3166 + gpio_free(tahvo_irq_pin);
3167 + return ret;
3168 + }
3169 +#endif
3170 + return 0;
3171 +}
3172 +
3173 +static int tahvo_remove(struct device *dev)
3174 +{
3175 +#ifdef CONFIG_CBUS_TAHVO_USER
3176 + tahvo_user_cleanup();
3177 +#endif
3178 + /* Mask all TAHVO interrupts */
3179 + tahvo_write_reg(TAHVO_REG_IMR, 0xffff);
3180 + free_irq(gpio_to_irq(tahvo_irq_pin), 0);
3181 + gpio_free(tahvo_irq_pin);
3182 + tasklet_kill(&tahvo_tasklet);
3183 +
3184 + return 0;
3185 +}
3186 +
3187 +static void tahvo_device_release(struct device *dev)
3188 +{
3189 + complete(&device_release);
3190 +}
3191 +
3192 +static struct device_driver tahvo_driver = {
3193 + .name = "tahvo",
3194 + .bus = &platform_bus_type,
3195 + .probe = tahvo_probe,
3196 + .remove = tahvo_remove,
3197 +};
3198 +
3199 +static struct platform_device tahvo_device = {
3200 + .name = "tahvo",
3201 + .id = -1,
3202 + .dev = {
3203 + .release = tahvo_device_release,
3204 + }
3205 +};
3206 +
3207 +/**
3208 + * tahvo_init - initialise Tahvo driver
3209 + *
3210 + * Initialise the Tahvo driver and return 0 if everything worked ok
3211 + */
3212 +static int __init tahvo_init(void)
3213 +{
3214 + int ret = 0;
3215 +
3216 + printk(KERN_INFO "Tahvo/Betty driver initialising\n");
3217 +
3218 + init_completion(&device_release);
3219 +
3220 + if ((ret = driver_register(&tahvo_driver)) < 0)
3221 + return ret;
3222 +
3223 + if ((ret = platform_device_register(&tahvo_device)) < 0) {
3224 + driver_unregister(&tahvo_driver);
3225 + return ret;
3226 + }
3227 + return 0;
3228 +}
3229 +
3230 +/*
3231 + * Cleanup
3232 + */
3233 +static void __exit tahvo_exit(void)
3234 +{
3235 + platform_device_unregister(&tahvo_device);
3236 + driver_unregister(&tahvo_driver);
3237 + wait_for_completion(&device_release);
3238 +}
3239 +
3240 +EXPORT_SYMBOL(tahvo_request_irq);
3241 +EXPORT_SYMBOL(tahvo_free_irq);
3242 +EXPORT_SYMBOL(tahvo_enable_irq);
3243 +EXPORT_SYMBOL(tahvo_disable_irq);
3244 +EXPORT_SYMBOL(tahvo_ack_irq);
3245 +EXPORT_SYMBOL(tahvo_read_reg);
3246 +EXPORT_SYMBOL(tahvo_write_reg);
3247 +EXPORT_SYMBOL(tahvo_get_backlight_level);
3248 +EXPORT_SYMBOL(tahvo_get_max_backlight_level);
3249 +EXPORT_SYMBOL(tahvo_set_backlight_level);
3250 +
3251 +subsys_initcall(tahvo_init);
3252 +module_exit(tahvo_exit);
3253 +
3254 +MODULE_DESCRIPTION("Tahvo ASIC control");
3255 +MODULE_LICENSE("GPL");
3256 +MODULE_AUTHOR("Juha Yrjölä, David Weinehall, and Mikko Ylinen");
3257 --- /dev/null
3258 +++ linux-2.6.35/drivers/cbus/tahvo.h
3259 @@ -0,0 +1,61 @@
3260 +/*
3261 + * drivers/cbus/tahvo.h
3262 + *
3263 + * Copyright (C) 2004, 2005 Nokia Corporation
3264 + *
3265 + * Written by Juha Yrjölä <juha.yrjola@nokia.com> and
3266 + * David Weinehall <david.weinehall@nokia.com>
3267 + *
3268 + * This file is subject to the terms and conditions of the GNU General
3269 + * Public License. See the file "COPYING" in the main directory of this
3270 + * archive for more details.
3271 + *
3272 + * This program is distributed in the hope that it will be useful,
3273 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3274 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3275 + * GNU General Public License for more details.
3276 +
3277 + * You should have received a copy of the GNU General Public License
3278 + * along with this program; if not, write to the Free Software
3279 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3280 + */
3281 +
3282 +#ifndef __DRIVERS_CBUS_TAHVO_H
3283 +#define __DRIVERS_CBUS_TAHVO_H
3284 +
3285 +#include <linux/types.h>
3286 +
3287 +/* Registers */
3288 +#define TAHVO_REG_ASICR 0x00 /* ASIC ID & revision */
3289 +#define TAHVO_REG_IDR 0x01 /* Interrupt ID */
3290 +#define TAHVO_REG_IDSR 0x02 /* Interrupt status */
3291 +#define TAHVO_REG_IMR 0x03 /* Interrupt mask */
3292 +#define TAHVO_REG_LEDPWMR 0x05 /* LED PWM */
3293 +#define TAHVO_REG_USBR 0x06 /* USB control */
3294 +#define TAHVO_REG_MAX 0x0d
3295 +
3296 +/* Interrupt sources */
3297 +#define TAHVO_INT_VBUSON 0
3298 +
3299 +#define MAX_TAHVO_IRQ_HANDLERS 8
3300 +
3301 +int tahvo_read_reg(int reg);
3302 +void tahvo_write_reg(int reg, u16 val);
3303 +void tahvo_set_clear_reg_bits(int reg, u16 set, u16 clear);
3304 +int tahvo_request_irq(int id, void *irq_handler, unsigned long arg, char *name);
3305 +void tahvo_free_irq(int id);
3306 +void tahvo_enable_irq(int id);
3307 +void tahvo_disable_irq(int id);
3308 +void tahvo_ack_irq(int id);
3309 +int tahvo_get_backlight_level(void);
3310 +int tahvo_get_max_backlight_level(void);
3311 +void tahvo_set_backlight_level(int level);
3312 +
3313 +#ifdef CONFIG_CBUS_TAHVO_USER
3314 +int tahvo_user_init(void);
3315 +void tahvo_user_cleanup(void);
3316 +#endif
3317 +
3318 +extern spinlock_t tahvo_lock;
3319 +
3320 +#endif /* __DRIVERS_CBUS_TAHVO_H */
3321 --- /dev/null
3322 +++ linux-2.6.35/drivers/cbus/tahvo-usb.c
3323 @@ -0,0 +1,777 @@
3324 +/**
3325 + * drivers/cbus/tahvo-usb.c
3326 + *
3327 + * Tahvo USB transeiver
3328 + *
3329 + * Copyright (C) 2005-2006 Nokia Corporation
3330 + *
3331 + * Parts copied from drivers/i2c/chips/isp1301_omap.c
3332 + * Copyright (C) 2004 Texas Instruments
3333 + * Copyright (C) 2004 David Brownell
3334 + *
3335 + * Written by Juha Yrjölä <juha.yrjola@nokia.com>,
3336 + * Tony Lindgren <tony@atomide.com>, and
3337 + * Timo Teräs <timo.teras@nokia.com>
3338 + *
3339 + * This file is subject to the terms and conditions of the GNU General
3340 + * Public License. See the file "COPYING" in the main directory of this
3341 + * archive for more details.
3342 + *
3343 + * This program is distributed in the hope that it will be useful,
3344 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3345 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3346 + * GNU General Public License for more details.
3347 + *
3348 + * You should have received a copy of the GNU General Public License
3349 + * along with this program; if not, write to the Free Software
3350 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3351 + */
3352 +
3353 +#include <linux/kernel.h>
3354 +#include <linux/module.h>
3355 +#include <linux/init.h>
3356 +#include <linux/slab.h>
3357 +#include <linux/io.h>
3358 +#include <linux/interrupt.h>
3359 +#include <linux/platform_device.h>
3360 +#include <linux/usb/ch9.h>
3361 +#include <linux/usb/gadget.h>
3362 +#include <linux/usb.h>
3363 +#include <linux/usb/otg.h>
3364 +#include <linux/i2c.h>
3365 +#include <linux/workqueue.h>
3366 +#include <linux/kobject.h>
3367 +#include <linux/clk.h>
3368 +#include <linux/mutex.h>
3369 +
3370 +#include <asm/irq.h>
3371 +#include <plat/usb.h>
3372 +
3373 +#include "cbus.h"
3374 +#include "tahvo.h"
3375 +
3376 +#define DRIVER_NAME "tahvo-usb"
3377 +
3378 +#define USBR_SLAVE_CONTROL (1 << 8)
3379 +#define USBR_VPPVIO_SW (1 << 7)
3380 +#define USBR_SPEED (1 << 6)
3381 +#define USBR_REGOUT (1 << 5)
3382 +#define USBR_MASTER_SW2 (1 << 4)
3383 +#define USBR_MASTER_SW1 (1 << 3)
3384 +#define USBR_SLAVE_SW (1 << 2)
3385 +#define USBR_NSUSPEND (1 << 1)
3386 +#define USBR_SEMODE (1 << 0)
3387 +
3388 +/* bits in OTG_CTRL */
3389 +
3390 +/* Bits that are controlled by OMAP OTG and are read-only */
3391 +#define OTG_CTRL_OMAP_MASK (OTG_PULLDOWN|OTG_PULLUP|OTG_DRV_VBUS|\
3392 + OTG_PD_VBUS|OTG_PU_VBUS|OTG_PU_ID)
3393 +/* Bits that are controlled by transceiver */
3394 +#define OTG_CTRL_XCVR_MASK (OTG_ASESSVLD|OTG_BSESSEND|\
3395 + OTG_BSESSVLD|OTG_VBUSVLD|OTG_ID)
3396 +/* Bits that are controlled by system */
3397 +#define OTG_CTRL_SYS_MASK (OTG_A_BUSREQ|OTG_A_SETB_HNPEN|OTG_B_BUSREQ|\
3398 + OTG_B_HNPEN|OTG_BUSDROP)
3399 +
3400 +#if defined(CONFIG_USB_OHCI_HCD) && !defined(CONFIG_USB_OTG)
3401 +#error tahvo-otg.c does not work with OCHI yet!
3402 +#endif
3403 +
3404 +#define TAHVO_MODE_HOST 0
3405 +#define TAHVO_MODE_PERIPHERAL 1
3406 +
3407 +#ifdef CONFIG_USB_OTG
3408 +#define TAHVO_MODE(tu) (tu)->tahvo_mode
3409 +#elif defined(CONFIG_USB_GADGET_OMAP)
3410 +#define TAHVO_MODE(tu) TAHVO_MODE_PERIPHERAL
3411 +#else
3412 +#define TAHVO_MODE(tu) TAHVO_MODE_HOST
3413 +#endif
3414 +
3415 +struct tahvo_usb {
3416 + struct platform_device *pt_dev;
3417 + struct otg_transceiver otg;
3418 + int vbus_state;
3419 + struct work_struct irq_work;
3420 + struct mutex serialize;
3421 +#ifdef CONFIG_USB_OTG
3422 + int tahvo_mode;
3423 +#endif
3424 +};
3425 +static struct platform_device tahvo_usb_device;
3426 +
3427 +/*
3428 + * ---------------------------------------------------------------------------
3429 + * OTG related functions
3430 + *
3431 + * These shoud be separated into omap-otg.c driver module, as they are used
3432 + * by various transceivers. These functions are needed in the UDC-only case
3433 + * as well. These functions are copied from GPL isp1301_omap.c
3434 + * ---------------------------------------------------------------------------
3435 + */
3436 +static struct platform_device *tahvo_otg_dev;
3437 +
3438 +static irqreturn_t omap_otg_irq(int irq, void *arg)
3439 +{
3440 + struct platform_device *otg_dev = arg;
3441 + struct tahvo_usb *tu = platform_get_drvdata(otg_dev);
3442 + u16 otg_irq;
3443 +
3444 + otg_irq = omap_readw(OTG_IRQ_SRC);
3445 + if (otg_irq & OPRT_CHG) {
3446 + omap_writew(OPRT_CHG, OTG_IRQ_SRC);
3447 + } else if (otg_irq & B_SRP_TMROUT) {
3448 + omap_writew(B_SRP_TMROUT, OTG_IRQ_SRC);
3449 + } else if (otg_irq & B_HNP_FAIL) {
3450 + omap_writew(B_HNP_FAIL, OTG_IRQ_SRC);
3451 + } else if (otg_irq & A_SRP_DETECT) {
3452 + omap_writew(A_SRP_DETECT, OTG_IRQ_SRC);
3453 + } else if (otg_irq & A_REQ_TMROUT) {
3454 + omap_writew(A_REQ_TMROUT, OTG_IRQ_SRC);
3455 + } else if (otg_irq & A_VBUS_ERR) {
3456 + omap_writew(A_VBUS_ERR, OTG_IRQ_SRC);
3457 + } else if (otg_irq & DRIVER_SWITCH) {
3458 + if ((!(omap_readl(OTG_CTRL) & OTG_DRIVER_SEL)) &&
3459 + tu->otg.host && tu->otg.state == OTG_STATE_A_HOST) {
3460 + /* role is host */
3461 + usb_bus_start_enum(tu->otg.host,
3462 + tu->otg.host->otg_port);
3463 + }
3464 + omap_writew(DRIVER_SWITCH, OTG_IRQ_SRC);
3465 + } else
3466 + return IRQ_NONE;
3467 +
3468 + return IRQ_HANDLED;
3469 +
3470 +}
3471 +
3472 +static int omap_otg_init(void)
3473 +{
3474 + u32 l;
3475 +
3476 +#ifdef CONFIG_USB_OTG
3477 + if (!tahvo_otg_dev) {
3478 + printk("tahvo-usb: no tahvo_otg_dev\n");
3479 + return -ENODEV;
3480 + }
3481 +#endif
3482 +
3483 + l = omap_readl(OTG_SYSCON_1);
3484 + l &= ~OTG_IDLE_EN;
3485 + omap_writel(l, OTG_SYSCON_1);
3486 + udelay(100);
3487 +
3488 + /* some of these values are board-specific... */
3489 + l = omap_readl(OTG_SYSCON_2);
3490 + l |= OTG_EN
3491 + /* for B-device: */
3492 + | SRP_GPDATA /* 9msec Bdev D+ pulse */
3493 + | SRP_GPDVBUS /* discharge after VBUS pulse */
3494 + // | (3 << 24) /* 2msec VBUS pulse */
3495 + /* for A-device: */
3496 + | (0 << 20) /* 200ms nominal A_WAIT_VRISE timer */
3497 + | SRP_DPW /* detect 167+ns SRP pulses */
3498 + | SRP_DATA | SRP_VBUS; /* accept both kinds of SRP pulse */
3499 + omap_writel(l, OTG_SYSCON_2);
3500 +
3501 + omap_writew(DRIVER_SWITCH | OPRT_CHG
3502 + | B_SRP_TMROUT | B_HNP_FAIL
3503 + | A_VBUS_ERR | A_SRP_DETECT | A_REQ_TMROUT,
3504 + OTG_IRQ_EN);
3505 + l = omap_readl(OTG_SYSCON_2);
3506 + l |= OTG_EN;
3507 + omap_writel(l, OTG_SYSCON_2);
3508 +
3509 + return 0;
3510 +}
3511 +
3512 +static int omap_otg_probe(struct device *dev)
3513 +{
3514 + int ret;
3515 +
3516 + tahvo_otg_dev = to_platform_device(dev);
3517 + ret = omap_otg_init();
3518 + if (ret != 0) {
3519 + printk(KERN_ERR "tahvo-usb: omap_otg_init failed\n");
3520 + return ret;
3521 + }
3522 +
3523 + return request_irq(tahvo_otg_dev->resource[1].start,
3524 + omap_otg_irq, IRQF_DISABLED, DRIVER_NAME,
3525 + &tahvo_usb_device);
3526 +}
3527 +
3528 +static int omap_otg_remove(struct device *dev)
3529 +{
3530 + free_irq(tahvo_otg_dev->resource[1].start, &tahvo_usb_device);
3531 + tahvo_otg_dev = NULL;
3532 +
3533 + return 0;
3534 +}
3535 +
3536 +struct device_driver omap_otg_driver = {
3537 + .name = "omap_otg",
3538 + .bus = &platform_bus_type,
3539 + .probe = omap_otg_probe,
3540 + .remove = omap_otg_remove,
3541 +};
3542 +
3543 +/*
3544 + * ---------------------------------------------------------------------------
3545 + * Tahvo related functions
3546 + * These are Nokia proprietary code, except for the OTG register settings,
3547 + * which are copied from isp1301.c
3548 + * ---------------------------------------------------------------------------
3549 + */
3550 +static ssize_t vbus_state_show(struct device *device,
3551 + struct device_attribute *attr, char *buf)
3552 +{
3553 + struct tahvo_usb *tu = dev_get_drvdata(device);
3554 + return sprintf(buf, "%d\n", tu->vbus_state);
3555 +}
3556 +static DEVICE_ATTR(vbus_state, 0444, vbus_state_show, NULL);
3557 +
3558 +int vbus_active = 0;
3559 +
3560 +#if 0
3561 +
3562 +static int host_suspend(struct tahvo_usb *tu)
3563 +{
3564 + struct device *dev;
3565 +
3566 + if (!tu->otg.host)
3567 + return -ENODEV;
3568 +
3569 + /* Currently ASSUMES only the OTG port matters;
3570 + * other ports could be active...
3571 + */
3572 + dev = tu->otg.host->controller;
3573 + return dev->driver->suspend(dev, PMSG_SUSPEND);
3574 +}
3575 +
3576 +static int host_resume(struct tahvo_usb *tu)
3577 +{
3578 + struct device *dev;
3579 +
3580 + if (!tu->otg.host)
3581 + return -ENODEV;
3582 +
3583 + dev = tu->otg.host->controller;
3584 + return dev->driver->resume(dev);
3585 +}
3586 +
3587 +#else
3588 +
3589 +static int host_suspend(struct tahvo_usb *tu)
3590 +{
3591 + return 0;
3592 +}
3593 +
3594 +static int host_resume(struct tahvo_usb *tu)
3595 +{
3596 + return 0;
3597 +}
3598 +
3599 +#endif
3600 +
3601 +static void check_vbus_state(struct tahvo_usb *tu)
3602 +{
3603 + int reg, prev_state;
3604 +
3605 + reg = tahvo_read_reg(TAHVO_REG_IDSR);
3606 + if (reg & 0x01) {
3607 + u32 l;
3608 +
3609 + vbus_active = 1;
3610 + switch (tu->otg.state) {
3611 + case OTG_STATE_B_IDLE:
3612 + /* Enable the gadget driver */
3613 + if (tu->otg.gadget)
3614 + usb_gadget_vbus_connect(tu->otg.gadget);
3615 + /* Set B-session valid and not B-sessio ended to indicate
3616 + * Vbus to be ok. */
3617 + l = omap_readl(OTG_CTRL);
3618 + l &= ~OTG_BSESSEND;
3619 + l |= OTG_BSESSVLD;
3620 + omap_writel(l, OTG_CTRL);
3621 +
3622 + tu->otg.state = OTG_STATE_B_PERIPHERAL;
3623 + break;
3624 + case OTG_STATE_A_IDLE:
3625 + /* Session is now valid assuming the USB hub is driving Vbus */
3626 + tu->otg.state = OTG_STATE_A_HOST;
3627 + host_resume(tu);
3628 + break;
3629 + default:
3630 + break;
3631 + }
3632 + printk("USB cable connected\n");
3633 + } else {
3634 + switch (tu->otg.state) {
3635 + case OTG_STATE_B_PERIPHERAL:
3636 + if (tu->otg.gadget)
3637 + usb_gadget_vbus_disconnect(tu->otg.gadget);
3638 + tu->otg.state = OTG_STATE_B_IDLE;
3639 + break;
3640 + case OTG_STATE_A_HOST:
3641 + tu->otg.state = OTG_STATE_A_IDLE;
3642 + break;
3643 + default:
3644 + break;
3645 + }
3646 + printk("USB cable disconnected\n");
3647 + vbus_active = 0;
3648 + }
3649 +
3650 + prev_state = tu->vbus_state;
3651 + tu->vbus_state = reg & 0x01;
3652 + if (prev_state != tu->vbus_state)
3653 + sysfs_notify(&tu->pt_dev->dev.kobj, NULL, "vbus_state");
3654 +}
3655 +
3656 +static void tahvo_usb_become_host(struct tahvo_usb *tu)
3657 +{
3658 + u32 l;
3659 +
3660 + /* Clear system and transceiver controlled bits
3661 + * also mark the A-session is always valid */
3662 + omap_otg_init();
3663 +
3664 + l = omap_readl(OTG_CTRL);
3665 + l &= ~(OTG_CTRL_XCVR_MASK | OTG_CTRL_SYS_MASK);
3666 + l |= OTG_ASESSVLD;
3667 + omap_writel(l, OTG_CTRL);
3668 +
3669 + /* Power up the transceiver in USB host mode */
3670 + tahvo_write_reg(TAHVO_REG_USBR, USBR_REGOUT | USBR_NSUSPEND |
3671 + USBR_MASTER_SW2 | USBR_MASTER_SW1);
3672 + tu->otg.state = OTG_STATE_A_IDLE;
3673 +
3674 + check_vbus_state(tu);
3675 +}
3676 +
3677 +static void tahvo_usb_stop_host(struct tahvo_usb *tu)
3678 +{
3679 + host_suspend(tu);
3680 + tu->otg.state = OTG_STATE_A_IDLE;
3681 +}
3682 +
3683 +static void tahvo_usb_become_peripheral(struct tahvo_usb *tu)
3684 +{
3685 + u32 l;
3686 +
3687 + /* Clear system and transceiver controlled bits
3688 + * and enable ID to mark peripheral mode and
3689 + * BSESSEND to mark no Vbus */
3690 + omap_otg_init();
3691 + l = omap_readl(OTG_CTRL);
3692 + l &= ~(OTG_CTRL_XCVR_MASK | OTG_CTRL_SYS_MASK | OTG_BSESSVLD);
3693 + l |= OTG_ID | OTG_BSESSEND;
3694 + omap_writel(l, OTG_CTRL);
3695 +
3696 + /* Power up transceiver and set it in USB perhiperal mode */
3697 + tahvo_write_reg(TAHVO_REG_USBR, USBR_SLAVE_CONTROL | USBR_REGOUT | USBR_NSUSPEND | USBR_SLAVE_SW);
3698 + tu->otg.state = OTG_STATE_B_IDLE;
3699 +
3700 + check_vbus_state(tu);
3701 +}
3702 +
3703 +static void tahvo_usb_stop_peripheral(struct tahvo_usb *tu)
3704 +{
3705 + u32 l;
3706 +
3707 + l = omap_readl(OTG_CTRL);
3708 + l &= ~OTG_BSESSVLD;
3709 + l |= OTG_BSESSEND;
3710 + omap_writel(l, OTG_CTRL);
3711 +
3712 + if (tu->otg.gadget)
3713 + usb_gadget_vbus_disconnect(tu->otg.gadget);
3714 + tu->otg.state = OTG_STATE_B_IDLE;
3715 +
3716 +}
3717 +
3718 +static void tahvo_usb_power_off(struct tahvo_usb *tu)
3719 +{
3720 + u32 l;
3721 + int id;
3722 +
3723 + /* Disable gadget controller if any */
3724 + if (tu->otg.gadget)
3725 + usb_gadget_vbus_disconnect(tu->otg.gadget);
3726 +
3727 + host_suspend(tu);
3728 +
3729 + /* Disable OTG and interrupts */
3730 + if (TAHVO_MODE(tu) == TAHVO_MODE_PERIPHERAL)
3731 + id = OTG_ID;
3732 + else
3733 + id = 0;
3734 + l = omap_readl(OTG_CTRL);
3735 + l &= ~(OTG_CTRL_XCVR_MASK | OTG_CTRL_SYS_MASK | OTG_BSESSVLD);
3736 + l |= id | OTG_BSESSEND;
3737 + omap_writel(l, OTG_CTRL);
3738 + omap_writew(0, OTG_IRQ_EN);
3739 +
3740 + l = omap_readl(OTG_SYSCON_2);
3741 + l &= ~OTG_EN;
3742 + omap_writel(l, OTG_SYSCON_2);
3743 +
3744 + l = omap_readl(OTG_SYSCON_1);
3745 + l |= OTG_IDLE_EN;
3746 + omap_writel(l, OTG_SYSCON_1);
3747 +
3748 + /* Power off transceiver */
3749 + tahvo_write_reg(TAHVO_REG_USBR, 0);
3750 + tu->otg.state = OTG_STATE_UNDEFINED;
3751 +}
3752 +
3753 +
3754 +static int tahvo_usb_set_power(struct otg_transceiver *dev, unsigned mA)
3755 +{
3756 + struct tahvo_usb *tu = container_of(dev, struct tahvo_usb, otg);
3757 +
3758 + dev_dbg(&tu->pt_dev->dev, "set_power %d mA\n", mA);
3759 +
3760 + if (dev->state == OTG_STATE_B_PERIPHERAL) {
3761 + /* REVISIT: Can Tahvo charge battery from VBUS? */
3762 + }
3763 + return 0;
3764 +}
3765 +
3766 +static int tahvo_usb_set_suspend(struct otg_transceiver *dev, int suspend)
3767 +{
3768 + struct tahvo_usb *tu = container_of(dev, struct tahvo_usb, otg);
3769 + u16 w;
3770 +
3771 + dev_dbg(&tu->pt_dev->dev, "set_suspend\n");
3772 +
3773 + w = tahvo_read_reg(TAHVO_REG_USBR);
3774 + if (suspend)
3775 + w &= ~USBR_NSUSPEND;
3776 + else
3777 + w |= USBR_NSUSPEND;
3778 + tahvo_write_reg(TAHVO_REG_USBR, w);
3779 +
3780 + return 0;
3781 +}
3782 +
3783 +static int tahvo_usb_start_srp(struct otg_transceiver *dev)
3784 +{
3785 + struct tahvo_usb *tu = container_of(dev, struct tahvo_usb, otg);
3786 + u32 otg_ctrl;
3787 +
3788 + dev_dbg(&tu->pt_dev->dev, "start_srp\n");
3789 +
3790 + if (!dev || tu->otg.state != OTG_STATE_B_IDLE)
3791 + return -ENODEV;
3792 +
3793 + otg_ctrl = omap_readl(OTG_CTRL);
3794 + if (!(otg_ctrl & OTG_BSESSEND))
3795 + return -EINVAL;
3796 +
3797 + otg_ctrl |= OTG_B_BUSREQ;
3798 + otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_SYS_MASK;
3799 + omap_writel(otg_ctrl, OTG_CTRL);
3800 + tu->otg.state = OTG_STATE_B_SRP_INIT;
3801 +
3802 + return 0;
3803 +}
3804 +
3805 +static int tahvo_usb_start_hnp(struct otg_transceiver *otg)
3806 +{
3807 + struct tahvo_usb *tu = container_of(otg, struct tahvo_usb, otg);
3808 +
3809 + dev_dbg(&tu->pt_dev->dev, "start_hnp\n");
3810 +#ifdef CONFIG_USB_OTG
3811 + /* REVISIT: Add this for OTG */
3812 +#endif
3813 + return -EINVAL;
3814 +}
3815 +
3816 +static int tahvo_usb_set_host(struct otg_transceiver *otg, struct usb_bus *host)
3817 +{
3818 + struct tahvo_usb *tu = container_of(otg, struct tahvo_usb, otg);
3819 + u32 l;
3820 +
3821 + dev_dbg(&tu->pt_dev->dev, "set_host %p\n", host);
3822 +
3823 + if (otg == NULL)
3824 + return -ENODEV;
3825 +
3826 +#if defined(CONFIG_USB_OTG) || !defined(CONFIG_USB_GADGET_OMAP)
3827 +
3828 + mutex_lock(&tu->serialize);
3829 +
3830 + if (host == NULL) {
3831 + if (TAHVO_MODE(tu) == TAHVO_MODE_HOST)
3832 + tahvo_usb_power_off(tu);
3833 + tu->otg.host = NULL;
3834 + mutex_unlock(&tu->serialize);
3835 + return 0;
3836 + }
3837 +
3838 + l = omap_readl(OTG_SYSCON_1);
3839 + l &= ~(OTG_IDLE_EN | HST_IDLE_EN | DEV_IDLE_EN);
3840 + omap_writel(l, OTG_SYSCON_1);
3841 +
3842 + if (TAHVO_MODE(tu) == TAHVO_MODE_HOST) {
3843 + tu->otg.host = NULL;
3844 + tahvo_usb_become_host(tu);
3845 + } else
3846 + host_suspend(tu);
3847 +
3848 + tu->otg.host = host;
3849 +
3850 + mutex_unlock(&tu->serialize);
3851 +#else
3852 + /* No host mode configured, so do not allow host controlled to be set */
3853 + return -EINVAL;
3854 +#endif
3855 +
3856 + return 0;
3857 +}
3858 +
3859 +static int tahvo_usb_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget)
3860 +{
3861 + struct tahvo_usb *tu = container_of(otg, struct tahvo_usb, otg);
3862 +
3863 + dev_dbg(&tu->pt_dev->dev, "set_peripheral %p\n", gadget);
3864 +
3865 + if (!otg)
3866 + return -ENODEV;
3867 +
3868 +#if defined(CONFIG_USB_OTG) || defined(CONFIG_USB_GADGET_OMAP)
3869 +
3870 + mutex_lock(&tu->serialize);
3871 +
3872 + if (!gadget) {
3873 + if (TAHVO_MODE(tu) == TAHVO_MODE_PERIPHERAL)
3874 + tahvo_usb_power_off(tu);
3875 + tu->otg.gadget = NULL;
3876 + mutex_unlock(&tu->serialize);
3877 + return 0;
3878 + }
3879 +
3880 + tu->otg.gadget = gadget;
3881 + if (TAHVO_MODE(tu) == TAHVO_MODE_PERIPHERAL)
3882 + tahvo_usb_become_peripheral(tu);
3883 +
3884 + mutex_unlock(&tu->serialize);
3885 +#else
3886 + /* No gadget mode configured, so do not allow host controlled to be set */
3887 + return -EINVAL;
3888 +#endif
3889 +
3890 + return 0;
3891 +}
3892 +
3893 +static void tahvo_usb_irq_work(struct work_struct *work)
3894 +{
3895 + struct tahvo_usb *tu = container_of(work, struct tahvo_usb, irq_work);
3896 +
3897 + mutex_lock(&tu->serialize);
3898 + check_vbus_state(tu);
3899 + mutex_unlock(&tu->serialize);
3900 +}
3901 +
3902 +static void tahvo_usb_vbus_interrupt(unsigned long arg)
3903 +{
3904 + struct tahvo_usb *tu = (struct tahvo_usb *) arg;
3905 +
3906 + tahvo_ack_irq(TAHVO_INT_VBUSON);
3907 + /* Seems we need this to acknowledge the interrupt */
3908 + tahvo_read_reg(TAHVO_REG_IDSR);
3909 + schedule_work(&tu->irq_work);
3910 +}
3911 +
3912 +#ifdef CONFIG_USB_OTG
3913 +static ssize_t otg_mode_show(struct device *device,
3914 + struct device_attribute *attr, char *buf)
3915 +{
3916 + struct tahvo_usb *tu = dev_get_drvdata(device);
3917 + switch (tu->tahvo_mode) {
3918 + case TAHVO_MODE_HOST:
3919 + return sprintf(buf, "host\n");
3920 + case TAHVO_MODE_PERIPHERAL:
3921 + return sprintf(buf, "peripheral\n");
3922 + }
3923 + return sprintf(buf, "unknown\n");
3924 +}
3925 +
3926 +static ssize_t otg_mode_store(struct device *device,
3927 + struct device_attribute *attr,
3928 + const char *buf, size_t count)
3929 +{
3930 + struct tahvo_usb *tu = dev_get_drvdata(device);
3931 + int r;
3932 +
3933 + r = strlen(buf);
3934 + mutex_lock(&tu->serialize);
3935 + if (strncmp(buf, "host", 4) == 0) {
3936 + if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL)
3937 + tahvo_usb_stop_peripheral(tu);
3938 + tu->tahvo_mode = TAHVO_MODE_HOST;
3939 + if (tu->otg.host) {
3940 + printk(KERN_INFO "Selected HOST mode: host controller present.\n");
3941 + tahvo_usb_become_host(tu);
3942 + } else {
3943 + printk(KERN_INFO "Selected HOST mode: no host controller, powering off.\n");
3944 + tahvo_usb_power_off(tu);
3945 + }
3946 + } else if (strncmp(buf, "peripheral", 10) == 0) {
3947 + if (tu->tahvo_mode == TAHVO_MODE_HOST)
3948 + tahvo_usb_stop_host(tu);
3949 + tu->tahvo_mode = TAHVO_MODE_PERIPHERAL;
3950 + if (tu->otg.gadget) {
3951 + printk(KERN_INFO "Selected PERIPHERAL mode: gadget driver present.\n");
3952 + tahvo_usb_become_peripheral(tu);
3953 + } else {
3954 + printk(KERN_INFO "Selected PERIPHERAL mode: no gadget driver, powering off.\n");
3955 + tahvo_usb_power_off(tu);
3956 + }
3957 + } else
3958 + r = -EINVAL;
3959 +
3960 + mutex_unlock(&tu->serialize);
3961 + return r;
3962 +}
3963 +
3964 +static DEVICE_ATTR(otg_mode, 0644, otg_mode_show, otg_mode_store);
3965 +#endif
3966 +
3967 +static int tahvo_usb_probe(struct device *dev)
3968 +{
3969 + struct tahvo_usb *tu;
3970 + int ret;
3971 +
3972 + dev_dbg(dev, "probe\n");
3973 +
3974 + /* Create driver data */
3975 + tu = kmalloc(sizeof(*tu), GFP_KERNEL);
3976 + if (!tu)
3977 + return -ENOMEM;
3978 + memset(tu, 0, sizeof(*tu));
3979 + tu->pt_dev = container_of(dev, struct platform_device, dev);
3980 +#ifdef CONFIG_USB_OTG
3981 + /* Default mode */
3982 +#ifdef CONFIG_CBUS_TAHVO_USB_HOST_BY_DEFAULT
3983 + tu->tahvo_mode = TAHVO_MODE_HOST;
3984 +#else
3985 + tu->tahvo_mode = TAHVO_MODE_PERIPHERAL;
3986 +#endif
3987 +#endif
3988 +
3989 + INIT_WORK(&tu->irq_work, tahvo_usb_irq_work);
3990 + mutex_init(&tu->serialize);
3991 +
3992 + /* Set initial state, so that we generate kevents only on
3993 + * state changes */
3994 + tu->vbus_state = tahvo_read_reg(TAHVO_REG_IDSR) & 0x01;
3995 +
3996 + /* We cannot enable interrupt until omap_udc is initialized */
3997 + ret = tahvo_request_irq(TAHVO_INT_VBUSON, tahvo_usb_vbus_interrupt,
3998 + (unsigned long) tu, "vbus_interrupt");
3999 + if (ret != 0) {
4000 + kfree(tu);
4001 + printk(KERN_ERR "Could not register Tahvo interrupt for VBUS\n");
4002 + return ret;
4003 + }
4004 +
4005 + /* Attributes */
4006 + ret = device_create_file(dev, &dev_attr_vbus_state);
4007 +#ifdef CONFIG_USB_OTG
4008 + ret |= device_create_file(dev, &dev_attr_otg_mode);
4009 +#endif
4010 + if (ret)
4011 + printk(KERN_ERR "attribute creation failed: %d\n", ret);
4012 +
4013 + /* Create OTG interface */
4014 + tahvo_usb_power_off(tu);
4015 + tu->otg.state = OTG_STATE_UNDEFINED;
4016 + tu->otg.label = DRIVER_NAME;
4017 + tu->otg.set_host = tahvo_usb_set_host;
4018 + tu->otg.set_peripheral = tahvo_usb_set_peripheral;
4019 + tu->otg.set_power = tahvo_usb_set_power;
4020 + tu->otg.set_suspend = tahvo_usb_set_suspend;
4021 + tu->otg.start_srp = tahvo_usb_start_srp;
4022 + tu->otg.start_hnp = tahvo_usb_start_hnp;
4023 +
4024 + ret = otg_set_transceiver(&tu->otg);
4025 + if (ret < 0) {
4026 + printk(KERN_ERR "Cannot register USB transceiver\n");
4027 + kfree(tu);
4028 + tahvo_free_irq(TAHVO_INT_VBUSON);
4029 + return ret;
4030 + }
4031 +
4032 + dev_set_drvdata(dev, tu);
4033 +
4034 + /* Act upon current vbus state once at startup. A vbus state irq may or
4035 + * may not be generated in addition to this. */
4036 + schedule_work(&tu->irq_work);
4037 + return 0;
4038 +}
4039 +
4040 +static int tahvo_usb_remove(struct device *dev)
4041 +{
4042 + dev_dbg(dev, "remove\n");
4043 +
4044 + tahvo_free_irq(TAHVO_INT_VBUSON);
4045 + flush_scheduled_work();
4046 + otg_set_transceiver(0);
4047 + device_remove_file(dev, &dev_attr_vbus_state);
4048 +#ifdef CONFIG_USB_OTG
4049 + device_remove_file(dev, &dev_attr_otg_mode);
4050 +#endif
4051 + return 0;
4052 +}
4053 +
4054 +static struct device_driver tahvo_usb_driver = {
4055 + .name = "tahvo-usb",
4056 + .bus = &platform_bus_type,
4057 + .probe = tahvo_usb_probe,
4058 + .remove = tahvo_usb_remove,
4059 +};
4060 +
4061 +static struct platform_device tahvo_usb_device = {
4062 + .name = "tahvo-usb",
4063 + .id = -1,
4064 +};
4065 +
4066 +static int __init tahvo_usb_init(void)
4067 +{
4068 + int ret = 0;
4069 +
4070 + printk(KERN_INFO "Tahvo USB transceiver driver initializing\n");
4071 + ret = driver_register(&tahvo_usb_driver);
4072 + if (ret)
4073 + return ret;
4074 + ret = platform_device_register(&tahvo_usb_device);
4075 + if (ret < 0) {
4076 + driver_unregister(&tahvo_usb_driver);
4077 + return ret;
4078 + }
4079 + ret = driver_register(&omap_otg_driver);
4080 + if (ret) {
4081 + platform_device_unregister(&tahvo_usb_device);
4082 + driver_unregister(&tahvo_usb_driver);
4083 + return ret;
4084 + }
4085 + return 0;
4086 +}
4087 +
4088 +subsys_initcall(tahvo_usb_init);
4089 +
4090 +static void __exit tahvo_usb_exit(void)
4091 +{
4092 + driver_unregister(&omap_otg_driver);
4093 + platform_device_unregister(&tahvo_usb_device);
4094 + driver_unregister(&tahvo_usb_driver);
4095 +}
4096 +module_exit(tahvo_usb_exit);
4097 +
4098 +MODULE_DESCRIPTION("Tahvo USB OTG Transceiver Driver");
4099 +MODULE_LICENSE("GPL");
4100 +MODULE_AUTHOR("Juha Yrjölä, Tony Lindgren, and Timo Teräs");
4101 --- /dev/null
4102 +++ linux-2.6.35/drivers/cbus/tahvo-user.c
4103 @@ -0,0 +1,407 @@
4104 +/**
4105 + * drivers/cbus/tahvo-user.c
4106 + *
4107 + * Tahvo user space interface functions
4108 + *
4109 + * Copyright (C) 2004, 2005 Nokia Corporation
4110 + *
4111 + * Written by Mikko Ylinen <mikko.k.ylinen@nokia.com>
4112 + *
4113 + * This file is subject to the terms and conditions of the GNU General
4114 + * Public License. See the file "COPYING" in the main directory of this
4115 + * archive for more details.
4116 + *
4117 + * This program is distributed in the hope that it will be useful,
4118 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4119 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4120 + * GNU General Public License for more details.
4121 + *
4122 + * You should have received a copy of the GNU General Public License
4123 + * along with this program; if not, write to the Free Software
4124 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
4125 + */
4126 +
4127 +#include <linux/types.h>
4128 +#include <linux/kernel.h>
4129 +#include <linux/interrupt.h>
4130 +#include <linux/module.h>
4131 +#include <linux/init.h>
4132 +#include <linux/fs.h>
4133 +#include <linux/miscdevice.h>
4134 +#include <linux/poll.h>
4135 +#include <linux/list.h>
4136 +#include <linux/spinlock.h>
4137 +#include <linux/sched.h>
4138 +#include <linux/mutex.h>
4139 +#include <linux/slab.h>
4140 +
4141 +#include <asm/uaccess.h>
4142 +
4143 +#include "tahvo.h"
4144 +
4145 +#include "user_retu_tahvo.h"
4146 +
4147 +/* Maximum size of IRQ node buffer/pool */
4148 +#define TAHVO_MAX_IRQ_BUF_LEN 16
4149 +
4150 +#define PFX "tahvo-user: "
4151 +
4152 +/* Bitmap for marking the interrupt sources as having the handlers */
4153 +static u32 tahvo_irq_bits;
4154 +
4155 +/* For allowing only one user process to subscribe to the tahvo interrupts */
4156 +static struct file *tahvo_irq_subscr = NULL;
4157 +
4158 +/* For poll and IRQ passing */
4159 +struct tahvo_irq {
4160 + u32 id;
4161 + struct list_head node;
4162 +};
4163 +
4164 +static spinlock_t tahvo_irqs_lock;
4165 +static struct tahvo_irq *tahvo_irq_block;
4166 +static LIST_HEAD(tahvo_irqs);
4167 +static LIST_HEAD(tahvo_irqs_reserve);
4168 +
4169 +/* Wait queue - used when user wants to read the device */
4170 +DECLARE_WAIT_QUEUE_HEAD(tahvo_user_waitqueue);
4171 +
4172 +/* Semaphore to protect irq subscription sequence */
4173 +static struct mutex tahvo_mutex;
4174 +
4175 +/* This array specifies TAHVO register types (read/write/toggle) */
4176 +static const u8 tahvo_access_bits[] = {
4177 + 1,
4178 + 4,
4179 + 1,
4180 + 3,
4181 + 3,
4182 + 3,
4183 + 3,
4184 + 3,
4185 + 3,
4186 + 3,
4187 + 3,
4188 + 3,
4189 + 3,
4190 + 1
4191 +};
4192 +
4193 +/*
4194 + * The handler for all TAHVO interrupts.
4195 + *
4196 + * arg is the interrupt source in TAHVO.
4197 + */
4198 +static void tahvo_user_irq_handler(unsigned long arg)
4199 +{
4200 + struct tahvo_irq *irq;
4201 +
4202 + /* user has to re-enable the interrupt once ready
4203 + * for receiving them again */
4204 + tahvo_disable_irq(arg);
4205 + tahvo_ack_irq(arg);
4206 +
4207 + spin_lock(&tahvo_irqs_lock);
4208 + if (list_empty(&tahvo_irqs_reserve)) {
4209 + spin_unlock(&tahvo_irqs_lock);
4210 + return;
4211 + }
4212 + irq = list_entry((&tahvo_irqs_reserve)->next, struct tahvo_irq, node);
4213 + irq->id = arg;
4214 + list_move_tail(&irq->node, &tahvo_irqs);
4215 + spin_unlock(&tahvo_irqs_lock);
4216 +
4217 + /* wake up waiting thread */
4218 + wake_up(&tahvo_user_waitqueue);
4219 +}
4220 +
4221 +/*
4222 + * This routine sets up the interrupt handler and marks an interrupt source
4223 + * in TAHVO as a candidate for signal delivery to the user process.
4224 + */
4225 +static int tahvo_user_subscribe_to_irq(int id, struct file *filp)
4226 +{
4227 + int ret;
4228 +
4229 + mutex_lock(&tahvo_mutex);
4230 + if ((tahvo_irq_subscr != NULL) && (tahvo_irq_subscr != filp)) {
4231 + mutex_unlock(&tahvo_mutex);
4232 + return -EBUSY;
4233 + }
4234 + /* Store the file pointer of the first user process registering IRQs */
4235 + tahvo_irq_subscr = filp;
4236 + mutex_unlock(&tahvo_mutex);
4237 +
4238 + if (tahvo_irq_bits & (1 << id))
4239 + return 0;
4240 +
4241 + ret = tahvo_request_irq(id, tahvo_user_irq_handler, id, "");
4242 + if (ret < 0)
4243 + return ret;
4244 +
4245 + /* Mark that this interrupt has a handler */
4246 + tahvo_irq_bits |= 1 << id;
4247 +
4248 + return 0;
4249 +}
4250 +
4251 +/*
4252 + * Unregister all TAHVO interrupt handlers
4253 + */
4254 +static void tahvo_unreg_irq_handlers(void)
4255 +{
4256 + int id;
4257 +
4258 + if (!tahvo_irq_bits)
4259 + return;
4260 +
4261 + for (id = 0; id < MAX_TAHVO_IRQ_HANDLERS; id++)
4262 + if (tahvo_irq_bits & (1 << id))
4263 + tahvo_free_irq(id);
4264 +
4265 + tahvo_irq_bits = 0;
4266 +}
4267 +
4268 +/*
4269 + * Write to TAHVO register.
4270 + * Returns 0 upon success, a negative error value otherwise.
4271 + */
4272 +static int tahvo_user_write_with_mask(u32 field, u16 value)
4273 +{
4274 + u32 mask;
4275 + u32 reg;
4276 + u_short tmp;
4277 + unsigned long flags;
4278 +
4279 + mask = MASK(field);
4280 + reg = REG(field);
4281 +
4282 + /* Detect bad mask and reg */
4283 + if (mask == 0 || reg > TAHVO_REG_MAX ||
4284 + tahvo_access_bits[reg] == READ_ONLY) {
4285 + printk(KERN_ERR PFX "invalid arguments (reg=%#x, mask=%#x)\n",
4286 + reg, mask);
4287 + return -EINVAL;
4288 + }
4289 +
4290 + /* Justify value according to mask */
4291 + while (!(mask & 1)) {
4292 + value = value << 1;
4293 + mask = mask >> 1;
4294 + }
4295 +
4296 + spin_lock_irqsave(&tahvo_lock, flags);
4297 + if (tahvo_access_bits[reg] == TOGGLE) {
4298 + /* No need to detect previous content of register */
4299 + tmp = 0;
4300 + } else {
4301 + /* Read current value of register */
4302 + tmp = tahvo_read_reg(reg);
4303 + }
4304 + /* Generate a new value */
4305 + tmp = (tmp & ~MASK(field)) | (value & MASK(field));
4306 + /* Write data to TAHVO */
4307 + tahvo_write_reg(reg, tmp);
4308 + spin_unlock_irqrestore(&tahvo_lock, flags);
4309 +
4310 + return 0;
4311 +}
4312 +
4313 +/*
4314 + * Read TAHVO register.
4315 + */
4316 +static u32 tahvo_user_read_with_mask(u32 field)
4317 +{
4318 + u_short value;
4319 + u32 mask, reg;
4320 +
4321 + mask = MASK(field);
4322 + reg = REG(field);
4323 +
4324 + /* Detect bad mask and reg */
4325 + if (mask == 0 || reg > TAHVO_REG_MAX) {
4326 + printk(KERN_ERR PFX "invalid arguments (reg=%#x, mask=%#x)\n",
4327 + reg, mask);
4328 + return -EINVAL;
4329 + }
4330 +
4331 + /* Read the register */
4332 + value = tahvo_read_reg(reg) & mask;
4333 +
4334 + /* Right justify value */
4335 + while (!(mask & 1)) {
4336 + value = value >> 1;
4337 + mask = mask >> 1;
4338 + }
4339 +
4340 + return value;
4341 +}
4342 +
4343 +/*
4344 + * Close device
4345 + */
4346 +static int tahvo_close(struct inode *inode, struct file *filp)
4347 +{
4348 + /* Unregister all interrupts that have been registered */
4349 + if (tahvo_irq_subscr == filp) {
4350 + tahvo_unreg_irq_handlers();
4351 + tahvo_irq_subscr = NULL;
4352 + }
4353 +
4354 + return 0;
4355 +}
4356 +
4357 +/*
4358 + * Device control (ioctl)
4359 + */
4360 +static int tahvo_ioctl(struct inode *inode, struct file *filp,
4361 + unsigned int cmd, unsigned long arg)
4362 +{
4363 + struct retu_tahvo_write_parms par;
4364 + int ret;
4365 +
4366 + switch (cmd) {
4367 + case URT_IOCT_IRQ_SUBSCR:
4368 + return tahvo_user_subscribe_to_irq(arg, filp);
4369 + case TAHVO_IOCH_READ:
4370 + return tahvo_user_read_with_mask(arg);
4371 + case TAHVO_IOCX_WRITE:
4372 + ret = copy_from_user(&par, (void __user *) arg, sizeof(par));
4373 + if (ret)
4374 + printk(KERN_ERR "copy_from_user failed: %d\n", ret);
4375 + par.result = tahvo_user_write_with_mask(par.field, par.value);
4376 + ret = copy_to_user((void __user *) arg, &par, sizeof(par));
4377 + if (ret)
4378 + printk(KERN_ERR "copy_to_user failed: %d\n", ret);
4379 + break;
4380 + default:
4381 + return -ENOIOCTLCMD;
4382 + }
4383 + return 0;
4384 +}
4385 +
4386 +/*
4387 + * Read from device
4388 + */
4389 +static ssize_t tahvo_read(struct file *filp, char *buf, size_t count,
4390 + loff_t * offp)
4391 +{
4392 + struct tahvo_irq *irq;
4393 +
4394 + u32 nr, i;
4395 +
4396 + /* read not permitted if neither filp nor anyone has registered IRQs */
4397 + if (tahvo_irq_subscr != filp)
4398 + return -EPERM;
4399 +
4400 + if ((count < sizeof(u32)) || ((count % sizeof(u32)) != 0))
4401 + return -EINVAL;
4402 +
4403 + nr = count / sizeof(u32);
4404 +
4405 + for (i = 0; i < nr; i++) {
4406 + unsigned long flags;
4407 + u32 irq_id;
4408 + int ret;
4409 +
4410 + ret = wait_event_interruptible(tahvo_user_waitqueue,
4411 + !list_empty(&tahvo_irqs));
4412 + if (ret < 0)
4413 + return ret;
4414 +
4415 + spin_lock_irqsave(&tahvo_irqs_lock, flags);
4416 + irq = list_entry((&tahvo_irqs)->next, struct tahvo_irq, node);
4417 + irq_id = irq->id;
4418 + list_move(&irq->node, &tahvo_irqs_reserve);
4419 + spin_unlock_irqrestore(&tahvo_irqs_lock, flags);
4420 +
4421 + ret = copy_to_user(buf + i * sizeof(irq_id), &irq_id,
4422 + sizeof(irq_id));
4423 + if (ret)
4424 + printk(KERN_ERR "copy_to_user failed: %d\n", ret);
4425 + }
4426 +
4427 + return count;
4428 +}
4429 +
4430 +/*
4431 + * Poll method
4432 + */
4433 +static unsigned tahvo_poll(struct file *filp, struct poll_table_struct *pt)
4434 +{
4435 + if (!list_empty(&tahvo_irqs))
4436 + return POLLIN;
4437 +
4438 + poll_wait(filp, &tahvo_user_waitqueue, pt);
4439 +
4440 + if (!list_empty(&tahvo_irqs))
4441 + return POLLIN;
4442 + else
4443 + return 0;
4444 +}
4445 +
4446 +static struct file_operations tahvo_user_fileops = {
4447 + .owner = THIS_MODULE,
4448 + .ioctl = tahvo_ioctl,
4449 + .read = tahvo_read,
4450 + .release = tahvo_close,
4451 + .poll = tahvo_poll
4452 +};
4453 +
4454 +static struct miscdevice tahvo_device = {
4455 + .minor = MISC_DYNAMIC_MINOR,
4456 + .name = "tahvo",
4457 + .fops = &tahvo_user_fileops
4458 +};
4459 +
4460 +/*
4461 + * Initialization
4462 + *
4463 + * @return 0 if successful, error value otherwise.
4464 + */
4465 +int tahvo_user_init(void)
4466 +{
4467 + struct tahvo_irq *irq;
4468 + int res, i;
4469 +
4470 + irq = kmalloc(sizeof(*irq) * TAHVO_MAX_IRQ_BUF_LEN, GFP_KERNEL);
4471 + if (irq == NULL) {
4472 + printk(KERN_ERR PFX "kmalloc failed\n");
4473 + return -ENOMEM;
4474 + }
4475 + memset(irq, 0, sizeof(*irq) * TAHVO_MAX_IRQ_BUF_LEN);
4476 + for (i = 0; i < TAHVO_MAX_IRQ_BUF_LEN; i++)
4477 + list_add(&irq[i].node, &tahvo_irqs_reserve);
4478 +
4479 + tahvo_irq_block = irq;
4480 +
4481 + spin_lock_init(&tahvo_irqs_lock);
4482 + mutex_init(&tahvo_mutex);
4483 +
4484 + /* Request a misc device */
4485 + res = misc_register(&tahvo_device);
4486 + if (res < 0) {
4487 + printk(KERN_ERR PFX "unable to register misc device for %s\n",
4488 + tahvo_device.name);
4489 + kfree(irq);
4490 + return res;
4491 + }
4492 +
4493 + return 0;
4494 +}
4495 +
4496 +/*
4497 + * Cleanup.
4498 + */
4499 +void tahvo_user_cleanup(void)
4500 +{
4501 + /* Unregister our misc device */
4502 + misc_deregister(&tahvo_device);
4503 + /* Unregister and disable all TAHVO interrupts */
4504 + tahvo_unreg_irq_handlers();
4505 + kfree(tahvo_irq_block);
4506 +}
4507 +
4508 +MODULE_DESCRIPTION("Tahvo ASIC user space functions");
4509 +MODULE_LICENSE("GPL");
4510 +MODULE_AUTHOR("Mikko Ylinen");
4511 --- /dev/null
4512 +++ linux-2.6.35/drivers/cbus/user_retu_tahvo.h
4513 @@ -0,0 +1,75 @@
4514 +/**
4515 + * drivers/cbus/user_retu_tahvo.h
4516 + *
4517 + * Copyright (C) 2004, 2005 Nokia Corporation
4518 + *
4519 + * Written by Mikko Ylinen <mikko.k.ylinen@nokia.com>
4520 + *
4521 + * Definitions and types used by both retu-user and tahvo-user.
4522 + *
4523 + * This file is subject to the terms and conditions of the GNU General
4524 + * Public License. See the file "COPYING" in the main directory of this
4525 + * archive for more details.
4526 + *
4527 + * This program is distributed in the hope that it will be useful,
4528 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4529 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4530 + * GNU General Public License for more details.
4531 +
4532 + * You should have received a copy of the GNU General Public License
4533 + * along with this program; if not, write to the Free Software
4534 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
4535 + */
4536 +
4537 +#ifndef _USER_RETU_TAHVO_H
4538 +#define _USER_RETU_TAHVO_H
4539 +
4540 +/* Chip IDs */
4541 +#define CHIP_RETU 1
4542 +#define CHIP_TAHVO 2
4543 +
4544 +/* Register access type bits */
4545 +#define READ_ONLY 1
4546 +#define WRITE_ONLY 2
4547 +#define READ_WRITE 3
4548 +#define TOGGLE 4
4549 +
4550 +#define MASK(field) ((u16)(field & 0xFFFF))
4551 +#define REG(field) ((u16)((field >> 16) & 0x3F))
4552 +
4553 +/*** IOCTL definitions. These should be kept in sync with user space **********/
4554 +
4555 +#define URT_IOC_MAGIC '`'
4556 +
4557 +/*
4558 + * IOCTL function naming conventions:
4559 + * ==================================
4560 + * 0 -- No argument and return value
4561 + * S -- Set through a pointer
4562 + * T -- Tell directly with the argument value
4563 + * G -- Reply by setting through a pointer
4564 + * Q -- response is on the return value
4565 + * X -- S and G atomically
4566 + * H -- T and Q atomically
4567 + */
4568 +
4569 +/* General */
4570 +#define URT_IOCT_IRQ_SUBSCR _IO(URT_IOC_MAGIC, 0)
4571 +
4572 +/* RETU */
4573 +#define RETU_IOCH_READ _IO(URT_IOC_MAGIC, 1)
4574 +#define RETU_IOCX_WRITE _IO(URT_IOC_MAGIC, 2)
4575 +#define RETU_IOCH_ADC_READ _IO(URT_IOC_MAGIC, 3)
4576 +
4577 +/* TAHVO */
4578 +#define TAHVO_IOCH_READ _IO(URT_IOC_MAGIC, 4)
4579 +#define TAHVO_IOCX_WRITE _IO(URT_IOC_MAGIC, 5)
4580 +
4581 +/* This structure is used for writing RETU/TAHVO registers */
4582 +struct retu_tahvo_write_parms {
4583 + u32 field;
4584 + u16 value;
4585 + u8 result;
4586 +};
4587 +
4588 +#endif
4589 --- linux-2.6.35.orig/drivers/Makefile
4590 +++ linux-2.6.35/drivers/Makefile
4591 @@ -74,7 +74,7 @@ obj-$(CONFIG_GAMEPORT) += input/gamepor
4592 obj-$(CONFIG_INPUT) += input/
4593 obj-$(CONFIG_I2O) += message/
4594 obj-$(CONFIG_RTC_LIB) += rtc/
4595 -obj-y += i2c/ media/
4596 +obj-y += i2c/ media/ cbus/
4597 obj-$(CONFIG_PPS) += pps/
4598 obj-$(CONFIG_W1) += w1/
4599 obj-$(CONFIG_POWER_SUPPLY) += power/
4600 --- linux-2.6.35.orig/arch/arm/Kconfig
4601 +++ linux-2.6.35/arch/arm/Kconfig
4602 @@ -1669,6 +1669,10 @@ source "net/Kconfig"
4603
4604 source "drivers/Kconfig"
4605
4606 +if ARCH_OMAP
4607 +source "drivers/cbus/Kconfig"
4608 +endif
4609 +
4610 source "fs/Kconfig"
4611
4612 source "arch/arm/Kconfig.debug"