2 * Microchip KSZ series switch common definitions
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 #include <linux/kernel.h>
23 #include <linux/mutex.h>
24 #include <linux/phy.h>
25 #include <linux/etherdevice.h>
28 #include "ksz_9477_reg.h"
37 struct dsa_switch *ds;
38 struct ksz_platform_data *pdata;
41 struct mutex reg_mutex; /* register access */
42 struct mutex stats_mutex; /* status access */
43 struct mutex alu_mutex; /* ALU access */
44 struct mutex vlan_mutex; /* vlan access */
45 const struct ksz_io_ops *ops;
51 /* chip specific data */
56 int cpu_port; /* port connected to CPU */
57 int cpu_ports; /* port bitmap can be cpu port */
60 struct vlan_table *vlan_cache;
62 u64 mib_value[TOTAL_SWITCH_COUNTER_NUM];
66 int (*read8)(struct ksz_device *dev, u32 reg, u8 *value);
67 int (*read16)(struct ksz_device *dev, u32 reg, u16 *value);
68 int (*read24)(struct ksz_device *dev, u32 reg, u32 *value);
69 int (*read32)(struct ksz_device *dev, u32 reg, u32 *value);
70 int (*write8)(struct ksz_device *dev, u32 reg, u8 value);
71 int (*write16)(struct ksz_device *dev, u32 reg, u16 value);
72 int (*write24)(struct ksz_device *dev, u32 reg, u32 value);
73 int (*write32)(struct ksz_device *dev, u32 reg, u32 value);
74 int (*phy_read16)(struct ksz_device *dev, int addr, int reg,
76 int (*phy_write16)(struct ksz_device *dev, int addr, int reg,
80 struct ksz_device *ksz_switch_alloc(struct device *base,
81 const struct ksz_io_ops *ops, void *priv);
82 int ksz_switch_detect(struct ksz_device *dev);
83 int ksz_switch_register(struct ksz_device *dev);
84 void ksz_switch_remove(struct ksz_device *dev);
86 static inline int ksz_read8(struct ksz_device *dev, u32 reg, u8 *val)
90 mutex_lock(&dev->reg_mutex);
91 ret = dev->ops->read8(dev, reg, val);
92 mutex_unlock(&dev->reg_mutex);
97 static inline int ksz_read16(struct ksz_device *dev, u32 reg, u16 *val)
101 mutex_lock(&dev->reg_mutex);
102 ret = dev->ops->read16(dev, reg, val);
103 mutex_unlock(&dev->reg_mutex);
108 static inline int ksz_read24(struct ksz_device *dev, u32 reg, u32 *val)
112 mutex_lock(&dev->reg_mutex);
113 ret = dev->ops->read24(dev, reg, val);
114 mutex_unlock(&dev->reg_mutex);
119 static inline int ksz_read32(struct ksz_device *dev, u32 reg, u32 *val)
123 mutex_lock(&dev->reg_mutex);
124 ret = dev->ops->read32(dev, reg, val);
125 mutex_unlock(&dev->reg_mutex);
130 static inline int ksz_write8(struct ksz_device *dev, u32 reg, u8 value)
134 mutex_lock(&dev->reg_mutex);
135 ret = dev->ops->write8(dev, reg, value);
136 mutex_unlock(&dev->reg_mutex);
141 static inline int ksz_write16(struct ksz_device *dev, u32 reg, u16 value)
145 mutex_lock(&dev->reg_mutex);
146 ret = dev->ops->write16(dev, reg, value);
147 mutex_unlock(&dev->reg_mutex);
152 static inline int ksz_write24(struct ksz_device *dev, u32 reg, u32 value)
156 mutex_lock(&dev->reg_mutex);
157 ret = dev->ops->write24(dev, reg, value);
158 mutex_unlock(&dev->reg_mutex);
163 static inline int ksz_write32(struct ksz_device *dev, u32 reg, u32 value)
167 mutex_lock(&dev->reg_mutex);
168 ret = dev->ops->write32(dev, reg, value);
169 mutex_unlock(&dev->reg_mutex);
174 static inline void ksz_pread8(struct ksz_device *dev, int port, int offset,
177 ksz_read8(dev, PORT_CTRL_ADDR(port, offset), data);
180 static inline void ksz_pread16(struct ksz_device *dev, int port, int offset,
183 ksz_read16(dev, PORT_CTRL_ADDR(port, offset), data);
186 static inline void ksz_pread32(struct ksz_device *dev, int port, int offset,
189 ksz_read32(dev, PORT_CTRL_ADDR(port, offset), data);
192 static inline void ksz_pwrite8(struct ksz_device *dev, int port, int offset,
195 ksz_write8(dev, PORT_CTRL_ADDR(port, offset), data);
198 static inline void ksz_pwrite16(struct ksz_device *dev, int port, int offset,
201 ksz_write16(dev, PORT_CTRL_ADDR(port, offset), data);
204 static inline void ksz_pwrite32(struct ksz_device *dev, int port, int offset,
207 ksz_write32(dev, PORT_CTRL_ADDR(port, offset), data);