[PATCH v2 6/9] mfd: add TI LMU hardware fault monitoring driver

2015-11-25 Thread Milo Kim
LM3633 and LM3697 are TI LMU MFD device.
Those devices have hardware monitoring feature which detects open or
short circuit case.

Debugfs
---
  Two files are created.
open_fault:  check light output channel is open or not.
short_fault: check light output channel is shorted or not.

  The driver checks the status of backlight output channels.
  LM3633 and LM3697 have same sequence to check channels, so common
  functions are used.
  ABI/testing document is also included.

Operations
--
  Two devices have common control flow but register addresses are different.
  The structure, 'ti_lmu_reg' is used for register configuration.

Event notifier
--
  After fault monitoring is done, LMU device is reset. So backlight and
  LED device should be reinitialized. It notifies an event as soon as
  the monitoring is done. Then, LM3633 and LM3697 backlight and LED drivers
  handle this event.

Cc: Lee Jones  
Cc: Jacek Anaszewski 
Cc: Mark Brown 
Cc: Rob Herring 
Cc: devicet...@vger.kernel.org
Cc: linux-l...@vger.kernel.org 
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Milo Kim 
---
 .../ABI/testing/debugfs-ti-lmu-fault-monitor   |  32 ++
 drivers/mfd/Kconfig|  10 +
 drivers/mfd/Makefile   |   1 +
 drivers/mfd/ti-lmu-fault-monitor.c | 405 +
 4 files changed, 448 insertions(+)
 create mode 100644 Documentation/ABI/testing/debugfs-ti-lmu-fault-monitor
 create mode 100644 drivers/mfd/ti-lmu-fault-monitor.c

diff --git a/Documentation/ABI/testing/debugfs-ti-lmu-fault-monitor 
b/Documentation/ABI/testing/debugfs-ti-lmu-fault-monitor
new file mode 100644
index 000..7e39e4a
--- /dev/null
+++ b/Documentation/ABI/testing/debugfs-ti-lmu-fault-monitor
@@ -0,0 +1,32 @@
+TI LMU (Lighting Management Unit) Fault Monitoring via the debugfs
+
+LM3633 and LM3697 support hardware fault monitoring which detects
+open or short circuit case.
+
+What:  /sys/kernel/debug/ti-lmu-fault-monitor/open_fault
+Date:  Dec 2015
+KernelVersion: 4.5
+Contact:   Milo Kim 
+Description:   read only
+Check whether light channel works or open circuit is detected.
+
+   Example:
+   cat /sys/kernel/debug/ti-lmu-fault-monitor/open_fault
+
+   Channel 0 works
+   Channel 1 works
+   Channel 2 is open
+
+What:  /sys/kernel/debug/ti-lmu-fault-monitor/short_fault
+Date:  Dec 2015
+KernelVersion: 4.5
+Contact:   Milo Kim 
+Description:   read only
+Check whether light channel works or short circuit is detected.
+
+   Example:
+   cat /sys/kernel/debug/ti-lmu-fault-monitor/short_fault
+
+   Channel 0 is shorted
+   Channel 1 works
+   Channel 2 works
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index a6aab27..e08acba 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1061,6 +1061,16 @@ config MFD_TI_LMU
  It consists of backlight, LED and regulator driver.
  It provides consistent device controls for lighting functions.
 
+config MFD_TI_LMU_FAULT_MONITOR
+   tristate "TI LMU Hardware Fault Monitoring Driver"
+   depends on MFD_TI_LMU && DEBUG_FS
+   help
+ Say Y here to include support for open and short circuit fault
+ detection of TI LMU devices.
+
+ This driver can also be built as a module. If so the module
+ will be called ti-lmu-fault-monitor.
+
 config MFD_OMAP_USB_HOST
bool "TI OMAP USBHS core and TLL driver"
depends on USB_EHCI_HCD_OMAP || USB_OHCI_HCD_OMAP3
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 10e4bc2..5ddb4e6 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -112,6 +112,7 @@ obj-$(CONFIG_MFD_LP3943)+= lp3943.o
 obj-$(CONFIG_MFD_LP8788)   += lp8788.o lp8788-irq.o
 
 obj-$(CONFIG_MFD_TI_LMU)   += ti-lmu.o
+obj-$(CONFIG_MFD_TI_LMU_FAULT_MONITOR) += ti-lmu-fault-monitor.o
 
 da9055-objs:= da9055-core.o da9055-i2c.o
 obj-$(CONFIG_MFD_DA9055)   += da9055.o
diff --git a/drivers/mfd/ti-lmu-fault-monitor.c 
b/drivers/mfd/ti-lmu-fault-monitor.c
new file mode 100644
index 000..ba65c93
--- /dev/null
+++ b/drivers/mfd/ti-lmu-fault-monitor.c
@@ -0,0 +1,405 @@
+/*
+ * TI LMU (Lighting Management Unit) Hardware Fault Monitoring Driver
+ *
+ * Copyright 2015 Texas Instruments
+ *
+ * Author: Milo Kim 
+ *
+ * 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 
+#include 
+#include 
+
+#define LMU_ENABLE_OPEN_MONITORING BIT(0)
+#define LMU_ENABLE_SHORT_MONITORINGBIT(1)
+#define LMU_DEFAULT_BANK  

[PATCH v2 6/9] mfd: add TI LMU hardware fault monitoring driver

2015-11-25 Thread Milo Kim
LM3633 and LM3697 are TI LMU MFD device.
Those devices have hardware monitoring feature which detects open or
short circuit case.

Debugfs
---
  Two files are created.
open_fault:  check light output channel is open or not.
short_fault: check light output channel is shorted or not.

  The driver checks the status of backlight output channels.
  LM3633 and LM3697 have same sequence to check channels, so common
  functions are used.
  ABI/testing document is also included.

Operations
--
  Two devices have common control flow but register addresses are different.
  The structure, 'ti_lmu_reg' is used for register configuration.

Event notifier
--
  After fault monitoring is done, LMU device is reset. So backlight and
  LED device should be reinitialized. It notifies an event as soon as
  the monitoring is done. Then, LM3633 and LM3697 backlight and LED drivers
  handle this event.

Cc: Lee Jones  
Cc: Jacek Anaszewski 
Cc: Mark Brown 
Cc: Rob Herring 
Cc: devicet...@vger.kernel.org
Cc: linux-l...@vger.kernel.org 
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Milo Kim 
---
 .../ABI/testing/debugfs-ti-lmu-fault-monitor   |  32 ++
 drivers/mfd/Kconfig|  10 +
 drivers/mfd/Makefile   |   1 +
 drivers/mfd/ti-lmu-fault-monitor.c | 405 +
 4 files changed, 448 insertions(+)
 create mode 100644 Documentation/ABI/testing/debugfs-ti-lmu-fault-monitor
 create mode 100644 drivers/mfd/ti-lmu-fault-monitor.c

diff --git a/Documentation/ABI/testing/debugfs-ti-lmu-fault-monitor 
b/Documentation/ABI/testing/debugfs-ti-lmu-fault-monitor
new file mode 100644
index 000..7e39e4a
--- /dev/null
+++ b/Documentation/ABI/testing/debugfs-ti-lmu-fault-monitor
@@ -0,0 +1,32 @@
+TI LMU (Lighting Management Unit) Fault Monitoring via the debugfs
+
+LM3633 and LM3697 support hardware fault monitoring which detects
+open or short circuit case.
+
+What:  /sys/kernel/debug/ti-lmu-fault-monitor/open_fault
+Date:  Dec 2015
+KernelVersion: 4.5
+Contact:   Milo Kim 
+Description:   read only
+Check whether light channel works or open circuit is detected.
+
+   Example:
+   cat /sys/kernel/debug/ti-lmu-fault-monitor/open_fault
+
+   Channel 0 works
+   Channel 1 works
+   Channel 2 is open
+
+What:  /sys/kernel/debug/ti-lmu-fault-monitor/short_fault
+Date:  Dec 2015
+KernelVersion: 4.5
+Contact:   Milo Kim 
+Description:   read only
+Check whether light channel works or short circuit is detected.
+
+   Example:
+   cat /sys/kernel/debug/ti-lmu-fault-monitor/short_fault
+
+   Channel 0 is shorted
+   Channel 1 works
+   Channel 2 works
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index a6aab27..e08acba 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1061,6 +1061,16 @@ config MFD_TI_LMU
  It consists of backlight, LED and regulator driver.
  It provides consistent device controls for lighting functions.
 
+config MFD_TI_LMU_FAULT_MONITOR
+   tristate "TI LMU Hardware Fault Monitoring Driver"
+   depends on MFD_TI_LMU && DEBUG_FS
+   help
+ Say Y here to include support for open and short circuit fault
+ detection of TI LMU devices.
+
+ This driver can also be built as a module. If so the module
+ will be called ti-lmu-fault-monitor.
+
 config MFD_OMAP_USB_HOST
bool "TI OMAP USBHS core and TLL driver"
depends on USB_EHCI_HCD_OMAP || USB_OHCI_HCD_OMAP3
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 10e4bc2..5ddb4e6 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -112,6 +112,7 @@ obj-$(CONFIG_MFD_LP3943)+= lp3943.o
 obj-$(CONFIG_MFD_LP8788)   += lp8788.o lp8788-irq.o
 
 obj-$(CONFIG_MFD_TI_LMU)   += ti-lmu.o
+obj-$(CONFIG_MFD_TI_LMU_FAULT_MONITOR) += ti-lmu-fault-monitor.o
 
 da9055-objs:= da9055-core.o da9055-i2c.o
 obj-$(CONFIG_MFD_DA9055)   += da9055.o
diff --git a/drivers/mfd/ti-lmu-fault-monitor.c 
b/drivers/mfd/ti-lmu-fault-monitor.c
new file mode 100644
index 000..ba65c93
--- /dev/null
+++ b/drivers/mfd/ti-lmu-fault-monitor.c
@@ -0,0 +1,405 @@
+/*
+ * TI LMU (Lighting Management Unit) Hardware Fault Monitoring Driver
+ *
+ * Copyright 2015 Texas Instruments
+ *
+ * Author: Milo Kim 
+ *
+ * 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 
+#include