1 // SPDX-License-Identifier: GPL-2.0-only
3 // Qualcomm PMIC VBUS output regulator driver
5 // Copyright (c) 2020, The Linux Foundation. All rights reserved.
7 #include <linux/module.h>
9 #include <linux/kernel.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>
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
= {
30 .ops
= &qcom_usb_vbus_reg_ops
,
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
;
45 ret
= of_property_read_u32(dev
->of_node
, "reg", &base
);
47 dev_err(dev
, "no base address found\n");
51 regmap
= dev_get_regmap(dev
->parent
, NULL
);
53 dev_err(dev
, "Failed to get regmap\n");
57 init_data
= of_get_regulator_init_data(dev
, dev
->of_node
,
58 &qcom_usb_vbus_rdesc
);
62 qcom_usb_vbus_rdesc
.enable_reg
= base
+ CMD_OTG
;
63 qcom_usb_vbus_rdesc
.enable_mask
= OTG_EN
;
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
);
72 dev_err(dev
, "not able to register vbus reg %d\n", ret
);
76 /* Disable HW logic for VBUS enable */
77 regmap_update_bits(regmap
, base
+ OTG_CFG
, OTG_EN_SRC_CFG
, 0);
82 static const struct of_device_id qcom_usb_vbus_regulator_match
[] = {
83 { .compatible
= "qcom,pm8150b-vbus-reg" },
86 MODULE_DEVICE_TABLE(of
, qcom_usb_vbus_regulator_match
);
88 static struct platform_driver qcom_usb_vbus_regulator_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");