xref: /openbmc/linux/drivers/net/dsa/microchip/ksz_common.h (revision c570f861fa059ea653599415a7c8cc1dfaf16763)
1b31141d3SNishad Kamdar /* SPDX-License-Identifier: GPL-2.0 */
2b31141d3SNishad Kamdar /* Microchip switch driver common header
3c2e86691STristram Ha  *
47c6ff470STristram Ha  * Copyright (C) 2017-2019 Microchip Technology Inc.
5c2e86691STristram Ha  */
6c2e86691STristram Ha 
7c2e86691STristram Ha #ifndef __KSZ_COMMON_H
8c2e86691STristram Ha #define __KSZ_COMMON_H
9c2e86691STristram Ha 
106a7abc61SMarek Vasut #include <linux/etherdevice.h>
116a7abc61SMarek Vasut #include <linux/kernel.h>
126a7abc61SMarek Vasut #include <linux/mutex.h>
136a7abc61SMarek Vasut #include <linux/phy.h>
14ee394feaSMarek Vasut #include <linux/regmap.h>
156a7abc61SMarek Vasut #include <net/dsa.h>
16c9cd961cSArun Ramadoss #include <linux/irq.h>
176a7abc61SMarek Vasut 
18eac1ea20SChristian Eggers #include "ksz_ptp.h"
19eac1ea20SChristian Eggers 
2065ac79e1SArun Ramadoss #define KSZ_MAX_NUM_PORTS 8
2165ac79e1SArun Ramadoss 
22f3c16545SArun Ramadoss struct ksz_device;
23cc13ab18SArun Ramadoss struct ksz_port;
24f3c16545SArun Ramadoss 
256a7abc61SMarek Vasut struct vlan_table {
266a7abc61SMarek Vasut 	u32 table[3];
276a7abc61SMarek Vasut };
286a7abc61SMarek Vasut 
296a7abc61SMarek Vasut struct ksz_port_mib {
306a7abc61SMarek Vasut 	struct mutex cnt_mutex;		/* structure access */
316a7abc61SMarek Vasut 	u8 cnt_ptr;
326a7abc61SMarek Vasut 	u64 *counters;
33a7f4f13aSOleksij Rempel 	struct rtnl_link_stats64 stats64;
34c4748ff6SOleksij Rempel 	struct ethtool_pause_stats pause_stats;
35a7f4f13aSOleksij Rempel 	struct spinlock stats64_lock;
366a7abc61SMarek Vasut };
376a7abc61SMarek Vasut 
38a530e6f2SArun Ramadoss struct ksz_mib_names {
39a530e6f2SArun Ramadoss 	int index;
40a530e6f2SArun Ramadoss 	char string[ETH_GSTRING_LEN];
41a530e6f2SArun Ramadoss };
42a530e6f2SArun Ramadoss 
43462d5250SArun Ramadoss struct ksz_chip_data {
44462d5250SArun Ramadoss 	u32 chip_id;
45462d5250SArun Ramadoss 	const char *dev_name;
46462d5250SArun Ramadoss 	int num_vlans;
47462d5250SArun Ramadoss 	int num_alus;
48462d5250SArun Ramadoss 	int num_statics;
49462d5250SArun Ramadoss 	int cpu_ports;
50462d5250SArun Ramadoss 	int port_cnt;
51978f1f72SArun Ramadoss 	u8 port_nirqs;
52e30f33a5SArun Ramadoss 	u8 num_tx_queues;
5371d7920fSArun Ramadoss 	bool tc_cbs_supported;
54*c570f861SOleksij Rempel 	bool tc_ets_supported;
556ec23aaaSArun Ramadoss 	const struct ksz_dev_ops *ops;
56462d5250SArun Ramadoss 	bool phy_errata_9477;
57462d5250SArun Ramadoss 	bool ksz87xx_eee_link_erratum;
58a530e6f2SArun Ramadoss 	const struct ksz_mib_names *mib_names;
59a530e6f2SArun Ramadoss 	int mib_cnt;
60a530e6f2SArun Ramadoss 	u8 reg_mib_cnt;
61a02579dfSArun Ramadoss 	const u16 *regs;
62d23a5e18SArun Ramadoss 	const u32 *masks;
6334e48383SArun Ramadoss 	const u8 *shifts;
64aa5b8b73SArun Ramadoss 	const u8 *xmii_ctrl0;
6546f80fa8SArun Ramadoss 	const u8 *xmii_ctrl1;
66e593df51SArun Ramadoss 	int stp_ctrl_reg;
671ca6437fSArun Ramadoss 	int broadcast_ctrl_reg;
680abab9f3SArun Ramadoss 	int multicast_ctrl_reg;
69ad08ac18SArun Ramadoss 	int start_ctrl_reg;
7065ac79e1SArun Ramadoss 	bool supports_mii[KSZ_MAX_NUM_PORTS];
7165ac79e1SArun Ramadoss 	bool supports_rmii[KSZ_MAX_NUM_PORTS];
7265ac79e1SArun Ramadoss 	bool supports_rgmii[KSZ_MAX_NUM_PORTS];
7365ac79e1SArun Ramadoss 	bool internal_phy[KSZ_MAX_NUM_PORTS];
74505bf320SOleksij Rempel 	bool gbit_capable[KSZ_MAX_NUM_PORTS];
75ec6ba50cSOleksij Rempel 	const struct regmap_access_table *wr_table;
76ec6ba50cSOleksij Rempel 	const struct regmap_access_table *rd_table;
77462d5250SArun Ramadoss };
78462d5250SArun Ramadoss 
79c9cd961cSArun Ramadoss struct ksz_irq {
80c9cd961cSArun Ramadoss 	u16 masked;
81e1add7ddSArun Ramadoss 	u16 reg_mask;
82e1add7ddSArun Ramadoss 	u16 reg_status;
83c9cd961cSArun Ramadoss 	struct irq_domain *domain;
84c9cd961cSArun Ramadoss 	int nirqs;
85e1add7ddSArun Ramadoss 	int irq_num;
86c9cd961cSArun Ramadoss 	char name[16];
87e1add7ddSArun Ramadoss 	struct ksz_device *dev;
88c9cd961cSArun Ramadoss };
89c9cd961cSArun Ramadoss 
90cc13ab18SArun Ramadoss struct ksz_ptp_irq {
91cc13ab18SArun Ramadoss 	struct ksz_port *port;
92cc13ab18SArun Ramadoss 	u16 ts_reg;
93ab32f56aSChristian Eggers 	bool ts_en;
94cc13ab18SArun Ramadoss 	char name[16];
95cc13ab18SArun Ramadoss 	int num;
96cc13ab18SArun Ramadoss };
97cc13ab18SArun Ramadoss 
986a7abc61SMarek Vasut struct ksz_port {
998f4f58f8SBen Hutchings 	bool remove_tag;		/* Remove Tag flag set, for ksz8795 only */
10015f7cfaeSVladimir Oltean 	bool learning;
1016a7abc61SMarek Vasut 	int stp_state;
1026a7abc61SMarek Vasut 	struct phy_device phydev;
1036a7abc61SMarek Vasut 
1046a7abc61SMarek Vasut 	u32 on:1;			/* port is not disabled by hardware */
1056a7abc61SMarek Vasut 	u32 fiber:1;			/* port is fiber */
1066a7abc61SMarek Vasut 	u32 force:1;
1076a7abc61SMarek Vasut 	u32 read:1;			/* read MIB counters in background */
1086a7abc61SMarek Vasut 	u32 freeze:1;			/* MIB counter freeze is enabled */
1096a7abc61SMarek Vasut 
1106a7abc61SMarek Vasut 	struct ksz_port_mib mib;
111edecfa98SHelmut Grohne 	phy_interface_t interface;
112b19ac41fSArun Ramadoss 	u32 rgmii_tx_val;
113b19ac41fSArun Ramadoss 	u32 rgmii_rx_val;
114f3c16545SArun Ramadoss 	struct ksz_device *ksz_dev;
115c9cd961cSArun Ramadoss 	struct ksz_irq pirq;
116f3c16545SArun Ramadoss 	u8 num;
117c59e12a1SChristian Eggers #if IS_ENABLED(CONFIG_NET_DSA_MICROCHIP_KSZ_PTP)
118c59e12a1SChristian Eggers 	struct hwtstamp_config tstamp_config;
119c2977c61SArun Ramadoss 	bool hwts_tx_en;
120c2977c61SArun Ramadoss 	bool hwts_rx_en;
121cc13ab18SArun Ramadoss 	struct ksz_irq ptpirq;
122cc13ab18SArun Ramadoss 	struct ksz_ptp_irq ptpmsg_irq[3];
123ab32f56aSChristian Eggers 	ktime_t tstamp_msg;
124ab32f56aSChristian Eggers 	struct completion tstamp_msg_comp;
125c59e12a1SChristian Eggers #endif
1266a7abc61SMarek Vasut };
1276a7abc61SMarek Vasut 
1286a7abc61SMarek Vasut struct ksz_device {
1296a7abc61SMarek Vasut 	struct dsa_switch *ds;
1306a7abc61SMarek Vasut 	struct ksz_platform_data *pdata;
131462d5250SArun Ramadoss 	const struct ksz_chip_data *info;
1326a7abc61SMarek Vasut 
1336a7abc61SMarek Vasut 	struct mutex dev_mutex;		/* device access */
134013572a2SMarek Vasut 	struct mutex regmap_mutex;	/* regmap access */
1356a7abc61SMarek Vasut 	struct mutex alu_mutex;		/* ALU access */
1366a7abc61SMarek Vasut 	struct mutex vlan_mutex;	/* vlan access */
1376a7abc61SMarek Vasut 	const struct ksz_dev_ops *dev_ops;
1386a7abc61SMarek Vasut 
1396a7abc61SMarek Vasut 	struct device *dev;
1406a7abc61SMarek Vasut 	struct regmap *regmap[3];
1416a7abc61SMarek Vasut 
1426a7abc61SMarek Vasut 	void *priv;
143c9cd961cSArun Ramadoss 	int irq;
1446a7abc61SMarek Vasut 
1456a7abc61SMarek Vasut 	struct gpio_desc *reset_gpio;	/* Optional reset GPIO */
1466a7abc61SMarek Vasut 
1476a7abc61SMarek Vasut 	/* chip specific data */
1486a7abc61SMarek Vasut 	u32 chip_id;
14991a98917SArun Ramadoss 	u8 chip_rev;
1506a7abc61SMarek Vasut 	int cpu_port;			/* port connected to CPU */
1516a7abc61SMarek Vasut 	int phy_port_cnt;
152edecfa98SHelmut Grohne 	phy_interface_t compat_interface;
1536a7abc61SMarek Vasut 	bool synclko_125;
15448bf8b8aSRobert Hancock 	bool synclko_disable;
1556a7abc61SMarek Vasut 
1566a7abc61SMarek Vasut 	struct vlan_table *vlan_cache;
1576a7abc61SMarek Vasut 
1586a7abc61SMarek Vasut 	struct ksz_port *ports;
159469b390eSGeorge McCollister 	struct delayed_work mib_read;
1606a7abc61SMarek Vasut 	unsigned long mib_read_interval;
1616a7abc61SMarek Vasut 	u16 mirror_rx;
1626a7abc61SMarek Vasut 	u16 mirror_tx;
1636a7abc61SMarek Vasut 	u16 port_mask;
164c9cd961cSArun Ramadoss 	struct mutex lock_irq;		/* IRQ Access */
165c9cd961cSArun Ramadoss 	struct ksz_irq girq;
166eac1ea20SChristian Eggers 	struct ksz_ptp_data ptp_data;
1676a7abc61SMarek Vasut };
1686a7abc61SMarek Vasut 
169462d5250SArun Ramadoss /* List of supported models */
170462d5250SArun Ramadoss enum ksz_model {
171b4490809SOleksij Rempel 	KSZ8563,
172462d5250SArun Ramadoss 	KSZ8795,
173462d5250SArun Ramadoss 	KSZ8794,
174462d5250SArun Ramadoss 	KSZ8765,
175462d5250SArun Ramadoss 	KSZ8830,
176462d5250SArun Ramadoss 	KSZ9477,
1772eb3ff3cSRomain Naour 	KSZ9896,
178462d5250SArun Ramadoss 	KSZ9897,
179462d5250SArun Ramadoss 	KSZ9893,
180ef912fe4SRakesh Sankaranarayanan 	KSZ9563,
181462d5250SArun Ramadoss 	KSZ9567,
182462d5250SArun Ramadoss 	LAN9370,
183462d5250SArun Ramadoss 	LAN9371,
184462d5250SArun Ramadoss 	LAN9372,
185462d5250SArun Ramadoss 	LAN9373,
186462d5250SArun Ramadoss 	LAN9374,
187462d5250SArun Ramadoss };
188462d5250SArun Ramadoss 
189462d5250SArun Ramadoss enum ksz_chip_id {
190b4490809SOleksij Rempel 	KSZ8563_CHIP_ID = 0x8563,
191462d5250SArun Ramadoss 	KSZ8795_CHIP_ID = 0x8795,
192462d5250SArun Ramadoss 	KSZ8794_CHIP_ID = 0x8794,
193462d5250SArun Ramadoss 	KSZ8765_CHIP_ID = 0x8765,
194462d5250SArun Ramadoss 	KSZ8830_CHIP_ID = 0x8830,
195462d5250SArun Ramadoss 	KSZ9477_CHIP_ID = 0x00947700,
1962eb3ff3cSRomain Naour 	KSZ9896_CHIP_ID = 0x00989600,
197462d5250SArun Ramadoss 	KSZ9897_CHIP_ID = 0x00989700,
198462d5250SArun Ramadoss 	KSZ9893_CHIP_ID = 0x00989300,
199ef912fe4SRakesh Sankaranarayanan 	KSZ9563_CHIP_ID = 0x00956300,
200462d5250SArun Ramadoss 	KSZ9567_CHIP_ID = 0x00956700,
201462d5250SArun Ramadoss 	LAN9370_CHIP_ID = 0x00937000,
202462d5250SArun Ramadoss 	LAN9371_CHIP_ID = 0x00937100,
203462d5250SArun Ramadoss 	LAN9372_CHIP_ID = 0x00937200,
204462d5250SArun Ramadoss 	LAN9373_CHIP_ID = 0x00937300,
205462d5250SArun Ramadoss 	LAN9374_CHIP_ID = 0x00937400,
206462d5250SArun Ramadoss };
207462d5250SArun Ramadoss 
208486f9ca7SArun Ramadoss enum ksz_regs {
209486f9ca7SArun Ramadoss 	REG_IND_CTRL_0,
210486f9ca7SArun Ramadoss 	REG_IND_DATA_8,
211486f9ca7SArun Ramadoss 	REG_IND_DATA_CHECK,
212486f9ca7SArun Ramadoss 	REG_IND_DATA_HI,
213486f9ca7SArun Ramadoss 	REG_IND_DATA_LO,
214486f9ca7SArun Ramadoss 	REG_IND_MIB_CHECK,
215486f9ca7SArun Ramadoss 	REG_IND_BYTE,
216486f9ca7SArun Ramadoss 	P_FORCE_CTRL,
217486f9ca7SArun Ramadoss 	P_LINK_STATUS,
218486f9ca7SArun Ramadoss 	P_LOCAL_CTRL,
219486f9ca7SArun Ramadoss 	P_NEG_RESTART_CTRL,
220486f9ca7SArun Ramadoss 	P_REMOTE_STATUS,
221486f9ca7SArun Ramadoss 	P_SPEED_STATUS,
222486f9ca7SArun Ramadoss 	S_TAIL_TAG_CTRL,
2236877102fSArun Ramadoss 	P_STP_CTRL,
2249d95329cSArun Ramadoss 	S_START_CTRL,
2259d95329cSArun Ramadoss 	S_BROADCAST_CTRL,
2269d95329cSArun Ramadoss 	S_MULTICAST_CTRL,
227aa5b8b73SArun Ramadoss 	P_XMII_CTRL_0,
22846f80fa8SArun Ramadoss 	P_XMII_CTRL_1,
229486f9ca7SArun Ramadoss };
230486f9ca7SArun Ramadoss 
231d23a5e18SArun Ramadoss enum ksz_masks {
232d23a5e18SArun Ramadoss 	PORT_802_1P_REMAPPING,
233d23a5e18SArun Ramadoss 	SW_TAIL_TAG_ENABLE,
234d23a5e18SArun Ramadoss 	MIB_COUNTER_OVERFLOW,
235d23a5e18SArun Ramadoss 	MIB_COUNTER_VALID,
236d23a5e18SArun Ramadoss 	VLAN_TABLE_FID,
237d23a5e18SArun Ramadoss 	VLAN_TABLE_MEMBERSHIP,
238d23a5e18SArun Ramadoss 	VLAN_TABLE_VALID,
239d23a5e18SArun Ramadoss 	STATIC_MAC_TABLE_VALID,
240d23a5e18SArun Ramadoss 	STATIC_MAC_TABLE_USE_FID,
241d23a5e18SArun Ramadoss 	STATIC_MAC_TABLE_FID,
242d23a5e18SArun Ramadoss 	STATIC_MAC_TABLE_OVERRIDE,
243d23a5e18SArun Ramadoss 	STATIC_MAC_TABLE_FWD_PORTS,
244d23a5e18SArun Ramadoss 	DYNAMIC_MAC_TABLE_ENTRIES_H,
245d23a5e18SArun Ramadoss 	DYNAMIC_MAC_TABLE_MAC_EMPTY,
246d23a5e18SArun Ramadoss 	DYNAMIC_MAC_TABLE_NOT_READY,
247d23a5e18SArun Ramadoss 	DYNAMIC_MAC_TABLE_ENTRIES,
248d23a5e18SArun Ramadoss 	DYNAMIC_MAC_TABLE_FID,
249d23a5e18SArun Ramadoss 	DYNAMIC_MAC_TABLE_SRC_PORT,
250d23a5e18SArun Ramadoss 	DYNAMIC_MAC_TABLE_TIMESTAMP,
251457c182aSArun Ramadoss 	ALU_STAT_WRITE,
252457c182aSArun Ramadoss 	ALU_STAT_READ,
2538560664fSArun Ramadoss 	P_MII_TX_FLOW_CTRL,
2548560664fSArun Ramadoss 	P_MII_RX_FLOW_CTRL,
255d23a5e18SArun Ramadoss };
256d23a5e18SArun Ramadoss 
25734e48383SArun Ramadoss enum ksz_shifts {
25834e48383SArun Ramadoss 	VLAN_TABLE_MEMBERSHIP_S,
25934e48383SArun Ramadoss 	VLAN_TABLE,
26034e48383SArun Ramadoss 	STATIC_MAC_FWD_PORTS,
26134e48383SArun Ramadoss 	STATIC_MAC_FID,
26234e48383SArun Ramadoss 	DYNAMIC_MAC_ENTRIES_H,
26334e48383SArun Ramadoss 	DYNAMIC_MAC_ENTRIES,
26434e48383SArun Ramadoss 	DYNAMIC_MAC_FID,
26534e48383SArun Ramadoss 	DYNAMIC_MAC_TIMESTAMP,
26634e48383SArun Ramadoss 	DYNAMIC_MAC_SRC_PORT,
267457c182aSArun Ramadoss 	ALU_STAT_INDEX,
26834e48383SArun Ramadoss };
26934e48383SArun Ramadoss 
270aa5b8b73SArun Ramadoss enum ksz_xmii_ctrl0 {
271aa5b8b73SArun Ramadoss 	P_MII_100MBIT,
272aa5b8b73SArun Ramadoss 	P_MII_10MBIT,
2738560664fSArun Ramadoss 	P_MII_FULL_DUPLEX,
2748560664fSArun Ramadoss 	P_MII_HALF_DUPLEX,
275aa5b8b73SArun Ramadoss };
276aa5b8b73SArun Ramadoss 
27746f80fa8SArun Ramadoss enum ksz_xmii_ctrl1 {
278dc1c596eSArun Ramadoss 	P_RGMII_SEL,
279dc1c596eSArun Ramadoss 	P_RMII_SEL,
280dc1c596eSArun Ramadoss 	P_GMII_SEL,
281dc1c596eSArun Ramadoss 	P_MII_SEL,
28246f80fa8SArun Ramadoss 	P_GMII_1GBIT,
28346f80fa8SArun Ramadoss 	P_GMII_NOT_1GBIT,
28446f80fa8SArun Ramadoss };
28546f80fa8SArun Ramadoss 
2866a7abc61SMarek Vasut struct alu_struct {
2876a7abc61SMarek Vasut 	/* entry 1 */
2886a7abc61SMarek Vasut 	u8	is_static:1;
2896a7abc61SMarek Vasut 	u8	is_src_filter:1;
2906a7abc61SMarek Vasut 	u8	is_dst_filter:1;
2916a7abc61SMarek Vasut 	u8	prio_age:3;
2926a7abc61SMarek Vasut 	u32	_reserv_0_1:23;
2936a7abc61SMarek Vasut 	u8	mstp:3;
2946a7abc61SMarek Vasut 	/* entry 2 */
2956a7abc61SMarek Vasut 	u8	is_override:1;
2966a7abc61SMarek Vasut 	u8	is_use_fid:1;
2976a7abc61SMarek Vasut 	u32	_reserv_1_1:23;
2986a7abc61SMarek Vasut 	u8	port_forward:7;
2996a7abc61SMarek Vasut 	/* entry 3 & 4*/
3006a7abc61SMarek Vasut 	u32	_reserv_2_1:9;
3016a7abc61SMarek Vasut 	u8	fid:7;
3026a7abc61SMarek Vasut 	u8	mac[ETH_ALEN];
3036a7abc61SMarek Vasut };
3046a7abc61SMarek Vasut 
3056a7abc61SMarek Vasut struct ksz_dev_ops {
306d2822e68SArun Ramadoss 	int (*setup)(struct dsa_switch *ds);
307c9cd961cSArun Ramadoss 	void (*teardown)(struct dsa_switch *ds);
3086a7abc61SMarek Vasut 	u32 (*get_port_addr)(int port, int offset);
3096a7abc61SMarek Vasut 	void (*cfg_port_member)(struct ksz_device *dev, int port, u8 member);
3106a7abc61SMarek Vasut 	void (*flush_dyn_mac_table)(struct ksz_device *dev, int port);
3116a7abc61SMarek Vasut 	void (*port_cleanup)(struct ksz_device *dev, int port);
3126a7abc61SMarek Vasut 	void (*port_setup)(struct ksz_device *dev, int port, bool cpu_port);
3132c119d99SArun Ramadoss 	int (*set_ageing_time)(struct ksz_device *dev, unsigned int msecs);
3148f420456SOleksij Rempel 	int (*r_phy)(struct ksz_device *dev, u16 phy, u16 reg, u16 *val);
3158f420456SOleksij Rempel 	int (*w_phy)(struct ksz_device *dev, u16 phy, u16 reg, u16 val);
3166a7abc61SMarek Vasut 	void (*r_mib_cnt)(struct ksz_device *dev, int port, u16 addr,
3176a7abc61SMarek Vasut 			  u64 *cnt);
3186a7abc61SMarek Vasut 	void (*r_mib_pkt)(struct ksz_device *dev, int port, u16 addr,
3196a7abc61SMarek Vasut 			  u64 *dropped, u64 *cnt);
320a7f4f13aSOleksij Rempel 	void (*r_mib_stat64)(struct ksz_device *dev, int port);
321f0d997e3SArun Ramadoss 	int  (*vlan_filtering)(struct ksz_device *dev, int port,
322f0d997e3SArun Ramadoss 			       bool flag, struct netlink_ext_ack *extack);
323f0d997e3SArun Ramadoss 	int  (*vlan_add)(struct ksz_device *dev, int port,
324f0d997e3SArun Ramadoss 			 const struct switchdev_obj_port_vlan *vlan,
325f0d997e3SArun Ramadoss 			 struct netlink_ext_ack *extack);
326f0d997e3SArun Ramadoss 	int  (*vlan_del)(struct ksz_device *dev, int port,
327f0d997e3SArun Ramadoss 			 const struct switchdev_obj_port_vlan *vlan);
32800a298bbSArun Ramadoss 	int (*mirror_add)(struct ksz_device *dev, int port,
32900a298bbSArun Ramadoss 			  struct dsa_mall_mirror_tc_entry *mirror,
33000a298bbSArun Ramadoss 			  bool ingress, struct netlink_ext_ack *extack);
33100a298bbSArun Ramadoss 	void (*mirror_del)(struct ksz_device *dev, int port,
33200a298bbSArun Ramadoss 			   struct dsa_mall_mirror_tc_entry *mirror);
333e587be75SArun Ramadoss 	int (*fdb_add)(struct ksz_device *dev, int port,
334e587be75SArun Ramadoss 		       const unsigned char *addr, u16 vid, struct dsa_db db);
335e587be75SArun Ramadoss 	int (*fdb_del)(struct ksz_device *dev, int port,
336e587be75SArun Ramadoss 		       const unsigned char *addr, u16 vid, struct dsa_db db);
337e587be75SArun Ramadoss 	int (*fdb_dump)(struct ksz_device *dev, int port,
338e587be75SArun Ramadoss 			dsa_fdb_dump_cb_t *cb, void *data);
339980c7d17SArun Ramadoss 	int (*mdb_add)(struct ksz_device *dev, int port,
340980c7d17SArun Ramadoss 		       const struct switchdev_obj_port_mdb *mdb,
341980c7d17SArun Ramadoss 		       struct dsa_db db);
342980c7d17SArun Ramadoss 	int (*mdb_del)(struct ksz_device *dev, int port,
343980c7d17SArun Ramadoss 		       const struct switchdev_obj_port_mdb *mdb,
344980c7d17SArun Ramadoss 		       struct dsa_db db);
3457012033cSArun Ramadoss 	void (*get_caps)(struct ksz_device *dev, int port,
3467012033cSArun Ramadoss 			 struct phylink_config *config);
3471fe94f54SArun Ramadoss 	int (*change_mtu)(struct ksz_device *dev, int port, int mtu);
3486a7abc61SMarek Vasut 	void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze);
3496a7abc61SMarek Vasut 	void (*port_init_cnt)(struct ksz_device *dev, int port);
350a0cb1aa4SArun Ramadoss 	void (*phylink_mac_config)(struct ksz_device *dev, int port,
351a0cb1aa4SArun Ramadoss 				   unsigned int mode,
352a0cb1aa4SArun Ramadoss 				   const struct phylink_link_state *state);
353f597d3adSArun Ramadoss 	void (*phylink_mac_link_up)(struct ksz_device *dev, int port,
354f597d3adSArun Ramadoss 				    unsigned int mode,
355f597d3adSArun Ramadoss 				    phy_interface_t interface,
356f597d3adSArun Ramadoss 				    struct phy_device *phydev, int speed,
357f597d3adSArun Ramadoss 				    int duplex, bool tx_pause, bool rx_pause);
358b19ac41fSArun Ramadoss 	void (*setup_rgmii_delay)(struct ksz_device *dev, int port);
35971d7920fSArun Ramadoss 	int (*tc_cbs_set_cinc)(struct ksz_device *dev, int port, u32 val);
360fb9324beSArun Ramadoss 	void (*config_cpu_port)(struct dsa_switch *ds);
361331d64f7SArun Ramadoss 	int (*enable_stp_addr)(struct ksz_device *dev);
362673b196fSArun Ramadoss 	int (*reset)(struct ksz_device *dev);
3636a7abc61SMarek Vasut 	int (*init)(struct ksz_device *dev);
3646a7abc61SMarek Vasut 	void (*exit)(struct ksz_device *dev);
3656a7abc61SMarek Vasut };
3666a7abc61SMarek Vasut 
3676a7abc61SMarek Vasut struct ksz_device *ksz_switch_alloc(struct device *base, void *priv);
3686ec23aaaSArun Ramadoss int ksz_switch_register(struct ksz_device *dev);
3696a7abc61SMarek Vasut void ksz_switch_remove(struct ksz_device *dev);
3706a7abc61SMarek Vasut 
3717c6ff470STristram Ha void ksz_init_mib_timer(struct ksz_device *dev);
372c6101dd7SArun Ramadoss void ksz_r_mib_stats64(struct ksz_device *dev, int port);
373bde55dd9SOleksij Rempel void ksz88xx_r_mib_stats64(struct ksz_device *dev, int port);
374e593df51SArun Ramadoss void ksz_port_stp_state_set(struct dsa_switch *ds, int port, u8 state);
37546f80fa8SArun Ramadoss bool ksz_get_gbit(struct ksz_device *dev, int port);
3760ab7f6bfSArun Ramadoss phy_interface_t ksz_get_xmii(struct ksz_device *dev, int port, bool gbit);
3771958eee8SArun Ramadoss extern const struct ksz_chip_data ksz_switch_chips[];
378c2e86691STristram Ha 
379c2e86691STristram Ha /* Common register access functions */
380c2e86691STristram Ha 
381c2e86691STristram Ha static inline int ksz_read8(struct ksz_device *dev, u32 reg, u8 *val)
382c2e86691STristram Ha {
383ee394feaSMarek Vasut 	unsigned int value;
384ee394feaSMarek Vasut 	int ret = regmap_read(dev->regmap[0], reg, &value);
385c2e86691STristram Ha 
386ec6ba50cSOleksij Rempel 	if (ret)
387ec6ba50cSOleksij Rempel 		dev_err(dev->dev, "can't read 8bit reg: 0x%x %pe\n", reg,
388ec6ba50cSOleksij Rempel 			ERR_PTR(ret));
389ec6ba50cSOleksij Rempel 
390ee394feaSMarek Vasut 	*val = value;
391c2e86691STristram Ha 	return ret;
392c2e86691STristram Ha }
393c2e86691STristram Ha 
394c2e86691STristram Ha static inline int ksz_read16(struct ksz_device *dev, u32 reg, u16 *val)
395c2e86691STristram Ha {
396ee394feaSMarek Vasut 	unsigned int value;
397ee394feaSMarek Vasut 	int ret = regmap_read(dev->regmap[1], reg, &value);
398c2e86691STristram Ha 
399ec6ba50cSOleksij Rempel 	if (ret)
400ec6ba50cSOleksij Rempel 		dev_err(dev->dev, "can't read 16bit reg: 0x%x %pe\n", reg,
401ec6ba50cSOleksij Rempel 			ERR_PTR(ret));
402ec6ba50cSOleksij Rempel 
403ee394feaSMarek Vasut 	*val = value;
404c2e86691STristram Ha 	return ret;
405c2e86691STristram Ha }
406c2e86691STristram Ha 
407c2e86691STristram Ha static inline int ksz_read32(struct ksz_device *dev, u32 reg, u32 *val)
408c2e86691STristram Ha {
409ee394feaSMarek Vasut 	unsigned int value;
410ee394feaSMarek Vasut 	int ret = regmap_read(dev->regmap[2], reg, &value);
411c2e86691STristram Ha 
412ec6ba50cSOleksij Rempel 	if (ret)
413ec6ba50cSOleksij Rempel 		dev_err(dev->dev, "can't read 32bit reg: 0x%x %pe\n", reg,
414ec6ba50cSOleksij Rempel 			ERR_PTR(ret));
415ec6ba50cSOleksij Rempel 
416ee394feaSMarek Vasut 	*val = value;
417c2e86691STristram Ha 	return ret;
418c2e86691STristram Ha }
419c2e86691STristram Ha 
420e66f840cSTristram Ha static inline int ksz_read64(struct ksz_device *dev, u32 reg, u64 *val)
421e66f840cSTristram Ha {
422e66f840cSTristram Ha 	u32 value[2];
423e66f840cSTristram Ha 	int ret;
424e66f840cSTristram Ha 
425e66f840cSTristram Ha 	ret = regmap_bulk_read(dev->regmap[2], reg, value, 2);
426ec6ba50cSOleksij Rempel 	if (ret)
427ec6ba50cSOleksij Rempel 		dev_err(dev->dev, "can't read 64bit reg: 0x%x %pe\n", reg,
428ec6ba50cSOleksij Rempel 			ERR_PTR(ret));
429ec6ba50cSOleksij Rempel 	else
430c34f674cSBen Hutchings 		*val = (u64)value[0] << 32 | value[1];
431e66f840cSTristram Ha 
432e66f840cSTristram Ha 	return ret;
433e66f840cSTristram Ha }
434e66f840cSTristram Ha 
435c2e86691STristram Ha static inline int ksz_write8(struct ksz_device *dev, u32 reg, u8 value)
436c2e86691STristram Ha {
437ec6ba50cSOleksij Rempel 	int ret;
438ec6ba50cSOleksij Rempel 
439ec6ba50cSOleksij Rempel 	ret = regmap_write(dev->regmap[0], reg, value);
440ec6ba50cSOleksij Rempel 	if (ret)
441ec6ba50cSOleksij Rempel 		dev_err(dev->dev, "can't write 8bit reg: 0x%x %pe\n", reg,
442ec6ba50cSOleksij Rempel 			ERR_PTR(ret));
443ec6ba50cSOleksij Rempel 
444ec6ba50cSOleksij Rempel 	return ret;
445c2e86691STristram Ha }
446c2e86691STristram Ha 
447c2e86691STristram Ha static inline int ksz_write16(struct ksz_device *dev, u32 reg, u16 value)
448c2e86691STristram Ha {
449ec6ba50cSOleksij Rempel 	int ret;
450ec6ba50cSOleksij Rempel 
451ec6ba50cSOleksij Rempel 	ret = regmap_write(dev->regmap[1], reg, value);
452ec6ba50cSOleksij Rempel 	if (ret)
453ec6ba50cSOleksij Rempel 		dev_err(dev->dev, "can't write 16bit reg: 0x%x %pe\n", reg,
454ec6ba50cSOleksij Rempel 			ERR_PTR(ret));
455ec6ba50cSOleksij Rempel 
456ec6ba50cSOleksij Rempel 	return ret;
457c2e86691STristram Ha }
458c2e86691STristram Ha 
459c2e86691STristram Ha static inline int ksz_write32(struct ksz_device *dev, u32 reg, u32 value)
460c2e86691STristram Ha {
461ec6ba50cSOleksij Rempel 	int ret;
462ec6ba50cSOleksij Rempel 
463ec6ba50cSOleksij Rempel 	ret = regmap_write(dev->regmap[2], reg, value);
464ec6ba50cSOleksij Rempel 	if (ret)
465ec6ba50cSOleksij Rempel 		dev_err(dev->dev, "can't write 32bit reg: 0x%x %pe\n", reg,
466ec6ba50cSOleksij Rempel 			ERR_PTR(ret));
467ec6ba50cSOleksij Rempel 
468ec6ba50cSOleksij Rempel 	return ret;
469c2e86691STristram Ha }
470c2e86691STristram Ha 
471eac1ea20SChristian Eggers static inline int ksz_rmw16(struct ksz_device *dev, u32 reg, u16 mask,
472eac1ea20SChristian Eggers 			    u16 value)
473eac1ea20SChristian Eggers {
474eac1ea20SChristian Eggers 	int ret;
475eac1ea20SChristian Eggers 
476eac1ea20SChristian Eggers 	ret = regmap_update_bits(dev->regmap[1], reg, mask, value);
477eac1ea20SChristian Eggers 	if (ret)
478eac1ea20SChristian Eggers 		dev_err(dev->dev, "can't rmw 16bit reg 0x%x: %pe\n", reg,
479eac1ea20SChristian Eggers 			ERR_PTR(ret));
480eac1ea20SChristian Eggers 
481eac1ea20SChristian Eggers 	return ret;
482eac1ea20SChristian Eggers }
483eac1ea20SChristian Eggers 
4841f12ae5bSChristian Eggers static inline int ksz_rmw32(struct ksz_device *dev, u32 reg, u32 mask,
4851f12ae5bSChristian Eggers 			    u32 value)
4861f12ae5bSChristian Eggers {
4871f12ae5bSChristian Eggers 	int ret;
4881f12ae5bSChristian Eggers 
4891f12ae5bSChristian Eggers 	ret = regmap_update_bits(dev->regmap[2], reg, mask, value);
4901f12ae5bSChristian Eggers 	if (ret)
4911f12ae5bSChristian Eggers 		dev_err(dev->dev, "can't rmw 32bit reg 0x%x: %pe\n", reg,
4921f12ae5bSChristian Eggers 			ERR_PTR(ret));
4931f12ae5bSChristian Eggers 
4941f12ae5bSChristian Eggers 	return ret;
4951f12ae5bSChristian Eggers }
4961f12ae5bSChristian Eggers 
497e66f840cSTristram Ha static inline int ksz_write64(struct ksz_device *dev, u32 reg, u64 value)
498e66f840cSTristram Ha {
499e66f840cSTristram Ha 	u32 val[2];
500e66f840cSTristram Ha 
501e66f840cSTristram Ha 	/* Ick! ToDo: Add 64bit R/W to regmap on 32bit systems */
502e66f840cSTristram Ha 	value = swab64(value);
503e66f840cSTristram Ha 	val[0] = swab32(value & 0xffffffffULL);
504e66f840cSTristram Ha 	val[1] = swab32(value >> 32ULL);
505e66f840cSTristram Ha 
506e66f840cSTristram Ha 	return regmap_bulk_write(dev->regmap[2], reg, val, 2);
507e66f840cSTristram Ha }
508e66f840cSTristram Ha 
5096f1b986aSOleksij Rempel static inline int ksz_rmw8(struct ksz_device *dev, int offset, u8 mask, u8 val)
5106f1b986aSOleksij Rempel {
5116f1b986aSOleksij Rempel 	return regmap_update_bits(dev->regmap[0], offset, mask, val);
5126f1b986aSOleksij Rempel }
5136f1b986aSOleksij Rempel 
514d38bc3b4SOleksij Rempel static inline int ksz_pread8(struct ksz_device *dev, int port, int offset,
515c2e86691STristram Ha 			     u8 *data)
516c2e86691STristram Ha {
517d38bc3b4SOleksij Rempel 	return ksz_read8(dev, dev->dev_ops->get_port_addr(port, offset), data);
518c2e86691STristram Ha }
519c2e86691STristram Ha 
520d38bc3b4SOleksij Rempel static inline int ksz_pread16(struct ksz_device *dev, int port, int offset,
521c2e86691STristram Ha 			      u16 *data)
522c2e86691STristram Ha {
523d38bc3b4SOleksij Rempel 	return ksz_read16(dev, dev->dev_ops->get_port_addr(port, offset), data);
524c2e86691STristram Ha }
525c2e86691STristram Ha 
526d38bc3b4SOleksij Rempel static inline int ksz_pread32(struct ksz_device *dev, int port, int offset,
527c2e86691STristram Ha 			      u32 *data)
528c2e86691STristram Ha {
529d38bc3b4SOleksij Rempel 	return ksz_read32(dev, dev->dev_ops->get_port_addr(port, offset), data);
530c2e86691STristram Ha }
531c2e86691STristram Ha 
532d38bc3b4SOleksij Rempel static inline int ksz_pwrite8(struct ksz_device *dev, int port, int offset,
533c2e86691STristram Ha 			      u8 data)
534c2e86691STristram Ha {
535d38bc3b4SOleksij Rempel 	return ksz_write8(dev, dev->dev_ops->get_port_addr(port, offset), data);
536c2e86691STristram Ha }
537c2e86691STristram Ha 
538d38bc3b4SOleksij Rempel static inline int ksz_pwrite16(struct ksz_device *dev, int port, int offset,
539c2e86691STristram Ha 			       u16 data)
540c2e86691STristram Ha {
541d38bc3b4SOleksij Rempel 	return ksz_write16(dev, dev->dev_ops->get_port_addr(port, offset),
542d38bc3b4SOleksij Rempel 			   data);
543c2e86691STristram Ha }
544c2e86691STristram Ha 
545d38bc3b4SOleksij Rempel static inline int ksz_pwrite32(struct ksz_device *dev, int port, int offset,
546c2e86691STristram Ha 			       u32 data)
547c2e86691STristram Ha {
548d38bc3b4SOleksij Rempel 	return ksz_write32(dev, dev->dev_ops->get_port_addr(port, offset),
549d38bc3b4SOleksij Rempel 			   data);
550c2e86691STristram Ha }
551c2e86691STristram Ha 
5528560664fSArun Ramadoss static inline void ksz_prmw8(struct ksz_device *dev, int port, int offset,
5538560664fSArun Ramadoss 			     u8 mask, u8 val)
5548560664fSArun Ramadoss {
5558560664fSArun Ramadoss 	regmap_update_bits(dev->regmap[0],
5568560664fSArun Ramadoss 			   dev->dev_ops->get_port_addr(port, offset),
5578560664fSArun Ramadoss 			   mask, val);
5588560664fSArun Ramadoss }
5598560664fSArun Ramadoss 
560013572a2SMarek Vasut static inline void ksz_regmap_lock(void *__mtx)
561013572a2SMarek Vasut {
562013572a2SMarek Vasut 	struct mutex *mtx = __mtx;
563013572a2SMarek Vasut 	mutex_lock(mtx);
564013572a2SMarek Vasut }
565013572a2SMarek Vasut 
566013572a2SMarek Vasut static inline void ksz_regmap_unlock(void *__mtx)
567013572a2SMarek Vasut {
568013572a2SMarek Vasut 	struct mutex *mtx = __mtx;
569013572a2SMarek Vasut 	mutex_unlock(mtx);
570013572a2SMarek Vasut }
571013572a2SMarek Vasut 
572f3d890f5SArun Ramadoss static inline bool ksz_is_ksz88x3(struct ksz_device *dev)
573f3d890f5SArun Ramadoss {
574f3d890f5SArun Ramadoss 	return dev->chip_id == KSZ8830_CHIP_ID;
575f3d890f5SArun Ramadoss }
576f3d890f5SArun Ramadoss 
57799b16df0SArun Ramadoss static inline int is_lan937x(struct ksz_device *dev)
57899b16df0SArun Ramadoss {
57999b16df0SArun Ramadoss 	return dev->chip_id == LAN9370_CHIP_ID ||
58099b16df0SArun Ramadoss 		dev->chip_id == LAN9371_CHIP_ID ||
58199b16df0SArun Ramadoss 		dev->chip_id == LAN9372_CHIP_ID ||
58299b16df0SArun Ramadoss 		dev->chip_id == LAN9373_CHIP_ID ||
58399b16df0SArun Ramadoss 		dev->chip_id == LAN9374_CHIP_ID;
58499b16df0SArun Ramadoss }
58599b16df0SArun Ramadoss 
586de6dd626SArun Ramadoss /* STP State Defines */
587de6dd626SArun Ramadoss #define PORT_TX_ENABLE			BIT(2)
588de6dd626SArun Ramadoss #define PORT_RX_ENABLE			BIT(1)
589de6dd626SArun Ramadoss #define PORT_LEARN_DISABLE		BIT(0)
590de6dd626SArun Ramadoss 
59191a98917SArun Ramadoss /* Switch ID Defines */
59291a98917SArun Ramadoss #define REG_CHIP_ID0			0x00
59391a98917SArun Ramadoss 
59491a98917SArun Ramadoss #define SW_FAMILY_ID_M			GENMASK(15, 8)
59591a98917SArun Ramadoss #define KSZ87_FAMILY_ID			0x87
59691a98917SArun Ramadoss #define KSZ88_FAMILY_ID			0x88
59791a98917SArun Ramadoss 
59891a98917SArun Ramadoss #define KSZ8_PORT_STATUS_0		0x08
59991a98917SArun Ramadoss #define KSZ8_PORT_FIBER_MODE		BIT(7)
60091a98917SArun Ramadoss 
60191a98917SArun Ramadoss #define SW_CHIP_ID_M			GENMASK(7, 4)
60291a98917SArun Ramadoss #define KSZ87_CHIP_ID_94		0x6
60391a98917SArun Ramadoss #define KSZ87_CHIP_ID_95		0x9
60491a98917SArun Ramadoss #define KSZ88_CHIP_ID_63		0x3
60591a98917SArun Ramadoss 
60691a98917SArun Ramadoss #define SW_REV_ID_M			GENMASK(7, 4)
60791a98917SArun Ramadoss 
608b4490809SOleksij Rempel /* KSZ9893, KSZ9563, KSZ8563 specific register  */
609b4490809SOleksij Rempel #define REG_CHIP_ID4			0x0f
610b4490809SOleksij Rempel #define SKU_ID_KSZ8563			0x3c
611ef912fe4SRakesh Sankaranarayanan #define SKU_ID_KSZ9563			0x1c
612b4490809SOleksij Rempel 
6131ca6437fSArun Ramadoss /* Driver set switch broadcast storm protection at 10% rate. */
6141ca6437fSArun Ramadoss #define BROADCAST_STORM_PROT_RATE	10
6151ca6437fSArun Ramadoss 
6161ca6437fSArun Ramadoss /* 148,800 frames * 67 ms / 100 */
6171ca6437fSArun Ramadoss #define BROADCAST_STORM_VALUE		9969
6181ca6437fSArun Ramadoss 
6191ca6437fSArun Ramadoss #define BROADCAST_STORM_RATE_HI		0x07
6201ca6437fSArun Ramadoss #define BROADCAST_STORM_RATE_LO		0xFF
6211ca6437fSArun Ramadoss #define BROADCAST_STORM_RATE		0x07FF
6221ca6437fSArun Ramadoss 
6230abab9f3SArun Ramadoss #define MULTICAST_STORM_DISABLE		BIT(6)
6240abab9f3SArun Ramadoss 
625ad08ac18SArun Ramadoss #define SW_START			0x01
626ad08ac18SArun Ramadoss 
62746f80fa8SArun Ramadoss /* xMII configuration */
6288560664fSArun Ramadoss #define P_MII_DUPLEX_M			BIT(6)
629aa5b8b73SArun Ramadoss #define P_MII_100MBIT_M			BIT(4)
630aa5b8b73SArun Ramadoss 
63146f80fa8SArun Ramadoss #define P_GMII_1GBIT_M			BIT(6)
632dc1c596eSArun Ramadoss #define P_RGMII_ID_IG_ENABLE		BIT(4)
633dc1c596eSArun Ramadoss #define P_RGMII_ID_EG_ENABLE		BIT(3)
6340ab7f6bfSArun Ramadoss #define P_MII_MAC_MODE			BIT(2)
635dc1c596eSArun Ramadoss #define P_MII_SEL_M			0x3
63646f80fa8SArun Ramadoss 
637ff319a64SArun Ramadoss /* Interrupt */
638e1add7ddSArun Ramadoss #define REG_SW_PORT_INT_STATUS__1	0x001B
639e1add7ddSArun Ramadoss #define REG_SW_PORT_INT_MASK__1		0x001F
640ff319a64SArun Ramadoss 
641ff319a64SArun Ramadoss #define REG_PORT_INT_STATUS		0x001B
642ff319a64SArun Ramadoss #define REG_PORT_INT_MASK		0x001F
643ff319a64SArun Ramadoss 
644ff319a64SArun Ramadoss #define PORT_SRC_PHY_INT		1
645cc13ab18SArun Ramadoss #define PORT_SRC_PTP_INT		2
646ff319a64SArun Ramadoss 
64729d1e85fSOleksij Rempel #define KSZ8795_HUGE_PACKET_SIZE	2000
64829d1e85fSOleksij Rempel #define KSZ8863_HUGE_PACKET_SIZE	1916
64929d1e85fSOleksij Rempel #define KSZ8863_NORMAL_PACKET_SIZE	1536
65029d1e85fSOleksij Rempel #define KSZ8_LEGAL_PACKET_SIZE		1518
651838c19f8SOleksij Rempel #define KSZ9477_MAX_FRAME_SIZE		9000
652838c19f8SOleksij Rempel 
653*c570f861SOleksij Rempel #define KSZ9477_REG_PORT_OUT_RATE_0	0x0420
654*c570f861SOleksij Rempel #define KSZ9477_OUT_RATE_NO_LIMIT	0
655*c570f861SOleksij Rempel 
656*c570f861SOleksij Rempel #define KSZ9477_PORT_MRI_TC_MAP__4	0x0808
657*c570f861SOleksij Rempel 
658*c570f861SOleksij Rempel #define KSZ9477_PORT_TC_MAP_S		4
659*c570f861SOleksij Rempel #define KSZ9477_MAX_TC_PRIO		7
660*c570f861SOleksij Rempel 
66171d7920fSArun Ramadoss /* CBS related registers */
66271d7920fSArun Ramadoss #define REG_PORT_MTI_QUEUE_INDEX__4	0x0900
66371d7920fSArun Ramadoss 
66471d7920fSArun Ramadoss #define REG_PORT_MTI_QUEUE_CTRL_0	0x0914
66571d7920fSArun Ramadoss 
66669444581SOleksij Rempel #define MTI_SCHEDULE_MODE_M		GENMASK(7, 6)
66771d7920fSArun Ramadoss #define MTI_SCHEDULE_STRICT_PRIO	0
66871d7920fSArun Ramadoss #define MTI_SCHEDULE_WRR		2
66969444581SOleksij Rempel #define MTI_SHAPING_M			GENMASK(5, 4)
67071d7920fSArun Ramadoss #define MTI_SHAPING_OFF			0
67171d7920fSArun Ramadoss #define MTI_SHAPING_SRP			1
67271d7920fSArun Ramadoss #define MTI_SHAPING_TIME_AWARE		2
67371d7920fSArun Ramadoss 
674*c570f861SOleksij Rempel #define KSZ9477_PORT_MTI_QUEUE_CTRL_1	0x0915
675*c570f861SOleksij Rempel #define KSZ9477_DEFAULT_WRR_WEIGHT	1
676*c570f861SOleksij Rempel 
67771d7920fSArun Ramadoss #define REG_PORT_MTI_HI_WATER_MARK	0x0916
67871d7920fSArun Ramadoss #define REG_PORT_MTI_LO_WATER_MARK	0x0918
67971d7920fSArun Ramadoss 
680255b59adSMarek Vasut /* Regmap tables generation */
681255b59adSMarek Vasut #define KSZ_SPI_OP_RD		3
682255b59adSMarek Vasut #define KSZ_SPI_OP_WR		2
683255b59adSMarek Vasut 
68420e03777STristram Ha #define swabnot_used(x)		0
68520e03777STristram Ha 
686255b59adSMarek Vasut #define KSZ_SPI_OP_FLAG_MASK(opcode, swp, regbits, regpad)		\
687255b59adSMarek Vasut 	swab##swp((opcode) << ((regbits) + (regpad)))
688255b59adSMarek Vasut 
689255b59adSMarek Vasut #define KSZ_REGMAP_ENTRY(width, swp, regbits, regpad, regalign)		\
690255b59adSMarek Vasut 	{								\
6915f81d545SGeorge McCollister 		.name = #width,						\
692255b59adSMarek Vasut 		.val_bits = (width),					\
693a3aa6e65SMarek Vasut 		.reg_stride = 1,					\
694255b59adSMarek Vasut 		.reg_bits = (regbits) + (regalign),			\
695255b59adSMarek Vasut 		.pad_bits = (regpad),					\
696255b59adSMarek Vasut 		.max_register = BIT(regbits) - 1,			\
697255b59adSMarek Vasut 		.cache_type = REGCACHE_NONE,				\
698255b59adSMarek Vasut 		.read_flag_mask =					\
699255b59adSMarek Vasut 			KSZ_SPI_OP_FLAG_MASK(KSZ_SPI_OP_RD, swp,	\
700255b59adSMarek Vasut 					     regbits, regpad),		\
701255b59adSMarek Vasut 		.write_flag_mask =					\
702255b59adSMarek Vasut 			KSZ_SPI_OP_FLAG_MASK(KSZ_SPI_OP_WR, swp,	\
703255b59adSMarek Vasut 					     regbits, regpad),		\
704013572a2SMarek Vasut 		.lock = ksz_regmap_lock,				\
705013572a2SMarek Vasut 		.unlock = ksz_regmap_unlock,				\
706255b59adSMarek Vasut 		.reg_format_endian = REGMAP_ENDIAN_BIG,			\
707255b59adSMarek Vasut 		.val_format_endian = REGMAP_ENDIAN_BIG			\
708255b59adSMarek Vasut 	}
709255b59adSMarek Vasut 
710255b59adSMarek Vasut #define KSZ_REGMAP_TABLE(ksz, swp, regbits, regpad, regalign)		\
711255b59adSMarek Vasut 	static const struct regmap_config ksz##_regmap_config[] = {	\
712255b59adSMarek Vasut 		KSZ_REGMAP_ENTRY(8, swp, (regbits), (regpad), (regalign)), \
713255b59adSMarek Vasut 		KSZ_REGMAP_ENTRY(16, swp, (regbits), (regpad), (regalign)), \
714255b59adSMarek Vasut 		KSZ_REGMAP_ENTRY(32, swp, (regbits), (regpad), (regalign)), \
715255b59adSMarek Vasut 	}
716255b59adSMarek Vasut 
717c2e86691STristram Ha #endif
718