kernel: add reset control support to rtl8366 driver
[openwrt/staging/blogic.git] / target / linux / generic / files / drivers / net / phy / rtl8366_smi.h
1 /*
2 * Realtek RTL8366 SMI interface driver defines
3 *
4 * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
9 */
10
11 #ifndef _RTL8366_SMI_H
12 #define _RTL8366_SMI_H
13
14 #include <linux/phy.h>
15 #include <linux/switch.h>
16 #include <linux/platform_device.h>
17 #include <linux/reset.h>
18
19 struct rtl8366_smi_ops;
20 struct rtl8366_vlan_ops;
21 struct mii_bus;
22 struct dentry;
23 struct inode;
24 struct file;
25
26 struct rtl8366_mib_counter {
27 unsigned base;
28 unsigned offset;
29 unsigned length;
30 const char *name;
31 };
32
33 struct rtl8366_smi {
34 struct device *parent;
35 unsigned int gpio_sda;
36 unsigned int gpio_sck;
37 void (*hw_reset)(struct rtl8366_smi *smi, bool active);
38 unsigned int clk_delay; /* ns */
39 u8 cmd_read;
40 u8 cmd_write;
41 spinlock_t lock;
42 struct mii_bus *mii_bus;
43 int mii_irq[PHY_MAX_ADDR];
44 struct switch_dev sw_dev;
45
46 unsigned int cpu_port;
47 unsigned int num_ports;
48 unsigned int num_vlan_mc;
49 unsigned int num_mib_counters;
50 struct rtl8366_mib_counter *mib_counters;
51
52 struct rtl8366_smi_ops *ops;
53
54 int vlan_enabled;
55 int vlan4k_enabled;
56
57 char buf[4096];
58
59 struct reset_control *reset;
60
61 #ifdef CONFIG_RTL8366_SMI_DEBUG_FS
62 struct dentry *debugfs_root;
63 u16 dbg_reg;
64 u8 dbg_vlan_4k_page;
65 #endif
66 };
67
68 struct rtl8366_vlan_mc {
69 u16 vid;
70 u16 untag;
71 u16 member;
72 u8 fid;
73 u8 priority;
74 };
75
76 struct rtl8366_vlan_4k {
77 u16 vid;
78 u16 untag;
79 u16 member;
80 u8 fid;
81 };
82
83 struct rtl8366_smi_ops {
84 int (*detect)(struct rtl8366_smi *smi);
85 int (*reset_chip)(struct rtl8366_smi *smi);
86 int (*setup)(struct rtl8366_smi *smi);
87
88 int (*mii_read)(struct mii_bus *bus, int addr, int reg);
89 int (*mii_write)(struct mii_bus *bus, int addr, int reg, u16 val);
90
91 int (*get_vlan_mc)(struct rtl8366_smi *smi, u32 index,
92 struct rtl8366_vlan_mc *vlanmc);
93 int (*set_vlan_mc)(struct rtl8366_smi *smi, u32 index,
94 const struct rtl8366_vlan_mc *vlanmc);
95 int (*get_vlan_4k)(struct rtl8366_smi *smi, u32 vid,
96 struct rtl8366_vlan_4k *vlan4k);
97 int (*set_vlan_4k)(struct rtl8366_smi *smi,
98 const struct rtl8366_vlan_4k *vlan4k);
99 int (*get_mc_index)(struct rtl8366_smi *smi, int port, int *val);
100 int (*set_mc_index)(struct rtl8366_smi *smi, int port, int index);
101 int (*get_mib_counter)(struct rtl8366_smi *smi, int counter,
102 int port, unsigned long long *val);
103 int (*is_vlan_valid)(struct rtl8366_smi *smi, unsigned vlan);
104 int (*enable_vlan)(struct rtl8366_smi *smi, int enable);
105 int (*enable_vlan4k)(struct rtl8366_smi *smi, int enable);
106 int (*enable_port)(struct rtl8366_smi *smi, int port, int enable);
107 };
108
109 struct rtl8366_smi *rtl8366_smi_alloc(struct device *parent);
110 int rtl8366_smi_init(struct rtl8366_smi *smi);
111 void rtl8366_smi_cleanup(struct rtl8366_smi *smi);
112 int rtl8366_smi_write_reg(struct rtl8366_smi *smi, u32 addr, u32 data);
113 int rtl8366_smi_write_reg_noack(struct rtl8366_smi *smi, u32 addr, u32 data);
114 int rtl8366_smi_read_reg(struct rtl8366_smi *smi, u32 addr, u32 *data);
115 int rtl8366_smi_rmwr(struct rtl8366_smi *smi, u32 addr, u32 mask, u32 data);
116
117 int rtl8366_reset_vlan(struct rtl8366_smi *smi);
118 int rtl8366_enable_vlan(struct rtl8366_smi *smi, int enable);
119 int rtl8366_enable_all_ports(struct rtl8366_smi *smi, int enable);
120
121 #ifdef CONFIG_RTL8366_SMI_DEBUG_FS
122 int rtl8366_debugfs_open(struct inode *inode, struct file *file);
123 #endif
124
125 static inline struct rtl8366_smi *sw_to_rtl8366_smi(struct switch_dev *sw)
126 {
127 return container_of(sw, struct rtl8366_smi, sw_dev);
128 }
129
130 int rtl8366_sw_reset_switch(struct switch_dev *dev);
131 int rtl8366_sw_get_port_pvid(struct switch_dev *dev, int port, int *val);
132 int rtl8366_sw_set_port_pvid(struct switch_dev *dev, int port, int val);
133 int rtl8366_sw_get_port_mib(struct switch_dev *dev,
134 const struct switch_attr *attr,
135 struct switch_val *val);
136 int rtl8366_sw_get_vlan_info(struct switch_dev *dev,
137 const struct switch_attr *attr,
138 struct switch_val *val);
139 int rtl8366_sw_get_vlan_fid(struct switch_dev *dev,
140 const struct switch_attr *attr,
141 struct switch_val *val);
142 int rtl8366_sw_set_vlan_fid(struct switch_dev *dev,
143 const struct switch_attr *attr,
144 struct switch_val *val);
145 int rtl8366_sw_get_vlan_ports(struct switch_dev *dev, struct switch_val *val);
146 int rtl8366_sw_set_vlan_ports(struct switch_dev *dev, struct switch_val *val);
147 int rtl8366_sw_get_vlan_enable(struct switch_dev *dev,
148 const struct switch_attr *attr,
149 struct switch_val *val);
150 int rtl8366_sw_set_vlan_enable(struct switch_dev *dev,
151 const struct switch_attr *attr,
152 struct switch_val *val);
153 int rtl8366_sw_get_port_stats(struct switch_dev *dev, int port,
154 struct switch_port_stats *stats,
155 int txb_id, int rxb_id);
156
157 struct rtl8366_smi* rtl8366_smi_probe(struct platform_device *pdev);
158
159 #endif /* _RTL8366_SMI_H */