Chinaunix首页 | 论坛 | 博客
  • 博客访问: 12877416
  • 博文数量: 1293
  • 博客积分: 13501
  • 博客等级: 上将
  • 技术积分: 17974
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-08 18:11
文章分类

全部博文(1293)

文章存档

2019年(1)

2018年(1)

2016年(118)

2015年(257)

2014年(128)

2013年(222)

2012年(229)

2011年(337)

分类: LINUX

2011-03-23 23:31:45

  1. #include <linux/errno.h>
  2. #include <linux/kernel.h>
  3. #include <linux/module.h>
  4. #include <linux/slab.h>
  5. #include <linux/input.h>
  6. #include <linux/init.h>
  7. #include <linux/serio.h>
  8. #include <linux/delay.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/clk.h>
  11. #include <asm/io.h>
  12. #include <asm/irq.h>

  13. #include <plat/regs-adc.h>
  14. #include <mach/regs-gpio.h>

  15. /* For ts.dev.id.version */
  16. #define S3C2410TSVERSION    0x0101

  17. #define WAIT4INT(x) (((x)<<8) | \
  18.          S3C2410_ADCTSC_YM_SEN | S3C2410_ADCTSC_YP_SEN | S3C2410_ADCTSC_XP_SEN | \
  19.          S3C2410_ADCTSC_XY_PST(3))

  20. #define AUTOPST     (S3C2410_ADCTSC_YM_SEN | S3C2410_ADCTSC_YP_SEN | S3C2410_ADCTSC_XP_SEN | \
  21.          S3C2410_ADCTSC_AUTO_PST | S3C2410_ADCTSC_XY_PST(0))

  22. static char *s3c2410ts_name = "s3c2410 TouchScreen";

  23. static    struct input_dev *dev;
  24. static    long xp;
  25. static    long yp;
  26. static    int count;

  27. static void __iomem *base_addr;

  28. static inline void s3c2410_ts_connect(void)
  29. {
  30.     s3c2410_gpio_cfgpin(S3C2410_GPG12, S3C2410_GPG12_XMON);
  31.     s3c2410_gpio_cfgpin(S3C2410_GPG13, S3C2410_GPG13_nXPON);
  32.     s3c2410_gpio_cfgpin(S3C2410_GPG14, S3C2410_GPG14_YMON);
  33.     s3c2410_gpio_cfgpin(S3C2410_GPG15, S3C2410_GPG15_nYPON);
  34. }

  35. static void touch_timer_fire(unsigned long data)
  36. {
  37.       unsigned long data0;
  38.       unsigned long data1;
  39.     int updown;

  40.       data0 = __raw_readl(base_addr+S3C2410_ADCDAT0);
  41.       data1 = __raw_readl(base_addr+S3C2410_ADCDAT1);

  42.      updown = (!(data0 & S3C2410_ADCDAT0_UPDOWN)) && (!(data1 & S3C2410_ADCDAT0_UPDOWN));

  43.      if (updown) {
  44.          if (count != 0) {
  45.             long tmp;
  46.             
  47.             xp >>= 2;
  48.             yp >>= 2;

  49.              input_report_abs(dev, ABS_X, xp);
  50.              input_report_abs(dev, ABS_Y, yp);

  51.              input_report_key(dev, BTN_TOUCH, 1);
  52.              input_report_abs(dev, ABS_PRESSURE, 1);
  53.              input_sync(dev);
  54.             printk("Debug ++++ %s ++++ xp=%d,yp=%d\n",__func__,xp,yp);
  55.          }

  56.          xp = 0;
  57.          yp = 0;
  58.          count = 0;

  59.          __raw_writel(S3C2410_ADCTSC_PULL_UP_DISABLE | AUTOPST, base_addr+S3C2410_ADCTSC);
  60.          __raw_writel(__raw_readl(base_addr+S3C2410_ADCCON) | S3C2410_ADCCON_ENABLE_START, base_addr+S3C2410_ADCCON);
  61.      } else {
  62.          count = 0;

  63.          input_report_key(dev, BTN_TOUCH, 0);
  64.          input_report_abs(dev, ABS_PRESSURE, 0);
  65.          input_sync(dev);

  66.          __raw_writel(WAIT4INT(0), base_addr+S3C2410_ADCTSC);

  67.      }
  68. }

  69. static struct timer_list touch_timer =
  70.         TIMER_INITIALIZER(touch_timer_fire, 0, 0);

  71. static irqreturn_t stylus_updown(int irq, void *dev_id)
  72. {
  73.     unsigned long data0;
  74.     unsigned long data1;
  75.     int updown;

  76.     
  77.     data0 = __raw_readl(base_addr+S3C2410_ADCDAT0);
  78.     data1 = __raw_readl(base_addr+S3C2410_ADCDAT1);

  79.     updown = (!(data0 & S3C2410_ADCDAT0_UPDOWN)) && (!(data1 & S3C2410_ADCDAT0_UPDOWN));

  80.     if (updown) {
  81.         touch_timer_fire(0);
  82.     }
  83.     
  84.     return IRQ_HANDLED;
  85. }


  86. static irqreturn_t stylus_action(int irq, void *dev_id)
  87. {
  88.     unsigned long data0;
  89.     unsigned long data1;

  90.     
  91.     data0 = __raw_readl(base_addr+S3C2410_ADCDAT0);
  92.     data1 = __raw_readl(base_addr+S3C2410_ADCDAT1);

  93.     xp += data0 & S3C2410_ADCDAT0_XPDATA_MASK;
  94.     yp += data1 & S3C2410_ADCDAT1_YPDATA_MASK;
  95.     count++;

  96.     if (count < (1<<2)) {
  97.         __raw_writel(S3C2410_ADCTSC_PULL_UP_DISABLE | AUTOPST, base_addr+S3C2410_ADCTSC);
  98.         __raw_writel(__raw_readl(base_addr+S3C2410_ADCCON) | S3C2410_ADCCON_ENABLE_START, base_addr+S3C2410_ADCCON);
  99.     } else {
  100.         mod_timer(&touch_timer, jiffies+1);
  101.         __raw_writel(WAIT4INT(1), base_addr+S3C2410_ADCTSC);
  102.     }
  103.     
  104.     return IRQ_HANDLED;
  105. }

  106. static struct clk    *adc_clock;

  107. static int __init s3c2410ts_init(void)
  108. {
  109.     struct input_dev *input_dev;
  110.     printk("Debug ++++++++++++ %s +++++++++++++++\n", __func__);
  111.     adc_clock = clk_get(NULL, "adc");
  112.     if (!adc_clock) {
  113.         printk(KERN_ERR "failed to get adc clock source\n");
  114.         return -ENOENT;
  115.     }
  116.     clk_enable(adc_clock);

  117.     base_addr=ioremap(S3C2410_PA_ADC,0x20);
  118.     if (base_addr == NULL) {
  119.         printk(KERN_ERR "Failed to remap register block\n");
  120.         return -ENOMEM;
  121.     }

  122.     /* Configure GPIOs */
  123.     s3c2410_ts_connect();

  124.     __raw_writel(S3C2410_ADCCON_PRSCEN | S3C2410_ADCCON_PRSCVL(0xFF),\
  125.          base_addr+S3C2410_ADCCON);
  126.     __raw_writel(0xffff, base_addr+S3C2410_ADCDLY);
  127.     __raw_writel(WAIT4INT(0), base_addr+S3C2410_ADCTSC);

  128.     /* Initialise input stuff */
  129.     input_dev = input_allocate_device();
  130.     if (!input_dev) {
  131.         printk(KERN_ERR "Unable to allocate the input device !!\n");
  132.         return -ENOMEM;
  133.     }

  134.     dev = input_dev;
  135.     dev->evbit[0] = BIT(EV_SYN) | BIT(EV_KEY) | BIT(EV_ABS);
  136.     dev->keybit[BITS_TO_LONGS(BTN_TOUCH)] = BIT(BTN_TOUCH);
  137.     input_set_abs_params(dev, ABS_X, 0, 0x3FF, 0, 0);
  138.     input_set_abs_params(dev, ABS_Y, 0, 0x3FF, 0, 0);
  139.     input_set_abs_params(dev, ABS_PRESSURE, 0, 1, 0, 0);

  140.     dev->name = s3c2410ts_name;
  141.     dev->id.bustype = BUS_RS232;
  142.     dev->id.vendor = 0xDEAD;
  143.     dev->id.product = 0xBEEF;
  144.     dev->id.version = S3C2410TSVERSION;


  145.     /* Get irqs */
  146.     if (request_irq(IRQ_ADC, stylus_action, IRQF_SAMPLE_RANDOM,
  147.         "s3c2410_action", dev)) {
  148.         printk(KERN_ERR "s3c2410_ts.c: Could not allocate ts IRQ_ADC !\n");
  149.         iounmap(base_addr);
  150.         return -EIO;
  151.     }
  152.     if (request_irq(IRQ_TC, stylus_updown, IRQF_SAMPLE_RANDOM,
  153.             "s3c2410_action", dev)) {
  154.         printk(KERN_ERR "s3c2410_ts.c: Could not allocate ts IRQ_TC !\n");
  155.         iounmap(base_addr);
  156.         return -EIO;
  157.     }

  158.     printk(KERN_INFO "%s successfully loaded\n", s3c2410ts_name);

  159.     /* All went ok, so register to the input system */
  160.     input_register_device(dev);

  161.     return 0;
  162. }

  163. static void __exit s3c2410ts_exit(void)
  164. {
  165.     disable_irq(IRQ_ADC);
  166.     disable_irq(IRQ_TC);
  167.     free_irq(IRQ_TC,dev);
  168.     free_irq(IRQ_ADC,dev);

  169.     if (adc_clock) {
  170.         clk_disable(adc_clock);
  171.         clk_put(adc_clock);
  172.         adc_clock = NULL;
  173.     }

  174.     input_unregister_device(dev);
  175.     iounmap(base_addr);
  176. }


  177. module_init(s3c2410ts_init);
  178. module_exit(s3c2410ts_exit);
 
//Lcd_Port_Init();
LTV350QV_Power_ON();
//Lcd_Init();
//Lcd_EnvidOnOff(1);  
//Lcd_ClearScr(0xffff)
  
dprintk("111-------------------11\n");
return 0;

我的很特别除了要搞老师教的。还要改驱动,还要屏蔽其中的这几行。
关键是看你的屏幕是什么类型的。我的是LTV350QV,
阅读(2467) | 评论(0) | 转发(0) |
0

上一篇:编译安装tslib1.4

下一篇:qt4-arm通用配置单

给主人留下些什么吧!~~