Skip to content

Commit

Permalink
Merge branch 'topic/hda-unbind' into for-next
Browse files Browse the repository at this point in the history
  • Loading branch information
Takashi Iwai committed Mar 16, 2015
2 parents 8f88f02 + b2a0baf commit 2a557a8
Show file tree
Hide file tree
Showing 24 changed files with 420 additions and 464 deletions.
3 changes: 2 additions & 1 deletion include/sound/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ int snd_device_new(struct snd_card *card, enum snd_device_type type,
void *device_data, struct snd_device_ops *ops);
int snd_device_register(struct snd_card *card, void *device_data);
int snd_device_register_all(struct snd_card *card);
int snd_device_disconnect_all(struct snd_card *card);
void snd_device_disconnect(struct snd_card *card, void *device_data);
void snd_device_disconnect_all(struct snd_card *card);
void snd_device_free(struct snd_card *card, void *device_data);
void snd_device_free_all(struct snd_card *card);

Expand Down
43 changes: 33 additions & 10 deletions sound/core/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,14 @@ int snd_device_new(struct snd_card *card, enum snd_device_type type,
}
EXPORT_SYMBOL(snd_device_new);

static int __snd_device_disconnect(struct snd_device *dev)
static void __snd_device_disconnect(struct snd_device *dev)
{
if (dev->state == SNDRV_DEV_REGISTERED) {
if (dev->ops->dev_disconnect &&
dev->ops->dev_disconnect(dev))
dev_err(dev->card->dev, "device disconnect failure\n");
dev->state = SNDRV_DEV_DISCONNECTED;
}
return 0;
}

static void __snd_device_free(struct snd_device *dev)
Expand All @@ -106,6 +105,34 @@ static struct snd_device *look_for_dev(struct snd_card *card, void *device_data)
return NULL;
}

/**
* snd_device_disconnect - disconnect the device
* @card: the card instance
* @device_data: the data pointer to disconnect
*
* Turns the device into the disconnection state, invoking
* dev_disconnect callback, if the device was already registered.
*
* Usually called from snd_card_disconnect().
*
* Return: Zero if successful, or a negative error code on failure or if the
* device not found.
*/
void snd_device_disconnect(struct snd_card *card, void *device_data)
{
struct snd_device *dev;

if (snd_BUG_ON(!card || !device_data))
return;
dev = look_for_dev(card, device_data);
if (dev)
__snd_device_disconnect(dev);
else
dev_dbg(card->dev, "device disconnect %p (from %pF), not found\n",
device_data, __builtin_return_address(0));
}
EXPORT_SYMBOL_GPL(snd_device_disconnect);

/**
* snd_device_free - release the device from the card
* @card: the card instance
Expand Down Expand Up @@ -193,18 +220,14 @@ int snd_device_register_all(struct snd_card *card)
* disconnect all the devices on the card.
* called from init.c
*/
int snd_device_disconnect_all(struct snd_card *card)
void snd_device_disconnect_all(struct snd_card *card)
{
struct snd_device *dev;
int err = 0;

if (snd_BUG_ON(!card))
return -ENXIO;
list_for_each_entry_reverse(dev, &card->devices, list) {
if (__snd_device_disconnect(dev) < 0)
err = -ENXIO;
}
return err;
return;
list_for_each_entry_reverse(dev, &card->devices, list)
__snd_device_disconnect(dev);
}

/*
Expand Down
5 changes: 1 addition & 4 deletions sound/core/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ static const struct file_operations snd_shutdown_f_ops =
int snd_card_disconnect(struct snd_card *card)
{
struct snd_monitor_file *mfile;
int err;

if (!card)
return -EINVAL;
Expand Down Expand Up @@ -445,9 +444,7 @@ int snd_card_disconnect(struct snd_card *card)
#endif

/* notify all devices that we are disconnected */
err = snd_device_disconnect_all(card);
if (err < 0)
dev_err(card->dev, "not all devices for card %i can be disconnected\n", card->number);
snd_device_disconnect_all(card);

snd_info_card_disconnect(card);
if (card->registered) {
Expand Down
4 changes: 2 additions & 2 deletions sound/pci/hda/hda_beep.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ static int snd_hda_do_attach(struct hda_beep *beep)
input_dev->name = "HDA Digital PCBeep";
input_dev->phys = beep->phys;
input_dev->id.bustype = BUS_PCI;
input_dev->dev.parent = &codec->bus->card->card_dev;
input_dev->dev.parent = &codec->card->card_dev;

input_dev->id.vendor = codec->vendor_id >> 16;
input_dev->id.product = codec->vendor_id & 0xffff;
Expand Down Expand Up @@ -224,7 +224,7 @@ int snd_hda_attach_beep_device(struct hda_codec *codec, int nid)
if (beep == NULL)
return -ENOMEM;
snprintf(beep->phys, sizeof(beep->phys),
"card%d/codec#%d/beep0", codec->bus->card->number, codec->addr);
"card%d/codec#%d/beep0", codec->card->number, codec->addr);
/* enable linear scale */
snd_hda_codec_write_cache(codec, nid, 0,
AC_VERB_SET_DIGI_CONVERT_2, 0x01);
Expand Down
41 changes: 31 additions & 10 deletions sound/pci/hda/hda_bind.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <linux/module.h>
#include <linux/export.h>
#include <linux/pm.h>
#include <linux/pm_runtime.h>
#include <sound/core.h>
#include "hda_codec.h"
#include "hda_local.h"
Expand Down Expand Up @@ -106,16 +107,28 @@ static int hda_codec_driver_probe(struct device *dev)
}

err = codec->preset->patch(codec);
if (err < 0) {
module_put(owner);
goto error;
if (err < 0)
goto error_module;

err = snd_hda_codec_build_pcms(codec);
if (err < 0)
goto error_module;
err = snd_hda_codec_build_controls(codec);
if (err < 0)
goto error_module;
if (codec->card->registered) {
err = snd_card_register(codec->card);
if (err < 0)
goto error_module;
}

return 0;

error_module:
module_put(owner);

error:
codec->preset = NULL;
memset(&codec->patch_ops, 0, sizeof(codec->patch_ops));
snd_hda_codec_cleanup_for_unbind(codec);
return err;
}

Expand All @@ -125,12 +138,19 @@ static int hda_codec_driver_remove(struct device *dev)

if (codec->patch_ops.free)
codec->patch_ops.free(codec);
codec->preset = NULL;
memset(&codec->patch_ops, 0, sizeof(codec->patch_ops));
snd_hda_codec_cleanup_for_unbind(codec);
module_put(dev->driver->owner);
return 0;
}

static void hda_codec_driver_shutdown(struct device *dev)
{
struct hda_codec *codec = dev_to_hda_codec(dev);

if (!pm_runtime_suspended(dev) && codec->patch_ops.reboot_notify)
codec->patch_ops.reboot_notify(codec);
}

int __hda_codec_driver_register(struct hda_codec_driver *drv, const char *name,
struct module *owner)
{
Expand All @@ -139,6 +159,7 @@ int __hda_codec_driver_register(struct hda_codec_driver *drv, const char *name,
drv->driver.bus = &snd_hda_bus_type;
drv->driver.probe = hda_codec_driver_probe;
drv->driver.remove = hda_codec_driver_remove;
drv->driver.shutdown = hda_codec_driver_shutdown;
drv->driver.pm = &hda_codec_driver_pm;
return driver_register(&drv->driver);
}
Expand Down Expand Up @@ -287,9 +308,9 @@ int snd_hda_codec_configure(struct hda_codec *codec)
}

/* audio codec should override the mixer name */
if (codec->afg || !*codec->bus->card->mixername)
snprintf(codec->bus->card->mixername,
sizeof(codec->bus->card->mixername),
if (codec->afg || !*codec->card->mixername)
snprintf(codec->card->mixername,
sizeof(codec->card->mixername),
"%s %s", codec->vendor_name, codec->chip_name);
return 0;

Expand Down
Loading

0 comments on commit 2a557a8

Please sign in to comment.