[{"id":1773530,"web_url":"http://patchwork.ozlabs.org/comment/1773530/","msgid":"<20170922120532.jddabnd57yt3iowe@rfolt0960.corp.atmel.com>","list_archive_url":null,"date":"2017-09-22T12:05:32","subject":"Re: [PATCH v2 1/9] clk: at91: pmc: Wait for clocks when resuming","submitter":{"id":70920,"url":"http://patchwork.ozlabs.org/api/people/70920/","name":"Ludovic Desroches","email":"ludovic.desroches@microchip.com"},"content":"On Fri, Sep 15, 2017 at 04:04:03PM +0200, Romain Izard wrote:\n> Wait for the syncronization of all clocks when resuming, not only the\n> UPLL clock. Do not use regmap_read_poll_timeout, as it will call BUG()\n> when interrupts are masked, which is the case in here.\n> \n> Signed-off-by: Romain Izard <romain.izard.pro@gmail.com>\nAcked-by: Ludovic Desroches <ludovic.desroches@microchip.com>\n\nI faced the same issue because of the use of regmap_read_poll_timeout\nwhen timekeeping is not ready.\n\n\nLudovic\n\n> ---\n>  drivers/clk/at91/pmc.c | 24 ++++++++++++++++--------\n>  1 file changed, 16 insertions(+), 8 deletions(-)\n> \n> diff --git a/drivers/clk/at91/pmc.c b/drivers/clk/at91/pmc.c\n> index 775af473fe11..5c2b26de303e 100644\n> --- a/drivers/clk/at91/pmc.c\n> +++ b/drivers/clk/at91/pmc.c\n> @@ -107,10 +107,20 @@ static int pmc_suspend(void)\n>  \treturn 0;\n>  }\n>  \n> +static bool pmc_ready(unsigned int mask)\n> +{\n> +\tunsigned int status;\n> +\n> +\tregmap_read(pmcreg, AT91_PMC_SR, &status);\n> +\n> +\treturn ((status & mask) == mask) ? 1 : 0;\n> +}\n> +\n>  static void pmc_resume(void)\n>  {\n> -\tint i, ret = 0;\n> +\tint i;\n>  \tu32 tmp;\n> +\tu32 mask = AT91_PMC_MCKRDY | AT91_PMC_LOCKA;\n>  \n>  \tregmap_read(pmcreg, AT91_PMC_MCKR, &tmp);\n>  \tif (pmc_cache.mckr != tmp)\n> @@ -134,13 +144,11 @@ static void pmc_resume(void)\n>  \t\t\t     AT91_PMC_PCR_CMD);\n>  \t}\n>  \n> -\tif (pmc_cache.uckr & AT91_PMC_UPLLEN) {\n> -\t\tret = regmap_read_poll_timeout(pmcreg, AT91_PMC_SR, tmp,\n> -\t\t\t\t\t       !(tmp & AT91_PMC_LOCKU),\n> -\t\t\t\t\t       10, 5000);\n> -\t\tif (ret)\n> -\t\t\tpr_crit(\"USB PLL didn't lock when resuming\\n\");\n> -\t}\n> +\tif (pmc_cache.uckr & AT91_PMC_UPLLEN)\n> +\t\tmask |= AT91_PMC_LOCKU;\n> +\n> +\twhile (!pmc_ready(mask))\n> +\t\tcpu_relax();\n>  }\n>  \n>  static struct syscore_ops pmc_syscore_ops = {\n> -- \n> 2.11.0\n> \n--\nTo unsubscribe from this list: send the line \"unsubscribe linux-pwm\" in\nthe body of a message to majordomo@vger.kernel.org\nMore majordomo info at  http://vger.kernel.org/majordomo-info.html","headers":{"Return-Path":"<linux-pwm-owner@vger.kernel.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=linux-pwm-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xzBzv40b8z9sPk\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri, 22 Sep 2017 22:07:07 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1752148AbdIVMHG (ORCPT <rfc822;incoming@patchwork.ozlabs.org>);\n\tFri, 22 Sep 2017 08:07:06 -0400","from esa3.microchip.iphmx.com ([68.232.153.233]:10799 \"EHLO\n\tesa3.microchip.iphmx.com\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n\twith ESMTP id S1752039AbdIVMHE (ORCPT\n\t<rfc822; linux-pwm@vger.kernel.org>); Fri, 22 Sep 2017 08:07:04 -0400","from exsmtp02.microchip.com (HELO email.microchip.com)\n\t([198.175.253.38])\n\tby esa3.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA;\n\t22 Sep 2017 05:06:39 -0700","from localhost (10.10.76.4) by chn-sv-exch02.mchp-main.com\n\t(10.10.76.38) with Microsoft SMTP Server id 14.3.352.0;\n\tFri, 22 Sep 2017 05:06:38 -0700"],"X-IronPort-AV":"E=Sophos;i=\"5.42,427,1500966000\"; d=\"scan'208\";a=\"7272402\"","Date":"Fri, 22 Sep 2017 14:05:32 +0200","From":"Ludovic Desroches <ludovic.desroches@microchip.com>","To":"Romain Izard <romain.izard.pro@gmail.com>","CC":"Nicolas Ferre <nicolas.ferre@microchip.com>,\n\tAlexandre Belloni <alexandre.belloni@free-electrons.com>,\n\tBoris Brezillon <boris.brezillon@free-electrons.com>,\n\tMichael Turquette <mturquette@baylibre.com>,\n\tStephen Boyd <sboyd@codeaurora.org>,\n\tLudovic Desroches <ludovic.desroches@microchip.com>,\n\tWenyou Yang <wenyou.yang@atmel.com>, Josh Wu <rainyfeeling@outlook.com>,\n\tDavid Woodhouse <dwmw2@infradead.org>,\n\tBrian Norris <computersforpeace@gmail.com>,\n\tMarek Vasut <marek.vasut@gmail.com>,\n\tCyrille Pitchen <cyrille.pitchen@wedev4u.fr>,\n\tThierry Reding <thierry.reding@gmail.com>,\n\tRichard Genoud <richard.genoud@gmail.com>,\n\tGreg Kroah-Hartman <gregkh@linuxfoundation.org>,\n\tAlan Stern <stern@rowland.harvard.edu>,\n\t<linux-clk@vger.kernel.org>, <linux-kernel@vger.kernel.org>,\n\t<linux-mtd@lists.infradead.org>, <linux-pwm@vger.kernel.org>,\n\t<linux-serial@vger.kernel.org>, <linux-usb@vger.kernel.org>,\n\t<linux-arm-kernel@lists.infradead.org>","Subject":"Re: [PATCH v2 1/9] clk: at91: pmc: Wait for clocks when resuming","Message-ID":"<20170922120532.jddabnd57yt3iowe@rfolt0960.corp.atmel.com>","Mail-Followup-To":"Romain Izard <romain.izard.pro@gmail.com>,\n\tNicolas Ferre <nicolas.ferre@microchip.com>,\n\tAlexandre Belloni <alexandre.belloni@free-electrons.com>,\n\tBoris Brezillon <boris.brezillon@free-electrons.com>,\n\tMichael Turquette <mturquette@baylibre.com>,\n\tStephen Boyd <sboyd@codeaurora.org>,\n\tWenyou Yang <wenyou.yang@atmel.com>,\n\tJosh Wu <rainyfeeling@outlook.com>,\n\tDavid Woodhouse <dwmw2@infradead.org>,\n\tBrian Norris <computersforpeace@gmail.com>,\n\tMarek Vasut <marek.vasut@gmail.com>,\n\tCyrille Pitchen <cyrille.pitchen@wedev4u.fr>,\n\tThierry Reding <thierry.reding@gmail.com>,\n\tRichard Genoud <richard.genoud@gmail.com>,\n\tGreg Kroah-Hartman <gregkh@linuxfoundation.org>,\n\tAlan Stern <stern@rowland.harvard.edu>, linux-clk@vger.kernel.org,\n\tlinux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org,\n\tlinux-pwm@vger.kernel.org, linux-serial@vger.kernel.org,\n\tlinux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org","References":"<20170915140411.31716-1-romain.izard.pro@gmail.com>\n\t<20170915140411.31716-2-romain.izard.pro@gmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Disposition":"inline","In-Reply-To":"<20170915140411.31716-2-romain.izard.pro@gmail.com>","User-Agent":"NeoMutt/20170609 (1.8.3)","Sender":"linux-pwm-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<linux-pwm.vger.kernel.org>","X-Mailing-List":"linux-pwm@vger.kernel.org"}},{"id":1773537,"web_url":"http://patchwork.ozlabs.org/comment/1773537/","msgid":"<e5e1fb83-3106-3f8f-26d6-8b2d3cb4748a@microchip.com>","list_archive_url":null,"date":"2017-09-22T12:13:26","subject":"Re: [PATCH v2 1/9] clk: at91: pmc: Wait for clocks when resuming","submitter":{"id":71036,"url":"http://patchwork.ozlabs.org/api/people/71036/","name":"Nicolas Ferre","email":"nicolas.ferre@microchip.com"},"content":"On 15/09/2017 at 16:04, Romain Izard wrote:\n> Wait for the syncronization of all clocks when resuming, not only the\n> UPLL clock. Do not use regmap_read_poll_timeout, as it will call BUG()\n> when interrupts are masked, which is the case in here.\n> \n> Signed-off-by: Romain Izard <romain.izard.pro@gmail.com>\n\nAnd here is my:\nAcked-by: Nicolas Ferre <nicolas.ferre@microchip.com>\n\n> ---\n>  drivers/clk/at91/pmc.c | 24 ++++++++++++++++--------\n>  1 file changed, 16 insertions(+), 8 deletions(-)\n> \n> diff --git a/drivers/clk/at91/pmc.c b/drivers/clk/at91/pmc.c\n> index 775af473fe11..5c2b26de303e 100644\n> --- a/drivers/clk/at91/pmc.c\n> +++ b/drivers/clk/at91/pmc.c\n> @@ -107,10 +107,20 @@ static int pmc_suspend(void)\n>  \treturn 0;\n>  }\n>  \n> +static bool pmc_ready(unsigned int mask)\n> +{\n> +\tunsigned int status;\n> +\n> +\tregmap_read(pmcreg, AT91_PMC_SR, &status);\n> +\n> +\treturn ((status & mask) == mask) ? 1 : 0;\n> +}\n> +\n>  static void pmc_resume(void)\n>  {\n> -\tint i, ret = 0;\n> +\tint i;\n>  \tu32 tmp;\n> +\tu32 mask = AT91_PMC_MCKRDY | AT91_PMC_LOCKA;\n>  \n>  \tregmap_read(pmcreg, AT91_PMC_MCKR, &tmp);\n>  \tif (pmc_cache.mckr != tmp)\n> @@ -134,13 +144,11 @@ static void pmc_resume(void)\n>  \t\t\t     AT91_PMC_PCR_CMD);\n>  \t}\n>  \n> -\tif (pmc_cache.uckr & AT91_PMC_UPLLEN) {\n> -\t\tret = regmap_read_poll_timeout(pmcreg, AT91_PMC_SR, tmp,\n> -\t\t\t\t\t       !(tmp & AT91_PMC_LOCKU),\n> -\t\t\t\t\t       10, 5000);\n> -\t\tif (ret)\n> -\t\t\tpr_crit(\"USB PLL didn't lock when resuming\\n\");\n> -\t}\n> +\tif (pmc_cache.uckr & AT91_PMC_UPLLEN)\n> +\t\tmask |= AT91_PMC_LOCKU;\n> +\n> +\twhile (!pmc_ready(mask))\n> +\t\tcpu_relax();\n>  }\n>  \n>  static struct syscore_ops pmc_syscore_ops = {\n>","headers":{"Return-Path":"<linux-pwm-owner@vger.kernel.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=linux-pwm-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xzC5y4hWVz9sPk\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri, 22 Sep 2017 22:12:22 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1752216AbdIVMMV (ORCPT <rfc822;incoming@patchwork.ozlabs.org>);\n\tFri, 22 Sep 2017 08:12:21 -0400","from esa2.microchip.iphmx.com ([68.232.149.84]:10277 \"EHLO\n\tesa2.microchip.iphmx.com\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n\twith ESMTP id S1752197AbdIVMMU (ORCPT\n\t<rfc822; linux-pwm@vger.kernel.org>); Fri, 22 Sep 2017 08:12:20 -0400","from exsmtp01.microchip.com (HELO email.microchip.com)\n\t([198.175.253.37])\n\tby esa2.microchip.iphmx.com with ESMTP/TLS/AES128-SHA;\n\t22 Sep 2017 05:12:19 -0700","from [10.159.245.112] (10.10.76.4) by CHN-SV-EXCH01.mchp-main.com\n\t(10.10.76.37) with Microsoft SMTP Server id 14.3.352.0;\n\tFri, 22 Sep 2017 05:12:19 -0700"],"X-IronPort-AV":"E=Sophos;i=\"5.42,427,1500966000\"; d=\"scan'208\";a=\"7216739\"","Subject":"Re: [PATCH v2 1/9] clk: at91: pmc: Wait for clocks when resuming","To":"Romain Izard <romain.izard.pro@gmail.com>,\n\tAlexandre Belloni <alexandre.belloni@free-electrons.com>,\n\tBoris Brezillon <boris.brezillon@free-electrons.com>,\n\tMichael Turquette <mturquette@baylibre.com>,\n\tStephen Boyd <sboyd@codeaurora.org>,\n\tLudovic Desroches <ludovic.desroches@microchip.com>,\n\tWenyou Yang <wenyou.yang@atmel.com>, Josh Wu <rainyfeeling@outlook.com>,\n\tDavid Woodhouse <dwmw2@infradead.org>,\n\tBrian Norris <computersforpeace@gmail.com>,\n\tMarek Vasut <marek.vasut@gmail.com>,\n\tCyrille Pitchen <cyrille.pitchen@wedev4u.fr>,\n\tThierry Reding <thierry.reding@gmail.com>,\n\tRichard Genoud <richard.genoud@gmail.com>,\n\tGreg Kroah-Hartman <gregkh@linuxfoundation.org>,\n\tAlan Stern <stern@rowland.harvard.edu>","CC":"<linux-clk@vger.kernel.org>, <linux-kernel@vger.kernel.org>,\n\t<linux-mtd@lists.infradead.org>, <linux-pwm@vger.kernel.org>,\n\t<linux-serial@vger.kernel.org>, <linux-usb@vger.kernel.org>,\n\t<linux-arm-kernel@lists.infradead.org>","References":"<20170915140411.31716-1-romain.izard.pro@gmail.com>\n\t<20170915140411.31716-2-romain.izard.pro@gmail.com>","From":"Nicolas Ferre <nicolas.ferre@microchip.com>","Organization":"microchip","Message-ID":"<e5e1fb83-3106-3f8f-26d6-8b2d3cb4748a@microchip.com>","Date":"Fri, 22 Sep 2017 14:13:26 +0200","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.3.0","MIME-Version":"1.0","In-Reply-To":"<20170915140411.31716-2-romain.izard.pro@gmail.com>","Content-Type":"text/plain; charset=\"utf-8\"","Content-Language":"en-US","Content-Transfer-Encoding":"7bit","Sender":"linux-pwm-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<linux-pwm.vger.kernel.org>","X-Mailing-List":"linux-pwm@vger.kernel.org"}}]