162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (c) 2022 Davicom Semiconductor,Inc. 462306a36Sopenharmony_ci * Davicom DM9051 SPI Fast Ethernet Linux driver 562306a36Sopenharmony_ci */ 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci#ifndef _DM9051_H_ 862306a36Sopenharmony_ci#define _DM9051_H_ 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#include <linux/bits.h> 1162306a36Sopenharmony_ci#include <linux/netdevice.h> 1262306a36Sopenharmony_ci#include <linux/types.h> 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#define DM9051_ID 0x9051 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci#define DM9051_NCR 0x00 1762306a36Sopenharmony_ci#define DM9051_NSR 0x01 1862306a36Sopenharmony_ci#define DM9051_TCR 0x02 1962306a36Sopenharmony_ci#define DM9051_RCR 0x05 2062306a36Sopenharmony_ci#define DM9051_BPTR 0x08 2162306a36Sopenharmony_ci#define DM9051_FCR 0x0A 2262306a36Sopenharmony_ci#define DM9051_EPCR 0x0B 2362306a36Sopenharmony_ci#define DM9051_EPAR 0x0C 2462306a36Sopenharmony_ci#define DM9051_EPDRL 0x0D 2562306a36Sopenharmony_ci#define DM9051_EPDRH 0x0E 2662306a36Sopenharmony_ci#define DM9051_PAR 0x10 2762306a36Sopenharmony_ci#define DM9051_MAR 0x16 2862306a36Sopenharmony_ci#define DM9051_GPCR 0x1E 2962306a36Sopenharmony_ci#define DM9051_GPR 0x1F 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci#define DM9051_VIDL 0x28 3262306a36Sopenharmony_ci#define DM9051_VIDH 0x29 3362306a36Sopenharmony_ci#define DM9051_PIDL 0x2A 3462306a36Sopenharmony_ci#define DM9051_PIDH 0x2B 3562306a36Sopenharmony_ci#define DM9051_SMCR 0x2F 3662306a36Sopenharmony_ci#define DM9051_ATCR 0x30 3762306a36Sopenharmony_ci#define DM9051_SPIBCR 0x38 3862306a36Sopenharmony_ci#define DM9051_INTCR 0x39 3962306a36Sopenharmony_ci#define DM9051_PPCR 0x3D 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci#define DM9051_MPCR 0x55 4262306a36Sopenharmony_ci#define DM9051_LMCR 0x57 4362306a36Sopenharmony_ci#define DM9051_MBNDRY 0x5E 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci#define DM9051_MRRL 0x74 4662306a36Sopenharmony_ci#define DM9051_MRRH 0x75 4762306a36Sopenharmony_ci#define DM9051_MWRL 0x7A 4862306a36Sopenharmony_ci#define DM9051_MWRH 0x7B 4962306a36Sopenharmony_ci#define DM9051_TXPLL 0x7C 5062306a36Sopenharmony_ci#define DM9051_TXPLH 0x7D 5162306a36Sopenharmony_ci#define DM9051_ISR 0x7E 5262306a36Sopenharmony_ci#define DM9051_IMR 0x7F 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ci#define DM_SPI_MRCMDX 0x70 5562306a36Sopenharmony_ci#define DM_SPI_MRCMD 0x72 5662306a36Sopenharmony_ci#define DM_SPI_MWCMD 0x78 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci#define DM_SPI_WR 0x80 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci/* dm9051 Ethernet controller registers bits 6162306a36Sopenharmony_ci */ 6262306a36Sopenharmony_ci/* 0x00 */ 6362306a36Sopenharmony_ci#define NCR_WAKEEN BIT(6) 6462306a36Sopenharmony_ci#define NCR_FDX BIT(3) 6562306a36Sopenharmony_ci#define NCR_RST BIT(0) 6662306a36Sopenharmony_ci/* 0x01 */ 6762306a36Sopenharmony_ci#define NSR_SPEED BIT(7) 6862306a36Sopenharmony_ci#define NSR_LINKST BIT(6) 6962306a36Sopenharmony_ci#define NSR_WAKEST BIT(5) 7062306a36Sopenharmony_ci#define NSR_TX2END BIT(3) 7162306a36Sopenharmony_ci#define NSR_TX1END BIT(2) 7262306a36Sopenharmony_ci/* 0x02 */ 7362306a36Sopenharmony_ci#define TCR_DIS_JABBER_TIMER BIT(6) /* for Jabber Packet support */ 7462306a36Sopenharmony_ci#define TCR_TXREQ BIT(0) 7562306a36Sopenharmony_ci/* 0x05 */ 7662306a36Sopenharmony_ci#define RCR_DIS_WATCHDOG_TIMER BIT(6) /* for Jabber Packet support */ 7762306a36Sopenharmony_ci#define RCR_DIS_LONG BIT(5) 7862306a36Sopenharmony_ci#define RCR_DIS_CRC BIT(4) 7962306a36Sopenharmony_ci#define RCR_ALL BIT(3) 8062306a36Sopenharmony_ci#define RCR_PRMSC BIT(1) 8162306a36Sopenharmony_ci#define RCR_RXEN BIT(0) 8262306a36Sopenharmony_ci#define RCR_RX_DISABLE (RCR_DIS_LONG | RCR_DIS_CRC) 8362306a36Sopenharmony_ci/* 0x06 */ 8462306a36Sopenharmony_ci#define RSR_RF BIT(7) 8562306a36Sopenharmony_ci#define RSR_MF BIT(6) 8662306a36Sopenharmony_ci#define RSR_LCS BIT(5) 8762306a36Sopenharmony_ci#define RSR_RWTO BIT(4) 8862306a36Sopenharmony_ci#define RSR_PLE BIT(3) 8962306a36Sopenharmony_ci#define RSR_AE BIT(2) 9062306a36Sopenharmony_ci#define RSR_CE BIT(1) 9162306a36Sopenharmony_ci#define RSR_FOE BIT(0) 9262306a36Sopenharmony_ci#define RSR_ERR_BITS (RSR_RF | RSR_LCS | RSR_RWTO | RSR_PLE | \ 9362306a36Sopenharmony_ci RSR_AE | RSR_CE | RSR_FOE) 9462306a36Sopenharmony_ci/* 0x0A */ 9562306a36Sopenharmony_ci#define FCR_TXPEN BIT(5) 9662306a36Sopenharmony_ci#define FCR_BKPM BIT(3) 9762306a36Sopenharmony_ci#define FCR_FLCE BIT(0) 9862306a36Sopenharmony_ci#define FCR_RXTX_BITS (FCR_TXPEN | FCR_BKPM | FCR_FLCE) 9962306a36Sopenharmony_ci/* 0x0B */ 10062306a36Sopenharmony_ci#define EPCR_WEP BIT(4) 10162306a36Sopenharmony_ci#define EPCR_EPOS BIT(3) 10262306a36Sopenharmony_ci#define EPCR_ERPRR BIT(2) 10362306a36Sopenharmony_ci#define EPCR_ERPRW BIT(1) 10462306a36Sopenharmony_ci#define EPCR_ERRE BIT(0) 10562306a36Sopenharmony_ci/* 0x1E */ 10662306a36Sopenharmony_ci#define GPCR_GEP_CNTL BIT(0) 10762306a36Sopenharmony_ci/* 0x1F */ 10862306a36Sopenharmony_ci#define GPR_PHY_OFF BIT(0) 10962306a36Sopenharmony_ci/* 0x30 */ 11062306a36Sopenharmony_ci#define ATCR_AUTO_TX BIT(7) 11162306a36Sopenharmony_ci/* 0x39 */ 11262306a36Sopenharmony_ci#define INTCR_POL_LOW (1 << 0) 11362306a36Sopenharmony_ci#define INTCR_POL_HIGH (0 << 0) 11462306a36Sopenharmony_ci/* 0x3D */ 11562306a36Sopenharmony_ci/* Pause Packet Control Register - default = 1 */ 11662306a36Sopenharmony_ci#define PPCR_PAUSE_COUNT 0x08 11762306a36Sopenharmony_ci/* 0x55 */ 11862306a36Sopenharmony_ci#define MPCR_RSTTX BIT(1) 11962306a36Sopenharmony_ci#define MPCR_RSTRX BIT(0) 12062306a36Sopenharmony_ci/* 0x57 */ 12162306a36Sopenharmony_ci/* LEDMode Control Register - LEDMode1 */ 12262306a36Sopenharmony_ci/* Value 0x81 : bit[7] = 1, bit[2] = 0, bit[1:0] = 01b */ 12362306a36Sopenharmony_ci#define LMCR_NEWMOD BIT(7) 12462306a36Sopenharmony_ci#define LMCR_TYPED1 BIT(1) 12562306a36Sopenharmony_ci#define LMCR_TYPED0 BIT(0) 12662306a36Sopenharmony_ci#define LMCR_MODE1 (LMCR_NEWMOD | LMCR_TYPED0) 12762306a36Sopenharmony_ci/* 0x5E */ 12862306a36Sopenharmony_ci#define MBNDRY_BYTE BIT(7) 12962306a36Sopenharmony_ci/* 0xFE */ 13062306a36Sopenharmony_ci#define ISR_MBS BIT(7) 13162306a36Sopenharmony_ci#define ISR_LNKCHG BIT(5) 13262306a36Sopenharmony_ci#define ISR_ROOS BIT(3) 13362306a36Sopenharmony_ci#define ISR_ROS BIT(2) 13462306a36Sopenharmony_ci#define ISR_PTS BIT(1) 13562306a36Sopenharmony_ci#define ISR_PRS BIT(0) 13662306a36Sopenharmony_ci#define ISR_CLR_INT (ISR_LNKCHG | ISR_ROOS | ISR_ROS | \ 13762306a36Sopenharmony_ci ISR_PTS | ISR_PRS) 13862306a36Sopenharmony_ci#define ISR_STOP_MRCMD (ISR_MBS) 13962306a36Sopenharmony_ci/* 0xFF */ 14062306a36Sopenharmony_ci#define IMR_PAR BIT(7) 14162306a36Sopenharmony_ci#define IMR_LNKCHGI BIT(5) 14262306a36Sopenharmony_ci#define IMR_PTM BIT(1) 14362306a36Sopenharmony_ci#define IMR_PRM BIT(0) 14462306a36Sopenharmony_ci 14562306a36Sopenharmony_ci/* Const 14662306a36Sopenharmony_ci */ 14762306a36Sopenharmony_ci#define DM9051_PHY_ADDR 1 /* PHY id */ 14862306a36Sopenharmony_ci#define DM9051_PHY 0x40 /* PHY address 0x01 */ 14962306a36Sopenharmony_ci#define DM9051_PKT_RDY 0x01 /* Packet ready to receive */ 15062306a36Sopenharmony_ci#define DM9051_PKT_MAX 1536 /* Received packet max size */ 15162306a36Sopenharmony_ci#define DM9051_TX_QUE_HI_WATER 50 15262306a36Sopenharmony_ci#define DM9051_TX_QUE_LO_WATER 25 15362306a36Sopenharmony_ci#define DM_EEPROM_MAGIC 0x9051 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_ci#define DM_RXHDR_SIZE sizeof(struct dm9051_rxhdr) 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_cistatic inline struct board_info *to_dm9051_board(struct net_device *ndev) 15862306a36Sopenharmony_ci{ 15962306a36Sopenharmony_ci return netdev_priv(ndev); 16062306a36Sopenharmony_ci} 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ci#endif /* _DM9051_H_ */ 163