[PATCH 0/7] Introduce PTX1K Boot FPGA driver

2016-10-07 Thread Pantelis Antoniou
Add Juniper's PTX1K Boot FPGA driver. Those FPGAs
are present in Juniper's PTX series of routers.

The MFD driver provices watchdog/mtd/hwmon devices.

There are full device tree binding documents for the
master mfd driver and for the slave driver.

This patchset is against mainline as of today: v4.8-9431-g3477d16
and is dependent on the "Juniper prerequisites" and
"Juniper infrastructure" patchsets sent earlier.

Georgi Vlaev (7):
  mfd: Add PTX1K I2CS BootFPGA MFD driver
  mfd: dt-bindings: Add bindings for the Juniper PTX1K Boot FPGA
  watchdog: Add PTX1K I2CS BootFPGA watchdog driver.
  watchdog: ptx1kbf-wdt: Add ptx1kbf device tree bindings
  mtd: ptx1kbf: Add PTX1K BootFPGA MTD driver
  mtd: ptx1kbf: Bindings for Juniper's PTX1K Boot FPGA
  hwmon: ptx1kbf: Add PTX1K I2CS BootFPGA sensor driver

 .../devicetree/bindings/mfd/jnx-ptx1k-bootfpga.txt |  34 ++
 .../devicetree/bindings/mtd/ptx1kbf-mtd.txt|  23 +
 .../bindings/watchdog/jnx-ptx1kbf-wdt.txt  |  17 +
 drivers/hwmon/Kconfig  |  17 +
 drivers/hwmon/Makefile |   1 +
 drivers/hwmon/jnx_ptx1kbf_hwmon.c  | 123 
 drivers/mfd/Kconfig|  11 +
 drivers/mfd/Makefile   |   1 +
 drivers/mfd/ptx1k-bootfpga.c   | 462 ++
 drivers/mtd/devices/Kconfig|  10 +
 drivers/mtd/devices/Makefile   |   1 +
 drivers/mtd/devices/jnx_ptx1kbf_mtd.c  | 677 +
 drivers/watchdog/Kconfig   |  15 +
 drivers/watchdog/Makefile  |   1 +
 drivers/watchdog/jnx_ptx1kbf_wdt.c | 229 +++
 include/linux/mfd/ptx1k-bootfpga.h |  93 +++
 16 files changed, 1715 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/jnx-ptx1k-bootfpga.txt
 create mode 100644 Documentation/devicetree/bindings/mtd/ptx1kbf-mtd.txt
 create mode 100644 
Documentation/devicetree/bindings/watchdog/jnx-ptx1kbf-wdt.txt
 create mode 100644 drivers/hwmon/jnx_ptx1kbf_hwmon.c
 create mode 100644 drivers/mfd/ptx1k-bootfpga.c
 create mode 100644 drivers/mtd/devices/jnx_ptx1kbf_mtd.c
 create mode 100644 drivers/watchdog/jnx_ptx1kbf_wdt.c
 create mode 100644 include/linux/mfd/ptx1k-bootfpga.h

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/7] watchdog: Add PTX1K I2CS BootFPGA watchdog driver.

2016-10-07 Thread Pantelis Antoniou
From: Georgi Vlaev 

This driver allows using the I2CS watchdog on PTX1K. The
BootFPGA implements a watchdog that allows setting timeout
from predefined set of values from 15 msec to 491 sec.

Signed-off-by: Georgi Vlaev 
Signed-off-by: Guenter Roeck 
Signed-off-by: JawaharBalaji Thirumalaisamy 
[Ported from Juniper kernel]
Signed-off-by: Pantelis Antoniou 
---
 drivers/watchdog/Kconfig   |  15 +++
 drivers/watchdog/Makefile  |   1 +
 drivers/watchdog/jnx_ptx1kbf_wdt.c | 229 +
 3 files changed, 245 insertions(+)
 create mode 100644 drivers/watchdog/jnx_ptx1kbf_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 2554f47..a3761eb 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -1033,6 +1033,21 @@ config IT87_WDT
  To compile this driver as a module, choose M here: the module will
  be called it87_wdt.
 
+config JNX_PTX1KBF_WDT
+   tristate "Juniper Networks PTX1000 I2CS BootFPGA Watchdog"
+   depends on X86 && MFD_JUNIPER_PTX1KBF
+   ---help---
+ This is the driver for the watchdog timer built-in on the Juniper
+ Networks PTX1000 I2CS/BootFPGA and acessible from the LPC bus. The
+ BootFPGA watchdog allows several predefined thresholds, so this
+ driver will select a value close to these static values: 15 ms,
+ 30 ms, 60 ms, 120 ms, 240 ms, 480 ms, 960 ms, 1920 ms, 3840 ms,
+ 7680 ms, 15360 ms, 30720 ms, 61440 ms, 122880 ms, 245760 ms and
+ 516096 ms.
+
+ To compile this driver as a module, choose M here: the
+ module will be called jnx_ptx1kbf_wdt.
+
 config HP_WATCHDOG
tristate "HP ProLiant iLO2+ Hardware Watchdog Timer"
depends on X86 && PCI
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 942b795..f9fafdf 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -111,6 +111,7 @@ endif
 obj-$(CONFIG_IT8712F_WDT) += it8712f_wdt.o
 obj-$(CONFIG_IT87_WDT) += it87_wdt.o
 obj-$(CONFIG_JNX_PTXPMB_WDT) += ptxpmb_wdt.o
+obj-$(CONFIG_JNX_PTX1KBF_WDT) += jnx_ptx1kbf_wdt.o
 obj-$(CONFIG_HP_WATCHDOG) += hpwdt.o
 obj-$(CONFIG_KEMPLD_WDT) += kempld_wdt.o
 obj-$(CONFIG_SC1200_WDT) += sc1200wdt.o
diff --git a/drivers/watchdog/jnx_ptx1kbf_wdt.c 
b/drivers/watchdog/jnx_ptx1kbf_wdt.c
new file mode 100644
index 000..7d3e0b7
--- /dev/null
+++ b/drivers/watchdog/jnx_ptx1kbf_wdt.c
@@ -0,0 +1,229 @@
+/*
+ * Juniper Networks PTX1K RCB I2CS Boot FPGA watchdog driver
+ *
+ * Copyright (C) 2014 Juniper Networks. All rights reserved.
+ * Author: Georgi Vlaev 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define WDT_MIN_TIMEOUT1
+#define WDT_MAX_TIMEOUT491
+#define WDT_DEFAULT_TIMEOUT60  /* default heartbeat in seconds */
+
+#define DRVNAME "jnx-ptx1kbf-wdt"
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, bool, 0);
+
+#define MSW_NOWAYOUT __MODULE_STRING(WATCHDOG_NOWAYOUT)
+MODULE_PARM_DESC(nowayout,
+"Cannot be stopped once started (def=" MSW_NOWAYOUT ")");
+
+struct ptx1kbf_wdt {
+   void __iomem *base;
+   struct watchdog_device wdt_dev;
+};
+
+/*
+ * The BOOT_FPGA_WATCHDOG_TIMER_THRESHOLD register defines the watchdog
+ * timer thresholds in ms: 0x0 = 15 ms, 0x1 = 30 ms, ...  0xD = 122880 ms,
+ * 0xE = 245760 ms, 0xF = 492520 ms, or value = (2^index * 15)
+ */
+static int ptx1kbf_index_to_timeout(u8 reg)
+{
+   return ((1 << (reg & WTT_THRESHOLD_MASK)) * 15) / 1000;
+}
+
+static u8 ptx1kbf_timeout_to_index(unsigned int timeout)
+{
+   return fls(timeout * 1000 / 15) & WTT_THRESHOLD_MASK;
+}
+
+static int ptx1kbf_wdt_set_timeout(struct watchdog_device *wdt_dev,
+  unsigned int timeout)
+{
+   struct ptx1kbf_wdt *wdt = watchdog_get_drvdata(wdt_dev);
+   u8 reg, index;
+
+   if (timeout > WDT_MAX_TIMEOUT)
+   return -EINVAL;
+
+   index = ptx1kbf_timeout_to_index(timeout);
+
+   reg = ioread8(wdt->base + BOOT_FPGA_WATCHDOG_TIMER_THRESHOLD);
+   reg &= ~WTT_THRESHOLD_MASK;
+   reg |= index;
+   iowrite8(reg, wdt->base + BOOT_FPGA_WATCHDOG_TIMER_THRESHOLD);
+
+   /* Set the actual timeout supported by the watchdog */
+   

[PATCH 03/10] i2c/muxes: Juniper I2CS RE mux

2016-10-07 Thread Pantelis Antoniou
From: Georgi Vlaev 

Add support for Juniper I2C Slave RE multiplexer driver.

This I2C multiplexer driver allows the RE to access some of
the FPC I2C buses. It's compatible only with the FPC variant of the
I2CS.

Signed-off-by: Georgi Vlaev 
Signed-off-by: Guenter Roeck 
[Ported from Juniper kernel]
Signed-off-by: Pantelis Antoniou 
---
 drivers/i2c/muxes/Kconfig|  10 +++
 drivers/i2c/muxes/Makefile   |   1 +
 drivers/i2c/muxes/i2c-mux-i2cs.c | 155 +++
 3 files changed, 166 insertions(+)
 create mode 100644 drivers/i2c/muxes/i2c-mux-i2cs.c

diff --git a/drivers/i2c/muxes/Kconfig b/drivers/i2c/muxes/Kconfig
index f45a9cb..c95380d 100644
--- a/drivers/i2c/muxes/Kconfig
+++ b/drivers/i2c/muxes/Kconfig
@@ -30,6 +30,16 @@ config I2C_MUX_GPIO
  This driver can also be built as a module.  If so, the module
  will be called i2c-mux-gpio.
 
+config I2C_MUX_I2CS
+   tristate "Juniper I2C Slave MFD client RE multiplexer"
+   depends on MFD_JUNIPER_I2CS
+   help
+ Select this to enable the Juniper I2C Slave RE multiplexer driver
+ on the relevant Juniper platforms.
+
+ This driver can also be built as a module.  If so, the module
+ will be called i2c-mux-i2cs.
+
 config I2C_MUX_PCA9541
tristate "NXP PCA9541 I2C Master Selector"
help
diff --git a/drivers/i2c/muxes/Makefile b/drivers/i2c/muxes/Makefile
index 78d8cba..45b4287 100644
--- a/drivers/i2c/muxes/Makefile
+++ b/drivers/i2c/muxes/Makefile
@@ -6,6 +6,7 @@ obj-$(CONFIG_I2C_ARB_GPIO_CHALLENGE)+= 
i2c-arb-gpio-challenge.o
 obj-$(CONFIG_I2C_DEMUX_PINCTRL)+= i2c-demux-pinctrl.o
 
 obj-$(CONFIG_I2C_MUX_GPIO) += i2c-mux-gpio.o
+obj-$(CONFIG_I2C_MUX_I2CS) += i2c-mux-i2cs.o
 obj-$(CONFIG_I2C_MUX_PCA9541)  += i2c-mux-pca9541.o
 obj-$(CONFIG_I2C_MUX_PCA954x)  += i2c-mux-pca954x.o
 obj-$(CONFIG_I2C_MUX_PINCTRL)  += i2c-mux-pinctrl.o
diff --git a/drivers/i2c/muxes/i2c-mux-i2cs.c b/drivers/i2c/muxes/i2c-mux-i2cs.c
new file mode 100644
index 000..c498a44
--- /dev/null
+++ b/drivers/i2c/muxes/i2c-mux-i2cs.c
@@ -0,0 +1,155 @@
+/*
+ * Juniper Networks I2CS RE mux driver
+ *
+ * Copyright (C) 2012, 2013, 2014 Juniper Networks. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define MISC_IO_RE_EN  0x01
+
+/*
+ * Read/write to mux register.
+ *   Don't use i2c_transfer()/i2c_smbus_xfer()
+ *   for this as they will try to lock adapter a second time
+ */
+static int i2cs_mux_read_byte(struct i2c_client *client,
+ u8 offset, u8 *val)
+{
+   struct i2c_msg msg[2];
+
+   msg[0].addr = client->addr;
+   msg[0].flags = 0;
+   msg[0].len = 1;
+   msg[0].buf = 
+
+   msg[1].addr = client->addr;
+   msg[1].flags = I2C_M_RD;
+   msg[1].len = 1;
+   msg[1].buf = val;
+
+   return client->adapter->algo->master_xfer(client->adapter, msg, 2);
+}
+
+static int i2cs_mux_write_byte(struct i2c_client *client, u8 offset, u8 val)
+{
+   struct i2c_msg msg;
+   char buf[2];
+
+   msg.addr = client->addr;
+   msg.flags = 0;
+   msg.len = 2;
+   buf[0] = offset;
+   buf[1] = val;
+   msg.buf = buf;
+
+   return client->adapter->algo->master_xfer(client->adapter, , 1);
+}
+
+static int i2cs_mux_select(struct i2c_mux_core *muxc, u32 chan)
+{
+   int ret;
+   u8 val = 0;
+   struct i2c_client *client = i2c_mux_priv(muxc);
+
+   ret = i2cs_mux_read_byte(client, I2CS_MISC_IO, );
+   if (ret < 0)
+   return ret;
+
+   val |= MISC_IO_RE_EN;
+   ret = i2cs_mux_write_byte(client, I2CS_MISC_IO, val);
+
+   return ret;
+}
+
+static int i2cs_mux_deselect(struct i2c_mux_core *muxc, u32 chan)
+{
+   int ret;
+   u8 val = 0;
+   struct i2c_client *client = i2c_mux_priv(muxc);
+
+   ret = i2cs_mux_read_byte(client, I2CS_MISC_IO, );
+   if (ret < 0)
+   return ret;
+
+   val &= ~MISC_IO_RE_EN;
+   ret = i2cs_mux_write_byte(client, I2CS_MISC_IO, val);
+
+   return 0;
+}
+
+static int i2cs_mux_probe(struct platform_device *pdev)
+{
+   struct device *dev = >dev;
+   struct i2c_client *client;
+   struct i2c_mux_core *muxc;
+   int ret;
+
+   if (!dev->parent)
+   return 

[PATCH 2/7] mfd: dt-bindings: Add bindings for the Juniper PTX1K Boot FPGA

2016-10-07 Thread Pantelis Antoniou
From: Georgi Vlaev 

Add device tree bindings for the Juniper PTX1K Boot FPGA MFD driver.

Signed-off-by: Georgi Vlaev 
[Ported from Juniper kernel]
Signed-off-by: Pantelis Antoniou 
---
 .../devicetree/bindings/mfd/jnx-ptx1k-bootfpga.txt | 34 ++
 1 file changed, 34 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/jnx-ptx1k-bootfpga.txt

diff --git a/Documentation/devicetree/bindings/mfd/jnx-ptx1k-bootfpga.txt 
b/Documentation/devicetree/bindings/mfd/jnx-ptx1k-bootfpga.txt
new file mode 100644
index 000..596dec7
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/jnx-ptx1k-bootfpga.txt
@@ -0,0 +1,34 @@
+* Device tree bindings for Juniper's PTX1K boot FPGA MFD driver
+
+The device supports a hardware watchdog, a flash MTD device and
+a hwmon sensor device. The bindings of those drivers are described
+in the jnx-ptx1kbf-wdt, jnx-ptx1kbf-mtd and jnx-ptx1kbf-hwmon documents.
+
+Required properties:
+
+- compatible:  "ptx1k-bootfpga"
+
+- reg: contains offset/length value for device state control
+   registers space.
+
+Example:
+
+bootfpga@1 {
+   compatible = "jnx,ptx1k-bootfpga";
+   reg = <0x1 0x100>;
+
+   wdt {
+   compatible = "jnx,ptx1kbf-wdt";
+   /* no properties required */
+   };
+
+   mtd {
+   compatible = "jnx,ptx1kbf-mtd";
+   /* use the full device */
+   };
+
+   hwmon {
+   compatible = "jnx,ptx1kbf-hwmon";
+   /* no properties required */
+   };
+};
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 07/10] leds: i2cs: Add I2CS FPGA leds driver

2016-10-07 Thread Pantelis Antoniou
From: Georgi Vlaev 

Add support for the FRU faceplate status LEDs (OK, FAIL,
ACTIVE, STANDBY) controlled by the Juniper I2CS FPGA. This
driver is a jnx-i2cs-core client.

Signed-off-by: Georgi Vlaev 
[Ported from Juniper kernel]
Signed-off-by: Pantelis Antoniou 
---
 drivers/leds/Kconfig |   9 ++
 drivers/leds/Makefile|   1 +
 drivers/leds/leds-jnx-i2cs.c | 219 +++
 3 files changed, 229 insertions(+)
 create mode 100644 drivers/leds/leds-jnx-i2cs.c

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 7a628c6..45c6612 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -659,6 +659,15 @@ config LEDS_MLXCPLD
  This option enabled support for the LEDs on the Mellanox
  boards. Say Y to enabled these.
 
+config LEDS_JNX_I2CS
+   tristate "LED support for the Juniper Networks I2CS FPGA"
+   depends on LEDS_CLASS && I2C
+   select REGMAP_I2C
+   help
+ This option enables support for the FRU faceplate status
+ LEDs (OK, FAIL, ACTIVE, STANDBY) controlled by the Juniper
+ I2CS FPGA.
+
 comment "LED Triggers"
 source "drivers/leds/trigger/Kconfig"
 
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 3965070..1ce2d0b 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -71,6 +71,7 @@ obj-$(CONFIG_LEDS_IS31FL319X) += leds-is31fl319x.o
 obj-$(CONFIG_LEDS_IS31FL32XX)  += leds-is31fl32xx.o
 obj-$(CONFIG_LEDS_PM8058)  += leds-pm8058.o
 obj-$(CONFIG_LEDS_MLXCPLD) += leds-mlxcpld.o
+obj-$(CONFIG_LEDS_JNX_I2CS)+= leds-jnx-i2cs.o
 
 # LED SPI Drivers
 obj-$(CONFIG_LEDS_DAC124S085)  += leds-dac124s085.o
diff --git a/drivers/leds/leds-jnx-i2cs.c b/drivers/leds/leds-jnx-i2cs.c
new file mode 100644
index 000..c2d7274
--- /dev/null
+++ b/drivers/leds/leds-jnx-i2cs.c
@@ -0,0 +1,219 @@
+/*
+ * Juniper Networks I2CS FPGA LEDs driver
+ *
+ * Copyright (C) 2016 Juniper Networks
+ * Author: Georgi Vlaev 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define FRU_LEDS   4 /* Total LEDs (active, fail, ok, standby) */
+#define HW_BLINK_LEDS  3 /* LEDs with hw blink cap (standby not supported) */
+
+/*
+ * I2CS fru_led [0x12]
+ *
+ * bit 6   | bit 5| bit 4   |...| bit 0
+ * blink_ok|blink_fail|blink_act|led_standby|led_ok|led_fail|led_act
+ */
+
+/* TODO: Use the regmap from the parent MFD */
+static struct regmap_config i2cs_leds_regmap_config = {
+   .reg_bits = 8,
+   .val_bits = 8,
+   .max_register = I2CS_SPARE_OE,
+};
+
+struct i2cs_led {
+   struct led_classdev lc;
+   struct regmap *regmap;
+   struct work_struct work;
+   int blink;
+   int on;
+   int bit;
+};
+
+struct i2cs_led_data {
+   int num_leds;
+   struct i2cs_led *leds;
+};
+
+static void jnx_i2cs_leds_work(struct work_struct *work)
+{
+   struct i2cs_led *led = container_of(work, struct i2cs_led, work);
+
+   int mask = (BIT(led->bit) << 4) | BIT(led->bit);
+   int value = ((led->blink << led->bit) << 4) | (led->on << led->bit);
+
+   regmap_update_bits(led->regmap, I2CS_FRU_LED, mask, value & 0x7f);
+}
+
+static void jnx_i2cs_leds_brightness_set(struct led_classdev *lc,
+enum led_brightness brightness)
+{
+   struct i2cs_led *led = container_of(lc, struct i2cs_led, lc);
+
+   led->on = (brightness != LED_OFF);
+   led->blink = 0; /* always turn off hw blink on brightness_set() */
+   schedule_work(>work);
+}
+
+static int jnx_i2cs_leds_blink_set(struct led_classdev *lc,
+  unsigned long *delay_on,
+  unsigned long *delay_off)
+{
+   struct i2cs_led *led = container_of(lc, struct i2cs_led, lc);
+
+   led->blink = (*delay_on > 0);
+   led->on = led->blink; /* 'on' bit should be set if blinking */
+   schedule_work(>work);
+
+   return 0;
+}
+
+static int jnx_i2cs_leds_init_one(struct device *dev, struct device_node *np,
+ struct i2cs_led_data *ild,
+ struct regmap *regmap, int num)
+{
+   struct i2cs_led *led;
+   const char *string;
+   bool hw_blink;
+   int ret;
+   u32 reg;
+
+   ret = of_property_read_u32(np, "reg", );
+   if (ret || reg >= FRU_LEDS)
+   return -ENODEV;
+
+   led = >leds[num];
+   led->bit = reg;
+   led->regmap = regmap;
+
+   if (!of_property_read_string(np, "label", ))
+   

[PATCH 02/10] mfd: dt-bindings: Add bindings for the Juniper I2CS MFD

2016-10-07 Thread Pantelis Antoniou
From: Georgi Vlaev 

Add device tree bindings for the Juniper I2CS MFD driver.

Signed-off-by: Georgi Vlaev 
[Ported from Juniper kernel]
Signed-off-by: Pantelis Antoniou 
---
 Documentation/devicetree/bindings/mfd/jnx-i2cs.txt | 68 ++
 1 file changed, 68 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/jnx-i2cs.txt

diff --git a/Documentation/devicetree/bindings/mfd/jnx-i2cs.txt 
b/Documentation/devicetree/bindings/mfd/jnx-i2cs.txt
new file mode 100644
index 000..0ec103b
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/jnx-i2cs.txt
@@ -0,0 +1,68 @@
+Device-Tree bindings for Juniper Networks I2CS FPGA MFD
+
+Required properties:
+- compatible - Must be one of:
+   "jnx,i2cs-rcb"  (Routing Engine or Control Board FRUs)
+   "jnx,i2cs-fpc"  (Flexible Port Concentrator FRUs)
+   "jnx,i2cs-sib"  (Switching Interface Board FRUs)
+   "jnx,i2cs-fan"  (Fan Tray FRUs)
+
+Optional properties:
+
+Depending on the FRU, the I2CS MFD has varied group of sub-devices:
+
+Device   Description
+--   ---
+jnx,i2cs-gpio  : Virtual gpio mapping driver
+jnx,i2cs-fan-hwmon : hwmon driver for fan trays
+jnx,i2c-mux-i2cs   : I2C Mux driver for FPC FRUs
+jnx,leds-i2cs  : Led driver
+
+All these optional nodes are described in their respective binding
+documents.
+
+Example node:
+
+i2cs@54 {
+   compatible = "jnx,i2cs-fpc";
+   reg = <0x54>;
+   #address-cells = <0>;
+   #size-cells = <0>;
+
+   fpc2_mux {
+   compatible = "jnx,i2c-mux-i2cs";
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   fpc2i2c0: i2c@0 {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   reg = <0>;
+   };
+   };
+
+   fpc2_gpiomap: gpio-jnx-i2cs {
+   compatible = "jnx,gpio-i2cs";
+   reg = <0x54>;
+   #gpio-cells = <2>;
+   gpio-controller;
+   interrupt-controller;
+
+   /*
+* Map bits [0-3] of reg 0x21 as gpio inputs, bits [4-7]
+* as gpio outputs
+*/
+   i2c-gpio-map = <0x21 0x0f>;
+   };
+
+   leds-jnx-i2cs {
+   compatible = "jnx,leds-i2cs";
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   sib8-active {
+   reg = <0>;
+   linux,default-trigger = "sib8-active";
+   };
+   };
+};
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 01/10] mfd: Add Juniper I2CS MFD driver

2016-10-07 Thread Pantelis Antoniou
From: Georgi Vlaev 

Add Juniper's I2CS FPGA MFD driver.

This driver is bare-bones and only provides a method for the
instantiation of the following subdevices.

- I2C mux driver (i2c-mux-i2cs)
- LEDS driver (leds-jnx-i2cs)
- GPIO driver (gpio-jnx-i2cs)
- HWMON driver (i2cs-fan-hwmon)

Signed-off-by: Georgi Vlaev 
Signed-off-by: Guenter Roeck 
Signed-off-by: JawaharBalaji Thirumalaisamy 
[Ported from Juniper kernel]
Signed-off-by: Pantelis Antoniou 
---
 drivers/mfd/Kconfig   |  17 ++
 drivers/mfd/Makefile  |   1 +
 drivers/mfd/jnx-i2cs-core.c   | 118 ++
 include/linux/mfd/jnx-i2cs-core.h |  96 +++
 4 files changed, 232 insertions(+)
 create mode 100644 drivers/mfd/jnx-i2cs-core.c
 create mode 100644 include/linux/mfd/jnx-i2cs-core.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 6107f7a..82493d5 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1400,6 +1400,23 @@ config MFD_JUNIPER_CBC
  This driver can be built as a module. If built as a module it will be
  called "cbc-core"
 
+config MFD_JUNIPER_I2CS
+   tristate "Juniper I2CS FPGA"
+   depends on JNX_PTX1K_RCB || PTXPMB_COMMON || JNX_SYSTEM
+   select MFD_CORE
+   select REGMAP_I2C
+   select GPIO_JNX_I2CS
+   select I2C_MUX_I2CS
+   select LEDS_JNX_I2CS
+   depends on I2C=y
+   default y
+   help
+ Select this to enable the I2CS FPGA multi-function kernel driver.
+ This FPGA is present on almost any Juniper Networks card.
+
+ This driver can be built as a module. If built as a module it will be
+ called "jnx_i2cs"
+
 config MFD_TWL4030_AUDIO
bool "TI TWL4030 Audio"
depends on TWL4030_CORE
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 0ea6dc6..215d9cf 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -152,6 +152,7 @@ obj-$(CONFIG_MFD_JUNIPER_CPLD)  += ptxpmb-cpld-core.o
 obj-$(CONFIG_MFD_JUNIPER_SAM)  += sam-core.o
 obj-$(CONFIG_MFD_JUNIPER_EXT_CPLD) += ptxpmb-ext-cpld-core.o
 obj-$(CONFIG_MFD_JUNIPER_CBC)  += cbc-core.o
+obj-$(CONFIG_MFD_JUNIPER_I2CS) += jnx-i2cs-core.o
 obj-$(CONFIG_MFD_DB8500_PRCMU) += db8500-prcmu.o
 # ab8500-core need to come after db8500-prcmu (which provides the channel)
 obj-$(CONFIG_AB8500_CORE)  += ab8500-core.o ab8500-sysctrl.o
diff --git a/drivers/mfd/jnx-i2cs-core.c b/drivers/mfd/jnx-i2cs-core.c
new file mode 100644
index 000..d279a73
--- /dev/null
+++ b/drivers/mfd/jnx-i2cs-core.c
@@ -0,0 +1,118 @@
+/*
+ * drivers/mfd/jnx-i2cs-core.c
+ *
+ * Copyright (c) 2014, Juniper Networks
+ * Author: Georgi Vlaev 
+ *
+ * The I2C Slave FPGA (I2CS) - found on almost any Juniper card.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int jnx_i2cs_probe(struct i2c_client *i2c,
+ const struct i2c_device_id *id)
+{
+   struct device *dev = >dev;
+   struct jnx_i2cs_platform_data *pdata = dev_get_platdata(dev);
+   struct device_node *child, *np = dev->of_node;
+   struct mfd_cell *cells;
+   int ncells, ret;
+
+   if (np) {
+   ncells = of_get_child_count(np);
+   if (ncells == 0) {
+   dev_err(dev, "No child specified for %s\n", np->name);
+   return -EINVAL;
+   }
+
+   cells = devm_kzalloc(dev, ncells * sizeof(*cells), GFP_KERNEL);
+   if (!cells)
+   return -ENOMEM;
+
+   ncells = 0;
+   for_each_available_child_of_node(dev->of_node, child) {
+   const char *s;
+
+   s = of_get_property(child, "compatible", NULL);
+   if (!s) {
+   dev_err(dev,
+   "Missing compatible property for %s\n",
+   child->name);
+   return -EINVAL;
+   }
+
+   cells[ncells].name = child->name;
+   cells[ncells].of_compatible = s;
+   ncells++;
+   }
+   if (ncells == 0) {
+   dev_err(dev, "No active child for %s\n", np->name);
+   return -EINVAL;
+   }
+   } else if (pdata) {
+   cells = pdata->cells;
+   ncells = pdata->ncells;
+   } else {
+   return -ENODEV;
+   }
+
+   ret = mfd_add_devices(dev, 

[PATCH 7/7] hwmon: ptx1kbf: Add PTX1K I2CS BootFPGA sensor driver

2016-10-07 Thread Pantelis Antoniou
From: Georgi Vlaev 

The drivers allows reading CPU, PCH and DIMM modules teperatures
from the I2CS FPGA via the SMLink1 to the PCH.

Signed-off-by: Georgi Vlaev 
Signed-off-by: Guenter Roeck 
[Ported from Juniper kernel]
Signed-off-by: Pantelis Antoniou 
---
 drivers/hwmon/Kconfig |  17 ++
 drivers/hwmon/Makefile|   1 +
 drivers/hwmon/jnx_ptx1kbf_hwmon.c | 123 ++
 3 files changed, 141 insertions(+)
 create mode 100644 drivers/hwmon/jnx_ptx1kbf_hwmon.c

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index b9348d2..5b66c7b 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -674,6 +674,23 @@ config SENSORS_JNX_FAN
  This driver can also be built as a module.  If so, the module
  will be called jnx-fan.
 
+config SENSORS_JNX_PTX1KBF
+   tristate "Juniper Networks PTX1000 I2CS BootFPGA thermal sensors"
+   depends on MFD_JUNIPER_PTX1KBF
+   help
+ If you say yes here you get support for the hardware
+ monitoring features of the Juniper Networks PTX1000 I2CS BootFPGA
+ on the LPC bus. The CPU's digital thermal sensor can be read over
+ the PECI interface. PECI is connected to the PCH and the PCH's
+ Management Engine (ME) can be configured to poll CPU and DIMM
+ temperatures over the PECI interface. Then, it is possible for an
+ external I2C master (in the I2CS FPGA) to read CPU, DIMM and PCH
+ temperatures from the PCH over SMLink1 (which is connected to the 
board
+ I2C tree).
+
+ This driver can also be built as a module.  If so, the module
+ will be called jnx_ptx1kbf_hwmon.
+
 config SENSORS_POWR1220
tristate "Lattice POWR1220 Power Monitoring"
depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index eea631e..a3dedef 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -82,6 +82,7 @@ obj-$(CONFIG_SENSORS_INA3221) += ina3221.o
 obj-$(CONFIG_SENSORS_IT87) += it87.o
 obj-$(CONFIG_SENSORS_JC42) += jc42.o
 obj-$(CONFIG_SENSORS_JNX_FAN)   += jnx-fan.o
+obj-$(CONFIG_SENSORS_JNX_PTX1KBF)  += jnx_ptx1kbf_hwmon.o
 obj-$(CONFIG_SENSORS_JZ4740)   += jz4740-hwmon.o
 obj-$(CONFIG_SENSORS_K8TEMP)   += k8temp.o
 obj-$(CONFIG_SENSORS_K10TEMP)  += k10temp.o
diff --git a/drivers/hwmon/jnx_ptx1kbf_hwmon.c 
b/drivers/hwmon/jnx_ptx1kbf_hwmon.c
new file mode 100644
index 000..a9d6562
--- /dev/null
+++ b/drivers/hwmon/jnx_ptx1kbf_hwmon.c
@@ -0,0 +1,123 @@
+/*
+ * Juniper Networks PTX1K RCB I2CS Boot FPGA hwmon driver
+ *
+ * Copyright (C) 2014 Juniper Networks. All rights reserved.
+ * Author: Georgi Vlaev 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DRVNAME "jnx-ptx1kbf-hwmon"
+
+struct bf_hwmon {
+   void __iomem *base;
+};
+
+static const char *const bf_temp_label[] = {
+   "CPU", "PCH", "DIMM1", "DIMM2"
+};
+
+static ssize_t bf_show_temp(struct device *dev,
+   struct device_attribute *attr, char *buf)
+{
+   struct bf_hwmon *hwmon = dev_get_drvdata(dev);
+   int channel = to_sensor_dev_attr(attr)->index;
+
+   return sprintf(buf, "%d\n", be16_to_cpu(ioread16(hwmon->base +
+   BOOT_FPGA_CPU_TEMP_MSB + (channel * 2;
+}
+
+static ssize_t bf_show_label(struct device *dev,
+struct device_attribute *attr, char *buf)
+{
+   int channel = to_sensor_dev_attr(attr)->index;
+
+   return sprintf(buf, "%s\n", bf_temp_label[channel]);
+}
+
+/* CPU Temp */
+static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, bf_show_temp, NULL, 0);
+static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, bf_show_label, NULL, 0);
+/* PCH Temp */
+static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, bf_show_temp, NULL, 1);
+static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, bf_show_label, NULL, 1);
+/* DIMM1 Temp */
+static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, bf_show_temp, NULL, 2);
+static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO, bf_show_label, NULL, 2);
+/* DIMM2 Temp */
+static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, bf_show_temp, NULL, 3);
+static SENSOR_DEVICE_ATTR(temp4_label, S_IRUGO, bf_show_label, NULL, 3);
+
+static struct attribute *bf_attrs[] = {
+   _dev_attr_temp1_input.dev_attr.attr,
+   

[PATCH 6/7] mtd: ptx1kbf: Bindings for Juniper's PTX1K Boot FPGA

2016-10-07 Thread Pantelis Antoniou
From: Georgi Vlaev 

Add binding document for Junipers Flash IP block present
in the PTX1K Boot FPGA on PTX series of routers.

Signed-off-by: Georgi Vlaev 
[Ported from Juniper kernel]
Signed-off-by: Pantelis Antoniou 
---
 .../devicetree/bindings/mtd/ptx1kbf-mtd.txt| 23 ++
 1 file changed, 23 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mtd/ptx1kbf-mtd.txt

diff --git a/Documentation/devicetree/bindings/mtd/ptx1kbf-mtd.txt 
b/Documentation/devicetree/bindings/mtd/ptx1kbf-mtd.txt
new file mode 100644
index 000..4e25060
--- /dev/null
+++ b/Documentation/devicetree/bindings/mtd/ptx1kbf-mtd.txt
@@ -0,0 +1,23 @@
+Flash device on a PTX1K Boot FPGA
+
+These flash chips are found in the PTX series of Juniper routers.
+
+Required properties:
+- compatible : must be "jnx,flash-sam"
+
+Optional properties:
+- reg : memory address for the flash chip, note that this is not
+required since usually the device is a subdevice of the SAM MFD
+driver which fills in the register fields.
+
+For the rest of the properties, see mtd-physmap.txt.
+
+The device tree may optionally contain sub-nodes describing partitions of the
+address space. See partition.txt for more detail.
+
+Example:
+
+ptx1kbf_mtd {
+   compatible = "jnx,ptx1kbf-mtd";
+   /* usually the whole flash is used */
+};
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 5/7] mtd: ptx1kbf: Add PTX1K BootFPGA MTD driver

2016-10-07 Thread Pantelis Antoniou
From: Georgi Vlaev 

This patch adds a MTD driver for configuration updates of the
Xilinx Spartan 3AN based FPGAs on the PTX1K RE boards. The
driver is client of the ptx1k-bootfpga driver.

Signed-off-by: Georgi Vlaev 
[Ported from Juniper kernel]
Signed-off-by: Pantelis Antoniou 
---
 drivers/mtd/devices/Kconfig   |  10 +
 drivers/mtd/devices/Makefile  |   1 +
 drivers/mtd/devices/jnx_ptx1kbf_mtd.c | 677 ++
 3 files changed, 688 insertions(+)
 create mode 100644 drivers/mtd/devices/jnx_ptx1kbf_mtd.c

diff --git a/drivers/mtd/devices/Kconfig b/drivers/mtd/devices/Kconfig
index f5a9032..25a1c4a 100644
--- a/drivers/mtd/devices/Kconfig
+++ b/drivers/mtd/devices/Kconfig
@@ -155,6 +155,16 @@ config MTD_SAM_FLASH
  This driver can also be built as a module. When it is so the name of
  the module is flash-sam.
 
+config MTD_JNX_PTX1KBF
+   tristate "Juniper I2CS BootFPGA MTD driver"
+   depends on MFD_JUNIPER_PTX1KBF
+   help
+ This enables the MTD driver for the Juniper I2CS BootFPGA.
+ The driver is used to perform software upgrades of the RE's
+ Spartan 3AN XC3S50AN, XC3S200AN, XCS400AN, XC3S700AN and
+ XC3S1400AN based I2CS. The I2CS BootFPGA must implement the
+ remote upgrade software interface.
+
 config JNX_PMB_NVRAM
tristate "Juniper FPC PMB NVRAM Driver"
depends on (PTXPMB_COMMON || JNX_PTX_NGPMB)
diff --git a/drivers/mtd/devices/Makefile b/drivers/mtd/devices/Makefile
index 7556311..e1adfa5 100644
--- a/drivers/mtd/devices/Makefile
+++ b/drivers/mtd/devices/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_MTD_ST_SPI_FSM)+= st_spi_fsm.o
 obj-$(CONFIG_MTD_POWERNV_FLASH)+= powernv_flash.o
 
 obj-$(CONFIG_MTD_SAM_FLASH)+= sam-flash.o
+obj-$(CONFIG_MTD_JNX_PTX1KBF)  += jnx_ptx1kbf_mtd.o
 obj-$(CONFIG_JNX_PMB_NVRAM) += jnx_pmb_nvram.o
 
 CFLAGS_docg3.o += -I$(src)
diff --git a/drivers/mtd/devices/jnx_ptx1kbf_mtd.c 
b/drivers/mtd/devices/jnx_ptx1kbf_mtd.c
new file mode 100644
index 000..3bc17be
--- /dev/null
+++ b/drivers/mtd/devices/jnx_ptx1kbf_mtd.c
@@ -0,0 +1,677 @@
+/*
+ * Juniper Networks PTX1K RCB I2CS Boot FPGA MTD driver
+ * FPGA upgrades of the Spartan3AN/XC3S700 based I2CS.
+ *
+ * Copyright (C) 2015 Juniper Networks. All rights reserved.
+ * Author: Georgi Vlaev 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DEFAULT_BUSY_TIMEOUT   5   /* default timeout (msec) */
+#define PAGE_BUFFER_TXFER  400 /* page->sram transfer (usec) */
+
+/* FLASH_IF_CONTROL commands */
+#define CONTROL_READ_SID   0x80
+#define CONTROL_READ_DID   0x04
+#define CONTROL_READ_STATUS0x08
+#define CONTROL_SECTOR_ERASE   0x20
+#define CONTROL_PAGE_ERASE 0x40
+#define CONTROL_PAGE_WRITE 0x02
+#define CONTROL_PAGE_READ  0x01
+#define CONTROL_SP_READ0x02
+#define CONTROL_SP_WRITE   0x08
+#define CONTROL_SP_UALL0x01
+
+/* FLASH_IF_STATUS bits */
+#define STATUS_BUSYBIT(0)
+#define STATUS_ILLEGAL_WRITE   BIT(1)
+#define STATUS_ILLEGAL_ERASE   BIT(2)
+#define STATUS_ILLEGAL (STATUS_ILLEGAL_WRITE | STATUS_ILLEGAL_ERASE)
+#define STATUS_POWER_2_ADDRBIT(3)
+#define STATUS_SID_I2CS0x1F /* I2CS Spartan3AN FPGA */
+
+/* RU_CONFIG_CONTROL_STATUS bits */
+#define RU_CCS_USER_IMAGE  BIT(7)
+#define RU_CCS_RECONFIGBIT(5)
+
+#define MASK_SPARE_PAGE0x1f
+#define MASK_SPARE_SECTOR  0x1fff
+
+#define SECTOR_UNPROTECT   0x00
+#define SECTOR_PROTECT 0xff
+
+struct bfmtd_info {
+   const char *name;
+   u8 device_id;   /* flash id as reported by the fpga */
+   size_t flash_size;  /* total flash size */
+   size_t page_size;   /* read/write page size */
+   size_t sector_size; /* erase sector size */
+   size_t nr_pages;/* total number of pages */
+   size_t nr_sectors;  /* total number of sectors */
+   size_t writesize;   /* write size */
+   size_t writebufsize;/* internal fpga sram buffer size (bytes) */
+   size_t spare_size;  /* additional bytes per page in 'default' mode*/
+   /*
+* Timeouts are defined in the Xilinx "In-System Flash (ISF) Upgrade
+* 

[PATCH 1/7] mfd: Add PTX1K I2CS BootFPGA MFD driver

2016-10-07 Thread Pantelis Antoniou
From: Georgi Vlaev 

The driver allows access to the BootFPGA logic of the I2CS FPGA
@0xfed5000 from the LPC bus. The driver exports debugfs entries
for manipulating registers and device attrs for reading board and
FPGA IDs and switching the active BIOS flash. The client devices
created by the MFD driver depend on the PCB and FPGA version
numbers. PTX1K (etch1) RE boards support only watchdog clients.
Warn on using engineering releases (FPGA version = 0xEE) and
disable clients on revisions known to cause problems.

- watchdog - jnx_ptx1kbf_wdt
- mtd - jnx_ptx1kbf_mtd (etch2)
- hwmon - jnx_ptx1kbf_hwmon (etch2)

Signed-off-by: Georgi Vlaev 
Signed-off-by: Guenter Roeck 
Signed-off-by: JawaharBalaji Thirumalaisamy 
[Ported from Juniper kernel]
Signed-off-by: Pantelis Antoniou 
---
 drivers/mfd/Kconfig|  11 +
 drivers/mfd/Makefile   |   1 +
 drivers/mfd/ptx1k-bootfpga.c   | 462 +
 include/linux/mfd/ptx1k-bootfpga.h |  93 
 4 files changed, 567 insertions(+)
 create mode 100644 drivers/mfd/ptx1k-bootfpga.c
 create mode 100644 include/linux/mfd/ptx1k-bootfpga.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 82493d5..a2564ba 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1417,6 +1417,17 @@ config MFD_JUNIPER_I2CS
  This driver can be built as a module. If built as a module it will be
  called "jnx_i2cs"
 
+config MFD_JUNIPER_PTX1KBF
+   tristate "Juniper PTX1K RCB I2CS BootFPGA"
+   depends on JNX_PTX1K_RCB
+   select MFD_CORE
+   help
+ Select this to enable the I2CS Boot FPGA multi-function kernel driver.
+ This FPGA is present on the PTX1K RCB.
+
+ This driver can be built as a module. If built as a module it will be
+ called "ptx1k-bootfpga"
+
 config MFD_TWL4030_AUDIO
bool "TI TWL4030 Audio"
depends on TWL4030_CORE
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 215d9cf..1661b82 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -153,6 +153,7 @@ obj-$(CONFIG_MFD_JUNIPER_SAM)   += sam-core.o
 obj-$(CONFIG_MFD_JUNIPER_EXT_CPLD) += ptxpmb-ext-cpld-core.o
 obj-$(CONFIG_MFD_JUNIPER_CBC)  += cbc-core.o
 obj-$(CONFIG_MFD_JUNIPER_I2CS) += jnx-i2cs-core.o
+obj-$(CONFIG_MFD_JUNIPER_PTX1KBF) += ptx1k-bootfpga.o
 obj-$(CONFIG_MFD_DB8500_PRCMU) += db8500-prcmu.o
 # ab8500-core need to come after db8500-prcmu (which provides the channel)
 obj-$(CONFIG_AB8500_CORE)  += ab8500-core.o ab8500-sysctrl.o
diff --git a/drivers/mfd/ptx1k-bootfpga.c b/drivers/mfd/ptx1k-bootfpga.c
new file mode 100644
index 000..5ab2ed2
--- /dev/null
+++ b/drivers/mfd/ptx1k-bootfpga.c
@@ -0,0 +1,462 @@
+/*
+ * Juniper Networks PTX1K RCB I2CS Boot FPGA multi-function core driver
+ *
+ * Copyright (C) 2014 Juniper Networks. All rights reserved.
+ * Author: Georgi Vlaev 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#ifdef CONFIG_DEBUG_FS
+#include 
+#include 
+#include 
+#endif
+
+struct ptx1kbf_core {
+   struct device   *dev;
+   void __iomem*base;
+#ifdef CONFIG_DEBUG_FS
+   struct dentry *dir;
+   u8 addr;/* any register offsset */
+   struct debugfs_blob_wrapper blob;   /* regspace page blob */
+#endif
+};
+
+static struct resource ptx1kbf_resources[] = {
+   {
+   .start  = 0,
+   .end= 0xff,
+   .flags  = IORESOURCE_MEM,
+   },
+};
+
+static struct mfd_cell ptx1kbf_cells[] = {
+   {
+   .name = "jnx-ptx1kbf-wdt",
+   .num_resources = ARRAY_SIZE(ptx1kbf_resources),
+   .resources = ptx1kbf_resources,
+   .of_compatible = "jnx,ptx1kbf-wdt",
+   }, {
+   .name = "jnx-ptx1kbf-mtd",
+   .num_resources = ARRAY_SIZE(ptx1kbf_resources),
+   .resources = ptx1kbf_resources,
+   .of_compatible = "jnx,ptx1kbf-mtd",
+   }, {
+   .name = "jnx-ptx1kbf-hwmon",
+   .num_resources = ARRAY_SIZE(ptx1kbf_resources),
+   .resources = ptx1kbf_resources,
+   .of_compatible = "jnx,ptx1kbf-hwmon",
+   },
+};
+
+/* ptx1k-bootfpga debugfs */
+#ifdef CONFIG_DEBUG_FS
+/* debugfs: set/get 

[PATCH 4/7] watchdog: ptx1kbf-wdt: Add ptx1kbf device tree bindings

2016-10-07 Thread Pantelis Antoniou
From: Georgi Vlaev 

Add binding document for the watchdog driver of PTX1K Boot FPGA.

Signed-off-by: Georgi Vlaev 
[Ported from Juniper kernel]
Signed-off-by: Pantelis Antoniou 
---
 .../devicetree/bindings/watchdog/jnx-ptx1kbf-wdt.txt| 17 +
 1 file changed, 17 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/watchdog/jnx-ptx1kbf-wdt.txt

diff --git a/Documentation/devicetree/bindings/watchdog/jnx-ptx1kbf-wdt.txt 
b/Documentation/devicetree/bindings/watchdog/jnx-ptx1kbf-wdt.txt
new file mode 100644
index 000..0aa8086
--- /dev/null
+++ b/Documentation/devicetree/bindings/watchdog/jnx-ptx1kbf-wdt.txt
@@ -0,0 +1,17 @@
+Juniper's PTX1K Boot FPGA watchdog driver
+
+Required properties:
+
+- compatible:  Should be "jnx,ptx1kbf-wdt"
+
+Optional properties:
+
+- reg : Specifies base physical address and size of the registers. It is
+  optional since the MFD parent driver supplies it, but can be overridden.
+
+Example:
+
+wdt {
+   compatible = "jnx,ptx1kbf-wdt";
+   /* no properties defined */
+};
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 06/10] gpio: gpio-i2cs: Document bindings of I2CS FPGA GPIO block

2016-10-07 Thread Pantelis Antoniou
From: Georgi Vlaev 

Add device tree bindings document for the GPIO driver of
Juniper's I2CS FPGA.

Signed-off-by: Georgi Vlaev 
[Ported from Juniper kernel]
Signed-off-by: Pantelis Antoniou 
---
 .../devicetree/bindings/gpio/jnx,gpio-i2cs.txt | 43 ++
 1 file changed, 43 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/gpio/jnx,gpio-i2cs.txt

diff --git a/Documentation/devicetree/bindings/gpio/jnx,gpio-i2cs.txt 
b/Documentation/devicetree/bindings/gpio/jnx,gpio-i2cs.txt
new file mode 100644
index 000..835b7fb4
--- /dev/null
+++ b/Documentation/devicetree/bindings/gpio/jnx,gpio-i2cs.txt
@@ -0,0 +1,43 @@
+Juniper I2CS FPGA GPIO presence block
+
+This is virtual gpio driver, that maps each bit of the I2CS FPGA to
+a gpio. It's used as a compatibility replacement for FRUs that use
+I2CS FPGA to report presence, control and report power status in
+the Juniper's driver infra that uses gpios. Compatible with any I2CS.
+
+Required properties:
+
+Required properties:
+- compatible: "jnx,gpio-i2cs"
+
+- reg:
+Address on the I2C bus of the I2CS FPGA
+
+- gpio-controller: Marks the device node as a gpio controller.
+
+- interrupt-controller: Marks the device node as an interrupt
+   controller.
+
+- i2c-gpio-map: Map of "I2CS register" and "direction". The registers
+   are 8 bit wide, each bit of the register is mapped to either
+   input or output depending on the bits of the "direction". If
+   the bit in the direction is 1, then that bit from the I2CS
+   register is mapped to gpio input, otherwise to gpio output.
+
+- #gpio-cells : Should be two.  The first cell is the pin number and
+   the second cell is used to specify the gpio polarity:
+   0 = active high
+   1 = active low
+
+Optional properties:
+
+Example:
+
+cb0_slave: i2c-slave@54 {
+   compatible = "jnx,gpio-i2cs";
+   reg = <0x54>;
+   #gpio-cells = <2>;
+   gpio-controller;
+   interrupt-controller;
+   i2c-gpio-map = <0x21 0xff>; /* power status (bit 6) */
+};
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 09/10] hwmon: Add driver for Fan Tray on Juniper I2CS FGPA

2016-10-07 Thread Pantelis Antoniou
From: Avirup Banerjee 

Add a hwmon driver for Fan Trays using Juniper's I2CS FPGA.

Signed-off-by: Avirup Banerjee 
Signed-off-by: Georgi Vlaev 
Signed-off-by: Guenter Roeck 
Signed-off-by: JawaharBalaji Thirumalaisamy 
[Ported from Juniper kernel]
Signed-off-by: Pantelis Antoniou 
---
 drivers/hwmon/Kconfig  |  11 +
 drivers/hwmon/Makefile |   1 +
 drivers/hwmon/jnx-fan.c| 471 +
 include/linux/platform_data/jnx-i2cs-fan.h |  13 +
 4 files changed, 496 insertions(+)
 create mode 100644 drivers/hwmon/jnx-fan.c
 create mode 100644 include/linux/platform_data/jnx-i2cs-fan.h

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 45cef3d..b9348d2 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -663,6 +663,17 @@ config SENSORS_JC42
  This driver can also be built as a module.  If so, the module
  will be called jc42.
 
+config SENSORS_JNX_FAN
+   tristate "Juniper Fan Tray driver"
+   depends on I2C && MFD_JUNIPER_I2CS
+   select REGMAP_I2C
+   help
+ If you say yes here you get support for the Juniper Networks
+ Fan Tray Driver.
+
+ This driver can also be built as a module.  If so, the module
+ will be called jnx-fan.
+
 config SENSORS_POWR1220
tristate "Lattice POWR1220 Power Monitoring"
depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index aecf4ba..eea631e 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -81,6 +81,7 @@ obj-$(CONFIG_SENSORS_INA2XX)  += ina2xx.o
 obj-$(CONFIG_SENSORS_INA3221)  += ina3221.o
 obj-$(CONFIG_SENSORS_IT87) += it87.o
 obj-$(CONFIG_SENSORS_JC42) += jc42.o
+obj-$(CONFIG_SENSORS_JNX_FAN)   += jnx-fan.o
 obj-$(CONFIG_SENSORS_JZ4740)   += jz4740-hwmon.o
 obj-$(CONFIG_SENSORS_K8TEMP)   += k8temp.o
 obj-$(CONFIG_SENSORS_K10TEMP)  += k10temp.o
diff --git a/drivers/hwmon/jnx-fan.c b/drivers/hwmon/jnx-fan.c
new file mode 100644
index 000..d04e3ce
--- /dev/null
+++ b/drivers/hwmon/jnx-fan.c
@@ -0,0 +1,471 @@
+/*
+ * hwmon: Driver for Juniper Fan Tray Controller
+ *
+ * Copyright (c) 2014 Juniper Networks. All rights reserved.
+ * Author: Avirup Banerjee 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DRIVER_NAME "i2cs_fan_hwmon"
+
+/*
+ * Fan fpga register offsets
+ */
+
+#define I2CS_FAN_ADEC_VER   0x01
+#define I2CS_FAN_SELECT 0x40
+#define I2CS_FAN_SPEED_CTRL 0x41
+#define I2CS_FAN_MAX_TACH   0x42
+#define I2CS_FAN_MIN_TACH   0x43
+#define I2CS_FAN_TACH   0x44
+#define I2CS_FAN_INT_SRC0x45
+#define I2CS_FAN_INT_MASK   0x46
+#define I2CS_FAN_INT_1_70x47
+#define I2CS_FAN_INT_8_14   0x48
+#define I2CS_FAN_SPARE_FAN_INT_15_220x49
+#define I2CS_FAN_MODE_AND_TEST  0x4A
+#define I2CS_FAN_HW_DEBUG_1 0x4B
+#define I2CS_FAN_HW_DEBUG_2 0x4C
+#define I2CS_FAN_SW_FAN_POWER_SPEED_FAIL0x4D
+#define I2CS_FAN_ADEC_MASK_WAIT_SECOND  0x4F
+#define I2CS_FAN_RESET_WAIT_CONTROL 0x50
+#define I2CS_FAN_BOARD_STAT_1   0x51
+#define I2CS_FAN_BOARD_STAT_2   0x52
+#define I2CS_FAN_OK_THRESHOLD   0x53
+#define I2CS_FAN_SPARE  0x54
+#define I2CS_FAN_SPARE_OE   0x55
+
+#define FAN_TACH_FACTOR 120
+#define NUM_FANS_PER_TRAY   14
+
+struct jnx_fan_data {
+   struct regmap *regmap;
+   struct device *hwmon_dev;
+   struct mutex update_lock;
+   int fan_index;
+   int num_fans;
+   int factor;
+};
+
+static int jnx_fan_select(struct jnx_fan_data *data, int index)
+{
+   /* Return if fan has already been selected */
+   if (data->fan_index == index)
+   return 0;
+
+   data->fan_index = index;
+
+   return regmap_write(data->regmap, I2CS_FAN_SELECT, index);
+}
+
+static int jnx_fan_read_reg(struct jnx_fan_data *data, u8 reg, int index)
+{
+   unsigned int value;
+   int ret;
+
+   

[PATCH 05/10] gpio: i2cs: Juniper I2CS to GPIO pin mapping driver

2016-10-07 Thread Pantelis Antoniou
From: Guenter Roeck 

This driver maps I2C slave register bits to GPIO pins. Registers
are supposed to be 8 bit wide. Interrupt support is optional.

The driver is implemented as client of the I2CS MFD driver.

Signed-off-by: Georgi Vlaev 
Signed-off-by: Guenter Roeck 
Signed-off-by: JawaharBalaji Thirumalaisamy 
[Ported from Juniper kernel]
Signed-off-by: Pantelis Antoniou 
---
 drivers/gpio/Kconfig |  11 +
 drivers/gpio/Makefile|   1 +
 drivers/gpio/gpio-jnx-i2cs.c | 523 +++
 3 files changed, 535 insertions(+)
 create mode 100644 drivers/gpio/gpio-jnx-i2cs.c

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index ef8f408..34840e9 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -746,6 +746,17 @@ config GPIO_ADNP
  enough to represent all pins, but the driver will assume a
  register layout for 64 pins (8 registers).
 
+config GPIO_JNX_I2CS
+   tristate "Juniper I2C slave GPIO driver"
+   depends on I2C
+   depends on MFD_JUNIPER_I2CS
+   help
+ This driver maps I2C slave register bits to GPIO pins.
+ Mapping is configured through devicetree data.
+
+ This driver can also be built as a module.  If so, the module
+ will be called gpio-jnx-i2cs.
+
 config GPIO_MAX7300
tristate "Maxim MAX7300 GPIO expander"
select GPIO_MAX730X
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 825c2636..06d5d51 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -55,6 +55,7 @@ obj-$(CONFIG_GPIO_ICH)+= gpio-ich.o
 obj-$(CONFIG_GPIO_IOP) += gpio-iop.o
 obj-$(CONFIG_GPIO_IT87)+= gpio-it87.o
 obj-$(CONFIG_GPIO_JANZ_TTL)+= gpio-janz-ttl.o
+obj-$(CONFIG_GPIO_JNX_I2CS)+= gpio-jnx-i2cs.o
 obj-$(CONFIG_GPIO_KEMPLD)  += gpio-kempld.o
 obj-$(CONFIG_ARCH_KS8695)  += gpio-ks8695.o
 obj-$(CONFIG_GPIO_INTEL_MID)   += gpio-intel-mid.o
diff --git a/drivers/gpio/gpio-jnx-i2cs.c b/drivers/gpio/gpio-jnx-i2cs.c
new file mode 100644
index 000..3a87b6a
--- /dev/null
+++ b/drivers/gpio/gpio-jnx-i2cs.c
@@ -0,0 +1,523 @@
+/*
+ * I2C -> GPIO mapping driver
+ * Copyright (c) 2013 Juniper Networks
+ *
+ * Derived from gpio-adnp.c
+ * Copyright (C) 2011-2012 Avionic Design GmbH
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct i2c_gpio_map {
+   u8 reg; /* register offset  */
+   u8 direction;   /* direction (in/out) for each bit  */
+   u8 value;   /* cached value */
+   u8 irq_enable;
+   u8 irq_level;
+   u8 irq_rise;
+   u8 irq_fall;
+   u8 irq_high;
+   u8 irq_low;
+};
+
+struct i2cs_gpio {
+   struct i2c_client *client;  /* platform's device parent client */
+   struct device *dev; /* our device */
+   struct gpio_chip gpio;
+   int irq;
+
+   struct mutex i2c_lock;
+
+   struct irq_domain *domain;
+   struct mutex irq_lock;
+
+   struct delayed_work work;
+
+   int num_regs;
+   struct i2c_gpio_map *map;
+};
+
+static inline struct i2cs_gpio *to_i2cs_gpio(struct gpio_chip *chip)
+{
+   return container_of(chip, struct i2cs_gpio, gpio);
+}
+
+static int i2cs_gpio_read_byte_data(struct i2c_client *client, u8 reg)
+{
+   int val, retries;
+
+   /*
+* i2c slave reads fail once in a while for no obvious reason.
+* Retry on any error code.
+*/
+   for (retries = 0; retries < 10; retries++) {
+   val = i2c_smbus_read_byte_data(client, reg);
+   if (val >= 0)
+   break;
+   }
+   return val;
+}
+
+static int i2cs_gpio_gpio_get(struct gpio_chip *chip, unsigned int offset)
+{
+   struct i2cs_gpio *i2cs_gpio = to_i2cs_gpio(chip);
+   struct i2c_gpio_map *map = _gpio->map[offset >> 3];
+   struct i2c_client *client = i2cs_gpio->client;
+   u8 pos = offset & 7;
+   u8 reg = map->reg;
+   int val;
+
+   val = i2cs_gpio_read_byte_data(client, reg);
+   if (val < 0)
+   return val;
+
+   map->value = val;
+
+   return !!(val & BIT(pos));
+}
+
+static void __i2cs_gpio_gpio_set(struct i2cs_gpio *i2cs_gpio,
+unsigned int offset, int value)
+{
+   struct i2c_gpio_map *map = _gpio->map[offset >> 3];
+   struct i2c_client *client = i2cs_gpio->client;
+   u8 pos = offset & 7;
+   u8 reg = map->reg;
+   int val;
+
+   val = i2cs_gpio_read_byte_data(client, reg);
+   if (val < 0)
+   return;
+
+   

Re: [PATCHv2] hwmon: Add tc654 driver

2016-10-07 Thread Guenter Roeck
On Fri, Oct 07, 2016 at 02:38:44PM +1300, Chris Packham wrote:
> Add support for the tc654 and tc655 fan controllers from Microchip.
> 
> http://ww1.microchip.com/downloads/en/DeviceDoc/20001734C.pdf
> 
> Signed-off-by: Chris Packham 
> ---
> 
> Changes in v2:
> - Add Documentation/hwmon/tc654
> - Incorporate most of the review comments from Guenter. Additional error
>   handling is added. Unused/unnecessary code is removed. I decided not
>   to go down the regmap path yet. I may circle back to it when I look at
>   using regmap in the adm9240 driver.
> 
>  .../devicetree/bindings/i2c/trivial-devices.txt|   2 +
>  Documentation/hwmon/tc654  |  26 ++
>  drivers/hwmon/Kconfig  |  11 +
>  drivers/hwmon/Makefile |   1 +
>  drivers/hwmon/tc654.c  | 513 
> +
>  5 files changed, 553 insertions(+)
>  create mode 100644 Documentation/hwmon/tc654
>  create mode 100644 drivers/hwmon/tc654.c
> 
> diff --git a/Documentation/devicetree/bindings/i2c/trivial-devices.txt 
> b/Documentation/devicetree/bindings/i2c/trivial-devices.txt
> index 1416c6a0d2cd..833fb9f133d3 100644
> --- a/Documentation/devicetree/bindings/i2c/trivial-devices.txt
> +++ b/Documentation/devicetree/bindings/i2c/trivial-devices.txt
> @@ -122,6 +122,8 @@ microchip,mcp4662-502 Microchip 8-bit Dual I2C 
> Digital Potentiometer with NV Mem
>  microchip,mcp4662-103Microchip 8-bit Dual I2C Digital Potentiometer 
> with NV Memory (10k)
>  microchip,mcp4662-503Microchip 8-bit Dual I2C Digital Potentiometer 
> with NV Memory (50k)
>  microchip,mcp4662-104Microchip 8-bit Dual I2C Digital Potentiometer 
> with NV Memory (100k)
> +microchip,tc654  PWM Fan Speed Controller With Fan Fault 
> Detection
> +microchip,tc655  PWM Fan Speed Controller With Fan Fault 
> Detection
>  national,lm63Temperature sensor with integrated fan control
>  national,lm75I2C TEMP SENSOR
>  national,lm80Serial Interface ACPI-Compatible Microprocessor 
> System Hardware Monitor
> diff --git a/Documentation/hwmon/tc654 b/Documentation/hwmon/tc654
> new file mode 100644
> index ..93796c5c7e79
> --- /dev/null
> +++ b/Documentation/hwmon/tc654
> @@ -0,0 +1,26 @@
> +Kernel driver tc654
> +===
> +
> +Supported chips:
> +  * Microship TC654 and TC655
> +Prefix: 'tc654'
> +Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/20001734C.pdf
> +
> +Authors:
> +Chris Packham 
> +Masahiko Iwamoto 
> +
> +Description
> +---
> +This driver implements support for the Microchip TC654 and TC655.
> +
> +The TC654 used the 2-wire interface compatible with the SMBUS 2.0

uses

> +specification. The TC654 has two (2) inputs for measuring fan RPM and
> +one (1) PWM output which can be used for fan control.
> +
> +Configuration Notes
> +---
> +Ordinarily the pwm1_mode ABI is used for controlling the pwm output
> +mode.  However, for this chip the output is always pwm, and the
> +pwm1_mode determines if the pwm output is controlled via the pwm1 value
> +or via the Vin analog input.

Please describe the supported values here.

> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> index 45cef3d2c75c..8681bc65cde5 100644
> --- a/drivers/hwmon/Kconfig
> +++ b/drivers/hwmon/Kconfig
> @@ -907,6 +907,17 @@ config SENSORS_MCP3021
> This driver can also be built as a module.  If so, the module
> will be called mcp3021.
>  
> +config SENSORS_TC654
> + tristate "Microchip TC654/TC655 and compatibles"
> + depends on I2C
> + help
> +   If you say yes here you get support for TC654 and TC655.
> +   The TC654 and TC655 are PWM mode fan speed controllers with
> +   FanSense technology for use with brushless DC fans.
> +
> +   This driver can also be built as a module.  If so, the module
> +   will be called tc654.
> +
>  config SENSORS_MENF21BMC_HWMON
>   tristate "MEN 14F021P00 BMC Hardware Monitoring"
>   depends on MFD_MENF21BMC
> diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
> index aecf4ba17460..c651f0f1d047 100644
> --- a/drivers/hwmon/Makefile
> +++ b/drivers/hwmon/Makefile
> @@ -122,6 +122,7 @@ obj-$(CONFIG_SENSORS_MAX6697) += max6697.o
>  obj-$(CONFIG_SENSORS_MAX31790)   += max31790.o
>  obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o
>  obj-$(CONFIG_SENSORS_MCP3021)+= mcp3021.o
> +obj-$(CONFIG_SENSORS_TC654)  += tc654.o
>  obj-$(CONFIG_SENSORS_MENF21BMC_HWMON) += menf21bmc_hwmon.o
>  obj-$(CONFIG_SENSORS_NCT6683)+= nct6683.o
>  obj-$(CONFIG_SENSORS_NCT6775)+= nct6775.o
> diff --git a/drivers/hwmon/tc654.c b/drivers/hwmon/tc654.c
> new file mode 100644
> index ..cba31cbd3383
> --- 

Re: [PATCH] hwmon: (lm73) Add temp1_max_hyst entry to sysfs

2016-10-07 Thread Guenter Roeck
On Fri, Oct 07, 2016 at 05:42:21PM +1300, Joshua Scott wrote:
> Currently, the lm73 driver has a temp1_max and a temp1_min. These make
> sense when using temp1_max_alarm and temp1_min_alarm to determine if the
> temperature has exceeded the chosen limits.
> 
> However, when using the ALARM output pin on the lm73 chip, the lower
> temperature value behaves as a hysteresis value. Rather than the low value
> triggering a "too cold" alarm, it is the point at which an existing high
> temperature alarm is turned off.
> 
> Add a sysfs entry for temp1_max_hyst, tied to the same register as
> temp1_min.
> 
Reading through the datasheet, resetting alert is really a side effect,
not really a hysteresis value. Hysteresis would be if THIGH would be
reset if the temperature goes below Tmin, but that is not the case.

It also looks like the alert bit should be reset by software, by
writing 1 into bit 3 of the configuration register. 

Given that, I don't think we should change anything. One option,
though, might be to implement alert and/or interrupt support and handle
the alert condition as expected, ie send an event to user space and
reset the alert bit in the interrupt/alert handler.

Guenter

> Signed-off-by: Joshua Scott 
> ---
>  drivers/hwmon/lm73.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/hwmon/lm73.c b/drivers/hwmon/lm73.c
> index 9653bb8..b46a91a 100644
> --- a/drivers/hwmon/lm73.c
> +++ b/drivers/hwmon/lm73.c
> @@ -170,6 +170,8 @@ abort:
>  
>  static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO,
>   show_temp, set_temp, LM73_REG_MAX);
> +static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO,
> + show_temp, set_temp, LM73_REG_MIN);
>  static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO,
>   show_temp, set_temp, LM73_REG_MIN);
>  static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO,
> @@ -184,6 +186,7 @@ static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO,
>  static struct attribute *lm73_attrs[] = {
>   _dev_attr_temp1_input.dev_attr.attr,
>   _dev_attr_temp1_max.dev_attr.attr,
> + _dev_attr_temp1_max_hyst.dev_attr.attr,
>   _dev_attr_temp1_min.dev_attr.attr,
>   _dev_attr_update_interval.dev_attr.attr,
>   _dev_attr_temp1_max_alarm.dev_attr.attr,
> -- 
> 2.9.3
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 2/9] hwmon: (core) New hwmon registration API

2016-10-07 Thread Jean Delvare
Hi Guenter,

On Tue, 4 Oct 2016 12:37:13 -0700, Guenter Roeck wrote:
> On Tue, Oct 04, 2016 at 10:45:59AM +0200, Jean Delvare wrote:
> > I see this patch is upstream now, but I had started reviewing it and
> > maybe some of my comments are still relevant.
> > 
> As always, I appreciate the feedback. I'll be happy to submit follow-up
> patches to address any concerns.
> 
> > It's not meant to be a complete review, which is why I had not sent it
> > yet :-(
> > 
> > Also I did not follow the first iterations of this patchset so my
> > apologies if I raise points which have already been discussed.
> > 
> > May I ask if any other subsystem is already doing anything like that?
> > 
> Depends what you mean with "anything like that". The API is inspired by
> the iio API and a little by the thermal API. The details are probably
> unique, though.

I meant the idea of describing the device capabilities and letting the
core code generate the device attributes (or anything else) based on
that data. The benefits are obvious, but it has a complexity and
run-time cost so I am wondering how popular this approach is.

> > FYI I gave a presentation about the hwmon device registration API
> > evolution last week at Kernel Recipes [1] in Paris and mentioned this
> > proposal.
> > 
> > [1] https://kernel-recipes.org/en/2016/
> > 
> > On dim., 2016-07-24 at 20:32 -0700, Guenter Roeck wrote:
> > > Up to now, each hwmon driver has to implement its own sysfs attributes.
> > > This requires a lot of template code, and distracts from the driver's core
> > > function to read and write chip registers.
> > > 
> > > To be able to reduce driver complexity, move sensor attribute handling
> > > and thermal zone registration into hwmon core. By using the new API,
> > > driver code and data size is typically reduced by 20-70%, depending
> > > on driver complexity and the number of sysfs attributes supported.
> > 
> > I looked at the diffstats for the drivers you have already converted and
> > couldn't see any such huge improvement... Some drivers appear to be even
> > larger after conversion?
> > 
> The above refers to code and data sizes.

You mean at the binary level?

Have you considered the case where several devices exist for the same
driver? Static attributes are shared between devices, but with the
generated ones this is no longer the case, right?

> > > (...)
> > > +static struct attribute *hwmon_genattr(struct device *dev,
> > > +const void *drvdata,
> > > +enum hwmon_sensor_types type,
> > > +u32 attr,
> > > +int index,
> > > +const char *template,
> > > +const struct hwmon_ops *ops)
> > > +{
> > > + struct hwmon_device_attribute *hattr;
> > > + struct device_attribute *dattr;
> > > + struct attribute *a;
> > > + umode_t mode;
> > > + char *name;
> > > +
> > > + /* The attribute is invisible if there is no template string */
> > > + if (!template)
> > > + return ERR_PTR(-ENOENT);
> > > +
> > > + mode = ops->is_visible(drvdata, type, attr, index);
> > 
> > Any reason why you don't simply attach the provided ->is_visible to the
> > attribute group and let the driver core do the work?
> > 
> Parameter are all different
>   umode_t (*is_visible)(const void *drvdata, enum hwmon_sensor_types type,
> u32 attr, int channel);
> vs.
>   umode_t (*is_visible)(struct kobject *, struct attribute *, int);

But this is the consequence of how you implemented it, not the reason?

Now I seem to understand that delegating the check to the driver core
would make it happen later, which means you would have to instantiate
all attributes, even if some are never going to be used? So this is an
optimization?

But this prevents sharing the attributes between devices, as pointed
out above. Well, I guess you can't have it all. I don't know what is
the more important.

> > > + return ERR_PTR(-ENOENT);
> > > +
> > > + if ((mode & S_IRUGO) && !ops->read)
> > > + return ERR_PTR(-EINVAL);
> > > + if ((mode & S_IWUGO) && !ops->write)
> > > + return ERR_PTR(-EINVAL);
> > > +
> > > + if (type == hwmon_chip) {
> > 
> > This needs a comment. It's not obvious what "hwmon_chip" is supposed to
> > represent. From what I understand, maybe "hwmon_unique" would be a more
> > appropriate name.
> > 
> Those are meant to be for attributes which apply to the entire chip.

Not really. As you implemented it, it is meant for attributes which are
not specific to an input or output in particular. That is, attributes
which do not include a channel number. "update_interval" and
"alarms" (which I'd like to get rid of, btw) apply to the entire chip,
but "temp_reset_history" does not.

> Not sure if 'hwmon_unique' would reflect that better.
> From the documentation:
>   "A virtual sensor type, used to describe attributes