Skip to content

Commit f2a8aa0

Browse files
Adam Thomsongregkh
authored andcommitted
typec: tcpm: Represent source supply through power_supply
This commit adds a power_supply class instance to represent a PD source's voltage and current properties. This provides an interface for reading these properties from user-space or other drivers. For PPS enabled Sources, this also provides write access to set the current and voltage and allows for swapping between standard PDO and PPS APDO. As this represents a superset of the information provided in the fusb302 driver, the power_supply instance in that code is removed as part of this change, so reverting the commit titled 'typec: tcpm: Represent source supply through power_supply class' Signed-off-by: Adam Thomson <[email protected]> Reviewed-by: Guenter Roeck <[email protected]> Reviewed-by: Heikki Krogerus <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent cf45004 commit f2a8aa0

File tree

4 files changed

+251
-66
lines changed

4 files changed

+251
-66
lines changed

drivers/usb/typec/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ config TYPEC_TCPM
4949
tristate "USB Type-C Port Controller Manager"
5050
depends on USB
5151
select USB_ROLE_SWITCH
52+
select POWER_SUPPLY
5253
help
5354
The Type-C Port Controller Manager provides a USB PD and USB Type-C
5455
state machine for use with Type-C Port Controllers.

drivers/usb/typec/fusb302/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
config TYPEC_FUSB302
22
tristate "Fairchild FUSB302 Type-C chip driver"
3-
depends on I2C && POWER_SUPPLY
3+
depends on I2C
44
help
55
The Fairchild FUSB302 Type-C chip driver that works with
66
Type-C Port Controller Manager to provide USB PD and USB

drivers/usb/typec/fusb302/fusb302.c

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <linux/of_device.h>
1919
#include <linux/of_gpio.h>
2020
#include <linux/pinctrl/consumer.h>
21-
#include <linux/power_supply.h>
2221
#include <linux/proc_fs.h>
2322
#include <linux/regulator/consumer.h>
2423
#include <linux/sched/clock.h>
@@ -99,11 +98,6 @@ struct fusb302_chip {
9998
/* lock for sharing chip states */
10099
struct mutex lock;
101100

102-
/* psy + psy status */
103-
struct power_supply *psy;
104-
u32 current_limit;
105-
u32 supply_voltage;
106-
107101
/* chip status */
108102
enum toggling_mode toggling_mode;
109103
enum src_current_status src_current_status;
@@ -862,13 +856,11 @@ static int tcpm_set_vbus(struct tcpc_dev *dev, bool on, bool charge)
862856
chip->vbus_on = on;
863857
fusb302_log(chip, "vbus := %s", on ? "On" : "Off");
864858
}
865-
if (chip->charge_on == charge) {
859+
if (chip->charge_on == charge)
866860
fusb302_log(chip, "charge is already %s",
867861
charge ? "On" : "Off");
868-
} else {
862+
else
869863
chip->charge_on = charge;
870-
power_supply_changed(chip->psy);
871-
}
872864

873865
done:
874866
mutex_unlock(&chip->lock);
@@ -884,11 +876,6 @@ static int tcpm_set_current_limit(struct tcpc_dev *dev, u32 max_ma, u32 mv)
884876
fusb302_log(chip, "current limit: %d ma, %d mv (not implemented)",
885877
max_ma, mv);
886878

887-
chip->supply_voltage = mv;
888-
chip->current_limit = max_ma;
889-
890-
power_supply_changed(chip->psy);
891-
892879
return 0;
893880
}
894881

@@ -1682,43 +1669,6 @@ static irqreturn_t fusb302_irq_intn(int irq, void *dev_id)
16821669
return IRQ_HANDLED;
16831670
}
16841671

1685-
static int fusb302_psy_get_property(struct power_supply *psy,
1686-
enum power_supply_property psp,
1687-
union power_supply_propval *val)
1688-
{
1689-
struct fusb302_chip *chip = power_supply_get_drvdata(psy);
1690-
1691-
switch (psp) {
1692-
case POWER_SUPPLY_PROP_ONLINE:
1693-
val->intval = chip->charge_on;
1694-
break;
1695-
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
1696-
val->intval = chip->supply_voltage * 1000; /* mV -> µV */
1697-
break;
1698-
case POWER_SUPPLY_PROP_CURRENT_MAX:
1699-
val->intval = chip->current_limit * 1000; /* mA -> µA */
1700-
break;
1701-
default:
1702-
return -ENODATA;
1703-
}
1704-
1705-
return 0;
1706-
}
1707-
1708-
static enum power_supply_property fusb302_psy_properties[] = {
1709-
POWER_SUPPLY_PROP_ONLINE,
1710-
POWER_SUPPLY_PROP_VOLTAGE_NOW,
1711-
POWER_SUPPLY_PROP_CURRENT_MAX,
1712-
};
1713-
1714-
static const struct power_supply_desc fusb302_psy_desc = {
1715-
.name = "fusb302-typec-source",
1716-
.type = POWER_SUPPLY_TYPE_USB_TYPE_C,
1717-
.properties = fusb302_psy_properties,
1718-
.num_properties = ARRAY_SIZE(fusb302_psy_properties),
1719-
.get_property = fusb302_psy_get_property,
1720-
};
1721-
17221672
static int init_gpio(struct fusb302_chip *chip)
17231673
{
17241674
struct device_node *node;
@@ -1781,7 +1731,6 @@ static int fusb302_probe(struct i2c_client *client,
17811731
struct fusb302_chip *chip;
17821732
struct i2c_adapter *adapter;
17831733
struct device *dev = &client->dev;
1784-
struct power_supply_config cfg = {};
17851734
const char *name;
17861735
int ret = 0;
17871736
u32 v;
@@ -1823,14 +1772,6 @@ static int fusb302_probe(struct i2c_client *client,
18231772
return -EPROBE_DEFER;
18241773
}
18251774

1826-
cfg.drv_data = chip;
1827-
chip->psy = devm_power_supply_register(dev, &fusb302_psy_desc, &cfg);
1828-
if (IS_ERR(chip->psy)) {
1829-
ret = PTR_ERR(chip->psy);
1830-
dev_err(chip->dev, "Error registering power-supply: %d\n", ret);
1831-
return ret;
1832-
}
1833-
18341775
ret = fusb302_debugfs_init(chip);
18351776
if (ret < 0)
18361777
return ret;

0 commit comments

Comments
 (0)