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