]> rtime.felk.cvut.cz Git - mx1ts.git/commitdiff
autokalibrace funguje, handler preruseni vraci X, Y
authorRadek Pupák <pupakr1@fel.cvut.cz>
Mon, 12 May 2008 12:55:08 +0000 (14:55 +0200)
committerRadek Pupák <pupakr1@fel.cvut.cz>
Mon, 12 May 2008 12:55:08 +0000 (14:55 +0200)
mx1_ts-driver.c

index d4e9f3d3816a649b257658ffee27e8e2df72728e..cda5b8316dcf5eafbaa7cb721f60e215cecd94a5 100644 (file)
@@ -170,8 +170,12 @@ struct mx1ts {
        u16                     x_akt;
        u16                     y_akt;
        u16                     u_akt;
+       u16                     cal_auto_zero;
+       u16                     cal_range_x;
+       u16                     cal_range_y;
        unsigned int            stav;
        u8                      auto_calibration;
+
 }; 
 
 
@@ -196,7 +200,6 @@ static inline void mx1ts_reg_clear_mask(struct mx1ts *mts , unsigned int reg, u3
 static inline void mx1ts_reg_write(struct mx1ts *mts, unsigned int reg, unsigned int val)
 {      
        __raw_writel(val, mts->mx1ts_mem+reg);
-       printk("<1> mx1_touchscreen: structura %p\n", mts);
        printk("mx1_touchscreen: zapisuji do : %p  hodnotu %x\n",mts->mx1ts_mem+reg, val);
        
 }
@@ -219,7 +222,7 @@ static inline void mx1ts_flush_fifo(struct mx1ts *mts)
                        mx1ts_reg_read(mts, ASP_PADFIFO);
 }
 
-static void mx1_ts_enable_auto_sample(struct mx1ts *mts)
+static void mx1ts_enable_auto_sample(struct mx1ts *mts)
 {
        unsigned int value;
 
@@ -325,8 +328,7 @@ static void mx1ts_start_auto_calibration(struct mx1ts *mts)
 
        /* Set the mode to X then Y */
        value &= ~ASP_MODE_MASK;
-       /*value |= ASP_MODE_ONLY_X;*/
-       value |= ASP_MODE_ONLY_Y;
+       value |= ASP_MODE_ONLY_X;
 
        /* Enable auto zero. */
        value |= ASP_AZE;
@@ -388,7 +390,7 @@ static void mx1ts_evt_add(struct input_dev *idev, u8 p , 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);*/
-       printk(KERN_ERR "ukladam hodnoty vystupu %i, %i, %i.\n", p, x, y);
+       printk(KERN_ERR "P %i X %i Y %i.\n", p, x, y);
        input_sync(idev);
 }
 
@@ -424,35 +426,37 @@ static irqreturn_t mx1ts_pendata_irq(int irq, struct mx1ts *mts)
                return IRQ_HANDLED;
        }
        
-       /*mts->stav = 1;*/
-/*     printk("mx1_touchscreen: moje pamet je : %p  \n", mts->mx1ts_mem);*/
-
-        
-       /*if (pmts->auto_calibration) {
+       if (mts->auto_calibration) {
                unsigned int value;
 
-               mx1_cal_auto_zero = mx1_reg_read(ASP_PADFIFO) & 0xFFFF;
-               mx1_cal_range_x = mx1_reg_read(ASP_PADFIFO) & 0xFFFF;
-               mx1_cal_range_y = mx1_reg_read(ASP_PADFIFO) & 0xFFFF;
+               mts->cal_auto_zero = mx1ts_reg_read(mts, ASP_PADFIFO) & 0xFFFF;
+               mts->cal_range_x = mx1ts_reg_read(mts, ASP_PADFIFO) & 0xFFFF;
+               mts->cal_range_y = mx1ts_reg_read(mts, ASP_PADFIFO) & 0xFFFF;
 
-               if ((mx1_cal_auto_zero >= mx1_cal_range_x) ||
-                   (mx1_cal_auto_zero >= mx1_cal_range_y)) {
+               if ((mts->cal_auto_zero >= mts->cal_range_x) ||
+                   (mts->cal_auto_zero >= mts->cal_range_y)) {
                        // Invalid data. 
-                       mx1ts_start_auto_calibration();
-                       return IRQ_HANDLED;
+                       printk(KERN_ERR "Invalid data.\n");
+                       mx1ts_start_auto_calibration(mts);
+                       return IRQ_NONE; /* return IRQ_HANDLED; */
                }
 
-               mx1_cal_range_x -= mx1_cal_auto_zero;
-               mx1_cal_range_y -= mx1_cal_auto_zero;
-
-               value = mx1_reg_read(ASP_ACNTLCR);
+               
+               mts->cal_range_x -= mts->cal_auto_zero;
+               mts->cal_range_y -= mts->cal_auto_zero;
+               
+               printk(KERN_ERR "Kalibrace cal_auto_zero %i.\n",mts->cal_auto_zero);
+               printk(KERN_ERR "Kalibrace cal_range_x %i.\n",mts->cal_range_x);
+               printk(KERN_ERR "Kalibrace cal_range_y %i.\n",mts->cal_range_y);
+               
+               value = mx1ts_reg_read(mts, ASP_ACNTLCR);
                value &= ~0x04000000; // Undocumented. 
-               mx1_reg_write(ASP_ACNTLCR, value);
+               mx1ts_reg_write(mts, ASP_ACNTLCR, value);
 
-               mx1_performing_auto_calibration = 0;
+               mts->auto_calibration = 0;
 
-               mx1ts_enable_auto_sample();
-       } else {*/
+               mx1ts_enable_auto_sample(mts);
+       } 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. 
@@ -462,32 +466,31 @@ static irqreturn_t mx1ts_pendata_irq(int irq, struct mx1ts *mts)
                }
 
                auto_zero = mx1ts_reg_read(mts, ASP_PADFIFO);
-               /*if (auto_zero > (mx1ts_cal_auto_zero + 0x200)) {
-                       return IRQ_HANDLED;
-               }*/
+               if (auto_zero > (mts->cal_auto_zero + 0x200)) {
+                       return IRQ_HANDLED; /* TODO asi se nic nedeje */
+               }
 
                pen_x = mx1ts_reg_read(mts, ASP_PADFIFO);
                pen_y = mx1ts_reg_read(mts, ASP_PADFIFO);
                pen_u = mx1ts_reg_read(mts, ASP_PADFIFO);
 
-               /*pen_x = (u32)(((pen_x - auto_zero) << 16) /
-                             mx1_cal_range_x);
+               pen_x = (u32)(((pen_x - auto_zero) << 16) /
+                             mts->cal_range_x);
                pen_y = (u32)(((pen_y - auto_zero) << 16) /
-                             mx1_cal_range_y);*/
-
+                             mts->cal_range_y);
+               
                mx1ts_evt_add(mts, 1, pen_x, pen_y);
-       /*}*/
+       }
        return IRQ_HANDLED;
 }
 
-static void mx1ts_pokus_zapnout(struct mx1ts *mts) {
+/* static void mx1ts_pokus_zapnout(struct mx1ts *mts) {
        mx1ts_reg_write(mts, ASP_CLKDIV, 0x1F); //clok divide register
        mx1ts_reg_write(mts, ASP_ICNTLR , ASP_PUIE | ASP_PDRE | ASP_PFFE | ASP_EDGE | ASP_PIRQE);       //interupt control register //0X00000833
        mx1ts_reg_write(mts, ASP_PSMPLRG, 0x0000487F);  //pen a/d sample rate control register 
        mx1ts_reg_write(mts,ASP_ACNTLCR, ASP_CLKEN | ASP_AZE | ASP_AUTO | (10<<12) | 3);        //control register
 
-
-}
+} */
 
 static void mx1ts_enable_pen_up_irq(struct mx1ts *mts)
 {
@@ -523,9 +526,6 @@ static irqreturn_t mx1ts_touch_irq(int irq, void *dev_id)
 static inline int mx1ts_enable_irqs(struct mx1ts *mts) //zaregistruje preruseni
 {
        int result;
-// int request_irq(unsigned int irq,  void (*handler)(int, struct pt_regs *),  unsigned long flags,  const char *device); 
-//static void mx1ts_pendata_int(int irq, void *dev_id, struct pt_regs *regs);
-//request_irq (irq, soc_intr, IRQF_SHARED, "SOC", (void *)s))
        result = request_irq(ASP_PENDATA_IRQ,
                             mx1ts_pendata_irq,
                             /*IRQF_*/ 0,