2014-08-04 20:54:49 +00:00
|
|
|
--- a/arch/mips/ar231x/Makefile
|
|
|
|
+++ b/arch/mips/ar231x/Makefile
|
|
|
|
@@ -14,3 +14,4 @@ obj-$(CONFIG_EARLY_PRINTK) += early_prin
|
|
|
|
|
|
|
|
obj-$(CONFIG_ATHEROS_AR5312) += ar5312.o
|
|
|
|
obj-$(CONFIG_ATHEROS_AR2315) += ar2315.o
|
|
|
|
+obj-$(CONFIG_ATHEROS_AR2315_PCI) += pci.o
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/arch/mips/ar231x/pci.c
|
2014-09-12 06:52:55 +00:00
|
|
|
@@ -0,0 +1,280 @@
|
2014-08-04 20:54:49 +00:00
|
|
|
+/*
|
|
|
|
+ * This program is free software; you can redistribute it and/or
|
|
|
|
+ * modify it under the terms of the GNU General Public License
|
|
|
|
+ * as published by the Free Software Foundation; either version 2
|
|
|
|
+ * of the License, or (at your option) any later version.
|
|
|
|
+ *
|
|
|
|
+ * This program is distributed in the hope that it will be useful,
|
|
|
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
+ * GNU General Public License for more details.
|
|
|
|
+ *
|
|
|
|
+ * You should have received a copy of the GNU General Public License
|
2014-09-12 06:51:33 +00:00
|
|
|
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2014-08-04 20:54:49 +00:00
|
|
|
+ */
|
|
|
|
+
|
2014-09-12 06:52:51 +00:00
|
|
|
+/**
|
|
|
|
+ * Both AR2315 and AR2316 chips have PCI interface unit, which supports DMA
|
|
|
|
+ * and interrupt. PCI interface supports MMIO access method, but does not
|
|
|
|
+ * seem to support I/O ports.
|
|
|
|
+ *
|
|
|
|
+ * Read/write operation in the region 0x80000000-0xBFFFFFFF causes
|
|
|
|
+ * a memory read/write command on the PCI bus. 30 LSBs of address on
|
|
|
|
+ * the bus are taken from memory read/write request and 2 MSBs are
|
|
|
|
+ * determined by PCI unit configuration.
|
|
|
|
+ *
|
|
|
|
+ * To work with the configuration space instead of memory is necessary set
|
|
|
|
+ * the CFG_SEL bit in the PCI_MISC_CONFIG register.
|
|
|
|
+ *
|
|
|
|
+ * Devices on the bus can perform DMA requests via chip BAR1. PCI host
|
|
|
|
+ * controller BARs are programmend as if an external device is programmed.
|
|
|
|
+ * Which means that during configuration, IDSEL pin of the chip should be
|
|
|
|
+ * asserted.
|
|
|
|
+ *
|
|
|
|
+ * We know (and support) only one board that uses the PCI interface -
|
|
|
|
+ * Fonera 2.0g (FON2202). It has a USB EHCI controller connected to the
|
|
|
|
+ * AR2315 PCI bus. IDSEL pin of USB controller is connected to AD[13] line
|
|
|
|
+ * and IDSEL pin of AR125 is connected to AD[16] line.
|
|
|
|
+ */
|
|
|
|
+
|
2014-08-04 20:54:49 +00:00
|
|
|
+#include <linux/types.h>
|
|
|
|
+#include <linux/pci.h>
|
|
|
|
+#include <linux/kernel.h>
|
|
|
|
+#include <linux/init.h>
|
|
|
|
+#include <linux/mm.h>
|
|
|
|
+#include <linux/delay.h>
|
|
|
|
+#include <linux/irq.h>
|
|
|
|
+#include <linux/io.h>
|
|
|
|
+#include <asm/paccess.h>
|
|
|
|
+#include <ar231x_platform.h>
|
|
|
|
+#include <ar231x.h>
|
|
|
|
+#include <ar2315_regs.h>
|
|
|
|
+#include "devices.h"
|
|
|
|
+
|
|
|
|
+#define AR2315_MEM_BASE 0x80800000UL
|
|
|
|
+#define AR2315_MEM_SIZE 0x00ffffffUL
|
|
|
|
+#define AR2315_IO_SIZE 0x00007fffUL
|
|
|
|
+
|
2014-09-12 06:52:55 +00:00
|
|
|
+#define AR2315_PCI_HOST_SLOT 3
|
|
|
|
+#define AR2315_PCI_HOST_DEVID ((0xff18 << 16) | PCI_VENDOR_ID_ATHEROS)
|
|
|
|
+
|
2014-08-04 20:54:49 +00:00
|
|
|
+static unsigned long configspace;
|
|
|
|
+
|
2014-09-12 06:52:51 +00:00
|
|
|
+static int ar2315_pci_cfg_access(int devfn, int where, int size, u32 *ptr,
|
|
|
|
+ bool write)
|
2014-08-04 20:54:49 +00:00
|
|
|
+{
|
|
|
|
+ int func = PCI_FUNC(devfn);
|
|
|
|
+ int dev = PCI_SLOT(devfn);
|
|
|
|
+ u32 value = 0;
|
|
|
|
+ int err = 0;
|
|
|
|
+ u32 addr;
|
|
|
|
+
|
|
|
|
+ /* Select Configuration access */
|
|
|
|
+ ar231x_mask_reg(AR2315_PCI_MISC_CONFIG, 0, AR2315_PCIMISC_CFG_SEL);
|
|
|
|
+ mb();
|
|
|
|
+
|
2014-09-12 06:52:36 +00:00
|
|
|
+ addr = (u32)configspace + (1 << (13 + dev)) + (func << 8) + where;
|
2014-08-04 20:54:49 +00:00
|
|
|
+ if (size == 1)
|
|
|
|
+ addr ^= 0x3;
|
|
|
|
+ else if (size == 2)
|
|
|
|
+ addr ^= 0x2;
|
|
|
|
+
|
|
|
|
+ if (write) {
|
|
|
|
+ value = *ptr;
|
|
|
|
+ if (size == 1)
|
|
|
|
+ err = put_dbe(value, (u8 *)addr);
|
|
|
|
+ else if (size == 2)
|
|
|
|
+ err = put_dbe(value, (u16 *)addr);
|
|
|
|
+ else if (size == 4)
|
|
|
|
+ err = put_dbe(value, (u32 *)addr);
|
|
|
|
+ } else {
|
|
|
|
+ if (size == 1)
|
|
|
|
+ err = get_dbe(value, (u8 *)addr);
|
|
|
|
+ else if (size == 2)
|
|
|
|
+ err = get_dbe(value, (u16 *)addr);
|
|
|
|
+ else if (size == 4)
|
|
|
|
+ err = get_dbe(value, (u32 *)addr);
|
|
|
|
+ if (err)
|
|
|
|
+ *ptr = 0xffffffff;
|
|
|
|
+ else
|
|
|
|
+ *ptr = value;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /* Select Memory access */
|
|
|
|
+ ar231x_mask_reg(AR2315_PCI_MISC_CONFIG, AR2315_PCIMISC_CFG_SEL, 0);
|
|
|
|
+
|
|
|
|
+ return err ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
|
|
|
|
+}
|
|
|
|
+
|
2014-09-12 06:52:55 +00:00
|
|
|
+static inline int ar2315_pci_local_cfg_rd(unsigned devfn, int where, u32 *val)
|
|
|
|
+{
|
|
|
|
+ return ar2315_pci_cfg_access(devfn, where, sizeof(u32), val, false);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static inline int ar2315_pci_local_cfg_wr(unsigned devfn, int where, u32 val)
|
|
|
|
+{
|
|
|
|
+ return ar2315_pci_cfg_access(devfn, where, sizeof(u32), &val, true);
|
|
|
|
+}
|
|
|
|
+
|
2014-09-12 06:52:51 +00:00
|
|
|
+static int ar2315_pci_cfg_read(struct pci_bus *bus, unsigned int devfn,
|
|
|
|
+ int where, int size, u32 *value)
|
2014-08-04 20:54:49 +00:00
|
|
|
+{
|
2014-09-12 06:52:55 +00:00
|
|
|
+ if ((PCI_SLOT(devfn) != 0) || (PCI_FUNC(devfn) > 2))
|
|
|
|
+ return PCIBIOS_DEVICE_NOT_FOUND;
|
|
|
|
+
|
2014-09-12 06:52:51 +00:00
|
|
|
+ return ar2315_pci_cfg_access(devfn, where, size, value, 0);
|
2014-08-04 20:54:49 +00:00
|
|
|
+}
|
|
|
|
+
|
2014-09-12 06:52:51 +00:00
|
|
|
+static int ar2315_pci_cfg_write(struct pci_bus *bus, unsigned int devfn,
|
|
|
|
+ int where, int size, u32 value)
|
2014-08-04 20:54:49 +00:00
|
|
|
+{
|
2014-09-12 06:52:55 +00:00
|
|
|
+ if ((PCI_SLOT(devfn) != 0) || (PCI_FUNC(devfn) > 2))
|
|
|
|
+ return PCIBIOS_DEVICE_NOT_FOUND;
|
|
|
|
+
|
2014-09-12 06:52:51 +00:00
|
|
|
+ return ar2315_pci_cfg_access(devfn, where, size, &value, 1);
|
2014-08-04 20:54:49 +00:00
|
|
|
+}
|
|
|
|
+
|
2014-09-12 06:52:51 +00:00
|
|
|
+static struct pci_ops ar2315_pci_ops = {
|
|
|
|
+ .read = ar2315_pci_cfg_read,
|
|
|
|
+ .write = ar2315_pci_cfg_write,
|
2014-08-04 20:54:49 +00:00
|
|
|
+};
|
|
|
|
+
|
2014-09-12 06:52:51 +00:00
|
|
|
+static struct resource ar2315_mem_resource = {
|
|
|
|
+ .name = "ar2315-pci-mem",
|
2014-08-04 20:54:49 +00:00
|
|
|
+ .start = AR2315_MEM_BASE,
|
|
|
|
+ .end = AR2315_MEM_BASE + AR2315_MEM_SIZE - AR2315_IO_SIZE - 1 +
|
|
|
|
+ 0x4000000,
|
|
|
|
+ .flags = IORESOURCE_MEM,
|
|
|
|
+};
|
|
|
|
+
|
2014-09-12 06:52:51 +00:00
|
|
|
+static struct resource ar2315_io_resource = {
|
|
|
|
+ .name = "ar2315-pci-io",
|
2014-08-04 20:54:49 +00:00
|
|
|
+ .start = AR2315_MEM_BASE + AR2315_MEM_SIZE - AR2315_IO_SIZE,
|
|
|
|
+ .end = AR2315_MEM_BASE + AR2315_MEM_SIZE - 1,
|
|
|
|
+ .flags = IORESOURCE_IO,
|
|
|
|
+};
|
|
|
|
+
|
2014-09-12 06:52:51 +00:00
|
|
|
+static struct pci_controller ar2315_pci_controller = {
|
|
|
|
+ .pci_ops = &ar2315_pci_ops,
|
|
|
|
+ .mem_resource = &ar2315_mem_resource,
|
|
|
|
+ .io_resource = &ar2315_io_resource,
|
2014-08-04 20:54:49 +00:00
|
|
|
+ .mem_offset = 0x00000000UL,
|
|
|
|
+ .io_offset = 0x00000000UL,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+int pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
|
|
|
|
+{
|
|
|
|
+ return AR2315_IRQ_LCBUS_PCI;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int pcibios_plat_dev_init(struct pci_dev *dev)
|
|
|
|
+{
|
|
|
|
+ pci_write_config_byte(dev, PCI_INTERRUPT_LINE, 5);
|
|
|
|
+ pci_write_config_word(dev, 0x40, 0);
|
|
|
|
+
|
|
|
|
+ /* Clear any pending Abort or external Interrupts
|
|
|
|
+ * and enable interrupt processing */
|
|
|
|
+ ar231x_mask_reg(AR2315_PCI_INTEN_REG, AR2315_PCI_INT_ENABLE, 0);
|
|
|
|
+ ar231x_write_reg(AR2315_PCI_INT_STATUS, (AR2315_PCI_ABORT_INT |
|
|
|
|
+ AR2315_PCI_EXT_INT));
|
|
|
|
+ ar231x_write_reg(AR2315_PCI_INT_MASK, (AR2315_PCI_ABORT_INT |
|
|
|
|
+ AR2315_PCI_EXT_INT));
|
|
|
|
+ ar231x_mask_reg(AR2315_PCI_INTEN_REG, 0, AR2315_PCI_INT_ENABLE);
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
2014-09-12 06:52:55 +00:00
|
|
|
+static int ar2315_pci_host_setup(void)
|
2014-08-04 20:54:49 +00:00
|
|
|
+{
|
2014-09-12 06:52:55 +00:00
|
|
|
+ unsigned devfn = PCI_DEVFN(AR2315_PCI_HOST_SLOT, 0);
|
|
|
|
+ int res;
|
|
|
|
+ u32 id;
|
|
|
|
+
|
|
|
|
+ res = ar2315_pci_local_cfg_rd(devfn, PCI_VENDOR_ID, &id);
|
|
|
|
+ if (res != PCIBIOS_SUCCESSFUL || id != AR2315_PCI_HOST_DEVID)
|
|
|
|
+ return -ENODEV;
|
|
|
|
+
|
|
|
|
+ /* Program MBARs */
|
|
|
|
+ ar2315_pci_local_cfg_wr(devfn, PCI_BASE_ADDRESS_0, HOST_PCI_MBAR0);
|
|
|
|
+ ar2315_pci_local_cfg_wr(devfn, PCI_BASE_ADDRESS_1, HOST_PCI_MBAR1);
|
|
|
|
+ ar2315_pci_local_cfg_wr(devfn, PCI_BASE_ADDRESS_2, HOST_PCI_MBAR2);
|
|
|
|
+
|
|
|
|
+ /* Run */
|
|
|
|
+ ar2315_pci_local_cfg_wr(devfn, PCI_COMMAND, PCI_COMMAND_MEMORY |
|
|
|
|
+ PCI_COMMAND_MASTER | PCI_COMMAND_SPECIAL |
|
|
|
|
+ PCI_COMMAND_INVALIDATE | PCI_COMMAND_PARITY |
|
|
|
|
+ PCI_COMMAND_SERR | PCI_COMMAND_FAST_BACK);
|
|
|
|
+
|
|
|
|
+ return 0;
|
2014-08-04 20:54:49 +00:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static int __init
|
|
|
|
+ar2315_pci_init(void)
|
|
|
|
+{
|
|
|
|
+ u32 reg;
|
2014-09-12 06:52:55 +00:00
|
|
|
+ int res;
|
2014-08-04 20:54:49 +00:00
|
|
|
+
|
|
|
|
+ if (ar231x_devtype != DEV_TYPE_AR2315)
|
|
|
|
+ return -ENODEV;
|
|
|
|
+
|
|
|
|
+ /* Remap PCI config space */
|
2014-09-12 06:52:36 +00:00
|
|
|
+ configspace = (unsigned long)ioremap_nocache(AR2315_PCIEXT,
|
|
|
|
+ 1 * 1024 * 1024);
|
2014-09-12 06:52:51 +00:00
|
|
|
+ ar2315_pci_controller.io_map_base =
|
2014-09-12 06:52:36 +00:00
|
|
|
+ (unsigned long)ioremap_nocache(AR2315_MEM_BASE +
|
2014-08-04 20:54:49 +00:00
|
|
|
+ AR2315_MEM_SIZE, AR2315_IO_SIZE);
|
2014-09-12 06:52:51 +00:00
|
|
|
+ set_io_port_base(ar2315_pci_controller.io_map_base); /* PCI I/O space*/
|
2014-08-04 20:54:49 +00:00
|
|
|
+
|
|
|
|
+ reg = ar231x_mask_reg(AR2315_RESET, 0, AR2315_RESET_PCIDMA);
|
|
|
|
+ msleep(20);
|
|
|
|
+
|
|
|
|
+ reg &= ~AR2315_RESET_PCIDMA;
|
|
|
|
+ ar231x_write_reg(AR2315_RESET, reg);
|
|
|
|
+ msleep(20);
|
|
|
|
+
|
|
|
|
+ ar231x_mask_reg(AR2315_ENDIAN_CTL, 0,
|
2014-09-12 06:52:36 +00:00
|
|
|
+ AR2315_CONFIG_PCIAHB | AR2315_CONFIG_PCIAHB_BRIDGE);
|
2014-08-04 20:54:49 +00:00
|
|
|
+
|
|
|
|
+ ar231x_write_reg(AR2315_PCICLK, AR2315_PCICLK_PLLC_CLKM |
|
2014-09-12 06:52:36 +00:00
|
|
|
+ (AR2315_PCICLK_IN_FREQ_DIV_6 << AR2315_PCICLK_DIV_S));
|
2014-08-04 20:54:49 +00:00
|
|
|
+ ar231x_mask_reg(AR2315_AHB_ARB_CTL, 0, AR2315_ARB_PCI);
|
|
|
|
+ ar231x_mask_reg(AR2315_IF_CTL, AR2315_IF_PCI_CLK_MASK | AR2315_IF_MASK,
|
2014-09-12 06:52:36 +00:00
|
|
|
+ AR2315_IF_PCI | AR2315_IF_PCI_HOST |
|
|
|
|
+ AR2315_IF_PCI_INTR | (AR2315_IF_PCI_CLK_OUTPUT_CLK <<
|
|
|
|
+ AR2315_IF_PCI_CLK_SHIFT));
|
2014-08-04 20:54:49 +00:00
|
|
|
+
|
|
|
|
+ /* Reset the PCI bus by setting bits 5-4 in PCI_MCFG */
|
|
|
|
+ ar231x_mask_reg(AR2315_PCI_MISC_CONFIG, AR2315_PCIMISC_RST_MODE,
|
2014-09-12 06:52:36 +00:00
|
|
|
+ AR2315_PCIRST_LOW);
|
2014-08-04 20:54:49 +00:00
|
|
|
+ msleep(100);
|
|
|
|
+
|
|
|
|
+ /* Bring the PCI out of reset */
|
|
|
|
+ ar231x_mask_reg(AR2315_PCI_MISC_CONFIG, AR2315_PCIMISC_RST_MODE,
|
2014-09-12 06:52:36 +00:00
|
|
|
+ AR2315_PCIRST_HIGH | AR2315_PCICACHE_DIS | 0x8);
|
2014-08-04 20:54:49 +00:00
|
|
|
+
|
|
|
|
+ ar231x_write_reg(AR2315_PCI_UNCACHE_CFG,
|
2014-09-12 06:52:36 +00:00
|
|
|
+ 0x1E | /* 1GB uncached */
|
|
|
|
+ (1 << 5) | /* Enable uncached */
|
|
|
|
+ (0x2 << 30) /* Base: 0x80000000 */);
|
2014-08-04 20:54:49 +00:00
|
|
|
+ ar231x_read_reg(AR2315_PCI_UNCACHE_CFG);
|
|
|
|
+
|
|
|
|
+ msleep(500);
|
|
|
|
+
|
|
|
|
+ /* dirty hack - anyone with a datasheet that knows the memory map ? */
|
|
|
|
+ ioport_resource.start = 0x10000000;
|
|
|
|
+ ioport_resource.end = 0xffffffff;
|
|
|
|
+
|
2014-09-12 06:52:55 +00:00
|
|
|
+ res = ar2315_pci_host_setup();
|
|
|
|
+ if (res)
|
|
|
|
+ goto error;
|
|
|
|
+
|
2014-09-12 06:52:51 +00:00
|
|
|
+ register_pci_controller(&ar2315_pci_controller);
|
2014-08-04 20:54:49 +00:00
|
|
|
+
|
|
|
|
+ return 0;
|
2014-09-12 06:52:55 +00:00
|
|
|
+
|
|
|
|
+error:
|
|
|
|
+ iounmap((void __iomem *)configspace);
|
|
|
|
+ return res;
|
2014-08-04 20:54:49 +00:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
+arch_initcall(ar2315_pci_init);
|
|
|
|
--- a/arch/mips/ar231x/Kconfig
|
|
|
|
+++ b/arch/mips/ar231x/Kconfig
|
2014-09-12 06:52:42 +00:00
|
|
|
@@ -7,3 +7,10 @@ config ATHEROS_AR2315
|
|
|
|
bool "Atheros 2315+ support"
|
|
|
|
depends on ATHEROS_AR231X
|
2014-08-04 20:54:49 +00:00
|
|
|
default y
|
|
|
|
+
|
|
|
|
+config ATHEROS_AR2315_PCI
|
|
|
|
+ bool "PCI support"
|
|
|
|
+ depends on ATHEROS_AR2315
|
|
|
|
+ select HW_HAS_PCI
|
|
|
|
+ select PCI
|
|
|
|
+ default y
|
|
|
|
--- a/arch/mips/ar231x/ar2315.c
|
|
|
|
+++ b/arch/mips/ar231x/ar2315.c
|
|
|
|
@@ -87,6 +87,28 @@ static void ar2315_misc_irq_handler(unsi
|
|
|
|
do_IRQ(AR2315_MISC_IRQ_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
+#ifdef CONFIG_ATHEROS_AR2315_PCI
|
|
|
|
+static inline void pci_abort_irq(void)
|
|
|
|
+{
|
|
|
|
+ ar231x_write_reg(AR2315_PCI_INT_STATUS, AR2315_PCI_ABORT_INT);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static inline void pci_ack_irq(void)
|
|
|
|
+{
|
|
|
|
+ ar231x_write_reg(AR2315_PCI_INT_STATUS, AR2315_PCI_EXT_INT);
|
|
|
|
+}
|
|
|
|
+
|
2014-09-12 06:51:10 +00:00
|
|
|
+static void ar2315_pci_irq(int irq)
|
2014-08-04 20:54:49 +00:00
|
|
|
+{
|
|
|
|
+ if (ar231x_read_reg(AR2315_PCI_INT_STATUS) == AR2315_PCI_ABORT_INT)
|
|
|
|
+ pci_abort_irq();
|
|
|
|
+ else {
|
|
|
|
+ do_IRQ(irq);
|
|
|
|
+ pci_ack_irq();
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+#endif /* CONFIG_ATHEROS_AR2315_PCI */
|
|
|
|
+
|
|
|
|
/*
|
|
|
|
* Called when an interrupt is received, this function
|
|
|
|
* determines exactly which interrupt it was, and it
|
|
|
|
@@ -104,6 +126,10 @@ ar2315_irq_dispatch(void)
|
|
|
|
do_IRQ(AR2315_IRQ_WLAN0_INTRS);
|
|
|
|
else if (pending & CAUSEF_IP4)
|
|
|
|
do_IRQ(AR2315_IRQ_ENET0_INTRS);
|
|
|
|
+#ifdef CONFIG_ATHEROS_AR2315_PCI
|
|
|
|
+ else if (pending & CAUSEF_IP5)
|
|
|
|
+ ar2315_pci_irq(AR2315_IRQ_LCBUS_PCI);
|
|
|
|
+#endif
|
|
|
|
else if (pending & CAUSEF_IP2)
|
|
|
|
do_IRQ(AR2315_IRQ_MISC_INTRS);
|
|
|
|
else if (pending & CAUSEF_IP7)
|