2 * Fifo-attached Serial Interface (FSI) support for SH7724
4 * Copyright (C) 2009 Renesas Solutions Corp.
5 * Kuninori Morimoto <morimoto.kuninori@renesas.com>
8 * Copyright (c) 2007 Manuel Lauss <mano@roarinelk.homelinux.net>
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.
15 #include <linux/delay.h>
16 #include <linux/pm_runtime.h>
18 #include <linux/slab.h>
19 #include <sound/soc.h>
20 #include <sound/sh_fsi.h>
23 #define DOFF_CTL 0x0004
24 #define DOFF_ST 0x0008
26 #define DIFF_CTL 0x0010
27 #define DIFF_ST 0x0014
32 #define MUTE_ST 0x0028
33 #define OUT_SEL 0x0030
34 #define REG_END OUT_SEL
36 #define A_MST_CTLR 0x0180
37 #define B_MST_CTLR 0x01A0
38 #define CPU_INT_ST 0x01F4
39 #define CPU_IEMSK 0x01F8
40 #define CPU_IMSK 0x01FC
45 #define CLK_RST 0x0210
46 #define SOFT_RST 0x0214
47 #define FIFO_SZ 0x0218
48 #define MREG_START A_MST_CTLR
49 #define MREG_END FIFO_SZ
53 #define CR_MONO (0x0 << 4)
54 #define CR_MONO_D (0x1 << 4)
55 #define CR_PCM (0x2 << 4)
56 #define CR_I2S (0x3 << 4)
57 #define CR_TDM (0x4 << 4)
58 #define CR_TDM_D (0x5 << 4)
59 #define CR_SPDIF 0x00100120
63 #define IRQ_HALF 0x00100000
64 #define FIFO_CLR 0x00000001
67 #define ERR_OVER 0x00000010
68 #define ERR_UNDER 0x00000001
69 #define ST_ERR (ERR_OVER | ERR_UNDER)
72 #define ACKMD_MASK 0x00007000
73 #define BPFMD_MASK 0x00000700
76 #define BP (1 << 4) /* Fix the signal of Biphase output */
77 #define SE (1 << 0) /* Fix the master clock */
80 #define B_CLK 0x00000010
81 #define A_CLK 0x00000001
83 /* IO SHIFT / MACRO */
88 #define AB_IO(param, shift) (param << shift)
91 #define PBSR (1 << 12) /* Port B Software Reset */
92 #define PASR (1 << 8) /* Port A Software Reset */
93 #define IR (1 << 4) /* Interrupt Reset */
94 #define FSISR (1 << 0) /* Software Reset */
97 #define FIFO_SZ_MASK 0x7
99 #define FSI_RATES SNDRV_PCM_RATE_8000_96000
101 #define FSI_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE)
104 * FSI driver use below type name for variable
106 * xxx_len : data length
107 * xxx_width : data width
108 * xxx_offset : data offset
109 * xxx_num : number of data
118 struct snd_pcm_substream *substream;
119 struct fsi_master *master;
143 struct fsi_priv fsia;
144 struct fsi_priv fsib;
145 struct fsi_core *core;
146 struct sh_fsi_platform_info *info;
151 * basic read write function
154 static void __fsi_reg_write(u32 reg, u32 data)
156 /* valid data area is 24bit */
159 __raw_writel(data, reg);
162 static u32 __fsi_reg_read(u32 reg)
164 return __raw_readl(reg);
167 static void __fsi_reg_mask_set(u32 reg, u32 mask, u32 data)
169 u32 val = __fsi_reg_read(reg);
174 __fsi_reg_write(reg, val);
177 static void fsi_reg_write(struct fsi_priv *fsi, u32 reg, u32 data)
180 pr_err("fsi: register access err (%s)\n", __func__);
184 __fsi_reg_write((u32)(fsi->base + reg), data);
187 static u32 fsi_reg_read(struct fsi_priv *fsi, u32 reg)
190 pr_err("fsi: register access err (%s)\n", __func__);
194 return __fsi_reg_read((u32)(fsi->base + reg));
197 static void fsi_reg_mask_set(struct fsi_priv *fsi, u32 reg, u32 mask, u32 data)
200 pr_err("fsi: register access err (%s)\n", __func__);
204 __fsi_reg_mask_set((u32)(fsi->base + reg), mask, data);
207 static void fsi_master_write(struct fsi_master *master, u32 reg, u32 data)
211 if ((reg < MREG_START) ||
213 pr_err("fsi: register access err (%s)\n", __func__);
217 spin_lock_irqsave(&master->lock, flags);
218 __fsi_reg_write((u32)(master->base + reg), data);
219 spin_unlock_irqrestore(&master->lock, flags);
222 static u32 fsi_master_read(struct fsi_master *master, u32 reg)
227 if ((reg < MREG_START) ||
229 pr_err("fsi: register access err (%s)\n", __func__);
233 spin_lock_irqsave(&master->lock, flags);
234 ret = __fsi_reg_read((u32)(master->base + reg));
235 spin_unlock_irqrestore(&master->lock, flags);
240 static void fsi_master_mask_set(struct fsi_master *master,
241 u32 reg, u32 mask, u32 data)
245 if ((reg < MREG_START) ||
247 pr_err("fsi: register access err (%s)\n", __func__);
251 spin_lock_irqsave(&master->lock, flags);
252 __fsi_reg_mask_set((u32)(master->base + reg), mask, data);
253 spin_unlock_irqrestore(&master->lock, flags);
260 static struct fsi_master *fsi_get_master(struct fsi_priv *fsi)
265 static int fsi_is_port_a(struct fsi_priv *fsi)
267 return fsi->master->base == fsi->base;
270 static struct snd_soc_dai *fsi_get_dai(struct snd_pcm_substream *substream)
272 struct snd_soc_pcm_runtime *rtd = substream->private_data;
277 static struct fsi_priv *fsi_get_priv(struct snd_pcm_substream *substream)
279 struct snd_soc_dai *dai = fsi_get_dai(substream);
280 struct fsi_master *master = snd_soc_dai_get_drvdata(dai);
283 return &master->fsia;
285 return &master->fsib;
288 static u32 fsi_get_info_flags(struct fsi_priv *fsi)
290 int is_porta = fsi_is_port_a(fsi);
291 struct fsi_master *master = fsi_get_master(fsi);
293 return is_porta ? master->info->porta_flags :
294 master->info->portb_flags;
297 static int fsi_is_master_mode(struct fsi_priv *fsi, int is_play)
300 u32 flags = fsi_get_info_flags(fsi);
302 mode = is_play ? SH_FSI_OUT_SLAVE_MODE : SH_FSI_IN_SLAVE_MODE;
309 return (mode & flags) != mode;
312 static u32 fsi_get_port_shift(struct fsi_priv *fsi, int is_play)
314 int is_porta = fsi_is_port_a(fsi);
318 shift = is_play ? AO_SHIFT : AI_SHIFT;
320 shift = is_play ? BO_SHIFT : BI_SHIFT;
325 static void fsi_stream_push(struct fsi_priv *fsi,
326 struct snd_pcm_substream *substream,
330 fsi->substream = substream;
331 fsi->buff_len = buffer_len;
332 fsi->buff_offset = 0;
333 fsi->period_len = period_len;
337 static void fsi_stream_pop(struct fsi_priv *fsi)
339 fsi->substream = NULL;
341 fsi->buff_offset = 0;
346 static int fsi_get_fifo_data_num(struct fsi_priv *fsi, int is_play)
349 u32 reg = is_play ? DOFF_ST : DIFF_ST;
352 status = fsi_reg_read(fsi, reg);
353 data_num = 0x1ff & (status >> 8);
354 data_num *= fsi->chan_num;
359 static int fsi_len2num(int len, int width)
364 #define fsi_num2offset(a, b) fsi_num2len(a, b)
365 static int fsi_num2len(int num, int width)
370 static int fsi_get_frame_width(struct fsi_priv *fsi)
372 struct snd_pcm_substream *substream = fsi->substream;
373 struct snd_pcm_runtime *runtime = substream->runtime;
375 return frames_to_bytes(runtime, 1) / fsi->chan_num;
382 static u8 *fsi_dma_get_area(struct fsi_priv *fsi)
384 return fsi->substream->runtime->dma_area + fsi->buff_offset;
387 static void fsi_dma_soft_push16(struct fsi_priv *fsi, int num)
392 start = (u16 *)fsi_dma_get_area(fsi);
394 for (i = 0; i < num; i++)
395 fsi_reg_write(fsi, DODT, ((u32)*(start + i) << 8));
398 static void fsi_dma_soft_pop16(struct fsi_priv *fsi, int num)
403 start = (u16 *)fsi_dma_get_area(fsi);
405 for (i = 0; i < num; i++)
406 *(start + i) = (u16)(fsi_reg_read(fsi, DIDT) >> 8);
409 static void fsi_dma_soft_push32(struct fsi_priv *fsi, int num)
414 start = (u32 *)fsi_dma_get_area(fsi);
416 for (i = 0; i < num; i++)
417 fsi_reg_write(fsi, DODT, *(start + i));
420 static void fsi_dma_soft_pop32(struct fsi_priv *fsi, int num)
425 start = (u32 *)fsi_dma_get_area(fsi);
427 for (i = 0; i < num; i++)
428 *(start + i) = fsi_reg_read(fsi, DIDT);
435 static void fsi_irq_enable(struct fsi_priv *fsi, int is_play)
437 u32 data = AB_IO(1, fsi_get_port_shift(fsi, is_play));
438 struct fsi_master *master = fsi_get_master(fsi);
440 fsi_master_mask_set(master, master->core->imsk, data, data);
441 fsi_master_mask_set(master, master->core->iemsk, data, data);
444 static void fsi_irq_disable(struct fsi_priv *fsi, int is_play)
446 u32 data = AB_IO(1, fsi_get_port_shift(fsi, is_play));
447 struct fsi_master *master = fsi_get_master(fsi);
449 fsi_master_mask_set(master, master->core->imsk, data, 0);
450 fsi_master_mask_set(master, master->core->iemsk, data, 0);
453 static u32 fsi_irq_get_status(struct fsi_master *master)
455 return fsi_master_read(master, master->core->int_st);
458 static void fsi_irq_clear_all_status(struct fsi_master *master)
460 fsi_master_write(master, master->core->int_st, 0);
463 static void fsi_irq_clear_status(struct fsi_priv *fsi)
466 struct fsi_master *master = fsi_get_master(fsi);
468 data |= AB_IO(1, fsi_get_port_shift(fsi, 0));
469 data |= AB_IO(1, fsi_get_port_shift(fsi, 1));
471 /* clear interrupt factor */
472 fsi_master_mask_set(master, master->core->int_st, data, 0);
476 * SPDIF master clock function
478 * These functions are used later FSI2
480 static void fsi_spdif_clk_ctrl(struct fsi_priv *fsi, int enable)
482 struct fsi_master *master = fsi_get_master(fsi);
485 if (master->core->ver < 2) {
486 pr_err("fsi: register access err (%s)\n", __func__);
491 fsi_master_mask_set(master, fsi->mst_ctrl, val, val);
493 fsi_master_mask_set(master, fsi->mst_ctrl, val, 0);
500 static void fsi_clk_ctrl(struct fsi_priv *fsi, int enable)
502 u32 val = fsi_is_port_a(fsi) ? (1 << 0) : (1 << 4);
503 struct fsi_master *master = fsi_get_master(fsi);
506 fsi_master_mask_set(master, CLK_RST, val, val);
508 fsi_master_mask_set(master, CLK_RST, val, 0);
511 static void fsi_fifo_init(struct fsi_priv *fsi,
513 struct snd_soc_dai *dai)
515 struct fsi_master *master = fsi_get_master(fsi);
518 /* get on-chip RAM capacity */
519 shift = fsi_master_read(master, FIFO_SZ);
520 shift >>= fsi_get_port_shift(fsi, is_play);
521 shift &= FIFO_SZ_MASK;
522 fsi->fifo_max_num = 256 << shift;
523 dev_dbg(dai->dev, "fifo = %d words\n", fsi->fifo_max_num);
526 * The maximum number of sample data varies depending
527 * on the number of channels selected for the format.
529 * FIFOs are used in 4-channel units in 3-channel mode
530 * and in 8-channel units in 5- to 7-channel mode
531 * meaning that more FIFOs than the required size of DPRAM
534 * ex) if 256 words of DP-RAM is connected
535 * 1 channel: 256 (256 x 1 = 256)
536 * 2 channels: 128 (128 x 2 = 256)
537 * 3 channels: 64 ( 64 x 3 = 192)
538 * 4 channels: 64 ( 64 x 4 = 256)
539 * 5 channels: 32 ( 32 x 5 = 160)
540 * 6 channels: 32 ( 32 x 6 = 192)
541 * 7 channels: 32 ( 32 x 7 = 224)
542 * 8 channels: 32 ( 32 x 8 = 256)
544 for (i = 1; i < fsi->chan_num; i <<= 1)
545 fsi->fifo_max_num >>= 1;
546 dev_dbg(dai->dev, "%d channel %d store\n",
547 fsi->chan_num, fsi->fifo_max_num);
549 ctrl = is_play ? DOFF_CTL : DIFF_CTL;
551 /* set interrupt generation factor */
552 fsi_reg_write(fsi, ctrl, IRQ_HALF);
555 fsi_reg_mask_set(fsi, ctrl, FIFO_CLR, FIFO_CLR);
558 static void fsi_soft_all_reset(struct fsi_master *master)
561 fsi_master_mask_set(master, SOFT_RST, PASR | PBSR, 0);
565 fsi_master_mask_set(master, SOFT_RST, FSISR, 0);
566 fsi_master_mask_set(master, SOFT_RST, FSISR, FSISR);
570 static int fsi_fifo_data_ctrl(struct fsi_priv *fsi, int startup, int is_play)
572 struct snd_pcm_runtime *runtime;
573 struct snd_pcm_substream *substream = NULL;
574 u32 status_reg = is_play ? DOFF_ST : DIFF_ST;
575 int data_residue_num;
580 void (*fn)(struct fsi_priv *fsi, int size);
584 !fsi->substream->runtime)
588 substream = fsi->substream;
589 runtime = substream->runtime;
591 /* FSI FIFO has limit.
592 * So, this driver can not send periods data at a time
594 if (fsi->buff_offset >=
595 fsi_num2offset(fsi->period_num + 1, fsi->period_len)) {
598 fsi->period_num = (fsi->period_num + 1) % runtime->periods;
600 if (0 == fsi->period_num)
601 fsi->buff_offset = 0;
604 /* get 1 channel data width */
605 ch_width = fsi_get_frame_width(fsi);
607 /* get residue data number of alsa */
608 data_residue_num = fsi_len2num(fsi->buff_len - fsi->buff_offset,
615 * data_num_max : number of FSI fifo free space
616 * data_num : number of ALSA residue data
618 data_num_max = fsi->fifo_max_num * fsi->chan_num;
619 data_num_max -= fsi_get_fifo_data_num(fsi, is_play);
621 data_num = data_residue_num;
625 fn = fsi_dma_soft_push16;
628 fn = fsi_dma_soft_push32;
637 * data_num_max : number of ALSA free space
638 * data_num : number of data in FSI fifo
640 data_num_max = data_residue_num;
641 data_num = fsi_get_fifo_data_num(fsi, is_play);
645 fn = fsi_dma_soft_pop16;
648 fn = fsi_dma_soft_pop32;
655 data_num = min(data_num, data_num_max);
659 /* update buff_offset */
660 fsi->buff_offset += fsi_num2offset(data_num, ch_width);
662 /* check fifo status */
664 struct snd_soc_dai *dai = fsi_get_dai(substream);
665 u32 status = fsi_reg_read(fsi, status_reg);
667 if (status & ERR_OVER)
668 dev_err(dai->dev, "over run\n");
669 if (status & ERR_UNDER)
670 dev_err(dai->dev, "under run\n");
672 fsi_reg_write(fsi, status_reg, 0);
675 fsi_irq_enable(fsi, is_play);
678 snd_pcm_period_elapsed(substream);
683 static int fsi_data_pop(struct fsi_priv *fsi, int startup)
685 return fsi_fifo_data_ctrl(fsi, startup, 0);
688 static int fsi_data_push(struct fsi_priv *fsi, int startup)
690 return fsi_fifo_data_ctrl(fsi, startup, 1);
693 static irqreturn_t fsi_interrupt(int irq, void *data)
695 struct fsi_master *master = data;
696 u32 int_st = fsi_irq_get_status(master);
698 /* clear irq status */
699 fsi_master_mask_set(master, SOFT_RST, IR, 0);
700 fsi_master_mask_set(master, SOFT_RST, IR, IR);
702 if (int_st & AB_IO(1, AO_SHIFT))
703 fsi_data_push(&master->fsia, 0);
704 if (int_st & AB_IO(1, BO_SHIFT))
705 fsi_data_push(&master->fsib, 0);
706 if (int_st & AB_IO(1, AI_SHIFT))
707 fsi_data_pop(&master->fsia, 0);
708 if (int_st & AB_IO(1, BI_SHIFT))
709 fsi_data_pop(&master->fsib, 0);
711 fsi_irq_clear_all_status(master);
720 static int fsi_dai_startup(struct snd_pcm_substream *substream,
721 struct snd_soc_dai *dai)
723 struct fsi_priv *fsi = fsi_get_priv(substream);
724 u32 flags = fsi_get_info_flags(fsi);
725 struct fsi_master *master = fsi_get_master(fsi);
729 int is_play = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
732 pm_runtime_get_sync(dai->dev);
735 data = is_play ? (1 << 0) : (1 << 4);
736 is_master = fsi_is_master_mode(fsi, is_play);
738 fsi_reg_mask_set(fsi, CKG1, data, data);
740 fsi_reg_mask_set(fsi, CKG1, data, 0);
742 /* clock inversion (CKG2) */
744 if (SH_FSI_LRM_INV & flags)
746 if (SH_FSI_BRM_INV & flags)
748 if (SH_FSI_LRS_INV & flags)
750 if (SH_FSI_BRS_INV & flags)
753 fsi_reg_write(fsi, CKG2, data);
757 reg = is_play ? DO_FMT : DI_FMT;
758 fmt = is_play ? SH_FSI_GET_OFMT(flags) : SH_FSI_GET_IFMT(flags);
760 case SH_FSI_FMT_MONO:
764 case SH_FSI_FMT_MONO_DELAY:
777 fsi->chan_num = is_play ?
778 SH_FSI_GET_CH_O(flags) : SH_FSI_GET_CH_I(flags);
779 data = CR_TDM | (fsi->chan_num - 1);
781 case SH_FSI_FMT_TDM_DELAY:
782 fsi->chan_num = is_play ?
783 SH_FSI_GET_CH_O(flags) : SH_FSI_GET_CH_I(flags);
784 data = CR_TDM_D | (fsi->chan_num - 1);
786 case SH_FSI_FMT_SPDIF:
787 if (master->core->ver < 2) {
788 dev_err(dai->dev, "This FSI can not use SPDIF\n");
793 fsi_spdif_clk_ctrl(fsi, 1);
794 fsi_reg_mask_set(fsi, OUT_SEL, 0x0010, 0x0010);
797 dev_err(dai->dev, "unknown format.\n");
800 fsi_reg_write(fsi, reg, data);
803 fsi_irq_disable(fsi, is_play);
804 fsi_irq_clear_status(fsi);
807 fsi_fifo_init(fsi, is_play, dai);
812 static void fsi_dai_shutdown(struct snd_pcm_substream *substream,
813 struct snd_soc_dai *dai)
815 struct fsi_priv *fsi = fsi_get_priv(substream);
816 int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
818 fsi_irq_disable(fsi, is_play);
819 fsi_clk_ctrl(fsi, 0);
821 pm_runtime_put_sync(dai->dev);
824 static int fsi_dai_trigger(struct snd_pcm_substream *substream, int cmd,
825 struct snd_soc_dai *dai)
827 struct fsi_priv *fsi = fsi_get_priv(substream);
828 struct snd_pcm_runtime *runtime = substream->runtime;
829 int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
833 case SNDRV_PCM_TRIGGER_START:
834 fsi_stream_push(fsi, substream,
835 frames_to_bytes(runtime, runtime->buffer_size),
836 frames_to_bytes(runtime, runtime->period_size));
837 ret = is_play ? fsi_data_push(fsi, 1) : fsi_data_pop(fsi, 1);
839 case SNDRV_PCM_TRIGGER_STOP:
840 fsi_irq_disable(fsi, is_play);
848 static int fsi_dai_hw_params(struct snd_pcm_substream *substream,
849 struct snd_pcm_hw_params *params,
850 struct snd_soc_dai *dai)
852 struct fsi_priv *fsi = fsi_get_priv(substream);
853 struct fsi_master *master = fsi_get_master(fsi);
854 int (*set_rate)(int is_porta, int rate) = master->info->set_rate;
855 int fsi_ver = master->core->ver;
856 int is_play = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
859 /* if slave mode, set_rate is not needed */
860 if (!fsi_is_master_mode(fsi, is_play))
863 /* it is error if no set_rate */
867 ret = set_rate(fsi_is_port_a(fsi), params_rate(params));
871 switch (ret & SH_FSI_ACKMD_MASK) {
874 case SH_FSI_ACKMD_512:
877 case SH_FSI_ACKMD_256:
880 case SH_FSI_ACKMD_128:
883 case SH_FSI_ACKMD_64:
886 case SH_FSI_ACKMD_32:
888 dev_err(dai->dev, "unsupported ACKMD\n");
894 switch (ret & SH_FSI_BPFMD_MASK) {
897 case SH_FSI_BPFMD_32:
900 case SH_FSI_BPFMD_64:
903 case SH_FSI_BPFMD_128:
906 case SH_FSI_BPFMD_256:
909 case SH_FSI_BPFMD_512:
912 case SH_FSI_BPFMD_16:
914 dev_err(dai->dev, "unsupported ACKMD\n");
920 fsi_reg_mask_set(fsi, CKG1, (ACKMD_MASK | BPFMD_MASK) , data);
922 fsi_clk_ctrl(fsi, 1);
930 static struct snd_soc_dai_ops fsi_dai_ops = {
931 .startup = fsi_dai_startup,
932 .shutdown = fsi_dai_shutdown,
933 .trigger = fsi_dai_trigger,
934 .hw_params = fsi_dai_hw_params,
941 static struct snd_pcm_hardware fsi_pcm_hardware = {
942 .info = SNDRV_PCM_INFO_INTERLEAVED |
943 SNDRV_PCM_INFO_MMAP |
944 SNDRV_PCM_INFO_MMAP_VALID |
945 SNDRV_PCM_INFO_PAUSE,
952 .buffer_bytes_max = 64 * 1024,
953 .period_bytes_min = 32,
954 .period_bytes_max = 8192,
960 static int fsi_pcm_open(struct snd_pcm_substream *substream)
962 struct snd_pcm_runtime *runtime = substream->runtime;
965 snd_soc_set_runtime_hwparams(substream, &fsi_pcm_hardware);
967 ret = snd_pcm_hw_constraint_integer(runtime,
968 SNDRV_PCM_HW_PARAM_PERIODS);
973 static int fsi_hw_params(struct snd_pcm_substream *substream,
974 struct snd_pcm_hw_params *hw_params)
976 return snd_pcm_lib_malloc_pages(substream,
977 params_buffer_bytes(hw_params));
980 static int fsi_hw_free(struct snd_pcm_substream *substream)
982 return snd_pcm_lib_free_pages(substream);
985 static snd_pcm_uframes_t fsi_pointer(struct snd_pcm_substream *substream)
987 struct snd_pcm_runtime *runtime = substream->runtime;
988 struct fsi_priv *fsi = fsi_get_priv(substream);
991 location = (fsi->buff_offset - 1);
995 return bytes_to_frames(runtime, location);
998 static struct snd_pcm_ops fsi_pcm_ops = {
999 .open = fsi_pcm_open,
1000 .ioctl = snd_pcm_lib_ioctl,
1001 .hw_params = fsi_hw_params,
1002 .hw_free = fsi_hw_free,
1003 .pointer = fsi_pointer,
1010 #define PREALLOC_BUFFER (32 * 1024)
1011 #define PREALLOC_BUFFER_MAX (32 * 1024)
1013 static void fsi_pcm_free(struct snd_pcm *pcm)
1015 snd_pcm_lib_preallocate_free_for_all(pcm);
1018 static int fsi_pcm_new(struct snd_card *card,
1019 struct snd_soc_dai *dai,
1020 struct snd_pcm *pcm)
1023 * dont use SNDRV_DMA_TYPE_DEV, since it will oops the SH kernel
1024 * in MMAP mode (i.e. aplay -M)
1026 return snd_pcm_lib_preallocate_pages_for_all(
1028 SNDRV_DMA_TYPE_CONTINUOUS,
1029 snd_dma_continuous_data(GFP_KERNEL),
1030 PREALLOC_BUFFER, PREALLOC_BUFFER_MAX);
1037 static struct snd_soc_dai_driver fsi_soc_dai[] = {
1042 .formats = FSI_FMTS,
1048 .formats = FSI_FMTS,
1052 .ops = &fsi_dai_ops,
1058 .formats = FSI_FMTS,
1064 .formats = FSI_FMTS,
1068 .ops = &fsi_dai_ops,
1072 static struct snd_soc_platform_driver fsi_soc_platform = {
1073 .ops = &fsi_pcm_ops,
1074 .pcm_new = fsi_pcm_new,
1075 .pcm_free = fsi_pcm_free,
1082 static int fsi_probe(struct platform_device *pdev)
1084 struct fsi_master *master;
1085 const struct platform_device_id *id_entry;
1086 struct resource *res;
1090 id_entry = pdev->id_entry;
1092 dev_err(&pdev->dev, "unknown fsi device\n");
1096 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1097 irq = platform_get_irq(pdev, 0);
1098 if (!res || (int)irq <= 0) {
1099 dev_err(&pdev->dev, "Not enough FSI platform resources.\n");
1104 master = kzalloc(sizeof(*master), GFP_KERNEL);
1106 dev_err(&pdev->dev, "Could not allocate master\n");
1111 master->base = ioremap_nocache(res->start, resource_size(res));
1112 if (!master->base) {
1114 dev_err(&pdev->dev, "Unable to ioremap FSI registers.\n");
1118 /* master setting */
1120 master->info = pdev->dev.platform_data;
1121 master->core = (struct fsi_core *)id_entry->driver_data;
1122 spin_lock_init(&master->lock);
1125 master->fsia.base = master->base;
1126 master->fsia.master = master;
1127 master->fsia.mst_ctrl = A_MST_CTLR;
1130 master->fsib.base = master->base + 0x40;
1131 master->fsib.master = master;
1132 master->fsib.mst_ctrl = B_MST_CTLR;
1134 pm_runtime_enable(&pdev->dev);
1135 pm_runtime_resume(&pdev->dev);
1136 dev_set_drvdata(&pdev->dev, master);
1138 fsi_soft_all_reset(master);
1140 ret = request_irq(irq, &fsi_interrupt, IRQF_DISABLED,
1141 id_entry->name, master);
1143 dev_err(&pdev->dev, "irq request err\n");
1147 ret = snd_soc_register_platform(&pdev->dev, &fsi_soc_platform);
1149 dev_err(&pdev->dev, "cannot snd soc register\n");
1153 return snd_soc_register_dais(&pdev->dev, fsi_soc_dai, ARRAY_SIZE(fsi_soc_dai));
1156 free_irq(irq, master);
1158 iounmap(master->base);
1159 pm_runtime_disable(&pdev->dev);
1167 static int fsi_remove(struct platform_device *pdev)
1169 struct fsi_master *master;
1171 master = dev_get_drvdata(&pdev->dev);
1173 snd_soc_unregister_dais(&pdev->dev, ARRAY_SIZE(fsi_soc_dai));
1174 snd_soc_unregister_platform(&pdev->dev);
1176 pm_runtime_disable(&pdev->dev);
1178 free_irq(master->irq, master);
1180 iounmap(master->base);
1186 static int fsi_runtime_nop(struct device *dev)
1188 /* Runtime PM callback shared between ->runtime_suspend()
1189 * and ->runtime_resume(). Simply returns success.
1191 * This driver re-initializes all registers after
1192 * pm_runtime_get_sync() anyway so there is no need
1193 * to save and restore registers here.
1198 static struct dev_pm_ops fsi_pm_ops = {
1199 .runtime_suspend = fsi_runtime_nop,
1200 .runtime_resume = fsi_runtime_nop,
1203 static struct fsi_core fsi1_core = {
1212 static struct fsi_core fsi2_core = {
1216 .int_st = CPU_INT_ST,
1221 static struct platform_device_id fsi_id_table[] = {
1222 { "sh_fsi", (kernel_ulong_t)&fsi1_core },
1223 { "sh_fsi2", (kernel_ulong_t)&fsi2_core },
1226 MODULE_DEVICE_TABLE(platform, fsi_id_table);
1228 static struct platform_driver fsi_driver = {
1230 .name = "fsi-pcm-audio",
1234 .remove = fsi_remove,
1235 .id_table = fsi_id_table,
1238 static int __init fsi_mobile_init(void)
1240 return platform_driver_register(&fsi_driver);
1243 static void __exit fsi_mobile_exit(void)
1245 platform_driver_unregister(&fsi_driver);
1248 module_init(fsi_mobile_init);
1249 module_exit(fsi_mobile_exit);
1251 MODULE_LICENSE("GPL");
1252 MODULE_DESCRIPTION("SuperH onchip FSI audio driver");
1253 MODULE_AUTHOR("Kuninori Morimoto <morimoto.kuninori@renesas.com>");