blob: ae888651a77a29b5cd5fbcc41a21ccbd934b1120 [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
15#include <linux/init.h>
16#include <linux/module.h>
17#include <linux/platform_device.h>
18#include <linux/delay.h>
19#include <linux/list.h>
Kuninori Morimoto785d1c42009-11-30 20:24:48 +090020#include <linux/pm_runtime.h>
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090021#include <linux/io.h>
22#include <sound/core.h>
23#include <sound/pcm.h>
24#include <sound/initval.h>
25#include <sound/soc.h>
26#include <sound/pcm_params.h>
27#include <sound/sh_fsi.h>
28#include <asm/atomic.h>
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090029
30#define DO_FMT 0x0000
31#define DOFF_CTL 0x0004
32#define DOFF_ST 0x0008
33#define DI_FMT 0x000C
34#define DIFF_CTL 0x0010
35#define DIFF_ST 0x0014
36#define CKG1 0x0018
37#define CKG2 0x001C
38#define DIDT 0x0020
39#define DODT 0x0024
40#define MUTE_ST 0x0028
41#define REG_END MUTE_ST
42
43#define INT_ST 0x0200
44#define IEMSK 0x0204
45#define IMSK 0x0208
46#define MUTE 0x020C
47#define CLK_RST 0x0210
48#define SOFT_RST 0x0214
Kuninori Morimoto4a942b42010-03-25 19:15:51 +090049#define FIFO_SZ 0x0218
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090050#define MREG_START INT_ST
Kuninori Morimoto4a942b42010-03-25 19:15:51 +090051#define MREG_END FIFO_SZ
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090052
53/* DO_FMT */
54/* DI_FMT */
55#define CR_FMT(param) ((param) << 4)
56# define CR_MONO 0x0
57# define CR_MONO_D 0x1
58# define CR_PCM 0x2
59# define CR_I2S 0x3
60# define CR_TDM 0x4
61# define CR_TDM_D 0x5
62
63/* DOFF_CTL */
64/* DIFF_CTL */
65#define IRQ_HALF 0x00100000
66#define FIFO_CLR 0x00000001
67
68/* DOFF_ST */
69#define ERR_OVER 0x00000010
70#define ERR_UNDER 0x00000001
Kuninori Morimoto59c3b002009-12-28 14:09:16 +090071#define ST_ERR (ERR_OVER | ERR_UNDER)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090072
73/* CLK_RST */
74#define B_CLK 0x00000010
75#define A_CLK 0x00000001
76
77/* INT_ST */
78#define INT_B_IN (1 << 12)
79#define INT_B_OUT (1 << 8)
80#define INT_A_IN (1 << 4)
81#define INT_A_OUT (1 << 0)
82
Kuninori Morimotofeb58cf2010-03-24 15:27:24 +090083/* SOFT_RST */
84#define PBSR (1 << 12) /* Port B Software Reset */
85#define PASR (1 << 8) /* Port A Software Reset */
86#define IR (1 << 4) /* Interrupt Reset */
87#define FSISR (1 << 0) /* Software Reset */
88
Kuninori Morimoto4a942b42010-03-25 19:15:51 +090089/* FIFO_SZ */
90#define OUT_SZ_MASK 0x7
91#define BO_SZ_SHIFT 8
92#define AO_SZ_SHIFT 0
93
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +090094#define FSI_RATES SNDRV_PCM_RATE_8000_96000
95
96#define FSI_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE)
97
98/************************************************************************
99
100
101 struct
102
103
104************************************************************************/
105struct fsi_priv {
106 void __iomem *base;
107 struct snd_pcm_substream *substream;
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900108 struct fsi_master *master;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900109
110 int fifo_max;
111 int chan;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900112
113 int byte_offset;
114 int period_len;
115 int buffer_len;
116 int periods;
117};
118
119struct fsi_master {
120 void __iomem *base;
121 int irq;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900122 struct fsi_priv fsia;
123 struct fsi_priv fsib;
124 struct sh_fsi_platform_info *info;
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900125 spinlock_t lock;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900126};
127
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900128/************************************************************************
129
130
131 basic read write function
132
133
134************************************************************************/
Guennadi Liakhovetski0f69d972010-02-03 17:37:23 +0100135static void __fsi_reg_write(u32 reg, u32 data)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900136{
137 /* valid data area is 24bit */
138 data &= 0x00ffffff;
139
Guennadi Liakhovetski0f69d972010-02-03 17:37:23 +0100140 __raw_writel(data, reg);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900141}
142
143static u32 __fsi_reg_read(u32 reg)
144{
Guennadi Liakhovetski0f69d972010-02-03 17:37:23 +0100145 return __raw_readl(reg);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900146}
147
Guennadi Liakhovetski0f69d972010-02-03 17:37:23 +0100148static void __fsi_reg_mask_set(u32 reg, u32 mask, u32 data)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900149{
150 u32 val = __fsi_reg_read(reg);
151
152 val &= ~mask;
153 val |= data & mask;
154
Guennadi Liakhovetski0f69d972010-02-03 17:37:23 +0100155 __fsi_reg_write(reg, val);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900156}
157
Guennadi Liakhovetski0f69d972010-02-03 17:37:23 +0100158static void fsi_reg_write(struct fsi_priv *fsi, u32 reg, u32 data)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900159{
160 if (reg > REG_END)
Guennadi Liakhovetski0f69d972010-02-03 17:37:23 +0100161 return;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900162
Guennadi Liakhovetski0f69d972010-02-03 17:37:23 +0100163 __fsi_reg_write((u32)(fsi->base + reg), data);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900164}
165
166static u32 fsi_reg_read(struct fsi_priv *fsi, u32 reg)
167{
168 if (reg > REG_END)
169 return 0;
170
171 return __fsi_reg_read((u32)(fsi->base + reg));
172}
173
Guennadi Liakhovetski0f69d972010-02-03 17:37:23 +0100174static void fsi_reg_mask_set(struct fsi_priv *fsi, u32 reg, u32 mask, u32 data)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900175{
176 if (reg > REG_END)
Guennadi Liakhovetski0f69d972010-02-03 17:37:23 +0100177 return;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900178
Guennadi Liakhovetski0f69d972010-02-03 17:37:23 +0100179 __fsi_reg_mask_set((u32)(fsi->base + reg), mask, data);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900180}
181
Guennadi Liakhovetski0f69d972010-02-03 17:37:23 +0100182static void fsi_master_write(struct fsi_master *master, u32 reg, u32 data)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900183{
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900184 unsigned long flags;
185
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900186 if ((reg < MREG_START) ||
187 (reg > MREG_END))
Guennadi Liakhovetski0f69d972010-02-03 17:37:23 +0100188 return;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900189
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900190 spin_lock_irqsave(&master->lock, flags);
Guennadi Liakhovetski0f69d972010-02-03 17:37:23 +0100191 __fsi_reg_write((u32)(master->base + reg), data);
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900192 spin_unlock_irqrestore(&master->lock, flags);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900193}
194
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900195static u32 fsi_master_read(struct fsi_master *master, u32 reg)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900196{
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900197 u32 ret;
198 unsigned long flags;
199
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900200 if ((reg < MREG_START) ||
201 (reg > MREG_END))
202 return 0;
203
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900204 spin_lock_irqsave(&master->lock, flags);
205 ret = __fsi_reg_read((u32)(master->base + reg));
206 spin_unlock_irqrestore(&master->lock, flags);
207
208 return ret;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900209}
210
Guennadi Liakhovetski0f69d972010-02-03 17:37:23 +0100211static void fsi_master_mask_set(struct fsi_master *master,
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900212 u32 reg, u32 mask, u32 data)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900213{
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900214 unsigned long flags;
215
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900216 if ((reg < MREG_START) ||
217 (reg > MREG_END))
Guennadi Liakhovetski0f69d972010-02-03 17:37:23 +0100218 return;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900219
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900220 spin_lock_irqsave(&master->lock, flags);
Guennadi Liakhovetski0f69d972010-02-03 17:37:23 +0100221 __fsi_reg_mask_set((u32)(master->base + reg), mask, data);
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900222 spin_unlock_irqrestore(&master->lock, flags);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900223}
224
225/************************************************************************
226
227
228 basic function
229
230
231************************************************************************/
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900232static struct fsi_master *fsi_get_master(struct fsi_priv *fsi)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900233{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900234 return fsi->master;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900235}
236
237static int fsi_is_port_a(struct fsi_priv *fsi)
238{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900239 return fsi->master->base == fsi->base;
240}
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900241
Kuninori Morimoto142e8172009-12-28 14:09:11 +0900242static struct snd_soc_dai *fsi_get_dai(struct snd_pcm_substream *substream)
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900243{
244 struct snd_soc_pcm_runtime *rtd = substream->private_data;
245 struct snd_soc_dai_link *machine = rtd->dai;
Kuninori Morimoto142e8172009-12-28 14:09:11 +0900246
247 return machine->cpu_dai;
248}
249
250static struct fsi_priv *fsi_get_priv(struct snd_pcm_substream *substream)
251{
252 struct snd_soc_dai *dai = fsi_get_dai(substream);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900253
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900254 return dai->private_data;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900255}
256
257static u32 fsi_get_info_flags(struct fsi_priv *fsi)
258{
259 int is_porta = fsi_is_port_a(fsi);
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900260 struct fsi_master *master = fsi_get_master(fsi);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900261
262 return is_porta ? master->info->porta_flags :
263 master->info->portb_flags;
264}
265
266static int fsi_is_master_mode(struct fsi_priv *fsi, int is_play)
267{
268 u32 mode;
269 u32 flags = fsi_get_info_flags(fsi);
270
271 mode = is_play ? SH_FSI_OUT_SLAVE_MODE : SH_FSI_IN_SLAVE_MODE;
272
273 /* return
274 * 1 : master mode
275 * 0 : slave mode
276 */
277
278 return (mode & flags) != mode;
279}
280
281static u32 fsi_port_ab_io_bit(struct fsi_priv *fsi, int is_play)
282{
283 int is_porta = fsi_is_port_a(fsi);
284 u32 data;
285
286 if (is_porta)
287 data = is_play ? (1 << 0) : (1 << 4);
288 else
289 data = is_play ? (1 << 8) : (1 << 12);
290
291 return data;
292}
293
294static void fsi_stream_push(struct fsi_priv *fsi,
295 struct snd_pcm_substream *substream,
296 u32 buffer_len,
297 u32 period_len)
298{
299 fsi->substream = substream;
300 fsi->buffer_len = buffer_len;
301 fsi->period_len = period_len;
302 fsi->byte_offset = 0;
303 fsi->periods = 0;
304}
305
306static void fsi_stream_pop(struct fsi_priv *fsi)
307{
308 fsi->substream = NULL;
309 fsi->buffer_len = 0;
310 fsi->period_len = 0;
311 fsi->byte_offset = 0;
312 fsi->periods = 0;
313}
314
315static int fsi_get_fifo_residue(struct fsi_priv *fsi, int is_play)
316{
317 u32 status;
318 u32 reg = is_play ? DOFF_ST : DIFF_ST;
319 int residue;
320
321 status = fsi_reg_read(fsi, reg);
322 residue = 0x1ff & (status >> 8);
323 residue *= fsi->chan;
324
325 return residue;
326}
327
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900328/************************************************************************
329
330
Kuninori Morimoto10ea76c2010-03-23 11:47:54 +0900331 irq function
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900332
333
334************************************************************************/
335static void fsi_irq_enable(struct fsi_priv *fsi, int is_play)
336{
337 u32 data = fsi_port_ab_io_bit(fsi, is_play);
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900338 struct fsi_master *master = fsi_get_master(fsi);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900339
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900340 fsi_master_mask_set(master, IMSK, data, data);
341 fsi_master_mask_set(master, IEMSK, data, data);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900342}
343
344static void fsi_irq_disable(struct fsi_priv *fsi, int is_play)
345{
346 u32 data = fsi_port_ab_io_bit(fsi, is_play);
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900347 struct fsi_master *master = fsi_get_master(fsi);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900348
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900349 fsi_master_mask_set(master, IMSK, data, 0);
350 fsi_master_mask_set(master, IEMSK, data, 0);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900351}
352
Kuninori Morimoto10ea76c2010-03-23 11:47:54 +0900353static u32 fsi_irq_get_status(struct fsi_master *master)
354{
355 return fsi_master_read(master, INT_ST);
356}
357
358static void fsi_irq_clear_all_status(struct fsi_master *master)
359{
360 fsi_master_write(master, INT_ST, 0x0000000);
361}
362
363static void fsi_irq_clear_status(struct fsi_priv *fsi)
364{
365 u32 data = 0;
366 struct fsi_master *master = fsi_get_master(fsi);
367
368 data |= fsi_port_ab_io_bit(fsi, 0);
369 data |= fsi_port_ab_io_bit(fsi, 1);
370
371 /* clear interrupt factor */
372 fsi_master_mask_set(master, INT_ST, data, 0);
373}
374
375/************************************************************************
376
377
378 ctrl function
379
380
381************************************************************************/
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900382static void fsi_clk_ctrl(struct fsi_priv *fsi, int enable)
383{
384 u32 val = fsi_is_port_a(fsi) ? (1 << 0) : (1 << 4);
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900385 struct fsi_master *master = fsi_get_master(fsi);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900386
387 if (enable)
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900388 fsi_master_mask_set(master, CLK_RST, val, val);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900389 else
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900390 fsi_master_mask_set(master, CLK_RST, val, 0);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900391}
392
Kuninori Morimoto4a942b42010-03-25 19:15:51 +0900393static void fsi_fifo_init(struct fsi_priv *fsi,
394 int is_play,
395 struct snd_soc_dai *dai)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900396{
Kuninori Morimoto4a942b42010-03-25 19:15:51 +0900397 struct fsi_master *master = fsi_get_master(fsi);
398 u32 ctrl, shift, i;
399
400 /* get on-chip RAM capacity */
401 shift = fsi_master_read(master, FIFO_SZ);
402 shift >>= fsi_is_port_a(fsi) ? AO_SZ_SHIFT : BO_SZ_SHIFT;
403 shift &= OUT_SZ_MASK;
404 fsi->fifo_max = 256 << shift;
405 dev_dbg(dai->dev, "fifo = %d words\n", fsi->fifo_max);
406
407 /*
408 * The maximum number of sample data varies depending
409 * on the number of channels selected for the format.
410 *
411 * FIFOs are used in 4-channel units in 3-channel mode
412 * and in 8-channel units in 5- to 7-channel mode
413 * meaning that more FIFOs than the required size of DPRAM
414 * are used.
415 *
416 * ex) if 256 words of DP-RAM is connected
417 * 1 channel: 256 (256 x 1 = 256)
418 * 2 channels: 128 (128 x 2 = 256)
419 * 3 channels: 64 ( 64 x 3 = 192)
420 * 4 channels: 64 ( 64 x 4 = 256)
421 * 5 channels: 32 ( 32 x 5 = 160)
422 * 6 channels: 32 ( 32 x 6 = 192)
423 * 7 channels: 32 ( 32 x 7 = 224)
424 * 8 channels: 32 ( 32 x 8 = 256)
425 */
426 for (i = 1; i < fsi->chan; i <<= 1)
427 fsi->fifo_max >>= 1;
428 dev_dbg(dai->dev, "%d channel %d store\n", fsi->chan, fsi->fifo_max);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900429
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900430 ctrl = is_play ? DOFF_CTL : DIFF_CTL;
431
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900432 /* set interrupt generation factor */
433 fsi_reg_write(fsi, ctrl, IRQ_HALF);
434
435 /* clear FIFO */
436 fsi_reg_mask_set(fsi, ctrl, FIFO_CLR, FIFO_CLR);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900437}
438
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900439static void fsi_soft_all_reset(struct fsi_master *master)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900440{
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900441 /* port AB reset */
Kuninori Morimotofeb58cf2010-03-24 15:27:24 +0900442 fsi_master_mask_set(master, SOFT_RST, PASR | PBSR, 0);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900443 mdelay(10);
444
445 /* soft reset */
Kuninori Morimotofeb58cf2010-03-24 15:27:24 +0900446 fsi_master_mask_set(master, SOFT_RST, FSISR, 0);
447 fsi_master_mask_set(master, SOFT_RST, FSISR, FSISR);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900448 mdelay(10);
449}
450
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900451/* playback interrupt */
Kuninori Morimoto47fc9a02010-02-22 16:41:57 +0900452static int fsi_data_push(struct fsi_priv *fsi, int startup)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900453{
454 struct snd_pcm_runtime *runtime;
455 struct snd_pcm_substream *substream = NULL;
Kuninori Morimoto59c3b002009-12-28 14:09:16 +0900456 u32 status;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900457 int send;
458 int fifo_free;
459 int width;
Kuninori Morimoto9ddc9aa2009-10-30 12:02:39 +0900460 u8 *start;
Kuninori Morimoto47fc9a02010-02-22 16:41:57 +0900461 int i, over_period;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900462
463 if (!fsi ||
464 !fsi->substream ||
465 !fsi->substream->runtime)
466 return -EINVAL;
467
Kuninori Morimoto1c418d12009-12-28 14:09:05 +0900468 over_period = 0;
469 substream = fsi->substream;
470 runtime = substream->runtime;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900471
472 /* FSI FIFO has limit.
473 * So, this driver can not send periods data at a time
474 */
475 if (fsi->byte_offset >=
476 fsi->period_len * (fsi->periods + 1)) {
477
Kuninori Morimoto1c418d12009-12-28 14:09:05 +0900478 over_period = 1;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900479 fsi->periods = (fsi->periods + 1) % runtime->periods;
480
481 if (0 == fsi->periods)
482 fsi->byte_offset = 0;
483 }
484
485 /* get 1 channel data width */
486 width = frames_to_bytes(runtime, 1) / fsi->chan;
487
488 /* get send size for alsa */
489 send = (fsi->buffer_len - fsi->byte_offset) / width;
490
491 /* get FIFO free size */
492 fifo_free = (fsi->fifo_max * fsi->chan) - fsi_get_fifo_residue(fsi, 1);
493
494 /* size check */
495 if (fifo_free < send)
496 send = fifo_free;
497
Kuninori Morimoto9ddc9aa2009-10-30 12:02:39 +0900498 start = runtime->dma_area;
499 start += fsi->byte_offset;
500
501 switch (width) {
502 case 2:
503 for (i = 0; i < send; i++)
504 fsi_reg_write(fsi, DODT,
505 ((u32)*((u16 *)start + i) << 8));
506 break;
507 case 4:
508 for (i = 0; i < send; i++)
509 fsi_reg_write(fsi, DODT, *((u32 *)start + i));
510 break;
511 default:
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900512 return -EINVAL;
Kuninori Morimoto9ddc9aa2009-10-30 12:02:39 +0900513 }
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900514
515 fsi->byte_offset += send * width;
516
Kuninori Morimoto59c3b002009-12-28 14:09:16 +0900517 status = fsi_reg_read(fsi, DOFF_ST);
Kuninori Morimoto47fc9a02010-02-22 16:41:57 +0900518 if (!startup) {
Kuninori Morimoto59c3b002009-12-28 14:09:16 +0900519 struct snd_soc_dai *dai = fsi_get_dai(substream);
Kuninori Morimoto47fc9a02010-02-22 16:41:57 +0900520
521 if (status & ERR_OVER)
522 dev_err(dai->dev, "over run\n");
523 if (status & ERR_UNDER)
524 dev_err(dai->dev, "under run\n");
Kuninori Morimoto59c3b002009-12-28 14:09:16 +0900525 }
Kuninori Morimoto47fc9a02010-02-22 16:41:57 +0900526 fsi_reg_write(fsi, DOFF_ST, 0);
Kuninori Morimoto59c3b002009-12-28 14:09:16 +0900527
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900528 fsi_irq_enable(fsi, 1);
529
Kuninori Morimoto1c418d12009-12-28 14:09:05 +0900530 if (over_period)
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900531 snd_pcm_period_elapsed(substream);
532
Kuninori Morimoto47fc9a02010-02-22 16:41:57 +0900533 return 0;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900534}
535
Kuninori Morimoto47fc9a02010-02-22 16:41:57 +0900536static int fsi_data_pop(struct fsi_priv *fsi, int startup)
Kuninori Morimoto07102f32009-10-30 12:02:44 +0900537{
538 struct snd_pcm_runtime *runtime;
539 struct snd_pcm_substream *substream = NULL;
Kuninori Morimoto59c3b002009-12-28 14:09:16 +0900540 u32 status;
Kuninori Morimoto07102f32009-10-30 12:02:44 +0900541 int free;
542 int fifo_fill;
543 int width;
544 u8 *start;
Kuninori Morimoto47fc9a02010-02-22 16:41:57 +0900545 int i, over_period;
Kuninori Morimoto07102f32009-10-30 12:02:44 +0900546
547 if (!fsi ||
548 !fsi->substream ||
549 !fsi->substream->runtime)
550 return -EINVAL;
551
Kuninori Morimoto1c418d12009-12-28 14:09:05 +0900552 over_period = 0;
553 substream = fsi->substream;
554 runtime = substream->runtime;
Kuninori Morimoto07102f32009-10-30 12:02:44 +0900555
556 /* FSI FIFO has limit.
557 * So, this driver can not send periods data at a time
558 */
559 if (fsi->byte_offset >=
560 fsi->period_len * (fsi->periods + 1)) {
561
Kuninori Morimoto1c418d12009-12-28 14:09:05 +0900562 over_period = 1;
Kuninori Morimoto07102f32009-10-30 12:02:44 +0900563 fsi->periods = (fsi->periods + 1) % runtime->periods;
564
565 if (0 == fsi->periods)
566 fsi->byte_offset = 0;
567 }
568
569 /* get 1 channel data width */
570 width = frames_to_bytes(runtime, 1) / fsi->chan;
571
572 /* get free space for alsa */
573 free = (fsi->buffer_len - fsi->byte_offset) / width;
574
575 /* get recv size */
576 fifo_fill = fsi_get_fifo_residue(fsi, 0);
577
578 if (free < fifo_fill)
579 fifo_fill = free;
580
581 start = runtime->dma_area;
582 start += fsi->byte_offset;
583
584 switch (width) {
585 case 2:
586 for (i = 0; i < fifo_fill; i++)
587 *((u16 *)start + i) =
588 (u16)(fsi_reg_read(fsi, DIDT) >> 8);
589 break;
590 case 4:
591 for (i = 0; i < fifo_fill; i++)
592 *((u32 *)start + i) = fsi_reg_read(fsi, DIDT);
593 break;
594 default:
595 return -EINVAL;
596 }
597
598 fsi->byte_offset += fifo_fill * width;
599
Kuninori Morimoto59c3b002009-12-28 14:09:16 +0900600 status = fsi_reg_read(fsi, DIFF_ST);
Kuninori Morimoto47fc9a02010-02-22 16:41:57 +0900601 if (!startup) {
Kuninori Morimoto59c3b002009-12-28 14:09:16 +0900602 struct snd_soc_dai *dai = fsi_get_dai(substream);
Kuninori Morimoto47fc9a02010-02-22 16:41:57 +0900603
604 if (status & ERR_OVER)
605 dev_err(dai->dev, "over run\n");
606 if (status & ERR_UNDER)
607 dev_err(dai->dev, "under run\n");
Kuninori Morimoto59c3b002009-12-28 14:09:16 +0900608 }
Kuninori Morimoto47fc9a02010-02-22 16:41:57 +0900609 fsi_reg_write(fsi, DIFF_ST, 0);
Kuninori Morimoto59c3b002009-12-28 14:09:16 +0900610
Kuninori Morimoto07102f32009-10-30 12:02:44 +0900611 fsi_irq_enable(fsi, 0);
612
Kuninori Morimoto1c418d12009-12-28 14:09:05 +0900613 if (over_period)
Kuninori Morimoto07102f32009-10-30 12:02:44 +0900614 snd_pcm_period_elapsed(substream);
615
Kuninori Morimoto47fc9a02010-02-22 16:41:57 +0900616 return 0;
Kuninori Morimoto07102f32009-10-30 12:02:44 +0900617}
618
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900619static irqreturn_t fsi_interrupt(int irq, void *data)
620{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900621 struct fsi_master *master = data;
Kuninori Morimoto10ea76c2010-03-23 11:47:54 +0900622 u32 int_st = fsi_irq_get_status(master);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900623
624 /* clear irq status */
Kuninori Morimotofeb58cf2010-03-24 15:27:24 +0900625 fsi_master_mask_set(master, SOFT_RST, IR, 0);
626 fsi_master_mask_set(master, SOFT_RST, IR, IR);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900627
628 if (int_st & INT_A_OUT)
Kuninori Morimoto47fc9a02010-02-22 16:41:57 +0900629 fsi_data_push(&master->fsia, 0);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900630 if (int_st & INT_B_OUT)
Kuninori Morimoto47fc9a02010-02-22 16:41:57 +0900631 fsi_data_push(&master->fsib, 0);
Kuninori Morimoto07102f32009-10-30 12:02:44 +0900632 if (int_st & INT_A_IN)
Kuninori Morimoto47fc9a02010-02-22 16:41:57 +0900633 fsi_data_pop(&master->fsia, 0);
Kuninori Morimoto07102f32009-10-30 12:02:44 +0900634 if (int_st & INT_B_IN)
Kuninori Morimoto47fc9a02010-02-22 16:41:57 +0900635 fsi_data_pop(&master->fsib, 0);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900636
Kuninori Morimoto10ea76c2010-03-23 11:47:54 +0900637 fsi_irq_clear_all_status(master);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900638
639 return IRQ_HANDLED;
640}
641
642/************************************************************************
643
644
645 dai ops
646
647
648************************************************************************/
649static int fsi_dai_startup(struct snd_pcm_substream *substream,
650 struct snd_soc_dai *dai)
651{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900652 struct fsi_priv *fsi = fsi_get_priv(substream);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900653 const char *msg;
654 u32 flags = fsi_get_info_flags(fsi);
655 u32 fmt;
656 u32 reg;
657 u32 data;
658 int is_play = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
659 int is_master;
660 int ret = 0;
661
Kuninori Morimoto785d1c42009-11-30 20:24:48 +0900662 pm_runtime_get_sync(dai->dev);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900663
664 /* CKG1 */
665 data = is_play ? (1 << 0) : (1 << 4);
666 is_master = fsi_is_master_mode(fsi, is_play);
667 if (is_master)
668 fsi_reg_mask_set(fsi, CKG1, data, data);
669 else
670 fsi_reg_mask_set(fsi, CKG1, data, 0);
671
672 /* clock inversion (CKG2) */
673 data = 0;
674 switch (SH_FSI_INVERSION_MASK & flags) {
675 case SH_FSI_LRM_INV:
676 data = 1 << 12;
677 break;
678 case SH_FSI_BRM_INV:
679 data = 1 << 8;
680 break;
681 case SH_FSI_LRS_INV:
682 data = 1 << 4;
683 break;
684 case SH_FSI_BRS_INV:
685 data = 1 << 0;
686 break;
687 }
688 fsi_reg_write(fsi, CKG2, data);
689
690 /* do fmt, di fmt */
691 data = 0;
692 reg = is_play ? DO_FMT : DI_FMT;
693 fmt = is_play ? SH_FSI_GET_OFMT(flags) : SH_FSI_GET_IFMT(flags);
694 switch (fmt) {
695 case SH_FSI_FMT_MONO:
696 msg = "MONO";
697 data = CR_FMT(CR_MONO);
698 fsi->chan = 1;
699 break;
700 case SH_FSI_FMT_MONO_DELAY:
701 msg = "MONO Delay";
702 data = CR_FMT(CR_MONO_D);
703 fsi->chan = 1;
704 break;
705 case SH_FSI_FMT_PCM:
706 msg = "PCM";
707 data = CR_FMT(CR_PCM);
708 fsi->chan = 2;
709 break;
710 case SH_FSI_FMT_I2S:
711 msg = "I2S";
712 data = CR_FMT(CR_I2S);
713 fsi->chan = 2;
714 break;
715 case SH_FSI_FMT_TDM:
716 msg = "TDM";
717 data = CR_FMT(CR_TDM) | (fsi->chan - 1);
718 fsi->chan = is_play ?
719 SH_FSI_GET_CH_O(flags) : SH_FSI_GET_CH_I(flags);
720 break;
721 case SH_FSI_FMT_TDM_DELAY:
722 msg = "TDM Delay";
723 data = CR_FMT(CR_TDM_D) | (fsi->chan - 1);
724 fsi->chan = is_play ?
725 SH_FSI_GET_CH_O(flags) : SH_FSI_GET_CH_I(flags);
726 break;
727 default:
728 dev_err(dai->dev, "unknown format.\n");
729 return -EINVAL;
730 }
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900731 fsi_reg_write(fsi, reg, data);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900732
733 /*
734 * clear clk reset if master mode
735 */
736 if (is_master)
737 fsi_clk_ctrl(fsi, 1);
738
Kuninori Morimoto10ea76c2010-03-23 11:47:54 +0900739 /* irq clear */
740 fsi_irq_disable(fsi, is_play);
741 fsi_irq_clear_status(fsi);
742
743 /* fifo init */
Kuninori Morimoto4a942b42010-03-25 19:15:51 +0900744 fsi_fifo_init(fsi, is_play, dai);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900745
746 return ret;
747}
748
749static void fsi_dai_shutdown(struct snd_pcm_substream *substream,
750 struct snd_soc_dai *dai)
751{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900752 struct fsi_priv *fsi = fsi_get_priv(substream);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900753 int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
754
755 fsi_irq_disable(fsi, is_play);
756 fsi_clk_ctrl(fsi, 0);
757
Kuninori Morimoto785d1c42009-11-30 20:24:48 +0900758 pm_runtime_put_sync(dai->dev);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900759}
760
761static int fsi_dai_trigger(struct snd_pcm_substream *substream, int cmd,
762 struct snd_soc_dai *dai)
763{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900764 struct fsi_priv *fsi = fsi_get_priv(substream);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900765 struct snd_pcm_runtime *runtime = substream->runtime;
766 int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
767 int ret = 0;
768
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900769 switch (cmd) {
770 case SNDRV_PCM_TRIGGER_START:
771 fsi_stream_push(fsi, substream,
772 frames_to_bytes(runtime, runtime->buffer_size),
773 frames_to_bytes(runtime, runtime->period_size));
Kuninori Morimoto47fc9a02010-02-22 16:41:57 +0900774 ret = is_play ? fsi_data_push(fsi, 1) : fsi_data_pop(fsi, 1);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900775 break;
776 case SNDRV_PCM_TRIGGER_STOP:
777 fsi_irq_disable(fsi, is_play);
778 fsi_stream_pop(fsi);
779 break;
780 }
781
782 return ret;
783}
784
785static struct snd_soc_dai_ops fsi_dai_ops = {
786 .startup = fsi_dai_startup,
787 .shutdown = fsi_dai_shutdown,
788 .trigger = fsi_dai_trigger,
789};
790
791/************************************************************************
792
793
794 pcm ops
795
796
797************************************************************************/
798static struct snd_pcm_hardware fsi_pcm_hardware = {
799 .info = SNDRV_PCM_INFO_INTERLEAVED |
800 SNDRV_PCM_INFO_MMAP |
801 SNDRV_PCM_INFO_MMAP_VALID |
802 SNDRV_PCM_INFO_PAUSE,
803 .formats = FSI_FMTS,
804 .rates = FSI_RATES,
805 .rate_min = 8000,
806 .rate_max = 192000,
807 .channels_min = 1,
808 .channels_max = 2,
809 .buffer_bytes_max = 64 * 1024,
810 .period_bytes_min = 32,
811 .period_bytes_max = 8192,
812 .periods_min = 1,
813 .periods_max = 32,
814 .fifo_size = 256,
815};
816
817static int fsi_pcm_open(struct snd_pcm_substream *substream)
818{
819 struct snd_pcm_runtime *runtime = substream->runtime;
820 int ret = 0;
821
822 snd_soc_set_runtime_hwparams(substream, &fsi_pcm_hardware);
823
824 ret = snd_pcm_hw_constraint_integer(runtime,
825 SNDRV_PCM_HW_PARAM_PERIODS);
826
827 return ret;
828}
829
830static int fsi_hw_params(struct snd_pcm_substream *substream,
831 struct snd_pcm_hw_params *hw_params)
832{
833 return snd_pcm_lib_malloc_pages(substream,
834 params_buffer_bytes(hw_params));
835}
836
837static int fsi_hw_free(struct snd_pcm_substream *substream)
838{
839 return snd_pcm_lib_free_pages(substream);
840}
841
842static snd_pcm_uframes_t fsi_pointer(struct snd_pcm_substream *substream)
843{
844 struct snd_pcm_runtime *runtime = substream->runtime;
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900845 struct fsi_priv *fsi = fsi_get_priv(substream);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900846 long location;
847
Kuninori Morimoto9ddc9aa2009-10-30 12:02:39 +0900848 location = (fsi->byte_offset - 1);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900849 if (location < 0)
850 location = 0;
851
852 return bytes_to_frames(runtime, location);
853}
854
855static struct snd_pcm_ops fsi_pcm_ops = {
856 .open = fsi_pcm_open,
857 .ioctl = snd_pcm_lib_ioctl,
858 .hw_params = fsi_hw_params,
859 .hw_free = fsi_hw_free,
860 .pointer = fsi_pointer,
861};
862
863/************************************************************************
864
865
866 snd_soc_platform
867
868
869************************************************************************/
870#define PREALLOC_BUFFER (32 * 1024)
871#define PREALLOC_BUFFER_MAX (32 * 1024)
872
873static void fsi_pcm_free(struct snd_pcm *pcm)
874{
875 snd_pcm_lib_preallocate_free_for_all(pcm);
876}
877
878static int fsi_pcm_new(struct snd_card *card,
879 struct snd_soc_dai *dai,
880 struct snd_pcm *pcm)
881{
882 /*
883 * dont use SNDRV_DMA_TYPE_DEV, since it will oops the SH kernel
884 * in MMAP mode (i.e. aplay -M)
885 */
886 return snd_pcm_lib_preallocate_pages_for_all(
887 pcm,
888 SNDRV_DMA_TYPE_CONTINUOUS,
889 snd_dma_continuous_data(GFP_KERNEL),
890 PREALLOC_BUFFER, PREALLOC_BUFFER_MAX);
891}
892
893/************************************************************************
894
895
896 alsa struct
897
898
899************************************************************************/
900struct snd_soc_dai fsi_soc_dai[] = {
901 {
902 .name = "FSIA",
903 .id = 0,
904 .playback = {
905 .rates = FSI_RATES,
906 .formats = FSI_FMTS,
907 .channels_min = 1,
908 .channels_max = 8,
909 },
Kuninori Morimoto07102f32009-10-30 12:02:44 +0900910 .capture = {
911 .rates = FSI_RATES,
912 .formats = FSI_FMTS,
913 .channels_min = 1,
914 .channels_max = 8,
915 },
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900916 .ops = &fsi_dai_ops,
917 },
918 {
919 .name = "FSIB",
920 .id = 1,
921 .playback = {
922 .rates = FSI_RATES,
923 .formats = FSI_FMTS,
924 .channels_min = 1,
925 .channels_max = 8,
926 },
Kuninori Morimoto07102f32009-10-30 12:02:44 +0900927 .capture = {
928 .rates = FSI_RATES,
929 .formats = FSI_FMTS,
930 .channels_min = 1,
931 .channels_max = 8,
932 },
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900933 .ops = &fsi_dai_ops,
934 },
935};
936EXPORT_SYMBOL_GPL(fsi_soc_dai);
937
938struct snd_soc_platform fsi_soc_platform = {
939 .name = "fsi-pcm",
940 .pcm_ops = &fsi_pcm_ops,
941 .pcm_new = fsi_pcm_new,
942 .pcm_free = fsi_pcm_free,
943};
944EXPORT_SYMBOL_GPL(fsi_soc_platform);
945
946/************************************************************************
947
948
949 platform function
950
951
952************************************************************************/
953static int fsi_probe(struct platform_device *pdev)
954{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900955 struct fsi_master *master;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900956 struct resource *res;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900957 unsigned int irq;
958 int ret;
959
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900960 if (0 != pdev->id) {
961 dev_err(&pdev->dev, "current fsi support id 0 only now\n");
962 return -ENODEV;
963 }
964
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900965 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
966 irq = platform_get_irq(pdev, 0);
Uwe Kleine-Königb6aa1792009-12-16 17:10:09 +0100967 if (!res || (int)irq <= 0) {
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900968 dev_err(&pdev->dev, "Not enough FSI platform resources.\n");
969 ret = -ENODEV;
970 goto exit;
971 }
972
973 master = kzalloc(sizeof(*master), GFP_KERNEL);
974 if (!master) {
975 dev_err(&pdev->dev, "Could not allocate master\n");
976 ret = -ENOMEM;
977 goto exit;
978 }
979
980 master->base = ioremap_nocache(res->start, resource_size(res));
981 if (!master->base) {
982 ret = -ENXIO;
983 dev_err(&pdev->dev, "Unable to ioremap FSI registers.\n");
984 goto exit_kfree;
985 }
986
987 master->irq = irq;
988 master->info = pdev->dev.platform_data;
989 master->fsia.base = master->base;
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900990 master->fsia.master = master;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900991 master->fsib.base = master->base + 0x40;
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900992 master->fsib.master = master;
Kuninori Morimoto8fc176d2010-01-28 13:46:16 +0900993 spin_lock_init(&master->lock);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900994
Kuninori Morimoto785d1c42009-11-30 20:24:48 +0900995 pm_runtime_enable(&pdev->dev);
996 pm_runtime_resume(&pdev->dev);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +0900997
998 fsi_soc_dai[0].dev = &pdev->dev;
Kuninori Morimoto71f6e062009-12-02 15:11:08 +0900999 fsi_soc_dai[0].private_data = &master->fsia;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001000 fsi_soc_dai[1].dev = &pdev->dev;
Kuninori Morimoto71f6e062009-12-02 15:11:08 +09001001 fsi_soc_dai[1].private_data = &master->fsib;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001002
Kuninori Morimoto71f6e062009-12-02 15:11:08 +09001003 fsi_soft_all_reset(master);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001004
1005 ret = request_irq(irq, &fsi_interrupt, IRQF_DISABLED, "fsi", master);
1006 if (ret) {
1007 dev_err(&pdev->dev, "irq request err\n");
Kuninori Morimoto9ddc9aa2009-10-30 12:02:39 +09001008 goto exit_iounmap;
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001009 }
1010
1011 ret = snd_soc_register_platform(&fsi_soc_platform);
1012 if (ret < 0) {
1013 dev_err(&pdev->dev, "cannot snd soc register\n");
1014 goto exit_free_irq;
1015 }
1016
1017 return snd_soc_register_dais(fsi_soc_dai, ARRAY_SIZE(fsi_soc_dai));
1018
1019exit_free_irq:
1020 free_irq(irq, master);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001021exit_iounmap:
1022 iounmap(master->base);
Kuninori Morimoto785d1c42009-11-30 20:24:48 +09001023 pm_runtime_disable(&pdev->dev);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001024exit_kfree:
1025 kfree(master);
1026 master = NULL;
1027exit:
1028 return ret;
1029}
1030
1031static int fsi_remove(struct platform_device *pdev)
1032{
Kuninori Morimoto71f6e062009-12-02 15:11:08 +09001033 struct fsi_master *master;
1034
1035 master = fsi_get_master(fsi_soc_dai[0].private_data);
1036
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001037 snd_soc_unregister_dais(fsi_soc_dai, ARRAY_SIZE(fsi_soc_dai));
1038 snd_soc_unregister_platform(&fsi_soc_platform);
1039
Kuninori Morimoto785d1c42009-11-30 20:24:48 +09001040 pm_runtime_disable(&pdev->dev);
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001041
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001042 free_irq(master->irq, master);
1043
1044 iounmap(master->base);
1045 kfree(master);
Kuninori Morimoto71f6e062009-12-02 15:11:08 +09001046
1047 fsi_soc_dai[0].dev = NULL;
1048 fsi_soc_dai[0].private_data = NULL;
1049 fsi_soc_dai[1].dev = NULL;
1050 fsi_soc_dai[1].private_data = NULL;
1051
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001052 return 0;
1053}
1054
Kuninori Morimoto785d1c42009-11-30 20:24:48 +09001055static int fsi_runtime_nop(struct device *dev)
1056{
1057 /* Runtime PM callback shared between ->runtime_suspend()
1058 * and ->runtime_resume(). Simply returns success.
1059 *
1060 * This driver re-initializes all registers after
1061 * pm_runtime_get_sync() anyway so there is no need
1062 * to save and restore registers here.
1063 */
1064 return 0;
1065}
1066
1067static struct dev_pm_ops fsi_pm_ops = {
1068 .runtime_suspend = fsi_runtime_nop,
1069 .runtime_resume = fsi_runtime_nop,
1070};
1071
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001072static struct platform_driver fsi_driver = {
1073 .driver = {
1074 .name = "sh_fsi",
Kuninori Morimoto785d1c42009-11-30 20:24:48 +09001075 .pm = &fsi_pm_ops,
Kuninori Morimotoa4d7d552009-08-20 21:01:05 +09001076 },
1077 .probe = fsi_probe,
1078 .remove = fsi_remove,
1079};
1080
1081static int __init fsi_mobile_init(void)
1082{
1083 return platform_driver_register(&fsi_driver);
1084}
1085
1086static void __exit fsi_mobile_exit(void)
1087{
1088 platform_driver_unregister(&fsi_driver);
1089}
1090module_init(fsi_mobile_init);
1091module_exit(fsi_mobile_exit);
1092
1093MODULE_LICENSE("GPL");
1094MODULE_DESCRIPTION("SuperH onchip FSI audio driver");
1095MODULE_AUTHOR("Kuninori Morimoto <morimoto.kuninori@renesas.com>");