mirror of
https://github.com/openwrt/openwrt.git
synced 2024-12-27 01:11:14 +00:00
f5919b65d4
Patch generation process: - rebase rpi/rpi-4.14.y on v4.14.89 from linux-stable - git format-patch v4.14.89 Patches skipped during rebase: - lan78xx: Read MAC address from DT if present - lan78xx: Enable LEDs and auto-negotiation - Revert "softirq: Let ksoftirqd do its job" - sc16is7xx: Fix for multi-channel stall - lan78xx: Ignore DT MAC address if already valid - lan78xx: Simple patch to prevent some crashes - tcp_write_queue_purge clears all the SKBs in the write queue - Revert "lan78xx: Simple patch to prevent some crashes" - lan78xx: Connect phy early - Arm: mm: ftrace: Only set text back to ro after kernel has been marked ro - Revert "Revert "softirq: Let ksoftirqd do its job"" - ASoC: cs4265: SOC_SINGLE register value error fix - Revert "ASoC: cs4265: SOC_SINGLE register value error fix" - Revert "net: pskb_trim_rcsum() and CHECKSUM_COMPLETE are friends" - Revert "Revert "net: pskb_trim_rcsum() and CHECKSUM_COMPLETE are friends"" Patches dropped after rebase: - net: Add non-mainline source for rtl8192cu wlan - net: Fix rtl8192cu build errors on other platforms - brcm: adds support for BCM43341 wifi - brcmfmac: Mute expected startup 'errors' - ARM64: Fix build break for RTL8187/RTL8192CU wifi - ARM64: Enable RTL8187/RTL8192CU wifi in build config - This is the driver for Sony CXD2880 DVB-T2/T tuner + demodulator - brcmfmac: add CLM download support - brcmfmac: request_firmware_direct is quieter - Sets the BCDC priority to constant 0 - brcmfmac: Disable ARP offloading when promiscuous - brcmfmac: Avoid possible out-of-bounds read - brcmfmac: Delete redundant length check - net: rtl8192cu: Normalize indentation - net: rtl8192cu: Fix implicit fallthrough warnings - Revert "Sets the BCDC priority to constant 0" - media: cxd2880: Bump to match 4.18.y version - media: cxd2880-spi: Bump to match 4.18.y version - Revert "mm: alloc_contig: re-allow CMA to compact FS pages" - Revert "Revert "mm: alloc_contig: re-allow CMA to compact FS pages"" - cxd2880: CXD2880_SPI_DRV should select DVB_CXD2880 with MEDIA_SUBDRV_AUTOSELECT - 950-0421-HID-hid-bigbenff-driver-for-BigBen-Interactive-PS3OF.patch - 950-0453-Add-hid-bigbenff-to-list-of-have_special_driver-for-.patch Make I2C built-in instead of modular as in upstream defconfig; also the easiest way to get MFD_ARIZONA enabled, which is required by kmod-sound-soc-rpi-cirrus. Add missing compatible strings from 4.9/960-add-rasbperrypi-compatible.patch, using upstream names for compute modules. Add extra patch to enable the LEDs on lan78xx. Compile-tested: bcm2708, bcm2709, bcm2710 (with CONFIG_ALL_KMODS=y) Runtime-tested: bcm2708, bcm2710 Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
305 lines
8.3 KiB
Diff
305 lines
8.3 KiB
Diff
From 74e1aacb52fcaf5d07b5d765dca1287e4234f34d Mon Sep 17 00:00:00 2001
|
|
From: Dave Stevenson <dave.stevenson@raspberrypi.org>
|
|
Date: Mon, 20 Feb 2017 17:01:21 +0000
|
|
Subject: [PATCH 091/454] bcm2835-gpio-exp: Driver for GPIO expander via
|
|
mailbox service
|
|
|
|
Pi3 and Compute Module 3 have a GPIO expander that the
|
|
VPU communicates with.
|
|
There is a mailbox service that now allows control of this
|
|
expander, so add a kernel driver that can make use of it.
|
|
|
|
Pwr_led node added to device-tree for Pi3.
|
|
|
|
Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
|
|
---
|
|
drivers/gpio/Kconfig | 7 +
|
|
drivers/gpio/Makefile | 1 +
|
|
drivers/gpio/gpio-bcm-exp.c | 254 ++++++++++++++++++++++++++++++++++++
|
|
3 files changed, 262 insertions(+)
|
|
create mode 100644 drivers/gpio/gpio-bcm-exp.c
|
|
|
|
--- a/drivers/gpio/Kconfig
|
|
+++ b/drivers/gpio/Kconfig
|
|
@@ -128,6 +128,13 @@ config GPIO_AXP209
|
|
help
|
|
Say yes to enable GPIO support for the AXP209 PMIC
|
|
|
|
+config GPIO_BCM_EXP
|
|
+ bool "Broadcom Exp GPIO"
|
|
+ depends on OF_GPIO && RASPBERRYPI_FIRMWARE && (ARCH_BCM2835 || COMPILE_TEST)
|
|
+ help
|
|
+ Turn on GPIO support for Broadcom chips using the firmware mailbox
|
|
+ to communicate with VideoCore on BCM283x chips.
|
|
+
|
|
config GPIO_BCM_KONA
|
|
bool "Broadcom Kona GPIO"
|
|
depends on OF_GPIO && (ARCH_BCM_MOBILE || COMPILE_TEST)
|
|
--- a/drivers/gpio/Makefile
|
|
+++ b/drivers/gpio/Makefile
|
|
@@ -33,6 +33,7 @@ obj-$(CONFIG_GPIO_ARIZONA) += gpio-arizo
|
|
obj-$(CONFIG_GPIO_ATH79) += gpio-ath79.o
|
|
obj-$(CONFIG_GPIO_ASPEED) += gpio-aspeed.o
|
|
obj-$(CONFIG_GPIO_AXP209) += gpio-axp209.o
|
|
+obj-$(CONFIG_GPIO_BCM_EXP) += gpio-bcm-exp.o
|
|
obj-$(CONFIG_GPIO_BCM_KONA) += gpio-bcm-kona.o
|
|
obj-$(CONFIG_GPIO_BD9571MWV) += gpio-bd9571mwv.o
|
|
obj-$(CONFIG_GPIO_BCM_VIRT) += gpio-bcm-virt.o
|
|
--- /dev/null
|
|
+++ b/drivers/gpio/gpio-bcm-exp.c
|
|
@@ -0,0 +1,254 @@
|
|
+/*
|
|
+ * Broadcom expander GPIO driver
|
|
+ *
|
|
+ * Uses the firmware mailbox service to communicate with the
|
|
+ * GPIO expander on the VPU.
|
|
+ *
|
|
+ * Copyright (C) 2017 Raspberry Pi Trading Ltd.
|
|
+ *
|
|
+ * Author: Dave Stevenson <dave.stevenson@raspberrypi.org>
|
|
+ * Based on gpio-bcm-virt.c by Dom Cobley <popcornmix@gmail.com>
|
|
+ *
|
|
+ * 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.
|
|
+ */
|
|
+
|
|
+#include <linux/err.h>
|
|
+#include <linux/gpio.h>
|
|
+#include <linux/module.h>
|
|
+#include <linux/platform_device.h>
|
|
+#include <linux/dma-mapping.h>
|
|
+#include <soc/bcm2835/raspberrypi-firmware.h>
|
|
+
|
|
+#define MODULE_NAME "brcmexp-gpio"
|
|
+#define NUM_GPIO 8
|
|
+
|
|
+struct brcmexp_gpio {
|
|
+ struct gpio_chip gc;
|
|
+ struct device *dev;
|
|
+ struct rpi_firmware *fw;
|
|
+};
|
|
+
|
|
+struct gpio_set_config {
|
|
+ u32 gpio, direction, polarity, term_en, term_pull_up, state;
|
|
+};
|
|
+
|
|
+struct gpio_get_config {
|
|
+ u32 gpio, direction, polarity, term_en, term_pull_up;
|
|
+};
|
|
+
|
|
+struct gpio_get_set_state {
|
|
+ u32 gpio, state;
|
|
+};
|
|
+
|
|
+static int brcmexp_gpio_get_polarity(struct gpio_chip *gc, unsigned int off)
|
|
+{
|
|
+ struct brcmexp_gpio *gpio;
|
|
+ struct gpio_get_config get;
|
|
+ int ret;
|
|
+
|
|
+ gpio = container_of(gc, struct brcmexp_gpio, gc);
|
|
+
|
|
+ get.gpio = off + gpio->gc.base; /* GPIO to update */
|
|
+
|
|
+ ret = rpi_firmware_property(gpio->fw, RPI_FIRMWARE_GET_GPIO_CONFIG,
|
|
+ &get, sizeof(get));
|
|
+ if (ret) {
|
|
+ dev_err(gpio->dev,
|
|
+ "Failed to get GPIO %u config (%d)\n", off, ret);
|
|
+ return ret;
|
|
+ }
|
|
+ return get.polarity;
|
|
+}
|
|
+
|
|
+static int brcmexp_gpio_dir_in(struct gpio_chip *gc, unsigned int off)
|
|
+{
|
|
+ struct brcmexp_gpio *gpio;
|
|
+ struct gpio_set_config set_in;
|
|
+ int ret;
|
|
+
|
|
+ gpio = container_of(gc, struct brcmexp_gpio, gc);
|
|
+
|
|
+ set_in.gpio = off + gpio->gc.base; /* GPIO to update */
|
|
+ set_in.direction = 0; /* Input */
|
|
+ set_in.polarity = brcmexp_gpio_get_polarity(gc, off);
|
|
+ /* Retain existing setting */
|
|
+ set_in.term_en = 0; /* termination disabled */
|
|
+ set_in.term_pull_up = 0; /* n/a as termination disabled */
|
|
+ set_in.state = 0; /* n/a as configured as an input */
|
|
+
|
|
+ ret = rpi_firmware_property(gpio->fw, RPI_FIRMWARE_SET_GPIO_CONFIG,
|
|
+ &set_in, sizeof(set_in));
|
|
+ if (ret) {
|
|
+ dev_err(gpio->dev,
|
|
+ "Failed to set GPIO %u to input (%d)\n",
|
|
+ off, ret);
|
|
+ return ret;
|
|
+ }
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static int brcmexp_gpio_dir_out(struct gpio_chip *gc, unsigned int off, int val)
|
|
+{
|
|
+ struct brcmexp_gpio *gpio;
|
|
+ struct gpio_set_config set_out;
|
|
+ int ret;
|
|
+
|
|
+ gpio = container_of(gc, struct brcmexp_gpio, gc);
|
|
+
|
|
+ set_out.gpio = off + gpio->gc.base; /* GPIO to update */
|
|
+ set_out.direction = 1; /* Output */
|
|
+ set_out.polarity = brcmexp_gpio_get_polarity(gc, off);
|
|
+ /* Retain existing setting */
|
|
+ set_out.term_en = 0; /* n/a as an output */
|
|
+ set_out.term_pull_up = 0; /* n/a as termination disabled */
|
|
+ set_out.state = val; /* Output state */
|
|
+
|
|
+ ret = rpi_firmware_property(gpio->fw, RPI_FIRMWARE_SET_GPIO_CONFIG,
|
|
+ &set_out, sizeof(set_out));
|
|
+ if (ret) {
|
|
+ dev_err(gpio->dev,
|
|
+ "Failed to set GPIO %u to output (%d)\n", off, ret);
|
|
+ return ret;
|
|
+ }
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static int brcmexp_gpio_get_direction(struct gpio_chip *gc, unsigned int off)
|
|
+{
|
|
+ struct brcmexp_gpio *gpio;
|
|
+ struct gpio_get_config get;
|
|
+ int ret;
|
|
+
|
|
+ gpio = container_of(gc, struct brcmexp_gpio, gc);
|
|
+
|
|
+ get.gpio = off + gpio->gc.base; /* GPIO to update */
|
|
+
|
|
+ ret = rpi_firmware_property(gpio->fw, RPI_FIRMWARE_GET_GPIO_CONFIG,
|
|
+ &get, sizeof(get));
|
|
+ if (ret) {
|
|
+ dev_err(gpio->dev,
|
|
+ "Failed to get GPIO %u config (%d)\n", off, ret);
|
|
+ return ret;
|
|
+ }
|
|
+ return get.direction ? GPIOF_DIR_OUT : GPIOF_DIR_IN;
|
|
+}
|
|
+
|
|
+static int brcmexp_gpio_get(struct gpio_chip *gc, unsigned int off)
|
|
+{
|
|
+ struct brcmexp_gpio *gpio;
|
|
+ struct gpio_get_set_state get;
|
|
+ int ret;
|
|
+
|
|
+ gpio = container_of(gc, struct brcmexp_gpio, gc);
|
|
+
|
|
+ get.gpio = off + gpio->gc.base; /* GPIO to update */
|
|
+ get.state = 0; /* storage for returned value */
|
|
+
|
|
+ ret = rpi_firmware_property(gpio->fw, RPI_FIRMWARE_GET_GPIO_STATE,
|
|
+ &get, sizeof(get));
|
|
+ if (ret) {
|
|
+ dev_err(gpio->dev,
|
|
+ "Failed to get GPIO %u state (%d)\n", off, ret);
|
|
+ return ret;
|
|
+ }
|
|
+ return !!get.state;
|
|
+}
|
|
+
|
|
+static void brcmexp_gpio_set(struct gpio_chip *gc, unsigned int off, int val)
|
|
+{
|
|
+ struct brcmexp_gpio *gpio;
|
|
+ struct gpio_get_set_state set;
|
|
+ int ret;
|
|
+
|
|
+ gpio = container_of(gc, struct brcmexp_gpio, gc);
|
|
+
|
|
+ set.gpio = off + gpio->gc.base; /* GPIO to update */
|
|
+ set.state = val; /* Output state */
|
|
+
|
|
+ ret = rpi_firmware_property(gpio->fw, RPI_FIRMWARE_SET_GPIO_STATE,
|
|
+ &set, sizeof(set));
|
|
+ if (ret)
|
|
+ dev_err(gpio->dev,
|
|
+ "Failed to set GPIO %u state (%d)\n", off, ret);
|
|
+}
|
|
+
|
|
+static int brcmexp_gpio_probe(struct platform_device *pdev)
|
|
+{
|
|
+ int err = 0;
|
|
+ struct device *dev = &pdev->dev;
|
|
+ struct device_node *np = dev->of_node;
|
|
+ struct device_node *fw_node;
|
|
+ struct rpi_firmware *fw;
|
|
+ struct brcmexp_gpio *ucb;
|
|
+
|
|
+ fw_node = of_parse_phandle(np, "firmware", 0);
|
|
+ if (!fw_node) {
|
|
+ dev_err(dev, "Missing firmware node\n");
|
|
+ return -ENOENT;
|
|
+ }
|
|
+
|
|
+ fw = rpi_firmware_get(fw_node);
|
|
+ if (!fw)
|
|
+ return -EPROBE_DEFER;
|
|
+
|
|
+ ucb = devm_kzalloc(dev, sizeof(*ucb), GFP_KERNEL);
|
|
+ if (!ucb)
|
|
+ return -EINVAL;
|
|
+
|
|
+ ucb->fw = fw;
|
|
+ ucb->dev = dev;
|
|
+ ucb->gc.label = MODULE_NAME;
|
|
+ ucb->gc.owner = THIS_MODULE;
|
|
+ ucb->gc.of_node = np;
|
|
+ ucb->gc.base = 128;
|
|
+ ucb->gc.ngpio = NUM_GPIO;
|
|
+
|
|
+ ucb->gc.direction_input = brcmexp_gpio_dir_in;
|
|
+ ucb->gc.direction_output = brcmexp_gpio_dir_out;
|
|
+ ucb->gc.get_direction = brcmexp_gpio_get_direction;
|
|
+ ucb->gc.get = brcmexp_gpio_get;
|
|
+ ucb->gc.set = brcmexp_gpio_set;
|
|
+ ucb->gc.can_sleep = true;
|
|
+
|
|
+ err = gpiochip_add(&ucb->gc);
|
|
+ if (err)
|
|
+ return err;
|
|
+
|
|
+ platform_set_drvdata(pdev, ucb);
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static int brcmexp_gpio_remove(struct platform_device *pdev)
|
|
+{
|
|
+ struct brcmexp_gpio *ucb = platform_get_drvdata(pdev);
|
|
+
|
|
+ gpiochip_remove(&ucb->gc);
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static const struct of_device_id __maybe_unused brcmexp_gpio_ids[] = {
|
|
+ { .compatible = "brcm,bcm2835-expgpio" },
|
|
+ { }
|
|
+};
|
|
+MODULE_DEVICE_TABLE(of, brcmexp_gpio_ids);
|
|
+
|
|
+static struct platform_driver brcmexp_gpio_driver = {
|
|
+ .driver = {
|
|
+ .name = MODULE_NAME,
|
|
+ .owner = THIS_MODULE,
|
|
+ .of_match_table = of_match_ptr(brcmexp_gpio_ids),
|
|
+ },
|
|
+ .probe = brcmexp_gpio_probe,
|
|
+ .remove = brcmexp_gpio_remove,
|
|
+};
|
|
+module_platform_driver(brcmexp_gpio_driver);
|
|
+
|
|
+MODULE_LICENSE("GPL");
|
|
+MODULE_AUTHOR("Dave Stevenson <dave.stevenson@raspberrypi.org>");
|
|
+MODULE_DESCRIPTION("brcm-exp GPIO driver");
|
|
+MODULE_ALIAS("platform:brcmexp-gpio");
|