0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <linux/err.h>
0012 #include <linux/init.h>
0013 #include <linux/mfd/stw481x.h>
0014 #include <linux/module.h>
0015 #include <linux/platform_device.h>
0016 #include <linux/regulator/driver.h>
0017 #include <linux/regulator/of_regulator.h>
0018
0019 static const unsigned int stw481x_vmmc_voltages[] = {
0020 1800000,
0021 1800000,
0022 2850000,
0023 3000000,
0024 1850000,
0025 2600000,
0026 2700000,
0027 3300000,
0028 };
0029
0030 static const struct regulator_ops stw481x_vmmc_ops = {
0031 .list_voltage = regulator_list_voltage_table,
0032 .enable = regulator_enable_regmap,
0033 .disable = regulator_disable_regmap,
0034 .is_enabled = regulator_is_enabled_regmap,
0035 .get_voltage_sel = regulator_get_voltage_sel_regmap,
0036 .set_voltage_sel = regulator_set_voltage_sel_regmap,
0037 };
0038
0039 static const struct regulator_desc vmmc_regulator = {
0040 .name = "VMMC",
0041 .id = 0,
0042 .ops = &stw481x_vmmc_ops,
0043 .type = REGULATOR_VOLTAGE,
0044 .owner = THIS_MODULE,
0045 .n_voltages = ARRAY_SIZE(stw481x_vmmc_voltages),
0046 .volt_table = stw481x_vmmc_voltages,
0047 .enable_time = 200,
0048 .enable_reg = STW_CONF1,
0049 .enable_mask = STW_CONF1_PDN_VMMC | STW_CONF1_MMC_LS_STATUS,
0050 .enable_val = STW_CONF1_PDN_VMMC,
0051 .vsel_reg = STW_CONF1,
0052 .vsel_mask = STW_CONF1_VMMC_MASK,
0053 };
0054
0055 static int stw481x_vmmc_regulator_probe(struct platform_device *pdev)
0056 {
0057 struct stw481x *stw481x = dev_get_platdata(&pdev->dev);
0058 struct regulator_config config = { };
0059 struct regulator_dev *rdev;
0060 int ret;
0061
0062
0063 ret = regmap_update_bits(stw481x->map, STW_CONF2,
0064 STW_CONF2_VMMC_EXT, 0);
0065 if (ret) {
0066 dev_err(&pdev->dev, "could not disable external VMMC\n");
0067 return ret;
0068 }
0069
0070
0071 config.dev = &pdev->dev;
0072 config.driver_data = stw481x;
0073 config.regmap = stw481x->map;
0074 config.of_node = pdev->dev.of_node;
0075 config.init_data = of_get_regulator_init_data(&pdev->dev,
0076 pdev->dev.of_node,
0077 &vmmc_regulator);
0078
0079 rdev = devm_regulator_register(&pdev->dev, &vmmc_regulator, &config);
0080 if (IS_ERR(rdev)) {
0081 dev_err(&pdev->dev,
0082 "error initializing STw481x VMMC regulator\n");
0083 return PTR_ERR(rdev);
0084 }
0085
0086 dev_info(&pdev->dev, "initialized STw481x VMMC regulator\n");
0087 return 0;
0088 }
0089
0090 static const struct of_device_id stw481x_vmmc_match[] = {
0091 { .compatible = "st,stw481x-vmmc", },
0092 {},
0093 };
0094
0095 static struct platform_driver stw481x_vmmc_regulator_driver = {
0096 .driver = {
0097 .name = "stw481x-vmmc-regulator",
0098 .of_match_table = stw481x_vmmc_match,
0099 },
0100 .probe = stw481x_vmmc_regulator_probe,
0101 };
0102
0103 module_platform_driver(stw481x_vmmc_regulator_driver);