ACPI: ibm-acpi: implement fan watchdog command
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / input / misc / ixp4xx-beeper.c
blob105c6fc27823e368cd445d63a8787b5fdfe9ac28
1 /*
2 * Generic IXP4xx beeper driver
4 * Copyright (C) 2005 Tower Technologies
6 * based on nslu2-io.c
7 * Copyright (C) 2004 Karen Spearel
9 * Author: Alessandro Zummo <a.zummo@towertech.it>
10 * Maintainers: http://www.nslu2-linux.org/
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
18 #include <linux/module.h>
19 #include <linux/input.h>
20 #include <linux/delay.h>
21 #include <linux/platform_device.h>
22 #include <linux/interrupt.h>
23 #include <asm/hardware.h>
25 MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
26 MODULE_DESCRIPTION("ixp4xx beeper driver");
27 MODULE_LICENSE("GPL");
29 static DEFINE_SPINLOCK(beep_lock);
31 static void ixp4xx_spkr_control(unsigned int pin, unsigned int count)
33 unsigned long flags;
35 spin_lock_irqsave(&beep_lock, flags);
37 if (count) {
38 gpio_line_config(pin, IXP4XX_GPIO_OUT);
39 gpio_line_set(pin, IXP4XX_GPIO_LOW);
41 *IXP4XX_OSRT2 = (count & ~IXP4XX_OST_RELOAD_MASK) | IXP4XX_OST_ENABLE;
42 } else {
43 gpio_line_config(pin, IXP4XX_GPIO_IN);
44 gpio_line_set(pin, IXP4XX_GPIO_HIGH);
46 *IXP4XX_OSRT2 = 0;
49 spin_unlock_irqrestore(&beep_lock, flags);
52 static int ixp4xx_spkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
54 unsigned int pin = (unsigned int) dev->private;
55 unsigned int count = 0;
57 if (type != EV_SND)
58 return -1;
60 switch (code) {
61 case SND_BELL:
62 if (value)
63 value = 1000;
64 case SND_TONE:
65 break;
66 default:
67 return -1;
70 if (value > 20 && value < 32767)
71 #ifndef FREQ
72 count = (ixp4xx_get_board_tick_rate() / (value * 4)) - 1;
73 #else
74 count = (FREQ / (value * 4)) - 1;
75 #endif
77 ixp4xx_spkr_control(pin, count);
79 return 0;
82 static irqreturn_t ixp4xx_spkr_interrupt(int irq, void *dev_id)
84 /* clear interrupt */
85 *IXP4XX_OSST = IXP4XX_OSST_TIMER_2_PEND;
87 /* flip the beeper output */
88 *IXP4XX_GPIO_GPOUTR ^= (1 << (unsigned int) dev_id);
90 return IRQ_HANDLED;
93 static int __devinit ixp4xx_spkr_probe(struct platform_device *dev)
95 struct input_dev *input_dev;
96 int err;
98 input_dev = input_allocate_device();
99 if (!input_dev)
100 return -ENOMEM;
102 input_dev->private = (void *) dev->id;
103 input_dev->name = "ixp4xx beeper",
104 input_dev->phys = "ixp4xx/gpio";
105 input_dev->id.bustype = BUS_HOST;
106 input_dev->id.vendor = 0x001f;
107 input_dev->id.product = 0x0001;
108 input_dev->id.version = 0x0100;
109 input_dev->cdev.dev = &dev->dev;
111 input_dev->evbit[0] = BIT(EV_SND);
112 input_dev->sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE);
113 input_dev->event = ixp4xx_spkr_event;
115 err = request_irq(IRQ_IXP4XX_TIMER2, &ixp4xx_spkr_interrupt,
116 IRQF_DISABLED | IRQF_TIMER, "ixp4xx-beeper", (void *) dev->id);
117 if (err)
118 goto err_free_device;
120 err = input_register_device(input_dev);
121 if (err)
122 goto err_free_irq;
124 platform_set_drvdata(dev, input_dev);
126 return 0;
128 err_free_irq:
129 free_irq(IRQ_IXP4XX_TIMER2, dev);
130 err_free_device:
131 input_free_device(input_dev);
133 return err;
136 static int __devexit ixp4xx_spkr_remove(struct platform_device *dev)
138 struct input_dev *input_dev = platform_get_drvdata(dev);
139 unsigned int pin = (unsigned int) input_dev->private;
141 input_unregister_device(input_dev);
142 platform_set_drvdata(dev, NULL);
144 /* turn the speaker off */
145 disable_irq(IRQ_IXP4XX_TIMER2);
146 ixp4xx_spkr_control(pin, 0);
148 free_irq(IRQ_IXP4XX_TIMER2, dev);
150 return 0;
153 static void ixp4xx_spkr_shutdown(struct platform_device *dev)
155 struct input_dev *input_dev = platform_get_drvdata(dev);
156 unsigned int pin = (unsigned int) input_dev->private;
158 /* turn off the speaker */
159 disable_irq(IRQ_IXP4XX_TIMER2);
160 ixp4xx_spkr_control(pin, 0);
163 static struct platform_driver ixp4xx_spkr_platform_driver = {
164 .driver = {
165 .name = "ixp4xx-beeper",
166 .owner = THIS_MODULE,
168 .probe = ixp4xx_spkr_probe,
169 .remove = __devexit_p(ixp4xx_spkr_remove),
170 .shutdown = ixp4xx_spkr_shutdown,
173 static int __init ixp4xx_spkr_init(void)
175 return platform_driver_register(&ixp4xx_spkr_platform_driver);
178 static void __exit ixp4xx_spkr_exit(void)
180 platform_driver_unregister(&ixp4xx_spkr_platform_driver);
183 module_init(ixp4xx_spkr_init);
184 module_exit(ixp4xx_spkr_exit);