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