37 #include <linux/module.h>
39 #include <linux/types.h>
40 #include <linux/fcntl.h>
41 #include <linux/string.h>
43 #include <linux/kernel.h>
44 #include <linux/errno.h>
50 #include <linux/bitops.h>
63 #define pcmcia_info(args...) printk(KERN_INFO "m8xx_pcmcia: "args)
64 #define pcmcia_error(args...) printk(KERN_ERR "m8xx_pcmcia: "args)
66 static const char *
version =
"Version 0.06, Aug 2005";
69 #if !defined(CONFIG_PCMCIA_SLOT_A) && !defined(CONFIG_PCMCIA_SLOT_B)
72 #if defined(CONFIG_RPXCLASSIC) || defined(CONFIG_RPXLITE)
73 #define CONFIG_PCMCIA_SLOT_B
74 #define CONFIG_BD_IS_MHZ
79 #define CONFIG_PCMCIA_SLOT_A
80 #define CONFIG_BD_IS_MHZ
85 #if defined(CONFIG_MPC860T) || defined(CONFIG_MPC860) || defined(CONFIG_MPC821)
86 #define CONFIG_PCMCIA_SLOT_A
88 #define CONFIG_PCMCIA_SLOT_B
92 #if defined(CONFIG_MPC885ADS)
93 #define CONFIG_PCMCIA_SLOT_A
94 #define PCMCIA_GLITCHY_CD
99 #define CONFIG_PCMCIA_SLOT_A
100 #define CONFIG_PCMCIA_SLOT_B
105 #if defined(CONFIG_PCMCIA_SLOT_A) && defined(CONFIG_PCMCIA_SLOT_B)
107 #define PCMCIA_SOCKETS_NO 2
109 #define PCMCIA_MEM_WIN_NO 2
110 #define PCMCIA_IO_WIN_NO 2
111 #define PCMCIA_SLOT_MSG "SLOT_A and SLOT_B"
113 #elif defined(CONFIG_PCMCIA_SLOT_A) || defined(CONFIG_PCMCIA_SLOT_B)
115 #define PCMCIA_SOCKETS_NO 1
117 #define PCMCIA_MEM_WIN_NO 5
118 #define PCMCIA_IO_WIN_NO 2
122 #ifdef CONFIG_PCMCIA_SLOT_A
124 #define PCMCIA_SLOT_MSG "SLOT_A"
127 #define PCMCIA_SLOT_MSG "SLOT_B"
131 #error m8xx_pcmcia: Bad configuration!
136 #define PCMCIA_MEM_WIN_BASE 0xe0000000
137 #define PCMCIA_MEM_WIN_SIZE 0x04000000
138 #define PCMCIA_IO_WIN_BASE _IO_BASE
141 static int pcmcia_schlvl;
145 #define PCMCIA_SOCKET_KEY_5V 1
146 #define PCMCIA_SOCKET_KEY_LV 2
149 static u32 *m8xx_pgcrx[2];
174 #define M8XX_PCMCIA_VS1(slot) (0x80000000 >> (slot << 4))
175 #define M8XX_PCMCIA_VS2(slot) (0x40000000 >> (slot << 4))
176 #define M8XX_PCMCIA_VS_MASK(slot) (0xc0000000 >> (slot << 4))
177 #define M8XX_PCMCIA_VS_SHIFT(slot) (30 - (slot << 4))
179 #define M8XX_PCMCIA_WP(slot) (0x20000000 >> (slot << 4))
180 #define M8XX_PCMCIA_CD2(slot) (0x10000000 >> (slot << 4))
181 #define M8XX_PCMCIA_CD1(slot) (0x08000000 >> (slot << 4))
182 #define M8XX_PCMCIA_BVD2(slot) (0x04000000 >> (slot << 4))
183 #define M8XX_PCMCIA_BVD1(slot) (0x02000000 >> (slot << 4))
184 #define M8XX_PCMCIA_RDY(slot) (0x01000000 >> (slot << 4))
185 #define M8XX_PCMCIA_RDY_L(slot) (0x00800000 >> (slot << 4))
186 #define M8XX_PCMCIA_RDY_H(slot) (0x00400000 >> (slot << 4))
187 #define M8XX_PCMCIA_RDY_R(slot) (0x00200000 >> (slot << 4))
188 #define M8XX_PCMCIA_RDY_F(slot) (0x00100000 >> (slot << 4))
189 #define M8XX_PCMCIA_MASK(slot) (0xFFFF0000 >> (slot << 4))
191 #define M8XX_PCMCIA_POR_VALID 0x00000001
192 #define M8XX_PCMCIA_POR_WRPROT 0x00000002
193 #define M8XX_PCMCIA_POR_ATTRMEM 0x00000010
194 #define M8XX_PCMCIA_POR_IO 0x00000018
195 #define M8XX_PCMCIA_POR_16BIT 0x00000040
197 #define M8XX_PGCRX(slot) m8xx_pgcrx[slot]
199 #define M8XX_PGCRX_CXOE 0x00000080
200 #define M8XX_PGCRX_CXRESET 0x00000040
204 #define PCMCIA_EVENTS_MAX 5
236 #define M8XX_SIZES_NO 32
239 0x00000001, 0x00000002, 0x00000008, 0x00000004,
240 0x00000080, 0x00000040, 0x00000010, 0x00000020,
241 0x00008000, 0x00004000, 0x00001000, 0x00002000,
242 0x00000100, 0x00000200, 0x00000800, 0x00000400,
244 0x0fffffff, 0xffffffff, 0xffffffff, 0xffffffff,
245 0x01000000, 0x02000000, 0xffffffff, 0x04000000,
246 0x00010000, 0x00020000, 0x00080000, 0x00040000,
247 0x00800000, 0x00400000, 0x00100000, 0x00200000
254 #define PCMCIA_BMT_LIMIT (15*4)
262 #if defined(CONFIG_RPXCLASSIC) || defined(CONFIG_RPXLITE)
269 #define PCMCIA_BOARD_MSG "RPX CLASSIC or RPX LITE"
271 #undef PCMCIA_BMT_LIMIT
272 #define PCMCIA_BMT_LIMIT (6*8)
274 static int voltage_set(
int slot,
int vcc,
int vpp)
282 reg |= BCSR1_PCVCTL4;
285 reg |= BCSR1_PCVCTL5;
297 reg |= BCSR1_PCVCTL6;
302 reg |= BCSR1_PCVCTL7;
307 if (!((vcc == 50) || (vcc == 0)))
313 in_be32(((
u32 *) RPX_CSR_ADDR)) & ~(BCSR1_PCVCTL4 |
325 #define socket_get(_slot_) PCMCIA_SOCKET_KEY_5V
326 #define hardware_enable(_slot_)
327 #define hardware_disable(_slot_)
333 #if defined(CONFIG_FADS)
335 #define PCMCIA_BOARD_MSG "FADS"
337 static int voltage_set(
int slot,
int vcc,
int vpp)
345 reg |= BCSR1_PCCVCC0;
348 reg |= BCSR1_PCCVCC1;
360 reg |= BCSR1_PCCVPP1;
365 if ((vcc == 33) || (vcc == 50))
366 reg |= BCSR1_PCCVPP0;
375 in_be32((
u32 *) BCSR1) & ~(BCSR1_PCCVCC_MASK |
384 #define socket_get(_slot_) PCMCIA_SOCKET_KEY_5V
386 static void hardware_enable(
int slot)
391 static void hardware_disable(
int slot)
400 #if defined(CONFIG_MPC885ADS)
402 #define PCMCIA_BOARD_MSG "MPC885ADS"
403 #define socket_get(_slot_) PCMCIA_SOCKET_KEY_5V
405 static inline void hardware_enable(
int slot)
410 static inline void hardware_disable(
int slot)
415 static inline int voltage_set(
int slot,
int vcc,
int vpp)
425 #if defined(CONFIG_MBX)
427 #define PCMCIA_BOARD_MSG "MBX"
429 static int voltage_set(
int slot,
int vcc,
int vpp)
457 if ((vcc == 33) || (vcc == 50))
467 in_8((
u8 *) MBX_CSR2_ADDR) & ~(CSR2_VCC_MASK | CSR2_VPP_MASK));
470 out_8((
u8 *) MBX_CSR2_ADDR,
in_8((
u8 *) MBX_CSR2_ADDR) | reg);
475 #define socket_get(_slot_) PCMCIA_SOCKET_KEY_5V
476 #define hardware_enable(_slot_)
477 #define hardware_disable(_slot_)
481 #if defined(CONFIG_PRxK)
482 #include <asm/cpld.h>
483 extern volatile fpga_pc_regs *fpga_pc;
485 #define PCMCIA_BOARD_MSG "MPC855T"
487 static int voltage_set(
int slot,
int vcc,
int vpp)
491 cpld_regs *ccpld = get_cpld();
497 reg |= PCMCIA_VCC_33;
500 reg |= PCMCIA_VCC_50;
512 reg |= PCMCIA_VPP_VCC;
517 if ((vcc == 33) || (vcc == 50))
518 reg |= PCMCIA_VPP_12;
525 reg = reg >> (slot << 2);
526 regread =
in_8(&ccpld->fpga_pc_ctl);
528 (regread & ((PCMCIA_VCC_MASK | PCMCIA_VPP_MASK) >> (slot << 2)))) {
531 regread & ~((PCMCIA_VCC_MASK | PCMCIA_VPP_MASK) >>
533 out_8(&ccpld->fpga_pc_ctl, reg | regread);
540 #define socket_get(_slot_) PCMCIA_SOCKET_KEY_LV
541 #define hardware_enable(_slot_)
542 #define hardware_disable(_slot_)
546 static u32 pending_events[PCMCIA_SOCKETS_NO];
556 pr_debug(
"m8xx_pcmcia: Interrupt!\n");
559 pscr =
in_be32(&pcmcia->pcmc_pscr);
560 pipr =
in_be32(&pcmcia->pcmc_pipr);
561 per =
in_be32(&pcmcia->pcmc_per);
563 for (i = 0; i < PCMCIA_SOCKETS_NO; i++) {
583 events &= ~SS_DETECT;
585 #ifdef PCMCIA_GLITCHY_CD
592 if ((events & SS_DETECT) &&
596 events &= ~SS_DETECT;
605 pr_debug(
"m8xx_pcmcia: slot %u: events = 0x%02x, pscr = 0x%08x, "
606 "pipr = 0x%08x\n", i, events, pscr, pipr);
609 spin_lock(&pending_event_lock);
611 spin_unlock(&pending_event_lock);
632 pr_debug(
"m8xx_pcmcia: Interrupt done.\n");
642 if (m8xx_size_to_gray[k] == size)
645 if ((k == M8XX_SIZES_NO) || (m8xx_size_to_gray[k] == -1))
653 u32 reg, clocks, psst, psl, psht;
679 clocks = ((bus_freq / 1000) * ns) / 1000;
680 clocks = (clocks *
ADJ) / (100 * 1000);
682 printk(
"Max access time limit reached\n");
688 psl = (clocks * 5) / 7;
690 psst += clocks - (psst + psht + psl);
703 unsigned int pipr,
reg;
704 pcmconf8xx_t *pcmcia = s->
pcmcia;
706 pipr =
in_be32(&pcmcia->pcmc_pipr);
806 pr_debug(
"m8xx_pcmcia: GetStatus(%d) = %#2.2x\n", lsock, *value);
817 pcmconf8xx_t *pcmcia =
socket[0].pcmcia;
819 pr_debug(
"m8xx_pcmcia: SetSocket(%d, flags %#3.3x, Vcc %d, Vpp %d, "
820 "io_irq %d, csc_mask %#2.2x)\n", lsock, state->
flags,
824 if (voltage_set(lsock, state->
Vcc, state->
Vpp))
844 if (state->
Vcc || state->
Vpp)
886 mk_int_int_mask(s->
hwirq) << 24);
944 spin_unlock_irqrestore(&events_lock, flags);
959 unsigned int reg, winnr;
960 pcmconf8xx_t *pcmcia = s->
pcmcia;
962 #define M8XX_SIZE (io->stop - io->start + 1)
963 #define M8XX_BASE (PCMCIA_IO_WIN_BASE + io->start)
965 pr_debug(
"m8xx_pcmcia: SetIOMap(%d, %d, %#2.2x, %d ns, "
966 "%#4.4llx-%#4.4llx)\n", lsock, io->
map, io->
flags,
968 (
unsigned long long)io->
stop);
970 if ((io->
map >= PCMCIA_IO_WIN_NO) || (io->
start > 0xffff)
974 if ((reg = m8xx_get_graycode(M8XX_SIZE)) == -1)
979 pr_debug(
"m8xx_pcmcia: io->flags & MAP_ACTIVE\n");
981 winnr = (PCMCIA_MEM_WIN_NO * PCMCIA_SOCKETS_NO)
982 + (lsock * PCMCIA_IO_WIN_NO) + io->
map;
986 w = (
void *)&pcmcia->pcmc_pbr0;
1009 pr_debug(
"m8xx_pcmcia: Socket %u: Mapped io window %u at "
1010 "%#8.8x, OR = %#8.8x.\n", lsock, io->
map, w->
br, w->
or);
1013 winnr = (PCMCIA_MEM_WIN_NO * PCMCIA_SOCKETS_NO)
1014 + (lsock * PCMCIA_IO_WIN_NO) + io->
map;
1018 w = (
void *)&pcmcia->pcmc_pbr0;
1024 pr_debug(
"m8xx_pcmcia: Socket %u: Unmapped io window %u at "
1025 "%#8.8x, OR = %#8.8x.\n", lsock, io->
map, w->
br, w->
or);
1031 pr_debug(
"m8xx_pcmcia: SetIOMap exit\n");
1043 unsigned int reg, winnr;
1044 pcmconf8xx_t *pcmcia = s->
pcmcia;
1046 pr_debug(
"m8xx_pcmcia: SetMemMap(%d, %d, %#2.2x, %d ns, "
1047 "%#5.5llx, %#5.5x)\n", lsock, mem->
map, mem->
flags,
1051 if ((mem->
map >= PCMCIA_MEM_WIN_NO)
1064 winnr = (lsock * PCMCIA_MEM_WIN_NO) + mem->
map;
1068 w = (
void *)&pcmcia->pcmc_pbr0;
1089 pr_debug(
"m8xx_pcmcia: Socket %u: Mapped memory window %u at %#8.8x, "
1090 "OR = %#8.8x.\n", lsock, mem->
map, w->
br, w->
or);
1099 pr_debug(
"m8xx_pcmcia: SetMemMap(%d, %d, %#2.2x, %d ns, "
1100 "%#5.5llx, %#5.5x)\n", lsock, mem->
map, mem->
flags,
1120 pr_debug(
"m8xx_pcmcia: sock_init(%d)\n", s);
1123 for (i = 0; i < PCMCIA_IO_WIN_NO; i++) {
1125 m8xx_set_io_map(sock, &io);
1127 for (i = 0; i < PCMCIA_MEM_WIN_NO; i++) {
1129 m8xx_set_mem_map(sock, &mem);
1142 .init = m8xx_sock_init,
1143 .suspend = m8xx_sock_suspend,
1144 .get_status = m8xx_get_status,
1145 .set_socket = m8xx_set_socket,
1146 .set_io_map = m8xx_set_io_map,
1147 .set_mem_map = m8xx_set_mem_map,
1153 unsigned int i,
m, hwirq;
1165 hwirq =
irq_map[pcmcia_schlvl].hwirq;
1166 if (pcmcia_schlvl < 0) {
1171 m8xx_pgcrx[0] = &pcmcia->pcmc_pgcra;
1172 m8xx_pgcrx[1] = &pcmcia->pcmc_pgcrb;
1174 pcmcia_info(PCMCIA_BOARD_MSG
" using " PCMCIA_SLOT_MSG
1175 " with IRQ %u (%d). \n", pcmcia_schlvl, hwirq);
1187 w = (
void *)&pcmcia->pcmc_pbr0;
1201 for (i = 0; i < PCMCIA_SOCKETS_NO; i++) {
1202 for (m = 0; m < PCMCIA_MEM_WIN_NO; m++) {
1205 * (m + i * PCMCIA_MEM_WIN_NO)));
1214 voltage_set(0, 0, 0);
1215 voltage_set(1, 0, 0);
1221 for (i = 0; i < PCMCIA_SOCKETS_NO; i++) {
1226 socket[
i].socket.irq_mask = 0x000;
1227 socket[
i].socket.map_size = 0x1000;
1228 socket[
i].socket.io_offset = 0;
1229 socket[
i].socket.pci_irq = pcmcia_schlvl;
1240 for (i = 0; i < PCMCIA_SOCKETS_NO; i++) {
1253 pcmconf8xx_t *pcmcia =
socket[0].pcmcia;
1255 for (i = 0; i < PCMCIA_SOCKETS_NO; i++) {
1256 w = (
void *)&pcmcia->pcmc_pbr0;
1266 for (m = 0; m < PCMCIA_MEM_WIN_NO; m++) {
1272 voltage_set(i, 0, 0);
1275 hardware_disable(i);
1277 for (i = 0; i < PCMCIA_SOCKETS_NO; i++)
1286 static const struct of_device_id m8xx_pcmcia_match[] = {
1289 .compatible =
"fsl,pq-pcmcia",
1300 .of_match_table = m8xx_pcmcia_match,
1302 .probe = m8xx_probe,
1303 .remove = m8xx_remove,