Skip to contentSkip to conversation

regulator: Check SET[1|2|3] GPIO settings earlier

PATCH In review Axel Lin 2 participants 2 messages Mar 13, 2012 Voltage and current regulator framework

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 regulator: Check SET[1|2|3] GPIO settings earlier

Unused GPIO is marked as -1, we need to check if one of the gpio is set to 0 here because gpio_is_valid considers 0 as a valid gpio.

Since we need to check the GPIOs anyway, check them altogether earlier makes the code cleaner.

---
 drivers/regulator/max8998.c |   32 +++++++-------------------------
 1 files changed, 7 insertions(+), 25 deletions(-)
drivers/regulator/max8998.c +7 -25
index 5890265..67140fa 100644
@@ -695,6 +695,13 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 
+	/* Unused GPIO is marked as -1 */
+	if (!pdata->buck1_set1 || !pdata->buck1_set2 || !pdata->buck2_set3) {
+		dev_err(&pdev->dev,
+		    "MAX8998 SET1/SET2/SET3 GPIO must not be defined as 0 !\n");
+		return -EINVAL;
+	}
+
 	max8998 = kzalloc(sizeof(struct max8998_data), GFP_KERNEL);
 	if (!max8998)
 		return -ENOMEM;
@@ -716,27 +723,9 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev)
 	max8998->buck1_idx = pdata->buck1_default_idx;
 	max8998->buck2_idx = pdata->buck2_default_idx;
 
-	/* NOTE: */
-	/* For unused GPIO NOT marked as -1 (thereof equal to 0)  WARN_ON */
-	/* will be displayed */
-
 	/* Check if MAX8998 voltage selection GPIOs are defined */
 	if (gpio_is_valid(pdata->buck1_set1) &&
 	    gpio_is_valid(pdata->buck1_set2)) {
-		/* Check if SET1 is not equal to 0 */
-		if (!pdata->buck1_set1) {
-			printk(KERN_ERR "MAX8998 SET1 GPIO defined as 0 !\n");
-			WARN_ON(!pdata->buck1_set1);
-			ret = -EIO;
-			goto err_free_mem;
-		}
-		/* Check if SET2 is not equal to 0 */
-		if (!pdata->buck1_set2) {
-			printk(KERN_ERR "MAX8998 SET2 GPIO defined as 0 !\n");
-			WARN_ON(!pdata->buck1_set2);
-			ret = -EIO;
-			goto err_free_mem;
-		}
 
 		gpio_request(pdata->buck1_set1, "MAX8998 BUCK1_SET1");
 		gpio_direction_output(pdata->buck1_set1,
@@ -796,13 +785,6 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev)
 	}
 
 	if (gpio_is_valid(pdata->buck2_set3)) {
-		/* Check if SET3 is not equal to 0 */
-		if (!pdata->buck2_set3) {
-			printk(KERN_ERR "MAX8998 SET3 GPIO defined as 0 !\n");
-			WARN_ON(!pdata->buck2_set3);
-			ret = -EIO;
-			goto err_free_mem;
-		}
 		gpio_request(pdata->buck2_set3, "MAX8998 BUCK2_SET3");
 		gpio_direction_output(pdata->buck2_set3,
 				      max8998->buck2_idx & 0x1);
Signature · 1 line
1.7.5.4
#1 lore raw
Quoted 2 lines · Axel Lin

Unused GPIO is marked as -1, we need to check if one of the gpio is set to 0 here because gpio_is_valid considers 0 as a valid gpio.

This will break existing boards, we need to manage the transfer more gracefully and complain if we're using a GPIO 0. Though I'm not sure it's worth bothering, I hope no modern gpiolib implementation will do this.