Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 //
0003 // Copyright (c) 2019 Mantas Pucka <mantas@8devices.com>
0004 // Copyright (c) 2019 Robert Marko <robert.marko@sartura.hr>
0005 //
0006 // Driver for IPQ4019 SD/MMC controller's I/O LDO voltage regulator
0007 
0008 #include <linux/io.h>
0009 #include <linux/module.h>
0010 #include <linux/of.h>
0011 #include <linux/platform_device.h>
0012 #include <linux/regmap.h>
0013 #include <linux/regulator/driver.h>
0014 #include <linux/regulator/machine.h>
0015 #include <linux/regulator/of_regulator.h>
0016 
0017 static const unsigned int ipq4019_vmmc_voltages[] = {
0018     1500000, 1800000, 2500000, 3000000,
0019 };
0020 
0021 static const struct regulator_ops ipq4019_regulator_voltage_ops = {
0022     .list_voltage = regulator_list_voltage_table,
0023     .map_voltage = regulator_map_voltage_ascend,
0024     .get_voltage_sel = regulator_get_voltage_sel_regmap,
0025     .set_voltage_sel = regulator_set_voltage_sel_regmap,
0026 };
0027 
0028 static const struct regulator_desc vmmc_regulator = {
0029     .name       = "vmmcq",
0030     .ops        = &ipq4019_regulator_voltage_ops,
0031     .type       = REGULATOR_VOLTAGE,
0032     .owner      = THIS_MODULE,
0033     .volt_table = ipq4019_vmmc_voltages,
0034     .n_voltages = ARRAY_SIZE(ipq4019_vmmc_voltages),
0035     .vsel_reg   = 0,
0036     .vsel_mask  = 0x3,
0037 };
0038 
0039 static const struct regmap_config ipq4019_vmmcq_regmap_config = {
0040     .reg_bits   = 32,
0041     .reg_stride = 4,
0042     .val_bits   = 32,
0043 };
0044 
0045 static int ipq4019_regulator_probe(struct platform_device *pdev)
0046 {
0047     struct device *dev = &pdev->dev;
0048     struct regulator_init_data *init_data;
0049     struct regulator_config cfg = {};
0050     struct regulator_dev *rdev;
0051     struct regmap *rmap;
0052     void __iomem *base;
0053 
0054     init_data = of_get_regulator_init_data(dev, dev->of_node,
0055                            &vmmc_regulator);
0056     if (!init_data)
0057         return -EINVAL;
0058 
0059     base = devm_platform_ioremap_resource(pdev, 0);
0060     if (IS_ERR(base))
0061         return PTR_ERR(base);
0062 
0063     rmap = devm_regmap_init_mmio(dev, base, &ipq4019_vmmcq_regmap_config);
0064     if (IS_ERR(rmap))
0065         return PTR_ERR(rmap);
0066 
0067     cfg.dev = dev;
0068     cfg.init_data = init_data;
0069     cfg.of_node = dev->of_node;
0070     cfg.regmap = rmap;
0071 
0072     rdev = devm_regulator_register(dev, &vmmc_regulator, &cfg);
0073     if (IS_ERR(rdev)) {
0074         dev_err(dev, "Failed to register regulator: %ld\n",
0075             PTR_ERR(rdev));
0076         return PTR_ERR(rdev);
0077     }
0078     platform_set_drvdata(pdev, rdev);
0079 
0080     return 0;
0081 }
0082 
0083 static const struct of_device_id regulator_ipq4019_of_match[] = {
0084     { .compatible = "qcom,vqmmc-ipq4019-regulator", },
0085     {},
0086 };
0087 
0088 static struct platform_driver ipq4019_regulator_driver = {
0089     .probe = ipq4019_regulator_probe,
0090     .driver = {
0091         .name = "vqmmc-ipq4019-regulator",
0092         .of_match_table = of_match_ptr(regulator_ipq4019_of_match),
0093     },
0094 };
0095 module_platform_driver(ipq4019_regulator_driver);
0096 
0097 MODULE_LICENSE("GPL");
0098 MODULE_AUTHOR("Mantas Pucka <mantas@8devices.com>");
0099 MODULE_DESCRIPTION("IPQ4019 VQMMC voltage regulator");