Skip to contentSkip to conversation

ADD DM9051 ETHERNET DRIVER

PATCH Superseded JosephCHANG 4 participants 7 messages Dec 10, 2021 – Dec 12, 2021

Subsystems (3)

v3 of 20 Superseded Latest is v20 →

lore
Share & tools
lore
#0 lore raw

v3 cover ADD DM9051 ETHERNET DRIVER

DM9051 is a spi interface ethernet controller chip Fewer connect pins to CPU compare to DM9000.

JosephCHANG (2):
yaml: Add dm9051 SPI network yaml file
net: Add dm9051 driver

 .../bindings/net/davicom,dm9051.yaml          |  71 ++
 drivers/net/ethernet/davicom/Kconfig          |  30 +
 drivers/net/ethernet/davicom/Makefile         |   1 +
 drivers/net/ethernet/davicom/dm9051.c         | 861 ++++++++++++++++++
 drivers/net/ethernet/davicom/dm9051.h         | 225 +++++
 5 files changed, 1188 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/davicom,dm9051.yaml
 create mode 100644 drivers/net/ethernet/davicom/dm9051.c
 create mode 100644 drivers/net/ethernet/davicom/dm9051.h

base-commit: 9d922f5df53844228b9f7c62f2593f4f06c0b69b

Signature · 1 line
2.20.1
#1 lore raw

PATCH v3 1/2 yaml: Add dm9051 SPI network yaml file

For support davicom dm9051 device tree configure

---
 .../bindings/net/davicom,dm9051.yaml          | 71 +++++++++++++++++++
 1 file changed, 71 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/davicom,dm9051.yaml
Documentation/devicetree/bindings/net/davicom,dm9051.yaml new file +71 -0
new file mode 100644
index 000000000000..4c2dd0362f7a
@@ -0,0 +1,71 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/davicom,dm9051.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Davicom DM9051 SPI Ethernet Controller
+
+maintainers:
+  - Joseph CHANG <[email protected]>
+
+description: |
+  The DM9051 is a fully integrated and cost-effective low pin count single
+  chip Fast Ethernet controller with a Serial Peripheral Interface (SPI).
+
+allOf:
+  - $ref: ethernet-controller.yaml#
+
+properties:
+  compatible:
+    const: davicom,dm9051
+
+  reg:
+    maxItems: 1
+
+  spi-max-frequency:
+    maximum: 45000000
+
+  interrupts:
+    maxItems: 1
+
+  local-mac-address: true
+
+  mac-address: true
+
+required:
+  - compatible
+  - reg
+  - spi-max-frequency
+  - interrupts
+
+additionalProperties: false
+
+examples:
+  # Raspberry Pi platform
+  - |
+    /* for Raspberry Pi with pin control stuff for GPIO irq */
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/gpio/gpio.h>
+    spi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        dm9051@0 {
+            compatible = "davicom,dm9051";
+            reg = <0>; /* spi chip select */
+            local-mac-address = [00 00 00 00 00 00];
+            pinctrl-names = "default";
+            pinctrl-0 = <&eth_int_pins>;
+            interrupt-parent = <&gpio>;
+            interrupts = <26 IRQ_TYPE_LEVEL_LOW>;
+            spi-max-frequency = <31200000>;
+        };
+    };
+    gpio {
+        eth_int_pins {
+            brcm,pins = <26>;
+            brcm,function = <0>; /* in */
+            brcm,pull = <0>; /* none */
+        };
+    };
Signature · 1 line
2.20.1
maintainer
#2 lore raw

Re: [PATCH v3, 1/2] yaml: Add dm9051 SPI network yaml file

Quoted 8 lines · JosephCHANG

For support davicom dm9051 device tree configure

---
 .../bindings/net/davicom,dm9051.yaml          | 71 +++++++++++++++++++
 1 file changed, 71 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/davicom,dm9051.yaml

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/net/davicom,dm9051.example.dt.yaml: dm9051@0: $nodename:0: 'dm9051@0' does not match '^ethernet(@.*)?$'
From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/net/davicom,dm9051.yaml

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/patch/1566354

This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit.

maintainer
#3 lore raw

Re: [PATCH v3, 1/2] yaml: Add dm9051 SPI network yaml file

In reply to JosephCHANG

On Fri, Dec 10, 2021 at 04:40:20PM +0800, JosephCHANG wrote:

Follow the subject style used for the directory. 'dt-bindings: net: ...'

Quoted 1 line

For support davicom dm9051 device tree configure

Complete sentences please.

Quoted 2 lines

space? ^

Quoted 55 lines
---
 .../bindings/net/davicom,dm9051.yaml          | 71 +++++++++++++++++++
 1 file changed, 71 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/davicom,dm9051.yaml
Documentation/devicetree/bindings/net/davicom,dm9051.yaml new file +44 -0
new file mode 100644
index 000000000000..4c2dd0362f7a
@@ -0,0 +1,71 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/davicom,dm9051.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Davicom DM9051 SPI Ethernet Controller
+
+maintainers:
+  - Joseph CHANG <[email protected]>
+
+description: |
+  The DM9051 is a fully integrated and cost-effective low pin count single
+  chip Fast Ethernet controller with a Serial Peripheral Interface (SPI).
+
+allOf:
+  - $ref: ethernet-controller.yaml#
+
+properties:
+  compatible:
+    const: davicom,dm9051
+
+  reg:
+    maxItems: 1
+
+  spi-max-frequency:
+    maximum: 45000000
+
+  interrupts:
+    maxItems: 1
+
+  local-mac-address: true
+
+  mac-address: true
+
+required:
+  - compatible
+  - reg
+  - spi-max-frequency
+  - interrupts
+
+additionalProperties: false
+
+examples:

Documentation/devicetree/bindings/net/davicom,dm9051.yaml line 54

Quoted 10 lines
Documentation/devicetree/bindings/net/davicom,dm9051.yaml new file +10 -0
+  # Raspberry Pi platform
+  - |
+    /* for Raspberry Pi with pin control stuff for GPIO irq */
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/gpio/gpio.h>
+    spi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        dm9051@0 {

ethernet@...

Documentation/devicetree/bindings/net/davicom,dm9051.yaml line 65

Quoted 11 lines
Documentation/devicetree/bindings/net/davicom,dm9051.yaml new file +11 -0
+            compatible = "davicom,dm9051";
+            reg = <0>; /* spi chip select */
+            local-mac-address = [00 00 00 00 00 00];
+            pinctrl-names = "default";
+            pinctrl-0 = <&eth_int_pins>;
+            interrupt-parent = <&gpio>;
+            interrupts = <26 IRQ_TYPE_LEVEL_LOW>;
+            spi-max-frequency = <31200000>;
+        };
+    };
+    gpio {

This part is not relevant to the binding example.

Quoted 10 lines
Documentation/devicetree/bindings/net/davicom,dm9051.yaml new file +6 -0
+        eth_int_pins {
+            brcm,pins = <26>;
+            brcm,function = <0>; /* in */
+            brcm,pull = <0>; /* none */
+        };
+    };
Signature · 1 line
2.20.1
#4 lore raw

PATCH v3 2/2 net: Add dm9051 driver

In reply to JosephCHANG

Add davicom dm9051 spi ethernet driver. The driver work for the device with its spi master.

Test ok with raspberry pi 2 and pi 4, the spi configure used in my raspberry pi 4 is spi0.1, spi speed 31200000, and INT by pin 26.

---
 drivers/net/ethernet/davicom/Kconfig  |  30 +
 drivers/net/ethernet/davicom/Makefile |   1 +
 drivers/net/ethernet/davicom/dm9051.c | 861 ++++++++++++++++++++++++++
 drivers/net/ethernet/davicom/dm9051.h | 225 +++++++
 4 files changed, 1117 insertions(+)
 create mode 100644 drivers/net/ethernet/davicom/dm9051.c
 create mode 100644 drivers/net/ethernet/davicom/dm9051.h
drivers/net/ethernet/davicom/Kconfig +30 -0
index 7af86b6d4150..9c00328f6e05 100644
@@ -3,6 +3,20 @@
 # Davicom device configuration
 #
 
+config NET_VENDOR_DAVICOM
+	bool "Davicom devices"
+	depends on ARM || MIPS || COLDFIRE || NIOS2 || COMPILE_TEST || SPI
+	default y
+	help
+	  If you have a network (Ethernet) card belonging to this class, say Y.
+
+	  Note that the answer to this question doesn't directly affect the
+	  kernel: saying N will just cause the configurator to skip all
+	  the questions about Davicom devices. If you say Y, you will be asked
+	  for your specific card in the following selections.
+
+if NET_VENDOR_DAVICOM
+
 config DM9000
 	tristate "DM9000 support"
 	depends on ARM || MIPS || COLDFIRE || NIOS2 || COMPILE_TEST
@@ -22,3 +36,19 @@ config DM9000_FORCE_SIMPLE_PHY_POLL
 	  bit to determine if the link is up or down instead of the more
 	  costly MII PHY reads. Note, this will not work if the chip is
 	  operating with an external PHY.
+
+config DM9051
+	tristate "DM9051 SPI support"
+	depends on SPI
+	select CRC32
+	select MII
+	help
+	  Support for DM9051 SPI chipset.
+
+	  To compile this driver as a module, choose M here.  The module
+	  will be called dm9051.
+
+	  The SPI mode for the host's SPI master to access DM9051 is mode
+	  0 on the SPI bus.
+
+endif # NET_VENDOR_DAVICOM
drivers/net/ethernet/davicom/Makefile +1 -0
index 173c87d21076..225f85bc1f53 100644
@@ -4,3 +4,4 @@
 #
 
 obj-$(CONFIG_DM9000) += dm9000.o
+obj-$(CONFIG_DM9051) += dm9051.o
drivers/net/ethernet/davicom/dm9051.c new file +861 -0

861 lines not on this page · raw message

drivers/net/ethernet/davicom/dm9051.h new file +225 -0

225 lines not on this page · raw message

Signature · 1 line
2.20.1
maintainer
#5 lore raw

Re: [PATCH v3, 2/2] net: Add dm9051 driver

Quoted 5 lines · On Fri, 10 Dec 2021 16:40:21 +0800 JosephCHANG wrote:

Add davicom dm9051 spi ethernet driver. The driver work for the device with its spi master.

Test ok with raspberry pi 2 and pi 4, the spi configure used in my raspberry pi 4 is spi0.1, spi speed 31200000, and INT by pin 26.

Please rebase on top of net-next, this does not build because netdev->dev_addr is constant now.

#6 lore raw

Re: [PATCH v3, 2/2] net: Add dm9051 driver

In reply to JosephCHANG

drivers/net/ethernet/davicom/dm9051.h line 148

Quoted 7 lines
drivers/net/ethernet/davicom/dm9051.h new file +7 -0
+/* netdev_ops
+ */
+static int dm9051_open(struct net_device *dev);
+static int dm9051_stop(struct net_device *dev);
+static netdev_tx_t dm9051_start_xmit(struct sk_buff *skb, struct net_device *dev);
+static void dm9051_set_multicast_list_schedule(struct net_device *dev);
+static int dm9051_set_mac_address(struct net_device *dev, void *p);

You should not need these. Move the code around so the functions come before there first use.

drivers/net/ethernet/davicom/dm9051.h line 158

Quoted 4 lines
drivers/net/ethernet/davicom/dm9051.h new file +4 -0
+/* carrier
+ */
+#define	dm_carrier_init(db)			mii_check_link(&(db)->mii)
+#define	dm_carrier_poll(db)			mii_check_link(&(db)->mii)

I requested you make use of phylib. Once you do, these will go away.

Quoted 1 line

+#define dm_carrier_off(dev) netif_carrier_off(dev)

No wrappers around standard functions. Also, once you use phylib, it will take care of the carrier for you.

drivers/net/ethernet/davicom/dm9051.h line 165

Quoted 6 lines
drivers/net/ethernet/davicom/dm9051.h new file +6 -0
+
+/* xmit support
+ */
+#define	dm_sk_buff_head_init(db)		skb_queue_head_init(&(db)->txq)
+#define	dm_sk_buff_get(db)			skb_dequeue(&(db)->txq)
+#define	dm_sk_buff_set(db, skb)			skb_queue_tail(&(db)->txq, skb)

These wrappers should also be removed.

Quoted 9 lines
drivers/net/ethernet/davicom/dm9051.h new file +9 -0
+/* spi transfers
+ */
+#define ior					std_spi_read_reg			// read reg
+#define iior					disp_spi_read_reg			// read disp
+#define iow					std_spi_write_reg			// write reg
+#define dm9inblk				std_read_rx_buf_ncpy			// read buff
+#define dm9outblk				std_write_tx_buf			// write buf
+
+#define	ncr_reg_reset(db)			iow(db, DM9051_NCR, NCR_RST)		// reset

drivers/net/ethernet/davicom/dm9051.h line 185

Quoted 10 lines
drivers/net/ethernet/davicom/dm9051.h new file +10 -0
+#define	mbd_reg_byte(db)			iow(db, DM9051_MBNDRY, MBNDRY_BYTE)	// MemBound
+#define	fcr_reg_enable(db)			iow(db, DM9051_FCR, FCR_FLOW_ENABLE)	// FlowCtrl
+#define	ppcr_reg_seeting(db)			iow(db, DM9051_PPCR, PPCR_PAUSE_COUNT)	// PauPktCn
+#define	isr_reg_clear_to_stop_mrcmd(db)		iow(db, DM9051_ISR, 0xff)		// ClearISR
+#define rcr_reg_stop(db)			iow(db, DM9051_RCR, RCR_RX_DISABLE)	// DisabRX
+#define imr_reg_stop(db)			iow(db, DM9051_IMR, IMR_PAR)		// DisabAll
+#define rcr_reg_start(db, rcr_all)		iow(db, DM9051_RCR, rcr_all)		// EnabRX
+#define imr_reg_start(db, imr_all)		iow(db, DM9051_IMR, imr_all)		// Re-enab
+#define	intcr_reg_setval(db)			iow(db, DM9051_INTCR, INTCR_POL_LOW)	// INTCR
+#define	ledcr_reg_setting(db, lcr_all)		iow(db, DM9051_LMCR, lcr_all)		// LEDMode1

Please remove all these wrapper.

Andrew