From patchwork Fri Nov 9 14:00:23 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Steffen Trumtrar X-Patchwork-Id: 1720621 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 66D66DF264 for ; Fri, 9 Nov 2012 14:03:44 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TWp9T-0006fe-MN; Fri, 09 Nov 2012 14:01:43 +0000 Received: from metis.ext.pengutronix.de ([2001:6f8:1178:4:290:27ff:fe1d:cc33]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TWp91-0006bB-GN for linux-arm-kernel@lists.infradead.org; Fri, 09 Nov 2012 14:01:20 +0000 Received: from dude.hi.pengutronix.de ([2001:6f8:1178:2:21e:67ff:fe11:9c5c]) by metis.ext.pengutronix.de with esmtp (Exim 4.72) (envelope-from ) id 1TWp8g-0000Rh-JM; Fri, 09 Nov 2012 15:00:54 +0100 Received: from str by dude.hi.pengutronix.de with local (Exim 4.80) (envelope-from ) id 1TWp8e-00021d-A2; Fri, 09 Nov 2012 15:00:52 +0100 From: Steffen Trumtrar To: devicetree-discuss@lists.ozlabs.org Subject: [PATCH 4/6] ASoC: wm8974: add SPI as a possible bus master Date: Fri, 9 Nov 2012 15:00:23 +0100 Message-Id: <1352469625-32024-5-git-send-email-s.trumtrar@pengutronix.de> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1352469625-32024-1-git-send-email-s.trumtrar@pengutronix.de> References: <1352469625-32024-1-git-send-email-s.trumtrar@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:6f8:1178:2:21e:67ff:fe11:9c5c X-SA-Exim-Mail-From: str@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121109_090116_035152_31179B17 X-CRM114-Status: GOOD ( 20.99 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: alsa-devel@alsa-project.org, Mark Brown , Sascha Hauer , patches@opensource.wolfsonmicro.com, Grant Likely , Rob Landley , spi-devel-general@lists.sourceforge.net, Steffen Trumtrar , Liam Girdwood , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The wm8974 can be controlled via i2c or spi. The current driver only supports i2c. Add SPI as possible bus. As the driver has to distinguish the bus type, pass this info via the wm8974_priv. This reverts c2562a8e3b5f871ad0b73caf98bb7541e8724efc, because the driver now needs it back. This is based on earlier work by Uwe Kleine-König. Signed-off-by: Steffen Trumtrar --- sound/soc/codecs/Kconfig | 2 +- sound/soc/codecs/wm8974.c | 62 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index b92759a..cc6069d 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig @@ -104,7 +104,7 @@ config SND_SOC_ALL_CODECS select SND_SOC_WM8961 if I2C select SND_SOC_WM8962 if I2C select SND_SOC_WM8971 if I2C - select SND_SOC_WM8974 if I2C + select SND_SOC_WM8974 if SND_SOC_I2C_AND_SPI select SND_SOC_WM8978 if I2C select SND_SOC_WM8983 if SND_SOC_I2C_AND_SPI select SND_SOC_WM8985 if SND_SOC_I2C_AND_SPI diff --git a/sound/soc/codecs/wm8974.c b/sound/soc/codecs/wm8974.c index b012e4d..8af553c 100644 --- a/sound/soc/codecs/wm8974.c +++ b/sound/soc/codecs/wm8974.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -48,6 +49,10 @@ static const u16 wm8974_reg[WM8974_CACHEREGNUM] = { #define WM8974_POWER1_BIASEN 0x08 #define WM8974_POWER1_BUFIOEN 0x04 +struct wm8974_priv { + enum snd_soc_control_type control_type; +}; + #define wm8974_reset(c) snd_soc_write(c, WM8974_RESET, 0) static const char *wm8974_companding[] = {"Off", "NC", "u-law", "A-law" }; @@ -617,8 +622,9 @@ static int wm8974_resume(struct snd_soc_codec *codec) static int wm8974_probe(struct snd_soc_codec *codec) { int ret = 0; + struct wm8974_priv *wm8974 = snd_soc_codec_get_drvdata(codec); - ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_I2C); + ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8974->control_type); if (ret < 0) { dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); return ret; @@ -660,13 +666,64 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8974 = { .num_dapm_routes = ARRAY_SIZE(wm8974_dapm_routes), }; +#if defined(CONFIG_SPI_MASTER) +static int __devinit wm8974_spi_probe(struct spi_device *spi) +{ + struct wm8974_priv *wm8974; + int ret; + + wm8974 = kzalloc(sizeof(*wm8974), GFP_KERNEL); + if (!wm8974) + return -ENOMEM; + + wm8974->control_type = SND_SOC_SPI; + spi_set_drvdata(spi, wm8974); + + ret = snd_soc_register_codec(&spi->dev, + &soc_codec_dev_wm8974, &wm8974_dai, 1); + if (ret) + kfree(wm8974); + + return ret; +} + +static int __devexit wm8974_spi_remove(struct spi_device *spi) +{ + snd_soc_unregister_codec(&spi->dev); + kfree(spi_get_drvdata(spi)); + return 0; +} + +static struct spi_driver wm8974_spi_driver = { + .driver = { + .name = "wm8974", + .owner = THIS_MODULE, + }, + .probe = wm8974_spi_probe, + .remove = __devexit_p(wm8974_spi_remove), +}; + +module_spi_driver(wm8974_spi_driver); +#endif + +#if IS_ENABLED(CONFIG_I2C) static __devinit int wm8974_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { + struct wm8974_priv *wm8974; int ret; + wm8974 = kzalloc(sizeof(*wm8974), GFP_KERNEL); + if (!wm8974) + return -ENOMEM; + + wm8974->control_type = SND_SOC_I2C; + i2c_set_clientdata(i2c, wm8974); + ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_wm8974, &wm8974_dai, 1); + if (ret) + kfree(wm8974); return ret; } @@ -674,7 +731,7 @@ static __devinit int wm8974_i2c_probe(struct i2c_client *i2c, static __devexit int wm8974_i2c_remove(struct i2c_client *client) { snd_soc_unregister_codec(&client->dev); - + kfree(i2c_get_clientdata(client)); return 0; } @@ -695,6 +752,7 @@ static struct i2c_driver wm8974_i2c_driver = { }; module_i2c_driver(wm8974_i2c_driver); +#endif MODULE_DESCRIPTION("ASoC WM8974 driver"); MODULE_AUTHOR("Liam Girdwood");