diff mbox series

usb: typec: disable pm for typec class devices

Message ID 1675752122-8147-1-git-send-email-quic_linyyuan@quicinc.com (mailing list archive)
State New, archived
Headers show
Series usb: typec: disable pm for typec class devices | expand

Commit Message

Linyu Yuan Feb. 7, 2023, 6:42 a.m. UTC
as there is no pm operation, call device_set_pm_not_required() to disable
all typec class devices.

Signed-off-by: Linyu Yuan <quic_linyyuan@quicinc.com>
---
 drivers/usb/typec/class.c   | 5 +++++
 drivers/usb/typec/mux.c     | 2 ++
 drivers/usb/typec/pd.c      | 3 +++
 drivers/usb/typec/retimer.c | 1 +
 4 files changed, 11 insertions(+)

Comments

Heikki Krogerus Feb. 7, 2023, 7:34 a.m. UTC | #1
On Tue, Feb 07, 2023 at 02:42:02PM +0800, Linyu Yuan wrote:
> as there is no pm operation, call device_set_pm_not_required() to disable
> all typec class devices.
> 
> Signed-off-by: Linyu Yuan <quic_linyyuan@quicinc.com>
> ---
>  drivers/usb/typec/class.c   | 5 +++++
>  drivers/usb/typec/mux.c     | 2 ++
>  drivers/usb/typec/pd.c      | 3 +++
>  drivers/usb/typec/retimer.c | 1 +
>  4 files changed, 11 insertions(+)

Now this is just boilerplate.

Why not propose this to be done in core for every new device that
doesn't have a bus, and that doesn't have the pm ops assigned in the
device type?


> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index ed3d070..b75ec6d 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -548,6 +548,7 @@ typec_register_altmode(struct device *parent,
>  	alt->adev.dev.groups = alt->groups;
>  	alt->adev.dev.type = &typec_altmode_dev_type;
>  	dev_set_name(&alt->adev.dev, "%s.%u", dev_name(parent), id);
> +	device_set_pm_not_required(&alt->adev.dev);

Note that for alt modes you can't do this. They can be bind to
drivers - there is a bus for them.

thanks,
Linyu Yuan Feb. 7, 2023, 8:07 a.m. UTC | #2
On 2/7/2023 3:34 PM, Heikki Krogerus wrote:
> On Tue, Feb 07, 2023 at 02:42:02PM +0800, Linyu Yuan wrote:
>> as there is no pm operation, call device_set_pm_not_required() to disable
>> all typec class devices.
>>
>> Signed-off-by: Linyu Yuan <quic_linyyuan@quicinc.com>
>> ---
>>   drivers/usb/typec/class.c   | 5 +++++
>>   drivers/usb/typec/mux.c     | 2 ++
>>   drivers/usb/typec/pd.c      | 3 +++
>>   drivers/usb/typec/retimer.c | 1 +
>>   4 files changed, 11 insertions(+)
> Now this is just boilerplate.
>
> Why not propose this to be done in core for every new device that
> doesn't have a bus, and that doesn't have the pm ops assigned in the
> device type?


thanks, will try.


>
>> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
>> index ed3d070..b75ec6d 100644
>> --- a/drivers/usb/typec/class.c
>> +++ b/drivers/usb/typec/class.c
>> @@ -548,6 +548,7 @@ typec_register_altmode(struct device *parent,
>>   	alt->adev.dev.groups = alt->groups;
>>   	alt->adev.dev.type = &typec_altmode_dev_type;
>>   	dev_set_name(&alt->adev.dev, "%s.%u", dev_name(parent), id);
>> +	device_set_pm_not_required(&alt->adev.dev);
> Note that for alt modes you can't do this. They can be bind to
> drivers - there is a bus for them.


but even in the bus, there is power management,

struct bus_type typec_bus = {
     .name = "typec",
     .dev_groups = typec_groups,
     .match = typec_match,
     .uevent = typec_uevent,
     .probe = typec_probe,
     .remove = typec_remove,
};


we can disable it, right ?


>
> thanks,
>
Heikki Krogerus Feb. 7, 2023, 9:03 a.m. UTC | #3
On Tue, Feb 07, 2023 at 04:07:17PM +0800, Linyu Yuan wrote:
> > Note that for alt modes you can't do this. They can be bind to
> > drivers - there is a bus for them.
> 
> but even in the bus, there is power management,
> 
> struct bus_type typec_bus = {
>     .name = "typec",
>     .dev_groups = typec_groups,
>     .match = typec_match,
>     .uevent = typec_uevent,
>     .probe = typec_probe,
>     .remove = typec_remove,
> };
> 
> we can disable it, right ?

No. It does not matter if the bus does not have the PM ops, a driver
can still supply the PM ops for the device.

Check how it's handled in drivers/base/power/main.c. Basically, if the
bus, pm domain, device type, or the class don't supply the PM ops,
the drivers own PM ops are then just used directly.

thanks,
diff mbox series

Patch

diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index ed3d070..b75ec6d 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -548,6 +548,7 @@  typec_register_altmode(struct device *parent,
 	alt->adev.dev.groups = alt->groups;
 	alt->adev.dev.type = &typec_altmode_dev_type;
 	dev_set_name(&alt->adev.dev, "%s.%u", dev_name(parent), id);
+	device_set_pm_not_required(&alt->adev.dev);
 
 	/* Link partners and plugs with the ports */
 	if (!is_port)
@@ -880,6 +881,7 @@  struct typec_partner *typec_register_partner(struct typec_port *port,
 	partner->dev.parent = &port->dev;
 	partner->dev.type = &typec_partner_dev_type;
 	dev_set_name(&partner->dev, "%s-partner", dev_name(&port->dev));
+	device_set_pm_not_required(&partner->dev);
 
 	ret = device_register(&partner->dev);
 	if (ret) {
@@ -1032,6 +1034,7 @@  struct typec_plug *typec_register_plug(struct typec_cable *cable,
 	plug->dev.parent = &cable->dev;
 	plug->dev.type = &typec_plug_dev_type;
 	dev_set_name(&plug->dev, "%s-%s", dev_name(cable->dev.parent), name);
+	device_set_pm_not_required(&plug->dev);
 
 	ret = device_register(&plug->dev);
 	if (ret) {
@@ -1197,6 +1200,7 @@  struct typec_cable *typec_register_cable(struct typec_port *port,
 	cable->dev.parent = &port->dev;
 	cable->dev.type = &typec_cable_dev_type;
 	dev_set_name(&cable->dev, "%s-cable", dev_name(&port->dev));
+	device_set_pm_not_required(&cable->dev);
 
 	ret = device_register(&cable->dev);
 	if (ret) {
@@ -2260,6 +2264,7 @@  struct typec_port *typec_register_port(struct device *parent,
 	port->dev.fwnode = cap->fwnode;
 	port->dev.type = &typec_port_dev_type;
 	dev_set_name(&port->dev, "port%d", id);
+	device_set_pm_not_required(&port->dev);
 	dev_set_drvdata(&port->dev, cap->driver_data);
 
 	port->cap = kmemdup(cap, sizeof(*cap), GFP_KERNEL);
diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c
index c7177dd..55b5417 100644
--- a/drivers/usb/typec/mux.c
+++ b/drivers/usb/typec/mux.c
@@ -183,6 +183,7 @@  typec_switch_register(struct device *parent,
 	sw_dev->dev.class = &typec_mux_class;
 	sw_dev->dev.type = &typec_switch_dev_type;
 	sw_dev->dev.driver_data = desc->drvdata;
+	device_set_pm_not_required(&sw_dev->dev);
 	ret = dev_set_name(&sw_dev->dev, "%s-switch", desc->name ? desc->name : dev_name(parent));
 	if (ret) {
 		put_device(&sw_dev->dev);
@@ -470,6 +471,7 @@  typec_mux_register(struct device *parent, const struct typec_mux_desc *desc)
 	mux_dev->dev.class = &typec_mux_class;
 	mux_dev->dev.type = &typec_mux_dev_type;
 	mux_dev->dev.driver_data = desc->drvdata;
+	device_set_pm_not_required(&mux_dev->dev);
 	ret = dev_set_name(&mux_dev->dev, "%s-mux", desc->name ? desc->name : dev_name(parent));
 	if (ret) {
 		put_device(&mux_dev->dev);
diff --git a/drivers/usb/typec/pd.c b/drivers/usb/typec/pd.c
index dc72005..252ef51 100644
--- a/drivers/usb/typec/pd.c
+++ b/drivers/usb/typec/pd.c
@@ -428,6 +428,7 @@  static int add_pdo(struct usb_power_delivery_capabilities *cap, u32 pdo, int pos
 	p->dev.parent = &cap->dev;
 	p->dev.type = type;
 	dev_set_name(&p->dev, "%u:%s", position + 1, name);
+	device_set_pm_not_required(&p->dev);
 
 	ret = device_register(&p->dev);
 	if (ret) {
@@ -490,6 +491,7 @@  usb_power_delivery_register_capabilities(struct usb_power_delivery *pd,
 	cap->dev.parent = &pd->dev;
 	cap->dev.type = &pd_capabilities_type;
 	dev_set_name(&cap->dev, "%s", cap_name[cap->role]);
+	device_set_pm_not_required(&cap->dev);
 
 	ret = device_register(&cap->dev);
 	if (ret) {
@@ -626,6 +628,7 @@  usb_power_delivery_register(struct device *parent, struct usb_power_delivery_des
 	pd->dev.type = &pd_type;
 	pd->dev.class = &pd_class;
 	dev_set_name(&pd->dev, "pd%d", pd->id);
+	device_set_pm_not_required(&pd->dev);
 
 	ret = device_register(&pd->dev);
 	if (ret) {
diff --git a/drivers/usb/typec/retimer.c b/drivers/usb/typec/retimer.c
index 0481e82..99105c9 100644
--- a/drivers/usb/typec/retimer.c
+++ b/drivers/usb/typec/retimer.c
@@ -122,6 +122,7 @@  typec_retimer_register(struct device *parent, const struct typec_retimer_desc *d
 	retimer->dev.class = &retimer_class;
 	retimer->dev.type = &typec_retimer_dev_type;
 	retimer->dev.driver_data = desc->drvdata;
+	device_set_pm_not_required(&retimer->dev);
 	dev_set_name(&retimer->dev, "%s-retimer",
 		     desc->name ? desc->name : dev_name(parent));