1 /*
2  * Marubun MR-SHPC-01 PCMCIA controller device driver
3  *
4  * (c) 2007 Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19  * MA 02111-1307 USA
20  *
21  */
22 
23 #include <common.h>
24 #include <config.h>
25 #include <pcmcia.h>
26 #include <asm/io.h>
27 
28 #undef CONFIG_PCMCIA
29 
30 #if defined(CONFIG_CMD_PCMCIA)
31 #define	CONFIG_PCMCIA
32 #endif
33 
34 #if defined(CONFIG_CMD_IDE)
35 #define	CONFIG_PCMCIA
36 #endif
37 
38 #if defined(CONFIG_PCMCIA)
39 
40 /* MR-SHPC-01 register */
41 #define MRSHPC_MODE	(CFG_MARUBUN_MRSHPC + 4)
42 #define MRSHPC_OPTION   (CFG_MARUBUN_MRSHPC + 6)
43 #define MRSHPC_CSR      (CFG_MARUBUN_MRSHPC + 8)
44 #define MRSHPC_ISR      (CFG_MARUBUN_MRSHPC + 10)
45 #define MRSHPC_ICR      (CFG_MARUBUN_MRSHPC + 12)
46 #define MRSHPC_CPWCR    (CFG_MARUBUN_MRSHPC + 14)
47 #define MRSHPC_MW0CR1   (CFG_MARUBUN_MRSHPC + 16)
48 #define MRSHPC_MW1CR1   (CFG_MARUBUN_MRSHPC + 18)
49 #define MRSHPC_IOWCR1   (CFG_MARUBUN_MRSHPC + 20)
50 #define MRSHPC_MW0CR2   (CFG_MARUBUN_MRSHPC + 22)
51 #define MRSHPC_MW1CR2   (CFG_MARUBUN_MRSHPC + 24)
52 #define MRSHPC_IOWCR2   (CFG_MARUBUN_MRSHPC + 26)
53 #define MRSHPC_CDCR     (CFG_MARUBUN_MRSHPC + 28)
54 #define MRSHPC_PCIC_INFO (CFG_MARUBUN_MRSHPC + 30)
55 
56 int pcmcia_on (void)
57 {
58 	printf("Enable PCMCIA " PCMCIA_SLOT_MSG "\n");
59 
60 	/* Init */
61 	outw( 0x0000 , MRSHPC_MODE );
62 
63 	if ((inw(MRSHPC_CSR) & 0x000c) == 0){	/* if card detect is true */
64 		if ((inw(MRSHPC_CSR) & 0x0080) == 0){
65 			outw(0x0674 ,MRSHPC_CPWCR);  /* Card Vcc is 3.3v? */
66 		}else{
67 			outw(0x0678 ,MRSHPC_CPWCR);  /* Card Vcc is 5V */
68 		}
69 		udelay( 100000 );   /* wait for power on */
70 	}else{
71 		return 1;
72 	}
73 	/*
74 	 *	PC-Card window open
75 	 *	flag == COMMON/ATTRIBUTE/IO
76 	 */
77 	/* common window open */
78 	outw(0x8a84,MRSHPC_MW0CR1); /* window 0xb8400000 */
79 	if ((inw(MRSHPC_CSR) & 0x4000) != 0)
80 		outw(0x0b00,MRSHPC_MW0CR2); /* common mode & bus width 16bit SWAP = 1 */
81 	else
82 		outw(0x0300,MRSHPC_MW0CR2); /* common mode & bus width 16bit SWAP = 0 */
83 
84 	/* attribute window open */
85 	outw(0x8a85,MRSHPC_MW1CR1); /* window 0xb8500000 */
86 	if ((inw(MRSHPC_CSR) & 0x4000) != 0)
87 		outw(0x0a00,MRSHPC_MW1CR2); /* attribute mode & bus width 16bit SWAP = 1 */
88 	else
89 		outw(0x0200,MRSHPC_MW1CR2); /* attribute mode & bus width 16bit SWAP = 0 */
90 
91 	/* I/O window open */
92 	outw(0x8a86,MRSHPC_IOWCR1); /* I/O window 0xb8600000 */
93 	outw(0x0008,MRSHPC_CDCR);   /* I/O card mode */
94 	if ((inw(MRSHPC_CSR) & 0x4000) != 0)
95 		outw(0x0a00,MRSHPC_IOWCR2); /* bus width 16bit SWAP = 1 */
96 	else
97 		outw(0x0200,MRSHPC_IOWCR2); /* bus width 16bit SWAP = 0 */
98 
99 	outw(0x0000,MRSHPC_ISR);
100 	outw(0x2000,MRSHPC_ICR);
101 	outb(0x00,(CFG_MARUBUN_MW2 + 0x206));
102 	outb(0x42,(CFG_MARUBUN_MW2 + 0x200));
103 
104 	return 0;
105 }
106 
107 int pcmcia_off (void)
108 {
109 	printf ("Disable PCMCIA " PCMCIA_SLOT_MSG "\n");
110 
111 	return 0;
112 }
113 
114 #endif /* CONFIG_PCMCIA */
115