patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / drivers / input / joystick / analog.c
index d76c5fb..3e83968 100644 (file)
 /*
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or 
+ * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- * 
+ *
  * Should you need to contact me, the author, you can do so either by
  * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
  * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
@@ -142,7 +142,7 @@ struct analog_port {
 
 #ifdef __i386__
 #define GET_TIME(x)    do { if (cpu_has_tsc) rdtscl(x); else x = get_time_pit(); } while (0)
-#define DELTA(x,y)     (cpu_has_tsc?((y)-(x)):((x)-(y)+((x)<(y)?1193182L/HZ:0)))
+#define DELTA(x,y)     (cpu_has_tsc ? ((y) - (x)) : ((x) - (y) + ((x) < (y) ? CLOCK_TICK_RATE / HZ : 0)))
 #define TIME_NAME      (cpu_has_tsc?"TSC":"PIT")
 static unsigned int get_time_pit(void)
 {
@@ -237,7 +237,7 @@ static int analog_cooked_read(struct analog_port *port)
 
        loopout = (ANALOG_LOOP_TIME * port->loop) / 1000;
        timeout = ANALOG_MAX_TIME * port->speed;
-       
+
        local_irq_save(flags);
        gameport_trigger(gameport);
        GET_TIME(now);
@@ -284,7 +284,7 @@ static int analog_button_read(struct analog_port *port, char saitek, char chf)
 
        u = gameport_read(port->gameport);
 
-       if (!chf) { 
+       if (!chf) {
                port->buttons = (~u >> 4) & 0xf;
                return 0;
        }
@@ -333,7 +333,7 @@ static void analog_timer(unsigned long data)
                }
        }
 
-       for (i = 0; i < 2; i++) 
+       for (i = 0; i < 2; i++)
                if (port->analog[i].mask)
                        analog_decode(port->analog + i, port->axes, port->initial, port->buttons);
 
@@ -348,7 +348,7 @@ static int analog_open(struct input_dev *dev)
 {
        struct analog_port *port = dev->private;
        if (!port->used++)
-               mod_timer(&port->timer, jiffies + ANALOG_REFRESH_TIME); 
+               mod_timer(&port->timer, jiffies + ANALOG_REFRESH_TIME);
        return 0;
 }
 
@@ -408,7 +408,7 @@ static void analog_calibrate_timer(struct analog_port *port)
 
 static void analog_name(struct analog *analog)
 {
-       sprintf(analog->name, "Analog %d-axis %d-button", 
+       sprintf(analog->name, "Analog %d-axis %d-button",
                hweight8(analog->mask & ANALOG_AXES_STD),
                hweight8(analog->mask & ANALOG_BTNS_STD) + !!(analog->mask & ANALOG_BTNS_CHF) * 2 +
                hweight16(analog->mask & ANALOG_BTNS_GAMEPAD) + !!(analog->mask & ANALOG_HBTN_CHF) * 4);
@@ -450,10 +450,10 @@ static void analog_init_device(struct analog_port *port, struct analog *analog,
        analog->dev.close = analog_close;
        analog->dev.private = port;
        analog->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
-       
+
        for (i = j = 0; i < 4; i++)
                if (analog->mask & (1 << i)) {
-                       
+
                        t = analog_axes[j];
                        x = port->axes[i];
                        y = (port->axes[0] + port->axes[1]) >> 1;
@@ -481,8 +481,8 @@ static void analog_init_device(struct analog_port *port, struct analog *analog,
                        j++;
                }
 
-       for (i = j = 0; i < 3; i++) 
-               if (analog->mask & analog_exts[i]) 
+       for (i = j = 0; i < 3; i++)
+               if (analog->mask & analog_exts[i])
                        for (x = 0; x < 2; x++) {
                                t = analog_hats[j++];
                                set_bit(t, analog->dev.absbit);
@@ -517,7 +517,7 @@ static void analog_init_device(struct analog_port *port, struct analog *analog,
        else
                printk(" [%s timer, %d %sHz clock, %d ns res]\n", TIME_NAME,
                port->speed > 10000 ? (port->speed + 800) / 1000 : port->speed,
-               port->speed > 10000 ? "M" : "k", 
+               port->speed > 10000 ? "M" : "k",
                port->speed > 10000 ? (port->loop * 1000) / (port->speed / 1000)
                                    : (port->loop * 1000000) / port->speed);
 }
@@ -580,11 +580,11 @@ static int analog_init_masks(struct analog_port *port)
 
                gameport_calibrate(port->gameport, port->axes, max);
        }
-               
-       for (i = 0; i < 4; i++) 
+
+       for (i = 0; i < 4; i++)
                port->initial[i] = port->axes[i];
 
-       return -!(analog[0].mask || analog[1].mask);    
+       return -!(analog[0].mask || analog[1].mask);
 }
 
 static int analog_init_port(struct gameport *gameport, struct gameport_dev *dev, struct analog_port *port)
@@ -603,25 +603,25 @@ static int analog_init_port(struct gameport *gameport, struct gameport_dev *dev,
 
                gameport_trigger(gameport);
                t = gameport_read(gameport);
-               wait_ms(ANALOG_MAX_TIME);
+               msleep(ANALOG_MAX_TIME);
                port->mask = (gameport_read(gameport) ^ t) & t & 0xf;
                port->fuzz = (port->speed * ANALOG_FUZZ_MAGIC) / port->loop / 1000 + ANALOG_FUZZ_BITS;
-       
+
                for (i = 0; i < ANALOG_INIT_RETRIES; i++) {
                        if (!analog_cooked_read(port)) break;
-                       wait_ms(ANALOG_MAX_TIME);
+                       msleep(ANALOG_MAX_TIME);
                }
 
                u = v = 0;
 
-               wait_ms(ANALOG_MAX_TIME);
+               msleep(ANALOG_MAX_TIME);
                t = gameport_time(gameport, ANALOG_MAX_TIME * 1000);
                gameport_trigger(gameport);
-               while ((gameport_read(port->gameport) & port->mask) && (u < t)) u++; 
+               while ((gameport_read(port->gameport) & port->mask) && (u < t)) u++;
                udelay(ANALOG_SAITEK_DELAY);
                t = gameport_time(gameport, ANALOG_SAITEK_TIME);
                gameport_trigger(gameport);
-               while ((gameport_read(port->gameport) & port->mask) && (v < t)) v++; 
+               while ((gameport_read(port->gameport) & port->mask) && (v < t)) v++;
 
                if (v < (u >> 1)) { /* FIXME - more than one port */
                        analog_options[0] |= /* FIXME - more than one port */
@@ -721,7 +721,7 @@ static void analog_parse_options(void)
                        if (!strcmp(analog_types[j].name, js[i])) {
                                analog_options[i] = analog_types[j].value;
                                break;
-                       } 
+                       }
                if (analog_types[j].name) continue;
 
                analog_options[i] = simple_strtoul(js[i], &end, 0);