2018-01-26 21:50:27 +03:00
// SPDX-License-Identifier: GPL-2.0
2015-05-13 00:23:01 +03:00
/*
* Copyright ( C ) 2015 Broadcom Corporation
* Copyright ( C ) 2015 Hauke Mehrtens < hauke @ hauke - m . de >
*/
# include <linux/kernel.h>
# include <linux/pci.h>
# include <linux/module.h>
# include <linux/slab.h>
# include <linux/phy/phy.h>
# include <linux/bcma/bcma.h>
# include <linux/ioport.h>
# include "pcie-iproc.h"
/* NS: CLASS field is R/O, and set to wrong 0x200 value */
static void bcma_pcie2_fixup_class ( struct pci_dev * dev )
{
2022-02-14 14:41:08 +03:00
dev - > class = PCI_CLASS_BRIDGE_PCI_NORMAL ;
2015-05-13 00:23:01 +03:00
}
DECLARE_PCI_FIXUP_EARLY ( PCI_VENDOR_ID_BROADCOM , 0x8011 , bcma_pcie2_fixup_class ) ;
DECLARE_PCI_FIXUP_EARLY ( PCI_VENDOR_ID_BROADCOM , 0x8012 , bcma_pcie2_fixup_class ) ;
2021-12-23 04:10:42 +03:00
static int iproc_bcma_pcie_map_irq ( const struct pci_dev * dev , u8 slot , u8 pin )
2015-05-13 00:23:01 +03:00
{
2018-03-07 18:42:36 +03:00
struct iproc_pcie * pcie = dev - > sysdata ;
2015-05-13 00:23:01 +03:00
struct bcma_device * bdev = container_of ( pcie - > dev , struct bcma_device , dev ) ;
return bcma_core_irq ( bdev , 5 ) ;
}
2021-12-23 04:10:42 +03:00
static int iproc_bcma_pcie_probe ( struct bcma_device * bdev )
2015-05-13 00:23:01 +03:00
{
2016-10-06 21:36:08 +03:00
struct device * dev = & bdev - > dev ;
2015-05-13 00:23:01 +03:00
struct iproc_pcie * pcie ;
2017-06-28 23:13:57 +03:00
struct pci_host_bridge * bridge ;
2015-05-13 00:23:01 +03:00
int ret ;
2017-06-28 23:13:57 +03:00
bridge = devm_pci_alloc_host_bridge ( dev , sizeof ( * pcie ) ) ;
if ( ! bridge )
2015-05-13 00:23:01 +03:00
return - ENOMEM ;
2017-06-28 23:13:57 +03:00
pcie = pci_host_bridge_priv ( bridge ) ;
2016-10-06 21:36:08 +03:00
pcie - > dev = dev ;
2015-05-13 00:23:01 +03:00
2016-11-01 03:38:32 +03:00
pcie - > type = IPROC_PCIE_PAXB_BCMA ;
2015-05-13 00:23:01 +03:00
pcie - > base = bdev - > io_addr ;
2016-10-06 21:36:07 +03:00
if ( ! pcie - > base ) {
dev_err ( dev , " no controller registers \n " ) ;
return - ENOMEM ;
}
2016-01-07 03:04:35 +03:00
pcie - > base_addr = bdev - > addr ;
2015-05-13 00:23:01 +03:00
2017-03-09 20:27:07 +03:00
pcie - > mem . start = bdev - > addr_s [ 0 ] ;
pcie - > mem . end = bdev - > addr_s [ 0 ] + SZ_128M - 1 ;
pcie - > mem . name = " PCIe MEM space " ;
pcie - > mem . flags = IORESOURCE_MEM ;
2021-08-04 00:56:56 +03:00
pci_add_resource ( & bridge - > windows , & pcie - > mem ) ;
ret = devm_request_pci_bus_resources ( dev , & bridge - > windows ) ;
if ( ret )
return ret ;
2015-05-13 00:23:01 +03:00
2021-12-23 04:10:42 +03:00
pcie - > map_irq = iproc_bcma_pcie_map_irq ;
2015-05-13 00:23:01 +03:00
2016-10-06 21:36:08 +03:00
bcma_set_drvdata ( bdev , pcie ) ;
2021-08-04 00:56:56 +03:00
return iproc_pcie_setup ( pcie , & bridge - > windows ) ;
2015-05-13 00:23:01 +03:00
}
2021-12-23 04:10:42 +03:00
static void iproc_bcma_pcie_remove ( struct bcma_device * bdev )
2015-05-13 00:23:01 +03:00
{
struct iproc_pcie * pcie = bcma_get_drvdata ( bdev ) ;
iproc_pcie_remove ( pcie ) ;
}
2021-12-23 04:10:42 +03:00
static const struct bcma_device_id iproc_bcma_pcie_table [ ] = {
2015-05-13 00:23:01 +03:00
BCMA_CORE ( BCMA_MANUF_BCM , BCMA_CORE_NS_PCIEG2 , BCMA_ANY_REV , BCMA_ANY_CLASS ) ,
{ } ,
} ;
2021-12-23 04:10:42 +03:00
MODULE_DEVICE_TABLE ( bcma , iproc_bcma_pcie_table ) ;
2015-05-13 00:23:01 +03:00
2021-12-23 04:10:42 +03:00
static struct bcma_driver iproc_bcma_pcie_driver = {
2015-05-13 00:23:01 +03:00
. name = KBUILD_MODNAME ,
2021-12-23 04:10:42 +03:00
. id_table = iproc_bcma_pcie_table ,
. probe = iproc_bcma_pcie_probe ,
. remove = iproc_bcma_pcie_remove ,
2015-05-13 00:23:01 +03:00
} ;
2021-12-23 04:10:42 +03:00
module_bcma_driver ( iproc_bcma_pcie_driver ) ;
2015-05-13 00:23:01 +03:00
MODULE_AUTHOR ( " Hauke Mehrtens " ) ;
MODULE_DESCRIPTION ( " Broadcom iProc PCIe BCMA driver " ) ;
MODULE_LICENSE ( " GPL v2 " ) ;