1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Microchip switch driver common header
4 * Copyright (C) 2017-2024 Microchip Technology Inc.
10 #include <linux/etherdevice.h>
11 #include <linux/kernel.h>
12 #include <linux/mutex.h>
13 #include <linux/phy.h>
14 #include <linux/regmap.h>
16 #include <linux/irq.h>
17 #include <linux/platform_data/microchip-ksz.h>
21 #define KSZ_MAX_NUM_PORTS 8
22 /* all KSZ switches count ports from 1 */
29 struct phylink_mac_ops;
31 enum ksz_regmap_width {
43 struct mutex cnt_mutex; /* structure access */
46 struct rtnl_link_stats64 stats64;
47 struct ethtool_pause_stats pause_stats;
48 struct spinlock stats64_lock;
51 struct ksz_mib_names {
53 char string[ETH_GSTRING_LEN];
56 struct ksz_chip_data {
66 u8 num_ipms; /* number of Internal Priority Maps */
67 bool tc_cbs_supported;
70 * @phy_side_mdio_supported: Indicates if the chip supports an additional
71 * side MDIO channel for accessing integrated PHYs.
73 bool phy_side_mdio_supported;
74 const struct ksz_dev_ops *ops;
75 const struct phylink_mac_ops *phylink_mac_ops;
77 bool ksz87xx_eee_link_erratum;
78 const struct ksz_mib_names *mib_names;
87 int broadcast_ctrl_reg;
88 int multicast_ctrl_reg;
90 bool supports_mii[KSZ_MAX_NUM_PORTS];
91 bool supports_rmii[KSZ_MAX_NUM_PORTS];
92 bool supports_rgmii[KSZ_MAX_NUM_PORTS];
93 bool internal_phy[KSZ_MAX_NUM_PORTS];
94 bool gbit_capable[KSZ_MAX_NUM_PORTS];
95 const struct regmap_access_table *wr_table;
96 const struct regmap_access_table *rd_table;
103 struct irq_domain *domain;
107 struct ksz_device *dev;
111 struct ksz_port *port;
118 struct ksz_switch_macaddr {
119 unsigned char addr[ETH_ALEN];
124 bool remove_tag; /* Remove Tag flag set, for ksz8795 only */
128 struct phy_device phydev;
130 u32 fiber:1; /* port is fiber */
132 u32 read:1; /* read MIB counters in background */
133 u32 freeze:1; /* MIB counter freeze is enabled */
135 struct ksz_port_mib mib;
136 phy_interface_t interface;
139 struct ksz_device *ksz_dev;
143 #if IS_ENABLED(CONFIG_NET_DSA_MICROCHIP_KSZ_PTP)
144 struct hwtstamp_config tstamp_config;
147 struct ksz_irq ptpirq;
148 struct ksz_ptp_irq ptpmsg_irq[3];
150 struct completion tstamp_msg_comp;
156 struct dsa_switch *ds;
157 struct ksz_platform_data *pdata;
158 const struct ksz_chip_data *info;
160 struct mutex dev_mutex; /* device access */
161 struct mutex regmap_mutex; /* regmap access */
162 struct mutex alu_mutex; /* ALU access */
163 struct mutex vlan_mutex; /* vlan access */
164 const struct ksz_dev_ops *dev_ops;
167 struct regmap *regmap[__KSZ_NUM_REGMAPS];
172 struct gpio_desc *reset_gpio; /* Optional reset GPIO */
174 /* chip specific data */
177 int cpu_port; /* port connected to CPU */
179 phy_interface_t compat_interface;
181 bool synclko_disable;
183 bool pme_active_high;
185 struct vlan_table *vlan_cache;
187 struct ksz_port *ports;
188 struct delayed_work mib_read;
189 unsigned long mib_read_interval;
193 struct mutex lock_irq; /* IRQ Access */
195 struct ksz_ptp_data ptp_data;
197 struct ksz_switch_macaddr *switch_macaddr;
198 struct net_device *hsr_dev; /* HSR */
202 * @phy_addr_map: Array mapping switch ports to their corresponding PHY
205 u8 phy_addr_map[KSZ_MAX_NUM_PORTS];
208 * @parent_mdio_bus: Pointer to the external MDIO bus controller.
210 * This points to an external MDIO bus controller that is used to access
211 * the PHYs integrated within the switch. Unlike an integrated MDIO
212 * bus, this external controller provides a direct path for managing
213 * the switch’s internal PHYs, bypassing the main SPI interface.
215 struct mii_bus *parent_mdio_bus;
218 /* List of supported models */
270 PORT_802_1P_REMAPPING,
272 MIB_COUNTER_OVERFLOW,
275 VLAN_TABLE_MEMBERSHIP,
277 STATIC_MAC_TABLE_VALID,
278 STATIC_MAC_TABLE_USE_FID,
279 STATIC_MAC_TABLE_FID,
280 STATIC_MAC_TABLE_OVERRIDE,
281 STATIC_MAC_TABLE_FWD_PORTS,
282 DYNAMIC_MAC_TABLE_ENTRIES_H,
283 DYNAMIC_MAC_TABLE_MAC_EMPTY,
284 DYNAMIC_MAC_TABLE_NOT_READY,
285 DYNAMIC_MAC_TABLE_ENTRIES,
286 DYNAMIC_MAC_TABLE_FID,
287 DYNAMIC_MAC_TABLE_SRC_PORT,
288 DYNAMIC_MAC_TABLE_TIMESTAMP,
296 VLAN_TABLE_MEMBERSHIP_S,
298 STATIC_MAC_FWD_PORTS,
300 DYNAMIC_MAC_ENTRIES_H,
303 DYNAMIC_MAC_TIMESTAMP,
304 DYNAMIC_MAC_SRC_PORT,
308 enum ksz_xmii_ctrl0 {
315 enum ksz_xmii_ctrl1 {
344 int (*setup)(struct dsa_switch *ds);
345 void (*teardown)(struct dsa_switch *ds);
346 u32 (*get_port_addr)(int port, int offset);
347 void (*cfg_port_member)(struct ksz_device *dev, int port, u8 member);
348 void (*flush_dyn_mac_table)(struct ksz_device *dev, int port);
349 void (*port_cleanup)(struct ksz_device *dev, int port);
350 void (*port_setup)(struct ksz_device *dev, int port, bool cpu_port);
351 int (*set_ageing_time)(struct ksz_device *dev, unsigned int msecs);
354 * @mdio_bus_preinit: Function pointer to pre-initialize the MDIO bus
355 * for accessing PHYs.
356 * @dev: Pointer to device structure.
357 * @side_mdio: Boolean indicating if the PHYs are accessed over a side
360 * This function pointer is used to configure the MDIO bus for PHY
361 * access before initiating regular PHY operations. It enables either
362 * SPI/I2C or side MDIO access modes by unlocking necessary registers
363 * and setting up access permissions for the selected mode.
367 * - Negative error code on failure.
369 int (*mdio_bus_preinit)(struct ksz_device *dev, bool side_mdio);
372 * @create_phy_addr_map: Function pointer to create a port-to-PHY
374 * @dev: Pointer to device structure.
375 * @side_mdio: Boolean indicating if the PHYs are accessed over a side
378 * This function pointer is responsible for mapping switch ports to PHY
379 * addresses according to the configured access mode (SPI or side MDIO)
380 * and the device’s strap configuration. The mapping setup may vary
381 * depending on the chip variant and configuration. Ensures the correct
382 * address mapping for PHY communication.
386 * - Negative error code on failure (e.g., invalid configuration).
388 int (*create_phy_addr_map)(struct ksz_device *dev, bool side_mdio);
389 int (*r_phy)(struct ksz_device *dev, u16 phy, u16 reg, u16 *val);
390 int (*w_phy)(struct ksz_device *dev, u16 phy, u16 reg, u16 val);
391 void (*r_mib_cnt)(struct ksz_device *dev, int port, u16 addr,
393 void (*r_mib_pkt)(struct ksz_device *dev, int port, u16 addr,
394 u64 *dropped, u64 *cnt);
395 void (*r_mib_stat64)(struct ksz_device *dev, int port);
396 int (*vlan_filtering)(struct ksz_device *dev, int port,
397 bool flag, struct netlink_ext_ack *extack);
398 int (*vlan_add)(struct ksz_device *dev, int port,
399 const struct switchdev_obj_port_vlan *vlan,
400 struct netlink_ext_ack *extack);
401 int (*vlan_del)(struct ksz_device *dev, int port,
402 const struct switchdev_obj_port_vlan *vlan);
403 int (*mirror_add)(struct ksz_device *dev, int port,
404 struct dsa_mall_mirror_tc_entry *mirror,
405 bool ingress, struct netlink_ext_ack *extack);
406 void (*mirror_del)(struct ksz_device *dev, int port,
407 struct dsa_mall_mirror_tc_entry *mirror);
408 int (*fdb_add)(struct ksz_device *dev, int port,
409 const unsigned char *addr, u16 vid, struct dsa_db db);
410 int (*fdb_del)(struct ksz_device *dev, int port,
411 const unsigned char *addr, u16 vid, struct dsa_db db);
412 int (*fdb_dump)(struct ksz_device *dev, int port,
413 dsa_fdb_dump_cb_t *cb, void *data);
414 int (*mdb_add)(struct ksz_device *dev, int port,
415 const struct switchdev_obj_port_mdb *mdb,
417 int (*mdb_del)(struct ksz_device *dev, int port,
418 const struct switchdev_obj_port_mdb *mdb,
420 void (*get_caps)(struct ksz_device *dev, int port,
421 struct phylink_config *config);
422 int (*change_mtu)(struct ksz_device *dev, int port, int mtu);
423 int (*pme_write8)(struct ksz_device *dev, u32 reg, u8 value);
424 int (*pme_pread8)(struct ksz_device *dev, int port, int offset,
426 int (*pme_pwrite8)(struct ksz_device *dev, int port, int offset,
428 void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze);
429 void (*port_init_cnt)(struct ksz_device *dev, int port);
430 void (*phylink_mac_link_up)(struct ksz_device *dev, int port,
432 phy_interface_t interface,
433 struct phy_device *phydev, int speed,
434 int duplex, bool tx_pause, bool rx_pause);
435 void (*setup_rgmii_delay)(struct ksz_device *dev, int port);
436 int (*tc_cbs_set_cinc)(struct ksz_device *dev, int port, u32 val);
437 void (*config_cpu_port)(struct dsa_switch *ds);
438 int (*enable_stp_addr)(struct ksz_device *dev);
439 int (*reset)(struct ksz_device *dev);
440 int (*init)(struct ksz_device *dev);
441 void (*exit)(struct ksz_device *dev);
444 struct ksz_device *ksz_switch_alloc(struct device *base, void *priv);
445 int ksz_switch_register(struct ksz_device *dev);
446 void ksz_switch_remove(struct ksz_device *dev);
448 void ksz_init_mib_timer(struct ksz_device *dev);
449 bool ksz_is_port_mac_global_usable(struct dsa_switch *ds, int port);
450 void ksz_r_mib_stats64(struct ksz_device *dev, int port);
451 void ksz88xx_r_mib_stats64(struct ksz_device *dev, int port);
452 void ksz_port_stp_state_set(struct dsa_switch *ds, int port, u8 state);
453 bool ksz_get_gbit(struct ksz_device *dev, int port);
454 phy_interface_t ksz_get_xmii(struct ksz_device *dev, int port, bool gbit);
455 extern const struct ksz_chip_data ksz_switch_chips[];
456 int ksz_switch_macaddr_get(struct dsa_switch *ds, int port,
457 struct netlink_ext_ack *extack);
458 void ksz_switch_macaddr_put(struct dsa_switch *ds);
459 void ksz_switch_shutdown(struct ksz_device *dev);
460 int ksz_handle_wake_reason(struct ksz_device *dev, int port);
462 /* Common register access functions */
463 static inline struct regmap *ksz_regmap_8(struct ksz_device *dev)
465 return dev->regmap[KSZ_REGMAP_8];
468 static inline struct regmap *ksz_regmap_16(struct ksz_device *dev)
470 return dev->regmap[KSZ_REGMAP_16];
473 static inline struct regmap *ksz_regmap_32(struct ksz_device *dev)
475 return dev->regmap[KSZ_REGMAP_32];
478 static inline int ksz_read8(struct ksz_device *dev, u32 reg, u8 *val)
481 int ret = regmap_read(ksz_regmap_8(dev), reg, &value);
484 dev_err(dev->dev, "can't read 8bit reg: 0x%x %pe\n", reg,
491 static inline int ksz_read16(struct ksz_device *dev, u32 reg, u16 *val)
494 int ret = regmap_read(ksz_regmap_16(dev), reg, &value);
497 dev_err(dev->dev, "can't read 16bit reg: 0x%x %pe\n", reg,
504 static inline int ksz_read32(struct ksz_device *dev, u32 reg, u32 *val)
507 int ret = regmap_read(ksz_regmap_32(dev), reg, &value);
510 dev_err(dev->dev, "can't read 32bit reg: 0x%x %pe\n", reg,
517 static inline int ksz_read64(struct ksz_device *dev, u32 reg, u64 *val)
522 ret = regmap_bulk_read(ksz_regmap_32(dev), reg, value, 2);
524 dev_err(dev->dev, "can't read 64bit reg: 0x%x %pe\n", reg,
527 *val = (u64)value[0] << 32 | value[1];
532 static inline int ksz_write8(struct ksz_device *dev, u32 reg, u8 value)
536 ret = regmap_write(ksz_regmap_8(dev), reg, value);
538 dev_err(dev->dev, "can't write 8bit reg: 0x%x %pe\n", reg,
544 static inline int ksz_write16(struct ksz_device *dev, u32 reg, u16 value)
548 ret = regmap_write(ksz_regmap_16(dev), reg, value);
550 dev_err(dev->dev, "can't write 16bit reg: 0x%x %pe\n", reg,
556 static inline int ksz_write32(struct ksz_device *dev, u32 reg, u32 value)
560 ret = regmap_write(ksz_regmap_32(dev), reg, value);
562 dev_err(dev->dev, "can't write 32bit reg: 0x%x %pe\n", reg,
568 static inline int ksz_rmw16(struct ksz_device *dev, u32 reg, u16 mask,
573 ret = regmap_update_bits(ksz_regmap_16(dev), reg, mask, value);
575 dev_err(dev->dev, "can't rmw 16bit reg 0x%x: %pe\n", reg,
581 static inline int ksz_rmw32(struct ksz_device *dev, u32 reg, u32 mask,
586 ret = regmap_update_bits(ksz_regmap_32(dev), reg, mask, value);
588 dev_err(dev->dev, "can't rmw 32bit reg 0x%x: %pe\n", reg,
594 static inline int ksz_write64(struct ksz_device *dev, u32 reg, u64 value)
598 /* Ick! ToDo: Add 64bit R/W to regmap on 32bit systems */
599 value = swab64(value);
600 val[0] = swab32(value & 0xffffffffULL);
601 val[1] = swab32(value >> 32ULL);
603 return regmap_bulk_write(ksz_regmap_32(dev), reg, val, 2);
606 static inline int ksz_rmw8(struct ksz_device *dev, int offset, u8 mask, u8 val)
610 ret = regmap_update_bits(ksz_regmap_8(dev), offset, mask, val);
612 dev_err(dev->dev, "can't rmw 8bit reg 0x%x: %pe\n", offset,
618 static inline int ksz_pread8(struct ksz_device *dev, int port, int offset,
621 return ksz_read8(dev, dev->dev_ops->get_port_addr(port, offset), data);
624 static inline int ksz_pread16(struct ksz_device *dev, int port, int offset,
627 return ksz_read16(dev, dev->dev_ops->get_port_addr(port, offset), data);
630 static inline int ksz_pread32(struct ksz_device *dev, int port, int offset,
633 return ksz_read32(dev, dev->dev_ops->get_port_addr(port, offset), data);
636 static inline int ksz_pwrite8(struct ksz_device *dev, int port, int offset,
639 return ksz_write8(dev, dev->dev_ops->get_port_addr(port, offset), data);
642 static inline int ksz_pwrite16(struct ksz_device *dev, int port, int offset,
645 return ksz_write16(dev, dev->dev_ops->get_port_addr(port, offset),
649 static inline int ksz_pwrite32(struct ksz_device *dev, int port, int offset,
652 return ksz_write32(dev, dev->dev_ops->get_port_addr(port, offset),
656 static inline int ksz_prmw8(struct ksz_device *dev, int port, int offset,
659 return ksz_rmw8(dev, dev->dev_ops->get_port_addr(port, offset),
663 static inline int ksz_prmw32(struct ksz_device *dev, int port, int offset,
666 return ksz_rmw32(dev, dev->dev_ops->get_port_addr(port, offset),
670 static inline void ksz_regmap_lock(void *__mtx)
672 struct mutex *mtx = __mtx;
676 static inline void ksz_regmap_unlock(void *__mtx)
678 struct mutex *mtx = __mtx;
682 static inline bool ksz_is_ksz87xx(struct ksz_device *dev)
684 return dev->chip_id == KSZ8795_CHIP_ID ||
685 dev->chip_id == KSZ8794_CHIP_ID ||
686 dev->chip_id == KSZ8765_CHIP_ID;
689 static inline bool ksz_is_ksz88x3(struct ksz_device *dev)
691 return dev->chip_id == KSZ88X3_CHIP_ID;
694 static inline bool ksz_is_8895_family(struct ksz_device *dev)
696 return dev->chip_id == KSZ8895_CHIP_ID ||
697 dev->chip_id == KSZ8864_CHIP_ID;
700 static inline bool is_ksz8(struct ksz_device *dev)
702 return ksz_is_ksz87xx(dev) || ksz_is_ksz88x3(dev) ||
703 ksz_is_8895_family(dev);
706 static inline bool is_ksz88xx(struct ksz_device *dev)
708 return ksz_is_ksz88x3(dev) || ksz_is_8895_family(dev);
711 static inline bool is_ksz9477(struct ksz_device *dev)
713 return dev->chip_id == KSZ9477_CHIP_ID;
716 static inline int is_lan937x(struct ksz_device *dev)
718 return dev->chip_id == LAN9370_CHIP_ID ||
719 dev->chip_id == LAN9371_CHIP_ID ||
720 dev->chip_id == LAN9372_CHIP_ID ||
721 dev->chip_id == LAN9373_CHIP_ID ||
722 dev->chip_id == LAN9374_CHIP_ID;
725 static inline bool is_lan937x_tx_phy(struct ksz_device *dev, int port)
727 return (dev->chip_id == LAN9371_CHIP_ID ||
728 dev->chip_id == LAN9372_CHIP_ID) && port == KSZ_PORT_4;
731 /* STP State Defines */
732 #define PORT_TX_ENABLE BIT(2)
733 #define PORT_RX_ENABLE BIT(1)
734 #define PORT_LEARN_DISABLE BIT(0)
736 /* Switch ID Defines */
737 #define REG_CHIP_ID0 0x00
739 #define SW_FAMILY_ID_M GENMASK(15, 8)
740 #define KSZ87_FAMILY_ID 0x87
741 #define KSZ88_FAMILY_ID 0x88
742 #define KSZ8895_FAMILY_ID 0x95
744 #define KSZ8_PORT_STATUS_0 0x08
745 #define KSZ8_PORT_FIBER_MODE BIT(7)
747 #define SW_CHIP_ID_M GENMASK(7, 4)
748 #define KSZ87_CHIP_ID_94 0x6
749 #define KSZ87_CHIP_ID_95 0x9
750 #define KSZ88_CHIP_ID_63 0x3
751 #define KSZ8895_CHIP_ID_95 0x4
752 #define KSZ8895_CHIP_ID_95R 0x6
754 /* KSZ8895 specific register */
755 #define REG_KSZ8864_CHIP_ID 0xFE
756 #define SW_KSZ8864 BIT(7)
758 #define SW_REV_ID_M GENMASK(7, 4)
760 /* KSZ9893, KSZ9563, KSZ8563 specific register */
761 #define REG_CHIP_ID4 0x0f
762 #define SKU_ID_KSZ8563 0x3c
763 #define SKU_ID_KSZ9563 0x1c
765 /* Driver set switch broadcast storm protection at 10% rate. */
766 #define BROADCAST_STORM_PROT_RATE 10
768 /* 148,800 frames * 67 ms / 100 */
769 #define BROADCAST_STORM_VALUE 9969
771 #define BROADCAST_STORM_RATE_HI 0x07
772 #define BROADCAST_STORM_RATE_LO 0xFF
773 #define BROADCAST_STORM_RATE 0x07FF
775 #define MULTICAST_STORM_DISABLE BIT(6)
777 #define SW_START 0x01
779 /* xMII configuration */
780 #define P_MII_DUPLEX_M BIT(6)
781 #define P_MII_100MBIT_M BIT(4)
783 #define P_GMII_1GBIT_M BIT(6)
784 #define P_RGMII_ID_IG_ENABLE BIT(4)
785 #define P_RGMII_ID_EG_ENABLE BIT(3)
786 #define P_MII_MAC_MODE BIT(2)
787 #define P_MII_SEL_M 0x3
789 /* KSZ9477, KSZ87xx Wake-on-LAN (WoL) masks */
790 #define PME_WOL_MAGICPKT BIT(2)
791 #define PME_WOL_LINKUP BIT(1)
792 #define PME_WOL_ENERGY BIT(0)
794 #define PME_ENABLE BIT(1)
795 #define PME_POLARITY BIT(0)
797 #define KSZ87XX_REG_INT_EN 0x7D
798 #define KSZ87XX_INT_PME_MASK BIT(4)
801 #define REG_SW_PORT_INT_STATUS__1 0x001B
802 #define REG_SW_PORT_INT_MASK__1 0x001F
804 #define REG_PORT_INT_STATUS 0x001B
805 #define REG_PORT_INT_MASK 0x001F
807 #define PORT_SRC_PHY_INT 1
808 #define PORT_SRC_PTP_INT 2
810 #define KSZ8795_HUGE_PACKET_SIZE 2000
811 #define KSZ8863_HUGE_PACKET_SIZE 1916
812 #define KSZ8863_NORMAL_PACKET_SIZE 1536
813 #define KSZ8_LEGAL_PACKET_SIZE 1518
814 #define KSZ9477_MAX_FRAME_SIZE 9000
816 #define KSZ8873_REG_GLOBAL_CTRL_12 0x0e
817 /* Drive Strength of I/O Pad
820 #define KSZ8873_DRIVE_STRENGTH_16MA BIT(6)
822 #define KSZ8795_REG_SW_CTRL_20 0xa3
823 #define KSZ9477_REG_SW_IO_STRENGTH 0x010d
824 #define SW_DRIVE_STRENGTH_M 0x7
825 #define SW_DRIVE_STRENGTH_2MA 0
826 #define SW_DRIVE_STRENGTH_4MA 1
827 #define SW_DRIVE_STRENGTH_8MA 2
828 #define SW_DRIVE_STRENGTH_12MA 3
829 #define SW_DRIVE_STRENGTH_16MA 4
830 #define SW_DRIVE_STRENGTH_20MA 5
831 #define SW_DRIVE_STRENGTH_24MA 6
832 #define SW_DRIVE_STRENGTH_28MA 7
833 #define SW_HI_SPEED_DRIVE_STRENGTH_S 4
834 #define SW_LO_SPEED_DRIVE_STRENGTH_S 0
836 #define KSZ9477_REG_PORT_OUT_RATE_0 0x0420
837 #define KSZ9477_OUT_RATE_NO_LIMIT 0
839 #define KSZ9477_PORT_MRI_TC_MAP__4 0x0808
841 #define KSZ9477_PORT_TC_MAP_S 4
843 /* CBS related registers */
844 #define REG_PORT_MTI_QUEUE_INDEX__4 0x0900
846 #define REG_PORT_MTI_QUEUE_CTRL_0 0x0914
848 #define MTI_SCHEDULE_MODE_M GENMASK(7, 6)
849 #define MTI_SCHEDULE_STRICT_PRIO 0
850 #define MTI_SCHEDULE_WRR 2
851 #define MTI_SHAPING_M GENMASK(5, 4)
852 #define MTI_SHAPING_OFF 0
853 #define MTI_SHAPING_SRP 1
854 #define MTI_SHAPING_TIME_AWARE 2
856 #define KSZ9477_PORT_MTI_QUEUE_CTRL_1 0x0915
857 #define KSZ9477_DEFAULT_WRR_WEIGHT 1
859 #define REG_PORT_MTI_HI_WATER_MARK 0x0916
860 #define REG_PORT_MTI_LO_WATER_MARK 0x0918
862 /* Regmap tables generation */
863 #define KSZ_SPI_OP_RD 3
864 #define KSZ_SPI_OP_WR 2
866 #define swabnot_used(x) 0
868 #define KSZ_SPI_OP_FLAG_MASK(opcode, swp, regbits, regpad) \
869 swab##swp((opcode) << ((regbits) + (regpad)))
871 #define KSZ_REGMAP_ENTRY(width, swp, regbits, regpad, regalign) \
874 .val_bits = (width), \
876 .reg_bits = (regbits) + (regalign), \
877 .pad_bits = (regpad), \
878 .max_register = BIT(regbits) - 1, \
879 .cache_type = REGCACHE_NONE, \
881 KSZ_SPI_OP_FLAG_MASK(KSZ_SPI_OP_RD, swp, \
884 KSZ_SPI_OP_FLAG_MASK(KSZ_SPI_OP_WR, swp, \
886 .lock = ksz_regmap_lock, \
887 .unlock = ksz_regmap_unlock, \
888 .reg_format_endian = REGMAP_ENDIAN_BIG, \
889 .val_format_endian = REGMAP_ENDIAN_BIG \
892 #define KSZ_REGMAP_TABLE(ksz, swp, regbits, regpad, regalign) \
893 static const struct regmap_config ksz##_regmap_config[] = { \
894 [KSZ_REGMAP_8] = KSZ_REGMAP_ENTRY(8, swp, (regbits), (regpad), (regalign)), \
895 [KSZ_REGMAP_16] = KSZ_REGMAP_ENTRY(16, swp, (regbits), (regpad), (regalign)), \
896 [KSZ_REGMAP_32] = KSZ_REGMAP_ENTRY(32, swp, (regbits), (regpad), (regalign)), \