xref: /linux/sound/soc/samsung/i2s.c (revision f36705366a2324fedd6cca7683fadf947ac0b154)
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 
135033f43cSJassi Brar #include <linux/delay.h>
145033f43cSJassi Brar #include <linux/slab.h>
155033f43cSJassi Brar #include <linux/clk.h>
165033f43cSJassi Brar #include <linux/io.h>
17da155d5bSPaul Gortmaker #include <linux/module.h>
1840476f61SPadmavathi Venna #include <linux/of.h>
1940476f61SPadmavathi Venna #include <linux/of_gpio.h>
20c5cf4dbcSMark Brown #include <linux/pm_runtime.h>
215033f43cSJassi Brar 
225033f43cSJassi Brar #include <sound/soc.h>
230378b6acSSeungwhan Youn #include <sound/pcm_params.h>
245033f43cSJassi Brar 
25436d42c6SArnd Bergmann #include <linux/platform_data/asoc-s3c.h>
265033f43cSJassi Brar 
275033f43cSJassi Brar #include "dma.h"
2861100f40SSangbeom Kim #include "idma.h"
295033f43cSJassi Brar #include "i2s.h"
30172a453dSSangbeom Kim #include "i2s-regs.h"
315033f43cSJassi Brar 
325033f43cSJassi Brar #define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t)
335033f43cSJassi Brar 
347c62eebbSPadmavathi Venna enum samsung_dai_type {
357c62eebbSPadmavathi Venna 	TYPE_PRI,
367c62eebbSPadmavathi Venna 	TYPE_SEC,
377c62eebbSPadmavathi Venna };
387c62eebbSPadmavathi Venna 
39a5a56871SPadmavathi Venna struct samsung_i2s_variant_regs {
40a5a56871SPadmavathi Venna 	unsigned int	bfs_off;
41a5a56871SPadmavathi Venna 	unsigned int	rfs_off;
42a5a56871SPadmavathi Venna 	unsigned int	sdf_off;
43a5a56871SPadmavathi Venna 	unsigned int	txr_off;
44a5a56871SPadmavathi Venna 	unsigned int	rclksrc_off;
45a5a56871SPadmavathi Venna 	unsigned int	mss_off;
46a5a56871SPadmavathi Venna 	unsigned int	cdclkcon_off;
47a5a56871SPadmavathi Venna 	unsigned int	lrp_off;
48a5a56871SPadmavathi Venna 	unsigned int	bfs_mask;
49a5a56871SPadmavathi Venna 	unsigned int	rfs_mask;
50a5a56871SPadmavathi Venna 	unsigned int	ftx0cnt_off;
51a5a56871SPadmavathi Venna };
52a5a56871SPadmavathi Venna 
5340476f61SPadmavathi Venna struct samsung_i2s_dai_data {
5440476f61SPadmavathi Venna 	int dai_type;
557da493e9SPadmavathi Venna 	u32 quirks;
56a5a56871SPadmavathi Venna 	const struct samsung_i2s_variant_regs *i2s_variant_regs;
5740476f61SPadmavathi Venna };
5840476f61SPadmavathi Venna 
595033f43cSJassi Brar struct i2s_dai {
605033f43cSJassi Brar 	/* Platform device for this DAI */
615033f43cSJassi Brar 	struct platform_device *pdev;
62af1cf5cfSSylwester Nawrocki 	/* Memory mapped SFR region */
635033f43cSJassi Brar 	void __iomem	*addr;
645033f43cSJassi Brar 	/* Rate of RCLK source clock */
655033f43cSJassi Brar 	unsigned long rclk_srcrate;
665033f43cSJassi Brar 	/* Frame Clock */
675033f43cSJassi Brar 	unsigned frmclk;
685033f43cSJassi Brar 	/*
695033f43cSJassi Brar 	 * Specifically requested RCLK,BCLK by MACHINE Driver.
705033f43cSJassi Brar 	 * 0 indicates CPU driver is free to choose any value.
715033f43cSJassi Brar 	 */
725033f43cSJassi Brar 	unsigned rfs, bfs;
735033f43cSJassi Brar 	/* I2S Controller's core clock */
745033f43cSJassi Brar 	struct clk *clk;
755033f43cSJassi Brar 	/* Clock for generating I2S signals */
765033f43cSJassi Brar 	struct clk *op_clk;
775033f43cSJassi Brar 	/* Pointer to the Primary_Fifo if this is Sec_Fifo, NULL otherwise */
785033f43cSJassi Brar 	struct i2s_dai *pri_dai;
795033f43cSJassi Brar 	/* Pointer to the Secondary_Fifo if it has one, NULL otherwise */
805033f43cSJassi Brar 	struct i2s_dai *sec_dai;
815033f43cSJassi Brar #define DAI_OPENED	(1 << 0) /* Dai is opened */
825033f43cSJassi Brar #define DAI_MANAGER	(1 << 1) /* Dai is the manager */
835033f43cSJassi Brar 	unsigned mode;
84b97c60abSSylwester Nawrocki 	/* CDCLK pin direction: 0  - input, 1 - output */
85b97c60abSSylwester Nawrocki 	unsigned int cdclk_out:1;
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;
97*f3670536SSylwester Nawrocki 
98*f3670536SSylwester Nawrocki 	/* Spinlock protecting access to the device's registers */
99*f3670536SSylwester Nawrocki 	spinlock_t spinlock;
100*f3670536SSylwester Nawrocki 	spinlock_t *lock;
1015033f43cSJassi Brar };
1025033f43cSJassi Brar 
1035033f43cSJassi Brar /* Lock for cross i/f checks */
1045033f43cSJassi Brar static DEFINE_SPINLOCK(lock);
1055033f43cSJassi Brar 
1065033f43cSJassi Brar /* If this is the 'overlay' stereo DAI */
1075033f43cSJassi Brar static inline bool is_secondary(struct i2s_dai *i2s)
1085033f43cSJassi Brar {
1095033f43cSJassi Brar 	return i2s->pri_dai ? true : false;
1105033f43cSJassi Brar }
1115033f43cSJassi Brar 
1125033f43cSJassi Brar /* If operating in SoC-Slave mode */
1135033f43cSJassi Brar static inline bool is_slave(struct i2s_dai *i2s)
1145033f43cSJassi Brar {
115a5a56871SPadmavathi Venna 	u32 mod = readl(i2s->addr + I2SMOD);
116a5a56871SPadmavathi Venna 	return (mod & (1 << i2s->variant_regs->mss_off)) ? true : false;
1175033f43cSJassi Brar }
1185033f43cSJassi Brar 
1195033f43cSJassi Brar /* If this interface of the controller is transmitting data */
1205033f43cSJassi Brar static inline bool tx_active(struct i2s_dai *i2s)
1215033f43cSJassi Brar {
1225033f43cSJassi Brar 	u32 active;
1235033f43cSJassi Brar 
1245033f43cSJassi Brar 	if (!i2s)
1255033f43cSJassi Brar 		return false;
1265033f43cSJassi Brar 
12733195500SSangbeom Kim 	active = readl(i2s->addr + I2SCON);
1285033f43cSJassi Brar 
1295033f43cSJassi Brar 	if (is_secondary(i2s))
1305033f43cSJassi Brar 		active &= CON_TXSDMA_ACTIVE;
1315033f43cSJassi Brar 	else
1325033f43cSJassi Brar 		active &= CON_TXDMA_ACTIVE;
1335033f43cSJassi Brar 
1345033f43cSJassi Brar 	return active ? true : false;
1355033f43cSJassi Brar }
1365033f43cSJassi Brar 
137dcd60fc3SSylwester Nawrocki /* Return pointer to the other DAI */
138dcd60fc3SSylwester Nawrocki static inline struct i2s_dai *get_other_dai(struct i2s_dai *i2s)
139dcd60fc3SSylwester Nawrocki {
140dcd60fc3SSylwester Nawrocki 	return i2s->pri_dai ? : i2s->sec_dai;
141dcd60fc3SSylwester Nawrocki }
142dcd60fc3SSylwester Nawrocki 
1435033f43cSJassi Brar /* If the other interface of the controller is transmitting data */
1445033f43cSJassi Brar static inline bool other_tx_active(struct i2s_dai *i2s)
1455033f43cSJassi Brar {
146dcd60fc3SSylwester Nawrocki 	struct i2s_dai *other = get_other_dai(i2s);
1475033f43cSJassi Brar 
1485033f43cSJassi Brar 	return tx_active(other);
1495033f43cSJassi Brar }
1505033f43cSJassi Brar 
1515033f43cSJassi Brar /* If any interface of the controller is transmitting data */
1525033f43cSJassi Brar static inline bool any_tx_active(struct i2s_dai *i2s)
1535033f43cSJassi Brar {
1545033f43cSJassi Brar 	return tx_active(i2s) || other_tx_active(i2s);
1555033f43cSJassi Brar }
1565033f43cSJassi Brar 
1575033f43cSJassi Brar /* If this interface of the controller is receiving data */
1585033f43cSJassi Brar static inline bool rx_active(struct i2s_dai *i2s)
1595033f43cSJassi Brar {
1605033f43cSJassi Brar 	u32 active;
1615033f43cSJassi Brar 
1625033f43cSJassi Brar 	if (!i2s)
1635033f43cSJassi Brar 		return false;
1645033f43cSJassi Brar 
16533195500SSangbeom Kim 	active = readl(i2s->addr + I2SCON) & CON_RXDMA_ACTIVE;
1665033f43cSJassi Brar 
1675033f43cSJassi Brar 	return active ? true : false;
1685033f43cSJassi Brar }
1695033f43cSJassi Brar 
1705033f43cSJassi Brar /* If the other interface of the controller is receiving data */
1715033f43cSJassi Brar static inline bool other_rx_active(struct i2s_dai *i2s)
1725033f43cSJassi Brar {
173dcd60fc3SSylwester Nawrocki 	struct i2s_dai *other = get_other_dai(i2s);
1745033f43cSJassi Brar 
1755033f43cSJassi Brar 	return rx_active(other);
1765033f43cSJassi Brar }
1775033f43cSJassi Brar 
1785033f43cSJassi Brar /* If any interface of the controller is receiving data */
1795033f43cSJassi Brar static inline bool any_rx_active(struct i2s_dai *i2s)
1805033f43cSJassi Brar {
1815033f43cSJassi Brar 	return rx_active(i2s) || other_rx_active(i2s);
1825033f43cSJassi Brar }
1835033f43cSJassi Brar 
1845033f43cSJassi Brar /* If the other DAI is transmitting or receiving data */
1855033f43cSJassi Brar static inline bool other_active(struct i2s_dai *i2s)
1865033f43cSJassi Brar {
1875033f43cSJassi Brar 	return other_rx_active(i2s) || other_tx_active(i2s);
1885033f43cSJassi Brar }
1895033f43cSJassi Brar 
1905033f43cSJassi Brar /* If this DAI is transmitting or receiving data */
1915033f43cSJassi Brar static inline bool this_active(struct i2s_dai *i2s)
1925033f43cSJassi Brar {
1935033f43cSJassi Brar 	return tx_active(i2s) || rx_active(i2s);
1945033f43cSJassi Brar }
1955033f43cSJassi Brar 
1965033f43cSJassi Brar /* If the controller is active anyway */
1975033f43cSJassi Brar static inline bool any_active(struct i2s_dai *i2s)
1985033f43cSJassi Brar {
1995033f43cSJassi Brar 	return this_active(i2s) || other_active(i2s);
2005033f43cSJassi Brar }
2015033f43cSJassi Brar 
2025033f43cSJassi Brar static inline struct i2s_dai *to_info(struct snd_soc_dai *dai)
2035033f43cSJassi Brar {
2045033f43cSJassi Brar 	return snd_soc_dai_get_drvdata(dai);
2055033f43cSJassi Brar }
2065033f43cSJassi Brar 
2075033f43cSJassi Brar static inline bool is_opened(struct i2s_dai *i2s)
2085033f43cSJassi Brar {
2095033f43cSJassi Brar 	if (i2s && (i2s->mode & DAI_OPENED))
2105033f43cSJassi Brar 		return true;
2115033f43cSJassi Brar 	else
2125033f43cSJassi Brar 		return false;
2135033f43cSJassi Brar }
2145033f43cSJassi Brar 
2155033f43cSJassi Brar static inline bool is_manager(struct i2s_dai *i2s)
2165033f43cSJassi Brar {
2175033f43cSJassi Brar 	if (is_opened(i2s) && (i2s->mode & DAI_MANAGER))
2185033f43cSJassi Brar 		return true;
2195033f43cSJassi Brar 	else
2205033f43cSJassi Brar 		return false;
2215033f43cSJassi Brar }
2225033f43cSJassi Brar 
2235033f43cSJassi Brar /* Read RCLK of I2S (in multiples of LRCLK) */
2245033f43cSJassi Brar static inline unsigned get_rfs(struct i2s_dai *i2s)
2255033f43cSJassi Brar {
2264ca0c0d4SPadmavathi Venna 	u32 rfs;
227a5a56871SPadmavathi Venna 	rfs = readl(i2s->addr + I2SMOD) >> i2s->variant_regs->rfs_off;
228a5a56871SPadmavathi Venna 	rfs &= i2s->variant_regs->rfs_mask;
2295033f43cSJassi Brar 
2305033f43cSJassi Brar 	switch (rfs) {
231a5a56871SPadmavathi Venna 	case 7: return 192;
232a5a56871SPadmavathi Venna 	case 6: return 96;
233a5a56871SPadmavathi Venna 	case 5: return 128;
234a5a56871SPadmavathi Venna 	case 4: return 64;
2355033f43cSJassi Brar 	case 3:	return 768;
2365033f43cSJassi Brar 	case 2: return 384;
2375033f43cSJassi Brar 	case 1:	return 512;
2385033f43cSJassi Brar 	default: return 256;
2395033f43cSJassi Brar 	}
2405033f43cSJassi Brar }
2415033f43cSJassi Brar 
2425033f43cSJassi Brar /* Write RCLK of I2S (in multiples of LRCLK) */
2435033f43cSJassi Brar static inline void set_rfs(struct i2s_dai *i2s, unsigned rfs)
2445033f43cSJassi Brar {
2455033f43cSJassi Brar 	u32 mod = readl(i2s->addr + I2SMOD);
246a5a56871SPadmavathi Venna 	int rfs_shift = i2s->variant_regs->rfs_off;
2475033f43cSJassi Brar 
248a5a56871SPadmavathi Venna 	mod &= ~(i2s->variant_regs->rfs_mask << rfs_shift);
2495033f43cSJassi Brar 
2505033f43cSJassi Brar 	switch (rfs) {
251a5a56871SPadmavathi Venna 	case 192:
252a5a56871SPadmavathi Venna 		mod |= (EXYNOS7_MOD_RCLK_192FS << rfs_shift);
253a5a56871SPadmavathi Venna 		break;
254a5a56871SPadmavathi Venna 	case 96:
255a5a56871SPadmavathi Venna 		mod |= (EXYNOS7_MOD_RCLK_96FS << rfs_shift);
256a5a56871SPadmavathi Venna 		break;
257a5a56871SPadmavathi Venna 	case 128:
258a5a56871SPadmavathi Venna 		mod |= (EXYNOS7_MOD_RCLK_128FS << rfs_shift);
259a5a56871SPadmavathi Venna 		break;
260a5a56871SPadmavathi Venna 	case 64:
261a5a56871SPadmavathi Venna 		mod |= (EXYNOS7_MOD_RCLK_64FS << rfs_shift);
262a5a56871SPadmavathi Venna 		break;
2635033f43cSJassi Brar 	case 768:
264b60be4aaSPadmavathi Venna 		mod |= (MOD_RCLK_768FS << rfs_shift);
2655033f43cSJassi Brar 		break;
2665033f43cSJassi Brar 	case 512:
267b60be4aaSPadmavathi Venna 		mod |= (MOD_RCLK_512FS << rfs_shift);
2685033f43cSJassi Brar 		break;
2695033f43cSJassi Brar 	case 384:
270b60be4aaSPadmavathi Venna 		mod |= (MOD_RCLK_384FS << rfs_shift);
2715033f43cSJassi Brar 		break;
2725033f43cSJassi Brar 	default:
273b60be4aaSPadmavathi Venna 		mod |= (MOD_RCLK_256FS << rfs_shift);
2745033f43cSJassi Brar 		break;
2755033f43cSJassi Brar 	}
2765033f43cSJassi Brar 
2775033f43cSJassi Brar 	writel(mod, i2s->addr + I2SMOD);
2785033f43cSJassi Brar }
2795033f43cSJassi Brar 
2805033f43cSJassi Brar /* Read Bit-Clock of I2S (in multiples of LRCLK) */
2815033f43cSJassi Brar static inline unsigned get_bfs(struct i2s_dai *i2s)
2825033f43cSJassi Brar {
2834ca0c0d4SPadmavathi Venna 	u32 bfs;
284a5a56871SPadmavathi Venna 	bfs = readl(i2s->addr + I2SMOD) >> i2s->variant_regs->bfs_off;
285a5a56871SPadmavathi Venna 	bfs &= i2s->variant_regs->bfs_mask;
2865033f43cSJassi Brar 
2875033f43cSJassi Brar 	switch (bfs) {
2884ca0c0d4SPadmavathi Venna 	case 8: return 256;
2894ca0c0d4SPadmavathi Venna 	case 7: return 192;
2904ca0c0d4SPadmavathi Venna 	case 6: return 128;
2914ca0c0d4SPadmavathi Venna 	case 5: return 96;
2924ca0c0d4SPadmavathi Venna 	case 4: return 64;
2935033f43cSJassi Brar 	case 3: return 24;
2945033f43cSJassi Brar 	case 2: return 16;
2955033f43cSJassi Brar 	case 1:	return 48;
2965033f43cSJassi Brar 	default: return 32;
2975033f43cSJassi Brar 	}
2985033f43cSJassi Brar }
2995033f43cSJassi Brar 
3005033f43cSJassi Brar /* Write Bit-Clock of I2S (in multiples of LRCLK) */
3015033f43cSJassi Brar static inline void set_bfs(struct i2s_dai *i2s, unsigned bfs)
3025033f43cSJassi Brar {
3035033f43cSJassi Brar 	u32 mod = readl(i2s->addr + I2SMOD);
3044ca0c0d4SPadmavathi Venna 	int tdm = i2s->quirks & QUIRK_SUPPORTS_TDM;
305a5a56871SPadmavathi Venna 	int bfs_shift = i2s->variant_regs->bfs_off;
3064ca0c0d4SPadmavathi Venna 
3074ca0c0d4SPadmavathi Venna 	/* Non-TDM I2S controllers do not support BCLK > 48 * FS */
3084ca0c0d4SPadmavathi Venna 	if (!tdm && bfs > 48) {
3094ca0c0d4SPadmavathi Venna 		dev_err(&i2s->pdev->dev, "Unsupported BCLK divider\n");
3104ca0c0d4SPadmavathi Venna 		return;
3114ca0c0d4SPadmavathi Venna 	}
3125033f43cSJassi Brar 
313a5a56871SPadmavathi Venna 	mod &= ~(i2s->variant_regs->bfs_mask << bfs_shift);
314a5a56871SPadmavathi Venna 
3155033f43cSJassi Brar 	switch (bfs) {
3165033f43cSJassi Brar 	case 48:
317b60be4aaSPadmavathi Venna 		mod |= (MOD_BCLK_48FS << bfs_shift);
3185033f43cSJassi Brar 		break;
3195033f43cSJassi Brar 	case 32:
320b60be4aaSPadmavathi Venna 		mod |= (MOD_BCLK_32FS << bfs_shift);
3215033f43cSJassi Brar 		break;
3225033f43cSJassi Brar 	case 24:
323b60be4aaSPadmavathi Venna 		mod |= (MOD_BCLK_24FS << bfs_shift);
3245033f43cSJassi Brar 		break;
3255033f43cSJassi Brar 	case 16:
326b60be4aaSPadmavathi Venna 		mod |= (MOD_BCLK_16FS << bfs_shift);
3275033f43cSJassi Brar 		break;
3284ca0c0d4SPadmavathi Venna 	case 64:
3294ca0c0d4SPadmavathi Venna 		mod |= (EXYNOS5420_MOD_BCLK_64FS << bfs_shift);
3304ca0c0d4SPadmavathi Venna 		break;
3314ca0c0d4SPadmavathi Venna 	case 96:
3324ca0c0d4SPadmavathi Venna 		mod |= (EXYNOS5420_MOD_BCLK_96FS << bfs_shift);
3334ca0c0d4SPadmavathi Venna 		break;
3344ca0c0d4SPadmavathi Venna 	case 128:
3354ca0c0d4SPadmavathi Venna 		mod |= (EXYNOS5420_MOD_BCLK_128FS << bfs_shift);
3364ca0c0d4SPadmavathi Venna 		break;
3374ca0c0d4SPadmavathi Venna 	case 192:
3384ca0c0d4SPadmavathi Venna 		mod |= (EXYNOS5420_MOD_BCLK_192FS << bfs_shift);
3394ca0c0d4SPadmavathi Venna 		break;
3404ca0c0d4SPadmavathi Venna 	case 256:
3414ca0c0d4SPadmavathi Venna 		mod |= (EXYNOS5420_MOD_BCLK_256FS << bfs_shift);
3425033f43cSJassi Brar 		break;
3435033f43cSJassi Brar 	default:
3445033f43cSJassi Brar 		dev_err(&i2s->pdev->dev, "Wrong BCLK Divider!\n");
3455033f43cSJassi Brar 		return;
3465033f43cSJassi Brar 	}
3475033f43cSJassi Brar 
3485033f43cSJassi Brar 	writel(mod, i2s->addr + I2SMOD);
3495033f43cSJassi Brar }
3505033f43cSJassi Brar 
3515033f43cSJassi Brar /* Sample-Size */
3525033f43cSJassi Brar static inline int get_blc(struct i2s_dai *i2s)
3535033f43cSJassi Brar {
3545033f43cSJassi Brar 	int blc = readl(i2s->addr + I2SMOD);
3555033f43cSJassi Brar 
3565033f43cSJassi Brar 	blc = (blc >> 13) & 0x3;
3575033f43cSJassi Brar 
3585033f43cSJassi Brar 	switch (blc) {
3595033f43cSJassi Brar 	case 2: return 24;
3605033f43cSJassi Brar 	case 1:	return 8;
3615033f43cSJassi Brar 	default: return 16;
3625033f43cSJassi Brar 	}
3635033f43cSJassi Brar }
3645033f43cSJassi Brar 
3655033f43cSJassi Brar /* TX Channel Control */
3665033f43cSJassi Brar static void i2s_txctrl(struct i2s_dai *i2s, int on)
3675033f43cSJassi Brar {
3685033f43cSJassi Brar 	void __iomem *addr = i2s->addr;
369a5a56871SPadmavathi Venna 	int txr_off = i2s->variant_regs->txr_off;
3705033f43cSJassi Brar 	u32 con = readl(addr + I2SCON);
371a5a56871SPadmavathi Venna 	u32 mod = readl(addr + I2SMOD) & ~(3 << txr_off);
3725033f43cSJassi Brar 
3735033f43cSJassi Brar 	if (on) {
3745033f43cSJassi Brar 		con |= CON_ACTIVE;
3755033f43cSJassi Brar 		con &= ~CON_TXCH_PAUSE;
3765033f43cSJassi Brar 
3775033f43cSJassi Brar 		if (is_secondary(i2s)) {
3785033f43cSJassi Brar 			con |= CON_TXSDMA_ACTIVE;
3795033f43cSJassi Brar 			con &= ~CON_TXSDMA_PAUSE;
3805033f43cSJassi Brar 		} else {
3815033f43cSJassi Brar 			con |= CON_TXDMA_ACTIVE;
3825033f43cSJassi Brar 			con &= ~CON_TXDMA_PAUSE;
3835033f43cSJassi Brar 		}
3845033f43cSJassi Brar 
3855033f43cSJassi Brar 		if (any_rx_active(i2s))
386a5a56871SPadmavathi Venna 			mod |= 2 << txr_off;
3875033f43cSJassi Brar 		else
388a5a56871SPadmavathi Venna 			mod |= 0 << txr_off;
3895033f43cSJassi Brar 	} else {
3905033f43cSJassi Brar 		if (is_secondary(i2s)) {
3915033f43cSJassi Brar 			con |=  CON_TXSDMA_PAUSE;
3925033f43cSJassi Brar 			con &= ~CON_TXSDMA_ACTIVE;
3935033f43cSJassi Brar 		} else {
3945033f43cSJassi Brar 			con |=  CON_TXDMA_PAUSE;
3955033f43cSJassi Brar 			con &= ~CON_TXDMA_ACTIVE;
3965033f43cSJassi Brar 		}
3975033f43cSJassi Brar 
3985033f43cSJassi Brar 		if (other_tx_active(i2s)) {
3995033f43cSJassi Brar 			writel(con, addr + I2SCON);
4005033f43cSJassi Brar 			return;
4015033f43cSJassi Brar 		}
4025033f43cSJassi Brar 
4035033f43cSJassi Brar 		con |=  CON_TXCH_PAUSE;
4045033f43cSJassi Brar 
4055033f43cSJassi Brar 		if (any_rx_active(i2s))
406a5a56871SPadmavathi Venna 			mod |= 1 << txr_off;
4075033f43cSJassi Brar 		else
4085033f43cSJassi Brar 			con &= ~CON_ACTIVE;
4095033f43cSJassi Brar 	}
4105033f43cSJassi Brar 
4115033f43cSJassi Brar 	writel(mod, addr + I2SMOD);
4125033f43cSJassi Brar 	writel(con, addr + I2SCON);
4135033f43cSJassi Brar }
4145033f43cSJassi Brar 
4155033f43cSJassi Brar /* RX Channel Control */
4165033f43cSJassi Brar static void i2s_rxctrl(struct i2s_dai *i2s, int on)
4175033f43cSJassi Brar {
4185033f43cSJassi Brar 	void __iomem *addr = i2s->addr;
419a5a56871SPadmavathi Venna 	int txr_off = i2s->variant_regs->txr_off;
4205033f43cSJassi Brar 	u32 con = readl(addr + I2SCON);
421a5a56871SPadmavathi Venna 	u32 mod = readl(addr + I2SMOD) & ~(3 << txr_off);
4225033f43cSJassi Brar 
4235033f43cSJassi Brar 	if (on) {
4245033f43cSJassi Brar 		con |= CON_RXDMA_ACTIVE | CON_ACTIVE;
4255033f43cSJassi Brar 		con &= ~(CON_RXDMA_PAUSE | CON_RXCH_PAUSE);
4265033f43cSJassi Brar 
4275033f43cSJassi Brar 		if (any_tx_active(i2s))
428a5a56871SPadmavathi Venna 			mod |= 2 << txr_off;
4295033f43cSJassi Brar 		else
430a5a56871SPadmavathi Venna 			mod |= 1 << txr_off;
4315033f43cSJassi Brar 	} else {
4325033f43cSJassi Brar 		con |=  CON_RXDMA_PAUSE | CON_RXCH_PAUSE;
4335033f43cSJassi Brar 		con &= ~CON_RXDMA_ACTIVE;
4345033f43cSJassi Brar 
4355033f43cSJassi Brar 		if (any_tx_active(i2s))
436a5a56871SPadmavathi Venna 			mod |= 0 << txr_off;
4375033f43cSJassi Brar 		else
4385033f43cSJassi Brar 			con &= ~CON_ACTIVE;
4395033f43cSJassi Brar 	}
4405033f43cSJassi Brar 
4415033f43cSJassi Brar 	writel(mod, addr + I2SMOD);
4425033f43cSJassi Brar 	writel(con, addr + I2SCON);
4435033f43cSJassi Brar }
4445033f43cSJassi Brar 
4455033f43cSJassi Brar /* Flush FIFO of an interface */
4465033f43cSJassi Brar static inline void i2s_fifo(struct i2s_dai *i2s, u32 flush)
4475033f43cSJassi Brar {
4485033f43cSJassi Brar 	void __iomem *fic;
4495033f43cSJassi Brar 	u32 val;
4505033f43cSJassi Brar 
4515033f43cSJassi Brar 	if (!i2s)
4525033f43cSJassi Brar 		return;
4535033f43cSJassi Brar 
4545033f43cSJassi Brar 	if (is_secondary(i2s))
4555033f43cSJassi Brar 		fic = i2s->addr + I2SFICS;
4565033f43cSJassi Brar 	else
4575033f43cSJassi Brar 		fic = i2s->addr + I2SFIC;
4585033f43cSJassi Brar 
4595033f43cSJassi Brar 	/* Flush the FIFO */
4605033f43cSJassi Brar 	writel(readl(fic) | flush, fic);
4615033f43cSJassi Brar 
4625033f43cSJassi Brar 	/* Be patient */
4635033f43cSJassi Brar 	val = msecs_to_loops(1) / 1000; /* 1 usec */
4645033f43cSJassi Brar 	while (--val)
4655033f43cSJassi Brar 		cpu_relax();
4665033f43cSJassi Brar 
4675033f43cSJassi Brar 	writel(readl(fic) & ~flush, fic);
4685033f43cSJassi Brar }
4695033f43cSJassi Brar 
4705033f43cSJassi Brar static int i2s_set_sysclk(struct snd_soc_dai *dai,
4715033f43cSJassi Brar 	  int clk_id, unsigned int rfs, int dir)
4725033f43cSJassi Brar {
4735033f43cSJassi Brar 	struct i2s_dai *i2s = to_info(dai);
474dcd60fc3SSylwester Nawrocki 	struct i2s_dai *other = get_other_dai(i2s);
4755033f43cSJassi Brar 	u32 mod = readl(i2s->addr + I2SMOD);
476a5a56871SPadmavathi Venna 	const struct samsung_i2s_variant_regs *i2s_regs = i2s->variant_regs;
477a5a56871SPadmavathi Venna 	unsigned int cdcon_mask = 1 << i2s_regs->cdclkcon_off;
478a5a56871SPadmavathi Venna 	unsigned int rsrc_mask = 1 << i2s_regs->rclksrc_off;
4795033f43cSJassi Brar 
4805033f43cSJassi Brar 	switch (clk_id) {
481c86d50f9SSylwester Nawrocki 	case SAMSUNG_I2S_OPCLK:
482c86d50f9SSylwester Nawrocki 		mod &= ~MOD_OPCLK_MASK;
483c86d50f9SSylwester Nawrocki 		mod |= dir;
484c86d50f9SSylwester Nawrocki 		break;
4855033f43cSJassi Brar 	case SAMSUNG_I2S_CDCLK:
4865033f43cSJassi Brar 		/* Shouldn't matter in GATING(CLOCK_IN) mode */
4875033f43cSJassi Brar 		if (dir == SND_SOC_CLOCK_IN)
4885033f43cSJassi Brar 			rfs = 0;
4895033f43cSJassi Brar 
490133c2681SCharles Keepax 		if ((rfs && other && other->rfs && (other->rfs != rfs)) ||
4915033f43cSJassi Brar 				(any_active(i2s) &&
4925033f43cSJassi Brar 				(((dir == SND_SOC_CLOCK_IN)
493a5a56871SPadmavathi Venna 					&& !(mod & cdcon_mask)) ||
4945033f43cSJassi Brar 				((dir == SND_SOC_CLOCK_OUT)
495a5a56871SPadmavathi Venna 					&& (mod & cdcon_mask))))) {
4965033f43cSJassi Brar 			dev_err(&i2s->pdev->dev,
4975033f43cSJassi Brar 				"%s:%d Other DAI busy\n", __func__, __LINE__);
4985033f43cSJassi Brar 			return -EAGAIN;
4995033f43cSJassi Brar 		}
5005033f43cSJassi Brar 
5015033f43cSJassi Brar 		if (dir == SND_SOC_CLOCK_IN)
502a5a56871SPadmavathi Venna 			mod |= 1 << i2s_regs->cdclkcon_off;
5035033f43cSJassi Brar 		else
504b2de1d20SPadmavathi Venna 			mod &= ~(1 << i2s_regs->cdclkcon_off);
5055033f43cSJassi Brar 
5065033f43cSJassi Brar 		i2s->rfs = rfs;
5075033f43cSJassi Brar 		break;
5085033f43cSJassi Brar 
5095033f43cSJassi Brar 	case SAMSUNG_I2S_RCLKSRC_0: /* clock corrsponding to IISMOD[10] := 0 */
5105033f43cSJassi Brar 	case SAMSUNG_I2S_RCLKSRC_1: /* clock corrsponding to IISMOD[10] := 1 */
5115033f43cSJassi Brar 		if ((i2s->quirks & QUIRK_NO_MUXPSR)
5125033f43cSJassi Brar 				|| (clk_id == SAMSUNG_I2S_RCLKSRC_0))
5135033f43cSJassi Brar 			clk_id = 0;
5145033f43cSJassi Brar 		else
5155033f43cSJassi Brar 			clk_id = 1;
5165033f43cSJassi Brar 
5175033f43cSJassi Brar 		if (!any_active(i2s)) {
518a6aba536SSylwester Nawrocki 			if (i2s->op_clk && !IS_ERR(i2s->op_clk)) {
519a5a56871SPadmavathi Venna 				if ((clk_id && !(mod & rsrc_mask)) ||
520a5a56871SPadmavathi Venna 					(!clk_id && (mod & rsrc_mask))) {
52198614cf6SThomas Abraham 					clk_disable_unprepare(i2s->op_clk);
5225033f43cSJassi Brar 					clk_put(i2s->op_clk);
5235033f43cSJassi Brar 				} else {
5246ce534aaSJassi Brar 					i2s->rclk_srcrate =
5256ce534aaSJassi Brar 						clk_get_rate(i2s->op_clk);
5265033f43cSJassi Brar 					return 0;
5275033f43cSJassi Brar 				}
5285033f43cSJassi Brar 			}
5295033f43cSJassi Brar 
5301974a042SPadmavathi Venna 			if (clk_id)
5315033f43cSJassi Brar 				i2s->op_clk = clk_get(&i2s->pdev->dev,
5321974a042SPadmavathi Venna 						"i2s_opclk1");
5331974a042SPadmavathi Venna 			else
5341974a042SPadmavathi Venna 				i2s->op_clk = clk_get(&i2s->pdev->dev,
5351974a042SPadmavathi Venna 						"i2s_opclk0");
536a6aba536SSylwester Nawrocki 
537a6aba536SSylwester Nawrocki 			if (WARN_ON(IS_ERR(i2s->op_clk)))
538a6aba536SSylwester Nawrocki 				return PTR_ERR(i2s->op_clk);
539a6aba536SSylwester Nawrocki 
54098614cf6SThomas Abraham 			clk_prepare_enable(i2s->op_clk);
5415033f43cSJassi Brar 			i2s->rclk_srcrate = clk_get_rate(i2s->op_clk);
5425033f43cSJassi Brar 
5435033f43cSJassi Brar 			/* Over-ride the other's */
5445033f43cSJassi Brar 			if (other) {
5455033f43cSJassi Brar 				other->op_clk = i2s->op_clk;
5465033f43cSJassi Brar 				other->rclk_srcrate = i2s->rclk_srcrate;
5475033f43cSJassi Brar 			}
548a5a56871SPadmavathi Venna 		} else if ((!clk_id && (mod & rsrc_mask))
549a5a56871SPadmavathi Venna 				|| (clk_id && !(mod & rsrc_mask))) {
5505033f43cSJassi Brar 			dev_err(&i2s->pdev->dev,
5515033f43cSJassi Brar 				"%s:%d Other DAI busy\n", __func__, __LINE__);
5525033f43cSJassi Brar 			return -EAGAIN;
5535033f43cSJassi Brar 		} else {
5545033f43cSJassi Brar 			/* Call can't be on the active DAI */
5555033f43cSJassi Brar 			i2s->op_clk = other->op_clk;
5565033f43cSJassi Brar 			i2s->rclk_srcrate = other->rclk_srcrate;
5575033f43cSJassi Brar 			return 0;
5585033f43cSJassi Brar 		}
5595033f43cSJassi Brar 
5605033f43cSJassi Brar 		if (clk_id == 0)
561b2de1d20SPadmavathi Venna 			mod &= ~(1 << i2s_regs->rclksrc_off);
5625033f43cSJassi Brar 		else
563a5a56871SPadmavathi Venna 			mod |= 1 << i2s_regs->rclksrc_off;
5645033f43cSJassi Brar 
565b2de1d20SPadmavathi Venna 		break;
5665033f43cSJassi Brar 	default:
5675033f43cSJassi Brar 		dev_err(&i2s->pdev->dev, "We don't serve that!\n");
5685033f43cSJassi Brar 		return -EINVAL;
5695033f43cSJassi Brar 	}
5705033f43cSJassi Brar 
5715033f43cSJassi Brar 	writel(mod, i2s->addr + I2SMOD);
5725033f43cSJassi Brar 
5735033f43cSJassi Brar 	return 0;
5745033f43cSJassi Brar }
5755033f43cSJassi Brar 
5765033f43cSJassi Brar static int i2s_set_fmt(struct snd_soc_dai *dai,
5775033f43cSJassi Brar 	unsigned int fmt)
5785033f43cSJassi Brar {
5795033f43cSJassi Brar 	struct i2s_dai *i2s = to_info(dai);
5805033f43cSJassi Brar 	u32 mod = readl(i2s->addr + I2SMOD);
581a5a56871SPadmavathi Venna 	int lrp_shift, sdf_shift, sdf_mask, lrp_rlow, mod_slave;
5825033f43cSJassi Brar 	u32 tmp = 0;
5835033f43cSJassi Brar 
584a5a56871SPadmavathi Venna 	lrp_shift = i2s->variant_regs->lrp_off;
585a5a56871SPadmavathi Venna 	sdf_shift = i2s->variant_regs->sdf_off;
586a5a56871SPadmavathi Venna 	mod_slave = 1 << i2s->variant_regs->mss_off;
5874ca0c0d4SPadmavathi Venna 
588b60be4aaSPadmavathi Venna 	sdf_mask = MOD_SDF_MASK << sdf_shift;
589b60be4aaSPadmavathi Venna 	lrp_rlow = MOD_LR_RLOW << lrp_shift;
590b60be4aaSPadmavathi Venna 
5915033f43cSJassi Brar 	/* Format is priority */
5925033f43cSJassi Brar 	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
5935033f43cSJassi Brar 	case SND_SOC_DAIFMT_RIGHT_J:
594b60be4aaSPadmavathi Venna 		tmp |= lrp_rlow;
595b60be4aaSPadmavathi Venna 		tmp |= (MOD_SDF_MSB << sdf_shift);
5965033f43cSJassi Brar 		break;
5975033f43cSJassi Brar 	case SND_SOC_DAIFMT_LEFT_J:
598b60be4aaSPadmavathi Venna 		tmp |= lrp_rlow;
599b60be4aaSPadmavathi Venna 		tmp |= (MOD_SDF_LSB << sdf_shift);
6005033f43cSJassi Brar 		break;
6015033f43cSJassi Brar 	case SND_SOC_DAIFMT_I2S:
602b60be4aaSPadmavathi Venna 		tmp |= (MOD_SDF_IIS << sdf_shift);
6035033f43cSJassi Brar 		break;
6045033f43cSJassi Brar 	default:
6055033f43cSJassi Brar 		dev_err(&i2s->pdev->dev, "Format not supported\n");
6065033f43cSJassi Brar 		return -EINVAL;
6075033f43cSJassi Brar 	}
6085033f43cSJassi Brar 
6095033f43cSJassi Brar 	/*
6105033f43cSJassi Brar 	 * INV flag is relative to the FORMAT flag - if set it simply
6115033f43cSJassi Brar 	 * flips the polarity specified by the Standard
6125033f43cSJassi Brar 	 */
6135033f43cSJassi Brar 	switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
6145033f43cSJassi Brar 	case SND_SOC_DAIFMT_NB_NF:
6155033f43cSJassi Brar 		break;
6165033f43cSJassi Brar 	case SND_SOC_DAIFMT_NB_IF:
617b60be4aaSPadmavathi Venna 		if (tmp & lrp_rlow)
618b60be4aaSPadmavathi Venna 			tmp &= ~lrp_rlow;
6195033f43cSJassi Brar 		else
620b60be4aaSPadmavathi Venna 			tmp |= lrp_rlow;
6215033f43cSJassi Brar 		break;
6225033f43cSJassi Brar 	default:
6235033f43cSJassi Brar 		dev_err(&i2s->pdev->dev, "Polarity not supported\n");
6245033f43cSJassi Brar 		return -EINVAL;
6255033f43cSJassi Brar 	}
6265033f43cSJassi Brar 
6275033f43cSJassi Brar 	switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
6285033f43cSJassi Brar 	case SND_SOC_DAIFMT_CBM_CFM:
629a5a56871SPadmavathi Venna 		tmp |= mod_slave;
6305033f43cSJassi Brar 		break;
6315033f43cSJassi Brar 	case SND_SOC_DAIFMT_CBS_CFS:
6325033f43cSJassi Brar 		/* Set default source clock in Master mode */
6335033f43cSJassi Brar 		if (i2s->rclk_srcrate == 0)
6345033f43cSJassi Brar 			i2s_set_sysclk(dai, SAMSUNG_I2S_RCLKSRC_0,
6355033f43cSJassi Brar 							0, SND_SOC_CLOCK_IN);
6365033f43cSJassi Brar 		break;
6375033f43cSJassi Brar 	default:
6385033f43cSJassi Brar 		dev_err(&i2s->pdev->dev, "master/slave format not supported\n");
6395033f43cSJassi Brar 		return -EINVAL;
6405033f43cSJassi Brar 	}
6415033f43cSJassi Brar 
642b60be4aaSPadmavathi Venna 	/*
643b60be4aaSPadmavathi Venna 	 * Don't change the I2S mode if any controller is active on this
644b60be4aaSPadmavathi Venna 	 * channel.
645b60be4aaSPadmavathi Venna 	 */
6465033f43cSJassi Brar 	if (any_active(i2s) &&
647a5a56871SPadmavathi Venna 		((mod & (sdf_mask | lrp_rlow | mod_slave)) != tmp)) {
6485033f43cSJassi Brar 		dev_err(&i2s->pdev->dev,
6495033f43cSJassi Brar 				"%s:%d Other DAI busy\n", __func__, __LINE__);
6505033f43cSJassi Brar 		return -EAGAIN;
6515033f43cSJassi Brar 	}
6525033f43cSJassi Brar 
653a5a56871SPadmavathi Venna 	mod &= ~(sdf_mask | lrp_rlow | mod_slave);
6545033f43cSJassi Brar 	mod |= tmp;
6555033f43cSJassi Brar 	writel(mod, i2s->addr + I2SMOD);
6565033f43cSJassi Brar 
6575033f43cSJassi Brar 	return 0;
6585033f43cSJassi Brar }
6595033f43cSJassi Brar 
6605033f43cSJassi Brar static int i2s_hw_params(struct snd_pcm_substream *substream,
6615033f43cSJassi Brar 	struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
6625033f43cSJassi Brar {
6635033f43cSJassi Brar 	struct i2s_dai *i2s = to_info(dai);
6645033f43cSJassi Brar 	u32 mod = readl(i2s->addr + I2SMOD);
6655033f43cSJassi Brar 
6665033f43cSJassi Brar 	if (!is_secondary(i2s))
6675033f43cSJassi Brar 		mod &= ~(MOD_DC2_EN | MOD_DC1_EN);
6685033f43cSJassi Brar 
6695033f43cSJassi Brar 	switch (params_channels(params)) {
6705033f43cSJassi Brar 	case 6:
6715033f43cSJassi Brar 		mod |= MOD_DC2_EN;
6725033f43cSJassi Brar 	case 4:
6735033f43cSJassi Brar 		mod |= MOD_DC1_EN;
6745033f43cSJassi Brar 		break;
6755033f43cSJassi Brar 	case 2:
676588fb705SSangsu Park 		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
677588fb705SSangsu Park 			i2s->dma_playback.dma_size = 4;
678588fb705SSangsu Park 		else
679588fb705SSangsu Park 			i2s->dma_capture.dma_size = 4;
680588fb705SSangsu Park 		break;
681588fb705SSangsu Park 	case 1:
682588fb705SSangsu Park 		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
683588fb705SSangsu Park 			i2s->dma_playback.dma_size = 2;
684588fb705SSangsu Park 		else
685588fb705SSangsu Park 			i2s->dma_capture.dma_size = 2;
686588fb705SSangsu Park 
6875033f43cSJassi Brar 		break;
6885033f43cSJassi Brar 	default:
6895033f43cSJassi Brar 		dev_err(&i2s->pdev->dev, "%d channels not supported\n",
6905033f43cSJassi Brar 				params_channels(params));
6915033f43cSJassi Brar 		return -EINVAL;
6925033f43cSJassi Brar 	}
6935033f43cSJassi Brar 
6945033f43cSJassi Brar 	if (is_secondary(i2s))
6955033f43cSJassi Brar 		mod &= ~MOD_BLCS_MASK;
6965033f43cSJassi Brar 	else
6975033f43cSJassi Brar 		mod &= ~MOD_BLCP_MASK;
6985033f43cSJassi Brar 
6995033f43cSJassi Brar 	if (is_manager(i2s))
7005033f43cSJassi Brar 		mod &= ~MOD_BLC_MASK;
7015033f43cSJassi Brar 
70288ce1465STushar Behera 	switch (params_width(params)) {
70388ce1465STushar Behera 	case 8:
7045033f43cSJassi Brar 		if (is_secondary(i2s))
7055033f43cSJassi Brar 			mod |= MOD_BLCS_8BIT;
7065033f43cSJassi Brar 		else
7075033f43cSJassi Brar 			mod |= MOD_BLCP_8BIT;
7085033f43cSJassi Brar 		if (is_manager(i2s))
7095033f43cSJassi Brar 			mod |= MOD_BLC_8BIT;
7105033f43cSJassi Brar 		break;
71188ce1465STushar Behera 	case 16:
7125033f43cSJassi Brar 		if (is_secondary(i2s))
7135033f43cSJassi Brar 			mod |= MOD_BLCS_16BIT;
7145033f43cSJassi Brar 		else
7155033f43cSJassi Brar 			mod |= MOD_BLCP_16BIT;
7165033f43cSJassi Brar 		if (is_manager(i2s))
7175033f43cSJassi Brar 			mod |= MOD_BLC_16BIT;
7185033f43cSJassi Brar 		break;
71988ce1465STushar Behera 	case 24:
7205033f43cSJassi Brar 		if (is_secondary(i2s))
7215033f43cSJassi Brar 			mod |= MOD_BLCS_24BIT;
7225033f43cSJassi Brar 		else
7235033f43cSJassi Brar 			mod |= MOD_BLCP_24BIT;
7245033f43cSJassi Brar 		if (is_manager(i2s))
7255033f43cSJassi Brar 			mod |= MOD_BLC_24BIT;
7265033f43cSJassi Brar 		break;
7275033f43cSJassi Brar 	default:
7285033f43cSJassi Brar 		dev_err(&i2s->pdev->dev, "Format(%d) not supported\n",
7295033f43cSJassi Brar 				params_format(params));
7305033f43cSJassi Brar 		return -EINVAL;
7315033f43cSJassi Brar 	}
7325033f43cSJassi Brar 	writel(mod, i2s->addr + I2SMOD);
7335033f43cSJassi Brar 
734d37bdf73SMark Brown 	samsung_asoc_init_dma_data(dai, &i2s->dma_playback, &i2s->dma_capture);
735d37bdf73SMark Brown 
7365033f43cSJassi Brar 	i2s->frmclk = params_rate(params);
7375033f43cSJassi Brar 
7385033f43cSJassi Brar 	return 0;
7395033f43cSJassi Brar }
7405033f43cSJassi Brar 
7415033f43cSJassi Brar /* We set constraints on the substream acc to the version of I2S */
7425033f43cSJassi Brar static int i2s_startup(struct snd_pcm_substream *substream,
7435033f43cSJassi Brar 	  struct snd_soc_dai *dai)
7445033f43cSJassi Brar {
7455033f43cSJassi Brar 	struct i2s_dai *i2s = to_info(dai);
746dcd60fc3SSylwester Nawrocki 	struct i2s_dai *other = get_other_dai(i2s);
7475033f43cSJassi Brar 	unsigned long flags;
7485033f43cSJassi Brar 
7495033f43cSJassi Brar 	spin_lock_irqsave(&lock, flags);
7505033f43cSJassi Brar 
7515033f43cSJassi Brar 	i2s->mode |= DAI_OPENED;
7525033f43cSJassi Brar 
7535033f43cSJassi Brar 	if (is_manager(other))
7545033f43cSJassi Brar 		i2s->mode &= ~DAI_MANAGER;
7555033f43cSJassi Brar 	else
7565033f43cSJassi Brar 		i2s->mode |= DAI_MANAGER;
7575033f43cSJassi Brar 
7582d77828dSPadmavathi Venna 	if (!any_active(i2s) && (i2s->quirks & QUIRK_NEED_RSTCLR))
7592d77828dSPadmavathi Venna 		writel(CON_RSTCLR, i2s->addr + I2SCON);
7602d77828dSPadmavathi Venna 
7615033f43cSJassi Brar 	spin_unlock_irqrestore(&lock, flags);
7625033f43cSJassi Brar 
763b97c60abSSylwester Nawrocki 	if (!is_opened(other) && i2s->cdclk_out)
764b97c60abSSylwester Nawrocki 		i2s_set_sysclk(dai, SAMSUNG_I2S_CDCLK,
765b97c60abSSylwester Nawrocki 				0, SND_SOC_CLOCK_OUT);
7665033f43cSJassi Brar 	return 0;
7675033f43cSJassi Brar }
7685033f43cSJassi Brar 
7695033f43cSJassi Brar static void i2s_shutdown(struct snd_pcm_substream *substream,
7705033f43cSJassi Brar 	struct snd_soc_dai *dai)
7715033f43cSJassi Brar {
7725033f43cSJassi Brar 	struct i2s_dai *i2s = to_info(dai);
773dcd60fc3SSylwester Nawrocki 	struct i2s_dai *other = get_other_dai(i2s);
7745033f43cSJassi Brar 	unsigned long flags;
775a5a56871SPadmavathi Venna 	const struct samsung_i2s_variant_regs *i2s_regs = i2s->variant_regs;
7765033f43cSJassi Brar 
7775033f43cSJassi Brar 	spin_lock_irqsave(&lock, flags);
7785033f43cSJassi Brar 
7795033f43cSJassi Brar 	i2s->mode &= ~DAI_OPENED;
7805033f43cSJassi Brar 	i2s->mode &= ~DAI_MANAGER;
7815033f43cSJassi Brar 
782b97c60abSSylwester Nawrocki 	if (is_opened(other)) {
7835033f43cSJassi Brar 		other->mode |= DAI_MANAGER;
784b97c60abSSylwester Nawrocki 	} else {
785b97c60abSSylwester Nawrocki 		u32 mod = readl(i2s->addr + I2SMOD);
786a5a56871SPadmavathi Venna 		i2s->cdclk_out = !(mod & (1 << i2s_regs->cdclkcon_off));
787133c2681SCharles Keepax 		if (other)
788b97c60abSSylwester Nawrocki 			other->cdclk_out = i2s->cdclk_out;
789b97c60abSSylwester Nawrocki 	}
7905033f43cSJassi Brar 	/* Reset any constraint on RFS and BFS */
7915033f43cSJassi Brar 	i2s->rfs = 0;
7925033f43cSJassi Brar 	i2s->bfs = 0;
7935033f43cSJassi Brar 
7945033f43cSJassi Brar 	spin_unlock_irqrestore(&lock, flags);
7955033f43cSJassi Brar 
7965033f43cSJassi Brar 	/* Gate CDCLK by default */
7975033f43cSJassi Brar 	if (!is_opened(other))
7985033f43cSJassi Brar 		i2s_set_sysclk(dai, SAMSUNG_I2S_CDCLK,
7995033f43cSJassi Brar 				0, SND_SOC_CLOCK_IN);
8005033f43cSJassi Brar }
8015033f43cSJassi Brar 
8025033f43cSJassi Brar static int config_setup(struct i2s_dai *i2s)
8035033f43cSJassi Brar {
804dcd60fc3SSylwester Nawrocki 	struct i2s_dai *other = get_other_dai(i2s);
8055033f43cSJassi Brar 	unsigned rfs, bfs, blc;
8065033f43cSJassi Brar 	u32 psr;
8075033f43cSJassi Brar 
8085033f43cSJassi Brar 	blc = get_blc(i2s);
8095033f43cSJassi Brar 
8105033f43cSJassi Brar 	bfs = i2s->bfs;
8115033f43cSJassi Brar 
8125033f43cSJassi Brar 	if (!bfs && other)
8135033f43cSJassi Brar 		bfs = other->bfs;
8145033f43cSJassi Brar 
8155033f43cSJassi Brar 	/* Select least possible multiple(2) if no constraint set */
8165033f43cSJassi Brar 	if (!bfs)
8175033f43cSJassi Brar 		bfs = blc * 2;
8185033f43cSJassi Brar 
8195033f43cSJassi Brar 	rfs = i2s->rfs;
8205033f43cSJassi Brar 
8215033f43cSJassi Brar 	if (!rfs && other)
8225033f43cSJassi Brar 		rfs = other->rfs;
8235033f43cSJassi Brar 
8245033f43cSJassi Brar 	if ((rfs == 256 || rfs == 512) && (blc == 24)) {
8255033f43cSJassi Brar 		dev_err(&i2s->pdev->dev,
8265033f43cSJassi Brar 			"%d-RFS not supported for 24-blc\n", rfs);
8275033f43cSJassi Brar 		return -EINVAL;
8285033f43cSJassi Brar 	}
8295033f43cSJassi Brar 
8305033f43cSJassi Brar 	if (!rfs) {
8315033f43cSJassi Brar 		if (bfs == 16 || bfs == 32)
8325033f43cSJassi Brar 			rfs = 256;
8335033f43cSJassi Brar 		else
8345033f43cSJassi Brar 			rfs = 384;
8355033f43cSJassi Brar 	}
8365033f43cSJassi Brar 
8375033f43cSJassi Brar 	/* If already setup and running */
8385033f43cSJassi Brar 	if (any_active(i2s) && (get_rfs(i2s) != rfs || get_bfs(i2s) != bfs)) {
8395033f43cSJassi Brar 		dev_err(&i2s->pdev->dev,
8405033f43cSJassi Brar 				"%s:%d Other DAI busy\n", __func__, __LINE__);
8415033f43cSJassi Brar 		return -EAGAIN;
8425033f43cSJassi Brar 	}
8435033f43cSJassi Brar 
8445033f43cSJassi Brar 	set_bfs(i2s, bfs);
8455033f43cSJassi Brar 	set_rfs(i2s, rfs);
8465033f43cSJassi Brar 
84777010010SPadmavathi Venna 	/* Don't bother with PSR in Slave mode */
84877010010SPadmavathi Venna 	if (is_slave(i2s))
84977010010SPadmavathi Venna 		return 0;
85077010010SPadmavathi Venna 
8515033f43cSJassi Brar 	if (!(i2s->quirks & QUIRK_NO_MUXPSR)) {
8525033f43cSJassi Brar 		psr = i2s->rclk_srcrate / i2s->frmclk / rfs;
8535033f43cSJassi Brar 		writel(((psr - 1) << 8) | PSR_PSREN, i2s->addr + I2SPSR);
8545033f43cSJassi Brar 		dev_dbg(&i2s->pdev->dev,
8555033f43cSJassi Brar 			"RCLK_SRC=%luHz PSR=%u, RCLK=%dfs, BCLK=%dfs\n",
8565033f43cSJassi Brar 				i2s->rclk_srcrate, psr, rfs, bfs);
8575033f43cSJassi Brar 	}
8585033f43cSJassi Brar 
8595033f43cSJassi Brar 	return 0;
8605033f43cSJassi Brar }
8615033f43cSJassi Brar 
8625033f43cSJassi Brar static int i2s_trigger(struct snd_pcm_substream *substream,
8635033f43cSJassi Brar 	int cmd, struct snd_soc_dai *dai)
8645033f43cSJassi Brar {
8655033f43cSJassi Brar 	int capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
8665033f43cSJassi Brar 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
8675033f43cSJassi Brar 	struct i2s_dai *i2s = to_info(rtd->cpu_dai);
8685033f43cSJassi Brar 	unsigned long flags;
8695033f43cSJassi Brar 
8705033f43cSJassi Brar 	switch (cmd) {
8715033f43cSJassi Brar 	case SNDRV_PCM_TRIGGER_START:
8725033f43cSJassi Brar 	case SNDRV_PCM_TRIGGER_RESUME:
8735033f43cSJassi Brar 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
874*f3670536SSylwester Nawrocki 		spin_lock_irqsave(i2s->lock, flags);
8755033f43cSJassi Brar 
8765033f43cSJassi Brar 		if (config_setup(i2s)) {
877*f3670536SSylwester Nawrocki 			spin_unlock_irqrestore(i2s->lock, flags);
8785033f43cSJassi Brar 			return -EINVAL;
8795033f43cSJassi Brar 		}
8805033f43cSJassi Brar 
8815033f43cSJassi Brar 		if (capture)
8825033f43cSJassi Brar 			i2s_rxctrl(i2s, 1);
8835033f43cSJassi Brar 		else
8845033f43cSJassi Brar 			i2s_txctrl(i2s, 1);
8855033f43cSJassi Brar 
886*f3670536SSylwester Nawrocki 		spin_unlock_irqrestore(i2s->lock, flags);
8875033f43cSJassi Brar 		break;
8885033f43cSJassi Brar 	case SNDRV_PCM_TRIGGER_STOP:
8895033f43cSJassi Brar 	case SNDRV_PCM_TRIGGER_SUSPEND:
8905033f43cSJassi Brar 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
891*f3670536SSylwester Nawrocki 		spin_lock_irqsave(i2s->lock, flags);
8925033f43cSJassi Brar 
893c90887feSJassi Brar 		if (capture) {
8945033f43cSJassi Brar 			i2s_rxctrl(i2s, 0);
895775bc971SJassi Brar 			i2s_fifo(i2s, FIC_RXFLUSH);
896c90887feSJassi Brar 		} else {
897c90887feSJassi Brar 			i2s_txctrl(i2s, 0);
898775bc971SJassi Brar 			i2s_fifo(i2s, FIC_TXFLUSH);
899c90887feSJassi Brar 		}
900775bc971SJassi Brar 
901*f3670536SSylwester Nawrocki 		spin_unlock_irqrestore(i2s->lock, flags);
9025033f43cSJassi Brar 		break;
9035033f43cSJassi Brar 	}
9045033f43cSJassi Brar 
9055033f43cSJassi Brar 	return 0;
9065033f43cSJassi Brar }
9075033f43cSJassi Brar 
9085033f43cSJassi Brar static int i2s_set_clkdiv(struct snd_soc_dai *dai,
9095033f43cSJassi Brar 	int div_id, int div)
9105033f43cSJassi Brar {
9115033f43cSJassi Brar 	struct i2s_dai *i2s = to_info(dai);
912dcd60fc3SSylwester Nawrocki 	struct i2s_dai *other = get_other_dai(i2s);
9135033f43cSJassi Brar 
9145033f43cSJassi Brar 	switch (div_id) {
9155033f43cSJassi Brar 	case SAMSUNG_I2S_DIV_BCLK:
9165033f43cSJassi Brar 		if ((any_active(i2s) && div && (get_bfs(i2s) != div))
9175033f43cSJassi Brar 			|| (other && other->bfs && (other->bfs != div))) {
9185033f43cSJassi Brar 			dev_err(&i2s->pdev->dev,
9195033f43cSJassi Brar 				"%s:%d Other DAI busy\n", __func__, __LINE__);
9205033f43cSJassi Brar 			return -EAGAIN;
9215033f43cSJassi Brar 		}
9225033f43cSJassi Brar 		i2s->bfs = div;
9235033f43cSJassi Brar 		break;
9245033f43cSJassi Brar 	default:
9255033f43cSJassi Brar 		dev_err(&i2s->pdev->dev,
9265033f43cSJassi Brar 			"Invalid clock divider(%d)\n", div_id);
9275033f43cSJassi Brar 		return -EINVAL;
9285033f43cSJassi Brar 	}
9295033f43cSJassi Brar 
9305033f43cSJassi Brar 	return 0;
9315033f43cSJassi Brar }
9325033f43cSJassi Brar 
9335033f43cSJassi Brar static snd_pcm_sframes_t
9345033f43cSJassi Brar i2s_delay(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
9355033f43cSJassi Brar {
9365033f43cSJassi Brar 	struct i2s_dai *i2s = to_info(dai);
9375033f43cSJassi Brar 	u32 reg = readl(i2s->addr + I2SFIC);
9385033f43cSJassi Brar 	snd_pcm_sframes_t delay;
939a5a56871SPadmavathi Venna 	const struct samsung_i2s_variant_regs *i2s_regs = i2s->variant_regs;
9405033f43cSJassi Brar 
9415033f43cSJassi Brar 	if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
9425033f43cSJassi Brar 		delay = FIC_RXCOUNT(reg);
9435033f43cSJassi Brar 	else if (is_secondary(i2s))
9445033f43cSJassi Brar 		delay = FICS_TXCOUNT(readl(i2s->addr + I2SFICS));
9455033f43cSJassi Brar 	else
946a5a56871SPadmavathi Venna 		delay = (reg >> i2s_regs->ftx0cnt_off) & 0x7f;
9475033f43cSJassi Brar 
9485033f43cSJassi Brar 	return delay;
9495033f43cSJassi Brar }
9505033f43cSJassi Brar 
9515033f43cSJassi Brar #ifdef CONFIG_PM
9525033f43cSJassi Brar static int i2s_suspend(struct snd_soc_dai *dai)
9535033f43cSJassi Brar {
9545033f43cSJassi Brar 	struct i2s_dai *i2s = to_info(dai);
9555033f43cSJassi Brar 
9565033f43cSJassi Brar 	i2s->suspend_i2smod = readl(i2s->addr + I2SMOD);
9575033f43cSJassi Brar 	i2s->suspend_i2scon = readl(i2s->addr + I2SCON);
9585033f43cSJassi Brar 	i2s->suspend_i2spsr = readl(i2s->addr + I2SPSR);
9595033f43cSJassi Brar 
9605033f43cSJassi Brar 	return 0;
9615033f43cSJassi Brar }
9625033f43cSJassi Brar 
9635033f43cSJassi Brar static int i2s_resume(struct snd_soc_dai *dai)
9645033f43cSJassi Brar {
9655033f43cSJassi Brar 	struct i2s_dai *i2s = to_info(dai);
9665033f43cSJassi Brar 
9675033f43cSJassi Brar 	writel(i2s->suspend_i2scon, i2s->addr + I2SCON);
9685033f43cSJassi Brar 	writel(i2s->suspend_i2smod, i2s->addr + I2SMOD);
9695033f43cSJassi Brar 	writel(i2s->suspend_i2spsr, i2s->addr + I2SPSR);
9705033f43cSJassi Brar 
9715033f43cSJassi Brar 	return 0;
9725033f43cSJassi Brar }
9735033f43cSJassi Brar #else
9745033f43cSJassi Brar #define i2s_suspend NULL
9755033f43cSJassi Brar #define i2s_resume  NULL
9765033f43cSJassi Brar #endif
9775033f43cSJassi Brar 
9785033f43cSJassi Brar static int samsung_i2s_dai_probe(struct snd_soc_dai *dai)
9795033f43cSJassi Brar {
9805033f43cSJassi Brar 	struct i2s_dai *i2s = to_info(dai);
981dcd60fc3SSylwester Nawrocki 	struct i2s_dai *other = get_other_dai(i2s);
9825033f43cSJassi Brar 
9830ec2ba80SSylwester Nawrocki 	if (is_secondary(i2s)) { /* If this is probe on the secondary DAI */
9843688569eSMark Brown 		samsung_asoc_init_dma_data(dai, &other->sec_dai->dma_playback,
9853688569eSMark Brown 					   NULL);
986872c26bdSSylwester Nawrocki 	} else {
987872c26bdSSylwester Nawrocki 		samsung_asoc_init_dma_data(dai, &i2s->dma_playback,
988872c26bdSSylwester Nawrocki 					   &i2s->dma_capture);
989511e3033SMark Brown 
9905033f43cSJassi Brar 		if (i2s->quirks & QUIRK_NEED_RSTCLR)
9915033f43cSJassi Brar 			writel(CON_RSTCLR, i2s->addr + I2SCON);
9925033f43cSJassi Brar 
993b0759736SPadmavathi Venna 		if (i2s->quirks & QUIRK_SUPPORTS_IDMA)
9949b8f5695SMark Brown 			idma_reg_addr_init(i2s->addr,
99561100f40SSangbeom Kim 					i2s->sec_dai->idma_playback.dma_addr);
996872c26bdSSylwester Nawrocki 	}
99761100f40SSangbeom Kim 
9985033f43cSJassi Brar 	/* Reset any constraint on RFS and BFS */
9995033f43cSJassi Brar 	i2s->rfs = 0;
10005033f43cSJassi Brar 	i2s->bfs = 0;
1001d66eac3eSTushar Behera 	i2s->rclk_srcrate = 0;
10025033f43cSJassi Brar 	i2s_txctrl(i2s, 0);
10035033f43cSJassi Brar 	i2s_rxctrl(i2s, 0);
10045033f43cSJassi Brar 	i2s_fifo(i2s, FIC_TXFLUSH);
10055033f43cSJassi Brar 	i2s_fifo(other, FIC_TXFLUSH);
10065033f43cSJassi Brar 	i2s_fifo(i2s, FIC_RXFLUSH);
10075033f43cSJassi Brar 
10085033f43cSJassi Brar 	/* Gate CDCLK by default */
10095033f43cSJassi Brar 	if (!is_opened(other))
10105033f43cSJassi Brar 		i2s_set_sysclk(dai, SAMSUNG_I2S_CDCLK,
10115033f43cSJassi Brar 				0, SND_SOC_CLOCK_IN);
10125033f43cSJassi Brar 
10135033f43cSJassi Brar 	return 0;
10145033f43cSJassi Brar }
10155033f43cSJassi Brar 
10165033f43cSJassi Brar static int samsung_i2s_dai_remove(struct snd_soc_dai *dai)
10175033f43cSJassi Brar {
10185033f43cSJassi Brar 	struct i2s_dai *i2s = snd_soc_dai_get_drvdata(dai);
10195033f43cSJassi Brar 
1020c92f1d0eSSylwester Nawrocki 	if (!is_secondary(i2s)) {
10215033f43cSJassi Brar 		if (i2s->quirks & QUIRK_NEED_RSTCLR)
10225033f43cSJassi Brar 			writel(0, i2s->addr + I2SCON);
10235033f43cSJassi Brar 	}
10245033f43cSJassi Brar 
10255033f43cSJassi Brar 	return 0;
10265033f43cSJassi Brar }
10275033f43cSJassi Brar 
102885e7652dSLars-Peter Clausen static const struct snd_soc_dai_ops samsung_i2s_dai_ops = {
10295033f43cSJassi Brar 	.trigger = i2s_trigger,
10305033f43cSJassi Brar 	.hw_params = i2s_hw_params,
10315033f43cSJassi Brar 	.set_fmt = i2s_set_fmt,
10325033f43cSJassi Brar 	.set_clkdiv = i2s_set_clkdiv,
10335033f43cSJassi Brar 	.set_sysclk = i2s_set_sysclk,
10345033f43cSJassi Brar 	.startup = i2s_startup,
10355033f43cSJassi Brar 	.shutdown = i2s_shutdown,
10365033f43cSJassi Brar 	.delay = i2s_delay,
10375033f43cSJassi Brar };
10385033f43cSJassi Brar 
10394b828535SKuninori Morimoto static const struct snd_soc_component_driver samsung_i2s_component = {
10404b828535SKuninori Morimoto 	.name		= "samsung-i2s",
10414b828535SKuninori Morimoto };
10424b828535SKuninori Morimoto 
10435033f43cSJassi Brar #define SAMSUNG_I2S_RATES	SNDRV_PCM_RATE_8000_96000
10445033f43cSJassi Brar 
10455033f43cSJassi Brar #define SAMSUNG_I2S_FMTS	(SNDRV_PCM_FMTBIT_S8 | \
10465033f43cSJassi Brar 					SNDRV_PCM_FMTBIT_S16_LE | \
10475033f43cSJassi Brar 					SNDRV_PCM_FMTBIT_S24_LE)
10485033f43cSJassi Brar 
1049fdca21adSBill Pemberton static struct i2s_dai *i2s_alloc_dai(struct platform_device *pdev, bool sec)
10505033f43cSJassi Brar {
10515033f43cSJassi Brar 	struct i2s_dai *i2s;
1052c6f9b1ebSPrathyush K 	int ret;
10535033f43cSJassi Brar 
1054b960ce74SMark Brown 	i2s = devm_kzalloc(&pdev->dev, sizeof(struct i2s_dai), GFP_KERNEL);
10555033f43cSJassi Brar 	if (i2s == NULL)
10565033f43cSJassi Brar 		return NULL;
10575033f43cSJassi Brar 
10585033f43cSJassi Brar 	i2s->pdev = pdev;
10595033f43cSJassi Brar 	i2s->pri_dai = NULL;
10605033f43cSJassi Brar 	i2s->sec_dai = NULL;
10615033f43cSJassi Brar 	i2s->i2s_dai_drv.symmetric_rates = 1;
10625033f43cSJassi Brar 	i2s->i2s_dai_drv.probe = samsung_i2s_dai_probe;
10635033f43cSJassi Brar 	i2s->i2s_dai_drv.remove = samsung_i2s_dai_remove;
10645033f43cSJassi Brar 	i2s->i2s_dai_drv.ops = &samsung_i2s_dai_ops;
10655033f43cSJassi Brar 	i2s->i2s_dai_drv.suspend = i2s_suspend;
10665033f43cSJassi Brar 	i2s->i2s_dai_drv.resume = i2s_resume;
1067a0ff6ea2SCharles Keepax 	i2s->i2s_dai_drv.playback.channels_min = 1;
10685033f43cSJassi Brar 	i2s->i2s_dai_drv.playback.channels_max = 2;
10695033f43cSJassi Brar 	i2s->i2s_dai_drv.playback.rates = SAMSUNG_I2S_RATES;
10705033f43cSJassi Brar 	i2s->i2s_dai_drv.playback.formats = SAMSUNG_I2S_FMTS;
10715033f43cSJassi Brar 
10725033f43cSJassi Brar 	if (!sec) {
1073588fb705SSangsu Park 		i2s->i2s_dai_drv.capture.channels_min = 1;
10745033f43cSJassi Brar 		i2s->i2s_dai_drv.capture.channels_max = 2;
10755033f43cSJassi Brar 		i2s->i2s_dai_drv.capture.rates = SAMSUNG_I2S_RATES;
10765033f43cSJassi Brar 		i2s->i2s_dai_drv.capture.formats = SAMSUNG_I2S_FMTS;
1077c6f9b1ebSPrathyush K 		dev_set_drvdata(&i2s->pdev->dev, i2s);
10785033f43cSJassi Brar 	} else {	/* Create a new platform_device for Secondary */
1079c6f9b1ebSPrathyush K 		i2s->pdev = platform_device_alloc("samsung-i2s-sec", -1);
108029ca9c73SWei Yongjun 		if (!i2s->pdev)
10815033f43cSJassi Brar 			return NULL;
10825033f43cSJassi Brar 
10832f6f0ffbSMark Brown 		i2s->pdev->dev.parent = &pdev->dev;
10842f6f0ffbSMark Brown 
1085c6f9b1ebSPrathyush K 		platform_set_drvdata(i2s->pdev, i2s);
1086c6f9b1ebSPrathyush K 		ret = platform_device_add(i2s->pdev);
1087c6f9b1ebSPrathyush K 		if (ret < 0)
1088c6f9b1ebSPrathyush K 			return NULL;
1089c6f9b1ebSPrathyush K 	}
10905033f43cSJassi Brar 
10915033f43cSJassi Brar 	return i2s;
10925033f43cSJassi Brar }
10935033f43cSJassi Brar 
109440476f61SPadmavathi Venna static const struct of_device_id exynos_i2s_match[];
109540476f61SPadmavathi Venna 
10967da493e9SPadmavathi Venna static inline const struct samsung_i2s_dai_data *samsung_i2s_get_driver_data(
10977da493e9SPadmavathi Venna 						struct platform_device *pdev)
10987c62eebbSPadmavathi Venna {
10999cf24747SSylwester Nawrocki 	if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {
110040476f61SPadmavathi Venna 		const struct of_device_id *match;
110140476f61SPadmavathi Venna 		match = of_match_node(exynos_i2s_match, pdev->dev.of_node);
11029cf24747SSylwester Nawrocki 		return match ? match->data : NULL;
11039cf24747SSylwester Nawrocki 	} else {
11047da493e9SPadmavathi Venna 		return (struct samsung_i2s_dai_data *)
11057da493e9SPadmavathi Venna 				platform_get_device_id(pdev)->driver_data;
11067c62eebbSPadmavathi Venna 	}
11079cf24747SSylwester Nawrocki }
11087c62eebbSPadmavathi Venna 
1109641d334bSRafael J. Wysocki #ifdef CONFIG_PM
11105b1d3c34SR. Chandrasekar static int i2s_runtime_suspend(struct device *dev)
11115b1d3c34SR. Chandrasekar {
11125b1d3c34SR. Chandrasekar 	struct i2s_dai *i2s = dev_get_drvdata(dev);
11135b1d3c34SR. Chandrasekar 
11145b1d3c34SR. Chandrasekar 	clk_disable_unprepare(i2s->clk);
11155b1d3c34SR. Chandrasekar 
11165b1d3c34SR. Chandrasekar 	return 0;
11175b1d3c34SR. Chandrasekar }
11185b1d3c34SR. Chandrasekar 
11195b1d3c34SR. Chandrasekar static int i2s_runtime_resume(struct device *dev)
11205b1d3c34SR. Chandrasekar {
11215b1d3c34SR. Chandrasekar 	struct i2s_dai *i2s = dev_get_drvdata(dev);
11225b1d3c34SR. Chandrasekar 
11235b1d3c34SR. Chandrasekar 	clk_prepare_enable(i2s->clk);
11245b1d3c34SR. Chandrasekar 
11255b1d3c34SR. Chandrasekar 	return 0;
11265b1d3c34SR. Chandrasekar }
1127641d334bSRafael J. Wysocki #endif /* CONFIG_PM */
11285b1d3c34SR. Chandrasekar 
1129fdca21adSBill Pemberton static int samsung_i2s_probe(struct platform_device *pdev)
11305033f43cSJassi Brar {
11315033f43cSJassi Brar 	struct i2s_dai *pri_dai, *sec_dai = NULL;
113240476f61SPadmavathi Venna 	struct s3c_audio_pdata *i2s_pdata = pdev->dev.platform_data;
113340476f61SPadmavathi Venna 	struct samsung_i2s *i2s_cfg = NULL;
11345033f43cSJassi Brar 	struct resource *res;
113540476f61SPadmavathi Venna 	u32 regs_base, quirks = 0, idma_addr = 0;
113640476f61SPadmavathi Venna 	struct device_node *np = pdev->dev.of_node;
11377da493e9SPadmavathi Venna 	const struct samsung_i2s_dai_data *i2s_dai_data;
1138c92f1d0eSSylwester Nawrocki 	int ret;
11395033f43cSJassi Brar 
11405033f43cSJassi Brar 	/* Call during Seconday interface registration */
11417da493e9SPadmavathi Venna 	i2s_dai_data = samsung_i2s_get_driver_data(pdev);
11427c62eebbSPadmavathi Venna 
11437da493e9SPadmavathi Venna 	if (i2s_dai_data->dai_type == TYPE_SEC) {
11445033f43cSJassi Brar 		sec_dai = dev_get_drvdata(&pdev->dev);
1145a9b977ecSPrathyush K 		if (!sec_dai) {
1146a9b977ecSPrathyush K 			dev_err(&pdev->dev, "Unable to get drvdata\n");
1147a9b977ecSPrathyush K 			return -EFAULT;
1148a9b977ecSPrathyush K 		}
114953f7faa1SSylwester Nawrocki 		ret = devm_snd_soc_register_component(&sec_dai->pdev->dev,
11504b828535SKuninori Morimoto 						&samsung_i2s_component,
11514b828535SKuninori Morimoto 						&sec_dai->i2s_dai_drv, 1);
115253f7faa1SSylwester Nawrocki 		if (ret != 0)
115353f7faa1SSylwester Nawrocki 			return ret;
115453f7faa1SSylwester Nawrocki 
115553f7faa1SSylwester Nawrocki 		return samsung_asoc_dma_platform_register(&pdev->dev);
11565033f43cSJassi Brar 	}
11575033f43cSJassi Brar 
115840476f61SPadmavathi Venna 	pri_dai = i2s_alloc_dai(pdev, false);
115940476f61SPadmavathi Venna 	if (!pri_dai) {
116040476f61SPadmavathi Venna 		dev_err(&pdev->dev, "Unable to alloc I2S_pri\n");
116140476f61SPadmavathi Venna 		return -ENOMEM;
116240476f61SPadmavathi Venna 	}
116340476f61SPadmavathi Venna 
1164*f3670536SSylwester Nawrocki 	spin_lock_init(&pri_dai->spinlock);
1165*f3670536SSylwester Nawrocki 	pri_dai->lock = &pri_dai->spinlock;
1166*f3670536SSylwester Nawrocki 
116740476f61SPadmavathi Venna 	if (!np) {
116840476f61SPadmavathi Venna 		res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
116940476f61SPadmavathi Venna 		if (!res) {
117040476f61SPadmavathi Venna 			dev_err(&pdev->dev,
117140476f61SPadmavathi Venna 				"Unable to get I2S-TX dma resource\n");
117240476f61SPadmavathi Venna 			return -ENXIO;
117340476f61SPadmavathi Venna 		}
117440476f61SPadmavathi Venna 		pri_dai->dma_playback.channel = res->start;
117540476f61SPadmavathi Venna 
117640476f61SPadmavathi Venna 		res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
117740476f61SPadmavathi Venna 		if (!res) {
117840476f61SPadmavathi Venna 			dev_err(&pdev->dev,
117940476f61SPadmavathi Venna 				"Unable to get I2S-RX dma resource\n");
118040476f61SPadmavathi Venna 			return -ENXIO;
118140476f61SPadmavathi Venna 		}
118240476f61SPadmavathi Venna 		pri_dai->dma_capture.channel = res->start;
118340476f61SPadmavathi Venna 
11845033f43cSJassi Brar 		if (i2s_pdata == NULL) {
11855033f43cSJassi Brar 			dev_err(&pdev->dev, "Can't work without s3c_audio_pdata\n");
11865033f43cSJassi Brar 			return -EINVAL;
11875033f43cSJassi Brar 		}
11885033f43cSJassi Brar 
118940476f61SPadmavathi Venna 		if (&i2s_pdata->type)
119040476f61SPadmavathi Venna 			i2s_cfg = &i2s_pdata->type.i2s;
11915033f43cSJassi Brar 
119240476f61SPadmavathi Venna 		if (i2s_cfg) {
119340476f61SPadmavathi Venna 			quirks = i2s_cfg->quirks;
119440476f61SPadmavathi Venna 			idma_addr = i2s_cfg->idma_addr;
11955033f43cSJassi Brar 		}
119640476f61SPadmavathi Venna 	} else {
11977da493e9SPadmavathi Venna 		quirks = i2s_dai_data->quirks;
119840476f61SPadmavathi Venna 		if (of_property_read_u32(np, "samsung,idma-addr",
119940476f61SPadmavathi Venna 					 &idma_addr)) {
1200b0759736SPadmavathi Venna 			if (quirks & QUIRK_SUPPORTS_IDMA) {
1201b0759736SPadmavathi Venna 				dev_info(&pdev->dev, "idma address is not"\
120240476f61SPadmavathi Venna 						"specified");
120340476f61SPadmavathi Venna 			}
120440476f61SPadmavathi Venna 		}
120540476f61SPadmavathi Venna 	}
12065033f43cSJassi Brar 
12075033f43cSJassi Brar 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1208af1cf5cfSSylwester Nawrocki 	pri_dai->addr = devm_ioremap_resource(&pdev->dev, res);
1209af1cf5cfSSylwester Nawrocki 	if (IS_ERR(pri_dai->addr))
1210af1cf5cfSSylwester Nawrocki 		return PTR_ERR(pri_dai->addr);
12115033f43cSJassi Brar 
12125033f43cSJassi Brar 	regs_base = res->start;
12135033f43cSJassi Brar 
12140ec2ba80SSylwester Nawrocki 	pri_dai->clk = devm_clk_get(&pdev->dev, "iis");
12150ec2ba80SSylwester Nawrocki 	if (IS_ERR(pri_dai->clk)) {
12160ec2ba80SSylwester Nawrocki 		dev_err(&pdev->dev, "Failed to get iis clock\n");
12170ec2ba80SSylwester Nawrocki 		return PTR_ERR(pri_dai->clk);
12180ec2ba80SSylwester Nawrocki 	}
1219c92f1d0eSSylwester Nawrocki 
1220c92f1d0eSSylwester Nawrocki 	ret = clk_prepare_enable(pri_dai->clk);
1221c92f1d0eSSylwester Nawrocki 	if (ret != 0) {
1222c92f1d0eSSylwester Nawrocki 		dev_err(&pdev->dev, "failed to enable clock: %d\n", ret);
1223c92f1d0eSSylwester Nawrocki 		return ret;
1224c92f1d0eSSylwester Nawrocki 	}
12255033f43cSJassi Brar 	pri_dai->dma_playback.dma_addr = regs_base + I2STXD;
12265033f43cSJassi Brar 	pri_dai->dma_capture.dma_addr = regs_base + I2SRXD;
122740476f61SPadmavathi Venna 	pri_dai->dma_playback.ch_name = "tx";
122840476f61SPadmavathi Venna 	pri_dai->dma_capture.ch_name = "rx";
12295033f43cSJassi Brar 	pri_dai->dma_playback.dma_size = 4;
12305033f43cSJassi Brar 	pri_dai->dma_capture.dma_size = 4;
12315033f43cSJassi Brar 	pri_dai->quirks = quirks;
1232a5a56871SPadmavathi Venna 	pri_dai->variant_regs = i2s_dai_data->i2s_variant_regs;
12335033f43cSJassi Brar 
12345033f43cSJassi Brar 	if (quirks & QUIRK_PRI_6CHAN)
12355033f43cSJassi Brar 		pri_dai->i2s_dai_drv.playback.channels_max = 6;
12365033f43cSJassi Brar 
12375033f43cSJassi Brar 	if (quirks & QUIRK_SEC_DAI) {
12385033f43cSJassi Brar 		sec_dai = i2s_alloc_dai(pdev, true);
12395033f43cSJassi Brar 		if (!sec_dai) {
12405033f43cSJassi Brar 			dev_err(&pdev->dev, "Unable to alloc I2S_sec\n");
1241af1cf5cfSSylwester Nawrocki 			return -ENOMEM;
12425033f43cSJassi Brar 		}
12437e5d8706SSylwester Nawrocki 
1244*f3670536SSylwester Nawrocki 		sec_dai->lock = &pri_dai->spinlock;
12457e5d8706SSylwester Nawrocki 		sec_dai->variant_regs = pri_dai->variant_regs;
12465033f43cSJassi Brar 		sec_dai->dma_playback.dma_addr = regs_base + I2STXDS;
124740476f61SPadmavathi Venna 		sec_dai->dma_playback.ch_name = "tx-sec";
124840476f61SPadmavathi Venna 
124940476f61SPadmavathi Venna 		if (!np) {
125040476f61SPadmavathi Venna 			res = platform_get_resource(pdev, IORESOURCE_DMA, 2);
125140476f61SPadmavathi Venna 			if (res)
125240476f61SPadmavathi Venna 				sec_dai->dma_playback.channel = res->start;
125340476f61SPadmavathi Venna 		}
125440476f61SPadmavathi Venna 
12555033f43cSJassi Brar 		sec_dai->dma_playback.dma_size = 4;
1256af1cf5cfSSylwester Nawrocki 		sec_dai->addr = pri_dai->addr;
12570ec2ba80SSylwester Nawrocki 		sec_dai->clk = pri_dai->clk;
12585033f43cSJassi Brar 		sec_dai->quirks = quirks;
125940476f61SPadmavathi Venna 		sec_dai->idma_playback.dma_addr = idma_addr;
12605033f43cSJassi Brar 		sec_dai->pri_dai = pri_dai;
12615033f43cSJassi Brar 		pri_dai->sec_dai = sec_dai;
12625033f43cSJassi Brar 	}
12635033f43cSJassi Brar 
12640429ffefSMark Brown 	if (i2s_pdata && i2s_pdata->cfg_gpio && i2s_pdata->cfg_gpio(pdev)) {
126540476f61SPadmavathi Venna 		dev_err(&pdev->dev, "Unable to configure gpio\n");
1266af1cf5cfSSylwester Nawrocki 		return -EINVAL;
126740476f61SPadmavathi Venna 	}
12685033f43cSJassi Brar 
1269d644a115SMark Brown 	devm_snd_soc_register_component(&pri_dai->pdev->dev,
1270d644a115SMark Brown 					&samsung_i2s_component,
12714b828535SKuninori Morimoto 					&pri_dai->i2s_dai_drv, 1);
12725033f43cSJassi Brar 
1273c5cf4dbcSMark Brown 	pm_runtime_enable(&pdev->dev);
1274c5cf4dbcSMark Brown 
127553f7faa1SSylwester Nawrocki 	ret = samsung_asoc_dma_platform_register(&pdev->dev);
127653f7faa1SSylwester Nawrocki 	if (ret != 0)
127753f7faa1SSylwester Nawrocki 		return ret;
1278a08485d8SPadmavathi Venna 
12795033f43cSJassi Brar 	return 0;
12805033f43cSJassi Brar }
12815033f43cSJassi Brar 
1282fdca21adSBill Pemberton static int samsung_i2s_remove(struct platform_device *pdev)
12835033f43cSJassi Brar {
12845033f43cSJassi Brar 	struct i2s_dai *i2s, *other;
12855033f43cSJassi Brar 
12865033f43cSJassi Brar 	i2s = dev_get_drvdata(&pdev->dev);
1287dcd60fc3SSylwester Nawrocki 	other = get_other_dai(i2s);
12885033f43cSJassi Brar 
12895033f43cSJassi Brar 	if (other) {
12905033f43cSJassi Brar 		other->pri_dai = NULL;
12915033f43cSJassi Brar 		other->sec_dai = NULL;
12925033f43cSJassi Brar 	} else {
1293c5cf4dbcSMark Brown 		pm_runtime_disable(&pdev->dev);
12945033f43cSJassi Brar 	}
12955033f43cSJassi Brar 
1296c92f1d0eSSylwester Nawrocki 	if (!is_secondary(i2s))
1297c92f1d0eSSylwester Nawrocki 		clk_disable_unprepare(i2s->clk);
1298c92f1d0eSSylwester Nawrocki 
12995033f43cSJassi Brar 	i2s->pri_dai = NULL;
13005033f43cSJassi Brar 	i2s->sec_dai = NULL;
13015033f43cSJassi Brar 
13025033f43cSJassi Brar 	return 0;
13035033f43cSJassi Brar }
13045033f43cSJassi Brar 
1305a5a56871SPadmavathi Venna static const struct samsung_i2s_variant_regs i2sv3_regs = {
1306a5a56871SPadmavathi Venna 	.bfs_off = 1,
1307a5a56871SPadmavathi Venna 	.rfs_off = 3,
1308a5a56871SPadmavathi Venna 	.sdf_off = 5,
1309a5a56871SPadmavathi Venna 	.txr_off = 8,
1310a5a56871SPadmavathi Venna 	.rclksrc_off = 10,
1311a5a56871SPadmavathi Venna 	.mss_off = 11,
1312a5a56871SPadmavathi Venna 	.cdclkcon_off = 12,
1313a5a56871SPadmavathi Venna 	.lrp_off = 7,
1314a5a56871SPadmavathi Venna 	.bfs_mask = 0x3,
1315a5a56871SPadmavathi Venna 	.rfs_mask = 0x3,
1316a5a56871SPadmavathi Venna 	.ftx0cnt_off = 8,
1317a5a56871SPadmavathi Venna };
1318a5a56871SPadmavathi Venna 
1319a5a56871SPadmavathi Venna static const struct samsung_i2s_variant_regs i2sv6_regs = {
1320a5a56871SPadmavathi Venna 	.bfs_off = 0,
1321a5a56871SPadmavathi Venna 	.rfs_off = 4,
1322a5a56871SPadmavathi Venna 	.sdf_off = 6,
1323a5a56871SPadmavathi Venna 	.txr_off = 8,
1324a5a56871SPadmavathi Venna 	.rclksrc_off = 10,
1325a5a56871SPadmavathi Venna 	.mss_off = 11,
1326a5a56871SPadmavathi Venna 	.cdclkcon_off = 12,
1327a5a56871SPadmavathi Venna 	.lrp_off = 15,
1328a5a56871SPadmavathi Venna 	.bfs_mask = 0xf,
1329a5a56871SPadmavathi Venna 	.rfs_mask = 0x3,
1330a5a56871SPadmavathi Venna 	.ftx0cnt_off = 8,
1331a5a56871SPadmavathi Venna };
1332a5a56871SPadmavathi Venna 
1333a5a56871SPadmavathi Venna static const struct samsung_i2s_variant_regs i2sv7_regs = {
1334a5a56871SPadmavathi Venna 	.bfs_off = 0,
1335a5a56871SPadmavathi Venna 	.rfs_off = 4,
1336a5a56871SPadmavathi Venna 	.sdf_off = 7,
1337a5a56871SPadmavathi Venna 	.txr_off = 9,
1338a5a56871SPadmavathi Venna 	.rclksrc_off = 11,
1339a5a56871SPadmavathi Venna 	.mss_off = 12,
1340a5a56871SPadmavathi Venna 	.cdclkcon_off = 22,
1341a5a56871SPadmavathi Venna 	.lrp_off = 15,
1342a5a56871SPadmavathi Venna 	.bfs_mask = 0xf,
1343a5a56871SPadmavathi Venna 	.rfs_mask = 0x7,
1344a5a56871SPadmavathi Venna 	.ftx0cnt_off = 0,
1345a5a56871SPadmavathi Venna };
1346a5a56871SPadmavathi Venna 
1347a5a56871SPadmavathi Venna static const struct samsung_i2s_variant_regs i2sv5_i2s1_regs = {
1348a5a56871SPadmavathi Venna 	.bfs_off = 0,
1349a5a56871SPadmavathi Venna 	.rfs_off = 3,
1350a5a56871SPadmavathi Venna 	.sdf_off = 6,
1351a5a56871SPadmavathi Venna 	.txr_off = 8,
1352a5a56871SPadmavathi Venna 	.rclksrc_off = 10,
1353a5a56871SPadmavathi Venna 	.mss_off = 11,
1354a5a56871SPadmavathi Venna 	.cdclkcon_off = 12,
1355a5a56871SPadmavathi Venna 	.lrp_off = 15,
1356a5a56871SPadmavathi Venna 	.bfs_mask = 0x7,
1357a5a56871SPadmavathi Venna 	.rfs_mask = 0x7,
1358a5a56871SPadmavathi Venna 	.ftx0cnt_off = 8,
1359a5a56871SPadmavathi Venna };
1360a5a56871SPadmavathi Venna 
13617da493e9SPadmavathi Venna static const struct samsung_i2s_dai_data i2sv3_dai_type = {
13627da493e9SPadmavathi Venna 	.dai_type = TYPE_PRI,
13637da493e9SPadmavathi Venna 	.quirks = QUIRK_NO_MUXPSR,
1364a5a56871SPadmavathi Venna 	.i2s_variant_regs = &i2sv3_regs,
13657da493e9SPadmavathi Venna };
13667da493e9SPadmavathi Venna 
13677da493e9SPadmavathi Venna static const struct samsung_i2s_dai_data i2sv5_dai_type = {
13687da493e9SPadmavathi Venna 	.dai_type = TYPE_PRI,
1369b0759736SPadmavathi Venna 	.quirks = QUIRK_PRI_6CHAN | QUIRK_SEC_DAI | QUIRK_NEED_RSTCLR |
1370b0759736SPadmavathi Venna 			QUIRK_SUPPORTS_IDMA,
1371a5a56871SPadmavathi Venna 	.i2s_variant_regs = &i2sv3_regs,
13727da493e9SPadmavathi Venna };
13737da493e9SPadmavathi Venna 
13744ca0c0d4SPadmavathi Venna static const struct samsung_i2s_dai_data i2sv6_dai_type = {
13754ca0c0d4SPadmavathi Venna 	.dai_type = TYPE_PRI,
13764ca0c0d4SPadmavathi Venna 	.quirks = QUIRK_PRI_6CHAN | QUIRK_SEC_DAI | QUIRK_NEED_RSTCLR |
1377b0759736SPadmavathi Venna 			QUIRK_SUPPORTS_TDM | QUIRK_SUPPORTS_IDMA,
1378a5a56871SPadmavathi Venna 	.i2s_variant_regs = &i2sv6_regs,
1379a5a56871SPadmavathi Venna };
1380a5a56871SPadmavathi Venna 
1381a5a56871SPadmavathi Venna static const struct samsung_i2s_dai_data i2sv7_dai_type = {
1382a5a56871SPadmavathi Venna 	.dai_type = TYPE_PRI,
1383a5a56871SPadmavathi Venna 	.quirks = QUIRK_PRI_6CHAN | QUIRK_SEC_DAI | QUIRK_NEED_RSTCLR |
1384a5a56871SPadmavathi Venna 			QUIRK_SUPPORTS_TDM,
1385a5a56871SPadmavathi Venna 	.i2s_variant_regs = &i2sv7_regs,
1386a5a56871SPadmavathi Venna };
1387a5a56871SPadmavathi Venna 
1388a5a56871SPadmavathi Venna static const struct samsung_i2s_dai_data i2sv5_dai_type_i2s1 = {
1389a5a56871SPadmavathi Venna 	.dai_type = TYPE_PRI,
1390a5a56871SPadmavathi Venna 	.quirks = QUIRK_PRI_6CHAN | QUIRK_NEED_RSTCLR,
1391a5a56871SPadmavathi Venna 	.i2s_variant_regs = &i2sv5_i2s1_regs,
13924ca0c0d4SPadmavathi Venna };
13934ca0c0d4SPadmavathi Venna 
13947da493e9SPadmavathi Venna static const struct samsung_i2s_dai_data samsung_dai_type_pri = {
13957da493e9SPadmavathi Venna 	.dai_type = TYPE_PRI,
13967da493e9SPadmavathi Venna };
13977da493e9SPadmavathi Venna 
13987da493e9SPadmavathi Venna static const struct samsung_i2s_dai_data samsung_dai_type_sec = {
13997da493e9SPadmavathi Venna 	.dai_type = TYPE_SEC,
14007da493e9SPadmavathi Venna };
14017da493e9SPadmavathi Venna 
14027c62eebbSPadmavathi Venna static struct platform_device_id samsung_i2s_driver_ids[] = {
14037c62eebbSPadmavathi Venna 	{
14047c62eebbSPadmavathi Venna 		.name           = "samsung-i2s",
14053f024980SMark Brown 		.driver_data	= (kernel_ulong_t)&i2sv3_dai_type,
14067c62eebbSPadmavathi Venna 	}, {
14077c62eebbSPadmavathi Venna 		.name           = "samsung-i2s-sec",
14087da493e9SPadmavathi Venna 		.driver_data    = (kernel_ulong_t)&samsung_dai_type_sec,
14093f024980SMark Brown 	}, {
14103f024980SMark Brown 		.name		= "samsung-i2sv4",
14113f024980SMark Brown 		.driver_data	= (kernel_ulong_t)&i2sv5_dai_type,
14127c62eebbSPadmavathi Venna 	},
14137c62eebbSPadmavathi Venna 	{},
14147c62eebbSPadmavathi Venna };
14152af19558SArnd Bergmann MODULE_DEVICE_TABLE(platform, samsung_i2s_driver_ids);
14167c62eebbSPadmavathi Venna 
141740476f61SPadmavathi Venna #ifdef CONFIG_OF
141840476f61SPadmavathi Venna static const struct of_device_id exynos_i2s_match[] = {
14197da493e9SPadmavathi Venna 	{
14207da493e9SPadmavathi Venna 		.compatible = "samsung,s3c6410-i2s",
14217da493e9SPadmavathi Venna 		.data = &i2sv3_dai_type,
14227da493e9SPadmavathi Venna 	}, {
14237da493e9SPadmavathi Venna 		.compatible = "samsung,s5pv210-i2s",
14247da493e9SPadmavathi Venna 		.data = &i2sv5_dai_type,
14254ca0c0d4SPadmavathi Venna 	}, {
14264ca0c0d4SPadmavathi Venna 		.compatible = "samsung,exynos5420-i2s",
14274ca0c0d4SPadmavathi Venna 		.data = &i2sv6_dai_type,
1428a5a56871SPadmavathi Venna 	}, {
1429a5a56871SPadmavathi Venna 		.compatible = "samsung,exynos7-i2s",
1430a5a56871SPadmavathi Venna 		.data = &i2sv7_dai_type,
1431a5a56871SPadmavathi Venna 	}, {
1432a5a56871SPadmavathi Venna 		.compatible = "samsung,exynos7-i2s1",
1433a5a56871SPadmavathi Venna 		.data = &i2sv5_dai_type_i2s1,
143440476f61SPadmavathi Venna 	},
143540476f61SPadmavathi Venna 	{},
143640476f61SPadmavathi Venna };
143740476f61SPadmavathi Venna MODULE_DEVICE_TABLE(of, exynos_i2s_match);
143840476f61SPadmavathi Venna #endif
143940476f61SPadmavathi Venna 
14405b1d3c34SR. Chandrasekar static const struct dev_pm_ops samsung_i2s_pm = {
14415b1d3c34SR. Chandrasekar 	SET_RUNTIME_PM_OPS(i2s_runtime_suspend,
14425b1d3c34SR. Chandrasekar 				i2s_runtime_resume, NULL)
14435b1d3c34SR. Chandrasekar };
14445b1d3c34SR. Chandrasekar 
14455033f43cSJassi Brar static struct platform_driver samsung_i2s_driver = {
14465033f43cSJassi Brar 	.probe  = samsung_i2s_probe,
1447fdca21adSBill Pemberton 	.remove = samsung_i2s_remove,
14487c62eebbSPadmavathi Venna 	.id_table = samsung_i2s_driver_ids,
14495033f43cSJassi Brar 	.driver = {
14505033f43cSJassi Brar 		.name = "samsung-i2s",
145140476f61SPadmavathi Venna 		.of_match_table = of_match_ptr(exynos_i2s_match),
14525b1d3c34SR. Chandrasekar 		.pm = &samsung_i2s_pm,
14535033f43cSJassi Brar 	},
14545033f43cSJassi Brar };
14555033f43cSJassi Brar 
1456e00c3f55SMark Brown module_platform_driver(samsung_i2s_driver);
14575033f43cSJassi Brar 
14585033f43cSJassi Brar /* Module information */
1459df8ad335SJaswinder Singh MODULE_AUTHOR("Jaswinder Singh, <jassisinghbrar@gmail.com>");
14605033f43cSJassi Brar MODULE_DESCRIPTION("Samsung I2S Interface");
14615033f43cSJassi Brar MODULE_ALIAS("platform:samsung-i2s");
14625033f43cSJassi Brar MODULE_LICENSE("GPL");
1463