Takashi Iwai | e3d280f | 2015-02-17 21:46:37 +0100 | [diff] [blame] | 1 | /* |
| 2 | * HD-audio core stuff |
| 3 | */ |
| 4 | |
| 5 | #ifndef __SOUND_HDAUDIO_H |
| 6 | #define __SOUND_HDAUDIO_H |
| 7 | |
| 8 | #include <linux/device.h> |
Takashi Iwai | 1475241 | 2015-04-14 12:15:47 +0200 | [diff] [blame] | 9 | #include <linux/interrupt.h> |
| 10 | #include <linux/timecounter.h> |
| 11 | #include <sound/core.h> |
| 12 | #include <sound/memalloc.h> |
Takashi Iwai | d068ebc | 2015-03-02 23:22:59 +0100 | [diff] [blame] | 13 | #include <sound/hda_verbs.h> |
| 14 | |
Takashi Iwai | 7639a06 | 2015-03-03 10:07:24 +0100 | [diff] [blame] | 15 | /* codec node id */ |
| 16 | typedef u16 hda_nid_t; |
| 17 | |
Takashi Iwai | d068ebc | 2015-03-02 23:22:59 +0100 | [diff] [blame] | 18 | struct hdac_bus; |
Takashi Iwai | 1475241 | 2015-04-14 12:15:47 +0200 | [diff] [blame] | 19 | struct hdac_stream; |
Takashi Iwai | d068ebc | 2015-03-02 23:22:59 +0100 | [diff] [blame] | 20 | struct hdac_device; |
| 21 | struct hdac_driver; |
Takashi Iwai | 3256be6 | 2015-02-24 14:59:42 +0100 | [diff] [blame] | 22 | struct hdac_widget_tree; |
Takashi Iwai | e3d280f | 2015-02-17 21:46:37 +0100 | [diff] [blame] | 23 | |
| 24 | /* |
| 25 | * exported bus type |
| 26 | */ |
| 27 | extern struct bus_type snd_hda_bus_type; |
| 28 | |
| 29 | /* |
Takashi Iwai | 71fc4c7 | 2015-03-03 17:33:10 +0100 | [diff] [blame] | 30 | * generic arrays |
| 31 | */ |
| 32 | struct snd_array { |
| 33 | unsigned int used; |
| 34 | unsigned int alloced; |
| 35 | unsigned int elem_size; |
| 36 | unsigned int alloc_align; |
| 37 | void *list; |
| 38 | }; |
| 39 | |
| 40 | /* |
Takashi Iwai | e3d280f | 2015-02-17 21:46:37 +0100 | [diff] [blame] | 41 | * HD-audio codec base device |
| 42 | */ |
| 43 | struct hdac_device { |
| 44 | struct device dev; |
| 45 | int type; |
Takashi Iwai | d068ebc | 2015-03-02 23:22:59 +0100 | [diff] [blame] | 46 | struct hdac_bus *bus; |
| 47 | unsigned int addr; /* codec address */ |
| 48 | struct list_head list; /* list point for bus codec_list */ |
Takashi Iwai | 7639a06 | 2015-03-03 10:07:24 +0100 | [diff] [blame] | 49 | |
| 50 | hda_nid_t afg; /* AFG node id */ |
| 51 | hda_nid_t mfg; /* MFG node id */ |
| 52 | |
| 53 | /* ids */ |
| 54 | unsigned int vendor_id; |
| 55 | unsigned int subsystem_id; |
| 56 | unsigned int revision_id; |
| 57 | unsigned int afg_function_id; |
| 58 | unsigned int mfg_function_id; |
| 59 | unsigned int afg_unsol:1; |
| 60 | unsigned int mfg_unsol:1; |
| 61 | |
| 62 | unsigned int power_caps; /* FG power caps */ |
| 63 | |
| 64 | const char *vendor_name; /* codec vendor name */ |
| 65 | const char *chip_name; /* codec chip name */ |
| 66 | |
Takashi Iwai | 0585244 | 2015-03-03 15:40:08 +0100 | [diff] [blame] | 67 | /* verb exec op override */ |
| 68 | int (*exec_verb)(struct hdac_device *dev, unsigned int cmd, |
| 69 | unsigned int flags, unsigned int *res); |
| 70 | |
Takashi Iwai | 7639a06 | 2015-03-03 10:07:24 +0100 | [diff] [blame] | 71 | /* widgets */ |
| 72 | unsigned int num_nodes; |
| 73 | hda_nid_t start_nid, end_nid; |
| 74 | |
| 75 | /* misc flags */ |
| 76 | atomic_t in_pm; /* suspend/resume being performed */ |
Takashi Iwai | 3256be6 | 2015-02-24 14:59:42 +0100 | [diff] [blame] | 77 | |
| 78 | /* sysfs */ |
| 79 | struct hdac_widget_tree *widgets; |
Takashi Iwai | 4d75faa0 | 2015-02-25 14:42:38 +0100 | [diff] [blame] | 80 | |
| 81 | /* regmap */ |
| 82 | struct regmap *regmap; |
Takashi Iwai | 5e56bce | 2015-02-26 12:29:03 +0100 | [diff] [blame] | 83 | struct snd_array vendor_verbs; |
Takashi Iwai | 4d75faa0 | 2015-02-25 14:42:38 +0100 | [diff] [blame] | 84 | bool lazy_cache:1; /* don't wake up for writes */ |
Takashi Iwai | faa75f8 | 2015-02-26 08:54:56 +0100 | [diff] [blame] | 85 | bool caps_overwriting:1; /* caps overwrite being in process */ |
Takashi Iwai | 40ba66a | 2015-03-13 15:56:25 +0100 | [diff] [blame] | 86 | bool cache_coef:1; /* cache COEF read/write too */ |
Takashi Iwai | e3d280f | 2015-02-17 21:46:37 +0100 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | /* device/driver type used for matching */ |
| 90 | enum { |
| 91 | HDA_DEV_CORE, |
| 92 | HDA_DEV_LEGACY, |
| 93 | }; |
| 94 | |
Takashi Iwai | 7639a06 | 2015-03-03 10:07:24 +0100 | [diff] [blame] | 95 | /* direction */ |
| 96 | enum { |
| 97 | HDA_INPUT, HDA_OUTPUT |
| 98 | }; |
| 99 | |
Takashi Iwai | e3d280f | 2015-02-17 21:46:37 +0100 | [diff] [blame] | 100 | #define dev_to_hdac_dev(_dev) container_of(_dev, struct hdac_device, dev) |
| 101 | |
Takashi Iwai | 7639a06 | 2015-03-03 10:07:24 +0100 | [diff] [blame] | 102 | int snd_hdac_device_init(struct hdac_device *dev, struct hdac_bus *bus, |
| 103 | const char *name, unsigned int addr); |
| 104 | void snd_hdac_device_exit(struct hdac_device *dev); |
Takashi Iwai | 3256be6 | 2015-02-24 14:59:42 +0100 | [diff] [blame] | 105 | int snd_hdac_device_register(struct hdac_device *codec); |
| 106 | void snd_hdac_device_unregister(struct hdac_device *codec); |
Takashi Iwai | 7639a06 | 2015-03-03 10:07:24 +0100 | [diff] [blame] | 107 | |
| 108 | int snd_hdac_refresh_widgets(struct hdac_device *codec); |
| 109 | |
| 110 | unsigned int snd_hdac_make_cmd(struct hdac_device *codec, hda_nid_t nid, |
| 111 | unsigned int verb, unsigned int parm); |
Takashi Iwai | 0585244 | 2015-03-03 15:40:08 +0100 | [diff] [blame] | 112 | int snd_hdac_exec_verb(struct hdac_device *codec, unsigned int cmd, |
| 113 | unsigned int flags, unsigned int *res); |
Takashi Iwai | 7639a06 | 2015-03-03 10:07:24 +0100 | [diff] [blame] | 114 | int snd_hdac_read(struct hdac_device *codec, hda_nid_t nid, |
| 115 | unsigned int verb, unsigned int parm, unsigned int *res); |
Takashi Iwai | 01ed3c0 | 2015-02-26 13:57:47 +0100 | [diff] [blame] | 116 | int _snd_hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, int parm, |
| 117 | unsigned int *res); |
Takashi Iwai | 9ba17b4 | 2015-03-03 23:29:47 +0100 | [diff] [blame] | 118 | int snd_hdac_read_parm_uncached(struct hdac_device *codec, hda_nid_t nid, |
| 119 | int parm); |
Takashi Iwai | faa75f8 | 2015-02-26 08:54:56 +0100 | [diff] [blame] | 120 | int snd_hdac_override_parm(struct hdac_device *codec, hda_nid_t nid, |
| 121 | unsigned int parm, unsigned int val); |
Takashi Iwai | 7639a06 | 2015-03-03 10:07:24 +0100 | [diff] [blame] | 122 | int snd_hdac_get_connections(struct hdac_device *codec, hda_nid_t nid, |
| 123 | hda_nid_t *conn_list, int max_conns); |
| 124 | int snd_hdac_get_sub_nodes(struct hdac_device *codec, hda_nid_t nid, |
| 125 | hda_nid_t *start_id); |
Takashi Iwai | b7d023e | 2015-04-16 08:19:06 +0200 | [diff] [blame] | 126 | unsigned int snd_hdac_calc_stream_format(unsigned int rate, |
| 127 | unsigned int channels, |
| 128 | unsigned int format, |
| 129 | unsigned int maxbps, |
| 130 | unsigned short spdif_ctls); |
| 131 | int snd_hdac_query_supported_pcm(struct hdac_device *codec, hda_nid_t nid, |
| 132 | u32 *ratesp, u64 *formatsp, unsigned int *bpsp); |
| 133 | bool snd_hdac_is_supported_format(struct hdac_device *codec, hda_nid_t nid, |
| 134 | unsigned int format); |
Takashi Iwai | 7639a06 | 2015-03-03 10:07:24 +0100 | [diff] [blame] | 135 | |
Takashi Iwai | 01ed3c0 | 2015-02-26 13:57:47 +0100 | [diff] [blame] | 136 | /** |
| 137 | * snd_hdac_read_parm - read a codec parameter |
| 138 | * @codec: the codec object |
| 139 | * @nid: NID to read a parameter |
| 140 | * @parm: parameter to read |
| 141 | * |
| 142 | * Returns -1 for error. If you need to distinguish the error more |
| 143 | * strictly, use _snd_hdac_read_parm() directly. |
| 144 | */ |
| 145 | static inline int snd_hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, |
| 146 | int parm) |
| 147 | { |
| 148 | unsigned int val; |
| 149 | |
| 150 | return _snd_hdac_read_parm(codec, nid, parm, &val) < 0 ? -1 : val; |
| 151 | } |
| 152 | |
Takashi Iwai | 7639a06 | 2015-03-03 10:07:24 +0100 | [diff] [blame] | 153 | #ifdef CONFIG_PM |
| 154 | void snd_hdac_power_up(struct hdac_device *codec); |
| 155 | void snd_hdac_power_down(struct hdac_device *codec); |
Takashi Iwai | c3aeda6 | 2015-04-13 11:01:14 +0200 | [diff] [blame] | 156 | void snd_hdac_power_up_pm(struct hdac_device *codec); |
| 157 | void snd_hdac_power_down_pm(struct hdac_device *codec); |
Takashi Iwai | 7639a06 | 2015-03-03 10:07:24 +0100 | [diff] [blame] | 158 | #else |
| 159 | static inline void snd_hdac_power_up(struct hdac_device *codec) {} |
| 160 | static inline void snd_hdac_power_down(struct hdac_device *codec) {} |
Takashi Iwai | c3aeda6 | 2015-04-13 11:01:14 +0200 | [diff] [blame] | 161 | static inline void snd_hdac_power_up_pm(struct hdac_device *codec) {} |
| 162 | static inline void snd_hdac_power_down_pm(struct hdac_device *codec) {} |
Takashi Iwai | 7639a06 | 2015-03-03 10:07:24 +0100 | [diff] [blame] | 163 | #endif |
| 164 | |
Takashi Iwai | e3d280f | 2015-02-17 21:46:37 +0100 | [diff] [blame] | 165 | /* |
| 166 | * HD-audio codec base driver |
| 167 | */ |
| 168 | struct hdac_driver { |
| 169 | struct device_driver driver; |
| 170 | int type; |
| 171 | int (*match)(struct hdac_device *dev, struct hdac_driver *drv); |
Takashi Iwai | d068ebc | 2015-03-02 23:22:59 +0100 | [diff] [blame] | 172 | void (*unsol_event)(struct hdac_device *dev, unsigned int event); |
Takashi Iwai | e3d280f | 2015-02-17 21:46:37 +0100 | [diff] [blame] | 173 | }; |
| 174 | |
| 175 | #define drv_to_hdac_driver(_drv) container_of(_drv, struct hdac_driver, driver) |
| 176 | |
Takashi Iwai | d068ebc | 2015-03-02 23:22:59 +0100 | [diff] [blame] | 177 | /* |
Takashi Iwai | 1475241 | 2015-04-14 12:15:47 +0200 | [diff] [blame] | 178 | * Bus verb operators |
Takashi Iwai | d068ebc | 2015-03-02 23:22:59 +0100 | [diff] [blame] | 179 | */ |
| 180 | struct hdac_bus_ops { |
| 181 | /* send a single command */ |
| 182 | int (*command)(struct hdac_bus *bus, unsigned int cmd); |
| 183 | /* get a response from the last command */ |
| 184 | int (*get_response)(struct hdac_bus *bus, unsigned int addr, |
| 185 | unsigned int *res); |
| 186 | }; |
| 187 | |
Takashi Iwai | 1475241 | 2015-04-14 12:15:47 +0200 | [diff] [blame] | 188 | /* |
| 189 | * Lowlevel I/O operators |
| 190 | */ |
| 191 | struct hdac_io_ops { |
| 192 | /* mapped register accesses */ |
| 193 | void (*reg_writel)(u32 value, u32 __iomem *addr); |
| 194 | u32 (*reg_readl)(u32 __iomem *addr); |
| 195 | void (*reg_writew)(u16 value, u16 __iomem *addr); |
| 196 | u16 (*reg_readw)(u16 __iomem *addr); |
| 197 | void (*reg_writeb)(u8 value, u8 __iomem *addr); |
| 198 | u8 (*reg_readb)(u8 __iomem *addr); |
Takashi Iwai | 8f3f600 | 2015-04-14 12:53:28 +0200 | [diff] [blame] | 199 | /* Allocation ops */ |
| 200 | int (*dma_alloc_pages)(struct hdac_bus *bus, int type, size_t size, |
| 201 | struct snd_dma_buffer *buf); |
| 202 | void (*dma_free_pages)(struct hdac_bus *bus, |
| 203 | struct snd_dma_buffer *buf); |
Takashi Iwai | 1475241 | 2015-04-14 12:15:47 +0200 | [diff] [blame] | 204 | }; |
Takashi Iwai | d068ebc | 2015-03-02 23:22:59 +0100 | [diff] [blame] | 205 | |
Takashi Iwai | 1475241 | 2015-04-14 12:15:47 +0200 | [diff] [blame] | 206 | #define HDA_UNSOL_QUEUE_SIZE 64 |
| 207 | #define HDA_MAX_CODECS 8 /* limit by controller side */ |
| 208 | |
| 209 | /* HD Audio class code */ |
| 210 | #define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403 |
| 211 | |
| 212 | /* |
| 213 | * CORB/RIRB |
| 214 | * |
| 215 | * Each CORB entry is 4byte, RIRB is 8byte |
| 216 | */ |
| 217 | struct hdac_rb { |
| 218 | __le32 *buf; /* virtual address of CORB/RIRB buffer */ |
| 219 | dma_addr_t addr; /* physical address of CORB/RIRB buffer */ |
| 220 | unsigned short rp, wp; /* RIRB read/write pointers */ |
| 221 | int cmds[HDA_MAX_CODECS]; /* number of pending requests */ |
| 222 | u32 res[HDA_MAX_CODECS]; /* last read value */ |
| 223 | }; |
| 224 | |
| 225 | /* |
| 226 | * HD-audio bus base driver |
| 227 | */ |
Takashi Iwai | d068ebc | 2015-03-02 23:22:59 +0100 | [diff] [blame] | 228 | struct hdac_bus { |
| 229 | struct device *dev; |
| 230 | const struct hdac_bus_ops *ops; |
Takashi Iwai | 1475241 | 2015-04-14 12:15:47 +0200 | [diff] [blame] | 231 | const struct hdac_io_ops *io_ops; |
| 232 | |
| 233 | /* h/w resources */ |
| 234 | unsigned long addr; |
| 235 | void __iomem *remap_addr; |
| 236 | int irq; |
Takashi Iwai | d068ebc | 2015-03-02 23:22:59 +0100 | [diff] [blame] | 237 | |
| 238 | /* codec linked list */ |
| 239 | struct list_head codec_list; |
| 240 | unsigned int num_codecs; |
| 241 | |
| 242 | /* link caddr -> codec */ |
| 243 | struct hdac_device *caddr_tbl[HDA_MAX_CODEC_ADDRESS + 1]; |
| 244 | |
| 245 | /* unsolicited event queue */ |
| 246 | u32 unsol_queue[HDA_UNSOL_QUEUE_SIZE * 2]; /* ring buffer */ |
| 247 | unsigned int unsol_rp, unsol_wp; |
| 248 | struct work_struct unsol_work; |
| 249 | |
Takashi Iwai | 1475241 | 2015-04-14 12:15:47 +0200 | [diff] [blame] | 250 | /* bit flags of detected codecs */ |
| 251 | unsigned long codec_mask; |
| 252 | |
Takashi Iwai | d068ebc | 2015-03-02 23:22:59 +0100 | [diff] [blame] | 253 | /* bit flags of powered codecs */ |
| 254 | unsigned long codec_powered; |
| 255 | |
Takashi Iwai | 1475241 | 2015-04-14 12:15:47 +0200 | [diff] [blame] | 256 | /* CORB/RIRB */ |
| 257 | struct hdac_rb corb; |
| 258 | struct hdac_rb rirb; |
| 259 | unsigned int last_cmd[HDA_MAX_CODECS]; /* last sent command */ |
| 260 | |
| 261 | /* CORB/RIRB and position buffers */ |
| 262 | struct snd_dma_buffer rb; |
| 263 | struct snd_dma_buffer posbuf; |
| 264 | |
| 265 | /* hdac_stream linked list */ |
| 266 | struct list_head stream_list; |
| 267 | |
| 268 | /* operation state */ |
| 269 | bool chip_init:1; /* h/w initialized */ |
| 270 | |
| 271 | /* behavior flags */ |
Takashi Iwai | d068ebc | 2015-03-02 23:22:59 +0100 | [diff] [blame] | 272 | bool sync_write:1; /* sync after verb write */ |
Takashi Iwai | 1475241 | 2015-04-14 12:15:47 +0200 | [diff] [blame] | 273 | bool use_posbuf:1; /* use position buffer */ |
| 274 | bool snoop:1; /* enable snooping */ |
| 275 | bool align_bdle_4k:1; /* BDLE align 4K boundary */ |
| 276 | bool reverse_assign:1; /* assign devices in reverse order */ |
| 277 | bool corbrp_self_clear:1; /* CORBRP clears itself after reset */ |
| 278 | |
| 279 | int bdl_pos_adj; /* BDL position adjustment */ |
Takashi Iwai | d068ebc | 2015-03-02 23:22:59 +0100 | [diff] [blame] | 280 | |
| 281 | /* locks */ |
Takashi Iwai | 1475241 | 2015-04-14 12:15:47 +0200 | [diff] [blame] | 282 | spinlock_t reg_lock; |
Takashi Iwai | d068ebc | 2015-03-02 23:22:59 +0100 | [diff] [blame] | 283 | struct mutex cmd_mutex; |
| 284 | }; |
| 285 | |
| 286 | int snd_hdac_bus_init(struct hdac_bus *bus, struct device *dev, |
Takashi Iwai | 1475241 | 2015-04-14 12:15:47 +0200 | [diff] [blame] | 287 | const struct hdac_bus_ops *ops, |
| 288 | const struct hdac_io_ops *io_ops); |
Takashi Iwai | d068ebc | 2015-03-02 23:22:59 +0100 | [diff] [blame] | 289 | void snd_hdac_bus_exit(struct hdac_bus *bus); |
| 290 | int snd_hdac_bus_exec_verb(struct hdac_bus *bus, unsigned int addr, |
| 291 | unsigned int cmd, unsigned int *res); |
| 292 | int snd_hdac_bus_exec_verb_unlocked(struct hdac_bus *bus, unsigned int addr, |
| 293 | unsigned int cmd, unsigned int *res); |
| 294 | void snd_hdac_bus_queue_event(struct hdac_bus *bus, u32 res, u32 res_ex); |
| 295 | |
| 296 | int snd_hdac_bus_add_device(struct hdac_bus *bus, struct hdac_device *codec); |
| 297 | void snd_hdac_bus_remove_device(struct hdac_bus *bus, |
| 298 | struct hdac_device *codec); |
| 299 | |
Takashi Iwai | 7639a06 | 2015-03-03 10:07:24 +0100 | [diff] [blame] | 300 | static inline void snd_hdac_codec_link_up(struct hdac_device *codec) |
| 301 | { |
| 302 | set_bit(codec->addr, &codec->bus->codec_powered); |
| 303 | } |
| 304 | |
| 305 | static inline void snd_hdac_codec_link_down(struct hdac_device *codec) |
| 306 | { |
| 307 | clear_bit(codec->addr, &codec->bus->codec_powered); |
| 308 | } |
| 309 | |
Takashi Iwai | 1475241 | 2015-04-14 12:15:47 +0200 | [diff] [blame] | 310 | int snd_hdac_bus_send_cmd(struct hdac_bus *bus, unsigned int val); |
| 311 | int snd_hdac_bus_get_response(struct hdac_bus *bus, unsigned int addr, |
| 312 | unsigned int *res); |
| 313 | |
| 314 | bool snd_hdac_bus_init_chip(struct hdac_bus *bus, bool full_reset); |
| 315 | void snd_hdac_bus_stop_chip(struct hdac_bus *bus); |
| 316 | void snd_hdac_bus_init_cmd_io(struct hdac_bus *bus); |
| 317 | void snd_hdac_bus_stop_cmd_io(struct hdac_bus *bus); |
| 318 | void snd_hdac_bus_enter_link_reset(struct hdac_bus *bus); |
| 319 | void snd_hdac_bus_exit_link_reset(struct hdac_bus *bus); |
| 320 | |
| 321 | void snd_hdac_bus_update_rirb(struct hdac_bus *bus); |
| 322 | void snd_hdac_bus_handle_stream_irq(struct hdac_bus *bus, unsigned int status, |
| 323 | void (*ack)(struct hdac_bus *, |
| 324 | struct hdac_stream *)); |
| 325 | |
Jeeja KP | 304dad3 | 2015-04-12 18:06:13 +0530 | [diff] [blame] | 326 | int snd_hdac_bus_alloc_stream_pages(struct hdac_bus *bus); |
| 327 | void snd_hdac_bus_free_stream_pages(struct hdac_bus *bus); |
| 328 | |
Takashi Iwai | 1475241 | 2015-04-14 12:15:47 +0200 | [diff] [blame] | 329 | /* |
| 330 | * macros for easy use |
| 331 | */ |
| 332 | #define _snd_hdac_chip_write(type, chip, reg, value) \ |
| 333 | ((chip)->io_ops->reg_write ## type(value, (chip)->remap_addr + (reg))) |
| 334 | #define _snd_hdac_chip_read(type, chip, reg) \ |
| 335 | ((chip)->io_ops->reg_read ## type((chip)->remap_addr + (reg))) |
| 336 | |
| 337 | /* read/write a register, pass without AZX_REG_ prefix */ |
| 338 | #define snd_hdac_chip_writel(chip, reg, value) \ |
| 339 | _snd_hdac_chip_write(l, chip, AZX_REG_ ## reg, value) |
| 340 | #define snd_hdac_chip_writew(chip, reg, value) \ |
| 341 | _snd_hdac_chip_write(w, chip, AZX_REG_ ## reg, value) |
| 342 | #define snd_hdac_chip_writeb(chip, reg, value) \ |
| 343 | _snd_hdac_chip_write(b, chip, AZX_REG_ ## reg, value) |
| 344 | #define snd_hdac_chip_readl(chip, reg) \ |
| 345 | _snd_hdac_chip_read(l, chip, AZX_REG_ ## reg) |
| 346 | #define snd_hdac_chip_readw(chip, reg) \ |
| 347 | _snd_hdac_chip_read(w, chip, AZX_REG_ ## reg) |
| 348 | #define snd_hdac_chip_readb(chip, reg) \ |
| 349 | _snd_hdac_chip_read(b, chip, AZX_REG_ ## reg) |
| 350 | |
| 351 | /* update a register, pass without AZX_REG_ prefix */ |
| 352 | #define snd_hdac_chip_updatel(chip, reg, mask, val) \ |
| 353 | snd_hdac_chip_writel(chip, reg, \ |
| 354 | (snd_hdac_chip_readl(chip, reg) & ~(mask)) | (val)) |
| 355 | #define snd_hdac_chip_updatew(chip, reg, mask, val) \ |
| 356 | snd_hdac_chip_writew(chip, reg, \ |
| 357 | (snd_hdac_chip_readw(chip, reg) & ~(mask)) | (val)) |
| 358 | #define snd_hdac_chip_updateb(chip, reg, mask, val) \ |
| 359 | snd_hdac_chip_writeb(chip, reg, \ |
| 360 | (snd_hdac_chip_readb(chip, reg) & ~(mask)) | (val)) |
| 361 | |
| 362 | /* |
| 363 | * HD-audio stream |
| 364 | */ |
| 365 | struct hdac_stream { |
| 366 | struct hdac_bus *bus; |
| 367 | struct snd_dma_buffer bdl; /* BDL buffer */ |
| 368 | __le32 *posbuf; /* position buffer pointer */ |
| 369 | int direction; /* playback / capture (SNDRV_PCM_STREAM_*) */ |
| 370 | |
| 371 | unsigned int bufsize; /* size of the play buffer in bytes */ |
| 372 | unsigned int period_bytes; /* size of the period in bytes */ |
| 373 | unsigned int frags; /* number for period in the play buffer */ |
| 374 | unsigned int fifo_size; /* FIFO size */ |
| 375 | |
| 376 | void __iomem *sd_addr; /* stream descriptor pointer */ |
| 377 | |
| 378 | u32 sd_int_sta_mask; /* stream int status mask */ |
| 379 | |
| 380 | /* pcm support */ |
| 381 | struct snd_pcm_substream *substream; /* assigned substream, |
| 382 | * set in PCM open |
| 383 | */ |
| 384 | unsigned int format_val; /* format value to be set in the |
| 385 | * controller and the codec |
| 386 | */ |
| 387 | unsigned char stream_tag; /* assigned stream */ |
| 388 | unsigned char index; /* stream index */ |
| 389 | int assigned_key; /* last device# key assigned to */ |
| 390 | |
| 391 | bool opened:1; |
| 392 | bool running:1; |
Takashi Iwai | 6d23c8f | 2015-04-17 13:34:30 +0200 | [diff] [blame^] | 393 | bool prepared:1; |
Takashi Iwai | 1475241 | 2015-04-14 12:15:47 +0200 | [diff] [blame] | 394 | bool no_period_wakeup:1; |
Takashi Iwai | 8f3f600 | 2015-04-14 12:53:28 +0200 | [diff] [blame] | 395 | bool locked:1; |
Takashi Iwai | 1475241 | 2015-04-14 12:15:47 +0200 | [diff] [blame] | 396 | |
| 397 | /* timestamp */ |
| 398 | unsigned long start_wallclk; /* start + minimum wallclk */ |
| 399 | unsigned long period_wallclk; /* wallclk for period */ |
| 400 | struct timecounter tc; |
| 401 | struct cyclecounter cc; |
| 402 | int delay_negative_threshold; |
| 403 | |
| 404 | struct list_head list; |
Takashi Iwai | 8f3f600 | 2015-04-14 12:53:28 +0200 | [diff] [blame] | 405 | #ifdef CONFIG_SND_HDA_DSP_LOADER |
| 406 | /* DSP access mutex */ |
| 407 | struct mutex dsp_mutex; |
| 408 | #endif |
Takashi Iwai | 1475241 | 2015-04-14 12:15:47 +0200 | [diff] [blame] | 409 | }; |
| 410 | |
| 411 | void snd_hdac_stream_init(struct hdac_bus *bus, struct hdac_stream *azx_dev, |
| 412 | int idx, int direction, int tag); |
| 413 | struct hdac_stream *snd_hdac_stream_assign(struct hdac_bus *bus, |
| 414 | struct snd_pcm_substream *substream); |
| 415 | void snd_hdac_stream_release(struct hdac_stream *azx_dev); |
| 416 | |
| 417 | int snd_hdac_stream_setup(struct hdac_stream *azx_dev); |
| 418 | void snd_hdac_stream_cleanup(struct hdac_stream *azx_dev); |
| 419 | int snd_hdac_stream_setup_periods(struct hdac_stream *azx_dev); |
| 420 | void snd_hdac_stream_start(struct hdac_stream *azx_dev, bool fresh_start); |
| 421 | void snd_hdac_stream_clear(struct hdac_stream *azx_dev); |
| 422 | void snd_hdac_stream_stop(struct hdac_stream *azx_dev); |
| 423 | void snd_hdac_stream_reset(struct hdac_stream *azx_dev); |
| 424 | void snd_hdac_stream_sync_trigger(struct hdac_stream *azx_dev, bool set, |
| 425 | unsigned int streams, unsigned int reg); |
| 426 | void snd_hdac_stream_sync(struct hdac_stream *azx_dev, bool start, |
| 427 | unsigned int streams); |
| 428 | void snd_hdac_stream_timecounter_init(struct hdac_stream *azx_dev, |
| 429 | unsigned int streams); |
| 430 | /* |
| 431 | * macros for easy use |
| 432 | */ |
| 433 | #define _snd_hdac_stream_write(type, dev, reg, value) \ |
| 434 | ((dev)->bus->io_ops->reg_write ## type(value, (dev)->sd_addr + (reg))) |
| 435 | #define _snd_hdac_stream_read(type, dev, reg) \ |
| 436 | ((dev)->bus->io_ops->reg_read ## type((dev)->sd_addr + (reg))) |
| 437 | |
| 438 | /* read/write a register, pass without AZX_REG_ prefix */ |
| 439 | #define snd_hdac_stream_writel(dev, reg, value) \ |
| 440 | _snd_hdac_stream_write(l, dev, AZX_REG_ ## reg, value) |
| 441 | #define snd_hdac_stream_writew(dev, reg, value) \ |
| 442 | _snd_hdac_stream_write(w, dev, AZX_REG_ ## reg, value) |
| 443 | #define snd_hdac_stream_writeb(dev, reg, value) \ |
| 444 | _snd_hdac_stream_write(b, dev, AZX_REG_ ## reg, value) |
| 445 | #define snd_hdac_stream_readl(dev, reg) \ |
| 446 | _snd_hdac_stream_read(l, dev, AZX_REG_ ## reg) |
| 447 | #define snd_hdac_stream_readw(dev, reg) \ |
| 448 | _snd_hdac_stream_read(w, dev, AZX_REG_ ## reg) |
| 449 | #define snd_hdac_stream_readb(dev, reg) \ |
| 450 | _snd_hdac_stream_read(b, dev, AZX_REG_ ## reg) |
| 451 | |
| 452 | /* update a register, pass without AZX_REG_ prefix */ |
| 453 | #define snd_hdac_stream_updatel(dev, reg, mask, val) \ |
| 454 | snd_hdac_stream_writel(dev, reg, \ |
| 455 | (snd_hdac_stream_readl(dev, reg) & \ |
| 456 | ~(mask)) | (val)) |
| 457 | #define snd_hdac_stream_updatew(dev, reg, mask, val) \ |
| 458 | snd_hdac_stream_writew(dev, reg, \ |
| 459 | (snd_hdac_stream_readw(dev, reg) & \ |
| 460 | ~(mask)) | (val)) |
| 461 | #define snd_hdac_stream_updateb(dev, reg, mask, val) \ |
| 462 | snd_hdac_stream_writeb(dev, reg, \ |
| 463 | (snd_hdac_stream_readb(dev, reg) & \ |
| 464 | ~(mask)) | (val)) |
| 465 | |
Takashi Iwai | 8f3f600 | 2015-04-14 12:53:28 +0200 | [diff] [blame] | 466 | #ifdef CONFIG_SND_HDA_DSP_LOADER |
| 467 | /* DSP lock helpers */ |
| 468 | #define snd_hdac_dsp_lock_init(dev) mutex_init(&(dev)->dsp_mutex) |
| 469 | #define snd_hdac_dsp_lock(dev) mutex_lock(&(dev)->dsp_mutex) |
| 470 | #define snd_hdac_dsp_unlock(dev) mutex_unlock(&(dev)->dsp_mutex) |
| 471 | #define snd_hdac_stream_is_locked(dev) ((dev)->locked) |
| 472 | /* DSP loader helpers */ |
| 473 | int snd_hdac_dsp_prepare(struct hdac_stream *azx_dev, unsigned int format, |
| 474 | unsigned int byte_size, struct snd_dma_buffer *bufp); |
| 475 | void snd_hdac_dsp_trigger(struct hdac_stream *azx_dev, bool start); |
| 476 | void snd_hdac_dsp_cleanup(struct hdac_stream *azx_dev, |
| 477 | struct snd_dma_buffer *dmab); |
| 478 | #else /* CONFIG_SND_HDA_DSP_LOADER */ |
| 479 | #define snd_hdac_dsp_lock_init(dev) do {} while (0) |
| 480 | #define snd_hdac_dsp_lock(dev) do {} while (0) |
| 481 | #define snd_hdac_dsp_unlock(dev) do {} while (0) |
| 482 | #define snd_hdac_stream_is_locked(dev) 0 |
| 483 | |
| 484 | static inline int |
| 485 | snd_hdac_dsp_prepare(struct hdac_stream *azx_dev, unsigned int format, |
| 486 | unsigned int byte_size, struct snd_dma_buffer *bufp) |
| 487 | { |
| 488 | return 0; |
| 489 | } |
| 490 | |
| 491 | static inline void snd_hdac_dsp_trigger(struct hdac_stream *azx_dev, bool start) |
| 492 | { |
| 493 | } |
| 494 | |
| 495 | static inline void snd_hdac_dsp_cleanup(struct hdac_stream *azx_dev, |
| 496 | struct snd_dma_buffer *dmab) |
| 497 | { |
| 498 | } |
| 499 | #endif /* CONFIG_SND_HDA_DSP_LOADER */ |
| 500 | |
| 501 | |
Takashi Iwai | 71fc4c7 | 2015-03-03 17:33:10 +0100 | [diff] [blame] | 502 | /* |
| 503 | * generic array helpers |
| 504 | */ |
| 505 | void *snd_array_new(struct snd_array *array); |
| 506 | void snd_array_free(struct snd_array *array); |
| 507 | static inline void snd_array_init(struct snd_array *array, unsigned int size, |
| 508 | unsigned int align) |
| 509 | { |
| 510 | array->elem_size = size; |
| 511 | array->alloc_align = align; |
| 512 | } |
| 513 | |
| 514 | static inline void *snd_array_elem(struct snd_array *array, unsigned int idx) |
| 515 | { |
| 516 | return array->list + idx * array->elem_size; |
| 517 | } |
| 518 | |
| 519 | static inline unsigned int snd_array_index(struct snd_array *array, void *ptr) |
| 520 | { |
| 521 | return (unsigned long)(ptr - array->list) / array->elem_size; |
| 522 | } |
| 523 | |
Takashi Iwai | e3d280f | 2015-02-17 21:46:37 +0100 | [diff] [blame] | 524 | #endif /* __SOUND_HDAUDIO_H */ |