| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* $Id: cf-enabler.c,v 1.4 2004/02/22 22:44:36 kkojima Exp $ | 
|  | 2 | * | 
|  | 3 | *  linux/drivers/block/cf-enabler.c | 
|  | 4 | * | 
|  | 5 | *  Copyright (C) 1999  Niibe Yutaka | 
|  | 6 | *  Copyright (C) 2000  Toshiharu Nozawa | 
|  | 7 | *  Copyright (C) 2001  A&D Co., Ltd. | 
|  | 8 | * | 
|  | 9 | *  Enable the CF configuration. | 
|  | 10 | */ | 
|  | 11 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/init.h> | 
|  | 13 |  | 
|  | 14 | #include <asm/io.h> | 
|  | 15 | #include <asm/irq.h> | 
|  | 16 |  | 
|  | 17 | /* | 
|  | 18 | * You can connect Compact Flash directly to the bus of SuperH. | 
|  | 19 | * This is the enabler for that. | 
|  | 20 | * | 
|  | 21 | * SIM: How generic is this really? It looks pretty board, or at | 
|  | 22 | * least SH sub-type, specific to me. | 
|  | 23 | * I know it doesn't work on the Overdrive! | 
|  | 24 | */ | 
|  | 25 |  | 
|  | 26 | /* | 
|  | 27 | * 0xB8000000 : Attribute | 
|  | 28 | * 0xB8001000 : Common Memory | 
|  | 29 | * 0xBA000000 : I/O | 
|  | 30 | */ | 
|  | 31 | #if defined(CONFIG_IDE) && defined(CONFIG_CPU_SH4) | 
|  | 32 | /* SH4 can't access PCMCIA interface through P2 area. | 
|  | 33 | * we must remap it with appropreate attribute bit of the page set. | 
|  | 34 | * this part is based on Greg Banks' hd64465_ss.c implementation - Masahiro Abe */ | 
|  | 35 | #include <linux/mm.h> | 
|  | 36 | #include <linux/vmalloc.h> | 
|  | 37 |  | 
|  | 38 | #if defined(CONFIG_CF_AREA6) | 
|  | 39 | #define slot_no 0 | 
|  | 40 | #else | 
|  | 41 | #define slot_no 1 | 
|  | 42 | #endif | 
|  | 43 |  | 
|  | 44 | /* defined in mm/ioremap.c */ | 
|  | 45 | extern void * p3_ioremap(unsigned long phys_addr, unsigned long size, unsigned long flags); | 
|  | 46 |  | 
|  | 47 | /* use this pointer to access to directly connected compact flash io area*/ | 
|  | 48 | void *cf_io_base; | 
|  | 49 |  | 
|  | 50 | static int __init allocate_cf_area(void) | 
|  | 51 | { | 
|  | 52 | pgprot_t prot; | 
|  | 53 | unsigned long paddrbase, psize; | 
|  | 54 |  | 
|  | 55 | /* open I/O area window */ | 
|  | 56 | paddrbase = virt_to_phys((void*)CONFIG_CF_BASE_ADDR); | 
|  | 57 | psize = PAGE_SIZE; | 
|  | 58 | prot = PAGE_KERNEL_PCC(slot_no, _PAGE_PCC_IO16); | 
|  | 59 | cf_io_base = p3_ioremap(paddrbase, psize, prot.pgprot); | 
|  | 60 | if (!cf_io_base) { | 
|  | 61 | printk("allocate_cf_area : can't open CF I/O window!\n"); | 
|  | 62 | return -ENOMEM; | 
|  | 63 | } | 
|  | 64 | /*	printk("p3_ioremap(paddr=0x%08lx, psize=0x%08lx, prot=0x%08lx)=0x%08lx\n", | 
|  | 65 | paddrbase, psize, prot.pgprot, cf_io_base);*/ | 
|  | 66 |  | 
|  | 67 | /* XXX : do we need attribute and common-memory area also? */ | 
|  | 68 |  | 
|  | 69 | return 0; | 
|  | 70 | } | 
|  | 71 | #endif | 
|  | 72 |  | 
|  | 73 | static int __init cf_init_default(void) | 
|  | 74 | { | 
|  | 75 | /* You must have enabled the card, and set the level interrupt | 
|  | 76 | * before reaching this point. Possibly in boot ROM or boot loader. | 
|  | 77 | */ | 
|  | 78 | #if defined(CONFIG_IDE) && defined(CONFIG_CPU_SH4) | 
|  | 79 | allocate_cf_area(); | 
|  | 80 | #endif | 
|  | 81 | #if defined(CONFIG_SH_UNKNOWN) | 
|  | 82 | /* This should be done in each board's init_xxx_irq. */ | 
|  | 83 | make_imask_irq(14); | 
|  | 84 | disable_irq(14); | 
|  | 85 | #endif | 
|  | 86 | return 0; | 
|  | 87 | } | 
|  | 88 |  | 
|  | 89 | #if defined(CONFIG_SH_SOLUTION_ENGINE) | 
|  | 90 | #include <asm/se/se.h> | 
|  | 91 |  | 
|  | 92 | /* | 
|  | 93 | * SolutionEngine | 
|  | 94 | * | 
|  | 95 | * 0xB8400000 : Common Memory | 
|  | 96 | * 0xB8500000 : Attribute | 
|  | 97 | * 0xB8600000 : I/O | 
|  | 98 | */ | 
|  | 99 |  | 
|  | 100 | static int __init cf_init_se(void) | 
|  | 101 | { | 
|  | 102 | if ((ctrl_inw(MRSHPC_CSR) & 0x000c) != 0) | 
|  | 103 | return 0;	/* Not detected */ | 
|  | 104 |  | 
|  | 105 | if ((ctrl_inw(MRSHPC_CSR) & 0x0080) == 0) { | 
|  | 106 | ctrl_outw(0x0674, MRSHPC_CPWCR); /* Card Vcc is 3.3v? */ | 
|  | 107 | } else { | 
|  | 108 | ctrl_outw(0x0678, MRSHPC_CPWCR); /* Card Vcc is 5V */ | 
|  | 109 | } | 
|  | 110 |  | 
|  | 111 | /* | 
|  | 112 | *  PC-Card window open | 
|  | 113 | *  flag == COMMON/ATTRIBUTE/IO | 
|  | 114 | */ | 
|  | 115 | /* common window open */ | 
|  | 116 | ctrl_outw(0x8a84, MRSHPC_MW0CR1);/* window 0xb8400000 */ | 
|  | 117 | if((ctrl_inw(MRSHPC_CSR) & 0x4000) != 0) | 
|  | 118 | /* common mode & bus width 16bit SWAP = 1*/ | 
|  | 119 | ctrl_outw(0x0b00, MRSHPC_MW0CR2); | 
|  | 120 | else | 
|  | 121 | /* common mode & bus width 16bit SWAP = 0*/ | 
|  | 122 | ctrl_outw(0x0300, MRSHPC_MW0CR2); | 
|  | 123 |  | 
|  | 124 | /* attribute window open */ | 
|  | 125 | ctrl_outw(0x8a85, MRSHPC_MW1CR1);/* window 0xb8500000 */ | 
|  | 126 | if ((ctrl_inw(MRSHPC_CSR) & 0x4000) != 0) | 
|  | 127 | /* attribute mode & bus width 16bit SWAP = 1*/ | 
|  | 128 | ctrl_outw(0x0a00, MRSHPC_MW1CR2); | 
|  | 129 | else | 
|  | 130 | /* attribute mode & bus width 16bit SWAP = 0*/ | 
|  | 131 | ctrl_outw(0x0200, MRSHPC_MW1CR2); | 
|  | 132 |  | 
|  | 133 | /* I/O window open */ | 
|  | 134 | ctrl_outw(0x8a86, MRSHPC_IOWCR1);/* I/O window 0xb8600000 */ | 
|  | 135 | ctrl_outw(0x0008, MRSHPC_CDCR);	 /* I/O card mode */ | 
|  | 136 | if ((ctrl_inw(MRSHPC_CSR) & 0x4000) != 0) | 
|  | 137 | ctrl_outw(0x0a00, MRSHPC_IOWCR2); /* bus width 16bit SWAP = 1*/ | 
|  | 138 | else | 
|  | 139 | ctrl_outw(0x0200, MRSHPC_IOWCR2); /* bus width 16bit SWAP = 0*/ | 
|  | 140 |  | 
|  | 141 | ctrl_outw(0x2000, MRSHPC_ICR); | 
|  | 142 | ctrl_outb(0x00, PA_MRSHPC_MW2 + 0x206); | 
|  | 143 | ctrl_outb(0x42, PA_MRSHPC_MW2 + 0x200); | 
|  | 144 | return 0; | 
|  | 145 | } | 
|  | 146 | #endif | 
|  | 147 |  | 
|  | 148 | int __init cf_init(void) | 
|  | 149 | { | 
|  | 150 | #if defined(CONFIG_SH_SOLUTION_ENGINE) | 
|  | 151 | if (MACH_SE) | 
|  | 152 | return cf_init_se(); | 
|  | 153 | #endif | 
|  | 154 | return cf_init_default(); | 
|  | 155 | } | 
|  | 156 |  | 
|  | 157 | __initcall (cf_init); |