2006-01-30 09:50:40 +07:00
|
|
|
/*
|
|
|
|
* Generic IXP4xx beeper driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Tower Technologies
|
|
|
|
*
|
|
|
|
* based on nslu2-io.c
|
|
|
|
* Copyright (C) 2004 Karen Spearel
|
|
|
|
*
|
|
|
|
* Author: Alessandro Zummo <a.zummo@towertech.it>
|
|
|
|
* Maintainers: http://www.nslu2-linux.org/
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/input.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/platform_device.h>
|
2006-02-15 12:48:40 +07:00
|
|
|
#include <linux/interrupt.h>
|
2013-09-10 17:53:03 +07:00
|
|
|
#include <linux/gpio.h>
|
2008-08-05 22:14:15 +07:00
|
|
|
#include <mach/hardware.h>
|
2006-01-30 09:50:40 +07:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
|
|
|
|
MODULE_DESCRIPTION("ixp4xx beeper driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
2008-03-29 04:15:59 +07:00
|
|
|
MODULE_ALIAS("platform:ixp4xx-beeper");
|
2006-01-30 09:50:40 +07:00
|
|
|
|
|
|
|
static DEFINE_SPINLOCK(beep_lock);
|
|
|
|
|
|
|
|
static void ixp4xx_spkr_control(unsigned int pin, unsigned int count)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&beep_lock, flags);
|
|
|
|
|
2013-09-10 17:53:03 +07:00
|
|
|
if (count) {
|
|
|
|
gpio_direction_output(pin, 0);
|
2006-01-30 09:50:40 +07:00
|
|
|
*IXP4XX_OSRT2 = (count & ~IXP4XX_OST_RELOAD_MASK) | IXP4XX_OST_ENABLE;
|
|
|
|
} else {
|
2013-09-10 17:53:03 +07:00
|
|
|
gpio_direction_output(pin, 1);
|
|
|
|
gpio_direction_input(pin);
|
2006-01-30 09:50:40 +07:00
|
|
|
*IXP4XX_OSRT2 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&beep_lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ixp4xx_spkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
|
|
|
|
{
|
2007-05-11 01:51:08 +07:00
|
|
|
unsigned int pin = (unsigned int) input_get_drvdata(dev);
|
2006-01-30 09:50:40 +07:00
|
|
|
unsigned int count = 0;
|
|
|
|
|
|
|
|
if (type != EV_SND)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
case SND_BELL:
|
|
|
|
if (value)
|
|
|
|
value = 1000;
|
|
|
|
case SND_TONE:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value > 20 && value < 32767)
|
2013-11-26 21:19:04 +07:00
|
|
|
count = (ixp4xx_timer_freq / (value * 4)) - 1;
|
2006-01-30 09:50:40 +07:00
|
|
|
|
|
|
|
ixp4xx_spkr_control(pin, count);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 20:55:46 +07:00
|
|
|
static irqreturn_t ixp4xx_spkr_interrupt(int irq, void *dev_id)
|
2006-01-30 09:50:40 +07:00
|
|
|
{
|
2013-09-10 18:06:57 +07:00
|
|
|
unsigned int pin = (unsigned int) dev_id;
|
|
|
|
|
2006-01-30 09:50:40 +07:00
|
|
|
/* clear interrupt */
|
|
|
|
*IXP4XX_OSST = IXP4XX_OSST_TIMER_2_PEND;
|
|
|
|
|
|
|
|
/* flip the beeper output */
|
2013-09-10 18:06:57 +07:00
|
|
|
gpio_set_value(pin, !gpio_get_value(pin));
|
2006-01-30 09:50:40 +07:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2012-11-24 12:38:25 +07:00
|
|
|
static int ixp4xx_spkr_probe(struct platform_device *dev)
|
2006-01-30 09:50:40 +07:00
|
|
|
{
|
|
|
|
struct input_dev *input_dev;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
input_dev = input_allocate_device();
|
|
|
|
if (!input_dev)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2007-04-12 12:34:33 +07:00
|
|
|
input_set_drvdata(input_dev, (void *) dev->id);
|
|
|
|
|
2006-01-30 09:50:40 +07:00
|
|
|
input_dev->name = "ixp4xx beeper",
|
|
|
|
input_dev->phys = "ixp4xx/gpio";
|
|
|
|
input_dev->id.bustype = BUS_HOST;
|
|
|
|
input_dev->id.vendor = 0x001f;
|
|
|
|
input_dev->id.product = 0x0001;
|
|
|
|
input_dev->id.version = 0x0100;
|
2007-04-12 12:35:32 +07:00
|
|
|
input_dev->dev.parent = &dev->dev;
|
2006-01-30 09:50:40 +07:00
|
|
|
|
2007-10-19 13:40:32 +07:00
|
|
|
input_dev->evbit[0] = BIT_MASK(EV_SND);
|
|
|
|
input_dev->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE);
|
2006-01-30 09:50:40 +07:00
|
|
|
input_dev->event = ixp4xx_spkr_event;
|
|
|
|
|
2013-09-10 18:06:57 +07:00
|
|
|
err = gpio_request(dev->id, "ixp4-beeper");
|
|
|
|
if (err)
|
|
|
|
goto err_free_device;
|
|
|
|
|
2006-01-30 09:50:40 +07:00
|
|
|
err = request_irq(IRQ_IXP4XX_TIMER2, &ixp4xx_spkr_interrupt,
|
2011-09-08 04:04:16 +07:00
|
|
|
IRQF_NO_SUSPEND, "ixp4xx-beeper",
|
2010-07-29 17:16:33 +07:00
|
|
|
(void *) dev->id);
|
2006-01-30 09:50:40 +07:00
|
|
|
if (err)
|
2013-09-10 18:06:57 +07:00
|
|
|
goto err_free_gpio;
|
2006-01-30 09:50:40 +07:00
|
|
|
|
|
|
|
err = input_register_device(input_dev);
|
|
|
|
if (err)
|
|
|
|
goto err_free_irq;
|
|
|
|
|
|
|
|
platform_set_drvdata(dev, input_dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_free_irq:
|
2013-05-23 23:30:15 +07:00
|
|
|
free_irq(IRQ_IXP4XX_TIMER2, (void *)dev->id);
|
2013-09-10 18:06:57 +07:00
|
|
|
err_free_gpio:
|
|
|
|
gpio_free(dev->id);
|
2006-01-30 09:50:40 +07:00
|
|
|
err_free_device:
|
|
|
|
input_free_device(input_dev);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2012-11-24 12:50:47 +07:00
|
|
|
static int ixp4xx_spkr_remove(struct platform_device *dev)
|
2006-01-30 09:50:40 +07:00
|
|
|
{
|
|
|
|
struct input_dev *input_dev = platform_get_drvdata(dev);
|
2007-04-12 12:34:33 +07:00
|
|
|
unsigned int pin = (unsigned int) input_get_drvdata(input_dev);
|
2006-01-30 09:50:40 +07:00
|
|
|
|
|
|
|
input_unregister_device(input_dev);
|
|
|
|
|
|
|
|
/* turn the speaker off */
|
|
|
|
disable_irq(IRQ_IXP4XX_TIMER2);
|
|
|
|
ixp4xx_spkr_control(pin, 0);
|
|
|
|
|
2013-05-23 23:30:15 +07:00
|
|
|
free_irq(IRQ_IXP4XX_TIMER2, (void *)dev->id);
|
2013-09-10 18:06:57 +07:00
|
|
|
gpio_free(dev->id);
|
2006-01-30 09:50:40 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ixp4xx_spkr_shutdown(struct platform_device *dev)
|
|
|
|
{
|
|
|
|
struct input_dev *input_dev = platform_get_drvdata(dev);
|
2007-04-12 12:34:33 +07:00
|
|
|
unsigned int pin = (unsigned int) input_get_drvdata(input_dev);
|
2006-01-30 09:50:40 +07:00
|
|
|
|
|
|
|
/* turn off the speaker */
|
|
|
|
disable_irq(IRQ_IXP4XX_TIMER2);
|
|
|
|
ixp4xx_spkr_control(pin, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver ixp4xx_spkr_platform_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "ixp4xx-beeper",
|
|
|
|
},
|
|
|
|
.probe = ixp4xx_spkr_probe,
|
2012-11-24 12:27:39 +07:00
|
|
|
.remove = ixp4xx_spkr_remove,
|
2006-01-30 09:50:40 +07:00
|
|
|
.shutdown = ixp4xx_spkr_shutdown,
|
|
|
|
};
|
2011-11-30 02:08:40 +07:00
|
|
|
module_platform_driver(ixp4xx_spkr_platform_driver);
|
2006-01-30 09:50:40 +07:00
|
|
|
|