]> rtime.felk.cvut.cz Git - mx1ts.git/commitdiff
verze po konzultaci, upraveny nektere ukazatele na struktury dev a idev, pridan...
authorRadek Pupák <pupakr1@fel.cvut.cz>
Wed, 11 Jun 2008 07:04:35 +0000 (09:04 +0200)
committerRadek Pupák <pupakr1@fel.cvut.cz>
Wed, 11 Jun 2008 07:04:35 +0000 (09:04 +0200)
mx1_ts-driver.c

index cda5b8316dcf5eafbaa7cb721f60e215cecd94a5..e6b444c547dbfbe522c9f3221a1f8c3ff09e4181 100644 (file)
@@ -175,12 +175,10 @@ struct mx1ts {
        u16                     cal_range_y;
        unsigned int            stav;
        u8                      auto_calibration;
+       u8                      is_open;
 
 }; 
 
-
-struct mx1ts mx1_ts;
-
 static inline void mx1ts_reg_set_mask(struct mx1ts *mts , unsigned int reg, u32 mask)
 {      
        u32 val;
@@ -390,7 +388,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 "P %i X %i Y %i.\n", p, x, y);
+       /*printk(KERN_ERR "P %i X %i Y %i.\n", p, x, y);*/ /*devprint dev_dbg(zarizeni, co se vypisuje)*/
        input_sync(idev);
 }
 
@@ -399,8 +397,9 @@ static void mx1ts_evt_add(struct input_dev *idev, u8 p , u16 x, u16 y)
  * 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)
+static irqreturn_t mx1ts_pendata_irq(int irq, void *dev_id)
 {      
+       struct mx1ts *mts = (struct mx1ts *)dev_id;
        u16 mx1_cal_range_x;
        u16 mx1_cal_range_y;
        static unsigned int auto_zero, pen_x, pen_y, pen_u;
@@ -419,7 +418,8 @@ static irqreturn_t mx1ts_pendata_irq(int irq, struct mx1ts *mts)
                mx1ts_disable_pen_up_interrupt(mts);
                mx1ts_enable_pen_touch_interrupt(mts);
 
-               mx1ts_evt_add(mts, 0, 0, 0);
+               if(mts->is_open)
+                       mx1ts_evt_add(mts->ts_idev, 0, 0, 0);
                printk(KERN_ERR "Zaplnena fifo.\n");
                mx1ts_flush_fifo(mts);
 
@@ -479,7 +479,8 @@ static irqreturn_t mx1ts_pendata_irq(int irq, struct mx1ts *mts)
                pen_y = (u32)(((pen_y - auto_zero) << 16) /
                              mts->cal_range_y);
                
-               mx1ts_evt_add(mts, 1, pen_x, pen_y);
+               if(mts->is_open)
+                       mx1ts_evt_add(mts->ts_idev, 1, pen_x, pen_y);
        }
        return IRQ_HANDLED;
 }
@@ -582,21 +583,22 @@ static int mx1ts_on(struct mx1ts *mts)
        return 0;
 }
 
-static int mx1ts_close(struct platform_device *dev)
+static void mx1ts_close(struct input_dev *idev)
 {
-       return 0;
+       struct mx1ts *mts = dev_get_drvdata(idev->dev.parent);
+       mts->is_open = 0;
 }
 
-static int mx1ts_open(struct platform_device *dev)
+static int mx1ts_open(struct input_dev *idev)
 {
+       struct mx1ts *mts = dev_get_drvdata(idev->dev.parent);
+       mts->is_open = 1;
        return 0;
 }
 
 static int mx1ts_probe(struct platform_device *dev)
 {
-               
-       //struct mx1ts *mts= &mx1_ts;
-       struct mx1ts *mts;              
+       struct mx1ts *mts;
        struct input_dev *idev;
        int error, id, x_res, y_res;
 
@@ -605,18 +607,14 @@ static int mx1ts_probe(struct platform_device *dev)
 //     mx1ts_enable_pen_up_interrupt();
 
        mts = kzalloc(sizeof(struct mx1ts), GFP_KERNEL);        //alokuje pamet
-       idev = input_allocate_device();                         
+       idev = input_allocate_device();
        if (!mts || !idev) {
                error = -ENOMEM;
                goto err_free_devs;
                return error;   //XXX
        }
-       mx1_ts = *mts;
-
        
        mx1ts_on(mts);  
-       
-       return 0;
 
        mts->ts_idev = idev;
        //ucb->adcsync = adcsync;
@@ -644,7 +642,8 @@ static int mx1ts_probe(struct platform_device *dev)
        }
        printk(KERN_DEBUG "UCB1400: found IRQ %d\n", ucb->irq);*/
 
-//     input_set_drvdata(idev, mx1_ts);
+       //input_set_drvdata(idev, mts);
+       platform_set_drvdata(dev, mts);
 
        idev->dev.parent        = &dev->dev;
        idev->name              = "MX1 touchscreen interface";
@@ -657,26 +656,25 @@ static int mx1ts_probe(struct platform_device *dev)
 
        //idev->bustype         = BUS_HOST;
 
-       printk("<1> mx1ts: setting idev struct \tOK\t");
+       printk("<1> mx1ts: setting idev struct \tOK\n");
        
-/*     mx1ts_adc_enable(ucb);
-       x_res = mx1ts_read_xres(ucb);
-       y_res = mx1ts_read_yres(ucb);
-       mx1ts_adc_disable(ucb);
-       printk(KERN_DEBUG "UCB1400: x/y = %d/%d\n", x_res, y_res);*/
+       x_res = 35000;
+       y_res = 35000;
+       printk(KERN_DEBUG "mx1ts: x/y = %d/%d\n", x_res, y_res);
 
        input_set_abs_params(idev, ABS_X, 0, x_res, 0, 0);
        input_set_abs_params(idev, ABS_Y, 0, y_res, 0, 0);
        input_set_abs_params(idev, ABS_PRESSURE, 0, 0, 0, 0);
 
-//     error = input_register_device(idev);
-//     if (error)
-//             goto err_free_irq;
+       error = input_register_device(idev);
+       if (error)
+               goto err_free_irq;
+
+       printk("<1> mx1ts: input device registered \tOK\n");
 
-//     dev_set_drvdata(dev, ucb);
        return 0;
 
-// err_free_irq:
+ err_free_irq:
 //     free_irq(ucb->irq, ucb);
  err_free_devs:
        printk("<1> mx1ts: chyba pri nastavovani irq  \n");
@@ -691,14 +689,17 @@ static int mx1ts_probe(struct platform_device *dev)
 
 static int mx1ts_remove(struct platform_device *dev)
 {
-       struct mx1_ts *mts = &mx1_ts;
-       
-       release_mem_region(ASP_BASE_ADDR, 0x40);
-       iounmap(mx1_ts.mx1ts_mem);
+       struct mx1ts *mts = platform_get_drvdata(dev);
+
+       BUG_ON(mts == NULL);
+
        free_irq(ASP_PENDATA_IRQ, mts);
        free_irq(ASP_TOUCH_IRQ, mts);
 
-       //input_free_device(mts->ts_idev);
+       iounmap(mts->mx1ts_mem);
+       release_mem_region(ASP_BASE_ADDR, 0x40);
+
+       input_free_device(mts->ts_idev);
        kfree(mts);
 
        printk("<1> Removing driver \tOK\n");