in leds-is31fl319x.c [202:277]
static int is31fl319x_parse_dt(struct device *dev,
struct is31fl319x_chip *is31)
{
struct device_node *np = dev_of_node(dev), *child;
int count;
int ret;
if (!np)
return -ENODEV;
is31->shutdown_gpio = devm_gpiod_get_optional(dev,
"shutdown",
GPIOD_OUT_HIGH);
if (IS_ERR(is31->shutdown_gpio)) {
ret = PTR_ERR(is31->shutdown_gpio);
dev_err(dev, "Failed to get shutdown gpio: %d\n", ret);
return ret;
}
is31->cdef = device_get_match_data(dev);
count = of_get_available_child_count(np);
dev_dbg(dev, "probing with %d leds defined in DT\n", count);
if (!count || count > is31->cdef->num_leds) {
dev_err(dev, "Number of leds defined must be between 1 and %u\n",
is31->cdef->num_leds);
return -ENODEV;
}
for_each_available_child_of_node(np, child) {
struct is31fl319x_led *led;
u32 reg;
ret = of_property_read_u32(child, "reg", ®);
if (ret) {
dev_err(dev, "Failed to read led 'reg' property\n");
goto put_child_node;
}
if (reg < 1 || reg > is31->cdef->num_leds) {
dev_err(dev, "invalid led reg %u\n", reg);
ret = -EINVAL;
goto put_child_node;
}
led = &is31->leds[reg - 1];
if (led->configured) {
dev_err(dev, "led %u is already configured\n", reg);
ret = -EINVAL;
goto put_child_node;
}
ret = is31fl319x_parse_child_dt(dev, child, led);
if (ret) {
dev_err(dev, "led %u DT parsing failed\n", reg);
goto put_child_node;
}
led->configured = true;
}
is31->audio_gain_db = 0;
ret = of_property_read_u32(np, "audio-gain-db", &is31->audio_gain_db);
if (!ret)
is31->audio_gain_db = min(is31->audio_gain_db,
IS31FL319X_AUDIO_GAIN_DB_MAX);
return 0;
put_child_node:
of_node_put(child);
return ret;
}