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