drivers/misc/tifm_core.c

Source file repositories/reference/linux-study-clean/drivers/misc/tifm_core.c

File Facts

System
Linux kernel
Corpus path
drivers/misc/tifm_core.c
Extension
.c
Size
8299 bytes
Lines
367
Domain
Driver Families
Bucket
drivers/misc
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 tifm_bus_match(struct device *dev, const struct device_driver *drv)
{
	struct tifm_dev *sock = container_of(dev, struct tifm_dev, dev);
	const struct tifm_driver *fm_drv = container_of_const(drv, struct tifm_driver,
							      driver);
	const struct tifm_device_id *ids = fm_drv->id_table;

	if (ids) {
		while (ids->type) {
			if (tifm_dev_match(sock, ids))
				return 1;
			++ids;
		}
	}
	return 0;
}

static int tifm_uevent(const struct device *dev, struct kobj_uevent_env *env)
{
	const struct tifm_dev *sock = container_of_const(dev, struct tifm_dev, dev);

	if (add_uevent_var(env, "TIFM_CARD_TYPE=%s", tifm_media_type_name(sock->type, 1)))
		return -ENOMEM;

	return 0;
}

static int tifm_device_probe(struct device *dev)
{
	struct tifm_dev *sock = container_of(dev, struct tifm_dev, dev);
	struct tifm_driver *drv = container_of(dev->driver, struct tifm_driver,
					       driver);
	int rc = -ENODEV;

	get_device(dev);
	if (dev->driver && drv->probe) {
		rc = drv->probe(sock);
		if (!rc)
			return 0;
	}
	put_device(dev);
	return rc;
}

static void tifm_dummy_event(struct tifm_dev *sock)
{
	return;
}

static void tifm_device_remove(struct device *dev)
{
	struct tifm_dev *sock = container_of(dev, struct tifm_dev, dev);
	struct tifm_driver *drv = container_of(dev->driver, struct tifm_driver,
					       driver);

	if (dev->driver && drv->remove) {
		sock->card_event = tifm_dummy_event;
		sock->data_event = tifm_dummy_event;
		drv->remove(sock);
		sock->dev.driver = NULL;
	}

	put_device(dev);
}

#ifdef CONFIG_PM

static int tifm_device_suspend(struct device *dev, pm_message_t state)
{
	struct tifm_dev *sock = container_of(dev, struct tifm_dev, dev);
	struct tifm_driver *drv = container_of(dev->driver, struct tifm_driver,
					       driver);

	if (dev->driver && drv->suspend)
		return drv->suspend(sock, state);
	return 0;
}

static int tifm_device_resume(struct device *dev)
{
	struct tifm_dev *sock = container_of(dev, struct tifm_dev, dev);
	struct tifm_driver *drv = container_of(dev->driver, struct tifm_driver,
					       driver);

	if (dev->driver && drv->resume)
		return drv->resume(sock);
	return 0;
}

#else

Annotation

Implementation Notes