📄 cmd_pcmcia.c.svn-base
字号:
/* * (C) Copyright 2000-2004 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * * See file CREDITS for list of people who contributed to this * project. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * ******************************************************************** * * Lots of code copied from: * * m8xx_pcmcia.c - Linux PCMCIA socket driver for the mpc8xx series. * (C) 1999-2000 Magnus Damm <damm@bitsmart.com> * * "The ExCA standard specifies that socket controllers should provide * two IO and five memory windows per socket, which can be independently * configured and positioned in the host address space and mapped to * arbitrary segments of card address space. " - David A Hinds. 1999 * * This controller does _not_ meet the ExCA standard. * * m8xx pcmcia controller brief info: * + 8 windows (attrib, mem, i/o) * + up to two slots (SLOT_A and SLOT_B) * + inputpins, outputpins, event and mask registers. * - no offset register. sigh. * * Because of the lacking offset register we must map the whole card. * We assign each memory window PCMCIA_MEM_WIN_SIZE address space. * Make sure there is (PCMCIA_MEM_WIN_SIZE * PCMCIA_MEM_WIN_NO * * PCMCIA_SOCKETS_NO) bytes at PCMCIA_MEM_WIN_BASE. * The i/o windows are dynamically allocated at PCMCIA_IO_WIN_BASE. * They are maximum 64KByte each... *//* #define DEBUG 1 *//* * PCMCIA support */#include <common.h>#include <command.h>#include <config.h>#include <pcmcia.h>#if defined(CONFIG_8xx)#include <mpc8xx.h>#endif#if defined(CONFIG_LWMON)#include <i2c.h>#endif#ifdef CONFIG_PXA_PCMCIA#include <asm/arch/pxa-regs.h>#endif#if (CONFIG_COMMANDS & CFG_CMD_PCMCIA) || \ ((CONFIG_COMMANDS & CFG_CMD_IDE) && defined(CONFIG_IDE_8xx_PCCARD))int pcmcia_on (void);#if (CONFIG_COMMANDS & CFG_CMD_PCMCIA)static int pcmcia_off (void);#endif#ifdef CONFIG_I82365extern int i82365_init (void);extern void i82365_exit (void);#else /* ! CONFIG_I82365 */#if (CONFIG_COMMANDS & CFG_CMD_PCMCIA)static int hardware_disable(int slot);#endifstatic int hardware_enable (int slot);static int voltage_set(int slot, int vcc, int vpp);#if (! defined(CONFIG_I82365)) && (! defined(CONFIG_PXA_PCMCIA))static u_int m8xx_get_graycode(u_int size);#endif /* !CONFIG_I82365, !CONFIG_PXA_PCMCIA */#if 0static u_int m8xx_get_speed(u_int ns, u_int is_io);#endif/* -------------------------------------------------------------------- */#ifndef CONFIG_PXA_PCMCIA/* look up table for pgcrx registers */static u_int *pcmcia_pgcrx[2] = { &((immap_t *)CFG_IMMR)->im_pcmcia.pcmc_pgcra, &((immap_t *)CFG_IMMR)->im_pcmcia.pcmc_pgcrb,};#define PCMCIA_PGCRX(slot) (*pcmcia_pgcrx[slot])#endif /* CONFIG_PXA_PCMCIA */#endif /* CONFIG_I82365 */#if defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_PXA_PCMCIA)static void print_funcid (int func);static void print_fixed (volatile uchar *p);static int identify (volatile uchar *p);static int check_ide_device (int slot);#endif /* CONFIG_IDE_8xx_PCCARD, CONFIG_PXA_PCMCIA */const char *indent = "\t ";/* -------------------------------------------------------------------- */#if (CONFIG_COMMANDS & CFG_CMD_PCMCIA)int do_pinit (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]){ int rcode = 0; if (argc != 2) { printf ("Usage: pinit {on | off}\n"); return 1; } if (strcmp(argv[1],"on") == 0) { rcode = pcmcia_on (); } else if (strcmp(argv[1],"off") == 0) { rcode = pcmcia_off (); } else { printf ("Usage: pinit {on | off}\n"); return 1; } return rcode;}#endif /* CFG_CMD_PCMCIA *//* -------------------------------------------------------------------- */#ifdef CONFIG_I82365int pcmcia_on (void){ u_int rc; debug ("Enable PCMCIA " PCMCIA_SLOT_MSG "\n"); rc = i82365_init(); if (rc == 0) { rc = check_ide_device(0); } return (rc);}#else#ifndef CONFIG_PXA_PCMCIA#ifdef CONFIG_HMI10# define HMI10_FRAM_TIMING (PCMCIA_SHT(2) | PCMCIA_SST(2) | PCMCIA_SL(4))#endif#if defined(CONFIG_LWMON) || defined(CONFIG_NSCU)# define CFG_PCMCIA_TIMING (PCMCIA_SHT(9) | PCMCIA_SST(3) | PCMCIA_SL(12))#else# define CFG_PCMCIA_TIMING (PCMCIA_SHT(2) | PCMCIA_SST(4) | PCMCIA_SL(9))#endifint pcmcia_on (void){ int i; u_long reg, base; pcmcia_win_t *win; u_int slotbit; u_int rc, slot; debug ("Enable PCMCIA " PCMCIA_SLOT_MSG "\n"); /* intialize the fixed memory windows */ win = (pcmcia_win_t *)(&((immap_t *)CFG_IMMR)->im_pcmcia.pcmc_pbr0); base = CFG_PCMCIA_MEM_ADDR; if((reg = m8xx_get_graycode(CFG_PCMCIA_MEM_SIZE)) == -1) { printf ("Cannot set window size to 0x%08x\n", CFG_PCMCIA_MEM_SIZE); return (1); } slotbit = PCMCIA_SLOT_x; for (i=0; i<PCMCIA_MEM_WIN_NO; ++i) { win->br = base;#if (PCMCIA_SOCKETS_NO == 2) if (i == 4) /* Another slot starting from win 4 */ slotbit = (slotbit ? PCMCIA_PSLOT_A : PCMCIA_PSLOT_B);#endif switch (i) {#ifdef CONFIG_IDE_8xx_PCCARD case 4:#ifdef CONFIG_HMI10 { /* map FRAM area */ win->or = ( PCMCIA_BSIZE_256K | PCMCIA_PPS_8 | PCMCIA_PRS_ATTR | slotbit | PCMCIA_PV | HMI10_FRAM_TIMING ); break; }#endif case 0: { /* map attribute memory */ win->or = ( PCMCIA_BSIZE_64M | PCMCIA_PPS_8 | PCMCIA_PRS_ATTR | slotbit | PCMCIA_PV | CFG_PCMCIA_TIMING ); break; } case 5: case 1: { /* map I/O window for data reg */ win->or = ( PCMCIA_BSIZE_1K | PCMCIA_PPS_16 | PCMCIA_PRS_IO | slotbit | PCMCIA_PV | CFG_PCMCIA_TIMING ); break; } case 6: case 2: { /* map I/O window for cmd/ctrl reg block */ win->or = ( PCMCIA_BSIZE_1K | PCMCIA_PPS_8 | PCMCIA_PRS_IO | slotbit | PCMCIA_PV | CFG_PCMCIA_TIMING ); break; }#endif /* CONFIG_IDE_8xx_PCCARD */#ifdef CONFIG_HMI10 case 3: { /* map I/O window for 4xUART data/ctrl */ win->br += 0x40000; win->or = ( PCMCIA_BSIZE_256K | PCMCIA_PPS_8 | PCMCIA_PRS_IO | slotbit | PCMCIA_PV | CFG_PCMCIA_TIMING ); break; }#endif /* CONFIG_HMI10 */ default: /* set to not valid */ win->or = 0; break; } debug ("MemWin %d: PBR 0x%08lX POR %08lX\n", i, win->br, win->or); base += CFG_PCMCIA_MEM_SIZE; ++win; } for (i=0, rc=0, slot=_slot_; i<PCMCIA_SOCKETS_NO; i++, slot = !slot) { /* turn off voltage */ if ((rc = voltage_set(slot, 0, 0))) continue; /* Enable external hardware */ if ((rc = hardware_enable(slot))) continue;#ifdef CONFIG_IDE_8xx_PCCARD if ((rc = check_ide_device(i))) continue;#endif } return (rc);}#endif /* CONFIG_PXA_PCMCIA */#endif /* CONFIG_I82365 */#ifdef CONFIG_PXA_PCMCIAstatic int hardware_enable (int slot){ return 0; /* No hardware to enable */}static int hardware_disable(int slot){ return 0; /* No hardware to disable */}static int voltage_set(int slot, int vcc, int vpp){ return 0;}void msWait(unsigned msVal){ udelay(msVal*1000);}int pcmcia_on (void){ unsigned int reg_arr[] = { 0x48000028, CFG_MCMEM0_VAL, 0x4800002c, CFG_MCMEM1_VAL, 0x48000030, CFG_MCATT0_VAL, 0x48000034, CFG_MCATT1_VAL, 0x48000038, CFG_MCIO0_VAL, 0x4800003c, CFG_MCIO1_VAL, 0, 0 }; int i, rc;#ifdef CONFIG_EXADRON1 int cardDetect; volatile unsigned int *v_pBCRReg = (volatile unsigned int *) 0x08000000;#endif debug ("%s\n", __FUNCTION__); i = 0; while (reg_arr[i]) *((volatile unsigned int *) reg_arr[i++]) |= reg_arr[i++]; udelay (1000); debug ("%s: programmed mem controller \n", __FUNCTION__);#ifdef CONFIG_EXADRON1/*define useful BCR masks */#define BCR_CF_INIT_VAL 0x00007230#define BCR_CF_PWRON_BUSOFF_RESETOFF_VAL 0x00007231#define BCR_CF_PWRON_BUSOFF_RESETON_VAL 0x00007233#define BCR_CF_PWRON_BUSON_RESETON_VAL 0x00007213#define BCR_CF_PWRON_BUSON_RESETOFF_VAL 0x00007211 /* we see from the GPIO bit if the card is present */ cardDetect = !(GPLR0 & GPIO_bit (14)); if (cardDetect) { printf ("No PCMCIA card found!\n"); } /* reset the card via the BCR line */ *v_pBCRReg = (unsigned) BCR_CF_INIT_VAL; msWait (500); *v_pBCRReg = (unsigned) BCR_CF_PWRON_BUSOFF_RESETOFF_VAL; msWait (500); *v_pBCRReg = (unsigned) BCR_CF_PWRON_BUSOFF_RESETON_VAL; msWait (500); *v_pBCRReg = (unsigned) BCR_CF_PWRON_BUSON_RESETON_VAL; msWait (500); *v_pBCRReg = (unsigned) BCR_CF_PWRON_BUSON_RESETOFF_VAL; msWait (1500); /* enable address bus */ GPCR1 = 0x01; /* and the first CF slot */ MECR = 0x00000002;#endif /* EXADRON 1 */ rc = check_ide_device (0); /* use just slot 0 */ return rc;}#endif /* CONFIG_PXA_PCMCIA *//* -------------------------------------------------------------------- */#if (CONFIG_COMMANDS & CFG_CMD_PCMCIA)#ifdef CONFIG_I82365static int pcmcia_off (void){ printf ("Disable PCMCIA " PCMCIA_SLOT_MSG "\n"); i82365_exit(); return 0;}#else#ifndef CONFIG_PXA_PCMCIAstatic int pcmcia_off (void){ int i; pcmcia_win_t *win; printf ("Disable PCMCIA " PCMCIA_SLOT_MSG "\n"); /* clear interrupt state, and disable interrupts */ ((immap_t *)CFG_IMMR)->im_pcmcia.pcmc_pscr = PCMCIA_MASK(_slot_); ((immap_t *)CFG_IMMR)->im_pcmcia.pcmc_per &= ~PCMCIA_MASK(_slot_); /* turn off interrupt and disable CxOE */ PCMCIA_PGCRX(_slot_) = __MY_PCMCIA_GCRX_CXOE; /* turn off memory windows */ win = (pcmcia_win_t *)(&((immap_t *)CFG_IMMR)->im_pcmcia.pcmc_pbr0); for (i=0; i<PCMCIA_MEM_WIN_NO; ++i) { /* disable memory window */ win->or = 0; ++win; } /* turn off voltage */ voltage_set(_slot_, 0, 0); /* disable external hardware */ printf ("Shutdown and Poweroff " PCMCIA_SLOT_MSG "\n"); hardware_disable(_slot_); return 0;}#endif /* CONFIG_PXA_PCMCIA */#endif /* CONFIG_I82365 */#ifdef CONFIG_PXA_PCMCIAstatic int pcmcia_off (void){ return 0;}#endif#endif /* CFG_CMD_PCMCIA *//* -------------------------------------------------------------------- */#if defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_PXA_PCMCIA)#define MAX_TUPEL_SZ 512#define MAX_FEATURES 4int ide_devices_found;static int check_ide_device (int slot){ volatile uchar *ident = NULL; volatile uchar *feature_p[MAX_FEATURES]; volatile uchar *p, *start, *addr; int n_features = 0; uchar func_id = ~0; uchar code, len; ushort config_base = 0; int found = 0; int i; addr = (volatile uchar *)(CFG_PCMCIA_MEM_ADDR + CFG_PCMCIA_MEM_SIZE * (slot * 4)); debug ("PCMCIA MEM: %08lX\n", (ulong)addr); start = p = (volatile uchar *) addr; while ((p - start) < MAX_TUPEL_SZ) { code = *p; p += 2; if (code == 0xFF) { /* End of chain */ break; } len = *p; p += 2;#if defined(DEBUG) && (DEBUG > 1) { volatile uchar *q = p; printf ("\nTuple code %02x length %d\n\tData:", code, len); for (i = 0; i < len; ++i) { printf (" %02x", *q); q+= 2; } }#endif /* DEBUG */ switch (code) { case CISTPL_VERS_1: ident = p + 4; break; case CISTPL_FUNCID: /* Fix for broken SanDisk which may have 0x80 bit set */ func_id = *p & 0x7F; break; case CISTPL_FUNCE: if (n_features < MAX_FEATURES) feature_p[n_features++] = p; break; case CISTPL_CONFIG: config_base = (*(p+6) << 8) + (*(p+4)); debug ("\n## Config_base = %04x ###\n", config_base); default: break; } p += 2 * len; } found = identify (ident); if (func_id != ((uchar)~0)) { print_funcid (func_id); if (func_id == CISTPL_FUNCID_FIXED) found = 1; else return (1); /* no disk drive */ } for (i=0; i<n_features; ++i) { print_fixed (feature_p[i]); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -