Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * soundbus generic definitions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #ifndef __SOUNDBUS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #define __SOUNDBUS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) /* When switching from master to slave or the other way around,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * you don't want to have the codec chip acting as clock source
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * while the bus still is.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * More importantly, while switch from slave to master, you need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * to turn off the chip's master function first, but then there's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * no clock for a while and other chips might reset, so we notify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * their drivers after having switched.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * The constants here are codec-point of view, so when we switch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * the soundbus to master we tell the codec we're going to switch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * and give it CLOCK_SWITCH_PREPARE_SLAVE!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) enum clock_switch {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	CLOCK_SWITCH_PREPARE_SLAVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	CLOCK_SWITCH_PREPARE_MASTER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	CLOCK_SWITCH_SLAVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	CLOCK_SWITCH_MASTER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	CLOCK_SWITCH_NOTIFY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) /* information on a transfer the codec can take */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) struct transfer_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	u64 formats;		/* SNDRV_PCM_FMTBIT_* */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	unsigned int rates;	/* SNDRV_PCM_RATE_* */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	/* flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	u32 transfer_in:1, /* input = 1, output = 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	    must_be_clock_source:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	/* for codecs to distinguish among their TIs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	int tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) struct codec_info_item {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	struct codec_info *codec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	void *codec_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	struct soundbus_dev *sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	/* internal, to be used by the soundbus provider */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) /* for prepare, where the codecs need to know
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  * what we're going to drive the bus with */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) struct bus_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	/* see below */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	int sysclock_factor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	int bus_factor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) /* information on the codec itself, plus function pointers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) struct codec_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	/* the module this lives in */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	struct module *owner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	/* supported transfer possibilities, array terminated by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	 * formats or rates being 0. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	struct transfer_info *transfers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	/* Master clock speed factor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	 * to be used (master clock speed = sysclock_factor * sampling freq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	 * Unused if the soundbus provider has no such notion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	int sysclock_factor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	/* Bus factor, bus clock speed = bus_factor * sampling freq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	 * Unused if the soundbus provider has no such notion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	int bus_factor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	/* operations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	/* clock switching, see above */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	int (*switch_clock)(struct codec_info_item *cii,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			    enum clock_switch clock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	/* called for each transfer_info when the user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	 * opens the pcm device to determine what the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	 * hardware can support at this point in time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	 * That can depend on other user-switchable controls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	 * Return 1 if usable, 0 if not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	 * out points to another instance of a transfer_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	 * which is initialised to the values in *ti, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	 * it's format and rate values can be modified by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	 * the callback if it is necessary to further restrict
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	 * the formats that can be used at the moment, for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	 * example when one codec has multiple logical codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	 * info structs for multiple inputs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	int (*usable)(struct codec_info_item *cii,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		      struct transfer_info *ti,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		      struct transfer_info *out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	/* called when pcm stream is opened, probably not implemented
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	 * most of the time since it isn't too useful */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	int (*open)(struct codec_info_item *cii,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		    struct snd_pcm_substream *substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	/* called when the pcm stream is closed, at this point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	 * the user choices can all be unlocked (see below) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	int (*close)(struct codec_info_item *cii,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		     struct snd_pcm_substream *substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	/* if the codec must forbid some user choices because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	 * they are not valid with the substream/transfer info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	 * it must do so here. Example: no digital output for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	 * incompatible framerate, say 8KHz, on Onyx.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	 * If the selected stuff in the substream is NOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	 * compatible, you have to reject this call! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	int (*prepare)(struct codec_info_item *cii,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		       struct bus_info *bi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		       struct snd_pcm_substream *substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	/* start() is called before data is pushed to the codec.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	 * Note that start() must be atomic! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	int (*start)(struct codec_info_item *cii,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		     struct snd_pcm_substream *substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	/* stop() is called after data is no longer pushed to the codec.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	 * Note that stop() must be atomic! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	int (*stop)(struct codec_info_item *cii,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		    struct snd_pcm_substream *substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	int (*suspend)(struct codec_info_item *cii, pm_message_t state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	int (*resume)(struct codec_info_item *cii);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) /* information on a soundbus device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct soundbus_dev {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	/* the bus it belongs to */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	struct list_head onbuslist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	/* the of device it represents */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	struct platform_device ofdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	/* what modules go by */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	char modalias[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	/* These fields must be before attach_codec can be called.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	 * They should be set by the owner of the alsa card object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	 * that is needed, and whoever sets them must make sure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	 * that they are unique within that alsa card object. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	char *pcmname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	int pcmid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	/* this is assigned by the soundbus provider in attach_codec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	struct snd_pcm *pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	/* operations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	/* attach a codec to this soundbus, give the alsa
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	 * card object the PCMs for this soundbus should be in.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	 * The 'data' pointer must be unique, it is used as the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	 * key for detach_codec(). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	int (*attach_codec)(struct soundbus_dev *dev, struct snd_card *card,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			    struct codec_info *ci, void *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	void (*detach_codec)(struct soundbus_dev *dev, void *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	/* TODO: suspend/resume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	/* private for the soundbus provider */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	struct list_head codec_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	u32 have_out:1, have_in:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) #define to_soundbus_device(d) container_of(d, struct soundbus_dev, ofdev.dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) #define of_to_soundbus_device(d) container_of(d, struct soundbus_dev, ofdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) extern int soundbus_add_one(struct soundbus_dev *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) extern void soundbus_remove_one(struct soundbus_dev *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) extern struct soundbus_dev *soundbus_dev_get(struct soundbus_dev *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) extern void soundbus_dev_put(struct soundbus_dev *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) struct soundbus_driver {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	struct module *owner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	/* we don't implement any matching at all */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	int	(*probe)(struct soundbus_dev* dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	int	(*remove)(struct soundbus_dev* dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	int	(*shutdown)(struct soundbus_dev* dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	struct device_driver driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) #define to_soundbus_driver(drv) container_of(drv,struct soundbus_driver, driver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) extern int soundbus_register_driver(struct soundbus_driver *drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) extern void soundbus_unregister_driver(struct soundbus_driver *drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) extern struct attribute *soundbus_dev_attrs[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) #endif /* __SOUNDBUS_H */