0001
0002
0003
0004
0005
0006
0007
0008 #ifndef RSND_H
0009 #define RSND_H
0010
0011 #include <linux/clk.h>
0012 #include <linux/device.h>
0013 #include <linux/dma-mapping.h>
0014 #include <linux/io.h>
0015 #include <linux/list.h>
0016 #include <linux/module.h>
0017 #include <linux/of_device.h>
0018 #include <linux/of_graph.h>
0019 #include <linux/of_irq.h>
0020 #include <linux/sh_dma.h>
0021 #include <linux/workqueue.h>
0022 #include <sound/soc.h>
0023 #include <sound/pcm_params.h>
0024
0025 #define RSND_GEN1_SRU 0
0026 #define RSND_GEN1_ADG 1
0027 #define RSND_GEN1_SSI 2
0028
0029 #define RSND_GEN2_SCU 0
0030 #define RSND_GEN2_ADG 1
0031 #define RSND_GEN2_SSIU 2
0032 #define RSND_GEN2_SSI 3
0033
0034 #define RSND_BASE_MAX 4
0035
0036
0037
0038
0039
0040
0041
0042
0043 enum rsnd_reg {
0044
0045 SRC_I_BUSIF_MODE,
0046 SRC_O_BUSIF_MODE,
0047 SRC_ROUTE_MODE0,
0048 SRC_SWRSR,
0049 SRC_SRCIR,
0050 SRC_ADINR,
0051 SRC_IFSCR,
0052 SRC_IFSVR,
0053 SRC_SRCCR,
0054 SRC_CTRL,
0055 SRC_BSDSR,
0056 SRC_BSISR,
0057 SRC_INT_ENABLE0,
0058 SRC_BUSIF_DALIGN,
0059 SRCIN_TIMSEL0,
0060 SRCIN_TIMSEL1,
0061 SRCIN_TIMSEL2,
0062 SRCIN_TIMSEL3,
0063 SRCIN_TIMSEL4,
0064 SRCOUT_TIMSEL0,
0065 SRCOUT_TIMSEL1,
0066 SRCOUT_TIMSEL2,
0067 SRCOUT_TIMSEL3,
0068 SRCOUT_TIMSEL4,
0069 SCU_SYS_STATUS0,
0070 SCU_SYS_STATUS1,
0071 SCU_SYS_INT_EN0,
0072 SCU_SYS_INT_EN1,
0073 CMD_CTRL,
0074 CMD_BUSIF_MODE,
0075 CMD_BUSIF_DALIGN,
0076 CMD_ROUTE_SLCT,
0077 CMDOUT_TIMSEL,
0078 CTU_SWRSR,
0079 CTU_CTUIR,
0080 CTU_ADINR,
0081 CTU_CPMDR,
0082 CTU_SCMDR,
0083 CTU_SV00R,
0084 CTU_SV01R,
0085 CTU_SV02R,
0086 CTU_SV03R,
0087 CTU_SV04R,
0088 CTU_SV05R,
0089 CTU_SV06R,
0090 CTU_SV07R,
0091 CTU_SV10R,
0092 CTU_SV11R,
0093 CTU_SV12R,
0094 CTU_SV13R,
0095 CTU_SV14R,
0096 CTU_SV15R,
0097 CTU_SV16R,
0098 CTU_SV17R,
0099 CTU_SV20R,
0100 CTU_SV21R,
0101 CTU_SV22R,
0102 CTU_SV23R,
0103 CTU_SV24R,
0104 CTU_SV25R,
0105 CTU_SV26R,
0106 CTU_SV27R,
0107 CTU_SV30R,
0108 CTU_SV31R,
0109 CTU_SV32R,
0110 CTU_SV33R,
0111 CTU_SV34R,
0112 CTU_SV35R,
0113 CTU_SV36R,
0114 CTU_SV37R,
0115 MIX_SWRSR,
0116 MIX_MIXIR,
0117 MIX_ADINR,
0118 MIX_MIXMR,
0119 MIX_MVPDR,
0120 MIX_MDBAR,
0121 MIX_MDBBR,
0122 MIX_MDBCR,
0123 MIX_MDBDR,
0124 MIX_MDBER,
0125 DVC_SWRSR,
0126 DVC_DVUIR,
0127 DVC_ADINR,
0128 DVC_DVUCR,
0129 DVC_ZCMCR,
0130 DVC_VOL0R,
0131 DVC_VOL1R,
0132 DVC_VOL2R,
0133 DVC_VOL3R,
0134 DVC_VOL4R,
0135 DVC_VOL5R,
0136 DVC_VOL6R,
0137 DVC_VOL7R,
0138 DVC_DVUER,
0139 DVC_VRCTR,
0140 DVC_VRPDR,
0141 DVC_VRDBR,
0142
0143
0144 BRRA,
0145 BRRB,
0146 BRGCKR,
0147 DIV_EN,
0148 AUDIO_CLK_SEL0,
0149 AUDIO_CLK_SEL1,
0150 AUDIO_CLK_SEL2,
0151
0152
0153 SSI_MODE,
0154 SSI_MODE0,
0155 SSI_MODE1,
0156 SSI_MODE2,
0157 SSI_CONTROL,
0158 SSI_CTRL,
0159 SSI_BUSIF0_MODE,
0160 SSI_BUSIF1_MODE,
0161 SSI_BUSIF2_MODE,
0162 SSI_BUSIF3_MODE,
0163 SSI_BUSIF4_MODE,
0164 SSI_BUSIF5_MODE,
0165 SSI_BUSIF6_MODE,
0166 SSI_BUSIF7_MODE,
0167 SSI_BUSIF0_ADINR,
0168 SSI_BUSIF1_ADINR,
0169 SSI_BUSIF2_ADINR,
0170 SSI_BUSIF3_ADINR,
0171 SSI_BUSIF4_ADINR,
0172 SSI_BUSIF5_ADINR,
0173 SSI_BUSIF6_ADINR,
0174 SSI_BUSIF7_ADINR,
0175 SSI_BUSIF0_DALIGN,
0176 SSI_BUSIF1_DALIGN,
0177 SSI_BUSIF2_DALIGN,
0178 SSI_BUSIF3_DALIGN,
0179 SSI_BUSIF4_DALIGN,
0180 SSI_BUSIF5_DALIGN,
0181 SSI_BUSIF6_DALIGN,
0182 SSI_BUSIF7_DALIGN,
0183 SSI_INT_ENABLE,
0184 SSI_SYS_STATUS0,
0185 SSI_SYS_STATUS1,
0186 SSI_SYS_STATUS2,
0187 SSI_SYS_STATUS3,
0188 SSI_SYS_STATUS4,
0189 SSI_SYS_STATUS5,
0190 SSI_SYS_STATUS6,
0191 SSI_SYS_STATUS7,
0192 SSI_SYS_INT_ENABLE0,
0193 SSI_SYS_INT_ENABLE1,
0194 SSI_SYS_INT_ENABLE2,
0195 SSI_SYS_INT_ENABLE3,
0196 SSI_SYS_INT_ENABLE4,
0197 SSI_SYS_INT_ENABLE5,
0198 SSI_SYS_INT_ENABLE6,
0199 SSI_SYS_INT_ENABLE7,
0200 HDMI0_SEL,
0201 HDMI1_SEL,
0202 SSI9_BUSIF0_MODE,
0203 SSI9_BUSIF1_MODE,
0204 SSI9_BUSIF2_MODE,
0205 SSI9_BUSIF3_MODE,
0206 SSI9_BUSIF4_MODE,
0207 SSI9_BUSIF5_MODE,
0208 SSI9_BUSIF6_MODE,
0209 SSI9_BUSIF7_MODE,
0210 SSI9_BUSIF0_ADINR,
0211 SSI9_BUSIF1_ADINR,
0212 SSI9_BUSIF2_ADINR,
0213 SSI9_BUSIF3_ADINR,
0214 SSI9_BUSIF4_ADINR,
0215 SSI9_BUSIF5_ADINR,
0216 SSI9_BUSIF6_ADINR,
0217 SSI9_BUSIF7_ADINR,
0218 SSI9_BUSIF0_DALIGN,
0219 SSI9_BUSIF1_DALIGN,
0220 SSI9_BUSIF2_DALIGN,
0221 SSI9_BUSIF3_DALIGN,
0222 SSI9_BUSIF4_DALIGN,
0223 SSI9_BUSIF5_DALIGN,
0224 SSI9_BUSIF6_DALIGN,
0225 SSI9_BUSIF7_DALIGN,
0226
0227
0228 SSICR,
0229 SSISR,
0230 SSITDR,
0231 SSIRDR,
0232 SSIWSR,
0233
0234 REG_MAX,
0235 };
0236 #define SRCIN_TIMSEL(i) (SRCIN_TIMSEL0 + (i))
0237 #define SRCOUT_TIMSEL(i) (SRCOUT_TIMSEL0 + (i))
0238 #define CTU_SVxxR(i, j) (CTU_SV00R + (i * 8) + (j))
0239 #define DVC_VOLxR(i) (DVC_VOL0R + (i))
0240 #define AUDIO_CLK_SEL(i) (AUDIO_CLK_SEL0 + (i))
0241 #define SSI_BUSIF_MODE(i) (SSI_BUSIF0_MODE + (i))
0242 #define SSI_BUSIF_ADINR(i) (SSI_BUSIF0_ADINR + (i))
0243 #define SSI_BUSIF_DALIGN(i) (SSI_BUSIF0_DALIGN + (i))
0244 #define SSI9_BUSIF_MODE(i) (SSI9_BUSIF0_MODE + (i))
0245 #define SSI9_BUSIF_ADINR(i) (SSI9_BUSIF0_ADINR + (i))
0246 #define SSI9_BUSIF_DALIGN(i) (SSI9_BUSIF0_DALIGN + (i))
0247 #define SSI_SYS_STATUS(i) (SSI_SYS_STATUS0 + (i))
0248 #define SSI_SYS_INT_ENABLE(i) (SSI_SYS_INT_ENABLE0 + (i))
0249
0250
0251 struct rsnd_priv;
0252 struct rsnd_mod;
0253 struct rsnd_dai;
0254 struct rsnd_dai_stream;
0255
0256
0257
0258
0259 u32 rsnd_mod_read(struct rsnd_mod *mod, enum rsnd_reg reg);
0260 void rsnd_mod_write(struct rsnd_mod *mod, enum rsnd_reg reg, u32 data);
0261 void rsnd_mod_bset(struct rsnd_mod *mod, enum rsnd_reg reg, u32 mask, u32 data);
0262 u32 rsnd_get_adinr_bit(struct rsnd_mod *mod, struct rsnd_dai_stream *io);
0263 u32 rsnd_get_dalign(struct rsnd_mod *mod, struct rsnd_dai_stream *io);
0264 u32 rsnd_get_busif_shift(struct rsnd_dai_stream *io, struct rsnd_mod *mod);
0265
0266
0267
0268
0269 int rsnd_dma_attach(struct rsnd_dai_stream *io,
0270 struct rsnd_mod *mod, struct rsnd_mod **dma_mod);
0271 int rsnd_dma_probe(struct rsnd_priv *priv);
0272 struct dma_chan *rsnd_dma_request_channel(struct device_node *of_node, char *name,
0273 struct rsnd_mod *mod, char *x);
0274
0275
0276
0277
0278 enum rsnd_mod_type {
0279 RSND_MOD_AUDMAPP,
0280 RSND_MOD_AUDMA,
0281 RSND_MOD_DVC,
0282 RSND_MOD_MIX,
0283 RSND_MOD_CTU,
0284 RSND_MOD_CMD,
0285 RSND_MOD_SRC,
0286 RSND_MOD_SSIM3,
0287 RSND_MOD_SSIM2,
0288 RSND_MOD_SSIM1,
0289 RSND_MOD_SSIP,
0290 RSND_MOD_SSI,
0291 RSND_MOD_SSIU,
0292 RSND_MOD_MAX,
0293 };
0294
0295 struct rsnd_mod_ops {
0296 char *name;
0297 struct dma_chan* (*dma_req)(struct rsnd_dai_stream *io,
0298 struct rsnd_mod *mod);
0299 int (*probe)(struct rsnd_mod *mod,
0300 struct rsnd_dai_stream *io,
0301 struct rsnd_priv *priv);
0302 int (*remove)(struct rsnd_mod *mod,
0303 struct rsnd_dai_stream *io,
0304 struct rsnd_priv *priv);
0305 int (*init)(struct rsnd_mod *mod,
0306 struct rsnd_dai_stream *io,
0307 struct rsnd_priv *priv);
0308 int (*quit)(struct rsnd_mod *mod,
0309 struct rsnd_dai_stream *io,
0310 struct rsnd_priv *priv);
0311 int (*start)(struct rsnd_mod *mod,
0312 struct rsnd_dai_stream *io,
0313 struct rsnd_priv *priv);
0314 int (*stop)(struct rsnd_mod *mod,
0315 struct rsnd_dai_stream *io,
0316 struct rsnd_priv *priv);
0317 int (*irq)(struct rsnd_mod *mod,
0318 struct rsnd_dai_stream *io,
0319 struct rsnd_priv *priv, int enable);
0320 int (*pcm_new)(struct rsnd_mod *mod,
0321 struct rsnd_dai_stream *io,
0322 struct snd_soc_pcm_runtime *rtd);
0323 int (*hw_params)(struct rsnd_mod *mod,
0324 struct rsnd_dai_stream *io,
0325 struct snd_pcm_substream *substream,
0326 struct snd_pcm_hw_params *hw_params);
0327 int (*pointer)(struct rsnd_mod *mod,
0328 struct rsnd_dai_stream *io,
0329 snd_pcm_uframes_t *pointer);
0330 int (*fallback)(struct rsnd_mod *mod,
0331 struct rsnd_dai_stream *io,
0332 struct rsnd_priv *priv);
0333 int (*prepare)(struct rsnd_mod *mod,
0334 struct rsnd_dai_stream *io,
0335 struct rsnd_priv *priv);
0336 int (*cleanup)(struct rsnd_mod *mod,
0337 struct rsnd_dai_stream *io,
0338 struct rsnd_priv *priv);
0339 int (*hw_free)(struct rsnd_mod *mod,
0340 struct rsnd_dai_stream *io,
0341 struct snd_pcm_substream *substream);
0342 u32 *(*get_status)(struct rsnd_mod *mod,
0343 struct rsnd_dai_stream *io,
0344 enum rsnd_mod_type type);
0345 int (*id)(struct rsnd_mod *mod);
0346 int (*id_sub)(struct rsnd_mod *mod);
0347 int (*id_cmd)(struct rsnd_mod *mod);
0348
0349 #ifdef CONFIG_DEBUG_FS
0350 void (*debug_info)(struct seq_file *m,
0351 struct rsnd_dai_stream *io, struct rsnd_mod *mod);
0352 #endif
0353 };
0354
0355 struct rsnd_dai_stream;
0356 struct rsnd_mod {
0357 int id;
0358 enum rsnd_mod_type type;
0359 struct rsnd_mod_ops *ops;
0360 struct rsnd_priv *priv;
0361 struct clk *clk;
0362 u32 status;
0363 };
0364
0365
0366
0367
0368
0369
0370
0371
0372
0373
0374
0375 #define __rsnd_mod_shift_init 4
0376 #define __rsnd_mod_shift_quit 4
0377 #define __rsnd_mod_shift_start 8
0378 #define __rsnd_mod_shift_stop 8
0379 #define __rsnd_mod_shift_hw_params 12
0380 #define __rsnd_mod_shift_hw_free 12
0381 #define __rsnd_mod_shift_probe 28
0382 #define __rsnd_mod_shift_remove 28
0383 #define __rsnd_mod_shift_irq 28
0384 #define __rsnd_mod_shift_pcm_new 28
0385 #define __rsnd_mod_shift_fallback 28
0386 #define __rsnd_mod_shift_pointer 28
0387 #define __rsnd_mod_shift_prepare 28
0388 #define __rsnd_mod_shift_cleanup 28
0389
0390 #define __rsnd_mod_add_probe 0
0391 #define __rsnd_mod_add_remove 0
0392 #define __rsnd_mod_add_prepare 0
0393 #define __rsnd_mod_add_cleanup 0
0394 #define __rsnd_mod_add_init 1
0395 #define __rsnd_mod_add_quit -1
0396 #define __rsnd_mod_add_start 1
0397 #define __rsnd_mod_add_stop -1
0398 #define __rsnd_mod_add_hw_params 1
0399 #define __rsnd_mod_add_hw_free -1
0400 #define __rsnd_mod_add_irq 0
0401 #define __rsnd_mod_add_pcm_new 0
0402 #define __rsnd_mod_add_fallback 0
0403 #define __rsnd_mod_add_pointer 0
0404
0405 #define __rsnd_mod_call_probe 0
0406 #define __rsnd_mod_call_remove 0
0407 #define __rsnd_mod_call_prepare 0
0408 #define __rsnd_mod_call_cleanup 0
0409 #define __rsnd_mod_call_init 0
0410 #define __rsnd_mod_call_quit 1
0411 #define __rsnd_mod_call_start 0
0412 #define __rsnd_mod_call_stop 1
0413 #define __rsnd_mod_call_hw_params 0
0414 #define __rsnd_mod_call_hw_free 1
0415 #define __rsnd_mod_call_irq 0
0416 #define __rsnd_mod_call_pcm_new 0
0417 #define __rsnd_mod_call_fallback 0
0418 #define __rsnd_mod_call_pointer 0
0419
0420 #define rsnd_mod_to_priv(mod) ((mod)->priv)
0421 #define rsnd_mod_power_on(mod) clk_enable((mod)->clk)
0422 #define rsnd_mod_power_off(mod) clk_disable((mod)->clk)
0423 #define rsnd_mod_get(ip) (&(ip)->mod)
0424
0425 int rsnd_mod_init(struct rsnd_priv *priv,
0426 struct rsnd_mod *mod,
0427 struct rsnd_mod_ops *ops,
0428 struct clk *clk,
0429 enum rsnd_mod_type type,
0430 int id);
0431 void rsnd_mod_quit(struct rsnd_mod *mod);
0432 struct dma_chan *rsnd_mod_dma_req(struct rsnd_dai_stream *io,
0433 struct rsnd_mod *mod);
0434 void rsnd_mod_interrupt(struct rsnd_mod *mod,
0435 void (*callback)(struct rsnd_mod *mod,
0436 struct rsnd_dai_stream *io));
0437 u32 *rsnd_mod_get_status(struct rsnd_mod *mod,
0438 struct rsnd_dai_stream *io,
0439 enum rsnd_mod_type type);
0440 int rsnd_mod_id(struct rsnd_mod *mod);
0441 int rsnd_mod_id_raw(struct rsnd_mod *mod);
0442 int rsnd_mod_id_sub(struct rsnd_mod *mod);
0443 char *rsnd_mod_name(struct rsnd_mod *mod);
0444 struct rsnd_mod *rsnd_mod_next(int *iterator,
0445 struct rsnd_dai_stream *io,
0446 enum rsnd_mod_type *array,
0447 int array_size);
0448 #define for_each_rsnd_mod(iterator, pos, io) \
0449 for (iterator = 0; \
0450 (pos = rsnd_mod_next(&iterator, io, NULL, 0)); iterator++)
0451 #define for_each_rsnd_mod_arrays(iterator, pos, io, array, size) \
0452 for (iterator = 0; \
0453 (pos = rsnd_mod_next(&iterator, io, array, size)); iterator++)
0454 #define for_each_rsnd_mod_array(iterator, pos, io, array) \
0455 for_each_rsnd_mod_arrays(iterator, pos, io, array, ARRAY_SIZE(array))
0456
0457 void rsnd_parse_connect_common(struct rsnd_dai *rdai, char *name,
0458 struct rsnd_mod* (*mod_get)(struct rsnd_priv *priv, int id),
0459 struct device_node *node,
0460 struct device_node *playback,
0461 struct device_node *capture);
0462 int rsnd_node_count(struct rsnd_priv *priv, struct device_node *node, char *name);
0463 int rsnd_node_fixed_index(struct device *dev, struct device_node *node, char *name, int idx);
0464
0465 int rsnd_channel_normalization(int chan);
0466 #define rsnd_runtime_channel_original(io) \
0467 rsnd_runtime_channel_original_with_params(io, NULL)
0468 int rsnd_runtime_channel_original_with_params(struct rsnd_dai_stream *io,
0469 struct snd_pcm_hw_params *params);
0470 #define rsnd_runtime_channel_after_ctu(io) \
0471 rsnd_runtime_channel_after_ctu_with_params(io, NULL)
0472 int rsnd_runtime_channel_after_ctu_with_params(struct rsnd_dai_stream *io,
0473 struct snd_pcm_hw_params *params);
0474 #define rsnd_runtime_channel_for_ssi(io) \
0475 rsnd_runtime_channel_for_ssi_with_params(io, NULL)
0476 int rsnd_runtime_channel_for_ssi_with_params(struct rsnd_dai_stream *io,
0477 struct snd_pcm_hw_params *params);
0478 int rsnd_runtime_is_multi_ssi(struct rsnd_dai_stream *io);
0479 int rsnd_runtime_is_tdm(struct rsnd_dai_stream *io);
0480 int rsnd_runtime_is_tdm_split(struct rsnd_dai_stream *io);
0481
0482
0483
0484
0485 #define rsnd_parse_of_node(priv, node) \
0486 of_get_child_by_name(rsnd_priv_to_dev(priv)->of_node, node)
0487 #define RSND_NODE_DAI "rcar_sound,dai"
0488 #define RSND_NODE_SSI "rcar_sound,ssi"
0489 #define RSND_NODE_SSIU "rcar_sound,ssiu"
0490 #define RSND_NODE_SRC "rcar_sound,src"
0491 #define RSND_NODE_CTU "rcar_sound,ctu"
0492 #define RSND_NODE_MIX "rcar_sound,mix"
0493 #define RSND_NODE_DVC "rcar_sound,dvc"
0494
0495
0496
0497
0498 #define RSND_DAI_NAME_SIZE 16
0499 struct rsnd_dai_stream {
0500 char name[RSND_DAI_NAME_SIZE];
0501 struct snd_pcm_substream *substream;
0502 struct rsnd_mod *mod[RSND_MOD_MAX];
0503 struct rsnd_mod *dma;
0504 struct rsnd_dai *rdai;
0505 struct device *dmac_dev;
0506 u32 converted_rate;
0507 int converted_chan;
0508 u32 parent_ssi_status;
0509 u32 flags;
0510 };
0511
0512
0513 #define RSND_STREAM_HDMI0 (1 << 0)
0514 #define RSND_STREAM_HDMI1 (1 << 1)
0515 #define RSND_STREAM_TDM_SPLIT (1 << 2)
0516
0517 #define rsnd_io_to_mod(io, i) ((i) < RSND_MOD_MAX ? (io)->mod[(i)] : NULL)
0518 #define rsnd_io_to_mod_ssi(io) rsnd_io_to_mod((io), RSND_MOD_SSI)
0519 #define rsnd_io_to_mod_ssiu(io) rsnd_io_to_mod((io), RSND_MOD_SSIU)
0520 #define rsnd_io_to_mod_ssip(io) rsnd_io_to_mod((io), RSND_MOD_SSIP)
0521 #define rsnd_io_to_mod_src(io) rsnd_io_to_mod((io), RSND_MOD_SRC)
0522 #define rsnd_io_to_mod_ctu(io) rsnd_io_to_mod((io), RSND_MOD_CTU)
0523 #define rsnd_io_to_mod_mix(io) rsnd_io_to_mod((io), RSND_MOD_MIX)
0524 #define rsnd_io_to_mod_dvc(io) rsnd_io_to_mod((io), RSND_MOD_DVC)
0525 #define rsnd_io_to_mod_cmd(io) rsnd_io_to_mod((io), RSND_MOD_CMD)
0526 #define rsnd_io_to_rdai(io) ((io)->rdai)
0527 #define rsnd_io_to_priv(io) (rsnd_rdai_to_priv(rsnd_io_to_rdai(io)))
0528 #define rsnd_io_is_play(io) (&rsnd_io_to_rdai(io)->playback == io)
0529 #define rsnd_io_to_runtime(io) ((io)->substream ? \
0530 (io)->substream->runtime : NULL)
0531 #define rsnd_io_converted_rate(io) ((io)->converted_rate)
0532 #define rsnd_io_converted_chan(io) ((io)->converted_chan)
0533 int rsnd_io_is_working(struct rsnd_dai_stream *io);
0534
0535 struct rsnd_dai {
0536 char name[RSND_DAI_NAME_SIZE];
0537 struct rsnd_dai_stream playback;
0538 struct rsnd_dai_stream capture;
0539 struct rsnd_priv *priv;
0540 struct snd_pcm_hw_constraint_list constraint;
0541
0542 int max_channels;
0543 int ssi_lane;
0544 int chan_width;
0545
0546 unsigned int clk_master:1;
0547 unsigned int bit_clk_inv:1;
0548 unsigned int frm_clk_inv:1;
0549 unsigned int sys_delay:1;
0550 unsigned int data_alignment:1;
0551 };
0552
0553 #define rsnd_rdai_nr(priv) ((priv)->rdai_nr)
0554 #define rsnd_rdai_is_clk_master(rdai) ((rdai)->clk_master)
0555 #define rsnd_rdai_to_priv(rdai) ((rdai)->priv)
0556 #define for_each_rsnd_dai(rdai, priv, i) \
0557 for (i = 0; \
0558 (i < rsnd_rdai_nr(priv)) && \
0559 ((rdai) = rsnd_rdai_get(priv, i)); \
0560 i++)
0561
0562 struct rsnd_dai *rsnd_rdai_get(struct rsnd_priv *priv, int id);
0563
0564 #define rsnd_rdai_channels_set(rdai, max_channels) \
0565 rsnd_rdai_channels_ctrl(rdai, max_channels)
0566 #define rsnd_rdai_channels_get(rdai) \
0567 rsnd_rdai_channels_ctrl(rdai, 0)
0568 int rsnd_rdai_channels_ctrl(struct rsnd_dai *rdai,
0569 int max_channels);
0570
0571 #define rsnd_rdai_ssi_lane_set(rdai, ssi_lane) \
0572 rsnd_rdai_ssi_lane_ctrl(rdai, ssi_lane)
0573 #define rsnd_rdai_ssi_lane_get(rdai) \
0574 rsnd_rdai_ssi_lane_ctrl(rdai, 0)
0575 int rsnd_rdai_ssi_lane_ctrl(struct rsnd_dai *rdai,
0576 int ssi_lane);
0577
0578 #define rsnd_rdai_width_set(rdai, width) \
0579 rsnd_rdai_width_ctrl(rdai, width)
0580 #define rsnd_rdai_width_get(rdai) \
0581 rsnd_rdai_width_ctrl(rdai, 0)
0582 int rsnd_rdai_width_ctrl(struct rsnd_dai *rdai, int width);
0583 void rsnd_dai_period_elapsed(struct rsnd_dai_stream *io);
0584 int rsnd_dai_connect(struct rsnd_mod *mod,
0585 struct rsnd_dai_stream *io,
0586 enum rsnd_mod_type type);
0587
0588
0589
0590
0591 int rsnd_gen_probe(struct rsnd_priv *priv);
0592 void __iomem *rsnd_gen_reg_get(struct rsnd_priv *priv,
0593 struct rsnd_mod *mod,
0594 enum rsnd_reg reg);
0595 phys_addr_t rsnd_gen_get_phy_addr(struct rsnd_priv *priv, int reg_id);
0596 #ifdef CONFIG_DEBUG_FS
0597 void __iomem *rsnd_gen_get_base_addr(struct rsnd_priv *priv, int reg_id);
0598 #endif
0599
0600
0601
0602
0603 int rsnd_adg_clk_query(struct rsnd_priv *priv, unsigned int rate);
0604 int rsnd_adg_ssi_clk_stop(struct rsnd_mod *ssi_mod);
0605 int rsnd_adg_ssi_clk_try_start(struct rsnd_mod *ssi_mod, unsigned int rate);
0606 int rsnd_adg_probe(struct rsnd_priv *priv);
0607 void rsnd_adg_remove(struct rsnd_priv *priv);
0608 int rsnd_adg_set_src_timesel_gen2(struct rsnd_mod *src_mod,
0609 struct rsnd_dai_stream *io,
0610 unsigned int in_rate,
0611 unsigned int out_rate);
0612 int rsnd_adg_set_cmd_timsel_gen2(struct rsnd_mod *cmd_mod,
0613 struct rsnd_dai_stream *io);
0614 #define rsnd_adg_clk_enable(priv) rsnd_adg_clk_control(priv, 1)
0615 #define rsnd_adg_clk_disable(priv) rsnd_adg_clk_control(priv, 0)
0616 void rsnd_adg_clk_control(struct rsnd_priv *priv, int enable);
0617 void rsnd_adg_clk_dbg_info(struct rsnd_priv *priv, struct seq_file *m);
0618
0619
0620
0621
0622 struct rsnd_priv {
0623
0624 struct platform_device *pdev;
0625 spinlock_t lock;
0626 unsigned long flags;
0627 #define RSND_GEN_MASK (0xF << 0)
0628 #define RSND_GEN1 (1 << 0)
0629 #define RSND_GEN2 (2 << 0)
0630 #define RSND_GEN3 (3 << 0)
0631 #define RSND_SOC_MASK (0xFF << 4)
0632 #define RSND_SOC_E (1 << 4)
0633
0634
0635
0636
0637 void *gen;
0638
0639
0640
0641
0642 void *adg;
0643
0644
0645
0646
0647 void *dma;
0648
0649
0650
0651
0652 void *ssi;
0653 int ssi_nr;
0654
0655
0656
0657
0658 void *ssiu;
0659 int ssiu_nr;
0660
0661
0662
0663
0664 void *src;
0665 int src_nr;
0666
0667
0668
0669
0670 void *ctu;
0671 int ctu_nr;
0672
0673
0674
0675
0676 void *mix;
0677 int mix_nr;
0678
0679
0680
0681
0682 void *dvc;
0683 int dvc_nr;
0684
0685
0686
0687
0688 void *cmd;
0689 int cmd_nr;
0690
0691
0692
0693
0694 struct snd_soc_dai_driver *daidrv;
0695 struct rsnd_dai *rdai;
0696 int rdai_nr;
0697 };
0698
0699 #define rsnd_priv_to_pdev(priv) ((priv)->pdev)
0700 #define rsnd_priv_to_dev(priv) (&(rsnd_priv_to_pdev(priv)->dev))
0701
0702 #define rsnd_is_gen1(priv) (((priv)->flags & RSND_GEN_MASK) == RSND_GEN1)
0703 #define rsnd_is_gen2(priv) (((priv)->flags & RSND_GEN_MASK) == RSND_GEN2)
0704 #define rsnd_is_gen3(priv) (((priv)->flags & RSND_GEN_MASK) == RSND_GEN3)
0705 #define rsnd_is_e3(priv) (((priv)->flags & \
0706 (RSND_GEN_MASK | RSND_SOC_MASK)) == \
0707 (RSND_GEN3 | RSND_SOC_E))
0708
0709 #define rsnd_flags_has(p, f) ((p)->flags & (f))
0710 #define rsnd_flags_set(p, f) ((p)->flags |= (f))
0711 #define rsnd_flags_del(p, f) ((p)->flags &= ~(f))
0712
0713
0714
0715
0716 struct rsnd_kctrl_cfg {
0717 unsigned int max;
0718 unsigned int size;
0719 u32 *val;
0720 const char * const *texts;
0721 int (*accept)(struct rsnd_dai_stream *io);
0722 void (*update)(struct rsnd_dai_stream *io, struct rsnd_mod *mod);
0723 struct rsnd_dai_stream *io;
0724 struct snd_card *card;
0725 struct snd_kcontrol *kctrl;
0726 struct rsnd_mod *mod;
0727 };
0728
0729 #define RSND_MAX_CHANNELS 8
0730 struct rsnd_kctrl_cfg_m {
0731 struct rsnd_kctrl_cfg cfg;
0732 u32 val[RSND_MAX_CHANNELS];
0733 };
0734
0735 struct rsnd_kctrl_cfg_s {
0736 struct rsnd_kctrl_cfg cfg;
0737 u32 val;
0738 };
0739 #define rsnd_kctrl_size(x) ((x).cfg.size)
0740 #define rsnd_kctrl_max(x) ((x).cfg.max)
0741 #define rsnd_kctrl_valm(x, i) ((x).val[i])
0742 #define rsnd_kctrl_vals(x) ((x).val)
0743
0744 int rsnd_kctrl_accept_anytime(struct rsnd_dai_stream *io);
0745 int rsnd_kctrl_accept_runtime(struct rsnd_dai_stream *io);
0746 struct rsnd_kctrl_cfg *rsnd_kctrl_init_m(struct rsnd_kctrl_cfg_m *cfg);
0747 struct rsnd_kctrl_cfg *rsnd_kctrl_init_s(struct rsnd_kctrl_cfg_s *cfg);
0748 int rsnd_kctrl_new(struct rsnd_mod *mod,
0749 struct rsnd_dai_stream *io,
0750 struct snd_soc_pcm_runtime *rtd,
0751 const unsigned char *name,
0752 int (*accept)(struct rsnd_dai_stream *io),
0753 void (*update)(struct rsnd_dai_stream *io,
0754 struct rsnd_mod *mod),
0755 struct rsnd_kctrl_cfg *cfg,
0756 const char * const *texts,
0757 int size,
0758 u32 max);
0759
0760 #define rsnd_kctrl_new_m(mod, io, rtd, name, accept, update, cfg, size, max) \
0761 rsnd_kctrl_new(mod, io, rtd, name, accept, update, rsnd_kctrl_init_m(cfg), \
0762 NULL, size, max)
0763
0764 #define rsnd_kctrl_new_s(mod, io, rtd, name, accept, update, cfg, max) \
0765 rsnd_kctrl_new(mod, io, rtd, name, accept, update, rsnd_kctrl_init_s(cfg), \
0766 NULL, 1, max)
0767
0768 #define rsnd_kctrl_new_e(mod, io, rtd, name, accept, update, cfg, texts, size) \
0769 rsnd_kctrl_new(mod, io, rtd, name, accept, update, rsnd_kctrl_init_s(cfg), \
0770 texts, 1, size)
0771
0772 extern const char * const volume_ramp_rate[];
0773 #define VOLUME_RAMP_MAX_DVC (0x17 + 1)
0774 #define VOLUME_RAMP_MAX_MIX (0x0a + 1)
0775
0776
0777
0778
0779 int rsnd_ssi_probe(struct rsnd_priv *priv);
0780 void rsnd_ssi_remove(struct rsnd_priv *priv);
0781 struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id);
0782 int rsnd_ssi_use_busif(struct rsnd_dai_stream *io);
0783 u32 rsnd_ssi_multi_secondaries_runtime(struct rsnd_dai_stream *io);
0784 int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod);
0785
0786 #define rsnd_ssi_is_pin_sharing(io) \
0787 __rsnd_ssi_is_pin_sharing(rsnd_io_to_mod_ssi(io))
0788 int __rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod);
0789
0790 #define rsnd_ssi_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_SSI)
0791 void rsnd_parse_connect_ssi(struct rsnd_dai *rdai,
0792 struct device_node *playback,
0793 struct device_node *capture);
0794 unsigned int rsnd_ssi_clk_query(struct rsnd_dai *rdai,
0795 int param1, int param2, int *idx);
0796
0797
0798
0799
0800 int rsnd_ssiu_attach(struct rsnd_dai_stream *io,
0801 struct rsnd_mod *mod);
0802 int rsnd_ssiu_probe(struct rsnd_priv *priv);
0803 void rsnd_ssiu_remove(struct rsnd_priv *priv);
0804 void rsnd_parse_connect_ssiu(struct rsnd_dai *rdai,
0805 struct device_node *playback,
0806 struct device_node *capture);
0807 #define rsnd_ssiu_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_SSIU)
0808 bool rsnd_ssiu_busif_err_status_clear(struct rsnd_mod *mod);
0809
0810
0811
0812
0813 int rsnd_src_probe(struct rsnd_priv *priv);
0814 void rsnd_src_remove(struct rsnd_priv *priv);
0815 struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id);
0816
0817 #define rsnd_src_get_in_rate(priv, io) rsnd_src_get_rate(priv, io, 1)
0818 #define rsnd_src_get_out_rate(priv, io) rsnd_src_get_rate(priv, io, 0)
0819 unsigned int rsnd_src_get_rate(struct rsnd_priv *priv,
0820 struct rsnd_dai_stream *io,
0821 int is_in);
0822
0823 #define rsnd_src_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_SRC)
0824 #define rsnd_parse_connect_src(rdai, playback, capture) \
0825 rsnd_parse_connect_common(rdai, "src", rsnd_src_mod_get, \
0826 rsnd_src_of_node(rsnd_rdai_to_priv(rdai)), \
0827 playback, capture)
0828
0829
0830
0831
0832 int rsnd_ctu_probe(struct rsnd_priv *priv);
0833 void rsnd_ctu_remove(struct rsnd_priv *priv);
0834 struct rsnd_mod *rsnd_ctu_mod_get(struct rsnd_priv *priv, int id);
0835 #define rsnd_ctu_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_CTU)
0836 #define rsnd_parse_connect_ctu(rdai, playback, capture) \
0837 rsnd_parse_connect_common(rdai, "ctu", rsnd_ctu_mod_get, \
0838 rsnd_ctu_of_node(rsnd_rdai_to_priv(rdai)), \
0839 playback, capture)
0840
0841
0842
0843
0844 int rsnd_mix_probe(struct rsnd_priv *priv);
0845 void rsnd_mix_remove(struct rsnd_priv *priv);
0846 struct rsnd_mod *rsnd_mix_mod_get(struct rsnd_priv *priv, int id);
0847 #define rsnd_mix_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_MIX)
0848 #define rsnd_parse_connect_mix(rdai, playback, capture) \
0849 rsnd_parse_connect_common(rdai, "mix", rsnd_mix_mod_get, \
0850 rsnd_mix_of_node(rsnd_rdai_to_priv(rdai)), \
0851 playback, capture)
0852
0853
0854
0855
0856 int rsnd_dvc_probe(struct rsnd_priv *priv);
0857 void rsnd_dvc_remove(struct rsnd_priv *priv);
0858 struct rsnd_mod *rsnd_dvc_mod_get(struct rsnd_priv *priv, int id);
0859 #define rsnd_dvc_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_DVC)
0860 #define rsnd_parse_connect_dvc(rdai, playback, capture) \
0861 rsnd_parse_connect_common(rdai, "dvc", rsnd_dvc_mod_get, \
0862 rsnd_dvc_of_node(rsnd_rdai_to_priv(rdai)), \
0863 playback, capture)
0864
0865
0866
0867
0868 int rsnd_cmd_probe(struct rsnd_priv *priv);
0869 void rsnd_cmd_remove(struct rsnd_priv *priv);
0870 int rsnd_cmd_attach(struct rsnd_dai_stream *io, int id);
0871
0872 void rsnd_mod_make_sure(struct rsnd_mod *mod, enum rsnd_mod_type type);
0873 #ifdef DEBUG
0874 #define rsnd_mod_confirm_ssi(mssi) rsnd_mod_make_sure(mssi, RSND_MOD_SSI)
0875 #define rsnd_mod_confirm_src(msrc) rsnd_mod_make_sure(msrc, RSND_MOD_SRC)
0876 #define rsnd_mod_confirm_dvc(mdvc) rsnd_mod_make_sure(mdvc, RSND_MOD_DVC)
0877 #else
0878 #define rsnd_mod_confirm_ssi(mssi)
0879 #define rsnd_mod_confirm_src(msrc)
0880 #define rsnd_mod_confirm_dvc(mdvc)
0881 #endif
0882
0883
0884
0885
0886
0887
0888
0889 #define rsnd_print_irq_status(dev, param...) do { \
0890 if (!IS_BUILTIN(RSND_DEBUG_NO_IRQ_STATUS)) \
0891 dev_info(dev, param); \
0892 } while (0)
0893
0894
0895
0896
0897
0898
0899
0900 #define rsnd_dbg_dai_call(dev, param...) \
0901 if (!IS_BUILTIN(RSND_DEBUG_NO_DAI_CALL)) \
0902 dev_dbg(dev, param)
0903
0904 #endif
0905
0906 #ifdef CONFIG_DEBUG_FS
0907 int rsnd_debugfs_probe(struct snd_soc_component *component);
0908 void rsnd_debugfs_reg_show(struct seq_file *m, phys_addr_t _addr,
0909 void __iomem *base, int offset, int size);
0910 void rsnd_debugfs_mod_reg_show(struct seq_file *m, struct rsnd_mod *mod,
0911 int reg_id, int offset, int size);
0912
0913 #else
0914 #define rsnd_debugfs_probe NULL
0915 #endif