From patchwork Thu Oct 20 20:42:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 6384 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp315208wrr; Thu, 20 Oct 2022 13:46:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5tE89T20DEg/i/ssWmclxCSIF3lvk2C0cXBiSiPdmb5q1OKoI0ElPEo98d/ISLUDxG+WKA X-Received: by 2002:a17:907:1c24:b0:78d:3518:2e58 with SMTP id nc36-20020a1709071c2400b0078d35182e58mr12408719ejc.574.1666298781551; Thu, 20 Oct 2022 13:46:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666298781; cv=none; d=google.com; s=arc-20160816; b=L0YiMkN/J3YwOezj/IvDQ/+crhWOW0cu/UziQ7K/yE7iiSqUW4ANRAQ0Gg9iQkdQP+ YASRlWkcfscephkZ6kVHHngXAxom4Qqg1IJYdSyh0d6ji6U7vqBBxISRpWsLOic1VK9k DG27S/eUJRlNUXDVou7QX0ahb5BusdHpvF9OiZ2n9P8NDtIzEe0ROBfollScyvtoje46 TYWMMgZxlDoEAxFbPRlP1imY91xP6m333yiUbJbXtl1/caeIl3SOvuTg1u1B+TNv6mJY 6MRn2puSe+Om0N48IOEU1kVxu6nqVwaG8pYQjpveBeKIEAx+TUDaR56//f6jc/GcdWI4 zo+Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gEclKalw77tbGWWA71OFLcTO3UIZD1FsHKoaZpABE+o=; b=YHLbT+CzRbeRflrgT20cKcJ2FAIN4x9QtV2ZIS33v34Ve8BddNyh5Z9VPVnTwX6Kma yKFa4sSUgEuTZERdRLNyoZxgRClAc6AJSqyU4PoFsmtiWjl1I2BjA/N9nxdNilKH0om8 rOY6eHwdl7ZEGBZFrGfPC7pkOsvUBWeMNNQeBiWX+9oV6xPCr9jAXLhYUbKNtCUnB5qo FRsF5/6u4N931eijFRclIppMz69uu+4EBmYdxGeuNlGrVfAkPZ0GnxQs+Xy1Yf/VAR5g IWZ6RU7muW6rX6S7PwV5HAfIMJGBN6TDS/s4+Io9EKINCIyGXCZLRBOCvcKUYSEP8pHC ApPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=jOC6LY2a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gv28-20020a1709072bdc00b0079800b81731si2303272ejc.82.2022.10.20.13.45.56; Thu, 20 Oct 2022 13:46:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=jOC6LY2a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229621AbiJTUna (ORCPT + 99 others); Thu, 20 Oct 2022 16:43:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229674AbiJTUnL (ORCPT ); Thu, 20 Oct 2022 16:43:11 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E5D020C991; Thu, 20 Oct 2022 13:42:56 -0700 (PDT) Received: from jupiter.universe (dyndsl-091-096-059-009.ewe-ip-backbone.de [91.96.59.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: sre) by madras.collabora.co.uk (Postfix) with ESMTPSA id B3227660252D; Thu, 20 Oct 2022 21:42:54 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1666298574; bh=Dmpj3FvbFbooH0xr/mAewEFx/soj7LsJn0sCs3wKPuc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jOC6LY2aWniXRLRhOwwN4Su56GODnqeDJ5eyx8s+aVg2/7FEEwXQImE+N3dSO2R59 b7WqwpDYPKSgHcxlpiOD9S9dS32bGBW7uPCiHbh5bC+fHMzX47IpaZQLxrt8+mGmhf JFkkURVCGP+KHqWL9ekGFmzjbAm3Kuti/v3VyRwojUJNU883j+UWGY5twh8rkezwIY NrGyRb6p9FDq0gsfMwibkn2n6m5nIwoUHAt5ocQFDav6PsLbSyqMYV/6bPMMUrvy2k 0J3a0vrx3LmF3qnEclDlYJyAGKykkUGXcONABokVz+89ymN8Hd4BlFtE3rM0Cg2C7h hOp0R07mGwMFQ== Received: by jupiter.universe (Postfix, from userid 1000) id 5704C480899; Thu, 20 Oct 2022 22:42:52 +0200 (CEST) From: Sebastian Reichel To: Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Lee Jones Cc: Michael Turquette , Stephen Boyd , Linus Walleij , Mark Brown , Liam Girdwood , Alexandre Belloni , Alessandro Zummo , linux-rockchip@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Sebastian Reichel , kernel@collabora.com Subject: [PATCHv4 04/13] mfd: rk808: convert to device managed resources Date: Thu, 20 Oct 2022 22:42:42 +0200 Message-Id: <20221020204251.108565-5-sebastian.reichel@collabora.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221020204251.108565-1-sebastian.reichel@collabora.com> References: <20221020204251.108565-1-sebastian.reichel@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747240911198678582?= X-GMAIL-MSGID: =?utf-8?q?1747240911198678582?= Fully convert the driver to device managed resources. Acked-for-MFD-by: Lee Jones Signed-off-by: Sebastian Reichel --- drivers/mfd/rk808.c | 64 ++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 42 deletions(-) diff --git a/drivers/mfd/rk808.c b/drivers/mfd/rk808.c index e00da7c7e3b1..e2e7a2c85019 100644 --- a/drivers/mfd/rk808.c +++ b/drivers/mfd/rk808.c @@ -541,13 +541,11 @@ static const struct regmap_irq_chip rk818_irq_chip = { .init_ack_masked = true, }; -static struct i2c_client *rk808_i2c_client; - -static void rk808_pm_power_off(void) +static int rk808_power_off(struct sys_off_data *data) { + struct rk808 *rk808 = data->cb_data; int ret; unsigned int reg, bit; - struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client); switch (rk808->variant) { case RK805_ID: @@ -568,16 +566,18 @@ static void rk808_pm_power_off(void) bit = DEV_OFF; break; default: - return; + return NOTIFY_DONE; } ret = regmap_update_bits(rk808->regmap, reg, bit, bit); if (ret) - dev_err(&rk808_i2c_client->dev, "Failed to shutdown device!\n"); + dev_err(&rk808->i2c->dev, "Failed to shutdown device!\n"); + + return NOTIFY_DONE; } -static int rk808_restart_notify(struct notifier_block *this, unsigned long mode, void *cmd) +static int rk808_restart(struct sys_off_data *data) { - struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client); + struct rk808 *rk808 = data->cb_data; unsigned int reg, bit; int ret; @@ -593,16 +593,11 @@ static int rk808_restart_notify(struct notifier_block *this, unsigned long mode, } ret = regmap_update_bits(rk808->regmap, reg, bit, bit); if (ret) - dev_err(&rk808_i2c_client->dev, "Failed to restart device!\n"); + dev_err(&rk808->i2c->dev, "Failed to restart device!\n"); return NOTIFY_DONE; } -static struct notifier_block rk808_restart_handler = { - .notifier_call = rk808_restart_notify, - .priority = 192, -}; - static void rk8xx_shutdown(struct i2c_client *client) { struct rk808 *rk808 = i2c_get_clientdata(client); @@ -739,9 +734,9 @@ static int rk808_probe(struct i2c_client *client, return -EINVAL; } - ret = regmap_add_irq_chip(rk808->regmap, client->irq, - IRQF_ONESHOT, -1, - rk808->regmap_irq_chip, &rk808->irq_data); + ret = devm_regmap_add_irq_chip(&client->dev, rk808->regmap, client->irq, + IRQF_ONESHOT, -1, + rk808->regmap_irq_chip, &rk808->irq_data); if (ret) { dev_err(&client->dev, "Failed to add irq_chip %d\n", ret); return ret; @@ -765,17 +760,23 @@ static int rk808_probe(struct i2c_client *client, regmap_irq_get_domain(rk808->irq_data)); if (ret) { dev_err(&client->dev, "failed to add MFD devices %d\n", ret); - goto err_irq; + return ret; } if (of_property_read_bool(np, "rockchip,system-power-controller")) { - rk808_i2c_client = client; - pm_power_off = rk808_pm_power_off; + ret = devm_register_sys_off_handler(&client->dev, + SYS_OFF_MODE_POWER_OFF_PREPARE, SYS_OFF_PRIO_HIGH, + &rk808_power_off, rk808); + if (ret) + return dev_err_probe(&client->dev, ret, + "failed to register poweroff handler\n"); switch (rk808->variant) { case RK809_ID: case RK817_ID: - ret = register_restart_handler(&rk808_restart_handler); + ret = devm_register_sys_off_handler(&client->dev, + SYS_OFF_MODE_RESTART, SYS_OFF_PRIO_HIGH, + &rk808_restart, rk808); if (ret) dev_warn(&client->dev, "failed to register rst handler, %d\n", ret); break; @@ -786,26 +787,6 @@ static int rk808_probe(struct i2c_client *client, } return 0; - -err_irq: - regmap_del_irq_chip(client->irq, rk808->irq_data); - return ret; -} - -static void rk808_remove(struct i2c_client *client) -{ - struct rk808 *rk808 = i2c_get_clientdata(client); - - regmap_del_irq_chip(client->irq, rk808->irq_data); - - /** - * pm_power_off may points to a function from another module. - * Check if the pointer is set by us and only then overwrite it. - */ - if (pm_power_off == rk808_pm_power_off) - pm_power_off = NULL; - - unregister_restart_handler(&rk808_restart_handler); } static int __maybe_unused rk8xx_suspend(struct device *dev) @@ -862,7 +843,6 @@ static struct i2c_driver rk808_i2c_driver = { .pm = &rk8xx_pm_ops, }, .probe = rk808_probe, - .remove = rk808_remove, .shutdown = rk8xx_shutdown, };