Commit a41d1224 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: hda - Embed bus into controller object

... 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.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent ccc98865
......@@ -481,78 +481,6 @@ int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid,
return devices;
}
/*
* 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
*/
......
......@@ -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;
......
This diff is collapsed.
......@@ -75,18 +75,6 @@ struct azx_dev {
#define azx_stream(dev) (&(dev)->core)
#define stream_to_azx_dev(s) container_of(s, struct azx_dev, core)
/* CORB/RIRB */
struct azx_rb {
u32 *buf; /* CORB/RIRB buffer
* Each CORB entry is 4byte, RIRB is 8byte
*/
dma_addr_t addr; /* physical address of CORB/RIRB buffer */
/* for RIRB */
unsigned short rp, wp; /* read/write pointers */
int cmds[AZX_MAX_CODECS]; /* number of pending requests */
u32 res[AZX_MAX_CODECS]; /* last read value */
};
struct azx;
/* Functions to read/write to hda registers. */
......@@ -116,6 +104,8 @@ typedef unsigned int (*azx_get_pos_callback_t)(struct azx *, struct azx_dev *);
typedef int (*azx_get_delay_callback_t)(struct azx *, struct azx_dev *, unsigned int pos);
struct azx {
struct hda_bus bus;
struct snd_card *card;
struct pci_dev *pci;
int dev_index;
......@@ -132,38 +122,21 @@ 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];
azx_get_delay_callback_t get_delay[2];
/* pci resources */
unsigned long addr;
void __iomem *remap_addr;
int irq;
/* locks */
spinlock_t reg_lock;
struct mutex open_mutex; /* Prevents concurrent open/close operations */
/* PCM */
struct list_head pcm_list; /* azx_pcm list */
/* HD codec */
unsigned short codec_mask;
int codec_probe_mask; /* copied from probe_mask option */
struct hda_bus *bus;
unsigned int beep_mode;
/* CORB/RIRB */
struct azx_rb corb;
struct azx_rb rirb;
/* CORB/RIRB and position buffers */
struct snd_dma_buffer rb;
struct snd_dma_buffer posbuf;
#ifdef CONFIG_SND_HDA_PATCH_LOADER
const struct firmware *fw;
#endif
......@@ -172,7 +145,6 @@ struct azx {
const int *bdl_pos_adj;
int poll_count;
unsigned int running:1;
unsigned int initialized:1;
unsigned int single_cmd:1;
unsigned int polling_mode:1;
unsigned int msi:1;
......@@ -182,15 +154,13 @@ struct azx {
unsigned int region_requested:1;
unsigned int disabled:1; /* disabled by VGA-switcher */
/* for debugging */
unsigned int last_cmd[AZX_MAX_CODECS];
#ifdef CONFIG_SND_HDA_DSP_LOADER
struct azx_dev saved_azx_dev;
#endif
};
#define azx_bus(chip) (&(chip)->bus->core)
#define azx_bus(chip) (&(chip)->bus.core)
#define bus_to_azx(_bus) container_of(_bus, struct azx, bus.core)
#ifdef CONFIG_X86
#define azx_snoop(chip) ((chip)->snoop)
......@@ -203,17 +173,17 @@ struct azx {
*/
#define azx_writel(chip, reg, value) \
((chip)->io_ops->reg_writel(value, (chip)->remap_addr + AZX_REG_##reg))
snd_hdac_chip_writel(azx_bus(chip), reg, value)
#define azx_readl(chip, reg) \
((chip)->io_ops->reg_readl((chip)->remap_addr + AZX_REG_##reg))
snd_hdac_chip_readl(azx_bus(chip), reg)
#define azx_writew(chip, reg, value) \
((chip)->io_ops->reg_writew(value, (chip)->remap_addr + AZX_REG_##reg))
snd_hdac_chip_writew(azx_bus(chip), reg, value)
#define azx_readw(chip, reg) \
((chip)->io_ops->reg_readw((chip)->remap_addr + AZX_REG_##reg))
snd_hdac_chip_readw(azx_bus(chip), reg)
#define azx_writeb(chip, reg, value) \
((chip)->io_ops->reg_writeb(value, (chip)->remap_addr + AZX_REG_##reg))
snd_hdac_chip_writeb(azx_bus(chip), reg, value)
#define azx_readb(chip, reg) \
((chip)->io_ops->reg_readb((chip)->remap_addr + AZX_REG_##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)
......@@ -244,19 +214,24 @@ unsigned int azx_get_pos_posbuf(struct azx *chip, struct azx_dev *azx_dev);
void azx_stop_all_streams(struct azx *chip);
/* Allocation functions. */
int azx_alloc_stream_pages(struct azx *chip);
void azx_free_stream_pages(struct azx *chip);
#define azx_alloc_stream_pages(chip) \
snd_hdac_bus_alloc_stream_pages(azx_bus(chip))
#define azx_free_stream_pages(chip) \
snd_hdac_bus_free_stream_pages(azx_bus(chip))
/* Low level azx interface */
void azx_init_chip(struct azx *chip, bool full_reset);
void azx_stop_chip(struct azx *chip);
void azx_enter_link_reset(struct azx *chip);
#define azx_enter_link_reset(chip) \
snd_hdac_bus_enter_link_reset(azx_bus(chip))
irqreturn_t azx_interrupt(int irq, void *dev_id);
/* Codec interface */
int azx_bus_create(struct azx *chip, const char *model);
int azx_bus_init(struct azx *chip, const char *model,
const struct hdac_io_ops *io_ops);
int azx_probe_codecs(struct azx *chip, unsigned int max_slots);
int azx_codec_configure(struct azx *chip);
int azx_init_stream(struct azx *chip);
int azx_init_streams(struct azx *chip);
void azx_free_streams(struct azx *chip);
#endif /* __SOUND_HDA_CONTROLLER_H */
This diff is collapsed.
......@@ -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;
......
......@@ -285,6 +285,14 @@ static const struct dev_pm_ops hda_tegra_pm = {
SET_SYSTEM_SLEEP_PM_OPS(hda_tegra_suspend, hda_tegra_resume)
};
static int hda_tegra_dev_disconnect(struct snd_device *device)
{
struct azx *chip = device->device_data;
chip->bus.shutdown = 1;
return 0;
}
/*
* destructor
*/
......@@ -292,12 +300,14 @@ static int hda_tegra_dev_free(struct snd_device *device)
{
struct azx *chip = device->device_data;
if (chip->initialized) {
if (azx_bus(chip)->chip_init) {
azx_stop_all_streams(chip);
azx_stop_chip(chip);
}
azx_free_stream_pages(chip);
azx_free_streams(chip);
snd_hdac_bus_exit(bus);
return 0;
}
......@@ -305,6 +315,7 @@ static int hda_tegra_dev_free(struct snd_device *device)
static int hda_tegra_init_chip(struct azx *chip, struct platform_device *pdev)
{
struct hda_tegra *hda = container_of(chip, struct hda_tegra, chip);
struct hdac_bus *bus = azx_bus(chip);
struct device *dev = hda->dev;
struct resource *res;
int err;
......@@ -324,9 +335,8 @@ static int hda_tegra_init_chip(struct azx *chip, struct platform_device *pdev)
if (IS_ERR(hda->regs))
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;
bus->remap_addr = hda->regs + HDA_BAR0;
bus->addr = res->start + HDA_BAR0;
err = hda_tegra_enable_clocks(hda);
if (err)
......@@ -339,6 +349,7 @@ static int hda_tegra_init_chip(struct azx *chip, struct platform_device *pdev)
static int hda_tegra_first_init(struct azx *chip, struct platform_device *pdev)
{
struct hdac_bus *bus = azx_bus(chip);
struct snd_card *card = chip->card;
int err;
unsigned short gcap;
......@@ -356,9 +367,9 @@ static int hda_tegra_first_init(struct azx *chip, struct platform_device *pdev)
irq_id);
return err;
}
chip->irq = irq_id;
bus->irq = irq_id;
synchronize_irq(chip->irq);
synchronize_irq(bus->irq);
gcap = azx_readw(chip, GCAP);
dev_dbg(card->dev, "chipset global capabilities = 0x%x\n", gcap);
......@@ -377,18 +388,20 @@ static int hda_tegra_first_init(struct azx *chip, struct platform_device *pdev)
chip->playback_index_offset = chip->capture_streams;
chip->num_streams = chip->playback_streams + chip->capture_streams;
err = azx_alloc_stream_pages(chip);
/* initialize streams */
err = azx_init_streams(chip);
if (err < 0)
return err;
/* initialize streams */
azx_init_stream(chip);
err = azx_alloc_stream_pages(chip);
if (err < 0)
return err;
/* initialize chip */
azx_init_chip(chip, 1);
/* codec detection */
if (!chip->codec_mask) {
if (!bus->codec_mask) {
dev_err(card->dev, "no codecs found!\n");
return -ENODEV;
}
......@@ -397,7 +410,7 @@ static int hda_tegra_first_init(struct azx *chip, struct platform_device *pdev)
strcpy(card->shortname, "tegra-hda");
snprintf(card->longname, sizeof(card->longname),
"%s at 0x%lx irq %i",
card->shortname, chip->addr, chip->irq);
card->shortname, bus->addr, bus->irq);
return 0;
}
......@@ -410,6 +423,7 @@ static int hda_tegra_create(struct snd_card *card,
struct hda_tegra *hda)
{
static struct snd_device_ops ops = {
.dev_disconnect = hda_tegra_dev_disconnect,
.dev_free = hda_tegra_dev_free,
};
struct azx *chip;
......@@ -417,12 +431,9 @@ static int hda_tegra_create(struct snd_card *card,
chip = &hda->chip;
spin_lock_init(&chip->reg_lock);
mutex_init(&chip->open_mutex);
chip->card = card;
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;
chip->dev_index = 0;
......@@ -469,7 +480,7 @@ static int hda_tegra_probe(struct platform_device *pdev)
return err;
}
err = azx_bus_create(chip, NULL);
err = azx_bus_init(chip, NULL, &hda_tegra_io_ops);
if (err < 0)
goto out_free;
......@@ -498,7 +509,7 @@ static int hda_tegra_probe(struct platform_device *pdev)
goto out_free;
chip->running = 1;
snd_hda_set_power_save(chip->bus, power_save * 1000);
snd_hda_set_power_save(&chip->bus, power_save * 1000);
return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment