aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/hda/hda_codec.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2014-02-25 01:53:47 -0500
committerTakashi Iwai <tiwai@suse.de>2014-02-25 06:12:54 -0500
commit13aeaf68019d297be79c99f828c2a9d6affef06b (patch)
treeb3f2946b2f335fa4f7c13c68e199d980279d1e5b /sound/pci/hda/hda_codec.c
parent2565c89908850337940d1f55dd015f229788de1e (diff)
ALSA: hda - Create own device struct for each codec
As the HD-audio is treated individually in each codec driver, it's more convenient to assign an own struct device to each codec object. Then we'll be able to use dev_err() more easily for each codec, for example. For achieving it, this patch just creates an object "hdaudioCxDy". It belongs to sound class instead of creating a new bus, just for simplicity, at this stage. No pm ops is implemented in the device struct level but currently it's merely a container. The PCM and hwdep devices are now children of this codec device. Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci/hda/hda_codec.c')
-rw-r--r--sound/pci/hda/hda_codec.c36
1 files changed, 33 insertions, 3 deletions
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 5ea1156954ab..98baf5674a63 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -1368,7 +1368,7 @@ static void snd_hda_codec_free(struct hda_codec *codec)
1368 kfree(codec->modelname); 1368 kfree(codec->modelname);
1369 kfree(codec->wcaps); 1369 kfree(codec->wcaps);
1370 codec->bus->num_codecs--; 1370 codec->bus->num_codecs--;
1371 kfree(codec); 1371 put_device(&codec->dev);
1372} 1372}
1373 1373
1374static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec, 1374static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec,
@@ -1377,12 +1377,33 @@ static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec,
1377static unsigned int hda_set_power_state(struct hda_codec *codec, 1377static unsigned int hda_set_power_state(struct hda_codec *codec,
1378 unsigned int power_state); 1378 unsigned int power_state);
1379 1379
1380static int snd_hda_codec_dev_register(struct snd_device *device)
1381{
1382 struct hda_codec *codec = device->device_data;
1383
1384 return device_add(&codec->dev);
1385}
1386
1387static int snd_hda_codec_dev_disconnect(struct snd_device *device)
1388{
1389 struct hda_codec *codec = device->device_data;
1390
1391 device_del(&codec->dev);
1392 return 0;
1393}
1394
1380static int snd_hda_codec_dev_free(struct snd_device *device) 1395static int snd_hda_codec_dev_free(struct snd_device *device)
1381{ 1396{
1382 snd_hda_codec_free(device->device_data); 1397 snd_hda_codec_free(device->device_data);
1383 return 0; 1398 return 0;
1384} 1399}
1385 1400
1401/* just free the container */
1402static void snd_hda_codec_dev_release(struct device *dev)
1403{
1404 kfree(container_of(dev, struct hda_codec, dev));
1405}
1406
1386/** 1407/**
1387 * snd_hda_codec_new - create a HDA codec 1408 * snd_hda_codec_new - create a HDA codec
1388 * @bus: the bus to assign 1409 * @bus: the bus to assign
@@ -1400,6 +1421,8 @@ int snd_hda_codec_new(struct hda_bus *bus,
1400 hda_nid_t fg; 1421 hda_nid_t fg;
1401 int err; 1422 int err;
1402 static struct snd_device_ops dev_ops = { 1423 static struct snd_device_ops dev_ops = {
1424 .dev_register = snd_hda_codec_dev_register,
1425 .dev_disconnect = snd_hda_codec_dev_disconnect,
1403 .dev_free = snd_hda_codec_dev_free, 1426 .dev_free = snd_hda_codec_dev_free,
1404 }; 1427 };
1405 1428
@@ -1420,6 +1443,13 @@ int snd_hda_codec_new(struct hda_bus *bus,
1420 return -ENOMEM; 1443 return -ENOMEM;
1421 } 1444 }
1422 1445
1446 device_initialize(&codec->dev);
1447 codec->dev.parent = &bus->card->card_dev;
1448 codec->dev.class = sound_class;
1449 codec->dev.release = snd_hda_codec_dev_release;
1450 dev_set_name(&codec->dev, "hdaudioC%dD%d", bus->card->number,
1451 codec_addr);
1452
1423 codec->bus = bus; 1453 codec->bus = bus;
1424 codec->addr = codec_addr; 1454 codec->addr = codec_addr;
1425 mutex_init(&codec->spdif_mutex); 1455 mutex_init(&codec->spdif_mutex);
@@ -1453,8 +1483,8 @@ int snd_hda_codec_new(struct hda_bus *bus,
1453 if (codec->bus->modelname) { 1483 if (codec->bus->modelname) {
1454 codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL); 1484 codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL);
1455 if (!codec->modelname) { 1485 if (!codec->modelname) {
1456 snd_hda_codec_free(codec); 1486 err = -ENODEV;
1457 return -ENODEV; 1487 goto error;
1458 } 1488 }
1459 } 1489 }
1460 1490