Skip to contentSkip to conversation

regulator: lp872x: Simplify implementation of lp872x_find_regulator_init_data()

PATCH Applied Axel Lin 3 participants 4 messages Jul 15, 2012 – Jul 16, 2012 Voltage and current regulator framework

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 regulator: lp872x: Simplify implementation of lp872x_find_regulator_init_data()

Pass regulator id rahter than the index to lp872x_find_regulator_init_data(), then the code can be simpler.
We can also get max_regulators by lp->num_regulators.

---
 drivers/regulator/lp872x.c |   28 +++++++---------------------
 1 file changed, 7 insertions(+), 21 deletions(-)
drivers/regulator/lp872x.c +7 -21
index 471f8e8..212c38e 100644
@@ -796,30 +796,16 @@ static int lp872x_config(struct lp872x *lp)
 }
 
 static struct regulator_init_data
-*lp872x_find_regulator_init_data(int idx, struct lp872x *lp)
+*lp872x_find_regulator_init_data(int id, struct lp872x *lp)
 {
-	int i, base, id, max_regulators;
-
-	switch (lp->chipid) {
-	case LP8720:
-		base = LP8720_ID_BASE;
-		max_regulators = LP8720_NUM_REGULATORS;
-		break;
-	case LP8725:
-		base = LP8725_ID_BASE;
-		max_regulators = LP8725_NUM_REGULATORS;
-		break;
-	default:
-		return NULL;
-	}
+	int i;
 
-	id = base + idx;
-	for (i = 0 ; i < max_regulators ; i++)
+	for (i = 0; i < lp->num_regulators; i++) {
 		if (lp->pdata->regulator_data[i].id == id)
-			break;
+			return lp->pdata->regulator_data[i].init_data;
+	}
 
-	return (i == max_regulators) ? NULL :
-			lp->pdata->regulator_data[i].init_data;
+	return NULL;
 }
 
 static int lp872x_regulator_register(struct lp872x *lp)
@@ -834,7 +820,7 @@ static int lp872x_regulator_register(struct lp872x *lp)
 						&lp8725_regulator_desc[i];
 
 		cfg.dev = lp->dev;
-		cfg.init_data = lp872x_find_regulator_init_data(i, lp);
+		cfg.init_data = lp872x_find_regulator_init_data(desc->id, lp);
 		cfg.driver_data = lp;
 		cfg.regmap = lp->regmap;
 
Signature · 1 line
1.7.9.5
Tested-by on v1 1/1
#1 lore raw
Quoted 4 lines

Pass regulator id rahter than the index to lp872x_find_regulator_init_data(),
then the code can be simpler.
We can also get max_regulators by lp->num_regulators.

It looks good to me and tested successfully in the target board. Thanks !

Best Regards,
Milo ���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m���� ������?�I�

Acked-by Tested-by on v1 1/1
#2 lore raw
In reply to Axel Lin
Quoted 4 lines

Pass regulator id rahter than the index to lp872x_find_regulator_init_data(),
then the code can be simpler.
We can also get max_regulators by lp->num_regulators.

It looks good to me and tested successfully in the target board. Thanks !

Best Regards,
Milo ���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m���� ������?�I�

Applied
#3 lore raw
In reply to Axel Lin
Quoted 3 lines · Axel Lin

Pass regulator id rahter than the index to lp872x_find_regulator_init_data(), then the code can be simpler.
We can also get max_regulators by lp->num_regulators.

Applied, thanks.