drivers/thermal/thermal_core.c

Source file repositories/reference/linux-study-clean/drivers/thermal/thermal_core.c

File Facts

System
Linux kernel
Corpus path
drivers/thermal/thermal_core.c
Extension
.c
Size
46771 bytes
Lines
1831
Domain
Driver Families
Bucket
drivers/thermal
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.

Dependency Surface

Detected Declarations

Annotated Snippet

ret = device_add(&cdev->device);
	if (ret)
		goto out_put_device;

	if (current_state <= cdev->max_state)
		thermal_debug_cdev_add(cdev, current_state);

	thermal_cooling_device_init_complete(cdev);

	return 0;

out_put_device:
	/*
	 * The device core will release the memory via
	 * thermal_release() after put_device() is called in the error
	 * path
	 */
	put_device(&cdev->device);
	return ret;
}

/**
 * thermal_cooling_device_register() - register a new thermal cooling device
 * @type:	the thermal cooling device type.
 * @devdata:	device private data.
 * @ops:	standard thermal cooling devices callbacks.
 *
 * This interface function adds a new thermal cooling device (fan/processor/...)
 * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
 * to all the thermal zone devices registered at the same time.
 *
 * Return: a pointer to the created struct thermal_cooling_device or an
 * ERR_PTR. Caller must check return value with IS_ERR*() helpers.
 */
struct thermal_cooling_device *
thermal_cooling_device_register(const char *type, void *devdata,
				const struct thermal_cooling_device_ops *ops)
{
	struct thermal_cooling_device *cdev;
	int ret;

	cdev = thermal_cooling_device_alloc(type, ops);
	if (IS_ERR(cdev))
		return cdev;

	ret = thermal_cooling_device_add(cdev, devdata);
	if (ret)
		return ERR_PTR(ret);

	return cdev;
}
EXPORT_SYMBOL_GPL(thermal_cooling_device_register);

static void thermal_cooling_device_release(void *data)
{
	struct thermal_cooling_device *cdev = data;

	thermal_cooling_device_unregister(cdev);
}

/**
 * devm_thermal_cooling_device_register() - register a thermal cooling device
 *
 * @dev:	a valid struct device pointer of a sensor device.
 * @type:	the thermal cooling device type.
 * @devdata:	device private data.
 * @ops:	standard thermal cooling devices callbacks.
 *
 * This function will register a cooling device. This interface
 * function adds a new thermal cooling device (fan/processor/...)  to
 * /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind
 * itself to all the thermal zone devices registered at the same time.
 *
 * Return: a pointer to the created struct thermal_cooling_device or an
 * ERR_PTR. Caller must check return value with IS_ERR*() helpers.
 */
struct thermal_cooling_device *
devm_thermal_cooling_device_register(struct device *dev, const char *type, void *devdata,
				     const struct thermal_cooling_device_ops *ops)
{
	struct thermal_cooling_device *cdev;
	int ret;

	cdev = thermal_cooling_device_register(type, devdata, ops);
	if (IS_ERR(cdev))
		return cdev;

	ret = devm_add_action_or_reset(dev, thermal_cooling_device_release, cdev);
	if (ret)
		return ERR_PTR(ret);

Annotation

Implementation Notes