* [PATCH 1/2] dt-bindings: Add vendor prefix and trivial device for BluTek BPA-RS600
@ 2021-03-16 2:35 Chris Packham
2021-03-16 2:35 ` [PATCH 2/2] hwmon: (pmbus): Add driver " Chris Packham
0 siblings, 1 reply; 9+ messages in thread
From: Chris Packham @ 2021-03-16 2:35 UTC (permalink / raw)
To: robh+dt, jdelvare, linux
Cc: devicetree, linux-hwmon, linux-kernel, Chris Packham
Add vendor prefix "blutek" for BluTek Power.
Add trivial device entry for BPA-RS600.
Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
Documentation/devicetree/bindings/trivial-devices.yaml | 2 ++
Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++
2 files changed, 4 insertions(+)
diff --git a/Documentation/devicetree/bindings/trivial-devices.yaml b/Documentation/devicetree/bindings/trivial-devices.yaml
index a327130d1faa..569236e9bed0 100644
--- a/Documentation/devicetree/bindings/trivial-devices.yaml
+++ b/Documentation/devicetree/bindings/trivial-devices.yaml
@@ -50,6 +50,8 @@ properties:
- atmel,atsha204a
# i2c h/w elliptic curve crypto module
- atmel,atecc508a
+ # BPA-RS600: Power Supply
+ - blutek,bpa-rs600
# Bosch Sensortec pressure, temperature, humididty and VOC sensor
- bosch,bme680
# CM32181: Ambient Light Sensor
diff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml b/Documentation/devicetree/bindings/vendor-prefixes.yaml
index f6064d84a424..d9d7226f5dfe 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.yaml
+++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml
@@ -169,6 +169,8 @@ patternProperties:
description: Beckhoff Automation GmbH & Co. KG
"^bitmain,.*":
description: Bitmain Technologies
+ "^blutek,.*":
+ description: BluTek Power
"^boe,.*":
description: BOE Technology Group Co., Ltd.
"^bosch,.*":
--
2.30.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/2] hwmon: (pmbus): Add driver for BluTek BPA-RS600
2021-03-16 2:35 [PATCH 1/2] dt-bindings: Add vendor prefix and trivial device for BluTek BPA-RS600 Chris Packham
@ 2021-03-16 2:35 ` Chris Packham
2021-03-16 3:30 ` Chris Packham
2021-03-16 3:43 ` Guenter Roeck
0 siblings, 2 replies; 9+ messages in thread
From: Chris Packham @ 2021-03-16 2:35 UTC (permalink / raw)
To: robh+dt, jdelvare, linux
Cc: devicetree, linux-hwmon, linux-kernel, Chris Packham
The BPA-RS600 is a compact 600W AC to DC removable power supply module.
Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
Documentation/hwmon/bpa-rs600.rst | 74 ++++++++++++
drivers/hwmon/pmbus/Kconfig | 10 ++
drivers/hwmon/pmbus/Makefile | 1 +
drivers/hwmon/pmbus/bpa-rs600.c | 179 ++++++++++++++++++++++++++++++
4 files changed, 264 insertions(+)
create mode 100644 Documentation/hwmon/bpa-rs600.rst
create mode 100644 drivers/hwmon/pmbus/bpa-rs600.c
diff --git a/Documentation/hwmon/bpa-rs600.rst b/Documentation/hwmon/bpa-rs600.rst
new file mode 100644
index 000000000000..28313995d4ae
--- /dev/null
+++ b/Documentation/hwmon/bpa-rs600.rst
@@ -0,0 +1,74 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Kernel driver bpa-rs600
+=======================
+
+Supported chips:
+
+ * BPA-RS600-120
+
+ Datasheet: Publicly available at the BluTek website
+ http://blutekpower.com/wp-content/uploads/2019/01/BPA-RS600-120-07-19-2018.pdf
+
+Authors:
+ - Chris Packham <chris.packham@alliedtelesis.co.nz>
+
+Description
+-----------
+
+The BPA-RS600 is a compact 600W removable power supply module.
+
+Usage Notes
+-----------
+
+This driver does not probe for PMBus devices. You will have to instantiate
+devices explicitly.
+
+Sysfs attributes
+----------------
+
+======================= ============================================
+curr1_label "iin"
+curr1_input Measured input current
+curr1_max Maximum input current
+curr1_max_alarm Input current high alarm
+
+curr2_label "iout1"
+curr2_input Measured output current
+curr2_max Maximum output current
+curr2_max_alarm Output current high alarm
+
+fan1_input Measured fan speed
+fan1_alarm Fan warning
+fan1_fault Fan fault
+
+in1_label "vin"
+in1_input Measured input voltage
+in1_max Maximum input voltage
+in1_max_alarm Input voltage high alarm
+in1_min Minimum input voltage
+in1_min_alarm Input voltage low alarm
+
+in2_label "vout1"
+in2_input Measured output voltage
+in2_max Maximum output voltage
+in2_max_alarm Output voltage high alarm
+in2_min Maximum output voltage
+in2_min_alarm Output voltage low alarm
+
+power1_label "pin"
+power1_input Measured input power
+power1_alarm Input power alarm
+power1_max Maximum input power
+
+power2_label "pout1"
+power2_input Measured output power
+power2_max Maximum output power
+power2_max_alarm Output power high alarm
+
+temp1_input Measured temperature around input connector
+temp1_alarm Temperature alarm
+
+temp2_input Measured temperature around output connector
+temp2_alarm Temperature alarm
+======================= ============================================
diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig
index 32d2fc850621..d1f0f1cd8247 100644
--- a/drivers/hwmon/pmbus/Kconfig
+++ b/drivers/hwmon/pmbus/Kconfig
@@ -56,6 +56,16 @@ config SENSORS_BEL_PFE
This driver can also be built as a module. If so, the module will
be called bel-pfe.
+config SENSORS_BPA_RS600
+ tristate "BluTek BPD-RS600 Power Supplies"
+ help
+ If you say yes here you get hardware monitoring support for BluTek
+ BPD-RS600 Power Supplies.
+
+ This driver can also be built as a module. If so, the module will
+ be called bpd-rs600.
+
+
config SENSORS_IBM_CFFPS
tristate "IBM Common Form Factor Power Supply"
depends on LEDS_CLASS
diff --git a/drivers/hwmon/pmbus/Makefile b/drivers/hwmon/pmbus/Makefile
index 6a4ba0fdc1db..80a437060dc4 100644
--- a/drivers/hwmon/pmbus/Makefile
+++ b/drivers/hwmon/pmbus/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_SENSORS_PMBUS) += pmbus.o
obj-$(CONFIG_SENSORS_ADM1266) += adm1266.o
obj-$(CONFIG_SENSORS_ADM1275) += adm1275.o
obj-$(CONFIG_SENSORS_BEL_PFE) += bel-pfe.o
+obj-$(CONFIG_SENSORS_BPA_RS600) += bpa-rs600.o
obj-$(CONFIG_SENSORS_IBM_CFFPS) += ibm-cffps.o
obj-$(CONFIG_SENSORS_INSPUR_IPSPS) += inspur-ipsps.o
obj-$(CONFIG_SENSORS_IR35221) += ir35221.o
diff --git a/drivers/hwmon/pmbus/bpa-rs600.c b/drivers/hwmon/pmbus/bpa-rs600.c
new file mode 100644
index 000000000000..94cbf42816f0
--- /dev/null
+++ b/drivers/hwmon/pmbus/bpa-rs600.c
@@ -0,0 +1,179 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Hardware monitoring driver for BluTek BPA-RS600 Power Supplies
+ *
+ * Copyright 2021 Allied Telesis Labs
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/i2c.h>
+#include <linux/pmbus.h>
+#include "pmbus.h"
+
+#define BPARS600_MFR_VIN_MIN 0xa0
+#define BPARS600_MFR_VIN_MAX 0xa1
+#define BPARS600_MFR_IIN_MAX 0xa2
+#define BPARS600_MFR_PIN_MAX 0xa3
+#define BPARS600_MFR_VOUT_MIN 0xa4
+#define BPARS600_MFR_VOUT_MAX 0xa5
+#define BPARS600_MFR_IOUT_MAX 0xa6
+#define BPARS600_MFR_POUT_MAX 0xa7
+
+static int bpa_rs600_read_byte_data(struct i2c_client *client, int page,
+ int reg)
+{
+ int ret;
+
+ if (page > 0)
+ return -ENXIO;
+
+ switch (reg) {
+ case PMBUS_FAN_CONFIG_12:
+ ret = pmbus_read_byte_data(client, 0,
+ PMBUS_FAN_CONFIG_12);
+ if (ret >= 0)
+ ret &= ~(PB_FAN_2_INSTALLED | PB_FAN_2_PULSE_MASK);
+ break;
+ default:
+ ret = -ENODATA;
+ break;
+ }
+
+ return ret;
+}
+
+static int bpa_rs600_read_word_data(struct i2c_client *client, int page,
+ int phase, int reg)
+{
+ int ret;
+
+ if (page > 0)
+ return -ENXIO;
+
+ switch (reg) {
+ case PMBUS_VIN_UV_FAULT_LIMIT:
+ case PMBUS_VIN_OV_FAULT_LIMIT:
+ case PMBUS_VOUT_UV_FAULT_LIMIT:
+ case PMBUS_VOUT_OV_FAULT_LIMIT:
+ ret = -ENXIO;
+ break;
+ case PMBUS_VIN_UV_WARN_LIMIT:
+ ret = pmbus_read_word_data(client, 0, 0xff,
+ BPARS600_MFR_VIN_MIN);
+ break;
+ case PMBUS_VIN_OV_WARN_LIMIT:
+ ret = pmbus_read_word_data(client, 0, 0xff,
+ BPARS600_MFR_VIN_MAX);
+ break;
+ case PMBUS_VOUT_UV_WARN_LIMIT:
+ ret = pmbus_read_word_data(client, 0, 0xff,
+ BPARS600_MFR_VOUT_MIN);
+ break;
+ case PMBUS_VOUT_OV_WARN_LIMIT:
+ ret = pmbus_read_word_data(client, 0, 0xff,
+ BPARS600_MFR_VOUT_MAX);
+ break;
+ case PMBUS_IIN_OC_WARN_LIMIT:
+ ret = pmbus_read_word_data(client, 0, 0xff,
+ BPARS600_MFR_IIN_MAX);
+ break;
+ case PMBUS_IOUT_OC_WARN_LIMIT:
+ ret = pmbus_read_word_data(client, 0, 0xff,
+ BPARS600_MFR_IOUT_MAX);
+ break;
+ case PMBUS_PIN_OP_WARN_LIMIT:
+ ret = pmbus_read_word_data(client, 0, 0xff,
+ BPARS600_MFR_PIN_MAX);
+ break;
+ case PMBUS_POUT_OP_WARN_LIMIT:
+ ret = pmbus_read_word_data(client, 0, 0xff,
+ BPARS600_MFR_POUT_MAX);
+ break;
+ default:
+ if (reg >= PMBUS_VIRT_BASE)
+ ret = -ENXIO;
+ else
+ ret = -ENODATA;
+ break;
+ }
+
+ return ret;
+}
+
+static struct pmbus_driver_info bpa_rs600_info = {
+ .pages = 1,
+ .format[PSC_VOLTAGE_IN] = linear,
+ .format[PSC_VOLTAGE_OUT] = linear,
+ .format[PSC_CURRENT_IN] = linear,
+ .format[PSC_CURRENT_OUT] = linear,
+ .format[PSC_POWER] = linear,
+ .format[PSC_TEMPERATURE] = linear,
+ .format[PSC_FAN] = linear,
+ .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT |
+ PMBUS_HAVE_IIN | PMBUS_HAVE_IOUT |
+ PMBUS_HAVE_PIN | PMBUS_HAVE_POUT |
+ PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2 |
+ PMBUS_HAVE_FAN12 |
+ PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_IOUT |
+ PMBUS_HAVE_STATUS_INPUT | PMBUS_HAVE_STATUS_TEMP |
+ PMBUS_HAVE_STATUS_FAN12,
+ .read_byte_data = bpa_rs600_read_byte_data,
+ .read_word_data = bpa_rs600_read_word_data,
+};
+
+static int bpa_rs600_probe(struct i2c_client *client)
+{
+ struct device *dev = &client->dev;
+ u8 buf[I2C_SMBUS_BLOCK_MAX];
+ int ret;
+
+ if (!i2c_check_functionality(client->adapter,
+ I2C_FUNC_SMBUS_READ_BYTE_DATA
+ | I2C_FUNC_SMBUS_READ_WORD_DATA
+ | I2C_FUNC_SMBUS_READ_BLOCK_DATA))
+ return -ENODEV;
+
+
+ ret = i2c_smbus_read_block_data(client, PMBUS_MFR_MODEL, buf);
+ if (ret < 0) {
+ dev_err(dev, "Failed to read Manufacturer Model\n");
+ return ret;
+ }
+
+ if (strncmp(buf, "BPA-RS600", 8)) {
+ buf[ret] = '\0';
+ dev_err(dev, "Unsupported Manufacturer Model '%s'\n", buf);
+ return -ENODEV;
+ }
+
+ return pmbus_do_probe(client, &bpa_rs600_info);
+}
+
+static const struct i2c_device_id bpa_rs600_id[] = {
+ { "bpa_rs600", 0 },
+ {},
+};
+MODULE_DEVICE_TABLE(i2c, bpa_rs600_id);
+
+static const struct of_device_id __maybe_unused bpa_rs600_of_match[] = {
+ { .compatible = "blutek,bpa-rs600" },
+ {},
+};
+MODULE_DEVICE_TABLE(of, bpa_rs600_of_match);
+
+static struct i2c_driver bpa_rs600_driver = {
+ .driver = {
+ .name = "bpa-rs600",
+ .of_match_table = of_match_ptr(bpa_rs600_of_match),
+ },
+ .probe_new = bpa_rs600_probe,
+ .id_table = bpa_rs600_id,
+};
+
+module_i2c_driver(bpa_rs600_driver);
+
+MODULE_AUTHOR("Chris Packham");
+MODULE_DESCRIPTION("PMBus driver for BluTek BPA-RS600");
+MODULE_LICENSE("GPL");
--
2.30.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] hwmon: (pmbus): Add driver for BluTek BPA-RS600
2021-03-16 2:35 ` [PATCH 2/2] hwmon: (pmbus): Add driver " Chris Packham
@ 2021-03-16 3:30 ` Chris Packham
2021-03-16 3:35 ` Guenter Roeck
2021-03-16 3:43 ` Guenter Roeck
1 sibling, 1 reply; 9+ messages in thread
From: Chris Packham @ 2021-03-16 3:30 UTC (permalink / raw)
To: robh+dt, jdelvare, linux; +Cc: devicetree, linux-hwmon, linux-kernel
On 16/03/21 3:35 pm, Chris Packham wrote:
> The BPA-RS600 is a compact 600W AC to DC removable power supply module.
>
> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
>
> +static const struct of_device_id __maybe_unused bpa_rs600_of_match[] = {
> + { .compatible = "blutek,bpa-rs600" },
> + {},
> +};
I see this will fall foul of the name check in
__hwmon_device_register(). How should I name things to avoid this?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] hwmon: (pmbus): Add driver for BluTek BPA-RS600
2021-03-16 3:30 ` Chris Packham
@ 2021-03-16 3:35 ` Guenter Roeck
2021-03-16 3:41 ` Chris Packham
0 siblings, 1 reply; 9+ messages in thread
From: Guenter Roeck @ 2021-03-16 3:35 UTC (permalink / raw)
To: Chris Packham, robh+dt, jdelvare; +Cc: devicetree, linux-hwmon, linux-kernel
On 3/15/21 8:30 PM, Chris Packham wrote:
>
> On 16/03/21 3:35 pm, Chris Packham wrote:
>> The BPA-RS600 is a compact 600W AC to DC removable power supply module.
>>
>> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
>>
>> +static const struct of_device_id __maybe_unused bpa_rs600_of_match[] = {
>> + { .compatible = "blutek,bpa-rs600" },
>> + {},
>> +};
>
> I see this will fall foul of the name check in
> __hwmon_device_register(). How should I name things to avoid this?
>
It isn't the binding. The driver name should not have a '-' in it.
You could just name it bpa_rs600 instead.
Guenter
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] hwmon: (pmbus): Add driver for BluTek BPA-RS600
2021-03-16 3:35 ` Guenter Roeck
@ 2021-03-16 3:41 ` Chris Packham
2021-03-16 3:45 ` Guenter Roeck
0 siblings, 1 reply; 9+ messages in thread
From: Chris Packham @ 2021-03-16 3:41 UTC (permalink / raw)
To: Guenter Roeck, robh+dt, jdelvare; +Cc: devicetree, linux-hwmon, linux-kernel
On 16/03/21 4:35 pm, Guenter Roeck wrote:
> On 3/15/21 8:30 PM, Chris Packham wrote:
>> On 16/03/21 3:35 pm, Chris Packham wrote:
>>> The BPA-RS600 is a compact 600W AC to DC removable power supply module.
>>>
>>> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
>>>
>>> +static const struct of_device_id __maybe_unused bpa_rs600_of_match[] = {
>>> + { .compatible = "blutek,bpa-rs600" },
>>> + {},
>>> +};
>> I see this will fall foul of the name check in
>> __hwmon_device_register(). How should I name things to avoid this?
>>
> It isn't the binding. The driver name should not have a '-' in it.
> You could just name it bpa_rs600 instead.
Sold.
I'll give the world a chance to turn so people can look at the rest of
the patch before I send a v2.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] hwmon: (pmbus): Add driver for BluTek BPA-RS600
2021-03-16 2:35 ` [PATCH 2/2] hwmon: (pmbus): Add driver " Chris Packham
2021-03-16 3:30 ` Chris Packham
@ 2021-03-16 3:43 ` Guenter Roeck
2021-03-16 4:21 ` Chris Packham
1 sibling, 1 reply; 9+ messages in thread
From: Guenter Roeck @ 2021-03-16 3:43 UTC (permalink / raw)
To: Chris Packham, robh+dt, jdelvare; +Cc: devicetree, linux-hwmon, linux-kernel
On 3/15/21 7:35 PM, Chris Packham wrote:
> The BPA-RS600 is a compact 600W AC to DC removable power supply module.
>
> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
> ---
> Documentation/hwmon/bpa-rs600.rst | 74 ++++++++++++
> drivers/hwmon/pmbus/Kconfig | 10 ++
> drivers/hwmon/pmbus/Makefile | 1 +
> drivers/hwmon/pmbus/bpa-rs600.c | 179 ++++++++++++++++++++++++++++++
> 4 files changed, 264 insertions(+)
> create mode 100644 Documentation/hwmon/bpa-rs600.rst
> create mode 100644 drivers/hwmon/pmbus/bpa-rs600.c
>
> diff --git a/Documentation/hwmon/bpa-rs600.rst b/Documentation/hwmon/bpa-rs600.rst
> new file mode 100644
> index 000000000000..28313995d4ae
> --- /dev/null
> +++ b/Documentation/hwmon/bpa-rs600.rst
> @@ -0,0 +1,74 @@
> +.. SPDX-License-Identifier: GPL-2.0
> +
> +Kernel driver bpa-rs600
> +=======================
> +
> +Supported chips:
> +
> + * BPA-RS600-120
> +
> + Datasheet: Publicly available at the BluTek website
> + http://blutekpower.com/wp-content/uploads/2019/01/BPA-RS600-120-07-19-2018.pdf
> +
> +Authors:
> + - Chris Packham <chris.packham@alliedtelesis.co.nz>
> +
> +Description
> +-----------
> +
> +The BPA-RS600 is a compact 600W removable power supply module.
> +
> +Usage Notes
> +-----------
> +
> +This driver does not probe for PMBus devices. You will have to instantiate
> +devices explicitly.
> +
> +Sysfs attributes
> +----------------
> +
> +======================= ============================================
> +curr1_label "iin"
> +curr1_input Measured input current
> +curr1_max Maximum input current
> +curr1_max_alarm Input current high alarm
> +
> +curr2_label "iout1"
> +curr2_input Measured output current
> +curr2_max Maximum output current
> +curr2_max_alarm Output current high alarm
> +
> +fan1_input Measured fan speed
> +fan1_alarm Fan warning
> +fan1_fault Fan fault
> +
> +in1_label "vin"
> +in1_input Measured input voltage
> +in1_max Maximum input voltage
> +in1_max_alarm Input voltage high alarm
> +in1_min Minimum input voltage
> +in1_min_alarm Input voltage low alarm
> +
> +in2_label "vout1"
> +in2_input Measured output voltage
> +in2_max Maximum output voltage
> +in2_max_alarm Output voltage high alarm
> +in2_min Maximum output voltage
> +in2_min_alarm Output voltage low alarm
> +
> +power1_label "pin"
> +power1_input Measured input power
> +power1_alarm Input power alarm
> +power1_max Maximum input power
> +
> +power2_label "pout1"
> +power2_input Measured output power
> +power2_max Maximum output power
> +power2_max_alarm Output power high alarm
> +
> +temp1_input Measured temperature around input connector
> +temp1_alarm Temperature alarm
> +
> +temp2_input Measured temperature around output connector
> +temp2_alarm Temperature alarm
> +======================= ============================================
> diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig
> index 32d2fc850621..d1f0f1cd8247 100644
> --- a/drivers/hwmon/pmbus/Kconfig
> +++ b/drivers/hwmon/pmbus/Kconfig
> @@ -56,6 +56,16 @@ config SENSORS_BEL_PFE
> This driver can also be built as a module. If so, the module will
> be called bel-pfe.
>
> +config SENSORS_BPA_RS600
> + tristate "BluTek BPD-RS600 Power Supplies"
> + help
> + If you say yes here you get hardware monitoring support for BluTek
> + BPD-RS600 Power Supplies.
> +
> + This driver can also be built as a module. If so, the module will
> + be called bpd-rs600.
> +
> +
Extra empty line
> config SENSORS_IBM_CFFPS
> tristate "IBM Common Form Factor Power Supply"
> depends on LEDS_CLASS
> diff --git a/drivers/hwmon/pmbus/Makefile b/drivers/hwmon/pmbus/Makefile
> index 6a4ba0fdc1db..80a437060dc4 100644
> --- a/drivers/hwmon/pmbus/Makefile
> +++ b/drivers/hwmon/pmbus/Makefile
> @@ -8,6 +8,7 @@ obj-$(CONFIG_SENSORS_PMBUS) += pmbus.o
> obj-$(CONFIG_SENSORS_ADM1266) += adm1266.o
> obj-$(CONFIG_SENSORS_ADM1275) += adm1275.o
> obj-$(CONFIG_SENSORS_BEL_PFE) += bel-pfe.o
> +obj-$(CONFIG_SENSORS_BPA_RS600) += bpa-rs600.o
> obj-$(CONFIG_SENSORS_IBM_CFFPS) += ibm-cffps.o
> obj-$(CONFIG_SENSORS_INSPUR_IPSPS) += inspur-ipsps.o
> obj-$(CONFIG_SENSORS_IR35221) += ir35221.o
> diff --git a/drivers/hwmon/pmbus/bpa-rs600.c b/drivers/hwmon/pmbus/bpa-rs600.c
> new file mode 100644
> index 000000000000..94cbf42816f0
> --- /dev/null
> +++ b/drivers/hwmon/pmbus/bpa-rs600.c
> @@ -0,0 +1,179 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Hardware monitoring driver for BluTek BPA-RS600 Power Supplies
> + *
> + * Copyright 2021 Allied Telesis Labs
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/init.h>
> +#include <linux/i2c.h>
> +#include <linux/pmbus.h>
> +#include "pmbus.h"
alphabetic include file order please
> +
> +#define BPARS600_MFR_VIN_MIN 0xa0
> +#define BPARS600_MFR_VIN_MAX 0xa1
> +#define BPARS600_MFR_IIN_MAX 0xa2
> +#define BPARS600_MFR_PIN_MAX 0xa3
> +#define BPARS600_MFR_VOUT_MIN 0xa4
> +#define BPARS600_MFR_VOUT_MAX 0xa5
> +#define BPARS600_MFR_IOUT_MAX 0xa6
> +#define BPARS600_MFR_POUT_MAX 0xa7
> +
> +static int bpa_rs600_read_byte_data(struct i2c_client *client, int page,
> + int reg)
100 column line length limit
> +{
> + int ret;
> +
> + if (page > 0)
> + return -ENXIO;
> +
> + switch (reg) {
> + case PMBUS_FAN_CONFIG_12:
> + ret = pmbus_read_byte_data(client, 0,
> + PMBUS_FAN_CONFIG_12);
> + if (ret >= 0)
> + ret &= ~(PB_FAN_2_INSTALLED | PB_FAN_2_PULSE_MASK);
Please explain.
> + break;
> + default:
> + ret = -ENODATA;
> + break;
> + }
> +
> + return ret;
> +}
> +
> +static int bpa_rs600_read_word_data(struct i2c_client *client, int page,
> + int phase, int reg)
line length limit, and multi-line alignment
> +{
> + int ret;
> +
> + if (page > 0)
> + return -ENXIO;
> +
> + switch (reg) {
> + case PMBUS_VIN_UV_FAULT_LIMIT:
> + case PMBUS_VIN_OV_FAULT_LIMIT:
> + case PMBUS_VOUT_UV_FAULT_LIMIT:
> + case PMBUS_VOUT_OV_FAULT_LIMIT:
> + ret = -ENXIO;
Is that needed ? Why not -ENODATA ?
> + break;
> + case PMBUS_VIN_UV_WARN_LIMIT:
> + ret = pmbus_read_word_data(client, 0, 0xff,
> + BPARS600_MFR_VIN_MIN);
> + break;
> + case PMBUS_VIN_OV_WARN_LIMIT:
> + ret = pmbus_read_word_data(client, 0, 0xff,
> + BPARS600_MFR_VIN_MAX);
> + break;
> + case PMBUS_VOUT_UV_WARN_LIMIT:
> + ret = pmbus_read_word_data(client, 0, 0xff,
> + BPARS600_MFR_VOUT_MIN);
> + break;
> + case PMBUS_VOUT_OV_WARN_LIMIT:
> + ret = pmbus_read_word_data(client, 0, 0xff,
> + BPARS600_MFR_VOUT_MAX);
> + break;
> + case PMBUS_IIN_OC_WARN_LIMIT:
> + ret = pmbus_read_word_data(client, 0, 0xff,
> + BPARS600_MFR_IIN_MAX);
> + break;
> + case PMBUS_IOUT_OC_WARN_LIMIT:
> + ret = pmbus_read_word_data(client, 0, 0xff,
> + BPARS600_MFR_IOUT_MAX);
> + break;
> + case PMBUS_PIN_OP_WARN_LIMIT:
> + ret = pmbus_read_word_data(client, 0, 0xff,
> + BPARS600_MFR_PIN_MAX);
> + break;
> + case PMBUS_POUT_OP_WARN_LIMIT:
> + ret = pmbus_read_word_data(client, 0, 0xff,
> + BPARS600_MFR_POUT_MAX);
> + break;
> + default:
> + if (reg >= PMBUS_VIRT_BASE)
> + ret = -ENXIO;
> + else
> + ret = -ENODATA;
> + break;
> + }
> +
> + return ret;
> +}
> +
> +static struct pmbus_driver_info bpa_rs600_info = {
> + .pages = 1,
> + .format[PSC_VOLTAGE_IN] = linear,
> + .format[PSC_VOLTAGE_OUT] = linear,
> + .format[PSC_CURRENT_IN] = linear,
> + .format[PSC_CURRENT_OUT] = linear,
> + .format[PSC_POWER] = linear,
> + .format[PSC_TEMPERATURE] = linear,
> + .format[PSC_FAN] = linear,
> + .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT |
> + PMBUS_HAVE_IIN | PMBUS_HAVE_IOUT |
> + PMBUS_HAVE_PIN | PMBUS_HAVE_POUT |
> + PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2 |
> + PMBUS_HAVE_FAN12 |
> + PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_IOUT |
> + PMBUS_HAVE_STATUS_INPUT | PMBUS_HAVE_STATUS_TEMP |
> + PMBUS_HAVE_STATUS_FAN12,
> + .read_byte_data = bpa_rs600_read_byte_data,
> + .read_word_data = bpa_rs600_read_word_data,
> +};
> +
> +static int bpa_rs600_probe(struct i2c_client *client)
> +{
> + struct device *dev = &client->dev;
> + u8 buf[I2C_SMBUS_BLOCK_MAX];
> + int ret;
> +
> + if (!i2c_check_functionality(client->adapter,
> + I2C_FUNC_SMBUS_READ_BYTE_DATA
> + | I2C_FUNC_SMBUS_READ_WORD_DATA
> + | I2C_FUNC_SMBUS_READ_BLOCK_DATA))
> + return -ENODEV;
> +
> +
extra empty line
> + ret = i2c_smbus_read_block_data(client, PMBUS_MFR_MODEL, buf);
> + if (ret < 0) {
> + dev_err(dev, "Failed to read Manufacturer Model\n");
> + return ret;
> + }
> +
> + if (strncmp(buf, "BPA-RS600", 8)) {
> + buf[ret] = '\0';
> + dev_err(dev, "Unsupported Manufacturer Model '%s'\n", buf);
> + return -ENODEV;
> + }
> +
> + return pmbus_do_probe(client, &bpa_rs600_info);
> +}
> +
> +static const struct i2c_device_id bpa_rs600_id[] = {
> + { "bpa_rs600", 0 },
Hmm, no, this has an underscore. Guess you'll have to use the trick from
iio_hwmon.c or similar to generate a valid name.
Oh, wait, this is a pmbus driver, and the pmbus core uses client->name.
Maybe we need to add an optional strreplace() to the pmbus core.
Guenter
> + {},
> +};
> +MODULE_DEVICE_TABLE(i2c, bpa_rs600_id);
> +
> +static const struct of_device_id __maybe_unused bpa_rs600_of_match[] = {
> + { .compatible = "blutek,bpa-rs600" },
> + {},
> +};
> +MODULE_DEVICE_TABLE(of, bpa_rs600_of_match);
> +
> +static struct i2c_driver bpa_rs600_driver = {
> + .driver = {
> + .name = "bpa-rs600",
> + .of_match_table = of_match_ptr(bpa_rs600_of_match),
> + },
> + .probe_new = bpa_rs600_probe,
> + .id_table = bpa_rs600_id,
> +};
> +
> +module_i2c_driver(bpa_rs600_driver);
> +
> +MODULE_AUTHOR("Chris Packham");
> +MODULE_DESCRIPTION("PMBus driver for BluTek BPA-RS600");
> +MODULE_LICENSE("GPL");
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] hwmon: (pmbus): Add driver for BluTek BPA-RS600
2021-03-16 3:41 ` Chris Packham
@ 2021-03-16 3:45 ` Guenter Roeck
0 siblings, 0 replies; 9+ messages in thread
From: Guenter Roeck @ 2021-03-16 3:45 UTC (permalink / raw)
To: Chris Packham, robh+dt, jdelvare; +Cc: devicetree, linux-hwmon, linux-kernel
On 3/15/21 8:41 PM, Chris Packham wrote:
>
> On 16/03/21 4:35 pm, Guenter Roeck wrote:
>> On 3/15/21 8:30 PM, Chris Packham wrote:
>>> On 16/03/21 3:35 pm, Chris Packham wrote:
>>>> The BPA-RS600 is a compact 600W AC to DC removable power supply module.
>>>>
>>>> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
>>>>
>>>> +static const struct of_device_id __maybe_unused bpa_rs600_of_match[] = {
>>>> + { .compatible = "blutek,bpa-rs600" },
>>>> + {},
>>>> +};
>>> I see this will fall foul of the name check in
>>> __hwmon_device_register(). How should I name things to avoid this?
>>>
>> It isn't the binding. The driver name should not have a '-' in it.
>> You could just name it bpa_rs600 instead.
>
> Sold.
>
Maybe not. Maybe the client name is derived from the bindings name.
If so, we'll have to work around it. Please give it a try and let me know.
Guenter
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] hwmon: (pmbus): Add driver for BluTek BPA-RS600
2021-03-16 3:43 ` Guenter Roeck
@ 2021-03-16 4:21 ` Chris Packham
2021-03-16 4:50 ` Guenter Roeck
0 siblings, 1 reply; 9+ messages in thread
From: Chris Packham @ 2021-03-16 4:21 UTC (permalink / raw)
To: Guenter Roeck, robh+dt, jdelvare; +Cc: devicetree, linux-hwmon, linux-kernel
On 16/03/21 4:43 pm, Guenter Roeck wrote:
> On 3/15/21 7:35 PM, Chris Packham wrote:
>> The BPA-RS600 is a compact 600W AC to DC removable power supply module.
>>
>> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
>> ---
<snip>
>> +
>> +static int bpa_rs600_read_word_data(struct i2c_client *client, int page,
>> + int phase, int reg)+{
>> + int ret;
>> +
>> + if (page > 0)
>> + return -ENXIO;
>> +
>> + switch (reg) {
>> + case PMBUS_VIN_UV_FAULT_LIMIT:
>> + case PMBUS_VIN_OV_FAULT_LIMIT:
>> + case PMBUS_VOUT_UV_FAULT_LIMIT:
>> + case PMBUS_VOUT_OV_FAULT_LIMIT:
>> + ret = -ENXIO;
> Is that needed ? Why not -ENODATA ?
Basically these commands get responses on the bus but they don't have
valid data (nor are they documented in the datasheet). I'll add a
comment to that effect.
If I'm reading things correctly -ENODATA is a signal to
_pmbus_read_word_data use the "normal" read operation. So I need to
return something other than that. I found another driver (mp2975.c)
doing the same thing for what I assume are similar reasons so I went
with -ENXIO.
>
>> + break;
<snip>
> +
>> +static const struct i2c_device_id bpa_rs600_id[] = {
>> + { "bpa_rs600", 0 },
> Hmm, no, this has an underscore. Guess you'll have to use the trick from
> iio_hwmon.c or similar to generate a valid name.
>
> Oh, wait, this is a pmbus driver, and the pmbus core uses client->name.
> Maybe we need to add an optional strreplace() to the pmbus core.
Looking into this now.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] hwmon: (pmbus): Add driver for BluTek BPA-RS600
2021-03-16 4:21 ` Chris Packham
@ 2021-03-16 4:50 ` Guenter Roeck
0 siblings, 0 replies; 9+ messages in thread
From: Guenter Roeck @ 2021-03-16 4:50 UTC (permalink / raw)
To: Chris Packham, robh+dt, jdelvare; +Cc: devicetree, linux-hwmon, linux-kernel
On 3/15/21 9:21 PM, Chris Packham wrote:
>
> On 16/03/21 4:43 pm, Guenter Roeck wrote:
>> On 3/15/21 7:35 PM, Chris Packham wrote:
>>> The BPA-RS600 is a compact 600W AC to DC removable power supply module.
>>>
>>> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
>>> ---
> <snip>
>>> +
>>> +static int bpa_rs600_read_word_data(struct i2c_client *client, int page,
>>> + int phase, int reg)+{
>>> + int ret;
>>> +
>>> + if (page > 0)
>>> + return -ENXIO;
>>> +
>>> + switch (reg) {
>>> + case PMBUS_VIN_UV_FAULT_LIMIT:
>>> + case PMBUS_VIN_OV_FAULT_LIMIT:
>>> + case PMBUS_VOUT_UV_FAULT_LIMIT:
>>> + case PMBUS_VOUT_OV_FAULT_LIMIT:
>>> + ret = -ENXIO;
>> Is that needed ? Why not -ENODATA ?
>
> Basically these commands get responses on the bus but they don't have
> valid data (nor are they documented in the datasheet). I'll add a
> comment to that effect.
>
> If I'm reading things correctly -ENODATA is a signal to
> _pmbus_read_word_data use the "normal" read operation. So I need to
Correct.
> return something other than that. I found another driver (mp2975.c)
> doing the same thing for what I assume are similar reasons so I went
> with -ENXIO.
>
-ENXIO is ok, but please document it.
Thanks,
Guenter
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2021-03-16 4:51 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-16 2:35 [PATCH 1/2] dt-bindings: Add vendor prefix and trivial device for BluTek BPA-RS600 Chris Packham
2021-03-16 2:35 ` [PATCH 2/2] hwmon: (pmbus): Add driver " Chris Packham
2021-03-16 3:30 ` Chris Packham
2021-03-16 3:35 ` Guenter Roeck
2021-03-16 3:41 ` Chris Packham
2021-03-16 3:45 ` Guenter Roeck
2021-03-16 3:43 ` Guenter Roeck
2021-03-16 4:21 ` Chris Packham
2021-03-16 4:50 ` Guenter Roeck
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.