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