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