ksz_common.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Microchip switch driver common header
  3. *
  4. * Copyright (C) 2017-2019 Microchip Technology Inc.
  5. */
  6. #ifndef __KSZ_COMMON_H
  7. #define __KSZ_COMMON_H
  8. #include <linux/etherdevice.h>
  9. #include <linux/kernel.h>
  10. #include <linux/mutex.h>
  11. #include <linux/phy.h>
  12. #include <linux/regmap.h>
  13. #include <net/dsa.h>
  14. #include <linux/irq.h>
  15. #define KSZ_MAX_NUM_PORTS 8
  16. struct ksz_device;
  17. struct vlan_table {
  18. u32 table[3];
  19. };
  20. struct ksz_port_mib {
  21. struct mutex cnt_mutex; /* structure access */
  22. u8 cnt_ptr;
  23. u64 *counters;
  24. struct rtnl_link_stats64 stats64;
  25. struct ethtool_pause_stats pause_stats;
  26. struct spinlock stats64_lock;
  27. };
  28. struct ksz_mib_names {
  29. int index;
  30. char string[ETH_GSTRING_LEN];
  31. };
  32. struct ksz_chip_data {
  33. u32 chip_id;
  34. const char *dev_name;
  35. int num_vlans;
  36. int num_alus;
  37. int num_statics;
  38. int cpu_ports;
  39. int port_cnt;
  40. u8 port_nirqs;
  41. const struct ksz_dev_ops *ops;
  42. bool phy_errata_9477;
  43. bool ksz87xx_eee_link_erratum;
  44. const struct ksz_mib_names *mib_names;
  45. int mib_cnt;
  46. u8 reg_mib_cnt;
  47. const u16 *regs;
  48. const u32 *masks;
  49. const u8 *shifts;
  50. const u8 *xmii_ctrl0;
  51. const u8 *xmii_ctrl1;
  52. int stp_ctrl_reg;
  53. int broadcast_ctrl_reg;
  54. int multicast_ctrl_reg;
  55. int start_ctrl_reg;
  56. bool supports_mii[KSZ_MAX_NUM_PORTS];
  57. bool supports_rmii[KSZ_MAX_NUM_PORTS];
  58. bool supports_rgmii[KSZ_MAX_NUM_PORTS];
  59. bool internal_phy[KSZ_MAX_NUM_PORTS];
  60. bool gbit_capable[KSZ_MAX_NUM_PORTS];
  61. const struct regmap_access_table *wr_table;
  62. const struct regmap_access_table *rd_table;
  63. };
  64. struct ksz_irq {
  65. u16 masked;
  66. u16 reg_mask;
  67. u16 reg_status;
  68. struct irq_domain *domain;
  69. int nirqs;
  70. int irq_num;
  71. char name[16];
  72. struct ksz_device *dev;
  73. };
  74. struct ksz_port {
  75. bool remove_tag; /* Remove Tag flag set, for ksz8795 only */
  76. bool learning;
  77. int stp_state;
  78. struct phy_device phydev;
  79. u32 on:1; /* port is not disabled by hardware */
  80. u32 fiber:1; /* port is fiber */
  81. u32 force:1;
  82. u32 read:1; /* read MIB counters in background */
  83. u32 freeze:1; /* MIB counter freeze is enabled */
  84. struct ksz_port_mib mib;
  85. phy_interface_t interface;
  86. u16 max_frame;
  87. u32 rgmii_tx_val;
  88. u32 rgmii_rx_val;
  89. struct ksz_device *ksz_dev;
  90. struct ksz_irq pirq;
  91. u8 num;
  92. };
  93. struct ksz_device {
  94. struct dsa_switch *ds;
  95. struct ksz_platform_data *pdata;
  96. const struct ksz_chip_data *info;
  97. struct mutex dev_mutex; /* device access */
  98. struct mutex regmap_mutex; /* regmap access */
  99. struct mutex alu_mutex; /* ALU access */
  100. struct mutex vlan_mutex; /* vlan access */
  101. const struct ksz_dev_ops *dev_ops;
  102. struct device *dev;
  103. struct regmap *regmap[3];
  104. void *priv;
  105. int irq;
  106. struct gpio_desc *reset_gpio; /* Optional reset GPIO */
  107. /* chip specific data */
  108. u32 chip_id;
  109. u8 chip_rev;
  110. int cpu_port; /* port connected to CPU */
  111. int phy_port_cnt;
  112. phy_interface_t compat_interface;
  113. bool synclko_125;
  114. bool synclko_disable;
  115. struct vlan_table *vlan_cache;
  116. struct ksz_port *ports;
  117. struct delayed_work mib_read;
  118. unsigned long mib_read_interval;
  119. u16 mirror_rx;
  120. u16 mirror_tx;
  121. u16 port_mask;
  122. struct mutex lock_irq; /* IRQ Access */
  123. struct ksz_irq girq;
  124. };
  125. /* List of supported models */
  126. enum ksz_model {
  127. KSZ8563,
  128. KSZ8795,
  129. KSZ8794,
  130. KSZ8765,
  131. KSZ8830,
  132. KSZ9477,
  133. KSZ9896,
  134. KSZ9897,
  135. KSZ9893,
  136. KSZ9567,
  137. LAN9370,
  138. LAN9371,
  139. LAN9372,
  140. LAN9373,
  141. LAN9374,
  142. };
  143. enum ksz_chip_id {
  144. KSZ8563_CHIP_ID = 0x8563,
  145. KSZ8795_CHIP_ID = 0x8795,
  146. KSZ8794_CHIP_ID = 0x8794,
  147. KSZ8765_CHIP_ID = 0x8765,
  148. KSZ8830_CHIP_ID = 0x8830,
  149. KSZ9477_CHIP_ID = 0x00947700,
  150. KSZ9896_CHIP_ID = 0x00989600,
  151. KSZ9897_CHIP_ID = 0x00989700,
  152. KSZ9893_CHIP_ID = 0x00989300,
  153. KSZ9567_CHIP_ID = 0x00956700,
  154. LAN9370_CHIP_ID = 0x00937000,
  155. LAN9371_CHIP_ID = 0x00937100,
  156. LAN9372_CHIP_ID = 0x00937200,
  157. LAN9373_CHIP_ID = 0x00937300,
  158. LAN9374_CHIP_ID = 0x00937400,
  159. };
  160. enum ksz_regs {
  161. REG_IND_CTRL_0,
  162. REG_IND_DATA_8,
  163. REG_IND_DATA_CHECK,
  164. REG_IND_DATA_HI,
  165. REG_IND_DATA_LO,
  166. REG_IND_MIB_CHECK,
  167. REG_IND_BYTE,
  168. P_FORCE_CTRL,
  169. P_LINK_STATUS,
  170. P_LOCAL_CTRL,
  171. P_NEG_RESTART_CTRL,
  172. P_REMOTE_STATUS,
  173. P_SPEED_STATUS,
  174. S_TAIL_TAG_CTRL,
  175. P_STP_CTRL,
  176. S_START_CTRL,
  177. S_BROADCAST_CTRL,
  178. S_MULTICAST_CTRL,
  179. P_XMII_CTRL_0,
  180. P_XMII_CTRL_1,
  181. };
  182. enum ksz_masks {
  183. PORT_802_1P_REMAPPING,
  184. SW_TAIL_TAG_ENABLE,
  185. MIB_COUNTER_OVERFLOW,
  186. MIB_COUNTER_VALID,
  187. VLAN_TABLE_FID,
  188. VLAN_TABLE_MEMBERSHIP,
  189. VLAN_TABLE_VALID,
  190. STATIC_MAC_TABLE_VALID,
  191. STATIC_MAC_TABLE_USE_FID,
  192. STATIC_MAC_TABLE_FID,
  193. STATIC_MAC_TABLE_OVERRIDE,
  194. STATIC_MAC_TABLE_FWD_PORTS,
  195. DYNAMIC_MAC_TABLE_ENTRIES_H,
  196. DYNAMIC_MAC_TABLE_MAC_EMPTY,
  197. DYNAMIC_MAC_TABLE_NOT_READY,
  198. DYNAMIC_MAC_TABLE_ENTRIES,
  199. DYNAMIC_MAC_TABLE_FID,
  200. DYNAMIC_MAC_TABLE_SRC_PORT,
  201. DYNAMIC_MAC_TABLE_TIMESTAMP,
  202. ALU_STAT_WRITE,
  203. ALU_STAT_READ,
  204. P_MII_TX_FLOW_CTRL,
  205. P_MII_RX_FLOW_CTRL,
  206. };
  207. enum ksz_shifts {
  208. VLAN_TABLE_MEMBERSHIP_S,
  209. VLAN_TABLE,
  210. STATIC_MAC_FWD_PORTS,
  211. STATIC_MAC_FID,
  212. DYNAMIC_MAC_ENTRIES_H,
  213. DYNAMIC_MAC_ENTRIES,
  214. DYNAMIC_MAC_FID,
  215. DYNAMIC_MAC_TIMESTAMP,
  216. DYNAMIC_MAC_SRC_PORT,
  217. ALU_STAT_INDEX,
  218. };
  219. enum ksz_xmii_ctrl0 {
  220. P_MII_100MBIT,
  221. P_MII_10MBIT,
  222. P_MII_FULL_DUPLEX,
  223. P_MII_HALF_DUPLEX,
  224. };
  225. enum ksz_xmii_ctrl1 {
  226. P_RGMII_SEL,
  227. P_RMII_SEL,
  228. P_GMII_SEL,
  229. P_MII_SEL,
  230. P_GMII_1GBIT,
  231. P_GMII_NOT_1GBIT,
  232. };
  233. struct alu_struct {
  234. /* entry 1 */
  235. u8 is_static:1;
  236. u8 is_src_filter:1;
  237. u8 is_dst_filter:1;
  238. u8 prio_age:3;
  239. u32 _reserv_0_1:23;
  240. u8 mstp:3;
  241. /* entry 2 */
  242. u8 is_override:1;
  243. u8 is_use_fid:1;
  244. u32 _reserv_1_1:23;
  245. u8 port_forward:7;
  246. /* entry 3 & 4*/
  247. u32 _reserv_2_1:9;
  248. u8 fid:7;
  249. u8 mac[ETH_ALEN];
  250. };
  251. struct ksz_dev_ops {
  252. int (*setup)(struct dsa_switch *ds);
  253. void (*teardown)(struct dsa_switch *ds);
  254. u32 (*get_port_addr)(int port, int offset);
  255. void (*cfg_port_member)(struct ksz_device *dev, int port, u8 member);
  256. void (*flush_dyn_mac_table)(struct ksz_device *dev, int port);
  257. void (*port_cleanup)(struct ksz_device *dev, int port);
  258. void (*port_setup)(struct ksz_device *dev, int port, bool cpu_port);
  259. int (*set_ageing_time)(struct ksz_device *dev, unsigned int msecs);
  260. int (*r_phy)(struct ksz_device *dev, u16 phy, u16 reg, u16 *val);
  261. int (*w_phy)(struct ksz_device *dev, u16 phy, u16 reg, u16 val);
  262. void (*r_mib_cnt)(struct ksz_device *dev, int port, u16 addr,
  263. u64 *cnt);
  264. void (*r_mib_pkt)(struct ksz_device *dev, int port, u16 addr,
  265. u64 *dropped, u64 *cnt);
  266. void (*r_mib_stat64)(struct ksz_device *dev, int port);
  267. int (*vlan_filtering)(struct ksz_device *dev, int port,
  268. bool flag, struct netlink_ext_ack *extack);
  269. int (*vlan_add)(struct ksz_device *dev, int port,
  270. const struct switchdev_obj_port_vlan *vlan,
  271. struct netlink_ext_ack *extack);
  272. int (*vlan_del)(struct ksz_device *dev, int port,
  273. const struct switchdev_obj_port_vlan *vlan);
  274. int (*mirror_add)(struct ksz_device *dev, int port,
  275. struct dsa_mall_mirror_tc_entry *mirror,
  276. bool ingress, struct netlink_ext_ack *extack);
  277. void (*mirror_del)(struct ksz_device *dev, int port,
  278. struct dsa_mall_mirror_tc_entry *mirror);
  279. int (*fdb_add)(struct ksz_device *dev, int port,
  280. const unsigned char *addr, u16 vid, struct dsa_db db);
  281. int (*fdb_del)(struct ksz_device *dev, int port,
  282. const unsigned char *addr, u16 vid, struct dsa_db db);
  283. int (*fdb_dump)(struct ksz_device *dev, int port,
  284. dsa_fdb_dump_cb_t *cb, void *data);
  285. int (*mdb_add)(struct ksz_device *dev, int port,
  286. const struct switchdev_obj_port_mdb *mdb,
  287. struct dsa_db db);
  288. int (*mdb_del)(struct ksz_device *dev, int port,
  289. const struct switchdev_obj_port_mdb *mdb,
  290. struct dsa_db db);
  291. void (*get_caps)(struct ksz_device *dev, int port,
  292. struct phylink_config *config);
  293. int (*change_mtu)(struct ksz_device *dev, int port, int mtu);
  294. int (*max_mtu)(struct ksz_device *dev, int port);
  295. void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze);
  296. void (*port_init_cnt)(struct ksz_device *dev, int port);
  297. void (*phylink_mac_config)(struct ksz_device *dev, int port,
  298. unsigned int mode,
  299. const struct phylink_link_state *state);
  300. void (*phylink_mac_link_up)(struct ksz_device *dev, int port,
  301. unsigned int mode,
  302. phy_interface_t interface,
  303. struct phy_device *phydev, int speed,
  304. int duplex, bool tx_pause, bool rx_pause);
  305. void (*setup_rgmii_delay)(struct ksz_device *dev, int port);
  306. void (*config_cpu_port)(struct dsa_switch *ds);
  307. int (*enable_stp_addr)(struct ksz_device *dev);
  308. int (*reset)(struct ksz_device *dev);
  309. int (*init)(struct ksz_device *dev);
  310. void (*exit)(struct ksz_device *dev);
  311. };
  312. struct ksz_device *ksz_switch_alloc(struct device *base, void *priv);
  313. int ksz_switch_register(struct ksz_device *dev);
  314. void ksz_switch_remove(struct ksz_device *dev);
  315. void ksz_init_mib_timer(struct ksz_device *dev);
  316. void ksz_r_mib_stats64(struct ksz_device *dev, int port);
  317. void ksz_port_stp_state_set(struct dsa_switch *ds, int port, u8 state);
  318. bool ksz_get_gbit(struct ksz_device *dev, int port);
  319. phy_interface_t ksz_get_xmii(struct ksz_device *dev, int port, bool gbit);
  320. extern const struct ksz_chip_data ksz_switch_chips[];
  321. /* Common register access functions */
  322. static inline int ksz_read8(struct ksz_device *dev, u32 reg, u8 *val)
  323. {
  324. unsigned int value;
  325. int ret = regmap_read(dev->regmap[0], reg, &value);
  326. if (ret)
  327. dev_err(dev->dev, "can't read 8bit reg: 0x%x %pe\n", reg,
  328. ERR_PTR(ret));
  329. *val = value;
  330. return ret;
  331. }
  332. static inline int ksz_read16(struct ksz_device *dev, u32 reg, u16 *val)
  333. {
  334. unsigned int value;
  335. int ret = regmap_read(dev->regmap[1], reg, &value);
  336. if (ret)
  337. dev_err(dev->dev, "can't read 16bit reg: 0x%x %pe\n", reg,
  338. ERR_PTR(ret));
  339. *val = value;
  340. return ret;
  341. }
  342. static inline int ksz_read32(struct ksz_device *dev, u32 reg, u32 *val)
  343. {
  344. unsigned int value;
  345. int ret = regmap_read(dev->regmap[2], reg, &value);
  346. if (ret)
  347. dev_err(dev->dev, "can't read 32bit reg: 0x%x %pe\n", reg,
  348. ERR_PTR(ret));
  349. *val = value;
  350. return ret;
  351. }
  352. static inline int ksz_read64(struct ksz_device *dev, u32 reg, u64 *val)
  353. {
  354. u32 value[2];
  355. int ret;
  356. ret = regmap_bulk_read(dev->regmap[2], reg, value, 2);
  357. if (ret)
  358. dev_err(dev->dev, "can't read 64bit reg: 0x%x %pe\n", reg,
  359. ERR_PTR(ret));
  360. else
  361. *val = (u64)value[0] << 32 | value[1];
  362. return ret;
  363. }
  364. static inline int ksz_write8(struct ksz_device *dev, u32 reg, u8 value)
  365. {
  366. int ret;
  367. ret = regmap_write(dev->regmap[0], reg, value);
  368. if (ret)
  369. dev_err(dev->dev, "can't write 8bit reg: 0x%x %pe\n", reg,
  370. ERR_PTR(ret));
  371. return ret;
  372. }
  373. static inline int ksz_write16(struct ksz_device *dev, u32 reg, u16 value)
  374. {
  375. int ret;
  376. ret = regmap_write(dev->regmap[1], reg, value);
  377. if (ret)
  378. dev_err(dev->dev, "can't write 16bit reg: 0x%x %pe\n", reg,
  379. ERR_PTR(ret));
  380. return ret;
  381. }
  382. static inline int ksz_write32(struct ksz_device *dev, u32 reg, u32 value)
  383. {
  384. int ret;
  385. ret = regmap_write(dev->regmap[2], reg, value);
  386. if (ret)
  387. dev_err(dev->dev, "can't write 32bit reg: 0x%x %pe\n", reg,
  388. ERR_PTR(ret));
  389. return ret;
  390. }
  391. static inline int ksz_write64(struct ksz_device *dev, u32 reg, u64 value)
  392. {
  393. u32 val[2];
  394. /* Ick! ToDo: Add 64bit R/W to regmap on 32bit systems */
  395. value = swab64(value);
  396. val[0] = swab32(value & 0xffffffffULL);
  397. val[1] = swab32(value >> 32ULL);
  398. return regmap_bulk_write(dev->regmap[2], reg, val, 2);
  399. }
  400. static inline int ksz_pread8(struct ksz_device *dev, int port, int offset,
  401. u8 *data)
  402. {
  403. return ksz_read8(dev, dev->dev_ops->get_port_addr(port, offset), data);
  404. }
  405. static inline int ksz_pread16(struct ksz_device *dev, int port, int offset,
  406. u16 *data)
  407. {
  408. return ksz_read16(dev, dev->dev_ops->get_port_addr(port, offset), data);
  409. }
  410. static inline int ksz_pread32(struct ksz_device *dev, int port, int offset,
  411. u32 *data)
  412. {
  413. return ksz_read32(dev, dev->dev_ops->get_port_addr(port, offset), data);
  414. }
  415. static inline int ksz_pwrite8(struct ksz_device *dev, int port, int offset,
  416. u8 data)
  417. {
  418. return ksz_write8(dev, dev->dev_ops->get_port_addr(port, offset), data);
  419. }
  420. static inline int ksz_pwrite16(struct ksz_device *dev, int port, int offset,
  421. u16 data)
  422. {
  423. return ksz_write16(dev, dev->dev_ops->get_port_addr(port, offset),
  424. data);
  425. }
  426. static inline int ksz_pwrite32(struct ksz_device *dev, int port, int offset,
  427. u32 data)
  428. {
  429. return ksz_write32(dev, dev->dev_ops->get_port_addr(port, offset),
  430. data);
  431. }
  432. static inline void ksz_prmw8(struct ksz_device *dev, int port, int offset,
  433. u8 mask, u8 val)
  434. {
  435. regmap_update_bits(dev->regmap[0],
  436. dev->dev_ops->get_port_addr(port, offset),
  437. mask, val);
  438. }
  439. static inline void ksz_regmap_lock(void *__mtx)
  440. {
  441. struct mutex *mtx = __mtx;
  442. mutex_lock(mtx);
  443. }
  444. static inline void ksz_regmap_unlock(void *__mtx)
  445. {
  446. struct mutex *mtx = __mtx;
  447. mutex_unlock(mtx);
  448. }
  449. static inline bool ksz_is_ksz87xx(struct ksz_device *dev)
  450. {
  451. return dev->chip_id == KSZ8795_CHIP_ID ||
  452. dev->chip_id == KSZ8794_CHIP_ID ||
  453. dev->chip_id == KSZ8765_CHIP_ID;
  454. }
  455. static inline bool ksz_is_ksz88x3(struct ksz_device *dev)
  456. {
  457. return dev->chip_id == KSZ8830_CHIP_ID;
  458. }
  459. static inline int is_lan937x(struct ksz_device *dev)
  460. {
  461. return dev->chip_id == LAN9370_CHIP_ID ||
  462. dev->chip_id == LAN9371_CHIP_ID ||
  463. dev->chip_id == LAN9372_CHIP_ID ||
  464. dev->chip_id == LAN9373_CHIP_ID ||
  465. dev->chip_id == LAN9374_CHIP_ID;
  466. }
  467. /* STP State Defines */
  468. #define PORT_TX_ENABLE BIT(2)
  469. #define PORT_RX_ENABLE BIT(1)
  470. #define PORT_LEARN_DISABLE BIT(0)
  471. /* Switch ID Defines */
  472. #define REG_CHIP_ID0 0x00
  473. #define SW_FAMILY_ID_M GENMASK(15, 8)
  474. #define KSZ87_FAMILY_ID 0x87
  475. #define KSZ88_FAMILY_ID 0x88
  476. #define KSZ8_PORT_STATUS_0 0x08
  477. #define KSZ8_PORT_FIBER_MODE BIT(7)
  478. #define SW_CHIP_ID_M GENMASK(7, 4)
  479. #define KSZ87_CHIP_ID_94 0x6
  480. #define KSZ87_CHIP_ID_95 0x9
  481. #define KSZ88_CHIP_ID_63 0x3
  482. #define SW_REV_ID_M GENMASK(7, 4)
  483. /* KSZ9893, KSZ9563, KSZ8563 specific register */
  484. #define REG_CHIP_ID4 0x0f
  485. #define SKU_ID_KSZ8563 0x3c
  486. /* Driver set switch broadcast storm protection at 10% rate. */
  487. #define BROADCAST_STORM_PROT_RATE 10
  488. /* 148,800 frames * 67 ms / 100 */
  489. #define BROADCAST_STORM_VALUE 9969
  490. #define BROADCAST_STORM_RATE_HI 0x07
  491. #define BROADCAST_STORM_RATE_LO 0xFF
  492. #define BROADCAST_STORM_RATE 0x07FF
  493. #define MULTICAST_STORM_DISABLE BIT(6)
  494. #define SW_START 0x01
  495. /* xMII configuration */
  496. #define P_MII_DUPLEX_M BIT(6)
  497. #define P_MII_100MBIT_M BIT(4)
  498. #define P_GMII_1GBIT_M BIT(6)
  499. #define P_RGMII_ID_IG_ENABLE BIT(4)
  500. #define P_RGMII_ID_EG_ENABLE BIT(3)
  501. #define P_MII_MAC_MODE BIT(2)
  502. #define P_MII_SEL_M 0x3
  503. /* Interrupt */
  504. #define REG_SW_PORT_INT_STATUS__1 0x001B
  505. #define REG_SW_PORT_INT_MASK__1 0x001F
  506. #define REG_PORT_INT_STATUS 0x001B
  507. #define REG_PORT_INT_MASK 0x001F
  508. #define PORT_SRC_PHY_INT 1
  509. /* Regmap tables generation */
  510. #define KSZ_SPI_OP_RD 3
  511. #define KSZ_SPI_OP_WR 2
  512. #define swabnot_used(x) 0
  513. #define KSZ_SPI_OP_FLAG_MASK(opcode, swp, regbits, regpad) \
  514. swab##swp((opcode) << ((regbits) + (regpad)))
  515. #define KSZ_REGMAP_ENTRY(width, swp, regbits, regpad, regalign) \
  516. { \
  517. .name = #width, \
  518. .val_bits = (width), \
  519. .reg_stride = 1, \
  520. .reg_bits = (regbits) + (regalign), \
  521. .pad_bits = (regpad), \
  522. .max_register = BIT(regbits) - 1, \
  523. .cache_type = REGCACHE_NONE, \
  524. .read_flag_mask = \
  525. KSZ_SPI_OP_FLAG_MASK(KSZ_SPI_OP_RD, swp, \
  526. regbits, regpad), \
  527. .write_flag_mask = \
  528. KSZ_SPI_OP_FLAG_MASK(KSZ_SPI_OP_WR, swp, \
  529. regbits, regpad), \
  530. .lock = ksz_regmap_lock, \
  531. .unlock = ksz_regmap_unlock, \
  532. .reg_format_endian = REGMAP_ENDIAN_BIG, \
  533. .val_format_endian = REGMAP_ENDIAN_BIG \
  534. }
  535. #define KSZ_REGMAP_TABLE(ksz, swp, regbits, regpad, regalign) \
  536. static const struct regmap_config ksz##_regmap_config[] = { \
  537. KSZ_REGMAP_ENTRY(8, swp, (regbits), (regpad), (regalign)), \
  538. KSZ_REGMAP_ENTRY(16, swp, (regbits), (regpad), (regalign)), \
  539. KSZ_REGMAP_ENTRY(32, swp, (regbits), (regpad), (regalign)), \
  540. }
  541. #endif