sound/hda/core/device.c
Source file repositories/reference/linux-study-clean/sound/hda/core/device.c
File Facts
- System
- Linux kernel
- Corpus path
sound/hda/core/device.c- Extension
.c- Size
- 29808 bytes
- Lines
- 1168
- Domain
- Driver Families
- Bucket
- sound/hda
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/init.hlinux/delay.hlinux/device.hlinux/slab.hlinux/module.hlinux/export.hlinux/pm_runtime.hsound/hdaudio.hsound/hda_regmap.hsound/pcm.hsound/pcm_params.hlocal.h
Detected Declarations
struct hda_vendor_idstruct hda_rate_tblfunction default_releasefunction snd_hdac_device_initfunction snd_hdac_device_exitfunction snd_hdac_device_registerfunction snd_hdac_device_unregisterfunction snd_hdac_device_set_chip_namefunction snd_hdac_codec_modaliasfunction snd_hdac_make_cmdfunction snd_hdac_bus_exec_verbfunction snd_hdac_readfunction snd_hdac_read_parmfunction snd_hdac_read_parm_uncachedfunction snd_hdac_override_parmfunction snd_hdac_get_sub_nodesfunction setup_fg_nodesfunction snd_hdac_refresh_widgetsfunction get_num_connsfunction snd_hdac_get_connectionsfunction snd_hdac_power_up_pmfunction snd_hdac_power_downfunction sleeperfunction snd_hdac_keep_power_upfunction snd_hdac_power_up_pmfunction get_codec_vendor_namefunction snd_hdac_format_normalizefunction snd_hdac_stream_format_bitsfunction snd_hdac_stream_formatfunction snd_hdac_spdif_stream_formatfunction query_pcm_paramfunction query_stream_paramfunction snd_hdac_query_supported_pcmfunction snd_hdac_is_supported_formatfunction codec_readfunction codec_writefunction snd_hdac_codec_readfunction snd_hdac_codec_writefunction snd_hdac_check_power_statefunction snd_hdac_sync_power_stateexport snd_hdac_device_initexport snd_hdac_device_exitexport snd_hdac_device_registerexport snd_hdac_device_unregisterexport snd_hdac_device_set_chip_nameexport snd_hdac_codec_modaliasexport snd_hdac_readexport _snd_hdac_read_parm
Annotated Snippet
err = device_add(&codec->dev);
if (err < 0)
return err;
scoped_guard(mutex, &codec->widget_lock) {
err = hda_widget_sysfs_init(codec);
}
if (err < 0) {
device_del(&codec->dev);
return err;
}
return 0;
}
EXPORT_SYMBOL_GPL(snd_hdac_device_register);
/**
* snd_hdac_device_unregister - unregister the hd-audio codec base device
* @codec: the device to unregister
*/
void snd_hdac_device_unregister(struct hdac_device *codec)
{
if (device_is_registered(&codec->dev)) {
scoped_guard(mutex, &codec->widget_lock) {
hda_widget_sysfs_exit(codec);
}
device_del(&codec->dev);
snd_hdac_bus_remove_device(codec->bus, codec);
}
}
EXPORT_SYMBOL_GPL(snd_hdac_device_unregister);
/**
* snd_hdac_device_set_chip_name - set/update the codec name
* @codec: the HDAC device
* @name: name string to set
*
* Returns 0 if the name is set or updated, or a negative error code.
*/
int snd_hdac_device_set_chip_name(struct hdac_device *codec, const char *name)
{
char *newname;
if (!name)
return 0;
newname = kstrdup(name, GFP_KERNEL);
if (!newname)
return -ENOMEM;
kfree(codec->chip_name);
codec->chip_name = newname;
return 0;
}
EXPORT_SYMBOL_GPL(snd_hdac_device_set_chip_name);
/**
* snd_hdac_codec_modalias - give the module alias name
* @codec: HDAC device
* @buf: string buffer to store
* @size: string buffer size
*
* Returns the size of string, like snprintf(), or a negative error code.
*/
int snd_hdac_codec_modalias(const struct hdac_device *codec, char *buf, size_t size)
{
return scnprintf(buf, size, "hdaudio:v%08Xr%08Xa%02X\n",
codec->vendor_id, codec->revision_id, codec->type);
}
EXPORT_SYMBOL_GPL(snd_hdac_codec_modalias);
/**
* snd_hdac_make_cmd - compose a 32bit command word to be sent to the
* HD-audio controller
* @codec: the codec object
* @nid: NID to encode
* @verb: verb to encode
* @parm: parameter to encode
*
* Return an encoded command verb or -1 for error.
*/
static unsigned int snd_hdac_make_cmd(struct hdac_device *codec, hda_nid_t nid,
unsigned int verb, unsigned int parm)
{
u32 val, addr;
addr = codec->addr;
if ((addr & ~0xf) || (nid & ~0x7f) ||
(verb & ~0xfff) || (parm & ~0xffff)) {
dev_err(&codec->dev, "out of range cmd %x:%x:%x:%x\n",
addr, nid, verb, parm);
return -1;
}
Annotation
- Immediate include surface: `linux/init.h`, `linux/delay.h`, `linux/device.h`, `linux/slab.h`, `linux/module.h`, `linux/export.h`, `linux/pm_runtime.h`, `sound/hdaudio.h`.
- Detected declarations: `struct hda_vendor_id`, `struct hda_rate_tbl`, `function default_release`, `function snd_hdac_device_init`, `function snd_hdac_device_exit`, `function snd_hdac_device_register`, `function snd_hdac_device_unregister`, `function snd_hdac_device_set_chip_name`, `function snd_hdac_codec_modalias`, `function snd_hdac_make_cmd`.
- Atlas domain: Driver Families / sound/hda.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.