Unverified Commit fabb0a10 authored by Mark Brown's avatar Mark Brown
Browse files

ASoC: convert GPIO chips to using new value setters

Merge series from Bartosz Golaszewski <brgl@bgdev.pl>:

struct gpio_chip now has callbacks for setting line values that return
an integer, allowing to indicate failures. We're in the process of
converting all GPIO drivers to using the new API. This series converts
all ASoC GPIO controllers.
parents 416e3bd3 8d2e9144
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -48,9 +48,10 @@ static int cirrus_scodec_test_gpio_direction_out(struct gpio_chip *chip,
	return -EOPNOTSUPP;
}

static void cirrus_scodec_test_gpio_set(struct gpio_chip *chip, unsigned int offset,
					int value)
static int cirrus_scodec_test_gpio_set(struct gpio_chip *chip,
				       unsigned int offset, int value)
{
	return -EOPNOTSUPP;
}

static int cirrus_scodec_test_gpio_set_config(struct gpio_chip *gc,
@@ -75,7 +76,7 @@ static const struct gpio_chip cirrus_scodec_test_gpio_chip = {
	.direction_input	= cirrus_scodec_test_gpio_direction_in,
	.get			= cirrus_scodec_test_gpio_get,
	.direction_output	= cirrus_scodec_test_gpio_direction_out,
	.set			= cirrus_scodec_test_gpio_set,
	.set_rv			= cirrus_scodec_test_gpio_set,
	.set_config		= cirrus_scodec_test_gpio_set_config,
	.base			= -1,
	.ngpio			= 32,
+11 −6
Original line number Diff line number Diff line
@@ -957,7 +957,8 @@ static const struct snd_soc_component_driver idt821034_component_driver = {
#define IDT821034_GPIO_OFFSET_TO_SLIC_CHANNEL(_offset) (((_offset) / 5) % 4)
#define IDT821034_GPIO_OFFSET_TO_SLIC_MASK(_offset)    BIT((_offset) % 5)

static void idt821034_chip_gpio_set(struct gpio_chip *c, unsigned int offset, int val)
static int idt821034_chip_gpio_set(struct gpio_chip *c, unsigned int offset,
				   int val)
{
	u8 ch = IDT821034_GPIO_OFFSET_TO_SLIC_CHANNEL(offset);
	u8 mask = IDT821034_GPIO_OFFSET_TO_SLIC_MASK(offset);
@@ -973,12 +974,14 @@ static void idt821034_chip_gpio_set(struct gpio_chip *c, unsigned int offset, in
	else
		slic_raw &= ~mask;
	ret = idt821034_write_slic_raw(idt821034, ch, slic_raw);
	if (ret) {

	mutex_unlock(&idt821034->mutex);

	if (ret)
		dev_err(&idt821034->spi->dev, "set gpio %d (%u, 0x%x) failed (%d)\n",
			offset, ch, mask, ret);
	}

	mutex_unlock(&idt821034->mutex);
	return ret;
}

static int idt821034_chip_gpio_get(struct gpio_chip *c, unsigned int offset)
@@ -1054,7 +1057,9 @@ static int idt821034_chip_direction_output(struct gpio_chip *c, unsigned int off
	u8 slic_conf;
	int ret;

	idt821034_chip_gpio_set(c, offset, val);
	ret = idt821034_chip_gpio_set(c, offset, val);
	if (ret)
		return ret;

	mutex_lock(&idt821034->mutex);

@@ -1112,7 +1117,7 @@ static int idt821034_gpio_init(struct idt821034 *idt821034)
	idt821034->gpio_chip.direction_input = idt821034_chip_direction_input;
	idt821034->gpio_chip.direction_output = idt821034_chip_direction_output;
	idt821034->gpio_chip.get = idt821034_chip_gpio_get;
	idt821034->gpio_chip.set = idt821034_chip_gpio_set;
	idt821034->gpio_chip.set_rv = idt821034_chip_gpio_set;
	idt821034->gpio_chip.can_sleep = true;

	return devm_gpiochip_add_data(&idt821034->spi->dev, &idt821034->gpio_chip,
+10 −5
Original line number Diff line number Diff line
@@ -1726,7 +1726,8 @@ static int peb2466_chip_gpio_update_bits(struct peb2466 *peb2466, unsigned int x
	return ret;
}

static void peb2466_chip_gpio_set(struct gpio_chip *c, unsigned int offset, int val)
static int peb2466_chip_gpio_set(struct gpio_chip *c, unsigned int offset,
				 int val)
{
	struct peb2466 *peb2466 = gpiochip_get_data(c);
	unsigned int xr_reg;
@@ -1740,14 +1741,14 @@ static void peb2466_chip_gpio_set(struct gpio_chip *c, unsigned int offset, int
		 */
		dev_warn(&peb2466->spi->dev, "cannot set gpio %d (read-only)\n",
			 offset);
		return;
		return -EINVAL;
	}

	ret = peb2466_chip_gpio_offset_to_data_regmask(offset, &xr_reg, &mask);
	if (ret) {
		dev_err(&peb2466->spi->dev, "cannot set gpio %d (%d)\n",
			offset, ret);
		return;
		return ret;
	}

	ret = peb2466_chip_gpio_update_bits(peb2466, xr_reg, mask, val ? mask : 0);
@@ -1755,6 +1756,8 @@ static void peb2466_chip_gpio_set(struct gpio_chip *c, unsigned int offset, int
		dev_err(&peb2466->spi->dev, "set gpio %d (0x%x, 0x%x) failed (%d)\n",
			offset, xr_reg, mask, ret);
	}

	return ret;
}

static int peb2466_chip_gpio_get(struct gpio_chip *c, unsigned int offset)
@@ -1879,7 +1882,9 @@ static int peb2466_chip_direction_output(struct gpio_chip *c, unsigned int offse
		return -EINVAL;
	}

	peb2466_chip_gpio_set(c, offset, val);
	ret = peb2466_chip_gpio_set(c, offset, val);
	if (ret)
		return ret;

	if (offset < 16) {
		/* SOx_{0,1} */
@@ -1940,7 +1945,7 @@ static int peb2466_gpio_init(struct peb2466 *peb2466)
	peb2466->gpio.gpio_chip.direction_input = peb2466_chip_direction_input;
	peb2466->gpio.gpio_chip.direction_output = peb2466_chip_direction_output;
	peb2466->gpio.gpio_chip.get = peb2466_chip_gpio_get;
	peb2466->gpio.gpio_chip.set = peb2466_chip_gpio_set;
	peb2466->gpio.gpio_chip.set_rv = peb2466_chip_gpio_set;
	peb2466->gpio.gpio_chip.can_sleep = true;

	return devm_gpiochip_add_data(&peb2466->spi->dev, &peb2466->gpio.gpio_chip,
+4 −3
Original line number Diff line number Diff line
@@ -4725,13 +4725,14 @@ static int rt5677_update_gpio_bits(struct rt5677_priv *rt5677, unsigned offset,
}

#ifdef CONFIG_GPIOLIB
static void rt5677_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
static int rt5677_gpio_set(struct gpio_chip *chip, unsigned int offset,
			   int value)
{
	struct rt5677_priv *rt5677 = gpiochip_get_data(chip);
	int level = value ? RT5677_GPIOx_OUT_HI : RT5677_GPIOx_OUT_LO;
	int m = RT5677_GPIOx_OUT_MASK;

	rt5677_update_gpio_bits(rt5677, offset, m, level);
	return rt5677_update_gpio_bits(rt5677, offset, m, level);
}

static int rt5677_gpio_direction_out(struct gpio_chip *chip,
@@ -4834,7 +4835,7 @@ static const struct gpio_chip rt5677_template_chip = {
	.label			= RT5677_DRV_NAME,
	.owner			= THIS_MODULE,
	.direction_output	= rt5677_gpio_direction_out,
	.set			= rt5677_gpio_set,
	.set_rv			= rt5677_gpio_set,
	.direction_input	= rt5677_gpio_direction_in,
	.get			= rt5677_gpio_get,
	.to_irq			= rt5677_to_irq,
+4 −4
Original line number Diff line number Diff line
@@ -1015,10 +1015,10 @@ static int adc3xxx_gpio_direction_out(struct gpio_chip *chip,
 * so we set the output mode and output value in the same call. Hence
 * .set in practice does the same thing as .direction_out .
 */
static void adc3xxx_gpio_set(struct gpio_chip *chip, unsigned int offset,
static int adc3xxx_gpio_set(struct gpio_chip *chip, unsigned int offset,
			    int value)
{
	(void) adc3xxx_gpio_direction_out(chip, offset, value);
	return adc3xxx_gpio_direction_out(chip, offset, value);
}

/* Even though we only support GPIO output for now, some GPIO clients
@@ -1052,7 +1052,7 @@ static const struct gpio_chip adc3xxx_gpio_chip = {
	.owner			= THIS_MODULE,
	.request		= adc3xxx_gpio_request,
	.direction_output	= adc3xxx_gpio_direction_out,
	.set			= adc3xxx_gpio_set,
	.set_rv			= adc3xxx_gpio_set,
	.get			= adc3xxx_gpio_get,
	.can_sleep		= 1,
};
Loading