]> rtime.felk.cvut.cz Git - mx1ts.git/commitdiff
uprava zpracovani data ready preruseni jeste nedokoncene
authorRadek Pupák <pupakr1@fel.cvut.cz>
Sun, 11 May 2008 22:56:14 +0000 (00:56 +0200)
committerRadek Pupák <pupakr1@fel.cvut.cz>
Sun, 11 May 2008 22:56:14 +0000 (00:56 +0200)
mx1_ts-driver.c

index 2d4be95d4b9bba010212a4138412a7de59602c35..acedd6ff705808b1b3ca1322707a36f2c87eee85 100644 (file)
@@ -167,7 +167,11 @@ struct mx1ts {
        
        u16                     x_res;          
        u16                     y_res;
-
+       u16                     x_akt;
+       u16                     y_akt;
+       u16                     u_akt;
+       unsigned int            stav;
+       u8                      auto_calibration;
 }; 
 
 
@@ -193,41 +197,165 @@ static inline unsigned int mx1ts_reg_read(struct mx1ts *mts, unsigned int reg)
        unsigned int out;
 
        out =  __raw_readl( mts->mx1ts_mem + reg );     
-       printk("mx1_touchscreen: ctu z %p : %d \n",mts->mx1ts_mem + reg, out);
+       /*printk("mx1_touchscreen: ctu z %p : %d \n",mts->mx1ts_mem + reg, out);*/
                
        return out;
 }
 
-static irqreturn_t mx1ts_pendata_irq(int irq, void *dev_id)
+static void mx1ts_disable_auto_sample(struct mx1ts *mts)
 {
-       struct mx1_ts *mts = (struct mx1_ts *) dev_id;
-       printk("<1> mx1_touchscreen: mx1_pendata_irq interrupt recived from struct %p\n", mts);
-       
-       //mx1ts_reg_write(mts, ASP_ICNTLR , ASP_PUIE | /* ASP_EDGE |*/ ASP_PIRQE);
+       unsigned int value;
 
-       mx1ts_reg_set_mask(mts, ASP_ISTATR, ASP_PUIS);
-       
-       unsigned int data = mx1ts_reg_read(mts, ASP_PADFIFO);
-printk("<1> mx1_touchscreen: FIFO data %i\n", data);
+       value = mx1ts_reg_read(mts, ASP_ACNTLCR);
 
+       /* Set the mode to none */
+       value &= ~ASP_MODE_MASK;
 
-       static unsigned int auto_zero, pen_x, pen_y, pen_u;
-/*
-       if (mx1_reg_read(ASP_ISTATR) & 0x400) {
-               mx1_reg_set_bit(ASP_ISTATR, 0x400);
+       /* Disable auto zero. */
+       value &= ~ASP_AZE;
+
+       /* Disable auto sample. */
+       value &= ~ASP_AUTO;
+
+       /* Disable pen A/D. */
+       value &= ~ASP_PADE;
+       mx1ts_reg_write(mts, ASP_ACNTLCR, value);
+
+       /* Disable pen data ready and full interrupt. */
+       value = mx1ts_reg_read(mts, ASP_ICNTLR);
+       value &= ~(ASP_PFFE | ASP_PDRE);
+       mx1ts_reg_write(mts, ASP_ICNTLR, value);
+}
+
+static void mx1ts_enable_pen_touch_interrupt(struct mx1ts *mts)
+{
+       unsigned int value;
+
+       /* Enable pen touch interrupt. */
+       value = mx1ts_reg_read(mts, ASP_ICNTLR);
+       value |= ASP_EDGE | ASP_PIRQE;
+       mx1ts_reg_write(mts, ASP_ICNTLR, value);
+}
+
+static void mx1ts_disable_pen_touch_interrupt(struct mx1ts *mts)
+{
+       unsigned int value;
+
+       /* Enable pen touch interrupt. */
+       value = mx1ts_reg_read(mts, ASP_ICNTLR);
+       value &= ~ASP_PIRQE;
+       mx1ts_reg_write(mts, ASP_ICNTLR, value);
+}
+
+static void mx1ts_enable_pen_up_interrupt(struct mx1ts *mts)
+{
+       unsigned int value;
+
+       /* Enable pen up interrupt. XXX: This feature is undocumented. */
+       value = mx1ts_reg_read(mts, ASP_ICNTLR);
+       value |= ASP_PUIE;
+       mx1ts_reg_write(mts, ASP_ICNTLR, value);
+}
+
+static void mx1ts_disable_pen_up_interrupt(struct mx1ts *mts)
+{
+       unsigned int value;
+
+       /* Enable pen up interrupt. XXX: This feature is undocumented. */
+       value = mx1ts_reg_read(mts, ASP_ICNTLR);
+       value &= ~ASP_PUIE;
+       mx1ts_reg_write(mts, ASP_ICNTLR, value);
+}
+
+static inline void mx1ts_flush_fifo(struct mx1ts *mts)
+{
+       int i;
+       for (i = 0; i < 12; i++)
+               if (mx1ts_reg_read(mts, ASP_ISTATR) & (ASP_PFF | ASP_PDR))
+                       mx1ts_reg_read(mts, ASP_PADFIFO);
+}
+
+static void mx1ts_start_auto_calibration(struct mx1ts *mts)
+{
+       unsigned int value;
 
-               mx1ts_disable_auto_sample();
-               mx1ts_disable_pen_up_interrupt();
-               mx1ts_enable_pen_touch_interrupt();
+       mts->auto_calibration = 1;
 
-               mx1ts_evt_add(&mx1ts, 0, pen_x, pen_y);
+       value = mx1ts_reg_read(mts, ASP_ACNTLCR);
 
-               mx1ts_flush_fifo();
+       /* Set the mode to X then Y */
+       value &= ~ASP_MODE_MASK;
+       value |= ASP_MODE_ONLY_X;
 
-               return;
+       /* Enable auto zero. */
+       value |= ASP_AZE;
+
+       /* Enable auto calibrate. XXX: Undocumented bitfield. */
+       value |= 0x04000000;
+
+       /* Enable auto sample. */
+       value |= ASP_AUTO;
+
+       /* Enable pen A/D. */
+       value |= ASP_PADE;
+       mx1ts_reg_write(mts, ASP_ACNTLCR, value);
+
+       /* Enable pen data ready and full interrupt. */
+       value = mx1ts_reg_read(mts, ASP_ICNTLR);
+       value |= ASP_PFFE | ASP_PDRE | ASP_PUIE;
+       mx1ts_reg_write(mts, ASP_ICNTLR, value);
+}
+
+static void mx1ts_evt_add(struct input_dev *idev, u8 p , u16 x, u16 y)
+{
+       input_report_key(idev, BTN_TOUCH, p);
+       input_report_abs(idev, ABS_X, x);
+       input_report_abs(idev, ABS_Y, y);
+       /* input_report_abs(idev, ABS_PRESSURE, pressure);*/
+       printk(KERN_ERR "ukladam hodnoty vystupu %i, %i, %i.\n", p, x, y);
+       input_sync(idev);
+}
+
+static irqreturn_t mx1ts_pendata_irq(int irq, void *dev_id)
+{      
+       u16 auto_zero;
+       u16 mx1ts_cal_auto_zero;
+       u16 mx1_cal_range_x;
+       u16 mx1_cal_range_y;
+       u16 data;
+       mx1_cal_range_x = 1;
+       mx1_cal_range_y = 1;
+/*     static unsigned int auto_zero, pen_x, pen_y, pen_u;*/
+
+       struct mx1_ts *mts = (struct mx1_ts *) dev_id;
+       /*printk("<1> mx1_touchscreen: mx1_pendata_irq interrupt recived from struct %p\n", mts);*/
+       
+       /*mx1ts_reg_write(mts, ASP_ICNTLR , ASP_PUIE | / ASP_EDGE |/ ASP_PIRQE);*/
+       
+       
+       /*mx1ts_reg_set_mask(mts, ASP_ISTATR, ASP_PUIS);*/
+       
+       /*data = mx1ts_reg_read(mts, ASP_PADFIFO);*/
+       
+       /*mts->akt[mts->stav++] = data;*/
+       /*printk("<1> mx1_touchscreen: FIFO data %i\n", data);*/
+       
+
+       if (mx1ts_reg_read(mts, ASP_ISTATR) & ASP_PUIS) {
+               mx1ts_reg_set_mask(mts, ASP_ISTATR, ASP_PUIS);
+
+               mx1ts_disable_auto_sample(mts);
+               mx1ts_disable_pen_up_interrupt(mts);
+               mx1ts_enable_pen_touch_interrupt(mts);
+
+               mx1ts_evt_add(mts, 0, 0, 0);
+               printk(KERN_ERR "Zaplnena fifo.\n");
+               mx1ts_flush_fifo(mts);
+
+               return IRQ_HANDLED;
        }
 
-       if (mx1_performing_auto_calibration) {
+       /*if (pmts->auto_calibration) {
                unsigned int value;
 
                mx1_cal_auto_zero = mx1_reg_read(ASP_PADFIFO) & 0xFFFF;
@@ -238,7 +366,7 @@ printk("<1> mx1_touchscreen: FIFO data %i\n", data);
                    (mx1_cal_auto_zero >= mx1_cal_range_y)) {
                        // Invalid data. 
                        mx1ts_start_auto_calibration();
-                       return;
+                       return IRQ_HANDLED;
                }
 
                mx1_cal_range_x -= mx1_cal_auto_zero;
@@ -251,31 +379,31 @@ printk("<1> mx1_touchscreen: FIFO data %i\n", data);
                mx1_performing_auto_calibration = 0;
 
                mx1ts_enable_auto_sample();
-       } else {
+       } else {*/
                // There could be more than one sample in the FIFO, but we're
                // only going to read one per call. The interrupt will be
                // generated as long as there is data in the FIFO. 
 
-               if ((mx1_reg_read(ASP_ISTATR) & ASP_PDR) != ASP_PDR) {
-                       return;
+               if ((mx1ts_reg_read(mts, ASP_ISTATR) & ASP_PDR) != ASP_PDR) {
+                       return IRQ_NONE; /* TODO je to tak? */
                }
 
-               auto_zero = mx1_reg_read(ASP_PADFIFO);
-               if (auto_zero > (mx1_cal_auto_zero + 0x200)) {
-                       return;
-               }
+               auto_zero = mx1ts_reg_read(mts, ASP_PADFIFO);
+               /*if (auto_zero > (mx1ts_cal_auto_zero + 0x200)) {
+                       return IRQ_HANDLED;
+               }*/
 
-               pen_x = mx1_reg_read(ASP_PADFIFO);
-               pen_y = mx1_reg_read(ASP_PADFIFO);
-               pen_u = mx1_reg_read(ASP_PADFIFO);
+               u16 pen_x = mx1ts_reg_read(mts, ASP_PADFIFO);
+               u16 pen_y = mx1ts_reg_read(mts, ASP_PADFIFO);
+               u16 pen_u = mx1ts_reg_read(mts, ASP_PADFIFO);
 
-               pen_x = (u32)(((pen_x - mx1_cal_auto_zero) << 16) /
+               pen_x = (u32)(((pen_x - mx1ts_cal_auto_zero) << 16) /
                              mx1_cal_range_x);
-               pen_y = (u32)(((pen_y - mx1_cal_auto_zero) << 16) /
+               pen_y = (u32)(((pen_y - mx1ts_cal_auto_zero) << 16) /
                              mx1_cal_range_y);
 
-               mx1ts_evt_add(&mx1ts, pen_u, pen_x, pen_y);
-       }*/
+               mx1ts_evt_add(mts, pen_u, pen_x, pen_y);
+       /*}*/
        return IRQ_HANDLED;
 }
 
@@ -292,12 +420,12 @@ static void mx1ts_enable_pen_up_irq(struct mx1ts *mts)
        unsigned int value;
        printk(KERN_ERR "Pen up irq.\n");       
 
-       //value = mx1ts_reg_read(mts, ASP_ICNTLR);
-       //value |= ASP_PUIE;
-       //mx1ts_reg_write(mts, ASP_ICNTLR, value);
-       //printk(KERN_ERR "Mely probehnout nejake zapisy.\n");
-       //printk(KERN_ERR "Na adresu %i\n",ASP_ICNTLR );
-       //printk(KERN_ERR "Hodnota %i\n",value );
+       value = mx1ts_reg_read(mts, ASP_ICNTLR);
+       value |= ASP_PUIE;
+       mx1ts_reg_write(mts, ASP_ICNTLR, value);
+       printk(KERN_ERR "Mely probehnout nejake zapisy.\n");
+       printk(KERN_ERR "Na adresu %i\n",ASP_ICNTLR );
+       printk(KERN_ERR "Hodnota %i\n",value );
 }
 
 static irqreturn_t mx1ts_touch_irq(int irq, void *dev_id)
@@ -342,18 +470,12 @@ static inline int mx1ts_enable_irqs(struct mx1ts *mts)    //zaregistruje preruseni
        return result;
 }
 
-static void mx1ts_evt_add(struct input_dev *idev, u16 pressure, u16 x, u16 y)
-{
-       input_report_abs(idev, ABS_X, x);
-       input_report_abs(idev, ABS_Y, y);
-       input_report_abs(idev, ABS_PRESSURE, pressure);
-       input_sync(idev);
-}
+
 
 static int mx1ts_on(struct mx1ts *mts)
 {
        int ret = 0;
-       int err;                //k check_region
+/*     int err;                //k check_region*/
        
        if(!request_mem_region(ASP_BASE_ADDR, 0x38 , "mx1ts")) {
                printk(KERN_ERR "mx1ts: request_mem_region \tFAILED\n");        
@@ -449,7 +571,9 @@ static int mx1ts_probe(struct platform_device *dev)
        idev->id.product        = id;
        idev->open              = mx1ts_open;
        idev->close             = mx1ts_close;
-       idev->evbit[0]          = BIT(EV_ABS); //BIT_MASK(EV_ABS);
+       idev->evbit[0]          = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
+       idev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
+
        //idev->bustype         = BUS_HOST;
 
        printk("<1> mx1ts: setting idev struct \tOK\t");
@@ -590,5 +714,8 @@ static void __exit mx1ts_exit(void)
 module_init(mx1ts_init);
 module_exit(mx1ts_exit);
 
+
 MODULE_DESCRIPTION("MX1 touchscreen driver");
+MODULE_AUTHOR("Radek Pupák (pupakr1@fel.cvut.cz)");
 MODULE_LICENSE("GPL");
+