Skip to contentSkip to conversation

Advantech iManager EC driver set

PATCH In review Richard Vidal-Dorsch 3 participants 9 messages Nov 2, 2016 – Nov 5, 2016

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

v4 cover Advantech iManager EC driver set

The Advantech iManager is a custom embedded controller based on ITE IT8518 or IT8528 EC (depending on PCB). It runs a custom firmware that provides access to features such as GPIO, I2C/SMbus, hwmon, watchdog, and backlight/brightness control. All drivers are being managed by the iManager (mfd) core driver. It acts as a 'gateway' and handles communications between EC and sub-drivers. The imanager-core follows a similar concept as Kontron's kempld-core driver.
During core init, the device id list is retrieved from the firmware and an internal device list is being created. This list is then passed down to managed drivers.

The out-of-tree iManager driver set is maintained at
https://www.github.com/rvido/iManager

Notebook manufactures such as Dell (XPS series) or Razerzone (Razer Blade) are using similar ITE ECs or even the same ones to implement their own embedded functions. Due to the level of firmware customization which those ITE ECs provide, the iManager EC driver set is incompatible with those vendors solutions (and probably others too).

Note that v1..v3 were submitted in Jan. 2016. It took some time to apply suggested changes. However, I kept the original versioning to avoid conflict with previous patch submissions.

Thanks to Krzysztof Kozłowski, Guenter Roeck, and Lee Jones for their invaluable feedback. Those drivers clearly needed to be further improved and cleaned.

Changes from v3:
- Merge imanager-ec-* with corresponding drivers This eliminates static init vars and reduces code size
- Remove Documentation/devicetree/bindings/mfd/imanager.txt No support for DT
- Add API comments
- List include files in alphabetic order
- Run patches through ./scripts/checkpatch.pl --strict
- Remove headers except imanger.h/imanager-ec.h Store them in include/linux/mfd/
imanager-core:
- Reduce amount of exported functions in core
- Use usleep_range() instead of udelay()
- Use dev_info() or dev_warn() where necessary
- Fix register/probing and __init/__exit
- Optimize imanager_read_device_config()
- Shrink down EC device table to known and supported devices
- Define flags with BIT()
- Use new imanager device struct
i2c-imanager:
- Add support for multiple I2C/SMbus adapters
- Use new imanager device struct
imanager-hwmon-*
gpio-imanager:
imanager_bl:
imanager_wdt:
- Define flags with BIT()
- Use new imanager device struct

Changes from v2:
- Remove .owner from platform_driver in:
drivers/gpio/imanager-bl
drivers/gpio/imanager-core.c
drivers/gpio/imanager-i2c.c
drivers/gpio/imanager-hwmon.c

Changes from v1:
- Remove .owner from platform_driver in drivers/gpio/imanager-gpio.c
- Remove .owner from platform_driver in drivers/gpio/imanager-wdt.c
- Replace 2015 by 2016 in all files

Richard Vidal-Dorsch (6):
Add Advantech iManager MFD core driver
Add Advantech iManager GPIO driver
Add Advantech iManager HWmon driver
Add Advantech iManager I2C driver
Add Advantech iManager Backlight driver
Add Advantech iManager Watchdog driver

 drivers/gpio/Kconfig                  |   10 +
 drivers/gpio/Makefile                 |    1 +
 drivers/gpio/gpio-imanager.c          |  155 +++++
 drivers/hwmon/Kconfig                 |   11 +
 drivers/hwmon/Makefile                |    1 +
 drivers/hwmon/imanager-hwmon.c        | 1226 +++++++++++++++++++++++++++++++++
 drivers/i2c/busses/Kconfig            |   10 +
 drivers/i2c/busses/Makefile           |    1 +
 drivers/i2c/busses/i2c-imanager.c     |  461 +++++++++++++
 drivers/mfd/Kconfig                   |   18 +
 drivers/mfd/Makefile                  |    1 +
 drivers/mfd/imanager-core.c           |  941 +++++++++++++++++++++++++
 drivers/video/backlight/Kconfig       |    8 +
 drivers/video/backlight/Makefile      |    1 +
 drivers/video/backlight/imanager_bl.c |  210 ++++++
 drivers/watchdog/Kconfig              |   11 +
 drivers/watchdog/Makefile             |    1 +
 drivers/watchdog/imanager_wdt.c       |  303 ++++++++
 include/linux/mfd/imanager-ec.h       |  228 ++++++
 include/linux/mfd/imanager.h          |  221 ++++++
 20 files changed, 3819 insertions(+)
 create mode 100644 drivers/gpio/gpio-imanager.c
 create mode 100644 drivers/hwmon/imanager-hwmon.c
 create mode 100644 drivers/i2c/busses/i2c-imanager.c
 create mode 100644 drivers/mfd/imanager-core.c
 create mode 100644 drivers/video/backlight/imanager_bl.c
 create mode 100644 drivers/watchdog/imanager_wdt.c
 create mode 100644 include/linux/mfd/imanager-ec.h
 create mode 100644 include/linux/mfd/imanager.h
Signature · 1 line
2.10.1
#1 lore raw

PATCH v4 1/6 Add Advantech iManager MFD core driver

This patch adds Advantech iManager Embedded Controller MFD core driver. This mfd core dirver provides an interface for GPIO, I2C, HWmon, Watchdog, and Backlight/Brightness control.

---
 drivers/mfd/Kconfig             |  18 +
 drivers/mfd/Makefile            |   1 +
 drivers/mfd/imanager-core.c     | 941 ++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/imanager-ec.h | 228 ++++++++++
 include/linux/mfd/imanager.h    | 221 ++++++++++
 5 files changed, 1409 insertions(+)
 create mode 100644 drivers/mfd/imanager-core.c
 create mode 100644 include/linux/mfd/imanager-ec.h
 create mode 100644 include/linux/mfd/imanager.h
drivers/mfd/Kconfig +18 -0
index c6df644..294c19d 100644
@@ -388,6 +388,24 @@ config MFD_INTEL_QUARK_I2C_GPIO
 	  their respective IO driver.
 	  The GPIO exports a total amount of 8 interrupt-capable GPIOs.
 
+config MFD_IMANAGER
+	tristate "Advantech iManager EC device"
+	select MFD_CORE
+	help
+	  This is the core driver for Advantech iManager Embedded Controller
+	  found on some Advantech SOM, MIO, AIMB, and PCM modules/boards. The
+	  EC may provide functions like GPIO, I2C bus, HW monitoring, Watchdog,
+	  and backlight/brightness control.
+
+	  The following Advantech boards are supported:
+		* All SOM modules newer than SOM-5788
+		* MIO-5250/5251/5270/5271/5272/5290 and newer
+		* PCM-9389/9365/9376 and newer
+		* AIMB-273/274/230/231 and newer
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called imanager-core.
+
 config LPC_ICH
 	tristate "Intel ICH LPC"
 	depends on PCI
drivers/mfd/Makefile +1 -0
index 9834e66..e4b0a4d 100644
@@ -156,6 +156,7 @@ obj-$(CONFIG_MFD_DB8500_PRCMU)	+= db8500-prcmu.o
 obj-$(CONFIG_AB8500_CORE)	+= ab8500-core.o ab8500-sysctrl.o
 obj-$(CONFIG_MFD_TIMBERDALE)    += timberdale.o
 obj-$(CONFIG_PMIC_ADP5520)	+= adp5520.o
+obj-$(CONFIG_MFD_IMANAGER)	+= imanager-core.o
 obj-$(CONFIG_MFD_KEMPLD)	+= kempld-core.o
 obj-$(CONFIG_MFD_INTEL_QUARK_I2C_GPIO)	+= intel_quark_i2c_gpio.o
 obj-$(CONFIG_LPC_SCH)		+= lpc_sch.o
drivers/mfd/imanager-core.c new file +941 -0

941 lines not on this page · raw message

include/linux/mfd/imanager-ec.h new file +228 -0

228 lines not on this page · raw message

include/linux/mfd/imanager.h new file +221 -0

221 lines not on this page · raw message

Signature · 1 line
2.10.1
#3 lore raw

PATCH v4 2/6 Add Advantech iManager GPIO driver

In reply to Richard Vidal-Dorsch
---
 drivers/gpio/Kconfig         |  10 +++
 drivers/gpio/Makefile        |   1 +
 drivers/gpio/gpio-imanager.c | 155 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 166 insertions(+)
 create mode 100644 drivers/gpio/gpio-imanager.c
drivers/gpio/Kconfig +10 -0
index d011cb8..52e371f 100644
@@ -884,6 +884,16 @@ config HTC_EGPIO
 	    several HTC phones.  It provides basic support for input
 	    pins, output pins, and irqs.
 
+config GPIO_IMANAGER
+	tristate "Advantech iManager GPIO"
+	depends on MFD_IMANAGER
+	help
+	  This enables support for the iManager GPIO interface on some
+	  Advantech SOM, MIO, AIMB, and PCM modules/boards.
+
+	  This driver can also be built as a module. If so, the module will be
+	  called gpio-imanager.
+
 config GPIO_JANZ_TTL
 	tristate "Janz VMOD-TTL Digital IO Module"
 	depends on MFD_JANZ_CMODIO
drivers/gpio/Makefile +1 -0
index ab28a2d..e1250eb 100644
@@ -50,6 +50,7 @@ obj-$(CONFIG_GPIO_GPIO_MM)	+= gpio-gpio-mm.o
 obj-$(CONFIG_GPIO_GRGPIO)	+= gpio-grgpio.o
 obj-$(CONFIG_HTC_EGPIO)		+= gpio-htc-egpio.o
 obj-$(CONFIG_GPIO_ICH)		+= gpio-ich.o
+obj-$(CONFIG_GPIO_IMANAGER)	+= gpio-imanager.o
 obj-$(CONFIG_GPIO_IOP)		+= gpio-iop.o
 obj-$(CONFIG_GPIO_IT87)		+= gpio-it87.o
 obj-$(CONFIG_GPIO_JANZ_TTL)	+= gpio-janz-ttl.o
drivers/gpio/gpio-imanager.c new file +155 -0

155 lines not on this page · raw message

Signature · 1 line
2.10.1
#5 lore raw

PATCH v4 3/6 Add Advantech iManager HWmon driver

In reply to Richard Vidal-Dorsch
---
 drivers/hwmon/Kconfig          |   11 +
 drivers/hwmon/Makefile         |    1 +
 drivers/hwmon/imanager-hwmon.c | 1226 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1238 insertions(+)
 create mode 100644 drivers/hwmon/imanager-hwmon.c
drivers/hwmon/Kconfig +11 -0
index 45cef3d..7a9db12 100644
@@ -625,6 +625,17 @@ config SENSORS_CORETEMP
 	  sensor inside your CPU. Most of the family 6 CPUs
 	  are supported. Check Documentation/hwmon/coretemp for details.
 
+config SENSORS_IMANAGER
+	tristate "Advantech iManager Hardware Monitoring"
+	depends on MFD_IMANAGER
+	select HWMON_VID
+	help
+	  This enables support for Advantech iManager hardware monitoring
+	  of some Advantech SOM, MIO, AIMB, and PCM modules/boards.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called imanager-hwmon.
+
 config SENSORS_IT87
 	tristate "ITE IT87xx and compatibles"
 	depends on !PPC
drivers/hwmon/Makefile +1 -0
index aecf4ba..3f489ae 100644
@@ -76,6 +76,7 @@ obj-$(CONFIG_SENSORS_IBMAEM)	+= ibmaem.o
 obj-$(CONFIG_SENSORS_IBMPEX)	+= ibmpex.o
 obj-$(CONFIG_SENSORS_IBMPOWERNV)+= ibmpowernv.o
 obj-$(CONFIG_SENSORS_IIO_HWMON) += iio_hwmon.o
+obj-$(CONFIG_SENSORS_IMANAGER)	+= imanager-hwmon.o
 obj-$(CONFIG_SENSORS_INA209)	+= ina209.o
 obj-$(CONFIG_SENSORS_INA2XX)	+= ina2xx.o
 obj-$(CONFIG_SENSORS_INA3221)	+= ina3221.o
drivers/hwmon/imanager-hwmon.c new file +1226 -0

1,226 lines not on this page · raw message

Signature · 1 line
2.10.1
#6 lore raw

PATCH v4 4/6 Add Advantech iManager I2C driver

In reply to Richard Vidal-Dorsch
---
 drivers/i2c/busses/Kconfig        |  10 +
 drivers/i2c/busses/Makefile       |   1 +
 drivers/i2c/busses/i2c-imanager.c | 461 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 472 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-imanager.c
drivers/i2c/busses/Kconfig +10 -0
index d252276..7d1ecb4 100644
@@ -42,6 +42,16 @@ config I2C_ALI15X3
 	  This driver can also be built as a module.  If so, the module
 	  will be called i2c-ali15x3.
 
+config I2C_IMANAGER
+	tristate "Advantech iManager I2C Interface"
+	depends on MFD_IMANAGER
+	help
+	  This enables support for Advantech iManager I2C of some
+	  Advantech SOM, MIO, AIMB, and PCM modules/boards.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called i2c-imanager.
+
 config I2C_AMD756
 	tristate "AMD 756/766/768/8111 and nVidia nForce"
 	depends on PCI
drivers/i2c/busses/Makefile +1 -0
index 29764cc..d9ff210 100644
@@ -54,6 +54,7 @@ obj-$(CONFIG_I2C_GPIO)		+= i2c-gpio.o
 obj-$(CONFIG_I2C_HIGHLANDER)	+= i2c-highlander.o
 obj-$(CONFIG_I2C_HIX5HD2)	+= i2c-hix5hd2.o
 obj-$(CONFIG_I2C_IBM_IIC)	+= i2c-ibm_iic.o
+obj-$(CONFIG_I2C_IMANAGER)	+= i2c-imanager.o
 obj-$(CONFIG_I2C_IMG)		+= i2c-img-scb.o
 obj-$(CONFIG_I2C_IMX)		+= i2c-imx.o
 obj-$(CONFIG_I2C_IOP3XX)	+= i2c-iop3xx.o
drivers/i2c/busses/i2c-imanager.c new file +461 -0

461 lines not on this page · raw message

Signature · 1 line
2.10.1
#7 lore raw

PATCH v4 5/6 Add Advantech iManager Backlight driver

In reply to Richard Vidal-Dorsch
---
 drivers/video/backlight/Kconfig       |   8 ++
 drivers/video/backlight/Makefile      |   1 +
 drivers/video/backlight/imanager_bl.c | 210 ++++++++++++++++++++++++++++++++++
 3 files changed, 219 insertions(+)
 create mode 100644 drivers/video/backlight/imanager_bl.c
drivers/video/backlight/Kconfig +8 -0
index 5ffa4b4..2dac696 100644
@@ -251,6 +251,14 @@ config BACKLIGHT_HP700
 	  If you have an HP Jornada 700 series,
 	  say Y to include backlight control driver.
 
+config BACKLIGHT_IMANAGER
+	tristate "Advantech iManager Backlight/Brightness"
+	depends on MFD_IMANAGER
+	help
+	  This enables support for Advantech iManager Backlight and
+	  Brightness control of some Advantech SOM, MIO, AIMB, and
+	  PCM modules/boards.
+
 config BACKLIGHT_CARILLO_RANCH
 	tristate "Intel Carillo Ranch Backlight Driver"
 	depends on LCD_CLASS_DEVICE && PCI && X86 && FB_LE80578
drivers/video/backlight/Makefile +1 -0
index 16ec534..713b406 100644
@@ -35,6 +35,7 @@ obj-$(CONFIG_BACKLIGHT_GENERIC)		+= generic_bl.o
 obj-$(CONFIG_BACKLIGHT_GPIO)		+= gpio_backlight.o
 obj-$(CONFIG_BACKLIGHT_HP680)		+= hp680_bl.o
 obj-$(CONFIG_BACKLIGHT_HP700)		+= jornada720_bl.o
+obj-$(CONFIG_BACKLIGHT_IMANAGER)	+= imanager_bl.o
 obj-$(CONFIG_BACKLIGHT_IPAQ_MICRO)	+= ipaq_micro_bl.o
 obj-$(CONFIG_BACKLIGHT_LM3533)		+= lm3533_bl.o
 obj-$(CONFIG_BACKLIGHT_LM3630A)		+= lm3630a_bl.o
drivers/video/backlight/imanager_bl.c new file +210 -0

210 lines not on this page · raw message

Signature · 1 line
2.10.1
#8 lore raw

PATCH v4 6/6 Add Advantech iManager Watchdog driver

In reply to Richard Vidal-Dorsch
---
 drivers/watchdog/Kconfig        |  11 ++
 drivers/watchdog/Makefile       |   1 +
 drivers/watchdog/imanager_wdt.c | 303 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 315 insertions(+)
 create mode 100644 drivers/watchdog/imanager_wdt.c
drivers/watchdog/Kconfig +11 -0
index fdd3228..d6859da 100644
@@ -912,6 +912,17 @@ config WAFER_WDT
 	  To compile this driver as a module, choose M here: the
 	  module will be called wafer5823wdt.
 
+config IMANAGER_WDT
+	tristate "Advantech iManager Watchdog"
+	depends on MFD_IMANAGER
+	select WATCHDOG_CORE
+	help
+	  Support for Advantech iManager watchdog on some Advantech
+	  SOM, MIO, AIMB, and PCM modules/boards.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called imanager_wdt.
+
 config I6300ESB_WDT
 	tristate "Intel 6300ESB Timer/Watchdog"
 	depends on PCI
drivers/watchdog/Makefile +1 -0
index caa9f4a..eb7fccf 100644
@@ -117,6 +117,7 @@ endif
 obj-$(CONFIG_IT8712F_WDT) += it8712f_wdt.o
 obj-$(CONFIG_IT87_WDT) += it87_wdt.o
 obj-$(CONFIG_HP_WATCHDOG) += hpwdt.o
+obj-$(CONFIG_IMANAGER_WDT) += imanager_wdt.o
 obj-$(CONFIG_KEMPLD_WDT) += kempld_wdt.o
 obj-$(CONFIG_SC1200_WDT) += sc1200wdt.o
 obj-$(CONFIG_SCx200_WDT) += scx200_wdt.o
drivers/watchdog/imanager_wdt.c new file +303 -0

303 lines not on this page · raw message

Signature · 1 line
2.10.1
#2 lore raw

Re: [PATCH v4 1/6] Add Advantech iManager MFD core driver

In reply to Richard Vidal-Dorsch
Quoted 5 lines · Richard Vidal-Dorsch

This patch adds Advantech iManager Embedded Controller MFD core driver. This mfd core dirver provides an interface for GPIO, I2C, HWmon, Watchdog, and Backlight/Brightness control.

Quoted 10 lines
---
 drivers/mfd/Kconfig             |  18 +
 drivers/mfd/Makefile            |   1 +
 drivers/mfd/imanager-core.c     | 941 ++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/imanager-ec.h | 228 ++++++++++
 include/linux/mfd/imanager.h    | 221 ++++++++++
 5 files changed, 1409 insertions(+)
 create mode 100644 drivers/mfd/imanager-core.c
 create mode 100644 include/linux/mfd/imanager-ec.h
 create mode 100644 include/linux/mfd/imanager.h

After a brief review, it is my belief that this looks like a platform driver, which should live in drivers/platform/.

Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#4 lore raw

Re: [PATCH v4 2/6] Add Advantech iManager GPIO driver

In reply to Richard Vidal-Dorsch

drivers/gpio/gpio-imanager.c line 16

Quoted 4 lines · Richard Vidal-Dorsch
drivers/gpio/gpio-imanager.c new file +2 -0
+#include <linux/device.h>
+#include <linux/gpio.h>

#include <linux/gpio/driver.h>
should be enough.

drivers/gpio/gpio-imanager.c line 29

Quoted 13 lines
drivers/gpio/gpio-imanager.c new file +13 -0
+#include <linux/init.h>
+#include <linux/mfd/imanager.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/platform_device.h>
+
+#define EC_GPIOF_DIR_OUT       BIT(6)
+#define EC_GPIOF_DIR_IN                BIT(7)
+
+struct imanager_gpio_data {
+       struct imanager_device_data *imgr;
+       struct gpio_chip chip;
+};

Maybe some kerneldoc for this. Not necessary though since its sort of self-explanatory.

drivers/gpio/gpio-imanager.c line 40

Quoted 10 lines
drivers/gpio/gpio-imanager.c new file +10 -0
+static int imanager_gpio_direction_in(struct gpio_chip *chip, uint offset)
+{
+       struct imanager_gpio_data *data = gpiochip_get_data(chip);
+       struct imanager_device_data *imgr = data->imgr;
+       struct imanager_device_attribute *attr = imgr->ec.gpio.attr[offset];
+
+       mutex_lock(&imgr->lock);
+       imanager_write8(&imgr->ec, EC_CMD_GPIO_DIR_WR, attr->did,
+                       EC_GPIOF_DIR_IN);
+       mutex_unlock(&imgr->lock);

It kind of looks like it would be smarter if the imanager_write8() was taking and releasing the lock so you don't have to do it everywhere.

drivers/gpio/gpio-imanager.c line 71

Quoted 12 lines
drivers/gpio/gpio-imanager.c new file +12 -0
+static int imanager_gpio_get_direction(struct gpio_chip *chip, uint offset)
+{
+       struct imanager_gpio_data *data = gpiochip_get_data(chip);
+       struct imanager_device_data *imgr = data->imgr;
+       struct imanager_device_attribute *attr = imgr->ec.gpio.attr[offset];
+       int ret;
+
+       mutex_lock(&imgr->lock);
+       ret = imanager_read8(&imgr->ec, EC_CMD_GPIO_DIR_RD, attr->did);
+       mutex_unlock(&imgr->lock);
+
+       return ret & EC_GPIOF_DIR_IN ? GPIOF_DIR_IN : GPIOF_DIR_OUT;

Don't use GPIOF* flags, those are for consumers. Just return 0/1.

drivers/gpio/gpio-imanager.c line 86

Quoted 13 lines
drivers/gpio/gpio-imanager.c new file +13 -0
+static int imanager_gpio_get(struct gpio_chip *chip, uint offset)
+{
+       struct imanager_gpio_data *data = gpiochip_get_data(chip);
+       struct imanager_device_data *imgr = data->imgr;
+       struct imanager_device_attribute *attr = imgr->ec.gpio.attr[offset];
+       int ret;
+
+       mutex_lock(&imgr->lock);
+       ret = imanager_read8(&imgr->ec, EC_CMD_HWP_RD, attr->did);
+       mutex_unlock(&imgr->lock);
+
+       return ret;
+}

Can the read function return an error code? In that case it should be checked everywhere.

Also be sure to clamp ret like this:

return !!ret;

Apart from this it looks good.

Yours,
Linus Walleij