diff options
Diffstat (limited to 'sound/soc/soc-ac97.c')
| -rw-r--r-- | sound/soc/soc-ac97.c | 221 |
1 files changed, 101 insertions, 120 deletions
diff --git a/sound/soc/soc-ac97.c b/sound/soc/soc-ac97.c index 36dae41f65fc..37486d6a438e 100644 --- a/sound/soc/soc-ac97.c +++ b/sound/soc/soc-ac97.c @@ -1,28 +1,22 @@ -/* - * soc-ac97.c -- ALSA SoC Audio Layer AC97 support - * - * Copyright 2005 Wolfson Microelectronics PLC. - * Copyright 2005 Openedhand Ltd. - * Copyright (C) 2010 Slimlogic Ltd. - * Copyright (C) 2010 Texas Instruments Inc. - * - * Author: Liam Girdwood <lrg@slimlogic.co.uk> - * with code, comments and ideas from :- - * Richard Purdie <richard@openedhand.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - */ +// SPDX-License-Identifier: GPL-2.0+ +// +// soc-ac97.c -- ALSA SoC Audio Layer AC97 support +// +// Copyright 2005 Wolfson Microelectronics PLC. +// Copyright 2005 Openedhand Ltd. +// Copyright (C) 2010 Slimlogic Ltd. +// Copyright (C) 2010 Texas Instruments Inc. +// +// Author: Liam Girdwood <lrg@slimlogic.co.uk> +// with code, comments and ideas from :- +// Richard Purdie <richard@openedhand.com> #include <linux/ctype.h> #include <linux/delay.h> #include <linux/export.h> -#include <linux/gpio.h> +#include <linux/gpio/consumer.h> #include <linux/gpio/driver.h> #include <linux/init.h> -#include <linux/of_gpio.h> #include <linux/of.h> #include <linux/pinctrl/consumer.h> #include <linux/slab.h> @@ -34,17 +28,9 @@ struct snd_ac97_reset_cfg { struct pinctrl_state *pstate_reset; struct pinctrl_state *pstate_warm_reset; struct pinctrl_state *pstate_run; - int gpio_sdata; - int gpio_sync; - int gpio_reset; -}; - -struct snd_ac97_gpio_priv { -#ifdef CONFIG_GPIOLIB - struct gpio_chip gpio_chip; -#endif - unsigned int gpios_set; - struct snd_soc_codec *codec; + struct gpio_desc *reset_gpio; + struct gpio_desc *sdata_gpio; + struct gpio_desc *sync_gpio; }; static struct snd_ac97_bus soc_ac97_bus = { @@ -57,14 +43,20 @@ static void soc_ac97_device_release(struct device *dev) } #ifdef CONFIG_GPIOLIB -static inline struct snd_soc_codec *gpio_to_codec(struct gpio_chip *chip) +struct snd_ac97_gpio_priv { + struct gpio_chip gpio_chip; + unsigned int gpios_set; + struct snd_soc_component *component; +}; + +static inline struct snd_soc_component *gpio_to_component(struct gpio_chip *chip) { struct snd_ac97_gpio_priv *gpio_priv = gpiochip_get_data(chip); - return gpio_priv->codec; + return gpio_priv->component; } -static int snd_soc_ac97_gpio_request(struct gpio_chip *chip, unsigned offset) +static int snd_soc_ac97_gpio_request(struct gpio_chip *chip, unsigned int offset) { if (offset >= AC97_NUM_GPIOS) return -EINVAL; @@ -73,47 +65,57 @@ static int snd_soc_ac97_gpio_request(struct gpio_chip *chip, unsigned offset) } static int snd_soc_ac97_gpio_direction_in(struct gpio_chip *chip, - unsigned offset) + unsigned int offset) { - struct snd_soc_codec *codec = gpio_to_codec(chip); + struct snd_soc_component *component = gpio_to_component(chip); - dev_dbg(codec->dev, "set gpio %d to output\n", offset); - return snd_soc_update_bits(codec, AC97_GPIO_CFG, + dev_dbg(component->dev, "set gpio %d to output\n", offset); + return snd_soc_component_update_bits(component, AC97_GPIO_CFG, 1 << offset, 1 << offset); } -static int snd_soc_ac97_gpio_get(struct gpio_chip *chip, unsigned offset) +static int snd_soc_ac97_gpio_get(struct gpio_chip *chip, unsigned int offset) { - struct snd_soc_codec *codec = gpio_to_codec(chip); + struct snd_soc_component *component = gpio_to_component(chip); int ret; - ret = snd_soc_read(codec, AC97_GPIO_STATUS); - dev_dbg(codec->dev, "get gpio %d : %d\n", offset, - ret < 0 ? ret : ret & (1 << offset)); + ret = snd_soc_component_read(component, AC97_GPIO_STATUS); + + dev_dbg(component->dev, "get gpio %d : %d\n", offset, + ret & (1 << offset)); - return ret < 0 ? ret : !!(ret & (1 << offset)); + return !!(ret & (1 << offset)); } -static void snd_soc_ac97_gpio_set(struct gpio_chip *chip, unsigned offset, - int value) +static int snd_soc_ac97_gpio_set(struct gpio_chip *chip, unsigned int offset, + int value) { struct snd_ac97_gpio_priv *gpio_priv = gpiochip_get_data(chip); - struct snd_soc_codec *codec = gpio_to_codec(chip); + struct snd_soc_component *component = gpio_to_component(chip); gpio_priv->gpios_set &= ~(1 << offset); gpio_priv->gpios_set |= (!!value) << offset; - snd_soc_write(codec, AC97_GPIO_STATUS, gpio_priv->gpios_set); - dev_dbg(codec->dev, "set gpio %d to %d\n", offset, !!value); + snd_soc_component_write(component, AC97_GPIO_STATUS, + gpio_priv->gpios_set); + dev_dbg(component->dev, "set gpio %d to %d\n", offset, !!value); + + return 0; } static int snd_soc_ac97_gpio_direction_out(struct gpio_chip *chip, unsigned offset, int value) { - struct snd_soc_codec *codec = gpio_to_codec(chip); + struct snd_soc_component *component = gpio_to_component(chip); + int ret; - dev_dbg(codec->dev, "set gpio %d to output\n", offset); - snd_soc_ac97_gpio_set(chip, offset, value); - return snd_soc_update_bits(codec, AC97_GPIO_CFG, 1 << offset, 0); + dev_dbg(component->dev, "set gpio %d to output\n", offset); + + ret = snd_soc_ac97_gpio_set(chip, offset, value); + if (ret) + return ret; + + return snd_soc_component_update_bits(component, AC97_GPIO_CFG, + 1 << offset, 0); } static const struct gpio_chip snd_soc_ac97_gpio_chip = { @@ -128,24 +130,24 @@ static const struct gpio_chip snd_soc_ac97_gpio_chip = { }; static int snd_soc_ac97_init_gpio(struct snd_ac97 *ac97, - struct snd_soc_codec *codec) + struct snd_soc_component *component) { struct snd_ac97_gpio_priv *gpio_priv; int ret; - gpio_priv = devm_kzalloc(codec->dev, sizeof(*gpio_priv), GFP_KERNEL); + gpio_priv = devm_kzalloc(component->dev, sizeof(*gpio_priv), GFP_KERNEL); if (!gpio_priv) return -ENOMEM; ac97->gpio_priv = gpio_priv; - gpio_priv->codec = codec; + gpio_priv->component = component; gpio_priv->gpio_chip = snd_soc_ac97_gpio_chip; gpio_priv->gpio_chip.ngpio = AC97_NUM_GPIOS; - gpio_priv->gpio_chip.parent = codec->dev; + gpio_priv->gpio_chip.parent = component->dev; gpio_priv->gpio_chip.base = -1; ret = gpiochip_add_data(&gpio_priv->gpio_chip, gpio_priv); if (ret != 0) - dev_err(codec->dev, "Failed to add GPIOs: %d\n", ret); + dev_err(component->dev, "Failed to add GPIOs: %d\n", ret); return ret; } @@ -155,7 +157,7 @@ static void snd_soc_ac97_free_gpio(struct snd_ac97 *ac97) } #else static int snd_soc_ac97_init_gpio(struct snd_ac97 *ac97, - struct snd_soc_codec *codec) + struct snd_soc_component *component) { return 0; } @@ -166,16 +168,16 @@ static void snd_soc_ac97_free_gpio(struct snd_ac97 *ac97) #endif /** - * snd_soc_alloc_ac97_codec() - Allocate new a AC'97 device - * @codec: The CODEC for which to create the AC'97 device + * snd_soc_alloc_ac97_component() - Allocate new a AC'97 device + * @component: The COMPONENT for which to create the AC'97 device * * Allocated a new snd_ac97 device and intializes it, but does not yet register * it. The caller is responsible to either call device_add(&ac97->dev) to * register the device, or to call put_device(&ac97->dev) to free the device. * - * Returns: A snd_ac97 device or a PTR_ERR in case of an error. + * Returns: A snd_ac97 device or an ERR_PTR in case of an error. */ -struct snd_ac97 *snd_soc_alloc_ac97_codec(struct snd_soc_codec *codec) +struct snd_ac97 *snd_soc_alloc_ac97_component(struct snd_soc_component *component) { struct snd_ac97 *ac97; @@ -187,47 +189,47 @@ struct snd_ac97 *snd_soc_alloc_ac97_codec(struct snd_soc_codec *codec) ac97->num = 0; ac97->dev.bus = &ac97_bus_type; - ac97->dev.parent = codec->component.card->dev; + ac97->dev.parent = component->card->dev; ac97->dev.release = soc_ac97_device_release; dev_set_name(&ac97->dev, "%d-%d:%s", - codec->component.card->snd_card->number, 0, - codec->component.name); + component->card->snd_card->number, 0, + component->name); device_initialize(&ac97->dev); return ac97; } -EXPORT_SYMBOL(snd_soc_alloc_ac97_codec); +EXPORT_SYMBOL(snd_soc_alloc_ac97_component); /** - * snd_soc_new_ac97_codec - initailise AC97 device - * @codec: audio codec + * snd_soc_new_ac97_component - initailise AC97 device + * @component: audio component * @id: The expected device ID * @id_mask: Mask that is applied to the device ID before comparing with @id * - * Initialises AC97 codec resources for use by ad-hoc devices only. + * Initialises AC97 component resources for use by ad-hoc devices only. * * If @id is not 0 this function will reset the device, then read the ID from * the device and check if it matches the expected ID. If it doesn't match an * error will be returned and device will not be registered. * - * Returns: A PTR_ERR() on failure or a valid snd_ac97 struct on success. + * Returns: An ERR_PTR on failure or a valid snd_ac97 struct on success. */ -struct snd_ac97 *snd_soc_new_ac97_codec(struct snd_soc_codec *codec, +struct snd_ac97 *snd_soc_new_ac97_component(struct snd_soc_component *component, unsigned int id, unsigned int id_mask) { struct snd_ac97 *ac97; int ret; - ac97 = snd_soc_alloc_ac97_codec(codec); + ac97 = snd_soc_alloc_ac97_component(component); if (IS_ERR(ac97)) return ac97; if (id) { ret = snd_ac97_reset(ac97, false, id, id_mask); if (ret < 0) { - dev_err(codec->dev, "Failed to reset AC97 device: %d\n", + dev_err(component->dev, "Failed to reset AC97 device: %d\n", ret); goto err_put_device; } @@ -237,7 +239,7 @@ struct snd_ac97 *snd_soc_new_ac97_codec(struct snd_soc_codec *codec, if (ret) goto err_put_device; - ret = snd_soc_ac97_init_gpio(ac97, codec); + ret = snd_soc_ac97_init_gpio(ac97, component); if (ret) goto err_put_device; @@ -247,22 +249,22 @@ err_put_device: put_device(&ac97->dev); return ERR_PTR(ret); } -EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec); +EXPORT_SYMBOL_GPL(snd_soc_new_ac97_component); /** - * snd_soc_free_ac97_codec - free AC97 codec device + * snd_soc_free_ac97_component - free AC97 component device * @ac97: snd_ac97 device to be freed * - * Frees AC97 codec device resources. + * Frees AC97 component device resources. */ -void snd_soc_free_ac97_codec(struct snd_ac97 *ac97) +void snd_soc_free_ac97_component(struct snd_ac97 *ac97) { snd_soc_ac97_free_gpio(ac97); device_del(&ac97->dev); ac97->bus = NULL; put_device(&ac97->dev); } -EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec); +EXPORT_SYMBOL_GPL(snd_soc_free_ac97_component); static struct snd_ac97_reset_cfg snd_ac97_rst_cfg; @@ -272,11 +274,11 @@ static void snd_soc_ac97_warm_reset(struct snd_ac97 *ac97) pinctrl_select_state(pctl, snd_ac97_rst_cfg.pstate_warm_reset); - gpio_direction_output(snd_ac97_rst_cfg.gpio_sync, 1); + gpiod_direction_output_raw(snd_ac97_rst_cfg.sync_gpio, 1); udelay(10); - gpio_direction_output(snd_ac97_rst_cfg.gpio_sync, 0); + gpiod_direction_output_raw(snd_ac97_rst_cfg.sync_gpio, 0); pinctrl_select_state(pctl, snd_ac97_rst_cfg.pstate_run); msleep(2); @@ -288,13 +290,13 @@ static void snd_soc_ac97_reset(struct snd_ac97 *ac97) pinctrl_select_state(pctl, snd_ac97_rst_cfg.pstate_reset); - gpio_direction_output(snd_ac97_rst_cfg.gpio_sync, 0); - gpio_direction_output(snd_ac97_rst_cfg.gpio_sdata, 0); - gpio_direction_output(snd_ac97_rst_cfg.gpio_reset, 0); + gpiod_direction_output_raw(snd_ac97_rst_cfg.sync_gpio, 0); + gpiod_direction_output_raw(snd_ac97_rst_cfg.sdata_gpio, 0); + gpiod_direction_output_raw(snd_ac97_rst_cfg.reset_gpio, 0); udelay(10); - gpio_direction_output(snd_ac97_rst_cfg.gpio_reset, 1); + gpiod_direction_output_raw(snd_ac97_rst_cfg.reset_gpio, 1); pinctrl_select_state(pctl, snd_ac97_rst_cfg.pstate_run); msleep(2); @@ -305,8 +307,6 @@ static int snd_soc_ac97_parse_pinctl(struct device *dev, { struct pinctrl *p; struct pinctrl_state *state; - int gpio; - int ret; p = devm_pinctrl_get(dev); if (IS_ERR(p)) { @@ -336,41 +336,20 @@ static int snd_soc_ac97_parse_pinctl(struct device *dev, } cfg->pstate_run = state; - gpio = of_get_named_gpio(dev->of_node, "ac97-gpios", 0); - if (gpio < 0) { - dev_err(dev, "Can't find ac97-sync gpio\n"); - return gpio; - } - ret = devm_gpio_request(dev, gpio, "AC97 link sync"); - if (ret) { - dev_err(dev, "Failed requesting ac97-sync gpio\n"); - return ret; - } - cfg->gpio_sync = gpio; + cfg->sync_gpio = devm_gpiod_get_index(dev, "ac97", 0, GPIOD_ASIS); + if (IS_ERR(cfg->sync_gpio)) + return dev_err_probe(dev, PTR_ERR(cfg->sync_gpio), "Can't find ac97-sync gpio\n"); + gpiod_set_consumer_name(cfg->sync_gpio, "AC97 link sync"); - gpio = of_get_named_gpio(dev->of_node, "ac97-gpios", 1); - if (gpio < 0) { - dev_err(dev, "Can't find ac97-sdata gpio %d\n", gpio); - return gpio; - } - ret = devm_gpio_request(dev, gpio, "AC97 link sdata"); - if (ret) { - dev_err(dev, "Failed requesting ac97-sdata gpio\n"); - return ret; - } - cfg->gpio_sdata = gpio; + cfg->sdata_gpio = devm_gpiod_get_index(dev, "ac97", 1, GPIOD_ASIS); + if (IS_ERR(cfg->sdata_gpio)) + return dev_err_probe(dev, PTR_ERR(cfg->sdata_gpio), "Can't find ac97-sdata gpio\n"); + gpiod_set_consumer_name(cfg->sdata_gpio, "AC97 link sdata"); - gpio = of_get_named_gpio(dev->of_node, "ac97-gpios", 2); - if (gpio < 0) { - dev_err(dev, "Can't find ac97-reset gpio\n"); - return gpio; - } - ret = devm_gpio_request(dev, gpio, "AC97 link reset"); - if (ret) { - dev_err(dev, "Failed requesting ac97-reset gpio\n"); - return ret; - } - cfg->gpio_reset = gpio; + cfg->reset_gpio = devm_gpiod_get_index(dev, "ac97", 2, GPIOD_ASIS); + if (IS_ERR(cfg->reset_gpio)) + return dev_err_probe(dev, PTR_ERR(cfg->reset_gpio), "Can't find ac97-reset gpio\n"); + gpiod_set_consumer_name(cfg->reset_gpio, "AC97 link reset"); return 0; } @@ -395,6 +374,8 @@ EXPORT_SYMBOL_GPL(snd_soc_set_ac97_ops); /** * snd_soc_set_ac97_ops_of_reset - Set ac97 ops with generic ac97 reset functions + * @ops: bus ops + * @pdev: platform device * * This function sets the reset and warm_reset properties of ops and parses * the device node of pdev to get pinctrl states and gpio numbers to use. |
