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