drivers/mfd/twl6040.c
Source file repositories/reference/linux-study-clean/drivers/mfd/twl6040.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mfd/twl6040.c- Extension
.c- Size
- 21103 bytes
- Lines
- 840
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/err.hlinux/platform_device.hlinux/of.hlinux/gpio/consumer.hlinux/delay.hlinux/i2c.hlinux/regmap.hlinux/mfd/core.hlinux/mfd/twl6040.hlinux/regulator/consumer.h
Detected Declarations
function twl6040_has_vibrafunction twl6040_reg_readfunction twl6040_reg_writefunction twl6040_set_bitsfunction twl6040_clear_bitsfunction twl6040_power_up_manualfunction twl6040_power_down_manualfunction twl6040_readyint_handlerfunction twl6040_thint_handlerfunction twl6040_power_up_automaticfunction twl6040_powerfunction twl6040_set_pllfunction twl6040_get_pllfunction twl6040_get_sysclkfunction twl6040_get_vibralr_statusfunction twl6040_readable_regfunction twl6040_volatile_regfunction twl6040_writeable_regfunction twl6040_probefunction twl6040_removeexport twl6040_reg_readexport twl6040_reg_writeexport twl6040_set_bitsexport twl6040_clear_bitsexport twl6040_powerexport twl6040_set_pllexport twl6040_get_pllexport twl6040_get_sysclkexport twl6040_get_vibralr_status
Annotated Snippet
if (!(intid & TWL6040_READYINT)) {
dev_err(twl6040->dev, "automatic power-up failed\n");
gpiod_set_value_cansleep(twl6040->audpwron, 0);
return -ETIMEDOUT;
}
}
return 0;
}
int twl6040_power(struct twl6040 *twl6040, int on)
{
int ret = 0;
mutex_lock(&twl6040->mutex);
if (on) {
/* already powered-up */
if (twl6040->power_count++)
goto out;
ret = clk_prepare_enable(twl6040->clk32k);
if (ret) {
twl6040->power_count = 0;
goto out;
}
/* Allow writes to the chip */
regcache_cache_only(twl6040->regmap, false);
if (twl6040->audpwron) {
/* use automatic power-up sequence */
ret = twl6040_power_up_automatic(twl6040);
if (ret) {
clk_disable_unprepare(twl6040->clk32k);
twl6040->power_count = 0;
goto out;
}
} else {
/* use manual power-up sequence */
ret = twl6040_power_up_manual(twl6040);
if (ret) {
clk_disable_unprepare(twl6040->clk32k);
twl6040->power_count = 0;
goto out;
}
}
/*
* Register access can produce errors after power-up unless we
* wait at least 8ms based on measurements on duovero.
*/
usleep_range(10000, 12000);
/* Sync with the HW */
ret = regcache_sync(twl6040->regmap);
if (ret) {
dev_err(twl6040->dev, "Failed to sync with the HW: %i\n",
ret);
goto out;
}
/* Default PLL configuration after power up */
twl6040->pll = TWL6040_SYSCLK_SEL_LPPLL;
twl6040->sysclk_rate = 19200000;
} else {
/* already powered-down */
if (!twl6040->power_count) {
dev_err(twl6040->dev,
"device is already powered-off\n");
ret = -EPERM;
goto out;
}
if (--twl6040->power_count)
goto out;
if (twl6040->audpwron) {
/* use AUDPWRON line */
gpiod_set_value_cansleep(twl6040->audpwron, 0);
/* power-down sequence latency */
usleep_range(500, 700);
} else {
/* use manual power-down sequence */
twl6040_power_down_manual(twl6040);
}
/* Set regmap to cache only and mark it as dirty */
regcache_cache_only(twl6040->regmap, true);
Annotation
- Immediate include surface: `linux/module.h`, `linux/types.h`, `linux/slab.h`, `linux/kernel.h`, `linux/err.h`, `linux/platform_device.h`, `linux/of.h`, `linux/gpio/consumer.h`.
- Detected declarations: `function twl6040_has_vibra`, `function twl6040_reg_read`, `function twl6040_reg_write`, `function twl6040_set_bits`, `function twl6040_clear_bits`, `function twl6040_power_up_manual`, `function twl6040_power_down_manual`, `function twl6040_readyint_handler`, `function twl6040_thint_handler`, `function twl6040_power_up_automatic`.
- 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.