drivers/siox/siox-core.c

Source file repositories/reference/linux-study-clean/drivers/siox/siox-core.c

File Facts

System
Linux kernel
Corpus path
drivers/siox/siox-core.c
Extension
.c
Size
22675 bytes
Lines
981
Domain
Driver Families
Bucket
drivers/siox
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.

Dependency Surface

Detected Declarations

Annotated Snippet

static int siox_match(struct device *dev, const struct device_driver *drv)
{
	if (dev->type != &siox_device_type)
		return 0;

	/* up to now there is only a single driver so keeping this simple */
	return 1;
}

static int siox_probe(struct device *dev)
{
	struct siox_driver *sdriver = to_siox_driver(dev->driver);
	struct siox_device *sdevice = to_siox_device(dev);

	return sdriver->probe(sdevice);
}

static void siox_remove(struct device *dev)
{
	struct siox_driver *sdriver =
		container_of(dev->driver, struct siox_driver, driver);
	struct siox_device *sdevice = to_siox_device(dev);

	if (sdriver->remove)
		sdriver->remove(sdevice);
}

static void siox_shutdown(struct device *dev)
{
	struct siox_device *sdevice = to_siox_device(dev);
	struct siox_driver *sdriver;

	if (!dev->driver)
		return;

	sdriver = container_of(dev->driver, struct siox_driver, driver);
	if (sdriver->shutdown)
		sdriver->shutdown(sdevice);
}

static const struct bus_type siox_bus_type = {
	.name = "siox",
	.match = siox_match,
	.probe = siox_probe,
	.remove = siox_remove,
	.shutdown = siox_shutdown,
};

static ssize_t active_show(struct device *dev,
			   struct device_attribute *attr, char *buf)
{
	struct siox_master *smaster = to_siox_master(dev);

	return sprintf(buf, "%d\n", smaster->active);
}

static ssize_t active_store(struct device *dev,
			    struct device_attribute *attr,
			    const char *buf, size_t count)
{
	struct siox_master *smaster = to_siox_master(dev);
	int ret;
	int active;

	ret = kstrtoint(buf, 0, &active);
	if (ret < 0)
		return ret;

	if (active)
		ret = siox_start(smaster);
	else
		ret = siox_stop(smaster);

	if (ret < 0)
		return ret;

	return count;
}

static DEVICE_ATTR_RW(active);

static struct siox_device *siox_device_add(struct siox_master *smaster,
					   const char *type, size_t inbytes,
					   size_t outbytes, u8 statustype);

static ssize_t device_add_store(struct device *dev,
				struct device_attribute *attr,
				const char *buf, size_t count)
{
	struct siox_master *smaster = to_siox_master(dev);

Annotation

Implementation Notes