Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1 | /* |
| 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 Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 15 | #include <linux/delay.h> |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 16 | #include <linux/pm_runtime.h> |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 17 | #include <linux/io.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 19 | #include <linux/module.h> |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 20 | #include <sound/soc.h> |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 21 | #include <sound/sh_fsi.h> |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 22 | |
Kuninori Morimoto | e8c8b63 | 2010-12-03 17:37:55 +0900 | [diff] [blame] | 23 | /* PortA/PortB register */ |
| 24 | #define REG_DO_FMT 0x0000 |
| 25 | #define REG_DOFF_CTL 0x0004 |
| 26 | #define REG_DOFF_ST 0x0008 |
| 27 | #define REG_DI_FMT 0x000C |
| 28 | #define REG_DIFF_CTL 0x0010 |
| 29 | #define REG_DIFF_ST 0x0014 |
| 30 | #define REG_CKG1 0x0018 |
| 31 | #define REG_CKG2 0x001C |
| 32 | #define REG_DIDT 0x0020 |
| 33 | #define REG_DODT 0x0024 |
| 34 | #define REG_MUTE_ST 0x0028 |
| 35 | #define REG_OUT_SEL 0x0030 |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 36 | |
Kuninori Morimoto | 43fa95c | 2010-12-03 17:38:03 +0900 | [diff] [blame] | 37 | /* master register */ |
| 38 | #define MST_CLK_RST 0x0210 |
| 39 | #define MST_SOFT_RST 0x0214 |
| 40 | #define MST_FIFO_SZ 0x0218 |
| 41 | |
| 42 | /* core register (depend on FSI version) */ |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 43 | #define A_MST_CTLR 0x0180 |
| 44 | #define B_MST_CTLR 0x01A0 |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 45 | #define CPU_INT_ST 0x01F4 |
| 46 | #define CPU_IEMSK 0x01F8 |
| 47 | #define CPU_IMSK 0x01FC |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 48 | #define INT_ST 0x0200 |
| 49 | #define IEMSK 0x0204 |
| 50 | #define IMSK 0x0208 |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 51 | |
| 52 | /* DO_FMT */ |
| 53 | /* DI_FMT */ |
Kuninori Morimoto | f7d711e | 2010-12-03 17:36:24 +0900 | [diff] [blame] | 54 | #define CR_BWS_24 (0x0 << 20) /* FSI2 */ |
| 55 | #define CR_BWS_16 (0x1 << 20) /* FSI2 */ |
| 56 | #define CR_BWS_20 (0x2 << 20) /* FSI2 */ |
| 57 | |
| 58 | #define CR_DTMD_PCM (0x0 << 8) /* FSI2 */ |
| 59 | #define CR_DTMD_SPDIF_PCM (0x1 << 8) /* FSI2 */ |
| 60 | #define CR_DTMD_SPDIF_STREAM (0x2 << 8) /* FSI2 */ |
| 61 | |
Kuninori Morimoto | a7ffb52 | 2010-07-13 12:13:00 +0900 | [diff] [blame] | 62 | #define CR_MONO (0x0 << 4) |
| 63 | #define CR_MONO_D (0x1 << 4) |
| 64 | #define CR_PCM (0x2 << 4) |
| 65 | #define CR_I2S (0x3 << 4) |
| 66 | #define CR_TDM (0x4 << 4) |
| 67 | #define CR_TDM_D (0x5 << 4) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 68 | |
| 69 | /* DOFF_CTL */ |
| 70 | /* DIFF_CTL */ |
| 71 | #define IRQ_HALF 0x00100000 |
| 72 | #define FIFO_CLR 0x00000001 |
| 73 | |
| 74 | /* DOFF_ST */ |
| 75 | #define ERR_OVER 0x00000010 |
| 76 | #define ERR_UNDER 0x00000001 |
Kuninori Morimoto | 59c3b00 | 2009-12-28 14:09:16 +0900 | [diff] [blame] | 77 | #define ST_ERR (ERR_OVER | ERR_UNDER) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 78 | |
Kuninori Morimoto | ccad7b4 | 2010-07-13 12:13:14 +0900 | [diff] [blame] | 79 | /* CKG1 */ |
| 80 | #define ACKMD_MASK 0x00007000 |
| 81 | #define BPFMD_MASK 0x00000700 |
Kuninori Morimoto | 4d805f7 | 2011-01-20 11:46:02 +0900 | [diff] [blame] | 82 | #define DIMD (1 << 4) |
| 83 | #define DOMD (1 << 0) |
Kuninori Morimoto | ccad7b4 | 2010-07-13 12:13:14 +0900 | [diff] [blame] | 84 | |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 85 | /* A/B MST_CTLR */ |
| 86 | #define BP (1 << 4) /* Fix the signal of Biphase output */ |
| 87 | #define SE (1 << 0) /* Fix the master clock */ |
| 88 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 89 | /* CLK_RST */ |
Kuninori Morimoto | 1f5e2a3 | 2011-04-21 10:33:52 +0900 | [diff] [blame] | 90 | #define CRB (1 << 4) |
| 91 | #define CRA (1 << 0) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 92 | |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 93 | /* IO SHIFT / MACRO */ |
| 94 | #define BI_SHIFT 12 |
| 95 | #define BO_SHIFT 8 |
| 96 | #define AI_SHIFT 4 |
| 97 | #define AO_SHIFT 0 |
| 98 | #define AB_IO(param, shift) (param << shift) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 99 | |
Kuninori Morimoto | feb58cf | 2010-03-24 15:27:24 +0900 | [diff] [blame] | 100 | /* SOFT_RST */ |
| 101 | #define PBSR (1 << 12) /* Port B Software Reset */ |
| 102 | #define PASR (1 << 8) /* Port A Software Reset */ |
| 103 | #define IR (1 << 4) /* Interrupt Reset */ |
| 104 | #define FSISR (1 << 0) /* Software Reset */ |
| 105 | |
Kuninori Morimoto | f7d711e | 2010-12-03 17:36:24 +0900 | [diff] [blame] | 106 | /* OUT_SEL (FSI2) */ |
| 107 | #define DMMD (1 << 4) /* SPDIF output timing 0: Biphase only */ |
| 108 | /* 1: Biphase and serial */ |
| 109 | |
Kuninori Morimoto | 4a942b4 | 2010-03-25 19:15:51 +0900 | [diff] [blame] | 110 | /* FIFO_SZ */ |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 111 | #define FIFO_SZ_MASK 0x7 |
Kuninori Morimoto | 4a942b4 | 2010-03-25 19:15:51 +0900 | [diff] [blame] | 112 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 113 | #define FSI_RATES SNDRV_PCM_RATE_8000_96000 |
| 114 | |
| 115 | #define FSI_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE) |
| 116 | |
Kuninori Morimoto | d7c5762 | 2011-01-24 10:42:33 +0900 | [diff] [blame] | 117 | typedef int (*set_rate_func)(struct device *dev, int is_porta, int rate, int enable); |
| 118 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 119 | /* |
Kuninori Morimoto | 5bfb9ad | 2010-09-17 13:48:45 +0900 | [diff] [blame] | 120 | * FSI driver use below type name for variable |
| 121 | * |
Kuninori Morimoto | 5bfb9ad | 2010-09-17 13:48:45 +0900 | [diff] [blame] | 122 | * xxx_num : number of data |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 123 | * xxx_pos : position of data |
| 124 | * xxx_capa : capacity of data |
| 125 | */ |
| 126 | |
| 127 | /* |
| 128 | * period/frame/sample image |
| 129 | * |
| 130 | * ex) PCM (2ch) |
| 131 | * |
| 132 | * period pos period pos |
| 133 | * [n] [n + 1] |
| 134 | * |<-------------------- period--------------------->| |
| 135 | * ==|============================================ ... =|== |
| 136 | * | | |
| 137 | * ||<----- frame ----->|<------ frame ----->| ... | |
| 138 | * |+--------------------+--------------------+- ... | |
| 139 | * ||[ sample ][ sample ]|[ sample ][ sample ]| ... | |
| 140 | * |+--------------------+--------------------+- ... | |
| 141 | * ==|============================================ ... =|== |
| 142 | */ |
| 143 | |
| 144 | /* |
| 145 | * FSI FIFO image |
| 146 | * |
| 147 | * | | |
| 148 | * | | |
| 149 | * | [ sample ] | |
| 150 | * | [ sample ] | |
| 151 | * | [ sample ] | |
| 152 | * | [ sample ] | |
| 153 | * --> go to codecs |
Kuninori Morimoto | 5bfb9ad | 2010-09-17 13:48:45 +0900 | [diff] [blame] | 154 | */ |
| 155 | |
| 156 | /* |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 157 | * struct |
| 158 | */ |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 159 | |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 160 | struct fsi_stream { |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 161 | struct snd_pcm_substream *substream; |
| 162 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 163 | int fifo_sample_capa; /* sample capacity of FSI FIFO */ |
| 164 | int buff_sample_capa; /* sample capacity of ALSA buffer */ |
| 165 | int buff_sample_pos; /* sample position of ALSA buffer */ |
| 166 | int period_samples; /* sample number / 1 period */ |
| 167 | int period_pos; /* current period position */ |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 168 | |
| 169 | int uerr_num; |
| 170 | int oerr_num; |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 171 | }; |
| 172 | |
| 173 | struct fsi_priv { |
| 174 | void __iomem *base; |
| 175 | struct fsi_master *master; |
| 176 | |
| 177 | struct fsi_stream playback; |
| 178 | struct fsi_stream capture; |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 179 | |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 180 | u32 do_fmt; |
| 181 | u32 di_fmt; |
| 182 | |
Kuninori Morimoto | 6a9ebad | 2011-04-21 10:33:36 +0900 | [diff] [blame] | 183 | int chan_num:16; |
| 184 | int clk_master:1; |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 185 | int spdif:1; |
Kuninori Morimoto | 6a9ebad | 2011-04-21 10:33:36 +0900 | [diff] [blame] | 186 | |
Kuninori Morimoto | d4bc99b | 2010-11-24 02:44:06 +0000 | [diff] [blame] | 187 | long rate; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 188 | }; |
| 189 | |
Kuninori Morimoto | 73b92c1 | 2010-07-13 12:13:04 +0900 | [diff] [blame] | 190 | struct fsi_core { |
| 191 | int ver; |
| 192 | |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 193 | u32 int_st; |
| 194 | u32 iemsk; |
| 195 | u32 imsk; |
Kuninori Morimoto | 2b0e730 | 2010-12-03 17:37:44 +0900 | [diff] [blame] | 196 | u32 a_mclk; |
| 197 | u32 b_mclk; |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 198 | }; |
| 199 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 200 | struct fsi_master { |
| 201 | void __iomem *base; |
| 202 | int irq; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 203 | struct fsi_priv fsia; |
| 204 | struct fsi_priv fsib; |
Kuninori Morimoto | 73b92c1 | 2010-07-13 12:13:04 +0900 | [diff] [blame] | 205 | struct fsi_core *core; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 206 | struct sh_fsi_platform_info *info; |
Kuninori Morimoto | 8fc176d | 2010-01-28 13:46:16 +0900 | [diff] [blame] | 207 | spinlock_t lock; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 208 | }; |
| 209 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 210 | /* |
| 211 | * basic read write function |
| 212 | */ |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 213 | |
Arnd Bergmann | ca7acee | 2011-10-02 22:28:02 +0200 | [diff] [blame] | 214 | static void __fsi_reg_write(u32 __iomem *reg, u32 data) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 215 | { |
| 216 | /* valid data area is 24bit */ |
| 217 | data &= 0x00ffffff; |
| 218 | |
Guennadi Liakhovetski | 0f69d97 | 2010-02-03 17:37:23 +0100 | [diff] [blame] | 219 | __raw_writel(data, reg); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 220 | } |
| 221 | |
Arnd Bergmann | ca7acee | 2011-10-02 22:28:02 +0200 | [diff] [blame] | 222 | static u32 __fsi_reg_read(u32 __iomem *reg) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 223 | { |
Guennadi Liakhovetski | 0f69d97 | 2010-02-03 17:37:23 +0100 | [diff] [blame] | 224 | return __raw_readl(reg); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 225 | } |
| 226 | |
Arnd Bergmann | ca7acee | 2011-10-02 22:28:02 +0200 | [diff] [blame] | 227 | static void __fsi_reg_mask_set(u32 __iomem *reg, u32 mask, u32 data) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 228 | { |
| 229 | u32 val = __fsi_reg_read(reg); |
| 230 | |
| 231 | val &= ~mask; |
| 232 | val |= data & mask; |
| 233 | |
Guennadi Liakhovetski | 0f69d97 | 2010-02-03 17:37:23 +0100 | [diff] [blame] | 234 | __fsi_reg_write(reg, val); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 235 | } |
| 236 | |
Kuninori Morimoto | e8c8b63 | 2010-12-03 17:37:55 +0900 | [diff] [blame] | 237 | #define fsi_reg_write(p, r, d)\ |
| 238 | __fsi_reg_write((u32)(p->base + REG_##r), d) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 239 | |
Kuninori Morimoto | e8c8b63 | 2010-12-03 17:37:55 +0900 | [diff] [blame] | 240 | #define fsi_reg_read(p, r)\ |
| 241 | __fsi_reg_read((u32)(p->base + REG_##r)) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 242 | |
Kuninori Morimoto | e8c8b63 | 2010-12-03 17:37:55 +0900 | [diff] [blame] | 243 | #define fsi_reg_mask_set(p, r, m, d)\ |
| 244 | __fsi_reg_mask_set((u32)(p->base + REG_##r), m, d) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 245 | |
Kuninori Morimoto | 43fa95c | 2010-12-03 17:38:03 +0900 | [diff] [blame] | 246 | #define fsi_master_read(p, r) _fsi_master_read(p, MST_##r) |
| 247 | #define fsi_core_read(p, r) _fsi_master_read(p, p->core->r) |
| 248 | static u32 _fsi_master_read(struct fsi_master *master, u32 reg) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 249 | { |
Kuninori Morimoto | 8fc176d | 2010-01-28 13:46:16 +0900 | [diff] [blame] | 250 | u32 ret; |
| 251 | unsigned long flags; |
| 252 | |
Kuninori Morimoto | 8fc176d | 2010-01-28 13:46:16 +0900 | [diff] [blame] | 253 | spin_lock_irqsave(&master->lock, flags); |
Arnd Bergmann | ca7acee | 2011-10-02 22:28:02 +0200 | [diff] [blame] | 254 | ret = __fsi_reg_read(master->base + reg); |
Kuninori Morimoto | 8fc176d | 2010-01-28 13:46:16 +0900 | [diff] [blame] | 255 | spin_unlock_irqrestore(&master->lock, flags); |
| 256 | |
| 257 | return ret; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 258 | } |
| 259 | |
Kuninori Morimoto | 43fa95c | 2010-12-03 17:38:03 +0900 | [diff] [blame] | 260 | #define fsi_master_mask_set(p, r, m, d) _fsi_master_mask_set(p, MST_##r, m, d) |
| 261 | #define fsi_core_mask_set(p, r, m, d) _fsi_master_mask_set(p, p->core->r, m, d) |
| 262 | static void _fsi_master_mask_set(struct fsi_master *master, |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 263 | u32 reg, u32 mask, u32 data) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 264 | { |
Kuninori Morimoto | 8fc176d | 2010-01-28 13:46:16 +0900 | [diff] [blame] | 265 | unsigned long flags; |
| 266 | |
Kuninori Morimoto | 8fc176d | 2010-01-28 13:46:16 +0900 | [diff] [blame] | 267 | spin_lock_irqsave(&master->lock, flags); |
Arnd Bergmann | ca7acee | 2011-10-02 22:28:02 +0200 | [diff] [blame] | 268 | __fsi_reg_mask_set(master->base + reg, mask, data); |
Kuninori Morimoto | 8fc176d | 2010-01-28 13:46:16 +0900 | [diff] [blame] | 269 | spin_unlock_irqrestore(&master->lock, flags); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 270 | } |
| 271 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 272 | /* |
| 273 | * basic function |
| 274 | */ |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 275 | |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 276 | static struct fsi_master *fsi_get_master(struct fsi_priv *fsi) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 277 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 278 | return fsi->master; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 279 | } |
| 280 | |
Kuninori Morimoto | 6a9ebad | 2011-04-21 10:33:36 +0900 | [diff] [blame] | 281 | static int fsi_is_clk_master(struct fsi_priv *fsi) |
| 282 | { |
| 283 | return fsi->clk_master; |
| 284 | } |
| 285 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 286 | static int fsi_is_port_a(struct fsi_priv *fsi) |
| 287 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 288 | return fsi->master->base == fsi->base; |
| 289 | } |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 290 | |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 291 | static int fsi_is_spdif(struct fsi_priv *fsi) |
| 292 | { |
| 293 | return fsi->spdif; |
| 294 | } |
| 295 | |
Kuninori Morimoto | 142e817 | 2009-12-28 14:09:11 +0900 | [diff] [blame] | 296 | static struct snd_soc_dai *fsi_get_dai(struct snd_pcm_substream *substream) |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 297 | { |
| 298 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Kuninori Morimoto | 142e817 | 2009-12-28 14:09:11 +0900 | [diff] [blame] | 299 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 300 | return rtd->cpu_dai; |
Kuninori Morimoto | 142e817 | 2009-12-28 14:09:11 +0900 | [diff] [blame] | 301 | } |
| 302 | |
Kuninori Morimoto | 0d032c1 | 2011-01-20 11:45:51 +0900 | [diff] [blame] | 303 | static struct fsi_priv *fsi_get_priv_frm_dai(struct snd_soc_dai *dai) |
Kuninori Morimoto | 142e817 | 2009-12-28 14:09:11 +0900 | [diff] [blame] | 304 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 305 | struct fsi_master *master = snd_soc_dai_get_drvdata(dai); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 306 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 307 | if (dai->id == 0) |
| 308 | return &master->fsia; |
| 309 | else |
| 310 | return &master->fsib; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 311 | } |
| 312 | |
Kuninori Morimoto | 0d032c1 | 2011-01-20 11:45:51 +0900 | [diff] [blame] | 313 | static struct fsi_priv *fsi_get_priv(struct snd_pcm_substream *substream) |
| 314 | { |
| 315 | return fsi_get_priv_frm_dai(fsi_get_dai(substream)); |
| 316 | } |
| 317 | |
Kuninori Morimoto | d7c5762 | 2011-01-24 10:42:33 +0900 | [diff] [blame] | 318 | static set_rate_func fsi_get_info_set_rate(struct fsi_master *master) |
| 319 | { |
| 320 | if (!master->info) |
| 321 | return NULL; |
| 322 | |
| 323 | return master->info->set_rate; |
| 324 | } |
| 325 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 326 | static u32 fsi_get_info_flags(struct fsi_priv *fsi) |
| 327 | { |
| 328 | int is_porta = fsi_is_port_a(fsi); |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 329 | struct fsi_master *master = fsi_get_master(fsi); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 330 | |
Kuninori Morimoto | d7c5762 | 2011-01-24 10:42:33 +0900 | [diff] [blame] | 331 | if (!master->info) |
| 332 | return 0; |
| 333 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 334 | return is_porta ? master->info->porta_flags : |
| 335 | master->info->portb_flags; |
| 336 | } |
| 337 | |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 338 | static inline int fsi_stream_is_play(int stream) |
| 339 | { |
| 340 | return stream == SNDRV_PCM_STREAM_PLAYBACK; |
| 341 | } |
| 342 | |
Kuninori Morimoto | 0054578 | 2010-10-12 18:30:14 +0900 | [diff] [blame] | 343 | static inline int fsi_is_play(struct snd_pcm_substream *substream) |
| 344 | { |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 345 | return fsi_stream_is_play(substream->stream); |
| 346 | } |
| 347 | |
| 348 | static inline struct fsi_stream *fsi_get_stream(struct fsi_priv *fsi, |
| 349 | int is_play) |
| 350 | { |
| 351 | return is_play ? &fsi->playback : &fsi->capture; |
Kuninori Morimoto | 0054578 | 2010-10-12 18:30:14 +0900 | [diff] [blame] | 352 | } |
| 353 | |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 354 | static u32 fsi_get_port_shift(struct fsi_priv *fsi, int is_play) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 355 | { |
| 356 | int is_porta = fsi_is_port_a(fsi); |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 357 | u32 shift; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 358 | |
| 359 | if (is_porta) |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 360 | shift = is_play ? AO_SHIFT : AI_SHIFT; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 361 | else |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 362 | shift = is_play ? BO_SHIFT : BI_SHIFT; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 363 | |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 364 | return shift; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 365 | } |
| 366 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 367 | static int fsi_frame2sample(struct fsi_priv *fsi, int frames) |
| 368 | { |
| 369 | return frames * fsi->chan_num; |
| 370 | } |
| 371 | |
| 372 | static int fsi_sample2frame(struct fsi_priv *fsi, int samples) |
| 373 | { |
| 374 | return samples / fsi->chan_num; |
| 375 | } |
| 376 | |
Kuninori Morimoto | cda828c | 2011-05-23 20:46:35 +0900 | [diff] [blame] | 377 | static int fsi_stream_is_working(struct fsi_priv *fsi, |
| 378 | int is_play) |
| 379 | { |
| 380 | struct fsi_stream *io = fsi_get_stream(fsi, is_play); |
| 381 | struct fsi_master *master = fsi_get_master(fsi); |
| 382 | unsigned long flags; |
| 383 | int ret; |
| 384 | |
| 385 | spin_lock_irqsave(&master->lock, flags); |
| 386 | ret = !!io->substream; |
| 387 | spin_unlock_irqrestore(&master->lock, flags); |
| 388 | |
| 389 | return ret; |
| 390 | } |
| 391 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 392 | static void fsi_stream_push(struct fsi_priv *fsi, |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 393 | int is_play, |
Kuninori Morimoto | 0ffe296 | 2011-05-23 20:45:57 +0900 | [diff] [blame] | 394 | struct snd_pcm_substream *substream) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 395 | { |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 396 | struct fsi_stream *io = fsi_get_stream(fsi, is_play); |
Kuninori Morimoto | 0ffe296 | 2011-05-23 20:45:57 +0900 | [diff] [blame] | 397 | struct snd_pcm_runtime *runtime = substream->runtime; |
Kuninori Morimoto | 2da6589 | 2011-05-23 20:46:13 +0900 | [diff] [blame] | 398 | struct fsi_master *master = fsi_get_master(fsi); |
| 399 | unsigned long flags; |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 400 | |
Kuninori Morimoto | 2da6589 | 2011-05-23 20:46:13 +0900 | [diff] [blame] | 401 | spin_lock_irqsave(&master->lock, flags); |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 402 | io->substream = substream; |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 403 | io->buff_sample_capa = fsi_frame2sample(fsi, runtime->buffer_size); |
| 404 | io->buff_sample_pos = 0; |
| 405 | io->period_samples = fsi_frame2sample(fsi, runtime->period_size); |
| 406 | io->period_pos = 0; |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 407 | io->oerr_num = -1; /* ignore 1st err */ |
| 408 | io->uerr_num = -1; /* ignore 1st err */ |
Kuninori Morimoto | 2da6589 | 2011-05-23 20:46:13 +0900 | [diff] [blame] | 409 | spin_unlock_irqrestore(&master->lock, flags); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 410 | } |
| 411 | |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 412 | static void fsi_stream_pop(struct fsi_priv *fsi, int is_play) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 413 | { |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 414 | struct fsi_stream *io = fsi_get_stream(fsi, is_play); |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 415 | struct snd_soc_dai *dai = fsi_get_dai(io->substream); |
Kuninori Morimoto | 2da6589 | 2011-05-23 20:46:13 +0900 | [diff] [blame] | 416 | struct fsi_master *master = fsi_get_master(fsi); |
| 417 | unsigned long flags; |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 418 | |
Kuninori Morimoto | 2da6589 | 2011-05-23 20:46:13 +0900 | [diff] [blame] | 419 | spin_lock_irqsave(&master->lock, flags); |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 420 | |
| 421 | if (io->oerr_num > 0) |
| 422 | dev_err(dai->dev, "over_run = %d\n", io->oerr_num); |
| 423 | |
| 424 | if (io->uerr_num > 0) |
| 425 | dev_err(dai->dev, "under_run = %d\n", io->uerr_num); |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 426 | |
| 427 | io->substream = NULL; |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 428 | io->buff_sample_capa = 0; |
| 429 | io->buff_sample_pos = 0; |
| 430 | io->period_samples = 0; |
| 431 | io->period_pos = 0; |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 432 | io->oerr_num = 0; |
| 433 | io->uerr_num = 0; |
Kuninori Morimoto | 2da6589 | 2011-05-23 20:46:13 +0900 | [diff] [blame] | 434 | spin_unlock_irqrestore(&master->lock, flags); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 435 | } |
| 436 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 437 | static int fsi_get_current_fifo_samples(struct fsi_priv *fsi, int is_play) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 438 | { |
| 439 | u32 status; |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 440 | int frames; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 441 | |
Kuninori Morimoto | e8c8b63 | 2010-12-03 17:37:55 +0900 | [diff] [blame] | 442 | status = is_play ? |
| 443 | fsi_reg_read(fsi, DOFF_ST) : |
| 444 | fsi_reg_read(fsi, DIFF_ST); |
| 445 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 446 | frames = 0x1ff & (status >> 8); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 447 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 448 | return fsi_frame2sample(fsi, frames); |
Kuninori Morimoto | cca1b23 | 2010-10-12 11:39:25 +0900 | [diff] [blame] | 449 | } |
| 450 | |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 451 | static void fsi_count_fifo_err(struct fsi_priv *fsi) |
| 452 | { |
| 453 | u32 ostatus = fsi_reg_read(fsi, DOFF_ST); |
| 454 | u32 istatus = fsi_reg_read(fsi, DIFF_ST); |
| 455 | |
| 456 | if (ostatus & ERR_OVER) |
| 457 | fsi->playback.oerr_num++; |
| 458 | |
| 459 | if (ostatus & ERR_UNDER) |
| 460 | fsi->playback.uerr_num++; |
| 461 | |
| 462 | if (istatus & ERR_OVER) |
| 463 | fsi->capture.oerr_num++; |
| 464 | |
| 465 | if (istatus & ERR_UNDER) |
| 466 | fsi->capture.uerr_num++; |
| 467 | |
| 468 | fsi_reg_write(fsi, DOFF_ST, 0); |
| 469 | fsi_reg_write(fsi, DIFF_ST, 0); |
| 470 | } |
| 471 | |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 472 | /* |
| 473 | * dma function |
| 474 | */ |
| 475 | |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 476 | static u8 *fsi_dma_get_area(struct fsi_priv *fsi, int stream) |
Kuninori Morimoto | c79eab3 | 2010-09-17 13:48:05 +0900 | [diff] [blame] | 477 | { |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 478 | int is_play = fsi_stream_is_play(stream); |
| 479 | struct fsi_stream *io = fsi_get_stream(fsi, is_play); |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 480 | struct snd_pcm_runtime *runtime = io->substream->runtime; |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 481 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 482 | return runtime->dma_area + |
| 483 | samples_to_bytes(runtime, io->buff_sample_pos); |
Kuninori Morimoto | c79eab3 | 2010-09-17 13:48:05 +0900 | [diff] [blame] | 484 | } |
| 485 | |
Kuninori Morimoto | 5bfb9ad | 2010-09-17 13:48:45 +0900 | [diff] [blame] | 486 | static void fsi_dma_soft_push16(struct fsi_priv *fsi, int num) |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 487 | { |
| 488 | u16 *start; |
| 489 | int i; |
| 490 | |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 491 | start = (u16 *)fsi_dma_get_area(fsi, SNDRV_PCM_STREAM_PLAYBACK); |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 492 | |
Kuninori Morimoto | 5bfb9ad | 2010-09-17 13:48:45 +0900 | [diff] [blame] | 493 | for (i = 0; i < num; i++) |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 494 | fsi_reg_write(fsi, DODT, ((u32)*(start + i) << 8)); |
| 495 | } |
| 496 | |
Kuninori Morimoto | 5bfb9ad | 2010-09-17 13:48:45 +0900 | [diff] [blame] | 497 | static void fsi_dma_soft_pop16(struct fsi_priv *fsi, int num) |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 498 | { |
| 499 | u16 *start; |
| 500 | int i; |
| 501 | |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 502 | start = (u16 *)fsi_dma_get_area(fsi, SNDRV_PCM_STREAM_CAPTURE); |
| 503 | |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 504 | |
Kuninori Morimoto | 5bfb9ad | 2010-09-17 13:48:45 +0900 | [diff] [blame] | 505 | for (i = 0; i < num; i++) |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 506 | *(start + i) = (u16)(fsi_reg_read(fsi, DIDT) >> 8); |
| 507 | } |
| 508 | |
Kuninori Morimoto | 5bfb9ad | 2010-09-17 13:48:45 +0900 | [diff] [blame] | 509 | static void fsi_dma_soft_push32(struct fsi_priv *fsi, int num) |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 510 | { |
| 511 | u32 *start; |
| 512 | int i; |
| 513 | |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 514 | start = (u32 *)fsi_dma_get_area(fsi, SNDRV_PCM_STREAM_PLAYBACK); |
| 515 | |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 516 | |
Kuninori Morimoto | 5bfb9ad | 2010-09-17 13:48:45 +0900 | [diff] [blame] | 517 | for (i = 0; i < num; i++) |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 518 | fsi_reg_write(fsi, DODT, *(start + i)); |
| 519 | } |
| 520 | |
Kuninori Morimoto | 5bfb9ad | 2010-09-17 13:48:45 +0900 | [diff] [blame] | 521 | static void fsi_dma_soft_pop32(struct fsi_priv *fsi, int num) |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 522 | { |
| 523 | u32 *start; |
| 524 | int i; |
| 525 | |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 526 | start = (u32 *)fsi_dma_get_area(fsi, SNDRV_PCM_STREAM_CAPTURE); |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 527 | |
Kuninori Morimoto | 5bfb9ad | 2010-09-17 13:48:45 +0900 | [diff] [blame] | 528 | for (i = 0; i < num; i++) |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 529 | *(start + i) = fsi_reg_read(fsi, DIDT); |
| 530 | } |
| 531 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 532 | /* |
| 533 | * irq function |
| 534 | */ |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 535 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 536 | static void fsi_irq_enable(struct fsi_priv *fsi, int is_play) |
| 537 | { |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 538 | u32 data = AB_IO(1, fsi_get_port_shift(fsi, is_play)); |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 539 | struct fsi_master *master = fsi_get_master(fsi); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 540 | |
Kuninori Morimoto | 43fa95c | 2010-12-03 17:38:03 +0900 | [diff] [blame] | 541 | fsi_core_mask_set(master, imsk, data, data); |
| 542 | fsi_core_mask_set(master, iemsk, data, data); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | static void fsi_irq_disable(struct fsi_priv *fsi, int is_play) |
| 546 | { |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 547 | u32 data = AB_IO(1, fsi_get_port_shift(fsi, is_play)); |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 548 | struct fsi_master *master = fsi_get_master(fsi); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 549 | |
Kuninori Morimoto | 43fa95c | 2010-12-03 17:38:03 +0900 | [diff] [blame] | 550 | fsi_core_mask_set(master, imsk, data, 0); |
| 551 | fsi_core_mask_set(master, iemsk, data, 0); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 552 | } |
| 553 | |
Kuninori Morimoto | 10ea76c | 2010-03-23 11:47:54 +0900 | [diff] [blame] | 554 | static u32 fsi_irq_get_status(struct fsi_master *master) |
| 555 | { |
Kuninori Morimoto | 43fa95c | 2010-12-03 17:38:03 +0900 | [diff] [blame] | 556 | return fsi_core_read(master, int_st); |
Kuninori Morimoto | 10ea76c | 2010-03-23 11:47:54 +0900 | [diff] [blame] | 557 | } |
| 558 | |
Kuninori Morimoto | 10ea76c | 2010-03-23 11:47:54 +0900 | [diff] [blame] | 559 | static void fsi_irq_clear_status(struct fsi_priv *fsi) |
| 560 | { |
| 561 | u32 data = 0; |
| 562 | struct fsi_master *master = fsi_get_master(fsi); |
| 563 | |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 564 | data |= AB_IO(1, fsi_get_port_shift(fsi, 0)); |
| 565 | data |= AB_IO(1, fsi_get_port_shift(fsi, 1)); |
Kuninori Morimoto | 10ea76c | 2010-03-23 11:47:54 +0900 | [diff] [blame] | 566 | |
| 567 | /* clear interrupt factor */ |
Kuninori Morimoto | 43fa95c | 2010-12-03 17:38:03 +0900 | [diff] [blame] | 568 | fsi_core_mask_set(master, int_st, data, 0); |
Kuninori Morimoto | 10ea76c | 2010-03-23 11:47:54 +0900 | [diff] [blame] | 569 | } |
| 570 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 571 | /* |
| 572 | * SPDIF master clock function |
| 573 | * |
| 574 | * These functions are used later FSI2 |
| 575 | */ |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 576 | static void fsi_spdif_clk_ctrl(struct fsi_priv *fsi, int enable) |
| 577 | { |
| 578 | struct fsi_master *master = fsi_get_master(fsi); |
Kuninori Morimoto | 2b0e730 | 2010-12-03 17:37:44 +0900 | [diff] [blame] | 579 | u32 mask, val; |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 580 | |
| 581 | if (master->core->ver < 2) { |
| 582 | pr_err("fsi: register access err (%s)\n", __func__); |
| 583 | return; |
| 584 | } |
| 585 | |
Kuninori Morimoto | 2b0e730 | 2010-12-03 17:37:44 +0900 | [diff] [blame] | 586 | mask = BP | SE; |
| 587 | val = enable ? mask : 0; |
| 588 | |
| 589 | fsi_is_port_a(fsi) ? |
Kuninori Morimoto | 43fa95c | 2010-12-03 17:38:03 +0900 | [diff] [blame] | 590 | fsi_core_mask_set(master, a_mclk, mask, val) : |
| 591 | fsi_core_mask_set(master, b_mclk, mask, val); |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 592 | } |
| 593 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 594 | /* |
Kuninori Morimoto | 1f5e2a3 | 2011-04-21 10:33:52 +0900 | [diff] [blame] | 595 | * clock function |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 596 | */ |
Kuninori Morimoto | 4f56cde | 2011-05-23 20:46:18 +0900 | [diff] [blame] | 597 | static int fsi_set_master_clk(struct device *dev, struct fsi_priv *fsi, |
| 598 | long rate, int enable) |
| 599 | { |
| 600 | struct fsi_master *master = fsi_get_master(fsi); |
| 601 | set_rate_func set_rate = fsi_get_info_set_rate(master); |
| 602 | int fsi_ver = master->core->ver; |
| 603 | int ret; |
| 604 | |
| 605 | ret = set_rate(dev, fsi_is_port_a(fsi), rate, enable); |
| 606 | if (ret < 0) /* error */ |
| 607 | return ret; |
| 608 | |
| 609 | if (!enable) |
| 610 | return 0; |
| 611 | |
| 612 | if (ret > 0) { |
| 613 | u32 data = 0; |
| 614 | |
| 615 | switch (ret & SH_FSI_ACKMD_MASK) { |
| 616 | default: |
| 617 | /* FALL THROUGH */ |
| 618 | case SH_FSI_ACKMD_512: |
| 619 | data |= (0x0 << 12); |
| 620 | break; |
| 621 | case SH_FSI_ACKMD_256: |
| 622 | data |= (0x1 << 12); |
| 623 | break; |
| 624 | case SH_FSI_ACKMD_128: |
| 625 | data |= (0x2 << 12); |
| 626 | break; |
| 627 | case SH_FSI_ACKMD_64: |
| 628 | data |= (0x3 << 12); |
| 629 | break; |
| 630 | case SH_FSI_ACKMD_32: |
| 631 | if (fsi_ver < 2) |
| 632 | dev_err(dev, "unsupported ACKMD\n"); |
| 633 | else |
| 634 | data |= (0x4 << 12); |
| 635 | break; |
| 636 | } |
| 637 | |
| 638 | switch (ret & SH_FSI_BPFMD_MASK) { |
| 639 | default: |
| 640 | /* FALL THROUGH */ |
| 641 | case SH_FSI_BPFMD_32: |
| 642 | data |= (0x0 << 8); |
| 643 | break; |
| 644 | case SH_FSI_BPFMD_64: |
| 645 | data |= (0x1 << 8); |
| 646 | break; |
| 647 | case SH_FSI_BPFMD_128: |
| 648 | data |= (0x2 << 8); |
| 649 | break; |
| 650 | case SH_FSI_BPFMD_256: |
| 651 | data |= (0x3 << 8); |
| 652 | break; |
| 653 | case SH_FSI_BPFMD_512: |
| 654 | data |= (0x4 << 8); |
| 655 | break; |
| 656 | case SH_FSI_BPFMD_16: |
| 657 | if (fsi_ver < 2) |
| 658 | dev_err(dev, "unsupported ACKMD\n"); |
| 659 | else |
| 660 | data |= (0x7 << 8); |
| 661 | break; |
| 662 | } |
| 663 | |
| 664 | fsi_reg_mask_set(fsi, CKG1, (ACKMD_MASK | BPFMD_MASK) , data); |
| 665 | udelay(10); |
| 666 | ret = 0; |
| 667 | } |
| 668 | |
| 669 | return ret; |
Kuninori Morimoto | 4f56cde | 2011-05-23 20:46:18 +0900 | [diff] [blame] | 670 | } |
| 671 | |
Kuninori Morimoto | 1ddddd3 | 2011-05-23 20:46:23 +0900 | [diff] [blame] | 672 | #define fsi_port_start(f, i) __fsi_port_clk_ctrl(f, i, 1) |
| 673 | #define fsi_port_stop(f, i) __fsi_port_clk_ctrl(f, i, 0) |
| 674 | static void __fsi_port_clk_ctrl(struct fsi_priv *fsi, int is_play, int enable) |
Kuninori Morimoto | 1f5e2a3 | 2011-04-21 10:33:52 +0900 | [diff] [blame] | 675 | { |
| 676 | struct fsi_master *master = fsi_get_master(fsi); |
Kuninori Morimoto | 1f5e2a3 | 2011-04-21 10:33:52 +0900 | [diff] [blame] | 677 | u32 clk = fsi_is_port_a(fsi) ? CRA : CRB; |
Kuninori Morimoto | 1f5e2a3 | 2011-04-21 10:33:52 +0900 | [diff] [blame] | 678 | |
Kuninori Morimoto | 1ddddd3 | 2011-05-23 20:46:23 +0900 | [diff] [blame] | 679 | if (enable) |
| 680 | fsi_irq_enable(fsi, is_play); |
| 681 | else |
| 682 | fsi_irq_disable(fsi, is_play); |
| 683 | |
Kuninori Morimoto | cda828c | 2011-05-23 20:46:35 +0900 | [diff] [blame] | 684 | if (fsi_is_clk_master(fsi)) |
Kuninori Morimoto | 1f5e2a3 | 2011-04-21 10:33:52 +0900 | [diff] [blame] | 685 | fsi_master_mask_set(master, CLK_RST, clk, (enable) ? clk : 0); |
| 686 | } |
| 687 | |
| 688 | /* |
| 689 | * ctrl function |
| 690 | */ |
Kuninori Morimoto | 4a942b4 | 2010-03-25 19:15:51 +0900 | [diff] [blame] | 691 | static void fsi_fifo_init(struct fsi_priv *fsi, |
| 692 | int is_play, |
Kuninori Morimoto | 23ca853 | 2011-05-23 20:46:26 +0900 | [diff] [blame] | 693 | struct device *dev) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 694 | { |
Kuninori Morimoto | 4a942b4 | 2010-03-25 19:15:51 +0900 | [diff] [blame] | 695 | struct fsi_master *master = fsi_get_master(fsi); |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 696 | struct fsi_stream *io = fsi_get_stream(fsi, is_play); |
Kuninori Morimoto | e8c8b63 | 2010-12-03 17:37:55 +0900 | [diff] [blame] | 697 | u32 shift, i; |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 698 | int frame_capa; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 699 | |
Kuninori Morimoto | 4a942b4 | 2010-03-25 19:15:51 +0900 | [diff] [blame] | 700 | /* get on-chip RAM capacity */ |
| 701 | shift = fsi_master_read(master, FIFO_SZ); |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 702 | shift >>= fsi_get_port_shift(fsi, is_play); |
| 703 | shift &= FIFO_SZ_MASK; |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 704 | frame_capa = 256 << shift; |
Kuninori Morimoto | 23ca853 | 2011-05-23 20:46:26 +0900 | [diff] [blame] | 705 | dev_dbg(dev, "fifo = %d words\n", frame_capa); |
Kuninori Morimoto | 4a942b4 | 2010-03-25 19:15:51 +0900 | [diff] [blame] | 706 | |
| 707 | /* |
| 708 | * The maximum number of sample data varies depending |
| 709 | * on the number of channels selected for the format. |
| 710 | * |
| 711 | * FIFOs are used in 4-channel units in 3-channel mode |
| 712 | * and in 8-channel units in 5- to 7-channel mode |
| 713 | * meaning that more FIFOs than the required size of DPRAM |
| 714 | * are used. |
| 715 | * |
| 716 | * ex) if 256 words of DP-RAM is connected |
| 717 | * 1 channel: 256 (256 x 1 = 256) |
| 718 | * 2 channels: 128 (128 x 2 = 256) |
| 719 | * 3 channels: 64 ( 64 x 3 = 192) |
| 720 | * 4 channels: 64 ( 64 x 4 = 256) |
| 721 | * 5 channels: 32 ( 32 x 5 = 160) |
| 722 | * 6 channels: 32 ( 32 x 6 = 192) |
| 723 | * 7 channels: 32 ( 32 x 7 = 224) |
| 724 | * 8 channels: 32 ( 32 x 8 = 256) |
| 725 | */ |
Kuninori Morimoto | 160afa7 | 2011-01-24 10:42:08 +0900 | [diff] [blame] | 726 | for (i = 1; i < fsi->chan_num; i <<= 1) |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 727 | frame_capa >>= 1; |
Kuninori Morimoto | 23ca853 | 2011-05-23 20:46:26 +0900 | [diff] [blame] | 728 | dev_dbg(dev, "%d channel %d store\n", |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 729 | fsi->chan_num, frame_capa); |
| 730 | |
| 731 | io->fifo_sample_capa = fsi_frame2sample(fsi, frame_capa); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 732 | |
Kuninori Morimoto | e8c8b63 | 2010-12-03 17:37:55 +0900 | [diff] [blame] | 733 | /* |
| 734 | * set interrupt generation factor |
| 735 | * clear FIFO |
| 736 | */ |
| 737 | if (is_play) { |
| 738 | fsi_reg_write(fsi, DOFF_CTL, IRQ_HALF); |
| 739 | fsi_reg_mask_set(fsi, DOFF_CTL, FIFO_CLR, FIFO_CLR); |
| 740 | } else { |
| 741 | fsi_reg_write(fsi, DIFF_CTL, IRQ_HALF); |
| 742 | fsi_reg_mask_set(fsi, DIFF_CTL, FIFO_CLR, FIFO_CLR); |
| 743 | } |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 744 | } |
| 745 | |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 746 | static int fsi_fifo_data_ctrl(struct fsi_priv *fsi, int stream) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 747 | { |
| 748 | struct snd_pcm_runtime *runtime; |
| 749 | struct snd_pcm_substream *substream = NULL; |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 750 | int is_play = fsi_stream_is_play(stream); |
| 751 | struct fsi_stream *io = fsi_get_stream(fsi, is_play); |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 752 | int sample_residues; |
| 753 | int sample_width; |
| 754 | int samples; |
| 755 | int samples_max; |
Kuninori Morimoto | b9fde18 | 2010-09-17 13:48:32 +0900 | [diff] [blame] | 756 | int over_period; |
Kuninori Morimoto | d8b3353 | 2010-09-17 13:49:05 +0900 | [diff] [blame] | 757 | void (*fn)(struct fsi_priv *fsi, int size); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 758 | |
| 759 | if (!fsi || |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 760 | !io->substream || |
| 761 | !io->substream->runtime) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 762 | return -EINVAL; |
| 763 | |
Kuninori Morimoto | 1c418d1 | 2009-12-28 14:09:05 +0900 | [diff] [blame] | 764 | over_period = 0; |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 765 | substream = io->substream; |
Kuninori Morimoto | 1c418d1 | 2009-12-28 14:09:05 +0900 | [diff] [blame] | 766 | runtime = substream->runtime; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 767 | |
| 768 | /* FSI FIFO has limit. |
| 769 | * So, this driver can not send periods data at a time |
| 770 | */ |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 771 | if (io->buff_sample_pos >= |
| 772 | io->period_samples * (io->period_pos + 1)) { |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 773 | |
Kuninori Morimoto | 1c418d1 | 2009-12-28 14:09:05 +0900 | [diff] [blame] | 774 | over_period = 1; |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 775 | io->period_pos = (io->period_pos + 1) % runtime->periods; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 776 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 777 | if (0 == io->period_pos) |
| 778 | io->buff_sample_pos = 0; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 779 | } |
| 780 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 781 | /* get 1 sample data width */ |
| 782 | sample_width = samples_to_bytes(runtime, 1); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 783 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 784 | /* get number of residue samples */ |
| 785 | sample_residues = io->buff_sample_capa - io->buff_sample_pos; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 786 | |
Kuninori Morimoto | d8b3353 | 2010-09-17 13:49:05 +0900 | [diff] [blame] | 787 | if (is_play) { |
| 788 | /* |
| 789 | * for play-back |
| 790 | * |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 791 | * samples_max : number of FSI fifo free samples space |
| 792 | * samples : number of ALSA residue samples |
Kuninori Morimoto | d8b3353 | 2010-09-17 13:49:05 +0900 | [diff] [blame] | 793 | */ |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 794 | samples_max = io->fifo_sample_capa; |
| 795 | samples_max -= fsi_get_current_fifo_samples(fsi, is_play); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 796 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 797 | samples = sample_residues; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 798 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 799 | switch (sample_width) { |
Kuninori Morimoto | d8b3353 | 2010-09-17 13:49:05 +0900 | [diff] [blame] | 800 | case 2: |
| 801 | fn = fsi_dma_soft_push16; |
| 802 | break; |
| 803 | case 4: |
| 804 | fn = fsi_dma_soft_push32; |
| 805 | break; |
| 806 | default: |
| 807 | return -EINVAL; |
| 808 | } |
| 809 | } else { |
| 810 | /* |
| 811 | * for capture |
| 812 | * |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 813 | * samples_max : number of ALSA free samples space |
| 814 | * samples : number of samples in FSI fifo |
Kuninori Morimoto | d8b3353 | 2010-09-17 13:49:05 +0900 | [diff] [blame] | 815 | */ |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 816 | samples_max = sample_residues; |
| 817 | samples = fsi_get_current_fifo_samples(fsi, is_play); |
Kuninori Morimoto | d8b3353 | 2010-09-17 13:49:05 +0900 | [diff] [blame] | 818 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 819 | switch (sample_width) { |
Kuninori Morimoto | d8b3353 | 2010-09-17 13:49:05 +0900 | [diff] [blame] | 820 | case 2: |
| 821 | fn = fsi_dma_soft_pop16; |
| 822 | break; |
| 823 | case 4: |
| 824 | fn = fsi_dma_soft_pop32; |
| 825 | break; |
| 826 | default: |
| 827 | return -EINVAL; |
| 828 | } |
Kuninori Morimoto | 9ddc9aa | 2009-10-30 12:02:39 +0900 | [diff] [blame] | 829 | } |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 830 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 831 | samples = min(samples, samples_max); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 832 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 833 | fn(fsi, samples); |
Kuninori Morimoto | d8b3353 | 2010-09-17 13:49:05 +0900 | [diff] [blame] | 834 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 835 | /* update buff_sample_pos */ |
| 836 | io->buff_sample_pos += samples; |
Kuninori Morimoto | d8b3353 | 2010-09-17 13:49:05 +0900 | [diff] [blame] | 837 | |
Kuninori Morimoto | 1c418d1 | 2009-12-28 14:09:05 +0900 | [diff] [blame] | 838 | if (over_period) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 839 | snd_pcm_period_elapsed(substream); |
| 840 | |
Kuninori Morimoto | 47fc9a0 | 2010-02-22 16:41:57 +0900 | [diff] [blame] | 841 | return 0; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 842 | } |
| 843 | |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 844 | static int fsi_data_pop(struct fsi_priv *fsi) |
Kuninori Morimoto | 07102f3 | 2009-10-30 12:02:44 +0900 | [diff] [blame] | 845 | { |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 846 | return fsi_fifo_data_ctrl(fsi, SNDRV_PCM_STREAM_CAPTURE); |
Kuninori Morimoto | d8b3353 | 2010-09-17 13:49:05 +0900 | [diff] [blame] | 847 | } |
Kuninori Morimoto | 07102f3 | 2009-10-30 12:02:44 +0900 | [diff] [blame] | 848 | |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 849 | static int fsi_data_push(struct fsi_priv *fsi) |
Kuninori Morimoto | d8b3353 | 2010-09-17 13:49:05 +0900 | [diff] [blame] | 850 | { |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 851 | return fsi_fifo_data_ctrl(fsi, SNDRV_PCM_STREAM_PLAYBACK); |
Kuninori Morimoto | 07102f3 | 2009-10-30 12:02:44 +0900 | [diff] [blame] | 852 | } |
| 853 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 854 | static irqreturn_t fsi_interrupt(int irq, void *data) |
| 855 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 856 | struct fsi_master *master = data; |
Kuninori Morimoto | 10ea76c | 2010-03-23 11:47:54 +0900 | [diff] [blame] | 857 | u32 int_st = fsi_irq_get_status(master); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 858 | |
| 859 | /* clear irq status */ |
Kuninori Morimoto | feb58cf | 2010-03-24 15:27:24 +0900 | [diff] [blame] | 860 | fsi_master_mask_set(master, SOFT_RST, IR, 0); |
| 861 | fsi_master_mask_set(master, SOFT_RST, IR, IR); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 862 | |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 863 | if (int_st & AB_IO(1, AO_SHIFT)) |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 864 | fsi_data_push(&master->fsia); |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 865 | if (int_st & AB_IO(1, BO_SHIFT)) |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 866 | fsi_data_push(&master->fsib); |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 867 | if (int_st & AB_IO(1, AI_SHIFT)) |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 868 | fsi_data_pop(&master->fsia); |
Kuninori Morimoto | cf6edd0 | 2010-10-12 11:40:53 +0900 | [diff] [blame] | 869 | if (int_st & AB_IO(1, BI_SHIFT)) |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 870 | fsi_data_pop(&master->fsib); |
| 871 | |
| 872 | fsi_count_fifo_err(&master->fsia); |
| 873 | fsi_count_fifo_err(&master->fsib); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 874 | |
Kuninori Morimoto | 48d78e5 | 2010-12-03 17:37:31 +0900 | [diff] [blame] | 875 | fsi_irq_clear_status(&master->fsia); |
| 876 | fsi_irq_clear_status(&master->fsib); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 877 | |
| 878 | return IRQ_HANDLED; |
| 879 | } |
| 880 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 881 | /* |
| 882 | * dai ops |
| 883 | */ |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 884 | |
Kuninori Morimoto | 23ca853 | 2011-05-23 20:46:26 +0900 | [diff] [blame] | 885 | static int fsi_hw_startup(struct fsi_priv *fsi, |
| 886 | int is_play, |
| 887 | struct device *dev) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 888 | { |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 889 | u32 flags = fsi_get_info_flags(fsi); |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 890 | u32 data = 0; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 891 | |
Kuninori Morimoto | 23ca853 | 2011-05-23 20:46:26 +0900 | [diff] [blame] | 892 | pm_runtime_get_sync(dev); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 893 | |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 894 | /* clock setting */ |
| 895 | if (fsi_is_clk_master(fsi)) |
| 896 | data = DIMD | DOMD; |
| 897 | |
| 898 | fsi_reg_mask_set(fsi, CKG1, (DIMD | DOMD), data); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 899 | |
| 900 | /* clock inversion (CKG2) */ |
| 901 | data = 0; |
Kuninori Morimoto | b427b44 | 2010-07-13 12:01:15 +0900 | [diff] [blame] | 902 | if (SH_FSI_LRM_INV & flags) |
| 903 | data |= 1 << 12; |
| 904 | if (SH_FSI_BRM_INV & flags) |
| 905 | data |= 1 << 8; |
| 906 | if (SH_FSI_LRS_INV & flags) |
| 907 | data |= 1 << 4; |
| 908 | if (SH_FSI_BRS_INV & flags) |
| 909 | data |= 1 << 0; |
| 910 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 911 | fsi_reg_write(fsi, CKG2, data); |
| 912 | |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 913 | /* set format */ |
| 914 | fsi_reg_write(fsi, DO_FMT, fsi->do_fmt); |
| 915 | fsi_reg_write(fsi, DI_FMT, fsi->di_fmt); |
| 916 | |
| 917 | /* spdif ? */ |
| 918 | if (fsi_is_spdif(fsi)) { |
| 919 | fsi_spdif_clk_ctrl(fsi, 1); |
| 920 | fsi_reg_mask_set(fsi, OUT_SEL, DMMD, DMMD); |
| 921 | } |
| 922 | |
Kuninori Morimoto | 10ea76c | 2010-03-23 11:47:54 +0900 | [diff] [blame] | 923 | /* irq clear */ |
| 924 | fsi_irq_disable(fsi, is_play); |
| 925 | fsi_irq_clear_status(fsi); |
| 926 | |
| 927 | /* fifo init */ |
Kuninori Morimoto | 23ca853 | 2011-05-23 20:46:26 +0900 | [diff] [blame] | 928 | fsi_fifo_init(fsi, is_play, dev); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 929 | |
Kuninori Morimoto | a68a3b4 | 2010-10-12 11:39:50 +0900 | [diff] [blame] | 930 | return 0; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 931 | } |
| 932 | |
Kuninori Morimoto | 23ca853 | 2011-05-23 20:46:26 +0900 | [diff] [blame] | 933 | static void fsi_hw_shutdown(struct fsi_priv *fsi, |
| 934 | int is_play, |
| 935 | struct device *dev) |
| 936 | { |
| 937 | if (fsi_is_clk_master(fsi)) |
| 938 | fsi_set_master_clk(dev, fsi, fsi->rate, 0); |
| 939 | |
| 940 | pm_runtime_put_sync(dev); |
| 941 | } |
| 942 | |
| 943 | static int fsi_dai_startup(struct snd_pcm_substream *substream, |
| 944 | struct snd_soc_dai *dai) |
| 945 | { |
| 946 | struct fsi_priv *fsi = fsi_get_priv(substream); |
| 947 | int is_play = fsi_is_play(substream); |
| 948 | |
| 949 | return fsi_hw_startup(fsi, is_play, dai->dev); |
| 950 | } |
| 951 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 952 | static void fsi_dai_shutdown(struct snd_pcm_substream *substream, |
| 953 | struct snd_soc_dai *dai) |
| 954 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 955 | struct fsi_priv *fsi = fsi_get_priv(substream); |
Kuninori Morimoto | 23ca853 | 2011-05-23 20:46:26 +0900 | [diff] [blame] | 956 | int is_play = fsi_is_play(substream); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 957 | |
Kuninori Morimoto | 23ca853 | 2011-05-23 20:46:26 +0900 | [diff] [blame] | 958 | fsi_hw_shutdown(fsi, is_play, dai->dev); |
Kuninori Morimoto | d4bc99b | 2010-11-24 02:44:06 +0000 | [diff] [blame] | 959 | fsi->rate = 0; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | static int fsi_dai_trigger(struct snd_pcm_substream *substream, int cmd, |
| 963 | struct snd_soc_dai *dai) |
| 964 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 965 | struct fsi_priv *fsi = fsi_get_priv(substream); |
Kuninori Morimoto | 0054578 | 2010-10-12 18:30:14 +0900 | [diff] [blame] | 966 | int is_play = fsi_is_play(substream); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 967 | int ret = 0; |
| 968 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 969 | switch (cmd) { |
| 970 | case SNDRV_PCM_TRIGGER_START: |
Kuninori Morimoto | 0ffe296 | 2011-05-23 20:45:57 +0900 | [diff] [blame] | 971 | fsi_stream_push(fsi, is_play, substream); |
Kuninori Morimoto | 1ec9bc3 | 2010-12-17 12:55:22 +0900 | [diff] [blame] | 972 | ret = is_play ? fsi_data_push(fsi) : fsi_data_pop(fsi); |
Kuninori Morimoto | 1ddddd3 | 2011-05-23 20:46:23 +0900 | [diff] [blame] | 973 | fsi_port_start(fsi, is_play); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 974 | break; |
| 975 | case SNDRV_PCM_TRIGGER_STOP: |
Kuninori Morimoto | 1ddddd3 | 2011-05-23 20:46:23 +0900 | [diff] [blame] | 976 | fsi_port_stop(fsi, is_play); |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 977 | fsi_stream_pop(fsi, is_play); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 978 | break; |
| 979 | } |
| 980 | |
| 981 | return ret; |
| 982 | } |
| 983 | |
Kuninori Morimoto | f17c13c | 2011-01-24 10:43:19 +0900 | [diff] [blame] | 984 | static int fsi_set_fmt_dai(struct fsi_priv *fsi, unsigned int fmt) |
| 985 | { |
| 986 | u32 data = 0; |
| 987 | |
| 988 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 989 | case SND_SOC_DAIFMT_I2S: |
| 990 | data = CR_I2S; |
| 991 | fsi->chan_num = 2; |
| 992 | break; |
| 993 | case SND_SOC_DAIFMT_LEFT_J: |
| 994 | data = CR_PCM; |
| 995 | fsi->chan_num = 2; |
| 996 | break; |
| 997 | default: |
| 998 | return -EINVAL; |
| 999 | } |
| 1000 | |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 1001 | fsi->do_fmt = data; |
| 1002 | fsi->di_fmt = data; |
Kuninori Morimoto | f17c13c | 2011-01-24 10:43:19 +0900 | [diff] [blame] | 1003 | |
| 1004 | return 0; |
| 1005 | } |
| 1006 | |
| 1007 | static int fsi_set_fmt_spdif(struct fsi_priv *fsi) |
| 1008 | { |
| 1009 | struct fsi_master *master = fsi_get_master(fsi); |
| 1010 | u32 data = 0; |
| 1011 | |
| 1012 | if (master->core->ver < 2) |
| 1013 | return -EINVAL; |
| 1014 | |
| 1015 | data = CR_BWS_16 | CR_DTMD_SPDIF_PCM | CR_PCM; |
| 1016 | fsi->chan_num = 2; |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 1017 | fsi->spdif = 1; |
Kuninori Morimoto | f17c13c | 2011-01-24 10:43:19 +0900 | [diff] [blame] | 1018 | |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 1019 | fsi->do_fmt = data; |
| 1020 | fsi->di_fmt = data; |
Kuninori Morimoto | f17c13c | 2011-01-24 10:43:19 +0900 | [diff] [blame] | 1021 | |
| 1022 | return 0; |
| 1023 | } |
| 1024 | |
Kuninori Morimoto | 4d805f7 | 2011-01-20 11:46:02 +0900 | [diff] [blame] | 1025 | static int fsi_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) |
| 1026 | { |
| 1027 | struct fsi_priv *fsi = fsi_get_priv_frm_dai(dai); |
Kuninori Morimoto | 6a9ebad | 2011-04-21 10:33:36 +0900 | [diff] [blame] | 1028 | struct fsi_master *master = fsi_get_master(fsi); |
| 1029 | set_rate_func set_rate = fsi_get_info_set_rate(master); |
Kuninori Morimoto | f17c13c | 2011-01-24 10:43:19 +0900 | [diff] [blame] | 1030 | u32 flags = fsi_get_info_flags(fsi); |
Kuninori Morimoto | 4d805f7 | 2011-01-20 11:46:02 +0900 | [diff] [blame] | 1031 | int ret; |
| 1032 | |
Kuninori Morimoto | 4d805f7 | 2011-01-20 11:46:02 +0900 | [diff] [blame] | 1033 | /* set master/slave audio interface */ |
| 1034 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 1035 | case SND_SOC_DAIFMT_CBM_CFM: |
Kuninori Morimoto | 6a9ebad | 2011-04-21 10:33:36 +0900 | [diff] [blame] | 1036 | fsi->clk_master = 1; |
Kuninori Morimoto | 4d805f7 | 2011-01-20 11:46:02 +0900 | [diff] [blame] | 1037 | break; |
| 1038 | case SND_SOC_DAIFMT_CBS_CFS: |
| 1039 | break; |
| 1040 | default: |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 1041 | return -EINVAL; |
Kuninori Morimoto | 4d805f7 | 2011-01-20 11:46:02 +0900 | [diff] [blame] | 1042 | } |
Kuninori Morimoto | 6a9ebad | 2011-04-21 10:33:36 +0900 | [diff] [blame] | 1043 | |
| 1044 | if (fsi_is_clk_master(fsi) && !set_rate) { |
| 1045 | dev_err(dai->dev, "platform doesn't have set_rate\n"); |
Kuninori Morimoto | 9478e0b | 2011-05-23 20:46:07 +0900 | [diff] [blame] | 1046 | return -EINVAL; |
Kuninori Morimoto | 6a9ebad | 2011-04-21 10:33:36 +0900 | [diff] [blame] | 1047 | } |
| 1048 | |
Kuninori Morimoto | f17c13c | 2011-01-24 10:43:19 +0900 | [diff] [blame] | 1049 | /* set format */ |
| 1050 | switch (flags & SH_FSI_FMT_MASK) { |
| 1051 | case SH_FSI_FMT_DAI: |
| 1052 | ret = fsi_set_fmt_dai(fsi, fmt & SND_SOC_DAIFMT_FORMAT_MASK); |
| 1053 | break; |
| 1054 | case SH_FSI_FMT_SPDIF: |
| 1055 | ret = fsi_set_fmt_spdif(fsi); |
| 1056 | break; |
| 1057 | default: |
| 1058 | ret = -EINVAL; |
| 1059 | } |
Kuninori Morimoto | 4d805f7 | 2011-01-20 11:46:02 +0900 | [diff] [blame] | 1060 | |
Kuninori Morimoto | 4d805f7 | 2011-01-20 11:46:02 +0900 | [diff] [blame] | 1061 | return ret; |
| 1062 | } |
| 1063 | |
Kuninori Morimoto | ccad7b4 | 2010-07-13 12:13:14 +0900 | [diff] [blame] | 1064 | static int fsi_dai_hw_params(struct snd_pcm_substream *substream, |
| 1065 | struct snd_pcm_hw_params *params, |
| 1066 | struct snd_soc_dai *dai) |
| 1067 | { |
| 1068 | struct fsi_priv *fsi = fsi_get_priv(substream); |
Kuninori Morimoto | d4bc99b | 2010-11-24 02:44:06 +0000 | [diff] [blame] | 1069 | long rate = params_rate(params); |
Kuninori Morimoto | ccad7b4 | 2010-07-13 12:13:14 +0900 | [diff] [blame] | 1070 | int ret; |
| 1071 | |
Kuninori Morimoto | 6a9ebad | 2011-04-21 10:33:36 +0900 | [diff] [blame] | 1072 | if (!fsi_is_clk_master(fsi)) |
Kuninori Morimoto | ccad7b4 | 2010-07-13 12:13:14 +0900 | [diff] [blame] | 1073 | return 0; |
| 1074 | |
Kuninori Morimoto | 4f56cde | 2011-05-23 20:46:18 +0900 | [diff] [blame] | 1075 | ret = fsi_set_master_clk(dai->dev, fsi, rate, 1); |
| 1076 | if (ret < 0) |
Kuninori Morimoto | d4bc99b | 2010-11-24 02:44:06 +0000 | [diff] [blame] | 1077 | return ret; |
Kuninori Morimoto | ccad7b4 | 2010-07-13 12:13:14 +0900 | [diff] [blame] | 1078 | |
Kuninori Morimoto | d4bc99b | 2010-11-24 02:44:06 +0000 | [diff] [blame] | 1079 | fsi->rate = rate; |
Kuninori Morimoto | ccad7b4 | 2010-07-13 12:13:14 +0900 | [diff] [blame] | 1080 | |
| 1081 | return ret; |
Kuninori Morimoto | ccad7b4 | 2010-07-13 12:13:14 +0900 | [diff] [blame] | 1082 | } |
| 1083 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1084 | static struct snd_soc_dai_ops fsi_dai_ops = { |
| 1085 | .startup = fsi_dai_startup, |
| 1086 | .shutdown = fsi_dai_shutdown, |
| 1087 | .trigger = fsi_dai_trigger, |
Kuninori Morimoto | 4d805f7 | 2011-01-20 11:46:02 +0900 | [diff] [blame] | 1088 | .set_fmt = fsi_dai_set_fmt, |
Kuninori Morimoto | ccad7b4 | 2010-07-13 12:13:14 +0900 | [diff] [blame] | 1089 | .hw_params = fsi_dai_hw_params, |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1090 | }; |
| 1091 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 1092 | /* |
| 1093 | * pcm ops |
| 1094 | */ |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1095 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1096 | static struct snd_pcm_hardware fsi_pcm_hardware = { |
| 1097 | .info = SNDRV_PCM_INFO_INTERLEAVED | |
| 1098 | SNDRV_PCM_INFO_MMAP | |
| 1099 | SNDRV_PCM_INFO_MMAP_VALID | |
| 1100 | SNDRV_PCM_INFO_PAUSE, |
| 1101 | .formats = FSI_FMTS, |
| 1102 | .rates = FSI_RATES, |
| 1103 | .rate_min = 8000, |
| 1104 | .rate_max = 192000, |
| 1105 | .channels_min = 1, |
| 1106 | .channels_max = 2, |
| 1107 | .buffer_bytes_max = 64 * 1024, |
| 1108 | .period_bytes_min = 32, |
| 1109 | .period_bytes_max = 8192, |
| 1110 | .periods_min = 1, |
| 1111 | .periods_max = 32, |
| 1112 | .fifo_size = 256, |
| 1113 | }; |
| 1114 | |
| 1115 | static int fsi_pcm_open(struct snd_pcm_substream *substream) |
| 1116 | { |
| 1117 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1118 | int ret = 0; |
| 1119 | |
| 1120 | snd_soc_set_runtime_hwparams(substream, &fsi_pcm_hardware); |
| 1121 | |
| 1122 | ret = snd_pcm_hw_constraint_integer(runtime, |
| 1123 | SNDRV_PCM_HW_PARAM_PERIODS); |
| 1124 | |
| 1125 | return ret; |
| 1126 | } |
| 1127 | |
| 1128 | static int fsi_hw_params(struct snd_pcm_substream *substream, |
| 1129 | struct snd_pcm_hw_params *hw_params) |
| 1130 | { |
| 1131 | return snd_pcm_lib_malloc_pages(substream, |
| 1132 | params_buffer_bytes(hw_params)); |
| 1133 | } |
| 1134 | |
| 1135 | static int fsi_hw_free(struct snd_pcm_substream *substream) |
| 1136 | { |
| 1137 | return snd_pcm_lib_free_pages(substream); |
| 1138 | } |
| 1139 | |
| 1140 | static snd_pcm_uframes_t fsi_pointer(struct snd_pcm_substream *substream) |
| 1141 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 1142 | struct fsi_priv *fsi = fsi_get_priv(substream); |
Kuninori Morimoto | 93193c2 | 2010-10-12 19:19:28 +0900 | [diff] [blame] | 1143 | struct fsi_stream *io = fsi_get_stream(fsi, fsi_is_play(substream)); |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 1144 | int samples_pos = io->buff_sample_pos - 1; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1145 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 1146 | if (samples_pos < 0) |
| 1147 | samples_pos = 0; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1148 | |
Kuninori Morimoto | 2e651ba | 2011-05-23 20:46:03 +0900 | [diff] [blame] | 1149 | return fsi_sample2frame(fsi, samples_pos); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | static struct snd_pcm_ops fsi_pcm_ops = { |
| 1153 | .open = fsi_pcm_open, |
| 1154 | .ioctl = snd_pcm_lib_ioctl, |
| 1155 | .hw_params = fsi_hw_params, |
| 1156 | .hw_free = fsi_hw_free, |
| 1157 | .pointer = fsi_pointer, |
| 1158 | }; |
| 1159 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 1160 | /* |
| 1161 | * snd_soc_platform |
| 1162 | */ |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1163 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1164 | #define PREALLOC_BUFFER (32 * 1024) |
| 1165 | #define PREALLOC_BUFFER_MAX (32 * 1024) |
| 1166 | |
| 1167 | static void fsi_pcm_free(struct snd_pcm *pcm) |
| 1168 | { |
| 1169 | snd_pcm_lib_preallocate_free_for_all(pcm); |
| 1170 | } |
| 1171 | |
Liam Girdwood | 552d1ef | 2011-06-07 16:08:33 +0100 | [diff] [blame] | 1172 | static int fsi_pcm_new(struct snd_soc_pcm_runtime *rtd) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1173 | { |
Liam Girdwood | 552d1ef | 2011-06-07 16:08:33 +0100 | [diff] [blame] | 1174 | struct snd_pcm *pcm = rtd->pcm; |
| 1175 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1176 | /* |
| 1177 | * dont use SNDRV_DMA_TYPE_DEV, since it will oops the SH kernel |
| 1178 | * in MMAP mode (i.e. aplay -M) |
| 1179 | */ |
| 1180 | return snd_pcm_lib_preallocate_pages_for_all( |
| 1181 | pcm, |
| 1182 | SNDRV_DMA_TYPE_CONTINUOUS, |
| 1183 | snd_dma_continuous_data(GFP_KERNEL), |
| 1184 | PREALLOC_BUFFER, PREALLOC_BUFFER_MAX); |
| 1185 | } |
| 1186 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 1187 | /* |
| 1188 | * alsa struct |
| 1189 | */ |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1190 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1191 | static struct snd_soc_dai_driver fsi_soc_dai[] = { |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1192 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1193 | .name = "fsia-dai", |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1194 | .playback = { |
| 1195 | .rates = FSI_RATES, |
| 1196 | .formats = FSI_FMTS, |
| 1197 | .channels_min = 1, |
| 1198 | .channels_max = 8, |
| 1199 | }, |
Kuninori Morimoto | 07102f3 | 2009-10-30 12:02:44 +0900 | [diff] [blame] | 1200 | .capture = { |
| 1201 | .rates = FSI_RATES, |
| 1202 | .formats = FSI_FMTS, |
| 1203 | .channels_min = 1, |
| 1204 | .channels_max = 8, |
| 1205 | }, |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1206 | .ops = &fsi_dai_ops, |
| 1207 | }, |
| 1208 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1209 | .name = "fsib-dai", |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1210 | .playback = { |
| 1211 | .rates = FSI_RATES, |
| 1212 | .formats = FSI_FMTS, |
| 1213 | .channels_min = 1, |
| 1214 | .channels_max = 8, |
| 1215 | }, |
Kuninori Morimoto | 07102f3 | 2009-10-30 12:02:44 +0900 | [diff] [blame] | 1216 | .capture = { |
| 1217 | .rates = FSI_RATES, |
| 1218 | .formats = FSI_FMTS, |
| 1219 | .channels_min = 1, |
| 1220 | .channels_max = 8, |
| 1221 | }, |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1222 | .ops = &fsi_dai_ops, |
| 1223 | }, |
| 1224 | }; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1225 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1226 | static struct snd_soc_platform_driver fsi_soc_platform = { |
| 1227 | .ops = &fsi_pcm_ops, |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1228 | .pcm_new = fsi_pcm_new, |
| 1229 | .pcm_free = fsi_pcm_free, |
| 1230 | }; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1231 | |
Kuninori Morimoto | c8fe257 | 2010-09-17 13:48:17 +0900 | [diff] [blame] | 1232 | /* |
| 1233 | * platform function |
| 1234 | */ |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1235 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1236 | static int fsi_probe(struct platform_device *pdev) |
| 1237 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 1238 | struct fsi_master *master; |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 1239 | const struct platform_device_id *id_entry; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1240 | struct resource *res; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1241 | unsigned int irq; |
| 1242 | int ret; |
| 1243 | |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 1244 | id_entry = pdev->id_entry; |
| 1245 | if (!id_entry) { |
| 1246 | dev_err(&pdev->dev, "unknown fsi device\n"); |
| 1247 | return -ENODEV; |
| 1248 | } |
| 1249 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1250 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1251 | irq = platform_get_irq(pdev, 0); |
Uwe Kleine-König | b6aa179 | 2009-12-16 17:10:09 +0100 | [diff] [blame] | 1252 | if (!res || (int)irq <= 0) { |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1253 | dev_err(&pdev->dev, "Not enough FSI platform resources.\n"); |
| 1254 | ret = -ENODEV; |
| 1255 | goto exit; |
| 1256 | } |
| 1257 | |
| 1258 | master = kzalloc(sizeof(*master), GFP_KERNEL); |
| 1259 | if (!master) { |
| 1260 | dev_err(&pdev->dev, "Could not allocate master\n"); |
| 1261 | ret = -ENOMEM; |
| 1262 | goto exit; |
| 1263 | } |
| 1264 | |
| 1265 | master->base = ioremap_nocache(res->start, resource_size(res)); |
| 1266 | if (!master->base) { |
| 1267 | ret = -ENXIO; |
| 1268 | dev_err(&pdev->dev, "Unable to ioremap FSI registers.\n"); |
| 1269 | goto exit_kfree; |
| 1270 | } |
| 1271 | |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 1272 | /* master setting */ |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1273 | master->irq = irq; |
| 1274 | master->info = pdev->dev.platform_data; |
Kuninori Morimoto | 73b92c1 | 2010-07-13 12:13:04 +0900 | [diff] [blame] | 1275 | master->core = (struct fsi_core *)id_entry->driver_data; |
Kuninori Morimoto | 8fc176d | 2010-01-28 13:46:16 +0900 | [diff] [blame] | 1276 | spin_lock_init(&master->lock); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1277 | |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 1278 | /* FSI A setting */ |
| 1279 | master->fsia.base = master->base; |
| 1280 | master->fsia.master = master; |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 1281 | |
| 1282 | /* FSI B setting */ |
| 1283 | master->fsib.base = master->base + 0x40; |
| 1284 | master->fsib.master = master; |
Kuninori Morimoto | 3bc2807 | 2010-07-29 16:48:32 +0900 | [diff] [blame] | 1285 | |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 1286 | pm_runtime_enable(&pdev->dev); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1287 | dev_set_drvdata(&pdev->dev, master); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1288 | |
Yong Zhang | 88e24c3 | 2011-09-22 16:59:20 +0800 | [diff] [blame] | 1289 | ret = request_irq(irq, &fsi_interrupt, 0, |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 1290 | id_entry->name, master); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1291 | if (ret) { |
| 1292 | dev_err(&pdev->dev, "irq request err\n"); |
Kuninori Morimoto | 9ddc9aa | 2009-10-30 12:02:39 +0900 | [diff] [blame] | 1293 | goto exit_iounmap; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1294 | } |
| 1295 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1296 | ret = snd_soc_register_platform(&pdev->dev, &fsi_soc_platform); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1297 | if (ret < 0) { |
| 1298 | dev_err(&pdev->dev, "cannot snd soc register\n"); |
| 1299 | goto exit_free_irq; |
| 1300 | } |
| 1301 | |
Kuninori Morimoto | 0b5ec87 | 2011-04-08 15:09:02 +0900 | [diff] [blame] | 1302 | ret = snd_soc_register_dais(&pdev->dev, fsi_soc_dai, |
| 1303 | ARRAY_SIZE(fsi_soc_dai)); |
| 1304 | if (ret < 0) { |
| 1305 | dev_err(&pdev->dev, "cannot snd dai register\n"); |
| 1306 | goto exit_snd_soc; |
| 1307 | } |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1308 | |
Kuninori Morimoto | 0b5ec87 | 2011-04-08 15:09:02 +0900 | [diff] [blame] | 1309 | return ret; |
| 1310 | |
| 1311 | exit_snd_soc: |
| 1312 | snd_soc_unregister_platform(&pdev->dev); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1313 | exit_free_irq: |
| 1314 | free_irq(irq, master); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1315 | exit_iounmap: |
| 1316 | iounmap(master->base); |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 1317 | pm_runtime_disable(&pdev->dev); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1318 | exit_kfree: |
| 1319 | kfree(master); |
| 1320 | master = NULL; |
| 1321 | exit: |
| 1322 | return ret; |
| 1323 | } |
| 1324 | |
| 1325 | static int fsi_remove(struct platform_device *pdev) |
| 1326 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 1327 | struct fsi_master *master; |
| 1328 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1329 | master = dev_get_drvdata(&pdev->dev); |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 1330 | |
Kuninori Morimoto | d985f27 | 2011-04-08 15:09:25 +0900 | [diff] [blame] | 1331 | free_irq(master->irq, master); |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 1332 | pm_runtime_disable(&pdev->dev); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1333 | |
Kuninori Morimoto | d985f27 | 2011-04-08 15:09:25 +0900 | [diff] [blame] | 1334 | snd_soc_unregister_dais(&pdev->dev, ARRAY_SIZE(fsi_soc_dai)); |
| 1335 | snd_soc_unregister_platform(&pdev->dev); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1336 | |
| 1337 | iounmap(master->base); |
| 1338 | kfree(master); |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame] | 1339 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1340 | return 0; |
| 1341 | } |
| 1342 | |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1343 | static void __fsi_suspend(struct fsi_priv *fsi, |
Kuninori Morimoto | cda828c | 2011-05-23 20:46:35 +0900 | [diff] [blame] | 1344 | int is_play, |
Kuninori Morimoto | 4f56cde | 2011-05-23 20:46:18 +0900 | [diff] [blame] | 1345 | struct device *dev) |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1346 | { |
Kuninori Morimoto | cda828c | 2011-05-23 20:46:35 +0900 | [diff] [blame] | 1347 | if (!fsi_stream_is_working(fsi, is_play)) |
| 1348 | return; |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1349 | |
Kuninori Morimoto | cda828c | 2011-05-23 20:46:35 +0900 | [diff] [blame] | 1350 | fsi_port_stop(fsi, is_play); |
| 1351 | fsi_hw_shutdown(fsi, is_play, dev); |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | static void __fsi_resume(struct fsi_priv *fsi, |
Kuninori Morimoto | cda828c | 2011-05-23 20:46:35 +0900 | [diff] [blame] | 1355 | int is_play, |
Kuninori Morimoto | 4f56cde | 2011-05-23 20:46:18 +0900 | [diff] [blame] | 1356 | struct device *dev) |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1357 | { |
Kuninori Morimoto | cda828c | 2011-05-23 20:46:35 +0900 | [diff] [blame] | 1358 | if (!fsi_stream_is_working(fsi, is_play)) |
| 1359 | return; |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1360 | |
Kuninori Morimoto | cda828c | 2011-05-23 20:46:35 +0900 | [diff] [blame] | 1361 | fsi_hw_startup(fsi, is_play, dev); |
| 1362 | |
| 1363 | if (fsi_is_clk_master(fsi) && fsi->rate) |
Kuninori Morimoto | 4f56cde | 2011-05-23 20:46:18 +0900 | [diff] [blame] | 1364 | fsi_set_master_clk(dev, fsi, fsi->rate, 1); |
Kuninori Morimoto | cda828c | 2011-05-23 20:46:35 +0900 | [diff] [blame] | 1365 | |
| 1366 | fsi_port_start(fsi, is_play); |
| 1367 | |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1368 | } |
| 1369 | |
| 1370 | static int fsi_suspend(struct device *dev) |
| 1371 | { |
| 1372 | struct fsi_master *master = dev_get_drvdata(dev); |
Kuninori Morimoto | cda828c | 2011-05-23 20:46:35 +0900 | [diff] [blame] | 1373 | struct fsi_priv *fsia = &master->fsia; |
| 1374 | struct fsi_priv *fsib = &master->fsib; |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1375 | |
Kuninori Morimoto | cda828c | 2011-05-23 20:46:35 +0900 | [diff] [blame] | 1376 | __fsi_suspend(fsia, 1, dev); |
| 1377 | __fsi_suspend(fsia, 0, dev); |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1378 | |
Kuninori Morimoto | cda828c | 2011-05-23 20:46:35 +0900 | [diff] [blame] | 1379 | __fsi_suspend(fsib, 1, dev); |
| 1380 | __fsi_suspend(fsib, 0, dev); |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1381 | |
| 1382 | return 0; |
| 1383 | } |
| 1384 | |
| 1385 | static int fsi_resume(struct device *dev) |
| 1386 | { |
| 1387 | struct fsi_master *master = dev_get_drvdata(dev); |
Kuninori Morimoto | cda828c | 2011-05-23 20:46:35 +0900 | [diff] [blame] | 1388 | struct fsi_priv *fsia = &master->fsia; |
| 1389 | struct fsi_priv *fsib = &master->fsib; |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1390 | |
Kuninori Morimoto | cda828c | 2011-05-23 20:46:35 +0900 | [diff] [blame] | 1391 | __fsi_resume(fsia, 1, dev); |
| 1392 | __fsi_resume(fsia, 0, dev); |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1393 | |
Kuninori Morimoto | cda828c | 2011-05-23 20:46:35 +0900 | [diff] [blame] | 1394 | __fsi_resume(fsib, 1, dev); |
| 1395 | __fsi_resume(fsib, 0, dev); |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1396 | |
| 1397 | return 0; |
| 1398 | } |
| 1399 | |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 1400 | static int fsi_runtime_nop(struct device *dev) |
| 1401 | { |
| 1402 | /* Runtime PM callback shared between ->runtime_suspend() |
| 1403 | * and ->runtime_resume(). Simply returns success. |
| 1404 | * |
| 1405 | * This driver re-initializes all registers after |
| 1406 | * pm_runtime_get_sync() anyway so there is no need |
| 1407 | * to save and restore registers here. |
| 1408 | */ |
| 1409 | return 0; |
| 1410 | } |
| 1411 | |
| 1412 | static struct dev_pm_ops fsi_pm_ops = { |
Kuninori Morimoto | 106c79e | 2011-04-21 10:33:47 +0900 | [diff] [blame] | 1413 | .suspend = fsi_suspend, |
| 1414 | .resume = fsi_resume, |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 1415 | .runtime_suspend = fsi_runtime_nop, |
| 1416 | .runtime_resume = fsi_runtime_nop, |
| 1417 | }; |
| 1418 | |
Kuninori Morimoto | 73b92c1 | 2010-07-13 12:13:04 +0900 | [diff] [blame] | 1419 | static struct fsi_core fsi1_core = { |
| 1420 | .ver = 1, |
| 1421 | |
| 1422 | /* Interrupt */ |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 1423 | .int_st = INT_ST, |
| 1424 | .iemsk = IEMSK, |
| 1425 | .imsk = IMSK, |
| 1426 | }; |
| 1427 | |
Kuninori Morimoto | 73b92c1 | 2010-07-13 12:13:04 +0900 | [diff] [blame] | 1428 | static struct fsi_core fsi2_core = { |
| 1429 | .ver = 2, |
| 1430 | |
| 1431 | /* Interrupt */ |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 1432 | .int_st = CPU_INT_ST, |
| 1433 | .iemsk = CPU_IEMSK, |
| 1434 | .imsk = CPU_IMSK, |
Kuninori Morimoto | 2b0e730 | 2010-12-03 17:37:44 +0900 | [diff] [blame] | 1435 | .a_mclk = A_MST_CTLR, |
| 1436 | .b_mclk = B_MST_CTLR, |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 1437 | }; |
| 1438 | |
| 1439 | static struct platform_device_id fsi_id_table[] = { |
Kuninori Morimoto | 73b92c1 | 2010-07-13 12:13:04 +0900 | [diff] [blame] | 1440 | { "sh_fsi", (kernel_ulong_t)&fsi1_core }, |
| 1441 | { "sh_fsi2", (kernel_ulong_t)&fsi2_core }, |
Guennadi Liakhovetski | 05c6945 | 2010-10-05 17:54:28 +0200 | [diff] [blame] | 1442 | {}, |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 1443 | }; |
Dzianis Kahanovich | d85a6d7 | 2010-09-17 16:42:05 +0300 | [diff] [blame] | 1444 | MODULE_DEVICE_TABLE(platform, fsi_id_table); |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 1445 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1446 | static struct platform_driver fsi_driver = { |
| 1447 | .driver = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1448 | .name = "fsi-pcm-audio", |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 1449 | .pm = &fsi_pm_ops, |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1450 | }, |
| 1451 | .probe = fsi_probe, |
| 1452 | .remove = fsi_remove, |
Kuninori Morimoto | cc780d3 | 2010-03-25 19:15:53 +0900 | [diff] [blame] | 1453 | .id_table = fsi_id_table, |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1454 | }; |
| 1455 | |
| 1456 | static int __init fsi_mobile_init(void) |
| 1457 | { |
| 1458 | return platform_driver_register(&fsi_driver); |
| 1459 | } |
| 1460 | |
| 1461 | static void __exit fsi_mobile_exit(void) |
| 1462 | { |
| 1463 | platform_driver_unregister(&fsi_driver); |
| 1464 | } |
Dzianis Kahanovich | d85a6d7 | 2010-09-17 16:42:05 +0300 | [diff] [blame] | 1465 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 1466 | module_init(fsi_mobile_init); |
| 1467 | module_exit(fsi_mobile_exit); |
| 1468 | |
| 1469 | MODULE_LICENSE("GPL"); |
| 1470 | MODULE_DESCRIPTION("SuperH onchip FSI audio driver"); |
| 1471 | MODULE_AUTHOR("Kuninori Morimoto <morimoto.kuninori@renesas.com>"); |
Guennadi Liakhovetski | b3c27b5 | 2011-04-15 20:17:34 +0200 | [diff] [blame] | 1472 | MODULE_ALIAS("platform:fsi-pcm-audio"); |