1dd4969a8SJeff Garzik /* 220b09c29SAndy Yan * Marvell 88SE64xx hardware specific 320b09c29SAndy Yan * 420b09c29SAndy Yan * Copyright 2007 Red Hat, Inc. 520b09c29SAndy Yan * Copyright 2008 Marvell. <kewei@marvell.com> 60b15fb1fSXiangliang Yu * Copyright 2009-2011 Marvell. <yuxiangl@marvell.com> 720b09c29SAndy Yan * 820b09c29SAndy Yan * This file is licensed under GPLv2. 920b09c29SAndy Yan * 1020b09c29SAndy Yan * This program is free software; you can redistribute it and/or 1120b09c29SAndy Yan * modify it under the terms of the GNU General Public License as 1220b09c29SAndy Yan * published by the Free Software Foundation; version 2 of the 1320b09c29SAndy Yan * License. 1420b09c29SAndy Yan * 1520b09c29SAndy Yan * This program is distributed in the hope that it will be useful, 1620b09c29SAndy Yan * but WITHOUT ANY WARRANTY; without even the implied warranty of 1720b09c29SAndy Yan * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1820b09c29SAndy Yan * General Public License for more details. 1920b09c29SAndy Yan * 2020b09c29SAndy Yan * You should have received a copy of the GNU General Public License 2120b09c29SAndy Yan * along with this program; if not, write to the Free Software 2220b09c29SAndy Yan * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 2320b09c29SAndy Yan * USA 24dd4969a8SJeff Garzik */ 25dd4969a8SJeff Garzik 26dd4969a8SJeff Garzik #include "mv_sas.h" 27dd4969a8SJeff Garzik #include "mv_64xx.h" 28dd4969a8SJeff Garzik #include "mv_chips.h" 29dd4969a8SJeff Garzik 3020b09c29SAndy Yan static void mvs_64xx_detect_porttype(struct mvs_info *mvi, int i) 31dd4969a8SJeff Garzik { 32dd4969a8SJeff Garzik void __iomem *regs = mvi->regs; 33dd4969a8SJeff Garzik u32 reg; 34dd4969a8SJeff Garzik struct mvs_phy *phy = &mvi->phy[i]; 35dd4969a8SJeff Garzik 3620b09c29SAndy Yan reg = mr32(MVS_GBL_PORT_TYPE); 3720b09c29SAndy Yan phy->phy_type &= ~(PORT_TYPE_SAS | PORT_TYPE_SATA); 38dd4969a8SJeff Garzik if (reg & MODE_SAS_SATA & (1 << i)) 39dd4969a8SJeff Garzik phy->phy_type |= PORT_TYPE_SAS; 40dd4969a8SJeff Garzik else 41dd4969a8SJeff Garzik phy->phy_type |= PORT_TYPE_SATA; 42dd4969a8SJeff Garzik } 43dd4969a8SJeff Garzik 4420b09c29SAndy Yan static void __devinit mvs_64xx_enable_xmt(struct mvs_info *mvi, int phy_id) 45dd4969a8SJeff Garzik { 46dd4969a8SJeff Garzik void __iomem *regs = mvi->regs; 47dd4969a8SJeff Garzik u32 tmp; 48dd4969a8SJeff Garzik 4920b09c29SAndy Yan tmp = mr32(MVS_PCS); 50a4632aaeSXiangliang Yu if (mvi->chip->n_phy <= MVS_SOC_PORTS) 5120b09c29SAndy Yan tmp |= 1 << (phy_id + PCS_EN_PORT_XMT_SHIFT); 52dd4969a8SJeff Garzik else 5320b09c29SAndy Yan tmp |= 1 << (phy_id + PCS_EN_PORT_XMT_SHIFT2); 5420b09c29SAndy Yan mw32(MVS_PCS, tmp); 55dd4969a8SJeff Garzik } 56dd4969a8SJeff Garzik 5720b09c29SAndy Yan static void __devinit mvs_64xx_phy_hacks(struct mvs_info *mvi) 58dd4969a8SJeff Garzik { 59dd4969a8SJeff Garzik void __iomem *regs = mvi->regs; 6084fbd0ceSXiangliang Yu int i; 61dd4969a8SJeff Garzik 6220b09c29SAndy Yan mvs_phy_hacks(mvi); 63dd4969a8SJeff Garzik 6420b09c29SAndy Yan if (!(mvi->flags & MVF_FLAG_SOC)) { 6584fbd0ceSXiangliang Yu for (i = 0; i < MVS_SOC_PORTS; i++) { 6684fbd0ceSXiangliang Yu mvs_write_port_vsr_addr(mvi, i, VSR_PHY_MODE8); 6784fbd0ceSXiangliang Yu mvs_write_port_vsr_data(mvi, i, 0x2F0); 6884fbd0ceSXiangliang Yu } 6920b09c29SAndy Yan } else { 7020b09c29SAndy Yan /* disable auto port detection */ 7120b09c29SAndy Yan mw32(MVS_GBL_PORT_TYPE, 0); 7220b09c29SAndy Yan for (i = 0; i < mvi->chip->n_phy; i++) { 7320b09c29SAndy Yan mvs_write_port_vsr_addr(mvi, i, VSR_PHY_MODE7); 7420b09c29SAndy Yan mvs_write_port_vsr_data(mvi, i, 0x90000000); 7520b09c29SAndy Yan mvs_write_port_vsr_addr(mvi, i, VSR_PHY_MODE9); 7620b09c29SAndy Yan mvs_write_port_vsr_data(mvi, i, 0x50f2); 7720b09c29SAndy Yan mvs_write_port_vsr_addr(mvi, i, VSR_PHY_MODE11); 7820b09c29SAndy Yan mvs_write_port_vsr_data(mvi, i, 0x0e); 7920b09c29SAndy Yan } 8020b09c29SAndy Yan } 81dd4969a8SJeff Garzik } 82dd4969a8SJeff Garzik 8320b09c29SAndy Yan static void mvs_64xx_stp_reset(struct mvs_info *mvi, u32 phy_id) 8420b09c29SAndy Yan { 8520b09c29SAndy Yan void __iomem *regs = mvi->regs; 8620b09c29SAndy Yan u32 reg, tmp; 8720b09c29SAndy Yan 8820b09c29SAndy Yan if (!(mvi->flags & MVF_FLAG_SOC)) { 89a4632aaeSXiangliang Yu if (phy_id < MVS_SOC_PORTS) 9020b09c29SAndy Yan pci_read_config_dword(mvi->pdev, PCR_PHY_CTL, ®); 9120b09c29SAndy Yan else 9220b09c29SAndy Yan pci_read_config_dword(mvi->pdev, PCR_PHY_CTL2, ®); 9320b09c29SAndy Yan 9420b09c29SAndy Yan } else 9520b09c29SAndy Yan reg = mr32(MVS_PHY_CTL); 9620b09c29SAndy Yan 9720b09c29SAndy Yan tmp = reg; 98a4632aaeSXiangliang Yu if (phy_id < MVS_SOC_PORTS) 9920b09c29SAndy Yan tmp |= (1U << phy_id) << PCTL_LINK_OFFS; 10020b09c29SAndy Yan else 101a4632aaeSXiangliang Yu tmp |= (1U << (phy_id - MVS_SOC_PORTS)) << PCTL_LINK_OFFS; 10220b09c29SAndy Yan 10320b09c29SAndy Yan if (!(mvi->flags & MVF_FLAG_SOC)) { 104a4632aaeSXiangliang Yu if (phy_id < MVS_SOC_PORTS) { 10520b09c29SAndy Yan pci_write_config_dword(mvi->pdev, PCR_PHY_CTL, tmp); 10620b09c29SAndy Yan mdelay(10); 10720b09c29SAndy Yan pci_write_config_dword(mvi->pdev, PCR_PHY_CTL, reg); 10820b09c29SAndy Yan } else { 10920b09c29SAndy Yan pci_write_config_dword(mvi->pdev, PCR_PHY_CTL2, tmp); 11020b09c29SAndy Yan mdelay(10); 11120b09c29SAndy Yan pci_write_config_dword(mvi->pdev, PCR_PHY_CTL2, reg); 11220b09c29SAndy Yan } 11320b09c29SAndy Yan } else { 11420b09c29SAndy Yan mw32(MVS_PHY_CTL, tmp); 11520b09c29SAndy Yan mdelay(10); 11620b09c29SAndy Yan mw32(MVS_PHY_CTL, reg); 11720b09c29SAndy Yan } 11820b09c29SAndy Yan } 11920b09c29SAndy Yan 12020b09c29SAndy Yan static void mvs_64xx_phy_reset(struct mvs_info *mvi, u32 phy_id, int hard) 12120b09c29SAndy Yan { 12220b09c29SAndy Yan u32 tmp; 12320b09c29SAndy Yan tmp = mvs_read_port_irq_stat(mvi, phy_id); 12420b09c29SAndy Yan tmp &= ~PHYEV_RDY_CH; 12520b09c29SAndy Yan mvs_write_port_irq_stat(mvi, phy_id, tmp); 12620b09c29SAndy Yan tmp = mvs_read_phy_ctl(mvi, phy_id); 127a4632aaeSXiangliang Yu if (hard == MVS_HARD_RESET) 12820b09c29SAndy Yan tmp |= PHY_RST_HARD; 129a4632aaeSXiangliang Yu else if (hard == MVS_SOFT_RESET) 13020b09c29SAndy Yan tmp |= PHY_RST; 13120b09c29SAndy Yan mvs_write_phy_ctl(mvi, phy_id, tmp); 13220b09c29SAndy Yan if (hard) { 13320b09c29SAndy Yan do { 13420b09c29SAndy Yan tmp = mvs_read_phy_ctl(mvi, phy_id); 13520b09c29SAndy Yan } while (tmp & PHY_RST_HARD); 13620b09c29SAndy Yan } 13720b09c29SAndy Yan } 13820b09c29SAndy Yan 1399dc9fd94SSrinivas void mvs_64xx_clear_srs_irq(struct mvs_info *mvi, u8 reg_set, u8 clear_all) 1409dc9fd94SSrinivas { 1419dc9fd94SSrinivas void __iomem *regs = mvi->regs; 1429dc9fd94SSrinivas u32 tmp; 1439dc9fd94SSrinivas if (clear_all) { 1449dc9fd94SSrinivas tmp = mr32(MVS_INT_STAT_SRS_0); 1459dc9fd94SSrinivas if (tmp) { 1469dc9fd94SSrinivas printk(KERN_DEBUG "check SRS 0 %08X.\n", tmp); 1479dc9fd94SSrinivas mw32(MVS_INT_STAT_SRS_0, tmp); 1489dc9fd94SSrinivas } 1499dc9fd94SSrinivas } else { 1509dc9fd94SSrinivas tmp = mr32(MVS_INT_STAT_SRS_0); 1519dc9fd94SSrinivas if (tmp & (1 << (reg_set % 32))) { 1529dc9fd94SSrinivas printk(KERN_DEBUG "register set 0x%x was stopped.\n", 1539dc9fd94SSrinivas reg_set); 1549dc9fd94SSrinivas mw32(MVS_INT_STAT_SRS_0, 1 << (reg_set % 32)); 1559dc9fd94SSrinivas } 1569dc9fd94SSrinivas } 1579dc9fd94SSrinivas } 1589dc9fd94SSrinivas 15920b09c29SAndy Yan static int __devinit mvs_64xx_chip_reset(struct mvs_info *mvi) 16020b09c29SAndy Yan { 16120b09c29SAndy Yan void __iomem *regs = mvi->regs; 16220b09c29SAndy Yan u32 tmp; 16320b09c29SAndy Yan int i; 16420b09c29SAndy Yan 16520b09c29SAndy Yan /* make sure interrupts are masked immediately (paranoia) */ 16620b09c29SAndy Yan mw32(MVS_GBL_CTL, 0); 16720b09c29SAndy Yan tmp = mr32(MVS_GBL_CTL); 16820b09c29SAndy Yan 16920b09c29SAndy Yan /* Reset Controller */ 17020b09c29SAndy Yan if (!(tmp & HBA_RST)) { 17120b09c29SAndy Yan if (mvi->flags & MVF_PHY_PWR_FIX) { 17220b09c29SAndy Yan pci_read_config_dword(mvi->pdev, PCR_PHY_CTL, &tmp); 17320b09c29SAndy Yan tmp &= ~PCTL_PWR_OFF; 17420b09c29SAndy Yan tmp |= PCTL_PHY_DSBL; 17520b09c29SAndy Yan pci_write_config_dword(mvi->pdev, PCR_PHY_CTL, tmp); 17620b09c29SAndy Yan 17720b09c29SAndy Yan pci_read_config_dword(mvi->pdev, PCR_PHY_CTL2, &tmp); 17820b09c29SAndy Yan tmp &= ~PCTL_PWR_OFF; 17920b09c29SAndy Yan tmp |= PCTL_PHY_DSBL; 18020b09c29SAndy Yan pci_write_config_dword(mvi->pdev, PCR_PHY_CTL2, tmp); 18120b09c29SAndy Yan } 18220b09c29SAndy Yan } 18320b09c29SAndy Yan 18420b09c29SAndy Yan /* make sure interrupts are masked immediately (paranoia) */ 18520b09c29SAndy Yan mw32(MVS_GBL_CTL, 0); 18620b09c29SAndy Yan tmp = mr32(MVS_GBL_CTL); 18720b09c29SAndy Yan 18820b09c29SAndy Yan /* Reset Controller */ 18920b09c29SAndy Yan if (!(tmp & HBA_RST)) { 19020b09c29SAndy Yan /* global reset, incl. COMRESET/H_RESET_N (self-clearing) */ 19120b09c29SAndy Yan mw32_f(MVS_GBL_CTL, HBA_RST); 19220b09c29SAndy Yan } 19320b09c29SAndy Yan 19420b09c29SAndy Yan /* wait for reset to finish; timeout is just a guess */ 19520b09c29SAndy Yan i = 1000; 19620b09c29SAndy Yan while (i-- > 0) { 19720b09c29SAndy Yan msleep(10); 19820b09c29SAndy Yan 19920b09c29SAndy Yan if (!(mr32(MVS_GBL_CTL) & HBA_RST)) 20020b09c29SAndy Yan break; 20120b09c29SAndy Yan } 20220b09c29SAndy Yan if (mr32(MVS_GBL_CTL) & HBA_RST) { 20320b09c29SAndy Yan dev_printk(KERN_ERR, mvi->dev, "HBA reset failed\n"); 20420b09c29SAndy Yan return -EBUSY; 20520b09c29SAndy Yan } 20620b09c29SAndy Yan return 0; 20720b09c29SAndy Yan } 20820b09c29SAndy Yan 20920b09c29SAndy Yan static void mvs_64xx_phy_disable(struct mvs_info *mvi, u32 phy_id) 21020b09c29SAndy Yan { 21120b09c29SAndy Yan void __iomem *regs = mvi->regs; 21220b09c29SAndy Yan u32 tmp; 21320b09c29SAndy Yan if (!(mvi->flags & MVF_FLAG_SOC)) { 21420b09c29SAndy Yan u32 offs; 21520b09c29SAndy Yan if (phy_id < 4) 21620b09c29SAndy Yan offs = PCR_PHY_CTL; 21720b09c29SAndy Yan else { 21820b09c29SAndy Yan offs = PCR_PHY_CTL2; 21920b09c29SAndy Yan phy_id -= 4; 22020b09c29SAndy Yan } 22120b09c29SAndy Yan pci_read_config_dword(mvi->pdev, offs, &tmp); 22220b09c29SAndy Yan tmp |= 1U << (PCTL_PHY_DSBL_OFFS + phy_id); 22320b09c29SAndy Yan pci_write_config_dword(mvi->pdev, offs, tmp); 22420b09c29SAndy Yan } else { 22520b09c29SAndy Yan tmp = mr32(MVS_PHY_CTL); 22620b09c29SAndy Yan tmp |= 1U << (PCTL_PHY_DSBL_OFFS + phy_id); 22720b09c29SAndy Yan mw32(MVS_PHY_CTL, tmp); 22820b09c29SAndy Yan } 22920b09c29SAndy Yan } 23020b09c29SAndy Yan 23120b09c29SAndy Yan static void mvs_64xx_phy_enable(struct mvs_info *mvi, u32 phy_id) 23220b09c29SAndy Yan { 23320b09c29SAndy Yan void __iomem *regs = mvi->regs; 23420b09c29SAndy Yan u32 tmp; 23520b09c29SAndy Yan if (!(mvi->flags & MVF_FLAG_SOC)) { 23620b09c29SAndy Yan u32 offs; 23720b09c29SAndy Yan if (phy_id < 4) 23820b09c29SAndy Yan offs = PCR_PHY_CTL; 23920b09c29SAndy Yan else { 24020b09c29SAndy Yan offs = PCR_PHY_CTL2; 24120b09c29SAndy Yan phy_id -= 4; 24220b09c29SAndy Yan } 24320b09c29SAndy Yan pci_read_config_dword(mvi->pdev, offs, &tmp); 24420b09c29SAndy Yan tmp &= ~(1U << (PCTL_PHY_DSBL_OFFS + phy_id)); 24520b09c29SAndy Yan pci_write_config_dword(mvi->pdev, offs, tmp); 24620b09c29SAndy Yan } else { 24720b09c29SAndy Yan tmp = mr32(MVS_PHY_CTL); 24820b09c29SAndy Yan tmp &= ~(1U << (PCTL_PHY_DSBL_OFFS + phy_id)); 24920b09c29SAndy Yan mw32(MVS_PHY_CTL, tmp); 25020b09c29SAndy Yan } 25120b09c29SAndy Yan } 25220b09c29SAndy Yan 25320b09c29SAndy Yan static int __devinit mvs_64xx_init(struct mvs_info *mvi) 25420b09c29SAndy Yan { 25520b09c29SAndy Yan void __iomem *regs = mvi->regs; 25620b09c29SAndy Yan int i; 25720b09c29SAndy Yan u32 tmp, cctl; 25820b09c29SAndy Yan 25920b09c29SAndy Yan if (mvi->pdev && mvi->pdev->revision == 0) 26020b09c29SAndy Yan mvi->flags |= MVF_PHY_PWR_FIX; 26120b09c29SAndy Yan if (!(mvi->flags & MVF_FLAG_SOC)) { 26220b09c29SAndy Yan mvs_show_pcie_usage(mvi); 26320b09c29SAndy Yan tmp = mvs_64xx_chip_reset(mvi); 26420b09c29SAndy Yan if (tmp) 26520b09c29SAndy Yan return tmp; 26620b09c29SAndy Yan } else { 26720b09c29SAndy Yan tmp = mr32(MVS_PHY_CTL); 26820b09c29SAndy Yan tmp &= ~PCTL_PWR_OFF; 26920b09c29SAndy Yan tmp |= PCTL_PHY_DSBL; 27020b09c29SAndy Yan mw32(MVS_PHY_CTL, tmp); 27120b09c29SAndy Yan } 27220b09c29SAndy Yan 27320b09c29SAndy Yan /* Init Chip */ 27420b09c29SAndy Yan /* make sure RST is set; HBA_RST /should/ have done that for us */ 27520b09c29SAndy Yan cctl = mr32(MVS_CTL) & 0xFFFF; 27620b09c29SAndy Yan if (cctl & CCTL_RST) 27720b09c29SAndy Yan cctl &= ~CCTL_RST; 27820b09c29SAndy Yan else 27920b09c29SAndy Yan mw32_f(MVS_CTL, cctl | CCTL_RST); 28020b09c29SAndy Yan 28120b09c29SAndy Yan if (!(mvi->flags & MVF_FLAG_SOC)) { 28220b09c29SAndy Yan /* write to device control _AND_ device status register */ 28320b09c29SAndy Yan pci_read_config_dword(mvi->pdev, PCR_DEV_CTRL, &tmp); 28420b09c29SAndy Yan tmp &= ~PRD_REQ_MASK; 28520b09c29SAndy Yan tmp |= PRD_REQ_SIZE; 28620b09c29SAndy Yan pci_write_config_dword(mvi->pdev, PCR_DEV_CTRL, tmp); 28720b09c29SAndy Yan 28820b09c29SAndy Yan pci_read_config_dword(mvi->pdev, PCR_PHY_CTL, &tmp); 28920b09c29SAndy Yan tmp &= ~PCTL_PWR_OFF; 29020b09c29SAndy Yan tmp &= ~PCTL_PHY_DSBL; 29120b09c29SAndy Yan pci_write_config_dword(mvi->pdev, PCR_PHY_CTL, tmp); 29220b09c29SAndy Yan 29320b09c29SAndy Yan pci_read_config_dword(mvi->pdev, PCR_PHY_CTL2, &tmp); 29420b09c29SAndy Yan tmp &= PCTL_PWR_OFF; 29520b09c29SAndy Yan tmp &= ~PCTL_PHY_DSBL; 29620b09c29SAndy Yan pci_write_config_dword(mvi->pdev, PCR_PHY_CTL2, tmp); 29720b09c29SAndy Yan } else { 29820b09c29SAndy Yan tmp = mr32(MVS_PHY_CTL); 29920b09c29SAndy Yan tmp &= ~PCTL_PWR_OFF; 30020b09c29SAndy Yan tmp |= PCTL_COM_ON; 30120b09c29SAndy Yan tmp &= ~PCTL_PHY_DSBL; 30220b09c29SAndy Yan tmp |= PCTL_LINK_RST; 30320b09c29SAndy Yan mw32(MVS_PHY_CTL, tmp); 30420b09c29SAndy Yan msleep(100); 30520b09c29SAndy Yan tmp &= ~PCTL_LINK_RST; 30620b09c29SAndy Yan mw32(MVS_PHY_CTL, tmp); 30720b09c29SAndy Yan msleep(100); 30820b09c29SAndy Yan } 30920b09c29SAndy Yan 31020b09c29SAndy Yan /* reset control */ 31120b09c29SAndy Yan mw32(MVS_PCS, 0); /* MVS_PCS */ 31220b09c29SAndy Yan /* init phys */ 31320b09c29SAndy Yan mvs_64xx_phy_hacks(mvi); 31420b09c29SAndy Yan 31584fbd0ceSXiangliang Yu tmp = mvs_cr32(mvi, CMD_PHY_MODE_21); 31684fbd0ceSXiangliang Yu tmp &= 0x0000ffff; 31784fbd0ceSXiangliang Yu tmp |= 0x00fa0000; 31884fbd0ceSXiangliang Yu mvs_cw32(mvi, CMD_PHY_MODE_21, tmp); 31984fbd0ceSXiangliang Yu 32020b09c29SAndy Yan /* enable auto port detection */ 32120b09c29SAndy Yan mw32(MVS_GBL_PORT_TYPE, MODE_AUTO_DET_EN); 32220b09c29SAndy Yan 32320b09c29SAndy Yan mw32(MVS_CMD_LIST_LO, mvi->slot_dma); 32420b09c29SAndy Yan mw32(MVS_CMD_LIST_HI, (mvi->slot_dma >> 16) >> 16); 32520b09c29SAndy Yan 32620b09c29SAndy Yan mw32(MVS_RX_FIS_LO, mvi->rx_fis_dma); 32720b09c29SAndy Yan mw32(MVS_RX_FIS_HI, (mvi->rx_fis_dma >> 16) >> 16); 32820b09c29SAndy Yan 32920b09c29SAndy Yan mw32(MVS_TX_CFG, MVS_CHIP_SLOT_SZ); 33020b09c29SAndy Yan mw32(MVS_TX_LO, mvi->tx_dma); 33120b09c29SAndy Yan mw32(MVS_TX_HI, (mvi->tx_dma >> 16) >> 16); 33220b09c29SAndy Yan 33320b09c29SAndy Yan mw32(MVS_RX_CFG, MVS_RX_RING_SZ); 33420b09c29SAndy Yan mw32(MVS_RX_LO, mvi->rx_dma); 33520b09c29SAndy Yan mw32(MVS_RX_HI, (mvi->rx_dma >> 16) >> 16); 33620b09c29SAndy Yan 33720b09c29SAndy Yan for (i = 0; i < mvi->chip->n_phy; i++) { 33820b09c29SAndy Yan /* set phy local SAS address */ 33920b09c29SAndy Yan /* should set little endian SAS address to 64xx chip */ 34020b09c29SAndy Yan mvs_set_sas_addr(mvi, i, PHYR_ADDR_LO, PHYR_ADDR_HI, 34120b09c29SAndy Yan cpu_to_be64(mvi->phy[i].dev_sas_addr)); 34220b09c29SAndy Yan 34320b09c29SAndy Yan mvs_64xx_enable_xmt(mvi, i); 34420b09c29SAndy Yan 345a4632aaeSXiangliang Yu mvs_64xx_phy_reset(mvi, i, MVS_HARD_RESET); 34620b09c29SAndy Yan msleep(500); 34720b09c29SAndy Yan mvs_64xx_detect_porttype(mvi, i); 34820b09c29SAndy Yan } 34920b09c29SAndy Yan if (mvi->flags & MVF_FLAG_SOC) { 35020b09c29SAndy Yan /* set select registers */ 35120b09c29SAndy Yan writel(0x0E008000, regs + 0x000); 35220b09c29SAndy Yan writel(0x59000008, regs + 0x004); 35320b09c29SAndy Yan writel(0x20, regs + 0x008); 35420b09c29SAndy Yan writel(0x20, regs + 0x00c); 35520b09c29SAndy Yan writel(0x20, regs + 0x010); 35620b09c29SAndy Yan writel(0x20, regs + 0x014); 35720b09c29SAndy Yan writel(0x20, regs + 0x018); 35820b09c29SAndy Yan writel(0x20, regs + 0x01c); 35920b09c29SAndy Yan } 36020b09c29SAndy Yan for (i = 0; i < mvi->chip->n_phy; i++) { 36120b09c29SAndy Yan /* clear phy int status */ 36220b09c29SAndy Yan tmp = mvs_read_port_irq_stat(mvi, i); 36320b09c29SAndy Yan tmp &= ~PHYEV_SIG_FIS; 36420b09c29SAndy Yan mvs_write_port_irq_stat(mvi, i, tmp); 36520b09c29SAndy Yan 36620b09c29SAndy Yan /* set phy int mask */ 36720b09c29SAndy Yan tmp = PHYEV_RDY_CH | PHYEV_BROAD_CH | PHYEV_UNASSOC_FIS | 36820b09c29SAndy Yan PHYEV_ID_DONE | PHYEV_DCDR_ERR | PHYEV_CRC_ERR | 36920b09c29SAndy Yan PHYEV_DEC_ERR; 37020b09c29SAndy Yan mvs_write_port_irq_mask(mvi, i, tmp); 37120b09c29SAndy Yan 37220b09c29SAndy Yan msleep(100); 37320b09c29SAndy Yan mvs_update_phyinfo(mvi, i, 1); 37420b09c29SAndy Yan } 37520b09c29SAndy Yan 37620b09c29SAndy Yan /* little endian for open address and command table, etc. */ 37720b09c29SAndy Yan cctl = mr32(MVS_CTL); 37820b09c29SAndy Yan cctl |= CCTL_ENDIAN_CMD; 37920b09c29SAndy Yan cctl |= CCTL_ENDIAN_DATA; 38020b09c29SAndy Yan cctl &= ~CCTL_ENDIAN_OPEN; 38120b09c29SAndy Yan cctl |= CCTL_ENDIAN_RSP; 38220b09c29SAndy Yan mw32_f(MVS_CTL, cctl); 38320b09c29SAndy Yan 38420b09c29SAndy Yan /* reset CMD queue */ 38520b09c29SAndy Yan tmp = mr32(MVS_PCS); 38620b09c29SAndy Yan tmp |= PCS_CMD_RST; 38784fbd0ceSXiangliang Yu tmp &= ~PCS_SELF_CLEAR; 38820b09c29SAndy Yan mw32(MVS_PCS, tmp); 389e144f7efSXiangliang Yu /* 390e144f7efSXiangliang Yu * the max count is 0x1ff, while our max slot is 0x200, 39120b09c29SAndy Yan * it will make count 0. 39220b09c29SAndy Yan */ 39320b09c29SAndy Yan tmp = 0; 39484fbd0ceSXiangliang Yu if (MVS_CHIP_SLOT_SZ > 0x1ff) 39584fbd0ceSXiangliang Yu mw32(MVS_INT_COAL, 0x1ff | COAL_EN); 39684fbd0ceSXiangliang Yu else 39784fbd0ceSXiangliang Yu mw32(MVS_INT_COAL, MVS_CHIP_SLOT_SZ | COAL_EN); 39820b09c29SAndy Yan 39983c7b61cSXiangliang Yu tmp = 0x10000 | interrupt_coalescing; 40020b09c29SAndy Yan mw32(MVS_INT_COAL_TMOUT, tmp); 40120b09c29SAndy Yan 40220b09c29SAndy Yan /* ladies and gentlemen, start your engines */ 40320b09c29SAndy Yan mw32(MVS_TX_CFG, 0); 40420b09c29SAndy Yan mw32(MVS_TX_CFG, MVS_CHIP_SLOT_SZ | TX_EN); 40520b09c29SAndy Yan mw32(MVS_RX_CFG, MVS_RX_RING_SZ | RX_EN); 40620b09c29SAndy Yan /* enable CMD/CMPL_Q/RESP mode */ 40720b09c29SAndy Yan mw32(MVS_PCS, PCS_SATA_RETRY | PCS_FIS_RX_EN | 40820b09c29SAndy Yan PCS_CMD_EN | PCS_CMD_STOP_ERR); 40920b09c29SAndy Yan 41020b09c29SAndy Yan /* enable completion queue interrupt */ 41120b09c29SAndy Yan tmp = (CINT_PORT_MASK | CINT_DONE | CINT_MEM | CINT_SRS | CINT_CI_STOP | 41220b09c29SAndy Yan CINT_DMA_PCIE); 41320b09c29SAndy Yan 41420b09c29SAndy Yan mw32(MVS_INT_MASK, tmp); 41520b09c29SAndy Yan 41620b09c29SAndy Yan /* Enable SRS interrupt */ 41720b09c29SAndy Yan mw32(MVS_INT_MASK_SRS_0, 0xFFFF); 41820b09c29SAndy Yan 41920b09c29SAndy Yan return 0; 42020b09c29SAndy Yan } 42120b09c29SAndy Yan 42220b09c29SAndy Yan static int mvs_64xx_ioremap(struct mvs_info *mvi) 42320b09c29SAndy Yan { 42420b09c29SAndy Yan if (!mvs_ioremap(mvi, 4, 2)) 42520b09c29SAndy Yan return 0; 42620b09c29SAndy Yan return -1; 42720b09c29SAndy Yan } 42820b09c29SAndy Yan 42920b09c29SAndy Yan static void mvs_64xx_iounmap(struct mvs_info *mvi) 43020b09c29SAndy Yan { 43120b09c29SAndy Yan mvs_iounmap(mvi->regs); 43220b09c29SAndy Yan mvs_iounmap(mvi->regs_ex); 43320b09c29SAndy Yan } 43420b09c29SAndy Yan 43520b09c29SAndy Yan static void mvs_64xx_interrupt_enable(struct mvs_info *mvi) 436dd4969a8SJeff Garzik { 437dd4969a8SJeff Garzik void __iomem *regs = mvi->regs; 438dd4969a8SJeff Garzik u32 tmp; 439dd4969a8SJeff Garzik 44020b09c29SAndy Yan tmp = mr32(MVS_GBL_CTL); 44120b09c29SAndy Yan mw32(MVS_GBL_CTL, tmp | INT_EN); 442dd4969a8SJeff Garzik } 443dd4969a8SJeff Garzik 44420b09c29SAndy Yan static void mvs_64xx_interrupt_disable(struct mvs_info *mvi) 445dd4969a8SJeff Garzik { 446dd4969a8SJeff Garzik void __iomem *regs = mvi->regs; 447dd4969a8SJeff Garzik u32 tmp; 448dd4969a8SJeff Garzik 44920b09c29SAndy Yan tmp = mr32(MVS_GBL_CTL); 45020b09c29SAndy Yan mw32(MVS_GBL_CTL, tmp & ~INT_EN); 451dd4969a8SJeff Garzik } 452dd4969a8SJeff Garzik 45320b09c29SAndy Yan static u32 mvs_64xx_isr_status(struct mvs_info *mvi, int irq) 45420b09c29SAndy Yan { 45520b09c29SAndy Yan void __iomem *regs = mvi->regs; 45620b09c29SAndy Yan u32 stat; 45720b09c29SAndy Yan 45820b09c29SAndy Yan if (!(mvi->flags & MVF_FLAG_SOC)) { 45920b09c29SAndy Yan stat = mr32(MVS_GBL_INT_STAT); 46020b09c29SAndy Yan 46120b09c29SAndy Yan if (stat == 0 || stat == 0xffffffff) 46220b09c29SAndy Yan return 0; 46320b09c29SAndy Yan } else 46420b09c29SAndy Yan stat = 1; 46520b09c29SAndy Yan return stat; 46620b09c29SAndy Yan } 46720b09c29SAndy Yan 46820b09c29SAndy Yan static irqreturn_t mvs_64xx_isr(struct mvs_info *mvi, int irq, u32 stat) 46920b09c29SAndy Yan { 47020b09c29SAndy Yan void __iomem *regs = mvi->regs; 47120b09c29SAndy Yan 47220b09c29SAndy Yan /* clear CMD_CMPLT ASAP */ 47320b09c29SAndy Yan mw32_f(MVS_INT_STAT, CINT_DONE); 474*6f8ac161SXiangliang Yu 47520b09c29SAndy Yan spin_lock(&mvi->lock); 47620b09c29SAndy Yan mvs_int_full(mvi); 47720b09c29SAndy Yan spin_unlock(&mvi->lock); 478*6f8ac161SXiangliang Yu 47920b09c29SAndy Yan return IRQ_HANDLED; 48020b09c29SAndy Yan } 48120b09c29SAndy Yan 48220b09c29SAndy Yan static void mvs_64xx_command_active(struct mvs_info *mvi, u32 slot_idx) 48320b09c29SAndy Yan { 48420b09c29SAndy Yan u32 tmp; 48520b09c29SAndy Yan mvs_cw32(mvi, 0x40 + (slot_idx >> 3), 1 << (slot_idx % 32)); 48620b09c29SAndy Yan mvs_cw32(mvi, 0x00 + (slot_idx >> 3), 1 << (slot_idx % 32)); 48720b09c29SAndy Yan do { 48820b09c29SAndy Yan tmp = mvs_cr32(mvi, 0x00 + (slot_idx >> 3)); 48920b09c29SAndy Yan } while (tmp & 1 << (slot_idx % 32)); 49020b09c29SAndy Yan do { 49120b09c29SAndy Yan tmp = mvs_cr32(mvi, 0x40 + (slot_idx >> 3)); 49220b09c29SAndy Yan } while (tmp & 1 << (slot_idx % 32)); 49320b09c29SAndy Yan } 49420b09c29SAndy Yan 49520b09c29SAndy Yan static void mvs_64xx_issue_stop(struct mvs_info *mvi, enum mvs_port_type type, 49620b09c29SAndy Yan u32 tfs) 49720b09c29SAndy Yan { 49820b09c29SAndy Yan void __iomem *regs = mvi->regs; 49920b09c29SAndy Yan u32 tmp; 50020b09c29SAndy Yan 50120b09c29SAndy Yan if (type == PORT_TYPE_SATA) { 50220b09c29SAndy Yan tmp = mr32(MVS_INT_STAT_SRS_0) | (1U << tfs); 50320b09c29SAndy Yan mw32(MVS_INT_STAT_SRS_0, tmp); 50420b09c29SAndy Yan } 50520b09c29SAndy Yan mw32(MVS_INT_STAT, CINT_CI_STOP); 50620b09c29SAndy Yan tmp = mr32(MVS_PCS) | 0xFF00; 50720b09c29SAndy Yan mw32(MVS_PCS, tmp); 50820b09c29SAndy Yan } 50920b09c29SAndy Yan 51020b09c29SAndy Yan static void mvs_64xx_free_reg_set(struct mvs_info *mvi, u8 *tfs) 511dd4969a8SJeff Garzik { 512dd4969a8SJeff Garzik void __iomem *regs = mvi->regs; 513dd4969a8SJeff Garzik u32 tmp, offs; 514dd4969a8SJeff Garzik 515dd4969a8SJeff Garzik if (*tfs == MVS_ID_NOT_MAPPED) 516dd4969a8SJeff Garzik return; 517dd4969a8SJeff Garzik 518dd4969a8SJeff Garzik offs = 1U << ((*tfs & 0x0f) + PCS_EN_SATA_REG_SHIFT); 519dd4969a8SJeff Garzik if (*tfs < 16) { 52020b09c29SAndy Yan tmp = mr32(MVS_PCS); 52120b09c29SAndy Yan mw32(MVS_PCS, tmp & ~offs); 522dd4969a8SJeff Garzik } else { 52320b09c29SAndy Yan tmp = mr32(MVS_CTL); 52420b09c29SAndy Yan mw32(MVS_CTL, tmp & ~offs); 525dd4969a8SJeff Garzik } 526dd4969a8SJeff Garzik 52720b09c29SAndy Yan tmp = mr32(MVS_INT_STAT_SRS_0) & (1U << *tfs); 528dd4969a8SJeff Garzik if (tmp) 52920b09c29SAndy Yan mw32(MVS_INT_STAT_SRS_0, tmp); 530dd4969a8SJeff Garzik 531dd4969a8SJeff Garzik *tfs = MVS_ID_NOT_MAPPED; 53220b09c29SAndy Yan return; 533dd4969a8SJeff Garzik } 534dd4969a8SJeff Garzik 53520b09c29SAndy Yan static u8 mvs_64xx_assign_reg_set(struct mvs_info *mvi, u8 *tfs) 536dd4969a8SJeff Garzik { 537dd4969a8SJeff Garzik int i; 538dd4969a8SJeff Garzik u32 tmp, offs; 539dd4969a8SJeff Garzik void __iomem *regs = mvi->regs; 540dd4969a8SJeff Garzik 54120b09c29SAndy Yan if (*tfs != MVS_ID_NOT_MAPPED) 542dd4969a8SJeff Garzik return 0; 543dd4969a8SJeff Garzik 54420b09c29SAndy Yan tmp = mr32(MVS_PCS); 545dd4969a8SJeff Garzik 546dd4969a8SJeff Garzik for (i = 0; i < mvi->chip->srs_sz; i++) { 547dd4969a8SJeff Garzik if (i == 16) 54820b09c29SAndy Yan tmp = mr32(MVS_CTL); 549dd4969a8SJeff Garzik offs = 1U << ((i & 0x0f) + PCS_EN_SATA_REG_SHIFT); 550dd4969a8SJeff Garzik if (!(tmp & offs)) { 55120b09c29SAndy Yan *tfs = i; 552dd4969a8SJeff Garzik 553dd4969a8SJeff Garzik if (i < 16) 55420b09c29SAndy Yan mw32(MVS_PCS, tmp | offs); 555dd4969a8SJeff Garzik else 55620b09c29SAndy Yan mw32(MVS_CTL, tmp | offs); 55720b09c29SAndy Yan tmp = mr32(MVS_INT_STAT_SRS_0) & (1U << i); 558dd4969a8SJeff Garzik if (tmp) 55920b09c29SAndy Yan mw32(MVS_INT_STAT_SRS_0, tmp); 560dd4969a8SJeff Garzik return 0; 561dd4969a8SJeff Garzik } 562dd4969a8SJeff Garzik } 563dd4969a8SJeff Garzik return MVS_ID_NOT_MAPPED; 564dd4969a8SJeff Garzik } 565dd4969a8SJeff Garzik 56620b09c29SAndy Yan void mvs_64xx_make_prd(struct scatterlist *scatter, int nr, void *prd) 56720b09c29SAndy Yan { 56820b09c29SAndy Yan int i; 56920b09c29SAndy Yan struct scatterlist *sg; 57020b09c29SAndy Yan struct mvs_prd *buf_prd = prd; 57120b09c29SAndy Yan for_each_sg(scatter, sg, nr, i) { 57220b09c29SAndy Yan buf_prd->addr = cpu_to_le64(sg_dma_address(sg)); 57320b09c29SAndy Yan buf_prd->len = cpu_to_le32(sg_dma_len(sg)); 57420b09c29SAndy Yan buf_prd++; 57520b09c29SAndy Yan } 57620b09c29SAndy Yan } 57720b09c29SAndy Yan 57820b09c29SAndy Yan static int mvs_64xx_oob_done(struct mvs_info *mvi, int i) 57920b09c29SAndy Yan { 58020b09c29SAndy Yan u32 phy_st; 58120b09c29SAndy Yan mvs_write_port_cfg_addr(mvi, i, 58220b09c29SAndy Yan PHYR_PHY_STAT); 58320b09c29SAndy Yan phy_st = mvs_read_port_cfg_data(mvi, i); 58420b09c29SAndy Yan if (phy_st & PHY_OOB_DTCTD) 58520b09c29SAndy Yan return 1; 58620b09c29SAndy Yan return 0; 58720b09c29SAndy Yan } 58820b09c29SAndy Yan 58920b09c29SAndy Yan static void mvs_64xx_fix_phy_info(struct mvs_info *mvi, int i, 59020b09c29SAndy Yan struct sas_identify_frame *id) 59120b09c29SAndy Yan 59220b09c29SAndy Yan { 59320b09c29SAndy Yan struct mvs_phy *phy = &mvi->phy[i]; 59420b09c29SAndy Yan struct asd_sas_phy *sas_phy = &phy->sas_phy; 59520b09c29SAndy Yan 59620b09c29SAndy Yan sas_phy->linkrate = 59720b09c29SAndy Yan (phy->phy_status & PHY_NEG_SPP_PHYS_LINK_RATE_MASK) >> 59820b09c29SAndy Yan PHY_NEG_SPP_PHYS_LINK_RATE_MASK_OFFSET; 59920b09c29SAndy Yan 60020b09c29SAndy Yan phy->minimum_linkrate = 60120b09c29SAndy Yan (phy->phy_status & 60220b09c29SAndy Yan PHY_MIN_SPP_PHYS_LINK_RATE_MASK) >> 8; 60320b09c29SAndy Yan phy->maximum_linkrate = 60420b09c29SAndy Yan (phy->phy_status & 60520b09c29SAndy Yan PHY_MAX_SPP_PHYS_LINK_RATE_MASK) >> 12; 60620b09c29SAndy Yan 60720b09c29SAndy Yan mvs_write_port_cfg_addr(mvi, i, PHYR_IDENTIFY); 60820b09c29SAndy Yan phy->dev_info = mvs_read_port_cfg_data(mvi, i); 60920b09c29SAndy Yan 61020b09c29SAndy Yan mvs_write_port_cfg_addr(mvi, i, PHYR_ATT_DEV_INFO); 61120b09c29SAndy Yan phy->att_dev_info = mvs_read_port_cfg_data(mvi, i); 61220b09c29SAndy Yan 61320b09c29SAndy Yan mvs_write_port_cfg_addr(mvi, i, PHYR_ATT_ADDR_HI); 61420b09c29SAndy Yan phy->att_dev_sas_addr = 61520b09c29SAndy Yan (u64) mvs_read_port_cfg_data(mvi, i) << 32; 61620b09c29SAndy Yan mvs_write_port_cfg_addr(mvi, i, PHYR_ATT_ADDR_LO); 61720b09c29SAndy Yan phy->att_dev_sas_addr |= mvs_read_port_cfg_data(mvi, i); 61820b09c29SAndy Yan phy->att_dev_sas_addr = SAS_ADDR(&phy->att_dev_sas_addr); 61920b09c29SAndy Yan } 62020b09c29SAndy Yan 62120b09c29SAndy Yan static void mvs_64xx_phy_work_around(struct mvs_info *mvi, int i) 62220b09c29SAndy Yan { 62320b09c29SAndy Yan u32 tmp; 62420b09c29SAndy Yan struct mvs_phy *phy = &mvi->phy[i]; 62520b09c29SAndy Yan mvs_write_port_vsr_addr(mvi, i, VSR_PHY_MODE6); 62620b09c29SAndy Yan tmp = mvs_read_port_vsr_data(mvi, i); 62720b09c29SAndy Yan if (((phy->phy_status & PHY_NEG_SPP_PHYS_LINK_RATE_MASK) >> 62820b09c29SAndy Yan PHY_NEG_SPP_PHYS_LINK_RATE_MASK_OFFSET) == 62920b09c29SAndy Yan SAS_LINK_RATE_1_5_GBPS) 63020b09c29SAndy Yan tmp &= ~PHY_MODE6_LATECLK; 63120b09c29SAndy Yan else 63220b09c29SAndy Yan tmp |= PHY_MODE6_LATECLK; 63320b09c29SAndy Yan mvs_write_port_vsr_data(mvi, i, tmp); 63420b09c29SAndy Yan } 63520b09c29SAndy Yan 63620b09c29SAndy Yan void mvs_64xx_phy_set_link_rate(struct mvs_info *mvi, u32 phy_id, 63720b09c29SAndy Yan struct sas_phy_linkrates *rates) 63820b09c29SAndy Yan { 63920b09c29SAndy Yan u32 lrmin = 0, lrmax = 0; 64020b09c29SAndy Yan u32 tmp; 64120b09c29SAndy Yan 64220b09c29SAndy Yan tmp = mvs_read_phy_ctl(mvi, phy_id); 64320b09c29SAndy Yan lrmin = (rates->minimum_linkrate << 8); 64420b09c29SAndy Yan lrmax = (rates->maximum_linkrate << 12); 64520b09c29SAndy Yan 64620b09c29SAndy Yan if (lrmin) { 64720b09c29SAndy Yan tmp &= ~(0xf << 8); 64820b09c29SAndy Yan tmp |= lrmin; 64920b09c29SAndy Yan } 65020b09c29SAndy Yan if (lrmax) { 65120b09c29SAndy Yan tmp &= ~(0xf << 12); 65220b09c29SAndy Yan tmp |= lrmax; 65320b09c29SAndy Yan } 65420b09c29SAndy Yan mvs_write_phy_ctl(mvi, phy_id, tmp); 655a4632aaeSXiangliang Yu mvs_64xx_phy_reset(mvi, phy_id, MVS_HARD_RESET); 65620b09c29SAndy Yan } 65720b09c29SAndy Yan 65820b09c29SAndy Yan static void mvs_64xx_clear_active_cmds(struct mvs_info *mvi) 65920b09c29SAndy Yan { 66020b09c29SAndy Yan u32 tmp; 66120b09c29SAndy Yan void __iomem *regs = mvi->regs; 66220b09c29SAndy Yan tmp = mr32(MVS_PCS); 66320b09c29SAndy Yan mw32(MVS_PCS, tmp & 0xFFFF); 66420b09c29SAndy Yan mw32(MVS_PCS, tmp); 66520b09c29SAndy Yan tmp = mr32(MVS_CTL); 66620b09c29SAndy Yan mw32(MVS_CTL, tmp & 0xFFFF); 66720b09c29SAndy Yan mw32(MVS_CTL, tmp); 66820b09c29SAndy Yan } 66920b09c29SAndy Yan 67020b09c29SAndy Yan 67120b09c29SAndy Yan u32 mvs_64xx_spi_read_data(struct mvs_info *mvi) 67220b09c29SAndy Yan { 67320b09c29SAndy Yan void __iomem *regs = mvi->regs_ex; 67420b09c29SAndy Yan return ior32(SPI_DATA_REG_64XX); 67520b09c29SAndy Yan } 67620b09c29SAndy Yan 67720b09c29SAndy Yan void mvs_64xx_spi_write_data(struct mvs_info *mvi, u32 data) 67820b09c29SAndy Yan { 67920b09c29SAndy Yan void __iomem *regs = mvi->regs_ex; 68020b09c29SAndy Yan iow32(SPI_DATA_REG_64XX, data); 68120b09c29SAndy Yan } 68220b09c29SAndy Yan 68320b09c29SAndy Yan 68420b09c29SAndy Yan int mvs_64xx_spi_buildcmd(struct mvs_info *mvi, 68520b09c29SAndy Yan u32 *dwCmd, 68620b09c29SAndy Yan u8 cmd, 68720b09c29SAndy Yan u8 read, 68820b09c29SAndy Yan u8 length, 68920b09c29SAndy Yan u32 addr 69020b09c29SAndy Yan ) 69120b09c29SAndy Yan { 69220b09c29SAndy Yan u32 dwTmp; 69320b09c29SAndy Yan 69420b09c29SAndy Yan dwTmp = ((u32)cmd << 24) | ((u32)length << 19); 69520b09c29SAndy Yan if (read) 69620b09c29SAndy Yan dwTmp |= 1U<<23; 69720b09c29SAndy Yan 69820b09c29SAndy Yan if (addr != MV_MAX_U32) { 69920b09c29SAndy Yan dwTmp |= 1U<<22; 70020b09c29SAndy Yan dwTmp |= (addr & 0x0003FFFF); 70120b09c29SAndy Yan } 70220b09c29SAndy Yan 70320b09c29SAndy Yan *dwCmd = dwTmp; 70420b09c29SAndy Yan return 0; 70520b09c29SAndy Yan } 70620b09c29SAndy Yan 70720b09c29SAndy Yan 70820b09c29SAndy Yan int mvs_64xx_spi_issuecmd(struct mvs_info *mvi, u32 cmd) 70920b09c29SAndy Yan { 71020b09c29SAndy Yan void __iomem *regs = mvi->regs_ex; 71120b09c29SAndy Yan int retry; 71220b09c29SAndy Yan 71320b09c29SAndy Yan for (retry = 0; retry < 1; retry++) { 71420b09c29SAndy Yan iow32(SPI_CTRL_REG_64XX, SPI_CTRL_VENDOR_ENABLE); 71520b09c29SAndy Yan iow32(SPI_CMD_REG_64XX, cmd); 71620b09c29SAndy Yan iow32(SPI_CTRL_REG_64XX, 71720b09c29SAndy Yan SPI_CTRL_VENDOR_ENABLE | SPI_CTRL_SPISTART); 71820b09c29SAndy Yan } 71920b09c29SAndy Yan 72020b09c29SAndy Yan return 0; 72120b09c29SAndy Yan } 72220b09c29SAndy Yan 72320b09c29SAndy Yan int mvs_64xx_spi_waitdataready(struct mvs_info *mvi, u32 timeout) 72420b09c29SAndy Yan { 72520b09c29SAndy Yan void __iomem *regs = mvi->regs_ex; 72620b09c29SAndy Yan u32 i, dwTmp; 72720b09c29SAndy Yan 72820b09c29SAndy Yan for (i = 0; i < timeout; i++) { 72920b09c29SAndy Yan dwTmp = ior32(SPI_CTRL_REG_64XX); 73020b09c29SAndy Yan if (!(dwTmp & SPI_CTRL_SPISTART)) 73120b09c29SAndy Yan return 0; 73220b09c29SAndy Yan msleep(10); 73320b09c29SAndy Yan } 73420b09c29SAndy Yan 73520b09c29SAndy Yan return -1; 73620b09c29SAndy Yan } 73720b09c29SAndy Yan 7388882f081SXiangliang Yu void mvs_64xx_fix_dma(struct mvs_info *mvi, u32 phy_mask, 7398882f081SXiangliang Yu int buf_len, int from, void *prd) 74020b09c29SAndy Yan { 74120b09c29SAndy Yan int i; 74220b09c29SAndy Yan struct mvs_prd *buf_prd = prd; 7438882f081SXiangliang Yu dma_addr_t buf_dma = mvi->bulk_buffer_dma; 7448882f081SXiangliang Yu 74520b09c29SAndy Yan buf_prd += from; 74620b09c29SAndy Yan for (i = 0; i < MAX_SG_ENTRY - from; i++) { 74720b09c29SAndy Yan buf_prd->addr = cpu_to_le64(buf_dma); 74820b09c29SAndy Yan buf_prd->len = cpu_to_le32(buf_len); 74920b09c29SAndy Yan ++buf_prd; 75020b09c29SAndy Yan } 75120b09c29SAndy Yan } 75220b09c29SAndy Yan 75383c7b61cSXiangliang Yu static void mvs_64xx_tune_interrupt(struct mvs_info *mvi, u32 time) 75483c7b61cSXiangliang Yu { 75583c7b61cSXiangliang Yu void __iomem *regs = mvi->regs; 75683c7b61cSXiangliang Yu u32 tmp = 0; 757e144f7efSXiangliang Yu /* 758e144f7efSXiangliang Yu * the max count is 0x1ff, while our max slot is 0x200, 75983c7b61cSXiangliang Yu * it will make count 0. 76083c7b61cSXiangliang Yu */ 76183c7b61cSXiangliang Yu if (time == 0) { 76283c7b61cSXiangliang Yu mw32(MVS_INT_COAL, 0); 76383c7b61cSXiangliang Yu mw32(MVS_INT_COAL_TMOUT, 0x10000); 76483c7b61cSXiangliang Yu } else { 76583c7b61cSXiangliang Yu if (MVS_CHIP_SLOT_SZ > 0x1ff) 76683c7b61cSXiangliang Yu mw32(MVS_INT_COAL, 0x1ff|COAL_EN); 76783c7b61cSXiangliang Yu else 76883c7b61cSXiangliang Yu mw32(MVS_INT_COAL, MVS_CHIP_SLOT_SZ|COAL_EN); 76983c7b61cSXiangliang Yu 77083c7b61cSXiangliang Yu tmp = 0x10000 | time; 77183c7b61cSXiangliang Yu mw32(MVS_INT_COAL_TMOUT, tmp); 77283c7b61cSXiangliang Yu } 77383c7b61cSXiangliang Yu } 77483c7b61cSXiangliang Yu 77520b09c29SAndy Yan const struct mvs_dispatch mvs_64xx_dispatch = { 77620b09c29SAndy Yan "mv64xx", 77720b09c29SAndy Yan mvs_64xx_init, 77820b09c29SAndy Yan NULL, 77920b09c29SAndy Yan mvs_64xx_ioremap, 78020b09c29SAndy Yan mvs_64xx_iounmap, 78120b09c29SAndy Yan mvs_64xx_isr, 78220b09c29SAndy Yan mvs_64xx_isr_status, 78320b09c29SAndy Yan mvs_64xx_interrupt_enable, 78420b09c29SAndy Yan mvs_64xx_interrupt_disable, 78520b09c29SAndy Yan mvs_read_phy_ctl, 78620b09c29SAndy Yan mvs_write_phy_ctl, 78720b09c29SAndy Yan mvs_read_port_cfg_data, 78820b09c29SAndy Yan mvs_write_port_cfg_data, 78920b09c29SAndy Yan mvs_write_port_cfg_addr, 79020b09c29SAndy Yan mvs_read_port_vsr_data, 79120b09c29SAndy Yan mvs_write_port_vsr_data, 79220b09c29SAndy Yan mvs_write_port_vsr_addr, 79320b09c29SAndy Yan mvs_read_port_irq_stat, 79420b09c29SAndy Yan mvs_write_port_irq_stat, 79520b09c29SAndy Yan mvs_read_port_irq_mask, 79620b09c29SAndy Yan mvs_write_port_irq_mask, 79720b09c29SAndy Yan mvs_64xx_command_active, 7989dc9fd94SSrinivas mvs_64xx_clear_srs_irq, 79920b09c29SAndy Yan mvs_64xx_issue_stop, 80020b09c29SAndy Yan mvs_start_delivery, 80120b09c29SAndy Yan mvs_rx_update, 80220b09c29SAndy Yan mvs_int_full, 80320b09c29SAndy Yan mvs_64xx_assign_reg_set, 80420b09c29SAndy Yan mvs_64xx_free_reg_set, 80520b09c29SAndy Yan mvs_get_prd_size, 80620b09c29SAndy Yan mvs_get_prd_count, 80720b09c29SAndy Yan mvs_64xx_make_prd, 80820b09c29SAndy Yan mvs_64xx_detect_porttype, 80920b09c29SAndy Yan mvs_64xx_oob_done, 81020b09c29SAndy Yan mvs_64xx_fix_phy_info, 81120b09c29SAndy Yan mvs_64xx_phy_work_around, 81220b09c29SAndy Yan mvs_64xx_phy_set_link_rate, 81320b09c29SAndy Yan mvs_hw_max_link_rate, 81420b09c29SAndy Yan mvs_64xx_phy_disable, 81520b09c29SAndy Yan mvs_64xx_phy_enable, 81620b09c29SAndy Yan mvs_64xx_phy_reset, 81720b09c29SAndy Yan mvs_64xx_stp_reset, 81820b09c29SAndy Yan mvs_64xx_clear_active_cmds, 81920b09c29SAndy Yan mvs_64xx_spi_read_data, 82020b09c29SAndy Yan mvs_64xx_spi_write_data, 82120b09c29SAndy Yan mvs_64xx_spi_buildcmd, 82220b09c29SAndy Yan mvs_64xx_spi_issuecmd, 82320b09c29SAndy Yan mvs_64xx_spi_waitdataready, 82420b09c29SAndy Yan mvs_64xx_fix_dma, 82583c7b61cSXiangliang Yu mvs_64xx_tune_interrupt, 826534ff101SXiangliang Yu NULL, 82720b09c29SAndy Yan }; 82820b09c29SAndy Yan 829