2 * Sonics Silicon Backplane SoC host related functions.
5 * Copyright 2005, Broadcom Corporation
6 * Copyright 2006, 2007, Michael Buesch <m@bues.ch>
8 * Licensed under the GNU/GPL. See COPYING for details.
11 #include <linux/ssb/ssb.h>
13 #include "ssb_private.h"
15 static u8
ssb_host_soc_read8(struct ssb_device
*dev
, u16 offset
)
17 struct ssb_bus
*bus
= dev
->bus
;
19 offset
+= dev
->core_index
* SSB_CORE_SIZE
;
20 return readb(bus
->mmio
+ offset
);
23 static u16
ssb_host_soc_read16(struct ssb_device
*dev
, u16 offset
)
25 struct ssb_bus
*bus
= dev
->bus
;
27 offset
+= dev
->core_index
* SSB_CORE_SIZE
;
28 return readw(bus
->mmio
+ offset
);
31 static u32
ssb_host_soc_read32(struct ssb_device
*dev
, u16 offset
)
33 struct ssb_bus
*bus
= dev
->bus
;
35 offset
+= dev
->core_index
* SSB_CORE_SIZE
;
36 return readl(bus
->mmio
+ offset
);
39 #ifdef CONFIG_SSB_BLOCKIO
40 static void ssb_host_soc_block_read(struct ssb_device
*dev
, void *buffer
,
41 size_t count
, u16 offset
, u8 reg_width
)
43 struct ssb_bus
*bus
= dev
->bus
;
46 offset
+= dev
->core_index
* SSB_CORE_SIZE
;
47 addr
= bus
->mmio
+ offset
;
54 *buf
= __raw_readb(addr
);
63 SSB_WARN_ON(count
& 1);
65 *buf
= (__force __le16
)__raw_readw(addr
);
74 SSB_WARN_ON(count
& 3);
76 *buf
= (__force __le32
)__raw_readl(addr
);
86 #endif /* CONFIG_SSB_BLOCKIO */
88 static void ssb_host_soc_write8(struct ssb_device
*dev
, u16 offset
, u8 value
)
90 struct ssb_bus
*bus
= dev
->bus
;
92 offset
+= dev
->core_index
* SSB_CORE_SIZE
;
93 writeb(value
, bus
->mmio
+ offset
);
96 static void ssb_host_soc_write16(struct ssb_device
*dev
, u16 offset
, u16 value
)
98 struct ssb_bus
*bus
= dev
->bus
;
100 offset
+= dev
->core_index
* SSB_CORE_SIZE
;
101 writew(value
, bus
->mmio
+ offset
);
104 static void ssb_host_soc_write32(struct ssb_device
*dev
, u16 offset
, u32 value
)
106 struct ssb_bus
*bus
= dev
->bus
;
108 offset
+= dev
->core_index
* SSB_CORE_SIZE
;
109 writel(value
, bus
->mmio
+ offset
);
112 #ifdef CONFIG_SSB_BLOCKIO
113 static void ssb_host_soc_block_write(struct ssb_device
*dev
, const void *buffer
,
114 size_t count
, u16 offset
, u8 reg_width
)
116 struct ssb_bus
*bus
= dev
->bus
;
119 offset
+= dev
->core_index
* SSB_CORE_SIZE
;
120 addr
= bus
->mmio
+ offset
;
124 const u8
*buf
= buffer
;
127 __raw_writeb(*buf
, addr
);
134 const __le16
*buf
= buffer
;
136 SSB_WARN_ON(count
& 1);
138 __raw_writew((__force u16
)(*buf
), addr
);
145 const __le32
*buf
= buffer
;
147 SSB_WARN_ON(count
& 3);
149 __raw_writel((__force u32
)(*buf
), addr
);
159 #endif /* CONFIG_SSB_BLOCKIO */
161 /* Ops for the plain SSB bus without a host-device (no PCI or PCMCIA). */
162 const struct ssb_bus_ops ssb_host_soc_ops
= {
163 .read8
= ssb_host_soc_read8
,
164 .read16
= ssb_host_soc_read16
,
165 .read32
= ssb_host_soc_read32
,
166 .write8
= ssb_host_soc_write8
,
167 .write16
= ssb_host_soc_write16
,
168 .write32
= ssb_host_soc_write32
,
169 #ifdef CONFIG_SSB_BLOCKIO
170 .block_read
= ssb_host_soc_block_read
,
171 .block_write
= ssb_host_soc_block_write
,