aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-ks8695
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm/mach-ks8695')
-rw-r--r--arch/arm/mach-ks8695/Makefile2
-rw-r--r--arch/arm/mach-ks8695/board-micrel.c2
-rw-r--r--arch/arm/mach-ks8695/gpio.c83
-rw-r--r--arch/arm/mach-ks8695/pci.c326
-rw-r--r--arch/arm/mach-ks8695/time.c3
5 files changed, 411 insertions, 5 deletions
diff --git a/arch/arm/mach-ks8695/Makefile b/arch/arm/mach-ks8695/Makefile
index 2a07a281fa8a..730a3af12c98 100644
--- a/arch/arm/mach-ks8695/Makefile
+++ b/arch/arm/mach-ks8695/Makefile
@@ -9,7 +9,7 @@ obj-n :=
9obj- := 9obj- :=
10 10
11# PCI support is optional 11# PCI support is optional
12#obj-$(CONFIG_PCI) += pci.o 12obj-$(CONFIG_PCI) += pci.o
13 13
14# Board-specific support 14# Board-specific support
15obj-$(CONFIG_MACH_KS8695) += board-micrel.o 15obj-$(CONFIG_MACH_KS8695) += board-micrel.o
diff --git a/arch/arm/mach-ks8695/board-micrel.c b/arch/arm/mach-ks8695/board-micrel.c
index 2feeef81d843..05ac2bd04020 100644
--- a/arch/arm/mach-ks8695/board-micrel.c
+++ b/arch/arm/mach-ks8695/board-micrel.c
@@ -40,7 +40,7 @@ static void __init micrel_init(void)
40 printk(KERN_INFO "Micrel KS8695 Development Board initializing\n"); 40 printk(KERN_INFO "Micrel KS8695 Development Board initializing\n");
41 41
42#ifdef CONFIG_PCI 42#ifdef CONFIG_PCI
43// ks8695_init_pci(&micrel_pci); 43 ks8695_init_pci(&micrel_pci);
44#endif 44#endif
45 45
46 /* Add devices */ 46 /* Add devices */
diff --git a/arch/arm/mach-ks8695/gpio.c b/arch/arm/mach-ks8695/gpio.c
index b1aa3cb3d4a3..5e46191c0af9 100644
--- a/arch/arm/mach-ks8695/gpio.c
+++ b/arch/arm/mach-ks8695/gpio.c
@@ -20,6 +20,8 @@
20#include <linux/kernel.h> 20#include <linux/kernel.h>
21#include <linux/mm.h> 21#include <linux/mm.h>
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/debugfs.h>
24#include <linux/seq_file.h>
23#include <linux/module.h> 25#include <linux/module.h>
24 26
25#include <asm/io.h> 27#include <asm/io.h>
@@ -216,3 +218,84 @@ int irq_to_gpio(unsigned int irq)
216 return (irq - KS8695_IRQ_EXTERN0); 218 return (irq - KS8695_IRQ_EXTERN0);
217} 219}
218EXPORT_SYMBOL(irq_to_gpio); 220EXPORT_SYMBOL(irq_to_gpio);
221
222
223/* .... Debug interface ..................................................... */
224
225#ifdef CONFIG_DEBUG_FS
226
227static int ks8695_gpio_show(struct seq_file *s, void *unused)
228{
229 unsigned int enable[] = { IOPC_IOEINT0EN, IOPC_IOEINT1EN, IOPC_IOEINT2EN, IOPC_IOEINT3EN, IOPC_IOTIM0EN, IOPC_IOTIM1EN };
230 unsigned int intmask[] = { IOPC_IOEINT0TM, IOPC_IOEINT1TM, IOPC_IOEINT2TM, IOPC_IOEINT3TM };
231 unsigned long mode, ctrl, data;
232 int i;
233
234 mode = __raw_readl(KS8695_GPIO_VA + KS8695_IOPM);
235 ctrl = __raw_readl(KS8695_GPIO_VA + KS8695_IOPC);
236 data = __raw_readl(KS8695_GPIO_VA + KS8695_IOPD);
237
238 seq_printf(s, "Pin\tI/O\tFunction\tState\n\n");
239
240 for (i = KS8695_GPIO_0; i <= KS8695_GPIO_15 ; i++) {
241 seq_printf(s, "%i:\t", i);
242
243 seq_printf(s, "%s\t", (mode & IOPM_(i)) ? "Output" : "Input");
244
245 if (i <= KS8695_GPIO_3) {
246 if (ctrl & enable[i]) {
247 seq_printf(s, "EXT%i ", i);
248
249 switch ((ctrl & intmask[i]) >> (4 * i)) {
250 case IOPC_TM_LOW:
251 seq_printf(s, "(Low)"); break;
252 case IOPC_TM_HIGH:
253 seq_printf(s, "(High)"); break;
254 case IOPC_TM_RISING:
255 seq_printf(s, "(Rising)"); break;
256 case IOPC_TM_FALLING:
257 seq_printf(s, "(Falling)"); break;
258 case IOPC_TM_EDGE:
259 seq_printf(s, "(Edges)"); break;
260 }
261 }
262 else
263 seq_printf(s, "GPIO\t");
264 }
265 else if (i <= KS8695_GPIO_5) {
266 if (ctrl & enable[i])
267 seq_printf(s, "TOUT%i\t", i - KS8695_GPIO_4);
268 else
269 seq_printf(s, "GPIO\t");
270 }
271 else
272 seq_printf(s, "GPIO\t");
273
274 seq_printf(s, "\t");
275
276 seq_printf(s, "%i\n", (data & IOPD_(i)) ? 1 : 0);
277 }
278 return 0;
279}
280
281static int ks8695_gpio_open(struct inode *inode, struct file *file)
282{
283 return single_open(file, ks8695_gpio_show, NULL);
284}
285
286static const struct file_operations ks8695_gpio_operations = {
287 .open = ks8695_gpio_open,
288 .read = seq_read,
289 .llseek = seq_lseek,
290 .release = single_release,
291};
292
293static int __init ks8695_gpio_debugfs_init(void)
294{
295 /* /sys/kernel/debug/ks8695_gpio */
296 (void) debugfs_create_file("ks8695_gpio", S_IFREG | S_IRUGO, NULL, NULL, &ks8695_gpio_operations);
297 return 0;
298}
299postcore_initcall(ks8695_gpio_debugfs_init);
300
301#endif
diff --git a/arch/arm/mach-ks8695/pci.c b/arch/arm/mach-ks8695/pci.c
new file mode 100644
index 000000000000..3f4e0330cb1a
--- /dev/null
+++ b/arch/arm/mach-ks8695/pci.c
@@ -0,0 +1,326 @@
1/*
2 * arch/arm/mach-ks8695/pci.c
3 *
4 * Copyright (C) 2003, Micrel Semiconductors
5 * Copyright (C) 2006, Greg Ungerer <gerg@snapgear.com>
6 * Copyright (C) 2006, Ben Dooks
7 * Copyright (C) 2007, Andrew Victor
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24#include <linux/kernel.h>
25#include <linux/pci.h>
26#include <linux/mm.h>
27#include <linux/init.h>
28#include <linux/irq.h>
29#include <linux/delay.h>
30
31#include <asm/io.h>
32#include <asm/signal.h>
33#include <asm/mach/pci.h>
34#include <asm/hardware.h>
35
36#include <asm/arch/devices.h>
37#include <asm/arch/regs-pci.h>
38
39
40static int pci_dbg;
41static int pci_cfg_dbg;
42
43
44static void ks8695_pci_setupconfig(unsigned int bus_nr, unsigned int devfn, unsigned int where)
45{
46 unsigned long pbca;
47
48 pbca = PBCA_ENABLE | (where & ~3);
49 pbca |= PCI_SLOT(devfn) << 11 ;
50 pbca |= PCI_FUNC(devfn) << 8;
51 pbca |= bus_nr << 16;
52
53 if (bus_nr == 0) {
54 /* use Type-0 transaction */
55 __raw_writel(pbca, KS8695_PCI_VA + KS8695_PBCA);
56 } else {
57 /* use Type-1 transaction */
58 __raw_writel(pbca | PBCA_TYPE1, KS8695_PCI_VA + KS8695_PBCA);
59 }
60}
61
62
63/*
64 * The KS8695 datasheet prohibits anything other than 32bit accesses
65 * to the IO registers, so all our configuration must be done with
66 * 32bit operations, and the correct bit masking and shifting.
67 */
68
69static int ks8695_pci_readconfig(struct pci_bus *bus,
70 unsigned int devfn, int where, int size, u32 *value)
71{
72 ks8695_pci_setupconfig(bus->number, devfn, where);
73
74 *value = __raw_readl(KS8695_PCI_VA + KS8695_PBCD);
75
76 switch (size) {
77 case 4:
78 break;
79 case 2:
80 *value = *value >> ((where & 2) * 8);
81 *value &= 0xffff;
82 break;
83 case 1:
84 *value = *value >> ((where & 3) * 8);
85 *value &= 0xff;
86 break;
87 }
88
89 if (pci_cfg_dbg) {
90 printk("read: %d,%08x,%02x,%d: %08x (%08x)\n",
91 bus->number, devfn, where, size, *value,
92 __raw_readl(KS8695_PCI_VA + KS8695_PBCD));
93 }
94
95 return PCIBIOS_SUCCESSFUL;
96}
97
98static int ks8695_pci_writeconfig(struct pci_bus *bus,
99 unsigned int devfn, int where, int size, u32 value)
100{
101 unsigned long tmp;
102
103 if (pci_cfg_dbg) {
104 printk("write: %d,%08x,%02x,%d: %08x\n",
105 bus->number, devfn, where, size, value);
106 }
107
108 ks8695_pci_setupconfig(bus->number, devfn, where);
109
110 switch (size) {
111 case 4:
112 __raw_writel(value, KS8695_PCI_VA + KS8695_PBCD);
113 break;
114 case 2:
115 tmp = __raw_readl(KS8695_PCI_VA + KS8695_PBCD);
116 tmp &= ~(0xffff << ((where & 2) * 8));
117 tmp |= value << ((where & 2) * 8);
118
119 __raw_writel(tmp, KS8695_PCI_VA + KS8695_PBCD);
120 break;
121 case 1:
122 tmp = __raw_readl(KS8695_PCI_VA + KS8695_PBCD);
123 tmp &= ~(0xff << ((where & 3) * 8));
124 tmp |= value << ((where & 3) * 8);
125
126 __raw_writel(tmp, KS8695_PCI_VA + KS8695_PBCD);
127 break;
128 }
129
130 return PCIBIOS_SUCCESSFUL;
131}
132
133static void ks8695_local_writeconfig(int where, u32 value)
134{
135 ks8695_pci_setupconfig(0, 0, where);
136 __raw_writel(value, KS8695_PCI_VA + KS8695_PBCD);
137}
138
139static struct pci_ops ks8695_pci_ops = {
140 .read = ks8695_pci_readconfig,
141 .write = ks8695_pci_writeconfig,
142};
143
144static struct pci_bus *ks8695_pci_scan_bus(int nr, struct pci_sys_data *sys)
145{
146 return pci_scan_bus(sys->busnr, &ks8695_pci_ops, sys);
147}
148
149static struct resource pci_mem = {
150 .name = "PCI Memory space",
151 .start = KS8695_PCIMEM_PA,
152 .end = KS8695_PCIMEM_PA + (KS8695_PCIMEM_SIZE - 1),
153 .flags = IORESOURCE_MEM,
154};
155
156static struct resource pci_io = {
157 .name = "PCI IO space",
158 .start = KS8695_PCIIO_PA,
159 .end = KS8695_PCIIO_PA + (KS8695_PCIIO_SIZE - 1),
160 .flags = IORESOURCE_IO,
161};
162
163static int __init ks8695_pci_setup(int nr, struct pci_sys_data *sys)
164{
165 if (nr > 0)
166 return 0;
167
168 request_resource(&iomem_resource, &pci_mem);
169 request_resource(&ioport_resource, &pci_io);
170
171 sys->resource[0] = &pci_io;
172 sys->resource[1] = &pci_mem;
173 sys->resource[2] = NULL;
174
175 /* Assign and enable processor bridge */
176 ks8695_local_writeconfig(PCI_BASE_ADDRESS_0, KS8695_PCIMEM_PA);
177
178 /* Enable bus-master & Memory Space access */
179 ks8695_local_writeconfig(PCI_COMMAND, PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
180
181 /* Set cache-line size & latency. */
182 ks8695_local_writeconfig(PCI_CACHE_LINE_SIZE, (32 << 8) | (L1_CACHE_BYTES / sizeof(u32)));
183
184 /* Reserve PCI memory space for PCI-AHB resources */
185 if (!request_mem_region(KS8695_PCIMEM_PA, SZ_64M, "PCI-AHB Bridge")) {
186 printk(KERN_ERR "Cannot allocate PCI-AHB Bridge memory.\n");
187 return -EBUSY;
188 }
189
190 return 1;
191}
192
193static inline unsigned int size_mask(unsigned long size)
194{
195 return (~size) + 1;
196}
197
198static int ks8695_pci_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
199{
200 unsigned long pc = instruction_pointer(regs);
201 unsigned long instr = *(unsigned long *)pc;
202 unsigned long cmdstat;
203
204 cmdstat = __raw_readl(KS8695_PCI_VA + KS8695_CRCFCS);
205
206 printk(KERN_ERR "PCI abort: address = 0x%08lx fsr = 0x%03x PC = 0x%08lx LR = 0x%08lx [%s%s%s%s%s]\n",
207 addr, fsr, regs->ARM_pc, regs->ARM_lr,
208 cmdstat & (PCI_STATUS_SIG_TARGET_ABORT << 16) ? "GenTarget" : " ",
209 cmdstat & (PCI_STATUS_REC_TARGET_ABORT << 16) ? "RecvTarget" : " ",
210 cmdstat & (PCI_STATUS_REC_MASTER_ABORT << 16) ? "MasterAbort" : " ",
211 cmdstat & (PCI_STATUS_SIG_SYSTEM_ERROR << 16) ? "SysError" : " ",
212 cmdstat & (PCI_STATUS_DETECTED_PARITY << 16) ? "Parity" : " "
213 );
214
215 __raw_writel(cmdstat, KS8695_PCI_VA + KS8695_CRCFCS);
216
217 /*
218 * If the instruction being executed was a read,
219 * make it look like it read all-ones.
220 */
221 if ((instr & 0x0c100000) == 0x04100000) {
222 int reg = (instr >> 12) & 15;
223 unsigned long val;
224
225 if (instr & 0x00400000)
226 val = 255;
227 else
228 val = -1;
229
230 regs->uregs[reg] = val;
231 regs->ARM_pc += 4;
232 return 0;
233 }
234
235 if ((instr & 0x0e100090) == 0x00100090) {
236 int reg = (instr >> 12) & 15;
237
238 regs->uregs[reg] = -1;
239 regs->ARM_pc += 4;
240 return 0;
241 }
242
243 return 1;
244}
245
246static void __init ks8695_pci_preinit(void)
247{
248 /* stage 1 initialization, subid, subdevice = 0x0001 */
249 __raw_writel(0x00010001, KS8695_PCI_VA + KS8695_CRCSID);
250
251 /* stage 2 initialization */
252 /* prefetch limits with 16 words, retry enable */
253 __raw_writel(0x40000000, KS8695_PCI_VA + KS8695_PBCS);
254
255 /* configure memory mapping */
256 __raw_writel(KS8695_PCIMEM_PA, KS8695_PCI_VA + KS8695_PMBA);
257 __raw_writel(size_mask(KS8695_PCIMEM_SIZE), KS8695_PCI_VA + KS8695_PMBAM);
258 __raw_writel(KS8695_PCIMEM_PA, KS8695_PCI_VA + KS8695_PMBAT);
259 __raw_writel(0, KS8695_PCI_VA + KS8695_PMBAC);
260
261 /* configure IO mapping */
262 __raw_writel(KS8695_PCIIO_PA, KS8695_PCI_VA + KS8695_PIOBA);
263 __raw_writel(size_mask(KS8695_PCIIO_SIZE), KS8695_PCI_VA + KS8695_PIOBAM);
264 __raw_writel(KS8695_PCIIO_PA, KS8695_PCI_VA + KS8695_PIOBAT);
265 __raw_writel(0, KS8695_PCI_VA + KS8695_PIOBAC);
266
267 /* hook in fault handlers */
268 hook_fault_code(8, ks8695_pci_fault, SIGBUS, "external abort on non-linefetch");
269 hook_fault_code(10, ks8695_pci_fault, SIGBUS, "external abort on non-linefetch");
270}
271
272static void ks8695_show_pciregs(void)
273{
274 if (!pci_dbg)
275 return;
276
277 printk(KERN_INFO "PCI: CRCFID = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_CRCFID));
278 printk(KERN_INFO "PCI: CRCFCS = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_CRCFCS));
279 printk(KERN_INFO "PCI: CRCFRV = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_CRCFRV));
280 printk(KERN_INFO "PCI: CRCFLT = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_CRCFLT));
281 printk(KERN_INFO "PCI: CRCBMA = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_CRCBMA));
282 printk(KERN_INFO "PCI: CRCSID = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_CRCSID));
283 printk(KERN_INFO "PCI: CRCFIT = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_CRCFIT));
284
285 printk(KERN_INFO "PCI: PBM = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_PBM));
286 printk(KERN_INFO "PCI: PBCS = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_PBCS));
287
288 printk(KERN_INFO "PCI: PMBA = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_PMBA));
289 printk(KERN_INFO "PCI: PMBAC = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_PMBAC));
290 printk(KERN_INFO "PCI: PMBAM = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_PMBAM));
291 printk(KERN_INFO "PCI: PMBAT = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_PMBAT));
292
293 printk(KERN_INFO "PCI: PIOBA = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_PIOBA));
294 printk(KERN_INFO "PCI: PIOBAC = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_PIOBAC));
295 printk(KERN_INFO "PCI: PIOBAM = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_PIOBAM));
296 printk(KERN_INFO "PCI: PIOBAT = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_PIOBAT));
297}
298
299
300static struct hw_pci ks8695_pci __initdata = {
301 .nr_controllers = 1,
302 .preinit = ks8695_pci_preinit,
303 .setup = ks8695_pci_setup,
304 .scan = ks8695_pci_scan_bus,
305 .postinit = NULL,
306 .swizzle = pci_std_swizzle,
307 .map_irq = NULL,
308};
309
310void __init ks8695_init_pci(struct ks8695_pci_cfg *cfg)
311{
312 if (__raw_readl(KS8695_PCI_VA + KS8695_CRCFRV) & CFRV_GUEST) {
313 printk("PCI: KS8695 in guest mode, not initialising\n");
314 return;
315 }
316
317 printk(KERN_INFO "PCI: Initialising\n");
318 ks8695_show_pciregs();
319
320 /* set Mode */
321 __raw_writel(cfg->mode << 29, KS8695_PCI_VA + KS8695_PBM);
322
323 ks8695_pci.map_irq = cfg->map_irq; /* board-specific map_irq method */
324
325 pci_common_init(&ks8695_pci);
326}
diff --git a/arch/arm/mach-ks8695/time.c b/arch/arm/mach-ks8695/time.c
index d2c86e4a72eb..02f766b3121d 100644
--- a/arch/arm/mach-ks8695/time.c
+++ b/arch/arm/mach-ks8695/time.c
@@ -70,10 +70,7 @@ static unsigned long ks8695_gettimeoffset (void)
70 */ 70 */
71static irqreturn_t ks8695_timer_interrupt(int irq, void *dev_id) 71static irqreturn_t ks8695_timer_interrupt(int irq, void *dev_id)
72{ 72{
73 write_seqlock(&xtime_lock);
74 timer_tick(); 73 timer_tick();
75 write_sequnlock(&xtime_lock);
76
77 return IRQ_HANDLED; 74 return IRQ_HANDLED;
78} 75}
79 76