bcma: trivial: add helpers for masking/setting
[pandora-kernel.git] / include / linux / bcma / bcma.h
1 #ifndef LINUX_BCMA_H_
2 #define LINUX_BCMA_H_
3
4 #include <linux/pci.h>
5 #include <linux/mod_devicetable.h>
6
7 #include <linux/bcma/bcma_driver_chipcommon.h>
8 #include <linux/bcma/bcma_driver_pci.h>
9 #include <linux/ssb/ssb.h> /* SPROM sharing */
10
11 #include "bcma_regs.h"
12
13 struct bcma_device;
14 struct bcma_bus;
15
16 enum bcma_hosttype {
17         BCMA_HOSTTYPE_NONE,
18         BCMA_HOSTTYPE_PCI,
19         BCMA_HOSTTYPE_SDIO,
20 };
21
22 struct bcma_chipinfo {
23         u16 id;
24         u8 rev;
25         u8 pkg;
26 };
27
28 struct bcma_host_ops {
29         u8 (*read8)(struct bcma_device *core, u16 offset);
30         u16 (*read16)(struct bcma_device *core, u16 offset);
31         u32 (*read32)(struct bcma_device *core, u16 offset);
32         void (*write8)(struct bcma_device *core, u16 offset, u8 value);
33         void (*write16)(struct bcma_device *core, u16 offset, u16 value);
34         void (*write32)(struct bcma_device *core, u16 offset, u32 value);
35 #ifdef CONFIG_BCMA_BLOCKIO
36         void (*block_read)(struct bcma_device *core, void *buffer,
37                            size_t count, u16 offset, u8 reg_width);
38         void (*block_write)(struct bcma_device *core, const void *buffer,
39                             size_t count, u16 offset, u8 reg_width);
40 #endif
41         /* Agent ops */
42         u32 (*aread32)(struct bcma_device *core, u16 offset);
43         void (*awrite32)(struct bcma_device *core, u16 offset, u32 value);
44 };
45
46 /* Core manufacturers */
47 #define BCMA_MANUF_ARM                  0x43B
48 #define BCMA_MANUF_MIPS                 0x4A7
49 #define BCMA_MANUF_BCM                  0x4BF
50
51 /* Core class values. */
52 #define BCMA_CL_SIM                     0x0
53 #define BCMA_CL_EROM                    0x1
54 #define BCMA_CL_CORESIGHT               0x9
55 #define BCMA_CL_VERIF                   0xB
56 #define BCMA_CL_OPTIMO                  0xD
57 #define BCMA_CL_GEN                     0xE
58 #define BCMA_CL_PRIMECELL               0xF
59
60 /* Core-ID values. */
61 #define BCMA_CORE_OOB_ROUTER            0x367   /* Out of band */
62 #define BCMA_CORE_INVALID               0x700
63 #define BCMA_CORE_CHIPCOMMON            0x800
64 #define BCMA_CORE_ILINE20               0x801
65 #define BCMA_CORE_SRAM                  0x802
66 #define BCMA_CORE_SDRAM                 0x803
67 #define BCMA_CORE_PCI                   0x804
68 #define BCMA_CORE_MIPS                  0x805
69 #define BCMA_CORE_ETHERNET              0x806
70 #define BCMA_CORE_V90                   0x807
71 #define BCMA_CORE_USB11_HOSTDEV         0x808
72 #define BCMA_CORE_ADSL                  0x809
73 #define BCMA_CORE_ILINE100              0x80A
74 #define BCMA_CORE_IPSEC                 0x80B
75 #define BCMA_CORE_UTOPIA                0x80C
76 #define BCMA_CORE_PCMCIA                0x80D
77 #define BCMA_CORE_INTERNAL_MEM          0x80E
78 #define BCMA_CORE_MEMC_SDRAM            0x80F
79 #define BCMA_CORE_OFDM                  0x810
80 #define BCMA_CORE_EXTIF                 0x811
81 #define BCMA_CORE_80211                 0x812
82 #define BCMA_CORE_PHY_A                 0x813
83 #define BCMA_CORE_PHY_B                 0x814
84 #define BCMA_CORE_PHY_G                 0x815
85 #define BCMA_CORE_MIPS_3302             0x816
86 #define BCMA_CORE_USB11_HOST            0x817
87 #define BCMA_CORE_USB11_DEV             0x818
88 #define BCMA_CORE_USB20_HOST            0x819
89 #define BCMA_CORE_USB20_DEV             0x81A
90 #define BCMA_CORE_SDIO_HOST             0x81B
91 #define BCMA_CORE_ROBOSWITCH            0x81C
92 #define BCMA_CORE_PARA_ATA              0x81D
93 #define BCMA_CORE_SATA_XORDMA           0x81E
94 #define BCMA_CORE_ETHERNET_GBIT         0x81F
95 #define BCMA_CORE_PCIE                  0x820
96 #define BCMA_CORE_PHY_N                 0x821
97 #define BCMA_CORE_SRAM_CTL              0x822
98 #define BCMA_CORE_MINI_MACPHY           0x823
99 #define BCMA_CORE_ARM_1176              0x824
100 #define BCMA_CORE_ARM_7TDMI             0x825
101 #define BCMA_CORE_PHY_LP                0x826
102 #define BCMA_CORE_PMU                   0x827
103 #define BCMA_CORE_PHY_SSN               0x828
104 #define BCMA_CORE_SDIO_DEV              0x829
105 #define BCMA_CORE_ARM_CM3               0x82A
106 #define BCMA_CORE_PHY_HT                0x82B
107 #define BCMA_CORE_MIPS_74K              0x82C
108 #define BCMA_CORE_MAC_GBIT              0x82D
109 #define BCMA_CORE_DDR12_MEM_CTL         0x82E
110 #define BCMA_CORE_PCIE_RC               0x82F   /* PCIe Root Complex */
111 #define BCMA_CORE_OCP_OCP_BRIDGE        0x830
112 #define BCMA_CORE_SHARED_COMMON         0x831
113 #define BCMA_CORE_OCP_AHB_BRIDGE        0x832
114 #define BCMA_CORE_SPI_HOST              0x833
115 #define BCMA_CORE_I2S                   0x834
116 #define BCMA_CORE_SDR_DDR1_MEM_CTL      0x835   /* SDR/DDR1 memory controller core */
117 #define BCMA_CORE_SHIM                  0x837   /* SHIM component in ubus/6362 */
118 #define BCMA_CORE_DEFAULT               0xFFF
119
120 #define BCMA_MAX_NR_CORES               16
121
122 struct bcma_device {
123         struct bcma_bus *bus;
124         struct bcma_device_id id;
125
126         struct device dev;
127         struct device *dma_dev;
128         unsigned int irq;
129         bool dev_registered;
130
131         u8 core_index;
132
133         u32 addr;
134         u32 wrap;
135
136         void *drvdata;
137         struct list_head list;
138 };
139
140 static inline void *bcma_get_drvdata(struct bcma_device *core)
141 {
142         return core->drvdata;
143 }
144 static inline void bcma_set_drvdata(struct bcma_device *core, void *drvdata)
145 {
146         core->drvdata = drvdata;
147 }
148
149 struct bcma_driver {
150         const char *name;
151         const struct bcma_device_id *id_table;
152
153         int (*probe)(struct bcma_device *dev);
154         void (*remove)(struct bcma_device *dev);
155         int (*suspend)(struct bcma_device *dev, pm_message_t state);
156         int (*resume)(struct bcma_device *dev);
157         void (*shutdown)(struct bcma_device *dev);
158
159         struct device_driver drv;
160 };
161 extern
162 int __bcma_driver_register(struct bcma_driver *drv, struct module *owner);
163 static inline int bcma_driver_register(struct bcma_driver *drv)
164 {
165         return __bcma_driver_register(drv, THIS_MODULE);
166 }
167 extern void bcma_driver_unregister(struct bcma_driver *drv);
168
169 struct bcma_bus {
170         /* The MMIO area. */
171         void __iomem *mmio;
172
173         const struct bcma_host_ops *ops;
174
175         enum bcma_hosttype hosttype;
176         union {
177                 /* Pointer to the PCI bus (only for BCMA_HOSTTYPE_PCI) */
178                 struct pci_dev *host_pci;
179                 /* Pointer to the SDIO device (only for BCMA_HOSTTYPE_SDIO) */
180                 struct sdio_func *host_sdio;
181         };
182
183         struct bcma_chipinfo chipinfo;
184
185         struct bcma_device *mapped_core;
186         struct list_head cores;
187         u8 nr_cores;
188
189         struct bcma_drv_cc drv_cc;
190         struct bcma_drv_pci drv_pci;
191
192         /* We decided to share SPROM struct with SSB as long as we do not need
193          * any hacks for BCMA. This simplifies drivers code. */
194         struct ssb_sprom sprom;
195 };
196
197 extern inline u32 bcma_read8(struct bcma_device *core, u16 offset)
198 {
199         return core->bus->ops->read8(core, offset);
200 }
201 extern inline u32 bcma_read16(struct bcma_device *core, u16 offset)
202 {
203         return core->bus->ops->read16(core, offset);
204 }
205 extern inline u32 bcma_read32(struct bcma_device *core, u16 offset)
206 {
207         return core->bus->ops->read32(core, offset);
208 }
209 extern inline
210 void bcma_write8(struct bcma_device *core, u16 offset, u32 value)
211 {
212         core->bus->ops->write8(core, offset, value);
213 }
214 extern inline
215 void bcma_write16(struct bcma_device *core, u16 offset, u32 value)
216 {
217         core->bus->ops->write16(core, offset, value);
218 }
219 extern inline
220 void bcma_write32(struct bcma_device *core, u16 offset, u32 value)
221 {
222         core->bus->ops->write32(core, offset, value);
223 }
224 #ifdef CONFIG_BCMA_BLOCKIO
225 extern inline void bcma_block_read(struct bcma_device *core, void *buffer,
226                                    size_t count, u16 offset, u8 reg_width)
227 {
228         core->bus->ops->block_read(core, buffer, count, offset, reg_width);
229 }
230 extern inline void bcma_block_write(struct bcma_device *core, const void *buffer,
231                                     size_t count, u16 offset, u8 reg_width)
232 {
233         core->bus->ops->block_write(core, buffer, count, offset, reg_width);
234 }
235 #endif
236 extern inline u32 bcma_aread32(struct bcma_device *core, u16 offset)
237 {
238         return core->bus->ops->aread32(core, offset);
239 }
240 extern inline
241 void bcma_awrite32(struct bcma_device *core, u16 offset, u32 value)
242 {
243         core->bus->ops->awrite32(core, offset, value);
244 }
245
246 #define bcma_mask32(cc, offset, mask) \
247         bcma_write32(cc, offset, bcma_read32(cc, offset) & (mask))
248 #define bcma_set32(cc, offset, set) \
249         bcma_write32(cc, offset, bcma_read32(cc, offset) | (set))
250 #define bcma_maskset32(cc, offset, mask, set) \
251         bcma_write32(cc, offset, (bcma_read32(cc, offset) & (mask)) | (set))
252
253 extern bool bcma_core_is_enabled(struct bcma_device *core);
254 extern void bcma_core_disable(struct bcma_device *core, u32 flags);
255 extern int bcma_core_enable(struct bcma_device *core, u32 flags);
256
257
258 #endif /* LINUX_BCMA_H_ */