Kuninori Morimoto | 1536a96 | 2013-07-21 21:35:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Renesas R-Car |
| 3 | * |
| 4 | * Copyright (C) 2013 Renesas Solutions Corp. |
| 5 | * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | #ifndef RSND_H |
| 12 | #define RSND_H |
| 13 | |
| 14 | #include <linux/clk.h> |
| 15 | #include <linux/device.h> |
| 16 | #include <linux/io.h> |
| 17 | #include <linux/list.h> |
| 18 | #include <linux/module.h> |
| 19 | #include <sound/rcar_snd.h> |
| 20 | #include <sound/soc.h> |
| 21 | #include <sound/pcm_params.h> |
| 22 | |
| 23 | /* |
| 24 | * pseudo register |
| 25 | * |
| 26 | * The register address offsets SRU/SCU/SSIU on Gen1/Gen2 are very different. |
| 27 | * This driver uses pseudo register in order to hide it. |
| 28 | * see gen1/gen2 for detail |
| 29 | */ |
Kuninori Morimoto | 3337744 | 2013-07-21 21:36:21 -0700 | [diff] [blame] | 30 | enum rsnd_reg { |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame^] | 31 | /* SRU/SCU */ |
| 32 | RSND_REG_SSI_MODE0, |
| 33 | RSND_REG_SSI_MODE1, |
| 34 | |
Kuninori Morimoto | 3337744 | 2013-07-21 21:36:21 -0700 | [diff] [blame] | 35 | RSND_REG_MAX, |
| 36 | }; |
| 37 | |
Kuninori Morimoto | 1536a96 | 2013-07-21 21:35:52 -0700 | [diff] [blame] | 38 | struct rsnd_priv; |
Kuninori Morimoto | cdaa3cd | 2013-07-21 21:36:03 -0700 | [diff] [blame] | 39 | struct rsnd_mod; |
Kuninori Morimoto | 1536a96 | 2013-07-21 21:35:52 -0700 | [diff] [blame] | 40 | struct rsnd_dai; |
| 41 | struct rsnd_dai_stream; |
| 42 | |
| 43 | /* |
Kuninori Morimoto | 3337744 | 2013-07-21 21:36:21 -0700 | [diff] [blame] | 44 | * R-Car basic functions |
| 45 | */ |
| 46 | #define rsnd_mod_read(m, r) \ |
| 47 | rsnd_read(rsnd_mod_to_priv(m), m, RSND_REG_##r) |
| 48 | #define rsnd_mod_write(m, r, d) \ |
| 49 | rsnd_write(rsnd_mod_to_priv(m), m, RSND_REG_##r, d) |
| 50 | #define rsnd_mod_bset(m, r, s, d) \ |
| 51 | rsnd_bset(rsnd_mod_to_priv(m), m, RSND_REG_##r, s, d) |
| 52 | |
| 53 | #define rsnd_priv_read(p, r) rsnd_read(p, NULL, RSND_REG_##r) |
| 54 | #define rsnd_priv_write(p, r, d) rsnd_write(p, NULL, RSND_REG_##r, d) |
| 55 | #define rsnd_priv_bset(p, r, s, d) rsnd_bset(p, NULL, RSND_REG_##r, s, d) |
| 56 | |
| 57 | u32 rsnd_read(struct rsnd_priv *priv, struct rsnd_mod *mod, enum rsnd_reg reg); |
| 58 | void rsnd_write(struct rsnd_priv *priv, struct rsnd_mod *mod, |
| 59 | enum rsnd_reg reg, u32 data); |
| 60 | void rsnd_bset(struct rsnd_priv *priv, struct rsnd_mod *mod, enum rsnd_reg reg, |
| 61 | u32 mask, u32 data); |
| 62 | |
| 63 | /* |
Kuninori Morimoto | cdaa3cd | 2013-07-21 21:36:03 -0700 | [diff] [blame] | 64 | * R-Car sound mod |
| 65 | */ |
| 66 | |
| 67 | struct rsnd_mod_ops { |
| 68 | char *name; |
| 69 | int (*init)(struct rsnd_mod *mod, |
| 70 | struct rsnd_dai *rdai, |
| 71 | struct rsnd_dai_stream *io); |
| 72 | int (*quit)(struct rsnd_mod *mod, |
| 73 | struct rsnd_dai *rdai, |
| 74 | struct rsnd_dai_stream *io); |
| 75 | int (*start)(struct rsnd_mod *mod, |
| 76 | struct rsnd_dai *rdai, |
| 77 | struct rsnd_dai_stream *io); |
| 78 | int (*stop)(struct rsnd_mod *mod, |
| 79 | struct rsnd_dai *rdai, |
| 80 | struct rsnd_dai_stream *io); |
| 81 | }; |
| 82 | |
| 83 | struct rsnd_mod { |
| 84 | int id; |
| 85 | struct rsnd_priv *priv; |
| 86 | struct rsnd_mod_ops *ops; |
| 87 | struct list_head list; /* connect to rsnd_dai playback/capture */ |
| 88 | }; |
| 89 | |
| 90 | #define rsnd_mod_to_priv(mod) ((mod)->priv) |
| 91 | #define rsnd_mod_id(mod) ((mod)->id) |
| 92 | #define for_each_rsnd_mod(pos, n, io) \ |
| 93 | list_for_each_entry_safe(pos, n, &(io)->head, list) |
| 94 | #define rsnd_mod_call(mod, func, rdai, io) \ |
| 95 | (!(mod) ? -ENODEV : \ |
| 96 | !((mod)->ops->func) ? 0 : \ |
| 97 | (mod)->ops->func(mod, rdai, io)) |
| 98 | |
| 99 | void rsnd_mod_init(struct rsnd_priv *priv, |
| 100 | struct rsnd_mod *mod, |
| 101 | struct rsnd_mod_ops *ops, |
| 102 | int id); |
| 103 | char *rsnd_mod_name(struct rsnd_mod *mod); |
| 104 | |
| 105 | /* |
Kuninori Morimoto | 1536a96 | 2013-07-21 21:35:52 -0700 | [diff] [blame] | 106 | * R-Car sound DAI |
| 107 | */ |
| 108 | #define RSND_DAI_NAME_SIZE 16 |
| 109 | struct rsnd_dai_stream { |
| 110 | struct list_head head; /* head of rsnd_mod list */ |
| 111 | struct snd_pcm_substream *substream; |
| 112 | int byte_pos; |
| 113 | int period_pos; |
| 114 | int byte_per_period; |
| 115 | int next_period_byte; |
| 116 | }; |
| 117 | |
| 118 | struct rsnd_dai { |
| 119 | char name[RSND_DAI_NAME_SIZE]; |
| 120 | struct rsnd_dai_platform_info *info; /* rcar_snd.h */ |
| 121 | struct rsnd_dai_stream playback; |
| 122 | struct rsnd_dai_stream capture; |
| 123 | |
| 124 | int clk_master:1; |
| 125 | int bit_clk_inv:1; |
| 126 | int frm_clk_inv:1; |
| 127 | int sys_delay:1; |
| 128 | int data_alignment:1; |
| 129 | }; |
| 130 | |
| 131 | #define rsnd_dai_nr(priv) ((priv)->dai_nr) |
| 132 | #define for_each_rsnd_dai(rdai, priv, i) \ |
| 133 | for (i = 0, (rdai) = rsnd_dai_get(priv, i); \ |
| 134 | i < rsnd_dai_nr(priv); \ |
| 135 | i++, (rdai) = rsnd_dai_get(priv, i)) |
| 136 | |
| 137 | struct rsnd_dai *rsnd_dai_get(struct rsnd_priv *priv, int id); |
Kuninori Morimoto | cdaa3cd | 2013-07-21 21:36:03 -0700 | [diff] [blame] | 138 | int rsnd_dai_disconnect(struct rsnd_mod *mod); |
| 139 | int rsnd_dai_connect(struct rsnd_dai *rdai, struct rsnd_mod *mod, |
| 140 | struct rsnd_dai_stream *io); |
Kuninori Morimoto | 1536a96 | 2013-07-21 21:35:52 -0700 | [diff] [blame] | 141 | int rsnd_dai_is_play(struct rsnd_dai *rdai, struct rsnd_dai_stream *io); |
| 142 | #define rsnd_dai_get_platform_info(rdai) ((rdai)->info) |
| 143 | |
| 144 | void rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int cnt); |
| 145 | int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional); |
| 146 | |
| 147 | /* |
Kuninori Morimoto | 3337744 | 2013-07-21 21:36:21 -0700 | [diff] [blame] | 148 | * R-Car Gen1/Gen2 |
| 149 | */ |
| 150 | int rsnd_gen_probe(struct platform_device *pdev, |
| 151 | struct rcar_snd_info *info, |
| 152 | struct rsnd_priv *priv); |
| 153 | void rsnd_gen_remove(struct platform_device *pdev, |
| 154 | struct rsnd_priv *priv); |
| 155 | int rsnd_gen_path_init(struct rsnd_priv *priv, |
| 156 | struct rsnd_dai *rdai, |
| 157 | struct rsnd_dai_stream *io); |
| 158 | int rsnd_gen_path_exit(struct rsnd_priv *priv, |
| 159 | struct rsnd_dai *rdai, |
| 160 | struct rsnd_dai_stream *io); |
| 161 | void __iomem *rsnd_gen_reg_get(struct rsnd_priv *priv, |
| 162 | struct rsnd_mod *mod, |
| 163 | enum rsnd_reg reg); |
| 164 | |
| 165 | /* |
Kuninori Morimoto | 1536a96 | 2013-07-21 21:35:52 -0700 | [diff] [blame] | 166 | * R-Car sound priv |
| 167 | */ |
| 168 | struct rsnd_priv { |
| 169 | |
| 170 | struct device *dev; |
| 171 | struct rcar_snd_info *info; |
| 172 | spinlock_t lock; |
| 173 | |
| 174 | /* |
Kuninori Morimoto | 3337744 | 2013-07-21 21:36:21 -0700 | [diff] [blame] | 175 | * below value will be filled on rsnd_gen_probe() |
| 176 | */ |
| 177 | void *gen; |
| 178 | |
| 179 | /* |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame^] | 180 | * below value will be filled on rsnd_scu_probe() |
| 181 | */ |
| 182 | void *scu; |
| 183 | int scu_nr; |
| 184 | |
| 185 | /* |
Kuninori Morimoto | 1536a96 | 2013-07-21 21:35:52 -0700 | [diff] [blame] | 186 | * below value will be filled on rsnd_dai_probe() |
| 187 | */ |
| 188 | struct snd_soc_dai_driver *daidrv; |
| 189 | struct rsnd_dai *rdai; |
| 190 | int dai_nr; |
| 191 | }; |
| 192 | |
| 193 | #define rsnd_priv_to_dev(priv) ((priv)->dev) |
| 194 | #define rsnd_lock(priv, flags) spin_lock_irqsave(&priv->lock, flags) |
| 195 | #define rsnd_unlock(priv, flags) spin_unlock_irqrestore(&priv->lock, flags) |
| 196 | |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame^] | 197 | /* |
| 198 | * R-Car SCU |
| 199 | */ |
| 200 | int rsnd_scu_probe(struct platform_device *pdev, |
| 201 | struct rcar_snd_info *info, |
| 202 | struct rsnd_priv *priv); |
| 203 | void rsnd_scu_remove(struct platform_device *pdev, |
| 204 | struct rsnd_priv *priv); |
| 205 | struct rsnd_mod *rsnd_scu_mod_get(struct rsnd_priv *priv, int id); |
| 206 | #define rsnd_scu_nr(priv) ((priv)->scu_nr) |
| 207 | |
Kuninori Morimoto | 1536a96 | 2013-07-21 21:35:52 -0700 | [diff] [blame] | 208 | #endif |