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 | 7da9ced | 2012-02-03 00:59:33 -0800 | [diff] [blame] | 16 | #include <linux/dma-mapping.h> |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 17 | #include <linux/pm_runtime.h> |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 18 | #include <linux/io.h> |
Kuninori Morimoto | 7da9ced | 2012-02-03 00:59:33 -0800 | [diff] [blame] | 19 | #include <linux/scatterlist.h> |
| 20 | #include <linux/sh_dma.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 21 | #include <linux/slab.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 22 | #include <linux/module.h> |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 23 | #include <sound/soc.h> |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 24 | #include <sound/sh_fsi.h> |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 25 | |
Kuninori Morimoto | e8c8b63 | 2010-12-03 17:37:55 +0900 | [diff] [blame] | 26 | /* PortA/PortB register */ |
| 27 | #define REG_DO_FMT 0x0000 |
| 28 | #define REG_DOFF_CTL 0x0004 |
| 29 | #define REG_DOFF_ST 0x0008 |
| 30 | #define REG_DI_FMT 0x000C |
| 31 | #define REG_DIFF_CTL 0x0010 |
| 32 | #define REG_DIFF_ST 0x0014 |
| 33 | #define REG_CKG1 0x0018 |
| 34 | #define REG_CKG2 0x001C |
| 35 | #define REG_DIDT 0x0020 |
| 36 | #define REG_DODT 0x0024 |
| 37 | #define REG_MUTE_ST 0x0028 |
Kuninori Morimoto | 65ff03f | 2011-11-06 22:05:25 -0800 | [diff] [blame] | 38 | #define REG_OUT_DMAC 0x002C |
Kuninori Morimoto | e8c8b63 | 2010-12-03 17:37:55 +0900 | [diff] [blame] | 39 | #define REG_OUT_SEL 0x0030 |
Kuninori Morimoto | 65ff03f | 2011-11-06 22:05:25 -0800 | [diff] [blame] | 40 | #define REG_IN_DMAC 0x0038 |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 41 | |
Kuninori Morimoto | 43fa95c | 2010-12-03 17:38:03 +0900 | [diff] [blame] | 42 | /* master register */ |
| 43 | #define MST_CLK_RST 0x0210 |
| 44 | #define MST_SOFT_RST 0x0214 |
| 45 | #define MST_FIFO_SZ 0x0218 |
| 46 | |
| 47 | /* core register (depend on FSI version) */ |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 48 | #define A_MST_CTLR 0x0180 |
| 49 | #define B_MST_CTLR 0x01A0 |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 50 | #define CPU_INT_ST 0x01F4 |
| 51 | #define CPU_IEMSK 0x01F8 |
| 52 | #define CPU_IMSK 0x01FC |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 53 | #define INT_ST 0x0200 |
| 54 | #define IEMSK 0x0204 |
| 55 | #define IMSK 0x0208 |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 56 | |
| 57 | /* DO_FMT */ |
| 58 | /* DI_FMT */ |
Kuninori Morimoto | 7da9ced | 2012-02-03 00:59:33 -0800 | [diff] [blame] | 59 | #define CR_BWS_MASK (0x3 << 20) /* FSI2 */ |
Kuninori Morimoto | f7d711e | 2010-12-03 17:36:24 +0900 | [diff] [blame] | 60 | #define CR_BWS_24 (0x0 << 20) /* FSI2 */ |
| 61 | #define CR_BWS_16 (0x1 << 20) /* FSI2 */ |
| 62 | #define CR_BWS_20 (0x2 << 20) /* FSI2 */ |
| 63 | |
| 64 | #define CR_DTMD_PCM (0x0 << 8) /* FSI2 */ |
| 65 | #define CR_DTMD_SPDIF_PCM (0x1 << 8) /* FSI2 */ |
| 66 | #define CR_DTMD_SPDIF_STREAM (0x2 << 8) /* FSI2 */ |
| 67 | |
Kuninori Morimoto | a7ffb52 | 2010-07-13 12:13:00 +0900 | [diff] [blame] | 68 | #define CR_MONO (0x0 << 4) |
| 69 | #define CR_MONO_D (0x1 << 4) |
| 70 | #define CR_PCM (0x2 << 4) |
| 71 | #define CR_I2S (0x3 << 4) |
| 72 | #define CR_TDM (0x4 << 4) |
| 73 | #define CR_TDM_D (0x5 << 4) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 74 | |
Kuninori Morimoto | 7da9ced | 2012-02-03 00:59:33 -0800 | [diff] [blame] | 75 | /* OUT_DMAC */ |
| 76 | /* IN_DMAC */ |
| 77 | #define VDMD_MASK (0x3 << 4) |
| 78 | #define VDMD_FRONT (0x0 << 4) /* Package in front */ |
| 79 | #define VDMD_BACK (0x1 << 4) /* Package in back */ |
| 80 | #define VDMD_STREAM (0x2 << 4) /* Stream mode(16bit * 2) */ |
| 81 | |
| 82 | #define DMA_ON (0x1 << 0) |
| 83 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 84 | /* DOFF_CTL */ |
| 85 | /* DIFF_CTL */ |
| 86 | #define IRQ_HALF 0x00100000 |
| 87 | #define FIFO_CLR 0x00000001 |
| 88 | |
| 89 | /* DOFF_ST */ |
| 90 | #define ERR_OVER 0x00000010 |
| 91 | #define ERR_UNDER 0x00000001 |
Kuninori Morimoto | 59c3b00 | 2009-12-28 14:09:16 +0900 | [diff] [blame] | 92 | #define ST_ERR (ERR_OVER | ERR_UNDER) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 93 | |
Kuninori Morimoto | ccad7b4 | 2010-07-13 12:13:14 +0900 | [diff] [blame] | 94 | /* CKG1 */ |
| 95 | #define ACKMD_MASK 0x00007000 |
| 96 | #define BPFMD_MASK 0x00000700 |
Kuninori Morimoto | 4d805f7 | 2011-01-20 11:46:02 +0900 | [diff] [blame] | 97 | #define DIMD (1 << 4) |
| 98 | #define DOMD (1 << 0) |
Kuninori Morimoto | ccad7b4 | 2010-07-13 12:13:14 +0900 | [diff] [blame] | 99 | |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 100 | /* A/B MST_CTLR */ |
| 101 | #define BP (1 << 4) /* Fix the signal of Biphase output */ |
| 102 | #define SE (1 << 0) /* Fix the master clock */ |
| 103 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 104 | /* CLK_RST */ |
Kuninori Morimoto | 1f5e2a3 | 2011-04-21 10:33:52 +0900 | [diff] [blame] | 105 | #define CRB (1 << 4) |
| 106 | #define CRA (1 << 0) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 107 | |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 108 | /* IO SHIFT / MACRO */ |
| 109 | #define BI_SHIFT 12 |
| 110 | #define BO_SHIFT 8 |
| 111 | #define AI_SHIFT 4 |
| 112 | #define AO_SHIFT 0 |
| 113 | #define AB_IO(param, shift) (param << shift) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 114 | |
Kuninori Morimoto | feb58cf | 2010-03-24 15:27:24 +0900 | [diff] [blame] | 115 | /* SOFT_RST */ |
| 116 | #define PBSR (1 << 12) /* Port B Software Reset */ |
| 117 | #define PASR (1 << 8) /* Port A Software Reset */ |
| 118 | #define IR (1 << 4) /* Interrupt Reset */ |
| 119 | #define FSISR (1 << 0) /* Software Reset */ |
| 120 | |
Kuninori Morimoto | f7d711e | 2010-12-03 17:36:24 +0900 | [diff] [blame] | 121 | /* OUT_SEL (FSI2) */ |
| 122 | #define DMMD (1 << 4) /* SPDIF output timing 0: Biphase only */ |
| 123 | /* 1: Biphase and serial */ |
| 124 | |
Kuninori Morimoto | 4a942b4 | 2010-03-25 19:15:51 +0900 | [diff] [blame] | 125 | /* FIFO_SZ */ |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 126 | #define FIFO_SZ_MASK 0x7 |
Kuninori Morimoto | 4a942b4 | 2010-03-25 19:15:51 +0900 | [diff] [blame] | 127 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 128 | #define FSI_RATES SNDRV_PCM_RATE_8000_96000 |
| 129 | |
| 130 | #define FSI_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE) |
| 131 | |
Kuninori Morimoto | fec691e | 2012-02-03 00:58:48 -0800 | [diff] [blame] | 132 | typedef int (*set_rate_func)(struct device *dev, int rate, int enable); |
Kuninori Morimoto | d7c5762 | 2011-01-24 10:42:33 +0900 | [diff] [blame] | 133 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 134 | /* |
Kuninori Morimoto | 766812e | 2012-05-17 17:36:47 -0700 | [diff] [blame] | 135 | * bus options |
| 136 | * |
| 137 | * 0x000000BA |
| 138 | * |
| 139 | * A : sample widtht 16bit setting |
| 140 | * B : sample widtht 24bit setting |
| 141 | */ |
| 142 | |
| 143 | #define SHIFT_16DATA 0 |
| 144 | #define SHIFT_24DATA 4 |
| 145 | |
| 146 | #define PACKAGE_24BITBUS_BACK 0 |
| 147 | #define PACKAGE_24BITBUS_FRONT 1 |
| 148 | #define PACKAGE_16BITBUS_STREAM 2 |
| 149 | |
| 150 | #define BUSOP_SET(s, a) ((a) << SHIFT_ ## s ## DATA) |
| 151 | #define BUSOP_GET(s, a) (((a) >> SHIFT_ ## s ## DATA) & 0xF) |
| 152 | |
| 153 | /* |
Kuninori Morimoto | 5bfb9ad | 2010-09-17 13:48:45 +0900 | [diff] [blame] | 154 | * FSI driver use below type name for variable |
| 155 | * |
Kuninori Morimoto | 5bfb9ad | 2010-09-17 13:48:45 +0900 | [diff] [blame] | 156 | * xxx_num : number of data |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 157 | * xxx_pos : position of data |
| 158 | * xxx_capa : capacity of data |
| 159 | */ |
| 160 | |
| 161 | /* |
| 162 | * period/frame/sample image |
| 163 | * |
| 164 | * ex) PCM (2ch) |
| 165 | * |
| 166 | * period pos period pos |
| 167 | * [n] [n + 1] |
| 168 | * |<-------------------- period--------------------->| |
| 169 | * ==|============================================ ... =|== |
| 170 | * | | |
| 171 | * ||<----- frame ----->|<------ frame ----->| ... | |
| 172 | * |+--------------------+--------------------+- ... | |
| 173 | * ||[ sample ][ sample ]|[ sample ][ sample ]| ... | |
| 174 | * |+--------------------+--------------------+- ... | |
| 175 | * ==|============================================ ... =|== |
| 176 | */ |
| 177 | |
| 178 | /* |
| 179 | * FSI FIFO image |
| 180 | * |
| 181 | * | | |
| 182 | * | | |
| 183 | * | [ sample ] | |
| 184 | * | [ sample ] | |
| 185 | * | [ sample ] | |
| 186 | * | [ sample ] | |
| 187 | * --> go to codecs |
Kuninori Morimoto | 5bfb9ad | 2010-09-17 13:48:45 +0900 | [diff] [blame] | 188 | */ |
| 189 | |
| 190 | /* |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 191 | * struct |
| 192 | */ |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 193 | |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 194 | struct fsi_stream_handler; |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 195 | struct fsi_stream { |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 196 | |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 197 | /* |
| 198 | * these are initialized by fsi_stream_init() |
| 199 | */ |
| 200 | struct snd_pcm_substream *substream; |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 201 | int fifo_sample_capa; /* sample capacity of FSI FIFO */ |
| 202 | int buff_sample_capa; /* sample capacity of ALSA buffer */ |
| 203 | int buff_sample_pos; /* sample position of ALSA buffer */ |
| 204 | int period_samples; /* sample number / 1 period */ |
| 205 | int period_pos; /* current period position */ |
Kuninori Morimoto | c1e6f10 | 2012-02-03 00:50:09 -0800 | [diff] [blame] | 206 | int sample_width; /* sample width */ |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 207 | int uerr_num; |
| 208 | int oerr_num; |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 209 | |
| 210 | /* |
Kuninori Morimoto | 766812e | 2012-05-17 17:36:47 -0700 | [diff] [blame] | 211 | * bus options |
| 212 | */ |
| 213 | u32 bus_option; |
| 214 | |
| 215 | /* |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 216 | * thse are initialized by fsi_handler_init() |
| 217 | */ |
| 218 | struct fsi_stream_handler *handler; |
| 219 | struct fsi_priv *priv; |
Kuninori Morimoto | 7da9ced | 2012-02-03 00:59:33 -0800 | [diff] [blame] | 220 | |
| 221 | /* |
| 222 | * these are for DMAEngine |
| 223 | */ |
| 224 | struct dma_chan *chan; |
| 225 | struct sh_dmae_slave slave; /* see fsi_handler_init() */ |
| 226 | struct tasklet_struct tasklet; |
| 227 | dma_addr_t dma; |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 228 | }; |
| 229 | |
| 230 | struct fsi_priv { |
| 231 | void __iomem *base; |
| 232 | struct fsi_master *master; |
Kuninori Morimoto | fec691e | 2012-02-03 00:58:48 -0800 | [diff] [blame] | 233 | struct sh_fsi_port_info *info; |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 234 | |
| 235 | struct fsi_stream playback; |
| 236 | struct fsi_stream capture; |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 237 | |
Kuninori Morimoto | 9c59dd3 | 2012-05-17 17:34:53 -0700 | [diff] [blame] | 238 | u32 fmt; |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 239 | |
Kuninori Morimoto | 6a9ebad | 2011-04-21 10:33:36 +0900 | [diff] [blame] | 240 | int chan_num:16; |
| 241 | int clk_master:1; |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 242 | int spdif:1; |
Kuninori Morimoto | 6a9ebad | 2011-04-21 10:33:36 +0900 | [diff] [blame] | 243 | |
Kuninori Morimoto | d4bc99b | 2010-11-24 02:44:06 +0000 | [diff] [blame] | 244 | long rate; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 245 | }; |
| 246 | |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 247 | struct fsi_stream_handler { |
Kuninori Morimoto | 8334402 | 2012-02-03 00:59:02 -0800 | [diff] [blame] | 248 | int (*init)(struct fsi_priv *fsi, struct fsi_stream *io); |
| 249 | int (*quit)(struct fsi_priv *fsi, struct fsi_stream *io); |
Kuninori Morimoto | b1226dc | 2012-05-24 23:56:19 -0700 | [diff] [blame^] | 250 | int (*probe)(struct fsi_priv *fsi, struct fsi_stream *io, struct device *dev); |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 251 | int (*transfer)(struct fsi_priv *fsi, struct fsi_stream *io); |
| 252 | int (*remove)(struct fsi_priv *fsi, struct fsi_stream *io); |
Kuninori Morimoto | 180346e | 2012-02-03 00:57:25 -0800 | [diff] [blame] | 253 | void (*start_stop)(struct fsi_priv *fsi, struct fsi_stream *io, |
| 254 | int enable); |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 255 | }; |
| 256 | #define fsi_stream_handler_call(io, func, args...) \ |
| 257 | (!(io) ? -ENODEV : \ |
| 258 | !((io)->handler->func) ? 0 : \ |
| 259 | (io)->handler->func(args)) |
| 260 | |
Kuninori Morimoto | 73b92c1 | 2010-07-13 12:13:04 +0900 | [diff] [blame] | 261 | struct fsi_core { |
| 262 | int ver; |
| 263 | |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 264 | u32 int_st; |
| 265 | u32 iemsk; |
| 266 | u32 imsk; |
Kuninori Morimoto | 2b0e730 | 2010-12-03 17:37:44 +0900 | [diff] [blame] | 267 | u32 a_mclk; |
| 268 | u32 b_mclk; |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 269 | }; |
| 270 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 271 | struct fsi_master { |
| 272 | void __iomem *base; |
| 273 | int irq; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 274 | struct fsi_priv fsia; |
| 275 | struct fsi_priv fsib; |
Kuninori Morimoto | 73b92c1 | 2010-07-13 12:13:04 +0900 | [diff] [blame] | 276 | struct fsi_core *core; |
Kuninori Morimoto | 8fc176d | 2010-01-28 13:46:16 +0900 | [diff] [blame] | 277 | spinlock_t lock; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 278 | }; |
| 279 | |
Kuninori Morimoto | 7b1b333 | 2012-02-03 00:55:26 -0800 | [diff] [blame] | 280 | static int fsi_stream_is_play(struct fsi_priv *fsi, struct fsi_stream *io); |
| 281 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 282 | /* |
| 283 | * basic read write function |
| 284 | */ |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 285 | |
Arnd Bergmann | ca7acee | 2011-10-02 22:28:02 +0200 | [diff] [blame] | 286 | static void __fsi_reg_write(u32 __iomem *reg, u32 data) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 287 | { |
| 288 | /* valid data area is 24bit */ |
| 289 | data &= 0x00ffffff; |
| 290 | |
Guennadi Liakhovetski | 0f69d97 | 2010-02-03 17:37:23 +0100 | [diff] [blame] | 291 | __raw_writel(data, reg); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 292 | } |
| 293 | |
Arnd Bergmann | ca7acee | 2011-10-02 22:28:02 +0200 | [diff] [blame] | 294 | static u32 __fsi_reg_read(u32 __iomem *reg) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 295 | { |
Guennadi Liakhovetski | 0f69d97 | 2010-02-03 17:37:23 +0100 | [diff] [blame] | 296 | return __raw_readl(reg); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 297 | } |
| 298 | |
Arnd Bergmann | ca7acee | 2011-10-02 22:28:02 +0200 | [diff] [blame] | 299 | 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] | 300 | { |
| 301 | u32 val = __fsi_reg_read(reg); |
| 302 | |
| 303 | val &= ~mask; |
| 304 | val |= data & mask; |
| 305 | |
Guennadi Liakhovetski | 0f69d97 | 2010-02-03 17:37:23 +0100 | [diff] [blame] | 306 | __fsi_reg_write(reg, val); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 307 | } |
| 308 | |
Kuninori Morimoto | e8c8b63 | 2010-12-03 17:37:55 +0900 | [diff] [blame] | 309 | #define fsi_reg_write(p, r, d)\ |
Kuninori Morimoto | 8918b84 | 2011-10-31 22:11:53 -0700 | [diff] [blame] | 310 | __fsi_reg_write((p->base + REG_##r), d) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 311 | |
Kuninori Morimoto | e8c8b63 | 2010-12-03 17:37:55 +0900 | [diff] [blame] | 312 | #define fsi_reg_read(p, r)\ |
Kuninori Morimoto | 8918b84 | 2011-10-31 22:11:53 -0700 | [diff] [blame] | 313 | __fsi_reg_read((p->base + REG_##r)) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 314 | |
Kuninori Morimoto | e8c8b63 | 2010-12-03 17:37:55 +0900 | [diff] [blame] | 315 | #define fsi_reg_mask_set(p, r, m, d)\ |
Kuninori Morimoto | 8918b84 | 2011-10-31 22:11:53 -0700 | [diff] [blame] | 316 | __fsi_reg_mask_set((p->base + REG_##r), m, d) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 317 | |
Kuninori Morimoto | 43fa95c | 2010-12-03 17:38:03 +0900 | [diff] [blame] | 318 | #define fsi_master_read(p, r) _fsi_master_read(p, MST_##r) |
| 319 | #define fsi_core_read(p, r) _fsi_master_read(p, p->core->r) |
| 320 | static u32 _fsi_master_read(struct fsi_master *master, u32 reg) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 321 | { |
Kuninori Morimoto | 8fc176d | 2010-01-28 13:46:16 +0900 | [diff] [blame] | 322 | u32 ret; |
| 323 | unsigned long flags; |
| 324 | |
Kuninori Morimoto | 8fc176d | 2010-01-28 13:46:16 +0900 | [diff] [blame] | 325 | spin_lock_irqsave(&master->lock, flags); |
Arnd Bergmann | ca7acee | 2011-10-02 22:28:02 +0200 | [diff] [blame] | 326 | ret = __fsi_reg_read(master->base + reg); |
Kuninori Morimoto | 8fc176d | 2010-01-28 13:46:16 +0900 | [diff] [blame] | 327 | spin_unlock_irqrestore(&master->lock, flags); |
| 328 | |
| 329 | return ret; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 330 | } |
| 331 | |
Kuninori Morimoto | 43fa95c | 2010-12-03 17:38:03 +0900 | [diff] [blame] | 332 | #define fsi_master_mask_set(p, r, m, d) _fsi_master_mask_set(p, MST_##r, m, d) |
| 333 | #define fsi_core_mask_set(p, r, m, d) _fsi_master_mask_set(p, p->core->r, m, d) |
| 334 | static void _fsi_master_mask_set(struct fsi_master *master, |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 335 | u32 reg, u32 mask, u32 data) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 336 | { |
Kuninori Morimoto | 8fc176d | 2010-01-28 13:46:16 +0900 | [diff] [blame] | 337 | unsigned long flags; |
| 338 | |
Kuninori Morimoto | 8fc176d | 2010-01-28 13:46:16 +0900 | [diff] [blame] | 339 | spin_lock_irqsave(&master->lock, flags); |
Arnd Bergmann | ca7acee | 2011-10-02 22:28:02 +0200 | [diff] [blame] | 340 | __fsi_reg_mask_set(master->base + reg, mask, data); |
Kuninori Morimoto | 8fc176d | 2010-01-28 13:46:16 +0900 | [diff] [blame] | 341 | spin_unlock_irqrestore(&master->lock, flags); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 342 | } |
| 343 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 344 | /* |
| 345 | * basic function |
| 346 | */ |
Kuninori Morimoto | 284c6f6 | 2012-05-17 17:34:16 -0700 | [diff] [blame] | 347 | static int fsi_version(struct fsi_master *master) |
| 348 | { |
| 349 | return master->core->ver; |
| 350 | } |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 351 | |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 352 | static struct fsi_master *fsi_get_master(struct fsi_priv *fsi) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 353 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 354 | return fsi->master; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 355 | } |
| 356 | |
Kuninori Morimoto | 6a9ebad | 2011-04-21 10:33:36 +0900 | [diff] [blame] | 357 | static int fsi_is_clk_master(struct fsi_priv *fsi) |
| 358 | { |
| 359 | return fsi->clk_master; |
| 360 | } |
| 361 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 362 | static int fsi_is_port_a(struct fsi_priv *fsi) |
| 363 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 364 | return fsi->master->base == fsi->base; |
| 365 | } |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 366 | |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 367 | static int fsi_is_spdif(struct fsi_priv *fsi) |
| 368 | { |
| 369 | return fsi->spdif; |
| 370 | } |
| 371 | |
Kuninori Morimoto | a449e46 | 2012-02-03 00:54:02 -0800 | [diff] [blame] | 372 | static int fsi_is_play(struct snd_pcm_substream *substream) |
| 373 | { |
| 374 | return substream->stream == SNDRV_PCM_STREAM_PLAYBACK; |
| 375 | } |
| 376 | |
Kuninori Morimoto | 142e817 | 2009-12-28 14:09:11 +0900 | [diff] [blame] | 377 | 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] | 378 | { |
| 379 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Kuninori Morimoto | 142e817 | 2009-12-28 14:09:11 +0900 | [diff] [blame] | 380 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 381 | return rtd->cpu_dai; |
Kuninori Morimoto | 142e817 | 2009-12-28 14:09:11 +0900 | [diff] [blame] | 382 | } |
| 383 | |
Kuninori Morimoto | 0d032c1 | 2011-01-20 11:45:51 +0900 | [diff] [blame] | 384 | 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] | 385 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 386 | struct fsi_master *master = snd_soc_dai_get_drvdata(dai); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 387 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 388 | if (dai->id == 0) |
| 389 | return &master->fsia; |
| 390 | else |
| 391 | return &master->fsib; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 392 | } |
| 393 | |
Kuninori Morimoto | 0d032c1 | 2011-01-20 11:45:51 +0900 | [diff] [blame] | 394 | static struct fsi_priv *fsi_get_priv(struct snd_pcm_substream *substream) |
| 395 | { |
| 396 | return fsi_get_priv_frm_dai(fsi_get_dai(substream)); |
| 397 | } |
| 398 | |
Kuninori Morimoto | fec691e | 2012-02-03 00:58:48 -0800 | [diff] [blame] | 399 | 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] | 400 | { |
Kuninori Morimoto | fec691e | 2012-02-03 00:58:48 -0800 | [diff] [blame] | 401 | if (!fsi->info) |
Kuninori Morimoto | d7c5762 | 2011-01-24 10:42:33 +0900 | [diff] [blame] | 402 | return NULL; |
| 403 | |
Kuninori Morimoto | fec691e | 2012-02-03 00:58:48 -0800 | [diff] [blame] | 404 | return fsi->info->set_rate; |
Kuninori Morimoto | d7c5762 | 2011-01-24 10:42:33 +0900 | [diff] [blame] | 405 | } |
| 406 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 407 | static u32 fsi_get_info_flags(struct fsi_priv *fsi) |
| 408 | { |
Kuninori Morimoto | fec691e | 2012-02-03 00:58:48 -0800 | [diff] [blame] | 409 | if (!fsi->info) |
Kuninori Morimoto | d7c5762 | 2011-01-24 10:42:33 +0900 | [diff] [blame] | 410 | return 0; |
| 411 | |
Kuninori Morimoto | fec691e | 2012-02-03 00:58:48 -0800 | [diff] [blame] | 412 | return fsi->info->flags; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 413 | } |
| 414 | |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 415 | 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] | 416 | { |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 417 | int is_play = fsi_stream_is_play(fsi, io); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 418 | int is_porta = fsi_is_port_a(fsi); |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 419 | u32 shift; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 420 | |
| 421 | if (is_porta) |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 422 | shift = is_play ? AO_SHIFT : AI_SHIFT; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 423 | else |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 424 | shift = is_play ? BO_SHIFT : BI_SHIFT; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 425 | |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 426 | return shift; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 427 | } |
| 428 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 429 | static int fsi_frame2sample(struct fsi_priv *fsi, int frames) |
| 430 | { |
| 431 | return frames * fsi->chan_num; |
| 432 | } |
| 433 | |
| 434 | static int fsi_sample2frame(struct fsi_priv *fsi, int samples) |
| 435 | { |
| 436 | return samples / fsi->chan_num; |
| 437 | } |
| 438 | |
Kuninori Morimoto | 7b1b333 | 2012-02-03 00:55:26 -0800 | [diff] [blame] | 439 | static int fsi_get_current_fifo_samples(struct fsi_priv *fsi, |
| 440 | struct fsi_stream *io) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 441 | { |
Kuninori Morimoto | 7b1b333 | 2012-02-03 00:55:26 -0800 | [diff] [blame] | 442 | int is_play = fsi_stream_is_play(fsi, io); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 443 | u32 status; |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 444 | int frames; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 445 | |
Kuninori Morimoto | e8c8b63 | 2010-12-03 17:37:55 +0900 | [diff] [blame] | 446 | status = is_play ? |
| 447 | fsi_reg_read(fsi, DOFF_ST) : |
| 448 | fsi_reg_read(fsi, DIFF_ST); |
| 449 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 450 | frames = 0x1ff & (status >> 8); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 451 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 452 | return fsi_frame2sample(fsi, frames); |
Kuninori Morimoto | cca1b23 | 2010-10-12 11:39:25 +0900 | [diff] [blame] | 453 | } |
| 454 | |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 455 | static void fsi_count_fifo_err(struct fsi_priv *fsi) |
| 456 | { |
| 457 | u32 ostatus = fsi_reg_read(fsi, DOFF_ST); |
| 458 | u32 istatus = fsi_reg_read(fsi, DIFF_ST); |
| 459 | |
| 460 | if (ostatus & ERR_OVER) |
| 461 | fsi->playback.oerr_num++; |
| 462 | |
| 463 | if (ostatus & ERR_UNDER) |
| 464 | fsi->playback.uerr_num++; |
| 465 | |
| 466 | if (istatus & ERR_OVER) |
| 467 | fsi->capture.oerr_num++; |
| 468 | |
| 469 | if (istatus & ERR_UNDER) |
| 470 | fsi->capture.uerr_num++; |
| 471 | |
| 472 | fsi_reg_write(fsi, DOFF_ST, 0); |
| 473 | fsi_reg_write(fsi, DIFF_ST, 0); |
| 474 | } |
| 475 | |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 476 | /* |
Kuninori Morimoto | 4e62d84 | 2012-02-03 00:50:35 -0800 | [diff] [blame] | 477 | * fsi_stream_xx() function |
| 478 | */ |
Kuninori Morimoto | a449e46 | 2012-02-03 00:54:02 -0800 | [diff] [blame] | 479 | static inline int fsi_stream_is_play(struct fsi_priv *fsi, |
| 480 | struct fsi_stream *io) |
Kuninori Morimoto | 4e62d84 | 2012-02-03 00:50:35 -0800 | [diff] [blame] | 481 | { |
Kuninori Morimoto | a449e46 | 2012-02-03 00:54:02 -0800 | [diff] [blame] | 482 | return &fsi->playback == io; |
Kuninori Morimoto | 4e62d84 | 2012-02-03 00:50:35 -0800 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | static inline struct fsi_stream *fsi_stream_get(struct fsi_priv *fsi, |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 486 | struct snd_pcm_substream *substream) |
Kuninori Morimoto | 4e62d84 | 2012-02-03 00:50:35 -0800 | [diff] [blame] | 487 | { |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 488 | return fsi_is_play(substream) ? &fsi->playback : &fsi->capture; |
Kuninori Morimoto | 4e62d84 | 2012-02-03 00:50:35 -0800 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | static int fsi_stream_is_working(struct fsi_priv *fsi, |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 492 | struct fsi_stream *io) |
Kuninori Morimoto | 4e62d84 | 2012-02-03 00:50:35 -0800 | [diff] [blame] | 493 | { |
Kuninori Morimoto | 4e62d84 | 2012-02-03 00:50:35 -0800 | [diff] [blame] | 494 | struct fsi_master *master = fsi_get_master(fsi); |
| 495 | unsigned long flags; |
| 496 | int ret; |
| 497 | |
| 498 | spin_lock_irqsave(&master->lock, flags); |
Kuninori Morimoto | 97df818 | 2012-02-03 00:57:40 -0800 | [diff] [blame] | 499 | ret = !!(io->substream && io->substream->runtime); |
Kuninori Morimoto | 4e62d84 | 2012-02-03 00:50:35 -0800 | [diff] [blame] | 500 | spin_unlock_irqrestore(&master->lock, flags); |
| 501 | |
| 502 | return ret; |
| 503 | } |
| 504 | |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 505 | static struct fsi_priv *fsi_stream_to_priv(struct fsi_stream *io) |
| 506 | { |
| 507 | return io->priv; |
| 508 | } |
| 509 | |
Kuninori Morimoto | 8c41529 | 2012-02-03 00:52:07 -0800 | [diff] [blame] | 510 | static void fsi_stream_init(struct fsi_priv *fsi, |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 511 | struct fsi_stream *io, |
Kuninori Morimoto | 4e62d84 | 2012-02-03 00:50:35 -0800 | [diff] [blame] | 512 | struct snd_pcm_substream *substream) |
| 513 | { |
Kuninori Morimoto | 4e62d84 | 2012-02-03 00:50:35 -0800 | [diff] [blame] | 514 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 515 | struct fsi_master *master = fsi_get_master(fsi); |
| 516 | unsigned long flags; |
| 517 | |
| 518 | spin_lock_irqsave(&master->lock, flags); |
| 519 | io->substream = substream; |
| 520 | io->buff_sample_capa = fsi_frame2sample(fsi, runtime->buffer_size); |
| 521 | io->buff_sample_pos = 0; |
| 522 | io->period_samples = fsi_frame2sample(fsi, runtime->period_size); |
| 523 | io->period_pos = 0; |
| 524 | io->sample_width = samples_to_bytes(runtime, 1); |
Kuninori Morimoto | 766812e | 2012-05-17 17:36:47 -0700 | [diff] [blame] | 525 | io->bus_option = 0; |
Kuninori Morimoto | 4e62d84 | 2012-02-03 00:50:35 -0800 | [diff] [blame] | 526 | io->oerr_num = -1; /* ignore 1st err */ |
| 527 | io->uerr_num = -1; /* ignore 1st err */ |
Kuninori Morimoto | 8334402 | 2012-02-03 00:59:02 -0800 | [diff] [blame] | 528 | fsi_stream_handler_call(io, init, fsi, io); |
Kuninori Morimoto | 4e62d84 | 2012-02-03 00:50:35 -0800 | [diff] [blame] | 529 | spin_unlock_irqrestore(&master->lock, flags); |
| 530 | } |
| 531 | |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 532 | 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] | 533 | { |
Kuninori Morimoto | 4e62d84 | 2012-02-03 00:50:35 -0800 | [diff] [blame] | 534 | struct snd_soc_dai *dai = fsi_get_dai(io->substream); |
| 535 | struct fsi_master *master = fsi_get_master(fsi); |
| 536 | unsigned long flags; |
| 537 | |
| 538 | spin_lock_irqsave(&master->lock, flags); |
| 539 | |
| 540 | if (io->oerr_num > 0) |
| 541 | dev_err(dai->dev, "over_run = %d\n", io->oerr_num); |
| 542 | |
| 543 | if (io->uerr_num > 0) |
| 544 | dev_err(dai->dev, "under_run = %d\n", io->uerr_num); |
| 545 | |
Kuninori Morimoto | 8334402 | 2012-02-03 00:59:02 -0800 | [diff] [blame] | 546 | fsi_stream_handler_call(io, quit, fsi, io); |
Kuninori Morimoto | 4e62d84 | 2012-02-03 00:50:35 -0800 | [diff] [blame] | 547 | io->substream = NULL; |
| 548 | io->buff_sample_capa = 0; |
| 549 | io->buff_sample_pos = 0; |
| 550 | io->period_samples = 0; |
| 551 | io->period_pos = 0; |
| 552 | io->sample_width = 0; |
Kuninori Morimoto | 766812e | 2012-05-17 17:36:47 -0700 | [diff] [blame] | 553 | io->bus_option = 0; |
Kuninori Morimoto | 4e62d84 | 2012-02-03 00:50:35 -0800 | [diff] [blame] | 554 | io->oerr_num = 0; |
| 555 | io->uerr_num = 0; |
| 556 | spin_unlock_irqrestore(&master->lock, flags); |
| 557 | } |
| 558 | |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 559 | static int fsi_stream_transfer(struct fsi_stream *io) |
| 560 | { |
| 561 | struct fsi_priv *fsi = fsi_stream_to_priv(io); |
| 562 | if (!fsi) |
| 563 | return -EIO; |
| 564 | |
| 565 | return fsi_stream_handler_call(io, transfer, fsi, io); |
| 566 | } |
| 567 | |
Kuninori Morimoto | 180346e | 2012-02-03 00:57:25 -0800 | [diff] [blame] | 568 | #define fsi_stream_start(fsi, io)\ |
| 569 | fsi_stream_handler_call(io, start_stop, fsi, io, 1) |
| 570 | |
| 571 | #define fsi_stream_stop(fsi, io)\ |
| 572 | fsi_stream_handler_call(io, start_stop, fsi, io, 0) |
| 573 | |
Kuninori Morimoto | b1226dc | 2012-05-24 23:56:19 -0700 | [diff] [blame^] | 574 | static int fsi_stream_probe(struct fsi_priv *fsi, struct device *dev) |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 575 | { |
| 576 | struct fsi_stream *io; |
| 577 | int ret1, ret2; |
| 578 | |
| 579 | io = &fsi->playback; |
Kuninori Morimoto | b1226dc | 2012-05-24 23:56:19 -0700 | [diff] [blame^] | 580 | ret1 = fsi_stream_handler_call(io, probe, fsi, io, dev); |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 581 | |
| 582 | io = &fsi->capture; |
Kuninori Morimoto | b1226dc | 2012-05-24 23:56:19 -0700 | [diff] [blame^] | 583 | ret2 = fsi_stream_handler_call(io, probe, fsi, io, dev); |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 584 | |
| 585 | if (ret1 < 0) |
| 586 | return ret1; |
| 587 | if (ret2 < 0) |
| 588 | return ret2; |
| 589 | |
| 590 | return 0; |
| 591 | } |
| 592 | |
| 593 | static int fsi_stream_remove(struct fsi_priv *fsi) |
| 594 | { |
| 595 | struct fsi_stream *io; |
| 596 | int ret1, ret2; |
| 597 | |
| 598 | io = &fsi->playback; |
| 599 | ret1 = fsi_stream_handler_call(io, remove, fsi, io); |
| 600 | |
| 601 | io = &fsi->capture; |
| 602 | ret2 = fsi_stream_handler_call(io, remove, fsi, io); |
| 603 | |
| 604 | if (ret1 < 0) |
| 605 | return ret1; |
| 606 | if (ret2 < 0) |
| 607 | return ret2; |
| 608 | |
| 609 | return 0; |
| 610 | } |
| 611 | |
Kuninori Morimoto | 4e62d84 | 2012-02-03 00:50:35 -0800 | [diff] [blame] | 612 | /* |
Kuninori Morimoto | 766812e | 2012-05-17 17:36:47 -0700 | [diff] [blame] | 613 | * format/bus/dma setting |
| 614 | */ |
| 615 | static void fsi_format_bus_setup(struct fsi_priv *fsi, struct fsi_stream *io, |
| 616 | u32 bus, struct device *dev) |
| 617 | { |
| 618 | struct fsi_master *master = fsi_get_master(fsi); |
| 619 | int is_play = fsi_stream_is_play(fsi, io); |
| 620 | u32 fmt = fsi->fmt; |
| 621 | |
| 622 | if (fsi_version(master) >= 2) { |
| 623 | u32 dma = 0; |
| 624 | |
| 625 | /* |
| 626 | * FSI2 needs DMA/Bus setting |
| 627 | */ |
| 628 | switch (bus) { |
| 629 | case PACKAGE_24BITBUS_FRONT: |
| 630 | fmt |= CR_BWS_24; |
| 631 | dma |= VDMD_FRONT; |
| 632 | dev_dbg(dev, "24bit bus / package in front\n"); |
| 633 | break; |
| 634 | case PACKAGE_16BITBUS_STREAM: |
| 635 | fmt |= CR_BWS_16; |
| 636 | dma |= VDMD_STREAM; |
| 637 | dev_dbg(dev, "16bit bus / stream mode\n"); |
| 638 | break; |
| 639 | case PACKAGE_24BITBUS_BACK: |
| 640 | default: |
| 641 | fmt |= CR_BWS_24; |
| 642 | dma |= VDMD_BACK; |
| 643 | dev_dbg(dev, "24bit bus / package in back\n"); |
| 644 | break; |
| 645 | } |
| 646 | |
| 647 | if (is_play) |
| 648 | fsi_reg_write(fsi, OUT_DMAC, dma); |
| 649 | else |
| 650 | fsi_reg_write(fsi, IN_DMAC, dma); |
| 651 | } |
| 652 | |
| 653 | if (is_play) |
| 654 | fsi_reg_write(fsi, DO_FMT, fmt); |
| 655 | else |
| 656 | fsi_reg_write(fsi, DI_FMT, fmt); |
| 657 | } |
| 658 | |
| 659 | /* |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 660 | * irq function |
| 661 | */ |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 662 | |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 663 | 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] | 664 | { |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 665 | u32 data = AB_IO(1, fsi_get_port_shift(fsi, io)); |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 666 | struct fsi_master *master = fsi_get_master(fsi); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 667 | |
Kuninori Morimoto | 43fa95c | 2010-12-03 17:38:03 +0900 | [diff] [blame] | 668 | fsi_core_mask_set(master, imsk, data, data); |
| 669 | fsi_core_mask_set(master, iemsk, data, data); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 670 | } |
| 671 | |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 672 | 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] | 673 | { |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 674 | u32 data = AB_IO(1, fsi_get_port_shift(fsi, io)); |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 675 | struct fsi_master *master = fsi_get_master(fsi); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 676 | |
Kuninori Morimoto | 43fa95c | 2010-12-03 17:38:03 +0900 | [diff] [blame] | 677 | fsi_core_mask_set(master, imsk, data, 0); |
| 678 | fsi_core_mask_set(master, iemsk, data, 0); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 679 | } |
| 680 | |
Kuninori Morimoto | 10ea76c | 2010-03-23 11:47:54 +0900 | [diff] [blame] | 681 | static u32 fsi_irq_get_status(struct fsi_master *master) |
| 682 | { |
Kuninori Morimoto | 43fa95c | 2010-12-03 17:38:03 +0900 | [diff] [blame] | 683 | return fsi_core_read(master, int_st); |
Kuninori Morimoto | 10ea76c | 2010-03-23 11:47:54 +0900 | [diff] [blame] | 684 | } |
| 685 | |
Kuninori Morimoto | 10ea76c | 2010-03-23 11:47:54 +0900 | [diff] [blame] | 686 | static void fsi_irq_clear_status(struct fsi_priv *fsi) |
| 687 | { |
| 688 | u32 data = 0; |
| 689 | struct fsi_master *master = fsi_get_master(fsi); |
| 690 | |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 691 | data |= AB_IO(1, fsi_get_port_shift(fsi, &fsi->playback)); |
| 692 | data |= AB_IO(1, fsi_get_port_shift(fsi, &fsi->capture)); |
Kuninori Morimoto | 10ea76c | 2010-03-23 11:47:54 +0900 | [diff] [blame] | 693 | |
| 694 | /* clear interrupt factor */ |
Kuninori Morimoto | 43fa95c | 2010-12-03 17:38:03 +0900 | [diff] [blame] | 695 | fsi_core_mask_set(master, int_st, data, 0); |
Kuninori Morimoto | 10ea76c | 2010-03-23 11:47:54 +0900 | [diff] [blame] | 696 | } |
| 697 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 698 | /* |
| 699 | * SPDIF master clock function |
| 700 | * |
| 701 | * These functions are used later FSI2 |
| 702 | */ |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 703 | static void fsi_spdif_clk_ctrl(struct fsi_priv *fsi, int enable) |
| 704 | { |
| 705 | struct fsi_master *master = fsi_get_master(fsi); |
Kuninori Morimoto | 2b0e730 | 2010-12-03 17:37:44 +0900 | [diff] [blame] | 706 | u32 mask, val; |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 707 | |
Kuninori Morimoto | 2b0e730 | 2010-12-03 17:37:44 +0900 | [diff] [blame] | 708 | mask = BP | SE; |
| 709 | val = enable ? mask : 0; |
| 710 | |
| 711 | fsi_is_port_a(fsi) ? |
Kuninori Morimoto | 43fa95c | 2010-12-03 17:38:03 +0900 | [diff] [blame] | 712 | fsi_core_mask_set(master, a_mclk, mask, val) : |
| 713 | fsi_core_mask_set(master, b_mclk, mask, val); |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 714 | } |
| 715 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 716 | /* |
Kuninori Morimoto | 1f5e2a3 | 2011-04-21 10:33:52 +0900 | [diff] [blame] | 717 | * clock function |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 718 | */ |
Kuninori Morimoto | 4f56cde | 2011-05-23 20:46:18 +0900 | [diff] [blame] | 719 | static int fsi_set_master_clk(struct device *dev, struct fsi_priv *fsi, |
| 720 | long rate, int enable) |
| 721 | { |
Kuninori Morimoto | fec691e | 2012-02-03 00:58:48 -0800 | [diff] [blame] | 722 | set_rate_func set_rate = fsi_get_info_set_rate(fsi); |
Kuninori Morimoto | 4f56cde | 2011-05-23 20:46:18 +0900 | [diff] [blame] | 723 | int ret; |
| 724 | |
Kuninori Morimoto | fec691e | 2012-02-03 00:58:48 -0800 | [diff] [blame] | 725 | if (!set_rate) |
| 726 | return 0; |
| 727 | |
| 728 | ret = set_rate(dev, rate, enable); |
Kuninori Morimoto | 4f56cde | 2011-05-23 20:46:18 +0900 | [diff] [blame] | 729 | if (ret < 0) /* error */ |
| 730 | return ret; |
| 731 | |
| 732 | if (!enable) |
| 733 | return 0; |
| 734 | |
| 735 | if (ret > 0) { |
| 736 | u32 data = 0; |
| 737 | |
| 738 | switch (ret & SH_FSI_ACKMD_MASK) { |
| 739 | default: |
| 740 | /* FALL THROUGH */ |
| 741 | case SH_FSI_ACKMD_512: |
| 742 | data |= (0x0 << 12); |
| 743 | break; |
| 744 | case SH_FSI_ACKMD_256: |
| 745 | data |= (0x1 << 12); |
| 746 | break; |
| 747 | case SH_FSI_ACKMD_128: |
| 748 | data |= (0x2 << 12); |
| 749 | break; |
| 750 | case SH_FSI_ACKMD_64: |
| 751 | data |= (0x3 << 12); |
| 752 | break; |
| 753 | case SH_FSI_ACKMD_32: |
Kuninori Morimoto | 284c6f6 | 2012-05-17 17:34:16 -0700 | [diff] [blame] | 754 | data |= (0x4 << 12); |
Kuninori Morimoto | 4f56cde | 2011-05-23 20:46:18 +0900 | [diff] [blame] | 755 | break; |
| 756 | } |
| 757 | |
| 758 | switch (ret & SH_FSI_BPFMD_MASK) { |
| 759 | default: |
| 760 | /* FALL THROUGH */ |
| 761 | case SH_FSI_BPFMD_32: |
| 762 | data |= (0x0 << 8); |
| 763 | break; |
| 764 | case SH_FSI_BPFMD_64: |
| 765 | data |= (0x1 << 8); |
| 766 | break; |
| 767 | case SH_FSI_BPFMD_128: |
| 768 | data |= (0x2 << 8); |
| 769 | break; |
| 770 | case SH_FSI_BPFMD_256: |
| 771 | data |= (0x3 << 8); |
| 772 | break; |
| 773 | case SH_FSI_BPFMD_512: |
| 774 | data |= (0x4 << 8); |
| 775 | break; |
| 776 | case SH_FSI_BPFMD_16: |
Kuninori Morimoto | 284c6f6 | 2012-05-17 17:34:16 -0700 | [diff] [blame] | 777 | data |= (0x7 << 8); |
Kuninori Morimoto | 4f56cde | 2011-05-23 20:46:18 +0900 | [diff] [blame] | 778 | break; |
| 779 | } |
| 780 | |
| 781 | fsi_reg_mask_set(fsi, CKG1, (ACKMD_MASK | BPFMD_MASK) , data); |
| 782 | udelay(10); |
| 783 | ret = 0; |
| 784 | } |
| 785 | |
| 786 | return ret; |
Kuninori Morimoto | 4f56cde | 2011-05-23 20:46:18 +0900 | [diff] [blame] | 787 | } |
| 788 | |
Kuninori Morimoto | 1f5e2a3 | 2011-04-21 10:33:52 +0900 | [diff] [blame] | 789 | /* |
Kuninori Morimoto | 1b0ca1a | 2012-02-03 00:56:27 -0800 | [diff] [blame] | 790 | * pio data transfer handler |
Kuninori Morimoto | 1f5e2a3 | 2011-04-21 10:33:52 +0900 | [diff] [blame] | 791 | */ |
Kuninori Morimoto | 1b0ca1a | 2012-02-03 00:56:27 -0800 | [diff] [blame] | 792 | static void fsi_pio_push16(struct fsi_priv *fsi, u8 *_buf, int samples) |
| 793 | { |
Kuninori Morimoto | 766812e | 2012-05-17 17:36:47 -0700 | [diff] [blame] | 794 | u32 enable_stream = fsi_get_info_flags(fsi) & SH_FSI_ENABLE_STREAM_MODE; |
Kuninori Morimoto | 1b0ca1a | 2012-02-03 00:56:27 -0800 | [diff] [blame] | 795 | int i; |
| 796 | |
Kuninori Morimoto | 766812e | 2012-05-17 17:36:47 -0700 | [diff] [blame] | 797 | if (enable_stream) { |
| 798 | /* |
| 799 | * stream mode |
| 800 | * see |
| 801 | * fsi_pio_push_init() |
| 802 | */ |
| 803 | u32 *buf = (u32 *)_buf; |
| 804 | |
| 805 | for (i = 0; i < samples / 2; i++) |
| 806 | fsi_reg_write(fsi, DODT, buf[i]); |
| 807 | } else { |
| 808 | /* normal mode */ |
| 809 | u16 *buf = (u16 *)_buf; |
| 810 | |
| 811 | for (i = 0; i < samples; i++) |
| 812 | fsi_reg_write(fsi, DODT, ((u32)*(buf + i) << 8)); |
| 813 | } |
Kuninori Morimoto | 1b0ca1a | 2012-02-03 00:56:27 -0800 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | static void fsi_pio_pop16(struct fsi_priv *fsi, u8 *_buf, int samples) |
| 817 | { |
| 818 | u16 *buf = (u16 *)_buf; |
| 819 | int i; |
| 820 | |
| 821 | for (i = 0; i < samples; i++) |
| 822 | *(buf + i) = (u16)(fsi_reg_read(fsi, DIDT) >> 8); |
| 823 | } |
| 824 | |
| 825 | static void fsi_pio_push32(struct fsi_priv *fsi, u8 *_buf, int samples) |
| 826 | { |
| 827 | u32 *buf = (u32 *)_buf; |
| 828 | int i; |
| 829 | |
| 830 | for (i = 0; i < samples; i++) |
| 831 | fsi_reg_write(fsi, DODT, *(buf + i)); |
| 832 | } |
| 833 | |
| 834 | static void fsi_pio_pop32(struct fsi_priv *fsi, u8 *_buf, int samples) |
| 835 | { |
| 836 | u32 *buf = (u32 *)_buf; |
| 837 | int i; |
| 838 | |
| 839 | for (i = 0; i < samples; i++) |
| 840 | *(buf + i) = fsi_reg_read(fsi, DIDT); |
| 841 | } |
| 842 | |
| 843 | static u8 *fsi_pio_get_area(struct fsi_priv *fsi, struct fsi_stream *io) |
| 844 | { |
| 845 | struct snd_pcm_runtime *runtime = io->substream->runtime; |
| 846 | |
| 847 | return runtime->dma_area + |
| 848 | samples_to_bytes(runtime, io->buff_sample_pos); |
| 849 | } |
| 850 | |
| 851 | 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] | 852 | void (*run16)(struct fsi_priv *fsi, u8 *buf, int samples), |
| 853 | void (*run32)(struct fsi_priv *fsi, u8 *buf, int samples), |
| 854 | int samples) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 855 | { |
| 856 | struct snd_pcm_runtime *runtime; |
Kuninori Morimoto | 376cf38 | 2012-02-03 00:50:59 -0800 | [diff] [blame] | 857 | struct snd_pcm_substream *substream; |
Kuninori Morimoto | 95b0cf0 | 2012-02-03 00:52:38 -0800 | [diff] [blame] | 858 | u8 *buf; |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 859 | int over_period; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 860 | |
Kuninori Morimoto | 97df818 | 2012-02-03 00:57:40 -0800 | [diff] [blame] | 861 | if (!fsi_stream_is_working(fsi, io)) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 862 | return -EINVAL; |
| 863 | |
Kuninori Morimoto | 1c418d1 | 2009-12-28 14:09:05 +0900 | [diff] [blame] | 864 | over_period = 0; |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 865 | substream = io->substream; |
Kuninori Morimoto | 1c418d1 | 2009-12-28 14:09:05 +0900 | [diff] [blame] | 866 | runtime = substream->runtime; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 867 | |
| 868 | /* FSI FIFO has limit. |
| 869 | * So, this driver can not send periods data at a time |
| 870 | */ |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 871 | if (io->buff_sample_pos >= |
| 872 | io->period_samples * (io->period_pos + 1)) { |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 873 | |
Kuninori Morimoto | 1c418d1 | 2009-12-28 14:09:05 +0900 | [diff] [blame] | 874 | over_period = 1; |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 875 | io->period_pos = (io->period_pos + 1) % runtime->periods; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 876 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 877 | if (0 == io->period_pos) |
| 878 | io->buff_sample_pos = 0; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 879 | } |
| 880 | |
Kuninori Morimoto | 95b0cf0 | 2012-02-03 00:52:38 -0800 | [diff] [blame] | 881 | buf = fsi_pio_get_area(fsi, io); |
| 882 | |
Kuninori Morimoto | 376cf38 | 2012-02-03 00:50:59 -0800 | [diff] [blame] | 883 | switch (io->sample_width) { |
| 884 | case 2: |
Kuninori Morimoto | 95b0cf0 | 2012-02-03 00:52:38 -0800 | [diff] [blame] | 885 | run16(fsi, buf, samples); |
Kuninori Morimoto | 376cf38 | 2012-02-03 00:50:59 -0800 | [diff] [blame] | 886 | break; |
| 887 | case 4: |
Kuninori Morimoto | 95b0cf0 | 2012-02-03 00:52:38 -0800 | [diff] [blame] | 888 | run32(fsi, buf, samples); |
Kuninori Morimoto | 376cf38 | 2012-02-03 00:50:59 -0800 | [diff] [blame] | 889 | break; |
| 890 | default: |
| 891 | return -EINVAL; |
Kuninori Morimoto | 9ddc9aa | 2009-10-30 12:02:39 +0900 | [diff] [blame] | 892 | } |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 893 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 894 | /* update buff_sample_pos */ |
| 895 | io->buff_sample_pos += samples; |
Kuninori Morimoto | d8b3353 | 2010-09-17 13:49:05 +0900 | [diff] [blame] | 896 | |
Kuninori Morimoto | 1c418d1 | 2009-12-28 14:09:05 +0900 | [diff] [blame] | 897 | if (over_period) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 898 | snd_pcm_period_elapsed(substream); |
| 899 | |
Kuninori Morimoto | 47fc9a0 | 2010-02-22 16:41:57 +0900 | [diff] [blame] | 900 | return 0; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 901 | } |
| 902 | |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 903 | 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] | 904 | { |
Kuninori Morimoto | 376cf38 | 2012-02-03 00:50:59 -0800 | [diff] [blame] | 905 | int sample_residues; /* samples in FSI fifo */ |
| 906 | int sample_space; /* ALSA free samples space */ |
| 907 | int samples; |
Kuninori Morimoto | 376cf38 | 2012-02-03 00:50:59 -0800 | [diff] [blame] | 908 | |
Kuninori Morimoto | 7b1b333 | 2012-02-03 00:55:26 -0800 | [diff] [blame] | 909 | sample_residues = fsi_get_current_fifo_samples(fsi, io); |
Kuninori Morimoto | 376cf38 | 2012-02-03 00:50:59 -0800 | [diff] [blame] | 910 | sample_space = io->buff_sample_capa - io->buff_sample_pos; |
| 911 | |
| 912 | samples = min(sample_residues, sample_space); |
| 913 | |
Kuninori Morimoto | 1b0ca1a | 2012-02-03 00:56:27 -0800 | [diff] [blame] | 914 | return fsi_pio_transfer(fsi, io, |
Kuninori Morimoto | d78629e | 2012-02-03 00:51:14 -0800 | [diff] [blame] | 915 | fsi_pio_pop16, |
| 916 | fsi_pio_pop32, |
Kuninori Morimoto | 376cf38 | 2012-02-03 00:50:59 -0800 | [diff] [blame] | 917 | samples); |
Kuninori Morimoto | d8b3353 | 2010-09-17 13:49:05 +0900 | [diff] [blame] | 918 | } |
Kuninori Morimoto | 07102f3 | 2009-10-30 12:02:44 +0900 | [diff] [blame] | 919 | |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 920 | 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] | 921 | { |
Kuninori Morimoto | 376cf38 | 2012-02-03 00:50:59 -0800 | [diff] [blame] | 922 | int sample_residues; /* ALSA residue samples */ |
| 923 | int sample_space; /* FSI fifo free samples space */ |
| 924 | int samples; |
Kuninori Morimoto | 376cf38 | 2012-02-03 00:50:59 -0800 | [diff] [blame] | 925 | |
| 926 | sample_residues = io->buff_sample_capa - io->buff_sample_pos; |
| 927 | sample_space = io->fifo_sample_capa - |
Kuninori Morimoto | 7b1b333 | 2012-02-03 00:55:26 -0800 | [diff] [blame] | 928 | fsi_get_current_fifo_samples(fsi, io); |
Kuninori Morimoto | 376cf38 | 2012-02-03 00:50:59 -0800 | [diff] [blame] | 929 | |
| 930 | samples = min(sample_residues, sample_space); |
| 931 | |
Kuninori Morimoto | 1b0ca1a | 2012-02-03 00:56:27 -0800 | [diff] [blame] | 932 | return fsi_pio_transfer(fsi, io, |
Kuninori Morimoto | d78629e | 2012-02-03 00:51:14 -0800 | [diff] [blame] | 933 | fsi_pio_push16, |
| 934 | fsi_pio_push32, |
Kuninori Morimoto | 376cf38 | 2012-02-03 00:50:59 -0800 | [diff] [blame] | 935 | samples); |
Kuninori Morimoto | 07102f3 | 2009-10-30 12:02:44 +0900 | [diff] [blame] | 936 | } |
| 937 | |
Kuninori Morimoto | 180346e | 2012-02-03 00:57:25 -0800 | [diff] [blame] | 938 | static void fsi_pio_start_stop(struct fsi_priv *fsi, struct fsi_stream *io, |
| 939 | int enable) |
| 940 | { |
| 941 | struct fsi_master *master = fsi_get_master(fsi); |
| 942 | u32 clk = fsi_is_port_a(fsi) ? CRA : CRB; |
| 943 | |
| 944 | if (enable) |
| 945 | fsi_irq_enable(fsi, io); |
| 946 | else |
| 947 | fsi_irq_disable(fsi, io); |
| 948 | |
| 949 | if (fsi_is_clk_master(fsi)) |
| 950 | fsi_master_mask_set(master, CLK_RST, clk, (enable) ? clk : 0); |
| 951 | } |
| 952 | |
Kuninori Morimoto | 766812e | 2012-05-17 17:36:47 -0700 | [diff] [blame] | 953 | static int fsi_pio_push_init(struct fsi_priv *fsi, struct fsi_stream *io) |
| 954 | { |
| 955 | u32 enable_stream = fsi_get_info_flags(fsi) & SH_FSI_ENABLE_STREAM_MODE; |
| 956 | |
| 957 | /* |
| 958 | * we can use 16bit stream mode |
| 959 | * when "playback" and "16bit data" |
| 960 | * and platform allows "stream mode" |
| 961 | * see |
| 962 | * fsi_pio_push16() |
| 963 | */ |
| 964 | if (enable_stream) |
| 965 | io->bus_option = BUSOP_SET(24, PACKAGE_24BITBUS_BACK) | |
| 966 | BUSOP_SET(16, PACKAGE_16BITBUS_STREAM); |
| 967 | else |
| 968 | io->bus_option = BUSOP_SET(24, PACKAGE_24BITBUS_BACK) | |
| 969 | BUSOP_SET(16, PACKAGE_24BITBUS_BACK); |
| 970 | return 0; |
| 971 | } |
| 972 | |
| 973 | static int fsi_pio_pop_init(struct fsi_priv *fsi, struct fsi_stream *io) |
| 974 | { |
| 975 | /* |
| 976 | * always 24bit bus, package back when "capture" |
| 977 | */ |
| 978 | io->bus_option = BUSOP_SET(24, PACKAGE_24BITBUS_BACK) | |
| 979 | BUSOP_SET(16, PACKAGE_24BITBUS_BACK); |
| 980 | return 0; |
| 981 | } |
| 982 | |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 983 | static struct fsi_stream_handler fsi_pio_push_handler = { |
Kuninori Morimoto | 766812e | 2012-05-17 17:36:47 -0700 | [diff] [blame] | 984 | .init = fsi_pio_push_init, |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 985 | .transfer = fsi_pio_push, |
Kuninori Morimoto | 180346e | 2012-02-03 00:57:25 -0800 | [diff] [blame] | 986 | .start_stop = fsi_pio_start_stop, |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 987 | }; |
| 988 | |
| 989 | static struct fsi_stream_handler fsi_pio_pop_handler = { |
Kuninori Morimoto | 766812e | 2012-05-17 17:36:47 -0700 | [diff] [blame] | 990 | .init = fsi_pio_pop_init, |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 991 | .transfer = fsi_pio_pop, |
Kuninori Morimoto | 180346e | 2012-02-03 00:57:25 -0800 | [diff] [blame] | 992 | .start_stop = fsi_pio_start_stop, |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 993 | }; |
| 994 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 995 | static irqreturn_t fsi_interrupt(int irq, void *data) |
| 996 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 997 | struct fsi_master *master = data; |
Kuninori Morimoto | 10ea76c | 2010-03-23 11:47:54 +0900 | [diff] [blame] | 998 | u32 int_st = fsi_irq_get_status(master); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 999 | |
| 1000 | /* clear irq status */ |
Kuninori Morimoto | feb58cf | 2010-03-24 15:27:24 +0900 | [diff] [blame] | 1001 | fsi_master_mask_set(master, SOFT_RST, IR, 0); |
| 1002 | fsi_master_mask_set(master, SOFT_RST, IR, IR); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1003 | |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 1004 | if (int_st & AB_IO(1, AO_SHIFT)) |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 1005 | fsi_stream_transfer(&master->fsia.playback); |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 1006 | if (int_st & AB_IO(1, BO_SHIFT)) |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 1007 | fsi_stream_transfer(&master->fsib.playback); |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 1008 | if (int_st & AB_IO(1, AI_SHIFT)) |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 1009 | fsi_stream_transfer(&master->fsia.capture); |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 1010 | if (int_st & AB_IO(1, BI_SHIFT)) |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 1011 | fsi_stream_transfer(&master->fsib.capture); |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 1012 | |
| 1013 | fsi_count_fifo_err(&master->fsia); |
| 1014 | fsi_count_fifo_err(&master->fsib); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1015 | |
Kuninori Morimoto | 48d78e5 | 2010-12-03 17:37:31 +0900 | [diff] [blame] | 1016 | fsi_irq_clear_status(&master->fsia); |
| 1017 | fsi_irq_clear_status(&master->fsib); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1018 | |
| 1019 | return IRQ_HANDLED; |
| 1020 | } |
| 1021 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 1022 | /* |
Kuninori Morimoto | 7da9ced | 2012-02-03 00:59:33 -0800 | [diff] [blame] | 1023 | * dma data transfer handler |
| 1024 | */ |
| 1025 | static int fsi_dma_init(struct fsi_priv *fsi, struct fsi_stream *io) |
| 1026 | { |
| 1027 | struct snd_pcm_runtime *runtime = io->substream->runtime; |
| 1028 | struct snd_soc_dai *dai = fsi_get_dai(io->substream); |
| 1029 | enum dma_data_direction dir = fsi_stream_is_play(fsi, io) ? |
| 1030 | DMA_TO_DEVICE : DMA_FROM_DEVICE; |
| 1031 | |
Kuninori Morimoto | 766812e | 2012-05-17 17:36:47 -0700 | [diff] [blame] | 1032 | /* |
| 1033 | * 24bit data : 24bit bus / package in back |
| 1034 | * 16bit data : 16bit bus / stream mode |
| 1035 | */ |
| 1036 | io->bus_option = BUSOP_SET(24, PACKAGE_24BITBUS_BACK) | |
| 1037 | BUSOP_SET(16, PACKAGE_16BITBUS_STREAM); |
| 1038 | |
Kuninori Morimoto | 7da9ced | 2012-02-03 00:59:33 -0800 | [diff] [blame] | 1039 | io->dma = dma_map_single(dai->dev, runtime->dma_area, |
| 1040 | snd_pcm_lib_buffer_bytes(io->substream), dir); |
| 1041 | return 0; |
| 1042 | } |
| 1043 | |
| 1044 | static int fsi_dma_quit(struct fsi_priv *fsi, struct fsi_stream *io) |
| 1045 | { |
| 1046 | struct snd_soc_dai *dai = fsi_get_dai(io->substream); |
| 1047 | enum dma_data_direction dir = fsi_stream_is_play(fsi, io) ? |
| 1048 | DMA_TO_DEVICE : DMA_FROM_DEVICE; |
| 1049 | |
| 1050 | dma_unmap_single(dai->dev, io->dma, |
| 1051 | snd_pcm_lib_buffer_bytes(io->substream), dir); |
| 1052 | return 0; |
| 1053 | } |
| 1054 | |
Kuninori Morimoto | 4a1b09b | 2012-05-28 23:27:49 -0700 | [diff] [blame] | 1055 | static dma_addr_t fsi_dma_get_area(struct fsi_stream *io) |
| 1056 | { |
| 1057 | struct snd_pcm_runtime *runtime = io->substream->runtime; |
| 1058 | |
| 1059 | return io->dma + samples_to_bytes(runtime, io->buff_sample_pos); |
| 1060 | } |
| 1061 | |
Kuninori Morimoto | 7da9ced | 2012-02-03 00:59:33 -0800 | [diff] [blame] | 1062 | static void fsi_dma_complete(void *data) |
| 1063 | { |
| 1064 | struct fsi_stream *io = (struct fsi_stream *)data; |
| 1065 | struct fsi_priv *fsi = fsi_stream_to_priv(io); |
| 1066 | struct snd_pcm_runtime *runtime = io->substream->runtime; |
| 1067 | struct snd_soc_dai *dai = fsi_get_dai(io->substream); |
| 1068 | enum dma_data_direction dir = fsi_stream_is_play(fsi, io) ? |
| 1069 | DMA_TO_DEVICE : DMA_FROM_DEVICE; |
| 1070 | |
Kuninori Morimoto | 4a1b09b | 2012-05-28 23:27:49 -0700 | [diff] [blame] | 1071 | dma_sync_single_for_cpu(dai->dev, fsi_dma_get_area(io), |
Kuninori Morimoto | 7da9ced | 2012-02-03 00:59:33 -0800 | [diff] [blame] | 1072 | samples_to_bytes(runtime, io->period_samples), dir); |
| 1073 | |
| 1074 | io->buff_sample_pos += io->period_samples; |
| 1075 | io->period_pos++; |
| 1076 | |
| 1077 | if (io->period_pos >= runtime->periods) { |
| 1078 | io->period_pos = 0; |
| 1079 | io->buff_sample_pos = 0; |
| 1080 | } |
| 1081 | |
| 1082 | fsi_count_fifo_err(fsi); |
| 1083 | fsi_stream_transfer(io); |
| 1084 | |
| 1085 | snd_pcm_period_elapsed(io->substream); |
| 1086 | } |
| 1087 | |
Kuninori Morimoto | 7da9ced | 2012-02-03 00:59:33 -0800 | [diff] [blame] | 1088 | static void fsi_dma_do_tasklet(unsigned long data) |
| 1089 | { |
| 1090 | struct fsi_stream *io = (struct fsi_stream *)data; |
| 1091 | struct fsi_priv *fsi = fsi_stream_to_priv(io); |
Kuninori Morimoto | 7da9ced | 2012-02-03 00:59:33 -0800 | [diff] [blame] | 1092 | struct snd_soc_dai *dai; |
| 1093 | struct dma_async_tx_descriptor *desc; |
Kuninori Morimoto | 7da9ced | 2012-02-03 00:59:33 -0800 | [diff] [blame] | 1094 | struct snd_pcm_runtime *runtime; |
| 1095 | enum dma_data_direction dir; |
Kuninori Morimoto | 7da9ced | 2012-02-03 00:59:33 -0800 | [diff] [blame] | 1096 | int is_play = fsi_stream_is_play(fsi, io); |
| 1097 | int len; |
| 1098 | dma_addr_t buf; |
| 1099 | |
| 1100 | if (!fsi_stream_is_working(fsi, io)) |
| 1101 | return; |
| 1102 | |
| 1103 | dai = fsi_get_dai(io->substream); |
Kuninori Morimoto | 7da9ced | 2012-02-03 00:59:33 -0800 | [diff] [blame] | 1104 | runtime = io->substream->runtime; |
| 1105 | dir = is_play ? DMA_TO_DEVICE : DMA_FROM_DEVICE; |
| 1106 | len = samples_to_bytes(runtime, io->period_samples); |
| 1107 | buf = fsi_dma_get_area(io); |
| 1108 | |
Kuninori Morimoto | 4a1b09b | 2012-05-28 23:27:49 -0700 | [diff] [blame] | 1109 | dma_sync_single_for_device(dai->dev, buf, len, dir); |
Kuninori Morimoto | 7da9ced | 2012-02-03 00:59:33 -0800 | [diff] [blame] | 1110 | |
Kuninori Morimoto | 5514efd | 2012-05-28 23:29:36 -0700 | [diff] [blame] | 1111 | desc = dmaengine_prep_slave_single(io->chan, buf, len, dir, |
| 1112 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
Kuninori Morimoto | 7da9ced | 2012-02-03 00:59:33 -0800 | [diff] [blame] | 1113 | if (!desc) { |
Paul Mundt | cdf27f3 | 2012-04-17 19:13:04 -0700 | [diff] [blame] | 1114 | dev_err(dai->dev, "dmaengine_prep_slave_sg() fail\n"); |
Kuninori Morimoto | 7da9ced | 2012-02-03 00:59:33 -0800 | [diff] [blame] | 1115 | return; |
| 1116 | } |
| 1117 | |
| 1118 | desc->callback = fsi_dma_complete; |
| 1119 | desc->callback_param = io; |
| 1120 | |
Kuninori Morimoto | 5514efd | 2012-05-28 23:29:36 -0700 | [diff] [blame] | 1121 | if (dmaengine_submit(desc) < 0) { |
Kuninori Morimoto | 7da9ced | 2012-02-03 00:59:33 -0800 | [diff] [blame] | 1122 | dev_err(dai->dev, "tx_submit() fail\n"); |
| 1123 | return; |
| 1124 | } |
| 1125 | |
Kuninori Morimoto | 5514efd | 2012-05-28 23:29:36 -0700 | [diff] [blame] | 1126 | dma_async_issue_pending(io->chan); |
Kuninori Morimoto | 7da9ced | 2012-02-03 00:59:33 -0800 | [diff] [blame] | 1127 | |
| 1128 | /* |
| 1129 | * FIXME |
| 1130 | * |
| 1131 | * In DMAEngine case, codec and FSI cannot be started simultaneously |
| 1132 | * since FSI is using tasklet. |
| 1133 | * Therefore, in capture case, probably FSI FIFO will have got |
| 1134 | * overflow error in this point. |
| 1135 | * in that case, DMA cannot start transfer until error was cleared. |
| 1136 | */ |
| 1137 | if (!is_play) { |
| 1138 | if (ERR_OVER & fsi_reg_read(fsi, DIFF_ST)) { |
| 1139 | fsi_reg_mask_set(fsi, DIFF_CTL, FIFO_CLR, FIFO_CLR); |
| 1140 | fsi_reg_write(fsi, DIFF_ST, 0); |
| 1141 | } |
| 1142 | } |
| 1143 | } |
| 1144 | |
| 1145 | static bool fsi_dma_filter(struct dma_chan *chan, void *param) |
| 1146 | { |
| 1147 | struct sh_dmae_slave *slave = param; |
| 1148 | |
| 1149 | chan->private = slave; |
| 1150 | |
| 1151 | return true; |
| 1152 | } |
| 1153 | |
| 1154 | static int fsi_dma_transfer(struct fsi_priv *fsi, struct fsi_stream *io) |
| 1155 | { |
| 1156 | tasklet_schedule(&io->tasklet); |
| 1157 | |
| 1158 | return 0; |
| 1159 | } |
| 1160 | |
| 1161 | static void fsi_dma_push_start_stop(struct fsi_priv *fsi, struct fsi_stream *io, |
| 1162 | int start) |
| 1163 | { |
Kuninori Morimoto | e42bb9b | 2012-05-24 23:55:11 -0700 | [diff] [blame] | 1164 | struct fsi_master *master = fsi_get_master(fsi); |
| 1165 | u32 clk = fsi_is_port_a(fsi) ? CRA : CRB; |
Kuninori Morimoto | 766812e | 2012-05-17 17:36:47 -0700 | [diff] [blame] | 1166 | u32 enable = start ? DMA_ON : 0; |
Kuninori Morimoto | 7da9ced | 2012-02-03 00:59:33 -0800 | [diff] [blame] | 1167 | |
Kuninori Morimoto | 766812e | 2012-05-17 17:36:47 -0700 | [diff] [blame] | 1168 | fsi_reg_mask_set(fsi, OUT_DMAC, DMA_ON, enable); |
Kuninori Morimoto | e42bb9b | 2012-05-24 23:55:11 -0700 | [diff] [blame] | 1169 | |
Kuninori Morimoto | fbe42f6 | 2012-05-28 23:28:22 -0700 | [diff] [blame] | 1170 | dmaengine_terminate_all(io->chan); |
| 1171 | |
Kuninori Morimoto | e42bb9b | 2012-05-24 23:55:11 -0700 | [diff] [blame] | 1172 | if (fsi_is_clk_master(fsi)) |
| 1173 | fsi_master_mask_set(master, CLK_RST, clk, (enable) ? clk : 0); |
Kuninori Morimoto | 7da9ced | 2012-02-03 00:59:33 -0800 | [diff] [blame] | 1174 | } |
| 1175 | |
Kuninori Morimoto | b1226dc | 2012-05-24 23:56:19 -0700 | [diff] [blame^] | 1176 | static int fsi_dma_probe(struct fsi_priv *fsi, struct fsi_stream *io, struct device *dev) |
Kuninori Morimoto | 7da9ced | 2012-02-03 00:59:33 -0800 | [diff] [blame] | 1177 | { |
| 1178 | dma_cap_mask_t mask; |
| 1179 | |
| 1180 | dma_cap_zero(mask); |
| 1181 | dma_cap_set(DMA_SLAVE, mask); |
| 1182 | |
| 1183 | io->chan = dma_request_channel(mask, fsi_dma_filter, &io->slave); |
Kuninori Morimoto | b1226dc | 2012-05-24 23:56:19 -0700 | [diff] [blame^] | 1184 | if (!io->chan) { |
| 1185 | |
| 1186 | /* switch to PIO handler */ |
| 1187 | if (fsi_stream_is_play(fsi, io)) |
| 1188 | fsi->playback.handler = &fsi_pio_push_handler; |
| 1189 | else |
| 1190 | fsi->capture.handler = &fsi_pio_pop_handler; |
| 1191 | |
| 1192 | dev_info(dev, "switch handler (dma => pio)\n"); |
| 1193 | |
| 1194 | /* probe again */ |
| 1195 | return fsi_stream_probe(fsi, dev); |
| 1196 | } |
Kuninori Morimoto | 7da9ced | 2012-02-03 00:59:33 -0800 | [diff] [blame] | 1197 | |
| 1198 | tasklet_init(&io->tasklet, fsi_dma_do_tasklet, (unsigned long)io); |
| 1199 | |
| 1200 | return 0; |
| 1201 | } |
| 1202 | |
| 1203 | static int fsi_dma_remove(struct fsi_priv *fsi, struct fsi_stream *io) |
| 1204 | { |
| 1205 | tasklet_kill(&io->tasklet); |
| 1206 | |
| 1207 | fsi_stream_stop(fsi, io); |
| 1208 | |
| 1209 | if (io->chan) |
| 1210 | dma_release_channel(io->chan); |
| 1211 | |
| 1212 | io->chan = NULL; |
| 1213 | return 0; |
| 1214 | } |
| 1215 | |
| 1216 | static struct fsi_stream_handler fsi_dma_push_handler = { |
| 1217 | .init = fsi_dma_init, |
| 1218 | .quit = fsi_dma_quit, |
| 1219 | .probe = fsi_dma_probe, |
| 1220 | .transfer = fsi_dma_transfer, |
| 1221 | .remove = fsi_dma_remove, |
| 1222 | .start_stop = fsi_dma_push_start_stop, |
| 1223 | }; |
| 1224 | |
| 1225 | /* |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 1226 | * dai ops |
| 1227 | */ |
Kuninori Morimoto | b49e802 | 2012-02-03 00:51:29 -0800 | [diff] [blame] | 1228 | static void fsi_fifo_init(struct fsi_priv *fsi, |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 1229 | struct fsi_stream *io, |
Kuninori Morimoto | b49e802 | 2012-02-03 00:51:29 -0800 | [diff] [blame] | 1230 | struct device *dev) |
| 1231 | { |
| 1232 | struct fsi_master *master = fsi_get_master(fsi); |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 1233 | int is_play = fsi_stream_is_play(fsi, io); |
Kuninori Morimoto | b49e802 | 2012-02-03 00:51:29 -0800 | [diff] [blame] | 1234 | u32 shift, i; |
| 1235 | int frame_capa; |
| 1236 | |
| 1237 | /* get on-chip RAM capacity */ |
| 1238 | shift = fsi_master_read(master, FIFO_SZ); |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 1239 | shift >>= fsi_get_port_shift(fsi, io); |
Kuninori Morimoto | b49e802 | 2012-02-03 00:51:29 -0800 | [diff] [blame] | 1240 | shift &= FIFO_SZ_MASK; |
| 1241 | frame_capa = 256 << shift; |
| 1242 | dev_dbg(dev, "fifo = %d words\n", frame_capa); |
| 1243 | |
| 1244 | /* |
| 1245 | * The maximum number of sample data varies depending |
| 1246 | * on the number of channels selected for the format. |
| 1247 | * |
| 1248 | * FIFOs are used in 4-channel units in 3-channel mode |
| 1249 | * and in 8-channel units in 5- to 7-channel mode |
| 1250 | * meaning that more FIFOs than the required size of DPRAM |
| 1251 | * are used. |
| 1252 | * |
| 1253 | * ex) if 256 words of DP-RAM is connected |
| 1254 | * 1 channel: 256 (256 x 1 = 256) |
| 1255 | * 2 channels: 128 (128 x 2 = 256) |
| 1256 | * 3 channels: 64 ( 64 x 3 = 192) |
| 1257 | * 4 channels: 64 ( 64 x 4 = 256) |
| 1258 | * 5 channels: 32 ( 32 x 5 = 160) |
| 1259 | * 6 channels: 32 ( 32 x 6 = 192) |
| 1260 | * 7 channels: 32 ( 32 x 7 = 224) |
| 1261 | * 8 channels: 32 ( 32 x 8 = 256) |
| 1262 | */ |
| 1263 | for (i = 1; i < fsi->chan_num; i <<= 1) |
| 1264 | frame_capa >>= 1; |
| 1265 | dev_dbg(dev, "%d channel %d store\n", |
| 1266 | fsi->chan_num, frame_capa); |
| 1267 | |
| 1268 | io->fifo_sample_capa = fsi_frame2sample(fsi, frame_capa); |
| 1269 | |
| 1270 | /* |
| 1271 | * set interrupt generation factor |
| 1272 | * clear FIFO |
| 1273 | */ |
| 1274 | if (is_play) { |
| 1275 | fsi_reg_write(fsi, DOFF_CTL, IRQ_HALF); |
| 1276 | fsi_reg_mask_set(fsi, DOFF_CTL, FIFO_CLR, FIFO_CLR); |
| 1277 | } else { |
| 1278 | fsi_reg_write(fsi, DIFF_CTL, IRQ_HALF); |
| 1279 | fsi_reg_mask_set(fsi, DIFF_CTL, FIFO_CLR, FIFO_CLR); |
| 1280 | } |
| 1281 | } |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1282 | |
Kuninori Morimoto | 23ca853 | 2011-05-23 20:46:26 +0900 | [diff] [blame] | 1283 | static int fsi_hw_startup(struct fsi_priv *fsi, |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 1284 | struct fsi_stream *io, |
Kuninori Morimoto | 23ca853 | 2011-05-23 20:46:26 +0900 | [diff] [blame] | 1285 | struct device *dev) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1286 | { |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 1287 | u32 flags = fsi_get_info_flags(fsi); |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 1288 | u32 data = 0; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1289 | |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 1290 | /* clock setting */ |
| 1291 | if (fsi_is_clk_master(fsi)) |
| 1292 | data = DIMD | DOMD; |
| 1293 | |
| 1294 | fsi_reg_mask_set(fsi, CKG1, (DIMD | DOMD), data); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1295 | |
| 1296 | /* clock inversion (CKG2) */ |
| 1297 | data = 0; |
Kuninori Morimoto | b427b44 | 2010-07-13 12:01:15 +0900 | [diff] [blame] | 1298 | if (SH_FSI_LRM_INV & flags) |
| 1299 | data |= 1 << 12; |
| 1300 | if (SH_FSI_BRM_INV & flags) |
| 1301 | data |= 1 << 8; |
| 1302 | if (SH_FSI_LRS_INV & flags) |
| 1303 | data |= 1 << 4; |
| 1304 | if (SH_FSI_BRS_INV & flags) |
| 1305 | data |= 1 << 0; |
| 1306 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1307 | fsi_reg_write(fsi, CKG2, data); |
| 1308 | |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 1309 | /* spdif ? */ |
| 1310 | if (fsi_is_spdif(fsi)) { |
| 1311 | fsi_spdif_clk_ctrl(fsi, 1); |
| 1312 | fsi_reg_mask_set(fsi, OUT_SEL, DMMD, DMMD); |
| 1313 | } |
| 1314 | |
Kuninori Morimoto | 65ff03f | 2011-11-06 22:05:25 -0800 | [diff] [blame] | 1315 | /* |
Kuninori Morimoto | 766812e | 2012-05-17 17:36:47 -0700 | [diff] [blame] | 1316 | * get bus settings |
Kuninori Morimoto | 65ff03f | 2011-11-06 22:05:25 -0800 | [diff] [blame] | 1317 | */ |
Kuninori Morimoto | 766812e | 2012-05-17 17:36:47 -0700 | [diff] [blame] | 1318 | data = 0; |
| 1319 | switch (io->sample_width) { |
| 1320 | case 2: |
| 1321 | data = BUSOP_GET(16, io->bus_option); |
| 1322 | break; |
| 1323 | case 4: |
| 1324 | data = BUSOP_GET(24, io->bus_option); |
| 1325 | break; |
Kuninori Morimoto | 65ff03f | 2011-11-06 22:05:25 -0800 | [diff] [blame] | 1326 | } |
Kuninori Morimoto | 766812e | 2012-05-17 17:36:47 -0700 | [diff] [blame] | 1327 | fsi_format_bus_setup(fsi, io, data, dev); |
Kuninori Morimoto | 65ff03f | 2011-11-06 22:05:25 -0800 | [diff] [blame] | 1328 | |
Kuninori Morimoto | 10ea76c | 2010-03-23 11:47:54 +0900 | [diff] [blame] | 1329 | /* irq clear */ |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 1330 | fsi_irq_disable(fsi, io); |
Kuninori Morimoto | 10ea76c | 2010-03-23 11:47:54 +0900 | [diff] [blame] | 1331 | fsi_irq_clear_status(fsi); |
| 1332 | |
| 1333 | /* fifo init */ |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 1334 | fsi_fifo_init(fsi, io, dev); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1335 | |
Kuninori Morimoto | a68a3b4 | 2010-10-12 11:39:50 +0900 | [diff] [blame] | 1336 | return 0; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1337 | } |
| 1338 | |
Kuninori Morimoto | 23ca853 | 2011-05-23 20:46:26 +0900 | [diff] [blame] | 1339 | static void fsi_hw_shutdown(struct fsi_priv *fsi, |
Kuninori Morimoto | 23ca853 | 2011-05-23 20:46:26 +0900 | [diff] [blame] | 1340 | struct device *dev) |
| 1341 | { |
| 1342 | if (fsi_is_clk_master(fsi)) |
| 1343 | fsi_set_master_clk(dev, fsi, fsi->rate, 0); |
Kuninori Morimoto | 23ca853 | 2011-05-23 20:46:26 +0900 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | static int fsi_dai_startup(struct snd_pcm_substream *substream, |
| 1347 | struct snd_soc_dai *dai) |
| 1348 | { |
| 1349 | struct fsi_priv *fsi = fsi_get_priv(substream); |
Kuninori Morimoto | 23ca853 | 2011-05-23 20:46:26 +0900 | [diff] [blame] | 1350 | |
Kuninori Morimoto | f33238e | 2012-05-17 17:35:34 -0700 | [diff] [blame] | 1351 | fsi->rate = 0; |
| 1352 | |
| 1353 | return 0; |
Kuninori Morimoto | 23ca853 | 2011-05-23 20:46:26 +0900 | [diff] [blame] | 1354 | } |
| 1355 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1356 | static void fsi_dai_shutdown(struct snd_pcm_substream *substream, |
| 1357 | struct snd_soc_dai *dai) |
| 1358 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 1359 | struct fsi_priv *fsi = fsi_get_priv(substream); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1360 | |
Kuninori Morimoto | d4bc99b | 2010-11-24 02:44:06 +0000 | [diff] [blame] | 1361 | fsi->rate = 0; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | static int fsi_dai_trigger(struct snd_pcm_substream *substream, int cmd, |
| 1365 | struct snd_soc_dai *dai) |
| 1366 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 1367 | struct fsi_priv *fsi = fsi_get_priv(substream); |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 1368 | struct fsi_stream *io = fsi_stream_get(fsi, substream); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1369 | int ret = 0; |
| 1370 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1371 | switch (cmd) { |
| 1372 | case SNDRV_PCM_TRIGGER_START: |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 1373 | fsi_stream_init(fsi, io, substream); |
Kuninori Morimoto | f33238e | 2012-05-17 17:35:34 -0700 | [diff] [blame] | 1374 | fsi_hw_startup(fsi, io, dai->dev); |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 1375 | ret = fsi_stream_transfer(io); |
| 1376 | if (0 == ret) |
Kuninori Morimoto | 180346e | 2012-02-03 00:57:25 -0800 | [diff] [blame] | 1377 | fsi_stream_start(fsi, io); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1378 | break; |
| 1379 | case SNDRV_PCM_TRIGGER_STOP: |
Kuninori Morimoto | f33238e | 2012-05-17 17:35:34 -0700 | [diff] [blame] | 1380 | fsi_hw_shutdown(fsi, dai->dev); |
Kuninori Morimoto | 180346e | 2012-02-03 00:57:25 -0800 | [diff] [blame] | 1381 | fsi_stream_stop(fsi, io); |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 1382 | fsi_stream_quit(fsi, io); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1383 | break; |
| 1384 | } |
| 1385 | |
| 1386 | return ret; |
| 1387 | } |
| 1388 | |
Kuninori Morimoto | f17c13c | 2011-01-24 10:43:19 +0900 | [diff] [blame] | 1389 | static int fsi_set_fmt_dai(struct fsi_priv *fsi, unsigned int fmt) |
| 1390 | { |
Kuninori Morimoto | f17c13c | 2011-01-24 10:43:19 +0900 | [diff] [blame] | 1391 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 1392 | case SND_SOC_DAIFMT_I2S: |
Kuninori Morimoto | 9c59dd3 | 2012-05-17 17:34:53 -0700 | [diff] [blame] | 1393 | fsi->fmt = CR_I2S; |
Kuninori Morimoto | f17c13c | 2011-01-24 10:43:19 +0900 | [diff] [blame] | 1394 | fsi->chan_num = 2; |
| 1395 | break; |
| 1396 | case SND_SOC_DAIFMT_LEFT_J: |
Kuninori Morimoto | 9c59dd3 | 2012-05-17 17:34:53 -0700 | [diff] [blame] | 1397 | fsi->fmt = CR_PCM; |
Kuninori Morimoto | f17c13c | 2011-01-24 10:43:19 +0900 | [diff] [blame] | 1398 | fsi->chan_num = 2; |
| 1399 | break; |
| 1400 | default: |
| 1401 | return -EINVAL; |
| 1402 | } |
| 1403 | |
Kuninori Morimoto | f17c13c | 2011-01-24 10:43:19 +0900 | [diff] [blame] | 1404 | return 0; |
| 1405 | } |
| 1406 | |
| 1407 | static int fsi_set_fmt_spdif(struct fsi_priv *fsi) |
| 1408 | { |
| 1409 | struct fsi_master *master = fsi_get_master(fsi); |
Kuninori Morimoto | f17c13c | 2011-01-24 10:43:19 +0900 | [diff] [blame] | 1410 | |
Kuninori Morimoto | 284c6f6 | 2012-05-17 17:34:16 -0700 | [diff] [blame] | 1411 | if (fsi_version(master) < 2) |
Kuninori Morimoto | f17c13c | 2011-01-24 10:43:19 +0900 | [diff] [blame] | 1412 | return -EINVAL; |
| 1413 | |
Kuninori Morimoto | 766812e | 2012-05-17 17:36:47 -0700 | [diff] [blame] | 1414 | fsi->fmt = CR_DTMD_SPDIF_PCM | CR_PCM; |
Kuninori Morimoto | f17c13c | 2011-01-24 10:43:19 +0900 | [diff] [blame] | 1415 | fsi->chan_num = 2; |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 1416 | fsi->spdif = 1; |
Kuninori Morimoto | f17c13c | 2011-01-24 10:43:19 +0900 | [diff] [blame] | 1417 | |
Kuninori Morimoto | f17c13c | 2011-01-24 10:43:19 +0900 | [diff] [blame] | 1418 | return 0; |
| 1419 | } |
| 1420 | |
Kuninori Morimoto | 4d805f7 | 2011-01-20 11:46:02 +0900 | [diff] [blame] | 1421 | static int fsi_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) |
| 1422 | { |
| 1423 | struct fsi_priv *fsi = fsi_get_priv_frm_dai(dai); |
Kuninori Morimoto | fec691e | 2012-02-03 00:58:48 -0800 | [diff] [blame] | 1424 | set_rate_func set_rate = fsi_get_info_set_rate(fsi); |
Kuninori Morimoto | f17c13c | 2011-01-24 10:43:19 +0900 | [diff] [blame] | 1425 | u32 flags = fsi_get_info_flags(fsi); |
Kuninori Morimoto | 4d805f7 | 2011-01-20 11:46:02 +0900 | [diff] [blame] | 1426 | int ret; |
| 1427 | |
Kuninori Morimoto | 4d805f7 | 2011-01-20 11:46:02 +0900 | [diff] [blame] | 1428 | /* set master/slave audio interface */ |
| 1429 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 1430 | case SND_SOC_DAIFMT_CBM_CFM: |
Kuninori Morimoto | 6a9ebad | 2011-04-21 10:33:36 +0900 | [diff] [blame] | 1431 | fsi->clk_master = 1; |
Kuninori Morimoto | 4d805f7 | 2011-01-20 11:46:02 +0900 | [diff] [blame] | 1432 | break; |
| 1433 | case SND_SOC_DAIFMT_CBS_CFS: |
| 1434 | break; |
| 1435 | default: |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 1436 | return -EINVAL; |
Kuninori Morimoto | 4d805f7 | 2011-01-20 11:46:02 +0900 | [diff] [blame] | 1437 | } |
Kuninori Morimoto | 6a9ebad | 2011-04-21 10:33:36 +0900 | [diff] [blame] | 1438 | |
| 1439 | if (fsi_is_clk_master(fsi) && !set_rate) { |
| 1440 | dev_err(dai->dev, "platform doesn't have set_rate\n"); |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 1441 | return -EINVAL; |
Kuninori Morimoto | 6a9ebad | 2011-04-21 10:33:36 +0900 | [diff] [blame] | 1442 | } |
| 1443 | |
Kuninori Morimoto | f17c13c | 2011-01-24 10:43:19 +0900 | [diff] [blame] | 1444 | /* set format */ |
| 1445 | switch (flags & SH_FSI_FMT_MASK) { |
| 1446 | case SH_FSI_FMT_DAI: |
| 1447 | ret = fsi_set_fmt_dai(fsi, fmt & SND_SOC_DAIFMT_FORMAT_MASK); |
| 1448 | break; |
| 1449 | case SH_FSI_FMT_SPDIF: |
| 1450 | ret = fsi_set_fmt_spdif(fsi); |
| 1451 | break; |
| 1452 | default: |
| 1453 | ret = -EINVAL; |
| 1454 | } |
Kuninori Morimoto | 4d805f7 | 2011-01-20 11:46:02 +0900 | [diff] [blame] | 1455 | |
Kuninori Morimoto | 4d805f7 | 2011-01-20 11:46:02 +0900 | [diff] [blame] | 1456 | return ret; |
| 1457 | } |
| 1458 | |
Kuninori Morimoto | ccad7b4 | 2010-07-13 12:13:14 +0900 | [diff] [blame] | 1459 | static int fsi_dai_hw_params(struct snd_pcm_substream *substream, |
| 1460 | struct snd_pcm_hw_params *params, |
| 1461 | struct snd_soc_dai *dai) |
| 1462 | { |
| 1463 | struct fsi_priv *fsi = fsi_get_priv(substream); |
Kuninori Morimoto | d4bc99b | 2010-11-24 02:44:06 +0000 | [diff] [blame] | 1464 | long rate = params_rate(params); |
Kuninori Morimoto | ccad7b4 | 2010-07-13 12:13:14 +0900 | [diff] [blame] | 1465 | int ret; |
| 1466 | |
Kuninori Morimoto | 6a9ebad | 2011-04-21 10:33:36 +0900 | [diff] [blame] | 1467 | if (!fsi_is_clk_master(fsi)) |
Kuninori Morimoto | ccad7b4 | 2010-07-13 12:13:14 +0900 | [diff] [blame] | 1468 | return 0; |
| 1469 | |
Kuninori Morimoto | 4f56cde | 2011-05-23 20:46:18 +0900 | [diff] [blame] | 1470 | ret = fsi_set_master_clk(dai->dev, fsi, rate, 1); |
| 1471 | if (ret < 0) |
Kuninori Morimoto | d4bc99b | 2010-11-24 02:44:06 +0000 | [diff] [blame] | 1472 | return ret; |
Kuninori Morimoto | ccad7b4 | 2010-07-13 12:13:14 +0900 | [diff] [blame] | 1473 | |
Kuninori Morimoto | d4bc99b | 2010-11-24 02:44:06 +0000 | [diff] [blame] | 1474 | fsi->rate = rate; |
Kuninori Morimoto | ccad7b4 | 2010-07-13 12:13:14 +0900 | [diff] [blame] | 1475 | |
| 1476 | return ret; |
Kuninori Morimoto | ccad7b4 | 2010-07-13 12:13:14 +0900 | [diff] [blame] | 1477 | } |
| 1478 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 1479 | static const struct snd_soc_dai_ops fsi_dai_ops = { |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1480 | .startup = fsi_dai_startup, |
| 1481 | .shutdown = fsi_dai_shutdown, |
| 1482 | .trigger = fsi_dai_trigger, |
Kuninori Morimoto | 4d805f7 | 2011-01-20 11:46:02 +0900 | [diff] [blame] | 1483 | .set_fmt = fsi_dai_set_fmt, |
Kuninori Morimoto | ccad7b4 | 2010-07-13 12:13:14 +0900 | [diff] [blame] | 1484 | .hw_params = fsi_dai_hw_params, |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1485 | }; |
| 1486 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 1487 | /* |
| 1488 | * pcm ops |
| 1489 | */ |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1490 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1491 | static struct snd_pcm_hardware fsi_pcm_hardware = { |
| 1492 | .info = SNDRV_PCM_INFO_INTERLEAVED | |
| 1493 | SNDRV_PCM_INFO_MMAP | |
| 1494 | SNDRV_PCM_INFO_MMAP_VALID | |
| 1495 | SNDRV_PCM_INFO_PAUSE, |
| 1496 | .formats = FSI_FMTS, |
| 1497 | .rates = FSI_RATES, |
| 1498 | .rate_min = 8000, |
| 1499 | .rate_max = 192000, |
| 1500 | .channels_min = 1, |
| 1501 | .channels_max = 2, |
| 1502 | .buffer_bytes_max = 64 * 1024, |
| 1503 | .period_bytes_min = 32, |
| 1504 | .period_bytes_max = 8192, |
| 1505 | .periods_min = 1, |
| 1506 | .periods_max = 32, |
| 1507 | .fifo_size = 256, |
| 1508 | }; |
| 1509 | |
| 1510 | static int fsi_pcm_open(struct snd_pcm_substream *substream) |
| 1511 | { |
| 1512 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1513 | int ret = 0; |
| 1514 | |
| 1515 | snd_soc_set_runtime_hwparams(substream, &fsi_pcm_hardware); |
| 1516 | |
| 1517 | ret = snd_pcm_hw_constraint_integer(runtime, |
| 1518 | SNDRV_PCM_HW_PARAM_PERIODS); |
| 1519 | |
| 1520 | return ret; |
| 1521 | } |
| 1522 | |
| 1523 | static int fsi_hw_params(struct snd_pcm_substream *substream, |
| 1524 | struct snd_pcm_hw_params *hw_params) |
| 1525 | { |
| 1526 | return snd_pcm_lib_malloc_pages(substream, |
| 1527 | params_buffer_bytes(hw_params)); |
| 1528 | } |
| 1529 | |
| 1530 | static int fsi_hw_free(struct snd_pcm_substream *substream) |
| 1531 | { |
| 1532 | return snd_pcm_lib_free_pages(substream); |
| 1533 | } |
| 1534 | |
| 1535 | static snd_pcm_uframes_t fsi_pointer(struct snd_pcm_substream *substream) |
| 1536 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 1537 | struct fsi_priv *fsi = fsi_get_priv(substream); |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 1538 | struct fsi_stream *io = fsi_stream_get(fsi, substream); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1539 | |
Kuninori Morimoto | 1987877 | 2012-02-08 16:57:29 -0800 | [diff] [blame] | 1540 | return fsi_sample2frame(fsi, io->buff_sample_pos); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1541 | } |
| 1542 | |
| 1543 | static struct snd_pcm_ops fsi_pcm_ops = { |
| 1544 | .open = fsi_pcm_open, |
| 1545 | .ioctl = snd_pcm_lib_ioctl, |
| 1546 | .hw_params = fsi_hw_params, |
| 1547 | .hw_free = fsi_hw_free, |
| 1548 | .pointer = fsi_pointer, |
| 1549 | }; |
| 1550 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 1551 | /* |
| 1552 | * snd_soc_platform |
| 1553 | */ |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1554 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1555 | #define PREALLOC_BUFFER (32 * 1024) |
| 1556 | #define PREALLOC_BUFFER_MAX (32 * 1024) |
| 1557 | |
| 1558 | static void fsi_pcm_free(struct snd_pcm *pcm) |
| 1559 | { |
| 1560 | snd_pcm_lib_preallocate_free_for_all(pcm); |
| 1561 | } |
| 1562 | |
Liam Girdwood | 552d1ef | 2011-06-07 16:08:33 +0100 | [diff] [blame] | 1563 | static int fsi_pcm_new(struct snd_soc_pcm_runtime *rtd) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1564 | { |
Liam Girdwood | 552d1ef | 2011-06-07 16:08:33 +0100 | [diff] [blame] | 1565 | struct snd_pcm *pcm = rtd->pcm; |
| 1566 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1567 | /* |
| 1568 | * dont use SNDRV_DMA_TYPE_DEV, since it will oops the SH kernel |
| 1569 | * in MMAP mode (i.e. aplay -M) |
| 1570 | */ |
| 1571 | return snd_pcm_lib_preallocate_pages_for_all( |
| 1572 | pcm, |
| 1573 | SNDRV_DMA_TYPE_CONTINUOUS, |
| 1574 | snd_dma_continuous_data(GFP_KERNEL), |
| 1575 | PREALLOC_BUFFER, PREALLOC_BUFFER_MAX); |
| 1576 | } |
| 1577 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 1578 | /* |
| 1579 | * alsa struct |
| 1580 | */ |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1581 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1582 | static struct snd_soc_dai_driver fsi_soc_dai[] = { |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1583 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1584 | .name = "fsia-dai", |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1585 | .playback = { |
| 1586 | .rates = FSI_RATES, |
| 1587 | .formats = FSI_FMTS, |
| 1588 | .channels_min = 1, |
| 1589 | .channels_max = 8, |
| 1590 | }, |
Kuninori Morimoto | 07102f3 | 2009-10-30 12:02:44 +0900 | [diff] [blame] | 1591 | .capture = { |
| 1592 | .rates = FSI_RATES, |
| 1593 | .formats = FSI_FMTS, |
| 1594 | .channels_min = 1, |
| 1595 | .channels_max = 8, |
| 1596 | }, |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1597 | .ops = &fsi_dai_ops, |
| 1598 | }, |
| 1599 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1600 | .name = "fsib-dai", |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1601 | .playback = { |
| 1602 | .rates = FSI_RATES, |
| 1603 | .formats = FSI_FMTS, |
| 1604 | .channels_min = 1, |
| 1605 | .channels_max = 8, |
| 1606 | }, |
Kuninori Morimoto | 07102f3 | 2009-10-30 12:02:44 +0900 | [diff] [blame] | 1607 | .capture = { |
| 1608 | .rates = FSI_RATES, |
| 1609 | .formats = FSI_FMTS, |
| 1610 | .channels_min = 1, |
| 1611 | .channels_max = 8, |
| 1612 | }, |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1613 | .ops = &fsi_dai_ops, |
| 1614 | }, |
| 1615 | }; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1616 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1617 | static struct snd_soc_platform_driver fsi_soc_platform = { |
| 1618 | .ops = &fsi_pcm_ops, |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1619 | .pcm_new = fsi_pcm_new, |
| 1620 | .pcm_free = fsi_pcm_free, |
| 1621 | }; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1622 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 1623 | /* |
| 1624 | * platform function |
| 1625 | */ |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 1626 | static void fsi_handler_init(struct fsi_priv *fsi) |
| 1627 | { |
| 1628 | fsi->playback.handler = &fsi_pio_push_handler; /* default PIO */ |
| 1629 | fsi->playback.priv = fsi; |
| 1630 | fsi->capture.handler = &fsi_pio_pop_handler; /* default PIO */ |
| 1631 | fsi->capture.priv = fsi; |
Kuninori Morimoto | 7da9ced | 2012-02-03 00:59:33 -0800 | [diff] [blame] | 1632 | |
| 1633 | if (fsi->info->tx_id) { |
| 1634 | fsi->playback.slave.slave_id = fsi->info->tx_id; |
| 1635 | fsi->playback.handler = &fsi_dma_push_handler; |
| 1636 | } |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 1637 | } |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1638 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1639 | static int fsi_probe(struct platform_device *pdev) |
| 1640 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 1641 | struct fsi_master *master; |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 1642 | const struct platform_device_id *id_entry; |
Kuninori Morimoto | fec691e | 2012-02-03 00:58:48 -0800 | [diff] [blame] | 1643 | struct sh_fsi_platform_info *info = pdev->dev.platform_data; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1644 | struct resource *res; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1645 | unsigned int irq; |
| 1646 | int ret; |
| 1647 | |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 1648 | id_entry = pdev->id_entry; |
| 1649 | if (!id_entry) { |
| 1650 | dev_err(&pdev->dev, "unknown fsi device\n"); |
| 1651 | return -ENODEV; |
| 1652 | } |
| 1653 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1654 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1655 | irq = platform_get_irq(pdev, 0); |
Uwe Kleine-König | b6aa179 | 2009-12-16 17:10:09 +0100 | [diff] [blame] | 1656 | if (!res || (int)irq <= 0) { |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1657 | dev_err(&pdev->dev, "Not enough FSI platform resources.\n"); |
| 1658 | ret = -ENODEV; |
| 1659 | goto exit; |
| 1660 | } |
| 1661 | |
| 1662 | master = kzalloc(sizeof(*master), GFP_KERNEL); |
| 1663 | if (!master) { |
| 1664 | dev_err(&pdev->dev, "Could not allocate master\n"); |
| 1665 | ret = -ENOMEM; |
| 1666 | goto exit; |
| 1667 | } |
| 1668 | |
| 1669 | master->base = ioremap_nocache(res->start, resource_size(res)); |
| 1670 | if (!master->base) { |
| 1671 | ret = -ENXIO; |
| 1672 | dev_err(&pdev->dev, "Unable to ioremap FSI registers.\n"); |
| 1673 | goto exit_kfree; |
| 1674 | } |
| 1675 | |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 1676 | /* master setting */ |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1677 | master->irq = irq; |
Kuninori Morimoto | 73b92c1 | 2010-07-13 12:13:04 +0900 | [diff] [blame] | 1678 | master->core = (struct fsi_core *)id_entry->driver_data; |
Kuninori Morimoto | 8fc176d | 2010-01-28 13:46:16 +0900 | [diff] [blame] | 1679 | spin_lock_init(&master->lock); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1680 | |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 1681 | /* FSI A setting */ |
| 1682 | master->fsia.base = master->base; |
| 1683 | master->fsia.master = master; |
Kuninori Morimoto | fec691e | 2012-02-03 00:58:48 -0800 | [diff] [blame] | 1684 | master->fsia.info = &info->port_a; |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 1685 | fsi_handler_init(&master->fsia); |
Kuninori Morimoto | b1226dc | 2012-05-24 23:56:19 -0700 | [diff] [blame^] | 1686 | ret = fsi_stream_probe(&master->fsia, &pdev->dev); |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 1687 | if (ret < 0) { |
| 1688 | dev_err(&pdev->dev, "FSIA stream probe failed\n"); |
| 1689 | goto exit_iounmap; |
| 1690 | } |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 1691 | |
| 1692 | /* FSI B setting */ |
| 1693 | master->fsib.base = master->base + 0x40; |
| 1694 | master->fsib.master = master; |
Kuninori Morimoto | fec691e | 2012-02-03 00:58:48 -0800 | [diff] [blame] | 1695 | master->fsib.info = &info->port_b; |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 1696 | fsi_handler_init(&master->fsib); |
Kuninori Morimoto | b1226dc | 2012-05-24 23:56:19 -0700 | [diff] [blame^] | 1697 | ret = fsi_stream_probe(&master->fsib, &pdev->dev); |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 1698 | if (ret < 0) { |
| 1699 | dev_err(&pdev->dev, "FSIB stream probe failed\n"); |
| 1700 | goto exit_fsia; |
| 1701 | } |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 1702 | |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 1703 | pm_runtime_enable(&pdev->dev); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1704 | dev_set_drvdata(&pdev->dev, master); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1705 | |
Yong Zhang | 88e24c3 | 2011-09-22 16:59:20 +0800 | [diff] [blame] | 1706 | ret = request_irq(irq, &fsi_interrupt, 0, |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 1707 | id_entry->name, master); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1708 | if (ret) { |
| 1709 | dev_err(&pdev->dev, "irq request err\n"); |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 1710 | goto exit_fsib; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1711 | } |
| 1712 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1713 | ret = snd_soc_register_platform(&pdev->dev, &fsi_soc_platform); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1714 | if (ret < 0) { |
| 1715 | dev_err(&pdev->dev, "cannot snd soc register\n"); |
| 1716 | goto exit_free_irq; |
| 1717 | } |
| 1718 | |
Kuninori Morimoto | 0b5ec87 | 2011-04-08 15:09:02 +0900 | [diff] [blame] | 1719 | ret = snd_soc_register_dais(&pdev->dev, fsi_soc_dai, |
| 1720 | ARRAY_SIZE(fsi_soc_dai)); |
| 1721 | if (ret < 0) { |
| 1722 | dev_err(&pdev->dev, "cannot snd dai register\n"); |
| 1723 | goto exit_snd_soc; |
| 1724 | } |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1725 | |
Kuninori Morimoto | 0b5ec87 | 2011-04-08 15:09:02 +0900 | [diff] [blame] | 1726 | return ret; |
| 1727 | |
| 1728 | exit_snd_soc: |
| 1729 | snd_soc_unregister_platform(&pdev->dev); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1730 | exit_free_irq: |
| 1731 | free_irq(irq, master); |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 1732 | exit_fsib: |
| 1733 | fsi_stream_remove(&master->fsib); |
| 1734 | exit_fsia: |
| 1735 | fsi_stream_remove(&master->fsia); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1736 | exit_iounmap: |
| 1737 | iounmap(master->base); |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 1738 | pm_runtime_disable(&pdev->dev); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1739 | exit_kfree: |
| 1740 | kfree(master); |
| 1741 | master = NULL; |
| 1742 | exit: |
| 1743 | return ret; |
| 1744 | } |
| 1745 | |
| 1746 | static int fsi_remove(struct platform_device *pdev) |
| 1747 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 1748 | struct fsi_master *master; |
| 1749 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1750 | master = dev_get_drvdata(&pdev->dev); |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 1751 | |
Kuninori Morimoto | d985f27 | 2011-04-08 15:09:25 +0900 | [diff] [blame] | 1752 | free_irq(master->irq, master); |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 1753 | pm_runtime_disable(&pdev->dev); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1754 | |
Kuninori Morimoto | d985f27 | 2011-04-08 15:09:25 +0900 | [diff] [blame] | 1755 | snd_soc_unregister_dais(&pdev->dev, ARRAY_SIZE(fsi_soc_dai)); |
| 1756 | snd_soc_unregister_platform(&pdev->dev); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1757 | |
Kuninori Morimoto | 5e97313 | 2012-02-03 00:55:55 -0800 | [diff] [blame] | 1758 | fsi_stream_remove(&master->fsia); |
| 1759 | fsi_stream_remove(&master->fsib); |
| 1760 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1761 | iounmap(master->base); |
| 1762 | kfree(master); |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 1763 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1764 | return 0; |
| 1765 | } |
| 1766 | |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1767 | static void __fsi_suspend(struct fsi_priv *fsi, |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 1768 | struct fsi_stream *io, |
Kuninori Morimoto | 4f56cde | 2011-05-23 20:46:18 +0900 | [diff] [blame] | 1769 | struct device *dev) |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1770 | { |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 1771 | if (!fsi_stream_is_working(fsi, io)) |
Kuninori Morimoto | cda828c | 2011-05-23 20:46:35 +0900 | [diff] [blame] | 1772 | return; |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1773 | |
Kuninori Morimoto | 180346e | 2012-02-03 00:57:25 -0800 | [diff] [blame] | 1774 | fsi_stream_stop(fsi, io); |
Kuninori Morimoto | 41bba15 | 2012-02-03 00:51:53 -0800 | [diff] [blame] | 1775 | fsi_hw_shutdown(fsi, dev); |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1776 | } |
| 1777 | |
| 1778 | static void __fsi_resume(struct fsi_priv *fsi, |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 1779 | struct fsi_stream *io, |
Kuninori Morimoto | 4f56cde | 2011-05-23 20:46:18 +0900 | [diff] [blame] | 1780 | struct device *dev) |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1781 | { |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 1782 | if (!fsi_stream_is_working(fsi, io)) |
Kuninori Morimoto | cda828c | 2011-05-23 20:46:35 +0900 | [diff] [blame] | 1783 | return; |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1784 | |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 1785 | fsi_hw_startup(fsi, io, dev); |
Kuninori Morimoto | cda828c | 2011-05-23 20:46:35 +0900 | [diff] [blame] | 1786 | |
| 1787 | if (fsi_is_clk_master(fsi) && fsi->rate) |
Kuninori Morimoto | 4f56cde | 2011-05-23 20:46:18 +0900 | [diff] [blame] | 1788 | fsi_set_master_clk(dev, fsi, fsi->rate, 1); |
Kuninori Morimoto | cda828c | 2011-05-23 20:46:35 +0900 | [diff] [blame] | 1789 | |
Kuninori Morimoto | 180346e | 2012-02-03 00:57:25 -0800 | [diff] [blame] | 1790 | fsi_stream_start(fsi, io); |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | static int fsi_suspend(struct device *dev) |
| 1794 | { |
| 1795 | struct fsi_master *master = dev_get_drvdata(dev); |
Kuninori Morimoto | cda828c | 2011-05-23 20:46:35 +0900 | [diff] [blame] | 1796 | struct fsi_priv *fsia = &master->fsia; |
| 1797 | struct fsi_priv *fsib = &master->fsib; |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1798 | |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 1799 | __fsi_suspend(fsia, &fsia->playback, dev); |
| 1800 | __fsi_suspend(fsia, &fsia->capture, dev); |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1801 | |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 1802 | __fsi_suspend(fsib, &fsib->playback, dev); |
| 1803 | __fsi_suspend(fsib, &fsib->capture, dev); |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1804 | |
| 1805 | return 0; |
| 1806 | } |
| 1807 | |
| 1808 | static int fsi_resume(struct device *dev) |
| 1809 | { |
| 1810 | struct fsi_master *master = dev_get_drvdata(dev); |
Kuninori Morimoto | cda828c | 2011-05-23 20:46:35 +0900 | [diff] [blame] | 1811 | struct fsi_priv *fsia = &master->fsia; |
| 1812 | struct fsi_priv *fsib = &master->fsib; |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1813 | |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 1814 | __fsi_resume(fsia, &fsia->playback, dev); |
| 1815 | __fsi_resume(fsia, &fsia->capture, dev); |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1816 | |
Kuninori Morimoto | 938e2a8 | 2012-02-03 00:56:57 -0800 | [diff] [blame] | 1817 | __fsi_resume(fsib, &fsib->playback, dev); |
| 1818 | __fsi_resume(fsib, &fsib->capture, dev); |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1819 | |
| 1820 | return 0; |
| 1821 | } |
| 1822 | |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 1823 | static struct dev_pm_ops fsi_pm_ops = { |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1824 | .suspend = fsi_suspend, |
| 1825 | .resume = fsi_resume, |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 1826 | }; |
| 1827 | |
Kuninori Morimoto | 73b92c1 | 2010-07-13 12:13:04 +0900 | [diff] [blame] | 1828 | static struct fsi_core fsi1_core = { |
| 1829 | .ver = 1, |
| 1830 | |
| 1831 | /* Interrupt */ |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 1832 | .int_st = INT_ST, |
| 1833 | .iemsk = IEMSK, |
| 1834 | .imsk = IMSK, |
| 1835 | }; |
| 1836 | |
Kuninori Morimoto | 73b92c1 | 2010-07-13 12:13:04 +0900 | [diff] [blame] | 1837 | static struct fsi_core fsi2_core = { |
| 1838 | .ver = 2, |
| 1839 | |
| 1840 | /* Interrupt */ |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 1841 | .int_st = CPU_INT_ST, |
| 1842 | .iemsk = CPU_IEMSK, |
| 1843 | .imsk = CPU_IMSK, |
Kuninori Morimoto | 2b0e730 | 2010-12-03 17:37:44 +0900 | [diff] [blame] | 1844 | .a_mclk = A_MST_CTLR, |
| 1845 | .b_mclk = B_MST_CTLR, |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 1846 | }; |
| 1847 | |
| 1848 | static struct platform_device_id fsi_id_table[] = { |
Kuninori Morimoto | 73b92c1 | 2010-07-13 12:13:04 +0900 | [diff] [blame] | 1849 | { "sh_fsi", (kernel_ulong_t)&fsi1_core }, |
| 1850 | { "sh_fsi2", (kernel_ulong_t)&fsi2_core }, |
Guennadi Liakhovetski | 05c6945 | 2010-10-05 17:54:28 +0200 | [diff] [blame] | 1851 | {}, |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 1852 | }; |
Dzianis Kahanovich | d85a6d7 | 2010-09-17 16:42:05 +0300 | [diff] [blame] | 1853 | MODULE_DEVICE_TABLE(platform, fsi_id_table); |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 1854 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1855 | static struct platform_driver fsi_driver = { |
| 1856 | .driver = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1857 | .name = "fsi-pcm-audio", |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 1858 | .pm = &fsi_pm_ops, |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1859 | }, |
| 1860 | .probe = fsi_probe, |
| 1861 | .remove = fsi_remove, |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 1862 | .id_table = fsi_id_table, |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1863 | }; |
| 1864 | |
Axel Lin | cb5e873 | 2011-11-25 10:15:07 +0800 | [diff] [blame] | 1865 | module_platform_driver(fsi_driver); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1866 | |
| 1867 | MODULE_LICENSE("GPL"); |
| 1868 | MODULE_DESCRIPTION("SuperH onchip FSI audio driver"); |
| 1869 | MODULE_AUTHOR("Kuninori Morimoto <morimoto.kuninori@renesas.com>"); |
Guennadi Liakhovetski | b3c27b5 | 2011-04-15 20:17:34 +0200 | [diff] [blame] | 1870 | MODULE_ALIAS("platform:fsi-pcm-audio"); |