diff options
author | Felipe Balbi <felipe.balbi@nokia.com> | 2009-08-10 02:05:13 -0400 |
---|---|---|
committer | Liam Girdwood <lrg@slimlogic.co.uk> | 2009-09-22 08:32:41 -0400 |
commit | e9d62698e8e5228638093c48783eb9dda788f1c3 (patch) | |
tree | 3c379f573de2797c147a3c734b8abfd1bfc7b7dc /drivers/regulator | |
parent | 86d9884b6a3646bc24e57430f1f694c5171c1bf6 (diff) |
regulator: userspace: use sysfs_create_group
and avoid introducing our own loops for creating
several sysfs entries.
Signed-off-by: Felipe Balbi <felipe.balbi@nokia.com>
Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
Diffstat (limited to 'drivers/regulator')
-rw-r--r-- | drivers/regulator/userspace-consumer.c | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/drivers/regulator/userspace-consumer.c b/drivers/regulator/userspace-consumer.c index 06d2fa96a8b4..44917da4ac97 100644 --- a/drivers/regulator/userspace-consumer.c +++ b/drivers/regulator/userspace-consumer.c | |||
@@ -93,16 +93,21 @@ static ssize_t reg_set_state(struct device *dev, struct device_attribute *attr, | |||
93 | static DEVICE_ATTR(name, 0444, reg_show_name, NULL); | 93 | static DEVICE_ATTR(name, 0444, reg_show_name, NULL); |
94 | static DEVICE_ATTR(state, 0644, reg_show_state, reg_set_state); | 94 | static DEVICE_ATTR(state, 0644, reg_show_state, reg_set_state); |
95 | 95 | ||
96 | static struct device_attribute *attributes[] = { | 96 | static struct attribute *attributes[] = { |
97 | &dev_attr_name, | 97 | &dev_attr_name.attr, |
98 | &dev_attr_state, | 98 | &dev_attr_state.attr, |
99 | NULL, | ||
100 | }; | ||
101 | |||
102 | static const struct attribute_group attr_group = { | ||
103 | .attrs = attributes, | ||
99 | }; | 104 | }; |
100 | 105 | ||
101 | static int regulator_userspace_consumer_probe(struct platform_device *pdev) | 106 | static int regulator_userspace_consumer_probe(struct platform_device *pdev) |
102 | { | 107 | { |
103 | struct regulator_userspace_consumer_data *pdata; | 108 | struct regulator_userspace_consumer_data *pdata; |
104 | struct userspace_consumer_data *drvdata; | 109 | struct userspace_consumer_data *drvdata; |
105 | int ret, i; | 110 | int ret; |
106 | 111 | ||
107 | pdata = pdev->dev.platform_data; | 112 | pdata = pdev->dev.platform_data; |
108 | if (!pdata) | 113 | if (!pdata) |
@@ -125,31 +130,29 @@ static int regulator_userspace_consumer_probe(struct platform_device *pdev) | |||
125 | goto err_alloc_supplies; | 130 | goto err_alloc_supplies; |
126 | } | 131 | } |
127 | 132 | ||
128 | for (i = 0; i < ARRAY_SIZE(attributes); i++) { | 133 | ret = sysfs_create_group(&pdev->dev.kobj, &attr_group); |
129 | ret = device_create_file(&pdev->dev, attributes[i]); | 134 | if (ret != 0) |
130 | if (ret != 0) | 135 | goto err_create_attrs; |
131 | goto err_create_attrs; | ||
132 | } | ||
133 | 136 | ||
134 | if (pdata->init_on) | 137 | if (pdata->init_on) { |
135 | ret = regulator_bulk_enable(drvdata->num_supplies, | 138 | ret = regulator_bulk_enable(drvdata->num_supplies, |
136 | drvdata->supplies); | 139 | drvdata->supplies); |
137 | 140 | if (ret) { | |
138 | drvdata->enabled = pdata->init_on; | 141 | dev_err(&pdev->dev, |
139 | 142 | "Failed to set initial state: %d\n", ret); | |
140 | if (ret) { | 143 | goto err_enable; |
141 | dev_err(&pdev->dev, "Failed to set initial state: %d\n", ret); | 144 | } |
142 | goto err_create_attrs; | ||
143 | } | 145 | } |
144 | 146 | ||
147 | drvdata->enabled = pdata->init_on; | ||
145 | platform_set_drvdata(pdev, drvdata); | 148 | platform_set_drvdata(pdev, drvdata); |
146 | 149 | ||
147 | return 0; | 150 | return 0; |
148 | 151 | ||
149 | err_create_attrs: | 152 | err_enable: |
150 | for (i = 0; i < ARRAY_SIZE(attributes); i++) | 153 | sysfs_remove_group(&pdev->dev.kobj, &attr_group); |
151 | device_remove_file(&pdev->dev, attributes[i]); | ||
152 | 154 | ||
155 | err_create_attrs: | ||
153 | regulator_bulk_free(drvdata->num_supplies, drvdata->supplies); | 156 | regulator_bulk_free(drvdata->num_supplies, drvdata->supplies); |
154 | 157 | ||
155 | err_alloc_supplies: | 158 | err_alloc_supplies: |
@@ -160,10 +163,8 @@ err_alloc_supplies: | |||
160 | static int regulator_userspace_consumer_remove(struct platform_device *pdev) | 163 | static int regulator_userspace_consumer_remove(struct platform_device *pdev) |
161 | { | 164 | { |
162 | struct userspace_consumer_data *data = platform_get_drvdata(pdev); | 165 | struct userspace_consumer_data *data = platform_get_drvdata(pdev); |
163 | int i; | ||
164 | 166 | ||
165 | for (i = 0; i < ARRAY_SIZE(attributes); i++) | 167 | sysfs_remove_group(&pdev->dev.kobj, &attr_group); |
166 | device_remove_file(&pdev->dev, attributes[i]); | ||
167 | 168 | ||
168 | if (data->enabled) | 169 | if (data->enabled) |
169 | regulator_bulk_disable(data->num_supplies, data->supplies); | 170 | regulator_bulk_disable(data->num_supplies, data->supplies); |