dm: sound: samsung: Make local function static
[oweals/u-boot.git] / drivers / sound / samsung-i2s.c
index 9f3117dd942012ae630c09ef57befb1af6212475..8f5cd191a2b6c3989d5f69dfd8766a2e4cd954f6 100644 (file)
@@ -1,24 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) 2012 Samsung Electronics
  * R. Chandrasekar <rcsekar@samsung.com>
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
  */
 
 #include <asm/arch/clk.h>
@@ -81,9 +64,7 @@ static void i2s_txctrl(struct i2s_reg *i2s_reg, int on)
        if (on) {
                con |= CON_ACTIVE;
                con &= ~CON_TXCH_PAUSE;
-
        } else {
-
                con |=  CON_TXCH_PAUSE;
                con &= ~CON_ACTIVE;
        }
@@ -130,7 +111,7 @@ static void i2s_set_bitclk_framesize(struct i2s_reg *i2s_reg, unsigned bfs)
  * @param flush                Tx fifo flush command (0x00 - do not flush
  *                             0x80 - flush tx fifo)
  */
-void i2s_fifo(struct i2s_reg *i2s_reg, unsigned int flush)
+static void i2s_fifo(struct i2s_reg *i2s_reg, unsigned int flush)
 {
        /* Flush the FIFO */
        setbits_le32(&i2s_reg->fic, flush);
@@ -145,7 +126,7 @@ void i2s_fifo(struct i2s_reg *i2s_reg, unsigned int flush)
  *
  * @return             int value 0 for success, -1 in case of error
  */
-int i2s_set_sysclk_dir(struct i2s_reg *i2s_reg, int dir)
+static int i2s_set_sysclk_dir(struct i2s_reg *i2s_reg, int dir)
 {
        unsigned int mod = readl(&i2s_reg->mod);
 
@@ -167,7 +148,7 @@ int i2s_set_sysclk_dir(struct i2s_reg *i2s_reg, int dir)
  *
  * @return             int value 0 for success, -1 in case of error
  */
-int i2s_set_fmt(struct i2s_reg *i2s_reg, unsigned int fmt)
+static int i2s_set_fmt(struct i2s_reg *i2s_reg, unsigned int fmt)
 {
        unsigned int mod = readl(&i2s_reg->mod);
        unsigned int tmp = 0;
@@ -188,7 +169,7 @@ int i2s_set_fmt(struct i2s_reg *i2s_reg, unsigned int fmt)
                break;
        default:
                debug("%s: Invalid format priority [0x%x]\n", __func__,
-                       (fmt & SND_SOC_DAIFMT_FORMAT_MASK));
+                     (fmt & SND_SOC_DAIFMT_FORMAT_MASK));
                return -1;
        }
 
@@ -207,7 +188,7 @@ int i2s_set_fmt(struct i2s_reg *i2s_reg, unsigned int fmt)
                break;
        default:
                debug("%s: Invalid clock ploarity input [0x%x]\n", __func__,
-                       (fmt & SND_SOC_DAIFMT_INV_MASK));
+                     (fmt & SND_SOC_DAIFMT_INV_MASK));
                return -1;
        }
 
@@ -225,7 +206,7 @@ int i2s_set_fmt(struct i2s_reg *i2s_reg, unsigned int fmt)
                break;
        default:
                debug("%s: Invalid master selection [0x%x]\n", __func__,
-                       (fmt & SND_SOC_DAIFMT_MASTER_MASK));
+                     (fmt & SND_SOC_DAIFMT_MASTER_MASK));
                return -1;
        }
 
@@ -244,7 +225,7 @@ int i2s_set_fmt(struct i2s_reg *i2s_reg, unsigned int fmt)
  *
  * @return             int value 0 for success, -1 in case of error
  */
-int i2s_set_samplesize(struct i2s_reg *i2s_reg, unsigned int blc)
+static int i2s_set_samplesize(struct i2s_reg *i2s_reg, unsigned int blc)
 {
        unsigned int mod = readl(&i2s_reg->mod);
 
@@ -266,7 +247,7 @@ int i2s_set_samplesize(struct i2s_reg *i2s_reg, unsigned int blc)
                break;
        default:
                debug("%s: Invalid sample size input [0x%x]\n",
-                       __func__, blc);
+                     __func__, blc);
                return -1;
        }
        writel(mod, &i2s_reg->mod);
@@ -317,27 +298,58 @@ int i2s_tx_init(struct i2stx_info *pi2s_tx)
        int ret;
        struct i2s_reg *i2s_reg =
                                (struct i2s_reg *)pi2s_tx->base_address;
+       if (pi2s_tx->id == 0) {
+               /* Initialize GPIO for I2S-0 */
+               exynos_pinmux_config(PERIPH_ID_I2S0, 0);
+
+               /* Set EPLL Clock */
+               ret = set_epll_clk(pi2s_tx->samplingrate * pi2s_tx->rfs * 4);
+       } else if (pi2s_tx->id == 1) {
+               /* Initialize GPIO for I2S-1 */
+               exynos_pinmux_config(PERIPH_ID_I2S1, 0);
+
+               /* Set EPLL Clock */
+               ret = set_epll_clk(pi2s_tx->audio_pll_clk);
+       } else {
+               debug("%s: unsupported i2s-%d bus\n", __func__, pi2s_tx->id);
+               return -1;
+       }
 
-       /* Initialize GPIO for I2s */
-       exynos_pinmux_config(PERIPH_ID_I2S1, 0);
-
-       /* Set EPLL Clock */
-       ret = set_epll_clk(pi2s_tx->audio_pll_clk);
        if (ret != 0) {
-               debug("%s: epll clock set rate falied\n", __func__);
+               debug("%s: epll clock set rate failed\n", __func__);
+               return -1;
+       }
+
+       /* Select Clk Source for Audio 0 or 1 */
+       ret = set_i2s_clk_source(pi2s_tx->id);
+       if (ret == -1) {
+               debug("%s: unsupported clock for i2s-%d\n", __func__,
+                     pi2s_tx->id);
                return -1;
        }
 
-       /* Select Clk Source for Audio1 */
-       set_i2s_clk_source();
+       if (pi2s_tx->id == 0) {
+               /*Reset the i2s module */
+               writel(CON_RESET, &i2s_reg->con);
 
-       /* Set Prescaler to get MCLK */
-       set_i2s_clk_prescaler(pi2s_tx->audio_pll_clk,
-                               (pi2s_tx->samplingrate * (pi2s_tx->rfs)));
+               writel(MOD_OP_CLK | MOD_RCLKSRC, &i2s_reg->mod);
+               /* set i2s prescaler */
+               writel(PSREN | PSVAL, &i2s_reg->psr);
+       } else {
+               /* Set Prescaler to get MCLK */
+               ret = set_i2s_clk_prescaler(pi2s_tx->audio_pll_clk,
+                               (pi2s_tx->samplingrate * (pi2s_tx->rfs)),
+                               pi2s_tx->id);
+       }
+       if (ret == -1) {
+               debug("%s: unsupported prescalar for i2s-%d\n", __func__,
+                     pi2s_tx->id);
+               return -1;
+       }
 
        /* Configure I2s format */
        ret = i2s_set_fmt(i2s_reg, (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
-                               SND_SOC_DAIFMT_CBM_CFM));
+                         SND_SOC_DAIFMT_CBM_CFM));
        if (ret == 0) {
                i2s_set_lr_framesize(i2s_reg, pi2s_tx->rfs);
                ret = i2s_set_samplesize(i2s_reg, pi2s_tx->bitspersample);