Lines Matching +full:gpio +full:- +full:cfg
1 // SPDX-License-Identifier: GPL-2.0+
3 // soc-ac97.c -- ALSA SoC Audio Layer AC97 support
11 // with code, comments and ideas from :-
17 #include <linux/gpio/consumer.h>
18 #include <linux/gpio/driver.h>
56 return gpio_priv->component; in gpio_to_component()
62 return -EINVAL; in snd_soc_ac97_gpio_request()
72 dev_dbg(component->dev, "set gpio %d to output\n", offset); in snd_soc_ac97_gpio_direction_in()
84 dev_dbg(component->dev, "get gpio %d : %d\n", offset, in snd_soc_ac97_gpio_get()
96 gpio_priv->gpios_set &= ~(1 << offset); in snd_soc_ac97_gpio_set()
97 gpio_priv->gpios_set |= (!!value) << offset; in snd_soc_ac97_gpio_set()
99 gpio_priv->gpios_set); in snd_soc_ac97_gpio_set()
100 dev_dbg(component->dev, "set gpio %d to %d\n", offset, !!value); in snd_soc_ac97_gpio_set()
108 dev_dbg(component->dev, "set gpio %d to output\n", offset); in snd_soc_ac97_gpio_direction_out()
131 gpio_priv = devm_kzalloc(component->dev, sizeof(*gpio_priv), GFP_KERNEL); in snd_soc_ac97_init_gpio()
133 return -ENOMEM; in snd_soc_ac97_init_gpio()
134 ac97->gpio_priv = gpio_priv; in snd_soc_ac97_init_gpio()
135 gpio_priv->component = component; in snd_soc_ac97_init_gpio()
136 gpio_priv->gpio_chip = snd_soc_ac97_gpio_chip; in snd_soc_ac97_init_gpio()
137 gpio_priv->gpio_chip.ngpio = AC97_NUM_GPIOS; in snd_soc_ac97_init_gpio()
138 gpio_priv->gpio_chip.parent = component->dev; in snd_soc_ac97_init_gpio()
139 gpio_priv->gpio_chip.base = -1; in snd_soc_ac97_init_gpio()
141 ret = gpiochip_add_data(&gpio_priv->gpio_chip, gpio_priv); in snd_soc_ac97_init_gpio()
143 dev_err(component->dev, "Failed to add GPIOs: %d\n", ret); in snd_soc_ac97_init_gpio()
149 gpiochip_remove(&ac97->gpio_priv->gpio_chip); in snd_soc_ac97_free_gpio()
164 * snd_soc_alloc_ac97_component() - Allocate new a AC'97 device
168 * it. The caller is responsible to either call device_add(&ac97->dev) to
169 * register the device, or to call put_device(&ac97->dev) to free the device.
179 return ERR_PTR(-ENOMEM); in snd_soc_alloc_ac97_component()
181 ac97->bus = &soc_ac97_bus; in snd_soc_alloc_ac97_component()
182 ac97->num = 0; in snd_soc_alloc_ac97_component()
184 ac97->dev.bus = &ac97_bus_type; in snd_soc_alloc_ac97_component()
185 ac97->dev.parent = component->card->dev; in snd_soc_alloc_ac97_component()
186 ac97->dev.release = soc_ac97_device_release; in snd_soc_alloc_ac97_component()
188 dev_set_name(&ac97->dev, "%d-%d:%s", in snd_soc_alloc_ac97_component()
189 component->card->snd_card->number, 0, in snd_soc_alloc_ac97_component()
190 component->name); in snd_soc_alloc_ac97_component()
192 device_initialize(&ac97->dev); in snd_soc_alloc_ac97_component()
199 * snd_soc_new_ac97_component - initailise AC97 device
204 * Initialises AC97 component resources for use by ad-hoc devices only.
225 dev_err(component->dev, "Failed to reset AC97 device: %d\n", in snd_soc_new_ac97_component()
231 ret = device_add(&ac97->dev); in snd_soc_new_ac97_component()
242 put_device(&ac97->dev); in snd_soc_new_ac97_component()
248 * snd_soc_free_ac97_component - free AC97 component device
256 device_del(&ac97->dev); in snd_soc_free_ac97_component()
257 ac97->bus = NULL; in snd_soc_free_ac97_component()
258 put_device(&ac97->dev); in snd_soc_free_ac97_component()
299 struct snd_ac97_reset_cfg *cfg) in snd_soc_ac97_parse_pinctl() argument
309 cfg->pctl = p; in snd_soc_ac97_parse_pinctl()
311 state = pinctrl_lookup_state(p, "ac97-reset"); in snd_soc_ac97_parse_pinctl()
313 dev_err(dev, "Can't find pinctrl state ac97-reset\n"); in snd_soc_ac97_parse_pinctl()
316 cfg->pstate_reset = state; in snd_soc_ac97_parse_pinctl()
318 state = pinctrl_lookup_state(p, "ac97-warm-reset"); in snd_soc_ac97_parse_pinctl()
320 dev_err(dev, "Can't find pinctrl state ac97-warm-reset\n"); in snd_soc_ac97_parse_pinctl()
323 cfg->pstate_warm_reset = state; in snd_soc_ac97_parse_pinctl()
325 state = pinctrl_lookup_state(p, "ac97-running"); in snd_soc_ac97_parse_pinctl()
327 dev_err(dev, "Can't find pinctrl state ac97-running\n"); in snd_soc_ac97_parse_pinctl()
330 cfg->pstate_run = state; in snd_soc_ac97_parse_pinctl()
332 cfg->sync_gpio = devm_gpiod_get_index(dev, "ac97", 0, GPIOD_ASIS); in snd_soc_ac97_parse_pinctl()
333 if (IS_ERR(cfg->sync_gpio)) in snd_soc_ac97_parse_pinctl()
334 return dev_err_probe(dev, PTR_ERR(cfg->sync_gpio), "Can't find ac97-sync gpio\n"); in snd_soc_ac97_parse_pinctl()
335 gpiod_set_consumer_name(cfg->sync_gpio, "AC97 link sync"); in snd_soc_ac97_parse_pinctl()
337 cfg->sdata_gpio = devm_gpiod_get_index(dev, "ac97", 1, GPIOD_ASIS); in snd_soc_ac97_parse_pinctl()
338 if (IS_ERR(cfg->sdata_gpio)) in snd_soc_ac97_parse_pinctl()
339 return dev_err_probe(dev, PTR_ERR(cfg->sdata_gpio), "Can't find ac97-sdata gpio\n"); in snd_soc_ac97_parse_pinctl()
340 gpiod_set_consumer_name(cfg->sdata_gpio, "AC97 link sdata"); in snd_soc_ac97_parse_pinctl()
342 cfg->reset_gpio = devm_gpiod_get_index(dev, "ac97", 2, GPIOD_ASIS); in snd_soc_ac97_parse_pinctl()
343 if (IS_ERR(cfg->reset_gpio)) in snd_soc_ac97_parse_pinctl()
344 return dev_err_probe(dev, PTR_ERR(cfg->reset_gpio), "Can't find ac97-reset gpio\n"); in snd_soc_ac97_parse_pinctl()
345 gpiod_set_consumer_name(cfg->reset_gpio, "AC97 link reset"); in snd_soc_ac97_parse_pinctl()
359 return -EBUSY; in snd_soc_set_ac97_ops()
369 * snd_soc_set_ac97_ops_of_reset - Set ac97 ops with generic ac97 reset functions
374 * the device node of pdev to get pinctrl states and gpio numbers to use.
379 struct device *dev = &pdev->dev; in snd_soc_set_ac97_ops_of_reset()
380 struct snd_ac97_reset_cfg cfg; in snd_soc_set_ac97_ops_of_reset() local
383 ret = snd_soc_ac97_parse_pinctl(dev, &cfg); in snd_soc_set_ac97_ops_of_reset()
391 ops->warm_reset = snd_soc_ac97_warm_reset; in snd_soc_set_ac97_ops_of_reset()
392 ops->reset = snd_soc_ac97_reset; in snd_soc_set_ac97_ops_of_reset()
394 snd_ac97_rst_cfg = cfg; in snd_soc_set_ac97_ops_of_reset()