Re: [PATCH v2] rtc/tpo: Driver to support rtc and wakeup on PowerNV platform

2014-10-05 Thread Neelesh Gupta


On 09/30/2014 03:46 PM, Neelesh Gupta wrote:

The patch implements the OPAL rtc driver that binds with the rtc
driver subsystem. The driver uses the platform device infrastructure
to probe the rtc device and register it to rtc class framework. The
'wakeup' is supported depending upon the property 'has-tpo' present
in the OF node. It provides a way to load the generic rtc driver in
in the absence of an OPAL driver.

The patch also moves the existing OPAL rtc get/set time interfaces to the
new driver and exposes the necessary OPAL calls using EXPORT_SYMBOL_GPL.

Test results:
-
Host:
[root@tul163p1 ~]# ls -l /sys/class/rtc/
total 0
lrwxrwxrwx 1 root root 0 Sep 30 04:58 rtc0 - ../../devices/opal-rtc/rtc/rtc0
[root@tul163p1 ~]# cat /sys/devices/opal-rtc/rtc/rtc0/time
10:01:51
[root@tul163p1 ~]# cat /sys/devices/opal-rtc/rtc/rtc0/time
10:02:07
[root@tul163p1 ~]# echo `date '+%s' -d '+ 3 minutes'`  
/sys/class/rtc/rtc0/wakealarm
[root@tul163p1 ~]# cat /sys/class/rtc/rtc0/wakealarm
1412071532
[root@tul163p1 ~]#

FSP:
$ smgr mfgState
standby
$ smgr mfgState
ipling
$

Signed-off-by: Neelesh Gupta neele...@linux.vnet.ibm.com
---

Changes in v2
=
- Added Documentation/devicetree/bindings/rtc/rtc-opal.txt
- Explicitly turn off RTC_UIE mode by setting 'rtc-uie_unsupported'

Dependency
==
This patch depends upon the below patch posted on 
'linuxppc-dev@lists.ozlabs.org'
[PATCH 1/4] powerpc/powernv: Add OPAL check token call
Signed-off-by: Michael Neuling mi...@neuling.org

  Documentation/devicetree/bindings/rtc/rtc-opal.txt |   16 +
  arch/powerpc/include/asm/opal.h|7 -
  arch/powerpc/kernel/time.c |1
  arch/powerpc/platforms/powernv/opal-async.c|3
  arch/powerpc/platforms/powernv/opal-rtc.c  |   63 +
  arch/powerpc/platforms/powernv/opal-wrappers.S |2
  arch/powerpc/platforms/powernv/opal.c  |6
  arch/powerpc/platforms/powernv/setup.c |2
  drivers/rtc/Kconfig|   11 +
  drivers/rtc/Makefile   |1
  drivers/rtc/rtc-opal.c |  261 
  11 files changed, 325 insertions(+), 48 deletions(-)
  create mode 100644 Documentation/devicetree/bindings/rtc/rtc-opal.txt
  create mode 100644 drivers/rtc/rtc-opal.c


Hi Alessandro,

The patch depends upon few things in powerpc tree so could you please 
Ack the

patch so that we can take it through the powerpc tree?

Thanks,
- Neelesh

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH V2] powerpc, powernv: Add OPAL platform event driver

2014-10-05 Thread Anshuman Khandual
This patch creates a new OPAL platform event character driver
which will give userspace clients the access to these events
and process them effectively. Following platforms events are
currently supported with this platform driver.

(1) Environmental and Power Warning (EPOW)
(2) Delayed Power Off (DPO)

The user interface for this driver is /dev/opal_event character
device file where the user space clients can poll and read for
new opal platform events. The expected sequence of events driven
from user space should be like the following.

(1) Open the character device file
(2) Poll on the file for POLLIN event
(3) When unblocked, must attempt to read PLAT_EVENT_MAX_SIZE size
(4) Kernel driver will pass at most one opal_plat_event structure
(5) Poll again for more new events

The driver registers for OPAL messages notifications corresponding to
individual OPAL events. When any of those event messages arrive in the
kernel, the callbacks are called to process them which in turn unblocks
the polling thread on the character device file. The driver also registers
a timer function which will be called after a threshold amount of time to
shutdown the system. The user space client receives the timeout value for
all individual OPAL platform events and hence must prepare the system and
eventually shutdown. In case the user client does not shutdown the system,
the timer function will be called after the threshold and shutdown the
system explicitly.

Reviewed-by: Neelesh Gupta neele...@linux.vnet.ibm.com
Signed-off-by: Anshuman Khandual khand...@linux.vnet.ibm.com
---
Changes in V2:
- Changed the function fetch_dpo_timeout
- Export opal_platform_events.h for user space consumption

 arch/powerpc/include/asm/opal.h|  45 +-
 arch/powerpc/include/uapi/asm/Kbuild   |   1 +
 .../include/uapi/asm/opal_platform_events.h|  90 +++
 arch/powerpc/platforms/powernv/Makefile|   2 +-
 .../platforms/powernv/opal-platform-events.c   | 736 +
 arch/powerpc/platforms/powernv/opal-wrappers.S |   1 +
 arch/powerpc/platforms/powernv/opal.c  |   8 +-
 7 files changed, 880 insertions(+), 3 deletions(-)
 create mode 100644 arch/powerpc/include/uapi/asm/opal_platform_events.h
 create mode 100644 arch/powerpc/platforms/powernv/opal-platform-events.c

diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index 86055e5..c134137 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -151,6 +151,7 @@ struct opal_sg_list {
 #define OPAL_HANDLE_HMI98
 #define OPAL_REGISTER_DUMP_REGION  101
 #define OPAL_UNREGISTER_DUMP_REGION102
+#define OPAL_GET_DPO_STATUS105
 
 #ifndef __ASSEMBLY__
 
@@ -249,6 +250,7 @@ enum OpalMessageType {
OPAL_MSG_EPOW,
OPAL_MSG_SHUTDOWN,
OPAL_MSG_HMI_EVT,
+   OPAL_MSG_DPO,
OPAL_MSG_TYPE_MAX,
 };
 
@@ -417,6 +419,46 @@ struct opal_msg {
__be64 params[8];
 };
 
+/*
+ * EPOW status sharing (OPAL and the host)
+ *
+ * The host will pass on OPAL, a buffer of length OPAL_SYSEPOW_MAX
+ * with individual elements being 16 bits wide to fetch the system
+ * wide EPOW status. Each element in the buffer will contain the
+ * EPOW status in it's bit representation for a particular EPOW sub
+ * class as defiend here. So multiple detailed EPOW status bits
+ * specific for any sub class can be represented in a single buffer
+ * element as it's bit representation.
+ */
+
+/* System EPOW type */
+enum OpalSysEpow {
+   OPAL_SYSEPOW_POWER  = 0,/* Power EPOW */
+   OPAL_SYSEPOW_TEMP   = 1,/* Temperature EPOW */
+   OPAL_SYSEPOW_COOLING= 2,/* Cooling EPOW */
+   OPAL_SYSEPOW_MAX= 3,/* Max EPOW categories */
+};
+
+/* Power EPOW */
+enum OpalSysPower {
+   OPAL_SYSPOWER_UPS   = 0x0001, /* System on UPS power */
+   OPAL_SYSPOWER_CHNG  = 0x0002, /* System power config change */
+   OPAL_SYSPOWER_FAIL  = 0x0004, /* System impending power failure */
+   OPAL_SYSPOWER_INCL  = 0x0008, /* System incomplete power */
+};
+
+/* Temperature EPOW */
+enum OpalSysTemp {
+   OPAL_SYSTEMP_AMB= 0x0001, /* System over ambient temperature */
+   OPAL_SYSTEMP_INT= 0x0002, /* System over internal temperature */
+   OPAL_SYSTEMP_HMD= 0x0004, /* System over ambient humidity */
+};
+
+/* Cooling EPOW */
+enum OpalSysCooling {
+   OPAL_SYSCOOL_INSF   = 0x0001, /* System insufficient cooling */
+};
+
 struct opal_machine_check_event {
enum OpalMCE_Versionversion:8;  /* 0x00 */
uint8_t in_use; /* 0x01 */
@@ -881,7 +923,7 @@ int64_t opal_pci_fence_phb(uint64_t phb_id);
 int64_t opal_pci_reinit(uint64_t phb_id, uint64_t reinit_scope, uint64_t data);
 int64_t