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