Commit 6efdd851 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: hda - Add card field to hda_codec struct

Allow the codec object to have an individual card pointer.  Not only
this simplifies the redirections in many places, also this will allow
us to make each codec assigned to a different card object.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 1a4ba30c
...@@ -160,7 +160,7 @@ static int snd_hda_do_attach(struct hda_beep *beep) ...@@ -160,7 +160,7 @@ static int snd_hda_do_attach(struct hda_beep *beep)
input_dev->name = "HDA Digital PCBeep"; input_dev->name = "HDA Digital PCBeep";
input_dev->phys = beep->phys; input_dev->phys = beep->phys;
input_dev->id.bustype = BUS_PCI; 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.vendor = codec->vendor_id >> 16;
input_dev->id.product = codec->vendor_id & 0xffff; input_dev->id.product = codec->vendor_id & 0xffff;
...@@ -224,7 +224,7 @@ int snd_hda_attach_beep_device(struct hda_codec *codec, int nid) ...@@ -224,7 +224,7 @@ int snd_hda_attach_beep_device(struct hda_codec *codec, int nid)
if (beep == NULL) if (beep == NULL)
return -ENOMEM; return -ENOMEM;
snprintf(beep->phys, sizeof(beep->phys), 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 */ /* enable linear scale */
snd_hda_codec_write_cache(codec, nid, 0, snd_hda_codec_write_cache(codec, nid, 0,
AC_VERB_SET_DIGI_CONVERT_2, 0x01); AC_VERB_SET_DIGI_CONVERT_2, 0x01);
......
...@@ -287,9 +287,9 @@ int snd_hda_codec_configure(struct hda_codec *codec) ...@@ -287,9 +287,9 @@ int snd_hda_codec_configure(struct hda_codec *codec)
} }
/* audio codec should override the mixer name */ /* audio codec should override the mixer name */
if (codec->afg || !*codec->bus->card->mixername) if (codec->afg || !*codec->card->mixername)
snprintf(codec->bus->card->mixername, snprintf(codec->card->mixername,
sizeof(codec->bus->card->mixername), sizeof(codec->card->mixername),
"%s %s", codec->vendor_name, codec->chip_name); "%s %s", codec->vendor_name, codec->chip_name);
return 0; return 0;
......
...@@ -1196,9 +1196,8 @@ static void snd_hda_codec_dev_release(struct device *dev) ...@@ -1196,9 +1196,8 @@ static void snd_hda_codec_dev_release(struct device *dev)
* *
* Returns 0 if successful, or a negative error code. * Returns 0 if successful, or a negative error code.
*/ */
int snd_hda_codec_new(struct hda_bus *bus, int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card,
unsigned int codec_addr, unsigned int codec_addr, struct hda_codec **codecp)
struct hda_codec **codecp)
{ {
struct hda_codec *codec; struct hda_codec *codec;
struct device *dev; struct device *dev;
...@@ -1217,7 +1216,7 @@ int snd_hda_codec_new(struct hda_bus *bus, ...@@ -1217,7 +1216,7 @@ int snd_hda_codec_new(struct hda_bus *bus,
return -EINVAL; return -EINVAL;
if (bus->caddr_tbl[codec_addr]) { if (bus->caddr_tbl[codec_addr]) {
dev_err(bus->card->dev, dev_err(card->dev,
"address 0x%x is already occupied\n", "address 0x%x is already occupied\n",
codec_addr); codec_addr);
return -EBUSY; return -EBUSY;
...@@ -1225,21 +1224,22 @@ int snd_hda_codec_new(struct hda_bus *bus, ...@@ -1225,21 +1224,22 @@ int snd_hda_codec_new(struct hda_bus *bus,
codec = kzalloc(sizeof(*codec), GFP_KERNEL); codec = kzalloc(sizeof(*codec), GFP_KERNEL);
if (codec == NULL) { if (codec == NULL) {
dev_err(bus->card->dev, "can't allocate struct hda_codec\n"); dev_err(card->dev, "can't allocate struct hda_codec\n");
return -ENOMEM; return -ENOMEM;
} }
dev = hda_codec_dev(codec); dev = hda_codec_dev(codec);
device_initialize(dev); device_initialize(dev);
dev->parent = bus->card->dev; dev->parent = card->dev;
dev->bus = &snd_hda_bus_type; dev->bus = &snd_hda_bus_type;
dev->release = snd_hda_codec_dev_release; dev->release = snd_hda_codec_dev_release;
dev->groups = snd_hda_dev_attr_groups; dev->groups = snd_hda_dev_attr_groups;
dev_set_name(dev, "hdaudioC%dD%d", bus->card->number, codec_addr); dev_set_name(dev, "hdaudioC%dD%d", card->number, codec_addr);
dev_set_drvdata(dev, codec); /* for sysfs */ dev_set_drvdata(dev, codec); /* for sysfs */
device_enable_async_suspend(dev); device_enable_async_suspend(dev);
codec->bus = bus; codec->bus = bus;
codec->card = card;
codec->addr = codec_addr; codec->addr = codec_addr;
mutex_init(&codec->spdif_mutex); mutex_init(&codec->spdif_mutex);
mutex_init(&codec->control_mutex); mutex_init(&codec->control_mutex);
...@@ -1300,7 +1300,7 @@ int snd_hda_codec_new(struct hda_bus *bus, ...@@ -1300,7 +1300,7 @@ int snd_hda_codec_new(struct hda_bus *bus,
setup_fg_nodes(codec); setup_fg_nodes(codec);
if (!codec->afg && !codec->mfg) { if (!codec->afg && !codec->mfg) {
dev_err(bus->card->dev, "no AFG or MFG node found\n"); dev_err(card->dev, "no AFG or MFG node found\n");
err = -ENODEV; err = -ENODEV;
goto error; goto error;
} }
...@@ -1308,7 +1308,7 @@ int snd_hda_codec_new(struct hda_bus *bus, ...@@ -1308,7 +1308,7 @@ int snd_hda_codec_new(struct hda_bus *bus,
fg = codec->afg ? codec->afg : codec->mfg; fg = codec->afg ? codec->afg : codec->mfg;
err = read_widget_caps(codec, fg); err = read_widget_caps(codec, fg);
if (err < 0) { if (err < 0) {
dev_err(bus->card->dev, "cannot malloc\n"); dev_err(card->dev, "cannot malloc\n");
goto error; goto error;
} }
err = read_pin_defaults(codec); err = read_pin_defaults(codec);
...@@ -1337,9 +1337,9 @@ int snd_hda_codec_new(struct hda_bus *bus, ...@@ -1337,9 +1337,9 @@ int snd_hda_codec_new(struct hda_bus *bus,
sprintf(component, "HDA:%08x,%08x,%08x", codec->vendor_id, sprintf(component, "HDA:%08x,%08x,%08x", codec->vendor_id,
codec->subsystem_id, codec->revision_id); codec->subsystem_id, codec->revision_id);
snd_component_add(codec->bus->card, component); snd_component_add(card, component);
err = snd_device_new(bus->card, SNDRV_DEV_CODEC, codec, &dev_ops); err = snd_device_new(card, SNDRV_DEV_CODEC, codec, &dev_ops);
if (err < 0) if (err < 0)
goto error; goto error;
...@@ -2237,7 +2237,7 @@ find_mixer_ctl(struct hda_codec *codec, const char *name, int dev, int idx) ...@@ -2237,7 +2237,7 @@ find_mixer_ctl(struct hda_codec *codec, const char *name, int dev, int idx)
if (snd_BUG_ON(strlen(name) >= sizeof(id.name))) if (snd_BUG_ON(strlen(name) >= sizeof(id.name)))
return NULL; return NULL;
strcpy(id.name, name); strcpy(id.name, name);
return snd_ctl_find_id(codec->bus->card, &id); return snd_ctl_find_id(codec->card, &id);
} }
/** /**
...@@ -2301,7 +2301,7 @@ int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid, ...@@ -2301,7 +2301,7 @@ int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
nid = kctl->id.subdevice & 0xffff; nid = kctl->id.subdevice & 0xffff;
if (kctl->id.subdevice & (HDA_SUBDEV_NID_FLAG|HDA_SUBDEV_AMP_FLAG)) if (kctl->id.subdevice & (HDA_SUBDEV_NID_FLAG|HDA_SUBDEV_AMP_FLAG))
kctl->id.subdevice = 0; kctl->id.subdevice = 0;
err = snd_ctl_add(codec->bus->card, kctl); err = snd_ctl_add(codec->card, kctl);
if (err < 0) if (err < 0)
return err; return err;
item = snd_array_new(&codec->mixers); item = snd_array_new(&codec->mixers);
...@@ -2354,7 +2354,7 @@ void snd_hda_ctls_clear(struct hda_codec *codec) ...@@ -2354,7 +2354,7 @@ void snd_hda_ctls_clear(struct hda_codec *codec)
int i; int i;
struct hda_nid_item *items = codec->mixers.list; struct hda_nid_item *items = codec->mixers.list;
for (i = 0; i < codec->mixers.used; i++) for (i = 0; i < codec->mixers.used; i++)
snd_ctl_remove(codec->bus->card, items[i].kctl); snd_ctl_remove(codec->card, items[i].kctl);
snd_array_free(&codec->mixers); snd_array_free(&codec->mixers);
snd_array_free(&codec->nids); snd_array_free(&codec->nids);
} }
...@@ -2427,7 +2427,7 @@ EXPORT_SYMBOL_GPL(snd_hda_unlock_devices); ...@@ -2427,7 +2427,7 @@ EXPORT_SYMBOL_GPL(snd_hda_unlock_devices);
int snd_hda_codec_reset(struct hda_codec *codec) int snd_hda_codec_reset(struct hda_codec *codec)
{ {
struct hda_bus *bus = codec->bus; struct hda_bus *bus = codec->bus;
struct snd_card *card = bus->card; struct snd_card *card = codec->card;
int i; int i;
if (snd_hda_lock_devices(bus) < 0) if (snd_hda_lock_devices(bus) < 0)
......
...@@ -274,6 +274,7 @@ struct hda_pcm { ...@@ -274,6 +274,7 @@ struct hda_pcm {
struct hda_codec { struct hda_codec {
struct device dev; struct device dev;
struct hda_bus *bus; struct hda_bus *bus;
struct snd_card *card;
unsigned int addr; /* codec addr*/ unsigned int addr; /* codec addr*/
struct list_head list; /* list point */ struct list_head list; /* list point */
...@@ -420,8 +421,8 @@ enum { ...@@ -420,8 +421,8 @@ enum {
* constructors * constructors
*/ */
int snd_hda_bus_new(struct snd_card *card, struct hda_bus **busp); int snd_hda_bus_new(struct snd_card *card, struct hda_bus **busp);
int snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr, int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card,
struct hda_codec **codecp); unsigned int codec_addr, struct hda_codec **codecp);
int snd_hda_codec_configure(struct hda_codec *codec); int snd_hda_codec_configure(struct hda_codec *codec);
int snd_hda_codec_update_widgets(struct hda_codec *codec); int snd_hda_codec_update_widgets(struct hda_codec *codec);
......
...@@ -1898,7 +1898,7 @@ int azx_probe_codecs(struct azx *chip, unsigned int max_slots) ...@@ -1898,7 +1898,7 @@ int azx_probe_codecs(struct azx *chip, unsigned int max_slots)
for (c = 0; c < max_slots; c++) { for (c = 0; c < max_slots; c++) {
if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) { if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) {
struct hda_codec *codec; struct hda_codec *codec;
err = snd_hda_codec_new(bus, c, &codec); err = snd_hda_codec_new(bus, bus->card, c, &codec);
if (err < 0) if (err < 0)
continue; continue;
codec->jackpoll_interval = get_jackpoll_interval(chip); codec->jackpoll_interval = get_jackpoll_interval(chip);
......
...@@ -101,7 +101,7 @@ int snd_hda_create_hwdep(struct hda_codec *codec) ...@@ -101,7 +101,7 @@ int snd_hda_create_hwdep(struct hda_codec *codec)
int err; int err;
sprintf(hwname, "HDA Codec %d", codec->addr); sprintf(hwname, "HDA Codec %d", codec->addr);
err = snd_hwdep_new(codec->bus->card, hwname, codec->addr, &hwdep); err = snd_hwdep_new(codec->card, hwname, codec->addr, &hwdep);
if (err < 0) if (err < 0)
return err; return err;
codec->hwdep = hwdep; codec->hwdep = hwdep;
......
...@@ -135,7 +135,7 @@ void snd_hda_jack_tbl_clear(struct hda_codec *codec) ...@@ -135,7 +135,7 @@ void snd_hda_jack_tbl_clear(struct hda_codec *codec)
#ifdef CONFIG_SND_HDA_INPUT_JACK #ifdef CONFIG_SND_HDA_INPUT_JACK
/* free jack instances manually when clearing/reconfiguring */ /* free jack instances manually when clearing/reconfiguring */
if (!codec->bus->shutdown && jack->jack) if (!codec->bus->shutdown && jack->jack)
snd_device_free(codec->bus->card, jack->jack); snd_device_free(codec->card, jack->jack);
#endif #endif
for (cb = jack->callback; cb; cb = next) { for (cb = jack->callback; cb; cb = next) {
next = cb->next; next = cb->next;
...@@ -340,7 +340,7 @@ void snd_hda_jack_report_sync(struct hda_codec *codec) ...@@ -340,7 +340,7 @@ void snd_hda_jack_report_sync(struct hda_codec *codec)
if (!jack->kctl || jack->block_report) if (!jack->kctl || jack->block_report)
continue; continue;
state = get_jack_plug_state(jack->pin_sense); state = get_jack_plug_state(jack->pin_sense);
snd_kctl_jack_report(codec->bus->card, jack->kctl, state); snd_kctl_jack_report(codec->card, jack->kctl, state);
#ifdef CONFIG_SND_HDA_INPUT_JACK #ifdef CONFIG_SND_HDA_INPUT_JACK
if (jack->jack) if (jack->jack)
snd_jack_report(jack->jack, snd_jack_report(jack->jack,
...@@ -412,11 +412,11 @@ static int __snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid, ...@@ -412,11 +412,11 @@ static int __snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid,
jack->phantom_jack = !!phantom_jack; jack->phantom_jack = !!phantom_jack;
state = snd_hda_jack_detect(codec, nid); state = snd_hda_jack_detect(codec, nid);
snd_kctl_jack_report(codec->bus->card, kctl, state); snd_kctl_jack_report(codec->card, kctl, state);
#ifdef CONFIG_SND_HDA_INPUT_JACK #ifdef CONFIG_SND_HDA_INPUT_JACK
if (!phantom_jack) { if (!phantom_jack) {
jack->type = get_input_jack_type(codec, nid); jack->type = get_input_jack_type(codec, nid);
err = snd_jack_new(codec->bus->card, name, jack->type, err = snd_jack_new(codec->card, name, jack->type,
&jack->jack); &jack->jack);
if (err < 0) if (err < 0)
return err; return err;
......
...@@ -839,7 +839,7 @@ int snd_hda_codec_proc_new(struct hda_codec *codec) ...@@ -839,7 +839,7 @@ int snd_hda_codec_proc_new(struct hda_codec *codec)
int err; int err;
snprintf(name, sizeof(name), "codec#%d", codec->addr); snprintf(name, sizeof(name), "codec#%d", codec->addr);
err = snd_card_proc_new(codec->bus->card, name, &entry); err = snd_card_proc_new(codec->card, name, &entry);
if (err < 0) if (err < 0)
return err; return err;
......
...@@ -149,7 +149,7 @@ static int reconfig_codec(struct hda_codec *codec) ...@@ -149,7 +149,7 @@ static int reconfig_codec(struct hda_codec *codec)
err = snd_hda_codec_build_controls(codec); err = snd_hda_codec_build_controls(codec);
if (err < 0) if (err < 0)
goto error; goto error;
err = snd_card_register(codec->bus->card); err = snd_card_register(codec->card);
error: error:
snd_hda_power_down(codec); snd_hda_power_down(codec);
return err; return err;
......
...@@ -23,7 +23,7 @@ DECLARE_EVENT_CLASS(hda_cmd, ...@@ -23,7 +23,7 @@ DECLARE_EVENT_CLASS(hda_cmd,
), ),
TP_fast_assign( TP_fast_assign(
__entry->card = (codec)->bus->card->number; __entry->card = (codec)->card->number;
__entry->addr = (codec)->addr; __entry->addr = (codec)->addr;
__entry->val = (val); __entry->val = (val);
), ),
...@@ -71,7 +71,7 @@ DECLARE_EVENT_CLASS(hda_power, ...@@ -71,7 +71,7 @@ DECLARE_EVENT_CLASS(hda_power,
), ),
TP_fast_assign( TP_fast_assign(
__entry->card = (codec)->bus->card->number; __entry->card = (codec)->card->number;
__entry->addr = (codec)->addr; __entry->addr = (codec)->addr;
), ),
......
...@@ -4352,7 +4352,7 @@ static bool ca0132_download_dsp_images(struct hda_codec *codec) ...@@ -4352,7 +4352,7 @@ static bool ca0132_download_dsp_images(struct hda_codec *codec)
const struct dsp_image_seg *dsp_os_image; const struct dsp_image_seg *dsp_os_image;
const struct firmware *fw_entry; const struct firmware *fw_entry;
if (request_firmware(&fw_entry, EFX_FILE, codec->bus->card->dev) != 0) if (request_firmware(&fw_entry, EFX_FILE, codec->card->dev) != 0)
return false; return false;
dsp_os_image = (struct dsp_image_seg *)(fw_entry->data); dsp_os_image = (struct dsp_image_seg *)(fw_entry->data);
......
...@@ -579,7 +579,7 @@ static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index) ...@@ -579,7 +579,7 @@ static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index)
int err; int err;
snprintf(name, sizeof(name), "eld#%d.%d", codec->addr, index); snprintf(name, sizeof(name), "eld#%d.%d", codec->addr, index);
err = snd_card_proc_new(codec->bus->card, name, &entry); err = snd_card_proc_new(codec->card, name, &entry);
if (err < 0) if (err < 0)
return err; return err;
...@@ -594,7 +594,7 @@ static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index) ...@@ -594,7 +594,7 @@ static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index)
static void eld_proc_free(struct hdmi_spec_per_pin *per_pin) static void eld_proc_free(struct hdmi_spec_per_pin *per_pin)
{ {
if (!per_pin->codec->bus->shutdown && per_pin->proc_entry) { if (!per_pin->codec->bus->shutdown && per_pin->proc_entry) {
snd_device_free(per_pin->codec->bus->card, per_pin->proc_entry); snd_device_free(per_pin->codec->card, per_pin->proc_entry);
per_pin->proc_entry = NULL; per_pin->proc_entry = NULL;
} }
} }
...@@ -1624,7 +1624,7 @@ static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll) ...@@ -1624,7 +1624,7 @@ static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
} }
if (eld_changed) if (eld_changed)
snd_ctl_notify(codec->bus->card, snd_ctl_notify(codec->card,
SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO, SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO,
&per_pin->eld_ctl->id); &per_pin->eld_ctl->id);
unlock: unlock:
......
...@@ -907,16 +907,16 @@ static int patch_vt1708S(struct hda_codec *codec) ...@@ -907,16 +907,16 @@ static int patch_vt1708S(struct hda_codec *codec)
if (get_codec_type(codec) == VT1708BCE) { if (get_codec_type(codec) == VT1708BCE) {
kfree(codec->chip_name); kfree(codec->chip_name);
codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL); codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
snprintf(codec->bus->card->mixername, snprintf(codec->card->mixername,
sizeof(codec->bus->card->mixername), sizeof(codec->card->mixername),
"%s %s", codec->vendor_name, codec->chip_name); "%s %s", codec->vendor_name, codec->chip_name);
} }
/* correct names for VT1705 */ /* correct names for VT1705 */
if (codec->vendor_id == 0x11064397) { if (codec->vendor_id == 0x11064397) {
kfree(codec->chip_name); kfree(codec->chip_name);
codec->chip_name = kstrdup("VT1705", GFP_KERNEL); codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
snprintf(codec->bus->card->mixername, snprintf(codec->card->mixername,
sizeof(codec->bus->card->mixername), sizeof(codec->card->mixername),
"%s %s", codec->vendor_name, codec->chip_name); "%s %s", codec->vendor_name, codec->chip_name);
} }
......
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