Unverified Commit 65086ec2 authored by Mark Brown's avatar Mark Brown
Browse files

ASoC: Convert PCM codecs to GPIO descriptors

Merge series from Linus Walleij <linus.walleij@linaro.org>:

Three remaining TI PCM codecs use the old GPIO API in
different ways, fix them all up and move over to
<linux/gpio/consumer.h> and get rid of <linux/gpio.h>.
parents b9d98aea 17fdf318
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -9,7 +9,6 @@
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/i2c.h>
#include <linux/regmap.h>
#include <linux/of.h>
+32 −29
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/device.h>
#include <linux/gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <sound/core.h>
@@ -22,16 +22,21 @@
#include <sound/initval.h>
#include <sound/soc.h>

#include "pcm3008.h"
struct pcm3008 {
	struct gpio_desc *dem0_pin;
	struct gpio_desc *dem1_pin;
	struct gpio_desc *pdad_pin;
	struct gpio_desc *pdda_pin;
};

static int pcm3008_dac_ev(struct snd_soc_dapm_widget *w,
			  struct snd_kcontrol *kcontrol,
			  int event)
{
	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
	struct pcm3008_setup_data *setup = component->dev->platform_data;
	struct pcm3008 *pcm = component->dev->platform_data;

	gpio_set_value_cansleep(setup->pdda_pin,
	gpiod_set_value_cansleep(pcm->pdda_pin,
				 SND_SOC_DAPM_EVENT_ON(event));

	return 0;
@@ -42,9 +47,9 @@ static int pcm3008_adc_ev(struct snd_soc_dapm_widget *w,
			  int event)
{
	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
	struct pcm3008_setup_data *setup = component->dev->platform_data;
	struct pcm3008 *pcm = component->dev->platform_data;

	gpio_set_value_cansleep(setup->pdad_pin,
	gpiod_set_value_cansleep(pcm->pdad_pin,
				 SND_SOC_DAPM_EVENT_ON(event));

	return 0;
@@ -106,11 +111,13 @@ static const struct snd_soc_component_driver soc_component_dev_pcm3008 = {

static int pcm3008_codec_probe(struct platform_device *pdev)
{
	struct pcm3008_setup_data *setup = pdev->dev.platform_data;
	int ret;
	struct device *dev = &pdev->dev;
	struct pcm3008 *pcm;

	if (!setup)
		return -EINVAL;
	pcm = devm_kzalloc(dev, sizeof(*pcm), GFP_KERNEL);
	if (!pcm)
		return -ENOMEM;
	platform_set_drvdata(pdev, pcm);

	/* DEM1  DEM0  DE-EMPHASIS_MODE
	 * Low   Low   De-emphasis 44.1 kHz ON
@@ -120,30 +127,26 @@ static int pcm3008_codec_probe(struct platform_device *pdev)
	 */

	/* Configure DEM0 GPIO (turning OFF DAC De-emphasis). */
	ret = devm_gpio_request_one(&pdev->dev, setup->dem0_pin,
				    GPIOF_OUT_INIT_HIGH, "codec_dem0");
	if (ret != 0)
		return ret;
	pcm->dem0_pin = devm_gpiod_get(dev, "dem0", GPIOD_OUT_HIGH);
	if (IS_ERR(pcm->dem0_pin))
		return PTR_ERR(pcm->dem0_pin);

	/* Configure DEM1 GPIO (turning OFF DAC De-emphasis). */
	ret = devm_gpio_request_one(&pdev->dev, setup->dem1_pin,
				    GPIOF_OUT_INIT_LOW, "codec_dem1");
	if (ret != 0)
		return ret;
	pcm->dem1_pin = devm_gpiod_get(dev, "dem1", GPIOD_OUT_LOW);
	if (IS_ERR(pcm->dem1_pin))
		return PTR_ERR(pcm->dem1_pin);

	/* Configure PDAD GPIO. */
	ret = devm_gpio_request_one(&pdev->dev, setup->pdad_pin,
				    GPIOF_OUT_INIT_LOW, "codec_pdad");
	if (ret != 0)
		return ret;
	pcm->pdad_pin = devm_gpiod_get(dev, "pdad", GPIOD_OUT_LOW);
	if (IS_ERR(pcm->pdad_pin))
		return PTR_ERR(pcm->pdad_pin);

	/* Configure PDDA GPIO. */
	ret = devm_gpio_request_one(&pdev->dev, setup->pdda_pin,
				    GPIOF_OUT_INIT_LOW, "codec_pdda");
	if (ret != 0)
		return ret;
	pcm->pdda_pin = devm_gpiod_get(dev, "pdda", GPIOD_OUT_LOW);
	if (IS_ERR(pcm->pdda_pin))
		return PTR_ERR(pcm->pdda_pin);

	return devm_snd_soc_register_component(&pdev->dev,
	return devm_snd_soc_register_component(dev,
			&soc_component_dev_pcm3008, &pcm3008_dai, 1);
}

sound/soc/codecs/pcm3008.h

deleted100644 → 0
+0 −19
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * PCM3008 ALSA SoC Layer
 *
 * Author:	Hugo Villeneuve
 * Copyright (C) 2008 Lyrtech inc
 */

#ifndef __LINUX_SND_SOC_PCM3008_H
#define __LINUX_SND_SOC_PCM3008_H

struct pcm3008_setup_data {
	unsigned dem0_pin;
	unsigned dem1_pin;
	unsigned pdad_pin;
	unsigned pdda_pin;
};

#endif
+7 −21
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@

#include <linux/unaligned.h>
#include <linux/firmware.h>
#include <linux/gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/i2c.h>
#include <linux/module.h>
#include <linux/of_irq.h>
@@ -2035,10 +2035,8 @@ static const struct regmap_config pcmdevice_i2c_regmap = {

static void pcmdevice_remove(struct pcmdevice_priv *pcm_dev)
{
	if (gpio_is_valid(pcm_dev->irq_info.gpio)) {
		gpio_free(pcm_dev->irq_info.gpio);
		free_irq(pcm_dev->irq_info.nmb, pcm_dev);
	}
	if (pcm_dev->irq)
		free_irq(pcm_dev->irq, pcm_dev);
	mutex_destroy(&pcm_dev->codec_lock);
}

@@ -2109,7 +2107,7 @@ static int pcmdevice_i2c_probe(struct i2c_client *i2c)
		ndev = 1;
		dev_addrs[0] = i2c->addr;
	}
	pcm_dev->irq_info.gpio = of_irq_get(np, 0);
	pcm_dev->irq = of_irq_get(np, 0);

	for (i = 0; i < ndev; i++)
		pcm_dev->addr[i] = dev_addrs[i];
@@ -2132,22 +2130,10 @@ static int pcmdevice_i2c_probe(struct i2c_client *i2c)

	if (pcm_dev->chip_id == PCM1690)
		goto skip_interrupt;
	if (gpio_is_valid(pcm_dev->irq_info.gpio)) {
		dev_dbg(pcm_dev->dev, "irq-gpio = %d", pcm_dev->irq_info.gpio);

		ret = gpio_request(pcm_dev->irq_info.gpio, "PCMDEV-IRQ");
		if (!ret) {
			int gpio = pcm_dev->irq_info.gpio;

			gpio_direction_input(gpio);
			pcm_dev->irq_info.nmb = gpio_to_irq(gpio);

		} else
			dev_err(pcm_dev->dev, "%s: GPIO %d request error\n",
				__func__, pcm_dev->irq_info.gpio);
	if (pcm_dev->irq) {
		dev_dbg(pcm_dev->dev, "irq = %d", pcm_dev->irq);
	} else
		dev_err(pcm_dev->dev, "Looking up irq-gpio failed %d\n",
			pcm_dev->irq_info.gpio);
		dev_err(pcm_dev->dev, "No irq provided\n");

skip_interrupt:
	ret = devm_snd_soc_register_component(&i2c->dev,
+1 −6
Original line number Diff line number Diff line
@@ -208,11 +208,6 @@ struct pcmdevice_regbin {
	struct pcmdevice_config_info **cfg_info;
};

struct pcmdevice_irqinfo {
	int gpio;
	int nmb;
};

struct pcmdevice_priv {
	struct snd_soc_component *component;
	struct i2c_client *client;
@@ -221,7 +216,7 @@ struct pcmdevice_priv {
	struct gpio_desc *hw_rst;
	struct regmap *regmap;
	struct pcmdevice_regbin regbin;
	struct pcmdevice_irqinfo irq_info;
	int irq;
	unsigned int addr[PCMDEVICE_MAX_I2C_DEVICES];
	unsigned int chip_id;
	int cur_conf;