/* * sb_hpet_cfg : * config the HPET module */ void sb_hpet_cfg(void) { u8 rev = get_sb600_revision(); pcitag_t sm_dev = _pci_make_tag(0, 20, 0); PRINTF_DEBUG(); #ifdef CFG_ATI_HPET_BASE #if CFG_ATI_HPET_BASE if(ati_sb_cfg.hpet_en == SB_ENABLE){ if(rev >= REV_SB600_A21){ set_pm_enable_bits(0x55, 1 << 7, 0 << 7); } ati_sb_cfg.hpet_base = CFG_ATI_HPET_BASE; _pci_conf_write(sm_dev, 0x14, ati_sb_cfg.hpet_base); set_sbcfg_enable_bits(sm_dev, 0x64, 1 << 10, 1 << 10); } #endif #endif if(rev >= REV_SB600_A21){ set_pm_enable_bits(0x55, 1 << 7, 1 << 7); set_pm_enable_bits(0x52, 1 << 6, 1 << 6); } return; }
void sb_last_sata_cache(void) { u32 base; u32 val; pcitag_t sata_dev = _pci_make_tag(0, 0x12, 0); PRINTF_DEBUG(); if(ati_sb_cfg.sata_cache_base){ /* store sata base, size and signature */ base = ati_sb_cfg.sata_cache_base | 0xa0000000; *(volatile u32 *)(base + 0x08) = ati_sb_cfg.sata_cache_base; *(volatile u32 *)(base + 0x04) = ati_sb_cfg.sata_cache_size; *(volatile u8 *)(base + 0x00) = 'A'; *(volatile u8 *)(base + 0x01) = 'T'; *(volatile u8 *)(base + 0x02) = 'i'; *(volatile u8 *)(base + 0x03) = 'B'; /* disable IO access */ set_sbcfg_enable_bits(sata_dev, 0x04, 1 << 0, 0 << 0); /* reserved bit */ set_sbcfg_enable_bits(sata_dev, 0x40, 1 << 20, 1 << 20); /* set cache base addr */ val = _pci_conf_read(sata_dev, 0x10); val &= 0x00ffffff; val |= (ati_sb_cfg.sata_cache_base >> 24) << 24; _pci_conf_write(sata_dev, 0x10, val); }
/*************************************** * Legacy devices are mapped to LPC space. * serial port 0 * KBC Port * ACPI Micro-controller port * LPC ROM size, * NOTE: Call me ASAP, because I will reset LPC ROM size! * NOTE : by general, it is called after HT emulation ***************************************/ void sb600_lpc_init(void) { u8 reg8; u32 reg32; pcitag_t sm_dev = _pci_make_tag(0, 20, 0); pcitag_t lpc_dev = _pci_make_tag(0, 20, 3); /* Enable lpc controller */ reg32 = _pci_conf_read(sm_dev, 0x64); reg32 |= 0x00100000; _pci_conf_write(sm_dev, 0x64, reg32); /* Serial 0 : 0x3f8~0x3ff */ reg8 = _pci_conf_readn(lpc_dev, 0x44, 1); reg8 |= (1 << 6); _pci_conf_writen(lpc_dev, 0x44, reg8, 1); /* PS/2 keyboard, ACPI : 0x60/0x64 & 0x62/0x66 */ reg8 = _pci_conf_readn(lpc_dev, 0x47, 1); reg8 |= (1 << 5) | (1 << 6); _pci_conf_writen(lpc_dev, 0x47, reg8, 1); /* SuperIO, LPC ROM */ reg8 = _pci_conf_readn(lpc_dev, 0x48, 1); reg8 |= (1 << 1) | (1 << 0); /* enable Super IO config port 2e-2h, 4e-4f */ reg8 |= (1 << 3) | (1 << 4); /* enable for LPC ROM address range1&2, Enable 512KB rom access at 0xFFF80000 - 0xFFFFFFFF */ reg8 |= 1 << 6; /* enable for RTC I/O range */ _pci_conf_writen(lpc_dev, 0x48, reg8, 1); /* hardware should enable LPC ROM by pin strapes */ /* rom access at 0xFFF80000/0xFFF00000 - 0xFFFFFFFF */ /* See detail in BDG-215SB600-03.pdf page 15. */ _pci_conf_writen(lpc_dev, 0x68, 0x000e, 2); /* enable LPC ROM range, 0xfff8: 512KB, 0xfff0: 1MB; */ _pci_conf_writen(lpc_dev, 0x6c, 0xfff0, 2); /* enable LPC ROM range, 0xfff8: 512KB, 0xfff0: 1MB */ }
int pci_write_config_dword(struct pci_device *linuxpd, int reg, u32 val) { if ((reg & 3) || reg < 0 || reg >= 0x100) { printf ("pci_write_config_dword: bad reg %x\n", reg); return -1; } _pci_conf_write(linuxpd->pa.pa_tag,reg,val); return 0; }
/* Get SB ASIC Revision.*/ u8 get_sb600_revision(void) { pcitag_t sb_dev = _pci_make_tag(0, 0x14, 0); u8 rev; u32 reg32; rev = _pci_conf_readn(sb_dev, 0x08, 1); if(rev >= REV_SB600_A13){ reg32 = _pci_conf_read(sb_dev, 0x70); reg32 |= 1 << 8; _pci_conf_write(sb_dev, 0x70, reg32); rev = _pci_conf_readn(sb_dev, 0x08, 1); reg32 &= ~(1 << 8); _pci_conf_write(sb_dev, 0x70, reg32); } return rev; }
void sb600_lpc_port80(void) { u8 byte; u32 dev; u32 reg32; /* enable lpc controller */ dev = _pci_make_tag(0, 20, 0); reg32 = _pci_conf_read(dev, 0x64); reg32 |= 0x00100000; /* lpcEnable */ _pci_conf_write(dev, 0x64, reg32); /* enable prot80 LPC decode in pci function 3 configuration space. */ dev = _pci_make_tag(0, 20, 3); byte = _pci_conf_readn(dev, 0x4a, 1); byte |= 1 << 5; /* enable port 80 */ _pci_conf_writen(dev, 0x4a, byte, 1); }
void sb_last_init_pci_autoclock_run(void) { u32 val; pcitag_t dev = _pci_make_tag(0, 20, 4); PRINTF_DEBUG(); _pci_conf_write(dev, 0x4C, ati_sb_cfg.clkrun_ctrl); val = _pci_conf_readn(dev, 0x50, 2); val &= 0x3F; val |= ati_sb_cfg.clkrun_ow << 6; _pci_conf_writen(dev, 0x50, val, 2); if(ati_sb_cfg.clkrun_ctrl == 1){ set_sbcfg_enable_bits(dev, 0x64, 1 << 15, 1 << 15); } return; }
void sb_last_sata_unconnected_shutdown_clock(void) { u8 sata_class = ati_sb_cfg.sata_class; pcitag_t sata_dev = _pci_make_tag(0, 18, 0); u32 temp; PRINTF_DEBUG(); if(ati_sb_cfg.sata_ck_au_off == SB_ENABLE){ // auto off if(ati_sb_cfg.sata_channel > 0){ // enable sata switch(sata_class){ case 0 : case 3 : case 4 : temp = _pci_conf_read(sata_dev, 0x40); temp |= (ati_sb_cfg.sb600_sata_sts & 0xFF0F) << 16; _pci_conf_write(sata_dev, 0x40, temp); default : } } } return; }
/* * sb_sata_init : * sb sata init, for real device init and make it available */ void sb_sata_init(void) { pcitag_t sm_dev = _pci_make_tag(0, 20, 0); pcitag_t ide_dev = _pci_make_tag(0, 20, 1); pcitag_t sata_dev = _pci_make_tag(0, 18, 0); u32 port_phy; u8 port_bist; u32 reg04; u32 sata_bar5; u8 rev, class; /* enable the sata controller according to config */ if(ati_sb_cfg.sata_smbus == SB_ENABLE){ // enable set_sbcfg_enable_bits(sm_dev, 0xAD, 1 << 1, 0 << 1); }else{ // disable set_sbcfg_enable_bits(sm_dev, 0xAD, 1 << 1, 1 << 1); } /* enable proper SATA channel based on config : '0' none, '1' SATA1 */ if(ati_sb_cfg.sata_channel == SB_DISABLE){ // disable SATA1 set_sbcfg_enable_bits(sm_dev, 0xAD, 1 << 0, 0 << 0); }else{ // enable SATA1 & set power saving mode set_sbcfg_enable_bits(sm_dev, 0xAD, (1 << 0) | (1 << 5), (1 << 0) | (1 << 5)); } /* BIT4 : disable fast boot * BIT0 : enable write subsystem id */ set_sbcfg_enable_bits(sata_dev, 0x40, (1 << 0) | (1 << 4), (1 << 0) | (1 << 4)); /* disable SATA MSI cap */ set_sbcfg_enable_bits(sata_dev, 0x40, 1 << 23, 1 << 23); /* disable IDP cap */ if(rev <= REV_SB600_A21){ set_sbcfg_enable_bits(sata_dev, 0x40, 1 << 25, 1 << 25); } /* setting device class */ class = ati_sb_cfg.sata_class; if(class == 3){ /* IDE native mode setting */ set_sbcfg_enable_bits(ide_dev, 0x08, 0xFF << 8, 0x8F << 8); } /* SATA class mode setting */ _pci_conf_write(sata_dev, 0x08, sata_class_table[class]); /* disable SATA class write */ set_sbcfg_enable_bits(sata_dev, 0x40, 1 << 0, 0 << 0); /* program wdt with 16 retries before timer timeout */ set_sbcfg_enable_bits(sata_dev, 0x44, 0xff << 16, 0x10 << 16); if(rev == REV_SB600_A11){ /* PHY global tuning x86 to 0x2400 */ _pci_conf_writen(sata_dev, 0x86, 0x2400, 2); /* PHY tuning for ports */ port_phy = 0x00B420D8; port_bist = 0x00; }else{ /* PHY global tuning x86 to 0x2400 */ _pci_conf_writen(sata_dev, 0x86, 0x2c00, 2); if(rev == REV_SB600_A12){ port_phy = 0x00B4005A; port_bist = 0xB8; }else if(rev == REV_SB600_A13){ port_phy = 0x00B401DA; port_bist = 0xB8; if(ati_sb_cfg.sata_phy_avdd == SB_ENABLE){ // phy AVDD is 1.25V port_phy = 0x00B401D5; port_bist = 0x78; } }else{ port_phy = 0x00B401D6; port_bist = 0xB8; } } /* tuning 4 ports phy */ _pci_conf_write(sata_dev, 0x88, port_phy); _pci_conf_write(sata_dev, 0x8C, port_phy); _pci_conf_write(sata_dev, 0x90, port_phy); _pci_conf_write(sata_dev, 0x94, port_phy); _pci_conf_writen(sata_dev, 0xA5, port_bist, 1); _pci_conf_writen(sata_dev, 0xAD, port_bist, 1); _pci_conf_writen(sata_dev, 0xB5, port_bist, 1); _pci_conf_writen(sata_dev, 0xBD, port_bist, 1); /* port reset */ delay(1000); // delay 1ms /* get sata bar5 base address */ reg04 = _pci_conf_read(sata_dev, 0x04); if( (_pci_conf_read(sata_dev, 0x24) & 0xfffffff0) == 0 ){ _pci_conf_write(sata_dev, 0x24, TEMP_SATA_BAR5_BASE); sata_bar5 = TEMP_SATA_BAR5_BASE | 0xA0000000; }else{ sata_bar5 = (_pci_conf_read(sata_dev, 0x24) & 0xfffffff0) | 0xA0000000; } /* enable io/mem access */ set_sbcfg_enable_bits(sata_dev, 0x04, (1 << 0) | (1 << 1), (1 << 0) | (1 << 1)); /* RPR 6.10 Hide Support-Aggressive-Link-Power-Management Capability * in AHCI HBA Capabilities Register (For all SB600) * 1. SATA_PCI_config 0x40 [0] = 1 * Unlocks configuration register so that HBA AHCI Capabilities Register * can be modified. * 2. SATA_BAR5 + 0xFC [11] = 0 * (CFG_CAP_SALP Disabled) Clearing this bit has the following effects: * Support-Aggressive-Link-Power-Management Capability is hidden from * software in AHCI HBA Capabilities Register. * As a result,;software will not enable the HBA to aggressively enter * power-saving (Partial/Slumber) mode. * 6.12 Hiding Slumber and Partial State Capabilities in AHCI HBA Capabilities * Register * 2. SATA_BAR5 + 0xFC [27] = 1 (CFG_CAP_SALP Disabled) * 3. SATA_PCI_config 0x40 [0]= 0 * Clears the bit to lock configuration registers so that AHCI HBA * Capabilities Register is read-only. */ set_sbcfg_enable_bits(sata_dev, 0x40, 1 << 0, 1 << 0); *(volatile u32 *)(sata_bar5 + 0xFC) &= ~(1 << 11); *(volatile u32 *)(sata_bar5 + 0xFC) |= 1 << 27; if(ati_sb_cfg.sata_port_mult_cap != SB_ENABLE){ *(volatile u32 *)(sata_bar5 + 0xFC) &= ~(1 << 12); } if(rev >= REV_SB600_A21){ if(ati_sb_cfg.sata_hot_plug_cap != SB_ENABLE){ *(volatile u32 *)(sata_bar5 + 0xFC) &= ~(1 << 17); } } set_sbcfg_enable_bits(sata_dev, 0x40, 1 << 0, 0 << 0); /* RPR6.11 Disabling SATA Interface Partial/Slumber States Power Management * Transitions (For all SB600 ) * Port0: SATA_BAR5 + 0x12C[11:08] = 0x03 * Port1: SATA_BAR5 + 0x1AC[11:08] = 0x03 * Port2: SATA_BAR5 + 0x22C[11:08] = 0x03 * Port3: SATA_BAR5 + 0x2AC[11:08] = 0x03 * Setting PxSCTL (Port X Serial ATA Control) register bits[11:8] (PxSCTL.IPM) * to 0x03 will disable interface power management states, * both Partial and Slumber. HBA is not allowed to initiate these two states, * and HBA must PMNAK any request from device to enter these states. */ *(volatile u32 *)(sata_bar5 + 0x12C) |= 3 << 8; *(volatile u32 *)(sata_bar5 + 0x1AC) |= 3 << 8; *(volatile u32 *)(sata_bar5 + 0x22C) |= 3 << 8; *(volatile u32 *)(sata_bar5 + 0x2AC) |= 3 << 8; /* restore pci cmd */ _pci_conf_write(sata_dev, 0x04, reg04); return; }
/* * sata_drive_detect : * detect the sata drive and put it into proper config */ static void sata_drive_detecting(void) { int ports = 4, count; int timeout; u32 base, reg32, reg04; u32 val; pcitag_t sata_dev = _pci_make_tag(0, 18, 0); PRINTF_DEBUG(); reg04 = _pci_conf_read(sata_dev, 0x04); /* force memory and io enabled */ set_sbcfg_enable_bits(sata_dev, 0x04, 0x03 << 0, 0x03 << 0); /* ahci base addr */ base = (_pci_conf_read(sata_dev, 0x24) & 0xfffffff0) | 0xA0000000; DEBUG_INFO("ahci base addr is %x \n", base); /* 4/PM 3/SM 2/PS 1/SS */ while(ports){ count = 3; while(count){ /* judge is the phy and communication is ok */ delay(1000); // delay 1 ms reg32 = *(volatile u32 *)(base + 0x128); DEBUG_INFO("sata status : reg128 0x%x\n", reg32); if((reg32 & 0x0000000F) == 0x03){ goto drive_is_stable; } /* test if bsy bit is set, it means the drive is connected */ reg32 = *(volatile u32 *)(base + 0x120); if((reg32 & 0x80) == 0){ val = *(volatile u32 *)(base + 0x128); if((val & 0x0f) != 0x1){ goto drive_is_stable; } } count--; } /* now drive is not stable even after waitting for 1 sec,so downgrade to GEN 1 */ reg32 = *(volatile u32 *)(base + 0x12C); if((reg32 & 0x0f) == 0x10){ goto drive_is_stable; // jump if already GEN1 } /* store the sata status */ ati_sb_cfg.sb600_sata_sts |= (0x8 << ports); /* set to GEN1 : reset the status*/ reg32 = *(volatile u32 *)(base + 0x12C); reg32 = (reg32 & 0x0f) | 0x10; *(volatile u32 *)(base + 0x12C) = reg32; reg32 |= 0x01; *(volatile u32 *)(base + 0x12C) = reg32; // force 00B delay(1000); //wait 1 ms reg32 = *(volatile u32 *)(base + 0x12C); reg32 &= 0xfe; *(volatile u32 *)(base + 0x12C) = reg32; /* re detect the device again */ ports--; continue; drive_is_stable: reg32 = *(volatile u32 *)(base + 0x128); if ((reg32 & 0x0f) == 0x3){ u16 sata_bar; sata_bar = _pci_conf_readn(sata_dev, 0x10, 2); if(ports & 0x01){ sata_bar = _pci_conf_readn(sata_dev, 0x18, 2); } sata_bar &= ~(7); sata_bar += 0x06; if(ports <= 2){ val |= 0xA0; }else{ val |= 0xB0; } linux_outb(val, sata_bar); sata_bar++; timeout = 3000; while(timeout--){ val = linux_inb(sata_bar); val &= 0x88000000; if(val == 0x00){ break; } delay(10 * 1000); } /* update the status */ ati_sb_cfg.sb600_sata_sts ^= (1 << (4 - ports)); } base += 0x80; // increase status offset by 80h for next port --ports; } /* while(i) */ /* restore PCI conf cmd */ _pci_conf_write(sata_dev, 0x04, reg04); return; }