^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* NXP PCF50633 PMIC Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * (C) 2006-2008 by Openmoko, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Author: Balaji Rao <balajirrao@openmoko.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Broken down from monstrous PCF50633 driver mainly by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Harald Welte and Andy Green and Werner Almesberger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/mfd/pcf50633/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/mfd/pcf50633/pmic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define PCF50633_REGULATOR(_name, _id, _min_uV, _uV_step, _min_sel, _n) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) .name = _name, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) .id = PCF50633_REGULATOR_##_id, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) .ops = &pcf50633_regulator_ops, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) .n_voltages = _n, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) .min_uV = _min_uV, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) .uV_step = _uV_step, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) .linear_min_sel = _min_sel, \
^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) .vsel_reg = PCF50633_REG_##_id##OUT, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) .vsel_mask = 0xff, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) .enable_reg = PCF50633_REG_##_id##OUT + 1, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) .enable_mask = PCF50633_REGULATOR_ON, \
^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 regulator_ops pcf50633_regulator_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) .set_voltage_sel = regulator_set_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) .get_voltage_sel = regulator_get_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) .list_voltage = regulator_list_voltage_linear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) .map_voltage = regulator_map_voltage_linear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) .enable = regulator_enable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) .disable = regulator_disable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) .is_enabled = regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static const struct regulator_desc regulators[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) [PCF50633_REGULATOR_AUTO] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) PCF50633_REGULATOR("auto", AUTO, 1800000, 25000, 0x2f, 128),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) [PCF50633_REGULATOR_DOWN1] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) PCF50633_REGULATOR("down1", DOWN1, 625000, 25000, 0, 96),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) [PCF50633_REGULATOR_DOWN2] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) PCF50633_REGULATOR("down2", DOWN2, 625000, 25000, 0, 96),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) [PCF50633_REGULATOR_LDO1] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) PCF50633_REGULATOR("ldo1", LDO1, 900000, 100000, 0, 28),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) [PCF50633_REGULATOR_LDO2] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) PCF50633_REGULATOR("ldo2", LDO2, 900000, 100000, 0, 28),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) [PCF50633_REGULATOR_LDO3] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) PCF50633_REGULATOR("ldo3", LDO3, 900000, 100000, 0, 28),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) [PCF50633_REGULATOR_LDO4] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) PCF50633_REGULATOR("ldo4", LDO4, 900000, 100000, 0, 28),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) [PCF50633_REGULATOR_LDO5] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) PCF50633_REGULATOR("ldo5", LDO5, 900000, 100000, 0, 28),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) [PCF50633_REGULATOR_LDO6] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) PCF50633_REGULATOR("ldo6", LDO6, 900000, 100000, 0, 28),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) [PCF50633_REGULATOR_HCLDO] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) PCF50633_REGULATOR("hcldo", HCLDO, 900000, 100000, 0, 28),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) [PCF50633_REGULATOR_MEMLDO] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) PCF50633_REGULATOR("memldo", MEMLDO, 900000, 100000, 0, 28),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static int pcf50633_regulator_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct regulator_dev *rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct pcf50633 *pcf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct regulator_config config = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) /* Already set by core driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) pcf = dev_to_pcf50633(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) config.dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) config.init_data = dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) config.driver_data = pcf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) config.regmap = pcf->regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) rdev = devm_regulator_register(&pdev->dev, ®ulators[pdev->id],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (IS_ERR(rdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) return PTR_ERR(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) platform_set_drvdata(pdev, rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (pcf->pdata->regulator_registered)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) pcf->pdata->regulator_registered(pcf, pdev->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static struct platform_driver pcf50633_regulator_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) .name = "pcf50633-regulator",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) .probe = pcf50633_regulator_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static int __init pcf50633_regulator_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) return platform_driver_register(&pcf50633_regulator_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) subsys_initcall(pcf50633_regulator_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static void __exit pcf50633_regulator_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) platform_driver_unregister(&pcf50633_regulator_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) module_exit(pcf50633_regulator_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) MODULE_AUTHOR("Balaji Rao <balajirrao@openmoko.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) MODULE_DESCRIPTION("PCF50633 regulator driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) MODULE_ALIAS("platform:pcf50633-regulator");