ADD DM9051 ETHERNET DRIVER
Subsystems (3)
v5 cover ADD DM9051 ETHERNET DRIVER
Adjust Kconfig for reasonable dependence, make dm9051.c better by remove the wrappers, and swap to phylib
DM9051 is a spi interface chip,
need only cs/mosi/miso/clock with an interrupt gpio pin
JosephCHANG (2):
yaml: Add dm9051 SPI network yaml file
net: Add dm9051 driver
.../bindings/net/davicom,dm9051.yaml | 62 ++ drivers/net/ethernet/davicom/Kconfig | 30 + drivers/net/ethernet/davicom/Makefile | 1 + drivers/net/ethernet/davicom/dm9051.c | 913 ++++++++++++++++++ drivers/net/ethernet/davicom/dm9051.h | 187 ++++ 5 files changed, 1193 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 v5 1/2 yaml: Add dm9051 SPI network yaml file
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
Rob Herring
maintainerRe: [PATCH v5, 1/2] yaml: Add dm9051 SPI network yaml file
Quoted 9 lines · JosephCHANG
This is a new yaml base data file for configure davicom dm9051 with device tree
Signed-off-by JosephCHANG <[email protected]>--- .../bindings/net/davicom,dm9051.yaml | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/davicom,dm9051.yaml
Please add Acked-by/Reviewed-by tags when posting new versions. However, there's no need to repost patches *only* to add the tags. The upstream maintainer will do that for acks received on the version they apply.
If a tag was not added on purpose, please state why and what changed.
Jakub Kicinski
maintainerRe: [PATCH v5, 1/2] yaml: Add dm9051 SPI network yaml file
Quoted 11 lines · On Wed, 15 Dec 2021 09:51:16 -0600 Rob Herring wrote:
Quoted 4 lines · JosephCHANG
This is a new yaml base data file for configure davicom dm9051 with device tree
Signed-off-by JosephCHANG <[email protected]>Please add Acked-by/Reviewed-by tags when posting new versions. However, there's no need to repost patches *only* to add the tags. The upstream maintainer will do that for acks received on the version they apply.
If a tag was not added on purpose, please state why and what changed.
And general changelog would be useful, what changed between v4 and v5? Again, no need to create v6 just for that, you can reply with the change log and include it with next versions if there are any.
PATCH v5 2/2 net: Add dm9051 driver
In reply to JosephCHANGAdd davicom dm9051 spi ethernet driver, The driver work with the device platform's spi master.
Work to eliminate the wrappers to be clear for read, swapped to phylib for phy connection tasks.
Tested with raspberry pi 4. Test for netwroking function, CAT5 cable unplug/plug and also ethtool detect for link state, and all are ok.
--- drivers/net/ethernet/davicom/Kconfig | 30 + drivers/net/ethernet/davicom/Makefile | 1 + drivers/net/ethernet/davicom/dm9051.c | 913 ++++++++++++++++++++++++++ drivers/net/ethernet/davicom/dm9051.h | 187 ++++++ 4 files changed, 1131 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
@@ -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,20 @@ 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" + select PHYLIB + 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
@@ -4,3 +4,4 @@ # obj-$(CONFIG_DM9000) += dm9000.o +obj-$(CONFIG_DM9051) += dm9051.o
drivers/net/ethernet/davicom/dm9051.c new file +913 -0
913 lines not on this page · raw message
drivers/net/ethernet/davicom/dm9051.h new file +187 -0
187 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [PATCH v5, 2/2] net: Add dm9051 driver
Quoted 1 line
+static u8
ior(struct board_info *db, unsigned int reg)
Can we have some meaningful names please. And don't forget namespace prefix, ideally dm9051_
drivers/net/ethernet/davicom/dm9051.c line 64
Quoted 9 lines
drivers/net/ethernet/davicom/dm9051.c new file +9
-0+{ +u8 rxb[1 ]; + +dm9051_xfer (db,DM_SPI_RD | reg,NULL , rxb,1 ); +return rxb[0 ]; +} + +/* chip ID display */ +static u8 iior (struct device *dev,struct board_info *db,unsigned int reg)
What does the extra i mean?
drivers/net/ethernet/davicom/dm9051.c line 72
Quoted 8 lines
drivers/net/ethernet/davicom/dm9051.c new file +8
-0+{ +u8 rxdata; + + rxdata =ior (db, reg); +if (reg ==DM9051_PIDL || reg ==DM9051_PIDH ) +dev_dbg (dev,"dm905.MOSI [%02x][..]\n" , reg); +if (reg ==DM9051_PIDL || reg ==DM9051_PIDH ) +dev_info (dev,"dm905.MISO [..][%02x]\n" , rxdata);
At appears to be the same condition for both? Is that wrong, or can they be combined?
drivers/net/ethernet/davicom/dm9051.c line 84
Quoted 12 lines
drivers/net/ethernet/davicom/dm9051.c new file +12
-0+return rxdata; +} + +static void iow (struct board_info *db,unsigned int reg,unsigned int val) +{ +u8 txb[1 ]; + + txb[0 ] = val; +dm9051_xfer (db,DM_SPI_WR | reg, txb,NULL ,1 ); +} + +static void dm9inblk (struct board_info *db,u8 *buff,unsigned int len)
Please make your namespace prefix uniform. I would suggest dm9051_.
drivers/net/ethernet/davicom/dm9051.c line 107
Quoted 9 lines
drivers/net/ethernet/davicom/dm9051.c new file +9
-0+static int dm_phy_read_func (struct board_info *db,int reg) +{ +int ret; +u8 check_val; + +iow (db,DM9051_EPAR ,DM9051_PHY | reg); +iow (db,DM9051_EPCR ,EPCR_ERPRR |EPCR_EPOS ); +read_poll_timeout (ior, check_val, !(check_val &EPCR_ERRE ),100 ,10000 , + true, db,DM9051_EPCR );
read_poll_timeout() return an error code. Don't ignore it.
drivers/net/ethernet/davicom/dm9051.c line 113
Quoted 6 lines
drivers/net/ethernet/davicom/dm9051.c new file +6
-0+iow (db,DM9051_EPCR ,0x0 ); + ret = (ior (db,DM9051_EPDRH ) <<8 ) |ior (db,DM9051_EPDRL ); +return ret; +} + +static void dm_phy_write_func (struct board_info *db,int reg,int value)
The _func does not add anything useful. Please remove them all.
Quoted 11 lines
drivers/net/ethernet/davicom/dm9051.c new file +11
-0+{ +u8 check_val; + +iow (db,DM9051_EPAR ,DM9051_PHY | reg); +iow (db,DM9051_EPDRL , value); +iow (db,DM9051_EPDRH , value >>8 ); +iow (db,DM9051_EPCR ,EPCR_EPOS |EPCR_ERPRW ); +read_poll_timeout (ior, check_val, !(check_val &EPCR_ERRE ),100 ,10000 , + true, db,DM9051_EPCR ); +iow (db,DM9051_EPCR ,0x0 ); +}
drivers/net/ethernet/davicom/dm9051.c line 167
Quoted 10 lines
drivers/net/ethernet/davicom/dm9051.c new file +9
-0+ +static int dm9051_mdio_read (struct mii_bus *mdiobus,int phy_id_unused,int reg) +{ +struct board_info *db = mdiobus->priv; +int val; + +mutex_lock (&db->addr_lock); + val =dm_phy_read_func (db, reg); +mutex_unlock (&db->addr_lock);
When you register the mdiobus, the MDIO core will probe all 32 addresses on the bus. It looks like you PHY is on address 1. You should return 0xffff for all addresses other than 1.
drivers/net/ethernet/davicom/dm9051.c line 178
Quoted 11 lines
drivers/net/ethernet/davicom/dm9051.c new file +11
-0+ +return val; +} + +static int dm9051_mdio_write (struct mii_bus *mdiobus,int phy_id_unused,int reg,u16 val) +{ +struct board_info *db = mdiobus->priv; + +mutex_lock (&db->addr_lock); +dm_phy_write_func (db, reg, val); +mutex_unlock (&db->addr_lock);
And here you should return -ENODEV for any address other than 1.
drivers/net/ethernet/davicom/dm9051.c line 216
Quoted 5 lines
drivers/net/ethernet/davicom/dm9051.c new file +5
-0+static void dm9051_fifo_reset (struct board_info *db) +{ + db->bc.DO_FIFO_RST_counter++; +dm_phy_write_func (db,MII_ADVERTISE ,ADVERTISE_PAUSE_CAP | +ADVERTISE_ALL |ADVERTISE_CSMA );/* for fcr, essential */
The MAC driver should not be accessing the PHY registers. That is the PHY drivers job.
drivers/net/ethernet/davicom/dm9051.c line 222
Quoted 6 lines
drivers/net/ethernet/davicom/dm9051.c new file +6
-0+iow (db,DM9051_FCR ,FCR_FLOW_ENABLE );/* FlowCtrl */ +iow (db,DM9051_PPCR ,PPCR_PAUSE_COUNT );/* Pause Pkt Count */ +iow (db,DM9051_LMCR , db->lcr_all);/* LEDMode1 */ +iow (db,DM9051_INTCR ,INTCR_POL_LOW );/* INTCR */ +} +