![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0-only */ 0002 /* 0003 * soundbus generic definitions 0004 * 0005 * Copyright 2006 Johannes Berg <johannes@sipsolutions.net> 0006 */ 0007 #ifndef __SOUNDBUS_H 0008 #define __SOUNDBUS_H 0009 0010 #include <linux/of_device.h> 0011 #include <sound/pcm.h> 0012 #include <linux/list.h> 0013 0014 0015 /* When switching from master to slave or the other way around, 0016 * you don't want to have the codec chip acting as clock source 0017 * while the bus still is. 0018 * More importantly, while switch from slave to master, you need 0019 * to turn off the chip's master function first, but then there's 0020 * no clock for a while and other chips might reset, so we notify 0021 * their drivers after having switched. 0022 * The constants here are codec-point of view, so when we switch 0023 * the soundbus to master we tell the codec we're going to switch 0024 * and give it CLOCK_SWITCH_PREPARE_SLAVE! 0025 */ 0026 enum clock_switch { 0027 CLOCK_SWITCH_PREPARE_SLAVE, 0028 CLOCK_SWITCH_PREPARE_MASTER, 0029 CLOCK_SWITCH_SLAVE, 0030 CLOCK_SWITCH_MASTER, 0031 CLOCK_SWITCH_NOTIFY, 0032 }; 0033 0034 /* information on a transfer the codec can take */ 0035 struct transfer_info { 0036 u64 formats; /* SNDRV_PCM_FMTBIT_* */ 0037 unsigned int rates; /* SNDRV_PCM_RATE_* */ 0038 /* flags */ 0039 u32 transfer_in:1, /* input = 1, output = 0 */ 0040 must_be_clock_source:1; 0041 /* for codecs to distinguish among their TIs */ 0042 int tag; 0043 }; 0044 0045 struct codec_info_item { 0046 struct codec_info *codec; 0047 void *codec_data; 0048 struct soundbus_dev *sdev; 0049 /* internal, to be used by the soundbus provider */ 0050 struct list_head list; 0051 }; 0052 0053 /* for prepare, where the codecs need to know 0054 * what we're going to drive the bus with */ 0055 struct bus_info { 0056 /* see below */ 0057 int sysclock_factor; 0058 int bus_factor; 0059 }; 0060 0061 /* information on the codec itself, plus function pointers */ 0062 struct codec_info { 0063 /* the module this lives in */ 0064 struct module *owner; 0065 0066 /* supported transfer possibilities, array terminated by 0067 * formats or rates being 0. */ 0068 struct transfer_info *transfers; 0069 0070 /* Master clock speed factor 0071 * to be used (master clock speed = sysclock_factor * sampling freq) 0072 * Unused if the soundbus provider has no such notion. 0073 */ 0074 int sysclock_factor; 0075 0076 /* Bus factor, bus clock speed = bus_factor * sampling freq) 0077 * Unused if the soundbus provider has no such notion. 0078 */ 0079 int bus_factor; 0080 0081 /* operations */ 0082 /* clock switching, see above */ 0083 int (*switch_clock)(struct codec_info_item *cii, 0084 enum clock_switch clock); 0085 0086 /* called for each transfer_info when the user 0087 * opens the pcm device to determine what the 0088 * hardware can support at this point in time. 0089 * That can depend on other user-switchable controls. 0090 * Return 1 if usable, 0 if not. 0091 * out points to another instance of a transfer_info 0092 * which is initialised to the values in *ti, and 0093 * it's format and rate values can be modified by 0094 * the callback if it is necessary to further restrict 0095 * the formats that can be used at the moment, for 0096 * example when one codec has multiple logical codec 0097 * info structs for multiple inputs. 0098 */ 0099 int (*usable)(struct codec_info_item *cii, 0100 struct transfer_info *ti, 0101 struct transfer_info *out); 0102 0103 /* called when pcm stream is opened, probably not implemented 0104 * most of the time since it isn't too useful */ 0105 int (*open)(struct codec_info_item *cii, 0106 struct snd_pcm_substream *substream); 0107 0108 /* called when the pcm stream is closed, at this point 0109 * the user choices can all be unlocked (see below) */ 0110 int (*close)(struct codec_info_item *cii, 0111 struct snd_pcm_substream *substream); 0112 0113 /* if the codec must forbid some user choices because 0114 * they are not valid with the substream/transfer info, 0115 * it must do so here. Example: no digital output for 0116 * incompatible framerate, say 8KHz, on Onyx. 0117 * If the selected stuff in the substream is NOT 0118 * compatible, you have to reject this call! */ 0119 int (*prepare)(struct codec_info_item *cii, 0120 struct bus_info *bi, 0121 struct snd_pcm_substream *substream); 0122 0123 /* start() is called before data is pushed to the codec. 0124 * Note that start() must be atomic! */ 0125 int (*start)(struct codec_info_item *cii, 0126 struct snd_pcm_substream *substream); 0127 0128 /* stop() is called after data is no longer pushed to the codec. 0129 * Note that stop() must be atomic! */ 0130 int (*stop)(struct codec_info_item *cii, 0131 struct snd_pcm_substream *substream); 0132 0133 int (*suspend)(struct codec_info_item *cii, pm_message_t state); 0134 int (*resume)(struct codec_info_item *cii); 0135 }; 0136 0137 /* information on a soundbus device */ 0138 struct soundbus_dev { 0139 /* the bus it belongs to */ 0140 struct list_head onbuslist; 0141 0142 /* the of device it represents */ 0143 struct platform_device ofdev; 0144 0145 /* what modules go by */ 0146 char modalias[32]; 0147 0148 /* These fields must be before attach_codec can be called. 0149 * They should be set by the owner of the alsa card object 0150 * that is needed, and whoever sets them must make sure 0151 * that they are unique within that alsa card object. */ 0152 char *pcmname; 0153 int pcmid; 0154 0155 /* this is assigned by the soundbus provider in attach_codec */ 0156 struct snd_pcm *pcm; 0157 0158 /* operations */ 0159 /* attach a codec to this soundbus, give the alsa 0160 * card object the PCMs for this soundbus should be in. 0161 * The 'data' pointer must be unique, it is used as the 0162 * key for detach_codec(). */ 0163 int (*attach_codec)(struct soundbus_dev *dev, struct snd_card *card, 0164 struct codec_info *ci, void *data); 0165 void (*detach_codec)(struct soundbus_dev *dev, void *data); 0166 /* TODO: suspend/resume */ 0167 0168 /* private for the soundbus provider */ 0169 struct list_head codec_list; 0170 u32 have_out:1, have_in:1; 0171 }; 0172 #define to_soundbus_device(d) container_of(d, struct soundbus_dev, ofdev.dev) 0173 #define of_to_soundbus_device(d) container_of(d, struct soundbus_dev, ofdev) 0174 0175 extern int soundbus_add_one(struct soundbus_dev *dev); 0176 extern void soundbus_remove_one(struct soundbus_dev *dev); 0177 0178 extern struct soundbus_dev *soundbus_dev_get(struct soundbus_dev *dev); 0179 extern void soundbus_dev_put(struct soundbus_dev *dev); 0180 0181 struct soundbus_driver { 0182 char *name; 0183 struct module *owner; 0184 0185 /* we don't implement any matching at all */ 0186 0187 int (*probe)(struct soundbus_dev* dev); 0188 int (*remove)(struct soundbus_dev* dev); 0189 0190 int (*shutdown)(struct soundbus_dev* dev); 0191 0192 struct device_driver driver; 0193 }; 0194 #define to_soundbus_driver(drv) container_of(drv,struct soundbus_driver, driver) 0195 0196 extern int soundbus_register_driver(struct soundbus_driver *drv); 0197 extern void soundbus_unregister_driver(struct soundbus_driver *drv); 0198 0199 extern struct attribute *soundbus_dev_attrs[]; 0200 0201 #endif /* __SOUNDBUS_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |