aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator/userspace-consumer.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/regulator/userspace-consumer.c')
-rw-r--r--drivers/regulator/userspace-consumer.c45
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,
93static DEVICE_ATTR(name, 0444, reg_show_name, NULL); 93static DEVICE_ATTR(name, 0444, reg_show_name, NULL);
94static DEVICE_ATTR(state, 0644, reg_show_state, reg_set_state); 94static DEVICE_ATTR(state, 0644, reg_show_state, reg_set_state);
95 95
96static struct device_attribute *attributes[] = { 96static 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
102static const struct attribute_group attr_group = {
103 .attrs = attributes,
99}; 104};
100 105
101static int regulator_userspace_consumer_probe(struct platform_device *pdev) 106static 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
149err_create_attrs: 152err_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
155err_create_attrs:
153 regulator_bulk_free(drvdata->num_supplies, drvdata->supplies); 156 regulator_bulk_free(drvdata->num_supplies, drvdata->supplies);
154 157
155err_alloc_supplies: 158err_alloc_supplies:
@@ -160,10 +163,8 @@ err_alloc_supplies:
160static int regulator_userspace_consumer_remove(struct platform_device *pdev) 163static 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);