]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/input/touchscreen/ads7846.c
Merge current mainline tree into linux-omap tree
[linux-2.6-omap-h63xx.git] / drivers / input / touchscreen / ads7846.c
index 39573b91c8de4be826ff4b2a44a3c5f6f71c36c4..cc1db125a14a5d0d6f0e9cb568ee43ebab9bd328 100644 (file)
@@ -80,6 +80,7 @@ struct ads7846 {
 #endif
 
        u16                     model;
+       u16                     vref_mv;
        u16                     vref_delay_usecs;
        u16                     x_plate_ohms;
        u16                     pressure_max;
@@ -177,9 +178,6 @@ struct ads7846 {
  * The range is GND..vREF. The ads7843 and ads7835 must use external vREF;
  * ads7846 lets that pin be unconnected, to use internal vREF.
  */
-static unsigned vREF_mV;
-module_param(vREF_mV, uint, 0);
-MODULE_PARM_DESC(vREF_mV, "external vREF voltage, in milliVolts");
 
 struct ser_req {
        u8                      ref_on;
@@ -206,7 +204,6 @@ static int ads7846_read12_ser(struct device *dev, unsigned command)
        struct ads7846          *ts = dev_get_drvdata(dev);
        struct ser_req          *req = kzalloc(sizeof *req, GFP_KERNEL);
        int                     status;
-       int                     uninitialized_var(sample);
        int                     use_internal;
 
        if (!req)
@@ -263,13 +260,13 @@ static int ads7846_read12_ser(struct device *dev, unsigned command)
 
        if (status == 0) {
                /* on-wire is a must-ignore bit, a BE12 value, then padding */
-               sample = be16_to_cpu(req->sample);
-               sample = sample >> 3;
-               sample &= 0x0fff;
+               status = be16_to_cpu(req->sample);
+               status = status >> 3;
+               status &= 0x0fff;
        }
 
        kfree(req);
-       return status ? status : sample;
+       return status;
 }
 
 #if defined(CONFIG_HWMON) || defined(CONFIG_HWMON_MODULE)
@@ -310,7 +307,7 @@ static inline unsigned vaux_adjust(struct ads7846 *ts, ssize_t v)
        unsigned retval = v;
 
        /* external resistors may scale vAUX into 0..vREF */
-       retval *= vREF_mV;
+       retval *= ts->vref_mv;
        retval = retval >> 12;
        return retval;
 }
@@ -368,14 +365,14 @@ static int ads784x_hwmon_register(struct spi_device *spi, struct ads7846 *ts)
        /* hwmon sensors need a reference voltage */
        switch (ts->model) {
        case 7846:
-               if (!vREF_mV) {
+               if (!ts->vref_mv) {
                        dev_dbg(&spi->dev, "assuming 2.5V internal vREF\n");
-                       vREF_mV = 2500;
+                       ts->vref_mv = 2500;
                }
                break;
        case 7845:
        case 7843:
-               if (!vREF_mV) {
+               if (!ts->vref_mv) {
                        dev_warn(&spi->dev,
                                "external vREF for ADS%d not specified\n",
                                ts->model);
@@ -520,7 +517,9 @@ static void ads7846_rx(void *ads)
        if (x == MAX_12BIT)
                x = 0;
 
-       if (likely(x && z1)) {
+       if (ts->model == 7843) {
+               Rt = ts->pressure_max / 2;
+       } else if (likely(x && z1)) {
                /* compute touch pressure resistance using equation #2 */
                Rt = z2;
                Rt -= z1;
@@ -528,11 +527,9 @@ static void ads7846_rx(void *ads)
                Rt *= ts->x_plate_ohms;
                Rt /= z1;
                Rt = (Rt + 2047) >> 12;
-       } else
+       } else {
                Rt = 0;
-
-       if (ts->model == 7843)
-               Rt = ts->pressure_max / 2;
+       }
 
        /* Sample found inconsistent by debouncing or pressure is beyond
         * the maximum. Don't report it to user space, repeat at least
@@ -636,19 +633,17 @@ static void ads7846_rx_val(void *ads)
        struct ads7846 *ts = ads;
        struct spi_message *m;
        struct spi_transfer *t;
-       u16 *rx_val;
        int val;
        int action;
        int status;
 
        m = &ts->msg[ts->msg_idx];
        t = list_entry(m->transfers.prev, struct spi_transfer, transfer_list);
-       rx_val = t->rx_buf;
 
        /* adjust:  on-wire is a must-ignore bit, a BE12 value, then padding;
         * built from two 8 bit values written msb-first.
         */
-       val = be16_to_cpu(*rx_val) >> 3;
+       val = be16_to_cpup((__be16 *)t->rx_buf) >> 3;
 
        action = ts->filter(ts->filter_data, ts->msg_idx, &val);
        switch (action) {
@@ -662,7 +657,7 @@ static void ads7846_rx_val(void *ads)
                m = ts->last_msg;
                break;
        case ADS7846_FILTER_OK:
-               *rx_val = val;
+               *(u16 *)t->rx_buf = val;
                ts->tc.ignore = 0;
                m = &ts->msg[++ts->msg_idx];
                break;
@@ -831,6 +826,15 @@ static int __devinit ads7846_probe(struct spi_device *spi)
                return -ENODEV;
        }
 
+       /* enable voltage */
+       if (pdata->vaux_control != NULL) {
+               err = pdata->vaux_control(VAUX_ENABLE);
+               if (err != 0) {
+                       dev_dbg(&spi->dev, "TS vaux enable failed\n");
+                       return err;
+               }
+       }
+
        /* don't exceed max specified sample rate */
        if (spi->max_speed_hz > (125000 * SAMPLE_BITS)) {
                dev_dbg(&spi->dev, "f(sample) %d KHz?\n",
@@ -868,6 +872,7 @@ static int __devinit ads7846_probe(struct spi_device *spi)
 
        ts->spi = spi;
        ts->input = input_dev;
+       ts->vref_mv = pdata->vref_mv;
 
        hrtimer_init(&ts->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
        ts->timer.function = ads7846_timer;