PPC: Cleanup tqm8xx_pcmcia.c

Signed-off-by: Marek Vasut <marek.vasut@gmail.com>
Tested-by: Wolfgang Denk <wd@denx.de>
Acked-by: Wolfgang Denk <wd@denx.de>
This commit is contained in:
Marek Vasut 2011-10-05 02:51:55 +00:00 committed by Wolfgang Denk
parent 7aabd2b12c
commit 6e96703172

View file

@ -3,6 +3,7 @@
/* SC8xx Boards by SinoVee Microsystems */ /* SC8xx Boards by SinoVee Microsystems */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
#include <common.h> #include <common.h>
#include <asm/io.h>
#ifdef CONFIG_8xx #ifdef CONFIG_8xx
#include <mpc8xx.h> #include <mpc8xx.h>
#endif #endif
@ -31,75 +32,86 @@
#if defined(CONFIG_NSCU) #if defined(CONFIG_NSCU)
#define power_config(slot) do {} while (0) static inline void power_config(int slot) {}
#define power_off(slot) do {} while (0) static inline void power_off(int slot) {}
#define power_on_5_0(slot) do {} while (0) static inline void power_on_5_0(int slot) {}
#define power_on_3_3(slot) do {} while (0) static inline void power_on_3_3(int slot) {}
#elif defined(CONFIG_VIRTLAB2) #elif defined(CONFIG_VIRTLAB2)
#define power_config(slot) do {} while (0) static inline void power_config(int slot) {}
static inline void power_off(int slot) static inline void power_off(int slot)
{ {
volatile unsigned char *powerctl = out_be32(PCMCIA_CTRL, 0);
(volatile unsigned char *)PCMCIA_CTRL;
*powerctl = 0;
} }
static inline void power_on_5_0(int slot) static inline void power_on_5_0(int slot)
{ {
volatile unsigned char *powerctl = /* Enable 5V Vccout */
(volatile unsigned char *)PCMCIA_CTRL; out_be32(PCMCIA_CTRL, 2);
*powerctl = 2; /* Enable 5V Vccout */
} }
static inline void power_on_3_3(int slot) static inline void power_on_3_3(int slot)
{ {
volatile unsigned char *powerctl = /* Enable 3.3V Vccout */
(volatile unsigned char *)PCMCIA_CTRL; out_be32(PCMCIA_CTRL, 1);
*powerctl = 1; /* Enable 3.3V Vccout */
} }
#else #else
static inline void power_config(int slot) static inline void power_config(int slot)
{ {
volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
/* /*
* Configure Port C pins for * Configure Port C pins for
* 5 Volts Enable and 3 Volts enable * 5 Volts Enable and 3 Volts enable
*/ */
immap->im_ioport.iop_pcpar &= ~(0x0002 | 0x0004); clrbits_be16(&immap->im_ioport.iop_pcpar, 0x0002 | 0x0004);
immap->im_ioport.iop_pcso &= ~(0x0002 | 0x0004); clrbits_be16(&immap->im_ioport.iop_pcso, 0x0002 | 0x0004);
} }
static inline void power_off(int slot) static inline void power_off(int slot)
{ {
volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
immap->im_ioport.iop_pcdat &= ~(0x0002 | 0x0004); clrbits_be16(&immap->im_ioport.iop_pcdat, 0x0002 | 0x0004);
} }
static inline void power_on_5_0(int slot) static inline void power_on_5_0(int slot)
{ {
volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
immap->im_ioport.iop_pcdat |= 0x0004; setbits_be16(&immap->im_ioport.iop_pcdat, 0x0004);
immap->im_ioport.iop_pcdir |= (0x0002 | 0x0004); setbits_be16(&immap->im_ioport.iop_pcdir, 0x0002 | 0x0004);
} }
static inline void power_on_3_3(int slot) static inline void power_on_3_3(int slot)
{ {
volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
immap->im_ioport.iop_pcdat |= 0x0002; setbits_be16(&immap->im_ioport.iop_pcdat, 0x0002);
immap->im_ioport.iop_pcdir |= (0x0002 | 0x0004); setbits_be16(&immap->im_ioport.iop_pcdir, 0x0002 | 0x0004);
} }
#endif #endif
/*
* Function to retrieve the PIPR register, used for debuging purposes.
*/
static inline uint32_t debug_get_pipr(void)
{
uint32_t pipr = 0;
#ifdef DEBUG
immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
pipr = in_be32(&immap->im_pcmcia.pcmc_pipr);
#endif
return pipr;
}
static inline int check_card_is_absent(int slot) static inline int check_card_is_absent(int slot)
{ {
volatile pcmconf8xx_t *pcmp = immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
(pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia)); uint32_t pipr = in_be32(&immap->im_pcmcia.pcmc_pipr);
return pcmp->pcmc_pipr & (0x18000000 >> (slot << 4)); return pipr & (0x18000000 >> (slot << 4));
} }
#ifdef NSCU_OE_INV #ifdef NSCU_OE_INV
@ -110,31 +122,30 @@ static inline int check_card_is_absent(int slot)
int pcmcia_hardware_enable(int slot) int pcmcia_hardware_enable(int slot)
{ {
volatile pcmconf8xx_t *pcmp = immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
(pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia));
volatile sysconf8xx_t *sysp =
(sysconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_siu_conf));
uint reg, mask; uint reg, mask;
debug ("hardware_enable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot); debug("hardware_enable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
udelay(10000); udelay(10000);
/* /*
* Configure SIUMCR to enable PCMCIA port B * Configure SIUMCR to enable PCMCIA port B
* (VFLS[0:1] are not used for debugging, we connect FRZ# instead) * (VFLS[0:1] are not used for debugging, we connect FRZ# instead)
*/ */
sysp->sc_siumcr &= ~SIUMCR_DBGC11; /* set DBGC to 00 */
/* clear interrupt state, and disable interrupts */ /* Set DBGC to 00 */
pcmp->pcmc_pscr = PCMCIA_MASK(slot); clrbits_be32(&immap->im_siu_conf.sc_siumcr, SIUMCR_DBGC11);
pcmp->pcmc_per &= ~PCMCIA_MASK(slot);
/* Clear interrupt state, and disable interrupts */
out_be32(&immap->im_pcmcia.pcmc_pscr, PCMCIA_MASK(slot));
clrbits_be32(&immap->im_pcmcia.pcmc_per, PCMCIA_MASK(slot));
/* /*
* Disable interrupts, DMA, and PCMCIA buffers * Disable interrupts, DMA, and PCMCIA buffers
* (isolate the interface) and assert RESET signal * (isolate the interface) and assert RESET signal
*/ */
debug ("Disable PCMCIA buffers and assert RESET\n"); debug("Disable PCMCIA buffers and assert RESET\n");
reg = 0; reg = 0;
reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */ reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
reg |= NSCU_GCRX_CXOE; reg |= NSCU_GCRX_CXOE;
@ -149,8 +160,9 @@ int pcmcia_hardware_enable(int slot)
* Make sure there is a card in the slot, then configure the interface. * Make sure there is a card in the slot, then configure the interface.
*/ */
udelay(10000); udelay(10000);
debug ("[%d] %s: PIPR(%p)=0x%x\n", __LINE__,__FUNCTION__, reg = debug_get_pipr();
&(pcmp->pcmc_pipr),pcmp->pcmc_pipr); debug("[%d] %s: PIPR(%p)=0x%x\n", __LINE__, __FUNCTION__,
&immap->im_pcmcia.pcmc_pipr, reg);
if (check_card_is_absent(slot)) { if (check_card_is_absent(slot)) {
printf (" No Card found\n"); printf (" No Card found\n");
@ -158,14 +170,14 @@ int pcmcia_hardware_enable(int slot)
} }
/* /*
* Power On. * Power On.
*/ */
mask = PCMCIA_VS1(slot) | PCMCIA_VS2(slot); mask = PCMCIA_VS1(slot) | PCMCIA_VS2(slot);
reg = pcmp->pcmc_pipr; reg = in_be32(&immap->im_pcmcia.pcmc_pipr);
debug ("PIPR: 0x%x ==> VS1=o%s, VS2=o%s\n", debug ("PIPR: 0x%x ==> VS1=o%s, VS2=o%s\n",
reg, reg,
(reg&PCMCIA_VS1(slot))?"n":"ff", (reg & PCMCIA_VS1(slot)) ? "n" : "ff",
(reg&PCMCIA_VS2(slot))?"n":"ff"); (reg & PCMCIA_VS2(slot)) ? "n" : "ff");
if ((reg & mask) == mask) { if ((reg & mask) == mask) {
power_on_5_0(slot); power_on_5_0(slot);
@ -183,7 +195,7 @@ int pcmcia_hardware_enable(int slot)
#endif #endif
udelay(1000); udelay(1000);
debug ("Enable PCMCIA buffers and stop RESET\n"); debug("Enable PCMCIA buffers and stop RESET\n");
reg = PCMCIA_PGCRX(slot); reg = PCMCIA_PGCRX(slot);
reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */ reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */ reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
@ -193,7 +205,7 @@ int pcmcia_hardware_enable(int slot)
udelay(250000); /* some cards need >150 ms to come up :-( */ udelay(250000); /* some cards need >150 ms to come up :-( */
debug ("# hardware_enable done\n"); debug("# hardware_enable done\n");
return (0); return (0);
} }
@ -204,13 +216,12 @@ int pcmcia_hardware_disable(int slot)
{ {
u_long reg; u_long reg;
debug ("hardware_disable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot); debug("hardware_disable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
/* remove all power */ /* remove all power */
power_off(slot); power_off(slot);
debug ("Disable PCMCIA buffers and assert RESET\n"); debug("Disable PCMCIA buffers and assert RESET\n");
reg = 0; reg = 0;
reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */ reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
reg |= NSCU_GCRX_CXOE; /* active low */ reg |= NSCU_GCRX_CXOE; /* active low */
@ -227,20 +238,17 @@ int pcmcia_voltage_set(int slot, int vcc, int vpp)
{ {
#ifndef CONFIG_NSCU #ifndef CONFIG_NSCU
u_long reg; u_long reg;
# ifdef DEBUG uint32_t pipr = 0;
volatile pcmconf8xx_t *pcmp =
(pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia));
# endif
debug ("voltage_set: " PCMCIA_BOARD_MSG debug("voltage_set: " PCMCIA_BOARD_MSG
" Slot %c, Vcc=%d.%d, Vpp=%d.%d\n", " Slot %c, Vcc=%d.%d, Vpp=%d.%d\n",
'A'+slot, vcc/10, vcc%10, vpp/10, vcc%10); 'A'+slot, vcc/10, vcc%10, vpp/10, vcc%10);
/* /*
* Disable PCMCIA buffers (isolate the interface) * Disable PCMCIA buffers (isolate the interface)
* and assert RESET signal * and assert RESET signal
*/ */
debug ("Disable PCMCIA buffers and assert RESET\n"); debug("Disable PCMCIA buffers and assert RESET\n");
reg = PCMCIA_PGCRX(slot); reg = PCMCIA_PGCRX(slot);
reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */ reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */ reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
@ -249,7 +257,7 @@ int pcmcia_voltage_set(int slot, int vcc, int vpp)
PCMCIA_PGCRX(slot) = reg; PCMCIA_PGCRX(slot) = reg;
udelay(500); udelay(500);
debug ("PCMCIA power OFF\n"); debug("PCMCIA power OFF\n");
power_config(slot); power_config(slot);
power_off(slot); power_off(slot);
@ -261,9 +269,9 @@ int pcmcia_voltage_set(int slot, int vcc, int vpp)
} }
/* Checking supported voltages */ /* Checking supported voltages */
pipr = debug_get_pipr();
debug("PIPR: 0x%x --> %s\n", pcmp->pcmc_pipr, debug("PIPR: 0x%x --> %s\n", pipr,
(pcmp->pcmc_pipr & 0x00008000) ? "only 5 V" : "can do 3.3V"); (pipr & 0x00008000) ? "only 5 V" : "can do 3.3V");
if (vcc) if (vcc)
debug("PCMCIA powered at %sV\n", (vcc == 50) ? "5.0" : "3.3"); debug("PCMCIA powered at %sV\n", (vcc == 50) ? "5.0" : "3.3");
@ -282,7 +290,7 @@ done:
debug("voltage_set: " PCMCIA_BOARD_MSG " Slot %c, DONE\n", slot+'A'); debug("voltage_set: " PCMCIA_BOARD_MSG " Slot %c, DONE\n", slot+'A');
#endif /* CONFIG_NSCU */ #endif /* CONFIG_NSCU */
return (0); return 0;
} }
#endif /* CONFIG_PCMCIA && (CONFIG_TQM8xxL || CONFIG_SVM_SC8xx) */ #endif /* CONFIG_PCMCIA && (CONFIG_TQM8xxL || CONFIG_SVM_SC8xx) */