drivers/mfd/twl4030-audio.c
Source file repositories/reference/linux-study-clean/drivers/mfd/twl4030-audio.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mfd/twl4030-audio.c- Extension
.c- Size
- 6806 bytes
- Lines
- 287
- Domain
- Driver Families
- Bucket
- drivers/mfd
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/types.hlinux/slab.hlinux/kernel.hlinux/fs.hlinux/platform_device.hlinux/of.hlinux/of_platform.hlinux/mfd/twl.hlinux/mfd/core.hlinux/mfd/twl4030-audio.h
Detected Declarations
struct twl4030_audio_resourcestruct twl4030_audiofunction twl4030_audio_set_resourcefunction twl4030_audio_get_resourcefunction twl4030_audio_enable_resourcefunction twl4030_audio_disable_resourcefunction twl4030_audio_get_mclkfunction twl4030_audio_has_codecfunction twl4030_audio_has_vibrafunction twl4030_audio_probefunction twl4030_audio_removeexport twl4030_audio_enable_resourceexport twl4030_audio_disable_resourceexport twl4030_audio_get_mclk
Annotated Snippet
struct twl4030_audio_resource {
int request_count;
u8 reg;
u8 mask;
};
struct twl4030_audio {
unsigned int audio_mclk;
struct mutex mutex;
struct twl4030_audio_resource resource[TWL4030_AUDIO_RES_MAX];
struct mfd_cell cells[TWL4030_AUDIO_CELLS];
};
/*
* Modify the resource, the function returns the content of the register
* after the modification.
*/
static int twl4030_audio_set_resource(enum twl4030_audio_res id, int enable)
{
struct twl4030_audio *audio = platform_get_drvdata(twl4030_audio_dev);
u8 val;
twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &val,
audio->resource[id].reg);
if (enable)
val |= audio->resource[id].mask;
else
val &= ~audio->resource[id].mask;
twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,
val, audio->resource[id].reg);
return val;
}
static inline int twl4030_audio_get_resource(enum twl4030_audio_res id)
{
struct twl4030_audio *audio = platform_get_drvdata(twl4030_audio_dev);
u8 val;
twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &val,
audio->resource[id].reg);
return val;
}
/*
* Enable the resource.
* The function returns with error or the content of the register
*/
int twl4030_audio_enable_resource(enum twl4030_audio_res id)
{
struct twl4030_audio *audio = platform_get_drvdata(twl4030_audio_dev);
int val;
if (id >= TWL4030_AUDIO_RES_MAX) {
dev_err(&twl4030_audio_dev->dev,
"Invalid resource ID (%u)\n", id);
return -EINVAL;
}
mutex_lock(&audio->mutex);
if (!audio->resource[id].request_count)
/* Resource was disabled, enable it */
val = twl4030_audio_set_resource(id, 1);
else
val = twl4030_audio_get_resource(id);
audio->resource[id].request_count++;
mutex_unlock(&audio->mutex);
return val;
}
EXPORT_SYMBOL_GPL(twl4030_audio_enable_resource);
/*
* Disable the resource.
* The function returns with error or the content of the register
*/
int twl4030_audio_disable_resource(enum twl4030_audio_res id)
{
struct twl4030_audio *audio = platform_get_drvdata(twl4030_audio_dev);
int val;
if (id >= TWL4030_AUDIO_RES_MAX) {
dev_err(&twl4030_audio_dev->dev,
"Invalid resource ID (%u)\n", id);
return -EINVAL;
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/types.h`, `linux/slab.h`, `linux/kernel.h`, `linux/fs.h`, `linux/platform_device.h`, `linux/of.h`, `linux/of_platform.h`.
- Detected declarations: `struct twl4030_audio_resource`, `struct twl4030_audio`, `function twl4030_audio_set_resource`, `function twl4030_audio_get_resource`, `function twl4030_audio_enable_resource`, `function twl4030_audio_disable_resource`, `function twl4030_audio_get_mclk`, `function twl4030_audio_has_codec`, `function twl4030_audio_has_vibra`, `function twl4030_audio_probe`.
- Atlas domain: Driver Families / drivers/mfd.
- 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.