/*1* soundbus generic definitions2*3* Copyright 2006 Johannes Berg <[email protected]>4*5* GPL v2, can be found in COPYING.6*/7#ifndef __SOUNDBUS_H8#define __SOUNDBUS_H910#include <linux/of_device.h>11#include <sound/pcm.h>12#include <linux/list.h>131415/* When switching from master to slave or the other way around,16* you don't want to have the codec chip acting as clock source17* while the bus still is.18* More importantly, while switch from slave to master, you need19* to turn off the chip's master function first, but then there's20* no clock for a while and other chips might reset, so we notify21* their drivers after having switched.22* The constants here are codec-point of view, so when we switch23* the soundbus to master we tell the codec we're going to switch24* and give it CLOCK_SWITCH_PREPARE_SLAVE!25*/26enum clock_switch {27CLOCK_SWITCH_PREPARE_SLAVE,28CLOCK_SWITCH_PREPARE_MASTER,29CLOCK_SWITCH_SLAVE,30CLOCK_SWITCH_MASTER,31CLOCK_SWITCH_NOTIFY,32};3334/* information on a transfer the codec can take */35struct transfer_info {36u64 formats; /* SNDRV_PCM_FMTBIT_* */37unsigned int rates; /* SNDRV_PCM_RATE_* */38/* flags */39u32 transfer_in:1, /* input = 1, output = 0 */40must_be_clock_source:1;41/* for codecs to distinguish among their TIs */42int tag;43};4445struct codec_info_item {46struct codec_info *codec;47void *codec_data;48struct soundbus_dev *sdev;49/* internal, to be used by the soundbus provider */50struct list_head list;51};5253/* for prepare, where the codecs need to know54* what we're going to drive the bus with */55struct bus_info {56/* see below */57int sysclock_factor;58int bus_factor;59};6061/* information on the codec itself, plus function pointers */62struct codec_info {63/* the module this lives in */64struct module *owner;6566/* supported transfer possibilities, array terminated by67* formats or rates being 0. */68struct transfer_info *transfers;6970/* Master clock speed factor71* to be used (master clock speed = sysclock_factor * sampling freq)72* Unused if the soundbus provider has no such notion.73*/74int sysclock_factor;7576/* Bus factor, bus clock speed = bus_factor * sampling freq)77* Unused if the soundbus provider has no such notion.78*/79int bus_factor;8081/* operations */82/* clock switching, see above */83int (*switch_clock)(struct codec_info_item *cii,84enum clock_switch clock);8586/* called for each transfer_info when the user87* opens the pcm device to determine what the88* hardware can support at this point in time.89* That can depend on other user-switchable controls.90* Return 1 if usable, 0 if not.91* out points to another instance of a transfer_info92* which is initialised to the values in *ti, and93* it's format and rate values can be modified by94* the callback if it is necessary to further restrict95* the formats that can be used at the moment, for96* example when one codec has multiple logical codec97* info structs for multiple inputs.98*/99int (*usable)(struct codec_info_item *cii,100struct transfer_info *ti,101struct transfer_info *out);102103/* called when pcm stream is opened, probably not implemented104* most of the time since it isn't too useful */105int (*open)(struct codec_info_item *cii,106struct snd_pcm_substream *substream);107108/* called when the pcm stream is closed, at this point109* the user choices can all be unlocked (see below) */110int (*close)(struct codec_info_item *cii,111struct snd_pcm_substream *substream);112113/* if the codec must forbid some user choices because114* they are not valid with the substream/transfer info,115* it must do so here. Example: no digital output for116* incompatible framerate, say 8KHz, on Onyx.117* If the selected stuff in the substream is NOT118* compatible, you have to reject this call! */119int (*prepare)(struct codec_info_item *cii,120struct bus_info *bi,121struct snd_pcm_substream *substream);122123/* start() is called before data is pushed to the codec.124* Note that start() must be atomic! */125int (*start)(struct codec_info_item *cii,126struct snd_pcm_substream *substream);127128/* stop() is called after data is no longer pushed to the codec.129* Note that stop() must be atomic! */130int (*stop)(struct codec_info_item *cii,131struct snd_pcm_substream *substream);132133int (*suspend)(struct codec_info_item *cii, pm_message_t state);134int (*resume)(struct codec_info_item *cii);135};136137/* information on a soundbus device */138struct soundbus_dev {139/* the bus it belongs to */140struct list_head onbuslist;141142/* the of device it represents */143struct platform_device ofdev;144145/* what modules go by */146char modalias[32];147148/* These fields must be before attach_codec can be called.149* They should be set by the owner of the alsa card object150* that is needed, and whoever sets them must make sure151* that they are unique within that alsa card object. */152char *pcmname;153int pcmid;154155/* this is assigned by the soundbus provider in attach_codec */156struct snd_pcm *pcm;157158/* operations */159/* attach a codec to this soundbus, give the alsa160* card object the PCMs for this soundbus should be in.161* The 'data' pointer must be unique, it is used as the162* key for detach_codec(). */163int (*attach_codec)(struct soundbus_dev *dev, struct snd_card *card,164struct codec_info *ci, void *data);165void (*detach_codec)(struct soundbus_dev *dev, void *data);166/* TODO: suspend/resume */167168/* private for the soundbus provider */169struct list_head codec_list;170u32 have_out:1, have_in:1;171};172#define to_soundbus_device(d) container_of(d, struct soundbus_dev, ofdev.dev)173#define of_to_soundbus_device(d) container_of(d, struct soundbus_dev, ofdev)174175extern int soundbus_add_one(struct soundbus_dev *dev);176extern void soundbus_remove_one(struct soundbus_dev *dev);177178extern struct soundbus_dev *soundbus_dev_get(struct soundbus_dev *dev);179extern void soundbus_dev_put(struct soundbus_dev *dev);180181struct soundbus_driver {182char *name;183struct module *owner;184185/* we don't implement any matching at all */186187int (*probe)(struct soundbus_dev* dev);188int (*remove)(struct soundbus_dev* dev);189190int (*suspend)(struct soundbus_dev* dev, pm_message_t state);191int (*resume)(struct soundbus_dev* dev);192int (*shutdown)(struct soundbus_dev* dev);193194struct device_driver driver;195};196#define to_soundbus_driver(drv) container_of(drv,struct soundbus_driver, driver)197198extern int soundbus_register_driver(struct soundbus_driver *drv);199extern void soundbus_unregister_driver(struct soundbus_driver *drv);200201extern struct device_attribute soundbus_dev_attrs[];202203#endif /* __SOUNDBUS_H */204205206