usb: common: usb-conn-gpio: use a unique name for usb connector device
[ Upstream commit d4e5b10c55627e2f3fc9e5b337a28b4e2f02a55e ] The current implementation of the usb-conn-gpio driver uses a fixed "usb-charger" name for all USB connector devices. This causes conflicts in the power supply subsystem when multiple USB connectors are present, as duplicate names are not allowed. Use IDA to manage unique IDs for naming usb connectors (e.g., usb-charger-0, usb-charger-1). Signed-off-by: Chance Yang <chance.yang@kneron.us> Link: https://lore.kernel.org/r/20250411-work-next-v3-1-7cd9aa80190c@kneron.us Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
8e958d10dd
commit
0aaf810416
@@ -20,6 +20,9 @@
|
|||||||
#include <linux/power_supply.h>
|
#include <linux/power_supply.h>
|
||||||
#include <linux/regulator/consumer.h>
|
#include <linux/regulator/consumer.h>
|
||||||
#include <linux/usb/role.h>
|
#include <linux/usb/role.h>
|
||||||
|
#include <linux/idr.h>
|
||||||
|
|
||||||
|
static DEFINE_IDA(usb_conn_ida);
|
||||||
|
|
||||||
#define USB_GPIO_DEB_MS 20 /* ms */
|
#define USB_GPIO_DEB_MS 20 /* ms */
|
||||||
#define USB_GPIO_DEB_US ((USB_GPIO_DEB_MS) * 1000) /* us */
|
#define USB_GPIO_DEB_US ((USB_GPIO_DEB_MS) * 1000) /* us */
|
||||||
@@ -29,6 +32,7 @@
|
|||||||
|
|
||||||
struct usb_conn_info {
|
struct usb_conn_info {
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
|
int conn_id; /* store the IDA-allocated ID */
|
||||||
struct usb_role_switch *role_sw;
|
struct usb_role_switch *role_sw;
|
||||||
enum usb_role last_role;
|
enum usb_role last_role;
|
||||||
struct regulator *vbus;
|
struct regulator *vbus;
|
||||||
@@ -160,7 +164,17 @@ static int usb_conn_psy_register(struct usb_conn_info *info)
|
|||||||
.of_node = dev->of_node,
|
.of_node = dev->of_node,
|
||||||
};
|
};
|
||||||
|
|
||||||
desc->name = "usb-charger";
|
info->conn_id = ida_alloc(&usb_conn_ida, GFP_KERNEL);
|
||||||
|
if (info->conn_id < 0)
|
||||||
|
return info->conn_id;
|
||||||
|
|
||||||
|
desc->name = devm_kasprintf(dev, GFP_KERNEL, "usb-charger-%d",
|
||||||
|
info->conn_id);
|
||||||
|
if (!desc->name) {
|
||||||
|
ida_free(&usb_conn_ida, info->conn_id);
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
desc->properties = usb_charger_properties;
|
desc->properties = usb_charger_properties;
|
||||||
desc->num_properties = ARRAY_SIZE(usb_charger_properties);
|
desc->num_properties = ARRAY_SIZE(usb_charger_properties);
|
||||||
desc->get_property = usb_charger_get_property;
|
desc->get_property = usb_charger_get_property;
|
||||||
@@ -168,8 +182,10 @@ static int usb_conn_psy_register(struct usb_conn_info *info)
|
|||||||
cfg.drv_data = info;
|
cfg.drv_data = info;
|
||||||
|
|
||||||
info->charger = devm_power_supply_register(dev, desc, &cfg);
|
info->charger = devm_power_supply_register(dev, desc, &cfg);
|
||||||
if (IS_ERR(info->charger))
|
if (IS_ERR(info->charger)) {
|
||||||
dev_err(dev, "Unable to register charger\n");
|
dev_err(dev, "Unable to register charger %d\n", info->conn_id);
|
||||||
|
ida_free(&usb_conn_ida, info->conn_id);
|
||||||
|
}
|
||||||
|
|
||||||
return PTR_ERR_OR_ZERO(info->charger);
|
return PTR_ERR_OR_ZERO(info->charger);
|
||||||
}
|
}
|
||||||
@@ -277,6 +293,9 @@ static void usb_conn_remove(struct platform_device *pdev)
|
|||||||
|
|
||||||
cancel_delayed_work_sync(&info->dw_det);
|
cancel_delayed_work_sync(&info->dw_det);
|
||||||
|
|
||||||
|
if (info->charger)
|
||||||
|
ida_free(&usb_conn_ida, info->conn_id);
|
||||||
|
|
||||||
if (info->last_role == USB_ROLE_HOST && info->vbus)
|
if (info->last_role == USB_ROLE_HOST && info->vbus)
|
||||||
regulator_disable(info->vbus);
|
regulator_disable(info->vbus);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user