diff options
author | Heiko Stuebner <heiko.stuebner@bqreaders.com> | 2014-02-11 19:01:42 -0500 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2014-02-12 10:51:25 -0500 |
commit | 5c24d355dd9af29abb25fb3891122af5e80a551d (patch) | |
tree | e493f5910d2ad6af1131cae38aed62fe95bcb7a5 /drivers | |
parent | 13cf4ea01abcc7868c64ce0f26dd5cb3abafda4c (diff) |
regulator: ti-abb-regulator: do not open-code counting and access of dt array elements
Open coding the counting of elements in a dt-property is abstracted by the newly
introduced of_property_count_uXX_elems functions. Additionally the raw iteration
over the states element exposes the endian conversion and dtb-format details,
which according to Mark Rutland "would be nice to limit [...] to of_ helper
functions".
Thus change ti-abb-regulator to use the helper for element counting and
of_property_read_u32_index for retrieval of individual values.
This makes it possible to remove the raw access to the property entirely.
Signed-off-by: Heiko Stuebner <heiko.stuebner@bqreaders.com>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/regulator/ti-abb-regulator.c | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/drivers/regulator/ti-abb-regulator.c b/drivers/regulator/ti-abb-regulator.c index a97d0c5e1097..804c83a31d69 100644 --- a/drivers/regulator/ti-abb-regulator.c +++ b/drivers/regulator/ti-abb-regulator.c | |||
@@ -507,32 +507,24 @@ static int ti_abb_init_table(struct device *dev, struct ti_abb *abb, | |||
507 | struct regulator_init_data *rinit_data) | 507 | struct regulator_init_data *rinit_data) |
508 | { | 508 | { |
509 | struct ti_abb_info *info; | 509 | struct ti_abb_info *info; |
510 | const struct property *prop; | ||
511 | const __be32 *abb_info; | ||
512 | const u32 num_values = 6; | 510 | const u32 num_values = 6; |
513 | char *pname = "ti,abb_info"; | 511 | char *pname = "ti,abb_info"; |
514 | u32 num_entries, i; | 512 | u32 i; |
515 | unsigned int *volt_table; | 513 | unsigned int *volt_table; |
516 | int min_uV = INT_MAX, max_uV = 0; | 514 | int num_entries, min_uV = INT_MAX, max_uV = 0; |
517 | struct regulation_constraints *c = &rinit_data->constraints; | 515 | struct regulation_constraints *c = &rinit_data->constraints; |
518 | 516 | ||
519 | prop = of_find_property(dev->of_node, pname, NULL); | ||
520 | if (!prop) { | ||
521 | dev_err(dev, "No '%s' property?\n", pname); | ||
522 | return -ENODEV; | ||
523 | } | ||
524 | |||
525 | if (!prop->value) { | ||
526 | dev_err(dev, "Empty '%s' property?\n", pname); | ||
527 | return -ENODATA; | ||
528 | } | ||
529 | |||
530 | /* | 517 | /* |
531 | * Each abb_info is a set of n-tuple, where n is num_values, consisting | 518 | * Each abb_info is a set of n-tuple, where n is num_values, consisting |
532 | * of voltage and a set of detection logic for ABB information for that | 519 | * of voltage and a set of detection logic for ABB information for that |
533 | * voltage to apply. | 520 | * voltage to apply. |
534 | */ | 521 | */ |
535 | num_entries = prop->length / sizeof(u32); | 522 | num_entries = of_property_count_u32_elems(dev->of_node, pname); |
523 | if (num_entries < 0) { | ||
524 | dev_err(dev, "No '%s' property?\n", pname); | ||
525 | return -ENODEV; | ||
526 | } | ||
527 | |||
536 | if (!num_entries || (num_entries % num_values)) { | 528 | if (!num_entries || (num_entries % num_values)) { |
537 | dev_err(dev, "All '%s' list entries need %d vals\n", pname, | 529 | dev_err(dev, "All '%s' list entries need %d vals\n", pname, |
538 | num_values); | 530 | num_values); |
@@ -561,18 +553,23 @@ static int ti_abb_init_table(struct device *dev, struct ti_abb *abb, | |||
561 | /* We do not know where the OPP voltage is at the moment */ | 553 | /* We do not know where the OPP voltage is at the moment */ |
562 | abb->current_info_idx = -EINVAL; | 554 | abb->current_info_idx = -EINVAL; |
563 | 555 | ||
564 | abb_info = prop->value; | ||
565 | for (i = 0; i < num_entries; i++, info++, volt_table++) { | 556 | for (i = 0; i < num_entries; i++, info++, volt_table++) { |
566 | u32 efuse_offset, rbb_mask, fbb_mask, vset_mask; | 557 | u32 efuse_offset, rbb_mask, fbb_mask, vset_mask; |
567 | u32 efuse_val; | 558 | u32 efuse_val; |
568 | 559 | ||
569 | /* NOTE: num_values should equal to entries picked up here */ | 560 | /* NOTE: num_values should equal to entries picked up here */ |
570 | *volt_table = be32_to_cpup(abb_info++); | 561 | of_property_read_u32_index(dev->of_node, pname, i * num_values, |
571 | info->opp_sel = be32_to_cpup(abb_info++); | 562 | volt_table); |
572 | efuse_offset = be32_to_cpup(abb_info++); | 563 | of_property_read_u32_index(dev->of_node, pname, |
573 | rbb_mask = be32_to_cpup(abb_info++); | 564 | i * num_values + 1, &info->opp_sel); |
574 | fbb_mask = be32_to_cpup(abb_info++); | 565 | of_property_read_u32_index(dev->of_node, pname, |
575 | vset_mask = be32_to_cpup(abb_info++); | 566 | i * num_values + 2, &efuse_offset); |
567 | of_property_read_u32_index(dev->of_node, pname, | ||
568 | i * num_values + 3, &rbb_mask); | ||
569 | of_property_read_u32_index(dev->of_node, pname, | ||
570 | i * num_values + 4, &fbb_mask); | ||
571 | of_property_read_u32_index(dev->of_node, pname, | ||
572 | i * num_values + 5, &vset_mask); | ||
576 | 573 | ||
577 | dev_dbg(dev, | 574 | dev_dbg(dev, |
578 | "[%d]v=%d ABB=%d ef=0x%x rbb=0x%x fbb=0x%x vset=0x%x\n", | 575 | "[%d]v=%d ABB=%d ef=0x%x rbb=0x%x fbb=0x%x vset=0x%x\n", |