From patchwork Thu Dec 13 10:42:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Padmavathi Venna X-Patchwork-Id: 1871681 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 81B6EDF2EF for ; Thu, 13 Dec 2012 10:46:58 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Tj6FG-0002PJ-V5; Thu, 13 Dec 2012 10:42:27 +0000 Received: from mailout2.samsung.com ([203.254.224.25]) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Tj6Ex-0002Mt-RK for linux-arm-kernel@lists.infradead.org; Thu, 13 Dec 2012 10:42:10 +0000 Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MEY00BJ7TPZNVU0@mailout2.samsung.com> for linux-arm-kernel@lists.infradead.org; Thu, 13 Dec 2012 19:42:05 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.123]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id E4.A9.01231.DF0B9C05; Thu, 13 Dec 2012 19:42:05 +0900 (KST) X-AuditID: cbfee61a-b7fa66d0000004cf-6c-50c9b0fd139d Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id F3.A9.01231.CF0B9C05; Thu, 13 Dec 2012 19:42:04 +0900 (KST) Received: from padma-linuxpc.sisodomain.com ([107.108.83.35]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MEY00FYNTPOTH90@mmp2.samsung.com> for linux-arm-kernel@lists.infradead.org; Thu, 13 Dec 2012 19:42:04 +0900 (KST) From: Padmavathi Venna To: padma.v@samsung.com, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, alsa-devel@alsa-project.org, devicetree-discuss@lists.ozlabs.org Subject: [PATCH V5 2/2] ASoC: SAMSUNG: Add DT support for i2s Date: Thu, 13 Dec 2012 16:12:53 +0530 Message-id: <1355395373-22058-3-git-send-email-padma.v@samsung.com> X-Mailer: git-send-email 1.7.4.4 In-reply-to: <1355395373-22058-1-git-send-email-padma.v@samsung.com> References: <1355395373-22058-1-git-send-email-padma.v@samsung.com> DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrNLMWRmVeSWpSXmKPExsWyRsSkWvfvhpMBBlfncFtsenyN1YHRY/OS +gDGKC6blNSczLLUIn27BK6MU5fa2QsmZVUcXRnSwDg/tIuRk0NCwETi36vnrBC2mMSFe+vZ uhi5OIQEljJKbLnfywxTNGVvC1RiOqPElb+voZytTBJnz9xg6WLk4GAT0JFoOesCEhcRWMYo cfDiY1YQh1lgIaNE56vJYDuEBWwl3s5qZASxWQRUJQ52NoHFeQWcJb7svw11h4LEsalfWUGG cgq4SBz6kQgSFgIqWdv9igmiVUDi2+RDYHslBGQlNh1gBlklIXCZTaLn8mF2iDGSEgdX3GCZ wCi8gJFhFaNoakFyQXFSeq6hXnFibnFpXrpecn7uJkZgCJ7+90xqB+PKBotDjAIcjEo8vAXh JwOEWBPLiitzDzFKcDArifD6LwcK8aYkVlalFuXHF5XmpBYfYvQBumQis5Rocj4wPvJK4g2N TcxNjU0tjYzMTE1xCCuJ8zZ7pAQICaQnlqRmp6YWpBbBjGPi4JRqYIz8UWMfuyLP3LdO/Ynq V/nNXn8tnpgZr0zbLa2yruCLyt5u/q8b/z9S/qxz5286q8HS1WsN/V68tH973XcN+yvRMmWO YuG63LsZe87ohc02PfxZZu61c5PEm7TedDS3HHvfM91uUVc6O+vWtSdmHjfhfGG5xOJqQ9br DRM3f2IssU5cuOO9z0MlluKMREMt5qLiRABsKJcjbgIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupikeLIzCtJLcpLzFFi42I5/e+xoO6fDScDDPa+trHY9PgaqwOjx+Yl 9QGMUQ2MNhmpiSmpRQqpecn5KZl56bZK3sHxzvGmZgaGuoaWFuZKCnmJuam2Si4+AbpumTlA U5UUyhJzSoFCAYnFxUr6dpgmhIa46VrANEbo+oYEwfUYGaCBhDWMGacutbMXTMqqOLoypIFx fmgXIyeHhICJxJS9LWwQtpjEhXvrgWwuDiGB6YwSV/6+hnK2MkmcPXODpYuRg4NNQEei5awL SFxEYBmjxMGLj1lBHGaBhYwSna8ms4KMEhawlXg7q5ERxGYRUJU42NkEFucVcJb4sv82K8Q6 BYljU7+yggzlFHCROPQjESQsBFSytvsV0wRG3gWMDKsYRVMLkguKk9JzDfWKE3OLS/PS9ZLz czcxggP8mdQOxpUNFocYBTgYlXh4C8JPBgixJpYVV+YeYpTgYFYS4fVfDhTiTUmsrEotyo8v Ks1JLT7E6AN01ERmKdHkfGD05ZXEGxqbmJsam1qaWJiYWeIQVhLnbfZICRASSE8sSc1OTS1I LYIZx8TBKdXAKDh956ew5dlyl93C5rV3FQl9yCuL+d50Y9tUngfu9YbzQlPqM6q+eLC/b3jN 4P+0zn1J0kdRHubG78sk47gYFkV5ZSjrp/07Gsju9lvy1O3Qxu7Vi6RbVmxo/T3HuLNUsdfM P//6jxvPU7Vn6bIXHQpvdDn7cv7ioHcen65YsIRNu9ow44igEktxRqKhFnNRcSIAiWVN4Z0C AAA= X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121213_054208_362496_BBDC4C16 X-CRM114-Status: GOOD ( 20.51 ) X-Spam-Score: -7.6 (-------) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-7.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [203.254.224.25 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -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: jassisinghbrar@gmail.com, kgene.kim@samsung.com, sbkim73@samsung.com, broonie@opensource.wolfsonmicro.com, tiwai@suse.de, ben-linux@fluff.org, lrg@ti.com 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: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Add support for device based discovery. Signed-off-by: Padmavathi Venna --- .../devicetree/bindings/sound/samsung-i2s.txt | 75 +++++++ sound/soc/samsung/dma.c | 1 + sound/soc/samsung/dma.h | 1 + sound/soc/samsung/i2s.c | 233 ++++++++++++++++---- 4 files changed, 269 insertions(+), 41 deletions(-) create mode 100644 Documentation/devicetree/bindings/sound/samsung-i2s.txt diff --git a/Documentation/devicetree/bindings/sound/samsung-i2s.txt b/Documentation/devicetree/bindings/sound/samsung-i2s.txt new file mode 100644 index 0000000..bff47b4 --- /dev/null +++ b/Documentation/devicetree/bindings/sound/samsung-i2s.txt @@ -0,0 +1,75 @@ +* Samsung I2S controller + +Required SoC Specific Properties: + +- compatible : "samsung,samsung-i2s" +- reg: physical base address of the controller and length of memory mapped + region. + +[PRELIMINARY: the dma channel allocation will change once there are +official DMA bindings] + +- tx-dma-channel-secondary: The dma channel specifier for secondary tx + operations. The format of the dma specifier depends on the dma + controller. +- tx-dma-channel: The dma channel specifier for tx operations. The format of + the dma specifier depends on the dma controller. +- rx-dma-channel: The dma channel specifier for rx operations. The format of + the dma specifier depends on the dma controller. + +Optional SoC Specific Properties: + +- samsung,supports-6ch: If the I2S Primary sound source has 5.1 Channel + support, this flag is enabled. +- samsung,supports-rstclr: This flag should be set if I2S software reset bit + control is required. When this flag is set I2S software reset bit will be + enabled or disabled based on need. +- samsung,supports-secdai:If I2S block has a secondary FIFO and internal DMA, + then this flag is enabled. +- samsung,idma-addr: Internal DMA register base address of the audio + sub system(used in secondary sound source). + +Required Board Specific Properties: + +- gpios: The gpio specifier for data out,data in, LRCLK, CDCLK and SCLK + interface lines. The format of the gpio specifier depends on the gpio + controller. + The syntax of samsung gpio specifier is + <[phandle of the gpio controller node] + [pin number within the gpio controller] + [mux function] + [flags and pull up/down] + [drive strength]> + +Aliases: + +- All the I2S controller nodes are represented in the aliases node using + the following format 'i2s{n}' where n is a unique number for the alias. + +Example: + +- SoC Specific Portion: + +i2s@03830000 { + compatible = "samsung,samsung-i2s"; + reg = <0x03830000 0x100>; + tx-dma-channel-secondary = <&pdma0 8>; + tx-dma-channel = <&pdma0 10>; + rx-dma-channel = <&pdma0 9>; + samsung,supports-6ch; + samsung,supports-rstclr; + samsung,supports-secdai; + samsung,idma-addr = <0x03000000>; +}; + +- Board Specific Portion: + +i2s_0: i2s@03830000 { + gpios = <&gpz 0 2 0 0>, /* I2S_0_SCLK */ + <&gpz 1 2 0 0>, /* I2S_0_CDCLK */ + <&gpz 2 2 0 0>, /* I2S_0_LRCK */ + <&gpz 3 2 0 0>, /* I2S_0_SDI */ + <&gpz 4 2 0 0>, /* I2S_0_SDO[1] */ + <&gpz 5 2 0 0>, /* I2S_0_SDO[2] */ + <&gpz 6 2 0 0>; /* I2S_0_SDO[3] */ +}; diff --git a/sound/soc/samsung/dma.c b/sound/soc/samsung/dma.c index db87628..eb79844 100644 --- a/sound/soc/samsung/dma.c +++ b/sound/soc/samsung/dma.c @@ -168,6 +168,7 @@ static int dma_hw_params(struct snd_pcm_substream *substream, req.cap = (samsung_dma_has_circular() ? DMA_CYCLIC : DMA_SLAVE); req.client = prtd->params->client; + req.dt_dmach_prop = prtd->params->dma_prop; config.direction = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM); diff --git a/sound/soc/samsung/dma.h b/sound/soc/samsung/dma.h index 73d8c7c..9f5b35c 100644 --- a/sound/soc/samsung/dma.h +++ b/sound/soc/samsung/dma.h @@ -19,6 +19,7 @@ struct s3c_dma_params { int dma_size; /* Size of the DMA transfer */ unsigned ch; struct samsung_dma_ops *ops; + struct property *dma_prop; }; int asoc_dma_platform_register(struct device *dev); diff --git a/sound/soc/samsung/i2s.c b/sound/soc/samsung/i2s.c index ed5eeae..e3c9673 100644 --- a/sound/soc/samsung/i2s.c +++ b/sound/soc/samsung/i2s.c @@ -15,11 +15,15 @@ #include #include #include +#include +#include #include #include #include +#include + #include #include "dma.h" @@ -34,6 +38,10 @@ enum samsung_dai_type { TYPE_SEC, }; +struct samsung_i2s_dai_data { + int dai_type; +}; + struct i2s_dai { /* Platform device for this DAI */ struct platform_device *pdev; @@ -71,6 +79,7 @@ struct i2s_dai { u32 suspend_i2smod; u32 suspend_i2scon; u32 suspend_i2spsr; + unsigned long gpios[7]; /* i2s gpio line numbers */ }; /* Lock for cross i/f checks */ @@ -997,19 +1006,79 @@ static struct i2s_dai *i2s_alloc_dai(struct platform_device *pdev, bool sec) return i2s; } +#ifdef CONFIG_OF +static int samsung_i2s_parse_dt_gpio(struct i2s_dai *i2s) +{ + struct device *dev = &i2s->pdev->dev; + int index, gpio, ret; + + for (index = 0; index < 7; index++) { + gpio = of_get_gpio(dev->of_node, index); + if (!gpio_is_valid(gpio)) { + dev_err(dev, "invalid gpio[%d]: %d\n", index, gpio); + goto free_gpio; + } + + ret = gpio_request(gpio, dev_name(dev)); + if (ret) { + dev_err(dev, "gpio [%d] request failed\n", gpio); + goto free_gpio; + } + i2s->gpios[index] = gpio; + } + return 0; + +free_gpio: + while (--index >= 0) + gpio_free(i2s->gpios[index]); + return -EINVAL; +} + +static void samsung_i2s_dt_gpio_free(struct i2s_dai *i2s) +{ + unsigned int index; + for (index = 0; index < 7; index++) + gpio_free(i2s->gpios[index]); +} +#else +static int samsung_i2s_parse_dt_gpio(struct i2s_dai *dai) +{ + return -EINVAL; +} + +static void samsung_i2s_dt_gpio_free(struct i2s_dai *dai) +{ +} + +#endif + +static const struct of_device_id exynos_i2s_match[]; + static inline int samsung_i2s_get_driver_data(struct platform_device *pdev) { - return platform_get_device_id(pdev)->driver_data; +#ifdef CONFIG_OF + struct samsung_i2s_dai_data *data; + if (pdev->dev.of_node) { + const struct of_device_id *match; + match = of_match_node(exynos_i2s_match, pdev->dev.of_node); + data = (struct samsung_i2s_dai_data *) match->data; + return data->dai_type; + } else +#endif + return platform_get_device_id(pdev)->driver_data; } static int samsung_i2s_probe(struct platform_device *pdev) { - u32 dma_pl_chan, dma_cp_chan, dma_pl_sec_chan; + u32 dma_pl_chan, dma_cp_chan; + u32 dma_pl_sec_chan = 0; struct i2s_dai *pri_dai, *sec_dai = NULL; - struct s3c_audio_pdata *i2s_pdata; - struct samsung_i2s *i2s_cfg; + struct s3c_audio_pdata *i2s_pdata = pdev->dev.platform_data; + struct samsung_i2s *i2s_cfg = NULL; struct resource *res; - u32 regs_base, quirks; + u32 regs_base, quirks = 0, idma_addr = 0; + struct property *prop; + struct device_node *np = pdev->dev.of_node; enum samsung_dai_type samsung_dai_type; int ret = 0; @@ -1024,31 +1093,82 @@ static int samsung_i2s_probe(struct platform_device *pdev) return 0; } - i2s_pdata = pdev->dev.platform_data; - if (i2s_pdata == NULL) { - dev_err(&pdev->dev, "Can't work without s3c_audio_pdata\n"); - return -EINVAL; + pri_dai = i2s_alloc_dai(pdev, false); + if (!pri_dai) { + dev_err(&pdev->dev, "Unable to alloc I2S_pri\n"); + return -ENOMEM; } - res = platform_get_resource(pdev, IORESOURCE_DMA, 0); - if (!res) { - dev_err(&pdev->dev, "Unable to get I2S-TX dma resource\n"); - return -ENXIO; - } - dma_pl_chan = res->start; + if (!np) { + res = platform_get_resource(pdev, IORESOURCE_DMA, 0); + if (!res) { + dev_err(&pdev->dev, + "Unable to get I2S-TX dma resource\n"); + return -ENXIO; + } + dma_pl_chan = res->start; - res = platform_get_resource(pdev, IORESOURCE_DMA, 1); - if (!res) { - dev_err(&pdev->dev, "Unable to get I2S-RX dma resource\n"); - return -ENXIO; - } - dma_cp_chan = res->start; + res = platform_get_resource(pdev, IORESOURCE_DMA, 1); + if (!res) { + dev_err(&pdev->dev, + "Unable to get I2S-RX dma resource\n"); + return -ENXIO; + } + dma_cp_chan = res->start; - res = platform_get_resource(pdev, IORESOURCE_DMA, 2); - if (res) - dma_pl_sec_chan = res->start; - else - dma_pl_sec_chan = 0; + res = platform_get_resource(pdev, IORESOURCE_DMA, 2); + if (res) + dma_pl_sec_chan = res->start; + + if (i2s_pdata == NULL) { + dev_err(&pdev->dev, "Can't work without s3c_audio_pdata\n"); + return -EINVAL; + } + + if (&i2s_pdata->type) + i2s_cfg = &i2s_pdata->type.i2s; + + if (i2s_cfg) { + quirks = i2s_cfg->quirks; + idma_addr = i2s_cfg->idma_addr; + } + } else { + prop = of_find_property(np, "tx-dma-channel", NULL); + if (!prop) { + dev_err(&pdev->dev, "tx dma channel property not"\ + "specified\n"); + return -ENXIO; + } + dma_pl_chan = DMACH_DT_PROP; + pri_dai->dma_playback.dma_prop = prop; + + prop = of_find_property(np, "rx-dma-channel", NULL); + if (!prop) { + dev_err(&pdev->dev, "tx dma channel property not"\ + "specified\n"); + return -ENXIO; + } + dma_cp_chan = DMACH_DT_PROP; + pri_dai->dma_capture.dma_prop = prop; + + if (of_find_property(np, "samsung,supports-6ch", NULL)) + quirks |= QUIRK_PRI_6CHAN; + + if (of_find_property(np, "samsung,supports-secdai", NULL)) + quirks |= QUIRK_SEC_DAI; + + if (of_find_property(np, "samsung,supports-rstclr", NULL)) + quirks |= QUIRK_NEED_RSTCLR; + + if (of_property_read_u32(np, "samsung,idma-addr", + &idma_addr)) { + if (quirks & QUIRK_SEC_DAI) { + dev_err(&pdev->dev, "idma address is not"\ + "specified"); + return -EINVAL; + } + } + } res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { @@ -1063,16 +1183,6 @@ static int samsung_i2s_probe(struct platform_device *pdev) } regs_base = res->start; - i2s_cfg = &i2s_pdata->type.i2s; - quirks = i2s_cfg->quirks; - - pri_dai = i2s_alloc_dai(pdev, false); - if (!pri_dai) { - dev_err(&pdev->dev, "Unable to alloc I2S_pri\n"); - ret = -ENOMEM; - goto err; - } - pri_dai->dma_playback.dma_addr = regs_base + I2STXD; pri_dai->dma_capture.dma_addr = regs_base + I2SRXD; pri_dai->dma_playback.client = @@ -1099,20 +1209,41 @@ static int samsung_i2s_probe(struct platform_device *pdev) sec_dai->dma_playback.dma_addr = regs_base + I2STXDS; sec_dai->dma_playback.client = (struct s3c2410_dma_client *)&sec_dai->dma_playback; + + if (np) { + prop = of_find_property(np, "tx-dma-channel-secondary", + NULL); + if (!prop) { + dev_err(&pdev->dev, "tx dma channel property"\ + "not specified\n"); + ret = -ENXIO; + goto err; + } + sec_dai->dma_playback.dma_prop = prop; + } + /* Use iDMA always if SysDMA not provided */ sec_dai->dma_playback.channel = dma_pl_sec_chan ? : -1; sec_dai->dma_playback.dma_size = 4; sec_dai->base = regs_base; sec_dai->quirks = quirks; - sec_dai->idma_playback.dma_addr = i2s_cfg->idma_addr; + sec_dai->idma_playback.dma_addr = idma_addr; sec_dai->pri_dai = pri_dai; pri_dai->sec_dai = sec_dai; } - if (i2s_pdata->cfg_gpio && i2s_pdata->cfg_gpio(pdev)) { - dev_err(&pdev->dev, "Unable to configure gpio\n"); - ret = -EINVAL; - goto err; + if (np) { + if (samsung_i2s_parse_dt_gpio(pri_dai)) { + dev_err(&pdev->dev, "Unable to configure gpio\n"); + ret = -EINVAL; + goto err; + } + } else { + if (i2s_pdata->cfg_gpio && i2s_pdata->cfg_gpio(pdev)) { + dev_err(&pdev->dev, "Unable to configure gpio\n"); + ret = -EINVAL; + goto err; + } } snd_soc_register_dai(&pri_dai->pdev->dev, &pri_dai->i2s_dai_drv); @@ -1132,10 +1263,14 @@ static int samsung_i2s_remove(struct platform_device *pdev) { struct i2s_dai *i2s, *other; struct resource *res; + struct s3c_audio_pdata *i2s_pdata = pdev->dev.platform_data; i2s = dev_get_drvdata(&pdev->dev); other = i2s->pri_dai ? : i2s->sec_dai; + if (!i2s_pdata->cfg_gpio && pdev->dev.of_node) + samsung_i2s_dt_gpio_free(i2s->pri_dai); + if (other) { other->pri_dai = NULL; other->sec_dai = NULL; @@ -1167,6 +1302,21 @@ static struct platform_device_id samsung_i2s_driver_ids[] = { }; MODULE_DEVICE_TABLE(platform, samsung-i2s-driver-ids); +#ifdef CONFIG_OF +static struct samsung_i2s_dai_data samsung_i2s_dai_data_array[] = { + [TYPE_PRI] = { TYPE_PRI }, + [TYPE_SEC] = { TYPE_SEC }, +}; + +static const struct of_device_id exynos_i2s_match[] = { + { .compatible = "samsung,samsung-i2s", + .data = &samsung_i2s_dai_data_array[TYPE_PRI], + }, + {}, +}; +MODULE_DEVICE_TABLE(of, exynos_i2s_match); +#endif + static struct platform_driver samsung_i2s_driver = { .probe = samsung_i2s_probe, .remove = samsung_i2s_remove, @@ -1174,6 +1324,7 @@ static struct platform_driver samsung_i2s_driver = { .driver = { .name = "samsung-i2s", .owner = THIS_MODULE, + .of_match_table = of_match_ptr(exynos_i2s_match), }, };