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