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) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/regulator/driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) static const struct regulator_ops pg86x_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 	.set_voltage_sel = regulator_set_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 	.get_voltage_sel = regulator_get_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 	.list_voltage = regulator_list_voltage_linear_range,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) static const struct linear_range pg86x_buck1_ranges[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 	REGULATOR_LINEAR_RANGE(      0,  0, 10,     0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	REGULATOR_LINEAR_RANGE(1000000, 11, 34, 25000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	REGULATOR_LINEAR_RANGE(1600000, 35, 47, 50000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) static const struct linear_range pg86x_buck2_ranges[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	REGULATOR_LINEAR_RANGE(      0,  0, 15,     0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	REGULATOR_LINEAR_RANGE(1000000, 16, 39, 25000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	REGULATOR_LINEAR_RANGE(1600000, 40, 52, 50000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static const struct regulator_desc pg86x_regulators[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 		.id = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 		.type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		.name = "buck1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		.of_match = of_match_ptr("buck1"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		.n_voltages = 11 + 24 + 13,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		.linear_ranges = pg86x_buck1_ranges,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 		.n_linear_ranges = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		.vsel_reg  = 0x24,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		.vsel_mask = 0xff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		.ops = &pg86x_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		.owner = THIS_MODULE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		.id = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		.type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		.name = "buck2",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		.of_match = of_match_ptr("buck2"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		.n_voltages = 16 + 24 + 13,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		.linear_ranges = pg86x_buck2_ranges,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		.n_linear_ranges = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		.vsel_reg  = 0x13,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		.vsel_mask = 0xff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		.ops = &pg86x_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		.owner = THIS_MODULE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) static const struct regmap_config pg86x_regmap = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	.reg_bits = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	.val_bits = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) static int pg86x_i2c_probe(struct i2c_client *i2c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	int id, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	struct regulator_config config = {.dev = &i2c->dev};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	struct regmap *regmap = devm_regmap_init_i2c(i2c, &pg86x_regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	if (IS_ERR(regmap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		ret = PTR_ERR(regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		dev_err(&i2c->dev, "regmap init failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	for (id = 0; id < ARRAY_SIZE(pg86x_regulators); id++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		struct regulator_dev *rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		rdev = devm_regulator_register(&i2c->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 					       &pg86x_regulators[id],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 					       &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		if (IS_ERR(rdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			ret = PTR_ERR(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 			dev_err(&i2c->dev, "failed to register %s: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 				pg86x_regulators[id].name, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) static const struct of_device_id __maybe_unused pg86x_dt_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	{ .compatible = "marvell,88pg867" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	{ .compatible = "marvell,88pg868" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) MODULE_DEVICE_TABLE(of, pg86x_dt_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) static const struct i2c_device_id pg86x_i2c_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	{ "88pg867", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	{ "88pg868", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) MODULE_DEVICE_TABLE(i2c, pg86x_i2c_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static struct i2c_driver pg86x_regulator_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		.name = "88pg86x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		.of_match_table = of_match_ptr(pg86x_dt_ids),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	.probe_new = pg86x_i2c_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	.id_table = pg86x_i2c_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) module_i2c_driver(pg86x_regulator_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) MODULE_DESCRIPTION("Marvell 88PG86X voltage regulator");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) MODULE_AUTHOR("Alexander Monakov <amonakov@gmail.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) MODULE_LICENSE("GPL");