drivers/bus/moxtet.c
Source file repositories/reference/linux-study-clean/drivers/bus/moxtet.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/bus/moxtet.c- Extension
.c- Size
- 19174 bytes
- Lines
- 888
- Domain
- Driver Families
- Bucket
- drivers/bus
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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
dt-bindings/bus/moxtet.hlinux/bitops.hlinux/debugfs.hlinux/hex.hlinux/interrupt.hlinux/module.hlinux/moxtet.hlinux/mutex.hlinux/of_device.hlinux/of_irq.hlinux/spi/spi.h
Detected Declarations
function mox_module_knownfunction moxtet_matchfunction __moxtet_register_driverfunction moxtet_dev_checkfunction moxtet_dev_releasefunction moxtet_alloc_devicefunction moxtet_add_devicefunction __unregisterfunction of_register_moxtet_devicefunction of_register_moxtet_devicesfunction for_each_available_child_of_nodefunction moxtet_register_devices_from_topologyfunction moxtet_set_irqfunction moxtet_find_topologyfunction moxtet_spi_readfunction moxtet_device_readfunction moxtet_device_writefunction moxtet_device_writtenfunction moxtet_debug_openfunction input_readfunction output_readfunction output_writefunction moxtet_register_debugfsfunction moxtet_unregister_debugfsfunction moxtet_register_debugfsfunction moxtet_unregister_debugfsfunction moxtet_irq_domain_xlatefunction moxtet_irq_maskfunction moxtet_irq_unmaskfunction moxtet_irq_print_chipfunction moxtet_irq_readfunction for_each_set_bitfunction moxtet_irq_thread_fnfunction for_each_set_bitfunction moxtet_irq_freefunction moxtet_irq_setupfunction moxtet_probefunction moxtet_removefunction moxtet_initfunction moxtet_exitexport __moxtet_register_driverexport moxtet_device_readexport moxtet_device_writeexport moxtet_device_written
Annotated Snippet
static int moxtet_match(struct device *dev, const struct device_driver *drv)
{
struct moxtet_device *mdev = to_moxtet_device(dev);
const struct moxtet_driver *tdrv = to_moxtet_driver(drv);
const enum turris_mox_module_id *t;
if (of_driver_match_device(dev, drv))
return 1;
if (!tdrv->id_table)
return 0;
for (t = tdrv->id_table; *t; ++t)
if (*t == mdev->id)
return 1;
return 0;
}
static const struct bus_type moxtet_bus_type = {
.name = "moxtet",
.dev_groups = moxtet_dev_groups,
.match = moxtet_match,
};
int __moxtet_register_driver(struct module *owner,
struct moxtet_driver *mdrv)
{
mdrv->driver.owner = owner;
mdrv->driver.bus = &moxtet_bus_type;
return driver_register(&mdrv->driver);
}
EXPORT_SYMBOL_GPL(__moxtet_register_driver);
static int moxtet_dev_check(struct device *dev, void *data)
{
struct moxtet_device *mdev = to_moxtet_device(dev);
struct moxtet_device *new_dev = data;
if (mdev->moxtet == new_dev->moxtet && mdev->id == new_dev->id &&
mdev->idx == new_dev->idx)
return -EBUSY;
return 0;
}
static void moxtet_dev_release(struct device *dev)
{
struct moxtet_device *mdev = to_moxtet_device(dev);
put_device(mdev->moxtet->dev);
kfree(mdev);
}
static struct moxtet_device *
moxtet_alloc_device(struct moxtet *moxtet)
{
struct moxtet_device *dev;
if (!get_device(moxtet->dev))
return NULL;
dev = kzalloc_obj(*dev);
if (!dev) {
put_device(moxtet->dev);
return NULL;
}
dev->moxtet = moxtet;
dev->dev.parent = moxtet->dev;
dev->dev.bus = &moxtet_bus_type;
dev->dev.release = moxtet_dev_release;
device_initialize(&dev->dev);
return dev;
}
static int moxtet_add_device(struct moxtet_device *dev)
{
static DEFINE_MUTEX(add_mutex);
int ret;
if (dev->idx >= TURRIS_MOX_MAX_MODULES || dev->id > 0xf)
return -EINVAL;
dev_set_name(&dev->dev, "moxtet-%s.%u", mox_module_name(dev->id),
dev->idx);
mutex_lock(&add_mutex);
Annotation
- Immediate include surface: `dt-bindings/bus/moxtet.h`, `linux/bitops.h`, `linux/debugfs.h`, `linux/hex.h`, `linux/interrupt.h`, `linux/module.h`, `linux/moxtet.h`, `linux/mutex.h`.
- Detected declarations: `function mox_module_known`, `function moxtet_match`, `function __moxtet_register_driver`, `function moxtet_dev_check`, `function moxtet_dev_release`, `function moxtet_alloc_device`, `function moxtet_add_device`, `function __unregister`, `function of_register_moxtet_device`, `function of_register_moxtet_devices`.
- Atlas domain: Driver Families / drivers/bus.
- Implementation status: pattern 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.