MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / regulator_gpio_probe

Function regulator_gpio_probe

components/drivers/regulator/regulator-gpio.c:170–287  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

168};
169
170static rt_err_t regulator_gpio_probe(struct rt_platform_device *pdev)
171{
172 rt_err_t err;
173 struct rt_device *dev = &pdev->parent;
174 struct regulator_gpio *rg = rt_calloc(1, sizeof(*rg));
175 struct rt_regulator_node *rgp;
176
177 if (!rg)
178 {
179 return -RT_ENOMEM;
180 }
181
182 regulator_ofw_parse(dev->ofw_node, &rg->param);
183
184 rgp = &rg->parent;
185 rgp->supply_name = rg->param.name;
186 rgp->ops = &regulator_gpio_ops;
187 rgp->param = &rg->param;
188 rgp->dev = &pdev->parent;
189
190 rt_dm_dev_prop_read_u32(dev, "startup-delay-us", &rg->startup_delay);
191 rt_dm_dev_prop_read_u32(dev, "off-on-delay-us", &rg->off_on_delay);
192
193 /* GPIO flags are ignored, we check by enable-active-high */
194 rg->enable_pin = rt_pin_get_named_pin(dev, "enable", 0, RT_NULL, RT_NULL);
195
196 if (rg->enable_pin < 0 && rg->enable_pin != PIN_NONE)
197 {
198 err = rg->enable_pin;
199 goto _fail;
200 }
201
202 rg->pins_nr = rt_pin_get_named_pin_count(dev, "gpios");
203
204 if (rg->pins_nr > 0)
205 {
206 rg->pins_desc = rt_malloc(sizeof(*rg->pins_desc) * rg->pins_nr);
207
208 if (!rg->pins_desc)
209 {
210 err = -RT_ENOMEM;
211
212 goto _fail;
213 }
214
215 for (int i = 0; i < rg->pins_nr; ++i)
216 {
217 rt_uint32_t val;
218 struct regulator_gpio_desc *gpiod = &rg->pins_desc[i];
219
220 gpiod->pin = rt_pin_get_named_pin(dev, RT_NULL, i, RT_NULL, RT_NULL);
221
222 if (gpiod->pin < 0)
223 {
224 err = gpiod->pin;
225 goto _fail;
226 }
227

Callers

nothing calls this directly

Calls 10

rt_callocFunction · 0.85
regulator_ofw_parseFunction · 0.85
rt_dm_dev_prop_read_u32Function · 0.85
rt_pin_get_named_pinFunction · 0.85
rt_mallocFunction · 0.85
rt_regulator_registerFunction · 0.85
rt_freeFunction · 0.85

Tested by

no test coverage detected