Add sht3x overlay, as yet untested
This commit is contained in:
parent
1e80edd3f7
commit
58f563522f
13
config/dts/rpi-sht3x.dts
Normal file
13
config/dts/rpi-sht3x.dts
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
/dts-v1/;
|
||||||
|
/plugin/;
|
||||||
|
|
||||||
|
/{
|
||||||
|
compatible = "brcm,bcm2835";
|
||||||
|
};
|
||||||
|
|
||||||
|
&i2c1 {
|
||||||
|
temp0: sht3x@44 {
|
||||||
|
compatible = "sensirion,sht3x";
|
||||||
|
reg = <0x44>;
|
||||||
|
};
|
||||||
|
};
|
8
config/overlay.nix
Normal file
8
config/overlay.nix
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
final: prev: {
|
||||||
|
kernelPatches = prev // {
|
||||||
|
sht3x_dt_binding = {
|
||||||
|
name = "sht3x-dt-binding";
|
||||||
|
patch = ./sht3x_dt_binding.patch;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
102
config/sht3x_dt_binding.patch
Normal file
102
config/sht3x_dt_binding.patch
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
diff --git a/Documentation/devicetree/bindings/hwmon/sht3x.yaml b/Documentation/devicetree/bindings/hwmon/sht3x.yaml
|
||||||
|
new file mode 100644
|
||||||
|
index 000000000000..89da68ba5772
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/Documentation/devicetree/bindings/hwmon/sht3x.yaml
|
||||||
|
@@ -0,0 +1,39 @@
|
||||||
|
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
|
||||||
|
+%YAML 1.2
|
||||||
|
+---
|
||||||
|
+$id: http://devicetree.org/schemas/hwmon/sht3x.yaml#
|
||||||
|
+$schema: http://devicetree.org/meta-schemas/core.yaml#
|
||||||
|
+
|
||||||
|
+title: SHT3x hwmon sensor
|
||||||
|
+
|
||||||
|
+maintainers:
|
||||||
|
+ - Artemis Tosini <linux@artem.ist>
|
||||||
|
+
|
||||||
|
+properties:
|
||||||
|
+ compatible:
|
||||||
|
+ enum:
|
||||||
|
+ - sensirion,sht3x
|
||||||
|
+ - sensirion,sts3x
|
||||||
|
+
|
||||||
|
+ reg:
|
||||||
|
+ maxItems: 1
|
||||||
|
+
|
||||||
|
+ vs-supply:
|
||||||
|
+ description: phandle to the regulator supplying Vdd
|
||||||
|
+
|
||||||
|
+requred:
|
||||||
|
+ - compatible
|
||||||
|
+ - reg
|
||||||
|
+
|
||||||
|
+examples:
|
||||||
|
+ - |
|
||||||
|
+ i2c {
|
||||||
|
+ #address-cells = <1>;
|
||||||
|
+ #size-cells = <0>;
|
||||||
|
+
|
||||||
|
+ sensor@44 {
|
||||||
|
+ compatible = "sensirion,sht3x";
|
||||||
|
+ reg = <0x44>;
|
||||||
|
+ vs-supply = <&v3v3>;
|
||||||
|
+ };
|
||||||
|
+ };
|
||||||
|
diff --git a/drivers/hwmon/sht3x.c b/drivers/hwmon/sht3x.c
|
||||||
|
index 79657910b79e..ff8684875880 100644
|
||||||
|
--- a/drivers/hwmon/sht3x.c
|
||||||
|
+++ b/drivers/hwmon/sht3x.c
|
||||||
|
@@ -18,6 +18,7 @@
|
||||||
|
#include <linux/init.h>
|
||||||
|
#include <linux/kernel.h>
|
||||||
|
#include <linux/module.h>
|
||||||
|
+#include <linux/of.h>
|
||||||
|
#include <linux/slab.h>
|
||||||
|
#include <linux/jiffies.h>
|
||||||
|
|
||||||
|
@@ -851,6 +852,20 @@ static const struct i2c_device_id sht3x_ids[] = {
|
||||||
|
|
||||||
|
MODULE_DEVICE_TABLE(i2c, sht3x_ids);
|
||||||
|
|
||||||
|
+static const struct of_device_id sht3x_of_match[] = {
|
||||||
|
+ {
|
||||||
|
+ .compatible = "sensirion,sht3x",
|
||||||
|
+ .data = (void *)sht3x
|
||||||
|
+ },
|
||||||
|
+ {
|
||||||
|
+ .compatible = "sensirion,sts3x",
|
||||||
|
+ .data = (void *)sts3x
|
||||||
|
+ },
|
||||||
|
+ { },
|
||||||
|
+};
|
||||||
|
+
|
||||||
|
+MODULE_DEVICE_TABLE(of, sht3x_of_match);
|
||||||
|
+
|
||||||
|
static int sht3x_probe(struct i2c_client *client)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
@@ -880,7 +895,10 @@ static int sht3x_probe(struct i2c_client *client)
|
||||||
|
data->mode = 0;
|
||||||
|
data->last_update = jiffies - msecs_to_jiffies(3000);
|
||||||
|
data->client = client;
|
||||||
|
- data->chip_id = i2c_match_id(sht3x_ids, client)->driver_data;
|
||||||
|
+ if (client->dev.of_node)
|
||||||
|
+ data->chip_id = (uintptr_t)of_device_get_match_data(&client->dev);
|
||||||
|
+ else
|
||||||
|
+ data->chip_id = i2c_match_id(sht3x_ids, client)->driver_data;
|
||||||
|
crc8_populate_msb(sht3x_crc8_table, SHT3X_CRC8_POLYNOMIAL);
|
||||||
|
|
||||||
|
sht3x_select_command(data);
|
||||||
|
@@ -912,7 +930,10 @@ static int sht3x_probe(struct i2c_client *client)
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct i2c_driver sht3x_i2c_driver = {
|
||||||
|
- .driver.name = "sht3x",
|
||||||
|
+ .driver = {
|
||||||
|
+ .name = "sht3x",
|
||||||
|
+ .of_match_table = of_match_ptr(sht3x_of_match)
|
||||||
|
+ },
|
||||||
|
.probe = sht3x_probe,
|
||||||
|
.id_table = sht3x_ids,
|
||||||
|
};
|
|
@ -2,16 +2,16 @@
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1701693815,
|
"lastModified": 1702083043,
|
||||||
"narHash": "sha256-7BkrXykVWfkn6+c1EhFA3ko4MLi3gVG0p9G96PNnKTM=",
|
"narHash": "sha256-nr58yddqfKB+Gcr9KnnmHj5XSEiIKdxjSKn4djq6J4s=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "09ec6a0881e1a36c29d67497693a67a16f4da573",
|
"rev": "950f7c7bd15c37f4485864d8fab4afc4b4d8e3eb",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"ref": "nixpkgs-unstable",
|
"ref": "release-23.11",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
|
|
53
flake.nix
53
flake.nix
|
@ -1,23 +1,19 @@
|
||||||
{
|
{
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
|
nixpkgs.url = "github:nixos/nixpkgs/release-23.11";
|
||||||
utils.url = "github:numtide/flake-utils";
|
utils.url = "github:numtide/flake-utils";
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = { self, nixpkgs, utils }:
|
outputs = { self, nixpkgs, utils }:
|
||||||
let supportedSystems = [ "x86_64-linux" "aarch64-linux" ];
|
let
|
||||||
|
supportedSystems = [ "x86_64-linux" "aarch64-linux" ];
|
||||||
|
inherit (nixpkgs) lib;
|
||||||
in (utils.lib.eachSystem supportedSystems (system:
|
in (utils.lib.eachSystem supportedSystems (system:
|
||||||
let
|
let
|
||||||
pkgs = import nixpkgs { inherit system; };
|
pkgs = import nixpkgs { inherit system; };
|
||||||
inherit (pkgs) lib;
|
|
||||||
makeImage = conf:
|
makeImage = conf:
|
||||||
(conf.extendModules {
|
(conf.extendModules {
|
||||||
modules = [{
|
modules = [{ config.nixpkgs.buildPlatform.system = system; }];
|
||||||
config.nixpkgs = {
|
|
||||||
hostPlatform.system = conf.config.nixpkgs.system;
|
|
||||||
buildPlatform.system = system;
|
|
||||||
};
|
|
||||||
}];
|
|
||||||
}).config.system.build.sdImage;
|
}).config.system.build.sdImage;
|
||||||
in {
|
in {
|
||||||
formatter = pkgs.nixfmt;
|
formatter = pkgs.nixfmt;
|
||||||
|
@ -29,6 +25,7 @@
|
||||||
disabledModules = [ "profiles/base.nix" ];
|
disabledModules = [ "profiles/base.nix" ];
|
||||||
config = {
|
config = {
|
||||||
boot.bcache.enable = false;
|
boot.bcache.enable = false;
|
||||||
|
boot.initrd.includeDefaultModules = false;
|
||||||
environment.defaultPackages = [ ];
|
environment.defaultPackages = [ ];
|
||||||
fonts.fontconfig.enable = false;
|
fonts.fontconfig.enable = false;
|
||||||
networking.firewall.enable = false;
|
networking.firewall.enable = false;
|
||||||
|
@ -38,6 +35,7 @@
|
||||||
|
|
||||||
# We could theoretically disable system-path.nix so we don't have
|
# We could theoretically disable system-path.nix so we don't have
|
||||||
# requiredPackages, but that seems like a lot of work.
|
# requiredPackages, but that seems like a lot of work.
|
||||||
|
# At that point I should just use buildroot...
|
||||||
|
|
||||||
# Leave networking.useDHCP = true since we would reenable it anyway
|
# Leave networking.useDHCP = true since we would reenable it anyway
|
||||||
|
|
||||||
|
@ -54,12 +52,45 @@
|
||||||
users.users.root.initialPassword = "ohnowo";
|
users.users.root.initialPassword = "ohnowo";
|
||||||
};
|
};
|
||||||
|
|
||||||
nixosConfigurations.aarch64-rpi = nixpkgs.lib.nixosSystem {
|
nixosModules.rpiSht3x = { pkgs, lib, ... }: {
|
||||||
system = "aarch64-linux";
|
# Patch doesn't apply on old vendor kernels
|
||||||
|
boot.kernelPackages = lib.mkForce pkgs.linuxPackages_latest;
|
||||||
|
|
||||||
|
nixpkgs.overlays = [ (import ./config/overlay.nix) ];
|
||||||
|
boot.kernelPatches = [ pkgs.kernelPatches.sht3x_dt_binding ];
|
||||||
|
|
||||||
|
hardware.deviceTree.overlays = [{
|
||||||
|
name = "sht3x";
|
||||||
|
dtsFile = ./config/dts/rpi-sht3x.dts;
|
||||||
|
}];
|
||||||
|
};
|
||||||
|
|
||||||
|
nixosConfigurations.aarch64-rpi = lib.nixosSystem {
|
||||||
modules = [
|
modules = [
|
||||||
self.nixosModules.minify
|
self.nixosModules.minify
|
||||||
self.nixosModules.insecureRemote
|
self.nixosModules.insecureRemote
|
||||||
"${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
|
"${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
|
||||||
|
{
|
||||||
|
nixpkgs.hostPlatform = lib.systems.examples.aarch64-multiplatform;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
nixosConfigurations.armv6-rpi = lib.nixosSystem {
|
||||||
|
modules = [
|
||||||
|
self.nixosModules.minify
|
||||||
|
self.nixosModules.insecureRemote
|
||||||
|
self.nixosModules.rpiSht3x
|
||||||
|
"${nixpkgs}/nixos/modules/installer/sd-card/sd-image-raspberrypi.nix"
|
||||||
|
({ pkgs, ... }: {
|
||||||
|
nixpkgs.hostPlatform = lib.systems.examples.raspberryPi;
|
||||||
|
nixpkgs.overlays = [
|
||||||
|
(final: prev: {
|
||||||
|
# compiler-rt 16 fails, 14 has a patch
|
||||||
|
llvmPackages = final.llvmPackages_14;
|
||||||
|
})
|
||||||
|
];
|
||||||
|
})
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Reference in a new issue