Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) // Copyright (c) 2019 Mantas Pucka <mantas@8devices.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) // Copyright (c) 2019 Robert Marko <robert.marko@sartura.hr>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) // Driver for IPQ4019 SD/MMC controller's I/O LDO voltage regulator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/regulator/driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/regulator/machine.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/regulator/of_regulator.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) static const unsigned int ipq4019_vmmc_voltages[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	1500000, 1800000, 2500000, 3000000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static const struct regulator_ops ipq4019_regulator_voltage_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	.list_voltage = regulator_list_voltage_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	.map_voltage = regulator_map_voltage_ascend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	.get_voltage_sel = regulator_get_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	.set_voltage_sel = regulator_set_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static const struct regulator_desc vmmc_regulator = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	.name		= "vmmcq",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	.ops		= &ipq4019_regulator_voltage_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	.type		= REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	.volt_table	= ipq4019_vmmc_voltages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	.n_voltages	= ARRAY_SIZE(ipq4019_vmmc_voltages),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	.vsel_reg	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	.vsel_mask	= 0x3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static const struct regmap_config ipq4019_vmmcq_regmap_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	.reg_bits	= 32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	.reg_stride	= 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	.val_bits	= 32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static int ipq4019_regulator_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	struct regulator_init_data *init_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	struct regulator_config cfg = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	struct regulator_dev *rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	struct regmap *rmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	void __iomem *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	init_data = of_get_regulator_init_data(dev, dev->of_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 					       &vmmc_regulator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	if (!init_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	base = devm_ioremap_resource(dev, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	if (IS_ERR(base))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		return PTR_ERR(base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	rmap = devm_regmap_init_mmio(dev, base, &ipq4019_vmmcq_regmap_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	if (IS_ERR(rmap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		return PTR_ERR(rmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	cfg.dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	cfg.init_data = init_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	cfg.of_node = dev->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	cfg.regmap = rmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	rdev = devm_regulator_register(dev, &vmmc_regulator, &cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if (IS_ERR(rdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		dev_err(dev, "Failed to register regulator: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			PTR_ERR(rdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		return PTR_ERR(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	platform_set_drvdata(pdev, rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) static const struct of_device_id regulator_ipq4019_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	{ .compatible = "qcom,vqmmc-ipq4019-regulator", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	{},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) static struct platform_driver ipq4019_regulator_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	.probe = ipq4019_regulator_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		.name = "vqmmc-ipq4019-regulator",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		.of_match_table = of_match_ptr(regulator_ipq4019_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) module_platform_driver(ipq4019_regulator_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) MODULE_AUTHOR("Mantas Pucka <mantas@8devices.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) MODULE_DESCRIPTION("IPQ4019 VQMMC voltage regulator");