Re: [PATCH v3 13/28] soc: qcom: Add driver for Qualcomm Krait L2 cache scaling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2.07.2023 19:42, Dmitry Baryshkov wrote:
> Add a simple driver that handles scaling of L2 frequency and voltages.
> 
> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@xxxxxxxxxx>
> ---
[...]

> +/* vdd-mem and vdd-dig */
> +#define NUM_SUPPLIES 2
> +static int krait_l2_config_regulators(struct device *dev,
> +				      struct dev_pm_opp *old_opp,
> +				      struct dev_pm_opp *new_opp,
> +				      struct regulator **regulators,
> +				      unsigned int count)
> +{
> +	struct dev_pm_opp_supply supplies[NUM_SUPPLIES];
> +	unsigned long old_freq, freq;
> +	unsigned int i;
> +	int ret;
> +
> +	if (WARN_ON_ONCE(count != NUM_SUPPLIES))
> +		return -EINVAL;
> +
> +	ret = dev_pm_opp_get_supplies(new_opp, supplies);
> +	if (WARN_ON(ret))
> +		return ret;
> +
> +	old_freq = dev_pm_opp_get_freq(old_opp);
> +	freq = dev_pm_opp_get_freq(new_opp);
> +
> +	WARN_ON(!old_freq || !freq);
> +	if (freq > old_freq) {
> +		for (i = 0; i < count; i++) {
> +			ret = krait_l2_set_one_supply(dev, regulators[i], &supplies[i]);
> +			if (ret)
> +				goto restore_backwards;
> +		}
// name the 0 and 1
ret = krait_l2_set_one_supply(dev, regulators[0], &supplies[0]);
if (ret)
	return ret;

ret = krait_l2_set_one_supply(dev, regulators[1], &supplies[1]);
if (ret) {
	dev_pm_opp_get_supplies(old_opp, supplies);

	return krait_l2_set_one_supply(dev, regulators[0], &supplies[0]);
}

> +	} else {
> +		for (i = count; i > 0; i--) {
> +			ret = krait_l2_set_one_supply(dev, regulators[i - 1], &supplies[i - 1]);
> +			if (ret)
> +				goto restore_forward;
> +		}
> +	}
analogous

> +
> +	return 0;
> +
> +restore_backwards:
and this part \/ becomes redundant

> +
> +	dev_pm_opp_get_supplies(old_opp, supplies);
> +
> +	for (; i > 0; i--)
> +		krait_l2_set_one_supply(dev, regulators[i - 1], &supplies[i - 1]);
> +
> +	return ret;
> +
> +restore_forward:
> +
> +	dev_pm_opp_get_supplies(old_opp, supplies);
> +
> +	for ( ; i < count; i++)
> +		krait_l2_set_one_supply(dev, regulators[i], &supplies[i]);
> +
> +	return ret;
> +}
> +
> +static int krait_l2_probe(struct platform_device *pdev)
> +{
> +	struct dev_pm_opp_config krait_l2_cfg = {
> +		.clk_names = (const char * const[]) { NULL, NULL },
> +		.config_regulators = krait_l2_config_regulators,
> +		.regulator_names = (const char * const[]) { "vdd-mem", "vdd-dig", NULL },
> +	};
> +	struct icc_clk_data data[] = {
> +		{ .name = "l2", .opp = true},
true }

Konrad
> +	};
> +
> +	struct device *dev = &pdev->dev;
> +	struct icc_provider *provider;
> +	struct clk *clk;
> +	int ret;
> +
> +	clk = devm_clk_get(dev, NULL);
> +	if (IS_ERR(clk))
> +		return PTR_ERR(clk);
> +
> +	ret = devm_pm_opp_set_config(dev, &krait_l2_cfg);
> +	if (ret)
> +		return ret;
> +
> +	ret = devm_pm_opp_of_add_table(dev);
> +	if (ret)
> +		return ret;
> +
> +	data[0].clk = clk;
> +	provider = icc_clk_register(dev, L2_MASTER_NODE, ARRAY_SIZE(data), data);
> +	if (IS_ERR(provider))
> +		return PTR_ERR(provider);
> +
> +	platform_set_drvdata(pdev, provider);
> +
> +	return 0;
> +}
> +
> +static int krait_l2_remove(struct platform_device *pdev)
> +{
> +	struct icc_provider *provider = platform_get_drvdata(pdev);
> +
> +	icc_clk_unregister(provider);
> +
> +	return 0;
> +}
> +
> +static const struct of_device_id krait_l2_match_table[] = {
> +	{ .compatible = "qcom,krait-l2-cache" },
> +	{}
> +};
> +MODULE_DEVICE_TABLE(of, krait_l2_match_table);
> +
> +static struct platform_driver krait_l2_driver = {
> +	.probe = krait_l2_probe,
> +	.remove = krait_l2_remove,
> +	.driver = {
> +		.name = "qcom-krait-l2",
> +		.of_match_table = krait_l2_match_table,
> +		.sync_state = icc_sync_state,
> +	},
> +};
> +
> +module_platform_driver(krait_l2_driver);
> +
> +MODULE_DESCRIPTION("Qualcomm Krait L2 scaling driver");
> +MODULE_LICENSE("GPL v2");



[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux