From patchwork Thu Nov 29 07:55:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rajeshwari Shinde X-Patchwork-Id: 13286 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 065C52425B for ; Thu, 29 Nov 2012 07:49:40 +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 71371A18BF8 for ; Thu, 29 Nov 2012 07:49:39 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id c10so9628217ieb.11 for ; Wed, 28 Nov 2012 23:49:39 -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=nNcHBR44tRHOLnQtgwKqp9cacUhdsCf4UOifqxlBm9s=; b=DLJYSU88n7mQBHstdumhTYJl8Uavhr9yrfYCs8Wgd9oIBdPgVuPkPN+f65tmJm3mPP evDWo76mtvfUtWX9QcjWRlMDSD66YhPicZR1KZLAKNVmQf/+/G2/bb79isaZx7J0I6Na s6NUZi1HVS2wPYVo6LDIiop0x22TL0JPJZT7EXyHHEucrIjifMZSDLD5GmITMrmL4MZE oX9GAJkWlTsMjojmxAHATgVijXPc8AgWqoLcKKqUbKGsFvhlfyj7kWC20lv2j9ZjKEQk BK9gwUv6VtzI7OdKgOSsi713LoKfTGCjreujXcqVImRlmRl4qRn4cv0uMZorwhdQ6P2S wnDA== Received: by 10.50.213.69 with SMTP id nq5mr24461630igc.70.1354175379133; Wed, 28 Nov 2012 23:49:39 -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 n20csp806389igt; Wed, 28 Nov 2012 23:49:38 -0800 (PST) Received: by 10.66.85.103 with SMTP id g7mr41289934paz.45.1354175378354; Wed, 28 Nov 2012 23:49:38 -0800 (PST) Received: from mailout3.samsung.com (mailout3.samsung.com. [203.254.224.33]) by mx.google.com with ESMTP id t9si1374421paz.26.2012.11.28.23.49.37; Wed, 28 Nov 2012 23:49:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of rajeshwari.s@samsung.com designates 203.254.224.33 as permitted sender) client-ip=203.254.224.33; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of rajeshwari.s@samsung.com designates 203.254.224.33 as permitted sender) smtp.mail=rajeshwari.s@samsung.com Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0ME800HYJOE8XD10@mailout3.samsung.com>; Thu, 29 Nov 2012 16:49:36 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.125]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 1E.D0.01231.09317B05; Thu, 29 Nov 2012 16:49:36 +0900 (KST) X-AuditID: cbfee61a-b7fa66d0000004cf-5b-50b713907298 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id CD.D0.01231.09317B05; Thu, 29 Nov 2012 16:49:36 +0900 (KST) Received: from rajeshwari-linux.sisodomain.com ([107.108.215.115]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0ME800LQWOECLB50@mmp2.samsung.com>; Thu, 29 Nov 2012 16:49:36 +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/6 V3] Sound: Add FDT support to driver Date: Thu, 29 Nov 2012 13:25:50 +0530 Message-id: <1354175752-17233-5-git-send-email-rajeshwari.s@samsung.com> X-Mailer: git-send-email 1.7.4.4 In-reply-to: <1354175752-17233-1-git-send-email-rajeshwari.s@samsung.com> References: <1354175752-17233-1-git-send-email-rajeshwari.s@samsung.com> DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrALMWRmVeSWpSXmKPExsWyRsSkVneC8PYAg3lNZhYP199ksZhy+AuL A5PHnWt72AIYo7hsUlJzMstSi/TtErgytt++yFwwza5ixut3jA2Mxwy7GDk5JARMJC5N7mGC sMUkLtxbz9bFyMUhJLCUUeLJj9eMMEVn+/vAbCGB6YwSnVf8IIomMklc63/EApJgEzCS2Hpy GliRiICExK/+q2A2s0CMxOv9P9hAbGEBC4kPe+6zdjFycLAIqErs2uYDEuYV8JA4+LKFGWKX gsSxqV9ZQWxOAU+JT5u6WCH2ekhsWL0GbCSLgIDEt8mHWEDGSAjISmw6wAxyjoTAbTaJW3cm Qt0sKXFwxQ2WCYzCCxgZVjGKphYkFxQnpeca6hUn5haX5qXrJefnbmIEBuPpf8+kdjCubLA4 xCjAwajEw7vJcluAEGtiWXFl7iFGCQ5mJRFezT9AId6UxMqq1KL8+KLSnNTiQ4w+QJdMZJYS Tc4HRkpeSbyhsYm5qbGppZGRmakpDmElcd5mj5QAIYH0xJLU7NTUgtQimHFMHJxSDYyyNoyT 9zd7bnl1cNVOk6muEas9jAqCZzEIyScvFVyX8is50V3nuoeIUh6LZlSVVMKVp++uJcluDn4a cvG1rer3TYeeWjNrt5REaBhppC/guCCb7K7w4zPbXKE5woeFj+3h/G1RyRzzwX5z26QzqZ9Y a260MsvULKtpMnh7TbKS5/H+9EepP5VYijMSDbWYi4oTAZrP4R5zAgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupnkeLIzCtJLcpLzFFi42I5/e+xoO4E4e0BBj0bNSwerr/JYjHl8BcW ByaPO9f2sAUwRjUw2mSkJqakFimk5iXnp2TmpdsqeQfHO8ebmhkY6hpaWpgrKeQl5qbaKrn4 BOi6ZeYAzVZSKEvMKQUKBSQWFyvp22GaEBripmsB0xih6xsSBNdjZIAGEtYwZmy/fZG5YJpd xYzX7xgbGI8ZdjFyckgImEic7e9jhLDFJC7cW88GYgsJTGeU6Lzi18XIBWRPZJK41v+IBSTB JmAksfXkNLAGEQEJiV/9V8FsZoEYidf7f4A1CwtYSHzYc5+1i5GDg0VAVWLXNh+QMK+Ah8TB ly3MELsUJI5N/coKYnMKeEp82tTFCrHXQ2LD6jWMExh5FzAyrGIUTS1ILihOSs811CtOzC0u zUvXS87P3cQIDvVnUjsYVzZYHGIU4GBU4uHdZLktQIg1say4MvcQowQHs5IIr+YfoBBvSmJl VWpRfnxRaU5q8SFGH6CjJjJLiSbnA+MwryTe0NjE3NTY1NLEwsTMEoewkjhvs0dKgJBAemJJ anZqakFqEcw4Jg5OqQZG46CkL9uvvbYu3mJwd0n71xWvo31Yv4VMV1a77ugp9GaJ/qu1p/sX b/t9UfhHVpepxsllz3/G3y2c2140c73XUy4FrcQLn014In5ofbot+m/WnYyEuI3bBFfGveVd 577mv6rTNatmRUOmNsN5RxLqNNmZL3+0W+1vOF1J/GWuhPjVdZK/+oVfKrEUZyQaajEXFScC AOZtkGqiAgAA X-CFilter-Loop: Reflected X-Gm-Message-State: ALoCoQkQtzSeIwcGS7DeQwJBIiu8W5siAPfab0x2XWn7QsnuFSs2VDA1Qvi4LnnOc6LoND3OFKP9 This patch adds FDT support to the sound driver. Signed-off-by: Rajeshwari Shinde Acked-by: Simon Glass --- Changes in V2: - Made single function to get i2s values,codec init and sount init in both FDT and non FDT support case. Changes in V3: - Removed #ifdef CONFIG_OF_CONTROL where ever not required. drivers/sound/sound.c | 173 +++++++++++++++++++++++++++++-------------------- include/sound.h | 4 +- 2 files changed, 105 insertions(+), 72 deletions(-) diff --git a/drivers/sound/sound.c b/drivers/sound/sound.c index 4c74534..fa8432d 100644 --- a/drivers/sound/sound.c +++ b/drivers/sound/sound.c @@ -24,111 +24,159 @@ #include #include #include +#include +#include #include #include #include -#include "wm8994.h" #include +#include "wm8994.h" /* defines */ #define SOUND_400_HZ 400 #define SOUND_BITS_IN_BYTE 8 static struct i2stx_info g_i2stx_pri; -static struct sound_codec_info g_codec_info; /* - * get_sound_fdt_values gets fdt values for i2s parameters + * get_sound_i2s_values gets values for i2s parameters * * @param i2stx_info i2s transmitter transfer param structure - * @param blob FDT blob - */ -static void get_sound_i2s_values(struct i2stx_info *i2s) -{ - i2s->base_address = samsung_get_base_i2s(); - i2s->audio_pll_clk = I2S_PLL_CLK; - i2s->samplingrate = I2S_SAMPLING_RATE; - i2s->bitspersample = I2S_BITS_PER_SAMPLE; - i2s->channels = I2S_CHANNELS; - i2s->rfs = I2S_RFS; - i2s->bfs = I2S_BFS; -} - -/* - * Gets fdt values for wm8994 config parameters - * - * @param pcodec_info codec information structure - * @param blob FDT blob - * @return int value, 0 for success + * @param blob FDT blob if enabled else NULL */ -static int get_sound_wm8994_values(struct sound_codec_info *pcodec_info) +static int get_sound_i2s_values(struct i2stx_info *i2s, const void *blob) { +#ifdef CONFIG_OF_CONTROL + int node; int error = 0; + int base; - switch (AUDIO_COMPAT) { - case AUDIO_COMPAT_SPI: - debug("%s: Support not added for SPI interface\n", __func__); + 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; - break; - case AUDIO_COMPAT_I2C: - pcodec_info->i2c_bus = AUDIO_I2C_BUS; - pcodec_info->i2c_dev_addr = AUDIO_I2C_REG; - debug("i2c dev addr = %d\n", pcodec_info->i2c_dev_addr); - break; - default: - debug("%s: Unknown compat id %d\n", __func__, AUDIO_COMPAT); + } + + /* + * 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 wm8994 codec node properties\n"); + debug("fail to get sound i2s node properties\n"); return -1; } - +#else + i2s->base_address = samsung_get_base_i2s(); + i2s->audio_pll_clk = I2S_PLL_CLK; + i2s->samplingrate = I2S_SAMPLING_RATE; + i2s->bitspersample = I2S_BITS_PER_SAMPLE; + i2s->channels = I2S_CHANNELS; + i2s->rfs = I2S_RFS; + i2s->bfs = I2S_BFS; +#endif return 0; } /* - * Gets fdt values for codec config parameters + * Init codec * - * @param pcodec_info codec information structure - * @param blob FDT blob - * @return int value, 0 for success + * @param blob FDT blob + * @param pi2s_tx i2s parameters required by codec + * @return int value, 0 for success */ -static int get_sound_codec_values(struct sound_codec_info *pcodec_info) +static int codec_init(const void *blob, struct i2stx_info *pi2s_tx) { - int error = 0; + int ret; const char *codectype; +#ifdef CONFIG_OF_CONTROL + int node; - codectype = AUDIO_CODEC; + /* 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); +#else + codectype = AUDIO_CODEC; +#endif if (!strcmp(codectype, "wm8994")) { - pcodec_info->codec_type = CODEC_WM_8994; - error = get_sound_wm8994_values(pcodec_info); + /* Check the codec type and initialise the same */ + ret = wm8994_init(blob, WM8994_AIF2, + pi2s_tx->samplingrate, + (pi2s_tx->samplingrate * (pi2s_tx->rfs)), + pi2s_tx->bitspersample, pi2s_tx->channels); } else { - error = -1; + debug("%s: Unknown code type %s\n", __func__, + codectype); + return -1; } - - if (error == -1) { - debug("fail to get sound codec node properties\n"); + if (ret) { + debug("%s: Codec init failed\n", __func__); return -1; } return 0; } -int sound_init(void) +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 */ - get_sound_i2s_values(pi2s_tx); + if (get_sound_i2s_values(pi2s_tx, blob) < 0) { + debug(" FDT I2S values failed\n"); + return -1; + } - /* Get the codec Values */ - if (get_sound_codec_values(pcodec_info) < 0) + if (codec_init(blob, pi2s_tx) < 0) { + debug(" Codec init failed\n"); return -1; + } ret = i2s_tx_init(pi2s_tx); if (ret) { @@ -137,21 +185,6 @@ int sound_init(void) 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; } diff --git a/include/sound.h b/include/sound.h index ea0b115..d73839d 100644 --- a/include/sound.h +++ b/include/sound.h @@ -46,10 +46,10 @@ struct sound_codec_info { /* * Initialises audio sub system - * + * @param blob Pointer of device tree node or NULL if none. * @return int value 0 for success, -1 for error */ -int sound_init(void); +int sound_init(const void *blob); /* * plays the pcm data buffer in pcm_data.h through i2s1 to make the