From patchwork Thu Nov 8 05:37:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rajeshwari Shinde X-Patchwork-Id: 12756 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id B1EF223E00 for ; Thu, 8 Nov 2012 05:34:51 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 43C77A1946A for ; Thu, 8 Nov 2012 05:34:51 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so3506439iej.11 for ; Wed, 07 Nov 2012 21:34:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:x-auditid :from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :dlp-filter:x-mtr:x-brightmail-tracker:x-brightmail-tracker :x-cfilter-loop:x-gm-message-state; bh=u9sAnMCyJ4cMHYIG/Cwur4ZHDOFa6IgnkndUZ58TBJQ=; b=Z43KxEyZ0OWQy2T4Me4YZW0m2JUbeCN0OscMWJVATRqfjp7v4TeYqQqaGv7xN39y+H 63XTv3I4PijboKv8vV/XBWmYMcPaWkyRCvdQB1KCbm6zLtt6d32Zb7zE7QJFNriRRJIS JJaIiN+rJhgijTDi7icTXLimYOBX6ZXCGw3pI5cXckGBMWEtjRX4W5VRgWI7UEZzrWVL TrdueV2aoHSegwKaeOZrWDPz6MT3KXa+pTtDbKFApTwaCtIPU9/mRcBpXL4fRDLHv0Bv uSXeEDVBjgNJbYG0W/SbuFfJbzFhvADKYYuLnWQUwLrvicM/Y4MByL1qV8/xdsl9hfHH v/Og== Received: by 10.43.7.132 with SMTP id oo4mr6179985icb.6.1352352890680; Wed, 07 Nov 2012 21:34:50 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.67.148 with SMTP id n20csp325449igt; Wed, 7 Nov 2012 21:34:50 -0800 (PST) Received: by 10.68.192.97 with SMTP id hf1mr20595066pbc.106.1352352889963; Wed, 07 Nov 2012 21:34:49 -0800 (PST) Received: from mailout4.samsung.com (mailout4.samsung.com. [203.254.224.34]) by mx.google.com with ESMTP id bc7si33897875pab.123.2012.11.07.21.34.49; Wed, 07 Nov 2012 21:34:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of rajeshwari.s@samsung.com designates 203.254.224.34 as permitted sender) client-ip=203.254.224.34; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of rajeshwari.s@samsung.com designates 203.254.224.34 as permitted sender) smtp.mail=rajeshwari.s@samsung.com Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MD500HY7M5QO8N0@mailout4.samsung.com>; Thu, 08 Nov 2012 14:34:48 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.123]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id B3.63.01231.8744B905; Thu, 08 Nov 2012 14:34:48 +0900 (KST) X-AuditID: cbfee61a-b7fa66d0000004cf-30-509b44786951 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 63.63.01231.8744B905; Thu, 08 Nov 2012 14:34:48 +0900 (KST) Received: from rajeshwari-linux.sisodomain.com ([107.108.215.115]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MD500CD1M0GTL50@mmp1.samsung.com>; Thu, 08 Nov 2012 14:34:48 +0900 (KST) From: Rajeshwari Shinde To: u-boot@lists.denx.de Cc: patches@linaro.org, sjg@chromium.org, mk7.kang@samsung.com, chander.kashyap@linaro.org Subject: [PATCH 4/5] Sound: Add FDT support to driver Date: Thu, 08 Nov 2012 11:07:18 +0530 Message-id: <1352353039-17165-5-git-send-email-rajeshwari.s@samsung.com> X-Mailer: git-send-email 1.7.4.4 In-reply-to: <1352353039-17165-1-git-send-email-rajeshwari.s@samsung.com> References: <1352353039-17165-1-git-send-email-rajeshwari.s@samsung.com> DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrILMWRmVeSWpSXmKPExsWyRsSkWrfCZXaAwYS9GhYP199ksZhy+AuL A5PHnWt72AIYo7hsUlJzMstSi/TtErgyerv+MxUcdq2YuOQYcwPjTPMuRk4OCQETiQ1PDjFC 2GISF+6tZ+ti5OIQEljKKLFgTzcrTNHms9OZIRKLGCUmNdxhgXAmMknMuzcHrIpNwEhi68lp YKNEBCQkfvVfBbOZBWIkXu//wQZiCwuYSqzevhssziKgKvHsbhM7iM0r4CFx/eUcNohtChLH pn4Fm8kp4CkxbcISoM0cQMs8JC4eK4BoFZD4NvkQC0hYQkBWYtMBsNskBG6zSTw63wI1RlLi 4IobLBMYhRcwMqxiFE0tSC4oTkrPNdQrTswtLs1L10vOz93ECAzH0/+eSe1gXNlgcYhRgINR iYdXQ3J2gBBrYllxZe4hRgkOZiUR3ilHZgUI8aYkVlalFuXHF5XmpBYfYvQBumQis5Rocj4w VvJK4g2NTcxNjU0tjYzMTE1xCCuJ8zZ7pAQICaQnlqRmp6YWpBbBjGPi4JRqYJSqKRRyeBGl JHnFOrRsZsi1q2tPtoZ154qucVgcNa3/n/RSJbdP789u2TGxf1JUkXv5ta1WJ///dv78aIV/ Z9yOBtcFHJMP1GQ+Y2S4/rztL9vHCzq/BY4seiGbsH9fGfvhB5uXZ5iUHPh26u4aPeVU9Uc8 93gyz7+Y/2R+0vl3fgf3mK26seCIEktxRqKhFnNRcSIAbsnrPnQCAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprAIsWRmVeSWpSXmKPExsVy+t9jAd0Kl9kBBh83Slk8XH+TxWLK4S8s Dkwed67tYQtgjGpgtMlITUxJLVJIzUvOT8nMS7dV8g6Od443NTMw1DW0tDBXUshLzE21VXLx CdB1y8wBmq2kUJaYUwoUCkgsLlbSt8M0ITTETdcCpjFC1zckCK7HyAANJKxhzOjt+s9UcNi1 YuKSY8wNjDPNuxg5OSQETCQ2n53ODGGLSVy4t56ti5GLQ0hgEaPEpIY7LBDORCaJeffmsIJU sQkYSWw9OY0RxBYRkJD41X8VzGYWiJF4vf8HG4gtLGAqsXr7brA4i4CqxLO7TewgNq+Ah8T1 l3PYILYpSByb+hVsJqeAp8S0CUuAruAAWuYhcfFYwQRG3gWMDKsYRVMLkguKk9JzDfWKE3OL S/PS9ZLzczcxgoP9mdQOxpUNFocYBTgYlXh4NSRnBwixJpYVV+YeYpTgYFYS4Z1yZFaAEG9K YmVValF+fFFpTmrxIUYfoKMmMkuJJucDIzGvJN7Q2MTc1NjU0sTCxMwSh7CSOG+zR0qAkEB6 YklqdmpqQWoRzDgmDk6pBkb7Pg+m0s92Uk4ld+cfCygofN3ssSf3vczxhvmFUVpyPPZKpaU6 RrqCmvnN1277VyWcfv52iWCkuPXHsgt758Zt3Sa0YdcuRsdanoQ12tc4zzmpmV9fxc2jcKYn TWlrBp99SpKnarvNnnuL5P8Y3z4emTW5kcP8Jtf+ncKem0WWP7Riat22TomlOCPRUIu5qDgR AMo+ScWjAgAA X-CFilter-Loop: Reflected X-Gm-Message-State: ALoCoQkw2gwOVP2CYS/zrUOaOmdrPe94iUpfmJa8I+I2f01hvWmJaDV+1E8+t9hLIzRpepcrbga7 This patch adds FDT support to the driver. Signed-off-by: Rajeshwari Shinde --- drivers/sound/sound.c | 228 +++++++++++++++++++++++++++++++++++++++++++++++-- include/sound.h | 9 ++ 2 files changed, 230 insertions(+), 7 deletions(-) diff --git a/drivers/sound/sound.c b/drivers/sound/sound.c index 4c74534..3a845c9 100644 --- a/drivers/sound/sound.c +++ b/drivers/sound/sound.c @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include #include #include @@ -37,12 +39,225 @@ static struct i2stx_info g_i2stx_pri; static struct sound_codec_info g_codec_info; + +#ifdef CONFIG_OF_CONTROL /* - * get_sound_fdt_values gets fdt values for i2s parameters + * get_sound_i2s_fdt_values gets fdt values for i2s parameters * * @param i2stx_info i2s transmitter transfer param structure * @param blob FDT blob */ +static int get_sound_i2s_fdt_values(struct i2stx_info *i2s, const void *blob) +{ + int node; + int error = 0; + int base; + + node = fdtdec_next_compatible(blob, 0, + COMPAT_SAMSUNG_EXYNOS5_SOUND); + if (node <= 0) { + debug("EXYNOS_SOUND: No node for sound in device tree\n"); + return -1; + } + + /* + * Get the pre-defined sound specific values from FDT. + * All of these are expected to be correct otherwise + * wrong register values in i2s setup parameters + * may result in no sound play. + */ + base = fdtdec_get_addr(blob, node, "reg"); + if (base == FDT_ADDR_T_NONE) { + debug("%s: Missing i2s base\n", __func__); + return -1; + } + i2s->base_address = base; + + i2s->audio_pll_clk = fdtdec_get_int(blob, + node, "samsung,i2s-epll-clock-frequency", -1); + error |= i2s->audio_pll_clk; + debug("audio_pll_clk = %d\n", i2s->audio_pll_clk); + i2s->samplingrate = fdtdec_get_int(blob, + node, "samsung,i2s-sampling-rate", -1); + error |= i2s->samplingrate; + debug("samplingrate = %d\n", i2s->samplingrate); + i2s->bitspersample = fdtdec_get_int(blob, + node, "samsung,i2s-bits-per-sample", -1); + error |= i2s->bitspersample; + debug("bitspersample = %d\n", i2s->bitspersample); + i2s->channels = fdtdec_get_int(blob, + node, "samsung,i2s-channels", -1); + error |= i2s->channels; + debug("channels = %d\n", i2s->channels); + i2s->rfs = fdtdec_get_int(blob, + node, "samsung,i2s-lr-clk-framesize", -1); + error |= i2s->rfs; + debug("rfs = %d\n", i2s->rfs); + i2s->bfs = fdtdec_get_int(blob, + node, "samsung,i2s-bit-clk-framesize", -1); + error |= i2s->bfs; + debug("bfs = %d\n", i2s->bfs); + if (error == -1) { + debug("fail to get sound i2s node properties\n"); + return -1; + } + + return 0; +} + +/* + * Gets fdt values for wm8994 config parameters + * + * @param pcodec_info codec information structure + * @param blob FDT blob + * @return int value, 0 for success + */ +static int get_sound_fdt_values(struct sound_codec_info *pcodec_info, + const void *blob, enum fdt_compat_id compat_id) +{ + enum fdt_compat_id compat; + int node; + int error = 0; + int parent; + + /* Get the node from FDT for codec */ + node = fdtdec_next_compatible(blob, 0, compat_id); + if (node <= 0) { + debug("EXYNOS_SOUND: No node for codec in device tree\n"); + debug("node = %d\n", node); + return -1; + } + + parent = fdt_parent_offset(blob, node); + if (parent < 0) { + debug("%s: Cannot find node parent\n", __func__); + return -1; + } + + compat = fdtdec_lookup(blob, parent); + switch (compat) { + case COMPAT_SAMSUNG_EXYNOS_SPI: + debug("%s: Support not added for SPI interface\n", __func__); + return -1; + break; + case COMPAT_SAMSUNG_S3C2440_I2C: + pcodec_info->i2c_bus = i2c_get_bus_num_fdt(blob, parent); + error |= pcodec_info->i2c_bus; + debug("i2c bus = %d\n", pcodec_info->i2c_bus); + pcodec_info->i2c_dev_addr = fdtdec_get_int(blob, node, + "reg", 0); + error |= pcodec_info->i2c_dev_addr; + debug("i2c dev addr = %d\n", pcodec_info->i2c_dev_addr); + break; + default: + debug("%s: Unknown compat id %d\n", __func__, compat); + return -1; + } + + if (error == -1) { + debug("fail to get codec node properties\n"); + return -1; + } + + return 0; +} + +/* + * Gets fdt values for codec config parameters + * + * @param pcodec_info codec information structure + * @param blob FDT blob + * @return int value, 0 for success + */ +static int get_sound_codec_fdt_values(struct sound_codec_info *pcodec_info, + const void *blob) +{ + int node; + int error = 0; + const char *codectype; + + /* Get the node from FDT for sound */ + node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS5_SOUND); + if (node <= 0) { + debug("EXYNOS_SOUND: No node for sound in device tree\n"); + debug("node = %d\n", node); + return -1; + } + + /* + * Get the pre-defined sound codec specific values from FDT. + * All of these are expected to be correct otherwise sound + * can not be played + */ + codectype = fdt_getprop(blob, node, "samsung,codec-type", NULL); + debug("device = %s\n", codectype); + + if (!strcmp(codectype, "wm8994")) { + pcodec_info->codec_type = CODEC_WM_8994; + error = get_sound_fdt_values(pcodec_info, blob, + COMPAT_WOLFSON_WM8994_CODEC); + } else { + error = -1; + } + + if (error == -1) { + debug("fail to get sound codec node properties\n"); + return -1; + } + + return 0; +} + +int sound_init(const void *blob) +{ + int ret; + struct i2stx_info *pi2s_tx = &g_i2stx_pri; + struct sound_codec_info *pcodec_info = &g_codec_info; + + /* Get the I2S Values */ + if (get_sound_i2s_fdt_values(pi2s_tx, blob) < 0) { + debug(" FDT I2S values failed\n"); + return -1; + } + + /* Get the codec Values */ + if (get_sound_codec_fdt_values(pcodec_info, blob) < 0) { + debug("FDT Codec values failed\n"); + return -1; + } + + ret = i2s_tx_init(pi2s_tx); + if (ret) { + debug("%s: Failed to init i2c transmit: ret=%d\n", __func__, + ret); + return ret; + } + + /* Check the codec type and initialise the same */ + if (pcodec_info->codec_type == CODEC_WM_8994) { + ret = wm8994_init(pcodec_info, WM8994_AIF2, + pi2s_tx->samplingrate, + (pi2s_tx->samplingrate * (pi2s_tx->rfs)), + pi2s_tx->bitspersample, pi2s_tx->channels); + } else { + debug("%s: Unknown code type %d\n", __func__, + pcodec_info->codec_type); + return -1; + } + if (ret) { + debug("%s: Codec init failed\n", __func__); + return -1; + } + + return ret; +} + +#else +/* + * get_sound_values gets values for i2s parameters + * + * @param i2stx_info i2s transmitter transfer param structure + */ static void get_sound_i2s_values(struct i2stx_info *i2s) { i2s->base_address = samsung_get_base_i2s(); @@ -55,13 +270,12 @@ static void get_sound_i2s_values(struct i2stx_info *i2s) } /* - * Gets fdt values for wm8994 config parameters + * Gets values for wm8994 config parameters * * @param pcodec_info codec information structure - * @param blob FDT blob * @return int value, 0 for success */ -static int get_sound_wm8994_values(struct sound_codec_info *pcodec_info) +static int get_sound_values(struct sound_codec_info *pcodec_info) { int error = 0; @@ -89,10 +303,9 @@ static int get_sound_wm8994_values(struct sound_codec_info *pcodec_info) } /* - * Gets fdt values for codec config parameters + * Gets values for codec config parameters * * @param pcodec_info codec information structure - * @param blob FDT blob * @return int value, 0 for success */ static int get_sound_codec_values(struct sound_codec_info *pcodec_info) @@ -104,7 +317,7 @@ static int get_sound_codec_values(struct sound_codec_info *pcodec_info) if (!strcmp(codectype, "wm8994")) { pcodec_info->codec_type = CODEC_WM_8994; - error = get_sound_wm8994_values(pcodec_info); + error = get_sound_values(pcodec_info); } else { error = -1; } @@ -155,6 +368,7 @@ int sound_init(void) return ret; } +#endif /* * Generates square wave sound data for 1 second diff --git a/include/sound.h b/include/sound.h index ea0b115..aeb70ee 100644 --- a/include/sound.h +++ b/include/sound.h @@ -44,12 +44,21 @@ struct sound_codec_info { enum en_sound_codec codec_type; }; +#ifdef CONFIG_OF_CONTROL +/* + * Initialises audio sub system + * @param blob Pointer of device tree node. + * @return int value 0 for success, -1 for error + */ +int sound_init(const void *blob); +#else /* * Initialises audio sub system * * @return int value 0 for success, -1 for error */ int sound_init(void); +#endif /* * plays the pcm data buffer in pcm_data.h through i2s1 to make the