aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/wm8903.c
diff options
context:
space:
mode:
authorStephen Warren <swarren@nvidia.com>2012-05-22 18:08:52 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-06-03 08:06:36 -0400
commit0bf79ef2c303cc70d036c9fb355aeb468e8efb62 (patch)
tree6a5d421f3d4fe9333f46651d8403a26e1d7134f3 /sound/soc/codecs/wm8903.c
parentf8f5701bdaf9134b1f90e5044a82c66324d2073f (diff)
ASoC: wm8903: init GPIOs during I2C probe not codec probe
This allows the GPIOs to be available as soon as the I2C device has probed, which in turn enables machine drivers to request the GPIOs in their probe(), rather than deferring this to their ASoC machine init function, i.e. after the whole sound card has been constructed, and hence the WM8903 codec is available. Signed-off-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/codecs/wm8903.c')
-rw-r--r--sound/soc/codecs/wm8903.c48
1 files changed, 22 insertions, 26 deletions
diff --git a/sound/soc/codecs/wm8903.c b/sound/soc/codecs/wm8903.c
index 86b8a2926591..f6a3fc5f09c0 100644
--- a/sound/soc/codecs/wm8903.c
+++ b/sound/soc/codecs/wm8903.c
@@ -2,7 +2,7 @@
2 * wm8903.c -- WM8903 ALSA SoC Audio driver 2 * wm8903.c -- WM8903 ALSA SoC Audio driver
3 * 3 *
4 * Copyright 2008 Wolfson Microelectronics 4 * Copyright 2008 Wolfson Microelectronics
5 * Copyright 2011 NVIDIA, Inc. 5 * Copyright 2011-2012 NVIDIA, Inc.
6 * 6 *
7 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> 7 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
8 * 8 *
@@ -116,6 +116,7 @@ static const struct reg_default wm8903_reg_defaults[] = {
116 116
117struct wm8903_priv { 117struct wm8903_priv {
118 struct wm8903_platform_data *pdata; 118 struct wm8903_platform_data *pdata;
119 struct device *dev;
119 struct snd_soc_codec *codec; 120 struct snd_soc_codec *codec;
120 struct regmap *regmap; 121 struct regmap *regmap;
121 122
@@ -1774,7 +1775,6 @@ static int wm8903_gpio_request(struct gpio_chip *chip, unsigned offset)
1774static int wm8903_gpio_direction_in(struct gpio_chip *chip, unsigned offset) 1775static int wm8903_gpio_direction_in(struct gpio_chip *chip, unsigned offset)
1775{ 1776{
1776 struct wm8903_priv *wm8903 = gpio_to_wm8903(chip); 1777 struct wm8903_priv *wm8903 = gpio_to_wm8903(chip);
1777 struct snd_soc_codec *codec = wm8903->codec;
1778 unsigned int mask, val; 1778 unsigned int mask, val;
1779 int ret; 1779 int ret;
1780 1780
@@ -1782,8 +1782,8 @@ static int wm8903_gpio_direction_in(struct gpio_chip *chip, unsigned offset)
1782 val = (WM8903_GPn_FN_GPIO_INPUT << WM8903_GP1_FN_SHIFT) | 1782 val = (WM8903_GPn_FN_GPIO_INPUT << WM8903_GP1_FN_SHIFT) |
1783 WM8903_GP1_DIR; 1783 WM8903_GP1_DIR;
1784 1784
1785 ret = snd_soc_update_bits(codec, WM8903_GPIO_CONTROL_1 + offset, 1785 ret = regmap_update_bits(wm8903->regmap,
1786 mask, val); 1786 WM8903_GPIO_CONTROL_1 + offset, mask, val);
1787 if (ret < 0) 1787 if (ret < 0)
1788 return ret; 1788 return ret;
1789 1789
@@ -1793,10 +1793,9 @@ static int wm8903_gpio_direction_in(struct gpio_chip *chip, unsigned offset)
1793static int wm8903_gpio_get(struct gpio_chip *chip, unsigned offset) 1793static int wm8903_gpio_get(struct gpio_chip *chip, unsigned offset)
1794{ 1794{
1795 struct wm8903_priv *wm8903 = gpio_to_wm8903(chip); 1795 struct wm8903_priv *wm8903 = gpio_to_wm8903(chip);
1796 struct snd_soc_codec *codec = wm8903->codec; 1796 unsigned int reg;
1797 int reg;
1798 1797
1799 reg = snd_soc_read(codec, WM8903_GPIO_CONTROL_1 + offset); 1798 regmap_read(wm8903->regmap, WM8903_GPIO_CONTROL_1 + offset, &reg);
1800 1799
1801 return (reg & WM8903_GP1_LVL_MASK) >> WM8903_GP1_LVL_SHIFT; 1800 return (reg & WM8903_GP1_LVL_MASK) >> WM8903_GP1_LVL_SHIFT;
1802} 1801}
@@ -1805,7 +1804,6 @@ static int wm8903_gpio_direction_out(struct gpio_chip *chip,
1805 unsigned offset, int value) 1804 unsigned offset, int value)
1806{ 1805{
1807 struct wm8903_priv *wm8903 = gpio_to_wm8903(chip); 1806 struct wm8903_priv *wm8903 = gpio_to_wm8903(chip);
1808 struct snd_soc_codec *codec = wm8903->codec;
1809 unsigned int mask, val; 1807 unsigned int mask, val;
1810 int ret; 1808 int ret;
1811 1809
@@ -1813,8 +1811,8 @@ static int wm8903_gpio_direction_out(struct gpio_chip *chip,
1813 val = (WM8903_GPn_FN_GPIO_OUTPUT << WM8903_GP1_FN_SHIFT) | 1811 val = (WM8903_GPn_FN_GPIO_OUTPUT << WM8903_GP1_FN_SHIFT) |
1814 (value << WM8903_GP2_LVL_SHIFT); 1812 (value << WM8903_GP2_LVL_SHIFT);
1815 1813
1816 ret = snd_soc_update_bits(codec, WM8903_GPIO_CONTROL_1 + offset, 1814 ret = regmap_update_bits(wm8903->regmap,
1817 mask, val); 1815 WM8903_GPIO_CONTROL_1 + offset, mask, val);
1818 if (ret < 0) 1816 if (ret < 0)
1819 return ret; 1817 return ret;
1820 1818
@@ -1824,11 +1822,10 @@ static int wm8903_gpio_direction_out(struct gpio_chip *chip,
1824static void wm8903_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 1822static void wm8903_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
1825{ 1823{
1826 struct wm8903_priv *wm8903 = gpio_to_wm8903(chip); 1824 struct wm8903_priv *wm8903 = gpio_to_wm8903(chip);
1827 struct snd_soc_codec *codec = wm8903->codec;
1828 1825
1829 snd_soc_update_bits(codec, WM8903_GPIO_CONTROL_1 + offset, 1826 regmap_update_bits(wm8903->regmap, WM8903_GPIO_CONTROL_1 + offset,
1830 WM8903_GP1_LVL_MASK, 1827 WM8903_GP1_LVL_MASK,
1831 !!value << WM8903_GP1_LVL_SHIFT); 1828 !!value << WM8903_GP1_LVL_SHIFT);
1832} 1829}
1833 1830
1834static struct gpio_chip wm8903_template_chip = { 1831static struct gpio_chip wm8903_template_chip = {
@@ -1842,15 +1839,14 @@ static struct gpio_chip wm8903_template_chip = {
1842 .can_sleep = 1, 1839 .can_sleep = 1,
1843}; 1840};
1844 1841
1845static void wm8903_init_gpio(struct snd_soc_codec *codec) 1842static void wm8903_init_gpio(struct wm8903_priv *wm8903)
1846{ 1843{
1847 struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
1848 struct wm8903_platform_data *pdata = wm8903->pdata; 1844 struct wm8903_platform_data *pdata = wm8903->pdata;
1849 int ret; 1845 int ret;
1850 1846
1851 wm8903->gpio_chip = wm8903_template_chip; 1847 wm8903->gpio_chip = wm8903_template_chip;
1852 wm8903->gpio_chip.ngpio = WM8903_NUM_GPIO; 1848 wm8903->gpio_chip.ngpio = WM8903_NUM_GPIO;
1853 wm8903->gpio_chip.dev = codec->dev; 1849 wm8903->gpio_chip.dev = wm8903->dev;
1854 1850
1855 if (pdata->gpio_base) 1851 if (pdata->gpio_base)
1856 wm8903->gpio_chip.base = pdata->gpio_base; 1852 wm8903->gpio_chip.base = pdata->gpio_base;
@@ -1859,24 +1855,23 @@ static void wm8903_init_gpio(struct snd_soc_codec *codec)
1859 1855
1860 ret = gpiochip_add(&wm8903->gpio_chip); 1856 ret = gpiochip_add(&wm8903->gpio_chip);
1861 if (ret != 0) 1857 if (ret != 0)
1862 dev_err(codec->dev, "Failed to add GPIOs: %d\n", ret); 1858 dev_err(wm8903->dev, "Failed to add GPIOs: %d\n", ret);
1863} 1859}
1864 1860
1865static void wm8903_free_gpio(struct snd_soc_codec *codec) 1861static void wm8903_free_gpio(struct wm8903_priv *wm8903)
1866{ 1862{
1867 struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
1868 int ret; 1863 int ret;
1869 1864
1870 ret = gpiochip_remove(&wm8903->gpio_chip); 1865 ret = gpiochip_remove(&wm8903->gpio_chip);
1871 if (ret != 0) 1866 if (ret != 0)
1872 dev_err(codec->dev, "Failed to remove GPIOs: %d\n", ret); 1867 dev_err(wm8903->dev, "Failed to remove GPIOs: %d\n", ret);
1873} 1868}
1874#else 1869#else
1875static void wm8903_init_gpio(struct snd_soc_codec *codec) 1870static void wm8903_init_gpio(struct wm8903_priv *wm8903)
1876{ 1871{
1877} 1872}
1878 1873
1879static void wm8903_free_gpio(struct snd_soc_codec *codec) 1874static void wm8903_free_gpio(struct wm8903_priv *wm8903)
1880{ 1875{
1881} 1876}
1882#endif 1877#endif
@@ -2000,8 +1995,6 @@ static int wm8903_probe(struct snd_soc_codec *codec)
2000 WM8903_DAC_MUTEMODE | WM8903_DAC_MUTE, 1995 WM8903_DAC_MUTEMODE | WM8903_DAC_MUTE,
2001 WM8903_DAC_MUTEMODE | WM8903_DAC_MUTE); 1996 WM8903_DAC_MUTEMODE | WM8903_DAC_MUTE);
2002 1997
2003 wm8903_init_gpio(codec);
2004
2005 return ret; 1998 return ret;
2006} 1999}
2007 2000
@@ -2010,7 +2003,6 @@ static int wm8903_remove(struct snd_soc_codec *codec)
2010{ 2003{
2011 struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec); 2004 struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
2012 2005
2013 wm8903_free_gpio(codec);
2014 wm8903_set_bias_level(codec, SND_SOC_BIAS_OFF); 2006 wm8903_set_bias_level(codec, SND_SOC_BIAS_OFF);
2015 if (wm8903->irq) 2007 if (wm8903->irq)
2016 free_irq(wm8903->irq, codec); 2008 free_irq(wm8903->irq, codec);
@@ -2130,6 +2122,7 @@ static __devinit int wm8903_i2c_probe(struct i2c_client *i2c,
2130 GFP_KERNEL); 2122 GFP_KERNEL);
2131 if (wm8903 == NULL) 2123 if (wm8903 == NULL)
2132 return -ENOMEM; 2124 return -ENOMEM;
2125 wm8903->dev = &i2c->dev;
2133 2126
2134 wm8903->regmap = regmap_init_i2c(i2c, &wm8903_regmap); 2127 wm8903->regmap = regmap_init_i2c(i2c, &wm8903_regmap);
2135 if (IS_ERR(wm8903->regmap)) { 2128 if (IS_ERR(wm8903->regmap)) {
@@ -2189,6 +2182,8 @@ static __devinit int wm8903_i2c_probe(struct i2c_client *i2c,
2189 /* Reset the device */ 2182 /* Reset the device */
2190 regmap_write(wm8903->regmap, WM8903_SW_RESET_AND_ID, 0x8903); 2183 regmap_write(wm8903->regmap, WM8903_SW_RESET_AND_ID, 0x8903);
2191 2184
2185 wm8903_init_gpio(wm8903);
2186
2192 ret = snd_soc_register_codec(&i2c->dev, 2187 ret = snd_soc_register_codec(&i2c->dev,
2193 &soc_codec_dev_wm8903, &wm8903_dai, 1); 2188 &soc_codec_dev_wm8903, &wm8903_dai, 1);
2194 if (ret != 0) 2189 if (ret != 0)
@@ -2204,6 +2199,7 @@ static __devexit int wm8903_i2c_remove(struct i2c_client *client)
2204{ 2199{
2205 struct wm8903_priv *wm8903 = i2c_get_clientdata(client); 2200 struct wm8903_priv *wm8903 = i2c_get_clientdata(client);
2206 2201
2202 wm8903_free_gpio(wm8903);
2207 regmap_exit(wm8903->regmap); 2203 regmap_exit(wm8903->regmap);
2208 snd_soc_unregister_codec(&client->dev); 2204 snd_soc_unregister_codec(&client->dev);
2209 2205