drivers/clk/imx/clk-imx8ulp-sim-lpav.c

Source file repositories/reference/linux-study-clean/drivers/clk/imx/clk-imx8ulp-sim-lpav.c

File Facts

System
Linux kernel
Corpus path
drivers/clk/imx/clk-imx8ulp-sim-lpav.c
Extension
.c
Size
4359 bytes
Lines
157
Domain
Driver Families
Bucket
drivers/clk
Inferred role
Driver Families: implementation source
Status
source 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 clk_imx8ulp_sim_lpav_data {
	spinlock_t lock; /* shared by MUX, clock gate and reset */
	unsigned long flags; /* for spinlock usage */
	struct clk_hw_onecell_data clk_data; /*  keep last */
};

struct clk_imx8ulp_sim_lpav_gate {
	const char *name;
	int id;
	const struct clk_parent_data parent;
	u8 bit;
};

static struct clk_imx8ulp_sim_lpav_gate gates[] = {
	IMX8ULP_HIFI_CLK_GATE("hifi_core", CORE, "core", 17),
	IMX8ULP_HIFI_CLK_GATE("hifi_pbclk", PBCLK, "bus", 18),
	IMX8ULP_HIFI_CLK_GATE("hifi_plat", PLAT, "plat", 19)
};

static void clk_imx8ulp_sim_lpav_lock(void *arg) __acquires(&data->lock)
{
	struct clk_imx8ulp_sim_lpav_data *data = dev_get_drvdata(arg);

	spin_lock_irqsave(&data->lock, data->flags);
}

static void clk_imx8ulp_sim_lpav_unlock(void *arg) __releases(&data->lock)
{
	struct clk_imx8ulp_sim_lpav_data *data = dev_get_drvdata(arg);

	spin_unlock_irqrestore(&data->lock, data->flags);
}

static int clk_imx8ulp_sim_lpav_probe(struct platform_device *pdev)
{
	const struct regmap_config regmap_config = {
		.reg_bits = 32,
		.val_bits = 32,
		.reg_stride = 4,
		.lock = clk_imx8ulp_sim_lpav_lock,
		.unlock = clk_imx8ulp_sim_lpav_unlock,
		.lock_arg = &pdev->dev,
	};
	struct clk_imx8ulp_sim_lpav_data *data;
	struct auxiliary_device *adev;
	struct regmap *regmap;
	void __iomem *base;
	struct clk_hw *hw;
	int i, ret;

	data = devm_kzalloc(&pdev->dev,
			    struct_size(data, clk_data.hws, ARRAY_SIZE(gates)),
			    GFP_KERNEL);
	if (!data)
		return -ENOMEM;

	dev_set_drvdata(&pdev->dev, data);

	/*
	 * this lock is used directly by the clock gate and indirectly
	 * by the reset and mux controller via the regmap API
	 */
	spin_lock_init(&data->lock);

	base = devm_platform_ioremap_resource(pdev, 0);
	if (IS_ERR(base))
		return dev_err_probe(&pdev->dev, PTR_ERR(base),
				     "failed to ioremap base\n");
	/*
	 * although the clock gate doesn't use the regmap API to modify the
	 * registers, we still need the regmap because of the reset auxiliary
	 * driver and the MUX drivers, which use the parent device's regmap
	 */
	regmap = devm_regmap_init_mmio(&pdev->dev, base, &regmap_config);
	if (IS_ERR(regmap))
		return dev_err_probe(&pdev->dev, PTR_ERR(regmap),
				     "failed to initialize regmap\n");

	data->clk_data.num = ARRAY_SIZE(gates);

	for (i = 0; i < ARRAY_SIZE(gates); i++) {
		hw = devm_clk_hw_register_gate_parent_data(&pdev->dev,
							   gates[i].name,
							   &gates[i].parent,
							   CLK_SET_RATE_PARENT,
							   base + SYSCTRL0,
							   gates[i].bit,
							   0x0, &data->lock);
		if (IS_ERR(hw))
			return dev_err_probe(&pdev->dev, PTR_ERR(hw),

Annotation

Implementation Notes