From patchwork Mon Mar 5 18:06:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ladislav Michl X-Patchwork-Id: 10259447 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D351C6037E for ; Mon, 5 Mar 2018 18:07:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C1F8828B74 for ; Mon, 5 Mar 2018 18:07:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B6B8028BB5; Mon, 5 Mar 2018 18:07:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 34C9628B74 for ; Mon, 5 Mar 2018 18:07:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752110AbeCESHC (ORCPT ); Mon, 5 Mar 2018 13:07:02 -0500 Received: from eddie.linux-mips.org ([148.251.95.138]:57702 "EHLO cvs.linux-mips.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752096AbeCESHC (ORCPT ); Mon, 5 Mar 2018 13:07:02 -0500 Received: (from localhost user: 'ladis' uid#1021 fake: STDIN (ladis@eddie.linux-mips.org)) by eddie.linux-mips.org id S23994673AbeCESHBIpIIn (ORCPT ); Mon, 5 Mar 2018 19:07:01 +0100 Date: Mon, 5 Mar 2018 19:06:55 +0100 From: Ladislav Michl To: linux-pm@vger.kernel.org Cc: Sebastian Reichel , Mike Looijmans Subject: [PATCH v2 5/6] power: supply: gpio-charger: LTC3651 support Message-ID: <20180305180655.GF5533@lenoch> References: <20180305180325.GA5533@lenoch> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180305180325.GA5533@lenoch> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Just a proof of concept... Signed-off-by: Ladislav Michl --- Changelog: - v2: Rebased on top of another round of cleanup patches drivers/power/supply/gpio-charger.c | 78 ++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 2 deletions(-) diff --git a/drivers/power/supply/gpio-charger.c b/drivers/power/supply/gpio-charger.c index 08e0c7fa6833..1a7975fd4278 100644 --- a/drivers/power/supply/gpio-charger.c +++ b/drivers/power/supply/gpio-charger.c @@ -242,7 +242,45 @@ static int gpio_charger_cfg_init(struct device *dev, struct gpio_charger *gpio_charger, struct gpio_charger_config *cfg) { - return -EINVAL; + struct gpio_desc *gpiod; + struct power_supply_desc *charger_desc; + int ret, i = 0; + + while (cfg->gpios[i].label) { + gpiod = (cfg->gpios[i].flags & FLAG_PIN_OPTIONAL) ? + devm_gpiod_get_optional(dev, cfg->gpios[i].label, + GPIOD_IN) : + devm_gpiod_get(dev, cfg->gpios[i].label, GPIOD_IN); + + if (IS_ERR(gpiod)) { + ret = PTR_ERR(gpiod); + if (ret != EPROBE_DEFER) + dev_err(dev, + "Failed to acquire '%s' GPIO: %d\n", + cfg->gpios[i].label, ret); + return ret; + } + gpio_charger->pin[i].gpiod = gpiod; + i++; + } + + gpio_charger->nmaps = cfg->nmaps; + gpio_charger->mapping = cfg->mapping; + gpio_charger->npins = i; + + charger_desc = &gpio_charger->charger_desc; + charger_desc->type = POWER_SUPPLY_TYPE_MAINS; + charger_desc->num_properties = cfg->nmaps; + charger_desc->properties = devm_kzalloc(dev, + cfg->nmaps * sizeof(enum power_supply_property), + GFP_KERNEL); + if (!charger_desc->properties) + return -ENOMEM; + + for (i = 0; i < cfg->nmaps; i++) + charger_desc->properties[i] = cfg->mapping[i].psp; + + return 0; } static int gpio_charger_probe(struct platform_device *pdev) @@ -370,8 +408,44 @@ static int gpio_charger_resume(struct device *dev) static SIMPLE_DEV_PM_OPS(gpio_charger_pm_ops, gpio_charger_suspend, gpio_charger_resume); +struct gpio_charger_mapping chrg_fault_mapping[] = { + { + POWER_SUPPLY_PROP_ONLINE, + 0, + MAP(0x01, + { 0x01, 1 }), + }, { + POWER_SUPPLY_PROP_STATUS, + POWER_SUPPLY_STATUS_UNKNOWN, + MAP(0x02, + { 0x02, POWER_SUPPLY_STATUS_CHARGING }, + { 0x00, POWER_SUPPLY_STATUS_NOT_CHARGING }), + }, { + POWER_SUPPLY_PROP_HEALTH, + POWER_SUPPLY_HEALTH_UNKNOWN, + MAP(0x06, + { 0x00, POWER_SUPPLY_HEALTH_GOOD }, + { 0x02, POWER_SUPPLY_HEALTH_OVERHEAT }, + { 0x06, POWER_SUPPLY_HEALTH_DEAD }), + }, +}; + +static const struct gpio_charger_config ltc3651_cfg = { + MAPPING(chrg_fault_mapping), + { + { "lltc,acpr", 0 }, + { "lltc,chrg", FLAG_PIN_OPTIONAL }, + { "lltc,fault", FLAG_PIN_OPTIONAL }, + { NULL, 0 }, + }, +}; + static const struct of_device_id gpio_charger_match[] = { - { .compatible = "gpio-charger" }, + { .compatible = "gpio-charger" }, + { + .compatible = "lltc,ltc3651-charger", + .data = (void *) <c3651_cfg, + }, { } }; MODULE_DEVICE_TABLE(of, gpio_charger_match);