2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2005-09-13 16:25:33 +08:00
|
|
|
* Touchscreen driver for Sharp SL-C7xx and SL-Cxx00 models
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Copyright (c) 2004-2005 Richard Purdie
|
|
|
|
*
|
|
|
|
* 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/delay.h>
|
2005-10-30 02:07:23 +08:00
|
|
|
#include <linux/platform_device.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/input.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/slab.h>
|
2006-07-02 05:32:15 +08:00
|
|
|
#include <linux/irq.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-13 16:25:33 +08:00
|
|
|
#include <asm/arch/sharpsl.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/arch/hardware.h>
|
|
|
|
#include <asm/arch/pxa-regs.h>
|
|
|
|
|
|
|
|
|
|
|
|
#define PWR_MODE_ACTIVE 0
|
|
|
|
#define PWR_MODE_SUSPEND 1
|
|
|
|
|
|
|
|
#define X_AXIS_MAX 3830
|
|
|
|
#define X_AXIS_MIN 150
|
|
|
|
#define Y_AXIS_MAX 3830
|
|
|
|
#define Y_AXIS_MIN 190
|
|
|
|
#define PRESSURE_MIN 0
|
|
|
|
#define PRESSURE_MAX 15000
|
|
|
|
|
|
|
|
struct ts_event {
|
|
|
|
short pressure;
|
|
|
|
short x;
|
|
|
|
short y;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct corgi_ts {
|
2005-09-15 15:01:46 +08:00
|
|
|
struct input_dev *input;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct timer_list timer;
|
|
|
|
struct ts_event tc;
|
|
|
|
int pendown;
|
|
|
|
int power_mode;
|
2005-09-13 16:25:33 +08:00
|
|
|
int irq_gpio;
|
|
|
|
struct corgits_machinfo *machinfo;
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2005-09-13 16:25:33 +08:00
|
|
|
#ifdef CONFIG_PXA25x
|
2005-04-17 06:20:36 +08:00
|
|
|
#define CCNT(a) asm volatile ("mrc p14, 0, %0, C1, C0, 0" : "=r"(a))
|
2005-09-07 06:19:01 +08:00
|
|
|
#define PMNC_GET(x) asm volatile ("mrc p14, 0, %0, C0, C0, 0" : "=r"(x))
|
|
|
|
#define PMNC_SET(x) asm volatile ("mcr p14, 0, %0, C0, C0, 0" : : "r"(x))
|
2005-09-13 16:25:33 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_PXA27x
|
|
|
|
#define CCNT(a) asm volatile ("mrc p14, 0, %0, C1, C1, 0" : "=r"(a))
|
|
|
|
#define PMNC_GET(x) asm volatile ("mrc p14, 0, %0, C0, C1, 0" : "=r"(x))
|
|
|
|
#define PMNC_SET(x) asm volatile ("mcr p14, 0, %0, C0, C1, 0" : : "r"(x))
|
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* ADS7846 Touch Screen Controller bit definitions */
|
|
|
|
#define ADSCTRL_PD0 (1u << 0) /* PD0 */
|
|
|
|
#define ADSCTRL_PD1 (1u << 1) /* PD1 */
|
|
|
|
#define ADSCTRL_DFR (1u << 2) /* SER/DFR */
|
|
|
|
#define ADSCTRL_MOD (1u << 3) /* Mode */
|
|
|
|
#define ADSCTRL_ADR_SH 4 /* Address setting */
|
|
|
|
#define ADSCTRL_STS (1u << 7) /* Start Bit */
|
|
|
|
|
|
|
|
/* External Functions */
|
|
|
|
extern unsigned int get_clk_frequency_khz(int info);
|
|
|
|
|
2005-09-13 16:25:33 +08:00
|
|
|
static unsigned long calc_waittime(struct corgi_ts *corgi_ts)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-09-13 16:25:33 +08:00
|
|
|
unsigned long hsync_len = corgi_ts->machinfo->get_hsync_len();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-07 06:19:05 +08:00
|
|
|
if (hsync_len)
|
|
|
|
return get_clk_frequency_khz(0)*1000/hsync_len;
|
|
|
|
else
|
2005-09-07 06:19:02 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-09-13 16:25:33 +08:00
|
|
|
static int sync_receive_data_send_cmd(struct corgi_ts *corgi_ts, int doRecive, int doSend,
|
|
|
|
unsigned int address, unsigned long wait_time)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-09-07 06:19:01 +08:00
|
|
|
unsigned long timer1 = 0, timer2, pmnc = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
int pos = 0;
|
|
|
|
|
2005-09-07 06:19:02 +08:00
|
|
|
if (wait_time && doSend) {
|
2005-09-07 06:19:01 +08:00
|
|
|
PMNC_GET(pmnc);
|
|
|
|
if (!(pmnc & 0x01))
|
2005-09-07 06:19:02 +08:00
|
|
|
PMNC_SET(0x01);
|
2005-09-07 06:19:01 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* polling HSync */
|
2005-09-13 16:25:33 +08:00
|
|
|
corgi_ts->machinfo->wait_hsync();
|
2005-04-17 06:20:36 +08:00
|
|
|
/* get CCNT */
|
|
|
|
CCNT(timer1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doRecive)
|
|
|
|
pos = corgi_ssp_ads7846_get();
|
|
|
|
|
|
|
|
if (doSend) {
|
|
|
|
int cmd = ADSCTRL_PD0 | ADSCTRL_PD1 | (address << ADSCTRL_ADR_SH) | ADSCTRL_STS;
|
|
|
|
/* dummy command */
|
|
|
|
corgi_ssp_ads7846_put(cmd);
|
|
|
|
corgi_ssp_ads7846_get();
|
|
|
|
|
2005-09-07 06:19:02 +08:00
|
|
|
if (wait_time) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Wait after HSync */
|
|
|
|
CCNT(timer2);
|
|
|
|
if (timer2-timer1 > wait_time) {
|
2005-09-07 06:19:02 +08:00
|
|
|
/* too slow - timeout, try again */
|
2005-09-13 16:25:33 +08:00
|
|
|
corgi_ts->machinfo->wait_hsync();
|
2005-04-17 06:20:36 +08:00
|
|
|
/* get OSCR */
|
|
|
|
CCNT(timer1);
|
|
|
|
/* Wait after HSync */
|
|
|
|
CCNT(timer2);
|
|
|
|
}
|
|
|
|
while (timer2 - timer1 < wait_time)
|
|
|
|
CCNT(timer2);
|
|
|
|
}
|
|
|
|
corgi_ssp_ads7846_put(cmd);
|
2005-09-07 06:19:02 +08:00
|
|
|
if (wait_time && !(pmnc & 0x01))
|
2005-09-07 06:19:01 +08:00
|
|
|
PMNC_SET(pmnc);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int read_xydata(struct corgi_ts *corgi_ts)
|
|
|
|
{
|
|
|
|
unsigned int x, y, z1, z2;
|
|
|
|
unsigned long flags, wait_time;
|
|
|
|
|
|
|
|
/* critical section */
|
|
|
|
local_irq_save(flags);
|
|
|
|
corgi_ssp_ads7846_lock();
|
2005-09-13 16:25:33 +08:00
|
|
|
wait_time = calc_waittime(corgi_ts);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Y-axis */
|
2005-09-13 16:25:33 +08:00
|
|
|
sync_receive_data_send_cmd(corgi_ts, 0, 1, 1u, wait_time);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Y-axis */
|
2005-09-13 16:25:33 +08:00
|
|
|
sync_receive_data_send_cmd(corgi_ts, 1, 1, 1u, wait_time);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* X-axis */
|
2005-09-13 16:25:33 +08:00
|
|
|
y = sync_receive_data_send_cmd(corgi_ts, 1, 1, 5u, wait_time);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Z1 */
|
2005-09-13 16:25:33 +08:00
|
|
|
x = sync_receive_data_send_cmd(corgi_ts, 1, 1, 3u, wait_time);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Z2 */
|
2005-09-13 16:25:33 +08:00
|
|
|
z1 = sync_receive_data_send_cmd(corgi_ts, 1, 1, 4u, wait_time);
|
|
|
|
z2 = sync_receive_data_send_cmd(corgi_ts, 1, 0, 4u, wait_time);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Power-Down Enable */
|
|
|
|
corgi_ssp_ads7846_put((1u << ADSCTRL_ADR_SH) | ADSCTRL_STS);
|
|
|
|
corgi_ssp_ads7846_get();
|
|
|
|
|
|
|
|
corgi_ssp_ads7846_unlock();
|
|
|
|
local_irq_restore(flags);
|
|
|
|
|
|
|
|
if (x== 0 || y == 0 || z1 == 0 || (x * (z2 - z1) / z1) >= 15000) {
|
|
|
|
corgi_ts->tc.pressure = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
corgi_ts->tc.x = x;
|
|
|
|
corgi_ts->tc.y = y;
|
|
|
|
corgi_ts->tc.pressure = (x * (z2 - z1)) / z1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
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 21:55:46 +08:00
|
|
|
static void new_data(struct corgi_ts *corgi_ts)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (corgi_ts->power_mode != PWR_MODE_ACTIVE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!corgi_ts->tc.pressure && corgi_ts->pendown == 0)
|
|
|
|
return;
|
|
|
|
|
2005-09-15 15:01:46 +08:00
|
|
|
input_report_abs(corgi_ts->input, ABS_X, corgi_ts->tc.x);
|
|
|
|
input_report_abs(corgi_ts->input, ABS_Y, corgi_ts->tc.y);
|
|
|
|
input_report_abs(corgi_ts->input, ABS_PRESSURE, corgi_ts->tc.pressure);
|
|
|
|
input_report_key(corgi_ts->input, BTN_TOUCH, (corgi_ts->pendown != 0));
|
|
|
|
input_sync(corgi_ts->input);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
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 21:55:46 +08:00
|
|
|
static void ts_interrupt_main(struct corgi_ts *corgi_ts, int isTimer)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-09-13 16:25:33 +08:00
|
|
|
if ((GPLR(IRQ_TO_GPIO(corgi_ts->irq_gpio)) & GPIO_bit(IRQ_TO_GPIO(corgi_ts->irq_gpio))) == 0) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Disable Interrupt */
|
2005-09-13 16:25:33 +08:00
|
|
|
set_irq_type(corgi_ts->irq_gpio, IRQT_NOEDGE);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (read_xydata(corgi_ts)) {
|
|
|
|
corgi_ts->pendown = 1;
|
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 21:55:46 +08:00
|
|
|
new_data(corgi_ts);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
mod_timer(&corgi_ts->timer, jiffies + HZ / 100);
|
|
|
|
} else {
|
|
|
|
if (corgi_ts->pendown == 1 || corgi_ts->pendown == 2) {
|
|
|
|
mod_timer(&corgi_ts->timer, jiffies + HZ / 100);
|
|
|
|
corgi_ts->pendown++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (corgi_ts->pendown) {
|
|
|
|
corgi_ts->tc.pressure = 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 21:55:46 +08:00
|
|
|
new_data(corgi_ts);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable Falling Edge */
|
2005-09-13 16:25:33 +08:00
|
|
|
set_irq_type(corgi_ts->irq_gpio, IRQT_FALLING);
|
2005-04-17 06:20:36 +08:00
|
|
|
corgi_ts->pendown = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void corgi_ts_timer(unsigned long data)
|
|
|
|
{
|
|
|
|
struct corgi_ts *corgits_data = (struct corgi_ts *) data;
|
2006-10-15 20:50:02 +08:00
|
|
|
ts_interrupt_main(corgits_data, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
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 21:55:46 +08:00
|
|
|
static irqreturn_t ts_interrupt(int irq, void *dev_id)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct corgi_ts *corgits_data = dev_id;
|
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 21:55:46 +08:00
|
|
|
ts_interrupt_main(corgits_data, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
2005-11-10 06:32:44 +08:00
|
|
|
static int corgits_suspend(struct platform_device *dev, pm_message_t state)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-10 06:32:44 +08:00
|
|
|
struct corgi_ts *corgi_ts = platform_get_drvdata(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-10-29 00:52:56 +08:00
|
|
|
if (corgi_ts->pendown) {
|
|
|
|
del_timer_sync(&corgi_ts->timer);
|
|
|
|
corgi_ts->tc.pressure = 0;
|
2006-10-15 20:50:02 +08:00
|
|
|
new_data(corgi_ts);
|
2005-10-29 00:52:56 +08:00
|
|
|
corgi_ts->pendown = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2005-10-29 00:52:56 +08:00
|
|
|
corgi_ts->power_mode = PWR_MODE_SUSPEND;
|
|
|
|
|
|
|
|
corgi_ssp_ads7846_putget((1u << ADSCTRL_ADR_SH) | ADSCTRL_STS);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-10 06:32:44 +08:00
|
|
|
static int corgits_resume(struct platform_device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-10 06:32:44 +08:00
|
|
|
struct corgi_ts *corgi_ts = platform_get_drvdata(dev);
|
2005-10-29 00:52:56 +08:00
|
|
|
|
|
|
|
corgi_ssp_ads7846_putget((4u << ADSCTRL_ADR_SH) | ADSCTRL_STS);
|
|
|
|
/* Enable Falling Edge */
|
|
|
|
set_irq_type(corgi_ts->irq_gpio, IRQT_FALLING);
|
|
|
|
corgi_ts->power_mode = PWR_MODE_ACTIVE;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define corgits_suspend NULL
|
|
|
|
#define corgits_resume NULL
|
|
|
|
#endif
|
|
|
|
|
2005-11-10 06:32:44 +08:00
|
|
|
static int __init corgits_probe(struct platform_device *pdev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct corgi_ts *corgi_ts;
|
2005-09-15 15:01:46 +08:00
|
|
|
struct input_dev *input_dev;
|
|
|
|
int err = -ENOMEM;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-15 15:01:46 +08:00
|
|
|
corgi_ts = kzalloc(sizeof(struct corgi_ts), GFP_KERNEL);
|
|
|
|
input_dev = input_allocate_device();
|
|
|
|
if (!corgi_ts || !input_dev)
|
|
|
|
goto fail;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-10 06:32:44 +08:00
|
|
|
platform_set_drvdata(pdev, corgi_ts);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-10 06:32:44 +08:00
|
|
|
corgi_ts->machinfo = pdev->dev.platform_data;
|
2005-09-13 16:25:33 +08:00
|
|
|
corgi_ts->irq_gpio = platform_get_irq(pdev, 0);
|
|
|
|
|
|
|
|
if (corgi_ts->irq_gpio < 0) {
|
2005-09-15 15:01:46 +08:00
|
|
|
err = -ENODEV;
|
|
|
|
goto fail;
|
2005-09-13 16:25:33 +08:00
|
|
|
}
|
|
|
|
|
2005-09-15 15:01:46 +08:00
|
|
|
corgi_ts->input = input_dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-15 15:01:46 +08:00
|
|
|
init_timer(&corgi_ts->timer);
|
|
|
|
corgi_ts->timer.data = (unsigned long) corgi_ts;
|
|
|
|
corgi_ts->timer.function = corgi_ts_timer;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-15 15:01:46 +08:00
|
|
|
input_dev->name = "Corgi Touchscreen";
|
|
|
|
input_dev->phys = "corgits/input0";
|
|
|
|
input_dev->id.bustype = BUS_HOST;
|
|
|
|
input_dev->id.vendor = 0x0001;
|
|
|
|
input_dev->id.product = 0x0002;
|
|
|
|
input_dev->id.version = 0x0100;
|
2005-11-10 06:32:44 +08:00
|
|
|
input_dev->cdev.dev = &pdev->dev;
|
2005-09-15 15:01:46 +08:00
|
|
|
input_dev->private = corgi_ts;
|
|
|
|
|
|
|
|
input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
|
|
|
|
input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
|
|
|
|
input_set_abs_params(input_dev, ABS_X, X_AXIS_MIN, X_AXIS_MAX, 0, 0);
|
|
|
|
input_set_abs_params(input_dev, ABS_Y, Y_AXIS_MIN, Y_AXIS_MAX, 0, 0);
|
|
|
|
input_set_abs_params(input_dev, ABS_PRESSURE, PRESSURE_MIN, PRESSURE_MAX, 0, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-13 16:25:33 +08:00
|
|
|
pxa_gpio_mode(IRQ_TO_GPIO(corgi_ts->irq_gpio) | GPIO_IN);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Initiaize ADS7846 Difference Reference mode */
|
|
|
|
corgi_ssp_ads7846_putget((1u << ADSCTRL_ADR_SH) | ADSCTRL_STS);
|
|
|
|
mdelay(5);
|
|
|
|
corgi_ssp_ads7846_putget((3u << ADSCTRL_ADR_SH) | ADSCTRL_STS);
|
|
|
|
mdelay(5);
|
|
|
|
corgi_ssp_ads7846_putget((4u << ADSCTRL_ADR_SH) | ADSCTRL_STS);
|
|
|
|
mdelay(5);
|
|
|
|
corgi_ssp_ads7846_putget((5u << ADSCTRL_ADR_SH) | ADSCTRL_STS);
|
|
|
|
mdelay(5);
|
|
|
|
|
2006-07-02 10:29:38 +08:00
|
|
|
if (request_irq(corgi_ts->irq_gpio, ts_interrupt, IRQF_DISABLED, "ts", corgi_ts)) {
|
2005-09-15 15:01:46 +08:00
|
|
|
err = -EBUSY;
|
|
|
|
goto fail;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-09-15 15:01:46 +08:00
|
|
|
input_register_device(corgi_ts->input);
|
|
|
|
|
|
|
|
corgi_ts->power_mode = PWR_MODE_ACTIVE;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Enable Falling Edge */
|
2005-09-13 16:25:33 +08:00
|
|
|
set_irq_type(corgi_ts->irq_gpio, IRQT_FALLING);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
2005-09-15 15:01:46 +08:00
|
|
|
|
|
|
|
fail: input_free_device(input_dev);
|
|
|
|
kfree(corgi_ts);
|
|
|
|
return err;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-11-10 06:32:44 +08:00
|
|
|
static int corgits_remove(struct platform_device *pdev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-10 06:32:44 +08:00
|
|
|
struct corgi_ts *corgi_ts = platform_get_drvdata(pdev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-13 16:25:33 +08:00
|
|
|
free_irq(corgi_ts->irq_gpio, NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
del_timer_sync(&corgi_ts->timer);
|
2005-09-13 16:25:33 +08:00
|
|
|
corgi_ts->machinfo->put_hsync();
|
2005-09-15 15:01:46 +08:00
|
|
|
input_unregister_device(corgi_ts->input);
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree(corgi_ts);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-10 06:32:44 +08:00
|
|
|
static struct platform_driver corgits_driver = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.probe = corgits_probe,
|
|
|
|
.remove = corgits_remove,
|
|
|
|
.suspend = corgits_suspend,
|
|
|
|
.resume = corgits_resume,
|
2005-11-10 06:32:44 +08:00
|
|
|
.driver = {
|
|
|
|
.name = "corgi-ts",
|
|
|
|
},
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __devinit corgits_init(void)
|
|
|
|
{
|
2005-11-10 06:32:44 +08:00
|
|
|
return platform_driver_register(&corgits_driver);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit corgits_exit(void)
|
|
|
|
{
|
2005-11-10 06:32:44 +08:00
|
|
|
platform_driver_unregister(&corgits_driver);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(corgits_init);
|
|
|
|
module_exit(corgits_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
|
|
|
|
MODULE_DESCRIPTION("Corgi TouchScreen Driver");
|
|
|
|
MODULE_LICENSE("GPL");
|