Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: WM8903: Fix platform data gpio_cfg confusion

wm8903_platform_data.gpio_cfg[] was intended to be interpreted as follows:
0: Don't touch this GPIO's configuration register
1..7fff: Write that value to the GPIO's configuration register
8000: Write zero to the GPIO's configuration register
other: Undefined (invalid)

The rationale is that platform data is usually global data, and a value of
zero means that the field wasn't explicitly set to anything (e.g. because
the field was new to the pdata type, and existing users weren't update to
initialize it) and hence the value zero should be ignored. 0x8000 is an
explicit way to get 0 in the register.

The code worked this way until commit 7cfe561 "ASoC: wm8903: Expose GPIOs
through gpiolib", where the behaviour was changed due to my lack of
awareness of the above rationale.

This patch reverts to the intended behaviour, and updates all in-tree users
to use the correct scheme. This also makes WM8903 consistent with other
devices that use a similar scheme.

WM8903_GPIO_NO_CONFIG is also renamed to WM8903_GPIO_CONFIG_ZERO so that
its name accurately reflects its purpose.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Cc: Olof Johansson <olof@lixom.net>
Cc: Colin Cross <ccross@android.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>

authored by

Stephen Warren and committed by
Mark Brown
a0f203d3 102477b6

+15 -11
+4 -4
arch/arm/mach-tegra/board-harmony.c
··· 89 89 .micdet_delay = 100, 90 90 .gpio_base = HARMONY_GPIO_WM8903(0), 91 91 .gpio_cfg = { 92 - WM8903_GPIO_NO_CONFIG, 93 - WM8903_GPIO_NO_CONFIG, 94 92 0, 95 - WM8903_GPIO_NO_CONFIG, 96 - WM8903_GPIO_NO_CONFIG, 93 + 0, 94 + WM8903_GPIO_CONFIG_ZERO, 95 + 0, 96 + 0, 97 97 }, 98 98 }; 99 99
+4 -4
arch/arm/mach-tegra/board-seaboard.c
··· 171 171 .micdet_delay = 100, 172 172 .gpio_base = SEABOARD_GPIO_WM8903(0), 173 173 .gpio_cfg = { 174 - WM8903_GPIO_NO_CONFIG, 175 - WM8903_GPIO_NO_CONFIG, 176 174 0, 177 - WM8903_GPIO_NO_CONFIG, 178 - WM8903_GPIO_NO_CONFIG, 175 + 0, 176 + WM8903_GPIO_CONFIG_ZERO, 177 + 0, 178 + 0, 179 179 }, 180 180 }; 181 181
+5 -2
include/sound/wm8903.h
··· 11 11 #ifndef __LINUX_SND_WM8903_H 12 12 #define __LINUX_SND_WM8903_H 13 13 14 - /* Used to enable configuration of a GPIO to all zeros */ 15 - #define WM8903_GPIO_NO_CONFIG 0x8000 14 + /* 15 + * Used to enable configuration of a GPIO to all zeros; a gpio_cfg value of 16 + * zero in platform data means "don't touch this pin". 17 + */ 18 + #define WM8903_GPIO_CONFIG_ZERO 0x8000 16 19 17 20 /* 18 21 * R6 (0x06) - Mic Bias Control 0
+2 -1
sound/soc/codecs/wm8903.c
··· 1893 1893 bool mic_gpio = false; 1894 1894 1895 1895 for (i = 0; i < ARRAY_SIZE(pdata->gpio_cfg); i++) { 1896 - if (pdata->gpio_cfg[i] > 0x7fff) 1896 + if ((!pdata->gpio_cfg[i]) || 1897 + (pdata->gpio_cfg[i] > WM8903_GPIO_CONFIG_ZERO)) 1897 1898 continue; 1898 1899 1899 1900 snd_soc_write(codec, WM8903_GPIO_CONTROL_1 + i,