Jassi Brar | 5033f43 | 2010-11-22 15:37:25 +0900 | [diff] [blame] | 1 | /* sound/soc/samsung/i2s.c |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 2 | * |
| 3 | * ALSA SoC Audio Layer - Samsung I2S Controller driver |
| 4 | * |
| 5 | * Copyright (c) 2010 Samsung Electronics Co. Ltd. |
Jaswinder Singh | df8ad33 | 2012-02-25 16:24:36 +0530 | [diff] [blame] | 6 | * Jaswinder Singh <jassisinghbrar@gmail.com> |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/delay.h> |
| 14 | #include <linux/slab.h> |
| 15 | #include <linux/clk.h> |
| 16 | #include <linux/io.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 17 | #include <linux/module.h> |
Padmavathi Venna | 40476f6 | 2013-01-18 17:17:01 +0530 | [diff] [blame] | 18 | #include <linux/of.h> |
| 19 | #include <linux/of_gpio.h> |
Mark Brown | c5cf4db | 2011-12-08 16:45:03 +0800 | [diff] [blame] | 20 | #include <linux/pm_runtime.h> |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 21 | |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 22 | #include <sound/soc.h> |
Seungwhan Youn | 0378b6a | 2011-01-11 07:26:06 +0900 | [diff] [blame] | 23 | #include <sound/pcm_params.h> |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 24 | |
Arnd Bergmann | 436d42c | 2012-08-24 15:22:12 +0200 | [diff] [blame] | 25 | #include <linux/platform_data/asoc-s3c.h> |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 26 | |
| 27 | #include "dma.h" |
Sangbeom Kim | 61100f4 | 2011-07-20 17:07:12 +0900 | [diff] [blame] | 28 | #include "idma.h" |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 29 | #include "i2s.h" |
Sangbeom Kim | 172a453 | 2011-06-20 16:36:18 +0900 | [diff] [blame] | 30 | #include "i2s-regs.h" |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 31 | |
| 32 | #define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t) |
| 33 | |
Padmavathi Venna | 7c62eeb | 2013-01-18 17:17:00 +0530 | [diff] [blame] | 34 | enum samsung_dai_type { |
| 35 | TYPE_PRI, |
| 36 | TYPE_SEC, |
| 37 | }; |
| 38 | |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 39 | struct samsung_i2s_variant_regs { |
| 40 | unsigned int bfs_off; |
| 41 | unsigned int rfs_off; |
| 42 | unsigned int sdf_off; |
| 43 | unsigned int txr_off; |
| 44 | unsigned int rclksrc_off; |
| 45 | unsigned int mss_off; |
| 46 | unsigned int cdclkcon_off; |
| 47 | unsigned int lrp_off; |
| 48 | unsigned int bfs_mask; |
| 49 | unsigned int rfs_mask; |
| 50 | unsigned int ftx0cnt_off; |
| 51 | }; |
| 52 | |
Padmavathi Venna | 40476f6 | 2013-01-18 17:17:01 +0530 | [diff] [blame] | 53 | struct samsung_i2s_dai_data { |
| 54 | int dai_type; |
Padmavathi Venna | 7da493e | 2013-08-12 15:19:51 +0530 | [diff] [blame] | 55 | u32 quirks; |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 56 | const struct samsung_i2s_variant_regs *i2s_variant_regs; |
Padmavathi Venna | 40476f6 | 2013-01-18 17:17:01 +0530 | [diff] [blame] | 57 | }; |
| 58 | |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 59 | struct i2s_dai { |
| 60 | /* Platform device for this DAI */ |
| 61 | struct platform_device *pdev; |
| 62 | /* IOREMAP'd SFRs */ |
| 63 | void __iomem *addr; |
| 64 | /* Physical base address of SFRs */ |
| 65 | u32 base; |
| 66 | /* Rate of RCLK source clock */ |
| 67 | unsigned long rclk_srcrate; |
| 68 | /* Frame Clock */ |
| 69 | unsigned frmclk; |
| 70 | /* |
| 71 | * Specifically requested RCLK,BCLK by MACHINE Driver. |
| 72 | * 0 indicates CPU driver is free to choose any value. |
| 73 | */ |
| 74 | unsigned rfs, bfs; |
| 75 | /* I2S Controller's core clock */ |
| 76 | struct clk *clk; |
| 77 | /* Clock for generating I2S signals */ |
| 78 | struct clk *op_clk; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 79 | /* Pointer to the Primary_Fifo if this is Sec_Fifo, NULL otherwise */ |
| 80 | struct i2s_dai *pri_dai; |
| 81 | /* Pointer to the Secondary_Fifo if it has one, NULL otherwise */ |
| 82 | struct i2s_dai *sec_dai; |
| 83 | #define DAI_OPENED (1 << 0) /* Dai is opened */ |
| 84 | #define DAI_MANAGER (1 << 1) /* Dai is the manager */ |
| 85 | unsigned mode; |
Sylwester Nawrocki | b97c60a | 2014-07-10 18:11:13 +0200 | [diff] [blame] | 86 | /* CDCLK pin direction: 0 - input, 1 - output */ |
| 87 | unsigned int cdclk_out:1; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 88 | /* Driver for this DAI */ |
| 89 | struct snd_soc_dai_driver i2s_dai_drv; |
| 90 | /* DMA parameters */ |
| 91 | struct s3c_dma_params dma_playback; |
| 92 | struct s3c_dma_params dma_capture; |
Sangbeom Kim | 61100f4 | 2011-07-20 17:07:12 +0900 | [diff] [blame] | 93 | struct s3c_dma_params idma_playback; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 94 | u32 quirks; |
| 95 | u32 suspend_i2smod; |
| 96 | u32 suspend_i2scon; |
| 97 | u32 suspend_i2spsr; |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 98 | const struct samsung_i2s_variant_regs *variant_regs; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | /* Lock for cross i/f checks */ |
| 102 | static DEFINE_SPINLOCK(lock); |
| 103 | |
| 104 | /* If this is the 'overlay' stereo DAI */ |
| 105 | static inline bool is_secondary(struct i2s_dai *i2s) |
| 106 | { |
| 107 | return i2s->pri_dai ? true : false; |
| 108 | } |
| 109 | |
| 110 | /* If operating in SoC-Slave mode */ |
| 111 | static inline bool is_slave(struct i2s_dai *i2s) |
| 112 | { |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 113 | u32 mod = readl(i2s->addr + I2SMOD); |
| 114 | return (mod & (1 << i2s->variant_regs->mss_off)) ? true : false; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /* If this interface of the controller is transmitting data */ |
| 118 | static inline bool tx_active(struct i2s_dai *i2s) |
| 119 | { |
| 120 | u32 active; |
| 121 | |
| 122 | if (!i2s) |
| 123 | return false; |
| 124 | |
Sangbeom Kim | 3319550 | 2011-06-10 10:36:54 +0900 | [diff] [blame] | 125 | active = readl(i2s->addr + I2SCON); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 126 | |
| 127 | if (is_secondary(i2s)) |
| 128 | active &= CON_TXSDMA_ACTIVE; |
| 129 | else |
| 130 | active &= CON_TXDMA_ACTIVE; |
| 131 | |
| 132 | return active ? true : false; |
| 133 | } |
| 134 | |
| 135 | /* If the other interface of the controller is transmitting data */ |
| 136 | static inline bool other_tx_active(struct i2s_dai *i2s) |
| 137 | { |
| 138 | struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai; |
| 139 | |
| 140 | return tx_active(other); |
| 141 | } |
| 142 | |
| 143 | /* If any interface of the controller is transmitting data */ |
| 144 | static inline bool any_tx_active(struct i2s_dai *i2s) |
| 145 | { |
| 146 | return tx_active(i2s) || other_tx_active(i2s); |
| 147 | } |
| 148 | |
| 149 | /* If this interface of the controller is receiving data */ |
| 150 | static inline bool rx_active(struct i2s_dai *i2s) |
| 151 | { |
| 152 | u32 active; |
| 153 | |
| 154 | if (!i2s) |
| 155 | return false; |
| 156 | |
Sangbeom Kim | 3319550 | 2011-06-10 10:36:54 +0900 | [diff] [blame] | 157 | active = readl(i2s->addr + I2SCON) & CON_RXDMA_ACTIVE; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 158 | |
| 159 | return active ? true : false; |
| 160 | } |
| 161 | |
| 162 | /* If the other interface of the controller is receiving data */ |
| 163 | static inline bool other_rx_active(struct i2s_dai *i2s) |
| 164 | { |
| 165 | struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai; |
| 166 | |
| 167 | return rx_active(other); |
| 168 | } |
| 169 | |
| 170 | /* If any interface of the controller is receiving data */ |
| 171 | static inline bool any_rx_active(struct i2s_dai *i2s) |
| 172 | { |
| 173 | return rx_active(i2s) || other_rx_active(i2s); |
| 174 | } |
| 175 | |
| 176 | /* If the other DAI is transmitting or receiving data */ |
| 177 | static inline bool other_active(struct i2s_dai *i2s) |
| 178 | { |
| 179 | return other_rx_active(i2s) || other_tx_active(i2s); |
| 180 | } |
| 181 | |
| 182 | /* If this DAI is transmitting or receiving data */ |
| 183 | static inline bool this_active(struct i2s_dai *i2s) |
| 184 | { |
| 185 | return tx_active(i2s) || rx_active(i2s); |
| 186 | } |
| 187 | |
| 188 | /* If the controller is active anyway */ |
| 189 | static inline bool any_active(struct i2s_dai *i2s) |
| 190 | { |
| 191 | return this_active(i2s) || other_active(i2s); |
| 192 | } |
| 193 | |
| 194 | static inline struct i2s_dai *to_info(struct snd_soc_dai *dai) |
| 195 | { |
| 196 | return snd_soc_dai_get_drvdata(dai); |
| 197 | } |
| 198 | |
| 199 | static inline bool is_opened(struct i2s_dai *i2s) |
| 200 | { |
| 201 | if (i2s && (i2s->mode & DAI_OPENED)) |
| 202 | return true; |
| 203 | else |
| 204 | return false; |
| 205 | } |
| 206 | |
| 207 | static inline bool is_manager(struct i2s_dai *i2s) |
| 208 | { |
| 209 | if (is_opened(i2s) && (i2s->mode & DAI_MANAGER)) |
| 210 | return true; |
| 211 | else |
| 212 | return false; |
| 213 | } |
| 214 | |
| 215 | /* Read RCLK of I2S (in multiples of LRCLK) */ |
| 216 | static inline unsigned get_rfs(struct i2s_dai *i2s) |
| 217 | { |
Padmavathi Venna | 4ca0c0d | 2013-08-12 15:19:52 +0530 | [diff] [blame] | 218 | u32 rfs; |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 219 | rfs = readl(i2s->addr + I2SMOD) >> i2s->variant_regs->rfs_off; |
| 220 | rfs &= i2s->variant_regs->rfs_mask; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 221 | |
| 222 | switch (rfs) { |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 223 | case 7: return 192; |
| 224 | case 6: return 96; |
| 225 | case 5: return 128; |
| 226 | case 4: return 64; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 227 | case 3: return 768; |
| 228 | case 2: return 384; |
| 229 | case 1: return 512; |
| 230 | default: return 256; |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | /* Write RCLK of I2S (in multiples of LRCLK) */ |
| 235 | static inline void set_rfs(struct i2s_dai *i2s, unsigned rfs) |
| 236 | { |
| 237 | u32 mod = readl(i2s->addr + I2SMOD); |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 238 | int rfs_shift = i2s->variant_regs->rfs_off; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 239 | |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 240 | mod &= ~(i2s->variant_regs->rfs_mask << rfs_shift); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 241 | |
| 242 | switch (rfs) { |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 243 | case 192: |
| 244 | mod |= (EXYNOS7_MOD_RCLK_192FS << rfs_shift); |
| 245 | break; |
| 246 | case 96: |
| 247 | mod |= (EXYNOS7_MOD_RCLK_96FS << rfs_shift); |
| 248 | break; |
| 249 | case 128: |
| 250 | mod |= (EXYNOS7_MOD_RCLK_128FS << rfs_shift); |
| 251 | break; |
| 252 | case 64: |
| 253 | mod |= (EXYNOS7_MOD_RCLK_64FS << rfs_shift); |
| 254 | break; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 255 | case 768: |
Padmavathi Venna | b60be4a | 2013-07-26 19:06:48 +0530 | [diff] [blame] | 256 | mod |= (MOD_RCLK_768FS << rfs_shift); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 257 | break; |
| 258 | case 512: |
Padmavathi Venna | b60be4a | 2013-07-26 19:06:48 +0530 | [diff] [blame] | 259 | mod |= (MOD_RCLK_512FS << rfs_shift); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 260 | break; |
| 261 | case 384: |
Padmavathi Venna | b60be4a | 2013-07-26 19:06:48 +0530 | [diff] [blame] | 262 | mod |= (MOD_RCLK_384FS << rfs_shift); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 263 | break; |
| 264 | default: |
Padmavathi Venna | b60be4a | 2013-07-26 19:06:48 +0530 | [diff] [blame] | 265 | mod |= (MOD_RCLK_256FS << rfs_shift); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 266 | break; |
| 267 | } |
| 268 | |
| 269 | writel(mod, i2s->addr + I2SMOD); |
| 270 | } |
| 271 | |
| 272 | /* Read Bit-Clock of I2S (in multiples of LRCLK) */ |
| 273 | static inline unsigned get_bfs(struct i2s_dai *i2s) |
| 274 | { |
Padmavathi Venna | 4ca0c0d | 2013-08-12 15:19:52 +0530 | [diff] [blame] | 275 | u32 bfs; |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 276 | bfs = readl(i2s->addr + I2SMOD) >> i2s->variant_regs->bfs_off; |
| 277 | bfs &= i2s->variant_regs->bfs_mask; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 278 | |
| 279 | switch (bfs) { |
Padmavathi Venna | 4ca0c0d | 2013-08-12 15:19:52 +0530 | [diff] [blame] | 280 | case 8: return 256; |
| 281 | case 7: return 192; |
| 282 | case 6: return 128; |
| 283 | case 5: return 96; |
| 284 | case 4: return 64; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 285 | case 3: return 24; |
| 286 | case 2: return 16; |
| 287 | case 1: return 48; |
| 288 | default: return 32; |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | /* Write Bit-Clock of I2S (in multiples of LRCLK) */ |
| 293 | static inline void set_bfs(struct i2s_dai *i2s, unsigned bfs) |
| 294 | { |
| 295 | u32 mod = readl(i2s->addr + I2SMOD); |
Padmavathi Venna | 4ca0c0d | 2013-08-12 15:19:52 +0530 | [diff] [blame] | 296 | int tdm = i2s->quirks & QUIRK_SUPPORTS_TDM; |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 297 | int bfs_shift = i2s->variant_regs->bfs_off; |
Padmavathi Venna | 4ca0c0d | 2013-08-12 15:19:52 +0530 | [diff] [blame] | 298 | |
| 299 | /* Non-TDM I2S controllers do not support BCLK > 48 * FS */ |
| 300 | if (!tdm && bfs > 48) { |
| 301 | dev_err(&i2s->pdev->dev, "Unsupported BCLK divider\n"); |
| 302 | return; |
| 303 | } |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 304 | |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 305 | mod &= ~(i2s->variant_regs->bfs_mask << bfs_shift); |
| 306 | |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 307 | switch (bfs) { |
| 308 | case 48: |
Padmavathi Venna | b60be4a | 2013-07-26 19:06:48 +0530 | [diff] [blame] | 309 | mod |= (MOD_BCLK_48FS << bfs_shift); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 310 | break; |
| 311 | case 32: |
Padmavathi Venna | b60be4a | 2013-07-26 19:06:48 +0530 | [diff] [blame] | 312 | mod |= (MOD_BCLK_32FS << bfs_shift); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 313 | break; |
| 314 | case 24: |
Padmavathi Venna | b60be4a | 2013-07-26 19:06:48 +0530 | [diff] [blame] | 315 | mod |= (MOD_BCLK_24FS << bfs_shift); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 316 | break; |
| 317 | case 16: |
Padmavathi Venna | b60be4a | 2013-07-26 19:06:48 +0530 | [diff] [blame] | 318 | mod |= (MOD_BCLK_16FS << bfs_shift); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 319 | break; |
Padmavathi Venna | 4ca0c0d | 2013-08-12 15:19:52 +0530 | [diff] [blame] | 320 | case 64: |
| 321 | mod |= (EXYNOS5420_MOD_BCLK_64FS << bfs_shift); |
| 322 | break; |
| 323 | case 96: |
| 324 | mod |= (EXYNOS5420_MOD_BCLK_96FS << bfs_shift); |
| 325 | break; |
| 326 | case 128: |
| 327 | mod |= (EXYNOS5420_MOD_BCLK_128FS << bfs_shift); |
| 328 | break; |
| 329 | case 192: |
| 330 | mod |= (EXYNOS5420_MOD_BCLK_192FS << bfs_shift); |
| 331 | break; |
| 332 | case 256: |
| 333 | mod |= (EXYNOS5420_MOD_BCLK_256FS << bfs_shift); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 334 | break; |
| 335 | default: |
| 336 | dev_err(&i2s->pdev->dev, "Wrong BCLK Divider!\n"); |
| 337 | return; |
| 338 | } |
| 339 | |
| 340 | writel(mod, i2s->addr + I2SMOD); |
| 341 | } |
| 342 | |
| 343 | /* Sample-Size */ |
| 344 | static inline int get_blc(struct i2s_dai *i2s) |
| 345 | { |
| 346 | int blc = readl(i2s->addr + I2SMOD); |
| 347 | |
| 348 | blc = (blc >> 13) & 0x3; |
| 349 | |
| 350 | switch (blc) { |
| 351 | case 2: return 24; |
| 352 | case 1: return 8; |
| 353 | default: return 16; |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | /* TX Channel Control */ |
| 358 | static void i2s_txctrl(struct i2s_dai *i2s, int on) |
| 359 | { |
| 360 | void __iomem *addr = i2s->addr; |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 361 | int txr_off = i2s->variant_regs->txr_off; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 362 | u32 con = readl(addr + I2SCON); |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 363 | u32 mod = readl(addr + I2SMOD) & ~(3 << txr_off); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 364 | |
| 365 | if (on) { |
| 366 | con |= CON_ACTIVE; |
| 367 | con &= ~CON_TXCH_PAUSE; |
| 368 | |
| 369 | if (is_secondary(i2s)) { |
| 370 | con |= CON_TXSDMA_ACTIVE; |
| 371 | con &= ~CON_TXSDMA_PAUSE; |
| 372 | } else { |
| 373 | con |= CON_TXDMA_ACTIVE; |
| 374 | con &= ~CON_TXDMA_PAUSE; |
| 375 | } |
| 376 | |
| 377 | if (any_rx_active(i2s)) |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 378 | mod |= 2 << txr_off; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 379 | else |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 380 | mod |= 0 << txr_off; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 381 | } else { |
| 382 | if (is_secondary(i2s)) { |
| 383 | con |= CON_TXSDMA_PAUSE; |
| 384 | con &= ~CON_TXSDMA_ACTIVE; |
| 385 | } else { |
| 386 | con |= CON_TXDMA_PAUSE; |
| 387 | con &= ~CON_TXDMA_ACTIVE; |
| 388 | } |
| 389 | |
| 390 | if (other_tx_active(i2s)) { |
| 391 | writel(con, addr + I2SCON); |
| 392 | return; |
| 393 | } |
| 394 | |
| 395 | con |= CON_TXCH_PAUSE; |
| 396 | |
| 397 | if (any_rx_active(i2s)) |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 398 | mod |= 1 << txr_off; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 399 | else |
| 400 | con &= ~CON_ACTIVE; |
| 401 | } |
| 402 | |
| 403 | writel(mod, addr + I2SMOD); |
| 404 | writel(con, addr + I2SCON); |
| 405 | } |
| 406 | |
| 407 | /* RX Channel Control */ |
| 408 | static void i2s_rxctrl(struct i2s_dai *i2s, int on) |
| 409 | { |
| 410 | void __iomem *addr = i2s->addr; |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 411 | int txr_off = i2s->variant_regs->txr_off; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 412 | u32 con = readl(addr + I2SCON); |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 413 | u32 mod = readl(addr + I2SMOD) & ~(3 << txr_off); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 414 | |
| 415 | if (on) { |
| 416 | con |= CON_RXDMA_ACTIVE | CON_ACTIVE; |
| 417 | con &= ~(CON_RXDMA_PAUSE | CON_RXCH_PAUSE); |
| 418 | |
| 419 | if (any_tx_active(i2s)) |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 420 | mod |= 2 << txr_off; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 421 | else |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 422 | mod |= 1 << txr_off; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 423 | } else { |
| 424 | con |= CON_RXDMA_PAUSE | CON_RXCH_PAUSE; |
| 425 | con &= ~CON_RXDMA_ACTIVE; |
| 426 | |
| 427 | if (any_tx_active(i2s)) |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 428 | mod |= 0 << txr_off; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 429 | else |
| 430 | con &= ~CON_ACTIVE; |
| 431 | } |
| 432 | |
| 433 | writel(mod, addr + I2SMOD); |
| 434 | writel(con, addr + I2SCON); |
| 435 | } |
| 436 | |
| 437 | /* Flush FIFO of an interface */ |
| 438 | static inline void i2s_fifo(struct i2s_dai *i2s, u32 flush) |
| 439 | { |
| 440 | void __iomem *fic; |
| 441 | u32 val; |
| 442 | |
| 443 | if (!i2s) |
| 444 | return; |
| 445 | |
| 446 | if (is_secondary(i2s)) |
| 447 | fic = i2s->addr + I2SFICS; |
| 448 | else |
| 449 | fic = i2s->addr + I2SFIC; |
| 450 | |
| 451 | /* Flush the FIFO */ |
| 452 | writel(readl(fic) | flush, fic); |
| 453 | |
| 454 | /* Be patient */ |
| 455 | val = msecs_to_loops(1) / 1000; /* 1 usec */ |
| 456 | while (--val) |
| 457 | cpu_relax(); |
| 458 | |
| 459 | writel(readl(fic) & ~flush, fic); |
| 460 | } |
| 461 | |
| 462 | static int i2s_set_sysclk(struct snd_soc_dai *dai, |
| 463 | int clk_id, unsigned int rfs, int dir) |
| 464 | { |
| 465 | struct i2s_dai *i2s = to_info(dai); |
| 466 | struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai; |
| 467 | u32 mod = readl(i2s->addr + I2SMOD); |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 468 | const struct samsung_i2s_variant_regs *i2s_regs = i2s->variant_regs; |
| 469 | unsigned int cdcon_mask = 1 << i2s_regs->cdclkcon_off; |
| 470 | unsigned int rsrc_mask = 1 << i2s_regs->rclksrc_off; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 471 | |
| 472 | switch (clk_id) { |
Sylwester Nawrocki | c86d50f | 2014-05-19 19:30:38 +0200 | [diff] [blame] | 473 | case SAMSUNG_I2S_OPCLK: |
| 474 | mod &= ~MOD_OPCLK_MASK; |
| 475 | mod |= dir; |
| 476 | break; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 477 | case SAMSUNG_I2S_CDCLK: |
| 478 | /* Shouldn't matter in GATING(CLOCK_IN) mode */ |
| 479 | if (dir == SND_SOC_CLOCK_IN) |
| 480 | rfs = 0; |
| 481 | |
Charles Keepax | 133c268 | 2014-09-09 16:51:49 +0100 | [diff] [blame] | 482 | if ((rfs && other && other->rfs && (other->rfs != rfs)) || |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 483 | (any_active(i2s) && |
| 484 | (((dir == SND_SOC_CLOCK_IN) |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 485 | && !(mod & cdcon_mask)) || |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 486 | ((dir == SND_SOC_CLOCK_OUT) |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 487 | && (mod & cdcon_mask))))) { |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 488 | dev_err(&i2s->pdev->dev, |
| 489 | "%s:%d Other DAI busy\n", __func__, __LINE__); |
| 490 | return -EAGAIN; |
| 491 | } |
| 492 | |
| 493 | if (dir == SND_SOC_CLOCK_IN) |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 494 | mod |= 1 << i2s_regs->cdclkcon_off; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 495 | else |
Padmavathi Venna | b2de1d2 | 2014-11-20 15:33:17 +0530 | [diff] [blame] | 496 | mod &= ~(1 << i2s_regs->cdclkcon_off); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 497 | |
| 498 | i2s->rfs = rfs; |
| 499 | break; |
| 500 | |
| 501 | case SAMSUNG_I2S_RCLKSRC_0: /* clock corrsponding to IISMOD[10] := 0 */ |
| 502 | case SAMSUNG_I2S_RCLKSRC_1: /* clock corrsponding to IISMOD[10] := 1 */ |
| 503 | if ((i2s->quirks & QUIRK_NO_MUXPSR) |
| 504 | || (clk_id == SAMSUNG_I2S_RCLKSRC_0)) |
| 505 | clk_id = 0; |
| 506 | else |
| 507 | clk_id = 1; |
| 508 | |
| 509 | if (!any_active(i2s)) { |
Sylwester Nawrocki | a6aba53 | 2014-05-22 12:10:52 +0200 | [diff] [blame] | 510 | if (i2s->op_clk && !IS_ERR(i2s->op_clk)) { |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 511 | if ((clk_id && !(mod & rsrc_mask)) || |
| 512 | (!clk_id && (mod & rsrc_mask))) { |
Thomas Abraham | 98614cf | 2012-10-03 08:46:58 +0900 | [diff] [blame] | 513 | clk_disable_unprepare(i2s->op_clk); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 514 | clk_put(i2s->op_clk); |
| 515 | } else { |
Jassi Brar | 6ce534a | 2010-12-20 11:05:46 +0900 | [diff] [blame] | 516 | i2s->rclk_srcrate = |
| 517 | clk_get_rate(i2s->op_clk); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 518 | return 0; |
| 519 | } |
| 520 | } |
| 521 | |
Padmavathi Venna | 1974a04 | 2012-11-28 16:17:48 +0530 | [diff] [blame] | 522 | if (clk_id) |
| 523 | i2s->op_clk = clk_get(&i2s->pdev->dev, |
| 524 | "i2s_opclk1"); |
| 525 | else |
| 526 | i2s->op_clk = clk_get(&i2s->pdev->dev, |
| 527 | "i2s_opclk0"); |
Sylwester Nawrocki | a6aba53 | 2014-05-22 12:10:52 +0200 | [diff] [blame] | 528 | |
| 529 | if (WARN_ON(IS_ERR(i2s->op_clk))) |
| 530 | return PTR_ERR(i2s->op_clk); |
| 531 | |
Thomas Abraham | 98614cf | 2012-10-03 08:46:58 +0900 | [diff] [blame] | 532 | clk_prepare_enable(i2s->op_clk); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 533 | i2s->rclk_srcrate = clk_get_rate(i2s->op_clk); |
| 534 | |
| 535 | /* Over-ride the other's */ |
| 536 | if (other) { |
| 537 | other->op_clk = i2s->op_clk; |
| 538 | other->rclk_srcrate = i2s->rclk_srcrate; |
| 539 | } |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 540 | } else if ((!clk_id && (mod & rsrc_mask)) |
| 541 | || (clk_id && !(mod & rsrc_mask))) { |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 542 | dev_err(&i2s->pdev->dev, |
| 543 | "%s:%d Other DAI busy\n", __func__, __LINE__); |
| 544 | return -EAGAIN; |
| 545 | } else { |
| 546 | /* Call can't be on the active DAI */ |
| 547 | i2s->op_clk = other->op_clk; |
| 548 | i2s->rclk_srcrate = other->rclk_srcrate; |
| 549 | return 0; |
| 550 | } |
| 551 | |
| 552 | if (clk_id == 0) |
Padmavathi Venna | b2de1d2 | 2014-11-20 15:33:17 +0530 | [diff] [blame] | 553 | mod &= ~(1 << i2s_regs->rclksrc_off); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 554 | else |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 555 | mod |= 1 << i2s_regs->rclksrc_off; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 556 | |
Padmavathi Venna | b2de1d2 | 2014-11-20 15:33:17 +0530 | [diff] [blame] | 557 | break; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 558 | default: |
| 559 | dev_err(&i2s->pdev->dev, "We don't serve that!\n"); |
| 560 | return -EINVAL; |
| 561 | } |
| 562 | |
| 563 | writel(mod, i2s->addr + I2SMOD); |
| 564 | |
| 565 | return 0; |
| 566 | } |
| 567 | |
| 568 | static int i2s_set_fmt(struct snd_soc_dai *dai, |
| 569 | unsigned int fmt) |
| 570 | { |
| 571 | struct i2s_dai *i2s = to_info(dai); |
| 572 | u32 mod = readl(i2s->addr + I2SMOD); |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 573 | int lrp_shift, sdf_shift, sdf_mask, lrp_rlow, mod_slave; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 574 | u32 tmp = 0; |
| 575 | |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 576 | lrp_shift = i2s->variant_regs->lrp_off; |
| 577 | sdf_shift = i2s->variant_regs->sdf_off; |
| 578 | mod_slave = 1 << i2s->variant_regs->mss_off; |
Padmavathi Venna | 4ca0c0d | 2013-08-12 15:19:52 +0530 | [diff] [blame] | 579 | |
Padmavathi Venna | b60be4a | 2013-07-26 19:06:48 +0530 | [diff] [blame] | 580 | sdf_mask = MOD_SDF_MASK << sdf_shift; |
| 581 | lrp_rlow = MOD_LR_RLOW << lrp_shift; |
| 582 | |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 583 | /* Format is priority */ |
| 584 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 585 | case SND_SOC_DAIFMT_RIGHT_J: |
Padmavathi Venna | b60be4a | 2013-07-26 19:06:48 +0530 | [diff] [blame] | 586 | tmp |= lrp_rlow; |
| 587 | tmp |= (MOD_SDF_MSB << sdf_shift); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 588 | break; |
| 589 | case SND_SOC_DAIFMT_LEFT_J: |
Padmavathi Venna | b60be4a | 2013-07-26 19:06:48 +0530 | [diff] [blame] | 590 | tmp |= lrp_rlow; |
| 591 | tmp |= (MOD_SDF_LSB << sdf_shift); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 592 | break; |
| 593 | case SND_SOC_DAIFMT_I2S: |
Padmavathi Venna | b60be4a | 2013-07-26 19:06:48 +0530 | [diff] [blame] | 594 | tmp |= (MOD_SDF_IIS << sdf_shift); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 595 | break; |
| 596 | default: |
| 597 | dev_err(&i2s->pdev->dev, "Format not supported\n"); |
| 598 | return -EINVAL; |
| 599 | } |
| 600 | |
| 601 | /* |
| 602 | * INV flag is relative to the FORMAT flag - if set it simply |
| 603 | * flips the polarity specified by the Standard |
| 604 | */ |
| 605 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 606 | case SND_SOC_DAIFMT_NB_NF: |
| 607 | break; |
| 608 | case SND_SOC_DAIFMT_NB_IF: |
Padmavathi Venna | b60be4a | 2013-07-26 19:06:48 +0530 | [diff] [blame] | 609 | if (tmp & lrp_rlow) |
| 610 | tmp &= ~lrp_rlow; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 611 | else |
Padmavathi Venna | b60be4a | 2013-07-26 19:06:48 +0530 | [diff] [blame] | 612 | tmp |= lrp_rlow; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 613 | break; |
| 614 | default: |
| 615 | dev_err(&i2s->pdev->dev, "Polarity not supported\n"); |
| 616 | return -EINVAL; |
| 617 | } |
| 618 | |
| 619 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 620 | case SND_SOC_DAIFMT_CBM_CFM: |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 621 | tmp |= mod_slave; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 622 | break; |
| 623 | case SND_SOC_DAIFMT_CBS_CFS: |
| 624 | /* Set default source clock in Master mode */ |
| 625 | if (i2s->rclk_srcrate == 0) |
| 626 | i2s_set_sysclk(dai, SAMSUNG_I2S_RCLKSRC_0, |
| 627 | 0, SND_SOC_CLOCK_IN); |
| 628 | break; |
| 629 | default: |
| 630 | dev_err(&i2s->pdev->dev, "master/slave format not supported\n"); |
| 631 | return -EINVAL; |
| 632 | } |
| 633 | |
Padmavathi Venna | b60be4a | 2013-07-26 19:06:48 +0530 | [diff] [blame] | 634 | /* |
| 635 | * Don't change the I2S mode if any controller is active on this |
| 636 | * channel. |
| 637 | */ |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 638 | if (any_active(i2s) && |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 639 | ((mod & (sdf_mask | lrp_rlow | mod_slave)) != tmp)) { |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 640 | dev_err(&i2s->pdev->dev, |
| 641 | "%s:%d Other DAI busy\n", __func__, __LINE__); |
| 642 | return -EAGAIN; |
| 643 | } |
| 644 | |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 645 | mod &= ~(sdf_mask | lrp_rlow | mod_slave); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 646 | mod |= tmp; |
| 647 | writel(mod, i2s->addr + I2SMOD); |
| 648 | |
| 649 | return 0; |
| 650 | } |
| 651 | |
| 652 | static int i2s_hw_params(struct snd_pcm_substream *substream, |
| 653 | struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) |
| 654 | { |
| 655 | struct i2s_dai *i2s = to_info(dai); |
| 656 | u32 mod = readl(i2s->addr + I2SMOD); |
| 657 | |
| 658 | if (!is_secondary(i2s)) |
| 659 | mod &= ~(MOD_DC2_EN | MOD_DC1_EN); |
| 660 | |
| 661 | switch (params_channels(params)) { |
| 662 | case 6: |
| 663 | mod |= MOD_DC2_EN; |
| 664 | case 4: |
| 665 | mod |= MOD_DC1_EN; |
| 666 | break; |
| 667 | case 2: |
Sangsu Park | 588fb70 | 2012-03-16 15:40:53 +0900 | [diff] [blame] | 668 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 669 | i2s->dma_playback.dma_size = 4; |
| 670 | else |
| 671 | i2s->dma_capture.dma_size = 4; |
| 672 | break; |
| 673 | case 1: |
| 674 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 675 | i2s->dma_playback.dma_size = 2; |
| 676 | else |
| 677 | i2s->dma_capture.dma_size = 2; |
| 678 | |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 679 | break; |
| 680 | default: |
| 681 | dev_err(&i2s->pdev->dev, "%d channels not supported\n", |
| 682 | params_channels(params)); |
| 683 | return -EINVAL; |
| 684 | } |
| 685 | |
| 686 | if (is_secondary(i2s)) |
| 687 | mod &= ~MOD_BLCS_MASK; |
| 688 | else |
| 689 | mod &= ~MOD_BLCP_MASK; |
| 690 | |
| 691 | if (is_manager(i2s)) |
| 692 | mod &= ~MOD_BLC_MASK; |
| 693 | |
Tushar Behera | 88ce146 | 2014-05-23 17:35:39 +0530 | [diff] [blame] | 694 | switch (params_width(params)) { |
| 695 | case 8: |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 696 | if (is_secondary(i2s)) |
| 697 | mod |= MOD_BLCS_8BIT; |
| 698 | else |
| 699 | mod |= MOD_BLCP_8BIT; |
| 700 | if (is_manager(i2s)) |
| 701 | mod |= MOD_BLC_8BIT; |
| 702 | break; |
Tushar Behera | 88ce146 | 2014-05-23 17:35:39 +0530 | [diff] [blame] | 703 | case 16: |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 704 | if (is_secondary(i2s)) |
| 705 | mod |= MOD_BLCS_16BIT; |
| 706 | else |
| 707 | mod |= MOD_BLCP_16BIT; |
| 708 | if (is_manager(i2s)) |
| 709 | mod |= MOD_BLC_16BIT; |
| 710 | break; |
Tushar Behera | 88ce146 | 2014-05-23 17:35:39 +0530 | [diff] [blame] | 711 | case 24: |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 712 | if (is_secondary(i2s)) |
| 713 | mod |= MOD_BLCS_24BIT; |
| 714 | else |
| 715 | mod |= MOD_BLCP_24BIT; |
| 716 | if (is_manager(i2s)) |
| 717 | mod |= MOD_BLC_24BIT; |
| 718 | break; |
| 719 | default: |
| 720 | dev_err(&i2s->pdev->dev, "Format(%d) not supported\n", |
| 721 | params_format(params)); |
| 722 | return -EINVAL; |
| 723 | } |
| 724 | writel(mod, i2s->addr + I2SMOD); |
| 725 | |
Mark Brown | d37bdf7 | 2013-12-05 14:14:52 +0000 | [diff] [blame] | 726 | samsung_asoc_init_dma_data(dai, &i2s->dma_playback, &i2s->dma_capture); |
| 727 | |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 728 | i2s->frmclk = params_rate(params); |
| 729 | |
| 730 | return 0; |
| 731 | } |
| 732 | |
| 733 | /* We set constraints on the substream acc to the version of I2S */ |
| 734 | static int i2s_startup(struct snd_pcm_substream *substream, |
| 735 | struct snd_soc_dai *dai) |
| 736 | { |
| 737 | struct i2s_dai *i2s = to_info(dai); |
| 738 | struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai; |
| 739 | unsigned long flags; |
| 740 | |
| 741 | spin_lock_irqsave(&lock, flags); |
| 742 | |
| 743 | i2s->mode |= DAI_OPENED; |
| 744 | |
| 745 | if (is_manager(other)) |
| 746 | i2s->mode &= ~DAI_MANAGER; |
| 747 | else |
| 748 | i2s->mode |= DAI_MANAGER; |
| 749 | |
Padmavathi Venna | 2d77828 | 2013-01-24 18:05:31 +0530 | [diff] [blame] | 750 | if (!any_active(i2s) && (i2s->quirks & QUIRK_NEED_RSTCLR)) |
| 751 | writel(CON_RSTCLR, i2s->addr + I2SCON); |
| 752 | |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 753 | spin_unlock_irqrestore(&lock, flags); |
| 754 | |
Sylwester Nawrocki | b97c60a | 2014-07-10 18:11:13 +0200 | [diff] [blame] | 755 | if (!is_opened(other) && i2s->cdclk_out) |
| 756 | i2s_set_sysclk(dai, SAMSUNG_I2S_CDCLK, |
| 757 | 0, SND_SOC_CLOCK_OUT); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 758 | return 0; |
| 759 | } |
| 760 | |
| 761 | static void i2s_shutdown(struct snd_pcm_substream *substream, |
| 762 | struct snd_soc_dai *dai) |
| 763 | { |
| 764 | struct i2s_dai *i2s = to_info(dai); |
| 765 | struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai; |
| 766 | unsigned long flags; |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 767 | const struct samsung_i2s_variant_regs *i2s_regs = i2s->variant_regs; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 768 | |
| 769 | spin_lock_irqsave(&lock, flags); |
| 770 | |
| 771 | i2s->mode &= ~DAI_OPENED; |
| 772 | i2s->mode &= ~DAI_MANAGER; |
| 773 | |
Sylwester Nawrocki | b97c60a | 2014-07-10 18:11:13 +0200 | [diff] [blame] | 774 | if (is_opened(other)) { |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 775 | other->mode |= DAI_MANAGER; |
Sylwester Nawrocki | b97c60a | 2014-07-10 18:11:13 +0200 | [diff] [blame] | 776 | } else { |
| 777 | u32 mod = readl(i2s->addr + I2SMOD); |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 778 | i2s->cdclk_out = !(mod & (1 << i2s_regs->cdclkcon_off)); |
Charles Keepax | 133c268 | 2014-09-09 16:51:49 +0100 | [diff] [blame] | 779 | if (other) |
| 780 | other->cdclk_out = i2s->cdclk_out; |
Sylwester Nawrocki | b97c60a | 2014-07-10 18:11:13 +0200 | [diff] [blame] | 781 | } |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 782 | /* Reset any constraint on RFS and BFS */ |
| 783 | i2s->rfs = 0; |
| 784 | i2s->bfs = 0; |
| 785 | |
| 786 | spin_unlock_irqrestore(&lock, flags); |
| 787 | |
| 788 | /* Gate CDCLK by default */ |
| 789 | if (!is_opened(other)) |
| 790 | i2s_set_sysclk(dai, SAMSUNG_I2S_CDCLK, |
| 791 | 0, SND_SOC_CLOCK_IN); |
| 792 | } |
| 793 | |
| 794 | static int config_setup(struct i2s_dai *i2s) |
| 795 | { |
| 796 | struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai; |
| 797 | unsigned rfs, bfs, blc; |
| 798 | u32 psr; |
| 799 | |
| 800 | blc = get_blc(i2s); |
| 801 | |
| 802 | bfs = i2s->bfs; |
| 803 | |
| 804 | if (!bfs && other) |
| 805 | bfs = other->bfs; |
| 806 | |
| 807 | /* Select least possible multiple(2) if no constraint set */ |
| 808 | if (!bfs) |
| 809 | bfs = blc * 2; |
| 810 | |
| 811 | rfs = i2s->rfs; |
| 812 | |
| 813 | if (!rfs && other) |
| 814 | rfs = other->rfs; |
| 815 | |
| 816 | if ((rfs == 256 || rfs == 512) && (blc == 24)) { |
| 817 | dev_err(&i2s->pdev->dev, |
| 818 | "%d-RFS not supported for 24-blc\n", rfs); |
| 819 | return -EINVAL; |
| 820 | } |
| 821 | |
| 822 | if (!rfs) { |
| 823 | if (bfs == 16 || bfs == 32) |
| 824 | rfs = 256; |
| 825 | else |
| 826 | rfs = 384; |
| 827 | } |
| 828 | |
| 829 | /* If already setup and running */ |
| 830 | if (any_active(i2s) && (get_rfs(i2s) != rfs || get_bfs(i2s) != bfs)) { |
| 831 | dev_err(&i2s->pdev->dev, |
| 832 | "%s:%d Other DAI busy\n", __func__, __LINE__); |
| 833 | return -EAGAIN; |
| 834 | } |
| 835 | |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 836 | set_bfs(i2s, bfs); |
| 837 | set_rfs(i2s, rfs); |
| 838 | |
Padmavathi Venna | 7701001 | 2013-07-11 12:38:25 +0530 | [diff] [blame] | 839 | /* Don't bother with PSR in Slave mode */ |
| 840 | if (is_slave(i2s)) |
| 841 | return 0; |
| 842 | |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 843 | if (!(i2s->quirks & QUIRK_NO_MUXPSR)) { |
| 844 | psr = i2s->rclk_srcrate / i2s->frmclk / rfs; |
| 845 | writel(((psr - 1) << 8) | PSR_PSREN, i2s->addr + I2SPSR); |
| 846 | dev_dbg(&i2s->pdev->dev, |
| 847 | "RCLK_SRC=%luHz PSR=%u, RCLK=%dfs, BCLK=%dfs\n", |
| 848 | i2s->rclk_srcrate, psr, rfs, bfs); |
| 849 | } |
| 850 | |
| 851 | return 0; |
| 852 | } |
| 853 | |
| 854 | static int i2s_trigger(struct snd_pcm_substream *substream, |
| 855 | int cmd, struct snd_soc_dai *dai) |
| 856 | { |
| 857 | int capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE); |
| 858 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 859 | struct i2s_dai *i2s = to_info(rtd->cpu_dai); |
| 860 | unsigned long flags; |
| 861 | |
| 862 | switch (cmd) { |
| 863 | case SNDRV_PCM_TRIGGER_START: |
| 864 | case SNDRV_PCM_TRIGGER_RESUME: |
| 865 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 866 | local_irq_save(flags); |
| 867 | |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 868 | if (config_setup(i2s)) { |
| 869 | local_irq_restore(flags); |
| 870 | return -EINVAL; |
| 871 | } |
| 872 | |
| 873 | if (capture) |
| 874 | i2s_rxctrl(i2s, 1); |
| 875 | else |
| 876 | i2s_txctrl(i2s, 1); |
| 877 | |
| 878 | local_irq_restore(flags); |
| 879 | break; |
| 880 | case SNDRV_PCM_TRIGGER_STOP: |
| 881 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 882 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 883 | local_irq_save(flags); |
| 884 | |
Jassi Brar | c90887f | 2012-02-25 16:42:34 +0530 | [diff] [blame] | 885 | if (capture) { |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 886 | i2s_rxctrl(i2s, 0); |
Jassi Brar | 775bc97 | 2010-12-20 11:05:47 +0900 | [diff] [blame] | 887 | i2s_fifo(i2s, FIC_RXFLUSH); |
Jassi Brar | c90887f | 2012-02-25 16:42:34 +0530 | [diff] [blame] | 888 | } else { |
| 889 | i2s_txctrl(i2s, 0); |
Jassi Brar | 775bc97 | 2010-12-20 11:05:47 +0900 | [diff] [blame] | 890 | i2s_fifo(i2s, FIC_TXFLUSH); |
Jassi Brar | c90887f | 2012-02-25 16:42:34 +0530 | [diff] [blame] | 891 | } |
Jassi Brar | 775bc97 | 2010-12-20 11:05:47 +0900 | [diff] [blame] | 892 | |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 893 | local_irq_restore(flags); |
| 894 | break; |
| 895 | } |
| 896 | |
| 897 | return 0; |
| 898 | } |
| 899 | |
| 900 | static int i2s_set_clkdiv(struct snd_soc_dai *dai, |
| 901 | int div_id, int div) |
| 902 | { |
| 903 | struct i2s_dai *i2s = to_info(dai); |
| 904 | struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai; |
| 905 | |
| 906 | switch (div_id) { |
| 907 | case SAMSUNG_I2S_DIV_BCLK: |
| 908 | if ((any_active(i2s) && div && (get_bfs(i2s) != div)) |
| 909 | || (other && other->bfs && (other->bfs != div))) { |
| 910 | dev_err(&i2s->pdev->dev, |
| 911 | "%s:%d Other DAI busy\n", __func__, __LINE__); |
| 912 | return -EAGAIN; |
| 913 | } |
| 914 | i2s->bfs = div; |
| 915 | break; |
| 916 | default: |
| 917 | dev_err(&i2s->pdev->dev, |
| 918 | "Invalid clock divider(%d)\n", div_id); |
| 919 | return -EINVAL; |
| 920 | } |
| 921 | |
| 922 | return 0; |
| 923 | } |
| 924 | |
| 925 | static snd_pcm_sframes_t |
| 926 | i2s_delay(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) |
| 927 | { |
| 928 | struct i2s_dai *i2s = to_info(dai); |
| 929 | u32 reg = readl(i2s->addr + I2SFIC); |
| 930 | snd_pcm_sframes_t delay; |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 931 | const struct samsung_i2s_variant_regs *i2s_regs = i2s->variant_regs; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 932 | |
| 933 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) |
| 934 | delay = FIC_RXCOUNT(reg); |
| 935 | else if (is_secondary(i2s)) |
| 936 | delay = FICS_TXCOUNT(readl(i2s->addr + I2SFICS)); |
| 937 | else |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 938 | delay = (reg >> i2s_regs->ftx0cnt_off) & 0x7f; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 939 | |
| 940 | return delay; |
| 941 | } |
| 942 | |
| 943 | #ifdef CONFIG_PM |
| 944 | static int i2s_suspend(struct snd_soc_dai *dai) |
| 945 | { |
| 946 | struct i2s_dai *i2s = to_info(dai); |
| 947 | |
Sylwester Nawrocki | d3d4e52 | 2014-07-04 16:05:45 +0200 | [diff] [blame] | 948 | i2s->suspend_i2smod = readl(i2s->addr + I2SMOD); |
| 949 | i2s->suspend_i2scon = readl(i2s->addr + I2SCON); |
| 950 | i2s->suspend_i2spsr = readl(i2s->addr + I2SPSR); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 951 | |
| 952 | return 0; |
| 953 | } |
| 954 | |
| 955 | static int i2s_resume(struct snd_soc_dai *dai) |
| 956 | { |
| 957 | struct i2s_dai *i2s = to_info(dai); |
| 958 | |
Sylwester Nawrocki | d3d4e52 | 2014-07-04 16:05:45 +0200 | [diff] [blame] | 959 | writel(i2s->suspend_i2scon, i2s->addr + I2SCON); |
| 960 | writel(i2s->suspend_i2smod, i2s->addr + I2SMOD); |
| 961 | writel(i2s->suspend_i2spsr, i2s->addr + I2SPSR); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 962 | |
| 963 | return 0; |
| 964 | } |
| 965 | #else |
| 966 | #define i2s_suspend NULL |
| 967 | #define i2s_resume NULL |
| 968 | #endif |
| 969 | |
| 970 | static int samsung_i2s_dai_probe(struct snd_soc_dai *dai) |
| 971 | { |
| 972 | struct i2s_dai *i2s = to_info(dai); |
| 973 | struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai; |
Mark Brown | ba56447 | 2014-12-05 19:58:32 +0000 | [diff] [blame] | 974 | int ret; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 975 | |
Mark Brown | 3688569 | 2013-10-19 15:23:15 +0100 | [diff] [blame] | 976 | if (other && other->clk) { /* If this is probe on secondary */ |
| 977 | samsung_asoc_init_dma_data(dai, &other->sec_dai->dma_playback, |
| 978 | NULL); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 979 | goto probe_exit; |
Mark Brown | 3688569 | 2013-10-19 15:23:15 +0100 | [diff] [blame] | 980 | } |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 981 | |
| 982 | i2s->addr = ioremap(i2s->base, 0x100); |
| 983 | if (i2s->addr == NULL) { |
| 984 | dev_err(&i2s->pdev->dev, "cannot ioremap registers\n"); |
| 985 | return -ENXIO; |
| 986 | } |
| 987 | |
| 988 | i2s->clk = clk_get(&i2s->pdev->dev, "iis"); |
| 989 | if (IS_ERR(i2s->clk)) { |
| 990 | dev_err(&i2s->pdev->dev, "failed to get i2s_clock\n"); |
| 991 | iounmap(i2s->addr); |
Mark Brown | ba56447 | 2014-12-05 19:58:32 +0000 | [diff] [blame] | 992 | return PTR_ERR(i2s->clk); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 993 | } |
Mark Brown | ba56447 | 2014-12-05 19:58:32 +0000 | [diff] [blame] | 994 | |
| 995 | ret = clk_prepare_enable(i2s->clk); |
| 996 | if (ret != 0) { |
| 997 | dev_err(&i2s->pdev->dev, "failed to enable clock: %d\n", ret); |
| 998 | return ret; |
| 999 | } |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1000 | |
Mark Brown | 3688569 | 2013-10-19 15:23:15 +0100 | [diff] [blame] | 1001 | samsung_asoc_init_dma_data(dai, &i2s->dma_playback, &i2s->dma_capture); |
Mark Brown | 511e3033 | 2013-10-17 21:18:40 +0100 | [diff] [blame] | 1002 | |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1003 | if (other) { |
| 1004 | other->addr = i2s->addr; |
| 1005 | other->clk = i2s->clk; |
| 1006 | } |
| 1007 | |
| 1008 | if (i2s->quirks & QUIRK_NEED_RSTCLR) |
| 1009 | writel(CON_RSTCLR, i2s->addr + I2SCON); |
| 1010 | |
Padmavathi Venna | b075973 | 2014-11-07 12:24:39 +0530 | [diff] [blame] | 1011 | if (i2s->quirks & QUIRK_SUPPORTS_IDMA) |
Mark Brown | 9b8f569 | 2011-11-27 21:35:40 +0000 | [diff] [blame] | 1012 | idma_reg_addr_init(i2s->addr, |
Sangbeom Kim | 61100f4 | 2011-07-20 17:07:12 +0900 | [diff] [blame] | 1013 | i2s->sec_dai->idma_playback.dma_addr); |
| 1014 | |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1015 | probe_exit: |
| 1016 | /* Reset any constraint on RFS and BFS */ |
| 1017 | i2s->rfs = 0; |
| 1018 | i2s->bfs = 0; |
Tushar Behera | d66eac3 | 2014-04-23 13:34:24 +0530 | [diff] [blame] | 1019 | i2s->rclk_srcrate = 0; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1020 | i2s_txctrl(i2s, 0); |
| 1021 | i2s_rxctrl(i2s, 0); |
| 1022 | i2s_fifo(i2s, FIC_TXFLUSH); |
| 1023 | i2s_fifo(other, FIC_TXFLUSH); |
| 1024 | i2s_fifo(i2s, FIC_RXFLUSH); |
| 1025 | |
| 1026 | /* Gate CDCLK by default */ |
| 1027 | if (!is_opened(other)) |
| 1028 | i2s_set_sysclk(dai, SAMSUNG_I2S_CDCLK, |
| 1029 | 0, SND_SOC_CLOCK_IN); |
| 1030 | |
| 1031 | return 0; |
| 1032 | } |
| 1033 | |
| 1034 | static int samsung_i2s_dai_remove(struct snd_soc_dai *dai) |
| 1035 | { |
| 1036 | struct i2s_dai *i2s = snd_soc_dai_get_drvdata(dai); |
| 1037 | struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai; |
| 1038 | |
| 1039 | if (!other || !other->clk) { |
| 1040 | |
| 1041 | if (i2s->quirks & QUIRK_NEED_RSTCLR) |
| 1042 | writel(0, i2s->addr + I2SCON); |
| 1043 | |
Thomas Abraham | 98614cf | 2012-10-03 08:46:58 +0900 | [diff] [blame] | 1044 | clk_disable_unprepare(i2s->clk); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1045 | clk_put(i2s->clk); |
| 1046 | |
| 1047 | iounmap(i2s->addr); |
| 1048 | } |
| 1049 | |
| 1050 | i2s->clk = NULL; |
| 1051 | |
| 1052 | return 0; |
| 1053 | } |
| 1054 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 1055 | static const struct snd_soc_dai_ops samsung_i2s_dai_ops = { |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1056 | .trigger = i2s_trigger, |
| 1057 | .hw_params = i2s_hw_params, |
| 1058 | .set_fmt = i2s_set_fmt, |
| 1059 | .set_clkdiv = i2s_set_clkdiv, |
| 1060 | .set_sysclk = i2s_set_sysclk, |
| 1061 | .startup = i2s_startup, |
| 1062 | .shutdown = i2s_shutdown, |
| 1063 | .delay = i2s_delay, |
| 1064 | }; |
| 1065 | |
Kuninori Morimoto | 4b82853 | 2013-03-21 03:35:55 -0700 | [diff] [blame] | 1066 | static const struct snd_soc_component_driver samsung_i2s_component = { |
| 1067 | .name = "samsung-i2s", |
| 1068 | }; |
| 1069 | |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1070 | #define SAMSUNG_I2S_RATES SNDRV_PCM_RATE_8000_96000 |
| 1071 | |
| 1072 | #define SAMSUNG_I2S_FMTS (SNDRV_PCM_FMTBIT_S8 | \ |
| 1073 | SNDRV_PCM_FMTBIT_S16_LE | \ |
| 1074 | SNDRV_PCM_FMTBIT_S24_LE) |
| 1075 | |
Bill Pemberton | fdca21a | 2012-12-07 09:26:15 -0500 | [diff] [blame] | 1076 | static struct i2s_dai *i2s_alloc_dai(struct platform_device *pdev, bool sec) |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1077 | { |
| 1078 | struct i2s_dai *i2s; |
Prathyush K | c6f9b1e | 2013-04-02 16:53:02 +0530 | [diff] [blame] | 1079 | int ret; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1080 | |
Mark Brown | b960ce7 | 2011-12-03 20:30:37 +0000 | [diff] [blame] | 1081 | i2s = devm_kzalloc(&pdev->dev, sizeof(struct i2s_dai), GFP_KERNEL); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1082 | if (i2s == NULL) |
| 1083 | return NULL; |
| 1084 | |
| 1085 | i2s->pdev = pdev; |
| 1086 | i2s->pri_dai = NULL; |
| 1087 | i2s->sec_dai = NULL; |
| 1088 | i2s->i2s_dai_drv.symmetric_rates = 1; |
| 1089 | i2s->i2s_dai_drv.probe = samsung_i2s_dai_probe; |
| 1090 | i2s->i2s_dai_drv.remove = samsung_i2s_dai_remove; |
| 1091 | i2s->i2s_dai_drv.ops = &samsung_i2s_dai_ops; |
| 1092 | i2s->i2s_dai_drv.suspend = i2s_suspend; |
| 1093 | i2s->i2s_dai_drv.resume = i2s_resume; |
Charles Keepax | a0ff6ea | 2013-09-11 15:27:29 +0100 | [diff] [blame] | 1094 | i2s->i2s_dai_drv.playback.channels_min = 1; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1095 | i2s->i2s_dai_drv.playback.channels_max = 2; |
| 1096 | i2s->i2s_dai_drv.playback.rates = SAMSUNG_I2S_RATES; |
| 1097 | i2s->i2s_dai_drv.playback.formats = SAMSUNG_I2S_FMTS; |
| 1098 | |
| 1099 | if (!sec) { |
Sangsu Park | 588fb70 | 2012-03-16 15:40:53 +0900 | [diff] [blame] | 1100 | i2s->i2s_dai_drv.capture.channels_min = 1; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1101 | i2s->i2s_dai_drv.capture.channels_max = 2; |
| 1102 | i2s->i2s_dai_drv.capture.rates = SAMSUNG_I2S_RATES; |
| 1103 | i2s->i2s_dai_drv.capture.formats = SAMSUNG_I2S_FMTS; |
Prathyush K | c6f9b1e | 2013-04-02 16:53:02 +0530 | [diff] [blame] | 1104 | dev_set_drvdata(&i2s->pdev->dev, i2s); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1105 | } else { /* Create a new platform_device for Secondary */ |
Prathyush K | c6f9b1e | 2013-04-02 16:53:02 +0530 | [diff] [blame] | 1106 | i2s->pdev = platform_device_alloc("samsung-i2s-sec", -1); |
Wei Yongjun | 29ca9c7 | 2013-10-25 17:06:24 +0800 | [diff] [blame] | 1107 | if (!i2s->pdev) |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1108 | return NULL; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1109 | |
Mark Brown | 2f6f0ff | 2013-08-01 11:02:47 +0100 | [diff] [blame] | 1110 | i2s->pdev->dev.parent = &pdev->dev; |
| 1111 | |
Prathyush K | c6f9b1e | 2013-04-02 16:53:02 +0530 | [diff] [blame] | 1112 | platform_set_drvdata(i2s->pdev, i2s); |
| 1113 | ret = platform_device_add(i2s->pdev); |
| 1114 | if (ret < 0) |
| 1115 | return NULL; |
| 1116 | } |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1117 | |
| 1118 | return i2s; |
| 1119 | } |
| 1120 | |
Padmavathi Venna | 40476f6 | 2013-01-18 17:17:01 +0530 | [diff] [blame] | 1121 | static const struct of_device_id exynos_i2s_match[]; |
| 1122 | |
Padmavathi Venna | 7da493e | 2013-08-12 15:19:51 +0530 | [diff] [blame] | 1123 | static inline const struct samsung_i2s_dai_data *samsung_i2s_get_driver_data( |
| 1124 | struct platform_device *pdev) |
Padmavathi Venna | 7c62eeb | 2013-01-18 17:17:00 +0530 | [diff] [blame] | 1125 | { |
Sylwester Nawrocki | 9cf2474 | 2015-01-14 19:42:28 +0100 | [diff] [blame^] | 1126 | if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) { |
Padmavathi Venna | 40476f6 | 2013-01-18 17:17:01 +0530 | [diff] [blame] | 1127 | const struct of_device_id *match; |
| 1128 | match = of_match_node(exynos_i2s_match, pdev->dev.of_node); |
Sylwester Nawrocki | 9cf2474 | 2015-01-14 19:42:28 +0100 | [diff] [blame^] | 1129 | return match ? match->data : NULL; |
| 1130 | } else { |
Padmavathi Venna | 7da493e | 2013-08-12 15:19:51 +0530 | [diff] [blame] | 1131 | return (struct samsung_i2s_dai_data *) |
| 1132 | platform_get_device_id(pdev)->driver_data; |
Sylwester Nawrocki | 9cf2474 | 2015-01-14 19:42:28 +0100 | [diff] [blame^] | 1133 | } |
Padmavathi Venna | 7c62eeb | 2013-01-18 17:17:00 +0530 | [diff] [blame] | 1134 | } |
| 1135 | |
Rafael J. Wysocki | 641d334 | 2014-12-13 00:42:18 +0100 | [diff] [blame] | 1136 | #ifdef CONFIG_PM |
R. Chandrasekar | 5b1d3c3 | 2013-01-30 17:41:04 +0530 | [diff] [blame] | 1137 | static int i2s_runtime_suspend(struct device *dev) |
| 1138 | { |
| 1139 | struct i2s_dai *i2s = dev_get_drvdata(dev); |
| 1140 | |
| 1141 | clk_disable_unprepare(i2s->clk); |
| 1142 | |
| 1143 | return 0; |
| 1144 | } |
| 1145 | |
| 1146 | static int i2s_runtime_resume(struct device *dev) |
| 1147 | { |
| 1148 | struct i2s_dai *i2s = dev_get_drvdata(dev); |
| 1149 | |
| 1150 | clk_prepare_enable(i2s->clk); |
| 1151 | |
| 1152 | return 0; |
| 1153 | } |
Rafael J. Wysocki | 641d334 | 2014-12-13 00:42:18 +0100 | [diff] [blame] | 1154 | #endif /* CONFIG_PM */ |
R. Chandrasekar | 5b1d3c3 | 2013-01-30 17:41:04 +0530 | [diff] [blame] | 1155 | |
Bill Pemberton | fdca21a | 2012-12-07 09:26:15 -0500 | [diff] [blame] | 1156 | static int samsung_i2s_probe(struct platform_device *pdev) |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1157 | { |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1158 | struct i2s_dai *pri_dai, *sec_dai = NULL; |
Padmavathi Venna | 40476f6 | 2013-01-18 17:17:01 +0530 | [diff] [blame] | 1159 | struct s3c_audio_pdata *i2s_pdata = pdev->dev.platform_data; |
| 1160 | struct samsung_i2s *i2s_cfg = NULL; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1161 | struct resource *res; |
Padmavathi Venna | 40476f6 | 2013-01-18 17:17:01 +0530 | [diff] [blame] | 1162 | u32 regs_base, quirks = 0, idma_addr = 0; |
| 1163 | struct device_node *np = pdev->dev.of_node; |
Padmavathi Venna | 7da493e | 2013-08-12 15:19:51 +0530 | [diff] [blame] | 1164 | const struct samsung_i2s_dai_data *i2s_dai_data; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1165 | int ret = 0; |
| 1166 | |
| 1167 | /* Call during Seconday interface registration */ |
Padmavathi Venna | 7da493e | 2013-08-12 15:19:51 +0530 | [diff] [blame] | 1168 | i2s_dai_data = samsung_i2s_get_driver_data(pdev); |
Padmavathi Venna | 7c62eeb | 2013-01-18 17:17:00 +0530 | [diff] [blame] | 1169 | |
Padmavathi Venna | 7da493e | 2013-08-12 15:19:51 +0530 | [diff] [blame] | 1170 | if (i2s_dai_data->dai_type == TYPE_SEC) { |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1171 | sec_dai = dev_get_drvdata(&pdev->dev); |
Prathyush K | a9b977e | 2013-04-02 16:53:01 +0530 | [diff] [blame] | 1172 | if (!sec_dai) { |
| 1173 | dev_err(&pdev->dev, "Unable to get drvdata\n"); |
| 1174 | return -EFAULT; |
| 1175 | } |
Mark Brown | d644a11 | 2013-09-04 20:37:51 +0100 | [diff] [blame] | 1176 | devm_snd_soc_register_component(&sec_dai->pdev->dev, |
| 1177 | &samsung_i2s_component, |
| 1178 | &sec_dai->i2s_dai_drv, 1); |
Mark Brown | 85ff3c2 | 2013-08-19 22:59:05 +0100 | [diff] [blame] | 1179 | samsung_asoc_dma_platform_register(&pdev->dev); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1180 | return 0; |
| 1181 | } |
| 1182 | |
Padmavathi Venna | 40476f6 | 2013-01-18 17:17:01 +0530 | [diff] [blame] | 1183 | pri_dai = i2s_alloc_dai(pdev, false); |
| 1184 | if (!pri_dai) { |
| 1185 | dev_err(&pdev->dev, "Unable to alloc I2S_pri\n"); |
| 1186 | return -ENOMEM; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1187 | } |
| 1188 | |
Padmavathi Venna | 40476f6 | 2013-01-18 17:17:01 +0530 | [diff] [blame] | 1189 | if (!np) { |
| 1190 | res = platform_get_resource(pdev, IORESOURCE_DMA, 0); |
| 1191 | if (!res) { |
| 1192 | dev_err(&pdev->dev, |
| 1193 | "Unable to get I2S-TX dma resource\n"); |
| 1194 | return -ENXIO; |
| 1195 | } |
| 1196 | pri_dai->dma_playback.channel = res->start; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1197 | |
Padmavathi Venna | 40476f6 | 2013-01-18 17:17:01 +0530 | [diff] [blame] | 1198 | res = platform_get_resource(pdev, IORESOURCE_DMA, 1); |
| 1199 | if (!res) { |
| 1200 | dev_err(&pdev->dev, |
| 1201 | "Unable to get I2S-RX dma resource\n"); |
| 1202 | return -ENXIO; |
| 1203 | } |
| 1204 | pri_dai->dma_capture.channel = res->start; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1205 | |
Padmavathi Venna | 40476f6 | 2013-01-18 17:17:01 +0530 | [diff] [blame] | 1206 | if (i2s_pdata == NULL) { |
| 1207 | dev_err(&pdev->dev, "Can't work without s3c_audio_pdata\n"); |
| 1208 | return -EINVAL; |
| 1209 | } |
| 1210 | |
| 1211 | if (&i2s_pdata->type) |
| 1212 | i2s_cfg = &i2s_pdata->type.i2s; |
| 1213 | |
| 1214 | if (i2s_cfg) { |
| 1215 | quirks = i2s_cfg->quirks; |
| 1216 | idma_addr = i2s_cfg->idma_addr; |
| 1217 | } |
| 1218 | } else { |
Padmavathi Venna | 7da493e | 2013-08-12 15:19:51 +0530 | [diff] [blame] | 1219 | quirks = i2s_dai_data->quirks; |
Padmavathi Venna | 40476f6 | 2013-01-18 17:17:01 +0530 | [diff] [blame] | 1220 | if (of_property_read_u32(np, "samsung,idma-addr", |
| 1221 | &idma_addr)) { |
Padmavathi Venna | b075973 | 2014-11-07 12:24:39 +0530 | [diff] [blame] | 1222 | if (quirks & QUIRK_SUPPORTS_IDMA) { |
| 1223 | dev_info(&pdev->dev, "idma address is not"\ |
Padmavathi Venna | 40476f6 | 2013-01-18 17:17:01 +0530 | [diff] [blame] | 1224 | "specified"); |
Padmavathi Venna | 40476f6 | 2013-01-18 17:17:01 +0530 | [diff] [blame] | 1225 | } |
| 1226 | } |
| 1227 | } |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1228 | |
| 1229 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1230 | if (!res) { |
| 1231 | dev_err(&pdev->dev, "Unable to get I2S SFR address\n"); |
| 1232 | return -ENXIO; |
| 1233 | } |
| 1234 | |
| 1235 | if (!request_mem_region(res->start, resource_size(res), |
| 1236 | "samsung-i2s")) { |
| 1237 | dev_err(&pdev->dev, "Unable to request SFR region\n"); |
| 1238 | return -EBUSY; |
| 1239 | } |
| 1240 | regs_base = res->start; |
| 1241 | |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1242 | pri_dai->dma_playback.dma_addr = regs_base + I2STXD; |
| 1243 | pri_dai->dma_capture.dma_addr = regs_base + I2SRXD; |
Padmavathi Venna | 40476f6 | 2013-01-18 17:17:01 +0530 | [diff] [blame] | 1244 | pri_dai->dma_playback.ch_name = "tx"; |
Padmavathi Venna | 40476f6 | 2013-01-18 17:17:01 +0530 | [diff] [blame] | 1245 | pri_dai->dma_capture.ch_name = "rx"; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1246 | pri_dai->dma_playback.dma_size = 4; |
| 1247 | pri_dai->dma_capture.dma_size = 4; |
| 1248 | pri_dai->base = regs_base; |
| 1249 | pri_dai->quirks = quirks; |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 1250 | pri_dai->variant_regs = i2s_dai_data->i2s_variant_regs; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1251 | |
| 1252 | if (quirks & QUIRK_PRI_6CHAN) |
| 1253 | pri_dai->i2s_dai_drv.playback.channels_max = 6; |
| 1254 | |
| 1255 | if (quirks & QUIRK_SEC_DAI) { |
| 1256 | sec_dai = i2s_alloc_dai(pdev, true); |
| 1257 | if (!sec_dai) { |
| 1258 | dev_err(&pdev->dev, "Unable to alloc I2S_sec\n"); |
| 1259 | ret = -ENOMEM; |
Mark Brown | b960ce7 | 2011-12-03 20:30:37 +0000 | [diff] [blame] | 1260 | goto err; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1261 | } |
Sylwester Nawrocki | 7e5d870 | 2014-12-08 18:45:54 +0100 | [diff] [blame] | 1262 | |
| 1263 | sec_dai->variant_regs = pri_dai->variant_regs; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1264 | sec_dai->dma_playback.dma_addr = regs_base + I2STXDS; |
Padmavathi Venna | 40476f6 | 2013-01-18 17:17:01 +0530 | [diff] [blame] | 1265 | sec_dai->dma_playback.ch_name = "tx-sec"; |
| 1266 | |
| 1267 | if (!np) { |
| 1268 | res = platform_get_resource(pdev, IORESOURCE_DMA, 2); |
| 1269 | if (res) |
| 1270 | sec_dai->dma_playback.channel = res->start; |
| 1271 | } |
| 1272 | |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1273 | sec_dai->dma_playback.dma_size = 4; |
| 1274 | sec_dai->base = regs_base; |
| 1275 | sec_dai->quirks = quirks; |
Padmavathi Venna | 40476f6 | 2013-01-18 17:17:01 +0530 | [diff] [blame] | 1276 | sec_dai->idma_playback.dma_addr = idma_addr; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1277 | sec_dai->pri_dai = pri_dai; |
| 1278 | pri_dai->sec_dai = sec_dai; |
| 1279 | } |
| 1280 | |
Mark Brown | 0429ffe | 2013-07-02 13:10:28 +0100 | [diff] [blame] | 1281 | if (i2s_pdata && i2s_pdata->cfg_gpio && i2s_pdata->cfg_gpio(pdev)) { |
| 1282 | dev_err(&pdev->dev, "Unable to configure gpio\n"); |
| 1283 | ret = -EINVAL; |
| 1284 | goto err; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1285 | } |
| 1286 | |
Mark Brown | d644a11 | 2013-09-04 20:37:51 +0100 | [diff] [blame] | 1287 | devm_snd_soc_register_component(&pri_dai->pdev->dev, |
| 1288 | &samsung_i2s_component, |
| 1289 | &pri_dai->i2s_dai_drv, 1); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1290 | |
Mark Brown | c5cf4db | 2011-12-08 16:45:03 +0800 | [diff] [blame] | 1291 | pm_runtime_enable(&pdev->dev); |
| 1292 | |
Mark Brown | 85ff3c2 | 2013-08-19 22:59:05 +0100 | [diff] [blame] | 1293 | samsung_asoc_dma_platform_register(&pdev->dev); |
Padmavathi Venna | a08485d8 | 2012-12-07 13:59:21 +0530 | [diff] [blame] | 1294 | |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1295 | return 0; |
Mark Brown | b960ce7 | 2011-12-03 20:30:37 +0000 | [diff] [blame] | 1296 | err: |
Sachin Kamat | 57e3378 | 2014-01-24 16:23:22 +0530 | [diff] [blame] | 1297 | if (res) |
| 1298 | release_mem_region(regs_base, resource_size(res)); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1299 | |
| 1300 | return ret; |
| 1301 | } |
| 1302 | |
Bill Pemberton | fdca21a | 2012-12-07 09:26:15 -0500 | [diff] [blame] | 1303 | static int samsung_i2s_remove(struct platform_device *pdev) |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1304 | { |
| 1305 | struct i2s_dai *i2s, *other; |
Mark Brown | c5cf4db | 2011-12-08 16:45:03 +0800 | [diff] [blame] | 1306 | struct resource *res; |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1307 | |
| 1308 | i2s = dev_get_drvdata(&pdev->dev); |
| 1309 | other = i2s->pri_dai ? : i2s->sec_dai; |
| 1310 | |
| 1311 | if (other) { |
| 1312 | other->pri_dai = NULL; |
| 1313 | other->sec_dai = NULL; |
| 1314 | } else { |
Mark Brown | c5cf4db | 2011-12-08 16:45:03 +0800 | [diff] [blame] | 1315 | pm_runtime_disable(&pdev->dev); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1316 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1317 | if (res) |
| 1318 | release_mem_region(res->start, resource_size(res)); |
| 1319 | } |
| 1320 | |
| 1321 | i2s->pri_dai = NULL; |
| 1322 | i2s->sec_dai = NULL; |
| 1323 | |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1324 | return 0; |
| 1325 | } |
| 1326 | |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 1327 | static const struct samsung_i2s_variant_regs i2sv3_regs = { |
| 1328 | .bfs_off = 1, |
| 1329 | .rfs_off = 3, |
| 1330 | .sdf_off = 5, |
| 1331 | .txr_off = 8, |
| 1332 | .rclksrc_off = 10, |
| 1333 | .mss_off = 11, |
| 1334 | .cdclkcon_off = 12, |
| 1335 | .lrp_off = 7, |
| 1336 | .bfs_mask = 0x3, |
| 1337 | .rfs_mask = 0x3, |
| 1338 | .ftx0cnt_off = 8, |
| 1339 | }; |
| 1340 | |
| 1341 | static const struct samsung_i2s_variant_regs i2sv6_regs = { |
| 1342 | .bfs_off = 0, |
| 1343 | .rfs_off = 4, |
| 1344 | .sdf_off = 6, |
| 1345 | .txr_off = 8, |
| 1346 | .rclksrc_off = 10, |
| 1347 | .mss_off = 11, |
| 1348 | .cdclkcon_off = 12, |
| 1349 | .lrp_off = 15, |
| 1350 | .bfs_mask = 0xf, |
| 1351 | .rfs_mask = 0x3, |
| 1352 | .ftx0cnt_off = 8, |
| 1353 | }; |
| 1354 | |
| 1355 | static const struct samsung_i2s_variant_regs i2sv7_regs = { |
| 1356 | .bfs_off = 0, |
| 1357 | .rfs_off = 4, |
| 1358 | .sdf_off = 7, |
| 1359 | .txr_off = 9, |
| 1360 | .rclksrc_off = 11, |
| 1361 | .mss_off = 12, |
| 1362 | .cdclkcon_off = 22, |
| 1363 | .lrp_off = 15, |
| 1364 | .bfs_mask = 0xf, |
| 1365 | .rfs_mask = 0x7, |
| 1366 | .ftx0cnt_off = 0, |
| 1367 | }; |
| 1368 | |
| 1369 | static const struct samsung_i2s_variant_regs i2sv5_i2s1_regs = { |
| 1370 | .bfs_off = 0, |
| 1371 | .rfs_off = 3, |
| 1372 | .sdf_off = 6, |
| 1373 | .txr_off = 8, |
| 1374 | .rclksrc_off = 10, |
| 1375 | .mss_off = 11, |
| 1376 | .cdclkcon_off = 12, |
| 1377 | .lrp_off = 15, |
| 1378 | .bfs_mask = 0x7, |
| 1379 | .rfs_mask = 0x7, |
| 1380 | .ftx0cnt_off = 8, |
| 1381 | }; |
| 1382 | |
Padmavathi Venna | 7da493e | 2013-08-12 15:19:51 +0530 | [diff] [blame] | 1383 | static const struct samsung_i2s_dai_data i2sv3_dai_type = { |
| 1384 | .dai_type = TYPE_PRI, |
| 1385 | .quirks = QUIRK_NO_MUXPSR, |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 1386 | .i2s_variant_regs = &i2sv3_regs, |
Padmavathi Venna | 7da493e | 2013-08-12 15:19:51 +0530 | [diff] [blame] | 1387 | }; |
| 1388 | |
| 1389 | static const struct samsung_i2s_dai_data i2sv5_dai_type = { |
| 1390 | .dai_type = TYPE_PRI, |
Padmavathi Venna | b075973 | 2014-11-07 12:24:39 +0530 | [diff] [blame] | 1391 | .quirks = QUIRK_PRI_6CHAN | QUIRK_SEC_DAI | QUIRK_NEED_RSTCLR | |
| 1392 | QUIRK_SUPPORTS_IDMA, |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 1393 | .i2s_variant_regs = &i2sv3_regs, |
Padmavathi Venna | 7da493e | 2013-08-12 15:19:51 +0530 | [diff] [blame] | 1394 | }; |
| 1395 | |
Padmavathi Venna | 4ca0c0d | 2013-08-12 15:19:52 +0530 | [diff] [blame] | 1396 | static const struct samsung_i2s_dai_data i2sv6_dai_type = { |
| 1397 | .dai_type = TYPE_PRI, |
| 1398 | .quirks = QUIRK_PRI_6CHAN | QUIRK_SEC_DAI | QUIRK_NEED_RSTCLR | |
Padmavathi Venna | b075973 | 2014-11-07 12:24:39 +0530 | [diff] [blame] | 1399 | QUIRK_SUPPORTS_TDM | QUIRK_SUPPORTS_IDMA, |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 1400 | .i2s_variant_regs = &i2sv6_regs, |
| 1401 | }; |
| 1402 | |
| 1403 | static const struct samsung_i2s_dai_data i2sv7_dai_type = { |
| 1404 | .dai_type = TYPE_PRI, |
| 1405 | .quirks = QUIRK_PRI_6CHAN | QUIRK_SEC_DAI | QUIRK_NEED_RSTCLR | |
| 1406 | QUIRK_SUPPORTS_TDM, |
| 1407 | .i2s_variant_regs = &i2sv7_regs, |
| 1408 | }; |
| 1409 | |
| 1410 | static const struct samsung_i2s_dai_data i2sv5_dai_type_i2s1 = { |
| 1411 | .dai_type = TYPE_PRI, |
| 1412 | .quirks = QUIRK_PRI_6CHAN | QUIRK_NEED_RSTCLR, |
| 1413 | .i2s_variant_regs = &i2sv5_i2s1_regs, |
Padmavathi Venna | 4ca0c0d | 2013-08-12 15:19:52 +0530 | [diff] [blame] | 1414 | }; |
| 1415 | |
Padmavathi Venna | 7da493e | 2013-08-12 15:19:51 +0530 | [diff] [blame] | 1416 | static const struct samsung_i2s_dai_data samsung_dai_type_pri = { |
| 1417 | .dai_type = TYPE_PRI, |
| 1418 | }; |
| 1419 | |
| 1420 | static const struct samsung_i2s_dai_data samsung_dai_type_sec = { |
| 1421 | .dai_type = TYPE_SEC, |
| 1422 | }; |
| 1423 | |
Padmavathi Venna | 7c62eeb | 2013-01-18 17:17:00 +0530 | [diff] [blame] | 1424 | static struct platform_device_id samsung_i2s_driver_ids[] = { |
| 1425 | { |
| 1426 | .name = "samsung-i2s", |
Mark Brown | 3f02498 | 2014-12-05 19:56:17 +0000 | [diff] [blame] | 1427 | .driver_data = (kernel_ulong_t)&i2sv3_dai_type, |
Padmavathi Venna | 7c62eeb | 2013-01-18 17:17:00 +0530 | [diff] [blame] | 1428 | }, { |
| 1429 | .name = "samsung-i2s-sec", |
Padmavathi Venna | 7da493e | 2013-08-12 15:19:51 +0530 | [diff] [blame] | 1430 | .driver_data = (kernel_ulong_t)&samsung_dai_type_sec, |
Mark Brown | 3f02498 | 2014-12-05 19:56:17 +0000 | [diff] [blame] | 1431 | }, { |
| 1432 | .name = "samsung-i2sv4", |
| 1433 | .driver_data = (kernel_ulong_t)&i2sv5_dai_type, |
Padmavathi Venna | 7c62eeb | 2013-01-18 17:17:00 +0530 | [diff] [blame] | 1434 | }, |
| 1435 | {}, |
| 1436 | }; |
Arnd Bergmann | 2af1955 | 2013-04-11 02:05:03 +0200 | [diff] [blame] | 1437 | MODULE_DEVICE_TABLE(platform, samsung_i2s_driver_ids); |
Padmavathi Venna | 7c62eeb | 2013-01-18 17:17:00 +0530 | [diff] [blame] | 1438 | |
Padmavathi Venna | 40476f6 | 2013-01-18 17:17:01 +0530 | [diff] [blame] | 1439 | #ifdef CONFIG_OF |
Padmavathi Venna | 40476f6 | 2013-01-18 17:17:01 +0530 | [diff] [blame] | 1440 | static const struct of_device_id exynos_i2s_match[] = { |
Padmavathi Venna | 7da493e | 2013-08-12 15:19:51 +0530 | [diff] [blame] | 1441 | { |
| 1442 | .compatible = "samsung,s3c6410-i2s", |
| 1443 | .data = &i2sv3_dai_type, |
| 1444 | }, { |
| 1445 | .compatible = "samsung,s5pv210-i2s", |
| 1446 | .data = &i2sv5_dai_type, |
Padmavathi Venna | 4ca0c0d | 2013-08-12 15:19:52 +0530 | [diff] [blame] | 1447 | }, { |
| 1448 | .compatible = "samsung,exynos5420-i2s", |
| 1449 | .data = &i2sv6_dai_type, |
Padmavathi Venna | a5a5687 | 2014-11-07 12:24:40 +0530 | [diff] [blame] | 1450 | }, { |
| 1451 | .compatible = "samsung,exynos7-i2s", |
| 1452 | .data = &i2sv7_dai_type, |
| 1453 | }, { |
| 1454 | .compatible = "samsung,exynos7-i2s1", |
| 1455 | .data = &i2sv5_dai_type_i2s1, |
Padmavathi Venna | 40476f6 | 2013-01-18 17:17:01 +0530 | [diff] [blame] | 1456 | }, |
| 1457 | {}, |
| 1458 | }; |
| 1459 | MODULE_DEVICE_TABLE(of, exynos_i2s_match); |
| 1460 | #endif |
| 1461 | |
R. Chandrasekar | 5b1d3c3 | 2013-01-30 17:41:04 +0530 | [diff] [blame] | 1462 | static const struct dev_pm_ops samsung_i2s_pm = { |
| 1463 | SET_RUNTIME_PM_OPS(i2s_runtime_suspend, |
| 1464 | i2s_runtime_resume, NULL) |
| 1465 | }; |
| 1466 | |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1467 | static struct platform_driver samsung_i2s_driver = { |
| 1468 | .probe = samsung_i2s_probe, |
Bill Pemberton | fdca21a | 2012-12-07 09:26:15 -0500 | [diff] [blame] | 1469 | .remove = samsung_i2s_remove, |
Padmavathi Venna | 7c62eeb | 2013-01-18 17:17:00 +0530 | [diff] [blame] | 1470 | .id_table = samsung_i2s_driver_ids, |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1471 | .driver = { |
| 1472 | .name = "samsung-i2s", |
Padmavathi Venna | 40476f6 | 2013-01-18 17:17:01 +0530 | [diff] [blame] | 1473 | .of_match_table = of_match_ptr(exynos_i2s_match), |
R. Chandrasekar | 5b1d3c3 | 2013-01-30 17:41:04 +0530 | [diff] [blame] | 1474 | .pm = &samsung_i2s_pm, |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1475 | }, |
| 1476 | }; |
| 1477 | |
Mark Brown | e00c3f5 | 2011-11-23 15:20:13 +0000 | [diff] [blame] | 1478 | module_platform_driver(samsung_i2s_driver); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1479 | |
| 1480 | /* Module information */ |
Jaswinder Singh | df8ad33 | 2012-02-25 16:24:36 +0530 | [diff] [blame] | 1481 | MODULE_AUTHOR("Jaswinder Singh, <jassisinghbrar@gmail.com>"); |
Jassi Brar | 1c7ac01 | 2010-11-22 15:36:59 +0900 | [diff] [blame] | 1482 | MODULE_DESCRIPTION("Samsung I2S Interface"); |
| 1483 | MODULE_ALIAS("platform:samsung-i2s"); |
| 1484 | MODULE_LICENSE("GPL"); |