The probe() function will now utilize the register_regulators() and
request_irqs() helper functions defined in the previous patch. Probe() will
cycle through common (overlapping) regulators and irqs first, and then
handle device-specific resources identified using the chip_data struct.
Signed-off-by: Shree Ramamoorthy <s-ramamoorthy@ti.com>
---
drivers/regulator/tps65219-regulator.c | 66 +++++++++++---------------
1 file changed, 27 insertions(+), 39 deletions(-)
diff --git a/drivers/regulator/tps65219-regulator.c b/drivers/regulator/tps65219-regulator.c
index 8469ee89802c..b27888fd1fa8 100644
--- a/drivers/regulator/tps65219-regulator.c
+++ b/drivers/regulator/tps65219-regulator.c
@@ -413,54 +413,42 @@ static int tps65219_request_irqs(struct tps65219_regulator_irq_type *irq_types,
static int tps65219_regulator_probe(struct platform_device *pdev)
{
struct tps65219 *tps = dev_get_drvdata(pdev->dev.parent);
- struct regulator_dev *rdev;
struct regulator_config config = { };
- int i;
int error;
- int irq;
struct tps65219_regulator_irq_data *irq_data;
- struct tps65219_regulator_irq_type *irq_type;
+ struct chip_data *pmic;
- config.dev = tps->dev;
- config.driver_data = tps;
- config.regmap = tps->regmap;
- for (i = 0; i < ARRAY_SIZE(regulators); i++) {
- rdev = devm_regulator_register(&pdev->dev, ®ulators[i],
- &config);
- if (IS_ERR(rdev))
- return dev_err_probe(tps->dev, PTR_ERR(rdev),
- "Failed to register %s regulator\n",
- regulators[i].name);
- }
-
- irq_data = devm_kmalloc(tps->dev,
- ARRAY_SIZE(tps65219_regulator_irq_types) *
- sizeof(struct tps65219_regulator_irq_data),
- GFP_KERNEL);
- if (!irq_data)
- return -ENOMEM;
-
- for (i = 0; i < ARRAY_SIZE(tps65219_regulator_irq_types); ++i) {
- irq_type = &tps65219_regulator_irq_types[i];
+ enum pmic_id chip = platform_get_device_id(pdev)->driver_data;
- irq = platform_get_irq_byname(pdev, irq_type->irq_name);
- if (irq < 0)
- return -EINVAL;
+ pmic = &chip_info_table[chip];
- irq_data[i].dev = tps->dev;
- irq_data[i].type = irq_type;
+ config.dev = tps->dev;
+ config.driver_data = tps;
+ config.regmap = tps->regmap;
- error = devm_request_threaded_irq(tps->dev, irq, NULL,
- tps65219_regulator_irq_handler,
- IRQF_ONESHOT,
- irq_type->irq_name,
- &irq_data[i]);
- if (error) {
- dev_err(tps->dev, "failed to request %s IRQ %d: %d\n",
- irq_type->irq_name, irq, error);
+ error = tps65219_register_regulators(pmic->common_rdesc, tps,
+ &pdev->dev, config, pmic->common_rdesc_size);
+ if (error)
+ return error;
+
+ error = tps65219_register_regulators(pmic->rdesc, tps, &pdev->dev,
+ config, pmic->rdesc_size);
+ if (error)
+ return error;
+
+ irq_data = devm_kmalloc(tps->dev, pmic->common_irq_size, GFP_KERNEL);
+ error = tps65219_request_irqs(pmic->common_irq_types, tps, pdev,
+ irq_data, pmic->common_irq_size);
+ if (error)
+ return error;
+
+ if (chip == TPS65219) {
+ irq_data = devm_kmalloc(tps->dev, pmic->dev_irq_size, GFP_KERNEL);
+ error = tps65219_request_irqs(pmic->irq_types, tps, pdev,
+ irq_data, pmic->dev_irq_size);
+ if (error)
return error;
- }
}
return 0;
--
2.34.1
On 26/12/2024 23:54, Shree Ramamoorthy wrote:
> The probe() function will now utilize the register_regulators() and
> request_irqs() helper functions defined in the previous patch. Probe() will
> cycle through common (overlapping) regulators and irqs first, and then
> handle device-specific resources identified using the chip_data struct.
>
> Signed-off-by: Shree Ramamoorthy <s-ramamoorthy@ti.com>
> ---
> drivers/regulator/tps65219-regulator.c | 66 +++++++++++---------------
> 1 file changed, 27 insertions(+), 39 deletions(-)
>
> diff --git a/drivers/regulator/tps65219-regulator.c b/drivers/regulator/tps65219-regulator.c
> index 8469ee89802c..b27888fd1fa8 100644
> --- a/drivers/regulator/tps65219-regulator.c
> +++ b/drivers/regulator/tps65219-regulator.c
> @@ -413,54 +413,42 @@ static int tps65219_request_irqs(struct tps65219_regulator_irq_type *irq_types,
> static int tps65219_regulator_probe(struct platform_device *pdev)
> {
> struct tps65219 *tps = dev_get_drvdata(pdev->dev.parent);
> - struct regulator_dev *rdev;
> struct regulator_config config = { };
> - int i;
> int error;
> - int irq;
> struct tps65219_regulator_irq_data *irq_data;
> - struct tps65219_regulator_irq_type *irq_type;
> + struct chip_data *pmic;
reverse xmas tree.
>
> - config.dev = tps->dev;
> - config.driver_data = tps;
> - config.regmap = tps->regmap;
>
> - for (i = 0; i < ARRAY_SIZE(regulators); i++) {
> - rdev = devm_regulator_register(&pdev->dev, ®ulators[i],
> - &config);
> - if (IS_ERR(rdev))
> - return dev_err_probe(tps->dev, PTR_ERR(rdev),
> - "Failed to register %s regulator\n",
> - regulators[i].name);
> - }
> -
> - irq_data = devm_kmalloc(tps->dev,
> - ARRAY_SIZE(tps65219_regulator_irq_types) *
> - sizeof(struct tps65219_regulator_irq_data),
> - GFP_KERNEL);
> - if (!irq_data)
> - return -ENOMEM;
> -
> - for (i = 0; i < ARRAY_SIZE(tps65219_regulator_irq_types); ++i) {
> - irq_type = &tps65219_regulator_irq_types[i];
> + enum pmic_id chip = platform_get_device_id(pdev)->driver_data;
>
> - irq = platform_get_irq_byname(pdev, irq_type->irq_name);
> - if (irq < 0)
> - return -EINVAL;
need a new line after declarations.
> + pmic = &chip_info_table[chip];
>
> - irq_data[i].dev = tps->dev;
> - irq_data[i].type = irq_type;
> + config.dev = tps->dev;
> + config.driver_data = tps;
> + config.regmap = tps->regmap;
>
> - error = devm_request_threaded_irq(tps->dev, irq, NULL,
> - tps65219_regulator_irq_handler,
> - IRQF_ONESHOT,
> - irq_type->irq_name,
> - &irq_data[i]);
> - if (error) {
> - dev_err(tps->dev, "failed to request %s IRQ %d: %d\n",
> - irq_type->irq_name, irq, error);
> + error = tps65219_register_regulators(pmic->common_rdesc, tps,
> + &pdev->dev, config, pmic->common_rdesc_size);
> + if (error)
maybe you could use goto and do any cleanup
and in the end use dev_err_probe().
> + return error;
> +
> + error = tps65219_register_regulators(pmic->rdesc, tps, &pdev->dev,
> + config, pmic->rdesc_size);
> + if (error)
> + return error;
> +
> + irq_data = devm_kmalloc(tps->dev, pmic->common_irq_size, GFP_KERNEL);
> + error = tps65219_request_irqs(pmic->common_irq_types, tps, pdev,
> + irq_data, pmic->common_irq_size);
> + if (error)
> + return error;
> +
> + if (chip == TPS65219) {
> + irq_data = devm_kmalloc(tps->dev, pmic->dev_irq_size, GFP_KERNEL);
> + error = tps65219_request_irqs(pmic->irq_types, tps, pdev,
> + irq_data, pmic->dev_irq_size);
> + if (error)
> return error;
> - }
> }
>
> return 0;
--
cheers,
-roger
Hi,
On 1/4/25 12:47 PM, Roger Quadros wrote:
>
> On 26/12/2024 23:54, Shree Ramamoorthy wrote:
>> The probe() function will now utilize the register_regulators() and
>> request_irqs() helper functions defined in the previous patch. Probe() will
>> cycle through common (overlapping) regulators and irqs first, and then
>> handle device-specific resources identified using the chip_data struct.
>>
>> Signed-off-by: Shree Ramamoorthy <s-ramamoorthy@ti.com>
>> ---
>> drivers/regulator/tps65219-regulator.c | 66 +++++++++++---------------
>> 1 file changed, 27 insertions(+), 39 deletions(-)
>>
>> diff --git a/drivers/regulator/tps65219-regulator.c b/drivers/regulator/tps65219-regulator.c
>> index 8469ee89802c..b27888fd1fa8 100644
>> --- a/drivers/regulator/tps65219-regulator.c
>> +++ b/drivers/regulator/tps65219-regulator.c
>> @@ -413,54 +413,42 @@ static int tps65219_request_irqs(struct tps65219_regulator_irq_type *irq_types,
>> static int tps65219_regulator_probe(struct platform_device *pdev)
>> {
>> struct tps65219 *tps = dev_get_drvdata(pdev->dev.parent);
>> - struct regulator_dev *rdev;
>> struct regulator_config config = { };
>> - int i;
>> int error;
>> - int irq;
>> struct tps65219_regulator_irq_data *irq_data;
>> - struct tps65219_regulator_irq_type *irq_type;
>> + struct chip_data *pmic;
> reverse xmas tree.
>
>>
>> - config.dev = tps->dev;
>> - config.driver_data = tps;
>> - config.regmap = tps->regmap;
>>
>> - for (i = 0; i < ARRAY_SIZE(regulators); i++) {
>> - rdev = devm_regulator_register(&pdev->dev, ®ulators[i],
>> - &config);
>> - if (IS_ERR(rdev))
>> - return dev_err_probe(tps->dev, PTR_ERR(rdev),
>> - "Failed to register %s regulator\n",
>> - regulators[i].name);
>> - }
>> -
>> - irq_data = devm_kmalloc(tps->dev,
>> - ARRAY_SIZE(tps65219_regulator_irq_types) *
>> - sizeof(struct tps65219_regulator_irq_data),
>> - GFP_KERNEL);
>> - if (!irq_data)
>> - return -ENOMEM;
>> -
>> - for (i = 0; i < ARRAY_SIZE(tps65219_regulator_irq_types); ++i) {
>> - irq_type = &tps65219_regulator_irq_types[i];
>> + enum pmic_id chip = platform_get_device_id(pdev)->driver_data;
>>
>> - irq = platform_get_irq_byname(pdev, irq_type->irq_name);
>> - if (irq < 0)
>> - return -EINVAL;
> need a new line after declarations.
>
>> + pmic = &chip_info_table[chip];
>>
>> - irq_data[i].dev = tps->dev;
>> - irq_data[i].type = irq_type;
>> + config.dev = tps->dev;
>> + config.driver_data = tps;
>> + config.regmap = tps->regmap;
>>
>> - error = devm_request_threaded_irq(tps->dev, irq, NULL,
>> - tps65219_regulator_irq_handler,
>> - IRQF_ONESHOT,
>> - irq_type->irq_name,
>> - &irq_data[i]);
>> - if (error) {
>> - dev_err(tps->dev, "failed to request %s IRQ %d: %d\n",
>> - irq_type->irq_name, irq, error);
>> + error = tps65219_register_regulators(pmic->common_rdesc, tps,
>> + &pdev->dev, config, pmic->common_rdesc_size);
>> + if (error)
> maybe you could use goto and do any cleanup
> and in the end use dev_err_probe().
Looking through all of the feedback/ideas, I am planning to have the helper functions return the error,
use goto to check and return dev_err_probe if an error is detected. This should hopefully minimize the
amount of repeated error checks in this probe function. Thank you for the feedback!
>> + return error;
>> +
>> + error = tps65219_register_regulators(pmic->rdesc, tps, &pdev->dev,
>> + config, pmic->rdesc_size);
>> + if (error)
>> + return error;
>> +
>> + irq_data = devm_kmalloc(tps->dev, pmic->common_irq_size, GFP_KERNEL);
>> + error = tps65219_request_irqs(pmic->common_irq_types, tps, pdev,
>> + irq_data, pmic->common_irq_size);
>> + if (error)
>> + return error;
>> +
>> + if (chip == TPS65219) {
>> + irq_data = devm_kmalloc(tps->dev, pmic->dev_irq_size, GFP_KERNEL);
>> + error = tps65219_request_irqs(pmic->irq_types, tps, pdev,
>> + irq_data, pmic->dev_irq_size);
>> + if (error)
>> return error;
>> - }
>> }
>>
>> return 0;
--
Best,
Shree Ramamoorthy
PMIC Software Engineer
Le 26/12/2024 à 22:54, Shree Ramamoorthy a écrit :
> The probe() function will now utilize the register_regulators() and
> request_irqs() helper functions defined in the previous patch. Probe() will
> cycle through common (overlapping) regulators and irqs first, and then
> handle device-specific resources identified using the chip_data struct.
>
> Signed-off-by: Shree Ramamoorthy <s-ramamoorthy@ti.com>
> ---
> drivers/regulator/tps65219-regulator.c | 66 +++++++++++---------------
> 1 file changed, 27 insertions(+), 39 deletions(-)
>
> diff --git a/drivers/regulator/tps65219-regulator.c b/drivers/regulator/tps65219-regulator.c
> index 8469ee89802c..b27888fd1fa8 100644
> --- a/drivers/regulator/tps65219-regulator.c
> +++ b/drivers/regulator/tps65219-regulator.c
> @@ -413,54 +413,42 @@ static int tps65219_request_irqs(struct tps65219_regulator_irq_type *irq_types,
> static int tps65219_regulator_probe(struct platform_device *pdev)
> {
> struct tps65219 *tps = dev_get_drvdata(pdev->dev.parent);
> - struct regulator_dev *rdev;
> struct regulator_config config = { };
> - int i;
> int error;
> - int irq;
> struct tps65219_regulator_irq_data *irq_data;
> - struct tps65219_regulator_irq_type *irq_type;
> + struct chip_data *pmic;
>
> - config.dev = tps->dev;
> - config.driver_data = tps;
> - config.regmap = tps->regmap;
>
> - for (i = 0; i < ARRAY_SIZE(regulators); i++) {
> - rdev = devm_regulator_register(&pdev->dev, ®ulators[i],
> - &config);
> - if (IS_ERR(rdev))
> - return dev_err_probe(tps->dev, PTR_ERR(rdev),
> - "Failed to register %s regulator\n",
> - regulators[i].name);
> - }
> -
> - irq_data = devm_kmalloc(tps->dev,
> - ARRAY_SIZE(tps65219_regulator_irq_types) *
> - sizeof(struct tps65219_regulator_irq_data),
> - GFP_KERNEL);
> - if (!irq_data)
> - return -ENOMEM;
> -
> - for (i = 0; i < ARRAY_SIZE(tps65219_regulator_irq_types); ++i) {
> - irq_type = &tps65219_regulator_irq_types[i];
> + enum pmic_id chip = platform_get_device_id(pdev)->driver_data;
>
> - irq = platform_get_irq_byname(pdev, irq_type->irq_name);
> - if (irq < 0)
> - return -EINVAL;
> + pmic = &chip_info_table[chip];
>
> - irq_data[i].dev = tps->dev;
> - irq_data[i].type = irq_type;
> + config.dev = tps->dev;
> + config.driver_data = tps;
> + config.regmap = tps->regmap;
>
> - error = devm_request_threaded_irq(tps->dev, irq, NULL,
> - tps65219_regulator_irq_handler,
> - IRQF_ONESHOT,
> - irq_type->irq_name,
> - &irq_data[i]);
> - if (error) {
> - dev_err(tps->dev, "failed to request %s IRQ %d: %d\n",
> - irq_type->irq_name, irq, error);
> + error = tps65219_register_regulators(pmic->common_rdesc, tps,
> + &pdev->dev, config, pmic->common_rdesc_size);
> + if (error)
> + return error;
> +
> + error = tps65219_register_regulators(pmic->rdesc, tps, &pdev->dev,
> + config, pmic->rdesc_size);
> + if (error)
> + return error;
> +
> + irq_data = devm_kmalloc(tps->dev, pmic->common_irq_size, GFP_KERNEL);
Error handling, as done previously?
> + error = tps65219_request_irqs(pmic->common_irq_types, tps, pdev,
> + irq_data, pmic->common_irq_size);
> + if (error)
> + return error;
> +
> + if (chip == TPS65219) {
> + irq_data = devm_kmalloc(tps->dev, pmic->dev_irq_size, GFP_KERNEL);
Error handling?
> + error = tps65219_request_irqs(pmic->irq_types, tps, pdev,
> + irq_data, pmic->dev_irq_size);
> + if (error)
> return error;
> - }
> }
>
> return 0;
Hi,
On 1/1/25 5:04 AM, Christophe JAILLET wrote:
> Le 26/12/2024 à 22:54, Shree Ramamoorthy a écrit :
>> The probe() function will now utilize the register_regulators() and
>> request_irqs() helper functions defined in the previous patch.
>> Probe() will
>> cycle through common (overlapping) regulators and irqs first, and then
>> handle device-specific resources identified using the chip_data struct.
>>
>> Signed-off-by: Shree Ramamoorthy <s-ramamoorthy@ti.com>
>> ---
>> drivers/regulator/tps65219-regulator.c | 66 +++++++++++---------------
>> 1 file changed, 27 insertions(+), 39 deletions(-)
>>
>> diff --git a/drivers/regulator/tps65219-regulator.c
>> b/drivers/regulator/tps65219-regulator.c
>> index 8469ee89802c..b27888fd1fa8 100644
>> --- a/drivers/regulator/tps65219-regulator.c
>> +++ b/drivers/regulator/tps65219-regulator.c
>> @@ -413,54 +413,42 @@ static int tps65219_request_irqs(struct
>> tps65219_regulator_irq_type *irq_types,
>> static int tps65219_regulator_probe(struct platform_device *pdev)
>> {
>> struct tps65219 *tps = dev_get_drvdata(pdev->dev.parent);
>> - struct regulator_dev *rdev;
>> struct regulator_config config = { };
>> - int i;
>> int error;
>> - int irq;
>> struct tps65219_regulator_irq_data *irq_data;
>> - struct tps65219_regulator_irq_type *irq_type;
>> + struct chip_data *pmic;
>> - config.dev = tps->dev;
>> - config.driver_data = tps;
>> - config.regmap = tps->regmap;
>> - for (i = 0; i < ARRAY_SIZE(regulators); i++) {
>> - rdev = devm_regulator_register(&pdev->dev, ®ulators[i],
>> - &config);
>> - if (IS_ERR(rdev))
>> - return dev_err_probe(tps->dev, PTR_ERR(rdev),
>> - "Failed to register %s regulator\n",
>> - regulators[i].name);
>> - }
>> -
>> - irq_data = devm_kmalloc(tps->dev,
>> - ARRAY_SIZE(tps65219_regulator_irq_types) *
>> - sizeof(struct tps65219_regulator_irq_data),
>> - GFP_KERNEL);
>> - if (!irq_data)
>> - return -ENOMEM;
>> -
>> - for (i = 0; i < ARRAY_SIZE(tps65219_regulator_irq_types); ++i) {
>> - irq_type = &tps65219_regulator_irq_types[i];
>> + enum pmic_id chip = platform_get_device_id(pdev)->driver_data;
>> - irq = platform_get_irq_byname(pdev, irq_type->irq_name);
>> - if (irq < 0)
>> - return -EINVAL;
>> + pmic = &chip_info_table[chip];
>> - irq_data[i].dev = tps->dev;
>> - irq_data[i].type = irq_type;
>> + config.dev = tps->dev;
>> + config.driver_data = tps;
>> + config.regmap = tps->regmap;
>> - error = devm_request_threaded_irq(tps->dev, irq, NULL,
>> - tps65219_regulator_irq_handler,
>> - IRQF_ONESHOT,
>> - irq_type->irq_name,
>> - &irq_data[i]);
>> - if (error) {
>> - dev_err(tps->dev, "failed to request %s IRQ %d: %d\n",
>> - irq_type->irq_name, irq, error);
>> + error = tps65219_register_regulators(pmic->common_rdesc, tps,
>> + &pdev->dev, config, pmic->common_rdesc_size);
>> + if (error)
>> + return error;
>> +
>> + error = tps65219_register_regulators(pmic->rdesc, tps, &pdev->dev,
>> + config, pmic->rdesc_size);
>> + if (error)
>> + return error;
>> +
>> + irq_data = devm_kmalloc(tps->dev, pmic->common_irq_size,
>> GFP_KERNEL);
>
> Error handling, as done previously?
Thanks for catching this, will add in the previous check:
if (!irq_data)
return -ENOMEM;
>> + error = tps65219_request_irqs(pmic->common_irq_types, tps, pdev,
>> + irq_data, pmic->common_irq_size);
>> + if (error)
>> + return error;
>> +
>> + if (chip == TPS65219) {
>> + irq_data = devm_kmalloc(tps->dev, pmic->dev_irq_size,
>> GFP_KERNEL);
>
> Error handling?
>
>> + error = tps65219_request_irqs(pmic->irq_types, tps, pdev,
>> + irq_data, pmic->dev_irq_size);
>> + if (error)
>> return error;
>> - }
>> }
>> return 0;
>
--
Best,
Shree Ramamoorthy
PMIC Software Engineer
© 2016 - 2026 Red Hat, Inc.