smb138x-charger: configure connector temp thresholds

Add a device tree property qcom,connector-temp-max-mdegc to configure
the connector temperature at which mitigation should start.

This will set the thresholds for when the temperature-change IRQ will
fire.

Change-Id: I47df477b56a6654fbf94b5bb0f7dfdfb80e2f16e
Signed-off-by: Nicholas Troast <ntroast@codeaurora.org>
This commit is contained in:
Nicholas Troast 2017-01-31 19:23:10 -08:00
parent 294cded42d
commit 82ca1cbfca
3 changed files with 59 additions and 0 deletions

View file

@ -58,6 +58,12 @@ Charger specific properties:
Definition: Specifies the maximum charger temperature in milli-degrees
Celsius. If unspecified a default of 80000 will be used.
- qcom,connector-temp-max-mdegc
Usage: optional
Value type: <u32>
Definition: Specifies the maximum connector temperature in milli-degrees
Celsius. If unspecified a default value of 105000 will be used.
- io-channels
Usage: optional
Value type: List of <phandle u32>

View file

@ -135,6 +135,9 @@ struct smb_iio {
struct iio_channel *usbin_i_chan;
struct iio_channel *usbin_v_chan;
struct iio_channel *batt_i_chan;
struct iio_channel *connector_temp_thr1_chan;
struct iio_channel *connector_temp_thr2_chan;
struct iio_channel *connector_temp_thr3_chan;
};
struct reg_info {

View file

@ -93,6 +93,7 @@ struct smb_dt_props {
int usb_icl_ua;
int dc_icl_ua;
int chg_temp_max_mdegc;
int connector_temp_max_mdegc;
};
struct smb138x {
@ -142,6 +143,12 @@ static int smb138x_parse_dt(struct smb138x *chip)
if (rc < 0)
chip->dt.chg_temp_max_mdegc = 80000;
rc = of_property_read_u32(node,
"qcom,connector-temp-max-mdegc",
&chip->dt.chg_temp_max_mdegc);
if (rc < 0)
chip->dt.connector_temp_max_mdegc = 105000;
return 0;
}
@ -672,6 +679,8 @@ static int smb138x_init_vconn_regulator(struct smb138x *chip)
* HARDWARE INITIALIZATION *
***************************/
#define MDEGC_3 3000
#define MDEGC_15 15000
static int smb138x_init_slave_hw(struct smb138x *chip)
{
struct smb_charger *chg = &chip->chg;
@ -771,6 +780,26 @@ static int smb138x_init_slave_hw(struct smb138x *chip)
return rc;
}
rc = iio_write_channel_processed(chg->iio.connector_temp_thr1_chan,
chip->dt.connector_temp_max_mdegc);
if (rc < 0) {
pr_err("Couldn't set connector temp threshold1 rc=%d\n", rc);
return rc;
}
rc = iio_write_channel_processed(chg->iio.connector_temp_thr2_chan,
chip->dt.connector_temp_max_mdegc + MDEGC_3);
if (rc < 0) {
pr_err("Couldn't set connector temp threshold2 rc=%d\n", rc);
return rc;
}
rc = iio_write_channel_processed(chg->iio.connector_temp_thr3_chan,
chip->dt.connector_temp_max_mdegc + MDEGC_15);
if (rc < 0) {
pr_err("Couldn't set connector temp threshold3 rc=%d\n", rc);
return rc;
}
return 0;
}
@ -1277,6 +1306,27 @@ static int smb138x_slave_probe(struct smb138x *chip)
goto cleanup;
}
chg->iio.connector_temp_thr1_chan = iio_channel_get(chg->dev,
"connector_temp_thr1");
if (IS_ERR(chg->iio.connector_temp_thr1_chan)) {
rc = PTR_ERR(chg->iio.connector_temp_thr1_chan);
goto cleanup;
}
chg->iio.connector_temp_thr2_chan = iio_channel_get(chg->dev,
"connector_temp_thr2");
if (IS_ERR(chg->iio.connector_temp_thr2_chan)) {
rc = PTR_ERR(chg->iio.connector_temp_thr2_chan);
goto cleanup;
}
chg->iio.connector_temp_thr3_chan = iio_channel_get(chg->dev,
"connector_temp_thr3");
if (IS_ERR(chg->iio.connector_temp_thr3_chan)) {
rc = PTR_ERR(chg->iio.connector_temp_thr3_chan);
goto cleanup;
}
rc = smb138x_parse_dt(chip);
if (rc < 0) {
pr_err("Couldn't parse device tree rc=%d\n", rc);