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. 65033f43cSJassi Brar * Jaswinder Singh <jassi.brar@samsung.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> 175033f43cSJassi Brar 185033f43cSJassi Brar #include <sound/soc.h> 19*0378b6acSSeungwhan Youn #include <sound/pcm_params.h> 205033f43cSJassi Brar 215033f43cSJassi Brar #include <plat/audio.h> 225033f43cSJassi Brar 235033f43cSJassi Brar #include "dma.h" 245033f43cSJassi Brar #include "i2s.h" 255033f43cSJassi Brar 265033f43cSJassi Brar #define I2SCON 0x0 275033f43cSJassi Brar #define I2SMOD 0x4 285033f43cSJassi Brar #define I2SFIC 0x8 295033f43cSJassi Brar #define I2SPSR 0xc 305033f43cSJassi Brar #define I2STXD 0x10 315033f43cSJassi Brar #define I2SRXD 0x14 325033f43cSJassi Brar #define I2SFICS 0x18 335033f43cSJassi Brar #define I2STXDS 0x1c 345033f43cSJassi Brar 355033f43cSJassi Brar #define CON_RSTCLR (1 << 31) 365033f43cSJassi Brar #define CON_FRXOFSTATUS (1 << 26) 375033f43cSJassi Brar #define CON_FRXORINTEN (1 << 25) 385033f43cSJassi Brar #define CON_FTXSURSTAT (1 << 24) 395033f43cSJassi Brar #define CON_FTXSURINTEN (1 << 23) 405033f43cSJassi Brar #define CON_TXSDMA_PAUSE (1 << 20) 415033f43cSJassi Brar #define CON_TXSDMA_ACTIVE (1 << 18) 425033f43cSJassi Brar 435033f43cSJassi Brar #define CON_FTXURSTATUS (1 << 17) 445033f43cSJassi Brar #define CON_FTXURINTEN (1 << 16) 455033f43cSJassi Brar #define CON_TXFIFO2_EMPTY (1 << 15) 465033f43cSJassi Brar #define CON_TXFIFO1_EMPTY (1 << 14) 475033f43cSJassi Brar #define CON_TXFIFO2_FULL (1 << 13) 485033f43cSJassi Brar #define CON_TXFIFO1_FULL (1 << 12) 495033f43cSJassi Brar 505033f43cSJassi Brar #define CON_LRINDEX (1 << 11) 515033f43cSJassi Brar #define CON_TXFIFO_EMPTY (1 << 10) 525033f43cSJassi Brar #define CON_RXFIFO_EMPTY (1 << 9) 535033f43cSJassi Brar #define CON_TXFIFO_FULL (1 << 8) 545033f43cSJassi Brar #define CON_RXFIFO_FULL (1 << 7) 555033f43cSJassi Brar #define CON_TXDMA_PAUSE (1 << 6) 565033f43cSJassi Brar #define CON_RXDMA_PAUSE (1 << 5) 575033f43cSJassi Brar #define CON_TXCH_PAUSE (1 << 4) 585033f43cSJassi Brar #define CON_RXCH_PAUSE (1 << 3) 595033f43cSJassi Brar #define CON_TXDMA_ACTIVE (1 << 2) 605033f43cSJassi Brar #define CON_RXDMA_ACTIVE (1 << 1) 615033f43cSJassi Brar #define CON_ACTIVE (1 << 0) 625033f43cSJassi Brar 635033f43cSJassi Brar #define MOD_OPCLK_CDCLK_OUT (0 << 30) 645033f43cSJassi Brar #define MOD_OPCLK_CDCLK_IN (1 << 30) 655033f43cSJassi Brar #define MOD_OPCLK_BCLK_OUT (2 << 30) 665033f43cSJassi Brar #define MOD_OPCLK_PCLK (3 << 30) 675033f43cSJassi Brar #define MOD_OPCLK_MASK (3 << 30) 685033f43cSJassi Brar #define MOD_TXS_IDMA (1 << 28) /* Sec_TXFIFO use I-DMA */ 695033f43cSJassi Brar 705033f43cSJassi Brar #define MOD_BLCS_SHIFT 26 715033f43cSJassi Brar #define MOD_BLCS_16BIT (0 << MOD_BLCS_SHIFT) 725033f43cSJassi Brar #define MOD_BLCS_8BIT (1 << MOD_BLCS_SHIFT) 735033f43cSJassi Brar #define MOD_BLCS_24BIT (2 << MOD_BLCS_SHIFT) 745033f43cSJassi Brar #define MOD_BLCS_MASK (3 << MOD_BLCS_SHIFT) 755033f43cSJassi Brar #define MOD_BLCP_SHIFT 24 765033f43cSJassi Brar #define MOD_BLCP_16BIT (0 << MOD_BLCP_SHIFT) 775033f43cSJassi Brar #define MOD_BLCP_8BIT (1 << MOD_BLCP_SHIFT) 785033f43cSJassi Brar #define MOD_BLCP_24BIT (2 << MOD_BLCP_SHIFT) 795033f43cSJassi Brar #define MOD_BLCP_MASK (3 << MOD_BLCP_SHIFT) 805033f43cSJassi Brar 815033f43cSJassi Brar #define MOD_C2DD_HHALF (1 << 21) /* Discard Higher-half */ 825033f43cSJassi Brar #define MOD_C2DD_LHALF (1 << 20) /* Discard Lower-half */ 835033f43cSJassi Brar #define MOD_C1DD_HHALF (1 << 19) 845033f43cSJassi Brar #define MOD_C1DD_LHALF (1 << 18) 855033f43cSJassi Brar #define MOD_DC2_EN (1 << 17) 865033f43cSJassi Brar #define MOD_DC1_EN (1 << 16) 875033f43cSJassi Brar #define MOD_BLC_16BIT (0 << 13) 885033f43cSJassi Brar #define MOD_BLC_8BIT (1 << 13) 895033f43cSJassi Brar #define MOD_BLC_24BIT (2 << 13) 905033f43cSJassi Brar #define MOD_BLC_MASK (3 << 13) 915033f43cSJassi Brar 925033f43cSJassi Brar #define MOD_IMS_SYSMUX (1 << 10) 935033f43cSJassi Brar #define MOD_SLAVE (1 << 11) 945033f43cSJassi Brar #define MOD_TXONLY (0 << 8) 955033f43cSJassi Brar #define MOD_RXONLY (1 << 8) 965033f43cSJassi Brar #define MOD_TXRX (2 << 8) 975033f43cSJassi Brar #define MOD_MASK (3 << 8) 985033f43cSJassi Brar #define MOD_LR_LLOW (0 << 7) 995033f43cSJassi Brar #define MOD_LR_RLOW (1 << 7) 1005033f43cSJassi Brar #define MOD_SDF_IIS (0 << 5) 1015033f43cSJassi Brar #define MOD_SDF_MSB (1 << 5) 1025033f43cSJassi Brar #define MOD_SDF_LSB (2 << 5) 1035033f43cSJassi Brar #define MOD_SDF_MASK (3 << 5) 1045033f43cSJassi Brar #define MOD_RCLK_256FS (0 << 3) 1055033f43cSJassi Brar #define MOD_RCLK_512FS (1 << 3) 1065033f43cSJassi Brar #define MOD_RCLK_384FS (2 << 3) 1075033f43cSJassi Brar #define MOD_RCLK_768FS (3 << 3) 1085033f43cSJassi Brar #define MOD_RCLK_MASK (3 << 3) 1095033f43cSJassi Brar #define MOD_BCLK_32FS (0 << 1) 1105033f43cSJassi Brar #define MOD_BCLK_48FS (1 << 1) 1115033f43cSJassi Brar #define MOD_BCLK_16FS (2 << 1) 1125033f43cSJassi Brar #define MOD_BCLK_24FS (3 << 1) 1135033f43cSJassi Brar #define MOD_BCLK_MASK (3 << 1) 1145033f43cSJassi Brar #define MOD_8BIT (1 << 0) 1155033f43cSJassi Brar 1165033f43cSJassi Brar #define MOD_CDCLKCON (1 << 12) 1175033f43cSJassi Brar 1185033f43cSJassi Brar #define PSR_PSREN (1 << 15) 1195033f43cSJassi Brar 1205033f43cSJassi Brar #define FIC_TX2COUNT(x) (((x) >> 24) & 0xf) 1215033f43cSJassi Brar #define FIC_TX1COUNT(x) (((x) >> 16) & 0xf) 1225033f43cSJassi Brar 1235033f43cSJassi Brar #define FIC_TXFLUSH (1 << 15) 1245033f43cSJassi Brar #define FIC_RXFLUSH (1 << 7) 1255033f43cSJassi Brar #define FIC_TXCOUNT(x) (((x) >> 8) & 0xf) 1265033f43cSJassi Brar #define FIC_RXCOUNT(x) (((x) >> 0) & 0xf) 1275033f43cSJassi Brar #define FICS_TXCOUNT(x) (((x) >> 8) & 0x7f) 1285033f43cSJassi Brar 1295033f43cSJassi Brar #define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t) 1305033f43cSJassi Brar 1315033f43cSJassi Brar struct i2s_dai { 1325033f43cSJassi Brar /* Platform device for this DAI */ 1335033f43cSJassi Brar struct platform_device *pdev; 1345033f43cSJassi Brar /* IOREMAP'd SFRs */ 1355033f43cSJassi Brar void __iomem *addr; 1365033f43cSJassi Brar /* Physical base address of SFRs */ 1375033f43cSJassi Brar u32 base; 1385033f43cSJassi Brar /* Rate of RCLK source clock */ 1395033f43cSJassi Brar unsigned long rclk_srcrate; 1405033f43cSJassi Brar /* Frame Clock */ 1415033f43cSJassi Brar unsigned frmclk; 1425033f43cSJassi Brar /* 1435033f43cSJassi Brar * Specifically requested RCLK,BCLK by MACHINE Driver. 1445033f43cSJassi Brar * 0 indicates CPU driver is free to choose any value. 1455033f43cSJassi Brar */ 1465033f43cSJassi Brar unsigned rfs, bfs; 1475033f43cSJassi Brar /* I2S Controller's core clock */ 1485033f43cSJassi Brar struct clk *clk; 1495033f43cSJassi Brar /* Clock for generating I2S signals */ 1505033f43cSJassi Brar struct clk *op_clk; 1515033f43cSJassi Brar /* Array of clock names for op_clk */ 1525033f43cSJassi Brar const char **src_clk; 1535033f43cSJassi Brar /* Pointer to the Primary_Fifo if this is Sec_Fifo, NULL otherwise */ 1545033f43cSJassi Brar struct i2s_dai *pri_dai; 1555033f43cSJassi Brar /* Pointer to the Secondary_Fifo if it has one, NULL otherwise */ 1565033f43cSJassi Brar struct i2s_dai *sec_dai; 1575033f43cSJassi Brar #define DAI_OPENED (1 << 0) /* Dai is opened */ 1585033f43cSJassi Brar #define DAI_MANAGER (1 << 1) /* Dai is the manager */ 1595033f43cSJassi Brar unsigned mode; 1605033f43cSJassi Brar /* Driver for this DAI */ 1615033f43cSJassi Brar struct snd_soc_dai_driver i2s_dai_drv; 1625033f43cSJassi Brar /* DMA parameters */ 1635033f43cSJassi Brar struct s3c_dma_params dma_playback; 1645033f43cSJassi Brar struct s3c_dma_params dma_capture; 1655033f43cSJassi Brar u32 quirks; 1665033f43cSJassi Brar u32 suspend_i2smod; 1675033f43cSJassi Brar u32 suspend_i2scon; 1685033f43cSJassi Brar u32 suspend_i2spsr; 1695033f43cSJassi Brar }; 1705033f43cSJassi Brar 1715033f43cSJassi Brar /* Lock for cross i/f checks */ 1725033f43cSJassi Brar static DEFINE_SPINLOCK(lock); 1735033f43cSJassi Brar 1745033f43cSJassi Brar /* If this is the 'overlay' stereo DAI */ 1755033f43cSJassi Brar static inline bool is_secondary(struct i2s_dai *i2s) 1765033f43cSJassi Brar { 1775033f43cSJassi Brar return i2s->pri_dai ? true : false; 1785033f43cSJassi Brar } 1795033f43cSJassi Brar 1805033f43cSJassi Brar /* If operating in SoC-Slave mode */ 1815033f43cSJassi Brar static inline bool is_slave(struct i2s_dai *i2s) 1825033f43cSJassi Brar { 1835033f43cSJassi Brar return (readl(i2s->addr + I2SMOD) & MOD_SLAVE) ? true : false; 1845033f43cSJassi Brar } 1855033f43cSJassi Brar 1865033f43cSJassi Brar /* If this interface of the controller is transmitting data */ 1875033f43cSJassi Brar static inline bool tx_active(struct i2s_dai *i2s) 1885033f43cSJassi Brar { 1895033f43cSJassi Brar u32 active; 1905033f43cSJassi Brar 1915033f43cSJassi Brar if (!i2s) 1925033f43cSJassi Brar return false; 1935033f43cSJassi Brar 1945033f43cSJassi Brar active = readl(i2s->addr + I2SMOD); 1955033f43cSJassi Brar 1965033f43cSJassi Brar if (is_secondary(i2s)) 1975033f43cSJassi Brar active &= CON_TXSDMA_ACTIVE; 1985033f43cSJassi Brar else 1995033f43cSJassi Brar active &= CON_TXDMA_ACTIVE; 2005033f43cSJassi Brar 2015033f43cSJassi Brar return active ? true : false; 2025033f43cSJassi Brar } 2035033f43cSJassi Brar 2045033f43cSJassi Brar /* If the other interface of the controller is transmitting data */ 2055033f43cSJassi Brar static inline bool other_tx_active(struct i2s_dai *i2s) 2065033f43cSJassi Brar { 2075033f43cSJassi Brar struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai; 2085033f43cSJassi Brar 2095033f43cSJassi Brar return tx_active(other); 2105033f43cSJassi Brar } 2115033f43cSJassi Brar 2125033f43cSJassi Brar /* If any interface of the controller is transmitting data */ 2135033f43cSJassi Brar static inline bool any_tx_active(struct i2s_dai *i2s) 2145033f43cSJassi Brar { 2155033f43cSJassi Brar return tx_active(i2s) || other_tx_active(i2s); 2165033f43cSJassi Brar } 2175033f43cSJassi Brar 2185033f43cSJassi Brar /* If this interface of the controller is receiving data */ 2195033f43cSJassi Brar static inline bool rx_active(struct i2s_dai *i2s) 2205033f43cSJassi Brar { 2215033f43cSJassi Brar u32 active; 2225033f43cSJassi Brar 2235033f43cSJassi Brar if (!i2s) 2245033f43cSJassi Brar return false; 2255033f43cSJassi Brar 2265033f43cSJassi Brar active = readl(i2s->addr + I2SMOD) & CON_RXDMA_ACTIVE; 2275033f43cSJassi Brar 2285033f43cSJassi Brar return active ? true : false; 2295033f43cSJassi Brar } 2305033f43cSJassi Brar 2315033f43cSJassi Brar /* If the other interface of the controller is receiving data */ 2325033f43cSJassi Brar static inline bool other_rx_active(struct i2s_dai *i2s) 2335033f43cSJassi Brar { 2345033f43cSJassi Brar struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai; 2355033f43cSJassi Brar 2365033f43cSJassi Brar return rx_active(other); 2375033f43cSJassi Brar } 2385033f43cSJassi Brar 2395033f43cSJassi Brar /* If any interface of the controller is receiving data */ 2405033f43cSJassi Brar static inline bool any_rx_active(struct i2s_dai *i2s) 2415033f43cSJassi Brar { 2425033f43cSJassi Brar return rx_active(i2s) || other_rx_active(i2s); 2435033f43cSJassi Brar } 2445033f43cSJassi Brar 2455033f43cSJassi Brar /* If the other DAI is transmitting or receiving data */ 2465033f43cSJassi Brar static inline bool other_active(struct i2s_dai *i2s) 2475033f43cSJassi Brar { 2485033f43cSJassi Brar return other_rx_active(i2s) || other_tx_active(i2s); 2495033f43cSJassi Brar } 2505033f43cSJassi Brar 2515033f43cSJassi Brar /* If this DAI is transmitting or receiving data */ 2525033f43cSJassi Brar static inline bool this_active(struct i2s_dai *i2s) 2535033f43cSJassi Brar { 2545033f43cSJassi Brar return tx_active(i2s) || rx_active(i2s); 2555033f43cSJassi Brar } 2565033f43cSJassi Brar 2575033f43cSJassi Brar /* If the controller is active anyway */ 2585033f43cSJassi Brar static inline bool any_active(struct i2s_dai *i2s) 2595033f43cSJassi Brar { 2605033f43cSJassi Brar return this_active(i2s) || other_active(i2s); 2615033f43cSJassi Brar } 2625033f43cSJassi Brar 2635033f43cSJassi Brar static inline struct i2s_dai *to_info(struct snd_soc_dai *dai) 2645033f43cSJassi Brar { 2655033f43cSJassi Brar return snd_soc_dai_get_drvdata(dai); 2665033f43cSJassi Brar } 2675033f43cSJassi Brar 2685033f43cSJassi Brar static inline bool is_opened(struct i2s_dai *i2s) 2695033f43cSJassi Brar { 2705033f43cSJassi Brar if (i2s && (i2s->mode & DAI_OPENED)) 2715033f43cSJassi Brar return true; 2725033f43cSJassi Brar else 2735033f43cSJassi Brar return false; 2745033f43cSJassi Brar } 2755033f43cSJassi Brar 2765033f43cSJassi Brar static inline bool is_manager(struct i2s_dai *i2s) 2775033f43cSJassi Brar { 2785033f43cSJassi Brar if (is_opened(i2s) && (i2s->mode & DAI_MANAGER)) 2795033f43cSJassi Brar return true; 2805033f43cSJassi Brar else 2815033f43cSJassi Brar return false; 2825033f43cSJassi Brar } 2835033f43cSJassi Brar 2845033f43cSJassi Brar /* Read RCLK of I2S (in multiples of LRCLK) */ 2855033f43cSJassi Brar static inline unsigned get_rfs(struct i2s_dai *i2s) 2865033f43cSJassi Brar { 2875033f43cSJassi Brar u32 rfs = (readl(i2s->addr + I2SMOD) >> 3) & 0x3; 2885033f43cSJassi Brar 2895033f43cSJassi Brar switch (rfs) { 2905033f43cSJassi Brar case 3: return 768; 2915033f43cSJassi Brar case 2: return 384; 2925033f43cSJassi Brar case 1: return 512; 2935033f43cSJassi Brar default: return 256; 2945033f43cSJassi Brar } 2955033f43cSJassi Brar } 2965033f43cSJassi Brar 2975033f43cSJassi Brar /* Write RCLK of I2S (in multiples of LRCLK) */ 2985033f43cSJassi Brar static inline void set_rfs(struct i2s_dai *i2s, unsigned rfs) 2995033f43cSJassi Brar { 3005033f43cSJassi Brar u32 mod = readl(i2s->addr + I2SMOD); 3015033f43cSJassi Brar 3025033f43cSJassi Brar mod &= ~MOD_RCLK_MASK; 3035033f43cSJassi Brar 3045033f43cSJassi Brar switch (rfs) { 3055033f43cSJassi Brar case 768: 3065033f43cSJassi Brar mod |= MOD_RCLK_768FS; 3075033f43cSJassi Brar break; 3085033f43cSJassi Brar case 512: 3095033f43cSJassi Brar mod |= MOD_RCLK_512FS; 3105033f43cSJassi Brar break; 3115033f43cSJassi Brar case 384: 3125033f43cSJassi Brar mod |= MOD_RCLK_384FS; 3135033f43cSJassi Brar break; 3145033f43cSJassi Brar default: 3155033f43cSJassi Brar mod |= MOD_RCLK_256FS; 3165033f43cSJassi Brar break; 3175033f43cSJassi Brar } 3185033f43cSJassi Brar 3195033f43cSJassi Brar writel(mod, i2s->addr + I2SMOD); 3205033f43cSJassi Brar } 3215033f43cSJassi Brar 3225033f43cSJassi Brar /* Read Bit-Clock of I2S (in multiples of LRCLK) */ 3235033f43cSJassi Brar static inline unsigned get_bfs(struct i2s_dai *i2s) 3245033f43cSJassi Brar { 3255033f43cSJassi Brar u32 bfs = (readl(i2s->addr + I2SMOD) >> 1) & 0x3; 3265033f43cSJassi Brar 3275033f43cSJassi Brar switch (bfs) { 3285033f43cSJassi Brar case 3: return 24; 3295033f43cSJassi Brar case 2: return 16; 3305033f43cSJassi Brar case 1: return 48; 3315033f43cSJassi Brar default: return 32; 3325033f43cSJassi Brar } 3335033f43cSJassi Brar } 3345033f43cSJassi Brar 3355033f43cSJassi Brar /* Write Bit-Clock of I2S (in multiples of LRCLK) */ 3365033f43cSJassi Brar static inline void set_bfs(struct i2s_dai *i2s, unsigned bfs) 3375033f43cSJassi Brar { 3385033f43cSJassi Brar u32 mod = readl(i2s->addr + I2SMOD); 3395033f43cSJassi Brar 3405033f43cSJassi Brar mod &= ~MOD_BCLK_MASK; 3415033f43cSJassi Brar 3425033f43cSJassi Brar switch (bfs) { 3435033f43cSJassi Brar case 48: 3445033f43cSJassi Brar mod |= MOD_BCLK_48FS; 3455033f43cSJassi Brar break; 3465033f43cSJassi Brar case 32: 3475033f43cSJassi Brar mod |= MOD_BCLK_32FS; 3485033f43cSJassi Brar break; 3495033f43cSJassi Brar case 24: 3505033f43cSJassi Brar mod |= MOD_BCLK_24FS; 3515033f43cSJassi Brar break; 3525033f43cSJassi Brar case 16: 3535033f43cSJassi Brar mod |= MOD_BCLK_16FS; 3545033f43cSJassi Brar break; 3555033f43cSJassi Brar default: 3565033f43cSJassi Brar dev_err(&i2s->pdev->dev, "Wrong BCLK Divider!\n"); 3575033f43cSJassi Brar return; 3585033f43cSJassi Brar } 3595033f43cSJassi Brar 3605033f43cSJassi Brar writel(mod, i2s->addr + I2SMOD); 3615033f43cSJassi Brar } 3625033f43cSJassi Brar 3635033f43cSJassi Brar /* Sample-Size */ 3645033f43cSJassi Brar static inline int get_blc(struct i2s_dai *i2s) 3655033f43cSJassi Brar { 3665033f43cSJassi Brar int blc = readl(i2s->addr + I2SMOD); 3675033f43cSJassi Brar 3685033f43cSJassi Brar blc = (blc >> 13) & 0x3; 3695033f43cSJassi Brar 3705033f43cSJassi Brar switch (blc) { 3715033f43cSJassi Brar case 2: return 24; 3725033f43cSJassi Brar case 1: return 8; 3735033f43cSJassi Brar default: return 16; 3745033f43cSJassi Brar } 3755033f43cSJassi Brar } 3765033f43cSJassi Brar 3775033f43cSJassi Brar /* TX Channel Control */ 3785033f43cSJassi Brar static void i2s_txctrl(struct i2s_dai *i2s, int on) 3795033f43cSJassi Brar { 3805033f43cSJassi Brar void __iomem *addr = i2s->addr; 3815033f43cSJassi Brar u32 con = readl(addr + I2SCON); 3825033f43cSJassi Brar u32 mod = readl(addr + I2SMOD) & ~MOD_MASK; 3835033f43cSJassi Brar 3845033f43cSJassi Brar if (on) { 3855033f43cSJassi Brar con |= CON_ACTIVE; 3865033f43cSJassi Brar con &= ~CON_TXCH_PAUSE; 3875033f43cSJassi Brar 3885033f43cSJassi Brar if (is_secondary(i2s)) { 3895033f43cSJassi Brar con |= CON_TXSDMA_ACTIVE; 3905033f43cSJassi Brar con &= ~CON_TXSDMA_PAUSE; 3915033f43cSJassi Brar } else { 3925033f43cSJassi Brar con |= CON_TXDMA_ACTIVE; 3935033f43cSJassi Brar con &= ~CON_TXDMA_PAUSE; 3945033f43cSJassi Brar } 3955033f43cSJassi Brar 3965033f43cSJassi Brar if (any_rx_active(i2s)) 3975033f43cSJassi Brar mod |= MOD_TXRX; 3985033f43cSJassi Brar else 3995033f43cSJassi Brar mod |= MOD_TXONLY; 4005033f43cSJassi Brar } else { 4015033f43cSJassi Brar if (is_secondary(i2s)) { 4025033f43cSJassi Brar con |= CON_TXSDMA_PAUSE; 4035033f43cSJassi Brar con &= ~CON_TXSDMA_ACTIVE; 4045033f43cSJassi Brar } else { 4055033f43cSJassi Brar con |= CON_TXDMA_PAUSE; 4065033f43cSJassi Brar con &= ~CON_TXDMA_ACTIVE; 4075033f43cSJassi Brar } 4085033f43cSJassi Brar 4095033f43cSJassi Brar if (other_tx_active(i2s)) { 4105033f43cSJassi Brar writel(con, addr + I2SCON); 4115033f43cSJassi Brar return; 4125033f43cSJassi Brar } 4135033f43cSJassi Brar 4145033f43cSJassi Brar con |= CON_TXCH_PAUSE; 4155033f43cSJassi Brar 4165033f43cSJassi Brar if (any_rx_active(i2s)) 4175033f43cSJassi Brar mod |= MOD_RXONLY; 4185033f43cSJassi Brar else 4195033f43cSJassi Brar con &= ~CON_ACTIVE; 4205033f43cSJassi Brar } 4215033f43cSJassi Brar 4225033f43cSJassi Brar writel(mod, addr + I2SMOD); 4235033f43cSJassi Brar writel(con, addr + I2SCON); 4245033f43cSJassi Brar } 4255033f43cSJassi Brar 4265033f43cSJassi Brar /* RX Channel Control */ 4275033f43cSJassi Brar static void i2s_rxctrl(struct i2s_dai *i2s, int on) 4285033f43cSJassi Brar { 4295033f43cSJassi Brar void __iomem *addr = i2s->addr; 4305033f43cSJassi Brar u32 con = readl(addr + I2SCON); 4315033f43cSJassi Brar u32 mod = readl(addr + I2SMOD) & ~MOD_MASK; 4325033f43cSJassi Brar 4335033f43cSJassi Brar if (on) { 4345033f43cSJassi Brar con |= CON_RXDMA_ACTIVE | CON_ACTIVE; 4355033f43cSJassi Brar con &= ~(CON_RXDMA_PAUSE | CON_RXCH_PAUSE); 4365033f43cSJassi Brar 4375033f43cSJassi Brar if (any_tx_active(i2s)) 4385033f43cSJassi Brar mod |= MOD_TXRX; 4395033f43cSJassi Brar else 4405033f43cSJassi Brar mod |= MOD_RXONLY; 4415033f43cSJassi Brar } else { 4425033f43cSJassi Brar con |= CON_RXDMA_PAUSE | CON_RXCH_PAUSE; 4435033f43cSJassi Brar con &= ~CON_RXDMA_ACTIVE; 4445033f43cSJassi Brar 4455033f43cSJassi Brar if (any_tx_active(i2s)) 4465033f43cSJassi Brar mod |= MOD_TXONLY; 4475033f43cSJassi Brar else 4485033f43cSJassi Brar con &= ~CON_ACTIVE; 4495033f43cSJassi Brar } 4505033f43cSJassi Brar 4515033f43cSJassi Brar writel(mod, addr + I2SMOD); 4525033f43cSJassi Brar writel(con, addr + I2SCON); 4535033f43cSJassi Brar } 4545033f43cSJassi Brar 4555033f43cSJassi Brar /* Flush FIFO of an interface */ 4565033f43cSJassi Brar static inline void i2s_fifo(struct i2s_dai *i2s, u32 flush) 4575033f43cSJassi Brar { 4585033f43cSJassi Brar void __iomem *fic; 4595033f43cSJassi Brar u32 val; 4605033f43cSJassi Brar 4615033f43cSJassi Brar if (!i2s) 4625033f43cSJassi Brar return; 4635033f43cSJassi Brar 4645033f43cSJassi Brar if (is_secondary(i2s)) 4655033f43cSJassi Brar fic = i2s->addr + I2SFICS; 4665033f43cSJassi Brar else 4675033f43cSJassi Brar fic = i2s->addr + I2SFIC; 4685033f43cSJassi Brar 4695033f43cSJassi Brar /* Flush the FIFO */ 4705033f43cSJassi Brar writel(readl(fic) | flush, fic); 4715033f43cSJassi Brar 4725033f43cSJassi Brar /* Be patient */ 4735033f43cSJassi Brar val = msecs_to_loops(1) / 1000; /* 1 usec */ 4745033f43cSJassi Brar while (--val) 4755033f43cSJassi Brar cpu_relax(); 4765033f43cSJassi Brar 4775033f43cSJassi Brar writel(readl(fic) & ~flush, fic); 4785033f43cSJassi Brar } 4795033f43cSJassi Brar 4805033f43cSJassi Brar static int i2s_set_sysclk(struct snd_soc_dai *dai, 4815033f43cSJassi Brar int clk_id, unsigned int rfs, int dir) 4825033f43cSJassi Brar { 4835033f43cSJassi Brar struct i2s_dai *i2s = to_info(dai); 4845033f43cSJassi Brar struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai; 4855033f43cSJassi Brar u32 mod = readl(i2s->addr + I2SMOD); 4865033f43cSJassi Brar 4875033f43cSJassi Brar switch (clk_id) { 4885033f43cSJassi Brar case SAMSUNG_I2S_CDCLK: 4895033f43cSJassi Brar /* Shouldn't matter in GATING(CLOCK_IN) mode */ 4905033f43cSJassi Brar if (dir == SND_SOC_CLOCK_IN) 4915033f43cSJassi Brar rfs = 0; 4925033f43cSJassi Brar 4935033f43cSJassi Brar if ((rfs && other->rfs && (other->rfs != rfs)) || 4945033f43cSJassi Brar (any_active(i2s) && 4955033f43cSJassi Brar (((dir == SND_SOC_CLOCK_IN) 4965033f43cSJassi Brar && !(mod & MOD_CDCLKCON)) || 4975033f43cSJassi Brar ((dir == SND_SOC_CLOCK_OUT) 4985033f43cSJassi Brar && (mod & MOD_CDCLKCON))))) { 4995033f43cSJassi Brar dev_err(&i2s->pdev->dev, 5005033f43cSJassi Brar "%s:%d Other DAI busy\n", __func__, __LINE__); 5015033f43cSJassi Brar return -EAGAIN; 5025033f43cSJassi Brar } 5035033f43cSJassi Brar 5045033f43cSJassi Brar if (dir == SND_SOC_CLOCK_IN) 5055033f43cSJassi Brar mod |= MOD_CDCLKCON; 5065033f43cSJassi Brar else 5075033f43cSJassi Brar mod &= ~MOD_CDCLKCON; 5085033f43cSJassi Brar 5095033f43cSJassi Brar i2s->rfs = rfs; 5105033f43cSJassi Brar break; 5115033f43cSJassi Brar 5125033f43cSJassi Brar case SAMSUNG_I2S_RCLKSRC_0: /* clock corrsponding to IISMOD[10] := 0 */ 5135033f43cSJassi Brar case SAMSUNG_I2S_RCLKSRC_1: /* clock corrsponding to IISMOD[10] := 1 */ 5145033f43cSJassi Brar if ((i2s->quirks & QUIRK_NO_MUXPSR) 5155033f43cSJassi Brar || (clk_id == SAMSUNG_I2S_RCLKSRC_0)) 5165033f43cSJassi Brar clk_id = 0; 5175033f43cSJassi Brar else 5185033f43cSJassi Brar clk_id = 1; 5195033f43cSJassi Brar 5205033f43cSJassi Brar if (!any_active(i2s)) { 5215033f43cSJassi Brar if (i2s->op_clk) { 5225033f43cSJassi Brar if ((clk_id && !(mod & MOD_IMS_SYSMUX)) || 5235033f43cSJassi Brar (!clk_id && (mod & MOD_IMS_SYSMUX))) { 5245033f43cSJassi Brar clk_disable(i2s->op_clk); 5255033f43cSJassi Brar clk_put(i2s->op_clk); 5265033f43cSJassi Brar } else { 5276ce534aaSJassi Brar i2s->rclk_srcrate = 5286ce534aaSJassi Brar clk_get_rate(i2s->op_clk); 5295033f43cSJassi Brar return 0; 5305033f43cSJassi Brar } 5315033f43cSJassi Brar } 5325033f43cSJassi Brar 5335033f43cSJassi Brar i2s->op_clk = clk_get(&i2s->pdev->dev, 5345033f43cSJassi Brar i2s->src_clk[clk_id]); 5355033f43cSJassi Brar clk_enable(i2s->op_clk); 5365033f43cSJassi Brar i2s->rclk_srcrate = clk_get_rate(i2s->op_clk); 5375033f43cSJassi Brar 5385033f43cSJassi Brar /* Over-ride the other's */ 5395033f43cSJassi Brar if (other) { 5405033f43cSJassi Brar other->op_clk = i2s->op_clk; 5415033f43cSJassi Brar other->rclk_srcrate = i2s->rclk_srcrate; 5425033f43cSJassi Brar } 5435033f43cSJassi Brar } else if ((!clk_id && (mod & MOD_IMS_SYSMUX)) 5445033f43cSJassi Brar || (clk_id && !(mod & MOD_IMS_SYSMUX))) { 5455033f43cSJassi Brar dev_err(&i2s->pdev->dev, 5465033f43cSJassi Brar "%s:%d Other DAI busy\n", __func__, __LINE__); 5475033f43cSJassi Brar return -EAGAIN; 5485033f43cSJassi Brar } else { 5495033f43cSJassi Brar /* Call can't be on the active DAI */ 5505033f43cSJassi Brar i2s->op_clk = other->op_clk; 5515033f43cSJassi Brar i2s->rclk_srcrate = other->rclk_srcrate; 5525033f43cSJassi Brar return 0; 5535033f43cSJassi Brar } 5545033f43cSJassi Brar 5555033f43cSJassi Brar if (clk_id == 0) 5565033f43cSJassi Brar mod &= ~MOD_IMS_SYSMUX; 5575033f43cSJassi Brar else 5585033f43cSJassi Brar mod |= MOD_IMS_SYSMUX; 5595033f43cSJassi Brar break; 5605033f43cSJassi Brar 5615033f43cSJassi Brar default: 5625033f43cSJassi Brar dev_err(&i2s->pdev->dev, "We don't serve that!\n"); 5635033f43cSJassi Brar return -EINVAL; 5645033f43cSJassi Brar } 5655033f43cSJassi Brar 5665033f43cSJassi Brar writel(mod, i2s->addr + I2SMOD); 5675033f43cSJassi Brar 5685033f43cSJassi Brar return 0; 5695033f43cSJassi Brar } 5705033f43cSJassi Brar 5715033f43cSJassi Brar static int i2s_set_fmt(struct snd_soc_dai *dai, 5725033f43cSJassi Brar unsigned int fmt) 5735033f43cSJassi Brar { 5745033f43cSJassi Brar struct i2s_dai *i2s = to_info(dai); 5755033f43cSJassi Brar u32 mod = readl(i2s->addr + I2SMOD); 5765033f43cSJassi Brar u32 tmp = 0; 5775033f43cSJassi Brar 5785033f43cSJassi Brar /* Format is priority */ 5795033f43cSJassi Brar switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 5805033f43cSJassi Brar case SND_SOC_DAIFMT_RIGHT_J: 5815033f43cSJassi Brar tmp |= MOD_LR_RLOW; 5825033f43cSJassi Brar tmp |= MOD_SDF_MSB; 5835033f43cSJassi Brar break; 5845033f43cSJassi Brar case SND_SOC_DAIFMT_LEFT_J: 5855033f43cSJassi Brar tmp |= MOD_LR_RLOW; 5865033f43cSJassi Brar tmp |= MOD_SDF_LSB; 5875033f43cSJassi Brar break; 5885033f43cSJassi Brar case SND_SOC_DAIFMT_I2S: 5895033f43cSJassi Brar tmp |= MOD_SDF_IIS; 5905033f43cSJassi Brar break; 5915033f43cSJassi Brar default: 5925033f43cSJassi Brar dev_err(&i2s->pdev->dev, "Format not supported\n"); 5935033f43cSJassi Brar return -EINVAL; 5945033f43cSJassi Brar } 5955033f43cSJassi Brar 5965033f43cSJassi Brar /* 5975033f43cSJassi Brar * INV flag is relative to the FORMAT flag - if set it simply 5985033f43cSJassi Brar * flips the polarity specified by the Standard 5995033f43cSJassi Brar */ 6005033f43cSJassi Brar switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 6015033f43cSJassi Brar case SND_SOC_DAIFMT_NB_NF: 6025033f43cSJassi Brar break; 6035033f43cSJassi Brar case SND_SOC_DAIFMT_NB_IF: 6045033f43cSJassi Brar if (tmp & MOD_LR_RLOW) 6055033f43cSJassi Brar tmp &= ~MOD_LR_RLOW; 6065033f43cSJassi Brar else 6075033f43cSJassi Brar tmp |= MOD_LR_RLOW; 6085033f43cSJassi Brar break; 6095033f43cSJassi Brar default: 6105033f43cSJassi Brar dev_err(&i2s->pdev->dev, "Polarity not supported\n"); 6115033f43cSJassi Brar return -EINVAL; 6125033f43cSJassi Brar } 6135033f43cSJassi Brar 6145033f43cSJassi Brar switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 6155033f43cSJassi Brar case SND_SOC_DAIFMT_CBM_CFM: 6165033f43cSJassi Brar tmp |= MOD_SLAVE; 6175033f43cSJassi Brar break; 6185033f43cSJassi Brar case SND_SOC_DAIFMT_CBS_CFS: 6195033f43cSJassi Brar /* Set default source clock in Master mode */ 6205033f43cSJassi Brar if (i2s->rclk_srcrate == 0) 6215033f43cSJassi Brar i2s_set_sysclk(dai, SAMSUNG_I2S_RCLKSRC_0, 6225033f43cSJassi Brar 0, SND_SOC_CLOCK_IN); 6235033f43cSJassi Brar break; 6245033f43cSJassi Brar default: 6255033f43cSJassi Brar dev_err(&i2s->pdev->dev, "master/slave format not supported\n"); 6265033f43cSJassi Brar return -EINVAL; 6275033f43cSJassi Brar } 6285033f43cSJassi Brar 6295033f43cSJassi Brar if (any_active(i2s) && 6305033f43cSJassi Brar ((mod & (MOD_SDF_MASK | MOD_LR_RLOW 6315033f43cSJassi Brar | MOD_SLAVE)) != tmp)) { 6325033f43cSJassi Brar dev_err(&i2s->pdev->dev, 6335033f43cSJassi Brar "%s:%d Other DAI busy\n", __func__, __LINE__); 6345033f43cSJassi Brar return -EAGAIN; 6355033f43cSJassi Brar } 6365033f43cSJassi Brar 6375033f43cSJassi Brar mod &= ~(MOD_SDF_MASK | MOD_LR_RLOW | MOD_SLAVE); 6385033f43cSJassi Brar mod |= tmp; 6395033f43cSJassi Brar writel(mod, i2s->addr + I2SMOD); 6405033f43cSJassi Brar 6415033f43cSJassi Brar return 0; 6425033f43cSJassi Brar } 6435033f43cSJassi Brar 6445033f43cSJassi Brar static int i2s_hw_params(struct snd_pcm_substream *substream, 6455033f43cSJassi Brar struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) 6465033f43cSJassi Brar { 6475033f43cSJassi Brar struct i2s_dai *i2s = to_info(dai); 6485033f43cSJassi Brar u32 mod = readl(i2s->addr + I2SMOD); 6495033f43cSJassi Brar 6505033f43cSJassi Brar if (!is_secondary(i2s)) 6515033f43cSJassi Brar mod &= ~(MOD_DC2_EN | MOD_DC1_EN); 6525033f43cSJassi Brar 6535033f43cSJassi Brar switch (params_channels(params)) { 6545033f43cSJassi Brar case 6: 6555033f43cSJassi Brar mod |= MOD_DC2_EN; 6565033f43cSJassi Brar case 4: 6575033f43cSJassi Brar mod |= MOD_DC1_EN; 6585033f43cSJassi Brar break; 6595033f43cSJassi Brar case 2: 6605033f43cSJassi Brar break; 6615033f43cSJassi Brar default: 6625033f43cSJassi Brar dev_err(&i2s->pdev->dev, "%d channels not supported\n", 6635033f43cSJassi Brar params_channels(params)); 6645033f43cSJassi Brar return -EINVAL; 6655033f43cSJassi Brar } 6665033f43cSJassi Brar 6675033f43cSJassi Brar if (is_secondary(i2s)) 6685033f43cSJassi Brar mod &= ~MOD_BLCS_MASK; 6695033f43cSJassi Brar else 6705033f43cSJassi Brar mod &= ~MOD_BLCP_MASK; 6715033f43cSJassi Brar 6725033f43cSJassi Brar if (is_manager(i2s)) 6735033f43cSJassi Brar mod &= ~MOD_BLC_MASK; 6745033f43cSJassi Brar 6755033f43cSJassi Brar switch (params_format(params)) { 6765033f43cSJassi Brar case SNDRV_PCM_FORMAT_S8: 6775033f43cSJassi Brar if (is_secondary(i2s)) 6785033f43cSJassi Brar mod |= MOD_BLCS_8BIT; 6795033f43cSJassi Brar else 6805033f43cSJassi Brar mod |= MOD_BLCP_8BIT; 6815033f43cSJassi Brar if (is_manager(i2s)) 6825033f43cSJassi Brar mod |= MOD_BLC_8BIT; 6835033f43cSJassi Brar break; 6845033f43cSJassi Brar case SNDRV_PCM_FORMAT_S16_LE: 6855033f43cSJassi Brar if (is_secondary(i2s)) 6865033f43cSJassi Brar mod |= MOD_BLCS_16BIT; 6875033f43cSJassi Brar else 6885033f43cSJassi Brar mod |= MOD_BLCP_16BIT; 6895033f43cSJassi Brar if (is_manager(i2s)) 6905033f43cSJassi Brar mod |= MOD_BLC_16BIT; 6915033f43cSJassi Brar break; 6925033f43cSJassi Brar case SNDRV_PCM_FORMAT_S24_LE: 6935033f43cSJassi Brar if (is_secondary(i2s)) 6945033f43cSJassi Brar mod |= MOD_BLCS_24BIT; 6955033f43cSJassi Brar else 6965033f43cSJassi Brar mod |= MOD_BLCP_24BIT; 6975033f43cSJassi Brar if (is_manager(i2s)) 6985033f43cSJassi Brar mod |= MOD_BLC_24BIT; 6995033f43cSJassi Brar break; 7005033f43cSJassi Brar default: 7015033f43cSJassi Brar dev_err(&i2s->pdev->dev, "Format(%d) not supported\n", 7025033f43cSJassi Brar params_format(params)); 7035033f43cSJassi Brar return -EINVAL; 7045033f43cSJassi Brar } 7055033f43cSJassi Brar writel(mod, i2s->addr + I2SMOD); 7065033f43cSJassi Brar 7075033f43cSJassi Brar if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 7085033f43cSJassi Brar snd_soc_dai_set_dma_data(dai, substream, 7095033f43cSJassi Brar (void *)&i2s->dma_playback); 7105033f43cSJassi Brar else 7115033f43cSJassi Brar snd_soc_dai_set_dma_data(dai, substream, 7125033f43cSJassi Brar (void *)&i2s->dma_capture); 7135033f43cSJassi Brar 7145033f43cSJassi Brar i2s->frmclk = params_rate(params); 7155033f43cSJassi Brar 7165033f43cSJassi Brar return 0; 7175033f43cSJassi Brar } 7185033f43cSJassi Brar 7195033f43cSJassi Brar /* We set constraints on the substream acc to the version of I2S */ 7205033f43cSJassi Brar static int i2s_startup(struct snd_pcm_substream *substream, 7215033f43cSJassi Brar struct snd_soc_dai *dai) 7225033f43cSJassi Brar { 7235033f43cSJassi Brar struct i2s_dai *i2s = to_info(dai); 7245033f43cSJassi Brar struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai; 7255033f43cSJassi Brar unsigned long flags; 7265033f43cSJassi Brar 7275033f43cSJassi Brar spin_lock_irqsave(&lock, flags); 7285033f43cSJassi Brar 7295033f43cSJassi Brar i2s->mode |= DAI_OPENED; 7305033f43cSJassi Brar 7315033f43cSJassi Brar if (is_manager(other)) 7325033f43cSJassi Brar i2s->mode &= ~DAI_MANAGER; 7335033f43cSJassi Brar else 7345033f43cSJassi Brar i2s->mode |= DAI_MANAGER; 7355033f43cSJassi Brar 7365033f43cSJassi Brar /* Enforce set_sysclk in Master mode */ 7375033f43cSJassi Brar i2s->rclk_srcrate = 0; 7385033f43cSJassi Brar 7395033f43cSJassi Brar spin_unlock_irqrestore(&lock, flags); 7405033f43cSJassi Brar 7415033f43cSJassi Brar return 0; 7425033f43cSJassi Brar } 7435033f43cSJassi Brar 7445033f43cSJassi Brar static void i2s_shutdown(struct snd_pcm_substream *substream, 7455033f43cSJassi Brar struct snd_soc_dai *dai) 7465033f43cSJassi Brar { 7475033f43cSJassi Brar struct i2s_dai *i2s = to_info(dai); 7485033f43cSJassi Brar struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai; 7495033f43cSJassi Brar unsigned long flags; 7505033f43cSJassi Brar 7515033f43cSJassi Brar spin_lock_irqsave(&lock, flags); 7525033f43cSJassi Brar 7535033f43cSJassi Brar i2s->mode &= ~DAI_OPENED; 7545033f43cSJassi Brar i2s->mode &= ~DAI_MANAGER; 7555033f43cSJassi Brar 7565033f43cSJassi Brar if (is_opened(other)) 7575033f43cSJassi Brar other->mode |= DAI_MANAGER; 7585033f43cSJassi Brar 7595033f43cSJassi Brar /* Reset any constraint on RFS and BFS */ 7605033f43cSJassi Brar i2s->rfs = 0; 7615033f43cSJassi Brar i2s->bfs = 0; 7625033f43cSJassi Brar 7635033f43cSJassi Brar spin_unlock_irqrestore(&lock, flags); 7645033f43cSJassi Brar 7655033f43cSJassi Brar /* Gate CDCLK by default */ 7665033f43cSJassi Brar if (!is_opened(other)) 7675033f43cSJassi Brar i2s_set_sysclk(dai, SAMSUNG_I2S_CDCLK, 7685033f43cSJassi Brar 0, SND_SOC_CLOCK_IN); 7695033f43cSJassi Brar } 7705033f43cSJassi Brar 7715033f43cSJassi Brar static int config_setup(struct i2s_dai *i2s) 7725033f43cSJassi Brar { 7735033f43cSJassi Brar struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai; 7745033f43cSJassi Brar unsigned rfs, bfs, blc; 7755033f43cSJassi Brar u32 psr; 7765033f43cSJassi Brar 7775033f43cSJassi Brar blc = get_blc(i2s); 7785033f43cSJassi Brar 7795033f43cSJassi Brar bfs = i2s->bfs; 7805033f43cSJassi Brar 7815033f43cSJassi Brar if (!bfs && other) 7825033f43cSJassi Brar bfs = other->bfs; 7835033f43cSJassi Brar 7845033f43cSJassi Brar /* Select least possible multiple(2) if no constraint set */ 7855033f43cSJassi Brar if (!bfs) 7865033f43cSJassi Brar bfs = blc * 2; 7875033f43cSJassi Brar 7885033f43cSJassi Brar rfs = i2s->rfs; 7895033f43cSJassi Brar 7905033f43cSJassi Brar if (!rfs && other) 7915033f43cSJassi Brar rfs = other->rfs; 7925033f43cSJassi Brar 7935033f43cSJassi Brar if ((rfs == 256 || rfs == 512) && (blc == 24)) { 7945033f43cSJassi Brar dev_err(&i2s->pdev->dev, 7955033f43cSJassi Brar "%d-RFS not supported for 24-blc\n", rfs); 7965033f43cSJassi Brar return -EINVAL; 7975033f43cSJassi Brar } 7985033f43cSJassi Brar 7995033f43cSJassi Brar if (!rfs) { 8005033f43cSJassi Brar if (bfs == 16 || bfs == 32) 8015033f43cSJassi Brar rfs = 256; 8025033f43cSJassi Brar else 8035033f43cSJassi Brar rfs = 384; 8045033f43cSJassi Brar } 8055033f43cSJassi Brar 8065033f43cSJassi Brar /* If already setup and running */ 8075033f43cSJassi Brar if (any_active(i2s) && (get_rfs(i2s) != rfs || get_bfs(i2s) != bfs)) { 8085033f43cSJassi Brar dev_err(&i2s->pdev->dev, 8095033f43cSJassi Brar "%s:%d Other DAI busy\n", __func__, __LINE__); 8105033f43cSJassi Brar return -EAGAIN; 8115033f43cSJassi Brar } 8125033f43cSJassi Brar 8135033f43cSJassi Brar /* Don't bother RFS, BFS & PSR in Slave mode */ 8145033f43cSJassi Brar if (is_slave(i2s)) 8155033f43cSJassi Brar return 0; 8165033f43cSJassi Brar 8175033f43cSJassi Brar set_bfs(i2s, bfs); 8185033f43cSJassi Brar set_rfs(i2s, rfs); 8195033f43cSJassi Brar 8205033f43cSJassi Brar if (!(i2s->quirks & QUIRK_NO_MUXPSR)) { 8215033f43cSJassi Brar psr = i2s->rclk_srcrate / i2s->frmclk / rfs; 8225033f43cSJassi Brar writel(((psr - 1) << 8) | PSR_PSREN, i2s->addr + I2SPSR); 8235033f43cSJassi Brar dev_dbg(&i2s->pdev->dev, 8245033f43cSJassi Brar "RCLK_SRC=%luHz PSR=%u, RCLK=%dfs, BCLK=%dfs\n", 8255033f43cSJassi Brar i2s->rclk_srcrate, psr, rfs, bfs); 8265033f43cSJassi Brar } 8275033f43cSJassi Brar 8285033f43cSJassi Brar return 0; 8295033f43cSJassi Brar } 8305033f43cSJassi Brar 8315033f43cSJassi Brar static int i2s_trigger(struct snd_pcm_substream *substream, 8325033f43cSJassi Brar int cmd, struct snd_soc_dai *dai) 8335033f43cSJassi Brar { 8345033f43cSJassi Brar int capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE); 8355033f43cSJassi Brar struct snd_soc_pcm_runtime *rtd = substream->private_data; 8365033f43cSJassi Brar struct i2s_dai *i2s = to_info(rtd->cpu_dai); 8375033f43cSJassi Brar unsigned long flags; 8385033f43cSJassi Brar 8395033f43cSJassi Brar switch (cmd) { 8405033f43cSJassi Brar case SNDRV_PCM_TRIGGER_START: 8415033f43cSJassi Brar case SNDRV_PCM_TRIGGER_RESUME: 8425033f43cSJassi Brar case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 8435033f43cSJassi Brar local_irq_save(flags); 8445033f43cSJassi Brar 8455033f43cSJassi Brar if (config_setup(i2s)) { 8465033f43cSJassi Brar local_irq_restore(flags); 8475033f43cSJassi Brar return -EINVAL; 8485033f43cSJassi Brar } 8495033f43cSJassi Brar 8505033f43cSJassi Brar if (capture) 8515033f43cSJassi Brar i2s_rxctrl(i2s, 1); 8525033f43cSJassi Brar else 8535033f43cSJassi Brar i2s_txctrl(i2s, 1); 8545033f43cSJassi Brar 8555033f43cSJassi Brar local_irq_restore(flags); 8565033f43cSJassi Brar break; 8575033f43cSJassi Brar case SNDRV_PCM_TRIGGER_STOP: 8585033f43cSJassi Brar case SNDRV_PCM_TRIGGER_SUSPEND: 8595033f43cSJassi Brar case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 8605033f43cSJassi Brar local_irq_save(flags); 8615033f43cSJassi Brar 8625033f43cSJassi Brar if (capture) 8635033f43cSJassi Brar i2s_rxctrl(i2s, 0); 8645033f43cSJassi Brar else 8655033f43cSJassi Brar i2s_txctrl(i2s, 0); 8665033f43cSJassi Brar 867775bc971SJassi Brar if (capture) 868775bc971SJassi Brar i2s_fifo(i2s, FIC_RXFLUSH); 869775bc971SJassi Brar else 870775bc971SJassi Brar i2s_fifo(i2s, FIC_TXFLUSH); 871775bc971SJassi Brar 8725033f43cSJassi Brar local_irq_restore(flags); 8735033f43cSJassi Brar break; 8745033f43cSJassi Brar } 8755033f43cSJassi Brar 8765033f43cSJassi Brar return 0; 8775033f43cSJassi Brar } 8785033f43cSJassi Brar 8795033f43cSJassi Brar static int i2s_set_clkdiv(struct snd_soc_dai *dai, 8805033f43cSJassi Brar int div_id, int div) 8815033f43cSJassi Brar { 8825033f43cSJassi Brar struct i2s_dai *i2s = to_info(dai); 8835033f43cSJassi Brar struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai; 8845033f43cSJassi Brar 8855033f43cSJassi Brar switch (div_id) { 8865033f43cSJassi Brar case SAMSUNG_I2S_DIV_BCLK: 8875033f43cSJassi Brar if ((any_active(i2s) && div && (get_bfs(i2s) != div)) 8885033f43cSJassi Brar || (other && other->bfs && (other->bfs != div))) { 8895033f43cSJassi Brar dev_err(&i2s->pdev->dev, 8905033f43cSJassi Brar "%s:%d Other DAI busy\n", __func__, __LINE__); 8915033f43cSJassi Brar return -EAGAIN; 8925033f43cSJassi Brar } 8935033f43cSJassi Brar i2s->bfs = div; 8945033f43cSJassi Brar break; 8955033f43cSJassi Brar default: 8965033f43cSJassi Brar dev_err(&i2s->pdev->dev, 8975033f43cSJassi Brar "Invalid clock divider(%d)\n", div_id); 8985033f43cSJassi Brar return -EINVAL; 8995033f43cSJassi Brar } 9005033f43cSJassi Brar 9015033f43cSJassi Brar return 0; 9025033f43cSJassi Brar } 9035033f43cSJassi Brar 9045033f43cSJassi Brar static snd_pcm_sframes_t 9055033f43cSJassi Brar i2s_delay(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) 9065033f43cSJassi Brar { 9075033f43cSJassi Brar struct i2s_dai *i2s = to_info(dai); 9085033f43cSJassi Brar u32 reg = readl(i2s->addr + I2SFIC); 9095033f43cSJassi Brar snd_pcm_sframes_t delay; 9105033f43cSJassi Brar 9115033f43cSJassi Brar if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) 9125033f43cSJassi Brar delay = FIC_RXCOUNT(reg); 9135033f43cSJassi Brar else if (is_secondary(i2s)) 9145033f43cSJassi Brar delay = FICS_TXCOUNT(readl(i2s->addr + I2SFICS)); 9155033f43cSJassi Brar else 9165033f43cSJassi Brar delay = FIC_TXCOUNT(reg); 9175033f43cSJassi Brar 9185033f43cSJassi Brar return delay; 9195033f43cSJassi Brar } 9205033f43cSJassi Brar 9215033f43cSJassi Brar #ifdef CONFIG_PM 9225033f43cSJassi Brar static int i2s_suspend(struct snd_soc_dai *dai) 9235033f43cSJassi Brar { 9245033f43cSJassi Brar struct i2s_dai *i2s = to_info(dai); 9255033f43cSJassi Brar 9265033f43cSJassi Brar if (dai->active) { 9275033f43cSJassi Brar i2s->suspend_i2smod = readl(i2s->addr + I2SMOD); 9285033f43cSJassi Brar i2s->suspend_i2scon = readl(i2s->addr + I2SCON); 9295033f43cSJassi Brar i2s->suspend_i2spsr = readl(i2s->addr + I2SPSR); 9305033f43cSJassi Brar } 9315033f43cSJassi Brar 9325033f43cSJassi Brar return 0; 9335033f43cSJassi Brar } 9345033f43cSJassi Brar 9355033f43cSJassi Brar static int i2s_resume(struct snd_soc_dai *dai) 9365033f43cSJassi Brar { 9375033f43cSJassi Brar struct i2s_dai *i2s = to_info(dai); 9385033f43cSJassi Brar 9395033f43cSJassi Brar if (dai->active) { 9405033f43cSJassi Brar writel(i2s->suspend_i2scon, i2s->addr + I2SCON); 9415033f43cSJassi Brar writel(i2s->suspend_i2smod, i2s->addr + I2SMOD); 9425033f43cSJassi Brar writel(i2s->suspend_i2spsr, i2s->addr + I2SPSR); 9435033f43cSJassi Brar } 9445033f43cSJassi Brar 9455033f43cSJassi Brar return 0; 9465033f43cSJassi Brar } 9475033f43cSJassi Brar #else 9485033f43cSJassi Brar #define i2s_suspend NULL 9495033f43cSJassi Brar #define i2s_resume NULL 9505033f43cSJassi Brar #endif 9515033f43cSJassi Brar 9525033f43cSJassi Brar static int samsung_i2s_dai_probe(struct snd_soc_dai *dai) 9535033f43cSJassi Brar { 9545033f43cSJassi Brar struct i2s_dai *i2s = to_info(dai); 9555033f43cSJassi Brar struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai; 9565033f43cSJassi Brar 9575033f43cSJassi Brar if (other && other->clk) /* If this is probe on secondary */ 9585033f43cSJassi Brar goto probe_exit; 9595033f43cSJassi Brar 9605033f43cSJassi Brar i2s->addr = ioremap(i2s->base, 0x100); 9615033f43cSJassi Brar if (i2s->addr == NULL) { 9625033f43cSJassi Brar dev_err(&i2s->pdev->dev, "cannot ioremap registers\n"); 9635033f43cSJassi Brar return -ENXIO; 9645033f43cSJassi Brar } 9655033f43cSJassi Brar 9665033f43cSJassi Brar i2s->clk = clk_get(&i2s->pdev->dev, "iis"); 9675033f43cSJassi Brar if (IS_ERR(i2s->clk)) { 9685033f43cSJassi Brar dev_err(&i2s->pdev->dev, "failed to get i2s_clock\n"); 9695033f43cSJassi Brar iounmap(i2s->addr); 9705033f43cSJassi Brar return -ENOENT; 9715033f43cSJassi Brar } 9725033f43cSJassi Brar clk_enable(i2s->clk); 9735033f43cSJassi Brar 9745033f43cSJassi Brar if (other) { 9755033f43cSJassi Brar other->addr = i2s->addr; 9765033f43cSJassi Brar other->clk = i2s->clk; 9775033f43cSJassi Brar } 9785033f43cSJassi Brar 9795033f43cSJassi Brar if (i2s->quirks & QUIRK_NEED_RSTCLR) 9805033f43cSJassi Brar writel(CON_RSTCLR, i2s->addr + I2SCON); 9815033f43cSJassi Brar 9825033f43cSJassi Brar probe_exit: 9835033f43cSJassi Brar /* Reset any constraint on RFS and BFS */ 9845033f43cSJassi Brar i2s->rfs = 0; 9855033f43cSJassi Brar i2s->bfs = 0; 9865033f43cSJassi Brar i2s_txctrl(i2s, 0); 9875033f43cSJassi Brar i2s_rxctrl(i2s, 0); 9885033f43cSJassi Brar i2s_fifo(i2s, FIC_TXFLUSH); 9895033f43cSJassi Brar i2s_fifo(other, FIC_TXFLUSH); 9905033f43cSJassi Brar i2s_fifo(i2s, FIC_RXFLUSH); 9915033f43cSJassi Brar 9925033f43cSJassi Brar /* Gate CDCLK by default */ 9935033f43cSJassi Brar if (!is_opened(other)) 9945033f43cSJassi Brar i2s_set_sysclk(dai, SAMSUNG_I2S_CDCLK, 9955033f43cSJassi Brar 0, SND_SOC_CLOCK_IN); 9965033f43cSJassi Brar 9975033f43cSJassi Brar return 0; 9985033f43cSJassi Brar } 9995033f43cSJassi Brar 10005033f43cSJassi Brar static int samsung_i2s_dai_remove(struct snd_soc_dai *dai) 10015033f43cSJassi Brar { 10025033f43cSJassi Brar struct i2s_dai *i2s = snd_soc_dai_get_drvdata(dai); 10035033f43cSJassi Brar struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai; 10045033f43cSJassi Brar 10055033f43cSJassi Brar if (!other || !other->clk) { 10065033f43cSJassi Brar 10075033f43cSJassi Brar if (i2s->quirks & QUIRK_NEED_RSTCLR) 10085033f43cSJassi Brar writel(0, i2s->addr + I2SCON); 10095033f43cSJassi Brar 10105033f43cSJassi Brar clk_disable(i2s->clk); 10115033f43cSJassi Brar clk_put(i2s->clk); 10125033f43cSJassi Brar 10135033f43cSJassi Brar iounmap(i2s->addr); 10145033f43cSJassi Brar } 10155033f43cSJassi Brar 10165033f43cSJassi Brar i2s->clk = NULL; 10175033f43cSJassi Brar 10185033f43cSJassi Brar return 0; 10195033f43cSJassi Brar } 10205033f43cSJassi Brar 10215033f43cSJassi Brar static struct snd_soc_dai_ops samsung_i2s_dai_ops = { 10225033f43cSJassi Brar .trigger = i2s_trigger, 10235033f43cSJassi Brar .hw_params = i2s_hw_params, 10245033f43cSJassi Brar .set_fmt = i2s_set_fmt, 10255033f43cSJassi Brar .set_clkdiv = i2s_set_clkdiv, 10265033f43cSJassi Brar .set_sysclk = i2s_set_sysclk, 10275033f43cSJassi Brar .startup = i2s_startup, 10285033f43cSJassi Brar .shutdown = i2s_shutdown, 10295033f43cSJassi Brar .delay = i2s_delay, 10305033f43cSJassi Brar }; 10315033f43cSJassi Brar 10325033f43cSJassi Brar #define SAMSUNG_I2S_RATES SNDRV_PCM_RATE_8000_96000 10335033f43cSJassi Brar 10345033f43cSJassi Brar #define SAMSUNG_I2S_FMTS (SNDRV_PCM_FMTBIT_S8 | \ 10355033f43cSJassi Brar SNDRV_PCM_FMTBIT_S16_LE | \ 10365033f43cSJassi Brar SNDRV_PCM_FMTBIT_S24_LE) 10375033f43cSJassi Brar 10385033f43cSJassi Brar static __devinit 10395033f43cSJassi Brar struct i2s_dai *i2s_alloc_dai(struct platform_device *pdev, bool sec) 10405033f43cSJassi Brar { 10415033f43cSJassi Brar struct i2s_dai *i2s; 10425033f43cSJassi Brar 10435033f43cSJassi Brar i2s = kzalloc(sizeof(struct i2s_dai), GFP_KERNEL); 10445033f43cSJassi Brar if (i2s == NULL) 10455033f43cSJassi Brar return NULL; 10465033f43cSJassi Brar 10475033f43cSJassi Brar i2s->pdev = pdev; 10485033f43cSJassi Brar i2s->pri_dai = NULL; 10495033f43cSJassi Brar i2s->sec_dai = NULL; 10505033f43cSJassi Brar i2s->i2s_dai_drv.symmetric_rates = 1; 10515033f43cSJassi Brar i2s->i2s_dai_drv.probe = samsung_i2s_dai_probe; 10525033f43cSJassi Brar i2s->i2s_dai_drv.remove = samsung_i2s_dai_remove; 10535033f43cSJassi Brar i2s->i2s_dai_drv.ops = &samsung_i2s_dai_ops; 10545033f43cSJassi Brar i2s->i2s_dai_drv.suspend = i2s_suspend; 10555033f43cSJassi Brar i2s->i2s_dai_drv.resume = i2s_resume; 10565033f43cSJassi Brar i2s->i2s_dai_drv.playback.channels_min = 2; 10575033f43cSJassi Brar i2s->i2s_dai_drv.playback.channels_max = 2; 10585033f43cSJassi Brar i2s->i2s_dai_drv.playback.rates = SAMSUNG_I2S_RATES; 10595033f43cSJassi Brar i2s->i2s_dai_drv.playback.formats = SAMSUNG_I2S_FMTS; 10605033f43cSJassi Brar 10615033f43cSJassi Brar if (!sec) { 10625033f43cSJassi Brar i2s->i2s_dai_drv.capture.channels_min = 2; 10635033f43cSJassi Brar i2s->i2s_dai_drv.capture.channels_max = 2; 10645033f43cSJassi Brar i2s->i2s_dai_drv.capture.rates = SAMSUNG_I2S_RATES; 10655033f43cSJassi Brar i2s->i2s_dai_drv.capture.formats = SAMSUNG_I2S_FMTS; 10665033f43cSJassi Brar } else { /* Create a new platform_device for Secondary */ 10675033f43cSJassi Brar i2s->pdev = platform_device_register_resndata(NULL, 10685033f43cSJassi Brar pdev->name, pdev->id + SAMSUNG_I2S_SECOFF, 10695033f43cSJassi Brar NULL, 0, NULL, 0); 10705033f43cSJassi Brar if (IS_ERR(i2s->pdev)) { 10715033f43cSJassi Brar kfree(i2s); 10725033f43cSJassi Brar return NULL; 10735033f43cSJassi Brar } 10745033f43cSJassi Brar } 10755033f43cSJassi Brar 10765033f43cSJassi Brar /* Pre-assign snd_soc_dai_set_drvdata */ 10775033f43cSJassi Brar dev_set_drvdata(&i2s->pdev->dev, i2s); 10785033f43cSJassi Brar 10795033f43cSJassi Brar return i2s; 10805033f43cSJassi Brar } 10815033f43cSJassi Brar 10825033f43cSJassi Brar static __devinit int samsung_i2s_probe(struct platform_device *pdev) 10835033f43cSJassi Brar { 10845033f43cSJassi Brar u32 dma_pl_chan, dma_cp_chan, dma_pl_sec_chan; 10855033f43cSJassi Brar struct i2s_dai *pri_dai, *sec_dai = NULL; 10865033f43cSJassi Brar struct s3c_audio_pdata *i2s_pdata; 10875033f43cSJassi Brar struct samsung_i2s *i2s_cfg; 10885033f43cSJassi Brar struct resource *res; 10895033f43cSJassi Brar u32 regs_base, quirks; 10905033f43cSJassi Brar int ret = 0; 10915033f43cSJassi Brar 10925033f43cSJassi Brar /* Call during Seconday interface registration */ 10935033f43cSJassi Brar if (pdev->id >= SAMSUNG_I2S_SECOFF) { 10945033f43cSJassi Brar sec_dai = dev_get_drvdata(&pdev->dev); 10955033f43cSJassi Brar snd_soc_register_dai(&sec_dai->pdev->dev, 10965033f43cSJassi Brar &sec_dai->i2s_dai_drv); 10975033f43cSJassi Brar return 0; 10985033f43cSJassi Brar } 10995033f43cSJassi Brar 11005033f43cSJassi Brar i2s_pdata = pdev->dev.platform_data; 11015033f43cSJassi Brar if (i2s_pdata == NULL) { 11025033f43cSJassi Brar dev_err(&pdev->dev, "Can't work without s3c_audio_pdata\n"); 11035033f43cSJassi Brar return -EINVAL; 11045033f43cSJassi Brar } 11055033f43cSJassi Brar 11065033f43cSJassi Brar res = platform_get_resource(pdev, IORESOURCE_DMA, 0); 11075033f43cSJassi Brar if (!res) { 11085033f43cSJassi Brar dev_err(&pdev->dev, "Unable to get I2S-TX dma resource\n"); 11095033f43cSJassi Brar return -ENXIO; 11105033f43cSJassi Brar } 11115033f43cSJassi Brar dma_pl_chan = res->start; 11125033f43cSJassi Brar 11135033f43cSJassi Brar res = platform_get_resource(pdev, IORESOURCE_DMA, 1); 11145033f43cSJassi Brar if (!res) { 11155033f43cSJassi Brar dev_err(&pdev->dev, "Unable to get I2S-RX dma resource\n"); 11165033f43cSJassi Brar return -ENXIO; 11175033f43cSJassi Brar } 11185033f43cSJassi Brar dma_cp_chan = res->start; 11195033f43cSJassi Brar 11205033f43cSJassi Brar res = platform_get_resource(pdev, IORESOURCE_DMA, 2); 11215033f43cSJassi Brar if (res) 11225033f43cSJassi Brar dma_pl_sec_chan = res->start; 11235033f43cSJassi Brar else 11245033f43cSJassi Brar dma_pl_sec_chan = 0; 11255033f43cSJassi Brar 11265033f43cSJassi Brar res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 11275033f43cSJassi Brar if (!res) { 11285033f43cSJassi Brar dev_err(&pdev->dev, "Unable to get I2S SFR address\n"); 11295033f43cSJassi Brar return -ENXIO; 11305033f43cSJassi Brar } 11315033f43cSJassi Brar 11325033f43cSJassi Brar if (!request_mem_region(res->start, resource_size(res), 11335033f43cSJassi Brar "samsung-i2s")) { 11345033f43cSJassi Brar dev_err(&pdev->dev, "Unable to request SFR region\n"); 11355033f43cSJassi Brar return -EBUSY; 11365033f43cSJassi Brar } 11375033f43cSJassi Brar regs_base = res->start; 11385033f43cSJassi Brar 11395033f43cSJassi Brar i2s_cfg = &i2s_pdata->type.i2s; 11405033f43cSJassi Brar quirks = i2s_cfg->quirks; 11415033f43cSJassi Brar 11425033f43cSJassi Brar pri_dai = i2s_alloc_dai(pdev, false); 11435033f43cSJassi Brar if (!pri_dai) { 11445033f43cSJassi Brar dev_err(&pdev->dev, "Unable to alloc I2S_pri\n"); 11455033f43cSJassi Brar ret = -ENOMEM; 11465033f43cSJassi Brar goto err1; 11475033f43cSJassi Brar } 11485033f43cSJassi Brar 11495033f43cSJassi Brar pri_dai->dma_playback.dma_addr = regs_base + I2STXD; 11505033f43cSJassi Brar pri_dai->dma_capture.dma_addr = regs_base + I2SRXD; 11515033f43cSJassi Brar pri_dai->dma_playback.client = 11525033f43cSJassi Brar (struct s3c2410_dma_client *)&pri_dai->dma_playback; 11535033f43cSJassi Brar pri_dai->dma_capture.client = 11545033f43cSJassi Brar (struct s3c2410_dma_client *)&pri_dai->dma_capture; 11555033f43cSJassi Brar pri_dai->dma_playback.channel = dma_pl_chan; 11565033f43cSJassi Brar pri_dai->dma_capture.channel = dma_cp_chan; 11575033f43cSJassi Brar pri_dai->src_clk = i2s_cfg->src_clk; 11585033f43cSJassi Brar pri_dai->dma_playback.dma_size = 4; 11595033f43cSJassi Brar pri_dai->dma_capture.dma_size = 4; 11605033f43cSJassi Brar pri_dai->base = regs_base; 11615033f43cSJassi Brar pri_dai->quirks = quirks; 11625033f43cSJassi Brar 11635033f43cSJassi Brar if (quirks & QUIRK_PRI_6CHAN) 11645033f43cSJassi Brar pri_dai->i2s_dai_drv.playback.channels_max = 6; 11655033f43cSJassi Brar 11665033f43cSJassi Brar if (quirks & QUIRK_SEC_DAI) { 11675033f43cSJassi Brar sec_dai = i2s_alloc_dai(pdev, true); 11685033f43cSJassi Brar if (!sec_dai) { 11695033f43cSJassi Brar dev_err(&pdev->dev, "Unable to alloc I2S_sec\n"); 11705033f43cSJassi Brar ret = -ENOMEM; 11715033f43cSJassi Brar goto err2; 11725033f43cSJassi Brar } 11735033f43cSJassi Brar sec_dai->dma_playback.dma_addr = regs_base + I2STXDS; 11745033f43cSJassi Brar sec_dai->dma_playback.client = 11755033f43cSJassi Brar (struct s3c2410_dma_client *)&sec_dai->dma_playback; 11765033f43cSJassi Brar /* Use iDMA always if SysDMA not provided */ 11775033f43cSJassi Brar sec_dai->dma_playback.channel = dma_pl_sec_chan ? : -1; 11785033f43cSJassi Brar sec_dai->src_clk = i2s_cfg->src_clk; 11795033f43cSJassi Brar sec_dai->dma_playback.dma_size = 4; 11805033f43cSJassi Brar sec_dai->base = regs_base; 11815033f43cSJassi Brar sec_dai->quirks = quirks; 11825033f43cSJassi Brar sec_dai->pri_dai = pri_dai; 11835033f43cSJassi Brar pri_dai->sec_dai = sec_dai; 11845033f43cSJassi Brar } 11855033f43cSJassi Brar 11865033f43cSJassi Brar if (i2s_pdata->cfg_gpio && i2s_pdata->cfg_gpio(pdev)) { 11875033f43cSJassi Brar dev_err(&pdev->dev, "Unable to configure gpio\n"); 11885033f43cSJassi Brar ret = -EINVAL; 11895033f43cSJassi Brar goto err3; 11905033f43cSJassi Brar } 11915033f43cSJassi Brar 11925033f43cSJassi Brar snd_soc_register_dai(&pri_dai->pdev->dev, &pri_dai->i2s_dai_drv); 11935033f43cSJassi Brar 11945033f43cSJassi Brar return 0; 11955033f43cSJassi Brar err3: 11965033f43cSJassi Brar kfree(sec_dai); 11975033f43cSJassi Brar err2: 11985033f43cSJassi Brar kfree(pri_dai); 11995033f43cSJassi Brar err1: 12005033f43cSJassi Brar release_mem_region(regs_base, resource_size(res)); 12015033f43cSJassi Brar 12025033f43cSJassi Brar return ret; 12035033f43cSJassi Brar } 12045033f43cSJassi Brar 12055033f43cSJassi Brar static __devexit int samsung_i2s_remove(struct platform_device *pdev) 12065033f43cSJassi Brar { 12075033f43cSJassi Brar struct i2s_dai *i2s, *other; 12085033f43cSJassi Brar 12095033f43cSJassi Brar i2s = dev_get_drvdata(&pdev->dev); 12105033f43cSJassi Brar other = i2s->pri_dai ? : i2s->sec_dai; 12115033f43cSJassi Brar 12125033f43cSJassi Brar if (other) { 12135033f43cSJassi Brar other->pri_dai = NULL; 12145033f43cSJassi Brar other->sec_dai = NULL; 12155033f43cSJassi Brar } else { 12165033f43cSJassi Brar struct resource *res; 12175033f43cSJassi Brar res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 12185033f43cSJassi Brar if (res) 12195033f43cSJassi Brar release_mem_region(res->start, resource_size(res)); 12205033f43cSJassi Brar } 12215033f43cSJassi Brar 12225033f43cSJassi Brar i2s->pri_dai = NULL; 12235033f43cSJassi Brar i2s->sec_dai = NULL; 12245033f43cSJassi Brar 12255033f43cSJassi Brar kfree(i2s); 12265033f43cSJassi Brar 12275033f43cSJassi Brar snd_soc_unregister_dai(&pdev->dev); 12285033f43cSJassi Brar 12295033f43cSJassi Brar return 0; 12305033f43cSJassi Brar } 12315033f43cSJassi Brar 12325033f43cSJassi Brar static struct platform_driver samsung_i2s_driver = { 12335033f43cSJassi Brar .probe = samsung_i2s_probe, 12345033f43cSJassi Brar .remove = samsung_i2s_remove, 12355033f43cSJassi Brar .driver = { 12365033f43cSJassi Brar .name = "samsung-i2s", 12375033f43cSJassi Brar .owner = THIS_MODULE, 12385033f43cSJassi Brar }, 12395033f43cSJassi Brar }; 12405033f43cSJassi Brar 12415033f43cSJassi Brar static int __init samsung_i2s_init(void) 12425033f43cSJassi Brar { 12435033f43cSJassi Brar return platform_driver_register(&samsung_i2s_driver); 12445033f43cSJassi Brar } 12455033f43cSJassi Brar module_init(samsung_i2s_init); 12465033f43cSJassi Brar 12475033f43cSJassi Brar static void __exit samsung_i2s_exit(void) 12485033f43cSJassi Brar { 12495033f43cSJassi Brar platform_driver_unregister(&samsung_i2s_driver); 12505033f43cSJassi Brar } 12515033f43cSJassi Brar module_exit(samsung_i2s_exit); 12525033f43cSJassi Brar 12535033f43cSJassi Brar /* Module information */ 12545033f43cSJassi Brar MODULE_AUTHOR("Jaswinder Singh, <jassi.brar@samsung.com>"); 12555033f43cSJassi Brar MODULE_DESCRIPTION("Samsung I2S Interface"); 12565033f43cSJassi Brar MODULE_ALIAS("platform:samsung-i2s"); 12575033f43cSJassi Brar MODULE_LICENSE("GPL"); 1258