iio: tsl2772: Use regulator_bulk_() APIs
PATCH v3 2/2 iio: tsl2772: Use regulator_bulk_() APIs
Use regulator_bulk_() APIs to shrink driver size.
---
Changes in v3:
- Split v2 into two patches.
- Add dev_err to log error messages.
- Add a check for EPROBE_DEFER.
drivers/iio/light/tsl2772.c | 82 +++++++++++-------------------------- 1 file changed, 24 insertions(+), 58 deletions(-)
drivers/iio/light/tsl2772.c +24 -58
@@ -134,6 +134,12 @@ enum {TSL2772_CHIP_SUSPENDED =2 }; +enum { +TSL2772_SUPPLY_VDD =0 , +TSL2772_SUPPLY_VDDIO =1 , +TSL2772_NUM_SUPPLIES =2 +}; +/* Per-device data */ struct tsl2772_als_info {u16 als_ch0;
@@ -161,8 +167,7 @@ struct tsl2772_chip {struct mutex prox_mutex;struct mutex als_mutex;struct i2c_client *client; -struct regulator *vdd_supply; -struct regulator *vddio_supply; +struct regulator_bulk_data reg[TSL2772_NUM_SUPPLIES ];u16 prox_data;struct tsl2772_als_info als_cur_info;struct tsl2772_settings settings;
@@ -697,46 +702,7 @@ static void tsl2772_disable_regulators_action(void *_data) {struct tsl2772_chip *chip = _data; -regulator_disable (chip->vdd_supply); -regulator_disable (chip->vddio_supply); -} - -static int tsl2772_enable_regulator (struct tsl2772_chip *chip, -struct regulator *regulator) -{ -int ret; - - ret =regulator_enable (regulator); -if (ret <0 ) { -dev_err (&chip->client->dev,"Failed to enable regulator: %d\n" , - ret); -return ret; - } - -return 0 ; -} - -static struct regulator *tsl2772_get_regulator (struct tsl2772_chip *chip, -char *name) -{ -struct regulator *regulator; -int ret; - - regulator =devm_regulator_get (&chip->client->dev, name); -if (IS_ERR (regulator)) { -if (PTR_ERR (regulator) != -EPROBE_DEFER ) -dev_err (&chip->client->dev, -"Failed to get %s regulator %d\n" , - name, (int )PTR_ERR (regulator)); - -return regulator; - } - - ret =tsl2772_enable_regulator (chip, regulator); -if (ret <0 ) -return ERR_PTR (ret); - -return regulator; +regulator_bulk_disable (ARRAY_SIZE (chip->reg), chip->reg); }static int tsl2772_chip_on (struct iio_dev *indio_dev)
@@ -1804,14 +1770,21 @@ static int tsl2772_probe(struct i2c_client *clientp, chip->client = clientp;i2c_set_clientdata (clientp, indio_dev); - chip->vddio_supply =tsl2772_get_regulator (chip,"vddio" ); -if (IS_ERR (chip->vddio_supply)) -return PTR_ERR (chip->vddio_supply); + chip->reg[TSL2772_SUPPLY_VDD ].supply ="vdd" ; + chip->reg[TSL2772_SUPPLY_VDDIO ].supply ="vddio" ; - chip->vdd_supply =tsl2772_get_regulator (chip,"vdd" ); -if (IS_ERR (chip->vdd_supply)) { -regulator_disable (chip->vddio_supply); -return PTR_ERR (chip->vdd_supply); + ret =devm_regulator_bulk_get (&clientp->dev,ARRAY_SIZE (chip->reg), + chip->reg); +if (ret <0 ) { +if (ret != -EPROBE_DEFER ) +dev_err (&clientp->dev,"Failed to get regulators: %d\n" , ret); +return ret; + } + + ret =regulator_bulk_enable (ARRAY_SIZE (chip->reg), chip->reg); +if (ret <0 ) { +dev_err (&clientp->dev,"Failed to enable regulators: %d\n" , ret); +return ret; } ret = devm_add_action_or_reset(&clientp->dev,
@@ -1901,8 +1874,7 @@ static int tsl2772_suspend(struct device *dev)int ret; ret =tsl2772_chip_off (indio_dev); -regulator_disable (chip->vdd_supply); -regulator_disable (chip->vddio_supply); +regulator_bulk_disable (ARRAY_SIZE (chip->reg), chip->reg);return ret; }
@@ -1913,16 +1885,10 @@ static int tsl2772_resume(struct device *dev)struct tsl2772_chip *chip =iio_priv (indio_dev);int ret; - ret =tsl2772_enable_regulator (chip, chip->vddio_supply); + ret =regulator_bulk_enable (ARRAY_SIZE (chip->reg), chip->reg);if (ret <0 )return ret; - ret =tsl2772_enable_regulator (chip, chip->vdd_supply); -if (ret <0 ) { -regulator_disable (chip->vddio_supply); -return ret; - } -usleep_range (TSL2772_BOOT_MIN_SLEEP_TIME ,TSL2772_BOOT_MAX_SLEEP_TIME );return tsl2772_chip_on (indio_dev);
Signature · 1 line
2.20.1
Hi Chuhong,
Quoted 3 lines · Chuhong Yuan
Use
regulator_bulk_()APIs to shrink driver size.Signed-off-by Chuhong Yuan <[email protected]>
Just a few minor nitpicks below. Overall, this is looking nice.
Quoted 27 lines
---
Changes in v3:
- Split v2 into two patches.
- Adddev_errto log error messages.
- Add a check forEPROBE_DEFER.drivers/iio/light/tsl2772.c | 82 +++++++++++-------------------------- 1 file changed, 24 insertions(+), 58 deletions(-)drivers/iio/light/tsl2772.c +6
-0@@ -134,6 +134,12 @@ enum {TSL2772_CHIP_SUSPENDED =2 }; +enum { +TSL2772_SUPPLY_VDD =0 , +TSL2772_SUPPLY_VDDIO =1 , +TSL2772_NUM_SUPPLIES =2 +}; +/* Per-device data */ struct tsl2772_als_info {u16 als_ch0;
drivers/iio/light/tsl2772.c struct tsl2772_chip { · line 170
Quoted 6 lines
drivers/iio/light/tsl2772.c +1
-2@@ -161,8 +167,7 @@ struct tsl2772_chip {struct mutex prox_mutex;struct mutex als_mutex;struct i2c_client *client; -struct regulator *vdd_supply; -struct regulator *vddio_supply; +struct regulator_bulk_data reg[TSL2772_NUM_SUPPLIES ];
I prefer that this was named something other than 'reg'. Maybe 'supplies'? I know that there are a few other drivers in IIO that use this name.
Quoted 57 lines
drivers/iio/light/tsl2772.c +1
-42u16 prox_data;struct tsl2772_als_info als_cur_info;struct tsl2772_settings settings;@@ -697,46 +702,7 @@ static void tsl2772_disable_regulators_action(void *_data) {struct tsl2772_chip *chip = _data; -regulator_disable (chip->vdd_supply); -regulator_disable (chip->vddio_supply); -} - -static int tsl2772_enable_regulator (struct tsl2772_chip *chip, -struct regulator *regulator) -{ -int ret; - - ret =regulator_enable (regulator); -if (ret <0 ) { -dev_err (&chip->client->dev,"Failed to enable regulator: %d\n" , - ret); -return ret; - } - -return 0 ; -} - -static struct regulator *tsl2772_get_regulator (struct tsl2772_chip *chip, -char *name) -{ -struct regulator *regulator; -int ret; - - regulator =devm_regulator_get (&chip->client->dev, name); -if (IS_ERR (regulator)) { -if (PTR_ERR (regulator) != -EPROBE_DEFER ) -dev_err (&chip->client->dev, -"Failed to get %s regulator %d\n" , - name, (int )PTR_ERR (regulator)); - -return regulator; - } - - ret =tsl2772_enable_regulator (chip, regulator); -if (ret <0 ) -return ERR_PTR (ret); - -return regulator; +regulator_bulk_disable (ARRAY_SIZE (chip->reg), chip->reg); }static int tsl2772_chip_on (struct iio_dev *indio_dev)@@ -1804,14 +1770,21 @@ static int tsl2772_probe(struct i2c_client *clientp, chip->client = clientp;i2c_set_clientdata (clientp, indio_dev); - chip->vddio_supply =tsl2772_get_regulator (chip,"vddio" ); -if (IS_ERR (chip->vddio_supply))
drivers/iio/light/tsl2772.c static int tsl2772_probe(struct i2c_client *clientp, · line 1777
Quoted 10 lines
drivers/iio/light/tsl2772.c +4
-5-return PTR_ERR (chip->vddio_supply); + chip->reg[TSL2772_SUPPLY_VDD ].supply ="vdd" ; + chip->reg[TSL2772_SUPPLY_VDDIO ].supply ="vddio" ; - chip->vdd_supply =tsl2772_get_regulator (chip,"vdd" ); -if (IS_ERR (chip->vdd_supply)) { -regulator_disable (chip->vddio_supply); -return PTR_ERR (chip->vdd_supply); + ret =devm_regulator_bulk_get (&clientp->dev,ARRAY_SIZE (chip->reg), + chip->reg);
This needs to be aligned with devm_regulator_bulk_get, not ARRAY_SIZE.
drivers/iio/light/tsl2772.c static int tsl2772_probe(struct i2c_client *clientp, · line 1780
Quoted 3 lines
drivers/iio/light/tsl2772.c +3
-0+if (ret <0 ) { +if (ret != -EPROBE_DEFER ) +dev_err (&clientp->dev,"Failed to get regulators: %d\n" , ret);
Add newline.
Brian
Quoted 39 lines · Brian Masney <[email protected]> 于2019年7月31日周三 下午5:40写道:
Hi Chuhong,
Quoted 3 lines · Chuhong Yuan
Use
regulator_bulk_()APIs to shrink driver size.Signed-off-by Chuhong Yuan <[email protected]>Just a few minor nitpicks below. Overall, this is looking nice.
Quoted 29 lines
---
Changes in v3:
- Split v2 into two patches.
- Adddev_errto log error messages.
- Add a check forEPROBE_DEFER.drivers/iio/light/tsl2772.c | 82 +++++++++++-------------------------- 1 file changed, 24 insertions(+), 58 deletions(-)drivers/iio/light/tsl2772.c +6
-0@@ -134,6 +134,12 @@ enum {TSL2772_CHIP_SUSPENDED =2 }; +enum { +TSL2772_SUPPLY_VDD =0 , +TSL2772_SUPPLY_VDDIO =1 , +TSL2772_NUM_SUPPLIES =2 +}; +/* Per-device data */ struct tsl2772_als_info {u16 als_ch0;@@ -161,8 +167,7 @@ struct tsl2772_chip {struct mutex prox_mutex;struct mutex als_mutex;
Quoted 9 lines
drivers/iio/light/tsl2772.c struct tsl2772_chip { · line 170
Quoted 4 lines
drivers/iio/light/tsl2772.c +1
-2struct i2c_client *client; -struct regulator *vdd_supply; -struct regulator *vddio_supply; +struct regulator_bulk_data reg[TSL2772_NUM_SUPPLIES ];I prefer that this was named something other than 'reg'. Maybe 'supplies'? I know that there are a few other drivers in IIO that use this name.
I have used grep "regulator_bulk_data" in drivers/iio but find no variable is named "supplies"...
Quoted 77 lines
Quoted 57 lines
drivers/iio/light/tsl2772.c +1
-42u16 prox_data;struct tsl2772_als_info als_cur_info;struct tsl2772_settings settings;@@ -697,46 +702,7 @@ static void tsl2772_disable_regulators_action(void *_data) {struct tsl2772_chip *chip = _data; -regulator_disable (chip->vdd_supply); -regulator_disable (chip->vddio_supply); -} - -static int tsl2772_enable_regulator (struct tsl2772_chip *chip, -struct regulator *regulator) -{ -int ret; - - ret =regulator_enable (regulator); -if (ret <0 ) { -dev_err (&chip->client->dev,"Failed to enable regulator: %d\n" , - ret); -return ret; - } - -return 0 ; -} - -static struct regulator *tsl2772_get_regulator (struct tsl2772_chip *chip, -char *name) -{ -struct regulator *regulator; -int ret; - - regulator =devm_regulator_get (&chip->client->dev, name); -if (IS_ERR (regulator)) { -if (PTR_ERR (regulator) != -EPROBE_DEFER ) -dev_err (&chip->client->dev, -"Failed to get %s regulator %d\n" , - name, (int )PTR_ERR (regulator)); - -return regulator; - } - - ret =tsl2772_enable_regulator (chip, regulator); -if (ret <0 ) -return ERR_PTR (ret); - -return regulator; +regulator_bulk_disable (ARRAY_SIZE (chip->reg), chip->reg); }static int tsl2772_chip_on (struct iio_dev *indio_dev)@@ -1804,14 +1770,21 @@ static int tsl2772_probe(struct i2c_client *clientp, chip->client = clientp;i2c_set_clientdata (clientp, indio_dev); - chip->vddio_supply =tsl2772_get_regulator (chip,"vddio" ); -if (IS_ERR (chip->vddio_supply))drivers/iio/light/tsl2772.c static int tsl2772_probe(struct i2c_client *clientp, · line 1777
Quoted 10 lines
drivers/iio/light/tsl2772.c +4
-5-return PTR_ERR (chip->vddio_supply); + chip->reg[TSL2772_SUPPLY_VDD ].supply ="vdd" ; + chip->reg[TSL2772_SUPPLY_VDDIO ].supply ="vddio" ; - chip->vdd_supply =tsl2772_get_regulator (chip,"vdd" ); -if (IS_ERR (chip->vdd_supply)) { -regulator_disable (chip->vddio_supply); -return PTR_ERR (chip->vdd_supply); + ret =devm_regulator_bulk_get (&clientp->dev,ARRAY_SIZE (chip->reg), + chip->reg);This needs to be aligned with
devm_regulator_bulk_get, notARRAY_SIZE.drivers/iio/light/tsl2772.c static int tsl2772_probe(struct i2c_client *clientp, · line 1780
Quoted 3 lines
drivers/iio/light/tsl2772.c +3
-0+if (ret <0 ) { +if (ret != -EPROBE_DEFER ) +dev_err (&clientp->dev,"Failed to get regulators: %d\n" , ret);Add newline.
Brian