From patchwork Mon Dec 6 16:55:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12658955 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 817BFC433EF for ; Mon, 6 Dec 2021 17:04:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237547AbhLFRH4 (ORCPT ); Mon, 6 Dec 2021 12:07:56 -0500 Received: from mga03.intel.com ([134.134.136.65]:14428 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236252AbhLFQ7J (ORCPT ); Mon, 6 Dec 2021 11:59:09 -0500 X-IronPort-AV: E=McAfee;i="6200,9189,10190"; a="237299818" X-IronPort-AV: E=Sophos;i="5.87,292,1631602800"; d="scan'208";a="237299818" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Dec 2021 08:55:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,292,1631602800"; d="scan'208";a="605096994" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga002.fm.intel.com with ESMTP; 06 Dec 2021 08:55:37 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 14A7D144; Mon, 6 Dec 2021 18:55:42 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Wolfgang Grandegger , Marc Kleine-Budde , "David S. Miller" , Jakub Kicinski Subject: [PATCH v2 1/4] can: hi311x: Use devm_clk_get_optional() to get the input clock Date: Mon, 6 Dec 2021 18:55:39 +0200 Message-Id: <20211206165542.69887-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org It's not clear what was the intention of redundant usage of IS_ERR() around the clock pointer since with the error check of devm_clk_get() followed by bailout it can't be invalid, Simplify the code which fetches the input clock by using devm_clk_get_optional(). It will allow to switch to device properties approach in the future. Signed-off-by: Andy Shevchenko --- v2: no changes drivers/net/can/spi/hi311x.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/net/can/spi/hi311x.c b/drivers/net/can/spi/hi311x.c index 89d9c986a229..13fb979645cf 100644 --- a/drivers/net/can/spi/hi311x.c +++ b/drivers/net/can/spi/hi311x.c @@ -835,7 +835,7 @@ static int hi3110_can_probe(struct spi_device *spi) struct clk *clk; int freq, ret; - clk = devm_clk_get(&spi->dev, NULL); + clk = devm_clk_get_optional(&spi->dev, NULL); if (IS_ERR(clk)) { dev_err(&spi->dev, "no CAN clock source defined\n"); return PTR_ERR(clk); @@ -851,11 +851,9 @@ static int hi3110_can_probe(struct spi_device *spi) if (!net) return -ENOMEM; - if (!IS_ERR(clk)) { - ret = clk_prepare_enable(clk); - if (ret) - goto out_free; - } + ret = clk_prepare_enable(clk); + if (ret) + goto out_free; net->netdev_ops = &hi3110_netdev_ops; net->flags |= IFF_ECHO; @@ -938,8 +936,7 @@ static int hi3110_can_probe(struct spi_device *spi) hi3110_power_enable(priv->power, 0); out_clk: - if (!IS_ERR(clk)) - clk_disable_unprepare(clk); + clk_disable_unprepare(clk); out_free: free_candev(net); @@ -957,8 +954,7 @@ static int hi3110_can_remove(struct spi_device *spi) hi3110_power_enable(priv->power, 0); - if (!IS_ERR(priv->clk)) - clk_disable_unprepare(priv->clk); + clk_disable_unprepare(priv->clk); free_candev(net); From patchwork Mon Dec 6 16:55:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12658947 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE030C433F5 for ; Mon, 6 Dec 2021 17:04:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234189AbhLFRHy (ORCPT ); Mon, 6 Dec 2021 12:07:54 -0500 Received: from mga02.intel.com ([134.134.136.20]:48272 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242253AbhLFQ7I (ORCPT ); Mon, 6 Dec 2021 11:59:08 -0500 X-IronPort-AV: E=McAfee;i="6200,9189,10190"; a="224607766" X-IronPort-AV: E=Sophos;i="5.87,292,1631602800"; d="scan'208";a="224607766" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Dec 2021 08:55:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,292,1631602800"; d="scan'208";a="611308084" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga004.jf.intel.com with ESMTP; 06 Dec 2021 08:55:37 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 1DCF2B8; Mon, 6 Dec 2021 18:55:43 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Wolfgang Grandegger , Marc Kleine-Budde , "David S. Miller" , Jakub Kicinski Subject: [PATCH v2 2/4] can: hi311x: try to get crystal clock rate from property Date: Mon, 6 Dec 2021 18:55:40 +0200 Message-Id: <20211206165542.69887-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211206165542.69887-1-andriy.shevchenko@linux.intel.com> References: <20211206165542.69887-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org In some configurations, mainly ACPI-based, the clock frequency of the device is supplied by very well established 'clock-frequency' property. Hence, try to get it from the property at last if no other providers are available. Signed-off-by: Andy Shevchenko --- v2: fixed rebase issue and hence no compilation error drivers/net/can/spi/hi311x.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/net/can/spi/hi311x.c b/drivers/net/can/spi/hi311x.c index 13fb979645cf..c9efdd10d0f8 100644 --- a/drivers/net/can/spi/hi311x.c +++ b/drivers/net/can/spi/hi311x.c @@ -830,17 +830,26 @@ static int hi3110_can_probe(struct spi_device *spi) { const struct of_device_id *of_id = of_match_device(hi3110_of_match, &spi->dev); + struct device *dev = &spi->dev; struct net_device *net; struct hi3110_priv *priv; struct clk *clk; - int freq, ret; + u32 freq; + int ret; clk = devm_clk_get_optional(&spi->dev, NULL); if (IS_ERR(clk)) { dev_err(&spi->dev, "no CAN clock source defined\n"); return PTR_ERR(clk); } - freq = clk_get_rate(clk); + + if (clk) { + freq = clk_get_rate(clk); + } else { + ret = device_property_read_u32(dev, "clock-frequency", &freq); + if (ret) + return dev_err_probe(dev, ret, "Failed to get clock-frequency!\n"); + } /* Sanity check */ if (freq > 40000000) From patchwork Mon Dec 6 16:55:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12658953 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC18CC43217 for ; Mon, 6 Dec 2021 17:04:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240371AbhLFRH5 (ORCPT ); Mon, 6 Dec 2021 12:07:57 -0500 Received: from mga12.intel.com ([192.55.52.136]:21821 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347489AbhLFQ7K (ORCPT ); Mon, 6 Dec 2021 11:59:10 -0500 X-IronPort-AV: E=McAfee;i="6200,9189,10190"; a="217381116" X-IronPort-AV: E=Sophos;i="5.87,292,1631602800"; d="scan'208";a="217381116" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Dec 2021 08:55:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,292,1631602800"; d="scan'208";a="479182504" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga002.jf.intel.com with ESMTP; 06 Dec 2021 08:55:37 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 2D79B199; Mon, 6 Dec 2021 18:55:43 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Wolfgang Grandegger , Marc Kleine-Budde , "David S. Miller" , Jakub Kicinski Subject: [PATCH v2 3/4] can: hi311x: Make use of device property API Date: Mon, 6 Dec 2021 18:55:41 +0200 Message-Id: <20211206165542.69887-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211206165542.69887-1-andriy.shevchenko@linux.intel.com> References: <20211206165542.69887-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Make use of device property API in this driver so that both OF based system and ACPI based system can use this driver. Signed-off-by: Andy Shevchenko --- v2: no changes drivers/net/can/spi/hi311x.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/net/can/spi/hi311x.c b/drivers/net/can/spi/hi311x.c index c9efdd10d0f8..78044ec24575 100644 --- a/drivers/net/can/spi/hi311x.c +++ b/drivers/net/can/spi/hi311x.c @@ -25,11 +25,11 @@ #include #include #include +#include #include #include -#include -#include #include +#include #include #include #include @@ -828,11 +828,10 @@ MODULE_DEVICE_TABLE(spi, hi3110_id_table); static int hi3110_can_probe(struct spi_device *spi) { - const struct of_device_id *of_id = of_match_device(hi3110_of_match, - &spi->dev); struct device *dev = &spi->dev; struct net_device *net; struct hi3110_priv *priv; + const void *match; struct clk *clk; u32 freq; int ret; @@ -877,8 +876,9 @@ static int hi3110_can_probe(struct spi_device *spi) CAN_CTRLMODE_LISTENONLY | CAN_CTRLMODE_BERR_REPORTING; - if (of_id) - priv->model = (enum hi3110_model)(uintptr_t)of_id->data; + match = device_get_match_data(dev); + if (match) + priv->model = (enum hi3110_model)(uintptr_t)match; else priv->model = spi_get_device_id(spi)->driver_data; priv->net = net; From patchwork Mon Dec 6 16:55:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12658949 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B507C433FE for ; Mon, 6 Dec 2021 17:04:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233925AbhLFRHz (ORCPT ); Mon, 6 Dec 2021 12:07:55 -0500 Received: from mga12.intel.com ([192.55.52.136]:21821 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347476AbhLFQ7I (ORCPT ); Mon, 6 Dec 2021 11:59:08 -0500 X-IronPort-AV: E=McAfee;i="6200,9189,10190"; a="217381108" X-IronPort-AV: E=Sophos;i="5.87,292,1631602800"; d="scan'208";a="217381108" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Dec 2021 08:55:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,292,1631602800"; d="scan'208";a="514829909" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga008.jf.intel.com with ESMTP; 06 Dec 2021 08:55:37 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 3751415C; Mon, 6 Dec 2021 18:55:43 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Wolfgang Grandegger , Marc Kleine-Budde , "David S. Miller" , Jakub Kicinski Subject: [PATCH v2 4/4] can: hi311x: Convert to use dev_err_probe() Date: Mon, 6 Dec 2021 18:55:42 +0200 Message-Id: <20211206165542.69887-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211206165542.69887-1-andriy.shevchenko@linux.intel.com> References: <20211206165542.69887-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org When deferred the reason is saved for further debugging. Besides that, it's fine to call dev_err_probe() in ->probe() when error code is known. Convert the driver to use dev_err_probe(). Signed-off-by: Andy Shevchenko --- v2: no changes drivers/net/can/spi/hi311x.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/drivers/net/can/spi/hi311x.c b/drivers/net/can/spi/hi311x.c index 78044ec24575..a17641d36468 100644 --- a/drivers/net/can/spi/hi311x.c +++ b/drivers/net/can/spi/hi311x.c @@ -837,10 +837,8 @@ static int hi3110_can_probe(struct spi_device *spi) int ret; clk = devm_clk_get_optional(&spi->dev, NULL); - if (IS_ERR(clk)) { - dev_err(&spi->dev, "no CAN clock source defined\n"); - return PTR_ERR(clk); - } + if (IS_ERR(clk)) + return dev_err_probe(dev, PTR_ERR(clk), "no CAN clock source defined\n"); if (clk) { freq = clk_get_rate(clk); @@ -925,9 +923,7 @@ static int hi3110_can_probe(struct spi_device *spi) ret = hi3110_hw_probe(spi); if (ret) { - if (ret == -ENODEV) - dev_err(&spi->dev, "Cannot initialize %x. Wrong wiring?\n", - priv->model); + dev_err_probe(dev, ret, "Cannot initialize %x. Wrong wiring?\n", priv->model); goto error_probe; } hi3110_hw_sleep(spi); @@ -950,8 +946,7 @@ static int hi3110_can_probe(struct spi_device *spi) out_free: free_candev(net); - dev_err(&spi->dev, "Probe failed, err=%d\n", -ret); - return ret; + return dev_err_probe(dev, ret, "Probe failed\n"); } static int hi3110_can_remove(struct spi_device *spi)