drivers/reset/core.c

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

File Facts

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

struct reset_control {
	struct reset_controller_dev __rcu *rcdev;
	struct srcu_struct srcu;
	struct list_head list;
	unsigned int id;
	struct kref refcnt;
	bool acquired;
	bool shared;
	bool array;
	atomic_t deassert_count;
	atomic_t triggered_count;
	struct mutex lock;
};

/**
 * struct reset_control_array - an array of reset controls
 * @base: reset control for compatibility with reset control API functions
 * @num_rstcs: number of reset controls
 * @rstc: array of reset controls
 */
struct reset_control_array {
	struct reset_control base;
	unsigned int num_rstcs;
	struct reset_control *rstc[] __counted_by(num_rstcs);
};

/**
 * struct reset_gpio_lookup - lookup key for ad-hoc created reset-gpio devices
 * @ref_args: Reference to the reset controller with all the args like GPIO number
 * @swnode: Software node containing the reference to the GPIO provider
 * @list: list entry for the reset_gpio_lookup_list
 * @adev: Auxiliary device representing the reset controller
 */
struct reset_gpio_lookup {
	struct fwnode_reference_args ref_args;
	struct fwnode_handle *swnode;
	struct list_head list;
	struct auxiliary_device adev;
};

static const char *rcdev_name(struct reset_controller_dev *rcdev)
{
	if (rcdev->dev)
		return dev_name(rcdev->dev);

	if (rcdev->fwnode)
		return fwnode_get_name(rcdev->fwnode);

	return NULL;
}

/**
 * fwnode_reset_simple_xlate - translate reset_spec to the reset line number
 * @rcdev: a pointer to the reset controller device
 * @reset_spec: reset line specifier as found in firmware
 *
 * This static translation function is used by default if neither fwnode_xlate
 * not of_xlate in :c:type:`reset_controller_dev` is not set. It is useful for
 * all reset controllers with 1:1 mapping, where reset lines can be indexed by
 * number without gaps.
 */
static int fwnode_reset_simple_xlate(struct reset_controller_dev *rcdev,
				     const struct fwnode_reference_args *reset_spec)
{
	if (reset_spec->args[0] >= rcdev->nr_resets)
		return -EINVAL;

	return reset_spec->args[0];
}

/**
 * reset_controller_register - register a reset controller device
 * @rcdev: a pointer to the initialized reset controller device
 */
int reset_controller_register(struct reset_controller_dev *rcdev)
{
	if ((rcdev->of_node && rcdev->fwnode) || (rcdev->of_xlate && rcdev->fwnode_xlate))
		return -EINVAL;

	if (rcdev->of_node && !rcdev->fwnode)
		rcdev->fwnode = of_fwnode_handle(rcdev->of_node);

	if (!rcdev->fwnode) {
		rcdev->fwnode = dev_fwnode(rcdev->dev);
		if (!rcdev->fwnode)
			return -EINVAL;
	}

	if (rcdev->of_xlate)
		rcdev->fwnode_reset_n_cells = rcdev->of_reset_n_cells;

Annotation

Implementation Notes