Skip to content

Commit 5b5513b

Browse files
Eddie Jamesgroeck
authored andcommitted
hwmon: Add On-Chip Controller (OCC) hwmon driver
The OCC is a device embedded on a POWER processor that collects and aggregates sensor data from the processor and system. The OCC can provide the raw sensor data as well as perform thermal and power management on the system. This driver provides a hwmon interface to the OCC from a service processor (e.g. a BMC). The driver supports both POWER8 and POWER9 OCCs. Communications with the POWER8 OCC are established over standard I2C bus. The driver communicates with the POWER9 OCC through the FSI-based OCC driver, which handles the lower-level communication details. This patch lays out the structure of the OCC hwmon driver. There are two platform drivers, one each for P8 and P9 OCCs. These are probed through the I2C tree and the FSI-based OCC driver, respectively. The patch also defines the first common structures and methods between the two OCC versions. Signed-off-by: Eddie James <eajames@linux.ibm.com> [groeck: Fix up SPDX license identifier] Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent c0c9872 commit 5b5513b

File tree

8 files changed

+242
-0
lines changed

8 files changed

+242
-0
lines changed

drivers/hwmon/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,6 +1293,8 @@ config SENSORS_NSA320
12931293
This driver can also be built as a module. If so, the module
12941294
will be called nsa320-hwmon.
12951295

1296+
source "drivers/hwmon/occ/Kconfig"
1297+
12961298
config SENSORS_PCF8591
12971299
tristate "Philips PCF8591 ADC/DAC"
12981300
depends on I2C

drivers/hwmon/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ obj-$(CONFIG_SENSORS_WM831X) += wm831x-hwmon.o
178178
obj-$(CONFIG_SENSORS_WM8350) += wm8350-hwmon.o
179179
obj-$(CONFIG_SENSORS_XGENE) += xgene-hwmon.o
180180

181+
obj-$(CONFIG_SENSORS_OCC) += occ/
181182
obj-$(CONFIG_PMBUS) += pmbus/
182183

183184
ccflags-$(CONFIG_HWMON_DEBUG_CHIP) := -DDEBUG

drivers/hwmon/occ/Kconfig

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#
2+
# On-Chip Controller configuration
3+
#
4+
5+
config SENSORS_OCC_P8_I2C
6+
tristate "POWER8 OCC through I2C"
7+
depends on I2C
8+
select SENSORS_OCC
9+
help
10+
This option enables support for monitoring sensors provided by the
11+
On-Chip Controller (OCC) on a POWER8 processor. Communications with
12+
the OCC are established through I2C bus.
13+
14+
This driver can also be built as a module. If so, the module will be
15+
called occ-p8-hwmon.
16+
17+
config SENSORS_OCC_P9_SBE
18+
tristate "POWER9 OCC through SBE"
19+
depends on FSI_OCC
20+
select SENSORS_OCC
21+
help
22+
This option enables support for monitoring sensors provided by the
23+
On-Chip Controller (OCC) on a POWER9 processor. Communications with
24+
the OCC are established through SBE fifo on an FSI bus.
25+
26+
This driver can also be built as a module. If so, the module will be
27+
called occ-p9-hwmon.
28+
29+
config SENSORS_OCC
30+
bool "POWER On-Chip Controller"
31+
depends on SENSORS_OCC_P8_I2C || SENSORS_OCC_P9_SBE

drivers/hwmon/occ/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
occ-p8-hwmon-objs := common.o p8_i2c.o
2+
occ-p9-hwmon-objs := common.o p9_sbe.o
3+
4+
obj-$(CONFIG_SENSORS_OCC_P8_I2C) += occ-p8-hwmon.o
5+
obj-$(CONFIG_SENSORS_OCC_P9_SBE) += occ-p9-hwmon.o

drivers/hwmon/occ/common.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include <linux/device.h>
4+
5+
#include "common.h"
6+
7+
static int occ_poll(struct occ *occ)
8+
{
9+
u16 checksum = occ->poll_cmd_data + 1;
10+
u8 cmd[8];
11+
12+
/* big endian */
13+
cmd[0] = 0; /* sequence number */
14+
cmd[1] = 0; /* cmd type */
15+
cmd[2] = 0; /* data length msb */
16+
cmd[3] = 1; /* data length lsb */
17+
cmd[4] = occ->poll_cmd_data; /* data */
18+
cmd[5] = checksum >> 8; /* checksum msb */
19+
cmd[6] = checksum & 0xFF; /* checksum lsb */
20+
cmd[7] = 0;
21+
22+
return occ->send_cmd(occ, cmd);
23+
}
24+
25+
int occ_setup(struct occ *occ, const char *name)
26+
{
27+
int rc;
28+
29+
rc = occ_poll(occ);
30+
if (rc == -ESHUTDOWN) {
31+
dev_info(occ->bus_dev, "host is not ready\n");
32+
return rc;
33+
} else if (rc < 0) {
34+
dev_err(occ->bus_dev, "failed to get OCC poll response: %d\n",
35+
rc);
36+
return rc;
37+
}
38+
39+
return 0;
40+
}

drivers/hwmon/occ/common.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
#ifndef OCC_COMMON_H
4+
#define OCC_COMMON_H
5+
6+
struct device;
7+
8+
#define OCC_RESP_DATA_BYTES 4089
9+
10+
/*
11+
* Same response format for all OCC versions.
12+
* Allocate the largest possible response.
13+
*/
14+
struct occ_response {
15+
u8 seq_no;
16+
u8 cmd_type;
17+
u8 return_status;
18+
__be16 data_length;
19+
u8 data[OCC_RESP_DATA_BYTES];
20+
__be16 checksum;
21+
} __packed;
22+
23+
struct occ {
24+
struct device *bus_dev;
25+
26+
struct occ_response resp;
27+
28+
u8 poll_cmd_data; /* to perform OCC poll command */
29+
int (*send_cmd)(struct occ *occ, u8 *cmd);
30+
};
31+
32+
int occ_setup(struct occ *occ, const char *name);
33+
34+
#endif /* OCC_COMMON_H */

drivers/hwmon/occ/p8_i2c.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include <linux/device.h>
4+
#include <linux/errno.h>
5+
#include <linux/i2c.h>
6+
#include <linux/module.h>
7+
8+
#include "common.h"
9+
10+
struct p8_i2c_occ {
11+
struct occ occ;
12+
struct i2c_client *client;
13+
};
14+
15+
#define to_p8_i2c_occ(x) container_of((x), struct p8_i2c_occ, occ)
16+
17+
static int p8_i2c_occ_send_cmd(struct occ *occ, u8 *cmd)
18+
{
19+
return -EOPNOTSUPP;
20+
}
21+
22+
static int p8_i2c_occ_probe(struct i2c_client *client,
23+
const struct i2c_device_id *id)
24+
{
25+
struct occ *occ;
26+
struct p8_i2c_occ *ctx = devm_kzalloc(&client->dev, sizeof(*ctx),
27+
GFP_KERNEL);
28+
if (!ctx)
29+
return -ENOMEM;
30+
31+
ctx->client = client;
32+
occ = &ctx->occ;
33+
occ->bus_dev = &client->dev;
34+
dev_set_drvdata(&client->dev, occ);
35+
36+
occ->poll_cmd_data = 0x10; /* P8 OCC poll data */
37+
occ->send_cmd = p8_i2c_occ_send_cmd;
38+
39+
return occ_setup(occ, "p8_occ");
40+
}
41+
42+
static const struct of_device_id p8_i2c_occ_of_match[] = {
43+
{ .compatible = "ibm,p8-occ-hwmon" },
44+
{}
45+
};
46+
MODULE_DEVICE_TABLE(of, p8_i2c_occ_of_match);
47+
48+
static struct i2c_driver p8_i2c_occ_driver = {
49+
.class = I2C_CLASS_HWMON,
50+
.driver = {
51+
.name = "occ-hwmon",
52+
.of_match_table = p8_i2c_occ_of_match,
53+
},
54+
.probe = p8_i2c_occ_probe,
55+
};
56+
57+
module_i2c_driver(p8_i2c_occ_driver);
58+
59+
MODULE_AUTHOR("Eddie James <eajames@linux.ibm.com>");
60+
MODULE_DESCRIPTION("BMC P8 OCC hwmon driver");
61+
MODULE_LICENSE("GPL");

drivers/hwmon/occ/p9_sbe.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include <linux/device.h>
4+
#include <linux/errno.h>
5+
#include <linux/module.h>
6+
#include <linux/platform_device.h>
7+
8+
#include "common.h"
9+
10+
struct p9_sbe_occ {
11+
struct occ occ;
12+
struct device *sbe;
13+
};
14+
15+
#define to_p9_sbe_occ(x) container_of((x), struct p9_sbe_occ, occ)
16+
17+
static int p9_sbe_occ_send_cmd(struct occ *occ, u8 *cmd)
18+
{
19+
return -EOPNOTSUPP;
20+
}
21+
22+
static int p9_sbe_occ_probe(struct platform_device *pdev)
23+
{
24+
int rc;
25+
struct occ *occ;
26+
struct p9_sbe_occ *ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx),
27+
GFP_KERNEL);
28+
if (!ctx)
29+
return -ENOMEM;
30+
31+
ctx->sbe = pdev->dev.parent;
32+
occ = &ctx->occ;
33+
occ->bus_dev = &pdev->dev;
34+
platform_set_drvdata(pdev, occ);
35+
36+
occ->poll_cmd_data = 0x20; /* P9 OCC poll data */
37+
occ->send_cmd = p9_sbe_occ_send_cmd;
38+
39+
rc = occ_setup(occ, "p9_occ");
40+
if (rc == -ESHUTDOWN)
41+
rc = -ENODEV; /* Host is shutdown, don't spew errors */
42+
43+
return rc;
44+
}
45+
46+
static int p9_sbe_occ_remove(struct platform_device *pdev)
47+
{
48+
struct occ *occ = platform_get_drvdata(pdev);
49+
struct p9_sbe_occ *ctx = to_p9_sbe_occ(occ);
50+
51+
ctx->sbe = NULL;
52+
53+
return 0;
54+
}
55+
56+
static struct platform_driver p9_sbe_occ_driver = {
57+
.driver = {
58+
.name = "occ-hwmon",
59+
},
60+
.probe = p9_sbe_occ_probe,
61+
.remove = p9_sbe_occ_remove,
62+
};
63+
64+
module_platform_driver(p9_sbe_occ_driver);
65+
66+
MODULE_AUTHOR("Eddie James <eajames@linux.ibm.com>");
67+
MODULE_DESCRIPTION("BMC P9 OCC hwmon driver");
68+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)