1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /* Realtek SMI interface driver defines
4 * Copyright (C) 2017 Linus Walleij <linus.walleij@linaro.org>
5 * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
11 #include <linux/phy.h>
12 #include <linux/platform_device.h>
13 #include <linux/gpio/consumer.h>
15 #include <linux/reset.h>
17 #define REALTEK_HW_STOP_DELAY 25 /* msecs */
18 #define REALTEK_HW_START_DELAY 100 /* msecs */
20 struct phylink_mac_ops
;
26 struct rtl8366_mib_counter
{
34 * struct rtl8366_vlan_mc - Virtual LAN member configuration
36 struct rtl8366_vlan_mc
{
44 struct rtl8366_vlan_4k
{
53 struct reset_control
*reset_ctl
;
54 struct gpio_desc
*reset
;
55 struct gpio_desc
*mdc
;
56 struct gpio_desc
*mdio
;
58 struct regmap
*map_nolock
;
59 struct mutex map_lock
;
60 struct mii_bus
*user_mii_bus
;
64 const struct realtek_variant
*variant
;
66 spinlock_t lock
; /* Locks around command writes */
68 struct irq_domain
*irqdomain
;
71 unsigned int cpu_port
;
72 unsigned int num_ports
;
73 unsigned int num_vlan_mc
;
74 unsigned int num_mib_counters
;
75 struct rtl8366_mib_counter
*mib_counters
;
77 const struct realtek_ops
*ops
;
78 int (*write_reg_noack
)(void *ctx
, u32 addr
, u32 data
);
84 void *chip_data
; /* Per-chip extra variant data */
88 * struct realtek_ops - vtable for the per-SMI-chiptype operations
89 * @detect: detects the chiptype
92 int (*detect
)(struct realtek_priv
*priv
);
93 int (*reset_chip
)(struct realtek_priv
*priv
);
94 int (*setup
)(struct realtek_priv
*priv
);
95 int (*get_mib_counter
)(struct realtek_priv
*priv
,
97 struct rtl8366_mib_counter
*mib
,
99 int (*get_vlan_mc
)(struct realtek_priv
*priv
, u32 index
,
100 struct rtl8366_vlan_mc
*vlanmc
);
101 int (*set_vlan_mc
)(struct realtek_priv
*priv
, u32 index
,
102 const struct rtl8366_vlan_mc
*vlanmc
);
103 int (*get_vlan_4k
)(struct realtek_priv
*priv
, u32 vid
,
104 struct rtl8366_vlan_4k
*vlan4k
);
105 int (*set_vlan_4k
)(struct realtek_priv
*priv
,
106 const struct rtl8366_vlan_4k
*vlan4k
);
107 int (*get_mc_index
)(struct realtek_priv
*priv
, int port
, int *val
);
108 int (*set_mc_index
)(struct realtek_priv
*priv
, int port
, int index
);
109 bool (*is_vlan_valid
)(struct realtek_priv
*priv
, unsigned int vlan
);
110 int (*enable_vlan
)(struct realtek_priv
*priv
, bool enable
);
111 int (*enable_vlan4k
)(struct realtek_priv
*priv
, bool enable
);
112 int (*enable_port
)(struct realtek_priv
*priv
, int port
, bool enable
);
113 int (*phy_read
)(struct realtek_priv
*priv
, int phy
, int regnum
);
114 int (*phy_write
)(struct realtek_priv
*priv
, int phy
, int regnum
,
118 struct realtek_variant
{
119 const struct dsa_switch_ops
*ds_ops
;
120 const struct realtek_ops
*ops
;
121 const struct phylink_mac_ops
*phylink_mac_ops
;
122 unsigned int clk_delay
;
128 /* RTL8366 library helpers */
129 int rtl8366_mc_is_used(struct realtek_priv
*priv
, int mc_index
, int *used
);
130 int rtl8366_set_vlan(struct realtek_priv
*priv
, int vid
, u32 member
,
132 int rtl8366_set_pvid(struct realtek_priv
*priv
, unsigned int port
,
134 int rtl8366_enable_vlan4k(struct realtek_priv
*priv
, bool enable
);
135 int rtl8366_enable_vlan(struct realtek_priv
*priv
, bool enable
);
136 int rtl8366_reset_vlan(struct realtek_priv
*priv
);
137 int rtl8366_vlan_add(struct dsa_switch
*ds
, int port
,
138 const struct switchdev_obj_port_vlan
*vlan
,
139 struct netlink_ext_ack
*extack
);
140 int rtl8366_vlan_del(struct dsa_switch
*ds
, int port
,
141 const struct switchdev_obj_port_vlan
*vlan
);
142 void rtl8366_get_strings(struct dsa_switch
*ds
, int port
, u32 stringset
,
144 int rtl8366_get_sset_count(struct dsa_switch
*ds
, int port
, int sset
);
145 void rtl8366_get_ethtool_stats(struct dsa_switch
*ds
, int port
, uint64_t *data
);
147 extern const struct realtek_variant rtl8366rb_variant
;
148 extern const struct realtek_variant rtl8365mb_variant
;
150 #endif /* _REALTEK_H */