Chinaunix首页 | 论坛 | 博客
  • 博客访问: 278375
  • 博文数量: 91
  • 博客积分: 2105
  • 博客等级: 大尉
  • 技术积分: 1050
  • 用 户 组: 普通用户
  • 注册时间: 2009-09-14 19:30
文章分类
文章存档

2011年(11)

2010年(64)

2009年(16)

我的朋友

分类: LINUX

2010-07-08 20:45:47

AR1020触摸屏驱动终于好了,最近一直在调linux下的一个小问题,问题是这样的,就是在点屏的时候,发现会在第五个时钟周期内,出现中断,导致死在那里,要过十秒钟左右才能点屏,后来发现修改寄存器的偏址0x11的那个寄存器,为他加个延时就好了,修改寄存器的地方,又发现一个问题,就是不进中断,后来用逻辑分析仪发现,spi的波特率要配置好,太大了会导致不能触发中断,太小又不能在一个时钟周期里包含中断,最后也是用逻辑分析仪解决这个问题,版本提交了,具体的驱动列出来只为交流学习,不为别的。
/* linux/drivers/input/touchscreen/sep0718_ts.c
 *  
 *
*  Copyright (C) 2010 SEU ASIC.
 *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
 *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
 *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
*/



#include

#include
#include
#include
#include

#include


#include
#include
#include
#include
#include
#include
#include
#include

#include
#include
#include
#include

#include
#include
#include
#include
#include

#include
#include
/* For ts->dev.id.version */
#define SEP_TSVERSION 0x0101

void __iomem  *base;

#define PEN_TIMER_DELAY_JUDGE           2// judge whether the pendown message is a true pendown     jiffes
#define PEN_TIMER_DELAY_LONGTOUCH       1// judge whether the pendown message is a long-time touch  jiffes


struct sep_ts
{
struct input_dev *dev;
    unsigned short zp;
    unsigned short xp;
    unsigned short yp;
    struct timer_list ts_timer;
};

struct sep_ts *ts;//触摸屏结构体



  unsigned short  SendCommand  (unsigned short ADCommand)
{
int data = 0;

*(volatile unsigned long*)(base + SEP0718_DR)=ADCommand;
while (!(*(volatile unsigned long*)(base + SEP0718_SR)& 0x4));
while (*(volatile unsigned long*)(base + SEP0718_SR) & 0x1);

data = *(volatile unsigned long*)(base + SEP0718_DR);
while ((*(volatile unsigned long*)(base + SEP0718_SR) & 0x8));
while (*(volatile unsigned long*)(base + SEP0718_SR) & 0x1);


return data;  
}



void write_reg(unsigned short addr, unsigned short data)
{
//printk("we write the AR1020 register address :0x%x,data:0x%x\n",addr,data);

SendCommand(0x55);
SendCommand(0x05);
SendCommand(0x21);
SendCommand(0x00);
SendCommand(addr);
SendCommand(0x01);
SendCommand(data);
//printk(" write register end \n");

}

void read_reg(unsigned short addr)
{

SendCommand(0x55);
SendCommand(0x04);
SendCommand(0x20);
SendCommand(0x00);
SendCommand(addr);
SendCommand(0x01);
}




static void sep0718_ts_setup(void )
{
 // printk("we are in sep0718 touch screen setup\n");

SEP0718_INT_DISABLE(INTSRC_EXT11);
     *(volatile unsigned long*)GPIO_PORTI_DIR_V &=~(1<<11);
     *(volatile unsigned long*)GPIO_PORTI_SEL_V |=(1<<11);
     *(volatile unsigned long*)GPIO_PORTI_INTRSEL_V |=(1<<11);
     *(volatile unsigned long*)GPIO_PORTI_INTRLEL_V |= (1<<11);
     *(volatile unsigned long*)GPIO_PORTI_INTRPOL_V &= ~(1<<11);


    writeb(0x0,  base + SEP0718_SSIENR);
    writeb(0x47, base + SEP0718_CONTROL0);
    writeb(0x00, base + SEP0718_CONTROL1);
   writel(0x300, base + SEP0718_BAUDR);
    writeb(0x1, base + SEP0718_TXFTLR);
    writeb(0x0, base + SEP0718_RXFTLR);
    writeb(0x0, base + SEP0718_DMACR);
    writeb(0x0, base + SEP0718_IMR);
    writeb(0x1, base + SEP0718_SER);
    writeb(0x1, base + SEP0718_SSIENR);


  mdelay(2);
    *(volatile unsigned long*)GPIO_PORTI_INTRCLR_V |=(1<<11);             
*(volatile unsigned long*)GPIO_PORTI_INTRCLR_V &= 0x000;                 //清除中断
SEP0718_INT_ENABLE(INTSRC_EXT11); 


write_reg(0x2C,0x51);
write_reg(0x31,0x10);

  printk("have  setup the touch screen \n");



static void tsevent(void)
{
    int data[5] = {0};
int i;
    int x,y;
*(volatile unsigned long*)(base + SEP0718_SSIENR)=0x0;
udelay(1);
*(volatile unsigned long*)(base + SEP0718_SSIENR)=0x1;

   data[0]=SendCommand(0x00)&0x81;
    data[1]=SendCommand(0x00)&0x3F;
    data[2]=SendCommand(0x00)&0x1F;
    data[3]=SendCommand(0x00)&0x3F;
    data[4]=SendCommand(0x00)&0x1F;


     ts->zp=data[0];

  ts->xp=(((data[2]<<7)+data[1])-140)*800/(3850-140);
ts->yp=(((data[4]<<7)+data[3])-290)*480/(3850-290);


if((ts->xp)>800 && (ts->xp)<900 )
ts->xp=799;
else if((ts->xp) >=65000)
ts->xp=1;

if((ts->yp)>480 && (ts->yp) <520 )
ts->yp=479;
else if((ts->yp) >=65000)
ts->yp=1;

printk("x:%d,y:%d,p:%x\n",ts->xp,ts->yp,ts->zp);
   if (ts->zp==0x81)
       {
input_report_abs(ts->dev, ABS_X, ts->xp);
input_report_abs(ts->dev, ABS_Y, ts->yp);
input_report_key(ts->dev, BTN_TOUCH, 1);
input_report_abs(ts->dev, ABS_PRESSURE, 1);
input_sync(ts->dev);
ts->zp=0;
ts->xp=0;
ts->yp=0;
 }
    else if(ts->zp==0x80)
       {
input_report_abs(ts->dev, ABS_X, ts->xp);
input_report_abs(ts->dev, ABS_Y, ts->yp);
input_report_key(ts->dev, BTN_TOUCH, 0);
input_report_abs(ts->dev, ABS_PRESSURE, 0);
input_sync(ts->dev);
  }



return;
}


static void ts_timer_handler(unsigned long arg)
{
     
SEP0718_INT_ENABLE(INTSRC_EXT11);
return;

}





static int sep0718_ts_irqhandler(int irq, void *dev_id, struct pt_regs *regs)
//printk("we are in sep0718_ts_irqhandler\n");
SEP0718_INT_DISABLE(INTSRC_EXT11);

tsevent();

   SEP0718_INT_ENABLE(INTSRC_EXT11);
    *(volatile unsigned long*)GPIO_PORTI_INTRCLR_V |=(1<<11);             
*(volatile unsigned long*)GPIO_PORTI_INTRCLR_V &= 0x000;                 //清除中断
 
    return IRQ_HANDLED;
}




static int __init sep0718_ts_probe(struct platform_device *pdev)
{
struct input_dev *input_dev;
int err;


printk("sep0718_ts_probe!\n");

ts = kzalloc(sizeof(struct sep_ts), GFP_KERNEL);
  

base = ioremap(SSI2_BASE, SZ_4K);
if (base == NULL) {
printk("base is null\n");
}

input_dev = input_allocate_device();

if (!input_dev) {
err = -ENOMEM;
goto fail;
}

ts->dev = input_dev;

ts->dev->evbit[0] = ts->dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
ts->dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);

input_set_abs_params(ts->dev, ABS_X, 0, 800, 0, 0);
input_set_abs_params(ts->dev, ABS_Y, 0, 480, 0, 0);
input_set_abs_params(ts->dev, ABS_PRESSURE, 0, 1, 0, 0);

//sprintf(ts->phys, "input(ts)");
//ts->dev->private = ts;
ts->dev->name = "SEP0718 Touchscreen";
//ts->dev->phys = ts->phys;
ts->dev->id.bustype = BUS_RS232;
ts->dev->id.vendor = 0xDEAD;
ts->dev->id.product = 0xBEEF;
ts->dev->id.version = SEP_TSVERSION;


    if(request_irq(INTSRC_EXT11,sep0718_ts_irqhandler,0,"sep0718_ts",ts->dev))
        {
        printk("request ts irq11 failed!\n");
        kfree(ts);
        return -1;
        }

 

/* All went ok, so register to the input system */
err = input_register_device(ts->dev);
if(err) {
free_irq(INTSRC_EXT11, ts->dev);
return -EIO;
}

sep0718_ts_setup();
setup_timer(&ts->ts_timer,ts_timer_handler,0);
return 0;



fail: input_free_device(input_dev);
kfree(ts);
return err;
}

static int sep0718_ts_remove(struct platform_device *dev)
{
printk(KERN_INFO "sep0718_ts_remove() of TS called !\n");

SEP0718_INT_DISABLE(INTSRC_EXT11);
free_irq(INTSRC_EXT11, ts->dev);

input_unregister_device(ts->dev);
return 0;
}



static int sep0718_ts_suspend(struct platform_device *dev, pm_message_t state)
{

SEP0718_INT_DISABLE(INTSRC_EXT11);
return 0;
}

static int sep0718_ts_resume(struct platform_device *pdev)
{
SEP0718_INT_ENABLE(INTSRC_EXT11);
return 0;
}


static struct platform_driver sep0718_ts_driver = {
       .probe          = sep0718_ts_probe,
       .remove         = sep0718_ts_remove,
       .suspend        = sep0718_ts_suspend,
       .resume         = sep0718_ts_resume,
       .driver = {
.owner = THIS_MODULE,
.name = "sep0718_ts",
},
};

static char banner[] __initdata = KERN_INFO "sep0718 Touchscreen driver, (c) 2010 SEU ASIC\n";

static int __init sep0718_ts_init(void)
{
printk(banner);

return platform_driver_register(&sep0718_ts_driver);
}

static void __exit sep0718_ts_exit(void)
{
platform_driver_unregister(&sep0718_ts_driver);
}

module_init(sep0718_ts_init);
module_exit(sep0718_ts_exit);

MODULE_AUTHOR("liyu allenseu@gmail.com ");
MODULE_DESCRIPTION("sep0718 touchscreen driver");
MODULE_LICENSE("GPL");




阅读(1318) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2011-04-13 16:40:09

学习了,多谢楼主分享哦!也欢迎广大linux爱好者来我的论坛一起讨论arm哦!www.lt-net.cn