Initial commit
Some checks failed
Build Kernel / Build all affected Kernels (push) Has been cancelled
Build all core packages / Build all core packages for selected target (push) Has been cancelled
Build and Push prebuilt tools container / Build and Push all prebuilt containers (push) Has been cancelled
Build Toolchains / Build Toolchains for each target (push) Has been cancelled
Build host tools / Build host tools for linux and macos based systems (push) Has been cancelled
Coverity scan build / Coverity x86/64 build (push) Has been cancelled
Some checks failed
Build Kernel / Build all affected Kernels (push) Has been cancelled
Build all core packages / Build all core packages for selected target (push) Has been cancelled
Build and Push prebuilt tools container / Build and Push all prebuilt containers (push) Has been cancelled
Build Toolchains / Build Toolchains for each target (push) Has been cancelled
Build host tools / Build host tools for linux and macos based systems (push) Has been cancelled
Coverity scan build / Coverity x86/64 build (push) Has been cancelled
This commit is contained in:
384
target/linux/bmips/files/drivers/leds/leds-sercomm-msp430.c
Normal file
384
target/linux/bmips/files/drivers/leds/leds-sercomm-msp430.c
Normal file
@@ -0,0 +1,384 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
/*
|
||||
* Driver for Sercomm MSP430G2513 LEDs.
|
||||
*
|
||||
* Copyright 2023 Álvaro Fernández Rojas <noltari@gmail.com>
|
||||
*/
|
||||
|
||||
#include <linux/delay.h>
|
||||
#include <linux/leds.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/of_device.h>
|
||||
#include <linux/spi/spi.h>
|
||||
#include "leds.h"
|
||||
|
||||
/*
|
||||
* MSP430G2513 SPI protocol description:
|
||||
* +----+----+----+----+----+----+
|
||||
* | b1 | b2 | b3 | b4 | b5 | b6 |
|
||||
* +----+----+----+----+----+----+
|
||||
* 6 bytes TX & RX per transaction.
|
||||
*
|
||||
* LEDs:
|
||||
* MSP430G2513 can control up to 9 LEDs.
|
||||
* b1: LED ID [1,9]
|
||||
* b2: LED function
|
||||
* b3-b6: LED function parameters
|
||||
*
|
||||
* LED functions:
|
||||
* [0] Off
|
||||
* [1] On
|
||||
* [2] Flash
|
||||
* - b4: delay (x 6ms)
|
||||
* - b5: repeat (0 = infinite)
|
||||
* [3] Pulse
|
||||
* - b3: delay (x 6ms)
|
||||
* - b4: blink while pulsing? (unknown)
|
||||
* - b5: repeat (0 = infinite)
|
||||
* [4] Pulse On
|
||||
* - b3: delay (x 6ms)
|
||||
* - b4: blink while pulsing? (unknown)
|
||||
* - b5: repeat (0 = infinite)
|
||||
* [5] Pulse Off
|
||||
* - b3: delay (x 6ms)
|
||||
* - b4: blink while pulsing? (unknown)
|
||||
* - b5: repeat (0 = infinite)
|
||||
* [6] Level
|
||||
* - b3: brightness [0,4]
|
||||
*
|
||||
* MCU Commands (b1 = 0x55):
|
||||
* [0x0a] FW upgrade data
|
||||
* - b3: Data size (usually 0x40), which is appended to TX & RX.
|
||||
* [0x31] Get MCU version? (unknown)
|
||||
* [0x68] Get MCU work mode
|
||||
* [0xa5] Start FW upgrade
|
||||
* [0xf0] End FW upgrade
|
||||
*/
|
||||
|
||||
#define MSP430_CMD_BYTES 6
|
||||
#define MSP430_CMD_MCU 0x55
|
||||
#define MSP430_MCU_WM 0x68
|
||||
|
||||
#define MSP430_LED_MIN_ID 1
|
||||
#define MSP430_LED_MAX_ID 9
|
||||
|
||||
#define MSP430_LED_OFF 0
|
||||
#define MSP430_LED_ON 1
|
||||
#define MSP430_LED_FLASH 2
|
||||
#define MSP430_LED_PULSE 3
|
||||
#define MSP430_LED_PULSE_ON 4
|
||||
#define MSP430_LED_PULSE_OFF 5
|
||||
#define MSP430_LED_LEVEL 6
|
||||
|
||||
#define MSP430_LED_BLINK_DEF 500
|
||||
#define MSP430_LED_BLINK_MASK 0xff
|
||||
#define MSP430_LED_BLINK_MS 6
|
||||
#define MSP430_LED_BLINK_MAX (MSP430_LED_BLINK_MS * \
|
||||
MSP430_LED_BLINK_MASK)
|
||||
|
||||
#define MSP430_LED_BRIGHTNESS_MAX 5
|
||||
#define MSP430_LED_REPEAT_MAX 0xff
|
||||
|
||||
/**
|
||||
* struct msp430_led - state container for Sercomm MSP430 based LEDs
|
||||
* @cdev: LED class device for this LED
|
||||
* @spi: spi resource
|
||||
* @id: LED ID
|
||||
*/
|
||||
struct msp430_led {
|
||||
struct led_classdev cdev;
|
||||
struct spi_device *spi;
|
||||
u8 id;
|
||||
};
|
||||
|
||||
static inline int msp430_cmd(struct spi_device *spi, u8 tx[MSP430_CMD_BYTES],
|
||||
u8 rx[MSP430_CMD_BYTES])
|
||||
{
|
||||
struct device *dev = &spi->dev;
|
||||
int rc;
|
||||
|
||||
memset(rx, 0, MSP430_CMD_BYTES);
|
||||
|
||||
rc = spi_write_then_read(spi, tx, MSP430_CMD_BYTES,
|
||||
rx, MSP430_CMD_BYTES);
|
||||
if (rc)
|
||||
dev_err(dev, "spi error\n");
|
||||
|
||||
dev_dbg(dev, "msp430_cmd: [%02x %02x %02x %02x %02x %02x]"
|
||||
" -> [%02x %02x %02x %02x %02x %02x]",
|
||||
tx[0], tx[1], tx[2], tx[3], tx[4], tx[5],
|
||||
rx[0], rx[1], rx[2], rx[3], rx[4], rx[5]);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static unsigned long msp430_blink_delay(unsigned long delay)
|
||||
{
|
||||
unsigned long msp430_delay;
|
||||
|
||||
msp430_delay = delay + MSP430_LED_BLINK_MS / 2;
|
||||
msp430_delay = msp430_delay / MSP430_LED_BLINK_MS;
|
||||
if (msp430_delay == 0)
|
||||
msp430_delay = 1;
|
||||
|
||||
return msp430_delay;
|
||||
}
|
||||
|
||||
static int msp430_blink_set(struct led_classdev *led_cdev,
|
||||
unsigned long *delay_on,
|
||||
unsigned long *delay_off)
|
||||
{
|
||||
struct msp430_led *led =
|
||||
container_of(led_cdev, struct msp430_led, cdev);
|
||||
u8 tx[MSP430_CMD_BYTES] = {led->id, MSP430_LED_FLASH, 0, 0, 0, 0};
|
||||
u8 rx[MSP430_CMD_BYTES];
|
||||
unsigned long delay;
|
||||
|
||||
if (!*delay_on)
|
||||
*delay_on = MSP430_LED_BLINK_DEF;
|
||||
if (!*delay_off)
|
||||
*delay_off = MSP430_LED_BLINK_DEF;
|
||||
|
||||
delay = msp430_blink_delay(*delay_on);
|
||||
if (delay != msp430_blink_delay(*delay_off)) {
|
||||
dev_dbg(led_cdev->dev,
|
||||
"fallback to soft blinking (delay_on != delay_off)\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (delay > MSP430_LED_BLINK_MASK) {
|
||||
dev_dbg(led_cdev->dev,
|
||||
"fallback to soft blinking (delay > %ums)\n",
|
||||
MSP430_LED_BLINK_MAX);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
tx[3] = delay;
|
||||
|
||||
return msp430_cmd(led->spi, tx, rx);
|
||||
}
|
||||
|
||||
static int msp430_brightness_set(struct led_classdev *led_cdev,
|
||||
enum led_brightness brightness)
|
||||
{
|
||||
struct msp430_led *led =
|
||||
container_of(led_cdev, struct msp430_led, cdev);
|
||||
u8 tx[MSP430_CMD_BYTES] = {led->id, 0, 0, 0, 0, 0};
|
||||
u8 rx[MSP430_CMD_BYTES];
|
||||
u8 val = (u8) brightness;
|
||||
|
||||
switch (val)
|
||||
{
|
||||
case LED_OFF:
|
||||
tx[1] = MSP430_LED_OFF;
|
||||
break;
|
||||
case MSP430_LED_BRIGHTNESS_MAX:
|
||||
tx[1] = MSP430_LED_ON;
|
||||
break;
|
||||
default:
|
||||
tx[1] = MSP430_LED_LEVEL;
|
||||
tx[2] = val - 1;
|
||||
break;
|
||||
}
|
||||
|
||||
return msp430_cmd(led->spi, tx, rx);
|
||||
}
|
||||
|
||||
static int msp430_pattern_clear(struct led_classdev *ldev)
|
||||
{
|
||||
msp430_brightness_set(ldev, LED_OFF);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int msp430_pattern_set(struct led_classdev *led_cdev,
|
||||
struct led_pattern *pattern,
|
||||
u32 len, int repeat)
|
||||
{
|
||||
struct msp430_led *led =
|
||||
container_of(led_cdev, struct msp430_led, cdev);
|
||||
u8 tx[MSP430_CMD_BYTES] = {led->id, 0, 0, 0, 0, 0};
|
||||
u8 rx[MSP430_CMD_BYTES];
|
||||
unsigned long delay0;
|
||||
unsigned long delay1;
|
||||
int rc;
|
||||
|
||||
if (len != 2 ||
|
||||
repeat > MSP430_LED_REPEAT_MAX ||
|
||||
pattern[0].delta_t > MSP430_LED_BLINK_MAX ||
|
||||
pattern[1].delta_t > MSP430_LED_BLINK_MAX)
|
||||
return -EINVAL;
|
||||
|
||||
delay0 = msp430_blink_delay(pattern[0].delta_t);
|
||||
delay1 = msp430_blink_delay(pattern[1].delta_t);
|
||||
|
||||
/* Infinite pattern */
|
||||
if (repeat < 0)
|
||||
repeat = 0;
|
||||
|
||||
/* Pulse: <off> <delay> <max> <delay> */
|
||||
if (delay0 == delay1 &&
|
||||
pattern[0].brightness == LED_OFF &&
|
||||
pattern[1].brightness == MSP430_LED_BRIGHTNESS_MAX)
|
||||
{
|
||||
tx[1] = MSP430_LED_PULSE;
|
||||
tx[2] = delay0;
|
||||
tx[4] = (u8) repeat;
|
||||
}
|
||||
|
||||
/* Pulse On: <off> <delay> <max> <0ms> */
|
||||
if (pattern[0].delta_t != 0 &&
|
||||
pattern[1].delta_t == 0 &&
|
||||
pattern[0].brightness == LED_OFF &&
|
||||
pattern[1].brightness == MSP430_LED_BRIGHTNESS_MAX) {
|
||||
tx[1] = MSP430_LED_PULSE_ON;
|
||||
tx[2] = delay0;
|
||||
tx[4] = (u8) repeat;
|
||||
}
|
||||
|
||||
/* Pulse Off: <max> <delay> <off> <0ms> */
|
||||
if (pattern[0].delta_t != 0 &&
|
||||
pattern[1].delta_t == 0 &&
|
||||
pattern[0].brightness == MSP430_LED_BRIGHTNESS_MAX &&
|
||||
pattern[1].brightness == LED_OFF) {
|
||||
tx[1] = MSP430_LED_PULSE_OFF;
|
||||
tx[2] = delay0;
|
||||
tx[4] = (u8) repeat;
|
||||
}
|
||||
|
||||
if (!tx[1])
|
||||
return -EINVAL;
|
||||
|
||||
rc = msp430_cmd(led->spi, tx, rx);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int msp430_led(struct spi_device *spi, struct device_node *nc, u8 id)
|
||||
{
|
||||
struct device *dev = &spi->dev;
|
||||
struct led_init_data init_data = {};
|
||||
struct msp430_led *led;
|
||||
enum led_default_state state;
|
||||
int rc;
|
||||
|
||||
led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL);
|
||||
if (!led)
|
||||
return -ENOMEM;
|
||||
|
||||
led->id = id;
|
||||
led->spi = spi;
|
||||
|
||||
init_data.fwnode = of_fwnode_handle(nc);
|
||||
|
||||
state = led_init_default_state_get(init_data.fwnode);
|
||||
switch (state) {
|
||||
case LEDS_DEFSTATE_ON:
|
||||
led->cdev.brightness = MSP430_LED_BRIGHTNESS_MAX;
|
||||
break;
|
||||
default:
|
||||
led->cdev.brightness = LED_OFF;
|
||||
break;
|
||||
}
|
||||
|
||||
msp430_brightness_set(&led->cdev, led->cdev.brightness);
|
||||
|
||||
led->cdev.blink_set = msp430_blink_set;
|
||||
led->cdev.brightness_set_blocking = msp430_brightness_set;
|
||||
led->cdev.max_brightness = MSP430_LED_BRIGHTNESS_MAX;
|
||||
led->cdev.pattern_clear = msp430_pattern_clear;
|
||||
led->cdev.pattern_set = msp430_pattern_set;
|
||||
|
||||
rc = devm_led_classdev_register_ext(dev, &led->cdev, &init_data);
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
|
||||
dev_dbg(dev, "registered LED %s\n", led->cdev.name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int msp430_check_workmode(struct spi_device *spi)
|
||||
{
|
||||
struct device *dev = &spi->dev;
|
||||
u8 tx[MSP430_CMD_BYTES] = {MSP430_CMD_MCU, MSP430_MCU_WM, 0, 0, 0, 0};
|
||||
u8 rx[MSP430_CMD_BYTES];
|
||||
int rc;
|
||||
|
||||
rc = msp430_cmd(spi, tx, rx);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
if ((rx[3] == 0xA5 && rx[4] == 'Z') ||
|
||||
(rx[4] == 0xA5 && rx[5] == 'Z') ||
|
||||
(rx[4] == '\b' && rx[5] == '\n')) {
|
||||
dev_err(dev, "invalid workmode: "
|
||||
"[%02x %02x %02x %02x %02x %02x]\n",
|
||||
rx[0], rx[1], rx[2], rx[3], rx[4], rx[5]);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int msp430_leds_probe(struct spi_device *spi)
|
||||
{
|
||||
struct device *dev = &spi->dev;
|
||||
struct device_node *np = dev_of_node(dev);
|
||||
struct device_node *child;
|
||||
int rc;
|
||||
|
||||
rc = msp430_check_workmode(spi);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
for_each_available_child_of_node(np, child) {
|
||||
u32 reg;
|
||||
|
||||
if (of_property_read_u32(child, "reg", ®))
|
||||
continue;
|
||||
|
||||
if (reg < MSP430_LED_MIN_ID || reg > MSP430_LED_MAX_ID) {
|
||||
dev_err(dev, "invalid LED (%u) [%d, %d]\n", reg,
|
||||
MSP430_LED_MIN_ID, MSP430_LED_MAX_ID);
|
||||
continue;
|
||||
}
|
||||
|
||||
rc = msp430_led(spi, child, reg);
|
||||
if (rc < 0) {
|
||||
of_node_put(child);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct of_device_id msp430_leds_of_match[] = {
|
||||
{ .compatible = "sercomm,msp430-leds", },
|
||||
{ /* sentinel */ },
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, msp430_leds_of_match);
|
||||
|
||||
static const struct spi_device_id msp430_leds_id_table[] = {
|
||||
{ "msp430-leds", 0 },
|
||||
{ /* sentinel */ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(spi, msp430_leds_id_table);
|
||||
|
||||
static struct spi_driver msp430_leds_driver = {
|
||||
.driver = {
|
||||
.name = KBUILD_MODNAME,
|
||||
.of_match_table = msp430_leds_of_match,
|
||||
},
|
||||
.id_table = msp430_leds_id_table,
|
||||
.probe = msp430_leds_probe,
|
||||
};
|
||||
module_spi_driver(msp430_leds_driver);
|
||||
|
||||
MODULE_AUTHOR("Álvaro Fernández Rojas <noltari@gmail.com>");
|
||||
MODULE_DESCRIPTION("LED driver for Sercomm MSP430 controllers");
|
||||
MODULE_LICENSE("GPL v2");
|
||||
MODULE_ALIAS("platform:leds-sercomm-msp430");
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
815
target/linux/bmips/files/drivers/pci/controller/pci-bcm6348.c
Normal file
815
target/linux/bmips/files/drivers/pci/controller/pci-bcm6348.c
Normal file
@@ -0,0 +1,815 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
/*
|
||||
* BCM6348 PCI Controller Driver
|
||||
*
|
||||
* Copyright (C) 2020 Álvaro Fernández Rojas <noltari@gmail.com>
|
||||
* Copyright (C) 2015 Jonas Gorski <jonas.gorski@gmail.com>
|
||||
* Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
|
||||
*/
|
||||
|
||||
#include <linux/clk.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/memblock.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/of_address.h>
|
||||
#include <linux/of_gpio.h>
|
||||
#include <linux/of_irq.h>
|
||||
#include <linux/of_pci.h>
|
||||
#include <linux/of_platform.h>
|
||||
#include <linux/pci.h>
|
||||
#include <linux/reset.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/vmalloc.h>
|
||||
|
||||
#include "../pci.h"
|
||||
|
||||
#define CARDBUS_DUMMY_ID 0x6348
|
||||
#define CARDBUS_PCI_IDSEL 0x8
|
||||
#define FAKE_CB_BRIDGE_SLOT 0x1e
|
||||
|
||||
#define BCMPCI_REG_TIMERS 0x40
|
||||
#define REG_TIMER_TRDY_SHIFT 0
|
||||
#define REG_TIMER_TRDY_MASK (0xff << REG_TIMER_TRDY_SHIFT)
|
||||
#define REG_TIMER_RETRY_SHIFT 8
|
||||
#define REG_TIMER_RETRY_MASK (0xff << REG_TIMER_RETRY_SHIFT)
|
||||
|
||||
#define MPI_SP0_RANGE_REG 0x100
|
||||
#define MPI_SP0_REMAP_REG 0x104
|
||||
#define MPI_SP0_REMAP_ENABLE_MASK (1 << 0)
|
||||
#define MPI_SP1_RANGE_REG 0x10C
|
||||
#define MPI_SP1_REMAP_REG 0x110
|
||||
#define MPI_SP1_REMAP_ENABLE_MASK (1 << 0)
|
||||
|
||||
#define MPI_L2PCFG_REG 0x11c
|
||||
#define MPI_L2PCFG_CFG_TYPE_SHIFT 0
|
||||
#define MPI_L2PCFG_CFG_TYPE_MASK (0x3 << MPI_L2PCFG_CFG_TYPE_SHIFT)
|
||||
#define MPI_L2PCFG_REG_SHIFT 2
|
||||
#define MPI_L2PCFG_REG_MASK (0x3f << MPI_L2PCFG_REG_SHIFT)
|
||||
#define MPI_L2PCFG_FUNC_SHIFT 8
|
||||
#define MPI_L2PCFG_FUNC_MASK (0x7 << MPI_L2PCFG_FUNC_SHIFT)
|
||||
#define MPI_L2PCFG_DEVNUM_SHIFT 11
|
||||
#define MPI_L2PCFG_DEVNUM_MASK (0x1f << MPI_L2PCFG_DEVNUM_SHIFT)
|
||||
#define MPI_L2PCFG_CFG_USEREG_MASK (1 << 30)
|
||||
#define MPI_L2PCFG_CFG_SEL_MASK (1 << 31)
|
||||
|
||||
#define MPI_L2PMEMRANGE1_REG 0x120
|
||||
#define MPI_L2PMEMBASE1_REG 0x124
|
||||
#define MPI_L2PMEMREMAP1_REG 0x128
|
||||
#define MPI_L2PMEMRANGE2_REG 0x12C
|
||||
#define MPI_L2PMEMBASE2_REG 0x130
|
||||
#define MPI_L2PMEMREMAP2_REG 0x134
|
||||
#define MPI_L2PIORANGE_REG 0x138
|
||||
#define MPI_L2PIOBASE_REG 0x13C
|
||||
#define MPI_L2PIOREMAP_REG 0x140
|
||||
#define MPI_L2P_BASE_MASK (0xffff8000)
|
||||
#define MPI_L2PREMAP_ENABLED_MASK (1 << 0)
|
||||
#define MPI_L2PREMAP_IS_CARDBUS_MASK (1 << 2)
|
||||
|
||||
#define MPI_PCIMODESEL_REG 0x144
|
||||
#define MPI_PCIMODESEL_BAR1_NOSWAP_MASK (1 << 0)
|
||||
#define MPI_PCIMODESEL_BAR2_NOSWAP_MASK (1 << 1)
|
||||
#define MPI_PCIMODESEL_EXT_ARB_MASK (1 << 2)
|
||||
#define MPI_PCIMODESEL_PREFETCH_SHIFT 4
|
||||
#define MPI_PCIMODESEL_PREFETCH_MASK (0xf << MPI_PCIMODESEL_PREFETCH_SHIFT)
|
||||
|
||||
#define MPI_LOCBUSCTL_REG 0x14c
|
||||
#define MPI_LOCBUSCTL_EN_PCI_GPIO_MASK (1 << 0)
|
||||
#define MPI_LOCBUSCTL_U2P_NOSWAP_MASK (1 << 1)
|
||||
|
||||
#define MPI_LOCINT_REG 0x150
|
||||
#define MPI_LOCINT_MASK(x) (1 << (x + 16))
|
||||
#define MPI_LOCINT_STAT(x) (1 << (x))
|
||||
#define MPI_LOCINT_DIR_FAILED 6
|
||||
#define MPI_LOCINT_EXT_PCI_INT 7
|
||||
#define MPI_LOCINT_SERR 8
|
||||
#define MPI_LOCINT_CSERR 9
|
||||
|
||||
#define MPI_PCICFGCTL_REG 0x178
|
||||
#define MPI_PCICFGCTL_CFGADDR_SHIFT 2
|
||||
#define MPI_PCICFGCTL_CFGADDR_MASK (0x1f << MPI_PCICFGCTL_CFGADDR_SHIFT)
|
||||
#define MPI_PCICFGCTL_WRITEEN_MASK (1 << 7)
|
||||
|
||||
#define MPI_PCICFGDATA_REG 0x17c
|
||||
|
||||
#define PCMCIA_OFFSET 0x54
|
||||
|
||||
#define PCMCIA_C1_REG 0x0
|
||||
#define PCMCIA_C1_CD1_MASK (1 << 0)
|
||||
#define PCMCIA_C1_CD2_MASK (1 << 1)
|
||||
#define PCMCIA_C1_VS1_MASK (1 << 2)
|
||||
#define PCMCIA_C1_VS2_MASK (1 << 3)
|
||||
#define PCMCIA_C1_VS1OE_MASK (1 << 6)
|
||||
#define PCMCIA_C1_VS2OE_MASK (1 << 7)
|
||||
#define PCMCIA_C1_CBIDSEL_SHIFT (8)
|
||||
#define PCMCIA_C1_CBIDSEL_MASK (0x1f << PCMCIA_C1_CBIDSEL_SHIFT)
|
||||
#define PCMCIA_C1_EN_PCMCIA_GPIO_MASK (1 << 13)
|
||||
#define PCMCIA_C1_EN_PCMCIA_MASK (1 << 14)
|
||||
#define PCMCIA_C1_EN_CARDBUS_MASK (1 << 15)
|
||||
#define PCMCIA_C1_RESET_MASK (1 << 18)
|
||||
|
||||
#ifdef CONFIG_CARDBUS
|
||||
struct bcm6348_cb {
|
||||
u16 pci_command;
|
||||
u8 cb_latency;
|
||||
u8 subordinate_busn;
|
||||
u8 cardbus_busn;
|
||||
u8 pci_busn;
|
||||
int bus_assigned;
|
||||
u16 bridge_control;
|
||||
|
||||
u32 mem_base0;
|
||||
u32 mem_limit0;
|
||||
u32 mem_base1;
|
||||
u32 mem_limit1;
|
||||
|
||||
u32 io_base0;
|
||||
u32 io_limit0;
|
||||
u32 io_base1;
|
||||
u32 io_limit1;
|
||||
};
|
||||
#endif /* CONFIG_CARDBUS */
|
||||
|
||||
struct bcm6348_pci {
|
||||
void __iomem *pci;
|
||||
void __iomem *pcmcia;
|
||||
void __iomem *io;
|
||||
int irq;
|
||||
struct reset_control *reset;
|
||||
bool remap;
|
||||
#ifdef CONFIG_CARDBUS
|
||||
struct bcm6348_cb cb;
|
||||
int cb_bus;
|
||||
#endif /* CONFIG_CARDBUS */
|
||||
};
|
||||
|
||||
static struct bcm6348_pci bcm6348_pci;
|
||||
|
||||
extern int bmips_pci_irq;
|
||||
|
||||
static u32 bcm6348_int_cfg_readl(u32 reg)
|
||||
{
|
||||
struct bcm6348_pci *priv = &bcm6348_pci;
|
||||
u32 tmp;
|
||||
|
||||
tmp = reg & MPI_PCICFGCTL_CFGADDR_MASK;
|
||||
tmp |= MPI_PCICFGCTL_WRITEEN_MASK;
|
||||
__raw_writel(tmp, priv->pci + MPI_PCICFGCTL_REG);
|
||||
iob();
|
||||
return __raw_readl(priv->pci + MPI_PCICFGDATA_REG);
|
||||
}
|
||||
|
||||
static void bcm6348_int_cfg_writel(u32 val, u32 reg)
|
||||
{
|
||||
struct bcm6348_pci *priv = &bcm6348_pci;
|
||||
u32 tmp;
|
||||
|
||||
tmp = reg & MPI_PCICFGCTL_CFGADDR_MASK;
|
||||
tmp |= MPI_PCICFGCTL_WRITEEN_MASK;
|
||||
__raw_writel(tmp, priv->pci + MPI_PCICFGCTL_REG);
|
||||
__raw_writel(val, priv->pci + MPI_PCICFGDATA_REG);
|
||||
}
|
||||
|
||||
/*
|
||||
* swizzle 32bits data to return only the needed part
|
||||
*/
|
||||
static int postprocess_read(u32 data, int where, unsigned int size)
|
||||
{
|
||||
u32 ret = 0;
|
||||
|
||||
switch (size) {
|
||||
case 1:
|
||||
ret = (data >> ((where & 3) << 3)) & 0xff;
|
||||
break;
|
||||
case 2:
|
||||
ret = (data >> ((where & 3) << 3)) & 0xffff;
|
||||
break;
|
||||
case 4:
|
||||
ret = data;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int preprocess_write(u32 orig_data, u32 val, int where,
|
||||
unsigned int size)
|
||||
{
|
||||
u32 ret = 0;
|
||||
|
||||
switch (size) {
|
||||
case 1:
|
||||
ret = (orig_data & ~(0xff << ((where & 3) << 3))) |
|
||||
(val << ((where & 3) << 3));
|
||||
break;
|
||||
case 2:
|
||||
ret = (orig_data & ~(0xffff << ((where & 3) << 3))) |
|
||||
(val << ((where & 3) << 3));
|
||||
break;
|
||||
case 4:
|
||||
ret = val;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int bcm6348_setup_cfg_access(int type, unsigned int busn,
|
||||
unsigned int devfn, int where)
|
||||
{
|
||||
struct bcm6348_pci *priv = &bcm6348_pci;
|
||||
unsigned int slot, func, reg;
|
||||
u32 val;
|
||||
|
||||
slot = PCI_SLOT(devfn);
|
||||
func = PCI_FUNC(devfn);
|
||||
reg = where >> 2;
|
||||
|
||||
/* sanity check */
|
||||
if (slot > (MPI_L2PCFG_DEVNUM_MASK >> MPI_L2PCFG_DEVNUM_SHIFT))
|
||||
return 1;
|
||||
|
||||
if (func > (MPI_L2PCFG_FUNC_MASK >> MPI_L2PCFG_FUNC_SHIFT))
|
||||
return 1;
|
||||
|
||||
if (reg > (MPI_L2PCFG_REG_MASK >> MPI_L2PCFG_REG_SHIFT))
|
||||
return 1;
|
||||
|
||||
/* ok, setup config access */
|
||||
val = (reg << MPI_L2PCFG_REG_SHIFT);
|
||||
val |= (func << MPI_L2PCFG_FUNC_SHIFT);
|
||||
val |= (slot << MPI_L2PCFG_DEVNUM_SHIFT);
|
||||
val |= MPI_L2PCFG_CFG_USEREG_MASK;
|
||||
val |= MPI_L2PCFG_CFG_SEL_MASK;
|
||||
/* type 0 cycle for local bus, type 1 cycle for anything else */
|
||||
if (type != 0) {
|
||||
/* FIXME: how to specify bus ??? */
|
||||
val |= (1 << MPI_L2PCFG_CFG_TYPE_SHIFT);
|
||||
}
|
||||
__raw_writel(val, priv->pci + MPI_L2PCFG_REG);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int bcm6348_do_cfg_read(int type, unsigned int busn,
|
||||
unsigned int devfn, int where, int size,
|
||||
u32 *val)
|
||||
{
|
||||
struct bcm6348_pci *priv = &bcm6348_pci;
|
||||
u32 data;
|
||||
|
||||
/* two phase cycle, first we write address, then read data at
|
||||
* another location, caller already has a spinlock so no need
|
||||
* to add one here */
|
||||
if (bcm6348_setup_cfg_access(type, busn, devfn, where))
|
||||
return PCIBIOS_DEVICE_NOT_FOUND;
|
||||
iob();
|
||||
data = le32_to_cpu(__raw_readl(priv->io));
|
||||
/* restore IO space normal behaviour */
|
||||
__raw_writel(0, priv->pci + MPI_L2PCFG_REG);
|
||||
|
||||
*val = postprocess_read(data, where, size);
|
||||
|
||||
return PCIBIOS_SUCCESSFUL;
|
||||
}
|
||||
|
||||
static int bcm6348_do_cfg_write(int type, unsigned int busn,
|
||||
unsigned int devfn, int where, int size,
|
||||
u32 val)
|
||||
{
|
||||
struct bcm6348_pci *priv = &bcm6348_pci;
|
||||
u32 data;
|
||||
|
||||
/* two phase cycle, first we write address, then write data to
|
||||
* another location, caller already has a spinlock so no need
|
||||
* to add one here */
|
||||
if (bcm6348_setup_cfg_access(type, busn, devfn, where))
|
||||
return PCIBIOS_DEVICE_NOT_FOUND;
|
||||
iob();
|
||||
|
||||
data = le32_to_cpu(__raw_readl(priv->io));
|
||||
data = preprocess_write(data, val, where, size);
|
||||
|
||||
__raw_writel(cpu_to_le32(data), priv->io);
|
||||
wmb();
|
||||
/* no way to know the access is done, we have to wait */
|
||||
udelay(500);
|
||||
/* restore IO space normal behaviour */
|
||||
__raw_writel(0, priv->pci + MPI_L2PCFG_REG);
|
||||
|
||||
return PCIBIOS_SUCCESSFUL;
|
||||
}
|
||||
|
||||
static int bcm6348_pci_read(struct pci_bus *bus, unsigned int devfn,
|
||||
int where, int size, u32 *val)
|
||||
{
|
||||
int type;
|
||||
|
||||
type = bus->parent ? 1 : 0;
|
||||
|
||||
if (type == 0 && PCI_SLOT(devfn) == CARDBUS_PCI_IDSEL)
|
||||
return PCIBIOS_DEVICE_NOT_FOUND;
|
||||
|
||||
return bcm6348_do_cfg_read(type, bus->number, devfn,
|
||||
where, size, val);
|
||||
}
|
||||
|
||||
static int bcm6348_pci_write(struct pci_bus *bus, unsigned int devfn,
|
||||
int where, int size, u32 val)
|
||||
{
|
||||
int type;
|
||||
|
||||
type = bus->parent ? 1 : 0;
|
||||
|
||||
if (type == 0 && PCI_SLOT(devfn) == CARDBUS_PCI_IDSEL)
|
||||
return PCIBIOS_DEVICE_NOT_FOUND;
|
||||
|
||||
return bcm6348_do_cfg_write(type, bus->number, devfn,
|
||||
where, size, val);
|
||||
}
|
||||
|
||||
static struct pci_ops bcm6348_pci_ops = {
|
||||
.read = bcm6348_pci_read,
|
||||
.write = bcm6348_pci_write,
|
||||
};
|
||||
|
||||
static struct resource bcm6348_pci_io_resource;
|
||||
static struct resource bcm6348_pci_mem_resource;
|
||||
static struct resource bcm6348_pci_busn_resource;
|
||||
|
||||
static struct pci_controller bcm6348_pci_controller = {
|
||||
.pci_ops = &bcm6348_pci_ops,
|
||||
.io_resource = &bcm6348_pci_io_resource,
|
||||
.mem_resource = &bcm6348_pci_mem_resource,
|
||||
};
|
||||
|
||||
#ifdef CONFIG_CARDBUS
|
||||
static int bcm6348_cb_bridge_read(int where, int size, u32 *val)
|
||||
{
|
||||
struct bcm6348_cb *cb = &bcm6348_pci.cb;
|
||||
unsigned int reg;
|
||||
u32 data;
|
||||
|
||||
data = 0;
|
||||
reg = where >> 2;
|
||||
switch (reg) {
|
||||
case (PCI_VENDOR_ID >> 2):
|
||||
case (PCI_CB_SUBSYSTEM_VENDOR_ID >> 2):
|
||||
/* create dummy vendor/device id from our cpu id */
|
||||
data = (CARDBUS_DUMMY_ID << 16) | PCI_VENDOR_ID_BROADCOM;
|
||||
break;
|
||||
|
||||
case (PCI_COMMAND >> 2):
|
||||
data = (PCI_STATUS_DEVSEL_SLOW << 16);
|
||||
data |= cb->pci_command;
|
||||
break;
|
||||
|
||||
case (PCI_CLASS_REVISION >> 2):
|
||||
data = (PCI_CLASS_BRIDGE_CARDBUS << 16);
|
||||
break;
|
||||
|
||||
case (PCI_CACHE_LINE_SIZE >> 2):
|
||||
data = (PCI_HEADER_TYPE_CARDBUS << 16);
|
||||
break;
|
||||
|
||||
case (PCI_INTERRUPT_LINE >> 2):
|
||||
/* bridge control */
|
||||
data = (cb->bridge_control << 16);
|
||||
/* pin:intA line:0xff */
|
||||
data |= (0x1 << 8) | 0xff;
|
||||
break;
|
||||
|
||||
case (PCI_CB_PRIMARY_BUS >> 2):
|
||||
data = (cb->cb_latency << 24);
|
||||
data |= (cb->subordinate_busn << 16);
|
||||
data |= (cb->cardbus_busn << 8);
|
||||
data |= cb->pci_busn;
|
||||
break;
|
||||
|
||||
case (PCI_CB_MEMORY_BASE_0 >> 2):
|
||||
data = cb->mem_base0;
|
||||
break;
|
||||
|
||||
case (PCI_CB_MEMORY_LIMIT_0 >> 2):
|
||||
data = cb->mem_limit0;
|
||||
break;
|
||||
|
||||
case (PCI_CB_MEMORY_BASE_1 >> 2):
|
||||
data = cb->mem_base1;
|
||||
break;
|
||||
|
||||
case (PCI_CB_MEMORY_LIMIT_1 >> 2):
|
||||
data = cb->mem_limit1;
|
||||
break;
|
||||
|
||||
case (PCI_CB_IO_BASE_0 >> 2):
|
||||
/* | 1 for 32bits io support */
|
||||
data = cb->io_base0 | 0x1;
|
||||
break;
|
||||
|
||||
case (PCI_CB_IO_LIMIT_0 >> 2):
|
||||
data = cb->io_limit0;
|
||||
break;
|
||||
|
||||
case (PCI_CB_IO_BASE_1 >> 2):
|
||||
/* | 1 for 32bits io support */
|
||||
data = cb->io_base1 | 0x1;
|
||||
break;
|
||||
|
||||
case (PCI_CB_IO_LIMIT_1 >> 2):
|
||||
data = cb->io_limit1;
|
||||
break;
|
||||
}
|
||||
|
||||
*val = postprocess_read(data, where, size);
|
||||
return PCIBIOS_SUCCESSFUL;
|
||||
}
|
||||
|
||||
/*
|
||||
* emulate configuration write access on a cardbus bridge
|
||||
*/
|
||||
static int bcm6348_cb_bridge_write(int where, int size, u32 val)
|
||||
{
|
||||
struct bcm6348_cb *cb = &bcm6348_pci.cb;
|
||||
unsigned int reg;
|
||||
u32 data, tmp;
|
||||
int ret;
|
||||
|
||||
ret = bcm6348_cb_bridge_read((where & ~0x3), 4, &data);
|
||||
if (ret != PCIBIOS_SUCCESSFUL)
|
||||
return ret;
|
||||
|
||||
data = preprocess_write(data, val, where, size);
|
||||
|
||||
reg = where >> 2;
|
||||
switch (reg) {
|
||||
case (PCI_COMMAND >> 2):
|
||||
cb->pci_command = (data & 0xffff);
|
||||
break;
|
||||
|
||||
case (PCI_CB_PRIMARY_BUS >> 2):
|
||||
cb->cb_latency = (data >> 24) & 0xff;
|
||||
cb->subordinate_busn = (data >> 16) & 0xff;
|
||||
cb->cardbus_busn = (data >> 8) & 0xff;
|
||||
cb->pci_busn = data & 0xff;
|
||||
if (cb->cardbus_busn)
|
||||
cb->bus_assigned = 1;
|
||||
break;
|
||||
|
||||
case (PCI_INTERRUPT_LINE >> 2):
|
||||
tmp = (data >> 16) & 0xffff;
|
||||
/* Disable memory prefetch support */
|
||||
tmp &= ~PCI_CB_BRIDGE_CTL_PREFETCH_MEM0;
|
||||
tmp &= ~PCI_CB_BRIDGE_CTL_PREFETCH_MEM1;
|
||||
cb->bridge_control = tmp;
|
||||
break;
|
||||
|
||||
case (PCI_CB_MEMORY_BASE_0 >> 2):
|
||||
cb->mem_base0 = data;
|
||||
break;
|
||||
|
||||
case (PCI_CB_MEMORY_LIMIT_0 >> 2):
|
||||
cb->mem_limit0 = data;
|
||||
break;
|
||||
|
||||
case (PCI_CB_MEMORY_BASE_1 >> 2):
|
||||
cb->mem_base1 = data;
|
||||
break;
|
||||
|
||||
case (PCI_CB_MEMORY_LIMIT_1 >> 2):
|
||||
cb->mem_limit1 = data;
|
||||
break;
|
||||
|
||||
case (PCI_CB_IO_BASE_0 >> 2):
|
||||
cb->io_base0 = data;
|
||||
break;
|
||||
|
||||
case (PCI_CB_IO_LIMIT_0 >> 2):
|
||||
cb->io_limit0 = data;
|
||||
break;
|
||||
|
||||
case (PCI_CB_IO_BASE_1 >> 2):
|
||||
cb->io_base1 = data;
|
||||
break;
|
||||
|
||||
case (PCI_CB_IO_LIMIT_1 >> 2):
|
||||
cb->io_limit1 = data;
|
||||
break;
|
||||
}
|
||||
|
||||
return PCIBIOS_SUCCESSFUL;
|
||||
}
|
||||
|
||||
static int bcm6348_cb_read(struct pci_bus *bus, unsigned int devfn,
|
||||
int where, int size, u32 *val)
|
||||
{
|
||||
struct bcm6348_pci *priv = &bcm6348_pci;
|
||||
struct bcm6348_cb *cb = &priv->cb;
|
||||
|
||||
/* Snoop access to slot 0x1e on root bus, we fake a cardbus
|
||||
* bridge at this location */
|
||||
if (!bus->parent && PCI_SLOT(devfn) == FAKE_CB_BRIDGE_SLOT) {
|
||||
priv->cb_bus = bus->number;
|
||||
return bcm6348_cb_bridge_read(where, size, val);
|
||||
}
|
||||
|
||||
/* A configuration cycle for the device behind the cardbus
|
||||
* bridge is actually done as a type 0 cycle on the primary
|
||||
* bus. This means that only one device can be on the cardbus
|
||||
* bus */
|
||||
if (cb->bus_assigned &&
|
||||
bus->number == cb->cardbus_busn &&
|
||||
PCI_SLOT(devfn) == 0)
|
||||
return bcm6348_do_cfg_read(0, 0,
|
||||
PCI_DEVFN(CARDBUS_PCI_IDSEL, 0),
|
||||
where, size, val);
|
||||
|
||||
return PCIBIOS_DEVICE_NOT_FOUND;
|
||||
}
|
||||
|
||||
static int bcm6348_cb_write(struct pci_bus *bus, unsigned int devfn,
|
||||
int where, int size, u32 val)
|
||||
{
|
||||
struct bcm6348_pci *priv = &bcm6348_pci;
|
||||
struct bcm6348_cb *cb = &priv->cb;
|
||||
|
||||
if (!bus->parent && PCI_SLOT(devfn) == FAKE_CB_BRIDGE_SLOT) {
|
||||
priv->cb_bus = bus->number;
|
||||
return bcm6348_cb_bridge_write(where, size, val);
|
||||
}
|
||||
|
||||
if (cb->bus_assigned &&
|
||||
bus->number == cb->cardbus_busn &&
|
||||
PCI_SLOT(devfn) == 0)
|
||||
return bcm6348_do_cfg_write(0, 0,
|
||||
PCI_DEVFN(CARDBUS_PCI_IDSEL, 0),
|
||||
where, size, val);
|
||||
|
||||
return PCIBIOS_DEVICE_NOT_FOUND;
|
||||
}
|
||||
|
||||
static struct pci_ops bcm6348_cb_ops = {
|
||||
.read = bcm6348_cb_read,
|
||||
.write = bcm6348_cb_write,
|
||||
};
|
||||
|
||||
/*
|
||||
* only one IO window, so it cannot be shared by PCI and cardbus, use
|
||||
* fixup to choose and detect unhandled configuration
|
||||
*/
|
||||
static void bcm6348_pci_fixup(struct pci_dev *dev)
|
||||
{
|
||||
struct bcm6348_pci *priv = &bcm6348_pci;
|
||||
struct bcm6348_cb *cb = &priv->cb;
|
||||
static int io_window = -1;
|
||||
int i, found, new_io_window;
|
||||
u32 val;
|
||||
|
||||
/* look for any io resource */
|
||||
found = 0;
|
||||
for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
|
||||
if (pci_resource_flags(dev, i) & IORESOURCE_IO) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
return;
|
||||
|
||||
/* skip our fake bus with only cardbus bridge on it */
|
||||
if (dev->bus->number == priv->cb_bus)
|
||||
return;
|
||||
|
||||
/* find on which bus the device is */
|
||||
if (cb->bus_assigned &&
|
||||
dev->bus->number == cb->cardbus_busn &&
|
||||
PCI_SLOT(dev->devfn) == 0)
|
||||
new_io_window = 1;
|
||||
else
|
||||
new_io_window = 0;
|
||||
|
||||
if (new_io_window == io_window)
|
||||
return;
|
||||
|
||||
if (io_window != -1) {
|
||||
pr_err("bcm63xx: both PCI and cardbus devices "
|
||||
"need IO, which hardware cannot do\n");
|
||||
return;
|
||||
}
|
||||
|
||||
pr_info("bcm63xx: PCI IO window assigned to %s\n",
|
||||
(new_io_window == 0) ? "PCI" : "cardbus");
|
||||
|
||||
val = __raw_readl(priv->pci + MPI_L2PIOREMAP_REG);
|
||||
if (io_window)
|
||||
val |= MPI_L2PREMAP_IS_CARDBUS_MASK;
|
||||
else
|
||||
val &= ~MPI_L2PREMAP_IS_CARDBUS_MASK;
|
||||
__raw_writel(val, priv->pci + MPI_L2PIOREMAP_REG);
|
||||
|
||||
io_window = new_io_window;
|
||||
}
|
||||
DECLARE_PCI_FIXUP_ENABLE(PCI_ANY_ID, PCI_ANY_ID, bcm6348_pci_fixup);
|
||||
|
||||
static struct resource bcm6348_cb_io_resource = {
|
||||
.name = "bcm6348 CB IO space",
|
||||
.flags = IORESOURCE_IO,
|
||||
};
|
||||
static struct resource bcm6348_cb_mem_resource;
|
||||
|
||||
static struct pci_controller bcm6348_cb_controller = {
|
||||
.pci_ops = &bcm6348_cb_ops,
|
||||
.io_resource = &bcm6348_cb_io_resource,
|
||||
.mem_resource = &bcm6348_cb_mem_resource,
|
||||
};
|
||||
#endif /* CONFIG_CARDBUS */
|
||||
|
||||
static void bcm6348_pci_setup(struct bcm6348_pci *priv)
|
||||
{
|
||||
u32 val;
|
||||
|
||||
/* Setup local bus to PCI access (PCI memory) */
|
||||
val = bcm6348_pci_mem_resource.start & MPI_L2P_BASE_MASK;
|
||||
__raw_writel(val, priv->pci + MPI_L2PMEMBASE1_REG);
|
||||
__raw_writel(~(resource_size(&bcm6348_pci_mem_resource) - 1),
|
||||
priv->pci + MPI_L2PMEMRANGE1_REG);
|
||||
__raw_writel(val | MPI_L2PREMAP_ENABLED_MASK,
|
||||
priv->pci + MPI_L2PMEMREMAP1_REG);
|
||||
|
||||
/* Set Cardbus IDSEL (type 0 cfg access on primary bus for
|
||||
* this IDSEL will be done on Cardbus instead) */
|
||||
val = __raw_readl(priv->pcmcia + PCMCIA_C1_REG);
|
||||
val &= ~PCMCIA_C1_CBIDSEL_MASK;
|
||||
val |= (CARDBUS_PCI_IDSEL << PCMCIA_C1_CBIDSEL_SHIFT);
|
||||
__raw_writel(val, priv->pcmcia + PCMCIA_C1_REG);
|
||||
|
||||
#ifdef CONFIG_CARDBUS
|
||||
/* setup local bus to PCI access (Cardbus memory) */
|
||||
val = bcm6348_cb_mem_resource.start & MPI_L2P_BASE_MASK;
|
||||
__raw_writel(val, priv->pci + MPI_L2PMEMBASE2_REG);
|
||||
__raw_writel(~(resource_size(&bcm6348_cb_mem_resource) - 1),
|
||||
priv->pci + MPI_L2PMEMRANGE2_REG);
|
||||
val |= MPI_L2PREMAP_ENABLED_MASK | MPI_L2PREMAP_IS_CARDBUS_MASK;
|
||||
__raw_writel(val, priv->pci + MPI_L2PMEMREMAP2_REG);
|
||||
#else
|
||||
/* disable second access windows */
|
||||
__raw_writel(0, priv->pci + MPI_L2PMEMREMAP2_REG);
|
||||
#endif
|
||||
|
||||
/* setup local bus to PCI access (IO memory), we have only 1
|
||||
* IO window for both PCI and cardbus, but it cannot handle
|
||||
* both at the same time, assume standard PCI for now, if
|
||||
* cardbus card has IO zone, PCI fixup will change window to
|
||||
* cardbus */
|
||||
val = bcm6348_pci_io_resource.start & MPI_L2P_BASE_MASK;
|
||||
__raw_writel(val, priv->pci + MPI_L2PIOBASE_REG);
|
||||
__raw_writel(~(resource_size(&bcm6348_pci_io_resource) - 1),
|
||||
priv->pci + MPI_L2PIORANGE_REG);
|
||||
__raw_writel(val | MPI_L2PREMAP_ENABLED_MASK,
|
||||
priv->pci + MPI_L2PIOREMAP_REG);
|
||||
|
||||
/* Enable PCI related GPIO pins */
|
||||
__raw_writel(MPI_LOCBUSCTL_EN_PCI_GPIO_MASK,
|
||||
priv->pci + MPI_LOCBUSCTL_REG);
|
||||
|
||||
/* Setup PCI to local bus access, used by PCI device to target
|
||||
* local RAM while bus mastering */
|
||||
bcm6348_int_cfg_writel(0, PCI_BASE_ADDRESS_3);
|
||||
if (priv->remap)
|
||||
val = MPI_SP0_REMAP_ENABLE_MASK;
|
||||
else
|
||||
val = 0;
|
||||
__raw_writel(val, priv->pci + MPI_SP0_REMAP_REG);
|
||||
|
||||
bcm6348_int_cfg_writel(0, PCI_BASE_ADDRESS_4);
|
||||
__raw_writel(0, priv->pci + MPI_SP1_REMAP_REG);
|
||||
|
||||
/* Setup sp0 range to local RAM size */
|
||||
__raw_writel(~(memblock_phys_mem_size() - 1),
|
||||
priv->pci + MPI_SP0_RANGE_REG);
|
||||
__raw_writel(0, priv->pci + MPI_SP1_RANGE_REG);
|
||||
|
||||
/* Change host bridge retry counter to infinite number of
|
||||
* retries, needed for some broadcom wifi cards with Silicon
|
||||
* Backplane bus where access to srom seems very slow */
|
||||
val = bcm6348_int_cfg_readl(BCMPCI_REG_TIMERS);
|
||||
val &= ~REG_TIMER_RETRY_MASK;
|
||||
bcm6348_int_cfg_writel(val, BCMPCI_REG_TIMERS);
|
||||
|
||||
/* EEnable memory decoder and bus mastering */
|
||||
val = bcm6348_int_cfg_readl(PCI_COMMAND);
|
||||
val |= (PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
|
||||
bcm6348_int_cfg_writel(val, PCI_COMMAND);
|
||||
|
||||
/* Enable read prefetching & disable byte swapping for bus
|
||||
* mastering transfers */
|
||||
val = __raw_readl(priv->pci + MPI_PCIMODESEL_REG);
|
||||
val &= ~MPI_PCIMODESEL_BAR1_NOSWAP_MASK;
|
||||
val &= ~MPI_PCIMODESEL_BAR2_NOSWAP_MASK;
|
||||
val &= ~MPI_PCIMODESEL_PREFETCH_MASK;
|
||||
val |= (8 << MPI_PCIMODESEL_PREFETCH_SHIFT);
|
||||
__raw_writel(val, priv->pci + MPI_PCIMODESEL_REG);
|
||||
|
||||
/* Enable pci interrupt */
|
||||
val = __raw_readl(priv->pci + MPI_LOCINT_REG);
|
||||
val |= MPI_LOCINT_MASK(MPI_LOCINT_EXT_PCI_INT);
|
||||
__raw_writel(val, priv->pci + MPI_LOCINT_REG);
|
||||
}
|
||||
|
||||
static int bcm6348_pci_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct device *dev = &pdev->dev;
|
||||
struct device_node *np = dev->of_node;
|
||||
struct bcm6348_pci *priv = &bcm6348_pci;
|
||||
struct resource *res;
|
||||
LIST_HEAD(resources);
|
||||
|
||||
of_pci_check_probe_only();
|
||||
|
||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
priv->pci = devm_ioremap_resource(dev, res);
|
||||
if (IS_ERR(priv->pci))
|
||||
return PTR_ERR(priv->pci);
|
||||
|
||||
priv->pcmcia = priv->pci + PCMCIA_OFFSET;
|
||||
|
||||
priv->irq = platform_get_irq(pdev, 0);
|
||||
if (!priv->irq)
|
||||
return -ENODEV;
|
||||
|
||||
bmips_pci_irq = priv->irq;
|
||||
|
||||
priv->reset = devm_reset_control_get(dev, "pci");
|
||||
if (IS_ERR(priv->reset))
|
||||
return PTR_ERR(priv->reset);
|
||||
|
||||
priv->remap = of_property_read_bool(np, "brcm,remap");
|
||||
|
||||
reset_control_reset(priv->reset);
|
||||
|
||||
pci_load_of_ranges(&bcm6348_pci_controller, np);
|
||||
if (!bcm6348_pci_mem_resource.start)
|
||||
return -EINVAL;
|
||||
|
||||
of_pci_parse_bus_range(np, &bcm6348_pci_busn_resource);
|
||||
pci_add_resource(&resources, &bcm6348_pci_busn_resource);
|
||||
|
||||
#ifdef CONFIG_CARDBUS
|
||||
bcm6348_cb_io_resource.start = bcm6348_pci_io_resource.start + (resource_size(&bcm6348_pci_io_resource) >> 1);
|
||||
bcm6348_cb_io_resource.end = bcm6348_pci_io_resource.end;
|
||||
bcm6348_pci_io_resource.end = bcm6348_pci_io_resource.end - (resource_size(&bcm6348_pci_io_resource) >> 1);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Configuration accesses are done through IO space, remap 4
|
||||
* first bytes to access it from CPU.
|
||||
*
|
||||
* This means that no IO access from CPU should happen while
|
||||
* we do a configuration cycle, but there's no way we can add
|
||||
* a spinlock for each io access, so this is currently kind of
|
||||
* broken on SMP.
|
||||
*/
|
||||
priv->io = ioremap(bcm6348_pci_io_resource.start, sizeof(u32));
|
||||
if (!priv->io)
|
||||
return -ENOMEM;
|
||||
|
||||
bcm6348_pci_setup(priv);
|
||||
|
||||
register_pci_controller(&bcm6348_pci_controller);
|
||||
|
||||
#ifdef CONFIG_CARDBUS
|
||||
priv->cb_bus = -1;
|
||||
register_pci_controller(&bcm6348_cb_controller);
|
||||
#endif /* CONFIG_CARDBUS */
|
||||
|
||||
/* Mark memory space used for IO mapping as reserved */
|
||||
request_mem_region(bcm6348_pci_io_resource.start,
|
||||
resource_size(&bcm6348_pci_io_resource),
|
||||
"BCM6348 PCI IO space");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct of_device_id bcm6348_pci_of_match[] = {
|
||||
{ .compatible = "brcm,bcm6348-pci", },
|
||||
{ /* sentinel */ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, bcm6348_pci_of_match);
|
||||
|
||||
static struct platform_driver bcm6348_pci_driver = {
|
||||
.probe = bcm6348_pci_probe,
|
||||
.driver = {
|
||||
.name = "bcm6348-pci",
|
||||
.of_match_table = bcm6348_pci_of_match,
|
||||
},
|
||||
};
|
||||
module_platform_driver(bcm6348_pci_driver);
|
||||
|
||||
MODULE_AUTHOR("Álvaro Fernández Rojas <noltari@gmail.com>");
|
||||
MODULE_DESCRIPTION("BCM6348 PCI Controller Driver");
|
||||
MODULE_LICENSE("GPL v2");
|
||||
MODULE_ALIAS("platform:bcm6348-pci");
|
||||
403
target/linux/bmips/files/drivers/pci/controller/pcie-bcm6318.c
Normal file
403
target/linux/bmips/files/drivers/pci/controller/pcie-bcm6318.c
Normal file
@@ -0,0 +1,403 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
/*
|
||||
* BCM6318 PCIe Controller Driver
|
||||
*
|
||||
* Copyright (C) 2020 Álvaro Fernández Rojas <noltari@gmail.com>
|
||||
* Copyright (C) 2015 Jonas Gorski <jonas.gorski@gmail.com>
|
||||
* Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
|
||||
*/
|
||||
|
||||
#include <linux/clk.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/of_gpio.h>
|
||||
#include <linux/of_irq.h>
|
||||
#include <linux/of_pci.h>
|
||||
#include <linux/of_platform.h>
|
||||
#include <linux/pci.h>
|
||||
#include <linux/reset.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/version.h>
|
||||
#include <linux/vmalloc.h>
|
||||
|
||||
#include "../pci.h"
|
||||
|
||||
#define PCIE_BUS_BRIDGE 0
|
||||
#define PCIE_BUS_DEVICE 1
|
||||
|
||||
#define PCIE_SPECIFIC_REG 0x188
|
||||
#define SPECIFIC_ENDIAN_MODE_BAR1_SHIFT 0
|
||||
#define SPECIFIC_ENDIAN_MODE_BAR1_MASK (0x3 << SPECIFIC_ENDIAN_MODE_BAR1_SHIFT)
|
||||
#define SPECIFIC_ENDIAN_MODE_BAR2_SHIFT 2
|
||||
#define SPECIFIC_ENDIAN_MODE_BAR2_MASK (0x3 << SPECIFIC_ENDIAN_MODE_BAR1_SHIFT)
|
||||
#define SPECIFIC_ENDIAN_MODE_BAR3_SHIFT 4
|
||||
#define SPECIFIC_ENDIAN_MODE_BAR3_MASK (0x3 << SPECIFIC_ENDIAN_MODE_BAR1_SHIFT)
|
||||
#define SPECIFIC_ENDIAN_MODE_WORD_ALIGN 0
|
||||
#define SPECIFIC_ENDIAN_MODE_HALFWORD_ALIGN 1
|
||||
#define SPECIFIC_ENDIAN_MODE_BYTE_ALIGN 2
|
||||
|
||||
#define PCIE_CONFIG2_REG 0x408
|
||||
#define CONFIG2_BAR1_SIZE_EN 1
|
||||
#define CONFIG2_BAR1_SIZE_MASK 0xf
|
||||
|
||||
#define PCIE_IDVAL3_REG 0x43c
|
||||
#define IDVAL3_CLASS_CODE_MASK 0xffffff
|
||||
#define IDVAL3_SUBCLASS_SHIFT 8
|
||||
#define IDVAL3_CLASS_SHIFT 16
|
||||
|
||||
#define PCIE_DLSTATUS_REG 0x1048
|
||||
#define DLSTATUS_PHYLINKUP (1 << 13)
|
||||
|
||||
#define PCIE_CPU_2_PCIE_MEM_WIN0_LO_REG 0x400c
|
||||
#define C2P_MEM_WIN_ENDIAN_MODE_MASK 0x3
|
||||
#define C2P_MEM_WIN_ENDIAN_NO_SWAP 0
|
||||
#define C2P_MEM_WIN_ENDIAN_HALF_WORD_SWAP 1
|
||||
#define C2P_MEM_WIN_ENDIAN_HALF_BYTE_SWAP 2
|
||||
#define C2P_MEM_WIN_BASE_ADDR_SHIFT 20
|
||||
#define C2P_MEM_WIN_BASE_ADDR_MASK (0xfff << C2P_MEM_WIN_BASE_ADDR_SHIFT)
|
||||
|
||||
#define PCIE_RC_BAR1_CONFIG_LO_REG 0x402c
|
||||
#define RC_BAR_CFG_LO_SIZE_256MB 0xd
|
||||
#define RC_BAR_CFG_LO_MATCH_ADDR_SHIFT 20
|
||||
#define RC_BAR_CFG_LO_MATCH_ADDR_MASK (0xfff << RC_BAR_CFG_LO_MATCH_ADDR_SHIFT)
|
||||
|
||||
#define PCIE_CPU_2_PCIE_MEM_WIN0_BASELIMIT_REG 0x4070
|
||||
#define C2P_BASELIMIT_LIMIT_SHIFT 20
|
||||
#define C2P_BASELIMIT_LIMIT_MASK (0xfff << C2P_BASELIMIT_LIMIT_SHIFT)
|
||||
#define C2P_BASELIMIT_BASE_SHIFT 4
|
||||
#define C2P_BASELIMIT_BASE_MASK (0xfff << C2P_BASELIMIT_BASE_SHIFT)
|
||||
|
||||
#define PCIE_UBUS_BAR1_CFG_REMAP_REG 0x4088
|
||||
#define BAR1_CFG_REMAP_OFFSET_SHIFT 20
|
||||
#define BAR1_CFG_REMAP_OFFSET_MASK (0xfff << BAR1_CFG_REMAP_OFFSET_SHIFT)
|
||||
#define BAR1_CFG_REMAP_ACCESS_EN 1
|
||||
|
||||
#define PCIE_HARD_DEBUG_REG 0x4204
|
||||
#define HARD_DEBUG_SERDES_IDDQ (1 << 23)
|
||||
|
||||
#define PCIE_CPU_INT1_MASK_CLEAR_REG 0x830c
|
||||
#define CPU_INT_PCIE_ERR_ATTN_CPU (1 << 0)
|
||||
#define CPU_INT_PCIE_INTA (1 << 1)
|
||||
#define CPU_INT_PCIE_INTB (1 << 2)
|
||||
#define CPU_INT_PCIE_INTC (1 << 3)
|
||||
#define CPU_INT_PCIE_INTD (1 << 4)
|
||||
#define CPU_INT_PCIE_INTR (1 << 5)
|
||||
#define CPU_INT_PCIE_NMI (1 << 6)
|
||||
#define CPU_INT_PCIE_UBUS (1 << 7)
|
||||
#define CPU_INT_IPI (1 << 8)
|
||||
|
||||
#define PCIE_EXT_CFG_INDEX_REG 0x8400
|
||||
#define EXT_CFG_FUNC_NUM_SHIFT 12
|
||||
#define EXT_CFG_FUNC_NUM_MASK (0x7 << EXT_CFG_FUNC_NUM_SHIFT)
|
||||
#define EXT_CFG_DEV_NUM_SHIFT 15
|
||||
#define EXT_CFG_DEV_NUM_MASK (0xf << EXT_CFG_DEV_NUM_SHIFT)
|
||||
#define EXT_CFG_BUS_NUM_SHIFT 20
|
||||
#define EXT_CFG_BUS_NUM_MASK (0xff << EXT_CFG_BUS_NUM_SHIFT)
|
||||
|
||||
#define PCIE_DEVICE_OFFSET 0x9000
|
||||
|
||||
struct bcm6318_pcie {
|
||||
void __iomem *base;
|
||||
int irq;
|
||||
struct clk *clk;
|
||||
struct clk *clk25;
|
||||
struct clk *clk_ubus;
|
||||
struct reset_control *reset;
|
||||
struct reset_control *reset_ext;
|
||||
struct reset_control *reset_core;
|
||||
struct reset_control *reset_hard;
|
||||
};
|
||||
|
||||
static struct bcm6318_pcie bcm6318_pcie;
|
||||
|
||||
extern int bmips_pci_irq;
|
||||
|
||||
/*
|
||||
* swizzle 32bits data to return only the needed part
|
||||
*/
|
||||
static int postprocess_read(u32 data, int where, unsigned int size)
|
||||
{
|
||||
u32 ret = 0;
|
||||
|
||||
switch (size) {
|
||||
case 1:
|
||||
ret = (data >> ((where & 3) << 3)) & 0xff;
|
||||
break;
|
||||
case 2:
|
||||
ret = (data >> ((where & 3) << 3)) & 0xffff;
|
||||
break;
|
||||
case 4:
|
||||
ret = data;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int preprocess_write(u32 orig_data, u32 val, int where,
|
||||
unsigned int size)
|
||||
{
|
||||
u32 ret = 0;
|
||||
|
||||
switch (size) {
|
||||
case 1:
|
||||
ret = (orig_data & ~(0xff << ((where & 3) << 3))) |
|
||||
(val << ((where & 3) << 3));
|
||||
break;
|
||||
case 2:
|
||||
ret = (orig_data & ~(0xffff << ((where & 3) << 3))) |
|
||||
(val << ((where & 3) << 3));
|
||||
break;
|
||||
case 4:
|
||||
ret = val;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int bcm6318_pcie_can_access(struct pci_bus *bus, int devfn)
|
||||
{
|
||||
struct bcm6318_pcie *priv = &bcm6318_pcie;
|
||||
|
||||
switch (bus->number) {
|
||||
case PCIE_BUS_BRIDGE:
|
||||
return PCI_SLOT(devfn) == 0;
|
||||
case PCIE_BUS_DEVICE:
|
||||
if (PCI_SLOT(devfn) == 0)
|
||||
return __raw_readl(priv->base + PCIE_DLSTATUS_REG)
|
||||
& DLSTATUS_PHYLINKUP;
|
||||
fallthrough;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static int bcm6318_pcie_read(struct pci_bus *bus, unsigned int devfn,
|
||||
int where, int size, u32 *val)
|
||||
{
|
||||
struct bcm6318_pcie *priv = &bcm6318_pcie;
|
||||
u32 data;
|
||||
u32 reg = where & ~3;
|
||||
|
||||
if (!bcm6318_pcie_can_access(bus, devfn))
|
||||
return PCIBIOS_DEVICE_NOT_FOUND;
|
||||
|
||||
if (bus->number == PCIE_BUS_DEVICE)
|
||||
reg += PCIE_DEVICE_OFFSET;
|
||||
|
||||
data = __raw_readl(priv->base + reg);
|
||||
*val = postprocess_read(data, where, size);
|
||||
|
||||
return PCIBIOS_SUCCESSFUL;
|
||||
}
|
||||
|
||||
static int bcm6318_pcie_write(struct pci_bus *bus, unsigned int devfn,
|
||||
int where, int size, u32 val)
|
||||
{
|
||||
struct bcm6318_pcie *priv = &bcm6318_pcie;
|
||||
u32 data;
|
||||
u32 reg = where & ~3;
|
||||
|
||||
if (!bcm6318_pcie_can_access(bus, devfn))
|
||||
return PCIBIOS_DEVICE_NOT_FOUND;
|
||||
|
||||
if (bus->number == PCIE_BUS_DEVICE)
|
||||
reg += PCIE_DEVICE_OFFSET;
|
||||
|
||||
data = __raw_readl(priv->base + reg);
|
||||
data = preprocess_write(data, val, where, size);
|
||||
__raw_writel(data, priv->base + reg);
|
||||
|
||||
return PCIBIOS_SUCCESSFUL;
|
||||
}
|
||||
|
||||
static struct pci_ops bcm6318_pcie_ops = {
|
||||
.read = bcm6318_pcie_read,
|
||||
.write = bcm6318_pcie_write,
|
||||
};
|
||||
|
||||
static struct resource bcm6318_pcie_io_resource;
|
||||
static struct resource bcm6318_pcie_mem_resource;
|
||||
static struct resource bcm6318_pcie_busn_resource;
|
||||
|
||||
static struct pci_controller bcm6318_pcie_controller = {
|
||||
.pci_ops = &bcm6318_pcie_ops,
|
||||
.io_resource = &bcm6318_pcie_io_resource,
|
||||
.mem_resource = &bcm6318_pcie_mem_resource,
|
||||
};
|
||||
|
||||
static void bcm6318_pcie_reset(struct bcm6318_pcie *priv)
|
||||
{
|
||||
u32 val;
|
||||
|
||||
reset_control_deassert(priv->reset_hard);
|
||||
|
||||
reset_control_assert(priv->reset);
|
||||
reset_control_assert(priv->reset_core);
|
||||
reset_control_assert(priv->reset_ext);
|
||||
mdelay(10);
|
||||
|
||||
reset_control_deassert(priv->reset_ext);
|
||||
mdelay(10);
|
||||
|
||||
reset_control_deassert(priv->reset);
|
||||
mdelay(10);
|
||||
|
||||
val = __raw_readl(priv->base + PCIE_HARD_DEBUG_REG);
|
||||
val &= ~HARD_DEBUG_SERDES_IDDQ;
|
||||
__raw_writel(val, priv->base + PCIE_HARD_DEBUG_REG);
|
||||
mdelay(10);
|
||||
|
||||
reset_control_deassert(priv->reset_core);
|
||||
mdelay(200);
|
||||
}
|
||||
|
||||
static void bcm6318_pcie_setup(struct bcm6318_pcie *priv)
|
||||
{
|
||||
u32 val;
|
||||
|
||||
__raw_writel(CPU_INT_PCIE_INTA | CPU_INT_PCIE_INTB |
|
||||
CPU_INT_PCIE_INTC | CPU_INT_PCIE_INTD,
|
||||
priv->base + PCIE_CPU_INT1_MASK_CLEAR_REG);
|
||||
|
||||
val = bcm6318_pcie_mem_resource.end & C2P_BASELIMIT_LIMIT_MASK;
|
||||
val |= (bcm6318_pcie_mem_resource.start >> C2P_BASELIMIT_LIMIT_SHIFT)
|
||||
<< C2P_BASELIMIT_BASE_SHIFT;
|
||||
__raw_writel(val, priv->base + PCIE_CPU_2_PCIE_MEM_WIN0_BASELIMIT_REG);
|
||||
|
||||
/* setup class code as bridge */
|
||||
val = __raw_readl(priv->base + PCIE_IDVAL3_REG);
|
||||
val &= ~IDVAL3_CLASS_CODE_MASK;
|
||||
val |= (PCI_CLASS_BRIDGE_PCI << IDVAL3_SUBCLASS_SHIFT);
|
||||
__raw_writel(val, priv->base + PCIE_IDVAL3_REG);
|
||||
|
||||
/* disable bar1 size */
|
||||
val = __raw_readl(priv->base + PCIE_CONFIG2_REG);
|
||||
val &= ~CONFIG2_BAR1_SIZE_MASK;
|
||||
__raw_writel(val, priv->base + PCIE_CONFIG2_REG);
|
||||
|
||||
/* set bar0 to little endian */
|
||||
val = __raw_readl(priv->base + PCIE_CPU_2_PCIE_MEM_WIN0_LO_REG);
|
||||
val |= bcm6318_pcie_mem_resource.start & C2P_MEM_WIN_BASE_ADDR_MASK;
|
||||
val |= C2P_MEM_WIN_ENDIAN_HALF_BYTE_SWAP;
|
||||
__raw_writel(val, priv->base + PCIE_CPU_2_PCIE_MEM_WIN0_LO_REG);
|
||||
|
||||
__raw_writel(SPECIFIC_ENDIAN_MODE_BYTE_ALIGN,
|
||||
priv->base + PCIE_SPECIFIC_REG);
|
||||
|
||||
__raw_writel(RC_BAR_CFG_LO_SIZE_256MB,
|
||||
priv->base + PCIE_RC_BAR1_CONFIG_LO_REG);
|
||||
|
||||
__raw_writel(BAR1_CFG_REMAP_ACCESS_EN,
|
||||
priv->base + PCIE_UBUS_BAR1_CFG_REMAP_REG);
|
||||
|
||||
__raw_writel(PCIE_BUS_DEVICE << EXT_CFG_BUS_NUM_SHIFT,
|
||||
priv->base + PCIE_EXT_CFG_INDEX_REG);
|
||||
}
|
||||
|
||||
static int bcm6318_pcie_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct device *dev = &pdev->dev;
|
||||
struct device_node *np = dev->of_node;
|
||||
struct bcm6318_pcie *priv = &bcm6318_pcie;
|
||||
struct resource *res;
|
||||
int ret;
|
||||
LIST_HEAD(resources);
|
||||
|
||||
of_pci_check_probe_only();
|
||||
|
||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
priv->base = devm_ioremap_resource(dev, res);
|
||||
if (IS_ERR(priv->base))
|
||||
return PTR_ERR(priv->base);
|
||||
|
||||
priv->irq = platform_get_irq(pdev, 0);
|
||||
if (!priv->irq)
|
||||
return -ENODEV;
|
||||
|
||||
bmips_pci_irq = priv->irq;
|
||||
|
||||
priv->reset = devm_reset_control_get(dev, "pcie");
|
||||
if (IS_ERR(priv->reset))
|
||||
return PTR_ERR(priv->reset);
|
||||
|
||||
priv->reset_ext = devm_reset_control_get(dev, "pcie-ext");
|
||||
if (IS_ERR(priv->reset_ext))
|
||||
return PTR_ERR(priv->reset_ext);
|
||||
|
||||
priv->reset_core = devm_reset_control_get(dev, "pcie-core");
|
||||
if (IS_ERR(priv->reset_core))
|
||||
return PTR_ERR(priv->reset_core);
|
||||
|
||||
priv->reset_hard = devm_reset_control_get(dev, "pcie-hard");
|
||||
if (IS_ERR(priv->reset_hard))
|
||||
return PTR_ERR(priv->reset_hard);
|
||||
|
||||
priv->clk = devm_clk_get(dev, "pcie");
|
||||
if (IS_ERR(priv->clk))
|
||||
return PTR_ERR(priv->clk);
|
||||
|
||||
priv->clk25 = devm_clk_get(dev, "pcie25");
|
||||
if (IS_ERR(priv->clk25))
|
||||
return PTR_ERR(priv->clk25);
|
||||
|
||||
priv->clk_ubus = devm_clk_get(dev, "pcie-ubus");
|
||||
if (IS_ERR(priv->clk_ubus))
|
||||
return PTR_ERR(priv->clk_ubus);
|
||||
|
||||
ret = clk_prepare_enable(priv->clk);
|
||||
if (ret) {
|
||||
dev_err(dev, "could not enable clock\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = clk_prepare_enable(priv->clk25);
|
||||
if (ret) {
|
||||
dev_err(dev, "could not enable clock\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = clk_prepare_enable(priv->clk_ubus);
|
||||
if (ret) {
|
||||
dev_err(dev, "could not enable clock\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
pci_load_of_ranges(&bcm6318_pcie_controller, np);
|
||||
if (!bcm6318_pcie_mem_resource.start)
|
||||
return -EINVAL;
|
||||
|
||||
of_pci_parse_bus_range(np, &bcm6318_pcie_busn_resource);
|
||||
pci_add_resource(&resources, &bcm6318_pcie_busn_resource);
|
||||
|
||||
bcm6318_pcie_reset(priv);
|
||||
bcm6318_pcie_setup(priv);
|
||||
|
||||
register_pci_controller(&bcm6318_pcie_controller);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct of_device_id bcm6318_pcie_of_match[] = {
|
||||
{ .compatible = "brcm,bcm6318-pcie", },
|
||||
{ /* sentinel */ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, bcm6318_pcie_of_match);
|
||||
|
||||
static struct platform_driver bcm6318_pcie_driver = {
|
||||
.probe = bcm6318_pcie_probe,
|
||||
.driver = {
|
||||
.name = "bcm6318-pcie",
|
||||
.of_match_table = bcm6318_pcie_of_match,
|
||||
},
|
||||
};
|
||||
module_platform_driver(bcm6318_pcie_driver);
|
||||
|
||||
MODULE_AUTHOR("Álvaro Fernández Rojas <noltari@gmail.com>");
|
||||
MODULE_DESCRIPTION("BCM6318 PCIe Controller Driver");
|
||||
MODULE_LICENSE("GPL v2");
|
||||
MODULE_ALIAS("platform:bcm6318-pcie");
|
||||
413
target/linux/bmips/files/drivers/pci/controller/pcie-bcm6328.c
Normal file
413
target/linux/bmips/files/drivers/pci/controller/pcie-bcm6328.c
Normal file
@@ -0,0 +1,413 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
/*
|
||||
* BCM6328 PCIe Controller Driver
|
||||
*
|
||||
* Copyright (C) 2020 Álvaro Fernández Rojas <noltari@gmail.com>
|
||||
* Copyright (C) 2015 Jonas Gorski <jonas.gorski@gmail.com>
|
||||
* Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
|
||||
*/
|
||||
|
||||
#include <linux/clk.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/mfd/syscon.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/of_gpio.h>
|
||||
#include <linux/of_irq.h>
|
||||
#include <linux/of_pci.h>
|
||||
#include <linux/of_platform.h>
|
||||
#include <linux/pci.h>
|
||||
#include <linux/pm_domain.h>
|
||||
#include <linux/pm_runtime.h>
|
||||
#include <linux/reset.h>
|
||||
#include <linux/regmap.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/version.h>
|
||||
#include <linux/vmalloc.h>
|
||||
|
||||
#include "../pci.h"
|
||||
|
||||
#define SERDES_PCIE_EXD_EN BIT(15)
|
||||
#define SERDES_PCIE_EN BIT(0)
|
||||
|
||||
#define PCIE_BUS_BRIDGE 0
|
||||
#define PCIE_BUS_DEVICE 1
|
||||
|
||||
#define PCIE_CONFIG2_REG 0x408
|
||||
#define CONFIG2_BAR1_SIZE_EN 1
|
||||
#define CONFIG2_BAR1_SIZE_MASK 0xf
|
||||
|
||||
#define PCIE_IDVAL3_REG 0x43c
|
||||
#define IDVAL3_CLASS_CODE_MASK 0xffffff
|
||||
#define IDVAL3_SUBCLASS_SHIFT 8
|
||||
#define IDVAL3_CLASS_SHIFT 16
|
||||
|
||||
#define PCIE_DLSTATUS_REG 0x1048
|
||||
#define DLSTATUS_PHYLINKUP (1 << 13)
|
||||
|
||||
#define PCIE_BRIDGE_OPT1_REG 0x2820
|
||||
#define OPT1_RD_BE_OPT_EN (1 << 7)
|
||||
#define OPT1_RD_REPLY_BE_FIX_EN (1 << 9)
|
||||
#define OPT1_PCIE_BRIDGE_HOLE_DET_EN (1 << 11)
|
||||
#define OPT1_L1_INT_STATUS_MASK_POL (1 << 12)
|
||||
|
||||
#define PCIE_BRIDGE_OPT2_REG 0x2824
|
||||
#define OPT2_UBUS_UR_DECODE_DIS (1 << 2)
|
||||
#define OPT2_TX_CREDIT_CHK_EN (1 << 4)
|
||||
#define OPT2_CFG_TYPE1_BD_SEL (1 << 7)
|
||||
#define OPT2_CFG_TYPE1_BUS_NO_SHIFT 16
|
||||
#define OPT2_CFG_TYPE1_BUS_NO_MASK (0xff << OPT2_CFG_TYPE1_BUS_NO_SHIFT)
|
||||
|
||||
#define PCIE_BRIDGE_BAR0_BASEMASK_REG 0x2828
|
||||
#define BASEMASK_REMAP_EN (1 << 0)
|
||||
#define BASEMASK_SWAP_EN (1 << 1)
|
||||
#define BASEMASK_MASK_SHIFT 4
|
||||
#define BASEMASK_MASK_MASK (0xfff << BASEMASK_MASK_SHIFT)
|
||||
#define BASEMASK_BASE_SHIFT 20
|
||||
#define BASEMASK_BASE_MASK (0xfff << BASEMASK_BASE_SHIFT)
|
||||
|
||||
#define PCIE_BRIDGE_BAR0_REBASE_ADDR_REG 0x282c
|
||||
#define REBASE_ADDR_BASE_SHIFT 20
|
||||
#define REBASE_ADDR_BASE_MASK (0xfff << REBASE_ADDR_BASE_SHIFT)
|
||||
|
||||
#define PCIE_BRIDGE_RC_INT_MASK_REG 0x2854
|
||||
#define PCIE_RC_INT_A (1 << 0)
|
||||
#define PCIE_RC_INT_B (1 << 1)
|
||||
#define PCIE_RC_INT_C (1 << 2)
|
||||
#define PCIE_RC_INT_D (1 << 3)
|
||||
|
||||
#define PCIE_DEVICE_OFFSET 0x8000
|
||||
|
||||
struct bcm6328_pcie {
|
||||
void __iomem *base;
|
||||
int irq;
|
||||
struct regmap *serdes;
|
||||
struct device **pm;
|
||||
struct device_link **link_pm;
|
||||
unsigned int num_pms;
|
||||
struct clk *clk;
|
||||
struct reset_control *reset;
|
||||
struct reset_control *reset_ext;
|
||||
struct reset_control *reset_core;
|
||||
struct reset_control *reset_hard;
|
||||
};
|
||||
|
||||
static struct bcm6328_pcie bcm6328_pcie;
|
||||
|
||||
extern int bmips_pci_irq;
|
||||
|
||||
/*
|
||||
* swizzle 32bits data to return only the needed part
|
||||
*/
|
||||
static int postprocess_read(u32 data, int where, unsigned int size)
|
||||
{
|
||||
u32 ret = 0;
|
||||
|
||||
switch (size) {
|
||||
case 1:
|
||||
ret = (data >> ((where & 3) << 3)) & 0xff;
|
||||
break;
|
||||
case 2:
|
||||
ret = (data >> ((where & 3) << 3)) & 0xffff;
|
||||
break;
|
||||
case 4:
|
||||
ret = data;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int preprocess_write(u32 orig_data, u32 val, int where,
|
||||
unsigned int size)
|
||||
{
|
||||
u32 ret = 0;
|
||||
|
||||
switch (size) {
|
||||
case 1:
|
||||
ret = (orig_data & ~(0xff << ((where & 3) << 3))) |
|
||||
(val << ((where & 3) << 3));
|
||||
break;
|
||||
case 2:
|
||||
ret = (orig_data & ~(0xffff << ((where & 3) << 3))) |
|
||||
(val << ((where & 3) << 3));
|
||||
break;
|
||||
case 4:
|
||||
ret = val;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int bcm6328_pcie_can_access(struct pci_bus *bus, int devfn)
|
||||
{
|
||||
struct bcm6328_pcie *priv = &bcm6328_pcie;
|
||||
|
||||
switch (bus->number) {
|
||||
case PCIE_BUS_BRIDGE:
|
||||
return PCI_SLOT(devfn) == 0;
|
||||
case PCIE_BUS_DEVICE:
|
||||
if (PCI_SLOT(devfn) == 0)
|
||||
return __raw_readl(priv->base + PCIE_DLSTATUS_REG)
|
||||
& DLSTATUS_PHYLINKUP;
|
||||
fallthrough;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static int bcm6328_pcie_read(struct pci_bus *bus, unsigned int devfn,
|
||||
int where, int size, u32 *val)
|
||||
{
|
||||
struct bcm6328_pcie *priv = &bcm6328_pcie;
|
||||
u32 data;
|
||||
u32 reg = where & ~3;
|
||||
|
||||
if (!bcm6328_pcie_can_access(bus, devfn))
|
||||
return PCIBIOS_DEVICE_NOT_FOUND;
|
||||
|
||||
if (bus->number == PCIE_BUS_DEVICE)
|
||||
reg += PCIE_DEVICE_OFFSET;
|
||||
|
||||
data = __raw_readl(priv->base + reg);
|
||||
*val = postprocess_read(data, where, size);
|
||||
|
||||
return PCIBIOS_SUCCESSFUL;
|
||||
}
|
||||
|
||||
static int bcm6328_pcie_write(struct pci_bus *bus, unsigned int devfn,
|
||||
int where, int size, u32 val)
|
||||
{
|
||||
struct bcm6328_pcie *priv = &bcm6328_pcie;
|
||||
u32 data;
|
||||
u32 reg = where & ~3;
|
||||
|
||||
if (!bcm6328_pcie_can_access(bus, devfn))
|
||||
return PCIBIOS_DEVICE_NOT_FOUND;
|
||||
|
||||
if (bus->number == PCIE_BUS_DEVICE)
|
||||
reg += PCIE_DEVICE_OFFSET;
|
||||
|
||||
data = __raw_readl(priv->base + reg);
|
||||
data = preprocess_write(data, val, where, size);
|
||||
__raw_writel(data, priv->base + reg);
|
||||
|
||||
return PCIBIOS_SUCCESSFUL;
|
||||
}
|
||||
|
||||
static struct pci_ops bcm6328_pcie_ops = {
|
||||
.read = bcm6328_pcie_read,
|
||||
.write = bcm6328_pcie_write,
|
||||
};
|
||||
|
||||
static struct resource bcm6328_pcie_io_resource;
|
||||
static struct resource bcm6328_pcie_mem_resource;
|
||||
static struct resource bcm6328_pcie_busn_resource;
|
||||
|
||||
static struct pci_controller bcm6328_pcie_controller = {
|
||||
.pci_ops = &bcm6328_pcie_ops,
|
||||
.io_resource = &bcm6328_pcie_io_resource,
|
||||
.mem_resource = &bcm6328_pcie_mem_resource,
|
||||
};
|
||||
|
||||
static void bcm6328_pcie_reset(struct bcm6328_pcie *priv)
|
||||
{
|
||||
regmap_write_bits(priv->serdes, 0,
|
||||
SERDES_PCIE_EXD_EN | SERDES_PCIE_EN,
|
||||
SERDES_PCIE_EXD_EN | SERDES_PCIE_EN);
|
||||
|
||||
reset_control_assert(priv->reset);
|
||||
reset_control_assert(priv->reset_core);
|
||||
reset_control_assert(priv->reset_ext);
|
||||
if (priv->reset_hard) {
|
||||
reset_control_assert(priv->reset_hard);
|
||||
mdelay(10);
|
||||
reset_control_deassert(priv->reset_hard);
|
||||
}
|
||||
mdelay(10);
|
||||
|
||||
reset_control_deassert(priv->reset_core);
|
||||
reset_control_deassert(priv->reset);
|
||||
mdelay(10);
|
||||
|
||||
reset_control_deassert(priv->reset_ext);
|
||||
mdelay(200);
|
||||
}
|
||||
|
||||
static void bcm6328_pcie_setup(struct bcm6328_pcie *priv)
|
||||
{
|
||||
u32 val;
|
||||
|
||||
val = __raw_readl(priv->base + PCIE_BRIDGE_OPT1_REG);
|
||||
val |= OPT1_RD_BE_OPT_EN;
|
||||
val |= OPT1_RD_REPLY_BE_FIX_EN;
|
||||
val |= OPT1_PCIE_BRIDGE_HOLE_DET_EN;
|
||||
val |= OPT1_L1_INT_STATUS_MASK_POL;
|
||||
__raw_writel(val, priv->base + PCIE_BRIDGE_OPT1_REG);
|
||||
|
||||
val = __raw_readl(priv->base + PCIE_BRIDGE_RC_INT_MASK_REG);
|
||||
val |= PCIE_RC_INT_A;
|
||||
val |= PCIE_RC_INT_B;
|
||||
val |= PCIE_RC_INT_C;
|
||||
val |= PCIE_RC_INT_D;
|
||||
__raw_writel(val, priv->base + PCIE_BRIDGE_RC_INT_MASK_REG);
|
||||
|
||||
val = __raw_readl(priv->base + PCIE_BRIDGE_OPT2_REG);
|
||||
/* enable credit checking and error checking */
|
||||
val |= OPT2_TX_CREDIT_CHK_EN;
|
||||
val |= OPT2_UBUS_UR_DECODE_DIS;
|
||||
/* set device bus/func for the pcie device */
|
||||
val |= (PCIE_BUS_DEVICE << OPT2_CFG_TYPE1_BUS_NO_SHIFT);
|
||||
val |= OPT2_CFG_TYPE1_BD_SEL;
|
||||
__raw_writel(val, priv->base + PCIE_BRIDGE_OPT2_REG);
|
||||
|
||||
/* setup class code as bridge */
|
||||
val = __raw_readl(priv->base + PCIE_IDVAL3_REG);
|
||||
val &= ~IDVAL3_CLASS_CODE_MASK;
|
||||
val |= (PCI_CLASS_BRIDGE_PCI << IDVAL3_SUBCLASS_SHIFT);
|
||||
__raw_writel(val, priv->base + PCIE_IDVAL3_REG);
|
||||
|
||||
/* disable bar1 size */
|
||||
val = __raw_readl(priv->base + PCIE_CONFIG2_REG);
|
||||
val &= ~CONFIG2_BAR1_SIZE_MASK;
|
||||
__raw_writel(val, priv->base + PCIE_CONFIG2_REG);
|
||||
|
||||
/* set bar0 to little endian */
|
||||
val = (bcm6328_pcie_mem_resource.start >> 20)
|
||||
<< BASEMASK_BASE_SHIFT;
|
||||
val |= (bcm6328_pcie_mem_resource.end >> 20) << BASEMASK_MASK_SHIFT;
|
||||
val |= BASEMASK_REMAP_EN;
|
||||
__raw_writel(val, priv->base + PCIE_BRIDGE_BAR0_BASEMASK_REG);
|
||||
|
||||
val = (bcm6328_pcie_mem_resource.start >> 20)
|
||||
<< REBASE_ADDR_BASE_SHIFT;
|
||||
__raw_writel(val, priv->base + PCIE_BRIDGE_BAR0_REBASE_ADDR_REG);
|
||||
}
|
||||
|
||||
static int bcm6328_pcie_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct device *dev = &pdev->dev;
|
||||
struct device_node *np = dev->of_node;
|
||||
struct bcm6328_pcie *priv = &bcm6328_pcie;
|
||||
struct resource *res;
|
||||
unsigned int i;
|
||||
int ret;
|
||||
LIST_HEAD(resources);
|
||||
|
||||
pm_runtime_enable(dev);
|
||||
pm_runtime_no_callbacks(dev);
|
||||
|
||||
priv->num_pms = of_count_phandle_with_args(np, "power-domains",
|
||||
"#power-domain-cells");
|
||||
if (priv->num_pms > 1) {
|
||||
priv->pm = devm_kcalloc(dev, priv->num_pms,
|
||||
sizeof(struct device *), GFP_KERNEL);
|
||||
if (!priv->pm)
|
||||
return -ENOMEM;
|
||||
|
||||
priv->link_pm = devm_kcalloc(dev, priv->num_pms,
|
||||
sizeof(struct device_link *),
|
||||
GFP_KERNEL);
|
||||
if (!priv->link_pm)
|
||||
return -ENOMEM;
|
||||
|
||||
for (i = 0; i < priv->num_pms; i++) {
|
||||
priv->pm[i] = genpd_dev_pm_attach_by_id(dev, i);
|
||||
if (IS_ERR(priv->pm[i])) {
|
||||
dev_err(dev, "error getting pm %d\n", i);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
priv->link_pm[i] = device_link_add(dev, priv->pm[i],
|
||||
DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME |
|
||||
DL_FLAG_RPM_ACTIVE);
|
||||
}
|
||||
}
|
||||
|
||||
ret = pm_runtime_get_sync(dev);
|
||||
if (ret < 0) {
|
||||
pm_runtime_disable(dev);
|
||||
dev_info(dev, "PM prober defer: ret=%d\n", ret);
|
||||
return -EPROBE_DEFER;
|
||||
}
|
||||
|
||||
of_pci_check_probe_only();
|
||||
|
||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
priv->base = devm_ioremap_resource(dev, res);
|
||||
if (IS_ERR(priv->base))
|
||||
return PTR_ERR(priv->base);
|
||||
|
||||
priv->irq = platform_get_irq(pdev, 0);
|
||||
if (!priv->irq)
|
||||
return -ENODEV;
|
||||
|
||||
bmips_pci_irq = priv->irq;
|
||||
|
||||
priv->serdes = syscon_regmap_lookup_by_phandle(np, "brcm,serdes");
|
||||
if (IS_ERR(priv->serdes))
|
||||
return PTR_ERR(priv->serdes);
|
||||
|
||||
priv->reset = devm_reset_control_get(dev, "pcie");
|
||||
if (IS_ERR(priv->reset))
|
||||
return PTR_ERR(priv->reset);
|
||||
|
||||
priv->reset_ext = devm_reset_control_get(dev, "pcie-ext");
|
||||
if (IS_ERR(priv->reset_ext))
|
||||
return PTR_ERR(priv->reset_ext);
|
||||
|
||||
priv->reset_core = devm_reset_control_get(dev, "pcie-core");
|
||||
if (IS_ERR(priv->reset_core))
|
||||
return PTR_ERR(priv->reset_core);
|
||||
|
||||
priv->reset_hard = devm_reset_control_get_optional(dev, "pcie-hard");
|
||||
if (IS_ERR(priv->reset_hard))
|
||||
return PTR_ERR(priv->reset_hard);
|
||||
|
||||
priv->clk = devm_clk_get(dev, "pcie");
|
||||
if (IS_ERR(priv->clk))
|
||||
return PTR_ERR(priv->clk);
|
||||
|
||||
ret = clk_prepare_enable(priv->clk);
|
||||
if (ret) {
|
||||
dev_err(dev, "could not enable clock\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
pci_load_of_ranges(&bcm6328_pcie_controller, np);
|
||||
if (!bcm6328_pcie_mem_resource.start)
|
||||
return -EINVAL;
|
||||
|
||||
of_pci_parse_bus_range(np, &bcm6328_pcie_busn_resource);
|
||||
pci_add_resource(&resources, &bcm6328_pcie_busn_resource);
|
||||
|
||||
bcm6328_pcie_reset(priv);
|
||||
bcm6328_pcie_setup(priv);
|
||||
|
||||
register_pci_controller(&bcm6328_pcie_controller);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct of_device_id bcm6328_pcie_of_match[] = {
|
||||
{ .compatible = "brcm,bcm6328-pcie", },
|
||||
{ /* sentinel */ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, bcm6328_pcie_of_match);
|
||||
|
||||
static struct platform_driver bcm6328_pcie_driver = {
|
||||
.probe = bcm6328_pcie_probe,
|
||||
.driver = {
|
||||
.name = "bcm6328-pcie",
|
||||
.of_match_table = bcm6328_pcie_of_match,
|
||||
},
|
||||
};
|
||||
module_platform_driver(bcm6328_pcie_driver);
|
||||
|
||||
MODULE_AUTHOR("Álvaro Fernández Rojas <noltari@gmail.com>");
|
||||
MODULE_DESCRIPTION("BCM6328 PCIe Controller Driver");
|
||||
MODULE_LICENSE("GPL v2");
|
||||
MODULE_ALIAS("platform:bcm6328-pcie");
|
||||
Reference in New Issue
Block a user