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 | 356 ++++++++++++++++++
9 drivers/cbus/retu-pwrbutton.c | 118 ++++++
10 drivers/cbus/retu-rtc.c | 477 ++++++++++++++++++++++++
11 drivers/cbus/retu-user.c | 424 ++++++++++++++++++++++
12 drivers/cbus/retu-wdt.c | 387 ++++++++++++++++++++
13 drivers/cbus/retu.c | 468 ++++++++++++++++++++++++
14 drivers/cbus/retu.h | 77 ++++
15 drivers/cbus/tahvo-usb.c | 788 +++++++++++++++++++++++++++++++++++++++++
16 drivers/cbus/tahvo-user.c | 406 +++++++++++++++++++++
17 drivers/cbus/tahvo.c | 443 +++++++++++++++++++++++
18 drivers/cbus/tahvo.h | 61 +++
19 drivers/cbus/user_retu_tahvo.h | 75 +++
20 18 files changed, 4533 insertions(+), 1 deletion(-)
22 Index: linux-2.6.37/drivers/cbus/cbus.c
23 ===================================================================
24 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
25 +++ linux-2.6.37/drivers/cbus/cbus.c 2011-01-27 14:17:39.085000008 +0100
28 + * drivers/cbus/cbus.c
30 + * Support functions for CBUS serial protocol
32 + * Copyright (C) 2004, 2005 Nokia Corporation
34 + * Written by Juha Yrjölä <juha.yrjola@nokia.com>,
35 + * David Weinehall <david.weinehall@nokia.com>, and
36 + * Mikko Ylinen <mikko.k.ylinen@nokia.com>
38 + * This file is subject to the terms and conditions of the GNU General
39 + * Public License. See the file "COPYING" in the main directory of this
40 + * archive for more details.
42 + * This program is distributed in the hope that it will be useful,
43 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
44 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 + * GNU General Public License for more details.
47 + * You should have received a copy of the GNU General Public License
48 + * along with this program; if not, write to the Free Software
49 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
52 +#include <linux/device.h>
53 +#include <linux/init.h>
54 +#include <linux/kernel.h>
55 +#include <linux/delay.h>
56 +#include <linux/spinlock.h>
57 +#include <linux/gpio.h>
58 +#include <linux/platform_device.h>
59 +#include <linux/slab.h>
62 +#include <asm/mach-types.h>
64 +#include <plat/board.h>
65 +#include <plat/cbus.h>
69 +struct cbus_host *cbus_host = NULL;
70 +EXPORT_SYMBOL(cbus_host);
72 +#ifdef CONFIG_ARCH_OMAP1
73 +/* We use our own MPUIO functions to get closer to 1MHz bus speed */
75 +static inline void cbus_set_gpio_direction(u32 base, int mpuio, int is_input)
80 + w = __raw_readw(base + OMAP_MPUIO_IO_CNTL);
85 + __raw_writew(w, base + OMAP_MPUIO_IO_CNTL);
89 +static inline void cbus_set_gpio_dataout(u32 base, int mpuio, int enable)
94 + w = __raw_readw(base + OMAP_MPUIO_OUTPUT);
99 + __raw_writew(w, base + OMAP_MPUIO_OUTPUT);
102 +static inline int cbus_get_gpio_datain(u32 base, int mpuio)
106 + return (__raw_readw(base + OMAP_MPUIO_INPUT_LATCH) & (1 << mpuio)) != 0;
109 +static void cbus_send_bit(struct cbus_host *host, u32 base, int bit,
112 + cbus_set_gpio_dataout(base, host->dat_gpio, bit ? 1 : 0);
113 + cbus_set_gpio_dataout(base, host->clk_gpio, 1);
115 + /* The data bit is read on the rising edge of CLK */
117 + cbus_set_gpio_direction(base, host->dat_gpio, 1);
119 + cbus_set_gpio_dataout(base, host->clk_gpio, 0);
122 +static u8 cbus_receive_bit(struct cbus_host *host, u32 base)
126 + cbus_set_gpio_dataout(base, host->clk_gpio, 1);
127 + ret = cbus_get_gpio_datain(base, host->dat_gpio);
128 + cbus_set_gpio_dataout(base, host->clk_gpio, 0);
133 +#define cbus_output(base, gpio, val) cbus_set_gpio_direction(base, gpio, 0)
137 +#define cbus_output(base, gpio, val) gpio_direction_output(gpio, val)
138 +#define cbus_set_gpio_dataout(base, gpio, enable) gpio_set_value(gpio, enable)
139 +#define cbus_get_gpio_datain(base, int, gpio) gpio_get_value(gpio)
141 +static void _cbus_send_bit(struct cbus_host *host, int bit, int set_to_input)
143 + gpio_set_value(host->dat_gpio, bit ? 1 : 0);
144 + gpio_set_value(host->clk_gpio, 1);
146 + /* The data bit is read on the rising edge of CLK */
148 + gpio_direction_input(host->dat_gpio);
150 + gpio_set_value(host->clk_gpio, 0);
153 +static u8 _cbus_receive_bit(struct cbus_host *host)
157 + gpio_set_value(host->clk_gpio, 1);
158 + ret = gpio_get_value(host->dat_gpio);
159 + gpio_set_value(host->clk_gpio, 0);
164 +#define cbus_send_bit(host, base, bit, set_to_input) _cbus_send_bit(host, bit, set_to_input)
165 +#define cbus_receive_bit(host, base) _cbus_receive_bit(host)
169 +static int cbus_transfer(struct cbus_host *host, int dev, int reg, int data)
173 + unsigned long flags;
176 +#ifdef CONFIG_ARCH_OMAP1
177 + base = OMAP1_IO_ADDRESS(OMAP1_MPUIO_BASE);
185 + /* We don't want interrupts disturbing our transfer */
186 + spin_lock_irqsave(&host->lock, flags);
188 + /* Reset state and start of transfer, SEL stays down during transfer */
189 + cbus_set_gpio_dataout(base, host->sel_gpio, 0);
191 + /* Set the DAT pin to output */
192 + cbus_output(base, host->dat_gpio, 1);
194 + /* Send the device address */
195 + for (i = 3; i > 0; i--)
196 + cbus_send_bit(host, base, dev & (1 << (i - 1)), 0);
198 + /* Send the rw flag */
199 + cbus_send_bit(host, base, is_read, 0);
201 + /* Send the register address */
202 + for (i = 5; i > 0; i--) {
203 + int set_to_input = 0;
205 + if (is_read && i == 1)
208 + cbus_send_bit(host, base, reg & (1 << (i - 1)), set_to_input);
212 + for (i = 16; i > 0; i--)
213 + cbus_send_bit(host, base, data & (1 << (i - 1)), 0);
215 + cbus_set_gpio_dataout(base, host->clk_gpio, 1);
218 + for (i = 16; i > 0; i--) {
219 + u8 bit = cbus_receive_bit(host, base);
222 + data |= 1 << (i - 1);
226 + /* Indicate end of transfer, SEL goes up until next transfer */
227 + cbus_set_gpio_dataout(base, host->sel_gpio, 1);
228 + cbus_set_gpio_dataout(base, host->clk_gpio, 1);
229 + cbus_set_gpio_dataout(base, host->clk_gpio, 0);
231 + spin_unlock_irqrestore(&host->lock, flags);
233 + return is_read ? data : 0;
237 + * Read a given register from the device
239 +int cbus_read_reg(struct cbus_host *host, int dev, int reg)
241 + return cbus_host ? cbus_transfer(host, dev, reg, -1) : -ENODEV;
243 +EXPORT_SYMBOL(cbus_read_reg);
246 + * Write to a given register of the device
248 +int cbus_write_reg(struct cbus_host *host, int dev, int reg, u16 val)
250 + return cbus_host ? cbus_transfer(host, dev, reg, (int)val) : -ENODEV;
252 +EXPORT_SYMBOL(cbus_write_reg);
254 +static int __init cbus_bus_probe(struct platform_device *pdev)
256 + struct cbus_host *chost;
257 + struct cbus_host_platform_data *pdata = pdev->dev.platform_data;
260 + chost = kzalloc(sizeof (*chost), GFP_KERNEL);
264 + spin_lock_init(&chost->lock);
266 + chost->clk_gpio = pdata->clk_gpio;
267 + chost->dat_gpio = pdata->dat_gpio;
268 + chost->sel_gpio = pdata->sel_gpio;
270 + if ((ret = gpio_request(chost->clk_gpio, "CBUS clk")) < 0)
273 + if ((ret = gpio_request(chost->dat_gpio, "CBUS data")) < 0)
276 + if ((ret = gpio_request(chost->sel_gpio, "CBUS sel")) < 0)
279 + gpio_direction_output(chost->clk_gpio, 0);
280 + gpio_direction_input(chost->dat_gpio);
281 + gpio_direction_output(chost->sel_gpio, 1);
283 + gpio_set_value(chost->clk_gpio, 1);
284 + gpio_set_value(chost->clk_gpio, 0);
286 + platform_set_drvdata(pdev, chost);
292 + gpio_free(chost->dat_gpio);
294 + gpio_free(chost->clk_gpio);
301 +static void __exit cbus_bus_remove(struct platform_device *pdev)
303 + struct cbus_host *chost = platform_get_drvdata(pdev);
305 + gpio_free(chost->dat_gpio);
306 + gpio_free(chost->clk_gpio);
310 +static struct platform_driver cbus_driver = {
311 + .remove = __exit_p(cbus_bus_remove),
317 +static int __init cbus_bus_init(void)
319 + return platform_driver_probe(&cbus_driver, cbus_bus_probe);
322 +subsys_initcall(cbus_bus_init);
324 +static void __exit cbus_bus_exit(void)
326 + platform_driver_unregister(&cbus_driver);
328 +module_exit(cbus_bus_exit);
330 +MODULE_DESCRIPTION("CBUS serial protocol");
331 +MODULE_LICENSE("GPL");
332 +MODULE_AUTHOR("Juha Yrjölä");
333 +MODULE_AUTHOR("David Weinehall");
334 +MODULE_AUTHOR("Mikko Ylinen");
336 Index: linux-2.6.37/drivers/cbus/cbus.h
337 ===================================================================
338 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
339 +++ linux-2.6.37/drivers/cbus/cbus.h 2011-01-27 14:17:39.085000008 +0100
342 + * drivers/cbus/cbus.h
344 + * Copyright (C) 2004, 2005 Nokia Corporation
346 + * Written by Juha Yrjölä <juha.yrjola@nokia.com> and
347 + * David Weinehall <david.weinehall@nokia.com>
349 + * This file is subject to the terms and conditions of the GNU General
350 + * Public License. See the file "COPYING" in the main directory of this
351 + * archive for more details.
353 + * This program is distributed in the hope that it will be useful,
354 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
355 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
356 + * GNU General Public License for more details.
358 + * You should have received a copy of the GNU General Public License
359 + * along with this program; if not, write to the Free Software
360 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
363 +#ifndef __DRIVERS_CBUS_CBUS_H
364 +#define __DRIVERS_CBUS_CBUS_H
367 + int clk_gpio, dat_gpio, sel_gpio;
371 +extern struct cbus_host *cbus_host;
373 +extern int cbus_read_reg(struct cbus_host *host, int dev, int reg);
374 +extern int cbus_write_reg(struct cbus_host *host, int dev, int reg, u16 val);
376 +#endif /* __DRIVERS_CBUS_CBUS_H */
377 Index: linux-2.6.37/drivers/cbus/Kconfig
378 ===================================================================
379 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
380 +++ linux-2.6.37/drivers/cbus/Kconfig 2011-01-27 14:17:39.085000008 +0100
383 +# CBUS device configuration
389 + depends on ARCH_OMAP
390 + bool "CBUS support on OMAP"
392 + CBUS is a proprietary serial protocol by Nokia. It is mainly
393 + used for accessing Energy Management auxiliary chips.
395 + If you want CBUS support, you should say Y here.
399 + bool "Support for Tahvo"
401 + Tahvo is a mixed signal ASIC with some system features
403 + If you want Tahvo support, you should say Y here.
405 +config CBUS_TAHVO_USER
406 + depends on CBUS_TAHVO
407 + bool "Support for Tahvo user space functions"
409 + If you want support for Tahvo's user space read/write etc. functions,
410 + you should say Y here.
412 +config CBUS_TAHVO_USB
413 + depends on CBUS_TAHVO && USB
414 + tristate "Support for Tahvo USB transceiver"
416 + If you want Tahvo support for USB transceiver, say Y or M here.
418 +config CBUS_TAHVO_USB_HOST_BY_DEFAULT
419 + depends on CBUS_TAHVO_USB && USB_OTG
420 + boolean "Device in USB host mode by default"
422 + Say Y here, if you want the device to enter USB host mode
423 + by default on bootup.
427 + bool "Support for Retu"
429 + Retu is a mixed signal ASIC with some system features
431 + If you want Retu support, you should say Y here.
433 +config CBUS_RETU_USER
434 + depends on CBUS_RETU
435 + bool "Support for Retu user space functions"
437 + If you want support for Retu's user space read/write etc. functions,
438 + you should say Y here.
440 +config CBUS_RETU_POWERBUTTON
441 + depends on CBUS_RETU
442 + bool "Support for Retu power button"
444 + The power button on Nokia 770 is connected to the Retu ASIC.
446 + If you want support for the Retu power button, you should say Y here.
448 +config CBUS_RETU_RTC
449 + depends on CBUS_RETU && SYSFS
450 + tristate "Support for Retu pseudo-RTC"
452 + Say Y here if you want support for the device that alleges to be an
453 + RTC in Retu. This will expose a sysfs interface for it.
455 +config CBUS_RETU_WDT
456 + depends on CBUS_RETU && SYSFS && WATCHDOG
457 + tristate "Support for Retu watchdog timer"
459 + Say Y here if you want support for the watchdog in Retu. This will
460 + expose a sysfs interface to grok it.
462 +config CBUS_RETU_HEADSET
463 + depends on CBUS_RETU && SYSFS
464 + tristate "Support for headset detection with Retu/Vilma"
466 + Say Y here if you want support detecting a headset that's connected
467 + to Retu/Vilma. Detection state and events are exposed through
471 Index: linux-2.6.37/drivers/cbus/Makefile
472 ===================================================================
473 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
474 +++ linux-2.6.37/drivers/cbus/Makefile 2011-01-27 14:17:39.085000008 +0100
477 +# Makefile for CBUS.
480 +obj-$(CONFIG_CBUS) += cbus.o
481 +obj-$(CONFIG_CBUS_TAHVO) += tahvo.o
482 +obj-$(CONFIG_CBUS_RETU) += retu.o
483 +obj-$(CONFIG_CBUS_TAHVO_USB) += tahvo-usb.o
484 +obj-$(CONFIG_CBUS_RETU_POWERBUTTON) += retu-pwrbutton.o
485 +obj-$(CONFIG_CBUS_RETU_RTC) += retu-rtc.o
486 +obj-$(CONFIG_CBUS_RETU_WDT) += retu-wdt.o
487 +obj-$(CONFIG_CBUS_TAHVO_USER) += tahvo-user.o
488 +obj-$(CONFIG_CBUS_RETU_USER) += retu-user.o
489 +obj-$(CONFIG_CBUS_RETU_HEADSET) += retu-headset.o
490 Index: linux-2.6.37/drivers/cbus/retu.c
491 ===================================================================
492 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
493 +++ linux-2.6.37/drivers/cbus/retu.c 2011-01-27 14:17:39.085000008 +0100
496 + * drivers/cbus/retu.c
498 + * Support functions for Retu ASIC
500 + * Copyright (C) 2004, 2005 Nokia Corporation
502 + * Written by Juha Yrjölä <juha.yrjola@nokia.com>,
503 + * David Weinehall <david.weinehall@nokia.com>, and
504 + * Mikko Ylinen <mikko.k.ylinen@nokia.com>
506 + * This file is subject to the terms and conditions of the GNU General
507 + * Public License. See the file "COPYING" in the main directory of this
508 + * archive for more details.
510 + * This program is distributed in the hope that it will be useful,
511 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
512 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
513 + * GNU General Public License for more details.
515 + * You should have received a copy of the GNU General Public License
516 + * along with this program; if not, write to the Free Software
517 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
520 +#include <linux/module.h>
521 +#include <linux/init.h>
523 +#include <linux/kernel.h>
524 +#include <linux/errno.h>
525 +#include <linux/device.h>
526 +#include <linux/miscdevice.h>
527 +#include <linux/poll.h>
528 +#include <linux/fs.h>
529 +#include <linux/irq.h>
530 +#include <linux/interrupt.h>
531 +#include <linux/platform_device.h>
532 +#include <linux/gpio.h>
534 +#include <asm/uaccess.h>
535 +#include <asm/mach-types.h>
537 +#include <plat/mux.h>
538 +#include <plat/board.h>
543 +#define RETU_ID 0x01
544 +#define PFX "retu: "
546 +static int retu_initialized;
547 +static int retu_irq_pin;
548 +static int retu_is_vilma;
550 +static struct tasklet_struct retu_tasklet;
551 +spinlock_t retu_lock = SPIN_LOCK_UNLOCKED;
553 +static struct completion device_release;
555 +struct retu_irq_handler_desc {
556 + int (*func)(unsigned long);
561 +static struct retu_irq_handler_desc retu_irq_handlers[MAX_RETU_IRQ_HANDLERS];
564 + * retu_read_reg - Read a value from a register in Retu
565 + * @reg: the register to read from
567 + * This function returns the contents of the specified register
569 +int retu_read_reg(int reg)
571 + BUG_ON(!retu_initialized);
572 + return cbus_read_reg(cbus_host, RETU_ID, reg);
576 + * retu_write_reg - Write a value to a register in Retu
577 + * @reg: the register to write to
578 + * @reg: the value to write to the register
580 + * This function writes a value to the specified register
582 +void retu_write_reg(int reg, u16 val)
584 + BUG_ON(!retu_initialized);
585 + cbus_write_reg(cbus_host, RETU_ID, reg, val);
588 +void retu_set_clear_reg_bits(int reg, u16 set, u16 clear)
590 + unsigned long flags;
593 + spin_lock_irqsave(&retu_lock, flags);
594 + w = retu_read_reg(reg);
597 + retu_write_reg(reg, w);
598 + spin_unlock_irqrestore(&retu_lock, flags);
601 +#define ADC_MAX_CHAN_NUMBER 13
603 +int retu_read_adc(int channel)
605 + unsigned long flags;
608 + if (channel < 0 || channel > ADC_MAX_CHAN_NUMBER)
611 + spin_lock_irqsave(&retu_lock, flags);
613 + if ((channel == 8) && retu_is_vilma) {
614 + int scr = retu_read_reg(RETU_REG_ADCSCR);
615 + int ch = (retu_read_reg(RETU_REG_ADCR) >> 10) & 0xf;
616 + if (((scr & 0xff) != 0) && (ch != 8))
617 + retu_write_reg (RETU_REG_ADCSCR, (scr & ~0xff));
620 + /* Select the channel and read result */
621 + retu_write_reg(RETU_REG_ADCR, channel << 10);
622 + res = retu_read_reg(RETU_REG_ADCR) & 0x3ff;
625 + retu_write_reg(RETU_REG_ADCR, (1 << 13));
628 + spin_unlock_irqrestore(&retu_lock, flags);
634 +static u16 retu_disable_bogus_irqs(u16 mask)
638 + for (i = 0; i < MAX_RETU_IRQ_HANDLERS; i++) {
639 + if (mask & (1 << i))
641 + if (retu_irq_handlers[i].func != NULL)
643 + /* an IRQ was enabled but we don't have a handler for it */
644 + printk(KERN_INFO PFX "disabling bogus IRQ %d\n", i);
651 + * Disable given RETU interrupt
653 +void retu_disable_irq(int id)
655 + unsigned long flags;
658 + spin_lock_irqsave(&retu_lock, flags);
659 + mask = retu_read_reg(RETU_REG_IMR);
661 + mask = retu_disable_bogus_irqs(mask);
662 + retu_write_reg(RETU_REG_IMR, mask);
663 + spin_unlock_irqrestore(&retu_lock, flags);
667 + * Enable given RETU interrupt
669 +void retu_enable_irq(int id)
671 + unsigned long flags;
675 + printk("Enabling Retu IRQ %d\n", id);
678 + spin_lock_irqsave(&retu_lock, flags);
679 + mask = retu_read_reg(RETU_REG_IMR);
680 + mask &= ~(1 << id);
681 + mask = retu_disable_bogus_irqs(mask);
682 + retu_write_reg(RETU_REG_IMR, mask);
683 + spin_unlock_irqrestore(&retu_lock, flags);
687 + * Acknowledge given RETU interrupt
689 +void retu_ack_irq(int id)
691 + retu_write_reg(RETU_REG_IDR, 1 << id);
695 + * RETU interrupt handler. Only schedules the tasklet.
697 +static irqreturn_t retu_irq_handler(int irq, void *dev_id)
699 + tasklet_schedule(&retu_tasklet);
700 + return IRQ_HANDLED;
706 +static void retu_tasklet_handler(unsigned long data)
708 + struct retu_irq_handler_desc *hnd;
714 + id = retu_read_reg(RETU_REG_IDR);
715 + im = ~retu_read_reg(RETU_REG_IMR);
721 + for (i = 0; id != 0; i++, id >>= 1) {
724 + hnd = &retu_irq_handlers[i];
725 + if (hnd->func == NULL) {
726 + /* Spurious retu interrupt - disable and ack it */
727 + printk(KERN_INFO "Spurious Retu interrupt "
729 + retu_disable_irq(i);
733 + hnd->func(hnd->arg);
735 + * Don't acknowledge the interrupt here
736 + * It must be done explicitly
743 + * Register the handler for a given RETU interrupt source.
745 +int retu_request_irq(int id, void *irq_handler, unsigned long arg, char *name)
747 + struct retu_irq_handler_desc *hnd;
749 + if (irq_handler == NULL || id >= MAX_RETU_IRQ_HANDLERS ||
751 + printk(KERN_ERR PFX "Invalid arguments to %s\n",
755 + hnd = &retu_irq_handlers[id];
756 + if (hnd->func != NULL) {
757 + printk(KERN_ERR PFX "IRQ %d already reserved\n", id);
760 + printk(KERN_INFO PFX "Registering interrupt %d for device %s\n",
762 + hnd->func = irq_handler;
764 + strlcpy(hnd->name, name, sizeof(hnd->name));
767 + retu_enable_irq(id);
773 + * Unregister the handler for a given RETU interrupt source.
775 +void retu_free_irq(int id)
777 + struct retu_irq_handler_desc *hnd;
779 + if (id >= MAX_RETU_IRQ_HANDLERS) {
780 + printk(KERN_ERR PFX "Invalid argument to %s\n",
784 + hnd = &retu_irq_handlers[id];
785 + if (hnd->func == NULL) {
786 + printk(KERN_ERR PFX "IRQ %d already freed\n", id);
790 + retu_disable_irq(id);
795 + * retu_power_off - Shut down power to system
797 + * This function puts the system in power off state
799 +static void retu_power_off(void)
801 + /* Ignore power button state */
802 + retu_write_reg(RETU_REG_CC1, retu_read_reg(RETU_REG_CC1) | 2);
803 + /* Expire watchdog immediately */
804 + retu_write_reg(RETU_REG_WATCHDOG, 0);
805 + /* Wait for poweroff*/
810 + * retu_probe - Probe for Retu ASIC
811 + * @dev: the Retu device
813 + * Probe for the Retu ASIC and allocate memory
814 + * for its device-struct if found
816 +static int __devinit retu_probe(struct device *dev)
820 + /* Prepare tasklet */
821 + tasklet_init(&retu_tasklet, retu_tasklet_handler, 0);
823 + /* REVISIT: Pass these from board-*.c files in platform_data */
824 + if (machine_is_nokia770()) {
826 + } else if (machine_is_nokia_n800() || machine_is_nokia_n810() ||
827 + machine_is_nokia_n810_wimax()) {
828 + retu_irq_pin = 108;
830 + printk(KERN_ERR "cbus: Unsupported board for tahvo\n");
834 + if ((ret = gpio_request(retu_irq_pin, "RETU irq")) < 0) {
835 + printk(KERN_ERR PFX "Unable to reserve IRQ GPIO\n");
839 + /* Set the pin as input */
840 + gpio_direction_input(retu_irq_pin);
842 + /* Rising edge triggers the IRQ */
843 + set_irq_type(gpio_to_irq(retu_irq_pin), IRQ_TYPE_EDGE_RISING);
845 + retu_initialized = 1;
847 + rev = retu_read_reg(RETU_REG_ASICR) & 0xff;
848 + if (rev & (1 << 7))
851 + printk(KERN_INFO "%s v%d.%d found\n", retu_is_vilma ? "Vilma" : "Retu",
852 + (rev >> 4) & 0x07, rev & 0x0f);
854 + /* Mask all RETU interrupts */
855 + retu_write_reg(RETU_REG_IMR, 0xffff);
857 + ret = request_irq(gpio_to_irq(retu_irq_pin), retu_irq_handler, 0,
860 + printk(KERN_ERR PFX "Unable to register IRQ handler\n");
861 + gpio_free(retu_irq_pin);
864 + set_irq_wake(gpio_to_irq(retu_irq_pin), 1);
866 + /* Register power off function */
867 + pm_power_off = retu_power_off;
869 +#ifdef CONFIG_CBUS_RETU_USER
870 + /* Initialize user-space interface */
871 + if (retu_user_init() < 0) {
872 + printk(KERN_ERR "Unable to initialize driver\n");
873 + free_irq(gpio_to_irq(retu_irq_pin), 0);
874 + gpio_free(retu_irq_pin);
882 +static int retu_remove(struct device *dev)
884 +#ifdef CONFIG_CBUS_RETU_USER
885 + retu_user_cleanup();
887 + /* Mask all RETU interrupts */
888 + retu_write_reg(RETU_REG_IMR, 0xffff);
889 + free_irq(gpio_to_irq(retu_irq_pin), 0);
890 + gpio_free(retu_irq_pin);
891 + tasklet_kill(&retu_tasklet);
896 +static void retu_device_release(struct device *dev)
898 + complete(&device_release);
901 +static struct device_driver retu_driver = {
903 + .bus = &platform_bus_type,
904 + .probe = retu_probe,
905 + .remove = retu_remove,
908 +static struct platform_device retu_device = {
912 + .release = retu_device_release,
917 + * retu_init - initialise Retu driver
919 + * Initialise the Retu driver and return 0 if everything worked ok
921 +static int __init retu_init(void)
925 + printk(KERN_INFO "Retu/Vilma driver initialising\n");
927 + init_completion(&device_release);
929 + if ((ret = driver_register(&retu_driver)) < 0)
932 + if ((ret = platform_device_register(&retu_device)) < 0) {
933 + driver_unregister(&retu_driver);
942 +static void __exit retu_exit(void)
944 + platform_device_unregister(&retu_device);
945 + driver_unregister(&retu_driver);
946 + wait_for_completion(&device_release);
949 +EXPORT_SYMBOL(retu_request_irq);
950 +EXPORT_SYMBOL(retu_free_irq);
951 +EXPORT_SYMBOL(retu_enable_irq);
952 +EXPORT_SYMBOL(retu_disable_irq);
953 +EXPORT_SYMBOL(retu_ack_irq);
954 +EXPORT_SYMBOL(retu_read_reg);
955 +EXPORT_SYMBOL(retu_write_reg);
957 +subsys_initcall(retu_init);
958 +module_exit(retu_exit);
960 +MODULE_DESCRIPTION("Retu ASIC control");
961 +MODULE_LICENSE("GPL");
962 +MODULE_AUTHOR("Juha Yrjölä, David Weinehall, and Mikko Ylinen");
963 Index: linux-2.6.37/drivers/cbus/retu.h
964 ===================================================================
965 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
966 +++ linux-2.6.37/drivers/cbus/retu.h 2011-01-27 14:17:39.085000008 +0100
969 + * drivers/cbus/retu.h
971 + * Copyright (C) 2004, 2005 Nokia Corporation
973 + * Written by Juha Yrjölä <juha.yrjola@nokia.com> and
974 + * David Weinehall <david.weinehall@nokia.com>
976 + * This file is subject to the terms and conditions of the GNU General
977 + * Public License. See the file "COPYING" in the main directory of this
978 + * archive for more details.
980 + * This program is distributed in the hope that it will be useful,
981 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
982 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
983 + * GNU General Public License for more details.
985 + * You should have received a copy of the GNU General Public License
986 + * along with this program; if not, write to the Free Software
987 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
990 +#ifndef __DRIVERS_CBUS_RETU_H
991 +#define __DRIVERS_CBUS_RETU_H
993 +#include <linux/types.h>
996 +#define RETU_REG_ASICR 0x00 /* ASIC ID & revision */
997 +#define RETU_REG_IDR 0x01 /* Interrupt ID */
998 +#define RETU_REG_IMR 0x02 /* Interrupt mask */
999 +#define RETU_REG_RTCDSR 0x03 /* RTC seconds register */
1000 +#define RETU_REG_RTCHMR 0x04 /* RTC hours and minutes register */
1001 +#define RETU_REG_RTCHMAR 0x05 /* RTC hours and minutes alarm and time set register */
1002 +#define RETU_REG_RTCCALR 0x06 /* RTC calibration register */
1003 +#define RETU_REG_ADCR 0x08 /* ADC result */
1004 +#define RETU_REG_ADCSCR 0x09 /* ADC sample ctrl */
1005 +#define RETU_REG_CC1 0x0d /* Common control register 1 */
1006 +#define RETU_REG_CC2 0x0e /* Common control register 2 */
1007 +#define RETU_REG_CTRL_CLR 0x0f /* Regulator clear register */
1008 +#define RETU_REG_CTRL_SET 0x10 /* Regulator set register */
1009 +#define RETU_REG_STATUS 0x16 /* Status register */
1010 +#define RETU_REG_WATCHDOG 0x17 /* Watchdog register */
1011 +#define RETU_REG_AUDTXR 0x18 /* Audio Codec Tx register */
1012 +#define RETU_REG_MAX 0x1f
1014 +/* Interrupt sources */
1015 +#define RETU_INT_PWR 0
1016 +#define RETU_INT_CHAR 1
1017 +#define RETU_INT_RTCS 2
1018 +#define RETU_INT_RTCM 3
1019 +#define RETU_INT_RTCD 4
1020 +#define RETU_INT_RTCA 5
1021 +#define RETU_INT_HOOK 6
1022 +#define RETU_INT_HEAD 7
1023 +#define RETU_INT_ADCS 8
1025 +#define MAX_RETU_IRQ_HANDLERS 16
1027 +int retu_read_reg(int reg);
1028 +void retu_write_reg(int reg, u16 val);
1029 +void retu_set_clear_reg_bits(int reg, u16 set, u16 clear);
1030 +int retu_read_adc(int channel);
1031 +int retu_request_irq(int id, void *irq_handler, unsigned long arg, char *name);
1032 +void retu_free_irq(int id);
1033 +void retu_enable_irq(int id);
1034 +void retu_disable_irq(int id);
1035 +void retu_ack_irq(int id);
1037 +#ifdef CONFIG_CBUS_RETU_USER
1038 +int retu_user_init(void);
1039 +void retu_user_cleanup(void);
1042 +extern spinlock_t retu_lock;
1044 +#endif /* __DRIVERS_CBUS_RETU_H */
1045 Index: linux-2.6.37/drivers/cbus/retu-headset.c
1046 ===================================================================
1047 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1048 +++ linux-2.6.37/drivers/cbus/retu-headset.c 2011-01-27 14:17:39.085000008 +0100
1051 + * Retu/Vilma headset detection
1053 + * Copyright (C) 2006 Nokia Corporation
1055 + * Written by Juha Yrjölä
1057 + * This file is subject to the terms and conditions of the GNU General
1058 + * Public License. See the file "COPYING" in the main directory of this
1059 + * archive for more details.
1061 + * This program is distributed in the hope that it will be useful,
1062 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1063 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1064 + * GNU General Public License for more details.
1066 + * You should have received a copy of the GNU General Public License
1067 + * along with this program; if not, write to the Free Software
1068 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1071 +#include <linux/module.h>
1072 +#include <linux/init.h>
1073 +#include <linux/kernel.h>
1074 +#include <linux/delay.h>
1075 +#include <linux/input.h>
1076 +#include <linux/platform_device.h>
1077 +#include <linux/slab.h>
1081 +#define RETU_ADC_CHANNEL_HOOKDET 0x05
1083 +#define RETU_HEADSET_KEY KEY_PHONE
1085 +struct retu_headset {
1087 + struct mutex mutex;
1088 + struct platform_device *pdev;
1089 + struct input_dev *idev;
1090 + unsigned bias_enabled;
1091 + unsigned detection_enabled;
1093 + struct timer_list enable_timer;
1094 + struct timer_list detect_timer;
1097 +static void retu_headset_set_bias(int enable)
1100 + retu_set_clear_reg_bits(RETU_REG_AUDTXR,
1101 + (1 << 0) | (1 << 1), 0);
1103 + retu_set_clear_reg_bits(RETU_REG_AUDTXR, 1 << 3, 0);
1105 + retu_set_clear_reg_bits(RETU_REG_AUDTXR, 0,
1106 + (1 << 0) | (1 << 1) | (1 << 3));
1110 +static void retu_headset_enable(struct retu_headset *hs)
1112 + mutex_lock(&hs->mutex);
1113 + if (!hs->bias_enabled) {
1114 + hs->bias_enabled = 1;
1115 + retu_headset_set_bias(1);
1117 + mutex_unlock(&hs->mutex);
1120 +static void retu_headset_disable(struct retu_headset *hs)
1122 + mutex_lock(&hs->mutex);
1123 + if (hs->bias_enabled) {
1124 + hs->bias_enabled = 0;
1125 + retu_headset_set_bias(0);
1127 + mutex_unlock(&hs->mutex);
1130 +static void retu_headset_det_enable(struct retu_headset *hs)
1132 + mutex_lock(&hs->mutex);
1133 + if (!hs->detection_enabled) {
1134 + hs->detection_enabled = 1;
1135 + retu_set_clear_reg_bits(RETU_REG_CC1, (1 << 10) | (1 << 8), 0);
1136 + retu_enable_irq(RETU_INT_HOOK);
1138 + mutex_unlock(&hs->mutex);
1141 +static void retu_headset_det_disable(struct retu_headset *hs)
1143 + unsigned long flags;
1145 + mutex_lock(&hs->mutex);
1146 + if (hs->detection_enabled) {
1147 + hs->detection_enabled = 0;
1148 + retu_disable_irq(RETU_INT_HOOK);
1149 + del_timer_sync(&hs->enable_timer);
1150 + del_timer_sync(&hs->detect_timer);
1151 + spin_lock_irqsave(&hs->lock, flags);
1153 + input_report_key(hs->idev, RETU_HEADSET_KEY, 0);
1154 + spin_unlock_irqrestore(&hs->lock, flags);
1155 + retu_set_clear_reg_bits(RETU_REG_CC1, 0, (1 << 10) | (1 << 8));
1157 + mutex_unlock(&hs->mutex);
1160 +static ssize_t retu_headset_hookdet_show(struct device *dev,
1161 + struct device_attribute *attr,
1166 + val = retu_read_adc(RETU_ADC_CHANNEL_HOOKDET);
1167 + return sprintf(buf, "%d\n", val);
1170 +static DEVICE_ATTR(hookdet, S_IRUGO, retu_headset_hookdet_show, NULL);
1172 +static ssize_t retu_headset_enable_show(struct device *dev,
1173 + struct device_attribute *attr,
1176 + struct retu_headset *hs = dev_get_drvdata(dev);
1178 + return sprintf(buf, "%u\n", hs->bias_enabled);
1181 +static ssize_t retu_headset_enable_store(struct device *dev,
1182 + struct device_attribute *attr,
1183 + const char *buf, size_t count)
1185 + struct retu_headset *hs = dev_get_drvdata(dev);
1188 + if (sscanf(buf, "%u", &enable) != 1)
1191 + retu_headset_enable(hs);
1193 + retu_headset_disable(hs);
1197 +static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR | S_IWGRP,
1198 + retu_headset_enable_show, retu_headset_enable_store);
1200 +static ssize_t retu_headset_enable_det_show(struct device *dev,
1201 + struct device_attribute *attr,
1204 + struct retu_headset *hs = dev_get_drvdata(dev);
1206 + return sprintf(buf, "%u\n", hs->detection_enabled);
1209 +static ssize_t retu_headset_enable_det_store(struct device *dev,
1210 + struct device_attribute *attr,
1211 + const char *buf, size_t count)
1213 + struct retu_headset *hs = dev_get_drvdata(dev);
1216 + if (sscanf(buf, "%u", &enable) != 1)
1219 + retu_headset_det_enable(hs);
1221 + retu_headset_det_disable(hs);
1225 +static DEVICE_ATTR(enable_det, S_IRUGO | S_IWUSR | S_IWGRP,
1226 + retu_headset_enable_det_show,
1227 + retu_headset_enable_det_store);
1229 +static void retu_headset_hook_interrupt(unsigned long arg)
1231 + struct retu_headset *hs = (struct retu_headset *) arg;
1232 + unsigned long flags;
1234 + retu_ack_irq(RETU_INT_HOOK);
1235 + spin_lock_irqsave(&hs->lock, flags);
1236 + if (!hs->pressed) {
1237 + /* Headset button was just pressed down. */
1239 + input_report_key(hs->idev, RETU_HEADSET_KEY, 1);
1241 + spin_unlock_irqrestore(&hs->lock, flags);
1242 + retu_set_clear_reg_bits(RETU_REG_CC1, 0, (1 << 10) | (1 << 8));
1243 + mod_timer(&hs->enable_timer, jiffies + msecs_to_jiffies(50));
1246 +static void retu_headset_enable_timer(unsigned long arg)
1248 + struct retu_headset *hs = (struct retu_headset *) arg;
1250 + retu_set_clear_reg_bits(RETU_REG_CC1, (1 << 10) | (1 << 8), 0);
1251 + mod_timer(&hs->detect_timer, jiffies + msecs_to_jiffies(350));
1254 +static void retu_headset_detect_timer(unsigned long arg)
1256 + struct retu_headset *hs = (struct retu_headset *) arg;
1257 + unsigned long flags;
1259 + spin_lock_irqsave(&hs->lock, flags);
1260 + if (hs->pressed) {
1262 + input_report_key(hs->idev, RETU_HEADSET_KEY, 0);
1264 + spin_unlock_irqrestore(&hs->lock, flags);
1267 +static int __init retu_headset_probe(struct platform_device *pdev)
1269 + struct retu_headset *hs;
1272 + hs = kzalloc(sizeof(*hs), GFP_KERNEL);
1278 + hs->idev = input_allocate_device();
1279 + if (hs->idev == NULL) {
1283 + hs->idev->name = "retu-headset";
1284 + hs->idev->dev.parent = &pdev->dev;
1285 + set_bit(EV_KEY, hs->idev->evbit);
1286 + set_bit(RETU_HEADSET_KEY, hs->idev->keybit);
1287 + r = input_register_device(hs->idev);
1291 + r = device_create_file(&pdev->dev, &dev_attr_hookdet);
1294 + r = device_create_file(&pdev->dev, &dev_attr_enable);
1297 + r = device_create_file(&pdev->dev, &dev_attr_enable_det);
1300 + platform_set_drvdata(pdev, hs);
1302 + spin_lock_init(&hs->lock);
1303 + mutex_init(&hs->mutex);
1304 + setup_timer(&hs->enable_timer, retu_headset_enable_timer,
1305 + (unsigned long) hs);
1306 + setup_timer(&hs->detect_timer, retu_headset_detect_timer,
1307 + (unsigned long) hs);
1309 + r = retu_request_irq(RETU_INT_HOOK, retu_headset_hook_interrupt,
1310 + (unsigned long) hs, "hookdet");
1312 + dev_err(&pdev->dev, "hookdet IRQ not available\n");
1315 + retu_disable_irq(RETU_INT_HOOK);
1318 + device_remove_file(&pdev->dev, &dev_attr_enable_det);
1320 + device_remove_file(&pdev->dev, &dev_attr_enable);
1322 + device_remove_file(&pdev->dev, &dev_attr_hookdet);
1324 + input_unregister_device(hs->idev);
1326 + input_free_device(hs->idev);
1332 +static int retu_headset_remove(struct platform_device *pdev)
1334 + struct retu_headset *hs = platform_get_drvdata(pdev);
1336 + device_remove_file(&pdev->dev, &dev_attr_hookdet);
1337 + device_remove_file(&pdev->dev, &dev_attr_enable);
1338 + device_remove_file(&pdev->dev, &dev_attr_enable_det);
1339 + retu_headset_disable(hs);
1340 + retu_headset_det_disable(hs);
1341 + retu_free_irq(RETU_INT_HOOK);
1342 + input_unregister_device(hs->idev);
1343 + input_free_device(hs->idev);
1347 +static int retu_headset_suspend(struct platform_device *pdev,
1348 + pm_message_t mesg)
1350 + struct retu_headset *hs = platform_get_drvdata(pdev);
1352 + mutex_lock(&hs->mutex);
1353 + if (hs->bias_enabled)
1354 + retu_headset_set_bias(0);
1355 + mutex_unlock(&hs->mutex);
1360 +static int retu_headset_resume(struct platform_device *pdev)
1362 + struct retu_headset *hs = platform_get_drvdata(pdev);
1364 + mutex_lock(&hs->mutex);
1365 + if (hs->bias_enabled)
1366 + retu_headset_set_bias(1);
1367 + mutex_unlock(&hs->mutex);
1372 +static struct platform_driver retu_headset_driver = {
1373 + .probe = retu_headset_probe,
1374 + .remove = retu_headset_remove,
1375 + .suspend = retu_headset_suspend,
1376 + .resume = retu_headset_resume,
1378 + .name = "retu-headset",
1382 +static int __init retu_headset_init(void)
1386 + printk(KERN_INFO "Retu/Vilma headset driver initializing\n");
1388 + r = platform_driver_register(&retu_headset_driver);
1395 +static void __exit retu_headset_exit(void)
1397 + platform_driver_unregister(&retu_headset_driver);
1400 +module_init(retu_headset_init);
1401 +module_exit(retu_headset_exit);
1403 +MODULE_DESCRIPTION("Retu/Vilma headset detection");
1404 +MODULE_LICENSE("GPL");
1405 +MODULE_AUTHOR("Juha Yrjölä");
1406 Index: linux-2.6.37/drivers/cbus/retu-pwrbutton.c
1407 ===================================================================
1408 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1409 +++ linux-2.6.37/drivers/cbus/retu-pwrbutton.c 2011-01-27 14:17:39.085000008 +0100
1412 + * drivers/cbus/retu-pwrbutton.c
1414 + * Driver for sending retu power button event to input-layer
1416 + * Copyright (C) 2004 Nokia Corporation
1418 + * Written by Ari Saastamoinen <ari.saastamoinen@elektrobit.com>
1420 + * Contact Juha Yrjölä <juha.yrjola@nokia.com>
1422 + * This file is subject to the terms and conditions of the GNU General
1423 + * Public License. See the file "COPYING" in the main directory of this
1424 + * archive for more details.
1426 + * This program is distributed in the hope that it will be useful,
1427 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1428 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1429 + * GNU General Public License for more details.
1431 + * You should have received a copy of the GNU General Public License
1432 + * along with this program; if not, write to the Free Software
1433 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1436 +#include <linux/module.h>
1437 +#include <linux/init.h>
1438 +#include <linux/kernel.h>
1439 +#include <linux/errno.h>
1440 +#include <linux/input.h>
1441 +#include <linux/timer.h>
1442 +#include <linux/jiffies.h>
1443 +#include <linux/bitops.h>
1447 +#define RETU_STATUS_PWRONX (1 << 5)
1449 +#define PWRBTN_DELAY 20
1450 +#define PWRBTN_UP 0
1451 +#define PWRBTN_PRESSED 1
1453 +static int pwrbtn_state;
1454 +static struct input_dev *pwrbtn_dev;
1455 +static struct timer_list pwrbtn_timer;
1457 +static void retubutton_timer_func(unsigned long arg)
1461 + if (retu_read_reg(RETU_REG_STATUS) & RETU_STATUS_PWRONX)
1462 + state = PWRBTN_UP;
1464 + state = PWRBTN_PRESSED;
1466 + if (pwrbtn_state != state) {
1467 + input_report_key(pwrbtn_dev, KEY_POWER, state);
1468 + pwrbtn_state = state;
1473 + * Interrupt function is called whenever power button key is pressed
1476 +static void retubutton_irq(unsigned long arg)
1478 + retu_ack_irq(RETU_INT_PWR);
1479 + mod_timer(&pwrbtn_timer, jiffies + msecs_to_jiffies(PWRBTN_DELAY));
1484 + * Allocates interrupt for power button and registers itself to input layer.
1486 +static int __init retubutton_init(void)
1490 + printk(KERN_INFO "Retu power button driver initialized\n");
1491 + irq = RETU_INT_PWR;
1493 + init_timer(&pwrbtn_timer);
1494 + pwrbtn_timer.function = retubutton_timer_func;
1496 + if (retu_request_irq(irq, &retubutton_irq, 0, "PwrOnX") < 0) {
1497 + printk(KERN_ERR "%s@%s: Cannot allocate irq\n",
1498 + __FUNCTION__, __FILE__);
1502 + pwrbtn_dev = input_allocate_device();
1506 + pwrbtn_dev->evbit[0] = BIT_MASK(EV_KEY);
1507 + pwrbtn_dev->keybit[BIT_WORD(KEY_POWER)] = BIT_MASK(KEY_POWER);
1508 + pwrbtn_dev->name = "retu-pwrbutton";
1510 + return input_register_device(pwrbtn_dev);
1514 + * Cleanup function which is called when driver is unloaded
1516 +static void __exit retubutton_exit(void)
1518 + retu_free_irq(RETU_INT_PWR);
1519 + del_timer_sync(&pwrbtn_timer);
1520 + input_unregister_device(pwrbtn_dev);
1523 +module_init(retubutton_init);
1524 +module_exit(retubutton_exit);
1526 +MODULE_DESCRIPTION("Retu Power Button");
1527 +MODULE_LICENSE("GPL");
1528 +MODULE_AUTHOR("Ari Saastamoinen");
1529 Index: linux-2.6.37/drivers/cbus/retu-rtc.c
1530 ===================================================================
1531 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1532 +++ linux-2.6.37/drivers/cbus/retu-rtc.c 2011-01-27 14:17:39.086000008 +0100
1535 + * drivers/cbus/retu-rtc.c
1537 + * Support for Retu RTC
1539 + * Copyright (C) 2004, 2005 Nokia Corporation
1541 + * Written by Paul Mundt <paul.mundt@nokia.com> and
1542 + * Igor Stoppa <igor.stoppa@nokia.com>
1544 + * The Retu RTC is essentially a partial read-only RTC that gives us Retu's
1545 + * idea of what time actually is. It's left as a userspace excercise to map
1546 + * this back to time in the real world and ensure that calibration settings
1547 + * are sane to compensate for any horrible drift (on account of not being able
1548 + * to set the clock to anything).
1550 + * Days are semi-writeable. Namely, Retu will only track 255 days for us
1551 + * consecutively, after which the counter is explicitly stuck at 255 until
1552 + * someone comes along and clears it with a write. In the event that no one
1553 + * comes along and clears it, we no longer have any idea what day it is.
1555 + * This file is subject to the terms and conditions of the GNU General
1556 + * Public License. See the file "COPYING" in the main directory of this
1557 + * archive for more details.
1559 + * This program is distributed in the hope that it will be useful,
1560 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1561 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1562 + * GNU General Public License for more details.
1564 + * You should have received a copy of the GNU General Public License
1565 + * along with this program; if not, write to the Free Software
1566 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1569 +#include <linux/device.h>
1570 +#include <linux/init.h>
1571 +#include <linux/kernel.h>
1572 +#include <linux/module.h>
1573 +#include <linux/completion.h>
1574 +#include <linux/platform_device.h>
1575 +#include <linux/mutex.h>
1576 +#include <linux/workqueue.h>
1581 +static struct mutex retu_rtc_mutex;
1582 +static u16 retu_rtc_alarm_expired;
1583 +static u16 retu_rtc_reset_occurred;
1585 +static DECLARE_COMPLETION(retu_rtc_exited);
1586 +static DECLARE_COMPLETION(retu_rtc_sync);
1588 +static void retu_rtc_barrier(void);
1590 +static void retu_rtc_device_release(struct device *dev)
1592 + complete(&retu_rtc_exited);
1595 +static ssize_t retu_rtc_time_show(struct device *dev, struct device_attribute *attr,
1598 + u16 dsr, hmr, dsr2;
1600 + mutex_lock(&retu_rtc_mutex);
1606 + * Not being in_interrupt() for a retu rtc IRQ, we need to
1607 + * read twice for consistency..
1609 + dummy = retu_read_reg(RETU_REG_RTCDSR);
1610 + dsr = retu_read_reg(RETU_REG_RTCDSR);
1612 + dummy = retu_read_reg(RETU_REG_RTCHMR);
1613 + hmr = retu_read_reg(RETU_REG_RTCHMR);
1615 + dummy = retu_read_reg(RETU_REG_RTCDSR);
1616 + dsr2 = retu_read_reg(RETU_REG_RTCDSR);
1617 + } while ((dsr != dsr2));
1619 + mutex_unlock(&retu_rtc_mutex);
1622 + * Format a 32-bit date-string for userspace
1624 + * days | hours | minutes | seconds
1626 + * 8 bits for each.
1628 + * This mostly sucks because days and seconds are tracked in RTCDSR
1629 + * while hours and minutes are tracked in RTCHMR. And yes, there
1630 + * really are no words that can describe an 8 bit day register (or
1631 + * rather, none that will be reprinted here).
1633 + return sprintf(buf, "0x%08x\n", (((dsr >> 8) & 0xff) << 24) |
1634 + (((hmr >> 8) & 0x1f) << 16) |
1635 + ((hmr & 0x3f) << 8) | (dsr & 0x3f));
1638 +static ssize_t retu_rtc_time_store(struct device *dev, struct device_attribute *attr,
1639 + const char *buf, size_t count)
1641 + mutex_lock(&retu_rtc_mutex);
1643 + * Writing anything to the day counter forces it to 0
1644 + * The seconds counter would be cleared by resetting the minutes counter,
1645 + * however this won't happen, since we are using the hh:mm counters as
1646 + * a set of free running counters and the day counter as a multiple
1647 + * overflow holder.
1650 + /* Reset day counter, but keep Temperature Shutdown state */
1651 + retu_write_reg(RETU_REG_RTCDSR,
1652 + retu_read_reg(RETU_REG_RTCDSR) & (1 << 6));
1654 + mutex_unlock(&retu_rtc_mutex);
1659 +static DEVICE_ATTR(time, S_IRUGO | S_IWUSR, retu_rtc_time_show,
1660 + retu_rtc_time_store);
1663 +static ssize_t retu_rtc_reset_show(struct device *dev, struct device_attribute *attr, char *buf)
1666 + * Returns the status of the rtc
1668 + * 0: no reset has occurred or the status has been cleared
1669 + * 1: a reset has occurred
1671 + * RTC needs to be reset only when both main battery
1672 + * _AND_ backup battery are discharged
1674 + return sprintf(buf, "%u\n", retu_rtc_reset_occurred);
1677 +static void retu_rtc_do_reset(void)
1681 + ccr1 = retu_read_reg(RETU_REG_CC1);
1682 + /* RTC in reset */
1683 + retu_write_reg(RETU_REG_CC1, ccr1 | 0x0001);
1684 + /* RTC in normal operating mode */
1685 + retu_write_reg(RETU_REG_CC1, ccr1 & ~0x0001);
1687 + retu_rtc_barrier();
1688 + /* Disable alarm and RTC WD */
1689 + retu_write_reg(RETU_REG_RTCHMAR, 0x7f3f);
1690 + /* Set Calibration register to default value */
1691 + retu_write_reg(RETU_REG_RTCCALR, 0x00c0);
1693 + retu_rtc_alarm_expired = 0;
1694 + retu_rtc_reset_occurred = 1;
1697 +static ssize_t retu_rtc_reset_store(struct device *dev, struct device_attribute *attr,
1698 + const char *buf, size_t count)
1702 + if(sscanf(buf, "%u", &choice) != 1)
1704 + mutex_lock(&retu_rtc_mutex);
1706 + retu_rtc_reset_occurred = 0;
1707 + else if (choice == 1)
1708 + retu_rtc_do_reset();
1709 + mutex_unlock(&retu_rtc_mutex);
1713 +static DEVICE_ATTR(reset, S_IRUGO | S_IWUSR, retu_rtc_reset_show,
1714 + retu_rtc_reset_store);
1716 +static ssize_t retu_rtc_alarm_show(struct device *dev, struct device_attribute *attr,
1722 + mutex_lock(&retu_rtc_mutex);
1724 + * Format a 16-bit date-string for userspace
1727 + * 8 bits for each.
1729 + chmar = retu_read_reg(RETU_REG_RTCHMAR);
1730 + /* No shifting needed, only masking unrelated bits */
1731 + retval = sprintf(buf, "0x%04x\n", chmar & 0x1f3f);
1732 + mutex_unlock(&retu_rtc_mutex);
1737 +static ssize_t retu_rtc_alarm_store(struct device *dev, struct device_attribute *attr,
1738 + const char *buf, size_t count)
1745 + mutex_lock(&retu_rtc_mutex);
1747 + if(sscanf(buf, "%x", &alrm) != 1)
1749 + hours = (alrm >> 8) & 0x001f;
1750 + minutes = (alrm >> 0) & 0x003f;
1751 + if ((hours < 24 && minutes < 60) || (hours == 24 && minutes == 60)) {
1753 + * OK, the time format for the alarm is valid (including the
1754 + * disabling values)
1756 + /* Keeps the RTC watchdog status */
1757 + chmar = retu_read_reg(RETU_REG_RTCHMAR) & 0x6000;
1758 + chmar |= alrm & 0x1f3f; /* Stores the requested alarm */
1759 + retu_rtc_barrier();
1760 + retu_write_reg(RETU_REG_RTCHMAR, chmar);
1761 + /* If the alarm is being disabled */
1762 + if (hours == 24 && minutes == 60) {
1763 + /* disable the interrupt */
1764 + retu_disable_irq(RETU_INT_RTCA);
1765 + retu_rtc_alarm_expired = 0;
1767 + /* enable the interrupt */
1768 + retu_enable_irq(RETU_INT_RTCA);
1770 + mutex_unlock(&retu_rtc_mutex);
1775 +static DEVICE_ATTR(alarm, S_IRUGO | S_IWUSR, retu_rtc_alarm_show,
1776 + retu_rtc_alarm_store);
1778 +static ssize_t retu_rtc_alarm_expired_show(struct device *dev, struct device_attribute *attr,
1783 + retval = sprintf(buf, "%u\n", retu_rtc_alarm_expired);
1788 +static ssize_t retu_rtc_alarm_expired_store(struct device *dev, struct device_attribute *attr,
1789 + const char *buf, size_t count)
1791 + retu_rtc_alarm_expired = 0;
1796 +static DEVICE_ATTR(alarm_expired, S_IRUGO | S_IWUSR, retu_rtc_alarm_expired_show,
1797 + retu_rtc_alarm_expired_store);
1800 +static ssize_t retu_rtc_cal_show(struct device *dev, struct device_attribute *attr,
1805 + mutex_lock(&retu_rtc_mutex);
1806 + rtccalr1 = retu_read_reg(RETU_REG_RTCCALR);
1807 + mutex_unlock(&retu_rtc_mutex);
1810 + * Shows the status of the Calibration Register.
1812 + * Default, after power loss: 0x0000
1813 + * Default, for R&D: 0x00C0
1814 + * Default, for factory: 0x00??
1817 + return sprintf(buf, "0x%04x\n", rtccalr1 & 0x00ff);
1820 +static ssize_t retu_rtc_cal_store(struct device *dev, struct device_attribute *attr,
1821 + const char *buf, size_t count)
1823 + unsigned calibration_value;
1825 + if (sscanf(buf, "%x", &calibration_value) != 1)
1828 + mutex_lock(&retu_rtc_mutex);
1829 + retu_rtc_barrier();
1830 + retu_write_reg(RETU_REG_RTCCALR, calibration_value & 0x00ff);
1831 + mutex_unlock(&retu_rtc_mutex);
1836 +static DEVICE_ATTR(cal, S_IRUGO | S_IWUSR, retu_rtc_cal_show,
1837 + retu_rtc_cal_store);
1839 +static struct platform_device retu_rtc_device;
1841 +static void retu_rtca_disable(void)
1843 + retu_disable_irq(RETU_INT_RTCA);
1844 + retu_rtc_alarm_expired = 1;
1845 + retu_rtc_barrier();
1846 + retu_write_reg(RETU_REG_RTCHMAR, (24 << 8) | 60);
1849 +static void retu_rtca_expired(struct work_struct *unused)
1851 + retu_rtca_disable();
1852 + sysfs_notify(&retu_rtc_device.dev.kobj, NULL, "alarm_expired");
1855 +DECLARE_WORK(retu_rtca_work, retu_rtca_expired);
1858 + * RTCHMR RTCHMAR RTCCAL must be accessed within 0.9 s since the seconds
1859 + * interrupt has been signaled in the IDR register
1861 +static void retu_rtcs_interrupt(unsigned long unused)
1863 + retu_ack_irq(RETU_INT_RTCS);
1864 + complete_all(&retu_rtc_sync);
1867 +static void retu_rtca_interrupt(unsigned long unused)
1869 + retu_ack_irq(RETU_INT_RTCA);
1870 + schedule_work(&retu_rtca_work);
1873 +static int retu_rtc_init_irq(void)
1877 + ret = retu_request_irq(RETU_INT_RTCS, retu_rtcs_interrupt, 0, "RTCS");
1881 + * We will take care of enabling and disabling the interrupt
1882 + * elsewhere, so leave it off by default..
1884 + retu_disable_irq(RETU_INT_RTCS);
1886 + ret = retu_request_irq(RETU_INT_RTCA, retu_rtca_interrupt, 0, "RTCA");
1888 + retu_free_irq(RETU_INT_RTCS);
1891 + retu_disable_irq(RETU_INT_RTCA);
1897 +static int __devinit retu_rtc_probe(struct device *dev)
1901 + retu_rtc_alarm_expired = retu_read_reg(RETU_REG_IDR) &
1902 + (0x1 << RETU_INT_RTCA);
1904 + if ((r = retu_rtc_init_irq()) != 0)
1907 + mutex_init(&retu_rtc_mutex);
1909 + /* If the calibration register is zero, we've probably lost
1911 + if (retu_read_reg(RETU_REG_RTCCALR) & 0x00ff)
1912 + retu_rtc_reset_occurred = 0;
1914 + retu_rtc_do_reset();
1916 + if ((r = device_create_file(dev, &dev_attr_time)) != 0)
1918 + else if ((r = device_create_file(dev, &dev_attr_reset)) != 0)
1919 + goto err_unregister_time;
1920 + else if ((r = device_create_file(dev, &dev_attr_alarm)) != 0)
1921 + goto err_unregister_reset;
1922 + else if ((r = device_create_file(dev, &dev_attr_alarm_expired)) != 0)
1923 + goto err_unregister_alarm;
1924 + else if ((r = device_create_file(dev, &dev_attr_cal)) != 0)
1925 + goto err_unregister_alarm_expired;
1929 +err_unregister_alarm_expired:
1930 + device_remove_file(dev, &dev_attr_alarm_expired);
1931 +err_unregister_alarm:
1932 + device_remove_file(dev, &dev_attr_alarm);
1933 +err_unregister_reset:
1934 + device_remove_file(dev, &dev_attr_reset);
1935 +err_unregister_time:
1936 + device_remove_file(dev, &dev_attr_time);
1940 +static int __devexit retu_rtc_remove(struct device *dev)
1942 + retu_disable_irq(RETU_INT_RTCS);
1943 + retu_free_irq(RETU_INT_RTCS);
1944 + retu_free_irq(RETU_INT_RTCA);
1945 + device_remove_file(dev, &dev_attr_cal);
1946 + device_remove_file(dev, &dev_attr_alarm_expired);
1947 + device_remove_file(dev, &dev_attr_alarm);
1948 + device_remove_file(dev, &dev_attr_reset);
1949 + device_remove_file(dev, &dev_attr_time);
1953 +static struct device_driver retu_rtc_driver = {
1954 + .name = "retu-rtc",
1955 + .bus = &platform_bus_type,
1956 + .probe = retu_rtc_probe,
1957 + .remove = __devexit_p(retu_rtc_remove),
1960 +static struct platform_device retu_rtc_device = {
1961 + .name = "retu-rtc",
1964 + .release = retu_rtc_device_release,
1968 +/* This function provides syncronization with the RTCS interrupt handler */
1969 +static void retu_rtc_barrier(void)
1971 + INIT_COMPLETION(retu_rtc_sync);
1972 + retu_ack_irq(RETU_INT_RTCS);
1973 + retu_enable_irq(RETU_INT_RTCS);
1974 + wait_for_completion(&retu_rtc_sync);
1975 + retu_disable_irq(RETU_INT_RTCS);
1978 +static int __init retu_rtc_init(void)
1982 + init_completion(&retu_rtc_exited);
1984 + if ((ret = driver_register(&retu_rtc_driver)) != 0)
1987 + if ((ret = platform_device_register(&retu_rtc_device)) != 0)
1988 + goto err_unregister_driver;
1992 +err_unregister_driver:
1993 + driver_unregister(&retu_rtc_driver);
1997 +static void __exit retu_rtc_exit(void)
1999 + platform_device_unregister(&retu_rtc_device);
2000 + driver_unregister(&retu_rtc_driver);
2002 + wait_for_completion(&retu_rtc_exited);
2005 +module_init(retu_rtc_init);
2006 +module_exit(retu_rtc_exit);
2008 +MODULE_DESCRIPTION("Retu RTC");
2009 +MODULE_LICENSE("GPL");
2010 +MODULE_AUTHOR("Paul Mundt and Igor Stoppa");
2011 Index: linux-2.6.37/drivers/cbus/retu-user.c
2012 ===================================================================
2013 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2014 +++ linux-2.6.37/drivers/cbus/retu-user.c 2011-01-27 14:17:39.086000008 +0100
2017 + * drivers/cbus/retu-user.c
2019 + * Retu user space interface functions
2021 + * Copyright (C) 2004, 2005 Nokia Corporation
2023 + * Written by Mikko Ylinen <mikko.k.ylinen@nokia.com>
2025 + * This file is subject to the terms and conditions of the GNU General
2026 + * Public License. See the file "COPYING" in the main directory of this
2027 + * archive for more details.
2029 + * This program is distributed in the hope that it will be useful,
2030 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2031 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2032 + * GNU General Public License for more details.
2034 + * You should have received a copy of the GNU General Public License
2035 + * along with this program; if not, write to the Free Software
2036 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2039 +#include <linux/types.h>
2040 +#include <linux/kernel.h>
2041 +#include <linux/interrupt.h>
2042 +#include <linux/module.h>
2043 +#include <linux/init.h>
2044 +#include <linux/fs.h>
2045 +#include <linux/miscdevice.h>
2046 +#include <linux/poll.h>
2047 +#include <linux/list.h>
2048 +#include <linux/spinlock.h>
2049 +#include <linux/sched.h>
2050 +#include <linux/mutex.h>
2051 +#include <linux/slab.h>
2053 +#include <asm/uaccess.h>
2057 +#include "user_retu_tahvo.h"
2059 +/* Maximum size of IRQ node buffer/pool */
2060 +#define RETU_MAX_IRQ_BUF_LEN 16
2062 +#define PFX "retu-user: "
2064 +/* Bitmap for marking the interrupt sources as having the handlers */
2065 +static u32 retu_irq_bits;
2067 +/* For allowing only one user process to subscribe to the retu interrupts */
2068 +static struct file *retu_irq_subscr = NULL;
2070 +/* For poll and IRQ passing */
2073 + struct list_head node;
2076 +static spinlock_t retu_irqs_lock;
2077 +static struct retu_irq *retu_irq_block;
2078 +static LIST_HEAD(retu_irqs);
2079 +static LIST_HEAD(retu_irqs_reserve);
2081 +/* Wait queue - used when user wants to read the device */
2082 +DECLARE_WAIT_QUEUE_HEAD(retu_user_waitqueue);
2084 +/* Semaphore to protect irq subscription sequence */
2085 +static struct mutex retu_mutex;
2087 +/* This array specifies RETU register types (read/write/toggle) */
2088 +static const u8 retu_access_bits[] = {
2124 + * The handler for all RETU interrupts.
2126 + * arg is the interrupt source in RETU.
2128 +static void retu_user_irq_handler(unsigned long arg)
2130 + struct retu_irq *irq;
2132 + retu_ack_irq(arg);
2134 + spin_lock(&retu_irqs_lock);
2135 + if (list_empty(&retu_irqs_reserve)) {
2136 + spin_unlock(&retu_irqs_lock);
2139 + irq = list_entry((&retu_irqs_reserve)->next, struct retu_irq, node);
2141 + list_move_tail(&irq->node, &retu_irqs);
2142 + spin_unlock(&retu_irqs_lock);
2144 + /* wake up waiting thread */
2145 + wake_up(&retu_user_waitqueue);
2149 + * This routine sets up the interrupt handler and marks an interrupt source
2150 + * in RETU as a candidate for signal delivery to the user process.
2152 +static int retu_user_subscribe_to_irq(int id, struct file *filp)
2156 + mutex_lock(&retu_mutex);
2157 + if ((retu_irq_subscr != NULL) && (retu_irq_subscr != filp)) {
2158 + mutex_unlock(&retu_mutex);
2161 + /* Store the file pointer of the first user process registering IRQs */
2162 + retu_irq_subscr = filp;
2163 + mutex_unlock(&retu_mutex);
2165 + if (retu_irq_bits & (1 << id))
2168 + ret = retu_request_irq(id, retu_user_irq_handler, id, "");
2172 + /* Mark that this interrupt has a handler */
2173 + retu_irq_bits |= 1 << id;
2179 + * Unregisters all RETU interrupt handlers.
2181 +static void retu_unreg_irq_handlers(void)
2185 + if (!retu_irq_bits)
2188 + for (id = 0; id < MAX_RETU_IRQ_HANDLERS; id++)
2189 + if (retu_irq_bits & (1 << id))
2190 + retu_free_irq(id);
2192 + retu_irq_bits = 0;
2196 + * Write to RETU register.
2197 + * Returns 0 upon success, a negative error value otherwise.
2199 +static int retu_user_write_with_mask(u32 field, u16 value)
2204 + unsigned long flags;
2206 + mask = MASK(field);
2209 + /* Detect bad mask and reg */
2210 + if (mask == 0 || reg > RETU_REG_MAX ||
2211 + retu_access_bits[reg] == READ_ONLY) {
2212 + printk(KERN_ERR PFX "invalid arguments (reg=%#x, mask=%#x)\n",
2217 + /* Justify value according to mask */
2218 + while (!(mask & 1)) {
2219 + value = value << 1;
2223 + spin_lock_irqsave(&retu_lock, flags);
2224 + if (retu_access_bits[reg] == TOGGLE) {
2225 + /* No need to detect previous content of register */
2228 + /* Read current value of register */
2229 + tmp = retu_read_reg(reg);
2232 + /* Generate new value */
2233 + tmp = (tmp & ~MASK(field)) | (value & MASK(field));
2234 + /* Write data to RETU */
2235 + retu_write_reg(reg, tmp);
2236 + spin_unlock_irqrestore(&retu_lock, flags);
2242 + * Read RETU register.
2244 +static u32 retu_user_read_with_mask(u32 field)
2249 + mask = MASK(field);
2252 + /* Detect bad mask and reg */
2253 + if (mask == 0 || reg > RETU_REG_MAX) {
2254 + printk(KERN_ERR PFX "invalid arguments (reg=%#x, mask=%#x)\n",
2259 + /* Read the register */
2260 + value = retu_read_reg(reg) & mask;
2262 + /* Right justify value */
2263 + while (!(mask & 1)) {
2264 + value = value >> 1;
2274 +static int retu_close(struct inode *inode, struct file *filp)
2276 + /* Unregister all interrupts that have been registered */
2277 + if (retu_irq_subscr == filp) {
2278 + retu_unreg_irq_handlers();
2279 + retu_irq_subscr = NULL;
2286 + * Device control (ioctl)
2288 +static long retu_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2290 + struct retu_tahvo_write_parms par;
2294 + case URT_IOCT_IRQ_SUBSCR:
2295 + return retu_user_subscribe_to_irq(arg, filp);
2296 + case RETU_IOCH_READ:
2297 + return retu_user_read_with_mask(arg);
2298 + case RETU_IOCX_WRITE:
2299 + ret = copy_from_user(&par, (void __user *) arg, sizeof(par));
2301 + printk(KERN_ERR "copy_from_user failed: %d\n", ret);
2302 + par.result = retu_user_write_with_mask(par.field, par.value);
2303 + ret = copy_to_user((void __user *) arg, &par, sizeof(par));
2305 + printk(KERN_ERR "copy_to_user failed: %d\n", ret);
2307 + case RETU_IOCH_ADC_READ:
2308 + return retu_read_adc(arg);
2310 + return -ENOIOCTLCMD;
2316 + * Read from device
2318 +static ssize_t retu_read(struct file *filp, char *buf, size_t count,
2321 + struct retu_irq *irq;
2325 + /* read not permitted if neither filp nor anyone has registered IRQs */
2326 + if (retu_irq_subscr != filp)
2329 + if ((count < sizeof(u32)) || ((count % sizeof(u32)) != 0))
2332 + nr = count / sizeof(u32);
2334 + for (i = 0; i < nr; i++) {
2335 + unsigned long flags;
2339 + ret = wait_event_interruptible(retu_user_waitqueue,
2340 + !list_empty(&retu_irqs));
2344 + spin_lock_irqsave(&retu_irqs_lock, flags);
2345 + irq = list_entry((&retu_irqs)->next, struct retu_irq, node);
2347 + list_move(&irq->node, &retu_irqs_reserve);
2348 + spin_unlock_irqrestore(&retu_irqs_lock, flags);
2350 + ret = copy_to_user(buf + i * sizeof(irq_id), &irq_id,
2353 + printk(KERN_ERR "copy_to_user failed: %d\n", ret);
2362 +static unsigned retu_poll(struct file *filp, struct poll_table_struct *pt)
2364 + if (!list_empty(&retu_irqs))
2367 + poll_wait(filp, &retu_user_waitqueue, pt);
2369 + if (!list_empty(&retu_irqs))
2375 +static struct file_operations retu_user_fileops = {
2376 + .owner = THIS_MODULE,
2377 + .unlocked_ioctl = retu_ioctl,
2378 + .read = retu_read,
2379 + .release = retu_close,
2383 +static struct miscdevice retu_device = {
2384 + .minor = MISC_DYNAMIC_MINOR,
2386 + .fops = &retu_user_fileops
2392 + * @return 0 if successful, error value otherwise.
2394 +int retu_user_init(void)
2396 + struct retu_irq *irq;
2399 + irq = kmalloc(sizeof(*irq) * RETU_MAX_IRQ_BUF_LEN, GFP_KERNEL);
2400 + if (irq == NULL) {
2401 + printk(KERN_ERR PFX "kmalloc failed\n");
2404 + memset(irq, 0, sizeof(*irq) * RETU_MAX_IRQ_BUF_LEN);
2405 + for (i = 0; i < RETU_MAX_IRQ_BUF_LEN; i++)
2406 + list_add(&irq[i].node, &retu_irqs_reserve);
2408 + retu_irq_block = irq;
2410 + spin_lock_init(&retu_irqs_lock);
2411 + mutex_init(&retu_mutex);
2413 + /* Request a misc device */
2414 + res = misc_register(&retu_device);
2416 + printk(KERN_ERR PFX "unable to register misc device for %s\n",
2417 + retu_device.name);
2428 +void retu_user_cleanup(void)
2430 + /* Unregister our misc device */
2431 + misc_deregister(&retu_device);
2432 + /* Unregister and disable all RETU interrupts used by this module */
2433 + retu_unreg_irq_handlers();
2434 + kfree(retu_irq_block);
2437 +MODULE_DESCRIPTION("Retu ASIC user space functions");
2438 +MODULE_LICENSE("GPL");
2439 +MODULE_AUTHOR("Mikko Ylinen");
2440 Index: linux-2.6.37/drivers/cbus/retu-wdt.c
2441 ===================================================================
2442 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2443 +++ linux-2.6.37/drivers/cbus/retu-wdt.c 2011-01-27 14:17:39.086000008 +0100
2446 + * drivers/cbus/retu-wdt.c
2448 + * Driver for Retu watchdog
2450 + * Copyright (C) 2004, 2005 Nokia Corporation
2452 + * Written by Amit Kucheria <amit.kucheria@nokia.com>
2454 + * This file is subject to the terms and conditions of the GNU General
2455 + * Public License. See the file "COPYING" in the main directory of this
2456 + * archive for more details.
2458 + * This program is distributed in the hope that it will be useful,
2459 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2460 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2461 + * GNU General Public License for more details.
2463 + * You should have received a copy of the GNU General Public License
2464 + * along with this program; if not, write to the Free Software
2465 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2468 +#include <linux/kernel.h>
2469 +#include <linux/module.h>
2470 +#include <linux/device.h>
2471 +#include <linux/init.h>
2472 +#include <linux/fs.h>
2473 +#include <linux/io.h>
2474 +#include <linux/platform_device.h>
2475 +#include <linux/slab.h>
2477 +#include <linux/completion.h>
2478 +#include <linux/errno.h>
2479 +#include <linux/moduleparam.h>
2480 +#include <linux/platform_device.h>
2481 +#include <linux/miscdevice.h>
2482 +#include <linux/watchdog.h>
2484 +#include <asm/uaccess.h>
2486 +#include <plat/prcm.h>
2491 +/* Watchdog timeout in seconds */
2492 +#define RETU_WDT_MIN_TIMER 0
2493 +#define RETU_WDT_DEFAULT_TIMER 32
2494 +#define RETU_WDT_MAX_TIMER 63
2496 +static struct completion retu_wdt_completion;
2497 +static DEFINE_MUTEX(retu_wdt_mutex);
2499 +/* Current period of watchdog */
2500 +static unsigned int period_val = RETU_WDT_DEFAULT_TIMER;
2501 +static int counter_param = RETU_WDT_MAX_TIMER;
2503 +struct retu_wdt_dev {
2504 + struct device *dev;
2506 + struct miscdevice retu_wdt_miscdev;
2507 + struct timer_list ping_timer;
2510 +static struct retu_wdt_dev *retu_wdt;
2512 +static void retu_wdt_set_ping_timer(unsigned long enable);
2514 +static int _retu_modify_counter(unsigned int new)
2516 + retu_write_reg(RETU_REG_WATCHDOG, (u16)new);
2521 +static int retu_modify_counter(unsigned int new)
2523 + if (new < RETU_WDT_MIN_TIMER || new > RETU_WDT_MAX_TIMER)
2526 + mutex_lock(&retu_wdt_mutex);
2528 + _retu_modify_counter(period_val);
2529 + mutex_unlock(&retu_wdt_mutex);
2534 +static ssize_t retu_wdt_period_show(struct device *dev,
2535 + struct device_attribute *attr, char *buf)
2537 + /* Show current max counter */
2538 + return sprintf(buf, "%u\n", (u16)period_val);
2542 + * Note: This inteface is non-standard and likely to disappear!
2543 + * Use /dev/watchdog instead, that's the standard.
2545 +static ssize_t retu_wdt_period_store(struct device *dev,
2546 + struct device_attribute *attr,
2547 + const char *buf, size_t count)
2549 + unsigned int new_period;
2552 +#ifdef CONFIG_WATCHDOG_NOWAYOUT
2553 + retu_wdt_set_ping_timer(0);
2556 + if (sscanf(buf, "%u", &new_period) != 1) {
2557 + printk(KERN_ALERT "retu_wdt_period_store: Invalid input\n");
2561 + ret = retu_modify_counter(new_period);
2565 + return strnlen(buf, count);
2568 +static ssize_t retu_wdt_counter_show(struct device *dev,
2569 + struct device_attribute *attr, char *buf)
2573 + /* Show current value in watchdog counter */
2574 + counter = retu_read_reg(RETU_REG_WATCHDOG);
2576 + /* Only the 5 LSB are important */
2577 + return snprintf(buf, PAGE_SIZE, "%u\n", (counter & 0x3F));
2580 +static DEVICE_ATTR(period, S_IRUGO | S_IWUSR, retu_wdt_period_show, \
2581 + retu_wdt_period_store);
2582 +static DEVICE_ATTR(counter, S_IRUGO, retu_wdt_counter_show, NULL);
2584 +/*----------------------------------------------------------------------------*/
2587 + * Since retu watchdog cannot be disabled in hardware, we must kick it
2588 + * with a timer until userspace watchdog software takes over. Do this
2589 + * unless /dev/watchdog is open or CONFIG_WATCHDOG_NOWAYOUT is set.
2591 +static void retu_wdt_set_ping_timer(unsigned long enable)
2593 + _retu_modify_counter(RETU_WDT_MAX_TIMER);
2595 + mod_timer(&retu_wdt->ping_timer,
2596 + jiffies + RETU_WDT_DEFAULT_TIMER * HZ);
2598 + del_timer_sync(&retu_wdt->ping_timer);
2601 +static int retu_wdt_open(struct inode *inode, struct file *file)
2603 + if (test_and_set_bit(1, (unsigned long *)&(retu_wdt->users)))
2606 + file->private_data = (void *)retu_wdt;
2607 + retu_wdt_set_ping_timer(0);
2609 + return nonseekable_open(inode, file);
2612 +static int retu_wdt_release(struct inode *inode, struct file *file)
2614 + struct retu_wdt_dev *wdev = file->private_data;
2616 +#ifndef CONFIG_WATCHDOG_NOWAYOUT
2617 + retu_wdt_set_ping_timer(1);
2624 +static ssize_t retu_wdt_write(struct file *file, const char __user *data,
2625 + size_t len, loff_t *ppos)
2628 + retu_modify_counter(RETU_WDT_MAX_TIMER);
2633 +static long retu_wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2637 + static struct watchdog_info ident = {
2638 + .identity = "Retu Watchdog",
2639 + .options = WDIOF_SETTIMEOUT,
2640 + .firmware_version = 0,
2646 + case WDIOC_GETSUPPORT:
2647 + return copy_to_user((struct watchdog_info __user *)arg, &ident,
2649 + case WDIOC_GETSTATUS:
2650 + return put_user(0, (int __user *)arg);
2651 + case WDIOC_GETBOOTSTATUS:
2652 + if (cpu_is_omap16xx())
2653 + return put_user(omap_readw(ARM_SYSST),
2654 + (int __user *)arg);
2655 + if (cpu_is_omap24xx())
2656 + return put_user(omap_prcm_get_reset_sources(),
2657 + (int __user *)arg);
2658 + case WDIOC_KEEPALIVE:
2659 + retu_modify_counter(RETU_WDT_MAX_TIMER);
2661 + case WDIOC_SETTIMEOUT:
2662 + if (get_user(new_margin, (int __user *)arg))
2664 + retu_modify_counter(new_margin);
2665 + /* Fall through */
2666 + case WDIOC_GETTIMEOUT:
2667 + return put_user(period_val, (int __user *)arg);
2673 +/* Start kicking retu watchdog until user space starts doing the kicking */
2674 +static int __init retu_wdt_ping(void)
2677 +#ifdef CONFIG_WATCHDOG_NOWAYOUT
2678 + retu_modify_counter(RETU_WDT_MAX_TIMER);
2680 + retu_wdt_set_ping_timer(1);
2685 +late_initcall(retu_wdt_ping);
2687 +static const struct file_operations retu_wdt_fops = {
2688 + .owner = THIS_MODULE,
2689 + .write = retu_wdt_write,
2690 + .unlocked_ioctl = retu_wdt_ioctl,
2691 + .open = retu_wdt_open,
2692 + .release = retu_wdt_release,
2695 +/*----------------------------------------------------------------------------*/
2697 +static int __devinit retu_wdt_probe(struct device *dev)
2699 + struct retu_wdt_dev *wdev;
2702 + wdev = kzalloc(sizeof(struct retu_wdt_dev), GFP_KERNEL);
2708 + ret = device_create_file(dev, &dev_attr_period);
2710 + printk(KERN_ERR "retu_wdt_probe: Error creating "
2711 + "sys device file: period\n");
2715 + ret = device_create_file(dev, &dev_attr_counter);
2717 + printk(KERN_ERR "retu_wdt_probe: Error creating "
2718 + "sys device file: counter\n");
2722 + dev_set_drvdata(dev, wdev);
2724 + wdev->retu_wdt_miscdev.parent = dev;
2725 + wdev->retu_wdt_miscdev.minor = WATCHDOG_MINOR;
2726 + wdev->retu_wdt_miscdev.name = "watchdog";
2727 + wdev->retu_wdt_miscdev.fops = &retu_wdt_fops;
2729 + ret = misc_register(&(wdev->retu_wdt_miscdev));
2733 + setup_timer(&wdev->ping_timer, retu_wdt_set_ping_timer, 1);
2735 + /* Kick the watchdog for kernel booting to finish */
2736 + retu_modify_counter(RETU_WDT_MAX_TIMER);
2741 + device_remove_file(dev, &dev_attr_counter);
2744 + device_remove_file(dev, &dev_attr_period);
2751 +static int __devexit retu_wdt_remove(struct device *dev)
2753 + struct retu_wdt_dev *wdev;
2755 + wdev = dev_get_drvdata(dev);
2756 + misc_deregister(&(wdev->retu_wdt_miscdev));
2757 + device_remove_file(dev, &dev_attr_period);
2758 + device_remove_file(dev, &dev_attr_counter);
2764 +static void retu_wdt_device_release(struct device *dev)
2766 + complete(&retu_wdt_completion);
2769 +static struct platform_device retu_wdt_device = {
2770 + .name = "retu-watchdog",
2773 + .release = retu_wdt_device_release,
2777 +static struct device_driver retu_wdt_driver = {
2778 + .name = "retu-watchdog",
2779 + .bus = &platform_bus_type,
2780 + .probe = retu_wdt_probe,
2781 + .remove = __devexit_p(retu_wdt_remove),
2784 +static int __init retu_wdt_init(void)
2788 + init_completion(&retu_wdt_completion);
2790 + ret = driver_register(&retu_wdt_driver);
2794 + ret = platform_device_register(&retu_wdt_device);
2798 + /* passed as module parameter? */
2799 + ret = retu_modify_counter(counter_param);
2800 + if (ret == -EINVAL) {
2801 + ret = retu_modify_counter(RETU_WDT_DEFAULT_TIMER);
2803 + "retu_wdt_init: Intializing to default value\n");
2806 + printk(KERN_INFO "Retu watchdog driver initialized\n");
2810 + driver_unregister(&retu_wdt_driver);
2811 + wait_for_completion(&retu_wdt_completion);
2816 +static void __exit retu_wdt_exit(void)
2818 + platform_device_unregister(&retu_wdt_device);
2819 + driver_unregister(&retu_wdt_driver);
2821 + wait_for_completion(&retu_wdt_completion);
2824 +module_init(retu_wdt_init);
2825 +module_exit(retu_wdt_exit);
2826 +module_param(counter_param, int, 0);
2828 +MODULE_DESCRIPTION("Retu WatchDog");
2829 +MODULE_AUTHOR("Amit Kucheria");
2830 +MODULE_LICENSE("GPL");
2832 Index: linux-2.6.37/drivers/cbus/tahvo.c
2833 ===================================================================
2834 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2835 +++ linux-2.6.37/drivers/cbus/tahvo.c 2011-01-27 14:17:39.086000008 +0100
2838 + * drivers/cbus/tahvo.c
2840 + * Support functions for Tahvo ASIC
2842 + * Copyright (C) 2004, 2005 Nokia Corporation
2844 + * Written by Juha Yrjölä <juha.yrjola@nokia.com>,
2845 + * David Weinehall <david.weinehall@nokia.com>, and
2846 + * Mikko Ylinen <mikko.k.ylinen@nokia.com>
2848 + * This file is subject to the terms and conditions of the GNU General
2849 + * Public License. See the file "COPYING" in the main directory of this
2850 + * archive for more details.
2852 + * This program is distributed in the hope that it will be useful,
2853 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2854 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2855 + * GNU General Public License for more details.
2857 + * You should have received a copy of the GNU General Public License
2858 + * along with this program; if not, write to the Free Software
2859 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2862 +#include <linux/module.h>
2863 +#include <linux/init.h>
2865 +#include <linux/kernel.h>
2866 +#include <linux/errno.h>
2867 +#include <linux/device.h>
2868 +#include <linux/miscdevice.h>
2869 +#include <linux/poll.h>
2870 +#include <linux/fs.h>
2871 +#include <linux/irq.h>
2872 +#include <linux/interrupt.h>
2873 +#include <linux/platform_device.h>
2874 +#include <linux/gpio.h>
2876 +#include <asm/uaccess.h>
2877 +#include <asm/mach-types.h>
2879 +#include <plat/mux.h>
2880 +#include <plat/board.h>
2885 +#define TAHVO_ID 0x02
2886 +#define PFX "tahvo: "
2888 +static int tahvo_initialized;
2889 +static int tahvo_irq_pin;
2890 +static int tahvo_is_betty;
2892 +static struct tasklet_struct tahvo_tasklet;
2893 +spinlock_t tahvo_lock = SPIN_LOCK_UNLOCKED;
2895 +static struct completion device_release;
2897 +struct tahvo_irq_handler_desc {
2898 + int (*func)(unsigned long);
2899 + unsigned long arg;
2903 +static struct tahvo_irq_handler_desc tahvo_irq_handlers[MAX_TAHVO_IRQ_HANDLERS];
2906 + * tahvo_read_reg - Read a value from a register in Tahvo
2907 + * @reg: the register to read from
2909 + * This function returns the contents of the specified register
2911 +int tahvo_read_reg(int reg)
2913 + BUG_ON(!tahvo_initialized);
2914 + return cbus_read_reg(cbus_host, TAHVO_ID, reg);
2918 + * tahvo_write_reg - Write a value to a register in Tahvo
2919 + * @reg: the register to write to
2920 + * @reg: the value to write to the register
2922 + * This function writes a value to the specified register
2924 +void tahvo_write_reg(int reg, u16 val)
2926 + BUG_ON(!tahvo_initialized);
2927 + cbus_write_reg(cbus_host, TAHVO_ID, reg, val);
2931 + * tahvo_set_clear_reg_bits - set and clear register bits atomically
2932 + * @reg: the register to write to
2933 + * @bits: the bits to set
2935 + * This function sets and clears the specified Tahvo register bits atomically
2937 +void tahvo_set_clear_reg_bits(int reg, u16 set, u16 clear)
2939 + unsigned long flags;
2942 + spin_lock_irqsave(&tahvo_lock, flags);
2943 + w = tahvo_read_reg(reg);
2946 + tahvo_write_reg(reg, w);
2947 + spin_unlock_irqrestore(&tahvo_lock, flags);
2951 + * Disable given TAHVO interrupt
2953 +void tahvo_disable_irq(int id)
2955 + unsigned long flags;
2958 + spin_lock_irqsave(&tahvo_lock, flags);
2959 + mask = tahvo_read_reg(TAHVO_REG_IMR);
2961 + tahvo_write_reg(TAHVO_REG_IMR, mask);
2962 + spin_unlock_irqrestore(&tahvo_lock, flags);
2966 + * Enable given TAHVO interrupt
2968 +void tahvo_enable_irq(int id)
2970 + unsigned long flags;
2973 + spin_lock_irqsave(&tahvo_lock, flags);
2974 + mask = tahvo_read_reg(TAHVO_REG_IMR);
2975 + mask &= ~(1 << id);
2976 + tahvo_write_reg(TAHVO_REG_IMR, mask);
2977 + spin_unlock_irqrestore(&tahvo_lock, flags);
2981 + * Acknowledge given TAHVO interrupt
2983 +void tahvo_ack_irq(int id)
2985 + tahvo_write_reg(TAHVO_REG_IDR, 1 << id);
2988 +static int tahvo_7bit_backlight;
2990 +int tahvo_get_backlight_level(void)
2994 + if (tahvo_7bit_backlight)
2998 + return tahvo_read_reg(TAHVO_REG_LEDPWMR) & mask;
3001 +int tahvo_get_max_backlight_level(void)
3003 + if (tahvo_7bit_backlight)
3009 +void tahvo_set_backlight_level(int level)
3013 + max_level = tahvo_get_max_backlight_level();
3014 + if (level > max_level)
3015 + level = max_level;
3016 + tahvo_write_reg(TAHVO_REG_LEDPWMR, level);
3020 + * TAHVO interrupt handler. Only schedules the tasklet.
3022 +static irqreturn_t tahvo_irq_handler(int irq, void *dev_id)
3024 + tasklet_schedule(&tahvo_tasklet);
3025 + return IRQ_HANDLED;
3031 +static void tahvo_tasklet_handler(unsigned long data)
3033 + struct tahvo_irq_handler_desc *hnd;
3039 + id = tahvo_read_reg(TAHVO_REG_IDR);
3040 + im = ~tahvo_read_reg(TAHVO_REG_IMR);
3046 + for (i = 0; id != 0; i++, id >>= 1) {
3049 + hnd = &tahvo_irq_handlers[i];
3050 + if (hnd->func == NULL) {
3051 + /* Spurious tahvo interrupt - just ack it */
3052 + printk(KERN_INFO "Spurious Tahvo interrupt "
3054 + tahvo_disable_irq(i);
3058 + hnd->func(hnd->arg);
3060 + * Don't acknowledge the interrupt here
3061 + * It must be done explicitly
3068 + * Register the handler for a given TAHVO interrupt source.
3070 +int tahvo_request_irq(int id, void *irq_handler, unsigned long arg, char *name)
3072 + struct tahvo_irq_handler_desc *hnd;
3074 + if (irq_handler == NULL || id >= MAX_TAHVO_IRQ_HANDLERS ||
3076 + printk(KERN_ERR PFX "Invalid arguments to %s\n",
3080 + hnd = &tahvo_irq_handlers[id];
3081 + if (hnd->func != NULL) {
3082 + printk(KERN_ERR PFX "IRQ %d already reserved\n", id);
3085 + printk(KERN_INFO PFX "Registering interrupt %d for device %s\n",
3087 + hnd->func = irq_handler;
3089 + strlcpy(hnd->name, name, sizeof(hnd->name));
3091 + tahvo_ack_irq(id);
3092 + tahvo_enable_irq(id);
3098 + * Unregister the handler for a given TAHVO interrupt source.
3100 +void tahvo_free_irq(int id)
3102 + struct tahvo_irq_handler_desc *hnd;
3104 + if (id >= MAX_TAHVO_IRQ_HANDLERS) {
3105 + printk(KERN_ERR PFX "Invalid argument to %s\n",
3109 + hnd = &tahvo_irq_handlers[id];
3110 + if (hnd->func == NULL) {
3111 + printk(KERN_ERR PFX "IRQ %d already freed\n", id);
3115 + tahvo_disable_irq(id);
3120 + * tahvo_probe - Probe for Tahvo ASIC
3121 + * @dev: the Tahvo device
3123 + * Probe for the Tahvo ASIC and allocate memory
3124 + * for its device-struct if found
3126 +static int __devinit tahvo_probe(struct device *dev)
3130 + /* Prepare tasklet */
3131 + tasklet_init(&tahvo_tasklet, tahvo_tasklet_handler, 0);
3133 + tahvo_initialized = 1;
3135 + rev = tahvo_read_reg(TAHVO_REG_ASICR);
3137 + id = (rev >> 8) & 0xff;
3139 + if ((rev & 0xff) >= 0x50)
3140 + tahvo_7bit_backlight = 1;
3141 + } else if (id == 0x0b) {
3142 + tahvo_is_betty = 1;
3143 + tahvo_7bit_backlight = 1;
3145 + printk(KERN_ERR "Tahvo/Betty chip not found");
3149 + printk(KERN_INFO "%s v%d.%d found\n", tahvo_is_betty ? "Betty" : "Tahvo",
3150 + (rev >> 4) & 0x0f, rev & 0x0f);
3152 + /* REVISIT: Pass these from board-*.c files in platform_data */
3153 + if (machine_is_nokia770()) {
3154 + tahvo_irq_pin = 40;
3155 + } else if (machine_is_nokia_n800() || machine_is_nokia_n810() ||
3156 + machine_is_nokia_n810_wimax()) {
3157 + tahvo_irq_pin = 111;
3159 + printk(KERN_ERR "cbus: Unsupported board for tahvo\n");
3163 + if ((ret = gpio_request(tahvo_irq_pin, "TAHVO irq")) < 0) {
3164 + printk(KERN_ERR PFX "Unable to reserve IRQ GPIO\n");
3168 + /* Set the pin as input */
3169 + gpio_direction_input(tahvo_irq_pin);
3171 + /* Rising edge triggers the IRQ */
3172 + set_irq_type(gpio_to_irq(tahvo_irq_pin), IRQ_TYPE_EDGE_RISING);
3174 + /* Mask all TAHVO interrupts */
3175 + tahvo_write_reg(TAHVO_REG_IMR, 0xffff);
3177 + ret = request_irq(gpio_to_irq(tahvo_irq_pin), tahvo_irq_handler, 0,
3180 + printk(KERN_ERR PFX "Unable to register IRQ handler\n");
3181 + gpio_free(tahvo_irq_pin);
3184 +#ifdef CONFIG_CBUS_TAHVO_USER
3185 + /* Initialize user-space interface */
3186 + if (tahvo_user_init() < 0) {
3187 + printk(KERN_ERR "Unable to initialize driver\n");
3188 + free_irq(gpio_to_irq(tahvo_irq_pin), 0);
3189 + gpio_free(tahvo_irq_pin);
3196 +static int tahvo_remove(struct device *dev)
3198 +#ifdef CONFIG_CBUS_TAHVO_USER
3199 + tahvo_user_cleanup();
3201 + /* Mask all TAHVO interrupts */
3202 + tahvo_write_reg(TAHVO_REG_IMR, 0xffff);
3203 + free_irq(gpio_to_irq(tahvo_irq_pin), 0);
3204 + gpio_free(tahvo_irq_pin);
3205 + tasklet_kill(&tahvo_tasklet);
3210 +static void tahvo_device_release(struct device *dev)
3212 + complete(&device_release);
3215 +static struct device_driver tahvo_driver = {
3217 + .bus = &platform_bus_type,
3218 + .probe = tahvo_probe,
3219 + .remove = tahvo_remove,
3222 +static struct platform_device tahvo_device = {
3226 + .release = tahvo_device_release,
3231 + * tahvo_init - initialise Tahvo driver
3233 + * Initialise the Tahvo driver and return 0 if everything worked ok
3235 +static int __init tahvo_init(void)
3239 + printk(KERN_INFO "Tahvo/Betty driver initialising\n");
3241 + init_completion(&device_release);
3243 + if ((ret = driver_register(&tahvo_driver)) < 0)
3246 + if ((ret = platform_device_register(&tahvo_device)) < 0) {
3247 + driver_unregister(&tahvo_driver);
3256 +static void __exit tahvo_exit(void)
3258 + platform_device_unregister(&tahvo_device);
3259 + driver_unregister(&tahvo_driver);
3260 + wait_for_completion(&device_release);
3263 +EXPORT_SYMBOL(tahvo_request_irq);
3264 +EXPORT_SYMBOL(tahvo_free_irq);
3265 +EXPORT_SYMBOL(tahvo_enable_irq);
3266 +EXPORT_SYMBOL(tahvo_disable_irq);
3267 +EXPORT_SYMBOL(tahvo_ack_irq);
3268 +EXPORT_SYMBOL(tahvo_read_reg);
3269 +EXPORT_SYMBOL(tahvo_write_reg);
3270 +EXPORT_SYMBOL(tahvo_get_backlight_level);
3271 +EXPORT_SYMBOL(tahvo_get_max_backlight_level);
3272 +EXPORT_SYMBOL(tahvo_set_backlight_level);
3274 +subsys_initcall(tahvo_init);
3275 +module_exit(tahvo_exit);
3277 +MODULE_DESCRIPTION("Tahvo ASIC control");
3278 +MODULE_LICENSE("GPL");
3279 +MODULE_AUTHOR("Juha Yrjölä, David Weinehall, and Mikko Ylinen");
3280 Index: linux-2.6.37/drivers/cbus/tahvo.h
3281 ===================================================================
3282 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3283 +++ linux-2.6.37/drivers/cbus/tahvo.h 2011-01-27 14:17:39.086000008 +0100
3286 + * drivers/cbus/tahvo.h
3288 + * Copyright (C) 2004, 2005 Nokia Corporation
3290 + * Written by Juha Yrjölä <juha.yrjola@nokia.com> and
3291 + * David Weinehall <david.weinehall@nokia.com>
3293 + * This file is subject to the terms and conditions of the GNU General
3294 + * Public License. See the file "COPYING" in the main directory of this
3295 + * archive for more details.
3297 + * This program is distributed in the hope that it will be useful,
3298 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3299 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3300 + * GNU General Public License for more details.
3302 + * You should have received a copy of the GNU General Public License
3303 + * along with this program; if not, write to the Free Software
3304 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3307 +#ifndef __DRIVERS_CBUS_TAHVO_H
3308 +#define __DRIVERS_CBUS_TAHVO_H
3310 +#include <linux/types.h>
3313 +#define TAHVO_REG_ASICR 0x00 /* ASIC ID & revision */
3314 +#define TAHVO_REG_IDR 0x01 /* Interrupt ID */
3315 +#define TAHVO_REG_IDSR 0x02 /* Interrupt status */
3316 +#define TAHVO_REG_IMR 0x03 /* Interrupt mask */
3317 +#define TAHVO_REG_LEDPWMR 0x05 /* LED PWM */
3318 +#define TAHVO_REG_USBR 0x06 /* USB control */
3319 +#define TAHVO_REG_MAX 0x0d
3321 +/* Interrupt sources */
3322 +#define TAHVO_INT_VBUSON 0
3324 +#define MAX_TAHVO_IRQ_HANDLERS 8
3326 +int tahvo_read_reg(int reg);
3327 +void tahvo_write_reg(int reg, u16 val);
3328 +void tahvo_set_clear_reg_bits(int reg, u16 set, u16 clear);
3329 +int tahvo_request_irq(int id, void *irq_handler, unsigned long arg, char *name);
3330 +void tahvo_free_irq(int id);
3331 +void tahvo_enable_irq(int id);
3332 +void tahvo_disable_irq(int id);
3333 +void tahvo_ack_irq(int id);
3334 +int tahvo_get_backlight_level(void);
3335 +int tahvo_get_max_backlight_level(void);
3336 +void tahvo_set_backlight_level(int level);
3338 +#ifdef CONFIG_CBUS_TAHVO_USER
3339 +int tahvo_user_init(void);
3340 +void tahvo_user_cleanup(void);
3343 +extern spinlock_t tahvo_lock;
3345 +#endif /* __DRIVERS_CBUS_TAHVO_H */
3346 Index: linux-2.6.37/drivers/cbus/tahvo-usb.c
3347 ===================================================================
3348 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3349 +++ linux-2.6.37/drivers/cbus/tahvo-usb.c 2011-01-27 14:17:39.087000008 +0100
3352 + * drivers/cbus/tahvo-usb.c
3354 + * Tahvo USB transeiver
3356 + * Copyright (C) 2005-2006 Nokia Corporation
3358 + * Parts copied from drivers/i2c/chips/isp1301_omap.c
3359 + * Copyright (C) 2004 Texas Instruments
3360 + * Copyright (C) 2004 David Brownell
3362 + * Written by Juha Yrjölä <juha.yrjola@nokia.com>,
3363 + * Tony Lindgren <tony@atomide.com>, and
3364 + * Timo Teräs <timo.teras@nokia.com>
3366 + * This file is subject to the terms and conditions of the GNU General
3367 + * Public License. See the file "COPYING" in the main directory of this
3368 + * archive for more details.
3370 + * This program is distributed in the hope that it will be useful,
3371 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3372 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3373 + * GNU General Public License for more details.
3375 + * You should have received a copy of the GNU General Public License
3376 + * along with this program; if not, write to the Free Software
3377 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3380 +#include <linux/kernel.h>
3381 +#include <linux/module.h>
3382 +#include <linux/init.h>
3383 +#include <linux/slab.h>
3384 +#include <linux/io.h>
3385 +#include <linux/interrupt.h>
3386 +#include <linux/platform_device.h>
3387 +#include <linux/usb/ch9.h>
3388 +#include <linux/usb/gadget.h>
3389 +#include <linux/usb.h>
3390 +#include <linux/usb/otg.h>
3391 +#include <linux/i2c.h>
3392 +#include <linux/workqueue.h>
3393 +#include <linux/kobject.h>
3394 +#include <linux/clk.h>
3395 +#include <linux/mutex.h>
3397 +#include <asm/irq.h>
3398 +#include <plat/usb.h>
3403 +#define DRIVER_NAME "tahvo-usb"
3405 +#define USBR_SLAVE_CONTROL (1 << 8)
3406 +#define USBR_VPPVIO_SW (1 << 7)
3407 +#define USBR_SPEED (1 << 6)
3408 +#define USBR_REGOUT (1 << 5)
3409 +#define USBR_MASTER_SW2 (1 << 4)
3410 +#define USBR_MASTER_SW1 (1 << 3)
3411 +#define USBR_SLAVE_SW (1 << 2)
3412 +#define USBR_NSUSPEND (1 << 1)
3413 +#define USBR_SEMODE (1 << 0)
3415 +/* bits in OTG_CTRL */
3417 +/* Bits that are controlled by OMAP OTG and are read-only */
3418 +#define OTG_CTRL_OMAP_MASK (OTG_PULLDOWN|OTG_PULLUP|OTG_DRV_VBUS|\
3419 + OTG_PD_VBUS|OTG_PU_VBUS|OTG_PU_ID)
3420 +/* Bits that are controlled by transceiver */
3421 +#define OTG_CTRL_XCVR_MASK (OTG_ASESSVLD|OTG_BSESSEND|\
3422 + OTG_BSESSVLD|OTG_VBUSVLD|OTG_ID)
3423 +/* Bits that are controlled by system */
3424 +#define OTG_CTRL_SYS_MASK (OTG_A_BUSREQ|OTG_A_SETB_HNPEN|OTG_B_BUSREQ|\
3425 + OTG_B_HNPEN|OTG_BUSDROP)
3427 +#if defined(CONFIG_USB_OHCI_HCD) && !defined(CONFIG_USB_OTG)
3428 +#error tahvo-otg.c does not work with OCHI yet!
3431 +#define TAHVO_MODE_HOST 0
3432 +#define TAHVO_MODE_PERIPHERAL 1
3434 +#ifdef CONFIG_USB_OTG
3435 +#define TAHVO_MODE(tu) (tu)->tahvo_mode
3436 +#elif defined(CONFIG_USB_GADGET_OMAP)
3437 +#define TAHVO_MODE(tu) TAHVO_MODE_PERIPHERAL
3439 +#define TAHVO_MODE(tu) TAHVO_MODE_HOST
3443 + struct platform_device *pt_dev;
3444 + struct otg_transceiver otg;
3446 + struct work_struct irq_work;
3447 + struct mutex serialize;
3448 +#ifdef CONFIG_USB_OTG
3452 +static struct platform_device tahvo_usb_device;
3455 + * ---------------------------------------------------------------------------
3456 + * OTG related functions
3458 + * These shoud be separated into omap-otg.c driver module, as they are used
3459 + * by various transceivers. These functions are needed in the UDC-only case
3460 + * as well. These functions are copied from GPL isp1301_omap.c
3461 + * ---------------------------------------------------------------------------
3463 +static struct platform_device *tahvo_otg_dev;
3465 +static irqreturn_t omap_otg_irq(int irq, void *arg)
3467 + struct platform_device *otg_dev = arg;
3468 + struct tahvo_usb *tu = platform_get_drvdata(otg_dev);
3471 + otg_irq = omap_readw(OTG_IRQ_SRC);
3472 + if (otg_irq & OPRT_CHG) {
3473 + omap_writew(OPRT_CHG, OTG_IRQ_SRC);
3474 + } else if (otg_irq & B_SRP_TMROUT) {
3475 + omap_writew(B_SRP_TMROUT, OTG_IRQ_SRC);
3476 + } else if (otg_irq & B_HNP_FAIL) {
3477 + omap_writew(B_HNP_FAIL, OTG_IRQ_SRC);
3478 + } else if (otg_irq & A_SRP_DETECT) {
3479 + omap_writew(A_SRP_DETECT, OTG_IRQ_SRC);
3480 + } else if (otg_irq & A_REQ_TMROUT) {
3481 + omap_writew(A_REQ_TMROUT, OTG_IRQ_SRC);
3482 + } else if (otg_irq & A_VBUS_ERR) {
3483 + omap_writew(A_VBUS_ERR, OTG_IRQ_SRC);
3484 + } else if (otg_irq & DRIVER_SWITCH) {
3485 + if ((!(omap_readl(OTG_CTRL) & OTG_DRIVER_SEL)) &&
3486 + tu->otg.host && tu->otg.state == OTG_STATE_A_HOST) {
3487 + /* role is host */
3488 + usb_bus_start_enum(tu->otg.host,
3489 + tu->otg.host->otg_port);
3491 + omap_writew(DRIVER_SWITCH, OTG_IRQ_SRC);
3495 + return IRQ_HANDLED;
3499 +static int tahvo_omap_otg_init(void)
3503 +#ifdef CONFIG_USB_OTG
3504 + if (!tahvo_otg_dev) {
3505 + printk("tahvo-usb: no tahvo_otg_dev\n");
3510 + l = omap_readl(OTG_SYSCON_1);
3511 + l &= ~OTG_IDLE_EN;
3512 + omap_writel(l, OTG_SYSCON_1);
3515 + /* some of these values are board-specific... */
3516 + l = omap_readl(OTG_SYSCON_2);
3518 + /* for B-device: */
3519 + | SRP_GPDATA /* 9msec Bdev D+ pulse */
3520 + | SRP_GPDVBUS /* discharge after VBUS pulse */
3521 + // | (3 << 24) /* 2msec VBUS pulse */
3522 + /* for A-device: */
3523 + | (0 << 20) /* 200ms nominal A_WAIT_VRISE timer */
3524 + | SRP_DPW /* detect 167+ns SRP pulses */
3525 + | SRP_DATA | SRP_VBUS; /* accept both kinds of SRP pulse */
3526 + omap_writel(l, OTG_SYSCON_2);
3528 + omap_writew(DRIVER_SWITCH | OPRT_CHG
3529 + | B_SRP_TMROUT | B_HNP_FAIL
3530 + | A_VBUS_ERR | A_SRP_DETECT | A_REQ_TMROUT,
3532 + l = omap_readl(OTG_SYSCON_2);
3534 + omap_writel(l, OTG_SYSCON_2);
3539 +static int omap_otg_probe(struct platform_device *pdev)
3543 + tahvo_otg_dev = pdev;
3544 + ret = tahvo_omap_otg_init();
3546 + printk(KERN_ERR "tahvo-usb: omap_otg_init failed\n");
3550 + err = request_irq(tahvo_otg_dev->resource[1].start,
3551 + omap_otg_irq, IRQF_DISABLED, DRIVER_NAME,
3552 + &tahvo_usb_device);
3557 +static int omap_otg_remove(struct platform_device *pdev)
3559 + free_irq(tahvo_otg_dev->resource[1].start, &tahvo_usb_device);
3560 + tahvo_otg_dev = NULL;
3565 +static struct platform_driver omap_otg_driver = {
3566 + .probe = omap_otg_probe,
3567 + .remove = omap_otg_remove,
3569 + .name = "omap_otg",
3574 + * ---------------------------------------------------------------------------
3575 + * Tahvo related functions
3576 + * These are Nokia proprietary code, except for the OTG register settings,
3577 + * which are copied from isp1301.c
3578 + * ---------------------------------------------------------------------------
3580 +static ssize_t vbus_state_show(struct device *device,
3581 + struct device_attribute *attr, char *buf)
3583 + struct platform_device *pdev = to_platform_device(device);
3584 + struct tahvo_usb *tu = platform_get_drvdata(pdev);
3585 + return sprintf(buf, "%d\n", tu->vbus_state);
3587 +static DEVICE_ATTR(vbus_state, 0444, vbus_state_show, NULL);
3589 +int vbus_active = 0;
3593 +static int host_suspend(struct tahvo_usb *tu)
3595 + struct device *dev;
3597 + if (!tu->otg.host)
3600 + /* Currently ASSUMES only the OTG port matters;
3601 + * other ports could be active...
3603 + dev = tu->otg.host->controller;
3604 + return dev->driver->suspend(dev, PMSG_SUSPEND);
3607 +static int host_resume(struct tahvo_usb *tu)
3609 + struct device *dev;
3611 + if (!tu->otg.host)
3614 + dev = tu->otg.host->controller;
3615 + return dev->driver->resume(dev);
3620 +static int host_suspend(struct tahvo_usb *tu)
3625 +static int host_resume(struct tahvo_usb *tu)
3632 +static void check_vbus_state(struct tahvo_usb *tu)
3634 + int reg, prev_state;
3636 + reg = tahvo_read_reg(TAHVO_REG_IDSR);
3641 + switch (tu->otg.state) {
3642 + case OTG_STATE_B_IDLE:
3643 + /* Enable the gadget driver */
3644 + if (tu->otg.gadget)
3645 + usb_gadget_vbus_connect(tu->otg.gadget);
3646 + /* Set B-session valid and not B-sessio ended to indicate
3647 + * Vbus to be ok. */
3648 + l = omap_readl(OTG_CTRL);
3649 + l &= ~OTG_BSESSEND;
3650 + l |= OTG_BSESSVLD;
3651 + omap_writel(l, OTG_CTRL);
3653 + tu->otg.state = OTG_STATE_B_PERIPHERAL;
3655 + case OTG_STATE_A_IDLE:
3656 + /* Session is now valid assuming the USB hub is driving Vbus */
3657 + tu->otg.state = OTG_STATE_A_HOST;
3663 + printk("USB cable connected\n");
3665 + switch (tu->otg.state) {
3666 + case OTG_STATE_B_PERIPHERAL:
3667 + if (tu->otg.gadget)
3668 + usb_gadget_vbus_disconnect(tu->otg.gadget);
3669 + tu->otg.state = OTG_STATE_B_IDLE;
3671 + case OTG_STATE_A_HOST:
3672 + tu->otg.state = OTG_STATE_A_IDLE;
3677 + printk("USB cable disconnected\n");
3681 + prev_state = tu->vbus_state;
3682 + tu->vbus_state = reg & 0x01;
3683 + if (prev_state != tu->vbus_state)
3684 + sysfs_notify(&tu->pt_dev->dev.kobj, NULL, "vbus_state");
3687 +static void tahvo_usb_become_host(struct tahvo_usb *tu)
3691 + /* Clear system and transceiver controlled bits
3692 + * also mark the A-session is always valid */
3693 + tahvo_omap_otg_init();
3695 + l = omap_readl(OTG_CTRL);
3696 + l &= ~(OTG_CTRL_XCVR_MASK | OTG_CTRL_SYS_MASK);
3697 + l |= OTG_ASESSVLD;
3698 + omap_writel(l, OTG_CTRL);
3700 + /* Power up the transceiver in USB host mode */
3701 + tahvo_write_reg(TAHVO_REG_USBR, USBR_REGOUT | USBR_NSUSPEND |
3702 + USBR_MASTER_SW2 | USBR_MASTER_SW1);
3703 + tu->otg.state = OTG_STATE_A_IDLE;
3705 + check_vbus_state(tu);
3708 +static void tahvo_usb_stop_host(struct tahvo_usb *tu)
3711 + tu->otg.state = OTG_STATE_A_IDLE;
3714 +static void tahvo_usb_become_peripheral(struct tahvo_usb *tu)
3718 + /* Clear system and transceiver controlled bits
3719 + * and enable ID to mark peripheral mode and
3720 + * BSESSEND to mark no Vbus */
3721 + tahvo_omap_otg_init();
3722 + l = omap_readl(OTG_CTRL);
3723 + l &= ~(OTG_CTRL_XCVR_MASK | OTG_CTRL_SYS_MASK | OTG_BSESSVLD);
3724 + l |= OTG_ID | OTG_BSESSEND;
3725 + omap_writel(l, OTG_CTRL);
3727 + /* Power up transceiver and set it in USB perhiperal mode */
3728 + tahvo_write_reg(TAHVO_REG_USBR, USBR_SLAVE_CONTROL | USBR_REGOUT | USBR_NSUSPEND | USBR_SLAVE_SW);
3729 + tu->otg.state = OTG_STATE_B_IDLE;
3731 + check_vbus_state(tu);
3734 +static void tahvo_usb_stop_peripheral(struct tahvo_usb *tu)
3738 + l = omap_readl(OTG_CTRL);
3739 + l &= ~OTG_BSESSVLD;
3740 + l |= OTG_BSESSEND;
3741 + omap_writel(l, OTG_CTRL);
3743 + if (tu->otg.gadget)
3744 + usb_gadget_vbus_disconnect(tu->otg.gadget);
3745 + tu->otg.state = OTG_STATE_B_IDLE;
3749 +static void tahvo_usb_power_off(struct tahvo_usb *tu)
3754 + /* Disable gadget controller if any */
3755 + if (tu->otg.gadget)
3756 + usb_gadget_vbus_disconnect(tu->otg.gadget);
3760 + /* Disable OTG and interrupts */
3761 + if (TAHVO_MODE(tu) == TAHVO_MODE_PERIPHERAL)
3765 + l = omap_readl(OTG_CTRL);
3766 + l &= ~(OTG_CTRL_XCVR_MASK | OTG_CTRL_SYS_MASK | OTG_BSESSVLD);
3767 + l |= id | OTG_BSESSEND;
3768 + omap_writel(l, OTG_CTRL);
3769 + omap_writew(0, OTG_IRQ_EN);
3771 + l = omap_readl(OTG_SYSCON_2);
3773 + omap_writel(l, OTG_SYSCON_2);
3775 + l = omap_readl(OTG_SYSCON_1);
3777 + omap_writel(l, OTG_SYSCON_1);
3779 + /* Power off transceiver */
3780 + tahvo_write_reg(TAHVO_REG_USBR, 0);
3781 + tu->otg.state = OTG_STATE_UNDEFINED;
3785 +static int tahvo_usb_set_power(struct otg_transceiver *dev, unsigned mA)
3787 + struct tahvo_usb *tu = container_of(dev, struct tahvo_usb, otg);
3789 + dev_dbg(&tu->pt_dev->dev, "set_power %d mA\n", mA);
3791 + if (dev->state == OTG_STATE_B_PERIPHERAL) {
3792 + /* REVISIT: Can Tahvo charge battery from VBUS? */
3797 +static int tahvo_usb_set_suspend(struct otg_transceiver *dev, int suspend)
3799 + struct tahvo_usb *tu = container_of(dev, struct tahvo_usb, otg);
3802 + dev_dbg(&tu->pt_dev->dev, "set_suspend\n");
3804 + w = tahvo_read_reg(TAHVO_REG_USBR);
3806 + w &= ~USBR_NSUSPEND;
3808 + w |= USBR_NSUSPEND;
3809 + tahvo_write_reg(TAHVO_REG_USBR, w);
3814 +static int tahvo_usb_start_srp(struct otg_transceiver *dev)
3816 + struct tahvo_usb *tu = container_of(dev, struct tahvo_usb, otg);
3819 + dev_dbg(&tu->pt_dev->dev, "start_srp\n");
3821 + if (!dev || tu->otg.state != OTG_STATE_B_IDLE)
3824 + otg_ctrl = omap_readl(OTG_CTRL);
3825 + if (!(otg_ctrl & OTG_BSESSEND))
3828 + otg_ctrl |= OTG_B_BUSREQ;
3829 + otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_SYS_MASK;
3830 + omap_writel(otg_ctrl, OTG_CTRL);
3831 + tu->otg.state = OTG_STATE_B_SRP_INIT;
3836 +static int tahvo_usb_start_hnp(struct otg_transceiver *otg)
3838 + struct tahvo_usb *tu = container_of(otg, struct tahvo_usb, otg);
3840 + dev_dbg(&tu->pt_dev->dev, "start_hnp\n");
3841 +#ifdef CONFIG_USB_OTG
3842 + /* REVISIT: Add this for OTG */
3847 +static int tahvo_usb_set_host(struct otg_transceiver *otg, struct usb_bus *host)
3849 + struct tahvo_usb *tu = container_of(otg, struct tahvo_usb, otg);
3852 + dev_dbg(&tu->pt_dev->dev, "set_host %p\n", host);
3857 +#if defined(CONFIG_USB_OTG) || !defined(CONFIG_USB_GADGET_OMAP)
3859 + mutex_lock(&tu->serialize);
3861 + if (host == NULL) {
3862 + if (TAHVO_MODE(tu) == TAHVO_MODE_HOST)
3863 + tahvo_usb_power_off(tu);
3864 + tu->otg.host = NULL;
3865 + mutex_unlock(&tu->serialize);
3869 + l = omap_readl(OTG_SYSCON_1);
3870 + l &= ~(OTG_IDLE_EN | HST_IDLE_EN | DEV_IDLE_EN);
3871 + omap_writel(l, OTG_SYSCON_1);
3873 + if (TAHVO_MODE(tu) == TAHVO_MODE_HOST) {
3874 + tu->otg.host = NULL;
3875 + tahvo_usb_become_host(tu);
3879 + tu->otg.host = host;
3881 + mutex_unlock(&tu->serialize);
3883 + /* No host mode configured, so do not allow host controlled to be set */
3890 +static int tahvo_usb_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget)
3892 + struct tahvo_usb *tu = container_of(otg, struct tahvo_usb, otg);
3894 + dev_dbg(&tu->pt_dev->dev, "set_peripheral %p\n", gadget);
3899 +#if defined(CONFIG_USB_OTG) || defined(CONFIG_USB_GADGET_OMAP)
3901 + mutex_lock(&tu->serialize);
3904 + if (TAHVO_MODE(tu) == TAHVO_MODE_PERIPHERAL)
3905 + tahvo_usb_power_off(tu);
3906 + tu->otg.gadget = NULL;
3907 + mutex_unlock(&tu->serialize);
3911 + tu->otg.gadget = gadget;
3912 + if (TAHVO_MODE(tu) == TAHVO_MODE_PERIPHERAL)
3913 + tahvo_usb_become_peripheral(tu);
3915 + mutex_unlock(&tu->serialize);
3917 + /* No gadget mode configured, so do not allow host controlled to be set */
3924 +static void tahvo_usb_irq_work(struct work_struct *work)
3926 + struct tahvo_usb *tu = container_of(work, struct tahvo_usb, irq_work);
3928 + mutex_lock(&tu->serialize);
3929 + check_vbus_state(tu);
3930 + mutex_unlock(&tu->serialize);
3933 +static void tahvo_usb_vbus_interrupt(unsigned long arg)
3935 + struct tahvo_usb *tu = (struct tahvo_usb *) arg;
3937 + tahvo_ack_irq(TAHVO_INT_VBUSON);
3938 + /* Seems we need this to acknowledge the interrupt */
3939 + tahvo_read_reg(TAHVO_REG_IDSR);
3940 + schedule_work(&tu->irq_work);
3943 +#ifdef CONFIG_USB_OTG
3944 +static ssize_t otg_mode_show(struct device *device,
3945 + struct device_attribute *attr, char *buf)
3947 + struct platform_device *pdev = to_platform_device(device);
3948 + struct tahvo_usb *tu = platform_get_drvdata(pdev);
3950 + switch (tu->tahvo_mode) {
3951 + case TAHVO_MODE_HOST:
3952 + return sprintf(buf, "host\n");
3953 + case TAHVO_MODE_PERIPHERAL:
3954 + return sprintf(buf, "peripheral\n");
3957 + return sprintf(buf, "unknown\n");
3960 +static ssize_t otg_mode_store(struct device *device,
3961 + struct device_attribute *attr,
3962 + const char *buf, size_t count)
3964 + struct platform_device *pdev = to_platform_device(device);
3965 + struct tahvo_usb *tu = platform_get_drvdata(pdev);
3969 + mutex_lock(&tu->serialize);
3970 + if (strncmp(buf, "host", 4) == 0) {
3971 + if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL)
3972 + tahvo_usb_stop_peripheral(tu);
3973 + tu->tahvo_mode = TAHVO_MODE_HOST;
3974 + if (tu->otg.host) {
3975 + printk(KERN_INFO "Selected HOST mode: host controller present.\n");
3976 + tahvo_usb_become_host(tu);
3978 + printk(KERN_INFO "Selected HOST mode: no host controller, powering off.\n");
3979 + tahvo_usb_power_off(tu);
3981 + } else if (strncmp(buf, "peripheral", 10) == 0) {
3982 + if (tu->tahvo_mode == TAHVO_MODE_HOST)
3983 + tahvo_usb_stop_host(tu);
3984 + tu->tahvo_mode = TAHVO_MODE_PERIPHERAL;
3985 + if (tu->otg.gadget) {
3986 + printk(KERN_INFO "Selected PERIPHERAL mode: gadget driver present.\n");
3987 + tahvo_usb_become_peripheral(tu);
3989 + printk(KERN_INFO "Selected PERIPHERAL mode: no gadget driver, powering off.\n");
3990 + tahvo_usb_power_off(tu);
3995 + mutex_unlock(&tu->serialize);
3999 +static DEVICE_ATTR(otg_mode, 0644, otg_mode_show, otg_mode_store);
4002 +static int tahvo_usb_probe(struct platform_device *pdev)
4004 + struct tahvo_usb *tu;
4007 + dev_dbg(&pdev->dev, "probe\n");
4009 + /* Create driver data */
4010 + tu = kmalloc(sizeof(*tu), GFP_KERNEL);
4013 + memset(tu, 0, sizeof(*tu));
4014 + tu->pt_dev = pdev;
4015 +#ifdef CONFIG_USB_OTG
4016 + /* Default mode */
4017 +#ifdef CONFIG_CBUS_TAHVO_USB_HOST_BY_DEFAULT
4018 + tu->tahvo_mode = TAHVO_MODE_HOST;
4020 + tu->tahvo_mode = TAHVO_MODE_PERIPHERAL;
4024 + INIT_WORK(&tu->irq_work, tahvo_usb_irq_work);
4025 + mutex_init(&tu->serialize);
4027 + /* Set initial state, so that we generate kevents only on
4028 + * state changes */
4029 + tu->vbus_state = tahvo_read_reg(TAHVO_REG_IDSR) & 0x01;
4031 + /* We cannot enable interrupt until omap_udc is initialized */
4032 + ret = tahvo_request_irq(TAHVO_INT_VBUSON, tahvo_usb_vbus_interrupt,
4033 + (unsigned long) tu, "vbus_interrupt");
4036 + printk(KERN_ERR "Could not register Tahvo interrupt for VBUS\n");
4041 + ret = device_create_file(&pdev->dev, &dev_attr_vbus_state);
4042 +#ifdef CONFIG_USB_OTG
4043 + ret |= device_create_file(&pdev->dev, &dev_attr_otg_mode);
4046 + printk(KERN_ERR "attribute creation failed: %d\n", ret);
4048 + /* Create OTG interface */
4049 + tahvo_usb_power_off(tu);
4050 + tu->otg.state = OTG_STATE_UNDEFINED;
4051 + tu->otg.label = DRIVER_NAME;
4052 + tu->otg.set_host = tahvo_usb_set_host;
4053 + tu->otg.set_peripheral = tahvo_usb_set_peripheral;
4054 + tu->otg.set_power = tahvo_usb_set_power;
4055 + tu->otg.set_suspend = tahvo_usb_set_suspend;
4056 + tu->otg.start_srp = tahvo_usb_start_srp;
4057 + tu->otg.start_hnp = tahvo_usb_start_hnp;
4059 + ret = otg_set_transceiver(&tu->otg);
4061 + printk(KERN_ERR "Cannot register USB transceiver\n");
4063 + tahvo_free_irq(TAHVO_INT_VBUSON);
4067 + platform_set_drvdata(pdev, tu);
4069 + /* Act upon current vbus state once at startup. A vbus state irq may or
4070 + * may not be generated in addition to this. */
4071 + schedule_work(&tu->irq_work);
4075 +static int tahvo_usb_remove(struct platform_device *pdev)
4077 + dev_dbg(&pdev->dev, "remove\n");
4079 + tahvo_free_irq(TAHVO_INT_VBUSON);
4080 + flush_scheduled_work();
4081 + otg_set_transceiver(0);
4082 + device_remove_file(&pdev->dev, &dev_attr_vbus_state);
4083 +#ifdef CONFIG_USB_OTG
4084 + device_remove_file(&pdev->dev, &dev_attr_otg_mode);
4089 +static struct platform_driver tahvo_usb_driver = {
4090 + .probe = tahvo_usb_probe,
4091 + .remove = tahvo_usb_remove,
4093 + .name = "tahvo-usb",
4097 +static struct platform_device tahvo_usb_device = {
4098 + .name = "tahvo-usb",
4102 +static int __init tahvo_usb_init(void)
4106 + printk(KERN_INFO "Tahvo USB transceiver driver initializing\n");
4108 + ret = platform_driver_register(&tahvo_usb_driver);
4111 + ret = platform_driver_register(&omap_otg_driver);
4113 + platform_driver_unregister(&tahvo_usb_driver);
4117 + ret = platform_device_register(&tahvo_usb_device);
4119 + platform_driver_unregister(&omap_otg_driver);
4120 + platform_driver_unregister(&tahvo_usb_driver);
4126 +subsys_initcall(tahvo_usb_init);
4128 +static void __exit tahvo_usb_exit(void)
4130 + platform_device_unregister(&tahvo_usb_device);
4131 + platform_driver_unregister(&omap_otg_driver);
4132 + platform_driver_unregister(&tahvo_usb_driver);
4134 +module_exit(tahvo_usb_exit);
4136 +MODULE_DESCRIPTION("Tahvo USB OTG Transceiver Driver");
4137 +MODULE_LICENSE("GPL");
4138 +MODULE_AUTHOR("Juha Yrjölä, Tony Lindgren, and Timo Teräs");
4139 Index: linux-2.6.37/drivers/cbus/tahvo-user.c
4140 ===================================================================
4141 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
4142 +++ linux-2.6.37/drivers/cbus/tahvo-user.c 2011-01-27 14:17:39.087000008 +0100
4145 + * drivers/cbus/tahvo-user.c
4147 + * Tahvo user space interface functions
4149 + * Copyright (C) 2004, 2005 Nokia Corporation
4151 + * Written by Mikko Ylinen <mikko.k.ylinen@nokia.com>
4153 + * This file is subject to the terms and conditions of the GNU General
4154 + * Public License. See the file "COPYING" in the main directory of this
4155 + * archive for more details.
4157 + * This program is distributed in the hope that it will be useful,
4158 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4159 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4160 + * GNU General Public License for more details.
4162 + * You should have received a copy of the GNU General Public License
4163 + * along with this program; if not, write to the Free Software
4164 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
4167 +#include <linux/types.h>
4168 +#include <linux/kernel.h>
4169 +#include <linux/interrupt.h>
4170 +#include <linux/module.h>
4171 +#include <linux/init.h>
4172 +#include <linux/fs.h>
4173 +#include <linux/miscdevice.h>
4174 +#include <linux/poll.h>
4175 +#include <linux/list.h>
4176 +#include <linux/spinlock.h>
4177 +#include <linux/sched.h>
4178 +#include <linux/mutex.h>
4179 +#include <linux/slab.h>
4181 +#include <asm/uaccess.h>
4185 +#include "user_retu_tahvo.h"
4187 +/* Maximum size of IRQ node buffer/pool */
4188 +#define TAHVO_MAX_IRQ_BUF_LEN 16
4190 +#define PFX "tahvo-user: "
4192 +/* Bitmap for marking the interrupt sources as having the handlers */
4193 +static u32 tahvo_irq_bits;
4195 +/* For allowing only one user process to subscribe to the tahvo interrupts */
4196 +static struct file *tahvo_irq_subscr = NULL;
4198 +/* For poll and IRQ passing */
4201 + struct list_head node;
4204 +static spinlock_t tahvo_irqs_lock;
4205 +static struct tahvo_irq *tahvo_irq_block;
4206 +static LIST_HEAD(tahvo_irqs);
4207 +static LIST_HEAD(tahvo_irqs_reserve);
4209 +/* Wait queue - used when user wants to read the device */
4210 +DECLARE_WAIT_QUEUE_HEAD(tahvo_user_waitqueue);
4212 +/* Semaphore to protect irq subscription sequence */
4213 +static struct mutex tahvo_mutex;
4215 +/* This array specifies TAHVO register types (read/write/toggle) */
4216 +static const u8 tahvo_access_bits[] = {
4234 + * The handler for all TAHVO interrupts.
4236 + * arg is the interrupt source in TAHVO.
4238 +static void tahvo_user_irq_handler(unsigned long arg)
4240 + struct tahvo_irq *irq;
4242 + /* user has to re-enable the interrupt once ready
4243 + * for receiving them again */
4244 + tahvo_disable_irq(arg);
4245 + tahvo_ack_irq(arg);
4247 + spin_lock(&tahvo_irqs_lock);
4248 + if (list_empty(&tahvo_irqs_reserve)) {
4249 + spin_unlock(&tahvo_irqs_lock);
4252 + irq = list_entry((&tahvo_irqs_reserve)->next, struct tahvo_irq, node);
4254 + list_move_tail(&irq->node, &tahvo_irqs);
4255 + spin_unlock(&tahvo_irqs_lock);
4257 + /* wake up waiting thread */
4258 + wake_up(&tahvo_user_waitqueue);
4262 + * This routine sets up the interrupt handler and marks an interrupt source
4263 + * in TAHVO as a candidate for signal delivery to the user process.
4265 +static int tahvo_user_subscribe_to_irq(int id, struct file *filp)
4269 + mutex_lock(&tahvo_mutex);
4270 + if ((tahvo_irq_subscr != NULL) && (tahvo_irq_subscr != filp)) {
4271 + mutex_unlock(&tahvo_mutex);
4274 + /* Store the file pointer of the first user process registering IRQs */
4275 + tahvo_irq_subscr = filp;
4276 + mutex_unlock(&tahvo_mutex);
4278 + if (tahvo_irq_bits & (1 << id))
4281 + ret = tahvo_request_irq(id, tahvo_user_irq_handler, id, "");
4285 + /* Mark that this interrupt has a handler */
4286 + tahvo_irq_bits |= 1 << id;
4292 + * Unregister all TAHVO interrupt handlers
4294 +static void tahvo_unreg_irq_handlers(void)
4298 + if (!tahvo_irq_bits)
4301 + for (id = 0; id < MAX_TAHVO_IRQ_HANDLERS; id++)
4302 + if (tahvo_irq_bits & (1 << id))
4303 + tahvo_free_irq(id);
4305 + tahvo_irq_bits = 0;
4309 + * Write to TAHVO register.
4310 + * Returns 0 upon success, a negative error value otherwise.
4312 +static int tahvo_user_write_with_mask(u32 field, u16 value)
4317 + unsigned long flags;
4319 + mask = MASK(field);
4322 + /* Detect bad mask and reg */
4323 + if (mask == 0 || reg > TAHVO_REG_MAX ||
4324 + tahvo_access_bits[reg] == READ_ONLY) {
4325 + printk(KERN_ERR PFX "invalid arguments (reg=%#x, mask=%#x)\n",
4330 + /* Justify value according to mask */
4331 + while (!(mask & 1)) {
4332 + value = value << 1;
4336 + spin_lock_irqsave(&tahvo_lock, flags);
4337 + if (tahvo_access_bits[reg] == TOGGLE) {
4338 + /* No need to detect previous content of register */
4341 + /* Read current value of register */
4342 + tmp = tahvo_read_reg(reg);
4344 + /* Generate a new value */
4345 + tmp = (tmp & ~MASK(field)) | (value & MASK(field));
4346 + /* Write data to TAHVO */
4347 + tahvo_write_reg(reg, tmp);
4348 + spin_unlock_irqrestore(&tahvo_lock, flags);
4354 + * Read TAHVO register.
4356 +static u32 tahvo_user_read_with_mask(u32 field)
4361 + mask = MASK(field);
4364 + /* Detect bad mask and reg */
4365 + if (mask == 0 || reg > TAHVO_REG_MAX) {
4366 + printk(KERN_ERR PFX "invalid arguments (reg=%#x, mask=%#x)\n",
4371 + /* Read the register */
4372 + value = tahvo_read_reg(reg) & mask;
4374 + /* Right justify value */
4375 + while (!(mask & 1)) {
4376 + value = value >> 1;
4386 +static int tahvo_close(struct inode *inode, struct file *filp)
4388 + /* Unregister all interrupts that have been registered */
4389 + if (tahvo_irq_subscr == filp) {
4390 + tahvo_unreg_irq_handlers();
4391 + tahvo_irq_subscr = NULL;
4398 + * Device control (ioctl)
4400 +static long tahvo_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4402 + struct retu_tahvo_write_parms par;
4406 + case URT_IOCT_IRQ_SUBSCR:
4407 + return tahvo_user_subscribe_to_irq(arg, filp);
4408 + case TAHVO_IOCH_READ:
4409 + return tahvo_user_read_with_mask(arg);
4410 + case TAHVO_IOCX_WRITE:
4411 + ret = copy_from_user(&par, (void __user *) arg, sizeof(par));
4413 + printk(KERN_ERR "copy_from_user failed: %d\n", ret);
4414 + par.result = tahvo_user_write_with_mask(par.field, par.value);
4415 + ret = copy_to_user((void __user *) arg, &par, sizeof(par));
4417 + printk(KERN_ERR "copy_to_user failed: %d\n", ret);
4420 + return -ENOIOCTLCMD;
4426 + * Read from device
4428 +static ssize_t tahvo_read(struct file *filp, char *buf, size_t count,
4431 + struct tahvo_irq *irq;
4435 + /* read not permitted if neither filp nor anyone has registered IRQs */
4436 + if (tahvo_irq_subscr != filp)
4439 + if ((count < sizeof(u32)) || ((count % sizeof(u32)) != 0))
4442 + nr = count / sizeof(u32);
4444 + for (i = 0; i < nr; i++) {
4445 + unsigned long flags;
4449 + ret = wait_event_interruptible(tahvo_user_waitqueue,
4450 + !list_empty(&tahvo_irqs));
4454 + spin_lock_irqsave(&tahvo_irqs_lock, flags);
4455 + irq = list_entry((&tahvo_irqs)->next, struct tahvo_irq, node);
4457 + list_move(&irq->node, &tahvo_irqs_reserve);
4458 + spin_unlock_irqrestore(&tahvo_irqs_lock, flags);
4460 + ret = copy_to_user(buf + i * sizeof(irq_id), &irq_id,
4463 + printk(KERN_ERR "copy_to_user failed: %d\n", ret);
4472 +static unsigned tahvo_poll(struct file *filp, struct poll_table_struct *pt)
4474 + if (!list_empty(&tahvo_irqs))
4477 + poll_wait(filp, &tahvo_user_waitqueue, pt);
4479 + if (!list_empty(&tahvo_irqs))
4485 +static struct file_operations tahvo_user_fileops = {
4486 + .owner = THIS_MODULE,
4487 + .unlocked_ioctl = tahvo_ioctl,
4488 + .read = tahvo_read,
4489 + .release = tahvo_close,
4490 + .poll = tahvo_poll
4493 +static struct miscdevice tahvo_device = {
4494 + .minor = MISC_DYNAMIC_MINOR,
4496 + .fops = &tahvo_user_fileops
4502 + * @return 0 if successful, error value otherwise.
4504 +int tahvo_user_init(void)
4506 + struct tahvo_irq *irq;
4509 + irq = kmalloc(sizeof(*irq) * TAHVO_MAX_IRQ_BUF_LEN, GFP_KERNEL);
4510 + if (irq == NULL) {
4511 + printk(KERN_ERR PFX "kmalloc failed\n");
4514 + memset(irq, 0, sizeof(*irq) * TAHVO_MAX_IRQ_BUF_LEN);
4515 + for (i = 0; i < TAHVO_MAX_IRQ_BUF_LEN; i++)
4516 + list_add(&irq[i].node, &tahvo_irqs_reserve);
4518 + tahvo_irq_block = irq;
4520 + spin_lock_init(&tahvo_irqs_lock);
4521 + mutex_init(&tahvo_mutex);
4523 + /* Request a misc device */
4524 + res = misc_register(&tahvo_device);
4526 + printk(KERN_ERR PFX "unable to register misc device for %s\n",
4527 + tahvo_device.name);
4538 +void tahvo_user_cleanup(void)
4540 + /* Unregister our misc device */
4541 + misc_deregister(&tahvo_device);
4542 + /* Unregister and disable all TAHVO interrupts */
4543 + tahvo_unreg_irq_handlers();
4544 + kfree(tahvo_irq_block);
4547 +MODULE_DESCRIPTION("Tahvo ASIC user space functions");
4548 +MODULE_LICENSE("GPL");
4549 +MODULE_AUTHOR("Mikko Ylinen");
4550 Index: linux-2.6.37/drivers/cbus/user_retu_tahvo.h
4551 ===================================================================
4552 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
4553 +++ linux-2.6.37/drivers/cbus/user_retu_tahvo.h 2011-01-27 14:17:39.087000008 +0100
4556 + * drivers/cbus/user_retu_tahvo.h
4558 + * Copyright (C) 2004, 2005 Nokia Corporation
4560 + * Written by Mikko Ylinen <mikko.k.ylinen@nokia.com>
4562 + * Definitions and types used by both retu-user and tahvo-user.
4564 + * This file is subject to the terms and conditions of the GNU General
4565 + * Public License. See the file "COPYING" in the main directory of this
4566 + * archive for more details.
4568 + * This program is distributed in the hope that it will be useful,
4569 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4570 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4571 + * GNU General Public License for more details.
4573 + * You should have received a copy of the GNU General Public License
4574 + * along with this program; if not, write to the Free Software
4575 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
4578 +#ifndef _USER_RETU_TAHVO_H
4579 +#define _USER_RETU_TAHVO_H
4582 +#define CHIP_RETU 1
4583 +#define CHIP_TAHVO 2
4585 +/* Register access type bits */
4586 +#define READ_ONLY 1
4587 +#define WRITE_ONLY 2
4588 +#define READ_WRITE 3
4591 +#define MASK(field) ((u16)(field & 0xFFFF))
4592 +#define REG(field) ((u16)((field >> 16) & 0x3F))
4594 +/*** IOCTL definitions. These should be kept in sync with user space **********/
4596 +#define URT_IOC_MAGIC '`'
4599 + * IOCTL function naming conventions:
4600 + * ==================================
4601 + * 0 -- No argument and return value
4602 + * S -- Set through a pointer
4603 + * T -- Tell directly with the argument value
4604 + * G -- Reply by setting through a pointer
4605 + * Q -- response is on the return value
4606 + * X -- S and G atomically
4607 + * H -- T and Q atomically
4611 +#define URT_IOCT_IRQ_SUBSCR _IO(URT_IOC_MAGIC, 0)
4614 +#define RETU_IOCH_READ _IO(URT_IOC_MAGIC, 1)
4615 +#define RETU_IOCX_WRITE _IO(URT_IOC_MAGIC, 2)
4616 +#define RETU_IOCH_ADC_READ _IO(URT_IOC_MAGIC, 3)
4619 +#define TAHVO_IOCH_READ _IO(URT_IOC_MAGIC, 4)
4620 +#define TAHVO_IOCX_WRITE _IO(URT_IOC_MAGIC, 5)
4622 +/* This structure is used for writing RETU/TAHVO registers */
4623 +struct retu_tahvo_write_parms {
4630 Index: linux-2.6.37/drivers/Makefile
4631 ===================================================================
4632 --- linux-2.6.37.orig/drivers/Makefile 2011-01-27 14:17:04.232000007 +0100
4633 +++ linux-2.6.37/drivers/Makefile 2011-01-27 14:17:39.087000008 +0100
4635 obj-$(CONFIG_INPUT) += input/
4636 obj-$(CONFIG_I2O) += message/
4637 obj-$(CONFIG_RTC_LIB) += rtc/
4638 -obj-y += i2c/ media/
4639 +obj-y += i2c/ media/ cbus/
4640 obj-$(CONFIG_PPS) += pps/
4641 obj-$(CONFIG_W1) += w1/
4642 obj-$(CONFIG_POWER_SUPPLY) += power/
4643 Index: linux-2.6.37/arch/arm/Kconfig
4644 ===================================================================
4645 --- linux-2.6.37.orig/arch/arm/Kconfig 2011-01-27 14:17:04.178000007 +0100
4646 +++ linux-2.6.37/arch/arm/Kconfig 2011-01-27 14:17:39.087000008 +0100
4647 @@ -1850,6 +1850,10 @@
4649 source "drivers/Kconfig"
4652 +source "drivers/cbus/Kconfig"
4657 source "arch/arm/Kconfig.debug"