[brcm63xx] only register fallback sprom and enable PCI if we actually have support...
[openwrt.git] / target / linux / brcm63xx / files / arch / mips / bcm63xx / dev-pcmcia.c
1 /*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
7 */
8
9 #include <linux/init.h>
10 #include <linux/kernel.h>
11 #include <asm/bootinfo.h>
12 #include <linux/platform_device.h>
13 #include <bcm63xx_cs.h>
14 #include <bcm63xx_cpu.h>
15 #include <bcm63xx_dev_pcmcia.h>
16 #include <bcm63xx_io.h>
17 #include <bcm63xx_regs.h>
18
19 static struct resource pcmcia_resources[] = {
20 /* pcmcia registers */
21 {
22 .start = -1, /* filled at runtime */
23 .end = -1, /* filled at runtime */
24 .flags = IORESOURCE_MEM,
25 },
26
27 /* pcmcia memory zone resources */
28 {
29 .start = BCM_PCMCIA_COMMON_BASE_PA,
30 .end = BCM_PCMCIA_COMMON_END_PA,
31 .flags = IORESOURCE_MEM,
32 },
33 {
34 .start = BCM_PCMCIA_ATTR_BASE_PA,
35 .end = BCM_PCMCIA_ATTR_END_PA,
36 .flags = IORESOURCE_MEM,
37 },
38 {
39 .start = BCM_PCMCIA_IO_BASE_PA,
40 .end = BCM_PCMCIA_IO_END_PA,
41 .flags = IORESOURCE_MEM,
42 },
43
44 /* PCMCIA irq */
45 {
46 .start = -1, /* filled at runtime */
47 .flags = IORESOURCE_IRQ,
48 },
49
50 /* declare PCMCIA IO resource also */
51 {
52 .start = BCM_PCMCIA_IO_BASE_PA,
53 .end = BCM_PCMCIA_IO_END_PA,
54 .flags = IORESOURCE_IO,
55 },
56 };
57
58 static struct bcm63xx_pcmcia_platform_data pd;
59
60 static struct platform_device bcm63xx_pcmcia_device = {
61 .name = "bcm63xx_pcmcia",
62 .id = 0,
63 .num_resources = ARRAY_SIZE(pcmcia_resources),
64 .resource = pcmcia_resources,
65 .dev = {
66 .platform_data = &pd,
67 },
68 };
69
70 static int __init config_pcmcia_cs(unsigned int cs,
71 u32 base, unsigned int size)
72 {
73 int ret;
74
75 ret = bcm63xx_set_cs_status(cs, 0);
76 if (!ret)
77 ret = bcm63xx_set_cs_base(cs, base, size);
78 if (!ret)
79 ret = bcm63xx_set_cs_status(cs, 1);
80 return ret;
81 }
82
83 static const __initdata unsigned int pcmcia_cs[3][3] = {
84 /* cs, base address, size */
85 { MPI_CS_PCMCIA_COMMON, BCM_PCMCIA_COMMON_BASE_PA,
86 BCM_PCMCIA_COMMON_SIZE },
87
88 { MPI_CS_PCMCIA_ATTR, BCM_PCMCIA_ATTR_BASE_PA,
89 BCM_PCMCIA_ATTR_SIZE },
90
91 { MPI_CS_PCMCIA_IO, BCM_PCMCIA_IO_BASE_PA,
92 BCM_PCMCIA_IO_SIZE },
93 };
94
95 int __init bcm63xx_pcmcia_register(void)
96 {
97 int ret, i;
98
99 if (!BCMCPU_IS_6348() && !BCMCPU_IS_6358())
100 return 0;
101
102 /* use correct pcmcia ready gpio depending on processor */
103 switch (bcm63xx_get_cpu_id()) {
104 case BCM6348_CPU_ID:
105 pd.ready_gpio = 22;
106 break;
107
108 case BCM6358_CPU_ID:
109 pd.ready_gpio = 22;
110 break;
111
112 default:
113 return -ENODEV;
114 }
115
116 pcmcia_resources[0].start = bcm63xx_regset_address(RSET_PCMCIA);
117 pcmcia_resources[0].end = pcmcia_resources[0].start;
118 pcmcia_resources[0].end += RSET_PCMCIA_SIZE - 1;
119 pcmcia_resources[4].start = bcm63xx_get_irq_number(IRQ_PCMCIA);
120
121 /* configure pcmcia chip selects */
122 for (i = 0; i < 3; i++) {
123 ret = config_pcmcia_cs(pcmcia_cs[i][0],
124 pcmcia_cs[i][1],
125 pcmcia_cs[i][2]);
126 if (ret)
127 goto out_err;
128 }
129
130 return platform_device_register(&bcm63xx_pcmcia_device);
131
132 out_err:
133 printk(KERN_ERR "unable to set pcmcia chip select");
134 return ret;
135 }
This page took 0.049063 seconds and 5 git commands to generate.