Skip to content

Commit

Permalink
ALSA: hda - Embed bus into controller object
Browse files Browse the repository at this point in the history
... 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: Takashi Iwai <tiwai@suse.de>
  • Loading branch information
tiwai committed Apr 16, 2015
1 parent ccc9886 commit a41d122
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 646 deletions.
72 changes: 0 additions & 72 deletions sound/pci/hda/hda_codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
3 changes: 0 additions & 3 deletions sound/pci/hda/hda_codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a41d122

Please sign in to comment.