blob: eefb16100cd19334c7b79e63d63f074ba5d5d77d [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 Morimoto9e7b6d62013-01-10 00:34:08 -080019#include <linux/of.h>
20#include <linux/of_device.h>
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -080021#include <linux/scatterlist.h>
22#include <linux/sh_dma.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090023#include <linux/slab.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040024#include <linux/module.h>
Guennadi Liakhovetski57451e42012-10-03 14:33:50 +020025#include <linux/workqueue.h>
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090026#include <sound/soc.h>
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -080027#include <sound/pcm_params.h>
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090028#include <sound/sh_fsi.h>
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090029
Kuninori Morimotoe8c8b632010-12-03 17:37:55 +090030/* PortA/PortB register */
31#define REG_DO_FMT 0x0000
32#define REG_DOFF_CTL 0x0004
33#define REG_DOFF_ST 0x0008
34#define REG_DI_FMT 0x000C
35#define REG_DIFF_CTL 0x0010
36#define REG_DIFF_ST 0x0014
37#define REG_CKG1 0x0018
38#define REG_CKG2 0x001C
39#define REG_DIDT 0x0020
40#define REG_DODT 0x0024
41#define REG_MUTE_ST 0x0028
Kuninori Morimoto65ff03f2011-11-06 22:05:25 -080042#define REG_OUT_DMAC 0x002C
Kuninori Morimotoe8c8b632010-12-03 17:37:55 +090043#define REG_OUT_SEL 0x0030
Kuninori Morimoto65ff03f2011-11-06 22:05:25 -080044#define REG_IN_DMAC 0x0038
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090045
Kuninori Morimoto43fa95c2010-12-03 17:38:03 +090046/* master register */
47#define MST_CLK_RST 0x0210
48#define MST_SOFT_RST 0x0214
49#define MST_FIFO_SZ 0x0218
50
51/* core register (depend on FSI version) */
Kuninori Morimoto3bc28072010-07-29 16:48:32 +090052#define A_MST_CTLR 0x0180
53#define B_MST_CTLR 0x01A0
Kuninori Morimotocc780d32010-03-25 19:15:53 +090054#define CPU_INT_ST 0x01F4
55#define CPU_IEMSK 0x01F8
56#define CPU_IMSK 0x01FC
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090057#define INT_ST 0x0200
58#define IEMSK 0x0204
59#define IMSK 0x0208
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090060
61/* DO_FMT */
62/* DI_FMT */
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -080063#define CR_BWS_MASK (0x3 << 20) /* FSI2 */
Kuninori Morimotof7d711e2010-12-03 17:36:24 +090064#define CR_BWS_24 (0x0 << 20) /* FSI2 */
65#define CR_BWS_16 (0x1 << 20) /* FSI2 */
66#define CR_BWS_20 (0x2 << 20) /* FSI2 */
67
68#define CR_DTMD_PCM (0x0 << 8) /* FSI2 */
69#define CR_DTMD_SPDIF_PCM (0x1 << 8) /* FSI2 */
70#define CR_DTMD_SPDIF_STREAM (0x2 << 8) /* FSI2 */
71
Kuninori Morimotoa7ffb522010-07-13 12:13:00 +090072#define CR_MONO (0x0 << 4)
73#define CR_MONO_D (0x1 << 4)
74#define CR_PCM (0x2 << 4)
75#define CR_I2S (0x3 << 4)
76#define CR_TDM (0x4 << 4)
77#define CR_TDM_D (0x5 << 4)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090078
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -080079/* OUT_DMAC */
80/* IN_DMAC */
81#define VDMD_MASK (0x3 << 4)
82#define VDMD_FRONT (0x0 << 4) /* Package in front */
83#define VDMD_BACK (0x1 << 4) /* Package in back */
84#define VDMD_STREAM (0x2 << 4) /* Stream mode(16bit * 2) */
85
86#define DMA_ON (0x1 << 0)
87
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090088/* DOFF_CTL */
89/* DIFF_CTL */
90#define IRQ_HALF 0x00100000
91#define FIFO_CLR 0x00000001
92
93/* DOFF_ST */
94#define ERR_OVER 0x00000010
95#define ERR_UNDER 0x00000001
Kuninori Morimoto59c3b002009-12-28 14:09:16 +090096#define ST_ERR (ERR_OVER | ERR_UNDER)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090097
Kuninori Morimotoccad7b42010-07-13 12:13:14 +090098/* CKG1 */
99#define ACKMD_MASK 0x00007000
100#define BPFMD_MASK 0x00000700
Kuninori Morimoto4d805f72011-01-20 11:46:02 +0900101#define DIMD (1 << 4)
102#define DOMD (1 << 0)
Kuninori Morimotoccad7b42010-07-13 12:13:14 +0900103
Kuninori Morimoto3bc28072010-07-29 16:48:32 +0900104/* A/B MST_CTLR */
105#define BP (1 << 4) /* Fix the signal of Biphase output */
106#define SE (1 << 0) /* Fix the master clock */
107
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900108/* CLK_RST */
Kuninori Morimoto1f5e2a32011-04-21 10:33:52 +0900109#define CRB (1 << 4)
110#define CRA (1 << 0)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900111
Kuninori Morimotocf6edd02010-10-12 11:40:53 +0900112/* IO SHIFT / MACRO */
113#define BI_SHIFT 12
114#define BO_SHIFT 8
115#define AI_SHIFT 4
116#define AO_SHIFT 0
117#define AB_IO(param, shift) (param << shift)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900118
Kuninori Morimotofeb58cf2010-03-24 15:27:24 +0900119/* SOFT_RST */
120#define PBSR (1 << 12) /* Port B Software Reset */
121#define PASR (1 << 8) /* Port A Software Reset */
122#define IR (1 << 4) /* Interrupt Reset */
123#define FSISR (1 << 0) /* Software Reset */
124
Kuninori Morimotof7d711e2010-12-03 17:36:24 +0900125/* OUT_SEL (FSI2) */
126#define DMMD (1 << 4) /* SPDIF output timing 0: Biphase only */
127 /* 1: Biphase and serial */
128
Kuninori Morimoto4a942b42010-03-25 19:15:51 +0900129/* FIFO_SZ */
Kuninori Morimotocf6edd02010-10-12 11:40:53 +0900130#define FIFO_SZ_MASK 0x7
Kuninori Morimoto4a942b42010-03-25 19:15:51 +0900131
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900132#define FSI_RATES SNDRV_PCM_RATE_8000_96000
133
134#define FSI_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE)
135
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +0900136/*
Kuninori Morimoto766812e2012-05-17 17:36:47 -0700137 * bus options
138 *
139 * 0x000000BA
140 *
141 * A : sample widtht 16bit setting
142 * B : sample widtht 24bit setting
143 */
144
145#define SHIFT_16DATA 0
146#define SHIFT_24DATA 4
147
148#define PACKAGE_24BITBUS_BACK 0
149#define PACKAGE_24BITBUS_FRONT 1
150#define PACKAGE_16BITBUS_STREAM 2
151
152#define BUSOP_SET(s, a) ((a) << SHIFT_ ## s ## DATA)
153#define BUSOP_GET(s, a) (((a) >> SHIFT_ ## s ## DATA) & 0xF)
154
155/*
Kuninori Morimoto5bfb9ad2010-09-17 13:48:45 +0900156 * FSI driver use below type name for variable
157 *
Kuninori Morimoto5bfb9ad2010-09-17 13:48:45 +0900158 * xxx_num : number of data
Kuninori Morimoto2e651ba2011-05-23 20:46:03 +0900159 * xxx_pos : position of data
160 * xxx_capa : capacity of data
161 */
162
163/*
164 * period/frame/sample image
165 *
166 * ex) PCM (2ch)
167 *
168 * period pos period pos
169 * [n] [n + 1]
170 * |<-------------------- period--------------------->|
171 * ==|============================================ ... =|==
172 * | |
173 * ||<----- frame ----->|<------ frame ----->| ... |
174 * |+--------------------+--------------------+- ... |
175 * ||[ sample ][ sample ]|[ sample ][ sample ]| ... |
176 * |+--------------------+--------------------+- ... |
177 * ==|============================================ ... =|==
178 */
179
180/*
181 * FSI FIFO image
182 *
183 * | |
184 * | |
185 * | [ sample ] |
186 * | [ sample ] |
187 * | [ sample ] |
188 * | [ sample ] |
189 * --> go to codecs
Kuninori Morimoto5bfb9ad2010-09-17 13:48:45 +0900190 */
191
192/*
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -0800193 * FSI clock
194 *
195 * FSIxCLK [CPG] (ick) -------> |
196 * |-> FSI_DIV (div)-> FSI2
197 * FSIxCK [external] (xck) ---> |
198 */
199
200/*
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +0900201 * struct
202 */
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900203
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800204struct fsi_stream_handler;
Kuninori Morimoto93193c22010-10-12 19:19:28 +0900205struct fsi_stream {
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900206
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800207 /*
208 * these are initialized by fsi_stream_init()
209 */
210 struct snd_pcm_substream *substream;
Kuninori Morimoto2e651ba2011-05-23 20:46:03 +0900211 int fifo_sample_capa; /* sample capacity of FSI FIFO */
212 int buff_sample_capa; /* sample capacity of ALSA buffer */
213 int buff_sample_pos; /* sample position of ALSA buffer */
214 int period_samples; /* sample number / 1 period */
215 int period_pos; /* current period position */
Kuninori Morimotoc1e6f102012-02-03 00:50:09 -0800216 int sample_width; /* sample width */
Kuninori Morimoto1ec9bc32010-12-17 12:55:22 +0900217 int uerr_num;
218 int oerr_num;
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800219
220 /*
Kuninori Morimoto766812e2012-05-17 17:36:47 -0700221 * bus options
222 */
223 u32 bus_option;
224
225 /*
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800226 * thse are initialized by fsi_handler_init()
227 */
228 struct fsi_stream_handler *handler;
229 struct fsi_priv *priv;
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -0800230
231 /*
232 * these are for DMAEngine
233 */
234 struct dma_chan *chan;
Kuninori Morimotoa0732782013-12-10 20:46:59 -0800235 int dma_id;
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;
254
255 struct fsi_stream playback;
256 struct fsi_stream capture;
Kuninori Morimoto3bc28072010-07-29 16:48:32 +0900257
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -0800258 struct fsi_clk clock;
259
Kuninori Morimoto9c59dd32012-05-17 17:34:53 -0700260 u32 fmt;
Kuninori Morimoto9478e0b2011-05-23 20:46:07 +0900261
Kuninori Morimoto6a9ebad2011-04-21 10:33:36 +0900262 int chan_num:16;
Lars-Peter Clausen9f98cd62014-06-19 09:40:31 +0200263 unsigned int clk_master:1;
264 unsigned int clk_cpg:1;
265 unsigned int spdif:1;
266 unsigned int enable_stream:1;
267 unsigned int bit_clk_inv:1;
268 unsigned int lr_clk_inv:1;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900269};
270
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800271struct fsi_stream_handler {
Kuninori Morimoto83344022012-02-03 00:59:02 -0800272 int (*init)(struct fsi_priv *fsi, struct fsi_stream *io);
273 int (*quit)(struct fsi_priv *fsi, struct fsi_stream *io);
Kuninori Morimotob1226dc2012-05-24 23:56:19 -0700274 int (*probe)(struct fsi_priv *fsi, struct fsi_stream *io, struct device *dev);
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800275 int (*transfer)(struct fsi_priv *fsi, struct fsi_stream *io);
276 int (*remove)(struct fsi_priv *fsi, struct fsi_stream *io);
Kuninori Morimotoc375b2d2013-05-28 00:55:12 -0700277 int (*start_stop)(struct fsi_priv *fsi, struct fsi_stream *io,
Kuninori Morimoto180346e2012-02-03 00:57:25 -0800278 int enable);
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800279};
280#define fsi_stream_handler_call(io, func, args...) \
281 (!(io) ? -ENODEV : \
282 !((io)->handler->func) ? 0 : \
283 (io)->handler->func(args))
284
Kuninori Morimoto73b92c12010-07-13 12:13:04 +0900285struct fsi_core {
286 int ver;
287
Kuninori Morimotocc780d32010-03-25 19:15:53 +0900288 u32 int_st;
289 u32 iemsk;
290 u32 imsk;
Kuninori Morimoto2b0e7302010-12-03 17:37:44 +0900291 u32 a_mclk;
292 u32 b_mclk;
Kuninori Morimotocc780d32010-03-25 19:15:53 +0900293};
294
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900295struct fsi_master {
296 void __iomem *base;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900297 struct fsi_priv fsia;
298 struct fsi_priv fsib;
Kuninori Morimoto9e7b6d62013-01-10 00:34:08 -0800299 const struct fsi_core *core;
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900300 spinlock_t lock;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900301};
302
Kuninori Morimoto7b1b3332012-02-03 00:55:26 -0800303static int fsi_stream_is_play(struct fsi_priv *fsi, struct fsi_stream *io);
304
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +0900305/*
306 * basic read write function
307 */
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900308
Arnd Bergmannca7acee2011-10-02 22:28:02 +0200309static void __fsi_reg_write(u32 __iomem *reg, u32 data)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900310{
311 /* valid data area is 24bit */
312 data &= 0x00ffffff;
313
Guennadi Liakhovetski0f69d972010-02-03 17:37:23 +0100314 __raw_writel(data, reg);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900315}
316
Arnd Bergmannca7acee2011-10-02 22:28:02 +0200317static u32 __fsi_reg_read(u32 __iomem *reg)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900318{
Guennadi Liakhovetski0f69d972010-02-03 17:37:23 +0100319 return __raw_readl(reg);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900320}
321
Arnd Bergmannca7acee2011-10-02 22:28:02 +0200322static void __fsi_reg_mask_set(u32 __iomem *reg, u32 mask, u32 data)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900323{
324 u32 val = __fsi_reg_read(reg);
325
326 val &= ~mask;
327 val |= data & mask;
328
Guennadi Liakhovetski0f69d972010-02-03 17:37:23 +0100329 __fsi_reg_write(reg, val);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900330}
331
Kuninori Morimotoe8c8b632010-12-03 17:37:55 +0900332#define fsi_reg_write(p, r, d)\
Kuninori Morimoto8918b842011-10-31 22:11:53 -0700333 __fsi_reg_write((p->base + REG_##r), d)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900334
Kuninori Morimotoe8c8b632010-12-03 17:37:55 +0900335#define fsi_reg_read(p, r)\
Kuninori Morimoto8918b842011-10-31 22:11:53 -0700336 __fsi_reg_read((p->base + REG_##r))
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900337
Kuninori Morimotoe8c8b632010-12-03 17:37:55 +0900338#define fsi_reg_mask_set(p, r, m, d)\
Kuninori Morimoto8918b842011-10-31 22:11:53 -0700339 __fsi_reg_mask_set((p->base + REG_##r), m, d)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900340
Kuninori Morimoto43fa95c2010-12-03 17:38:03 +0900341#define fsi_master_read(p, r) _fsi_master_read(p, MST_##r)
342#define fsi_core_read(p, r) _fsi_master_read(p, p->core->r)
343static u32 _fsi_master_read(struct fsi_master *master, u32 reg)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900344{
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900345 u32 ret;
346 unsigned long flags;
347
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900348 spin_lock_irqsave(&master->lock, flags);
Arnd Bergmannca7acee2011-10-02 22:28:02 +0200349 ret = __fsi_reg_read(master->base + reg);
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900350 spin_unlock_irqrestore(&master->lock, flags);
351
352 return ret;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900353}
354
Kuninori Morimoto43fa95c2010-12-03 17:38:03 +0900355#define fsi_master_mask_set(p, r, m, d) _fsi_master_mask_set(p, MST_##r, m, d)
356#define fsi_core_mask_set(p, r, m, d) _fsi_master_mask_set(p, p->core->r, m, d)
357static void _fsi_master_mask_set(struct fsi_master *master,
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900358 u32 reg, u32 mask, u32 data)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900359{
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900360 unsigned long flags;
361
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900362 spin_lock_irqsave(&master->lock, flags);
Arnd Bergmannca7acee2011-10-02 22:28:02 +0200363 __fsi_reg_mask_set(master->base + reg, mask, data);
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900364 spin_unlock_irqrestore(&master->lock, flags);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900365}
366
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +0900367/*
368 * basic function
369 */
Kuninori Morimoto284c6f62012-05-17 17:34:16 -0700370static int fsi_version(struct fsi_master *master)
371{
372 return master->core->ver;
373}
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900374
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900375static struct fsi_master *fsi_get_master(struct fsi_priv *fsi)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900376{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900377 return fsi->master;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900378}
379
Kuninori Morimoto6a9ebad2011-04-21 10:33:36 +0900380static int fsi_is_clk_master(struct fsi_priv *fsi)
381{
382 return fsi->clk_master;
383}
384
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900385static int fsi_is_port_a(struct fsi_priv *fsi)
386{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900387 return fsi->master->base == fsi->base;
388}
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900389
Kuninori Morimoto9478e0b2011-05-23 20:46:07 +0900390static int fsi_is_spdif(struct fsi_priv *fsi)
391{
392 return fsi->spdif;
393}
394
Kuninori Morimoto2522acd2012-11-16 01:17:30 -0800395static int fsi_is_enable_stream(struct fsi_priv *fsi)
396{
397 return fsi->enable_stream;
398}
399
Kuninori Morimotoa449e462012-02-03 00:54:02 -0800400static int fsi_is_play(struct snd_pcm_substream *substream)
401{
402 return substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
403}
404
Kuninori Morimoto142e8172009-12-28 14:09:11 +0900405static struct snd_soc_dai *fsi_get_dai(struct snd_pcm_substream *substream)
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900406{
407 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Kuninori Morimoto142e8172009-12-28 14:09:11 +0900408
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000409 return rtd->cpu_dai;
Kuninori Morimoto142e8172009-12-28 14:09:11 +0900410}
411
Kuninori Morimoto0d032c12011-01-20 11:45:51 +0900412static struct fsi_priv *fsi_get_priv_frm_dai(struct snd_soc_dai *dai)
Kuninori Morimoto142e8172009-12-28 14:09:11 +0900413{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000414 struct fsi_master *master = snd_soc_dai_get_drvdata(dai);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900415
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000416 if (dai->id == 0)
417 return &master->fsia;
418 else
419 return &master->fsib;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900420}
421
Kuninori Morimoto0d032c12011-01-20 11:45:51 +0900422static struct fsi_priv *fsi_get_priv(struct snd_pcm_substream *substream)
423{
424 return fsi_get_priv_frm_dai(fsi_get_dai(substream));
425}
426
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800427static u32 fsi_get_port_shift(struct fsi_priv *fsi, struct fsi_stream *io)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900428{
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800429 int is_play = fsi_stream_is_play(fsi, io);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900430 int is_porta = fsi_is_port_a(fsi);
Kuninori Morimotocf6edd02010-10-12 11:40:53 +0900431 u32 shift;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900432
433 if (is_porta)
Kuninori Morimotocf6edd02010-10-12 11:40:53 +0900434 shift = is_play ? AO_SHIFT : AI_SHIFT;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900435 else
Kuninori Morimotocf6edd02010-10-12 11:40:53 +0900436 shift = is_play ? BO_SHIFT : BI_SHIFT;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900437
Kuninori Morimotocf6edd02010-10-12 11:40:53 +0900438 return shift;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900439}
440
Kuninori Morimoto2e651ba2011-05-23 20:46:03 +0900441static int fsi_frame2sample(struct fsi_priv *fsi, int frames)
442{
443 return frames * fsi->chan_num;
444}
445
446static int fsi_sample2frame(struct fsi_priv *fsi, int samples)
447{
448 return samples / fsi->chan_num;
449}
450
Kuninori Morimoto7b1b3332012-02-03 00:55:26 -0800451static int fsi_get_current_fifo_samples(struct fsi_priv *fsi,
452 struct fsi_stream *io)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900453{
Kuninori Morimoto7b1b3332012-02-03 00:55:26 -0800454 int is_play = fsi_stream_is_play(fsi, io);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900455 u32 status;
Kuninori Morimoto2e651ba2011-05-23 20:46:03 +0900456 int frames;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900457
Kuninori Morimotoe8c8b632010-12-03 17:37:55 +0900458 status = is_play ?
459 fsi_reg_read(fsi, DOFF_ST) :
460 fsi_reg_read(fsi, DIFF_ST);
461
Kuninori Morimoto2e651ba2011-05-23 20:46:03 +0900462 frames = 0x1ff & (status >> 8);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900463
Kuninori Morimoto2e651ba2011-05-23 20:46:03 +0900464 return fsi_frame2sample(fsi, frames);
Kuninori Morimotocca1b232010-10-12 11:39:25 +0900465}
466
Kuninori Morimoto1ec9bc32010-12-17 12:55:22 +0900467static void fsi_count_fifo_err(struct fsi_priv *fsi)
468{
469 u32 ostatus = fsi_reg_read(fsi, DOFF_ST);
470 u32 istatus = fsi_reg_read(fsi, DIFF_ST);
471
472 if (ostatus & ERR_OVER)
473 fsi->playback.oerr_num++;
474
475 if (ostatus & ERR_UNDER)
476 fsi->playback.uerr_num++;
477
478 if (istatus & ERR_OVER)
479 fsi->capture.oerr_num++;
480
481 if (istatus & ERR_UNDER)
482 fsi->capture.uerr_num++;
483
484 fsi_reg_write(fsi, DOFF_ST, 0);
485 fsi_reg_write(fsi, DIFF_ST, 0);
486}
487
Kuninori Morimotob9fde182010-09-17 13:48:32 +0900488/*
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800489 * fsi_stream_xx() function
490 */
Kuninori Morimotoa449e462012-02-03 00:54:02 -0800491static inline int fsi_stream_is_play(struct fsi_priv *fsi,
492 struct fsi_stream *io)
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800493{
Kuninori Morimotoa449e462012-02-03 00:54:02 -0800494 return &fsi->playback == io;
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800495}
496
497static inline struct fsi_stream *fsi_stream_get(struct fsi_priv *fsi,
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800498 struct snd_pcm_substream *substream)
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800499{
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800500 return fsi_is_play(substream) ? &fsi->playback : &fsi->capture;
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800501}
502
503static int fsi_stream_is_working(struct fsi_priv *fsi,
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800504 struct fsi_stream *io)
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800505{
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800506 struct fsi_master *master = fsi_get_master(fsi);
507 unsigned long flags;
508 int ret;
509
510 spin_lock_irqsave(&master->lock, flags);
Kuninori Morimoto97df8182012-02-03 00:57:40 -0800511 ret = !!(io->substream && io->substream->runtime);
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800512 spin_unlock_irqrestore(&master->lock, flags);
513
514 return ret;
515}
516
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800517static struct fsi_priv *fsi_stream_to_priv(struct fsi_stream *io)
518{
519 return io->priv;
520}
521
Kuninori Morimoto8c415292012-02-03 00:52:07 -0800522static void fsi_stream_init(struct fsi_priv *fsi,
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800523 struct fsi_stream *io,
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800524 struct snd_pcm_substream *substream)
525{
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800526 struct snd_pcm_runtime *runtime = substream->runtime;
527 struct fsi_master *master = fsi_get_master(fsi);
528 unsigned long flags;
529
530 spin_lock_irqsave(&master->lock, flags);
531 io->substream = substream;
532 io->buff_sample_capa = fsi_frame2sample(fsi, runtime->buffer_size);
533 io->buff_sample_pos = 0;
534 io->period_samples = fsi_frame2sample(fsi, runtime->period_size);
535 io->period_pos = 0;
536 io->sample_width = samples_to_bytes(runtime, 1);
Kuninori Morimoto766812e2012-05-17 17:36:47 -0700537 io->bus_option = 0;
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800538 io->oerr_num = -1; /* ignore 1st err */
539 io->uerr_num = -1; /* ignore 1st err */
Kuninori Morimoto83344022012-02-03 00:59:02 -0800540 fsi_stream_handler_call(io, init, fsi, io);
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800541 spin_unlock_irqrestore(&master->lock, flags);
542}
543
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800544static void fsi_stream_quit(struct fsi_priv *fsi, struct fsi_stream *io)
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800545{
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800546 struct snd_soc_dai *dai = fsi_get_dai(io->substream);
547 struct fsi_master *master = fsi_get_master(fsi);
548 unsigned long flags;
549
550 spin_lock_irqsave(&master->lock, flags);
551
552 if (io->oerr_num > 0)
553 dev_err(dai->dev, "over_run = %d\n", io->oerr_num);
554
555 if (io->uerr_num > 0)
556 dev_err(dai->dev, "under_run = %d\n", io->uerr_num);
557
Kuninori Morimoto83344022012-02-03 00:59:02 -0800558 fsi_stream_handler_call(io, quit, fsi, io);
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800559 io->substream = NULL;
560 io->buff_sample_capa = 0;
561 io->buff_sample_pos = 0;
562 io->period_samples = 0;
563 io->period_pos = 0;
564 io->sample_width = 0;
Kuninori Morimoto766812e2012-05-17 17:36:47 -0700565 io->bus_option = 0;
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800566 io->oerr_num = 0;
567 io->uerr_num = 0;
568 spin_unlock_irqrestore(&master->lock, flags);
569}
570
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800571static int fsi_stream_transfer(struct fsi_stream *io)
572{
573 struct fsi_priv *fsi = fsi_stream_to_priv(io);
574 if (!fsi)
575 return -EIO;
576
577 return fsi_stream_handler_call(io, transfer, fsi, io);
578}
579
Kuninori Morimoto180346e2012-02-03 00:57:25 -0800580#define fsi_stream_start(fsi, io)\
581 fsi_stream_handler_call(io, start_stop, fsi, io, 1)
582
583#define fsi_stream_stop(fsi, io)\
584 fsi_stream_handler_call(io, start_stop, fsi, io, 0)
585
Kuninori Morimotob1226dc2012-05-24 23:56:19 -0700586static int fsi_stream_probe(struct fsi_priv *fsi, struct device *dev)
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800587{
588 struct fsi_stream *io;
589 int ret1, ret2;
590
591 io = &fsi->playback;
Kuninori Morimotob1226dc2012-05-24 23:56:19 -0700592 ret1 = fsi_stream_handler_call(io, probe, fsi, io, dev);
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800593
594 io = &fsi->capture;
Kuninori Morimotob1226dc2012-05-24 23:56:19 -0700595 ret2 = fsi_stream_handler_call(io, probe, fsi, io, dev);
Kuninori Morimoto5e973132012-02-03 00:55:55 -0800596
597 if (ret1 < 0)
598 return ret1;
599 if (ret2 < 0)
600 return ret2;
601
602 return 0;
603}
604
605static int fsi_stream_remove(struct fsi_priv *fsi)
606{
607 struct fsi_stream *io;
608 int ret1, ret2;
609
610 io = &fsi->playback;
611 ret1 = fsi_stream_handler_call(io, remove, fsi, io);
612
613 io = &fsi->capture;
614 ret2 = fsi_stream_handler_call(io, remove, fsi, io);
615
616 if (ret1 < 0)
617 return ret1;
618 if (ret2 < 0)
619 return ret2;
620
621 return 0;
622}
623
Kuninori Morimoto4e62d842012-02-03 00:50:35 -0800624/*
Kuninori Morimoto766812e2012-05-17 17:36:47 -0700625 * format/bus/dma setting
626 */
627static void fsi_format_bus_setup(struct fsi_priv *fsi, struct fsi_stream *io,
628 u32 bus, struct device *dev)
629{
630 struct fsi_master *master = fsi_get_master(fsi);
631 int is_play = fsi_stream_is_play(fsi, io);
632 u32 fmt = fsi->fmt;
633
634 if (fsi_version(master) >= 2) {
635 u32 dma = 0;
636
637 /*
638 * FSI2 needs DMA/Bus setting
639 */
640 switch (bus) {
641 case PACKAGE_24BITBUS_FRONT:
642 fmt |= CR_BWS_24;
643 dma |= VDMD_FRONT;
644 dev_dbg(dev, "24bit bus / package in front\n");
645 break;
646 case PACKAGE_16BITBUS_STREAM:
647 fmt |= CR_BWS_16;
648 dma |= VDMD_STREAM;
649 dev_dbg(dev, "16bit bus / stream mode\n");
650 break;
651 case PACKAGE_24BITBUS_BACK:
652 default:
653 fmt |= CR_BWS_24;
654 dma |= VDMD_BACK;
655 dev_dbg(dev, "24bit bus / package in back\n");
656 break;
657 }
658
659 if (is_play)
660 fsi_reg_write(fsi, OUT_DMAC, dma);
661 else
662 fsi_reg_write(fsi, IN_DMAC, dma);
663 }
664
665 if (is_play)
666 fsi_reg_write(fsi, DO_FMT, fmt);
667 else
668 fsi_reg_write(fsi, DI_FMT, fmt);
669}
670
671/*
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +0900672 * irq function
673 */
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900674
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800675static void fsi_irq_enable(struct fsi_priv *fsi, struct fsi_stream *io)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900676{
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800677 u32 data = AB_IO(1, fsi_get_port_shift(fsi, io));
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900678 struct fsi_master *master = fsi_get_master(fsi);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900679
Kuninori Morimoto43fa95c2010-12-03 17:38:03 +0900680 fsi_core_mask_set(master, imsk, data, data);
681 fsi_core_mask_set(master, iemsk, data, data);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900682}
683
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800684static void fsi_irq_disable(struct fsi_priv *fsi, struct fsi_stream *io)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900685{
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800686 u32 data = AB_IO(1, fsi_get_port_shift(fsi, io));
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900687 struct fsi_master *master = fsi_get_master(fsi);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900688
Kuninori Morimoto43fa95c2010-12-03 17:38:03 +0900689 fsi_core_mask_set(master, imsk, data, 0);
690 fsi_core_mask_set(master, iemsk, data, 0);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900691}
692
Kuninori Morimoto10ea76c2010-03-23 11:47:54 +0900693static u32 fsi_irq_get_status(struct fsi_master *master)
694{
Kuninori Morimoto43fa95c2010-12-03 17:38:03 +0900695 return fsi_core_read(master, int_st);
Kuninori Morimoto10ea76c2010-03-23 11:47:54 +0900696}
697
Kuninori Morimoto10ea76c2010-03-23 11:47:54 +0900698static void fsi_irq_clear_status(struct fsi_priv *fsi)
699{
700 u32 data = 0;
701 struct fsi_master *master = fsi_get_master(fsi);
702
Kuninori Morimoto938e2a82012-02-03 00:56:57 -0800703 data |= AB_IO(1, fsi_get_port_shift(fsi, &fsi->playback));
704 data |= AB_IO(1, fsi_get_port_shift(fsi, &fsi->capture));
Kuninori Morimoto10ea76c2010-03-23 11:47:54 +0900705
706 /* clear interrupt factor */
Kuninori Morimoto43fa95c2010-12-03 17:38:03 +0900707 fsi_core_mask_set(master, int_st, data, 0);
Kuninori Morimoto10ea76c2010-03-23 11:47:54 +0900708}
709
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +0900710/*
711 * SPDIF master clock function
712 *
713 * These functions are used later FSI2
714 */
Kuninori Morimoto3bc28072010-07-29 16:48:32 +0900715static void fsi_spdif_clk_ctrl(struct fsi_priv *fsi, int enable)
716{
717 struct fsi_master *master = fsi_get_master(fsi);
Kuninori Morimoto2b0e7302010-12-03 17:37:44 +0900718 u32 mask, val;
Kuninori Morimoto3bc28072010-07-29 16:48:32 +0900719
Kuninori Morimoto2b0e7302010-12-03 17:37:44 +0900720 mask = BP | SE;
721 val = enable ? mask : 0;
722
723 fsi_is_port_a(fsi) ?
Kuninori Morimoto43fa95c2010-12-03 17:38:03 +0900724 fsi_core_mask_set(master, a_mclk, mask, val) :
725 fsi_core_mask_set(master, b_mclk, mask, val);
Kuninori Morimoto3bc28072010-07-29 16:48:32 +0900726}
727
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +0900728/*
Kuninori Morimoto1f5e2a32011-04-21 10:33:52 +0900729 * clock function
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +0900730 */
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -0800731static int fsi_clk_init(struct device *dev,
732 struct fsi_priv *fsi,
733 int xck,
734 int ick,
735 int div,
736 int (*set_rate)(struct device *dev,
Kuninori Morimoto6cbdbff2012-12-16 22:12:21 -0800737 struct fsi_priv *fsi))
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -0800738{
739 struct fsi_clk *clock = &fsi->clock;
740 int is_porta = fsi_is_port_a(fsi);
741
742 clock->xck = NULL;
743 clock->ick = NULL;
744 clock->div = NULL;
745 clock->rate = 0;
746 clock->count = 0;
747 clock->set_rate = set_rate;
748
749 clock->own = devm_clk_get(dev, NULL);
750 if (IS_ERR(clock->own))
751 return -EINVAL;
752
753 /* external clock */
754 if (xck) {
755 clock->xck = devm_clk_get(dev, is_porta ? "xcka" : "xckb");
756 if (IS_ERR(clock->xck)) {
757 dev_err(dev, "can't get xck clock\n");
758 return -EINVAL;
759 }
760 if (clock->xck == clock->own) {
761 dev_err(dev, "cpu doesn't support xck clock\n");
762 return -EINVAL;
763 }
764 }
765
766 /* FSIACLK/FSIBCLK */
767 if (ick) {
768 clock->ick = devm_clk_get(dev, is_porta ? "icka" : "ickb");
769 if (IS_ERR(clock->ick)) {
770 dev_err(dev, "can't get ick clock\n");
771 return -EINVAL;
772 }
773 if (clock->ick == clock->own) {
774 dev_err(dev, "cpu doesn't support ick clock\n");
775 return -EINVAL;
776 }
777 }
778
779 /* FSI-DIV */
780 if (div) {
781 clock->div = devm_clk_get(dev, is_porta ? "diva" : "divb");
782 if (IS_ERR(clock->div)) {
783 dev_err(dev, "can't get div clock\n");
784 return -EINVAL;
785 }
786 if (clock->div == clock->own) {
787 dev_err(dev, "cpu doens't support div clock\n");
788 return -EINVAL;
789 }
790 }
791
792 return 0;
793}
794
795#define fsi_clk_invalid(fsi) fsi_clk_valid(fsi, 0)
796static void fsi_clk_valid(struct fsi_priv *fsi, unsigned long rate)
797{
798 fsi->clock.rate = rate;
799}
800
801static int fsi_clk_is_valid(struct fsi_priv *fsi)
802{
803 return fsi->clock.set_rate &&
804 fsi->clock.rate;
805}
806
807static int fsi_clk_enable(struct device *dev,
Kuninori Morimoto6cbdbff2012-12-16 22:12:21 -0800808 struct fsi_priv *fsi)
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -0800809{
810 struct fsi_clk *clock = &fsi->clock;
811 int ret = -EINVAL;
812
813 if (!fsi_clk_is_valid(fsi))
814 return ret;
815
816 if (0 == clock->count) {
Kuninori Morimoto6cbdbff2012-12-16 22:12:21 -0800817 ret = clock->set_rate(dev, fsi);
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -0800818 if (ret < 0) {
819 fsi_clk_invalid(fsi);
820 return ret;
821 }
822
823 if (clock->xck)
824 clk_enable(clock->xck);
825 if (clock->ick)
826 clk_enable(clock->ick);
827 if (clock->div)
828 clk_enable(clock->div);
829
830 clock->count++;
831 }
832
833 return ret;
834}
835
836static int fsi_clk_disable(struct device *dev,
837 struct fsi_priv *fsi)
838{
839 struct fsi_clk *clock = &fsi->clock;
840
841 if (!fsi_clk_is_valid(fsi))
842 return -EINVAL;
843
844 if (1 == clock->count--) {
Markus Elfringe98c89e2014-12-02 14:34:30 +0100845 clk_disable(clock->xck);
846 clk_disable(clock->ick);
847 clk_disable(clock->div);
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -0800848 }
849
850 return 0;
851}
852
853static int fsi_clk_set_ackbpf(struct device *dev,
854 struct fsi_priv *fsi,
855 int ackmd, int bpfmd)
856{
857 u32 data = 0;
858
859 /* check ackmd/bpfmd relationship */
860 if (bpfmd > ackmd) {
861 dev_err(dev, "unsupported rate (%d/%d)\n", ackmd, bpfmd);
862 return -EINVAL;
863 }
864
865 /* ACKMD */
866 switch (ackmd) {
867 case 512:
868 data |= (0x0 << 12);
869 break;
870 case 256:
871 data |= (0x1 << 12);
872 break;
873 case 128:
874 data |= (0x2 << 12);
875 break;
876 case 64:
877 data |= (0x3 << 12);
878 break;
879 case 32:
880 data |= (0x4 << 12);
881 break;
882 default:
883 dev_err(dev, "unsupported ackmd (%d)\n", ackmd);
884 return -EINVAL;
885 }
886
887 /* BPFMD */
888 switch (bpfmd) {
889 case 32:
890 data |= (0x0 << 8);
891 break;
892 case 64:
893 data |= (0x1 << 8);
894 break;
895 case 128:
896 data |= (0x2 << 8);
897 break;
898 case 256:
899 data |= (0x3 << 8);
900 break;
901 case 512:
902 data |= (0x4 << 8);
903 break;
904 case 16:
905 data |= (0x7 << 8);
906 break;
907 default:
908 dev_err(dev, "unsupported bpfmd (%d)\n", bpfmd);
909 return -EINVAL;
910 }
911
912 dev_dbg(dev, "ACKMD/BPFMD = %d/%d\n", ackmd, bpfmd);
913
914 fsi_reg_mask_set(fsi, CKG1, (ACKMD_MASK | BPFMD_MASK) , data);
915 udelay(10);
916
917 return 0;
918}
919
920static int fsi_clk_set_rate_external(struct device *dev,
Kuninori Morimoto6cbdbff2012-12-16 22:12:21 -0800921 struct fsi_priv *fsi)
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -0800922{
923 struct clk *xck = fsi->clock.xck;
924 struct clk *ick = fsi->clock.ick;
Kuninori Morimoto6cbdbff2012-12-16 22:12:21 -0800925 unsigned long rate = fsi->clock.rate;
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -0800926 unsigned long xrate;
927 int ackmd, bpfmd;
928 int ret = 0;
929
930 /* check clock rate */
931 xrate = clk_get_rate(xck);
932 if (xrate % rate) {
933 dev_err(dev, "unsupported clock rate\n");
934 return -EINVAL;
935 }
936
937 clk_set_parent(ick, xck);
938 clk_set_rate(ick, xrate);
939
940 bpfmd = fsi->chan_num * 32;
941 ackmd = xrate / rate;
942
943 dev_dbg(dev, "external/rate = %ld/%ld\n", xrate, rate);
944
945 ret = fsi_clk_set_ackbpf(dev, fsi, ackmd, bpfmd);
946 if (ret < 0)
947 dev_err(dev, "%s failed", __func__);
948
949 return ret;
950}
951
952static int fsi_clk_set_rate_cpg(struct device *dev,
Kuninori Morimoto6cbdbff2012-12-16 22:12:21 -0800953 struct fsi_priv *fsi)
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -0800954{
955 struct clk *ick = fsi->clock.ick;
956 struct clk *div = fsi->clock.div;
Kuninori Morimoto6cbdbff2012-12-16 22:12:21 -0800957 unsigned long rate = fsi->clock.rate;
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -0800958 unsigned long target = 0; /* 12288000 or 11289600 */
959 unsigned long actual, cout;
960 unsigned long diff, min;
961 unsigned long best_cout, best_act;
962 int adj;
963 int ackmd, bpfmd;
964 int ret = -EINVAL;
965
966 if (!(12288000 % rate))
967 target = 12288000;
968 if (!(11289600 % rate))
969 target = 11289600;
970 if (!target) {
971 dev_err(dev, "unsupported rate\n");
972 return ret;
973 }
974
975 bpfmd = fsi->chan_num * 32;
976 ackmd = target / rate;
977 ret = fsi_clk_set_ackbpf(dev, fsi, ackmd, bpfmd);
978 if (ret < 0) {
979 dev_err(dev, "%s failed", __func__);
980 return ret;
981 }
982
983 /*
984 * The clock flow is
985 *
986 * [CPG] = cout => [FSI_DIV] = audio => [FSI] => [codec]
987 *
988 * But, it needs to find best match of CPG and FSI_DIV
989 * combination, since it is difficult to generate correct
990 * frequency of audio clock from ick clock only.
991 * Because ick is created from its parent clock.
992 *
993 * target = rate x [512/256/128/64]fs
994 * cout = round(target x adjustment)
995 * actual = cout / adjustment (by FSI-DIV) ~= target
996 * audio = actual
997 */
998 min = ~0;
999 best_cout = 0;
1000 best_act = 0;
1001 for (adj = 1; adj < 0xffff; adj++) {
1002
1003 cout = target * adj;
1004 if (cout > 100000000) /* max clock = 100MHz */
1005 break;
1006
1007 /* cout/actual audio clock */
1008 cout = clk_round_rate(ick, cout);
1009 actual = cout / adj;
1010
1011 /* find best frequency */
1012 diff = abs(actual - target);
1013 if (diff < min) {
1014 min = diff;
1015 best_cout = cout;
1016 best_act = actual;
1017 }
1018 }
1019
1020 ret = clk_set_rate(ick, best_cout);
1021 if (ret < 0) {
1022 dev_err(dev, "ick clock failed\n");
1023 return -EIO;
1024 }
1025
1026 ret = clk_set_rate(div, clk_round_rate(div, best_act));
1027 if (ret < 0) {
1028 dev_err(dev, "div clock failed\n");
1029 return -EIO;
1030 }
1031
1032 dev_dbg(dev, "ick/div = %ld/%ld\n",
1033 clk_get_rate(ick), clk_get_rate(div));
1034
1035 return ret;
1036}
1037
Kuninori Morimotod403e242014-06-22 17:55:41 -07001038static void fsi_pointer_update(struct fsi_stream *io, int size)
1039{
1040 io->buff_sample_pos += size;
1041
1042 if (io->buff_sample_pos >=
1043 io->period_samples * (io->period_pos + 1)) {
1044 struct snd_pcm_substream *substream = io->substream;
1045 struct snd_pcm_runtime *runtime = substream->runtime;
1046
1047 io->period_pos++;
1048
1049 if (io->period_pos >= runtime->periods) {
1050 io->buff_sample_pos = 0;
1051 io->period_pos = 0;
1052 }
1053
1054 snd_pcm_period_elapsed(substream);
1055 }
1056}
1057
Kuninori Morimoto1f5e2a32011-04-21 10:33:52 +09001058/*
Kuninori Morimoto1b0ca1a2012-02-03 00:56:27 -08001059 * pio data transfer handler
Kuninori Morimoto1f5e2a32011-04-21 10:33:52 +09001060 */
Kuninori Morimoto1b0ca1a2012-02-03 00:56:27 -08001061static void fsi_pio_push16(struct fsi_priv *fsi, u8 *_buf, int samples)
1062{
Kuninori Morimoto1b0ca1a2012-02-03 00:56:27 -08001063 int i;
1064
Kuninori Morimoto2522acd2012-11-16 01:17:30 -08001065 if (fsi_is_enable_stream(fsi)) {
Kuninori Morimoto766812e2012-05-17 17:36:47 -07001066 /*
1067 * stream mode
1068 * see
1069 * fsi_pio_push_init()
1070 */
1071 u32 *buf = (u32 *)_buf;
1072
1073 for (i = 0; i < samples / 2; i++)
1074 fsi_reg_write(fsi, DODT, buf[i]);
1075 } else {
1076 /* normal mode */
1077 u16 *buf = (u16 *)_buf;
1078
1079 for (i = 0; i < samples; i++)
1080 fsi_reg_write(fsi, DODT, ((u32)*(buf + i) << 8));
1081 }
Kuninori Morimoto1b0ca1a2012-02-03 00:56:27 -08001082}
1083
1084static void fsi_pio_pop16(struct fsi_priv *fsi, u8 *_buf, int samples)
1085{
1086 u16 *buf = (u16 *)_buf;
1087 int i;
1088
1089 for (i = 0; i < samples; i++)
1090 *(buf + i) = (u16)(fsi_reg_read(fsi, DIDT) >> 8);
1091}
1092
1093static void fsi_pio_push32(struct fsi_priv *fsi, u8 *_buf, int samples)
1094{
1095 u32 *buf = (u32 *)_buf;
1096 int i;
1097
1098 for (i = 0; i < samples; i++)
1099 fsi_reg_write(fsi, DODT, *(buf + i));
1100}
1101
1102static void fsi_pio_pop32(struct fsi_priv *fsi, u8 *_buf, int samples)
1103{
1104 u32 *buf = (u32 *)_buf;
1105 int i;
1106
1107 for (i = 0; i < samples; i++)
1108 *(buf + i) = fsi_reg_read(fsi, DIDT);
1109}
1110
1111static u8 *fsi_pio_get_area(struct fsi_priv *fsi, struct fsi_stream *io)
1112{
1113 struct snd_pcm_runtime *runtime = io->substream->runtime;
1114
1115 return runtime->dma_area +
1116 samples_to_bytes(runtime, io->buff_sample_pos);
1117}
1118
1119static int fsi_pio_transfer(struct fsi_priv *fsi, struct fsi_stream *io,
Kuninori Morimoto95b0cf02012-02-03 00:52:38 -08001120 void (*run16)(struct fsi_priv *fsi, u8 *buf, int samples),
1121 void (*run32)(struct fsi_priv *fsi, u8 *buf, int samples),
1122 int samples)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001123{
Kuninori Morimoto95b0cf02012-02-03 00:52:38 -08001124 u8 *buf;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001125
Kuninori Morimoto97df8182012-02-03 00:57:40 -08001126 if (!fsi_stream_is_working(fsi, io))
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001127 return -EINVAL;
1128
Kuninori Morimoto95b0cf02012-02-03 00:52:38 -08001129 buf = fsi_pio_get_area(fsi, io);
1130
Kuninori Morimoto376cf382012-02-03 00:50:59 -08001131 switch (io->sample_width) {
1132 case 2:
Kuninori Morimoto95b0cf02012-02-03 00:52:38 -08001133 run16(fsi, buf, samples);
Kuninori Morimoto376cf382012-02-03 00:50:59 -08001134 break;
1135 case 4:
Kuninori Morimoto95b0cf02012-02-03 00:52:38 -08001136 run32(fsi, buf, samples);
Kuninori Morimoto376cf382012-02-03 00:50:59 -08001137 break;
1138 default:
1139 return -EINVAL;
Kuninori Morimoto9ddc9aa2009-10-30 12:02:39 +09001140 }
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001141
Kuninori Morimotod403e242014-06-22 17:55:41 -07001142 fsi_pointer_update(io, samples);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001143
Kuninori Morimoto47fc9a02010-02-22 16:41:57 +09001144 return 0;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001145}
1146
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001147static int fsi_pio_pop(struct fsi_priv *fsi, struct fsi_stream *io)
Kuninori Morimoto07102f32009-10-30 12:02:44 +09001148{
Kuninori Morimoto376cf382012-02-03 00:50:59 -08001149 int sample_residues; /* samples in FSI fifo */
1150 int sample_space; /* ALSA free samples space */
1151 int samples;
Kuninori Morimoto376cf382012-02-03 00:50:59 -08001152
Kuninori Morimoto7b1b3332012-02-03 00:55:26 -08001153 sample_residues = fsi_get_current_fifo_samples(fsi, io);
Kuninori Morimoto376cf382012-02-03 00:50:59 -08001154 sample_space = io->buff_sample_capa - io->buff_sample_pos;
1155
1156 samples = min(sample_residues, sample_space);
1157
Kuninori Morimoto1b0ca1a2012-02-03 00:56:27 -08001158 return fsi_pio_transfer(fsi, io,
Kuninori Morimotod78629e2012-02-03 00:51:14 -08001159 fsi_pio_pop16,
1160 fsi_pio_pop32,
Kuninori Morimoto376cf382012-02-03 00:50:59 -08001161 samples);
Kuninori Morimotod8b33532010-09-17 13:49:05 +09001162}
Kuninori Morimoto07102f32009-10-30 12:02:44 +09001163
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001164static int fsi_pio_push(struct fsi_priv *fsi, struct fsi_stream *io)
Kuninori Morimotod8b33532010-09-17 13:49:05 +09001165{
Kuninori Morimoto376cf382012-02-03 00:50:59 -08001166 int sample_residues; /* ALSA residue samples */
1167 int sample_space; /* FSI fifo free samples space */
1168 int samples;
Kuninori Morimoto376cf382012-02-03 00:50:59 -08001169
1170 sample_residues = io->buff_sample_capa - io->buff_sample_pos;
1171 sample_space = io->fifo_sample_capa -
Kuninori Morimoto7b1b3332012-02-03 00:55:26 -08001172 fsi_get_current_fifo_samples(fsi, io);
Kuninori Morimoto376cf382012-02-03 00:50:59 -08001173
1174 samples = min(sample_residues, sample_space);
1175
Kuninori Morimoto1b0ca1a2012-02-03 00:56:27 -08001176 return fsi_pio_transfer(fsi, io,
Kuninori Morimotod78629e2012-02-03 00:51:14 -08001177 fsi_pio_push16,
1178 fsi_pio_push32,
Kuninori Morimoto376cf382012-02-03 00:50:59 -08001179 samples);
Kuninori Morimoto07102f32009-10-30 12:02:44 +09001180}
1181
Kuninori Morimotoc375b2d2013-05-28 00:55:12 -07001182static int fsi_pio_start_stop(struct fsi_priv *fsi, struct fsi_stream *io,
Kuninori Morimoto180346e2012-02-03 00:57:25 -08001183 int enable)
1184{
1185 struct fsi_master *master = fsi_get_master(fsi);
1186 u32 clk = fsi_is_port_a(fsi) ? CRA : CRB;
1187
1188 if (enable)
1189 fsi_irq_enable(fsi, io);
1190 else
1191 fsi_irq_disable(fsi, io);
1192
1193 if (fsi_is_clk_master(fsi))
1194 fsi_master_mask_set(master, CLK_RST, clk, (enable) ? clk : 0);
Kuninori Morimotoc375b2d2013-05-28 00:55:12 -07001195
1196 return 0;
Kuninori Morimoto180346e2012-02-03 00:57:25 -08001197}
1198
Kuninori Morimoto766812e2012-05-17 17:36:47 -07001199static int fsi_pio_push_init(struct fsi_priv *fsi, struct fsi_stream *io)
1200{
Kuninori Morimoto766812e2012-05-17 17:36:47 -07001201 /*
1202 * we can use 16bit stream mode
1203 * when "playback" and "16bit data"
1204 * and platform allows "stream mode"
1205 * see
1206 * fsi_pio_push16()
1207 */
Kuninori Morimoto2522acd2012-11-16 01:17:30 -08001208 if (fsi_is_enable_stream(fsi))
Kuninori Morimoto766812e2012-05-17 17:36:47 -07001209 io->bus_option = BUSOP_SET(24, PACKAGE_24BITBUS_BACK) |
1210 BUSOP_SET(16, PACKAGE_16BITBUS_STREAM);
1211 else
1212 io->bus_option = BUSOP_SET(24, PACKAGE_24BITBUS_BACK) |
1213 BUSOP_SET(16, PACKAGE_24BITBUS_BACK);
1214 return 0;
1215}
1216
1217static int fsi_pio_pop_init(struct fsi_priv *fsi, struct fsi_stream *io)
1218{
1219 /*
1220 * always 24bit bus, package back when "capture"
1221 */
1222 io->bus_option = BUSOP_SET(24, PACKAGE_24BITBUS_BACK) |
1223 BUSOP_SET(16, PACKAGE_24BITBUS_BACK);
1224 return 0;
1225}
1226
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001227static struct fsi_stream_handler fsi_pio_push_handler = {
Kuninori Morimoto766812e2012-05-17 17:36:47 -07001228 .init = fsi_pio_push_init,
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001229 .transfer = fsi_pio_push,
Kuninori Morimoto180346e2012-02-03 00:57:25 -08001230 .start_stop = fsi_pio_start_stop,
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001231};
1232
1233static struct fsi_stream_handler fsi_pio_pop_handler = {
Kuninori Morimoto766812e2012-05-17 17:36:47 -07001234 .init = fsi_pio_pop_init,
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001235 .transfer = fsi_pio_pop,
Kuninori Morimoto180346e2012-02-03 00:57:25 -08001236 .start_stop = fsi_pio_start_stop,
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001237};
1238
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001239static irqreturn_t fsi_interrupt(int irq, void *data)
1240{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +09001241 struct fsi_master *master = data;
Kuninori Morimoto10ea76c2010-03-23 11:47:54 +09001242 u32 int_st = fsi_irq_get_status(master);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001243
1244 /* clear irq status */
Kuninori Morimotofeb58cf2010-03-24 15:27:24 +09001245 fsi_master_mask_set(master, SOFT_RST, IR, 0);
1246 fsi_master_mask_set(master, SOFT_RST, IR, IR);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001247
Kuninori Morimotocf6edd02010-10-12 11:40:53 +09001248 if (int_st & AB_IO(1, AO_SHIFT))
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001249 fsi_stream_transfer(&master->fsia.playback);
Kuninori Morimotocf6edd02010-10-12 11:40:53 +09001250 if (int_st & AB_IO(1, BO_SHIFT))
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001251 fsi_stream_transfer(&master->fsib.playback);
Kuninori Morimotocf6edd02010-10-12 11:40:53 +09001252 if (int_st & AB_IO(1, AI_SHIFT))
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001253 fsi_stream_transfer(&master->fsia.capture);
Kuninori Morimotocf6edd02010-10-12 11:40:53 +09001254 if (int_st & AB_IO(1, BI_SHIFT))
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001255 fsi_stream_transfer(&master->fsib.capture);
Kuninori Morimoto1ec9bc32010-12-17 12:55:22 +09001256
1257 fsi_count_fifo_err(&master->fsia);
1258 fsi_count_fifo_err(&master->fsib);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001259
Kuninori Morimoto48d78e52010-12-03 17:37:31 +09001260 fsi_irq_clear_status(&master->fsia);
1261 fsi_irq_clear_status(&master->fsib);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001262
1263 return IRQ_HANDLED;
1264}
1265
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +09001266/*
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001267 * dma data transfer handler
1268 */
1269static int fsi_dma_init(struct fsi_priv *fsi, struct fsi_stream *io)
1270{
Kuninori Morimoto766812e2012-05-17 17:36:47 -07001271 /*
1272 * 24bit data : 24bit bus / package in back
1273 * 16bit data : 16bit bus / stream mode
1274 */
1275 io->bus_option = BUSOP_SET(24, PACKAGE_24BITBUS_BACK) |
1276 BUSOP_SET(16, PACKAGE_16BITBUS_STREAM);
1277
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001278 return 0;
1279}
1280
1281static void fsi_dma_complete(void *data)
1282{
1283 struct fsi_stream *io = (struct fsi_stream *)data;
1284 struct fsi_priv *fsi = fsi_stream_to_priv(io);
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001285
Kuninori Morimotod403e242014-06-22 17:55:41 -07001286 fsi_pointer_update(io, io->period_samples);
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001287
1288 fsi_count_fifo_err(fsi);
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001289}
1290
Kuninori Morimoto8457e0e2014-06-22 17:55:59 -07001291static int fsi_dma_transfer(struct fsi_priv *fsi, struct fsi_stream *io)
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001292{
Kuninori Morimoto8457e0e2014-06-22 17:55:59 -07001293 struct snd_soc_dai *dai = fsi_get_dai(io->substream);
1294 struct snd_pcm_substream *substream = io->substream;
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001295 struct dma_async_tx_descriptor *desc;
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001296 int is_play = fsi_stream_is_play(fsi, io);
Lars-Peter Clausen6c7d1df2014-08-17 16:18:20 +02001297 enum dma_transfer_direction dir;
Kuninori Morimoto8457e0e2014-06-22 17:55:59 -07001298 int ret = -EIO;
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001299
Lars-Peter Clausen6c7d1df2014-08-17 16:18:20 +02001300 if (is_play)
1301 dir = DMA_MEM_TO_DEV;
1302 else
1303 dir = DMA_DEV_TO_MEM;
1304
Kuninori Morimoto8457e0e2014-06-22 17:55:59 -07001305 desc = dmaengine_prep_dma_cyclic(io->chan,
1306 substream->runtime->dma_addr,
1307 snd_pcm_lib_buffer_bytes(substream),
1308 snd_pcm_lib_period_bytes(substream),
1309 dir,
1310 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
1311 if (!desc) {
1312 dev_err(dai->dev, "dmaengine_prep_dma_cyclic() fail\n");
1313 goto fsi_dma_transfer_err;
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001314 }
1315
Kuninori Morimoto8457e0e2014-06-22 17:55:59 -07001316 desc->callback = fsi_dma_complete;
1317 desc->callback_param = io;
1318
1319 if (dmaengine_submit(desc) < 0) {
1320 dev_err(dai->dev, "tx_submit() fail\n");
1321 goto fsi_dma_transfer_err;
1322 }
1323
1324 dma_async_issue_pending(io->chan);
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001325
1326 /*
1327 * FIXME
1328 *
1329 * In DMAEngine case, codec and FSI cannot be started simultaneously
Guennadi Liakhovetski57451e42012-10-03 14:33:50 +02001330 * since FSI is using the scheduler work queue.
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001331 * Therefore, in capture case, probably FSI FIFO will have got
1332 * overflow error in this point.
1333 * in that case, DMA cannot start transfer until error was cleared.
1334 */
1335 if (!is_play) {
1336 if (ERR_OVER & fsi_reg_read(fsi, DIFF_ST)) {
1337 fsi_reg_mask_set(fsi, DIFF_CTL, FIFO_CLR, FIFO_CLR);
1338 fsi_reg_write(fsi, DIFF_ST, 0);
1339 }
1340 }
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001341
Kuninori Morimoto8457e0e2014-06-22 17:55:59 -07001342 ret = 0;
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001343
Kuninori Morimoto8457e0e2014-06-22 17:55:59 -07001344fsi_dma_transfer_err:
1345 return ret;
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001346}
1347
Kuninori Morimotoc375b2d2013-05-28 00:55:12 -07001348static int fsi_dma_push_start_stop(struct fsi_priv *fsi, struct fsi_stream *io,
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001349 int start)
1350{
Kuninori Morimotoe42bb9b2012-05-24 23:55:11 -07001351 struct fsi_master *master = fsi_get_master(fsi);
1352 u32 clk = fsi_is_port_a(fsi) ? CRA : CRB;
Kuninori Morimoto766812e2012-05-17 17:36:47 -07001353 u32 enable = start ? DMA_ON : 0;
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001354
Kuninori Morimoto766812e2012-05-17 17:36:47 -07001355 fsi_reg_mask_set(fsi, OUT_DMAC, DMA_ON, enable);
Kuninori Morimotoe42bb9b2012-05-24 23:55:11 -07001356
Kuninori Morimotofbe42f62012-05-28 23:28:22 -07001357 dmaengine_terminate_all(io->chan);
1358
Kuninori Morimotoe42bb9b2012-05-24 23:55:11 -07001359 if (fsi_is_clk_master(fsi))
1360 fsi_master_mask_set(master, CLK_RST, clk, (enable) ? clk : 0);
Kuninori Morimotoc375b2d2013-05-28 00:55:12 -07001361
1362 return 0;
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001363}
1364
Kuninori Morimotob1226dc2012-05-24 23:56:19 -07001365static int fsi_dma_probe(struct fsi_priv *fsi, struct fsi_stream *io, struct device *dev)
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001366{
1367 dma_cap_mask_t mask;
Kuninori Morimotoa0732782013-12-10 20:46:59 -08001368 int is_play = fsi_stream_is_play(fsi, io);
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001369
1370 dma_cap_zero(mask);
1371 dma_cap_set(DMA_SLAVE, mask);
1372
Kuninori Morimotoa0732782013-12-10 20:46:59 -08001373 io->chan = dma_request_slave_channel_compat(mask,
1374 shdma_chan_filter, (void *)io->dma_id,
1375 dev, is_play ? "tx" : "rx");
1376 if (io->chan) {
1377 struct dma_slave_config cfg;
1378 int ret;
1379
1380 cfg.slave_id = io->dma_id;
1381 cfg.dst_addr = 0; /* use default addr */
1382 cfg.src_addr = 0; /* use default addr */
1383 cfg.direction = is_play ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM;
1384
1385 ret = dmaengine_slave_config(io->chan, &cfg);
1386 if (ret < 0) {
1387 dma_release_channel(io->chan);
1388 io->chan = NULL;
1389 }
1390 }
1391
Kuninori Morimotob1226dc2012-05-24 23:56:19 -07001392 if (!io->chan) {
1393
1394 /* switch to PIO handler */
Kuninori Morimotoa0732782013-12-10 20:46:59 -08001395 if (is_play)
Kuninori Morimotob1226dc2012-05-24 23:56:19 -07001396 fsi->playback.handler = &fsi_pio_push_handler;
1397 else
1398 fsi->capture.handler = &fsi_pio_pop_handler;
1399
1400 dev_info(dev, "switch handler (dma => pio)\n");
1401
1402 /* probe again */
1403 return fsi_stream_probe(fsi, dev);
1404 }
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001405
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001406 return 0;
1407}
1408
1409static int fsi_dma_remove(struct fsi_priv *fsi, struct fsi_stream *io)
1410{
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001411 fsi_stream_stop(fsi, io);
1412
1413 if (io->chan)
1414 dma_release_channel(io->chan);
1415
1416 io->chan = NULL;
1417 return 0;
1418}
1419
1420static struct fsi_stream_handler fsi_dma_push_handler = {
1421 .init = fsi_dma_init,
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001422 .probe = fsi_dma_probe,
1423 .transfer = fsi_dma_transfer,
1424 .remove = fsi_dma_remove,
1425 .start_stop = fsi_dma_push_start_stop,
1426};
1427
1428/*
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +09001429 * dai ops
1430 */
Kuninori Morimotob49e8022012-02-03 00:51:29 -08001431static void fsi_fifo_init(struct fsi_priv *fsi,
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001432 struct fsi_stream *io,
Kuninori Morimotob49e8022012-02-03 00:51:29 -08001433 struct device *dev)
1434{
1435 struct fsi_master *master = fsi_get_master(fsi);
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001436 int is_play = fsi_stream_is_play(fsi, io);
Kuninori Morimotob49e8022012-02-03 00:51:29 -08001437 u32 shift, i;
1438 int frame_capa;
1439
1440 /* get on-chip RAM capacity */
1441 shift = fsi_master_read(master, FIFO_SZ);
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001442 shift >>= fsi_get_port_shift(fsi, io);
Kuninori Morimotob49e8022012-02-03 00:51:29 -08001443 shift &= FIFO_SZ_MASK;
1444 frame_capa = 256 << shift;
1445 dev_dbg(dev, "fifo = %d words\n", frame_capa);
1446
1447 /*
1448 * The maximum number of sample data varies depending
1449 * on the number of channels selected for the format.
1450 *
1451 * FIFOs are used in 4-channel units in 3-channel mode
1452 * and in 8-channel units in 5- to 7-channel mode
1453 * meaning that more FIFOs than the required size of DPRAM
1454 * are used.
1455 *
1456 * ex) if 256 words of DP-RAM is connected
1457 * 1 channel: 256 (256 x 1 = 256)
1458 * 2 channels: 128 (128 x 2 = 256)
1459 * 3 channels: 64 ( 64 x 3 = 192)
1460 * 4 channels: 64 ( 64 x 4 = 256)
1461 * 5 channels: 32 ( 32 x 5 = 160)
1462 * 6 channels: 32 ( 32 x 6 = 192)
1463 * 7 channels: 32 ( 32 x 7 = 224)
1464 * 8 channels: 32 ( 32 x 8 = 256)
1465 */
1466 for (i = 1; i < fsi->chan_num; i <<= 1)
1467 frame_capa >>= 1;
1468 dev_dbg(dev, "%d channel %d store\n",
1469 fsi->chan_num, frame_capa);
1470
1471 io->fifo_sample_capa = fsi_frame2sample(fsi, frame_capa);
1472
1473 /*
1474 * set interrupt generation factor
1475 * clear FIFO
1476 */
1477 if (is_play) {
1478 fsi_reg_write(fsi, DOFF_CTL, IRQ_HALF);
1479 fsi_reg_mask_set(fsi, DOFF_CTL, FIFO_CLR, FIFO_CLR);
1480 } else {
1481 fsi_reg_write(fsi, DIFF_CTL, IRQ_HALF);
1482 fsi_reg_mask_set(fsi, DIFF_CTL, FIFO_CLR, FIFO_CLR);
1483 }
1484}
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001485
Kuninori Morimoto23ca8532011-05-23 20:46:26 +09001486static int fsi_hw_startup(struct fsi_priv *fsi,
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001487 struct fsi_stream *io,
Kuninori Morimoto23ca8532011-05-23 20:46:26 +09001488 struct device *dev)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001489{
Kuninori Morimoto9478e0b2011-05-23 20:46:07 +09001490 u32 data = 0;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001491
Kuninori Morimoto9478e0b2011-05-23 20:46:07 +09001492 /* clock setting */
1493 if (fsi_is_clk_master(fsi))
1494 data = DIMD | DOMD;
1495
1496 fsi_reg_mask_set(fsi, CKG1, (DIMD | DOMD), data);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001497
1498 /* clock inversion (CKG2) */
1499 data = 0;
Kuninori Morimoto3449f5f2012-11-16 01:17:43 -08001500 if (fsi->bit_clk_inv)
1501 data |= (1 << 0);
1502 if (fsi->lr_clk_inv)
1503 data |= (1 << 4);
1504 if (fsi_is_clk_master(fsi))
1505 data <<= 8;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001506 fsi_reg_write(fsi, CKG2, data);
1507
Kuninori Morimoto9478e0b2011-05-23 20:46:07 +09001508 /* spdif ? */
1509 if (fsi_is_spdif(fsi)) {
1510 fsi_spdif_clk_ctrl(fsi, 1);
1511 fsi_reg_mask_set(fsi, OUT_SEL, DMMD, DMMD);
1512 }
1513
Kuninori Morimoto65ff03f2011-11-06 22:05:25 -08001514 /*
Kuninori Morimoto766812e2012-05-17 17:36:47 -07001515 * get bus settings
Kuninori Morimoto65ff03f2011-11-06 22:05:25 -08001516 */
Kuninori Morimoto766812e2012-05-17 17:36:47 -07001517 data = 0;
1518 switch (io->sample_width) {
1519 case 2:
1520 data = BUSOP_GET(16, io->bus_option);
1521 break;
1522 case 4:
1523 data = BUSOP_GET(24, io->bus_option);
1524 break;
Kuninori Morimoto65ff03f2011-11-06 22:05:25 -08001525 }
Kuninori Morimoto766812e2012-05-17 17:36:47 -07001526 fsi_format_bus_setup(fsi, io, data, dev);
Kuninori Morimoto65ff03f2011-11-06 22:05:25 -08001527
Kuninori Morimoto10ea76c2010-03-23 11:47:54 +09001528 /* irq clear */
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001529 fsi_irq_disable(fsi, io);
Kuninori Morimoto10ea76c2010-03-23 11:47:54 +09001530 fsi_irq_clear_status(fsi);
1531
1532 /* fifo init */
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001533 fsi_fifo_init(fsi, io, dev);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001534
Kuninori Morimotoddeb2d72012-10-29 00:37:22 -07001535 /* start master clock */
1536 if (fsi_is_clk_master(fsi))
Kuninori Morimoto6cbdbff2012-12-16 22:12:21 -08001537 return fsi_clk_enable(dev, fsi);
Kuninori Morimotoddeb2d72012-10-29 00:37:22 -07001538
Kuninori Morimotoa68a3b42010-10-12 11:39:50 +09001539 return 0;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001540}
1541
Kuninori Morimoto80b4add2012-10-30 19:59:15 -07001542static int fsi_hw_shutdown(struct fsi_priv *fsi,
Kuninori Morimoto23ca8532011-05-23 20:46:26 +09001543 struct device *dev)
1544{
Kuninori Morimotoddeb2d72012-10-29 00:37:22 -07001545 /* stop master clock */
Kuninori Morimoto23ca8532011-05-23 20:46:26 +09001546 if (fsi_is_clk_master(fsi))
Kuninori Morimoto6cbdbff2012-12-16 22:12:21 -08001547 return fsi_clk_disable(dev, fsi);
Kuninori Morimoto80b4add2012-10-30 19:59:15 -07001548
1549 return 0;
Kuninori Morimoto23ca8532011-05-23 20:46:26 +09001550}
1551
1552static int fsi_dai_startup(struct snd_pcm_substream *substream,
1553 struct snd_soc_dai *dai)
1554{
1555 struct fsi_priv *fsi = fsi_get_priv(substream);
Kuninori Morimoto23ca8532011-05-23 20:46:26 +09001556
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -08001557 fsi_clk_invalid(fsi);
Kuninori Morimotof33238e2012-05-17 17:35:34 -07001558
1559 return 0;
Kuninori Morimoto23ca8532011-05-23 20:46:26 +09001560}
1561
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001562static void fsi_dai_shutdown(struct snd_pcm_substream *substream,
1563 struct snd_soc_dai *dai)
1564{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +09001565 struct fsi_priv *fsi = fsi_get_priv(substream);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001566
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -08001567 fsi_clk_invalid(fsi);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001568}
1569
1570static int fsi_dai_trigger(struct snd_pcm_substream *substream, int cmd,
1571 struct snd_soc_dai *dai)
1572{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +09001573 struct fsi_priv *fsi = fsi_get_priv(substream);
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001574 struct fsi_stream *io = fsi_stream_get(fsi, substream);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001575 int ret = 0;
1576
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001577 switch (cmd) {
1578 case SNDRV_PCM_TRIGGER_START:
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001579 fsi_stream_init(fsi, io, substream);
Kuninori Morimoto80b4add2012-10-30 19:59:15 -07001580 if (!ret)
1581 ret = fsi_hw_startup(fsi, io, dai->dev);
1582 if (!ret)
Kuninori Morimoto8457e0e2014-06-22 17:55:59 -07001583 ret = fsi_stream_start(fsi, io);
Kuninori Morimoto80b4add2012-10-30 19:59:15 -07001584 if (!ret)
Kuninori Morimoto8457e0e2014-06-22 17:55:59 -07001585 ret = fsi_stream_transfer(io);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001586 break;
1587 case SNDRV_PCM_TRIGGER_STOP:
Kuninori Morimoto80b4add2012-10-30 19:59:15 -07001588 if (!ret)
1589 ret = fsi_hw_shutdown(fsi, dai->dev);
Kuninori Morimoto180346e2012-02-03 00:57:25 -08001590 fsi_stream_stop(fsi, io);
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001591 fsi_stream_quit(fsi, io);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001592 break;
1593 }
1594
1595 return ret;
1596}
1597
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001598static int fsi_set_fmt_dai(struct fsi_priv *fsi, unsigned int fmt)
1599{
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001600 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
1601 case SND_SOC_DAIFMT_I2S:
Kuninori Morimoto9c59dd32012-05-17 17:34:53 -07001602 fsi->fmt = CR_I2S;
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001603 fsi->chan_num = 2;
1604 break;
1605 case SND_SOC_DAIFMT_LEFT_J:
Kuninori Morimoto9c59dd32012-05-17 17:34:53 -07001606 fsi->fmt = CR_PCM;
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001607 fsi->chan_num = 2;
1608 break;
1609 default:
1610 return -EINVAL;
1611 }
1612
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001613 return 0;
1614}
1615
1616static int fsi_set_fmt_spdif(struct fsi_priv *fsi)
1617{
1618 struct fsi_master *master = fsi_get_master(fsi);
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001619
Kuninori Morimoto284c6f62012-05-17 17:34:16 -07001620 if (fsi_version(master) < 2)
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001621 return -EINVAL;
1622
Kuninori Morimoto766812e2012-05-17 17:36:47 -07001623 fsi->fmt = CR_DTMD_SPDIF_PCM | CR_PCM;
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001624 fsi->chan_num = 2;
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001625
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001626 return 0;
1627}
1628
Kuninori Morimoto4d805f72011-01-20 11:46:02 +09001629static int fsi_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
1630{
1631 struct fsi_priv *fsi = fsi_get_priv_frm_dai(dai);
Kuninori Morimoto4d805f72011-01-20 11:46:02 +09001632 int ret;
1633
Kuninori Morimoto4d805f72011-01-20 11:46:02 +09001634 /* set master/slave audio interface */
1635 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1636 case SND_SOC_DAIFMT_CBM_CFM:
Kuninori Morimoto4d805f72011-01-20 11:46:02 +09001637 break;
1638 case SND_SOC_DAIFMT_CBS_CFS:
Kuninori Morimotoc7a507e2014-03-13 17:56:25 -07001639 fsi->clk_master = 1; /* codec is slave, cpu is master */
Kuninori Morimoto4d805f72011-01-20 11:46:02 +09001640 break;
1641 default:
Kuninori Morimoto9478e0b2011-05-23 20:46:07 +09001642 return -EINVAL;
Kuninori Morimoto4d805f72011-01-20 11:46:02 +09001643 }
Kuninori Morimoto6a9ebad2011-04-21 10:33:36 +09001644
Kuninori Morimoto3449f5f2012-11-16 01:17:43 -08001645 /* set clock inversion */
1646 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
1647 case SND_SOC_DAIFMT_NB_IF:
1648 fsi->bit_clk_inv = 0;
1649 fsi->lr_clk_inv = 1;
1650 break;
1651 case SND_SOC_DAIFMT_IB_NF:
1652 fsi->bit_clk_inv = 1;
1653 fsi->lr_clk_inv = 0;
1654 break;
1655 case SND_SOC_DAIFMT_IB_IF:
1656 fsi->bit_clk_inv = 1;
1657 fsi->lr_clk_inv = 1;
1658 break;
1659 case SND_SOC_DAIFMT_NB_NF:
1660 default:
1661 fsi->bit_clk_inv = 0;
1662 fsi->lr_clk_inv = 0;
1663 break;
1664 }
1665
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -08001666 if (fsi_is_clk_master(fsi)) {
Kuninori Morimotoab6340c2012-11-16 01:17:18 -08001667 if (fsi->clk_cpg)
Kuninori Morimotoab6f6d82012-11-05 18:30:38 -08001668 fsi_clk_init(dai->dev, fsi, 0, 1, 1,
1669 fsi_clk_set_rate_cpg);
Kuninori Morimotoab6340c2012-11-16 01:17:18 -08001670 else
1671 fsi_clk_init(dai->dev, fsi, 1, 1, 0,
1672 fsi_clk_set_rate_external);
Kuninori Morimoto6a9ebad2011-04-21 10:33:36 +09001673 }
1674
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001675 /* set format */
Kuninori Morimotoc2052de2012-11-16 01:17:06 -08001676 if (fsi_is_spdif(fsi))
Kuninori Morimotof17c13c2011-01-24 10:43:19 +09001677 ret = fsi_set_fmt_spdif(fsi);
Kuninori Morimotoc2052de2012-11-16 01:17:06 -08001678 else
1679 ret = fsi_set_fmt_dai(fsi, fmt & SND_SOC_DAIFMT_FORMAT_MASK);
Kuninori Morimoto4d805f72011-01-20 11:46:02 +09001680
Kuninori Morimoto4d805f72011-01-20 11:46:02 +09001681 return ret;
1682}
1683
Kuninori Morimotoccad7b42010-07-13 12:13:14 +09001684static int fsi_dai_hw_params(struct snd_pcm_substream *substream,
1685 struct snd_pcm_hw_params *params,
1686 struct snd_soc_dai *dai)
1687{
1688 struct fsi_priv *fsi = fsi_get_priv(substream);
Kuninori Morimotoccad7b42010-07-13 12:13:14 +09001689
Kuninori Morimoto6cbdbff2012-12-16 22:12:21 -08001690 if (fsi_is_clk_master(fsi))
1691 fsi_clk_valid(fsi, params_rate(params));
Kuninori Morimotoccad7b42010-07-13 12:13:14 +09001692
Kuninori Morimotoddeb2d72012-10-29 00:37:22 -07001693 return 0;
Kuninori Morimotoccad7b42010-07-13 12:13:14 +09001694}
1695
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01001696static const struct snd_soc_dai_ops fsi_dai_ops = {
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001697 .startup = fsi_dai_startup,
1698 .shutdown = fsi_dai_shutdown,
1699 .trigger = fsi_dai_trigger,
Kuninori Morimoto4d805f72011-01-20 11:46:02 +09001700 .set_fmt = fsi_dai_set_fmt,
Kuninori Morimotoccad7b42010-07-13 12:13:14 +09001701 .hw_params = fsi_dai_hw_params,
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001702};
1703
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +09001704/*
1705 * pcm ops
1706 */
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001707
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001708static struct snd_pcm_hardware fsi_pcm_hardware = {
1709 .info = SNDRV_PCM_INFO_INTERLEAVED |
1710 SNDRV_PCM_INFO_MMAP |
1711 SNDRV_PCM_INFO_MMAP_VALID |
1712 SNDRV_PCM_INFO_PAUSE,
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001713 .buffer_bytes_max = 64 * 1024,
1714 .period_bytes_min = 32,
1715 .period_bytes_max = 8192,
1716 .periods_min = 1,
1717 .periods_max = 32,
1718 .fifo_size = 256,
1719};
1720
1721static int fsi_pcm_open(struct snd_pcm_substream *substream)
1722{
1723 struct snd_pcm_runtime *runtime = substream->runtime;
1724 int ret = 0;
1725
1726 snd_soc_set_runtime_hwparams(substream, &fsi_pcm_hardware);
1727
1728 ret = snd_pcm_hw_constraint_integer(runtime,
1729 SNDRV_PCM_HW_PARAM_PERIODS);
1730
1731 return ret;
1732}
1733
1734static int fsi_hw_params(struct snd_pcm_substream *substream,
1735 struct snd_pcm_hw_params *hw_params)
1736{
1737 return snd_pcm_lib_malloc_pages(substream,
1738 params_buffer_bytes(hw_params));
1739}
1740
1741static int fsi_hw_free(struct snd_pcm_substream *substream)
1742{
1743 return snd_pcm_lib_free_pages(substream);
1744}
1745
1746static snd_pcm_uframes_t fsi_pointer(struct snd_pcm_substream *substream)
1747{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +09001748 struct fsi_priv *fsi = fsi_get_priv(substream);
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08001749 struct fsi_stream *io = fsi_stream_get(fsi, substream);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001750
Kuninori Morimoto19878772012-02-08 16:57:29 -08001751 return fsi_sample2frame(fsi, io->buff_sample_pos);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001752}
1753
1754static struct snd_pcm_ops fsi_pcm_ops = {
1755 .open = fsi_pcm_open,
1756 .ioctl = snd_pcm_lib_ioctl,
1757 .hw_params = fsi_hw_params,
1758 .hw_free = fsi_hw_free,
1759 .pointer = fsi_pointer,
1760};
1761
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +09001762/*
1763 * snd_soc_platform
1764 */
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001765
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001766#define PREALLOC_BUFFER (32 * 1024)
1767#define PREALLOC_BUFFER_MAX (32 * 1024)
1768
1769static void fsi_pcm_free(struct snd_pcm *pcm)
1770{
1771 snd_pcm_lib_preallocate_free_for_all(pcm);
1772}
1773
Liam Girdwood552d1ef2011-06-07 16:08:33 +01001774static int fsi_pcm_new(struct snd_soc_pcm_runtime *rtd)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001775{
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001776 return snd_pcm_lib_preallocate_pages_for_all(
Kuninori Morimotoffb83e82014-06-22 17:55:18 -07001777 rtd->pcm,
1778 SNDRV_DMA_TYPE_DEV,
1779 rtd->card->snd_card->dev,
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001780 PREALLOC_BUFFER, PREALLOC_BUFFER_MAX);
1781}
1782
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +09001783/*
1784 * alsa struct
1785 */
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001786
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001787static struct snd_soc_dai_driver fsi_soc_dai[] = {
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001788 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001789 .name = "fsia-dai",
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001790 .playback = {
1791 .rates = FSI_RATES,
1792 .formats = FSI_FMTS,
Kuninori Morimoto2a8c8a52012-10-02 19:08:53 -07001793 .channels_min = 2,
1794 .channels_max = 2,
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001795 },
Kuninori Morimoto07102f32009-10-30 12:02:44 +09001796 .capture = {
1797 .rates = FSI_RATES,
1798 .formats = FSI_FMTS,
Kuninori Morimoto2a8c8a52012-10-02 19:08:53 -07001799 .channels_min = 2,
1800 .channels_max = 2,
Kuninori Morimoto07102f32009-10-30 12:02:44 +09001801 },
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001802 .ops = &fsi_dai_ops,
1803 },
1804 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001805 .name = "fsib-dai",
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001806 .playback = {
1807 .rates = FSI_RATES,
1808 .formats = FSI_FMTS,
Kuninori Morimoto2a8c8a52012-10-02 19:08:53 -07001809 .channels_min = 2,
1810 .channels_max = 2,
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001811 },
Kuninori Morimoto07102f32009-10-30 12:02:44 +09001812 .capture = {
1813 .rates = FSI_RATES,
1814 .formats = FSI_FMTS,
Kuninori Morimoto2a8c8a52012-10-02 19:08:53 -07001815 .channels_min = 2,
1816 .channels_max = 2,
Kuninori Morimoto07102f32009-10-30 12:02:44 +09001817 },
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001818 .ops = &fsi_dai_ops,
1819 },
1820};
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001821
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001822static struct snd_soc_platform_driver fsi_soc_platform = {
1823 .ops = &fsi_pcm_ops,
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001824 .pcm_new = fsi_pcm_new,
1825 .pcm_free = fsi_pcm_free,
1826};
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001827
Kuninori Morimotoda4f2f92013-03-14 00:19:20 -07001828static const struct snd_soc_component_driver fsi_soc_component = {
1829 .name = "fsi",
1830};
1831
Kuninori Morimotoc8fe2572010-09-17 13:48:17 +09001832/*
1833 * platform function
1834 */
Kuninori Morimoto9e7b6d62013-01-10 00:34:08 -08001835static void fsi_of_parse(char *name,
1836 struct device_node *np,
1837 struct sh_fsi_port_info *info,
1838 struct device *dev)
1839{
1840 int i;
1841 char prop[128];
1842 unsigned long flags = 0;
1843 struct {
1844 char *name;
1845 unsigned int val;
1846 } of_parse_property[] = {
1847 { "spdif-connection", SH_FSI_FMT_SPDIF },
1848 { "stream-mode-support", SH_FSI_ENABLE_STREAM_MODE },
1849 { "use-internal-clock", SH_FSI_CLK_CPG },
1850 };
1851
1852 for (i = 0; i < ARRAY_SIZE(of_parse_property); i++) {
1853 sprintf(prop, "%s,%s", name, of_parse_property[i].name);
1854 if (of_get_property(np, prop, NULL))
1855 flags |= of_parse_property[i].val;
1856 }
1857 info->flags = flags;
1858
1859 dev_dbg(dev, "%s flags : %lx\n", name, info->flags);
1860}
1861
Kuninori Morimotoc2052de2012-11-16 01:17:06 -08001862static void fsi_port_info_init(struct fsi_priv *fsi,
1863 struct sh_fsi_port_info *info)
1864{
1865 if (info->flags & SH_FSI_FMT_SPDIF)
1866 fsi->spdif = 1;
Kuninori Morimotoab6340c2012-11-16 01:17:18 -08001867
1868 if (info->flags & SH_FSI_CLK_CPG)
1869 fsi->clk_cpg = 1;
Kuninori Morimoto2522acd2012-11-16 01:17:30 -08001870
1871 if (info->flags & SH_FSI_ENABLE_STREAM_MODE)
1872 fsi->enable_stream = 1;
Kuninori Morimotoc2052de2012-11-16 01:17:06 -08001873}
1874
Kuninori Morimoto943fdad2012-11-16 01:16:52 -08001875static void fsi_handler_init(struct fsi_priv *fsi,
1876 struct sh_fsi_port_info *info)
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001877{
1878 fsi->playback.handler = &fsi_pio_push_handler; /* default PIO */
1879 fsi->playback.priv = fsi;
1880 fsi->capture.handler = &fsi_pio_pop_handler; /* default PIO */
1881 fsi->capture.priv = fsi;
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001882
Kuninori Morimoto943fdad2012-11-16 01:16:52 -08001883 if (info->tx_id) {
Kuninori Morimotoa0732782013-12-10 20:46:59 -08001884 fsi->playback.dma_id = info->tx_id;
Guennadi Liakhovetskib8373142012-05-09 17:09:20 +02001885 fsi->playback.handler = &fsi_dma_push_handler;
Kuninori Morimoto7da9ced2012-02-03 00:59:33 -08001886 }
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001887}
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001888
Kuninori Morimoto9e7b6d62013-01-10 00:34:08 -08001889static struct of_device_id fsi_of_match[];
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001890static int fsi_probe(struct platform_device *pdev)
1891{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +09001892 struct fsi_master *master;
Kuninori Morimoto9e7b6d62013-01-10 00:34:08 -08001893 struct device_node *np = pdev->dev.of_node;
Kuninori Morimotofd974e52012-12-27 19:15:08 -08001894 struct sh_fsi_platform_info info;
Kuninori Morimoto9e7b6d62013-01-10 00:34:08 -08001895 const struct fsi_core *core;
Kuninori Morimoto40f91182012-11-16 01:16:22 -08001896 struct fsi_priv *fsi;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001897 struct resource *res;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001898 unsigned int irq;
1899 int ret;
1900
Kuninori Morimotofd974e52012-12-27 19:15:08 -08001901 memset(&info, 0, sizeof(info));
Kuninori Morimoto943fdad2012-11-16 01:16:52 -08001902
Kuninori Morimoto9e7b6d62013-01-10 00:34:08 -08001903 core = NULL;
1904 if (np) {
1905 const struct of_device_id *of_id;
1906
1907 of_id = of_match_device(fsi_of_match, &pdev->dev);
1908 if (of_id) {
1909 core = of_id->data;
1910 fsi_of_parse("fsia", np, &info.port_a, &pdev->dev);
1911 fsi_of_parse("fsib", np, &info.port_b, &pdev->dev);
1912 }
1913 } else {
1914 const struct platform_device_id *id_entry = pdev->id_entry;
1915 if (id_entry)
1916 core = (struct fsi_core *)id_entry->driver_data;
1917
1918 if (pdev->dev.platform_data)
1919 memcpy(&info, pdev->dev.platform_data, sizeof(info));
1920 }
1921
1922 if (!core) {
Kuninori Morimotocc780d32010-03-25 19:15:53 +09001923 dev_err(&pdev->dev, "unknown fsi device\n");
1924 return -ENODEV;
1925 }
1926
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001927 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1928 irq = platform_get_irq(pdev, 0);
Uwe Kleine-Königb6aa1792009-12-16 17:10:09 +01001929 if (!res || (int)irq <= 0) {
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001930 dev_err(&pdev->dev, "Not enough FSI platform resources.\n");
Kuninori Morimoto6ac42622012-09-10 02:14:31 -07001931 return -ENODEV;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001932 }
1933
Kuninori Morimoto6ac42622012-09-10 02:14:31 -07001934 master = devm_kzalloc(&pdev->dev, sizeof(*master), GFP_KERNEL);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001935 if (!master) {
1936 dev_err(&pdev->dev, "Could not allocate master\n");
Kuninori Morimoto6ac42622012-09-10 02:14:31 -07001937 return -ENOMEM;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001938 }
1939
Kuninori Morimoto6ac42622012-09-10 02:14:31 -07001940 master->base = devm_ioremap_nocache(&pdev->dev,
1941 res->start, resource_size(res));
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001942 if (!master->base) {
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001943 dev_err(&pdev->dev, "Unable to ioremap FSI registers.\n");
Kuninori Morimoto6ac42622012-09-10 02:14:31 -07001944 return -ENXIO;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001945 }
1946
Kuninori Morimoto3bc28072010-07-29 16:48:32 +09001947 /* master setting */
Kuninori Morimoto9e7b6d62013-01-10 00:34:08 -08001948 master->core = core;
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +09001949 spin_lock_init(&master->lock);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001950
Kuninori Morimoto3bc28072010-07-29 16:48:32 +09001951 /* FSI A setting */
Kuninori Morimoto40f91182012-11-16 01:16:22 -08001952 fsi = &master->fsia;
1953 fsi->base = master->base;
1954 fsi->master = master;
Kuninori Morimotofd974e52012-12-27 19:15:08 -08001955 fsi_port_info_init(fsi, &info.port_a);
1956 fsi_handler_init(fsi, &info.port_a);
Kuninori Morimoto40f91182012-11-16 01:16:22 -08001957 ret = fsi_stream_probe(fsi, &pdev->dev);
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001958 if (ret < 0) {
1959 dev_err(&pdev->dev, "FSIA stream probe failed\n");
Kuninori Morimoto6ac42622012-09-10 02:14:31 -07001960 return ret;
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001961 }
Kuninori Morimoto3bc28072010-07-29 16:48:32 +09001962
1963 /* FSI B setting */
Kuninori Morimoto40f91182012-11-16 01:16:22 -08001964 fsi = &master->fsib;
1965 fsi->base = master->base + 0x40;
1966 fsi->master = master;
Kuninori Morimotofd974e52012-12-27 19:15:08 -08001967 fsi_port_info_init(fsi, &info.port_b);
1968 fsi_handler_init(fsi, &info.port_b);
Kuninori Morimoto40f91182012-11-16 01:16:22 -08001969 ret = fsi_stream_probe(fsi, &pdev->dev);
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001970 if (ret < 0) {
1971 dev_err(&pdev->dev, "FSIB stream probe failed\n");
1972 goto exit_fsia;
1973 }
Kuninori Morimoto3bc28072010-07-29 16:48:32 +09001974
Kuninori Morimoto785d1c42009-11-30 20:24:48 +09001975 pm_runtime_enable(&pdev->dev);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001976 dev_set_drvdata(&pdev->dev, master);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001977
Kuninori Morimoto1ddd8282012-10-02 23:22:57 -07001978 ret = devm_request_irq(&pdev->dev, irq, &fsi_interrupt, 0,
Kuninori Morimoto9e7b6d62013-01-10 00:34:08 -08001979 dev_name(&pdev->dev), master);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001980 if (ret) {
1981 dev_err(&pdev->dev, "irq request err\n");
Kuninori Morimoto5e973132012-02-03 00:55:55 -08001982 goto exit_fsib;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001983 }
1984
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001985 ret = snd_soc_register_platform(&pdev->dev, &fsi_soc_platform);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001986 if (ret < 0) {
1987 dev_err(&pdev->dev, "cannot snd soc register\n");
Kuninori Morimoto1ddd8282012-10-02 23:22:57 -07001988 goto exit_fsib;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001989 }
1990
Kuninori Morimotoda4f2f92013-03-14 00:19:20 -07001991 ret = snd_soc_register_component(&pdev->dev, &fsi_soc_component,
1992 fsi_soc_dai, ARRAY_SIZE(fsi_soc_dai));
Kuninori Morimoto0b5ec872011-04-08 15:09:02 +09001993 if (ret < 0) {
Kuninori Morimotoda4f2f92013-03-14 00:19:20 -07001994 dev_err(&pdev->dev, "cannot snd component register\n");
Kuninori Morimoto0b5ec872011-04-08 15:09:02 +09001995 goto exit_snd_soc;
1996 }
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001997
Kuninori Morimoto0b5ec872011-04-08 15:09:02 +09001998 return ret;
1999
2000exit_snd_soc:
2001 snd_soc_unregister_platform(&pdev->dev);
Kuninori Morimoto5e973132012-02-03 00:55:55 -08002002exit_fsib:
Kuninori Morimotoc35e0052012-09-10 02:13:52 -07002003 pm_runtime_disable(&pdev->dev);
Kuninori Morimoto5e973132012-02-03 00:55:55 -08002004 fsi_stream_remove(&master->fsib);
2005exit_fsia:
2006 fsi_stream_remove(&master->fsia);
Kuninori Morimoto6ac42622012-09-10 02:14:31 -07002007
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09002008 return ret;
2009}
2010
2011static int fsi_remove(struct platform_device *pdev)
2012{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +09002013 struct fsi_master *master;
2014
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002015 master = dev_get_drvdata(&pdev->dev);
Kuninori Morimoto71f6e062009-12-02 15:11:08 +09002016
Kuninori Morimoto785d1c42009-11-30 20:24:48 +09002017 pm_runtime_disable(&pdev->dev);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09002018
Kuninori Morimotoda4f2f92013-03-14 00:19:20 -07002019 snd_soc_unregister_component(&pdev->dev);
Kuninori Morimotod985f272011-04-08 15:09:25 +09002020 snd_soc_unregister_platform(&pdev->dev);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09002021
Kuninori Morimoto5e973132012-02-03 00:55:55 -08002022 fsi_stream_remove(&master->fsia);
2023 fsi_stream_remove(&master->fsib);
2024
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09002025 return 0;
2026}
2027
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09002028static void __fsi_suspend(struct fsi_priv *fsi,
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08002029 struct fsi_stream *io,
Kuninori Morimoto4f56cde2011-05-23 20:46:18 +09002030 struct device *dev)
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09002031{
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08002032 if (!fsi_stream_is_working(fsi, io))
Kuninori Morimotocda828c2011-05-23 20:46:35 +09002033 return;
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09002034
Kuninori Morimoto180346e2012-02-03 00:57:25 -08002035 fsi_stream_stop(fsi, io);
Kuninori Morimoto41bba152012-02-03 00:51:53 -08002036 fsi_hw_shutdown(fsi, dev);
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09002037}
2038
2039static void __fsi_resume(struct fsi_priv *fsi,
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08002040 struct fsi_stream *io,
Kuninori Morimoto4f56cde2011-05-23 20:46:18 +09002041 struct device *dev)
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09002042{
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08002043 if (!fsi_stream_is_working(fsi, io))
Kuninori Morimotocda828c2011-05-23 20:46:35 +09002044 return;
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09002045
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08002046 fsi_hw_startup(fsi, io, dev);
Kuninori Morimoto180346e2012-02-03 00:57:25 -08002047 fsi_stream_start(fsi, io);
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09002048}
2049
2050static int fsi_suspend(struct device *dev)
2051{
2052 struct fsi_master *master = dev_get_drvdata(dev);
Kuninori Morimotocda828c2011-05-23 20:46:35 +09002053 struct fsi_priv *fsia = &master->fsia;
2054 struct fsi_priv *fsib = &master->fsib;
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09002055
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08002056 __fsi_suspend(fsia, &fsia->playback, dev);
2057 __fsi_suspend(fsia, &fsia->capture, dev);
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09002058
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08002059 __fsi_suspend(fsib, &fsib->playback, dev);
2060 __fsi_suspend(fsib, &fsib->capture, dev);
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09002061
2062 return 0;
2063}
2064
2065static int fsi_resume(struct device *dev)
2066{
2067 struct fsi_master *master = dev_get_drvdata(dev);
Kuninori Morimotocda828c2011-05-23 20:46:35 +09002068 struct fsi_priv *fsia = &master->fsia;
2069 struct fsi_priv *fsib = &master->fsib;
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09002070
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08002071 __fsi_resume(fsia, &fsia->playback, dev);
2072 __fsi_resume(fsia, &fsia->capture, dev);
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09002073
Kuninori Morimoto938e2a82012-02-03 00:56:57 -08002074 __fsi_resume(fsib, &fsib->playback, dev);
2075 __fsi_resume(fsib, &fsib->capture, dev);
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09002076
2077 return 0;
2078}
2079
Kuninori Morimoto785d1c42009-11-30 20:24:48 +09002080static struct dev_pm_ops fsi_pm_ops = {
Kuninori Morimoto106c79e2011-04-21 10:33:47 +09002081 .suspend = fsi_suspend,
2082 .resume = fsi_resume,
Kuninori Morimoto785d1c42009-11-30 20:24:48 +09002083};
2084
Kuninori Morimoto73b92c12010-07-13 12:13:04 +09002085static struct fsi_core fsi1_core = {
2086 .ver = 1,
2087
2088 /* Interrupt */
Kuninori Morimotocc780d32010-03-25 19:15:53 +09002089 .int_st = INT_ST,
2090 .iemsk = IEMSK,
2091 .imsk = IMSK,
2092};
2093
Kuninori Morimoto73b92c12010-07-13 12:13:04 +09002094static struct fsi_core fsi2_core = {
2095 .ver = 2,
2096
2097 /* Interrupt */
Kuninori Morimotocc780d32010-03-25 19:15:53 +09002098 .int_st = CPU_INT_ST,
2099 .iemsk = CPU_IEMSK,
2100 .imsk = CPU_IMSK,
Kuninori Morimoto2b0e7302010-12-03 17:37:44 +09002101 .a_mclk = A_MST_CTLR,
2102 .b_mclk = B_MST_CTLR,
Kuninori Morimotocc780d32010-03-25 19:15:53 +09002103};
2104
Thierry Redinge43fc6a2013-01-16 12:09:45 +01002105static struct of_device_id fsi_of_match[] = {
Kuninori Morimoto9e7b6d62013-01-10 00:34:08 -08002106 { .compatible = "renesas,sh_fsi", .data = &fsi1_core},
2107 { .compatible = "renesas,sh_fsi2", .data = &fsi2_core},
2108 {},
2109};
2110MODULE_DEVICE_TABLE(of, fsi_of_match);
2111
Kuninori Morimotocc780d32010-03-25 19:15:53 +09002112static struct platform_device_id fsi_id_table[] = {
Kuninori Morimoto73b92c12010-07-13 12:13:04 +09002113 { "sh_fsi", (kernel_ulong_t)&fsi1_core },
2114 { "sh_fsi2", (kernel_ulong_t)&fsi2_core },
Guennadi Liakhovetski05c69452010-10-05 17:54:28 +02002115 {},
Kuninori Morimotocc780d32010-03-25 19:15:53 +09002116};
Dzianis Kahanovichd85a6d72010-09-17 16:42:05 +03002117MODULE_DEVICE_TABLE(platform, fsi_id_table);
Kuninori Morimotocc780d32010-03-25 19:15:53 +09002118
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09002119static struct platform_driver fsi_driver = {
2120 .driver = {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002121 .name = "fsi-pcm-audio",
Kuninori Morimoto785d1c42009-11-30 20:24:48 +09002122 .pm = &fsi_pm_ops,
Kuninori Morimoto9e7b6d62013-01-10 00:34:08 -08002123 .of_match_table = fsi_of_match,
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09002124 },
2125 .probe = fsi_probe,
2126 .remove = fsi_remove,
Kuninori Morimotocc780d32010-03-25 19:15:53 +09002127 .id_table = fsi_id_table,
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09002128};
2129
Axel Lincb5e8732011-11-25 10:15:07 +08002130module_platform_driver(fsi_driver);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09002131
2132MODULE_LICENSE("GPL");
2133MODULE_DESCRIPTION("SuperH onchip FSI audio driver");
2134MODULE_AUTHOR("Kuninori Morimoto <morimoto.kuninori@renesas.com>");
Guennadi Liakhovetskib3c27b52011-04-15 20:17:34 +02002135MODULE_ALIAS("platform:fsi-pcm-audio");