From patchwork Fri Jan 11 19:42:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pawe=C5=82_Chmiel?= X-Patchwork-Id: 10760605 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6E6A71390 for ; Fri, 11 Jan 2019 19:43:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A93C2A078 for ; Fri, 11 Jan 2019 19:43:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4AFE02A08A; Fri, 11 Jan 2019 19:43:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C1AE22A073 for ; Fri, 11 Jan 2019 19:43:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732701AbfAKTnC (ORCPT ); Fri, 11 Jan 2019 14:43:02 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:36800 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732097AbfAKTnC (ORCPT ); Fri, 11 Jan 2019 14:43:02 -0500 Received: by mail-lj1-f195.google.com with SMTP id g11-v6so13965279ljk.3; Fri, 11 Jan 2019 11:42:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=WZRVS57tv9I9ffMetpNGaYITV4nVk628qDxZw36pJwY=; b=JoF+RxuWc2U9ZqruqdjMEi3EjCHt0bgwXRIwuZppsWf8QH8qSge61SMBsSilfSj6Tg pw4ZUIBNDO0tUwDtPKfgMFMBK3XFn5y6Qhgg03Iv0VNDuh+hLNhYUWZNGbf93yeK+5UM ZrxVROqyBcFhWrMElADODgOAENuuFx7t/ep+ZIddLBvvZHeBERqmkejK0mmu5JPXntBN Fcssi9buJrfJm0RUg/J5vDecw9WzoxkI7N/uh73NzFpO2vuo5F++6j2aH60pdxGSesrf Wv1wq15hteaG+z4NtC/OGLH9byfsjaNSasr3UprXgwDP5DxlpSAOpW86ViMmBBk9e+uq KZ6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=WZRVS57tv9I9ffMetpNGaYITV4nVk628qDxZw36pJwY=; b=eMza6BbSYqvmm9gDH++Ts5ymhQBdz44uCRDq5e0ul6Tlp040LTJUPnZsOCYJ1L7CWe Paqi4sOIh/36/l+Twv04vyq0L5vGpQ9KpTvuEB3MA2EqIHKzERyiyLNsdyPITdY8DMC3 hSc38F+ociy3yVJrZKSNaDDZr66J2HZJpnUBZRf5Mo0tvBcWLHcXI37Ni88gGVkNamsl 5raONeTkT2g5NN+Oc34603DBnWzFoKX7qfwjJ4cU+pFlFeti83TxInNfXvuhz4Guqa6U C4YrhgjQJdG+8gxHTmQXL8Zh028ygKuJMi5i5dx1Vci5SumQaNxSuIN4Q1bJ/KI48ZRF gKIQ== X-Gm-Message-State: AJcUukeiXMwHApz8Er5R7woI5zp2UKiGbgWElmqr7xV/tqK9jEpAlL55 BoKfge9QZmTiP03Rd0EGiaA= X-Google-Smtp-Source: ALg8bN5G1D/gYawrOZ1LXdLsVI9Ryj4UGQP1xBGAR8D5E9SYUt9eLCKuZEmQortAT8+vnWDeCbTIgw== X-Received: by 2002:a2e:e02:: with SMTP id 2-v6mr6808353ljo.10.1547235778733; Fri, 11 Jan 2019 11:42:58 -0800 (PST) Received: from localhost.localdomain ([2a02:a315:5445:5300:1c33:9053:5344:9f1f]) by smtp.googlemail.com with ESMTPSA id h3sm14602964lfj.25.2019.01.11.11.42.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Jan 2019 11:42:57 -0800 (PST) From: =?utf-8?q?Pawe=C5=82_Chmiel?= To: kgene@kernel.org Cc: krzk@kernel.org, viresh.kumar@linaro.org, rjw@rjwysocki.net, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Pawe?= =?utf-8?q?=C5=82_Chmiel?= Subject: [PATCH v3] cpufreq: s5pv210: Defer probe if getting regulators fail Date: Fri, 11 Jan 2019 20:42:44 +0100 Message-Id: <20190111194244.2439-1-pawel.mikolaj.chmiel@gmail.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There is possibility, that when probing driver, regulators are not yet initialized. In this case we should return EPROBE_DEFER and wait till they're initialized, since they're required currently for cpufreq driver to work. Also move regulator initialization code at beginning of probe, so we can defer as fast as posibble. Signed-off-by: Paweł Chmiel --- Changes from v2: - Handle all error paths in probe Changes from v1: - Fix compilation error - Reorganize code so it's smaller --- drivers/cpufreq/s5pv210-cpufreq.c | 68 ++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 19 deletions(-) diff --git a/drivers/cpufreq/s5pv210-cpufreq.c b/drivers/cpufreq/s5pv210-cpufreq.c index f51697f1e0b3..627b132e3e61 100644 --- a/drivers/cpufreq/s5pv210-cpufreq.c +++ b/drivers/cpufreq/s5pv210-cpufreq.c @@ -584,7 +584,7 @@ static struct notifier_block s5pv210_cpufreq_reboot_notifier = { static int s5pv210_cpufreq_probe(struct platform_device *pdev) { struct device_node *np; - int id; + int id, result = 0; /* * HACK: This is a temporary workaround to get access to clock @@ -594,18 +594,40 @@ static int s5pv210_cpufreq_probe(struct platform_device *pdev) * this whole driver as soon as S5PV210 gets migrated to use * cpufreq-dt driver. */ + arm_regulator = regulator_get(NULL, "vddarm"); + if (IS_ERR(arm_regulator)) { + if (PTR_ERR(arm_regulator) == -EPROBE_DEFER) + pr_debug("vddarm regulator not ready, defer\n"); + else + pr_err("failed to get regulator vddarm\n"); + result = PTR_ERR(arm_regulator); + goto err_arm_regulator; + } + + int_regulator = regulator_get(NULL, "vddint"); + if (IS_ERR(int_regulator)) { + if (PTR_ERR(int_regulator) == -EPROBE_DEFER) + pr_debug("vddint regulator not ready, defer\n"); + else + pr_err("failed to get regulator vddint\n"); + result = PTR_ERR(int_regulator); + goto err_int_regulator; + } + np = of_find_compatible_node(NULL, NULL, "samsung,s5pv210-clock"); if (!np) { pr_err("%s: failed to find clock controller DT node\n", __func__); - return -ENODEV; + result = -ENODEV; + goto err_clock; } clk_base = of_iomap(np, 0); of_node_put(np); if (!clk_base) { pr_err("%s: failed to map clock registers\n", __func__); - return -EFAULT; + result = -EFAULT; + goto err_clock; } for_each_compatible_node(np, NULL, "samsung,s5pv210-dmc") { @@ -614,7 +636,8 @@ static int s5pv210_cpufreq_probe(struct platform_device *pdev) pr_err("%s: failed to get alias of dmc node '%pOFn'\n", __func__, np); of_node_put(np); - return id; + result = id; + goto err_clk_base; } dmc_base[id] = of_iomap(np, 0); @@ -622,33 +645,40 @@ static int s5pv210_cpufreq_probe(struct platform_device *pdev) pr_err("%s: failed to map dmc%d registers\n", __func__, id); of_node_put(np); - return -EFAULT; + result = -EFAULT; + goto err_dmc; } } for (id = 0; id < ARRAY_SIZE(dmc_base); ++id) { if (!dmc_base[id]) { pr_err("%s: failed to find dmc%d node\n", __func__, id); - return -ENODEV; + result = -ENODEV; + goto err_dmc; } } - arm_regulator = regulator_get(NULL, "vddarm"); - if (IS_ERR(arm_regulator)) { - pr_err("failed to get regulator vddarm\n"); - return PTR_ERR(arm_regulator); - } - - int_regulator = regulator_get(NULL, "vddint"); - if (IS_ERR(int_regulator)) { - pr_err("failed to get regulator vddint\n"); - regulator_put(arm_regulator); - return PTR_ERR(int_regulator); - } - register_reboot_notifier(&s5pv210_cpufreq_reboot_notifier); return cpufreq_register_driver(&s5pv210_driver); + +err_dmc: + for (id = 0; id < ARRAY_SIZE(dmc_base); ++id) + if (dmc_base[id]) + iounmap(dmc_base[id]); + +err_clk_base: + iounmap(clk_base); + +err_clock: + regulator_put(int_regulator); + +err_int_regulator: + regulator_put(arm_regulator); + +err_arm_regulator: + + return result; } static struct platform_driver s5pv210_cpufreq_platdrv = {