]> rtime.felk.cvut.cz Git - mx1ts.git/commitdiff
upravene zpracovani preruseni, verze pred zmenou autokalibrace
authorRadek Pupák <pupakr1@fel.cvut.cz>
Mon, 12 May 2008 10:50:46 +0000 (12:50 +0200)
committerRadek Pupák <pupakr1@fel.cvut.cz>
Mon, 12 May 2008 10:50:46 +0000 (12:50 +0200)
mx1_ts-driver.c

index acedd6ff705808b1b3ca1322707a36f2c87eee85..d4e9f3d3816a649b257658ffee27e8e2df72728e 100644 (file)
@@ -185,10 +185,19 @@ static inline void mx1ts_reg_set_mask(struct mx1ts *mts , unsigned int reg, u32
        __raw_writel(val, mts->mx1ts_mem+reg );
 }
 
+static inline void mx1ts_reg_clear_mask(struct mx1ts *mts , unsigned int reg, u32 mask)
+{      
+       u32 val;
+       val = __raw_readl(mts->mx1ts_mem+reg);
+       val &= mask;
+       __raw_writel(val, mts->mx1ts_mem+reg );
+}
+
 static inline void mx1ts_reg_write(struct mx1ts *mts, unsigned int reg, unsigned int val)
 {      
        __raw_writel(val, mts->mx1ts_mem+reg);
-       printk("mx1_touchscreen: zapisuji do : %p  hodnotu %d\n",mts->mx1ts_mem+reg, val);
+       printk("<1> mx1_touchscreen: structura %p\n", mts);
+       printk("mx1_touchscreen: zapisuji do : %p  hodnotu %x\n",mts->mx1ts_mem+reg, val);
        
 }
 
@@ -202,6 +211,43 @@ static inline unsigned int mx1ts_reg_read(struct mx1ts *mts, unsigned int reg)
        return out;
 }
 
+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 mx1_ts_enable_auto_sample(struct mx1ts *mts)
+{
+       unsigned int value;
+
+       mx1ts_flush_fifo(mts);
+
+       value = mx1ts_reg_read(mts, ASP_ACNTLCR);
+
+       /* Set the mode to X then Y */
+       value &= ~ASP_MODE_MASK;
+       value |= ASP_MODE_ONLY_Y;
+
+       /* Enable auto zero. */
+       value |= ASP_AZE;
+
+       /* 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;
+       mx1ts_reg_write(mts, ASP_ICNTLR, value);
+}
+
+
 static void mx1ts_disable_auto_sample(struct mx1ts *mts)
 {
        unsigned int value;
@@ -261,19 +307,13 @@ static void mx1ts_disable_pen_up_interrupt(struct mx1ts *mts)
 {
        unsigned int value;
 
-       /* Enable pen up interrupt. XXX: This feature is undocumented. */
+       /* Enable pen up interrupt.  */
        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)
 {
@@ -285,7 +325,8 @@ 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_X;*/
+       value |= ASP_MODE_ONLY_Y;
 
        /* Enable auto zero. */
        value |= ASP_AZE;
@@ -306,6 +347,41 @@ static void mx1ts_start_auto_calibration(struct mx1ts *mts)
        mx1ts_reg_write(mts, ASP_ICNTLR, value);
 }
 
+static void mx1ts_reset_asp(struct mx1ts *mts)
+{
+       unsigned int value;
+
+       mx1ts_flush_fifo(mts);
+
+       /* Soft reset the ASP module */
+        mx1ts_reg_write(mts, ASP_ACNTLCR, ASP_SWRST);
+       /* Read back the reset value of the control register */
+       value = mx1ts_reg_read(mts, ASP_ACNTLCR);
+
+       /* Enable the clock and wait for a short while */
+       value |= ASP_CLKEN;
+        mx1ts_reg_write(mts, ASP_ACNTLCR, value);
+       udelay(100);
+
+       /* Set the value of the conrtol register. */
+       value = ASP_CLKEN | ASP_NM | ASP_SW6 | ASP_BGE;
+        mx1ts_reg_write(mts, ASP_ACNTLCR, value);
+
+       /* Set the clock divide ratio to 2. */
+       mx1ts_reg_write(mts, ASP_CLKDIV, 0x01);
+
+       /* Set the sample rate control register. These values should yield
+         * about 150 samples per second, which seems to give good smooth
+         * lines. */
+       value = (0x2 << ASP_DMCNT_SCALE) |      /* Decimation ratio is 3 */
+               (0x1 << ASP_IDLECNT_SCALE) |    /* Idle count is 1 clock */
+               (0x2 << ASP_DSCNT_SCALE);       /* Data setup is 2 clocks */
+       mx1ts_reg_write(mts, ASP_PSMPLRG, value);
+
+       /* Disable the compare function. */
+       mx1ts_reg_write(mts, ASP_CMPCNTL, 0);
+}
+
 static void mx1ts_evt_add(struct input_dev *idev, u8 p , u16 x, u16 y)
 {
        input_report_key(idev, BTN_TOUCH, p);
@@ -316,31 +392,24 @@ static void mx1ts_evt_add(struct input_dev *idev, u8 p , u16 x, u16 y)
        input_sync(idev);
 }
 
-static irqreturn_t mx1ts_pendata_irq(int irq, void *dev_id)
+/*
+ * Handle the pen data ready interrupt, generated when pen data is
+ * in the FIFO.
+ */
+/*static irqreturn_t mx1ts_pendata_irq(int irq, void *dev_id)*/
+static irqreturn_t mx1ts_pendata_irq(int irq, struct mx1ts *mts)
 {      
-       u16 auto_zero;
-       u16 mx1ts_cal_auto_zero;
        u16 mx1_cal_range_x;
        u16 mx1_cal_range_y;
-       u16 data;
+       static unsigned int auto_zero, pen_x, pen_y, pen_u;
+
+       /*struct mx1ts *mts = (struct mx1_ts *) dev_id;*/
+
        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);*/
-       
-
+/*     printk("<1> mx1_touchscreen: mx1_pendata_irq interrupt recived from struct %p\n", mts);*/
+               
        if (mx1ts_reg_read(mts, ASP_ISTATR) & ASP_PUIS) {
                mx1ts_reg_set_mask(mts, ASP_ISTATR, ASP_PUIS);
 
@@ -354,7 +423,11 @@ static irqreturn_t mx1ts_pendata_irq(int irq, void *dev_id)
 
                return IRQ_HANDLED;
        }
+       
+       /*mts->stav = 1;*/
+/*     printk("mx1_touchscreen: moje pamet je : %p  \n", mts->mx1ts_mem);*/
 
+        
        /*if (pmts->auto_calibration) {
                unsigned int value;
 
@@ -393,26 +466,27 @@ static irqreturn_t mx1ts_pendata_irq(int irq, void *dev_id)
                        return IRQ_HANDLED;
                }*/
 
-               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 = 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 - mx1ts_cal_auto_zero) << 16) /
+               /*pen_x = (u32)(((pen_x - auto_zero) << 16) /
                              mx1_cal_range_x);
-               pen_y = (u32)(((pen_y - mx1ts_cal_auto_zero) << 16) /
-                             mx1_cal_range_y);
+               pen_y = (u32)(((pen_y - auto_zero) << 16) /
+                             mx1_cal_range_y);*/
 
-               mx1ts_evt_add(mts, pen_u, pen_x, pen_y);
+               mx1ts_evt_add(mts, 1, pen_x, pen_y);
        /*}*/
        return IRQ_HANDLED;
 }
 
 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_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)
@@ -423,21 +497,26 @@ static void mx1ts_enable_pen_up_irq(struct mx1ts *mts)
        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 );
 }
 
+/*
+ * Handle the touch interrupt, generated when the pen is pressed/
+ * released.
+ */
+
 static irqreturn_t mx1ts_touch_irq(int irq, void *dev_id)
 {
        struct mx1ts *mts = (struct mx1ts *) dev_id;
        
+       printk(KERN_ERR "Prijat touch irq \n"); 
+
        /* Clear the interrupt. */
        mx1ts_reg_set_mask(mts, ASP_ISTATR, ASP_PEN);
 
-//     mx1ts_disable_pen_touch_interrupt();
-//     mx1ts_start_auto_calibration();
-//     mx1ts_enable_pen_up_irq(mts);
+       mx1ts_disable_pen_touch_interrupt(mts);
+       mx1ts_start_auto_calibration(mts);
+       mx1ts_enable_pen_up_interrupt(mts);
+
        return IRQ_HANDLED;
 }
 
@@ -475,10 +554,10 @@ static inline int mx1ts_enable_irqs(struct mx1ts *mts)    //zaregistruje preruseni
 static int mx1ts_on(struct mx1ts *mts)
 {
        int ret = 0;
-/*     int err;                //k check_region*/
        
        if(!request_mem_region(ASP_BASE_ADDR, 0x38 , "mx1ts")) {
-               printk(KERN_ERR "mx1ts: request_mem_region \tFAILED\n");        
+               printk(KERN_ERR "mx1ts: request_mem_region \tFAILED\n");
+               return -1;      
        }
 
        printk("<1>mx1ts: request_mem_region \tOK\n");  
@@ -486,27 +565,29 @@ static int mx1ts_on(struct mx1ts *mts)
        mts->mx1ts_mem = ioremap ( ASP_BASE_ADDR, 0x38);
        
        printk("<1>mx1ts: memory remaped on %p \n", mts->mx1ts_mem);
-       //mx1ts_reset_asp();
+       
+
 
        printk("<1>mx1ts: enabling irqs\n");
        if ((ret = mx1ts_enable_irqs(mts)))
                return ret;
        printk("<1>mx1ts: irqs enabled \tOK\n");        
 
-       mx1ts_pokus_zapnout(mts);
-       printk("<1>mx1ts: vypada ze zapisy probehly\n");        
-
-       //mx1ts_evt_add(mts->ts_idev, 1, 2,3);
-
+       
+       mx1ts_reset_asp(mts);
+       printk("<1>mx1ts: reset\tOK\n");
+       
+       mx1ts_enable_pen_touch_interrupt(mts);
+       printk("<1>mx1ts: zapnuti touch interrupt\n");  
        return 0;
 }
 
-static int mx1ts_close(struct platform_dev *dev)
+static int mx1ts_close(struct platform_device *dev)
 {
        return 0;
 }
 
-static int mx1ts_open(struct platform_dev *dev)
+static int mx1ts_open(struct platform_device *dev)
 {
        return 0;
 }
@@ -598,6 +679,7 @@ static int mx1ts_probe(struct platform_device *dev)
 // err_free_irq:
 //     free_irq(ucb->irq, ucb);
  err_free_devs:
+       printk("<1> mx1ts: chyba pri nastavovani irq  \n");
        input_free_device(idev);
        kfree(mts);
        return error;