xref: /linux/sound/soc/samsung/i2s.c (revision eb8ca0fa5d724976c8832ea5aea09f14fa83d437)
15033f43cSJassi Brar /* sound/soc/samsung/i2s.c
25033f43cSJassi Brar  *
35033f43cSJassi Brar  * ALSA SoC Audio Layer - Samsung I2S Controller driver
45033f43cSJassi Brar  *
55033f43cSJassi Brar  * Copyright (c) 2010 Samsung Electronics Co. Ltd.
6df8ad335SJaswinder Singh  *	Jaswinder Singh <jassisinghbrar@gmail.com>
75033f43cSJassi Brar  *
85033f43cSJassi Brar  * This program is free software; you can redistribute it and/or modify
95033f43cSJassi Brar  * it under the terms of the GNU General Public License version 2 as
105033f43cSJassi Brar  * published by the Free Software Foundation.
115033f43cSJassi Brar  */
125033f43cSJassi Brar 
13074b89bbSSylwester Nawrocki #include <dt-bindings/sound/samsung-i2s.h>
145033f43cSJassi Brar #include <linux/delay.h>
155033f43cSJassi Brar #include <linux/slab.h>
165033f43cSJassi Brar #include <linux/clk.h>
17074b89bbSSylwester Nawrocki #include <linux/clk-provider.h>
185033f43cSJassi Brar #include <linux/io.h>
19da155d5bSPaul Gortmaker #include <linux/module.h>
2040476f61SPadmavathi Venna #include <linux/of.h>
2140476f61SPadmavathi Venna #include <linux/of_gpio.h>
22c5cf4dbcSMark Brown #include <linux/pm_runtime.h>
235033f43cSJassi Brar 
245033f43cSJassi Brar #include <sound/soc.h>
250378b6acSSeungwhan Youn #include <sound/pcm_params.h>
265033f43cSJassi Brar 
27436d42c6SArnd Bergmann #include <linux/platform_data/asoc-s3c.h>
285033f43cSJassi Brar 
295033f43cSJassi Brar #include "dma.h"
3061100f40SSangbeom Kim #include "idma.h"
315033f43cSJassi Brar #include "i2s.h"
32172a453dSSangbeom Kim #include "i2s-regs.h"
335033f43cSJassi Brar 
345033f43cSJassi Brar #define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t)
355033f43cSJassi Brar 
367c62eebbSPadmavathi Venna enum samsung_dai_type {
377c62eebbSPadmavathi Venna 	TYPE_PRI,
387c62eebbSPadmavathi Venna 	TYPE_SEC,
397c62eebbSPadmavathi Venna };
407c62eebbSPadmavathi Venna 
41a5a56871SPadmavathi Venna struct samsung_i2s_variant_regs {
42a5a56871SPadmavathi Venna 	unsigned int	bfs_off;
43a5a56871SPadmavathi Venna 	unsigned int	rfs_off;
44a5a56871SPadmavathi Venna 	unsigned int	sdf_off;
45a5a56871SPadmavathi Venna 	unsigned int	txr_off;
46a5a56871SPadmavathi Venna 	unsigned int	rclksrc_off;
47a5a56871SPadmavathi Venna 	unsigned int	mss_off;
48a5a56871SPadmavathi Venna 	unsigned int	cdclkcon_off;
49a5a56871SPadmavathi Venna 	unsigned int	lrp_off;
50a5a56871SPadmavathi Venna 	unsigned int	bfs_mask;
51a5a56871SPadmavathi Venna 	unsigned int	rfs_mask;
52a5a56871SPadmavathi Venna 	unsigned int	ftx0cnt_off;
53a5a56871SPadmavathi Venna };
54a5a56871SPadmavathi Venna 
5540476f61SPadmavathi Venna struct samsung_i2s_dai_data {
5640476f61SPadmavathi Venna 	int dai_type;
577da493e9SPadmavathi Venna 	u32 quirks;
58a5a56871SPadmavathi Venna 	const struct samsung_i2s_variant_regs *i2s_variant_regs;
5940476f61SPadmavathi Venna };
6040476f61SPadmavathi Venna 
615033f43cSJassi Brar struct i2s_dai {
625033f43cSJassi Brar 	/* Platform device for this DAI */
635033f43cSJassi Brar 	struct platform_device *pdev;
64af1cf5cfSSylwester Nawrocki 	/* Memory mapped SFR region */
655033f43cSJassi Brar 	void __iomem	*addr;
665033f43cSJassi Brar 	/* Rate of RCLK source clock */
675033f43cSJassi Brar 	unsigned long rclk_srcrate;
685033f43cSJassi Brar 	/* Frame Clock */
695033f43cSJassi Brar 	unsigned frmclk;
705033f43cSJassi Brar 	/*
715033f43cSJassi Brar 	 * Specifically requested RCLK,BCLK by MACHINE Driver.
725033f43cSJassi Brar 	 * 0 indicates CPU driver is free to choose any value.
735033f43cSJassi Brar 	 */
745033f43cSJassi Brar 	unsigned rfs, bfs;
755033f43cSJassi Brar 	/* I2S Controller's core clock */
765033f43cSJassi Brar 	struct clk *clk;
775033f43cSJassi Brar 	/* Clock for generating I2S signals */
785033f43cSJassi Brar 	struct clk *op_clk;
795033f43cSJassi Brar 	/* Pointer to the Primary_Fifo if this is Sec_Fifo, NULL otherwise */
805033f43cSJassi Brar 	struct i2s_dai *pri_dai;
815033f43cSJassi Brar 	/* Pointer to the Secondary_Fifo if it has one, NULL otherwise */
825033f43cSJassi Brar 	struct i2s_dai *sec_dai;
835033f43cSJassi Brar #define DAI_OPENED	(1 << 0) /* Dai is opened */
845033f43cSJassi Brar #define DAI_MANAGER	(1 << 1) /* Dai is the manager */
855033f43cSJassi Brar 	unsigned mode;
865033f43cSJassi Brar 	/* Driver for this DAI */
875033f43cSJassi Brar 	struct snd_soc_dai_driver i2s_dai_drv;
885033f43cSJassi Brar 	/* DMA parameters */
895033f43cSJassi Brar 	struct s3c_dma_params dma_playback;
905033f43cSJassi Brar 	struct s3c_dma_params dma_capture;
9161100f40SSangbeom Kim 	struct s3c_dma_params idma_playback;
925033f43cSJassi Brar 	u32	quirks;
935033f43cSJassi Brar 	u32	suspend_i2smod;
945033f43cSJassi Brar 	u32	suspend_i2scon;
955033f43cSJassi Brar 	u32	suspend_i2spsr;
96a5a56871SPadmavathi Venna 	const struct samsung_i2s_variant_regs *variant_regs;
97f3670536SSylwester Nawrocki 
98f3670536SSylwester Nawrocki 	/* Spinlock protecting access to the device's registers */
99f3670536SSylwester Nawrocki 	spinlock_t spinlock;
100f3670536SSylwester Nawrocki 	spinlock_t *lock;
101074b89bbSSylwester Nawrocki 
102074b89bbSSylwester Nawrocki 	/* Below fields are only valid if this is the primary FIFO */
103074b89bbSSylwester Nawrocki 	struct clk *clk_table[3];
104074b89bbSSylwester Nawrocki 	struct clk_onecell_data clk_data;
1055033f43cSJassi Brar };
1065033f43cSJassi Brar 
1075033f43cSJassi Brar /* Lock for cross i/f checks */
1085033f43cSJassi Brar static DEFINE_SPINLOCK(lock);
1095033f43cSJassi Brar 
1105033f43cSJassi Brar /* If this is the 'overlay' stereo DAI */
1115033f43cSJassi Brar static inline bool is_secondary(struct i2s_dai *i2s)
1125033f43cSJassi Brar {
1135033f43cSJassi Brar 	return i2s->pri_dai ? true : false;
1145033f43cSJassi Brar }
1155033f43cSJassi Brar 
1165033f43cSJassi Brar /* If operating in SoC-Slave mode */
1175033f43cSJassi Brar static inline bool is_slave(struct i2s_dai *i2s)
1185033f43cSJassi Brar {
119a5a56871SPadmavathi Venna 	u32 mod = readl(i2s->addr + I2SMOD);
120a5a56871SPadmavathi Venna 	return (mod & (1 << i2s->variant_regs->mss_off)) ? true : false;
1215033f43cSJassi Brar }
1225033f43cSJassi Brar 
1235033f43cSJassi Brar /* If this interface of the controller is transmitting data */
1245033f43cSJassi Brar static inline bool tx_active(struct i2s_dai *i2s)
1255033f43cSJassi Brar {
1265033f43cSJassi Brar 	u32 active;
1275033f43cSJassi Brar 
1285033f43cSJassi Brar 	if (!i2s)
1295033f43cSJassi Brar 		return false;
1305033f43cSJassi Brar 
13133195500SSangbeom Kim 	active = readl(i2s->addr + I2SCON);
1325033f43cSJassi Brar 
1335033f43cSJassi Brar 	if (is_secondary(i2s))
1345033f43cSJassi Brar 		active &= CON_TXSDMA_ACTIVE;
1355033f43cSJassi Brar 	else
1365033f43cSJassi Brar 		active &= CON_TXDMA_ACTIVE;
1375033f43cSJassi Brar 
1385033f43cSJassi Brar 	return active ? true : false;
1395033f43cSJassi Brar }
1405033f43cSJassi Brar 
141dcd60fc3SSylwester Nawrocki /* Return pointer to the other DAI */
142dcd60fc3SSylwester Nawrocki static inline struct i2s_dai *get_other_dai(struct i2s_dai *i2s)
143dcd60fc3SSylwester Nawrocki {
144dcd60fc3SSylwester Nawrocki 	return i2s->pri_dai ? : i2s->sec_dai;
145dcd60fc3SSylwester Nawrocki }
146dcd60fc3SSylwester Nawrocki 
1475033f43cSJassi Brar /* If the other interface of the controller is transmitting data */
1485033f43cSJassi Brar static inline bool other_tx_active(struct i2s_dai *i2s)
1495033f43cSJassi Brar {
150dcd60fc3SSylwester Nawrocki 	struct i2s_dai *other = get_other_dai(i2s);
1515033f43cSJassi Brar 
1525033f43cSJassi Brar 	return tx_active(other);
1535033f43cSJassi Brar }
1545033f43cSJassi Brar 
1555033f43cSJassi Brar /* If any interface of the controller is transmitting data */
1565033f43cSJassi Brar static inline bool any_tx_active(struct i2s_dai *i2s)
1575033f43cSJassi Brar {
1585033f43cSJassi Brar 	return tx_active(i2s) || other_tx_active(i2s);
1595033f43cSJassi Brar }
1605033f43cSJassi Brar 
1615033f43cSJassi Brar /* If this interface of the controller is receiving data */
1625033f43cSJassi Brar static inline bool rx_active(struct i2s_dai *i2s)
1635033f43cSJassi Brar {
1645033f43cSJassi Brar 	u32 active;
1655033f43cSJassi Brar 
1665033f43cSJassi Brar 	if (!i2s)
1675033f43cSJassi Brar 		return false;
1685033f43cSJassi Brar 
16933195500SSangbeom Kim 	active = readl(i2s->addr + I2SCON) & CON_RXDMA_ACTIVE;
1705033f43cSJassi Brar 
1715033f43cSJassi Brar 	return active ? true : false;
1725033f43cSJassi Brar }
1735033f43cSJassi Brar 
1745033f43cSJassi Brar /* If the other interface of the controller is receiving data */
1755033f43cSJassi Brar static inline bool other_rx_active(struct i2s_dai *i2s)
1765033f43cSJassi Brar {
177dcd60fc3SSylwester Nawrocki 	struct i2s_dai *other = get_other_dai(i2s);
1785033f43cSJassi Brar 
1795033f43cSJassi Brar 	return rx_active(other);
1805033f43cSJassi Brar }
1815033f43cSJassi Brar 
1825033f43cSJassi Brar /* If any interface of the controller is receiving data */
1835033f43cSJassi Brar static inline bool any_rx_active(struct i2s_dai *i2s)
1845033f43cSJassi Brar {
1855033f43cSJassi Brar 	return rx_active(i2s) || other_rx_active(i2s);
1865033f43cSJassi Brar }
1875033f43cSJassi Brar 
1885033f43cSJassi Brar /* If the other DAI is transmitting or receiving data */
1895033f43cSJassi Brar static inline bool other_active(struct i2s_dai *i2s)
1905033f43cSJassi Brar {
1915033f43cSJassi Brar 	return other_rx_active(i2s) || other_tx_active(i2s);
1925033f43cSJassi Brar }
1935033f43cSJassi Brar 
1945033f43cSJassi Brar /* If this DAI is transmitting or receiving data */
1955033f43cSJassi Brar static inline bool this_active(struct i2s_dai *i2s)
1965033f43cSJassi Brar {
1975033f43cSJassi Brar 	return tx_active(i2s) || rx_active(i2s);
1985033f43cSJassi Brar }
1995033f43cSJassi Brar 
2005033f43cSJassi Brar /* If the controller is active anyway */
2015033f43cSJassi Brar static inline bool any_active(struct i2s_dai *i2s)
2025033f43cSJassi Brar {
2035033f43cSJassi Brar 	return this_active(i2s) || other_active(i2s);
2045033f43cSJassi Brar }
2055033f43cSJassi Brar 
2065033f43cSJassi Brar static inline struct i2s_dai *to_info(struct snd_soc_dai *dai)
2075033f43cSJassi Brar {
2085033f43cSJassi Brar 	return snd_soc_dai_get_drvdata(dai);
2095033f43cSJassi Brar }
2105033f43cSJassi Brar 
2115033f43cSJassi Brar static inline bool is_opened(struct i2s_dai *i2s)
2125033f43cSJassi Brar {
2135033f43cSJassi Brar 	if (i2s && (i2s->mode & DAI_OPENED))
2145033f43cSJassi Brar 		return true;
2155033f43cSJassi Brar 	else
2165033f43cSJassi Brar 		return false;
2175033f43cSJassi Brar }
2185033f43cSJassi Brar 
2195033f43cSJassi Brar static inline bool is_manager(struct i2s_dai *i2s)
2205033f43cSJassi Brar {
2215033f43cSJassi Brar 	if (is_opened(i2s) && (i2s->mode & DAI_MANAGER))
2225033f43cSJassi Brar 		return true;
2235033f43cSJassi Brar 	else
2245033f43cSJassi Brar 		return false;
2255033f43cSJassi Brar }
2265033f43cSJassi Brar 
2275033f43cSJassi Brar /* Read RCLK of I2S (in multiples of LRCLK) */
2285033f43cSJassi Brar static inline unsigned get_rfs(struct i2s_dai *i2s)
2295033f43cSJassi Brar {
2304ca0c0d4SPadmavathi Venna 	u32 rfs;
231a5a56871SPadmavathi Venna 	rfs = readl(i2s->addr + I2SMOD) >> i2s->variant_regs->rfs_off;
232a5a56871SPadmavathi Venna 	rfs &= i2s->variant_regs->rfs_mask;
2335033f43cSJassi Brar 
2345033f43cSJassi Brar 	switch (rfs) {
235a5a56871SPadmavathi Venna 	case 7: return 192;
236a5a56871SPadmavathi Venna 	case 6: return 96;
237a5a56871SPadmavathi Venna 	case 5: return 128;
238a5a56871SPadmavathi Venna 	case 4: return 64;
2395033f43cSJassi Brar 	case 3:	return 768;
2405033f43cSJassi Brar 	case 2: return 384;
2415033f43cSJassi Brar 	case 1:	return 512;
2425033f43cSJassi Brar 	default: return 256;
2435033f43cSJassi Brar 	}
2445033f43cSJassi Brar }
2455033f43cSJassi Brar 
2465033f43cSJassi Brar /* Write RCLK of I2S (in multiples of LRCLK) */
2475033f43cSJassi Brar static inline void set_rfs(struct i2s_dai *i2s, unsigned rfs)
2485033f43cSJassi Brar {
2495033f43cSJassi Brar 	u32 mod = readl(i2s->addr + I2SMOD);
250a5a56871SPadmavathi Venna 	int rfs_shift = i2s->variant_regs->rfs_off;
2515033f43cSJassi Brar 
252a5a56871SPadmavathi Venna 	mod &= ~(i2s->variant_regs->rfs_mask << rfs_shift);
2535033f43cSJassi Brar 
2545033f43cSJassi Brar 	switch (rfs) {
255a5a56871SPadmavathi Venna 	case 192:
256a5a56871SPadmavathi Venna 		mod |= (EXYNOS7_MOD_RCLK_192FS << rfs_shift);
257a5a56871SPadmavathi Venna 		break;
258a5a56871SPadmavathi Venna 	case 96:
259a5a56871SPadmavathi Venna 		mod |= (EXYNOS7_MOD_RCLK_96FS << rfs_shift);
260a5a56871SPadmavathi Venna 		break;
261a5a56871SPadmavathi Venna 	case 128:
262a5a56871SPadmavathi Venna 		mod |= (EXYNOS7_MOD_RCLK_128FS << rfs_shift);
263a5a56871SPadmavathi Venna 		break;
264a5a56871SPadmavathi Venna 	case 64:
265a5a56871SPadmavathi Venna 		mod |= (EXYNOS7_MOD_RCLK_64FS << rfs_shift);
266a5a56871SPadmavathi Venna 		break;
2675033f43cSJassi Brar 	case 768:
268b60be4aaSPadmavathi Venna 		mod |= (MOD_RCLK_768FS << rfs_shift);
2695033f43cSJassi Brar 		break;
2705033f43cSJassi Brar 	case 512:
271b60be4aaSPadmavathi Venna 		mod |= (MOD_RCLK_512FS << rfs_shift);
2725033f43cSJassi Brar 		break;
2735033f43cSJassi Brar 	case 384:
274b60be4aaSPadmavathi Venna 		mod |= (MOD_RCLK_384FS << rfs_shift);
2755033f43cSJassi Brar 		break;
2765033f43cSJassi Brar 	default:
277b60be4aaSPadmavathi Venna 		mod |= (MOD_RCLK_256FS << rfs_shift);
2785033f43cSJassi Brar 		break;
2795033f43cSJassi Brar 	}
2805033f43cSJassi Brar 
2815033f43cSJassi Brar 	writel(mod, i2s->addr + I2SMOD);
2825033f43cSJassi Brar }
2835033f43cSJassi Brar 
2845033f43cSJassi Brar /* Read Bit-Clock of I2S (in multiples of LRCLK) */
2855033f43cSJassi Brar static inline unsigned get_bfs(struct i2s_dai *i2s)
2865033f43cSJassi Brar {
2874ca0c0d4SPadmavathi Venna 	u32 bfs;
288a5a56871SPadmavathi Venna 	bfs = readl(i2s->addr + I2SMOD) >> i2s->variant_regs->bfs_off;
289a5a56871SPadmavathi Venna 	bfs &= i2s->variant_regs->bfs_mask;
2905033f43cSJassi Brar 
2915033f43cSJassi Brar 	switch (bfs) {
2924ca0c0d4SPadmavathi Venna 	case 8: return 256;
2934ca0c0d4SPadmavathi Venna 	case 7: return 192;
2944ca0c0d4SPadmavathi Venna 	case 6: return 128;
2954ca0c0d4SPadmavathi Venna 	case 5: return 96;
2964ca0c0d4SPadmavathi Venna 	case 4: return 64;
2975033f43cSJassi Brar 	case 3: return 24;
2985033f43cSJassi Brar 	case 2: return 16;
2995033f43cSJassi Brar 	case 1:	return 48;
3005033f43cSJassi Brar 	default: return 32;
3015033f43cSJassi Brar 	}
3025033f43cSJassi Brar }
3035033f43cSJassi Brar 
3045033f43cSJassi Brar /* Write Bit-Clock of I2S (in multiples of LRCLK) */
3055033f43cSJassi Brar static inline void set_bfs(struct i2s_dai *i2s, unsigned bfs)
3065033f43cSJassi Brar {
3075033f43cSJassi Brar 	u32 mod = readl(i2s->addr + I2SMOD);
3084ca0c0d4SPadmavathi Venna 	int tdm = i2s->quirks & QUIRK_SUPPORTS_TDM;
309a5a56871SPadmavathi Venna 	int bfs_shift = i2s->variant_regs->bfs_off;
3104ca0c0d4SPadmavathi Venna 
3114ca0c0d4SPadmavathi Venna 	/* Non-TDM I2S controllers do not support BCLK > 48 * FS */
3124ca0c0d4SPadmavathi Venna 	if (!tdm && bfs > 48) {
3134ca0c0d4SPadmavathi Venna 		dev_err(&i2s->pdev->dev, "Unsupported BCLK divider\n");
3144ca0c0d4SPadmavathi Venna 		return;
3154ca0c0d4SPadmavathi Venna 	}
3165033f43cSJassi Brar 
317a5a56871SPadmavathi Venna 	mod &= ~(i2s->variant_regs->bfs_mask << bfs_shift);
318a5a56871SPadmavathi Venna 
3195033f43cSJassi Brar 	switch (bfs) {
3205033f43cSJassi Brar 	case 48:
321b60be4aaSPadmavathi Venna 		mod |= (MOD_BCLK_48FS << bfs_shift);
3225033f43cSJassi Brar 		break;
3235033f43cSJassi Brar 	case 32:
324b60be4aaSPadmavathi Venna 		mod |= (MOD_BCLK_32FS << bfs_shift);
3255033f43cSJassi Brar 		break;
3265033f43cSJassi Brar 	case 24:
327b60be4aaSPadmavathi Venna 		mod |= (MOD_BCLK_24FS << bfs_shift);
3285033f43cSJassi Brar 		break;
3295033f43cSJassi Brar 	case 16:
330b60be4aaSPadmavathi Venna 		mod |= (MOD_BCLK_16FS << bfs_shift);
3315033f43cSJassi Brar 		break;
3324ca0c0d4SPadmavathi Venna 	case 64:
3334ca0c0d4SPadmavathi Venna 		mod |= (EXYNOS5420_MOD_BCLK_64FS << bfs_shift);
3344ca0c0d4SPadmavathi Venna 		break;
3354ca0c0d4SPadmavathi Venna 	case 96:
3364ca0c0d4SPadmavathi Venna 		mod |= (EXYNOS5420_MOD_BCLK_96FS << bfs_shift);
3374ca0c0d4SPadmavathi Venna 		break;
3384ca0c0d4SPadmavathi Venna 	case 128:
3394ca0c0d4SPadmavathi Venna 		mod |= (EXYNOS5420_MOD_BCLK_128FS << bfs_shift);
3404ca0c0d4SPadmavathi Venna 		break;
3414ca0c0d4SPadmavathi Venna 	case 192:
3424ca0c0d4SPadmavathi Venna 		mod |= (EXYNOS5420_MOD_BCLK_192FS << bfs_shift);
3434ca0c0d4SPadmavathi Venna 		break;
3444ca0c0d4SPadmavathi Venna 	case 256:
3454ca0c0d4SPadmavathi Venna 		mod |= (EXYNOS5420_MOD_BCLK_256FS << bfs_shift);
3465033f43cSJassi Brar 		break;
3475033f43cSJassi Brar 	default:
3485033f43cSJassi Brar 		dev_err(&i2s->pdev->dev, "Wrong BCLK Divider!\n");
3495033f43cSJassi Brar 		return;
3505033f43cSJassi Brar 	}
3515033f43cSJassi Brar 
3525033f43cSJassi Brar 	writel(mod, i2s->addr + I2SMOD);
3535033f43cSJassi Brar }
3545033f43cSJassi Brar 
3555033f43cSJassi Brar /* Sample-Size */
3565033f43cSJassi Brar static inline int get_blc(struct i2s_dai *i2s)
3575033f43cSJassi Brar {
3585033f43cSJassi Brar 	int blc = readl(i2s->addr + I2SMOD);
3595033f43cSJassi Brar 
3605033f43cSJassi Brar 	blc = (blc >> 13) & 0x3;
3615033f43cSJassi Brar 
3625033f43cSJassi Brar 	switch (blc) {
3635033f43cSJassi Brar 	case 2: return 24;
3645033f43cSJassi Brar 	case 1:	return 8;
3655033f43cSJassi Brar 	default: return 16;
3665033f43cSJassi Brar 	}
3675033f43cSJassi Brar }
3685033f43cSJassi Brar 
3695033f43cSJassi Brar /* TX Channel Control */
3705033f43cSJassi Brar static void i2s_txctrl(struct i2s_dai *i2s, int on)
3715033f43cSJassi Brar {
3725033f43cSJassi Brar 	void __iomem *addr = i2s->addr;
373a5a56871SPadmavathi Venna 	int txr_off = i2s->variant_regs->txr_off;
3745033f43cSJassi Brar 	u32 con = readl(addr + I2SCON);
375a5a56871SPadmavathi Venna 	u32 mod = readl(addr + I2SMOD) & ~(3 << txr_off);
3765033f43cSJassi Brar 
3775033f43cSJassi Brar 	if (on) {
3785033f43cSJassi Brar 		con |= CON_ACTIVE;
3795033f43cSJassi Brar 		con &= ~CON_TXCH_PAUSE;
3805033f43cSJassi Brar 
3815033f43cSJassi Brar 		if (is_secondary(i2s)) {
3825033f43cSJassi Brar 			con |= CON_TXSDMA_ACTIVE;
3835033f43cSJassi Brar 			con &= ~CON_TXSDMA_PAUSE;
3845033f43cSJassi Brar 		} else {
3855033f43cSJassi Brar 			con |= CON_TXDMA_ACTIVE;
3865033f43cSJassi Brar 			con &= ~CON_TXDMA_PAUSE;
3875033f43cSJassi Brar 		}
3885033f43cSJassi Brar 
3895033f43cSJassi Brar 		if (any_rx_active(i2s))
390a5a56871SPadmavathi Venna 			mod |= 2 << txr_off;
3915033f43cSJassi Brar 		else
392a5a56871SPadmavathi Venna 			mod |= 0 << txr_off;
3935033f43cSJassi Brar 	} else {
3945033f43cSJassi Brar 		if (is_secondary(i2s)) {
3955033f43cSJassi Brar 			con |=  CON_TXSDMA_PAUSE;
3965033f43cSJassi Brar 			con &= ~CON_TXSDMA_ACTIVE;
3975033f43cSJassi Brar 		} else {
3985033f43cSJassi Brar 			con |=  CON_TXDMA_PAUSE;
3995033f43cSJassi Brar 			con &= ~CON_TXDMA_ACTIVE;
4005033f43cSJassi Brar 		}
4015033f43cSJassi Brar 
4025033f43cSJassi Brar 		if (other_tx_active(i2s)) {
4035033f43cSJassi Brar 			writel(con, addr + I2SCON);
4045033f43cSJassi Brar 			return;
4055033f43cSJassi Brar 		}
4065033f43cSJassi Brar 
4075033f43cSJassi Brar 		con |=  CON_TXCH_PAUSE;
4085033f43cSJassi Brar 
4095033f43cSJassi Brar 		if (any_rx_active(i2s))
410a5a56871SPadmavathi Venna 			mod |= 1 << txr_off;
4115033f43cSJassi Brar 		else
4125033f43cSJassi Brar 			con &= ~CON_ACTIVE;
4135033f43cSJassi Brar 	}
4145033f43cSJassi Brar 
4155033f43cSJassi Brar 	writel(mod, addr + I2SMOD);
4165033f43cSJassi Brar 	writel(con, addr + I2SCON);
4175033f43cSJassi Brar }
4185033f43cSJassi Brar 
4195033f43cSJassi Brar /* RX Channel Control */
4205033f43cSJassi Brar static void i2s_rxctrl(struct i2s_dai *i2s, int on)
4215033f43cSJassi Brar {
4225033f43cSJassi Brar 	void __iomem *addr = i2s->addr;
423a5a56871SPadmavathi Venna 	int txr_off = i2s->variant_regs->txr_off;
4245033f43cSJassi Brar 	u32 con = readl(addr + I2SCON);
425a5a56871SPadmavathi Venna 	u32 mod = readl(addr + I2SMOD) & ~(3 << txr_off);
4265033f43cSJassi Brar 
4275033f43cSJassi Brar 	if (on) {
4285033f43cSJassi Brar 		con |= CON_RXDMA_ACTIVE | CON_ACTIVE;
4295033f43cSJassi Brar 		con &= ~(CON_RXDMA_PAUSE | CON_RXCH_PAUSE);
4305033f43cSJassi Brar 
4315033f43cSJassi Brar 		if (any_tx_active(i2s))
432a5a56871SPadmavathi Venna 			mod |= 2 << txr_off;
4335033f43cSJassi Brar 		else
434a5a56871SPadmavathi Venna 			mod |= 1 << txr_off;
4355033f43cSJassi Brar 	} else {
4365033f43cSJassi Brar 		con |=  CON_RXDMA_PAUSE | CON_RXCH_PAUSE;
4375033f43cSJassi Brar 		con &= ~CON_RXDMA_ACTIVE;
4385033f43cSJassi Brar 
4395033f43cSJassi Brar 		if (any_tx_active(i2s))
440a5a56871SPadmavathi Venna 			mod |= 0 << txr_off;
4415033f43cSJassi Brar 		else
4425033f43cSJassi Brar 			con &= ~CON_ACTIVE;
4435033f43cSJassi Brar 	}
4445033f43cSJassi Brar 
4455033f43cSJassi Brar 	writel(mod, addr + I2SMOD);
4465033f43cSJassi Brar 	writel(con, addr + I2SCON);
4475033f43cSJassi Brar }
4485033f43cSJassi Brar 
4495033f43cSJassi Brar /* Flush FIFO of an interface */
4505033f43cSJassi Brar static inline void i2s_fifo(struct i2s_dai *i2s, u32 flush)
4515033f43cSJassi Brar {
4525033f43cSJassi Brar 	void __iomem *fic;
4535033f43cSJassi Brar 	u32 val;
4545033f43cSJassi Brar 
4555033f43cSJassi Brar 	if (!i2s)
4565033f43cSJassi Brar 		return;
4575033f43cSJassi Brar 
4585033f43cSJassi Brar 	if (is_secondary(i2s))
4595033f43cSJassi Brar 		fic = i2s->addr + I2SFICS;
4605033f43cSJassi Brar 	else
4615033f43cSJassi Brar 		fic = i2s->addr + I2SFIC;
4625033f43cSJassi Brar 
4635033f43cSJassi Brar 	/* Flush the FIFO */
4645033f43cSJassi Brar 	writel(readl(fic) | flush, fic);
4655033f43cSJassi Brar 
4665033f43cSJassi Brar 	/* Be patient */
4675033f43cSJassi Brar 	val = msecs_to_loops(1) / 1000; /* 1 usec */
4685033f43cSJassi Brar 	while (--val)
4695033f43cSJassi Brar 		cpu_relax();
4705033f43cSJassi Brar 
4715033f43cSJassi Brar 	writel(readl(fic) & ~flush, fic);
4725033f43cSJassi Brar }
4735033f43cSJassi Brar 
4745033f43cSJassi Brar static int i2s_set_sysclk(struct snd_soc_dai *dai,
4755033f43cSJassi Brar 	  int clk_id, unsigned int rfs, int dir)
4765033f43cSJassi Brar {
4775033f43cSJassi Brar 	struct i2s_dai *i2s = to_info(dai);
478dcd60fc3SSylwester Nawrocki 	struct i2s_dai *other = get_other_dai(i2s);
479a5a56871SPadmavathi Venna 	const struct samsung_i2s_variant_regs *i2s_regs = i2s->variant_regs;
480a5a56871SPadmavathi Venna 	unsigned int cdcon_mask = 1 << i2s_regs->cdclkcon_off;
481a5a56871SPadmavathi Venna 	unsigned int rsrc_mask = 1 << i2s_regs->rclksrc_off;
482ce8bcdbbSSylwester Nawrocki 	u32 mod, mask, val = 0;
483ce8bcdbbSSylwester Nawrocki 
484ce8bcdbbSSylwester Nawrocki 	spin_lock(i2s->lock);
485ce8bcdbbSSylwester Nawrocki 	mod = readl(i2s->addr + I2SMOD);
486ce8bcdbbSSylwester Nawrocki 	spin_unlock(i2s->lock);
4875033f43cSJassi Brar 
4885033f43cSJassi Brar 	switch (clk_id) {
489c86d50f9SSylwester Nawrocki 	case SAMSUNG_I2S_OPCLK:
490ce8bcdbbSSylwester Nawrocki 		mask = MOD_OPCLK_MASK;
491ce8bcdbbSSylwester Nawrocki 		val = dir;
492c86d50f9SSylwester Nawrocki 		break;
4935033f43cSJassi Brar 	case SAMSUNG_I2S_CDCLK:
494ce8bcdbbSSylwester Nawrocki 		mask = 1 << i2s_regs->cdclkcon_off;
4955033f43cSJassi Brar 		/* Shouldn't matter in GATING(CLOCK_IN) mode */
4965033f43cSJassi Brar 		if (dir == SND_SOC_CLOCK_IN)
4975033f43cSJassi Brar 			rfs = 0;
4985033f43cSJassi Brar 
499133c2681SCharles Keepax 		if ((rfs && other && other->rfs && (other->rfs != rfs)) ||
5005033f43cSJassi Brar 				(any_active(i2s) &&
5015033f43cSJassi Brar 				(((dir == SND_SOC_CLOCK_IN)
502a5a56871SPadmavathi Venna 					&& !(mod & cdcon_mask)) ||
5035033f43cSJassi Brar 				((dir == SND_SOC_CLOCK_OUT)
504a5a56871SPadmavathi Venna 					&& (mod & cdcon_mask))))) {
5055033f43cSJassi Brar 			dev_err(&i2s->pdev->dev,
5065033f43cSJassi Brar 				"%s:%d Other DAI busy\n", __func__, __LINE__);
5075033f43cSJassi Brar 			return -EAGAIN;
5085033f43cSJassi Brar 		}
5095033f43cSJassi Brar 
5105033f43cSJassi Brar 		if (dir == SND_SOC_CLOCK_IN)
511ce8bcdbbSSylwester Nawrocki 			val = 1 << i2s_regs->cdclkcon_off;
5125033f43cSJassi Brar 
5135033f43cSJassi Brar 		i2s->rfs = rfs;
5145033f43cSJassi Brar 		break;
5155033f43cSJassi Brar 
5165033f43cSJassi Brar 	case SAMSUNG_I2S_RCLKSRC_0: /* clock corrsponding to IISMOD[10] := 0 */
5175033f43cSJassi Brar 	case SAMSUNG_I2S_RCLKSRC_1: /* clock corrsponding to IISMOD[10] := 1 */
518ce8bcdbbSSylwester Nawrocki 		mask = 1 << i2s_regs->rclksrc_off;
519ce8bcdbbSSylwester Nawrocki 
5205033f43cSJassi Brar 		if ((i2s->quirks & QUIRK_NO_MUXPSR)
5215033f43cSJassi Brar 				|| (clk_id == SAMSUNG_I2S_RCLKSRC_0))
5225033f43cSJassi Brar 			clk_id = 0;
5235033f43cSJassi Brar 		else
5245033f43cSJassi Brar 			clk_id = 1;
5255033f43cSJassi Brar 
5265033f43cSJassi Brar 		if (!any_active(i2s)) {
527a6aba536SSylwester Nawrocki 			if (i2s->op_clk && !IS_ERR(i2s->op_clk)) {
528a5a56871SPadmavathi Venna 				if ((clk_id && !(mod & rsrc_mask)) ||
529a5a56871SPadmavathi Venna 					(!clk_id && (mod & rsrc_mask))) {
53098614cf6SThomas Abraham 					clk_disable_unprepare(i2s->op_clk);
5315033f43cSJassi Brar 					clk_put(i2s->op_clk);
5325033f43cSJassi Brar 				} else {
5336ce534aaSJassi Brar 					i2s->rclk_srcrate =
5346ce534aaSJassi Brar 						clk_get_rate(i2s->op_clk);
5355033f43cSJassi Brar 					return 0;
5365033f43cSJassi Brar 				}
5375033f43cSJassi Brar 			}
5385033f43cSJassi Brar 
5391974a042SPadmavathi Venna 			if (clk_id)
5405033f43cSJassi Brar 				i2s->op_clk = clk_get(&i2s->pdev->dev,
5411974a042SPadmavathi Venna 						"i2s_opclk1");
5421974a042SPadmavathi Venna 			else
5431974a042SPadmavathi Venna 				i2s->op_clk = clk_get(&i2s->pdev->dev,
5441974a042SPadmavathi Venna 						"i2s_opclk0");
545a6aba536SSylwester Nawrocki 
546a6aba536SSylwester Nawrocki 			if (WARN_ON(IS_ERR(i2s->op_clk)))
547a6aba536SSylwester Nawrocki 				return PTR_ERR(i2s->op_clk);
548a6aba536SSylwester Nawrocki 
54998614cf6SThomas Abraham 			clk_prepare_enable(i2s->op_clk);
5505033f43cSJassi Brar 			i2s->rclk_srcrate = clk_get_rate(i2s->op_clk);
5515033f43cSJassi Brar 
5525033f43cSJassi Brar 			/* Over-ride the other's */
5535033f43cSJassi Brar 			if (other) {
5545033f43cSJassi Brar 				other->op_clk = i2s->op_clk;
5555033f43cSJassi Brar 				other->rclk_srcrate = i2s->rclk_srcrate;
5565033f43cSJassi Brar 			}
557a5a56871SPadmavathi Venna 		} else if ((!clk_id && (mod & rsrc_mask))
558a5a56871SPadmavathi Venna 				|| (clk_id && !(mod & rsrc_mask))) {
5595033f43cSJassi Brar 			dev_err(&i2s->pdev->dev,
5605033f43cSJassi Brar 				"%s:%d Other DAI busy\n", __func__, __LINE__);
5615033f43cSJassi Brar 			return -EAGAIN;
5625033f43cSJassi Brar 		} else {
5635033f43cSJassi Brar 			/* Call can't be on the active DAI */
5645033f43cSJassi Brar 			i2s->op_clk = other->op_clk;
5655033f43cSJassi Brar 			i2s->rclk_srcrate = other->rclk_srcrate;
5665033f43cSJassi Brar 			return 0;
5675033f43cSJassi Brar 		}
5685033f43cSJassi Brar 
569ce8bcdbbSSylwester Nawrocki 		if (clk_id == 1)
570ce8bcdbbSSylwester Nawrocki 			val = 1 << i2s_regs->rclksrc_off;
571b2de1d20SPadmavathi Venna 		break;
5725033f43cSJassi Brar 	default:
5735033f43cSJassi Brar 		dev_err(&i2s->pdev->dev, "We don't serve that!\n");
5745033f43cSJassi Brar 		return -EINVAL;
5755033f43cSJassi Brar 	}
5765033f43cSJassi Brar 
577ce8bcdbbSSylwester Nawrocki 	spin_lock(i2s->lock);
578ce8bcdbbSSylwester Nawrocki 	mod = readl(i2s->addr + I2SMOD);
579ce8bcdbbSSylwester Nawrocki 	mod = (mod & ~mask) | val;
5805033f43cSJassi Brar 	writel(mod, i2s->addr + I2SMOD);
581ce8bcdbbSSylwester Nawrocki 	spin_unlock(i2s->lock);
5825033f43cSJassi Brar 
5835033f43cSJassi Brar 	return 0;
5845033f43cSJassi Brar }
5855033f43cSJassi Brar 
5865033f43cSJassi Brar static int i2s_set_fmt(struct snd_soc_dai *dai,
5875033f43cSJassi Brar 	unsigned int fmt)
5885033f43cSJassi Brar {
5895033f43cSJassi Brar 	struct i2s_dai *i2s = to_info(dai);
590a5a56871SPadmavathi Venna 	int lrp_shift, sdf_shift, sdf_mask, lrp_rlow, mod_slave;
591ce8bcdbbSSylwester Nawrocki 	u32 mod, tmp = 0;
5925033f43cSJassi Brar 
593a5a56871SPadmavathi Venna 	lrp_shift = i2s->variant_regs->lrp_off;
594a5a56871SPadmavathi Venna 	sdf_shift = i2s->variant_regs->sdf_off;
595a5a56871SPadmavathi Venna 	mod_slave = 1 << i2s->variant_regs->mss_off;
5964ca0c0d4SPadmavathi Venna 
597b60be4aaSPadmavathi Venna 	sdf_mask = MOD_SDF_MASK << sdf_shift;
598b60be4aaSPadmavathi Venna 	lrp_rlow = MOD_LR_RLOW << lrp_shift;
599b60be4aaSPadmavathi Venna 
6005033f43cSJassi Brar 	/* Format is priority */
6015033f43cSJassi Brar 	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
6025033f43cSJassi Brar 	case SND_SOC_DAIFMT_RIGHT_J:
603b60be4aaSPadmavathi Venna 		tmp |= lrp_rlow;
604b60be4aaSPadmavathi Venna 		tmp |= (MOD_SDF_MSB << sdf_shift);
6055033f43cSJassi Brar 		break;
6065033f43cSJassi Brar 	case SND_SOC_DAIFMT_LEFT_J:
607b60be4aaSPadmavathi Venna 		tmp |= lrp_rlow;
608b60be4aaSPadmavathi Venna 		tmp |= (MOD_SDF_LSB << sdf_shift);
6095033f43cSJassi Brar 		break;
6105033f43cSJassi Brar 	case SND_SOC_DAIFMT_I2S:
611b60be4aaSPadmavathi Venna 		tmp |= (MOD_SDF_IIS << sdf_shift);
6125033f43cSJassi Brar 		break;
6135033f43cSJassi Brar 	default:
6145033f43cSJassi Brar 		dev_err(&i2s->pdev->dev, "Format not supported\n");
6155033f43cSJassi Brar 		return -EINVAL;
6165033f43cSJassi Brar 	}
6175033f43cSJassi Brar 
6185033f43cSJassi Brar 	/*
6195033f43cSJassi Brar 	 * INV flag is relative to the FORMAT flag - if set it simply
6205033f43cSJassi Brar 	 * flips the polarity specified by the Standard
6215033f43cSJassi Brar 	 */
6225033f43cSJassi Brar 	switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
6235033f43cSJassi Brar 	case SND_SOC_DAIFMT_NB_NF:
6245033f43cSJassi Brar 		break;
6255033f43cSJassi Brar 	case SND_SOC_DAIFMT_NB_IF:
626b60be4aaSPadmavathi Venna 		if (tmp & lrp_rlow)
627b60be4aaSPadmavathi Venna 			tmp &= ~lrp_rlow;
6285033f43cSJassi Brar 		else
629b60be4aaSPadmavathi Venna 			tmp |= lrp_rlow;
6305033f43cSJassi Brar 		break;
6315033f43cSJassi Brar 	default:
6325033f43cSJassi Brar 		dev_err(&i2s->pdev->dev, "Polarity not supported\n");
6335033f43cSJassi Brar 		return -EINVAL;
6345033f43cSJassi Brar 	}
6355033f43cSJassi Brar 
6365033f43cSJassi Brar 	switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
6375033f43cSJassi Brar 	case SND_SOC_DAIFMT_CBM_CFM:
638a5a56871SPadmavathi Venna 		tmp |= mod_slave;
6395033f43cSJassi Brar 		break;
6405033f43cSJassi Brar 	case SND_SOC_DAIFMT_CBS_CFS:
6415033f43cSJassi Brar 		/* Set default source clock in Master mode */
6425033f43cSJassi Brar 		if (i2s->rclk_srcrate == 0)
6435033f43cSJassi Brar 			i2s_set_sysclk(dai, SAMSUNG_I2S_RCLKSRC_0,
6445033f43cSJassi Brar 							0, SND_SOC_CLOCK_IN);
6455033f43cSJassi Brar 		break;
6465033f43cSJassi Brar 	default:
6475033f43cSJassi Brar 		dev_err(&i2s->pdev->dev, "master/slave format not supported\n");
6485033f43cSJassi Brar 		return -EINVAL;
6495033f43cSJassi Brar 	}
6505033f43cSJassi Brar 
651ce8bcdbbSSylwester Nawrocki 	spin_lock(i2s->lock);
652ce8bcdbbSSylwester Nawrocki 	mod = readl(i2s->addr + I2SMOD);
653b60be4aaSPadmavathi Venna 	/*
654b60be4aaSPadmavathi Venna 	 * Don't change the I2S mode if any controller is active on this
655b60be4aaSPadmavathi Venna 	 * channel.
656b60be4aaSPadmavathi Venna 	 */
6575033f43cSJassi Brar 	if (any_active(i2s) &&
658a5a56871SPadmavathi Venna 		((mod & (sdf_mask | lrp_rlow | mod_slave)) != tmp)) {
659ce8bcdbbSSylwester Nawrocki 		spin_unlock(i2s->lock);
6605033f43cSJassi Brar 		dev_err(&i2s->pdev->dev,
6615033f43cSJassi Brar 				"%s:%d Other DAI busy\n", __func__, __LINE__);
6625033f43cSJassi Brar 		return -EAGAIN;
6635033f43cSJassi Brar 	}
6645033f43cSJassi Brar 
665a5a56871SPadmavathi Venna 	mod &= ~(sdf_mask | lrp_rlow | mod_slave);
6665033f43cSJassi Brar 	mod |= tmp;
6675033f43cSJassi Brar 	writel(mod, i2s->addr + I2SMOD);
668ce8bcdbbSSylwester Nawrocki 	spin_unlock(i2s->lock);
6695033f43cSJassi Brar 
6705033f43cSJassi Brar 	return 0;
6715033f43cSJassi Brar }
6725033f43cSJassi Brar 
6735033f43cSJassi Brar static int i2s_hw_params(struct snd_pcm_substream *substream,
6745033f43cSJassi Brar 	struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
6755033f43cSJassi Brar {
6765033f43cSJassi Brar 	struct i2s_dai *i2s = to_info(dai);
677ce8bcdbbSSylwester Nawrocki 	u32 mod, mask = 0, val = 0;
6785033f43cSJassi Brar 
6795033f43cSJassi Brar 	if (!is_secondary(i2s))
680ce8bcdbbSSylwester Nawrocki 		mask |= (MOD_DC2_EN | MOD_DC1_EN);
6815033f43cSJassi Brar 
6825033f43cSJassi Brar 	switch (params_channels(params)) {
6835033f43cSJassi Brar 	case 6:
684ce8bcdbbSSylwester Nawrocki 		val |= MOD_DC2_EN;
6855033f43cSJassi Brar 	case 4:
686ce8bcdbbSSylwester Nawrocki 		val |= MOD_DC1_EN;
6875033f43cSJassi Brar 		break;
6885033f43cSJassi Brar 	case 2:
689588fb705SSangsu Park 		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
690588fb705SSangsu Park 			i2s->dma_playback.dma_size = 4;
691588fb705SSangsu Park 		else
692588fb705SSangsu Park 			i2s->dma_capture.dma_size = 4;
693588fb705SSangsu Park 		break;
694588fb705SSangsu Park 	case 1:
695588fb705SSangsu Park 		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
696588fb705SSangsu Park 			i2s->dma_playback.dma_size = 2;
697588fb705SSangsu Park 		else
698588fb705SSangsu Park 			i2s->dma_capture.dma_size = 2;
699588fb705SSangsu Park 
7005033f43cSJassi Brar 		break;
7015033f43cSJassi Brar 	default:
7025033f43cSJassi Brar 		dev_err(&i2s->pdev->dev, "%d channels not supported\n",
7035033f43cSJassi Brar 				params_channels(params));
7045033f43cSJassi Brar 		return -EINVAL;
7055033f43cSJassi Brar 	}
7065033f43cSJassi Brar 
7075033f43cSJassi Brar 	if (is_secondary(i2s))
708ce8bcdbbSSylwester Nawrocki 		mask |= MOD_BLCS_MASK;
7095033f43cSJassi Brar 	else
710ce8bcdbbSSylwester Nawrocki 		mask |= MOD_BLCP_MASK;
7115033f43cSJassi Brar 
7125033f43cSJassi Brar 	if (is_manager(i2s))
713ce8bcdbbSSylwester Nawrocki 		mask |= MOD_BLC_MASK;
7145033f43cSJassi Brar 
71588ce1465STushar Behera 	switch (params_width(params)) {
71688ce1465STushar Behera 	case 8:
7175033f43cSJassi Brar 		if (is_secondary(i2s))
718ce8bcdbbSSylwester Nawrocki 			val |= MOD_BLCS_8BIT;
7195033f43cSJassi Brar 		else
720ce8bcdbbSSylwester Nawrocki 			val |= MOD_BLCP_8BIT;
7215033f43cSJassi Brar 		if (is_manager(i2s))
722ce8bcdbbSSylwester Nawrocki 			val |= MOD_BLC_8BIT;
7235033f43cSJassi Brar 		break;
72488ce1465STushar Behera 	case 16:
7255033f43cSJassi Brar 		if (is_secondary(i2s))
726ce8bcdbbSSylwester Nawrocki 			val |= MOD_BLCS_16BIT;
7275033f43cSJassi Brar 		else
728ce8bcdbbSSylwester Nawrocki 			val |= MOD_BLCP_16BIT;
7295033f43cSJassi Brar 		if (is_manager(i2s))
730ce8bcdbbSSylwester Nawrocki 			val |= MOD_BLC_16BIT;
7315033f43cSJassi Brar 		break;
73288ce1465STushar Behera 	case 24:
7335033f43cSJassi Brar 		if (is_secondary(i2s))
734ce8bcdbbSSylwester Nawrocki 			val |= MOD_BLCS_24BIT;
7355033f43cSJassi Brar 		else
736ce8bcdbbSSylwester Nawrocki 			val |= MOD_BLCP_24BIT;
7375033f43cSJassi Brar 		if (is_manager(i2s))
738ce8bcdbbSSylwester Nawrocki 			val |= MOD_BLC_24BIT;
7395033f43cSJassi Brar 		break;
7405033f43cSJassi Brar 	default:
7415033f43cSJassi Brar 		dev_err(&i2s->pdev->dev, "Format(%d) not supported\n",
7425033f43cSJassi Brar 				params_format(params));
7435033f43cSJassi Brar 		return -EINVAL;
7445033f43cSJassi Brar 	}
745ce8bcdbbSSylwester Nawrocki 
746ce8bcdbbSSylwester Nawrocki 	spin_lock(i2s->lock);
747ce8bcdbbSSylwester Nawrocki 	mod = readl(i2s->addr + I2SMOD);
748ce8bcdbbSSylwester Nawrocki 	mod = (mod & ~mask) | val;
7495033f43cSJassi Brar 	writel(mod, i2s->addr + I2SMOD);
750ce8bcdbbSSylwester Nawrocki 	spin_unlock(i2s->lock);
7515033f43cSJassi Brar 
752d37bdf73SMark Brown 	samsung_asoc_init_dma_data(dai, &i2s->dma_playback, &i2s->dma_capture);
753d37bdf73SMark Brown 
7545033f43cSJassi Brar 	i2s->frmclk = params_rate(params);
7555033f43cSJassi Brar 
7565033f43cSJassi Brar 	return 0;
7575033f43cSJassi Brar }
7585033f43cSJassi Brar 
7595033f43cSJassi Brar /* We set constraints on the substream acc to the version of I2S */
7605033f43cSJassi Brar static int i2s_startup(struct snd_pcm_substream *substream,
7615033f43cSJassi Brar 	  struct snd_soc_dai *dai)
7625033f43cSJassi Brar {
7635033f43cSJassi Brar 	struct i2s_dai *i2s = to_info(dai);
764dcd60fc3SSylwester Nawrocki 	struct i2s_dai *other = get_other_dai(i2s);
7655033f43cSJassi Brar 	unsigned long flags;
7665033f43cSJassi Brar 
7675033f43cSJassi Brar 	spin_lock_irqsave(&lock, flags);
7685033f43cSJassi Brar 
7695033f43cSJassi Brar 	i2s->mode |= DAI_OPENED;
7705033f43cSJassi Brar 
7715033f43cSJassi Brar 	if (is_manager(other))
7725033f43cSJassi Brar 		i2s->mode &= ~DAI_MANAGER;
7735033f43cSJassi Brar 	else
7745033f43cSJassi Brar 		i2s->mode |= DAI_MANAGER;
7755033f43cSJassi Brar 
7762d77828dSPadmavathi Venna 	if (!any_active(i2s) && (i2s->quirks & QUIRK_NEED_RSTCLR))
7772d77828dSPadmavathi Venna 		writel(CON_RSTCLR, i2s->addr + I2SCON);
7782d77828dSPadmavathi Venna 
7795033f43cSJassi Brar 	spin_unlock_irqrestore(&lock, flags);
7805033f43cSJassi Brar 
7815033f43cSJassi Brar 	return 0;
7825033f43cSJassi Brar }
7835033f43cSJassi Brar 
7845033f43cSJassi Brar static void i2s_shutdown(struct snd_pcm_substream *substream,
7855033f43cSJassi Brar 	struct snd_soc_dai *dai)
7865033f43cSJassi Brar {
7875033f43cSJassi Brar 	struct i2s_dai *i2s = to_info(dai);
788dcd60fc3SSylwester Nawrocki 	struct i2s_dai *other = get_other_dai(i2s);
7895033f43cSJassi Brar 	unsigned long flags;
7905033f43cSJassi Brar 
7915033f43cSJassi Brar 	spin_lock_irqsave(&lock, flags);
7925033f43cSJassi Brar 
7935033f43cSJassi Brar 	i2s->mode &= ~DAI_OPENED;
7945033f43cSJassi Brar 	i2s->mode &= ~DAI_MANAGER;
7955033f43cSJassi Brar 
796074b89bbSSylwester Nawrocki 	if (is_opened(other))
7975033f43cSJassi Brar 		other->mode |= DAI_MANAGER;
798074b89bbSSylwester Nawrocki 
7995033f43cSJassi Brar 	/* Reset any constraint on RFS and BFS */
8005033f43cSJassi Brar 	i2s->rfs = 0;
8015033f43cSJassi Brar 	i2s->bfs = 0;
8025033f43cSJassi Brar 
8035033f43cSJassi Brar 	spin_unlock_irqrestore(&lock, flags);
8045033f43cSJassi Brar }
8055033f43cSJassi Brar 
8065033f43cSJassi Brar static int config_setup(struct i2s_dai *i2s)
8075033f43cSJassi Brar {
808dcd60fc3SSylwester Nawrocki 	struct i2s_dai *other = get_other_dai(i2s);
8095033f43cSJassi Brar 	unsigned rfs, bfs, blc;
8105033f43cSJassi Brar 	u32 psr;
8115033f43cSJassi Brar 
8125033f43cSJassi Brar 	blc = get_blc(i2s);
8135033f43cSJassi Brar 
8145033f43cSJassi Brar 	bfs = i2s->bfs;
8155033f43cSJassi Brar 
8165033f43cSJassi Brar 	if (!bfs && other)
8175033f43cSJassi Brar 		bfs = other->bfs;
8185033f43cSJassi Brar 
8195033f43cSJassi Brar 	/* Select least possible multiple(2) if no constraint set */
8205033f43cSJassi Brar 	if (!bfs)
8215033f43cSJassi Brar 		bfs = blc * 2;
8225033f43cSJassi Brar 
8235033f43cSJassi Brar 	rfs = i2s->rfs;
8245033f43cSJassi Brar 
8255033f43cSJassi Brar 	if (!rfs && other)
8265033f43cSJassi Brar 		rfs = other->rfs;
8275033f43cSJassi Brar 
8285033f43cSJassi Brar 	if ((rfs == 256 || rfs == 512) && (blc == 24)) {
8295033f43cSJassi Brar 		dev_err(&i2s->pdev->dev,
8305033f43cSJassi Brar 			"%d-RFS not supported for 24-blc\n", rfs);
8315033f43cSJassi Brar 		return -EINVAL;
8325033f43cSJassi Brar 	}
8335033f43cSJassi Brar 
8345033f43cSJassi Brar 	if (!rfs) {
8355033f43cSJassi Brar 		if (bfs == 16 || bfs == 32)
8365033f43cSJassi Brar 			rfs = 256;
8375033f43cSJassi Brar 		else
8385033f43cSJassi Brar 			rfs = 384;
8395033f43cSJassi Brar 	}
8405033f43cSJassi Brar 
8415033f43cSJassi Brar 	/* If already setup and running */
8425033f43cSJassi Brar 	if (any_active(i2s) && (get_rfs(i2s) != rfs || get_bfs(i2s) != bfs)) {
8435033f43cSJassi Brar 		dev_err(&i2s->pdev->dev,
8445033f43cSJassi Brar 				"%s:%d Other DAI busy\n", __func__, __LINE__);
8455033f43cSJassi Brar 		return -EAGAIN;
8465033f43cSJassi Brar 	}
8475033f43cSJassi Brar 
8485033f43cSJassi Brar 	set_bfs(i2s, bfs);
8495033f43cSJassi Brar 	set_rfs(i2s, rfs);
8505033f43cSJassi Brar 
85177010010SPadmavathi Venna 	/* Don't bother with PSR in Slave mode */
85277010010SPadmavathi Venna 	if (is_slave(i2s))
85377010010SPadmavathi Venna 		return 0;
85477010010SPadmavathi Venna 
8555033f43cSJassi Brar 	if (!(i2s->quirks & QUIRK_NO_MUXPSR)) {
8565033f43cSJassi Brar 		psr = i2s->rclk_srcrate / i2s->frmclk / rfs;
8575033f43cSJassi Brar 		writel(((psr - 1) << 8) | PSR_PSREN, i2s->addr + I2SPSR);
8585033f43cSJassi Brar 		dev_dbg(&i2s->pdev->dev,
8595033f43cSJassi Brar 			"RCLK_SRC=%luHz PSR=%u, RCLK=%dfs, BCLK=%dfs\n",
8605033f43cSJassi Brar 				i2s->rclk_srcrate, psr, rfs, bfs);
8615033f43cSJassi Brar 	}
8625033f43cSJassi Brar 
8635033f43cSJassi Brar 	return 0;
8645033f43cSJassi Brar }
8655033f43cSJassi Brar 
8665033f43cSJassi Brar static int i2s_trigger(struct snd_pcm_substream *substream,
8675033f43cSJassi Brar 	int cmd, struct snd_soc_dai *dai)
8685033f43cSJassi Brar {
8695033f43cSJassi Brar 	int capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
8705033f43cSJassi Brar 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
8715033f43cSJassi Brar 	struct i2s_dai *i2s = to_info(rtd->cpu_dai);
8725033f43cSJassi Brar 	unsigned long flags;
8735033f43cSJassi Brar 
8745033f43cSJassi Brar 	switch (cmd) {
8755033f43cSJassi Brar 	case SNDRV_PCM_TRIGGER_START:
8765033f43cSJassi Brar 	case SNDRV_PCM_TRIGGER_RESUME:
8775033f43cSJassi Brar 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
878f3670536SSylwester Nawrocki 		spin_lock_irqsave(i2s->lock, flags);
8795033f43cSJassi Brar 
8805033f43cSJassi Brar 		if (config_setup(i2s)) {
881f3670536SSylwester Nawrocki 			spin_unlock_irqrestore(i2s->lock, flags);
8825033f43cSJassi Brar 			return -EINVAL;
8835033f43cSJassi Brar 		}
8845033f43cSJassi Brar 
8855033f43cSJassi Brar 		if (capture)
8865033f43cSJassi Brar 			i2s_rxctrl(i2s, 1);
8875033f43cSJassi Brar 		else
8885033f43cSJassi Brar 			i2s_txctrl(i2s, 1);
8895033f43cSJassi Brar 
890f3670536SSylwester Nawrocki 		spin_unlock_irqrestore(i2s->lock, flags);
8915033f43cSJassi Brar 		break;
8925033f43cSJassi Brar 	case SNDRV_PCM_TRIGGER_STOP:
8935033f43cSJassi Brar 	case SNDRV_PCM_TRIGGER_SUSPEND:
8945033f43cSJassi Brar 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
895f3670536SSylwester Nawrocki 		spin_lock_irqsave(i2s->lock, flags);
8965033f43cSJassi Brar 
897c90887feSJassi Brar 		if (capture) {
8985033f43cSJassi Brar 			i2s_rxctrl(i2s, 0);
899775bc971SJassi Brar 			i2s_fifo(i2s, FIC_RXFLUSH);
900c90887feSJassi Brar 		} else {
901c90887feSJassi Brar 			i2s_txctrl(i2s, 0);
902775bc971SJassi Brar 			i2s_fifo(i2s, FIC_TXFLUSH);
903c90887feSJassi Brar 		}
904775bc971SJassi Brar 
905f3670536SSylwester Nawrocki 		spin_unlock_irqrestore(i2s->lock, flags);
9065033f43cSJassi Brar 		break;
9075033f43cSJassi Brar 	}
9085033f43cSJassi Brar 
9095033f43cSJassi Brar 	return 0;
9105033f43cSJassi Brar }
9115033f43cSJassi Brar 
9125033f43cSJassi Brar static int i2s_set_clkdiv(struct snd_soc_dai *dai,
9135033f43cSJassi Brar 	int div_id, int div)
9145033f43cSJassi Brar {
9155033f43cSJassi Brar 	struct i2s_dai *i2s = to_info(dai);
916dcd60fc3SSylwester Nawrocki 	struct i2s_dai *other = get_other_dai(i2s);
9175033f43cSJassi Brar 
9185033f43cSJassi Brar 	switch (div_id) {
9195033f43cSJassi Brar 	case SAMSUNG_I2S_DIV_BCLK:
9205033f43cSJassi Brar 		if ((any_active(i2s) && div && (get_bfs(i2s) != div))
9215033f43cSJassi Brar 			|| (other && other->bfs && (other->bfs != div))) {
9225033f43cSJassi Brar 			dev_err(&i2s->pdev->dev,
9235033f43cSJassi Brar 				"%s:%d Other DAI busy\n", __func__, __LINE__);
9245033f43cSJassi Brar 			return -EAGAIN;
9255033f43cSJassi Brar 		}
9265033f43cSJassi Brar 		i2s->bfs = div;
9275033f43cSJassi Brar 		break;
9285033f43cSJassi Brar 	default:
9295033f43cSJassi Brar 		dev_err(&i2s->pdev->dev,
9305033f43cSJassi Brar 			"Invalid clock divider(%d)\n", div_id);
9315033f43cSJassi Brar 		return -EINVAL;
9325033f43cSJassi Brar 	}
9335033f43cSJassi Brar 
9345033f43cSJassi Brar 	return 0;
9355033f43cSJassi Brar }
9365033f43cSJassi Brar 
9375033f43cSJassi Brar static snd_pcm_sframes_t
9385033f43cSJassi Brar i2s_delay(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
9395033f43cSJassi Brar {
9405033f43cSJassi Brar 	struct i2s_dai *i2s = to_info(dai);
9415033f43cSJassi Brar 	u32 reg = readl(i2s->addr + I2SFIC);
9425033f43cSJassi Brar 	snd_pcm_sframes_t delay;
943a5a56871SPadmavathi Venna 	const struct samsung_i2s_variant_regs *i2s_regs = i2s->variant_regs;
9445033f43cSJassi Brar 
9455033f43cSJassi Brar 	if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
9465033f43cSJassi Brar 		delay = FIC_RXCOUNT(reg);
9475033f43cSJassi Brar 	else if (is_secondary(i2s))
9485033f43cSJassi Brar 		delay = FICS_TXCOUNT(readl(i2s->addr + I2SFICS));
9495033f43cSJassi Brar 	else
950a5a56871SPadmavathi Venna 		delay = (reg >> i2s_regs->ftx0cnt_off) & 0x7f;
9515033f43cSJassi Brar 
9525033f43cSJassi Brar 	return delay;
9535033f43cSJassi Brar }
9545033f43cSJassi Brar 
9555033f43cSJassi Brar #ifdef CONFIG_PM
9565033f43cSJassi Brar static int i2s_suspend(struct snd_soc_dai *dai)
9575033f43cSJassi Brar {
9585033f43cSJassi Brar 	struct i2s_dai *i2s = to_info(dai);
9595033f43cSJassi Brar 
9605033f43cSJassi Brar 	i2s->suspend_i2smod = readl(i2s->addr + I2SMOD);
9615033f43cSJassi Brar 	i2s->suspend_i2scon = readl(i2s->addr + I2SCON);
9625033f43cSJassi Brar 	i2s->suspend_i2spsr = readl(i2s->addr + I2SPSR);
9635033f43cSJassi Brar 
9645033f43cSJassi Brar 	return 0;
9655033f43cSJassi Brar }
9665033f43cSJassi Brar 
9675033f43cSJassi Brar static int i2s_resume(struct snd_soc_dai *dai)
9685033f43cSJassi Brar {
9695033f43cSJassi Brar 	struct i2s_dai *i2s = to_info(dai);
9705033f43cSJassi Brar 
9715033f43cSJassi Brar 	writel(i2s->suspend_i2scon, i2s->addr + I2SCON);
9725033f43cSJassi Brar 	writel(i2s->suspend_i2smod, i2s->addr + I2SMOD);
9735033f43cSJassi Brar 	writel(i2s->suspend_i2spsr, i2s->addr + I2SPSR);
9745033f43cSJassi Brar 
9755033f43cSJassi Brar 	return 0;
9765033f43cSJassi Brar }
9775033f43cSJassi Brar #else
9785033f43cSJassi Brar #define i2s_suspend NULL
9795033f43cSJassi Brar #define i2s_resume  NULL
9805033f43cSJassi Brar #endif
9815033f43cSJassi Brar 
9825033f43cSJassi Brar static int samsung_i2s_dai_probe(struct snd_soc_dai *dai)
9835033f43cSJassi Brar {
9845033f43cSJassi Brar 	struct i2s_dai *i2s = to_info(dai);
985dcd60fc3SSylwester Nawrocki 	struct i2s_dai *other = get_other_dai(i2s);
986ce8bcdbbSSylwester Nawrocki 	unsigned long flags;
9875033f43cSJassi Brar 
9880ec2ba80SSylwester Nawrocki 	if (is_secondary(i2s)) { /* If this is probe on the secondary DAI */
9893688569eSMark Brown 		samsung_asoc_init_dma_data(dai, &other->sec_dai->dma_playback,
9903688569eSMark Brown 					   NULL);
991872c26bdSSylwester Nawrocki 	} else {
992872c26bdSSylwester Nawrocki 		samsung_asoc_init_dma_data(dai, &i2s->dma_playback,
993872c26bdSSylwester Nawrocki 					   &i2s->dma_capture);
994511e3033SMark Brown 
9955033f43cSJassi Brar 		if (i2s->quirks & QUIRK_NEED_RSTCLR)
9965033f43cSJassi Brar 			writel(CON_RSTCLR, i2s->addr + I2SCON);
9975033f43cSJassi Brar 
998b0759736SPadmavathi Venna 		if (i2s->quirks & QUIRK_SUPPORTS_IDMA)
9999b8f5695SMark Brown 			idma_reg_addr_init(i2s->addr,
100061100f40SSangbeom Kim 					i2s->sec_dai->idma_playback.dma_addr);
1001872c26bdSSylwester Nawrocki 	}
100261100f40SSangbeom Kim 
10035033f43cSJassi Brar 	/* Reset any constraint on RFS and BFS */
10045033f43cSJassi Brar 	i2s->rfs = 0;
10055033f43cSJassi Brar 	i2s->bfs = 0;
1006d66eac3eSTushar Behera 	i2s->rclk_srcrate = 0;
1007ce8bcdbbSSylwester Nawrocki 
1008ce8bcdbbSSylwester Nawrocki 	spin_lock_irqsave(i2s->lock, flags);
10095033f43cSJassi Brar 	i2s_txctrl(i2s, 0);
10105033f43cSJassi Brar 	i2s_rxctrl(i2s, 0);
10115033f43cSJassi Brar 	i2s_fifo(i2s, FIC_TXFLUSH);
10125033f43cSJassi Brar 	i2s_fifo(other, FIC_TXFLUSH);
10135033f43cSJassi Brar 	i2s_fifo(i2s, FIC_RXFLUSH);
1014ce8bcdbbSSylwester Nawrocki 	spin_unlock_irqrestore(i2s->lock, flags);
10155033f43cSJassi Brar 
10165033f43cSJassi Brar 	/* Gate CDCLK by default */
10175033f43cSJassi Brar 	if (!is_opened(other))
10185033f43cSJassi Brar 		i2s_set_sysclk(dai, SAMSUNG_I2S_CDCLK,
10195033f43cSJassi Brar 				0, SND_SOC_CLOCK_IN);
10205033f43cSJassi Brar 
10215033f43cSJassi Brar 	return 0;
10225033f43cSJassi Brar }
10235033f43cSJassi Brar 
10245033f43cSJassi Brar static int samsung_i2s_dai_remove(struct snd_soc_dai *dai)
10255033f43cSJassi Brar {
10265033f43cSJassi Brar 	struct i2s_dai *i2s = snd_soc_dai_get_drvdata(dai);
10275033f43cSJassi Brar 
1028c92f1d0eSSylwester Nawrocki 	if (!is_secondary(i2s)) {
1029ce8bcdbbSSylwester Nawrocki 		if (i2s->quirks & QUIRK_NEED_RSTCLR) {
1030ce8bcdbbSSylwester Nawrocki 			spin_lock(i2s->lock);
10315033f43cSJassi Brar 			writel(0, i2s->addr + I2SCON);
1032ce8bcdbbSSylwester Nawrocki 			spin_unlock(i2s->lock);
1033ce8bcdbbSSylwester Nawrocki 		}
10345033f43cSJassi Brar 	}
10355033f43cSJassi Brar 
10365033f43cSJassi Brar 	return 0;
10375033f43cSJassi Brar }
10385033f43cSJassi Brar 
103985e7652dSLars-Peter Clausen static const struct snd_soc_dai_ops samsung_i2s_dai_ops = {
10405033f43cSJassi Brar 	.trigger = i2s_trigger,
10415033f43cSJassi Brar 	.hw_params = i2s_hw_params,
10425033f43cSJassi Brar 	.set_fmt = i2s_set_fmt,
10435033f43cSJassi Brar 	.set_clkdiv = i2s_set_clkdiv,
10445033f43cSJassi Brar 	.set_sysclk = i2s_set_sysclk,
10455033f43cSJassi Brar 	.startup = i2s_startup,
10465033f43cSJassi Brar 	.shutdown = i2s_shutdown,
10475033f43cSJassi Brar 	.delay = i2s_delay,
10485033f43cSJassi Brar };
10495033f43cSJassi Brar 
10504b828535SKuninori Morimoto static const struct snd_soc_component_driver samsung_i2s_component = {
10514b828535SKuninori Morimoto 	.name		= "samsung-i2s",
10524b828535SKuninori Morimoto };
10534b828535SKuninori Morimoto 
10545033f43cSJassi Brar #define SAMSUNG_I2S_RATES	SNDRV_PCM_RATE_8000_96000
10555033f43cSJassi Brar 
10565033f43cSJassi Brar #define SAMSUNG_I2S_FMTS	(SNDRV_PCM_FMTBIT_S8 | \
10575033f43cSJassi Brar 					SNDRV_PCM_FMTBIT_S16_LE | \
10585033f43cSJassi Brar 					SNDRV_PCM_FMTBIT_S24_LE)
10595033f43cSJassi Brar 
1060fdca21adSBill Pemberton static struct i2s_dai *i2s_alloc_dai(struct platform_device *pdev, bool sec)
10615033f43cSJassi Brar {
10625033f43cSJassi Brar 	struct i2s_dai *i2s;
1063c6f9b1ebSPrathyush K 	int ret;
10645033f43cSJassi Brar 
1065b960ce74SMark Brown 	i2s = devm_kzalloc(&pdev->dev, sizeof(struct i2s_dai), GFP_KERNEL);
10665033f43cSJassi Brar 	if (i2s == NULL)
10675033f43cSJassi Brar 		return NULL;
10685033f43cSJassi Brar 
10695033f43cSJassi Brar 	i2s->pdev = pdev;
10705033f43cSJassi Brar 	i2s->pri_dai = NULL;
10715033f43cSJassi Brar 	i2s->sec_dai = NULL;
10725033f43cSJassi Brar 	i2s->i2s_dai_drv.symmetric_rates = 1;
10735033f43cSJassi Brar 	i2s->i2s_dai_drv.probe = samsung_i2s_dai_probe;
10745033f43cSJassi Brar 	i2s->i2s_dai_drv.remove = samsung_i2s_dai_remove;
10755033f43cSJassi Brar 	i2s->i2s_dai_drv.ops = &samsung_i2s_dai_ops;
10765033f43cSJassi Brar 	i2s->i2s_dai_drv.suspend = i2s_suspend;
10775033f43cSJassi Brar 	i2s->i2s_dai_drv.resume = i2s_resume;
1078a0ff6ea2SCharles Keepax 	i2s->i2s_dai_drv.playback.channels_min = 1;
10795033f43cSJassi Brar 	i2s->i2s_dai_drv.playback.channels_max = 2;
10805033f43cSJassi Brar 	i2s->i2s_dai_drv.playback.rates = SAMSUNG_I2S_RATES;
10815033f43cSJassi Brar 	i2s->i2s_dai_drv.playback.formats = SAMSUNG_I2S_FMTS;
10825033f43cSJassi Brar 
10835033f43cSJassi Brar 	if (!sec) {
1084588fb705SSangsu Park 		i2s->i2s_dai_drv.capture.channels_min = 1;
10855033f43cSJassi Brar 		i2s->i2s_dai_drv.capture.channels_max = 2;
10865033f43cSJassi Brar 		i2s->i2s_dai_drv.capture.rates = SAMSUNG_I2S_RATES;
10875033f43cSJassi Brar 		i2s->i2s_dai_drv.capture.formats = SAMSUNG_I2S_FMTS;
1088c6f9b1ebSPrathyush K 		dev_set_drvdata(&i2s->pdev->dev, i2s);
10895033f43cSJassi Brar 	} else {	/* Create a new platform_device for Secondary */
1090c6f9b1ebSPrathyush K 		i2s->pdev = platform_device_alloc("samsung-i2s-sec", -1);
109129ca9c73SWei Yongjun 		if (!i2s->pdev)
10925033f43cSJassi Brar 			return NULL;
10935033f43cSJassi Brar 
10942f6f0ffbSMark Brown 		i2s->pdev->dev.parent = &pdev->dev;
10952f6f0ffbSMark Brown 
1096c6f9b1ebSPrathyush K 		platform_set_drvdata(i2s->pdev, i2s);
1097c6f9b1ebSPrathyush K 		ret = platform_device_add(i2s->pdev);
1098c6f9b1ebSPrathyush K 		if (ret < 0)
1099c6f9b1ebSPrathyush K 			return NULL;
1100c6f9b1ebSPrathyush K 	}
11015033f43cSJassi Brar 
11025033f43cSJassi Brar 	return i2s;
11035033f43cSJassi Brar }
11045033f43cSJassi Brar 
110540476f61SPadmavathi Venna static const struct of_device_id exynos_i2s_match[];
110640476f61SPadmavathi Venna 
11077da493e9SPadmavathi Venna static inline const struct samsung_i2s_dai_data *samsung_i2s_get_driver_data(
11087da493e9SPadmavathi Venna 						struct platform_device *pdev)
11097c62eebbSPadmavathi Venna {
11109cf24747SSylwester Nawrocki 	if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {
111140476f61SPadmavathi Venna 		const struct of_device_id *match;
111240476f61SPadmavathi Venna 		match = of_match_node(exynos_i2s_match, pdev->dev.of_node);
11139cf24747SSylwester Nawrocki 		return match ? match->data : NULL;
11149cf24747SSylwester Nawrocki 	} else {
11157da493e9SPadmavathi Venna 		return (struct samsung_i2s_dai_data *)
11167da493e9SPadmavathi Venna 				platform_get_device_id(pdev)->driver_data;
11177c62eebbSPadmavathi Venna 	}
11189cf24747SSylwester Nawrocki }
11197c62eebbSPadmavathi Venna 
1120641d334bSRafael J. Wysocki #ifdef CONFIG_PM
11215b1d3c34SR. Chandrasekar static int i2s_runtime_suspend(struct device *dev)
11225b1d3c34SR. Chandrasekar {
11235b1d3c34SR. Chandrasekar 	struct i2s_dai *i2s = dev_get_drvdata(dev);
11245b1d3c34SR. Chandrasekar 
11255b1d3c34SR. Chandrasekar 	clk_disable_unprepare(i2s->clk);
11265b1d3c34SR. Chandrasekar 
11275b1d3c34SR. Chandrasekar 	return 0;
11285b1d3c34SR. Chandrasekar }
11295b1d3c34SR. Chandrasekar 
11305b1d3c34SR. Chandrasekar static int i2s_runtime_resume(struct device *dev)
11315b1d3c34SR. Chandrasekar {
11325b1d3c34SR. Chandrasekar 	struct i2s_dai *i2s = dev_get_drvdata(dev);
11335b1d3c34SR. Chandrasekar 
11345b1d3c34SR. Chandrasekar 	clk_prepare_enable(i2s->clk);
11355b1d3c34SR. Chandrasekar 
11365b1d3c34SR. Chandrasekar 	return 0;
11375b1d3c34SR. Chandrasekar }
1138641d334bSRafael J. Wysocki #endif /* CONFIG_PM */
11395b1d3c34SR. Chandrasekar 
1140074b89bbSSylwester Nawrocki static void i2s_unregister_clocks(struct i2s_dai *i2s)
1141074b89bbSSylwester Nawrocki {
1142074b89bbSSylwester Nawrocki 	int i;
1143074b89bbSSylwester Nawrocki 
1144074b89bbSSylwester Nawrocki 	for (i = 0; i < i2s->clk_data.clk_num; i++) {
1145074b89bbSSylwester Nawrocki 		if (!IS_ERR(i2s->clk_table[i]))
1146074b89bbSSylwester Nawrocki 			clk_unregister(i2s->clk_table[i]);
1147074b89bbSSylwester Nawrocki 	}
1148074b89bbSSylwester Nawrocki }
1149074b89bbSSylwester Nawrocki 
1150074b89bbSSylwester Nawrocki static void i2s_unregister_clock_provider(struct platform_device *pdev)
1151074b89bbSSylwester Nawrocki {
1152074b89bbSSylwester Nawrocki 	struct i2s_dai *i2s = dev_get_drvdata(&pdev->dev);
1153074b89bbSSylwester Nawrocki 
1154074b89bbSSylwester Nawrocki 	of_clk_del_provider(pdev->dev.of_node);
1155074b89bbSSylwester Nawrocki 	i2s_unregister_clocks(i2s);
1156074b89bbSSylwester Nawrocki }
1157074b89bbSSylwester Nawrocki 
1158074b89bbSSylwester Nawrocki static int i2s_register_clock_provider(struct platform_device *pdev)
1159074b89bbSSylwester Nawrocki {
1160074b89bbSSylwester Nawrocki 	struct device *dev = &pdev->dev;
1161074b89bbSSylwester Nawrocki 	struct i2s_dai *i2s = dev_get_drvdata(dev);
1162074b89bbSSylwester Nawrocki 	const char *clk_name[2] = { "i2s_opclk0", "i2s_opclk1" };
1163074b89bbSSylwester Nawrocki 	const char *p_names[2] = { NULL };
1164074b89bbSSylwester Nawrocki 	const struct samsung_i2s_variant_regs *reg_info = i2s->variant_regs;
1165074b89bbSSylwester Nawrocki 	struct clk *rclksrc;
1166074b89bbSSylwester Nawrocki 	int ret, i;
1167074b89bbSSylwester Nawrocki 
1168074b89bbSSylwester Nawrocki 	/* Register the clock provider only if it's expected in the DTB */
1169074b89bbSSylwester Nawrocki 	if (!of_find_property(dev->of_node, "#clock-cells", NULL))
1170074b89bbSSylwester Nawrocki 		return 0;
1171074b89bbSSylwester Nawrocki 
1172074b89bbSSylwester Nawrocki 	/* Get the RCLKSRC mux clock parent clock names */
1173074b89bbSSylwester Nawrocki 	for (i = 0; i < ARRAY_SIZE(p_names); i++) {
1174074b89bbSSylwester Nawrocki 		rclksrc = clk_get(dev, clk_name[i]);
1175074b89bbSSylwester Nawrocki 		if (IS_ERR(rclksrc))
1176074b89bbSSylwester Nawrocki 			continue;
1177074b89bbSSylwester Nawrocki 		p_names[i] = __clk_get_name(rclksrc);
1178074b89bbSSylwester Nawrocki 		clk_put(rclksrc);
1179074b89bbSSylwester Nawrocki 	}
1180074b89bbSSylwester Nawrocki 
1181074b89bbSSylwester Nawrocki 	if (!(i2s->quirks & QUIRK_NO_MUXPSR)) {
1182074b89bbSSylwester Nawrocki 		/* Activate the prescaler */
1183074b89bbSSylwester Nawrocki 		u32 val = readl(i2s->addr + I2SPSR);
1184074b89bbSSylwester Nawrocki 		writel(val | PSR_PSREN, i2s->addr + I2SPSR);
1185074b89bbSSylwester Nawrocki 
1186074b89bbSSylwester Nawrocki 		i2s->clk_table[CLK_I2S_RCLK_SRC] = clk_register_mux(NULL,
1187074b89bbSSylwester Nawrocki 				"i2s_rclksrc", p_names, ARRAY_SIZE(p_names),
1188074b89bbSSylwester Nawrocki 				CLK_SET_RATE_NO_REPARENT | CLK_SET_RATE_PARENT,
1189074b89bbSSylwester Nawrocki 				i2s->addr + I2SMOD, reg_info->rclksrc_off,
1190074b89bbSSylwester Nawrocki 				1, 0, i2s->lock);
1191074b89bbSSylwester Nawrocki 
1192074b89bbSSylwester Nawrocki 		i2s->clk_table[CLK_I2S_RCLK_PSR] = clk_register_divider(NULL,
1193074b89bbSSylwester Nawrocki 				"i2s_presc", "i2s_rclksrc",
1194074b89bbSSylwester Nawrocki 				CLK_SET_RATE_PARENT,
1195074b89bbSSylwester Nawrocki 				i2s->addr + I2SPSR, 8, 6, 0, i2s->lock);
1196074b89bbSSylwester Nawrocki 
1197074b89bbSSylwester Nawrocki 		p_names[0] = "i2s_presc";
1198074b89bbSSylwester Nawrocki 		i2s->clk_data.clk_num = 2;
1199074b89bbSSylwester Nawrocki 	}
1200074b89bbSSylwester Nawrocki 	of_property_read_string_index(dev->of_node,
1201074b89bbSSylwester Nawrocki 				"clock-output-names", 0, &clk_name[0]);
1202074b89bbSSylwester Nawrocki 
1203074b89bbSSylwester Nawrocki 	i2s->clk_table[CLK_I2S_CDCLK] = clk_register_gate(NULL, clk_name[0],
1204074b89bbSSylwester Nawrocki 				p_names[0], CLK_SET_RATE_PARENT,
1205074b89bbSSylwester Nawrocki 				i2s->addr + I2SMOD, reg_info->cdclkcon_off,
1206074b89bbSSylwester Nawrocki 				CLK_GATE_SET_TO_DISABLE, i2s->lock);
1207074b89bbSSylwester Nawrocki 
1208074b89bbSSylwester Nawrocki 	i2s->clk_data.clk_num += 1;
1209074b89bbSSylwester Nawrocki 	i2s->clk_data.clks = i2s->clk_table;
1210074b89bbSSylwester Nawrocki 
1211074b89bbSSylwester Nawrocki 	ret = of_clk_add_provider(dev->of_node, of_clk_src_onecell_get,
1212074b89bbSSylwester Nawrocki 				  &i2s->clk_data);
1213074b89bbSSylwester Nawrocki 	if (ret < 0) {
1214074b89bbSSylwester Nawrocki 		dev_err(dev, "failed to add clock provider: %d\n", ret);
1215074b89bbSSylwester Nawrocki 		i2s_unregister_clocks(i2s);
1216074b89bbSSylwester Nawrocki 	}
1217074b89bbSSylwester Nawrocki 
1218074b89bbSSylwester Nawrocki 	return ret;
1219074b89bbSSylwester Nawrocki }
1220074b89bbSSylwester Nawrocki 
1221fdca21adSBill Pemberton static int samsung_i2s_probe(struct platform_device *pdev)
12225033f43cSJassi Brar {
12235033f43cSJassi Brar 	struct i2s_dai *pri_dai, *sec_dai = NULL;
122440476f61SPadmavathi Venna 	struct s3c_audio_pdata *i2s_pdata = pdev->dev.platform_data;
122540476f61SPadmavathi Venna 	struct samsung_i2s *i2s_cfg = NULL;
12265033f43cSJassi Brar 	struct resource *res;
122740476f61SPadmavathi Venna 	u32 regs_base, quirks = 0, idma_addr = 0;
122840476f61SPadmavathi Venna 	struct device_node *np = pdev->dev.of_node;
12297da493e9SPadmavathi Venna 	const struct samsung_i2s_dai_data *i2s_dai_data;
1230c92f1d0eSSylwester Nawrocki 	int ret;
12315033f43cSJassi Brar 
12325033f43cSJassi Brar 	/* Call during Seconday interface registration */
12337da493e9SPadmavathi Venna 	i2s_dai_data = samsung_i2s_get_driver_data(pdev);
12347c62eebbSPadmavathi Venna 
12357da493e9SPadmavathi Venna 	if (i2s_dai_data->dai_type == TYPE_SEC) {
12365033f43cSJassi Brar 		sec_dai = dev_get_drvdata(&pdev->dev);
1237a9b977ecSPrathyush K 		if (!sec_dai) {
1238a9b977ecSPrathyush K 			dev_err(&pdev->dev, "Unable to get drvdata\n");
1239a9b977ecSPrathyush K 			return -EFAULT;
1240a9b977ecSPrathyush K 		}
124153f7faa1SSylwester Nawrocki 		ret = devm_snd_soc_register_component(&sec_dai->pdev->dev,
12424b828535SKuninori Morimoto 						&samsung_i2s_component,
12434b828535SKuninori Morimoto 						&sec_dai->i2s_dai_drv, 1);
124453f7faa1SSylwester Nawrocki 		if (ret != 0)
124553f7faa1SSylwester Nawrocki 			return ret;
124653f7faa1SSylwester Nawrocki 
124753f7faa1SSylwester Nawrocki 		return samsung_asoc_dma_platform_register(&pdev->dev);
12485033f43cSJassi Brar 	}
12495033f43cSJassi Brar 
125040476f61SPadmavathi Venna 	pri_dai = i2s_alloc_dai(pdev, false);
125140476f61SPadmavathi Venna 	if (!pri_dai) {
125240476f61SPadmavathi Venna 		dev_err(&pdev->dev, "Unable to alloc I2S_pri\n");
125340476f61SPadmavathi Venna 		return -ENOMEM;
125440476f61SPadmavathi Venna 	}
125540476f61SPadmavathi Venna 
1256f3670536SSylwester Nawrocki 	spin_lock_init(&pri_dai->spinlock);
1257f3670536SSylwester Nawrocki 	pri_dai->lock = &pri_dai->spinlock;
1258f3670536SSylwester Nawrocki 
125940476f61SPadmavathi Venna 	if (!np) {
126040476f61SPadmavathi Venna 		res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
126140476f61SPadmavathi Venna 		if (!res) {
126240476f61SPadmavathi Venna 			dev_err(&pdev->dev,
126340476f61SPadmavathi Venna 				"Unable to get I2S-TX dma resource\n");
126440476f61SPadmavathi Venna 			return -ENXIO;
126540476f61SPadmavathi Venna 		}
126640476f61SPadmavathi Venna 		pri_dai->dma_playback.channel = res->start;
126740476f61SPadmavathi Venna 
126840476f61SPadmavathi Venna 		res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
126940476f61SPadmavathi Venna 		if (!res) {
127040476f61SPadmavathi Venna 			dev_err(&pdev->dev,
127140476f61SPadmavathi Venna 				"Unable to get I2S-RX dma resource\n");
127240476f61SPadmavathi Venna 			return -ENXIO;
127340476f61SPadmavathi Venna 		}
127440476f61SPadmavathi Venna 		pri_dai->dma_capture.channel = res->start;
127540476f61SPadmavathi Venna 
12765033f43cSJassi Brar 		if (i2s_pdata == NULL) {
12775033f43cSJassi Brar 			dev_err(&pdev->dev, "Can't work without s3c_audio_pdata\n");
12785033f43cSJassi Brar 			return -EINVAL;
12795033f43cSJassi Brar 		}
12805033f43cSJassi Brar 
128140476f61SPadmavathi Venna 		if (&i2s_pdata->type)
128240476f61SPadmavathi Venna 			i2s_cfg = &i2s_pdata->type.i2s;
12835033f43cSJassi Brar 
128440476f61SPadmavathi Venna 		if (i2s_cfg) {
128540476f61SPadmavathi Venna 			quirks = i2s_cfg->quirks;
128640476f61SPadmavathi Venna 			idma_addr = i2s_cfg->idma_addr;
12875033f43cSJassi Brar 		}
128840476f61SPadmavathi Venna 	} else {
12897da493e9SPadmavathi Venna 		quirks = i2s_dai_data->quirks;
129040476f61SPadmavathi Venna 		if (of_property_read_u32(np, "samsung,idma-addr",
129140476f61SPadmavathi Venna 					 &idma_addr)) {
1292b0759736SPadmavathi Venna 			if (quirks & QUIRK_SUPPORTS_IDMA) {
1293b0759736SPadmavathi Venna 				dev_info(&pdev->dev, "idma address is not"\
129440476f61SPadmavathi Venna 						"specified");
129540476f61SPadmavathi Venna 			}
129640476f61SPadmavathi Venna 		}
129740476f61SPadmavathi Venna 	}
12985033f43cSJassi Brar 
12995033f43cSJassi Brar 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1300af1cf5cfSSylwester Nawrocki 	pri_dai->addr = devm_ioremap_resource(&pdev->dev, res);
1301af1cf5cfSSylwester Nawrocki 	if (IS_ERR(pri_dai->addr))
1302af1cf5cfSSylwester Nawrocki 		return PTR_ERR(pri_dai->addr);
13035033f43cSJassi Brar 
13045033f43cSJassi Brar 	regs_base = res->start;
13055033f43cSJassi Brar 
13060ec2ba80SSylwester Nawrocki 	pri_dai->clk = devm_clk_get(&pdev->dev, "iis");
13070ec2ba80SSylwester Nawrocki 	if (IS_ERR(pri_dai->clk)) {
13080ec2ba80SSylwester Nawrocki 		dev_err(&pdev->dev, "Failed to get iis clock\n");
13090ec2ba80SSylwester Nawrocki 		return PTR_ERR(pri_dai->clk);
13100ec2ba80SSylwester Nawrocki 	}
1311c92f1d0eSSylwester Nawrocki 
1312c92f1d0eSSylwester Nawrocki 	ret = clk_prepare_enable(pri_dai->clk);
1313c92f1d0eSSylwester Nawrocki 	if (ret != 0) {
1314c92f1d0eSSylwester Nawrocki 		dev_err(&pdev->dev, "failed to enable clock: %d\n", ret);
1315c92f1d0eSSylwester Nawrocki 		return ret;
1316c92f1d0eSSylwester Nawrocki 	}
13175033f43cSJassi Brar 	pri_dai->dma_playback.dma_addr = regs_base + I2STXD;
13185033f43cSJassi Brar 	pri_dai->dma_capture.dma_addr = regs_base + I2SRXD;
131940476f61SPadmavathi Venna 	pri_dai->dma_playback.ch_name = "tx";
132040476f61SPadmavathi Venna 	pri_dai->dma_capture.ch_name = "rx";
13215033f43cSJassi Brar 	pri_dai->dma_playback.dma_size = 4;
13225033f43cSJassi Brar 	pri_dai->dma_capture.dma_size = 4;
13235033f43cSJassi Brar 	pri_dai->quirks = quirks;
1324a5a56871SPadmavathi Venna 	pri_dai->variant_regs = i2s_dai_data->i2s_variant_regs;
13255033f43cSJassi Brar 
13265033f43cSJassi Brar 	if (quirks & QUIRK_PRI_6CHAN)
13275033f43cSJassi Brar 		pri_dai->i2s_dai_drv.playback.channels_max = 6;
13285033f43cSJassi Brar 
13295033f43cSJassi Brar 	if (quirks & QUIRK_SEC_DAI) {
13305033f43cSJassi Brar 		sec_dai = i2s_alloc_dai(pdev, true);
13315033f43cSJassi Brar 		if (!sec_dai) {
13325033f43cSJassi Brar 			dev_err(&pdev->dev, "Unable to alloc I2S_sec\n");
1333af1cf5cfSSylwester Nawrocki 			return -ENOMEM;
13345033f43cSJassi Brar 		}
13357e5d8706SSylwester Nawrocki 
1336f3670536SSylwester Nawrocki 		sec_dai->lock = &pri_dai->spinlock;
13377e5d8706SSylwester Nawrocki 		sec_dai->variant_regs = pri_dai->variant_regs;
13385033f43cSJassi Brar 		sec_dai->dma_playback.dma_addr = regs_base + I2STXDS;
133940476f61SPadmavathi Venna 		sec_dai->dma_playback.ch_name = "tx-sec";
134040476f61SPadmavathi Venna 
134140476f61SPadmavathi Venna 		if (!np) {
134240476f61SPadmavathi Venna 			res = platform_get_resource(pdev, IORESOURCE_DMA, 2);
134340476f61SPadmavathi Venna 			if (res)
134440476f61SPadmavathi Venna 				sec_dai->dma_playback.channel = res->start;
134540476f61SPadmavathi Venna 		}
134640476f61SPadmavathi Venna 
13475033f43cSJassi Brar 		sec_dai->dma_playback.dma_size = 4;
1348af1cf5cfSSylwester Nawrocki 		sec_dai->addr = pri_dai->addr;
13490ec2ba80SSylwester Nawrocki 		sec_dai->clk = pri_dai->clk;
13505033f43cSJassi Brar 		sec_dai->quirks = quirks;
135140476f61SPadmavathi Venna 		sec_dai->idma_playback.dma_addr = idma_addr;
13525033f43cSJassi Brar 		sec_dai->pri_dai = pri_dai;
13535033f43cSJassi Brar 		pri_dai->sec_dai = sec_dai;
13545033f43cSJassi Brar 	}
13555033f43cSJassi Brar 
13560429ffefSMark Brown 	if (i2s_pdata && i2s_pdata->cfg_gpio && i2s_pdata->cfg_gpio(pdev)) {
135740476f61SPadmavathi Venna 		dev_err(&pdev->dev, "Unable to configure gpio\n");
1358af1cf5cfSSylwester Nawrocki 		return -EINVAL;
135940476f61SPadmavathi Venna 	}
13605033f43cSJassi Brar 
1361d644a115SMark Brown 	devm_snd_soc_register_component(&pri_dai->pdev->dev,
1362d644a115SMark Brown 					&samsung_i2s_component,
13634b828535SKuninori Morimoto 					&pri_dai->i2s_dai_drv, 1);
13645033f43cSJassi Brar 
1365c5cf4dbcSMark Brown 	pm_runtime_enable(&pdev->dev);
1366c5cf4dbcSMark Brown 
136753f7faa1SSylwester Nawrocki 	ret = samsung_asoc_dma_platform_register(&pdev->dev);
136853f7faa1SSylwester Nawrocki 	if (ret != 0)
136953f7faa1SSylwester Nawrocki 		return ret;
1370a08485d8SPadmavathi Venna 
1371074b89bbSSylwester Nawrocki 	return i2s_register_clock_provider(pdev);
13725033f43cSJassi Brar }
13735033f43cSJassi Brar 
1374fdca21adSBill Pemberton static int samsung_i2s_remove(struct platform_device *pdev)
13755033f43cSJassi Brar {
13765033f43cSJassi Brar 	struct i2s_dai *i2s, *other;
13775033f43cSJassi Brar 
13785033f43cSJassi Brar 	i2s = dev_get_drvdata(&pdev->dev);
1379dcd60fc3SSylwester Nawrocki 	other = get_other_dai(i2s);
13805033f43cSJassi Brar 
13815033f43cSJassi Brar 	if (other) {
13825033f43cSJassi Brar 		other->pri_dai = NULL;
13835033f43cSJassi Brar 		other->sec_dai = NULL;
13845033f43cSJassi Brar 	} else {
1385c5cf4dbcSMark Brown 		pm_runtime_disable(&pdev->dev);
13865033f43cSJassi Brar 	}
13875033f43cSJassi Brar 
1388074b89bbSSylwester Nawrocki 	if (!is_secondary(i2s)) {
1389074b89bbSSylwester Nawrocki 		i2s_unregister_clock_provider(pdev);
1390c92f1d0eSSylwester Nawrocki 		clk_disable_unprepare(i2s->clk);
1391074b89bbSSylwester Nawrocki 	}
1392c92f1d0eSSylwester Nawrocki 
13935033f43cSJassi Brar 	i2s->pri_dai = NULL;
13945033f43cSJassi Brar 	i2s->sec_dai = NULL;
13955033f43cSJassi Brar 
13965033f43cSJassi Brar 	return 0;
13975033f43cSJassi Brar }
13985033f43cSJassi Brar 
1399a5a56871SPadmavathi Venna static const struct samsung_i2s_variant_regs i2sv3_regs = {
1400a5a56871SPadmavathi Venna 	.bfs_off = 1,
1401a5a56871SPadmavathi Venna 	.rfs_off = 3,
1402a5a56871SPadmavathi Venna 	.sdf_off = 5,
1403a5a56871SPadmavathi Venna 	.txr_off = 8,
1404a5a56871SPadmavathi Venna 	.rclksrc_off = 10,
1405a5a56871SPadmavathi Venna 	.mss_off = 11,
1406a5a56871SPadmavathi Venna 	.cdclkcon_off = 12,
1407a5a56871SPadmavathi Venna 	.lrp_off = 7,
1408a5a56871SPadmavathi Venna 	.bfs_mask = 0x3,
1409a5a56871SPadmavathi Venna 	.rfs_mask = 0x3,
1410a5a56871SPadmavathi Venna 	.ftx0cnt_off = 8,
1411a5a56871SPadmavathi Venna };
1412a5a56871SPadmavathi Venna 
1413a5a56871SPadmavathi Venna static const struct samsung_i2s_variant_regs i2sv6_regs = {
1414a5a56871SPadmavathi Venna 	.bfs_off = 0,
1415a5a56871SPadmavathi Venna 	.rfs_off = 4,
1416a5a56871SPadmavathi Venna 	.sdf_off = 6,
1417a5a56871SPadmavathi Venna 	.txr_off = 8,
1418a5a56871SPadmavathi Venna 	.rclksrc_off = 10,
1419a5a56871SPadmavathi Venna 	.mss_off = 11,
1420a5a56871SPadmavathi Venna 	.cdclkcon_off = 12,
1421a5a56871SPadmavathi Venna 	.lrp_off = 15,
1422a5a56871SPadmavathi Venna 	.bfs_mask = 0xf,
1423a5a56871SPadmavathi Venna 	.rfs_mask = 0x3,
1424a5a56871SPadmavathi Venna 	.ftx0cnt_off = 8,
1425a5a56871SPadmavathi Venna };
1426a5a56871SPadmavathi Venna 
1427a5a56871SPadmavathi Venna static const struct samsung_i2s_variant_regs i2sv7_regs = {
1428a5a56871SPadmavathi Venna 	.bfs_off = 0,
1429a5a56871SPadmavathi Venna 	.rfs_off = 4,
1430a5a56871SPadmavathi Venna 	.sdf_off = 7,
1431a5a56871SPadmavathi Venna 	.txr_off = 9,
1432a5a56871SPadmavathi Venna 	.rclksrc_off = 11,
1433a5a56871SPadmavathi Venna 	.mss_off = 12,
1434a5a56871SPadmavathi Venna 	.cdclkcon_off = 22,
1435a5a56871SPadmavathi Venna 	.lrp_off = 15,
1436a5a56871SPadmavathi Venna 	.bfs_mask = 0xf,
1437a5a56871SPadmavathi Venna 	.rfs_mask = 0x7,
1438a5a56871SPadmavathi Venna 	.ftx0cnt_off = 0,
1439a5a56871SPadmavathi Venna };
1440a5a56871SPadmavathi Venna 
1441a5a56871SPadmavathi Venna static const struct samsung_i2s_variant_regs i2sv5_i2s1_regs = {
1442a5a56871SPadmavathi Venna 	.bfs_off = 0,
1443a5a56871SPadmavathi Venna 	.rfs_off = 3,
1444a5a56871SPadmavathi Venna 	.sdf_off = 6,
1445a5a56871SPadmavathi Venna 	.txr_off = 8,
1446a5a56871SPadmavathi Venna 	.rclksrc_off = 10,
1447a5a56871SPadmavathi Venna 	.mss_off = 11,
1448a5a56871SPadmavathi Venna 	.cdclkcon_off = 12,
1449a5a56871SPadmavathi Venna 	.lrp_off = 15,
1450a5a56871SPadmavathi Venna 	.bfs_mask = 0x7,
1451a5a56871SPadmavathi Venna 	.rfs_mask = 0x7,
1452a5a56871SPadmavathi Venna 	.ftx0cnt_off = 8,
1453a5a56871SPadmavathi Venna };
1454a5a56871SPadmavathi Venna 
14557da493e9SPadmavathi Venna static const struct samsung_i2s_dai_data i2sv3_dai_type = {
14567da493e9SPadmavathi Venna 	.dai_type = TYPE_PRI,
14577da493e9SPadmavathi Venna 	.quirks = QUIRK_NO_MUXPSR,
1458a5a56871SPadmavathi Venna 	.i2s_variant_regs = &i2sv3_regs,
14597da493e9SPadmavathi Venna };
14607da493e9SPadmavathi Venna 
14617da493e9SPadmavathi Venna static const struct samsung_i2s_dai_data i2sv5_dai_type = {
14627da493e9SPadmavathi Venna 	.dai_type = TYPE_PRI,
1463b0759736SPadmavathi Venna 	.quirks = QUIRK_PRI_6CHAN | QUIRK_SEC_DAI | QUIRK_NEED_RSTCLR |
1464b0759736SPadmavathi Venna 			QUIRK_SUPPORTS_IDMA,
1465a5a56871SPadmavathi Venna 	.i2s_variant_regs = &i2sv3_regs,
14667da493e9SPadmavathi Venna };
14677da493e9SPadmavathi Venna 
14684ca0c0d4SPadmavathi Venna static const struct samsung_i2s_dai_data i2sv6_dai_type = {
14694ca0c0d4SPadmavathi Venna 	.dai_type = TYPE_PRI,
14704ca0c0d4SPadmavathi Venna 	.quirks = QUIRK_PRI_6CHAN | QUIRK_SEC_DAI | QUIRK_NEED_RSTCLR |
1471b0759736SPadmavathi Venna 			QUIRK_SUPPORTS_TDM | QUIRK_SUPPORTS_IDMA,
1472a5a56871SPadmavathi Venna 	.i2s_variant_regs = &i2sv6_regs,
1473a5a56871SPadmavathi Venna };
1474a5a56871SPadmavathi Venna 
1475a5a56871SPadmavathi Venna static const struct samsung_i2s_dai_data i2sv7_dai_type = {
1476a5a56871SPadmavathi Venna 	.dai_type = TYPE_PRI,
1477a5a56871SPadmavathi Venna 	.quirks = QUIRK_PRI_6CHAN | QUIRK_SEC_DAI | QUIRK_NEED_RSTCLR |
1478a5a56871SPadmavathi Venna 			QUIRK_SUPPORTS_TDM,
1479a5a56871SPadmavathi Venna 	.i2s_variant_regs = &i2sv7_regs,
1480a5a56871SPadmavathi Venna };
1481a5a56871SPadmavathi Venna 
1482a5a56871SPadmavathi Venna static const struct samsung_i2s_dai_data i2sv5_dai_type_i2s1 = {
1483a5a56871SPadmavathi Venna 	.dai_type = TYPE_PRI,
1484a5a56871SPadmavathi Venna 	.quirks = QUIRK_PRI_6CHAN | QUIRK_NEED_RSTCLR,
1485a5a56871SPadmavathi Venna 	.i2s_variant_regs = &i2sv5_i2s1_regs,
14864ca0c0d4SPadmavathi Venna };
14874ca0c0d4SPadmavathi Venna 
14887da493e9SPadmavathi Venna static const struct samsung_i2s_dai_data samsung_dai_type_pri = {
14897da493e9SPadmavathi Venna 	.dai_type = TYPE_PRI,
14907da493e9SPadmavathi Venna };
14917da493e9SPadmavathi Venna 
14927da493e9SPadmavathi Venna static const struct samsung_i2s_dai_data samsung_dai_type_sec = {
14937da493e9SPadmavathi Venna 	.dai_type = TYPE_SEC,
14947da493e9SPadmavathi Venna };
14957da493e9SPadmavathi Venna 
1496*eb8ca0faSKrzysztof Kozlowski static const struct platform_device_id samsung_i2s_driver_ids[] = {
14977c62eebbSPadmavathi Venna 	{
14987c62eebbSPadmavathi Venna 		.name           = "samsung-i2s",
14993f024980SMark Brown 		.driver_data	= (kernel_ulong_t)&i2sv3_dai_type,
15007c62eebbSPadmavathi Venna 	}, {
15017c62eebbSPadmavathi Venna 		.name           = "samsung-i2s-sec",
15027da493e9SPadmavathi Venna 		.driver_data    = (kernel_ulong_t)&samsung_dai_type_sec,
15033f024980SMark Brown 	}, {
15043f024980SMark Brown 		.name		= "samsung-i2sv4",
15053f024980SMark Brown 		.driver_data	= (kernel_ulong_t)&i2sv5_dai_type,
15067c62eebbSPadmavathi Venna 	},
15077c62eebbSPadmavathi Venna 	{},
15087c62eebbSPadmavathi Venna };
15092af19558SArnd Bergmann MODULE_DEVICE_TABLE(platform, samsung_i2s_driver_ids);
15107c62eebbSPadmavathi Venna 
151140476f61SPadmavathi Venna #ifdef CONFIG_OF
151240476f61SPadmavathi Venna static const struct of_device_id exynos_i2s_match[] = {
15137da493e9SPadmavathi Venna 	{
15147da493e9SPadmavathi Venna 		.compatible = "samsung,s3c6410-i2s",
15157da493e9SPadmavathi Venna 		.data = &i2sv3_dai_type,
15167da493e9SPadmavathi Venna 	}, {
15177da493e9SPadmavathi Venna 		.compatible = "samsung,s5pv210-i2s",
15187da493e9SPadmavathi Venna 		.data = &i2sv5_dai_type,
15194ca0c0d4SPadmavathi Venna 	}, {
15204ca0c0d4SPadmavathi Venna 		.compatible = "samsung,exynos5420-i2s",
15214ca0c0d4SPadmavathi Venna 		.data = &i2sv6_dai_type,
1522a5a56871SPadmavathi Venna 	}, {
1523a5a56871SPadmavathi Venna 		.compatible = "samsung,exynos7-i2s",
1524a5a56871SPadmavathi Venna 		.data = &i2sv7_dai_type,
1525a5a56871SPadmavathi Venna 	}, {
1526a5a56871SPadmavathi Venna 		.compatible = "samsung,exynos7-i2s1",
1527a5a56871SPadmavathi Venna 		.data = &i2sv5_dai_type_i2s1,
152840476f61SPadmavathi Venna 	},
152940476f61SPadmavathi Venna 	{},
153040476f61SPadmavathi Venna };
153140476f61SPadmavathi Venna MODULE_DEVICE_TABLE(of, exynos_i2s_match);
153240476f61SPadmavathi Venna #endif
153340476f61SPadmavathi Venna 
15345b1d3c34SR. Chandrasekar static const struct dev_pm_ops samsung_i2s_pm = {
15355b1d3c34SR. Chandrasekar 	SET_RUNTIME_PM_OPS(i2s_runtime_suspend,
15365b1d3c34SR. Chandrasekar 				i2s_runtime_resume, NULL)
15375b1d3c34SR. Chandrasekar };
15385b1d3c34SR. Chandrasekar 
15395033f43cSJassi Brar static struct platform_driver samsung_i2s_driver = {
15405033f43cSJassi Brar 	.probe  = samsung_i2s_probe,
1541fdca21adSBill Pemberton 	.remove = samsung_i2s_remove,
15427c62eebbSPadmavathi Venna 	.id_table = samsung_i2s_driver_ids,
15435033f43cSJassi Brar 	.driver = {
15445033f43cSJassi Brar 		.name = "samsung-i2s",
154540476f61SPadmavathi Venna 		.of_match_table = of_match_ptr(exynos_i2s_match),
15465b1d3c34SR. Chandrasekar 		.pm = &samsung_i2s_pm,
15475033f43cSJassi Brar 	},
15485033f43cSJassi Brar };
15495033f43cSJassi Brar 
1550e00c3f55SMark Brown module_platform_driver(samsung_i2s_driver);
15515033f43cSJassi Brar 
15525033f43cSJassi Brar /* Module information */
1553df8ad335SJaswinder Singh MODULE_AUTHOR("Jaswinder Singh, <jassisinghbrar@gmail.com>");
15545033f43cSJassi Brar MODULE_DESCRIPTION("Samsung I2S Interface");
15555033f43cSJassi Brar MODULE_ALIAS("platform:samsung-i2s");
15565033f43cSJassi Brar MODULE_LICENSE("GPL");
1557