分类: LINUX
2009-07-16 22:51:51
转载来源:http://blog.163.com/yuan_xihua/blog/static/30740544200811832630293/
针对本人运行环境,稍作修改.
本人移植环境:
主机:Red.Hat.9.0(完全安装)
交叉编译器:arm-linux-gcc-3.4.1
开发板平台:S3C2440(GEC-2440开发板)
目标板linux内核版本:26.24.4 / 目标板bootloader :u-boot 1.2
添加touchscreen驱动到基于linux-
1, 修改drivers/input/touchscreen/Makefile文件
# vi drivers/input/touchscreen/Makefile
添加:
obj-$(CONFIG_TOUCHSCREEN_S
2, 修改drivers/input/touchscreen/Kconfig文件
# vi drivers/input/touchscreen/Kconfig
添加:
config TOUCHSCREEN_S
tristate "Samsung S
depends on ARCH_SMDK2410 && INPUT && INPUT_TOUCHSCREEN
select SERIO
help
Say Y here if you have the s
If unsure, say N.
To compile this driver as a module, choose M here: the
module will be called s
config TOUCHSCREEN_S
boolean "Samsung S
depends on TOUCHSCREEN_S
help
Select this if you want debug messages
3,编译配置内核
# make menuconfig
进入配置菜单添加驱动到内核:
Device Drivers --->
Input device support --->
[*] Touchscreens --->
<*> Samsung S
[*] Samsung S
4,修改arch/arm/mach-s
# vi arch/arm/mach-s
添加:
static struct s
.delay = 10000,
.presc = 49,
.oversampling_shift = 2,
};
在static struct platform_device *smdk2410_devices[] __initdata = {结构中添加:
&s
在static void __init smdk2410_map_io(void)函数中添加:
s
5,修改include/asm-arm/plat-s
# vi include/asm-arm/plat-s
添加:
struct s
int delay;
int presc;
int oversampling_shift;
};
void __init s
extern struct platform_device s
6,修改arch/arm/plat-s
# vi arch/arm/plat-s
添加:
// Touchscreen
static struct s
void __init s
{
memcpy(&s
}
EXPORT_SYMBOL(s
struct platform_device s
.name = "s
.id = -1,
.num_resources = ARRAY_SIZE(s
.resource = s
.dev = {
.platform_data = &s
}
};
EXPORT_SYMBOL(s
7,添加drivers/input/touchscreen/s
# vi drivers/input/touchscreen/s
添加的源码见附件。
8,编译内核生成驱动
# make
9,在内核启动可以看到input: s
注册信息为:
# cat /proc/bus/input/devices
I: Bus=0019 Vendor=0001 Product=0002 Version=0100
N: Name="s
P: Phys=s
S: Sysfs=/class/input/input0
U: Uniq=
H: Handlers=mouse0 event0
B: EV=b
B: KEY=400 0 0 0 0 0 0 0 0 0 0
B: ABS=1000003
设备结点为:
# ll /dev/
crw-rw---- 1 root root 13, 64 Dec 10 2008 event0
crw-rw---- 1 root root 13, 32 Dec 7 2008 mouse0
编译移植成功后,可以使用 tslib 进行测试---->请看下篇<
附件:
/* drivers/input/touchscreen/s3c2410_ts.c
*
* Touchscreen driver for GEC2440 with Samsung S3C2440A
*
* modify from corgi_ts.c
*
* 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
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define WAIT4INT(x) (((x)<<8) | \
S3C2410_ADCTSC_YM_SEN | S3C2410_ADCTSC_YP_SEN | S3C2410_ADCTSC_XP_SEN | \
S3C2410_ADCTSC_XY_PST(3))
#define AUTOPST (S3C2410_ADCTSC_YM_SEN | S3C2410_ADCTSC_YP_SEN | S3C2410_ADCTSC_XP_SEN | \
S3C2410_ADCTSC_AUTO_PST | S3C2410_ADCTSC_XY_PST(0))
#define DEBUG_LVL KERN_DEBUG
#define X_AXIS_MAX 0x3ff
#define X_AXIS_MIN 0
#define Y_AXIS_MAX 0x3ff
#define Y_AXIS_MIN 0
#define PRESSURE_MIN 0
#define PRESSURE_MAX 1
/*
* Definitions & global arrays.
*/
/*
* Per-touchscreen data.
*/
struct ts_event {
short pressure;
short xp;
short yp;
};
struct s3c2410_ts {
struct input_dev *input;
struct resource *res;
struct timer_list timer;
struct ts_event tc;
int pendown;
int count;
int shift;
struct resource *irq_gpio[2];
struct s3c2410_ts_mach_info *machinfo;
};
static void __iomem *base_addr;
static inline void s3c2410_ts_connect(void)
{
s3c2410_gpio_cfgpin(S3C2410_GPG12, S3C2410_GPG12_XMON);
s3c2410_gpio_cfgpin(S3C2410_GPG13, S3C2410_GPG13_nXPON);
s3c2410_gpio_cfgpin(S3C2410_GPG14, S3C2410_GPG14_YMON);
s3c2410_gpio_cfgpin(S3C2410_GPG15, S3C2410_GPG15_nYPON);
}
static void touch_timer_fire(struct s3c2410_ts *s3c2410_ts,unsigned long data)
{
unsigned long data0;
unsigned long data1;
struct input_dev *dev = s3c2410_ts->input;
/* Disable Interrupt */
set_irq_type(s3c2410_ts->irq_gpio[0]->start, IRQT_NOEDGE);
set_irq_type(s3c2410_ts->irq_gpio[1]->start, IRQT_NOEDGE);
data0 = readl(base_addr+S3C2410_ADCDAT0);
data1 = readl(base_addr+S3C2410_ADCDAT1);
s3c2410_ts->pendown = (!(data0 & S3C2410_ADCDAT0_UPDOWN)) && (!(data1 & S3C2410_ADCDAT0_UPDOWN));
if (s3c2410_ts->pendown) {
if (s3c2410_ts->count != 0) {
s3c2410_ts->tc.xp >>= s3c2410_ts->shift;
s3c2410_ts->tc.yp >>= s3c2410_ts->shift;
#ifdef CONFIG_TOUCHSCREEN_S3C2410_DEBUG
{
struct timeval tv;
do_gettimeofday(&tv);
printk(KERN_INFO "T: %06d, X: %03x, Y: %03x\n", (int)tv.tv_usec, s3c2410_ts->tc.xp, s3c2410_ts->tc.yp);
}
#endif
input_report_abs(dev, ABS_X, s3c2410_ts->tc.xp);
input_report_abs(dev, ABS_Y, s3c2410_ts->tc.yp);
input_report_abs(dev, ABS_PRESSURE, s3c2410_ts->tc.pressure);
input_report_key(dev, BTN_TOUCH, s3c2410_ts->pendown);
input_sync(dev);
}
s3c2410_ts->tc.xp = 0;
s3c2410_ts->tc.yp = 0;
s3c2410_ts->count = 0;
s3c2410_ts->tc.pressure = 0;
writel(S3C2410_ADCTSC_PULL_UP_DISABLE | AUTOPST, base_addr+S3C2410_ADCTSC);
writel(readl(base_addr+S3C2410_ADCCON) | S3C2410_ADCCON_ENABLE_START, base_addr+S3C2410_ADCCON);
} else {
s3c2410_ts->count = 0;
input_report_key(dev, BTN_TOUCH, 0);
input_report_abs(dev, ABS_PRESSURE, 0);
input_sync(dev);
writel(WAIT4INT(0), base_addr+S3C2410_ADCTSC);
}
/* Enable Falling Edge */
set_irq_type(s3c2410_ts->irq_gpio[0]->start, IRQT_BOTHEDGE);
set_irq_type(s3c2410_ts->irq_gpio[1]->start, IRQT_BOTHEDGE);
}
static void s3c2410_ts_timer(unsigned long data)
{
struct s3c2410_ts *s3c2410ts_data = (struct s3c2410_ts *) data;
touch_timer_fire(s3c2410ts_data, 1);
}
static irqreturn_t stylus_updown(int irq, void *dev_id, struct pt_regs *regs)
{
unsigned long data0;
unsigned long data1;
struct s3c2410_ts *s3c2410_ts = dev_id;
#ifdef CONFIG_TOUCHSCREEN_S3C2410_DEBUG
printk(KERN_ERR "%s() No.%d line:\n\r",__FUNCTION__,__LINE__);
#endif
data0 = readl(base_addr+S3C2410_ADCDAT0);
data1 = readl(base_addr+S3C2410_ADCDAT1);
s3c2410_ts->pendown = (!(data0 & S3C2410_ADCDAT0_UPDOWN)) && (!(data1 & S3C2410_ADCDAT1_UPDOWN));
/* TODO we should never get an interrupt with updown set while
* the timer is running, but maybe we ought to verify that the
* timer isn't running anyways. */
if (s3c2410_ts->pendown)
touch_timer_fire(s3c2410_ts, 0);
return IRQ_HANDLED;
}
static irqreturn_t stylus_action(int irq, void *dev_id, struct pt_regs *regs)
{
unsigned long data0;
unsigned long data1;
struct s3c2410_ts *s3c2410_ts = dev_id;
#ifdef CONFIG_TOUCHSCREEN_S3C2410_DEBUG
printk(KERN_ERR "%s() No.%d line:\n\r",__FUNCTION__,__LINE__);
#endif
data0 = readl(base_addr+S3C2410_ADCDAT0);
data1 = readl(base_addr+S3C2410_ADCDAT1);
/*修改处,因为在QT上运行时出现X轴,Y轴掉转,且方向相反,修改了下面X,Y的读取值,源码请看原创!!其实出现这种情况还有一种修改的方法,就是修改QT的源文件,因为QT的坐标读取有问题,所以也可以直接修改QT的QCustomTPanelHandlerPrivate::readMouseData(),具体修改方法可参考网上博客*/
s3c2410_ts->tc.xp += (S3C2410_ADCDAT1_YPDATA_MASK-data1) & S3C2410_ADCDAT1_YPDATA_MASK;
s3c2410_ts->tc.yp += (S3C2410_ADCDAT0_XPDATA_MASK-data0) & S3C2410_ADCDAT0_XPDATA_MASK;
s3c2410_ts->count++;
s3c2410_ts->tc.pressure = 1;
if (s3c2410_ts->count < (1<
writel(S3C2410_ADCTSC_PULL_UP_DISABLE | AUTOPST, base_addr+S3C2410_ADCTSC);
writel(readl(base_addr+S3C2410_ADCCON) | S3C2410_ADCCON_ENABLE_START, base_addr+S3C2410_ADCCON);
} else {
mod_timer(&s3c2410_ts->timer, jiffies + HZ / 100);
writel(WAIT4INT(1), base_addr+S3C2410_ADCTSC);
}
return IRQ_HANDLED;
}
static struct clk *adc_clock;
/*
* The functions for inserting/removing us as a module.
*/
#define s3c2410ts_suspend NULL
#define s3c2410ts_resume NULL
static int __init s3c2410ts_probe(struct platform_device *pdev)
{
struct s3c2410_ts *s3c2410_ts;
struct input_dev *input_dev;
int size;
int err = -ENOMEM;
s3c2410_ts = kzalloc(sizeof(struct s3c2410_ts), GFP_KERNEL);
input_dev = input_allocate_device();
if (!s3c2410_ts || !input_dev)
goto fail1;
platform_set_drvdata(pdev, s3c2410_ts);
s3c2410_ts->machinfo = pdev->dev.platform_data;
s3c2410_ts->irq_gpio[0] = platform_get_resource(pdev, IORESOURCE_IRQ,0);
s3c2410_ts->irq_gpio[1] = platform_get_resource(pdev, IORESOURCE_IRQ,1);
#ifdef CONFIG_TOUCHSCREEN_S3C2410_DEBUG
printk(KERN_ERR "s3c2410_ts->irq_gpio[0] = %d,IRQ_TC = %d\n",s3c2410_ts->irq_gpio[0]->start,IRQ_TC);
printk(KERN_ERR "s3c2410_ts->irq_gpio[1] = %d,IRQ_ADC = %d\n",s3c2410_ts->irq_gpio[1]->start,IRQ_ADC);
#endif
if ((s3c2410_ts->irq_gpio[0]->start < 0)|(s3c2410_ts->irq_gpio[1]->start < 0)) {
err = -ENODEV;
printk(KERN_ERR "Hm... too bad : no irq for ts\n");
goto fail1;
}
if (!s3c2410_ts->machinfo)
{
printk(KERN_ERR "Hm... too bad : no platform data for ts\n");
return -EINVAL;
}
s3c2410_ts->res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (s3c2410_ts->res == NULL) {
printk(KERN_ERR "no memory resource specified\n");
return -ENOENT;
}
adc_clock = clk_get(NULL, "adc");
if (!adc_clock) {
printk(KERN_ERR "failed to get adc clock source\n");
return -ENOENT;
}
clk_enable(adc_clock);
size = (s3c2410_ts->res->end-s3c2410_ts->res->start)+1;
base_addr=ioremap(s3c2410_ts->res->start, size);
#ifdef CONFIG_TOUCHSCREEN_S3C2410_DEBUG
printk(KERN_ERR "ioremap %08x to base_addr=%08x , size=%08x\n",s3c2410_ts->res->start,(unsigned int)base_addr,size);
#endif
if (base_addr == NULL) {
printk(KERN_ERR "Failed to remap register block\n");
return -ENOMEM;
}
/* Configure GPIOs */
s3c2410_ts_connect();
#ifdef CONFIG_TOUCHSCREEN_S3C2410_DEBUG
printk(KERN_ERR "s3c2410_ts->machinfo delay = %d,presc = %d,oversampling_shift = %d\n",
s3c2410_ts->machinfo->delay,
s3c2410_ts->machinfo->presc,
s3c2410_ts->machinfo->oversampling_shift);
#endif
if ((s3c2410_ts->machinfo->presc&0xff) > 0)
writel(S3C2410_ADCCON_PRSCEN | S3C2410_ADCCON_PRSCVL(s3c2410_ts->machinfo->presc&0xFF),\
base_addr+S3C2410_ADCCON);
else
writel(0,base_addr+S3C2410_ADCCON);
/* Initialise the adcdly registers */
if ((s3c2410_ts->machinfo->delay&0xffff) > 0)
writel(s3c2410_ts->machinfo->delay & 0xffff, base_addr+S3C2410_ADCDLY);
writel(WAIT4INT(0), base_addr+S3C2410_ADCTSC);
__raw_writel(__raw_readl(S3C2410_GPGCON)|(0xff<<24), S3C2410_GPGCON);
s3c2410_ts->input = input_dev;
init_timer(&s3c2410_ts->timer);
s3c2410_ts->timer.data = (unsigned long) s3c2410_ts;
s3c2410_ts->timer.function = s3c2410_ts_timer;
// input_dev->private = s3c2410_ts;
input_dev->name = "s3c2410 Touchscreen";
input_dev->phys = "s3c2410ts/input0";
input_dev->id.bustype = BUS_HOST;
input_dev->id.vendor = 0x0001;
input_dev->id.product = 0x0002;
input_dev->id.version = 0x0100;
// input_dev->dev.parent = &pdev->dev;
s3c2410_ts->shift = s3c2410_ts->machinfo->oversampling_shift;
input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(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);
/* Get irqs */
if (request_irq(s3c2410_ts->irq_gpio[1]->start, stylus_action, IRQF_DISABLED, pdev->name, s3c2410_ts)) {
printk(KERN_ERR "s3c2410_ts.c: Could not allocate ts IRQ_ADC !\n");
iounmap(base_addr);
err = -EBUSY;
goto fail1;
}
if (request_irq(s3c2410_ts->irq_gpio[0]->start, stylus_updown, IRQF_DISABLED, pdev->name, s3c2410_ts)) {
printk(KERN_ERR "s3c2410_ts.c: Could not allocate ts IRQ_TC !\n");
iounmap(base_addr);
err = -EBUSY;
goto fail1;
}
/* All went ok, so register to the input system */
err = input_register_device(s3c2410_ts->input);
if (err)
goto fail2;
/* Enable Falling Edge */
set_irq_type(s3c2410_ts->irq_gpio[0]->start, IRQT_BOTHEDGE);
set_irq_type(s3c2410_ts->irq_gpio[1]->start, IRQT_BOTHEDGE);
return 0;
fail2: free_irq(s3c2410_ts->irq_gpio, s3c2410_ts);
fail1: input_free_device(input_dev);
kfree(s3c2410_ts);
return err;
}
static int s3c2410ts_remove(struct platform_device *pdev)
{
struct s3c2410_ts *s3c2410_ts = platform_get_drvdata(pdev);
disable_irq(s3c2410_ts->irq_gpio[0]->start);
disable_irq(s3c2410_ts->irq_gpio[1]->start);
free_irq(s3c2410_ts->irq_gpio[0]->start,s3c2410_ts);
free_irq(s3c2410_ts->irq_gpio[1]->start,s3c2410_ts);
del_timer_sync(&s3c2410_ts->timer);
if (adc_clock) {
clk_disable(adc_clock);
clk_put(adc_clock);
adc_clock = NULL;
}
input_unregister_device(s3c2410_ts->input);
iounmap(base_addr);
kfree(s3c2410_ts);
return 0;
}
static struct platform_driver s3c2410ts_driver = {
.probe = s3c2410ts_probe,
.remove = s3c2410ts_remove,
.suspend = s3c2410ts_suspend,
.resume = s3c2410ts_resume,
.driver = {
.name = "s3c2410-ts",
.owner = THIS_MODULE,
},
};
static int __devinit s3c2410ts_init(void)
{
return platform_driver_register(&s3c2410ts_driver);
}
static void __exit s3c2410ts_exit(void)
{
platform_driver_unregister(&s3c2410ts_driver);
}
module_init(s3c2410ts_init);
module_exit(s3c2410ts_exit);
MODULE_AUTHOR("9g2440");
MODULE_DESCRIPTION("s3c2440 TouchScreen Driver");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:s3c2410-ts");