From patchwork Sun Jan 10 14:49:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 360180 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp2188658jai; Sun, 10 Jan 2021 06:52:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJy/RgetbxRDvCXQg5pYUuJ7dQ0LO/7Bnf4bmJ2GwCE3M0C9B+1QIm2R9MS5qTUL+9sDO5JI X-Received: by 2002:a17:906:9acc:: with SMTP id ah12mr7830640ejc.386.1610290377541; Sun, 10 Jan 2021 06:52:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610290377; cv=none; d=google.com; s=arc-20160816; b=ElDeW6WlHTdJWjnSYR3xwJllL9DquotfiZnZJv99d8Br+mz04Mj9YjBNj5phjV45Bb ElrryUSZmQrraPfusyLXjDOGrXesuBlwOrS0uyDf/zqCvdp6UYPDA/UD8p3IMyVc9cyx hlyQAaqn0T9NFS/RbbNKWQOsNBbZ9oT7te5COyCI3gpKCPGH5OPZ+gBNqEytRxyolobO Qyjyt6gJVglD+//mT+blWAxDzZhjlKTiGO4G+jVi674m9TYWoAjk+neJDsO5HU8Bdo+D pbS7Sp1cVYer5QdsufBIHkMSKLgv9DSn7mh/zw3YOzfjpH+hNZIt6t4/x5RWjwbCxVka aaoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=rdjFgfFB6SoIkzaabYkYsn6ww2vuxrkot6sP0zdtMNE=; b=YBL5R8iD7WxmgKywGdbfQpMBeSUD7xh7rgTUl84kv0WH34khDrMfUtWpQpSeMO36zK 6pGL3Kd+W1VOXKNe9ciZQSmMRFdjPNxKC8JSpCI+dnVFrsTuJ/g9p1P4O3tRoyV7R5nD XJTPdhgYYcKrdAVHhg5OkVPGGucKtOnKbfSOs6h0Lj5oqf51EeQFIPyBjuP0JuUlCqth +hx0APlprech/ogIwtzKE62FhTyt5OCj9aZ/GcAIZnls834dQ2gt9nyghEkEH+rqqDOY TjsTXLh8KFHieRkgodgo2ggGYmP8+4BUSFyHZj70JPvuE81yK8RmyF7PZnla85NlZ3/L v8+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wiLMIaPZ; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v23si5807604ejy.208.2021.01.10.06.52.57; Sun, 10 Jan 2021 06:52:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wiLMIaPZ; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726415AbhAJOvu (ORCPT + 7 others); Sun, 10 Jan 2021 09:51:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726250AbhAJOvu (ORCPT ); Sun, 10 Jan 2021 09:51:50 -0500 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F38CBC061786 for ; Sun, 10 Jan 2021 06:51:09 -0800 (PST) Received: by mail-lj1-x22d.google.com with SMTP id n11so732710lji.5 for ; Sun, 10 Jan 2021 06:51:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rdjFgfFB6SoIkzaabYkYsn6ww2vuxrkot6sP0zdtMNE=; b=wiLMIaPZh/eYfK/Ya+YsdVlyBXEYWvzNffzLITLIy5CDCLlG+RwutZ59MnRveuThSG ojpo1fI6jtOA5hgqX8SqaPu3dXwlJYQyUJljqZtz/fRaAbPK7yGJAUtSWGsHn5fKm6Gw USLk9glYEJzDi8KYfjHtsQUIOjQDAxZ2nVYDxRKFcmjCuK9SoJr2Qw/WMWKRkr9pUPe1 mWiiKv17xDIDTCbZeqKY5QVDaJPR0dDYBP1SNfG9KLZ2/hzsOgwSSvS7qRj6ECwi0gO3 41AGva1sCuCAHM9fM5+uj8urqLpq7y08iAJs60tvmThzN8cjnDTKGojHFc8udOrCknsH d3mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rdjFgfFB6SoIkzaabYkYsn6ww2vuxrkot6sP0zdtMNE=; b=UQm3NSmdLzrGAR1DlwBh+SP8+RDJwQSILyePVjKnT60EQ+VtCzDUpGe/w+QEeItSyh +5+SqTxBK+NtdTympuPZsyEWn9u2EKMnbNnzhLasxv2VOvvLVOgHCBOKav8cPfAKrE1B Swofq6nMPc06/a9PmVn89z2peXDtq9rr4+2lCqF7TCfsmZDA2W0H6+omjqaV5IX7hoa7 dN7px6TLvGpww34xqjAr4Sj8of20D0zXMqSrEV7K+qBFE982y4qNzEHfnoAX2waTCxgl dzX9TIq4VJld1rLpC6lxS592/V0V38yFmrC9P3VVPfK7kuLd4ENdyHbmyelNlNNGPfBo iQag== X-Gm-Message-State: AOAM533x8YnjIJpc9d3LrXVrXt4Aq9ZSU3KwpwoZUGC0jN98HWy9UHhk Pevt2GpBKLQK+AGAqePlOc+GRw== X-Received: by 2002:a2e:914d:: with SMTP id q13mr5459861ljg.205.1610290268437; Sun, 10 Jan 2021 06:51:08 -0800 (PST) Received: from localhost.localdomain (c-92d7225c.014-348-6c756e10.bbcust.telenor.se. [92.34.215.146]) by smtp.gmail.com with ESMTPSA id k21sm3077275ljb.43.2021.01.10.06.51.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Jan 2021 06:51:07 -0800 (PST) From: Linus Walleij To: Sebastian Reichel Cc: linux-pm@vger.kernel.org, Linus Walleij , Daniel Mack , Haojian Zhuang , Robert Jarzmik , linux-arm-kernel@lists.infradead.org Subject: [PATCH] power: supply: z2_battery: Convert to GPIO descriptors Date: Sun, 10 Jan 2021 15:49:05 +0100 Message-Id: <20210110144906.168877-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org This converts the Palm Z2 battery driver to use GPIO descriptors. Cc: Daniel Mack Cc: Haojian Zhuang Cc: Robert Jarzmik Cc: linux-arm-kernel@lists.infradead.org Signed-off-by: Linus Walleij --- arch/arm/mach-pxa/z2.c | 12 +++++++- drivers/power/supply/z2_battery.c | 46 ++++++++++++++----------------- include/linux/z2_battery.h | 1 - 3 files changed, 32 insertions(+), 27 deletions(-) -- 2.29.2 Reviewed-by: Daniel Mack Signed-off-by: Sebastian Reichel diff --git a/arch/arm/mach-pxa/z2.c b/arch/arm/mach-pxa/z2.c index 21fd76bb09cd..a5dad8d08cac 100644 --- a/arch/arm/mach-pxa/z2.c +++ b/arch/arm/mach-pxa/z2.c @@ -488,7 +488,6 @@ static struct z2_battery_info batt_chip_info = { .batt_I2C_bus = 0, .batt_I2C_addr = 0x55, .batt_I2C_reg = 2, - .charge_gpio = GPIO0_ZIPITZ2_AC_DETECT, .min_voltage = 3475000, .max_voltage = 4190000, .batt_div = 59, @@ -497,9 +496,19 @@ static struct z2_battery_info batt_chip_info = { .batt_name = "Z2", }; +static struct gpiod_lookup_table z2_battery_gpio_table = { + .dev_id = "aer915", + .table = { + GPIO_LOOKUP("gpio-pxa", GPIO0_ZIPITZ2_AC_DETECT, + NULL, GPIO_ACTIVE_HIGH), + { }, + }, +}; + static struct i2c_board_info __initdata z2_i2c_board_info[] = { { I2C_BOARD_INFO("aer915", 0x55), + .dev_name = "aer915", .platform_data = &batt_chip_info, }, { I2C_BOARD_INFO("wm8750", 0x1b), @@ -510,6 +519,7 @@ static struct i2c_board_info __initdata z2_i2c_board_info[] = { static void __init z2_i2c_init(void) { pxa_set_i2c_info(NULL); + gpiod_add_lookup_table(&z2_battery_gpio_table); i2c_register_board_info(0, ARRAY_AND_SIZE(z2_i2c_board_info)); } #else diff --git a/drivers/power/supply/z2_battery.c b/drivers/power/supply/z2_battery.c index ebd2e42a4457..b1508fe70e5e 100644 --- a/drivers/power/supply/z2_battery.c +++ b/drivers/power/supply/z2_battery.c @@ -6,7 +6,7 @@ */ #include -#include +#include #include #include #include @@ -18,6 +18,7 @@ struct z2_charger { struct z2_battery_info *info; + struct gpio_desc *charge_gpiod; int bat_status; struct i2c_client *client; struct power_supply *batt_ps; @@ -95,8 +96,8 @@ static void z2_batt_update(struct z2_charger *charger) mutex_lock(&charger->work_lock); - charger->bat_status = (info->charge_gpio >= 0) ? - (gpio_get_value(info->charge_gpio) ? + charger->bat_status = charger->charge_gpiod ? + (gpiod_get_value(charger->charge_gpiod) ? POWER_SUPPLY_STATUS_CHARGING : POWER_SUPPLY_STATUS_DISCHARGING) : POWER_SUPPLY_STATUS_UNKNOWN; @@ -131,7 +132,7 @@ static int z2_batt_ps_init(struct z2_charger *charger, int props) enum power_supply_property *prop; struct z2_battery_info *info = charger->info; - if (info->charge_gpio >= 0) + if (charger->charge_gpiod) props++; /* POWER_SUPPLY_PROP_STATUS */ if (info->batt_tech >= 0) props++; /* POWER_SUPPLY_PROP_TECHNOLOGY */ @@ -147,7 +148,7 @@ static int z2_batt_ps_init(struct z2_charger *charger, int props) return -ENOMEM; prop[i++] = POWER_SUPPLY_PROP_PRESENT; - if (info->charge_gpio >= 0) + if (charger->charge_gpiod) prop[i++] = POWER_SUPPLY_PROP_STATUS; if (info->batt_tech >= 0) prop[i++] = POWER_SUPPLY_PROP_TECHNOLOGY; @@ -206,22 +207,23 @@ static int z2_batt_probe(struct i2c_client *client, mutex_init(&charger->work_lock); - if (info->charge_gpio >= 0 && gpio_is_valid(info->charge_gpio)) { - ret = gpio_request(info->charge_gpio, "BATT CHRG"); - if (ret) - goto err; + charger->charge_gpiod = devm_gpiod_get_optional(&client->dev, + NULL, GPIOD_IN); + if (IS_ERR(charger->charge_gpiod)) + return dev_err_probe(&client->dev, + PTR_ERR(charger->charge_gpiod), + "failed to get charge GPIO\n"); - ret = gpio_direction_input(info->charge_gpio); - if (ret) - goto err2; + if (charger->charge_gpiod) { + gpiod_set_consumer_name(charger->charge_gpiod, "BATT CHRG"); - irq_set_irq_type(gpio_to_irq(info->charge_gpio), + irq_set_irq_type(gpiod_to_irq(charger->charge_gpiod), IRQ_TYPE_EDGE_BOTH); - ret = request_irq(gpio_to_irq(info->charge_gpio), + ret = request_irq(gpiod_to_irq(charger->charge_gpiod), z2_charge_switch_irq, 0, "AC Detect", charger); if (ret) - goto err3; + goto err; } ret = z2_batt_ps_init(charger, props); @@ -245,11 +247,8 @@ static int z2_batt_probe(struct i2c_client *client, err4: kfree(charger->batt_ps_desc.properties); err3: - if (info->charge_gpio >= 0 && gpio_is_valid(info->charge_gpio)) - free_irq(gpio_to_irq(info->charge_gpio), charger); -err2: - if (info->charge_gpio >= 0 && gpio_is_valid(info->charge_gpio)) - gpio_free(info->charge_gpio); + if (charger->charge_gpiod) + free_irq(gpiod_to_irq(charger->charge_gpiod), charger); err: kfree(charger); return ret; @@ -258,16 +257,13 @@ static int z2_batt_probe(struct i2c_client *client, static int z2_batt_remove(struct i2c_client *client) { struct z2_charger *charger = i2c_get_clientdata(client); - struct z2_battery_info *info = charger->info; cancel_work_sync(&charger->bat_work); power_supply_unregister(charger->batt_ps); kfree(charger->batt_ps_desc.properties); - if (info->charge_gpio >= 0 && gpio_is_valid(info->charge_gpio)) { - free_irq(gpio_to_irq(info->charge_gpio), charger); - gpio_free(info->charge_gpio); - } + if (charger->charge_gpiod) + free_irq(gpiod_to_irq(charger->charge_gpiod), charger); kfree(charger); diff --git a/include/linux/z2_battery.h b/include/linux/z2_battery.h index eaba53ff387c..9e8be7a7cd25 100644 --- a/include/linux/z2_battery.h +++ b/include/linux/z2_battery.h @@ -6,7 +6,6 @@ struct z2_battery_info { int batt_I2C_bus; int batt_I2C_addr; int batt_I2C_reg; - int charge_gpio; int min_voltage; int max_voltage; int batt_div;