Merge tag 'trace-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
[linux/fpc-iii.git] / drivers / regulator / qcom_usb_vbus-regulator.c
blob457788b505720775ce8d96b83dc0a332bcebd292
1 // SPDX-License-Identifier: GPL-2.0-only
2 //
3 // Qualcomm PMIC VBUS output regulator driver
4 //
5 // Copyright (c) 2020, The Linux Foundation. All rights reserved.
7 #include <linux/module.h>
8 #include <linux/err.h>
9 #include <linux/kernel.h>
10 #include <linux/of.h>
11 #include <linux/of_device.h>
12 #include <linux/platform_device.h>
13 #include <linux/regulator/driver.h>
14 #include <linux/regulator/of_regulator.h>
15 #include <linux/regmap.h>
17 #define CMD_OTG 0x40
18 #define OTG_EN BIT(0)
19 #define OTG_CFG 0x53
20 #define OTG_EN_SRC_CFG BIT(1)
22 static const struct regulator_ops qcom_usb_vbus_reg_ops = {
23 .enable = regulator_enable_regmap,
24 .disable = regulator_disable_regmap,
25 .is_enabled = regulator_is_enabled_regmap,
28 static struct regulator_desc qcom_usb_vbus_rdesc = {
29 .name = "usb_vbus",
30 .ops = &qcom_usb_vbus_reg_ops,
31 .owner = THIS_MODULE,
32 .type = REGULATOR_VOLTAGE,
35 static int qcom_usb_vbus_regulator_probe(struct platform_device *pdev)
37 struct device *dev = &pdev->dev;
38 struct regulator_dev *rdev;
39 struct regmap *regmap;
40 struct regulator_config config = { };
41 struct regulator_init_data *init_data;
42 int ret;
43 u32 base;
45 ret = of_property_read_u32(dev->of_node, "reg", &base);
46 if (ret < 0) {
47 dev_err(dev, "no base address found\n");
48 return ret;
51 regmap = dev_get_regmap(dev->parent, NULL);
52 if (!regmap) {
53 dev_err(dev, "Failed to get regmap\n");
54 return -ENOENT;
57 init_data = of_get_regulator_init_data(dev, dev->of_node,
58 &qcom_usb_vbus_rdesc);
59 if (!init_data)
60 return -ENOMEM;
62 qcom_usb_vbus_rdesc.enable_reg = base + CMD_OTG;
63 qcom_usb_vbus_rdesc.enable_mask = OTG_EN;
64 config.dev = dev;
65 config.init_data = init_data;
66 config.of_node = dev->of_node;
67 config.regmap = regmap;
69 rdev = devm_regulator_register(dev, &qcom_usb_vbus_rdesc, &config);
70 if (IS_ERR(rdev)) {
71 ret = PTR_ERR(rdev);
72 dev_err(dev, "not able to register vbus reg %d\n", ret);
73 return ret;
76 /* Disable HW logic for VBUS enable */
77 regmap_update_bits(regmap, base + OTG_CFG, OTG_EN_SRC_CFG, 0);
79 return 0;
82 static const struct of_device_id qcom_usb_vbus_regulator_match[] = {
83 { .compatible = "qcom,pm8150b-vbus-reg" },
84 { }
86 MODULE_DEVICE_TABLE(of, qcom_usb_vbus_regulator_match);
88 static struct platform_driver qcom_usb_vbus_regulator_driver = {
89 .driver = {
90 .name = "qcom-usb-vbus-regulator",
91 .of_match_table = qcom_usb_vbus_regulator_match,
93 .probe = qcom_usb_vbus_regulator_probe,
95 module_platform_driver(qcom_usb_vbus_regulator_driver);
97 MODULE_DESCRIPTION("Qualcomm USB vbus regulator driver");
98 MODULE_LICENSE("GPL v2");