Lines Matching +full:gpio +full:- +full:op +full:- +full:cfg
1 // SPDX-License-Identifier: GPL-2.0-or-later
13 #include <linux/gpio/consumer.h>
15 #include <linux/i2c-of-prober.h>
27 * resources, they can be marked as "fail-needs-probe" and have a prober
30 * This prober assumes such drop-in parts are on the same I2C bus, have
31 * non-conflicting addresses, and can be directly probed by seeing which
35 * - Support I2C muxes
68 return -ENOMEM; in i2c_of_probe_enable_node()
93 * i2c_of_probe_component() - probe for devices of "type" on the same i2c bus
95 * @cfg: Pointer to the &struct i2c_of_probe_cfg containing callbacks and other options
99 * Probe for possible I2C components of the same "type" (&i2c_of_probe_cfg->type)
100 * on the same I2C bus that have their status marked as "fail-needs-probe".
112 * Context: Process context only. Does non-atomic I2C transfers.
114 * can return -EPROBE_DEFER if the I2C adapter or other resources
116 * Return: 0 on success or no-op, error code otherwise.
117 * A no-op can happen when it seems like the device tree already
120 * the status of the to-be-probed components as "fail-needs-probe".
127 int i2c_of_probe_component(struct device *dev, const struct i2c_of_probe_cfg *cfg, void *ctx) in i2c_of_probe_component() argument
134 ops = cfg->ops ?: &i2c_of_probe_dummy_ops; in i2c_of_probe_component()
135 type = cfg->type; in i2c_of_probe_component()
139 return -ENODEV; in i2c_of_probe_component()
142 * If any devices of the given "type" are already enabled then this function is a no-op. in i2c_of_probe_component()
152 return dev_err_probe(dev, -EPROBE_DEFER, "Couldn't get I2C adapter\n"); in i2c_of_probe_component()
156 if (ops->enable) in i2c_of_probe_component()
157 ret = ops->enable(dev, i2c_node, ctx); in i2c_of_probe_component()
171 if (ops->cleanup_early) in i2c_of_probe_component()
172 ops->cleanup_early(dev, ctx); in i2c_of_probe_component()
177 if (ops->cleanup) in i2c_of_probe_component()
178 ops->cleanup(dev, ctx); in i2c_of_probe_component()
198 supply_name = ctx->opts->supply_name; in i2c_of_probe_simple_get_supply()
209 ctx->supply = supply; in i2c_of_probe_simple_get_supply()
216 regulator_put(ctx->supply); in i2c_of_probe_simple_put_supply()
217 ctx->supply = NULL; in i2c_of_probe_simple_put_supply()
224 if (!ctx->supply) in i2c_of_probe_simple_enable_regulator()
227 dev_dbg(dev, "Enabling regulator supply \"%s\"\n", ctx->opts->supply_name); in i2c_of_probe_simple_enable_regulator()
229 ret = regulator_enable(ctx->supply); in i2c_of_probe_simple_enable_regulator()
233 if (ctx->opts->post_power_on_delay_ms) in i2c_of_probe_simple_enable_regulator()
234 msleep(ctx->opts->post_power_on_delay_ms); in i2c_of_probe_simple_enable_regulator()
241 if (!ctx->supply) in i2c_of_probe_simple_disable_regulator()
244 dev_dbg(dev, "Disabling regulator supply \"%s\"\n", ctx->opts->supply_name); in i2c_of_probe_simple_disable_regulator()
246 regulator_disable(ctx->supply); in i2c_of_probe_simple_disable_regulator()
256 /* NULL signals no GPIO needed */ in i2c_of_probe_simple_get_gpiod()
257 if (!ctx->opts->gpio_name) in i2c_of_probe_simple_get_gpiod()
260 /* An empty string signals an unnamed GPIO */ in i2c_of_probe_simple_get_gpiod()
261 if (!ctx->opts->gpio_name[0]) in i2c_of_probe_simple_get_gpiod()
264 con_id = ctx->opts->gpio_name; in i2c_of_probe_simple_get_gpiod()
266 gpiod = fwnode_gpiod_get_index(fwnode, con_id, 0, GPIOD_ASIS, "i2c-of-prober"); in i2c_of_probe_simple_get_gpiod()
270 ctx->gpiod = gpiod; in i2c_of_probe_simple_get_gpiod()
277 gpiod_put(ctx->gpiod); in i2c_of_probe_simple_put_gpiod()
278 ctx->gpiod = NULL; in i2c_of_probe_simple_put_gpiod()
285 if (!ctx->gpiod) in i2c_of_probe_simple_set_gpio()
288 dev_dbg(dev, "Configuring GPIO\n"); in i2c_of_probe_simple_set_gpio()
290 ret = gpiod_direction_output(ctx->gpiod, ctx->opts->gpio_assert_to_enable); in i2c_of_probe_simple_set_gpio()
294 if (ctx->opts->post_gpio_config_delay_ms) in i2c_of_probe_simple_set_gpio()
295 msleep(ctx->opts->post_gpio_config_delay_ms); in i2c_of_probe_simple_set_gpio()
302 gpiod_set_value(ctx->gpiod, !ctx->opts->gpio_assert_to_enable); in i2c_of_probe_simple_disable_gpio()
306 * i2c_of_probe_simple_enable - Simple helper for I2C OF prober to get and enable resources
311 * If &i2c_of_probe_simple_opts->supply_name is given, request the named regulator supply.
312 * If &i2c_of_probe_simple_opts->gpio_name is given, request the named GPIO. Or if it is
313 * the empty string, request the unnamed GPIO.
315 * If a GPIO line was found, configure the GPIO line to output and set value
318 * Return: %0 on success or no-op, or a negative error number on failure.
329 if (!ctx || !ctx->opts) in i2c_of_probe_simple_enable()
330 return -EINVAL; in i2c_of_probe_simple_enable()
332 compat = ctx->opts->res_node_compatible; in i2c_of_probe_simple_enable()
334 return -EINVAL; in i2c_of_probe_simple_enable()
338 return dev_err_probe(dev, -ENODEV, "No device compatible with \"%s\" found\n", in i2c_of_probe_simple_enable()
372 * i2c_of_probe_simple_cleanup_early - \
377 * GPIO descriptors are exclusive and have to be released before the
389 * i2c_of_probe_simple_cleanup - Clean up and release resources for I2C OF prober simple helpers
393 * * If a GPIO line was found and not yet released, set its value to the opposite of that
401 /* GPIO operations here are no-ops if i2c_of_probe_simple_cleanup_early was called. */ in i2c_of_probe_simple_cleanup()