regulator: core: support of supply name through desc
[linux-2.6.git] / drivers / regulator / ad5398.c
index 6de6bda..26d23ad 100644 (file)
@@ -25,7 +25,7 @@ struct ad5398_chip_info {
        unsigned int current_level;
        unsigned int current_mask;
        unsigned int current_offset;
-       struct regulator_dev rdev;
+       struct regulator_dev *rdev;
 };
 
 static int ad5398_calc_current(struct ad5398_chip_info *chip,
@@ -94,8 +94,8 @@ static int ad5398_set_current_limit(struct regulator_dev *rdev, int min_uA, int
        if (max_uA > chip->max_uA || max_uA < chip->min_uA)
                return -EINVAL;
 
-       selector = ((min_uA - chip->min_uA) * chip->current_level +
-                       range_uA - 1) / range_uA;
+       selector = DIV_ROUND_UP((min_uA - chip->min_uA) * chip->current_level,
+                               range_uA);
        if (ad5398_calc_current(chip, selector) > max_uA)
                return -EINVAL;
 
@@ -211,7 +211,6 @@ MODULE_DEVICE_TABLE(i2c, ad5398_id);
 static int __devinit ad5398_probe(struct i2c_client *client,
                                const struct i2c_device_id *id)
 {
-       struct regulator_dev *rdev;
        struct regulator_init_data *init_data = client->dev.platform_data;
        struct ad5398_chip_info *chip;
        const struct ad5398_current_data_format *df =
@@ -233,9 +232,10 @@ static int __devinit ad5398_probe(struct i2c_client *client,
        chip->current_offset = df->current_offset;
        chip->current_mask = (chip->current_level - 1) << chip->current_offset;
 
-       rdev = regulator_register(&ad5398_reg, &client->dev, init_data, chip);
-       if (IS_ERR(rdev)) {
-               ret = PTR_ERR(rdev);
+       chip->rdev = regulator_register(&ad5398_reg, &client->dev,
+                                       init_data, chip, NULL);
+       if (IS_ERR(chip->rdev)) {
+               ret = PTR_ERR(chip->rdev);
                dev_err(&client->dev, "failed to register %s %s\n",
                        id->name, ad5398_reg.name);
                goto err;
@@ -254,9 +254,8 @@ static int __devexit ad5398_remove(struct i2c_client *client)
 {
        struct ad5398_chip_info *chip = i2c_get_clientdata(client);
 
-       regulator_unregister(&chip->rdev);
+       regulator_unregister(chip->rdev);
        kfree(chip);
-       i2c_set_clientdata(client, NULL);
 
        return 0;
 }
@@ -274,7 +273,7 @@ static int __init ad5398_init(void)
 {
        return i2c_add_driver(&ad5398_driver);
 }
-module_init(ad5398_init);
+subsys_initcall(ad5398_init);
 
 static void __exit ad5398_exit(void)
 {