/* * This means the line is asserted. * * The signal is active low, but the inversion is handled in the GPIO * library as the line should be flagged GPIO_ACTIVE_LOW in the device * tree.
*/
ta_in = gpiod_get_value(data->dok);
if (ta_in == data->ta_in) return IRQ_HANDLED;
data->ta_in = ta_in;
/* Set Current-Limit-Mode 1:DC 0:USB */ if (data->dcm)
gpiod_set_value(data->dcm, ta_in);
/* Charger Enable / Disable */ if (data->cen) { int val;
if (ta_in) /* Certainly enable if DOK is asserted */
val = 1; elseif (data->usb_in) /* Enable if the USB charger is enabled */
val = 1; else /* Else default-disable */
val = 0;
/* * This means the line is asserted. * * The signal is active low, but the inversion is handled in the GPIO * library as the line should be flagged GPIO_ACTIVE_LOW in the device * tree.
*/
usb_in = gpiod_get_value(data->uok);
if (usb_in == data->usb_in) return IRQ_HANDLED;
data->usb_in = usb_in;
/* Do not touch Current-Limit-Mode */
/* Charger Enable / Disable */ if (data->cen) { int val;
if (usb_in) /* Certainly enable if UOK is asserted */
val = 1; elseif (data->ta_in) /* Enable if the DC charger is enabled */
val = 1; else /* Else default-disable */
val = 0;
/* * This means the line is asserted. * * The signal is active low, but the inversion is handled in the GPIO * library as the line should be flagged GPIO_ACTIVE_LOW in the device * tree.
*/
fault = gpiod_get_value(data->flt);
if (fault == data->fault) return IRQ_HANDLED;
data->fault = fault;
if (fault)
dev_err(data->dev, "Charger suffers a fault and stops.\n"); else
dev_err(data->dev, "Charger recovered from a fault.\n");
data->dok = devm_gpiod_get_optional(dev, "dok", GPIOD_IN); if (IS_ERR(data->dok)) return dev_err_probe(dev, PTR_ERR(data->dok), "failed to get DOK GPIO"); if (data->dok) {
gpiod_set_consumer_name(data->dok, data->psy_desc.name); /* * The DC OK is pulled up to 1 and goes low when a charger * is plugged in (active low) but in the device tree the * line is marked as GPIO_ACTIVE_LOW so we get a 1 (asserted) * here if the DC charger is plugged in.
*/
ta_in = gpiod_get_value(data->dok);
}
data->uok = devm_gpiod_get_optional(dev, "uok", GPIOD_IN); if (IS_ERR(data->uok)) return dev_err_probe(dev, PTR_ERR(data->uok), "failed to get UOK GPIO"); if (data->uok) {
gpiod_set_consumer_name(data->uok, data->psy_desc.name); /* * The USB OK is pulled up to 1 and goes low when a USB charger * is plugged in (active low) but in the device tree the * line is marked as GPIO_ACTIVE_LOW so we get a 1 (asserted) * here if the USB charger is plugged in.
*/
usb_in = gpiod_get_value(data->uok);
}
/* Either DC OK or USB OK must be provided */ if (!data->dok && !data->uok) {
dev_err(dev, "no valid power source\n"); return -EINVAL;
}
/* * If either charger is already connected at this point, * assert the CEN line and enable charging from the start. * * The line is active low but also marked with GPIO_ACTIVE_LOW * in the device tree, so when we assert the line with * GPIOD_OUT_HIGH the line will be driven low.
*/
flags = (ta_in || usb_in) ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW; /* * If DC OK is provided, Charger Enable CEN is compulsory * so this is not optional here.
*/
data->cen = devm_gpiod_get(dev, "cen", flags); if (IS_ERR(data->cen)) return dev_err_probe(dev, PTR_ERR(data->cen), "failed to get CEN GPIO");
gpiod_set_consumer_name(data->cen, data->psy_desc.name);
/* * If the DC charger is connected, then select it. * * The DCM line should be marked GPIO_ACTIVE_HIGH in the * device tree. Driving it high will enable the DC charger * input over the USB charger input.
*/
flags = ta_in ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW;
data->dcm = devm_gpiod_get_optional(dev, "dcm", flags); if (IS_ERR(data->dcm)) return dev_err_probe(dev, PTR_ERR(data->dcm), "failed to get DCM GPIO");
gpiod_set_consumer_name(data->dcm, data->psy_desc.name);
data->chg = devm_gpiod_get_optional(dev, "chg", GPIOD_IN); if (IS_ERR(data->chg)) return dev_err_probe(dev, PTR_ERR(data->chg), "failed to get CHG GPIO");
gpiod_set_consumer_name(data->chg, data->psy_desc.name);
data->flt = devm_gpiod_get_optional(dev, "flt", GPIOD_IN); if (IS_ERR(data->flt)) return dev_err_probe(dev, PTR_ERR(data->flt), "failed to get FLT GPIO");
gpiod_set_consumer_name(data->flt, data->psy_desc.name);
data->usus = devm_gpiod_get_optional(dev, "usus", GPIOD_IN); if (IS_ERR(data->usus)) return dev_err_probe(dev, PTR_ERR(data->usus), "failed to get USUS GPIO");
gpiod_set_consumer_name(data->usus, data->psy_desc.name);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.