ADD DM9051 ETHERNET DRIVER
Subsystems (3)
v15 cover ADD DM9051 ETHERNET DRIVER
DM9051 is a spi interface chip,
need cs/mosi/miso/clock with an interrupt gpio pin
Joseph CHAMG (1):
net: Add dm9051 driver
JosephCHANG (1):
yaml: Add dm9051 SPI network yaml file
.../bindings/net/davicom,dm9051.yaml | 62 + drivers/net/ethernet/davicom/Kconfig | 31 + drivers/net/ethernet/davicom/Makefile | 1 + drivers/net/ethernet/davicom/dm9051.c | 1162 +++++++++++++++++ drivers/net/ethernet/davicom/dm9051.h | 159 +++ 5 files changed, 1415 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
PATCH v15 1/2 yaml: Add dm9051 SPI network yaml file
From: JosephCHANG <[email protected]>
This is a new yaml base data file for configure davicom dm9051 with device tree
--- .../bindings/net/davicom,dm9051.yaml | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/davicom,dm9051.yaml
Documentation/devicetree/bindings/net/davicom,dm9051.yaml new file +62 -0
@@ -0,0 +1,62 @@ +# 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>; + + ethernet@0 { + compatible = "davicom,dm9051"; + reg = <0>; /* spi chip select */ + local-mac-address = [00 00 00 00 00 00]; + interrupt-parent = <&gpio>; + interrupts = <26 IRQ_TYPE_LEVEL_LOW>; + spi-max-frequency = <31200000>; + }; + };
Signature · 1 line
2.20.1
PATCH v15 2/2 net: Add dm9051 driver
In reply to Joseph CHAMGAdd davicom dm9051 spi ethernet driver, The driver work for the device platform which has the spi master
---
Cc: Jakub Kicinski <[email protected]>
Cc: Andrew Lunn <[email protected]>
Cc: Leon Romanovsky <[email protected]>
Cc: andy Shevchenko <[email protected]>
v1-v4
Test ok with raspberry pi 2 and pi 4
v5
swapped to phylib for phy connection tasks
v6
remove the redundant code that phylib has support
v7
read/write registers must return error code to the caller
v8
not parmanently set MAC by .ndo_set_mac_address
v9
improve the registers read/write so that error code return as far as possible up the call stack.
v10
use regmap APIs for SPI and MDIO
v11
use regmap_read_poll_timeout
use corresponding regmap APIs, i.e. SPI, MDIO
v12
use mdiobus API instead of regmap MDIO APIs
v13
Simply all regmap APIs return value checked
Clear the fifo reset report
Eliminate redundant comments
Comment that DM9051_GPR register bit 0 function for power-up the internal phy, if this bit is updated from 1 to 0, then the whole dm9051 chip registers could not be accessed within 1 ms, so that has mdelay(1) to wait 1 ms
v14
To eliminate touching PHY registers, instead take advantage of phy_start to have it
Make neat to be readable exactly
v15
Process the mac address function to be exactly right Re-arrange functions for better style
Handle to auto negotiation to be right procedure
drivers/net/ethernet/davicom/Kconfig | 31 + drivers/net/ethernet/davicom/Makefile | 1 + drivers/net/ethernet/davicom/dm9051.c | 1162 +++++++++++++++++++++++++ drivers/net/ethernet/davicom/dm9051.h | 159 ++++ 4 files changed, 1353 insertions(+) create mode 100644 drivers/net/ethernet/davicom/dm9051.c create mode 100644 drivers/net/ethernet/davicom/dm9051.h
drivers/net/ethernet/davicom/Kconfig +31 -0
@@ -3,6 +3,19 @@ # Davicom device configuration # +config NET_VENDOR_DAVICOM + bool "Davicom devices" + 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 +35,21 @@ 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 MDIO + select PHYLIB + select REGMAP_SPI + 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
@@ -4,3 +4,4 @@ # obj-$(CONFIG_DM9000) += dm9000.o +obj-$(CONFIG_DM9051) += dm9051.o
drivers/net/ethernet/davicom/dm9051.c new file +1162 -0
1,162 lines not on this page · raw message
drivers/net/ethernet/davicom/dm9051.h new file +159 -0
159 lines not on this page · raw message
Signature · 1 line
2.20.1
Jakub Kicinski
maintainerRe: [PATCH v15, 2/2] net: Add dm9051 driver
Quoted 5 lines · On Fri, 28 Jan 2022 14:45:32 +0800 Joseph CHAMG wrote:
drivers/net/ethernet/davicom/dm9051.c new file +5
-0+/* Open network device +* Called when the network device is marked active, such as a user executing +* 'ifconfig up' on the device +*/ +static int dm9051_open (struct net_device *ndev)
drivers/net/ethernet/davicom/dm9051.c line 910
Quoted 10 lines
drivers/net/ethernet/davicom/dm9051.c new file +10
-0+{ +struct board_info *db =to_dm9051_board (ndev); +struct spi_device *spi = db->spidev; +int ret; + + db->imr_all =IMR_PAR |IMR_PRM ; + db->rcr_all =RCR_DIS_LONG |RCR_DIS_CRC |RCR_RXEN ; + db->lcr_all =LMCR_MODE1 ; + +netif_wake_queue (ndev);
This should be last, after the device is actually ready to transmit.
Quoted 33 lines
drivers/net/ethernet/davicom/dm9051.c new file +33
-0+ ndev->irq = spi->irq;/* by dts */ + ret =request_threaded_irq (spi->irq,NULL , dm9051_rx_threaded_irq, +IRQF_TRIGGER_LOW |IRQF_ONESHOT , + ndev->name, db); +if (ret <0 ) { +netdev_err (ndev,"failed to get irq\n" ); +return ret; + } + +phy_support_sym_pause (db->phydev);/* Enable support of sym pause */ +phy_start (db->phydev);/* it enclose with mutex_lock/mutex_unlock */ + + ret =dm9051_all_start (db); +if (ret) { +phy_stop (db->phydev); +free_irq (spi->irq, db); +netif_stop_queue (ndev); +return ret; + } + +/* init pause param FlowCtrl */ + db->eth_pause.rx_pause = true; + db->eth_pause.tx_pause = true; + db->eth_pause.autoneg =AUTONEG_DISABLE ; + +if (db->phydev->autoneg) + db->eth_pause.autoneg =AUTONEG_ENABLE ; + +return 0 ; +} + +/* Close network device +* Called to close down a network device which has been active. Cancel any
drivers/net/ethernet/davicom/dm9051.c line 954
Quoted 10 lines
drivers/net/ethernet/davicom/dm9051.c new file +10
-0+* work, shutdown the RX and TX process and then place the chip into a low +* power state while it is not being used +*/ +static int dm9051_stop (struct net_device *ndev) +{ +struct board_info *db =to_dm9051_board (ndev); + +phy_stop (db->phydev); +free_irq (db->spidev->irq, db); +netif_stop_queue (ndev);
I don't see anything draining &db->txq when the worker is stopped. It should probably be drained here, after the queue is stopped.
Quoted 2 lines
drivers/net/ethernet/davicom/dm9051.c new file +2
-0+return dm9051_all_stop (db); +}