mfd: Rename twl4030* driver files to enable re-use
[safe/jmp/linux-2.6] / drivers / mfd / twl4030-power.c
index 2c38ac1..424b255 100644 (file)
@@ -26,7 +26,7 @@
 
 #include <linux/module.h>
 #include <linux/pm.h>
-#include <linux/i2c/twl4030.h>
+#include <linux/i2c/twl.h>
 #include <linux/platform_device.h>
 
 #include <asm/mach-types.h>
@@ -75,6 +75,8 @@ static u8 twl4030_start_script_address = 0x2b;
 */
 #define DEV_GRP_OFFSET         0
 #define TYPE_OFFSET            1
+#define REMAP_OFFSET           2
+#define DEDICATED_OFFSET       3
 
 /* Bit positions in the registers */
 
@@ -88,6 +90,12 @@ static u8 twl4030_start_script_address = 0x2b;
 #define TYPE2_SHIFT            3
 #define TYPE2_MASK             (3 << TYPE2_SHIFT)
 
+/* <RESOURCE>_REMAP */
+#define SLEEP_STATE_SHIFT      0
+#define SLEEP_STATE_MASK       (0xf << SLEEP_STATE_SHIFT)
+#define OFF_STATE_SHIFT                4
+#define OFF_STATE_MASK         (0xf << OFF_STATE_SHIFT)
+
 static u8 res_config_addrs[] = {
        [RES_VAUX1]     = 0x17,
        [RES_VAUX2]     = 0x1b,
@@ -325,6 +333,7 @@ static int __init twl4030_configure_resource(struct twl4030_resconfig *rconfig)
        int err;
        u8 type;
        u8 grp;
+       u8 remap;
 
        if (rconfig->resource > TOTAL_RESOURCES) {
                pr_err("TWL4030 Resource %d does not exist\n",
@@ -343,7 +352,7 @@ static int __init twl4030_configure_resource(struct twl4030_resconfig *rconfig)
                return err;
        }
 
-       if (rconfig->devgroup >= 0) {
+       if (rconfig->devgroup != TWL4030_RESCONFIG_UNDEF) {
                grp &= ~DEV_GRP_MASK;
                grp |= rconfig->devgroup << DEV_GRP_SHIFT;
                err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
@@ -363,12 +372,12 @@ static int __init twl4030_configure_resource(struct twl4030_resconfig *rconfig)
                return err;
        }
 
-       if (rconfig->type >= 0) {
+       if (rconfig->type != TWL4030_RESCONFIG_UNDEF) {
                type &= ~TYPE_MASK;
                type |= rconfig->type << TYPE_SHIFT;
        }
 
-       if (rconfig->type2 >= 0) {
+       if (rconfig->type2 != TWL4030_RESCONFIG_UNDEF) {
                type &= ~TYPE2_MASK;
                type |= rconfig->type2 << TYPE2_SHIFT;
        }
@@ -380,6 +389,33 @@ static int __init twl4030_configure_resource(struct twl4030_resconfig *rconfig)
                return err;
        }
 
+       /* Set remap states */
+       err = twl4030_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER, &remap,
+                               rconfig_addr + REMAP_OFFSET);
+       if (err < 0) {
+               pr_err("TWL4030 Resource %d remap could not be read\n",
+                       rconfig->resource);
+               return err;
+       }
+
+       if (rconfig->remap_off != TWL4030_RESCONFIG_UNDEF) {
+               remap &= ~OFF_STATE_MASK;
+               remap |= rconfig->remap_off << OFF_STATE_SHIFT;
+       }
+
+       if (rconfig->remap_sleep != TWL4030_RESCONFIG_UNDEF) {
+               remap &= ~SLEEP_STATE_MASK;
+               remap |= rconfig->remap_off << SLEEP_STATE_SHIFT;
+       }
+
+       err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
+                               remap,
+                               rconfig_addr + REMAP_OFFSET);
+       if (err < 0) {
+               pr_err("TWL4030 failed to program remap\n");
+               return err;
+       }
+
        return 0;
 }