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 | |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/delay.h> |
| 19 | #include <linux/list.h> |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 20 | #include <linux/pm_runtime.h> |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 21 | #include <linux/io.h> |
| 22 | #include <sound/core.h> |
| 23 | #include <sound/pcm.h> |
| 24 | #include <sound/initval.h> |
| 25 | #include <sound/soc.h> |
| 26 | #include <sound/pcm_params.h> |
| 27 | #include <sound/sh_fsi.h> |
| 28 | #include <asm/atomic.h> |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 29 | |
| 30 | #define DO_FMT 0x0000 |
| 31 | #define DOFF_CTL 0x0004 |
| 32 | #define DOFF_ST 0x0008 |
| 33 | #define DI_FMT 0x000C |
| 34 | #define DIFF_CTL 0x0010 |
| 35 | #define DIFF_ST 0x0014 |
| 36 | #define CKG1 0x0018 |
| 37 | #define CKG2 0x001C |
| 38 | #define DIDT 0x0020 |
| 39 | #define DODT 0x0024 |
| 40 | #define MUTE_ST 0x0028 |
| 41 | #define REG_END MUTE_ST |
| 42 | |
| 43 | #define INT_ST 0x0200 |
| 44 | #define IEMSK 0x0204 |
| 45 | #define IMSK 0x0208 |
| 46 | #define MUTE 0x020C |
| 47 | #define CLK_RST 0x0210 |
| 48 | #define SOFT_RST 0x0214 |
| 49 | #define MREG_START INT_ST |
| 50 | #define MREG_END SOFT_RST |
| 51 | |
| 52 | /* DO_FMT */ |
| 53 | /* DI_FMT */ |
| 54 | #define CR_FMT(param) ((param) << 4) |
| 55 | # define CR_MONO 0x0 |
| 56 | # define CR_MONO_D 0x1 |
| 57 | # define CR_PCM 0x2 |
| 58 | # define CR_I2S 0x3 |
| 59 | # define CR_TDM 0x4 |
| 60 | # define CR_TDM_D 0x5 |
| 61 | |
| 62 | /* DOFF_CTL */ |
| 63 | /* DIFF_CTL */ |
| 64 | #define IRQ_HALF 0x00100000 |
| 65 | #define FIFO_CLR 0x00000001 |
| 66 | |
| 67 | /* DOFF_ST */ |
| 68 | #define ERR_OVER 0x00000010 |
| 69 | #define ERR_UNDER 0x00000001 |
| 70 | |
| 71 | /* CLK_RST */ |
| 72 | #define B_CLK 0x00000010 |
| 73 | #define A_CLK 0x00000001 |
| 74 | |
| 75 | /* INT_ST */ |
| 76 | #define INT_B_IN (1 << 12) |
| 77 | #define INT_B_OUT (1 << 8) |
| 78 | #define INT_A_IN (1 << 4) |
| 79 | #define INT_A_OUT (1 << 0) |
| 80 | |
| 81 | #define FSI_RATES SNDRV_PCM_RATE_8000_96000 |
| 82 | |
| 83 | #define FSI_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE) |
| 84 | |
| 85 | /************************************************************************ |
| 86 | |
| 87 | |
| 88 | struct |
| 89 | |
| 90 | |
| 91 | ************************************************************************/ |
| 92 | struct fsi_priv { |
| 93 | void __iomem *base; |
| 94 | struct snd_pcm_substream *substream; |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 95 | struct fsi_master *master; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 96 | |
| 97 | int fifo_max; |
| 98 | int chan; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 99 | |
| 100 | int byte_offset; |
| 101 | int period_len; |
| 102 | int buffer_len; |
| 103 | int periods; |
| 104 | }; |
| 105 | |
| 106 | struct fsi_master { |
| 107 | void __iomem *base; |
| 108 | int irq; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 109 | struct fsi_priv fsia; |
| 110 | struct fsi_priv fsib; |
| 111 | struct sh_fsi_platform_info *info; |
| 112 | }; |
| 113 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 114 | /************************************************************************ |
| 115 | |
| 116 | |
| 117 | basic read write function |
| 118 | |
| 119 | |
| 120 | ************************************************************************/ |
| 121 | static int __fsi_reg_write(u32 reg, u32 data) |
| 122 | { |
| 123 | /* valid data area is 24bit */ |
| 124 | data &= 0x00ffffff; |
| 125 | |
| 126 | return ctrl_outl(data, reg); |
| 127 | } |
| 128 | |
| 129 | static u32 __fsi_reg_read(u32 reg) |
| 130 | { |
| 131 | return ctrl_inl(reg); |
| 132 | } |
| 133 | |
| 134 | static int __fsi_reg_mask_set(u32 reg, u32 mask, u32 data) |
| 135 | { |
| 136 | u32 val = __fsi_reg_read(reg); |
| 137 | |
| 138 | val &= ~mask; |
| 139 | val |= data & mask; |
| 140 | |
| 141 | return __fsi_reg_write(reg, val); |
| 142 | } |
| 143 | |
| 144 | static int fsi_reg_write(struct fsi_priv *fsi, u32 reg, u32 data) |
| 145 | { |
| 146 | if (reg > REG_END) |
| 147 | return -1; |
| 148 | |
| 149 | return __fsi_reg_write((u32)(fsi->base + reg), data); |
| 150 | } |
| 151 | |
| 152 | static u32 fsi_reg_read(struct fsi_priv *fsi, u32 reg) |
| 153 | { |
| 154 | if (reg > REG_END) |
| 155 | return 0; |
| 156 | |
| 157 | return __fsi_reg_read((u32)(fsi->base + reg)); |
| 158 | } |
| 159 | |
| 160 | static int fsi_reg_mask_set(struct fsi_priv *fsi, u32 reg, u32 mask, u32 data) |
| 161 | { |
| 162 | if (reg > REG_END) |
| 163 | return -1; |
| 164 | |
| 165 | return __fsi_reg_mask_set((u32)(fsi->base + reg), mask, data); |
| 166 | } |
| 167 | |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 168 | static int fsi_master_write(struct fsi_master *master, u32 reg, u32 data) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 169 | { |
| 170 | if ((reg < MREG_START) || |
| 171 | (reg > MREG_END)) |
| 172 | return -1; |
| 173 | |
| 174 | return __fsi_reg_write((u32)(master->base + reg), data); |
| 175 | } |
| 176 | |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 177 | static u32 fsi_master_read(struct fsi_master *master, u32 reg) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 178 | { |
| 179 | if ((reg < MREG_START) || |
| 180 | (reg > MREG_END)) |
| 181 | return 0; |
| 182 | |
| 183 | return __fsi_reg_read((u32)(master->base + reg)); |
| 184 | } |
| 185 | |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 186 | static int fsi_master_mask_set(struct fsi_master *master, |
| 187 | u32 reg, u32 mask, u32 data) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 188 | { |
| 189 | if ((reg < MREG_START) || |
| 190 | (reg > MREG_END)) |
| 191 | return -1; |
| 192 | |
| 193 | return __fsi_reg_mask_set((u32)(master->base + reg), mask, data); |
| 194 | } |
| 195 | |
| 196 | /************************************************************************ |
| 197 | |
| 198 | |
| 199 | basic function |
| 200 | |
| 201 | |
| 202 | ************************************************************************/ |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 203 | static struct fsi_master *fsi_get_master(struct fsi_priv *fsi) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 204 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 205 | return fsi->master; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | static int fsi_is_port_a(struct fsi_priv *fsi) |
| 209 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 210 | return fsi->master->base == fsi->base; |
| 211 | } |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 212 | |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 213 | static struct fsi_priv *fsi_get_priv(struct snd_pcm_substream *substream) |
| 214 | { |
| 215 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 216 | struct snd_soc_dai_link *machine = rtd->dai; |
| 217 | struct snd_soc_dai *dai = machine->cpu_dai; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 218 | |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 219 | return dai->private_data; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | static u32 fsi_get_info_flags(struct fsi_priv *fsi) |
| 223 | { |
| 224 | int is_porta = fsi_is_port_a(fsi); |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 225 | struct fsi_master *master = fsi_get_master(fsi); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 226 | |
| 227 | return is_porta ? master->info->porta_flags : |
| 228 | master->info->portb_flags; |
| 229 | } |
| 230 | |
| 231 | static int fsi_is_master_mode(struct fsi_priv *fsi, int is_play) |
| 232 | { |
| 233 | u32 mode; |
| 234 | u32 flags = fsi_get_info_flags(fsi); |
| 235 | |
| 236 | mode = is_play ? SH_FSI_OUT_SLAVE_MODE : SH_FSI_IN_SLAVE_MODE; |
| 237 | |
| 238 | /* return |
| 239 | * 1 : master mode |
| 240 | * 0 : slave mode |
| 241 | */ |
| 242 | |
| 243 | return (mode & flags) != mode; |
| 244 | } |
| 245 | |
| 246 | static u32 fsi_port_ab_io_bit(struct fsi_priv *fsi, int is_play) |
| 247 | { |
| 248 | int is_porta = fsi_is_port_a(fsi); |
| 249 | u32 data; |
| 250 | |
| 251 | if (is_porta) |
| 252 | data = is_play ? (1 << 0) : (1 << 4); |
| 253 | else |
| 254 | data = is_play ? (1 << 8) : (1 << 12); |
| 255 | |
| 256 | return data; |
| 257 | } |
| 258 | |
| 259 | static void fsi_stream_push(struct fsi_priv *fsi, |
| 260 | struct snd_pcm_substream *substream, |
| 261 | u32 buffer_len, |
| 262 | u32 period_len) |
| 263 | { |
| 264 | fsi->substream = substream; |
| 265 | fsi->buffer_len = buffer_len; |
| 266 | fsi->period_len = period_len; |
| 267 | fsi->byte_offset = 0; |
| 268 | fsi->periods = 0; |
| 269 | } |
| 270 | |
| 271 | static void fsi_stream_pop(struct fsi_priv *fsi) |
| 272 | { |
| 273 | fsi->substream = NULL; |
| 274 | fsi->buffer_len = 0; |
| 275 | fsi->period_len = 0; |
| 276 | fsi->byte_offset = 0; |
| 277 | fsi->periods = 0; |
| 278 | } |
| 279 | |
| 280 | static int fsi_get_fifo_residue(struct fsi_priv *fsi, int is_play) |
| 281 | { |
| 282 | u32 status; |
| 283 | u32 reg = is_play ? DOFF_ST : DIFF_ST; |
| 284 | int residue; |
| 285 | |
| 286 | status = fsi_reg_read(fsi, reg); |
| 287 | residue = 0x1ff & (status >> 8); |
| 288 | residue *= fsi->chan; |
| 289 | |
| 290 | return residue; |
| 291 | } |
| 292 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 293 | /************************************************************************ |
| 294 | |
| 295 | |
| 296 | ctrl function |
| 297 | |
| 298 | |
| 299 | ************************************************************************/ |
| 300 | static void fsi_irq_enable(struct fsi_priv *fsi, int is_play) |
| 301 | { |
| 302 | u32 data = fsi_port_ab_io_bit(fsi, is_play); |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 303 | struct fsi_master *master = fsi_get_master(fsi); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 304 | |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 305 | fsi_master_mask_set(master, IMSK, data, data); |
| 306 | fsi_master_mask_set(master, IEMSK, data, data); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | static void fsi_irq_disable(struct fsi_priv *fsi, int is_play) |
| 310 | { |
| 311 | u32 data = fsi_port_ab_io_bit(fsi, is_play); |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 312 | struct fsi_master *master = fsi_get_master(fsi); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 313 | |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 314 | fsi_master_mask_set(master, IMSK, data, 0); |
| 315 | fsi_master_mask_set(master, IEMSK, data, 0); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | static void fsi_clk_ctrl(struct fsi_priv *fsi, int enable) |
| 319 | { |
| 320 | u32 val = fsi_is_port_a(fsi) ? (1 << 0) : (1 << 4); |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 321 | struct fsi_master *master = fsi_get_master(fsi); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 322 | |
| 323 | if (enable) |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 324 | fsi_master_mask_set(master, CLK_RST, val, val); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 325 | else |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 326 | fsi_master_mask_set(master, CLK_RST, val, 0); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | static void fsi_irq_init(struct fsi_priv *fsi, int is_play) |
| 330 | { |
| 331 | u32 data; |
| 332 | u32 ctrl; |
| 333 | |
| 334 | data = fsi_port_ab_io_bit(fsi, is_play); |
| 335 | ctrl = is_play ? DOFF_CTL : DIFF_CTL; |
| 336 | |
| 337 | /* set IMSK */ |
| 338 | fsi_irq_disable(fsi, is_play); |
| 339 | |
| 340 | /* set interrupt generation factor */ |
| 341 | fsi_reg_write(fsi, ctrl, IRQ_HALF); |
| 342 | |
| 343 | /* clear FIFO */ |
| 344 | fsi_reg_mask_set(fsi, ctrl, FIFO_CLR, FIFO_CLR); |
| 345 | |
| 346 | /* clear interrupt factor */ |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 347 | fsi_master_mask_set(fsi_get_master(fsi), INT_ST, data, 0); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 348 | } |
| 349 | |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 350 | static void fsi_soft_all_reset(struct fsi_master *master) |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 351 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 352 | u32 status = fsi_master_read(master, SOFT_RST); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 353 | |
| 354 | /* port AB reset */ |
| 355 | status &= 0x000000ff; |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 356 | fsi_master_write(master, SOFT_RST, status); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 357 | mdelay(10); |
| 358 | |
| 359 | /* soft reset */ |
| 360 | status &= 0x000000f0; |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 361 | fsi_master_write(master, SOFT_RST, status); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 362 | status |= 0x00000001; |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 363 | fsi_master_write(master, SOFT_RST, status); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 364 | mdelay(10); |
| 365 | } |
| 366 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 367 | /* playback interrupt */ |
| 368 | static int fsi_data_push(struct fsi_priv *fsi) |
| 369 | { |
| 370 | struct snd_pcm_runtime *runtime; |
| 371 | struct snd_pcm_substream *substream = NULL; |
| 372 | int send; |
| 373 | int fifo_free; |
| 374 | int width; |
Kuninori Morimoto | 9ddc9aa | 2009-10-30 12:02:39 +0900 | [diff] [blame] | 375 | u8 *start; |
| 376 | int i; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 377 | |
| 378 | if (!fsi || |
| 379 | !fsi->substream || |
| 380 | !fsi->substream->runtime) |
| 381 | return -EINVAL; |
| 382 | |
| 383 | runtime = fsi->substream->runtime; |
| 384 | |
| 385 | /* FSI FIFO has limit. |
| 386 | * So, this driver can not send periods data at a time |
| 387 | */ |
| 388 | if (fsi->byte_offset >= |
| 389 | fsi->period_len * (fsi->periods + 1)) { |
| 390 | |
| 391 | substream = fsi->substream; |
| 392 | fsi->periods = (fsi->periods + 1) % runtime->periods; |
| 393 | |
| 394 | if (0 == fsi->periods) |
| 395 | fsi->byte_offset = 0; |
| 396 | } |
| 397 | |
| 398 | /* get 1 channel data width */ |
| 399 | width = frames_to_bytes(runtime, 1) / fsi->chan; |
| 400 | |
| 401 | /* get send size for alsa */ |
| 402 | send = (fsi->buffer_len - fsi->byte_offset) / width; |
| 403 | |
| 404 | /* get FIFO free size */ |
| 405 | fifo_free = (fsi->fifo_max * fsi->chan) - fsi_get_fifo_residue(fsi, 1); |
| 406 | |
| 407 | /* size check */ |
| 408 | if (fifo_free < send) |
| 409 | send = fifo_free; |
| 410 | |
Kuninori Morimoto | 9ddc9aa | 2009-10-30 12:02:39 +0900 | [diff] [blame] | 411 | start = runtime->dma_area; |
| 412 | start += fsi->byte_offset; |
| 413 | |
| 414 | switch (width) { |
| 415 | case 2: |
| 416 | for (i = 0; i < send; i++) |
| 417 | fsi_reg_write(fsi, DODT, |
| 418 | ((u32)*((u16 *)start + i) << 8)); |
| 419 | break; |
| 420 | case 4: |
| 421 | for (i = 0; i < send; i++) |
| 422 | fsi_reg_write(fsi, DODT, *((u32 *)start + i)); |
| 423 | break; |
| 424 | default: |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 425 | return -EINVAL; |
Kuninori Morimoto | 9ddc9aa | 2009-10-30 12:02:39 +0900 | [diff] [blame] | 426 | } |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 427 | |
| 428 | fsi->byte_offset += send * width; |
| 429 | |
| 430 | fsi_irq_enable(fsi, 1); |
| 431 | |
| 432 | if (substream) |
| 433 | snd_pcm_period_elapsed(substream); |
| 434 | |
| 435 | return 0; |
| 436 | } |
| 437 | |
Kuninori Morimoto | 07102f3 | 2009-10-30 12:02:44 +0900 | [diff] [blame] | 438 | static int fsi_data_pop(struct fsi_priv *fsi) |
| 439 | { |
| 440 | struct snd_pcm_runtime *runtime; |
| 441 | struct snd_pcm_substream *substream = NULL; |
| 442 | int free; |
| 443 | int fifo_fill; |
| 444 | int width; |
| 445 | u8 *start; |
| 446 | int i; |
| 447 | |
| 448 | if (!fsi || |
| 449 | !fsi->substream || |
| 450 | !fsi->substream->runtime) |
| 451 | return -EINVAL; |
| 452 | |
| 453 | runtime = fsi->substream->runtime; |
| 454 | |
| 455 | /* FSI FIFO has limit. |
| 456 | * So, this driver can not send periods data at a time |
| 457 | */ |
| 458 | if (fsi->byte_offset >= |
| 459 | fsi->period_len * (fsi->periods + 1)) { |
| 460 | |
| 461 | substream = fsi->substream; |
| 462 | fsi->periods = (fsi->periods + 1) % runtime->periods; |
| 463 | |
| 464 | if (0 == fsi->periods) |
| 465 | fsi->byte_offset = 0; |
| 466 | } |
| 467 | |
| 468 | /* get 1 channel data width */ |
| 469 | width = frames_to_bytes(runtime, 1) / fsi->chan; |
| 470 | |
| 471 | /* get free space for alsa */ |
| 472 | free = (fsi->buffer_len - fsi->byte_offset) / width; |
| 473 | |
| 474 | /* get recv size */ |
| 475 | fifo_fill = fsi_get_fifo_residue(fsi, 0); |
| 476 | |
| 477 | if (free < fifo_fill) |
| 478 | fifo_fill = free; |
| 479 | |
| 480 | start = runtime->dma_area; |
| 481 | start += fsi->byte_offset; |
| 482 | |
| 483 | switch (width) { |
| 484 | case 2: |
| 485 | for (i = 0; i < fifo_fill; i++) |
| 486 | *((u16 *)start + i) = |
| 487 | (u16)(fsi_reg_read(fsi, DIDT) >> 8); |
| 488 | break; |
| 489 | case 4: |
| 490 | for (i = 0; i < fifo_fill; i++) |
| 491 | *((u32 *)start + i) = fsi_reg_read(fsi, DIDT); |
| 492 | break; |
| 493 | default: |
| 494 | return -EINVAL; |
| 495 | } |
| 496 | |
| 497 | fsi->byte_offset += fifo_fill * width; |
| 498 | |
| 499 | fsi_irq_enable(fsi, 0); |
| 500 | |
| 501 | if (substream) |
| 502 | snd_pcm_period_elapsed(substream); |
| 503 | |
| 504 | return 0; |
| 505 | } |
| 506 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 507 | static irqreturn_t fsi_interrupt(int irq, void *data) |
| 508 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 509 | struct fsi_master *master = data; |
| 510 | u32 status = fsi_master_read(master, SOFT_RST) & ~0x00000010; |
| 511 | u32 int_st = fsi_master_read(master, INT_ST); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 512 | |
| 513 | /* clear irq status */ |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 514 | fsi_master_write(master, SOFT_RST, status); |
| 515 | fsi_master_write(master, SOFT_RST, status | 0x00000010); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 516 | |
| 517 | if (int_st & INT_A_OUT) |
| 518 | fsi_data_push(&master->fsia); |
| 519 | if (int_st & INT_B_OUT) |
| 520 | fsi_data_push(&master->fsib); |
Kuninori Morimoto | 07102f3 | 2009-10-30 12:02:44 +0900 | [diff] [blame] | 521 | if (int_st & INT_A_IN) |
| 522 | fsi_data_pop(&master->fsia); |
| 523 | if (int_st & INT_B_IN) |
| 524 | fsi_data_pop(&master->fsib); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 525 | |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 526 | fsi_master_write(master, INT_ST, 0x0000000); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 527 | |
| 528 | return IRQ_HANDLED; |
| 529 | } |
| 530 | |
| 531 | /************************************************************************ |
| 532 | |
| 533 | |
| 534 | dai ops |
| 535 | |
| 536 | |
| 537 | ************************************************************************/ |
| 538 | static int fsi_dai_startup(struct snd_pcm_substream *substream, |
| 539 | struct snd_soc_dai *dai) |
| 540 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 541 | struct fsi_priv *fsi = fsi_get_priv(substream); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 542 | const char *msg; |
| 543 | u32 flags = fsi_get_info_flags(fsi); |
| 544 | u32 fmt; |
| 545 | u32 reg; |
| 546 | u32 data; |
| 547 | int is_play = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); |
| 548 | int is_master; |
| 549 | int ret = 0; |
| 550 | |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 551 | pm_runtime_get_sync(dai->dev); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 552 | |
| 553 | /* CKG1 */ |
| 554 | data = is_play ? (1 << 0) : (1 << 4); |
| 555 | is_master = fsi_is_master_mode(fsi, is_play); |
| 556 | if (is_master) |
| 557 | fsi_reg_mask_set(fsi, CKG1, data, data); |
| 558 | else |
| 559 | fsi_reg_mask_set(fsi, CKG1, data, 0); |
| 560 | |
| 561 | /* clock inversion (CKG2) */ |
| 562 | data = 0; |
| 563 | switch (SH_FSI_INVERSION_MASK & flags) { |
| 564 | case SH_FSI_LRM_INV: |
| 565 | data = 1 << 12; |
| 566 | break; |
| 567 | case SH_FSI_BRM_INV: |
| 568 | data = 1 << 8; |
| 569 | break; |
| 570 | case SH_FSI_LRS_INV: |
| 571 | data = 1 << 4; |
| 572 | break; |
| 573 | case SH_FSI_BRS_INV: |
| 574 | data = 1 << 0; |
| 575 | break; |
| 576 | } |
| 577 | fsi_reg_write(fsi, CKG2, data); |
| 578 | |
| 579 | /* do fmt, di fmt */ |
| 580 | data = 0; |
| 581 | reg = is_play ? DO_FMT : DI_FMT; |
| 582 | fmt = is_play ? SH_FSI_GET_OFMT(flags) : SH_FSI_GET_IFMT(flags); |
| 583 | switch (fmt) { |
| 584 | case SH_FSI_FMT_MONO: |
| 585 | msg = "MONO"; |
| 586 | data = CR_FMT(CR_MONO); |
| 587 | fsi->chan = 1; |
| 588 | break; |
| 589 | case SH_FSI_FMT_MONO_DELAY: |
| 590 | msg = "MONO Delay"; |
| 591 | data = CR_FMT(CR_MONO_D); |
| 592 | fsi->chan = 1; |
| 593 | break; |
| 594 | case SH_FSI_FMT_PCM: |
| 595 | msg = "PCM"; |
| 596 | data = CR_FMT(CR_PCM); |
| 597 | fsi->chan = 2; |
| 598 | break; |
| 599 | case SH_FSI_FMT_I2S: |
| 600 | msg = "I2S"; |
| 601 | data = CR_FMT(CR_I2S); |
| 602 | fsi->chan = 2; |
| 603 | break; |
| 604 | case SH_FSI_FMT_TDM: |
| 605 | msg = "TDM"; |
| 606 | data = CR_FMT(CR_TDM) | (fsi->chan - 1); |
| 607 | fsi->chan = is_play ? |
| 608 | SH_FSI_GET_CH_O(flags) : SH_FSI_GET_CH_I(flags); |
| 609 | break; |
| 610 | case SH_FSI_FMT_TDM_DELAY: |
| 611 | msg = "TDM Delay"; |
| 612 | data = CR_FMT(CR_TDM_D) | (fsi->chan - 1); |
| 613 | fsi->chan = is_play ? |
| 614 | SH_FSI_GET_CH_O(flags) : SH_FSI_GET_CH_I(flags); |
| 615 | break; |
| 616 | default: |
| 617 | dev_err(dai->dev, "unknown format.\n"); |
| 618 | return -EINVAL; |
| 619 | } |
| 620 | |
| 621 | switch (fsi->chan) { |
| 622 | case 1: |
| 623 | fsi->fifo_max = 256; |
| 624 | break; |
| 625 | case 2: |
| 626 | fsi->fifo_max = 128; |
| 627 | break; |
| 628 | case 3: |
| 629 | case 4: |
| 630 | fsi->fifo_max = 64; |
| 631 | break; |
| 632 | case 5: |
| 633 | case 6: |
| 634 | case 7: |
| 635 | case 8: |
| 636 | fsi->fifo_max = 32; |
| 637 | break; |
| 638 | default: |
| 639 | dev_err(dai->dev, "channel size error.\n"); |
| 640 | return -EINVAL; |
| 641 | } |
| 642 | |
| 643 | fsi_reg_write(fsi, reg, data); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 644 | |
| 645 | /* |
| 646 | * clear clk reset if master mode |
| 647 | */ |
| 648 | if (is_master) |
| 649 | fsi_clk_ctrl(fsi, 1); |
| 650 | |
| 651 | /* irq setting */ |
| 652 | fsi_irq_init(fsi, is_play); |
| 653 | |
| 654 | return ret; |
| 655 | } |
| 656 | |
| 657 | static void fsi_dai_shutdown(struct snd_pcm_substream *substream, |
| 658 | struct snd_soc_dai *dai) |
| 659 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 660 | struct fsi_priv *fsi = fsi_get_priv(substream); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 661 | int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; |
| 662 | |
| 663 | fsi_irq_disable(fsi, is_play); |
| 664 | fsi_clk_ctrl(fsi, 0); |
| 665 | |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 666 | pm_runtime_put_sync(dai->dev); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | static int fsi_dai_trigger(struct snd_pcm_substream *substream, int cmd, |
| 670 | struct snd_soc_dai *dai) |
| 671 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 672 | struct fsi_priv *fsi = fsi_get_priv(substream); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 673 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 674 | int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; |
| 675 | int ret = 0; |
| 676 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 677 | switch (cmd) { |
| 678 | case SNDRV_PCM_TRIGGER_START: |
| 679 | fsi_stream_push(fsi, substream, |
| 680 | frames_to_bytes(runtime, runtime->buffer_size), |
| 681 | frames_to_bytes(runtime, runtime->period_size)); |
Kuninori Morimoto | 07102f3 | 2009-10-30 12:02:44 +0900 | [diff] [blame] | 682 | ret = is_play ? fsi_data_push(fsi) : fsi_data_pop(fsi); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 683 | break; |
| 684 | case SNDRV_PCM_TRIGGER_STOP: |
| 685 | fsi_irq_disable(fsi, is_play); |
| 686 | fsi_stream_pop(fsi); |
| 687 | break; |
| 688 | } |
| 689 | |
| 690 | return ret; |
| 691 | } |
| 692 | |
| 693 | static struct snd_soc_dai_ops fsi_dai_ops = { |
| 694 | .startup = fsi_dai_startup, |
| 695 | .shutdown = fsi_dai_shutdown, |
| 696 | .trigger = fsi_dai_trigger, |
| 697 | }; |
| 698 | |
| 699 | /************************************************************************ |
| 700 | |
| 701 | |
| 702 | pcm ops |
| 703 | |
| 704 | |
| 705 | ************************************************************************/ |
| 706 | static struct snd_pcm_hardware fsi_pcm_hardware = { |
| 707 | .info = SNDRV_PCM_INFO_INTERLEAVED | |
| 708 | SNDRV_PCM_INFO_MMAP | |
| 709 | SNDRV_PCM_INFO_MMAP_VALID | |
| 710 | SNDRV_PCM_INFO_PAUSE, |
| 711 | .formats = FSI_FMTS, |
| 712 | .rates = FSI_RATES, |
| 713 | .rate_min = 8000, |
| 714 | .rate_max = 192000, |
| 715 | .channels_min = 1, |
| 716 | .channels_max = 2, |
| 717 | .buffer_bytes_max = 64 * 1024, |
| 718 | .period_bytes_min = 32, |
| 719 | .period_bytes_max = 8192, |
| 720 | .periods_min = 1, |
| 721 | .periods_max = 32, |
| 722 | .fifo_size = 256, |
| 723 | }; |
| 724 | |
| 725 | static int fsi_pcm_open(struct snd_pcm_substream *substream) |
| 726 | { |
| 727 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 728 | int ret = 0; |
| 729 | |
| 730 | snd_soc_set_runtime_hwparams(substream, &fsi_pcm_hardware); |
| 731 | |
| 732 | ret = snd_pcm_hw_constraint_integer(runtime, |
| 733 | SNDRV_PCM_HW_PARAM_PERIODS); |
| 734 | |
| 735 | return ret; |
| 736 | } |
| 737 | |
| 738 | static int fsi_hw_params(struct snd_pcm_substream *substream, |
| 739 | struct snd_pcm_hw_params *hw_params) |
| 740 | { |
| 741 | return snd_pcm_lib_malloc_pages(substream, |
| 742 | params_buffer_bytes(hw_params)); |
| 743 | } |
| 744 | |
| 745 | static int fsi_hw_free(struct snd_pcm_substream *substream) |
| 746 | { |
| 747 | return snd_pcm_lib_free_pages(substream); |
| 748 | } |
| 749 | |
| 750 | static snd_pcm_uframes_t fsi_pointer(struct snd_pcm_substream *substream) |
| 751 | { |
| 752 | struct snd_pcm_runtime *runtime = substream->runtime; |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 753 | struct fsi_priv *fsi = fsi_get_priv(substream); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 754 | long location; |
| 755 | |
Kuninori Morimoto | 9ddc9aa | 2009-10-30 12:02:39 +0900 | [diff] [blame] | 756 | location = (fsi->byte_offset - 1); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 757 | if (location < 0) |
| 758 | location = 0; |
| 759 | |
| 760 | return bytes_to_frames(runtime, location); |
| 761 | } |
| 762 | |
| 763 | static struct snd_pcm_ops fsi_pcm_ops = { |
| 764 | .open = fsi_pcm_open, |
| 765 | .ioctl = snd_pcm_lib_ioctl, |
| 766 | .hw_params = fsi_hw_params, |
| 767 | .hw_free = fsi_hw_free, |
| 768 | .pointer = fsi_pointer, |
| 769 | }; |
| 770 | |
| 771 | /************************************************************************ |
| 772 | |
| 773 | |
| 774 | snd_soc_platform |
| 775 | |
| 776 | |
| 777 | ************************************************************************/ |
| 778 | #define PREALLOC_BUFFER (32 * 1024) |
| 779 | #define PREALLOC_BUFFER_MAX (32 * 1024) |
| 780 | |
| 781 | static void fsi_pcm_free(struct snd_pcm *pcm) |
| 782 | { |
| 783 | snd_pcm_lib_preallocate_free_for_all(pcm); |
| 784 | } |
| 785 | |
| 786 | static int fsi_pcm_new(struct snd_card *card, |
| 787 | struct snd_soc_dai *dai, |
| 788 | struct snd_pcm *pcm) |
| 789 | { |
| 790 | /* |
| 791 | * dont use SNDRV_DMA_TYPE_DEV, since it will oops the SH kernel |
| 792 | * in MMAP mode (i.e. aplay -M) |
| 793 | */ |
| 794 | return snd_pcm_lib_preallocate_pages_for_all( |
| 795 | pcm, |
| 796 | SNDRV_DMA_TYPE_CONTINUOUS, |
| 797 | snd_dma_continuous_data(GFP_KERNEL), |
| 798 | PREALLOC_BUFFER, PREALLOC_BUFFER_MAX); |
| 799 | } |
| 800 | |
| 801 | /************************************************************************ |
| 802 | |
| 803 | |
| 804 | alsa struct |
| 805 | |
| 806 | |
| 807 | ************************************************************************/ |
| 808 | struct snd_soc_dai fsi_soc_dai[] = { |
| 809 | { |
| 810 | .name = "FSIA", |
| 811 | .id = 0, |
| 812 | .playback = { |
| 813 | .rates = FSI_RATES, |
| 814 | .formats = FSI_FMTS, |
| 815 | .channels_min = 1, |
| 816 | .channels_max = 8, |
| 817 | }, |
Kuninori Morimoto | 07102f3 | 2009-10-30 12:02:44 +0900 | [diff] [blame] | 818 | .capture = { |
| 819 | .rates = FSI_RATES, |
| 820 | .formats = FSI_FMTS, |
| 821 | .channels_min = 1, |
| 822 | .channels_max = 8, |
| 823 | }, |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 824 | .ops = &fsi_dai_ops, |
| 825 | }, |
| 826 | { |
| 827 | .name = "FSIB", |
| 828 | .id = 1, |
| 829 | .playback = { |
| 830 | .rates = FSI_RATES, |
| 831 | .formats = FSI_FMTS, |
| 832 | .channels_min = 1, |
| 833 | .channels_max = 8, |
| 834 | }, |
Kuninori Morimoto | 07102f3 | 2009-10-30 12:02:44 +0900 | [diff] [blame] | 835 | .capture = { |
| 836 | .rates = FSI_RATES, |
| 837 | .formats = FSI_FMTS, |
| 838 | .channels_min = 1, |
| 839 | .channels_max = 8, |
| 840 | }, |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 841 | .ops = &fsi_dai_ops, |
| 842 | }, |
| 843 | }; |
| 844 | EXPORT_SYMBOL_GPL(fsi_soc_dai); |
| 845 | |
| 846 | struct snd_soc_platform fsi_soc_platform = { |
| 847 | .name = "fsi-pcm", |
| 848 | .pcm_ops = &fsi_pcm_ops, |
| 849 | .pcm_new = fsi_pcm_new, |
| 850 | .pcm_free = fsi_pcm_free, |
| 851 | }; |
| 852 | EXPORT_SYMBOL_GPL(fsi_soc_platform); |
| 853 | |
| 854 | /************************************************************************ |
| 855 | |
| 856 | |
| 857 | platform function |
| 858 | |
| 859 | |
| 860 | ************************************************************************/ |
| 861 | static int fsi_probe(struct platform_device *pdev) |
| 862 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 863 | struct fsi_master *master; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 864 | struct resource *res; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 865 | unsigned int irq; |
| 866 | int ret; |
| 867 | |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 868 | if (0 != pdev->id) { |
| 869 | dev_err(&pdev->dev, "current fsi support id 0 only now\n"); |
| 870 | return -ENODEV; |
| 871 | } |
| 872 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 873 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 874 | irq = platform_get_irq(pdev, 0); |
| 875 | if (!res || !irq) { |
| 876 | dev_err(&pdev->dev, "Not enough FSI platform resources.\n"); |
| 877 | ret = -ENODEV; |
| 878 | goto exit; |
| 879 | } |
| 880 | |
| 881 | master = kzalloc(sizeof(*master), GFP_KERNEL); |
| 882 | if (!master) { |
| 883 | dev_err(&pdev->dev, "Could not allocate master\n"); |
| 884 | ret = -ENOMEM; |
| 885 | goto exit; |
| 886 | } |
| 887 | |
| 888 | master->base = ioremap_nocache(res->start, resource_size(res)); |
| 889 | if (!master->base) { |
| 890 | ret = -ENXIO; |
| 891 | dev_err(&pdev->dev, "Unable to ioremap FSI registers.\n"); |
| 892 | goto exit_kfree; |
| 893 | } |
| 894 | |
| 895 | master->irq = irq; |
| 896 | master->info = pdev->dev.platform_data; |
| 897 | master->fsia.base = master->base; |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 898 | master->fsia.master = master; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 899 | master->fsib.base = master->base + 0x40; |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 900 | master->fsib.master = master; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 901 | |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 902 | pm_runtime_enable(&pdev->dev); |
| 903 | pm_runtime_resume(&pdev->dev); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 904 | |
| 905 | fsi_soc_dai[0].dev = &pdev->dev; |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 906 | fsi_soc_dai[0].private_data = &master->fsia; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 907 | fsi_soc_dai[1].dev = &pdev->dev; |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 908 | fsi_soc_dai[1].private_data = &master->fsib; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 909 | |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 910 | fsi_soft_all_reset(master); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 911 | |
| 912 | ret = request_irq(irq, &fsi_interrupt, IRQF_DISABLED, "fsi", master); |
| 913 | if (ret) { |
| 914 | dev_err(&pdev->dev, "irq request err\n"); |
Kuninori Morimoto | 9ddc9aa | 2009-10-30 12:02:39 +0900 | [diff] [blame] | 915 | goto exit_iounmap; |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | ret = snd_soc_register_platform(&fsi_soc_platform); |
| 919 | if (ret < 0) { |
| 920 | dev_err(&pdev->dev, "cannot snd soc register\n"); |
| 921 | goto exit_free_irq; |
| 922 | } |
| 923 | |
| 924 | return snd_soc_register_dais(fsi_soc_dai, ARRAY_SIZE(fsi_soc_dai)); |
| 925 | |
| 926 | exit_free_irq: |
| 927 | free_irq(irq, master); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 928 | exit_iounmap: |
| 929 | iounmap(master->base); |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 930 | pm_runtime_disable(&pdev->dev); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 931 | exit_kfree: |
| 932 | kfree(master); |
| 933 | master = NULL; |
| 934 | exit: |
| 935 | return ret; |
| 936 | } |
| 937 | |
| 938 | static int fsi_remove(struct platform_device *pdev) |
| 939 | { |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 940 | struct fsi_master *master; |
| 941 | |
| 942 | master = fsi_get_master(fsi_soc_dai[0].private_data); |
| 943 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 944 | snd_soc_unregister_dais(fsi_soc_dai, ARRAY_SIZE(fsi_soc_dai)); |
| 945 | snd_soc_unregister_platform(&fsi_soc_platform); |
| 946 | |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 947 | pm_runtime_disable(&pdev->dev); |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 948 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 949 | free_irq(master->irq, master); |
| 950 | |
| 951 | iounmap(master->base); |
| 952 | kfree(master); |
Kuninori Morimoto | 71f6e06 | 2009-12-02 15:11:08 +0900 | [diff] [blame^] | 953 | |
| 954 | fsi_soc_dai[0].dev = NULL; |
| 955 | fsi_soc_dai[0].private_data = NULL; |
| 956 | fsi_soc_dai[1].dev = NULL; |
| 957 | fsi_soc_dai[1].private_data = NULL; |
| 958 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 959 | return 0; |
| 960 | } |
| 961 | |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 962 | static int fsi_runtime_nop(struct device *dev) |
| 963 | { |
| 964 | /* Runtime PM callback shared between ->runtime_suspend() |
| 965 | * and ->runtime_resume(). Simply returns success. |
| 966 | * |
| 967 | * This driver re-initializes all registers after |
| 968 | * pm_runtime_get_sync() anyway so there is no need |
| 969 | * to save and restore registers here. |
| 970 | */ |
| 971 | return 0; |
| 972 | } |
| 973 | |
| 974 | static struct dev_pm_ops fsi_pm_ops = { |
| 975 | .runtime_suspend = fsi_runtime_nop, |
| 976 | .runtime_resume = fsi_runtime_nop, |
| 977 | }; |
| 978 | |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 979 | static struct platform_driver fsi_driver = { |
| 980 | .driver = { |
| 981 | .name = "sh_fsi", |
Kuninori Morimoto | 785d1c4 | 2009-11-30 20:24:48 +0900 | [diff] [blame] | 982 | .pm = &fsi_pm_ops, |
Kuninori Morimoto | a4d7d55 | 2009-08-20 21:01:05 +0900 | [diff] [blame] | 983 | }, |
| 984 | .probe = fsi_probe, |
| 985 | .remove = fsi_remove, |
| 986 | }; |
| 987 | |
| 988 | static int __init fsi_mobile_init(void) |
| 989 | { |
| 990 | return platform_driver_register(&fsi_driver); |
| 991 | } |
| 992 | |
| 993 | static void __exit fsi_mobile_exit(void) |
| 994 | { |
| 995 | platform_driver_unregister(&fsi_driver); |
| 996 | } |
| 997 | module_init(fsi_mobile_init); |
| 998 | module_exit(fsi_mobile_exit); |
| 999 | |
| 1000 | MODULE_LICENSE("GPL"); |
| 1001 | MODULE_DESCRIPTION("SuperH onchip FSI audio driver"); |
| 1002 | MODULE_AUTHOR("Kuninori Morimoto <morimoto.kuninori@renesas.com>"); |