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

This commit is contained in:
domenico
2025-06-24 12:51:15 +02:00
commit 27c9d80f51
10493 changed files with 1885777 additions and 0 deletions

View File

@@ -0,0 +1,205 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* GPIO latch driver
*
* Copyright (C) 2014 Gabor Juhos <juhosg@openwrt.org>
*/
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/gpio/consumer.h>
#include <linux/gpio/driver.h>
#include <linux/platform_device.h>
#include <linux/of_platform.h>
#include <linux/of_gpio.h>
#define GPIO_LATCH_DRIVER_NAME "gpio-latch-mikrotik"
#define GPIO_LATCH_LINES 9
struct gpio_latch_chip {
struct gpio_chip gc;
struct mutex mutex;
struct mutex latch_mutex;
bool latch_enabled;
int le_gpio;
bool le_active_low;
struct gpio_desc *gpios[GPIO_LATCH_LINES];
};
static inline struct gpio_latch_chip *to_gpio_latch_chip(struct gpio_chip *gc)
{
return container_of(gc, struct gpio_latch_chip, gc);
}
static void gpio_latch_lock(struct gpio_latch_chip *glc, bool enable)
{
mutex_lock(&glc->mutex);
if (enable)
glc->latch_enabled = true;
if (glc->latch_enabled)
mutex_lock(&glc->latch_mutex);
}
static void gpio_latch_unlock(struct gpio_latch_chip *glc, bool disable)
{
if (glc->latch_enabled)
mutex_unlock(&glc->latch_mutex);
if (disable)
glc->latch_enabled = true;
mutex_unlock(&glc->mutex);
}
static int
gpio_latch_get(struct gpio_chip *gc, unsigned offset)
{
struct gpio_latch_chip *glc = to_gpio_latch_chip(gc);
int ret;
gpio_latch_lock(glc, false);
ret = gpiod_get_raw_value_cansleep(glc->gpios[offset]);
gpio_latch_unlock(glc, false);
return ret;
}
static void
gpio_latch_set(struct gpio_chip *gc, unsigned offset, int value)
{
struct gpio_latch_chip *glc = to_gpio_latch_chip(gc);
bool enable_latch = false;
bool disable_latch = false;
if (offset == glc->le_gpio) {
enable_latch = value ^ glc->le_active_low;
disable_latch = !enable_latch;
}
gpio_latch_lock(glc, enable_latch);
gpiod_set_raw_value_cansleep(glc->gpios[offset], value);
gpio_latch_unlock(glc, disable_latch);
}
static int
gpio_latch_direction_output(struct gpio_chip *gc, unsigned offset, int value)
{
struct gpio_latch_chip *glc = to_gpio_latch_chip(gc);
bool enable_latch = false;
bool disable_latch = false;
int ret;
if (offset == glc->le_gpio) {
enable_latch = value ^ glc->le_active_low;
disable_latch = !enable_latch;
}
gpio_latch_lock(glc, enable_latch);
ret = gpiod_direction_output_raw(glc->gpios[offset], value);
gpio_latch_unlock(glc, disable_latch);
return ret;
}
static int gpio_latch_probe(struct platform_device *pdev)
{
struct gpio_latch_chip *glc;
struct gpio_chip *gc;
struct device *dev = &pdev->dev;
struct fwnode_handle *fwnode = dev->fwnode;
int i, n;
glc = devm_kzalloc(dev, sizeof(*glc), GFP_KERNEL);
if (!glc)
return -ENOMEM;
mutex_init(&glc->mutex);
mutex_init(&glc->latch_mutex);
n = gpiod_count(dev, NULL);
if (n <= 0) {
dev_err(dev, "failed to get gpios: %d\n", n);
return n;
} else if (n != GPIO_LATCH_LINES) {
dev_err(dev, "expected %d gpios\n", GPIO_LATCH_LINES);
return -EINVAL;
}
for (i = 0; i < n; i++) {
glc->gpios[i] = devm_gpiod_get_index_optional(dev, NULL, i,
GPIOD_OUT_LOW);
if (IS_ERR(glc->gpios[i])) {
if (PTR_ERR(glc->gpios[i]) != -EPROBE_DEFER) {
dev_err(dev, "failed to get gpio %d: %ld\n", i,
PTR_ERR(glc->gpios[i]));
}
return PTR_ERR(glc->gpios[i]);
}
}
glc->le_gpio = 8;
glc->le_active_low = gpiod_is_active_low(glc->gpios[glc->le_gpio]);
if (!glc->gpios[glc->le_gpio]) {
dev_err(dev, "missing required latch-enable gpio %d\n",
glc->le_gpio);
return -EINVAL;
}
gc = &glc->gc;
gc->label = GPIO_LATCH_DRIVER_NAME;
gc->can_sleep = true;
gc->base = -1;
gc->ngpio = GPIO_LATCH_LINES;
gc->get = gpio_latch_get;
gc->set = gpio_latch_set;
gc->direction_output = gpio_latch_direction_output;
gc->fwnode = fwnode;
platform_set_drvdata(pdev, glc);
i = gpiochip_add(&glc->gc);
if (i) {
dev_err(dev, "gpiochip_add() failed: %d\n", i);
return i;
}
return 0;
}
static int gpio_latch_remove(struct platform_device *pdev)
{
struct gpio_latch_chip *glc = platform_get_drvdata(pdev);
gpiochip_remove(&glc->gc);
return 0;
}
static const struct of_device_id gpio_latch_match[] = {
{ .compatible = GPIO_LATCH_DRIVER_NAME },
{},
};
MODULE_DEVICE_TABLE(of, gpio_latch_match);
static struct platform_driver gpio_latch_driver = {
.probe = gpio_latch_probe,
.remove = gpio_latch_remove,
.driver = {
.name = GPIO_LATCH_DRIVER_NAME,
.owner = THIS_MODULE,
.of_match_table = gpio_latch_match,
},
};
module_platform_driver(gpio_latch_driver);
MODULE_DESCRIPTION("GPIO latch driver");
MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
MODULE_AUTHOR("Denis Kalashnikov <denis281089@gmail.com>");
MODULE_LICENSE("GPL v2");
MODULE_ALIAS("platform:" GPIO_LATCH_DRIVER_NAME);

View File

@@ -0,0 +1,172 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* GPIO driver for the MikroTik RouterBoard 4xx series
*
* Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
* Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
* Copyright (C) 2015 Bert Vermeulen <bert@biot.com>
* Copyright (C) 2020 Christopher Hill <ch6574@gmail.com>
*
* This file was based on the driver for Linux 2.6.22 published by
* MikroTik for their RouterBoard 4xx series devices.
*
* N.B. driver probe reports "DMA mask not set" warnings which are
* an artifact of using a platform_driver as an MFD device child.
* See conversation here https://lkml.org/lkml/2020/4/28/675
*/
#include <linux/platform_device.h>
#include <linux/gpio/driver.h>
#include <linux/module.h>
#include <linux/of_device.h>
#include <mfd/rb4xx-cpld.h>
struct rb4xx_gpio {
struct rb4xx_cpld *cpld;
struct device *dev;
struct gpio_chip chip;
struct mutex lock;
u16 values; /* bitfield of GPIO 0-8 current values */
};
static int rb4xx_gpio_cpld_set(struct rb4xx_gpio *gpio, unsigned int offset,
int value)
{
struct rb4xx_cpld *cpld = gpio->cpld;
u16 values;
int ret;
mutex_lock(&gpio->lock);
values = gpio->values;
if (value)
values |= BIT(offset);
else
values &= ~(BIT(offset));
if (values == gpio->values) {
ret = 0;
goto unlock;
}
if (offset < 8) {
ret = cpld->gpio_set_0_7(cpld, values & 0xff);
} else if (offset == 8) {
ret = cpld->gpio_set_8(cpld, values >> 8);
}
if(likely(!ret))
gpio->values = values;
unlock:
mutex_unlock(&gpio->lock);
return ret;
}
static int rb4xx_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
{
return 0; /* All 9 GPIOs are out */
}
static int rb4xx_gpio_direction_input(struct gpio_chip *chip,
unsigned int offset)
{
return -EOPNOTSUPP;
}
static int rb4xx_gpio_direction_output(struct gpio_chip *chip,
unsigned int offset, int value)
{
return rb4xx_gpio_cpld_set(gpiochip_get_data(chip), offset, value);
}
static int rb4xx_gpio_get(struct gpio_chip *chip, unsigned int offset)
{
struct rb4xx_gpio *gpio = gpiochip_get_data(chip);
int ret;
mutex_lock(&gpio->lock);
ret = (gpio->values >> offset) & 0x1;
mutex_unlock(&gpio->lock);
return ret;
}
static void rb4xx_gpio_set(struct gpio_chip *chip, unsigned int offset,
int value)
{
rb4xx_gpio_cpld_set(gpiochip_get_data(chip), offset, value);
}
static int rb4xx_gpio_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct device *parent = dev->parent;
struct rb4xx_gpio *gpio;
u32 val;
if (!parent)
return -ENODEV;
gpio = devm_kzalloc(dev, sizeof(*gpio), GFP_KERNEL);
if (!gpio)
return -ENOMEM;
platform_set_drvdata(pdev, gpio);
gpio->cpld = dev_get_drvdata(parent);
gpio->dev = dev;
gpio->values = 0;
mutex_init(&gpio->lock);
gpio->chip.label = "rb4xx-gpio";
gpio->chip.parent = dev;
gpio->chip.owner = THIS_MODULE;
gpio->chip.get_direction = rb4xx_gpio_get_direction;
gpio->chip.direction_input = rb4xx_gpio_direction_input;
gpio->chip.direction_output = rb4xx_gpio_direction_output;
gpio->chip.get = rb4xx_gpio_get;
gpio->chip.set = rb4xx_gpio_set;
gpio->chip.ngpio = 9;
gpio->chip.base = -1;
gpio->chip.can_sleep = 1;
if (!of_property_read_u32(dev->of_node, "base", &val))
gpio->chip.base = val;
return gpiochip_add_data(&gpio->chip, gpio);
}
static int rb4xx_gpio_remove(struct platform_device *pdev)
{
struct rb4xx_gpio *gpio = platform_get_drvdata(pdev);
gpiochip_remove(&gpio->chip);
mutex_destroy(&gpio->lock);
return 0;
}
static const struct platform_device_id rb4xx_gpio_id_table[] = {
{ "mikrotik,rb4xx-gpio", },
{ },
};
MODULE_DEVICE_TABLE(platform, rb4xx_gpio_id_table);
static struct platform_driver rb4xx_gpio_driver = {
.probe = rb4xx_gpio_probe,
.remove = rb4xx_gpio_remove,
.id_table = rb4xx_gpio_id_table,
.driver = {
.name = "rb4xx-gpio",
},
};
module_platform_driver(rb4xx_gpio_driver);
MODULE_DESCRIPTION("Mikrotik RB4xx GPIO driver");
MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
MODULE_AUTHOR("Imre Kaloz <kaloz@openwrt.org>");
MODULE_AUTHOR("Bert Vermeulen <bert@biot.com>");
MODULE_AUTHOR("Christopher Hill <ch6574@gmail.com");
MODULE_LICENSE("GPL v2");

View File

@@ -0,0 +1,218 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Driver for reset key gpio line on MikroTik RB91x board series.
* This line is shared between NAND ALE (goes through a latch),
* NAND IO7 and reset key. We make 3 virtual gpio lines from the
* single physical one:
* 1) Capable output one for NAND,
* 2) Capable input one for reset key,
* 3) And capable output one, aka "key-poll-disable",
* for NAND -- to syncronise NAND operation and key polling.
*
* Copyright (C) 2021 Denis Kalashnikov <denis281089@gmail.com>
*/
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/gpio/consumer.h>
#include <linux/gpio/driver.h>
#include <linux/platform_device.h>
#include <linux/of_platform.h>
#include <linux/of_gpio.h>
#include <linux/delay.h>
#define GPIO_RB91X_KEY_DRIVER_NAME "gpio-rb91x-key"
enum gpio_rb91x_key_gpios {
GPIO_RB91X_KEY_NAND,
GPIO_RB91X_KEY_POLL,
GPIO_RB91X_KEY_PDIS,
GPIO_RB91X_KEY_NGPIOS,
};
struct gpio_rb91x_key {
struct gpio_chip gc;
struct mutex mutex;
struct mutex poll_mutex;
int polling_disabled;
struct gpio_desc *gpio;
};
static inline struct gpio_rb91x_key *to_gpio_rb91x_key(struct gpio_chip *gc)
{
return container_of(gc, struct gpio_rb91x_key, gc);
}
static int gpio_rb91x_key_get(struct gpio_chip *gc, unsigned offset)
{
struct gpio_rb91x_key *drvdata = to_gpio_rb91x_key(gc);
struct gpio_desc *gpio = drvdata->gpio;
int val, bak_val;
switch (offset) {
case GPIO_RB91X_KEY_NAND:
mutex_lock(&drvdata->mutex);
val = gpiod_get_value_cansleep(gpio);
mutex_unlock(&drvdata->mutex);
break;
case GPIO_RB91X_KEY_PDIS:
mutex_lock(&drvdata->mutex);
val = drvdata->polling_disabled;
mutex_unlock(&drvdata->mutex);
break;
case GPIO_RB91X_KEY_POLL:
mutex_lock(&drvdata->poll_mutex);
mutex_lock(&drvdata->mutex);
bak_val = gpiod_get_raw_value_cansleep(gpio);
gpiod_direction_input(gpio);
/*
* Without this delay nothing works. Get it
* from mikrotik RouterOS linux kernel patches.
*/
udelay(200);
val = gpiod_get_raw_value_cansleep(gpio);
gpiod_direction_output_raw(gpio, bak_val);
mutex_unlock(&drvdata->mutex);
mutex_unlock(&drvdata->poll_mutex);
break;
default:
return -EINVAL;
}
return val;
}
static int gpio_rb91x_key_direction_input(struct gpio_chip *gc, unsigned offset)
{
switch (offset) {
case GPIO_RB91X_KEY_POLL:
return 0;
default:
return -EINVAL;
}
}
static void gpio_rb91x_key_set(struct gpio_chip *gc, unsigned offset, int value)
{
struct gpio_rb91x_key *drvdata = to_gpio_rb91x_key(gc);
struct gpio_desc *gpio = drvdata->gpio;
mutex_lock(&drvdata->mutex);
switch (offset) {
case GPIO_RB91X_KEY_NAND:
gpiod_set_raw_value_cansleep(gpio, value);
break;
case GPIO_RB91X_KEY_PDIS:
if (value) {
if (!drvdata->polling_disabled) {
mutex_lock(&drvdata->poll_mutex);
drvdata->polling_disabled = 1;
}
} else {
if (drvdata->polling_disabled) {
mutex_unlock(&drvdata->poll_mutex);
drvdata->polling_disabled = 0;
}
}
break;
default:
break;
}
mutex_unlock(&drvdata->mutex);
}
static int gpio_rb91x_key_direction_output(struct gpio_chip *gc, unsigned offset,
int value)
{
switch (offset) {
case GPIO_RB91X_KEY_NAND:
case GPIO_RB91X_KEY_PDIS:
gpio_rb91x_key_set(gc, offset, value);
return 0;
default:
return -EINVAL;
}
}
static int gpio_rb91x_key_probe(struct platform_device *pdev)
{
struct gpio_rb91x_key *drvdata;
struct gpio_chip *gc;
struct device *dev = &pdev->dev;
struct fwnode_handle *fwnode = dev->fwnode;
int r;
drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
if (!drvdata)
return -ENOMEM;
mutex_init(&drvdata->mutex);
mutex_init(&drvdata->poll_mutex);
drvdata->gpio = devm_gpiod_get(dev, NULL, GPIOD_OUT_LOW);
if (IS_ERR(drvdata->gpio)) {
if (PTR_ERR(drvdata->gpio) != -EPROBE_DEFER) {
dev_err(dev, "failed to get gpio: %ld\n",
PTR_ERR(drvdata->gpio));
}
return PTR_ERR(drvdata->gpio);
}
gc = &drvdata->gc;
gc->label = GPIO_RB91X_KEY_DRIVER_NAME;
gc->can_sleep = 1;
gc->base = -1;
gc->ngpio = GPIO_RB91X_KEY_NGPIOS;
gc->get = gpio_rb91x_key_get;
gc->set = gpio_rb91x_key_set;
gc->direction_output = gpio_rb91x_key_direction_output;
gc->direction_input = gpio_rb91x_key_direction_input;
gc->fwnode = fwnode;
platform_set_drvdata(pdev, drvdata);
r = gpiochip_add(&drvdata->gc);
if (r) {
dev_err(dev, "gpiochip_add() failed: %d\n", r);
return r;
}
return 0;
}
static int gpio_rb91x_key_remove(struct platform_device *pdev)
{
struct gpio_rb91x_key *drvdata = platform_get_drvdata(pdev);
gpiochip_remove(&drvdata->gc);
return 0;
}
static const struct of_device_id gpio_rb91x_key_match[] = {
{ .compatible = "mikrotik,"GPIO_RB91X_KEY_DRIVER_NAME },
{},
};
MODULE_DEVICE_TABLE(of, gpio_rb91x_key_match);
static struct platform_driver gpio_rb91x_key_driver = {
.probe = gpio_rb91x_key_probe,
.remove = gpio_rb91x_key_remove,
.driver = {
.name = GPIO_RB91X_KEY_DRIVER_NAME,
.owner = THIS_MODULE,
.of_match_table = gpio_rb91x_key_match,
},
};
module_platform_driver(gpio_rb91x_key_driver);
MODULE_DESCRIPTION("Driver for reset key gpio line shared with NAND for MikroTik RB91x board series.");
MODULE_AUTHOR("Denis Kalashnikov <denis281089@gmail.com>");
MODULE_LICENSE("GPL v2");
MODULE_ALIAS("platform:" GPIO_RB91X_KEY_DRIVER_NAME);