[ALSA] aica - fix behaviour in poor resource conditions
[pandora-kernel.git] / drivers / hwmon / hdaps.c
index e8ef62b..e0cf5e6 100644 (file)
 #include <linux/platform_device.h>
 #include <linux/input.h>
 #include <linux/kernel.h>
+#include <linux/mutex.h>
 #include <linux/module.h>
 #include <linux/timer.h>
 #include <linux/dmi.h>
 #include <linux/jiffies.h>
+
 #include <asm/io.h>
 
 #define HDAPS_LOW_PORT         0x1600  /* first port used by hdaps */
@@ -71,10 +73,10 @@ static u8 km_activity;
 static int rest_x;
 static int rest_y;
 
-static DECLARE_MUTEX(hdaps_sem);
+static DEFINE_MUTEX(hdaps_mtx);
 
 /*
- * __get_latch - Get the value from a given port.  Callers must hold hdaps_sem.
+ * __get_latch - Get the value from a given port.  Callers must hold hdaps_mtx.
  */
 static inline u8 __get_latch(u16 port)
 {
@@ -83,7 +85,7 @@ static inline u8 __get_latch(u16 port)
 
 /*
  * __check_latch - Check a port latch for a given value.  Returns zero if the
- * port contains the given value.  Callers must hold hdaps_sem.
+ * port contains the given value.  Callers must hold hdaps_mtx.
  */
 static inline int __check_latch(u16 port, u8 val)
 {
@@ -94,7 +96,7 @@ static inline int __check_latch(u16 port, u8 val)
 
 /*
  * __wait_latch - Wait up to 100us for a port latch to get a certain value,
- * returning zero if the value is obtained.  Callers must hold hdaps_sem.
+ * returning zero if the value is obtained.  Callers must hold hdaps_mtx.
  */
 static int __wait_latch(u16 port, u8 val)
 {
@@ -111,7 +113,7 @@ static int __wait_latch(u16 port, u8 val)
 
 /*
  * __device_refresh - request a refresh from the accelerometer.  Does not wait
- * for refresh to complete.  Callers must hold hdaps_sem.
+ * for refresh to complete.  Callers must hold hdaps_mtx.
  */
 static void __device_refresh(void)
 {
@@ -125,7 +127,7 @@ static void __device_refresh(void)
 /*
  * __device_refresh_sync - request a synchronous refresh from the
  * accelerometer.  We wait for the refresh to complete.  Returns zero if
- * successful and nonzero on error.  Callers must hold hdaps_sem.
+ * successful and nonzero on error.  Callers must hold hdaps_mtx.
  */
 static int __device_refresh_sync(void)
 {
@@ -135,7 +137,7 @@ static int __device_refresh_sync(void)
 
 /*
  * __device_complete - indicate to the accelerometer that we are done reading
- * data, and then initiate an async refresh.  Callers must hold hdaps_sem.
+ * data, and then initiate an async refresh.  Callers must hold hdaps_mtx.
  */
 static inline void __device_complete(void)
 {
@@ -153,7 +155,7 @@ static int hdaps_readb_one(unsigned int port, u8 *val)
 {
        int ret;
 
-       down(&hdaps_sem);
+       mutex_lock(&hdaps_mtx);
 
        /* do a sync refresh -- we need to be sure that we read fresh data */
        ret = __device_refresh_sync();
@@ -164,7 +166,7 @@ static int hdaps_readb_one(unsigned int port, u8 *val)
        __device_complete();
 
 out:
-       up(&hdaps_sem);
+       mutex_unlock(&hdaps_mtx);
        return ret;
 }
 
@@ -199,9 +201,9 @@ static int hdaps_read_pair(unsigned int port1, unsigned int port2,
 {
        int ret;
 
-       down(&hdaps_sem);
+       mutex_lock(&hdaps_mtx);
        ret = __hdaps_read_pair(port1, port2, val1, val2);
-       up(&hdaps_sem);
+       mutex_unlock(&hdaps_mtx);
 
        return ret;
 }
@@ -214,7 +216,7 @@ static int hdaps_device_init(void)
 {
        int total, ret = -ENXIO;
 
-       down(&hdaps_sem);
+       mutex_lock(&hdaps_mtx);
 
        outb(0x13, 0x1610);
        outb(0x01, 0x161f);
@@ -280,7 +282,7 @@ static int hdaps_device_init(void)
        }
 
 out:
-       up(&hdaps_sem);
+       mutex_unlock(&hdaps_mtx);
        return ret;
 }
 
@@ -314,7 +316,7 @@ static struct platform_driver hdaps_driver = {
 };
 
 /*
- * hdaps_calibrate - Set our "resting" values.  Callers must hold hdaps_sem.
+ * hdaps_calibrate - Set our "resting" values.  Callers must hold hdaps_mtx.
  */
 static void hdaps_calibrate(void)
 {
@@ -326,7 +328,7 @@ static void hdaps_mousedev_poll(unsigned long unused)
        int x, y;
 
        /* Cannot sleep.  Try nonblockingly.  If we fail, try again later. */
-       if (down_trylock(&hdaps_sem)) {
+       if (mutex_trylock(&hdaps_mtx)) {
                mod_timer(&hdaps_timer,jiffies + HDAPS_POLL_PERIOD);
                return;
        }
@@ -341,7 +343,7 @@ static void hdaps_mousedev_poll(unsigned long unused)
        mod_timer(&hdaps_timer, jiffies + HDAPS_POLL_PERIOD);
 
 out:
-       up(&hdaps_sem);
+       mutex_unlock(&hdaps_mtx);
 }
 
 
@@ -421,9 +423,9 @@ static ssize_t hdaps_calibrate_store(struct device *dev,
                                     struct device_attribute *attr,
                                     const char *buf, size_t count)
 {
-       down(&hdaps_sem);
+       mutex_lock(&hdaps_mtx);
        hdaps_calibrate();
-       up(&hdaps_sem);
+       mutex_unlock(&hdaps_mtx);
 
        return count;
 }
@@ -478,74 +480,64 @@ static struct attribute_group hdaps_attribute_group = {
 /* Module stuff */
 
 /* hdaps_dmi_match - found a match.  return one, short-circuiting the hunt. */
-static int hdaps_dmi_match(struct dmi_system_id *id)
+static int __init hdaps_dmi_match(struct dmi_system_id *id)
 {
        printk(KERN_INFO "hdaps: %s detected.\n", id->ident);
        return 1;
 }
 
 /* hdaps_dmi_match_invert - found an inverted match. */
-static int hdaps_dmi_match_invert(struct dmi_system_id *id)
+static int __init hdaps_dmi_match_invert(struct dmi_system_id *id)
 {
        hdaps_invert = 1;
        printk(KERN_INFO "hdaps: inverting axis readings.\n");
        return hdaps_dmi_match(id);
 }
 
-#define HDAPS_DMI_MATCH_NORMAL(model)  {               \
-       .ident = "IBM " model,                          \
+#define HDAPS_DMI_MATCH_NORMAL(vendor, model) {                \
+       .ident = vendor " " model,                      \
        .callback = hdaps_dmi_match,                    \
        .matches = {                                    \
-               DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),     \
+               DMI_MATCH(DMI_BOARD_VENDOR, vendor),    \
                DMI_MATCH(DMI_PRODUCT_VERSION, model)   \
        }                                               \
 }
 
-#define HDAPS_DMI_MATCH_INVERT(model)  {               \
-       .ident = "IBM " model,                          \
+#define HDAPS_DMI_MATCH_INVERT(vendor, model) {                \
+       .ident = vendor " " model,                      \
        .callback = hdaps_dmi_match_invert,             \
        .matches = {                                    \
-               DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),     \
+               DMI_MATCH(DMI_BOARD_VENDOR, vendor),    \
                DMI_MATCH(DMI_PRODUCT_VERSION, model)   \
        }                                               \
 }
 
-#define HDAPS_DMI_MATCH_LENOVO(model)   {               \
-        .ident = "Lenovo " model,                       \
-        .callback = hdaps_dmi_match_invert,             \
-        .matches = {                                    \
-                DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"),  \
-                DMI_MATCH(DMI_PRODUCT_VERSION, model)   \
-        }                                               \
-}
+/* Note that HDAPS_DMI_MATCH_NORMAL("ThinkPad T42") would match
+   "ThinkPad T42p", so the order of the entries matters.
+   If your ThinkPad is not recognized, please update to latest
+   BIOS. This is especially the case for some R52 ThinkPads. */
+static struct dmi_system_id __initdata hdaps_whitelist[] = {
+       HDAPS_DMI_MATCH_INVERT("IBM", "ThinkPad R50p"),
+       HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad R50"),
+       HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad R51"),
+       HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad R52"),
+       HDAPS_DMI_MATCH_INVERT("IBM", "ThinkPad T41p"),
+       HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T41"),
+       HDAPS_DMI_MATCH_INVERT("IBM", "ThinkPad T42p"),
+       HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T42"),
+       HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T43"),
+       HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad T60"),
+       HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad X40"),
+       HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad X41"),
+       HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad X60"),
+       HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad Z60m"),
+       { .ident = NULL }
+};
 
 static int __init hdaps_init(void)
 {
        int ret;
 
-       /* Note that HDAPS_DMI_MATCH_NORMAL("ThinkPad T42") would match
-         "ThinkPad T42p", so the order of the entries matters */
-       struct dmi_system_id hdaps_whitelist[] = {
-               HDAPS_DMI_MATCH_NORMAL("ThinkPad H"),
-               HDAPS_DMI_MATCH_INVERT("ThinkPad R50p"),
-               HDAPS_DMI_MATCH_NORMAL("ThinkPad R50"),
-               HDAPS_DMI_MATCH_NORMAL("ThinkPad R51"),
-               HDAPS_DMI_MATCH_NORMAL("ThinkPad R52"),
-               HDAPS_DMI_MATCH_NORMAL("ThinkPad H"),    /* R52 (1846AQG) */
-               HDAPS_DMI_MATCH_INVERT("ThinkPad T41p"),
-               HDAPS_DMI_MATCH_NORMAL("ThinkPad T41"),
-               HDAPS_DMI_MATCH_INVERT("ThinkPad T42p"),
-               HDAPS_DMI_MATCH_NORMAL("ThinkPad T42"),
-               HDAPS_DMI_MATCH_NORMAL("ThinkPad T43"),
-               HDAPS_DMI_MATCH_LENOVO("ThinkPad T60p"),
-               HDAPS_DMI_MATCH_LENOVO("ThinkPad T60"),
-               HDAPS_DMI_MATCH_NORMAL("ThinkPad X40"),
-               HDAPS_DMI_MATCH_NORMAL("ThinkPad X41"),
-               HDAPS_DMI_MATCH_LENOVO("ThinkPad X60"),
-               HDAPS_DMI_MATCH_NORMAL("ThinkPad Z60m"),
-               { .ident = NULL }
-       };
-
        if (!dmi_check_system(hdaps_whitelist)) {
                printk(KERN_WARNING "hdaps: supported laptop not found!\n");
                ret = -ENODEV;
@@ -582,7 +574,7 @@ static int __init hdaps_init(void)
 
        /* initialize the input class */
        hdaps_idev->name = "hdaps";
-       hdaps_idev->cdev.dev = &pdev->dev;
+       hdaps_idev->dev.parent = &pdev->dev;
        hdaps_idev->evbit[0] = BIT(EV_ABS);
        input_set_abs_params(hdaps_idev, ABS_X,
                        -256, 256, HDAPS_INPUT_FUZZ, HDAPS_INPUT_FLAT);