/* SPDX-License-Identifier: GPL-2.0-only */1/*2* soundbus generic definitions3*4* Copyright 2006 Johannes Berg <[email protected]>5*/6#ifndef __SOUNDBUS_H7#define __SOUNDBUS_H89#include <linux/platform_device.h>10#include <sound/pcm.h>11#include <linux/list.h>121314/* When switching from master to slave or the other way around,15* you don't want to have the codec chip acting as clock source16* while the bus still is.17* More importantly, while switch from slave to master, you need18* to turn off the chip's master function first, but then there's19* no clock for a while and other chips might reset, so we notify20* their drivers after having switched.21* The constants here are codec-point of view, so when we switch22* the soundbus to master we tell the codec we're going to switch23* and give it CLOCK_SWITCH_PREPARE_SLAVE!24*/25enum clock_switch {26CLOCK_SWITCH_PREPARE_SLAVE,27CLOCK_SWITCH_PREPARE_MASTER,28CLOCK_SWITCH_SLAVE,29CLOCK_SWITCH_MASTER,30CLOCK_SWITCH_NOTIFY,31};3233/* information on a transfer the codec can take */34struct transfer_info {35u64 formats; /* SNDRV_PCM_FMTBIT_* */36unsigned int rates; /* SNDRV_PCM_RATE_* */37/* flags */38u32 transfer_in:1, /* input = 1, output = 0 */39must_be_clock_source:1;40/* for codecs to distinguish among their TIs */41int tag;42};4344struct codec_info_item {45struct codec_info *codec;46void *codec_data;47struct soundbus_dev *sdev;48/* internal, to be used by the soundbus provider */49struct list_head list;50};5152/* for prepare, where the codecs need to know53* what we're going to drive the bus with */54struct bus_info {55/* see below */56int sysclock_factor;57int bus_factor;58};5960/* information on the codec itself, plus function pointers */61struct codec_info {62/* the module this lives in */63struct module *owner;6465/* supported transfer possibilities, array terminated by66* formats or rates being 0. */67struct transfer_info *transfers;6869/* Master clock speed factor70* to be used (master clock speed = sysclock_factor * sampling freq)71* Unused if the soundbus provider has no such notion.72*/73int sysclock_factor;7475/* Bus factor, bus clock speed = bus_factor * sampling freq)76* Unused if the soundbus provider has no such notion.77*/78int bus_factor;7980/* operations */81/* clock switching, see above */82int (*switch_clock)(struct codec_info_item *cii,83enum clock_switch clock);8485/* called for each transfer_info when the user86* opens the pcm device to determine what the87* hardware can support at this point in time.88* That can depend on other user-switchable controls.89* Return 1 if usable, 0 if not.90* out points to another instance of a transfer_info91* which is initialised to the values in *ti, and92* it's format and rate values can be modified by93* the callback if it is necessary to further restrict94* the formats that can be used at the moment, for95* example when one codec has multiple logical codec96* info structs for multiple inputs.97*/98int (*usable)(struct codec_info_item *cii,99struct transfer_info *ti,100struct transfer_info *out);101102/* called when pcm stream is opened, probably not implemented103* most of the time since it isn't too useful */104int (*open)(struct codec_info_item *cii,105struct snd_pcm_substream *substream);106107/* called when the pcm stream is closed, at this point108* the user choices can all be unlocked (see below) */109int (*close)(struct codec_info_item *cii,110struct snd_pcm_substream *substream);111112/* if the codec must forbid some user choices because113* they are not valid with the substream/transfer info,114* it must do so here. Example: no digital output for115* incompatible framerate, say 8KHz, on Onyx.116* If the selected stuff in the substream is NOT117* compatible, you have to reject this call! */118int (*prepare)(struct codec_info_item *cii,119struct bus_info *bi,120struct snd_pcm_substream *substream);121122/* start() is called before data is pushed to the codec.123* Note that start() must be atomic! */124int (*start)(struct codec_info_item *cii,125struct snd_pcm_substream *substream);126127/* stop() is called after data is no longer pushed to the codec.128* Note that stop() must be atomic! */129int (*stop)(struct codec_info_item *cii,130struct snd_pcm_substream *substream);131132int (*suspend)(struct codec_info_item *cii, pm_message_t state);133int (*resume)(struct codec_info_item *cii);134};135136/* information on a soundbus device */137struct soundbus_dev {138/* the bus it belongs to */139struct list_head onbuslist;140141/* the of device it represents */142struct platform_device ofdev;143144/* what modules go by */145char modalias[32];146147/* These fields must be before attach_codec can be called.148* They should be set by the owner of the alsa card object149* that is needed, and whoever sets them must make sure150* that they are unique within that alsa card object. */151char *pcmname;152int pcmid;153154/* this is assigned by the soundbus provider in attach_codec */155struct snd_pcm *pcm;156157/* operations */158/* attach a codec to this soundbus, give the alsa159* card object the PCMs for this soundbus should be in.160* The 'data' pointer must be unique, it is used as the161* key for detach_codec(). */162int (*attach_codec)(struct soundbus_dev *dev, struct snd_card *card,163struct codec_info *ci, void *data);164void (*detach_codec)(struct soundbus_dev *dev, void *data);165/* TODO: suspend/resume */166167/* private for the soundbus provider */168struct list_head codec_list;169u32 have_out:1, have_in:1;170};171#define to_soundbus_device(d) container_of(d, struct soundbus_dev, ofdev.dev)172#define of_to_soundbus_device(d) container_of(d, struct soundbus_dev, ofdev)173174extern int soundbus_add_one(struct soundbus_dev *dev);175extern void soundbus_remove_one(struct soundbus_dev *dev);176177extern struct soundbus_dev *soundbus_dev_get(struct soundbus_dev *dev);178extern void soundbus_dev_put(struct soundbus_dev *dev);179180struct soundbus_driver {181char *name;182struct module *owner;183184/* we don't implement any matching at all */185186int (*probe)(struct soundbus_dev* dev);187void (*remove)(struct soundbus_dev *dev);188189int (*shutdown)(struct soundbus_dev* dev);190191struct device_driver driver;192};193#define to_soundbus_driver(drv) container_of(drv,struct soundbus_driver, driver)194195extern int soundbus_register_driver(struct soundbus_driver *drv);196extern void soundbus_unregister_driver(struct soundbus_driver *drv);197198extern struct attribute *soundbus_dev_attrs[];199200#endif /* __SOUNDBUS_H */201202203