Nobuhiro Iwamatsu | 770395e | 2007-11-25 02:39:31 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Marubun MR-SHPC-01 PCMCIA controller device driver |
| 3 | * |
| 4 | * (c) 2007 Nobuhiro Iwamatsu <iwamatsu@nigauri.org> |
| 5 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
Wolfgang Denk | 0a5c214 | 2007-12-27 01:52:50 +0100 | [diff] [blame] | 7 | */ |
Nobuhiro Iwamatsu | 770395e | 2007-11-25 02:39:31 +0900 | [diff] [blame] | 8 | |
| 9 | #include <common.h> |
| 10 | #include <config.h> |
| 11 | #include <pcmcia.h> |
| 12 | #include <asm/io.h> |
| 13 | |
Nobuhiro Iwamatsu | 74eca5b | 2008-01-15 17:48:13 +0900 | [diff] [blame] | 14 | #undef CONFIG_PCMCIA |
| 15 | |
| 16 | #if defined(CONFIG_CMD_PCMCIA) |
Nobuhiro Iwamatsu | 770395e | 2007-11-25 02:39:31 +0900 | [diff] [blame] | 17 | #define CONFIG_PCMCIA |
| 18 | #endif |
| 19 | |
Jean-Christophe PLAGNIOL-VILLARD | 1ec80fa | 2008-05-18 19:09:50 +0200 | [diff] [blame] | 20 | #if defined(CONFIG_CMD_IDE) |
Nobuhiro Iwamatsu | 770395e | 2007-11-25 02:39:31 +0900 | [diff] [blame] | 21 | #define CONFIG_PCMCIA |
| 22 | #endif |
| 23 | |
Jean-Christophe PLAGNIOL-VILLARD | 1ec80fa | 2008-05-18 19:09:50 +0200 | [diff] [blame] | 24 | #if defined(CONFIG_PCMCIA) |
Nobuhiro Iwamatsu | 770395e | 2007-11-25 02:39:31 +0900 | [diff] [blame] | 25 | |
| 26 | /* MR-SHPC-01 register */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 27 | #define MRSHPC_MODE (CONFIG_SYS_MARUBUN_MRSHPC + 4) |
| 28 | #define MRSHPC_OPTION (CONFIG_SYS_MARUBUN_MRSHPC + 6) |
| 29 | #define MRSHPC_CSR (CONFIG_SYS_MARUBUN_MRSHPC + 8) |
| 30 | #define MRSHPC_ISR (CONFIG_SYS_MARUBUN_MRSHPC + 10) |
| 31 | #define MRSHPC_ICR (CONFIG_SYS_MARUBUN_MRSHPC + 12) |
| 32 | #define MRSHPC_CPWCR (CONFIG_SYS_MARUBUN_MRSHPC + 14) |
| 33 | #define MRSHPC_MW0CR1 (CONFIG_SYS_MARUBUN_MRSHPC + 16) |
| 34 | #define MRSHPC_MW1CR1 (CONFIG_SYS_MARUBUN_MRSHPC + 18) |
| 35 | #define MRSHPC_IOWCR1 (CONFIG_SYS_MARUBUN_MRSHPC + 20) |
| 36 | #define MRSHPC_MW0CR2 (CONFIG_SYS_MARUBUN_MRSHPC + 22) |
| 37 | #define MRSHPC_MW1CR2 (CONFIG_SYS_MARUBUN_MRSHPC + 24) |
| 38 | #define MRSHPC_IOWCR2 (CONFIG_SYS_MARUBUN_MRSHPC + 26) |
| 39 | #define MRSHPC_CDCR (CONFIG_SYS_MARUBUN_MRSHPC + 28) |
| 40 | #define MRSHPC_PCIC_INFO (CONFIG_SYS_MARUBUN_MRSHPC + 30) |
Nobuhiro Iwamatsu | 770395e | 2007-11-25 02:39:31 +0900 | [diff] [blame] | 41 | |
| 42 | int pcmcia_on (void) |
| 43 | { |
| 44 | printf("Enable PCMCIA " PCMCIA_SLOT_MSG "\n"); |
| 45 | |
| 46 | /* Init */ |
| 47 | outw( 0x0000 , MRSHPC_MODE ); |
| 48 | |
| 49 | if ((inw(MRSHPC_CSR) & 0x000c) == 0){ /* if card detect is true */ |
| 50 | if ((inw(MRSHPC_CSR) & 0x0080) == 0){ |
| 51 | outw(0x0674 ,MRSHPC_CPWCR); /* Card Vcc is 3.3v? */ |
| 52 | }else{ |
| 53 | outw(0x0678 ,MRSHPC_CPWCR); /* Card Vcc is 5V */ |
| 54 | } |
| 55 | udelay( 100000 ); /* wait for power on */ |
| 56 | }else{ |
| 57 | return 1; |
| 58 | } |
| 59 | /* |
| 60 | * PC-Card window open |
| 61 | * flag == COMMON/ATTRIBUTE/IO |
| 62 | */ |
| 63 | /* common window open */ |
| 64 | outw(0x8a84,MRSHPC_MW0CR1); /* window 0xb8400000 */ |
| 65 | if ((inw(MRSHPC_CSR) & 0x4000) != 0) |
| 66 | outw(0x0b00,MRSHPC_MW0CR2); /* common mode & bus width 16bit SWAP = 1 */ |
| 67 | else |
| 68 | outw(0x0300,MRSHPC_MW0CR2); /* common mode & bus width 16bit SWAP = 0 */ |
Wolfgang Denk | 0a5c214 | 2007-12-27 01:52:50 +0100 | [diff] [blame] | 69 | |
Nobuhiro Iwamatsu | 770395e | 2007-11-25 02:39:31 +0900 | [diff] [blame] | 70 | /* attribute window open */ |
| 71 | outw(0x8a85,MRSHPC_MW1CR1); /* window 0xb8500000 */ |
| 72 | if ((inw(MRSHPC_CSR) & 0x4000) != 0) |
| 73 | outw(0x0a00,MRSHPC_MW1CR2); /* attribute mode & bus width 16bit SWAP = 1 */ |
| 74 | else |
| 75 | outw(0x0200,MRSHPC_MW1CR2); /* attribute mode & bus width 16bit SWAP = 0 */ |
Wolfgang Denk | 0a5c214 | 2007-12-27 01:52:50 +0100 | [diff] [blame] | 76 | |
Nobuhiro Iwamatsu | 770395e | 2007-11-25 02:39:31 +0900 | [diff] [blame] | 77 | /* I/O window open */ |
| 78 | outw(0x8a86,MRSHPC_IOWCR1); /* I/O window 0xb8600000 */ |
| 79 | outw(0x0008,MRSHPC_CDCR); /* I/O card mode */ |
| 80 | if ((inw(MRSHPC_CSR) & 0x4000) != 0) |
| 81 | outw(0x0a00,MRSHPC_IOWCR2); /* bus width 16bit SWAP = 1 */ |
| 82 | else |
| 83 | outw(0x0200,MRSHPC_IOWCR2); /* bus width 16bit SWAP = 0 */ |
Wolfgang Denk | 0a5c214 | 2007-12-27 01:52:50 +0100 | [diff] [blame] | 84 | |
Nobuhiro Iwamatsu | 770395e | 2007-11-25 02:39:31 +0900 | [diff] [blame] | 85 | outw(0x0000,MRSHPC_ISR); |
| 86 | outw(0x2000,MRSHPC_ICR); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 87 | outb(0x00,(CONFIG_SYS_MARUBUN_MW2 + 0x206)); |
| 88 | outb(0x42,(CONFIG_SYS_MARUBUN_MW2 + 0x200)); |
Nobuhiro Iwamatsu | 770395e | 2007-11-25 02:39:31 +0900 | [diff] [blame] | 89 | |
| 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | int pcmcia_off (void) |
| 94 | { |
| 95 | printf ("Disable PCMCIA " PCMCIA_SLOT_MSG "\n"); |
| 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | |
Jean-Christophe PLAGNIOL-VILLARD | 1ec80fa | 2008-05-18 19:09:50 +0200 | [diff] [blame] | 100 | #endif /* CONFIG_PCMCIA */ |