]> rtime.felk.cvut.cz Git - mx1ts.git/blobdiff - mx1_ts-driver.c
po oprave odporu mezi PX1 a napajenim, funguji preruseni, netreba ignorovat urcite...
[mx1ts.git] / mx1_ts-driver.c
index cda5b8316dcf5eafbaa7cb721f60e215cecd94a5..e4fbe3cb49efa2b0c87061c83ae8d27f4475a58c 100644 (file)
@@ -1,19 +1,23 @@
 /*
- *  MX1 touchscreen driver
+ * MX1 touchscreen driver
  *
- *  Author:    Nicolas Pitre
- *  Created:   September 25, 2006
- *  Copyright: MontaVista Software, Inc.
+ * Copyright (C) 2008
+ * Radek Pupak (pupakr1@fel.cvut.cz)
+ * Czech Technical University, FEE, DCE
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  *
- * This code is heavily based on ucb1x00-*.c copyrighted by Russell King
- * covering the UCB1100, UCB1200 and UCB1300..  Support for the UCB1400 has
- * been made separate from ucb1x00-core/ucb1x00-ts on Russell's request.
+ * This code is heavily based on ucb*.c copyrighted by Russell King
+ * and Nicolas Pitre covering the UCB1100, UCB1200, UCB1300 and UCB1400.
+ *
+ * Hardware specific properties are based on mx1ts.h and mx1ts.c copyrated
+ * by Blue Mug, Inc. for Motorola, Inc.
+ *
  */
 
+
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/init.h>
@@ -175,11 +179,12 @@ struct mx1ts {
        u16                     cal_range_y;
        unsigned int            stav;
        u8                      auto_calibration;
+       u8                      is_open;
 
 }; 
 
-
-struct mx1ts mx1_ts;
+static int MX1TS_lastx = 0;
+static int MX1TS_lasty = 0;
 
 static inline void mx1ts_reg_set_mask(struct mx1ts *mts , unsigned int reg, u32 mask)
 {      
@@ -200,7 +205,7 @@ 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("mx1_touchscreen: zapisuji do : %p  hodnotu %x\n",mts->mx1ts_mem+reg, val);
+       printk(KERN_DEBUG "mx1_touchscreen: writing into : %p value %x\n",mts->mx1ts_mem+reg, val);
        
 }
 
@@ -209,7 +214,7 @@ 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(KERN_DEBUG "mx1_touchscreen: reading from %p : %d \n",mts->mx1ts_mem + reg, out);*/
                
        return out;
 }
@@ -282,8 +287,10 @@ static void mx1ts_enable_pen_touch_interrupt(struct mx1ts *mts)
 
        /* Enable pen touch interrupt. */
        value = mx1ts_reg_read(mts, ASP_ICNTLR);
-       value |= ASP_EDGE | ASP_PIRQE;
+       value |= ASP_EDGE | /*ASP_POL |*/ ASP_PIRQE;
        mx1ts_reg_write(mts, ASP_ICNTLR, value);
+       
+       printk(KERN_DEBUG "mx1_touchscreen: pen_touch: activating pen_down interrupt \n");
 }
 
 static void mx1ts_disable_pen_touch_interrupt(struct mx1ts *mts)
@@ -294,16 +301,17 @@ static void mx1ts_disable_pen_touch_interrupt(struct mx1ts *mts)
        value = mx1ts_reg_read(mts, ASP_ICNTLR);
        value &= ~ASP_PIRQE;
        mx1ts_reg_write(mts, ASP_ICNTLR, value);
+       printk(KERN_DEBUG "mx1_touchscreen: pen_touch: deaktivating pen_down interrupt \n");
 }
 
 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;
+       value |= ASP_PUIE; 
        mx1ts_reg_write(mts, ASP_ICNTLR, value);
+       printk(KERN_DEBUG "mx1_touchscreen: pen_up: activating pen_up interrupt \n");
 }
 
 static void mx1ts_disable_pen_up_interrupt(struct mx1ts *mts)
@@ -314,6 +322,7 @@ static void mx1ts_disable_pen_up_interrupt(struct mx1ts *mts)
        value = mx1ts_reg_read(mts, ASP_ICNTLR);
        value &= ~ASP_PUIE;
        mx1ts_reg_write(mts, ASP_ICNTLR, value);
+       printk(KERN_DEBUG "mx1_touchscreen: pen_up: deaktivating pen_up interrupt \n");
 }
 
 
@@ -321,6 +330,8 @@ static void mx1ts_disable_pen_up_interrupt(struct mx1ts *mts)
 static void mx1ts_start_auto_calibration(struct mx1ts *mts)
 {
        unsigned int value;
+       printk(KERN_DEBUG "mx1_touchscreen: start_auto_calibration \n");
+
 
        mts->auto_calibration = 1;
 
@@ -369,28 +380,39 @@ static void mx1ts_reset_asp(struct mx1ts *mts)
        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);
+       /* 0x01 Set the clock divide ratio to 2. */
+       mx1ts_reg_write(mts, ASP_CLKDIV, 0x1f);
 
        /* 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 */
+       value = (0x7 << ASP_DMCNT_SCALE) |      /* 0x2 - Decimation ratio is 3 */
+               (0x3F << ASP_IDLECNT_SCALE) |   /* 0x1 - Idle count is 1 clock */
+               (0xF << ASP_DSCNT_SCALE);       /* 0x2 - 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)
+static void mx1ts_evt_add_touch(struct input_dev *idev, u8 p , u16 x, u16 y)
 {
-       input_report_key(idev, BTN_TOUCH, p);
+       input_report_key(idev, BTN_TOUCH, 1);
        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);
+       /*input_report_abs(idev, ABS_PRESSURE, p);*/
+       input_report_abs(idev, ABS_PRESSURE, 1);
+       MX1TS_lastx = x;
+       MX1TS_lasty = y;
+       input_sync(idev);
+}
+
+static void mx1ts_evt_add_up(struct input_dev *idev)
+{
+       input_report_abs(idev, ABS_X, MX1TS_lastx);
+       input_report_abs(idev, ABS_Y, MX1TS_lasty);
+       input_report_abs(idev, ABS_PRESSURE, 0);
+       /*input_report_key(idev, BTN_TOUCH, 0);*/
        input_sync(idev);
 }
 
@@ -398,36 +420,38 @@ static void mx1ts_evt_add(struct input_dev *idev, u8 p , u16 x, u16 y)
  * 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)
+
+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;
 
-       /*struct mx1ts *mts = (struct mx1_ts *) dev_id;*/
-
        mx1_cal_range_x = 1;
        mx1_cal_range_y = 1;
-       
-/*     printk("<1> mx1_touchscreen: mx1_pendata_irq interrupt recived from struct %p\n", mts);*/
+
+       /*printk(KERN_DEBUG "mx1_touchscreen mx1ts_pendata_irq \n");*/
+/*     printk(KERN_DEBUG "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);
+       if (mx1ts_reg_read(mts, ASP_ISTATR) & ASP_PUIS) {       /*pen up interupt pending*/
+               mx1ts_reg_set_mask(mts, ASP_ISTATR, ASP_PUIS);  /*clearing pen up interupt*/
 
-               mx1ts_disable_auto_sample(mts);
+               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");
+               if(mts->is_open)                                        /*report last known touch*/
+                       mx1ts_evt_add_up(mts->ts_idev);
+               printk(KERN_DEBUG "Pen up interrupt.\n");                       
                mx1ts_flush_fifo(mts);
 
                return IRQ_HANDLED;
        }
        
        if (mts->auto_calibration) {
-               unsigned int value;
+/*             unsigned int value;*/
 
                mts->cal_auto_zero = mx1ts_reg_read(mts, ASP_PADFIFO) & 0xFFFF;
                mts->cal_range_x = mx1ts_reg_read(mts, ASP_PADFIFO) & 0xFFFF;
@@ -436,23 +460,25 @@ static irqreturn_t mx1ts_pendata_irq(int irq, struct mx1ts *mts)
                if ((mts->cal_auto_zero >= mts->cal_range_x) ||
                    (mts->cal_auto_zero >= mts->cal_range_y)) {
                        // Invalid data. 
-                       printk(KERN_ERR "Invalid data.\n");
+                       printk(KERN_INFO "Invalid calibration data. Recalibrating. \n");
+                       mx1ts_flush_fifo(mts);                  /*if there are some older data*/
                        mx1ts_start_auto_calibration(mts);
-                       return IRQ_NONE; /* return IRQ_HANDLED; */
+                       return IRQ_HANDLED; /*return IRQ_NONE;*/
                }
 
+               printk(KERN_DEBUG "mx1 touchscreen: calibration cal_auto_zero %i.\n",mts->cal_auto_zero);
+               printk(KERN_DEBUG "mx1 touchscreen: calibration cal_range_x %i.\n",mts->cal_range_x);
+               printk(KERN_DEBUG "mx1 touchscreen: calibration cal_range_y %i.\n",mts->cal_range_y);
                
                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. 
+               /*
+               value = mx1ts_reg_read(mts, ASP_ACNTLCR);  podle me duplicita
+               value &= ~0x04000000; 
                mx1ts_reg_write(mts, ASP_ACNTLCR, value);
-
+               */
                mts->auto_calibration = 0;
 
                mx1ts_enable_auto_sample(mts);
@@ -462,7 +488,7 @@ static irqreturn_t mx1ts_pendata_irq(int irq, struct mx1ts *mts)
                // generated as long as there is data in the FIFO. 
 
                if ((mx1ts_reg_read(mts, ASP_ISTATR) & ASP_PDR) != ASP_PDR) {
-                       return IRQ_NONE; /* TODO je to tak? */
+                       return IRQ_NONE; 
                }
 
                auto_zero = mx1ts_reg_read(mts, ASP_PADFIFO);
@@ -479,29 +505,12 @@ 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_touch(mts->ts_idev, 200 , 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_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)
-{
-       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);
-}
-
 /*
  * Handle the touch interrupt, generated when the pen is pressed/
  * released.
@@ -511,12 +520,13 @@ 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"); 
+       printk(KERN_ERR "mx1 touchscreen: Touch down interrupt \n");    
 
        /* Clear the interrupt. */
        mx1ts_reg_set_mask(mts, ASP_ISTATR, ASP_PEN);
 
        mx1ts_disable_pen_touch_interrupt(mts);
+       mx1ts_flush_fifo(mts);
        mx1ts_start_auto_calibration(mts);
        mx1ts_enable_pen_up_interrupt(mts);
 
@@ -526,13 +536,14 @@ static irqreturn_t mx1ts_touch_irq(int irq, void *dev_id)
 static inline int mx1ts_enable_irqs(struct mx1ts *mts) //zaregistruje preruseni
 {
        int result;
+//TODO printk(KERN_ERR "enabling irq %d.\n",mts->ts_idev->dev.parent.resource[1]->start);
        result = request_irq(ASP_PENDATA_IRQ,
                             mx1ts_pendata_irq,
-                            /*IRQF_*/ 0,
+                                0,
                             DEV_IRQ_ID,
                             mts);
        if (result) {
-               printk(KERN_ERR "Couldn't request pen data IRQ.\n");
+               printk(KERN_ERR "mx1 touchscreen: Couldn't request pen data IRQ.\n");
                return result;
        }
 
@@ -542,7 +553,7 @@ static inline int mx1ts_enable_irqs(struct mx1ts *mts)      //zaregistruje preruseni
                             DEV_IRQ_ID,
                             mts);
        if (result) {
-               printk(KERN_ERR "Couldn't request pen touch IRQ.\n");
+               printk(KERN_ERR "mx1 touchscreen: Couldn't request pen touch IRQ.\n");
                free_irq(ASP_PENDATA_IRQ, mts);
                return result;
        }
@@ -551,136 +562,122 @@ static inline int mx1ts_enable_irqs(struct mx1ts *mts)  //zaregistruje preruseni
 
 
 
-static int mx1ts_on(struct mx1ts *mts)
+static int mx1ts_on(struct mx1ts *mts)    /*TODO doplnit pri chybach*/
 {
        int ret = 0;
        
        if(!request_mem_region(ASP_BASE_ADDR, 0x38 , "mx1ts")) {
-               printk(KERN_ERR "mx1ts: request_mem_region \tFAILED\n");
+               printk(KERN_ERR "mx1 touchscreen: request_mem_region \tFAILED\n");
                return -1;      
        }
 
-       printk("<1>mx1ts: request_mem_region \tOK\n");  
+       printk(KERN_DEBUG "mx1 touchscreen: request_mem_region \tOK\n");        
 
        mts->mx1ts_mem = ioremap ( ASP_BASE_ADDR, 0x38);
        
-       printk("<1>mx1ts: memory remaped on %p \n", mts->mx1ts_mem);
+       if(!mts->mx1ts_mem) {
+               printk(KERN_ERR "mx1 touchscreen: ioremap  \tFAILED\n");
+               return -1;      
+       }
+
+       printk(KERN_DEBUG "mx1 touchscreen: memory remaped on %p \n", mts->mx1ts_mem);
        
 
 
-       printk("<1>mx1ts: enabling irqs\n");
+       /*printk(KERN_DEBUG "mx1 touchscreen: enabling irqs\n");*/
        if ((ret = mx1ts_enable_irqs(mts)))
                return ret;
-       printk("<1>mx1ts: irqs enabled \tOK\n");        
+       printk(KERN_DEBUG "mx1 touchscreen: irqs enabled \tOK\n");      
 
        
        mx1ts_reset_asp(mts);
-       printk("<1>mx1ts: reset\tOK\n");
+       printk(KERN_DEBUG "mx1 touchscreen: reset\tOK\n");
        
-       mx1ts_enable_pen_touch_interrupt(mts);
-       printk("<1>mx1ts: zapnuti touch interrupt\n");  
        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;
+       mx1ts_flush_fifo(mts);
+       mx1ts_reset_asp(mts);
+       printk(KERN_DEBUG "mx1 touchscreen: reset\tOK\n");
+       mx1ts_disable_pen_touch_interrupt(mts);
+       mx1ts_disable_pen_up_interrupt(mts);
+
 }
 
-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;
+       mx1ts_flush_fifo(mts);                  /*if there are some older data*/
+       mx1ts_enable_pen_touch_interrupt(mts);
+       printk(KERN_DEBUG "mx1 touchscreen: touch_down interupt enabled\n");    
        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;
+       int error, x_res, y_res;
 
-//     mx1ts_disable_pen_touch_interrupt();
-//     mx1ts_start_auto_calibration();
-//     mx1ts_enable_pen_up_interrupt();
+       /* TODO jak poznat ze zarizeni je pritomne ? */
 
-       mts = kzalloc(sizeof(struct mx1ts), GFP_KERNEL);        //alokuje pamet
-       idev = input_allocate_device();                         
+       mts = kzalloc(sizeof(struct mx1ts), GFP_KERNEL);        /* alokuje pamet */
+       idev = input_allocate_device();
        if (!mts || !idev) {
                error = -ENOMEM;
+               printk(KERN_ERR "mx1 touchscreen: failed allocate memory for struct mx1ts or idev\n");  
                goto err_free_devs;
-               return error;   //XXX
+               return error;   
        }
-       mx1_ts = *mts;
-
-       
-       mx1ts_on(mts);  
        
-       return 0;
+       mx1ts_on(mts);                  /* remaping registers, reseting device */
 
        mts->ts_idev = idev;
-       //ucb->adcsync = adcsync;
-       //ucb->ac97 = to_ac97_t(dev);
        init_waitqueue_head(&mts->ts_wait);
 
-/*     id = mx1ts_reg_read(ucb, UCB_ID);
-       if (id != UCB_ID_1400) {
-               error = -ENODEV;
-               goto err_free_devs;
-       }
-
-       error = mx1ts_detect_irq(ucb);
-       if (error) {
-               printk(KERN_ERR "UCB1400: IRQ probe failed\n");
-               goto err_free_devs;
-       }
-
-       error = request_irq(ucb->irq, mx1ts_hard_irq, IRQF_TRIGGER_RISING,
-                               "UCB1400", ucb);
-       if (error) {
-               printk(KERN_ERR "mx1ts: unable to grab irq%d: %d\n",
-                               ucb->irq, error);
-               goto err_free_devs;
-       }
-       printk(KERN_DEBUG "UCB1400: found IRQ %d\n", ucb->irq);*/
-
-//     input_set_drvdata(idev, mx1_ts);
+       //input_set_drvdata(idev, mts);         /*moznost ulozit ukazatel na trukturu do input_driver*/
+       platform_set_drvdata(dev, mts);
 
        idev->dev.parent        = &dev->dev;
        idev->name              = "MX1 touchscreen interface";
-       idev->id.vendor         = (unsigned int) 345;//mx1ts_reg_read(mx1_ts, AC97_VENDOR_ID1);
-       idev->id.product        = id;
+       idev->phys              = "mx1ts/input0";       //dodano
+       idev->id.vendor         = (unsigned int) 345;   /*mx1ts_reg_read(mx1_ts, AC97_VENDOR_ID1);*/
+       idev->id.product        = (unsigned int) 354;   /*id;*/
+       idev->id.version        = 0x0100;               //dodano
+       idev->id.bustype        = BUS_HOST;
        idev->open              = mx1ts_open;
        idev->close             = mx1ts_close;
        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");
+       printk(KERN_DEBUG "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 = 60000;          /*TODO neni mozne zmerit ? */
+       y_res = 60000;
+       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);
+       input_set_abs_params(idev, ABS_PRESSURE, 0, 1, 0, 0);
+
+       error = input_register_device(idev);
+       if (error) {
+               printk(KERN_ERR "mx1 touchscreen: error while register input device\n");
+               goto err_free_devs;
+               }
 
-//     error = input_register_device(idev);
-//     if (error)
-//             goto err_free_irq;
+       printk(KERN_DEBUG "mx1ts: input device registered \tOK\n");
 
-//     dev_set_drvdata(dev, ucb);
        return 0;
 
-// err_free_irq:
-//     free_irq(ucb->irq, ucb);
- err_free_devs:
-       printk("<1> mx1ts: chyba pri nastavovani irq  \n");
-       input_free_device(idev);
+  err_free_devs:
+       printk(KERN_ERR "mx1 touchscreen: error in device probe  \n");
+       /*input_free_device(idev);*/
        kfree(mts);
        return error;
 
@@ -688,20 +685,26 @@ static int mx1ts_probe(struct platform_device *dev)
 
 
 
-
 static int mx1ts_remove(struct platform_device *dev)
 {
-       struct mx1_ts *mts = &mx1_ts;
+       struct mx1ts *mts = platform_get_drvdata(dev);
+
+       //BUG_ON(mts == NULL);
        
-       release_mem_region(ASP_BASE_ADDR, 0x40);
-       iounmap(mx1_ts.mx1ts_mem);
        free_irq(ASP_PENDATA_IRQ, mts);
        free_irq(ASP_TOUCH_IRQ, mts);
 
-       //input_free_device(mts->ts_idev);
+       /*input_free_device(mts->ts_idev);
+       printk(KERN_DEBUG "Free device \tOK\n");*/
+       
+       input_unregister_device(mts->ts_idev);
+       printk(KERN_INFO "mx1 touchscreen: Unregister device \tOK\n");
+       iounmap(mts->mx1ts_mem);
+       release_mem_region(ASP_BASE_ADDR, 0x38);
+               
        kfree(mts);
 
-       printk("<1> Removing driver \tOK\n");
+       printk(KERN_INFO "mx1 touchscreen: Removing driver \tOK\n");
        return 0;
 }
 
@@ -742,11 +745,21 @@ static struct resource mx1ts_resources[] = {
        },
 };
 
+void mx1ts_device_release(struct device *dev) {
+       /*struct platform_device *pdev = to_platform_device(dev);
+       release_resource(&dev->res);
+       kfree(pdev);
+       }*/
+}
+
 static struct platform_device mx1ts_device = {
        .name           = "mx1ts",
        .id             = 0,
        .num_resources  = ARRAY_SIZE(mx1ts_resources),
        .resource       = mx1ts_resources,
+       .dev = {
+       .release = mx1ts_device_release,
+       },
 };
 
 
@@ -758,7 +771,7 @@ static int __init mx1ts_init(void)
        int error;
        error = platform_device_register(&mx1ts_device);
        if(error) {
-               printk(KERN_ERR "PiMX1_touchsceen: device registration failed\n");
+               printk(KERN_ERR "mx1 touchscreen: device registration failed\n");
                return error;
        }