Skip to contentSkip to conversation

hwmon: occ: Add I2C SCOM transport implementation

RFC PATCH NAK [email protected] 2 participants 2 messages Nov 29, 2016 – Dec 13, 2016 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

RFC PATCH v6 4/9 hwmon: occ: Add I2C SCOM transport implementation

From: "Edward A. James" <[email protected]>

The BMC queries the OCC on POWER8 chips with SCOMs over I2C.

---
 drivers/hwmon/occ/occ_scom_i2c.c | 68 ++++++++++++++++++++++++++++++++++++++++
 drivers/hwmon/occ/occ_scom_i2c.h | 20 ++++++++++++
 2 files changed, 88 insertions(+)
 create mode 100644 drivers/hwmon/occ/occ_scom_i2c.c
 create mode 100644 drivers/hwmon/occ/occ_scom_i2c.h
drivers/hwmon/occ/occ_scom_i2c.c new file +68 -0
new file mode 100644
index 0000000..e1bb363
@@ -0,0 +1,68 @@
+/*
+ * occ_i2c.c - hwmon OCC driver
+ *
+ * This file contains the i2c layer for accessing the OCC over i2c bus.
+ *
+ * Copyright 2016 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.
+ *
+ * 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/i2c.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+
+#include "scom.h"
+#include "occ_scom_i2c.h"
+
+#define OCC_I2C_NAME   "occ-p8-i2c"
+
+int occ_i2c_getscom(void *bus, u32 address, u8 *data, size_t offset)
+{
+       ssize_t rc;
+       u64 buf;
+       struct i2c_client *client = bus;
+
+       rc = i2c_master_send(client, (const char *)&address, sizeof(u32));
+       if (rc != sizeof(u32))
+               return -SCOM_WRITE_ERROR;
+
+       rc = i2c_master_recv(client, (char *)&buf, sizeof(u64));
+       if (rc != sizeof(u64))
+               return -SCOM_READ_ERROR;
+
+       *((u64 *)&data[offset]) = be64_to_cpu(buf);
+
+       return 0;
+}
+EXPORT_SYMBOL(occ_i2c_getscom);
+
+int occ_i2c_putscom(void *bus, u32 address, u32 data0, u32 data1)
+{
+       u32 buf[3];
+       ssize_t rc;
+       struct i2c_client *client = bus;
+
+       buf[0] = address;
+       buf[1] = data1;
+       buf[2] = data0;
+
+       rc = i2c_master_send(client, (const char *)buf, sizeof(u32) * 3);
+       if (rc != sizeof(u32) * 3)
+               return -SCOM_WRITE_ERROR;
+
+       return 0;
+}
+EXPORT_SYMBOL(occ_i2c_putscom);
+
+MODULE_AUTHOR("Eddie James <[email protected]>");
+MODULE_DESCRIPTION("I2C OCC SCOM transport");
+MODULE_LICENSE("GPL");
drivers/hwmon/occ/occ_scom_i2c.h new file +20 -0
new file mode 100644
index 0000000..92225f4
@@ -0,0 +1,20 @@
+/*
+ * occ_i2c.c - hwmon OCC driver
+ *
+ * This file contains the i2c layer for accessing the OCC over i2c bus.
+ *
+ * Copyright 2016 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.
+ *
+ * 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.
+ */
+
+int occ_i2c_getscom(void *bus, u32 address, u8 *data, size_t offset);
+int occ_i2c_putscom(void *bus, u32 address, u32 data0, u32 data1);
Signature · 1 line
1.9.1
#1 lore raw
Quoted 50 lines · On Tue, 2016-11-29 at 17:03 -0600, [email protected] wrote:
Quoted 1 line

From: "Edward A. James" <[email protected]>

The BMC queries the OCC on POWER8 chips with SCOMs over I2C.

Quoted 1 line

---
 drivers/hwmon/occ/occ_scom_i2c.c | 68 ++++++++++++++++++++++++++++++++++++++++ drivers/hwmon/occ/occ_scom_i2c.h | 20 ++++++++++++

 2 files changed, 88 insertions(+)

 create mode 100644 drivers/hwmon/occ/occ_scom_i2c.c create mode 100644 drivers/hwmon/occ/occ_scom_i2c.h

drivers/hwmon/occ/occ_scom_i2c.c new file +32 -0
new file mode 100644
index 0000000..e1bb363
@@ -0,0 +1,68 @@
+/*
+ * occ_i2c.c - hwmon OCC driver
+ *
+ * This file contains the i2c layer for accessing the OCC over i2c bus.
+ *
+ * Copyright 2016 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.
+ *
+ * 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/i2c.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+
+#include "scom.h"
+#include "occ_scom_i2c.h"
+
+#define OCC_I2C_NAME   "occ-p8-i2c"
+
+int occ_i2c_getscom(void *bus, u32 address, u8 *data, size_t offset)
+{
+       ssize_t rc;
+       u64 buf;
+       struct i2c_client *client = bus;

drivers/hwmon/occ/occ_scom_i2c.c line 42

Quoted 10 lines
drivers/hwmon/occ/occ_scom_i2c.c new file +10 -0
+
+       rc = i2c_master_send(client, (const char *)&address, sizeof(u32));
+       if (rc != sizeof(u32))
+               return -SCOM_WRITE_ERROR;
+
+       rc = i2c_master_recv(client, (char *)&buf, sizeof(u64));
+       if (rc != sizeof(u64))
+               return -SCOM_READ_ERROR;
+
+       *((u64 *)&data[offset]) = be64_to_cpu(buf);

See the comments in 2/9 regarding changing the interface.

Quoted 41 lines
drivers/hwmon/occ/occ_scom_i2c.c new file +23 -0
+
+       return 0;
+}
+EXPORT_SYMBOL(occ_i2c_getscom);
+
+int occ_i2c_putscom(void *bus, u32 address, u32 data0, u32 data1)
+{
+       u32 buf[3];
+       ssize_t rc;
+       struct i2c_client *client = bus;
+
+       buf[0] = address;
+       buf[1] = data1;
+       buf[2] = data0;
+
+       rc = i2c_master_send(client, (const char *)buf, sizeof(u32) * 3);
+       if (rc != sizeof(u32) * 3)
+               return -SCOM_WRITE_ERROR;
+
+       return 0;
+}
+EXPORT_SYMBOL(occ_i2c_putscom);
+
Quoted 1 line

+MODULE_AUTHOR("Eddie James <[email protected]>");

drivers/hwmon/occ/occ_scom_i2c.c new file +2 -0
+MODULE_DESCRIPTION("I2C OCC SCOM transport");
+MODULE_LICENSE("GPL");
drivers/hwmon/occ/occ_scom_i2c.h new file +9 -0
new file mode 100644
index 0000000..92225f4
@@ -0,0 +1,20 @@
+/*
+ * occ_i2c.c - hwmon OCC driver
+ *
+ * This file contains the i2c layer for accessing the OCC over i2c bus.
+ *
+ * Copyright 2016 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

drivers/hwmon/occ/occ_scom_i2c.h line 19

Quoted 10 lines
drivers/hwmon/occ/occ_scom_i2c.h new file +10 -0
+ * 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.
+ */
+
+int occ_i2c_getscom(void *bus, u32 address, u8 *data, size_t offset);

+int occ_i2c_putscom(void *bus, u32 address, u32 data0, u32 data1);