blob: 378cc5b056d72f6c9ed5d28481869e3a608df871 [file] [log] [blame]
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001/*
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 Morimotoa4d7d552009-08-20 21:01:05 +090015#include <linux/delay.h>
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -080016#include <linux/dma-mapping.h>
Kuninori Morimoto785d1c42009-11-30 20:24:48 +090017#include <linux/pm_runtime.h>
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090018#include <linux/io.h>
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -080019#include <linux/scatterlist.h>
20#include <linux/sh_dma.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090021#include <linux/slab.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040022#include <linux/module.h>
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090023#include <sound/soc.h>
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090024#include <sound/sh_fsi.h>
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090025
Kuninori Morimotoe8c8b632010-12-03 17:37:55 +090026/* PortA/PortB register */
27#define REG_DO_FMT 0x0000
28#define REG_DOFF_CTL 0x0004
29#define REG_DOFF_ST 0x0008
30#define REG_DI_FMT 0x000C
31#define REG_DIFF_CTL 0x0010
32#define REG_DIFF_ST 0x0014
33#define REG_CKG1 0x0018
34#define REG_CKG2 0x001C
35#define REG_DIDT 0x0020
36#define REG_DODT 0x0024
37#define REG_MUTE_ST 0x0028
Kuninori Morimoto65ff03f2011-11-06 22:05:25 -080038#define REG_OUT_DMAC 0x002C
Kuninori Morimotoe8c8b632010-12-03 17:37:55 +090039#define REG_OUT_SEL 0x0030
Kuninori Morimoto65ff03f2011-11-06 22:05:25 -080040#define REG_IN_DMAC 0x0038
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090041
Kuninori Morimoto43fa95c2010-12-03 17:38:03 +090042/* master register */
43#define MST_CLK_RST 0x0210
44#define MST_SOFT_RST 0x0214
45#define MST_FIFO_SZ 0x0218
46
47/* core register (depend on FSI version) */
Kuninori Morimoto3bc28072010-07-29 16:48:32 +090048#define A_MST_CTLR 0x0180
49#define B_MST_CTLR 0x01A0
Kuninori Morimotocc780d32010-03-25 19:15:53 +090050#define CPU_INT_ST 0x01F4
51#define CPU_IEMSK 0x01F8
52#define CPU_IMSK 0x01FC
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090053#define INT_ST 0x0200
54#define IEMSK 0x0204
55#define IMSK 0x0208
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090056
57/* DO_FMT */
58/* DI_FMT */
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -080059#define CR_BWS_MASK (0x3 << 20) /* FSI2 */
Kuninori Morimotof7d711e2010-12-03 17:36:24 +090060#define CR_BWS_24 (0x0 << 20) /* FSI2 */
61#define CR_BWS_16 (0x1 << 20) /* FSI2 */
62#define CR_BWS_20 (0x2 << 20) /* FSI2 */
63
64#define CR_DTMD_PCM (0x0 << 8) /* FSI2 */
65#define CR_DTMD_SPDIF_PCM (0x1 << 8) /* FSI2 */
66#define CR_DTMD_SPDIF_STREAM (0x2 << 8) /* FSI2 */
67
Kuninori Morimotoa7ffb522010-07-13 12:13:00 +090068#define CR_MONO (0x0 << 4)
69#define CR_MONO_D (0x1 << 4)
70#define CR_PCM (0x2 << 4)
71#define CR_I2S (0x3 << 4)
72#define CR_TDM (0x4 << 4)
73#define CR_TDM_D (0x5 << 4)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090074
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -080075/* OUT_DMAC */
76/* IN_DMAC */
77#define VDMD_MASK (0x3 << 4)
78#define VDMD_FRONT (0x0 << 4) /* Package in front */
79#define VDMD_BACK (0x1 << 4) /* Package in back */
80#define VDMD_STREAM (0x2 << 4) /* Stream mode(16bit * 2) */
81
82#define DMA_ON (0x1 << 0)
83
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090084/* DOFF_CTL */
85/* DIFF_CTL */
86#define IRQ_HALF 0x00100000
87#define FIFO_CLR 0x00000001
88
89/* DOFF_ST */
90#define ERR_OVER 0x00000010
91#define ERR_UNDER 0x00000001
Kuninori Morimoto59c3b002009-12-28 14:09:16 +090092#define ST_ERR (ERR_OVER | ERR_UNDER)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090093
Kuninori Morimotoccad7b42010-07-13 12:13:14 +090094/* CKG1 */
95#define ACKMD_MASK 0x00007000
96#define BPFMD_MASK 0x00000700
Kuninori Morimoto4d805f72011-01-20 11:46:02 +090097#define DIMD (1 << 4)
98#define DOMD (1 << 0)
Kuninori Morimotoccad7b42010-07-13 12:13:14 +090099
Kuninori Morimoto3bc28072010-07-29 16:48:32 +0900100/* A/B MST_CTLR */
101#define BP (1 << 4) /* Fix the signal of Biphase output */
102#define SE (1 << 0) /* Fix the master clock */
103
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900104/* CLK_RST */
Kuninori Morimoto1f5e2a32011-04-21 10:33:52 +0900105#define CRB (1 << 4)
106#define CRA (1 << 0)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900107
Kuninori Morimotocf6edd02010-10-12 11:40:53 +0900108/* IO SHIFT / MACRO */
109#define BI_SHIFT 12
110#define BO_SHIFT 8
111#define AI_SHIFT 4
112#define AO_SHIFT 0
113#define AB_IO(param, shift) (param << shift)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900114
Kuninori Morimotofeb58cf2010-03-24 15:27:24 +0900115/* SOFT_RST */
116#define PBSR (1 << 12) /* Port B Software Reset */
117#define PASR (1 << 8) /* Port A Software Reset */
118#define IR (1 << 4) /* Interrupt Reset */
119#define FSISR (1 << 0) /* Software Reset */
120
Kuninori Morimotof7d711e2010-12-03 17:36:24 +0900121/* OUT_SEL (FSI2) */
122#define DMMD (1 << 4) /* SPDIF output timing 0: Biphase only */
123 /* 1: Biphase and serial */
124
Kuninori Morimoto4a942b42010-03-25 19:15:51 +0900125/* FIFO_SZ */
Kuninori Morimotocf6edd02010-10-12 11:40:53 +0900126#define FIFO_SZ_MASK 0x7
Kuninori Morimoto4a942b42010-03-25 19:15:51 +0900127
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900128#define FSI_RATES SNDRV_PCM_RATE_8000_96000
129
130#define FSI_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE)
131
Kuninori Morimotofec691e2012-02-03 00:58:48 -0800132typedef int (*set_rate_func)(struct device *dev, int rate, int enable);
Kuninori Morimotod7c57622011-01-24 10:42:33 +0900133
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +0900134/*
Kuninori Morimoto5bfb9ad2010-09-17 13:48:45 +0900135 * FSI driver use below type name for variable
136 *
Kuninori Morimoto5bfb9ad2010-09-17 13:48:45 +0900137 * xxx_num : number of data
Kuninori Morimoto2e651ba2011-05-23 20:46:03 +0900138 * xxx_pos : position of data
139 * xxx_capa : capacity of data
140 */
141
142/*
143 * period/frame/sample image
144 *
145 * ex) PCM (2ch)
146 *
147 * period pos period pos
148 * [n] [n + 1]
149 * |<-------------------- period--------------------->|
150 * ==|============================================ ... =|==
151 * | |
152 * ||<----- frame ----->|<------ frame ----->| ... |
153 * |+--------------------+--------------------+- ... |
154 * ||[ sample ][ sample ]|[ sample ][ sample ]| ... |
155 * |+--------------------+--------------------+- ... |
156 * ==|============================================ ... =|==
157 */
158
159/*
160 * FSI FIFO image
161 *
162 * | |
163 * | |
164 * | [ sample ] |
165 * | [ sample ] |
166 * | [ sample ] |
167 * | [ sample ] |
168 * --> go to codecs
Kuninori Morimoto5bfb9ad2010-09-17 13:48:45 +0900169 */
170
171/*
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +0900172 * struct
173 */
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900174
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800175struct fsi_stream_handler;
Kuninori Morimoto93193c22010-10-12 19:19:28 +0900176struct fsi_stream {
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900177
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800178 /*
179 * these are initialized by fsi_stream_init()
180 */
181 struct snd_pcm_substream *substream;
Kuninori Morimoto2e651ba2011-05-23 20:46:03 +0900182 int fifo_sample_capa; /* sample capacity of FSI FIFO */
183 int buff_sample_capa; /* sample capacity of ALSA buffer */
184 int buff_sample_pos; /* sample position of ALSA buffer */
185 int period_samples; /* sample number / 1 period */
186 int period_pos; /* current period position */
Kuninori Morimotoc1e6f102012-02-03 00:50:09 -0800187 int sample_width; /* sample width */
Kuninori Morimoto1ec9bc32010-12-17 12:55:22 +0900188 int uerr_num;
189 int oerr_num;
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800190
191 /*
192 * thse are initialized by fsi_handler_init()
193 */
194 struct fsi_stream_handler *handler;
195 struct fsi_priv *priv;
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -0800196
197 /*
198 * these are for DMAEngine
199 */
200 struct dma_chan *chan;
201 struct sh_dmae_slave slave; /* see fsi_handler_init() */
202 struct tasklet_struct tasklet;
203 dma_addr_t dma;
Kuninori Morimoto93193c22010-10-12 19:19:28 +0900204};
205
206struct fsi_priv {
207 void __iomem *base;
208 struct fsi_master *master;
Kuninori Morimotofec691e2012-02-03 00:58:48 -0800209 struct sh_fsi_port_info *info;
Kuninori Morimoto93193c22010-10-12 19:19:28 +0900210
211 struct fsi_stream playback;
212 struct fsi_stream capture;
Kuninori Morimoto3bc28072010-07-29 16:48:32 +0900213
Kuninori Morimoto9478e0b2011-05-23 20:46:07 +0900214 u32 do_fmt;
215 u32 di_fmt;
216
Kuninori Morimoto6a9ebad2011-04-21 10:33:36 +0900217 int chan_num:16;
218 int clk_master:1;
Kuninori Morimoto9478e0b2011-05-23 20:46:07 +0900219 int spdif:1;
Kuninori Morimoto6a9ebad2011-04-21 10:33:36 +0900220
Kuninori Morimotod4bc99b2010-11-24 02:44:06 +0000221 long rate;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900222};
223
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800224struct fsi_stream_handler {
Kuninori Morimoto83344022012-02-03 00:59:02 -0800225 int (*init)(struct fsi_priv *fsi, struct fsi_stream *io);
226 int (*quit)(struct fsi_priv *fsi, struct fsi_stream *io);
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800227 int (*probe)(struct fsi_priv *fsi, struct fsi_stream *io);
228 int (*transfer)(struct fsi_priv *fsi, struct fsi_stream *io);
229 int (*remove)(struct fsi_priv *fsi, struct fsi_stream *io);
Kuninori Morimoto180346e2012-02-03 00:57:25 -0800230 void (*start_stop)(struct fsi_priv *fsi, struct fsi_stream *io,
231 int enable);
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800232};
233#define fsi_stream_handler_call(io, func, args...) \
234 (!(io) ? -ENODEV : \
235 !((io)->handler->func) ? 0 : \
236 (io)->handler->func(args))
237
Kuninori Morimoto73b92c12010-07-13 12:13:04 +0900238struct fsi_core {
239 int ver;
240
Kuninori Morimotocc780d32010-03-25 19:15:53 +0900241 u32 int_st;
242 u32 iemsk;
243 u32 imsk;
Kuninori Morimoto2b0e7302010-12-03 17:37:44 +0900244 u32 a_mclk;
245 u32 b_mclk;
Kuninori Morimotocc780d32010-03-25 19:15:53 +0900246};
247
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900248struct fsi_master {
249 void __iomem *base;
250 int irq;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900251 struct fsi_priv fsia;
252 struct fsi_priv fsib;
Kuninori Morimoto73b92c12010-07-13 12:13:04 +0900253 struct fsi_core *core;
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900254 spinlock_t lock;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900255};
256
Kuninori Morimoto7b1b3332012-02-03 00:55:26 -0800257static int fsi_stream_is_play(struct fsi_priv *fsi, struct fsi_stream *io);
258
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +0900259/*
260 * basic read write function
261 */
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900262
Arnd Bergmannca7acee2011-10-02 22:28:02 +0200263static void __fsi_reg_write(u32 __iomem *reg, u32 data)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900264{
265 /* valid data area is 24bit */
266 data &= 0x00ffffff;
267
Guennadi Liakhovetski0f69d972010-02-03 17:37:23 +0100268 __raw_writel(data, reg);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900269}
270
Arnd Bergmannca7acee2011-10-02 22:28:02 +0200271static u32 __fsi_reg_read(u32 __iomem *reg)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900272{
Guennadi Liakhovetski0f69d972010-02-03 17:37:23 +0100273 return __raw_readl(reg);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900274}
275
Arnd Bergmannca7acee2011-10-02 22:28:02 +0200276static void __fsi_reg_mask_set(u32 __iomem *reg, u32 mask, u32 data)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900277{
278 u32 val = __fsi_reg_read(reg);
279
280 val &= ~mask;
281 val |= data & mask;
282
Guennadi Liakhovetski0f69d972010-02-03 17:37:23 +0100283 __fsi_reg_write(reg, val);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900284}
285
Kuninori Morimotoe8c8b632010-12-03 17:37:55 +0900286#define fsi_reg_write(p, r, d)\
Kuninori Morimoto8918b842011-10-31 22:11:53 -0700287 __fsi_reg_write((p->base + REG_##r), d)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900288
Kuninori Morimotoe8c8b632010-12-03 17:37:55 +0900289#define fsi_reg_read(p, r)\
Kuninori Morimoto8918b842011-10-31 22:11:53 -0700290 __fsi_reg_read((p->base + REG_##r))
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900291
Kuninori Morimotoe8c8b632010-12-03 17:37:55 +0900292#define fsi_reg_mask_set(p, r, m, d)\
Kuninori Morimoto8918b842011-10-31 22:11:53 -0700293 __fsi_reg_mask_set((p->base + REG_##r), m, d)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900294
Kuninori Morimoto43fa95c2010-12-03 17:38:03 +0900295#define fsi_master_read(p, r) _fsi_master_read(p, MST_##r)
296#define fsi_core_read(p, r) _fsi_master_read(p, p->core->r)
297static u32 _fsi_master_read(struct fsi_master *master, u32 reg)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900298{
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900299 u32 ret;
300 unsigned long flags;
301
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900302 spin_lock_irqsave(&master->lock, flags);
Arnd Bergmannca7acee2011-10-02 22:28:02 +0200303 ret = __fsi_reg_read(master->base + reg);
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900304 spin_unlock_irqrestore(&master->lock, flags);
305
306 return ret;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900307}
308
Kuninori Morimoto43fa95c2010-12-03 17:38:03 +0900309#define fsi_master_mask_set(p, r, m, d) _fsi_master_mask_set(p, MST_##r, m, d)
310#define fsi_core_mask_set(p, r, m, d) _fsi_master_mask_set(p, p->core->r, m, d)
311static void _fsi_master_mask_set(struct fsi_master *master,
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900312 u32 reg, u32 mask, u32 data)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900313{
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900314 unsigned long flags;
315
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900316 spin_lock_irqsave(&master->lock, flags);
Arnd Bergmannca7acee2011-10-02 22:28:02 +0200317 __fsi_reg_mask_set(master->base + reg, mask, data);
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900318 spin_unlock_irqrestore(&master->lock, flags);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900319}
320
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +0900321/*
322 * basic function
323 */
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900324
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900325static struct fsi_master *fsi_get_master(struct fsi_priv *fsi)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900326{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900327 return fsi->master;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900328}
329
Kuninori Morimoto6a9ebad2011-04-21 10:33:36 +0900330static int fsi_is_clk_master(struct fsi_priv *fsi)
331{
332 return fsi->clk_master;
333}
334
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900335static int fsi_is_port_a(struct fsi_priv *fsi)
336{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900337 return fsi->master->base == fsi->base;
338}
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900339
Kuninori Morimoto9478e0b2011-05-23 20:46:07 +0900340static int fsi_is_spdif(struct fsi_priv *fsi)
341{
342 return fsi->spdif;
343}
344
Kuninori Morimotoa449e462012-02-03 00:54:02 -0800345static int fsi_is_play(struct snd_pcm_substream *substream)
346{
347 return substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
348}
349
Kuninori Morimoto142e8172009-12-28 14:09:11 +0900350static struct snd_soc_dai *fsi_get_dai(struct snd_pcm_substream *substream)
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900351{
352 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Kuninori Morimoto142e8172009-12-28 14:09:11 +0900353
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000354 return rtd->cpu_dai;
Kuninori Morimoto142e8172009-12-28 14:09:11 +0900355}
356
Kuninori Morimoto0d032c12011-01-20 11:45:51 +0900357static struct fsi_priv *fsi_get_priv_frm_dai(struct snd_soc_dai *dai)
Kuninori Morimoto142e8172009-12-28 14:09:11 +0900358{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000359 struct fsi_master *master = snd_soc_dai_get_drvdata(dai);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900360
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000361 if (dai->id == 0)
362 return &master->fsia;
363 else
364 return &master->fsib;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900365}
366
Kuninori Morimoto0d032c12011-01-20 11:45:51 +0900367static struct fsi_priv *fsi_get_priv(struct snd_pcm_substream *substream)
368{
369 return fsi_get_priv_frm_dai(fsi_get_dai(substream));
370}
371
Kuninori Morimotofec691e2012-02-03 00:58:48 -0800372static set_rate_func fsi_get_info_set_rate(struct fsi_priv *fsi)
Kuninori Morimotod7c57622011-01-24 10:42:33 +0900373{
Kuninori Morimotofec691e2012-02-03 00:58:48 -0800374 if (!fsi->info)
Kuninori Morimotod7c57622011-01-24 10:42:33 +0900375 return NULL;
376
Kuninori Morimotofec691e2012-02-03 00:58:48 -0800377 return fsi->info->set_rate;
Kuninori Morimotod7c57622011-01-24 10:42:33 +0900378}
379
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900380static u32 fsi_get_info_flags(struct fsi_priv *fsi)
381{
Kuninori Morimotofec691e2012-02-03 00:58:48 -0800382 if (!fsi->info)
Kuninori Morimotod7c57622011-01-24 10:42:33 +0900383 return 0;
384
Kuninori Morimotofec691e2012-02-03 00:58:48 -0800385 return fsi->info->flags;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900386}
387
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800388static u32 fsi_get_port_shift(struct fsi_priv *fsi, struct fsi_stream *io)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900389{
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800390 int is_play = fsi_stream_is_play(fsi, io);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900391 int is_porta = fsi_is_port_a(fsi);
Kuninori Morimotocf6edd02010-10-12 11:40:53 +0900392 u32 shift;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900393
394 if (is_porta)
Kuninori Morimotocf6edd02010-10-12 11:40:53 +0900395 shift = is_play ? AO_SHIFT : AI_SHIFT;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900396 else
Kuninori Morimotocf6edd02010-10-12 11:40:53 +0900397 shift = is_play ? BO_SHIFT : BI_SHIFT;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900398
Kuninori Morimotocf6edd02010-10-12 11:40:53 +0900399 return shift;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900400}
401
Kuninori Morimoto2e651ba2011-05-23 20:46:03 +0900402static int fsi_frame2sample(struct fsi_priv *fsi, int frames)
403{
404 return frames * fsi->chan_num;
405}
406
407static int fsi_sample2frame(struct fsi_priv *fsi, int samples)
408{
409 return samples / fsi->chan_num;
410}
411
Kuninori Morimoto7b1b3332012-02-03 00:55:26 -0800412static int fsi_get_current_fifo_samples(struct fsi_priv *fsi,
413 struct fsi_stream *io)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900414{
Kuninori Morimoto7b1b3332012-02-03 00:55:26 -0800415 int is_play = fsi_stream_is_play(fsi, io);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900416 u32 status;
Kuninori Morimoto2e651ba2011-05-23 20:46:03 +0900417 int frames;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900418
Kuninori Morimotoe8c8b632010-12-03 17:37:55 +0900419 status = is_play ?
420 fsi_reg_read(fsi, DOFF_ST) :
421 fsi_reg_read(fsi, DIFF_ST);
422
Kuninori Morimoto2e651ba2011-05-23 20:46:03 +0900423 frames = 0x1ff & (status >> 8);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900424
Kuninori Morimoto2e651ba2011-05-23 20:46:03 +0900425 return fsi_frame2sample(fsi, frames);
Kuninori Morimotocca1b232010-10-12 11:39:25 +0900426}
427
Kuninori Morimoto1ec9bc32010-12-17 12:55:22 +0900428static void fsi_count_fifo_err(struct fsi_priv *fsi)
429{
430 u32 ostatus = fsi_reg_read(fsi, DOFF_ST);
431 u32 istatus = fsi_reg_read(fsi, DIFF_ST);
432
433 if (ostatus & ERR_OVER)
434 fsi->playback.oerr_num++;
435
436 if (ostatus & ERR_UNDER)
437 fsi->playback.uerr_num++;
438
439 if (istatus & ERR_OVER)
440 fsi->capture.oerr_num++;
441
442 if (istatus & ERR_UNDER)
443 fsi->capture.uerr_num++;
444
445 fsi_reg_write(fsi, DOFF_ST, 0);
446 fsi_reg_write(fsi, DIFF_ST, 0);
447}
448
Kuninori Morimotob9fde182010-09-17 13:48:32 +0900449/*
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800450 * fsi_stream_xx() function
451 */
Kuninori Morimotoa449e462012-02-03 00:54:02 -0800452static inline int fsi_stream_is_play(struct fsi_priv *fsi,
453 struct fsi_stream *io)
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800454{
Kuninori Morimotoa449e462012-02-03 00:54:02 -0800455 return &fsi->playback == io;
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800456}
457
458static inline struct fsi_stream *fsi_stream_get(struct fsi_priv *fsi,
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800459 struct snd_pcm_substream *substream)
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800460{
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800461 return fsi_is_play(substream) ? &fsi->playback : &fsi->capture;
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800462}
463
464static int fsi_stream_is_working(struct fsi_priv *fsi,
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800465 struct fsi_stream *io)
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800466{
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800467 struct fsi_master *master = fsi_get_master(fsi);
468 unsigned long flags;
469 int ret;
470
471 spin_lock_irqsave(&master->lock, flags);
Kuninori Morimoto97df8182012-02-03 00:57:40 -0800472 ret = !!(io->substream && io->substream->runtime);
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800473 spin_unlock_irqrestore(&master->lock, flags);
474
475 return ret;
476}
477
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800478static struct fsi_priv *fsi_stream_to_priv(struct fsi_stream *io)
479{
480 return io->priv;
481}
482
Kuninori Morimoto8c415292012-02-03 00:52:07 -0800483static void fsi_stream_init(struct fsi_priv *fsi,
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800484 struct fsi_stream *io,
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800485 struct snd_pcm_substream *substream)
486{
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800487 struct snd_pcm_runtime *runtime = substream->runtime;
488 struct fsi_master *master = fsi_get_master(fsi);
489 unsigned long flags;
490
491 spin_lock_irqsave(&master->lock, flags);
492 io->substream = substream;
493 io->buff_sample_capa = fsi_frame2sample(fsi, runtime->buffer_size);
494 io->buff_sample_pos = 0;
495 io->period_samples = fsi_frame2sample(fsi, runtime->period_size);
496 io->period_pos = 0;
497 io->sample_width = samples_to_bytes(runtime, 1);
498 io->oerr_num = -1; /* ignore 1st err */
499 io->uerr_num = -1; /* ignore 1st err */
Kuninori Morimoto83344022012-02-03 00:59:02 -0800500 fsi_stream_handler_call(io, init, fsi, io);
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800501 spin_unlock_irqrestore(&master->lock, flags);
502}
503
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800504static void fsi_stream_quit(struct fsi_priv *fsi, struct fsi_stream *io)
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800505{
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800506 struct snd_soc_dai *dai = fsi_get_dai(io->substream);
507 struct fsi_master *master = fsi_get_master(fsi);
508 unsigned long flags;
509
510 spin_lock_irqsave(&master->lock, flags);
511
512 if (io->oerr_num > 0)
513 dev_err(dai->dev, "over_run = %d\n", io->oerr_num);
514
515 if (io->uerr_num > 0)
516 dev_err(dai->dev, "under_run = %d\n", io->uerr_num);
517
Kuninori Morimoto83344022012-02-03 00:59:02 -0800518 fsi_stream_handler_call(io, quit, fsi, io);
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800519 io->substream = NULL;
520 io->buff_sample_capa = 0;
521 io->buff_sample_pos = 0;
522 io->period_samples = 0;
523 io->period_pos = 0;
524 io->sample_width = 0;
525 io->oerr_num = 0;
526 io->uerr_num = 0;
527 spin_unlock_irqrestore(&master->lock, flags);
528}
529
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800530static int fsi_stream_transfer(struct fsi_stream *io)
531{
532 struct fsi_priv *fsi = fsi_stream_to_priv(io);
533 if (!fsi)
534 return -EIO;
535
536 return fsi_stream_handler_call(io, transfer, fsi, io);
537}
538
Kuninori Morimoto180346e2012-02-03 00:57:25 -0800539#define fsi_stream_start(fsi, io)\
540 fsi_stream_handler_call(io, start_stop, fsi, io, 1)
541
542#define fsi_stream_stop(fsi, io)\
543 fsi_stream_handler_call(io, start_stop, fsi, io, 0)
544
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800545static int fsi_stream_probe(struct fsi_priv *fsi)
546{
547 struct fsi_stream *io;
548 int ret1, ret2;
549
550 io = &fsi->playback;
551 ret1 = fsi_stream_handler_call(io, probe, fsi, io);
552
553 io = &fsi->capture;
554 ret2 = fsi_stream_handler_call(io, probe, fsi, io);
555
556 if (ret1 < 0)
557 return ret1;
558 if (ret2 < 0)
559 return ret2;
560
561 return 0;
562}
563
564static int fsi_stream_remove(struct fsi_priv *fsi)
565{
566 struct fsi_stream *io;
567 int ret1, ret2;
568
569 io = &fsi->playback;
570 ret1 = fsi_stream_handler_call(io, remove, fsi, io);
571
572 io = &fsi->capture;
573 ret2 = fsi_stream_handler_call(io, remove, fsi, io);
574
575 if (ret1 < 0)
576 return ret1;
577 if (ret2 < 0)
578 return ret2;
579
580 return 0;
581}
582
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800583/*
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +0900584 * irq function
585 */
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900586
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800587static void fsi_irq_enable(struct fsi_priv *fsi, struct fsi_stream *io)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900588{
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800589 u32 data = AB_IO(1, fsi_get_port_shift(fsi, io));
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900590 struct fsi_master *master = fsi_get_master(fsi);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900591
Kuninori Morimoto43fa95c2010-12-03 17:38:03 +0900592 fsi_core_mask_set(master, imsk, data, data);
593 fsi_core_mask_set(master, iemsk, data, data);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900594}
595
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800596static void fsi_irq_disable(struct fsi_priv *fsi, struct fsi_stream *io)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900597{
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800598 u32 data = AB_IO(1, fsi_get_port_shift(fsi, io));
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900599 struct fsi_master *master = fsi_get_master(fsi);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900600
Kuninori Morimoto43fa95c2010-12-03 17:38:03 +0900601 fsi_core_mask_set(master, imsk, data, 0);
602 fsi_core_mask_set(master, iemsk, data, 0);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900603}
604
Kuninori Morimoto10ea76c2010-03-23 11:47:54 +0900605static u32 fsi_irq_get_status(struct fsi_master *master)
606{
Kuninori Morimoto43fa95c2010-12-03 17:38:03 +0900607 return fsi_core_read(master, int_st);
Kuninori Morimoto10ea76c2010-03-23 11:47:54 +0900608}
609
Kuninori Morimoto10ea76c2010-03-23 11:47:54 +0900610static void fsi_irq_clear_status(struct fsi_priv *fsi)
611{
612 u32 data = 0;
613 struct fsi_master *master = fsi_get_master(fsi);
614
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800615 data |= AB_IO(1, fsi_get_port_shift(fsi, &fsi->playback));
616 data |= AB_IO(1, fsi_get_port_shift(fsi, &fsi->capture));
Kuninori Morimoto10ea76c2010-03-23 11:47:54 +0900617
618 /* clear interrupt factor */
Kuninori Morimoto43fa95c2010-12-03 17:38:03 +0900619 fsi_core_mask_set(master, int_st, data, 0);
Kuninori Morimoto10ea76c2010-03-23 11:47:54 +0900620}
621
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +0900622/*
623 * SPDIF master clock function
624 *
625 * These functions are used later FSI2
626 */
Kuninori Morimoto3bc28072010-07-29 16:48:32 +0900627static void fsi_spdif_clk_ctrl(struct fsi_priv *fsi, int enable)
628{
629 struct fsi_master *master = fsi_get_master(fsi);
Kuninori Morimoto2b0e7302010-12-03 17:37:44 +0900630 u32 mask, val;
Kuninori Morimoto3bc28072010-07-29 16:48:32 +0900631
632 if (master->core->ver < 2) {
633 pr_err("fsi: register access err (%s)\n", __func__);
634 return;
635 }
636
Kuninori Morimoto2b0e7302010-12-03 17:37:44 +0900637 mask = BP | SE;
638 val = enable ? mask : 0;
639
640 fsi_is_port_a(fsi) ?
Kuninori Morimoto43fa95c2010-12-03 17:38:03 +0900641 fsi_core_mask_set(master, a_mclk, mask, val) :
642 fsi_core_mask_set(master, b_mclk, mask, val);
Kuninori Morimoto3bc28072010-07-29 16:48:32 +0900643}
644
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +0900645/*
Kuninori Morimoto1f5e2a32011-04-21 10:33:52 +0900646 * clock function
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +0900647 */
Kuninori Morimoto4f56cde2011-05-23 20:46:18 +0900648static int fsi_set_master_clk(struct device *dev, struct fsi_priv *fsi,
649 long rate, int enable)
650{
651 struct fsi_master *master = fsi_get_master(fsi);
Kuninori Morimotofec691e2012-02-03 00:58:48 -0800652 set_rate_func set_rate = fsi_get_info_set_rate(fsi);
Kuninori Morimoto4f56cde2011-05-23 20:46:18 +0900653 int fsi_ver = master->core->ver;
654 int ret;
655
Kuninori Morimotofec691e2012-02-03 00:58:48 -0800656 if (!set_rate)
657 return 0;
658
659 ret = set_rate(dev, rate, enable);
Kuninori Morimoto4f56cde2011-05-23 20:46:18 +0900660 if (ret < 0) /* error */
661 return ret;
662
663 if (!enable)
664 return 0;
665
666 if (ret > 0) {
667 u32 data = 0;
668
669 switch (ret & SH_FSI_ACKMD_MASK) {
670 default:
671 /* FALL THROUGH */
672 case SH_FSI_ACKMD_512:
673 data |= (0x0 << 12);
674 break;
675 case SH_FSI_ACKMD_256:
676 data |= (0x1 << 12);
677 break;
678 case SH_FSI_ACKMD_128:
679 data |= (0x2 << 12);
680 break;
681 case SH_FSI_ACKMD_64:
682 data |= (0x3 << 12);
683 break;
684 case SH_FSI_ACKMD_32:
685 if (fsi_ver < 2)
686 dev_err(dev, "unsupported ACKMD\n");
687 else
688 data |= (0x4 << 12);
689 break;
690 }
691
692 switch (ret & SH_FSI_BPFMD_MASK) {
693 default:
694 /* FALL THROUGH */
695 case SH_FSI_BPFMD_32:
696 data |= (0x0 << 8);
697 break;
698 case SH_FSI_BPFMD_64:
699 data |= (0x1 << 8);
700 break;
701 case SH_FSI_BPFMD_128:
702 data |= (0x2 << 8);
703 break;
704 case SH_FSI_BPFMD_256:
705 data |= (0x3 << 8);
706 break;
707 case SH_FSI_BPFMD_512:
708 data |= (0x4 << 8);
709 break;
710 case SH_FSI_BPFMD_16:
711 if (fsi_ver < 2)
712 dev_err(dev, "unsupported ACKMD\n");
713 else
714 data |= (0x7 << 8);
715 break;
716 }
717
718 fsi_reg_mask_set(fsi, CKG1, (ACKMD_MASK | BPFMD_MASK) , data);
719 udelay(10);
720 ret = 0;
721 }
722
723 return ret;
Kuninori Morimoto4f56cde2011-05-23 20:46:18 +0900724}
725
Kuninori Morimoto1f5e2a32011-04-21 10:33:52 +0900726/*
Kuninori Morimoto1b0ca1a2012-02-03 00:56:27 -0800727 * pio data transfer handler
Kuninori Morimoto1f5e2a32011-04-21 10:33:52 +0900728 */
Kuninori Morimoto1b0ca1a2012-02-03 00:56:27 -0800729static void fsi_pio_push16(struct fsi_priv *fsi, u8 *_buf, int samples)
730{
731 u16 *buf = (u16 *)_buf;
732 int i;
733
734 for (i = 0; i < samples; i++)
735 fsi_reg_write(fsi, DODT, ((u32)*(buf + i) << 8));
736}
737
738static void fsi_pio_pop16(struct fsi_priv *fsi, u8 *_buf, int samples)
739{
740 u16 *buf = (u16 *)_buf;
741 int i;
742
743 for (i = 0; i < samples; i++)
744 *(buf + i) = (u16)(fsi_reg_read(fsi, DIDT) >> 8);
745}
746
747static void fsi_pio_push32(struct fsi_priv *fsi, u8 *_buf, int samples)
748{
749 u32 *buf = (u32 *)_buf;
750 int i;
751
752 for (i = 0; i < samples; i++)
753 fsi_reg_write(fsi, DODT, *(buf + i));
754}
755
756static void fsi_pio_pop32(struct fsi_priv *fsi, u8 *_buf, int samples)
757{
758 u32 *buf = (u32 *)_buf;
759 int i;
760
761 for (i = 0; i < samples; i++)
762 *(buf + i) = fsi_reg_read(fsi, DIDT);
763}
764
765static u8 *fsi_pio_get_area(struct fsi_priv *fsi, struct fsi_stream *io)
766{
767 struct snd_pcm_runtime *runtime = io->substream->runtime;
768
769 return runtime->dma_area +
770 samples_to_bytes(runtime, io->buff_sample_pos);
771}
772
773static int fsi_pio_transfer(struct fsi_priv *fsi, struct fsi_stream *io,
Kuninori Morimoto95b0cf02012-02-03 00:52:38 -0800774 void (*run16)(struct fsi_priv *fsi, u8 *buf, int samples),
775 void (*run32)(struct fsi_priv *fsi, u8 *buf, int samples),
776 int samples)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900777{
778 struct snd_pcm_runtime *runtime;
Kuninori Morimoto376cf382012-02-03 00:50:59 -0800779 struct snd_pcm_substream *substream;
Kuninori Morimoto95b0cf02012-02-03 00:52:38 -0800780 u8 *buf;
Kuninori Morimotob9fde182010-09-17 13:48:32 +0900781 int over_period;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900782
Kuninori Morimoto97df8182012-02-03 00:57:40 -0800783 if (!fsi_stream_is_working(fsi, io))
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900784 return -EINVAL;
785
Kuninori Morimoto1c418d12009-12-28 14:09:05 +0900786 over_period = 0;
Kuninori Morimoto93193c22010-10-12 19:19:28 +0900787 substream = io->substream;
Kuninori Morimoto1c418d12009-12-28 14:09:05 +0900788 runtime = substream->runtime;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900789
790 /* FSI FIFO has limit.
791 * So, this driver can not send periods data at a time
792 */
Kuninori Morimoto2e651ba2011-05-23 20:46:03 +0900793 if (io->buff_sample_pos >=
794 io->period_samples * (io->period_pos + 1)) {
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900795
Kuninori Morimoto1c418d12009-12-28 14:09:05 +0900796 over_period = 1;
Kuninori Morimoto2e651ba2011-05-23 20:46:03 +0900797 io->period_pos = (io->period_pos + 1) % runtime->periods;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900798
Kuninori Morimoto2e651ba2011-05-23 20:46:03 +0900799 if (0 == io->period_pos)
800 io->buff_sample_pos = 0;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900801 }
802
Kuninori Morimoto95b0cf02012-02-03 00:52:38 -0800803 buf = fsi_pio_get_area(fsi, io);
804
Kuninori Morimoto376cf382012-02-03 00:50:59 -0800805 switch (io->sample_width) {
806 case 2:
Kuninori Morimoto95b0cf02012-02-03 00:52:38 -0800807 run16(fsi, buf, samples);
Kuninori Morimoto376cf382012-02-03 00:50:59 -0800808 break;
809 case 4:
Kuninori Morimoto95b0cf02012-02-03 00:52:38 -0800810 run32(fsi, buf, samples);
Kuninori Morimoto376cf382012-02-03 00:50:59 -0800811 break;
812 default:
813 return -EINVAL;
Kuninori Morimoto9ddc9aa2009-10-30 12:02:39 +0900814 }
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900815
Kuninori Morimoto2e651ba2011-05-23 20:46:03 +0900816 /* update buff_sample_pos */
817 io->buff_sample_pos += samples;
Kuninori Morimotod8b33532010-09-17 13:49:05 +0900818
Kuninori Morimoto1c418d12009-12-28 14:09:05 +0900819 if (over_period)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900820 snd_pcm_period_elapsed(substream);
821
Kuninori Morimoto47fc9a02010-02-22 16:41:57 +0900822 return 0;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900823}
824
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800825static int fsi_pio_pop(struct fsi_priv *fsi, struct fsi_stream *io)
Kuninori Morimoto07102f32009-10-30 12:02:44 +0900826{
Kuninori Morimoto376cf382012-02-03 00:50:59 -0800827 int sample_residues; /* samples in FSI fifo */
828 int sample_space; /* ALSA free samples space */
829 int samples;
Kuninori Morimoto376cf382012-02-03 00:50:59 -0800830
Kuninori Morimoto7b1b3332012-02-03 00:55:26 -0800831 sample_residues = fsi_get_current_fifo_samples(fsi, io);
Kuninori Morimoto376cf382012-02-03 00:50:59 -0800832 sample_space = io->buff_sample_capa - io->buff_sample_pos;
833
834 samples = min(sample_residues, sample_space);
835
Kuninori Morimoto1b0ca1a2012-02-03 00:56:27 -0800836 return fsi_pio_transfer(fsi, io,
Kuninori Morimotod78629e2012-02-03 00:51:14 -0800837 fsi_pio_pop16,
838 fsi_pio_pop32,
Kuninori Morimoto376cf382012-02-03 00:50:59 -0800839 samples);
Kuninori Morimotod8b33532010-09-17 13:49:05 +0900840}
Kuninori Morimoto07102f32009-10-30 12:02:44 +0900841
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800842static int fsi_pio_push(struct fsi_priv *fsi, struct fsi_stream *io)
Kuninori Morimotod8b33532010-09-17 13:49:05 +0900843{
Kuninori Morimoto376cf382012-02-03 00:50:59 -0800844 int sample_residues; /* ALSA residue samples */
845 int sample_space; /* FSI fifo free samples space */
846 int samples;
Kuninori Morimoto376cf382012-02-03 00:50:59 -0800847
848 sample_residues = io->buff_sample_capa - io->buff_sample_pos;
849 sample_space = io->fifo_sample_capa -
Kuninori Morimoto7b1b3332012-02-03 00:55:26 -0800850 fsi_get_current_fifo_samples(fsi, io);
Kuninori Morimoto376cf382012-02-03 00:50:59 -0800851
852 samples = min(sample_residues, sample_space);
853
Kuninori Morimoto1b0ca1a2012-02-03 00:56:27 -0800854 return fsi_pio_transfer(fsi, io,
Kuninori Morimotod78629e2012-02-03 00:51:14 -0800855 fsi_pio_push16,
856 fsi_pio_push32,
Kuninori Morimoto376cf382012-02-03 00:50:59 -0800857 samples);
Kuninori Morimoto07102f32009-10-30 12:02:44 +0900858}
859
Kuninori Morimoto180346e2012-02-03 00:57:25 -0800860static void fsi_pio_start_stop(struct fsi_priv *fsi, struct fsi_stream *io,
861 int enable)
862{
863 struct fsi_master *master = fsi_get_master(fsi);
864 u32 clk = fsi_is_port_a(fsi) ? CRA : CRB;
865
866 if (enable)
867 fsi_irq_enable(fsi, io);
868 else
869 fsi_irq_disable(fsi, io);
870
871 if (fsi_is_clk_master(fsi))
872 fsi_master_mask_set(master, CLK_RST, clk, (enable) ? clk : 0);
873}
874
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800875static struct fsi_stream_handler fsi_pio_push_handler = {
876 .transfer = fsi_pio_push,
Kuninori Morimoto180346e2012-02-03 00:57:25 -0800877 .start_stop = fsi_pio_start_stop,
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800878};
879
880static struct fsi_stream_handler fsi_pio_pop_handler = {
881 .transfer = fsi_pio_pop,
Kuninori Morimoto180346e2012-02-03 00:57:25 -0800882 .start_stop = fsi_pio_start_stop,
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800883};
884
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900885static irqreturn_t fsi_interrupt(int irq, void *data)
886{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900887 struct fsi_master *master = data;
Kuninori Morimoto10ea76c2010-03-23 11:47:54 +0900888 u32 int_st = fsi_irq_get_status(master);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900889
890 /* clear irq status */
Kuninori Morimotofeb58cf2010-03-24 15:27:24 +0900891 fsi_master_mask_set(master, SOFT_RST, IR, 0);
892 fsi_master_mask_set(master, SOFT_RST, IR, IR);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900893
Kuninori Morimotocf6edd02010-10-12 11:40:53 +0900894 if (int_st & AB_IO(1, AO_SHIFT))
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800895 fsi_stream_transfer(&master->fsia.playback);
Kuninori Morimotocf6edd02010-10-12 11:40:53 +0900896 if (int_st & AB_IO(1, BO_SHIFT))
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800897 fsi_stream_transfer(&master->fsib.playback);
Kuninori Morimotocf6edd02010-10-12 11:40:53 +0900898 if (int_st & AB_IO(1, AI_SHIFT))
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800899 fsi_stream_transfer(&master->fsia.capture);
Kuninori Morimotocf6edd02010-10-12 11:40:53 +0900900 if (int_st & AB_IO(1, BI_SHIFT))
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800901 fsi_stream_transfer(&master->fsib.capture);
Kuninori Morimoto1ec9bc32010-12-17 12:55:22 +0900902
903 fsi_count_fifo_err(&master->fsia);
904 fsi_count_fifo_err(&master->fsib);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900905
Kuninori Morimoto48d78e52010-12-03 17:37:31 +0900906 fsi_irq_clear_status(&master->fsia);
907 fsi_irq_clear_status(&master->fsib);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900908
909 return IRQ_HANDLED;
910}
911
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +0900912/*
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -0800913 * dma data transfer handler
914 */
915static int fsi_dma_init(struct fsi_priv *fsi, struct fsi_stream *io)
916{
917 struct snd_pcm_runtime *runtime = io->substream->runtime;
918 struct snd_soc_dai *dai = fsi_get_dai(io->substream);
919 enum dma_data_direction dir = fsi_stream_is_play(fsi, io) ?
920 DMA_TO_DEVICE : DMA_FROM_DEVICE;
921
922 io->dma = dma_map_single(dai->dev, runtime->dma_area,
923 snd_pcm_lib_buffer_bytes(io->substream), dir);
924 return 0;
925}
926
927static int fsi_dma_quit(struct fsi_priv *fsi, struct fsi_stream *io)
928{
929 struct snd_soc_dai *dai = fsi_get_dai(io->substream);
930 enum dma_data_direction dir = fsi_stream_is_play(fsi, io) ?
931 DMA_TO_DEVICE : DMA_FROM_DEVICE;
932
933 dma_unmap_single(dai->dev, io->dma,
934 snd_pcm_lib_buffer_bytes(io->substream), dir);
935 return 0;
936}
937
938static void fsi_dma_complete(void *data)
939{
940 struct fsi_stream *io = (struct fsi_stream *)data;
941 struct fsi_priv *fsi = fsi_stream_to_priv(io);
942 struct snd_pcm_runtime *runtime = io->substream->runtime;
943 struct snd_soc_dai *dai = fsi_get_dai(io->substream);
944 enum dma_data_direction dir = fsi_stream_is_play(fsi, io) ?
945 DMA_TO_DEVICE : DMA_FROM_DEVICE;
946
947 dma_sync_single_for_cpu(dai->dev, io->dma,
948 samples_to_bytes(runtime, io->period_samples), dir);
949
950 io->buff_sample_pos += io->period_samples;
951 io->period_pos++;
952
953 if (io->period_pos >= runtime->periods) {
954 io->period_pos = 0;
955 io->buff_sample_pos = 0;
956 }
957
958 fsi_count_fifo_err(fsi);
959 fsi_stream_transfer(io);
960
961 snd_pcm_period_elapsed(io->substream);
962}
963
964static dma_addr_t fsi_dma_get_area(struct fsi_stream *io)
965{
966 struct snd_pcm_runtime *runtime = io->substream->runtime;
967
968 return io->dma + samples_to_bytes(runtime, io->buff_sample_pos);
969}
970
971static void fsi_dma_do_tasklet(unsigned long data)
972{
973 struct fsi_stream *io = (struct fsi_stream *)data;
974 struct fsi_priv *fsi = fsi_stream_to_priv(io);
975 struct dma_chan *chan;
976 struct snd_soc_dai *dai;
977 struct dma_async_tx_descriptor *desc;
978 struct scatterlist sg;
979 struct snd_pcm_runtime *runtime;
980 enum dma_data_direction dir;
981 dma_cookie_t cookie;
982 int is_play = fsi_stream_is_play(fsi, io);
983 int len;
984 dma_addr_t buf;
985
986 if (!fsi_stream_is_working(fsi, io))
987 return;
988
989 dai = fsi_get_dai(io->substream);
990 chan = io->chan;
991 runtime = io->substream->runtime;
992 dir = is_play ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
993 len = samples_to_bytes(runtime, io->period_samples);
994 buf = fsi_dma_get_area(io);
995
996 dma_sync_single_for_device(dai->dev, io->dma, len, dir);
997
998 sg_init_table(&sg, 1);
999 sg_set_page(&sg, pfn_to_page(PFN_DOWN(buf)),
1000 len , offset_in_page(buf));
1001 sg_dma_address(&sg) = buf;
1002 sg_dma_len(&sg) = len;
1003
1004 desc = chan->device->device_prep_slave_sg(chan, &sg, 1, dir,
1005 DMA_PREP_INTERRUPT |
1006 DMA_CTRL_ACK);
1007 if (!desc) {
1008 dev_err(dai->dev, "device_prep_slave_sg() fail\n");
1009 return;
1010 }
1011
1012 desc->callback = fsi_dma_complete;
1013 desc->callback_param = io;
1014
1015 cookie = desc->tx_submit(desc);
1016 if (cookie < 0) {
1017 dev_err(dai->dev, "tx_submit() fail\n");
1018 return;
1019 }
1020
1021 dma_async_issue_pending(chan);
1022
1023 /*
1024 * FIXME
1025 *
1026 * In DMAEngine case, codec and FSI cannot be started simultaneously
1027 * since FSI is using tasklet.
1028 * Therefore, in capture case, probably FSI FIFO will have got
1029 * overflow error in this point.
1030 * in that case, DMA cannot start transfer until error was cleared.
1031 */
1032 if (!is_play) {
1033 if (ERR_OVER & fsi_reg_read(fsi, DIFF_ST)) {
1034 fsi_reg_mask_set(fsi, DIFF_CTL, FIFO_CLR, FIFO_CLR);
1035 fsi_reg_write(fsi, DIFF_ST, 0);
1036 }
1037 }
1038}
1039
1040static bool fsi_dma_filter(struct dma_chan *chan, void *param)
1041{
1042 struct sh_dmae_slave *slave = param;
1043
1044 chan->private = slave;
1045
1046 return true;
1047}
1048
1049static int fsi_dma_transfer(struct fsi_priv *fsi, struct fsi_stream *io)
1050{
1051 tasklet_schedule(&io->tasklet);
1052
1053 return 0;
1054}
1055
1056static void fsi_dma_push_start_stop(struct fsi_priv *fsi, struct fsi_stream *io,
1057 int start)
1058{
1059 u32 bws;
1060 u32 dma;
1061
1062 switch (io->sample_width * start) {
1063 case 2:
1064 bws = CR_BWS_16;
1065 dma = VDMD_STREAM | DMA_ON;
1066 break;
1067 case 4:
1068 bws = CR_BWS_24;
1069 dma = VDMD_BACK | DMA_ON;
1070 break;
1071 default:
1072 bws = 0;
1073 dma = 0;
1074 }
1075
1076 fsi_reg_mask_set(fsi, DO_FMT, CR_BWS_MASK, bws);
1077 fsi_reg_write(fsi, OUT_DMAC, dma);
1078}
1079
1080static int fsi_dma_probe(struct fsi_priv *fsi, struct fsi_stream *io)
1081{
1082 dma_cap_mask_t mask;
1083
1084 dma_cap_zero(mask);
1085 dma_cap_set(DMA_SLAVE, mask);
1086
1087 io->chan = dma_request_channel(mask, fsi_dma_filter, &io->slave);
1088 if (!io->chan)
1089 return -EIO;
1090
1091 tasklet_init(&io->tasklet, fsi_dma_do_tasklet, (unsigned long)io);
1092
1093 return 0;
1094}
1095
1096static int fsi_dma_remove(struct fsi_priv *fsi, struct fsi_stream *io)
1097{
1098 tasklet_kill(&io->tasklet);
1099
1100 fsi_stream_stop(fsi, io);
1101
1102 if (io->chan)
1103 dma_release_channel(io->chan);
1104
1105 io->chan = NULL;
1106 return 0;
1107}
1108
1109static struct fsi_stream_handler fsi_dma_push_handler = {
1110 .init = fsi_dma_init,
1111 .quit = fsi_dma_quit,
1112 .probe = fsi_dma_probe,
1113 .transfer = fsi_dma_transfer,
1114 .remove = fsi_dma_remove,
1115 .start_stop = fsi_dma_push_start_stop,
1116};
1117
1118/*
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +09001119 * dai ops
1120 */
Kuninori Morimotob49e8022012-02-03 00:51:29 -08001121static void fsi_fifo_init(struct fsi_priv *fsi,
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001122 struct fsi_stream *io,
Kuninori Morimotob49e8022012-02-03 00:51:29 -08001123 struct device *dev)
1124{
1125 struct fsi_master *master = fsi_get_master(fsi);
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001126 int is_play = fsi_stream_is_play(fsi, io);
Kuninori Morimotob49e8022012-02-03 00:51:29 -08001127 u32 shift, i;
1128 int frame_capa;
1129
1130 /* get on-chip RAM capacity */
1131 shift = fsi_master_read(master, FIFO_SZ);
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001132 shift >>= fsi_get_port_shift(fsi, io);
Kuninori Morimotob49e8022012-02-03 00:51:29 -08001133 shift &= FIFO_SZ_MASK;
1134 frame_capa = 256 << shift;
1135 dev_dbg(dev, "fifo = %d words\n", frame_capa);
1136
1137 /*
1138 * The maximum number of sample data varies depending
1139 * on the number of channels selected for the format.
1140 *
1141 * FIFOs are used in 4-channel units in 3-channel mode
1142 * and in 8-channel units in 5- to 7-channel mode
1143 * meaning that more FIFOs than the required size of DPRAM
1144 * are used.
1145 *
1146 * ex) if 256 words of DP-RAM is connected
1147 * 1 channel: 256 (256 x 1 = 256)
1148 * 2 channels: 128 (128 x 2 = 256)
1149 * 3 channels: 64 ( 64 x 3 = 192)
1150 * 4 channels: 64 ( 64 x 4 = 256)
1151 * 5 channels: 32 ( 32 x 5 = 160)
1152 * 6 channels: 32 ( 32 x 6 = 192)
1153 * 7 channels: 32 ( 32 x 7 = 224)
1154 * 8 channels: 32 ( 32 x 8 = 256)
1155 */
1156 for (i = 1; i < fsi->chan_num; i <<= 1)
1157 frame_capa >>= 1;
1158 dev_dbg(dev, "%d channel %d store\n",
1159 fsi->chan_num, frame_capa);
1160
1161 io->fifo_sample_capa = fsi_frame2sample(fsi, frame_capa);
1162
1163 /*
1164 * set interrupt generation factor
1165 * clear FIFO
1166 */
1167 if (is_play) {
1168 fsi_reg_write(fsi, DOFF_CTL, IRQ_HALF);
1169 fsi_reg_mask_set(fsi, DOFF_CTL, FIFO_CLR, FIFO_CLR);
1170 } else {
1171 fsi_reg_write(fsi, DIFF_CTL, IRQ_HALF);
1172 fsi_reg_mask_set(fsi, DIFF_CTL, FIFO_CLR, FIFO_CLR);
1173 }
1174}
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001175
Kuninori Morimoto23ca8532011-05-23 20:46:26 +09001176static int fsi_hw_startup(struct fsi_priv *fsi,
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001177 struct fsi_stream *io,
Kuninori Morimoto23ca8532011-05-23 20:46:26 +09001178 struct device *dev)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001179{
Kuninori Morimoto65ff03f2011-11-06 22:05:25 -08001180 struct fsi_master *master = fsi_get_master(fsi);
1181 int fsi_ver = master->core->ver;
Kuninori Morimoto93193c22010-10-12 19:19:28 +09001182 u32 flags = fsi_get_info_flags(fsi);
Kuninori Morimoto9478e0b2011-05-23 20:46:07 +09001183 u32 data = 0;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001184
Kuninori Morimoto9478e0b2011-05-23 20:46:07 +09001185 /* clock setting */
1186 if (fsi_is_clk_master(fsi))
1187 data = DIMD | DOMD;
1188
1189 fsi_reg_mask_set(fsi, CKG1, (DIMD | DOMD), data);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001190
1191 /* clock inversion (CKG2) */
1192 data = 0;
Kuninori Morimotob427b442010-07-13 12:01:15 +09001193 if (SH_FSI_LRM_INV & flags)
1194 data |= 1 << 12;
1195 if (SH_FSI_BRM_INV & flags)
1196 data |= 1 << 8;
1197 if (SH_FSI_LRS_INV & flags)
1198 data |= 1 << 4;
1199 if (SH_FSI_BRS_INV & flags)
1200 data |= 1 << 0;
1201
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001202 fsi_reg_write(fsi, CKG2, data);
1203
Kuninori Morimoto9478e0b2011-05-23 20:46:07 +09001204 /* set format */
1205 fsi_reg_write(fsi, DO_FMT, fsi->do_fmt);
1206 fsi_reg_write(fsi, DI_FMT, fsi->di_fmt);
1207
1208 /* spdif ? */
1209 if (fsi_is_spdif(fsi)) {
1210 fsi_spdif_clk_ctrl(fsi, 1);
1211 fsi_reg_mask_set(fsi, OUT_SEL, DMMD, DMMD);
1212 }
1213
Kuninori Morimoto65ff03f2011-11-06 22:05:25 -08001214 /*
1215 * FIXME
1216 *
1217 * FSI driver assumed that data package is in-back.
1218 * FSI2 chip can select it.
1219 */
1220 if (fsi_ver >= 2) {
1221 fsi_reg_write(fsi, OUT_DMAC, (1 << 4));
1222 fsi_reg_write(fsi, IN_DMAC, (1 << 4));
1223 }
1224
Kuninori Morimoto10ea76c2010-03-23 11:47:54 +09001225 /* irq clear */
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001226 fsi_irq_disable(fsi, io);
Kuninori Morimoto10ea76c2010-03-23 11:47:54 +09001227 fsi_irq_clear_status(fsi);
1228
1229 /* fifo init */
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001230 fsi_fifo_init(fsi, io, dev);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001231
Kuninori Morimotoa68a3b42010-10-12 11:39:50 +09001232 return 0;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001233}
1234
Kuninori Morimoto23ca8532011-05-23 20:46:26 +09001235static void fsi_hw_shutdown(struct fsi_priv *fsi,
Kuninori Morimoto23ca8532011-05-23 20:46:26 +09001236 struct device *dev)
1237{
1238 if (fsi_is_clk_master(fsi))
1239 fsi_set_master_clk(dev, fsi, fsi->rate, 0);
Kuninori Morimoto23ca8532011-05-23 20:46:26 +09001240}
1241
1242static int fsi_dai_startup(struct snd_pcm_substream *substream,
1243 struct snd_soc_dai *dai)
1244{
1245 struct fsi_priv *fsi = fsi_get_priv(substream);
Kuninori Morimoto23ca8532011-05-23 20:46:26 +09001246
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001247 return fsi_hw_startup(fsi, fsi_stream_get(fsi, substream), dai->dev);
Kuninori Morimoto23ca8532011-05-23 20:46:26 +09001248}
1249
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001250static void fsi_dai_shutdown(struct snd_pcm_substream *substream,
1251 struct snd_soc_dai *dai)
1252{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +09001253 struct fsi_priv *fsi = fsi_get_priv(substream);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001254
Kuninori Morimoto41bba152012-02-03 00:51:53 -08001255 fsi_hw_shutdown(fsi, dai->dev);
Kuninori Morimotod4bc99b2010-11-24 02:44:06 +00001256 fsi->rate = 0;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001257}
1258
1259static int fsi_dai_trigger(struct snd_pcm_substream *substream, int cmd,
1260 struct snd_soc_dai *dai)
1261{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +09001262 struct fsi_priv *fsi = fsi_get_priv(substream);
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001263 struct fsi_stream *io = fsi_stream_get(fsi, substream);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001264 int ret = 0;
1265
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001266 switch (cmd) {
1267 case SNDRV_PCM_TRIGGER_START:
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001268 fsi_stream_init(fsi, io, substream);
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001269 ret = fsi_stream_transfer(io);
1270 if (0 == ret)
Kuninori Morimoto180346e2012-02-03 00:57:25 -08001271 fsi_stream_start(fsi, io);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001272 break;
1273 case SNDRV_PCM_TRIGGER_STOP:
Kuninori Morimoto180346e2012-02-03 00:57:25 -08001274 fsi_stream_stop(fsi, io);
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001275 fsi_stream_quit(fsi, io);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001276 break;
1277 }
1278
1279 return ret;
1280}
1281
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001282static int fsi_set_fmt_dai(struct fsi_priv *fsi, unsigned int fmt)
1283{
1284 u32 data = 0;
1285
1286 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
1287 case SND_SOC_DAIFMT_I2S:
1288 data = CR_I2S;
1289 fsi->chan_num = 2;
1290 break;
1291 case SND_SOC_DAIFMT_LEFT_J:
1292 data = CR_PCM;
1293 fsi->chan_num = 2;
1294 break;
1295 default:
1296 return -EINVAL;
1297 }
1298
Kuninori Morimoto9478e0b2011-05-23 20:46:07 +09001299 fsi->do_fmt = data;
1300 fsi->di_fmt = data;
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001301
1302 return 0;
1303}
1304
1305static int fsi_set_fmt_spdif(struct fsi_priv *fsi)
1306{
1307 struct fsi_master *master = fsi_get_master(fsi);
1308 u32 data = 0;
1309
1310 if (master->core->ver < 2)
1311 return -EINVAL;
1312
1313 data = CR_BWS_16 | CR_DTMD_SPDIF_PCM | CR_PCM;
1314 fsi->chan_num = 2;
Kuninori Morimoto9478e0b2011-05-23 20:46:07 +09001315 fsi->spdif = 1;
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001316
Kuninori Morimoto9478e0b2011-05-23 20:46:07 +09001317 fsi->do_fmt = data;
1318 fsi->di_fmt = data;
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001319
1320 return 0;
1321}
1322
Kuninori Morimoto4d805f72011-01-20 11:46:02 +09001323static int fsi_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
1324{
1325 struct fsi_priv *fsi = fsi_get_priv_frm_dai(dai);
Kuninori Morimotofec691e2012-02-03 00:58:48 -08001326 set_rate_func set_rate = fsi_get_info_set_rate(fsi);
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001327 u32 flags = fsi_get_info_flags(fsi);
Kuninori Morimoto4d805f72011-01-20 11:46:02 +09001328 int ret;
1329
Kuninori Morimoto4d805f72011-01-20 11:46:02 +09001330 /* set master/slave audio interface */
1331 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1332 case SND_SOC_DAIFMT_CBM_CFM:
Kuninori Morimoto6a9ebad2011-04-21 10:33:36 +09001333 fsi->clk_master = 1;
Kuninori Morimoto4d805f72011-01-20 11:46:02 +09001334 break;
1335 case SND_SOC_DAIFMT_CBS_CFS:
1336 break;
1337 default:
Kuninori Morimoto9478e0b2011-05-23 20:46:07 +09001338 return -EINVAL;
Kuninori Morimoto4d805f72011-01-20 11:46:02 +09001339 }
Kuninori Morimoto6a9ebad2011-04-21 10:33:36 +09001340
1341 if (fsi_is_clk_master(fsi) && !set_rate) {
1342 dev_err(dai->dev, "platform doesn't have set_rate\n");
Kuninori Morimoto9478e0b2011-05-23 20:46:07 +09001343 return -EINVAL;
Kuninori Morimoto6a9ebad2011-04-21 10:33:36 +09001344 }
1345
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001346 /* set format */
1347 switch (flags & SH_FSI_FMT_MASK) {
1348 case SH_FSI_FMT_DAI:
1349 ret = fsi_set_fmt_dai(fsi, fmt & SND_SOC_DAIFMT_FORMAT_MASK);
1350 break;
1351 case SH_FSI_FMT_SPDIF:
1352 ret = fsi_set_fmt_spdif(fsi);
1353 break;
1354 default:
1355 ret = -EINVAL;
1356 }
Kuninori Morimoto4d805f72011-01-20 11:46:02 +09001357
Kuninori Morimoto4d805f72011-01-20 11:46:02 +09001358 return ret;
1359}
1360
Kuninori Morimotoccad7b42010-07-13 12:13:14 +09001361static int fsi_dai_hw_params(struct snd_pcm_substream *substream,
1362 struct snd_pcm_hw_params *params,
1363 struct snd_soc_dai *dai)
1364{
1365 struct fsi_priv *fsi = fsi_get_priv(substream);
Kuninori Morimotod4bc99b2010-11-24 02:44:06 +00001366 long rate = params_rate(params);
Kuninori Morimotoccad7b42010-07-13 12:13:14 +09001367 int ret;
1368
Kuninori Morimoto6a9ebad2011-04-21 10:33:36 +09001369 if (!fsi_is_clk_master(fsi))
Kuninori Morimotoccad7b42010-07-13 12:13:14 +09001370 return 0;
1371
Kuninori Morimoto4f56cde2011-05-23 20:46:18 +09001372 ret = fsi_set_master_clk(dai->dev, fsi, rate, 1);
1373 if (ret < 0)
Kuninori Morimotod4bc99b2010-11-24 02:44:06 +00001374 return ret;
Kuninori Morimotoccad7b42010-07-13 12:13:14 +09001375
Kuninori Morimotod4bc99b2010-11-24 02:44:06 +00001376 fsi->rate = rate;
Kuninori Morimotoccad7b42010-07-13 12:13:14 +09001377
1378 return ret;
Kuninori Morimotoccad7b42010-07-13 12:13:14 +09001379}
1380
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01001381static const struct snd_soc_dai_ops fsi_dai_ops = {
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001382 .startup = fsi_dai_startup,
1383 .shutdown = fsi_dai_shutdown,
1384 .trigger = fsi_dai_trigger,
Kuninori Morimoto4d805f72011-01-20 11:46:02 +09001385 .set_fmt = fsi_dai_set_fmt,
Kuninori Morimotoccad7b42010-07-13 12:13:14 +09001386 .hw_params = fsi_dai_hw_params,
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001387};
1388
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +09001389/*
1390 * pcm ops
1391 */
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001392
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001393static struct snd_pcm_hardware fsi_pcm_hardware = {
1394 .info = SNDRV_PCM_INFO_INTERLEAVED |
1395 SNDRV_PCM_INFO_MMAP |
1396 SNDRV_PCM_INFO_MMAP_VALID |
1397 SNDRV_PCM_INFO_PAUSE,
1398 .formats = FSI_FMTS,
1399 .rates = FSI_RATES,
1400 .rate_min = 8000,
1401 .rate_max = 192000,
1402 .channels_min = 1,
1403 .channels_max = 2,
1404 .buffer_bytes_max = 64 * 1024,
1405 .period_bytes_min = 32,
1406 .period_bytes_max = 8192,
1407 .periods_min = 1,
1408 .periods_max = 32,
1409 .fifo_size = 256,
1410};
1411
1412static int fsi_pcm_open(struct snd_pcm_substream *substream)
1413{
1414 struct snd_pcm_runtime *runtime = substream->runtime;
1415 int ret = 0;
1416
1417 snd_soc_set_runtime_hwparams(substream, &fsi_pcm_hardware);
1418
1419 ret = snd_pcm_hw_constraint_integer(runtime,
1420 SNDRV_PCM_HW_PARAM_PERIODS);
1421
1422 return ret;
1423}
1424
1425static int fsi_hw_params(struct snd_pcm_substream *substream,
1426 struct snd_pcm_hw_params *hw_params)
1427{
1428 return snd_pcm_lib_malloc_pages(substream,
1429 params_buffer_bytes(hw_params));
1430}
1431
1432static int fsi_hw_free(struct snd_pcm_substream *substream)
1433{
1434 return snd_pcm_lib_free_pages(substream);
1435}
1436
1437static snd_pcm_uframes_t fsi_pointer(struct snd_pcm_substream *substream)
1438{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +09001439 struct fsi_priv *fsi = fsi_get_priv(substream);
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001440 struct fsi_stream *io = fsi_stream_get(fsi, substream);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001441
Kuninori Morimoto19878772012-02-08 16:57:29 -08001442 return fsi_sample2frame(fsi, io->buff_sample_pos);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001443}
1444
1445static struct snd_pcm_ops fsi_pcm_ops = {
1446 .open = fsi_pcm_open,
1447 .ioctl = snd_pcm_lib_ioctl,
1448 .hw_params = fsi_hw_params,
1449 .hw_free = fsi_hw_free,
1450 .pointer = fsi_pointer,
1451};
1452
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +09001453/*
1454 * snd_soc_platform
1455 */
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001456
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001457#define PREALLOC_BUFFER (32 * 1024)
1458#define PREALLOC_BUFFER_MAX (32 * 1024)
1459
1460static void fsi_pcm_free(struct snd_pcm *pcm)
1461{
1462 snd_pcm_lib_preallocate_free_for_all(pcm);
1463}
1464
Liam Girdwood552d1ef2011-06-07 16:08:33 +01001465static int fsi_pcm_new(struct snd_soc_pcm_runtime *rtd)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001466{
Liam Girdwood552d1ef2011-06-07 16:08:33 +01001467 struct snd_pcm *pcm = rtd->pcm;
1468
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001469 /*
1470 * dont use SNDRV_DMA_TYPE_DEV, since it will oops the SH kernel
1471 * in MMAP mode (i.e. aplay -M)
1472 */
1473 return snd_pcm_lib_preallocate_pages_for_all(
1474 pcm,
1475 SNDRV_DMA_TYPE_CONTINUOUS,
1476 snd_dma_continuous_data(GFP_KERNEL),
1477 PREALLOC_BUFFER, PREALLOC_BUFFER_MAX);
1478}
1479
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +09001480/*
1481 * alsa struct
1482 */
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001483
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001484static struct snd_soc_dai_driver fsi_soc_dai[] = {
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001485 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001486 .name = "fsia-dai",
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001487 .playback = {
1488 .rates = FSI_RATES,
1489 .formats = FSI_FMTS,
1490 .channels_min = 1,
1491 .channels_max = 8,
1492 },
Kuninori Morimoto07102f32009-10-30 12:02:44 +09001493 .capture = {
1494 .rates = FSI_RATES,
1495 .formats = FSI_FMTS,
1496 .channels_min = 1,
1497 .channels_max = 8,
1498 },
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001499 .ops = &fsi_dai_ops,
1500 },
1501 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001502 .name = "fsib-dai",
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001503 .playback = {
1504 .rates = FSI_RATES,
1505 .formats = FSI_FMTS,
1506 .channels_min = 1,
1507 .channels_max = 8,
1508 },
Kuninori Morimoto07102f32009-10-30 12:02:44 +09001509 .capture = {
1510 .rates = FSI_RATES,
1511 .formats = FSI_FMTS,
1512 .channels_min = 1,
1513 .channels_max = 8,
1514 },
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001515 .ops = &fsi_dai_ops,
1516 },
1517};
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001518
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001519static struct snd_soc_platform_driver fsi_soc_platform = {
1520 .ops = &fsi_pcm_ops,
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001521 .pcm_new = fsi_pcm_new,
1522 .pcm_free = fsi_pcm_free,
1523};
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001524
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +09001525/*
1526 * platform function
1527 */
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001528static void fsi_handler_init(struct fsi_priv *fsi)
1529{
1530 fsi->playback.handler = &fsi_pio_push_handler; /* default PIO */
1531 fsi->playback.priv = fsi;
1532 fsi->capture.handler = &fsi_pio_pop_handler; /* default PIO */
1533 fsi->capture.priv = fsi;
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001534
1535 if (fsi->info->tx_id) {
1536 fsi->playback.slave.slave_id = fsi->info->tx_id;
1537 fsi->playback.handler = &fsi_dma_push_handler;
1538 }
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001539}
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001540
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001541static int fsi_probe(struct platform_device *pdev)
1542{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +09001543 struct fsi_master *master;
Kuninori Morimotocc780d32010-03-25 19:15:53 +09001544 const struct platform_device_id *id_entry;
Kuninori Morimotofec691e2012-02-03 00:58:48 -08001545 struct sh_fsi_platform_info *info = pdev->dev.platform_data;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001546 struct resource *res;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001547 unsigned int irq;
1548 int ret;
1549
Kuninori Morimotocc780d32010-03-25 19:15:53 +09001550 id_entry = pdev->id_entry;
1551 if (!id_entry) {
1552 dev_err(&pdev->dev, "unknown fsi device\n");
1553 return -ENODEV;
1554 }
1555
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001556 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1557 irq = platform_get_irq(pdev, 0);
Uwe Kleine-Königb6aa1792009-12-16 17:10:09 +01001558 if (!res || (int)irq <= 0) {
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001559 dev_err(&pdev->dev, "Not enough FSI platform resources.\n");
1560 ret = -ENODEV;
1561 goto exit;
1562 }
1563
1564 master = kzalloc(sizeof(*master), GFP_KERNEL);
1565 if (!master) {
1566 dev_err(&pdev->dev, "Could not allocate master\n");
1567 ret = -ENOMEM;
1568 goto exit;
1569 }
1570
1571 master->base = ioremap_nocache(res->start, resource_size(res));
1572 if (!master->base) {
1573 ret = -ENXIO;
1574 dev_err(&pdev->dev, "Unable to ioremap FSI registers.\n");
1575 goto exit_kfree;
1576 }
1577
Kuninori Morimoto3bc28072010-07-29 16:48:32 +09001578 /* master setting */
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001579 master->irq = irq;
Kuninori Morimoto73b92c12010-07-13 12:13:04 +09001580 master->core = (struct fsi_core *)id_entry->driver_data;
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +09001581 spin_lock_init(&master->lock);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001582
Kuninori Morimoto3bc28072010-07-29 16:48:32 +09001583 /* FSI A setting */
1584 master->fsia.base = master->base;
1585 master->fsia.master = master;
Kuninori Morimotofec691e2012-02-03 00:58:48 -08001586 master->fsia.info = &info->port_a;
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001587 fsi_handler_init(&master->fsia);
1588 ret = fsi_stream_probe(&master->fsia);
1589 if (ret < 0) {
1590 dev_err(&pdev->dev, "FSIA stream probe failed\n");
1591 goto exit_iounmap;
1592 }
Kuninori Morimoto3bc28072010-07-29 16:48:32 +09001593
1594 /* FSI B setting */
1595 master->fsib.base = master->base + 0x40;
1596 master->fsib.master = master;
Kuninori Morimotofec691e2012-02-03 00:58:48 -08001597 master->fsib.info = &info->port_b;
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001598 fsi_handler_init(&master->fsib);
1599 ret = fsi_stream_probe(&master->fsib);
1600 if (ret < 0) {
1601 dev_err(&pdev->dev, "FSIB stream probe failed\n");
1602 goto exit_fsia;
1603 }
Kuninori Morimoto3bc28072010-07-29 16:48:32 +09001604
Kuninori Morimoto785d1c42009-11-30 20:24:48 +09001605 pm_runtime_enable(&pdev->dev);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001606 dev_set_drvdata(&pdev->dev, master);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001607
Yong Zhang88e24c32011-09-22 16:59:20 +08001608 ret = request_irq(irq, &fsi_interrupt, 0,
Kuninori Morimotocc780d32010-03-25 19:15:53 +09001609 id_entry->name, master);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001610 if (ret) {
1611 dev_err(&pdev->dev, "irq request err\n");
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001612 goto exit_fsib;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001613 }
1614
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001615 ret = snd_soc_register_platform(&pdev->dev, &fsi_soc_platform);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001616 if (ret < 0) {
1617 dev_err(&pdev->dev, "cannot snd soc register\n");
1618 goto exit_free_irq;
1619 }
1620
Kuninori Morimoto0b5ec872011-04-08 15:09:02 +09001621 ret = snd_soc_register_dais(&pdev->dev, fsi_soc_dai,
1622 ARRAY_SIZE(fsi_soc_dai));
1623 if (ret < 0) {
1624 dev_err(&pdev->dev, "cannot snd dai register\n");
1625 goto exit_snd_soc;
1626 }
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001627
Kuninori Morimoto0b5ec872011-04-08 15:09:02 +09001628 return ret;
1629
1630exit_snd_soc:
1631 snd_soc_unregister_platform(&pdev->dev);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001632exit_free_irq:
1633 free_irq(irq, master);
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001634exit_fsib:
1635 fsi_stream_remove(&master->fsib);
1636exit_fsia:
1637 fsi_stream_remove(&master->fsia);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001638exit_iounmap:
1639 iounmap(master->base);
Kuninori Morimoto785d1c42009-11-30 20:24:48 +09001640 pm_runtime_disable(&pdev->dev);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001641exit_kfree:
1642 kfree(master);
1643 master = NULL;
1644exit:
1645 return ret;
1646}
1647
1648static int fsi_remove(struct platform_device *pdev)
1649{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +09001650 struct fsi_master *master;
1651
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001652 master = dev_get_drvdata(&pdev->dev);
Kuninori Morimoto71f6e062009-12-02 15:11:08 +09001653
Kuninori Morimotod985f272011-04-08 15:09:25 +09001654 free_irq(master->irq, master);
Kuninori Morimoto785d1c42009-11-30 20:24:48 +09001655 pm_runtime_disable(&pdev->dev);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001656
Kuninori Morimotod985f272011-04-08 15:09:25 +09001657 snd_soc_unregister_dais(&pdev->dev, ARRAY_SIZE(fsi_soc_dai));
1658 snd_soc_unregister_platform(&pdev->dev);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001659
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001660 fsi_stream_remove(&master->fsia);
1661 fsi_stream_remove(&master->fsib);
1662
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001663 iounmap(master->base);
1664 kfree(master);
Kuninori Morimoto71f6e062009-12-02 15:11:08 +09001665
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001666 return 0;
1667}
1668
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09001669static void __fsi_suspend(struct fsi_priv *fsi,
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001670 struct fsi_stream *io,
Kuninori Morimoto4f56cde2011-05-23 20:46:18 +09001671 struct device *dev)
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09001672{
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001673 if (!fsi_stream_is_working(fsi, io))
Kuninori Morimotocda828c2011-05-23 20:46:35 +09001674 return;
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09001675
Kuninori Morimoto180346e2012-02-03 00:57:25 -08001676 fsi_stream_stop(fsi, io);
Kuninori Morimoto41bba152012-02-03 00:51:53 -08001677 fsi_hw_shutdown(fsi, dev);
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09001678}
1679
1680static void __fsi_resume(struct fsi_priv *fsi,
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001681 struct fsi_stream *io,
Kuninori Morimoto4f56cde2011-05-23 20:46:18 +09001682 struct device *dev)
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09001683{
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001684 if (!fsi_stream_is_working(fsi, io))
Kuninori Morimotocda828c2011-05-23 20:46:35 +09001685 return;
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09001686
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001687 fsi_hw_startup(fsi, io, dev);
Kuninori Morimotocda828c2011-05-23 20:46:35 +09001688
1689 if (fsi_is_clk_master(fsi) && fsi->rate)
Kuninori Morimoto4f56cde2011-05-23 20:46:18 +09001690 fsi_set_master_clk(dev, fsi, fsi->rate, 1);
Kuninori Morimotocda828c2011-05-23 20:46:35 +09001691
Kuninori Morimoto180346e2012-02-03 00:57:25 -08001692 fsi_stream_start(fsi, io);
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09001693}
1694
1695static int fsi_suspend(struct device *dev)
1696{
1697 struct fsi_master *master = dev_get_drvdata(dev);
Kuninori Morimotocda828c2011-05-23 20:46:35 +09001698 struct fsi_priv *fsia = &master->fsia;
1699 struct fsi_priv *fsib = &master->fsib;
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09001700
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001701 __fsi_suspend(fsia, &fsia->playback, dev);
1702 __fsi_suspend(fsia, &fsia->capture, dev);
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09001703
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001704 __fsi_suspend(fsib, &fsib->playback, dev);
1705 __fsi_suspend(fsib, &fsib->capture, dev);
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09001706
1707 return 0;
1708}
1709
1710static int fsi_resume(struct device *dev)
1711{
1712 struct fsi_master *master = dev_get_drvdata(dev);
Kuninori Morimotocda828c2011-05-23 20:46:35 +09001713 struct fsi_priv *fsia = &master->fsia;
1714 struct fsi_priv *fsib = &master->fsib;
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09001715
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001716 __fsi_resume(fsia, &fsia->playback, dev);
1717 __fsi_resume(fsia, &fsia->capture, dev);
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09001718
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001719 __fsi_resume(fsib, &fsib->playback, dev);
1720 __fsi_resume(fsib, &fsib->capture, dev);
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09001721
1722 return 0;
1723}
1724
Kuninori Morimoto785d1c42009-11-30 20:24:48 +09001725static struct dev_pm_ops fsi_pm_ops = {
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09001726 .suspend = fsi_suspend,
1727 .resume = fsi_resume,
Kuninori Morimoto785d1c42009-11-30 20:24:48 +09001728};
1729
Kuninori Morimoto73b92c12010-07-13 12:13:04 +09001730static struct fsi_core fsi1_core = {
1731 .ver = 1,
1732
1733 /* Interrupt */
Kuninori Morimotocc780d32010-03-25 19:15:53 +09001734 .int_st = INT_ST,
1735 .iemsk = IEMSK,
1736 .imsk = IMSK,
1737};
1738
Kuninori Morimoto73b92c12010-07-13 12:13:04 +09001739static struct fsi_core fsi2_core = {
1740 .ver = 2,
1741
1742 /* Interrupt */
Kuninori Morimotocc780d32010-03-25 19:15:53 +09001743 .int_st = CPU_INT_ST,
1744 .iemsk = CPU_IEMSK,
1745 .imsk = CPU_IMSK,
Kuninori Morimoto2b0e7302010-12-03 17:37:44 +09001746 .a_mclk = A_MST_CTLR,
1747 .b_mclk = B_MST_CTLR,
Kuninori Morimotocc780d32010-03-25 19:15:53 +09001748};
1749
1750static struct platform_device_id fsi_id_table[] = {
Kuninori Morimoto73b92c12010-07-13 12:13:04 +09001751 { "sh_fsi", (kernel_ulong_t)&fsi1_core },
1752 { "sh_fsi2", (kernel_ulong_t)&fsi2_core },
Guennadi Liakhovetski05c69452010-10-05 17:54:28 +02001753 {},
Kuninori Morimotocc780d32010-03-25 19:15:53 +09001754};
Dzianis Kahanovichd85a6d72010-09-17 16:42:05 +03001755MODULE_DEVICE_TABLE(platform, fsi_id_table);
Kuninori Morimotocc780d32010-03-25 19:15:53 +09001756
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001757static struct platform_driver fsi_driver = {
1758 .driver = {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001759 .name = "fsi-pcm-audio",
Kuninori Morimoto785d1c42009-11-30 20:24:48 +09001760 .pm = &fsi_pm_ops,
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001761 },
1762 .probe = fsi_probe,
1763 .remove = fsi_remove,
Kuninori Morimotocc780d32010-03-25 19:15:53 +09001764 .id_table = fsi_id_table,
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001765};
1766
Axel Lincb5e8732011-11-25 10:15:07 +08001767module_platform_driver(fsi_driver);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001768
1769MODULE_LICENSE("GPL");
1770MODULE_DESCRIPTION("SuperH onchip FSI audio driver");
1771MODULE_AUTHOR("Kuninori Morimoto <morimoto.kuninori@renesas.com>");
Guennadi Liakhovetskib3c27b52011-04-15 20:17:34 +02001772MODULE_ALIAS("platform:fsi-pcm-audio");