Lines Matching +full:i2s +full:- +full:regs
1 // SPDX-License-Identifier: GPL-2.0+
9 #include <i2s.h>
13 #include <asm/arch/i2s-regs.h>
22 #define TIMEOUT_I2S_TX 100 /* i2s transfer timeout */
25 * Sets the frame size for I2S LR clock
27 * @param i2s_reg i2s register address
32 unsigned int mod = readl(&i2s_reg->mod); in i2s_set_lr_framesize()
51 writel(mod, &i2s_reg->mod); in i2s_set_lr_framesize()
55 * Sets the i2s transfer control
57 * @param i2s_reg i2s register address
62 unsigned int con = readl(&i2s_reg->con); in i2s_txctrl()
63 unsigned int mod = readl(&i2s_reg->mod) & ~MOD_MASK; in i2s_txctrl()
73 writel(mod, &i2s_reg->mod); in i2s_txctrl()
74 writel(con, &i2s_reg->con); in i2s_txctrl()
80 * @param i2s_reg i2s register address
85 unsigned int mod = readl(&i2s_reg->mod); in i2s_set_bitclk_framesize()
105 writel(mod, &i2s_reg->mod); in i2s_set_bitclk_framesize()
111 * @param i2s_reg i2s register address
112 * @param flush Tx fifo flush command (0x00 - do not flush
113 * 0x80 - flush tx fifo)
118 setbits_le32(&i2s_reg->fic, flush); in i2s_fifo()
119 clrbits_le32(&i2s_reg->fic, flush); in i2s_fifo()
125 * @param i2s_reg i2s register address
128 * @return int value 0 for success, -1 in case of error
132 unsigned int mod = readl(&i2s_reg->mod); in i2s_set_sysclk_dir()
139 writel(mod, &i2s_reg->mod); in i2s_set_sysclk_dir()
145 * Sets I2S Clcok format
147 * @param fmt i2s clock properties
148 * @param i2s_reg i2s register address
150 * @return int value 0 for success, -1 in case of error
154 unsigned int mod = readl(&i2s_reg->mod); in i2s_set_fmt()
174 return -ERANGE; in i2s_set_fmt()
178 * INV flag is relative to the FORMAT flag - if set it simply in i2s_set_fmt()
193 return -ERANGE; in i2s_set_fmt()
204 debug("%s:set i2s clock direction failed\n", __func__); in i2s_set_fmt()
211 return -ERANGE; in i2s_set_fmt()
216 writel(mod, &i2s_reg->mod); in i2s_set_fmt()
225 * @param i2s_reg i2s register address
227 * @return int value 0 for success, -1 in case of error
231 unsigned int mod = readl(&i2s_reg->mod); in i2s_set_samplesize()
252 return -ERANGE; in i2s_set_samplesize()
254 writel(mod, &i2s_reg->mod); in i2s_set_samplesize()
262 struct i2s_reg *i2s_reg = (struct i2s_reg *)pi2s_tx->base_address; in i2s_transfer_tx_data()
269 return -ENODATA; /* invalid pcm data size */ in i2s_transfer_tx_data()
274 writel(*ptr++, &i2s_reg->txd); in i2s_transfer_tx_data()
276 data_size -= sizeof(*ptr) * FIFO_LENGTH; in i2s_transfer_tx_data()
281 if (!(CON_TXFIFO_FULL & (readl(&i2s_reg->con)))) { in i2s_transfer_tx_data()
282 writel(*ptr++, &i2s_reg->txd); in i2s_transfer_tx_data()
283 data_size -= sizeof(*ptr); in i2s_transfer_tx_data()
287 debug("%s: I2S Transfer Timeout\n", __func__); in i2s_transfer_tx_data()
288 return -ETIMEDOUT; in i2s_transfer_tx_data()
300 struct i2s_reg *i2s_reg = (struct i2s_reg *)pi2s_tx->base_address; in i2s_tx_init()
302 if (pi2s_tx->id == 0) { in i2s_tx_init()
303 /* Initialize GPIO for I2S-0 */ in i2s_tx_init()
307 ret = set_epll_clk(pi2s_tx->samplingrate * pi2s_tx->rfs * 4); in i2s_tx_init()
308 } else if (pi2s_tx->id == 1) { in i2s_tx_init()
309 /* Initialize GPIO for I2S-1 */ in i2s_tx_init()
313 ret = set_epll_clk(pi2s_tx->audio_pll_clk); in i2s_tx_init()
315 debug("%s: unsupported i2s-%d bus\n", __func__, pi2s_tx->id); in i2s_tx_init()
316 return -ERANGE; in i2s_tx_init()
325 ret = set_i2s_clk_source(pi2s_tx->id); in i2s_tx_init()
327 debug("%s: unsupported clock for i2s-%d\n", __func__, in i2s_tx_init()
328 pi2s_tx->id); in i2s_tx_init()
332 if (pi2s_tx->id == 0) { in i2s_tx_init()
333 /*Reset the i2s module */ in i2s_tx_init()
334 writel(CON_RESET, &i2s_reg->con); in i2s_tx_init()
336 writel(MOD_OP_CLK | MOD_RCLKSRC, &i2s_reg->mod); in i2s_tx_init()
337 /* set i2s prescaler */ in i2s_tx_init()
338 writel(PSREN | PSVAL, &i2s_reg->psr); in i2s_tx_init()
341 ret = set_i2s_clk_prescaler(pi2s_tx->audio_pll_clk, in i2s_tx_init()
342 (pi2s_tx->samplingrate * (pi2s_tx->rfs)), in i2s_tx_init()
343 pi2s_tx->id); in i2s_tx_init()
346 debug("%s: unsupported prescalar for i2s-%d\n", __func__, in i2s_tx_init()
347 pi2s_tx->id); in i2s_tx_init()
351 /* Configure I2s format */ in i2s_tx_init()
355 i2s_set_lr_framesize(i2s_reg, pi2s_tx->rfs); in i2s_tx_init()
356 ret = i2s_set_samplesize(i2s_reg, pi2s_tx->bitspersample); in i2s_tx_init()
362 i2s_set_bitclk_framesize(i2s_reg, pi2s_tx->bfs); in i2s_tx_init()
363 /* disable i2s transfer flag and flush the fifo */ in i2s_tx_init()
393 * Get the pre-defined sound specific values from FDT. in samsung_i2s_ofdata_to_platdata()
395 * wrong register values in i2s setup parameters in samsung_i2s_ofdata_to_platdata()
400 debug("%s: Missing i2s base\n", __func__); in samsung_i2s_ofdata_to_platdata()
401 return -EINVAL; in samsung_i2s_ofdata_to_platdata()
403 priv->base_address = base; in samsung_i2s_ofdata_to_platdata()
405 if (dev_read_u32u(dev, "samsung,i2s-epll-clock-frequency", in samsung_i2s_ofdata_to_platdata()
406 &priv->audio_pll_clk)) in samsung_i2s_ofdata_to_platdata()
408 debug("audio_pll_clk = %d\n", priv->audio_pll_clk); in samsung_i2s_ofdata_to_platdata()
409 if (dev_read_u32u(dev, "samsung,i2s-sampling-rate", in samsung_i2s_ofdata_to_platdata()
410 &priv->samplingrate)) in samsung_i2s_ofdata_to_platdata()
412 debug("samplingrate = %d\n", priv->samplingrate); in samsung_i2s_ofdata_to_platdata()
413 if (dev_read_u32u(dev, "samsung,i2s-bits-per-sample", in samsung_i2s_ofdata_to_platdata()
414 &priv->bitspersample)) in samsung_i2s_ofdata_to_platdata()
416 debug("bitspersample = %d\n", priv->bitspersample); in samsung_i2s_ofdata_to_platdata()
417 if (dev_read_u32u(dev, "samsung,i2s-channels", &priv->channels)) in samsung_i2s_ofdata_to_platdata()
419 debug("channels = %d\n", priv->channels); in samsung_i2s_ofdata_to_platdata()
420 if (dev_read_u32u(dev, "samsung,i2s-lr-clk-framesize", &priv->rfs)) in samsung_i2s_ofdata_to_platdata()
422 debug("rfs = %d\n", priv->rfs); in samsung_i2s_ofdata_to_platdata()
423 if (dev_read_u32u(dev, "samsung,i2s-bit-clk-framesize", &priv->bfs)) in samsung_i2s_ofdata_to_platdata()
425 debug("bfs = %d\n", priv->bfs); in samsung_i2s_ofdata_to_platdata()
427 if (dev_read_u32u(dev, "samsung,i2s-id", &priv->id)) in samsung_i2s_ofdata_to_platdata()
429 debug("id = %d\n", priv->id); in samsung_i2s_ofdata_to_platdata()
434 debug("fail to get sound i2s node properties\n"); in samsung_i2s_ofdata_to_platdata()
436 return -EINVAL; in samsung_i2s_ofdata_to_platdata()
444 { .compatible = "samsung,s5pv210-i2s" },