162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Northstar Plus switch SerDes/SGMII PHY definitions
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (C) 2018 Florian Fainelli <f.fainelli@gmail.com>
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#include <linux/phy.h>
962306a36Sopenharmony_ci#include <linux/types.h>
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci/* Non-standard page used to access SerDes PHY registers on NorthStar Plus */
1262306a36Sopenharmony_ci#define B53_SERDES_PAGE			0x16
1362306a36Sopenharmony_ci#define B53_SERDES_BLKADDR		0x3e
1462306a36Sopenharmony_ci#define B53_SERDES_LANE			0x3c
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#define B53_SERDES_ID0			0x20
1762306a36Sopenharmony_ci#define  SERDES_ID0_MODEL_MASK		0x3f
1862306a36Sopenharmony_ci#define  SERDES_ID0_REV_NUM_SHIFT	11
1962306a36Sopenharmony_ci#define  SERDES_ID0_REV_NUM_MASK	0x7
2062306a36Sopenharmony_ci#define  SERDES_ID0_REV_LETTER_SHIFT	14
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci#define B53_SERDES_MII_REG(x)		(0x20 + (x) * 2)
2362306a36Sopenharmony_ci#define B53_SERDES_DIGITAL_CONTROL(x)	(0x1e + (x) * 2)
2462306a36Sopenharmony_ci#define B53_SERDES_DIGITAL_STATUS	0x28
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci/* SERDES_DIGITAL_CONTROL1 */
2762306a36Sopenharmony_ci#define  FIBER_MODE_1000X		BIT(0)
2862306a36Sopenharmony_ci#define  TBI_INTERFACE			BIT(1)
2962306a36Sopenharmony_ci#define  SIGNAL_DETECT_EN		BIT(2)
3062306a36Sopenharmony_ci#define  INVERT_SIGNAL_DETECT		BIT(3)
3162306a36Sopenharmony_ci#define  AUTODET_EN			BIT(4)
3262306a36Sopenharmony_ci#define  SGMII_MASTER_MODE		BIT(5)
3362306a36Sopenharmony_ci#define  DISABLE_DLL_PWRDOWN		BIT(6)
3462306a36Sopenharmony_ci#define  CRC_CHECKER_DIS		BIT(7)
3562306a36Sopenharmony_ci#define  COMMA_DET_EN			BIT(8)
3662306a36Sopenharmony_ci#define  ZERO_COMMA_DET_EN		BIT(9)
3762306a36Sopenharmony_ci#define  REMOTE_LOOPBACK		BIT(10)
3862306a36Sopenharmony_ci#define  SEL_RX_PKTS_FOR_CNTR		BIT(11)
3962306a36Sopenharmony_ci#define  MASTER_MDIO_PHY_SEL		BIT(13)
4062306a36Sopenharmony_ci#define  DISABLE_SIGNAL_DETECT_FLT	BIT(14)
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci/* SERDES_DIGITAL_CONTROL2 */
4362306a36Sopenharmony_ci#define  EN_PARALLEL_DET		BIT(0)
4462306a36Sopenharmony_ci#define  DIS_FALSE_LINK			BIT(1)
4562306a36Sopenharmony_ci#define  FLT_FORCE_LINK			BIT(2)
4662306a36Sopenharmony_ci#define  EN_AUTONEG_ERR_TIMER		BIT(3)
4762306a36Sopenharmony_ci#define  DIS_REMOTE_FAULT_SENSING	BIT(4)
4862306a36Sopenharmony_ci#define  FORCE_XMIT_DATA		BIT(5)
4962306a36Sopenharmony_ci#define  AUTONEG_FAST_TIMERS		BIT(6)
5062306a36Sopenharmony_ci#define  DIS_CARRIER_EXTEND		BIT(7)
5162306a36Sopenharmony_ci#define  DIS_TRRR_GENERATION		BIT(8)
5262306a36Sopenharmony_ci#define  BYPASS_PCS_RX			BIT(9)
5362306a36Sopenharmony_ci#define  BYPASS_PCS_TX			BIT(10)
5462306a36Sopenharmony_ci#define  TEST_CNTR_EN			BIT(11)
5562306a36Sopenharmony_ci#define  TX_PACKET_SEQ_TEST		BIT(12)
5662306a36Sopenharmony_ci#define  TX_IDLE_JAM_SEQ_TEST		BIT(13)
5762306a36Sopenharmony_ci#define  CLR_BER_CNTR			BIT(14)
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci/* SERDES_DIGITAL_CONTROL3 */
6062306a36Sopenharmony_ci#define  TX_FIFO_RST			BIT(0)
6162306a36Sopenharmony_ci#define  FIFO_ELAST_TX_RX_SHIFT		1
6262306a36Sopenharmony_ci#define  FIFO_ELAST_TX_RX_5K		0
6362306a36Sopenharmony_ci#define  FIFO_ELAST_TX_RX_10K		1
6462306a36Sopenharmony_ci#define  FIFO_ELAST_TX_RX_13_5K		2
6562306a36Sopenharmony_ci#define  FIFO_ELAST_TX_RX_18_5K		3
6662306a36Sopenharmony_ci#define  BLOCK_TXEN_MODE		BIT(9)
6762306a36Sopenharmony_ci#define  JAM_FALSE_CARRIER_MODE		BIT(10)
6862306a36Sopenharmony_ci#define  EXT_PHY_CRS_MODE		BIT(11)
6962306a36Sopenharmony_ci#define  INVERT_EXT_PHY_CRS		BIT(12)
7062306a36Sopenharmony_ci#define  DISABLE_TX_CRS			BIT(13)
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci/* SERDES_DIGITAL_STATUS */
7362306a36Sopenharmony_ci#define  SGMII_MODE			BIT(0)
7462306a36Sopenharmony_ci#define  LINK_STATUS			BIT(1)
7562306a36Sopenharmony_ci#define  DUPLEX_STATUS			BIT(2)
7662306a36Sopenharmony_ci#define  SPEED_STATUS_SHIFT		3
7762306a36Sopenharmony_ci#define  SPEED_STATUS_10		0
7862306a36Sopenharmony_ci#define  SPEED_STATUS_100		1
7962306a36Sopenharmony_ci#define  SPEED_STATUS_1000		2
8062306a36Sopenharmony_ci#define  SPEED_STATUS_2500		3
8162306a36Sopenharmony_ci#define  SPEED_STATUS_MASK		SPEED_STATUS_2500
8262306a36Sopenharmony_ci#define  PAUSE_RESOLUTION_TX_SIDE	BIT(5)
8362306a36Sopenharmony_ci#define  PAUSE_RESOLUTION_RX_SIDE	BIT(6)
8462306a36Sopenharmony_ci#define  LINK_STATUS_CHANGE		BIT(7)
8562306a36Sopenharmony_ci#define  EARLY_END_EXT_DET		BIT(8)
8662306a36Sopenharmony_ci#define  CARRIER_EXT_ERR_DET		BIT(9)
8762306a36Sopenharmony_ci#define  RX_ERR_DET			BIT(10)
8862306a36Sopenharmony_ci#define  TX_ERR_DET			BIT(11)
8962306a36Sopenharmony_ci#define  CRC_ERR_DET			BIT(12)
9062306a36Sopenharmony_ci#define  FALSE_CARRIER_ERR_DET		BIT(13)
9162306a36Sopenharmony_ci#define  RXFIFO_ERR_DET			BIT(14)
9262306a36Sopenharmony_ci#define  TXFIFO_ERR_DET			BIT(15)
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci/* Block offsets */
9562306a36Sopenharmony_ci#define SERDES_DIGITAL_BLK		0x8300
9662306a36Sopenharmony_ci#define SERDES_ID0			0x8310
9762306a36Sopenharmony_ci#define SERDES_MII_BLK			0xffe0
9862306a36Sopenharmony_ci#define SERDES_XGXSBLK0_BLOCKADDRESS	0xffd0
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_cistruct phylink_link_state;
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_cistatic inline u8 b53_serdes_map_lane(struct b53_device *dev, int port)
10362306a36Sopenharmony_ci{
10462306a36Sopenharmony_ci	if (!dev->ops->serdes_map_lane)
10562306a36Sopenharmony_ci		return B53_INVALID_LANE;
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ci	return dev->ops->serdes_map_lane(dev, port);
10862306a36Sopenharmony_ci}
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_civoid b53_serdes_link_set(struct b53_device *dev, int port, unsigned int mode,
11162306a36Sopenharmony_ci			 phy_interface_t interface, bool link_up);
11262306a36Sopenharmony_cistruct phylink_pcs *b53_serdes_phylink_mac_select_pcs(struct b53_device *dev,
11362306a36Sopenharmony_ci						      int port,
11462306a36Sopenharmony_ci						      phy_interface_t interface);
11562306a36Sopenharmony_civoid b53_serdes_phylink_get_caps(struct b53_device *dev, int port,
11662306a36Sopenharmony_ci				 struct phylink_config *config);
11762306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_B53_SERDES)
11862306a36Sopenharmony_ciint b53_serdes_init(struct b53_device *dev, int port);
11962306a36Sopenharmony_ci#else
12062306a36Sopenharmony_cistatic inline int b53_serdes_init(struct b53_device *dev, int port)
12162306a36Sopenharmony_ci{
12262306a36Sopenharmony_ci	return -ENODEV;
12362306a36Sopenharmony_ci}
12462306a36Sopenharmony_ci#endif
125