mfd: 88pm860x: Use REG in leds resource
authorHaojian Zhuang <haojian.zhuang@gmail.com>
Wed, 8 Aug 2012 15:17:27 +0000 (23:17 +0800)
committerSamuel Ortiz <sameo@linux.intel.com>
Tue, 11 Sep 2012 09:38:09 +0000 (11:38 +0200)
Since the resources of 88pm860x leds are changed from IORESOURCE_IO
to IORESOURCE_REG that is register offset, change the original
self-defined IORESOURCE_IO to register offset.

Signed-off-by: Haojian Zhuang <haojian.zhuang@gmail.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
drivers/leds/leds-88pm860x.c
drivers/mfd/88pm860x-core.c
include/linux/mfd/88pm860x.h

index ea2615b25082c89916f1a7d40b6b8fea5b44cafa..70232b1756f9bfb6e907e61f2a8d6b6671f36e9c 100644 (file)
 #include <linux/mfd/88pm860x.h>
 #include <linux/module.h>
 
-#define LED_PWM_SHIFT          (3)
 #define LED_PWM_MASK           (0x1F)
 #define LED_CURRENT_MASK       (0x07 << 5)
 
-#define LED_BLINK_ON_MASK      (0x07)
 #define LED_BLINK_MASK         (0x7F)
 
-#define LED_BLINK_ON(x)                ((x & 0x7) * 66 + 66)
-#define LED_BLINK_ON_MIN       LED_BLINK_ON(0)
-#define LED_BLINK_ON_MAX       LED_BLINK_ON(0x7)
 #define LED_ON_CONTINUOUS      (0x0F << 3)
-#define LED_TO_ON(x)           ((x - 66) / 66)
 
 #define LED1_BLINK_EN          (1 << 1)
 #define LED2_BLINK_EN          (1 << 2)
@@ -49,85 +43,25 @@ struct pm860x_led {
        unsigned char brightness;
        unsigned char current_brightness;
 
-       int blink_data;
-       int blink_time;
-       int blink_on;
-       int blink_off;
+       int reg_control;
+       int reg_blink;
+       int blink_mask;
 };
 
-/* return offset of color register */
-static inline int __led_off(int port)
-{
-       int ret = -EINVAL;
-
-       switch (port) {
-       case PM8606_LED1_RED:
-       case PM8606_LED1_GREEN:
-       case PM8606_LED1_BLUE:
-               ret = port - PM8606_LED1_RED + PM8606_RGB1B;
-               break;
-       case PM8606_LED2_RED:
-       case PM8606_LED2_GREEN:
-       case PM8606_LED2_BLUE:
-               ret = port - PM8606_LED2_RED + PM8606_RGB2B;
-               break;
-       }
-       return ret;
-}
-
-/* return offset of blink register */
-static inline int __blink_off(int port)
-{
-       int ret = -EINVAL;
-
-       switch (port) {
-       case PM8606_LED1_RED:
-       case PM8606_LED1_GREEN:
-       case PM8606_LED1_BLUE:
-               ret = PM8606_RGB1A;
-               break;
-       case PM8606_LED2_RED:
-       case PM8606_LED2_GREEN:
-       case PM8606_LED2_BLUE:
-               ret = PM8606_RGB2A;
-               break;
-       }
-       return ret;
-}
-
-static inline int __blink_ctl_mask(int port)
-{
-       int ret = -EINVAL;
-
-       switch (port) {
-       case PM8606_LED1_RED:
-       case PM8606_LED1_GREEN:
-       case PM8606_LED1_BLUE:
-               ret = LED1_BLINK_EN;
-               break;
-       case PM8606_LED2_RED:
-       case PM8606_LED2_GREEN:
-       case PM8606_LED2_BLUE:
-               ret = LED2_BLINK_EN;
-               break;
-       }
-       return ret;
-}
-
 static int led_power_set(struct pm860x_chip *chip, int port, int on)
 {
        int ret = -EINVAL;
 
        switch (port) {
-       case PM8606_LED1_RED:
-       case PM8606_LED1_GREEN:
-       case PM8606_LED1_BLUE:
+       case 0:
+       case 1:
+       case 2:
                ret = on ? pm8606_osc_enable(chip, RGB1_ENABLE) :
                        pm8606_osc_disable(chip, RGB1_ENABLE);
                break;
-       case PM8606_LED2_RED:
-       case PM8606_LED2_GREEN:
-       case PM8606_LED2_BLUE:
+       case 3:
+       case 4:
+       case 5:
                ret = on ? pm8606_osc_enable(chip, RGB2_ENABLE) :
                        pm8606_osc_disable(chip, RGB2_ENABLE);
                break;
@@ -141,7 +75,7 @@ static void pm860x_led_work(struct work_struct *work)
        struct pm860x_led *led;
        struct pm860x_chip *chip;
        unsigned char buf[3];
-       int mask, ret;
+       int ret;
 
        led = container_of(work, struct pm860x_led, work);
        chip = led->chip;
@@ -149,34 +83,34 @@ static void pm860x_led_work(struct work_struct *work)
        if ((led->current_brightness == 0) && led->brightness) {
                led_power_set(chip, led->port, 1);
                if (led->iset) {
-                       pm860x_set_bits(led->i2c, __led_off(led->port),
+                       pm860x_set_bits(led->i2c, led->reg_control,
                                        LED_CURRENT_MASK, led->iset);
                }
-               pm860x_set_bits(led->i2c, __blink_off(led->port),
+               pm860x_set_bits(led->i2c, led->reg_blink,
                                LED_BLINK_MASK, LED_ON_CONTINUOUS);
-               mask = __blink_ctl_mask(led->port);
-               pm860x_set_bits(led->i2c, PM8606_WLED3B, mask, mask);
+               pm860x_set_bits(led->i2c, PM8606_WLED3B, led->blink_mask,
+                               led->blink_mask);
        }
-       pm860x_set_bits(led->i2c, __led_off(led->port), LED_PWM_MASK,
+       pm860x_set_bits(led->i2c, led->reg_control, LED_PWM_MASK,
                        led->brightness);
 
        if (led->brightness == 0) {
-               pm860x_bulk_read(led->i2c, __led_off(led->port), 3, buf);
+               pm860x_bulk_read(led->i2c, led->reg_control, 3, buf);
                ret = buf[0] & LED_PWM_MASK;
                ret |= buf[1] & LED_PWM_MASK;
                ret |= buf[2] & LED_PWM_MASK;
                if (ret == 0) {
                        /* unset current since no led is lighting */
-                       pm860x_set_bits(led->i2c, __led_off(led->port),
+                       pm860x_set_bits(led->i2c, led->reg_control,
                                        LED_CURRENT_MASK, 0);
-                       mask = __blink_ctl_mask(led->port);
-                       pm860x_set_bits(led->i2c, PM8606_WLED3B, mask, 0);
+                       pm860x_set_bits(led->i2c, PM8606_WLED3B,
+                                       led->blink_mask, 0);
                        led_power_set(chip, led->port, 0);
                }
        }
        led->current_brightness = led->brightness;
        dev_dbg(chip->dev, "Update LED. (reg:%d, brightness:%d)\n",
-               __led_off(led->port), led->brightness);
+               led->reg_control, led->brightness);
        mutex_unlock(&led->lock);
 }
 
@@ -192,36 +126,61 @@ static void pm860x_led_set(struct led_classdev *cdev,
 static int pm860x_led_probe(struct platform_device *pdev)
 {
        struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
-       struct pm860x_led_pdata *pdata;
+       struct pm860x_led_pdata *pdata = pdev->dev.platform_data;
        struct pm860x_led *data;
        struct resource *res;
-       int ret;
-
-       res = platform_get_resource(pdev, IORESOURCE_REG, 0);
-       if (res == NULL) {
-               dev_err(&pdev->dev, "No I/O resource!\n");
-               return -EINVAL;
-       }
-
-       pdata = pdev->dev.platform_data;
-       if (pdata == NULL) {
-               dev_err(&pdev->dev, "No platform data!\n");
-               return -EINVAL;
-       }
+       int ret = 0;
 
        data = devm_kzalloc(&pdev->dev, sizeof(struct pm860x_led), GFP_KERNEL);
        if (data == NULL)
                return -ENOMEM;
-       strncpy(data->name, res->name, MFD_NAME_SIZE - 1);
+       res = platform_get_resource_byname(pdev, IORESOURCE_REG, "control");
+       if (!res) {
+               dev_err(&pdev->dev, "No REG resource for control\n");
+               ret = -ENXIO;
+               goto out;
+       }
+       data->reg_control = res->start;
+       res = platform_get_resource_byname(pdev, IORESOURCE_REG, "blink");
+       if (!res) {
+               dev_err(&pdev->dev, "No REG resource for blink\n");
+               ret = -ENXIO;
+               goto out;
+       }
+       data->reg_blink = res->start;
+       memset(data->name, 0, MFD_NAME_SIZE);
+       switch (pdev->id) {
+       case 0:
+               data->blink_mask = LED1_BLINK_EN;
+               sprintf(data->name, "led0-red");
+               break;
+       case 1:
+               data->blink_mask = LED1_BLINK_EN;
+               sprintf(data->name, "led0-green");
+               break;
+       case 2:
+               data->blink_mask = LED1_BLINK_EN;
+               sprintf(data->name, "led0-blue");
+               break;
+       case 3:
+               data->blink_mask = LED2_BLINK_EN;
+               sprintf(data->name, "led1-red");
+               break;
+       case 4:
+               data->blink_mask = LED2_BLINK_EN;
+               sprintf(data->name, "led1-green");
+               break;
+       case 5:
+               data->blink_mask = LED2_BLINK_EN;
+               sprintf(data->name, "led1-blue");
+               break;
+       }
        dev_set_drvdata(&pdev->dev, data);
        data->chip = chip;
        data->i2c = (chip->id == CHIP_PM8606) ? chip->client : chip->companion;
-       data->iset = pdata->iset;
-       data->port = pdata->flags;
-       if (data->port < 0) {
-               dev_err(&pdev->dev, "check device failed\n");
-               return -EINVAL;
-       }
+       data->port = pdev->id;
+       if (pdata && pdata->iset)
+               data->iset = pdata->iset;
 
        data->current_brightness = 0;
        data->cdev.name = data->name;
@@ -236,6 +195,9 @@ static int pm860x_led_probe(struct platform_device *pdev)
        }
        pm860x_led_set(&data->cdev, 0);
        return 0;
+out:
+       devm_kfree(&pdev->dev, data);
+       return ret;
 }
 
 static int pm860x_led_remove(struct platform_device *pdev)
index b72628e8d6ee4081527b5c80335e29560ba31b65..e364b22f957d70336df1ab1dfa12980520f991a3 100644 (file)
@@ -37,13 +37,35 @@ static struct resource bk2_resources[] __devinitdata = {
        {5, 5, "current",    IORESOURCE_REG, },
 };
 
-static struct resource led_resources[] __devinitdata = {
-       {PM8606_LED1_RED,   PM8606_LED1_RED,   "led0-red",   IORESOURCE_REG,},
-       {PM8606_LED1_GREEN, PM8606_LED1_GREEN, "led0-green", IORESOURCE_REG,},
-       {PM8606_LED1_BLUE,  PM8606_LED1_BLUE,  "led0-blue",  IORESOURCE_REG,},
-       {PM8606_LED2_RED,   PM8606_LED2_RED,   "led1-red",   IORESOURCE_REG,},
-       {PM8606_LED2_GREEN, PM8606_LED2_GREEN, "led1-green", IORESOURCE_REG,},
-       {PM8606_LED2_BLUE,  PM8606_LED2_BLUE,  "led1-blue",  IORESOURCE_REG,},
+static struct resource led0_resources[] __devinitdata = {
+       /* RGB1 Red LED */
+       {0xd, 0xd, "control", IORESOURCE_REG, },
+       {0xc, 0xc, "blink",   IORESOURCE_REG, },
+};
+static struct resource led1_resources[] __devinitdata = {
+       /* RGB1 Green LED */
+       {0xe, 0xe, "control", IORESOURCE_REG, },
+       {0xc, 0xc, "blink",   IORESOURCE_REG, },
+};
+static struct resource led2_resources[] __devinitdata = {
+       /* RGB1 Blue LED */
+       {0xf, 0xf, "control", IORESOURCE_REG, },
+       {0xc, 0xc, "blink",   IORESOURCE_REG, },
+};
+static struct resource led3_resources[] __devinitdata = {
+       /* RGB2 Red LED */
+       {0x9, 0x9, "control", IORESOURCE_REG, },
+       {0x8, 0x8, "blink",   IORESOURCE_REG, },
+};
+static struct resource led4_resources[] __devinitdata = {
+       /* RGB2 Green LED */
+       {0xa, 0xa, "control", IORESOURCE_REG, },
+       {0x8, 0x8, "blink",   IORESOURCE_REG, },
+};
+static struct resource led5_resources[] __devinitdata = {
+       /* RGB2 Blue LED */
+       {0xb, 0xb, "control", IORESOURCE_REG, },
+       {0x8, 0x8, "blink",   IORESOURCE_REG, },
 };
 
 static struct resource regulator_resources[] __devinitdata = {
@@ -128,12 +150,37 @@ static struct mfd_cell bk_devs[] = {
 };
 
 static struct mfd_cell led_devs[] = {
-       {"88pm860x-led", 0,},
-       {"88pm860x-led", 1,},
-       {"88pm860x-led", 2,},
-       {"88pm860x-led", 3,},
-       {"88pm860x-led", 4,},
-       {"88pm860x-led", 5,},
+       {
+               .name = "88pm860x-led",
+               .id = 0,
+               .num_resources = ARRAY_SIZE(led0_resources),
+               .resources = led0_resources,
+       }, {
+               .name = "88pm860x-led",
+               .id = 1,
+               .num_resources = ARRAY_SIZE(led1_resources),
+               .resources = led1_resources,
+       }, {
+               .name = "88pm860x-led",
+               .id = 2,
+               .num_resources = ARRAY_SIZE(led2_resources),
+               .resources = led2_resources,
+       }, {
+               .name = "88pm860x-led",
+               .id = 3,
+               .num_resources = ARRAY_SIZE(led3_resources),
+               .resources = led3_resources,
+       }, {
+               .name = "88pm860x-led",
+               .id = 4,
+               .num_resources = ARRAY_SIZE(led4_resources),
+               .resources = led4_resources,
+       }, {
+               .name = "88pm860x-led",
+               .id = 5,
+               .num_resources = ARRAY_SIZE(led5_resources),
+               .resources = led5_resources,
+       },
 };
 
 static struct mfd_cell regulator_devs[] = {
@@ -658,36 +705,23 @@ static void __devinit device_bk_init(struct pm860x_chip *chip,
 static void __devinit device_led_init(struct pm860x_chip *chip,
                                      struct pm860x_platform_data *pdata)
 {
-       int ret;
-       int i, j, id;
-
-       if ((pdata == NULL) || (pdata->led == NULL))
-               return;
+       int ret, i;
 
-       if (pdata->num_leds > ARRAY_SIZE(led_devs))
-               pdata->num_leds = ARRAY_SIZE(led_devs);
-
-       for (i = 0; i < pdata->num_leds; i++) {
-               led_devs[i].platform_data = &pdata->led[i];
-               led_devs[i].pdata_size = sizeof(struct pm860x_led_pdata);
-
-               for (j = 0; j < ARRAY_SIZE(led_devs); j++) {
-                       id = led_resources[j].start;
-                       if (pdata->led[i].flags != id)
-                               continue;
-
-                       led_devs[i].num_resources = 1;
-                       led_devs[i].resources = &led_resources[j],
-                       ret = mfd_add_devices(chip->dev, 0,
-                                             &led_devs[i], 1,
-                                             &led_resources[j], 0);
-                       if (ret < 0) {
-                               dev_err(chip->dev, "Failed to add "
-                                       "led subdev\n");
-                               return;
-                       }
+       if (pdata && pdata->led) {
+               if (pdata->num_leds > ARRAY_SIZE(led_devs))
+                       pdata->num_leds = ARRAY_SIZE(led_devs);
+               for (i = 0; i < pdata->num_leds; i++) {
+                       led_devs[i].platform_data = &pdata->led[i];
+                       led_devs[i].pdata_size =
+                               sizeof(struct pm860x_led_pdata);
                }
        }
+       ret = mfd_add_devices(chip->dev, 0, led_devs,
+                             ARRAY_SIZE(led_devs), NULL, 0);
+       if (ret < 0) {
+               dev_err(chip->dev, "Failed to add led subdev\n");
+               return;
+       }
 }
 
 static void __devinit device_regulator_init(struct pm860x_chip *chip,
index b7e656d29be3a3c5e77058772c96fd46addcc540..2d042f972c686f08393ae27ee9f37e2ed3c38fd0 100644 (file)
@@ -34,16 +34,6 @@ enum {
        PM8606_ID_MAX,
 };
 
-enum {
-       PM8606_LED1_RED = 0,
-       PM8606_LED1_GREEN,
-       PM8606_LED1_BLUE,
-       PM8606_LED2_RED,
-       PM8606_LED2_GREEN,
-       PM8606_LED2_BLUE,
-       PM8607_LED_VIBRATOR,
-};
-
 
 /* 8606 Registers */
 #define PM8606_DCM_BOOST               (0x00)
@@ -339,9 +329,7 @@ struct pm860x_backlight_pdata {
 };
 
 struct pm860x_led_pdata {
-       int             id;
        int             iset;
-       unsigned long   flags;
 };
 
 struct pm860x_rtc_pdata {