aboutsummaryrefslogtreecommitdiffstats
path: root/include/sound
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2015-04-14 06:15:47 -0400
committerTakashi Iwai <tiwai@suse.de>2015-04-16 01:27:58 -0400
commit14752412721c61d9ac1e8d8fb51d7148cb15f85b (patch)
treea66845e59854c2a01b107695b69ebf05e692776c /include/sound
parentcad372f1be5ef7cf14b980e679fbf30430dc241f (diff)
ALSA: hda - Add the controller helper codes to hda-core module
This patch adds the controller helper codes to hda-core library. The I/O access ops are added to the bus ops. The CORB/RIRB, the basic attributes like irq# and iomap address, some locks and the list of streams are added to the bus object, together with the stream object and its helpers. Currently the codes are just copied from the legacy driver, so you can find duplicated codes in both directories. Only constants are removed from the original hda_controller.h. More integration work will follow in the later patches. Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'include/sound')
-rw-r--r--include/sound/hda_register.h152
-rw-r--r--include/sound/hdaudio.h224
2 files changed, 373 insertions, 3 deletions
diff --git a/include/sound/hda_register.h b/include/sound/hda_register.h
new file mode 100644
index 000000000000..4f6d3fce6ee6
--- /dev/null
+++ b/include/sound/hda_register.h
@@ -0,0 +1,152 @@
1/*
2 * HD-audio controller (Azalia) registers and helpers
3 *
4 * For traditional reasons, we still use azx_ prefix here
5 */
6
7#ifndef __SOUND_HDA_REGISTER_H
8#define __SOUND_HDA_REGISTER_H
9
10#include <linux/io.h>
11#include <sound/hdaudio.h>
12
13#define AZX_REG_GCAP 0x00
14#define AZX_GCAP_64OK (1 << 0) /* 64bit address support */
15#define AZX_GCAP_NSDO (3 << 1) /* # of serial data out signals */
16#define AZX_GCAP_BSS (31 << 3) /* # of bidirectional streams */
17#define AZX_GCAP_ISS (15 << 8) /* # of input streams */
18#define AZX_GCAP_OSS (15 << 12) /* # of output streams */
19#define AZX_REG_VMIN 0x02
20#define AZX_REG_VMAJ 0x03
21#define AZX_REG_OUTPAY 0x04
22#define AZX_REG_INPAY 0x06
23#define AZX_REG_GCTL 0x08
24#define AZX_GCTL_RESET (1 << 0) /* controller reset */
25#define AZX_GCTL_FCNTRL (1 << 1) /* flush control */
26#define AZX_GCTL_UNSOL (1 << 8) /* accept unsol. response enable */
27#define AZX_REG_WAKEEN 0x0c
28#define AZX_REG_STATESTS 0x0e
29#define AZX_REG_GSTS 0x10
30#define AZX_GSTS_FSTS (1 << 1) /* flush status */
31#define AZX_REG_INTCTL 0x20
32#define AZX_REG_INTSTS 0x24
33#define AZX_REG_WALLCLK 0x30 /* 24Mhz source */
34#define AZX_REG_OLD_SSYNC 0x34 /* SSYNC for old ICH */
35#define AZX_REG_SSYNC 0x38
36#define AZX_REG_CORBLBASE 0x40
37#define AZX_REG_CORBUBASE 0x44
38#define AZX_REG_CORBWP 0x48
39#define AZX_REG_CORBRP 0x4a
40#define AZX_CORBRP_RST (1 << 15) /* read pointer reset */
41#define AZX_REG_CORBCTL 0x4c
42#define AZX_CORBCTL_RUN (1 << 1) /* enable DMA */
43#define AZX_CORBCTL_CMEIE (1 << 0) /* enable memory error irq */
44#define AZX_REG_CORBSTS 0x4d
45#define AZX_CORBSTS_CMEI (1 << 0) /* memory error indication */
46#define AZX_REG_CORBSIZE 0x4e
47
48#define AZX_REG_RIRBLBASE 0x50
49#define AZX_REG_RIRBUBASE 0x54
50#define AZX_REG_RIRBWP 0x58
51#define AZX_RIRBWP_RST (1 << 15) /* write pointer reset */
52#define AZX_REG_RINTCNT 0x5a
53#define AZX_REG_RIRBCTL 0x5c
54#define AZX_RBCTL_IRQ_EN (1 << 0) /* enable IRQ */
55#define AZX_RBCTL_DMA_EN (1 << 1) /* enable DMA */
56#define AZX_RBCTL_OVERRUN_EN (1 << 2) /* enable overrun irq */
57#define AZX_REG_RIRBSTS 0x5d
58#define AZX_RBSTS_IRQ (1 << 0) /* response irq */
59#define AZX_RBSTS_OVERRUN (1 << 2) /* overrun irq */
60#define AZX_REG_RIRBSIZE 0x5e
61
62#define AZX_REG_IC 0x60
63#define AZX_REG_IR 0x64
64#define AZX_REG_IRS 0x68
65#define AZX_IRS_VALID (1<<1)
66#define AZX_IRS_BUSY (1<<0)
67
68#define AZX_REG_DPLBASE 0x70
69#define AZX_REG_DPUBASE 0x74
70#define AZX_DPLBASE_ENABLE 0x1 /* Enable position buffer */
71
72/* SD offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
73enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
74
75/* stream register offsets from stream base */
76#define AZX_REG_SD_CTL 0x00
77#define AZX_REG_SD_STS 0x03
78#define AZX_REG_SD_LPIB 0x04
79#define AZX_REG_SD_CBL 0x08
80#define AZX_REG_SD_LVI 0x0c
81#define AZX_REG_SD_FIFOW 0x0e
82#define AZX_REG_SD_FIFOSIZE 0x10
83#define AZX_REG_SD_FORMAT 0x12
84#define AZX_REG_SD_BDLPL 0x18
85#define AZX_REG_SD_BDLPU 0x1c
86
87/* PCI space */
88#define AZX_PCIREG_TCSEL 0x44
89
90/*
91 * other constants
92 */
93
94/* max number of fragments - we may use more if allocating more pages for BDL */
95#define BDL_SIZE 4096
96#define AZX_MAX_BDL_ENTRIES (BDL_SIZE / 16)
97#define AZX_MAX_FRAG 32
98/* max buffer size - no h/w limit, you can increase as you like */
99#define AZX_MAX_BUF_SIZE (1024*1024*1024)
100
101/* RIRB int mask: overrun[2], response[0] */
102#define RIRB_INT_RESPONSE 0x01
103#define RIRB_INT_OVERRUN 0x04
104#define RIRB_INT_MASK 0x05
105
106/* STATESTS int mask: S3,SD2,SD1,SD0 */
107#define STATESTS_INT_MASK ((1 << HDA_MAX_CODECS) - 1)
108
109/* SD_CTL bits */
110#define SD_CTL_STREAM_RESET 0x01 /* stream reset bit */
111#define SD_CTL_DMA_START 0x02 /* stream DMA start bit */
112#define SD_CTL_STRIPE (3 << 16) /* stripe control */
113#define SD_CTL_TRAFFIC_PRIO (1 << 18) /* traffic priority */
114#define SD_CTL_DIR (1 << 19) /* bi-directional stream */
115#define SD_CTL_STREAM_TAG_MASK (0xf << 20)
116#define SD_CTL_STREAM_TAG_SHIFT 20
117
118/* SD_CTL and SD_STS */
119#define SD_INT_DESC_ERR 0x10 /* descriptor error interrupt */
120#define SD_INT_FIFO_ERR 0x08 /* FIFO error interrupt */
121#define SD_INT_COMPLETE 0x04 /* completion interrupt */
122#define SD_INT_MASK (SD_INT_DESC_ERR|SD_INT_FIFO_ERR|\
123 SD_INT_COMPLETE)
124
125/* SD_STS */
126#define SD_STS_FIFO_READY 0x20 /* FIFO ready */
127
128/* INTCTL and INTSTS */
129#define AZX_INT_ALL_STREAM 0xff /* all stream interrupts */
130#define AZX_INT_CTRL_EN 0x40000000 /* controller interrupt enable bit */
131#define AZX_INT_GLOBAL_EN 0x80000000 /* global interrupt enable bit */
132
133/* below are so far hardcoded - should read registers in future */
134#define AZX_MAX_CORB_ENTRIES 256
135#define AZX_MAX_RIRB_ENTRIES 256
136
137/*
138 * helpers to read the stream position
139 */
140static inline unsigned int
141snd_hdac_stream_get_pos_lpib(struct hdac_stream *stream)
142{
143 return snd_hdac_stream_readl(stream, SD_LPIB);
144}
145
146static inline unsigned int
147snd_hdac_stream_get_pos_posbuf(struct hdac_stream *stream)
148{
149 return le32_to_cpu(*stream->posbuf);
150}
151
152#endif /* __SOUND_HDA_REGISTER_H */
diff --git a/include/sound/hdaudio.h b/include/sound/hdaudio.h
index 2a8aa9dfb83d..9349ccf15a36 100644
--- a/include/sound/hdaudio.h
+++ b/include/sound/hdaudio.h
@@ -6,12 +6,17 @@
6#define __SOUND_HDAUDIO_H 6#define __SOUND_HDAUDIO_H
7 7
8#include <linux/device.h> 8#include <linux/device.h>
9#include <linux/interrupt.h>
10#include <linux/timecounter.h>
11#include <sound/core.h>
12#include <sound/memalloc.h>
9#include <sound/hda_verbs.h> 13#include <sound/hda_verbs.h>
10 14
11/* codec node id */ 15/* codec node id */
12typedef u16 hda_nid_t; 16typedef u16 hda_nid_t;
13 17
14struct hdac_bus; 18struct hdac_bus;
19struct hdac_stream;
15struct hdac_device; 20struct hdac_device;
16struct hdac_driver; 21struct hdac_driver;
17struct hdac_widget_tree; 22struct hdac_widget_tree;
@@ -161,7 +166,7 @@ struct hdac_driver {
161#define drv_to_hdac_driver(_drv) container_of(_drv, struct hdac_driver, driver) 166#define drv_to_hdac_driver(_drv) container_of(_drv, struct hdac_driver, driver)
162 167
163/* 168/*
164 * HD-audio bus base driver 169 * Bus verb operators
165 */ 170 */
166struct hdac_bus_ops { 171struct hdac_bus_ops {
167 /* send a single command */ 172 /* send a single command */
@@ -171,11 +176,50 @@ struct hdac_bus_ops {
171 unsigned int *res); 176 unsigned int *res);
172}; 177};
173 178
179/*
180 * Lowlevel I/O operators
181 */
182struct hdac_io_ops {
183 /* mapped register accesses */
184 void (*reg_writel)(u32 value, u32 __iomem *addr);
185 u32 (*reg_readl)(u32 __iomem *addr);
186 void (*reg_writew)(u16 value, u16 __iomem *addr);
187 u16 (*reg_readw)(u16 __iomem *addr);
188 void (*reg_writeb)(u8 value, u8 __iomem *addr);
189 u8 (*reg_readb)(u8 __iomem *addr);
190};
191
174#define HDA_UNSOL_QUEUE_SIZE 64 192#define HDA_UNSOL_QUEUE_SIZE 64
193#define HDA_MAX_CODECS 8 /* limit by controller side */
194
195/* HD Audio class code */
196#define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403
197
198/*
199 * CORB/RIRB
200 *
201 * Each CORB entry is 4byte, RIRB is 8byte
202 */
203struct hdac_rb {
204 __le32 *buf; /* virtual address of CORB/RIRB buffer */
205 dma_addr_t addr; /* physical address of CORB/RIRB buffer */
206 unsigned short rp, wp; /* RIRB read/write pointers */
207 int cmds[HDA_MAX_CODECS]; /* number of pending requests */
208 u32 res[HDA_MAX_CODECS]; /* last read value */
209};
175 210
211/*
212 * HD-audio bus base driver
213 */
176struct hdac_bus { 214struct hdac_bus {
177 struct device *dev; 215 struct device *dev;
178 const struct hdac_bus_ops *ops; 216 const struct hdac_bus_ops *ops;
217 const struct hdac_io_ops *io_ops;
218
219 /* h/w resources */
220 unsigned long addr;
221 void __iomem *remap_addr;
222 int irq;
179 223
180 /* codec linked list */ 224 /* codec linked list */
181 struct list_head codec_list; 225 struct list_head codec_list;
@@ -189,18 +233,45 @@ struct hdac_bus {
189 unsigned int unsol_rp, unsol_wp; 233 unsigned int unsol_rp, unsol_wp;
190 struct work_struct unsol_work; 234 struct work_struct unsol_work;
191 235
236 /* bit flags of detected codecs */
237 unsigned long codec_mask;
238
192 /* bit flags of powered codecs */ 239 /* bit flags of powered codecs */
193 unsigned long codec_powered; 240 unsigned long codec_powered;
194 241
195 /* flags */ 242 /* CORB/RIRB */
243 struct hdac_rb corb;
244 struct hdac_rb rirb;
245 unsigned int last_cmd[HDA_MAX_CODECS]; /* last sent command */
246
247 /* CORB/RIRB and position buffers */
248 struct snd_dma_buffer rb;
249 struct snd_dma_buffer posbuf;
250
251 /* hdac_stream linked list */
252 struct list_head stream_list;
253
254 /* operation state */
255 bool chip_init:1; /* h/w initialized */
256
257 /* behavior flags */
196 bool sync_write:1; /* sync after verb write */ 258 bool sync_write:1; /* sync after verb write */
259 bool use_posbuf:1; /* use position buffer */
260 bool snoop:1; /* enable snooping */
261 bool align_bdle_4k:1; /* BDLE align 4K boundary */
262 bool reverse_assign:1; /* assign devices in reverse order */
263 bool corbrp_self_clear:1; /* CORBRP clears itself after reset */
264
265 int bdl_pos_adj; /* BDL position adjustment */
197 266
198 /* locks */ 267 /* locks */
268 spinlock_t reg_lock;
199 struct mutex cmd_mutex; 269 struct mutex cmd_mutex;
200}; 270};
201 271
202int snd_hdac_bus_init(struct hdac_bus *bus, struct device *dev, 272int snd_hdac_bus_init(struct hdac_bus *bus, struct device *dev,
203 const struct hdac_bus_ops *ops); 273 const struct hdac_bus_ops *ops,
274 const struct hdac_io_ops *io_ops);
204void snd_hdac_bus_exit(struct hdac_bus *bus); 275void snd_hdac_bus_exit(struct hdac_bus *bus);
205int snd_hdac_bus_exec_verb(struct hdac_bus *bus, unsigned int addr, 276int snd_hdac_bus_exec_verb(struct hdac_bus *bus, unsigned int addr,
206 unsigned int cmd, unsigned int *res); 277 unsigned int cmd, unsigned int *res);
@@ -222,6 +293,153 @@ static inline void snd_hdac_codec_link_down(struct hdac_device *codec)
222 clear_bit(codec->addr, &codec->bus->codec_powered); 293 clear_bit(codec->addr, &codec->bus->codec_powered);
223} 294}
224 295
296int snd_hdac_bus_send_cmd(struct hdac_bus *bus, unsigned int val);
297int snd_hdac_bus_get_response(struct hdac_bus *bus, unsigned int addr,
298 unsigned int *res);
299
300bool snd_hdac_bus_init_chip(struct hdac_bus *bus, bool full_reset);
301void snd_hdac_bus_stop_chip(struct hdac_bus *bus);
302void snd_hdac_bus_init_cmd_io(struct hdac_bus *bus);
303void snd_hdac_bus_stop_cmd_io(struct hdac_bus *bus);
304void snd_hdac_bus_enter_link_reset(struct hdac_bus *bus);
305void snd_hdac_bus_exit_link_reset(struct hdac_bus *bus);
306
307void snd_hdac_bus_update_rirb(struct hdac_bus *bus);
308void snd_hdac_bus_handle_stream_irq(struct hdac_bus *bus, unsigned int status,
309 void (*ack)(struct hdac_bus *,
310 struct hdac_stream *));
311
312/*
313 * macros for easy use
314 */
315#define _snd_hdac_chip_write(type, chip, reg, value) \
316 ((chip)->io_ops->reg_write ## type(value, (chip)->remap_addr + (reg)))
317#define _snd_hdac_chip_read(type, chip, reg) \
318 ((chip)->io_ops->reg_read ## type((chip)->remap_addr + (reg)))
319
320/* read/write a register, pass without AZX_REG_ prefix */
321#define snd_hdac_chip_writel(chip, reg, value) \
322 _snd_hdac_chip_write(l, chip, AZX_REG_ ## reg, value)
323#define snd_hdac_chip_writew(chip, reg, value) \
324 _snd_hdac_chip_write(w, chip, AZX_REG_ ## reg, value)
325#define snd_hdac_chip_writeb(chip, reg, value) \
326 _snd_hdac_chip_write(b, chip, AZX_REG_ ## reg, value)
327#define snd_hdac_chip_readl(chip, reg) \
328 _snd_hdac_chip_read(l, chip, AZX_REG_ ## reg)
329#define snd_hdac_chip_readw(chip, reg) \
330 _snd_hdac_chip_read(w, chip, AZX_REG_ ## reg)
331#define snd_hdac_chip_readb(chip, reg) \
332 _snd_hdac_chip_read(b, chip, AZX_REG_ ## reg)
333
334/* update a register, pass without AZX_REG_ prefix */
335#define snd_hdac_chip_updatel(chip, reg, mask, val) \
336 snd_hdac_chip_writel(chip, reg, \
337 (snd_hdac_chip_readl(chip, reg) & ~(mask)) | (val))
338#define snd_hdac_chip_updatew(chip, reg, mask, val) \
339 snd_hdac_chip_writew(chip, reg, \
340 (snd_hdac_chip_readw(chip, reg) & ~(mask)) | (val))
341#define snd_hdac_chip_updateb(chip, reg, mask, val) \
342 snd_hdac_chip_writeb(chip, reg, \
343 (snd_hdac_chip_readb(chip, reg) & ~(mask)) | (val))
344
345/*
346 * HD-audio stream
347 */
348struct hdac_stream {
349 struct hdac_bus *bus;
350 struct snd_dma_buffer bdl; /* BDL buffer */
351 __le32 *posbuf; /* position buffer pointer */
352 int direction; /* playback / capture (SNDRV_PCM_STREAM_*) */
353
354 unsigned int bufsize; /* size of the play buffer in bytes */
355 unsigned int period_bytes; /* size of the period in bytes */
356 unsigned int frags; /* number for period in the play buffer */
357 unsigned int fifo_size; /* FIFO size */
358
359 void __iomem *sd_addr; /* stream descriptor pointer */
360
361 u32 sd_int_sta_mask; /* stream int status mask */
362
363 /* pcm support */
364 struct snd_pcm_substream *substream; /* assigned substream,
365 * set in PCM open
366 */
367 unsigned int format_val; /* format value to be set in the
368 * controller and the codec
369 */
370 unsigned char stream_tag; /* assigned stream */
371 unsigned char index; /* stream index */
372 int assigned_key; /* last device# key assigned to */
373
374 bool opened:1;
375 bool running:1;
376 bool no_period_wakeup:1;
377
378 /* timestamp */
379 unsigned long start_wallclk; /* start + minimum wallclk */
380 unsigned long period_wallclk; /* wallclk for period */
381 struct timecounter tc;
382 struct cyclecounter cc;
383 int delay_negative_threshold;
384
385 struct list_head list;
386};
387
388void snd_hdac_stream_init(struct hdac_bus *bus, struct hdac_stream *azx_dev,
389 int idx, int direction, int tag);
390struct hdac_stream *snd_hdac_stream_assign(struct hdac_bus *bus,
391 struct snd_pcm_substream *substream);
392void snd_hdac_stream_release(struct hdac_stream *azx_dev);
393
394int snd_hdac_stream_setup(struct hdac_stream *azx_dev);
395void snd_hdac_stream_cleanup(struct hdac_stream *azx_dev);
396int snd_hdac_stream_setup_periods(struct hdac_stream *azx_dev);
397void snd_hdac_stream_start(struct hdac_stream *azx_dev, bool fresh_start);
398void snd_hdac_stream_clear(struct hdac_stream *azx_dev);
399void snd_hdac_stream_stop(struct hdac_stream *azx_dev);
400void snd_hdac_stream_reset(struct hdac_stream *azx_dev);
401void snd_hdac_stream_sync_trigger(struct hdac_stream *azx_dev, bool set,
402 unsigned int streams, unsigned int reg);
403void snd_hdac_stream_sync(struct hdac_stream *azx_dev, bool start,
404 unsigned int streams);
405void snd_hdac_stream_timecounter_init(struct hdac_stream *azx_dev,
406 unsigned int streams);
407/*
408 * macros for easy use
409 */
410#define _snd_hdac_stream_write(type, dev, reg, value) \
411 ((dev)->bus->io_ops->reg_write ## type(value, (dev)->sd_addr + (reg)))
412#define _snd_hdac_stream_read(type, dev, reg) \
413 ((dev)->bus->io_ops->reg_read ## type((dev)->sd_addr + (reg)))
414
415/* read/write a register, pass without AZX_REG_ prefix */
416#define snd_hdac_stream_writel(dev, reg, value) \
417 _snd_hdac_stream_write(l, dev, AZX_REG_ ## reg, value)
418#define snd_hdac_stream_writew(dev, reg, value) \
419 _snd_hdac_stream_write(w, dev, AZX_REG_ ## reg, value)
420#define snd_hdac_stream_writeb(dev, reg, value) \
421 _snd_hdac_stream_write(b, dev, AZX_REG_ ## reg, value)
422#define snd_hdac_stream_readl(dev, reg) \
423 _snd_hdac_stream_read(l, dev, AZX_REG_ ## reg)
424#define snd_hdac_stream_readw(dev, reg) \
425 _snd_hdac_stream_read(w, dev, AZX_REG_ ## reg)
426#define snd_hdac_stream_readb(dev, reg) \
427 _snd_hdac_stream_read(b, dev, AZX_REG_ ## reg)
428
429/* update a register, pass without AZX_REG_ prefix */
430#define snd_hdac_stream_updatel(dev, reg, mask, val) \
431 snd_hdac_stream_writel(dev, reg, \
432 (snd_hdac_stream_readl(dev, reg) & \
433 ~(mask)) | (val))
434#define snd_hdac_stream_updatew(dev, reg, mask, val) \
435 snd_hdac_stream_writew(dev, reg, \
436 (snd_hdac_stream_readw(dev, reg) & \
437 ~(mask)) | (val))
438#define snd_hdac_stream_updateb(dev, reg, mask, val) \
439 snd_hdac_stream_writeb(dev, reg, \
440 (snd_hdac_stream_readb(dev, reg) & \
441 ~(mask)) | (val))
442
225/* 443/*
226 * generic array helpers 444 * generic array helpers
227 */ 445 */