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