drivers/devfreq/imx-bus.c

Source file repositories/reference/linux-study-clean/drivers/devfreq/imx-bus.c

File Facts

System
Linux kernel
Corpus path
drivers/devfreq/imx-bus.c
Extension
.c
Size
4195 bytes
Lines
167
Domain
Driver Families
Bucket
drivers/devfreq
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 imx_bus {
	struct devfreq_dev_profile profile;
	struct devfreq *devfreq;
	struct clk *clk;
	struct platform_device *icc_pdev;
};

static int imx_bus_target(struct device *dev,
		unsigned long *freq, u32 flags)
{
	struct dev_pm_opp *new_opp;
	int ret;

	new_opp = devfreq_recommended_opp(dev, freq, flags);
	if (IS_ERR(new_opp)) {
		ret = PTR_ERR(new_opp);
		dev_err(dev, "failed to get recommended opp: %d\n", ret);
		return ret;
	}
	dev_pm_opp_put(new_opp);

	return dev_pm_opp_set_rate(dev, *freq);
}

static int imx_bus_get_cur_freq(struct device *dev, unsigned long *freq)
{
	struct imx_bus *priv = dev_get_drvdata(dev);

	*freq = clk_get_rate(priv->clk);

	return 0;
}

static void imx_bus_exit(struct device *dev)
{
	struct imx_bus *priv = dev_get_drvdata(dev);

	dev_pm_opp_of_remove_table(dev);
	platform_device_unregister(priv->icc_pdev);
}

/* imx_bus_init_icc() - register matching icc provider if required */
static int imx_bus_init_icc(struct device *dev)
{
	struct imx_bus *priv = dev_get_drvdata(dev);
	const char *icc_driver_name;

	if (!of_property_present(dev->of_node, "#interconnect-cells"))
		return 0;
	if (!IS_ENABLED(CONFIG_INTERCONNECT_IMX)) {
		dev_warn(dev, "imx interconnect drivers disabled\n");
		return 0;
	}

	icc_driver_name = of_device_get_match_data(dev);
	if (!icc_driver_name) {
		dev_err(dev, "unknown interconnect driver\n");
		return 0;
	}

	priv->icc_pdev = platform_device_register_data(
			dev, icc_driver_name, -1, NULL, 0);
	if (IS_ERR(priv->icc_pdev)) {
		dev_err(dev, "failed to register icc provider %s: %ld\n",
				icc_driver_name, PTR_ERR(priv->icc_pdev));
		return PTR_ERR(priv->icc_pdev);
	}

	return 0;
}

static int imx_bus_probe(struct platform_device *pdev)
{
	struct device *dev = &pdev->dev;
	struct imx_bus *priv;
	const char *gov = DEVFREQ_GOV_USERSPACE;
	int ret;

	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
	if (!priv)
		return -ENOMEM;

	/*
	 * Fetch the clock to adjust but don't explicitly enable.
	 *
	 * For imx bus clock clk_set_rate is safe no matter if the clock is on
	 * or off and some peripheral side-buses might be off unless enabled by
	 * drivers for devices on those specific buses.
	 *
	 * Rate adjustment on a disabled bus clock just takes effect later.

Annotation

Implementation Notes