Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1747362ybg; Sat, 19 Oct 2019 01:37:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqxXN0jVO3A1A2mGs4bvmzsN4ikppEm5h2Lf5VMeHkZJrCbE7mDP++KBq/o22FD4X/jGIm0g X-Received: by 2002:a17:906:4716:: with SMTP id y22mr12516201ejq.225.1571474271719; Sat, 19 Oct 2019 01:37:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571474271; cv=none; d=google.com; s=arc-20160816; b=fhtBYLrLa+2S25I/fO1YGHlMnI66nFKh5k/uatb71mEGAOW+aKGTxTDLSVyPTX87a1 bYlUabdu5AMhxUS76QNTM7ON4sh+5pmGXYsRejYbdmk0MzKIEbb6NOXDbiY8x6eh/PSq 96GT8pwFX3Z1PHVRWkz3zJr94Ca4Z24+e1HN9q70ld/nOCSe3pVNt5m+mabbqg4ag6ml ewMCVRKAdAAlnMch8eVD6hHXq5JphXBaghqJtBE1b1U5LU25sZkzNq2/jr1E2rIFiNd9 zTJQU6j/XIAN07NrizkEQmIRiKhSWMQBoHk9GrtdSWnjvi9x1ftfDl88vxgLwdR/3Zyi 1Pow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=coNgMFOpiK14khaVXnq6BpXcHLUxcoibYe0qsJJmGzg=; b=HV5mUnZ8iJ2hKLrEslVT5yVUM7MZ2zHhHH146yhyW5TVjziWBXHS2LUBB1eGZbmyZC 6RH53YmunirBrk7282XsUpg02b5rks6c2PJQTfCd5wassuQhAnKB9rJ4uElQblvhQBLA BQNYEJOgKI0yKcs9P3uAqljLWUpC7B1fnG3s615/gKbCw6yVK0X2TqWMPYrDejausu9s vezYMkkvayNXQJ43T6d0EDCYsjUXoUn3WcS0rPzVqRl8jZDFbd0cCet6yZQUEqrRSOc6 7pKjZ5aEKgoekjN6Lm+/8cq7e9PPZ5HB9I+9i407VMrRnJXXgh6sp4L/T27e0qjhw2B4 7XMg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 8si5612740ejc.104.2019.10.19.01.37.28; Sat, 19 Oct 2019 01:37:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2505211AbfJRPmp (ORCPT + 99 others); Fri, 18 Oct 2019 11:42:45 -0400 Received: from mout.kundenserver.de ([217.72.192.75]:51121 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2505167AbfJRPmk (ORCPT ); Fri, 18 Oct 2019 11:42:40 -0400 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1Mq2rM-1hiK9j1L1e-00n5fL; Fri, 18 Oct 2019 17:42:33 +0200 From: Arnd Bergmann To: Daniel Mack , Haojian Zhuang , Robert Jarzmik Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij , Arnd Bergmann , Sebastian Reichel , linux-pm@vger.kernel.org Subject: [PATCH 39/46] power: tosa: simplify probe function Date: Fri, 18 Oct 2019 17:41:54 +0200 Message-Id: <20191018154201.1276638-39-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191018154052.1276506-1-arnd@arndb.de> References: <20191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WP63uJ0l33g32WBLUCxEH82OtVBaSU9BXRYoeJh nfxJr+55wQNqDBa2UfH3ccIHTo7sEoRuG2Zl5dA9xiYnJDgneAxAoINw1wy5S/8r/AmkA31Gk yFfFbUaXdiJS8WT0H2tVEaW6xyOc0+EcuV7zwq7+0PX/PEzKDk1u/p/TAir1FIPGtgX3w7iq1 0VQp6qh9uRbkEH8o4DZA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Cc: 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, -- 2.20.0