Commit 4218388b authored by Alén Arias Vázquez's avatar Alén Arias Vázquez 😎

merge with master

parents dfe01116 c15c7481
Pipeline #3744 passed with stages
in 116 minutes and 37 seconds
......@@ -52,6 +52,15 @@ ifeq (,$(filter $(SB_VER),1 2))
$(error SB_VER=$(SB_VER) not supported)
endif
GIT_VER = $(shell git describe --always)
GIT_USR = $(shell git config --get user.name)
# if user.name is not available from git use user@hostname
ifeq ($(GIT_USR),)
GIT_USR = $(shell whoami)@$(shell hostname)
endif
# create _done directory
$(shell mkdir -p _done)
$(shell mkdir -p build)
......@@ -560,7 +569,8 @@ rootfs_prepare: $(PETALINUX_CONFIG_BIN)
rootfs_build: rootfs_prepare $(PETALINUX_BUILD_BIN)
$(VT)echo -e "$(CO)Building rootfs...$(NC)" $(LOGT)
# compile rootfs
$(V) export SB_VER=$(SB_VER); export BB_ENV_EXTRAWHITE="$$BB_ENV_EXTRAWHITE SB_VER";\
$(V) export GIT_VER="$(GIT_VER)"; export GIT_USR="$(GIT_USR)"; export SB_VER=$(SB_VER); \
export BB_ENV_EXTRAWHITE="$$BB_ENV_EXTRAWHITE SB_VER GIT_VER GIT_USR"; \
cd "$(ROOTFS_DIR)" && petalinux-build -c rootfs $(LOG)
$(VT)echo -e "$(CO)Building rootfs... done$(NC)" $(LOGT)
$(V) echo `date` > _done/$@ $(LOG)
......
......@@ -106,14 +106,14 @@
"update_kernel_qspi_from_sd= echo Updating ${kernel_img} in QSPI from microSD; setenv psize ${qspi_kernelsize}; run load_kernel_from_sd test_img install_kernel_to_qspi\0" \
"update_kernel_emmc_from_sd= echo Updating ${kernel_img} in eMMC from microSD; run load_kernel_from_sd install_kernel_to_emmc\0" \
/* Try to fetch ${bootfile} image. First try to run it as a script, if fails then as regular image. */ \
"boot_dhcp_script_and_boot=echo Try to fetch ${bootfile} pointed by DHCP from network...; run test_ip && run load_kernel_from_dhcp && echo Try as script...; && source ${clobstart} || echo Try as image...; && bootm ${clobstart}\0" \
"boot_dhcp_script_and_boot=echo Try to fetch ${bootfile} pointed by DHCP from network...; run test_ip && run load_kernel_from_dhcp && echo Try as script...; && setenv uimage_source \"dhcp script\";&& source ${clobstart} || echo Try as image...; && setenv uimage_source \"dhcp image\"; && bootm ${clobstart}\0" \
/* Try to fetch ${kernel_img} image. First try to run it as a script, if fails then as regular image. */ \
"boot_net_script_and_boot=echo Try to fetch ${kernel_img} from network...; run test_ip && run load_kernel_from_net && echo Try as script...; && source ${clobstart} || echo Try as image...; && bootm ${clobstart}\0" \
"boot_net_script_and_boot=echo Try to fetch ${kernel_img} from network...; run test_ip && run load_kernel_from_net && echo Try as script...; && setenv uimage_source \"network script\"; && source ${clobstart} || echo Try as image...; && setenv uimage_source \"network image\"; && bootm ${clobstart}\0" \
"boot_net_script=echo Try to boot from network script...; run load_kernel_from_net && source ${clobstart}\0" \
"boot_net= echo Try to boot from network...; run load_kernel_from_net && bootm ${clobstart}\0" \
"boot_sd= echo Try to boot from microSD...; run load_kernel_from_sd && bootm ${clobstart}\0" \
"boot_emmc= echo Try to boot from eMMC...; run load_kernel_from_emmc && bootm ${clobstart}\0" \
"boot_qspi= echo Try to boot from QSPI...; run load_kernel_from_qspi && bootm ${clobstart}\0" \
"boot_sd= echo Try to boot from microSD...; run load_kernel_from_sd && setenv uimage_source \"microSD\"; && bootm ${clobstart}\0" \
"boot_emmc= echo Try to boot from eMMC...; run load_kernel_from_emmc && setenv uimage_source \"emmc\"; &&bootm ${clobstart}\0" \
"boot_qspi= echo Try to boot from QSPI...; run load_kernel_from_qspi && setenv uimage_source \"qspi\"; &&bootm ${clobstart}\0" \
"default_bootcmd=echo Executing default boot script; run uenvboot; run boot_dhcp_script_and_boot || run boot_net_script_and_boot || run boot_sd || run boot_emmc || run boot_qspi || echo Giving up. No image found! Reset...; || sleep 3 && reset\0" \
""
......
From c3e066aa06ad29841de63fe58d173e7f500229d7 Mon Sep 17 00:00:00 2001
From ae587d0fba972f5a491e4cb46aa91f2816dc016f Mon Sep 17 00:00:00 2001
From: Adam Wujek <dev_public@wujek.eu>
Date: Wed, 20 Oct 2021 22:54:23 +0200
Subject: [PATCH] hwmon: (pmbus) Add Hartmann PSU driver
Add support for D575.00520 Power Supply Unit
Add support for Hartmann D575.00520 Power Supply Unit
300W cPCI Serial power supply, 3U, AC/DC, 8 HP wide
Signed-off-by: Adam Wujek <dev_public@wujek.eu>
---
drivers/hwmon/pmbus/Kconfig | 9 ++
drivers/hwmon/pmbus/Makefile | 1 +
drivers/hwmon/pmbus/hartmann_psu.c | 148 +++++++++++++++++++++++++++++
3 files changed, 158 insertions(+)
drivers/hwmon/pmbus/hartmann_psu.c | 158 +++++++++++++++++++++++++++++
3 files changed, 168 insertions(+)
create mode 100644 drivers/hwmon/pmbus/hartmann_psu.c
diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig
......@@ -48,10 +48,10 @@ index 73b6424b6553..10fb78c7341e 100644
obj-$(CONFIG_SENSORS_IRPS5401) += irps5401.o
diff --git a/drivers/hwmon/pmbus/hartmann_psu.c b/drivers/hwmon/pmbus/hartmann_psu.c
new file mode 100644
index 000000000000..0515ef47af5d
index 000000000000..c8585730f079
--- /dev/null
+++ b/drivers/hwmon/pmbus/hartmann_psu.c
@@ -0,0 +1,148 @@
@@ -0,0 +1,158 @@
+/*
+ * Hardware monitoring driver for Hartmann PSU
+ *
......@@ -80,35 +80,42 @@ index 000000000000..0515ef47af5d
+#define LINEAR11_EXPONENT_SHIFT 11
+#define LINEAR11_EXPONENT_SHIFTED_MASK 0x1F
+
+/* NOTE: Values PMBUS_VOUT_OV_FAULT_LIMIT, PMBUS_VOUT_UV_FAULT_LIMIT,
+/*
+ * NOTE: Values PMBUS_VOUT_OV_FAULT_LIMIT, PMBUS_VOUT_UV_FAULT_LIMIT,
+ * PMBUS_VOUT_OV_WARN_LIMIT, PMBUS_VOUT_UV_WARN_LIMIT and PMBUS_READ_VOUT
+ * reported by this PSU are in format linear11 not linear16. As today kernel
+ * expects them to be in linear16, so convert.
+ * PSU does not report PMBUS_VOUT_MODE value. So fill it with exponent part
+ * from PMBUS_READ_VOUT. It is assumed that exponent does not change over time.
+ * */
+ */
+static int hartmann_read_byte_data(struct i2c_client *client, int page, int reg)
+{
+ int ret;
+
+ switch (reg) {
+ case PMBUS_VOUT_MODE:
+ /* For this PSU VOUT values are returned as linear11, while
+ * the kernel expects them to be linear16 */
+ /*
+ * For this PSU the VOUT value is returned as linear11, while
+ * the kernel expects them to be linear16.
+ */
+ ret = pmbus_read_byte_data(client, page, reg);
+ if (ret >= 0) {
+ /* If valid PMBUS_VOUT_MODE is available, return it */
+ return ret;
+ }
+
+ /* Failed to read VOUT_MODE */
+ /* Assume that exponent does not change */
+
+ /*
+ * Failed to read VOUT_MODE.
+ * Assume the exponent does not change.
+ */
+ ret = pmbus_read_word_data(client, page, PMBUS_READ_VOUT);
+ if (ret < 0)
+ return ret;
+
+ /* Take exponent part from PMBUS_READ_VOUT and return it as
+ * a part of PMBUS_VOUT_MODE */
+ /*
+ * Take exponent part from PMBUS_READ_VOUT and return it as
+ * a part of PMBUS_VOUT_MODE
+ */
+ ret = ((int16_t) ret) >> LINEAR11_EXPONENT_SHIFT;
+ ret &= LINEAR11_EXPONENT_SHIFTED_MASK;
+ /* PB_VOUT_MODE_LINEAR is 0 anyway */
......@@ -138,10 +145,12 @@ index 000000000000..0515ef47af5d
+ if (val < 0)
+ return val;
+
+ ret = pmbus_read_byte_data(client, page, PMBUS_READ_VOUT);
+ ret = pmbus_read_byte_data(client, page, PMBUS_VOUT_MODE);
+ if (ret >= 0) {
+ /* If an valid PMBUS_VOUT_MODE is available,
+ * return PMBUS_READ_VOUT as is (probably linear16) */
+ /*
+ * If a valid PMBUS_VOUT_MODE is available,
+ * return PMBUS_READ_VOUT as is (probably linear16)
+ */
+ return val;
+ }
+
......@@ -167,8 +176,10 @@ index 000000000000..0515ef47af5d
+ .func[0] = HARTMANN_SW_FUNC,
+ .read_word_data = hartmann_read_word_data,
+ .read_byte_data = hartmann_read_byte_data,
+ /* linear11, kernel does not support it, so convert in
+ * hartmann_read_word_data and hartmann_read_byte_data */
+ /*
+ * linear11, kernel does not support it, so convert in
+ * hartmann_read_word_data and hartmann_read_byte_data
+ */
+ .format[PSC_VOLTAGE_OUT] = linear,
+};
+
......@@ -185,7 +196,6 @@ index 000000000000..0515ef47af5d
+
+MODULE_DEVICE_TABLE(i2c, hartmann_psu_id);
+
+/* This is the driver that will be inserted */
+static struct i2c_driver hartmann_psu_driver = {
+ .driver = {
+ .name = "hartmann-psu",
......
......@@ -77,8 +77,8 @@ index 000000000000..fb3674492936
+
+#define MONIMOD_FUNC_0 (PMBUS_HAVE_VOUT | PMBUS_HAVE_IOUT | \
+ PMBUS_HAVE_TEMP | \
+ PMBUS_HAVE_FAN12 | PMBUS_HAVE_STATUS_FAN12 | \
+ PMBUS_HAVE_FAN34 | PMBUS_HAVE_STATUS_FAN34)
+ PMBUS_HAVE_FAN12 | \
+ PMBUS_HAVE_FAN34)
+#define MONIMOD_FUNC_1 (PMBUS_HAVE_VOUT | PMBUS_HAVE_IOUT)
+#define MONIMOD_FUNC_2 (PMBUS_HAVE_IOUT)
+
......
From e5befc024cb4515d815662ed8746712cc5366bfc Mon Sep 17 00:00:00 2001
From: Eddie James <eajames@linux.ibm.com>
Date: Tue, 22 Dec 2020 09:26:39 -0600
Subject: [PATCH] hwmon: (pmbus) Add a PMBUS_NO_CAPABILITY platform data flag
Some PMBus chips don't respond with valid data when reading the
CAPABILITY register. Add a flag that device drivers can set so
that the PMBus core driver doesn't use CAPABILITY to determine it's
behavior.
Signed-off-by: Eddie James <eajames@linux.ibm.com>
Link: https://lore.kernel.org/r/20201222152640.27749-2-eajames@linux.ibm.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
drivers/hwmon/pmbus/pmbus_core.c | 8 +++++---
include/linux/pmbus.h | 9 +++++++++
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 192442b3b7a2..906c9fec9cce 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -2204,9 +2204,11 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data,
}
/* Enable PEC if the controller supports it */
- ret = i2c_smbus_read_byte_data(client, PMBUS_CAPABILITY);
- if (ret >= 0 && (ret & PB_CAPABILITY_ERROR_CHECK))
- client->flags |= I2C_CLIENT_PEC;
+ if (!(data->flags & PMBUS_NO_CAPABILITY)) {
+ ret = i2c_smbus_read_byte_data(client, PMBUS_CAPABILITY);
+ if (ret >= 0 && (ret & PB_CAPABILITY_ERROR_CHECK))
+ client->flags |= I2C_CLIENT_PEC;
+ }
pmbus_clear_faults(client);
diff --git a/include/linux/pmbus.h b/include/linux/pmbus.h
index ee3c2aba2a8e..a747057a095f 100644
--- a/include/linux/pmbus.h
+++ b/include/linux/pmbus.h
@@ -38,6 +38,15 @@
*/
#define PMBUS_SKIP_STATUS_CHECK (1 << 0)
+/*
+ * PMBUS_NO_CAPABILITY
+ *
+ * Some PMBus chips don't respond with valid data when reading the CAPABILITY
+ * register. For such chips, this flag should be set so that the PMBus core
+ * driver doesn't use CAPABILITY to determine it's behavior.
+ */
+#define PMBUS_NO_CAPABILITY BIT(2)
+
struct pmbus_platform_data {
u32 flags; /* Device specific flags */
--
2.17.1
From 5f7e74288c8ea8dedefeb3d443168f95d1ea252e Mon Sep 17 00:00:00 2001
From: Adam Wujek <dev_public@wujek.eu>
Date: Wed, 20 Apr 2022 00:48:05 +0200
Subject: [PATCH] hwmon: (hartmann_psu) ignore the content of CAPABILITY
register
Hartmann PSU returns the wrong value of CAPABILITY (0x1f) register.
It returns 0xff, which include the support for PEC, which is not true
at least for some registers like 0x9A-0x9E.
Signed-off-by: Adam Wujek <dev_public@wujek.eu>
---
drivers/hwmon/pmbus/hartmann_psu.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/hwmon/pmbus/hartmann_psu.c b/drivers/hwmon/pmbus/hartmann_psu.c
index 0515ef47af5d..439d63afa342 100644
--- a/drivers/hwmon/pmbus/hartmann_psu.c
+++ b/drivers/hwmon/pmbus/hartmann_psu.c
@@ -20,6 +20,7 @@
#include <linux/init.h>
#include <linux/err.h>
#include <linux/i2c.h>
+#include <linux/pmbus.h>
#include "pmbus.h"
#define LINEAR11_MANTISSA_MASK 0x7FF
@@ -118,9 +119,14 @@ static struct pmbus_driver_info hartmann_psu_info = {
.format[PSC_VOLTAGE_OUT] = linear,
};
+static struct pmbus_platform_data hartmann_psu_pdata = {
+ .flags = PMBUS_NO_CAPABILITY,
+};
+
static int hartmann_psu_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
+ client->dev.platform_data = &hartmann_psu_pdata;
return pmbus_do_probe(client, id, &hartmann_psu_info);
}
--
2.17.1
From de289a48724f90476146549751049edf1d255853 Mon Sep 17 00:00:00 2001
From: Adam Wujek <dev_public@wujek.eu>
Date: Wed, 20 Apr 2022 00:40:03 +0200
Subject: [PATCH] hwmod: (pmbus) disable PEC if not enabled
Explicitly disable PEC when the client does not support it.
Without the explicit disable, when the device with the PEC support is
removed later when a device without PEC support is inserted into the same
address, the driver uses the old value of client->flags which contains
the I2C_CLIENT_PEC flag. As a consequence the PEC is used when it should
not be used.
Signed-off-by: Adam Wujek <dev_public@wujek.eu>
---
drivers/hwmon/pmbus/pmbus_core.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 8db4f0c8b099..30e7facd97db 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -2010,6 +2010,9 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data,
data->has_status_word = true;
}
+ /* Make sure PEC is disabled, will be enabled later if needed */
+ client->flags &= ~I2C_CLIENT_PEC;
+
/* Enable PEC if the controller supports it */
if (!(data->flags & PMBUS_NO_CAPABILITY)) {
ret = i2c_smbus_read_byte_data(client, PMBUS_CAPABILITY);
--
2.17.1
From 4c95a7eeeb7a38bfd37dade15e9decc9fadf08f9 Mon Sep 17 00:00:00 2001
From: Adam Wujek <dev_public@wujek.eu>
Date: Thu, 19 May 2022 04:10:33 +0200
Subject: [PATCH] hwmon: (pmbus) Check PEC support before reading other
registers
Make sure that the support of PEC is determined before the read of other
registers. Otherwise the validation of PEC can trigger an error on the read
of STATUS_BYTE.
The problematic scenario is the following. A device with enabled PEC
support is up and running and a kernel driver is loaded.
Then the driver is unloaded (or device unbound), the HW device
is reconfigured externally (e.g. by i2cset) to advertise itself as not
supporting PEC. Without the move of the code, at the second load of
the driver (or bind) the status byte or word register is always read with
PEC enabled, which is likely to cause a read error resulting with fail of
a driver load (or bind).
Signed-off-by: Adam Wujek <dev_public@wujek.eu>
---
drivers/hwmon/pmbus/pmbus_core.c | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 30e7facd97db..947d3fa41373 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -1992,6 +1992,19 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data,
struct device *dev = &client->dev;
int page, ret;
+ /*
+ * Figure out if PEC is enabled before accessing any other register.
+ * Make sure PEC is disabled, will be enabled later if needed.
+ */
+ client->flags &= ~I2C_CLIENT_PEC;
+
+ /* Enable PEC if the controller supports it */
+ if (!(data->flags & PMBUS_NO_CAPABILITY)) {
+ ret = i2c_smbus_read_byte_data(client, PMBUS_CAPABILITY);
+ if (ret >= 0 && (ret & PB_CAPABILITY_ERROR_CHECK))
+ client->flags |= I2C_CLIENT_PEC;
+ }
+
/*
* Some PMBus chips don't support PMBUS_STATUS_WORD, so try
* to use PMBUS_STATUS_BYTE instead if that is the case.
@@ -2010,15 +2023,6 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data,
data->has_status_word = true;
}
- /* Make sure PEC is disabled, will be enabled later if needed */
- client->flags &= ~I2C_CLIENT_PEC;
-
- /* Enable PEC if the controller supports it */
- if (!(data->flags & PMBUS_NO_CAPABILITY)) {
- ret = i2c_smbus_read_byte_data(client, PMBUS_CAPABILITY);
- if (ret >= 0 && (ret & PB_CAPABILITY_ERROR_CHECK))
- client->flags |= I2C_CLIENT_PEC;
- }
pmbus_clear_faults(client);
--
2.17.1
From 26d8934faf2f84485f3739285897a2284f83f3bc Mon Sep 17 00:00:00 2001
From: Adam Wujek <dev_public@wujek.eu>
Date: Thu, 19 May 2022 04:03:02 +0200
Subject: [PATCH] i2c: busses: i2c-cadence: fix message length when receive
block message
Needed by hwmon/pmbus_core driver to calculate PEC correctly.
The hwmon/pmbus_core driver relies on bus drivers to update the message
length of receive block transfers. Only in this type of smbus transfer
the length is not known before the transfer is started.
Signed-off-by: Adam Wujek <dev_public@wujek.eu>
---
drivers/i2c/busses/i2c-cadence.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
index 20ac432a37ea..677082e1b233 100644
--- a/drivers/i2c/busses/i2c-cadence.c
+++ b/drivers/i2c/busses/i2c-cadence.c
@@ -830,6 +830,13 @@ static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg,
return -ETIMEDOUT;
}
+ /*
+ * Update message len, as i2c/smbus driver (function
+ * i2c_smbus_xfer_emulated) relies on i2c device drivers to do this.
+ */
+ if ((msg->flags & I2C_M_RECV_LEN) && (msg->flags & I2C_M_RD))
+ msg->len = msg->buf[0] + 2; /* add len byte + PEC byte */
+
cdns_i2c_writereg(CDNS_I2C_IXR_ALL_INTR_MASK,
CDNS_I2C_IDR_OFFSET);
--
2.17.1
From 10a4735ad1f7af3e89ea33aa66a450df1efe7e70 Mon Sep 17 00:00:00 2001
From: Adam Wujek <dev_public@wujek.eu>
Date: Thu, 19 May 2022 13:55:14 +0200
Subject: [PATCH] hwmod: (pmbus) add a function to check the presence of a
block register
Other functions (like pmbus_check_byte_register) cannot be used to check
the presence of a block register, because it will generate error when PEC
is used.
Signed-off-by: Adam Wujek <dev_public@wujek.eu>
---
drivers/hwmon/pmbus/pmbus_core.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 947d3fa41373..f0697271a604 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -394,6 +394,19 @@ int pmbus_update_byte_data(struct i2c_client *client, int page, u8 reg,
}
EXPORT_SYMBOL_GPL(pmbus_update_byte_data);
+static int pmbus_read_block_data(struct i2c_client *client, int page, u8 reg,
+ char *data_buf)
+{
+ int rv;
+
+ rv = pmbus_set_page(client, page);
+ if (rv < 0)
+ return rv;
+
+ return i2c_smbus_read_block_data(client, reg, data_buf);
+}
+
+
/*
* _pmbus_read_byte_data() is similar to pmbus_read_byte_data(), but checks if
* a device specific mapping function exists and calls it if necessary.
@@ -547,6 +560,20 @@ bool pmbus_check_word_register(struct i2c_client *client, int page, int reg)
}
EXPORT_SYMBOL_GPL(pmbus_check_word_register);
+static bool pmbus_check_block_register(struct i2c_client *client, int page,
+ int reg)
+{
+ int rv;
+ struct pmbus_data *data = i2c_get_clientdata(client);
+ char data_buf[I2C_SMBUS_BLOCK_MAX + 2];
+
+ rv = pmbus_read_block_data(client, page, reg, data_buf);
+ if (rv >= 0 && !(data->flags & PMBUS_SKIP_STATUS_CHECK))
+ rv = pmbus_check_status_cml(client);
+ pmbus_clear_fault_page(client, -1);
+ return rv >= 0;
+}
+
const struct pmbus_driver_info *pmbus_get_driver_info(struct i2c_client *client)
{
struct pmbus_data *data = i2c_get_clientdata(client);
--
2.17.1
From 017094babf4a5dbf0c70a0bfe2268c2e66403132 Mon Sep 17 00:00:00 2001
From: Adam Wujek <dev_public@wujek.eu>
Date: Tue, 19 Apr 2022 19:34:19 +0200
Subject: [PATCH] hwmon: (pmbus) add MFR_* registers to debugfs
Add registers to debugfs:
PMBUS_MFR_ID
PMBUS_MFR_MODEL
PMBUS_MFR_REVISION
PMBUS_MFR_LOCATION
PMBUS_MFR_DATE
PMBUS_MFR_SERIAL
Please note that it is assumed that values of these registers are the same
for all pages. To reduce the number of debugfs entries, only values from
page 0 are reported.
Signed-off-by: Adam Wujek <dev_public@wujek.eu>
---
drivers/hwmon/pmbus/pmbus_core.c | 101 ++++++++++++++++++++++++++++++-
1 file changed, 99 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index f0697271a604..9eb03fe590f2 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -2192,6 +2192,35 @@ static int pmbus_debugfs_get_status(void *data, u64 *val)
DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops_status, pmbus_debugfs_get_status,
NULL, "0x%04llx\n");
+
+static ssize_t pmbus_debugfs_mfr_read(struct file *file, char __user *buf,
+ size_t count, loff_t *ppos)
+{
+ int rc;
+ struct pmbus_debugfs_entry *entry = file->private_data;
+ char data[I2C_SMBUS_BLOCK_MAX + 2] = { 0 };
+
+ rc = pmbus_read_block_data(entry->client, entry->page, entry->reg,
+ data);
+ if (rc < 0)
+ return rc;
+
+ /* Add newline at the end of a read data */
+ data[rc] = '\n';
+
+ /* Include newline into the length */
+ rc += 1;
+
+ return simple_read_from_buffer(buf, count, ppos, data, rc);
+}
+
+static const struct file_operations pmbus_debugfs_ops_mfr = {
+ .llseek = noop_llseek,
+ .read = pmbus_debugfs_mfr_read,
+ .write = NULL,
+ .open = simple_open,
+};
+
static int pmbus_init_debugfs(struct i2c_client *client,
struct pmbus_data *data)
{
@@ -2213,13 +2242,80 @@ static int pmbus_init_debugfs(struct i2c_client *client,
return -ENODEV;
}
- /* Allocate the max possible entries we need. */
+ /*
+ * Allocate the max possible entries we need.
+ * 6 entries device-specific
+ * 10 entries page-specific
+ */
entries = devm_kcalloc(data->dev,
- data->info->pages * 10, sizeof(*entries),
+ data->info->pages * 10 + 6, sizeof(*entries),
GFP_KERNEL);
if (!entries)
return -ENOMEM;
+ /*
+ * Add device-specific entries.
+ * Please note that the PMBUS standard allows all registers to be
+ * page-specific.
+ * To reduce the number of debugfs entries for devices with many
+ * pages assume that values of the following registers are the same
+ * for all pages and report values only for page 0.
+ */
+ if (pmbus_check_block_register(client, 0, PMBUS_MFR_ID)) {
+ entries[idx].client = client;
+ entries[idx].page = 0;
+ entries[idx].reg = PMBUS_MFR_ID;
+ debugfs_create_file("mfr_id", 0444, data->debugfs,
+ &entries[idx++],
+ &pmbus_debugfs_ops_mfr);
+ }
+
+ if (pmbus_check_block_register(client, 0, PMBUS_MFR_MODEL)) {
+ entries[idx].client = client;
+ entries[idx].page = 0;
+ entries[idx].reg = PMBUS_MFR_MODEL;
+ debugfs_create_file("mfr_model", 0444, data->debugfs,
+ &entries[idx++],
+ &pmbus_debugfs_ops_mfr);
+ }
+
+ if (pmbus_check_block_register(client, 0, PMBUS_MFR_REVISION)) {
+ entries[idx].client = client;
+ entries[idx].page = 0;
+ entries[idx].reg = PMBUS_MFR_REVISION;
+ debugfs_create_file("mfr_revision", 0444, data->debugfs,
+ &entries[idx++],
+ &pmbus_debugfs_ops_mfr);
+ }
+
+ if (pmbus_check_block_register(client, 0, PMBUS_MFR_LOCATION)) {
+ entries[idx].client = client;
+ entries[idx].page = 0;
+ entries[idx].reg = PMBUS_MFR_LOCATION;
+ debugfs_create_file("mfr_location", 0444, data->debugfs,
+ &entries[idx++],
+ &pmbus_debugfs_ops_mfr);
+ }
+
+ if (pmbus_check_block_register(client, 0, PMBUS_MFR_DATE)) {
+ entries[idx].client = client;
+ entries[idx].page = 0;
+ entries[idx].reg = PMBUS_MFR_DATE;
+ debugfs_create_file("mfr_date", 0444, data->debugfs,
+ &entries[idx++],
+ &pmbus_debugfs_ops_mfr);
+ }
+
+ if (pmbus_check_block_register(client, 0, PMBUS_MFR_SERIAL)) {
+ entries[idx].client = client;
+ entries[idx].page = 0;
+ entries[idx].reg = PMBUS_MFR_SERIAL;
+ debugfs_create_file("mfr_serial", 0444, data->debugfs,
+ &entries[idx++],
+ &pmbus_debugfs_ops_mfr);
+ }
+
+ /* Add page specific entries */
for (i = 0; i < data->info->pages; ++i) {
/* Check accessibility of status register if it's not page 0 */
if (!i || pmbus_check_status_register(client, i)) {
@@ -2322,6 +2418,7 @@ static int pmbus_init_debugfs(struct i2c_client *client,
&entries[idx++],
&pmbus_debugfs_ops);
}
+
}
return 0;
--
2.17.1
From df8b1139cdcf622087735d00402783ea1f03888d Mon Sep 17 00:00:00 2001
From: Adam Wujek <dev_public@wujek.eu>
Date: Tue, 19 Apr 2022 19:52:58 +0200
Subject: [PATCH] hwmon: (pmbus) add PMBUS_IC_DEVICE_REV register to
debugfs
Add PMBUS_IC_DEVICE_REV register to debugfs
Signed-off-by: Adam Wujek <dev_public@wujek.eu>
---
drivers/hwmon/pmbus/pmbus.h | 2 ++
drivers/hwmon/pmbus/pmbus_core.c | 11 ++++++++++-
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/drivers/hwmon/pmbus/pmbus.h b/drivers/hwmon/pmbus/pmbus.h
index 1d24397d36ec..baadf61d4f87 100644
--- a/drivers/hwmon/pmbus/pmbus.h
+++ b/drivers/hwmon/pmbus/pmbus.h
@@ -130,6 +130,8 @@ enum pmbus_regs {
PMBUS_MFR_DATE = 0x9D,
PMBUS_MFR_SERIAL = 0x9E,
+ PMBUS_IC_DEVICE_REV = 0xAE,
+
/*
* Virtual registers.
* Useful to support attributes which are not supported by standard PMBus
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 9eb03fe590f2..21ceaae869b0 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -2248,7 +2248,7 @@ static int pmbus_init_debugfs(struct i2c_client *client,
* 10 entries page-specific
*/
entries = devm_kcalloc(data->dev,
- data->info->pages * 10 + 6, sizeof(*entries),
+ data->info->pages * 10 + 7, sizeof(*entries),
GFP_KERNEL);
if (!entries)
return -ENOMEM;
@@ -2315,6 +2315,15 @@ static int pmbus_init_debugfs(struct i2c_client *client,
&pmbus_debugfs_ops_mfr);
}
+ if (pmbus_check_block_register(client, 0, PMBUS_IC_DEVICE_REV)) {
+ entries[idx].client = client;
+ entries[idx].page = 0;
+ entries[idx].reg = PMBUS_IC_DEVICE_REV;
+ debugfs_create_file("ic_device_rev", 0444, data->debugfs,
+ &entries[idx++],
+ &pmbus_debugfs_ops_mfr);
+ }
+
/* Add page specific entries */
for (i = 0; i < data->info->pages; ++i) {
/* Check accessibility of status register if it's not page 0 */
--
2.17.1
From a4a2c0fde5aa5286d574046e09f4179c4e716510 Mon Sep 17 00:00:00 2001
From: Adam Wujek <dev_public@wujek.eu>
Date: Fri, 29 Apr 2022 02:44:39 +0200
Subject: [PATCH] hwmon: (monimod) add 4 debugfs registers
added:
BOOT_NEW_FW
UPTIME_SECS
TMR_ERROR_CNT
USE_PEC
Signed-off-by: Adam Wujek <dev_public@wujek.eu>
---
drivers/hwmon/pmbus/monimod.c | 160 +++++++++++++++++++++++++++++++++-
1 file changed, 158 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/pmbus/monimod.c b/drivers/hwmon/pmbus/monimod.c
index 15f95dd4488c..2d9fef5c5300 100644
--- a/drivers/hwmon/pmbus/monimod.c
+++ b/drivers/hwmon/pmbus/monimod.c
@@ -2,7 +2,7 @@
* Hardware monitoring driver for Monimod FANTRAY
*
* Author: Adam Wujek
- * Copyright (c) 2021 CERN
+ * Copyright (c) 2021-2022 CERN
*
* 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
@@ -20,8 +20,17 @@
#include <linux/init.h>
#include <linux/err.h>
#include <linux/i2c.h>
+#include <linux/debugfs.h>
#include "pmbus.h"
+#define MONIMOD_FW_TYPE_BOOTLOADER 1
+#define MONIMOD_FW_TYPE_MAIN 2
+
+#define MONIMOD_REG_BOOT_NEW_FW 0xD5
+#define MONIMOD_REG_UPTIME_SECS 0xD7
+#define MONIMOD_REG_TMR_ERROR_CNT 0xD8
+#define MONIMOD_REG_USE_PEC 0xD9
+
#define MONIMOD_FUNC_0 (PMBUS_HAVE_VOUT | PMBUS_HAVE_IOUT | \
PMBUS_HAVE_TEMP | \
PMBUS_HAVE_FAN12 | \
@@ -29,6 +38,11 @@
#define MONIMOD_FUNC_1 (PMBUS_HAVE_VOUT | PMBUS_HAVE_IOUT)
#define MONIMOD_FUNC_2 (PMBUS_HAVE_IOUT)
+struct pmbus_debugfs_entry {
+ struct i2c_client *client;
+ u8 reg;
+};
+
static struct pmbus_driver_info monimod_info = {
.pages = 3,
.func[0] = MONIMOD_FUNC_0,
@@ -37,10 +51,24 @@ static struct pmbus_driver_info monimod_info = {
.format[PSC_VOLTAGE_OUT] = linear,
};
+static int monimod_debugfs(struct i2c_client *client);
+
+
static int monimod_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
- return pmbus_do_probe(client, id, &monimod_info);
+ int ret;
+ int probe_ret;
+
+ probe_ret = pmbus_do_probe(client, id, &monimod_info);
+ if (probe_ret < 0)
+ return probe_ret;
+
+ ret = monimod_debugfs(client);
+ if (ret)
+ dev_warn(&client->dev, "Failed to register debugfs\n");
+
+ return probe_ret;
}
static const struct i2c_device_id monimod_id[] = {
@@ -62,6 +90,134 @@ static struct i2c_driver monimod_driver = {
module_i2c_driver(monimod_driver);
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+static int monimod_debugfs_get_byte(void *data, u64 *val)
+{
+ int rc;
+ struct pmbus_debugfs_entry *entry = data;
+
+ rc = pmbus_read_byte_data(entry->client, 0, entry->reg);
+ if (rc < 0)
+ return rc;
+
+ *val = rc;
+
+ return 0;
+}
+DEFINE_DEBUGFS_ATTRIBUTE(monimod_debugfs_ops_get_byte, monimod_debugfs_get_byte,
+ NULL, "%llx\n");
+
+
+static int monimod_debugfs_get_dword(void *data, u64 *val)
+{
+ int rc;
+ struct pmbus_debugfs_entry *entry = data;
+ u8 tmp[4];
+
+ rc = i2c_smbus_read_i2c_block_data(entry->client, entry->reg,
+ sizeof(tmp), tmp);
+ if (rc < 0)
+ return rc;
+
+ *val = tmp[0] | tmp[1] << 8 | tmp[2] << 16 | tmp[3] << 24;
+
+ return 0;
+}
+DEFINE_DEBUGFS_ATTRIBUTE(monimod_debugfs_ops_get_dword,
+ monimod_debugfs_get_dword, NULL, "%lld\n");
+
+static ssize_t monimod_debugfs_get_fw_type(struct file *file, char __user *buf,
+ size_t count, loff_t *ppos)
+{
+ int rc;
+ struct pmbus_debugfs_entry *entry = file->private_data;
+ char *data = NULL;
+
+ rc = pmbus_read_byte_data(entry->client, 0, entry->reg);
+ if (rc < 0)
+ return rc;
+
+ switch (rc) {
+ case MONIMOD_FW_TYPE_BOOTLOADER:
+ data = "bootloader\n";
+ break;
+ case MONIMOD_FW_TYPE_MAIN:
+ data = "main_fw\n";
+ break;
+
+ default:
+ break;
+ }
+
+ return simple_read_from_buffer(buf, count, ppos, data, strlen(data));
+}
+
+static const struct file_operations monimod_debugfs_ops_get_fw_type = {
+ .llseek = noop_llseek,
+ .read = monimod_debugfs_get_fw_type,
+ .write = NULL,
+ .open = simple_open,
+};
+
+static int monimod_debugfs(struct i2c_client *client)
+{
+ struct dentry *debugfs;
+ struct dentry *monimod_dir;
+ struct pmbus_debugfs_entry *entries;
+ int idx = 0;
+
+ debugfs = pmbus_get_debugfs_dir(client);
+ monimod_dir = debugfs_create_dir("monimod", debugfs);
+ if (IS_ERR_OR_NULL(monimod_dir)) {
+ monimod_dir = NULL;
+ return -ENODEV;
+ }
+
+ /* Allocate the max possible entries we need. */
+ entries = devm_kcalloc(&client->dev,
+ 3, sizeof(*entries),
+ GFP_KERNEL);
+ if (!entries)
+ return -ENOMEM;
+
+ /* Create debugfs entry for fw_type */
+ entries[idx].client = client;
+ entries[idx].reg = MONIMOD_REG_BOOT_NEW_FW;
+ debugfs_create_file("fw_type", 0444, monimod_dir,
+ &entries[idx++],
+ &monimod_debugfs_ops_get_fw_type);
+
+ /* Create debugfs entry for uptime_secs */
+ entries[idx].client = client;
+ entries[idx].reg = MONIMOD_REG_UPTIME_SECS;
+ debugfs_create_file("uptime_secs", 0444, monimod_dir,
+ &entries[idx++],
+ &monimod_debugfs_ops_get_dword);
+
+ /* Create debugfs entry for tmr_error_cnt */
+ entries[idx].client = client;
+ entries[idx].reg = MONIMOD_REG_TMR_ERROR_CNT;
+ debugfs_create_file("tmr_error_cnt", 0444, monimod_dir,
+ &entries[idx++],
+ &monimod_debugfs_ops_get_dword);
+
+ /* Create debugfs entry for use_pec */
+ entries[idx].client = client;
+ entries[idx].reg = MONIMOD_REG_USE_PEC;
+ debugfs_create_file("use_pec", 0444, monimod_dir,
+ &entries[idx++],
+ &monimod_debugfs_ops_get_byte);
+
+ return 0;
+}
+#else
+static int monimod_debugfs(struct i2c_client *client)
+{
+ return 0;
+}
+#endif /* IS_ENABLED(CONFIG_DEBUG_FS) */
+
+
MODULE_AUTHOR("Adam Wujek");
MODULE_DESCRIPTION("PMBus driver for monimod");
MODULE_LICENSE("GPL");
--
2.17.1
From 830814154f26ec938d9a11ed39fd2c423fddf688 Mon Sep 17 00:00:00 2001
From: Adam Wujek <dev_public@wujek.eu>
Date: Wed, 6 Apr 2022 00:24:33 +0200
Subject: [PATCH] fdt_support: add modeboot, uimage_source and reset_reason to
FDT
Under /chosen
modeboot and reset_reason are filled by a uboot automatically.
Signed-off-by: Adam Wujek <dev_public@wujek.eu>
---
common/fdt_support.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/common/fdt_support.c b/common/fdt_support.c
index 3440e42a25..2b3f811bbd 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -299,6 +299,39 @@ int fdt_chosen(void *fdt)
}
}
+ str = env_get("modeboot");
+ if (str) {
+ err = fdt_setprop(fdt, nodeoffset, "modeboot", str,
+ strlen(str) + 1);
+ if (err < 0) {
+ printf("WARNING: could not set modeboot %s.\n",
+ fdt_strerror(err));
+ return err;
+ }
+ }
+
+ str = env_get("uimage_source");
+ if (str) {
+ err = fdt_setprop(fdt, nodeoffset, "uimage_source", str,
+ strlen(str) + 1);
+ if (err < 0) {
+ printf("WARNING: could not set uimage_source %s.\n",
+ fdt_strerror(err));
+ return err;
+ }
+ }
+
+ str = env_get("reset_reason");
+ if (str) {
+ err = fdt_setprop(fdt, nodeoffset, "reset_reason", str,
+ strlen(str) + 1);
+ if (err < 0) {
+ printf("WARNING: could not set reset_reason %s.\n",
+ fdt_strerror(err));
+ return err;
+ }
+ }
+
return fdt_fixup_stdout(fdt, nodeoffset);
}
--
2.17.1
......@@ -15,8 +15,11 @@ SRC_URI = " \
file://diot_util_clk.h \
file://diot_util_error.c \
file://diot_util_error.h \
file://diot_util_fantray.c \
file://diot_util_fantray.h \
file://diot_util_gpio.c \
file://diot_util_gpio.h \
file://diot_util_i2c.h \
file://diot_util_sensors.c \
file://diot_util_sensors.h \
file://diot_util_pts.c \
......@@ -31,8 +34,8 @@ SRC_URI = " \
file://util.h \
"
DEPENDS = "libgpiod readline lmsensors"
RDEPENDS_${PN} = "lmsensors-libsensors"
DEPENDS = "libgpiod readline lmsensors i2c-tools"
RDEPENDS_${PN} = "lmsensors-libsensors i2c-tools"
S = "${WORKDIR}"
CFLAGS_prepend = "-I ${S}/include"
......@@ -49,4 +52,6 @@ do_install() {
do_compile_prepend() {
export SB_VER=${SB_VER}
export GIT_VER="${GIT_VER}"
export GIT_USR="${GIT_USR}"
}
......@@ -5,6 +5,7 @@ APP_OBJS = \
diot_util.o \
diot_util_clk.o \
diot_util_error.o \
diot_util_fantray.o \
diot_util_gpio.o \
diot_util_sensors.o \
diot_util_pts.o \
......@@ -13,9 +14,12 @@ APP_OBJS = \
term.o \
util.o \
LDLIBS+=-lgpiod -lreadline -lsensors
LDLIBS+=-lgpiod -lreadline -lsensors -li2c
CFLAGS+=-Wall -ggdb -g -O2 \
-DSB_VER=$(SB_VER)
-DSB_VER=$(SB_VER) \
-D__GIT_USR__="\"$(GIT_USR)\"" \
-D__GIT_VER__="\"$(GIT_VER)\"" \
LDFLAGS+= -ggdb -g
......
......@@ -9,6 +9,15 @@
#ifndef __DIOT_UTIL_H
#define __DIOT_UTIL_H
struct command_entry {
char *cmd_name;
int (*cmd_func)(char *params);
char *cmd_help_string;
char *cmd_params;
};
int cmd_help(char *params);
#define COLOR_RED "\033[1;31m"
#define COLOR_OFF "\033[0m"
......
......@@ -12,43 +12,18 @@
#include <stdlib.h>
#include "diot_util_error.h"
#include "diot_util_pts.h"
#include "diot_util_i2c.h"
#include "util.h"
# define INPUT_PRESENT_FILE "/sys/bus/i2c/drivers/si5341/" SI5341_I2C "-00" SI5341_I2C_ADDR "/input_present"
# define PLL_LOCKED_FILE "/sys/bus/i2c/drivers/si5341/" SI5341_I2C "-00" SI5341_I2C_ADDR "/pll_locked"
# define INPUT_SELECTED_FILE "/sys/bus/i2c/drivers/si5341/" SI5341_I2C "-00" SI5341_I2C_ADDR "/input_selected"
#if SB_VER == 1
# define INPUT_PRESENT_FILE "/sys/bus/i2c/drivers/si5341/7-0076/input_present"
# define PLL_LOCKED_FILE "/sys/bus/i2c/drivers/si5341/7-0076/pll_locked"
# define INPUT_SELECTED_FILE "/sys/bus/i2c/drivers/si5341/7-0076/input_selected"
#elif SB_VER == 2
# define INPUT_PRESENT_FILE "/sys/bus/i2c/drivers/si5341/6-0076/input_present"
# define PLL_LOCKED_FILE "/sys/bus/i2c/drivers/si5341/6-0076/pll_locked"
# define INPUT_SELECTED_FILE "/sys/bus/i2c/drivers/si5341/6-0076/input_selected"
#else
# error SB_VER not defined
#endif
#define SI5341_PREFIX_PATH "/sys/kernel/debug/clk/si5341"
#define SI5341_N_CH_OUT 10
int get_file_content(char *file_name, int *val)
{
int ret;
FILE * fp;
fp = fopen (file_name, "r");
if (!fp) {
diot_error_add("Unable to read file %s\n", file_name);
return -1;
}
ret = fscanf(fp, "%d", val);
fclose(fp);
if (ret <= 0 || ret == EOF) {
diot_error_add("Unable to read value from file %s\n", file_name);
return -1;
}
return ret;
}
int get_selected_input(int *val, char *input_name, char *input_name_dtb)
{
......@@ -132,18 +107,18 @@ void print_clk_rate(void)
printf("-------+------------+\n");
snprintf(path_buff, sizeof(path_buff), "%s/clk_rate", SI5341_PREFIX_PATH);
ret = get_file_content(path_buff, &val);
ret = get_file_content_int(path_buff, &val);
printf("InDiv | %10s |\n", value_float_or_error(buff, ret, val));
snprintf(path_buff, sizeof(path_buff), "%s.N0/clk_rate",
SI5341_PREFIX_PATH);
ret = get_file_content(path_buff, &val);
ret = get_file_content_int(path_buff, &val);
printf("PLLout | %10s |\n", value_float_or_error(buff, ret, val));
for (i = 0; i < SI5341_N_CH_OUT; i++) {
snprintf(path_buff, sizeof(path_buff), "%s.%d/clk_rate",
SI5341_PREFIX_PATH, i);
ret = get_file_content(path_buff, &val);
ret = get_file_content_int(path_buff, &val);
printf("Out%d | %10s |\n", i, value_float_or_error(buff, ret, val));
}
......@@ -173,7 +148,7 @@ int pts_clocks(void)
printf("Test Clocks");
ret = get_file_content(INPUT_PRESENT_FILE, &val);
ret = get_file_content_int(INPUT_PRESENT_FILE, &val);
pts_sensor_p = find_pts_sensor("PLL Input Present");
if (ret < 0 || !pts_sensor_inrange(val, pts_sensor_p)) {
if (errors++ == 0)
......@@ -182,7 +157,7 @@ int pts_clocks(void)
val, pts_sensor_p->allowed_min, pts_sensor_p->allowed_max);
}
ret = get_file_content(PLL_LOCKED_FILE, &val);
ret = get_file_content_int(PLL_LOCKED_FILE, &val);
pts_sensor_p = find_pts_sensor("PLL Locked");
if (ret < 0 || !pts_sensor_inrange(val, pts_sensor_p)) {
if (errors++ == 0)
......@@ -203,7 +178,7 @@ int pts_clocks(void)
for (i = 0; i < SI5341_N_CH_OUT; i++) {
snprintf(path_buff, sizeof(path_buff), "%s.%d/clk_rate",
SI5341_PREFIX_PATH, i);
ret = get_file_content(path_buff, &val);
ret = get_file_content_int(path_buff, &val);
snprintf(path_buff, sizeof(path_buff), "PLL Out%d", i);
pts_sensor_p = find_pts_sensor(path_buff);
if (ret < 0 || !pts_sensor_inrange((float)val/1000000, pts_sensor_p)) {
......@@ -233,9 +208,9 @@ int cmd_clocks(char *params)
diot_error_clear();
printf("----------------+------------+\n");
ret = get_file_content(INPUT_PRESENT_FILE, &val);
ret = get_file_content_int(INPUT_PRESENT_FILE, &val);
printf("Input present |%11s |\n", check_ret_value(ret, val));
ret = get_file_content(PLL_LOCKED_FILE, &val);
ret = get_file_content_int(PLL_LOCKED_FILE, &val);
printf("Pll locked |%11s |\n", check_ret_value(ret, val));
get_selected_input(&val, buff_input_name, buff_input_name_DTB);
printf("Input id |%11s |\n", value_or_error(buff, val, val));
......
/*
* diot_util_fantray - functions specific to fantray (monimod) used in DIOT
* crate
*
* Author: Adam Wujek for CERN
* Copyright CERN 2022
*
*/
#ifndef __DIOT_UTIL_FANTRAY_H
#define __DIOT_UTIL_FANTRAY_H
extern struct command_entry commands_list_fantray[];
int cmd_fantray(char *params);
#endif /* __DIOT_UTIL_FANTRAY_H */
......@@ -14,34 +14,21 @@
#include <errno.h>
#include <stdint.h>
#include "diot_util_error.h"
#include "diot_util_i2c.h"
#define EEPROM_DRIVER_PATH "/sys/bus/i2c/drivers/at24"
#define FMC_EEPROM_PATH "/sys/bus/i2c/drivers/at24/0-0050/eeprom"
#define FMC_EEPROM_PATH "/sys/bus/i2c/drivers/at24/" FMC_EEPROM_I2C "-00" FMC_EEPROM_I2C_ADDR "/eeprom"
#define PSU_DRIVER_PATH "/sys/bus/i2c/drivers/hartmann-psu"
#define XIIC_DRIVER_PATH "/sys/bus/platform/drivers/xiic-i2c"
#define XIIC_ADDRESS_2 "a0010000.i2c"
#if SB_VER == 1
#define PB_EEPROM_PATH "/sys/bus/i2c/drivers/at24/4-0050/eeprom"
#define PB_EEPROM_I2C_ADDR "4-0050"
char * psu_addr[] = {
[1] = "3-0018",
[2] = "3-0019",
};
#elif SB_VER == 2
#define PB_EEPROM_PATH "/sys/bus/i2c/drivers/at24/9-0050/eeprom"
#define PB_EEPROM_I2C_ADDR "3-0050"
#define PB_EEPROM_PATH "/sys/bus/i2c/drivers/at24/" PB_EEPROM_I2C "-00" PB_EEPROM_I2C_ADDR "/eeprom"
#define PB_EEPROM_FULL_I2C_ADDR PB_EEPROM_I2C "-00" PB_EEPROM_I2C_ADDR
char * psu_addr[] = {
[1] = "8-0018",
[2] = "8-0019",
[1] = PSU_I2C "-00" PSU1_I2C_ADDR,
[2] = PSU_I2C "-00" PSU2_I2C_ADDR,
};
#else
#error SB_VER not defined
#endif
#define CONSUMER "diot_util"
const char *chipname = "gpiochip0";
......@@ -99,6 +86,7 @@ enum diot_gpio{
#endif
RST_N,
PSU_ALERT,
F_RST,
MAX_GPIO,
};
......@@ -145,6 +133,7 @@ struct gpio_entry gpio_entries[MAX_GPIO] = {
#endif
DECLARE_GPIO_OUT(RST_N, 1),
DECLARE_GPIO_IN(PSU_ALERT),
DECLARE_GPIO_OUT(F_RST, 1),
};
/* commands */
......@@ -469,7 +458,7 @@ int read_pb_eeprom(uint8_t *eeprom_buff, size_t eeprom_size, int slot)
ret = -1;
goto out_set_input;
}
msg = PB_EEPROM_I2C_ADDR;
msg = PB_EEPROM_FULL_I2C_ADDR;
ret = fwrite(msg, 1, sizeof(msg), bind_file);
fclose(bind_file);
......@@ -498,7 +487,7 @@ out_unbind:
ret = -1;
goto out_set_input;
}
msg = PB_EEPROM_I2C_ADDR;
msg = PB_EEPROM_FULL_I2C_ADDR;
ret = fwrite(msg, sizeof(msg), 1, bind_file);
fclose(bind_file);
......@@ -659,3 +648,8 @@ int restore_i2c(void)
return 1;
}
int gpio_fantray_reset(int val)
{
return gpiod_line_set_value(gpio_entries[F_RST].gpio_line, val);
}
......@@ -27,6 +27,7 @@ int read_pb_eeprom(uint8_t *eeprom_buff, size_t eeprom_size, int slot);
int read_fmc_eeprom(uint8_t *eeprom_buff, size_t eeprom_size);
int psu_added_or_removed(int psu);
int restore_i2c(void);
int gpio_fantray_reset(int val);
......
/*
* diot_util_i2c - i2c channels and addresses on DIOT system board
*
* Author: Adam Wujek for CERN
* Copyright CERN 2021
*
*/
#ifndef __DIOT_UTIL_I2C_H
#define __DIOT_UTIL_I2C_H
#if SB_VER == 1
#define MAX6639_I2C "9"
#define LM75_I2C "6"
#define IRPS5401_I2C "5"
#define PSU_I2C "3"
#define SI5341_I2C "7"
#define PB_EEPROM_I2C "4"
#elif SB_VER == 2
#define MAX6639_I2C "8"
#define LM75_I2C "5"
#define IRPS5401_I2C "4"
#define PSU_I2C "9"
#define SI5341_I2C "6"
#define PB_EEPROM_I2C "3"
#else
#error SB_VER not defined
#endif
#define FANTRAY_I2C PSU_I2C
#define FANTRAY_I2C_ADDR "12"
#define FANTRAY_I2C_REG_WRITTEN_FW_SIZE 0xD1
#define FANTRAY_I2C_REG_WRITTEN_FW_BLOCK 0xD2
#define FANTRAY_I2C_REG_WRITTEN_FW_CHKSUM 0xD3
#define FANTRAY_I2C_REG_LOCAL_FW_CHKSUM 0xD4
#define FANTRAY_I2C_REG_BOOT_NEW_FW 0xD5
#define FANTRAY_I2C_REG_RESET 0xD6
#define FANTRAY_FW_TYPE_BOOTLOADER 0x1
#define FANTRAY_FW_TYPE_MAIN 0x2
#define FMC_EEPROM_I2C "0"
#define FMC_EEPROM_I2C_ADDR "50"
#define PSU1_I2C_ADDR "18"
#define PSU2_I2C_ADDR "19"
#define IRPS5401_1_I2C_ADDR "44"
#define IRPS5401_2_I2C_ADDR "45"
#define LM75_1_I2C_ADDR "49"
#define LM75_2_I2C_ADDR "48"
#define LM75_3_I2C_ADDR "4a"
#define MAX6639_I2C_ADDR "2c"
#define SI5341_I2C_ADDR "76"
#define PB_EEPROM_I2C_ADDR "50"
#define FANTRAY_DRIVER_PATH "/sys/bus/i2c/drivers/monimod"
#define FANTRAY_FULL_I2C_ADDR FANTRAY_I2C "-00" FANTRAY_I2C_ADDR
#define FANTRAY_HWMON_SYS_PATH "/sys/devices/platform/amba/ff030000.i2c/i2c-1/i2c-" FANTRAY_I2C "/" FANTRAY_I2C "-00" FANTRAY_I2C_ADDR "/hwmon"
#define PSU1_HWMON_SYS_PATH "/sys/devices/platform/amba/ff030000.i2c/i2c-1/i2c-" PSU_I2C "/" PSU_I2C "-00" PSU1_I2C_ADDR "/hwmon"
#define PSU2_HWMON_SYS_PATH "/sys/devices/platform/amba/ff030000.i2c/i2c-1/i2c-" PSU_I2C "/" PSU_I2C "-00" PSU2_I2C_ADDR "/hwmon"
#define DEBUGFS_PMBUS "/sys/kernel/debug/pmbus"
#endif /* __DIOT_UTIL_I2C_H */
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <errno.h>
#include "util.h"
#include "diot_util_error.h"
/* get monotonic number of seconds */
time_t get_monotonic_sec(void)
......@@ -7,3 +13,133 @@ time_t get_monotonic_sec(void)
clock_gettime(CLOCK_MONOTONIC, &tv);
return tv.tv_sec;
}
char *get_file_content(char *filename, char *buff, size_t buff_size)
{
FILE *file_h;
int ret;
file_h = fopen(filename, "r");
if (!file_h) {
diot_error_add("Unable to open file (%s)\n", filename);
return "Error";
}
ret = fread(buff, 1, buff_size, file_h);
if (ret >= buff_size)
ret--;
/* make sure the last character is 0 */
buff[ret] = 0;
if (ferror(file_h)) {
diot_error_add("Error while reading file (%s)\n", filename);
return "Error";
}
fclose(file_h);
return buff;
}
int get_file_content_int(char *file_name, int *val)
{
int ret;
FILE * fp;
fp = fopen (file_name, "r");
if (!fp) {
diot_error_add("Unable to read file %s\n", file_name);
return -1;
}
ret = fscanf(fp, "%d", val);
fclose(fp);
if (ret <= 0 || ret == EOF) {
diot_error_add("Unable to read value from file %s\n", file_name);
return -1;
}
return ret;
}
int set_file_content_int(char *file_name, int val)
{
int ret;
FILE * fp;
fp = fopen (file_name, "w");
if (!fp) {
diot_error_add("Unable to write to file %s\n", file_name);
return -1;
}
ret = fprintf(fp, "%d", val);
fclose(fp);
if (ret <= 0 || ret == EOF) {
diot_error_add("Unable to write value %ld to file %s\n",
val, file_name);
return -1;
}
return ret;
}
char *end_str_at_newline(char *buff)
{
char *p;
p = strchr(buff, '\n');
if (p)
*p = '\0';
return buff;
}
char *string_map_get(char *name, struct string_map *map, size_t map_size)
{
int i;
for (i = 0; i < map_size; i++)
if (!strcmp(map[i].index, name))
return map[i].label;
return "Unknown";
}
char *get_hwmon_number(char *hwmon_sys_dir, char * buff, size_t buff_size)
{
int ret;
DIR *d;
struct dirent *dir;
d = opendir(hwmon_sys_dir);
if (!d) {
return NULL;
}
while ((dir = readdir(d)) != NULL) {
if (!strncmp(dir->d_name, ".", 1))
continue;
ret = snprintf(buff, buff_size, "%s", dir->d_name);
if (ret > buff_size) {
/* buffer not big enough */
diot_error_add("Buffer too short for hwmon number. Written "
"\"%s\"(len %d), wanted \"%s\"(len %d)\n",
buff, strlen(buff), dir->d_name, strlen(dir->d_name)
);
closedir(d);
errno = ENOBUFS;
return NULL;
}
/* assume there is only one entry in the directory like:
* /sys/devices/platform/amba/ff030000.i2c/i2c-1/i2c-9/9-0012/hwmon
*/
break;
}
closedir(d);
return buff;
}
......@@ -8,7 +8,21 @@
#ifndef __UTIL_H
#define __UTIL_H
#include <time.h>
struct string_map {
char *index;
char *label;
};
time_t get_monotonic_sec(void);
char *get_file_content(char *filename, char *buff, size_t buff_size);
int get_file_content_int(char *file_name, int *val);
int set_file_content_int(char *file_name, int val);
char *end_str_at_newline(char *buff);
char *get_hwmon_number(char *hwmon_sys_dir, char * buff, size_t buff_size);
char *string_map_get(char *name, struct string_map *map, size_t map_size);
#endif /* __UTIL_H */
......@@ -3,7 +3,7 @@
#
SUMMARY = "Simple copy-emmcp2 application"
SECTION = "PETALINUX/apps"
SECTION = "PETALINUX/core"
LICENSE = "GPLv3+"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/GPL-3.0;md5=c79ff39f19dfec6d293b95dea7b07891"
......
diot-version - adds file /etc/version.diot with the information about HW version, GIT commit id, build date, time and author
#
# This file is the diot-version recipe.
#
SUMMARY = "Put the build information into /etc/version.diot"
SECTION = "PETALINUX/core"
LICENSE = "GPLv3+"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/GPL-3.0;md5=c79ff39f19dfec6d293b95dea7b07891"
S = "${WORKDIR}"
do_compile() {
echo "HW version: ${SB_VER}" > ${S}/version.diot
echo "GIT commit id: ${GIT_VER}" >> ${S}/version.diot
echo "Built by: ${GIT_USR}" >> ${S}/version.diot
echo "Build date: `date +%Y.%m.%d-%H:%M:%S`" >> ${S}/version.diot
}
do_install() {
install -d ${D}${sysconfdir}
install -m 0644 ${S}/version.diot ${D}${sysconfdir}/
}
FILES_${PN} += "${sysconfdir}/version.diot"
# DIOT HW v2
bus "i2c-8" "xiic-i2c"
bus "i2c-9" "i2c-1-mux (chan_id 5)"
chip "D57500520-i2c-8-18"
chip "D57500520-i2c-9-18"
label temp1 "PSU1 Temp1"
label temp2 "PSU1 Temp2"
label in1 "PSU1 12V Voltage"
label curr1 "PSU1 12V Current"
label power1 "PSU1 12V Power"
chip "D57500520-i2c-8-19"
chip "D57500520-i2c-9-19"
label temp1 "PSU2 Temp1"
label temp2 "PSU2 Temp2"
label in1 "PSU2 12V Voltage"
......
bus "i2c-3" "xiic-i2c"
bus "i2c-9" "i2c-1-mux (chan_id 5)"
chip "monimod-i2c-3-12"
chip "monimod-i2c-9-12"
label temp1 "FANTRAY Temp"
label in1 "FANTRAY 12V Voltage"
label in2 "FANTRAY 5V Voltage"
......
......@@ -5,4 +5,7 @@ IMAGE_INSTALL_append = "\
lmsensors-sensors \
lmsensors-config-diot \
copy-emmcp2 \
diot-version \
python3-pytest \
python3-smbus \
"
From 6c2df6081d35e5b7386e513ba066cf3c72b92682 Mon Sep 17 00:00:00 2001
From: Georgii Staroselskii <georgii.staroselskii@emlid.com>
Date: Fri, 23 Nov 2018 09:40:26 +0100
Subject: [PATCH] py-smbus: Fix i2c_smbus_* error propagation
The Python bindings haven't been updated after commit
330bba29f3d02432e2dca6f85082763b248887ff ("libi2c: Properly
propagate real error codes on read errors"). This led to erronenous
behavior every time an error other than -1 is returned by i2c_smbus_*
functions.
[JD: Edited description.]
Signed-off-by: Georgii Staroselskii <georgii.staroselskii@emlid.com>
Signed-off-by: Jean Delvare <jdelvare@suse.de>
---
CHANGES | 2 ++
py-smbus/smbusmodule.c | 14 +++++++-------
2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/CHANGES b/CHANGES
index 15ff761..630a48c 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,8 @@
i2c-tools CHANGES
-----------------
+ py-smbus: Fix i2c_smbus_* error propagation
+
4.0 (2017-10-30)
tools: Fix build with recent compilers (gcc 4.6+)
Add examples to the manual pages
diff --git a/py-smbus/smbusmodule.c b/py-smbus/smbusmodule.c
index 48a408b..bf9b284 100644
--- a/py-smbus/smbusmodule.c
+++ b/py-smbus/smbusmodule.c
@@ -215,7 +215,7 @@ SMBus_read_byte(SMBus *self, PyObject *args)
SMBus_SET_ADDR(self, addr);
- if ((result = i2c_smbus_read_byte(self->fd)) == -1) {
+ if ((result = i2c_smbus_read_byte(self->fd)) < 0) {
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
@@ -238,7 +238,7 @@ SMBus_write_byte(SMBus *self, PyObject *args)
SMBus_SET_ADDR(self, addr);
- if ((result = i2c_smbus_write_byte(self->fd, (__u8)val)) == -1) {
+ if ((result = i2c_smbus_write_byte(self->fd, (__u8)val)) < 0) {
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
@@ -262,7 +262,7 @@ SMBus_read_byte_data(SMBus *self, PyObject *args)
SMBus_SET_ADDR(self, addr);
- if ((result = i2c_smbus_read_byte_data(self->fd, (__u8)cmd)) == -1) {
+ if ((result = i2c_smbus_read_byte_data(self->fd, (__u8)cmd)) < 0) {
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
@@ -286,7 +286,7 @@ SMBus_write_byte_data(SMBus *self, PyObject *args)
SMBus_SET_ADDR(self, addr);
if ((result = i2c_smbus_write_byte_data(self->fd,
- (__u8)cmd, (__u8)val)) == -1) {
+ (__u8)cmd, (__u8)val)) < 0) {
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
@@ -310,7 +310,7 @@ SMBus_read_word_data(SMBus *self, PyObject *args)
SMBus_SET_ADDR(self, addr);
- if ((result = i2c_smbus_read_word_data(self->fd, (__u8)cmd)) == -1) {
+ if ((result = i2c_smbus_read_word_data(self->fd, (__u8)cmd)) < 0) {
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
@@ -334,7 +334,7 @@ SMBus_write_word_data(SMBus *self, PyObject *args)
SMBus_SET_ADDR(self, addr);
if ((result = i2c_smbus_write_word_data(self->fd,
- (__u8)cmd, (__u16)val)) == -1) {
+ (__u8)cmd, (__u16)val)) < 0) {
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
@@ -359,7 +359,7 @@ SMBus_process_call(SMBus *self, PyObject *args)
SMBus_SET_ADDR(self, addr);
if ((result = i2c_smbus_process_call(self->fd,
- (__u8)cmd, (__u16)val)) == -1) {
+ (__u8)cmd, (__u16)val)) < 0) {
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
--
2.17.1
#Patch
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
SRC_URI += " file://0001-py-smbus-Fix-i2c_smbus_-error-propagation.patch;patchdir=${WORKDIR}/i2c-tools-${PV}"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment