blob: 5cb1332e0438388ba81b6b016bb67a2d891d4ec1 [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>
Guennadi Liakhovetski57451e42012-10-03 14:33:50 +020023#include <linux/workqueue.h>
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090024#include <sound/soc.h>
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -080025#include <sound/pcm_params.h>
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090026#include <sound/sh_fsi.h>
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090027
Kuninori Morimotoe8c8b632010-12-03 17:37:55 +090028/* PortA/PortB register */
29#define REG_DO_FMT 0x0000
30#define REG_DOFF_CTL 0x0004
31#define REG_DOFF_ST 0x0008
32#define REG_DI_FMT 0x000C
33#define REG_DIFF_CTL 0x0010
34#define REG_DIFF_ST 0x0014
35#define REG_CKG1 0x0018
36#define REG_CKG2 0x001C
37#define REG_DIDT 0x0020
38#define REG_DODT 0x0024
39#define REG_MUTE_ST 0x0028
Kuninori Morimoto65ff03f2011-11-06 22:05:25 -080040#define REG_OUT_DMAC 0x002C
Kuninori Morimotoe8c8b632010-12-03 17:37:55 +090041#define REG_OUT_SEL 0x0030
Kuninori Morimoto65ff03f2011-11-06 22:05:25 -080042#define REG_IN_DMAC 0x0038
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090043
Kuninori Morimoto43fa95c2010-12-03 17:38:03 +090044/* master register */
45#define MST_CLK_RST 0x0210
46#define MST_SOFT_RST 0x0214
47#define MST_FIFO_SZ 0x0218
48
49/* core register (depend on FSI version) */
Kuninori Morimoto3bc28072010-07-29 16:48:32 +090050#define A_MST_CTLR 0x0180
51#define B_MST_CTLR 0x01A0
Kuninori Morimotocc780d32010-03-25 19:15:53 +090052#define CPU_INT_ST 0x01F4
53#define CPU_IEMSK 0x01F8
54#define CPU_IMSK 0x01FC
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090055#define INT_ST 0x0200
56#define IEMSK 0x0204
57#define IMSK 0x0208
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090058
59/* DO_FMT */
60/* DI_FMT */
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -080061#define CR_BWS_MASK (0x3 << 20) /* FSI2 */
Kuninori Morimotof7d711e2010-12-03 17:36:24 +090062#define CR_BWS_24 (0x0 << 20) /* FSI2 */
63#define CR_BWS_16 (0x1 << 20) /* FSI2 */
64#define CR_BWS_20 (0x2 << 20) /* FSI2 */
65
66#define CR_DTMD_PCM (0x0 << 8) /* FSI2 */
67#define CR_DTMD_SPDIF_PCM (0x1 << 8) /* FSI2 */
68#define CR_DTMD_SPDIF_STREAM (0x2 << 8) /* FSI2 */
69
Kuninori Morimotoa7ffb522010-07-13 12:13:00 +090070#define CR_MONO (0x0 << 4)
71#define CR_MONO_D (0x1 << 4)
72#define CR_PCM (0x2 << 4)
73#define CR_I2S (0x3 << 4)
74#define CR_TDM (0x4 << 4)
75#define CR_TDM_D (0x5 << 4)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090076
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -080077/* OUT_DMAC */
78/* IN_DMAC */
79#define VDMD_MASK (0x3 << 4)
80#define VDMD_FRONT (0x0 << 4) /* Package in front */
81#define VDMD_BACK (0x1 << 4) /* Package in back */
82#define VDMD_STREAM (0x2 << 4) /* Stream mode(16bit * 2) */
83
84#define DMA_ON (0x1 << 0)
85
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090086/* DOFF_CTL */
87/* DIFF_CTL */
88#define IRQ_HALF 0x00100000
89#define FIFO_CLR 0x00000001
90
91/* DOFF_ST */
92#define ERR_OVER 0x00000010
93#define ERR_UNDER 0x00000001
Kuninori Morimoto59c3b002009-12-28 14:09:16 +090094#define ST_ERR (ERR_OVER | ERR_UNDER)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090095
Kuninori Morimotoccad7b42010-07-13 12:13:14 +090096/* CKG1 */
97#define ACKMD_MASK 0x00007000
98#define BPFMD_MASK 0x00000700
Kuninori Morimoto4d805f72011-01-20 11:46:02 +090099#define DIMD (1 << 4)
100#define DOMD (1 << 0)
Kuninori Morimotoccad7b42010-07-13 12:13:14 +0900101
Kuninori Morimoto3bc28072010-07-29 16:48:32 +0900102/* A/B MST_CTLR */
103#define BP (1 << 4) /* Fix the signal of Biphase output */
104#define SE (1 << 0) /* Fix the master clock */
105
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900106/* CLK_RST */
Kuninori Morimoto1f5e2a32011-04-21 10:33:52 +0900107#define CRB (1 << 4)
108#define CRA (1 << 0)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900109
Kuninori Morimotocf6edd02010-10-12 11:40:53 +0900110/* IO SHIFT / MACRO */
111#define BI_SHIFT 12
112#define BO_SHIFT 8
113#define AI_SHIFT 4
114#define AO_SHIFT 0
115#define AB_IO(param, shift) (param << shift)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900116
Kuninori Morimotofeb58cf2010-03-24 15:27:24 +0900117/* SOFT_RST */
118#define PBSR (1 << 12) /* Port B Software Reset */
119#define PASR (1 << 8) /* Port A Software Reset */
120#define IR (1 << 4) /* Interrupt Reset */
121#define FSISR (1 << 0) /* Software Reset */
122
Kuninori Morimotof7d711e2010-12-03 17:36:24 +0900123/* OUT_SEL (FSI2) */
124#define DMMD (1 << 4) /* SPDIF output timing 0: Biphase only */
125 /* 1: Biphase and serial */
126
Kuninori Morimoto4a942b42010-03-25 19:15:51 +0900127/* FIFO_SZ */
Kuninori Morimotocf6edd02010-10-12 11:40:53 +0900128#define FIFO_SZ_MASK 0x7
Kuninori Morimoto4a942b42010-03-25 19:15:51 +0900129
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900130#define FSI_RATES SNDRV_PCM_RATE_8000_96000
131
132#define FSI_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE)
133
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +0900134/*
Kuninori Morimoto766812e2012-05-17 17:36:47 -0700135 * bus options
136 *
137 * 0x000000BA
138 *
139 * A : sample widtht 16bit setting
140 * B : sample widtht 24bit setting
141 */
142
143#define SHIFT_16DATA 0
144#define SHIFT_24DATA 4
145
146#define PACKAGE_24BITBUS_BACK 0
147#define PACKAGE_24BITBUS_FRONT 1
148#define PACKAGE_16BITBUS_STREAM 2
149
150#define BUSOP_SET(s, a) ((a) << SHIFT_ ## s ## DATA)
151#define BUSOP_GET(s, a) (((a) >> SHIFT_ ## s ## DATA) & 0xF)
152
153/*
Kuninori Morimoto5bfb9ad2010-09-17 13:48:45 +0900154 * FSI driver use below type name for variable
155 *
Kuninori Morimoto5bfb9ad2010-09-17 13:48:45 +0900156 * xxx_num : number of data
Kuninori Morimoto2e651ba2011-05-23 20:46:03 +0900157 * xxx_pos : position of data
158 * xxx_capa : capacity of data
159 */
160
161/*
162 * period/frame/sample image
163 *
164 * ex) PCM (2ch)
165 *
166 * period pos period pos
167 * [n] [n + 1]
168 * |<-------------------- period--------------------->|
169 * ==|============================================ ... =|==
170 * | |
171 * ||<----- frame ----->|<------ frame ----->| ... |
172 * |+--------------------+--------------------+- ... |
173 * ||[ sample ][ sample ]|[ sample ][ sample ]| ... |
174 * |+--------------------+--------------------+- ... |
175 * ==|============================================ ... =|==
176 */
177
178/*
179 * FSI FIFO image
180 *
181 * | |
182 * | |
183 * | [ sample ] |
184 * | [ sample ] |
185 * | [ sample ] |
186 * | [ sample ] |
187 * --> go to codecs
Kuninori Morimoto5bfb9ad2010-09-17 13:48:45 +0900188 */
189
190/*
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -0800191 * FSI clock
192 *
193 * FSIxCLK [CPG] (ick) -------> |
194 * |-> FSI_DIV (div)-> FSI2
195 * FSIxCK [external] (xck) ---> |
196 */
197
198/*
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +0900199 * struct
200 */
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900201
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800202struct fsi_stream_handler;
Kuninori Morimoto93193c22010-10-12 19:19:28 +0900203struct fsi_stream {
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900204
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800205 /*
206 * these are initialized by fsi_stream_init()
207 */
208 struct snd_pcm_substream *substream;
Kuninori Morimoto2e651ba2011-05-23 20:46:03 +0900209 int fifo_sample_capa; /* sample capacity of FSI FIFO */
210 int buff_sample_capa; /* sample capacity of ALSA buffer */
211 int buff_sample_pos; /* sample position of ALSA buffer */
212 int period_samples; /* sample number / 1 period */
213 int period_pos; /* current period position */
Kuninori Morimotoc1e6f102012-02-03 00:50:09 -0800214 int sample_width; /* sample width */
Kuninori Morimoto1ec9bc32010-12-17 12:55:22 +0900215 int uerr_num;
216 int oerr_num;
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800217
218 /*
Kuninori Morimoto766812e2012-05-17 17:36:47 -0700219 * bus options
220 */
221 u32 bus_option;
222
223 /*
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800224 * thse are initialized by fsi_handler_init()
225 */
226 struct fsi_stream_handler *handler;
227 struct fsi_priv *priv;
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -0800228
229 /*
230 * these are for DMAEngine
231 */
232 struct dma_chan *chan;
233 struct sh_dmae_slave slave; /* see fsi_handler_init() */
Guennadi Liakhovetski57451e42012-10-03 14:33:50 +0200234 struct work_struct work;
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -0800235 dma_addr_t dma;
Kuninori Morimoto93193c22010-10-12 19:19:28 +0900236};
237
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -0800238struct fsi_clk {
239 /* see [FSI clock] */
240 struct clk *own;
241 struct clk *xck;
242 struct clk *ick;
243 struct clk *div;
244 int (*set_rate)(struct device *dev,
Kuninori Morimoto6cbdbff2012-12-16 22:12:21 -0800245 struct fsi_priv *fsi);
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -0800246
247 unsigned long rate;
248 unsigned int count;
249};
250
Kuninori Morimoto93193c22010-10-12 19:19:28 +0900251struct fsi_priv {
252 void __iomem *base;
253 struct fsi_master *master;
Kuninori Morimotofec691e2012-02-03 00:58:48 -0800254 struct sh_fsi_port_info *info;
Kuninori Morimoto93193c22010-10-12 19:19:28 +0900255
256 struct fsi_stream playback;
257 struct fsi_stream capture;
Kuninori Morimoto3bc28072010-07-29 16:48:32 +0900258
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -0800259 struct fsi_clk clock;
260
Kuninori Morimoto9c59dd32012-05-17 17:34:53 -0700261 u32 fmt;
Kuninori Morimoto9478e0b2011-05-23 20:46:07 +0900262
Kuninori Morimoto6a9ebad2011-04-21 10:33:36 +0900263 int chan_num:16;
264 int clk_master:1;
Kuninori Morimotoab6340c2012-11-16 01:17:18 -0800265 int clk_cpg:1;
Kuninori Morimoto9478e0b2011-05-23 20:46:07 +0900266 int spdif:1;
Kuninori Morimoto2522acd2012-11-16 01:17:30 -0800267 int enable_stream:1;
Kuninori Morimoto3449f5f2012-11-16 01:17:43 -0800268 int bit_clk_inv:1;
269 int lr_clk_inv:1;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900270};
271
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800272struct fsi_stream_handler {
Kuninori Morimoto83344022012-02-03 00:59:02 -0800273 int (*init)(struct fsi_priv *fsi, struct fsi_stream *io);
274 int (*quit)(struct fsi_priv *fsi, struct fsi_stream *io);
Kuninori Morimotob1226dc2012-05-24 23:56:19 -0700275 int (*probe)(struct fsi_priv *fsi, struct fsi_stream *io, struct device *dev);
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800276 int (*transfer)(struct fsi_priv *fsi, struct fsi_stream *io);
277 int (*remove)(struct fsi_priv *fsi, struct fsi_stream *io);
Kuninori Morimoto180346e2012-02-03 00:57:25 -0800278 void (*start_stop)(struct fsi_priv *fsi, struct fsi_stream *io,
279 int enable);
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800280};
281#define fsi_stream_handler_call(io, func, args...) \
282 (!(io) ? -ENODEV : \
283 !((io)->handler->func) ? 0 : \
284 (io)->handler->func(args))
285
Kuninori Morimoto73b92c12010-07-13 12:13:04 +0900286struct fsi_core {
287 int ver;
288
Kuninori Morimotocc780d32010-03-25 19:15:53 +0900289 u32 int_st;
290 u32 iemsk;
291 u32 imsk;
Kuninori Morimoto2b0e7302010-12-03 17:37:44 +0900292 u32 a_mclk;
293 u32 b_mclk;
Kuninori Morimotocc780d32010-03-25 19:15:53 +0900294};
295
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900296struct fsi_master {
297 void __iomem *base;
298 int irq;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900299 struct fsi_priv fsia;
300 struct fsi_priv fsib;
Kuninori Morimoto73b92c12010-07-13 12:13:04 +0900301 struct fsi_core *core;
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900302 spinlock_t lock;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900303};
304
Kuninori Morimoto7b1b3332012-02-03 00:55:26 -0800305static int fsi_stream_is_play(struct fsi_priv *fsi, struct fsi_stream *io);
306
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +0900307/*
308 * basic read write function
309 */
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900310
Arnd Bergmannca7acee2011-10-02 22:28:02 +0200311static void __fsi_reg_write(u32 __iomem *reg, u32 data)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900312{
313 /* valid data area is 24bit */
314 data &= 0x00ffffff;
315
Guennadi Liakhovetski0f69d972010-02-03 17:37:23 +0100316 __raw_writel(data, reg);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900317}
318
Arnd Bergmannca7acee2011-10-02 22:28:02 +0200319static u32 __fsi_reg_read(u32 __iomem *reg)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900320{
Guennadi Liakhovetski0f69d972010-02-03 17:37:23 +0100321 return __raw_readl(reg);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900322}
323
Arnd Bergmannca7acee2011-10-02 22:28:02 +0200324static void __fsi_reg_mask_set(u32 __iomem *reg, u32 mask, u32 data)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900325{
326 u32 val = __fsi_reg_read(reg);
327
328 val &= ~mask;
329 val |= data & mask;
330
Guennadi Liakhovetski0f69d972010-02-03 17:37:23 +0100331 __fsi_reg_write(reg, val);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900332}
333
Kuninori Morimotoe8c8b632010-12-03 17:37:55 +0900334#define fsi_reg_write(p, r, d)\
Kuninori Morimoto8918b842011-10-31 22:11:53 -0700335 __fsi_reg_write((p->base + REG_##r), d)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900336
Kuninori Morimotoe8c8b632010-12-03 17:37:55 +0900337#define fsi_reg_read(p, r)\
Kuninori Morimoto8918b842011-10-31 22:11:53 -0700338 __fsi_reg_read((p->base + REG_##r))
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900339
Kuninori Morimotoe8c8b632010-12-03 17:37:55 +0900340#define fsi_reg_mask_set(p, r, m, d)\
Kuninori Morimoto8918b842011-10-31 22:11:53 -0700341 __fsi_reg_mask_set((p->base + REG_##r), m, d)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900342
Kuninori Morimoto43fa95c2010-12-03 17:38:03 +0900343#define fsi_master_read(p, r) _fsi_master_read(p, MST_##r)
344#define fsi_core_read(p, r) _fsi_master_read(p, p->core->r)
345static u32 _fsi_master_read(struct fsi_master *master, u32 reg)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900346{
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900347 u32 ret;
348 unsigned long flags;
349
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900350 spin_lock_irqsave(&master->lock, flags);
Arnd Bergmannca7acee2011-10-02 22:28:02 +0200351 ret = __fsi_reg_read(master->base + reg);
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900352 spin_unlock_irqrestore(&master->lock, flags);
353
354 return ret;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900355}
356
Kuninori Morimoto43fa95c2010-12-03 17:38:03 +0900357#define fsi_master_mask_set(p, r, m, d) _fsi_master_mask_set(p, MST_##r, m, d)
358#define fsi_core_mask_set(p, r, m, d) _fsi_master_mask_set(p, p->core->r, m, d)
359static void _fsi_master_mask_set(struct fsi_master *master,
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900360 u32 reg, u32 mask, u32 data)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900361{
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900362 unsigned long flags;
363
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900364 spin_lock_irqsave(&master->lock, flags);
Arnd Bergmannca7acee2011-10-02 22:28:02 +0200365 __fsi_reg_mask_set(master->base + reg, mask, data);
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900366 spin_unlock_irqrestore(&master->lock, flags);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900367}
368
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +0900369/*
370 * basic function
371 */
Kuninori Morimoto284c6f62012-05-17 17:34:16 -0700372static int fsi_version(struct fsi_master *master)
373{
374 return master->core->ver;
375}
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900376
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900377static struct fsi_master *fsi_get_master(struct fsi_priv *fsi)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900378{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900379 return fsi->master;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900380}
381
Kuninori Morimoto6a9ebad2011-04-21 10:33:36 +0900382static int fsi_is_clk_master(struct fsi_priv *fsi)
383{
384 return fsi->clk_master;
385}
386
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900387static int fsi_is_port_a(struct fsi_priv *fsi)
388{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900389 return fsi->master->base == fsi->base;
390}
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900391
Kuninori Morimoto9478e0b2011-05-23 20:46:07 +0900392static int fsi_is_spdif(struct fsi_priv *fsi)
393{
394 return fsi->spdif;
395}
396
Kuninori Morimoto2522acd2012-11-16 01:17:30 -0800397static int fsi_is_enable_stream(struct fsi_priv *fsi)
398{
399 return fsi->enable_stream;
400}
401
Kuninori Morimotoa449e462012-02-03 00:54:02 -0800402static int fsi_is_play(struct snd_pcm_substream *substream)
403{
404 return substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
405}
406
Kuninori Morimoto142e8172009-12-28 14:09:11 +0900407static struct snd_soc_dai *fsi_get_dai(struct snd_pcm_substream *substream)
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900408{
409 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Kuninori Morimoto142e8172009-12-28 14:09:11 +0900410
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000411 return rtd->cpu_dai;
Kuninori Morimoto142e8172009-12-28 14:09:11 +0900412}
413
Kuninori Morimoto0d032c12011-01-20 11:45:51 +0900414static struct fsi_priv *fsi_get_priv_frm_dai(struct snd_soc_dai *dai)
Kuninori Morimoto142e8172009-12-28 14:09:11 +0900415{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000416 struct fsi_master *master = snd_soc_dai_get_drvdata(dai);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900417
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000418 if (dai->id == 0)
419 return &master->fsia;
420 else
421 return &master->fsib;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900422}
423
Kuninori Morimoto0d032c12011-01-20 11:45:51 +0900424static struct fsi_priv *fsi_get_priv(struct snd_pcm_substream *substream)
425{
426 return fsi_get_priv_frm_dai(fsi_get_dai(substream));
427}
428
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900429static u32 fsi_get_info_flags(struct fsi_priv *fsi)
430{
Kuninori Morimotofec691e2012-02-03 00:58:48 -0800431 if (!fsi->info)
Kuninori Morimotod7c57622011-01-24 10:42:33 +0900432 return 0;
433
Kuninori Morimotofec691e2012-02-03 00:58:48 -0800434 return fsi->info->flags;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900435}
436
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800437static u32 fsi_get_port_shift(struct fsi_priv *fsi, struct fsi_stream *io)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900438{
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800439 int is_play = fsi_stream_is_play(fsi, io);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900440 int is_porta = fsi_is_port_a(fsi);
Kuninori Morimotocf6edd02010-10-12 11:40:53 +0900441 u32 shift;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900442
443 if (is_porta)
Kuninori Morimotocf6edd02010-10-12 11:40:53 +0900444 shift = is_play ? AO_SHIFT : AI_SHIFT;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900445 else
Kuninori Morimotocf6edd02010-10-12 11:40:53 +0900446 shift = is_play ? BO_SHIFT : BI_SHIFT;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900447
Kuninori Morimotocf6edd02010-10-12 11:40:53 +0900448 return shift;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900449}
450
Kuninori Morimoto2e651ba2011-05-23 20:46:03 +0900451static int fsi_frame2sample(struct fsi_priv *fsi, int frames)
452{
453 return frames * fsi->chan_num;
454}
455
456static int fsi_sample2frame(struct fsi_priv *fsi, int samples)
457{
458 return samples / fsi->chan_num;
459}
460
Kuninori Morimoto7b1b3332012-02-03 00:55:26 -0800461static int fsi_get_current_fifo_samples(struct fsi_priv *fsi,
462 struct fsi_stream *io)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900463{
Kuninori Morimoto7b1b3332012-02-03 00:55:26 -0800464 int is_play = fsi_stream_is_play(fsi, io);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900465 u32 status;
Kuninori Morimoto2e651ba2011-05-23 20:46:03 +0900466 int frames;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900467
Kuninori Morimotoe8c8b632010-12-03 17:37:55 +0900468 status = is_play ?
469 fsi_reg_read(fsi, DOFF_ST) :
470 fsi_reg_read(fsi, DIFF_ST);
471
Kuninori Morimoto2e651ba2011-05-23 20:46:03 +0900472 frames = 0x1ff & (status >> 8);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900473
Kuninori Morimoto2e651ba2011-05-23 20:46:03 +0900474 return fsi_frame2sample(fsi, frames);
Kuninori Morimotocca1b232010-10-12 11:39:25 +0900475}
476
Kuninori Morimoto1ec9bc32010-12-17 12:55:22 +0900477static void fsi_count_fifo_err(struct fsi_priv *fsi)
478{
479 u32 ostatus = fsi_reg_read(fsi, DOFF_ST);
480 u32 istatus = fsi_reg_read(fsi, DIFF_ST);
481
482 if (ostatus & ERR_OVER)
483 fsi->playback.oerr_num++;
484
485 if (ostatus & ERR_UNDER)
486 fsi->playback.uerr_num++;
487
488 if (istatus & ERR_OVER)
489 fsi->capture.oerr_num++;
490
491 if (istatus & ERR_UNDER)
492 fsi->capture.uerr_num++;
493
494 fsi_reg_write(fsi, DOFF_ST, 0);
495 fsi_reg_write(fsi, DIFF_ST, 0);
496}
497
Kuninori Morimotob9fde182010-09-17 13:48:32 +0900498/*
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800499 * fsi_stream_xx() function
500 */
Kuninori Morimotoa449e462012-02-03 00:54:02 -0800501static inline int fsi_stream_is_play(struct fsi_priv *fsi,
502 struct fsi_stream *io)
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800503{
Kuninori Morimotoa449e462012-02-03 00:54:02 -0800504 return &fsi->playback == io;
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800505}
506
507static inline struct fsi_stream *fsi_stream_get(struct fsi_priv *fsi,
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800508 struct snd_pcm_substream *substream)
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800509{
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800510 return fsi_is_play(substream) ? &fsi->playback : &fsi->capture;
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800511}
512
513static int fsi_stream_is_working(struct fsi_priv *fsi,
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800514 struct fsi_stream *io)
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800515{
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800516 struct fsi_master *master = fsi_get_master(fsi);
517 unsigned long flags;
518 int ret;
519
520 spin_lock_irqsave(&master->lock, flags);
Kuninori Morimoto97df8182012-02-03 00:57:40 -0800521 ret = !!(io->substream && io->substream->runtime);
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800522 spin_unlock_irqrestore(&master->lock, flags);
523
524 return ret;
525}
526
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800527static struct fsi_priv *fsi_stream_to_priv(struct fsi_stream *io)
528{
529 return io->priv;
530}
531
Kuninori Morimoto8c415292012-02-03 00:52:07 -0800532static void fsi_stream_init(struct fsi_priv *fsi,
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800533 struct fsi_stream *io,
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800534 struct snd_pcm_substream *substream)
535{
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800536 struct snd_pcm_runtime *runtime = substream->runtime;
537 struct fsi_master *master = fsi_get_master(fsi);
538 unsigned long flags;
539
540 spin_lock_irqsave(&master->lock, flags);
541 io->substream = substream;
542 io->buff_sample_capa = fsi_frame2sample(fsi, runtime->buffer_size);
543 io->buff_sample_pos = 0;
544 io->period_samples = fsi_frame2sample(fsi, runtime->period_size);
545 io->period_pos = 0;
546 io->sample_width = samples_to_bytes(runtime, 1);
Kuninori Morimoto766812e2012-05-17 17:36:47 -0700547 io->bus_option = 0;
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800548 io->oerr_num = -1; /* ignore 1st err */
549 io->uerr_num = -1; /* ignore 1st err */
Kuninori Morimoto83344022012-02-03 00:59:02 -0800550 fsi_stream_handler_call(io, init, fsi, io);
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800551 spin_unlock_irqrestore(&master->lock, flags);
552}
553
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800554static void fsi_stream_quit(struct fsi_priv *fsi, struct fsi_stream *io)
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800555{
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800556 struct snd_soc_dai *dai = fsi_get_dai(io->substream);
557 struct fsi_master *master = fsi_get_master(fsi);
558 unsigned long flags;
559
560 spin_lock_irqsave(&master->lock, flags);
561
562 if (io->oerr_num > 0)
563 dev_err(dai->dev, "over_run = %d\n", io->oerr_num);
564
565 if (io->uerr_num > 0)
566 dev_err(dai->dev, "under_run = %d\n", io->uerr_num);
567
Kuninori Morimoto83344022012-02-03 00:59:02 -0800568 fsi_stream_handler_call(io, quit, fsi, io);
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800569 io->substream = NULL;
570 io->buff_sample_capa = 0;
571 io->buff_sample_pos = 0;
572 io->period_samples = 0;
573 io->period_pos = 0;
574 io->sample_width = 0;
Kuninori Morimoto766812e2012-05-17 17:36:47 -0700575 io->bus_option = 0;
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800576 io->oerr_num = 0;
577 io->uerr_num = 0;
578 spin_unlock_irqrestore(&master->lock, flags);
579}
580
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800581static int fsi_stream_transfer(struct fsi_stream *io)
582{
583 struct fsi_priv *fsi = fsi_stream_to_priv(io);
584 if (!fsi)
585 return -EIO;
586
587 return fsi_stream_handler_call(io, transfer, fsi, io);
588}
589
Kuninori Morimoto180346e2012-02-03 00:57:25 -0800590#define fsi_stream_start(fsi, io)\
591 fsi_stream_handler_call(io, start_stop, fsi, io, 1)
592
593#define fsi_stream_stop(fsi, io)\
594 fsi_stream_handler_call(io, start_stop, fsi, io, 0)
595
Kuninori Morimotob1226dc2012-05-24 23:56:19 -0700596static int fsi_stream_probe(struct fsi_priv *fsi, struct device *dev)
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800597{
598 struct fsi_stream *io;
599 int ret1, ret2;
600
601 io = &fsi->playback;
Kuninori Morimotob1226dc2012-05-24 23:56:19 -0700602 ret1 = fsi_stream_handler_call(io, probe, fsi, io, dev);
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800603
604 io = &fsi->capture;
Kuninori Morimotob1226dc2012-05-24 23:56:19 -0700605 ret2 = fsi_stream_handler_call(io, probe, fsi, io, dev);
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800606
607 if (ret1 < 0)
608 return ret1;
609 if (ret2 < 0)
610 return ret2;
611
612 return 0;
613}
614
615static int fsi_stream_remove(struct fsi_priv *fsi)
616{
617 struct fsi_stream *io;
618 int ret1, ret2;
619
620 io = &fsi->playback;
621 ret1 = fsi_stream_handler_call(io, remove, fsi, io);
622
623 io = &fsi->capture;
624 ret2 = fsi_stream_handler_call(io, remove, fsi, io);
625
626 if (ret1 < 0)
627 return ret1;
628 if (ret2 < 0)
629 return ret2;
630
631 return 0;
632}
633
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800634/*
Kuninori Morimoto766812e2012-05-17 17:36:47 -0700635 * format/bus/dma setting
636 */
637static void fsi_format_bus_setup(struct fsi_priv *fsi, struct fsi_stream *io,
638 u32 bus, struct device *dev)
639{
640 struct fsi_master *master = fsi_get_master(fsi);
641 int is_play = fsi_stream_is_play(fsi, io);
642 u32 fmt = fsi->fmt;
643
644 if (fsi_version(master) >= 2) {
645 u32 dma = 0;
646
647 /*
648 * FSI2 needs DMA/Bus setting
649 */
650 switch (bus) {
651 case PACKAGE_24BITBUS_FRONT:
652 fmt |= CR_BWS_24;
653 dma |= VDMD_FRONT;
654 dev_dbg(dev, "24bit bus / package in front\n");
655 break;
656 case PACKAGE_16BITBUS_STREAM:
657 fmt |= CR_BWS_16;
658 dma |= VDMD_STREAM;
659 dev_dbg(dev, "16bit bus / stream mode\n");
660 break;
661 case PACKAGE_24BITBUS_BACK:
662 default:
663 fmt |= CR_BWS_24;
664 dma |= VDMD_BACK;
665 dev_dbg(dev, "24bit bus / package in back\n");
666 break;
667 }
668
669 if (is_play)
670 fsi_reg_write(fsi, OUT_DMAC, dma);
671 else
672 fsi_reg_write(fsi, IN_DMAC, dma);
673 }
674
675 if (is_play)
676 fsi_reg_write(fsi, DO_FMT, fmt);
677 else
678 fsi_reg_write(fsi, DI_FMT, fmt);
679}
680
681/*
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +0900682 * irq function
683 */
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900684
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800685static void fsi_irq_enable(struct fsi_priv *fsi, struct fsi_stream *io)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900686{
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800687 u32 data = AB_IO(1, fsi_get_port_shift(fsi, io));
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900688 struct fsi_master *master = fsi_get_master(fsi);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900689
Kuninori Morimoto43fa95c2010-12-03 17:38:03 +0900690 fsi_core_mask_set(master, imsk, data, data);
691 fsi_core_mask_set(master, iemsk, data, data);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900692}
693
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800694static void fsi_irq_disable(struct fsi_priv *fsi, struct fsi_stream *io)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900695{
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800696 u32 data = AB_IO(1, fsi_get_port_shift(fsi, io));
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900697 struct fsi_master *master = fsi_get_master(fsi);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900698
Kuninori Morimoto43fa95c2010-12-03 17:38:03 +0900699 fsi_core_mask_set(master, imsk, data, 0);
700 fsi_core_mask_set(master, iemsk, data, 0);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900701}
702
Kuninori Morimoto10ea76c2010-03-23 11:47:54 +0900703static u32 fsi_irq_get_status(struct fsi_master *master)
704{
Kuninori Morimoto43fa95c2010-12-03 17:38:03 +0900705 return fsi_core_read(master, int_st);
Kuninori Morimoto10ea76c2010-03-23 11:47:54 +0900706}
707
Kuninori Morimoto10ea76c2010-03-23 11:47:54 +0900708static void fsi_irq_clear_status(struct fsi_priv *fsi)
709{
710 u32 data = 0;
711 struct fsi_master *master = fsi_get_master(fsi);
712
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800713 data |= AB_IO(1, fsi_get_port_shift(fsi, &fsi->playback));
714 data |= AB_IO(1, fsi_get_port_shift(fsi, &fsi->capture));
Kuninori Morimoto10ea76c2010-03-23 11:47:54 +0900715
716 /* clear interrupt factor */
Kuninori Morimoto43fa95c2010-12-03 17:38:03 +0900717 fsi_core_mask_set(master, int_st, data, 0);
Kuninori Morimoto10ea76c2010-03-23 11:47:54 +0900718}
719
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +0900720/*
721 * SPDIF master clock function
722 *
723 * These functions are used later FSI2
724 */
Kuninori Morimoto3bc28072010-07-29 16:48:32 +0900725static void fsi_spdif_clk_ctrl(struct fsi_priv *fsi, int enable)
726{
727 struct fsi_master *master = fsi_get_master(fsi);
Kuninori Morimoto2b0e7302010-12-03 17:37:44 +0900728 u32 mask, val;
Kuninori Morimoto3bc28072010-07-29 16:48:32 +0900729
Kuninori Morimoto2b0e7302010-12-03 17:37:44 +0900730 mask = BP | SE;
731 val = enable ? mask : 0;
732
733 fsi_is_port_a(fsi) ?
Kuninori Morimoto43fa95c2010-12-03 17:38:03 +0900734 fsi_core_mask_set(master, a_mclk, mask, val) :
735 fsi_core_mask_set(master, b_mclk, mask, val);
Kuninori Morimoto3bc28072010-07-29 16:48:32 +0900736}
737
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +0900738/*
Kuninori Morimoto1f5e2a32011-04-21 10:33:52 +0900739 * clock function
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +0900740 */
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -0800741static int fsi_clk_init(struct device *dev,
742 struct fsi_priv *fsi,
743 int xck,
744 int ick,
745 int div,
746 int (*set_rate)(struct device *dev,
Kuninori Morimoto6cbdbff2012-12-16 22:12:21 -0800747 struct fsi_priv *fsi))
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -0800748{
749 struct fsi_clk *clock = &fsi->clock;
750 int is_porta = fsi_is_port_a(fsi);
751
752 clock->xck = NULL;
753 clock->ick = NULL;
754 clock->div = NULL;
755 clock->rate = 0;
756 clock->count = 0;
757 clock->set_rate = set_rate;
758
759 clock->own = devm_clk_get(dev, NULL);
760 if (IS_ERR(clock->own))
761 return -EINVAL;
762
763 /* external clock */
764 if (xck) {
765 clock->xck = devm_clk_get(dev, is_porta ? "xcka" : "xckb");
766 if (IS_ERR(clock->xck)) {
767 dev_err(dev, "can't get xck clock\n");
768 return -EINVAL;
769 }
770 if (clock->xck == clock->own) {
771 dev_err(dev, "cpu doesn't support xck clock\n");
772 return -EINVAL;
773 }
774 }
775
776 /* FSIACLK/FSIBCLK */
777 if (ick) {
778 clock->ick = devm_clk_get(dev, is_porta ? "icka" : "ickb");
779 if (IS_ERR(clock->ick)) {
780 dev_err(dev, "can't get ick clock\n");
781 return -EINVAL;
782 }
783 if (clock->ick == clock->own) {
784 dev_err(dev, "cpu doesn't support ick clock\n");
785 return -EINVAL;
786 }
787 }
788
789 /* FSI-DIV */
790 if (div) {
791 clock->div = devm_clk_get(dev, is_porta ? "diva" : "divb");
792 if (IS_ERR(clock->div)) {
793 dev_err(dev, "can't get div clock\n");
794 return -EINVAL;
795 }
796 if (clock->div == clock->own) {
797 dev_err(dev, "cpu doens't support div clock\n");
798 return -EINVAL;
799 }
800 }
801
802 return 0;
803}
804
805#define fsi_clk_invalid(fsi) fsi_clk_valid(fsi, 0)
806static void fsi_clk_valid(struct fsi_priv *fsi, unsigned long rate)
807{
808 fsi->clock.rate = rate;
809}
810
811static int fsi_clk_is_valid(struct fsi_priv *fsi)
812{
813 return fsi->clock.set_rate &&
814 fsi->clock.rate;
815}
816
817static int fsi_clk_enable(struct device *dev,
Kuninori Morimoto6cbdbff2012-12-16 22:12:21 -0800818 struct fsi_priv *fsi)
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -0800819{
820 struct fsi_clk *clock = &fsi->clock;
821 int ret = -EINVAL;
822
823 if (!fsi_clk_is_valid(fsi))
824 return ret;
825
826 if (0 == clock->count) {
Kuninori Morimoto6cbdbff2012-12-16 22:12:21 -0800827 ret = clock->set_rate(dev, fsi);
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -0800828 if (ret < 0) {
829 fsi_clk_invalid(fsi);
830 return ret;
831 }
832
833 if (clock->xck)
834 clk_enable(clock->xck);
835 if (clock->ick)
836 clk_enable(clock->ick);
837 if (clock->div)
838 clk_enable(clock->div);
839
840 clock->count++;
841 }
842
843 return ret;
844}
845
846static int fsi_clk_disable(struct device *dev,
847 struct fsi_priv *fsi)
848{
849 struct fsi_clk *clock = &fsi->clock;
850
851 if (!fsi_clk_is_valid(fsi))
852 return -EINVAL;
853
854 if (1 == clock->count--) {
855 if (clock->xck)
856 clk_disable(clock->xck);
857 if (clock->ick)
858 clk_disable(clock->ick);
859 if (clock->div)
860 clk_disable(clock->div);
861 }
862
863 return 0;
864}
865
866static int fsi_clk_set_ackbpf(struct device *dev,
867 struct fsi_priv *fsi,
868 int ackmd, int bpfmd)
869{
870 u32 data = 0;
871
872 /* check ackmd/bpfmd relationship */
873 if (bpfmd > ackmd) {
874 dev_err(dev, "unsupported rate (%d/%d)\n", ackmd, bpfmd);
875 return -EINVAL;
876 }
877
878 /* ACKMD */
879 switch (ackmd) {
880 case 512:
881 data |= (0x0 << 12);
882 break;
883 case 256:
884 data |= (0x1 << 12);
885 break;
886 case 128:
887 data |= (0x2 << 12);
888 break;
889 case 64:
890 data |= (0x3 << 12);
891 break;
892 case 32:
893 data |= (0x4 << 12);
894 break;
895 default:
896 dev_err(dev, "unsupported ackmd (%d)\n", ackmd);
897 return -EINVAL;
898 }
899
900 /* BPFMD */
901 switch (bpfmd) {
902 case 32:
903 data |= (0x0 << 8);
904 break;
905 case 64:
906 data |= (0x1 << 8);
907 break;
908 case 128:
909 data |= (0x2 << 8);
910 break;
911 case 256:
912 data |= (0x3 << 8);
913 break;
914 case 512:
915 data |= (0x4 << 8);
916 break;
917 case 16:
918 data |= (0x7 << 8);
919 break;
920 default:
921 dev_err(dev, "unsupported bpfmd (%d)\n", bpfmd);
922 return -EINVAL;
923 }
924
925 dev_dbg(dev, "ACKMD/BPFMD = %d/%d\n", ackmd, bpfmd);
926
927 fsi_reg_mask_set(fsi, CKG1, (ACKMD_MASK | BPFMD_MASK) , data);
928 udelay(10);
929
930 return 0;
931}
932
933static int fsi_clk_set_rate_external(struct device *dev,
Kuninori Morimoto6cbdbff2012-12-16 22:12:21 -0800934 struct fsi_priv *fsi)
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -0800935{
936 struct clk *xck = fsi->clock.xck;
937 struct clk *ick = fsi->clock.ick;
Kuninori Morimoto6cbdbff2012-12-16 22:12:21 -0800938 unsigned long rate = fsi->clock.rate;
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -0800939 unsigned long xrate;
940 int ackmd, bpfmd;
941 int ret = 0;
942
943 /* check clock rate */
944 xrate = clk_get_rate(xck);
945 if (xrate % rate) {
946 dev_err(dev, "unsupported clock rate\n");
947 return -EINVAL;
948 }
949
950 clk_set_parent(ick, xck);
951 clk_set_rate(ick, xrate);
952
953 bpfmd = fsi->chan_num * 32;
954 ackmd = xrate / rate;
955
956 dev_dbg(dev, "external/rate = %ld/%ld\n", xrate, rate);
957
958 ret = fsi_clk_set_ackbpf(dev, fsi, ackmd, bpfmd);
959 if (ret < 0)
960 dev_err(dev, "%s failed", __func__);
961
962 return ret;
963}
964
965static int fsi_clk_set_rate_cpg(struct device *dev,
Kuninori Morimoto6cbdbff2012-12-16 22:12:21 -0800966 struct fsi_priv *fsi)
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -0800967{
968 struct clk *ick = fsi->clock.ick;
969 struct clk *div = fsi->clock.div;
Kuninori Morimoto6cbdbff2012-12-16 22:12:21 -0800970 unsigned long rate = fsi->clock.rate;
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -0800971 unsigned long target = 0; /* 12288000 or 11289600 */
972 unsigned long actual, cout;
973 unsigned long diff, min;
974 unsigned long best_cout, best_act;
975 int adj;
976 int ackmd, bpfmd;
977 int ret = -EINVAL;
978
979 if (!(12288000 % rate))
980 target = 12288000;
981 if (!(11289600 % rate))
982 target = 11289600;
983 if (!target) {
984 dev_err(dev, "unsupported rate\n");
985 return ret;
986 }
987
988 bpfmd = fsi->chan_num * 32;
989 ackmd = target / rate;
990 ret = fsi_clk_set_ackbpf(dev, fsi, ackmd, bpfmd);
991 if (ret < 0) {
992 dev_err(dev, "%s failed", __func__);
993 return ret;
994 }
995
996 /*
997 * The clock flow is
998 *
999 * [CPG] = cout => [FSI_DIV] = audio => [FSI] => [codec]
1000 *
1001 * But, it needs to find best match of CPG and FSI_DIV
1002 * combination, since it is difficult to generate correct
1003 * frequency of audio clock from ick clock only.
1004 * Because ick is created from its parent clock.
1005 *
1006 * target = rate x [512/256/128/64]fs
1007 * cout = round(target x adjustment)
1008 * actual = cout / adjustment (by FSI-DIV) ~= target
1009 * audio = actual
1010 */
1011 min = ~0;
1012 best_cout = 0;
1013 best_act = 0;
1014 for (adj = 1; adj < 0xffff; adj++) {
1015
1016 cout = target * adj;
1017 if (cout > 100000000) /* max clock = 100MHz */
1018 break;
1019
1020 /* cout/actual audio clock */
1021 cout = clk_round_rate(ick, cout);
1022 actual = cout / adj;
1023
1024 /* find best frequency */
1025 diff = abs(actual - target);
1026 if (diff < min) {
1027 min = diff;
1028 best_cout = cout;
1029 best_act = actual;
1030 }
1031 }
1032
1033 ret = clk_set_rate(ick, best_cout);
1034 if (ret < 0) {
1035 dev_err(dev, "ick clock failed\n");
1036 return -EIO;
1037 }
1038
1039 ret = clk_set_rate(div, clk_round_rate(div, best_act));
1040 if (ret < 0) {
1041 dev_err(dev, "div clock failed\n");
1042 return -EIO;
1043 }
1044
1045 dev_dbg(dev, "ick/div = %ld/%ld\n",
1046 clk_get_rate(ick), clk_get_rate(div));
1047
1048 return ret;
1049}
1050
Kuninori Morimoto1f5e2a32011-04-21 10:33:52 +09001051/*
Kuninori Morimoto1b0ca1a2012-02-03 00:56:27 -08001052 * pio data transfer handler
Kuninori Morimoto1f5e2a32011-04-21 10:33:52 +09001053 */
Kuninori Morimoto1b0ca1a2012-02-03 00:56:27 -08001054static void fsi_pio_push16(struct fsi_priv *fsi, u8 *_buf, int samples)
1055{
Kuninori Morimoto1b0ca1a2012-02-03 00:56:27 -08001056 int i;
1057
Kuninori Morimoto2522acd2012-11-16 01:17:30 -08001058 if (fsi_is_enable_stream(fsi)) {
Kuninori Morimoto766812e2012-05-17 17:36:47 -07001059 /*
1060 * stream mode
1061 * see
1062 * fsi_pio_push_init()
1063 */
1064 u32 *buf = (u32 *)_buf;
1065
1066 for (i = 0; i < samples / 2; i++)
1067 fsi_reg_write(fsi, DODT, buf[i]);
1068 } else {
1069 /* normal mode */
1070 u16 *buf = (u16 *)_buf;
1071
1072 for (i = 0; i < samples; i++)
1073 fsi_reg_write(fsi, DODT, ((u32)*(buf + i) << 8));
1074 }
Kuninori Morimoto1b0ca1a2012-02-03 00:56:27 -08001075}
1076
1077static void fsi_pio_pop16(struct fsi_priv *fsi, u8 *_buf, int samples)
1078{
1079 u16 *buf = (u16 *)_buf;
1080 int i;
1081
1082 for (i = 0; i < samples; i++)
1083 *(buf + i) = (u16)(fsi_reg_read(fsi, DIDT) >> 8);
1084}
1085
1086static void fsi_pio_push32(struct fsi_priv *fsi, u8 *_buf, int samples)
1087{
1088 u32 *buf = (u32 *)_buf;
1089 int i;
1090
1091 for (i = 0; i < samples; i++)
1092 fsi_reg_write(fsi, DODT, *(buf + i));
1093}
1094
1095static void fsi_pio_pop32(struct fsi_priv *fsi, u8 *_buf, int samples)
1096{
1097 u32 *buf = (u32 *)_buf;
1098 int i;
1099
1100 for (i = 0; i < samples; i++)
1101 *(buf + i) = fsi_reg_read(fsi, DIDT);
1102}
1103
1104static u8 *fsi_pio_get_area(struct fsi_priv *fsi, struct fsi_stream *io)
1105{
1106 struct snd_pcm_runtime *runtime = io->substream->runtime;
1107
1108 return runtime->dma_area +
1109 samples_to_bytes(runtime, io->buff_sample_pos);
1110}
1111
1112static int fsi_pio_transfer(struct fsi_priv *fsi, struct fsi_stream *io,
Kuninori Morimoto95b0cf02012-02-03 00:52:38 -08001113 void (*run16)(struct fsi_priv *fsi, u8 *buf, int samples),
1114 void (*run32)(struct fsi_priv *fsi, u8 *buf, int samples),
1115 int samples)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001116{
1117 struct snd_pcm_runtime *runtime;
Kuninori Morimoto376cf382012-02-03 00:50:59 -08001118 struct snd_pcm_substream *substream;
Kuninori Morimoto95b0cf02012-02-03 00:52:38 -08001119 u8 *buf;
Kuninori Morimotob9fde182010-09-17 13:48:32 +09001120 int over_period;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001121
Kuninori Morimoto97df8182012-02-03 00:57:40 -08001122 if (!fsi_stream_is_working(fsi, io))
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001123 return -EINVAL;
1124
Kuninori Morimoto1c418d12009-12-28 14:09:05 +09001125 over_period = 0;
Kuninori Morimoto93193c22010-10-12 19:19:28 +09001126 substream = io->substream;
Kuninori Morimoto1c418d12009-12-28 14:09:05 +09001127 runtime = substream->runtime;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001128
1129 /* FSI FIFO has limit.
1130 * So, this driver can not send periods data at a time
1131 */
Kuninori Morimoto2e651ba2011-05-23 20:46:03 +09001132 if (io->buff_sample_pos >=
1133 io->period_samples * (io->period_pos + 1)) {
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001134
Kuninori Morimoto1c418d12009-12-28 14:09:05 +09001135 over_period = 1;
Kuninori Morimoto2e651ba2011-05-23 20:46:03 +09001136 io->period_pos = (io->period_pos + 1) % runtime->periods;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001137
Kuninori Morimoto2e651ba2011-05-23 20:46:03 +09001138 if (0 == io->period_pos)
1139 io->buff_sample_pos = 0;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001140 }
1141
Kuninori Morimoto95b0cf02012-02-03 00:52:38 -08001142 buf = fsi_pio_get_area(fsi, io);
1143
Kuninori Morimoto376cf382012-02-03 00:50:59 -08001144 switch (io->sample_width) {
1145 case 2:
Kuninori Morimoto95b0cf02012-02-03 00:52:38 -08001146 run16(fsi, buf, samples);
Kuninori Morimoto376cf382012-02-03 00:50:59 -08001147 break;
1148 case 4:
Kuninori Morimoto95b0cf02012-02-03 00:52:38 -08001149 run32(fsi, buf, samples);
Kuninori Morimoto376cf382012-02-03 00:50:59 -08001150 break;
1151 default:
1152 return -EINVAL;
Kuninori Morimoto9ddc9aa2009-10-30 12:02:39 +09001153 }
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001154
Kuninori Morimoto2e651ba2011-05-23 20:46:03 +09001155 /* update buff_sample_pos */
1156 io->buff_sample_pos += samples;
Kuninori Morimotod8b33532010-09-17 13:49:05 +09001157
Kuninori Morimoto1c418d12009-12-28 14:09:05 +09001158 if (over_period)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001159 snd_pcm_period_elapsed(substream);
1160
Kuninori Morimoto47fc9a02010-02-22 16:41:57 +09001161 return 0;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001162}
1163
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001164static int fsi_pio_pop(struct fsi_priv *fsi, struct fsi_stream *io)
Kuninori Morimoto07102f32009-10-30 12:02:44 +09001165{
Kuninori Morimoto376cf382012-02-03 00:50:59 -08001166 int sample_residues; /* samples in FSI fifo */
1167 int sample_space; /* ALSA free samples space */
1168 int samples;
Kuninori Morimoto376cf382012-02-03 00:50:59 -08001169
Kuninori Morimoto7b1b3332012-02-03 00:55:26 -08001170 sample_residues = fsi_get_current_fifo_samples(fsi, io);
Kuninori Morimoto376cf382012-02-03 00:50:59 -08001171 sample_space = io->buff_sample_capa - io->buff_sample_pos;
1172
1173 samples = min(sample_residues, sample_space);
1174
Kuninori Morimoto1b0ca1a2012-02-03 00:56:27 -08001175 return fsi_pio_transfer(fsi, io,
Kuninori Morimotod78629e2012-02-03 00:51:14 -08001176 fsi_pio_pop16,
1177 fsi_pio_pop32,
Kuninori Morimoto376cf382012-02-03 00:50:59 -08001178 samples);
Kuninori Morimotod8b33532010-09-17 13:49:05 +09001179}
Kuninori Morimoto07102f32009-10-30 12:02:44 +09001180
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001181static int fsi_pio_push(struct fsi_priv *fsi, struct fsi_stream *io)
Kuninori Morimotod8b33532010-09-17 13:49:05 +09001182{
Kuninori Morimoto376cf382012-02-03 00:50:59 -08001183 int sample_residues; /* ALSA residue samples */
1184 int sample_space; /* FSI fifo free samples space */
1185 int samples;
Kuninori Morimoto376cf382012-02-03 00:50:59 -08001186
1187 sample_residues = io->buff_sample_capa - io->buff_sample_pos;
1188 sample_space = io->fifo_sample_capa -
Kuninori Morimoto7b1b3332012-02-03 00:55:26 -08001189 fsi_get_current_fifo_samples(fsi, io);
Kuninori Morimoto376cf382012-02-03 00:50:59 -08001190
1191 samples = min(sample_residues, sample_space);
1192
Kuninori Morimoto1b0ca1a2012-02-03 00:56:27 -08001193 return fsi_pio_transfer(fsi, io,
Kuninori Morimotod78629e2012-02-03 00:51:14 -08001194 fsi_pio_push16,
1195 fsi_pio_push32,
Kuninori Morimoto376cf382012-02-03 00:50:59 -08001196 samples);
Kuninori Morimoto07102f32009-10-30 12:02:44 +09001197}
1198
Kuninori Morimoto180346e2012-02-03 00:57:25 -08001199static void fsi_pio_start_stop(struct fsi_priv *fsi, struct fsi_stream *io,
1200 int enable)
1201{
1202 struct fsi_master *master = fsi_get_master(fsi);
1203 u32 clk = fsi_is_port_a(fsi) ? CRA : CRB;
1204
1205 if (enable)
1206 fsi_irq_enable(fsi, io);
1207 else
1208 fsi_irq_disable(fsi, io);
1209
1210 if (fsi_is_clk_master(fsi))
1211 fsi_master_mask_set(master, CLK_RST, clk, (enable) ? clk : 0);
1212}
1213
Kuninori Morimoto766812e2012-05-17 17:36:47 -07001214static int fsi_pio_push_init(struct fsi_priv *fsi, struct fsi_stream *io)
1215{
Kuninori Morimoto766812e2012-05-17 17:36:47 -07001216 /*
1217 * we can use 16bit stream mode
1218 * when "playback" and "16bit data"
1219 * and platform allows "stream mode"
1220 * see
1221 * fsi_pio_push16()
1222 */
Kuninori Morimoto2522acd2012-11-16 01:17:30 -08001223 if (fsi_is_enable_stream(fsi))
Kuninori Morimoto766812e2012-05-17 17:36:47 -07001224 io->bus_option = BUSOP_SET(24, PACKAGE_24BITBUS_BACK) |
1225 BUSOP_SET(16, PACKAGE_16BITBUS_STREAM);
1226 else
1227 io->bus_option = BUSOP_SET(24, PACKAGE_24BITBUS_BACK) |
1228 BUSOP_SET(16, PACKAGE_24BITBUS_BACK);
1229 return 0;
1230}
1231
1232static int fsi_pio_pop_init(struct fsi_priv *fsi, struct fsi_stream *io)
1233{
1234 /*
1235 * always 24bit bus, package back when "capture"
1236 */
1237 io->bus_option = BUSOP_SET(24, PACKAGE_24BITBUS_BACK) |
1238 BUSOP_SET(16, PACKAGE_24BITBUS_BACK);
1239 return 0;
1240}
1241
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001242static struct fsi_stream_handler fsi_pio_push_handler = {
Kuninori Morimoto766812e2012-05-17 17:36:47 -07001243 .init = fsi_pio_push_init,
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001244 .transfer = fsi_pio_push,
Kuninori Morimoto180346e2012-02-03 00:57:25 -08001245 .start_stop = fsi_pio_start_stop,
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001246};
1247
1248static struct fsi_stream_handler fsi_pio_pop_handler = {
Kuninori Morimoto766812e2012-05-17 17:36:47 -07001249 .init = fsi_pio_pop_init,
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001250 .transfer = fsi_pio_pop,
Kuninori Morimoto180346e2012-02-03 00:57:25 -08001251 .start_stop = fsi_pio_start_stop,
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001252};
1253
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001254static irqreturn_t fsi_interrupt(int irq, void *data)
1255{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +09001256 struct fsi_master *master = data;
Kuninori Morimoto10ea76c2010-03-23 11:47:54 +09001257 u32 int_st = fsi_irq_get_status(master);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001258
1259 /* clear irq status */
Kuninori Morimotofeb58cf2010-03-24 15:27:24 +09001260 fsi_master_mask_set(master, SOFT_RST, IR, 0);
1261 fsi_master_mask_set(master, SOFT_RST, IR, IR);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001262
Kuninori Morimotocf6edd02010-10-12 11:40:53 +09001263 if (int_st & AB_IO(1, AO_SHIFT))
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001264 fsi_stream_transfer(&master->fsia.playback);
Kuninori Morimotocf6edd02010-10-12 11:40:53 +09001265 if (int_st & AB_IO(1, BO_SHIFT))
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001266 fsi_stream_transfer(&master->fsib.playback);
Kuninori Morimotocf6edd02010-10-12 11:40:53 +09001267 if (int_st & AB_IO(1, AI_SHIFT))
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001268 fsi_stream_transfer(&master->fsia.capture);
Kuninori Morimotocf6edd02010-10-12 11:40:53 +09001269 if (int_st & AB_IO(1, BI_SHIFT))
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001270 fsi_stream_transfer(&master->fsib.capture);
Kuninori Morimoto1ec9bc32010-12-17 12:55:22 +09001271
1272 fsi_count_fifo_err(&master->fsia);
1273 fsi_count_fifo_err(&master->fsib);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001274
Kuninori Morimoto48d78e52010-12-03 17:37:31 +09001275 fsi_irq_clear_status(&master->fsia);
1276 fsi_irq_clear_status(&master->fsib);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001277
1278 return IRQ_HANDLED;
1279}
1280
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +09001281/*
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001282 * dma data transfer handler
1283 */
1284static int fsi_dma_init(struct fsi_priv *fsi, struct fsi_stream *io)
1285{
1286 struct snd_pcm_runtime *runtime = io->substream->runtime;
1287 struct snd_soc_dai *dai = fsi_get_dai(io->substream);
1288 enum dma_data_direction dir = fsi_stream_is_play(fsi, io) ?
1289 DMA_TO_DEVICE : DMA_FROM_DEVICE;
1290
Kuninori Morimoto766812e2012-05-17 17:36:47 -07001291 /*
1292 * 24bit data : 24bit bus / package in back
1293 * 16bit data : 16bit bus / stream mode
1294 */
1295 io->bus_option = BUSOP_SET(24, PACKAGE_24BITBUS_BACK) |
1296 BUSOP_SET(16, PACKAGE_16BITBUS_STREAM);
1297
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001298 io->dma = dma_map_single(dai->dev, runtime->dma_area,
1299 snd_pcm_lib_buffer_bytes(io->substream), dir);
1300 return 0;
1301}
1302
1303static int fsi_dma_quit(struct fsi_priv *fsi, struct fsi_stream *io)
1304{
1305 struct snd_soc_dai *dai = fsi_get_dai(io->substream);
1306 enum dma_data_direction dir = fsi_stream_is_play(fsi, io) ?
1307 DMA_TO_DEVICE : DMA_FROM_DEVICE;
1308
1309 dma_unmap_single(dai->dev, io->dma,
1310 snd_pcm_lib_buffer_bytes(io->substream), dir);
1311 return 0;
1312}
1313
Kuninori Morimoto4a1b09b2012-05-28 23:27:49 -07001314static dma_addr_t fsi_dma_get_area(struct fsi_stream *io)
1315{
1316 struct snd_pcm_runtime *runtime = io->substream->runtime;
1317
1318 return io->dma + samples_to_bytes(runtime, io->buff_sample_pos);
1319}
1320
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001321static void fsi_dma_complete(void *data)
1322{
1323 struct fsi_stream *io = (struct fsi_stream *)data;
1324 struct fsi_priv *fsi = fsi_stream_to_priv(io);
1325 struct snd_pcm_runtime *runtime = io->substream->runtime;
1326 struct snd_soc_dai *dai = fsi_get_dai(io->substream);
1327 enum dma_data_direction dir = fsi_stream_is_play(fsi, io) ?
1328 DMA_TO_DEVICE : DMA_FROM_DEVICE;
1329
Kuninori Morimoto4a1b09b2012-05-28 23:27:49 -07001330 dma_sync_single_for_cpu(dai->dev, fsi_dma_get_area(io),
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001331 samples_to_bytes(runtime, io->period_samples), dir);
1332
1333 io->buff_sample_pos += io->period_samples;
1334 io->period_pos++;
1335
1336 if (io->period_pos >= runtime->periods) {
1337 io->period_pos = 0;
1338 io->buff_sample_pos = 0;
1339 }
1340
1341 fsi_count_fifo_err(fsi);
1342 fsi_stream_transfer(io);
1343
1344 snd_pcm_period_elapsed(io->substream);
1345}
1346
Guennadi Liakhovetski57451e42012-10-03 14:33:50 +02001347static void fsi_dma_do_work(struct work_struct *work)
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001348{
Guennadi Liakhovetski57451e42012-10-03 14:33:50 +02001349 struct fsi_stream *io = container_of(work, struct fsi_stream, work);
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001350 struct fsi_priv *fsi = fsi_stream_to_priv(io);
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001351 struct snd_soc_dai *dai;
1352 struct dma_async_tx_descriptor *desc;
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001353 struct snd_pcm_runtime *runtime;
1354 enum dma_data_direction dir;
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001355 int is_play = fsi_stream_is_play(fsi, io);
1356 int len;
1357 dma_addr_t buf;
1358
1359 if (!fsi_stream_is_working(fsi, io))
1360 return;
1361
1362 dai = fsi_get_dai(io->substream);
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001363 runtime = io->substream->runtime;
1364 dir = is_play ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
1365 len = samples_to_bytes(runtime, io->period_samples);
1366 buf = fsi_dma_get_area(io);
1367
Kuninori Morimoto4a1b09b2012-05-28 23:27:49 -07001368 dma_sync_single_for_device(dai->dev, buf, len, dir);
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001369
Kuninori Morimoto5514efd2012-05-28 23:29:36 -07001370 desc = dmaengine_prep_slave_single(io->chan, buf, len, dir,
1371 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001372 if (!desc) {
Paul Mundtcdf27f32012-04-17 19:13:04 -07001373 dev_err(dai->dev, "dmaengine_prep_slave_sg() fail\n");
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001374 return;
1375 }
1376
1377 desc->callback = fsi_dma_complete;
1378 desc->callback_param = io;
1379
Kuninori Morimoto5514efd2012-05-28 23:29:36 -07001380 if (dmaengine_submit(desc) < 0) {
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001381 dev_err(dai->dev, "tx_submit() fail\n");
1382 return;
1383 }
1384
Kuninori Morimoto5514efd2012-05-28 23:29:36 -07001385 dma_async_issue_pending(io->chan);
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001386
1387 /*
1388 * FIXME
1389 *
1390 * In DMAEngine case, codec and FSI cannot be started simultaneously
Guennadi Liakhovetski57451e42012-10-03 14:33:50 +02001391 * since FSI is using the scheduler work queue.
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001392 * Therefore, in capture case, probably FSI FIFO will have got
1393 * overflow error in this point.
1394 * in that case, DMA cannot start transfer until error was cleared.
1395 */
1396 if (!is_play) {
1397 if (ERR_OVER & fsi_reg_read(fsi, DIFF_ST)) {
1398 fsi_reg_mask_set(fsi, DIFF_CTL, FIFO_CLR, FIFO_CLR);
1399 fsi_reg_write(fsi, DIFF_ST, 0);
1400 }
1401 }
1402}
1403
1404static bool fsi_dma_filter(struct dma_chan *chan, void *param)
1405{
1406 struct sh_dmae_slave *slave = param;
1407
1408 chan->private = slave;
1409
1410 return true;
1411}
1412
1413static int fsi_dma_transfer(struct fsi_priv *fsi, struct fsi_stream *io)
1414{
Guennadi Liakhovetski57451e42012-10-03 14:33:50 +02001415 schedule_work(&io->work);
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001416
1417 return 0;
1418}
1419
1420static void fsi_dma_push_start_stop(struct fsi_priv *fsi, struct fsi_stream *io,
1421 int start)
1422{
Kuninori Morimotoe42bb9b2012-05-24 23:55:11 -07001423 struct fsi_master *master = fsi_get_master(fsi);
1424 u32 clk = fsi_is_port_a(fsi) ? CRA : CRB;
Kuninori Morimoto766812e2012-05-17 17:36:47 -07001425 u32 enable = start ? DMA_ON : 0;
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001426
Kuninori Morimoto766812e2012-05-17 17:36:47 -07001427 fsi_reg_mask_set(fsi, OUT_DMAC, DMA_ON, enable);
Kuninori Morimotoe42bb9b2012-05-24 23:55:11 -07001428
Kuninori Morimotofbe42f62012-05-28 23:28:22 -07001429 dmaengine_terminate_all(io->chan);
1430
Kuninori Morimotoe42bb9b2012-05-24 23:55:11 -07001431 if (fsi_is_clk_master(fsi))
1432 fsi_master_mask_set(master, CLK_RST, clk, (enable) ? clk : 0);
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001433}
1434
Kuninori Morimotob1226dc2012-05-24 23:56:19 -07001435static int fsi_dma_probe(struct fsi_priv *fsi, struct fsi_stream *io, struct device *dev)
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001436{
1437 dma_cap_mask_t mask;
1438
1439 dma_cap_zero(mask);
1440 dma_cap_set(DMA_SLAVE, mask);
1441
1442 io->chan = dma_request_channel(mask, fsi_dma_filter, &io->slave);
Kuninori Morimotob1226dc2012-05-24 23:56:19 -07001443 if (!io->chan) {
1444
1445 /* switch to PIO handler */
1446 if (fsi_stream_is_play(fsi, io))
1447 fsi->playback.handler = &fsi_pio_push_handler;
1448 else
1449 fsi->capture.handler = &fsi_pio_pop_handler;
1450
1451 dev_info(dev, "switch handler (dma => pio)\n");
1452
1453 /* probe again */
1454 return fsi_stream_probe(fsi, dev);
1455 }
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001456
Guennadi Liakhovetski57451e42012-10-03 14:33:50 +02001457 INIT_WORK(&io->work, fsi_dma_do_work);
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001458
1459 return 0;
1460}
1461
1462static int fsi_dma_remove(struct fsi_priv *fsi, struct fsi_stream *io)
1463{
Guennadi Liakhovetski57451e42012-10-03 14:33:50 +02001464 cancel_work_sync(&io->work);
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001465
1466 fsi_stream_stop(fsi, io);
1467
1468 if (io->chan)
1469 dma_release_channel(io->chan);
1470
1471 io->chan = NULL;
1472 return 0;
1473}
1474
1475static struct fsi_stream_handler fsi_dma_push_handler = {
1476 .init = fsi_dma_init,
1477 .quit = fsi_dma_quit,
1478 .probe = fsi_dma_probe,
1479 .transfer = fsi_dma_transfer,
1480 .remove = fsi_dma_remove,
1481 .start_stop = fsi_dma_push_start_stop,
1482};
1483
1484/*
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +09001485 * dai ops
1486 */
Kuninori Morimotob49e8022012-02-03 00:51:29 -08001487static void fsi_fifo_init(struct fsi_priv *fsi,
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001488 struct fsi_stream *io,
Kuninori Morimotob49e8022012-02-03 00:51:29 -08001489 struct device *dev)
1490{
1491 struct fsi_master *master = fsi_get_master(fsi);
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001492 int is_play = fsi_stream_is_play(fsi, io);
Kuninori Morimotob49e8022012-02-03 00:51:29 -08001493 u32 shift, i;
1494 int frame_capa;
1495
1496 /* get on-chip RAM capacity */
1497 shift = fsi_master_read(master, FIFO_SZ);
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001498 shift >>= fsi_get_port_shift(fsi, io);
Kuninori Morimotob49e8022012-02-03 00:51:29 -08001499 shift &= FIFO_SZ_MASK;
1500 frame_capa = 256 << shift;
1501 dev_dbg(dev, "fifo = %d words\n", frame_capa);
1502
1503 /*
1504 * The maximum number of sample data varies depending
1505 * on the number of channels selected for the format.
1506 *
1507 * FIFOs are used in 4-channel units in 3-channel mode
1508 * and in 8-channel units in 5- to 7-channel mode
1509 * meaning that more FIFOs than the required size of DPRAM
1510 * are used.
1511 *
1512 * ex) if 256 words of DP-RAM is connected
1513 * 1 channel: 256 (256 x 1 = 256)
1514 * 2 channels: 128 (128 x 2 = 256)
1515 * 3 channels: 64 ( 64 x 3 = 192)
1516 * 4 channels: 64 ( 64 x 4 = 256)
1517 * 5 channels: 32 ( 32 x 5 = 160)
1518 * 6 channels: 32 ( 32 x 6 = 192)
1519 * 7 channels: 32 ( 32 x 7 = 224)
1520 * 8 channels: 32 ( 32 x 8 = 256)
1521 */
1522 for (i = 1; i < fsi->chan_num; i <<= 1)
1523 frame_capa >>= 1;
1524 dev_dbg(dev, "%d channel %d store\n",
1525 fsi->chan_num, frame_capa);
1526
1527 io->fifo_sample_capa = fsi_frame2sample(fsi, frame_capa);
1528
1529 /*
1530 * set interrupt generation factor
1531 * clear FIFO
1532 */
1533 if (is_play) {
1534 fsi_reg_write(fsi, DOFF_CTL, IRQ_HALF);
1535 fsi_reg_mask_set(fsi, DOFF_CTL, FIFO_CLR, FIFO_CLR);
1536 } else {
1537 fsi_reg_write(fsi, DIFF_CTL, IRQ_HALF);
1538 fsi_reg_mask_set(fsi, DIFF_CTL, FIFO_CLR, FIFO_CLR);
1539 }
1540}
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001541
Kuninori Morimoto23ca8532011-05-23 20:46:26 +09001542static int fsi_hw_startup(struct fsi_priv *fsi,
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001543 struct fsi_stream *io,
Kuninori Morimoto23ca8532011-05-23 20:46:26 +09001544 struct device *dev)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001545{
Kuninori Morimoto93193c22010-10-12 19:19:28 +09001546 u32 flags = fsi_get_info_flags(fsi);
Kuninori Morimoto9478e0b2011-05-23 20:46:07 +09001547 u32 data = 0;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001548
Kuninori Morimoto9478e0b2011-05-23 20:46:07 +09001549 /* clock setting */
1550 if (fsi_is_clk_master(fsi))
1551 data = DIMD | DOMD;
1552
1553 fsi_reg_mask_set(fsi, CKG1, (DIMD | DOMD), data);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001554
1555 /* clock inversion (CKG2) */
1556 data = 0;
Kuninori Morimoto3449f5f2012-11-16 01:17:43 -08001557 if (fsi->bit_clk_inv)
1558 data |= (1 << 0);
1559 if (fsi->lr_clk_inv)
1560 data |= (1 << 4);
1561 if (fsi_is_clk_master(fsi))
1562 data <<= 8;
1563 /* FIXME
1564 *
1565 * SH_FSI_xxx_INV style will be removed
1566 */
Kuninori Morimotob427b442010-07-13 12:01:15 +09001567 if (SH_FSI_LRM_INV & flags)
1568 data |= 1 << 12;
1569 if (SH_FSI_BRM_INV & flags)
1570 data |= 1 << 8;
1571 if (SH_FSI_LRS_INV & flags)
1572 data |= 1 << 4;
1573 if (SH_FSI_BRS_INV & flags)
1574 data |= 1 << 0;
1575
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001576 fsi_reg_write(fsi, CKG2, data);
1577
Kuninori Morimoto9478e0b2011-05-23 20:46:07 +09001578 /* spdif ? */
1579 if (fsi_is_spdif(fsi)) {
1580 fsi_spdif_clk_ctrl(fsi, 1);
1581 fsi_reg_mask_set(fsi, OUT_SEL, DMMD, DMMD);
1582 }
1583
Kuninori Morimoto65ff03f2011-11-06 22:05:25 -08001584 /*
Kuninori Morimoto766812e2012-05-17 17:36:47 -07001585 * get bus settings
Kuninori Morimoto65ff03f2011-11-06 22:05:25 -08001586 */
Kuninori Morimoto766812e2012-05-17 17:36:47 -07001587 data = 0;
1588 switch (io->sample_width) {
1589 case 2:
1590 data = BUSOP_GET(16, io->bus_option);
1591 break;
1592 case 4:
1593 data = BUSOP_GET(24, io->bus_option);
1594 break;
Kuninori Morimoto65ff03f2011-11-06 22:05:25 -08001595 }
Kuninori Morimoto766812e2012-05-17 17:36:47 -07001596 fsi_format_bus_setup(fsi, io, data, dev);
Kuninori Morimoto65ff03f2011-11-06 22:05:25 -08001597
Kuninori Morimoto10ea76c2010-03-23 11:47:54 +09001598 /* irq clear */
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001599 fsi_irq_disable(fsi, io);
Kuninori Morimoto10ea76c2010-03-23 11:47:54 +09001600 fsi_irq_clear_status(fsi);
1601
1602 /* fifo init */
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001603 fsi_fifo_init(fsi, io, dev);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001604
Kuninori Morimotoddeb2d72012-10-29 00:37:22 -07001605 /* start master clock */
1606 if (fsi_is_clk_master(fsi))
Kuninori Morimoto6cbdbff2012-12-16 22:12:21 -08001607 return fsi_clk_enable(dev, fsi);
Kuninori Morimotoddeb2d72012-10-29 00:37:22 -07001608
Kuninori Morimotoa68a3b42010-10-12 11:39:50 +09001609 return 0;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001610}
1611
Kuninori Morimoto80b4add2012-10-30 19:59:15 -07001612static int fsi_hw_shutdown(struct fsi_priv *fsi,
Kuninori Morimoto23ca8532011-05-23 20:46:26 +09001613 struct device *dev)
1614{
Kuninori Morimotoddeb2d72012-10-29 00:37:22 -07001615 /* stop master clock */
Kuninori Morimoto23ca8532011-05-23 20:46:26 +09001616 if (fsi_is_clk_master(fsi))
Kuninori Morimoto6cbdbff2012-12-16 22:12:21 -08001617 return fsi_clk_disable(dev, fsi);
Kuninori Morimoto80b4add2012-10-30 19:59:15 -07001618
1619 return 0;
Kuninori Morimoto23ca8532011-05-23 20:46:26 +09001620}
1621
1622static int fsi_dai_startup(struct snd_pcm_substream *substream,
1623 struct snd_soc_dai *dai)
1624{
1625 struct fsi_priv *fsi = fsi_get_priv(substream);
Kuninori Morimoto23ca8532011-05-23 20:46:26 +09001626
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -08001627 fsi_clk_invalid(fsi);
Kuninori Morimotof33238e2012-05-17 17:35:34 -07001628
1629 return 0;
Kuninori Morimoto23ca8532011-05-23 20:46:26 +09001630}
1631
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001632static void fsi_dai_shutdown(struct snd_pcm_substream *substream,
1633 struct snd_soc_dai *dai)
1634{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +09001635 struct fsi_priv *fsi = fsi_get_priv(substream);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001636
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -08001637 fsi_clk_invalid(fsi);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001638}
1639
1640static int fsi_dai_trigger(struct snd_pcm_substream *substream, int cmd,
1641 struct snd_soc_dai *dai)
1642{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +09001643 struct fsi_priv *fsi = fsi_get_priv(substream);
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001644 struct fsi_stream *io = fsi_stream_get(fsi, substream);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001645 int ret = 0;
1646
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001647 switch (cmd) {
1648 case SNDRV_PCM_TRIGGER_START:
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001649 fsi_stream_init(fsi, io, substream);
Kuninori Morimoto80b4add2012-10-30 19:59:15 -07001650 if (!ret)
1651 ret = fsi_hw_startup(fsi, io, dai->dev);
1652 if (!ret)
1653 ret = fsi_stream_transfer(io);
1654 if (!ret)
Kuninori Morimoto180346e2012-02-03 00:57:25 -08001655 fsi_stream_start(fsi, io);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001656 break;
1657 case SNDRV_PCM_TRIGGER_STOP:
Kuninori Morimoto80b4add2012-10-30 19:59:15 -07001658 if (!ret)
1659 ret = fsi_hw_shutdown(fsi, dai->dev);
Kuninori Morimoto180346e2012-02-03 00:57:25 -08001660 fsi_stream_stop(fsi, io);
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001661 fsi_stream_quit(fsi, io);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001662 break;
1663 }
1664
1665 return ret;
1666}
1667
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001668static int fsi_set_fmt_dai(struct fsi_priv *fsi, unsigned int fmt)
1669{
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001670 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
1671 case SND_SOC_DAIFMT_I2S:
Kuninori Morimoto9c59dd32012-05-17 17:34:53 -07001672 fsi->fmt = CR_I2S;
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001673 fsi->chan_num = 2;
1674 break;
1675 case SND_SOC_DAIFMT_LEFT_J:
Kuninori Morimoto9c59dd32012-05-17 17:34:53 -07001676 fsi->fmt = CR_PCM;
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001677 fsi->chan_num = 2;
1678 break;
1679 default:
1680 return -EINVAL;
1681 }
1682
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001683 return 0;
1684}
1685
1686static int fsi_set_fmt_spdif(struct fsi_priv *fsi)
1687{
1688 struct fsi_master *master = fsi_get_master(fsi);
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001689
Kuninori Morimoto284c6f62012-05-17 17:34:16 -07001690 if (fsi_version(master) < 2)
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001691 return -EINVAL;
1692
Kuninori Morimoto766812e2012-05-17 17:36:47 -07001693 fsi->fmt = CR_DTMD_SPDIF_PCM | CR_PCM;
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001694 fsi->chan_num = 2;
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001695
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001696 return 0;
1697}
1698
Kuninori Morimoto4d805f72011-01-20 11:46:02 +09001699static int fsi_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
1700{
1701 struct fsi_priv *fsi = fsi_get_priv_frm_dai(dai);
Kuninori Morimoto4d805f72011-01-20 11:46:02 +09001702 int ret;
1703
Kuninori Morimoto4d805f72011-01-20 11:46:02 +09001704 /* set master/slave audio interface */
1705 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1706 case SND_SOC_DAIFMT_CBM_CFM:
Kuninori Morimoto6a9ebad2011-04-21 10:33:36 +09001707 fsi->clk_master = 1;
Kuninori Morimoto4d805f72011-01-20 11:46:02 +09001708 break;
1709 case SND_SOC_DAIFMT_CBS_CFS:
1710 break;
1711 default:
Kuninori Morimoto9478e0b2011-05-23 20:46:07 +09001712 return -EINVAL;
Kuninori Morimoto4d805f72011-01-20 11:46:02 +09001713 }
Kuninori Morimoto6a9ebad2011-04-21 10:33:36 +09001714
Kuninori Morimoto3449f5f2012-11-16 01:17:43 -08001715 /* set clock inversion */
1716 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
1717 case SND_SOC_DAIFMT_NB_IF:
1718 fsi->bit_clk_inv = 0;
1719 fsi->lr_clk_inv = 1;
1720 break;
1721 case SND_SOC_DAIFMT_IB_NF:
1722 fsi->bit_clk_inv = 1;
1723 fsi->lr_clk_inv = 0;
1724 break;
1725 case SND_SOC_DAIFMT_IB_IF:
1726 fsi->bit_clk_inv = 1;
1727 fsi->lr_clk_inv = 1;
1728 break;
1729 case SND_SOC_DAIFMT_NB_NF:
1730 default:
1731 fsi->bit_clk_inv = 0;
1732 fsi->lr_clk_inv = 0;
1733 break;
1734 }
1735
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -08001736 if (fsi_is_clk_master(fsi)) {
Kuninori Morimotoab6340c2012-11-16 01:17:18 -08001737 if (fsi->clk_cpg)
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -08001738 fsi_clk_init(dai->dev, fsi, 0, 1, 1,
1739 fsi_clk_set_rate_cpg);
Kuninori Morimotoab6340c2012-11-16 01:17:18 -08001740 else
1741 fsi_clk_init(dai->dev, fsi, 1, 1, 0,
1742 fsi_clk_set_rate_external);
Kuninori Morimoto6a9ebad2011-04-21 10:33:36 +09001743 }
1744
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001745 /* set format */
Kuninori Morimotoc2052de2012-11-16 01:17:06 -08001746 if (fsi_is_spdif(fsi))
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001747 ret = fsi_set_fmt_spdif(fsi);
Kuninori Morimotoc2052de2012-11-16 01:17:06 -08001748 else
1749 ret = fsi_set_fmt_dai(fsi, fmt & SND_SOC_DAIFMT_FORMAT_MASK);
Kuninori Morimoto4d805f72011-01-20 11:46:02 +09001750
Kuninori Morimoto4d805f72011-01-20 11:46:02 +09001751 return ret;
1752}
1753
Kuninori Morimotoccad7b42010-07-13 12:13:14 +09001754static int fsi_dai_hw_params(struct snd_pcm_substream *substream,
1755 struct snd_pcm_hw_params *params,
1756 struct snd_soc_dai *dai)
1757{
1758 struct fsi_priv *fsi = fsi_get_priv(substream);
Kuninori Morimotoccad7b42010-07-13 12:13:14 +09001759
Kuninori Morimoto6cbdbff2012-12-16 22:12:21 -08001760 if (fsi_is_clk_master(fsi))
1761 fsi_clk_valid(fsi, params_rate(params));
Kuninori Morimotoccad7b42010-07-13 12:13:14 +09001762
Kuninori Morimotoddeb2d72012-10-29 00:37:22 -07001763 return 0;
Kuninori Morimotoccad7b42010-07-13 12:13:14 +09001764}
1765
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01001766static const struct snd_soc_dai_ops fsi_dai_ops = {
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001767 .startup = fsi_dai_startup,
1768 .shutdown = fsi_dai_shutdown,
1769 .trigger = fsi_dai_trigger,
Kuninori Morimoto4d805f72011-01-20 11:46:02 +09001770 .set_fmt = fsi_dai_set_fmt,
Kuninori Morimotoccad7b42010-07-13 12:13:14 +09001771 .hw_params = fsi_dai_hw_params,
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001772};
1773
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +09001774/*
1775 * pcm ops
1776 */
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001777
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001778static struct snd_pcm_hardware fsi_pcm_hardware = {
1779 .info = SNDRV_PCM_INFO_INTERLEAVED |
1780 SNDRV_PCM_INFO_MMAP |
1781 SNDRV_PCM_INFO_MMAP_VALID |
1782 SNDRV_PCM_INFO_PAUSE,
1783 .formats = FSI_FMTS,
1784 .rates = FSI_RATES,
1785 .rate_min = 8000,
1786 .rate_max = 192000,
Kuninori Morimoto2a8c8a52012-10-02 19:08:53 -07001787 .channels_min = 2,
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001788 .channels_max = 2,
1789 .buffer_bytes_max = 64 * 1024,
1790 .period_bytes_min = 32,
1791 .period_bytes_max = 8192,
1792 .periods_min = 1,
1793 .periods_max = 32,
1794 .fifo_size = 256,
1795};
1796
1797static int fsi_pcm_open(struct snd_pcm_substream *substream)
1798{
1799 struct snd_pcm_runtime *runtime = substream->runtime;
1800 int ret = 0;
1801
1802 snd_soc_set_runtime_hwparams(substream, &fsi_pcm_hardware);
1803
1804 ret = snd_pcm_hw_constraint_integer(runtime,
1805 SNDRV_PCM_HW_PARAM_PERIODS);
1806
1807 return ret;
1808}
1809
1810static int fsi_hw_params(struct snd_pcm_substream *substream,
1811 struct snd_pcm_hw_params *hw_params)
1812{
1813 return snd_pcm_lib_malloc_pages(substream,
1814 params_buffer_bytes(hw_params));
1815}
1816
1817static int fsi_hw_free(struct snd_pcm_substream *substream)
1818{
1819 return snd_pcm_lib_free_pages(substream);
1820}
1821
1822static snd_pcm_uframes_t fsi_pointer(struct snd_pcm_substream *substream)
1823{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +09001824 struct fsi_priv *fsi = fsi_get_priv(substream);
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001825 struct fsi_stream *io = fsi_stream_get(fsi, substream);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001826
Kuninori Morimoto19878772012-02-08 16:57:29 -08001827 return fsi_sample2frame(fsi, io->buff_sample_pos);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001828}
1829
1830static struct snd_pcm_ops fsi_pcm_ops = {
1831 .open = fsi_pcm_open,
1832 .ioctl = snd_pcm_lib_ioctl,
1833 .hw_params = fsi_hw_params,
1834 .hw_free = fsi_hw_free,
1835 .pointer = fsi_pointer,
1836};
1837
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +09001838/*
1839 * snd_soc_platform
1840 */
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001841
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001842#define PREALLOC_BUFFER (32 * 1024)
1843#define PREALLOC_BUFFER_MAX (32 * 1024)
1844
1845static void fsi_pcm_free(struct snd_pcm *pcm)
1846{
1847 snd_pcm_lib_preallocate_free_for_all(pcm);
1848}
1849
Liam Girdwood552d1ef2011-06-07 16:08:33 +01001850static int fsi_pcm_new(struct snd_soc_pcm_runtime *rtd)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001851{
Liam Girdwood552d1ef2011-06-07 16:08:33 +01001852 struct snd_pcm *pcm = rtd->pcm;
1853
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001854 /*
1855 * dont use SNDRV_DMA_TYPE_DEV, since it will oops the SH kernel
1856 * in MMAP mode (i.e. aplay -M)
1857 */
1858 return snd_pcm_lib_preallocate_pages_for_all(
1859 pcm,
1860 SNDRV_DMA_TYPE_CONTINUOUS,
1861 snd_dma_continuous_data(GFP_KERNEL),
1862 PREALLOC_BUFFER, PREALLOC_BUFFER_MAX);
1863}
1864
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +09001865/*
1866 * alsa struct
1867 */
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001868
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001869static struct snd_soc_dai_driver fsi_soc_dai[] = {
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001870 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001871 .name = "fsia-dai",
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001872 .playback = {
1873 .rates = FSI_RATES,
1874 .formats = FSI_FMTS,
Kuninori Morimoto2a8c8a52012-10-02 19:08:53 -07001875 .channels_min = 2,
1876 .channels_max = 2,
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001877 },
Kuninori Morimoto07102f32009-10-30 12:02:44 +09001878 .capture = {
1879 .rates = FSI_RATES,
1880 .formats = FSI_FMTS,
Kuninori Morimoto2a8c8a52012-10-02 19:08:53 -07001881 .channels_min = 2,
1882 .channels_max = 2,
Kuninori Morimoto07102f32009-10-30 12:02:44 +09001883 },
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001884 .ops = &fsi_dai_ops,
1885 },
1886 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001887 .name = "fsib-dai",
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001888 .playback = {
1889 .rates = FSI_RATES,
1890 .formats = FSI_FMTS,
Kuninori Morimoto2a8c8a52012-10-02 19:08:53 -07001891 .channels_min = 2,
1892 .channels_max = 2,
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001893 },
Kuninori Morimoto07102f32009-10-30 12:02:44 +09001894 .capture = {
1895 .rates = FSI_RATES,
1896 .formats = FSI_FMTS,
Kuninori Morimoto2a8c8a52012-10-02 19:08:53 -07001897 .channels_min = 2,
1898 .channels_max = 2,
Kuninori Morimoto07102f32009-10-30 12:02:44 +09001899 },
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001900 .ops = &fsi_dai_ops,
1901 },
1902};
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001903
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001904static struct snd_soc_platform_driver fsi_soc_platform = {
1905 .ops = &fsi_pcm_ops,
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001906 .pcm_new = fsi_pcm_new,
1907 .pcm_free = fsi_pcm_free,
1908};
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001909
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +09001910/*
1911 * platform function
1912 */
Kuninori Morimotoc2052de2012-11-16 01:17:06 -08001913static void fsi_port_info_init(struct fsi_priv *fsi,
1914 struct sh_fsi_port_info *info)
1915{
1916 if (info->flags & SH_FSI_FMT_SPDIF)
1917 fsi->spdif = 1;
Kuninori Morimotoab6340c2012-11-16 01:17:18 -08001918
1919 if (info->flags & SH_FSI_CLK_CPG)
1920 fsi->clk_cpg = 1;
Kuninori Morimoto2522acd2012-11-16 01:17:30 -08001921
1922 if (info->flags & SH_FSI_ENABLE_STREAM_MODE)
1923 fsi->enable_stream = 1;
Kuninori Morimotoc2052de2012-11-16 01:17:06 -08001924}
1925
Kuninori Morimoto943fdad2012-11-16 01:16:52 -08001926static void fsi_handler_init(struct fsi_priv *fsi,
1927 struct sh_fsi_port_info *info)
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001928{
1929 fsi->playback.handler = &fsi_pio_push_handler; /* default PIO */
1930 fsi->playback.priv = fsi;
1931 fsi->capture.handler = &fsi_pio_pop_handler; /* default PIO */
1932 fsi->capture.priv = fsi;
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001933
Kuninori Morimoto943fdad2012-11-16 01:16:52 -08001934 if (info->tx_id) {
1935 fsi->playback.slave.shdma_slave.slave_id = info->tx_id;
Guennadi Liakhovetskib8373142012-05-09 17:09:20 +02001936 fsi->playback.handler = &fsi_dma_push_handler;
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001937 }
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001938}
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001939
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001940static int fsi_probe(struct platform_device *pdev)
1941{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +09001942 struct fsi_master *master;
Kuninori Morimotocc780d32010-03-25 19:15:53 +09001943 const struct platform_device_id *id_entry;
Kuninori Morimotofec691e2012-02-03 00:58:48 -08001944 struct sh_fsi_platform_info *info = pdev->dev.platform_data;
Kuninori Morimoto943fdad2012-11-16 01:16:52 -08001945 struct sh_fsi_port_info nul_info, *pinfo;
Kuninori Morimoto40f91182012-11-16 01:16:22 -08001946 struct fsi_priv *fsi;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001947 struct resource *res;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001948 unsigned int irq;
1949 int ret;
1950
Kuninori Morimoto943fdad2012-11-16 01:16:52 -08001951 nul_info.flags = 0;
1952 nul_info.tx_id = 0;
1953 nul_info.rx_id = 0;
1954
Kuninori Morimotocc780d32010-03-25 19:15:53 +09001955 id_entry = pdev->id_entry;
1956 if (!id_entry) {
1957 dev_err(&pdev->dev, "unknown fsi device\n");
1958 return -ENODEV;
1959 }
1960
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001961 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1962 irq = platform_get_irq(pdev, 0);
Uwe Kleine-Königb6aa1792009-12-16 17:10:09 +01001963 if (!res || (int)irq <= 0) {
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001964 dev_err(&pdev->dev, "Not enough FSI platform resources.\n");
Kuninori Morimoto6ac42622012-09-10 02:14:31 -07001965 return -ENODEV;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001966 }
1967
Kuninori Morimoto6ac42622012-09-10 02:14:31 -07001968 master = devm_kzalloc(&pdev->dev, sizeof(*master), GFP_KERNEL);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001969 if (!master) {
1970 dev_err(&pdev->dev, "Could not allocate master\n");
Kuninori Morimoto6ac42622012-09-10 02:14:31 -07001971 return -ENOMEM;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001972 }
1973
Kuninori Morimoto6ac42622012-09-10 02:14:31 -07001974 master->base = devm_ioremap_nocache(&pdev->dev,
1975 res->start, resource_size(res));
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001976 if (!master->base) {
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001977 dev_err(&pdev->dev, "Unable to ioremap FSI registers.\n");
Kuninori Morimoto6ac42622012-09-10 02:14:31 -07001978 return -ENXIO;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001979 }
1980
Kuninori Morimoto3bc28072010-07-29 16:48:32 +09001981 /* master setting */
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001982 master->irq = irq;
Kuninori Morimoto73b92c12010-07-13 12:13:04 +09001983 master->core = (struct fsi_core *)id_entry->driver_data;
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +09001984 spin_lock_init(&master->lock);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001985
Kuninori Morimoto3bc28072010-07-29 16:48:32 +09001986 /* FSI A setting */
Kuninori Morimoto943fdad2012-11-16 01:16:52 -08001987 pinfo = (info) ? &info->port_a : &nul_info;
Kuninori Morimoto40f91182012-11-16 01:16:22 -08001988 fsi = &master->fsia;
1989 fsi->base = master->base;
1990 fsi->master = master;
Kuninori Morimoto943fdad2012-11-16 01:16:52 -08001991 fsi->info = pinfo;
Kuninori Morimotoc2052de2012-11-16 01:17:06 -08001992 fsi_port_info_init(fsi, pinfo);
Kuninori Morimoto943fdad2012-11-16 01:16:52 -08001993 fsi_handler_init(fsi, pinfo);
Kuninori Morimoto40f91182012-11-16 01:16:22 -08001994 ret = fsi_stream_probe(fsi, &pdev->dev);
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001995 if (ret < 0) {
1996 dev_err(&pdev->dev, "FSIA stream probe failed\n");
Kuninori Morimoto6ac42622012-09-10 02:14:31 -07001997 return ret;
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001998 }
Kuninori Morimoto3bc28072010-07-29 16:48:32 +09001999
2000 /* FSI B setting */
Kuninori Morimoto943fdad2012-11-16 01:16:52 -08002001 pinfo = (info) ? &info->port_b : &nul_info;
Kuninori Morimoto40f91182012-11-16 01:16:22 -08002002 fsi = &master->fsib;
2003 fsi->base = master->base + 0x40;
2004 fsi->master = master;
Kuninori Morimoto943fdad2012-11-16 01:16:52 -08002005 fsi->info = pinfo;
Kuninori Morimotoc2052de2012-11-16 01:17:06 -08002006 fsi_port_info_init(fsi, pinfo);
Kuninori Morimoto943fdad2012-11-16 01:16:52 -08002007 fsi_handler_init(fsi, pinfo);
Kuninori Morimoto40f91182012-11-16 01:16:22 -08002008 ret = fsi_stream_probe(fsi, &pdev->dev);
Kuninori Morimoto5e973132012-02-03 00:55:55 -08002009 if (ret < 0) {
2010 dev_err(&pdev->dev, "FSIB stream probe failed\n");
2011 goto exit_fsia;
2012 }
Kuninori Morimoto3bc28072010-07-29 16:48:32 +09002013
Kuninori Morimoto785d1c42009-11-30 20:24:48 +09002014 pm_runtime_enable(&pdev->dev);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002015 dev_set_drvdata(&pdev->dev, master);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09002016
Kuninori Morimoto1ddd8282012-10-02 23:22:57 -07002017 ret = devm_request_irq(&pdev->dev, irq, &fsi_interrupt, 0,
Kuninori Morimotocc780d32010-03-25 19:15:53 +09002018 id_entry->name, master);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09002019 if (ret) {
2020 dev_err(&pdev->dev, "irq request err\n");
Kuninori Morimoto5e973132012-02-03 00:55:55 -08002021 goto exit_fsib;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09002022 }
2023
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002024 ret = snd_soc_register_platform(&pdev->dev, &fsi_soc_platform);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09002025 if (ret < 0) {
2026 dev_err(&pdev->dev, "cannot snd soc register\n");
Kuninori Morimoto1ddd8282012-10-02 23:22:57 -07002027 goto exit_fsib;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09002028 }
2029
Kuninori Morimoto0b5ec872011-04-08 15:09:02 +09002030 ret = snd_soc_register_dais(&pdev->dev, fsi_soc_dai,
2031 ARRAY_SIZE(fsi_soc_dai));
2032 if (ret < 0) {
2033 dev_err(&pdev->dev, "cannot snd dai register\n");
2034 goto exit_snd_soc;
2035 }
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09002036
Kuninori Morimoto0b5ec872011-04-08 15:09:02 +09002037 return ret;
2038
2039exit_snd_soc:
2040 snd_soc_unregister_platform(&pdev->dev);
Kuninori Morimoto5e973132012-02-03 00:55:55 -08002041exit_fsib:
Kuninori Morimotoc35e0052012-09-10 02:13:52 -07002042 pm_runtime_disable(&pdev->dev);
Kuninori Morimoto5e973132012-02-03 00:55:55 -08002043 fsi_stream_remove(&master->fsib);
2044exit_fsia:
2045 fsi_stream_remove(&master->fsia);
Kuninori Morimoto6ac42622012-09-10 02:14:31 -07002046
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09002047 return ret;
2048}
2049
2050static int fsi_remove(struct platform_device *pdev)
2051{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +09002052 struct fsi_master *master;
2053
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002054 master = dev_get_drvdata(&pdev->dev);
Kuninori Morimoto71f6e062009-12-02 15:11:08 +09002055
Kuninori Morimoto785d1c42009-11-30 20:24:48 +09002056 pm_runtime_disable(&pdev->dev);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09002057
Kuninori Morimotod985f272011-04-08 15:09:25 +09002058 snd_soc_unregister_dais(&pdev->dev, ARRAY_SIZE(fsi_soc_dai));
2059 snd_soc_unregister_platform(&pdev->dev);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09002060
Kuninori Morimoto5e973132012-02-03 00:55:55 -08002061 fsi_stream_remove(&master->fsia);
2062 fsi_stream_remove(&master->fsib);
2063
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09002064 return 0;
2065}
2066
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09002067static void __fsi_suspend(struct fsi_priv *fsi,
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08002068 struct fsi_stream *io,
Kuninori Morimoto4f56cde2011-05-23 20:46:18 +09002069 struct device *dev)
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09002070{
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08002071 if (!fsi_stream_is_working(fsi, io))
Kuninori Morimotocda828c2011-05-23 20:46:35 +09002072 return;
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09002073
Kuninori Morimoto180346e2012-02-03 00:57:25 -08002074 fsi_stream_stop(fsi, io);
Kuninori Morimoto41bba152012-02-03 00:51:53 -08002075 fsi_hw_shutdown(fsi, dev);
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09002076}
2077
2078static void __fsi_resume(struct fsi_priv *fsi,
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08002079 struct fsi_stream *io,
Kuninori Morimoto4f56cde2011-05-23 20:46:18 +09002080 struct device *dev)
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09002081{
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08002082 if (!fsi_stream_is_working(fsi, io))
Kuninori Morimotocda828c2011-05-23 20:46:35 +09002083 return;
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09002084
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08002085 fsi_hw_startup(fsi, io, dev);
Kuninori Morimoto180346e2012-02-03 00:57:25 -08002086 fsi_stream_start(fsi, io);
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09002087}
2088
2089static int fsi_suspend(struct device *dev)
2090{
2091 struct fsi_master *master = dev_get_drvdata(dev);
Kuninori Morimotocda828c2011-05-23 20:46:35 +09002092 struct fsi_priv *fsia = &master->fsia;
2093 struct fsi_priv *fsib = &master->fsib;
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09002094
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08002095 __fsi_suspend(fsia, &fsia->playback, dev);
2096 __fsi_suspend(fsia, &fsia->capture, dev);
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09002097
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08002098 __fsi_suspend(fsib, &fsib->playback, dev);
2099 __fsi_suspend(fsib, &fsib->capture, dev);
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09002100
2101 return 0;
2102}
2103
2104static int fsi_resume(struct device *dev)
2105{
2106 struct fsi_master *master = dev_get_drvdata(dev);
Kuninori Morimotocda828c2011-05-23 20:46:35 +09002107 struct fsi_priv *fsia = &master->fsia;
2108 struct fsi_priv *fsib = &master->fsib;
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09002109
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08002110 __fsi_resume(fsia, &fsia->playback, dev);
2111 __fsi_resume(fsia, &fsia->capture, dev);
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09002112
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08002113 __fsi_resume(fsib, &fsib->playback, dev);
2114 __fsi_resume(fsib, &fsib->capture, dev);
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09002115
2116 return 0;
2117}
2118
Kuninori Morimoto785d1c42009-11-30 20:24:48 +09002119static struct dev_pm_ops fsi_pm_ops = {
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09002120 .suspend = fsi_suspend,
2121 .resume = fsi_resume,
Kuninori Morimoto785d1c42009-11-30 20:24:48 +09002122};
2123
Kuninori Morimoto73b92c12010-07-13 12:13:04 +09002124static struct fsi_core fsi1_core = {
2125 .ver = 1,
2126
2127 /* Interrupt */
Kuninori Morimotocc780d32010-03-25 19:15:53 +09002128 .int_st = INT_ST,
2129 .iemsk = IEMSK,
2130 .imsk = IMSK,
2131};
2132
Kuninori Morimoto73b92c12010-07-13 12:13:04 +09002133static struct fsi_core fsi2_core = {
2134 .ver = 2,
2135
2136 /* Interrupt */
Kuninori Morimotocc780d32010-03-25 19:15:53 +09002137 .int_st = CPU_INT_ST,
2138 .iemsk = CPU_IEMSK,
2139 .imsk = CPU_IMSK,
Kuninori Morimoto2b0e7302010-12-03 17:37:44 +09002140 .a_mclk = A_MST_CTLR,
2141 .b_mclk = B_MST_CTLR,
Kuninori Morimotocc780d32010-03-25 19:15:53 +09002142};
2143
2144static struct platform_device_id fsi_id_table[] = {
Kuninori Morimoto73b92c12010-07-13 12:13:04 +09002145 { "sh_fsi", (kernel_ulong_t)&fsi1_core },
2146 { "sh_fsi2", (kernel_ulong_t)&fsi2_core },
Guennadi Liakhovetski05c69452010-10-05 17:54:28 +02002147 {},
Kuninori Morimotocc780d32010-03-25 19:15:53 +09002148};
Dzianis Kahanovichd85a6d72010-09-17 16:42:05 +03002149MODULE_DEVICE_TABLE(platform, fsi_id_table);
Kuninori Morimotocc780d32010-03-25 19:15:53 +09002150
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09002151static struct platform_driver fsi_driver = {
2152 .driver = {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002153 .name = "fsi-pcm-audio",
Kuninori Morimoto785d1c42009-11-30 20:24:48 +09002154 .pm = &fsi_pm_ops,
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09002155 },
2156 .probe = fsi_probe,
2157 .remove = fsi_remove,
Kuninori Morimotocc780d32010-03-25 19:15:53 +09002158 .id_table = fsi_id_table,
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09002159};
2160
Axel Lincb5e8732011-11-25 10:15:07 +08002161module_platform_driver(fsi_driver);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09002162
2163MODULE_LICENSE("GPL");
2164MODULE_DESCRIPTION("SuperH onchip FSI audio driver");
2165MODULE_AUTHOR("Kuninori Morimoto <morimoto.kuninori@renesas.com>");
Guennadi Liakhovetskib3c27b52011-04-15 20:17:34 +02002166MODULE_ALIAS("platform:fsi-pcm-audio");