diff options
author | Takashi Iwai <tiwai@suse.de> | 2014-02-25 01:53:47 -0500 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2014-02-25 06:12:54 -0500 |
commit | 13aeaf68019d297be79c99f828c2a9d6affef06b (patch) | |
tree | b3f2946b2f335fa4f7c13c68e199d980279d1e5b | |
parent | 2565c89908850337940d1f55dd015f229788de1e (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>
-rw-r--r-- | sound/pci/hda/hda_codec.c | 36 | ||||
-rw-r--r-- | sound/pci/hda/hda_codec.h | 1 | ||||
-rw-r--r-- | sound/pci/hda/hda_hwdep.c | 3 | ||||
-rw-r--r-- | sound/pci/hda/hda_intel.c | 2 |
4 files changed, 39 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 | ||
1374 | static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec, | 1374 | static 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, | |||
1377 | static unsigned int hda_set_power_state(struct hda_codec *codec, | 1377 | static unsigned int hda_set_power_state(struct hda_codec *codec, |
1378 | unsigned int power_state); | 1378 | unsigned int power_state); |
1379 | 1379 | ||
1380 | static 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 | |||
1387 | static 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 | |||
1380 | static int snd_hda_codec_dev_free(struct snd_device *device) | 1395 | static 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 */ | ||
1402 | static 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 | ||
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index ab2a444ba501..4d9dd2b70f4a 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h | |||
@@ -271,6 +271,7 @@ struct hda_pcm { | |||
271 | 271 | ||
272 | /* codec information */ | 272 | /* codec information */ |
273 | struct hda_codec { | 273 | struct hda_codec { |
274 | struct device dev; | ||
274 | struct hda_bus *bus; | 275 | struct hda_bus *bus; |
275 | unsigned int addr; /* codec addr*/ | 276 | unsigned int addr; /* codec addr*/ |
276 | struct list_head list; /* list point */ | 277 | struct list_head list; /* list point */ |
diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c index 0fada0f8cfe8..896d116ca951 100644 --- a/sound/pci/hda/hda_hwdep.c +++ b/sound/pci/hda/hda_hwdep.c | |||
@@ -155,6 +155,9 @@ int snd_hda_create_hwdep(struct hda_codec *codec) | |||
155 | snd_array_init(&codec->hints, sizeof(struct hda_hint), 32); | 155 | snd_array_init(&codec->hints, sizeof(struct hda_hint), 32); |
156 | snd_array_init(&codec->user_pins, sizeof(struct hda_pincfg), 16); | 156 | snd_array_init(&codec->user_pins, sizeof(struct hda_pincfg), 16); |
157 | 157 | ||
158 | /* link to codec */ | ||
159 | hwdep->dev = &codec->dev; | ||
160 | |||
158 | return 0; | 161 | return 0; |
159 | } | 162 | } |
160 | 163 | ||
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index 0870f5f3ed1c..459f54da8d6b 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c | |||
@@ -2663,6 +2663,8 @@ azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec, | |||
2663 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, | 2663 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, |
2664 | snd_dma_pci_data(chip->pci), | 2664 | snd_dma_pci_data(chip->pci), |
2665 | size, MAX_PREALLOC_SIZE); | 2665 | size, MAX_PREALLOC_SIZE); |
2666 | /* link to codec */ | ||
2667 | pcm->dev = &codec->dev; | ||
2666 | return 0; | 2668 | return 0; |
2667 | } | 2669 | } |
2668 | 2670 | ||