Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Fifo-attached Serial Interface (FSI) support for SH7724 |
| 3 | * |
| 4 | * Copyright (C) 2009 Renesas Solutions Corp. |
| 5 | * Kuninori Morimoto <morimoto.kuninori@renesas.com> |
| 6 | * |
| 7 | * Based on ssi.c |
| 8 | * Copyright (c) 2007 Manuel Lauss <mano@roarinelk.homelinux.net> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License version 2 as |
| 12 | * published by the Free Software Foundation. |
| 13 | */ |
| 14 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 15 | #include <linux/delay.h> |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 16 | #include <linux/pm_runtime.h> |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 17 | #include <linux/io.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 19 | #include <sound/soc.h> |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 20 | #include <sound/sh_fsi.h> |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 21 | |
Kuninori Morimoto | e8c8b63 | 2010-12-03 17:37:55 +0900 | [diff] [blame] | 22 | /* PortA/PortB register */ |
| 23 | #define REG_DO_FMT 0x0000 |
| 24 | #define REG_DOFF_CTL 0x0004 |
| 25 | #define REG_DOFF_ST 0x0008 |
| 26 | #define REG_DI_FMT 0x000C |
| 27 | #define REG_DIFF_CTL 0x0010 |
| 28 | #define REG_DIFF_ST 0x0014 |
| 29 | #define REG_CKG1 0x0018 |
| 30 | #define REG_CKG2 0x001C |
| 31 | #define REG_DIDT 0x0020 |
| 32 | #define REG_DODT 0x0024 |
| 33 | #define REG_MUTE_ST 0x0028 |
| 34 | #define REG_OUT_SEL 0x0030 |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 35 | |
Kuninori Morimoto | 43fa95c | 2010-12-03 17:38:03 +0900 | [diff] [blame] | 36 | /* master register */ |
| 37 | #define MST_CLK_RST 0x0210 |
| 38 | #define MST_SOFT_RST 0x0214 |
| 39 | #define MST_FIFO_SZ 0x0218 |
| 40 | |
| 41 | /* core register (depend on FSI version) */ |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 42 | #define A_MST_CTLR 0x0180 |
| 43 | #define B_MST_CTLR 0x01A0 |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 44 | #define CPU_INT_ST 0x01F4 |
| 45 | #define CPU_IEMSK 0x01F8 |
| 46 | #define CPU_IMSK 0x01FC |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 47 | #define INT_ST 0x0200 |
| 48 | #define IEMSK 0x0204 |
| 49 | #define IMSK 0x0208 |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 50 | |
| 51 | /* DO_FMT */ |
| 52 | /* DI_FMT */ |
Kuninori Morimoto | f7d711e | 2010-12-03 17:36:24 +0900 | [diff] [blame] | 53 | #define CR_BWS_24 (0x0 << 20) /* FSI2 */ |
| 54 | #define CR_BWS_16 (0x1 << 20) /* FSI2 */ |
| 55 | #define CR_BWS_20 (0x2 << 20) /* FSI2 */ |
| 56 | |
| 57 | #define CR_DTMD_PCM (0x0 << 8) /* FSI2 */ |
| 58 | #define CR_DTMD_SPDIF_PCM (0x1 << 8) /* FSI2 */ |
| 59 | #define CR_DTMD_SPDIF_STREAM (0x2 << 8) /* FSI2 */ |
| 60 | |
Kuninori Morimoto | a7ffb52 | 2010-07-13 12:13:00 +0900 | [diff] [blame] | 61 | #define CR_MONO (0x0 << 4) |
| 62 | #define CR_MONO_D (0x1 << 4) |
| 63 | #define CR_PCM (0x2 << 4) |
| 64 | #define CR_I2S (0x3 << 4) |
| 65 | #define CR_TDM (0x4 << 4) |
| 66 | #define CR_TDM_D (0x5 << 4) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 67 | |
| 68 | /* DOFF_CTL */ |
| 69 | /* DIFF_CTL */ |
| 70 | #define IRQ_HALF 0x00100000 |
| 71 | #define FIFO_CLR 0x00000001 |
| 72 | |
| 73 | /* DOFF_ST */ |
| 74 | #define ERR_OVER 0x00000010 |
| 75 | #define ERR_UNDER 0x00000001 |
Kuninori Morimoto | 59c3b00 | 2009-12-28 14:09:16 +0900 | [diff] [blame] | 76 | #define ST_ERR (ERR_OVER | ERR_UNDER) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 77 | |
Kuninori Morimoto | ccad7b4 | 2010-07-13 12:13:14 +0900 | [diff] [blame] | 78 | /* CKG1 */ |
| 79 | #define ACKMD_MASK 0x00007000 |
| 80 | #define BPFMD_MASK 0x00000700 |
Kuninori Morimoto | 4d805f7 | 2011-01-20 11:46:02 +0900 | [diff] [blame] | 81 | #define DIMD (1 << 4) |
| 82 | #define DOMD (1 << 0) |
Kuninori Morimoto | ccad7b4 | 2010-07-13 12:13:14 +0900 | [diff] [blame] | 83 | |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 84 | /* A/B MST_CTLR */ |
| 85 | #define BP (1 << 4) /* Fix the signal of Biphase output */ |
| 86 | #define SE (1 << 0) /* Fix the master clock */ |
| 87 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 88 | /* CLK_RST */ |
Kuninori Morimoto | 1f5e2a3 | 2011-04-21 10:33:52 +0900 | [diff] [blame] | 89 | #define CRB (1 << 4) |
| 90 | #define CRA (1 << 0) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 91 | |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 92 | /* IO SHIFT / MACRO */ |
| 93 | #define BI_SHIFT 12 |
| 94 | #define BO_SHIFT 8 |
| 95 | #define AI_SHIFT 4 |
| 96 | #define AO_SHIFT 0 |
| 97 | #define AB_IO(param, shift) (param << shift) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 98 | |
Kuninori Morimoto | feb58cf | 2010-03-24 15:27:24 +0900 | [diff] [blame] | 99 | /* SOFT_RST */ |
| 100 | #define PBSR (1 << 12) /* Port B Software Reset */ |
| 101 | #define PASR (1 << 8) /* Port A Software Reset */ |
| 102 | #define IR (1 << 4) /* Interrupt Reset */ |
| 103 | #define FSISR (1 << 0) /* Software Reset */ |
| 104 | |
Kuninori Morimoto | f7d711e | 2010-12-03 17:36:24 +0900 | [diff] [blame] | 105 | /* OUT_SEL (FSI2) */ |
| 106 | #define DMMD (1 << 4) /* SPDIF output timing 0: Biphase only */ |
| 107 | /* 1: Biphase and serial */ |
| 108 | |
Kuninori Morimoto | 4a942b4 | 2010-03-25 19:15:51 +0900 | [diff] [blame] | 109 | /* FIFO_SZ */ |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 110 | #define FIFO_SZ_MASK 0x7 |
Kuninori Morimoto | 4a942b4 | 2010-03-25 19:15:51 +0900 | [diff] [blame] | 111 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 112 | #define FSI_RATES SNDRV_PCM_RATE_8000_96000 |
| 113 | |
| 114 | #define FSI_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE) |
| 115 | |
Kuninori Morimoto | d7c5762 | 2011-01-24 10:42:33 +0900 | [diff] [blame] | 116 | typedef int (*set_rate_func)(struct device *dev, int is_porta, int rate, int enable); |
| 117 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 118 | /* |
Kuninori Morimoto | 5bfb9ad | 2010-09-17 13:48:45 +0900 | [diff] [blame] | 119 | * FSI driver use below type name for variable |
| 120 | * |
Kuninori Morimoto | 5bfb9ad | 2010-09-17 13:48:45 +0900 | [diff] [blame] | 121 | * xxx_num : number of data |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 122 | * xxx_pos : position of data |
| 123 | * xxx_capa : capacity of data |
| 124 | */ |
| 125 | |
| 126 | /* |
| 127 | * period/frame/sample image |
| 128 | * |
| 129 | * ex) PCM (2ch) |
| 130 | * |
| 131 | * period pos period pos |
| 132 | * [n] [n + 1] |
| 133 | * |<-------------------- period--------------------->| |
| 134 | * ==|============================================ ... =|== |
| 135 | * | | |
| 136 | * ||<----- frame ----->|<------ frame ----->| ... | |
| 137 | * |+--------------------+--------------------+- ... | |
| 138 | * ||[ sample ][ sample ]|[ sample ][ sample ]| ... | |
| 139 | * |+--------------------+--------------------+- ... | |
| 140 | * ==|============================================ ... =|== |
| 141 | */ |
| 142 | |
| 143 | /* |
| 144 | * FSI FIFO image |
| 145 | * |
| 146 | * | | |
| 147 | * | | |
| 148 | * | [ sample ] | |
| 149 | * | [ sample ] | |
| 150 | * | [ sample ] | |
| 151 | * | [ sample ] | |
| 152 | * --> go to codecs |
Kuninori Morimoto | 5bfb9ad | 2010-09-17 13:48:45 +0900 | [diff] [blame] | 153 | */ |
| 154 | |
| 155 | /* |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 156 | * struct |
| 157 | */ |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 158 | |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 159 | struct fsi_stream { |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 160 | struct snd_pcm_substream *substream; |
| 161 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 162 | int fifo_sample_capa; /* sample capacity of FSI FIFO */ |
| 163 | int buff_sample_capa; /* sample capacity of ALSA buffer */ |
| 164 | int buff_sample_pos; /* sample position of ALSA buffer */ |
| 165 | int period_samples; /* sample number / 1 period */ |
| 166 | int period_pos; /* current period position */ |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 167 | |
| 168 | int uerr_num; |
| 169 | int oerr_num; |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | struct fsi_priv { |
| 173 | void __iomem *base; |
| 174 | struct fsi_master *master; |
| 175 | |
| 176 | struct fsi_stream playback; |
| 177 | struct fsi_stream capture; |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 178 | |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 179 | u32 do_fmt; |
| 180 | u32 di_fmt; |
| 181 | |
Kuninori Morimoto | 6a9ebad | 2011-04-21 10:33:36 +0900 | [diff] [blame] | 182 | int chan_num:16; |
| 183 | int clk_master:1; |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 184 | int spdif:1; |
Kuninori Morimoto | 6a9ebad | 2011-04-21 10:33:36 +0900 | [diff] [blame] | 185 | |
Kuninori Morimoto | d4bc99b | 2010-11-24 02:44:06 +0000 | [diff] [blame] | 186 | long rate; |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 187 | |
| 188 | /* for suspend/resume */ |
| 189 | u32 saved_do_fmt; |
| 190 | u32 saved_di_fmt; |
| 191 | u32 saved_ckg1; |
| 192 | u32 saved_ckg2; |
| 193 | u32 saved_out_sel; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 194 | }; |
| 195 | |
Kuninori Morimoto | 73b92c1 | 2010-07-13 12:13:04 +0900 | [diff] [blame] | 196 | struct fsi_core { |
| 197 | int ver; |
| 198 | |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 199 | u32 int_st; |
| 200 | u32 iemsk; |
| 201 | u32 imsk; |
Kuninori Morimoto | 2b0e730 | 2010-12-03 17:37:44 +0900 | [diff] [blame] | 202 | u32 a_mclk; |
| 203 | u32 b_mclk; |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 204 | }; |
| 205 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 206 | struct fsi_master { |
| 207 | void __iomem *base; |
| 208 | int irq; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 209 | struct fsi_priv fsia; |
| 210 | struct fsi_priv fsib; |
Kuninori Morimoto | 73b92c1 | 2010-07-13 12:13:04 +0900 | [diff] [blame] | 211 | struct fsi_core *core; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 212 | struct sh_fsi_platform_info *info; |
Kuninori Morimoto | 8fc176d | 2010-01-28 13:46:16 +0900 | [diff] [blame] | 213 | spinlock_t lock; |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 214 | |
| 215 | /* for suspend/resume */ |
| 216 | u32 saved_a_mclk; |
| 217 | u32 saved_b_mclk; |
| 218 | u32 saved_iemsk; |
| 219 | u32 saved_imsk; |
| 220 | u32 saved_clk_rst; |
Kuninori Morimoto | 1f5e2a3 | 2011-04-21 10:33:52 +0900 | [diff] [blame] | 221 | u32 saved_soft_rst; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 222 | }; |
| 223 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 224 | /* |
| 225 | * basic read write function |
| 226 | */ |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 227 | |
Guennadi Liakhovetski | 0f69d97 | 2010-02-03 17:37:23 +0100 | [diff] [blame] | 228 | static void __fsi_reg_write(u32 reg, u32 data) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 229 | { |
| 230 | /* valid data area is 24bit */ |
| 231 | data &= 0x00ffffff; |
| 232 | |
Guennadi Liakhovetski | 0f69d97 | 2010-02-03 17:37:23 +0100 | [diff] [blame] | 233 | __raw_writel(data, reg); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | static u32 __fsi_reg_read(u32 reg) |
| 237 | { |
Guennadi Liakhovetski | 0f69d97 | 2010-02-03 17:37:23 +0100 | [diff] [blame] | 238 | return __raw_readl(reg); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 239 | } |
| 240 | |
Guennadi Liakhovetski | 0f69d97 | 2010-02-03 17:37:23 +0100 | [diff] [blame] | 241 | static void __fsi_reg_mask_set(u32 reg, u32 mask, u32 data) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 242 | { |
| 243 | u32 val = __fsi_reg_read(reg); |
| 244 | |
| 245 | val &= ~mask; |
| 246 | val |= data & mask; |
| 247 | |
Guennadi Liakhovetski | 0f69d97 | 2010-02-03 17:37:23 +0100 | [diff] [blame] | 248 | __fsi_reg_write(reg, val); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 249 | } |
| 250 | |
Kuninori Morimoto | e8c8b63 | 2010-12-03 17:37:55 +0900 | [diff] [blame] | 251 | #define fsi_reg_write(p, r, d)\ |
| 252 | __fsi_reg_write((u32)(p->base + REG_##r), d) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 253 | |
Kuninori Morimoto | e8c8b63 | 2010-12-03 17:37:55 +0900 | [diff] [blame] | 254 | #define fsi_reg_read(p, r)\ |
| 255 | __fsi_reg_read((u32)(p->base + REG_##r)) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 256 | |
Kuninori Morimoto | e8c8b63 | 2010-12-03 17:37:55 +0900 | [diff] [blame] | 257 | #define fsi_reg_mask_set(p, r, m, d)\ |
| 258 | __fsi_reg_mask_set((u32)(p->base + REG_##r), m, d) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 259 | |
Kuninori Morimoto | 43fa95c | 2010-12-03 17:38:03 +0900 | [diff] [blame] | 260 | #define fsi_master_read(p, r) _fsi_master_read(p, MST_##r) |
| 261 | #define fsi_core_read(p, r) _fsi_master_read(p, p->core->r) |
| 262 | static u32 _fsi_master_read(struct fsi_master *master, u32 reg) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 263 | { |
Kuninori Morimoto | 8fc176d | 2010-01-28 13:46:16 +0900 | [diff] [blame] | 264 | u32 ret; |
| 265 | unsigned long flags; |
| 266 | |
Kuninori Morimoto | 8fc176d | 2010-01-28 13:46:16 +0900 | [diff] [blame] | 267 | spin_lock_irqsave(&master->lock, flags); |
| 268 | ret = __fsi_reg_read((u32)(master->base + reg)); |
| 269 | spin_unlock_irqrestore(&master->lock, flags); |
| 270 | |
| 271 | return ret; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 272 | } |
| 273 | |
Kuninori Morimoto | 43fa95c | 2010-12-03 17:38:03 +0900 | [diff] [blame] | 274 | #define fsi_master_mask_set(p, r, m, d) _fsi_master_mask_set(p, MST_##r, m, d) |
| 275 | #define fsi_core_mask_set(p, r, m, d) _fsi_master_mask_set(p, p->core->r, m, d) |
| 276 | static void _fsi_master_mask_set(struct fsi_master *master, |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 277 | u32 reg, u32 mask, u32 data) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 278 | { |
Kuninori Morimoto | 8fc176d | 2010-01-28 13:46:16 +0900 | [diff] [blame] | 279 | unsigned long flags; |
| 280 | |
Kuninori Morimoto | 8fc176d | 2010-01-28 13:46:16 +0900 | [diff] [blame] | 281 | spin_lock_irqsave(&master->lock, flags); |
Guennadi Liakhovetski | 0f69d97 | 2010-02-03 17:37:23 +0100 | [diff] [blame] | 282 | __fsi_reg_mask_set((u32)(master->base + reg), mask, data); |
Kuninori Morimoto | 8fc176d | 2010-01-28 13:46:16 +0900 | [diff] [blame] | 283 | spin_unlock_irqrestore(&master->lock, flags); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 284 | } |
| 285 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 286 | /* |
| 287 | * basic function |
| 288 | */ |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 289 | |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 290 | static struct fsi_master *fsi_get_master(struct fsi_priv *fsi) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 291 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 292 | return fsi->master; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 293 | } |
| 294 | |
Kuninori Morimoto | 6a9ebad | 2011-04-21 10:33:36 +0900 | [diff] [blame] | 295 | static int fsi_is_clk_master(struct fsi_priv *fsi) |
| 296 | { |
| 297 | return fsi->clk_master; |
| 298 | } |
| 299 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 300 | static int fsi_is_port_a(struct fsi_priv *fsi) |
| 301 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 302 | return fsi->master->base == fsi->base; |
| 303 | } |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 304 | |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 305 | static int fsi_is_spdif(struct fsi_priv *fsi) |
| 306 | { |
| 307 | return fsi->spdif; |
| 308 | } |
| 309 | |
Kuninori Morimoto | 142e817 | 2009-12-28 14:09:11 +0900 | [diff] [blame] | 310 | static struct snd_soc_dai *fsi_get_dai(struct snd_pcm_substream *substream) |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 311 | { |
| 312 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Kuninori Morimoto | 142e817 | 2009-12-28 14:09:11 +0900 | [diff] [blame] | 313 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 314 | return rtd->cpu_dai; |
Kuninori Morimoto | 142e817 | 2009-12-28 14:09:11 +0900 | [diff] [blame] | 315 | } |
| 316 | |
Kuninori Morimoto | 0d032c1 | 2011-01-20 11:45:51 +0900 | [diff] [blame] | 317 | static struct fsi_priv *fsi_get_priv_frm_dai(struct snd_soc_dai *dai) |
Kuninori Morimoto | 142e817 | 2009-12-28 14:09:11 +0900 | [diff] [blame] | 318 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 319 | struct fsi_master *master = snd_soc_dai_get_drvdata(dai); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 320 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 321 | if (dai->id == 0) |
| 322 | return &master->fsia; |
| 323 | else |
| 324 | return &master->fsib; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 325 | } |
| 326 | |
Kuninori Morimoto | 0d032c1 | 2011-01-20 11:45:51 +0900 | [diff] [blame] | 327 | static struct fsi_priv *fsi_get_priv(struct snd_pcm_substream *substream) |
| 328 | { |
| 329 | return fsi_get_priv_frm_dai(fsi_get_dai(substream)); |
| 330 | } |
| 331 | |
Kuninori Morimoto | d7c5762 | 2011-01-24 10:42:33 +0900 | [diff] [blame] | 332 | static set_rate_func fsi_get_info_set_rate(struct fsi_master *master) |
| 333 | { |
| 334 | if (!master->info) |
| 335 | return NULL; |
| 336 | |
| 337 | return master->info->set_rate; |
| 338 | } |
| 339 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 340 | static u32 fsi_get_info_flags(struct fsi_priv *fsi) |
| 341 | { |
| 342 | int is_porta = fsi_is_port_a(fsi); |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 343 | struct fsi_master *master = fsi_get_master(fsi); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 344 | |
Kuninori Morimoto | d7c5762 | 2011-01-24 10:42:33 +0900 | [diff] [blame] | 345 | if (!master->info) |
| 346 | return 0; |
| 347 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 348 | return is_porta ? master->info->porta_flags : |
| 349 | master->info->portb_flags; |
| 350 | } |
| 351 | |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 352 | static inline int fsi_stream_is_play(int stream) |
| 353 | { |
| 354 | return stream == SNDRV_PCM_STREAM_PLAYBACK; |
| 355 | } |
| 356 | |
Kuninori Morimoto | 0054578 | 2010-10-12 18:30:14 +0900 | [diff] [blame] | 357 | static inline int fsi_is_play(struct snd_pcm_substream *substream) |
| 358 | { |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 359 | return fsi_stream_is_play(substream->stream); |
| 360 | } |
| 361 | |
| 362 | static inline struct fsi_stream *fsi_get_stream(struct fsi_priv *fsi, |
| 363 | int is_play) |
| 364 | { |
| 365 | return is_play ? &fsi->playback : &fsi->capture; |
Kuninori Morimoto | 0054578 | 2010-10-12 18:30:14 +0900 | [diff] [blame] | 366 | } |
| 367 | |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 368 | static u32 fsi_get_port_shift(struct fsi_priv *fsi, int is_play) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 369 | { |
| 370 | int is_porta = fsi_is_port_a(fsi); |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 371 | u32 shift; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 372 | |
| 373 | if (is_porta) |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 374 | shift = is_play ? AO_SHIFT : AI_SHIFT; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 375 | else |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 376 | shift = is_play ? BO_SHIFT : BI_SHIFT; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 377 | |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 378 | return shift; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 379 | } |
| 380 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 381 | static int fsi_frame2sample(struct fsi_priv *fsi, int frames) |
| 382 | { |
| 383 | return frames * fsi->chan_num; |
| 384 | } |
| 385 | |
| 386 | static int fsi_sample2frame(struct fsi_priv *fsi, int samples) |
| 387 | { |
| 388 | return samples / fsi->chan_num; |
| 389 | } |
| 390 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 391 | static void fsi_stream_push(struct fsi_priv *fsi, |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 392 | int is_play, |
Kuninori Morimoto | 0ffe296 | 2011-05-23 20:45:57 +0900 | [diff] [blame] | 393 | struct snd_pcm_substream *substream) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 394 | { |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 395 | struct fsi_stream *io = fsi_get_stream(fsi, is_play); |
Kuninori Morimoto | 0ffe296 | 2011-05-23 20:45:57 +0900 | [diff] [blame] | 396 | struct snd_pcm_runtime *runtime = substream->runtime; |
Kuninori Morimoto | 2da6589 | 2011-05-23 20:46:13 +0900 | [diff] [blame^] | 397 | struct fsi_master *master = fsi_get_master(fsi); |
| 398 | unsigned long flags; |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 399 | |
Kuninori Morimoto | 2da6589 | 2011-05-23 20:46:13 +0900 | [diff] [blame^] | 400 | spin_lock_irqsave(&master->lock, flags); |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 401 | io->substream = substream; |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 402 | io->buff_sample_capa = fsi_frame2sample(fsi, runtime->buffer_size); |
| 403 | io->buff_sample_pos = 0; |
| 404 | io->period_samples = fsi_frame2sample(fsi, runtime->period_size); |
| 405 | io->period_pos = 0; |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 406 | io->oerr_num = -1; /* ignore 1st err */ |
| 407 | io->uerr_num = -1; /* ignore 1st err */ |
Kuninori Morimoto | 2da6589 | 2011-05-23 20:46:13 +0900 | [diff] [blame^] | 408 | spin_unlock_irqrestore(&master->lock, flags); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 409 | } |
| 410 | |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 411 | static void fsi_stream_pop(struct fsi_priv *fsi, int is_play) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 412 | { |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 413 | struct fsi_stream *io = fsi_get_stream(fsi, is_play); |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 414 | struct snd_soc_dai *dai = fsi_get_dai(io->substream); |
Kuninori Morimoto | 2da6589 | 2011-05-23 20:46:13 +0900 | [diff] [blame^] | 415 | struct fsi_master *master = fsi_get_master(fsi); |
| 416 | unsigned long flags; |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 417 | |
Kuninori Morimoto | 2da6589 | 2011-05-23 20:46:13 +0900 | [diff] [blame^] | 418 | spin_lock_irqsave(&master->lock, flags); |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 419 | |
| 420 | if (io->oerr_num > 0) |
| 421 | dev_err(dai->dev, "over_run = %d\n", io->oerr_num); |
| 422 | |
| 423 | if (io->uerr_num > 0) |
| 424 | dev_err(dai->dev, "under_run = %d\n", io->uerr_num); |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 425 | |
| 426 | io->substream = NULL; |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 427 | io->buff_sample_capa = 0; |
| 428 | io->buff_sample_pos = 0; |
| 429 | io->period_samples = 0; |
| 430 | io->period_pos = 0; |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 431 | io->oerr_num = 0; |
| 432 | io->uerr_num = 0; |
Kuninori Morimoto | 2da6589 | 2011-05-23 20:46:13 +0900 | [diff] [blame^] | 433 | spin_unlock_irqrestore(&master->lock, flags); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 434 | } |
| 435 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 436 | static int fsi_get_current_fifo_samples(struct fsi_priv *fsi, int is_play) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 437 | { |
| 438 | u32 status; |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 439 | int frames; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 440 | |
Kuninori Morimoto | e8c8b63 | 2010-12-03 17:37:55 +0900 | [diff] [blame] | 441 | status = is_play ? |
| 442 | fsi_reg_read(fsi, DOFF_ST) : |
| 443 | fsi_reg_read(fsi, DIFF_ST); |
| 444 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 445 | frames = 0x1ff & (status >> 8); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 446 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 447 | return fsi_frame2sample(fsi, frames); |
Kuninori Morimoto | cca1b23 | 2010-10-12 11:39:25 +0900 | [diff] [blame] | 448 | } |
| 449 | |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 450 | static void fsi_count_fifo_err(struct fsi_priv *fsi) |
| 451 | { |
| 452 | u32 ostatus = fsi_reg_read(fsi, DOFF_ST); |
| 453 | u32 istatus = fsi_reg_read(fsi, DIFF_ST); |
| 454 | |
| 455 | if (ostatus & ERR_OVER) |
| 456 | fsi->playback.oerr_num++; |
| 457 | |
| 458 | if (ostatus & ERR_UNDER) |
| 459 | fsi->playback.uerr_num++; |
| 460 | |
| 461 | if (istatus & ERR_OVER) |
| 462 | fsi->capture.oerr_num++; |
| 463 | |
| 464 | if (istatus & ERR_UNDER) |
| 465 | fsi->capture.uerr_num++; |
| 466 | |
| 467 | fsi_reg_write(fsi, DOFF_ST, 0); |
| 468 | fsi_reg_write(fsi, DIFF_ST, 0); |
| 469 | } |
| 470 | |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 471 | /* |
| 472 | * dma function |
| 473 | */ |
| 474 | |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 475 | static u8 *fsi_dma_get_area(struct fsi_priv *fsi, int stream) |
Kuninori Morimoto | c79eab3 | 2010-09-17 13:48:05 +0900 | [diff] [blame] | 476 | { |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 477 | int is_play = fsi_stream_is_play(stream); |
| 478 | struct fsi_stream *io = fsi_get_stream(fsi, is_play); |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 479 | struct snd_pcm_runtime *runtime = io->substream->runtime; |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 480 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 481 | return runtime->dma_area + |
| 482 | samples_to_bytes(runtime, io->buff_sample_pos); |
Kuninori Morimoto | c79eab3 | 2010-09-17 13:48:05 +0900 | [diff] [blame] | 483 | } |
| 484 | |
Kuninori Morimoto | 5bfb9ad | 2010-09-17 13:48:45 +0900 | [diff] [blame] | 485 | static void fsi_dma_soft_push16(struct fsi_priv *fsi, int num) |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 486 | { |
| 487 | u16 *start; |
| 488 | int i; |
| 489 | |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 490 | start = (u16 *)fsi_dma_get_area(fsi, SNDRV_PCM_STREAM_PLAYBACK); |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 491 | |
Kuninori Morimoto | 5bfb9ad | 2010-09-17 13:48:45 +0900 | [diff] [blame] | 492 | for (i = 0; i < num; i++) |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 493 | fsi_reg_write(fsi, DODT, ((u32)*(start + i) << 8)); |
| 494 | } |
| 495 | |
Kuninori Morimoto | 5bfb9ad | 2010-09-17 13:48:45 +0900 | [diff] [blame] | 496 | static void fsi_dma_soft_pop16(struct fsi_priv *fsi, int num) |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 497 | { |
| 498 | u16 *start; |
| 499 | int i; |
| 500 | |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 501 | start = (u16 *)fsi_dma_get_area(fsi, SNDRV_PCM_STREAM_CAPTURE); |
| 502 | |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 503 | |
Kuninori Morimoto | 5bfb9ad | 2010-09-17 13:48:45 +0900 | [diff] [blame] | 504 | for (i = 0; i < num; i++) |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 505 | *(start + i) = (u16)(fsi_reg_read(fsi, DIDT) >> 8); |
| 506 | } |
| 507 | |
Kuninori Morimoto | 5bfb9ad | 2010-09-17 13:48:45 +0900 | [diff] [blame] | 508 | static void fsi_dma_soft_push32(struct fsi_priv *fsi, int num) |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 509 | { |
| 510 | u32 *start; |
| 511 | int i; |
| 512 | |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 513 | start = (u32 *)fsi_dma_get_area(fsi, SNDRV_PCM_STREAM_PLAYBACK); |
| 514 | |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 515 | |
Kuninori Morimoto | 5bfb9ad | 2010-09-17 13:48:45 +0900 | [diff] [blame] | 516 | for (i = 0; i < num; i++) |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 517 | fsi_reg_write(fsi, DODT, *(start + i)); |
| 518 | } |
| 519 | |
Kuninori Morimoto | 5bfb9ad | 2010-09-17 13:48:45 +0900 | [diff] [blame] | 520 | static void fsi_dma_soft_pop32(struct fsi_priv *fsi, int num) |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 521 | { |
| 522 | u32 *start; |
| 523 | int i; |
| 524 | |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 525 | start = (u32 *)fsi_dma_get_area(fsi, SNDRV_PCM_STREAM_CAPTURE); |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 526 | |
Kuninori Morimoto | 5bfb9ad | 2010-09-17 13:48:45 +0900 | [diff] [blame] | 527 | for (i = 0; i < num; i++) |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 528 | *(start + i) = fsi_reg_read(fsi, DIDT); |
| 529 | } |
| 530 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 531 | /* |
| 532 | * irq function |
| 533 | */ |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 534 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 535 | static void fsi_irq_enable(struct fsi_priv *fsi, int is_play) |
| 536 | { |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 537 | u32 data = AB_IO(1, fsi_get_port_shift(fsi, is_play)); |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 538 | struct fsi_master *master = fsi_get_master(fsi); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 539 | |
Kuninori Morimoto | 43fa95c | 2010-12-03 17:38:03 +0900 | [diff] [blame] | 540 | fsi_core_mask_set(master, imsk, data, data); |
| 541 | fsi_core_mask_set(master, iemsk, data, data); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | static void fsi_irq_disable(struct fsi_priv *fsi, int is_play) |
| 545 | { |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 546 | u32 data = AB_IO(1, fsi_get_port_shift(fsi, is_play)); |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 547 | struct fsi_master *master = fsi_get_master(fsi); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 548 | |
Kuninori Morimoto | 43fa95c | 2010-12-03 17:38:03 +0900 | [diff] [blame] | 549 | fsi_core_mask_set(master, imsk, data, 0); |
| 550 | fsi_core_mask_set(master, iemsk, data, 0); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 551 | } |
| 552 | |
Kuninori Morimoto | 10ea76c | 2010-03-23 11:47:54 +0900 | [diff] [blame] | 553 | static u32 fsi_irq_get_status(struct fsi_master *master) |
| 554 | { |
Kuninori Morimoto | 43fa95c | 2010-12-03 17:38:03 +0900 | [diff] [blame] | 555 | return fsi_core_read(master, int_st); |
Kuninori Morimoto | 10ea76c | 2010-03-23 11:47:54 +0900 | [diff] [blame] | 556 | } |
| 557 | |
Kuninori Morimoto | 10ea76c | 2010-03-23 11:47:54 +0900 | [diff] [blame] | 558 | static void fsi_irq_clear_status(struct fsi_priv *fsi) |
| 559 | { |
| 560 | u32 data = 0; |
| 561 | struct fsi_master *master = fsi_get_master(fsi); |
| 562 | |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 563 | data |= AB_IO(1, fsi_get_port_shift(fsi, 0)); |
| 564 | data |= AB_IO(1, fsi_get_port_shift(fsi, 1)); |
Kuninori Morimoto | 10ea76c | 2010-03-23 11:47:54 +0900 | [diff] [blame] | 565 | |
| 566 | /* clear interrupt factor */ |
Kuninori Morimoto | 43fa95c | 2010-12-03 17:38:03 +0900 | [diff] [blame] | 567 | fsi_core_mask_set(master, int_st, data, 0); |
Kuninori Morimoto | 10ea76c | 2010-03-23 11:47:54 +0900 | [diff] [blame] | 568 | } |
| 569 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 570 | /* |
| 571 | * SPDIF master clock function |
| 572 | * |
| 573 | * These functions are used later FSI2 |
| 574 | */ |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 575 | static void fsi_spdif_clk_ctrl(struct fsi_priv *fsi, int enable) |
| 576 | { |
| 577 | struct fsi_master *master = fsi_get_master(fsi); |
Kuninori Morimoto | 2b0e730 | 2010-12-03 17:37:44 +0900 | [diff] [blame] | 578 | u32 mask, val; |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 579 | |
| 580 | if (master->core->ver < 2) { |
| 581 | pr_err("fsi: register access err (%s)\n", __func__); |
| 582 | return; |
| 583 | } |
| 584 | |
Kuninori Morimoto | 2b0e730 | 2010-12-03 17:37:44 +0900 | [diff] [blame] | 585 | mask = BP | SE; |
| 586 | val = enable ? mask : 0; |
| 587 | |
| 588 | fsi_is_port_a(fsi) ? |
Kuninori Morimoto | 43fa95c | 2010-12-03 17:38:03 +0900 | [diff] [blame] | 589 | fsi_core_mask_set(master, a_mclk, mask, val) : |
| 590 | fsi_core_mask_set(master, b_mclk, mask, val); |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 591 | } |
| 592 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 593 | /* |
Kuninori Morimoto | 1f5e2a3 | 2011-04-21 10:33:52 +0900 | [diff] [blame] | 594 | * clock function |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 595 | */ |
Kuninori Morimoto | 4f56cde | 2011-05-23 20:46:18 +0900 | [diff] [blame] | 596 | static int fsi_set_master_clk(struct device *dev, struct fsi_priv *fsi, |
| 597 | long rate, int enable) |
| 598 | { |
| 599 | struct fsi_master *master = fsi_get_master(fsi); |
| 600 | set_rate_func set_rate = fsi_get_info_set_rate(master); |
| 601 | int fsi_ver = master->core->ver; |
| 602 | int ret; |
| 603 | |
| 604 | ret = set_rate(dev, fsi_is_port_a(fsi), rate, enable); |
| 605 | if (ret < 0) /* error */ |
| 606 | return ret; |
| 607 | |
| 608 | if (!enable) |
| 609 | return 0; |
| 610 | |
| 611 | if (ret > 0) { |
| 612 | u32 data = 0; |
| 613 | |
| 614 | switch (ret & SH_FSI_ACKMD_MASK) { |
| 615 | default: |
| 616 | /* FALL THROUGH */ |
| 617 | case SH_FSI_ACKMD_512: |
| 618 | data |= (0x0 << 12); |
| 619 | break; |
| 620 | case SH_FSI_ACKMD_256: |
| 621 | data |= (0x1 << 12); |
| 622 | break; |
| 623 | case SH_FSI_ACKMD_128: |
| 624 | data |= (0x2 << 12); |
| 625 | break; |
| 626 | case SH_FSI_ACKMD_64: |
| 627 | data |= (0x3 << 12); |
| 628 | break; |
| 629 | case SH_FSI_ACKMD_32: |
| 630 | if (fsi_ver < 2) |
| 631 | dev_err(dev, "unsupported ACKMD\n"); |
| 632 | else |
| 633 | data |= (0x4 << 12); |
| 634 | break; |
| 635 | } |
| 636 | |
| 637 | switch (ret & SH_FSI_BPFMD_MASK) { |
| 638 | default: |
| 639 | /* FALL THROUGH */ |
| 640 | case SH_FSI_BPFMD_32: |
| 641 | data |= (0x0 << 8); |
| 642 | break; |
| 643 | case SH_FSI_BPFMD_64: |
| 644 | data |= (0x1 << 8); |
| 645 | break; |
| 646 | case SH_FSI_BPFMD_128: |
| 647 | data |= (0x2 << 8); |
| 648 | break; |
| 649 | case SH_FSI_BPFMD_256: |
| 650 | data |= (0x3 << 8); |
| 651 | break; |
| 652 | case SH_FSI_BPFMD_512: |
| 653 | data |= (0x4 << 8); |
| 654 | break; |
| 655 | case SH_FSI_BPFMD_16: |
| 656 | if (fsi_ver < 2) |
| 657 | dev_err(dev, "unsupported ACKMD\n"); |
| 658 | else |
| 659 | data |= (0x7 << 8); |
| 660 | break; |
| 661 | } |
| 662 | |
| 663 | fsi_reg_mask_set(fsi, CKG1, (ACKMD_MASK | BPFMD_MASK) , data); |
| 664 | udelay(10); |
| 665 | ret = 0; |
| 666 | } |
| 667 | |
| 668 | return ret; |
| 669 | |
| 670 | } |
| 671 | |
Kuninori Morimoto | 1f5e2a3 | 2011-04-21 10:33:52 +0900 | [diff] [blame] | 672 | #define fsi_module_init(m, d) __fsi_module_clk_ctrl(m, d, 1) |
| 673 | #define fsi_module_kill(m, d) __fsi_module_clk_ctrl(m, d, 0) |
| 674 | static void __fsi_module_clk_ctrl(struct fsi_master *master, |
| 675 | struct device *dev, |
| 676 | int enable) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 677 | { |
Kuninori Morimoto | 1f5e2a3 | 2011-04-21 10:33:52 +0900 | [diff] [blame] | 678 | pm_runtime_get_sync(dev); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 679 | |
Kuninori Morimoto | 1f5e2a3 | 2011-04-21 10:33:52 +0900 | [diff] [blame] | 680 | if (enable) { |
| 681 | /* enable only SR */ |
| 682 | fsi_master_mask_set(master, SOFT_RST, FSISR, FSISR); |
| 683 | fsi_master_mask_set(master, SOFT_RST, PASR | PBSR, 0); |
| 684 | } else { |
| 685 | /* clear all registers */ |
| 686 | fsi_master_mask_set(master, SOFT_RST, FSISR, 0); |
| 687 | } |
| 688 | |
| 689 | pm_runtime_put_sync(dev); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 690 | } |
| 691 | |
Kuninori Morimoto | 1ddddd3 | 2011-05-23 20:46:23 +0900 | [diff] [blame] | 692 | #define fsi_port_start(f, i) __fsi_port_clk_ctrl(f, i, 1) |
| 693 | #define fsi_port_stop(f, i) __fsi_port_clk_ctrl(f, i, 0) |
| 694 | static void __fsi_port_clk_ctrl(struct fsi_priv *fsi, int is_play, int enable) |
Kuninori Morimoto | 1f5e2a3 | 2011-04-21 10:33:52 +0900 | [diff] [blame] | 695 | { |
| 696 | struct fsi_master *master = fsi_get_master(fsi); |
| 697 | u32 soft = fsi_is_port_a(fsi) ? PASR : PBSR; |
| 698 | u32 clk = fsi_is_port_a(fsi) ? CRA : CRB; |
| 699 | int is_master = fsi_is_clk_master(fsi); |
| 700 | |
Kuninori Morimoto | 1ddddd3 | 2011-05-23 20:46:23 +0900 | [diff] [blame] | 701 | if (enable) |
| 702 | fsi_irq_enable(fsi, is_play); |
| 703 | else |
| 704 | fsi_irq_disable(fsi, is_play); |
| 705 | |
Kuninori Morimoto | 1f5e2a3 | 2011-04-21 10:33:52 +0900 | [diff] [blame] | 706 | fsi_master_mask_set(master, SOFT_RST, soft, (enable) ? soft : 0); |
| 707 | if (is_master) |
| 708 | fsi_master_mask_set(master, CLK_RST, clk, (enable) ? clk : 0); |
| 709 | } |
| 710 | |
| 711 | /* |
| 712 | * ctrl function |
| 713 | */ |
Kuninori Morimoto | 4a942b4 | 2010-03-25 19:15:51 +0900 | [diff] [blame] | 714 | static void fsi_fifo_init(struct fsi_priv *fsi, |
| 715 | int is_play, |
| 716 | struct snd_soc_dai *dai) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 717 | { |
Kuninori Morimoto | 4a942b4 | 2010-03-25 19:15:51 +0900 | [diff] [blame] | 718 | struct fsi_master *master = fsi_get_master(fsi); |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 719 | struct fsi_stream *io = fsi_get_stream(fsi, is_play); |
Kuninori Morimoto | e8c8b63 | 2010-12-03 17:37:55 +0900 | [diff] [blame] | 720 | u32 shift, i; |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 721 | int frame_capa; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 722 | |
Kuninori Morimoto | 4a942b4 | 2010-03-25 19:15:51 +0900 | [diff] [blame] | 723 | /* get on-chip RAM capacity */ |
| 724 | shift = fsi_master_read(master, FIFO_SZ); |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 725 | shift >>= fsi_get_port_shift(fsi, is_play); |
| 726 | shift &= FIFO_SZ_MASK; |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 727 | frame_capa = 256 << shift; |
| 728 | dev_dbg(dai->dev, "fifo = %d words\n", frame_capa); |
Kuninori Morimoto | 4a942b4 | 2010-03-25 19:15:51 +0900 | [diff] [blame] | 729 | |
| 730 | /* |
| 731 | * The maximum number of sample data varies depending |
| 732 | * on the number of channels selected for the format. |
| 733 | * |
| 734 | * FIFOs are used in 4-channel units in 3-channel mode |
| 735 | * and in 8-channel units in 5- to 7-channel mode |
| 736 | * meaning that more FIFOs than the required size of DPRAM |
| 737 | * are used. |
| 738 | * |
| 739 | * ex) if 256 words of DP-RAM is connected |
| 740 | * 1 channel: 256 (256 x 1 = 256) |
| 741 | * 2 channels: 128 (128 x 2 = 256) |
| 742 | * 3 channels: 64 ( 64 x 3 = 192) |
| 743 | * 4 channels: 64 ( 64 x 4 = 256) |
| 744 | * 5 channels: 32 ( 32 x 5 = 160) |
| 745 | * 6 channels: 32 ( 32 x 6 = 192) |
| 746 | * 7 channels: 32 ( 32 x 7 = 224) |
| 747 | * 8 channels: 32 ( 32 x 8 = 256) |
| 748 | */ |
Kuninori Morimoto | 160afa7 | 2011-01-24 10:42:08 +0900 | [diff] [blame] | 749 | for (i = 1; i < fsi->chan_num; i <<= 1) |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 750 | frame_capa >>= 1; |
Kuninori Morimoto | 5bfb9ad | 2010-09-17 13:48:45 +0900 | [diff] [blame] | 751 | dev_dbg(dai->dev, "%d channel %d store\n", |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 752 | fsi->chan_num, frame_capa); |
| 753 | |
| 754 | io->fifo_sample_capa = fsi_frame2sample(fsi, frame_capa); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 755 | |
Kuninori Morimoto | e8c8b63 | 2010-12-03 17:37:55 +0900 | [diff] [blame] | 756 | /* |
| 757 | * set interrupt generation factor |
| 758 | * clear FIFO |
| 759 | */ |
| 760 | if (is_play) { |
| 761 | fsi_reg_write(fsi, DOFF_CTL, IRQ_HALF); |
| 762 | fsi_reg_mask_set(fsi, DOFF_CTL, FIFO_CLR, FIFO_CLR); |
| 763 | } else { |
| 764 | fsi_reg_write(fsi, DIFF_CTL, IRQ_HALF); |
| 765 | fsi_reg_mask_set(fsi, DIFF_CTL, FIFO_CLR, FIFO_CLR); |
| 766 | } |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 767 | } |
| 768 | |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 769 | static int fsi_fifo_data_ctrl(struct fsi_priv *fsi, int stream) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 770 | { |
| 771 | struct snd_pcm_runtime *runtime; |
| 772 | struct snd_pcm_substream *substream = NULL; |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 773 | int is_play = fsi_stream_is_play(stream); |
| 774 | struct fsi_stream *io = fsi_get_stream(fsi, is_play); |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 775 | int sample_residues; |
| 776 | int sample_width; |
| 777 | int samples; |
| 778 | int samples_max; |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 779 | int over_period; |
Kuninori Morimoto | d8b3353 | 2010-09-17 13:49:05 +0900 | [diff] [blame] | 780 | void (*fn)(struct fsi_priv *fsi, int size); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 781 | |
| 782 | if (!fsi || |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 783 | !io->substream || |
| 784 | !io->substream->runtime) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 785 | return -EINVAL; |
| 786 | |
Kuninori Morimoto | 1c418d1 | 2009-12-28 14:09:05 +0900 | [diff] [blame] | 787 | over_period = 0; |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 788 | substream = io->substream; |
Kuninori Morimoto | 1c418d1 | 2009-12-28 14:09:05 +0900 | [diff] [blame] | 789 | runtime = substream->runtime; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 790 | |
| 791 | /* FSI FIFO has limit. |
| 792 | * So, this driver can not send periods data at a time |
| 793 | */ |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 794 | if (io->buff_sample_pos >= |
| 795 | io->period_samples * (io->period_pos + 1)) { |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 796 | |
Kuninori Morimoto | 1c418d1 | 2009-12-28 14:09:05 +0900 | [diff] [blame] | 797 | over_period = 1; |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 798 | io->period_pos = (io->period_pos + 1) % runtime->periods; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 799 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 800 | if (0 == io->period_pos) |
| 801 | io->buff_sample_pos = 0; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 802 | } |
| 803 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 804 | /* get 1 sample data width */ |
| 805 | sample_width = samples_to_bytes(runtime, 1); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 806 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 807 | /* get number of residue samples */ |
| 808 | sample_residues = io->buff_sample_capa - io->buff_sample_pos; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 809 | |
Kuninori Morimoto | d8b3353 | 2010-09-17 13:49:05 +0900 | [diff] [blame] | 810 | if (is_play) { |
| 811 | /* |
| 812 | * for play-back |
| 813 | * |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 814 | * samples_max : number of FSI fifo free samples space |
| 815 | * samples : number of ALSA residue samples |
Kuninori Morimoto | d8b3353 | 2010-09-17 13:49:05 +0900 | [diff] [blame] | 816 | */ |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 817 | samples_max = io->fifo_sample_capa; |
| 818 | samples_max -= fsi_get_current_fifo_samples(fsi, is_play); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 819 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 820 | samples = sample_residues; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 821 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 822 | switch (sample_width) { |
Kuninori Morimoto | d8b3353 | 2010-09-17 13:49:05 +0900 | [diff] [blame] | 823 | case 2: |
| 824 | fn = fsi_dma_soft_push16; |
| 825 | break; |
| 826 | case 4: |
| 827 | fn = fsi_dma_soft_push32; |
| 828 | break; |
| 829 | default: |
| 830 | return -EINVAL; |
| 831 | } |
| 832 | } else { |
| 833 | /* |
| 834 | * for capture |
| 835 | * |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 836 | * samples_max : number of ALSA free samples space |
| 837 | * samples : number of samples in FSI fifo |
Kuninori Morimoto | d8b3353 | 2010-09-17 13:49:05 +0900 | [diff] [blame] | 838 | */ |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 839 | samples_max = sample_residues; |
| 840 | samples = fsi_get_current_fifo_samples(fsi, is_play); |
Kuninori Morimoto | d8b3353 | 2010-09-17 13:49:05 +0900 | [diff] [blame] | 841 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 842 | switch (sample_width) { |
Kuninori Morimoto | d8b3353 | 2010-09-17 13:49:05 +0900 | [diff] [blame] | 843 | case 2: |
| 844 | fn = fsi_dma_soft_pop16; |
| 845 | break; |
| 846 | case 4: |
| 847 | fn = fsi_dma_soft_pop32; |
| 848 | break; |
| 849 | default: |
| 850 | return -EINVAL; |
| 851 | } |
Kuninori Morimoto | 9ddc9aa | 2009-10-30 12:02:39 +0900 | [diff] [blame] | 852 | } |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 853 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 854 | samples = min(samples, samples_max); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 855 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 856 | fn(fsi, samples); |
Kuninori Morimoto | d8b3353 | 2010-09-17 13:49:05 +0900 | [diff] [blame] | 857 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 858 | /* update buff_sample_pos */ |
| 859 | io->buff_sample_pos += samples; |
Kuninori Morimoto | d8b3353 | 2010-09-17 13:49:05 +0900 | [diff] [blame] | 860 | |
Kuninori Morimoto | 1c418d1 | 2009-12-28 14:09:05 +0900 | [diff] [blame] | 861 | if (over_period) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 862 | snd_pcm_period_elapsed(substream); |
| 863 | |
Kuninori Morimoto | 47fc9a0 | 2010-02-22 16:41:57 +0900 | [diff] [blame] | 864 | return 0; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 865 | } |
| 866 | |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 867 | static int fsi_data_pop(struct fsi_priv *fsi) |
Kuninori Morimoto | 07102f3 | 2009-10-30 12:02:44 +0900 | [diff] [blame] | 868 | { |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 869 | return fsi_fifo_data_ctrl(fsi, SNDRV_PCM_STREAM_CAPTURE); |
Kuninori Morimoto | d8b3353 | 2010-09-17 13:49:05 +0900 | [diff] [blame] | 870 | } |
Kuninori Morimoto | 07102f3 | 2009-10-30 12:02:44 +0900 | [diff] [blame] | 871 | |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 872 | static int fsi_data_push(struct fsi_priv *fsi) |
Kuninori Morimoto | d8b3353 | 2010-09-17 13:49:05 +0900 | [diff] [blame] | 873 | { |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 874 | return fsi_fifo_data_ctrl(fsi, SNDRV_PCM_STREAM_PLAYBACK); |
Kuninori Morimoto | 07102f3 | 2009-10-30 12:02:44 +0900 | [diff] [blame] | 875 | } |
| 876 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 877 | static irqreturn_t fsi_interrupt(int irq, void *data) |
| 878 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 879 | struct fsi_master *master = data; |
Kuninori Morimoto | 10ea76c | 2010-03-23 11:47:54 +0900 | [diff] [blame] | 880 | u32 int_st = fsi_irq_get_status(master); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 881 | |
| 882 | /* clear irq status */ |
Kuninori Morimoto | feb58cf | 2010-03-24 15:27:24 +0900 | [diff] [blame] | 883 | fsi_master_mask_set(master, SOFT_RST, IR, 0); |
| 884 | fsi_master_mask_set(master, SOFT_RST, IR, IR); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 885 | |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 886 | if (int_st & AB_IO(1, AO_SHIFT)) |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 887 | fsi_data_push(&master->fsia); |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 888 | if (int_st & AB_IO(1, BO_SHIFT)) |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 889 | fsi_data_push(&master->fsib); |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 890 | if (int_st & AB_IO(1, AI_SHIFT)) |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 891 | fsi_data_pop(&master->fsia); |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 892 | if (int_st & AB_IO(1, BI_SHIFT)) |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 893 | fsi_data_pop(&master->fsib); |
| 894 | |
| 895 | fsi_count_fifo_err(&master->fsia); |
| 896 | fsi_count_fifo_err(&master->fsib); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 897 | |
Kuninori Morimoto | 48d78e5 | 2010-12-03 17:37:31 +0900 | [diff] [blame] | 898 | fsi_irq_clear_status(&master->fsia); |
| 899 | fsi_irq_clear_status(&master->fsib); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 900 | |
| 901 | return IRQ_HANDLED; |
| 902 | } |
| 903 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 904 | /* |
| 905 | * dai ops |
| 906 | */ |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 907 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 908 | static int fsi_dai_startup(struct snd_pcm_substream *substream, |
| 909 | struct snd_soc_dai *dai) |
| 910 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 911 | struct fsi_priv *fsi = fsi_get_priv(substream); |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 912 | u32 flags = fsi_get_info_flags(fsi); |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 913 | u32 data = 0; |
Kuninori Morimoto | 0054578 | 2010-10-12 18:30:14 +0900 | [diff] [blame] | 914 | int is_play = fsi_is_play(substream); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 915 | |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 916 | pm_runtime_get_sync(dai->dev); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 917 | |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 918 | /* clock setting */ |
| 919 | if (fsi_is_clk_master(fsi)) |
| 920 | data = DIMD | DOMD; |
| 921 | |
| 922 | fsi_reg_mask_set(fsi, CKG1, (DIMD | DOMD), data); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 923 | |
| 924 | /* clock inversion (CKG2) */ |
| 925 | data = 0; |
Kuninori Morimoto | b427b44 | 2010-07-13 12:01:15 +0900 | [diff] [blame] | 926 | if (SH_FSI_LRM_INV & flags) |
| 927 | data |= 1 << 12; |
| 928 | if (SH_FSI_BRM_INV & flags) |
| 929 | data |= 1 << 8; |
| 930 | if (SH_FSI_LRS_INV & flags) |
| 931 | data |= 1 << 4; |
| 932 | if (SH_FSI_BRS_INV & flags) |
| 933 | data |= 1 << 0; |
| 934 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 935 | fsi_reg_write(fsi, CKG2, data); |
| 936 | |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 937 | /* set format */ |
| 938 | fsi_reg_write(fsi, DO_FMT, fsi->do_fmt); |
| 939 | fsi_reg_write(fsi, DI_FMT, fsi->di_fmt); |
| 940 | |
| 941 | /* spdif ? */ |
| 942 | if (fsi_is_spdif(fsi)) { |
| 943 | fsi_spdif_clk_ctrl(fsi, 1); |
| 944 | fsi_reg_mask_set(fsi, OUT_SEL, DMMD, DMMD); |
| 945 | } |
| 946 | |
Kuninori Morimoto | 10ea76c | 2010-03-23 11:47:54 +0900 | [diff] [blame] | 947 | /* irq clear */ |
| 948 | fsi_irq_disable(fsi, is_play); |
| 949 | fsi_irq_clear_status(fsi); |
| 950 | |
| 951 | /* fifo init */ |
Kuninori Morimoto | 4a942b4 | 2010-03-25 19:15:51 +0900 | [diff] [blame] | 952 | fsi_fifo_init(fsi, is_play, dai); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 953 | |
Kuninori Morimoto | a68a3b4 | 2010-10-12 11:39:50 +0900 | [diff] [blame] | 954 | return 0; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | static void fsi_dai_shutdown(struct snd_pcm_substream *substream, |
| 958 | struct snd_soc_dai *dai) |
| 959 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 960 | struct fsi_priv *fsi = fsi_get_priv(substream); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 961 | |
Kuninori Morimoto | 1f5e2a3 | 2011-04-21 10:33:52 +0900 | [diff] [blame] | 962 | if (fsi_is_clk_master(fsi)) |
Kuninori Morimoto | 4f56cde | 2011-05-23 20:46:18 +0900 | [diff] [blame] | 963 | fsi_set_master_clk(dai->dev, fsi, fsi->rate, 0); |
Kuninori Morimoto | 6a9ebad | 2011-04-21 10:33:36 +0900 | [diff] [blame] | 964 | |
Kuninori Morimoto | d4bc99b | 2010-11-24 02:44:06 +0000 | [diff] [blame] | 965 | fsi->rate = 0; |
| 966 | |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 967 | pm_runtime_put_sync(dai->dev); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | static int fsi_dai_trigger(struct snd_pcm_substream *substream, int cmd, |
| 971 | struct snd_soc_dai *dai) |
| 972 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 973 | struct fsi_priv *fsi = fsi_get_priv(substream); |
Kuninori Morimoto | 0054578 | 2010-10-12 18:30:14 +0900 | [diff] [blame] | 974 | int is_play = fsi_is_play(substream); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 975 | int ret = 0; |
| 976 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 977 | switch (cmd) { |
| 978 | case SNDRV_PCM_TRIGGER_START: |
Kuninori Morimoto | 0ffe296 | 2011-05-23 20:45:57 +0900 | [diff] [blame] | 979 | fsi_stream_push(fsi, is_play, substream); |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 980 | ret = is_play ? fsi_data_push(fsi) : fsi_data_pop(fsi); |
Kuninori Morimoto | 1ddddd3 | 2011-05-23 20:46:23 +0900 | [diff] [blame] | 981 | fsi_port_start(fsi, is_play); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 982 | break; |
| 983 | case SNDRV_PCM_TRIGGER_STOP: |
Kuninori Morimoto | 1ddddd3 | 2011-05-23 20:46:23 +0900 | [diff] [blame] | 984 | fsi_port_stop(fsi, is_play); |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 985 | fsi_stream_pop(fsi, is_play); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 986 | break; |
| 987 | } |
| 988 | |
| 989 | return ret; |
| 990 | } |
| 991 | |
Kuninori Morimoto | f17c13c | 2011-01-24 10:43:19 +0900 | [diff] [blame] | 992 | static int fsi_set_fmt_dai(struct fsi_priv *fsi, unsigned int fmt) |
| 993 | { |
| 994 | u32 data = 0; |
| 995 | |
| 996 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 997 | case SND_SOC_DAIFMT_I2S: |
| 998 | data = CR_I2S; |
| 999 | fsi->chan_num = 2; |
| 1000 | break; |
| 1001 | case SND_SOC_DAIFMT_LEFT_J: |
| 1002 | data = CR_PCM; |
| 1003 | fsi->chan_num = 2; |
| 1004 | break; |
| 1005 | default: |
| 1006 | return -EINVAL; |
| 1007 | } |
| 1008 | |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 1009 | fsi->do_fmt = data; |
| 1010 | fsi->di_fmt = data; |
Kuninori Morimoto | f17c13c | 2011-01-24 10:43:19 +0900 | [diff] [blame] | 1011 | |
| 1012 | return 0; |
| 1013 | } |
| 1014 | |
| 1015 | static int fsi_set_fmt_spdif(struct fsi_priv *fsi) |
| 1016 | { |
| 1017 | struct fsi_master *master = fsi_get_master(fsi); |
| 1018 | u32 data = 0; |
| 1019 | |
| 1020 | if (master->core->ver < 2) |
| 1021 | return -EINVAL; |
| 1022 | |
| 1023 | data = CR_BWS_16 | CR_DTMD_SPDIF_PCM | CR_PCM; |
| 1024 | fsi->chan_num = 2; |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 1025 | fsi->spdif = 1; |
Kuninori Morimoto | f17c13c | 2011-01-24 10:43:19 +0900 | [diff] [blame] | 1026 | |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 1027 | fsi->do_fmt = data; |
| 1028 | fsi->di_fmt = data; |
Kuninori Morimoto | f17c13c | 2011-01-24 10:43:19 +0900 | [diff] [blame] | 1029 | |
| 1030 | return 0; |
| 1031 | } |
| 1032 | |
Kuninori Morimoto | 4d805f7 | 2011-01-20 11:46:02 +0900 | [diff] [blame] | 1033 | static int fsi_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) |
| 1034 | { |
| 1035 | struct fsi_priv *fsi = fsi_get_priv_frm_dai(dai); |
Kuninori Morimoto | 6a9ebad | 2011-04-21 10:33:36 +0900 | [diff] [blame] | 1036 | struct fsi_master *master = fsi_get_master(fsi); |
| 1037 | set_rate_func set_rate = fsi_get_info_set_rate(master); |
Kuninori Morimoto | f17c13c | 2011-01-24 10:43:19 +0900 | [diff] [blame] | 1038 | u32 flags = fsi_get_info_flags(fsi); |
Kuninori Morimoto | 4d805f7 | 2011-01-20 11:46:02 +0900 | [diff] [blame] | 1039 | int ret; |
| 1040 | |
Kuninori Morimoto | 4d805f7 | 2011-01-20 11:46:02 +0900 | [diff] [blame] | 1041 | /* set master/slave audio interface */ |
| 1042 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 1043 | case SND_SOC_DAIFMT_CBM_CFM: |
Kuninori Morimoto | 6a9ebad | 2011-04-21 10:33:36 +0900 | [diff] [blame] | 1044 | fsi->clk_master = 1; |
Kuninori Morimoto | 4d805f7 | 2011-01-20 11:46:02 +0900 | [diff] [blame] | 1045 | break; |
| 1046 | case SND_SOC_DAIFMT_CBS_CFS: |
| 1047 | break; |
| 1048 | default: |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 1049 | return -EINVAL; |
Kuninori Morimoto | 4d805f7 | 2011-01-20 11:46:02 +0900 | [diff] [blame] | 1050 | } |
Kuninori Morimoto | 6a9ebad | 2011-04-21 10:33:36 +0900 | [diff] [blame] | 1051 | |
| 1052 | if (fsi_is_clk_master(fsi) && !set_rate) { |
| 1053 | dev_err(dai->dev, "platform doesn't have set_rate\n"); |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 1054 | return -EINVAL; |
Kuninori Morimoto | 6a9ebad | 2011-04-21 10:33:36 +0900 | [diff] [blame] | 1055 | } |
| 1056 | |
Kuninori Morimoto | f17c13c | 2011-01-24 10:43:19 +0900 | [diff] [blame] | 1057 | /* set format */ |
| 1058 | switch (flags & SH_FSI_FMT_MASK) { |
| 1059 | case SH_FSI_FMT_DAI: |
| 1060 | ret = fsi_set_fmt_dai(fsi, fmt & SND_SOC_DAIFMT_FORMAT_MASK); |
| 1061 | break; |
| 1062 | case SH_FSI_FMT_SPDIF: |
| 1063 | ret = fsi_set_fmt_spdif(fsi); |
| 1064 | break; |
| 1065 | default: |
| 1066 | ret = -EINVAL; |
| 1067 | } |
Kuninori Morimoto | 4d805f7 | 2011-01-20 11:46:02 +0900 | [diff] [blame] | 1068 | |
Kuninori Morimoto | 4d805f7 | 2011-01-20 11:46:02 +0900 | [diff] [blame] | 1069 | return ret; |
| 1070 | } |
| 1071 | |
Kuninori Morimoto | ccad7b4 | 2010-07-13 12:13:14 +0900 | [diff] [blame] | 1072 | static int fsi_dai_hw_params(struct snd_pcm_substream *substream, |
| 1073 | struct snd_pcm_hw_params *params, |
| 1074 | struct snd_soc_dai *dai) |
| 1075 | { |
| 1076 | struct fsi_priv *fsi = fsi_get_priv(substream); |
Kuninori Morimoto | d4bc99b | 2010-11-24 02:44:06 +0000 | [diff] [blame] | 1077 | long rate = params_rate(params); |
Kuninori Morimoto | ccad7b4 | 2010-07-13 12:13:14 +0900 | [diff] [blame] | 1078 | int ret; |
| 1079 | |
Kuninori Morimoto | 6a9ebad | 2011-04-21 10:33:36 +0900 | [diff] [blame] | 1080 | if (!fsi_is_clk_master(fsi)) |
Kuninori Morimoto | ccad7b4 | 2010-07-13 12:13:14 +0900 | [diff] [blame] | 1081 | return 0; |
| 1082 | |
Kuninori Morimoto | 4f56cde | 2011-05-23 20:46:18 +0900 | [diff] [blame] | 1083 | ret = fsi_set_master_clk(dai->dev, fsi, rate, 1); |
| 1084 | if (ret < 0) |
Kuninori Morimoto | d4bc99b | 2010-11-24 02:44:06 +0000 | [diff] [blame] | 1085 | return ret; |
Kuninori Morimoto | ccad7b4 | 2010-07-13 12:13:14 +0900 | [diff] [blame] | 1086 | |
Kuninori Morimoto | d4bc99b | 2010-11-24 02:44:06 +0000 | [diff] [blame] | 1087 | fsi->rate = rate; |
Kuninori Morimoto | ccad7b4 | 2010-07-13 12:13:14 +0900 | [diff] [blame] | 1088 | |
| 1089 | return ret; |
Kuninori Morimoto | ccad7b4 | 2010-07-13 12:13:14 +0900 | [diff] [blame] | 1090 | } |
| 1091 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1092 | static struct snd_soc_dai_ops fsi_dai_ops = { |
| 1093 | .startup = fsi_dai_startup, |
| 1094 | .shutdown = fsi_dai_shutdown, |
| 1095 | .trigger = fsi_dai_trigger, |
Kuninori Morimoto | 4d805f7 | 2011-01-20 11:46:02 +0900 | [diff] [blame] | 1096 | .set_fmt = fsi_dai_set_fmt, |
Kuninori Morimoto | ccad7b4 | 2010-07-13 12:13:14 +0900 | [diff] [blame] | 1097 | .hw_params = fsi_dai_hw_params, |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1098 | }; |
| 1099 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 1100 | /* |
| 1101 | * pcm ops |
| 1102 | */ |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1103 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1104 | static struct snd_pcm_hardware fsi_pcm_hardware = { |
| 1105 | .info = SNDRV_PCM_INFO_INTERLEAVED | |
| 1106 | SNDRV_PCM_INFO_MMAP | |
| 1107 | SNDRV_PCM_INFO_MMAP_VALID | |
| 1108 | SNDRV_PCM_INFO_PAUSE, |
| 1109 | .formats = FSI_FMTS, |
| 1110 | .rates = FSI_RATES, |
| 1111 | .rate_min = 8000, |
| 1112 | .rate_max = 192000, |
| 1113 | .channels_min = 1, |
| 1114 | .channels_max = 2, |
| 1115 | .buffer_bytes_max = 64 * 1024, |
| 1116 | .period_bytes_min = 32, |
| 1117 | .period_bytes_max = 8192, |
| 1118 | .periods_min = 1, |
| 1119 | .periods_max = 32, |
| 1120 | .fifo_size = 256, |
| 1121 | }; |
| 1122 | |
| 1123 | static int fsi_pcm_open(struct snd_pcm_substream *substream) |
| 1124 | { |
| 1125 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1126 | int ret = 0; |
| 1127 | |
| 1128 | snd_soc_set_runtime_hwparams(substream, &fsi_pcm_hardware); |
| 1129 | |
| 1130 | ret = snd_pcm_hw_constraint_integer(runtime, |
| 1131 | SNDRV_PCM_HW_PARAM_PERIODS); |
| 1132 | |
| 1133 | return ret; |
| 1134 | } |
| 1135 | |
| 1136 | static int fsi_hw_params(struct snd_pcm_substream *substream, |
| 1137 | struct snd_pcm_hw_params *hw_params) |
| 1138 | { |
| 1139 | return snd_pcm_lib_malloc_pages(substream, |
| 1140 | params_buffer_bytes(hw_params)); |
| 1141 | } |
| 1142 | |
| 1143 | static int fsi_hw_free(struct snd_pcm_substream *substream) |
| 1144 | { |
| 1145 | return snd_pcm_lib_free_pages(substream); |
| 1146 | } |
| 1147 | |
| 1148 | static snd_pcm_uframes_t fsi_pointer(struct snd_pcm_substream *substream) |
| 1149 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 1150 | struct fsi_priv *fsi = fsi_get_priv(substream); |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 1151 | struct fsi_stream *io = fsi_get_stream(fsi, fsi_is_play(substream)); |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 1152 | int samples_pos = io->buff_sample_pos - 1; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1153 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 1154 | if (samples_pos < 0) |
| 1155 | samples_pos = 0; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1156 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 1157 | return fsi_sample2frame(fsi, samples_pos); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | static struct snd_pcm_ops fsi_pcm_ops = { |
| 1161 | .open = fsi_pcm_open, |
| 1162 | .ioctl = snd_pcm_lib_ioctl, |
| 1163 | .hw_params = fsi_hw_params, |
| 1164 | .hw_free = fsi_hw_free, |
| 1165 | .pointer = fsi_pointer, |
| 1166 | }; |
| 1167 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 1168 | /* |
| 1169 | * snd_soc_platform |
| 1170 | */ |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1171 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1172 | #define PREALLOC_BUFFER (32 * 1024) |
| 1173 | #define PREALLOC_BUFFER_MAX (32 * 1024) |
| 1174 | |
| 1175 | static void fsi_pcm_free(struct snd_pcm *pcm) |
| 1176 | { |
| 1177 | snd_pcm_lib_preallocate_free_for_all(pcm); |
| 1178 | } |
| 1179 | |
| 1180 | static int fsi_pcm_new(struct snd_card *card, |
| 1181 | struct snd_soc_dai *dai, |
| 1182 | struct snd_pcm *pcm) |
| 1183 | { |
| 1184 | /* |
| 1185 | * dont use SNDRV_DMA_TYPE_DEV, since it will oops the SH kernel |
| 1186 | * in MMAP mode (i.e. aplay -M) |
| 1187 | */ |
| 1188 | return snd_pcm_lib_preallocate_pages_for_all( |
| 1189 | pcm, |
| 1190 | SNDRV_DMA_TYPE_CONTINUOUS, |
| 1191 | snd_dma_continuous_data(GFP_KERNEL), |
| 1192 | PREALLOC_BUFFER, PREALLOC_BUFFER_MAX); |
| 1193 | } |
| 1194 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 1195 | /* |
| 1196 | * alsa struct |
| 1197 | */ |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1198 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1199 | static struct snd_soc_dai_driver fsi_soc_dai[] = { |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1200 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1201 | .name = "fsia-dai", |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1202 | .playback = { |
| 1203 | .rates = FSI_RATES, |
| 1204 | .formats = FSI_FMTS, |
| 1205 | .channels_min = 1, |
| 1206 | .channels_max = 8, |
| 1207 | }, |
Kuninori Morimoto | 07102f3 | 2009-10-30 12:02:44 +0900 | [diff] [blame] | 1208 | .capture = { |
| 1209 | .rates = FSI_RATES, |
| 1210 | .formats = FSI_FMTS, |
| 1211 | .channels_min = 1, |
| 1212 | .channels_max = 8, |
| 1213 | }, |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1214 | .ops = &fsi_dai_ops, |
| 1215 | }, |
| 1216 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1217 | .name = "fsib-dai", |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1218 | .playback = { |
| 1219 | .rates = FSI_RATES, |
| 1220 | .formats = FSI_FMTS, |
| 1221 | .channels_min = 1, |
| 1222 | .channels_max = 8, |
| 1223 | }, |
Kuninori Morimoto | 07102f3 | 2009-10-30 12:02:44 +0900 | [diff] [blame] | 1224 | .capture = { |
| 1225 | .rates = FSI_RATES, |
| 1226 | .formats = FSI_FMTS, |
| 1227 | .channels_min = 1, |
| 1228 | .channels_max = 8, |
| 1229 | }, |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1230 | .ops = &fsi_dai_ops, |
| 1231 | }, |
| 1232 | }; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1233 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1234 | static struct snd_soc_platform_driver fsi_soc_platform = { |
| 1235 | .ops = &fsi_pcm_ops, |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1236 | .pcm_new = fsi_pcm_new, |
| 1237 | .pcm_free = fsi_pcm_free, |
| 1238 | }; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1239 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 1240 | /* |
| 1241 | * platform function |
| 1242 | */ |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1243 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1244 | static int fsi_probe(struct platform_device *pdev) |
| 1245 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 1246 | struct fsi_master *master; |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 1247 | const struct platform_device_id *id_entry; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1248 | struct resource *res; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1249 | unsigned int irq; |
| 1250 | int ret; |
| 1251 | |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 1252 | id_entry = pdev->id_entry; |
| 1253 | if (!id_entry) { |
| 1254 | dev_err(&pdev->dev, "unknown fsi device\n"); |
| 1255 | return -ENODEV; |
| 1256 | } |
| 1257 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1258 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1259 | irq = platform_get_irq(pdev, 0); |
Uwe Kleine-König | b6aa179 | 2009-12-16 17:10:09 +0100 | [diff] [blame] | 1260 | if (!res || (int)irq <= 0) { |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1261 | dev_err(&pdev->dev, "Not enough FSI platform resources.\n"); |
| 1262 | ret = -ENODEV; |
| 1263 | goto exit; |
| 1264 | } |
| 1265 | |
| 1266 | master = kzalloc(sizeof(*master), GFP_KERNEL); |
| 1267 | if (!master) { |
| 1268 | dev_err(&pdev->dev, "Could not allocate master\n"); |
| 1269 | ret = -ENOMEM; |
| 1270 | goto exit; |
| 1271 | } |
| 1272 | |
| 1273 | master->base = ioremap_nocache(res->start, resource_size(res)); |
| 1274 | if (!master->base) { |
| 1275 | ret = -ENXIO; |
| 1276 | dev_err(&pdev->dev, "Unable to ioremap FSI registers.\n"); |
| 1277 | goto exit_kfree; |
| 1278 | } |
| 1279 | |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 1280 | /* master setting */ |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1281 | master->irq = irq; |
| 1282 | master->info = pdev->dev.platform_data; |
Kuninori Morimoto | 73b92c1 | 2010-07-13 12:13:04 +0900 | [diff] [blame] | 1283 | master->core = (struct fsi_core *)id_entry->driver_data; |
Kuninori Morimoto | 8fc176d | 2010-01-28 13:46:16 +0900 | [diff] [blame] | 1284 | spin_lock_init(&master->lock); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1285 | |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 1286 | /* FSI A setting */ |
| 1287 | master->fsia.base = master->base; |
| 1288 | master->fsia.master = master; |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 1289 | |
| 1290 | /* FSI B setting */ |
| 1291 | master->fsib.base = master->base + 0x40; |
| 1292 | master->fsib.master = master; |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 1293 | |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 1294 | pm_runtime_enable(&pdev->dev); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1295 | dev_set_drvdata(&pdev->dev, master); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1296 | |
Kuninori Morimoto | 1f5e2a3 | 2011-04-21 10:33:52 +0900 | [diff] [blame] | 1297 | fsi_module_init(master, &pdev->dev); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1298 | |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 1299 | ret = request_irq(irq, &fsi_interrupt, IRQF_DISABLED, |
| 1300 | id_entry->name, master); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1301 | if (ret) { |
| 1302 | dev_err(&pdev->dev, "irq request err\n"); |
Kuninori Morimoto | 9ddc9aa | 2009-10-30 12:02:39 +0900 | [diff] [blame] | 1303 | goto exit_iounmap; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1304 | } |
| 1305 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1306 | ret = snd_soc_register_platform(&pdev->dev, &fsi_soc_platform); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1307 | if (ret < 0) { |
| 1308 | dev_err(&pdev->dev, "cannot snd soc register\n"); |
| 1309 | goto exit_free_irq; |
| 1310 | } |
| 1311 | |
Kuninori Morimoto | 0b5ec87 | 2011-04-08 15:09:02 +0900 | [diff] [blame] | 1312 | ret = snd_soc_register_dais(&pdev->dev, fsi_soc_dai, |
| 1313 | ARRAY_SIZE(fsi_soc_dai)); |
| 1314 | if (ret < 0) { |
| 1315 | dev_err(&pdev->dev, "cannot snd dai register\n"); |
| 1316 | goto exit_snd_soc; |
| 1317 | } |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1318 | |
Kuninori Morimoto | 0b5ec87 | 2011-04-08 15:09:02 +0900 | [diff] [blame] | 1319 | return ret; |
| 1320 | |
| 1321 | exit_snd_soc: |
| 1322 | snd_soc_unregister_platform(&pdev->dev); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1323 | exit_free_irq: |
| 1324 | free_irq(irq, master); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1325 | exit_iounmap: |
| 1326 | iounmap(master->base); |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 1327 | pm_runtime_disable(&pdev->dev); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1328 | exit_kfree: |
| 1329 | kfree(master); |
| 1330 | master = NULL; |
| 1331 | exit: |
| 1332 | return ret; |
| 1333 | } |
| 1334 | |
| 1335 | static int fsi_remove(struct platform_device *pdev) |
| 1336 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 1337 | struct fsi_master *master; |
| 1338 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1339 | master = dev_get_drvdata(&pdev->dev); |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 1340 | |
Kuninori Morimoto | 1f5e2a3 | 2011-04-21 10:33:52 +0900 | [diff] [blame] | 1341 | fsi_module_kill(master, &pdev->dev); |
| 1342 | |
Kuninori Morimoto | d985f27 | 2011-04-08 15:09:25 +0900 | [diff] [blame] | 1343 | free_irq(master->irq, master); |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 1344 | pm_runtime_disable(&pdev->dev); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1345 | |
Kuninori Morimoto | d985f27 | 2011-04-08 15:09:25 +0900 | [diff] [blame] | 1346 | snd_soc_unregister_dais(&pdev->dev, ARRAY_SIZE(fsi_soc_dai)); |
| 1347 | snd_soc_unregister_platform(&pdev->dev); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1348 | |
| 1349 | iounmap(master->base); |
| 1350 | kfree(master); |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 1351 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1352 | return 0; |
| 1353 | } |
| 1354 | |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1355 | static void __fsi_suspend(struct fsi_priv *fsi, |
Kuninori Morimoto | 4f56cde | 2011-05-23 20:46:18 +0900 | [diff] [blame] | 1356 | struct device *dev) |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1357 | { |
| 1358 | fsi->saved_do_fmt = fsi_reg_read(fsi, DO_FMT); |
| 1359 | fsi->saved_di_fmt = fsi_reg_read(fsi, DI_FMT); |
| 1360 | fsi->saved_ckg1 = fsi_reg_read(fsi, CKG1); |
| 1361 | fsi->saved_ckg2 = fsi_reg_read(fsi, CKG2); |
| 1362 | fsi->saved_out_sel = fsi_reg_read(fsi, OUT_SEL); |
| 1363 | |
| 1364 | if (fsi_is_clk_master(fsi)) |
Kuninori Morimoto | 4f56cde | 2011-05-23 20:46:18 +0900 | [diff] [blame] | 1365 | fsi_set_master_clk(dev, fsi, fsi->rate, 0); |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | static void __fsi_resume(struct fsi_priv *fsi, |
Kuninori Morimoto | 4f56cde | 2011-05-23 20:46:18 +0900 | [diff] [blame] | 1369 | struct device *dev) |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1370 | { |
| 1371 | fsi_reg_write(fsi, DO_FMT, fsi->saved_do_fmt); |
| 1372 | fsi_reg_write(fsi, DI_FMT, fsi->saved_di_fmt); |
| 1373 | fsi_reg_write(fsi, CKG1, fsi->saved_ckg1); |
| 1374 | fsi_reg_write(fsi, CKG2, fsi->saved_ckg2); |
| 1375 | fsi_reg_write(fsi, OUT_SEL, fsi->saved_out_sel); |
| 1376 | |
| 1377 | if (fsi_is_clk_master(fsi)) |
Kuninori Morimoto | 4f56cde | 2011-05-23 20:46:18 +0900 | [diff] [blame] | 1378 | fsi_set_master_clk(dev, fsi, fsi->rate, 1); |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | static int fsi_suspend(struct device *dev) |
| 1382 | { |
| 1383 | struct fsi_master *master = dev_get_drvdata(dev); |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1384 | |
| 1385 | pm_runtime_get_sync(dev); |
| 1386 | |
Kuninori Morimoto | 4f56cde | 2011-05-23 20:46:18 +0900 | [diff] [blame] | 1387 | __fsi_suspend(&master->fsia, dev); |
| 1388 | __fsi_suspend(&master->fsib, dev); |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1389 | |
| 1390 | master->saved_a_mclk = fsi_core_read(master, a_mclk); |
| 1391 | master->saved_b_mclk = fsi_core_read(master, b_mclk); |
| 1392 | master->saved_iemsk = fsi_core_read(master, iemsk); |
| 1393 | master->saved_imsk = fsi_core_read(master, imsk); |
| 1394 | master->saved_clk_rst = fsi_master_read(master, CLK_RST); |
Kuninori Morimoto | 1f5e2a3 | 2011-04-21 10:33:52 +0900 | [diff] [blame] | 1395 | master->saved_soft_rst = fsi_master_read(master, SOFT_RST); |
| 1396 | |
| 1397 | fsi_module_kill(master, dev); |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1398 | |
| 1399 | pm_runtime_put_sync(dev); |
| 1400 | |
| 1401 | return 0; |
| 1402 | } |
| 1403 | |
| 1404 | static int fsi_resume(struct device *dev) |
| 1405 | { |
| 1406 | struct fsi_master *master = dev_get_drvdata(dev); |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1407 | |
| 1408 | pm_runtime_get_sync(dev); |
| 1409 | |
Kuninori Morimoto | 1f5e2a3 | 2011-04-21 10:33:52 +0900 | [diff] [blame] | 1410 | fsi_module_init(master, dev); |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1411 | |
Kuninori Morimoto | 1f5e2a3 | 2011-04-21 10:33:52 +0900 | [diff] [blame] | 1412 | fsi_master_mask_set(master, SOFT_RST, 0xffff, master->saved_soft_rst); |
| 1413 | fsi_master_mask_set(master, CLK_RST, 0xffff, master->saved_clk_rst); |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1414 | fsi_core_mask_set(master, a_mclk, 0xffff, master->saved_a_mclk); |
| 1415 | fsi_core_mask_set(master, b_mclk, 0xffff, master->saved_b_mclk); |
| 1416 | fsi_core_mask_set(master, iemsk, 0xffff, master->saved_iemsk); |
| 1417 | fsi_core_mask_set(master, imsk, 0xffff, master->saved_imsk); |
Kuninori Morimoto | 1f5e2a3 | 2011-04-21 10:33:52 +0900 | [diff] [blame] | 1418 | |
Kuninori Morimoto | 4f56cde | 2011-05-23 20:46:18 +0900 | [diff] [blame] | 1419 | __fsi_resume(&master->fsia, dev); |
| 1420 | __fsi_resume(&master->fsib, dev); |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1421 | |
| 1422 | pm_runtime_put_sync(dev); |
| 1423 | |
| 1424 | return 0; |
| 1425 | } |
| 1426 | |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 1427 | static int fsi_runtime_nop(struct device *dev) |
| 1428 | { |
| 1429 | /* Runtime PM callback shared between ->runtime_suspend() |
| 1430 | * and ->runtime_resume(). Simply returns success. |
| 1431 | * |
| 1432 | * This driver re-initializes all registers after |
| 1433 | * pm_runtime_get_sync() anyway so there is no need |
| 1434 | * to save and restore registers here. |
| 1435 | */ |
| 1436 | return 0; |
| 1437 | } |
| 1438 | |
| 1439 | static struct dev_pm_ops fsi_pm_ops = { |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1440 | .suspend = fsi_suspend, |
| 1441 | .resume = fsi_resume, |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 1442 | .runtime_suspend = fsi_runtime_nop, |
| 1443 | .runtime_resume = fsi_runtime_nop, |
| 1444 | }; |
| 1445 | |
Kuninori Morimoto | 73b92c1 | 2010-07-13 12:13:04 +0900 | [diff] [blame] | 1446 | static struct fsi_core fsi1_core = { |
| 1447 | .ver = 1, |
| 1448 | |
| 1449 | /* Interrupt */ |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 1450 | .int_st = INT_ST, |
| 1451 | .iemsk = IEMSK, |
| 1452 | .imsk = IMSK, |
| 1453 | }; |
| 1454 | |
Kuninori Morimoto | 73b92c1 | 2010-07-13 12:13:04 +0900 | [diff] [blame] | 1455 | static struct fsi_core fsi2_core = { |
| 1456 | .ver = 2, |
| 1457 | |
| 1458 | /* Interrupt */ |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 1459 | .int_st = CPU_INT_ST, |
| 1460 | .iemsk = CPU_IEMSK, |
| 1461 | .imsk = CPU_IMSK, |
Kuninori Morimoto | 2b0e730 | 2010-12-03 17:37:44 +0900 | [diff] [blame] | 1462 | .a_mclk = A_MST_CTLR, |
| 1463 | .b_mclk = B_MST_CTLR, |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 1464 | }; |
| 1465 | |
| 1466 | static struct platform_device_id fsi_id_table[] = { |
Kuninori Morimoto | 73b92c1 | 2010-07-13 12:13:04 +0900 | [diff] [blame] | 1467 | { "sh_fsi", (kernel_ulong_t)&fsi1_core }, |
| 1468 | { "sh_fsi2", (kernel_ulong_t)&fsi2_core }, |
Guennadi Liakhovetski | 05c6945 | 2010-10-05 17:54:28 +0200 | [diff] [blame] | 1469 | {}, |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 1470 | }; |
Dzianis Kahanovich | d85a6d7 | 2010-09-17 16:42:05 +0300 | [diff] [blame] | 1471 | MODULE_DEVICE_TABLE(platform, fsi_id_table); |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 1472 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1473 | static struct platform_driver fsi_driver = { |
| 1474 | .driver = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1475 | .name = "fsi-pcm-audio", |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 1476 | .pm = &fsi_pm_ops, |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1477 | }, |
| 1478 | .probe = fsi_probe, |
| 1479 | .remove = fsi_remove, |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 1480 | .id_table = fsi_id_table, |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1481 | }; |
| 1482 | |
| 1483 | static int __init fsi_mobile_init(void) |
| 1484 | { |
| 1485 | return platform_driver_register(&fsi_driver); |
| 1486 | } |
| 1487 | |
| 1488 | static void __exit fsi_mobile_exit(void) |
| 1489 | { |
| 1490 | platform_driver_unregister(&fsi_driver); |
| 1491 | } |
Dzianis Kahanovich | d85a6d7 | 2010-09-17 16:42:05 +0300 | [diff] [blame] | 1492 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1493 | module_init(fsi_mobile_init); |
| 1494 | module_exit(fsi_mobile_exit); |
| 1495 | |
| 1496 | MODULE_LICENSE("GPL"); |
| 1497 | MODULE_DESCRIPTION("SuperH onchip FSI audio driver"); |
| 1498 | MODULE_AUTHOR("Kuninori Morimoto <morimoto.kuninori@renesas.com>"); |
Guennadi Liakhovetski | b3c27b5 | 2011-04-15 20:17:34 +0200 | [diff] [blame] | 1499 | MODULE_ALIAS("platform:fsi-pcm-audio"); |