Skip to content

Add Raspberry Pi PoE+ HAT support #4366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions arch/arm/boot/dts/overlays/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ dtbo-$(CONFIG_ARCH_BCM2835) += \
rpi-display.dtbo \
rpi-ft5406.dtbo \
rpi-poe.dtbo \
rpi-poe-plus.dtbo \
rpi-proto.dtbo \
rpi-sense.dtbo \
rpi-tv.dtbo \
Expand Down
19 changes: 19 additions & 0 deletions arch/arm/boot/dts/overlays/rpi-poe-plus-overlay.dts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: (GPL-2.0 OR MIT)
// Overlay for the Raspberry Pi PoE+ HAT.

#include "rpi-poe-overlay.dts"

/ {
compatible = "brcm,bcm2835";

fragment@3 {
target-path = "/";
__overlay__ {
rpi_poe_power_supply: rpi-poe-power-supply@0 {
compatible = "raspberrypi,rpi-poe-power-supply";
firmware = <&firmware>;
status = "okay";
};
};
};
};
1 change: 1 addition & 0 deletions arch/arm/configs/bcm2709_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ CONFIG_W1_SLAVE_DS28E04=m
CONFIG_W1_SLAVE_DS28E17=m
CONFIG_POWER_RESET=y
CONFIG_POWER_RESET_GPIO=y
CONFIG_RPI_POE_POWER=m
CONFIG_BATTERY_DS2760=m
CONFIG_BATTERY_MAX17040=m
CONFIG_BATTERY_GAUGE_LTC2941=m
Expand Down
1 change: 1 addition & 0 deletions arch/arm/configs/bcm2711_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ CONFIG_W1_SLAVE_DS28E04=m
CONFIG_W1_SLAVE_DS28E17=m
CONFIG_POWER_RESET=y
CONFIG_POWER_RESET_GPIO=y
CONFIG_RPI_POE_POWER=m
CONFIG_BATTERY_DS2760=m
CONFIG_BATTERY_MAX17040=m
CONFIG_BATTERY_GAUGE_LTC2941=m
Expand Down
1 change: 1 addition & 0 deletions arch/arm/configs/bcmrpi_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ CONFIG_W1_SLAVE_DS28E04=m
CONFIG_W1_SLAVE_DS28E17=m
CONFIG_POWER_RESET=y
CONFIG_POWER_RESET_GPIO=y
CONFIG_RPI_POE_POWER=m
CONFIG_BATTERY_DS2760=m
CONFIG_BATTERY_MAX17040=m
CONFIG_BATTERY_GAUGE_LTC2941=m
Expand Down
1 change: 1 addition & 0 deletions arch/arm64/configs/bcm2711_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ CONFIG_W1_SLAVE_DS2781=m
CONFIG_W1_SLAVE_DS28E04=m
CONFIG_W1_SLAVE_DS28E17=m
CONFIG_POWER_RESET_GPIO=y
CONFIG_RPI_POE_POWER=m
CONFIG_BATTERY_DS2760=m
CONFIG_BATTERY_MAX17040=m
CONFIG_BATTERY_GAUGE_LTC2941=m
Expand Down
35 changes: 25 additions & 10 deletions drivers/hwmon/rpi-poe-fan.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
struct rpi_poe_fan_ctx {
struct mutex lock;
struct rpi_firmware *fw;
u32 set_tag;
unsigned int pwm_value;
unsigned int def_pwm_value;
unsigned int rpi_poe_fan_state;
Expand All @@ -43,13 +44,15 @@ struct fw_tag_data_s{
u32 ret;
};

static int write_reg(struct rpi_firmware *fw, u32 reg, u32 *val){
static int write_reg(struct rpi_firmware *fw, u32 reg, u32 *val, u32 set_tag)
{
struct fw_tag_data_s fw_tag_data = {
.reg = reg,
.val = *val
};
int ret;
ret = rpi_firmware_property(fw, RPI_FIRMWARE_SET_POE_HAT_VAL,

ret = rpi_firmware_property(fw, set_tag,
&fw_tag_data, sizeof(fw_tag_data));
if (ret) {
return ret;
Expand Down Expand Up @@ -82,7 +85,7 @@ static int rpi_poe_reboot(struct notifier_block *nb, unsigned long code,
nb);

if (ctx->pwm_value != ctx->def_pwm_value)
write_reg(ctx->fw, POE_CUR_PWM, &ctx->def_pwm_value);
write_reg(ctx->fw, POE_CUR_PWM, &ctx->def_pwm_value, ctx->set_tag);

return NOTIFY_DONE;
}
Expand All @@ -95,7 +98,7 @@ static int __set_pwm(struct rpi_poe_fan_ctx *ctx, u32 pwm)
if (ctx->pwm_value == pwm)
goto exit_set_pwm_err;

ret = write_reg(ctx->fw, POE_CUR_PWM, &pwm);
ret = write_reg(ctx->fw, POE_CUR_PWM, &pwm, ctx->set_tag);
if (!ret)
ctx->pwm_value = pwm;
exit_set_pwm_err:
Expand All @@ -110,7 +113,7 @@ static int __set_def_pwm(struct rpi_poe_fan_ctx *ctx, u32 def_pwm)
if (ctx->def_pwm_value == def_pwm)
goto exit_set_def_pwm_err;

ret = write_reg(ctx->fw, POE_DEF_PWM, &def_pwm);
ret = write_reg(ctx->fw, POE_DEF_PWM, &def_pwm, ctx->set_tag);
if (!ret)
ctx->def_pwm_value = def_pwm;
exit_set_def_pwm_err:
Expand Down Expand Up @@ -297,6 +300,7 @@ static int rpi_poe_fan_probe(struct platform_device *pdev)
struct device *hwmon;
struct device_node *np = pdev->dev.of_node;
struct device_node *fw_node;
u32 revision;
int ret;

fw_node = of_parse_phandle(np, "firmware", 0);
Expand All @@ -314,6 +318,17 @@ static int rpi_poe_fan_probe(struct platform_device *pdev)
ctx->fw = rpi_firmware_get(fw_node);
if (!ctx->fw)
return -EPROBE_DEFER;
ret = rpi_firmware_property(ctx->fw,
RPI_FIRMWARE_GET_FIRMWARE_REVISION,
&revision, sizeof(revision));
if (ret) {
dev_err(&pdev->dev, "Failed to get firmware revision: %i\n", ret);
return ret;
}
if (revision < 0x60af72e8)
ctx->set_tag = RPI_FIRMWARE_SET_POE_HAT_VAL_OLD;
else
ctx->set_tag = RPI_FIRMWARE_SET_POE_HAT_VAL;

platform_set_drvdata(pdev, ctx);

Expand Down Expand Up @@ -378,9 +393,9 @@ static int rpi_poe_fan_remove(struct platform_device *pdev)

unregister_reboot_notifier(&ctx->nb);
thermal_cooling_device_unregister(ctx->cdev);
if (ctx->pwm_value != value) {
write_reg(ctx->fw, POE_CUR_PWM, &value);
}
if (ctx->pwm_value != value)
write_reg(ctx->fw, POE_CUR_PWM, &value, ctx->set_tag);

return 0;
}

Expand All @@ -392,7 +407,7 @@ static int rpi_poe_fan_suspend(struct device *dev)
int ret = 0;

if (ctx->pwm_value != value)
ret = write_reg(ctx->fw, POE_CUR_PWM, &value);
ret = write_reg(ctx->fw, POE_CUR_PWM, &value, ctx->set_tag);
return ret;
}

Expand All @@ -403,7 +418,7 @@ static int rpi_poe_fan_resume(struct device *dev)
int ret = 0;

if (value != 0)
ret = write_reg(ctx->fw, POE_CUR_PWM, &value);
ret = write_reg(ctx->fw, POE_CUR_PWM, &value, ctx->set_tag);

return ret;
}
Expand Down
6 changes: 6 additions & 0 deletions drivers/power/supply/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ config POWER_SUPPLY_HWMON
Say 'Y' here if you want power supplies to
have hwmon sysfs interface too.

config RPI_POE_POWER
tristate "Raspberry Pi PoE+ HAT power supply driver"
depends on RASPBERRYPI_FIRMWARE
help
Say Y here to enable support for Raspberry Pi PoE+ (Power over Ethernet
Plus) HAT current measurement.

config PDA_POWER
tristate "Generic PDA/phone power driver"
Expand Down
1 change: 1 addition & 0 deletions drivers/power/supply/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ obj-$(CONFIG_POWER_SUPPLY) += power_supply.o
obj-$(CONFIG_POWER_SUPPLY_HWMON) += power_supply_hwmon.o
obj-$(CONFIG_GENERIC_ADC_BATTERY) += generic-adc-battery.o

obj-$(CONFIG_RPI_POE_POWER) += rpi_poe_power.o
obj-$(CONFIG_PDA_POWER) += pda_power.o
obj-$(CONFIG_APM_POWER) += apm_power.o
obj-$(CONFIG_AXP20X_POWER) += axp20x_usb_power.o
Expand Down
Loading