Re: [RESEND PATCH v4 5/6] hwmon: ahc1ec0-hwmon: Add sub-device hwmon for Advantech embedded controller

2020-11-25 Thread Guenter Roeck
On Wed, Nov 25, 2020 at 03:07:43PM +0800, Shihlun Lin wrote:
> This is one of sub-device driver for Advantech embedded controller
> AHC1EC0. This driver provides sysfs ABI for Advantech related
> applications to monitor the system status.
> 
> Signed-off-by: Shihlun Lin 
> ---
>  drivers/hwmon/Kconfig |8 +
>  drivers/hwmon/Makefile|1 +
>  drivers/hwmon/ahc1ec0-hwmon.c | 1504 +

Documentation and context is completely missing.

What does this driver have to do with Fintek chips ? We already have a driver
for those chips. Why would we want or need another driver for the same chips
under any circumstances ?

Also, new drivers shall use hwmon_device_register_with_info() to register
hwmon devices.

Guenter

>  3 files changed, 1513 insertions(+)
>  create mode 100644 drivers/hwmon/ahc1ec0-hwmon.c
> 
> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> index a850e4f0e0bd..577dd1dd60ee 100644
> --- a/drivers/hwmon/Kconfig
> +++ b/drivers/hwmon/Kconfig
> @@ -2095,6 +2095,14 @@ config SENSORS_INTEL_M10_BMC_HWMON
> sensors monitor various telemetry data of different components on the
> card, e.g. board temperature, FPGA core temperature/voltage/current.
>  
> +config SENSORS_AHC1EC0_HWMON
> + tristate "Advantech EC Hardware Monitor Function"
> + depends on MFD_AHC1EC0
> + help
> +   This is sub-device for Advantech embedded controller AHC1EC0. This
> +   driver provides the sysfs attributes for applications to monitor
> +   the system status.
> +
>  if ACPI
>  
>  comment "ACPI drivers"
> diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
> index 9db2903b61e5..e06ddc314b4a 100644
> --- a/drivers/hwmon/Makefile
> +++ b/drivers/hwmon/Makefile
> @@ -45,6 +45,7 @@ obj-$(CONFIG_SENSORS_ADT7411)   += adt7411.o
>  obj-$(CONFIG_SENSORS_ADT7462)+= adt7462.o
>  obj-$(CONFIG_SENSORS_ADT7470)+= adt7470.o
>  obj-$(CONFIG_SENSORS_ADT7475)+= adt7475.o
> +obj-$(CONFIG_SENSORS_AHC1EC0_HWMON)  += ahc1ec0-hwmon.o
>  obj-$(CONFIG_SENSORS_AMD_ENERGY) += amd_energy.o
>  obj-$(CONFIG_SENSORS_APPLESMC)   += applesmc.o
>  obj-$(CONFIG_SENSORS_ARM_SCMI)   += scmi-hwmon.o
> diff --git a/drivers/hwmon/ahc1ec0-hwmon.c b/drivers/hwmon/ahc1ec0-hwmon.c
> new file mode 100644
> index ..d71eb8e01422
> --- /dev/null
> +++ b/drivers/hwmon/ahc1ec0-hwmon.c
> @@ -0,0 +1,1504 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * HWMON Driver for Advantech controlling EC chip AHC1EC0
> + *
> + * Copyright (C) 2020, Advantech Automation Corp.
> + *
> + * Change Log:
> + *   Version 1.00 <11/05/2015> Jiangwei.Zhu
> + * - Initial version
> + *   Version 1.01 <03/04/2016> Jiangwei.Zhu
> + * - Support UNO-1372G-E3AE, TPC-1782H-433AE, APAX-5580-433AE
> + *   Version 1.02 <05/09/2016> Ji.Xu
> + * - Support APAX-5580-473AE/4C3AE
> + * - Modify the device name check method to fuzzy matching.
> + *   Version 1.03 <05/09/2017> Ji.Xu
> + * - Support UNO-2271G-E2xAE
> + * - Support UNO-2271G-E02xAE
> + * - Support ECU-4784
> + * - Support UNO-2473G-JxAE
> + *   Version 1.04 <09/20/2017> Ji.Xu
> + * - Support UNO-2484G-633xAE
> + * - Support UNO-2484G-653xAE
> + * - Support UNO-2484G-673xAE
> + * - Support UNO-2484G-733xAE
> + * - Support UNO-2484G-753xAE
> + * - Support UNO-2484G-773xAE
> + *   Version 1.05 <10/26/2017> Ji.Xu
> + * - Support PR/VR4
> + * - Support UNO-3283G-674AE
> + * - Support UNO-3285G-674AE
> + *   Version 1.06 <11/16/2017> Zhang.Yang
> + * - Support UNO-1372G-J021AE/J031AE
> + * - Support UNO-2372G
> + *   Version 1.07 <02/02/2018> Ji.Xu
> + * - Convert the driver to use new hwmon API after kernel version 4.10.0
> + * - Support EC TPC-B500-6??AE
> + * - Support EC TPC-5???T-6??AE
> + *   Version 1.08 <02/20/2019> Ji.Xu
> + * - Support EC UNO-420
> + * - Support EC TPC-B200-???AE
> + * - Support EC TPC-2???T-???AE
> + * - Support EC TPC-2???W-???AE
> + *   Version 1.09 <04/24/2020> Yao.Kang
> + * - Support EC UNO-2473G
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define ADVANTECH_EC_HWMON_VER "1.09"
> +#define ADVANTECH_EC_HWMON_DATE"04/24/2020"
> +
> +/* Addresses to scan */
> +static const unsigned short normal_i2c[] = { 0x2d, 0x2e, I2C_CLIENT_END };
> +
> +enum chips { f75373, f75375, f75387 };
> +
> +/* Fintek F75375 registers  */
> +#define F75375_REG_CONFIG0   0x0
> +#define F75375_REG_CONFIG1   0x1
> +#define F75375_REG_CONFIG2   0x2
> +#define F75375_REG_CONFIG3   0x3
> +#define F75375_REG_ADDR 

[RESEND PATCH v4 5/6] hwmon: ahc1ec0-hwmon: Add sub-device hwmon for Advantech embedded controller

2020-11-24 Thread Shihlun Lin
This is one of sub-device driver for Advantech embedded controller
AHC1EC0. This driver provides sysfs ABI for Advantech related
applications to monitor the system status.

Signed-off-by: Shihlun Lin 
---
 drivers/hwmon/Kconfig |8 +
 drivers/hwmon/Makefile|1 +
 drivers/hwmon/ahc1ec0-hwmon.c | 1504 +
 3 files changed, 1513 insertions(+)
 create mode 100644 drivers/hwmon/ahc1ec0-hwmon.c

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index a850e4f0e0bd..577dd1dd60ee 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -2095,6 +2095,14 @@ config SENSORS_INTEL_M10_BMC_HWMON
  sensors monitor various telemetry data of different components on the
  card, e.g. board temperature, FPGA core temperature/voltage/current.
 
+config SENSORS_AHC1EC0_HWMON
+   tristate "Advantech EC Hardware Monitor Function"
+   depends on MFD_AHC1EC0
+   help
+ This is sub-device for Advantech embedded controller AHC1EC0. This
+ driver provides the sysfs attributes for applications to monitor
+ the system status.
+
 if ACPI
 
 comment "ACPI drivers"
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 9db2903b61e5..e06ddc314b4a 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -45,6 +45,7 @@ obj-$(CONFIG_SENSORS_ADT7411) += adt7411.o
 obj-$(CONFIG_SENSORS_ADT7462)  += adt7462.o
 obj-$(CONFIG_SENSORS_ADT7470)  += adt7470.o
 obj-$(CONFIG_SENSORS_ADT7475)  += adt7475.o
+obj-$(CONFIG_SENSORS_AHC1EC0_HWMON)+= ahc1ec0-hwmon.o
 obj-$(CONFIG_SENSORS_AMD_ENERGY) += amd_energy.o
 obj-$(CONFIG_SENSORS_APPLESMC) += applesmc.o
 obj-$(CONFIG_SENSORS_ARM_SCMI) += scmi-hwmon.o
diff --git a/drivers/hwmon/ahc1ec0-hwmon.c b/drivers/hwmon/ahc1ec0-hwmon.c
new file mode 100644
index ..d71eb8e01422
--- /dev/null
+++ b/drivers/hwmon/ahc1ec0-hwmon.c
@@ -0,0 +1,1504 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * HWMON Driver for Advantech controlling EC chip AHC1EC0
+ *
+ * Copyright (C) 2020, Advantech Automation Corp.
+ *
+ * Change Log:
+ * Version 1.00 <11/05/2015> Jiangwei.Zhu
+ *   - Initial version
+ * Version 1.01 <03/04/2016> Jiangwei.Zhu
+ *   - Support UNO-1372G-E3AE, TPC-1782H-433AE, APAX-5580-433AE
+ * Version 1.02 <05/09/2016> Ji.Xu
+ *   - Support APAX-5580-473AE/4C3AE
+ *   - Modify the device name check method to fuzzy matching.
+ * Version 1.03 <05/09/2017> Ji.Xu
+ *   - Support UNO-2271G-E2xAE
+ *   - Support UNO-2271G-E02xAE
+ *   - Support ECU-4784
+ *   - Support UNO-2473G-JxAE
+ * Version 1.04 <09/20/2017> Ji.Xu
+ *   - Support UNO-2484G-633xAE
+ *   - Support UNO-2484G-653xAE
+ *   - Support UNO-2484G-673xAE
+ *   - Support UNO-2484G-733xAE
+ *   - Support UNO-2484G-753xAE
+ *   - Support UNO-2484G-773xAE
+ * Version 1.05 <10/26/2017> Ji.Xu
+ *   - Support PR/VR4
+ *   - Support UNO-3283G-674AE
+ *   - Support UNO-3285G-674AE
+ * Version 1.06 <11/16/2017> Zhang.Yang
+ *   - Support UNO-1372G-J021AE/J031AE
+ *   - Support UNO-2372G
+ * Version 1.07 <02/02/2018> Ji.Xu
+ *   - Convert the driver to use new hwmon API after kernel version 4.10.0
+ *   - Support EC TPC-B500-6??AE
+ *   - Support EC TPC-5???T-6??AE
+ * Version 1.08 <02/20/2019> Ji.Xu
+ *   - Support EC UNO-420
+ *   - Support EC TPC-B200-???AE
+ *   - Support EC TPC-2???T-???AE
+ *   - Support EC TPC-2???W-???AE
+ * Version 1.09 <04/24/2020> Yao.Kang
+ *   - Support EC UNO-2473G
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define ADVANTECH_EC_HWMON_VER "1.09"
+#define ADVANTECH_EC_HWMON_DATE"04/24/2020"
+
+/* Addresses to scan */
+static const unsigned short normal_i2c[] = { 0x2d, 0x2e, I2C_CLIENT_END };
+
+enum chips { f75373, f75375, f75387 };
+
+/* Fintek F75375 registers  */
+#define F75375_REG_CONFIG0 0x0
+#define F75375_REG_CONFIG1 0x1
+#define F75375_REG_CONFIG2 0x2
+#define F75375_REG_CONFIG3 0x3
+#define F75375_REG_ADDR0x4
+#define F75375_REG_INTR0x31
+#define F75375_CHIP_ID 0x5A
+#define F75375_REG_VERSION 0x5C
+#define F75375_REG_VENDOR  0x5D
+
+#define F75375_REG_TEMP(nr)(0x14 + (nr))
+#define F75387_REG_TEMP11_LSB(nr)  (0x1c + (nr))
+#define F75375_REG_TEMP_HIGH(nr)   (0x28 + (nr) * 2)
+#define F75375_REG_TEMP_HYST(nr)   (0x29 + (nr) * 2)
+
+/*
+ * Data structures and manipulation thereof
+ */
+
+struct f75375_data {
+   unsigned short addr;
+   struct device *hwmon_dev;
+
+   const char *name;
+