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