0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/kernel.h>
0013 #include <linux/module.h>
0014 #include <linux/init.h>
0015 #include <linux/device.h>
0016 #include <linux/err.h>
0017 #include <linux/platform_device.h>
0018
0019 #include <linux/mfd/pcf50633/core.h>
0020 #include <linux/mfd/pcf50633/pmic.h>
0021
0022 #define PCF50633_REGULATOR(_name, _id, _min_uV, _uV_step, _min_sel, _n) \
0023 { \
0024 .name = _name, \
0025 .id = PCF50633_REGULATOR_##_id, \
0026 .ops = &pcf50633_regulator_ops, \
0027 .n_voltages = _n, \
0028 .min_uV = _min_uV, \
0029 .uV_step = _uV_step, \
0030 .linear_min_sel = _min_sel, \
0031 .type = REGULATOR_VOLTAGE, \
0032 .owner = THIS_MODULE, \
0033 .vsel_reg = PCF50633_REG_##_id##OUT, \
0034 .vsel_mask = 0xff, \
0035 .enable_reg = PCF50633_REG_##_id##OUT + 1, \
0036 .enable_mask = PCF50633_REGULATOR_ON, \
0037 }
0038
0039 static const struct regulator_ops pcf50633_regulator_ops = {
0040 .set_voltage_sel = regulator_set_voltage_sel_regmap,
0041 .get_voltage_sel = regulator_get_voltage_sel_regmap,
0042 .list_voltage = regulator_list_voltage_linear,
0043 .map_voltage = regulator_map_voltage_linear,
0044 .enable = regulator_enable_regmap,
0045 .disable = regulator_disable_regmap,
0046 .is_enabled = regulator_is_enabled_regmap,
0047 };
0048
0049 static const struct regulator_desc regulators[] = {
0050 [PCF50633_REGULATOR_AUTO] =
0051 PCF50633_REGULATOR("auto", AUTO, 1800000, 25000, 0x2f, 128),
0052 [PCF50633_REGULATOR_DOWN1] =
0053 PCF50633_REGULATOR("down1", DOWN1, 625000, 25000, 0, 96),
0054 [PCF50633_REGULATOR_DOWN2] =
0055 PCF50633_REGULATOR("down2", DOWN2, 625000, 25000, 0, 96),
0056 [PCF50633_REGULATOR_LDO1] =
0057 PCF50633_REGULATOR("ldo1", LDO1, 900000, 100000, 0, 28),
0058 [PCF50633_REGULATOR_LDO2] =
0059 PCF50633_REGULATOR("ldo2", LDO2, 900000, 100000, 0, 28),
0060 [PCF50633_REGULATOR_LDO3] =
0061 PCF50633_REGULATOR("ldo3", LDO3, 900000, 100000, 0, 28),
0062 [PCF50633_REGULATOR_LDO4] =
0063 PCF50633_REGULATOR("ldo4", LDO4, 900000, 100000, 0, 28),
0064 [PCF50633_REGULATOR_LDO5] =
0065 PCF50633_REGULATOR("ldo5", LDO5, 900000, 100000, 0, 28),
0066 [PCF50633_REGULATOR_LDO6] =
0067 PCF50633_REGULATOR("ldo6", LDO6, 900000, 100000, 0, 28),
0068 [PCF50633_REGULATOR_HCLDO] =
0069 PCF50633_REGULATOR("hcldo", HCLDO, 900000, 100000, 0, 28),
0070 [PCF50633_REGULATOR_MEMLDO] =
0071 PCF50633_REGULATOR("memldo", MEMLDO, 900000, 100000, 0, 28),
0072 };
0073
0074 static int pcf50633_regulator_probe(struct platform_device *pdev)
0075 {
0076 struct regulator_dev *rdev;
0077 struct pcf50633 *pcf;
0078 struct regulator_config config = { };
0079
0080
0081 pcf = dev_to_pcf50633(pdev->dev.parent);
0082
0083 config.dev = &pdev->dev;
0084 config.init_data = dev_get_platdata(&pdev->dev);
0085 config.driver_data = pcf;
0086 config.regmap = pcf->regmap;
0087
0088 rdev = devm_regulator_register(&pdev->dev, ®ulators[pdev->id],
0089 &config);
0090 if (IS_ERR(rdev))
0091 return PTR_ERR(rdev);
0092
0093 platform_set_drvdata(pdev, rdev);
0094
0095 if (pcf->pdata->regulator_registered)
0096 pcf->pdata->regulator_registered(pcf, pdev->id);
0097
0098 return 0;
0099 }
0100
0101 static struct platform_driver pcf50633_regulator_driver = {
0102 .driver = {
0103 .name = "pcf50633-regulator",
0104 },
0105 .probe = pcf50633_regulator_probe,
0106 };
0107
0108 static int __init pcf50633_regulator_init(void)
0109 {
0110 return platform_driver_register(&pcf50633_regulator_driver);
0111 }
0112 subsys_initcall(pcf50633_regulator_init);
0113
0114 static void __exit pcf50633_regulator_exit(void)
0115 {
0116 platform_driver_unregister(&pcf50633_regulator_driver);
0117 }
0118 module_exit(pcf50633_regulator_exit);
0119
0120 MODULE_AUTHOR("Balaji Rao <balajirrao@openmoko.org>");
0121 MODULE_DESCRIPTION("PCF50633 regulator driver");
0122 MODULE_LICENSE("GPL");
0123 MODULE_ALIAS("platform:pcf50633-regulator");