mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-11 07:03:09 -04:00
charge: add iio interface for typeC mode
charge/typec add typeC mode iio interface form typec module Change-Id: I2df7d66757399924e03678e69e734637b5dac06e Signed-off-by: chailu1 <chailu1@lenovo.com> Reviewed-on: https://gerrit.mot.com/2106497 SME-Granted: SME Approvals Granted SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: Haijian Ma <mahj8@motorola.com> Reviewed-by: Huosheng Liao <liaohs@motorola.com> Submit-Approved: Jira Key
This commit is contained in:
parent
0222c9e9e7
commit
fbe06d4b12
4 changed files with 31 additions and 38 deletions
|
|
@ -314,8 +314,8 @@ static int get_usb_online(struct mmi_discrete_charger *chip,
|
|||
return rc;
|
||||
|
||||
//typec logic mask, bring up bc1.2 firstly
|
||||
if (/*(chip->typec_mode == MMI_POWER_SUPPLY_TYPEC_SOURCE_DEFAULT)
|
||||
&& */chip->real_charger_type == POWER_SUPPLY_TYPE_USB)
|
||||
if ((chip->typec_mode == MMI_POWER_SUPPLY_TYPEC_SOURCE_DEFAULT)
|
||||
&& chip->real_charger_type == POWER_SUPPLY_TYPE_USB)
|
||||
val->intval = 0;
|
||||
else
|
||||
val->intval = 1;
|
||||
|
|
@ -336,9 +336,9 @@ static int get_usb_port_online(struct mmi_discrete_charger *chip,
|
|||
return rc;
|
||||
|
||||
//typec logic mask, bring up bc1.2 firstly
|
||||
if (/*(chip->typec_mode ==
|
||||
if ((chip->typec_mode ==
|
||||
MMI_POWER_SUPPLY_TYPEC_SOURCE_DEFAULT)
|
||||
&& */chip->real_charger_type == POWER_SUPPLY_TYPE_USB)
|
||||
&& chip->real_charger_type == POWER_SUPPLY_TYPE_USB)
|
||||
val->intval = 1;
|
||||
else
|
||||
val->intval = 0;
|
||||
|
|
@ -502,12 +502,6 @@ static int set_prop_dc_current_max(struct mmi_discrete_charger *chip,
|
|||
return rc;
|
||||
}
|
||||
|
||||
static int mmi_get_prop_typec_mode(struct mmi_discrete_charger *chg)
|
||||
{
|
||||
//need to get typec mode
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mmi_get_rp_based_dcp_current(struct mmi_discrete_charger *chg, int typec_mode)
|
||||
{
|
||||
int rp_ua;
|
||||
|
|
@ -531,7 +525,7 @@ static int mmi_get_rp_based_dcp_current(struct mmi_discrete_charger *chg, int ty
|
|||
static int mmi_discrete_handle_usb_current(struct mmi_discrete_charger *chg,
|
||||
int usb_current)
|
||||
{
|
||||
int rc = 0, rp_ua, typec_mode;
|
||||
int rc = 0, rp_ua;
|
||||
union power_supply_propval val = {0, };
|
||||
|
||||
if (chg->real_charger_type == POWER_SUPPLY_TYPE_USB_FLOAT) {
|
||||
|
|
@ -540,9 +534,8 @@ static int mmi_discrete_handle_usb_current(struct mmi_discrete_charger *chg,
|
|||
* Valid FLOAT charger, report the current
|
||||
* based of Rp.
|
||||
*/
|
||||
typec_mode = mmi_get_prop_typec_mode(chg);
|
||||
rp_ua = mmi_get_rp_based_dcp_current(chg,
|
||||
typec_mode);
|
||||
chg->typec_mode);
|
||||
rc = vote(chg->usb_icl_votable,
|
||||
SW_ICL_MAX_VOTER, true, rp_ua);
|
||||
if (rc < 0)
|
||||
|
|
@ -568,8 +561,7 @@ static int mmi_discrete_handle_usb_current(struct mmi_discrete_charger *chg,
|
|||
if (!rc && !val.intval)
|
||||
return 0;
|
||||
|
||||
typec_mode = mmi_get_prop_typec_mode(chg);
|
||||
if (typec_rp_med_high(chg, typec_mode)) {
|
||||
if (typec_rp_med_high(chg, chg->typec_mode)) {
|
||||
vote(chg->usb_icl_votable, USB_PSY_VOTER,
|
||||
false, 0);
|
||||
return 0;
|
||||
|
|
@ -1639,7 +1631,6 @@ static void mmi_notify_device_mode(struct mmi_discrete_charger *chg, bool enable
|
|||
|
||||
static void update_sw_icl_max(struct mmi_discrete_charger *chg)
|
||||
{
|
||||
int typec_mode;
|
||||
int rp_ua;
|
||||
|
||||
/* while PD is active it should have complete ICL control */
|
||||
|
|
@ -1659,9 +1650,8 @@ static void update_sw_icl_max(struct mmi_discrete_charger *chg)
|
|||
return;
|
||||
|
||||
/* TypeC rp med or high, use rp value */
|
||||
typec_mode = mmi_get_prop_typec_mode(chg);
|
||||
if (typec_rp_med_high(chg, typec_mode)) {
|
||||
rp_ua = mmi_get_rp_based_dcp_current(chg, typec_mode);
|
||||
if (typec_rp_med_high(chg, chg->typec_mode)) {
|
||||
rp_ua = mmi_get_rp_based_dcp_current(chg, chg->typec_mode);
|
||||
vote(chg->usb_icl_votable, SW_ICL_MAX_VOTER, true, rp_ua);
|
||||
vote(chg->usb_icl_votable, USB_PSY_VOTER, false, 0);
|
||||
return;
|
||||
|
|
@ -1683,7 +1673,7 @@ static void update_sw_icl_max(struct mmi_discrete_charger *chg)
|
|||
vote(chg->usb_icl_votable, USB_PSY_VOTER, false, 0);
|
||||
break;
|
||||
case POWER_SUPPLY_TYPE_USB_DCP:
|
||||
rp_ua = mmi_get_rp_based_dcp_current(chg, typec_mode);
|
||||
rp_ua = mmi_get_rp_based_dcp_current(chg, chg->typec_mode);
|
||||
vote(chg->usb_icl_votable, SW_ICL_MAX_VOTER, true, rp_ua);
|
||||
vote(chg->usb_icl_votable, USB_PSY_VOTER, false, 0);
|
||||
break;
|
||||
|
|
@ -1725,6 +1715,21 @@ static void mmi_handle_apsd_done(struct mmi_discrete_charger *chip, bool apsd_do
|
|||
chip->real_charger_type);
|
||||
}
|
||||
|
||||
int mmi_discrete_config_typec_mode(struct mmi_discrete_charger *chip, int val)
|
||||
{
|
||||
mmi_info(chip, "config typec mode is %d old mode is %d\n", val, chip->typec_mode);
|
||||
|
||||
if (val != chip->typec_mode) {
|
||||
chip->typec_mode = val;
|
||||
update_sw_icl_max(chip);
|
||||
|
||||
if (chip->usb_psy)
|
||||
power_supply_changed(chip->usb_psy);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mmi_discrete_usb_plugout(struct mmi_discrete_charger * chip)
|
||||
{
|
||||
chip->real_charger_type = POWER_SUPPLY_TYPE_UNKNOWN;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
#include <linux/iio/iio.h>
|
||||
#include <linux/extcon-provider.h>
|
||||
#include "mmi_charger.h"
|
||||
#include <linux/usb/mmi_discrete_typec.h>
|
||||
|
||||
#define MMI_HB_VOTER "MMI_HB_VOTER"
|
||||
#define USER_VOTER "USER_VOTER"
|
||||
|
|
@ -49,24 +50,6 @@ enum {
|
|||
MMI_POWER_SUPPLY_DP_DM_DM_PULSE = 2,
|
||||
};
|
||||
|
||||
/* Indicates USB Type-C CC connection status */
|
||||
enum power_supply_typec_mode {
|
||||
MMI_POWER_SUPPLY_TYPEC_NONE,
|
||||
|
||||
/* Acting as source */
|
||||
MMI_POWER_SUPPLY_TYPEC_SINK, /* Rd only */
|
||||
MMI_POWER_SUPPLY_TYPEC_SINK_POWERED_CABLE, /* Rd/Ra */
|
||||
MMI_POWER_SUPPLY_TYPEC_SINK_DEBUG_ACCESSORY,/* Rd/Rd */
|
||||
MMI_POWER_SUPPLY_TYPEC_SINK_AUDIO_ADAPTER, /* Ra/Ra */
|
||||
MMI_POWER_SUPPLY_TYPEC_POWERED_CABLE_ONLY, /* Ra only */
|
||||
|
||||
/* Acting as sink */
|
||||
MMI_POWER_SUPPLY_TYPEC_SOURCE_DEFAULT, /* Rp default */
|
||||
MMI_POWER_SUPPLY_TYPEC_SOURCE_MEDIUM, /* Rp 1.5A */
|
||||
MMI_POWER_SUPPLY_TYPEC_SOURCE_HIGH, /* Rp 3A */
|
||||
MMI_POWER_SUPPLY_TYPEC_NON_COMPLIANT,
|
||||
};
|
||||
|
||||
struct mmi_discrete_chg_client {
|
||||
struct mmi_discrete_charger *chip;
|
||||
struct mmi_battery_info batt_info;
|
||||
|
|
@ -143,5 +126,6 @@ struct mmi_discrete_charger {
|
|||
|
||||
int mmi_discrete_otg_enable(struct mmi_discrete_charger *chip, bool en);
|
||||
int mmi_discrete_is_usb_suspended(struct mmi_discrete_charger *chip);
|
||||
int mmi_discrete_config_typec_mode(struct mmi_discrete_charger *chip, int val);
|
||||
|
||||
#endif
|
||||
|
|
@ -23,6 +23,9 @@ static int mmi_discrete_iio_write_raw(struct iio_dev *indio_dev,
|
|||
case PSY_IIO_MMI_OTG_ENABLE:
|
||||
rc = mmi_discrete_otg_enable(chip, !!val1);
|
||||
break;
|
||||
case PSY_IIO_TYPEC_MODE:
|
||||
rc = mmi_discrete_config_typec_mode(chip, val1);
|
||||
break;
|
||||
default:
|
||||
pr_err("Unsupported mmi_discrete IIO chan %d\n", chan->channel);
|
||||
rc = -EINVAL;
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ struct mmi_discrete_iio_channels {
|
|||
static const struct mmi_discrete_iio_channels mmi_discrete_iio_psy_channels[] = {
|
||||
MMI_DISCRETE_CHAN_INDEX("usb_real_type", PSY_IIO_USB_REAL_TYPE)
|
||||
MMI_DISCRETE_CHAN_INDEX("otg_enable", PSY_IIO_MMI_OTG_ENABLE)
|
||||
MMI_DISCRETE_CHAN_INDEX("typec_mode", PSY_IIO_TYPEC_MODE)
|
||||
};
|
||||
|
||||
int mmi_discrete_init_iio_psy(struct mmi_discrete_charger *chip,
|
||||
|
|
|
|||
Loading…
Reference in a new issue