18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Broadcom specific AMBA 38c2ecf20Sopenharmony_ci * Bus scanning 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Licensed under the GNU/GPL. See COPYING for details. 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include "scan.h" 98c2ecf20Sopenharmony_ci#include "bcma_private.h" 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <linux/bcma/bcma.h> 128c2ecf20Sopenharmony_ci#include <linux/bcma/bcma_regs.h> 138c2ecf20Sopenharmony_ci#include <linux/pci.h> 148c2ecf20Sopenharmony_ci#include <linux/io.h> 158c2ecf20Sopenharmony_ci#include <linux/dma-mapping.h> 168c2ecf20Sopenharmony_ci#include <linux/slab.h> 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_cistruct bcma_device_id_name { 198c2ecf20Sopenharmony_ci u16 id; 208c2ecf20Sopenharmony_ci const char *name; 218c2ecf20Sopenharmony_ci}; 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_cistatic const struct bcma_device_id_name bcma_arm_device_names[] = { 248c2ecf20Sopenharmony_ci { BCMA_CORE_4706_MAC_GBIT_COMMON, "BCM4706 GBit MAC Common" }, 258c2ecf20Sopenharmony_ci { BCMA_CORE_ARM_1176, "ARM 1176" }, 268c2ecf20Sopenharmony_ci { BCMA_CORE_ARM_7TDMI, "ARM 7TDMI" }, 278c2ecf20Sopenharmony_ci { BCMA_CORE_ARM_CM3, "ARM CM3" }, 288c2ecf20Sopenharmony_ci}; 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_cistatic const struct bcma_device_id_name bcma_bcm_device_names[] = { 318c2ecf20Sopenharmony_ci { BCMA_CORE_OOB_ROUTER, "OOB Router" }, 328c2ecf20Sopenharmony_ci { BCMA_CORE_4706_CHIPCOMMON, "BCM4706 ChipCommon" }, 338c2ecf20Sopenharmony_ci { BCMA_CORE_4706_SOC_RAM, "BCM4706 SOC RAM" }, 348c2ecf20Sopenharmony_ci { BCMA_CORE_4706_MAC_GBIT, "BCM4706 GBit MAC" }, 358c2ecf20Sopenharmony_ci { BCMA_CORE_NS_PCIEG2, "PCIe Gen 2" }, 368c2ecf20Sopenharmony_ci { BCMA_CORE_NS_DMA, "DMA" }, 378c2ecf20Sopenharmony_ci { BCMA_CORE_NS_SDIO3, "SDIO3" }, 388c2ecf20Sopenharmony_ci { BCMA_CORE_NS_USB20, "USB 2.0" }, 398c2ecf20Sopenharmony_ci { BCMA_CORE_NS_USB30, "USB 3.0" }, 408c2ecf20Sopenharmony_ci { BCMA_CORE_NS_A9JTAG, "ARM Cortex A9 JTAG" }, 418c2ecf20Sopenharmony_ci { BCMA_CORE_NS_DDR23, "Denali DDR2/DDR3 memory controller" }, 428c2ecf20Sopenharmony_ci { BCMA_CORE_NS_ROM, "ROM" }, 438c2ecf20Sopenharmony_ci { BCMA_CORE_NS_NAND, "NAND flash controller" }, 448c2ecf20Sopenharmony_ci { BCMA_CORE_NS_QSPI, "SPI flash controller" }, 458c2ecf20Sopenharmony_ci { BCMA_CORE_NS_CHIPCOMMON_B, "Chipcommon B" }, 468c2ecf20Sopenharmony_ci { BCMA_CORE_ARMCA9, "ARM Cortex A9 core (ihost)" }, 478c2ecf20Sopenharmony_ci { BCMA_CORE_AMEMC, "AMEMC (DDR)" }, 488c2ecf20Sopenharmony_ci { BCMA_CORE_ALTA, "ALTA (I2S)" }, 498c2ecf20Sopenharmony_ci { BCMA_CORE_INVALID, "Invalid" }, 508c2ecf20Sopenharmony_ci { BCMA_CORE_CHIPCOMMON, "ChipCommon" }, 518c2ecf20Sopenharmony_ci { BCMA_CORE_ILINE20, "ILine 20" }, 528c2ecf20Sopenharmony_ci { BCMA_CORE_SRAM, "SRAM" }, 538c2ecf20Sopenharmony_ci { BCMA_CORE_SDRAM, "SDRAM" }, 548c2ecf20Sopenharmony_ci { BCMA_CORE_PCI, "PCI" }, 558c2ecf20Sopenharmony_ci { BCMA_CORE_ETHERNET, "Fast Ethernet" }, 568c2ecf20Sopenharmony_ci { BCMA_CORE_V90, "V90" }, 578c2ecf20Sopenharmony_ci { BCMA_CORE_USB11_HOSTDEV, "USB 1.1 Hostdev" }, 588c2ecf20Sopenharmony_ci { BCMA_CORE_ADSL, "ADSL" }, 598c2ecf20Sopenharmony_ci { BCMA_CORE_ILINE100, "ILine 100" }, 608c2ecf20Sopenharmony_ci { BCMA_CORE_IPSEC, "IPSEC" }, 618c2ecf20Sopenharmony_ci { BCMA_CORE_UTOPIA, "UTOPIA" }, 628c2ecf20Sopenharmony_ci { BCMA_CORE_PCMCIA, "PCMCIA" }, 638c2ecf20Sopenharmony_ci { BCMA_CORE_INTERNAL_MEM, "Internal Memory" }, 648c2ecf20Sopenharmony_ci { BCMA_CORE_MEMC_SDRAM, "MEMC SDRAM" }, 658c2ecf20Sopenharmony_ci { BCMA_CORE_OFDM, "OFDM" }, 668c2ecf20Sopenharmony_ci { BCMA_CORE_EXTIF, "EXTIF" }, 678c2ecf20Sopenharmony_ci { BCMA_CORE_80211, "IEEE 802.11" }, 688c2ecf20Sopenharmony_ci { BCMA_CORE_PHY_A, "PHY A" }, 698c2ecf20Sopenharmony_ci { BCMA_CORE_PHY_B, "PHY B" }, 708c2ecf20Sopenharmony_ci { BCMA_CORE_PHY_G, "PHY G" }, 718c2ecf20Sopenharmony_ci { BCMA_CORE_USB11_HOST, "USB 1.1 Host" }, 728c2ecf20Sopenharmony_ci { BCMA_CORE_USB11_DEV, "USB 1.1 Device" }, 738c2ecf20Sopenharmony_ci { BCMA_CORE_USB20_HOST, "USB 2.0 Host" }, 748c2ecf20Sopenharmony_ci { BCMA_CORE_USB20_DEV, "USB 2.0 Device" }, 758c2ecf20Sopenharmony_ci { BCMA_CORE_SDIO_HOST, "SDIO Host" }, 768c2ecf20Sopenharmony_ci { BCMA_CORE_ROBOSWITCH, "Roboswitch" }, 778c2ecf20Sopenharmony_ci { BCMA_CORE_PARA_ATA, "PATA" }, 788c2ecf20Sopenharmony_ci { BCMA_CORE_SATA_XORDMA, "SATA XOR-DMA" }, 798c2ecf20Sopenharmony_ci { BCMA_CORE_ETHERNET_GBIT, "GBit Ethernet" }, 808c2ecf20Sopenharmony_ci { BCMA_CORE_PCIE, "PCIe" }, 818c2ecf20Sopenharmony_ci { BCMA_CORE_PHY_N, "PHY N" }, 828c2ecf20Sopenharmony_ci { BCMA_CORE_SRAM_CTL, "SRAM Controller" }, 838c2ecf20Sopenharmony_ci { BCMA_CORE_MINI_MACPHY, "Mini MACPHY" }, 848c2ecf20Sopenharmony_ci { BCMA_CORE_PHY_LP, "PHY LP" }, 858c2ecf20Sopenharmony_ci { BCMA_CORE_PMU, "PMU" }, 868c2ecf20Sopenharmony_ci { BCMA_CORE_PHY_SSN, "PHY SSN" }, 878c2ecf20Sopenharmony_ci { BCMA_CORE_SDIO_DEV, "SDIO Device" }, 888c2ecf20Sopenharmony_ci { BCMA_CORE_PHY_HT, "PHY HT" }, 898c2ecf20Sopenharmony_ci { BCMA_CORE_MAC_GBIT, "GBit MAC" }, 908c2ecf20Sopenharmony_ci { BCMA_CORE_DDR12_MEM_CTL, "DDR1/DDR2 Memory Controller" }, 918c2ecf20Sopenharmony_ci { BCMA_CORE_PCIE_RC, "PCIe Root Complex" }, 928c2ecf20Sopenharmony_ci { BCMA_CORE_OCP_OCP_BRIDGE, "OCP to OCP Bridge" }, 938c2ecf20Sopenharmony_ci { BCMA_CORE_SHARED_COMMON, "Common Shared" }, 948c2ecf20Sopenharmony_ci { BCMA_CORE_OCP_AHB_BRIDGE, "OCP to AHB Bridge" }, 958c2ecf20Sopenharmony_ci { BCMA_CORE_SPI_HOST, "SPI Host" }, 968c2ecf20Sopenharmony_ci { BCMA_CORE_I2S, "I2S" }, 978c2ecf20Sopenharmony_ci { BCMA_CORE_SDR_DDR1_MEM_CTL, "SDR/DDR1 Memory Controller" }, 988c2ecf20Sopenharmony_ci { BCMA_CORE_SHIM, "SHIM" }, 998c2ecf20Sopenharmony_ci { BCMA_CORE_PCIE2, "PCIe Gen2" }, 1008c2ecf20Sopenharmony_ci { BCMA_CORE_ARM_CR4, "ARM CR4" }, 1018c2ecf20Sopenharmony_ci { BCMA_CORE_GCI, "GCI" }, 1028c2ecf20Sopenharmony_ci { BCMA_CORE_CMEM, "CNDS DDR2/3 memory controller" }, 1038c2ecf20Sopenharmony_ci { BCMA_CORE_ARM_CA7, "ARM CA7" }, 1048c2ecf20Sopenharmony_ci { BCMA_CORE_DEFAULT, "Default" }, 1058c2ecf20Sopenharmony_ci}; 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_cistatic const struct bcma_device_id_name bcma_mips_device_names[] = { 1088c2ecf20Sopenharmony_ci { BCMA_CORE_MIPS, "MIPS" }, 1098c2ecf20Sopenharmony_ci { BCMA_CORE_MIPS_3302, "MIPS 3302" }, 1108c2ecf20Sopenharmony_ci { BCMA_CORE_MIPS_74K, "MIPS 74K" }, 1118c2ecf20Sopenharmony_ci}; 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_cistatic const char *bcma_device_name(const struct bcma_device_id *id) 1148c2ecf20Sopenharmony_ci{ 1158c2ecf20Sopenharmony_ci const struct bcma_device_id_name *names; 1168c2ecf20Sopenharmony_ci int size, i; 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci /* search manufacturer specific names */ 1198c2ecf20Sopenharmony_ci switch (id->manuf) { 1208c2ecf20Sopenharmony_ci case BCMA_MANUF_ARM: 1218c2ecf20Sopenharmony_ci names = bcma_arm_device_names; 1228c2ecf20Sopenharmony_ci size = ARRAY_SIZE(bcma_arm_device_names); 1238c2ecf20Sopenharmony_ci break; 1248c2ecf20Sopenharmony_ci case BCMA_MANUF_BCM: 1258c2ecf20Sopenharmony_ci names = bcma_bcm_device_names; 1268c2ecf20Sopenharmony_ci size = ARRAY_SIZE(bcma_bcm_device_names); 1278c2ecf20Sopenharmony_ci break; 1288c2ecf20Sopenharmony_ci case BCMA_MANUF_MIPS: 1298c2ecf20Sopenharmony_ci names = bcma_mips_device_names; 1308c2ecf20Sopenharmony_ci size = ARRAY_SIZE(bcma_mips_device_names); 1318c2ecf20Sopenharmony_ci break; 1328c2ecf20Sopenharmony_ci default: 1338c2ecf20Sopenharmony_ci return "UNKNOWN"; 1348c2ecf20Sopenharmony_ci } 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci for (i = 0; i < size; i++) { 1378c2ecf20Sopenharmony_ci if (names[i].id == id->id) 1388c2ecf20Sopenharmony_ci return names[i].name; 1398c2ecf20Sopenharmony_ci } 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci return "UNKNOWN"; 1428c2ecf20Sopenharmony_ci} 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_cistatic u32 bcma_scan_read32(struct bcma_bus *bus, u8 current_coreidx, 1458c2ecf20Sopenharmony_ci u16 offset) 1468c2ecf20Sopenharmony_ci{ 1478c2ecf20Sopenharmony_ci return readl(bus->mmio + offset); 1488c2ecf20Sopenharmony_ci} 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_cistatic void bcma_scan_switch_core(struct bcma_bus *bus, u32 addr) 1518c2ecf20Sopenharmony_ci{ 1528c2ecf20Sopenharmony_ci if (bus->hosttype == BCMA_HOSTTYPE_PCI) 1538c2ecf20Sopenharmony_ci pci_write_config_dword(bus->host_pci, BCMA_PCI_BAR0_WIN, 1548c2ecf20Sopenharmony_ci addr); 1558c2ecf20Sopenharmony_ci} 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_cistatic u32 bcma_erom_get_ent(struct bcma_bus *bus, u32 __iomem **eromptr) 1588c2ecf20Sopenharmony_ci{ 1598c2ecf20Sopenharmony_ci u32 ent = readl(*eromptr); 1608c2ecf20Sopenharmony_ci (*eromptr)++; 1618c2ecf20Sopenharmony_ci return ent; 1628c2ecf20Sopenharmony_ci} 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_cistatic void bcma_erom_push_ent(u32 __iomem **eromptr) 1658c2ecf20Sopenharmony_ci{ 1668c2ecf20Sopenharmony_ci (*eromptr)--; 1678c2ecf20Sopenharmony_ci} 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_cistatic s32 bcma_erom_get_ci(struct bcma_bus *bus, u32 __iomem **eromptr) 1708c2ecf20Sopenharmony_ci{ 1718c2ecf20Sopenharmony_ci u32 ent = bcma_erom_get_ent(bus, eromptr); 1728c2ecf20Sopenharmony_ci if (!(ent & SCAN_ER_VALID)) 1738c2ecf20Sopenharmony_ci return -ENOENT; 1748c2ecf20Sopenharmony_ci if ((ent & SCAN_ER_TAG) != SCAN_ER_TAG_CI) 1758c2ecf20Sopenharmony_ci return -ENOENT; 1768c2ecf20Sopenharmony_ci return ent; 1778c2ecf20Sopenharmony_ci} 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_cistatic bool bcma_erom_is_end(struct bcma_bus *bus, u32 __iomem **eromptr) 1808c2ecf20Sopenharmony_ci{ 1818c2ecf20Sopenharmony_ci u32 ent = bcma_erom_get_ent(bus, eromptr); 1828c2ecf20Sopenharmony_ci bcma_erom_push_ent(eromptr); 1838c2ecf20Sopenharmony_ci return (ent == (SCAN_ER_TAG_END | SCAN_ER_VALID)); 1848c2ecf20Sopenharmony_ci} 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_cistatic bool bcma_erom_is_bridge(struct bcma_bus *bus, u32 __iomem **eromptr) 1878c2ecf20Sopenharmony_ci{ 1888c2ecf20Sopenharmony_ci u32 ent = bcma_erom_get_ent(bus, eromptr); 1898c2ecf20Sopenharmony_ci bcma_erom_push_ent(eromptr); 1908c2ecf20Sopenharmony_ci return (((ent & SCAN_ER_VALID)) && 1918c2ecf20Sopenharmony_ci ((ent & SCAN_ER_TAGX) == SCAN_ER_TAG_ADDR) && 1928c2ecf20Sopenharmony_ci ((ent & SCAN_ADDR_TYPE) == SCAN_ADDR_TYPE_BRIDGE)); 1938c2ecf20Sopenharmony_ci} 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_cistatic void bcma_erom_skip_component(struct bcma_bus *bus, u32 __iomem **eromptr) 1968c2ecf20Sopenharmony_ci{ 1978c2ecf20Sopenharmony_ci u32 ent; 1988c2ecf20Sopenharmony_ci while (1) { 1998c2ecf20Sopenharmony_ci ent = bcma_erom_get_ent(bus, eromptr); 2008c2ecf20Sopenharmony_ci if ((ent & SCAN_ER_VALID) && 2018c2ecf20Sopenharmony_ci ((ent & SCAN_ER_TAG) == SCAN_ER_TAG_CI)) 2028c2ecf20Sopenharmony_ci break; 2038c2ecf20Sopenharmony_ci if (ent == (SCAN_ER_TAG_END | SCAN_ER_VALID)) 2048c2ecf20Sopenharmony_ci break; 2058c2ecf20Sopenharmony_ci } 2068c2ecf20Sopenharmony_ci bcma_erom_push_ent(eromptr); 2078c2ecf20Sopenharmony_ci} 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_cistatic s32 bcma_erom_get_mst_port(struct bcma_bus *bus, u32 __iomem **eromptr) 2108c2ecf20Sopenharmony_ci{ 2118c2ecf20Sopenharmony_ci u32 ent = bcma_erom_get_ent(bus, eromptr); 2128c2ecf20Sopenharmony_ci if (!(ent & SCAN_ER_VALID)) 2138c2ecf20Sopenharmony_ci return -ENOENT; 2148c2ecf20Sopenharmony_ci if ((ent & SCAN_ER_TAG) != SCAN_ER_TAG_MP) 2158c2ecf20Sopenharmony_ci return -ENOENT; 2168c2ecf20Sopenharmony_ci return ent; 2178c2ecf20Sopenharmony_ci} 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_cistatic u32 bcma_erom_get_addr_desc(struct bcma_bus *bus, u32 __iomem **eromptr, 2208c2ecf20Sopenharmony_ci u32 type, u8 port) 2218c2ecf20Sopenharmony_ci{ 2228c2ecf20Sopenharmony_ci u32 addrl; 2238c2ecf20Sopenharmony_ci u32 size; 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci u32 ent = bcma_erom_get_ent(bus, eromptr); 2268c2ecf20Sopenharmony_ci if ((!(ent & SCAN_ER_VALID)) || 2278c2ecf20Sopenharmony_ci ((ent & SCAN_ER_TAGX) != SCAN_ER_TAG_ADDR) || 2288c2ecf20Sopenharmony_ci ((ent & SCAN_ADDR_TYPE) != type) || 2298c2ecf20Sopenharmony_ci (((ent & SCAN_ADDR_PORT) >> SCAN_ADDR_PORT_SHIFT) != port)) { 2308c2ecf20Sopenharmony_ci bcma_erom_push_ent(eromptr); 2318c2ecf20Sopenharmony_ci return (u32)-EINVAL; 2328c2ecf20Sopenharmony_ci } 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci addrl = ent & SCAN_ADDR_ADDR; 2358c2ecf20Sopenharmony_ci if (ent & SCAN_ADDR_AG32) 2368c2ecf20Sopenharmony_ci bcma_erom_get_ent(bus, eromptr); 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci if ((ent & SCAN_ADDR_SZ) == SCAN_ADDR_SZ_SZD) { 2398c2ecf20Sopenharmony_ci size = bcma_erom_get_ent(bus, eromptr); 2408c2ecf20Sopenharmony_ci if (size & SCAN_SIZE_SG32) 2418c2ecf20Sopenharmony_ci bcma_erom_get_ent(bus, eromptr); 2428c2ecf20Sopenharmony_ci } 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ci return addrl; 2458c2ecf20Sopenharmony_ci} 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_cistatic struct bcma_device *bcma_find_core_by_index(struct bcma_bus *bus, 2488c2ecf20Sopenharmony_ci u16 index) 2498c2ecf20Sopenharmony_ci{ 2508c2ecf20Sopenharmony_ci struct bcma_device *core; 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ci list_for_each_entry(core, &bus->cores, list) { 2538c2ecf20Sopenharmony_ci if (core->core_index == index) 2548c2ecf20Sopenharmony_ci return core; 2558c2ecf20Sopenharmony_ci } 2568c2ecf20Sopenharmony_ci return NULL; 2578c2ecf20Sopenharmony_ci} 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_cistatic struct bcma_device *bcma_find_core_reverse(struct bcma_bus *bus, u16 coreid) 2608c2ecf20Sopenharmony_ci{ 2618c2ecf20Sopenharmony_ci struct bcma_device *core; 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_ci list_for_each_entry_reverse(core, &bus->cores, list) { 2648c2ecf20Sopenharmony_ci if (core->id.id == coreid) 2658c2ecf20Sopenharmony_ci return core; 2668c2ecf20Sopenharmony_ci } 2678c2ecf20Sopenharmony_ci return NULL; 2688c2ecf20Sopenharmony_ci} 2698c2ecf20Sopenharmony_ci 2708c2ecf20Sopenharmony_ci#define IS_ERR_VALUE_U32(x) ((x) >= (u32)-MAX_ERRNO) 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_cistatic int bcma_get_next_core(struct bcma_bus *bus, u32 __iomem **eromptr, 2738c2ecf20Sopenharmony_ci struct bcma_device_id *match, int core_num, 2748c2ecf20Sopenharmony_ci struct bcma_device *core) 2758c2ecf20Sopenharmony_ci{ 2768c2ecf20Sopenharmony_ci u32 tmp; 2778c2ecf20Sopenharmony_ci u8 i, j, k; 2788c2ecf20Sopenharmony_ci s32 cia, cib; 2798c2ecf20Sopenharmony_ci u8 ports[2], wrappers[2]; 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci /* get CIs */ 2828c2ecf20Sopenharmony_ci cia = bcma_erom_get_ci(bus, eromptr); 2838c2ecf20Sopenharmony_ci if (cia < 0) { 2848c2ecf20Sopenharmony_ci bcma_erom_push_ent(eromptr); 2858c2ecf20Sopenharmony_ci if (bcma_erom_is_end(bus, eromptr)) 2868c2ecf20Sopenharmony_ci return -ESPIPE; 2878c2ecf20Sopenharmony_ci return -EILSEQ; 2888c2ecf20Sopenharmony_ci } 2898c2ecf20Sopenharmony_ci cib = bcma_erom_get_ci(bus, eromptr); 2908c2ecf20Sopenharmony_ci if (cib < 0) 2918c2ecf20Sopenharmony_ci return -EILSEQ; 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_ci /* parse CIs */ 2948c2ecf20Sopenharmony_ci core->id.class = (cia & SCAN_CIA_CLASS) >> SCAN_CIA_CLASS_SHIFT; 2958c2ecf20Sopenharmony_ci core->id.id = (cia & SCAN_CIA_ID) >> SCAN_CIA_ID_SHIFT; 2968c2ecf20Sopenharmony_ci core->id.manuf = (cia & SCAN_CIA_MANUF) >> SCAN_CIA_MANUF_SHIFT; 2978c2ecf20Sopenharmony_ci ports[0] = (cib & SCAN_CIB_NMP) >> SCAN_CIB_NMP_SHIFT; 2988c2ecf20Sopenharmony_ci ports[1] = (cib & SCAN_CIB_NSP) >> SCAN_CIB_NSP_SHIFT; 2998c2ecf20Sopenharmony_ci wrappers[0] = (cib & SCAN_CIB_NMW) >> SCAN_CIB_NMW_SHIFT; 3008c2ecf20Sopenharmony_ci wrappers[1] = (cib & SCAN_CIB_NSW) >> SCAN_CIB_NSW_SHIFT; 3018c2ecf20Sopenharmony_ci core->id.rev = (cib & SCAN_CIB_REV) >> SCAN_CIB_REV_SHIFT; 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ci if (((core->id.manuf == BCMA_MANUF_ARM) && 3048c2ecf20Sopenharmony_ci (core->id.id == 0xFFF)) || 3058c2ecf20Sopenharmony_ci (ports[1] == 0)) { 3068c2ecf20Sopenharmony_ci bcma_erom_skip_component(bus, eromptr); 3078c2ecf20Sopenharmony_ci return -ENXIO; 3088c2ecf20Sopenharmony_ci } 3098c2ecf20Sopenharmony_ci 3108c2ecf20Sopenharmony_ci /* check if component is a core at all */ 3118c2ecf20Sopenharmony_ci if (wrappers[0] + wrappers[1] == 0) { 3128c2ecf20Sopenharmony_ci /* Some specific cores don't need wrappers */ 3138c2ecf20Sopenharmony_ci switch (core->id.id) { 3148c2ecf20Sopenharmony_ci case BCMA_CORE_4706_MAC_GBIT_COMMON: 3158c2ecf20Sopenharmony_ci case BCMA_CORE_NS_CHIPCOMMON_B: 3168c2ecf20Sopenharmony_ci case BCMA_CORE_PMU: 3178c2ecf20Sopenharmony_ci case BCMA_CORE_GCI: 3188c2ecf20Sopenharmony_ci /* Not used yet: case BCMA_CORE_OOB_ROUTER: */ 3198c2ecf20Sopenharmony_ci break; 3208c2ecf20Sopenharmony_ci default: 3218c2ecf20Sopenharmony_ci bcma_erom_skip_component(bus, eromptr); 3228c2ecf20Sopenharmony_ci return -ENXIO; 3238c2ecf20Sopenharmony_ci } 3248c2ecf20Sopenharmony_ci } 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_ci if (bcma_erom_is_bridge(bus, eromptr)) { 3278c2ecf20Sopenharmony_ci bcma_erom_skip_component(bus, eromptr); 3288c2ecf20Sopenharmony_ci return -ENXIO; 3298c2ecf20Sopenharmony_ci } 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_ci if (bcma_find_core_by_index(bus, core_num)) { 3328c2ecf20Sopenharmony_ci bcma_erom_skip_component(bus, eromptr); 3338c2ecf20Sopenharmony_ci return -ENODEV; 3348c2ecf20Sopenharmony_ci } 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_ci if (match && ((match->manuf != BCMA_ANY_MANUF && 3378c2ecf20Sopenharmony_ci match->manuf != core->id.manuf) || 3388c2ecf20Sopenharmony_ci (match->id != BCMA_ANY_ID && match->id != core->id.id) || 3398c2ecf20Sopenharmony_ci (match->rev != BCMA_ANY_REV && match->rev != core->id.rev) || 3408c2ecf20Sopenharmony_ci (match->class != BCMA_ANY_CLASS && match->class != core->id.class) 3418c2ecf20Sopenharmony_ci )) { 3428c2ecf20Sopenharmony_ci bcma_erom_skip_component(bus, eromptr); 3438c2ecf20Sopenharmony_ci return -ENODEV; 3448c2ecf20Sopenharmony_ci } 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_ci /* get & parse master ports */ 3478c2ecf20Sopenharmony_ci for (i = 0; i < ports[0]; i++) { 3488c2ecf20Sopenharmony_ci s32 mst_port_d = bcma_erom_get_mst_port(bus, eromptr); 3498c2ecf20Sopenharmony_ci if (mst_port_d < 0) 3508c2ecf20Sopenharmony_ci return -EILSEQ; 3518c2ecf20Sopenharmony_ci } 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci /* First Slave Address Descriptor should be port 0: 3548c2ecf20Sopenharmony_ci * the main register space for the core 3558c2ecf20Sopenharmony_ci */ 3568c2ecf20Sopenharmony_ci tmp = bcma_erom_get_addr_desc(bus, eromptr, SCAN_ADDR_TYPE_SLAVE, 0); 3578c2ecf20Sopenharmony_ci if (tmp == 0 || IS_ERR_VALUE_U32(tmp)) { 3588c2ecf20Sopenharmony_ci /* Try again to see if it is a bridge */ 3598c2ecf20Sopenharmony_ci tmp = bcma_erom_get_addr_desc(bus, eromptr, 3608c2ecf20Sopenharmony_ci SCAN_ADDR_TYPE_BRIDGE, 0); 3618c2ecf20Sopenharmony_ci if (tmp == 0 || IS_ERR_VALUE_U32(tmp)) { 3628c2ecf20Sopenharmony_ci return -EILSEQ; 3638c2ecf20Sopenharmony_ci } else { 3648c2ecf20Sopenharmony_ci bcma_info(bus, "Bridge found\n"); 3658c2ecf20Sopenharmony_ci return -ENXIO; 3668c2ecf20Sopenharmony_ci } 3678c2ecf20Sopenharmony_ci } 3688c2ecf20Sopenharmony_ci core->addr = tmp; 3698c2ecf20Sopenharmony_ci 3708c2ecf20Sopenharmony_ci /* get & parse slave ports */ 3718c2ecf20Sopenharmony_ci k = 0; 3728c2ecf20Sopenharmony_ci for (i = 0; i < ports[1]; i++) { 3738c2ecf20Sopenharmony_ci for (j = 0; ; j++) { 3748c2ecf20Sopenharmony_ci tmp = bcma_erom_get_addr_desc(bus, eromptr, 3758c2ecf20Sopenharmony_ci SCAN_ADDR_TYPE_SLAVE, i); 3768c2ecf20Sopenharmony_ci if (IS_ERR_VALUE_U32(tmp)) { 3778c2ecf20Sopenharmony_ci /* no more entries for port _i_ */ 3788c2ecf20Sopenharmony_ci /* pr_debug("erom: slave port %d " 3798c2ecf20Sopenharmony_ci * "has %d descriptors\n", i, j); */ 3808c2ecf20Sopenharmony_ci break; 3818c2ecf20Sopenharmony_ci } else if (k < ARRAY_SIZE(core->addr_s)) { 3828c2ecf20Sopenharmony_ci core->addr_s[k] = tmp; 3838c2ecf20Sopenharmony_ci k++; 3848c2ecf20Sopenharmony_ci } 3858c2ecf20Sopenharmony_ci } 3868c2ecf20Sopenharmony_ci } 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_ci /* get & parse master wrappers */ 3898c2ecf20Sopenharmony_ci for (i = 0; i < wrappers[0]; i++) { 3908c2ecf20Sopenharmony_ci for (j = 0; ; j++) { 3918c2ecf20Sopenharmony_ci tmp = bcma_erom_get_addr_desc(bus, eromptr, 3928c2ecf20Sopenharmony_ci SCAN_ADDR_TYPE_MWRAP, i); 3938c2ecf20Sopenharmony_ci if (IS_ERR_VALUE_U32(tmp)) { 3948c2ecf20Sopenharmony_ci /* no more entries for port _i_ */ 3958c2ecf20Sopenharmony_ci /* pr_debug("erom: master wrapper %d " 3968c2ecf20Sopenharmony_ci * "has %d descriptors\n", i, j); */ 3978c2ecf20Sopenharmony_ci break; 3988c2ecf20Sopenharmony_ci } else { 3998c2ecf20Sopenharmony_ci if (i == 0 && j == 0) 4008c2ecf20Sopenharmony_ci core->wrap = tmp; 4018c2ecf20Sopenharmony_ci } 4028c2ecf20Sopenharmony_ci } 4038c2ecf20Sopenharmony_ci } 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_ci /* get & parse slave wrappers */ 4068c2ecf20Sopenharmony_ci for (i = 0; i < wrappers[1]; i++) { 4078c2ecf20Sopenharmony_ci u8 hack = (ports[1] == 1) ? 0 : 1; 4088c2ecf20Sopenharmony_ci for (j = 0; ; j++) { 4098c2ecf20Sopenharmony_ci tmp = bcma_erom_get_addr_desc(bus, eromptr, 4108c2ecf20Sopenharmony_ci SCAN_ADDR_TYPE_SWRAP, i + hack); 4118c2ecf20Sopenharmony_ci if (IS_ERR_VALUE_U32(tmp)) { 4128c2ecf20Sopenharmony_ci /* no more entries for port _i_ */ 4138c2ecf20Sopenharmony_ci /* pr_debug("erom: master wrapper %d " 4148c2ecf20Sopenharmony_ci * has %d descriptors\n", i, j); */ 4158c2ecf20Sopenharmony_ci break; 4168c2ecf20Sopenharmony_ci } else { 4178c2ecf20Sopenharmony_ci if (wrappers[0] == 0 && !i && !j) 4188c2ecf20Sopenharmony_ci core->wrap = tmp; 4198c2ecf20Sopenharmony_ci } 4208c2ecf20Sopenharmony_ci } 4218c2ecf20Sopenharmony_ci } 4228c2ecf20Sopenharmony_ci if (bus->hosttype == BCMA_HOSTTYPE_SOC) { 4238c2ecf20Sopenharmony_ci core->io_addr = ioremap(core->addr, BCMA_CORE_SIZE); 4248c2ecf20Sopenharmony_ci if (!core->io_addr) 4258c2ecf20Sopenharmony_ci return -ENOMEM; 4268c2ecf20Sopenharmony_ci if (core->wrap) { 4278c2ecf20Sopenharmony_ci core->io_wrap = ioremap(core->wrap, 4288c2ecf20Sopenharmony_ci BCMA_CORE_SIZE); 4298c2ecf20Sopenharmony_ci if (!core->io_wrap) { 4308c2ecf20Sopenharmony_ci iounmap(core->io_addr); 4318c2ecf20Sopenharmony_ci return -ENOMEM; 4328c2ecf20Sopenharmony_ci } 4338c2ecf20Sopenharmony_ci } 4348c2ecf20Sopenharmony_ci } 4358c2ecf20Sopenharmony_ci return 0; 4368c2ecf20Sopenharmony_ci} 4378c2ecf20Sopenharmony_ci 4388c2ecf20Sopenharmony_civoid bcma_detect_chip(struct bcma_bus *bus) 4398c2ecf20Sopenharmony_ci{ 4408c2ecf20Sopenharmony_ci s32 tmp; 4418c2ecf20Sopenharmony_ci struct bcma_chipinfo *chipinfo = &(bus->chipinfo); 4428c2ecf20Sopenharmony_ci char chip_id[8]; 4438c2ecf20Sopenharmony_ci 4448c2ecf20Sopenharmony_ci bcma_scan_switch_core(bus, BCMA_ADDR_BASE); 4458c2ecf20Sopenharmony_ci 4468c2ecf20Sopenharmony_ci tmp = bcma_scan_read32(bus, 0, BCMA_CC_ID); 4478c2ecf20Sopenharmony_ci chipinfo->id = (tmp & BCMA_CC_ID_ID) >> BCMA_CC_ID_ID_SHIFT; 4488c2ecf20Sopenharmony_ci chipinfo->rev = (tmp & BCMA_CC_ID_REV) >> BCMA_CC_ID_REV_SHIFT; 4498c2ecf20Sopenharmony_ci chipinfo->pkg = (tmp & BCMA_CC_ID_PKG) >> BCMA_CC_ID_PKG_SHIFT; 4508c2ecf20Sopenharmony_ci 4518c2ecf20Sopenharmony_ci snprintf(chip_id, ARRAY_SIZE(chip_id), 4528c2ecf20Sopenharmony_ci (chipinfo->id > 0x9999) ? "%d" : "0x%04X", chipinfo->id); 4538c2ecf20Sopenharmony_ci bcma_info(bus, "Found chip with id %s, rev 0x%02X and package 0x%02X\n", 4548c2ecf20Sopenharmony_ci chip_id, chipinfo->rev, chipinfo->pkg); 4558c2ecf20Sopenharmony_ci} 4568c2ecf20Sopenharmony_ci 4578c2ecf20Sopenharmony_ciint bcma_bus_scan(struct bcma_bus *bus) 4588c2ecf20Sopenharmony_ci{ 4598c2ecf20Sopenharmony_ci u32 erombase; 4608c2ecf20Sopenharmony_ci u32 __iomem *eromptr, *eromend; 4618c2ecf20Sopenharmony_ci 4628c2ecf20Sopenharmony_ci int err, core_num = 0; 4638c2ecf20Sopenharmony_ci 4648c2ecf20Sopenharmony_ci /* Skip if bus was already scanned (e.g. during early register) */ 4658c2ecf20Sopenharmony_ci if (bus->nr_cores) 4668c2ecf20Sopenharmony_ci return 0; 4678c2ecf20Sopenharmony_ci 4688c2ecf20Sopenharmony_ci erombase = bcma_scan_read32(bus, 0, BCMA_CC_EROM); 4698c2ecf20Sopenharmony_ci if (bus->hosttype == BCMA_HOSTTYPE_SOC) { 4708c2ecf20Sopenharmony_ci eromptr = ioremap(erombase, BCMA_CORE_SIZE); 4718c2ecf20Sopenharmony_ci if (!eromptr) 4728c2ecf20Sopenharmony_ci return -ENOMEM; 4738c2ecf20Sopenharmony_ci } else { 4748c2ecf20Sopenharmony_ci eromptr = bus->mmio; 4758c2ecf20Sopenharmony_ci } 4768c2ecf20Sopenharmony_ci 4778c2ecf20Sopenharmony_ci eromend = eromptr + BCMA_CORE_SIZE / sizeof(u32); 4788c2ecf20Sopenharmony_ci 4798c2ecf20Sopenharmony_ci bcma_scan_switch_core(bus, erombase); 4808c2ecf20Sopenharmony_ci 4818c2ecf20Sopenharmony_ci while (eromptr < eromend) { 4828c2ecf20Sopenharmony_ci struct bcma_device *other_core; 4838c2ecf20Sopenharmony_ci struct bcma_device *core = kzalloc(sizeof(*core), GFP_KERNEL); 4848c2ecf20Sopenharmony_ci if (!core) { 4858c2ecf20Sopenharmony_ci err = -ENOMEM; 4868c2ecf20Sopenharmony_ci goto out; 4878c2ecf20Sopenharmony_ci } 4888c2ecf20Sopenharmony_ci INIT_LIST_HEAD(&core->list); 4898c2ecf20Sopenharmony_ci core->bus = bus; 4908c2ecf20Sopenharmony_ci 4918c2ecf20Sopenharmony_ci err = bcma_get_next_core(bus, &eromptr, NULL, core_num, core); 4928c2ecf20Sopenharmony_ci if (err < 0) { 4938c2ecf20Sopenharmony_ci kfree(core); 4948c2ecf20Sopenharmony_ci if (err == -ENODEV) { 4958c2ecf20Sopenharmony_ci core_num++; 4968c2ecf20Sopenharmony_ci continue; 4978c2ecf20Sopenharmony_ci } else if (err == -ENXIO) { 4988c2ecf20Sopenharmony_ci continue; 4998c2ecf20Sopenharmony_ci } else if (err == -ESPIPE) { 5008c2ecf20Sopenharmony_ci break; 5018c2ecf20Sopenharmony_ci } 5028c2ecf20Sopenharmony_ci goto out; 5038c2ecf20Sopenharmony_ci } 5048c2ecf20Sopenharmony_ci 5058c2ecf20Sopenharmony_ci core->core_index = core_num++; 5068c2ecf20Sopenharmony_ci bus->nr_cores++; 5078c2ecf20Sopenharmony_ci other_core = bcma_find_core_reverse(bus, core->id.id); 5088c2ecf20Sopenharmony_ci core->core_unit = (other_core == NULL) ? 0 : other_core->core_unit + 1; 5098c2ecf20Sopenharmony_ci bcma_prepare_core(bus, core); 5108c2ecf20Sopenharmony_ci 5118c2ecf20Sopenharmony_ci bcma_info(bus, "Core %d found: %s (manuf 0x%03X, id 0x%03X, rev 0x%02X, class 0x%X)\n", 5128c2ecf20Sopenharmony_ci core->core_index, bcma_device_name(&core->id), 5138c2ecf20Sopenharmony_ci core->id.manuf, core->id.id, core->id.rev, 5148c2ecf20Sopenharmony_ci core->id.class); 5158c2ecf20Sopenharmony_ci 5168c2ecf20Sopenharmony_ci list_add_tail(&core->list, &bus->cores); 5178c2ecf20Sopenharmony_ci } 5188c2ecf20Sopenharmony_ci 5198c2ecf20Sopenharmony_ci err = 0; 5208c2ecf20Sopenharmony_ciout: 5218c2ecf20Sopenharmony_ci if (bus->hosttype == BCMA_HOSTTYPE_SOC) 5228c2ecf20Sopenharmony_ci iounmap(eromptr); 5238c2ecf20Sopenharmony_ci 5248c2ecf20Sopenharmony_ci return err; 5258c2ecf20Sopenharmony_ci} 526