0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #include <linux/delay.h>
0023 #include <linux/io.h>
0024 #include <linux/kernel.h>
0025 #include <linux/pci.h> /* for PCI defines */
0026 #include <linux/string.h>
0027
0028 #include <asm/pci-direct.h> /* for direct PCI config space access */
0029 #include <asm/fixmap.h>
0030
0031 #include <linux/init_ohci1394_dma.h>
0032 #include "ohci.h"
0033
0034 int __initdata init_ohci1394_dma_early;
0035
0036 struct ohci {
0037 void __iomem *registers;
0038 };
0039
0040 static inline void reg_write(const struct ohci *ohci, int offset, u32 data)
0041 {
0042 writel(data, ohci->registers + offset);
0043 }
0044
0045 static inline u32 reg_read(const struct ohci *ohci, int offset)
0046 {
0047 return readl(ohci->registers + offset);
0048 }
0049
0050 #define OHCI_LOOP_COUNT 100
0051
0052
0053 static inline u8 __init get_phy_reg(struct ohci *ohci, u8 addr)
0054 {
0055 int i;
0056 u32 r;
0057
0058 reg_write(ohci, OHCI1394_PhyControl, (addr << 8) | 0x00008000);
0059
0060 for (i = 0; i < OHCI_LOOP_COUNT; i++) {
0061 if (reg_read(ohci, OHCI1394_PhyControl) & 0x80000000)
0062 break;
0063 mdelay(1);
0064 }
0065 r = reg_read(ohci, OHCI1394_PhyControl);
0066
0067 return (r & 0x00ff0000) >> 16;
0068 }
0069
0070
0071 static inline void __init set_phy_reg(struct ohci *ohci, u8 addr, u8 data)
0072 {
0073 int i;
0074
0075 reg_write(ohci, OHCI1394_PhyControl, (addr << 8) | data | 0x00004000);
0076
0077 for (i = 0; i < OHCI_LOOP_COUNT; i++) {
0078 if (!(reg_read(ohci, OHCI1394_PhyControl) & 0x00004000))
0079 break;
0080 mdelay(1);
0081 }
0082 }
0083
0084
0085 static inline void __init init_ohci1394_soft_reset(struct ohci *ohci)
0086 {
0087 int i;
0088
0089 reg_write(ohci, OHCI1394_HCControlSet, OHCI1394_HCControl_softReset);
0090
0091 for (i = 0; i < OHCI_LOOP_COUNT; i++) {
0092 if (!(reg_read(ohci, OHCI1394_HCControlSet)
0093 & OHCI1394_HCControl_softReset))
0094 break;
0095 mdelay(1);
0096 }
0097 }
0098
0099 #define OHCI1394_MAX_AT_REQ_RETRIES 0xf
0100 #define OHCI1394_MAX_AT_RESP_RETRIES 0x2
0101 #define OHCI1394_MAX_PHYS_RESP_RETRIES 0x8
0102
0103
0104 static inline void __init init_ohci1394_initialize(struct ohci *ohci)
0105 {
0106 u32 bus_options;
0107 int num_ports, i;
0108
0109
0110 bus_options = reg_read(ohci, OHCI1394_BusOptions);
0111 bus_options |= 0x60000000;
0112 bus_options &= ~0x00ff0000;
0113 bus_options &= ~0x18000000;
0114 reg_write(ohci, OHCI1394_BusOptions, bus_options);
0115
0116
0117 reg_write(ohci, OHCI1394_NodeID, 0x0000ffc0);
0118
0119
0120 reg_write(ohci, OHCI1394_HCControlSet,
0121 OHCI1394_HCControl_postedWriteEnable);
0122
0123
0124 reg_write(ohci, OHCI1394_LinkControlClear, 0xffffffff);
0125
0126
0127 reg_write(ohci, OHCI1394_LinkControlSet,
0128 OHCI1394_LinkControl_rcvPhyPkt);
0129
0130
0131 reg_write(ohci, OHCI1394_LinkControlClear, 0x00000400);
0132
0133
0134 reg_write(ohci, OHCI1394_IsoRecvIntMaskClear, 0xffffffff);
0135 reg_write(ohci, OHCI1394_IsoRecvIntEventClear, 0xffffffff);
0136 reg_write(ohci, OHCI1394_IsoXmitIntMaskClear, 0xffffffff);
0137 reg_write(ohci, OHCI1394_IsoXmitIntEventClear, 0xffffffff);
0138
0139
0140 reg_write(ohci, OHCI1394_AsReqFilterHiSet, 0x80000000);
0141
0142
0143 reg_write(ohci, OHCI1394_ATRetries,
0144 OHCI1394_MAX_AT_REQ_RETRIES |
0145 (OHCI1394_MAX_AT_RESP_RETRIES<<4) |
0146 (OHCI1394_MAX_PHYS_RESP_RETRIES<<8));
0147
0148
0149 reg_write(ohci, OHCI1394_HCControlClear,
0150 OHCI1394_HCControl_noByteSwapData);
0151
0152
0153 reg_write(ohci, OHCI1394_HCControlSet, OHCI1394_HCControl_linkEnable);
0154
0155
0156 num_ports = get_phy_reg(ohci, 2) & 0xf;
0157 for (i = 0; i < num_ports; i++) {
0158 unsigned int status;
0159
0160 set_phy_reg(ohci, 7, i);
0161 status = get_phy_reg(ohci, 8);
0162
0163 if (status & 0x20)
0164 set_phy_reg(ohci, 8, status & ~1);
0165 }
0166 }
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177 static inline void __init init_ohci1394_wait_for_busresets(struct ohci *ohci)
0178 {
0179 int i, events;
0180
0181 for (i = 0; i < 9; i++) {
0182 mdelay(200);
0183 events = reg_read(ohci, OHCI1394_IntEventSet);
0184 if (events & OHCI1394_busReset)
0185 reg_write(ohci, OHCI1394_IntEventClear,
0186 OHCI1394_busReset);
0187 }
0188 }
0189
0190
0191
0192
0193
0194
0195 static inline void __init init_ohci1394_enable_physical_dma(struct ohci *ohci)
0196 {
0197 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, 0xffffffff);
0198 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, 0xffffffff);
0199 reg_write(ohci, OHCI1394_PhyUpperBound, 0xffff0000);
0200 }
0201
0202
0203
0204
0205
0206 static inline void __init init_ohci1394_reset_and_init_dma(struct ohci *ohci)
0207 {
0208
0209 init_ohci1394_soft_reset(ohci);
0210
0211
0212 reg_write(ohci, OHCI1394_HCControlSet, OHCI1394_HCControl_LPS);
0213
0214
0215 reg_write(ohci, OHCI1394_IntEventClear, 0xffffffff);
0216 reg_write(ohci, OHCI1394_IntMaskClear, 0xffffffff);
0217
0218 mdelay(50);
0219
0220 init_ohci1394_initialize(ohci);
0221
0222
0223
0224
0225 init_ohci1394_wait_for_busresets(ohci);
0226
0227
0228 init_ohci1394_enable_physical_dma(ohci);
0229 }
0230
0231
0232
0233
0234
0235 static inline void __init init_ohci1394_controller(int num, int slot, int func)
0236 {
0237 unsigned long ohci_base;
0238 struct ohci ohci;
0239
0240 printk(KERN_INFO "init_ohci1394_dma: initializing OHCI-1394"
0241 " at %02x:%02x.%x\n", num, slot, func);
0242
0243 ohci_base = read_pci_config(num, slot, func, PCI_BASE_ADDRESS_0+(0<<2))
0244 & PCI_BASE_ADDRESS_MEM_MASK;
0245
0246 set_fixmap_nocache(FIX_OHCI1394_BASE, ohci_base);
0247
0248 ohci.registers = (void __iomem *)fix_to_virt(FIX_OHCI1394_BASE);
0249
0250 init_ohci1394_reset_and_init_dma(&ohci);
0251 }
0252
0253
0254
0255
0256
0257 void __init init_ohci1394_dma_on_all_controllers(void)
0258 {
0259 int num, slot, func;
0260 u32 class;
0261
0262 if (!early_pci_allowed())
0263 return;
0264
0265
0266 for (num = 0; num < 32; num++) {
0267 for (slot = 0; slot < 32; slot++) {
0268 for (func = 0; func < 8; func++) {
0269 class = read_pci_config(num, slot, func,
0270 PCI_CLASS_REVISION);
0271 if (class == 0xffffffff)
0272 continue;
0273
0274 if (class>>8 != PCI_CLASS_SERIAL_FIREWIRE_OHCI)
0275 continue;
0276
0277 init_ohci1394_controller(num, slot, func);
0278 break;
0279 }
0280 }
0281 }
0282 printk(KERN_INFO "init_ohci1394_dma: finished initializing OHCI DMA\n");
0283 }
0284
0285
0286
0287
0288 static int __init setup_ohci1394_dma(char *opt)
0289 {
0290 if (!strcmp(opt, "early"))
0291 init_ohci1394_dma_early = 1;
0292 return 0;
0293 }
0294
0295
0296 early_param("ohci1394_dma", setup_ohci1394_dma);