summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2020-07-29 14:24:17 -0400
committerTom Rini <trini@konsulko.com>2020-07-29 14:24:17 -0400
commit8da75b1ddf966bd8457a2b5bf59dec0bfc9a1cd6 (patch)
tree41d2ef5d35c09e393409d18fa329848774580592 /drivers
parent423e08cb77015beab6a81595765ec1faa34bedde (diff)
parent2ae7adc659f7fca9ea65df4318e5bca2b8274310 (diff)
Merge branch '2020-07-29-add-brcm-ns3-support'
- Add initial Broadcom NS3 SoC support.
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gpio/Kconfig11
-rw-r--r--drivers/gpio/Makefile1
-rw-r--r--drivers/gpio/iproc_gpio.c290
-rw-r--r--drivers/tee/Kconfig1
-rw-r--r--drivers/tee/Makefile1
-rw-r--r--drivers/tee/broadcom/Kconfig7
-rw-r--r--drivers/tee/broadcom/Makefile3
-rw-r--r--drivers/tee/broadcom/chimp_optee.c183
8 files changed, 497 insertions, 0 deletions
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index c1928442be..ff5cd7efce 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -154,6 +154,17 @@ config IMX_RGPIO2P
help
This driver supports i.MX7ULP Rapid GPIO2P controller.
+config IPROC_GPIO
+ bool "Broadcom iProc GPIO driver(without pinconf)"
+ default n
+ help
+ The Broadcom iProc based SoCs- Cygnus, NS2, NS3, NSP and Stingray,
+ use the same GPIO Controller IP hence this driver could be used
+ for all.
+
+ The Broadcom iProc based SoCs have multiple GPIO controllers and only
+ the always-ON GPIO controller (CRMU/AON) is supported by this driver.
+
config HSDK_CREG_GPIO
bool "HSDK CREG GPIO griver"
depends on DM_GPIO
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 334c5f27fe..e769509c69 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_CORTINA_GPIO) += cortina_gpio.o
obj-$(CONFIG_INTEL_GPIO) += intel_gpio.o
obj-$(CONFIG_INTEL_ICH6_GPIO) += intel_ich6_gpio.o
obj-$(CONFIG_INTEL_BROADWELL_GPIO) += intel_broadwell_gpio.o
+obj-$(CONFIG_IPROC_GPIO) += iproc_gpio.o
obj-$(CONFIG_KIRKWOOD_GPIO) += kw_gpio.o
obj-$(CONFIG_KONA_GPIO) += kona_gpio.o
obj-$(CONFIG_MARVELL_GPIO) += mvgpio.o
diff --git a/drivers/gpio/iproc_gpio.c b/drivers/gpio/iproc_gpio.c
new file mode 100644
index 0000000000..cc26a1306b
--- /dev/null
+++ b/drivers/gpio/iproc_gpio.c
@@ -0,0 +1,290 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020 Broadcom
+ */
+
+#include <common.h>
+#include <errno.h>
+#include <asm/gpio.h>
+#include <asm/io.h>
+#include <dm.h>
+#include <dm/device_compat.h>
+#include <dm/devres.h>
+#include <dm/pinctrl.h>
+
+/*
+ * There are five GPIO bank register. Each bank can configure max of 32 gpios.
+ * BANK0 - gpios 0 to 31
+ * BANK1 - gpios 32 to 63
+ * BANK2 - gpios 64 to 95
+ * BANK3 - gpios 96 to 127
+ * BANK4 - gpios 128 to 150
+ *
+ * Offset difference between consecutive bank register is 0x200
+ */
+#define NGPIO_PER_BANK 32
+#define GPIO_BANK_SIZE 0x200
+#define GPIO_BANK(pin) ((pin) / NGPIO_PER_BANK)
+#define GPIO_SHIFT(pin) ((pin) % NGPIO_PER_BANK)
+#define GPIO_REG(pin, reg) (GPIO_BANK_SIZE * GPIO_BANK(pin) + (reg))
+
+/* device register offset */
+#define DATA_IN_OFFSET 0x00
+#define DATA_OUT_OFFSET 0x04
+#define OUT_EN_OFFSET 0x08
+
+/**
+ * struct iproc_gpio_pctrl_map - gpio and pinctrl mapping
+ * @gpio_pin: start of gpio number in gpio-ranges
+ * @pctrl_pin: start of pinctrl number in gpio-ranges
+ * @npins: total number of pins in gpio-ranges
+ * @node: list node
+ */
+struct iproc_gpio_pctrl_map {
+ u32 gpio_pin;
+ u32 pctrl_pin;
+ u32 npins;
+ struct list_head node;
+};
+
+/**
+ * struct iproc_gpio_pctrl_map - gpio device instance
+ * @pinctrl_dev:pointer to pinctrl device
+ * @gpiomap: list node having mapping between gpio and pinctrl
+ * @base: I/O register base address of gpio device
+ * @name: gpio device name, ex GPIO0, GPIO1
+ * @ngpios: total number of gpios
+ */
+struct iproc_gpio_platdata {
+ struct udevice *pinctrl_dev;
+ struct list_head gpiomap;
+ void __iomem *base;
+ char *name;
+ u32 ngpios;
+};
+
+/**
+ * iproc_gpio_set_bit - set or clear one bit in an iproc GPIO register.
+ *
+ * The bit relates to a GPIO pin.
+ *
+ * @plat: iproc GPIO device
+ * @reg: register offset
+ * @gpio: GPIO pin
+ * @set: set or clear
+ */
+static inline void iproc_gpio_set_bit(struct iproc_gpio_platdata *plat,
+ u32 reg, u32 gpio, bool set)
+{
+ u32 offset = GPIO_REG(gpio, reg);
+ u32 shift = GPIO_SHIFT(gpio);
+
+ clrsetbits_le32(plat->base + offset, BIT(shift),
+ (set ? BIT(shift) : 0));
+}
+
+static inline bool iproc_gpio_get_bit(struct iproc_gpio_platdata *plat,
+ u32 reg, u32 gpio)
+{
+ u32 offset = GPIO_REG(gpio, reg);
+ u32 shift = GPIO_SHIFT(gpio);
+
+ return readl(plat->base + offset) & BIT(shift);
+}
+
+/**
+ * iproc_get_gpio_pctrl_mapping() - get associated pinctrl pin from gpio pin
+ *
+ * @plat: iproc GPIO device
+ * @gpio: GPIO pin
+ */
+static u32 iproc_get_pctrl_from_gpio(struct iproc_gpio_platdata *plat, u32 gpio)
+{
+ struct iproc_gpio_pctrl_map *range = NULL;
+ struct list_head *pos, *tmp;
+ u32 ret = 0;
+
+ list_for_each_safe(pos, tmp, &plat->gpiomap) {
+ range = list_entry(pos, struct iproc_gpio_pctrl_map, node);
+ if (gpio == range->gpio_pin ||
+ gpio < (range->gpio_pin + range->npins)) {
+ ret = range->pctrl_pin + (gpio - range->gpio_pin);
+ break;
+ }
+ }
+
+ return ret;
+}
+
+/**
+ * iproc_get_gpio_pctrl_mapping() - get mapping between gpio and pinctrl
+ *
+ * Read dt node "gpio-ranges" to get gpio and pinctrl mapping and store
+ * in private data structure to use it later while enabling gpio.
+ *
+ * @dev: pointer to GPIO device
+ * @return 0 on success and -ENOMEM on failure
+ */
+static int iproc_get_gpio_pctrl_mapping(struct udevice *dev)
+{
+ struct iproc_gpio_platdata *plat = dev_get_platdata(dev);
+ struct iproc_gpio_pctrl_map *range = NULL;
+ struct ofnode_phandle_args args;
+ int index = 0, ret;
+
+ for (;; index++) {
+ ret = dev_read_phandle_with_args(dev, "gpio-ranges",
+ NULL, 3, index, &args);
+ if (ret)
+ break;
+
+ range = devm_kzalloc(dev, sizeof(*range), GFP_KERNEL);
+ if (!range)
+ return -ENOMEM;
+
+ range->gpio_pin = args.args[0];
+ range->pctrl_pin = args.args[1];
+ range->npins = args.args[2];
+ list_add_tail(&range->node, &plat->gpiomap);
+ }
+
+ return 0;
+}
+
+static int iproc_gpio_request(struct udevice *dev, u32 gpio, const char *label)
+{
+ struct iproc_gpio_platdata *plat = dev_get_platdata(dev);
+ u32 pctrl;
+
+ /* nothing to do if there is no corresponding pinctrl device */
+ if (!plat->pinctrl_dev)
+ return 0;
+
+ pctrl = iproc_get_pctrl_from_gpio(plat, gpio);
+
+ return pinctrl_request(plat->pinctrl_dev, pctrl, 0);
+}
+
+static int iproc_gpio_direction_input(struct udevice *dev, u32 gpio)
+{
+ struct iproc_gpio_platdata *plat = dev_get_platdata(dev);
+
+ iproc_gpio_set_bit(plat, OUT_EN_OFFSET, gpio, false);
+ dev_dbg(dev, "gpio:%u set input\n", gpio);
+
+ return 0;
+}
+
+static int iproc_gpio_direction_output(struct udevice *dev, u32 gpio, int value)
+{
+ struct iproc_gpio_platdata *plat = dev_get_platdata(dev);
+
+ iproc_gpio_set_bit(plat, OUT_EN_OFFSET, gpio, true);
+ iproc_gpio_set_bit(plat, DATA_OUT_OFFSET, gpio, value);
+ dev_dbg(dev, "gpio:%u set output, value:%d\n", gpio, value);
+
+ return 0;
+}
+
+static int iproc_gpio_get_value(struct udevice *dev, u32 gpio)
+{
+ struct iproc_gpio_platdata *plat = dev_get_platdata(dev);
+ int value;
+
+ value = iproc_gpio_get_bit(plat, DATA_IN_OFFSET, gpio);
+ dev_dbg(dev, "gpio:%u get, value:%d\n", gpio, value);
+
+ return value;
+}
+
+static int iproc_gpio_set_value(struct udevice *dev, u32 gpio, int value)
+{
+ struct iproc_gpio_platdata *plat = dev_get_platdata(dev);
+
+ if (iproc_gpio_get_bit(plat, OUT_EN_OFFSET, gpio))
+ iproc_gpio_set_bit(plat, DATA_OUT_OFFSET, gpio, value);
+
+ dev_dbg(dev, "gpio:%u set, value:%d\n", gpio, value);
+ return 0;
+}
+
+static int iproc_gpio_get_function(struct udevice *dev, u32 gpio)
+{
+ struct iproc_gpio_platdata *plat = dev_get_platdata(dev);
+
+ if (iproc_gpio_get_bit(plat, OUT_EN_OFFSET, gpio))
+ return GPIOF_OUTPUT;
+ else
+ return GPIOF_INPUT;
+}
+
+static int iproc_gpio_ofdata_to_platdata(struct udevice *dev)
+{
+ struct iproc_gpio_platdata *plat = dev_get_platdata(dev);
+ struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+ int ret;
+ char name[10];
+
+ plat->base = dev_read_addr_ptr(dev);
+ if (!plat->base) {
+ debug("%s: Failed to get base address\n", __func__);
+ return -EINVAL;
+ }
+
+ ret = dev_read_u32(dev, "ngpios", &plat->ngpios);
+ if (ret < 0) {
+ dev_err(dev, "%s: Failed to get ngpios\n", __func__);
+ return ret;
+ }
+
+ uclass_get_device_by_phandle(UCLASS_PINCTRL, dev, "gpio-ranges",
+ &plat->pinctrl_dev);
+ if (ret < 0) {
+ dev_err(dev, "%s: Failed to get pinctrl phandle\n", __func__);
+ return ret;
+ }
+
+ INIT_LIST_HEAD(&plat->gpiomap);
+ ret = iproc_get_gpio_pctrl_mapping(dev);
+ if (ret < 0) {
+ dev_err(dev, "%s: Failed to get gpio to pctrl map ret(%d)\n",
+ __func__, ret);
+ return ret;
+ }
+
+ snprintf(name, sizeof(name), "GPIO%d", dev->req_seq);
+ plat->name = strdup(name);
+ if (!plat->name)
+ return -ENOMEM;
+
+ uc_priv->gpio_count = plat->ngpios;
+ uc_priv->bank_name = plat->name;
+
+ dev_info(dev, ":bank name(%s) base %p, #gpios %d\n",
+ plat->name, plat->base, plat->ngpios);
+
+ return 0;
+}
+
+static const struct dm_gpio_ops iproc_gpio_ops = {
+ .request = iproc_gpio_request,
+ .direction_input = iproc_gpio_direction_input,
+ .direction_output = iproc_gpio_direction_output,
+ .get_value = iproc_gpio_get_value,
+ .set_value = iproc_gpio_set_value,
+ .get_function = iproc_gpio_get_function,
+};
+
+static const struct udevice_id iproc_gpio_ids[] = {
+ { .compatible = "brcm,iproc-gpio" },
+ { }
+};
+
+U_BOOT_DRIVER(iproc_gpio) = {
+ .name = "iproc_gpio",
+ .id = UCLASS_GPIO,
+ .of_match = iproc_gpio_ids,
+ .ops = &iproc_gpio_ops,
+ .ofdata_to_platdata = iproc_gpio_ofdata_to_platdata,
+ .platdata_auto_alloc_size = sizeof(struct iproc_gpio_platdata),
+};
diff --git a/drivers/tee/Kconfig b/drivers/tee/Kconfig
index 5c0c89043f..5ca5a0836c 100644
--- a/drivers/tee/Kconfig
+++ b/drivers/tee/Kconfig
@@ -29,6 +29,7 @@ config SANDBOX_TEE
"avb" commands.
source "drivers/tee/optee/Kconfig"
+source "drivers/tee/broadcom/Kconfig"
endmenu
diff --git a/drivers/tee/Makefile b/drivers/tee/Makefile
index f72c68c09f..5c8ffdbce8 100644
--- a/drivers/tee/Makefile
+++ b/drivers/tee/Makefile
@@ -3,3 +3,4 @@
obj-y += tee-uclass.o
obj-$(CONFIG_SANDBOX) += sandbox.o
obj-$(CONFIG_OPTEE) += optee/
+obj-y += broadcom/
diff --git a/drivers/tee/broadcom/Kconfig b/drivers/tee/broadcom/Kconfig
new file mode 100644
index 0000000000..ce95072d4e
--- /dev/null
+++ b/drivers/tee/broadcom/Kconfig
@@ -0,0 +1,7 @@
+config CHIMP_OPTEE
+ bool "Enable secure ChiMP firmware loading"
+ depends on OPTEE
+ default y
+ help
+ This driver is used to load bnxt firmware binary using OpTEE.
+ bnxt is Broadcom NetXtreme controller Ethernet card.
diff --git a/drivers/tee/broadcom/Makefile b/drivers/tee/broadcom/Makefile
new file mode 100644
index 0000000000..cb3cef16df
--- /dev/null
+++ b/drivers/tee/broadcom/Makefile
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0+
+
+obj-y += chimp_optee.o
diff --git a/drivers/tee/broadcom/chimp_optee.c b/drivers/tee/broadcom/chimp_optee.c
new file mode 100644
index 0000000000..37f9b094f7
--- /dev/null
+++ b/drivers/tee/broadcom/chimp_optee.c
@@ -0,0 +1,183 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright 2020 Broadcom.
+ */
+
+#include <common.h>
+#include <tee.h>
+#include <broadcom/chimp.h>
+
+#ifdef CONFIG_CHIMP_OPTEE
+
+#define CHMIP_BOOT_UUID { 0x6272636D, 0x2019, 0x0716, \
+ { 0x42, 0x43, 0x4D, 0x5F, 0x53, 0x43, 0x48, 0x49 } }
+
+enum {
+ TEE_CHIMP_FASTBOOT = 0,
+ TEE_CHIMP_HEALTH_STATUS,
+ TEE_CHIMP_HANDSHAKE_STATUS,
+} tee_chmip_cmd;
+
+struct bcm_chimp_data {
+ struct udevice *tee;
+ u32 session;
+} chimp_data;
+
+static int get_open_session(struct bcm_chimp_data *b_data)
+{
+ const struct tee_optee_ta_uuid uuid = CHMIP_BOOT_UUID;
+ struct tee_open_session_arg arg;
+ struct udevice *tee = NULL;
+ int rc;
+
+ tee = tee_find_device(NULL, NULL, NULL, NULL);
+ if (!tee)
+ return -ENODEV;
+
+ memset(&arg, 0, sizeof(arg));
+ tee_optee_ta_uuid_to_octets(arg.uuid, &uuid);
+ rc = tee_open_session(tee, &arg, 0, NULL);
+ if (rc < 0)
+ return -ENODEV;
+
+ b_data->tee = tee;
+ b_data->session = arg.session;
+
+ return 0;
+}
+
+static int init_arg(struct tee_invoke_arg *arg, u32 func)
+{
+ if (get_open_session(&chimp_data))
+ return -EINVAL;
+
+ memset(arg, 0, sizeof(struct tee_invoke_arg));
+ arg->func = func;
+ arg->session = chimp_data.session;
+
+ return 0;
+}
+
+int chimp_handshake_status_optee(u32 timeout, u32 *hs)
+{
+ struct tee_invoke_arg arg;
+ struct tee_param param[1];
+ int ret;
+
+ ret = init_arg(&arg, TEE_CHIMP_HANDSHAKE_STATUS);
+ if (ret < 0)
+ return ret;
+
+ param[0].attr = TEE_PARAM_ATTR_TYPE_VALUE_INOUT;
+ param[0].u.value.a = timeout;
+
+ ret = tee_invoke_func(chimp_data.tee, &arg, ARRAY_SIZE(param), param);
+ if (ret < 0) {
+ printf("Handshake status command failed\n");
+ goto out;
+ }
+
+ switch (arg.ret) {
+ case TEE_SUCCESS:
+ *hs = param[0].u.value.a;
+ ret = 0;
+ break;
+ default:
+ ret = -EINVAL;
+ break;
+ }
+
+out:
+ tee_close_session(chimp_data.tee, chimp_data.session);
+ chimp_data.tee = NULL;
+
+ return ret;
+}
+
+int chimp_health_status_optee(u32 *health)
+{
+ struct tee_invoke_arg arg;
+ struct tee_param param[1];
+ int ret;
+
+ ret = init_arg(&arg, TEE_CHIMP_HEALTH_STATUS);
+ if (ret < 0)
+ return ret;
+
+ param[0].attr = TEE_PARAM_ATTR_TYPE_VALUE_OUTPUT;
+
+ ret = tee_invoke_func(chimp_data.tee, &arg, ARRAY_SIZE(param), param);
+ if (ret < 0) {
+ printf("Helath status command failed\n");
+ goto out;
+ }
+
+ switch (arg.ret) {
+ case TEE_SUCCESS:
+ *health = param[0].u.value.a;
+ ret = 0;
+ break;
+ default:
+ ret = -EINVAL;
+ break;
+ }
+
+out:
+ tee_close_session(chimp_data.tee, chimp_data.session);
+ chimp_data.tee = NULL;
+
+ return ret;
+}
+
+int chimp_fastboot_optee(void)
+{
+ struct tee_invoke_arg arg;
+ int ret;
+
+ ret = init_arg(&arg, TEE_CHIMP_FASTBOOT);
+ if (ret < 0)
+ return ret;
+
+ ret = tee_invoke_func(chimp_data.tee, &arg, 0, NULL);
+ if (ret < 0) {
+ printf("Chimp boot_fail\n");
+ goto out;
+ }
+
+ switch (arg.ret) {
+ case TEE_SUCCESS:
+ ret = 0;
+ break;
+ default:
+ ret = -EINVAL;
+ break;
+ }
+
+out:
+ tee_close_session(chimp_data.tee, chimp_data.session);
+ chimp_data.tee = NULL;
+
+ return ret;
+}
+#else
+int chimp_handshake_status_optee(u32 timeout, u32 *status)
+{
+ printf("ChiMP handshake status fail (OPTEE not enabled)\n");
+
+ return -EINVAL;
+}
+
+int chimp_health_status_optee(u32 *status)
+{
+ printf("ChiMP health status fail (OPTEE not enabled)\n");
+
+ return -EINVAL;
+}
+
+int chimp_fastboot_optee(void)
+{
+ printf("ChiMP secure boot fail (OPTEE not enabled)\n");
+
+ return -EINVAL;
+}
+#endif /* CONFIG_CHIMP_OPTEE */