Re: [PATCH] ipmi/powernv: Fix potential invalid pointer dereference

2015-07-29 Thread Neelesh Gupta

Hi Alistair,

Thanks for the review.

On 07/28/2015 11:21 PM, Alistair Popple wrote:

Hi Neelesh,

This fix looks reasonable to me, although Jeremy would be the best person to
comment if he has time. I wonder why we bother polling at all given that our
event interface should call opal_ipmi_recv() whenever a message is ready?


Agree. I thought about it and didn't find any reason to have it as we 
have event

mechanism.. but didn't think of changing as it is not causing any issue..



Also the firmware fix you refer to and this fix are independent of each other
so there's no ordering issues there.


Correct. Though, there is no relation, but I figured out the skiboot 
issue after

this change.. yes, they are independent. Please find time to review the
skiboot patch.

Corey,

Please queue this patch for upstream if you Ok with it.

Thanks,
Neelesh.



Reviewed-By: Alistair Popple alist...@popple.id.au

On Tue, 28 Jul 2015 13:20:07 Neelesh Gupta wrote:

On 07/17/2015 02:12 PM, Neelesh Gupta wrote:

Hi Corey,

On 07/16/2015 08:31 PM, Corey Minyard wrote:

Ok, this looks fine.  A couple of question...

Do I need to send this upstream right now?  How well has this been

tested?

I would want either Jeremy or Alistair to review this patch before you
send this
upstream. There is also firmware piece
http://patchwork.ozlabs.org/patch/496645/
awaiting review.

In the testing front, I manually made the opal_ipmi_recv() function to
fail for testing
the error path and see if the driver recovers from it and subsequent
ipmi commands
work all good.

Hi Jeremy/Alistair,

Could you please review it and the corresponding skiboot patch...

Thanks,
Neelesh.


Do you want this backported to 4.0 stable?

Yes, I want this to be be backported to 4.0 stable.

Thanks,
Neelesh.


-corey

On 07/16/2015 06:16 AM, Neelesh Gupta wrote:

If the OPAL call to receive the ipmi message fails, then we free up the
smi message and return. But, the driver still holds the reference to
old smi message in the 'cur_msg' which can potentially be accessed later
and freed again leading to kernel oops. To fix it up,

The kernel driver should reset the 'cur_msg' and send reply to the user
in addition to freeing the message.

Signed-off-by: Neelesh Guptaneele...@linux.vnet.ibm.com
---
   drivers/char/ipmi/ipmi_powernv.c |   13 ++---
   1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_powernv.c

b/drivers/char/ipmi/ipmi_powernv.c

index 9b409c0..637486d 100644
--- a/drivers/char/ipmi/ipmi_powernv.c
+++ b/drivers/char/ipmi/ipmi_powernv.c
@@ -143,9 +143,16 @@ static int ipmi_powernv_recv(struct

ipmi_smi_powernv *smi)

pr_devel(%s:   - %d (size %lld)\n, __func__,
rc, rc == 0 ? size : 0);
if (rc) {
-   spin_unlock_irqrestore(smi-msg_lock, flags);
-   ipmi_free_smi_msg(msg);
-   return 0;
+   /* If came via the poll, and response was not yet ready */
+   if (rc == OPAL_EMPTY) {
+   spin_unlock_irqrestore(smi-msg_lock, flags);
+   return 0;
+   } else {
+   smi-cur_msg = NULL;
+   spin_unlock_irqrestore(smi-msg_lock, flags);
+   send_error_reply(smi, msg, IPMI_ERR_UNSPECIFIED);
+   return 0;
+   }
}

if (size  sizeof(*opal_msg)) {




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


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

Re: [PATCH] ipmi/powernv: Fix potential invalid pointer dereference

2015-07-17 Thread Neelesh Gupta

Hi Corey,

On 07/16/2015 08:31 PM, Corey Minyard wrote:

Ok, this looks fine.  A couple of question...

Do I need to send this upstream right now?  How well has this been tested?


I would want either Jeremy or Alistair to review this patch before you 
send this
upstream. There is also firmware piece 
http://patchwork.ozlabs.org/patch/496645/

awaiting review.

In the testing front, I manually made the opal_ipmi_recv() function to 
fail for testing
the error path and see if the driver recovers from it and subsequent 
ipmi commands

work all good.



Do you want this backported to 4.0 stable?


Yes, I want this to be be backported to 4.0 stable.

Thanks,
Neelesh.



-corey

On 07/16/2015 06:16 AM, Neelesh Gupta wrote:

If the OPAL call to receive the ipmi message fails, then we free up the
smi message and return. But, the driver still holds the reference to
old smi message in the 'cur_msg' which can potentially be accessed later
and freed again leading to kernel oops. To fix it up,

The kernel driver should reset the 'cur_msg' and send reply to the user
in addition to freeing the message.

Signed-off-by: Neelesh Gupta neele...@linux.vnet.ibm.com
---
  drivers/char/ipmi/ipmi_powernv.c |   13 ++---
  1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_powernv.c b/drivers/char/ipmi/ipmi_powernv.c
index 9b409c0..637486d 100644
--- a/drivers/char/ipmi/ipmi_powernv.c
+++ b/drivers/char/ipmi/ipmi_powernv.c
@@ -143,9 +143,16 @@ static int ipmi_powernv_recv(struct ipmi_smi_powernv *smi)
pr_devel(%s:   - %d (size %lld)\n, __func__,
rc, rc == 0 ? size : 0);
if (rc) {
-   spin_unlock_irqrestore(smi-msg_lock, flags);
-   ipmi_free_smi_msg(msg);
-   return 0;
+   /* If came via the poll, and response was not yet ready */
+   if (rc == OPAL_EMPTY) {
+   spin_unlock_irqrestore(smi-msg_lock, flags);
+   return 0;
+   } else {
+   smi-cur_msg = NULL;
+   spin_unlock_irqrestore(smi-msg_lock, flags);
+   send_error_reply(smi, msg, IPMI_ERR_UNSPECIFIED);
+   return 0;
+   }
}
  
  	if (size  sizeof(*opal_msg)) {




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

[PATCH] ipmi/powernv: Fix potential invalid pointer dereference

2015-07-16 Thread Neelesh Gupta
If the OPAL call to receive the ipmi message fails, then we free up the
smi message and return. But, the driver still holds the reference to
old smi message in the 'cur_msg' which can potentially be accessed later
and freed again leading to kernel oops. To fix it up,

The kernel driver should reset the 'cur_msg' and send reply to the user
in addition to freeing the message.

Signed-off-by: Neelesh Gupta neele...@linux.vnet.ibm.com
---
 drivers/char/ipmi/ipmi_powernv.c |   13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_powernv.c b/drivers/char/ipmi/ipmi_powernv.c
index 9b409c0..637486d 100644
--- a/drivers/char/ipmi/ipmi_powernv.c
+++ b/drivers/char/ipmi/ipmi_powernv.c
@@ -143,9 +143,16 @@ static int ipmi_powernv_recv(struct ipmi_smi_powernv *smi)
pr_devel(%s:   - %d (size %lld)\n, __func__,
rc, rc == 0 ? size : 0);
if (rc) {
-   spin_unlock_irqrestore(smi-msg_lock, flags);
-   ipmi_free_smi_msg(msg);
-   return 0;
+   /* If came via the poll, and response was not yet ready */
+   if (rc == OPAL_EMPTY) {
+   spin_unlock_irqrestore(smi-msg_lock, flags);
+   return 0;
+   } else {
+   smi-cur_msg = NULL;
+   spin_unlock_irqrestore(smi-msg_lock, flags);
+   send_error_reply(smi, msg, IPMI_ERR_UNSPECIFIED);
+   return 0;
+   }
}
 
if (size  sizeof(*opal_msg)) {

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

Re: ipmi/powernv: Fix a minor bug

2015-07-09 Thread Neelesh Gupta

Hi Michael,

On 07/08/2015 04:12 PM, Michael Ellerman wrote:

On Wed, 2015-08-07 at 06:27:28 UTC, Neelesh Gupta wrote:

If the OPAL call to receive the ipmi message fails, then we free up the smi
message before returning. But, the driver still holds the reference to old
smi message in the 'cur_msg' which is dangerous if the driver derefernces it
later and it will further block the subsequent ipmi operations.

This doesn't sound like a minor bug ?

What are the actual symptoms of the bug? Does it crash, always, sometimes? Does
it actually block the subsequent ipmi operations?


In the normal scenario, it doesn't happen.
To create the crash, I passed error code in opal call 'opal_ipmi_recv()'
I think there is more need to be done than this change. So, I will resend
the next version addressing all of your concerns.

Thanks,
Neelesh.



Even if this *is* a minor bug, please give it a proper subject that describes
what it does.

Also which commit introduced the bug?

And finally you don't seem to have CC'ed the ipmi maintainers?

cheers



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

[PATCH] ipmi/powernv: Fix a minor bug

2015-07-08 Thread Neelesh Gupta
If the OPAL call to receive the ipmi message fails, then we free up the smi
message before returning. But, the driver still holds the reference to old
smi message in the 'cur_msg' which is dangerous if the driver derefernces it
later and it will further block the subsequent ipmi operations. So, to fix
it up, we need to nullify 'cur_msg' in the error case.

Signed-off-by: Neelesh Gupta neele...@linux.vnet.ibm.com
---
 drivers/char/ipmi/ipmi_powernv.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/char/ipmi/ipmi_powernv.c b/drivers/char/ipmi/ipmi_powernv.c
index 9b409c0..08dd38f 100644
--- a/drivers/char/ipmi/ipmi_powernv.c
+++ b/drivers/char/ipmi/ipmi_powernv.c
@@ -143,6 +143,7 @@ static int ipmi_powernv_recv(struct ipmi_smi_powernv *smi)
pr_devel(%s:   - %d (size %lld)\n, __func__,
rc, rc == 0 ? size : 0);
if (rc) {
+   smi-cur_msg = NULL;
spin_unlock_irqrestore(smi-msg_lock, flags);
ipmi_free_smi_msg(msg);
return 0;

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

Re: [PATCH] rtc/rtc-opal: Disable rtc-alarms when opal doesn't support tpo

2015-06-03 Thread Neelesh Gupta



On 06/03/2015 10:21 AM, Vaibhav Jain wrote:

rtc-opal driver provides support for rtc alarms via
times-power-on(tpo). However some platforms like BML use a fake rtc
clock and don't support tpo. Such platforms are indicated by the missing
'has-tpo' property in the device tree.

Current implementation however enables callback for
rtc_class_ops.read/set alarm irrespective of the tpo support from the
platform. This results in a failed opal call when kernel tries to read
an existing alarms via opal_get_tpo_time during rtc device registration.

This patch fixes this issue by setting opal_rtc_ops.read/set_alarm
callback pointers only when tpo is supported.

Signed-off-by: Vaibhav Jain vaib...@linux.vnet.ibm.com


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

Thanks,
Neelesh.


---
  drivers/rtc/rtc-opal.c | 9 +
  1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/rtc/rtc-opal.c b/drivers/rtc/rtc-opal.c
index 7061dca..1125641 100644
--- a/drivers/rtc/rtc-opal.c
+++ b/drivers/rtc/rtc-opal.c
@@ -190,11 +190,9 @@ exit:
return rc;
  }

-static const struct rtc_class_ops opal_rtc_ops = {
+static struct rtc_class_ops opal_rtc_ops = {
.read_time  = opal_get_rtc_time,
.set_time   = opal_set_rtc_time,
-   .read_alarm = opal_get_tpo_time,
-   .set_alarm  = opal_set_tpo_time,
  };

  static int opal_rtc_probe(struct platform_device *pdev)
@@ -202,8 +200,11 @@ static int opal_rtc_probe(struct platform_device *pdev)
struct rtc_device *rtc;

if (pdev-dev.of_node  of_get_property(pdev-dev.of_node, has-tpo,
-NULL))
+NULL)) {
device_set_wakeup_capable(pdev-dev, true);
+   opal_rtc_ops.read_alarm = opal_get_tpo_time;
+   opal_rtc_ops.set_alarm = opal_set_tpo_time;
+   }

rtc = devm_rtc_device_register(pdev-dev, DRVNAME, opal_rtc_ops,
   THIS_MODULE);


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

Re: [PATCH V3] drivers/mtd: add powernv flash MTD abstraction driver

2015-06-01 Thread Neelesh Gupta



On 06/02/2015 09:56 AM, Cyril Bur wrote:

Powerpc powernv platforms allow access to certain system flash devices
through a firmwarwe interface. This change adds an mtd driver for these
flash devices.

Minor updates from Jeremy Kerr and Joel Stanley.

Signed-off-by: Cyril Bur cyril...@gmail.com
Signed-off-by: Joel Stanley j...@jms.id.au
Signed-off-by: Jeremy Kerr j...@ozlabs.org


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

Neelesh.


---
Hello Brian and MTD folk,
Could I please get an ACK for Michael to take this through the powerpc
tree.
Thanks.


V2: Address Brian Norris' review
 Fix typos
 Change from NAND flash type to NOR flash type
 Correctness tweaks
V3: Address Neelesh Gupta's review
 Minor corrections
 Release the opal token on error
 Unregister mtd device on module remove
---
  drivers/mtd/devices/Kconfig |   8 +
  drivers/mtd/devices/Makefile|   1 +
  drivers/mtd/devices/powernv_flash.c | 286 
  3 files changed, 295 insertions(+)
  create mode 100644 drivers/mtd/devices/powernv_flash.c




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

Re: [PATCH V3] drivers/mtd: add powernv flash MTD abstraction driver

2015-05-29 Thread Neelesh Gupta


[...]

+/**
+ * @mtd: the device
+ * @erase: the erase info
+ * Returns 0 if erase successful or -ERRNO if an error occurred
+ */
+static int powernv_flash_erase(struct mtd_info *mtd, struct erase_info *erase)
+{
+   int rc;
+
+   erase-state = MTD_ERASING;
+
+   /* todo: register our own notifier to do a true async implementation */
+   rc =  powernv_flash_async_op(mtd, FLASH_OP_ERASE, erase-addr,
+   erase-len, NULL, NULL);
+
+   if (rc) {
+   erase-fail_addr = erase-addr;
+   erase-state = MTD_ERASE_FAILED;
+   } else {
+   erase-state = MTD_ERASE_DONE;
+   }
+   mtd_erase_callback(erase);


return rc ? You also document the same  ' or -ERRNO if an error 
occurred'



+   return 0;
+}
+
+/**
+ * powernv_flash_set_driver_info - Fill the mtd_info structure and docg3
+ * structure @pdev: The platform device
+ * @mtd: The structure to fill
+ */
+static int powernv_flash_set_driver_info(struct device *dev,
+   struct mtd_info *mtd)
+{
+   u64 size;
+   u32 erase_size;
+   int rc;
+
+   rc = of_property_read_u32(dev-of_node, ibm,flash-block-size,
+   erase_size);
+   if (rc) {
+   dev_err(dev, couldn't get resource block size information\n);
+   return rc;
+   }
+
+   rc = of_property_read_u64(dev-of_node, reg, size);
+   if (rc) {
+   dev_err(dev, couldn't get resource size information\n);
+   return rc;
+   }
+
+   /*
+* Going to have to check what details I need to set and how to
+* get them
+*/
+   mtd-name = of_get_property(dev-of_node, name, NULL);
+   mtd-type = MTD_NORFLASH;
+   mtd-flags = MTD_WRITEABLE;
+   mtd-size = size;
+   mtd-erasesize = erase_size;
+   mtd-writebufsize = mtd-writesize = 1;
+   mtd-owner = THIS_MODULE;
+   mtd-_erase = powernv_flash_erase;
+   mtd-_read = powernv_flash_read;
+   mtd-_write = powernv_flash_write;
+   mtd-dev.parent = dev;
+   return 0;
+}
+
+/**
+ * powernv_flash_probe
+ * @pdev: platform device
+ *
+ * Returns 0 on success, -ENOMEM, -ENXIO on error
+ */
+static int powernv_flash_probe(struct platform_device *pdev)
+{
+   struct device *dev = pdev-dev;
+   struct powernv_flash *data;
+   int ret;
+
+   data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
+   if (!data) {
+   ret = -ENOMEM;
+   goto out;
+   }
+   data-mtd.priv = data;


'mtd' is contained within the 'data' so you can cast 'mtd' to get the 'data'
anywhere you want using container_of() macro.. 'priv' can be used to pass
an unrelated structure   just a thought, you may ignore it.. :)

Rest looks ok.

Neelesh.


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

Re: [PATCH V2] drivers/mtd: add powernv flash MTD abstraction driver

2015-05-29 Thread Neelesh Gupta



On 05/29/2015 12:57 PM, Cedric Le Goater wrote:

Hello,

On 05/28/2015 07:25 PM, Neelesh Gupta wrote:


On 05/28/2015 06:36 PM, Cyril Bur wrote:
+
+   rc = opal_async_wait_response(token, msg);
+   opal_async_release_token(token);
+   if (rc) {
+   dev_err(dev, opal async wait failed (rc %d)\n, rc);
+   return -EIO;
+   }
+
+   rc = be64_to_cpu(msg.params[1]);
+   if (rc == OPAL_SUCCESS) {
+   rc = 0;
+   if (retlen)
+   *retlen = len;
+   } else {
+   rc = -EIO;
+   }
+

return rc;

You could use opal_error_code() to convert opal codes in errnos.

Also, powernv_flash_async_op() only contains low level OPAL cookery. I think
the code would be better placed under 'arch/powerpc/platforms/powernv/' ?


The logic would unnecessary be split between the platform and driver, it 
would make
sense if the method is going to change across the platforms, but that's 
not the case.
Moreover, we will still have to export the symbol to make this work as a 
module ...


Neelesh.



Cheers,

C.




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

Re: [PATCH V2] drivers/mtd: add powernv flash MTD abstraction driver

2015-05-28 Thread Neelesh Gupta



On 05/28/2015 06:36 PM, Cyril Bur wrote:

Powerpc powernv platforms allow access to certain system flash devices
through a firmwarwe interface. This change adds an mtd driver for these
flash devices.

Minor updates from Jeremy Kerr and Joel Stanley.

Signed-off-by: Cyril Bur cyril...@gmail.com
Signed-off-by: Joel Stanley j...@jms.id.au
Signed-off-by: Jeremy Kerr j...@ozlabs.org
---
V2: Address Brian Norris' review
 Fix typos
 Change from NAND flash type to NOR flash type
 Correctness tweaks
---
  drivers/mtd/devices/Kconfig |   8 +
  drivers/mtd/devices/Makefile|   1 +
  drivers/mtd/devices/powernv_flash.c | 286 
  3 files changed, 295 insertions(+)
  create mode 100644 drivers/mtd/devices/powernv_flash.c

diff --git a/drivers/mtd/devices/Kconfig b/drivers/mtd/devices/Kconfig
index c49d0b1..a8cc237 100644
--- a/drivers/mtd/devices/Kconfig
+++ b/drivers/mtd/devices/Kconfig
@@ -195,6 +195,14 @@ config MTD_BLOCK2MTD
  Testing MTD users (eg JFFS2) on large media and media that might
  be removed during a write (using the floppy drive).
  
+config MTD_POWERNV_FLASH

+   tristate powernv flash MTD driver
+   depends on PPC_POWERNV
+   help
+ This provides an MTD device to access NVRAM on powernv OPAL


NVRAM ? or to access FLASH device ?


+ platforms from Linux. This device abstracts away the
+ firmware interface for NVRAM access.
+
  comment Disk-On-Chip Device Drivers
  
  config MTD_DOCG3

diff --git a/drivers/mtd/devices/Makefile b/drivers/mtd/devices/Makefile
index f0b0e61..7912d3a 100644
--- a/drivers/mtd/devices/Makefile
+++ b/drivers/mtd/devices/Makefile
@@ -16,6 +16,7 @@ obj-$(CONFIG_MTD_SPEAR_SMI)   += spear_smi.o
  obj-$(CONFIG_MTD_SST25L)  += sst25l.o
  obj-$(CONFIG_MTD_BCM47XXSFLASH)   += bcm47xxsflash.o
  obj-$(CONFIG_MTD_ST_SPI_FSM)+= st_spi_fsm.o
+obj-$(CONFIG_MTD_POWERNV_FLASH)+= powernv_flash.o
  
  
  CFLAGS_docg3.o			+= -I$(src)

diff --git a/drivers/mtd/devices/powernv_flash.c 
b/drivers/mtd/devices/powernv_flash.c
new file mode 100644
index 000..f619e4a
--- /dev/null
+++ b/drivers/mtd/devices/powernv_flash.c
@@ -0,0 +1,286 @@
+/*
+ * OPAL PNOR flash MTD abstraction
+ *
+ * IBM 2015
+ *
+ * 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 linux/kernel.h
+#include linux/module.h
+#include linux/errno.h
+#include linux/of.h
+#include linux/of_address.h
+#include linux/platform_device.h
+#include linux/string.h
+#include linux/slab.h
+#include linux/mtd/mtd.h
+#include linux/mtd/partitions.h
+
+#include linux/debugfs.h
+#include linux/seq_file.h
+
+#include asm/opal.h
+
+
+/*
+ * This driver creates the a Linux MTD abstraction for platform PNOR flash
+ * backed by OPAL calls
+ */
+
+struct powernv_flash {
+   struct mtd_info mtd;
+   uint64_tid;


'id' should be u32


+};
+
+enum flash_op {
+   FLASH_OP_READ,
+   FLASH_OP_WRITE,
+   FLASH_OP_ERASE,
+};
+
+static int powernv_flash_async_op(struct mtd_info *mtd, enum flash_op op,
+   loff_t offset, size_t len, size_t *retlen, u_char *buf)
+{
+   struct powernv_flash *info = (struct powernv_flash *)mtd-priv;
+   struct device *dev = mtd-dev;
+   int token;
+   struct opal_msg msg;
+   int rc;
+
+   dev_dbg(dev, %s(op=%d, offset=0x%llx, len=%zu)\n,
+   __func__, op, offset, len);
+
+   token = opal_async_get_token_interruptible();
+   if (token  0) {
+   dev_err(dev, Failed to get an async token\n);
+   return -ENOMEM;


ENOMEM is not correct code here.. 'token' itself has the right one in 
case of

failure. To be more precise,
if (token  0) {
if (token != -ERESTARTSYS)
dev_err(dev, Failed to get an async token\n);

return token;
}


+   }
+
+   switch (op) {
+   case FLASH_OP_READ:
+   rc = opal_flash_read(info-id, offset, __pa(buf), len, token);
+   break;
+   case FLASH_OP_WRITE:
+   rc = opal_flash_write(info-id, offset, __pa(buf), len, token);
+   break;
+   case FLASH_OP_ERASE:
+   rc = opal_flash_erase(info-id, offset, len, token);
+   break;
+   default:
+   BUG_ON(1);
+   }
+
+   if (rc != OPAL_ASYNC_COMPLETION) {
+   dev_err(dev, opal_flash_async_op(op=%d) failed (rc %d)\n,
+   op, rc);


release the token, opal_async_release_token();


+

Re: [PATCH] powerpc/powernv: Add poweroff (EPOW, DPO) events support for PowerNV platform

2015-05-02 Thread Neelesh Gupta



On 04/30/2015 11:37 AM, Vipin K Parashar wrote:

diff --git a/arch/powerpc/platforms/powernv/opal-poweroff-events.c 
b/arch/powerpc/platforms/powernv/opal-poweroff-events.c
new file mode 100644
index 000..9b169e2
--- /dev/null
+++ b/arch/powerpc/platforms/powernv/opal-poweroff-events.c
@@ -0,0 +1,358 @@
+/*
+ * PowerNV poweroff events support
+ *
+ * Copyright 2015 IBM Corp.
+ *
+ * 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.
+ */
+
+#define pr_fmt(fmt)POWEROFF_EVENT: fmt
+
+#include linux/kernel.h
+#include linux/spinlock.h
+#include linux/timer.h
+#include linux/reboot.h
+#include asm/opal.h
+#include asm/machdep.h
+
+/* System EPOW status */
+u32 epow_status[OPAL_MAX_EPOW_CLASSES];
+int num_epow_classes;


static


+
+/* EPOW event timer and corresponding locks */
+static struct timer_list epow_timer;
+static DEFINE_SPINLOCK(epow_timer_spinlock);
+
+/* EPOW, DPO event status values */
+#defineDPO_DETECTED1
+#defineEPOW_DETECTED   1
+
+/* EPOW events supported */
+#define EPOW_POWER_UPS  0
+#define EPOW_POWER_UPS_LOW  1
+#define EPOW_TEMP_HIGH_AMB  2
+#define EPOW_TEMP_CRIT_AMB  3
+#define EPOW_TEMP_HIGH_INT  4
+#define EPOW_TEMP_CRIT_INT  5
+#define MAX_EPOW_EVENTS6
+
+/* EPOW events description */
+static const char * const epow_events_map[] = {
+   [EPOW_POWER_UPS]= UPS,
+   [EPOW_POWER_UPS_LOW]= UPS-low,
+   [EPOW_TEMP_HIGH_AMB]= high-ambient-temp,
+   [EPOW_TEMP_CRIT_AMB]= crit-ambient-temp,
+   [EPOW_TEMP_HIGH_INT]= high-internal-temp,
+   [EPOW_TEMP_CRIT_INT]= crit-internal-temp,
+};
+
+/* EPOW events timeout values */
+static int epow_timeout[MAX_EPOW_EVENTS];
+
+/*
+ * TODO: Export various event timeout values via device tree.
+ *  Zero timeout value for any event suggests that it needs
+ *  immediate shutdown.
+ */
+#define TIMEOUT_EPOW_POWER_UPS 450
+#define TIMEOUT_EPOW_TEMP_HIGH_AMB 450
+
+/*
+ * Get various EPOW event timeouts.
+ * TODO: For now hardcoding timeout values but they need to be
+ * obtained via firmware device-tree.
+ */
+void get_epow_timeouts(void)


static ?


+{
+   epow_timeout[EPOW_POWER_UPS] = TIMEOUT_EPOW_POWER_UPS;
+   epow_timeout[EPOW_TEMP_HIGH_AMB] = TIMEOUT_EPOW_TEMP_HIGH_AMB;


What about the timeout values for other cases ? don't see assigned
anywhere but used in the process_epow() function..


+}
+
+/* EPOW poweroff function. */
+static void epow_poweroff(unsigned long event)
+{
+   pr_info(Powering off system due to %s EPOW event\n,
+   epow_events_map[event]);
+   orderly_poweroff(true);
+}
+
+/* Start EPOW poweroff timer */
+static void start_epow_timer(unsigned long event, int32_t timeout)


'event' is of type 'int' which you are passing..


+{
+   unsigned long flags;
+
+   spin_lock_irqsave(epow_timer_spinlock, flags);
+   /* Check for already running epow poweroff timer */
+   if (timer_pending(epow_timer)) {
+   /* Timer for same event */
+   if (epow_timer.data == event) {
+   spin_unlock_irqrestore(epow_timer_spinlock, flags);
+   return;
+   }
+
+   /* Timer with early poweroff timeout */
+   if (epow_timer.expires  (jiffies + timeout * HZ)) {


Should it also return for the equal condition ?

if (epow_timer.expires = (jiffies + timeout * HZ))


+   event = epow_timer.data;
+   spin_unlock_irqrestore(epow_timer_spinlock, flags);
+   pr_info(Poweroff already scheduled for %s EPOW event 
+   with earlier timeout.\n,
+   epow_events_map[event]);
+   return;
+   }
+   }
+
+   /* Start a new timer/modify existing timer with new timeout value */
+   epow_timer.data = event;
+   mod_timer(epow_timer, jiffies + timeout  * HZ);
+   spin_unlock_irqrestore(epow_timer_spinlock, flags);
+   pr_info(Scheduled system poweroff due to %s EPOW event 
+   after %d seconds\n, epow_events_map[event], timeout);
+}
+
+/* Stop poweroff timer */
+static void stop_epow_timer(void)
+{
+   int rc;
+   unsigned long flags;
+
+   spin_lock_irqsave(epow_timer_spinlock, flags);
+   rc = del_timer(epow_timer);
+   spin_unlock_irqrestore(epow_timer_spinlock, flags);
+
+   if (rc)
+   pr_info(Poweroff timer deactivated\n);
+}
+
+/* Get DPO status */
+static int get_dpo_status(int32_t *dpo_timeout)
+{
+   int rc;
+   __be32 opal_dpo_timeout;
+
+   rc = opal_get_dpo_status(opal_dpo_timeout);
+   if (rc == OPAL_WRONG_STATE) {
+ 

Re: [PATCH] powerpc/powernv: Silence SYSPARAM warning on boot

2015-05-01 Thread Neelesh Gupta



On 04/30/2015 09:20 AM, Joel Stanley wrote:

OpenPower BMC machines do not place any sysparams in the device tree, so
at every boot we get a warning:

  [0.437176] SYSPARAM: Opal sysparam node not found

Remove the warning, and reorder the init so we don't peform allocations
when there is no sysparam node in the device tree.


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



Signed-off-by: Joel Stanley j...@jms.id.au
---
  arch/powerpc/platforms/powernv/opal-sysparam.c | 31 +-
  1 file changed, 15 insertions(+), 16 deletions(-)


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

Re: [PATCH V2 1/8] powerpc/powernv: Add a virtual irqchip for opal events

2015-04-30 Thread Neelesh Gupta

Hi Alistair,

With all the patches applied on top of 'v4.0-rc7', I see this issue during
the boot itself http://pastebin.hursley.ibm.com/918

Few compile warnings and minor comments.
drivers/tty/hvc/hvc_opal.c: In function ‘hvc_opal_probe’:
drivers/tty/hvc/hvc_opal.c:174:6: warning: unused variable ‘rc’ 
[-Wunused-variable]

  int rc;
  ^
drivers/tty/hvc/hvc_opal.c: At top level:
drivers/tty/hvc/hvc_opal.c:65:13: warning: ‘hvc_opal_event_registered’ 
defined but not used [-Wunused-variable]

 static bool hvc_opal_event_registered;



On 04/10/2015 01:54 PM, Alistair Popple wrote:

Whenever an interrupt is received for opal the linux kernel gets a
bitfield indicating certain events that have occurred and need handling
by the various device drivers. Currently this is handled using a
notifier interface where we call every device driver that has
registered to receive opal events.

This approach has several drawbacks. For example each driver has to do
its own checking to see if the event is relevant as well as event
masking. There is also no easy method of recording the number of times
we receive particular events.

This patch solves these issues by exposing opal events via the
standard interrupt APIs by adding a new interrupt chip and
domain. Drivers can then register for the appropriate events using
standard kernel calls such as irq_of_parse_and_map().

Signed-off-by: Alistair Popple alist...@popple.id.au
---

+
+static int __init opal_event_init(void)
+{
+   struct device_node *dn, *opal_node;
+   const __be32 *irqs;
+   int i, irqlen;
+
+   opal_node = of_find_node_by_path(/ibm,opal);
+   if (!opal_node) {
+   pr_warn(opal: Node not found\n);
+   return -ENODEV;
+   }
+
+   dn = of_find_compatible_node(NULL, NULL, ibm,opal-event);
+
+   /* If dn is NULL it means the domain won't be linked to a DT
+* node so therefore irq_of_parse_and_map(...) wont work. But
+* that shouldn't be problem because if we're running a
+* version of skiboot that doesn't have the dn then the
+* devices won't have the correct properties and will have to
+* fall back to the legacy method (opal_event_request(...))
+* anyway. */
+   opal_event_irqchip.domain =
+   irq_domain_add_linear(dn, 64, opal_event_domain_ops,


A macro would be better, which is maximum event bits we have.


+ opal_event_irqchip);
+   if (IS_ERR(opal_event_irqchip.domain)) {
+   pr_warn(opal: Unable to create irq domain\n);
+   return PTR_ERR(opal_event_irqchip.domain);
+   }
+
+   /* Get interrupt property */
+   irqs = of_get_property(opal_node, opal-interrupts, irqlen);


of_node_put()
Should decrement the refcount of the nodes 'opal_node' and 'dn' (if !NULL)
before returning from the function.


+   opal_irq_count = irqs ? (irqlen / 4) : 0;
+   pr_debug(Found %d interrupts reserved for OPAL\n, opal_irq_count);
+
+   /* Install interrupt handlers */
+   opal_irqs = kcalloc(opal_irq_count, sizeof(unsigned int), GFP_KERNEL);


Safer to use 'sizeof(*opal_irqs)'

Neelesh.


+   for (i = 0; irqs  i  opal_irq_count; i++, irqs++) {
+   unsigned int irq, virq;
+   int rc;
+
+   /* Get hardware and virtual IRQ */
+   irq = be32_to_cpup(irqs);
+   virq = irq_create_mapping(NULL, irq);
+   if (virq == NO_IRQ) {
+   pr_warn(Failed to map irq 0x%x\n, irq);
+   continue;
+   }
+
+   /* Install interrupt handler */
+   rc = request_irq(virq, opal_interrupt, 0, opal, NULL);
+   if (rc) {
+   irq_dispose_mapping(virq);
+   pr_warn(Error %d requesting irq %d (0x%x)\n,
+rc, virq, irq);
+   continue;
+   }
+
+   /* Cache IRQ */
+   opal_irqs[i] = virq;
+   }
+
+   return 0;
+}
+machine_core_initcall(powernv, opal_event_init);
+



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

Re: [PATCH V2 1/8] powerpc/powernv: Add a virtual irqchip for opal events

2015-04-30 Thread Neelesh Gupta

Hi Alistair,

Applied all of the patches on top of 'v4.0-rc7', found this issue during
the boot itself http://pastebin.hursley.ibm.com/918.

There are few compile warnings and minor comments.

drivers/tty/hvc/hvc_opal.c: In function ‘hvc_opal_probe’:
drivers/tty/hvc/hvc_opal.c:174:6: warning: unused variable ‘rc’ 
[-Wunused-variable]

  int rc;
  ^
drivers/tty/hvc/hvc_opal.c: At top level:
drivers/tty/hvc/hvc_opal.c:65:13: warning: ‘hvc_opal_event_registered’ 
defined but not used [-Wunused-variable]

 static bool hvc_opal_event_registered;

Regards,
Neelesh.

On 04/10/2015 01:54 PM, Alistair Popple wrote:

Whenever an interrupt is received for opal the linux kernel gets a
bitfield indicating certain events that have occurred and need handling
by the various device drivers. Currently this is handled using a
notifier interface where we call every device driver that has
registered to receive opal events.

This approach has several drawbacks. For example each driver has to do
its own checking to see if the event is relevant as well as event
masking. There is also no easy method of recording the number of times
we receive particular events.

This patch solves these issues by exposing opal events via the
standard interrupt APIs by adding a new interrupt chip and
domain. Drivers can then register for the appropriate events using
standard kernel calls such as irq_of_parse_and_map().

Signed-off-by: Alistair Popple alist...@popple.id.au
---

+static int __init opal_event_init(void)
+{
+   struct device_node *dn, *opal_node;
+   const __be32 *irqs;
+   int i, irqlen;
+
+   opal_node = of_find_node_by_path(/ibm,opal);
+   if (!opal_node) {
+   pr_warn(opal: Node not found\n);
+   return -ENODEV;
+   }
+
+   dn = of_find_compatible_node(NULL, NULL, ibm,opal-event);
+
+   /* If dn is NULL it means the domain won't be linked to a DT
+* node so therefore irq_of_parse_and_map(...) wont work. But
+* that shouldn't be problem because if we're running a
+* version of skiboot that doesn't have the dn then the
+* devices won't have the correct properties and will have to
+* fall back to the legacy method (opal_event_request(...))
+* anyway. */
+   opal_event_irqchip.domain =
+   irq_domain_add_linear(dn, 64, opal_event_domain_ops,


A macro would be better, which is maximum event bits we have.


+ opal_event_irqchip);
+   if (IS_ERR(opal_event_irqchip.domain)) {
+   pr_warn(opal: Unable to create irq domain\n);
+   return PTR_ERR(opal_event_irqchip.domain);
+   }
+
+   /* Get interrupt property */
+   irqs = of_get_property(opal_node, opal-interrupts, irqlen);
+   opal_irq_count = irqs ? (irqlen / 4) : 0;


of_node_put()
Need to decrement the refcount of these nodes, 'opal_node'  'dn' (if !NULL)


+   pr_debug(Found %d interrupts reserved for OPAL\n, opal_irq_count);
+
+   /* Install interrupt handlers */
+   opal_irqs = kcalloc(opal_irq_count, sizeof(unsigned int), GFP_KERNEL);


Safe to use 'sizeof(*opal_irqs)'


+   for (i = 0; irqs  i  opal_irq_count; i++, irqs++) {
+   unsigned int irq, virq;
+   int rc;
+
+   /* Get hardware and virtual IRQ */
+   irq = be32_to_cpup(irqs);
+   virq = irq_create_mapping(NULL, irq);
+   if (virq == NO_IRQ) {
+   pr_warn(Failed to map irq 0x%x\n, irq);
+   continue;
+   }
+
+   /* Install interrupt handler */
+   rc = request_irq(virq, opal_interrupt, 0, opal, NULL);
+   if (rc) {
+   irq_dispose_mapping(virq);
+   pr_warn(Error %d requesting irq %d (0x%x)\n,
+rc, virq, irq);
+   continue;
+   }
+
+   /* Cache IRQ */
+   opal_irqs[i] = virq;
+   }
+
+   return 0;
+}
+machine_core_initcall(powernv, opal_event_init);
+



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

Re: [RFC V2 04/12] i2c: opal: make use of the new infrastructure for quirks

2015-03-13 Thread Neelesh Gupta

Hi Wolfram,

Based on your patch:
[RFC V2 04/12] i2c: opal: make use of the new infrastructure for quirks


From: Neelesh Gupta neele...@linux.vnet.ibm.com
Subject: [PATCH] i2c: opal: Update quirk flags to do write-then-anything

Support write-then-anything in the case of 2 i2c messages
for i2c transfer.

Signed-off-by: Neelesh Guptaneele...@linux.vnet.ibm.com
---
 drivers/i2c/busses/i2c-opal.c |   11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/i2c/busses/i2c-opal.c b/drivers/i2c/busses/i2c-opal.c
index b2788ec..1ec7fc9 100644
--- a/drivers/i2c/busses/i2c-opal.c
+++ b/drivers/i2c/busses/i2c-opal.c
@@ -104,7 +104,8 @@ static int i2c_opal_master_xfer(struct i2c_adapter *adap, 
struct i2c_msg *msgs,
req.buffer_ra = cpu_to_be64(__pa(msgs[0].buf));
break;
case 2:
-   req.type = OPAL_I2C_SM_READ;
+   req.type = (msgs[1].flags  I2C_M_RD) ?
+   OPAL_I2C_SM_READ : OPAL_I2C_SM_WRITE;
req.addr = cpu_to_be16(msgs[0].addr);
req.subaddr_sz = msgs[0].len;
for (i = 0; i  msgs[0].len; i++)
@@ -199,13 +200,11 @@ static const struct i2c_algorithm i2c_opal_algo = {
.functionality  = i2c_opal_func,
 };

-/* For two messages, we basically support only simple
- * smbus transactions of a write plus a read. We might
- * want to allow also two writes but we'd have to bounce
- * the data into a single buffer.
+/* For two messages, we basically support simple smbus transactions of a
+ * write-then-anything.
  */
 static struct i2c_adapter_quirks i2c_opal_quirks = {
-   .flags = I2C_AQ_COMB_WRITE_THEN_READ,
+   .flags = I2C_AQ_COMB | I2C_AQ_COMB_WRITE_FIRST | I2C_AQ_COMB_SAME_ADDR,
.max_comb_1st_msg_len = 4,
 };





On 02/25/2015 09:31 PM, Wolfram Sang wrote:

From: Wolfram Sang wsa+rene...@sang-engineering.com

Signed-off-by: Wolfram Sang wsa+rene...@sang-engineering.com
---
  drivers/i2c/busses/i2c-opal.c | 22 +++---
  1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/i2c/busses/i2c-opal.c b/drivers/i2c/busses/i2c-opal.c
index 16f90b1a750894..b2788ecad5b3cb 100644
--- a/drivers/i2c/busses/i2c-opal.c
+++ b/drivers/i2c/busses/i2c-opal.c
@@ -104,17 +104,6 @@ static int i2c_opal_master_xfer(struct i2c_adapter *adap, 
struct i2c_msg *msgs,
req.buffer_ra = cpu_to_be64(__pa(msgs[0].buf));
break;
case 2:
-   /* For two messages, we basically support only simple
-* smbus transactions of a write plus a read. We might
-* want to allow also two writes but we'd have to bounce
-* the data into a single buffer.
-*/
-   if ((msgs[0].flags  I2C_M_RD) || !(msgs[1].flags  I2C_M_RD))
-   return -EOPNOTSUPP;
-   if (msgs[0].len  4)
-   return -EOPNOTSUPP;
-   if (msgs[0].addr != msgs[1].addr)
-   return -EOPNOTSUPP;
req.type = OPAL_I2C_SM_READ;
req.addr = cpu_to_be16(msgs[0].addr);
req.subaddr_sz = msgs[0].len;
@@ -210,6 +199,16 @@ static const struct i2c_algorithm i2c_opal_algo = {
.functionality  = i2c_opal_func,
  };
  
+/* For two messages, we basically support only simple

+ * smbus transactions of a write plus a read. We might
+ * want to allow also two writes but we'd have to bounce
+ * the data into a single buffer.
+ */
+static struct i2c_adapter_quirks i2c_opal_quirks = {
+   .flags = I2C_AQ_COMB_WRITE_THEN_READ,
+   .max_comb_1st_msg_len = 4,
+};
+
  static int i2c_opal_probe(struct platform_device *pdev)
  {
struct i2c_adapter  *adapter;
@@ -232,6 +231,7 @@ static int i2c_opal_probe(struct platform_device *pdev)
  
  	adapter-algo = i2c_opal_algo;

adapter-algo_data = (void *)(unsigned long)opal_id;
+   adapter-quirks = i2c_opal_quirks;
adapter-dev.parent = pdev-dev;
adapter-dev.of_node = of_node_get(pdev-dev.of_node);
pname = of_get_property(pdev-dev.of_node, ibm,port-name, NULL);


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

Re: [RFC V2 04/12] i2c: opal: make use of the new infrastructure for quirks

2015-03-10 Thread Neelesh Gupta

I tested the i2c opal driver after updating the patch as below.
Basically I think we can also support write-then-{read/write}
for the number of messages = 2.
Ben, any issues if we support both write plus read/write in the
opal driver ?

Regards,
Neelesh


 drivers/i2c/busses/i2c-opal.c |   20 
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/drivers/i2c/busses/i2c-opal.c b/drivers/i2c/busses/i2c-opal.c
index 16f90b1..85412ba 100644
--- a/drivers/i2c/busses/i2c-opal.c
+++ b/drivers/i2c/busses/i2c-opal.c
@@ -104,18 +104,8 @@ static int i2c_opal_master_xfer(struct i2c_adapter *adap, 
struct i2c_msg *msgs,
req.buffer_ra = cpu_to_be64(__pa(msgs[0].buf));
break;
case 2:
-   /* For two messages, we basically support only simple
-* smbus transactions of a write plus a read. We might
-* want to allow also two writes but we'd have to bounce
-* the data into a single buffer.
-*/
-   if ((msgs[0].flags  I2C_M_RD) || !(msgs[1].flags  I2C_M_RD))
-   return -EOPNOTSUPP;
-   if (msgs[0].len  4)
-   return -EOPNOTSUPP;
-   if (msgs[0].addr != msgs[1].addr)
-   return -EOPNOTSUPP;
-   req.type = OPAL_I2C_SM_READ;
+   req.type = (msgs[1].flags  I2C_M_RD) ?
+   OPAL_I2C_SM_READ : OPAL_I2C_SM_WRITE;
req.addr = cpu_to_be16(msgs[0].addr);
req.subaddr_sz = msgs[0].len;
for (i = 0; i  msgs[0].len; i++)
@@ -210,6 +200,11 @@ static const struct i2c_algorithm i2c_opal_algo = {
.functionality  = i2c_opal_func,
 };

+static struct i2c_adapter_quirks i2c_opal_quirks = {
+   .flags = I2C_AQ_COMB | I2C_AQ_COMB_WRITE_FIRST | I2C_AQ_COMB_SAME_ADDR,
+   .max_comb_1st_msg_len = 4,
+};
+
 static int i2c_opal_probe(struct platform_device *pdev)
 {
struct i2c_adapter  *adapter;
@@ -232,6 +227,7 @@ static int i2c_opal_probe(struct platform_device *pdev)

adapter-algo = i2c_opal_algo;
adapter-algo_data = (void *)(unsigned long)opal_id;
+   adapter-quirks = i2c_opal_quirks;
adapter-dev.parent = pdev-dev;
adapter-dev.of_node = of_node_get(pdev-dev.of_node);
pname = of_get_property(pdev-dev.of_node, ibm,port-name, NULL);



On 02/25/2015 09:31 PM, Wolfram Sang wrote:

From: Wolfram Sang wsa+rene...@sang-engineering.com

Signed-off-by: Wolfram Sang wsa+rene...@sang-engineering.com
---
  drivers/i2c/busses/i2c-opal.c | 22 +++---
  1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/i2c/busses/i2c-opal.c b/drivers/i2c/busses/i2c-opal.c
index 16f90b1a750894..b2788ecad5b3cb 100644
--- a/drivers/i2c/busses/i2c-opal.c
+++ b/drivers/i2c/busses/i2c-opal.c
@@ -104,17 +104,6 @@ static int i2c_opal_master_xfer(struct i2c_adapter *adap, 
struct i2c_msg *msgs,
req.buffer_ra = cpu_to_be64(__pa(msgs[0].buf));
break;
case 2:
-   /* For two messages, we basically support only simple
-* smbus transactions of a write plus a read. We might
-* want to allow also two writes but we'd have to bounce
-* the data into a single buffer.
-*/
-   if ((msgs[0].flags  I2C_M_RD) || !(msgs[1].flags  I2C_M_RD))
-   return -EOPNOTSUPP;
-   if (msgs[0].len  4)
-   return -EOPNOTSUPP;
-   if (msgs[0].addr != msgs[1].addr)
-   return -EOPNOTSUPP;
req.type = OPAL_I2C_SM_READ;
req.addr = cpu_to_be16(msgs[0].addr);
req.subaddr_sz = msgs[0].len;
@@ -210,6 +199,16 @@ static const struct i2c_algorithm i2c_opal_algo = {
.functionality  = i2c_opal_func,
  };
  
+/* For two messages, we basically support only simple

+ * smbus transactions of a write plus a read. We might
+ * want to allow also two writes but we'd have to bounce
+ * the data into a single buffer.
+ */
+static struct i2c_adapter_quirks i2c_opal_quirks = {
+   .flags = I2C_AQ_COMB_WRITE_THEN_READ,
+   .max_comb_1st_msg_len = 4,
+};
+
  static int i2c_opal_probe(struct platform_device *pdev)
  {
struct i2c_adapter  *adapter;
@@ -232,6 +231,7 @@ static int i2c_opal_probe(struct platform_device *pdev)
  
  	adapter-algo = i2c_opal_algo;

adapter-algo_data = (void *)(unsigned long)opal_id;
+   adapter-quirks = i2c_opal_quirks;
adapter-dev.parent = pdev-dev;
adapter-dev.of_node = of_node_get(pdev-dev.of_node);
pname = of_get_property(pdev-dev.of_node, ibm,port-name, NULL);


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

Re: [RFC V2 04/12] i2c: opal: make use of the new infrastructure for quirks

2015-03-10 Thread Neelesh Gupta


On 03/11/2015 04:42 AM, Benjamin Herrenschmidt wrote:

On Tue, 2015-03-10 at 22:43 +0530, Neelesh Gupta wrote:

I tested the i2c opal driver after updating the patch as below.
Basically I think we can also support write-then-{read/write}
for the number of messages = 2.
Ben, any issues if we support both write plus read/write in the
opal driver ?

Nope, in fact it's a good idea, I found myself having to expoes such
an interface to some userspace tool of ours.

However...


diff --git a/drivers/i2c/busses/i2c-opal.c b/drivers/i2c/busses/i2c-opal.c
index 16f90b1..85412ba 100644
--- a/drivers/i2c/busses/i2c-opal.c
+++ b/drivers/i2c/busses/i2c-opal.c
@@ -104,18 +104,8 @@ static int i2c_opal_master_xfer(struct i2c_adapter *adap, 
struct i2c_msg *msgs,
req.buffer_ra = cpu_to_be64(__pa(msgs[0].buf));
break;
case 2:
-   /* For two messages, we basically support only simple
-* smbus transactions of a write plus a read. We might
-* want to allow also two writes but we'd have to bounce
-* the data into a single buffer.
-*/
-   if ((msgs[0].flags  I2C_M_RD) || !(msgs[1].flags  I2C_M_RD))
-   return -EOPNOTSUPP;

Don't we still want to enforce that the first message is a write ?
Somebody may not be looking at the quirks...


-   if (msgs[0].len  4)
-   return -EOPNOTSUPP;

And that the len is supported...


-   if (msgs[0].addr != msgs[1].addr)
-   return -EOPNOTSUPP;

Same...

Ie, the quirk indicates to the callers what we support, but we should
still check that we aren't called with something that doesn't match.


Quirk *also* return error to the user if any of the conditions mismatch with
what we have indicated through the quriks structure...

I think we can't land up here by-passing the check for quirks so above 
checks

are duplicated here..

Neelesh.




-   req.type = OPAL_I2C_SM_READ;
+   req.type = (msgs[1].flags  I2C_M_RD) ?
+   OPAL_I2C_SM_READ : OPAL_I2C_SM_WRITE;
req.addr = cpu_to_be16(msgs[0].addr);
req.subaddr_sz = msgs[0].len;
for (i = 0; i  msgs[0].len; i++)
@@ -210,6 +200,11 @@ static const struct i2c_algorithm i2c_opal_algo = {
.functionality  = i2c_opal_func,
   };

+static struct i2c_adapter_quirks i2c_opal_quirks = {
+   .flags = I2C_AQ_COMB | I2C_AQ_COMB_WRITE_FIRST | I2C_AQ_COMB_SAME_ADDR,
+   .max_comb_1st_msg_len = 4,
+};
+
   static int i2c_opal_probe(struct platform_device *pdev)
   {
struct i2c_adapter  *adapter;
@@ -232,6 +227,7 @@ static int i2c_opal_probe(struct platform_device *pdev)

adapter-algo = i2c_opal_algo;
adapter-algo_data = (void *)(unsigned long)opal_id;
+   adapter-quirks = i2c_opal_quirks;
adapter-dev.parent = pdev-dev;
adapter-dev.of_node = of_node_get(pdev-dev.of_node);
pname = of_get_property(pdev-dev.of_node, ibm,port-name, NULL);



On 02/25/2015 09:31 PM, Wolfram Sang wrote:

From: Wolfram Sang wsa+rene...@sang-engineering.com

Signed-off-by: Wolfram Sang wsa+rene...@sang-engineering.com
---
   drivers/i2c/busses/i2c-opal.c | 22 +++---
   1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/i2c/busses/i2c-opal.c b/drivers/i2c/busses/i2c-opal.c
index 16f90b1a750894..b2788ecad5b3cb 100644
--- a/drivers/i2c/busses/i2c-opal.c
+++ b/drivers/i2c/busses/i2c-opal.c
@@ -104,17 +104,6 @@ static int i2c_opal_master_xfer(struct i2c_adapter *adap, 
struct i2c_msg *msgs,
req.buffer_ra = cpu_to_be64(__pa(msgs[0].buf));
break;
case 2:
-   /* For two messages, we basically support only simple
-* smbus transactions of a write plus a read. We might
-* want to allow also two writes but we'd have to bounce
-* the data into a single buffer.
-*/
-   if ((msgs[0].flags  I2C_M_RD) || !(msgs[1].flags  I2C_M_RD))
-   return -EOPNOTSUPP;
-   if (msgs[0].len  4)
-   return -EOPNOTSUPP;
-   if (msgs[0].addr != msgs[1].addr)
-   return -EOPNOTSUPP;
req.type = OPAL_I2C_SM_READ;
req.addr = cpu_to_be16(msgs[0].addr);
req.subaddr_sz = msgs[0].len;
@@ -210,6 +199,16 @@ static const struct i2c_algorithm i2c_opal_algo = {
.functionality  = i2c_opal_func,
   };
   
+/* For two messages, we basically support only simple

+ * smbus transactions of a write plus a read. We might
+ * want to allow also two writes but we'd have to bounce
+ * the data into a single buffer.
+ */
+static struct i2c_adapter_quirks i2c_opal_quirks = {
+   .flags = I2C_AQ_COMB_WRITE_THEN_READ,
+   .max_comb_1st_msg_len = 4,
+};
+
   static int i2c_opal_probe

Re: [PATCH 2/2] opal: Add message notifier unregister function

2015-02-12 Thread Neelesh Gupta


On 02/11/2015 04:27 PM, Anshuman Khandual wrote:

On 02/11/2015 11:57 AM, Neelesh Gupta wrote:

Provide an unregister interface for the opal message notifiers
to be called when not needed like during driver unload/remove.

Why only for unload/remove, you can also use it in cases where you need
to abort because of any other error soon after successful registration
for an OPAL message.


I didn't mean *only* driver unload/remove.. gave a simple use case of why do
we need this change.

Neelesh.





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

[PATCH 1/2] opal: Fix the overflow of message notifiers head array

2015-02-10 Thread Neelesh Gupta
Signed-off-by: Neelesh Gupta neele...@linux.vnet.ibm.com
Reviewed-by: Vasant Hegde hegdevas...@linux.vnet.ibm.com
---
 arch/powerpc/platforms/powernv/opal.c |   12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/opal.c 
b/arch/powerpc/platforms/powernv/opal.c
index f10b9ec..2651e22 100644
--- a/arch/powerpc/platforms/powernv/opal.c
+++ b/arch/powerpc/platforms/powernv/opal.c
@@ -305,16 +305,12 @@ void opal_notifier_disable(void)
 int opal_message_notifier_register(enum OpalMessageType msg_type,
struct notifier_block *nb)
 {
-   if (!nb) {
-   pr_warning(%s: Invalid argument (%p)\n,
-  __func__, nb);
-   return -EINVAL;
-   }
-   if (msg_type  OPAL_MSG_TYPE_MAX) {
-   pr_warning(%s: Invalid message type argument (%d)\n,
+   if (!nb || msg_type = OPAL_MSG_TYPE_MAX) {
+   pr_warning(%s: Invalid arguments, msg_type:%d\n,
   __func__, msg_type);
return -EINVAL;
}
+
return atomic_notifier_chain_register(
opal_msg_notifier_head[msg_type], nb);
 }
@@ -351,7 +347,7 @@ static void opal_handle_message(void)
type = be32_to_cpu(msg.msg_type);
 
/* Sanity check */
-   if (type  OPAL_MSG_TYPE_MAX) {
+   if (type = OPAL_MSG_TYPE_MAX) {
pr_warning(%s: Unknown message type: %u\n, __func__, type);
return;
}

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

[PATCH 2/2] opal: Add message notifier unregister function

2015-02-10 Thread Neelesh Gupta
Provide an unregister interface for the opal message notifiers
to be called when not needed like during driver unload/remove.

Signed-off-by: Neelesh Gupta neele...@linux.vnet.ibm.com
Reviewed-by: Vasant Hegde hegdevas...@linux.vnet.ibm.com
---
 arch/powerpc/include/asm/opal.h   |2 ++
 arch/powerpc/platforms/powernv/opal.c |7 +++
 2 files changed, 9 insertions(+)

diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index eb95b67..70eb45f 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -940,6 +940,8 @@ extern int opal_notifier_unregister(struct notifier_block 
*nb);
 
 extern int opal_message_notifier_register(enum OpalMessageType msg_type,
struct notifier_block *nb);
+extern int opal_message_notifier_unregister(enum OpalMessageType msg_type,
+   struct notifier_block *nb);
 extern void opal_notifier_enable(void);
 extern void opal_notifier_disable(void);
 extern void opal_notifier_update_evt(uint64_t evt_mask, uint64_t evt_val);
diff --git a/arch/powerpc/platforms/powernv/opal.c 
b/arch/powerpc/platforms/powernv/opal.c
index 2651e22..6c108ce 100644
--- a/arch/powerpc/platforms/powernv/opal.c
+++ b/arch/powerpc/platforms/powernv/opal.c
@@ -315,6 +315,13 @@ int opal_message_notifier_register(enum OpalMessageType 
msg_type,
opal_msg_notifier_head[msg_type], nb);
 }
 
+int opal_message_notifier_unregister(enum OpalMessageType msg_type,
+struct notifier_block *nb)
+{
+   return atomic_notifier_chain_unregister(
+   opal_msg_notifier_head[msg_type], nb);
+}
+
 static void opal_message_do_notify(uint32_t msg_type, void *msg)
 {
/* notify subscribers */

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

[PATCH v2 1/2] opal: Fix the overflow of message notifiers head array

2015-02-10 Thread Neelesh Gupta
Fixes the condition check of incoming message type which can
otherwise shoot beyond the message notifiers head array.

Signed-off-by: Neelesh Gupta neele...@linux.vnet.ibm.com
Reviewed-by: Vasant Hegde hegdevas...@linux.vnet.ibm.com
---
 arch/powerpc/platforms/powernv/opal.c |   12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/opal.c 
b/arch/powerpc/platforms/powernv/opal.c
index f10b9ec..2651e22 100644
--- a/arch/powerpc/platforms/powernv/opal.c
+++ b/arch/powerpc/platforms/powernv/opal.c
@@ -305,16 +305,12 @@ void opal_notifier_disable(void)
 int opal_message_notifier_register(enum OpalMessageType msg_type,
struct notifier_block *nb)
 {
-   if (!nb) {
-   pr_warning(%s: Invalid argument (%p)\n,
-  __func__, nb);
-   return -EINVAL;
-   }
-   if (msg_type  OPAL_MSG_TYPE_MAX) {
-   pr_warning(%s: Invalid message type argument (%d)\n,
+   if (!nb || msg_type = OPAL_MSG_TYPE_MAX) {
+   pr_warning(%s: Invalid arguments, msg_type:%d\n,
   __func__, msg_type);
return -EINVAL;
}
+
return atomic_notifier_chain_register(
opal_msg_notifier_head[msg_type], nb);
 }
@@ -351,7 +347,7 @@ static void opal_handle_message(void)
type = be32_to_cpu(msg.msg_type);
 
/* Sanity check */
-   if (type  OPAL_MSG_TYPE_MAX) {
+   if (type = OPAL_MSG_TYPE_MAX) {
pr_warning(%s: Unknown message type: %u\n, __func__, type);
return;
}

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

[PATCH 2/2] opal: Add message notifier unregister function

2015-02-10 Thread Neelesh Gupta
Provide an unregister interface for the opal message notifiers
to be called when not needed like during driver unload/remove.

Signed-off-by: Neelesh Gupta neele...@linux.vnet.ibm.com
Reviewed-by: Vasant Hegde hegdevas...@linux.vnet.ibm.com
---
 arch/powerpc/include/asm/opal.h   |2 ++
 arch/powerpc/platforms/powernv/opal.c |7 +++
 2 files changed, 9 insertions(+)

diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index eb95b67..70eb45f 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -940,6 +940,8 @@ extern int opal_notifier_unregister(struct notifier_block 
*nb);
 
 extern int opal_message_notifier_register(enum OpalMessageType msg_type,
struct notifier_block *nb);
+extern int opal_message_notifier_unregister(enum OpalMessageType msg_type,
+   struct notifier_block *nb);
 extern void opal_notifier_enable(void);
 extern void opal_notifier_disable(void);
 extern void opal_notifier_update_evt(uint64_t evt_mask, uint64_t evt_val);
diff --git a/arch/powerpc/platforms/powernv/opal.c 
b/arch/powerpc/platforms/powernv/opal.c
index 2651e22..6c108ce 100644
--- a/arch/powerpc/platforms/powernv/opal.c
+++ b/arch/powerpc/platforms/powernv/opal.c
@@ -315,6 +315,13 @@ int opal_message_notifier_register(enum OpalMessageType 
msg_type,
opal_msg_notifier_head[msg_type], nb);
 }
 
+int opal_message_notifier_unregister(enum OpalMessageType msg_type,
+struct notifier_block *nb)
+{
+   return atomic_notifier_chain_unregister(
+   opal_msg_notifier_head[msg_type], nb);
+}
+
 static void opal_message_do_notify(uint32_t msg_type, void *msg)
 {
/* notify subscribers */

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

[PATCH v4] i2c: Driver to expose PowerNV platform i2c busses

2014-12-13 Thread Neelesh Gupta
The patch exposes the available i2c busses on the PowerNV platform
to the kernel and implements the bus driver to support i2c and
smbus commands.
The driver uses the platform device infrastructure to probe the busses
on the platform and registers them with the i2c driver framework.

Signed-off-by: Neelesh Gupta neele...@linux.vnet.ibm.com
Signed-off-by: Benjamin Herrenschmidt b...@kernel.crashing.org
Acked-by: Wolfram Sang w...@the-dreams.de (I2C part, excluding the bindings)
---

v3 - v4:
- Rebased to the latest tree.
- Exported the opal function 'opal_i2c_request' in opal.c to make the
  driver build as module.

v2 - v3:
- Added the device tree binding documentation for the driver.
- Sorted the ordering of this new driver added in Makefile.
- Removed populating the superfluous .owner field in 'struct driver'.

 Documentation/devicetree/bindings/i2c/i2c-opal.txt |   37 +++
 arch/powerpc/include/asm/opal.h|   29 ++
 arch/powerpc/platforms/powernv/opal-wrappers.S |1 
 arch/powerpc/platforms/powernv/opal.c  |   12 +
 drivers/i2c/busses/Kconfig |   11 +
 drivers/i2c/busses/Makefile|1 
 drivers/i2c/busses/i2c-opal.c  |  294 
 7 files changed, 385 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i2c/i2c-opal.txt
 create mode 100644 drivers/i2c/busses/i2c-opal.c

diff --git a/Documentation/devicetree/bindings/i2c/i2c-opal.txt 
b/Documentation/devicetree/bindings/i2c/i2c-opal.txt
new file mode 100644
index 000..12bc614
--- /dev/null
+++ b/Documentation/devicetree/bindings/i2c/i2c-opal.txt
@@ -0,0 +1,37 @@
+Device-tree bindings for I2C OPAL driver
+
+
+Most of the device node and properties layout is specific to the firmware and
+used by the firmware itself for configuring the port. From the linux
+perspective, the properties of use are ibm,port-name and ibm,opal-id.
+
+Required properties:
+
+- reg: Port-id within a given master
+- compatible: must be ibm,opal-i2c
+- ibm,opal-id: Refers to a specific bus and used to identify it when calling
+  the relevant OPAL functions.
+- bus-frequency: Operating frequency of the i2c bus (in HZ). Informational for
+linux, used by the FW though.
+
+Optional properties:
+- ibm,port-name: Firmware provides this name that uniquely identifies the i2c
+port.
+
+The node contains a number of other properties that are used by the FW itself
+and depend on the specific hardware implementation. The example below depicts
+a P8 on-chip bus.
+
+Example:
+
+i2c-bus@0 {
+   reg = 0x0;
+   bus-frequency = 0x61a80;
+   compatible = ibm,power8-i2c-port, ibm,opal-i2c;
+   ibm,opal-id = 0x1;
+   ibm,port-name = p8__e1p0;
+   #address-cells = 0x1;
+   phandle = 0x1006;
+   #size-cells = 0x0;
+   linux,phandle = 0x1006;
+};
diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index 5cd8d2f..4095749 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -56,6 +56,14 @@ struct opal_sg_list {
 #define OPAL_HARDWARE_FROZEN   -13
 #define OPAL_WRONG_STATE   -14
 #define OPAL_ASYNC_COMPLETION  -15
+#define OPAL_I2C_TIMEOUT   -17
+#define OPAL_I2C_INVALID_CMD   -18
+#define OPAL_I2C_LBUS_PARITY   -19
+#define OPAL_I2C_BKEND_OVERRUN -20
+#define OPAL_I2C_BKEND_ACCESS  -21
+#define OPAL_I2C_ARBT_LOST -22
+#define OPAL_I2C_NACK_RCVD -23
+#define OPAL_I2C_STOP_ERR  -24
 
 /* API Tokens (in r0) */
 #define OPAL_INVALID_CALL  -1
@@ -158,6 +166,7 @@ struct opal_sg_list {
 #define OPAL_READ_TPO  104
 #define OPAL_IPMI_SEND 107
 #define OPAL_IPMI_RECV 108
+#define OPAL_I2C_REQUEST   109
 
 #ifndef __ASSEMBLY__
 
@@ -712,6 +721,24 @@ typedef struct oppanel_line {
uint64_tline_len;
 } oppanel_line_t;
 
+/* OPAL I2C request */
+struct opal_i2c_request {
+   uint8_t type;
+#define OPAL_I2C_RAW_READ  0
+#define OPAL_I2C_RAW_WRITE 1
+#define OPAL_I2C_SM_READ   2
+#define OPAL_I2C_SM_WRITE  3
+   uint8_t flags;
+#define OPAL_I2C_ADDR_10   0x01/* Not supported yet */
+   uint8_t subaddr_sz; /* Max 4 */
+   uint8_t reserved;
+   __be16 addr;/* 7 or 10 bit address */
+   __be16 reserved2;
+   __be32 subaddr; /* Sub-address if any */
+   __be32 size;/* Data size */
+   __be64 buffer_ra;   /* Buffer real address */
+};
+
 /* /sys/firmware/opal */
 extern struct kobject *opal_kobj;
 
@@ -881,6 +908,8 @@ int64_t opal_ipmi_send(uint64_t interface, struct 
opal_ipmi_msg *msg,
uint64_t msg_len);
 int64_t opal_ipmi_recv(uint64_t interface, struct opal_ipmi_msg *msg,
uint64_t *msg_len

Re: [v3] i2c: Driver to expose PowerNV platform i2c busses

2014-12-09 Thread Neelesh Gupta


On 12/09/2014 03:15 PM, Michael Ellerman wrote:

On Mon, 2014-08-12 at 06:36:16 UTC, Neelesh Gupta wrote:

The patch exposes the available i2c busses on the PowerNV platform
to the kernel and implements the bus driver to support i2c and
smbus commands.
The driver uses the platform device infrastructure to probe the busses
on the platform and registers them with the i2c driver framework.
  arch/powerpc/include/asm/opal.h|   29 ++
  arch/powerpc/platforms/powernv/opal-wrappers.S |1
  arch/powerpc/platforms/powernv/opal.c  |   11 +

This had major conflicts in the above files.

I've fixed it up but please check I did it correctly:

   https://github.com/mpe/powerpc-merge/commits/pw/neelesh-i2c

It also doesn't build as a module:

   $ grep CONFIG_I2C_OPAL .config
   CONFIG_I2C_OPAL=m
   $ make ...
   ...
   ERROR: opal_i2c_request [drivers/i2c/busses/i2c-opal.ko] undefined!


Yeah, this needs to be exported.
I think for the same reason, opal-rtc is still waiting, plus awaiting 
ack from

maintainers.

- Neelesh



cheers



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

[PATCH v3] i2c: Driver to expose PowerNV platform i2c busses

2014-12-07 Thread Neelesh Gupta
The patch exposes the available i2c busses on the PowerNV platform
to the kernel and implements the bus driver to support i2c and
smbus commands.
The driver uses the platform device infrastructure to probe the busses
on the platform and registers them with the i2c driver framework.

Signed-off-by: Neelesh Gupta neele...@linux.vnet.ibm.com
Signed-off-by: Benjamin Herrenschmidt b...@kernel.crashing.org
---

v2 - v3:
- Added the device tree binding documentation for the driver.
- Sorted the ordering of this new driver added in Makefile.
- Removed populating the superfluous .owner field in 'struct driver'.

 Documentation/devicetree/bindings/i2c/i2c-opal.txt |   37 +++
 arch/powerpc/include/asm/opal.h|   29 ++
 arch/powerpc/platforms/powernv/opal-wrappers.S |1 
 arch/powerpc/platforms/powernv/opal.c  |   11 +
 drivers/i2c/busses/Kconfig |   11 +
 drivers/i2c/busses/Makefile|1 
 drivers/i2c/busses/i2c-opal.c  |  294 
 7 files changed, 384 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i2c/i2c-opal.txt
 create mode 100644 drivers/i2c/busses/i2c-opal.c

diff --git a/Documentation/devicetree/bindings/i2c/i2c-opal.txt 
b/Documentation/devicetree/bindings/i2c/i2c-opal.txt
new file mode 100644
index 000..12bc614
--- /dev/null
+++ b/Documentation/devicetree/bindings/i2c/i2c-opal.txt
@@ -0,0 +1,37 @@
+Device-tree bindings for I2C OPAL driver
+
+
+Most of the device node and properties layout is specific to the firmware and
+used by the firmware itself for configuring the port. From the linux
+perspective, the properties of use are ibm,port-name and ibm,opal-id.
+
+Required properties:
+
+- reg: Port-id within a given master
+- compatible: must be ibm,opal-i2c
+- ibm,opal-id: Refers to a specific bus and used to identify it when calling
+  the relevant OPAL functions.
+- bus-frequency: Operating frequency of the i2c bus (in HZ). Informational for
+linux, used by the FW though.
+
+Optional properties:
+- ibm,port-name: Firmware provides this name that uniquely identifies the i2c
+port.
+
+The node contains a number of other properties that are used by the FW itself
+and depend on the specific hardware implementation. The example below depicts
+a P8 on-chip bus.
+
+Example:
+
+i2c-bus@0 {
+   reg = 0x0;
+   bus-frequency = 0x61a80;
+   compatible = ibm,power8-i2c-port, ibm,opal-i2c;
+   ibm,opal-id = 0x1;
+   ibm,port-name = p8__e1p0;
+   #address-cells = 0x1;
+   phandle = 0x1006;
+   #size-cells = 0x0;
+   linux,phandle = 0x1006;
+};
diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index 9124b0e..537807b 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -56,6 +56,14 @@ struct opal_sg_list {
 #define OPAL_HARDWARE_FROZEN   -13
 #define OPAL_WRONG_STATE   -14
 #define OPAL_ASYNC_COMPLETION  -15
+#define OPAL_I2C_TIMEOUT   -17
+#define OPAL_I2C_INVALID_CMD   -18
+#define OPAL_I2C_LBUS_PARITY   -19
+#define OPAL_I2C_BKEND_OVERRUN -20
+#define OPAL_I2C_BKEND_ACCESS  -21
+#define OPAL_I2C_ARBT_LOST -22
+#define OPAL_I2C_NACK_RCVD -23
+#define OPAL_I2C_STOP_ERR  -24
 
 /* API Tokens (in r0) */
 #define OPAL_INVALID_CALL  -1
@@ -154,6 +162,7 @@ struct opal_sg_list {
 #define OPAL_HANDLE_HMI98
 #define OPAL_REGISTER_DUMP_REGION  101
 #define OPAL_UNREGISTER_DUMP_REGION102
+#define OPAL_I2C_REQUEST   109
 
 #ifndef __ASSEMBLY__
 
@@ -801,6 +810,24 @@ typedef struct oppanel_line {
uint64_tline_len;
 } oppanel_line_t;
 
+/* OPAL I2C request */
+struct opal_i2c_request {
+   uint8_t type;
+#define OPAL_I2C_RAW_READ  0
+#define OPAL_I2C_RAW_WRITE 1
+#define OPAL_I2C_SM_READ   2
+#define OPAL_I2C_SM_WRITE  3
+   uint8_t flags;
+#define OPAL_I2C_ADDR_10   0x01/* Not supported yet */
+   uint8_t subaddr_sz; /* Max 4 */
+   uint8_t reserved;
+   __be16 addr;/* 7 or 10 bit address */
+   __be16 reserved2;
+   __be32 subaddr; /* Sub-address if any */
+   __be32 size;/* Data size */
+   __be64 buffer_ra;   /* Buffer real address */
+};
+
 /* /sys/firmware/opal */
 extern struct kobject *opal_kobj;
 
@@ -963,6 +990,8 @@ int64_t opal_handle_hmi(void);
 int64_t opal_register_dump_region(uint32_t id, uint64_t start, uint64_t end);
 int64_t opal_unregister_dump_region(uint32_t id);
 int64_t opal_pci_set_phb_cxl_mode(uint64_t phb_id, uint64_t mode, uint64_t 
pe_number);
+int64_t opal_i2c_request(uint64_t async_token, uint32_t bus_id,
+struct opal_i2c_request *oreq);
 
 /* Internal functions */
 extern int

Re: [PATCH v2] i2c: Driver to expose PowerNV platform i2c busses

2014-11-20 Thread Neelesh Gupta


On 11/16/2014 10:47 PM, Neelesh Gupta wrote:

The patch exposes the available i2c busses on the PowerNV platform
to the kernel and implements the bus driver to support i2c and
smbus commands.
The driver uses the platform device infrastructure to probe the busses
on the platform and registers them with the i2c driver framework.

Signed-off-by: Neelesh Gupta neele...@linux.vnet.ibm.com
Signed-off-by: Benjamin Herrenschmidt b...@kernel.crashing.org
---


Hi Wolfram,

Did you get the chance to look at it?
The patch addresses the comments and discussions on v1.

Thanks,
Neelesh


  arch/powerpc/include/asm/opal.h|   29 ++
  arch/powerpc/platforms/powernv/opal-wrappers.S |1
  arch/powerpc/platforms/powernv/opal.c  |   11 +
  drivers/i2c/busses/Kconfig |   11 +
  drivers/i2c/busses/Makefile|1
  drivers/i2c/busses/i2c-opal.c  |  295 
  6 files changed, 348 insertions(+)
  create mode 100644 drivers/i2c/busses/i2c-opal.c

diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index 9124b0e..537807b 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h



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

[PATCH v2] i2c: Driver to expose PowerNV platform i2c busses

2014-11-16 Thread Neelesh Gupta
The patch exposes the available i2c busses on the PowerNV platform
to the kernel and implements the bus driver to support i2c and
smbus commands.
The driver uses the platform device infrastructure to probe the busses
on the platform and registers them with the i2c driver framework.

Signed-off-by: Neelesh Gupta neele...@linux.vnet.ibm.com
Signed-off-by: Benjamin Herrenschmidt b...@kernel.crashing.org
---
 arch/powerpc/include/asm/opal.h|   29 ++
 arch/powerpc/platforms/powernv/opal-wrappers.S |1 
 arch/powerpc/platforms/powernv/opal.c  |   11 +
 drivers/i2c/busses/Kconfig |   11 +
 drivers/i2c/busses/Makefile|1 
 drivers/i2c/busses/i2c-opal.c  |  295 
 6 files changed, 348 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-opal.c

diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index 9124b0e..537807b 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -56,6 +56,14 @@ struct opal_sg_list {
 #define OPAL_HARDWARE_FROZEN   -13
 #define OPAL_WRONG_STATE   -14
 #define OPAL_ASYNC_COMPLETION  -15
+#define OPAL_I2C_TIMEOUT   -17
+#define OPAL_I2C_INVALID_CMD   -18
+#define OPAL_I2C_LBUS_PARITY   -19
+#define OPAL_I2C_BKEND_OVERRUN -20
+#define OPAL_I2C_BKEND_ACCESS  -21
+#define OPAL_I2C_ARBT_LOST -22
+#define OPAL_I2C_NACK_RCVD -23
+#define OPAL_I2C_STOP_ERR  -24
 
 /* API Tokens (in r0) */
 #define OPAL_INVALID_CALL  -1
@@ -154,6 +162,7 @@ struct opal_sg_list {
 #define OPAL_HANDLE_HMI98
 #define OPAL_REGISTER_DUMP_REGION  101
 #define OPAL_UNREGISTER_DUMP_REGION102
+#define OPAL_I2C_REQUEST   109
 
 #ifndef __ASSEMBLY__
 
@@ -801,6 +810,24 @@ typedef struct oppanel_line {
uint64_tline_len;
 } oppanel_line_t;
 
+/* OPAL I2C request */
+struct opal_i2c_request {
+   uint8_t type;
+#define OPAL_I2C_RAW_READ  0
+#define OPAL_I2C_RAW_WRITE 1
+#define OPAL_I2C_SM_READ   2
+#define OPAL_I2C_SM_WRITE  3
+   uint8_t flags;
+#define OPAL_I2C_ADDR_10   0x01/* Not supported yet */
+   uint8_t subaddr_sz; /* Max 4 */
+   uint8_t reserved;
+   __be16 addr;/* 7 or 10 bit address */
+   __be16 reserved2;
+   __be32 subaddr; /* Sub-address if any */
+   __be32 size;/* Data size */
+   __be64 buffer_ra;   /* Buffer real address */
+};
+
 /* /sys/firmware/opal */
 extern struct kobject *opal_kobj;
 
@@ -963,6 +990,8 @@ int64_t opal_handle_hmi(void);
 int64_t opal_register_dump_region(uint32_t id, uint64_t start, uint64_t end);
 int64_t opal_unregister_dump_region(uint32_t id);
 int64_t opal_pci_set_phb_cxl_mode(uint64_t phb_id, uint64_t mode, uint64_t 
pe_number);
+int64_t opal_i2c_request(uint64_t async_token, uint32_t bus_id,
+struct opal_i2c_request *oreq);
 
 /* Internal functions */
 extern int early_init_dt_scan_opal(unsigned long node, const char *uname,
diff --git a/arch/powerpc/platforms/powernv/opal-wrappers.S 
b/arch/powerpc/platforms/powernv/opal-wrappers.S
index feb549a..4673c02 100644
--- a/arch/powerpc/platforms/powernv/opal-wrappers.S
+++ b/arch/powerpc/platforms/powernv/opal-wrappers.S
@@ -250,3 +250,4 @@ OPAL_CALL(opal_handle_hmi,  
OPAL_HANDLE_HMI);
 OPAL_CALL(opal_register_dump_region,   OPAL_REGISTER_DUMP_REGION);
 OPAL_CALL(opal_unregister_dump_region, OPAL_UNREGISTER_DUMP_REGION);
 OPAL_CALL(opal_pci_set_phb_cxl_mode,   OPAL_PCI_SET_PHB_CXL_MODE);
+OPAL_CALL(opal_i2c_request,OPAL_I2C_REQUEST);
diff --git a/arch/powerpc/platforms/powernv/opal.c 
b/arch/powerpc/platforms/powernv/opal.c
index bb90e6e..994975e 100644
--- a/arch/powerpc/platforms/powernv/opal.c
+++ b/arch/powerpc/platforms/powernv/opal.c
@@ -667,6 +667,14 @@ static void opal_console_create_devs(void)
 
 }
 
+static void opal_i2c_create_devs(void)
+{
+   struct device_node *np;
+
+   for_each_compatible_node(np, NULL, ibm,opal-i2c)
+   of_platform_device_create(np, NULL, NULL);
+}
+
 static void opal_request_interrupts(void)
 {
const __be32 *irqs;
@@ -732,6 +740,9 @@ static int __init opal_init(void)
/* Create console platform devices */
opal_console_create_devs();
 
+   /* Create i2c platform devices */
+   opal_i2c_create_devs();
+
/* Register OPAL interrupts */
opal_request_interrupts();
 
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 917c358..71ad6e1 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -1044,4 +1044,15 @@ config SCx200_ACB
  This support is also available as a module.  If so, the module
  will be called scx200_acb.
 
+config I2C_OPAL
+   tristate IBM OPAL I2C driver

Re: [PATCH] i2c: Driver to expose PowerNV platform i2c busses

2014-11-14 Thread Neelesh Gupta


On 11/13/2014 01:28 PM, Wolfram Sang wrote:

Hi,

I am basically fine if this goes via the powerpc-tree and I was hoping
that I could ack it right now. However, the driver looks a bit rushed
and definately needs updates before it is ready to go.

On Mon, Nov 10, 2014 at 11:35:39AM +0530, Neelesh Gupta wrote:

The patch exposes the available i2c busses on the PowerNV platform
to the kernel and implements the bus driver to support i2c and
smbus commands.
The driver uses the platform device infrastructure to probe the busses
on the platform and registers them with the i2c driver framework.

Signed-off-by: Neelesh Gupta neele...@linux.vnet.ibm.com
Signed-off-by: Benjamin Herrenschmidt b...@kernel.crashing.org

Review for the I2C parts:


diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index 78d56c5..350aa86 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -102,5 +102,6 @@ obj-$(CONFIG_I2C_ELEKTOR)   += i2c-elektor.o
  obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o
  obj-$(CONFIG_I2C_SIBYTE)  += i2c-sibyte.o
  obj-$(CONFIG_SCx200_ACB)  += scx200_acb.o
+obj-$(CONFIG_I2C_OPAL) += i2c-opal.o

Please sort it properly, not simply at the end.


I don't find match under any 'comment' in this file so keeping it under
Other I2C/SMBus bus drivers.



  
  ccflags-$(CONFIG_I2C_DEBUG_BUS) := -DDEBUG

diff --git a/drivers/i2c/busses/i2c-opal.c b/drivers/i2c/busses/i2c-opal.c
new file mode 100644
index 000..3261716
--- /dev/null
+++ b/drivers/i2c/busses/i2c-opal.c
+
+   return rc;
+}
+
+static int i2c_opal_remove(struct platform_device *pdev)
+{
+   struct i2c_adapter *adapter = platform_get_drvdata(pdev);
+
+   i2c_del_adapter(adapter);
+
+   kfree(adapter);
+
+   return 0;
+}
+
+static const struct of_device_id i2c_opal_of_match[] = {
+   {
+   .compatible = ibm,power8-i2c-port,
+   },
+   { }
+};
+MODULE_DEVICE_TABLE(of, i2c_opal_of_match);
+
+static struct platform_driver i2c_opal_driver = {
+   .probe  = i2c_opal_probe,
+   .remove = i2c_opal_remove,
+   .driver = {
+   .name   = i2c-opal,
+   .owner  = THIS_MODULE,

Not needed.


I didn't get this.




+   .of_match_table = i2c_opal_of_match,
+   },
+};
+
+static int __init i2c_opal_init(void)
+{
+   if (!firmware_has_feature(FW_FEATURE_OPAL))
+   return -ENODEV;
+
+   return platform_driver_register(i2c_opal_driver);
+}
+
+static void __exit i2c_opal_exit(void)
+{
+   return platform_driver_unregister(i2c_opal_driver);
+}
+
+MODULE_AUTHOR(Neelesh Gupta neele...@linux.vnet.ibm.com);
+MODULE_DESCRIPTION(IBM OPAL I2C driver);
+MODULE_LICENSE(GPL);
+
+module_init(i2c_opal_init);
+module_exit(i2c_opal_exit);

Please put thos right below the functions it references.


Okay.

- Neelesh



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


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


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

Re: [PATCH] i2c: Driver to expose PowerNV platform i2c busses

2014-11-13 Thread Neelesh Gupta


On 11/13/2014 06:10 PM, Benjamin Herrenschmidt wrote:

On Thu, 2014-11-13 at 21:56 +1100, Benjamin Herrenschmidt wrote:

No, there is no timeout, if that fails something went quite wrong, it
could almost be a BUG_ON (basically we passed a wrong token or a NULL
msg).


+   }
+
+   rc = be64_to_cpu(msg.params[1]);
+   if (rc != OPAL_SUCCESS) {
+   rc = -EIO;
+   goto exit;
+   }
+

Actually, to correct myself, there are a number of error conditions
including timeouts inside the FW layer, but they are returned here, not
from opal_async_wait_response(). So indeed, we could do some error code
conversion at that point.

Neelesh, can you do that on top of your patch that adds the detailed
error codes ? We can merge it fw side tomorrow if you have a new spin,
worst case if the FW is old and only returns OPAL_HARDWARE we return
-EIO and if the FW is newer we'll have more precise error codes in Linux
too.


Yes, nice to have more precise error codes so I'm adding them in firmware
and rolling out new version of the FW. Please look at it.

Thanks,
Neelesh



Cheers,
Ben.




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

[PATCH] i2c: Driver to expose PowerNV platform i2c busses

2014-11-09 Thread Neelesh Gupta
The patch exposes the available i2c busses on the PowerNV platform
to the kernel and implements the bus driver to support i2c and
smbus commands.
The driver uses the platform device infrastructure to probe the busses
on the platform and registers them with the i2c driver framework.

Signed-off-by: Neelesh Gupta neele...@linux.vnet.ibm.com
Signed-off-by: Benjamin Herrenschmidt b...@kernel.crashing.org
---
 arch/powerpc/include/asm/opal.h|   21 ++
 arch/powerpc/platforms/powernv/opal-wrappers.S |1 
 arch/powerpc/platforms/powernv/opal.c  |   48 +++-
 drivers/i2c/busses/Kconfig |   11 +
 drivers/i2c/busses/Makefile|1 
 drivers/i2c/busses/i2c-opal.c  |  276 
 6 files changed, 349 insertions(+), 9 deletions(-)
 create mode 100644 drivers/i2c/busses/i2c-opal.c

diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index 9124b0e..7e94577 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -154,6 +154,7 @@ struct opal_sg_list {
 #define OPAL_HANDLE_HMI98
 #define OPAL_REGISTER_DUMP_REGION  101
 #define OPAL_UNREGISTER_DUMP_REGION102
+#define OPAL_I2C_REQUEST   109
 
 #ifndef __ASSEMBLY__
 
@@ -801,6 +802,24 @@ typedef struct oppanel_line {
uint64_tline_len;
 } oppanel_line_t;
 
+/* OPAL I2C request */
+struct opal_i2c_request {
+   uint8_t type;
+#define OPAL_I2C_RAW_READ  0
+#define OPAL_I2C_RAW_WRITE 1
+#define OPAL_I2C_SM_READ   2
+#define OPAL_I2C_SM_WRITE  3
+   uint8_t flags;
+#define OPAL_I2C_ADDR_10   0x01/* Not supported yet */
+   uint8_t subaddr_sz; /* Max 4 */
+   uint8_t reserved;
+   __be16 addr;/* 7 or 10 bit address */
+   __be16 reserved2;
+   __be32 subaddr; /* Sub-address if any */
+   __be32 size;/* Data size */
+   __be64 buffer_ra;   /* Buffer real address */
+};
+
 /* /sys/firmware/opal */
 extern struct kobject *opal_kobj;
 
@@ -963,6 +982,8 @@ int64_t opal_handle_hmi(void);
 int64_t opal_register_dump_region(uint32_t id, uint64_t start, uint64_t end);
 int64_t opal_unregister_dump_region(uint32_t id);
 int64_t opal_pci_set_phb_cxl_mode(uint64_t phb_id, uint64_t mode, uint64_t 
pe_number);
+int64_t opal_i2c_request(uint64_t async_token, uint32_t bus_id,
+struct opal_i2c_request *oreq);
 
 /* Internal functions */
 extern int early_init_dt_scan_opal(unsigned long node, const char *uname,
diff --git a/arch/powerpc/platforms/powernv/opal-wrappers.S 
b/arch/powerpc/platforms/powernv/opal-wrappers.S
index e9e2450..b84224b 100644
--- a/arch/powerpc/platforms/powernv/opal-wrappers.S
+++ b/arch/powerpc/platforms/powernv/opal-wrappers.S
@@ -250,3 +250,4 @@ OPAL_CALL(opal_handle_hmi,  
OPAL_HANDLE_HMI);
 OPAL_CALL(opal_register_dump_region,   OPAL_REGISTER_DUMP_REGION);
 OPAL_CALL(opal_unregister_dump_region, OPAL_UNREGISTER_DUMP_REGION);
 OPAL_CALL(opal_pci_set_phb_cxl_mode,   OPAL_PCI_SET_PHB_CXL_MODE);
+OPAL_CALL(opal_i2c_request,OPAL_I2C_REQUEST);
diff --git a/arch/powerpc/platforms/powernv/opal.c 
b/arch/powerpc/platforms/powernv/opal.c
index d019b08..217630b 100644
--- a/arch/powerpc/platforms/powernv/opal.c
+++ b/arch/powerpc/platforms/powernv/opal.c
@@ -644,17 +644,10 @@ static void __init opal_dump_region_init(void)
pr_warn(DUMP: Failed to register kernel log buffer. 
rc = %d\n, rc);
 }
-static int __init opal_init(void)
+
+static void opal_console_create_devs(void)
 {
struct device_node *np, *consoles;
-   const __be32 *irqs;
-   int rc, i, irqlen;
-
-   opal_node = of_find_node_by_path(/ibm,opal);
-   if (!opal_node) {
-   pr_warn(opal: Node not found\n);
-   return -ENODEV;
-   }
 
/* Register OPAL consoles if any ports */
if (firmware_has_feature(FW_FEATURE_OPALv2))
@@ -670,6 +663,21 @@ static int __init opal_init(void)
of_node_put(consoles);
}
 
+}
+
+static void opal_i2c_create_devs(void)
+{
+   struct device_node *np;
+
+   for_each_compatible_node(np, NULL, ibm,power8-i2c-port)
+   of_platform_device_create(np, NULL, NULL);
+}
+
+static void opal_request_interrupts(void)
+{
+   const __be32 *irqs;
+   int rc, i, irqlen;
+
/* Find all OPAL interrupts and request them */
irqs = of_get_property(opal_node, opal-interrupts, irqlen);
pr_debug(opal: Found %d interrupts reserved for OPAL\n,
@@ -689,6 +697,26 @@ static int __init opal_init(void)
(0x%x)\n, rc, irq, hwirq);
opal_irqs[i] = irq;
}
+}
+
+static int __init opal_init(void)
+{
+   int rc;
+
+   opal_node

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

2014-10-22 Thread Neelesh Gupta


On 10/14/2014 02:08 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.


Hi Alessandro,

Awaiting Ack from your side, so that we can take this through the 
powerpc tree.


Regards,
Neelesh



Test results:
-
Host:
[root@tul169p1 ~]# ls -l /sys/class/rtc/
total 0
lrwxrwxrwx 1 root root 0 Oct 14 03:07 rtc0 - ../../devices/opal-rtc/rtc/rtc0
[root@tul169p1 ~]# cat /sys/devices/opal-rtc/rtc/rtc0/time
08:10:07
[root@tul169p1 ~]# echo `date '+%s' -d '+ 2 minutes'`  
/sys/class/rtc/rtc0/wakealarm
[root@tul169p1 ~]# cat /sys/class/rtc/rtc0/wakealarm
1413274345
[root@tul169p1 ~]#

FSP:
$ smgr mfgState
standby
$ rtim timeofday

System time is valid: 2014/10/14 08:12:04.225115

$ smgr mfgState
ipling
$

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

Changes in v3
=
- Rebased to the latest tree.

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

  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  |   65 +
  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(+), 50 deletions(-)
  create mode 100644 Documentation/devicetree/bindings/rtc/rtc-opal.txt
  create mode 100644 drivers/rtc/rtc-opal.c



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

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

2014-10-14 Thread Neelesh Gupta
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@tul169p1 ~]# ls -l /sys/class/rtc/
total 0
lrwxrwxrwx 1 root root 0 Oct 14 03:07 rtc0 - ../../devices/opal-rtc/rtc/rtc0
[root@tul169p1 ~]# cat /sys/devices/opal-rtc/rtc/rtc0/time
08:10:07
[root@tul169p1 ~]# echo `date '+%s' -d '+ 2 minutes'`  
/sys/class/rtc/rtc0/wakealarm
[root@tul169p1 ~]# cat /sys/class/rtc/rtc0/wakealarm
1413274345
[root@tul169p1 ~]#

FSP:
$ smgr mfgState
standby
$ rtim timeofday

System time is valid: 2014/10/14 08:12:04.225115

$ smgr mfgState
ipling
$ 

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

Changes in v3
=
- Rebased to the latest tree.

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

 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  |   65 +
 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(+), 50 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/rtc/rtc-opal.txt
 create mode 100644 drivers/rtc/rtc-opal.c

diff --git a/Documentation/devicetree/bindings/rtc/rtc-opal.txt 
b/Documentation/devicetree/bindings/rtc/rtc-opal.txt
new file mode 100644
index 000..af87e5e
--- /dev/null
+++ b/Documentation/devicetree/bindings/rtc/rtc-opal.txt
@@ -0,0 +1,16 @@
+IBM OPAL real-time clock
+
+
+Required properties:
+- comapatible: Should be ibm,opal-rtc
+
+Optional properties:
+- has-tpo: Decides if the wakeup is supported or not.
+
+Example:
+   rtc {
+   compatible = ibm,opal-rtc;
+   has-tpo;
+   phandle = 0x1029;
+   linux,phandle = 0x1029;
+   };
diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index 9124b0e..2c20561 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -154,6 +154,8 @@ struct opal_sg_list {
 #define OPAL_HANDLE_HMI98
 #define OPAL_REGISTER_DUMP_REGION  101
 #define OPAL_UNREGISTER_DUMP_REGION102
+#define OPAL_WRITE_TPO 103
+#define OPAL_READ_TPO  104
 
 #ifndef __ASSEMBLY__
 
@@ -819,6 +821,9 @@ int64_t opal_rtc_read(__be32 *year_month_day,
  __be64 *hour_minute_second_millisecond);
 int64_t opal_rtc_write(uint32_t year_month_day,
   uint64_t hour_minute_second_millisecond);
+int64_t opal_tpo_read(uint64_t token, __be32 *year_mon_day, __be32 *hour_min);
+int64_t opal_tpo_write(uint64_t token, uint32_t year_mon_day,
+  uint32_t hour_min);
 int64_t opal_cec_power_down(uint64_t request);
 int64_t opal_cec_reboot(void);
 int64_t opal_read_nvram(uint64_t buffer, uint64_t size, uint64_t offset);
@@ -992,8 +997,6 @@ extern int opal_async_wait_response(uint64_t token, struct 
opal_msg *msg);
 extern int opal_get_sensor_data(u32 sensor_hndl, u32 *sensor_data);
 
 struct rtc_time;
-extern int opal_set_rtc_time(struct rtc_time *tm);
-extern void opal_get_rtc_time(struct rtc_time *tm);
 extern unsigned long opal_get_boot_time(void);
 extern void opal_nvram_init(void);
 extern void opal_flash_init(void);
diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index 7505599..54490c7 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -989,6 +989,7 @@ void GregorianDay(struct rtc_time * tm)
 
tm-tm_wday = day % 7;
 }
+EXPORT_SYMBOL_GPL(GregorianDay);
 
 void to_tm(int tim, struct rtc_time * tm)
 {
diff --git a/arch/powerpc/platforms/powernv/opal-async.c 
b/arch/powerpc/platforms/powernv/opal-async.c
index e462ab9..693b6cd 100644
--- a/arch/powerpc/platforms/powernv/opal-async.c
+++ b/arch/powerpc/platforms/powernv/opal-async.c
@@ -71,6 +71,7 @@ int opal_async_get_token_interruptible(void)
 
return token

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] rtc/tpo: Driver to support rtc and wakeup on PowerNV platform

2014-09-30 Thread Neelesh Gupta
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

diff --git a/Documentation/devicetree/bindings/rtc/rtc-opal.txt 
b/Documentation/devicetree/bindings/rtc/rtc-opal.txt
new file mode 100644
index 000..af87e5e
--- /dev/null
+++ b/Documentation/devicetree/bindings/rtc/rtc-opal.txt
@@ -0,0 +1,16 @@
+IBM OPAL real-time clock
+
+
+Required properties:
+- comapatible: Should be ibm,opal-rtc
+
+Optional properties:
+- has-tpo: Decides if the wakeup is supported or not.
+
+Example:
+   rtc {
+   compatible = ibm,opal-rtc;
+   has-tpo;
+   phandle = 0x1029;
+   linux,phandle = 0x1029;
+   };
diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index 4593a93..215c560 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -152,6 +152,8 @@ struct opal_sg_list {
 #define OPAL_HANDLE_HMI98
 #define OPAL_REGISTER_DUMP_REGION  101
 #define OPAL_UNREGISTER_DUMP_REGION102
+#define OPAL_WRITE_TPO 103
+#define OPAL_READ_TPO  104
 
 #ifndef __ASSEMBLY__
 
@@ -790,6 +792,9 @@ int64_t opal_rtc_read(__be32 *year_month_day,
  __be64 *hour_minute_second_millisecond);
 int64_t opal_rtc_write(uint32_t year_month_day,
   uint64_t hour_minute_second_millisecond);
+int64_t opal_tpo_read(uint64_t token, __be32 *year_mon_day, __be32 *hour_min);
+int64_t opal_tpo_write(uint64_t token, uint32_t year_mon_day,
+  uint32_t hour_min);
 int64_t opal_cec_power_down(uint64_t request);
 int64_t opal_cec_reboot(void);
 int64_t opal_read_nvram(uint64_t buffer, uint64_t size, uint64_t offset);
@@ -960,8 +965,6 @@ extern int opal_async_wait_response(uint64_t token, struct 
opal_msg *msg);
 extern int opal_get_sensor_data(u32 sensor_hndl, u32 *sensor_data);
 
 struct rtc_time;
-extern int opal_set_rtc_time(struct rtc_time *tm);
-extern void opal_get_rtc_time(struct rtc_time *tm);
 extern unsigned long opal_get_boot_time(void);
 extern void opal_nvram_init(void);
 extern void opal_flash_init(void);
diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index 368ab37..149dc80 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -989,6 +989,7 @@ void GregorianDay(struct rtc_time * tm)
 
tm-tm_wday = day % 7;
 }
+EXPORT_SYMBOL_GPL(GregorianDay);
 
 void to_tm(int tim, struct rtc_time * tm)
 {
diff --git a/arch/powerpc/platforms/powernv/opal-async.c 
b/arch/powerpc/platforms/powernv/opal-async.c
index e462ab9..693b6cd 100644
--- a/arch/powerpc/platforms/powernv/opal-async.c

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

2014-09-29 Thread Neelesh Gupta


On 09/29/2014 03:53 PM, Anshuman Khandual wrote:

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.

Signed-off-by: Anshuman Khandual khand...@linux.vnet.ibm.com


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

- Neelesh


---
  arch/powerpc/include/asm/opal.h|  45 +-
  .../include/uapi/asm/opal_platform_events.h|  90 +++
  arch/powerpc/platforms/powernv/Makefile|   2 +-
  .../platforms/powernv/opal-platform-events.c   | 737 +
  arch/powerpc/platforms/powernv/opal-wrappers.S |   1 +
  arch/powerpc/platforms/powernv/opal.c  |   8 +-
  6 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_HMI   98
  #define OPAL_REGISTER_DUMP_REGION 101
  #define OPAL_UNREGISTER_DUMP_REGION   102
+#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 */
+};
+


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

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

2014-09-09 Thread Neelesh Gupta
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@tul169p1 linus]# ls -l /sys/class/rtc/
total 0
lrwxrwxrwx 1 root root 0 Aug 28 03:21 rtc0 - ../../devices/opal-rtc/rtc/rtc0
[root@tul169p1 linus]#
[root@tul169p1 linus]# cat /sys/devices/opal-rtc/rtc/rtc0/time 
08:22:16
[root@tul169p1 linus]# cat /sys/devices/opal-rtc/rtc/rtc0/time 
08:23:30
[root@tul169p1 linus]# echo `date '+%s' -d '+ 3 minutes'`  
/sys/class/rtc/rtc0/wakealarm
[root@tul169p1 linus]# cat /sys/class/rtc/rtc0/wakealarm
1409214402
[root@tul169p1 linus]#

FSP:
$ smgr mfgState
standby
$ rtim timeofday

System time is valid: 2014/08/28 08:25:16.128924

$ smgr mfgState
ipling
$

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

Note:
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

 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 |  257 
 10 files changed, 305 insertions(+), 48 deletions(-)
 create mode 100644 drivers/rtc/rtc-opal.c

diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index 4593a93..215c560 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -152,6 +152,8 @@ struct opal_sg_list {
 #define OPAL_HANDLE_HMI98
 #define OPAL_REGISTER_DUMP_REGION  101
 #define OPAL_UNREGISTER_DUMP_REGION102
+#define OPAL_WRITE_TPO 103
+#define OPAL_READ_TPO  104
 
 #ifndef __ASSEMBLY__
 
@@ -790,6 +792,9 @@ int64_t opal_rtc_read(__be32 *year_month_day,
  __be64 *hour_minute_second_millisecond);
 int64_t opal_rtc_write(uint32_t year_month_day,
   uint64_t hour_minute_second_millisecond);
+int64_t opal_tpo_read(uint64_t token, __be32 *year_mon_day, __be32 *hour_min);
+int64_t opal_tpo_write(uint64_t token, uint32_t year_mon_day,
+  uint32_t hour_min);
 int64_t opal_cec_power_down(uint64_t request);
 int64_t opal_cec_reboot(void);
 int64_t opal_read_nvram(uint64_t buffer, uint64_t size, uint64_t offset);
@@ -960,8 +965,6 @@ extern int opal_async_wait_response(uint64_t token, struct 
opal_msg *msg);
 extern int opal_get_sensor_data(u32 sensor_hndl, u32 *sensor_data);
 
 struct rtc_time;
-extern int opal_set_rtc_time(struct rtc_time *tm);
-extern void opal_get_rtc_time(struct rtc_time *tm);
 extern unsigned long opal_get_boot_time(void);
 extern void opal_nvram_init(void);
 extern void opal_flash_init(void);
diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index 368ab37..149dc80 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -989,6 +989,7 @@ void GregorianDay(struct rtc_time * tm)
 
tm-tm_wday = day % 7;
 }
+EXPORT_SYMBOL_GPL(GregorianDay);
 
 void to_tm(int tim, struct rtc_time * tm)
 {
diff --git a/arch/powerpc/platforms/powernv/opal-async.c 
b/arch/powerpc/platforms/powernv/opal-async.c
index e462ab9..693b6cd 100644
--- a/arch/powerpc/platforms/powernv/opal-async.c
+++ b/arch/powerpc/platforms/powernv/opal-async.c
@@ -71,6 +71,7 @@ int opal_async_get_token_interruptible(void)
 
return token;
 }
+EXPORT_SYMBOL_GPL(opal_async_get_token_interruptible);
 
 int __opal_async_release_token(int token)
 {
@@ -102,6 +103,7 @@ int opal_async_release_token(int token)
 
return 0;
 }
+EXPORT_SYMBOL_GPL(opal_async_release_token);
 
 int opal_async_wait_response(uint64_t token, struct opal_msg *msg)
 {
@@ -120,6 +122,7 @@ int opal_async_wait_response(uint64_t token, struct 
opal_msg *msg)
 
return 0;
 }
+EXPORT_SYMBOL_GPL(opal_async_wait_response);
 
 static int opal_async_comp_event(struct notifier_block *nb,
unsigned long msg_type, void *msg)
diff --git a/arch/powerpc/platforms/powernv/opal-rtc.c 
b/arch/powerpc/platforms/powernv/opal-rtc.c
index b1885db..a3c1b43 100644

[PATCH v5] powerpc/powernv: hwmon driver for power, fan rpm, voltage and temperature

2014-07-08 Thread Neelesh Gupta
This patch adds basic kernel support for reading power values, fan
speed rpm, voltage and temperature data on powernv platforms which
will be exported to user space through sysfs interface.

Test results:
-
[root@tul163p1 ~]# sensors
ibmpowernv-isa-
Adapter: ISA adapter
fan1:5465 RPM  (min =0 RPM)
fan2:5152 RPM  (min =0 RPM)
fan3:5521 RPM  (min =0 RPM)
fan4:4891 RPM  (min =0 RPM)
fan5:   0 RPM  (min =0 RPM)
fan6:   0 RPM  (min =0 RPM)
fan7:7480 RPM  (min =0 RPM)
fan8:7944 RPM  (min =0 RPM)
temp1:+39.0°C  (high =  +0.0°C)
power1:  190.00 W  

[root@tul163p1 ~]# ls /sys/devices/platform/
alarmtimer  ibmpowernv.0  power  rtc-generic  serial8250  uevent
[root@tul163p1 ~]# ls /sys/devices/platform/ibmpowernv.0/hwmon/hwmon0/
device  fan2_minfan4_minfan6_minfan8_min   power
fan1_fault  fan3_fault  fan5_fault  fan7_fault  in1_fault  power1_input
fan1_input  fan3_input  fan5_input  fan7_input  in2_fault  subsystem
fan1_minfan3_minfan5_minfan7_minin3_fault  temp1_input
fan2_fault  fan4_fault  fan6_fault  fan8_fault  in4_fault  temp1_max
fan2_input  fan4_input  fan6_input  fan8_input  name   uevent
[root@tul163p1 ~]# ls /sys/class/hwmon/hwmon0/
device  fan2_minfan4_minfan6_minfan8_min   power
fan1_fault  fan3_fault  fan5_fault  fan7_fault  in1_fault  power1_input
fan1_input  fan3_input  fan5_input  fan7_input  in2_fault  subsystem
fan1_minfan3_minfan5_minfan7_minin3_fault  temp1_input
fan2_fault  fan4_fault  fan6_fault  fan8_fault  in4_fault  temp1_max
fan2_input  fan4_input  fan6_input  fan8_input  name   uevent
[root@tul163p1 ~]#

Signed-off-by: Neelesh Gupta neele...@linux.vnet.ibm.com
Reviewed-by: Guenter Roeck li...@roeck-us.net
---

Changes in v5
=
- Addressed couple minor comments in v4.

Changes in v4
=
- Replaced pr_err() with dev_err() for logging print messages.
- Using kstrtou32() function for converting string to u32 instead of sscanf().

Changes in v3
=
- Fixed an endianness bug leading the driver to break on LE.
- Fixed a bug that when one of the 'attribute_group' not populated, following
  groups attributes were dropped.
- Rewrite the get_sensor_index_attr() function to handle all the error scenarios
  like 'sscanf' etc.
- Fixed all the errors/warnings related to coding style/whitespace.
- Added 'Documentation' files.
- Addressed remaining review comments on V2.

Changes in v2
=
- Generic use of devm_* functions in hwmon like using devm_kzalloc() for dynamic
  memory request, avoiding the need to explicit free of memory.
  Adding 'struct attribute_group' as member of platform data structure to be
  populated and then passed to devm_hwmon_device_register_with_groups().

  Note: Having an array of pointers of 'attribute_group' and each group
  corresponds to 'enum sensors' type. Not completely sure, if it's ideal or
  could have just one group populated with attributes of sensor types?

- 'ibmpowernv' is not hot-pluggable device so moving 'platform_driver' callback
  function (probe) as part of __init code.
- Fixed issues related to coding style.
- Other general comments in v1.

 .../devicetree/bindings/hwmon/ibmpowernv.txt   |   23 +
 Documentation/hwmon/ibmpowernv |   41 ++
 drivers/hwmon/Kconfig  |   11 +
 drivers/hwmon/Makefile |1 
 drivers/hwmon/ibmpowernv.c |  364 
 5 files changed, 440 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/ibmpowernv.txt
 create mode 100644 Documentation/hwmon/ibmpowernv
 create mode 100644 drivers/hwmon/ibmpowernv.c

diff --git a/Documentation/devicetree/bindings/hwmon/ibmpowernv.txt 
b/Documentation/devicetree/bindings/hwmon/ibmpowernv.txt
new file mode 100644
index 000..f93242b
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/ibmpowernv.txt
@@ -0,0 +1,23 @@
+IBM POWERNV platform sensors
+
+
+Required node properties:
+- compatible: must be one of
+   ibm,opal-sensor-cooling-fan
+   ibm,opal-sensor-amb-temp
+   ibm,opal-sensor-power-supply
+   ibm,opal-sensor-power
+- sensor-id: an opaque id provided by the firmware to the kernel, identifies a
+given sensor and its attribute data
+
+Example sensors node:
+
+cooling-fan#8-data {
+   sensor-id = 0x7052107;
+   compatible = ibm,opal-sensor-cooling-fan;
+};
+
+amb-temp#1-thrs {
+   sensor-id = 0x5096000;
+   compatible = ibm,opal-sensor-amb-temp;
+};
diff --git a/Documentation/hwmon/ibmpowernv b/Documentation/hwmon/ibmpowernv
new file mode 100644
index 000..644245a
--- /dev/null
+++ b/Documentation/hwmon/ibmpowernv
@@ -0,0 +1,41 @@
+Kernel Driver IBMPOWENV
+===
+
+Supported systems

[PATCH v4] powerpc/powernv: hwmon driver for power, fan rpm, voltage and temperature

2014-07-04 Thread Neelesh Gupta
This patch adds basic kernel support for reading power values, fan
speed rpm, voltage and temperature data on powernv platforms which will
be exported to user space through sysfs interface.

Test results:
-
[root@tul163p1 ~]# sensors
ibmpowernv-isa-
Adapter: ISA adapter
fan1:5567 RPM  (min =0 RPM)
fan2:5232 RPM  (min =0 RPM)
fan3:5532 RPM  (min =0 RPM)
fan4:4945 RPM  (min =0 RPM)
fan5:   0 RPM  (min =0 RPM)
fan6:   0 RPM  (min =0 RPM)
fan7:7392 RPM  (min =0 RPM)
fan8:7936 RPM  (min =0 RPM)
temp1:+39.0°C  (high =  +0.0°C)
power1:  191.00 W

[root@tul163p1 ~]# ls /sys/devices/platform/
alarmtimer  ibmpowernv.0  power  rtc-generic  serial8250  uevent
[root@tul163p1 ~]# ls /sys/devices/platform/ibmpowernv.0/hwmon/hwmon0/
device  fan2_minfan4_minfan6_minfan8_min   power
fan1_fault  fan3_fault  fan5_fault  fan7_fault  in1_fault  power1_input
fan1_input  fan3_input  fan5_input  fan7_input  in2_fault  subsystem
fan1_minfan3_minfan5_minfan7_minin3_fault  temp1_input
fan2_fault  fan4_fault  fan6_fault  fan8_fault  in4_fault  temp1_max
fan2_input  fan4_input  fan6_input  fan8_input  name   uevent
[root@tul163p1 ~]# 
[root@tul163p1 ~]# ls /sys/class/hwmon/hwmon0/
device  fan2_minfan4_minfan6_minfan8_min   power
fan1_fault  fan3_fault  fan5_fault  fan7_fault  in1_fault  power1_input
fan1_input  fan3_input  fan5_input  fan7_input  in2_fault  subsystem
fan1_minfan3_minfan5_minfan7_minin3_fault  temp1_input
fan2_fault  fan4_fault  fan6_fault  fan8_fault  in4_fault  temp1_max
fan2_input  fan4_input  fan6_input  fan8_input  name   uevent
[root@tul163p1 ~]#

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

Changes in v4
=
- Replaced pr_err() with dev_err() for loggin print messages.
- Using kstrtou32() function for converting string to u32 instead of sscanf().

Changes in v3
=
- Fixed an endianness bug leading the driver to break on LE.
- Fixed a bug that when one of the 'attribute_group' not populated, following
  groups attributes were dropped.
- Rewrite the get_sensor_index_attr() function to handle all the error scenarios
  like 'sscanf' etc.
- Fixed all the errors/warnings related to coding style/whitespace.
- Added 'Documentation' files.
- Addressed remaining review comments on V2.

Changes in v2
=
- Generic use of devm_* functions in hwmon like using devm_kzalloc() for dynamic
  memory request, avoiding the need to explicit free of memory.
  Adding 'struct attribute_group' as member of platform data structure to be
  populated and then passed to devm_hwmon_device_register_with_groups().

  Note: Having an array of pointers of 'attribute_group' and each group
  corresponds to 'enum sensors' type. Not completely sure, if it's ideal or
  could have just one group populated with attributes of sensor types?

- 'ibmpowernv' is not hot-pluggable device so moving 'platform_driver' callback
  function (probe) as part of __init code.
- Fixed issues related to coding style.
- Other general comments in v1.

 .../devicetree/bindings/hwmon/ibmpowernv.txt   |   27 +
 Documentation/hwmon/ibmpowernv |   41 ++
 drivers/hwmon/Kconfig  |   11 +
 drivers/hwmon/Makefile |1 
 drivers/hwmon/ibmpowernv.c |  362 
 5 files changed, 442 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/ibmpowernv.txt
 create mode 100644 Documentation/hwmon/ibmpowernv
 create mode 100644 drivers/hwmon/ibmpowernv.c

diff --git a/Documentation/devicetree/bindings/hwmon/ibmpowernv.txt 
b/Documentation/devicetree/bindings/hwmon/ibmpowernv.txt
new file mode 100644
index 000..e3bd1eb
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/ibmpowernv.txt
@@ -0,0 +1,27 @@
+IBM POWERNV platform sensors
+
+
+Required node properties:
+- compatible: must be one of
+   ibm,opal-sensor-cooling-fan
+   ibm,opal-sensor-amb-temp
+   ibm,opal-sensor-power-supply
+   ibm,opal-sensor-power
+- sensor-id: an opaque id provided by the firmware to the kernel, identifies a
+given sensor and its attribute data
+
+Example sensors node:
+
+cooling-fan#8-data {
+   sensor-id = 0x7052107;
+   phandle = 0x1028;
+   linux,phandle = 0x1028;
+   compatible = ibm,opal-sensor-cooling-fan;
+};
+
+amb-temp#1-thrs {
+   sensor-id = 0x5096000;
+   phandle = 0x1017;
+   linux,phandle = 0x1017;
+   compatible = ibm,opal-sensor-amb-temp;
+};
diff --git a/Documentation/hwmon/ibmpowernv b/Documentation/hwmon/ibmpowernv
new file mode 100644
index 000..644245a
--- /dev/null
+++ b/Documentation/hwmon/ibmpowernv
@@ -0,0 +1,41 @@
+Kernel Driver IBMPOWENV

[PATCH v3] powerpc/powernv: hwmon driver for power, fan rpm, voltage and temperature

2014-06-18 Thread Neelesh Gupta
This patch adds basic kernel enablement for reading power values, fan
speed rpm, voltage and temperature data on powernv platforms which will
be exported to user space through sysfs interface.

Test results:
-
[root@ltctul57a-p1 ~]# sensors
ibmpowernv-isa-
Adapter: ISA adapter
fan1:5660 RPM  (min =0 RPM)
fan2:5273 RPM  (min =0 RPM)
fan3:5625 RPM  (min =0 RPM)
fan4:5283 RPM  (min =0 RPM)
fan5:5625 RPM  (min =0 RPM)
fan6:5242 RPM  (min =0 RPM)
fan7:5636 RPM  (min =0 RPM)
fan8:5273 RPM  (min =0 RPM)
fan9:4984 RPM  (min =0 RPM)
fan10:   4984 RPM  (min =0 RPM)
fan11:   4984 RPM  (min =0 RPM)
fan12:   4984 RPM  (min =0 RPM)
temp1:+24.0 C  (high =  +0.0 C)
power1:  573.00 W  

[root@ltctul57a-p1 ~]# 
[root@ltctul57a-p1 ~]# ls /sys/devices/platform/
alarmtimer  ibmpowernv.0  rtc-generic  serial8250  uevent
[root@ltctul57a-p1 ~]# ls /sys/devices/platform/ibmpowernv.0/hwmon/hwmon0/
device   fan12_input  fan3_fault  fan5_minfan8_input  in4_fault
fan10_fault  fan12_minfan3_input  fan6_fault  fan8_minname
fan10_input  fan1_fault   fan3_minfan6_input  fan9_fault  power1_input
fan10_minfan1_input   fan4_fault  fan6_minfan9_input  subsystem
fan11_fault  fan1_min fan4_input  fan7_fault  fan9_mintemp1_input
fan11_input  fan2_fault   fan4_minfan7_input  in1_fault   temp1_max
fan11_minfan2_input   fan5_fault  fan7_minin2_fault   uevent
fan12_fault  fan2_min fan5_input  fan8_fault  in3_fault
[root@ltctul57a-p1 ~]# 
[root@ltctul57a-p1 ~]# ls /sys/class/hwmon/hwmon0/
device   fan12_input  fan3_fault  fan5_minfan8_input  in4_fault
fan10_fault  fan12_minfan3_input  fan6_fault  fan8_minname
fan10_input  fan1_fault   fan3_minfan6_input  fan9_fault  power1_input
fan10_minfan1_input   fan4_fault  fan6_minfan9_input  subsystem
fan11_fault  fan1_min fan4_input  fan7_fault  fan9_mintemp1_input
fan11_input  fan2_fault   fan4_minfan7_input  in1_fault   temp1_max
fan11_minfan2_input   fan5_fault  fan7_minin2_fault   uevent
fan12_fault  fan2_min fan5_input  fan8_fault  in3_fault
[root@ltctul57a-p1 ~]#

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

Changes in V3
=
- Fixed an endianness bug leading the driver to break on LE.
- Fixed a bug that when one of the 'attribute_group' not populated, following
  groups attributes were dropped.
- Rewrite the get_sensor_index_attr() function to handle all the error scenarios
  like 'sscanf' etc.
- Fixed all the errors/warnings related to coding style/whitespace.
- Added 'Documentation' files.
- Addressed remaining review comments on V2.

Changes in v2
=
- Generic use of devm_* functions in hwmon like using devm_kzalloc() for dynamic
  memory request, avoiding the need to explicit free of memory.
  Adding 'struct attribute_group' as member of platform data structure to be
  populated and then passed to devm_hwmon_device_register_with_groups().

  Note: Having an array of pointers of 'attribute_group' and each group
  corresponds to 'enum sensors' type. Not completely sure, if it's ideal or
  could have just one group populated with attributes of sensor types?

- 'ibmpowernv' is not hot-pluggable device so moving 'platform_driver' callback
  function (probe) as part of __init code.
- Fixed issues related to coding style.
- Other general comments in v1.

 .../devicetree/bindings/hwmon/ibmpowernv.txt   |   27 +
 Documentation/hwmon/ibmpowernv |   41 ++
 drivers/hwmon/Kconfig  |   11 +
 drivers/hwmon/Makefile |1 
 drivers/hwmon/ibmpowernv.c |  366 
 5 files changed, 446 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/ibmpowernv.txt
 create mode 100644 Documentation/hwmon/ibmpowernv
 create mode 100644 drivers/hwmon/ibmpowernv.c

diff --git a/Documentation/devicetree/bindings/hwmon/ibmpowernv.txt 
b/Documentation/devicetree/bindings/hwmon/ibmpowernv.txt
new file mode 100644
index 000..e3bd1eb
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/ibmpowernv.txt
@@ -0,0 +1,27 @@
+IBM POWERNV platform sensors
+
+
+Required node properties:
+- compatible: must be one of
+   ibm,opal-sensor-cooling-fan
+   ibm,opal-sensor-amb-temp
+   ibm,opal-sensor-power-supply
+   ibm,opal-sensor-power
+- sensor-id: an opaque id provided by the firmware to the kernel, identifies a
+given sensor and its attribute data
+
+Example sensors node:
+
+cooling-fan#8-data {
+   sensor-id = 0x7052107;
+   phandle = 0x1028;
+   linux,phandle = 0x1028;
+   compatible = ibm,opal-sensor-cooling-fan;
+};
+
+amb-temp#1-thrs {
+   sensor-id = 0x5096000;
+   phandle

Re: [PATCH v2] powerpc/powernv: hwmon driver for power values, fan rpm and temperature

2014-06-18 Thread Neelesh Gupta



+}
+
+static void __init get_sensor_index_attr(const char *name, u32 
*index, char *attr)

+{
+char *hash_pos = strchr(name, '#');
+char *dash_pos;
+u32 copy_len;
+char buf[8];
+
+memset(buf, 0, sizeof(buf));
+*index = 0;
+*attr = '\0';
+
+if (hash_pos) {
+dash_pos = strchr(hash_pos, '-');
+if (dash_pos) {
+copy_len = dash_pos - hash_pos - 1;
+if (copy_len  sizeof(buf)) {
+strncpy(buf, hash_pos + 1, copy_len);
+sscanf(buf, %d, index);


What if sscanf fails ? Might be an interesting exercise to try and create
multiple sensors with index 0 (or, for that matter, with the same 
index value).
Do you have any protection against bad input data ? Guess not; did you 
test

what happens if you pass bad data to the driver (such as duplicate sensor
entries) ?


We can't have duplicate entries in the device tree under the same node ?
But yes, rest other scenarios must be validated.

- Neelesh




+}
+
+strncpy(attr, dash_pos + 1, MAX_ATTR_LEN);
+}
+}
+}
+
+



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


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

Re: [PATCH v2] powerpc/powernv: hwmon driver for power values, fan rpm and temperature

2014-06-09 Thread Neelesh Gupta


On 05/28/2014 12:53 PM, Guenter Roeck wrote:

On 05/19/2014 07:26 AM, Neelesh Gupta wrote:

This patch adds basic kernel enablement for reading power values, fan
speed rpm and temperature values on powernv platforms which will
be exported to user space through sysfs interface.

Test results:
-
[root@tul163p1 ~]# sensors
ibmpowernv-isa-
Adapter: ISA adapter
fan1:5487 RPM  (min =0 RPM)
fan2:5152 RPM  (min =0 RPM)
fan3:5590 RPM  (min =0 RPM)
fan4:4963 RPM  (min =0 RPM)
fan5:   0 RPM  (min =0 RPM)
fan6:   0 RPM  (min =0 RPM)
fan7:7488 RPM  (min =0 RPM)
fan8:7944 RPM  (min =0 RPM)
temp1:+39.0°C  (high =  +0.0°C)
power1:  192.00 W

[root@tul163p1 ~]# ls /sys/devices/platform/
alarmtimer  ibmpowernv.0  rtc-generic  serial8250  uevent
[root@tul163p1 ~]# ls /sys/devices/platform/ibmpowernv.0/
driver/hwmon/ modalias   subsystem/ uevent
[root@tul163p1 ~]# ls /sys/devices/platform/ibmpowernv.0/hwmon/hwmon0/
devicefan2_minfan4_minfan6_minfan8_min power1_input
fan1_fault  fan3_faultfan5_fault  fan7_faultin1_fault subsystem
fan1_input  fan3_inputfan5_input  fan7_inputin2_fault 
temp1_input

fan1_minfan3_minfan5_minfan7_minin3_fault temp1_max
fan2_fault  fan4_faultfan6_fault  fan8_faultin4_fault uevent
fan2_input  fan4_inputfan6_input  fan8_inputname
[root@tul163p1 ~]#
[root@tul163p1 ~]# ls /sys/class/hwmon/hwmon0/
devicefan2_minfan4_minfan6_minfan8_min power1_input
fan1_fault  fan3_faultfan5_fault  fan7_faultin1_fault subsystem
fan1_input  fan3_inputfan5_input  fan7_inputin2_fault 
temp1_input

fan1_minfan3_minfan5_minfan7_minin3_fault temp1_max
fan2_fault  fan4_faultfan6_fault  fan8_faultin4_fault uevent
fan2_input  fan4_inputfan6_input  fan8_inputname
[root@tul163p1 ~]#




The inX_fault attributes don't really make much sense. _fault 
attributes without
_input attributes don't have any value and are, as you noticed, not 
displayed
with the sensors command. Is this a problem in teh devicetree data or 
do you

really have voltage faults without voltages ?


There is no issue with the device data, somehow I'm getting only the 
_fault attribute

for the inX_ (power-supply) attributes.




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


Checkpatch says:

total: 8 errors, 11 warnings, 389 lines checked

NOTE: whitespace errors detected, you may wish to use 
scripts/cleanpatch or

  scripts/cleanfile

which should really not happen at this point.

Please make sure you follow CodingStyle. checkpatch --strict points to 
a number

of additional violations.

More comments inline.


Fixed all of these issues related to coding style.




Changes in v2
=
- Generic use of devm_* functions in hwmon like using devm_kzalloc() 
for dynamic

   memory request, avoiding the need to explicit free of memory.
   Adding 'struct attribute_group' as member of platform data 
structure to be
   populated and then passed to 
devm_hwmon_device_register_with_groups().


   Note: Having an array of pointers of 'attribute_group' and each group
   corresponds to 'enum sensors' type. Not completely sure, if it's 
ideal or

   could have just one group populated with attributes of sensor types?

Your call, really; whatever is easier for you. I won't dictate one or 
the other.


Question though is what happens if one group is not populated. If I 
understand
the code correctly this will result in the remaining groups to be 
'dropped',

ie not displayed at all.


Yes, should be fixed.



- 'ibmpowernv' is not hot-pluggable device so moving 
'platform_driver' callback

   function (probe) as part of __init code.
- Fixed issues related to coding style.
- Other general comments in v1.

  drivers/hwmon/Kconfig  |8 +
  drivers/hwmon/Makefile |1
  drivers/hwmon/ibmpowernv.c |  368 



You'll also need Documentation/hwmon/ibmpowernv and
Documentation/devicetree/bindings/hwmon/ibmpowernv.

The latter will need to get an Ack from the devicetree maintainers.


I'll do as required.


  3 files changed, 377 insertions(+)
  create mode 100644 drivers/hwmon/ibmpowernv.c

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index bc196f4..3e308fa 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -554,6 +554,14 @@ config SENSORS_IBMPEX
This driver can also be built as a module.  If so, the module
will be called ibmpex.

+config SENSORS_IBMPOWERNV
+tristate IBM POWERNV platform sensors
+depends on PPC_POWERNV
+default y
+help
+  If you say yes here you get support for the temperature/fan/power
+  sensors on your platform.
+
  config SENSORS_IIO_HWMON
  tristate Hwmon driver that uses channels specified via iio maps
  depends on IIO
diff --git

Re: [PATCH v2] powerpc/powernv: hwmon driver for power values, fan rpm and temperature

2014-05-30 Thread Neelesh Gupta


On 05/28/2014 01:11 PM, Benjamin Herrenschmidt wrote:

On Wed, 2014-05-28 at 00:23 -0700, Guenter Roeck wrote:

Consider using of_property_read_u32().


+ sdata[count].id = *sensor_id;
+ sdata[count].type = type;

Especially since this is broken for Little Endian !

Neelesh, please make sure you test your patch on LE.

Cheers,
Ben.


Fixing it and will surely test on LE as well before posting.

- Neelesh

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

Re: [PATCH v2] powerpc/powernv: hwmon driver for power values, fan rpm and temperature

2014-05-26 Thread Neelesh Gupta

Any updates on the patch.

- Neelesh

On 05/19/2014 07:56 PM, Neelesh Gupta wrote:

This patch adds basic kernel enablement for reading power values, fan
speed rpm and temperature values on powernv platforms which will
be exported to user space through sysfs interface.

Test results:
-
[root@tul163p1 ~]# sensors
ibmpowernv-isa-
Adapter: ISA adapter
fan1:5487 RPM  (min =0 RPM)
fan2:5152 RPM  (min =0 RPM)
fan3:5590 RPM  (min =0 RPM)
fan4:4963 RPM  (min =0 RPM)
fan5:   0 RPM  (min =0 RPM)
fan6:   0 RPM  (min =0 RPM)
fan7:7488 RPM  (min =0 RPM)
fan8:7944 RPM  (min =0 RPM)
temp1:+39.0°C  (high =  +0.0°C)
power1:  192.00 W

[root@tul163p1 ~]# ls /sys/devices/platform/
alarmtimer  ibmpowernv.0  rtc-generic  serial8250  uevent
[root@tul163p1 ~]# ls /sys/devices/platform/ibmpowernv.0/
driver/hwmon/ modalias   subsystem/ uevent
[root@tul163p1 ~]# ls /sys/devices/platform/ibmpowernv.0/hwmon/hwmon0/
device  fan2_minfan4_minfan6_minfan8_min   power1_input
fan1_fault  fan3_fault  fan5_fault  fan7_fault  in1_fault  subsystem
fan1_input  fan3_input  fan5_input  fan7_input  in2_fault  temp1_input
fan1_minfan3_minfan5_minfan7_minin3_fault  temp1_max
fan2_fault  fan4_fault  fan6_fault  fan8_fault  in4_fault  uevent
fan2_input  fan4_input  fan6_input  fan8_input  name
[root@tul163p1 ~]#
[root@tul163p1 ~]# ls /sys/class/hwmon/hwmon0/
device  fan2_minfan4_minfan6_minfan8_min   power1_input
fan1_fault  fan3_fault  fan5_fault  fan7_fault  in1_fault  subsystem
fan1_input  fan3_input  fan5_input  fan7_input  in2_fault  temp1_input
fan1_minfan3_minfan5_minfan7_minin3_fault  temp1_max
fan2_fault  fan4_fault  fan6_fault  fan8_fault  in4_fault  uevent
fan2_input  fan4_input  fan6_input  fan8_input  name
[root@tul163p1 ~]#

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

Changes in v2
=
- Generic use of devm_* functions in hwmon like using devm_kzalloc() for dynamic
   memory request, avoiding the need to explicit free of memory.
   Adding 'struct attribute_group' as member of platform data structure to be
   populated and then passed to devm_hwmon_device_register_with_groups().

   Note: Having an array of pointers of 'attribute_group' and each group
   corresponds to 'enum sensors' type. Not completely sure, if it's ideal or
   could have just one group populated with attributes of sensor types?

- 'ibmpowernv' is not hot-pluggable device so moving 'platform_driver' callback
   function (probe) as part of __init code.
- Fixed issues related to coding style.
- Other general comments in v1.

  drivers/hwmon/Kconfig  |8 +
  drivers/hwmon/Makefile |1
  drivers/hwmon/ibmpowernv.c |  368 
  3 files changed, 377 insertions(+)
  create mode 100644 drivers/hwmon/ibmpowernv.c

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index bc196f4..3e308fa 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -554,6 +554,14 @@ config SENSORS_IBMPEX
  This driver can also be built as a module.  If so, the module
  will be called ibmpex.
  
+config SENSORS_IBMPOWERNV

+   tristate IBM POWERNV platform sensors
+   depends on PPC_POWERNV
+   default y
+   help
+ If you say yes here you get support for the temperature/fan/power
+ sensors on your platform.
+
  config SENSORS_IIO_HWMON
tristate Hwmon driver that uses channels specified via iio maps
depends on IIO
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index c48f987..199c401 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -71,6 +71,7 @@ obj-$(CONFIG_SENSORS_ULTRA45) += ultra45_env.o
  obj-$(CONFIG_SENSORS_I5K_AMB) += i5k_amb.o
  obj-$(CONFIG_SENSORS_IBMAEM)  += ibmaem.o
  obj-$(CONFIG_SENSORS_IBMPEX)  += ibmpex.o
+obj-$(CONFIG_SENSORS_IBMPOWERNV)+= ibmpowernv.o
  obj-$(CONFIG_SENSORS_IIO_HWMON) += iio_hwmon.o
  obj-$(CONFIG_SENSORS_INA209)  += ina209.o
  obj-$(CONFIG_SENSORS_INA2XX)  += ina2xx.o
diff --git a/drivers/hwmon/ibmpowernv.c b/drivers/hwmon/ibmpowernv.c
new file mode 100644
index 000..afce620
--- /dev/null
+++ b/drivers/hwmon/ibmpowernv.c
@@ -0,0 +1,368 @@
+/*
+ * IBM PowerNV platform sensors for temperature/fan/power
+ * Copyright (C) 2014 IBM
+ *
+ * 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.
+ *
+ * You should have received a copy

[PATCH v2] powerpc/powernv: hwmon driver for power values, fan rpm and temperature

2014-05-19 Thread Neelesh Gupta
This patch adds basic kernel enablement for reading power values, fan
speed rpm and temperature values on powernv platforms which will
be exported to user space through sysfs interface.

Test results:
-
[root@tul163p1 ~]# sensors
ibmpowernv-isa-
Adapter: ISA adapter
fan1:5487 RPM  (min =0 RPM)
fan2:5152 RPM  (min =0 RPM)
fan3:5590 RPM  (min =0 RPM)
fan4:4963 RPM  (min =0 RPM)
fan5:   0 RPM  (min =0 RPM)
fan6:   0 RPM  (min =0 RPM)
fan7:7488 RPM  (min =0 RPM)
fan8:7944 RPM  (min =0 RPM)
temp1:+39.0°C  (high =  +0.0°C)
power1:  192.00 W  

[root@tul163p1 ~]# ls /sys/devices/platform/
alarmtimer  ibmpowernv.0  rtc-generic  serial8250  uevent
[root@tul163p1 ~]# ls /sys/devices/platform/ibmpowernv.0/
driver/hwmon/ modalias   subsystem/ uevent 
[root@tul163p1 ~]# ls /sys/devices/platform/ibmpowernv.0/hwmon/hwmon0/
device  fan2_minfan4_minfan6_minfan8_min   power1_input
fan1_fault  fan3_fault  fan5_fault  fan7_fault  in1_fault  subsystem
fan1_input  fan3_input  fan5_input  fan7_input  in2_fault  temp1_input
fan1_minfan3_minfan5_minfan7_minin3_fault  temp1_max
fan2_fault  fan4_fault  fan6_fault  fan8_fault  in4_fault  uevent
fan2_input  fan4_input  fan6_input  fan8_input  name
[root@tul163p1 ~]# 
[root@tul163p1 ~]# ls /sys/class/hwmon/hwmon0/
device  fan2_minfan4_minfan6_minfan8_min   power1_input
fan1_fault  fan3_fault  fan5_fault  fan7_fault  in1_fault  subsystem
fan1_input  fan3_input  fan5_input  fan7_input  in2_fault  temp1_input
fan1_minfan3_minfan5_minfan7_minin3_fault  temp1_max
fan2_fault  fan4_fault  fan6_fault  fan8_fault  in4_fault  uevent
fan2_input  fan4_input  fan6_input  fan8_input  name
[root@tul163p1 ~]#

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

Changes in v2
=
- Generic use of devm_* functions in hwmon like using devm_kzalloc() for dynamic
  memory request, avoiding the need to explicit free of memory.
  Adding 'struct attribute_group' as member of platform data structure to be
  populated and then passed to devm_hwmon_device_register_with_groups().

  Note: Having an array of pointers of 'attribute_group' and each group
  corresponds to 'enum sensors' type. Not completely sure, if it's ideal or
  could have just one group populated with attributes of sensor types?

- 'ibmpowernv' is not hot-pluggable device so moving 'platform_driver' callback
  function (probe) as part of __init code.
- Fixed issues related to coding style.
- Other general comments in v1.

 drivers/hwmon/Kconfig  |8 +
 drivers/hwmon/Makefile |1 
 drivers/hwmon/ibmpowernv.c |  368 
 3 files changed, 377 insertions(+)
 create mode 100644 drivers/hwmon/ibmpowernv.c

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index bc196f4..3e308fa 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -554,6 +554,14 @@ config SENSORS_IBMPEX
  This driver can also be built as a module.  If so, the module
  will be called ibmpex.
 
+config SENSORS_IBMPOWERNV
+   tristate IBM POWERNV platform sensors
+   depends on PPC_POWERNV
+   default y
+   help
+ If you say yes here you get support for the temperature/fan/power
+ sensors on your platform.
+
 config SENSORS_IIO_HWMON
tristate Hwmon driver that uses channels specified via iio maps
depends on IIO
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index c48f987..199c401 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -71,6 +71,7 @@ obj-$(CONFIG_SENSORS_ULTRA45) += ultra45_env.o
 obj-$(CONFIG_SENSORS_I5K_AMB)  += i5k_amb.o
 obj-$(CONFIG_SENSORS_IBMAEM)   += ibmaem.o
 obj-$(CONFIG_SENSORS_IBMPEX)   += ibmpex.o
+obj-$(CONFIG_SENSORS_IBMPOWERNV)+= ibmpowernv.o
 obj-$(CONFIG_SENSORS_IIO_HWMON) += iio_hwmon.o
 obj-$(CONFIG_SENSORS_INA209)   += ina209.o
 obj-$(CONFIG_SENSORS_INA2XX)   += ina2xx.o
diff --git a/drivers/hwmon/ibmpowernv.c b/drivers/hwmon/ibmpowernv.c
new file mode 100644
index 000..afce620
--- /dev/null
+++ b/drivers/hwmon/ibmpowernv.c
@@ -0,0 +1,368 @@
+/*
+ * IBM PowerNV platform sensors for temperature/fan/power
+ * Copyright (C) 2014 IBM
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.
+ */
+
+#include linux/init.h

Re: [PATCH] powerpc/powernv: hwmon driver for power values, fan rpm and temperature

2014-05-18 Thread Neelesh Gupta

On 05/14/2014 10:39 PM, Guenter Roeck wrote:

On Wed, May 14, 2014 at 11:31:53AM +0530, Neelesh Gupta wrote:

This patch adds basic kernel enablement for reading power values, fan
speed rpm and temperature values on powernv platforms which will
be exported to user space through sysfs interface.

Test results:
-
[root@tul163p1 ~]# sensors
ibmpowernv-isa-
Adapter: ISA adapter
fan1:5294 RPM  (min =0 RPM)
fan2:4945 RPM  (min =0 RPM)
fan3:5831 RPM  (min =0 RPM)
fan4:5212 RPM  (min =0 RPM)
fan5:   0 RPM  (min =0 RPM)
fan6:   0 RPM  (min =0 RPM)
fan7:7472 RPM  (min =0 RPM)
fan8:7920 RPM  (min =0 RPM)
temp1:+39.0°C  (high =  +0.0°C)
power1:  192.00 W

[root@tul163p1 ~]#
[root@tul163p1 ~]# ls /sys/devices/platform/ibmpowernv.0/
driver  fan2_minfan4_minfan6_minfan8_min   modalias  uevent
fan1_fault  fan3_fault  fan5_fault  fan7_fault  hwmon  name
fan1_input  fan3_input  fan5_input  fan7_input  in1_fault  power1_input
fan1_minfan3_minfan5_minfan7_minin2_fault  subsystem
fan2_fault  fan4_fault  fan6_fault  fan8_fault  in3_fault  temp1_input
fan2_input  fan4_input  fan6_input  fan8_input  in4_fault  temp1_max
[root@tul163p1 ~]#
[root@tul163p1 ~]# ls /sys/class/hwmon/hwmon0/device/
driver  fan2_minfan4_minfan6_minfan8_min   modalias  uevent
fan1_fault  fan3_fault  fan5_fault  fan7_fault  hwmon  name
fan1_input  fan3_input  fan5_input  fan7_input  in1_fault  power1_input
fan1_minfan3_minfan5_minfan7_minin2_fault  subsystem
fan2_fault  fan4_fault  fan6_fault  fan8_fault  in3_fault  temp1_input
fan2_input  fan4_input  fan6_input  fan8_input  in4_fault  temp1_max
[root@tul163p1 ~]#

Signed-off-by: Shivaprasad G Bhat sb...@linux.vnet.ibm.com
Signed-off-by: Neelesh Gupta neele...@linux.vnet.ibm.com
---
  drivers/hwmon/Kconfig  |8 +
  drivers/hwmon/Makefile |1
  drivers/hwmon/ibmpowernv.c |  386 
  3 files changed, 395 insertions(+)
  create mode 100644 drivers/hwmon/ibmpowernv.c

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index bc196f4..3e308fa 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -554,6 +554,14 @@ config SENSORS_IBMPEX
  This driver can also be built as a module.  If so, the module
  will be called ibmpex.
  
+config SENSORS_IBMPOWERNV

+   tristate IBM POWERNV platform sensors
+   depends on PPC_POWERNV
+   default y
+   help
+ If you say yes here you get support for the temperature/fan/power
+ sensors on your platform.
+
  config SENSORS_IIO_HWMON
tristate Hwmon driver that uses channels specified via iio maps
depends on IIO
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index c48f987..199c401 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -71,6 +71,7 @@ obj-$(CONFIG_SENSORS_ULTRA45) += ultra45_env.o
  obj-$(CONFIG_SENSORS_I5K_AMB) += i5k_amb.o
  obj-$(CONFIG_SENSORS_IBMAEM)  += ibmaem.o
  obj-$(CONFIG_SENSORS_IBMPEX)  += ibmpex.o
+obj-$(CONFIG_SENSORS_IBMPOWERNV)+= ibmpowernv.o
  obj-$(CONFIG_SENSORS_IIO_HWMON) += iio_hwmon.o
  obj-$(CONFIG_SENSORS_INA209)  += ina209.o
  obj-$(CONFIG_SENSORS_INA2XX)  += ina2xx.o
diff --git a/drivers/hwmon/ibmpowernv.c b/drivers/hwmon/ibmpowernv.c
new file mode 100644
index 000..e5cffce
--- /dev/null
+++ b/drivers/hwmon/ibmpowernv.c
@@ -0,0 +1,386 @@
+/*
+ * IBM PowerNV platform sensors for temperature/fan/power
+ * Copyright (C) 2014 IBM
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

Please drop the FSF address; it can change, and we don't want to update the
driver each time it does.


+ */
+
+#include linux/init.h
+#include linux/module.h
+#include linux/kernel.h
+#include linux/hwmon.h
+#include linux/hwmon-sysfs.h
+#include linux/of.h
+#include linux/slab.h
+
+#include linux/platform_device.h
+#include asm/opal.h
+#include linux/err.h
+
+#define DRVNAMEibmpowernv
+#define MAX_ATTR_LEN   32
+
+/* Sensor suffix name from DT */
+#define DT_FAULT_ATTR_SUFFIX   faulted
+#define DT_DATA_ATTR_SUFFIXdata
+#define DT_THRESHOLD_ATTR_SUFFIX   thrs
+
+/* Enumerates all the sensors

[PATCH] powerpc/powernv: hwmon driver for power values, fan rpm and temperature

2014-05-14 Thread Neelesh Gupta
This patch adds basic kernel enablement for reading power values, fan
speed rpm and temperature values on powernv platforms which will
be exported to user space through sysfs interface.

Test results:
-
[root@tul163p1 ~]# sensors
ibmpowernv-isa-
Adapter: ISA adapter
fan1:5294 RPM  (min =0 RPM)
fan2:4945 RPM  (min =0 RPM)
fan3:5831 RPM  (min =0 RPM)
fan4:5212 RPM  (min =0 RPM)
fan5:   0 RPM  (min =0 RPM)
fan6:   0 RPM  (min =0 RPM)
fan7:7472 RPM  (min =0 RPM)
fan8:7920 RPM  (min =0 RPM)
temp1:+39.0°C  (high =  +0.0°C)
power1:  192.00 W  

[root@tul163p1 ~]# 
[root@tul163p1 ~]# ls /sys/devices/platform/ibmpowernv.0/
driver  fan2_minfan4_minfan6_minfan8_min   modalias  uevent
fan1_fault  fan3_fault  fan5_fault  fan7_fault  hwmon  name
fan1_input  fan3_input  fan5_input  fan7_input  in1_fault  power1_input
fan1_minfan3_minfan5_minfan7_minin2_fault  subsystem
fan2_fault  fan4_fault  fan6_fault  fan8_fault  in3_fault  temp1_input
fan2_input  fan4_input  fan6_input  fan8_input  in4_fault  temp1_max
[root@tul163p1 ~]# 
[root@tul163p1 ~]# ls /sys/class/hwmon/hwmon0/device/
driver  fan2_minfan4_minfan6_minfan8_min   modalias  uevent
fan1_fault  fan3_fault  fan5_fault  fan7_fault  hwmon  name
fan1_input  fan3_input  fan5_input  fan7_input  in1_fault  power1_input
fan1_minfan3_minfan5_minfan7_minin2_fault  subsystem
fan2_fault  fan4_fault  fan6_fault  fan8_fault  in3_fault  temp1_input
fan2_input  fan4_input  fan6_input  fan8_input  in4_fault  temp1_max
[root@tul163p1 ~]#

Signed-off-by: Shivaprasad G Bhat sb...@linux.vnet.ibm.com
Signed-off-by: Neelesh Gupta neele...@linux.vnet.ibm.com
---
 drivers/hwmon/Kconfig  |8 +
 drivers/hwmon/Makefile |1 
 drivers/hwmon/ibmpowernv.c |  386 
 3 files changed, 395 insertions(+)
 create mode 100644 drivers/hwmon/ibmpowernv.c

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index bc196f4..3e308fa 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -554,6 +554,14 @@ config SENSORS_IBMPEX
  This driver can also be built as a module.  If so, the module
  will be called ibmpex.
 
+config SENSORS_IBMPOWERNV
+   tristate IBM POWERNV platform sensors
+   depends on PPC_POWERNV
+   default y
+   help
+ If you say yes here you get support for the temperature/fan/power
+ sensors on your platform.
+
 config SENSORS_IIO_HWMON
tristate Hwmon driver that uses channels specified via iio maps
depends on IIO
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index c48f987..199c401 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -71,6 +71,7 @@ obj-$(CONFIG_SENSORS_ULTRA45) += ultra45_env.o
 obj-$(CONFIG_SENSORS_I5K_AMB)  += i5k_amb.o
 obj-$(CONFIG_SENSORS_IBMAEM)   += ibmaem.o
 obj-$(CONFIG_SENSORS_IBMPEX)   += ibmpex.o
+obj-$(CONFIG_SENSORS_IBMPOWERNV)+= ibmpowernv.o
 obj-$(CONFIG_SENSORS_IIO_HWMON) += iio_hwmon.o
 obj-$(CONFIG_SENSORS_INA209)   += ina209.o
 obj-$(CONFIG_SENSORS_INA2XX)   += ina2xx.o
diff --git a/drivers/hwmon/ibmpowernv.c b/drivers/hwmon/ibmpowernv.c
new file mode 100644
index 000..e5cffce
--- /dev/null
+++ b/drivers/hwmon/ibmpowernv.c
@@ -0,0 +1,386 @@
+/*
+ * IBM PowerNV platform sensors for temperature/fan/power
+ * Copyright (C) 2014 IBM
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include linux/init.h
+#include linux/module.h
+#include linux/kernel.h
+#include linux/hwmon.h
+#include linux/hwmon-sysfs.h
+#include linux/of.h
+#include linux/slab.h
+
+#include linux/platform_device.h
+#include asm/opal.h
+#include linux/err.h
+
+#define DRVNAMEibmpowernv
+#define MAX_ATTR_LEN   32
+
+/* Sensor suffix name from DT */
+#define DT_FAULT_ATTR_SUFFIX   faulted
+#define DT_DATA_ATTR_SUFFIXdata
+#define DT_THRESHOLD_ATTR_SUFFIX   thrs
+
+/* Enumerates all the sensors in the POWERNV platform and also index into
+ * 'struct sensor_name'
+ */
+enum sensors {
+   FAN,
+   AMBIENT_TEMP,
+   POWERSUPPLY,
+   POWER,
+   MAX_SENSOR_TYPE,
+};
+
+static struct sensor_name

[PATCH] powerpc/powernv: Infrastructure to support OPAL async completion

2014-03-06 Thread Neelesh Gupta
This patch adds support for notifying the clients of their request
completion. Clients request for the token before making OPAL call
and then wait for the response.

This patch uses messaging infrastructure to pull the data to linux
by registering itself for the message type OPAL_MSG_ASYNC_COMP.

Signed-off-by: Neelesh Gupta neele...@linux.vnet.ibm.com
Signed-off-by: Benjamin Herrenschmidt b...@kernel.crashing.org
---
 arch/powerpc/include/asm/opal.h |   12 +-
 arch/powerpc/platforms/powernv/Makefile |2 
 arch/powerpc/platforms/powernv/opal-async.c |  203 +++
 3 files changed, 215 insertions(+), 2 deletions(-)
 create mode 100644 arch/powerpc/platforms/powernv/opal-async.c

diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index ed82142..90fad59 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -83,6 +83,8 @@ extern int opal_enter_rtas(struct rtas_args *args,
 #define OPAL_INTERNAL_ERROR-11
 #define OPAL_BUSY_EVENT-12
 #define OPAL_HARDWARE_FROZEN   -13
+#define OPAL_WRONG_STATE   -14
+#define OPAL_ASYNC_COMPLETION  -15
 
 /* API Tokens (in r0) */
 #define OPAL_CONSOLE_WRITE 1
@@ -241,7 +243,9 @@ enum OpalPendingState {
 };
 
 enum OpalMessageType {
-   OPAL_MSG_ASYNC_COMP = 0,
+   OPAL_MSG_ASYNC_COMP = 0,/* params[0] = token, params[1] = rc,
+* additional params function-specific
+*/
OPAL_MSG_MEM_ERR,
OPAL_MSG_EPOW,
OPAL_MSG_SHUTDOWN,
@@ -853,6 +857,12 @@ extern void opal_notifier_update_evt(uint64_t evt_mask, 
uint64_t evt_val);
 extern int opal_get_chars(uint32_t vtermno, char *buf, int count);
 extern int opal_put_chars(uint32_t vtermno, const char *buf, int total_len);
 
+extern int __opal_async_get_token(void);
+extern int opal_async_get_token_interruptible(void);
+extern int __opal_async_release_token(int token);
+extern int opal_async_release_token(int token);
+extern int opal_async_wait_response(uint64_t token, struct opal_msg *msg);
+
 extern void hvc_opal_init_early(void);
 
 struct rtc_time;
diff --git a/arch/powerpc/platforms/powernv/Makefile 
b/arch/powerpc/platforms/powernv/Makefile
index 8d767fd..c0f85ea 100644
--- a/arch/powerpc/platforms/powernv/Makefile
+++ b/arch/powerpc/platforms/powernv/Makefile
@@ -1,4 +1,4 @@
-obj-y  += setup.o opal-takeover.o opal-wrappers.o opal.o
+obj-y  += setup.o opal-takeover.o opal-wrappers.o opal.o 
opal-async.o
 obj-y  += opal-rtc.o opal-nvram.o opal-lpc.o opal-flash.o
 obj-y  += rng.o
 
diff --git a/arch/powerpc/platforms/powernv/opal-async.c 
b/arch/powerpc/platforms/powernv/opal-async.c
new file mode 100644
index 000..cd0c135
--- /dev/null
+++ b/arch/powerpc/platforms/powernv/opal-async.c
@@ -0,0 +1,203 @@
+/*
+ * PowerNV OPAL asynchronous completion interfaces
+ *
+ * Copyright 2013 IBM Corp.
+ *
+ * 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.
+ */
+
+#undef DEBUG
+
+#include linux/kernel.h
+#include linux/init.h
+#include linux/slab.h
+#include linux/sched.h
+#include linux/semaphore.h
+#include linux/spinlock.h
+#include linux/wait.h
+#include linux/gfp.h
+#include linux/of.h
+#include asm/opal.h
+
+#define N_ASYNC_COMPLETIONS64
+
+static DECLARE_BITMAP(opal_async_complete_map, N_ASYNC_COMPLETIONS) = {~0UL};
+static DECLARE_BITMAP(opal_async_token_map, N_ASYNC_COMPLETIONS);
+static DECLARE_WAIT_QUEUE_HEAD(opal_async_wait);
+static DEFINE_SPINLOCK(opal_async_comp_lock);
+static struct semaphore opal_async_sem;
+static struct opal_msg *opal_async_responses;
+static unsigned int opal_max_async_tokens;
+
+int __opal_async_get_token(void)
+{
+   unsigned long flags;
+   int token;
+
+   spin_lock_irqsave(opal_async_comp_lock, flags);
+   token = find_first_bit(opal_async_complete_map, opal_max_async_tokens);
+   if (token = opal_max_async_tokens) {
+   token = -EBUSY;
+   goto out;
+   }
+
+   if (__test_and_set_bit(token, opal_async_token_map)) {
+   token = -EBUSY;
+   goto out;
+   }
+
+   __clear_bit(token, opal_async_complete_map);
+
+out:
+   spin_unlock_irqrestore(opal_async_comp_lock, flags);
+   return token;
+}
+
+int opal_async_get_token_interruptible(void)
+{
+   int token;
+
+   /* Wait until a token is available */
+   if (down_interruptible(opal_async_sem))
+   return -ERESTARTSYS;
+
+   token = __opal_async_get_token();
+   if (token  0)
+   up(opal_async_sem);
+
+   return token;
+}
+
+int __opal_async_release_token(int token)
+{
+   unsigned

[PATCH] powerpc/powernv: Enable reading and updating of system parameters

2014-03-06 Thread Neelesh Gupta
This patch enables reading and updating of system parameters through
OPAL call.

Signed-off-by: Neelesh Gupta neele...@linux.vnet.ibm.com
Signed-off-by: Benjamin Herrenschmidt b...@kernel.crashing.org
---
 arch/powerpc/include/asm/opal.h|   14 +
 arch/powerpc/platforms/powernv/Makefile|2 
 arch/powerpc/platforms/powernv/opal-sysparam.c |  290 
 arch/powerpc/platforms/powernv/opal-wrappers.S |2 
 arch/powerpc/platforms/powernv/opal.c  |2 
 5 files changed, 309 insertions(+), 1 deletion(-)
 create mode 100644 arch/powerpc/platforms/powernv/opal-sysparam.c

diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index 90fad59..60b3edc 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -159,6 +159,8 @@ extern int opal_enter_rtas(struct rtas_args *args,
 #define OPAL_GET_MSG   85
 #define OPAL_CHECK_ASYNC_COMPLETION86
 #define OPAL_SYNC_HOST_REBOOT  87
+#define OPAL_GET_PARAM 89
+#define OPAL_SET_PARAM 90
 
 #ifndef __ASSEMBLY__
 
@@ -398,6 +400,13 @@ enum OpalLPCAddressType {
OPAL_LPC_FW = 2,
 };
 
+/* System parameter permission */
+enum OpalSysparamPerm {
+   OPAL_SYSPARAM_READ  = 0x1,
+   OPAL_SYSPARAM_WRITE = 0x2,
+   OPAL_SYSPARAM_RW= (OPAL_SYSPARAM_READ | OPAL_SYSPARAM_WRITE),
+};
+
 struct opal_msg {
uint32_t msg_type;
uint32_t reserved;
@@ -834,6 +843,10 @@ int64_t opal_update_flash(uint64_t blk_list);
 int64_t opal_get_msg(uint64_t buffer, size_t size);
 int64_t opal_check_completion(uint64_t buffer, size_t size, uint64_t token);
 int64_t opal_sync_host_reboot(void);
+int64_t opal_get_param(uint64_t token, uint32_t param_id, uint64_t buffer,
+   size_t length);
+int64_t opal_set_param(uint64_t token, uint32_t param_id, uint64_t buffer,
+   size_t length);
 
 /* Internal functions */
 extern int early_init_dt_scan_opal(unsigned long node, const char *uname, int 
depth, void *data);
@@ -871,6 +884,7 @@ extern void opal_get_rtc_time(struct rtc_time *tm);
 extern unsigned long opal_get_boot_time(void);
 extern void opal_nvram_init(void);
 extern void opal_flash_init(void);
+extern void opal_sys_param_init(void);
 
 extern int opal_machine_check(struct pt_regs *regs);
 
diff --git a/arch/powerpc/platforms/powernv/Makefile 
b/arch/powerpc/platforms/powernv/Makefile
index c0f85ea..e6166d3 100644
--- a/arch/powerpc/platforms/powernv/Makefile
+++ b/arch/powerpc/platforms/powernv/Makefile
@@ -1,5 +1,5 @@
 obj-y  += setup.o opal-takeover.o opal-wrappers.o opal.o 
opal-async.o
-obj-y  += opal-rtc.o opal-nvram.o opal-lpc.o opal-flash.o
+obj-y  += opal-rtc.o opal-nvram.o opal-lpc.o opal-flash.o 
opal-sysparam.o
 obj-y  += rng.o
 
 obj-$(CONFIG_SMP)  += smp.o
diff --git a/arch/powerpc/platforms/powernv/opal-sysparam.c 
b/arch/powerpc/platforms/powernv/opal-sysparam.c
new file mode 100644
index 000..0bd249a
--- /dev/null
+++ b/arch/powerpc/platforms/powernv/opal-sysparam.c
@@ -0,0 +1,290 @@
+/*
+ * PowerNV system parameter code
+ *
+ * Copyright (C) 2013 IBM
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include linux/kobject.h
+#include linux/mutex.h
+#include linux/slab.h
+#include linux/of.h
+#include linux/gfp.h
+#include linux/stat.h
+#include asm/opal.h
+
+#define MAX_PARAM_DATA_LEN 64
+
+static DEFINE_MUTEX(opal_sysparam_mutex);
+static struct kobject *sysparam_kobj;
+static void *param_data_buf;
+
+struct param_attr {
+   struct list_head list;
+   u32 param_id;
+   u32 param_size;
+   struct kobj_attribute kobj_attr;
+};
+
+static int opal_get_sys_param(u32 param_id, u32 length, void *buffer)
+{
+   struct opal_msg msg;
+   int ret, token;
+
+   token = opal_async_get_token_interruptible();
+   if (token  0) {
+   if (token != -ERESTARTSYS)
+   pr_err(%s: Couldn't get the token, returning\n,
+   __func__);
+   ret = token;
+   goto out;
+   }
+
+   ret = opal_get_param(token, param_id, (u64)buffer, length);
+   if (ret

[PATCH 0/2] Enable powernv based platform sensors

2014-03-06 Thread Neelesh Gupta
This patchset contains the enablement code to expose platform sensor data
on powernv platform. First patch fetches the sensor data from the firmware
and second patch being an hwmon driver, enables the sysfs interfaces.

---

Neelesh Gupta (1):
  powerpc/powernv: Enable fetching of platform sensor data

Shivaprasad G Bhat (1):
  powerpc/powernv: hwmon driver for power values, fan rpm and temperature


 arch/powerpc/include/asm/opal.h|4 
 arch/powerpc/platforms/powernv/Makefile|2 
 arch/powerpc/platforms/powernv/opal-sensor.c   |   64 +++
 arch/powerpc/platforms/powernv/opal-wrappers.S |1 
 drivers/hwmon/Kconfig  |8 
 drivers/hwmon/Makefile |1 
 drivers/hwmon/ibmpowernv.c |  529 
 7 files changed, 608 insertions(+), 1 deletion(-)
 create mode 100644 arch/powerpc/platforms/powernv/opal-sensor.c
 create mode 100644 drivers/hwmon/ibmpowernv.c

-- 
Signature

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

[PATCH 1/2] powerpc/powernv: Enable fetching of platform sensor data

2014-03-06 Thread Neelesh Gupta
This patch enables fetching of various platform sensor data through
OPAL and expects a sensor handle from the driver to pass to OPAL.

Signed-off-by: Neelesh Gupta neele...@linux.vnet.ibm.com
Signed-off-by: Benjamin Herrenschmidt b...@kernel.crashing.org
---
 arch/powerpc/include/asm/opal.h|4 ++
 arch/powerpc/platforms/powernv/Makefile|2 -
 arch/powerpc/platforms/powernv/opal-sensor.c   |   64 
 arch/powerpc/platforms/powernv/opal-wrappers.S |1 
 4 files changed, 70 insertions(+), 1 deletion(-)
 create mode 100644 arch/powerpc/platforms/powernv/opal-sensor.c

diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index 60b3edc..a1cc4dd 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -159,6 +159,7 @@ extern int opal_enter_rtas(struct rtas_args *args,
 #define OPAL_GET_MSG   85
 #define OPAL_CHECK_ASYNC_COMPLETION86
 #define OPAL_SYNC_HOST_REBOOT  87
+#define OPAL_SENSOR_READ   88
 #define OPAL_GET_PARAM 89
 #define OPAL_SET_PARAM 90
 
@@ -847,6 +848,8 @@ int64_t opal_get_param(uint64_t token, uint32_t param_id, 
uint64_t buffer,
size_t length);
 int64_t opal_set_param(uint64_t token, uint32_t param_id, uint64_t buffer,
size_t length);
+int64_t opal_sensor_read(uint32_t sensor_hndl, int token,
+   uint32_t *sensor_data);
 
 /* Internal functions */
 extern int early_init_dt_scan_opal(unsigned long node, const char *uname, int 
depth, void *data);
@@ -875,6 +878,7 @@ extern int opal_async_get_token_interruptible(void);
 extern int __opal_async_release_token(int token);
 extern int opal_async_release_token(int token);
 extern int opal_async_wait_response(uint64_t token, struct opal_msg *msg);
+extern int opal_get_sensor_data(u32 sensor_hndl, u32 *sensor_data);
 
 extern void hvc_opal_init_early(void);
 
diff --git a/arch/powerpc/platforms/powernv/Makefile 
b/arch/powerpc/platforms/powernv/Makefile
index e6166d3..00ae938 100644
--- a/arch/powerpc/platforms/powernv/Makefile
+++ b/arch/powerpc/platforms/powernv/Makefile
@@ -1,6 +1,6 @@
 obj-y  += setup.o opal-takeover.o opal-wrappers.o opal.o 
opal-async.o
 obj-y  += opal-rtc.o opal-nvram.o opal-lpc.o opal-flash.o 
opal-sysparam.o
-obj-y  += rng.o
+obj-y  += rng.o opal-sensor.o
 
 obj-$(CONFIG_SMP)  += smp.o
 obj-$(CONFIG_PCI)  += pci.o pci-p5ioc2.o pci-ioda.o
diff --git a/arch/powerpc/platforms/powernv/opal-sensor.c 
b/arch/powerpc/platforms/powernv/opal-sensor.c
new file mode 100644
index 000..663cc9c
--- /dev/null
+++ b/arch/powerpc/platforms/powernv/opal-sensor.c
@@ -0,0 +1,64 @@
+/*
+ * PowerNV sensor code
+ *
+ * Copyright (C) 2013 IBM
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include linux/delay.h
+#include linux/mutex.h
+#include asm/opal.h
+
+static DEFINE_MUTEX(opal_sensor_mutex);
+
+/*
+ * This will return sensor information to driver based on the requested sensor
+ * handle. A handle is an opaque id for the powernv, read by the driver from 
the
+ * device tree..
+ */
+int opal_get_sensor_data(u32 sensor_hndl, u32 *sensor_data)
+{
+   int ret, token;
+   struct opal_msg msg;
+
+   token = opal_async_get_token_interruptible();
+   if (token  0) {
+   pr_err(%s: Couldn't get the token, returning\n, __func__);
+   ret = token;
+   goto out;
+   }
+
+   mutex_lock(opal_sensor_mutex);
+   ret = opal_sensor_read(sensor_hndl, token, sensor_data);
+   if (ret != OPAL_ASYNC_COMPLETION)
+   goto out_token;
+
+   ret = opal_async_wait_response(token, msg);
+   if (ret) {
+   pr_err(%s: Failed to wait for the async response, %d\n,
+   __func__, ret);
+   goto out_token;
+   }
+
+   ret = msg.params[1];
+
+out_token:
+   mutex_unlock(opal_sensor_mutex);
+   opal_async_release_token(token);
+out:
+   return ret;
+}
+EXPORT_SYMBOL_GPL(opal_get_sensor_data);
diff --git a/arch/powerpc/platforms/powernv/opal-wrappers.S 
b/arch/powerpc/platforms/powernv/opal-wrappers.S
index

[PATCH 2/2] powerpc/powernv: hwmon driver for power values, fan rpm and temperature

2014-03-06 Thread Neelesh Gupta
From: Shivaprasad G Bhat sb...@linux.vnet.ibm.com

This patch adds basic kernel enablement for reading power values, fan
speed rpm and temperature values on powernv platforms which will
be exported to user space through sysfs interface.

Signed-off-by: Shivaprasad G Bhat sb...@linux.vnet.ibm.com
Signed-off-by: Neelesh Gupta neele...@linux.vnet.ibm.com
Signed-off-by: Benjamin Herrenschmidt b...@kernel.crashing.org
---
 drivers/hwmon/Kconfig  |8 +
 drivers/hwmon/Makefile |1 
 drivers/hwmon/ibmpowernv.c |  529 
 3 files changed, 538 insertions(+)
 create mode 100644 drivers/hwmon/ibmpowernv.c

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 5ce43d8..ad4cdcb 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -557,6 +557,14 @@ config SENSORS_IBMPEX
  This driver can also be built as a module.  If so, the module
  will be called ibmpex.
 
+config SENSORS_IBMPOWERNV
+   tristate IBM PowerNv Platform temperature/power/fan sensor
+   depends on PPC_POWERNV
+   default y
+   help
+ If you say yes here you get support for the temperature/fan/power
+ sensors on your platform.
+
 config SENSORS_IIO_HWMON
tristate Hwmon driver that uses channels specified via iio maps
depends on IIO
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index ec7cde0..807e172 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -70,6 +70,7 @@ obj-$(CONFIG_SENSORS_ULTRA45) += ultra45_env.o
 obj-$(CONFIG_SENSORS_I5K_AMB)  += i5k_amb.o
 obj-$(CONFIG_SENSORS_IBMAEM)   += ibmaem.o
 obj-$(CONFIG_SENSORS_IBMPEX)   += ibmpex.o
+obj-$(CONFIG_SENSORS_IBMPOWERNV)+= ibmpowernv.o
 obj-$(CONFIG_SENSORS_IIO_HWMON) += iio_hwmon.o
 obj-$(CONFIG_SENSORS_INA209)   += ina209.o
 obj-$(CONFIG_SENSORS_INA2XX)   += ina2xx.o
diff --git a/drivers/hwmon/ibmpowernv.c b/drivers/hwmon/ibmpowernv.c
new file mode 100644
index 000..b7b1297
--- /dev/null
+++ b/drivers/hwmon/ibmpowernv.c
@@ -0,0 +1,529 @@
+/*
+ * hwmon driver for temperature/power/fan on IBM PowerNV platform
+ * Copyright (C) 2013 IBM
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include linux/init.h
+#include linux/module.h
+#include linux/kernel.h
+#include linux/hwmon.h
+#include linux/hwmon-sysfs.h
+#include linux/of.h
+#include linux/slab.h
+
+#include linux/jiffies.h
+#include linux/platform_device.h
+#include asm/opal.h
+#include linux/err.h
+
+MODULE_DESCRIPTION(IBM PowerNV Platform power/temp/fan sensor hwmon module);
+MODULE_LICENSE(GPL);
+
+#define MAX_ATTR_LENGTH32
+
+/* Device tree sensor name prefixes. The device tree has the names in the
+ * format cooling-fan#2-faulted where the cooling-fan is the sensor type,
+ * 2 is the sensor count, and faulted is the sensor data attribute type.
+ */
+#define DT_FAULT_ATTR_SUFFIX   faulted
+#define DT_DATA_ATTR_SUFFIXdata
+#define DT_THRESHOLD_ATTR_SUFFIX   thrs
+
+enum sensors {
+   FAN,
+   TEMPERATURE,
+   POWERSUPPLY,
+   POWER,
+   MAX_SENSOR_TYPE,
+};
+
+enum attributes {
+   INPUT,
+   MINIMUM,
+   MAXIMUM,
+   FAULT,
+   MAX_ATTR_TYPES
+};
+
+static struct sensor_name {
+   char *name;
+   char *compaible;
+} sensor_names[] = {
+   {fan-sensor, ibm,opal-sensor-cooling-fan},
+   {amb-temp-sensor, ibm,opal-sensor-amb-temp},
+   {power-sensor, ibm,opal-sensor-power-supply},
+   {power, ibm,opal-sensor-power}
+};
+
+static const char * const attribute_type_table[] = {
+   input,
+   min,
+   max,
+   fault,
+   NULL
+};
+
+struct pdev_entry {
+   struct list_head list;
+   struct platform_device *pdev;
+   enum sensors type;
+};
+
+static LIST_HEAD(pdev_list);
+
+/* The sensors are categorised on type.
+ *
+ * The sensors of same type are categorised under a common platform device.
+ * So, The pdev is shared by all sensors of same type.
+ * Ex : temp1_input, temp1_max, temp2_input,temp2_max all share same platform
+ * device.
+ *
+ * sensor_data is the Platform device specific data.
+ * There is one hwmon_device instance for all the sensors of same type.
+ * This also holds the list of all sensors with same type