Merge branches 'ib-mfd-arm-3.18', 'ib-mfd-hwmon-leds-watchdog-3.18' and 'ib-mfd-power...
authorLee Jones <lee.jones@linaro.org>
Fri, 26 Sep 2014 07:14:30 +0000 (08:14 +0100)
committerLee Jones <lee.jones@linaro.org>
Fri, 26 Sep 2014 07:14:30 +0000 (08:14 +0100)
21 files changed:
Documentation/devicetree/bindings/i2c/trivial-devices.txt
Documentation/devicetree/bindings/regulator/da9210.txt
Documentation/devicetree/bindings/vendor-prefixes.txt
Documentation/hwmon/menf21bmc [new file with mode: 0644]
arch/arm/boot/dts/imx53-smd.dts
arch/arm/boot/dts/imx6qdl-phytec-pfla02.dtsi
arch/arm/boot/dts/r8a7790-lager.dts
arch/arm/boot/dts/r8a7791-koelsch.dts
drivers/hwmon/Kconfig
drivers/hwmon/Makefile
drivers/hwmon/menf21bmc_hwmon.c [new file with mode: 0644]
drivers/leds/Kconfig
drivers/leds/Makefile
drivers/leds/leds-menf21bmc.c [new file with mode: 0644]
drivers/mfd/Kconfig
drivers/mfd/Makefile
drivers/mfd/da9055-core.c
drivers/mfd/menf21bmc.c [new file with mode: 0644]
drivers/watchdog/Kconfig
drivers/watchdog/Makefile
drivers/watchdog/menf21bmc_wdt.c [new file with mode: 0644]

index 6af570ec53b4b5b9ea96bcc42a722007265d96aa..5af3d9df6ecb05c5da5dbeff969bcfba18a09a9a 100644 (file)
@@ -44,7 +44,7 @@ dallas,ds1775         Tiny Digital Thermometer and Thermostat
 dallas,ds3232          Extremely Accurate I²C RTC with Integrated Crystal and SRAM
 dallas,ds4510          CPU Supervisor with Nonvolatile Memory and Programmable I/O
 dallas,ds75            Digital Thermometer and Thermostat
-dialog,da9053          DA9053: flexible system level PMIC with multicore support
+dlg,da9053             DA9053: flexible system level PMIC with multicore support
 epson,rx8025           High-Stability. I2C-Bus INTERFACE REAL TIME CLOCK MODULE
 epson,rx8581           I2C-BUS INTERFACE REAL TIME CLOCK MODULE
 fsl,mag3110            MAG3110: Xtrinsic High Accuracy, 3D Magnetometer
index f120f229d67d3e0da3ae3772368484e481611ea0..3297c53cb9152395c310693034e33dc3ee26f95e 100644 (file)
@@ -2,7 +2,7 @@
 
 Required properties:
 
-- compatible:  must be "diasemi,da9210"
+- compatible:  must be "dlg,da9210"
 - reg:         the i2c slave address of the regulator. It should be 0x68.
 
 Any standard regulator properties can be used to configure the single da9210
@@ -11,7 +11,7 @@ DCDC.
 Example:
 
        da9210@68 {
-               compatible = "diasemi,da9210";
+               compatible = "dlg,da9210";
                reg = <0x68>;
 
                regulator-min-microvolt = <900000>;
index ac7269f90764da1193f064dad2af7193398b5d8f..f4318d7be35cdce476e154372af4b83f3ff192c3 100644 (file)
@@ -38,6 +38,7 @@ dallas        Maxim Integrated Products (formerly Dallas Semiconductor)
 davicom        DAVICOM Semiconductor, Inc.
 denx   Denx Software Engineering
 digi   Digi International Inc.
+dlg    Dialog Semiconductor
 dlink  D-Link Corporation
 dmo    Data Modul AG
 ebv    EBV Elektronik
diff --git a/Documentation/hwmon/menf21bmc b/Documentation/hwmon/menf21bmc
new file mode 100644 (file)
index 0000000..2a273a0
--- /dev/null
@@ -0,0 +1,50 @@
+Kernel driver menf21bmc_hwmon
+=============================
+
+Supported chips:
+       * MEN 14F021P00
+         Prefix: 'menf21bmc_hwmon'
+         Adresses scanned: -
+
+Author: Andreas Werner <andreas.werner@men.de>
+
+Description
+-----------
+
+The menf21bmc is a Board Management Controller (BMC) which provides an I2C
+interface to the host to access the features implemented in the BMC.
+
+This driver gives access to the voltage monitoring feature of the main
+voltages of the board.
+The voltage sensors are connected to the ADC inputs of the BMC which is
+a PIC16F917 Mikrocontroller.
+
+Usage Notes
+-----------
+
+This driver is part of the MFD driver named "menf21bmc" and does
+not auto-detect devices.
+You will have to instantiate the MFD driver explicitly.
+Please see Documentation/i2c/instantiating-devices for
+details.
+
+Sysfs entries
+-------------
+
+The following attributes are supported. All attributes are read only
+The Limits are read once by the driver.
+
+in0_input      +3.3V input voltage
+in1_input      +5.0V input voltage
+in2_input      +12.0V input voltage
+in3_input      +5V Standby input voltage
+in4_input      VBAT (on board battery)
+
+in[0-4]_min    Minimum voltage limit
+in[0-4]_max    Maximum voltage limit
+
+in0_label      "MON_3_3V"
+in1_label      "MON_5V"
+in2_label      "MON_12V"
+in3_label      "5V_STANDBY"
+in4_label      "VBAT"
index 5ec1590ff7bcc328540b0c92609c26a75cccc52b..1d325576bcc04d4a119d96f7c85612f2f4bd62a2 100644 (file)
        };
 
        pmic: dialog@48 {
-               compatible = "dialog,da9053", "dialog,da9052";
+               compatible = "dlg,da9053", "dlg,da9052";
                reg = <0x48>;
        };
 };
index 2694aa84e18748b532a491b25f50fef0a2fc4a6d..0e50bb0a6b94c846f8dc0cf039893b1560fd4b97 100644 (file)
@@ -83,7 +83,7 @@
        };
 
        pmic@58 {
-               compatible = "dialog,da9063";
+               compatible = "dlg,da9063";
                reg = <0x58>;
                interrupt-parent = <&gpio4>;
                interrupts = <17 0x8>; /* active-low GPIO4_17 */
index 856b4236b67470a6a484116f71cad2ccf58ebb98..e3db1056d0027ac2dac9d9dc03bf56605942ef05 100644 (file)
        status = "okay";
 
        vdd_dvfs: regulator@68 {
-               compatible = "diasemi,da9210";
+               compatible = "dlg,da9210";
                reg = <0x68>;
 
                regulator-min-microvolt = <1000000>;
index be59014474b20114b77ff0d7043b05635b4d9013..be29711ff31919c0b30ad250e68d33f09127bba3 100644 (file)
        clock-frequency = <100000>;
 
        vdd_dvfs: regulator@68 {
-               compatible = "diasemi,da9210";
+               compatible = "dlg,da9210";
                reg = <0x68>;
 
                regulator-min-microvolt = <1000000>;
index f00d048aa583591c45aca5a7e683002c5bbc4721..c08d172bbab44df7052ca985161aab0d0b8dba41 100644 (file)
@@ -839,6 +839,16 @@ config SENSORS_MCP3021
          This driver can also be built as a module.  If so, the module
          will be called mcp3021.
 
+config SENSORS_MENF21BMC_HWMON
+       tristate "MEN 14F021P00 BMC Hardware Monitoring"
+       depends on MFD_MENF21BMC
+       help
+         Say Y here to include support for the MEN 14F021P00 BMC
+         hardware monitoring.
+
+         This driver can also be built as a module. If so the module
+         will be called menf21bmc_hwmon.
+
 config SENSORS_ADCXX
        tristate "National Semiconductor ADCxxxSxxx"
        depends on SPI_MASTER
index be28152c9848806391f58abecce93914f7edf384..c90a7611efaabc26c35c8b66cc90fbe50b4e9c96 100644 (file)
@@ -115,6 +115,7 @@ obj-$(CONFIG_SENSORS_MAX6650)       += max6650.o
 obj-$(CONFIG_SENSORS_MAX6697)  += max6697.o
 obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o
 obj-$(CONFIG_SENSORS_MCP3021)  += mcp3021.o
+obj-$(CONFIG_SENSORS_MENF21BMC_HWMON) += menf21bmc_hwmon.o
 obj-$(CONFIG_SENSORS_NCT6683)  += nct6683.o
 obj-$(CONFIG_SENSORS_NCT6775)  += nct6775.o
 obj-$(CONFIG_SENSORS_NTC_THERMISTOR)   += ntc_thermistor.o
diff --git a/drivers/hwmon/menf21bmc_hwmon.c b/drivers/hwmon/menf21bmc_hwmon.c
new file mode 100644 (file)
index 0000000..c92229d
--- /dev/null
@@ -0,0 +1,230 @@
+/*
+ *  MEN 14F021P00 Board Management Controller (BMC) hwmon driver.
+ *
+ *  This is the core hwmon driver of the MEN 14F021P00 BMC.
+ *  The BMC monitors the board voltages which can be access with this
+ *  driver through sysfs.
+ *
+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
+ *
+ *  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 <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/jiffies.h>
+#include <linux/slab.h>
+#include <linux/i2c.h>
+
+#define DRV_NAME  "menf21bmc_hwmon"
+
+#define BMC_VOLT_COUNT 5
+#define MENF21BMC_V33  0
+#define MENF21BMC_V5   1
+#define MENF21BMC_V12  2
+#define MENF21BMC_V5_SB        3
+#define MENF21BMC_VBAT 4
+
+#define IDX_TO_VOLT_MIN_CMD(idx) (0x40 + idx)
+#define IDX_TO_VOLT_MAX_CMD(idx) (0x50 + idx)
+#define IDX_TO_VOLT_INP_CMD(idx) (0x60 + idx)
+
+struct menf21bmc_hwmon {
+       bool valid;
+       struct i2c_client *i2c_client;
+       unsigned long last_update;
+       int in_val[BMC_VOLT_COUNT];
+       int in_min[BMC_VOLT_COUNT];
+       int in_max[BMC_VOLT_COUNT];
+};
+
+static const char *const input_names[] = {
+       [MENF21BMC_V33]         = "MON_3_3V",
+       [MENF21BMC_V5]          = "MON_5V",
+       [MENF21BMC_V12]         = "MON_12V",
+       [MENF21BMC_V5_SB]       = "5V_STANDBY",
+       [MENF21BMC_VBAT]        = "VBAT"
+};
+
+static struct menf21bmc_hwmon *menf21bmc_hwmon_update(struct device *dev)
+{
+       int i;
+       int val;
+       struct menf21bmc_hwmon *drv_data = dev_get_drvdata(dev);
+       struct menf21bmc_hwmon *data_ret = drv_data;
+
+       if (time_after(jiffies, drv_data->last_update + HZ)
+           || !drv_data->valid) {
+               for (i = 0; i < BMC_VOLT_COUNT; i++) {
+                       val = i2c_smbus_read_word_data(drv_data->i2c_client,
+                                                      IDX_TO_VOLT_INP_CMD(i));
+                       if (val < 0) {
+                               data_ret = ERR_PTR(val);
+                               goto abort;
+                       }
+                       drv_data->in_val[i] = val;
+               }
+               drv_data->last_update = jiffies;
+               drv_data->valid = true;
+       }
+abort:
+       return data_ret;
+}
+
+static int menf21bmc_hwmon_get_volt_limits(struct menf21bmc_hwmon *drv_data)
+{
+       int i, val;
+
+       for (i = 0; i < BMC_VOLT_COUNT; i++) {
+               val = i2c_smbus_read_word_data(drv_data->i2c_client,
+                                              IDX_TO_VOLT_MIN_CMD(i));
+               if (val < 0)
+                       return val;
+
+               drv_data->in_min[i] = val;
+
+               val = i2c_smbus_read_word_data(drv_data->i2c_client,
+                                              IDX_TO_VOLT_MAX_CMD(i));
+               if (val < 0)
+                       return val;
+
+               drv_data->in_max[i] = val;
+       }
+       return 0;
+}
+
+static ssize_t
+show_label(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+
+       return sprintf(buf, "%s\n", input_names[attr->index]);
+}
+
+static ssize_t
+show_in(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
+
+       if (IS_ERR(drv_data))
+               return PTR_ERR(drv_data);
+
+       return sprintf(buf, "%d\n", drv_data->in_val[attr->index]);
+}
+
+static ssize_t
+show_min(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct menf21bmc_hwmon *drv_data = dev_get_drvdata(dev);
+
+       return sprintf(buf, "%d\n", drv_data->in_min[attr->index]);
+}
+
+static ssize_t
+show_max(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct menf21bmc_hwmon *drv_data = dev_get_drvdata(dev);
+
+       return sprintf(buf, "%d\n", drv_data->in_max[attr->index]);
+}
+
+#define create_voltage_sysfs(idx)                      \
+static SENSOR_DEVICE_ATTR(in##idx##_input, S_IRUGO,    \
+                       show_in, NULL, idx);            \
+static SENSOR_DEVICE_ATTR(in##idx##_min, S_IRUGO,      \
+                       show_min, NULL, idx);           \
+static SENSOR_DEVICE_ATTR(in##idx##_max, S_IRUGO,      \
+                       show_max, NULL, idx);           \
+static SENSOR_DEVICE_ATTR(in##idx##_label, S_IRUGO,    \
+                       show_label, NULL, idx);
+
+create_voltage_sysfs(0);
+create_voltage_sysfs(1);
+create_voltage_sysfs(2);
+create_voltage_sysfs(3);
+create_voltage_sysfs(4);
+
+static struct attribute *menf21bmc_hwmon_attrs[] = {
+       &sensor_dev_attr_in0_input.dev_attr.attr,
+       &sensor_dev_attr_in0_min.dev_attr.attr,
+       &sensor_dev_attr_in0_max.dev_attr.attr,
+       &sensor_dev_attr_in0_label.dev_attr.attr,
+
+       &sensor_dev_attr_in1_input.dev_attr.attr,
+       &sensor_dev_attr_in1_min.dev_attr.attr,
+       &sensor_dev_attr_in1_max.dev_attr.attr,
+       &sensor_dev_attr_in1_label.dev_attr.attr,
+
+       &sensor_dev_attr_in2_input.dev_attr.attr,
+       &sensor_dev_attr_in2_min.dev_attr.attr,
+       &sensor_dev_attr_in2_max.dev_attr.attr,
+       &sensor_dev_attr_in2_label.dev_attr.attr,
+
+       &sensor_dev_attr_in3_input.dev_attr.attr,
+       &sensor_dev_attr_in3_min.dev_attr.attr,
+       &sensor_dev_attr_in3_max.dev_attr.attr,
+       &sensor_dev_attr_in3_label.dev_attr.attr,
+
+       &sensor_dev_attr_in4_input.dev_attr.attr,
+       &sensor_dev_attr_in4_min.dev_attr.attr,
+       &sensor_dev_attr_in4_max.dev_attr.attr,
+       &sensor_dev_attr_in4_label.dev_attr.attr,
+       NULL
+};
+
+ATTRIBUTE_GROUPS(menf21bmc_hwmon);
+
+static int menf21bmc_hwmon_probe(struct platform_device *pdev)
+{
+       int ret;
+       struct menf21bmc_hwmon *drv_data;
+       struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent);
+       struct device *hwmon_dev;
+
+       drv_data = devm_kzalloc(&pdev->dev, sizeof(struct menf21bmc_hwmon),
+                               GFP_KERNEL);
+       if (!drv_data)
+               return -ENOMEM;
+
+       drv_data->i2c_client = i2c_client;
+
+       ret = menf21bmc_hwmon_get_volt_limits(drv_data);
+       if (ret) {
+               dev_err(&pdev->dev, "failed to read sensor limits");
+               return ret;
+       }
+
+       hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev,
+                                                  "menf21bmc", drv_data,
+                                                  menf21bmc_hwmon_groups);
+       if (IS_ERR(hwmon_dev))
+               return PTR_ERR(hwmon_dev);
+
+       dev_info(&pdev->dev, "MEN 14F021P00 BMC hwmon device enabled");
+
+       return 0;
+}
+
+static struct platform_driver menf21bmc_hwmon = {
+       .probe          = menf21bmc_hwmon_probe,
+       .driver         = {
+               .name           = DRV_NAME,
+               .owner          = THIS_MODULE,
+       },
+};
+
+module_platform_driver(menf21bmc_hwmon);
+
+MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
+MODULE_DESCRIPTION("MEN 14F021P00 BMC hwmon");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:menf21bmc_hwmon");
index 8c96e2ddf43bf035ce59d4453b2aac38e151cb7f..eadd56c91551aed0e86c1e660a6227dbf786757c 100644 (file)
@@ -468,6 +468,15 @@ config LEDS_OT200
          This option enables support for the LEDs on the Bachmann OT200.
          Say Y to enable LEDs on the Bachmann OT200.
 
+config LEDS_MENF21BMC
+       tristate "LED support for the MEN 14F021P00 BMC"
+       depends on LEDS_CLASS && MFD_MENF21BMC
+       help
+         Say Y here to include support for the MEN 14F021P00 BMC LEDs.
+
+         This driver can also be built as a module. If so the module
+         will be called leds-menf21bmc.
+
 comment "LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)"
 
 config LEDS_BLINKM
index d8cc5f2777de94e880da92d6fdde7894cf8877c8..9a72fddc1d78ff1cfc54e0cdcba226f18a862b24 100644 (file)
@@ -54,6 +54,7 @@ obj-$(CONFIG_LEDS_MAX8997)            += leds-max8997.o
 obj-$(CONFIG_LEDS_LM355x)              += leds-lm355x.o
 obj-$(CONFIG_LEDS_BLINKM)              += leds-blinkm.o
 obj-$(CONFIG_LEDS_VERSATILE)           += leds-versatile.o
+obj-$(CONFIG_LEDS_MENF21BMC)           += leds-menf21bmc.o
 
 # LED SPI Drivers
 obj-$(CONFIG_LEDS_DAC124S085)          += leds-dac124s085.o
diff --git a/drivers/leds/leds-menf21bmc.c b/drivers/leds/leds-menf21bmc.c
new file mode 100644 (file)
index 0000000..89dd577
--- /dev/null
@@ -0,0 +1,131 @@
+/*
+ *  MEN 14F021P00 Board Management Controller (BMC) LEDs Driver.
+ *
+ *  This is the core LED driver of the MEN 14F021P00 BMC.
+ *  There are four LEDs available which can be switched on and off.
+ *  STATUS LED, HOT SWAP LED, USER LED 1, USER LED 2
+ *
+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
+ *
+ *  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 <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/leds.h>
+#include <linux/i2c.h>
+
+#define BMC_CMD_LED_GET_SET    0xA0
+#define BMC_BIT_LED_STATUS     BIT(0)
+#define BMC_BIT_LED_HOTSWAP    BIT(1)
+#define BMC_BIT_LED_USER1      BIT(2)
+#define BMC_BIT_LED_USER2      BIT(3)
+
+struct menf21bmc_led {
+       struct led_classdev cdev;
+       u8 led_bit;
+       const char *name;
+       struct i2c_client *i2c_client;
+};
+
+static struct menf21bmc_led leds[] = {
+       {
+               .name = "menf21bmc:led_status",
+               .led_bit = BMC_BIT_LED_STATUS,
+       },
+       {
+               .name = "menf21bmc:led_hotswap",
+               .led_bit = BMC_BIT_LED_HOTSWAP,
+       },
+       {
+               .name = "menf21bmc:led_user1",
+               .led_bit = BMC_BIT_LED_USER1,
+       },
+       {
+               .name = "menf21bmc:led_user2",
+               .led_bit = BMC_BIT_LED_USER2,
+       }
+};
+
+static DEFINE_MUTEX(led_lock);
+
+static void
+menf21bmc_led_set(struct led_classdev *led_cdev, enum led_brightness value)
+{
+       int led_val;
+       struct menf21bmc_led *led = container_of(led_cdev,
+                                       struct menf21bmc_led, cdev);
+
+       mutex_lock(&led_lock);
+       led_val = i2c_smbus_read_byte_data(led->i2c_client,
+                                          BMC_CMD_LED_GET_SET);
+       if (led_val < 0)
+               goto err_out;
+
+       if (value == LED_OFF)
+               led_val &= ~led->led_bit;
+       else
+               led_val |= led->led_bit;
+
+       i2c_smbus_write_byte_data(led->i2c_client,
+                                 BMC_CMD_LED_GET_SET, led_val);
+err_out:
+       mutex_unlock(&led_lock);
+}
+
+static int menf21bmc_led_probe(struct platform_device *pdev)
+{
+       int i;
+       int ret;
+       struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent);
+
+       for (i = 0; i < ARRAY_SIZE(leds); i++) {
+               leds[i].cdev.name = leds[i].name;
+               leds[i].cdev.brightness_set = menf21bmc_led_set;
+               leds[i].i2c_client = i2c_client;
+               ret = led_classdev_register(&pdev->dev, &leds[i].cdev);
+               if (ret < 0)
+                       goto err_free_leds;
+       }
+       dev_info(&pdev->dev, "MEN 140F21P00 BMC LED device enabled\n");
+
+       return 0;
+
+err_free_leds:
+       dev_err(&pdev->dev, "failed to register LED device\n");
+
+       for (i = i - 1; i >= 0; i--)
+               led_classdev_unregister(&leds[i].cdev);
+
+       return ret;
+}
+
+static int menf21bmc_led_remove(struct platform_device *pdev)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(leds); i++)
+               led_classdev_unregister(&leds[i].cdev);
+
+       return 0;
+}
+
+static struct platform_driver menf21bmc_led = {
+       .probe          = menf21bmc_led_probe,
+       .remove         = menf21bmc_led_remove,
+       .driver         = {
+               .name           = "menf21bmc_led",
+               .owner          = THIS_MODULE,
+       },
+};
+
+module_platform_driver(menf21bmc_led);
+
+MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
+MODULE_DESCRIPTION("MEN 14F021P00 BMC led driver");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:menf21bmc_led");
index de5abf244746ac7dc32e99d02b61d131e4877a77..cf66ef1ffaf32d59b60ed2ff30873988ec2bd3e4 100644 (file)
@@ -454,6 +454,21 @@ config MFD_MAX8998
          additional drivers must be enabled in order to use the functionality
          of the device.
 
+config MFD_MENF21BMC
+       tristate "MEN 14F021P00 Board Management Controller Support"
+       depends on I2C
+       select MFD_CORE
+       help
+         Say yes here to add support for the MEN 14F021P00 BMC
+         which is a Board Management Controller connected to the I2C bus.
+         The device supports multiple sub-devices like LED, HWMON and WDT.
+         This driver provides common support for accessing the devices;
+         additional drivers must be enabled in order to use the
+         functionality of the BMC device.
+
+         This driver can also be built as a module. If so the module
+         will be called menf21bmc.
+
 config EZX_PCAP
        bool "Motorola EZXPCAP Support"
        depends on SPI_MASTER
index f00148782d9b3c234609ad10827430ec84c2a56b..d58068aa8aa9492fbbdd432123e4b5749d819bbf 100644 (file)
@@ -169,6 +169,7 @@ obj-$(CONFIG_MFD_AS3711)    += as3711.o
 obj-$(CONFIG_MFD_AS3722)       += as3722.o
 obj-$(CONFIG_MFD_STW481X)      += stw481x.o
 obj-$(CONFIG_MFD_IPAQ_MICRO)   += ipaq-micro.o
+obj-$(CONFIG_MFD_MENF21BMC)    += menf21bmc.o
 
 intel-soc-pmic-objs            := intel_soc_pmic_core.o intel_soc_pmic_crc.o
 obj-$(CONFIG_INTEL_SOC_PMIC)   += intel-soc-pmic.o
index caf8dcffd0ad403d6b239f9f0c3442ac1651aa2c..b4d920c1ead1f2d92ce52433bc9c3a17b73fca7d 100644 (file)
@@ -296,73 +296,73 @@ static struct resource da9055_ld05_6_resource = {
 
 static const struct mfd_cell da9055_devs[] = {
        {
-               .of_compatible = "dialog,da9055-gpio",
+               .of_compatible = "dlg,da9055-gpio",
                .name = "da9055-gpio",
        },
        {
-               .of_compatible = "dialog,da9055-regulator",
+               .of_compatible = "dlg,da9055-regulator",
                .name = "da9055-regulator",
                .id = 1,
        },
        {
-               .of_compatible = "dialog,da9055-regulator",
+               .of_compatible = "dlg,da9055-regulator",
                .name = "da9055-regulator",
                .id = 2,
        },
        {
-               .of_compatible = "dialog,da9055-regulator",
+               .of_compatible = "dlg,da9055-regulator",
                .name = "da9055-regulator",
                .id = 3,
        },
        {
-               .of_compatible = "dialog,da9055-regulator",
+               .of_compatible = "dlg,da9055-regulator",
                .name = "da9055-regulator",
                .id = 4,
        },
        {
-               .of_compatible = "dialog,da9055-regulator",
+               .of_compatible = "dlg,da9055-regulator",
                .name = "da9055-regulator",
                .id = 5,
        },
        {
-               .of_compatible = "dialog,da9055-regulator",
+               .of_compatible = "dlg,da9055-regulator",
                .name = "da9055-regulator",
                .id = 6,
        },
        {
-               .of_compatible = "dialog,da9055-regulator",
+               .of_compatible = "dlg,da9055-regulator",
                .name = "da9055-regulator",
                .id = 7,
                .resources = &da9055_ld05_6_resource,
                .num_resources = 1,
        },
        {
-               .of_compatible = "dialog,da9055-regulator",
+               .of_compatible = "dlg,da9055-regulator",
                .name = "da9055-regulator",
                .resources = &da9055_ld05_6_resource,
                .num_resources = 1,
                .id = 8,
        },
        {
-               .of_compatible = "dialog,da9055-onkey",
+               .of_compatible = "dlg,da9055-onkey",
                .name = "da9055-onkey",
                .resources = &da9055_onkey_resource,
                .num_resources = 1,
        },
        {
-               .of_compatible = "dialog,da9055-rtc",
+               .of_compatible = "dlg,da9055-rtc",
                .name = "da9055-rtc",
                .resources = da9055_rtc_resource,
                .num_resources = ARRAY_SIZE(da9055_rtc_resource),
        },
        {
-               .of_compatible = "dialog,da9055-hwmon",
+               .of_compatible = "dlg,da9055-hwmon",
                .name = "da9055-hwmon",
                .resources = &da9055_hwmon_resource,
                .num_resources = 1,
        },
        {
-               .of_compatible = "dialog,da9055-watchdog",
+               .of_compatible = "dlg,da9055-watchdog",
                .name = "da9055-watchdog",
        },
 };
diff --git a/drivers/mfd/menf21bmc.c b/drivers/mfd/menf21bmc.c
new file mode 100644 (file)
index 0000000..1c27434
--- /dev/null
@@ -0,0 +1,132 @@
+/*
+ *  MEN 14F021P00 Board Management Controller (BMC) MFD Core Driver.
+ *
+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
+ *
+ *  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 <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/i2c.h>
+#include <linux/mfd/core.h>
+
+#define BMC_CMD_WDT_EXIT_PROD  0x18
+#define BMC_CMD_WDT_PROD_STAT  0x19
+#define BMC_CMD_REV_MAJOR      0x80
+#define BMC_CMD_REV_MINOR      0x81
+#define BMC_CMD_REV_MAIN       0x82
+
+static struct mfd_cell menf21bmc_cell[] = {
+       { .name = "menf21bmc_wdt", },
+       { .name = "menf21bmc_led", },
+       { .name = "menf21bmc_hwmon", }
+};
+
+static int menf21bmc_wdt_exit_prod_mode(struct i2c_client *client)
+{
+       int val, ret;
+
+       val = i2c_smbus_read_byte_data(client, BMC_CMD_WDT_PROD_STAT);
+       if (val < 0)
+               return val;
+
+       /*
+        * Production mode should be not active after delivery of the Board.
+        * To be sure we check it, inform the user and exit the mode
+        * if active.
+        */
+       if (val == 0x00) {
+               dev_info(&client->dev,
+                       "BMC in production mode. Exit production mode\n");
+
+               ret = i2c_smbus_write_byte(client, BMC_CMD_WDT_EXIT_PROD);
+               if (ret < 0)
+                       return ret;
+       }
+
+       return 0;
+}
+
+static int
+menf21bmc_probe(struct i2c_client *client, const struct i2c_device_id *ids)
+{
+       int rev_major, rev_minor, rev_main;
+       int ret;
+
+       ret = i2c_check_functionality(client->adapter,
+                                     I2C_FUNC_SMBUS_BYTE_DATA |
+                                     I2C_FUNC_SMBUS_WORD_DATA |
+                                     I2C_FUNC_SMBUS_BYTE);
+       if (!ret)
+               return -ENODEV;
+
+       rev_major = i2c_smbus_read_word_data(client, BMC_CMD_REV_MAJOR);
+       if (rev_major < 0) {
+               dev_err(&client->dev, "failed to get BMC major revision\n");
+               return rev_major;
+       }
+
+       rev_minor = i2c_smbus_read_word_data(client, BMC_CMD_REV_MINOR);
+       if (rev_minor < 0) {
+               dev_err(&client->dev, "failed to get BMC minor revision\n");
+               return rev_minor;
+       }
+
+       rev_main = i2c_smbus_read_word_data(client, BMC_CMD_REV_MAIN);
+       if (rev_main < 0) {
+               dev_err(&client->dev, "failed to get BMC main revision\n");
+               return rev_main;
+       }
+
+       dev_info(&client->dev, "FW Revision: %02d.%02d.%02d\n",
+                rev_major, rev_minor, rev_main);
+
+       /*
+        * We have to exit the Production Mode of the BMC to activate the
+        * Watchdog functionality and the BIOS life sign monitoring.
+        */
+       ret = menf21bmc_wdt_exit_prod_mode(client);
+       if (ret < 0) {
+               dev_err(&client->dev, "failed to leave production mode\n");
+               return ret;
+       }
+
+       ret = mfd_add_devices(&client->dev, 0, menf21bmc_cell,
+                             ARRAY_SIZE(menf21bmc_cell), NULL, 0, NULL);
+       if (ret < 0) {
+               dev_err(&client->dev, "failed to add BMC sub-devices\n");
+               return ret;
+       }
+
+       return 0;
+}
+
+static int menf21bmc_remove(struct i2c_client *client)
+{
+       mfd_remove_devices(&client->dev);
+       return 0;
+}
+
+static const struct i2c_device_id menf21bmc_id_table[] = {
+       { "menf21bmc" },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, menf21bmc_id_table);
+
+static struct i2c_driver menf21bmc_driver = {
+       .driver.name    = "menf21bmc",
+       .id_table       = menf21bmc_id_table,
+       .probe          = menf21bmc_probe,
+       .remove         = menf21bmc_remove,
+};
+
+module_i2c_driver(menf21bmc_driver);
+
+MODULE_DESCRIPTION("MEN 14F021P00 BMC mfd core driver");
+MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
+MODULE_LICENSE("GPL v2");
index f57312fced80f0e60a75019db688a25b659a9886..a50828e34e3b8d692db94530767a982a222fe404 100644 (file)
@@ -95,6 +95,16 @@ config GPIO_WATCHDOG
          If you say yes here you get support for watchdog device
          controlled through GPIO-line.
 
+config MENF21BMC_WATCHDOG
+       tristate "MEN 14F021P00 BMC Watchdog"
+       depends on MFD_MENF21BMC
+       select WATCHDOG_CORE
+       help
+         Say Y here to include support for the MEN 14F021P00 BMC Watchdog.
+
+         This driver can also be built as a module. If so the module
+         will be called menf21bmc_wdt.
+
 config WM831X_WATCHDOG
        tristate "WM831x watchdog"
        depends on MFD_WM831X
index 468c3204c3b190b7be20616d02d25ba947408581..de1701470c14fd12f2bfcc08b74fd56cedbe3a6a 100644 (file)
@@ -178,3 +178,4 @@ obj-$(CONFIG_WM831X_WATCHDOG) += wm831x_wdt.o
 obj-$(CONFIG_WM8350_WATCHDOG) += wm8350_wdt.o
 obj-$(CONFIG_MAX63XX_WATCHDOG) += max63xx_wdt.o
 obj-$(CONFIG_SOFT_WATCHDOG) += softdog.o
+obj-$(CONFIG_MENF21BMC_WATCHDOG) += menf21bmc_wdt.o
diff --git a/drivers/watchdog/menf21bmc_wdt.c b/drivers/watchdog/menf21bmc_wdt.c
new file mode 100644 (file)
index 0000000..2042874
--- /dev/null
@@ -0,0 +1,203 @@
+/*
+ *  MEN 14F021P00 Board Management Controller (BMC) Watchdog Driver.
+ *
+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
+ *
+ *  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 <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/watchdog.h>
+#include <linux/platform_device.h>
+#include <linux/i2c.h>
+
+#define DEVNAME "menf21bmc_wdt"
+
+#define BMC_CMD_WD_ON          0x11
+#define BMC_CMD_WD_OFF         0x12
+#define BMC_CMD_WD_TRIG                0x13
+#define BMC_CMD_WD_TIME                0x14
+#define BMC_CMD_WD_STATE       0x17
+#define BMC_WD_OFF_VAL         0x69
+#define BMC_CMD_RST_RSN                0x92
+
+#define BMC_WD_TIMEOUT_MIN     1       /* in sec */
+#define BMC_WD_TIMEOUT_MAX     6553    /* in sec */
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, bool, 0);
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
+                               __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+
+struct menf21bmc_wdt {
+       struct watchdog_device wdt;
+       struct i2c_client *i2c_client;
+};
+
+static int menf21bmc_wdt_set_bootstatus(struct menf21bmc_wdt *data)
+{
+       int rst_rsn;
+
+       rst_rsn = i2c_smbus_read_byte_data(data->i2c_client, BMC_CMD_RST_RSN);
+       if (rst_rsn < 0)
+               return rst_rsn;
+
+       if (rst_rsn == 0x02)
+               data->wdt.bootstatus |= WDIOF_CARDRESET;
+       else if (rst_rsn == 0x05)
+               data->wdt.bootstatus |= WDIOF_EXTERN1;
+       else if (rst_rsn == 0x06)
+               data->wdt.bootstatus |= WDIOF_EXTERN2;
+       else if (rst_rsn == 0x0A)
+               data->wdt.bootstatus |= WDIOF_POWERUNDER;
+
+       return 0;
+}
+
+static int menf21bmc_wdt_start(struct watchdog_device *wdt)
+{
+       struct menf21bmc_wdt *drv_data = watchdog_get_drvdata(wdt);
+
+       return i2c_smbus_write_byte(drv_data->i2c_client, BMC_CMD_WD_ON);
+}
+
+static int menf21bmc_wdt_stop(struct watchdog_device *wdt)
+{
+       struct menf21bmc_wdt *drv_data = watchdog_get_drvdata(wdt);
+
+       return i2c_smbus_write_byte_data(drv_data->i2c_client,
+                                        BMC_CMD_WD_OFF, BMC_WD_OFF_VAL);
+}
+
+static int
+menf21bmc_wdt_settimeout(struct watchdog_device *wdt, unsigned int timeout)
+{
+       int ret;
+       struct menf21bmc_wdt *drv_data = watchdog_get_drvdata(wdt);
+
+       /*
+        *  BMC Watchdog does have a resolution of 100ms.
+        *  Watchdog API defines the timeout in seconds, so we have to
+        *  multiply the value.
+        */
+       ret = i2c_smbus_write_word_data(drv_data->i2c_client,
+                                       BMC_CMD_WD_TIME, timeout * 10);
+       if (ret < 0)
+               return ret;
+
+       wdt->timeout = timeout;
+
+       return 0;
+}
+
+static int menf21bmc_wdt_ping(struct watchdog_device *wdt)
+{
+       struct menf21bmc_wdt *drv_data = watchdog_get_drvdata(wdt);
+
+       return i2c_smbus_write_byte(drv_data->i2c_client, BMC_CMD_WD_TRIG);
+}
+
+static const struct watchdog_info menf21bmc_wdt_info = {
+       .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
+       .identity = DEVNAME,
+};
+
+static const struct watchdog_ops menf21bmc_wdt_ops = {
+       .owner          = THIS_MODULE,
+       .start          = menf21bmc_wdt_start,
+       .stop           = menf21bmc_wdt_stop,
+       .ping           = menf21bmc_wdt_ping,
+       .set_timeout    = menf21bmc_wdt_settimeout,
+};
+
+static int menf21bmc_wdt_probe(struct platform_device *pdev)
+{
+       int ret, bmc_timeout;
+       struct menf21bmc_wdt *drv_data;
+       struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent);
+
+       drv_data = devm_kzalloc(&pdev->dev,
+                               sizeof(struct menf21bmc_wdt), GFP_KERNEL);
+       if (!drv_data)
+               return -ENOMEM;
+
+       drv_data->wdt.ops = &menf21bmc_wdt_ops;
+       drv_data->wdt.info = &menf21bmc_wdt_info;
+       drv_data->wdt.min_timeout = BMC_WD_TIMEOUT_MIN;
+       drv_data->wdt.max_timeout = BMC_WD_TIMEOUT_MAX;
+       drv_data->i2c_client = i2c_client;
+
+       /*
+        * Get the current wdt timeout value from the BMC because
+        * the BMC will save the value set before if the system restarts.
+        */
+       bmc_timeout = i2c_smbus_read_word_data(drv_data->i2c_client,
+                                              BMC_CMD_WD_TIME);
+       if (bmc_timeout < 0) {
+               dev_err(&pdev->dev, "failed to get current WDT timeout\n");
+               return bmc_timeout;
+       }
+
+       watchdog_init_timeout(&drv_data->wdt, bmc_timeout / 10, &pdev->dev);
+       watchdog_set_nowayout(&drv_data->wdt, nowayout);
+       watchdog_set_drvdata(&drv_data->wdt, drv_data);
+       platform_set_drvdata(pdev, drv_data);
+
+       ret = menf21bmc_wdt_set_bootstatus(drv_data);
+       if (ret < 0) {
+               dev_err(&pdev->dev, "failed to set Watchdog bootstatus\n");
+               return ret;
+       }
+
+       ret = watchdog_register_device(&drv_data->wdt);
+       if (ret) {
+               dev_err(&pdev->dev, "failed to register Watchdog device\n");
+               return ret;
+       }
+
+       dev_info(&pdev->dev, "MEN 14F021P00 BMC Watchdog device enabled\n");
+
+       return 0;
+}
+
+static int menf21bmc_wdt_remove(struct platform_device *pdev)
+{
+       struct menf21bmc_wdt *drv_data = platform_get_drvdata(pdev);
+
+       dev_warn(&pdev->dev,
+                "Unregister MEN 14F021P00 BMC Watchdog device, board may reset\n");
+
+       watchdog_unregister_device(&drv_data->wdt);
+
+       return 0;
+}
+
+static void menf21bmc_wdt_shutdown(struct platform_device *pdev)
+{
+       struct menf21bmc_wdt *drv_data = platform_get_drvdata(pdev);
+
+       i2c_smbus_write_word_data(drv_data->i2c_client,
+                                 BMC_CMD_WD_OFF, BMC_WD_OFF_VAL);
+}
+
+static struct  platform_driver menf21bmc_wdt = {
+       .driver         = {
+               .owner = THIS_MODULE,
+               .name   = DEVNAME,
+       },
+       .probe          = menf21bmc_wdt_probe,
+       .remove         = menf21bmc_wdt_remove,
+       .shutdown       = menf21bmc_wdt_shutdown,
+};
+
+module_platform_driver(menf21bmc_wdt);
+
+MODULE_DESCRIPTION("MEN 14F021P00 BMC Watchdog driver");
+MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:menf21bmc_wdt");