drivers/media/v4l2-core/v4l2-spi.c
Source file repositories/reference/linux-study-clean/drivers/media/v4l2-core/v4l2-spi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/v4l2-core/v4l2-spi.c- Extension
.c- Size
- 1945 bytes
- Lines
- 79
- Domain
- Driver Families
- Bucket
- drivers/media
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/spi/spi.hmedia/v4l2-common.hmedia/v4l2-device.h
Detected Declarations
function v4l2_spi_subdev_unregisterfunction v4l2_spi_subdev_initexport v4l2_spi_subdev_initexport v4l2_spi_new_subdev
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* v4l2-spi - SPI helpers for Video4Linux2
*/
#include <linux/module.h>
#include <linux/spi/spi.h>
#include <media/v4l2-common.h>
#include <media/v4l2-device.h>
void v4l2_spi_subdev_unregister(struct v4l2_subdev *sd)
{
struct spi_device *spi = v4l2_get_subdevdata(sd);
if (spi && !spi->dev.of_node && !spi->dev.fwnode)
spi_unregister_device(spi);
}
void v4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi,
const struct v4l2_subdev_ops *ops)
{
v4l2_subdev_init(sd, ops);
sd->flags |= V4L2_SUBDEV_FL_IS_SPI;
/* the owner is the same as the spi_device's driver owner */
sd->owner = spi->dev.driver->owner;
sd->dev = &spi->dev;
/* spi_device and v4l2_subdev point to one another */
v4l2_set_subdevdata(sd, spi);
spi_set_drvdata(spi, sd);
/* initialize name */
snprintf(sd->name, sizeof(sd->name), "%s %s",
spi->dev.driver->name, dev_name(&spi->dev));
}
EXPORT_SYMBOL_GPL(v4l2_spi_subdev_init);
struct v4l2_subdev *v4l2_spi_new_subdev(struct v4l2_device *v4l2_dev,
struct spi_controller *ctlr,
struct spi_board_info *info)
{
struct v4l2_subdev *sd = NULL;
struct spi_device *spi = NULL;
if (!v4l2_dev)
return NULL;
if (info->modalias[0])
request_module(info->modalias);
spi = spi_new_device(ctlr, info);
if (!spi || !spi->dev.driver)
goto error;
if (!try_module_get(spi->dev.driver->owner))
goto error;
sd = spi_get_drvdata(spi);
/*
* Register with the v4l2_device which increases the module's
* use count as well.
*/
if (__v4l2_device_register_subdev(v4l2_dev, sd, sd->owner))
sd = NULL;
/* Decrease the module use count to match the first try_module_get. */
module_put(spi->dev.driver->owner);
error:
/*
* If we have a client but no subdev, then something went wrong and
* we must unregister the client.
*/
if (!sd)
spi_unregister_device(spi);
return sd;
}
EXPORT_SYMBOL_GPL(v4l2_spi_new_subdev);
Annotation
- Immediate include surface: `linux/module.h`, `linux/spi/spi.h`, `media/v4l2-common.h`, `media/v4l2-device.h`.
- Detected declarations: `function v4l2_spi_subdev_unregister`, `function v4l2_spi_subdev_init`, `export v4l2_spi_subdev_init`, `export v4l2_spi_new_subdev`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: integration implementation candidate.
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.