Skip to content

Commit

Permalink
bq25890: Add max input limit property and input_voltage_now attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
jekhor committed Jan 10, 2019
1 parent 63796a9 commit 4cfbd13
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions drivers/power/supply/bq25890_charger.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ struct bq25890_init_data {
u8 boostf; /* boost frequency */
u8 ilim_en; /* enable ILIM pin */
u8 treg; /* thermal regulation threshold */
u8 iinlim_max; /* maximum input current limit allowed */
};

struct bq25890_state {
Expand Down Expand Up @@ -687,7 +688,8 @@ 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_TREG, bq->init_data.treg}
{F_TREG, bq->init_data.treg},
{F_IINLIM, bq->init_data.iinlim_max},
};

/* Don't reset chip at driver initialization if property 'disable-reset'
Expand Down Expand Up @@ -768,6 +770,24 @@ static const struct power_supply_desc bq25890_power_supply_desc = {
.get_property = bq25890_power_supply_get_property,
};


static ssize_t bq25890_show_input_voltage(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct bq25890_device *bq = dev_get_drvdata(dev);
int ret;

ret = bq25890_field_read(bq, F_VBUSV);
if (ret < 0)
return ret;

return scnprintf(buf, PAGE_SIZE, "%u", ret * 100000 + 2600000);
}

DEVICE_ATTR(input_voltage_now, S_IRUGO, bq25890_show_input_voltage, NULL);


static int bq25890_power_supply_init(struct bq25890_device *bq)
{
struct power_supply_config psy_cfg = { .drv_data = bq, };
Expand Down Expand Up @@ -821,14 +841,19 @@ static void bq25890_usb_work(struct work_struct *data)
default:
if (bq->usb_event >= 100) {
/* Charger max current event */
unsigned int ilim;
u8 iinlim;
unsigned long mA = bq->usb_event;

if (mA > 3250)
mA = 3250;

ilim = (mA - 100) / 50;
ret = bq25890_field_write(bq, F_IINLIM, ilim);
iinlim = bq25890_find_idx(mA * 1000, TBL_IINLIM);

dev_dbg(bq->dev, "Found iilim = %u, bq->init_data.iinlim_max = %u\n", iinlim, bq->init_data.iinlim_max);

iinlim = min(bq->init_data.iinlim_max, iinlim);

ret = bq25890_field_write(bq, F_IINLIM, iinlim);
if (ret)
goto error;

Expand All @@ -844,7 +869,8 @@ static void bq25890_usb_work(struct work_struct *data)

power_supply_changed(bq->charger);

dev_dbg(bq->dev, "Set max input current to %lu mA (ILIM=0x%x)\n", mA, ilim);
dev_dbg(bq->dev, "Set input current limit to %u mA (IINLIM=0x%x)\n",
bq25890_find_val(iinlim, TBL_IINLIM) / 1000, iinlim);
} else {
dev_dbg(bq->dev, "Unknown USB event %lu\n", bq->usb_event);
}
Expand Down Expand Up @@ -946,11 +972,13 @@ static int bq25890_fw_read_u32_props(struct bq25890_device *bq)
{"ti,boost-max-current", false, TBL_BOOSTI, &init->boosti},

/* optional properties */
{"ti,thermal-regulation-threshold", true, TBL_TREG, &init->treg}
{"ti,thermal-regulation-threshold", true, TBL_TREG, &init->treg},
{"ti,input-max-current", true, TBL_IINLIM, &init->iinlim_max},
};

/* initialize data for optional properties */
init->treg = 3; /* 120 degrees Celsius */
init->iinlim_max = 0x3f;

for (i = 0; i < ARRAY_SIZE(props); i++) {
ret = device_property_read_u32(bq->dev, props[i].name,
Expand Down

0 comments on commit 4cfbd13

Please sign in to comment.