From patchwork Tue Apr 19 16:38:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 565242 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 23B3EC433EF for ; Fri, 22 Apr 2022 13:46:22 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 7086682A; Fri, 22 Apr 2022 15:45:30 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 7086682A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1650635180; bh=qlaYFyobKEQjnzQZM9MNp5qNQqkRYezyfa1kDOn31O4=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=fhBkHySFGhRDR+SHI7K2q/eEizYSlwQppPwjS0APv6QRoawUYtqzUMKwKTMCyuIvh L4Mc//sK8f7JaYTg0WAPwTVwR//FdfCXrp9KBb5Xyv3sy+P3z3j9bo6Oj0L/y3mUKV CDNJUxwdWG2MkG+JUkIsS15yzelJ9dKNFSdpKTpQ= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id BCB8FF8067D; Fri, 22 Apr 2022 15:32:19 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 6B4AEF80237; Tue, 19 Apr 2022 18:44:01 +0200 (CEST) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 9C0F3F80237 for ; Tue, 19 Apr 2022 18:43:58 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 9C0F3F80237 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IfCx1sYs" Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 951AA61877; Tue, 19 Apr 2022 16:43:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7EC2BC385A5; Tue, 19 Apr 2022 16:43:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1650386637; bh=qlaYFyobKEQjnzQZM9MNp5qNQqkRYezyfa1kDOn31O4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IfCx1sYsItrvvOhd62OVGq73m59nNboCQp/gH4IxEBVU5zCvpQPCNPA7TuLYFXC6C LwaFif0SpZk4iKNSuUv5XERVH3Itoh7apK3zIBcowiSB/8aMiJR+86E55VqZMRViGM vxBgMMnsawZno/joMpTCd+ep1ROboUpME3CMorprNKBdA5wmg9bbhuyypuFsCjLW8G yE/u4h18EsDdKvT5ABnu1pHVnRKTIiK1fqnwH6cD1Nj0kuQJNcwzeZUE12odIw17Nr I4FoURlNeI1+CxCMlSZX0Yt4E6U9SjEz7W8MiBWwtf7IWB7ooRCN+I7IGpKqWmgJa2 GROrW1/+TSmQA== From: Arnd Bergmann To: robert.jarzmik@free.fr, linux-arm-kernel@lists.infradead.org Subject: [PATCH 39/48] power: tosa: simplify probe function Date: Tue, 19 Apr 2022 18:38:01 +0200 Message-Id: <20220419163810.2118169-40-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220419163810.2118169-1-arnd@kernel.org> References: <20220419163810.2118169-1-arnd@kernel.org> MIME-Version: 1.0 X-Mailman-Approved-At: Fri, 22 Apr 2022 15:31:42 +0200 Cc: Ulf Hansson , linux-usb@vger.kernel.org, Philipp Zabel , "Rafael J. Wysocki" , Viresh Kumar , Sergey Lapin , linux-fbdev@vger.kernel.org, Dominik Brodowski , linux-kernel@vger.kernel.org, linux-ide@vger.kernel.org, linux-mtd@lists.infradead.org, Tomas Cech , linux-clk@vger.kernel.org, linux-leds@vger.kernel.org, linux-rtc@vger.kernel.org, Helge Deller , Marek Vasut , Paul Parsons , Linus Walleij , Arnd Bergmann , linux-pm@vger.kernel.org, linux-input@vger.kernel.org, Haojian Zhuang , Lubomir Rintel , Mark Brown , dri-devel@lists.freedesktop.org, Thomas Bogendoerfer , Stephen Boyd , patches@opensource.cirrus.com, Dmitry Torokhov , linux-mmc@vger.kernel.org, linux-mips@vger.kernel.org, Michael Turquette , Sebastian Reichel , alsa-devel@alsa-project.org, Daniel Mack X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" From: Arnd Bergmann We have three power supplies that need similar initialization. As a preparation for the gpio lookup table conversion, split out the initialization into a separate function. Reviewed-by: Sebastian Reichel Acked-by: Sebastian Reichel Cc: linux-pm@vger.kernel.org Signed-off-by: Arnd Bergmann --- drivers/power/supply/tosa_battery.c | 50 ++++++++++++++--------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/drivers/power/supply/tosa_battery.c b/drivers/power/supply/tosa_battery.c index 32cc31cd4761..b26b0eca33e1 100644 --- a/drivers/power/supply/tosa_battery.c +++ b/drivers/power/supply/tosa_battery.c @@ -343,12 +343,24 @@ static int tosa_bat_resume(struct platform_device *dev) #define tosa_bat_resume NULL #endif +static int tosa_power_supply_register(struct device *dev, + struct tosa_bat *bat, + const struct power_supply_desc *desc) +{ + struct power_supply_config cfg = { + .drv_data = bat, + }; + + mutex_init(&bat->work_lock); + bat->psy = power_supply_register(dev, desc, &cfg); + + return PTR_ERR_OR_ZERO(bat->psy); +} + + static int tosa_bat_probe(struct platform_device *dev) { int ret; - struct power_supply_config main_psy_cfg = {}, - jacket_psy_cfg = {}, - bu_psy_cfg = {}; if (!machine_is_tosa()) return -ENODEV; @@ -357,36 +369,22 @@ static int tosa_bat_probe(struct platform_device *dev) if (ret) return ret; - mutex_init(&tosa_bat_main.work_lock); - mutex_init(&tosa_bat_jacket.work_lock); - INIT_WORK(&bat_work, tosa_bat_work); - main_psy_cfg.drv_data = &tosa_bat_main; - tosa_bat_main.psy = power_supply_register(&dev->dev, - &tosa_bat_main_desc, - &main_psy_cfg); - if (IS_ERR(tosa_bat_main.psy)) { - ret = PTR_ERR(tosa_bat_main.psy); + ret = tosa_power_supply_register(&dev->dev, &tosa_bat_main, + &tosa_bat_main_desc); + if (ret) goto err_psy_reg_main; - } - jacket_psy_cfg.drv_data = &tosa_bat_jacket; - tosa_bat_jacket.psy = power_supply_register(&dev->dev, - &tosa_bat_jacket_desc, - &jacket_psy_cfg); - if (IS_ERR(tosa_bat_jacket.psy)) { - ret = PTR_ERR(tosa_bat_jacket.psy); + ret = tosa_power_supply_register(&dev->dev, &tosa_bat_jacket, + &tosa_bat_jacket_desc); + if (ret) goto err_psy_reg_jacket; - } - bu_psy_cfg.drv_data = &tosa_bat_bu; - tosa_bat_bu.psy = power_supply_register(&dev->dev, &tosa_bat_bu_desc, - &bu_psy_cfg); - if (IS_ERR(tosa_bat_bu.psy)) { - ret = PTR_ERR(tosa_bat_bu.psy); + ret = tosa_power_supply_register(&dev->dev, &tosa_bat_bu, + &tosa_bat_bu_desc); + if (ret) goto err_psy_reg_bu; - } ret = request_irq(gpio_to_irq(TOSA_GPIO_BAT0_CRG), tosa_bat_gpio_isr,