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.38-rc6/drivers/cbus/cbus.c
23 ===================================================================
24 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
25 +++ linux-2.6.38-rc6/drivers/cbus/cbus.c 2011-02-24 12:04:51.456189134 +0100
28 + * drivers/cbus/cbus.c
30 + * Support functions for CBUS serial protocol
32 + * Copyright (C) 2004-2010 Nokia Corporation
33 + * Contact: Felipe Balbi <felipe.balbi@nokia.com>
35 + * Written by Juha Yrjölä <juha.yrjola@nokia.com>,
36 + * David Weinehall <david.weinehall@nokia.com>, and
37 + * Mikko Ylinen <mikko.k.ylinen@nokia.com>
39 + * Several updates and cleanups by Felipe Balbi <felipe.balbi@nokia.com>
41 + * This file is subject to the terms and conditions of the GNU General
42 + * Public License. See the file "COPYING" in the main directory of this
43 + * archive for more details.
45 + * This program is distributed in the hope that it will be useful,
46 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
47 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48 + * GNU General Public License for more details.
50 + * You should have received a copy of the GNU General Public License
51 + * along with this program; if not, write to the Free Software
52 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
55 +#include <linux/device.h>
56 +#include <linux/init.h>
57 +#include <linux/kernel.h>
58 +#include <linux/slab.h>
59 +#include <linux/spinlock.h>
60 +#include <linux/gpio.h>
61 +#include <linux/platform_device.h>
63 +#include <plat/cbus.h>
67 +#define CBUS_XFER_READ 1
68 +#define CBUS_XFER_WRITE 0
81 +static struct cbus_host *cbus_host;
84 + * cbus_send_bit - sends one bit over the bus
85 + * @host: the host we're using
86 + * @bit: one bit of information to send
87 + * @input: whether to set data pin as input after sending
89 +static int cbus_send_bit(struct cbus_host *host, unsigned bit,
94 + gpio_set_value(host->dat_gpio, bit ? 1 : 0);
95 + gpio_set_value(host->clk_gpio, 1);
97 + /* The data bit is read on the rising edge of CLK */
99 + ret = gpio_direction_input(host->dat_gpio);
101 + gpio_set_value(host->clk_gpio, 0);
107 + * cbus_send_data - sends @len amount of data over the bus
108 + * @host: the host we're using
109 + * @data: the data to send
110 + * @len: size of the transfer
111 + * @input: whether to set data pin as input after sending
113 +static int cbus_send_data(struct cbus_host *host, unsigned data, unsigned len,
119 + for (i = len; i > 0; i--) {
120 + ret = cbus_send_bit(host, data & (1 << (i - 1)),
121 + input && (i == 1));
131 + * cbus_receive_bit - receives one bit from the bus
132 + * @host: the host we're using
134 +static int cbus_receive_bit(struct cbus_host *host)
138 + gpio_set_value(host->clk_gpio, 1);
139 + ret = gpio_get_value(host->dat_gpio);
142 + gpio_set_value(host->clk_gpio, 0);
149 + * cbus_receive_data - receives @len data from the bus
150 + * @host: the host we're using
151 + * @len: the length of data to receive
153 +static int cbus_receive_data(struct cbus_host *host, unsigned len)
158 + for (i = 16; i > 0; i--) {
159 + int bit = cbus_receive_bit(host);
165 + ret |= 1 << (i - 1);
173 + * cbus_transfer - transfers data over the bus
174 + * @host: the host we're using
175 + * @rw: read/write flag
176 + * @dev: device address
177 + * @reg: register address
178 + * @data: if @rw == 0 data to send otherwise 0
180 +static int cbus_transfer(struct cbus_host *host, unsigned rw, unsigned dev,
181 + unsigned reg, unsigned data)
183 + unsigned long flags;
187 + /* We don't want interrupts disturbing our transfer */
188 + spin_lock_irqsave(&host->lock, flags);
190 + /* Reset state and start of transfer, SEL stays down during transfer */
191 + gpio_set_value(host->sel_gpio, 0);
193 + /* Set the DAT pin to output */
194 + gpio_direction_output(host->dat_gpio, 1);
196 + /* Send the device address */
197 + ret = cbus_send_data(host, dev, 3, 0);
199 + dev_dbg(host->dev, "failed sending device addr\n");
203 + /* Send the rw flag */
204 + ret = cbus_send_bit(host, rw, 0);
206 + dev_dbg(host->dev, "failed sending read/write flag\n");
210 + /* Send the register address */
214 + ret = cbus_send_data(host, reg, 5, input);
216 + dev_dbg(host->dev, "failed sending register addr\n");
221 + ret = cbus_send_data(host, data, 16, 0);
223 + dev_dbg(host->dev, "failed sending data\n");
227 + gpio_set_value(host->clk_gpio, 1);
229 + ret = cbus_receive_data(host, 16);
231 + dev_dbg(host->dev, "failed receiving data\n");
236 + /* Indicate end of transfer, SEL goes up until next transfer */
237 + gpio_set_value(host->sel_gpio, 1);
238 + gpio_set_value(host->clk_gpio, 1);
239 + gpio_set_value(host->clk_gpio, 0);
242 + spin_unlock_irqrestore(&host->lock, flags);
248 + * cbus_read_reg - reads a given register from the device
249 + * @dev: device address
250 + * @reg: register address
252 +int cbus_read_reg(unsigned dev, unsigned reg)
254 + return cbus_transfer(cbus_host, CBUS_XFER_READ, dev, reg, 0);
256 +EXPORT_SYMBOL(cbus_read_reg);
259 + * cbus_write_reg - writes to a given register of the device
260 + * @dev: device address
261 + * @reg: register address
262 + * @val: data to be written to @reg
264 +int cbus_write_reg(unsigned dev, unsigned reg, unsigned val)
266 + return cbus_transfer(cbus_host, CBUS_XFER_WRITE, dev, reg, val);
268 +EXPORT_SYMBOL(cbus_write_reg);
270 +static int __init cbus_bus_probe(struct platform_device *pdev)
272 + struct cbus_host *chost;
273 + struct cbus_host_platform_data *pdata = pdev->dev.platform_data;
276 + chost = kzalloc(sizeof(*chost), GFP_KERNEL);
280 + spin_lock_init(&chost->lock);
282 + chost->clk_gpio = pdata->clk_gpio;
283 + chost->dat_gpio = pdata->dat_gpio;
284 + chost->sel_gpio = pdata->sel_gpio;
285 + chost->dev = &pdev->dev;
287 + ret = gpio_request(chost->clk_gpio, "CBUS clk");
291 + ret = gpio_request(chost->dat_gpio, "CBUS data");
295 + ret = gpio_request(chost->sel_gpio, "CBUS sel");
299 + gpio_direction_output(chost->clk_gpio, 0);
300 + gpio_direction_input(chost->dat_gpio);
301 + gpio_direction_output(chost->sel_gpio, 1);
303 + gpio_set_value(chost->clk_gpio, 1);
304 + gpio_set_value(chost->clk_gpio, 0);
306 + platform_set_drvdata(pdev, chost);
312 + gpio_free(chost->dat_gpio);
314 + gpio_free(chost->clk_gpio);
321 +static void __exit cbus_bus_remove(struct platform_device *pdev)
323 + struct cbus_host *chost = platform_get_drvdata(pdev);
325 + gpio_free(chost->sel_gpio);
326 + gpio_free(chost->dat_gpio);
327 + gpio_free(chost->clk_gpio);
333 +static struct platform_driver cbus_driver = {
334 + .remove = __exit_p(cbus_bus_remove),
340 +static int __init cbus_bus_init(void)
342 + return platform_driver_probe(&cbus_driver, cbus_bus_probe);
344 +subsys_initcall(cbus_bus_init);
346 +static void __exit cbus_bus_exit(void)
348 + platform_driver_unregister(&cbus_driver);
350 +module_exit(cbus_bus_exit);
352 +MODULE_DESCRIPTION("CBUS serial protocol");
353 +MODULE_LICENSE("GPL");
354 +MODULE_AUTHOR("Juha Yrjölä");
355 +MODULE_AUTHOR("David Weinehall");
356 +MODULE_AUTHOR("Mikko Ylinen");
357 +MODULE_AUTHOR("Felipe Balbi <felipe.balbi@nokia.com>");
359 Index: linux-2.6.38-rc6/drivers/cbus/cbus.h
360 ===================================================================
361 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
362 +++ linux-2.6.38-rc6/drivers/cbus/cbus.h 2011-02-24 12:04:51.456189134 +0100
365 + * drivers/cbus/cbus.h
367 + * Copyright (C) 2004, 2005 Nokia Corporation
369 + * Written by Juha Yrjölä <juha.yrjola@nokia.com> and
370 + * David Weinehall <david.weinehall@nokia.com>
372 + * This file is subject to the terms and conditions of the GNU General
373 + * Public License. See the file "COPYING" in the main directory of this
374 + * archive for more details.
376 + * This program is distributed in the hope that it will be useful,
377 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
378 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
379 + * GNU General Public License for more details.
381 + * You should have received a copy of the GNU General Public License
382 + * along with this program; if not, write to the Free Software
383 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
386 +#ifndef __DRIVERS_CBUS_CBUS_H
387 +#define __DRIVERS_CBUS_CBUS_H
389 +extern int cbus_read_reg(unsigned dev, unsigned reg);
390 +extern int cbus_write_reg(unsigned dev, unsigned reg, unsigned val);
392 +#endif /* __DRIVERS_CBUS_CBUS_H */
393 Index: linux-2.6.38-rc6/drivers/cbus/Kconfig
394 ===================================================================
395 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
396 +++ linux-2.6.38-rc6/drivers/cbus/Kconfig 2011-02-24 12:04:51.457189107 +0100
399 +# CBUS device configuration
405 + depends on ARCH_OMAP
406 + bool "CBUS support on OMAP"
408 + CBUS is a proprietary serial protocol by Nokia. It is mainly
409 + used for accessing Energy Management auxiliary chips.
411 + If you want CBUS support, you should say Y here.
415 + bool "Support for Tahvo"
417 + Tahvo is a mixed signal ASIC with some system features
419 + If you want Tahvo support, you should say Y here.
421 +config CBUS_TAHVO_USB
422 + depends on CBUS_TAHVO && USB
423 + tristate "Support for Tahvo USB transceiver"
425 + If you want Tahvo support for USB transceiver, say Y or M here.
427 +config CBUS_TAHVO_USB_HOST_BY_DEFAULT
428 + depends on CBUS_TAHVO_USB && USB_OTG
429 + boolean "Device in USB host mode by default"
431 + Say Y here, if you want the device to enter USB host mode
432 + by default on bootup.
436 + bool "Support for Retu"
438 + Retu is a mixed signal ASIC with some system features
440 + If you want Retu support, you should say Y here.
442 +config CBUS_RETU_POWERBUTTON
443 + depends on CBUS_RETU
444 + bool "Support for Retu power button"
446 + The power button on Nokia 770 is connected to the Retu ASIC.
448 + If you want support for the Retu power button, you should say Y here.
450 +config CBUS_RETU_RTC
451 + depends on CBUS_RETU && RTC_CLASS
452 + tristate "Support for Retu pseudo-RTC"
454 + Say Y here if you want support for the device that alleges to be an
455 + RTC in Retu. This will expose a sysfs interface for it.
457 +config CBUS_RETU_WDT
458 + depends on CBUS_RETU && SYSFS && WATCHDOG
459 + tristate "Support for Retu watchdog timer"
461 + Say Y here if you want support for the watchdog in Retu. This will
462 + expose a sysfs interface to grok it.
464 +config CBUS_RETU_HEADSET
465 + depends on CBUS_RETU && SYSFS
466 + tristate "Support for headset detection with Retu/Vilma"
468 + Say Y here if you want support detecting a headset that's connected
469 + to Retu/Vilma. Detection state and events are exposed through
473 Index: linux-2.6.38-rc6/drivers/cbus/Makefile
474 ===================================================================
475 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
476 +++ linux-2.6.38-rc6/drivers/cbus/Makefile 2011-02-24 12:04:51.458189081 +0100
479 +# Makefile for CBUS.
482 +obj-$(CONFIG_CBUS) += cbus.o
483 +obj-$(CONFIG_CBUS_TAHVO) += tahvo.o
484 +obj-$(CONFIG_CBUS_RETU) += retu.o
485 +obj-$(CONFIG_CBUS_TAHVO_USB) += tahvo-usb.o
487 +obj-$(CONFIG_CBUS_RETU_POWERBUTTON) += retu-pwrbutton.o
488 +obj-$(CONFIG_CBUS_RETU_RTC) += retu-rtc.o
489 +obj-$(CONFIG_CBUS_RETU_WDT) += retu-wdt.o
490 +obj-$(CONFIG_CBUS_RETU_HEADSET) += retu-headset.o
491 Index: linux-2.6.38-rc6/drivers/cbus/retu.c
492 ===================================================================
493 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
494 +++ linux-2.6.38-rc6/drivers/cbus/retu.c 2011-02-24 12:04:51.458189081 +0100
497 + * drivers/cbus/retu.c
499 + * Support functions for Retu ASIC
501 + * Copyright (C) 2004, 2005 Nokia Corporation
503 + * Written by Juha Yrjölä <juha.yrjola@nokia.com>,
504 + * David Weinehall <david.weinehall@nokia.com>, and
505 + * Mikko Ylinen <mikko.k.ylinen@nokia.com>
507 + * This file is subject to the terms and conditions of the GNU General
508 + * Public License. See the file "COPYING" in the main directory of this
509 + * archive for more details.
511 + * This program is distributed in the hope that it will be useful,
512 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
513 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
514 + * GNU General Public License for more details.
516 + * You should have received a copy of the GNU General Public License
517 + * along with this program; if not, write to the Free Software
518 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
521 +#include <linux/module.h>
522 +#include <linux/init.h>
524 +#include <linux/slab.h>
525 +#include <linux/kernel.h>
526 +#include <linux/errno.h>
527 +#include <linux/device.h>
528 +#include <linux/miscdevice.h>
529 +#include <linux/poll.h>
530 +#include <linux/fs.h>
531 +#include <linux/mutex.h>
532 +#include <linux/irq.h>
533 +#include <linux/interrupt.h>
534 +#include <linux/platform_device.h>
535 +#include <linux/gpio.h>
537 +#include <asm/uaccess.h>
538 +#include <asm/mach-types.h>
540 +#include <plat/mux.h>
541 +#include <plat/board.h>
542 +#include <plat/cbus.h>
549 + struct mutex mutex;
550 + struct device *dev;
568 +static struct retu *the_retu;
571 + * __retu_read_reg - Read a value from a register in Retu
572 + * @retu: pointer to retu structure
573 + * @reg: the register address to read from
575 +static int __retu_read_reg(struct retu *retu, unsigned reg)
577 + return cbus_read_reg(retu->devid, reg);
581 + * __retu_write_reg - Writes a value to a register in Retu
582 + * @retu: pointer to retu structure
583 + * @reg: the register address to write to
584 + * @val: the value to write to the register
586 +static void __retu_write_reg(struct retu *retu, unsigned reg, u16 val)
588 + cbus_write_reg(retu->devid, reg, val);
592 + * retu_read_reg - Read a value from a register in Retu
593 + * @child: device pointer for the calling child
594 + * @reg: the register to read from
596 + * This function returns the contents of the specified register
598 +int retu_read_reg(struct device *child, unsigned reg)
600 + struct retu *retu = dev_get_drvdata(child->parent);
602 + return __retu_read_reg(retu, reg);
604 +EXPORT_SYMBOL_GPL(retu_read_reg);
607 + * retu_write_reg - Write a value to a register in Retu
608 + * @child: the pointer to our calling child
609 + * @reg: the register to write to
610 + * @val: the value to write to the register
612 + * This function writes a value to the specified register
614 +void retu_write_reg(struct device *child, unsigned reg, u16 val)
616 + struct retu *retu = dev_get_drvdata(child->parent);
618 + __retu_write_reg(retu, reg, val);
620 +EXPORT_SYMBOL_GPL(retu_write_reg);
623 + * retu_set_clear_reg_bits - helper function to read/set/clear bits
624 + * @child: device pointer to calling child
625 + * @reg: the register address
626 + * @set: mask for setting bits
627 + * @clear: mask for clearing bits
629 +void retu_set_clear_reg_bits(struct device *child, unsigned reg, u16 set,
632 + struct retu *retu = dev_get_drvdata(child->parent);
635 + mutex_lock(&retu->mutex);
636 + w = __retu_read_reg(retu, reg);
639 + __retu_write_reg(retu, reg, w);
640 + mutex_unlock(&retu->mutex);
642 +EXPORT_SYMBOL_GPL(retu_set_clear_reg_bits);
644 +#define ADC_MAX_CHAN_NUMBER 13
647 + * retu_read_adc - Reads AD conversion result
648 + * @child: device pointer to calling child
649 + * @channel: the ADC channel to read from
651 +int retu_read_adc(struct device *child, int channel)
653 + struct retu *retu = dev_get_drvdata(child->parent);
659 + if (channel < 0 || channel > ADC_MAX_CHAN_NUMBER)
662 + mutex_lock(&retu->mutex);
664 + if ((channel == 8) && retu->is_vilma) {
665 + int scr = __retu_read_reg(retu, RETU_REG_ADCSCR);
666 + int ch = (__retu_read_reg(retu, RETU_REG_ADCR) >> 10) & 0xf;
667 + if (((scr & 0xff) != 0) && (ch != 8))
668 + __retu_write_reg(retu, RETU_REG_ADCSCR, (scr & ~0xff));
671 + /* Select the channel and read result */
672 + __retu_write_reg(retu, RETU_REG_ADCR, channel << 10);
673 + res = __retu_read_reg(retu, RETU_REG_ADCR) & 0x3ff;
675 + if (retu->is_vilma)
676 + __retu_write_reg(retu, RETU_REG_ADCR, (1 << 13));
679 + mutex_unlock(&retu->mutex);
683 +EXPORT_SYMBOL_GPL(retu_read_adc);
685 +static irqreturn_t retu_irq_handler(int irq, void *_retu)
687 + struct retu *retu = _retu;
694 + idr = __retu_read_reg(retu, RETU_REG_IDR);
695 + imr = __retu_read_reg(retu, RETU_REG_IMR);
699 + dev_vdbg(retu->dev, "No IRQ, spurious?\n");
703 + for (i = 0; idr != 0; i++, idr >>= 1) {
707 + handle_nested_irq(i);
710 + return IRQ_HANDLED;
713 +/* -------------------------------------------------------------------------- */
715 +static void retu_irq_mask(struct irq_data *data)
717 + struct retu *retu = irq_data_get_irq_chip_data(data);
718 + int irq = data->irq;
720 + retu->mask |= (1 << (irq - retu->irq_base));
721 + retu->mask_pending = true;
724 +static void retu_irq_unmask(struct irq_data *data)
726 + struct retu *retu = irq_data_get_irq_chip_data(data);
727 + int irq = data->irq;
729 + retu->mask &= ~(1 << (irq - retu->irq_base));
730 + retu->mask_pending = true;
734 +static void retu_irq_ack(struct irq_data *data)
736 + struct retu *retu = irq_data_get_irq_chip_data(data);
737 + int irq = data->irq;
739 + retu->ack |= (1 << (irq - retu->irq_base));
740 + retu->ack_pending = true;
743 +static void retu_bus_lock(struct irq_data *data)
745 + struct retu *retu = irq_data_get_irq_chip_data(data);
747 + mutex_lock(&retu->mutex);
750 +static void retu_bus_sync_unlock(struct irq_data *data)
752 + struct retu *retu = irq_data_get_irq_chip_data(data);
754 + if (retu->mask_pending) {
755 + __retu_write_reg(retu, RETU_REG_IMR, retu->mask);
756 + retu->mask_pending = false;
759 + if (retu->ack_pending) {
760 + __retu_write_reg(retu, RETU_REG_IDR, retu->ack);
761 + retu->ack_pending = false;
764 + mutex_unlock(&retu->mutex);
767 +static struct irq_chip retu_irq_chip = {
769 + .irq_bus_lock = retu_bus_lock,
770 + .irq_bus_sync_unlock = retu_bus_sync_unlock,
771 + .irq_mask = retu_irq_mask,
772 + .irq_unmask = retu_irq_unmask,
773 + .irq_ack = retu_irq_ack,
776 +static inline void retu_irq_setup(int irq)
779 + set_irq_flags(irq, IRQF_VALID);
781 + set_irq_noprobe(irq);
785 +static void retu_irq_init(struct retu *retu)
787 + int base = retu->irq_base;
788 + int end = retu->irq_end;
791 + for (irq = base; irq < end; irq++) {
792 + set_irq_chip_data(irq, retu);
793 + set_irq_chip_and_handler(irq, &retu_irq_chip,
794 + handle_simple_irq);
795 + set_irq_nested_thread(irq, 1);
796 + retu_irq_setup(irq);
800 +static void retu_irq_exit(struct retu *retu)
802 + int base = retu->irq_base;
803 + int end = retu->irq_end;
806 + for (irq = base; irq < end; irq++) {
808 + set_irq_flags(irq, 0);
810 + set_irq_chip_and_handler(irq, NULL, NULL);
811 + set_irq_chip_data(irq, NULL);
815 +/* -------------------------------------------------------------------------- */
818 + * retu_power_off - Shut down power to system
820 + * This function puts the system in power off state
822 +static void retu_power_off(void)
824 + struct retu *retu = the_retu;
827 + reg = __retu_read_reg(retu, RETU_REG_CC1);
829 + /* Ignore power button state */
830 + __retu_write_reg(retu, RETU_REG_CC1, reg | 2);
831 + /* Expire watchdog immediately */
832 + __retu_write_reg(retu, RETU_REG_WATCHDOG, 0);
833 + /* Wait for poweroff*/
837 +static struct resource generic_resources[] = {
839 + .start = -EINVAL, /* fixed later */
840 + .flags = IORESOURCE_IRQ,
843 + .start = -EINVAL, /* fixed later */
844 + .flags = IORESOURCE_IRQ,
849 + * retu_allocate_child - Allocates one Retu child
850 + * @name: name of new child
851 + * @parent: parent device for this child
853 +static struct device *retu_allocate_child(char *name, struct device *parent,
854 + int irq_base, int irq1, int irq2, int num)
856 + struct platform_device *pdev;
859 + pdev = platform_device_alloc(name, -1);
861 + dev_dbg(parent, "can't allocate %s\n", name);
865 + pdev->dev.parent = parent;
868 + generic_resources[0].start = irq_base + irq1;
869 + generic_resources[1].start = irq_base + irq2;
871 + status = platform_device_add_resources(pdev,
872 + generic_resources, num);
874 + dev_dbg(parent, "can't add resources to %s\n", name);
879 + status = platform_device_add(pdev);
881 + dev_dbg(parent, "can't add %s\n", name);
888 + platform_device_put(pdev);
894 + * retu_allocate_children - Allocates Retu's children
896 +static int retu_allocate_children(struct device *parent, int irq_base)
898 + struct device *child;
900 + child = retu_allocate_child("retu-pwrbutton", parent, irq_base,
901 + RETU_INT_PWR, -1, 1);
905 + child = retu_allocate_child("retu-headset", parent, irq_base,
906 + RETU_INT_HOOK, -1, 1);
910 + child = retu_allocate_child("retu-rtc", parent, irq_base,
911 + RETU_INT_RTCS, RETU_INT_RTCA, 2);
915 + child = retu_allocate_child("retu-wdt", parent, -1, -1, -1, 0);
923 + * retu_probe - Probe for Retu ASIC
924 + * @dev: the Retu device
926 + * Probe for the Retu ASIC and allocate memory
927 + * for its device-struct if found
929 +static int __init retu_probe(struct platform_device *pdev)
932 + struct cbus_retu_platform_data *pdata = pdev->dev.platform_data;
937 + retu = kzalloc(sizeof(*retu), GFP_KERNEL);
939 + dev_err(&pdev->dev, "not enough memory\n");
943 + platform_set_drvdata(pdev, retu);
945 + retu->irq = platform_get_irq(pdev, 0);
946 + retu->irq_base = pdata->irq_base;
947 + retu->irq_end = pdata->irq_end;
948 + retu->devid = pdata->devid;
951 + mutex_init(&retu->mutex);
953 + retu_irq_init(retu);
955 + rev = __retu_read_reg(retu, RETU_REG_ASICR) & 0xff;
956 + if (rev & (1 << 7))
957 + retu->is_vilma = true;
959 + dev_info(&pdev->dev, "%s v%d.%d found\n",
960 + retu->is_vilma ? "Vilma" : "Retu",
961 + (rev >> 4) & 0x07, rev & 0x0f);
963 + /* Mask all RETU interrupts */
964 + __retu_write_reg(retu, RETU_REG_IMR, 0xffff);
966 + ret = request_threaded_irq(retu->irq, NULL, retu_irq_handler, 0,
969 + dev_err(&pdev->dev, "Unable to register IRQ handler\n");
973 + set_irq_wake(retu->irq, 1);
975 + /* Register power off function */
976 + pm_power_off = retu_power_off;
978 + ret = retu_allocate_children(&pdev->dev, retu->irq_base);
980 + dev_err(&pdev->dev, "Unable to allocate Retu children\n");
987 + pm_power_off = NULL;
988 + __retu_write_reg(retu, RETU_REG_IMR, 0xffff);
989 + free_irq(retu->irq, retu);
999 +static int __exit retu_remove(struct platform_device *pdev)
1001 + struct retu *retu = platform_get_drvdata(pdev);
1003 + pm_power_off = NULL;
1006 + /* Mask all RETU interrupts */
1007 + __retu_write_reg(retu, RETU_REG_IMR, 0xffff);
1009 + free_irq(retu->irq, retu);
1010 + retu_irq_exit(retu);
1016 +static struct platform_driver retu_driver = {
1017 + .remove = __exit_p(retu_remove),
1023 +static int __init retu_init(void)
1025 + return platform_driver_probe(&retu_driver, retu_probe);
1027 +subsys_initcall(retu_init);
1029 +static void __exit retu_exit(void)
1031 + platform_driver_unregister(&retu_driver);
1033 +module_exit(retu_exit);
1035 +MODULE_DESCRIPTION("Retu ASIC control");
1036 +MODULE_LICENSE("GPL");
1037 +MODULE_AUTHOR("Juha Yrjölä");
1038 +MODULE_AUTHOR("David Weinehall");
1039 +MODULE_AUTHOR("Mikko Ylinen");
1040 Index: linux-2.6.38-rc6/drivers/cbus/retu.h
1041 ===================================================================
1042 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1043 +++ linux-2.6.38-rc6/drivers/cbus/retu.h 2011-02-24 12:04:51.459189067 +0100
1046 + * drivers/cbus/retu.h
1048 + * Copyright (C) 2004, 2005 Nokia Corporation
1050 + * Written by Juha Yrjölä <juha.yrjola@nokia.com> and
1051 + * David Weinehall <david.weinehall@nokia.com>
1053 + * This file is subject to the terms and conditions of the GNU General
1054 + * Public License. See the file "COPYING" in the main directory of this
1055 + * archive for more details.
1057 + * This program is distributed in the hope that it will be useful,
1058 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1059 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1060 + * GNU General Public License for more details.
1062 + * You should have received a copy of the GNU General Public License
1063 + * along with this program; if not, write to the Free Software
1064 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1067 +#ifndef __DRIVERS_CBUS_RETU_H
1068 +#define __DRIVERS_CBUS_RETU_H
1070 +#include <linux/types.h>
1073 +#define RETU_REG_ASICR 0x00 /* ASIC ID & revision */
1074 +#define RETU_REG_IDR 0x01 /* Interrupt ID */
1075 +#define RETU_REG_IMR 0x02 /* Interrupt mask */
1076 +#define RETU_REG_RTCDSR 0x03 /* RTC seconds register */
1077 +#define RETU_REG_RTCHMR 0x04 /* RTC hours and minutes register */
1078 +#define RETU_REG_RTCHMAR 0x05 /* RTC hours and minutes alarm and time set register */
1079 +#define RETU_REG_RTCCALR 0x06 /* RTC calibration register */
1080 +#define RETU_REG_ADCR 0x08 /* ADC result */
1081 +#define RETU_REG_ADCSCR 0x09 /* ADC sample ctrl */
1082 +#define RETU_REG_CC1 0x0d /* Common control register 1 */
1083 +#define RETU_REG_CC2 0x0e /* Common control register 2 */
1084 +#define RETU_REG_CTRL_CLR 0x0f /* Regulator clear register */
1085 +#define RETU_REG_CTRL_SET 0x10 /* Regulator set register */
1086 +#define RETU_REG_STATUS 0x16 /* Status register */
1087 +#define RETU_REG_WATCHDOG 0x17 /* Watchdog register */
1088 +#define RETU_REG_AUDTXR 0x18 /* Audio Codec Tx register */
1089 +#define RETU_REG_MAX 0x1f
1091 +/* Interrupt sources */
1092 +#define RETU_INT_PWR 0
1093 +#define RETU_INT_CHAR 1
1094 +#define RETU_INT_RTCS 2
1095 +#define RETU_INT_RTCM 3
1096 +#define RETU_INT_RTCD 4
1097 +#define RETU_INT_RTCA 5
1098 +#define RETU_INT_HOOK 6
1099 +#define RETU_INT_HEAD 7
1100 +#define RETU_INT_ADCS 8
1102 +#define MAX_RETU_IRQ_HANDLERS 16
1104 +int retu_read_reg(struct device *child, unsigned reg);
1105 +void retu_write_reg(struct device *child, unsigned reg, u16 val);
1106 +void retu_set_clear_reg_bits(struct device *child, unsigned reg, u16 set,
1108 +int retu_read_adc(struct device *child, int channel);
1110 +#endif /* __DRIVERS_CBUS_RETU_H */
1111 Index: linux-2.6.38-rc6/drivers/cbus/retu-headset.c
1112 ===================================================================
1113 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1114 +++ linux-2.6.38-rc6/drivers/cbus/retu-headset.c 2011-02-24 12:04:51.460189032 +0100
1117 + * Retu/Vilma headset detection
1119 + * Copyright (C) 2006 Nokia Corporation
1121 + * Written by Juha Yrjölä
1123 + * This file is subject to the terms and conditions of the GNU General
1124 + * Public License. See the file "COPYING" in the main directory of this
1125 + * archive for more details.
1127 + * This program is distributed in the hope that it will be useful,
1128 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1129 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1130 + * GNU General Public License for more details.
1132 + * You should have received a copy of the GNU General Public License
1133 + * along with this program; if not, write to the Free Software
1134 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1137 +#include <linux/module.h>
1138 +#include <linux/init.h>
1139 +#include <linux/kernel.h>
1140 +#include <linux/irq.h>
1141 +#include <linux/interrupt.h>
1142 +#include <linux/slab.h>
1143 +#include <linux/delay.h>
1144 +#include <linux/input.h>
1145 +#include <linux/platform_device.h>
1149 +#define RETU_ADC_CHANNEL_HOOKDET 0x05
1151 +#define RETU_HEADSET_KEY KEY_PHONE
1153 +struct retu_headset {
1155 + struct mutex mutex;
1156 + struct device *dev;
1157 + struct input_dev *idev;
1158 + unsigned bias_enabled;
1159 + unsigned detection_enabled;
1161 + struct timer_list enable_timer;
1162 + struct timer_list detect_timer;
1166 +static void retu_headset_set_bias(struct retu_headset *hs, int enable)
1169 + retu_set_clear_reg_bits(hs->dev, RETU_REG_AUDTXR,
1170 + (1 << 0) | (1 << 1), 0);
1172 + retu_set_clear_reg_bits(hs->dev, RETU_REG_AUDTXR,
1175 + retu_set_clear_reg_bits(hs->dev, RETU_REG_AUDTXR, 0,
1176 + (1 << 0) | (1 << 1) | (1 << 3));
1180 +static void retu_headset_enable(struct retu_headset *hs)
1182 + mutex_lock(&hs->mutex);
1183 + if (!hs->bias_enabled) {
1184 + hs->bias_enabled = 1;
1185 + retu_headset_set_bias(hs, 1);
1187 + mutex_unlock(&hs->mutex);
1190 +static void retu_headset_disable(struct retu_headset *hs)
1192 + mutex_lock(&hs->mutex);
1193 + if (hs->bias_enabled) {
1194 + hs->bias_enabled = 0;
1195 + retu_headset_set_bias(hs, 0);
1197 + mutex_unlock(&hs->mutex);
1200 +static void retu_headset_det_enable(struct retu_headset *hs)
1202 + mutex_lock(&hs->mutex);
1203 + if (!hs->detection_enabled) {
1204 + hs->detection_enabled = 1;
1205 + retu_set_clear_reg_bits(hs->dev, RETU_REG_CC1,
1206 + (1 << 10) | (1 << 8), 0);
1208 + mutex_unlock(&hs->mutex);
1211 +static void retu_headset_det_disable(struct retu_headset *hs)
1213 + unsigned long flags;
1215 + mutex_lock(&hs->mutex);
1216 + if (hs->detection_enabled) {
1217 + hs->detection_enabled = 0;
1218 + del_timer_sync(&hs->enable_timer);
1219 + del_timer_sync(&hs->detect_timer);
1220 + spin_lock_irqsave(&hs->lock, flags);
1222 + input_report_key(hs->idev, RETU_HEADSET_KEY, 0);
1223 + spin_unlock_irqrestore(&hs->lock, flags);
1224 + retu_set_clear_reg_bits(hs->dev, RETU_REG_CC1, 0,
1225 + (1 << 10) | (1 << 8));
1227 + mutex_unlock(&hs->mutex);
1230 +static ssize_t retu_headset_hookdet_show(struct device *dev,
1231 + struct device_attribute *attr,
1236 + val = retu_read_adc(dev, RETU_ADC_CHANNEL_HOOKDET);
1237 + return sprintf(buf, "%d\n", val);
1240 +static DEVICE_ATTR(hookdet, S_IRUGO, retu_headset_hookdet_show, NULL);
1242 +static ssize_t retu_headset_enable_show(struct device *dev,
1243 + struct device_attribute *attr,
1246 + struct retu_headset *hs = dev_get_drvdata(dev);
1248 + return sprintf(buf, "%u\n", hs->bias_enabled);
1251 +static ssize_t retu_headset_enable_store(struct device *dev,
1252 + struct device_attribute *attr,
1253 + const char *buf, size_t count)
1255 + struct retu_headset *hs = dev_get_drvdata(dev);
1258 + if (sscanf(buf, "%u", &enable) != 1)
1261 + retu_headset_enable(hs);
1263 + retu_headset_disable(hs);
1267 +static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR | S_IWGRP,
1268 + retu_headset_enable_show, retu_headset_enable_store);
1270 +static ssize_t retu_headset_enable_det_show(struct device *dev,
1271 + struct device_attribute *attr,
1274 + struct retu_headset *hs = dev_get_drvdata(dev);
1276 + return sprintf(buf, "%u\n", hs->detection_enabled);
1279 +static ssize_t retu_headset_enable_det_store(struct device *dev,
1280 + struct device_attribute *attr,
1281 + const char *buf, size_t count)
1283 + struct retu_headset *hs = dev_get_drvdata(dev);
1286 + if (sscanf(buf, "%u", &enable) != 1)
1289 + retu_headset_det_enable(hs);
1291 + retu_headset_det_disable(hs);
1295 +static DEVICE_ATTR(enable_det, S_IRUGO | S_IWUSR | S_IWGRP,
1296 + retu_headset_enable_det_show,
1297 + retu_headset_enable_det_store);
1299 +static irqreturn_t retu_headset_hook_interrupt(int irq, void *_hs)
1301 + struct retu_headset *hs = _hs;
1302 + unsigned long flags;
1304 + spin_lock_irqsave(&hs->lock, flags);
1305 + if (!hs->pressed) {
1306 + /* Headset button was just pressed down. */
1308 + input_report_key(hs->idev, RETU_HEADSET_KEY, 1);
1310 + spin_unlock_irqrestore(&hs->lock, flags);
1311 + retu_set_clear_reg_bits(hs->dev, RETU_REG_CC1, 0,
1312 + (1 << 10) | (1 << 8));
1313 + mod_timer(&hs->enable_timer, jiffies + msecs_to_jiffies(50));
1315 + return IRQ_HANDLED;
1318 +static void retu_headset_enable_timer(unsigned long arg)
1320 + struct retu_headset *hs = (struct retu_headset *) arg;
1322 + retu_set_clear_reg_bits(hs->dev, RETU_REG_CC1,
1323 + (1 << 10) | (1 << 8), 0);
1324 + mod_timer(&hs->detect_timer, jiffies + msecs_to_jiffies(350));
1327 +static void retu_headset_detect_timer(unsigned long arg)
1329 + struct retu_headset *hs = (struct retu_headset *) arg;
1330 + unsigned long flags;
1332 + spin_lock_irqsave(&hs->lock, flags);
1333 + if (hs->pressed) {
1335 + input_report_key(hs->idev, RETU_HEADSET_KEY, 0);
1337 + spin_unlock_irqrestore(&hs->lock, flags);
1340 +static int __init retu_headset_probe(struct platform_device *pdev)
1342 + struct retu_headset *hs;
1346 + hs = kzalloc(sizeof(*hs), GFP_KERNEL);
1350 + hs->dev = &pdev->dev;
1352 + hs->idev = input_allocate_device();
1353 + if (hs->idev == NULL) {
1357 + hs->idev->name = "retu-headset";
1358 + hs->idev->dev.parent = &pdev->dev;
1359 + set_bit(EV_KEY, hs->idev->evbit);
1360 + set_bit(RETU_HEADSET_KEY, hs->idev->keybit);
1361 + r = input_register_device(hs->idev);
1365 + r = device_create_file(&pdev->dev, &dev_attr_hookdet);
1368 + r = device_create_file(&pdev->dev, &dev_attr_enable);
1371 + r = device_create_file(&pdev->dev, &dev_attr_enable_det);
1374 + platform_set_drvdata(pdev, hs);
1376 + spin_lock_init(&hs->lock);
1377 + mutex_init(&hs->mutex);
1378 + setup_timer(&hs->enable_timer, retu_headset_enable_timer,
1379 + (unsigned long) hs);
1380 + setup_timer(&hs->detect_timer, retu_headset_detect_timer,
1381 + (unsigned long) hs);
1383 + irq = platform_get_irq(pdev, 0);
1386 + r = request_threaded_irq(irq, NULL, retu_headset_hook_interrupt, 0,
1389 + dev_err(&pdev->dev, "hookdet IRQ not available\n");
1395 + device_remove_file(&pdev->dev, &dev_attr_enable_det);
1397 + device_remove_file(&pdev->dev, &dev_attr_enable);
1399 + device_remove_file(&pdev->dev, &dev_attr_hookdet);
1401 + input_unregister_device(hs->idev);
1403 + input_free_device(hs->idev);
1409 +static int retu_headset_remove(struct platform_device *pdev)
1411 + struct retu_headset *hs = platform_get_drvdata(pdev);
1413 + device_remove_file(&pdev->dev, &dev_attr_hookdet);
1414 + device_remove_file(&pdev->dev, &dev_attr_enable);
1415 + device_remove_file(&pdev->dev, &dev_attr_enable_det);
1416 + retu_headset_disable(hs);
1417 + retu_headset_det_disable(hs);
1418 + free_irq(hs->irq, hs);
1419 + input_unregister_device(hs->idev);
1420 + input_free_device(hs->idev);
1425 +static int retu_headset_suspend(struct platform_device *pdev,
1426 + pm_message_t mesg)
1428 + struct retu_headset *hs = platform_get_drvdata(pdev);
1430 + mutex_lock(&hs->mutex);
1431 + if (hs->bias_enabled)
1432 + retu_headset_set_bias(hs, 0);
1433 + mutex_unlock(&hs->mutex);
1438 +static int retu_headset_resume(struct platform_device *pdev)
1440 + struct retu_headset *hs = platform_get_drvdata(pdev);
1442 + mutex_lock(&hs->mutex);
1443 + if (hs->bias_enabled)
1444 + retu_headset_set_bias(hs, 1);
1445 + mutex_unlock(&hs->mutex);
1450 +static struct platform_driver retu_headset_driver = {
1451 + .remove = retu_headset_remove,
1452 + .suspend = retu_headset_suspend,
1453 + .resume = retu_headset_resume,
1455 + .name = "retu-headset",
1459 +static int __init retu_headset_init(void)
1461 + return platform_driver_probe(&retu_headset_driver, retu_headset_probe);
1464 +static void __exit retu_headset_exit(void)
1466 + platform_driver_unregister(&retu_headset_driver);
1469 +module_init(retu_headset_init);
1470 +module_exit(retu_headset_exit);
1472 +MODULE_DESCRIPTION("Retu/Vilma headset detection");
1473 +MODULE_LICENSE("GPL");
1474 +MODULE_AUTHOR("Juha Yrjölä");
1475 Index: linux-2.6.38-rc6/drivers/cbus/retu-pwrbutton.c
1476 ===================================================================
1477 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1478 +++ linux-2.6.38-rc6/drivers/cbus/retu-pwrbutton.c 2011-02-24 12:04:51.460189032 +0100
1481 + * drivers/cbus/retu-pwrbutton.c
1483 + * Driver for sending retu power button event to input-layer
1485 + * Copyright (C) 2004-2010 Nokia Corporation
1488 + * Ari Saastamoinen <ari.saastamoinen@elektrobit.com>
1489 + * Juha Yrjola <juha.yrjola@solidboot.com>
1491 + * Contact: Felipe Balbi <felipe.balbi@nokia.com>
1493 + * This file is subject to the terms and conditions of the GNU General
1494 + * Public License. See the file "COPYING" in the main directory of this
1495 + * archive for more details.
1497 + * This program is distributed in the hope that it will be useful,
1498 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1499 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1500 + * GNU General Public License for more details.
1502 + * You should have received a copy of the GNU General Public License
1503 + * along with this program; if not, write to the Free Software
1504 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1507 +#include <linux/module.h>
1508 +#include <linux/init.h>
1509 +#include <linux/kernel.h>
1510 +#include <linux/errno.h>
1511 +#include <linux/input.h>
1512 +#include <linux/jiffies.h>
1513 +#include <linux/bitops.h>
1514 +#include <linux/irq.h>
1515 +#include <linux/interrupt.h>
1516 +#include <linux/platform_device.h>
1517 +#include <linux/slab.h>
1521 +#define RETU_STATUS_PWRONX (1 << 5)
1523 +#define PWRBTN_DELAY 20
1524 +#define PWRBTN_UP 0
1525 +#define PWRBTN_PRESSED 1
1527 +struct retu_pwrbutton {
1528 + struct input_dev *idev;
1529 + struct device *dev;
1535 +static irqreturn_t retubutton_irq(int irq, void *_pwr)
1537 + struct retu_pwrbutton *pwr = _pwr;
1540 + if (retu_read_reg(pwr->dev, RETU_REG_STATUS) & RETU_STATUS_PWRONX)
1541 + state = PWRBTN_UP;
1543 + state = PWRBTN_PRESSED;
1545 + if (pwr->state != state) {
1546 + input_report_key(pwr->idev, KEY_POWER, state);
1547 + input_sync(pwr->idev);
1548 + pwr->state = state;
1551 + return IRQ_HANDLED;
1554 +static int __init retubutton_probe(struct platform_device *pdev)
1556 + struct retu_pwrbutton *pwr;
1559 + pwr = kzalloc(sizeof(*pwr), GFP_KERNEL);
1561 + dev_err(&pdev->dev, "not enough memory\n");
1566 + pwr->dev = &pdev->dev;
1567 + pwr->irq = platform_get_irq(pdev, 0);
1568 + platform_set_drvdata(pdev, pwr);
1570 + ret = request_threaded_irq(pwr->irq, NULL, retubutton_irq, 0,
1571 + "retu-pwrbutton", pwr);
1573 + dev_err(&pdev->dev, "Cannot allocate irq\n");
1577 + pwr->idev = input_allocate_device();
1579 + dev_err(&pdev->dev, "can't allocate input device\n");
1584 + pwr->idev->evbit[0] = BIT_MASK(EV_KEY);
1585 + pwr->idev->keybit[BIT_WORD(KEY_POWER)] = BIT_MASK(KEY_POWER);
1586 + pwr->idev->name = "retu-pwrbutton";
1588 + ret = input_register_device(pwr->idev);
1590 + dev_err(&pdev->dev, "failed to register input device\n");
1597 + input_free_device(pwr->idev);
1600 + free_irq(pwr->irq, pwr);
1609 +static int __exit retubutton_remove(struct platform_device *pdev)
1611 + struct retu_pwrbutton *pwr = platform_get_drvdata(pdev);
1613 + free_irq(pwr->irq, pwr);
1614 + input_unregister_device(pwr->idev);
1615 + input_free_device(pwr->idev);
1621 +static struct platform_driver retu_pwrbutton_driver = {
1622 + .remove = __exit_p(retubutton_remove),
1624 + .name = "retu-pwrbutton",
1628 +static int __init retubutton_init(void)
1630 + return platform_driver_probe(&retu_pwrbutton_driver, retubutton_probe);
1632 +module_init(retubutton_init);
1634 +static void __exit retubutton_exit(void)
1636 + platform_driver_unregister(&retu_pwrbutton_driver);
1638 +module_exit(retubutton_exit);
1640 +MODULE_DESCRIPTION("Retu Power Button");
1641 +MODULE_LICENSE("GPL");
1642 +MODULE_AUTHOR("Ari Saastamoinen");
1643 +MODULE_AUTHOR("Felipe Balbi <felipe.balbi@nokia.com>");
1645 Index: linux-2.6.38-rc6/drivers/cbus/retu-rtc.c
1646 ===================================================================
1647 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1648 +++ linux-2.6.38-rc6/drivers/cbus/retu-rtc.c 2011-02-24 12:04:51.461188993 +0100
1651 + * drivers/cbus/retu-rtc.c
1653 + * Support for Retu RTC
1655 + * Copyright (C) 2004, 2005 Nokia Corporation
1657 + * Written by Paul Mundt <paul.mundt@nokia.com> and
1658 + * Igor Stoppa <igor.stoppa@nokia.com>
1660 + * The Retu RTC is essentially a partial read-only RTC that gives us Retu's
1661 + * idea of what time actually is. It's left as a userspace excercise to map
1662 + * this back to time in the real world and ensure that calibration settings
1663 + * are sane to compensate for any horrible drift (on account of not being able
1664 + * to set the clock to anything).
1666 + * Days are semi-writeable. Namely, Retu will only track 255 days for us
1667 + * consecutively, after which the counter is explicitly stuck at 255 until
1668 + * someone comes along and clears it with a write. In the event that no one
1669 + * comes along and clears it, we no longer have any idea what day it is.
1671 + * This file is subject to the terms and conditions of the GNU General
1672 + * Public License. See the file "COPYING" in the main directory of this
1673 + * archive for more details.
1675 + * This program is distributed in the hope that it will be useful,
1676 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1677 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1678 + * GNU General Public License for more details.
1680 + * You should have received a copy of the GNU General Public License
1681 + * along with this program; if not, write to the Free Software
1682 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1685 +#include <linux/device.h>
1686 +#include <linux/init.h>
1687 +#include <linux/kernel.h>
1688 +#include <linux/slab.h>
1689 +#include <linux/module.h>
1690 +#include <linux/platform_device.h>
1691 +#include <linux/mutex.h>
1692 +#include <linux/rtc.h>
1699 + struct mutex mutex;
1700 + struct device *dev;
1701 + struct rtc_device *rtc;
1703 + u16 alarm_expired;
1708 +static void retu_rtc_do_reset(struct retu_rtc *rtc)
1712 + ccr1 = retu_read_reg(rtc->dev, RETU_REG_CC1);
1713 + /* RTC in reset */
1714 + retu_write_reg(rtc->dev, RETU_REG_CC1, ccr1 | 0x0001);
1715 + /* RTC in normal operating mode */
1716 + retu_write_reg(rtc->dev, RETU_REG_CC1, ccr1 & ~0x0001);
1718 + /* Disable alarm and RTC WD */
1719 + retu_write_reg(rtc->dev, RETU_REG_RTCHMAR, 0x7f3f);
1720 + /* Set Calibration register to default value */
1721 + retu_write_reg(rtc->dev, RETU_REG_RTCCALR, 0x00c0);
1723 + rtc->alarm_expired = 0;
1726 +static irqreturn_t retu_rtc_interrupt(int irq, void *_rtc)
1728 + struct retu_rtc *rtc = _rtc;
1730 + mutex_lock(&rtc->mutex);
1731 + rtc->alarm_expired = 1;
1732 + retu_write_reg(rtc->dev, RETU_REG_RTCHMAR, (24 << 8) | 60);
1733 + mutex_unlock(&rtc->mutex);
1735 + return IRQ_HANDLED;
1738 +static int retu_rtc_init_irq(struct retu_rtc *rtc)
1743 + irq = platform_get_irq(to_platform_device(rtc->dev), 0);
1744 + rtc->irq_rtcs = irq;
1746 + irq = platform_get_irq(to_platform_device(rtc->dev), 1);
1747 + rtc->irq_rtca = irq;
1749 + ret = request_threaded_irq(rtc->irq_rtcs, NULL, retu_rtc_interrupt,
1754 + ret = request_threaded_irq(rtc->irq_rtca, NULL, retu_rtc_interrupt,
1757 + free_irq(rtc->irq_rtcs, rtc);
1764 +static int retu_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
1766 + struct retu_rtc *rtc = dev_get_drvdata(dev);
1769 + mutex_lock(&rtc->mutex);
1771 + chmar = ((alm->time.tm_hour & 0x1f) << 8) | (alm->time.tm_min & 0x3f);
1772 + retu_write_reg(rtc->dev, RETU_REG_RTCHMAR, chmar);
1774 + mutex_unlock(&rtc->mutex);
1779 +static int retu_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
1781 + struct retu_rtc *rtc = dev_get_drvdata(dev);
1784 + mutex_lock(&rtc->mutex);
1786 + chmar = retu_read_reg(rtc->dev, RETU_REG_RTCHMAR);
1788 + alm->time.tm_hour = (chmar >> 8) & 0x1f;
1789 + alm->time.tm_min = chmar & 0x3f;
1790 + alm->enabled = !!rtc->alarm_expired;
1792 + mutex_unlock(&rtc->mutex);
1797 +static int retu_rtc_set_time(struct device *dev, struct rtc_time *tm)
1799 + struct retu_rtc *rtc = dev_get_drvdata(dev);
1803 + dsr = ((tm->tm_mday & 0xff) << 8) | (tm->tm_hour & 0xff);
1804 + hmr = ((tm->tm_min & 0xff) << 8) | (tm->tm_sec & 0xff);
1806 + mutex_lock(&rtc->mutex);
1808 + retu_write_reg(rtc->dev, RETU_REG_RTCDSR, dsr);
1809 + retu_write_reg(rtc->dev, RETU_REG_RTCHMR, hmr);
1811 + mutex_unlock(&rtc->mutex);
1816 +static int retu_rtc_read_time(struct device *dev, struct rtc_time *tm)
1818 + struct retu_rtc *rtc = dev_get_drvdata(dev);
1823 + * DSR holds days and hours
1824 + * HMR hols minutes and seconds
1826 + * both are 16 bit registers with 8-bit for each field.
1829 + mutex_lock(&rtc->mutex);
1831 + dsr = retu_read_reg(rtc->dev, RETU_REG_RTCDSR);
1832 + hmr = retu_read_reg(rtc->dev, RETU_REG_RTCHMR);
1834 + tm->tm_sec = hmr & 0xff;
1835 + tm->tm_min = hmr >> 8;
1836 + tm->tm_hour = dsr & 0xff;
1837 + tm->tm_mday = dsr >> 8;
1839 + mutex_unlock(&rtc->mutex);
1844 +static struct rtc_class_ops retu_rtc_ops = {
1845 + .read_time = retu_rtc_read_time,
1846 + .set_time = retu_rtc_set_time,
1847 + .read_alarm = retu_rtc_read_alarm,
1848 + .set_alarm = retu_rtc_set_alarm,
1851 +static int __init retu_rtc_probe(struct platform_device *pdev)
1853 + struct retu_rtc *rtc;
1856 + rtc = kzalloc(sizeof(*rtc), GFP_KERNEL);
1858 + dev_err(&pdev->dev, "not enough memory\n");
1863 + rtc->dev = &pdev->dev;
1864 + platform_set_drvdata(pdev, rtc);
1865 + mutex_init(&rtc->mutex);
1867 + rtc->alarm_expired = retu_read_reg(rtc->dev, RETU_REG_IDR) &
1868 + (0x1 << RETU_INT_RTCA);
1870 + r = retu_rtc_init_irq(rtc);
1872 + dev_err(&pdev->dev, "failed to request retu irq\n");
1876 + /* If the calibration register is zero, we've probably lost power */
1877 + if (!(retu_read_reg(rtc->dev, RETU_REG_RTCCALR) & 0x00ff))
1878 + retu_rtc_do_reset(rtc);
1880 + rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, &
1881 + retu_rtc_ops, THIS_MODULE);
1882 + if (IS_ERR(rtc->rtc)) {
1883 + dev_err(&pdev->dev, "can't register RTC device\n");
1890 + free_irq(rtc->irq_rtcs, rtc);
1891 + free_irq(rtc->irq_rtca, rtc);
1900 +static int __devexit retu_rtc_remove(struct platform_device *pdev)
1902 + struct retu_rtc *rtc = platform_get_drvdata(pdev);
1904 + free_irq(rtc->irq_rtcs, rtc);
1905 + free_irq(rtc->irq_rtca, rtc);
1906 + rtc_device_unregister(rtc->rtc);
1912 +static struct platform_driver retu_rtc_driver = {
1913 + .remove = __exit_p(retu_rtc_remove),
1915 + .name = "retu-rtc",
1919 +static int __init retu_rtc_init(void)
1921 + return platform_driver_probe(&retu_rtc_driver, retu_rtc_probe);
1923 +module_init(retu_rtc_init);
1925 +static void __exit retu_rtc_exit(void)
1927 + platform_driver_unregister(&retu_rtc_driver);
1929 +module_exit(retu_rtc_exit);
1931 +MODULE_DESCRIPTION("Retu RTC");
1932 +MODULE_LICENSE("GPL");
1933 +MODULE_AUTHOR("Paul Mundt");
1934 +MODULE_AUTHOR("Igor Stoppa");
1935 +MODULE_AUTHOR("Felipe Balbi <felipe.balbi@nokia.com>");
1937 Index: linux-2.6.38-rc6/drivers/cbus/retu-wdt.c
1938 ===================================================================
1939 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1940 +++ linux-2.6.38-rc6/drivers/cbus/retu-wdt.c 2011-02-24 12:04:51.461188993 +0100
1943 + * drivers/cbus/retu-wdt.c
1945 + * Driver for Retu watchdog
1947 + * Copyright (C) 2004, 2005 Nokia Corporation
1949 + * Written by Amit Kucheria <amit.kucheria@nokia.com>
1951 + * This file is subject to the terms and conditions of the GNU General
1952 + * Public License. See the file "COPYING" in the main directory of this
1953 + * archive for more details.
1955 + * This program is distributed in the hope that it will be useful,
1956 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1957 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1958 + * GNU General Public License for more details.
1960 + * You should have received a copy of the GNU General Public License
1961 + * along with this program; if not, write to the Free Software
1962 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1965 +#include <linux/kernel.h>
1966 +#include <linux/slab.h>
1967 +#include <linux/module.h>
1968 +#include <linux/device.h>
1969 +#include <linux/init.h>
1970 +#include <linux/fs.h>
1971 +#include <linux/io.h>
1972 +#include <linux/platform_device.h>
1974 +#include <linux/completion.h>
1975 +#include <linux/errno.h>
1976 +#include <linux/moduleparam.h>
1977 +#include <linux/miscdevice.h>
1978 +#include <linux/watchdog.h>
1980 +#include <asm/uaccess.h>
1982 +#include <plat/prcm.h>
1987 +/* Watchdog timeout in seconds */
1988 +#define RETU_WDT_MIN_TIMER 0
1989 +#define RETU_WDT_DEFAULT_TIMER 32
1990 +#define RETU_WDT_MAX_TIMER 63
1992 +static DEFINE_MUTEX(retu_wdt_mutex);
1994 +/* Current period of watchdog */
1995 +static unsigned int period_val = RETU_WDT_DEFAULT_TIMER;
1996 +static int counter_param = RETU_WDT_MAX_TIMER;
1998 +struct retu_wdt_dev {
1999 + struct device *dev;
2001 + struct miscdevice retu_wdt_miscdev;
2002 + struct timer_list ping_timer;
2005 +static struct retu_wdt_dev *retu_wdt;
2007 +static void retu_wdt_set_ping_timer(unsigned long enable);
2009 +static int _retu_modify_counter(unsigned int new)
2012 + retu_write_reg(retu_wdt->dev, RETU_REG_WATCHDOG, (u16)new);
2017 +static int retu_modify_counter(unsigned int new)
2019 + if (new < RETU_WDT_MIN_TIMER || new > RETU_WDT_MAX_TIMER)
2022 + mutex_lock(&retu_wdt_mutex);
2024 + _retu_modify_counter(period_val);
2025 + mutex_unlock(&retu_wdt_mutex);
2030 +static ssize_t retu_wdt_period_show(struct device *dev,
2031 + struct device_attribute *attr, char *buf)
2033 + /* Show current max counter */
2034 + return sprintf(buf, "%u\n", (u16)period_val);
2038 + * Note: This inteface is non-standard and likely to disappear!
2039 + * Use /dev/watchdog instead, that's the standard.
2041 +static ssize_t retu_wdt_period_store(struct device *dev,
2042 + struct device_attribute *attr,
2043 + const char *buf, size_t count)
2045 + unsigned int new_period;
2048 +#ifdef CONFIG_WATCHDOG_NOWAYOUT
2049 + retu_wdt_set_ping_timer(0);
2052 + if (sscanf(buf, "%u", &new_period) != 1) {
2053 + printk(KERN_ALERT "retu_wdt_period_store: Invalid input\n");
2057 + ret = retu_modify_counter(new_period);
2061 + return strnlen(buf, count);
2064 +static ssize_t retu_wdt_counter_show(struct device *dev,
2065 + struct device_attribute *attr, char *buf)
2069 + /* Show current value in watchdog counter */
2070 + counter = retu_read_reg(dev, RETU_REG_WATCHDOG);
2072 + /* Only the 5 LSB are important */
2073 + return snprintf(buf, PAGE_SIZE, "%u\n", (counter & 0x3F));
2076 +static DEVICE_ATTR(period, S_IRUGO | S_IWUSR, retu_wdt_period_show, \
2077 + retu_wdt_period_store);
2078 +static DEVICE_ATTR(counter, S_IRUGO, retu_wdt_counter_show, NULL);
2080 +/*----------------------------------------------------------------------------*/
2083 + * Since retu watchdog cannot be disabled in hardware, we must kick it
2084 + * with a timer until userspace watchdog software takes over. Do this
2085 + * unless /dev/watchdog is open or CONFIG_WATCHDOG_NOWAYOUT is set.
2087 +static void retu_wdt_set_ping_timer(unsigned long enable)
2089 + _retu_modify_counter(RETU_WDT_MAX_TIMER);
2091 + mod_timer(&retu_wdt->ping_timer,
2092 + jiffies + RETU_WDT_DEFAULT_TIMER * HZ);
2094 + del_timer_sync(&retu_wdt->ping_timer);
2097 +static int retu_wdt_open(struct inode *inode, struct file *file)
2099 + if (test_and_set_bit(1, (unsigned long *)&(retu_wdt->users)))
2102 + file->private_data = (void *)retu_wdt;
2103 + retu_wdt_set_ping_timer(0);
2105 + return nonseekable_open(inode, file);
2108 +static int retu_wdt_release(struct inode *inode, struct file *file)
2110 + struct retu_wdt_dev *wdev = file->private_data;
2112 +#ifndef CONFIG_WATCHDOG_NOWAYOUT
2113 + retu_wdt_set_ping_timer(1);
2120 +static ssize_t retu_wdt_write(struct file *file, const char __user *data,
2121 + size_t len, loff_t *ppos)
2124 + retu_modify_counter(RETU_WDT_MAX_TIMER);
2129 +static long retu_wdt_ioctl(struct file *file, unsigned int cmd,
2130 + unsigned long arg)
2134 + static struct watchdog_info ident = {
2135 + .identity = "Retu Watchdog",
2136 + .options = WDIOF_SETTIMEOUT,
2137 + .firmware_version = 0,
2143 + case WDIOC_GETSUPPORT:
2144 + return copy_to_user((struct watchdog_info __user *)arg, &ident,
2146 + case WDIOC_GETSTATUS:
2147 + return put_user(0, (int __user *)arg);
2148 + case WDIOC_GETBOOTSTATUS:
2149 + if (cpu_is_omap16xx())
2150 + return put_user(omap_readw(ARM_SYSST),
2151 + (int __user *)arg);
2152 + if (cpu_is_omap24xx())
2153 + return put_user(omap_prcm_get_reset_sources(),
2154 + (int __user *)arg);
2155 + case WDIOC_KEEPALIVE:
2156 + retu_modify_counter(RETU_WDT_MAX_TIMER);
2158 + case WDIOC_SETTIMEOUT:
2159 + if (get_user(new_margin, (int __user *)arg))
2161 + retu_modify_counter(new_margin);
2162 + /* Fall through */
2163 + case WDIOC_GETTIMEOUT:
2164 + return put_user(period_val, (int __user *)arg);
2170 +/* Start kicking retu watchdog until user space starts doing the kicking */
2171 +static int __devinit retu_wdt_ping(void)
2173 +#ifdef CONFIG_WATCHDOG_NOWAYOUT
2174 + retu_modify_counter(RETU_WDT_MAX_TIMER);
2176 + retu_wdt_set_ping_timer(1);
2182 +static const struct file_operations retu_wdt_fops = {
2183 + .owner = THIS_MODULE,
2184 + .write = retu_wdt_write,
2185 + .unlocked_ioctl = retu_wdt_ioctl,
2186 + .open = retu_wdt_open,
2187 + .release = retu_wdt_release,
2190 +/*----------------------------------------------------------------------------*/
2192 +static int __init retu_wdt_probe(struct platform_device *pdev)
2194 + struct retu_wdt_dev *wdev;
2197 + wdev = kzalloc(sizeof(struct retu_wdt_dev), GFP_KERNEL);
2201 + wdev->dev = &pdev->dev;
2204 + ret = device_create_file(&pdev->dev, &dev_attr_period);
2206 + dev_err(&pdev->dev, "Error creating sysfs period\n");
2210 + ret = device_create_file(&pdev->dev, &dev_attr_counter);
2212 + dev_err(&pdev->dev, "Error creating sysfs counter\n");
2216 + platform_set_drvdata(pdev, wdev);
2218 + wdev->retu_wdt_miscdev.parent = &pdev->dev;
2219 + wdev->retu_wdt_miscdev.minor = WATCHDOG_MINOR;
2220 + wdev->retu_wdt_miscdev.name = "watchdog";
2221 + wdev->retu_wdt_miscdev.fops = &retu_wdt_fops;
2223 + ret = misc_register(&(wdev->retu_wdt_miscdev));
2227 + setup_timer(&wdev->ping_timer, retu_wdt_set_ping_timer, 1);
2229 + /* passed as module parameter? */
2230 + ret = retu_modify_counter(counter_param);
2231 + if (ret == -EINVAL) {
2232 + ret = retu_modify_counter(RETU_WDT_DEFAULT_TIMER);
2233 + dev_dbg(&pdev->dev, "Initializing to default value\n");
2236 + /* Kick the watchdog for kernel booting to finish */
2237 + retu_modify_counter(RETU_WDT_MAX_TIMER);
2239 + ret = retu_wdt_ping();
2241 + dev_err(&pdev->dev, "Failed to ping\n");
2248 + misc_deregister(&wdev->retu_wdt_miscdev);
2251 + device_remove_file(&pdev->dev, &dev_attr_counter);
2254 + device_remove_file(&pdev->dev, &dev_attr_period);
2262 +static int __devexit retu_wdt_remove(struct platform_device *pdev)
2264 + struct retu_wdt_dev *wdev;
2266 + wdev = platform_get_drvdata(pdev);
2267 + misc_deregister(&wdev->retu_wdt_miscdev);
2268 + device_remove_file(&pdev->dev, &dev_attr_period);
2269 + device_remove_file(&pdev->dev, &dev_attr_counter);
2275 +static struct platform_driver retu_wdt_driver = {
2276 + .remove = __exit_p(retu_wdt_remove),
2278 + .name = "retu-wdt",
2282 +static int __init retu_wdt_init(void)
2284 + return platform_driver_probe(&retu_wdt_driver, retu_wdt_probe);
2287 +static void __exit retu_wdt_exit(void)
2289 + platform_driver_unregister(&retu_wdt_driver);
2292 +module_init(retu_wdt_init);
2293 +module_exit(retu_wdt_exit);
2294 +module_param(counter_param, int, 0);
2296 +MODULE_DESCRIPTION("Retu WatchDog");
2297 +MODULE_AUTHOR("Amit Kucheria");
2298 +MODULE_LICENSE("GPL");
2300 Index: linux-2.6.38-rc6/drivers/cbus/tahvo.c
2301 ===================================================================
2302 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2303 +++ linux-2.6.38-rc6/drivers/cbus/tahvo.c 2011-02-24 12:04:51.463188907 +0100
2306 + * drivers/cbus/tahvo.c
2308 + * Support functions for Tahvo ASIC
2310 + * Copyright (C) 2004, 2005 Nokia Corporation
2312 + * Written by Juha Yrjölä <juha.yrjola@nokia.com>,
2313 + * David Weinehall <david.weinehall@nokia.com>, and
2314 + * Mikko Ylinen <mikko.k.ylinen@nokia.com>
2316 + * This file is subject to the terms and conditions of the GNU General
2317 + * Public License. See the file "COPYING" in the main directory of this
2318 + * archive for more details.
2320 + * This program is distributed in the hope that it will be useful,
2321 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2322 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2323 + * GNU General Public License for more details.
2325 + * You should have received a copy of the GNU General Public License
2326 + * along with this program; if not, write to the Free Software
2327 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2330 +#include <linux/module.h>
2331 +#include <linux/init.h>
2333 +#include <linux/kernel.h>
2334 +#include <linux/errno.h>
2335 +#include <linux/device.h>
2336 +#include <linux/miscdevice.h>
2337 +#include <linux/poll.h>
2338 +#include <linux/fs.h>
2339 +#include <linux/irq.h>
2340 +#include <linux/interrupt.h>
2341 +#include <linux/platform_device.h>
2342 +#include <linux/gpio.h>
2344 +#include <asm/uaccess.h>
2345 +#include <asm/mach-types.h>
2347 +#include <plat/mux.h>
2348 +#include <plat/board.h>
2353 +#define TAHVO_ID 0x02
2354 +#define PFX "tahvo: "
2356 +static int tahvo_initialized;
2357 +static int tahvo_is_betty;
2359 +static struct tasklet_struct tahvo_tasklet;
2360 +spinlock_t tahvo_lock = SPIN_LOCK_UNLOCKED;
2362 +struct tahvo_irq_handler_desc {
2363 + int (*func)(unsigned long);
2364 + unsigned long arg;
2368 +static struct tahvo_irq_handler_desc tahvo_irq_handlers[MAX_TAHVO_IRQ_HANDLERS];
2370 +int tahvo_get_status(void)
2372 + return tahvo_initialized;
2374 +EXPORT_SYMBOL(tahvo_get_status);
2377 + * tahvo_read_reg - Read a value from a register in Tahvo
2378 + * @reg: the register to read from
2380 + * This function returns the contents of the specified register
2382 +int tahvo_read_reg(unsigned reg)
2384 + BUG_ON(!tahvo_initialized);
2385 + return cbus_read_reg(TAHVO_ID, reg);
2387 +EXPORT_SYMBOL(tahvo_read_reg);
2390 + * tahvo_write_reg - Write a value to a register in Tahvo
2391 + * @reg: the register to write to
2392 + * @reg: the value to write to the register
2394 + * This function writes a value to the specified register
2396 +void tahvo_write_reg(unsigned reg, u16 val)
2398 + BUG_ON(!tahvo_initialized);
2399 + cbus_write_reg(TAHVO_ID, reg, val);
2401 +EXPORT_SYMBOL(tahvo_write_reg);
2404 + * tahvo_set_clear_reg_bits - set and clear register bits atomically
2405 + * @reg: the register to write to
2406 + * @bits: the bits to set
2408 + * This function sets and clears the specified Tahvo register bits atomically
2410 +void tahvo_set_clear_reg_bits(unsigned reg, u16 set, u16 clear)
2412 + unsigned long flags;
2415 + spin_lock_irqsave(&tahvo_lock, flags);
2416 + w = tahvo_read_reg(reg);
2419 + tahvo_write_reg(reg, w);
2420 + spin_unlock_irqrestore(&tahvo_lock, flags);
2424 + * Disable given TAHVO interrupt
2426 +void tahvo_disable_irq(int id)
2428 + unsigned long flags;
2431 + spin_lock_irqsave(&tahvo_lock, flags);
2432 + mask = tahvo_read_reg(TAHVO_REG_IMR);
2434 + tahvo_write_reg(TAHVO_REG_IMR, mask);
2435 + spin_unlock_irqrestore(&tahvo_lock, flags);
2437 +EXPORT_SYMBOL(tahvo_disable_irq);
2440 + * Enable given TAHVO interrupt
2442 +void tahvo_enable_irq(int id)
2444 + unsigned long flags;
2447 + spin_lock_irqsave(&tahvo_lock, flags);
2448 + mask = tahvo_read_reg(TAHVO_REG_IMR);
2449 + mask &= ~(1 << id);
2450 + tahvo_write_reg(TAHVO_REG_IMR, mask);
2451 + spin_unlock_irqrestore(&tahvo_lock, flags);
2453 +EXPORT_SYMBOL(tahvo_enable_irq);
2456 + * Acknowledge given TAHVO interrupt
2458 +void tahvo_ack_irq(int id)
2460 + tahvo_write_reg(TAHVO_REG_IDR, 1 << id);
2462 +EXPORT_SYMBOL(tahvo_ack_irq);
2464 +static int tahvo_7bit_backlight;
2466 +int tahvo_get_backlight_level(void)
2470 + if (tahvo_7bit_backlight)
2474 + return tahvo_read_reg(TAHVO_REG_LEDPWMR) & mask;
2476 +EXPORT_SYMBOL(tahvo_get_backlight_level);
2478 +int tahvo_get_max_backlight_level(void)
2480 + if (tahvo_7bit_backlight)
2485 +EXPORT_SYMBOL(tahvo_get_max_backlight_level);
2487 +void tahvo_set_backlight_level(int level)
2491 + max_level = tahvo_get_max_backlight_level();
2492 + if (level > max_level)
2493 + level = max_level;
2494 + tahvo_write_reg(TAHVO_REG_LEDPWMR, level);
2496 +EXPORT_SYMBOL(tahvo_set_backlight_level);
2499 + * TAHVO interrupt handler. Only schedules the tasklet.
2501 +static irqreturn_t tahvo_irq_handler(int irq, void *dev_id)
2503 + tasklet_schedule(&tahvo_tasklet);
2504 + return IRQ_HANDLED;
2510 +static void tahvo_tasklet_handler(unsigned long data)
2512 + struct tahvo_irq_handler_desc *hnd;
2518 + id = tahvo_read_reg(TAHVO_REG_IDR);
2519 + im = ~tahvo_read_reg(TAHVO_REG_IMR);
2525 + for (i = 0; id != 0; i++, id >>= 1) {
2528 + hnd = &tahvo_irq_handlers[i];
2529 + if (hnd->func == NULL) {
2530 + /* Spurious tahvo interrupt - just ack it */
2531 + printk(KERN_INFO "Spurious Tahvo interrupt "
2533 + tahvo_disable_irq(i);
2537 + hnd->func(hnd->arg);
2539 + * Don't acknowledge the interrupt here
2540 + * It must be done explicitly
2547 + * Register the handler for a given TAHVO interrupt source.
2549 +int tahvo_request_irq(int id, void *irq_handler, unsigned long arg, char *name)
2551 + struct tahvo_irq_handler_desc *hnd;
2553 + if (irq_handler == NULL || id >= MAX_TAHVO_IRQ_HANDLERS ||
2555 + printk(KERN_ERR PFX "Invalid arguments to %s\n",
2559 + hnd = &tahvo_irq_handlers[id];
2560 + if (hnd->func != NULL) {
2561 + printk(KERN_ERR PFX "IRQ %d already reserved\n", id);
2564 + printk(KERN_INFO PFX "Registering interrupt %d for device %s\n",
2566 + hnd->func = irq_handler;
2568 + strlcpy(hnd->name, name, sizeof(hnd->name));
2570 + tahvo_ack_irq(id);
2571 + tahvo_enable_irq(id);
2575 +EXPORT_SYMBOL(tahvo_request_irq);
2578 + * Unregister the handler for a given TAHVO interrupt source.
2580 +void tahvo_free_irq(int id)
2582 + struct tahvo_irq_handler_desc *hnd;
2584 + if (id >= MAX_TAHVO_IRQ_HANDLERS) {
2585 + printk(KERN_ERR PFX "Invalid argument to %s\n",
2589 + hnd = &tahvo_irq_handlers[id];
2590 + if (hnd->func == NULL) {
2591 + printk(KERN_ERR PFX "IRQ %d already freed\n", id);
2595 + tahvo_disable_irq(id);
2598 +EXPORT_SYMBOL(tahvo_free_irq);
2601 + * tahvo_probe - Probe for Tahvo ASIC
2602 + * @dev: the Tahvo device
2604 + * Probe for the Tahvo ASIC and allocate memory
2605 + * for its device-struct if found
2607 +static int __init tahvo_probe(struct platform_device *pdev)
2612 + /* Prepare tasklet */
2613 + tasklet_init(&tahvo_tasklet, tahvo_tasklet_handler, 0);
2615 + tahvo_initialized = 1;
2617 + rev = tahvo_read_reg(TAHVO_REG_ASICR);
2619 + id = (rev >> 8) & 0xff;
2621 + if ((rev & 0xff) >= 0x50)
2622 + tahvo_7bit_backlight = 1;
2623 + } else if (id == 0x0b) {
2624 + tahvo_is_betty = 1;
2625 + tahvo_7bit_backlight = 1;
2627 + dev_err(&pdev->dev, "Tahvo/Betty chip not found");
2631 + dev_err(&pdev->dev, "%s v%d.%d found\n", tahvo_is_betty ? "Betty" : "Tahvo",
2632 + (rev >> 4) & 0x0f, rev & 0x0f);
2634 + irq = platform_get_irq(pdev, 0);
2636 + /* Mask all TAHVO interrupts */
2637 + tahvo_write_reg(TAHVO_REG_IMR, 0xffff);
2639 + ret = request_irq(irq, tahvo_irq_handler, IRQF_TRIGGER_RISING,
2642 + dev_err(&pdev->dev, "Unable to register IRQ handler\n");
2648 +static int __exit tahvo_remove(struct platform_device *pdev)
2652 + irq = platform_get_irq(pdev, 0);
2654 + /* Mask all TAHVO interrupts */
2655 + tahvo_write_reg(TAHVO_REG_IMR, 0xffff);
2657 + tasklet_kill(&tahvo_tasklet);
2662 +static struct platform_driver tahvo_driver = {
2663 + .remove = __exit_p(tahvo_remove),
2670 + * tahvo_init - initialise Tahvo driver
2672 + * Initialise the Tahvo driver and return 0 if everything worked ok
2674 +static int __init tahvo_init(void)
2676 + return platform_driver_probe(&tahvo_driver, tahvo_probe);
2682 +static void __exit tahvo_exit(void)
2684 + platform_driver_unregister(&tahvo_driver);
2687 +subsys_initcall(tahvo_init);
2688 +module_exit(tahvo_exit);
2690 +MODULE_DESCRIPTION("Tahvo ASIC control");
2691 +MODULE_LICENSE("GPL");
2692 +MODULE_AUTHOR("Juha Yrjölä");
2693 +MODULE_AUTHOR("David Weinehall");
2694 +MODULE_AUTHOR("Mikko Ylinen");
2696 Index: linux-2.6.38-rc6/drivers/cbus/tahvo.h
2697 ===================================================================
2698 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2699 +++ linux-2.6.38-rc6/drivers/cbus/tahvo.h 2011-02-24 12:04:51.463188907 +0100
2702 + * drivers/cbus/tahvo.h
2704 + * Copyright (C) 2004, 2005 Nokia Corporation
2706 + * Written by Juha Yrjölä <juha.yrjola@nokia.com> and
2707 + * David Weinehall <david.weinehall@nokia.com>
2709 + * This file is subject to the terms and conditions of the GNU General
2710 + * Public License. See the file "COPYING" in the main directory of this
2711 + * archive for more details.
2713 + * This program is distributed in the hope that it will be useful,
2714 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2715 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2716 + * GNU General Public License for more details.
2718 + * You should have received a copy of the GNU General Public License
2719 + * along with this program; if not, write to the Free Software
2720 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2723 +#ifndef __DRIVERS_CBUS_TAHVO_H
2724 +#define __DRIVERS_CBUS_TAHVO_H
2726 +#include <linux/types.h>
2729 +#define TAHVO_REG_ASICR 0x00 /* ASIC ID & revision */
2730 +#define TAHVO_REG_IDR 0x01 /* Interrupt ID */
2731 +#define TAHVO_REG_IDSR 0x02 /* Interrupt status */
2732 +#define TAHVO_REG_IMR 0x03 /* Interrupt mask */
2733 +#define TAHVO_REG_LEDPWMR 0x05 /* LED PWM */
2734 +#define TAHVO_REG_USBR 0x06 /* USB control */
2735 +#define TAHVO_REG_MAX 0x0d
2737 +/* Interrupt sources */
2738 +#define TAHVO_INT_VBUSON 0
2740 +#define MAX_TAHVO_IRQ_HANDLERS 8
2742 +int tahvo_get_status(void);
2743 +int tahvo_read_reg(unsigned reg);
2744 +void tahvo_write_reg(unsigned reg, u16 val);
2745 +void tahvo_set_clear_reg_bits(unsigned reg, u16 set, u16 clear);
2746 +int tahvo_request_irq(int id, void *irq_handler, unsigned long arg, char *name);
2747 +void tahvo_free_irq(int id);
2748 +void tahvo_enable_irq(int id);
2749 +void tahvo_disable_irq(int id);
2750 +void tahvo_ack_irq(int id);
2751 +int tahvo_get_backlight_level(void);
2752 +int tahvo_get_max_backlight_level(void);
2753 +void tahvo_set_backlight_level(int level);
2755 +extern spinlock_t tahvo_lock;
2757 +#endif /* __DRIVERS_CBUS_TAHVO_H */
2758 Index: linux-2.6.38-rc6/drivers/cbus/tahvo-usb.c
2759 ===================================================================
2760 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2761 +++ linux-2.6.38-rc6/drivers/cbus/tahvo-usb.c 2011-02-24 12:04:51.464188862 +0100
2764 + * drivers/cbus/tahvo-usb.c
2766 + * Tahvo USB transeiver
2768 + * Copyright (C) 2005-2006 Nokia Corporation
2770 + * Parts copied from drivers/i2c/chips/isp1301_omap.c
2771 + * Copyright (C) 2004 Texas Instruments
2772 + * Copyright (C) 2004 David Brownell
2774 + * Written by Juha Yrjölä <juha.yrjola@nokia.com>,
2775 + * Tony Lindgren <tony@atomide.com>, and
2776 + * Timo Teräs <timo.teras@nokia.com>
2778 + * This file is subject to the terms and conditions of the GNU General
2779 + * Public License. See the file "COPYING" in the main directory of this
2780 + * archive for more details.
2782 + * This program is distributed in the hope that it will be useful,
2783 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2784 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2785 + * GNU General Public License for more details.
2787 + * You should have received a copy of the GNU General Public License
2788 + * along with this program; if not, write to the Free Software
2789 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2792 +#include <linux/kernel.h>
2793 +#include <linux/module.h>
2794 +#include <linux/init.h>
2795 +#include <linux/slab.h>
2796 +#include <linux/io.h>
2797 +#include <linux/interrupt.h>
2798 +#include <linux/platform_device.h>
2799 +#include <linux/usb/ch9.h>
2800 +#include <linux/usb/gadget.h>
2801 +#include <linux/usb.h>
2802 +#include <linux/usb/otg.h>
2803 +#include <linux/i2c.h>
2804 +#include <linux/workqueue.h>
2805 +#include <linux/kobject.h>
2806 +#include <linux/clk.h>
2807 +#include <linux/mutex.h>
2809 +#include <asm/irq.h>
2810 +#include <plat/usb.h>
2815 +#define DRIVER_NAME "tahvo-usb"
2817 +#define USBR_SLAVE_CONTROL (1 << 8)
2818 +#define USBR_VPPVIO_SW (1 << 7)
2819 +#define USBR_SPEED (1 << 6)
2820 +#define USBR_REGOUT (1 << 5)
2821 +#define USBR_MASTER_SW2 (1 << 4)
2822 +#define USBR_MASTER_SW1 (1 << 3)
2823 +#define USBR_SLAVE_SW (1 << 2)
2824 +#define USBR_NSUSPEND (1 << 1)
2825 +#define USBR_SEMODE (1 << 0)
2827 +/* bits in OTG_CTRL */
2829 +/* Bits that are controlled by OMAP OTG and are read-only */
2830 +#define OTG_CTRL_OMAP_MASK (OTG_PULLDOWN|OTG_PULLUP|OTG_DRV_VBUS|\
2831 + OTG_PD_VBUS|OTG_PU_VBUS|OTG_PU_ID)
2832 +/* Bits that are controlled by transceiver */
2833 +#define OTG_CTRL_XCVR_MASK (OTG_ASESSVLD|OTG_BSESSEND|\
2834 + OTG_BSESSVLD|OTG_VBUSVLD|OTG_ID)
2835 +/* Bits that are controlled by system */
2836 +#define OTG_CTRL_SYS_MASK (OTG_A_BUSREQ|OTG_A_SETB_HNPEN|OTG_B_BUSREQ|\
2837 + OTG_B_HNPEN|OTG_BUSDROP)
2839 +#if defined(CONFIG_USB_OHCI_HCD) && !defined(CONFIG_USB_OTG)
2840 +#error tahvo-otg.c does not work with OCHI yet!
2843 +#define TAHVO_MODE_HOST 0
2844 +#define TAHVO_MODE_PERIPHERAL 1
2846 +#ifdef CONFIG_USB_OTG
2847 +#define TAHVO_MODE(tu) (tu)->tahvo_mode
2848 +#elif defined(CONFIG_USB_GADGET_OMAP)
2849 +#define TAHVO_MODE(tu) TAHVO_MODE_PERIPHERAL
2851 +#define TAHVO_MODE(tu) TAHVO_MODE_HOST
2855 + struct platform_device *pt_dev;
2856 + struct otg_transceiver otg;
2858 + struct work_struct irq_work;
2859 + struct mutex serialize;
2860 +#ifdef CONFIG_USB_OTG
2864 +static struct platform_device tahvo_usb_device;
2867 + * ---------------------------------------------------------------------------
2868 + * OTG related functions
2870 + * These shoud be separated into omap-otg.c driver module, as they are used
2871 + * by various transceivers. These functions are needed in the UDC-only case
2872 + * as well. These functions are copied from GPL isp1301_omap.c
2873 + * ---------------------------------------------------------------------------
2875 +static struct platform_device *tahvo_otg_dev;
2877 +static irqreturn_t omap_otg_irq(int irq, void *arg)
2879 + struct platform_device *otg_dev = arg;
2880 + struct tahvo_usb *tu = platform_get_drvdata(otg_dev);
2883 + otg_irq = omap_readw(OTG_IRQ_SRC);
2884 + if (otg_irq & OPRT_CHG) {
2885 + omap_writew(OPRT_CHG, OTG_IRQ_SRC);
2886 + } else if (otg_irq & B_SRP_TMROUT) {
2887 + omap_writew(B_SRP_TMROUT, OTG_IRQ_SRC);
2888 + } else if (otg_irq & B_HNP_FAIL) {
2889 + omap_writew(B_HNP_FAIL, OTG_IRQ_SRC);
2890 + } else if (otg_irq & A_SRP_DETECT) {
2891 + omap_writew(A_SRP_DETECT, OTG_IRQ_SRC);
2892 + } else if (otg_irq & A_REQ_TMROUT) {
2893 + omap_writew(A_REQ_TMROUT, OTG_IRQ_SRC);
2894 + } else if (otg_irq & A_VBUS_ERR) {
2895 + omap_writew(A_VBUS_ERR, OTG_IRQ_SRC);
2896 + } else if (otg_irq & DRIVER_SWITCH) {
2897 +#ifdef CONFIG_USB_OTG
2898 + if ((!(omap_readl(OTG_CTRL) & OTG_DRIVER_SEL)) &&
2899 + tu->otg.host && tu->otg.state == OTG_STATE_A_HOST) {
2900 + /* role is host */
2901 + usb_bus_start_enum(tu->otg.host,
2902 + tu->otg.host->otg_port);
2905 + omap_writew(DRIVER_SWITCH, OTG_IRQ_SRC);
2909 + return IRQ_HANDLED;
2913 +static int tahvo_otg_init(void)
2917 +#ifdef CONFIG_USB_OTG
2918 + if (!tahvo_otg_dev) {
2919 + printk("tahvo-usb: no tahvo_otg_dev\n");
2924 + l = omap_readl(OTG_SYSCON_1);
2925 + l &= ~OTG_IDLE_EN;
2926 + omap_writel(l, OTG_SYSCON_1);
2929 + /* some of these values are board-specific... */
2930 + l = omap_readl(OTG_SYSCON_2);
2932 + /* for B-device: */
2933 + | SRP_GPDATA /* 9msec Bdev D+ pulse */
2934 + | SRP_GPDVBUS /* discharge after VBUS pulse */
2935 + // | (3 << 24) /* 2msec VBUS pulse */
2936 + /* for A-device: */
2937 + | (0 << 20) /* 200ms nominal A_WAIT_VRISE timer */
2938 + | SRP_DPW /* detect 167+ns SRP pulses */
2939 + | SRP_DATA | SRP_VBUS; /* accept both kinds of SRP pulse */
2940 + omap_writel(l, OTG_SYSCON_2);
2942 + omap_writew(DRIVER_SWITCH | OPRT_CHG
2943 + | B_SRP_TMROUT | B_HNP_FAIL
2944 + | A_VBUS_ERR | A_SRP_DETECT | A_REQ_TMROUT,
2946 + l = omap_readl(OTG_SYSCON_2);
2948 + omap_writel(l, OTG_SYSCON_2);
2953 +static int __init omap_otg_probe(struct platform_device *pdev)
2957 + tahvo_otg_dev = pdev;
2958 + ret = tahvo_otg_init();
2960 + printk(KERN_ERR "tahvo-usb: tahvo_otg_init failed\n");
2964 + return request_irq(tahvo_otg_dev->resource[1].start,
2965 + omap_otg_irq, IRQF_DISABLED, DRIVER_NAME,
2966 + &tahvo_usb_device);
2969 +static int __exit omap_otg_remove(struct platform_device *pdev)
2971 + free_irq(tahvo_otg_dev->resource[1].start, &tahvo_usb_device);
2972 + tahvo_otg_dev = NULL;
2977 +struct platform_driver omap_otg_driver = {
2979 + .name = "omap_otg",
2981 + .remove = __exit_p(omap_otg_remove),
2985 + * ---------------------------------------------------------------------------
2986 + * Tahvo related functions
2987 + * These are Nokia proprietary code, except for the OTG register settings,
2988 + * which are copied from isp1301.c
2989 + * ---------------------------------------------------------------------------
2991 +static ssize_t vbus_state_show(struct device *device,
2992 + struct device_attribute *attr, char *buf)
2994 + struct tahvo_usb *tu = dev_get_drvdata(device);
2995 + return sprintf(buf, "%d\n", tu->vbus_state);
2997 +static DEVICE_ATTR(vbus_state, 0444, vbus_state_show, NULL);
2999 +int vbus_active = 0;
3003 +static int host_suspend(struct tahvo_usb *tu)
3005 + struct device *dev;
3007 + if (!tu->otg.host)
3010 + /* Currently ASSUMES only the OTG port matters;
3011 + * other ports could be active...
3013 + dev = tu->otg.host->controller;
3014 + return dev->driver->suspend(dev, PMSG_SUSPEND);
3017 +static int host_resume(struct tahvo_usb *tu)
3019 + struct device *dev;
3021 + if (!tu->otg.host)
3024 + dev = tu->otg.host->controller;
3025 + return dev->driver->resume(dev);
3030 +static int host_suspend(struct tahvo_usb *tu)
3035 +static int host_resume(struct tahvo_usb *tu)
3042 +static void check_vbus_state(struct tahvo_usb *tu)
3044 + int reg, prev_state;
3046 + reg = tahvo_read_reg(TAHVO_REG_IDSR);
3051 + switch (tu->otg.state) {
3052 + case OTG_STATE_B_IDLE:
3053 + /* Enable the gadget driver */
3054 + if (tu->otg.gadget)
3055 + usb_gadget_vbus_connect(tu->otg.gadget);
3056 + /* Set B-session valid and not B-sessio ended to indicate
3057 + * Vbus to be ok. */
3058 + l = omap_readl(OTG_CTRL);
3059 + l &= ~OTG_BSESSEND;
3060 + l |= OTG_BSESSVLD;
3061 + omap_writel(l, OTG_CTRL);
3063 + tu->otg.state = OTG_STATE_B_PERIPHERAL;
3065 + case OTG_STATE_A_IDLE:
3066 + /* Session is now valid assuming the USB hub is driving Vbus */
3067 + tu->otg.state = OTG_STATE_A_HOST;
3073 + printk("USB cable connected\n");
3075 + switch (tu->otg.state) {
3076 + case OTG_STATE_B_PERIPHERAL:
3077 + if (tu->otg.gadget)
3078 + usb_gadget_vbus_disconnect(tu->otg.gadget);
3079 + tu->otg.state = OTG_STATE_B_IDLE;
3081 + case OTG_STATE_A_HOST:
3082 + tu->otg.state = OTG_STATE_A_IDLE;
3087 + printk("USB cable disconnected\n");
3091 + prev_state = tu->vbus_state;
3092 + tu->vbus_state = reg & 0x01;
3093 + if (prev_state != tu->vbus_state)
3094 + sysfs_notify(&tu->pt_dev->dev.kobj, NULL, "vbus_state");
3097 +static void tahvo_usb_become_host(struct tahvo_usb *tu)
3101 + /* Clear system and transceiver controlled bits
3102 + * also mark the A-session is always valid */
3105 + l = omap_readl(OTG_CTRL);
3106 + l &= ~(OTG_CTRL_XCVR_MASK | OTG_CTRL_SYS_MASK);
3107 + l |= OTG_ASESSVLD;
3108 + omap_writel(l, OTG_CTRL);
3110 + /* Power up the transceiver in USB host mode */
3111 + tahvo_write_reg(TAHVO_REG_USBR, USBR_REGOUT | USBR_NSUSPEND |
3112 + USBR_MASTER_SW2 | USBR_MASTER_SW1);
3113 + tu->otg.state = OTG_STATE_A_IDLE;
3115 + check_vbus_state(tu);
3118 +static void tahvo_usb_stop_host(struct tahvo_usb *tu)
3121 + tu->otg.state = OTG_STATE_A_IDLE;
3124 +static void tahvo_usb_become_peripheral(struct tahvo_usb *tu)
3128 + /* Clear system and transceiver controlled bits
3129 + * and enable ID to mark peripheral mode and
3130 + * BSESSEND to mark no Vbus */
3132 + l = omap_readl(OTG_CTRL);
3133 + l &= ~(OTG_CTRL_XCVR_MASK | OTG_CTRL_SYS_MASK | OTG_BSESSVLD);
3134 + l |= OTG_ID | OTG_BSESSEND;
3135 + omap_writel(l, OTG_CTRL);
3137 + /* Power up transceiver and set it in USB perhiperal mode */
3138 + tahvo_write_reg(TAHVO_REG_USBR, USBR_SLAVE_CONTROL | USBR_REGOUT | USBR_NSUSPEND | USBR_SLAVE_SW);
3139 + tu->otg.state = OTG_STATE_B_IDLE;
3141 + check_vbus_state(tu);
3144 +static void tahvo_usb_stop_peripheral(struct tahvo_usb *tu)
3148 + l = omap_readl(OTG_CTRL);
3149 + l &= ~OTG_BSESSVLD;
3150 + l |= OTG_BSESSEND;
3151 + omap_writel(l, OTG_CTRL);
3153 + if (tu->otg.gadget)
3154 + usb_gadget_vbus_disconnect(tu->otg.gadget);
3155 + tu->otg.state = OTG_STATE_B_IDLE;
3159 +static void tahvo_usb_power_off(struct tahvo_usb *tu)
3164 + /* Disable gadget controller if any */
3165 + if (tu->otg.gadget)
3166 + usb_gadget_vbus_disconnect(tu->otg.gadget);
3170 + /* Disable OTG and interrupts */
3171 + if (TAHVO_MODE(tu) == TAHVO_MODE_PERIPHERAL)
3175 + l = omap_readl(OTG_CTRL);
3176 + l &= ~(OTG_CTRL_XCVR_MASK | OTG_CTRL_SYS_MASK | OTG_BSESSVLD);
3177 + l |= id | OTG_BSESSEND;
3178 + omap_writel(l, OTG_CTRL);
3179 + omap_writew(0, OTG_IRQ_EN);
3181 + l = omap_readl(OTG_SYSCON_2);
3183 + omap_writel(l, OTG_SYSCON_2);
3185 + l = omap_readl(OTG_SYSCON_1);
3187 + omap_writel(l, OTG_SYSCON_1);
3189 + /* Power off transceiver */
3190 + tahvo_write_reg(TAHVO_REG_USBR, 0);
3191 + tu->otg.state = OTG_STATE_UNDEFINED;
3195 +static int tahvo_usb_set_power(struct otg_transceiver *dev, unsigned mA)
3197 + struct tahvo_usb *tu = container_of(dev, struct tahvo_usb, otg);
3199 + dev_dbg(&tu->pt_dev->dev, "set_power %d mA\n", mA);
3201 + if (dev->state == OTG_STATE_B_PERIPHERAL) {
3202 + /* REVISIT: Can Tahvo charge battery from VBUS? */
3207 +static int tahvo_usb_set_suspend(struct otg_transceiver *dev, int suspend)
3209 + struct tahvo_usb *tu = container_of(dev, struct tahvo_usb, otg);
3212 + dev_dbg(&tu->pt_dev->dev, "set_suspend\n");
3214 + w = tahvo_read_reg(TAHVO_REG_USBR);
3216 + w &= ~USBR_NSUSPEND;
3218 + w |= USBR_NSUSPEND;
3219 + tahvo_write_reg(TAHVO_REG_USBR, w);
3224 +static int tahvo_usb_start_srp(struct otg_transceiver *dev)
3226 + struct tahvo_usb *tu = container_of(dev, struct tahvo_usb, otg);
3229 + dev_dbg(&tu->pt_dev->dev, "start_srp\n");
3231 + if (!dev || tu->otg.state != OTG_STATE_B_IDLE)
3234 + otg_ctrl = omap_readl(OTG_CTRL);
3235 + if (!(otg_ctrl & OTG_BSESSEND))
3238 + otg_ctrl |= OTG_B_BUSREQ;
3239 + otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_SYS_MASK;
3240 + omap_writel(otg_ctrl, OTG_CTRL);
3241 + tu->otg.state = OTG_STATE_B_SRP_INIT;
3246 +static int tahvo_usb_start_hnp(struct otg_transceiver *otg)
3248 + struct tahvo_usb *tu = container_of(otg, struct tahvo_usb, otg);
3250 + dev_dbg(&tu->pt_dev->dev, "start_hnp\n");
3251 +#ifdef CONFIG_USB_OTG
3252 + /* REVISIT: Add this for OTG */
3257 +static int tahvo_usb_set_host(struct otg_transceiver *otg, struct usb_bus *host)
3259 + struct tahvo_usb *tu = container_of(otg, struct tahvo_usb, otg);
3262 + dev_dbg(&tu->pt_dev->dev, "set_host %p\n", host);
3267 +#if defined(CONFIG_USB_OTG) || !defined(CONFIG_USB_GADGET_OMAP)
3269 + mutex_lock(&tu->serialize);
3271 + if (host == NULL) {
3272 + if (TAHVO_MODE(tu) == TAHVO_MODE_HOST)
3273 + tahvo_usb_power_off(tu);
3274 + tu->otg.host = NULL;
3275 + mutex_unlock(&tu->serialize);
3279 + l = omap_readl(OTG_SYSCON_1);
3280 + l &= ~(OTG_IDLE_EN | HST_IDLE_EN | DEV_IDLE_EN);
3281 + omap_writel(l, OTG_SYSCON_1);
3283 + if (TAHVO_MODE(tu) == TAHVO_MODE_HOST) {
3284 + tu->otg.host = NULL;
3285 + tahvo_usb_become_host(tu);
3289 + tu->otg.host = host;
3291 + mutex_unlock(&tu->serialize);
3293 + /* No host mode configured, so do not allow host controlled to be set */
3300 +static int tahvo_usb_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget)
3302 + struct tahvo_usb *tu = container_of(otg, struct tahvo_usb, otg);
3304 + dev_dbg(&tu->pt_dev->dev, "set_peripheral %p\n", gadget);
3309 +#if defined(CONFIG_USB_OTG) || defined(CONFIG_USB_GADGET_OMAP)
3311 + mutex_lock(&tu->serialize);
3314 + if (TAHVO_MODE(tu) == TAHVO_MODE_PERIPHERAL)
3315 + tahvo_usb_power_off(tu);
3316 + tu->otg.gadget = NULL;
3317 + mutex_unlock(&tu->serialize);
3321 + tu->otg.gadget = gadget;
3322 + if (TAHVO_MODE(tu) == TAHVO_MODE_PERIPHERAL)
3323 + tahvo_usb_become_peripheral(tu);
3325 + mutex_unlock(&tu->serialize);
3327 + /* No gadget mode configured, so do not allow host controlled to be set */
3334 +static void tahvo_usb_irq_work(struct work_struct *work)
3336 + struct tahvo_usb *tu = container_of(work, struct tahvo_usb, irq_work);
3338 + mutex_lock(&tu->serialize);
3339 + check_vbus_state(tu);
3340 + mutex_unlock(&tu->serialize);
3343 +static void tahvo_usb_vbus_interrupt(unsigned long arg)
3345 + struct tahvo_usb *tu = (struct tahvo_usb *) arg;
3347 + tahvo_ack_irq(TAHVO_INT_VBUSON);
3348 + /* Seems we need this to acknowledge the interrupt */
3349 + tahvo_read_reg(TAHVO_REG_IDSR);
3350 + schedule_work(&tu->irq_work);
3353 +#ifdef CONFIG_USB_OTG
3354 +static ssize_t otg_mode_show(struct device *device,
3355 + struct device_attribute *attr, char *buf)
3357 + struct tahvo_usb *tu = dev_get_drvdata(device);
3358 + switch (tu->tahvo_mode) {
3359 + case TAHVO_MODE_HOST:
3360 + return sprintf(buf, "host\n");
3361 + case TAHVO_MODE_PERIPHERAL:
3362 + return sprintf(buf, "peripheral\n");
3364 + return sprintf(buf, "unknown\n");
3367 +static ssize_t otg_mode_store(struct device *device,
3368 + struct device_attribute *attr,
3369 + const char *buf, size_t count)
3371 + struct tahvo_usb *tu = dev_get_drvdata(device);
3375 + mutex_lock(&tu->serialize);
3376 + if (strncmp(buf, "host", 4) == 0) {
3377 + if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL)
3378 + tahvo_usb_stop_peripheral(tu);
3379 + tu->tahvo_mode = TAHVO_MODE_HOST;
3380 + if (tu->otg.host) {
3381 + printk(KERN_INFO "Selected HOST mode: host controller present.\n");
3382 + tahvo_usb_become_host(tu);
3384 + printk(KERN_INFO "Selected HOST mode: no host controller, powering off.\n");
3385 + tahvo_usb_power_off(tu);
3387 + } else if (strncmp(buf, "peripheral", 10) == 0) {
3388 + if (tu->tahvo_mode == TAHVO_MODE_HOST)
3389 + tahvo_usb_stop_host(tu);
3390 + tu->tahvo_mode = TAHVO_MODE_PERIPHERAL;
3391 + if (tu->otg.gadget) {
3392 + printk(KERN_INFO "Selected PERIPHERAL mode: gadget driver present.\n");
3393 + tahvo_usb_become_peripheral(tu);
3395 + printk(KERN_INFO "Selected PERIPHERAL mode: no gadget driver, powering off.\n");
3396 + tahvo_usb_power_off(tu);
3401 + mutex_unlock(&tu->serialize);
3405 +static DEVICE_ATTR(otg_mode, 0644, otg_mode_show, otg_mode_store);
3408 +static int __init tahvo_usb_probe(struct platform_device *pdev)
3410 + struct tahvo_usb *tu;
3411 + struct device *dev = &pdev->dev;
3414 + ret = tahvo_get_status();
3418 + dev_dbg(dev, "probe\n");
3420 + /* Create driver data */
3421 + tu = kzalloc(sizeof(*tu), GFP_KERNEL);
3425 + tu->pt_dev = container_of(dev, struct platform_device, dev);
3426 +#ifdef CONFIG_USB_OTG
3427 + /* Default mode */
3428 +#ifdef CONFIG_CBUS_TAHVO_USB_HOST_BY_DEFAULT
3429 + tu->tahvo_mode = TAHVO_MODE_HOST;
3431 + tu->tahvo_mode = TAHVO_MODE_PERIPHERAL;
3435 + INIT_WORK(&tu->irq_work, tahvo_usb_irq_work);
3436 + mutex_init(&tu->serialize);
3438 + /* Set initial state, so that we generate kevents only on
3439 + * state changes */
3440 + tu->vbus_state = tahvo_read_reg(TAHVO_REG_IDSR) & 0x01;
3442 + /* We cannot enable interrupt until omap_udc is initialized */
3443 + ret = tahvo_request_irq(TAHVO_INT_VBUSON, tahvo_usb_vbus_interrupt,
3444 + (unsigned long) tu, "vbus_interrupt");
3447 + printk(KERN_ERR "Could not register Tahvo interrupt for VBUS\n");
3452 + ret = device_create_file(dev, &dev_attr_vbus_state);
3453 +#ifdef CONFIG_USB_OTG
3454 + ret |= device_create_file(dev, &dev_attr_otg_mode);
3457 + printk(KERN_ERR "attribute creation failed: %d\n", ret);
3459 + /* Create OTG interface */
3460 + tahvo_usb_power_off(tu);
3461 + tu->otg.state = OTG_STATE_UNDEFINED;
3462 + tu->otg.label = DRIVER_NAME;
3463 + tu->otg.set_host = tahvo_usb_set_host;
3464 + tu->otg.set_peripheral = tahvo_usb_set_peripheral;
3465 + tu->otg.set_power = tahvo_usb_set_power;
3466 + tu->otg.set_suspend = tahvo_usb_set_suspend;
3467 + tu->otg.start_srp = tahvo_usb_start_srp;
3468 + tu->otg.start_hnp = tahvo_usb_start_hnp;
3470 + ret = otg_set_transceiver(&tu->otg);
3472 + printk(KERN_ERR "Cannot register USB transceiver\n");
3474 + tahvo_free_irq(TAHVO_INT_VBUSON);
3478 + dev_set_drvdata(dev, tu);
3480 + /* Act upon current vbus state once at startup. A vbus state irq may or
3481 + * may not be generated in addition to this. */
3482 + schedule_work(&tu->irq_work);
3486 +static int __exit tahvo_usb_remove(struct platform_device *pdev)
3488 + dev_dbg(&pdev->dev, "remove\n");
3490 + tahvo_free_irq(TAHVO_INT_VBUSON);
3491 + flush_scheduled_work();
3492 + otg_set_transceiver(0);
3493 + device_remove_file(&pdev->dev, &dev_attr_vbus_state);
3494 +#ifdef CONFIG_USB_OTG
3495 + device_remove_file(&pdev->dev, &dev_attr_otg_mode);
3500 +static struct platform_driver tahvo_usb_driver = {
3502 + .name = "tahvo-usb",
3504 + .remove = __exit_p(tahvo_usb_remove),
3507 +static int __init tahvo_usb_init(void)
3511 + ret = platform_driver_probe(&tahvo_usb_driver, tahvo_usb_probe);
3515 + ret = platform_driver_probe(&omap_otg_driver, omap_otg_probe);
3517 + platform_driver_unregister(&tahvo_usb_driver);
3524 +subsys_initcall(tahvo_usb_init);
3526 +static void __exit tahvo_usb_exit(void)
3528 + platform_driver_unregister(&omap_otg_driver);
3529 + platform_driver_unregister(&tahvo_usb_driver);
3531 +module_exit(tahvo_usb_exit);
3533 +MODULE_DESCRIPTION("Tahvo USB OTG Transceiver Driver");
3534 +MODULE_LICENSE("GPL");
3535 +MODULE_AUTHOR("Juha Yrjölä, Tony Lindgren, and Timo Teräs");
3536 Index: linux-2.6.38-rc6/drivers/Makefile
3537 ===================================================================
3538 --- linux-2.6.38-rc6.orig/drivers/Makefile 2011-02-24 12:03:07.439316519 +0100
3539 +++ linux-2.6.38-rc6/drivers/Makefile 2011-02-24 12:03:27.457522207 +0100
3541 obj-$(CONFIG_INPUT) += input/
3542 obj-$(CONFIG_I2O) += message/
3543 obj-$(CONFIG_RTC_LIB) += rtc/
3544 -obj-y += i2c/ media/
3545 +obj-y += i2c/ media/ cbus/
3546 obj-$(CONFIG_PPS) += pps/
3547 obj-$(CONFIG_W1) += w1/
3548 obj-$(CONFIG_POWER_SUPPLY) += power/
3549 Index: linux-2.6.38-rc6/arch/arm/Kconfig
3550 ===================================================================
3551 --- linux-2.6.38-rc6.orig/arch/arm/Kconfig 2011-02-24 12:03:07.286322589 +0100
3552 +++ linux-2.6.38-rc6/arch/arm/Kconfig 2011-02-24 12:03:27.458522167 +0100
3553 @@ -1930,6 +1930,10 @@
3555 source "drivers/Kconfig"
3558 +source "drivers/cbus/Kconfig"
3563 source "arch/arm/Kconfig.debug"