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

2020-11-24 Thread Shihlun Lin
This is one of sub-device driver for Advantech embedded controller
AHC1EC0. This driver provide watchdog functionality for Advantech
related applications to restart the system.

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

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index fd7968635e6d..82084e5af35e 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -1634,6 +1634,14 @@ config NIC7018_WDT
  To compile this driver as a module, choose M here: the module will be
  called nic7018_wdt.
 
+config AHC1EC0_WDT
+   tristate "Advantech EC Watchdog Function"
+   depends on MFD_AHC1EC0
+   help
+ This is sub-device for Advantech embedded controller AHC1EC0. This
+ driver provide watchdog functionality for Advantech related
+ applications to restart the system.
+
 # M68K Architecture
 
 config M54xx_WATCHDOG
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 071a2e50be98..93d15eed1f7c 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -145,6 +145,7 @@ obj-$(CONFIG_INTEL_MID_WATCHDOG) += intel-mid_wdt.o
 obj-$(CONFIG_INTEL_MEI_WDT) += mei_wdt.o
 obj-$(CONFIG_NI903X_WDT) += ni903x_wdt.o
 obj-$(CONFIG_NIC7018_WDT) += nic7018_wdt.o
+obj-$(CONFIG_AHC1EC0_WDT) += ahc1ec0-wdt.o
 obj-$(CONFIG_MLX_WDT) += mlx_wdt.o
 
 # M68K Architecture
diff --git a/drivers/watchdog/ahc1ec0-wdt.c b/drivers/watchdog/ahc1ec0-wdt.c
new file mode 100644
index ..3799b99f6423
--- /dev/null
+++ b/drivers/watchdog/ahc1ec0-wdt.c
@@ -0,0 +1,489 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Watchdog Driver for Advantech controlling EC chip AHC1EC0
+ *
+ * Copyright (C) 2020, Advantech Automation Corp.
+ *
+ * Change Log:
+ * Version 1.00 <10/10/2014> Sun.Lang
+ *- Initial version
+ *  Version 1.01 <12/30/2015> Jiangwei.Zhu
+ *- Modify adv_watchdog_init function to install the driver to
+ *- the support devices.
+ *  Version 1.02 <03/04/2016> Jiangwei.Zhu
+ *- Support UNO-1372G-E3AE, TPC-1782H-433AE, APAX-5580-433AE
+ *  Version 1.03 <05/09/2016> Ji.Xu
+ *- Support EC watchdog mini-board on UNO-3083G/3085G-D44E/D64E
+ *- APAX-5580-473AE/4C3AE.
+ *- Modify the timeout unit to 1 second.
+ *- Modify the device name check method to fuzzy matching.
+ *  Version 1.04 <06/28/2017> Ji.Xu
+ *- Support EC UNO-2271G-E2xAE.
+ *- Support EC UNO-2271G-E02xAE.
+ *- Support EC UNO-2473G-JxAE.
+ *- Support proc filesystem.
+ *  Version 1.05 <09/20/2017> Ji.Xu
+ *- Support EC UNO-2484G-633xAE.
+ *- Support EC UNO-2484G-653xAE.
+ *- Support EC UNO-2484G-673xAE.
+ *- Support EC UNO-2484G-733xAE.
+ *- Support EC UNO-2484G-753xAE.
+ *- Support EC UNO-2484G-773xAE.
+ *  Version 1.06 <10/26/2017> Ji.Xu
+ *- Support EC UNO-3283G-674AE
+ *- Support EC UNO-3285G-674AE
+ *  Version 1.07 <11/16/2017> Zhang.Yang
+ *- Support EC UNO-1372G-J021AE/J031AE
+ *- Support EC UNO-2372G
+ *  Version 1.08 <02/02/2018> Ji.Xu
+ *- Support EC TPC-B500-6??AE
+ *- Support EC TPC-5???T-6??AE
+ *- Support EC TPC-5???W-6??AE
+ *  Version 1.09 <03/20/2018> Ji.Xu
+ *- Support for compiling in kernel-4.10 and below.
+ *  Version 1.10 <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.11 <08/30/2019> Yao.Kang
+ *   - Support 32-bit programs on 64-bit kernel
+ *  Version 1.12 <12/03/2019> Jianfeng.dai
+ *   - Support support UNO-2372G watchdog
+ *  Version 1.13 <04/24/2020> Yao.Kang
+ *   - Support support 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 
+
+#define ADVANTECH_EC_WDT_VER"1.12"
+#define ADVANTECH_EC_WDT_DATE   "04/24/2020"
+
+#define PROCFS_MAX_SIZE 128
+
+static char adv_expect_close;
+static unsigned long advwdt_is_open;
+static unsigned short timeout = 450;
+static unsigned int major;
+struct mutex lock_ioctl;
+
+struct adv_wdt_info {
+   unsigned char chip_name[32];
+   unsigned char is_enable[8];
+   unsigned long current_timeout;
+};
+
+static struct adv_wdt_info wdt_data = {
+   .chip_name = "Advantech Embedded Controller",
+   .i

[RESEND PATCH v4 4/6] mfd: ahc1ec0: Add support for Advantech embedded controller

2020-11-24 Thread Shihlun Lin
AHC1EC0 is the embedded controller driver for Advantech industrial
products. This provides sub-devices such as hwmon and watchdog, and also
expose functions for sub-devices to read/write the value to embedded
controller.

Signed-off-by: Shihlun Lin 
---
 drivers/mfd/Kconfig |   10 +
 drivers/mfd/Makefile|2 +
 drivers/mfd/ahc1ec0.c   | 1405 +++
 include/linux/mfd/ahc1ec0.h |  338 +
 4 files changed, 1755 insertions(+)
 create mode 100644 drivers/mfd/ahc1ec0.c
 create mode 100644 include/linux/mfd/ahc1ec0.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 8b99a13669bf..1cc40217f798 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -2166,5 +2166,15 @@ config MFD_INTEL_M10_BMC
  additional drivers must be enabled in order to use the functionality
  of the device.
 
+config MFD_AHC1EC0
+   tristate "Advantech Embedded Controller Module"
+   depends on X86
+   select MFD_CORE
+   help
+ This is the core function that for Advantech EC drivers. It
+ includes the sub-devices such as hwmon, watchdog, etc. And also
+ provides expose functions for sub-devices to read/write the value
+ to embedded controller.
+
 endmenu
 endif
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 1780019d2474..80a9a2bdc3ba 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -267,3 +267,5 @@ obj-$(CONFIG_MFD_KHADAS_MCU)+= khadas-mcu.o
 obj-$(CONFIG_SGI_MFD_IOC3) += ioc3.o
 obj-$(CONFIG_MFD_SIMPLE_MFD_I2C)   += simple-mfd-i2c.o
 obj-$(CONFIG_MFD_INTEL_M10_BMC)   += intel-m10-bmc.o
+
+obj-$(CONFIG_MFD_AHC1EC0)  += ahc1ec0.o
diff --git a/drivers/mfd/ahc1ec0.c b/drivers/mfd/ahc1ec0.c
new file mode 100644
index ..768d2063bed1
--- /dev/null
+++ b/drivers/mfd/ahc1ec0.c
@@ -0,0 +1,1405 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Base driver for Advantech controlling EC chip AHC1EC0
+ *
+ * Copyright (C) 2020, Advantech Automation Corp.
+ *
+ * Change Log:
+ *  Version 1.00 <10/10/2014> Sun.Lang
+ *  - Initial version
+ *  Version 1.01 <11/05/2015> Jiangwei.Zhu
+ *  - Modify read_ad_value() function.
+ *  - Add smbus_read_byte() function.
+ *  - Add smbus_write_byte() function.
+ *  - Add wait_smbus_protocol_finish() function.
+ *  Version 1.02 <03/04/2016> Jiangwei.Zhu
+ *  - Add smbus_read_word() function.
+ *  Version 1.03 <01/22/2017> Ji.Xu
+ *  - Add detect to Advantech porduct name "ECU".
+ *  Version 1.04 <09/20/2017> Ji.Xu
+ *  - Update to support detect Advantech product name in UEFI
+ *BIOS(DMI).
+ *  Version 1.05 <11/02/2017> Ji.Xu
+ *  - Fixed issue: Cache coherency error when exec 
'ioremap_uncache()'
+ *in kernel-4.10.
+ *  Version 2.00 <11/04/2020> Shihlun.Lin
+ *  - Update: Replace ioremap_nocache() with ioremap_uc() since
+ *ioremap_uc() was used on the entire PCI BAR.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define ADVANTECH_EC_NAME  "ahc1ec0"
+#define ADVANTECH_EC_MFD_VER"2.0.0"
+#define ADVANTECH_EC_MFD_DATE   "11/04/2020"
+
+struct mutex lock;
+
+enum {
+   ADVEC_SUBDEV_BRIGHTNESS = 0,
+   ADVEC_SUBDEV_EEPROM,
+   ADVEC_SUBDEV_GPIO,
+   ADVEC_SUBDEV_HWMON,
+   ADVEC_SUBDEV_LED,
+   ADVEC_SUBDEV_WDT,
+   ADVEC_SUBDEV_MAX,
+};
+
+static int wait_ibf(void)
+{
+   int i;
+
+   for (i = 0; i < EC_MAX_TIMEOUT_COUNT; i++) {
+   if ((inb(EC_COMMAND_PORT) & 0x02) == 0)
+   return 0;
+
+   udelay(EC_UDELAY_TIME);
+   }
+
+   return -ETIMEDOUT;
+}
+
+/* Wait OBF (Output buffer full) set */
+static int wait_obf(void)
+{
+   int i;
+
+   for (i = 0; i < EC_MAX_TIMEOUT_COUNT; i++) {
+   if ((inb(EC_COMMAND_PORT) & 0x01) != 0)
+   return 0;
+
+   udelay(EC_UDELAY_TIME);
+   }
+
+   return -ETIMEDOUT;
+}
+
+/* Read data from EC HW ram */
+static int read_hw_ram(uchar addr, uchar *data)
+{
+   int ret;
+
+   mutex_lock();
+
+   /* Step 0. Wait IBF clear */
+   ret = wait_ibf();
+   if (ret)
+   goto error;
+
+   /* Step 1. Send "read EC HW ram" command to EC Command port */
+   outb(EC_HW_RAM_READ, EC_COMMAND_PORT);
+
+   /* Step 2. Wait IBF clear */
+   ret = wait_ibf();
+   if (ret)
+   goto error;
+
+   /* Step 3. Send "EC HW ram" address to EC Data port */
+   outb(addr, EC_STATUS_PORT);
+
+   /* Step

[RESEND PATCH v4 3/6] dt-bindings: mfd: ahc1ec0.yaml: Add Advantech embedded controller - AHC1EC0

2020-11-24 Thread Shihlun Lin
Add DT binding schema for Advantech embedded controller AHC1EC0.

Signed-off-by: Shihlun Lin 
---
 .../devicetree/bindings/mfd/ahc1ec0.yaml  | 70 +++
 1 file changed, 70 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/ahc1ec0.yaml

diff --git a/Documentation/devicetree/bindings/mfd/ahc1ec0.yaml 
b/Documentation/devicetree/bindings/mfd/ahc1ec0.yaml
new file mode 100644
index ..a73d1cf65a4c
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/ahc1ec0.yaml
@@ -0,0 +1,70 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/ahc1ec0.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Advantech Embedded Controller (AHC1EC0)
+
+maintainers:
+  - Shihlun Lin 
+  - Campion Kang 
+
+description: |
+  AHC1EC0 is one of the embedded controllers used by Advantech to provide 
several
+  functions such as watchdog, hwmon, brightness, etc. Advantech related 
applications
+  can control the whole system via these functions.
+
+properties:
+  compatible:
+const: advantech,ahc1ec0
+
+  advantech,sub-dev-nb:
+description:
+  The number of sub-devices specified in the platform.
+$ref: /schemas/types.yaml#/definitions/uint32
+maxItems: 1
+
+  advantech,sub-dev:
+description:
+  A list of the sub-devices supported in the platform. Defines for the
+  appropriate values can found in dt-bindings/mfd/ahc1ec0.h.
+$ref: "/schemas/types.yaml#/definitions/uint32-array"
+minItems: 1
+maxItems: 6
+
+  advantech,hwmon-profile:
+description:
+  The number of sub-devices specified in the platform. Defines for the
+  hwmon profiles can found in dt-bindings/mfd/ahc1ec0.
+$ref: /schemas/types.yaml#/definitions/uint32
+maxItems: 1
+
+required:
+  - compatible
+  - advantech,sub-dev-nb
+  - advantech,sub-dev
+
+if:
+  properties:
+advantech,sub-dev:
+  contains:
+const: 0x3
+then:
+  required:
+- advantech,hwmon-profile
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+ahc1ec0 {
+compatible = "advantech,ahc1ec0";
+
+advantech,sub-dev-nb = <2>;
+advantech,sub-dev = ;
+
+advantech,hwmon-profile = ;
+};
-- 
2.17.1



[RESEND PATCH v4 1/6] MAINTAINERS: Add Advantech embedded controller entry

2020-11-24 Thread Shihlun Lin
Add Advantech embedded controller entry

Signed-off-by: Shihlun Lin 
---
 MAINTAINERS | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 94ac10a153c7..c1fe5233b469 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -562,6 +562,17 @@ S: Maintained
 F: Documentation/scsi/advansys.rst
 F: drivers/scsi/advansys.c
 
+ADVANTECH EMBEDDED CONTROLLER DRIVER
+M: Shihlun Lin 
+M: Campion Kang 
+L: linux-kernel@vger.kernel.org
+S: Maintained
+F: Documentation/devicetree/bindings/mfd/ahc1ec0.yaml
+F: drivers/mfd/ahc1ec0-hwmon.c
+F: drivers/mfd/ahc1ec0-wdt.c
+F: drivers/mfd/ahc1ec0.c
+F: include/dt-bindings/mfd/ahc1ec0.h
+
 ADXL34X THREE-AXIS DIGITAL ACCELEROMETER DRIVER (ADXL345/ADXL346)
 M: Michael Hennerich 
 S: Supported

base-commit: 3d5e28bff7ad55aea081c1af516cc1c94a5eca7d
-- 
2.17.1



[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 f75

[RESEND PATCH v4 2/6] mfd: ahc1ec0: Add Advantech EC include file used by dt-bindings

2020-11-24 Thread Shihlun Lin
This files defines the sud-device types and hwmon profiles support by
Advantech embedded controller.

Signed-off-by: Shihlun Lin 
---
 include/dt-bindings/mfd/ahc1ec0.h | 25 +
 1 file changed, 25 insertions(+)
 create mode 100644 include/dt-bindings/mfd/ahc1ec0.h

diff --git a/include/dt-bindings/mfd/ahc1ec0.h 
b/include/dt-bindings/mfd/ahc1ec0.h
new file mode 100644
index ..389a7a7f8f02
--- /dev/null
+++ b/include/dt-bindings/mfd/ahc1ec0.h
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Device Tree defines for Advantech Embedded Controller (AHC1EC0)
+ */
+
+#ifndef _DT_BINDINGS_MFD_AHC1EC0_H
+#define _DT_BINDINGS_MFD_AHC1EC0_H
+
+/* Sub-device Definitions */
+#define AHC1EC0_SUBDEV_BRIGHTNESS 0x0
+#define AHC1EC0_SUBDEV_EEPROM 0x1
+#define AHC1EC0_SUBDEV_GPIO   0x2
+#define AHC1EC0_SUBDEV_HWMON  0x3
+#define AHC1EC0_SUBDEV_LED0x4
+#define AHC1EC0_SUBDEV_WDT0x5
+
+/* HWMON Profile Definitions */
+#define AHC1EC0_HWMON_PRO_TEMPLATE 0x0
+#define AHC1EC0_HWMON_PRO_TPC5XXX  0x1
+#define AHC1EC0_HWMON_PRO_PRVR40x2
+#define AHC1EC0_HWMON_PRO_UNO2271G 0x3
+#define AHC1EC0_HWMON_PRO_UNO1172A 0x4
+#define AHC1EC0_HWMON_PRO_UNO1372G 0x5
+
+#endif /* _DT_BINDINGS_MFD_AHC1EC0_H */
-- 
2.17.1



[PATCH v4 4/6] mfd: ahc1ec0: Add support for Advantech embedded controller

2020-11-12 Thread Shihlun Lin
AHC1EC0 is the embedded controller driver for Advantech industrial
products. This provides sub-devices such as hwmon and watchdog, and also
expose functions for sub-devices to read/write the value to embedded
controller.

Signed-off-by: Shihlun Lin 
---
 drivers/mfd/Kconfig |   10 +
 drivers/mfd/Makefile|2 +
 drivers/mfd/ahc1ec0.c   | 1405 +++
 include/linux/mfd/ahc1ec0.h |  338 +
 4 files changed, 1755 insertions(+)
 create mode 100644 drivers/mfd/ahc1ec0.c
 create mode 100644 include/linux/mfd/ahc1ec0.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 8b99a13669bf..1cc40217f798 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -2166,5 +2166,15 @@ config MFD_INTEL_M10_BMC
  additional drivers must be enabled in order to use the functionality
  of the device.
 
+config MFD_AHC1EC0
+   tristate "Advantech Embedded Controller Module"
+   depends on X86
+   select MFD_CORE
+   help
+ This is the core function that for Advantech EC drivers. It
+ includes the sub-devices such as hwmon, watchdog, etc. And also
+ provides expose functions for sub-devices to read/write the value
+ to embedded controller.
+
 endmenu
 endif
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 1780019d2474..80a9a2bdc3ba 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -267,3 +267,5 @@ obj-$(CONFIG_MFD_KHADAS_MCU)+= khadas-mcu.o
 obj-$(CONFIG_SGI_MFD_IOC3) += ioc3.o
 obj-$(CONFIG_MFD_SIMPLE_MFD_I2C)   += simple-mfd-i2c.o
 obj-$(CONFIG_MFD_INTEL_M10_BMC)   += intel-m10-bmc.o
+
+obj-$(CONFIG_MFD_AHC1EC0)  += ahc1ec0.o
diff --git a/drivers/mfd/ahc1ec0.c b/drivers/mfd/ahc1ec0.c
new file mode 100644
index ..768d2063bed1
--- /dev/null
+++ b/drivers/mfd/ahc1ec0.c
@@ -0,0 +1,1405 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Base driver for Advantech controlling EC chip AHC1EC0
+ *
+ * Copyright (C) 2020, Advantech Automation Corp.
+ *
+ * Change Log:
+ *  Version 1.00 <10/10/2014> Sun.Lang
+ *  - Initial version
+ *  Version 1.01 <11/05/2015> Jiangwei.Zhu
+ *  - Modify read_ad_value() function.
+ *  - Add smbus_read_byte() function.
+ *  - Add smbus_write_byte() function.
+ *  - Add wait_smbus_protocol_finish() function.
+ *  Version 1.02 <03/04/2016> Jiangwei.Zhu
+ *  - Add smbus_read_word() function.
+ *  Version 1.03 <01/22/2017> Ji.Xu
+ *  - Add detect to Advantech porduct name "ECU".
+ *  Version 1.04 <09/20/2017> Ji.Xu
+ *  - Update to support detect Advantech product name in UEFI
+ *BIOS(DMI).
+ *  Version 1.05 <11/02/2017> Ji.Xu
+ *  - Fixed issue: Cache coherency error when exec 
'ioremap_uncache()'
+ *in kernel-4.10.
+ *  Version 2.00 <11/04/2020> Shihlun.Lin
+ *  - Update: Replace ioremap_nocache() with ioremap_uc() since
+ *ioremap_uc() was used on the entire PCI BAR.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define ADVANTECH_EC_NAME  "ahc1ec0"
+#define ADVANTECH_EC_MFD_VER"2.0.0"
+#define ADVANTECH_EC_MFD_DATE   "11/04/2020"
+
+struct mutex lock;
+
+enum {
+   ADVEC_SUBDEV_BRIGHTNESS = 0,
+   ADVEC_SUBDEV_EEPROM,
+   ADVEC_SUBDEV_GPIO,
+   ADVEC_SUBDEV_HWMON,
+   ADVEC_SUBDEV_LED,
+   ADVEC_SUBDEV_WDT,
+   ADVEC_SUBDEV_MAX,
+};
+
+static int wait_ibf(void)
+{
+   int i;
+
+   for (i = 0; i < EC_MAX_TIMEOUT_COUNT; i++) {
+   if ((inb(EC_COMMAND_PORT) & 0x02) == 0)
+   return 0;
+
+   udelay(EC_UDELAY_TIME);
+   }
+
+   return -ETIMEDOUT;
+}
+
+/* Wait OBF (Output buffer full) set */
+static int wait_obf(void)
+{
+   int i;
+
+   for (i = 0; i < EC_MAX_TIMEOUT_COUNT; i++) {
+   if ((inb(EC_COMMAND_PORT) & 0x01) != 0)
+   return 0;
+
+   udelay(EC_UDELAY_TIME);
+   }
+
+   return -ETIMEDOUT;
+}
+
+/* Read data from EC HW ram */
+static int read_hw_ram(uchar addr, uchar *data)
+{
+   int ret;
+
+   mutex_lock();
+
+   /* Step 0. Wait IBF clear */
+   ret = wait_ibf();
+   if (ret)
+   goto error;
+
+   /* Step 1. Send "read EC HW ram" command to EC Command port */
+   outb(EC_HW_RAM_READ, EC_COMMAND_PORT);
+
+   /* Step 2. Wait IBF clear */
+   ret = wait_ibf();
+   if (ret)
+   goto error;
+
+   /* Step 3. Send "EC HW ram" address to EC Data port */
+   outb(addr, EC_STATUS_PORT);
+
+   /* Step

[PATCH v4 3/6] dt-bindings: mfd: ahc1ec0.yaml: Add Advantech embedded controller - AHC1EC0

2020-11-12 Thread Shihlun Lin
Add DT binding schema for Advantech embedded controller AHC1EC0.

Signed-off-by: Shihlun Lin 
---
 .../devicetree/bindings/mfd/ahc1ec0.yaml  | 70 +++
 1 file changed, 70 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/ahc1ec0.yaml

diff --git a/Documentation/devicetree/bindings/mfd/ahc1ec0.yaml 
b/Documentation/devicetree/bindings/mfd/ahc1ec0.yaml
new file mode 100644
index ..a73d1cf65a4c
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/ahc1ec0.yaml
@@ -0,0 +1,70 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/ahc1ec0.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Advantech Embedded Controller (AHC1EC0)
+
+maintainers:
+  - Shihlun Lin 
+  - Campion Kang 
+
+description: |
+  AHC1EC0 is one of the embedded controllers used by Advantech to provide 
several
+  functions such as watchdog, hwmon, brightness, etc. Advantech related 
applications
+  can control the whole system via these functions.
+
+properties:
+  compatible:
+const: advantech,ahc1ec0
+
+  advantech,sub-dev-nb:
+description:
+  The number of sub-devices specified in the platform.
+$ref: /schemas/types.yaml#/definitions/uint32
+maxItems: 1
+
+  advantech,sub-dev:
+description:
+  A list of the sub-devices supported in the platform. Defines for the
+  appropriate values can found in dt-bindings/mfd/ahc1ec0.h.
+$ref: "/schemas/types.yaml#/definitions/uint32-array"
+minItems: 1
+maxItems: 6
+
+  advantech,hwmon-profile:
+description:
+  The number of sub-devices specified in the platform. Defines for the
+  hwmon profiles can found in dt-bindings/mfd/ahc1ec0.
+$ref: /schemas/types.yaml#/definitions/uint32
+maxItems: 1
+
+required:
+  - compatible
+  - advantech,sub-dev-nb
+  - advantech,sub-dev
+
+if:
+  properties:
+advantech,sub-dev:
+  contains:
+const: 0x3
+then:
+  required:
+- advantech,hwmon-profile
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+ahc1ec0 {
+compatible = "advantech,ahc1ec0";
+
+advantech,sub-dev-nb = <2>;
+advantech,sub-dev = ;
+
+advantech,hwmon-profile = ;
+};
-- 
2.17.1



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

2020-11-12 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 f75

[PATCH v4 6/6] watchdog: ahc1ec0-wdt: Add sub-device watchdog for Advantech embedded controller

2020-11-12 Thread Shihlun Lin
This is one of sub-device driver for Advantech embedded controller
AHC1EC0. This driver provide watchdog functionality for Advantech
related applications to restart the system.

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

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index fd7968635e6d..82084e5af35e 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -1634,6 +1634,14 @@ config NIC7018_WDT
  To compile this driver as a module, choose M here: the module will be
  called nic7018_wdt.
 
+config AHC1EC0_WDT
+   tristate "Advantech EC Watchdog Function"
+   depends on MFD_AHC1EC0
+   help
+ This is sub-device for Advantech embedded controller AHC1EC0. This
+ driver provide watchdog functionality for Advantech related
+ applications to restart the system.
+
 # M68K Architecture
 
 config M54xx_WATCHDOG
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 071a2e50be98..93d15eed1f7c 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -145,6 +145,7 @@ obj-$(CONFIG_INTEL_MID_WATCHDOG) += intel-mid_wdt.o
 obj-$(CONFIG_INTEL_MEI_WDT) += mei_wdt.o
 obj-$(CONFIG_NI903X_WDT) += ni903x_wdt.o
 obj-$(CONFIG_NIC7018_WDT) += nic7018_wdt.o
+obj-$(CONFIG_AHC1EC0_WDT) += ahc1ec0-wdt.o
 obj-$(CONFIG_MLX_WDT) += mlx_wdt.o
 
 # M68K Architecture
diff --git a/drivers/watchdog/ahc1ec0-wdt.c b/drivers/watchdog/ahc1ec0-wdt.c
new file mode 100644
index ..3799b99f6423
--- /dev/null
+++ b/drivers/watchdog/ahc1ec0-wdt.c
@@ -0,0 +1,489 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Watchdog Driver for Advantech controlling EC chip AHC1EC0
+ *
+ * Copyright (C) 2020, Advantech Automation Corp.
+ *
+ * Change Log:
+ * Version 1.00 <10/10/2014> Sun.Lang
+ *- Initial version
+ *  Version 1.01 <12/30/2015> Jiangwei.Zhu
+ *- Modify adv_watchdog_init function to install the driver to
+ *- the support devices.
+ *  Version 1.02 <03/04/2016> Jiangwei.Zhu
+ *- Support UNO-1372G-E3AE, TPC-1782H-433AE, APAX-5580-433AE
+ *  Version 1.03 <05/09/2016> Ji.Xu
+ *- Support EC watchdog mini-board on UNO-3083G/3085G-D44E/D64E
+ *- APAX-5580-473AE/4C3AE.
+ *- Modify the timeout unit to 1 second.
+ *- Modify the device name check method to fuzzy matching.
+ *  Version 1.04 <06/28/2017> Ji.Xu
+ *- Support EC UNO-2271G-E2xAE.
+ *- Support EC UNO-2271G-E02xAE.
+ *- Support EC UNO-2473G-JxAE.
+ *- Support proc filesystem.
+ *  Version 1.05 <09/20/2017> Ji.Xu
+ *- Support EC UNO-2484G-633xAE.
+ *- Support EC UNO-2484G-653xAE.
+ *- Support EC UNO-2484G-673xAE.
+ *- Support EC UNO-2484G-733xAE.
+ *- Support EC UNO-2484G-753xAE.
+ *- Support EC UNO-2484G-773xAE.
+ *  Version 1.06 <10/26/2017> Ji.Xu
+ *- Support EC UNO-3283G-674AE
+ *- Support EC UNO-3285G-674AE
+ *  Version 1.07 <11/16/2017> Zhang.Yang
+ *- Support EC UNO-1372G-J021AE/J031AE
+ *- Support EC UNO-2372G
+ *  Version 1.08 <02/02/2018> Ji.Xu
+ *- Support EC TPC-B500-6??AE
+ *- Support EC TPC-5???T-6??AE
+ *- Support EC TPC-5???W-6??AE
+ *  Version 1.09 <03/20/2018> Ji.Xu
+ *- Support for compiling in kernel-4.10 and below.
+ *  Version 1.10 <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.11 <08/30/2019> Yao.Kang
+ *   - Support 32-bit programs on 64-bit kernel
+ *  Version 1.12 <12/03/2019> Jianfeng.dai
+ *   - Support support UNO-2372G watchdog
+ *  Version 1.13 <04/24/2020> Yao.Kang
+ *   - Support support 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 
+
+#define ADVANTECH_EC_WDT_VER"1.12"
+#define ADVANTECH_EC_WDT_DATE   "04/24/2020"
+
+#define PROCFS_MAX_SIZE 128
+
+static char adv_expect_close;
+static unsigned long advwdt_is_open;
+static unsigned short timeout = 450;
+static unsigned int major;
+struct mutex lock_ioctl;
+
+struct adv_wdt_info {
+   unsigned char chip_name[32];
+   unsigned char is_enable[8];
+   unsigned long current_timeout;
+};
+
+static struct adv_wdt_info wdt_data = {
+   .chip_name = "Advantech Embedded Controller",
+   .i

[PATCH v4 2/6] mfd: ahc1ec0: Add Advantech EC include file used by dt-bindings

2020-11-12 Thread Shihlun Lin
This files defines the sud-device types and hwmon profiles support by
Advantech embedded controller.

Signed-off-by: Shihlun Lin 
---
 include/dt-bindings/mfd/ahc1ec0.h | 25 +
 1 file changed, 25 insertions(+)
 create mode 100644 include/dt-bindings/mfd/ahc1ec0.h

diff --git a/include/dt-bindings/mfd/ahc1ec0.h 
b/include/dt-bindings/mfd/ahc1ec0.h
new file mode 100644
index ..389a7a7f8f02
--- /dev/null
+++ b/include/dt-bindings/mfd/ahc1ec0.h
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Device Tree defines for Advantech Embedded Controller (AHC1EC0)
+ */
+
+#ifndef _DT_BINDINGS_MFD_AHC1EC0_H
+#define _DT_BINDINGS_MFD_AHC1EC0_H
+
+/* Sub-device Definitions */
+#define AHC1EC0_SUBDEV_BRIGHTNESS 0x0
+#define AHC1EC0_SUBDEV_EEPROM 0x1
+#define AHC1EC0_SUBDEV_GPIO   0x2
+#define AHC1EC0_SUBDEV_HWMON  0x3
+#define AHC1EC0_SUBDEV_LED0x4
+#define AHC1EC0_SUBDEV_WDT0x5
+
+/* HWMON Profile Definitions */
+#define AHC1EC0_HWMON_PRO_TEMPLATE 0x0
+#define AHC1EC0_HWMON_PRO_TPC5XXX  0x1
+#define AHC1EC0_HWMON_PRO_PRVR40x2
+#define AHC1EC0_HWMON_PRO_UNO2271G 0x3
+#define AHC1EC0_HWMON_PRO_UNO1172A 0x4
+#define AHC1EC0_HWMON_PRO_UNO1372G 0x5
+
+#endif /* _DT_BINDINGS_MFD_AHC1EC0_H */
-- 
2.17.1



[PATCH v4 1/6] MAINTAINERS: Add Advantech embedded controller entry

2020-11-12 Thread Shihlun Lin
Add Advantech embedded controller entry

Signed-off-by: Shihlun Lin 
---
 MAINTAINERS | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 94ac10a153c7..c1fe5233b469 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -562,6 +562,17 @@ S: Maintained
 F: Documentation/scsi/advansys.rst
 F: drivers/scsi/advansys.c
 
+ADVANTECH EMBEDDED CONTROLLER DRIVER
+M: Shihlun Lin 
+M: Campion Kang 
+L: linux-kernel@vger.kernel.org
+S: Maintained
+F: Documentation/devicetree/bindings/mfd/ahc1ec0.yaml
+F: drivers/mfd/ahc1ec0-hwmon.c
+F: drivers/mfd/ahc1ec0-wdt.c
+F: drivers/mfd/ahc1ec0.c
+F: include/dt-bindings/mfd/ahc1ec0.h
+
 ADXL34X THREE-AXIS DIGITAL ACCELEROMETER DRIVER (ADXL345/ADXL346)
 M: Michael Hennerich 
 S: Supported

base-commit: 3d5e28bff7ad55aea081c1af516cc1c94a5eca7d
-- 
2.17.1



[PATCH v3 6/6] mfd: ahc1ec0-wdt: Add sub-device watchdog for Advantech embedded controller

2020-11-01 Thread Shihlun Lin
This is one of sub-device driver for Advantech embedded controller
AHC1EC0. This driver provide watchdog functionality for Advantech
related applications to restart the system.

Signed-off-by: Shihlun Lin 
Reported-by: kernel test robot 
---
 drivers/mfd/Kconfig   |   4 +
 drivers/mfd/Makefile  |   1 +
 drivers/mfd/ahc1ec0-wdt.c | 502 ++
 3 files changed, 507 insertions(+)
 create mode 100644 drivers/mfd/ahc1ec0-wdt.c

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 52ca49b211fc..b6b2122fb757 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -2183,5 +2183,9 @@ config MFD_AHC1EC0_HWMON
  driver provides the sysfs attribues for applications to monitor
  the system status.
 
+config MFD_AHC1EC0_WDT
+   tristate "Advantech EC Watchdog Function"
+   depends on MFD_AHC1EC0
+
 endmenu
 endif
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index eb645db817b5..263e6273729c 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -270,3 +270,4 @@ obj-$(CONFIG_MFD_INTEL_M10_BMC)   += intel-m10-bmc.o
 
 obj-$(CONFIG_MFD_AHC1EC0)  += ahc1ec0.o
 obj-$(CONFIG_MFD_AHC1EC0_HWMON)+= ahc1ec0-hwmon.o
+obj-$(CONFIG_MFD_AHC1EC0_WDT)  += ahc1ec0-wdt.o
diff --git a/drivers/mfd/ahc1ec0-wdt.c b/drivers/mfd/ahc1ec0-wdt.c
new file mode 100644
index ..c275b41d873b
--- /dev/null
+++ b/drivers/mfd/ahc1ec0-wdt.c
@@ -0,0 +1,502 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2018, Advantech Automation Corp.
+ * THIS IS AN UNPUBLISHED WORK CONTAINING CONFIDENTIAL AND PROPRIETARY
+ *  INFORMATION WHICH IS THE PROPERTY OF ADVANTECH AUTOMATION CORP.
+ *
+ *   ANY DISCLOSURE, USE, OR REPRODUCTION, WITHOUT WRITTEN AUTHORIZATION FROM
+ *  ADVANTECH AUTOMATION CORP., IS STRICTLY PROHIBITED.
+ *
+ *
+ * File:ahc1ec0-wdt.c
+ * Version: 1.00  <10/10/2014>
+ * Author:  Sun.Lang
+ *
+ * Description: The ahc1ec0-wdt is driver for controlling EC watchdog.
+ *
+ *
+ * Status:  working
+ *
+ * Change Log:
+ *  Version 1.00 <10/10/2014> Sun.Lang
+ *  - Initial version
+ *  Version 1.01 <12/30/2015> Jiangwei.Zhu
+ *  - Modify adv_watchdog_init function to install the driver to
+ *  - the support devices.
+ *  Version 1.02 <03/04/2016> Jiangwei.Zhu
+ *  - Support UNO-1372G-E3AE, TPC-1782H-433AE, APAX-5580-433AE
+ *  Version 1.03 <05/09/2016> Ji.Xu
+ *  - Support EC watchdog mini-board on UNO-3083G/3085G-D44E/D64E
+ *  - APAX-5580-473AE/4C3AE.
+ *  - Modify the timeout unit to 1 second.
+ *  - Modify the device name check method to fuzzy matching.
+ *  Version 1.04 <06/28/2017> Ji.Xu
+ *  - Support EC UNO-2271G-E2xAE.
+ *  - Support EC UNO-2271G-E02xAE.
+ *  - Support EC UNO-2473G-JxAE.
+ *  - Support proc filesystem.
+ *  Version 1.05 <09/20/2017> Ji.Xu
+ *  - Support EC UNO-2484G-633xAE.
+ *  - Support EC UNO-2484G-653xAE.
+ *  - Support EC UNO-2484G-673xAE.
+ *  - Support EC UNO-2484G-733xAE.
+ *  - Support EC UNO-2484G-753xAE.
+ *  - Support EC UNO-2484G-773xAE.
+ *  Version 1.06 <10/26/2017> Ji.Xu
+ *  - Support EC UNO-3283G-674AE
+ *  - Support EC UNO-3285G-674AE
+ *  Version 1.07 <11/16/2017> Zhang.Yang
+ *  - Support EC UNO-1372G-J021AE/J031AE
+ *  - Support EC UNO-2372G
+ *  Version 1.08 <02/02/2018> Ji.Xu
+ *  - Support EC TPC-B500-6??AE
+ *  - Support EC TPC-5???T-6??AE
+ *  - Support EC TPC-5???W-6??AE
+ *  Version 1.09 <03/20/2018> Ji.Xu
+ *  - Support for compiling in kernel-4.10 and below.
+ *  Version 1.10 <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.11 <08/30/2019> Yao.Kang
+ * - Support 32-bit programs on 64-bit kernel
+ *  Version 1.12 <12/03/2019> Jianfeng.dai
+ * - Support support UNO-2372G watchdog
+ *  Version 1.13 <04/24/2020> Yao.Kang
+ * - Support support UNO-2473G
+ 
**/
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#includ

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

2020-10-29 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 
Reported-by: kernel test robot 
---
 drivers/mfd/Kconfig |8 +
 drivers/mfd/Makefile|1 +
 drivers/mfd/ahc1ec0-hwmon.c | 1514 +++
 3 files changed, 1523 insertions(+)
 create mode 100644 drivers/mfd/ahc1ec0-hwmon.c

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 965bcafbe5b2..52ca49b211fc 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -2175,5 +2175,13 @@ config MFD_AHC1EC0
  provides expose functions for sub-devices to read/write the value
  to embedded controller.
 
+config MFD_AHC1EC0_HWMON
+   tristate "Advantech EC Hareware Monitor Function"
+   depends on MFD_AHC1EC0
+   help
+ This is sub-device for Advantech embedded controller AHC1EC0. This
+ driver provides the sysfs attribues for applications to monitor
+ the system status.
+
 endmenu
 endif
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 80a9a2bdc3ba..eb645db817b5 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -269,3 +269,4 @@ obj-$(CONFIG_MFD_SIMPLE_MFD_I2C)+= simple-mfd-i2c.o
 obj-$(CONFIG_MFD_INTEL_M10_BMC)   += intel-m10-bmc.o
 
 obj-$(CONFIG_MFD_AHC1EC0)  += ahc1ec0.o
+obj-$(CONFIG_MFD_AHC1EC0_HWMON)+= ahc1ec0-hwmon.o
diff --git a/drivers/mfd/ahc1ec0-hwmon.c b/drivers/mfd/ahc1ec0-hwmon.c
new file mode 100644
index ..3e493b040b4a
--- /dev/null
+++ b/drivers/mfd/ahc1ec0-hwmon.c
@@ -0,0 +1,1514 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2018, Advantech Automation Corp.
+ * THIS IS AN UNPUBLISHED WORK CONTAINING CONFIDENTIAL AND PROPRIETARY
+ * INFORMATION WHICH IS THE PROPERTY OF ADVANTECH AUTOMATION CORP.
+ *
+ * ANY DISCLOSURE, USE, OR REPRODUCTION, WITHOUT WRITTEN AUTHORIZATION FROM
+ * ADVANTECH AUTOMATION CORP., IS STRICTLY PROHIBITED.
+ *
+ *
+ * File:ahc1ec0-hwmon.c
+ * Version: 1.00  <11/05/2015>
+ * Author:  Jiangwei.Zhu
+ *
+ * Description: The ahc1ec0-hwmon driver is for controlling EC hwmon.
+ *
+ * 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_

[PATCH v3 3/6] dt-bindings: mfd: ahc1ec0.yaml: Add Advantech Embedded Controll - AHC1EC0

2020-10-29 Thread Shihlun Lin
Add DT binding schema for Advantech embedded controller AHC1EC0.

Signed-off-by: Shihlun Lin 
---
 .../devicetree/bindings/mfd/ahc1ec0.yaml  | 70 +++
 1 file changed, 70 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/ahc1ec0.yaml

diff --git a/Documentation/devicetree/bindings/mfd/ahc1ec0.yaml 
b/Documentation/devicetree/bindings/mfd/ahc1ec0.yaml
new file mode 100644
index ..a73d1cf65a4c
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/ahc1ec0.yaml
@@ -0,0 +1,70 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/ahc1ec0.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Advantech Embedded Controller (AHC1EC0)
+
+maintainers:
+  - Shihlun Lin 
+  - Campion Kang 
+
+description: |
+  AHC1EC0 is one of the embedded controllers used by Advantech to provide 
several
+  functions such as watchdog, hwmon, brightness, etc. Advantech related 
applications
+  can control the whole system via these functions.
+
+properties:
+  compatible:
+const: advantech,ahc1ec0
+
+  advantech,sub-dev-nb:
+description:
+  The number of sub-devices specified in the platform.
+$ref: /schemas/types.yaml#/definitions/uint32
+maxItems: 1
+
+  advantech,sub-dev:
+description:
+  A list of the sub-devices supported in the platform. Defines for the
+  appropriate values can found in dt-bindings/mfd/ahc1ec0.h.
+$ref: "/schemas/types.yaml#/definitions/uint32-array"
+minItems: 1
+maxItems: 6
+
+  advantech,hwmon-profile:
+description:
+  The number of sub-devices specified in the platform. Defines for the
+  hwmon profiles can found in dt-bindings/mfd/ahc1ec0.
+$ref: /schemas/types.yaml#/definitions/uint32
+maxItems: 1
+
+required:
+  - compatible
+  - advantech,sub-dev-nb
+  - advantech,sub-dev
+
+if:
+  properties:
+advantech,sub-dev:
+  contains:
+const: 0x3
+then:
+  required:
+- advantech,hwmon-profile
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+ahc1ec0 {
+compatible = "advantech,ahc1ec0";
+
+advantech,sub-dev-nb = <2>;
+advantech,sub-dev = ;
+
+advantech,hwmon-profile = ;
+};
-- 
2.17.1



[PATCH v3 1/6] MAINTAINERS: Add Advantech embedded controller entry

2020-10-29 Thread Shihlun Lin
Add Advantech embedded controller entry

Signed-off-by: Shihlun Lin 
---
 MAINTAINERS | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index e73636b75f29..d59e051c3f9d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -562,6 +562,17 @@ S: Maintained
 F: Documentation/scsi/advansys.rst
 F: drivers/scsi/advansys.c
 
+ADVANTECH EMBEDDED CONTROLLER DRIVER
+M: Shihlun Lin 
+M: Campion Kang 
+L: linux-kernel@vger.kernel.org
+S: Maintained
+F: Documentation/devicetree/bindings/mfd/ahc1ec0.yaml
+F: drivers/mfd/ahc1ec0-hwmon.c
+F: drivers/mfd/ahc1ec0-wdt.c
+F: drivers/mfd/ahc1ec0.c
+F: include/dt-bindings/mfd/ahc1ec0.h
+
 ADXL34X THREE-AXIS DIGITAL ACCELEROMETER DRIVER (ADXL345/ADXL346)
 M: Michael Hennerich 
 S: Supported

base-commit: 23859ae44402f4d935b9ee548135dd1e65e2cbf4
-- 
2.17.1



[PATCH v3 4/6] mfd: ahc1ec0: Add support for Advantech embedded controller

2020-10-29 Thread Shihlun Lin
AHC1EC0 is the embedded controller driver for Advantech industrial
products. This provides sub-devices such as hwmon and watchdog, and also
expose functions for sud-devices to read/write the value to embedded
controller.

Signed-off-by: Shihlun Lin 
Reported-by: kernel test robot 
---
 drivers/mfd/Kconfig |9 +
 drivers/mfd/Makefile|2 +
 drivers/mfd/ahc1ec0.c   | 1418 +++
 include/linux/mfd/ahc1ec0.h |  338 +
 4 files changed, 1767 insertions(+)
 create mode 100644 drivers/mfd/ahc1ec0.c
 create mode 100644 include/linux/mfd/ahc1ec0.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 8b99a13669bf..965bcafbe5b2 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -2166,5 +2166,14 @@ config MFD_INTEL_M10_BMC
  additional drivers must be enabled in order to use the functionality
  of the device.
 
+config MFD_AHC1EC0
+   tristate "Advantech Embedded Controller Module"
+   select MFD_CORE
+   help
+ This is the core function that for Advantech EC drivers. It
+ includes the sub-devices such as hwmon, watchdog, etc. And also
+ provides expose functions for sub-devices to read/write the value
+ to embedded controller.
+
 endmenu
 endif
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 1780019d2474..80a9a2bdc3ba 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -267,3 +267,5 @@ obj-$(CONFIG_MFD_KHADAS_MCU)+= khadas-mcu.o
 obj-$(CONFIG_SGI_MFD_IOC3) += ioc3.o
 obj-$(CONFIG_MFD_SIMPLE_MFD_I2C)   += simple-mfd-i2c.o
 obj-$(CONFIG_MFD_INTEL_M10_BMC)   += intel-m10-bmc.o
+
+obj-$(CONFIG_MFD_AHC1EC0)  += ahc1ec0.o
diff --git a/drivers/mfd/ahc1ec0.c b/drivers/mfd/ahc1ec0.c
new file mode 100644
index ..dd99e7d4cf3f
--- /dev/null
+++ b/drivers/mfd/ahc1ec0.c
@@ -0,0 +1,1418 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2018, Advantech Automation Corp.
+ * THIS IS AN UNPUBLISHED WORK CONTAINING CONFIDENTIAL AND PROPRIETARY
+ *  INFORMATION WHICH IS THE PROPERTY OF ADVANTECH AUTOMATION CORP.
+ *
+ *   ANY DISCLOSURE, USE, OR REPRODUCTION, WITHOUT WRITTEN AUTHORIZATION FROM
+ *  ADVANTECH AUTOMATION CORP., IS STRICTLY PROHIBITED.
+ *
+ *
+ * File:ahc1ec0.c
+ * Version: 1.00  <10/10/2014>
+ * Author:  Sun.Lang
+ *
+ * Description: The ahc1ec0 is multifunctional driver for controlling EC chip.
+ *
+ *
+ * Status:  working
+ *
+ * Change Log:
+ *  Version 1.00 <10/10/2014> Sun.Lang
+ *  - Initial version
+ *  Version 1.01 <11/05/2015> Jiangwei.Zhu
+ *  - Modify read_ad_value() function.
+ *  - Add smbus_read_byte() function.
+ *  - Add smbus_write_byte() function.
+ *  - Add wait_smbus_protocol_finish() function.
+ *  Version 1.02 <03/04/2016> Jiangwei.Zhu
+ *  - Add smbus_read_word() function.
+ *  Version 1.03 <01/22/2017> Ji.Xu
+ *  - Add detect to Advantech porduct name "ECU".
+ *  Version 1.04 <09/20/2017> Ji.Xu
+ *  - Update to support detect Advantech product name in UEFI
+ *BIOS(DMI).
+ *  Version 1.05 <11/02/2017> Ji.Xu
+ *  - Fixed issue: Cache coherency error when exec 
'ioremap_uncache()'
+ *in kernel-4.10.
+ *  Version 1.06 <10/16/2020> Shihlun.Lin
+ *  - Update: Replace ioremap_nocache() with ioremap_uc() since
+ *ioremap_uc() was used on the entire PCI BAR.
+ 
**/
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define ADVANTECH_EC_NAME  "ahc1ec0"
+#define ADVANTECH_EC_MFD_VER"2.0.0"
+#define ADVANTECH_EC_MFD_DATE   "10/16/2020"
+
+struct mutex lock;
+
+enum {
+   ADVEC_SUBDEV_BRIGHTNESS = 0,
+   ADVEC_SUBDEV_EEPROM,
+   ADVEC_SUBDEV_GPIO,
+   ADVEC_SUBDEV_HWMON,
+   ADVEC_SUBDEV_LED,
+   ADVEC_SUBDEV_WDT,
+   ADVEC_SUBDEV_MAX,
+};
+
+static int wait_ibf(void)
+{
+   int i;
+
+   for (i = 0; i < EC_MAX_TIMEOUT_COUNT; i++) {
+   if ((inb(EC_COMMAND_PORT) & 0x02) == 0)
+   return 0;
+
+   udelay(EC_UDELAY_TIME);
+   }
+
+   return -ETIMEDOUT;
+}
+
+/* Wait OBF (Output buffer full) set */
+static int wait_obf(void)
+{
+   int i;
+
+   for (i = 0; i < EC_MAX_TIMEOUT_COUNT; i++) {
+   if ((inb(EC_COMMAND_PORT) & 0x01) != 0)
+

[PATCH v3 2/6] mfd: ahc1ec0: Add Advantech EC include file used by dt-bindings

2020-10-29 Thread Shihlun Lin
This files defines the sud-device types and hwmon profiles support by
Advantech embedded controller.

Signed-off-by: Shihlun Lin 
---
 include/dt-bindings/mfd/ahc1ec0.h | 25 +
 1 file changed, 25 insertions(+)
 create mode 100644 include/dt-bindings/mfd/ahc1ec0.h

diff --git a/include/dt-bindings/mfd/ahc1ec0.h 
b/include/dt-bindings/mfd/ahc1ec0.h
new file mode 100644
index ..389a7a7f8f02
--- /dev/null
+++ b/include/dt-bindings/mfd/ahc1ec0.h
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Device Tree defines for Advantech Embedded Controller (AHC1EC0)
+ */
+
+#ifndef _DT_BINDINGS_MFD_AHC1EC0_H
+#define _DT_BINDINGS_MFD_AHC1EC0_H
+
+/* Sub-device Definitions */
+#define AHC1EC0_SUBDEV_BRIGHTNESS 0x0
+#define AHC1EC0_SUBDEV_EEPROM 0x1
+#define AHC1EC0_SUBDEV_GPIO   0x2
+#define AHC1EC0_SUBDEV_HWMON  0x3
+#define AHC1EC0_SUBDEV_LED0x4
+#define AHC1EC0_SUBDEV_WDT0x5
+
+/* HWMON Profile Definitions */
+#define AHC1EC0_HWMON_PRO_TEMPLATE 0x0
+#define AHC1EC0_HWMON_PRO_TPC5XXX  0x1
+#define AHC1EC0_HWMON_PRO_PRVR40x2
+#define AHC1EC0_HWMON_PRO_UNO2271G 0x3
+#define AHC1EC0_HWMON_PRO_UNO1172A 0x4
+#define AHC1EC0_HWMON_PRO_UNO1372G 0x5
+
+#endif /* _DT_BINDINGS_MFD_AHC1EC0_H */
-- 
2.17.1



[PATCH v2 3/3] mfd: ahc1ec0-wdt: Add sub-device watchdog for Advantech embedded controller

2020-10-16 Thread Shihlun Lin
This is one of sub-device driver for Advantech embedded controller
AHC1EC0. This driver provide watchdog functionality for Advantech
related applications to restart the system.

Signed-off-by: Shihlun Lin 
Reported-by: kernel test robot 
---
 drivers/mfd/Kconfig   |   4 +
 drivers/mfd/Makefile  |   3 +-
 drivers/mfd/ahc1ec0-wdt.c | 502 ++
 3 files changed, 508 insertions(+), 1 deletion(-)
 create mode 100644 drivers/mfd/ahc1ec0-wdt.c

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 4945638ca6cb..662285afb42f 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -2135,5 +2135,9 @@ config MFD_AHC1EC0_HWMON
  driver provides the sysfs attribues for applications to monitor
  the system status.
 
+config MFD_AHC1EC0_WDT
+   tristate "Advantech EC Watchdog Function"
+   depends on MFD_AHC1EC0
+
 endmenu
 endif
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 46168ac64903..d5ce7e7eaf21 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -265,5 +265,6 @@ obj-$(CONFIG_MFD_KHADAS_MCU)+= khadas-mcu.o
 
 obj-$(CONFIG_SGI_MFD_IOC3) += ioc3.o
 
-obj-$(CONFIG_MFD_AHC1EC0)  += ahc1ec0.o
+obj-$(CONFIG_MFD_AHC1EC0)  += ahc1ec0.o
 obj-$(CONFIG_MFD_AHC1EC0_HWMON)+= ahc1ec0-hwmon.o
+obj-$(CONFIG_MFD_AHC1EC0_WDT)  += ahc1ec0-wdt.o
diff --git a/drivers/mfd/ahc1ec0-wdt.c b/drivers/mfd/ahc1ec0-wdt.c
new file mode 100644
index ..c275b41d873b
--- /dev/null
+++ b/drivers/mfd/ahc1ec0-wdt.c
@@ -0,0 +1,502 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2018, Advantech Automation Corp.
+ * THIS IS AN UNPUBLISHED WORK CONTAINING CONFIDENTIAL AND PROPRIETARY
+ *  INFORMATION WHICH IS THE PROPERTY OF ADVANTECH AUTOMATION CORP.
+ *
+ *   ANY DISCLOSURE, USE, OR REPRODUCTION, WITHOUT WRITTEN AUTHORIZATION FROM
+ *  ADVANTECH AUTOMATION CORP., IS STRICTLY PROHIBITED.
+ *
+ *
+ * File:ahc1ec0-wdt.c
+ * Version: 1.00  <10/10/2014>
+ * Author:  Sun.Lang
+ *
+ * Description: The ahc1ec0-wdt is driver for controlling EC watchdog.
+ *
+ *
+ * Status:  working
+ *
+ * Change Log:
+ *  Version 1.00 <10/10/2014> Sun.Lang
+ *  - Initial version
+ *  Version 1.01 <12/30/2015> Jiangwei.Zhu
+ *  - Modify adv_watchdog_init function to install the driver to
+ *  - the support devices.
+ *  Version 1.02 <03/04/2016> Jiangwei.Zhu
+ *  - Support UNO-1372G-E3AE, TPC-1782H-433AE, APAX-5580-433AE
+ *  Version 1.03 <05/09/2016> Ji.Xu
+ *  - Support EC watchdog mini-board on UNO-3083G/3085G-D44E/D64E
+ *  - APAX-5580-473AE/4C3AE.
+ *  - Modify the timeout unit to 1 second.
+ *  - Modify the device name check method to fuzzy matching.
+ *  Version 1.04 <06/28/2017> Ji.Xu
+ *  - Support EC UNO-2271G-E2xAE.
+ *  - Support EC UNO-2271G-E02xAE.
+ *  - Support EC UNO-2473G-JxAE.
+ *  - Support proc filesystem.
+ *  Version 1.05 <09/20/2017> Ji.Xu
+ *  - Support EC UNO-2484G-633xAE.
+ *  - Support EC UNO-2484G-653xAE.
+ *  - Support EC UNO-2484G-673xAE.
+ *  - Support EC UNO-2484G-733xAE.
+ *  - Support EC UNO-2484G-753xAE.
+ *  - Support EC UNO-2484G-773xAE.
+ *  Version 1.06 <10/26/2017> Ji.Xu
+ *  - Support EC UNO-3283G-674AE
+ *  - Support EC UNO-3285G-674AE
+ *  Version 1.07 <11/16/2017> Zhang.Yang
+ *  - Support EC UNO-1372G-J021AE/J031AE
+ *  - Support EC UNO-2372G
+ *  Version 1.08 <02/02/2018> Ji.Xu
+ *  - Support EC TPC-B500-6??AE
+ *  - Support EC TPC-5???T-6??AE
+ *  - Support EC TPC-5???W-6??AE
+ *  Version 1.09 <03/20/2018> Ji.Xu
+ *  - Support for compiling in kernel-4.10 and below.
+ *  Version 1.10 <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.11 <08/30/2019> Yao.Kang
+ * - Support 32-bit programs on 64-bit kernel
+ *  Version 1.12 <12/03/2019> Jianfeng.dai
+ * - Support support UNO-2372G watchdog
+ *  Version 1.13 <04/24/2020> Yao.Kang
+ * - Support support UNO-2473G
+ 
**/
+
+#includ

[PATCH v2 1/3] mfd: ahc1ec0: Add support for Advantech embedded controller

2020-10-16 Thread Shihlun Lin
AHC1EC0 is the embedded controller driver for Advantech industrial
products. This provides sub-devices such as hwmon and watchdog, and also
expose functions for sud-devices to read/write the value to embedded
controller.

Signed-off-by: Shihlun Lin 
Reported-by: kernel test robot 
---
 drivers/mfd/Kconfig |9 +
 drivers/mfd/Makefile|2 +
 drivers/mfd/ahc1ec0.c   | 1419 +++
 include/linux/mfd/ahc1ec0.h |  338 +
 4 files changed, 1768 insertions(+)
 create mode 100644 drivers/mfd/ahc1ec0.c
 create mode 100644 include/linux/mfd/ahc1ec0.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 33df0837ab41..d0fc0c380b93 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -2118,5 +2118,14 @@ config SGI_MFD_IOC3
  If you have an SGI Origin, Octane, or a PCI IOC3 card,
  then say Y. Otherwise say N.
 
+config MFD_AHC1EC0
+   tristate "Advantech Embedded Controller Module"
+   select MFD_CORE
+   help
+  This is the core function that for Advantech EC drivers. It
+  includes the sub-devices such as hwmon, watchdog, etc. And also
+  provides expose functions for sub-devices to read/write the value
+  to embedded controller.
+
 endmenu
 endif
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index a60e5f835283..643e6cdd3300 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -264,3 +264,5 @@ obj-$(CONFIG_MFD_STMFX) += stmfx.o
 obj-$(CONFIG_MFD_KHADAS_MCU)   += khadas-mcu.o
 
 obj-$(CONFIG_SGI_MFD_IOC3) += ioc3.o
+
+obj-$(CONFIG_MFD_AHC1EC0)  += ahc1ec0.o
diff --git a/drivers/mfd/ahc1ec0.c b/drivers/mfd/ahc1ec0.c
new file mode 100644
index ..a6cda424d5d3
--- /dev/null
+++ b/drivers/mfd/ahc1ec0.c
@@ -0,0 +1,1419 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2018, Advantech Automation Corp.
+ * THIS IS AN UNPUBLISHED WORK CONTAINING CONFIDENTIAL AND PROPRIETARY
+ *  INFORMATION WHICH IS THE PROPERTY OF ADVANTECH AUTOMATION CORP.
+ *
+ *   ANY DISCLOSURE, USE, OR REPRODUCTION, WITHOUT WRITTEN AUTHORIZATION FROM
+ *  ADVANTECH AUTOMATION CORP., IS STRICTLY PROHIBITED.
+ *
+ *
+ * File:ahc1ec0.c
+ * Version: 1.00  <10/10/2014>
+ * Author:  Sun.Lang
+ *
+ * Description: The ahc1ec0 is multifunctional driver for controlling EC chip.
+ *
+ *
+ * Status:  working
+ *
+ * Change Log:
+ *  Version 1.00 <10/10/2014> Sun.Lang
+ *  - Initial version
+ *  Version 1.01 <11/05/2015> Jiangwei.Zhu
+ *  - Modify read_ad_value() function.
+ *  - Add smbus_read_byte() function.
+ *  - Add smbus_write_byte() function.
+ *  - Add wait_smbus_protocol_finish() function.
+ *  Version 1.02 <03/04/2016> Jiangwei.Zhu
+ *  - Add smbus_read_word() function.
+ *  Version 1.03 <01/22/2017> Ji.Xu
+ *  - Add detect to Advantech porduct name "ECU".
+ *  Version 1.04 <09/20/2017> Ji.Xu
+ *  - Update to support detect Advantech product name in UEFI
+ *BIOS(DMI).
+ *  Version 1.05 <11/02/2017> Ji.Xu
+ *  - Fixed issue: Cache coherency error when exec 
'ioremap_uncache()'
+ *in kernel-4.10.
+ *  Version 1.06 <10/16/2020> Shihlun.Lin
+ *  - Update: Replace ioremap_nocache() with ioremap_uc() since
+ *ioremap_uc() was used on the entire PCI BAR.
+ 
**/
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define ADVANTECH_EC_NAME  "ahc1ec0"
+#define ADVANTECH_EC_MFD_VER"2.0.0"
+#define ADVANTECH_EC_MFD_DATE   "10/16/2020"
+
+struct mutex lock;
+
+enum {
+   ADVEC_SUBDEV_BRIGHTNESS = 0,
+   ADVEC_SUBDEV_EEPROM,
+   ADVEC_SUBDEV_GPIO,
+   ADVEC_SUBDEV_HWMON,
+   ADVEC_SUBDEV_LED,
+   ADVEC_SUBDEV_WDT,
+   ADVEC_SUBDEV_MAX,
+};
+
+static int wait_ibf(void)
+{
+   int i;
+
+   for (i = 0; i < EC_MAX_TIMEOUT_COUNT; i++) {
+   if ((inb(EC_COMMAND_PORT) & 0x02) == 0)
+   return 0;
+
+   udelay(EC_UDELAY_TIME);
+   }
+
+   return -ETIMEDOUT;
+}
+
+/* Wait OBF (Output buffer full) set */
+static int wait_obf(void)
+{
+   int i;
+
+   for (i = 0; i < EC_MAX_TIMEOUT_COUNT; i++) {
+   if ((inb(EC_COMMAND_PORT) & 0x01) != 0)
+   return 0;
+
+   udelay(EC_UDELAY_TIME);
+

[PATCH v2 2/3] mfd: ahc1ec0-hwmon: Add sub-device hwmon for Advantech embedded controller

2020-10-16 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 
Reported-by: kernel test robot 
---
 drivers/mfd/Kconfig |8 +
 drivers/mfd/Makefile|1 +
 drivers/mfd/ahc1ec0-hwmon.c | 1514 +++
 3 files changed, 1523 insertions(+)
 create mode 100644 drivers/mfd/ahc1ec0-hwmon.c

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index d0fc0c380b93..4945638ca6cb 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -2127,5 +2127,13 @@ config MFD_AHC1EC0
   provides expose functions for sub-devices to read/write the value
   to embedded controller.
 
+config MFD_AHC1EC0_HWMON
+   tristate "Advantech EC Hareware Monitor Function"
+   depends on MFD_AHC1EC0
+   help
+ This is sub-device for Advantech embedded controller AHC1EC0. This
+ driver provides the sysfs attribues for applications to monitor
+ the system status.
+
 endmenu
 endif
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 643e6cdd3300..46168ac64903 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -266,3 +266,4 @@ obj-$(CONFIG_MFD_KHADAS_MCU)+= khadas-mcu.o
 obj-$(CONFIG_SGI_MFD_IOC3) += ioc3.o
 
 obj-$(CONFIG_MFD_AHC1EC0)  += ahc1ec0.o
+obj-$(CONFIG_MFD_AHC1EC0_HWMON)+= ahc1ec0-hwmon.o
diff --git a/drivers/mfd/ahc1ec0-hwmon.c b/drivers/mfd/ahc1ec0-hwmon.c
new file mode 100644
index ..3e493b040b4a
--- /dev/null
+++ b/drivers/mfd/ahc1ec0-hwmon.c
@@ -0,0 +1,1514 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2018, Advantech Automation Corp.
+ * THIS IS AN UNPUBLISHED WORK CONTAINING CONFIDENTIAL AND PROPRIETARY
+ * INFORMATION WHICH IS THE PROPERTY OF ADVANTECH AUTOMATION CORP.
+ *
+ * ANY DISCLOSURE, USE, OR REPRODUCTION, WITHOUT WRITTEN AUTHORIZATION FROM
+ * ADVANTECH AUTOMATION CORP., IS STRICTLY PROHIBITED.
+ *
+ *
+ * File:ahc1ec0-hwmon.c
+ * Version: 1.00  <11/05/2015>
+ * Author:  Jiangwei.Zhu
+ *
+ * Description: The ahc1ec0-hwmon driver is for controlling EC hwmon.
+ *
+ * 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_

[PATCH 3/3] mfd: ahc1ec0-wdt: Add sub-device watchdog for Advantech embedded controller

2020-10-14 Thread Shihlun Lin
This is one of sub-device driver for Advantech embedded controller
AHC1EC0. This driver provide watchdog functionality for Advantech
related applications to restart the system.

Signed-off-by: Shihlun Lin 
---
 drivers/mfd/Kconfig   |   4 +
 drivers/mfd/Makefile  |   3 +-
 drivers/mfd/ahc1ec0-wdt.c | 506 ++
 3 files changed, 512 insertions(+), 1 deletion(-)
 create mode 100644 drivers/mfd/ahc1ec0-wdt.c

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 4945638ca6cb..662285afb42f 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -2135,5 +2135,9 @@ config MFD_AHC1EC0_HWMON
  driver provides the sysfs attribues for applications to monitor
  the system status.
 
+config MFD_AHC1EC0_WDT
+   tristate "Advantech EC Watchdog Function"
+   depends on MFD_AHC1EC0
+
 endmenu
 endif
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 46168ac64903..d5ce7e7eaf21 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -265,5 +265,6 @@ obj-$(CONFIG_MFD_KHADAS_MCU)+= khadas-mcu.o
 
 obj-$(CONFIG_SGI_MFD_IOC3) += ioc3.o
 
-obj-$(CONFIG_MFD_AHC1EC0)  += ahc1ec0.o
+obj-$(CONFIG_MFD_AHC1EC0)  += ahc1ec0.o
 obj-$(CONFIG_MFD_AHC1EC0_HWMON)+= ahc1ec0-hwmon.o
+obj-$(CONFIG_MFD_AHC1EC0_WDT)  += ahc1ec0-wdt.o
diff --git a/drivers/mfd/ahc1ec0-wdt.c b/drivers/mfd/ahc1ec0-wdt.c
new file mode 100644
index ..d4554520c7ca
--- /dev/null
+++ b/drivers/mfd/ahc1ec0-wdt.c
@@ -0,0 +1,506 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2018, Advantech Automation Corp.
+ * THIS IS AN UNPUBLISHED WORK CONTAINING CONFIDENTIAL AND PROPRIETARY
+ *  INFORMATION WHICH IS THE PROPERTY OF ADVANTECH AUTOMATION CORP.
+ *
+ *   ANY DISCLOSURE, USE, OR REPRODUCTION, WITHOUT WRITTEN AUTHORIZATION FROM
+ *  ADVANTECH AUTOMATION CORP., IS STRICTLY PROHIBITED.
+ *
+ *
+ * File:ahc1ec0-wdt.c
+ * Version: 1.00  <10/10/2014>
+ * Author:  Sun.Lang
+ *
+ * Description: The ahc1ec0-wdt is driver for controlling EC watchdog.
+ *
+ *
+ * Status:  working
+ *
+ * Change Log:
+ *  Version 1.00 <10/10/2014> Sun.Lang
+ *  - Initial version
+ *  Version 1.01 <12/30/2015> Jiangwei.Zhu
+ *  - Modify adv_watchdog_init function to install the driver to
+ *  - the support devices.
+ *  Version 1.02 <03/04/2016> Jiangwei.Zhu
+ *  - Support UNO-1372G-E3AE, TPC-1782H-433AE, APAX-5580-433AE
+ *  Version 1.03 <05/09/2016> Ji.Xu
+ *  - Support EC watchdog mini-board on UNO-3083G/3085G-D44E/D64E
+ *  - APAX-5580-473AE/4C3AE.
+ *  - Modify the timeout unit to 1 second.
+ *  - Modify the device name check method to fuzzy matching.
+ *  Version 1.04 <06/28/2017> Ji.Xu
+ *  - Support EC UNO-2271G-E2xAE.
+ *  - Support EC UNO-2271G-E02xAE.
+ *  - Support EC UNO-2473G-JxAE.
+ *  - Support proc filesystem.
+ *  Version 1.05 <09/20/2017> Ji.Xu
+ *  - Support EC UNO-2484G-633xAE.
+ *  - Support EC UNO-2484G-653xAE.
+ *  - Support EC UNO-2484G-673xAE.
+ *  - Support EC UNO-2484G-733xAE.
+ *  - Support EC UNO-2484G-753xAE.
+ *  - Support EC UNO-2484G-773xAE.
+ *  Version 1.06 <10/26/2017> Ji.Xu
+ *  - Support EC UNO-3283G-674AE
+ *  - Support EC UNO-3285G-674AE
+ *  Version 1.07 <11/16/2017> Zhang.Yang
+ *  - Support EC UNO-1372G-J021AE/J031AE
+ *  - Support EC UNO-2372G
+ *  Version 1.08 <02/02/2018> Ji.Xu
+ *  - Support EC TPC-B500-6??AE
+ *  - Support EC TPC-5???T-6??AE
+ *  - Support EC TPC-5???W-6??AE
+ *  Version 1.09 <03/20/2018> Ji.Xu
+ *  - Support for compiling in kernel-4.10 and below.
+ *  Version 1.10 <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.11 <08/30/2019> Yao.Kang
+ * - Support 32-bit programs on 64-bit kernel
+ *  Version 1.12 <12/03/2019> Jianfeng.dai
+ * - Support support UNO-2372G watchdog
+ *  Version 1.13 <04/24/2020> Yao.Kang
+ * - Support support UNO-2473G
+ 
**/
+
+#include 
+#include 
+#include 
+#includ

[PATCH 1/3] mfd: ahc1ec0: Add support for Advantech embedded controller

2020-10-14 Thread Shihlun Lin
AHC1EC0 is the embedded controller driver for Advantech industrial
products. This provides sub-devices such as hwmon and watchdog, and also
expose functions for sud-devices to read/write the value to embedded
controller.

Signed-off-by: Shihlun Lin 
---
 drivers/mfd/Kconfig |9 +
 drivers/mfd/Makefile|2 +
 drivers/mfd/ahc1ec0.c   | 1420 +++
 include/linux/mfd/ahc1ec0.h |  327 
 4 files changed, 1758 insertions(+)
 create mode 100644 drivers/mfd/ahc1ec0.c
 create mode 100644 include/linux/mfd/ahc1ec0.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 33df0837ab41..d0fc0c380b93 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -2118,5 +2118,14 @@ config SGI_MFD_IOC3
  If you have an SGI Origin, Octane, or a PCI IOC3 card,
  then say Y. Otherwise say N.
 
+config MFD_AHC1EC0
+   tristate "Advantech Embedded Controller Module"
+   select MFD_CORE
+   help
+  This is the core function that for Advantech EC drivers. It
+  includes the sub-devices such as hwmon, watchdog, etc. And also
+  provides expose functions for sub-devices to read/write the value
+  to embedded controller.
+
 endmenu
 endif
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index a60e5f835283..643e6cdd3300 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -264,3 +264,5 @@ obj-$(CONFIG_MFD_STMFX) += stmfx.o
 obj-$(CONFIG_MFD_KHADAS_MCU)   += khadas-mcu.o
 
 obj-$(CONFIG_SGI_MFD_IOC3) += ioc3.o
+
+obj-$(CONFIG_MFD_AHC1EC0)  += ahc1ec0.o
diff --git a/drivers/mfd/ahc1ec0.c b/drivers/mfd/ahc1ec0.c
new file mode 100644
index ..a840e3710982
--- /dev/null
+++ b/drivers/mfd/ahc1ec0.c
@@ -0,0 +1,1420 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2018, Advantech Automation Corp.
+ * THIS IS AN UNPUBLISHED WORK CONTAINING CONFIDENTIAL AND PROPRIETARY
+ *  INFORMATION WHICH IS THE PROPERTY OF ADVANTECH AUTOMATION CORP.
+ *
+ *   ANY DISCLOSURE, USE, OR REPRODUCTION, WITHOUT WRITTEN AUTHORIZATION FROM
+ *  ADVANTECH AUTOMATION CORP., IS STRICTLY PROHIBITED.
+ *
+ *
+ * File:ahc1ec0.c
+ * Version: 1.00  <10/10/2014>
+ * Author:  Sun.Lang
+ *
+ * Description: The ahc1ec0 is multifunctional driver for controlling EC chip.
+ *
+ *
+ * Status:  working
+ *
+ * Change Log:
+ *  Version 1.00 <10/10/2014> Sun.Lang
+ *  - Initial version
+ *  Version 1.01 <11/05/2015> Jiangwei.Zhu
+ *  - Modify read_ad_value() function.
+ *  - Add smbus_read_byte() function.
+ *  - Add smbus_write_byte() function.
+ *  - Add wait_smbus_protocol_finish() function.
+ *  Version 1.02 <03/04/2016> Jiangwei.Zhu
+ *  - Add smbus_read_word() function.
+ *  Version 1.03 <01/22/2017> Ji.Xu
+ *  - Add detect to Advantech porduct name "ECU".
+ *  Version 1.04 <09/20/2017> Ji.Xu
+ *  - Update to support detect Advantech product name in UEFI
+ *BIOS(DMI).
+ *  Version 1.05 <11/02/2017> Ji.Xu
+ *  - Fixed issue: Cache coherency error when exec 
'ioremap_uncache()'
+ *in kernel-4.10.
+ 
**/
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define ADVANTECH_EC_NAME  "ahc1ec0"
+#define ADVANTECH_EC_MFD_VER"2.0.0"
+#define ADVANTECH_EC_MFD_DATE   "11/09/2020"
+
+struct mutex lock;
+
+enum {
+   ADVEC_SUBDEV_BRIGHTNESS = 0,
+   ADVEC_SUBDEV_EEPROM,
+   ADVEC_SUBDEV_GPIO,
+   ADVEC_SUBDEV_HWMON,
+   ADVEC_SUBDEV_LED,
+   ADVEC_SUBDEV_WDT,
+   ADVEC_SUBDEV_MAX,
+};
+
+int wait_ibf(void)
+{
+   int i;
+
+   for (i = 0; i < EC_MAX_TIMEOUT_COUNT; i++) {
+   if ((inb(EC_COMMAND_PORT) & 0x02) == 0)
+   return 0;
+
+   udelay(EC_UDELAY_TIME);
+   }
+
+   return -ETIMEDOUT;
+}
+
+/* Wait OBF (Output buffer full) set */
+int wait_obf(void)
+{
+   int i;
+
+   for (i = 0; i < EC_MAX_TIMEOUT_COUNT; i++) {
+   if ((inb(EC_COMMAND_PORT) & 0x01) != 0)
+   return 0;
+
+   udelay(EC_UDELAY_TIME);
+   }
+
+   return -ETIMEDOUT;
+}
+
+/* Read data from EC HW ram */
+int read_hw_ram(uchar addr, uchar *data)
+{
+   int ret;
+
+   mutex_lock();
+
+   /* Step 0. Wait IBF clear */
+   ret = wait_ibf();
+   if (ret)
+  

[PATCH 2/3] mfd: ahc1ec0-hwmon: Add sub-device hwmon for Advantech embedded controller

2020-10-14 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/mfd/Kconfig |8 +
 drivers/mfd/Makefile|1 +
 drivers/mfd/ahc1ec0-hwmon.c | 1514 +++
 3 files changed, 1523 insertions(+)
 create mode 100644 drivers/mfd/ahc1ec0-hwmon.c

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index d0fc0c380b93..4945638ca6cb 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -2127,5 +2127,13 @@ config MFD_AHC1EC0
   provides expose functions for sub-devices to read/write the value
   to embedded controller.
 
+config MFD_AHC1EC0_HWMON
+   tristate "Advantech EC Hareware Monitor Function"
+   depends on MFD_AHC1EC0
+   help
+ This is sub-device for Advantech embedded controller AHC1EC0. This
+ driver provides the sysfs attribues for applications to monitor
+ the system status.
+
 endmenu
 endif
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 643e6cdd3300..46168ac64903 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -266,3 +266,4 @@ obj-$(CONFIG_MFD_KHADAS_MCU)+= khadas-mcu.o
 obj-$(CONFIG_SGI_MFD_IOC3) += ioc3.o
 
 obj-$(CONFIG_MFD_AHC1EC0)  += ahc1ec0.o
+obj-$(CONFIG_MFD_AHC1EC0_HWMON)+= ahc1ec0-hwmon.o
diff --git a/drivers/mfd/ahc1ec0-hwmon.c b/drivers/mfd/ahc1ec0-hwmon.c
new file mode 100644
index ..6f2a6ad0295c
--- /dev/null
+++ b/drivers/mfd/ahc1ec0-hwmon.c
@@ -0,0 +1,1514 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2018, Advantech Automation Corp.
+ * THIS IS AN UNPUBLISHED WORK CONTAINING CONFIDENTIAL AND PROPRIETARY
+ * INFORMATION WHICH IS THE PROPERTY OF ADVANTECH AUTOMATION CORP.
+ *
+ * ANY DISCLOSURE, USE, OR REPRODUCTION, WITHOUT WRITTEN AUTHORIZATION FROM
+ * ADVANTECH AUTOMATION CORP., IS STRICTLY PROHIBITED.
+ *
+ *
+ * File:ahc1ec0-hwmon.c
+ * Version: 1.00  <11/05/2015>
+ * Author:  Jiangwei.Zhu
+ *
+ * Description: The ahc1ec0-hwmon driver is for controlling EC hwmon.
+ *
+ * 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

[PATCH 1/2] mfd: ahc1ec0: Add Advantech EC include file used by dt-bindings

2020-10-14 Thread Shihlun Lin
This files defines the sud-device types and hwmon profiles support by
Advantech embedded controller.

Signed-off-by: Shihlun Lin 
---
 include/dt-bindings/mfd/ahc1ec0.h | 29 +
 1 file changed, 29 insertions(+)
 create mode 100644 include/dt-bindings/mfd/ahc1ec0.h

diff --git a/include/dt-bindings/mfd/ahc1ec0.h 
b/include/dt-bindings/mfd/ahc1ec0.h
new file mode 100644
index ..767d29bcb78e
--- /dev/null
+++ b/include/dt-bindings/mfd/ahc1ec0.h
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Device Tree defines for Advantech Embedded Controller (AHC1EC0)
+ *
+ * Copyright 2020 Advantech Co., Ltd.
+ *
+ * Author: William Sung 
+ */
+
+#ifndef _DT_BINDINGS_MFD_AHC1EC0_H
+#define _DT_BINDINGS_MFD_AHC1EC0_H
+
+/* Sub-device Definitions */
+#define AHC1EC0_SUBDEV_BRIGHTNESS 0x0
+#define AHC1EC0_SUBDEV_EEPROM 0x1
+#define AHC1EC0_SUBDEV_GPIO   0x2
+#define AHC1EC0_SUBDEV_HWMON  0x3
+#define AHC1EC0_SUBDEV_LED0x4
+#define AHC1EC0_SUBDEV_WDT0x5
+
+/* HWMON Profile Definitions */
+#define AHC1EC0_HWMON_PRO_TEMPLATE 0x0
+#define AHC1EC0_HWMON_PRO_TPC5XXX  0x1
+#define AHC1EC0_HWMON_PRO_PRVR40x2
+#define AHC1EC0_HWMON_PRO_UNO2271G 0x3
+#define AHC1EC0_HWMON_PRO_UNO1172A 0x4
+#define AHC1EC0_HWMON_PRO_UNO1372G 0x5
+
+#endif
-- 
2.17.1



[PATCH] MAINTAINERS: Add Advantech embedded controller entry

2020-10-14 Thread Shihlun Lin
Add Advantech embedded controller entry

Signed-off-by: Shihlun Lin 
---
 MAINTAINERS | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 6336f9314ae1..41e94692c4f8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -562,6 +562,17 @@ S: Maintained
 F: Documentation/scsi/advansys.rst
 F: drivers/scsi/advansys.c
 
+ADVANTECH EMBEDDED CONTROLLER DRIVER
+M: Shihlun Lin 
+M: Campion Kang 
+L: linux-kernel@vger.kernel.org
+S: Maintained
+F: Documentation/devicetree/bindings/mfd/ahc1ec0.yaml
+F: drivers/mfd/ahc1ec0-hwmon.c
+F: drivers/mfd/ahc1ec0-wdt.c
+F: drivers/mfd/ahc1ec0.c
+F: include/dt-bindings/mfd/ahc1ec0.h
+
 ADXL34X THREE-AXIS DIGITAL ACCELEROMETER DRIVER (ADXL345/ADXL346)
 M: Michael Hennerich 
 S: Supported
-- 
2.17.1



[PATCH 2/2] dt-bindings: mfd: ahc1ec0.yaml: Add Advantech Embedded Controll - AHC1EC0

2020-10-14 Thread Shihlun Lin
Add DT binding schema for Advantech embedded controller AHC1EC0.

Signed-off-by: Shihlun Lin 
---
 .../devicetree/bindings/mfd/ahc1ec0.yaml  | 76 +++
 1 file changed, 76 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/ahc1ec0.yaml

diff --git a/Documentation/devicetree/bindings/mfd/ahc1ec0.yaml 
b/Documentation/devicetree/bindings/mfd/ahc1ec0.yaml
new file mode 100644
index ..2a3581d2ecab
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/ahc1ec0.yaml
@@ -0,0 +1,76 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+# All the top-level keys are standard json-schema keywords except for
+# 'maintainers' and 'select'
+
+
+$id: http://devicetree.org/schemas/mfd/ahc1ec0.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Advantech Embedded Controller (AHC1EC0)
+
+maintainers:
+  - Shihlun Lin 
+  - Campion Kang 
+
+description: |
+  AHC1EC0 is one of the embedded controllers used by Advantech to provide 
several
+  functions such as watchdog, hwmon, brightness, etc. Advantech related 
applications
+  can control the whole system via these functions.
+
+  # In this case, a 'false' schema will never match.
+
+properties:
+  compatible:
+const: advantech,ahc1ec0
+
+  advantech,sub-dev-nb:
+description:
+  The number of sub-devices specified in the platform.
+$ref: /schemas/types.yaml#/definitions/uint32
+maxItems: 1
+
+  advantech,sub-dev:
+description:
+  A list of the sub-devices supported in the platform. Defines for the
+  appropriate values can found in dt-bindings/mfd/ahc1ec0.h.
+$ref: "/schemas/types.yaml#/definitions/uint32-array"
+minItems: 1
+maxItems: 6
+
+  advantech,hwmon-profile:
+description:
+  The number of sub-devices specified in the platform. Defines for the
+  hwmon profiles can found in dt-bindings/mfd/ahc1ec0.
+$ref: /schemas/types.yaml#/definitions/uint32
+maxItems: 1
+
+required:
+  - compatible
+  - advantech,sub-dev-nb
+  - advantech,sub-dev
+
+if:
+  properties:
+advantech,sub-dev:
+  contains:
+const: AHC1EC0_SUBDEV_HWMON
+then:
+  required:
+- advantech,hwmon-profile
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+ahc1ec0 {
+compatible = "advantech,ahc1ec0";
+
+advantech,sub-dev-nb = <2>;
+advantech,sub-dev = ;
+
+advantech,hwmon-profile = ;
+};
-- 
2.17.1