linux: rtl836x: add a reset_chip callback to rtl8366_smi_ops
[openwrt/staging/chunkeey.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
17 struct rtl8366_smi_ops;
18 struct rtl8366_vlan_ops;
19 struct mii_bus;
20 struct dentry;
21 struct inode;
22 struct file;
23
24 struct rtl8366_mib_counter {
25 unsigned base;
26 unsigned offset;
27 unsigned length;
28 const char *name;
29 };
30
31 struct rtl8366_smi {
32 struct device *parent;
33 unsigned int gpio_sda;
34 unsigned int gpio_sck;
35 unsigned int clk_delay; /* ns */
36 u8 cmd_read;
37 u8 cmd_write;
38 spinlock_t lock;
39 struct mii_bus *mii_bus;
40 int mii_irq[PHY_MAX_ADDR];
41 struct switch_dev sw_dev;
42
43 unsigned int cpu_port;
44 unsigned int num_ports;
45 unsigned int num_vlan_mc;
46 unsigned int num_mib_counters;
47 struct rtl8366_mib_counter *mib_counters;
48
49 struct rtl8366_smi_ops *ops;
50
51 int vlan_enabled;
52 int vlan4k_enabled;
53
54 char buf[4096];
55 #ifdef CONFIG_RTL8366S_PHY_DEBUG_FS
56 struct dentry *debugfs_root;
57 u16 dbg_reg;
58 u8 dbg_vlan_4k_page;
59 #endif
60 };
61
62 struct rtl8366_vlan_mc {
63 u16 vid;
64 u16 untag;
65 u16 member;
66 u8 fid;
67 u8 priority;
68 };
69
70 struct rtl8366_vlan_4k {
71 u16 vid;
72 u16 untag;
73 u16 member;
74 u8 fid;
75 };
76
77 struct rtl8366_smi_ops {
78 int (*detect)(struct rtl8366_smi *smi);
79 int (*reset_chip)(struct rtl8366_smi *smi);
80 int (*setup)(struct rtl8366_smi *smi);
81
82 int (*mii_read)(struct mii_bus *bus, int addr, int reg);
83 int (*mii_write)(struct mii_bus *bus, int addr, int reg, u16 val);
84
85 int (*get_vlan_mc)(struct rtl8366_smi *smi, u32 index,
86 struct rtl8366_vlan_mc *vlanmc);
87 int (*set_vlan_mc)(struct rtl8366_smi *smi, u32 index,
88 const struct rtl8366_vlan_mc *vlanmc);
89 int (*get_vlan_4k)(struct rtl8366_smi *smi, u32 vid,
90 struct rtl8366_vlan_4k *vlan4k);
91 int (*set_vlan_4k)(struct rtl8366_smi *smi,
92 const struct rtl8366_vlan_4k *vlan4k);
93 int (*get_mc_index)(struct rtl8366_smi *smi, int port, int *val);
94 int (*set_mc_index)(struct rtl8366_smi *smi, int port, int index);
95 int (*get_mib_counter)(struct rtl8366_smi *smi, int counter,
96 int port, unsigned long long *val);
97 int (*is_vlan_valid)(struct rtl8366_smi *smi, unsigned vlan);
98 int (*enable_vlan)(struct rtl8366_smi *smi, int enable);
99 int (*enable_vlan4k)(struct rtl8366_smi *smi, int enable);
100 int (*enable_port)(struct rtl8366_smi *smi, int port, int enable);
101 };
102
103 struct rtl8366_smi *rtl8366_smi_alloc(struct device *parent);
104 int rtl8366_smi_init(struct rtl8366_smi *smi);
105 void rtl8366_smi_cleanup(struct rtl8366_smi *smi);
106 int rtl8366_smi_write_reg(struct rtl8366_smi *smi, u32 addr, u32 data);
107 int rtl8366_smi_write_reg_noack(struct rtl8366_smi *smi, u32 addr, u32 data);
108 int rtl8366_smi_read_reg(struct rtl8366_smi *smi, u32 addr, u32 *data);
109 int rtl8366_smi_rmwr(struct rtl8366_smi *smi, u32 addr, u32 mask, u32 data);
110
111 int rtl8366_reset_vlan(struct rtl8366_smi *smi);
112 int rtl8366_enable_vlan(struct rtl8366_smi *smi, int enable);
113 int rtl8366_enable_all_ports(struct rtl8366_smi *smi, int enable);
114
115 #ifdef CONFIG_RTL8366S_PHY_DEBUG_FS
116 int rtl8366_debugfs_open(struct inode *inode, struct file *file);
117 #endif
118
119 static inline struct rtl8366_smi *sw_to_rtl8366_smi(struct switch_dev *sw)
120 {
121 return container_of(sw, struct rtl8366_smi, sw_dev);
122 }
123
124 int rtl8366_sw_get_port_pvid(struct switch_dev *dev, int port, int *val);
125 int rtl8366_sw_set_port_pvid(struct switch_dev *dev, int port, int val);
126 int rtl8366_sw_get_port_mib(struct switch_dev *dev,
127 const struct switch_attr *attr,
128 struct switch_val *val);
129 int rtl8366_sw_get_vlan_info(struct switch_dev *dev,
130 const struct switch_attr *attr,
131 struct switch_val *val);
132 int rtl8366_sw_get_vlan_fid(struct switch_dev *dev,
133 const struct switch_attr *attr,
134 struct switch_val *val);
135 int rtl8366_sw_set_vlan_fid(struct switch_dev *dev,
136 const struct switch_attr *attr,
137 struct switch_val *val);
138 int rtl8366_sw_get_vlan_ports(struct switch_dev *dev, struct switch_val *val);
139 int rtl8366_sw_set_vlan_ports(struct switch_dev *dev, struct switch_val *val);
140 int rtl8366_sw_get_vlan_enable(struct switch_dev *dev,
141 const struct switch_attr *attr,
142 struct switch_val *val);
143 int rtl8366_sw_set_vlan_enable(struct switch_dev *dev,
144 const struct switch_attr *attr,
145 struct switch_val *val);
146
147 #endif /* _RTL8366_SMI_H */