All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 0/8] pull-request: can-next 2021-12-08
@ 2021-12-08 12:50 Marc Kleine-Budde
  2021-12-08 12:50 ` [PATCH net-next 1/8] can: bittiming: replace CAN units with the generic ones from linux/units.h Marc Kleine-Budde
                   ` (7 more replies)
  0 siblings, 8 replies; 10+ messages in thread
From: Marc Kleine-Budde @ 2021-12-08 12:50 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel

Hello Jakub, hello David,

this is a pull request of 8 patches for net-next/master.

The first patch is by Vincent Mailhol and replaces the custom CAN
units with generic one form linux/units.h.

The next 3 patches are by Evgeny Boger and add Allwinner R40 support
to the sun4i CAN driver.

Andy Shevchenko contributes 4 patches to the hi311x CAN driver,
consisting of cleanups and converting the driver to the device
property API.

regards,
Marc

---
The following changes since commit 1fe5b01262844be03de98afdd56d1d393df04d7e:

  Merge branch 's390-net-updates-2021-12-06' (2021-12-07 22:01:08 -0800)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next.git tags/linux-can-next-for-5.17-20211208

for you to fetch changes up to 6a93ea38217706ef8318efba672b960bcd5d0642:

  can: hi311x: hi3110_can_probe(): convert to use dev_err_probe() (2021-12-08 10:20:33 +0100)

----------------------------------------------------------------
linux-can-next-for-5.17-20211208

----------------------------------------------------------------
Andy Shevchenko (4):
      can: hi311x: hi3110_can_probe(): use devm_clk_get_optional() to get the input clock
      can: hi311x: hi3110_can_probe(): try to get crystal clock rate from property
      can: hi311x: hi3110_can_probe(): make use of device property API
      can: hi311x: hi3110_can_probe(): convert to use dev_err_probe()

Evgeny Boger (3):
      dt-bindings: net: can: add support for Allwinner R40 CAN controller
      can: sun4i_can: add support for R40 CAN controller
      ARM: dts: sun8i: r40: add node for CAN controller

Vincent Mailhol (1):
      can: bittiming: replace CAN units with the generic ones from linux/units.h

 .../bindings/net/can/allwinner,sun4i-a10-can.yaml  | 24 +++++++++
 arch/arm/boot/dts/sun8i-r40.dtsi                   | 19 +++++++
 drivers/net/can/dev/bittiming.c                    |  5 +-
 drivers/net/can/spi/hi311x.c                       | 52 +++++++++---------
 drivers/net/can/sun4i_can.c                        | 62 +++++++++++++++++++++-
 drivers/net/can/usb/etas_es58x/es581_4.c           |  5 +-
 drivers/net/can/usb/etas_es58x/es58x_fd.c          |  5 +-
 include/linux/can/bittiming.h                      |  7 ---
 8 files changed, 138 insertions(+), 41 deletions(-)



^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH net-next 1/8] can: bittiming: replace CAN units with the generic ones from linux/units.h
  2021-12-08 12:50 [PATCH net-next 0/8] pull-request: can-next 2021-12-08 Marc Kleine-Budde
@ 2021-12-08 12:50 ` Marc Kleine-Budde
  2021-12-09  1:20   ` patchwork-bot+netdevbpf
  2021-12-08 12:50 ` [PATCH net-next 2/8] dt-bindings: net: can: add support for Allwinner R40 CAN controller Marc Kleine-Budde
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 10+ messages in thread
From: Marc Kleine-Budde @ 2021-12-08 12:50 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Vincent Mailhol, Jimmy Assarsson,
	Oliver Hartkopp, Marc Kleine-Budde

From: Vincent Mailhol <mailhol.vincent@wanadoo.fr>

In [1], we introduced a set of units in linux/can/bittiming.h. Since
then, generic SI prefixes were added to linux/units.h in [2]. Those
new prefixes can perfectly replace CAN specific ones.

This patch replaces all occurrences of the CAN units with their
corresponding prefix (from linux/units) and the unit (as a comment)
according to below table.

 CAN units	SI metric prefix (from linux/units) + unit (as a comment)
 ------------------------------------------------------------------------
 CAN_KBPS	KILO /* BPS */
 CAN_MBPS	MEGA /* BPS */
 CAM_MHZ	MEGA /* Hz */

The definition are then removed from linux/can/bittiming.h

[1] commit 1d7750760b70 ("can: bittiming: add CAN_KBPS, CAN_MBPS and
CAN_MHZ macros")

[2] commit 26471d4a6cf8 ("units: Add SI metric prefix definitions")

Link: https://lore.kernel.org/all/20211124014536.782550-1-mailhol.vincent@wanadoo.fr
Suggested-by: Jimmy Assarsson <extja@kvaser.com>
Suggested-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/dev/bittiming.c           | 5 +++--
 drivers/net/can/usb/etas_es58x/es581_4.c  | 5 +++--
 drivers/net/can/usb/etas_es58x/es58x_fd.c | 5 +++--
 include/linux/can/bittiming.h             | 7 -------
 4 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/drivers/net/can/dev/bittiming.c b/drivers/net/can/dev/bittiming.c
index 0509625c3082..d5fca3bfaf9a 100644
--- a/drivers/net/can/dev/bittiming.c
+++ b/drivers/net/can/dev/bittiming.c
@@ -4,6 +4,7 @@
  * Copyright (C) 2008-2009 Wolfgang Grandegger <wg@grandegger.com>
  */
 
+#include <linux/units.h>
 #include <linux/can/dev.h>
 
 #ifdef CONFIG_CAN_CALC_BITTIMING
@@ -81,9 +82,9 @@ int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt,
 	if (bt->sample_point) {
 		sample_point_nominal = bt->sample_point;
 	} else {
-		if (bt->bitrate > 800 * CAN_KBPS)
+		if (bt->bitrate > 800 * KILO /* BPS */)
 			sample_point_nominal = 750;
-		else if (bt->bitrate > 500 * CAN_KBPS)
+		else if (bt->bitrate > 500 * KILO /* BPS */)
 			sample_point_nominal = 800;
 		else
 			sample_point_nominal = 875;
diff --git a/drivers/net/can/usb/etas_es58x/es581_4.c b/drivers/net/can/usb/etas_es58x/es581_4.c
index 14e360c9f2c9..1bcdcece5ec7 100644
--- a/drivers/net/can/usb/etas_es58x/es581_4.c
+++ b/drivers/net/can/usb/etas_es58x/es581_4.c
@@ -10,6 +10,7 @@
  */
 
 #include <linux/kernel.h>
+#include <linux/units.h>
 #include <asm/unaligned.h>
 
 #include "es58x_core.h"
@@ -469,8 +470,8 @@ const struct es58x_parameters es581_4_param = {
 	.bittiming_const = &es581_4_bittiming_const,
 	.data_bittiming_const = NULL,
 	.tdc_const = NULL,
-	.bitrate_max = 1 * CAN_MBPS,
-	.clock = {.freq = 50 * CAN_MHZ},
+	.bitrate_max = 1 * MEGA /* BPS */,
+	.clock = {.freq = 50 * MEGA /* Hz */},
 	.ctrlmode_supported = CAN_CTRLMODE_CC_LEN8_DLC,
 	.tx_start_of_frame = 0xAFAF,
 	.rx_start_of_frame = 0xFAFA,
diff --git a/drivers/net/can/usb/etas_es58x/es58x_fd.c b/drivers/net/can/usb/etas_es58x/es58x_fd.c
index 4f0cae29f4d8..ec87126e1a7d 100644
--- a/drivers/net/can/usb/etas_es58x/es58x_fd.c
+++ b/drivers/net/can/usb/etas_es58x/es58x_fd.c
@@ -12,6 +12,7 @@
  */
 
 #include <linux/kernel.h>
+#include <linux/units.h>
 #include <asm/unaligned.h>
 
 #include "es58x_core.h"
@@ -522,8 +523,8 @@ const struct es58x_parameters es58x_fd_param = {
 	 * Mbps work in an optimal environment but are not recommended
 	 * for production environment.
 	 */
-	.bitrate_max = 8 * CAN_MBPS,
-	.clock = {.freq = 80 * CAN_MHZ},
+	.bitrate_max = 8 * MEGA /* BPS */,
+	.clock = {.freq = 80 * MEGA /* Hz */},
 	.ctrlmode_supported = CAN_CTRLMODE_LOOPBACK | CAN_CTRLMODE_LISTENONLY |
 	    CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_FD | CAN_CTRLMODE_FD_NON_ISO |
 	    CAN_CTRLMODE_CC_LEN8_DLC | CAN_CTRLMODE_TDC_AUTO,
diff --git a/include/linux/can/bittiming.h b/include/linux/can/bittiming.h
index 20b50baf3a02..a81652d1c6f3 100644
--- a/include/linux/can/bittiming.h
+++ b/include/linux/can/bittiming.h
@@ -12,13 +12,6 @@
 #define CAN_SYNC_SEG 1
 
 
-/* Kilobits and Megabits per second */
-#define CAN_KBPS 1000UL
-#define CAN_MBPS 1000000UL
-
-/* Megahertz */
-#define CAN_MHZ 1000000UL
-
 #define CAN_CTRLMODE_TDC_MASK					\
 	(CAN_CTRLMODE_TDC_AUTO | CAN_CTRLMODE_TDC_MANUAL)
 

base-commit: 1fe5b01262844be03de98afdd56d1d393df04d7e
-- 
2.33.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH net-next 2/8] dt-bindings: net: can: add support for Allwinner R40 CAN controller
  2021-12-08 12:50 [PATCH net-next 0/8] pull-request: can-next 2021-12-08 Marc Kleine-Budde
  2021-12-08 12:50 ` [PATCH net-next 1/8] can: bittiming: replace CAN units with the generic ones from linux/units.h Marc Kleine-Budde
@ 2021-12-08 12:50 ` Marc Kleine-Budde
  2021-12-08 12:50 ` [PATCH net-next 3/8] can: sun4i_can: add support for " Marc Kleine-Budde
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Marc Kleine-Budde @ 2021-12-08 12:50 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Evgeny Boger, Rob Herring,
	Marc Kleine-Budde

From: Evgeny Boger <boger@wirenboard.com>

Allwinner R40 (also known as A40i, T3, V40) has a CAN controller. The
controller is the same as in earlier A10 and A20 SoCs, but needs reset
line to be deasserted before use.

This patch Introduces new compatible for R40 CAN controller with
required resets property.

Link: https://lore.kernel.org/all/20211122104616.537156-2-boger@wirenboard.com
Signed-off-by: Evgeny Boger <boger@wirenboard.com>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 .../net/can/allwinner,sun4i-a10-can.yaml      | 24 +++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/can/allwinner,sun4i-a10-can.yaml b/Documentation/devicetree/bindings/net/can/allwinner,sun4i-a10-can.yaml
index a95960ee3feb..c93fe9d3ea82 100644
--- a/Documentation/devicetree/bindings/net/can/allwinner,sun4i-a10-can.yaml
+++ b/Documentation/devicetree/bindings/net/can/allwinner,sun4i-a10-can.yaml
@@ -17,6 +17,7 @@ properties:
           - const: allwinner,sun7i-a20-can
           - const: allwinner,sun4i-a10-can
       - const: allwinner,sun4i-a10-can
+      - const: allwinner,sun8i-r40-can
 
   reg:
     maxItems: 1
@@ -27,6 +28,19 @@ properties:
   clocks:
     maxItems: 1
 
+  resets:
+    maxItems: 1
+
+if:
+  properties:
+    compatible:
+      contains:
+        const: allwinner,sun8i-r40-can
+
+then:
+  required:
+    - resets
+
 required:
   - compatible
   - reg
@@ -47,5 +61,15 @@ examples:
         interrupts = <GIC_SPI 26 IRQ_TYPE_LEVEL_HIGH>;
         clocks = <&ccu CLK_APB1_CAN>;
     };
+  - |
+    #define RST_BUS_CAN		68
+    #define CLK_BUS_CAN		91
+    can1: can@1c2bc00 {
+        compatible = "allwinner,sun8i-r40-can";
+        reg = <0x01c2bc00 0x400>;
+        interrupts = <GIC_SPI 26 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&ccu CLK_BUS_CAN>;
+        resets = <&ccu RST_BUS_CAN>;
+    };
 
 ...
-- 
2.33.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH net-next 3/8] can: sun4i_can: add support for R40 CAN controller
  2021-12-08 12:50 [PATCH net-next 0/8] pull-request: can-next 2021-12-08 Marc Kleine-Budde
  2021-12-08 12:50 ` [PATCH net-next 1/8] can: bittiming: replace CAN units with the generic ones from linux/units.h Marc Kleine-Budde
  2021-12-08 12:50 ` [PATCH net-next 2/8] dt-bindings: net: can: add support for Allwinner R40 CAN controller Marc Kleine-Budde
@ 2021-12-08 12:50 ` Marc Kleine-Budde
  2021-12-08 12:50 ` [PATCH net-next 4/8] ARM: dts: sun8i: r40: add node for " Marc Kleine-Budde
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Marc Kleine-Budde @ 2021-12-08 12:50 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel, Evgeny Boger, Marc Kleine-Budde

From: Evgeny Boger <boger@wirenboard.com>

Allwinner R40 (also known as A40i, T3, V40) has a CAN controller. The
controller is the same as in earlier A10 and A20 SoCs, but needs reset
line to be deasserted before use.

This patch adds a new compatible for R40 CAN controller. Depending
on the compatible, reset line can be requested from DT.

Link: https://lore.kernel.org/all/20211122104616.537156-3-boger@wirenboard.com
Signed-off-by: Evgeny Boger <boger@wirenboard.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/sun4i_can.c | 62 +++++++++++++++++++++++++++++++++++--
 1 file changed, 60 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/sun4i_can.c b/drivers/net/can/sun4i_can.c
index 54aa7c25c4de..37862e7f6840 100644
--- a/drivers/net/can/sun4i_can.c
+++ b/drivers/net/can/sun4i_can.c
@@ -61,6 +61,7 @@
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/platform_device.h>
+#include <linux/reset.h>
 
 #define DRV_NAME "sun4i_can"
 
@@ -200,10 +201,20 @@
 #define SUN4I_CAN_MAX_IRQ	20
 #define SUN4I_MODE_MAX_RETRIES	100
 
+/**
+ * struct sun4ican_quirks - Differences between SoC variants.
+ *
+ * @has_reset: SoC needs reset deasserted.
+ */
+struct sun4ican_quirks {
+	bool has_reset;
+};
+
 struct sun4ican_priv {
 	struct can_priv can;
 	void __iomem *base;
 	struct clk *clk;
+	struct reset_control *reset;
 	spinlock_t cmdreg_lock;	/* lock for concurrent cmd register writes */
 };
 
@@ -702,6 +713,13 @@ static int sun4ican_open(struct net_device *dev)
 		goto exit_irq;
 	}
 
+	/* software reset deassert */
+	err = reset_control_deassert(priv->reset);
+	if (err) {
+		netdev_err(dev, "could not deassert CAN reset\n");
+		goto exit_soft_reset;
+	}
+
 	/* turn on clocking for CAN peripheral block */
 	err = clk_prepare_enable(priv->clk);
 	if (err) {
@@ -723,6 +741,8 @@ static int sun4ican_open(struct net_device *dev)
 exit_can_start:
 	clk_disable_unprepare(priv->clk);
 exit_clock:
+	reset_control_assert(priv->reset);
+exit_soft_reset:
 	free_irq(dev->irq, dev);
 exit_irq:
 	close_candev(dev);
@@ -736,6 +756,7 @@ static int sun4ican_close(struct net_device *dev)
 	netif_stop_queue(dev);
 	sun4i_can_stop(dev);
 	clk_disable_unprepare(priv->clk);
+	reset_control_assert(priv->reset);
 
 	free_irq(dev->irq, dev);
 	close_candev(dev);
@@ -750,9 +771,27 @@ static const struct net_device_ops sun4ican_netdev_ops = {
 	.ndo_start_xmit = sun4ican_start_xmit,
 };
 
+static const struct sun4ican_quirks sun4ican_quirks_a10 = {
+	.has_reset = false,
+};
+
+static const struct sun4ican_quirks sun4ican_quirks_r40 = {
+	.has_reset = true,
+};
+
 static const struct of_device_id sun4ican_of_match[] = {
-	{.compatible = "allwinner,sun4i-a10-can"},
-	{},
+	{
+		.compatible = "allwinner,sun4i-a10-can",
+		.data = &sun4ican_quirks_a10
+	}, {
+		.compatible = "allwinner,sun7i-a20-can",
+		.data = &sun4ican_quirks_a10
+	}, {
+		.compatible = "allwinner,sun8i-r40-can",
+		.data = &sun4ican_quirks_r40
+	}, {
+		/* sentinel */
+	},
 };
 
 MODULE_DEVICE_TABLE(of, sun4ican_of_match);
@@ -771,10 +810,28 @@ static int sun4ican_probe(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
 	struct clk *clk;
+	struct reset_control *reset = NULL;
 	void __iomem *addr;
 	int err, irq;
 	struct net_device *dev;
 	struct sun4ican_priv *priv;
+	const struct sun4ican_quirks *quirks;
+
+	quirks = of_device_get_match_data(&pdev->dev);
+	if (!quirks) {
+		dev_err(&pdev->dev, "failed to determine the quirks to use\n");
+		err = -ENODEV;
+		goto exit;
+	}
+
+	if (quirks->has_reset) {
+		reset = devm_reset_control_get_exclusive(&pdev->dev, NULL);
+		if (IS_ERR(reset)) {
+			dev_err(&pdev->dev, "unable to request reset\n");
+			err = PTR_ERR(reset);
+			goto exit;
+		}
+	}
 
 	clk = of_clk_get(np, 0);
 	if (IS_ERR(clk)) {
@@ -818,6 +875,7 @@ static int sun4ican_probe(struct platform_device *pdev)
 				       CAN_CTRLMODE_3_SAMPLES;
 	priv->base = addr;
 	priv->clk = clk;
+	priv->reset = reset;
 	spin_lock_init(&priv->cmdreg_lock);
 
 	platform_set_drvdata(pdev, dev);
-- 
2.33.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH net-next 4/8] ARM: dts: sun8i: r40: add node for CAN controller
  2021-12-08 12:50 [PATCH net-next 0/8] pull-request: can-next 2021-12-08 Marc Kleine-Budde
                   ` (2 preceding siblings ...)
  2021-12-08 12:50 ` [PATCH net-next 3/8] can: sun4i_can: add support for " Marc Kleine-Budde
@ 2021-12-08 12:50 ` Marc Kleine-Budde
  2021-12-08 12:50 ` [PATCH net-next 5/8] can: hi311x: hi3110_can_probe(): use devm_clk_get_optional() to get the input clock Marc Kleine-Budde
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Marc Kleine-Budde @ 2021-12-08 12:50 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel, Evgeny Boger, Marc Kleine-Budde

From: Evgeny Boger <boger@wirenboard.com>

Allwinner R40 (also known as A40i, T3, V40) has a CAN controller. The
controller is the same as in earlier A10 and A20 SoCs, but needs reset
line to be deasserted before use.

This patch adds a CAN node and the corresponding pinctrl descriptions.

Link: https://lore.kernel.org/all/20211122104616.537156-4-boger@wirenboard.com
Signed-off-by: Evgeny Boger <boger@wirenboard.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 arch/arm/boot/dts/sun8i-r40.dtsi | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/arch/arm/boot/dts/sun8i-r40.dtsi b/arch/arm/boot/dts/sun8i-r40.dtsi
index 1d87fc0c24ee..c99c92f008a0 100644
--- a/arch/arm/boot/dts/sun8i-r40.dtsi
+++ b/arch/arm/boot/dts/sun8i-r40.dtsi
@@ -511,6 +511,16 @@ pio: pinctrl@1c20800 {
 			#interrupt-cells = <3>;
 			#gpio-cells = <3>;
 
+			can_ph_pins: can-ph-pins {
+				pins = "PH20", "PH21";
+				function = "can";
+			};
+
+			can_pa_pins: can-pa-pins {
+				pins = "PA16", "PA17";
+				function = "can";
+			};
+
 			clk_out_a_pin: clk-out-a-pin {
 				pins = "PI12";
 				function = "clk_out_a";
@@ -926,6 +936,15 @@ i2c3: i2c@1c2b800 {
 			#size-cells = <0>;
 		};
 
+		can0: can@1c2bc00 {
+			compatible = "allwinner,sun8i-r40-can";
+			reg = <0x01c2bc00 0x400>;
+			interrupts = <GIC_SPI 26 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&ccu CLK_BUS_CAN>;
+			resets = <&ccu RST_BUS_CAN>;
+			status = "disabled";
+		};
+
 		i2c4: i2c@1c2c000 {
 			compatible = "allwinner,sun6i-a31-i2c";
 			reg = <0x01c2c000 0x400>;
-- 
2.33.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH net-next 5/8] can: hi311x: hi3110_can_probe(): use devm_clk_get_optional() to get the input clock
  2021-12-08 12:50 [PATCH net-next 0/8] pull-request: can-next 2021-12-08 Marc Kleine-Budde
                   ` (3 preceding siblings ...)
  2021-12-08 12:50 ` [PATCH net-next 4/8] ARM: dts: sun8i: r40: add node for " Marc Kleine-Budde
@ 2021-12-08 12:50 ` Marc Kleine-Budde
  2021-12-08 12:50 ` [PATCH net-next 6/8] can: hi311x: hi3110_can_probe(): try to get crystal clock rate from property Marc Kleine-Budde
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Marc Kleine-Budde @ 2021-12-08 12:50 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel, Andy Shevchenko, Marc Kleine-Budde

From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

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.

Link: https://lore.kernel.org/all/20211206165542.69887-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 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);
 
-- 
2.33.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH net-next 6/8] can: hi311x: hi3110_can_probe(): try to get crystal clock rate from property
  2021-12-08 12:50 [PATCH net-next 0/8] pull-request: can-next 2021-12-08 Marc Kleine-Budde
                   ` (4 preceding siblings ...)
  2021-12-08 12:50 ` [PATCH net-next 5/8] can: hi311x: hi3110_can_probe(): use devm_clk_get_optional() to get the input clock Marc Kleine-Budde
@ 2021-12-08 12:50 ` Marc Kleine-Budde
  2021-12-08 12:50 ` [PATCH net-next 7/8] can: hi311x: hi3110_can_probe(): make use of device property API Marc Kleine-Budde
  2021-12-08 12:50 ` [PATCH net-next 8/8] can: hi311x: hi3110_can_probe(): convert to use dev_err_probe() Marc Kleine-Budde
  7 siblings, 0 replies; 10+ messages in thread
From: Marc Kleine-Budde @ 2021-12-08 12:50 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel, Andy Shevchenko, Marc Kleine-Budde

From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

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.

Link: https://lore.kernel.org/all/20211206165542.69887-2-andriy.shevchenko@linux.intel.com
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 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)
-- 
2.33.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH net-next 7/8] can: hi311x: hi3110_can_probe(): make use of device property API
  2021-12-08 12:50 [PATCH net-next 0/8] pull-request: can-next 2021-12-08 Marc Kleine-Budde
                   ` (5 preceding siblings ...)
  2021-12-08 12:50 ` [PATCH net-next 6/8] can: hi311x: hi3110_can_probe(): try to get crystal clock rate from property Marc Kleine-Budde
@ 2021-12-08 12:50 ` Marc Kleine-Budde
  2021-12-08 12:50 ` [PATCH net-next 8/8] can: hi311x: hi3110_can_probe(): convert to use dev_err_probe() Marc Kleine-Budde
  7 siblings, 0 replies; 10+ messages in thread
From: Marc Kleine-Budde @ 2021-12-08 12:50 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel, Andy Shevchenko, Marc Kleine-Budde

From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Make use of device property API in this driver so that both OF based
system and ACPI based system can use this driver.

Link: https://lore.kernel.org/all/20211206165542.69887-3-andriy.shevchenko@linux.intel.com
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 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 <linux/interrupt.h>
 #include <linux/io.h>
 #include <linux/kernel.h>
+#include <linux/mod_devicetable.h>
 #include <linux/module.h>
 #include <linux/netdevice.h>
-#include <linux/of.h>
-#include <linux/of_device.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 #include <linux/regulator/consumer.h>
 #include <linux/slab.h>
 #include <linux/spi/spi.h>
@@ -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;
-- 
2.33.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH net-next 8/8] can: hi311x: hi3110_can_probe(): convert to use dev_err_probe()
  2021-12-08 12:50 [PATCH net-next 0/8] pull-request: can-next 2021-12-08 Marc Kleine-Budde
                   ` (6 preceding siblings ...)
  2021-12-08 12:50 ` [PATCH net-next 7/8] can: hi311x: hi3110_can_probe(): make use of device property API Marc Kleine-Budde
@ 2021-12-08 12:50 ` Marc Kleine-Budde
  7 siblings, 0 replies; 10+ messages in thread
From: Marc Kleine-Budde @ 2021-12-08 12:50 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel, Andy Shevchenko, Marc Kleine-Budde

From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

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().

Link: https://lore.kernel.org/all/20211206165542.69887-4-andriy.shevchenko@linux.intel.com
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 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)
-- 
2.33.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH net-next 1/8] can: bittiming: replace CAN units with the generic ones from linux/units.h
  2021-12-08 12:50 ` [PATCH net-next 1/8] can: bittiming: replace CAN units with the generic ones from linux/units.h Marc Kleine-Budde
@ 2021-12-09  1:20   ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 10+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-12-09  1:20 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: netdev, davem, kuba, linux-can, kernel, mailhol.vincent, extja,
	socketcan

Hello:

This series was applied to netdev/net-next.git (master)
by Marc Kleine-Budde <mkl@pengutronix.de>:

On Wed,  8 Dec 2021 13:50:48 +0100 you wrote:
> From: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
> 
> In [1], we introduced a set of units in linux/can/bittiming.h. Since
> then, generic SI prefixes were added to linux/units.h in [2]. Those
> new prefixes can perfectly replace CAN specific ones.
> 
> This patch replaces all occurrences of the CAN units with their
> corresponding prefix (from linux/units) and the unit (as a comment)
> according to below table.
> 
> [...]

Here is the summary with links:
  - [net-next,1/8] can: bittiming: replace CAN units with the generic ones from linux/units.h
    https://git.kernel.org/netdev/net-next/c/330c6d3bfa26
  - [net-next,2/8] dt-bindings: net: can: add support for Allwinner R40 CAN controller
    https://git.kernel.org/netdev/net-next/c/d0342ceb78ed
  - [net-next,3/8] can: sun4i_can: add support for R40 CAN controller
    https://git.kernel.org/netdev/net-next/c/2c2fd0e68d9e
  - [net-next,4/8] ARM: dts: sun8i: r40: add node for CAN controller
    https://git.kernel.org/netdev/net-next/c/671f852c1bee
  - [net-next,5/8] can: hi311x: hi3110_can_probe(): use devm_clk_get_optional() to get the input clock
    https://git.kernel.org/netdev/net-next/c/369cf4e6ac53
  - [net-next,6/8] can: hi311x: hi3110_can_probe(): try to get crystal clock rate from property
    https://git.kernel.org/netdev/net-next/c/3a1ae63a4d21
  - [net-next,7/8] can: hi311x: hi3110_can_probe(): make use of device property API
    https://git.kernel.org/netdev/net-next/c/dc64d98aae75
  - [net-next,8/8] can: hi311x: hi3110_can_probe(): convert to use dev_err_probe()
    https://git.kernel.org/netdev/net-next/c/6a93ea382177

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-12-09  1:20 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-08 12:50 [PATCH net-next 0/8] pull-request: can-next 2021-12-08 Marc Kleine-Budde
2021-12-08 12:50 ` [PATCH net-next 1/8] can: bittiming: replace CAN units with the generic ones from linux/units.h Marc Kleine-Budde
2021-12-09  1:20   ` patchwork-bot+netdevbpf
2021-12-08 12:50 ` [PATCH net-next 2/8] dt-bindings: net: can: add support for Allwinner R40 CAN controller Marc Kleine-Budde
2021-12-08 12:50 ` [PATCH net-next 3/8] can: sun4i_can: add support for " Marc Kleine-Budde
2021-12-08 12:50 ` [PATCH net-next 4/8] ARM: dts: sun8i: r40: add node for " Marc Kleine-Budde
2021-12-08 12:50 ` [PATCH net-next 5/8] can: hi311x: hi3110_can_probe(): use devm_clk_get_optional() to get the input clock Marc Kleine-Budde
2021-12-08 12:50 ` [PATCH net-next 6/8] can: hi311x: hi3110_can_probe(): try to get crystal clock rate from property Marc Kleine-Budde
2021-12-08 12:50 ` [PATCH net-next 7/8] can: hi311x: hi3110_can_probe(): make use of device property API Marc Kleine-Budde
2021-12-08 12:50 ` [PATCH net-next 8/8] can: hi311x: hi3110_can_probe(): convert to use dev_err_probe() Marc Kleine-Budde

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.