From patchwork Mon Feb 5 19:44:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Davis X-Patchwork-Id: 197032 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1158395dyb; Mon, 5 Feb 2024 13:36:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IESin/KGSl9MjxRnAkCX4Oujy5agGiR+lh3v82oNG5FSMHZSyg1r05mCP4X8N/d1zr8N8KA X-Received: by 2002:a05:6a20:1453:b0:19c:9a4a:6606 with SMTP id a19-20020a056a20145300b0019c9a4a6606mr1027069pzi.13.1707168964325; Mon, 05 Feb 2024 13:36:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707168964; cv=pass; d=google.com; s=arc-20160816; b=ES1hBCLU2Tp40Um6xYTQmhZ7hWmgF1ICDZS+HoOUcH067YjLnermXOkZXNwmW31o5J ZzLUZS+8jXZHy6otpcwRZ2AHcPmqEB0EI0W3nwXffePEzpGRYKY3ECzfJ3x/ui8fd45P aL3zaqpJd7+7vfSkQPABUKV5Uk4mJIaeDK4EOTUnF2EaYfAbLkJdHcdMt2qA/Vs5niL+ gbUi1UqEVM/sq515zympmWPx2yrnCmuVhHcTaXyHTvFPjL+M8PP0Sr7sMM9NaQA8ruqH n0IdeBJ6BdyDOf4XgyT3BI+GhMV3HekOsl1IrhBUE/OEncoTksep59YCq2uIs2tm+H7n CcWw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=NIThW8dvWRvWMprZfYkUcAv9QvAIjazC0Wh9+WTdW/k=; fh=g+lq/nKlUVERF+NoyDb6ir/m3LiBMq2LTbMo8t+3qws=; b=z0ea8dk4iv6aUXPOVRiEtinIm7sFtbHhHUD7j33kGKj/r+UpzOJ2tEJUMUcuPPHYxH s1bMR4eOreP4VrF5Ruj9eNevokWafhE0ab/UEv8z+7uf2U2vTNPjbrwf8uoRnib178+X 6x9nI1nP2ewD43+YUWHcoCem2Juki/pjG6npw9r1+PuKYtogjp4A2WcVARfO5/B3i+oB 1No9fUOzF/iW0E9GY24GXLPN15JLZQJj/kKgNWFpLhlAIsn/E24F6IxfQGgAAC618Vci thixpX1q1tVACXzVagrbuAJOnM/1M83qSC8c9gZ845r5pBMCOn3RhovoJghOp/XOexRD db+A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="U/TDTDZe"; arc=pass (i=1 spf=pass spfdomain=ti.com dkim=pass dkdomain=ti.com dmarc=pass fromdomain=ti.com); spf=pass (google.com: domain of linux-kernel+bounces-53854-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53854-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com X-Forwarded-Encrypted: i=1; AJvYcCWp1fNog9A/CMJ6ML5POzQmKbcnlAcd8UpW27c/njcBTgnsrmJeeYRgOem91jMWVlKRsk2xGPwQPu4amcq0VIRkYUYJMg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id j34-20020a63fc22000000b005cdffe116d0si448656pgi.532.2024.02.05.13.36.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 13:36:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-53854-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="U/TDTDZe"; arc=pass (i=1 spf=pass spfdomain=ti.com dkim=pass dkdomain=ti.com dmarc=pass fromdomain=ti.com); spf=pass (google.com: domain of linux-kernel+bounces-53854-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53854-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id A29F02885D7 for ; Mon, 5 Feb 2024 21:29:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8B9267E58A; Mon, 5 Feb 2024 19:45:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="U/TDTDZe" Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99437745E0; Mon, 5 Feb 2024 19:45:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.249 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707162310; cv=none; b=pDM5swpaM6/p/8n5jV7MUyI5tmkxYXEjPYgGIywYzq4vyOvsdbe5Ab8iB8raS+4EaOKMswiNiH+AXtaqhOUsyhITvLRByH8jHlSaaPOVBut+jp8jTC6nZLTvE+h6qOth0o3IvoZebCBRLG3IVnbu+k8KWR9O23ZGYKjaP/AjkY8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707162310; c=relaxed/simple; bh=XmOFZVJS2nbpGNUIJRoCh2m3rWFsAgRF8B1pZ3UaoOo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sy2QDPcpE4SHAKty750eEafSStxSqA1Qt63dTXFeXV1SfrQ/c3Ams4ZfsmU6hL3TTcPPtzbR/4+rp98eV3t31/XX34EXckcLITYRAcreh0PJP6t9FiR0M88P7sPHcQFvVuSQ7KlS+EIsmV1LVBLWHHCUu6Ozp4expNNpGoHSQaI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=U/TDTDZe; arc=none smtp.client-ip=198.47.23.249 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Received: from fllv0034.itg.ti.com ([10.64.40.246]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 415JipUM101215; Mon, 5 Feb 2024 13:44:51 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1707162291; bh=NIThW8dvWRvWMprZfYkUcAv9QvAIjazC0Wh9+WTdW/k=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=U/TDTDZe48TOZlXKa2/P5bsRemvEkpBf2zyycXeCvsfYIdO+o9EUhYrflRA9TzKi7 ojOnTHFu3wGQ41vLoQCyPhBK4d1tw0pk93aOPmp5SttYKOV3URTAH2ZrJBH0Y0K7SC gSqacdWWQu2J0Q+d1zPa59WE9cTXWcxMLozZqblg= Received: from DLEE111.ent.ti.com (dlee111.ent.ti.com [157.170.170.22]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 415JipKS071105 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 5 Feb 2024 13:44:51 -0600 Received: from DLEE103.ent.ti.com (157.170.170.33) by DLEE111.ent.ti.com (157.170.170.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Mon, 5 Feb 2024 13:44:51 -0600 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DLEE103.ent.ti.com (157.170.170.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Mon, 5 Feb 2024 13:44:51 -0600 Received: from lelvsmtp5.itg.ti.com ([10.249.42.149]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 415JicQg028467; Mon, 5 Feb 2024 13:44:50 -0600 From: Andrew Davis To: Sebastian Reichel , Manivannan Sadhasivam , Cristian Ciocaltea , Florian Fainelli , Ray Jui , Scott Branden , Bjorn Andersson , Konrad Dybcio , Sean Wang , Matthias Brugger , AngeloGioacchino Del Regno CC: , , , , , , Andrew Davis Subject: [PATCH v2 19/19] power: reset: syscon-poweroff: Use devm_register_sys_off_handler(POWER_OFF) Date: Mon, 5 Feb 2024 13:44:37 -0600 Message-ID: <20240205194437.180802-20-afd@ti.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240205194437.180802-1-afd@ti.com> References: <20240205194437.180802-1-afd@ti.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790096404052419934 X-GMAIL-MSGID: 1790096404052419934 Use device life-cycle managed register function to simplify probe and exit paths. Signed-off-by: Andrew Davis Reviewed-by: AngeloGioacchino Del Regno --- drivers/power/reset/syscon-poweroff.c | 34 ++++++++++++--------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/drivers/power/reset/syscon-poweroff.c b/drivers/power/reset/syscon-poweroff.c index 4899a019256e8..203936f4c544f 100644 --- a/drivers/power/reset/syscon-poweroff.c +++ b/drivers/power/reset/syscon-poweroff.c @@ -13,6 +13,7 @@ #include #include #include +#include #include struct syscon_poweroff_data { @@ -22,23 +23,30 @@ struct syscon_poweroff_data { u32 mask; }; -static struct syscon_poweroff_data *data; - -static void syscon_poweroff(void) +static int syscon_poweroff(struct sys_off_data *off_data) { + struct syscon_poweroff_data *data = off_data->cb_data; + /* Issue the poweroff */ regmap_update_bits(data->map, data->offset, data->mask, data->value); mdelay(1000); pr_emerg("Unable to poweroff system\n"); + + return NOTIFY_DONE; } static int syscon_poweroff_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; + struct syscon_poweroff_data *data; int mask_err, value_err; + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + data->map = syscon_regmap_lookup_by_phandle(dev->of_node, "regmap"); if (IS_ERR(data->map)) { data->map = syscon_node_to_regmap(dev->parent->of_node); @@ -69,21 +77,10 @@ static int syscon_poweroff_probe(struct platform_device *pdev) data->mask = 0xFFFFFFFF; } - if (pm_power_off) { - dev_err(dev, "pm_power_off already claimed for %ps", - pm_power_off); - return -EBUSY; - } - - pm_power_off = syscon_poweroff; - - return 0; -} - -static void syscon_poweroff_remove(struct platform_device *pdev) -{ - if (pm_power_off == syscon_poweroff) - pm_power_off = NULL; + return devm_register_sys_off_handler(&pdev->dev, + SYS_OFF_MODE_POWER_OFF, + SYS_OFF_PRIO_DEFAULT, + syscon_poweroff, data); } static const struct of_device_id syscon_poweroff_of_match[] = { @@ -93,7 +90,6 @@ static const struct of_device_id syscon_poweroff_of_match[] = { static struct platform_driver syscon_poweroff_driver = { .probe = syscon_poweroff_probe, - .remove_new = syscon_poweroff_remove, .driver = { .name = "syscon-poweroff", .of_match_table = syscon_poweroff_of_match,