Commit 71ba0565 authored by Guido Gunther's avatar Guido Gunther

Merge branches 'usb-c-current' and 'drop-keys' into agx

Pipeline #63074 passed with stage
in 63 minutes and 16 seconds
......@@ -33,6 +33,7 @@ Optional properties:
- ti,thermal-regulation-threshold: integer, temperature above which the charge
current is lowered, to avoid overheating (in degrees Celsius). If omitted,
the default setting will be used (120 degrees);
- ti,auto_dpdm_disable: disable the auto_dpdm negotiation
Example:
......
......@@ -561,7 +561,7 @@ MX8MQ_IOMUXC_NAND_CE3_B_GPIO3_IO4 0x3
pinctrl_charger_in: chargeringrp {
fsl,pins = <
/* CHRG_INT */
MX8MQ_IOMUXC_NAND_CE2_B_GPIO3_IO3 0x00
MX8MQ_IOMUXC_NAND_CE2_B_GPIO3_IO3 0x80
/* CHG_STATUS_B */
MX8MQ_IOMUXC_NAND_ALE_GPIO3_IO0 0x80
>;
......@@ -1457,10 +1457,11 @@ bq25895: charger@6a {
ti,termination-current = <128000>; /* uA */
ti,precharge-current = <128000>; /* uA */
ti,minimum-sys-voltage = <3700000>; /* uV */
ti,boost-voltage = <15000000>; /* uV */
ti,boost-max-current = <500000>; /* uA */
ti,boost-voltage = <5000000>; /* uV */
ti,boost-max-current = <1500000>; /* uA */
ti,use-vinmin-threshold = <1>; /* enable VINDPM */
ti,vinmin-threshold = <3900000>; /* uV */
ti,auto_dpdm_disable;
monitored-battery = <&bat>;
power-supplies = <&tps65982>;
otg-gpios = <&gpio3 4 GPIO_ACTIVE_HIGH>;
......
......@@ -83,6 +83,7 @@ struct bq25890_init_data {
u8 boosti; /* boost current limit */
u8 boostf; /* boost frequency */
u8 ilim_en; /* enable ILIM pin */
u8 auto_dpdm_en; /* enable auto_dpdm - enabled is the default */
u8 force_vindpm;/* force vinmin threshold */
u8 vindpm; /* vinmin threshold */
u8 treg; /* thermal regulation threshold */
......@@ -678,6 +679,7 @@ static int bq25890_hw_init(struct bq25890_device *bq)
{F_BOOSTI, bq->init_data.boosti},
{F_BOOSTF, bq->init_data.boostf},
{F_EN_ILIM, bq->init_data.ilim_en},
{F_AUTO_DPDM_EN, bq->init_data.auto_dpdm_en},
{F_FORCE_VINDPM, bq->init_data.force_vindpm},
{F_VINDPM, bq->init_data.vindpm},
{F_TREG, bq->init_data.treg}
......@@ -754,19 +756,53 @@ static void bq25890_external_power_changed(struct power_supply *psy)
{
struct bq25890_device *bq = power_supply_get_drvdata(psy);
bool supplied;
int ret;
int ret, max_current = 500; /* mA, save default */
struct power_supply *psy_supply;
union power_supply_propval val;
supplied = power_supply_am_i_supplied(bq->charger);
dev_info(bq->dev, "Upstream supply changed: %d.\n", supplied);
if (!bq->otg_en)
psy_supply = power_supply_get_by_name(*bq->charger->supplied_from);
if (IS_ERR(psy_supply)) {
dev_err(bq->dev, "Failed to get upstream supply: %ld\n", PTR_ERR(psy_supply));
return;
}
dev_info(bq->dev, "%sabling OTG_EN pin\n", supplied ? "dis" : "en");
gpiod_set_value_cansleep(bq->otg_en, !supplied);
ret = bq25890_field_write(bq, F_CHG_CFG, supplied);
if (ret < 0)
dev_err(bq->dev, "Failed to set charging to %d", supplied);
if (supplied) {
if (bq->otg_en) {
dev_info(bq->dev, "Disabling OTG_EN pin\n");
gpiod_set_value_cansleep(bq->otg_en, 0);
}
ret = bq25890_field_write(bq, F_OTG_CFG, 0);
if (ret < 0)
dev_err(bq->dev, "Failed to disable otg: %d\n", ret);
if (!power_supply_get_property(psy_supply, POWER_SUPPLY_PROP_CURRENT_MAX, &val))
max_current = val.intval / 1000;
else
dev_err(bq->dev, "Failed to get supply current\n");
/* Just as a safety net for now */
if (max_current < 100 || max_current > 3000) {
dev_err(bq->dev, "Max_current out of range: %d\n", max_current);
max_current = 500;
}
dev_dbg(bq->dev, "Setting max current to %dmA\n", max_current);
ret = bq25890_field_write(bq, F_IILIM, (max_current-100)/50);
if (ret < 0)
dev_err(bq->dev, "Failed to set IILIM: %d\n", ret);
} else {
if (bq->otg_en) {
dev_info(bq->dev, "Enabling OTG_EN pin\n");
gpiod_set_value_cansleep(bq->otg_en, 1);
}
ret = bq25890_field_write(bq, F_OTG_CFG, 1);
if (ret < 0)
dev_err(bq->dev, "Failed to enable otg: %d\n", ret);
}
power_supply_changed(bq->charger);
}
......@@ -959,6 +995,8 @@ static int bq25890_fw_probe(struct bq25890_device *bq)
init->ilim_en = device_property_read_bool(bq->dev, "ti,use-ilim-pin");
init->boostf = device_property_read_bool(bq->dev, "ti,boost-low-freq");
/* use the inverse so that we don't change the default behaviour */
init->auto_dpdm_en = !device_property_read_bool(bq->dev, "ti,auto_dpdm_disable");
return 0;
}
......
......@@ -64,9 +64,10 @@ config TYPEC_HD3SS3220
config TYPEC_TPS6598X
tristate "TI TPS6598x USB Power Delivery controller driver"
depends on I2C
depends on REGMAP_I2C
depends on USB_ROLE_SWITCH || !USB_ROLE_SWITCH
depends on EXTCON
select EXTCON
select POWER_SUPPLY
select REGMAP_I2C
select USB_ROLE_SWITCH
help
Say Y or M here if your system has TI TPS65982 or TPS65983 USB Power
Delivery controller.
......
# SPDX-License-Identifier: GPL-2.0
# define_trace.h needs to know how to find our header
CFLAGS_tps6598x.o := -I$(src)
obj-$(CONFIG_TYPEC) += typec.o
typec-y := class.o mux.o bus.o
obj-$(CONFIG_TYPEC) += altmodes/
......
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0+ */
/*
* Driver for TI TPS6598x USB Power Delivery controller family
*
* Copyright (C) 2017, Intel Corporation
* Author: Heikki Krogerus <heikki.krogerus@linux.intel.com>
*/
#include <linux/bitfield.h>
#ifndef __TPS6598X_H__
#define __TPS6598X_H__
/* TPS_REG_STATUS bits */
#define TPS_STATUS_PLUG_PRESENT BIT(0)
#define TPS_STATUS_PLUG_UPSIDE_DOWN BIT(4)
#define TPS_STATUS_PORTROLE BIT(5)
#define TPS_STATUS_TO_TYPEC_PORTROLE(s) (!!((s) & TPS_STATUS_PORTROLE))
#define TPS_STATUS_DATAROLE BIT(6)
#define TPS_STATUS_TO_TYPEC_DATAROLE(s) (!!((s) & TPS_STATUS_DATAROLE))
#define TPS_STATUS_VCONN BIT(7)
#define TPS_STATUS_TO_TYPEC_VCONN(s) (!!((s) & TPS_STATUS_VCONN))
#define TPS_STATUS_OVERCURRENT BIT(16)
#define TPS_STATUS_GOTO_MIN_ACTIVE BIT(26)
#define TPS_STATUS_BIST BIT(27)
#define TPS_STATUS_HIGH_VOLAGE_WARNING BIT(28)
#define TPS_STATUS_HIGH_LOW_VOLTAGE_WARNING BIT(29)
#define TPS_STATUS_CONN_STATE_MASK GENMASK(3, 1)
#define TPS_STATUS_CONN_STATE(x) FIELD_GET(TPS_STATUS_CONN_STATE_MASK, (x))
#define TPS_STATUS_PP_5V0_SWITCH_MASK GENMASK(9, 8)
#define TPS_STATUS_PP_5V0_SWITCH(x) FIELD_GET(TPS_STATUS_PP_5V0_SWITCH_MASK, (x))
#define TPS_STATUS_PP_HV_SWITCH_MASK GENMASK(11, 10)
#define TPS_STATUS_PP_HV_SWITCH(x) FIELD_GET(TPS_STATUS_PP_HV_SWITCH_MASK, (x))
#define TPS_STATUS_PP_EXT_SWITCH_MASK GENMASK(13, 12)
#define TPS_STATUS_PP_EXT_SWITCH(x) FIELD_GET(TPS_STATUS_PP_EXT_SWITCH_MASK, (x))
#define TPS_STATUS_PP_CABLE_SWITCH_MASK GENMASK(15, 14)
#define TPS_STATUS_PP_CABLE_SWITCH(x) FIELD_GET(TPS_STATUS_PP_CABLE_SWITCH_MASK, (x))
#define TPS_STATUS_POWER_SOURCE_MASK GENMASK(19, 18)
#define TPS_STATUS_POWER_SOURCE(x) FIELD_GET(TPS_STATUS_POWER_SOURCE_MASK, (x))
#define TPS_STATUS_VBUS_STATUS_MASK GENMASK(21, 20)
#define TPS_STATUS_VBUS_STATUS(x) FIELD_GET(TPS_STATUS_VBUS_STATUS_MASK, (x))
#define TPS_STATUS_USB_HOST_PRESENT_MASK GENMASK(23, 22)
#define TPS_STATUS_USB_HOST_PRESENT(x) FIELD_GET(TPS_STATUS_USB_HOST_PRESENT_MASK, (x))
#define TPS_STATUS_LEGACY_MASK GENMASK(25, 24)
#define TPS_STATUS_LEGACY(x) FIELD_GET(TPS_STATUS_LEGACY_MASK, (x))
#define TPS_STATUS_CONN_STATE_NO_CONN 0
#define TPS_STATUS_CONN_STATE_DISABLED 1
#define TPS_STATUS_CONN_STATE_AUDIO_CONN 2
#define TPS_STATUS_CONN_STATE_DEBUG_CONN 3
#define TPS_STATUS_CONN_STATE_NO_CONN_R_A 4
#define TPS_STATUS_CONN_STATE_RESERVED 5
#define TPS_STATUS_CONN_STATE_CONN_NO_R_A 6
#define TPS_STATUS_CONN_STATE_CONN_WITH_R_A 7
#define TPS_STATUS_PP_SWITCH_STATE_DISABLED 0
#define TPS_STATUS_PP_SWITCH_STATE_FAULT 1
#define TPS_STATUS_PP_SWITCH_STATE_OUT 2
#define TPS_STATUS_PP_SWITCH_STATE_IN 3
#define TPS_STATUS_POWER_SOURCE_UNKNOWN 0
#define TPS_STATUS_POWER_SOURCE_VIN_3P3 1
#define TPS_STATUS_POWER_SOURCE_DEAD_BAT 2
#define TPS_STATUS_POWER_SOURCE_VBUS 3
#define TPS_STATUS_VBUS_STATUS_VSAFE0V 0
#define TPS_STATUS_VBUS_STATUS_VSAFE5V 1
#define TPS_STATUS_VBUS_STATUS_PD 2
#define TPS_STATUS_VBUS_STATUS_FAULT 3
#define TPS_STATUS_USB_HOST_PRESENT_NO 0
#define TPS_STATUS_USB_HOST_PRESENT_PD_NO_USB 1
#define TPS_STATUS_USB_HOST_PRESENT_NO_PD 2
#define TPS_STATUS_USB_HOST_PRESENT_PD_USB 3
#define TPS_STATUS_LEGACY_NO 0
#define TPS_STATUS_LEGACY_SINK 1
#define TPS_STATUS_LEGACY_SOURCE 2
/* TPS_REG_INT_* bits */
#define TPS_REG_INT_USER_VID_ALT_MODE_OTHER_VDM BIT(27+32)
#define TPS_REG_INT_USER_VID_ALT_MODE_ATTN_VDM BIT(26+32)
#define TPS_REG_INT_USER_VID_ALT_MODE_EXIT BIT(25+32)
#define TPS_REG_INT_USER_VID_ALT_MODE_ENTERED BIT(24+32)
#define TPS_REG_INT_EXIT_MODES_COMPLETE BIT(20+32)
#define TPS_REG_INT_DISCOVER_MODES_COMPLETE BIT(19+32)
#define TPS_REG_INT_VDM_MSG_SENT BIT(18+32)
#define TPS_REG_INT_VDM_ENTERED_MODE BIT(17+32)
#define TPS_REG_INT_ERROR_UNABLE_TO_SOURCE BIT(14+32)
#define TPS_REG_INT_SRC_TRANSITION BIT(10+32)
#define TPS_REG_INT_ERROR_DISCHARGE_FAILED BIT(9+32)
#define TPS_REG_INT_ERROR_MESSAGE_DATA BIT(7+32)
#define TPS_REG_INT_ERROR_PROTOCOL_ERROR BIT(6+32)
#define TPS_REG_INT_ERROR_MISSING_GET_CAP_MESSAGE BIT(4+32)
#define TPS_REG_INT_ERROR_POWER_EVENT_OCCURRED BIT(3+32)
#define TPS_REG_INT_ERROR_CAN_PROVIDE_PWR_LATER BIT(2+32)
#define TPS_REG_INT_ERROR_CANNOT_PROVIDE_PWR BIT(1+32)
#define TPS_REG_INT_ERROR_DEVICE_INCOMPATIBLE BIT(0+32)
#define TPS_REG_INT_CMD2_COMPLETE BIT(31)
#define TPS_REG_INT_CMD1_COMPLETE BIT(30)
#define TPS_REG_INT_ADC_HIGH_THRESHOLD BIT(29)
#define TPS_REG_INT_ADC_LOW_THRESHOLD BIT(28)
#define TPS_REG_INT_PD_STATUS_UPDATE BIT(27)
#define TPS_REG_INT_STATUS_UPDATE BIT(26)
#define TPS_REG_INT_DATA_STATUS_UPDATE BIT(25)
#define TPS_REG_INT_POWER_STATUS_UPDATE BIT(24)
#define TPS_REG_INT_PP_SWITCH_CHANGED BIT(23)
#define TPS_REG_INT_HIGH_VOLTAGE_WARNING BIT(22)
#define TPS_REG_INT_USB_HOST_PRESENT_NO_LONGER BIT(21)
#define TPS_REG_INT_USB_HOST_PRESENT BIT(20)
#define TPS_REG_INT_GOTO_MIN_RECEIVED BIT(19)
#define TPS_REG_INT_PR_SWAP_REQUESTED BIT(17)
#define TPS_REG_INT_SINK_CAP_MESSAGE_READY BIT(15)
#define TPS_REG_INT_SOURCE_CAP_MESSAGE_READY BIT(14)
#define TPS_REG_INT_NEW_CONTRACT_AS_PROVIDER BIT(13)
#define TPS_REG_INT_NEW_CONTRACT_AS_CONSUMER BIT(12)
#define TPS_REG_INT_VDM_RECEIVED BIT(11)
#define TPS_REG_INT_ATTENTION_RECEIVED BIT(10)
#define TPS_REG_INT_OVERCURRENT BIT(9)
#define TPS_REG_INT_BIST BIT(8)
#define TPS_REG_INT_RDO_RECEIVED_FROM_SINK BIT(7)
#define TPS_REG_INT_DR_SWAP_COMPLETE BIT(5)
#define TPS_REG_INT_PR_SWAP_COMPLETE BIT(4)
#define TPS_REG_INT_PLUG_EVENT BIT(3)
#define TPS_REG_INT_HARD_RESET BIT(1)
#define TPS_REG_INT_PD_SOFT_RESET BIT(0)
/* TPS_REG_POWER_STATUS bits */
#define TPS_POWER_STATUS_CONNECTION(x) FIELD_GET(BIT(0), (x))
#define TPS_POWER_STATUS_SOURCESINK(x) FIELD_GET(BIT(1), (x))
#define TPS_POWER_STATUS_BC12_DET(x) FIELD_GET(BIT(2), (x))
#define TPS_POWER_STATUS_TYPEC_CURRENT_MASK GENMASK(3, 2)
#define TPS_POWER_STATUS_PWROPMODE(p) FIELD_GET(TPS_POWER_STATUS_TYPEC_CURRENT_MASK, (p))
#define TPS_POWER_STATUS_BC12_STATUS_MASK GENMASK(6, 5)
#define TPS_POWER_STATUS_BC12_STATUS(p) FIELD_GET(TPS_POWER_STATUS_BC12_STATUS_MASK, (p))
#define TPS_POWER_STATUS_TYPEC_CURRENT_USB 0
#define TPS_POWER_STATUS_TYPEC_CURRENT_1A5 1
#define TPS_POWER_STATUS_TYPEC_CURRENT_3A0 2
#define TPS_POWER_STATUS_TYPEC_CURRENT_PD 3
#define TPS_POWER_STATUS_BC12_STATUS_SDP 0
#define TPS_POWER_STATUS_BC12_STATUS_CDP 2
#define TPS_POWER_STATUS_BC12_STATUS_DCP 3
/* TPS_REG_DATA_STATUS bits */
#define TPS_DATA_STATUS_DATA_CONNECTION BIT(0)
#define TPS_DATA_STATUS_UPSIDE_DOWN BIT(1)
#define TPS_DATA_STATUS_ACTIVE_CABLE BIT(2)
#define TPS_DATA_STATUS_USB2_CONNECTION BIT(4)
#define TPS_DATA_STATUS_USB3_CONNECTION BIT(5)
#define TPS_DATA_STATUS_USB3_GEN2 BIT(6)
#define TPS_DATA_STATUS_USB_DATA_ROLE BIT(7)
#define TPS_DATA_STATUS_DP_CONNECTION BIT(8)
#define TPS_DATA_STATUS_DP_SINK BIT(9)
#define TPS_DATA_STATUS_TBT_CONNECTION BIT(16)
#define TPS_DATA_STATUS_TBT_TYPE BIT(17)
#define TPS_DATA_STATUS_OPTICAL_CABLE BIT(18)
#define TPS_DATA_STATUS_ACTIVE_LINK_TRAIN BIT(20)
#define TPS_DATA_STATUS_FORCE_LSX BIT(23)
#define TPS_DATA_STATUS_POWER_MISMATCH BIT(24)
#define TPS_DATA_STATUS_DP_PIN_ASSIGNMENT_MASK GENMASK(11, 10)
#define TPS_DATA_STATUS_DP_PIN_ASSIGNMENT(x) \
FIELD_GET(TPS_DATA_STATUS_DP_PIN_ASSIGNMENT_MASK, (x))
#define TPS_DATA_STATUS_TBT_CABLE_SPEED_MASK GENMASK(27, 25)
#define TPS_DATA_STATUS_TBT_CABLE_SPEED FIELD_GET(TPS_DATA_STATUS_TBT_CABLE_SPEED_MASK, (x))
#define TPS_DATA_STATUS_TBT_CABLE_GEN_MASK GENMASK(29, 28)
#define TPS_DATA_STATUS_TBT_CABLE_GEN FIELD_GET(TPS_DATA_STATUS_TBT_CABLE_GEN_MASK, (x))
/* Map data status to DP spec assignements */
#define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT(x) \
((TPS_DATA_STATUS_DP_PIN_ASSIGNMENT(x) << 1) | \
FIELD_GET(TPS_DATA_STATUS_USB3_CONNECTION, (x)))
#define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_E 0
#define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_F BIT(0)
#define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_C BIT(1)
#define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_D (BIT(1) | BIT(0))
#define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_A BIT(2)
#define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_B (BIT(2) | BIT(1))
/* PDO decoding as in https://www.ti.com/lit/an/slva842/slva842.pdf */
#define TPS_PDO_CONTRACT_TYPE(x) FIELD_GET(GENMASK(31, 30), x)
#define TPS_PDO_CONTRACT_FIXED 0
#define TPS_PDO_CONTRACT_BATTERY 1
#define TPS_PDO_CONTRACT_VARIABLE 2
#define TPS_PDO_FIXED_CONTRACT_DETAILS GENMASK(29, 25)
#define TPS_PDO_FIXED_CONTRACT_DR_POWER BIT(29)
#define TPS_PDO_FIXED_CONTRACT_USB_SUSPEND BIT(28)
#define TPS_PDO_FIXED_CONTRACT_EXTERNAL_PWR BIT(27)
#define TPS_PDO_FIXED_CONTRACT_USB_COMMS BIT(26)
#define TPS_PDO_FIXED_CONTRACT_DR_DATA BIT(25)
#define TPS_PDO_FIXED_CONTRACT_VOLTAGE(x) (FIELD_GET(GENMASK(19, 10), x) * 50000)
#define TPS_PDO_FIXED_CONTRACT_MAX_CURRENT(x) (FIELD_GET(GENMASK(9, 0), x) * 10000)
#define TPS_PDO_VAR_CONTRACT_MAX_VOLTAGE(x) (FIELD_GET(GENMASK(29, 20), x) * 50000)
#define TPS_PDO_VAR_CONTRACT_MIN_VOLTAGE(x) (FIELD_GET(GENMASK(19, 10), x) * 50000)
#define TPS_PDO_VAR_CONTRACT_MAX_CURRENT(x) (FIELD_GET(GENMASK(9, 0), x) * 10000)
#define TPS_PDO_BAT_CONTRACT_MAX_VOLTAGE(x) (FIELD_GET(GENMASK(29, 20), x) * 50000)
#define TPS_PDO_BAT_CONTRACT_MIN_VOLTAGE(x) (FIELD_GET(GENMASK(19, 10), x) * 50000)
#define TPS_PDO_BAT_CONTRACT_MAX_POWER(x) (FIELD_GET(GENMASK(9, 0), x) * 250000)
struct tps6598x_pdo {
u32 pdo;
int max_voltage; /* uV */
int max_current; /* uA */
int max_power; /* uW */
};
#endif /* __TPS6598X_H__ */
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment