Skip to content

Commit

Permalink
Merge pull request #7 from Risca/topic-nanopi-r2s-disconnect
Browse files Browse the repository at this point in the history
nanopi-r2s: add support for disconnecting LAN port
  • Loading branch information
andni233 authored Aug 25, 2021
2 parents 3c5db7c + 0579050 commit 01c9446
Show file tree
Hide file tree
Showing 7 changed files with 9,362 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ build/armbian:
armbian_image: pypi | build/armbian
mkdir -p dist/image build/armbian/userpatches/overlay
cp -r image/armbian/userpatches/* build/armbian/userpatches
cp -r requirements.txt dist/pypi/*.whl image/common/files/* build/armbian/userpatches/overlay
cp -r requirements.txt dist/pypi/*.whl image/common/files/* image/armbian/files/* build/armbian/userpatches/overlay/
cd ./build/armbian && ./compile.sh docker znail-nanopi-r2s
mv build/armbian/output/images/* dist/image

Expand Down
25 changes: 25 additions & 0 deletions image/armbian/files/hub-ctrl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

while getopts "b:d:P:p:" o; do
case "${o}" in
p)
p=${OPTARG}
;;
*)
# ignore
;;
esac
done
shift $((OPTIND-1))

if [ -z "${p}" ]; then
exit 1
fi

if [ "${p}" == "0" ]; then
# Avoid error spam from driver
rmmod r8152
echo 0 > /sys/devices/platform/lan-switch/state
else
echo 1 > /sys/devices/platform/lan-switch/state
fi
3 changes: 1 addition & 2 deletions image/armbian/userpatches/customize-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ InstallZnail() {
install -v -m 644 "${OVERLAY}/znail.service" "/etc/systemd/system/"
rm -f "/etc/systemd/system/multi-user.target.wants/znail.service"
ln -s "/etc/systemd/system/znail.service" "/etc/systemd/system/multi-user.target.wants/znail.service"
# Fake hub-ctrl to make znail start
rm -f "/usr/local/bin/hub-ctrl"
ln -s "/usr/bin/true" "/usr/local/bin/hub-ctrl"
install -v -m 775 "${OVERLAY}/hub-ctrl" "/usr/local/bin/hub-ctrl"
}

EnableKernelModules "$@"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
From f003651c631a0a25832600e7446cd562f80c52a7 Mon Sep 17 00:00:00 2001
From: Laxman Dewangan <[email protected]>
Date: Wed, 30 Jul 2014 19:23:59 +0530
Subject: [PATCH 1/2] regulator: userspace-consumer: add DT support

Add DT support of the regulator driver userspace-consumer.
The supply names for this driver is provided through DT properties
so that proper regulator handle can be acquired.

Signed-off-by: Laxman Dewangan <[email protected]>
---
drivers/regulator/userspace-consumer.c | 48 ++++++++++++++++++++++++++
1 file changed, 48 insertions(+)

diff --git a/drivers/regulator/userspace-consumer.c b/drivers/regulator/userspace-consumer.c
index 765acc11c9c8..91d50a2770c0 100644
--- a/drivers/regulator/userspace-consumer.c
+++ b/drivers/regulator/userspace-consumer.c
@@ -23,6 +23,7 @@
#include <linux/regulator/consumer.h>
#include <linux/regulator/userspace-consumer.h>
#include <linux/slab.h>
+#include <linux/of.h>

struct userspace_consumer_data {
const char *name;
@@ -105,6 +106,41 @@ static const struct attribute_group attr_group = {
.attrs = attributes,
};

+static struct regulator_userspace_consumer_data *get_pdata_from_dt_node(
+ struct platform_device *pdev)
+{
+ struct regulator_userspace_consumer_data *pdata;
+ struct device_node *np = pdev->dev.of_node;
+ struct property *prop;
+ const char *supply;
+ int num_supplies;
+ int count = 0;
+
+ pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
+ if (!pdata)
+ return ERR_PTR(-ENOMEM);
+
+ pdata->name = of_get_property(np, "regulator-name", NULL);
+ pdata->init_on = of_property_read_bool(np, "regulator-boot-on");
+
+ num_supplies = of_property_count_strings(np, "regulator-supplies");
+ if (num_supplies < 0) {
+ dev_err(&pdev->dev,
+ "could not parse property regulator-supplies\n");
+ return ERR_PTR(-EINVAL);
+ }
+ pdata->num_supplies = num_supplies;
+ pdata->supplies = devm_kzalloc(&pdev->dev, num_supplies *
+ sizeof(*pdata->supplies), GFP_KERNEL);
+ if (!pdata->supplies)
+ return ERR_PTR(-ENOMEM);
+
+ of_property_for_each_string(np, "regulator-supplies", prop, supply)
+ pdata->supplies[count++].supply = supply;
+
+ return pdata;
+}
+
static int regulator_userspace_consumer_probe(struct platform_device *pdev)
{
struct regulator_userspace_consumer_data *pdata;
@@ -112,6 +148,11 @@ static int regulator_userspace_consumer_probe(struct platform_device *pdev)
int ret;

pdata = dev_get_platdata(&pdev->dev);
+ if (!pdata && pdev->dev.of_node) {
+ pdata = get_pdata_from_dt_node(pdev);
+ if (IS_ERR(pdata))
+ return PTR_ERR(pdata);
+ }
if (!pdata)
return -EINVAL;

@@ -171,11 +212,18 @@ static int regulator_userspace_consumer_remove(struct platform_device *pdev)
return 0;
}

+static const struct of_device_id regulator_userspace_consumer_of_match[] = {
+ { .compatible = "reg-userspace-consumer", },
+ {},
+};
+MODULE_DEVICE_TABLE(of, regulator_userspace_consumer_of_match);
+
static struct platform_driver regulator_userspace_consumer_driver = {
.probe = regulator_userspace_consumer_probe,
.remove = regulator_userspace_consumer_remove,
.driver = {
.name = "reg-userspace-consumer",
+ .of_match_table = regulator_userspace_consumer_of_match,
},
};

--
2.17.1
6 changes: 6 additions & 0 deletions image/armbian/userpatches/kernel/rockchip64-current/NOTE
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Patch naming matters!

armbian build scripts will apply its own patches and the patches here in alpha-
betical order, which means that special care needs to be taken if any custom
patches modifies files introduced by armbian, e.g.
nanopi-r2s-move-vcc_rtl8153-regulator-to-userspace.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
dt: nanopi-r2s: move vcc_rtl8153 regulator to userspace

This changes the vcc_rtl8153 so it's no longer "always-on", but instead
depends on number of consumers. Add a userspace regulator consumer and
make it on by default.

diff --git a/arch/arm64/boot/dts/rockchip/rk3328-nanopi-r2-rev00.dts b/arch/arm64/boot/dts/rockchip/rk3328-nanopi-r2-rev00.dts
index 717b1b2ed..fc88d49da 100644
--- a/arch/arm64/boot/dts/rockchip/rk3328-nanopi-r2-rev00.dts
+++ b/arch/arm64/boot/dts/rockchip/rk3328-nanopi-r2-rev00.dts
@@ -36,13 +36,20 @@ vcc_rtl8153: vcc-rtl8153-regulator {
gpio = <&gpio2 RK_PC6 GPIO_ACTIVE_HIGH>;
pinctrl-names = "default";
pinctrl-0 = <&usb30_en_drv>;
- regulator-always-on;
regulator-name = "vcc_rtl8153";
regulator-min-microvolt = <5000000>;
regulator-max-microvolt = <5000000>;
off-on-delay-us = <5000>;
enable-active-high;
};
+
+ lan-switch {
+ compatible = "reg-userspace-consumer";
+ regulator-name = "rtl8153-regulator-consumer";
+ regulator-boot-on;
+ regulator-supplies = "vdd5";
+ vdd5-supply = <&vcc_rtl8153>;
+ };
};

&mach {
Loading

0 comments on commit 01c9446

Please sign in to comment.