]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/pci/pci_ixp.c
video: Skip bitmaps which do not fit into the screen in cfb_console
[karo-tx-uboot.git] / drivers / pci / pci_ixp.c
1 /*
2  * IXP PCI Init
3  *
4  * (C) Copyright 2011
5  * Michael Schwingen, michael@schwingen.org
6  * (C) Copyright 2004 eslab.whut.edu.cn
7  * Yue Hu(huyue_whut@yahoo.com.cn), Ligong Xue(lgxue@hotmail.com)
8  *
9  * See file CREDITS for list of people who contributed to this
10  * project.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License as
14  * published by the Free Software Foundation; either version 2 of
15  * the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25  * MA 02111-1307 USA
26  */
27
28 #include <common.h>
29 #include <asm/processor.h>
30 #include <asm/io.h>
31 #include <pci.h>
32 #include <asm/arch/ixp425.h>
33 #include <asm/arch/ixp425pci.h>
34
35 DECLARE_GLOBAL_DATA_PTR;
36
37 static void non_prefetch_read(unsigned int addr, unsigned int cmd,
38                               unsigned int *data);
39 static void non_prefetch_write(unsigned int addr, unsigned int cmd,
40                                unsigned int data);
41
42 /*define the sub vendor and subsystem to be used */
43 #define IXP425_PCI_SUB_VENDOR_SYSTEM 0x00000000
44
45 #define PCI_MEMORY_BUS          0x00000000
46 #define PCI_MEMORY_PHY          0x00000000
47 #define PCI_MEMORY_SIZE         0x04000000
48
49 #define PCI_MEM_BUS             0x48000000
50 #define PCI_MEM_PHY             0x00000000
51 #define PCI_MEM_SIZE            0x04000000
52
53 #define PCI_IO_BUS              0x00000000
54 #define PCI_IO_PHY              0x00000000
55 #define PCI_IO_SIZE             0x00010000
56
57 /* build address value for config sycle */
58 static unsigned int pci_config_addr(pci_dev_t bdf, unsigned int reg)
59 {
60         unsigned int bus = PCI_BUS(bdf);
61         unsigned int dev = PCI_DEV(bdf);
62         unsigned int func = PCI_FUNC(bdf);
63         unsigned int addr;
64
65         if (bus) { /* secondary bus, use type 1 config cycle */
66                 addr = bdf | (reg & ~3) | 1;
67         } else {
68                 /*
69                   primary bus, type 0 config cycle. address bits 31:28
70                   specify the device 10:8 specify the function
71                 */
72                 addr = BIT((31 - dev)) | (func << 8) | (reg & ~3);
73         }
74
75         return addr;
76 }
77
78 static int pci_config_status(void)
79 {
80         unsigned int regval;
81
82         regval = readl(PCI_CSR_BASE + PCI_ISR_OFFSET);
83         if ((regval & PCI_ISR_PFE) == 0)
84                 return OK;
85
86         /* no device present, make sure that the master abort bit is reset */
87         writel(PCI_ISR_PFE, PCI_CSR_BASE + PCI_ISR_OFFSET);
88         return ERROR;
89 }
90
91 static int pci_ixp_hose_read_config_dword(struct pci_controller *hose,
92                                    pci_dev_t bdf, int where, unsigned int *val)
93 {
94         unsigned int retval;
95         unsigned int addr;
96         int stat;
97
98         debug("pci_ixp_hose_read_config_dword: bdf %x, reg %x", bdf, where);
99         /*Set the address to be read */
100         addr = pci_config_addr(bdf, where);
101         non_prefetch_read(addr, NP_CMD_CONFIGREAD, &retval);
102         *val = retval;
103
104         stat = pci_config_status();
105         if (stat < 0)
106                 *val = -1;
107         debug("-> val %x, status %x\n", *val, stat);
108         return stat;
109 }
110
111 static int pci_ixp_hose_read_config_word(struct pci_controller *hose,
112                                   pci_dev_t bdf, int where, unsigned short *val)
113 {
114         unsigned int n;
115         unsigned int retval;
116         unsigned int addr;
117         unsigned int byteEnables;
118         int stat;
119
120         debug("pci_ixp_hose_read_config_word: bdf %x, reg %x", bdf, where);
121         n = where % 4;
122         /*byte enables are 4 bits active low, the position of each
123            bit maps to the byte that it enables */
124         byteEnables =
125                 (~(BIT(n) | BIT((n + 1)))) &
126                 IXP425_PCI_BOTTOM_NIBBLE_OF_LONG_MASK;
127         byteEnables = byteEnables << PCI_NP_CBE_BESL;
128         /*Set the address to be read */
129         addr = pci_config_addr(bdf, where);
130         non_prefetch_read(addr, byteEnables | NP_CMD_CONFIGREAD, &retval);
131
132         /*Pick out the word we are interested in */
133         *val = retval >> (8 * n);
134
135         stat = pci_config_status();
136         if (stat < 0)
137                 *val = -1;
138         debug("-> val %x, status %x\n", *val, stat);
139         return stat;
140 }
141
142 static int pci_ixp_hose_read_config_byte(struct pci_controller *hose,
143                                   pci_dev_t bdf, int where, unsigned char *val)
144 {
145         unsigned int retval;
146         unsigned int n;
147         unsigned int byteEnables;
148         unsigned int addr;
149         int stat;
150
151         debug("pci_ixp_hose_read_config_byte: bdf %x, reg %x", bdf, where);
152         n = where % 4;
153         /*byte enables are 4 bits, active low, the position of each
154            bit maps to the byte that it enables */
155         byteEnables = (~BIT(n)) & IXP425_PCI_BOTTOM_NIBBLE_OF_LONG_MASK;
156         byteEnables = byteEnables << PCI_NP_CBE_BESL;
157
158         /*Set the address to be read */
159         addr = pci_config_addr(bdf, where);
160         non_prefetch_read(addr, byteEnables | NP_CMD_CONFIGREAD, &retval);
161         /*Pick out the byte we are interested in */
162         *val = retval >> (8 * n);
163
164         stat = pci_config_status();
165         if (stat < 0)
166                 *val = -1;
167         debug("-> val %x, status %x\n", *val, stat);
168         return stat;
169 }
170
171 static int pci_ixp_hose_write_config_byte(struct pci_controller *hose,
172                                    pci_dev_t bdf, int where, unsigned char val)
173 {
174         unsigned int addr;
175         unsigned int byteEnables;
176         unsigned int n;
177         unsigned int ldata;
178         int stat;
179
180         debug("pci_ixp_hose_write_config_byte: bdf %x, reg %x, val %x",
181               bdf, where, val);
182         n = where % 4;
183         /*byte enables are 4 bits active low, the position of each
184            bit maps to the byte that it enables */
185         byteEnables = (~BIT(n)) & IXP425_PCI_BOTTOM_NIBBLE_OF_LONG_MASK;
186         byteEnables = byteEnables << PCI_NP_CBE_BESL;
187         ldata = val << (8 * n);
188         /*Set the address to be written */
189         addr = pci_config_addr(bdf, where);
190         non_prefetch_write(addr, byteEnables | NP_CMD_CONFIGWRITE, ldata);
191
192         stat = pci_config_status();
193         debug("-> status %x\n", stat);
194         return stat;
195 }
196
197 static int pci_ixp_hose_write_config_word(struct pci_controller *hose,
198                                    pci_dev_t bdf, int where, unsigned short val)
199 {
200         unsigned int addr;
201         unsigned int byteEnables;
202         unsigned int n;
203         unsigned int ldata;
204         int stat;
205
206         debug("pci_ixp_hose_write_config_word: bdf %x, reg %x, val %x",
207               bdf, where, val);
208         n = where % 4;
209         /*byte enables are 4 bits active low, the position of each
210            bit maps to the byte that it enables */
211         byteEnables =
212                 (~(BIT(n) | BIT((n + 1)))) &
213                 IXP425_PCI_BOTTOM_NIBBLE_OF_LONG_MASK;
214         byteEnables = byteEnables << PCI_NP_CBE_BESL;
215         ldata = val << (8 * n);
216         /*Set the address to be written */
217         addr = pci_config_addr(bdf, where);
218         non_prefetch_write(addr, byteEnables | NP_CMD_CONFIGWRITE, ldata);
219
220         stat = pci_config_status();
221         debug("-> status %x\n", stat);
222         return stat;
223 }
224
225 static int pci_ixp_hose_write_config_dword(struct pci_controller *hose,
226                                     pci_dev_t bdf, int where, unsigned int val)
227 {
228         unsigned int addr;
229         int stat;
230
231         debug("pci_ixp_hose_write_config_dword: bdf %x, reg %x, val %x",
232               bdf, where, val);
233         /*Set the address to be written */
234         addr = pci_config_addr(bdf, where);
235         non_prefetch_write(addr, NP_CMD_CONFIGWRITE, val);
236
237         stat = pci_config_status();
238         debug("-> status %x\n", stat);
239         return stat;
240 }
241
242 static void non_prefetch_read(unsigned int addr,
243                        unsigned int cmd, unsigned int *data)
244 {
245         writel(addr, PCI_CSR_BASE + PCI_NP_AD_OFFSET);
246
247         /*set up and execute the read */
248         writel(cmd, PCI_CSR_BASE + PCI_NP_CBE_OFFSET);
249
250         /*The result of the read is now in np_rdata */
251         *data = readl(PCI_CSR_BASE + PCI_NP_RDATA_OFFSET);
252
253         return;
254 }
255
256 static void non_prefetch_write(unsigned int addr,
257                         unsigned int cmd, unsigned int data)
258 {
259
260         writel(addr, PCI_CSR_BASE + PCI_NP_AD_OFFSET);
261         /*set up the write */
262         writel(cmd, PCI_CSR_BASE + PCI_NP_CBE_OFFSET);
263         /*Execute the write by writing to NP_WDATA */
264         writel(data, PCI_CSR_BASE + PCI_NP_WDATA_OFFSET);
265
266         return;
267 }
268
269 static void crp_write(unsigned int offset, unsigned int data)
270 {
271         /*
272          * The CRP address register bit 16 indicates that we want to do a
273          * write
274          */
275         writel(PCI_CRP_WRITE | offset, PCI_CSR_BASE + PCI_CRP_AD_CBE_OFFSET);
276         writel(data, PCI_CSR_BASE + PCI_CRP_WDATA_OFFSET);
277 }
278
279 void pci_ixp_init(struct pci_controller *hose)
280 {
281         unsigned int csr;
282
283         /*
284          * Specify that the AHB bus is operating in big endian mode. Set up
285          * byte lane swapping between little-endian PCI and the big-endian
286          * AHB bus
287          */
288 #ifdef __ARMEB__
289         csr =  PCI_CSR_ABE | PCI_CSR_PDS | PCI_CSR_ADS;
290 #else
291         csr = PCI_CSR_ABE;
292 #endif
293         writel(csr, PCI_CSR_BASE + PCI_CSR_OFFSET);
294
295         writel(0, PCI_CSR_BASE + PCI_INTEN_OFFSET);
296
297         /*
298          * We configure the PCI inbound memory windows to be
299          * 1:1 mapped to SDRAM
300          */
301         crp_write(PCI_CFG_BASE_ADDRESS_0, 0x00000000);
302         crp_write(PCI_CFG_BASE_ADDRESS_1, 0x01000000);
303         crp_write(PCI_CFG_BASE_ADDRESS_2, 0x02000000);
304         crp_write(PCI_CFG_BASE_ADDRESS_3, 0x03000000);
305
306         /*
307          * Enable CSR window at 64 MiB to allow PCI masters
308          * to continue prefetching past 64 MiB boundary.
309          */
310         crp_write(PCI_CFG_BASE_ADDRESS_4, 0x04000000);
311         /*
312          * Enable the IO window to be way up high, at 0xfffffc00
313          */
314         crp_write(PCI_CFG_BASE_ADDRESS_5, 0xfffffc01);
315
316         /*Setup PCI-AHB and AHB-PCI address mappings */
317         writel(0x00010203, PCI_CSR_BASE + PCI_AHBMEMBASE_OFFSET);
318
319         writel(0x00000000, PCI_CSR_BASE + PCI_AHBIOBASE_OFFSET);
320
321         writel(0x48494a4b, PCI_CSR_BASE + PCI_PCIMEMBASE_OFFSET);
322
323         crp_write(PCI_CFG_SUB_VENDOR_ID, IXP425_PCI_SUB_VENDOR_SYSTEM);
324
325         crp_write(PCI_CFG_COMMAND, PCI_CFG_CMD_MAE | PCI_CFG_CMD_BME);
326         udelay(1000);
327
328         /* clear error bits in status register */
329         writel(PCI_ISR_PSE | PCI_ISR_PFE | PCI_ISR_PPE | PCI_ISR_AHBE,
330                PCI_CSR_BASE + PCI_ISR_OFFSET);
331
332         /*
333          * Set Initialize Complete in PCI Control Register: allow IXP4XX to
334          * respond to PCI configuration cycles.
335          */
336         csr |= PCI_CSR_IC;
337         writel(csr, PCI_CSR_BASE + PCI_CSR_OFFSET);
338
339         hose->first_busno = 0;
340         hose->last_busno = 0;
341
342         /* System memory space */
343         pci_set_region(hose->regions + 0,
344                        PCI_MEMORY_BUS,
345                        PCI_MEMORY_PHY, PCI_MEMORY_SIZE, PCI_REGION_SYS_MEMORY);
346
347         /* PCI memory space */
348         pci_set_region(hose->regions + 1,
349                        PCI_MEM_BUS,
350                        PCI_MEM_PHY, PCI_MEM_SIZE, PCI_REGION_MEM);
351         /* PCI I/O space */
352         pci_set_region(hose->regions + 2,
353                        PCI_IO_BUS, PCI_IO_PHY, PCI_IO_SIZE, PCI_REGION_IO);
354
355         hose->region_count = 3;
356
357         pci_set_ops(hose,
358                     pci_ixp_hose_read_config_byte,
359                     pci_ixp_hose_read_config_word,
360                     pci_ixp_hose_read_config_dword,
361                     pci_ixp_hose_write_config_byte,
362                     pci_ixp_hose_write_config_word,
363                     pci_ixp_hose_write_config_dword);
364
365         pci_register_hose(hose);
366         hose->last_busno = pci_hose_scan(hose);
367 }