{"id":1641681,"url":"http://patchwork.ozlabs.org/api/patches/1641681/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-ide/patch/20220610081801.11854-11-Sergey.Semin@baikalelectronics.ru/","project":{"id":13,"url":"http://patchwork.ozlabs.org/api/projects/13/?format=json","name":"Linux IDE development","link_name":"linux-ide","list_id":"linux-ide.vger.kernel.org","list_email":"linux-ide@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20220610081801.11854-11-Sergey.Semin@baikalelectronics.ru>","list_archive_url":null,"date":"2022-06-10T08:17:48","name":"[v4,10/23] ata: libahci_platform: Introduce reset assertion/deassertion methods","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"59ba79918ecf62dfd4699f8846f95cc38198a8a7","submitter":{"id":78624,"url":"http://patchwork.ozlabs.org/api/people/78624/?format=json","name":"Serge Semin","email":"Sergey.Semin@baikalelectronics.ru"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-ide/patch/20220610081801.11854-11-Sergey.Semin@baikalelectronics.ru/mbox/","series":[{"id":304159,"url":"http://patchwork.ozlabs.org/api/series/304159/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-ide/list/?series=304159","date":"2022-06-10T08:17:42","name":"ata: ahci: Add DWC/Baikal-T1 AHCI SATA support","version":4,"mbox":"http://patchwork.ozlabs.org/series/304159/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/1641681/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/1641681/checks/","tags":{},"related":[],"headers":{"Return-Path":"<linux-ide-owner@vger.kernel.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["bilbo.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=baikalelectronics.ru header.i=@baikalelectronics.ru\n header.a=rsa-sha256 header.s=mail header.b=JioxRJW7;\n\tdkim-atps=neutral","ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2620:137:e000::1:20; helo=out1.vger.email;\n envelope-from=linux-ide-owner@vger.kernel.org; receiver=<UNKNOWN>)"],"Received":["from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20])\n\tby bilbo.ozlabs.org (Postfix) with ESMTP id 4LKDQQ2h7Dz9s09\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 10 Jun 2022 18:19:26 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n        id S1347521AbiFJITW (ORCPT <rfc822;incoming@patchwork.ozlabs.org>);\n        Fri, 10 Jun 2022 04:19:22 -0400","from lindbergh.monkeyblade.net ([23.128.96.19]:57324 \"EHLO\n        lindbergh.monkeyblade.net\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n        with ESMTP id S1347340AbiFJISX (ORCPT\n        <rfc822;linux-ide@vger.kernel.org>); Fri, 10 Jun 2022 04:18:23 -0400","from mail.baikalelectronics.com (mail.baikalelectronics.com\n [87.245.175.230])\n        by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9964D244142;\n        Fri, 10 Jun 2022 01:18:21 -0700 (PDT)","from mail (mail.baikal.int [192.168.51.25])\n        by mail.baikalelectronics.com (Postfix) with ESMTP id 857C316AB;\n        Fri, 10 Jun 2022 11:19:03 +0300 (MSK)","from localhost (192.168.53.207) by mail (192.168.51.25) with\n Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 10 Jun 2022 11:18:11 +0300"],"DKIM-Filter":"OpenDKIM Filter v2.11.0 mail.baikalelectronics.com 857C316AB","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=baikalelectronics.ru; s=mail; t=1654849143;\n        bh=BfDL2499VHFzGQhkO0OyO5IsQDeHm0cdb0M5NbXP5Nk=;\n        h=From:To:CC:Subject:Date:In-Reply-To:References:From;\n        b=JioxRJW7z7ZIAb/2CC4rxdxcuWayey525W9b1elJ+lsSB5iYpEwg5fOLY+dg8iC0L\n         aF4zfHcjNvu6M3p32vpGtqS6cJhYD1PjyMlIQm2XUvO09GTEQgbJY/AkWreZVHKJSD\n         WAaYTcO/mV+yIGHbNqV5x6oLrJAFphjIb4daS9/Q=","From":"Serge Semin <Sergey.Semin@baikalelectronics.ru>","To":"Damien Le Moal <damien.lemoal@opensource.wdc.com>,\n        Hans de Goede <hdegoede@redhat.com>,\n        Jens Axboe <axboe@kernel.dk>, Hannes Reinecke <hare@suse.de>","CC":"Serge Semin <Sergey.Semin@baikalelectronics.ru>,\n        Serge Semin <fancer.lancer@gmail.com>,\n        Alexey Malahov <Alexey.Malahov@baikalelectronics.ru>,\n        Pavel Parkhomenko <Pavel.Parkhomenko@baikalelectronics.ru>,\n        Rob Herring <robh+dt@kernel.org>, <linux-ide@vger.kernel.org>,\n        <linux-kernel@vger.kernel.org>, <devicetree@vger.kernel.org>","Subject":"[PATCH v4 10/23] ata: libahci_platform: Introduce reset\n assertion/deassertion methods","Date":"Fri, 10 Jun 2022 11:17:48 +0300","Message-ID":"<20220610081801.11854-11-Sergey.Semin@baikalelectronics.ru>","In-Reply-To":"<20220610081801.11854-1-Sergey.Semin@baikalelectronics.ru>","References":"<20220610081801.11854-1-Sergey.Semin@baikalelectronics.ru>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Content-Type":"text/plain","X-ClientProxiedBy":"MAIL.baikal.int (192.168.51.25) To mail (192.168.51.25)","X-Spam-Status":"No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,\n        DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS,\n        T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no\n        version=3.4.6","X-Spam-Checker-Version":"SpamAssassin 3.4.6 (2021-04-09) on\n        lindbergh.monkeyblade.net","Precedence":"bulk","List-ID":"<linux-ide.vger.kernel.org>","X-Mailing-List":"linux-ide@vger.kernel.org"},"content":"Currently the ACHI-platform library supports only the assert and deassert\nreset signals and ignores the platforms with self-deasserting reset lines.\nThat prone to having the platforms with self-deasserting reset method\nmisbehaviour when it comes to resuming from sleep state after the clocks\nhave been fully disabled. For such cases the controller needs to be fully\nreset all over after the reference clocks are enabled and stable,\notherwise the controller state machine might be in an undetermined state.\n\nThe best solution would be to auto-detect which reset method is supported\nby the particular platform and use it implicitly in the framework of the\nahci_platform_enable_resources()/ahci_platform_disable_resources()\nmethods. Alas it can't be implemented due to the AHCI-platform library\nalready supporting the shared reset control lines. As [1] says in such\ncase we have to use only one of the next methods:\n+ reset_control_assert()/reset_control_deassert();\n+ reset_control_reset()/reset_control_rearm().\nIf the driver had an exclusive control over the reset lines we could have\nbeen able to manipulate the lines with no much limitation and just used\nthe combination of the methods above to cover all the possible\nreset-control cases. Since the shared reset control has already been\nadvertised and couldn't be changed with no risk to breaking the platforms\nrelying on it, we have no choice but to make the platform drivers to\ndetermine which reset methods the platform reset system supports.\n\nIn order to implement both types of reset control support we suggest to\nintroduce the new AHCI-platform flag: AHCI_PLATFORM_RST_TRIGGER, which\nwhen passed to the ahci_platform_get_resources() method together with the\nAHCI_PLATFORM_GET_RESETS flag will indicate that the reset lines are\nself-deasserting thus the reset_control_reset()/reset_control_rearm() will\nbe used to control the reset state. Otherwise the\nreset_control_deassert()/reset_control_assert() methods will be utilized.\n\n[1] Documentation/driver-api/reset.rst\n\nSigned-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>\nReviewed-by: Hannes Reinecke <hare@suse.de>\n\n---\n\nChangelog v2:\n- Convert the ahci_platform_assert_rsts() method to returning int status\n  (@Damien).\n- Fix some grammar mistakes in the ahci_platform_deassert_rsts() doc\n  (@Damien).\n---\n drivers/ata/ahci.h             |  1 +\n drivers/ata/libahci_platform.c | 50 ++++++++++++++++++++++++++++++----\n include/linux/ahci_platform.h  |  5 +++-\n 3 files changed, 50 insertions(+), 6 deletions(-)","diff":"diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h\nindex c3770a19781b..7d834deefeb9 100644\n--- a/drivers/ata/ahci.h\n+++ b/drivers/ata/ahci.h\n@@ -340,6 +340,7 @@ struct ahci_host_priv {\n \tbool\t\t\tgot_runtime_pm; /* Did we do pm_runtime_get? */\n \tunsigned int\t\tn_clks;\n \tstruct clk_bulk_data\t*clks;\t\t/* Optional */\n+\tunsigned int\t\tf_rsts;\n \tstruct reset_control\t*rsts;\t\t/* Optional */\n \tstruct regulator\t**target_pwrs;\t/* Optional */\n \tstruct regulator\t*ahci_regulator;/* Optional */\ndiff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c\nindex 1a7060646009..fcf00ffc7d12 100644\n--- a/drivers/ata/libahci_platform.c\n+++ b/drivers/ata/libahci_platform.c\n@@ -123,6 +123,44 @@ void ahci_platform_disable_clks(struct ahci_host_priv *hpriv)\n }\n EXPORT_SYMBOL_GPL(ahci_platform_disable_clks);\n \n+/**\n+ * ahci_platform_deassert_rsts - Deassert/trigger platform resets\n+ * @hpriv: host private area to store config values\n+ *\n+ * This function deasserts or triggers all the reset lines found for\n+ * the AHCI device.\n+ *\n+ * RETURNS:\n+ * 0 on success otherwise a negative error code\n+ */\n+int ahci_platform_deassert_rsts(struct ahci_host_priv *hpriv)\n+{\n+\tif (hpriv->f_rsts & AHCI_PLATFORM_RST_TRIGGER)\n+\t\treturn reset_control_reset(hpriv->rsts);\n+\n+\treturn reset_control_deassert(hpriv->rsts);\n+}\n+EXPORT_SYMBOL_GPL(ahci_platform_deassert_rsts);\n+\n+/**\n+ * ahci_platform_assert_rsts - Assert/rearm platform resets\n+ * @hpriv: host private area to store config values\n+ *\n+ * This function asserts or rearms (for self-deasserting resets) all\n+ * the reset controls found for the AHCI device.\n+ *\n+ * RETURNS:\n+ * 0 on success otherwise a negative error code\n+ */\n+int ahci_platform_assert_rsts(struct ahci_host_priv *hpriv)\n+{\n+\tif (hpriv->f_rsts & AHCI_PLATFORM_RST_TRIGGER)\n+\t\treturn reset_control_rearm(hpriv->rsts);\n+\n+\treturn reset_control_assert(hpriv->rsts);\n+}\n+EXPORT_SYMBOL_GPL(ahci_platform_assert_rsts);\n+\n /**\n  * ahci_platform_enable_regulators - Enable regulators\n  * @hpriv: host private area to store config values\n@@ -220,18 +258,18 @@ int ahci_platform_enable_resources(struct ahci_host_priv *hpriv)\n \tif (rc)\n \t\tgoto disable_regulator;\n \n-\trc = reset_control_deassert(hpriv->rsts);\n+\trc = ahci_platform_deassert_rsts(hpriv);\n \tif (rc)\n \t\tgoto disable_clks;\n \n \trc = ahci_platform_enable_phys(hpriv);\n \tif (rc)\n-\t\tgoto disable_resets;\n+\t\tgoto disable_rsts;\n \n \treturn 0;\n \n-disable_resets:\n-\treset_control_assert(hpriv->rsts);\n+disable_rsts:\n+\tahci_platform_assert_rsts(hpriv);\n \n disable_clks:\n \tahci_platform_disable_clks(hpriv);\n@@ -258,7 +296,7 @@ void ahci_platform_disable_resources(struct ahci_host_priv *hpriv)\n {\n \tahci_platform_disable_phys(hpriv);\n \n-\treset_control_assert(hpriv->rsts);\n+\tahci_platform_assert_rsts(hpriv);\n \n \tahci_platform_disable_clks(hpriv);\n \n@@ -449,6 +487,8 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev,\n \t\t\trc = PTR_ERR(hpriv->rsts);\n \t\t\tgoto err_out;\n \t\t}\n+\n+\t\thpriv->f_rsts = flags & AHCI_PLATFORM_RST_TRIGGER;\n \t}\n \n \t/*\ndiff --git a/include/linux/ahci_platform.h b/include/linux/ahci_platform.h\nindex 49e5383d4222..6d7dd472d370 100644\n--- a/include/linux/ahci_platform.h\n+++ b/include/linux/ahci_platform.h\n@@ -23,6 +23,8 @@ int ahci_platform_enable_phys(struct ahci_host_priv *hpriv);\n void ahci_platform_disable_phys(struct ahci_host_priv *hpriv);\n int ahci_platform_enable_clks(struct ahci_host_priv *hpriv);\n void ahci_platform_disable_clks(struct ahci_host_priv *hpriv);\n+int ahci_platform_deassert_rsts(struct ahci_host_priv *hpriv);\n+int ahci_platform_assert_rsts(struct ahci_host_priv *hpriv);\n int ahci_platform_enable_regulators(struct ahci_host_priv *hpriv);\n void ahci_platform_disable_regulators(struct ahci_host_priv *hpriv);\n int ahci_platform_enable_resources(struct ahci_host_priv *hpriv);\n@@ -41,6 +43,7 @@ int ahci_platform_resume_host(struct device *dev);\n int ahci_platform_suspend(struct device *dev);\n int ahci_platform_resume(struct device *dev);\n \n-#define AHCI_PLATFORM_GET_RESETS\t0x01\n+#define AHCI_PLATFORM_GET_RESETS\tBIT(0)\n+#define AHCI_PLATFORM_RST_TRIGGER\tBIT(1)\n \n #endif /* _AHCI_PLATFORM_H */\n","prefixes":["v4","10/23"]}