Skip to contentSkip to conversation

HD-audio controller driver split

PATCH New Takashi Iwai 1 participant 22 messages Apr 24, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover HD-audio controller driver split

Hi,

here is a patch series to split HD-audio controller driver code to snd-hda-core helper module. It's not targeted for 4.1 but rather for 4.2 together with ASoC HD-audio.

There is no real changes from the functionality POV. It's mostly code splits and cleanups.

The latest patches are found in topic/hda branch of sound git tree.

Takashi

===

Jeeja KP (2):
ALSA: hda - moved alloc/free stream pages function to controller
library
ALSA: hda - add generic functions to set hdac stream params

Ramesh Babu (1):
ALSA: hda - add ASoC device type for hda core

Takashi Iwai (18):
ALSA: hda - Handle error from get_response bus ops directly
ALSA: hda - Add the controller helper codes to hda-core module
ALSA: hda - Add DSP loader to core library code
ALSA: hda - Merge codec and controller helpers
ALSA: hda - Move send_cmd / get_response to hdac_bus_ops
ALSA: hda - Pass bus io_ops directly from the top-level driver
ALSA: hda - Migrate hdac_stream into legacy driver
ALSA: hda - Migrate more hdac_stream codes
ALSA: hda - Embed bus into controller object
ALSA: hda - Minor refactoring
ALSA: hda - Move PCM format and rate handling code to core library
ALSA: hda - Add missing inclusion of <linux/clocksource.h>
ALSA: hda - Reenable tracepoints for controller
ALSA: hda/tegra - Fix build error and warning
ALSA: hda - Drop azx_sd_read*/write*() macros
ALSA: hda - Replace hda_bus_ops with static binding
ALSA: hda - Move prepared flag into struct hdac_stream
ALSA: hda - Replace open codes with snd_hdac_stream_set_params()

 include/sound/hda_register.h    |  152 +++++
 include/sound/hdaudio.h         |  286 ++++++++-
 sound/hda/Kconfig               |    3 +
 sound/hda/Makefile              |    2 +-
 sound/hda/hdac_bus.c            |   20 +-
 sound/hda/hdac_controller.c     |  507 +++++++++++++++
 sound/hda/hdac_device.c         |  300 +++++++++
 sound/hda/hdac_stream.c         |  686 ++++++++++++++++++++
 sound/pci/hda/Kconfig           |    3 -
 sound/pci/hda/Makefile          |    3 +-
 sound/pci/hda/hda_codec.c       |  421 +------------
 sound/pci/hda/hda_codec.h       |   80 +--
 sound/pci/hda/hda_controller.c  | 1330 ++++++++-------------------------------
 sound/pci/hda/hda_controller.h  |  270 +-------
 sound/pci/hda/hda_intel.c       |  234 ++++---
 sound/pci/hda/hda_intel.h       |    1 +
 sound/pci/hda/hda_intel_trace.h |    4 +-
 sound/pci/hda/hda_tegra.c       |   76 +--
 sound/pci/hda/patch_ca0132.c    |    7 +-
 19 files changed, 2457 insertions(+), 1928 deletions(-)
 create mode 100644 include/sound/hda_register.h
 create mode 100644 sound/hda/hdac_controller.c
 create mode 100644 sound/hda/hdac_stream.c
Signature · 1 line
2.3.5
#1 lore raw

PATCH 1/21 ALSA: hda - Handle error from get_response bus ops directly

... and drop bus->rirb_error flag. This makes the code simpler.

We treat -EAGAIN from get_response ops as a special meaning: it allows the caller to retry after bus reset.

---
 sound/pci/hda/hda_codec.c      | 17 +++++++--------
 sound/pci/hda/hda_codec.h      |  3 +--
 sound/pci/hda/hda_controller.c | 47 +++++++++++++++++++++---------------------
 3 files changed, 32 insertions(+), 35 deletions(-)
sound/pci/hda/hda_codec.c +7 -10
index e70a7fb393dd..c13d5c3e1d03 100644
@@ -146,7 +146,7 @@ static int codec_exec_verb(struct hdac_device *dev, unsigned int cmd,
 	bus->no_response_fallback = 0;
 	mutex_unlock(&bus->core.cmd_mutex);
 	snd_hda_power_down_pm(codec);
-	if (!codec_in_pm(codec) && res && err < 0 && bus->rirb_error) {
+	if (!codec_in_pm(codec) && res && err == -EAGAIN) {
 		if (bus->response_reset) {
 			codec_dbg(codec,
 				  "resetting BUS due to fatal communication error\n");
@@ -436,9 +436,8 @@ static unsigned int get_num_devices(struct hda_codec *codec, hda_nid_t nid)
 	    get_wcaps_type(wcaps) != AC_WID_PIN)
 		return 0;
 
-	parm = snd_hda_param_read(codec, nid, AC_PAR_DEVLIST_LEN);
-	if (parm == -1 && codec->bus->rirb_error)
-		parm = 0;
+	if (_snd_hdac_read_parm(&codec->core, nid, AC_PAR_DEVLIST_LEN, &parm))
+		return 0; /* error */
 	return parm & AC_DEV_LIST_LEN_MASK;
 }
 
@@ -467,10 +466,9 @@ int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid,
 
 	devices = 0;
 	while (devices < dev_len) {
-		parm = snd_hda_codec_read(codec, nid, 0,
-					  AC_VERB_GET_DEVICE_LIST, devices);
-		if (parm == -1 && codec->bus->rirb_error)
-			break;
+		if (snd_hdac_read(&codec->core, nid,
+				  AC_VERB_GET_DEVICE_LIST, devices, &parm))
+			break; /* error */
 
 		for (i = 0; i < 8; i++) {
 			dev_list[devices] = (u8)parm;
@@ -520,8 +518,7 @@ static int _hda_bus_get_response(struct hdac_bus *_bus, unsigned int addr,
 				 unsigned int *res)
 {
 	struct hda_bus *bus = container_of(_bus, struct hda_bus, core);
-	*res = bus->ops.get_response(bus, addr);
-	return bus->rirb_error ? -EIO : 0;
+	return bus->ops.get_response(bus, addr, res);
 }
 
 static const struct hdac_bus_ops bus_ops = {
sound/pci/hda/hda_codec.h +1 -2
index 9075ac28dc4b..fc4f76188a1d 100644
@@ -45,7 +45,7 @@ struct hda_bus_ops {
 	/* send a single command */
 	int (*command)(struct hda_bus *bus, unsigned int cmd);
 	/* get a response from the last command */
-	unsigned int (*get_response)(struct hda_bus *bus, unsigned int addr);
+	int (*get_response)(struct hda_bus *bus, unsigned int addr, unsigned int *res);
 	/* free the private data */
 	void (*private_free)(struct hda_bus *);
 	/* attach a PCM stream */
@@ -92,7 +92,6 @@ struct hda_bus {
 	unsigned int allow_bus_reset:1;	/* allow bus reset at fatal error */
 	/* status for codec/controller */
 	unsigned int shutdown :1;	/* being unloaded */
-	unsigned int rirb_error:1;	/* error in codec communication */
 	unsigned int response_reset:1;	/* controller was reset */
 	unsigned int in_reset:1;	/* during reset operation */
 	unsigned int no_response_fallback:1; /* don't fallback at RIRB error */
sound/pci/hda/hda_controller.c +24 -23

132 lines not on this page · raw message

Signature · 1 line
2.3.5
#2 lore raw

PATCH 2/21 ALSA: hda - Add the controller helper codes to hda-core module

In reply to Takashi Iwai

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.

---
 include/sound/hda_register.h   | 152 ++++++++++++
 include/sound/hdaudio.h        | 224 ++++++++++++++++-
 sound/hda/Makefile             |   2 +-
 sound/hda/hdac_bus.c           |  20 +-
 sound/hda/hdac_controller.c    | 449 ++++++++++++++++++++++++++++++++++
 sound/hda/hdac_stream.c        | 536 +++++++++++++++++++++++++++++++++++++++++
 sound/pci/hda/hda_codec.c      |   2 +-
 sound/pci/hda/hda_controller.h | 132 +---------
 8 files changed, 1380 insertions(+), 137 deletions(-)
 create mode 100644 include/sound/hda_register.h
 create mode 100644 sound/hda/hdac_controller.c
 create mode 100644 sound/hda/hdac_stream.c
include/sound/hda_register.h new file +152 -0
new file mode 100644
index 000000000000..4f6d3fce6ee6
@@ -0,0 +1,152 @@
+/*
+ * HD-audio controller (Azalia) registers and helpers
+ *
+ * For traditional reasons, we still use azx_ prefix here
+ */
+
+#ifndef __SOUND_HDA_REGISTER_H
+#define __SOUND_HDA_REGISTER_H
+
+#include <linux/io.h>
+#include <sound/hdaudio.h>
+
+#define AZX_REG_GCAP			0x00
+#define   AZX_GCAP_64OK		(1 << 0)   /* 64bit address support */
+#define   AZX_GCAP_NSDO		(3 << 1)   /* # of serial data out signals */
+#define   AZX_GCAP_BSS		(31 << 3)  /* # of bidirectional streams */
+#define   AZX_GCAP_ISS		(15 << 8)  /* # of input streams */
+#define   AZX_GCAP_OSS		(15 << 12) /* # of output streams */
+#define AZX_REG_VMIN			0x02
+#define AZX_REG_VMAJ			0x03
+#define AZX_REG_OUTPAY			0x04
+#define AZX_REG_INPAY			0x06
+#define AZX_REG_GCTL			0x08
+#define   AZX_GCTL_RESET	(1 << 0)   /* controller reset */
+#define   AZX_GCTL_FCNTRL	(1 << 1)   /* flush control */
+#define   AZX_GCTL_UNSOL	(1 << 8)   /* accept unsol. response enable */
+#define AZX_REG_WAKEEN			0x0c
+#define AZX_REG_STATESTS		0x0e
+#define AZX_REG_GSTS			0x10
+#define   AZX_GSTS_FSTS		(1 << 1)   /* flush status */
+#define AZX_REG_INTCTL			0x20
+#define AZX_REG_INTSTS			0x24
+#define AZX_REG_WALLCLK			0x30	/* 24Mhz source */
+#define AZX_REG_OLD_SSYNC		0x34	/* SSYNC for old ICH */
+#define AZX_REG_SSYNC			0x38
+#define AZX_REG_CORBLBASE		0x40
+#define AZX_REG_CORBUBASE		0x44
+#define AZX_REG_CORBWP			0x48
+#define AZX_REG_CORBRP			0x4a
+#define   AZX_CORBRP_RST	(1 << 15)  /* read pointer reset */
+#define AZX_REG_CORBCTL			0x4c
+#define   AZX_CORBCTL_RUN	(1 << 1)   /* enable DMA */
+#define   AZX_CORBCTL_CMEIE	(1 << 0)   /* enable memory error irq */
+#define AZX_REG_CORBSTS			0x4d
+#define   AZX_CORBSTS_CMEI	(1 << 0)   /* memory error indication */
+#define AZX_REG_CORBSIZE		0x4e
+
+#define AZX_REG_RIRBLBASE		0x50
+#define AZX_REG_RIRBUBASE		0x54
+#define AZX_REG_RIRBWP			0x58
+#define   AZX_RIRBWP_RST	(1 << 15)  /* write pointer reset */
+#define AZX_REG_RINTCNT			0x5a
+#define AZX_REG_RIRBCTL			0x5c
+#define   AZX_RBCTL_IRQ_EN	(1 << 0)   /* enable IRQ */
+#define   AZX_RBCTL_DMA_EN	(1 << 1)   /* enable DMA */
+#define   AZX_RBCTL_OVERRUN_EN	(1 << 2)   /* enable overrun irq */
+#define AZX_REG_RIRBSTS			0x5d
+#define   AZX_RBSTS_IRQ		(1 << 0)   /* response irq */
+#define   AZX_RBSTS_OVERRUN	(1 << 2)   /* overrun irq */
+#define AZX_REG_RIRBSIZE		0x5e
+
+#define AZX_REG_IC			0x60
+#define AZX_REG_IR			0x64
+#define AZX_REG_IRS			0x68
+#define   AZX_IRS_VALID		(1<<1)
+#define   AZX_IRS_BUSY		(1<<0)
+
+#define AZX_REG_DPLBASE			0x70
+#define AZX_REG_DPUBASE			0x74
+#define   AZX_DPLBASE_ENABLE	0x1	/* Enable position buffer */
+
+/* SD offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
+enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
+
+/* stream register offsets from stream base */
+#define AZX_REG_SD_CTL			0x00
+#define AZX_REG_SD_STS			0x03
+#define AZX_REG_SD_LPIB			0x04
+#define AZX_REG_SD_CBL			0x08
+#define AZX_REG_SD_LVI			0x0c
+#define AZX_REG_SD_FIFOW		0x0e
+#define AZX_REG_SD_FIFOSIZE		0x10
+#define AZX_REG_SD_FORMAT		0x12
+#define AZX_REG_SD_BDLPL		0x18
+#define AZX_REG_SD_BDLPU		0x1c
+
+/* PCI space */
+#define AZX_PCIREG_TCSEL		0x44
+
+/*
+ * other constants
+ */
+
+/* max number of fragments - we may use more if allocating more pages for BDL */
+#define BDL_SIZE		4096
+#define AZX_MAX_BDL_ENTRIES	(BDL_SIZE / 16)
+#define AZX_MAX_FRAG		32
+/* max buffer size - no h/w limit, you can increase as you like */
+#define AZX_MAX_BUF_SIZE	(1024*1024*1024)
+
+/* RIRB int mask: overrun[2], response[0] */
+#define RIRB_INT_RESPONSE	0x01
+#define RIRB_INT_OVERRUN	0x04
+#define RIRB_INT_MASK		0x05
+
+/* STATESTS int mask: S3,SD2,SD1,SD0 */
+#define STATESTS_INT_MASK	((1 << HDA_MAX_CODECS) - 1)
+
+/* SD_CTL bits */
+#define SD_CTL_STREAM_RESET	0x01	/* stream reset bit */
+#define SD_CTL_DMA_START	0x02	/* stream DMA start bit */
+#define SD_CTL_STRIPE		(3 << 16)	/* stripe control */
+#define SD_CTL_TRAFFIC_PRIO	(1 << 18)	/* traffic priority */
+#define SD_CTL_DIR		(1 << 19)	/* bi-directional stream */
+#define SD_CTL_STREAM_TAG_MASK	(0xf << 20)
+#define SD_CTL_STREAM_TAG_SHIFT	20
+
+/* SD_CTL and SD_STS */
+#define SD_INT_DESC_ERR		0x10	/* descriptor error interrupt */
+#define SD_INT_FIFO_ERR		0x08	/* FIFO error interrupt */
+#define SD_INT_COMPLETE		0x04	/* completion interrupt */
+#define SD_INT_MASK		(SD_INT_DESC_ERR|SD_INT_FIFO_ERR|\
+				 SD_INT_COMPLETE)
+
+/* SD_STS */
+#define SD_STS_FIFO_READY	0x20	/* FIFO ready */
+
+/* INTCTL and INTSTS */
+#define AZX_INT_ALL_STREAM	0xff	   /* all stream interrupts */
+#define AZX_INT_CTRL_EN	0x40000000 /* controller interrupt enable bit */
+#define AZX_INT_GLOBAL_EN	0x80000000 /* global interrupt enable bit */
+
+/* below are so far hardcoded - should read registers in future */
+#define AZX_MAX_CORB_ENTRIES	256
+#define AZX_MAX_RIRB_ENTRIES	256
+
+/*
+ * helpers to read the stream position
+ */
+static inline unsigned int
+snd_hdac_stream_get_pos_lpib(struct hdac_stream *stream)
+{
+	return snd_hdac_stream_readl(stream, SD_LPIB);
+}
+
+static inline unsigned int
+snd_hdac_stream_get_pos_posbuf(struct hdac_stream *stream)
+{
+	return le32_to_cpu(*stream->posbuf);
+}
+
+#endif /* __SOUND_HDA_REGISTER_H */
include/sound/hdaudio.h +221 -3

275 lines not on this page · raw message

sound/hda/Makefile +1 -1
index 7a359f5b7e25..5b4bb47c16fd 100644
@@ -1,5 +1,5 @@
 snd-hda-core-objs := hda_bus_type.o hdac_bus.o hdac_device.o hdac_sysfs.o \
-	hdac_regmap.o array.o
+	hdac_regmap.o hdac_controller.o hdac_stream.o array.o
 
 snd-hda-core-objs += trace.o
 CFLAGS_trace.o := -I$(src)
sound/hda/hdac_bus.c +18 -2
index 8e262da74f6a..27c447e4fe5c 100644
@@ -11,21 +11,36 @@
 
 static void process_unsol_events(struct work_struct *work);
 
+static const struct hdac_bus_ops default_ops = {
+	.command = snd_hdac_bus_send_cmd,
+	.get_response = snd_hdac_bus_get_response,
+};
+
 /**
  * snd_hdac_bus_init - initialize a HD-audio bas bus
  * @bus: the pointer to bus object
+ * @ops: bus verb operators
+ * @io_ops: lowlevel I/O operators
  *
  * Returns 0 if successful, or a negative error code.
  */
 int snd_hdac_bus_init(struct hdac_bus *bus, struct device *dev,
-		      const struct hdac_bus_ops *ops)
+		      const struct hdac_bus_ops *ops,
+		      const struct hdac_io_ops *io_ops)
 {
 	memset(bus, 0, sizeof(*bus));
 	bus->dev = dev;
-	bus->ops = ops;
+	if (ops)
+		bus->ops = ops;
+	else
+		bus->ops = &default_ops;
+	bus->io_ops = io_ops;
+	INIT_LIST_HEAD(&bus->stream_list);
 	INIT_LIST_HEAD(&bus->codec_list);
 	INIT_WORK(&bus->unsol_work, process_unsol_events);
+	spin_lock_init(&bus->reg_lock);
 	mutex_init(&bus->cmd_mutex);
+	bus->irq = -1;
 	return 0;
 }
 EXPORT_SYMBOL_GPL(snd_hdac_bus_init);
@@ -36,6 +51,7 @@ EXPORT_SYMBOL_GPL(snd_hdac_bus_init);
  */
 void snd_hdac_bus_exit(struct hdac_bus *bus)
 {
+	WARN_ON(!list_empty(&bus->stream_list));
 	WARN_ON(!list_empty(&bus->codec_list));
 	cancel_work_sync(&bus->unsol_work);
 }
sound/hda/hdac_controller.c new file +449 -0

449 lines not on this page · raw message

sound/hda/hdac_stream.c new file +536 -0

536 lines not on this page · raw message

sound/pci/hda/hda_codec.c +1 -1
index c13d5c3e1d03..b86e2f449e56 100644
@@ -550,7 +550,7 @@ int snd_hda_bus_new(struct snd_card *card,
 	if (!bus)
 		return -ENOMEM;
 
-	err = snd_hdac_bus_init(&bus->core, card->dev, &bus_ops);
+	err = snd_hdac_bus_init(&bus->core, card->dev, &bus_ops, NULL);
 	if (err < 0) {
 		kfree(bus);
 		return err;
sound/pci/hda/hda_controller.h +2 -130

146 lines not on this page · raw message

Signature · 1 line
2.3.5
#3 lore raw

PATCH 3/21 ALSA: hda - Add DSP loader to core library code

In reply to Takashi Iwai

Copied from the legacy driver code, no transition done yet.

---
 include/sound/hdaudio.h |  46 ++++++++++++++++++++
 sound/hda/Kconfig       |   3 ++
 sound/hda/hdac_stream.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++++
 sound/pci/hda/Kconfig   |   3 --
 4 files changed, 162 insertions(+), 3 deletions(-)
include/sound/hdaudio.h +46 -0
index 9349ccf15a36..69f27bc49eb4 100644
@@ -187,6 +187,11 @@ struct hdac_io_ops {
 	u16 (*reg_readw)(u16 __iomem *addr);
 	void (*reg_writeb)(u8 value, u8 __iomem *addr);
 	u8 (*reg_readb)(u8 __iomem *addr);
+	/* Allocation ops */
+	int (*dma_alloc_pages)(struct hdac_bus *bus, int type, size_t size,
+			       struct snd_dma_buffer *buf);
+	void (*dma_free_pages)(struct hdac_bus *bus,
+			       struct snd_dma_buffer *buf);
 };
 
 #define HDA_UNSOL_QUEUE_SIZE	64
@@ -374,6 +379,7 @@ struct hdac_stream {
 	bool opened:1;
 	bool running:1;
 	bool no_period_wakeup:1;
+	bool locked:1;
 
 	/* timestamp */
 	unsigned long start_wallclk;	/* start + minimum wallclk */
@@ -383,6 +389,10 @@ struct hdac_stream {
 	int delay_negative_threshold;
 
 	struct list_head list;
+#ifdef CONFIG_SND_HDA_DSP_LOADER
+	/* DSP access mutex */
+	struct mutex dsp_mutex;
+#endif
 };
 
 void snd_hdac_stream_init(struct hdac_bus *bus, struct hdac_stream *azx_dev,
@@ -440,6 +450,42 @@ void snd_hdac_stream_timecounter_init(struct hdac_stream *azx_dev,
 			       (snd_hdac_stream_readb(dev, reg) & \
 				~(mask)) | (val))
 
+#ifdef CONFIG_SND_HDA_DSP_LOADER
+/* DSP lock helpers */
+#define snd_hdac_dsp_lock_init(dev)	mutex_init(&(dev)->dsp_mutex)
+#define snd_hdac_dsp_lock(dev)		mutex_lock(&(dev)->dsp_mutex)
+#define snd_hdac_dsp_unlock(dev)	mutex_unlock(&(dev)->dsp_mutex)
+#define snd_hdac_stream_is_locked(dev)	((dev)->locked)
+/* DSP loader helpers */
+int snd_hdac_dsp_prepare(struct hdac_stream *azx_dev, unsigned int format,
+			 unsigned int byte_size, struct snd_dma_buffer *bufp);
+void snd_hdac_dsp_trigger(struct hdac_stream *azx_dev, bool start);
+void snd_hdac_dsp_cleanup(struct hdac_stream *azx_dev,
+			  struct snd_dma_buffer *dmab);
+#else /* CONFIG_SND_HDA_DSP_LOADER */
+#define snd_hdac_dsp_lock_init(dev)	do {} while (0)
+#define snd_hdac_dsp_lock(dev)		do {} while (0)
+#define snd_hdac_dsp_unlock(dev)	do {} while (0)
+#define snd_hdac_stream_is_locked(dev)	0
+
+static inline int
+snd_hdac_dsp_prepare(struct hdac_stream *azx_dev, unsigned int format,
+		     unsigned int byte_size, struct snd_dma_buffer *bufp)
+{
+	return 0;
+}
+
+static inline void snd_hdac_dsp_trigger(struct hdac_stream *azx_dev, bool start)
+{
+}
+
+static inline void snd_hdac_dsp_cleanup(struct hdac_stream *azx_dev,
+					struct snd_dma_buffer *dmab)
+{
+}
+#endif /* CONFIG_SND_HDA_DSP_LOADER */
+
+
 /*
  * generic array helpers
  */
sound/hda/Kconfig +3 -0
index 001c6588a5ff..7a17fca4f627 100644
@@ -1,3 +1,6 @@
 config SND_HDA_CORE
 	tristate
 	select REGMAP
+
+config SND_HDA_DSP_LOADER
+	bool
sound/hda/hdac_stream.c +113 -0

122 lines not on this page · raw message

sound/pci/hda/Kconfig +0 -3
index a5ed1c181784..47aa7b8b7519 100644
@@ -38,9 +38,6 @@ config SND_HDA_TEGRA
 
 if SND_HDA
 
-config SND_HDA_DSP_LOADER
-	bool
-
 config SND_HDA_PREALLOC_SIZE
 	int "Pre-allocated buffer size for HD-audio driver"
 	range 0 32768
Signature · 1 line
2.3.5
#4 lore raw

PATCH 4/21 ALSA: hda - moved alloc/free stream pages function to controller library

In reply to Takashi Iwai

From: Jeeja KP <[email protected]>

Moved azx_alloc_stream_pages and azx_free_stream_pages to controller library.

---
 include/sound/hdaudio.h     |  3 +++
 sound/hda/hdac_controller.c | 58 +++++++++++++++++++++++++++++++++++++++++++++
 sound/hda/hdac_stream.c     |  2 --
 3 files changed, 61 insertions(+), 2 deletions(-)
include/sound/hdaudio.h +3 -0
index 69f27bc49eb4..59d21848a472 100644
@@ -314,6 +314,9 @@ void snd_hdac_bus_handle_stream_irq(struct hdac_bus *bus, unsigned int status,
 				    void (*ack)(struct hdac_bus *,
 						struct hdac_stream *));
 
+int snd_hdac_bus_alloc_stream_pages(struct hdac_bus *bus);
+void snd_hdac_bus_free_stream_pages(struct hdac_bus *bus);
+
 /*
  * macros for easy use
  */
sound/hda/hdac_controller.c +58 -0

61 lines not on this page · raw message

sound/hda/hdac_stream.c +0 -2
index 7f6b845d90eb..8bd67a824b5e 100644
@@ -24,8 +24,6 @@ void snd_hdac_stream_init(struct hdac_bus *bus, struct hdac_stream *azx_dev,
 			  int idx, int direction, int tag)
 {
 	azx_dev->bus = bus;
-	if (bus->posbuf.area)
-		azx_dev->posbuf = (__le32 *)(bus->posbuf.area + idx * 8);
 	/* offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
 	azx_dev->sd_addr = bus->remap_addr + (0x20 * idx + 0x80);
 	/* int mask: SDI0=0x01, SDI1=0x02, ... SDO3=0x80 */
Signature · 1 line
2.3.5
#5 lore raw

PATCH 5/21 ALSA: hda - Merge codec and controller helpers

In reply to Takashi Iwai

There is no much merit to keep the HD-audio codec and controller helper codes in separate modules any longer. Let's merge them into a single helper module.

This patch just changes Makefile entries to merge two individual modules to one. The only code change is the removal of superfluous MODULE_*() macros in one side.

---
 sound/pci/hda/Makefile         | 3 +--
 sound/pci/hda/hda_controller.c | 3 ---
 2 files changed, 1 insertion(+), 5 deletions(-)
sound/pci/hda/Makefile +1 -2
index af78fb33a4fd..c5e6651efb49 100644
@@ -1,10 +1,10 @@
 snd-hda-intel-objs := hda_intel.o
-snd-hda-controller-objs := hda_controller.o
 snd-hda-tegra-objs := hda_tegra.o
 # for haswell power well
 snd-hda-intel-$(CONFIG_SND_HDA_I915) +=	hda_i915.o
 
 snd-hda-codec-y := hda_bind.o hda_codec.o hda_jack.o hda_auto_parser.o hda_sysfs.o
+snd-hda-codec-y += hda_controller.o
 snd-hda-codec-$(CONFIG_PROC_FS) += hda_proc.o
 snd-hda-codec-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o
 snd-hda-codec-$(CONFIG_SND_HDA_INPUT_BEEP) += hda_beep.o
@@ -27,7 +27,6 @@ snd-hda-codec-hdmi-objs :=	patch_hdmi.o hda_eld.o
 
 # common driver
 obj-$(CONFIG_SND_HDA) := snd-hda-codec.o
-obj-$(CONFIG_SND_HDA) += snd-hda-controller.o
 
 # codec drivers
 obj-$(CONFIG_SND_HDA_GENERIC) += snd-hda-codec-generic.o
sound/pci/hda/hda_controller.c +0 -3
index b4474e27631d..6b39f2e8c820 100644
@@ -1966,6 +1966,3 @@ int azx_init_stream(struct azx *chip)
 	return 0;
 }
 EXPORT_SYMBOL_GPL(azx_init_stream);
-
-MODULE_LICENSE("GPL");
-MODULE_DESCRIPTION("Common HDA driver functions");
Signature · 1 line
2.3.5
#6 lore raw

PATCH 6/21 ALSA: hda - Move send_cmd / get_response to hdac_bus_ops

In reply to Takashi Iwai

One less redirection.

---
 sound/pci/hda/hda_codec.c      | 22 ++--------------------
 sound/pci/hda/hda_codec.h      | 11 ++++++-----
 sound/pci/hda/hda_controller.c | 24 +++++++++++++++---------
 3 files changed, 23 insertions(+), 34 deletions(-)
sound/pci/hda/hda_codec.c +2 -20
index b86e2f449e56..7e3dcaba6365 100644
@@ -507,25 +507,6 @@ static int snd_hda_bus_dev_disconnect(struct snd_device *device)
 	return 0;
 }
 
-/* hdac_bus_ops translations */
-static int _hda_bus_command(struct hdac_bus *_bus, unsigned int cmd)
-{
-	struct hda_bus *bus = container_of(_bus, struct hda_bus, core);
-	return bus->ops.command(bus, cmd);
-}
-
-static int _hda_bus_get_response(struct hdac_bus *_bus, unsigned int addr,
-				 unsigned int *res)
-{
-	struct hda_bus *bus = container_of(_bus, struct hda_bus, core);
-	return bus->ops.get_response(bus, addr, res);
-}
-
-static const struct hdac_bus_ops bus_ops = {
-	.command = _hda_bus_command,
-	.get_response = _hda_bus_get_response,
-};
-
 /**
  * snd_hda_bus_new - create a HDA bus
  * @card: the card entry
@@ -534,6 +515,7 @@ static const struct hdac_bus_ops bus_ops = {
  * Returns 0 if successful, or a negative error code.
  */
 int snd_hda_bus_new(struct snd_card *card,
+		    const struct hdac_bus_ops *ops,
 		    struct hda_bus **busp)
 {
 	struct hda_bus *bus;
@@ -550,7 +532,7 @@ int snd_hda_bus_new(struct snd_card *card,
 	if (!bus)
 		return -ENOMEM;
 
-	err = snd_hdac_bus_init(&bus->core, card->dev, &bus_ops, NULL);
+	err = snd_hdac_bus_init(&bus->core, card->dev, ops, NULL);
 	if (err < 0) {
 		kfree(bus);
 		return err;
sound/pci/hda/hda_codec.h +6 -5
index fc4f76188a1d..b4261721d8f1 100644
@@ -42,10 +42,6 @@ struct hda_pcm_stream;
 
 /* bus operators */
 struct hda_bus_ops {
-	/* send a single command */
-	int (*command)(struct hda_bus *bus, unsigned int cmd);
-	/* get a response from the last command */
-	int (*get_response)(struct hda_bus *bus, unsigned int addr, unsigned int *res);
 	/* free the private data */
 	void (*private_free)(struct hda_bus *);
 	/* attach a PCM stream */
@@ -99,6 +95,9 @@ struct hda_bus {
 	int primary_dig_out_type;	/* primary digital out PCM type */
 };
 
+/* from hdac_bus to hda_bus */
+#define to_hda_bus(bus)		container_of(bus, struct hda_bus, core)
+
 /*
  * codec preset
  *
@@ -327,7 +326,9 @@ struct hda_codec {
 /*
  * constructors
  */
-int snd_hda_bus_new(struct snd_card *card, struct hda_bus **busp);
+int snd_hda_bus_new(struct snd_card *card,
+		    const struct hdac_bus_ops *ops,
+		    struct hda_bus **busp);
 int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card,
 		      unsigned int codec_addr, struct hda_codec **codecp);
 int snd_hda_codec_configure(struct hda_codec *codec);
sound/pci/hda/hda_controller.c +15 -9
index 6b39f2e8c820..666dee232e95 100644
@@ -1328,8 +1328,9 @@ static int azx_single_get_response(struct hda_bus *bus, unsigned int addr,
  */
 
 /* send a command */
-static int azx_send_cmd(struct hda_bus *bus, unsigned int val)
+static int azx_send_cmd(struct hdac_bus *_bus, unsigned int val)
 {
+	struct hda_bus *bus = to_hda_bus(_bus);
 	struct azx *chip = bus->private_data;
 
 	if (chip->disabled)
@@ -1342,9 +1343,10 @@ static int azx_send_cmd(struct hda_bus *bus, unsigned int val)
 }
 
 /* get a response */
-static int azx_get_response(struct hda_bus *bus, unsigned int addr,
+static int azx_get_response(struct hdac_bus *_bus, unsigned int addr,
 			    unsigned int *res)
 {
+	struct hda_bus *bus = to_hda_bus(_bus);
 	struct azx *chip = bus->private_data;
 	if (chip->disabled)
 		return 0;
@@ -1354,6 +1356,11 @@ static int azx_get_response(struct hda_bus *bus, unsigned int addr,
 		return azx_rirb_get_response(bus, addr, res);
 }
 
+static const struct hdac_bus_ops bus_core_ops = {
+	.command = azx_send_cmd,
+	.get_response = azx_get_response,
+};
+
 #ifdef CONFIG_SND_HDA_DSP_LOADER
 /*
  * DSP loading code (e.g. for CA0132)
@@ -1762,15 +1769,16 @@ static int probe_codec(struct azx *chip, int addr)
 {
 	unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) |
 		(AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID;
+	struct hdac_bus *bus = &chip->bus->core;
 	int err;
 	unsigned int res;
 
-	mutex_lock(&chip->bus->core.cmd_mutex);
+	mutex_lock(&bus->cmd_mutex);
 	chip->probing = 1;
-	azx_send_cmd(chip->bus, cmd);
-	err = azx_get_response(chip->bus, addr, &res);
+	azx_send_cmd(bus, cmd);
+	err = azx_get_response(bus, addr, &res);
 	chip->probing = 0;
-	mutex_unlock(&chip->bus->core.cmd_mutex);
+	mutex_unlock(&bus->cmd_mutex);
 	if (err < 0 || res == -1)
 		return -EIO;
 	dev_dbg(chip->card->dev, "codec #%d probed OK\n", addr);
@@ -1811,8 +1819,6 @@ static int get_jackpoll_interval(struct azx *chip)
 }
 
 static struct hda_bus_ops bus_ops = {
-	.command = azx_send_cmd,
-	.get_response = azx_get_response,
 	.attach_pcm = azx_attach_pcm_stream,
 	.bus_reset = azx_bus_reset,
 #ifdef CONFIG_SND_HDA_DSP_LOADER
@@ -1828,7 +1834,7 @@ int azx_bus_create(struct azx *chip, const char *model)
 	struct hda_bus *bus;
 	int err;
 
-	err = snd_hda_bus_new(chip->card, &bus);
+	err = snd_hda_bus_new(chip->card, &bus_core_ops, &bus);
 	if (err < 0)
 		return err;
 
Signature · 1 line
2.3.5
#7 lore raw

PATCH 7/21 ALSA: hda - Pass bus io_ops directly from the top-level driver

In reply to Takashi Iwai

One less redirection again. This also requires the change of the call order in the toplevel divers. Namely, the bus has to be created at first before other initializations since the memory allocation ops are called through bus object now.

---
 sound/pci/hda/hda_codec.c      |  3 ++-
 sound/pci/hda/hda_codec.h      |  1 +
 sound/pci/hda/hda_controller.c | 26 +++++++++++++-------------
 sound/pci/hda/hda_controller.h | 40 +++++++++++++++-------------------------
 sound/pci/hda/hda_intel.c      | 34 +++++++++++++++++++++-------------
 sound/pci/hda/hda_tegra.c      | 25 ++++++++++++++-----------
 6 files changed, 66 insertions(+), 63 deletions(-)
sound/pci/hda/hda_codec.c +2 -1
index 7e3dcaba6365..ddebe7541390 100644
@@ -516,6 +516,7 @@ static int snd_hda_bus_dev_disconnect(struct snd_device *device)
  */
 int snd_hda_bus_new(struct snd_card *card,
 		    const struct hdac_bus_ops *ops,
+		    const struct hdac_io_ops *io_ops,
 		    struct hda_bus **busp)
 {
 	struct hda_bus *bus;
@@ -532,7 +533,7 @@ int snd_hda_bus_new(struct snd_card *card,
 	if (!bus)
 		return -ENOMEM;
 
-	err = snd_hdac_bus_init(&bus->core, card->dev, ops, NULL);
+	err = snd_hdac_bus_init(&bus->core, card->dev, ops, io_ops);
 	if (err < 0) {
 		kfree(bus);
 		return err;
sound/pci/hda/hda_codec.h +1 -0
index b4261721d8f1..c8031360de90 100644
@@ -328,6 +328,7 @@ struct hda_codec {
  */
 int snd_hda_bus_new(struct snd_card *card,
 		    const struct hdac_bus_ops *ops,
+		    const struct hdac_io_ops *io_ops,
 		    struct hda_bus **busp);
 int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card,
 		      unsigned int codec_addr, struct hda_codec **codecp);
sound/pci/hda/hda_controller.c +13 -13
index 666dee232e95..aadce642aabc 100644
@@ -985,8 +985,8 @@ static int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec,
 static int azx_alloc_cmd_io(struct azx *chip)
 {
 	/* single page (at least 4096 bytes) must suffice for both ringbuffes */
-	return chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV,
-					  PAGE_SIZE, &chip->rb);
+	return chip->io_ops->dma_alloc_pages(azx_bus(chip), SNDRV_DMA_TYPE_DEV,
+					     PAGE_SIZE, &chip->rb);
 }
 
 static void azx_init_cmd_io(struct azx *chip)
@@ -1396,8 +1396,8 @@ static int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format,
 	azx_dev->locked = 1;
 	spin_unlock_irq(&chip->reg_lock);
 
-	err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV_SG,
-					 byte_size, bufp);
+	err = chip->io_ops->dma_alloc_pages(&bus->core, SNDRV_DMA_TYPE_DEV_SG,
+					    byte_size, bufp);
 	if (err < 0)
 		goto err_alloc;
 
@@ -1422,7 +1422,7 @@ static int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format,
 	return azx_dev->stream_tag;
 
  error:
-	chip->ops->dma_free_pages(chip, bufp);
+	chip->io_ops->dma_free_pages(&bus->core, bufp);
  err_alloc:
 	spin_lock_irq(&chip->reg_lock);
 	if (azx_dev->opened)
@@ -1464,7 +1464,7 @@ static void azx_load_dsp_cleanup(struct hda_bus *bus,
 	azx_dev->period_bytes = 0;
 	azx_dev->format_val = 0;
 
-	chip->ops->dma_free_pages(chip, dmab);
+	chip->io_ops->dma_free_pages(&bus->core, dmab);
 	dmab->area = NULL;
 
 	spin_lock_irq(&chip->reg_lock);
@@ -1483,14 +1483,14 @@ int azx_alloc_stream_pages(struct azx *chip)
 	for (i = 0; i < chip->num_streams; i++) {
 		dsp_lock_init(&chip->azx_dev[i]);
 		/* allocate memory for the BDL for each stream */
-		err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV,
+		err = chip->io_ops->dma_alloc_pages(azx_bus(chip), SNDRV_DMA_TYPE_DEV,
 						 BDL_SIZE,
 						 &chip->azx_dev[i].bdl);
 		if (err < 0)
 			return -ENOMEM;
 	}
 	/* allocate memory for the position buffer */
-	err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV,
+	err = chip->io_ops->dma_alloc_pages(azx_bus(chip), SNDRV_DMA_TYPE_DEV,
 					 chip->num_streams * 8, &chip->posbuf);
 	if (err < 0)
 		return -ENOMEM;
@@ -1509,13 +1509,13 @@ void azx_free_stream_pages(struct azx *chip)
 	if (chip->azx_dev) {
 		for (i = 0; i < chip->num_streams; i++)
 			if (chip->azx_dev[i].bdl.area)
-				chip->ops->dma_free_pages(
-					chip, &chip->azx_dev[i].bdl);
+				chip->io_ops->dma_free_pages(azx_bus(chip),
+							     &chip->azx_dev[i].bdl);
 	}
 	if (chip->rb.area)
-		chip->ops->dma_free_pages(chip, &chip->rb);
+		chip->io_ops->dma_free_pages(azx_bus(chip), &chip->rb);
 	if (chip->posbuf.area)
-		chip->ops->dma_free_pages(chip, &chip->posbuf);
+		chip->io_ops->dma_free_pages(azx_bus(chip), &chip->posbuf);
 }
 EXPORT_SYMBOL_GPL(azx_free_stream_pages);
 
@@ -1834,7 +1834,7 @@ int azx_bus_create(struct azx *chip, const char *model)
 	struct hda_bus *bus;
 	int err;
 
-	err = snd_hda_bus_new(chip->card, &bus_core_ops, &bus);
+	err = snd_hda_bus_new(chip->card, &bus_core_ops, chip->io_ops, &bus);
 	if (err < 0)
 		return err;
 
sound/pci/hda/hda_controller.h +15 -25
index 15a796c21b9d..d6b090daa7dc 100644
@@ -125,21 +125,8 @@ struct azx;
 
 /* Functions to read/write to hda registers. */
 struct hda_controller_ops {
-	/* Register Access */
-	void (*reg_writel)(u32 value, u32 __iomem *addr);
-	u32 (*reg_readl)(u32 __iomem *addr);
-	void (*reg_writew)(u16 value, u16 __iomem *addr);
-	u16 (*reg_readw)(u16 __iomem *addr);
-	void (*reg_writeb)(u8 value, u8 __iomem *addr);
-	u8 (*reg_readb)(u8 __iomem *addr);
 	/* Disable msi if supported, PCI only */
 	int (*disable_msi_reset_irq)(struct azx *);
-	/* Allocation ops */
-	int (*dma_alloc_pages)(struct azx *chip,
-			       int type,
-			       size_t size,
-			       struct snd_dma_buffer *buf);
-	void (*dma_free_pages)(struct azx *chip, struct snd_dma_buffer *buf);
 	int (*substream_alloc_pages)(struct azx *chip,
 				     struct snd_pcm_substream *substream,
 				     size_t size);
@@ -179,6 +166,7 @@ struct azx {
 
 	/* Register interaction. */
 	const struct hda_controller_ops *ops;
+	const struct hdac_io_ops *io_ops;
 
 	/* position adjustment callbacks */
 	azx_get_pos_callback_t get_position[2];
@@ -239,6 +227,8 @@ struct azx {
 #endif
 };
 
+#define azx_bus(chip)	(&(chip)->bus->core)
+
 #ifdef CONFIG_X86
 #define azx_snoop(chip)		((chip)->snoop)
 #else
@@ -250,30 +240,30 @@ struct azx {
  */
 
 #define azx_writel(chip, reg, value) \
-	((chip)->ops->reg_writel(value, (chip)->remap_addr + AZX_REG_##reg))
+	((chip)->io_ops->reg_writel(value, (chip)->remap_addr + AZX_REG_##reg))
 #define azx_readl(chip, reg) \
-	((chip)->ops->reg_readl((chip)->remap_addr + AZX_REG_##reg))
+	((chip)->io_ops->reg_readl((chip)->remap_addr + AZX_REG_##reg))
 #define azx_writew(chip, reg, value) \
-	((chip)->ops->reg_writew(value, (chip)->remap_addr + AZX_REG_##reg))
+	((chip)->io_ops->reg_writew(value, (chip)->remap_addr + AZX_REG_##reg))
 #define azx_readw(chip, reg) \
-	((chip)->ops->reg_readw((chip)->remap_addr + AZX_REG_##reg))
+	((chip)->io_ops->reg_readw((chip)->remap_addr + AZX_REG_##reg))
 #define azx_writeb(chip, reg, value) \
-	((chip)->ops->reg_writeb(value, (chip)->remap_addr + AZX_REG_##reg))
+	((chip)->io_ops->reg_writeb(value, (chip)->remap_addr + AZX_REG_##reg))
 #define azx_readb(chip, reg) \
-	((chip)->ops->reg_readb((chip)->remap_addr + AZX_REG_##reg))
+	((chip)->io_ops->reg_readb((chip)->remap_addr + AZX_REG_##reg))
 
 #define azx_sd_writel(chip, dev, reg, value) \
-	((chip)->ops->reg_writel(value, (dev)->sd_addr + AZX_REG_##reg))
+	((chip)->io_ops->reg_writel(value, (dev)->sd_addr + AZX_REG_##reg))
 #define azx_sd_readl(chip, dev, reg) \
-	((chip)->ops->reg_readl((dev)->sd_addr + AZX_REG_##reg))
+	((chip)->io_ops->reg_readl((dev)->sd_addr + AZX_REG_##reg))
 #define azx_sd_writew(chip, dev, reg, value) \
-	((chip)->ops->reg_writew(value, (dev)->sd_addr + AZX_REG_##reg))
+	((chip)->io_ops->reg_writew(value, (dev)->sd_addr + AZX_REG_##reg))
 #define azx_sd_readw(chip, dev, reg) \
-	((chip)->ops->reg_readw((dev)->sd_addr + AZX_REG_##reg))
+	((chip)->io_ops->reg_readw((dev)->sd_addr + AZX_REG_##reg))
 #define azx_sd_writeb(chip, dev, reg, value) \
-	((chip)->ops->reg_writeb(value, (dev)->sd_addr + AZX_REG_##reg))
+	((chip)->io_ops->reg_writeb(value, (dev)->sd_addr + AZX_REG_##reg))
 #define azx_sd_readb(chip, dev, reg) \
-	((chip)->ops->reg_readb((dev)->sd_addr + AZX_REG_##reg))
+	((chip)->io_ops->reg_readb((dev)->sd_addr + AZX_REG_##reg))
 
 #define azx_has_pm_runtime(chip) \
 	(!AZX_DCAPS_PM_RUNTIME || ((chip)->driver_caps & AZX_DCAPS_PM_RUNTIME))
sound/pci/hda/hda_intel.c +21 -13
index e1c210515581..7492d11fd8ff 100644
@@ -1365,9 +1365,11 @@ static void azx_probe_work(struct work_struct *work)
 /*
  * constructor
  */
+static const struct hdac_io_ops pci_hda_io_ops;
+static const struct hda_controller_ops pci_hda_ops;
+
 static int azx_create(struct snd_card *card, struct pci_dev *pci,
 		      int dev, unsigned int driver_caps,
-		      const struct hda_controller_ops *hda_ops,
 		      struct azx **rchip)
 {
 	static struct snd_device_ops ops = {
@@ -1394,7 +1396,8 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci,
 	mutex_init(&chip->open_mutex);
 	chip->card = card;
 	chip->pci = pci;
-	chip->ops = hda_ops;
+	chip->ops = &pci_hda_ops;
+	chip->io_ops = &pci_hda_io_ops;
 	chip->irq = -1;
 	chip->driver_caps = driver_caps;
 	chip->driver_type = driver_caps & 0xff;
@@ -1681,15 +1684,16 @@ static int disable_msi_reset_irq(struct azx *chip)
 }
 
 /* DMA page allocation helpers.  */
-static int dma_alloc_pages(struct azx *chip,
+static int dma_alloc_pages(struct hdac_bus *bus,
 			   int type,
 			   size_t size,
 			   struct snd_dma_buffer *buf)
 {
+	struct azx *chip = to_hda_bus(bus)->private_data;
 	int err;
 
 	err = snd_dma_alloc_pages(type,
-				  chip->card->dev,
+				  bus->dev,
 				  size, buf);
 	if (err < 0)
 		return err;
@@ -1697,8 +1701,10 @@ static int dma_alloc_pages(struct azx *chip,
 	return 0;
 }
 
-static void dma_free_pages(struct azx *chip, struct snd_dma_buffer *buf)
+static void dma_free_pages(struct hdac_bus *bus, struct snd_dma_buffer *buf)
 {
+	struct azx *chip = to_hda_bus(bus)->private_data;
+
 	mark_pages_wc(chip, buf, false);
 	snd_dma_free_pages(buf);
 }
@@ -1740,16 +1746,19 @@ static void pcm_mmap_prepare(struct snd_pcm_substream *substream,
 #endif
 }
 
-static const struct hda_controller_ops pci_hda_ops = {
+static const struct hdac_io_ops pci_hda_io_ops = {
 	.reg_writel = pci_azx_writel,
 	.reg_readl = pci_azx_readl,
 	.reg_writew = pci_azx_writew,
 	.reg_readw = pci_azx_readw,
 	.reg_writeb = pci_azx_writeb,
 	.reg_readb = pci_azx_readb,
-	.disable_msi_reset_irq = disable_msi_reset_irq,
 	.dma_alloc_pages = dma_alloc_pages,
 	.dma_free_pages = dma_free_pages,
+};
+
+static const struct hda_controller_ops pci_hda_ops = {
+	.disable_msi_reset_irq = disable_msi_reset_irq,
 	.substream_alloc_pages = substream_alloc_pages,
 	.substream_free_pages = substream_free_pages,
 	.pcm_mmap_prepare = pcm_mmap_prepare,
@@ -1780,8 +1789,7 @@ static int azx_probe(struct pci_dev *pci,
 		return err;
 	}
 
-	err = azx_create(card, pci, dev, pci_id->driver_data,
-			 &pci_hda_ops, &chip);
+	err = azx_create(card, pci, dev, pci_id->driver_data, &chip);
 	if (err < 0)
 		goto out_free;
 	card->private_data = chip;
@@ -1862,6 +1870,10 @@ static int azx_probe_continue(struct azx *chip)
 #endif
 	}
 
+	err = azx_bus_create(chip, model[dev]);
+	if (err < 0)
+		goto out_free;
+
 	err = azx_first_init(chip);
 	if (err < 0)
 		goto out_free;
@@ -1871,10 +1883,6 @@ static int azx_probe_continue(struct azx *chip)
 #endif
 
 	/* create codec instances */
-	err = azx_bus_create(chip, model[dev]);
-	if (err < 0)
-		goto out_free;
-
 	err = azx_probe_codecs(chip, azx_max_codecs[chip->driver_type]);
 	if (err < 0)
 		goto out_free;
sound/pci/hda/hda_tegra.c +14 -11
index 2e4fd5c56d3b..b150cb50961c 100644
@@ -87,13 +87,13 @@ MODULE_PARM_DESC(power_save,
 /*
  * DMA page allocation ops.
  */
-static int dma_alloc_pages(struct azx *chip, int type, size_t size,
+static int dma_alloc_pages(struct hdac_bus *bus, int type, size_t size,
 			   struct snd_dma_buffer *buf)
 {
-	return snd_dma_alloc_pages(type, chip->card->dev, size, buf);
+	return snd_dma_alloc_pages(type, bus->dev, size, buf);
 }
 
-static void dma_free_pages(struct azx *chip, struct snd_dma_buffer *buf)
+static void dma_free_pages(struct hdac_bus *bus, struct snd_dma_buffer *buf)
 {
 	snd_dma_free_pages(buf);
 }
@@ -173,7 +173,7 @@ static u8 hda_tegra_readb(u8 *addr)
 	return (v >> shift) & 0xff;
 }
 
-static const struct hda_controller_ops hda_tegra_ops = {
+static const struct hdac_io_ops hda_tegra_io_ops = {
 	.reg_writel = hda_tegra_writel,
 	.reg_readl = hda_tegra_readl,
 	.reg_writew = hda_tegra_writew,
@@ -182,6 +182,9 @@ static const struct hda_controller_ops hda_tegra_ops = {
 	.reg_readb = hda_tegra_readb,
 	.dma_alloc_pages = dma_alloc_pages,
 	.dma_free_pages = dma_free_pages,
+};
+
+static const struct hda_controller_ops hda_tegra_ops = {
 	.substream_alloc_pages = substream_alloc_pages,
 	.substream_free_pages = substream_free_pages,
 };
@@ -409,7 +412,6 @@ static int hda_tegra_first_init(struct azx *chip, struct platform_device *pdev)
  */
 static int hda_tegra_create(struct snd_card *card,
 			    unsigned int driver_caps,
-			    const struct hda_controller_ops *hda_ops,
 			    struct hda_tegra *hda)
 {
 	static struct snd_device_ops ops = {
@@ -423,7 +425,8 @@ static int hda_tegra_create(struct snd_card *card,
 	spin_lock_init(&chip->reg_lock);
 	mutex_init(&chip->open_mutex);
 	chip->card = card;
-	chip->ops = hda_ops;
+	chip->ops = &hda_tegra_ops;
+	chip->io_ops = &hda_tegra_io_ops;
 	chip->irq = -1;
 	chip->driver_caps = driver_caps;
 	chip->driver_type = driver_caps & 0xff;
@@ -471,7 +474,11 @@ static int hda_tegra_probe(struct platform_device *pdev)
 		return err;
 	}
 
-	err = hda_tegra_create(card, driver_flags, &hda_tegra_ops, hda);
+	err = azx_bus_create(chip, NULL);
+	if (err < 0)
+		goto out_free;
+
+	err = hda_tegra_create(card, driver_flags, hda);
 	if (err < 0)
 		goto out_free;
 	card->private_data = chip;
@@ -483,10 +490,6 @@ static int hda_tegra_probe(struct platform_device *pdev)
 		goto out_free;
 
 	/* create codec instances */
-	err = azx_bus_create(chip, NULL);
-	if (err < 0)
-		goto out_free;
-
 	err = azx_probe_codecs(chip, 0);
 	if (err < 0)
 		goto out_free;
Signature · 1 line
2.3.5
#8 lore raw

PATCH 8/21 ALSA: hda - Migrate hdac_stream into legacy driver

In reply to Takashi Iwai

Embed hdac_stream object into azx_dev, and use a few basic helper functions. The most of helper codes for hdac_stream aren't still used yet.

Also this commit disables the tracepoints temporarily due to build problems. It'll be enabled again later.

---
 sound/pci/hda/hda_controller.c | 415 ++++++++++++++++-------------------------
 sound/pci/hda/hda_controller.h |  61 ++----
 sound/pci/hda/hda_intel.c      |  80 ++++----
 sound/pci/hda/hda_tegra.c      |  14 +-
 4 files changed, 211 insertions(+), 359 deletions(-)
sound/pci/hda/hda_controller.c +156 -259
index aadce642aabc..0b85c88c75ac 100644
@@ -31,92 +31,15 @@
 #include <sound/initval.h>
 #include "hda_controller.h"
 
-#define CREATE_TRACE_POINTS
-#include "hda_intel_trace.h"
-
 /* DSP lock helpers */
-#ifdef CONFIG_SND_HDA_DSP_LOADER
-#define dsp_lock_init(dev)	mutex_init(&(dev)->dsp_mutex)
-#define dsp_lock(dev)		mutex_lock(&(dev)->dsp_mutex)
-#define dsp_unlock(dev)		mutex_unlock(&(dev)->dsp_mutex)
-#define dsp_is_locked(dev)	((dev)->locked)
-#else
-#define dsp_lock_init(dev)	do {} while (0)
-#define dsp_lock(dev)		do {} while (0)
-#define dsp_unlock(dev)		do {} while (0)
-#define dsp_is_locked(dev)	0
-#endif
+#define dsp_lock(dev)		snd_hdac_dsp_lock(azx_stream(dev))
+#define dsp_unlock(dev)		snd_hdac_dsp_unlock(azx_stream(dev))
+#define dsp_is_locked(dev)	snd_hdac_stream_is_locked(azx_stream(dev))
 
 /*
  * AZX stream operations.
  */
 
-/* start a stream */
-static void azx_stream_start(struct azx *chip, struct azx_dev *azx_dev)
-{
-	/*
-	 * Before stream start, initialize parameter
-	 */
-	azx_dev->insufficient = 1;
-
-	/* enable SIE */
-	azx_writel(chip, INTCTL,
-		   azx_readl(chip, INTCTL) | (1 << azx_dev->index));
-	/* set DMA start and interrupt mask */
-	azx_sd_writeb(chip, azx_dev, SD_CTL,
-		      azx_sd_readb(chip, azx_dev, SD_CTL) |
-		      SD_CTL_DMA_START | SD_INT_MASK);
-}
-
-/* stop DMA */
-static void azx_stream_clear(struct azx *chip, struct azx_dev *azx_dev)
-{
-	azx_sd_writeb(chip, azx_dev, SD_CTL,
-		      azx_sd_readb(chip, azx_dev, SD_CTL) &
-		      ~(SD_CTL_DMA_START | SD_INT_MASK));
-	azx_sd_writeb(chip, azx_dev, SD_STS, SD_INT_MASK); /* to be sure */
-}
-
-/* stop a stream */
-void azx_stream_stop(struct azx *chip, struct azx_dev *azx_dev)
-{
-	azx_stream_clear(chip, azx_dev);
-	/* disable SIE */
-	azx_writel(chip, INTCTL,
-		   azx_readl(chip, INTCTL) & ~(1 << azx_dev->index));
-}
-EXPORT_SYMBOL_GPL(azx_stream_stop);
-
-/* reset stream */
-static void azx_stream_reset(struct azx *chip, struct azx_dev *azx_dev)
-{
-	unsigned char val;
-	int timeout;
-
-	azx_stream_clear(chip, azx_dev);
-
-	azx_sd_writeb(chip, azx_dev, SD_CTL,
-		      azx_sd_readb(chip, azx_dev, SD_CTL) |
-		      SD_CTL_STREAM_RESET);
-	udelay(3);
-	timeout = 300;
-	while (!((val = azx_sd_readb(chip, azx_dev, SD_CTL)) &
-		 SD_CTL_STREAM_RESET) && --timeout)
-		;
-	val &= ~SD_CTL_STREAM_RESET;
-	azx_sd_writeb(chip, azx_dev, SD_CTL, val);
-	udelay(3);
-
-	timeout = 300;
-	/* waiting for hardware to report that the stream is out of reset */
-	while (((val = azx_sd_readb(chip, azx_dev, SD_CTL)) &
-		SD_CTL_STREAM_RESET) && --timeout)
-		;
-
-	/* reset first position - may not be synced with hw at this time */
-	*azx_dev->posbuf = 0;
-}
-
 /*
  * set up the SD for streaming
  */
@@ -124,31 +47,31 @@ static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev)
 {
 	unsigned int val;
 	/* make sure the run bit is zero for SD */
-	azx_stream_clear(chip, azx_dev);
+	snd_hdac_stream_clear(azx_stream(azx_dev));
 	/* program the stream_tag */
 	val = azx_sd_readl(chip, azx_dev, SD_CTL);
 	val = (val & ~SD_CTL_STREAM_TAG_MASK) |
-		(azx_dev->stream_tag << SD_CTL_STREAM_TAG_SHIFT);
+		(azx_dev->core.stream_tag << SD_CTL_STREAM_TAG_SHIFT);
 	if (!azx_snoop(chip))
 		val |= SD_CTL_TRAFFIC_PRIO;
 	azx_sd_writel(chip, azx_dev, SD_CTL, val);
 
 	/* program the length of samples in cyclic buffer */
-	azx_sd_writel(chip, azx_dev, SD_CBL, azx_dev->bufsize);
+	azx_sd_writel(chip, azx_dev, SD_CBL, azx_dev->core.bufsize);
 
 	/* program the stream format */
 	/* this value needs to be the same as the one programmed */
-	azx_sd_writew(chip, azx_dev, SD_FORMAT, azx_dev->format_val);
+	azx_sd_writew(chip, azx_dev, SD_FORMAT, azx_dev->core.format_val);
 
 	/* program the stream LVI (last valid index) of the BDL */
-	azx_sd_writew(chip, azx_dev, SD_LVI, azx_dev->frags - 1);
+	azx_sd_writew(chip, azx_dev, SD_LVI, azx_dev->core.frags - 1);
 
 	/* program the BDL address */
 	/* lower BDL address */
-	azx_sd_writel(chip, azx_dev, SD_BDLPL, (u32)azx_dev->bdl.addr);
+	azx_sd_writel(chip, azx_dev, SD_BDLPL, (u32)azx_dev->core.bdl.addr);
 	/* upper BDL address */
 	azx_sd_writel(chip, azx_dev, SD_BDLPU,
-		      upper_32_bits(azx_dev->bdl.addr));
+		      upper_32_bits(azx_dev->core.bdl.addr));
 
 	/* enable the position buffer */
 	if (chip->get_position[0] != azx_get_pos_lpib ||
@@ -169,54 +92,24 @@ static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev)
 static inline struct azx_dev *
 azx_assign_device(struct azx *chip, struct snd_pcm_substream *substream)
 {
-	int dev, i, nums;
-	struct azx_dev *res = NULL;
-	/* make a non-zero unique key for the substream */
-	int key = (substream->pcm->device << 16) | (substream->number << 2) |
-		(substream->stream + 1);
-
-	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
-		dev = chip->playback_index_offset;
-		nums = chip->playback_streams;
-	} else {
-		dev = chip->capture_index_offset;
-		nums = chip->capture_streams;
-	}
-	for (i = 0; i < nums; i++, dev++) {
-		struct azx_dev *azx_dev = &chip->azx_dev[dev];
-		dsp_lock(azx_dev);
-		if (!azx_dev->opened && !dsp_is_locked(azx_dev)) {
-			if (azx_dev->assigned_key == key) {
-				azx_dev->opened = 1;
-				azx_dev->assigned_key = key;
-				dsp_unlock(azx_dev);
-				return azx_dev;
-			}
-			if (!res ||
-			    (chip->driver_caps & AZX_DCAPS_REVERSE_ASSIGN))
-				res = azx_dev;
-		}
-		dsp_unlock(azx_dev);
-	}
-	if (res) {
-		dsp_lock(res);
-		res->opened = 1;
-		res->assigned_key = key;
-		dsp_unlock(res);
-	}
-	return res;
+	struct hdac_stream *s;
+
+	s = snd_hdac_stream_assign(azx_bus(chip), substream);
+	if (!s)
+		return NULL;
+	return stream_to_azx_dev(s);
 }
 
 /* release the assigned stream */
 static inline void azx_release_device(struct azx_dev *azx_dev)
 {
-	azx_dev->opened = 0;
+	snd_hdac_stream_release(azx_stream(azx_dev));
 }
 
 static cycle_t azx_cc_read(const struct cyclecounter *cc)
 {
-	struct azx_dev *azx_dev = container_of(cc, struct azx_dev, azx_cc);
-	struct snd_pcm_substream *substream = azx_dev->substream;
+	struct azx_dev *azx_dev = container_of(cc, struct azx_dev, core.cc);
+	struct snd_pcm_substream *substream = azx_dev->core.substream;
 	struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
 	struct azx *chip = apcm->chip;
 
@@ -227,8 +120,8 @@ static void azx_timecounter_init(struct snd_pcm_substream *substream,
 				bool force, cycle_t last)
 {
 	struct azx_dev *azx_dev = get_azx_dev(substream);
-	struct timecounter *tc = &azx_dev->azx_tc;
-	struct cyclecounter *cc = &azx_dev->azx_cc;
+	struct timecounter *tc = &azx_dev->core.tc;
+	struct cyclecounter *cc = &azx_dev->core.cc;
 	u64 nsec;
 
 	cc->read = azx_cc_read;
@@ -298,7 +191,7 @@ static int setup_bdle(struct azx *chip,
 		dma_addr_t addr;
 		int chunk;
 
-		if (azx_dev->frags >= AZX_MAX_BDL_ENTRIES)
+		if (azx_dev->core.frags >= AZX_MAX_BDL_ENTRIES)
 			return -EINVAL;
 
 		addr = snd_sgbuf_get_addr(dmab, ofs);
@@ -320,7 +213,7 @@ static int setup_bdle(struct azx *chip,
 		size -= chunk;
 		bdl[3] = (size || !with_ioc) ? 0 : cpu_to_le32(0x01);
 		bdl += 4;
-		azx_dev->frags++;
+		azx_dev->core.frags++;
 		ofs += chunk;
 	}
 	*bdlp = bdl;
@@ -342,17 +235,17 @@ static int azx_setup_periods(struct azx *chip,
 	azx_sd_writel(chip, azx_dev, SD_BDLPL, 0);
 	azx_sd_writel(chip, azx_dev, SD_BDLPU, 0);
 
-	period_bytes = azx_dev->period_bytes;
-	periods = azx_dev->bufsize / period_bytes;
+	period_bytes = azx_dev->core.period_bytes;
+	periods = azx_dev->core.bufsize / period_bytes;
 
 	/* program the initial BDL entries */
-	bdl = (u32 *)azx_dev->bdl.area;
+	bdl = (u32 *)azx_dev->core.bdl.area;
 	ofs = 0;
-	azx_dev->frags = 0;
+	azx_dev->core.frags = 0;
 
 	if (chip->bdl_pos_adj)
 		pos_adj = chip->bdl_pos_adj[chip->dev_index];
-	if (!azx_dev->no_period_wakeup && pos_adj > 0) {
+	if (!azx_dev->core.no_period_wakeup && pos_adj > 0) {
 		struct snd_pcm_runtime *runtime = substream->runtime;
 		int pos_align = pos_adj;
 		pos_adj = (pos_adj * runtime->rate + 47999) / 48000;
@@ -385,7 +278,7 @@ static int azx_setup_periods(struct azx *chip,
 			ofs = setup_bdle(chip, snd_pcm_get_dma_buf(substream),
 					 azx_dev, &bdl, ofs,
 					 period_bytes,
-					 !azx_dev->no_period_wakeup);
+					 !azx_dev->core.no_period_wakeup);
 		if (ofs < 0)
 			goto error;
 	}
@@ -393,7 +286,7 @@ static int azx_setup_periods(struct azx *chip,
 
  error:
 	dev_err(chip->card->dev, "Too many BDL entries: buffer=%d, period=%d\n",
-		azx_dev->bufsize, period_bytes);
+		azx_dev->core.bufsize, period_bytes);
 	return -EINVAL;
 }
 
@@ -411,8 +304,8 @@ static int azx_pcm_close(struct snd_pcm_substream *substream)
 
 	mutex_lock(&chip->open_mutex);
 	spin_lock_irqsave(&chip->reg_lock, flags);
-	azx_dev->substream = NULL;
-	azx_dev->running = 0;
+	azx_dev->core.substream = NULL;
+	azx_dev->core.running = 0;
 	spin_unlock_irqrestore(&chip->reg_lock, flags);
 	azx_release_device(azx_dev);
 	if (hinfo->ops.close)
@@ -457,9 +350,9 @@ static int azx_pcm_hw_free(struct snd_pcm_substream *substream)
 		azx_sd_writel(chip, azx_dev, SD_BDLPL, 0);
 		azx_sd_writel(chip, azx_dev, SD_BDLPU, 0);
 		azx_sd_writel(chip, azx_dev, SD_CTL, 0);
-		azx_dev->bufsize = 0;
-		azx_dev->period_bytes = 0;
-		azx_dev->format_val = 0;
+		azx_dev->core.bufsize = 0;
+		azx_dev->core.period_bytes = 0;
+		azx_dev->core.format_val = 0;
 	}
 
 	snd_hda_codec_cleanup(apcm->codec, hinfo, substream);
@@ -489,7 +382,7 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
 		goto unlock;
 	}
 
-	azx_stream_reset(chip, azx_dev);
+	snd_hdac_stream_reset(azx_stream(azx_dev));
 	format_val = snd_hda_calc_stream_format(apcm->codec,
 						runtime->rate,
 						runtime->channels,
@@ -510,14 +403,14 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
 	dev_dbg(chip->card->dev, "azx_pcm_prepare: bufsize=0x%x, format=0x%x\n",
 		bufsize, format_val);
 
-	if (bufsize != azx_dev->bufsize ||
-	    period_bytes != azx_dev->period_bytes ||
-	    format_val != azx_dev->format_val ||
-	    runtime->no_period_wakeup != azx_dev->no_period_wakeup) {
-		azx_dev->bufsize = bufsize;
-		azx_dev->period_bytes = period_bytes;
-		azx_dev->format_val = format_val;
-		azx_dev->no_period_wakeup = runtime->no_period_wakeup;
+	if (bufsize != azx_dev->core.bufsize ||
+	    period_bytes != azx_dev->core.period_bytes ||
+	    format_val != azx_dev->core.format_val ||
+	    runtime->no_period_wakeup != azx_dev->core.no_period_wakeup) {
+		azx_dev->core.bufsize = bufsize;
+		azx_dev->core.period_bytes = period_bytes;
+		azx_dev->core.format_val = format_val;
+		azx_dev->core.no_period_wakeup = runtime->no_period_wakeup;
 		err = azx_setup_periods(chip, substream, azx_dev);
 		if (err < 0)
 			goto unlock;
@@ -528,27 +421,27 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
 	 * 64 frames
 	 */
 	if (runtime->period_size > 64)
-		azx_dev->delay_negative_threshold = -frames_to_bytes(runtime, 64);
+		azx_dev->core.delay_negative_threshold = -frames_to_bytes(runtime, 64);
 	else
-		azx_dev->delay_negative_threshold = 0;
+		azx_dev->core.delay_negative_threshold = 0;
 
 	/* wallclk has 24Mhz clock source */
-	azx_dev->period_wallclk = (((runtime->period_size * 24000) /
+	azx_dev->core.period_wallclk = (((runtime->period_size * 24000) /
 						runtime->rate) * 1000);
 	azx_setup_controller(chip, azx_dev);
 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
-		azx_dev->fifo_size =
+		azx_dev->core.fifo_size =
 			azx_sd_readw(chip, azx_dev, SD_FIFOSIZE) + 1;
 	else
-		azx_dev->fifo_size = 0;
+		azx_dev->core.fifo_size = 0;
 
-	stream_tag = azx_dev->stream_tag;
+	stream_tag = azx_dev->core.stream_tag;
 	/* CA-IBG chips need the playback stream starting from 1 */
 	if ((chip->driver_caps & AZX_DCAPS_CTX_WORKAROUND) &&
 	    stream_tag > chip->capture_streams)
 		stream_tag -= chip->capture_streams;
 	err = snd_hda_codec_prepare(apcm->codec, hinfo, stream_tag,
-				     azx_dev->format_val, substream);
+				     azx_dev->core.format_val, substream);
 
  unlock:
 	if (!err)
@@ -567,7 +460,6 @@ static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
 	int nwait, timeout;
 
 	azx_dev = get_azx_dev(substream);
-	trace_azx_pcm_trigger(chip, azx_dev, cmd);
 
 	if (dsp_is_locked(azx_dev) || !azx_dev->prepared)
 		return -EPIPE;
@@ -592,7 +484,7 @@ static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
 		if (s->pcm->card != substream->pcm->card)
 			continue;
 		azx_dev = get_azx_dev(s);
-		sbits |= 1 << azx_dev->index;
+		sbits |= 1 << azx_dev->core.index;
 		nsync++;
 		snd_pcm_trigger_done(s, substream);
 	}
@@ -611,15 +503,11 @@ static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
 			continue;
 		azx_dev = get_azx_dev(s);
 		if (start) {
-			azx_dev->start_wallclk = azx_readl(chip, WALLCLK);
-			if (!rstart)
-				azx_dev->start_wallclk -=
-						azx_dev->period_wallclk;
-			azx_stream_start(chip, azx_dev);
+			azx_dev->insufficient = 1;
+			snd_hdac_stream_start(azx_stream(azx_dev), true);
 		} else {
-			azx_stream_stop(chip, azx_dev);
+			snd_hdac_stream_stop(azx_stream(azx_dev));
 		}
-		azx_dev->running = start;
 	}
 	spin_unlock(&chip->reg_lock);
 	if (start) {
@@ -672,7 +560,7 @@ static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
 
 			/* same start cycle for master and group */
 			azx_dev = get_azx_dev(substream);
-			cycle_last = azx_dev->azx_tc.cycle_last;
+			cycle_last = azx_dev->core.tc.cycle_last;
 
 			snd_pcm_group_for_each_entry(s, substream) {
 				if (s->pcm->card != substream->pcm->card)
@@ -687,20 +575,20 @@ static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
 
 unsigned int azx_get_pos_lpib(struct azx *chip, struct azx_dev *azx_dev)
 {
-	return azx_sd_readl(chip, azx_dev, SD_LPIB);
+	return snd_hdac_stream_get_pos_lpib(azx_stream(azx_dev));
 }
 EXPORT_SYMBOL_GPL(azx_get_pos_lpib);
 
 unsigned int azx_get_pos_posbuf(struct azx *chip, struct azx_dev *azx_dev)
 {
-	return le32_to_cpu(*azx_dev->posbuf);
+	return snd_hdac_stream_get_pos_posbuf(azx_stream(azx_dev));
 }
 EXPORT_SYMBOL_GPL(azx_get_pos_posbuf);
 
 unsigned int azx_get_position(struct azx *chip,
 			      struct azx_dev *azx_dev)
 {
-	struct snd_pcm_substream *substream = azx_dev->substream;
+	struct snd_pcm_substream *substream = azx_dev->core.substream;
 	unsigned int pos;
 	int stream = substream->stream;
 	int delay = 0;
@@ -710,7 +598,7 @@ unsigned int azx_get_position(struct azx *chip,
 	else /* use the position buffer as default */
 		pos = azx_get_pos_posbuf(chip, azx_dev);
 
-	if (pos >= azx_dev->bufsize)
+	if (pos >= azx_dev->core.bufsize)
 		pos = 0;
 
 	if (substream->runtime) {
@@ -725,7 +613,6 @@ unsigned int azx_get_position(struct azx *chip,
 		substream->runtime->delay = delay;
 	}
 
-	trace_azx_get_position(chip, azx_dev, pos, delay);
 	return pos;
 }
 EXPORT_SYMBOL_GPL(azx_get_position);
@@ -752,7 +639,7 @@ static int azx_get_time_info(struct snd_pcm_substream *substream,
 
 		snd_pcm_gettime(substream->runtime, system_ts);
 
-		nsec = timecounter_read(&azx_dev->azx_tc);
+		nsec = timecounter_read(&azx_dev->core.tc);
 		nsec = div_u64(nsec, 3); /* can be optimized */
 		if (audio_tstamp_config->report_delay)
 			nsec = azx_adjust_codec_delay(substream, nsec);
@@ -875,8 +762,8 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
 	}
 
 	spin_lock_irqsave(&chip->reg_lock, flags);
-	azx_dev->substream = substream;
-	azx_dev->running = 0;
+	azx_dev->core.substream = substream;
+	azx_dev->core.running = 0;
 	spin_unlock_irqrestore(&chip->reg_lock, flags);
 
 	runtime->private_data = azx_dev;
@@ -1370,7 +1257,14 @@ static const struct hdac_bus_ops bus_core_ops = {
 static struct azx_dev *
 azx_get_dsp_loader_dev(struct azx *chip)
 {
-	return &chip->azx_dev[chip->playback_index_offset];
+	struct hdac_bus *bus = azx_bus(chip);
+	struct hdac_stream *s;
+
+	list_for_each_entry(s, &bus->stream_list, list)
+		if (s->index == chip->playback_index_offset)
+			return stream_to_azx_dev(s);
+
+	return NULL;
 }
 
 static int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format,
@@ -1386,14 +1280,14 @@ static int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format,
 
 	dsp_lock(azx_dev);
 	spin_lock_irq(&chip->reg_lock);
-	if (azx_dev->running || azx_dev->locked) {
+	if (azx_dev->core.running || azx_dev->core.locked) {
 		spin_unlock_irq(&chip->reg_lock);
 		err = -EBUSY;
 		goto unlock;
 	}
 	azx_dev->prepared = 0;
 	chip->saved_azx_dev = *azx_dev;
-	azx_dev->locked = 1;
+	azx_dev->core.locked = 1;
 	spin_unlock_irq(&chip->reg_lock);
 
 	err = chip->io_ops->dma_alloc_pages(&bus->core, SNDRV_DMA_TYPE_DEV_SG,
@@ -1401,33 +1295,33 @@ static int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format,
 	if (err < 0)
 		goto err_alloc;
 
-	azx_dev->bufsize = byte_size;
-	azx_dev->period_bytes = byte_size;
-	azx_dev->format_val = format;
+	azx_dev->core.bufsize = byte_size;
+	azx_dev->core.period_bytes = byte_size;
+	azx_dev->core.format_val = format;
 
-	azx_stream_reset(chip, azx_dev);
+	snd_hdac_stream_reset(azx_stream(azx_dev));
 
 	/* reset BDL address */
 	azx_sd_writel(chip, azx_dev, SD_BDLPL, 0);
 	azx_sd_writel(chip, azx_dev, SD_BDLPU, 0);
 
-	azx_dev->frags = 0;
-	bdl = (u32 *)azx_dev->bdl.area;
+	azx_dev->core.frags = 0;
+	bdl = (u32 *)azx_dev->core.bdl.area;
 	err = setup_bdle(chip, bufp, azx_dev, &bdl, 0, byte_size, 0);
 	if (err < 0)
 		goto error;
 
 	azx_setup_controller(chip, azx_dev);
 	dsp_unlock(azx_dev);
-	return azx_dev->stream_tag;
+	return azx_dev->core.stream_tag;
 
  error:
 	chip->io_ops->dma_free_pages(&bus->core, bufp);
  err_alloc:
 	spin_lock_irq(&chip->reg_lock);
-	if (azx_dev->opened)
+	if (azx_dev->core.opened)
 		*azx_dev = chip->saved_azx_dev;
-	azx_dev->locked = 0;
+	azx_dev->core.locked = 0;
 	spin_unlock_irq(&chip->reg_lock);
  unlock:
 	dsp_unlock(azx_dev);
@@ -1440,10 +1334,9 @@ static void azx_load_dsp_trigger(struct hda_bus *bus, bool start)
 	struct azx_dev *azx_dev = azx_get_dsp_loader_dev(chip);
 
 	if (start)
-		azx_stream_start(chip, azx_dev);
+		snd_hdac_stream_start(azx_stream(azx_dev), false);
 	else
-		azx_stream_stop(chip, azx_dev);
-	azx_dev->running = start;
+		snd_hdac_stream_stop(azx_stream(azx_dev));
 }
 
 static void azx_load_dsp_cleanup(struct hda_bus *bus,
@@ -1452,7 +1345,7 @@ static void azx_load_dsp_cleanup(struct hda_bus *bus,
 	struct azx *chip = bus->private_data;
 	struct azx_dev *azx_dev = azx_get_dsp_loader_dev(chip);
 
-	if (!dmab->area || !azx_dev->locked)
+	if (!dmab->area || !azx_dev->core.locked)
 		return;
 
 	dsp_lock(azx_dev);
@@ -1460,17 +1353,17 @@ static void azx_load_dsp_cleanup(struct hda_bus *bus,
 	azx_sd_writel(chip, azx_dev, SD_BDLPL, 0);
 	azx_sd_writel(chip, azx_dev, SD_BDLPU, 0);
 	azx_sd_writel(chip, azx_dev, SD_CTL, 0);
-	azx_dev->bufsize = 0;
-	azx_dev->period_bytes = 0;
-	azx_dev->format_val = 0;
+	azx_dev->core.bufsize = 0;
+	azx_dev->core.period_bytes = 0;
+	azx_dev->core.format_val = 0;
 
 	chip->io_ops->dma_free_pages(&bus->core, dmab);
 	dmab->area = NULL;
 
 	spin_lock_irq(&chip->reg_lock);
-	if (azx_dev->opened)
+	if (azx_dev->core.opened)
 		*azx_dev = chip->saved_azx_dev;
-	azx_dev->locked = 0;
+	azx_dev->core.locked = 0;
 	spin_unlock_irq(&chip->reg_lock);
 	dsp_unlock(azx_dev);
 }
@@ -1478,17 +1371,18 @@ static void azx_load_dsp_cleanup(struct hda_bus *bus,
 
 int azx_alloc_stream_pages(struct azx *chip)
 {
-	int i, err;
+	struct hdac_bus *bus = azx_bus(chip);
+	struct hdac_stream *s;
+	int err;
 
-	for (i = 0; i < chip->num_streams; i++) {
-		dsp_lock_init(&chip->azx_dev[i]);
+	list_for_each_entry(s, &bus->stream_list, list) {
 		/* allocate memory for the BDL for each stream */
 		err = chip->io_ops->dma_alloc_pages(azx_bus(chip), SNDRV_DMA_TYPE_DEV,
-						 BDL_SIZE,
-						 &chip->azx_dev[i].bdl);
+						 BDL_SIZE, &s->bdl);
 		if (err < 0)
 			return -ENOMEM;
 	}
+
 	/* allocate memory for the position buffer */
 	err = chip->io_ops->dma_alloc_pages(azx_bus(chip), SNDRV_DMA_TYPE_DEV,
 					 chip->num_streams * 8, &chip->posbuf);
@@ -1505,13 +1399,15 @@ EXPORT_SYMBOL_GPL(azx_alloc_stream_pages);
 
 void azx_free_stream_pages(struct azx *chip)
 {
-	int i;
-	if (chip->azx_dev) {
-		for (i = 0; i < chip->num_streams; i++)
-			if (chip->azx_dev[i].bdl.area)
-				chip->io_ops->dma_free_pages(azx_bus(chip),
-							     &chip->azx_dev[i].bdl);
+	struct hdac_bus *bus = azx_bus(chip);
+	struct hdac_stream *s, *next;
+
+	list_for_each_entry_safe(s, next, &bus->stream_list, list) {
+		if (s->bdl.area)
+			chip->io_ops->dma_free_pages(azx_bus(chip), &s->bdl);
+		kfree(s);
 	}
+
 	if (chip->rb.area)
 		chip->io_ops->dma_free_pages(azx_bus(chip), &chip->rb);
 	if (chip->posbuf.area)
@@ -1607,15 +1503,12 @@ static void azx_int_enable(struct azx *chip)
 /* disable interrupts */
 static void azx_int_disable(struct azx *chip)
 {
-	int i;
+	struct hdac_bus *bus = azx_bus(chip);
+	struct hdac_stream *s;
 
 	/* disable interrupts in stream descriptor */
-	for (i = 0; i < chip->num_streams; i++) {
-		struct azx_dev *azx_dev = &chip->azx_dev[i];
-		azx_sd_writeb(chip, azx_dev, SD_CTL,
-			      azx_sd_readb(chip, azx_dev, SD_CTL) &
-					~SD_INT_MASK);
-	}
+	list_for_each_entry(s, &bus->stream_list, list)
+		snd_hdac_stream_updateb(s, SD_CTL, SD_INT_MASK, 0);
 
 	/* disable SIE for all streams */
 	azx_writeb(chip, INTCTL, 0);
@@ -1628,13 +1521,12 @@ static void azx_int_disable(struct azx *chip)
 /* clear interrupts */
 static void azx_int_clear(struct azx *chip)
 {
-	int i;
+	struct hdac_bus *bus = azx_bus(chip);
+	struct hdac_stream *s;
 
 	/* clear stream status */
-	for (i = 0; i < chip->num_streams; i++) {
-		struct azx_dev *azx_dev = &chip->azx_dev[i];
-		azx_sd_writeb(chip, azx_dev, SD_STS, SD_INT_MASK);
-	}
+	list_for_each_entry(s, &bus->stream_list, list)
+		snd_hdac_stream_writeb(s, SD_STS, SD_INT_MASK);
 
 	/* clear STATESTS */
 	azx_writew(chip, STATESTS, STATESTS_INT_MASK);
@@ -1673,6 +1565,16 @@ void azx_init_chip(struct azx *chip, bool full_reset)
 }
 EXPORT_SYMBOL_GPL(azx_init_chip);
 
+void azx_stop_all_streams(struct azx *chip)
+{
+	struct hdac_bus *bus = azx_bus(chip);
+	struct hdac_stream *s;
+
+	list_for_each_entry(s, &bus->stream_list, list)
+		snd_hdac_stream_stop(s);
+}
+EXPORT_SYMBOL_GPL(azx_stop_all_streams);
+
 void azx_stop_chip(struct azx *chip)
 {
 	if (!chip->initialized)
@@ -1696,13 +1598,26 @@ EXPORT_SYMBOL_GPL(azx_stop_chip);
 /*
  * interrupt handler
  */
+static void stream_update(struct hdac_bus *bus, struct hdac_stream *s)
+{
+	struct hda_bus *hbus = container_of(bus, struct hda_bus, core);
+	struct azx *chip = hbus->private_data;
+	struct azx_dev *azx_dev = stream_to_azx_dev(s);
+
+	/* check whether this IRQ is really acceptable */
+	if (!chip->ops->position_check ||
+	    chip->ops->position_check(chip, azx_dev)) {
+		spin_unlock(&chip->reg_lock);
+		snd_pcm_period_elapsed(azx_dev->core.substream);
+		spin_lock(&chip->reg_lock);
+	}
+}
+
 irqreturn_t azx_interrupt(int irq, void *dev_id)
 {
 	struct azx *chip = dev_id;
-	struct azx_dev *azx_dev;
+	struct hdac_bus *bus = azx_bus(chip);
 	u32 status;
-	u8 sd_status;
-	int i;
 
 #ifdef CONFIG_PM
 	if (azx_has_pm_runtime(chip))
@@ -1723,23 +1638,7 @@ irqreturn_t azx_interrupt(int irq, void *dev_id)
 		return IRQ_NONE;
 	}
 
-	for (i = 0; i < chip->num_streams; i++) {
-		azx_dev = &chip->azx_dev[i];
-		if (status & azx_dev->sd_int_sta_mask) {
-			sd_status = azx_sd_readb(chip, azx_dev, SD_STS);
-			azx_sd_writeb(chip, azx_dev, SD_STS, SD_INT_MASK);
-			if (!azx_dev->substream || !azx_dev->running ||
-			    !(sd_status & SD_INT_COMPLETE))
-				continue;
-			/* check whether this IRQ is really acceptable */
-			if (!chip->ops->position_check ||
-			    chip->ops->position_check(chip, azx_dev)) {
-				spin_unlock(&chip->reg_lock);
-				snd_pcm_period_elapsed(azx_dev->substream);
-				spin_lock(&chip->reg_lock);
-			}
-		}
-	}
+	snd_hdac_bus_handle_stream_irq(bus, status, stream_update);
 
 	/* clear rirb int */
 	status = azx_readb(chip, RIRBSTS);
@@ -1769,7 +1668,7 @@ static int probe_codec(struct azx *chip, int addr)
 {
 	unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) |
 		(AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID;
-	struct hdac_bus *bus = &chip->bus->core;
+	struct hdac_bus *bus = azx_bus(chip);
 	int err;
 	unsigned int res;
 
@@ -1927,33 +1826,32 @@ int azx_codec_configure(struct azx *chip)
 }
 EXPORT_SYMBOL_GPL(azx_codec_configure);
 
-
-static bool is_input_stream(struct azx *chip, unsigned char index)
+static int stream_direction(struct azx *chip, unsigned char index)
 {
-	return (index >= chip->capture_index_offset &&
-		index < chip->capture_index_offset + chip->capture_streams);
+	if (index >= chip->capture_index_offset &&
+	    index < chip->capture_index_offset + chip->capture_streams)
+		return SNDRV_PCM_STREAM_CAPTURE;
+	return SNDRV_PCM_STREAM_PLAYBACK;
 }
 
 /* initialize SD streams */
 int azx_init_stream(struct azx *chip)
 {
 	int i;
-	int in_stream_tag = 0;
-	int out_stream_tag = 0;
+	int stream_tags[2] = { 0, 0 };
 
 	/* initialize each stream (aka device)
 	 * assign the starting bdl address to each stream (device)
 	 * and initialize
 	 */
 	for (i = 0; i < chip->num_streams; i++) {
-		struct azx_dev *azx_dev = &chip->azx_dev[i];
-		azx_dev->posbuf = (u32 __iomem *)(chip->posbuf.area + i * 8);
-		/* offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
-		azx_dev->sd_addr = chip->remap_addr + (0x20 * i + 0x80);
-		/* int mask: SDI0=0x01, SDI1=0x02, ... SDO3=0x80 */
-		azx_dev->sd_int_sta_mask = 1 << i;
-		azx_dev->index = i;
+		struct azx_dev *azx_dev = kzalloc(sizeof(*azx_dev), GFP_KERNEL);
+		int dir, tag;
+
+		if (!azx_dev)
+			return -ENOMEM;
 
+		dir = stream_direction(chip, i);
 		/* stream tag must be unique throughout
 		 * the stream direction group,
 		 * valid values 1...15
@@ -1961,12 +1859,11 @@ int azx_init_stream(struct azx *chip)
 		 * AZX_DCAPS_SEPARATE_STREAM_TAG is used
 		 */
 		if (chip->driver_caps & AZX_DCAPS_SEPARATE_STREAM_TAG)
-			azx_dev->stream_tag =
-				is_input_stream(chip, i) ?
-				++in_stream_tag :
-				++out_stream_tag;
+			tag = ++stream_tags[dir];
 		else
-			azx_dev->stream_tag = i + 1;
+			tag = i + 1;
+		snd_hdac_stream_init(azx_bus(chip), azx_stream(azx_dev),
+				     i, dir, tag);
 	}
 
 	return 0;
sound/pci/hda/hda_controller.h +12 -49

100 lines not on this page · raw message

sound/pci/hda/hda_intel.c +39 -41

203 lines not on this page · raw message

sound/pci/hda/hda_tegra.c +4 -10
index b150cb50961c..e25e0df7f067 100644
@@ -104,9 +104,9 @@ static int substream_alloc_pages(struct azx *chip,
 {
 	struct azx_dev *azx_dev = get_azx_dev(substream);
 
-	azx_dev->bufsize = 0;
-	azx_dev->period_bytes = 0;
-	azx_dev->format_val = 0;
+	azx_dev->core.bufsize = 0;
+	azx_dev->core.period_bytes = 0;
+	azx_dev->core.format_val = 0;
 	return snd_pcm_lib_malloc_pages(substream, size);
 }
 
@@ -290,12 +290,10 @@ static const struct dev_pm_ops hda_tegra_pm = {
  */
 static int hda_tegra_dev_free(struct snd_device *device)
 {
-	int i;
 	struct azx *chip = device->device_data;
 
 	if (chip->initialized) {
-		for (i = 0; i < chip->num_streams; i++)
-			azx_stream_stop(chip, &chip->azx_dev[i]);
+		azx_stop_all_streams(chip);
 		azx_stop_chip(chip);
 	}
 
@@ -377,10 +375,6 @@ static int hda_tegra_first_init(struct azx *chip, struct platform_device *pdev)
 	chip->capture_index_offset = 0;
 	chip->playback_index_offset = chip->capture_streams;
 	chip->num_streams = chip->playback_streams + chip->capture_streams;
-	chip->azx_dev = devm_kcalloc(card->dev, chip->num_streams,
-				     sizeof(*chip->azx_dev), GFP_KERNEL);
-	if (!chip->azx_dev)
-		return -ENOMEM;
 
 	err = azx_alloc_stream_pages(chip);
 	if (err < 0)
Signature · 1 line
2.3.5
#9 lore raw

PATCH 9/21 ALSA: hda - Migrate more hdac_stream codes

In reply to Takashi Iwai

... including dsp loader helpers. Lots of codes removed.

---
 sound/pci/hda/hda_controller.c | 428 +++++------------------------------------
 sound/pci/hda/hda_intel.c      |   4 +
 sound/pci/hda/hda_tegra.c      |   1 +
 3 files changed, 54 insertions(+), 379 deletions(-)
sound/pci/hda/hda_controller.c +49 -379
index 0b85c88c75ac..32f98f71c1e6 100644
@@ -36,58 +36,6 @@
 #define dsp_unlock(dev)		snd_hdac_dsp_unlock(azx_stream(dev))
 #define dsp_is_locked(dev)	snd_hdac_stream_is_locked(azx_stream(dev))
 
-/*
- * AZX stream operations.
- */
-
-/*
- * set up the SD for streaming
- */
-static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev)
-{
-	unsigned int val;
-	/* make sure the run bit is zero for SD */
-	snd_hdac_stream_clear(azx_stream(azx_dev));
-	/* program the stream_tag */
-	val = azx_sd_readl(chip, azx_dev, SD_CTL);
-	val = (val & ~SD_CTL_STREAM_TAG_MASK) |
-		(azx_dev->core.stream_tag << SD_CTL_STREAM_TAG_SHIFT);
-	if (!azx_snoop(chip))
-		val |= SD_CTL_TRAFFIC_PRIO;
-	azx_sd_writel(chip, azx_dev, SD_CTL, val);
-
-	/* program the length of samples in cyclic buffer */
-	azx_sd_writel(chip, azx_dev, SD_CBL, azx_dev->core.bufsize);
-
-	/* program the stream format */
-	/* this value needs to be the same as the one programmed */
-	azx_sd_writew(chip, azx_dev, SD_FORMAT, azx_dev->core.format_val);
-
-	/* program the stream LVI (last valid index) of the BDL */
-	azx_sd_writew(chip, azx_dev, SD_LVI, azx_dev->core.frags - 1);
-
-	/* program the BDL address */
-	/* lower BDL address */
-	azx_sd_writel(chip, azx_dev, SD_BDLPL, (u32)azx_dev->core.bdl.addr);
-	/* upper BDL address */
-	azx_sd_writel(chip, azx_dev, SD_BDLPU,
-		      upper_32_bits(azx_dev->core.bdl.addr));
-
-	/* enable the position buffer */
-	if (chip->get_position[0] != azx_get_pos_lpib ||
-	    chip->get_position[1] != azx_get_pos_lpib) {
-		if (!(azx_readl(chip, DPLBASE) & AZX_DPLBASE_ENABLE))
-			azx_writel(chip, DPLBASE,
-				(u32)chip->posbuf.addr | AZX_DPLBASE_ENABLE);
-	}
-
-	/* set the interrupt enable bits in the descriptor control register */
-	azx_sd_writel(chip, azx_dev, SD_CTL,
-		      azx_sd_readl(chip, azx_dev, SD_CTL) | SD_INT_MASK);
-
-	return 0;
-}
-
 /* assign a stream for the PCM */
 static inline struct azx_dev *
 azx_assign_device(struct azx *chip, struct snd_pcm_substream *substream)
@@ -106,50 +54,6 @@ static inline void azx_release_device(struct azx_dev *azx_dev)
 	snd_hdac_stream_release(azx_stream(azx_dev));
 }
 
-static cycle_t azx_cc_read(const struct cyclecounter *cc)
-{
-	struct azx_dev *azx_dev = container_of(cc, struct azx_dev, core.cc);
-	struct snd_pcm_substream *substream = azx_dev->core.substream;
-	struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
-	struct azx *chip = apcm->chip;
-
-	return azx_readl(chip, WALLCLK);
-}
-
-static void azx_timecounter_init(struct snd_pcm_substream *substream,
-				bool force, cycle_t last)
-{
-	struct azx_dev *azx_dev = get_azx_dev(substream);
-	struct timecounter *tc = &azx_dev->core.tc;
-	struct cyclecounter *cc = &azx_dev->core.cc;
-	u64 nsec;
-
-	cc->read = azx_cc_read;
-	cc->mask = CLOCKSOURCE_MASK(32);
-
-	/*
-	 * Converting from 24 MHz to ns means applying a 125/3 factor.
-	 * To avoid any saturation issues in intermediate operations,
-	 * the 125 factor is applied first. The division is applied
-	 * last after reading the timecounter value.
-	 * Applying the 1/3 factor as part of the multiplication
-	 * requires at least 20 bits for a decent precision, however
-	 * overflows occur after about 4 hours or less, not a option.
-	 */
-
-	cc->mult = 125; /* saturation after 195 years */
-	cc->shift = 0;
-
-	nsec = 0; /* audio time is elapsed time since trigger */
-	timecounter_init(tc, cc, nsec);
-	if (force)
-		/*
-		 * force timecounter to use predefined value,
-		 * used for synchronized starts
-		 */
-		tc->cycle_last = last;
-}
-
 static inline struct hda_pcm_stream *
 to_hda_pcm_stream(struct snd_pcm_substream *substream)
 {
@@ -178,119 +82,6 @@ static u64 azx_adjust_codec_delay(struct snd_pcm_substream *substream,
 }
 
 /*
- * set up a BDL entry
- */
-static int setup_bdle(struct azx *chip,
-		      struct snd_dma_buffer *dmab,
-		      struct azx_dev *azx_dev, u32 **bdlp,
-		      int ofs, int size, int with_ioc)
-{
-	u32 *bdl = *bdlp;
-
-	while (size > 0) {
-		dma_addr_t addr;
-		int chunk;
-
-		if (azx_dev->core.frags >= AZX_MAX_BDL_ENTRIES)
-			return -EINVAL;
-
-		addr = snd_sgbuf_get_addr(dmab, ofs);
-		/* program the address field of the BDL entry */
-		bdl[0] = cpu_to_le32((u32)addr);
-		bdl[1] = cpu_to_le32(upper_32_bits(addr));
-		/* program the size field of the BDL entry */
-		chunk = snd_sgbuf_get_chunk_size(dmab, ofs, size);
-		/* one BDLE cannot cross 4K boundary on CTHDA chips */
-		if (chip->driver_caps & AZX_DCAPS_4K_BDLE_BOUNDARY) {
-			u32 remain = 0x1000 - (ofs & 0xfff);
-			if (chunk > remain)
-				chunk = remain;
-		}
-		bdl[2] = cpu_to_le32(chunk);
-		/* program the IOC to enable interrupt
-		 * only when the whole fragment is processed
-		 */
-		size -= chunk;
-		bdl[3] = (size || !with_ioc) ? 0 : cpu_to_le32(0x01);
-		bdl += 4;
-		azx_dev->core.frags++;
-		ofs += chunk;
-	}
-	*bdlp = bdl;
-	return ofs;
-}
-
-/*
- * set up BDL entries
- */
-static int azx_setup_periods(struct azx *chip,
-			     struct snd_pcm_substream *substream,
-			     struct azx_dev *azx_dev)
-{
-	u32 *bdl;
-	int i, ofs, periods, period_bytes;
-	int pos_adj = 0;
-
-	/* reset BDL address */
-	azx_sd_writel(chip, azx_dev, SD_BDLPL, 0);
-	azx_sd_writel(chip, azx_dev, SD_BDLPU, 0);
-
-	period_bytes = azx_dev->core.period_bytes;
-	periods = azx_dev->core.bufsize / period_bytes;
-
-	/* program the initial BDL entries */
-	bdl = (u32 *)azx_dev->core.bdl.area;
-	ofs = 0;
-	azx_dev->core.frags = 0;
-
-	if (chip->bdl_pos_adj)
-		pos_adj = chip->bdl_pos_adj[chip->dev_index];
-	if (!azx_dev->core.no_period_wakeup && pos_adj > 0) {
-		struct snd_pcm_runtime *runtime = substream->runtime;
-		int pos_align = pos_adj;
-		pos_adj = (pos_adj * runtime->rate + 47999) / 48000;
-		if (!pos_adj)
-			pos_adj = pos_align;
-		else
-			pos_adj = ((pos_adj + pos_align - 1) / pos_align) *
-				pos_align;
-		pos_adj = frames_to_bytes(runtime, pos_adj);
-		if (pos_adj >= period_bytes) {
-			dev_warn(chip->card->dev,"Too big adjustment %d\n",
-				 pos_adj);
-			pos_adj = 0;
-		} else {
-			ofs = setup_bdle(chip, snd_pcm_get_dma_buf(substream),
-					 azx_dev,
-					 &bdl, ofs, pos_adj, true);
-			if (ofs < 0)
-				goto error;
-		}
-	} else
-		pos_adj = 0;
-
-	for (i = 0; i < periods; i++) {
-		if (i == periods - 1 && pos_adj)
-			ofs = setup_bdle(chip, snd_pcm_get_dma_buf(substream),
-					 azx_dev, &bdl, ofs,
-					 period_bytes - pos_adj, 0);
-		else
-			ofs = setup_bdle(chip, snd_pcm_get_dma_buf(substream),
-					 azx_dev, &bdl, ofs,
-					 period_bytes,
-					 !azx_dev->core.no_period_wakeup);
-		if (ofs < 0)
-			goto error;
-	}
-	return 0;
-
- error:
-	dev_err(chip->card->dev, "Too many BDL entries: buffer=%d, period=%d\n",
-		azx_dev->core.bufsize, period_bytes);
-	return -EINVAL;
-}
-
-/*
  * PCM ops
  */
 
@@ -300,13 +91,8 @@ static int azx_pcm_close(struct snd_pcm_substream *substream)
 	struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream);
 	struct azx *chip = apcm->chip;
 	struct azx_dev *azx_dev = get_azx_dev(substream);
-	unsigned long flags;
 
 	mutex_lock(&chip->open_mutex);
-	spin_lock_irqsave(&chip->reg_lock, flags);
-	azx_dev->core.substream = NULL;
-	azx_dev->core.running = 0;
-	spin_unlock_irqrestore(&chip->reg_lock, flags);
 	azx_release_device(azx_dev);
 	if (hinfo->ops.close)
 		hinfo->ops.close(hinfo, apcm->codec, substream);
@@ -346,14 +132,8 @@ static int azx_pcm_hw_free(struct snd_pcm_substream *substream)
 
 	/* reset BDL address */
 	dsp_lock(azx_dev);
-	if (!dsp_is_locked(azx_dev)) {
-		azx_sd_writel(chip, azx_dev, SD_BDLPL, 0);
-		azx_sd_writel(chip, azx_dev, SD_BDLPU, 0);
-		azx_sd_writel(chip, azx_dev, SD_CTL, 0);
-		azx_dev->core.bufsize = 0;
-		azx_dev->core.period_bytes = 0;
-		azx_dev->core.format_val = 0;
-	}
+	if (!dsp_is_locked(azx_dev))
+		snd_hdac_stream_cleanup(azx_stream(azx_dev));
 
 	snd_hda_codec_cleanup(apcm->codec, hinfo, substream);
 
@@ -411,29 +191,12 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
 		azx_dev->core.period_bytes = period_bytes;
 		azx_dev->core.format_val = format_val;
 		azx_dev->core.no_period_wakeup = runtime->no_period_wakeup;
-		err = azx_setup_periods(chip, substream, azx_dev);
+		err = snd_hdac_stream_setup_periods(azx_stream(azx_dev));
 		if (err < 0)
 			goto unlock;
 	}
 
-	/* when LPIB delay correction gives a small negative value,
-	 * we ignore it; currently set the threshold statically to
-	 * 64 frames
-	 */
-	if (runtime->period_size > 64)
-		azx_dev->core.delay_negative_threshold = -frames_to_bytes(runtime, 64);
-	else
-		azx_dev->core.delay_negative_threshold = 0;
-
-	/* wallclk has 24Mhz clock source */
-	azx_dev->core.period_wallclk = (((runtime->period_size * 24000) /
-						runtime->rate) * 1000);
-	azx_setup_controller(chip, azx_dev);
-	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
-		azx_dev->core.fifo_size =
-			azx_sd_readw(chip, azx_dev, SD_FIFOSIZE) + 1;
-	else
-		azx_dev->core.fifo_size = 0;
+	snd_hdac_stream_setup(azx_stream(azx_dev));
 
 	stream_tag = azx_dev->core.stream_tag;
 	/* CA-IBG chips need the playback stream starting from 1 */
@@ -456,25 +219,31 @@ static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
 	struct azx *chip = apcm->chip;
 	struct azx_dev *azx_dev;
 	struct snd_pcm_substream *s;
-	int rstart = 0, start, nsync = 0, sbits = 0;
-	int nwait, timeout;
+	struct hdac_stream *hstr;
+	bool start;
+	int sbits = 0;
+	int sync_reg;
 
 	azx_dev = get_azx_dev(substream);
+	hstr = azx_stream(azx_dev);
+	if (chip->driver_caps & AZX_DCAPS_OLD_SSYNC)
+		sync_reg = AZX_REG_OLD_SSYNC;
+	else
+		sync_reg = AZX_REG_SSYNC;
 
 	if (dsp_is_locked(azx_dev) || !azx_dev->prepared)
 		return -EPIPE;
 
 	switch (cmd) {
 	case SNDRV_PCM_TRIGGER_START:
-		rstart = 1;
 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
 	case SNDRV_PCM_TRIGGER_RESUME:
-		start = 1;
+		start = true;
 		break;
 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
 	case SNDRV_PCM_TRIGGER_SUSPEND:
 	case SNDRV_PCM_TRIGGER_STOP:
-		start = 0;
+		start = false;
 		break;
 	default:
 		return -EINVAL;
@@ -485,18 +254,13 @@ static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
 			continue;
 		azx_dev = get_azx_dev(s);
 		sbits |= 1 << azx_dev->core.index;
-		nsync++;
 		snd_pcm_trigger_done(s, substream);
 	}
 
 	spin_lock(&chip->reg_lock);
 
 	/* first, set SYNC bits of corresponding streams */
-	if (chip->driver_caps & AZX_DCAPS_OLD_SSYNC)
-		azx_writel(chip, OLD_SSYNC,
-			azx_readl(chip, OLD_SSYNC) | sbits);
-	else
-		azx_writel(chip, SSYNC, azx_readl(chip, SSYNC) | sbits);
+	snd_hdac_stream_sync_trigger(hstr, true, sbits, sync_reg);
 
 	snd_pcm_group_for_each_entry(s, substream) {
 		if (s->pcm->card != substream->pcm->card)
@@ -510,65 +274,14 @@ static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
 		}
 	}
 	spin_unlock(&chip->reg_lock);
-	if (start) {
-		/* wait until all FIFOs get ready */
-		for (timeout = 5000; timeout; timeout--) {
-			nwait = 0;
-			snd_pcm_group_for_each_entry(s, substream) {
-				if (s->pcm->card != substream->pcm->card)
-					continue;
-				azx_dev = get_azx_dev(s);
-				if (!(azx_sd_readb(chip, azx_dev, SD_STS) &
-				      SD_STS_FIFO_READY))
-					nwait++;
-			}
-			if (!nwait)
-				break;
-			cpu_relax();
-		}
-	} else {
-		/* wait until all RUN bits are cleared */
-		for (timeout = 5000; timeout; timeout--) {
-			nwait = 0;
-			snd_pcm_group_for_each_entry(s, substream) {
-				if (s->pcm->card != substream->pcm->card)
-					continue;
-				azx_dev = get_azx_dev(s);
-				if (azx_sd_readb(chip, azx_dev, SD_CTL) &
-				    SD_CTL_DMA_START)
-					nwait++;
-			}
-			if (!nwait)
-				break;
-			cpu_relax();
-		}
-	}
+
+	snd_hdac_stream_sync(hstr, start, sbits);
+
 	spin_lock(&chip->reg_lock);
 	/* reset SYNC bits */
-	if (chip->driver_caps & AZX_DCAPS_OLD_SSYNC)
-		azx_writel(chip, OLD_SSYNC,
-			azx_readl(chip, OLD_SSYNC) & ~sbits);
-	else
-		azx_writel(chip, SSYNC, azx_readl(chip, SSYNC) & ~sbits);
-	if (start) {
-		azx_timecounter_init(substream, 0, 0);
-		snd_pcm_gettime(substream->runtime, &substream->runtime->trigger_tstamp);
-		substream->runtime->trigger_tstamp_latched = true;
-
-		if (nsync > 1) {
-			cycle_t cycle_last;
-
-			/* same start cycle for master and group */
-			azx_dev = get_azx_dev(substream);
-			cycle_last = azx_dev->core.tc.cycle_last;
-
-			snd_pcm_group_for_each_entry(s, substream) {
-				if (s->pcm->card != substream->pcm->card)
-					continue;
-				azx_timecounter_init(s, 1, cycle_last);
-			}
-		}
-	}
+	snd_hdac_stream_sync_trigger(hstr, false, sbits, sync_reg);
+	if (start)
+		snd_hdac_stream_timecounter_init(hstr, sbits);
 	spin_unlock(&chip->reg_lock);
 	return 0;
 }
@@ -689,7 +402,6 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
 	struct azx *chip = apcm->chip;
 	struct azx_dev *azx_dev;
 	struct snd_pcm_runtime *runtime = substream->runtime;
-	unsigned long flags;
 	int err;
 	int buff_step;
 
@@ -700,6 +412,7 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
 		err = -EBUSY;
 		goto unlock;
 	}
+	runtime->private_data = azx_dev;
 	runtime->hw = azx_pcm_hw;
 	runtime->hw.channels_min = hinfo->channels_min;
 	runtime->hw.channels_max = hinfo->channels_max;
@@ -761,12 +474,6 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
 		runtime->hw.info &= ~SNDRV_PCM_INFO_HAS_LINK_ATIME;
 	}
 
-	spin_lock_irqsave(&chip->reg_lock, flags);
-	azx_dev->core.substream = substream;
-	azx_dev->core.running = 0;
-	spin_unlock_irqrestore(&chip->reg_lock, flags);
-
-	runtime->private_data = azx_dev;
 	snd_pcm_set_sync(substream);
 	mutex_unlock(&chip->open_mutex);
 	return 0;
@@ -1271,60 +978,31 @@ static int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format,
 				unsigned int byte_size,
 				struct snd_dma_buffer *bufp)
 {
-	u32 *bdl;
 	struct azx *chip = bus->private_data;
 	struct azx_dev *azx_dev;
+	struct hdac_stream *hstr;
+	bool saved = false;
 	int err;
 
 	azx_dev = azx_get_dsp_loader_dev(chip);
-
-	dsp_lock(azx_dev);
+	hstr = azx_stream(azx_dev);
 	spin_lock_irq(&chip->reg_lock);
-	if (azx_dev->core.running || azx_dev->core.locked) {
-		spin_unlock_irq(&chip->reg_lock);
-		err = -EBUSY;
-		goto unlock;
+	if (hstr->opened) {
+		chip->saved_azx_dev = *azx_dev;
+		saved = true;
 	}
-	azx_dev->prepared = 0;
-	chip->saved_azx_dev = *azx_dev;
-	azx_dev->core.locked = 1;
 	spin_unlock_irq(&chip->reg_lock);
 
-	err = chip->io_ops->dma_alloc_pages(&bus->core, SNDRV_DMA_TYPE_DEV_SG,
-					    byte_size, bufp);
-	if (err < 0)
-		goto err_alloc;
-
-	azx_dev->core.bufsize = byte_size;
-	azx_dev->core.period_bytes = byte_size;
-	azx_dev->core.format_val = format;
-
-	snd_hdac_stream_reset(azx_stream(azx_dev));
-
-	/* reset BDL address */
-	azx_sd_writel(chip, azx_dev, SD_BDLPL, 0);
-	azx_sd_writel(chip, azx_dev, SD_BDLPU, 0);
-
-	azx_dev->core.frags = 0;
-	bdl = (u32 *)azx_dev->core.bdl.area;
-	err = setup_bdle(chip, bufp, azx_dev, &bdl, 0, byte_size, 0);
-	if (err < 0)
-		goto error;
-
-	azx_setup_controller(chip, azx_dev);
-	dsp_unlock(azx_dev);
-	return azx_dev->core.stream_tag;
+	err = snd_hdac_dsp_prepare(hstr, format, byte_size, bufp);
+	if (err < 0) {
+		spin_lock_irq(&chip->reg_lock);
+		if (saved)
+			*azx_dev = chip->saved_azx_dev;
+		spin_unlock_irq(&chip->reg_lock);
+		return err;
+	}
 
- error:
-	chip->io_ops->dma_free_pages(&bus->core, bufp);
- err_alloc:
-	spin_lock_irq(&chip->reg_lock);
-	if (azx_dev->core.opened)
-		*azx_dev = chip->saved_azx_dev;
-	azx_dev->core.locked = 0;
-	spin_unlock_irq(&chip->reg_lock);
- unlock:
-	dsp_unlock(azx_dev);
+	azx_dev->prepared = 0;
 	return err;
 }
 
@@ -1333,10 +1011,7 @@ static void azx_load_dsp_trigger(struct hda_bus *bus, bool start)
 	struct azx *chip = bus->private_data;
 	struct azx_dev *azx_dev = azx_get_dsp_loader_dev(chip);
 
-	if (start)
-		snd_hdac_stream_start(azx_stream(azx_dev), false);
-	else
-		snd_hdac_stream_stop(azx_stream(azx_dev));
+	snd_hdac_dsp_trigger(azx_stream(azx_dev), start);
 }
 
 static void azx_load_dsp_cleanup(struct hda_bus *bus,
@@ -1344,28 +1019,17 @@ static void azx_load_dsp_cleanup(struct hda_bus *bus,
 {
 	struct azx *chip = bus->private_data;
 	struct azx_dev *azx_dev = azx_get_dsp_loader_dev(chip);
+	struct hdac_stream *hstr = azx_stream(azx_dev);
 
 	if (!dmab->area || !azx_dev->core.locked)
 		return;
 
-	dsp_lock(azx_dev);
-	/* reset BDL address */
-	azx_sd_writel(chip, azx_dev, SD_BDLPL, 0);
-	azx_sd_writel(chip, azx_dev, SD_BDLPU, 0);
-	azx_sd_writel(chip, azx_dev, SD_CTL, 0);
-	azx_dev->core.bufsize = 0;
-	azx_dev->core.period_bytes = 0;
-	azx_dev->core.format_val = 0;
-
-	chip->io_ops->dma_free_pages(&bus->core, dmab);
-	dmab->area = NULL;
-
+	snd_hdac_dsp_cleanup(hstr, dmab);
 	spin_lock_irq(&chip->reg_lock);
-	if (azx_dev->core.opened)
+	if (hstr->opened)
 		*azx_dev = chip->saved_azx_dev;
-	azx_dev->core.locked = 0;
+	hstr->locked = false;
 	spin_unlock_irq(&chip->reg_lock);
-	dsp_unlock(azx_dev);
 }
 #endif /* CONFIG_SND_HDA_DSP_LOADER */
 
@@ -1742,6 +1406,12 @@ int azx_bus_create(struct azx *chip, const char *model)
 	bus->pci = chip->pci;
 	bus->modelname = model;
 	bus->ops = bus_ops;
+	bus->core.snoop = azx_snoop(chip);
+	if (chip->get_position[0] != azx_get_pos_lpib ||
+	    chip->get_position[1] != azx_get_pos_lpib)
+		bus->core.use_posbuf = true;
+	if (chip->bdl_pos_adj)
+		bus->core.bdl_pos_adj = chip->bdl_pos_adj[chip->dev_index];
 
 	if (chip->driver_caps & AZX_DCAPS_RIRB_DELAY) {
 		dev_dbg(chip->card->dev, "Enable delay in RIRB handling\n");
sound/pci/hda/hda_intel.c +4 -0
index c440ac1e34c8..a55d8504fe00 100644
@@ -568,6 +568,9 @@ static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev)
 			dev_info(chip->card->dev,
 				 "Invalid position buffer, using LPIB read method instead.\n");
 			chip->get_position[stream] = azx_get_pos_lpib;
+			if (chip->get_position[0] == azx_get_pos_lpib &&
+			    chip->get_position[1] == azx_get_pos_lpib)
+				azx_bus(chip)->use_posbuf = false;
 			pos = azx_get_pos_lpib(chip, azx_dev);
 			chip->get_delay[stream] = NULL;
 		} else {
@@ -1477,6 +1480,7 @@ static int azx_first_init(struct azx *chip)
 		dev_err(card->dev, "ioremap error\n");
 		return -ENXIO;
 	}
+	azx_bus(chip)->remap_addr = chip->remap_addr; /* FIXME */
 
 	if (chip->msi) {
 		if (chip->driver_caps & AZX_DCAPS_NO_MSI64) {
sound/pci/hda/hda_tegra.c +1 -0
index e25e0df7f067..c6fc96afbdc1 100644
@@ -325,6 +325,7 @@ static int hda_tegra_init_chip(struct azx *chip, struct platform_device *pdev)
 		return PTR_ERR(hda->regs);
 
 	chip->remap_addr = hda->regs + HDA_BAR0;
+	azx_bus(chip)->remap_addr = chip->remap_addr; /* FIXME */
 	chip->addr = res->start + HDA_BAR0;
 
 	err = hda_tegra_enable_clocks(hda);
Signature · 1 line
2.3.5
#10 lore raw

PATCH 10/21 ALSA: hda - Embed bus into controller object

In reply to Takashi Iwai

... and replace with the existing hda-core helper codes. This reduces lots of lines, finally.

Since struct hda_bus is now embedded into struct azx, snd_hda_bus_new() is moved and expanded from hda_codec.c to hda_controller.c, accordingly. Also private_free bus ops and private_data field are removed because we no longer need to point azx object from bus (we can use container_of())

The spin locks are consolidated into the single one, bus->reg_lock.

---
 sound/pci/hda/hda_codec.c      |  72 ------
 sound/pci/hda/hda_codec.h      |   3 -
 sound/pci/hda/hda_controller.c | 561 ++++++++---------------------------------
 sound/pci/hda/hda_controller.h |  65 ++---
 sound/pci/hda/hda_intel.c      | 133 ++++++----
 sound/pci/hda/hda_intel.h      |   1 +
 sound/pci/hda/hda_tegra.c      |  43 ++--
 7 files changed, 232 insertions(+), 646 deletions(-)
sound/pci/hda/hda_codec.c +0 -72
index ddebe7541390..2abf9f95dcbb 100644
@@ -482,78 +482,6 @@ int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid,
 }
 
 /*
- * destructor
- */
-static void snd_hda_bus_free(struct hda_bus *bus)
-{
-	if (!bus)
-		return;
-	if (bus->ops.private_free)
-		bus->ops.private_free(bus);
-	snd_hdac_bus_exit(&bus->core);
-	kfree(bus);
-}
-
-static int snd_hda_bus_dev_free(struct snd_device *device)
-{
-	snd_hda_bus_free(device->device_data);
-	return 0;
-}
-
-static int snd_hda_bus_dev_disconnect(struct snd_device *device)
-{
-	struct hda_bus *bus = device->device_data;
-	bus->shutdown = 1;
-	return 0;
-}
-
-/**
- * snd_hda_bus_new - create a HDA bus
- * @card: the card entry
- * @busp: the pointer to store the created bus instance
- *
- * Returns 0 if successful, or a negative error code.
- */
-int snd_hda_bus_new(struct snd_card *card,
-		    const struct hdac_bus_ops *ops,
-		    const struct hdac_io_ops *io_ops,
-		    struct hda_bus **busp)
-{
-	struct hda_bus *bus;
-	int err;
-	static struct snd_device_ops dev_ops = {
-		.dev_disconnect = snd_hda_bus_dev_disconnect,
-		.dev_free = snd_hda_bus_dev_free,
-	};
-
-	if (busp)
-		*busp = NULL;
-
-	bus = kzalloc(sizeof(*bus), GFP_KERNEL);
-	if (!bus)
-		return -ENOMEM;
-
-	err = snd_hdac_bus_init(&bus->core, card->dev, ops, io_ops);
-	if (err < 0) {
-		kfree(bus);
-		return err;
-	}
-
-	bus->card = card;
-	mutex_init(&bus->prepare_mutex);
-
-	err = snd_device_new(card, SNDRV_DEV_BUS, bus, &dev_ops);
-	if (err < 0) {
-		snd_hda_bus_free(bus);
-		return err;
-	}
-	if (busp)
-		*busp = bus;
-	return 0;
-}
-EXPORT_SYMBOL_GPL(snd_hda_bus_new);
-
-/*
  * read widget caps for each widget and store in cache
  */
 static int read_widget_caps(struct hda_codec *codec, hda_nid_t fg_node)
sound/pci/hda/hda_codec.h +0 -3
index c8031360de90..57b9aa0f36c1 100644
@@ -42,8 +42,6 @@ struct hda_pcm_stream;
 
 /* bus operators */
 struct hda_bus_ops {
-	/* free the private data */
-	void (*private_free)(struct hda_bus *);
 	/* attach a PCM stream */
 	int (*attach_pcm)(struct hda_bus *bus, struct hda_codec *codec,
 			  struct hda_pcm *pcm);
@@ -73,7 +71,6 @@ struct hda_bus {
 
 	struct snd_card *card;
 
-	void *private_data;
 	struct pci_dev *pci;
 	const char *modelname;
 	struct hda_bus_ops ops;
sound/pci/hda/hda_controller.c +107 -454

877 lines not on this page · raw message

sound/pci/hda/hda_controller.h +20 -45

140 lines not on this page · raw message

sound/pci/hda/hda_intel.c +77 -56

395 lines not on this page · raw message

sound/pci/hda/hda_intel.h +1 -0
index d5231f7216a7..206989878bc6 100644
@@ -34,6 +34,7 @@ struct hda_intel {
 
 	/* extra flags */
 	unsigned int irq_pending_warned:1;
+	unsigned int probe_continued:1;
 
 	/* VGA-switcheroo setup */
 	unsigned int use_vga_switcheroo:1;
sound/pci/hda/hda_tegra.c +27 -16

132 lines not on this page · raw message

Signature · 1 line
2.3.5
#11 lore raw

PATCH 11/21 ALSA: hda - Minor refactoring

In reply to Takashi Iwai

Move the small portion of the common sequence in hda_intel.c and hda_tegra.c into hda_controller.c.

---
 sound/pci/hda/hda_controller.c | 10 +++++++---
 sound/pci/hda/hda_intel.c      |  3 ---
 sound/pci/hda/hda_tegra.c      |  3 ---
 3 files changed, 7 insertions(+), 9 deletions(-)
sound/pci/hda/hda_controller.c +7 -3
index 21058b41b2c6..aaf01e841426 100644
@@ -107,18 +107,22 @@ static int azx_pcm_hw_params(struct snd_pcm_substream *substream,
 {
 	struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
 	struct azx *chip = apcm->chip;
+	struct azx_dev *azx_dev = get_azx_dev(substream);
 	int ret;
 
-	dsp_lock(get_azx_dev(substream));
-	if (dsp_is_locked(get_azx_dev(substream))) {
+	dsp_lock(azx_dev);
+	if (dsp_is_locked(azx_dev)) {
 		ret = -EBUSY;
 		goto unlock;
 	}
 
+	azx_dev->core.bufsize = 0;
+	azx_dev->core.period_bytes = 0;
+	azx_dev->core.format_val = 0;
 	ret = chip->ops->substream_alloc_pages(chip, substream,
 					  params_buffer_bytes(hw_params));
 unlock:
-	dsp_unlock(get_azx_dev(substream));
+	dsp_unlock(azx_dev);
 	return ret;
 }
 
sound/pci/hda/hda_intel.c +0 -3
index 9dff693005ea..8a1471851ca7 100644
@@ -1743,9 +1743,6 @@ static int substream_alloc_pages(struct azx *chip,
 	int ret;
 
 	mark_runtime_wc(chip, azx_dev, substream, false);
-	azx_dev->core.bufsize = 0;
-	azx_dev->core.period_bytes = 0;
-	azx_dev->core.format_val = 0;
 	ret = snd_pcm_lib_malloc_pages(substream, size);
 	if (ret < 0)
 		return ret;
sound/pci/hda/hda_tegra.c +0 -3
index 397e1821020f..d5349809f43d 100644
@@ -104,9 +104,6 @@ static int substream_alloc_pages(struct azx *chip,
 {
 	struct azx_dev *azx_dev = get_azx_dev(substream);
 
-	azx_dev->core.bufsize = 0;
-	azx_dev->core.period_bytes = 0;
-	azx_dev->core.format_val = 0;
 	return snd_pcm_lib_malloc_pages(substream, size);
 }
 
Signature · 1 line
2.3.5
#12 lore raw

PATCH 12/21 ALSA: hda - Move PCM format and rate handling code to core library

In reply to Takashi Iwai
---
 include/sound/hdaudio.h        |   9 ++
 sound/hda/hdac_device.c        | 300 ++++++++++++++++++++++++++++++++++++++++
 sound/pci/hda/hda_codec.c      | 305 -----------------------------------------
 sound/pci/hda/hda_codec.h      |  15 +-
 sound/pci/hda/hda_controller.c |   3 +-
 sound/pci/hda/patch_ca0132.c   |   7 +-
 6 files changed, 317 insertions(+), 322 deletions(-)
include/sound/hdaudio.h +9 -0
index 59d21848a472..15bc039de78d 100644
@@ -123,6 +123,15 @@ int snd_hdac_get_connections(struct hdac_device *codec, hda_nid_t nid,
 			     hda_nid_t *conn_list, int max_conns);
 int snd_hdac_get_sub_nodes(struct hdac_device *codec, hda_nid_t nid,
 			   hda_nid_t *start_id);
+unsigned int snd_hdac_calc_stream_format(unsigned int rate,
+					 unsigned int channels,
+					 unsigned int format,
+					 unsigned int maxbps,
+					 unsigned short spdif_ctls);
+int snd_hdac_query_supported_pcm(struct hdac_device *codec, hda_nid_t nid,
+				u32 *ratesp, u64 *formatsp, unsigned int *bpsp);
+bool snd_hdac_is_supported_format(struct hdac_device *codec, hda_nid_t nid,
+				  unsigned int format);
 
 /**
  * snd_hdac_read_parm - read a codec parameter
sound/hda/hdac_device.c +300 -0

309 lines not on this page · raw message

sound/pci/hda/hda_codec.c +0 -305

311 lines not on this page · raw message

sound/pci/hda/hda_codec.h +5 -10
index 57b9aa0f36c1..1ffdd39cb556 100644
@@ -365,8 +365,6 @@ int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux,
 			   hda_nid_t nid, int recursive);
 int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid,
 			u8 *dev_list, int max_devices);
-int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid,
-				u32 *ratesp, u64 *formatsp, unsigned int *bpsp);
 
 struct hda_verb {
 	hda_nid_t nid;
@@ -458,14 +456,11 @@ void __snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid,
 				    int do_now);
 #define snd_hda_codec_cleanup_stream(codec, nid) \
 	__snd_hda_codec_cleanup_stream(codec, nid, 0)
-unsigned int snd_hda_calc_stream_format(struct hda_codec *codec,
-					unsigned int rate,
-					unsigned int channels,
-					unsigned int format,
-					unsigned int maxbps,
-					unsigned short spdif_ctls);
-int snd_hda_is_supported_format(struct hda_codec *codec, hda_nid_t nid,
-				unsigned int format);
+
+#define snd_hda_query_supported_pcm(codec, nid, ratesp, fmtsp, bpsp) \
+	snd_hdac_query_supported_pcm(&(codec)->core, nid, ratesp, fmtsp, bpsp)
+#define snd_hda_is_supported_format(codec, nid, fmt) \
+	snd_hdac_is_supported_format(&(codec)->core, nid, fmt)
 
 extern const struct snd_pcm_chmap_elem snd_pcm_2_1_chmaps[];
 
sound/pci/hda/hda_controller.c +1 -2
index aaf01e841426..8f12ad9a4df5 100644
@@ -167,8 +167,7 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
 	}
 
 	snd_hdac_stream_reset(azx_stream(azx_dev));
-	format_val = snd_hda_calc_stream_format(apcm->codec,
-						runtime->rate,
+	format_val = snd_hdac_calc_stream_format(runtime->rate,
 						runtime->channels,
 						runtime->format,
 						hinfo->maxbps,
sound/pci/hda/patch_ca0132.c +2 -5
index 4a4e7b282e4f..2de1a4222a7d 100644
@@ -2052,11 +2052,8 @@ static int dma_convert_to_hda_format(struct hda_codec *codec,
 {
 	unsigned int format_val;
 
-	format_val = snd_hda_calc_stream_format(codec,
-				sample_rate,
-				channels,
-				SNDRV_PCM_FORMAT_S32_LE,
-				32, 0);
+	format_val = snd_hdac_calc_stream_format(sample_rate,
+				channels, SNDRV_PCM_FORMAT_S32_LE, 32, 0);
 
 	if (hda_format)
 		*hda_format = (unsigned short)format_val;
Signature · 1 line
2.3.5
#13 lore raw

PATCH 13/21 ALSA: hda - Add missing inclusion of <linux/clocksource.h>

In reply to Takashi Iwai

For fixing randconfig build errors like:

sound/hda/hdac_stream.c: In function 'azx_timecounter_init':
sound/hda/hdac_stream.c:365:2: error: implicit declaration of function 'CLOCKSOURCE_MASK' [-Werror=implicit-function-declaration]

---
 sound/hda/hdac_stream.c | 1 +
 1 file changed, 1 insertion(+)
sound/hda/hdac_stream.c +1 -0
index 8bd67a824b5e..9ffff6d9ba8e 100644
@@ -5,6 +5,7 @@
 #include <linux/kernel.h>
 #include <linux/delay.h>
 #include <linux/export.h>
+#include <linux/clocksource.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/hdaudio.h>
Signature · 1 line
2.3.5
#14 lore raw

PATCH 14/21 ALSA: hda - Reenable tracepoints for controller

In reply to Takashi Iwai

After correcting the fields to point the right members, tracepoints can be reenabled again for the legacy controller code.

---
 sound/pci/hda/hda_controller.c  | 6 ++++++
 sound/pci/hda/hda_intel_trace.h | 4 ++--
 2 files changed, 8 insertions(+), 2 deletions(-)
sound/pci/hda/hda_controller.c +6 -0
index 8f12ad9a4df5..0e43f79e1d9b 100644
@@ -31,6 +31,9 @@
 #include <sound/initval.h>
 #include "hda_controller.h"
 
+#define CREATE_TRACE_POINTS
+#include "hda_intel_trace.h"
+
 /* DSP lock helpers */
 #define dsp_lock(dev)		snd_hdac_dsp_lock(azx_stream(dev))
 #define dsp_unlock(dev)		snd_hdac_dsp_unlock(azx_stream(dev))
@@ -229,6 +232,8 @@ static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
 	int sync_reg;
 
 	azx_dev = get_azx_dev(substream);
+	trace_azx_pcm_trigger(chip, azx_dev, cmd);
+
 	hstr = azx_stream(azx_dev);
 	if (chip->driver_caps & AZX_DCAPS_OLD_SSYNC)
 		sync_reg = AZX_REG_OLD_SSYNC;
@@ -330,6 +335,7 @@ unsigned int azx_get_position(struct azx *chip,
 		substream->runtime->delay = delay;
 	}
 
+	trace_azx_get_position(chip, azx_dev, pos, delay);
 	return pos;
 }
 EXPORT_SYMBOL_GPL(azx_get_position);
sound/pci/hda/hda_intel_trace.h +2 -2
index 7b5e4c2cf9d5..ae004737d0fd 100644
@@ -24,7 +24,7 @@ TRACE_EVENT(azx_pcm_trigger,
 
 	TP_fast_assign(
 		__entry->card = (chip)->card->number;
-		__entry->idx = (dev)->index;
+		__entry->idx = (dev)->core.index;
 		__entry->cmd = cmd;
 	),
 
@@ -46,7 +46,7 @@ TRACE_EVENT(azx_get_position,
 
 	TP_fast_assign(
 		__entry->card = (chip)->card->number;
-		__entry->idx = (dev)->index;
+		__entry->idx = (dev)->core.index;
 		__entry->pos = pos;
 		__entry->delay = delay;
 	),
Signature · 1 line
2.3.5
#15 lore raw

PATCH 15/21 ALSA: hda/tegra - Fix build error and warning

In reply to Takashi Iwai

I seem to have failed to run the build test properly...
sound/pci/hda/hda_tegra.c: In function 'hda_tegra_dev_free':
sound/pci/hda/hda_tegra.c:310:20: error: 'bus' undeclared (first use in this function)

         snd_hdac_bus_exit(bus);
---
 sound/pci/hda/hda_tegra.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
sound/pci/hda/hda_tegra.c +1 -3
index d5349809f43d..801e9fb4a467 100644
@@ -102,8 +102,6 @@ static int substream_alloc_pages(struct azx *chip,
 				 struct snd_pcm_substream *substream,
 				 size_t size)
 {
-	struct azx_dev *azx_dev = get_azx_dev(substream);
-
 	return snd_pcm_lib_malloc_pages(substream, size);
 }
 
@@ -304,7 +302,7 @@ static int hda_tegra_dev_free(struct snd_device *device)
 
 	azx_free_stream_pages(chip);
 	azx_free_streams(chip);
-	snd_hdac_bus_exit(bus);
+	snd_hdac_bus_exit(azx_bus(chip));
 
 	return 0;
 }
Signature · 1 line
2.3.5
#16 lore raw

PATCH 16/21 ALSA: hda - Drop azx_sd_read*/write*() macros

In reply to Takashi Iwai

They are no longer used (only one place which can be replaced with a proper helper function). Let's drop.

---
 sound/pci/hda/hda_controller.h | 13 -------------
 sound/pci/hda/hda_intel.c      |  2 +-
 2 files changed, 1 insertion(+), 14 deletions(-)
sound/pci/hda/hda_controller.h +0 -13
index e8edb02c12d3..407cba6577b8 100644
@@ -185,19 +185,6 @@ struct azx {
 #define azx_readb(chip, reg) \
 	snd_hdac_chip_readb(azx_bus(chip), reg)
 
-#define azx_sd_writel(chip, dev, reg, value) \
-	snd_hdac_stream_writel(&(dev)->core, reg, value)
-#define azx_sd_readl(chip, dev, reg) \
-	snd_hdac_stream_readl(&(dev)->core, reg)
-#define azx_sd_writew(chip, dev, reg, value) \
-	snd_hdac_stream_writew(&(dev)->core, reg, value)
-#define azx_sd_readw(chip, dev, reg) \
-	snd_hdac_stream_readw(&(dev)->core, reg)
-#define azx_sd_writeb(chip, dev, reg, value) \
-	snd_hdac_stream_writeb(&(dev)->core, reg, value)
-#define azx_sd_readb(chip, dev, reg) \
-	snd_hdac_stream_readb(&(dev)->core, reg)
-
 #define azx_has_pm_runtime(chip) \
 	(!AZX_DCAPS_PM_RUNTIME || ((chip)->driver_caps & AZX_DCAPS_PM_RUNTIME))
 
sound/pci/hda/hda_intel.c +1 -1
index 8a1471851ca7..2b823d4ad888 100644
@@ -680,7 +680,7 @@ static unsigned int azx_via_get_position(struct azx *chip,
 	unsigned int mod_link_pos, mod_dma_pos, mod_mini_pos;
 	unsigned int fifo_size;
 
-	link_pos = azx_sd_readl(chip, azx_dev, SD_LPIB);
+	link_pos = snd_hdac_stream_get_pos_lpib(azx_stream(azx_dev));
 	if (azx_dev->core.substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
 		/* Playback, no problem using link position */
 		return link_pos;
Signature · 1 line
2.3.5
#17 lore raw

PATCH 17/21 ALSA: hda - Replace hda_bus_ops with static binding

In reply to Takashi Iwai

Originally hda_bus takes its own ops (hda_bus_ops) to allow different controller drivers giving individual implementations of PCM attachment, etc. But this never happened and we finally merged both codec and controller helper codes. Thus there is no merit to keep the indirect accesses to functions via hda_bus_ops.

This patch replaces these calls with the direct local function calls for simplification.

---
 sound/pci/hda/hda_codec.c      | 12 ++++-------
 sound/pci/hda/hda_codec.h      | 49 +++++++++---------------------------------
 sound/pci/hda/hda_controller.c | 42 +++++++++++++++---------------------
 3 files changed, 31 insertions(+), 72 deletions(-)
sound/pci/hda/hda_codec.c +4 -8
index df3cebc06110..2d8883fbde2b 100644
@@ -150,7 +150,7 @@ static int codec_exec_verb(struct hdac_device *dev, unsigned int cmd,
 		if (bus->response_reset) {
 			codec_dbg(codec,
 				  "resetting BUS due to fatal communication error\n");
-			bus->ops.bus_reset(bus);
+			snd_hda_bus_reset(bus);
 		}
 		goto again;
 	}
@@ -3403,9 +3403,6 @@ int snd_hda_codec_build_pcms(struct hda_codec *codec)
 	struct hda_pcm *cpcm;
 	int dev, err;
 
-	if (snd_BUG_ON(!bus->ops.attach_pcm))
-		return -EINVAL;
-
 	err = snd_hda_codec_parse_pcms(codec);
 	if (err < 0) {
 		snd_hda_codec_reset(codec);
@@ -3423,7 +3420,7 @@ int snd_hda_codec_build_pcms(struct hda_codec *codec)
 		if (dev < 0)
 			continue; /* no fatal error */
 		cpcm->device = dev;
-		err =  bus->ops.attach_pcm(bus, codec, cpcm);
+		err =  snd_hda_attach_pcm_stream(bus, codec, cpcm);
 		if (err < 0) {
 			codec_err(codec,
 				  "cannot attach PCM stream %d for codec #%d\n",
@@ -4093,10 +4090,10 @@ int snd_hda_add_imux_item(struct hda_codec *codec,
 EXPORT_SYMBOL_GPL(snd_hda_add_imux_item);
 
 /**
- * snd_hda_bus_reset - Reset the bus
+ * snd_hda_bus_reset_codecs - Reset the bus
  * @bus: HD-audio bus
  */
-void snd_hda_bus_reset(struct hda_bus *bus)
+void snd_hda_bus_reset_codecs(struct hda_bus *bus)
 {
 	struct hda_codec *codec;
 
@@ -4111,7 +4108,6 @@ void snd_hda_bus_reset(struct hda_bus *bus)
 #endif
 	}
 }
-EXPORT_SYMBOL_GPL(snd_hda_bus_reset);
 
 /**
  * snd_print_pcm_bits - Print the supported PCM fmt bits to the string buffer
sound/pci/hda/hda_codec.h +10 -39

79 lines not on this page · raw message

sound/pci/hda/hda_controller.c +17 -25

104 lines not on this page · raw message

Signature · 1 line
2.3.5
#18 lore raw

PATCH 18/21 ALSA: hda - Move prepared flag into struct hdac_stream

In reply to Takashi Iwai

This flag seems used commonly, so deserves to be located there.

---
 include/sound/hdaudio.h        | 1 +
 sound/pci/hda/hda_controller.c | 8 ++++----
 sound/pci/hda/hda_controller.h | 1 -
 3 files changed, 5 insertions(+), 5 deletions(-)
include/sound/hdaudio.h +1 -0
index 15bc039de78d..dbeb195eb4e8 100644
@@ -390,6 +390,7 @@ struct hdac_stream {
 
 	bool opened:1;
 	bool running:1;
+	bool prepared:1;
 	bool no_period_wakeup:1;
 	bool locked:1;
 
sound/pci/hda/hda_controller.c +4 -4
index 9bc8eaf0e5ac..14ffb6bd986c 100644
@@ -145,7 +145,7 @@ static int azx_pcm_hw_free(struct snd_pcm_substream *substream)
 	snd_hda_codec_cleanup(apcm->codec, hinfo, substream);
 
 	err = chip->ops->substream_free_pages(chip, substream);
-	azx_dev->prepared = 0;
+	azx_stream(azx_dev)->prepared = 0;
 	dsp_unlock(azx_dev);
 	return err;
 }
@@ -214,7 +214,7 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
 
  unlock:
 	if (!err)
-		azx_dev->prepared = 1;
+		azx_stream(azx_dev)->prepared = 1;
 	dsp_unlock(azx_dev);
 	return err;
 }
@@ -240,7 +240,7 @@ static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
 	else
 		sync_reg = AZX_REG_SSYNC;
 
-	if (dsp_is_locked(azx_dev) || !azx_dev->prepared)
+	if (dsp_is_locked(azx_dev) || !hstr->prepared)
 		return -EPIPE;
 
 	switch (cmd) {
@@ -843,7 +843,7 @@ int snd_hda_codec_load_dsp_prepare(struct hda_codec *codec, unsigned int format,
 		return err;
 	}
 
-	azx_dev->prepared = 0;
+	hstr->prepared = 0;
 	return err;
 }
 EXPORT_SYMBOL_GPL(snd_hda_codec_load_dsp_prepare);
sound/pci/hda/hda_controller.h +0 -1
index 407cba6577b8..173bf7c85b6e 100644
@@ -62,7 +62,6 @@ struct azx_dev {
 	struct hdac_stream core;
 
 	unsigned int irq_pending:1;
-	unsigned int prepared:1;
 	/*
 	 * For VIA:
 	 *  A flag to ensure DMA position is 0
Signature · 1 line
2.3.5
#19 lore raw

PATCH 19/21 ALSA: hda - add ASoC device type for hda core

In reply to Takashi Iwai

From: Ramesh Babu <[email protected]>

Add HDA_DEV_ASOC device/driver type to support
ASoC HDA drivers.

---
 include/sound/hdaudio.h | 1 +
 1 file changed, 1 insertion(+)
include/sound/hdaudio.h +1 -0
index dbeb195eb4e8..d05931fc6f28 100644
@@ -90,6 +90,7 @@ struct hdac_device {
 enum {
 	HDA_DEV_CORE,
 	HDA_DEV_LEGACY,
+	HDA_DEV_ASOC,
 };
 
 /* direction */
Signature · 1 line
2.3.5
#20 lore raw

PATCH 20/21 ALSA: hda - add generic functions to set hdac stream params

In reply to Takashi Iwai

From: Jeeja KP <[email protected]>

This will be used by hda controller driver to setup stream params in prepare. This function will setup the bdl and periods.

---
 include/sound/hdaudio.h |  2 ++
 sound/hda/hdac_stream.c | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)
include/sound/hdaudio.h +2 -0
index d05931fc6f28..6a2e030c836c 100644
@@ -418,6 +418,8 @@ void snd_hdac_stream_release(struct hdac_stream *azx_dev);
 int snd_hdac_stream_setup(struct hdac_stream *azx_dev);
 void snd_hdac_stream_cleanup(struct hdac_stream *azx_dev);
 int snd_hdac_stream_setup_periods(struct hdac_stream *azx_dev);
+int snd_hdac_stream_set_params(struct hdac_stream *azx_dev,
+				unsigned int format_val);
 void snd_hdac_stream_start(struct hdac_stream *azx_dev, bool fresh_start);
 void snd_hdac_stream_clear(struct hdac_stream *azx_dev);
 void snd_hdac_stream_stop(struct hdac_stream *azx_dev);
sound/hda/hdac_stream.c +38 -0
index 9ffff6d9ba8e..1ba0462ef7ca 100644
@@ -394,6 +394,44 @@ int snd_hdac_stream_setup_periods(struct hdac_stream *azx_dev)
 }
 EXPORT_SYMBOL_GPL(snd_hdac_stream_setup_periods);
 
+/* snd_hdac_stream_set_params - set stream parameters
+ * @azx_dev: HD-audio core stream for which parameters are to be set
+ * @format_val: format value parameter
+ *
+ * Setup the HD-audio core stream parameters from substream of the stream
+ * and passed format value
+ */
+int snd_hdac_stream_set_params(struct hdac_stream *azx_dev,
+				 unsigned int format_val)
+{
+
+	unsigned int bufsize, period_bytes;
+	struct snd_pcm_substream *substream = azx_dev->substream;
+	struct snd_pcm_runtime *runtime;
+	int err;
+
+	if (!substream)
+		return -EINVAL;
+	runtime = substream->runtime;
+	bufsize = snd_pcm_lib_buffer_bytes(substream);
+	period_bytes = snd_pcm_lib_period_bytes(substream);
+
+	if (bufsize != azx_dev->bufsize ||
+	    period_bytes != azx_dev->period_bytes ||
+	    format_val != azx_dev->format_val ||
+	    runtime->no_period_wakeup != azx_dev->no_period_wakeup) {
+		azx_dev->bufsize = bufsize;
+		azx_dev->period_bytes = period_bytes;
+		azx_dev->format_val = format_val;
+		azx_dev->no_period_wakeup = runtime->no_period_wakeup;
+		err = snd_hdac_stream_setup_periods(azx_dev);
+		if (err < 0)
+			return err;
+	}
+	return 0;
+}
+EXPORT_SYMBOL_GPL(snd_hdac_stream_set_params);
+
 static cycle_t azx_cc_read(const struct cyclecounter *cc)
 {
 	struct hdac_stream *azx_dev = container_of(cc, struct hdac_stream, cc);
Signature · 1 line
2.3.5
#21 lore raw

PATCH 21/21 ALSA: hda - Replace open codes with snd_hdac_stream_set_params()

In reply to Takashi Iwai
---
 sound/pci/hda/hda_controller.c | 23 ++++-------------------
 1 file changed, 4 insertions(+), 19 deletions(-)
sound/pci/hda/hda_controller.c +4 -19
index 14ffb6bd986c..e0bb6231ff0c 100644
@@ -157,7 +157,7 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
 	struct azx_dev *azx_dev = get_azx_dev(substream);
 	struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream);
 	struct snd_pcm_runtime *runtime = substream->runtime;
-	unsigned int bufsize, period_bytes, format_val, stream_tag;
+	unsigned int format_val, stream_tag;
 	int err;
 	struct hda_spdif_out *spdif =
 		snd_hda_spdif_out_of_nid(apcm->codec, hinfo->nid);
@@ -183,24 +183,9 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
 		goto unlock;
 	}
 
-	bufsize = snd_pcm_lib_buffer_bytes(substream);
-	period_bytes = snd_pcm_lib_period_bytes(substream);
-
-	dev_dbg(chip->card->dev, "azx_pcm_prepare: bufsize=0x%x, format=0x%x\n",
-		bufsize, format_val);
-
-	if (bufsize != azx_dev->core.bufsize ||
-	    period_bytes != azx_dev->core.period_bytes ||
-	    format_val != azx_dev->core.format_val ||
-	    runtime->no_period_wakeup != azx_dev->core.no_period_wakeup) {
-		azx_dev->core.bufsize = bufsize;
-		azx_dev->core.period_bytes = period_bytes;
-		azx_dev->core.format_val = format_val;
-		azx_dev->core.no_period_wakeup = runtime->no_period_wakeup;
-		err = snd_hdac_stream_setup_periods(azx_stream(azx_dev));
-		if (err < 0)
-			goto unlock;
-	}
+	err = snd_hdac_stream_set_params(azx_stream(azx_dev), format_val);
+	if (err < 0)
+		goto unlock;
 
 	snd_hdac_stream_setup(azx_stream(azx_dev));
 
Signature · 1 line
2.3.5