Resguardo inicial

This commit is contained in:
lastdragon
2026-09-06 12:53:21 -06:00
parent 662efe3c2a
commit ad2088d178
94853 changed files with 43200404 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
# SPDX-License-Identifier: GPL-2.0-only
#
# On-Chip Controller configuration
#
config SENSORS_OCC_P8_I2C
tristate "POWER8 OCC through I2C"
depends on I2C
select SENSORS_OCC
help
This option enables support for monitoring sensors provided by the
On-Chip Controller (OCC) on a POWER8 processor. However, this driver
can only run on a baseboard management controller (BMC) connected to
the P8, not the POWER processor itself. Communications with the OCC are
established through I2C bus.
This driver can also be built as a module. If so, the module will be
called occ-p8-hwmon.
config SENSORS_OCC_P9_SBE
tristate "POWER9 OCC through SBE"
depends on FSI_OCC
select SENSORS_OCC
help
This option enables support for monitoring sensors provided by the
On-Chip Controller (OCC) on a POWER9 processor. However, this driver
can only run on a baseboard management controller (BMC) connected to
the P9, not the POWER processor itself. Communications with the OCC are
established through SBE fifo on an FSI bus.
This driver can also be built as a module. If so, the module will be
called occ-p9-hwmon.
config SENSORS_OCC
tristate
+8
View File
@@ -0,0 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only
occ-hwmon-common-objs := common.o sysfs.o
occ-p8-hwmon-objs := p8_i2c.o
occ-p9-hwmon-objs := p9_sbe.o
obj-$(CONFIG_SENSORS_OCC) += occ-hwmon-common.o
obj-$(CONFIG_SENSORS_OCC_P8_I2C) += occ-p8-hwmon.o
obj-$(CONFIG_SENSORS_OCC_P9_SBE) += occ-p9-hwmon.o
File diff suppressed because it is too large Load Diff
+137
View File
@@ -0,0 +1,137 @@
/* SPDX-License-Identifier: GPL-2.0+ */
/* Copyright IBM Corp 2019 */
#ifndef OCC_COMMON_H
#define OCC_COMMON_H
#include <linux/hwmon-sysfs.h>
#include <linux/mutex.h>
#include <linux/sysfs.h>
struct device;
#define OCC_RESP_DATA_BYTES 4089
/*
* Same response format for all OCC versions.
* Allocate the largest possible response.
*/
struct occ_response {
u8 seq_no;
u8 cmd_type;
u8 return_status;
__be16 data_length;
u8 data[OCC_RESP_DATA_BYTES];
__be16 checksum;
} __packed;
struct occ_sensor_data_block_header {
u8 eye_catcher[4];
u8 reserved;
u8 sensor_format;
u8 sensor_length;
u8 num_sensors;
} __packed;
struct occ_sensor_data_block {
struct occ_sensor_data_block_header header;
u32 data;
} __packed;
struct occ_poll_response_header {
u8 status;
u8 ext_status;
u8 occs_present;
u8 config_data;
u8 occ_state;
u8 mode;
u8 ips_status;
u8 error_log_id;
__be32 error_log_start_address;
__be16 error_log_length;
u16 reserved;
u8 occ_code_level[16];
u8 eye_catcher[6];
u8 num_sensor_data_blocks;
u8 sensor_data_block_header_version;
} __packed;
struct occ_poll_response {
struct occ_poll_response_header header;
struct occ_sensor_data_block block;
} __packed;
struct occ_sensor {
u8 num_sensors;
u8 version;
void *data; /* pointer to sensor data start within response */
};
/*
* OCC only provides one sensor data block of each type, but any number of
* sensors within that block.
*/
struct occ_sensors {
struct occ_sensor temp;
struct occ_sensor freq;
struct occ_sensor power;
struct occ_sensor caps;
struct occ_sensor extended;
};
/*
* Use our own attribute struct so we can dynamically allocate space for the
* name.
*/
struct occ_attribute {
char name[32];
struct sensor_device_attribute_2 sensor;
};
struct occ {
struct device *bus_dev;
struct occ_response resp;
struct occ_sensors sensors;
int powr_sample_time_us; /* average power sample time */
u8 poll_cmd_data; /* to perform OCC poll command */
int (*send_cmd)(struct occ *occ, u8 *cmd, size_t len, void *resp,
size_t resp_len);
unsigned long next_update;
struct mutex lock; /* lock OCC access */
struct mutex hwmon_lock; /* serialize hwmon registration/removal */
struct device *hwmon;
struct occ_attribute *attrs;
struct attribute_group group;
const struct attribute_group *groups[2];
bool active;
int error; /* final transfer error after retry */
int last_error; /* latest transfer error */
unsigned int error_count; /* number of xfr errors observed */
unsigned long last_safe; /* time OCC entered "safe" state */
/*
* Store the previous state data for comparison in order to notify
* sysfs readers of state changes.
*/
int prev_error;
u8 prev_stat;
u8 prev_ext_stat;
u8 prev_occs_present;
u8 prev_ips_status;
u8 prev_mode;
};
int occ_active(struct occ *occ, bool active);
int occ_setup(struct occ *occ);
int occ_setup_sysfs(struct occ *occ);
void occ_shutdown(struct occ *occ);
void occ_shutdown_sysfs(struct occ *occ);
void occ_sysfs_poll_done(struct occ *occ);
int occ_update_response(struct occ *occ);
#endif /* OCC_COMMON_H */
+256
View File
@@ -0,0 +1,256 @@
// SPDX-License-Identifier: GPL-2.0+
// Copyright IBM Corp 2019
#include <linux/device.h>
#include <linux/errno.h>
#include <linux/fsi-occ.h>
#include <linux/i2c.h>
#include <linux/jiffies.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/unaligned.h>
#include "common.h"
#define OCC_TIMEOUT_MS 1000
#define OCC_CMD_IN_PRG_WAIT_MS 50
/* OCB (on-chip control bridge - interface to OCC) registers */
#define OCB_DATA1 0x6B035
#define OCB_ADDR 0x6B070
#define OCB_DATA3 0x6B075
/* OCC SRAM address space */
#define OCC_SRAM_ADDR_CMD 0xFFFF6000
#define OCC_SRAM_ADDR_RESP 0xFFFF7000
#define OCC_DATA_ATTN 0x20010000
struct p8_i2c_occ {
struct occ occ;
struct i2c_client *client;
};
#define to_p8_i2c_occ(x) container_of((x), struct p8_i2c_occ, occ)
static int p8_i2c_occ_getscom(struct i2c_client *client, u32 address, u8 *data)
{
ssize_t rc;
__be64 buf;
struct i2c_msg msgs[2];
/* p8 i2c slave requires shift */
address <<= 1;
msgs[0].addr = client->addr;
msgs[0].flags = client->flags & I2C_M_TEN;
msgs[0].len = sizeof(u32);
/* address is a scom address; bus-endian */
msgs[0].buf = (char *)&address;
/* data from OCC is big-endian */
msgs[1].addr = client->addr;
msgs[1].flags = (client->flags & I2C_M_TEN) | I2C_M_RD;
msgs[1].len = sizeof(u64);
msgs[1].buf = (char *)&buf;
rc = i2c_transfer(client->adapter, msgs, 2);
if (rc < 0)
return rc;
*(u64 *)data = be64_to_cpu(buf);
return 0;
}
static int p8_i2c_occ_putscom(struct i2c_client *client, u32 address, u8 *data)
{
u32 buf[3];
ssize_t rc;
/* p8 i2c slave requires shift */
address <<= 1;
/* address is bus-endian; data passed through from user as-is */
buf[0] = address;
memcpy(&buf[1], &data[4], sizeof(u32));
memcpy(&buf[2], data, sizeof(u32));
rc = i2c_master_send(client, (const char *)buf, sizeof(buf));
if (rc < 0)
return rc;
else if (rc != sizeof(buf))
return -EIO;
return 0;
}
static int p8_i2c_occ_putscom_u32(struct i2c_client *client, u32 address,
u32 data0, u32 data1)
{
u8 buf[8];
memcpy(buf, &data0, 4);
memcpy(buf + 4, &data1, 4);
return p8_i2c_occ_putscom(client, address, buf);
}
static int p8_i2c_occ_putscom_be(struct i2c_client *client, u32 address,
u8 *data, size_t len)
{
__be32 data0 = 0, data1 = 0;
memcpy(&data0, data, min_t(size_t, len, 4));
if (len > 4) {
len -= 4;
memcpy(&data1, data + 4, min_t(size_t, len, 4));
}
return p8_i2c_occ_putscom_u32(client, address, be32_to_cpu(data0),
be32_to_cpu(data1));
}
static int p8_i2c_occ_send_cmd(struct occ *occ, u8 *cmd, size_t len,
void *resp, size_t resp_len)
{
int i, rc;
unsigned long start;
u16 data_length;
const unsigned long timeout = msecs_to_jiffies(OCC_TIMEOUT_MS);
const long wait_time = msecs_to_jiffies(OCC_CMD_IN_PRG_WAIT_MS);
struct p8_i2c_occ *ctx = to_p8_i2c_occ(occ);
struct i2c_client *client = ctx->client;
struct occ_response *or = (struct occ_response *)resp;
start = jiffies;
/* set sram address for command */
rc = p8_i2c_occ_putscom_u32(client, OCB_ADDR, OCC_SRAM_ADDR_CMD, 0);
if (rc)
return rc;
/* write command (expected to already be BE), we need bus-endian... */
rc = p8_i2c_occ_putscom_be(client, OCB_DATA3, cmd, len);
if (rc)
return rc;
/* trigger OCC attention */
rc = p8_i2c_occ_putscom_u32(client, OCB_DATA1, OCC_DATA_ATTN, 0);
if (rc)
return rc;
do {
/* set sram address for response */
rc = p8_i2c_occ_putscom_u32(client, OCB_ADDR,
OCC_SRAM_ADDR_RESP, 0);
if (rc)
return rc;
rc = p8_i2c_occ_getscom(client, OCB_DATA3, (u8 *)resp);
if (rc)
return rc;
/* wait for OCC */
if (or->return_status == OCC_RESP_CMD_IN_PRG) {
rc = -EALREADY;
if (time_after(jiffies, start + timeout))
break;
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(wait_time);
}
} while (rc);
/* check the OCC response */
switch (or->return_status) {
case OCC_RESP_CMD_IN_PRG:
rc = -ETIMEDOUT;
break;
case OCC_RESP_SUCCESS:
rc = 0;
break;
case OCC_RESP_CMD_INVAL:
case OCC_RESP_CMD_LEN_INVAL:
case OCC_RESP_DATA_INVAL:
case OCC_RESP_CHKSUM_ERR:
rc = -EINVAL;
break;
case OCC_RESP_INT_ERR:
case OCC_RESP_BAD_STATE:
case OCC_RESP_CRIT_EXCEPT:
case OCC_RESP_CRIT_INIT:
case OCC_RESP_CRIT_WATCHDOG:
case OCC_RESP_CRIT_OCB:
case OCC_RESP_CRIT_HW:
rc = -EREMOTEIO;
break;
default:
rc = -EPROTO;
}
if (rc < 0)
return rc;
data_length = get_unaligned_be16(&or->data_length);
if ((data_length + 7) > resp_len)
return -EMSGSIZE;
/* fetch the rest of the response data */
for (i = 8; i < data_length + 7; i += 8) {
rc = p8_i2c_occ_getscom(client, OCB_DATA3, ((u8 *)resp) + i);
if (rc)
return rc;
}
return 0;
}
static int p8_i2c_occ_probe(struct i2c_client *client)
{
struct occ *occ;
struct p8_i2c_occ *ctx = devm_kzalloc(&client->dev, sizeof(*ctx),
GFP_KERNEL);
if (!ctx)
return -ENOMEM;
ctx->client = client;
occ = &ctx->occ;
occ->bus_dev = &client->dev;
dev_set_drvdata(&client->dev, occ);
occ->powr_sample_time_us = 250;
occ->poll_cmd_data = 0x10; /* P8 OCC poll data */
occ->send_cmd = p8_i2c_occ_send_cmd;
return occ_setup(occ);
}
static void p8_i2c_occ_remove(struct i2c_client *client)
{
struct occ *occ = dev_get_drvdata(&client->dev);
occ_shutdown(occ);
}
static const struct of_device_id p8_i2c_occ_of_match[] = {
{ .compatible = "ibm,p8-occ-hwmon" },
{}
};
MODULE_DEVICE_TABLE(of, p8_i2c_occ_of_match);
static struct i2c_driver p8_i2c_occ_driver = {
.driver = {
.name = "occ-hwmon",
.of_match_table = p8_i2c_occ_of_match,
},
.probe = p8_i2c_occ_probe,
.remove = p8_i2c_occ_remove,
};
module_i2c_driver(p8_i2c_occ_driver);
MODULE_AUTHOR("Eddie James <eajames@linux.ibm.com>");
MODULE_DESCRIPTION("BMC P8 OCC hwmon driver");
MODULE_LICENSE("GPL");
+202
View File
@@ -0,0 +1,202 @@
// SPDX-License-Identifier: GPL-2.0+
// Copyright IBM Corp 2019
#include <linux/device.h>
#include <linux/errno.h>
#include <linux/slab.h>
#include <linux/fsi-occ.h>
#include <linux/mm.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/platform_device.h>
#include <linux/string.h>
#include <linux/sysfs.h>
#include "common.h"
#define OCC_CHECKSUM_RETRIES 3
struct p9_sbe_occ {
struct occ occ;
bool sbe_error;
void *ffdc;
size_t ffdc_len;
size_t ffdc_size;
struct mutex sbe_error_lock; /* lock access to ffdc data */
struct device *sbe;
};
#define to_p9_sbe_occ(x) container_of((x), struct p9_sbe_occ, occ)
static ssize_t ffdc_read(struct file *filp, struct kobject *kobj,
const struct bin_attribute *battr, char *buf, loff_t pos,
size_t count)
{
ssize_t rc = 0;
struct occ *occ = dev_get_drvdata(kobj_to_dev(kobj));
struct p9_sbe_occ *ctx = to_p9_sbe_occ(occ);
mutex_lock(&ctx->sbe_error_lock);
if (ctx->sbe_error) {
rc = memory_read_from_buffer(buf, count, &pos, ctx->ffdc,
ctx->ffdc_len);
if (pos >= ctx->ffdc_len)
ctx->sbe_error = false;
}
mutex_unlock(&ctx->sbe_error_lock);
return rc;
}
static const BIN_ATTR_RO(ffdc, OCC_MAX_RESP_WORDS * 4);
static bool p9_sbe_occ_save_ffdc(struct p9_sbe_occ *ctx, const void *resp,
size_t resp_len)
{
bool notify = false;
mutex_lock(&ctx->sbe_error_lock);
if (!ctx->sbe_error) {
if (resp_len > ctx->ffdc_size) {
kvfree(ctx->ffdc);
ctx->ffdc = kvmalloc(resp_len, GFP_KERNEL);
if (!ctx->ffdc) {
ctx->ffdc_len = 0;
ctx->ffdc_size = 0;
goto done;
}
ctx->ffdc_size = resp_len;
}
notify = true;
ctx->sbe_error = true;
ctx->ffdc_len = resp_len;
memcpy(ctx->ffdc, resp, resp_len);
}
done:
mutex_unlock(&ctx->sbe_error_lock);
return notify;
}
static int p9_sbe_occ_send_cmd(struct occ *occ, u8 *cmd, size_t len,
void *resp, size_t resp_len)
{
size_t original_resp_len = resp_len;
struct p9_sbe_occ *ctx = to_p9_sbe_occ(occ);
int rc, i;
for (i = 0; i < OCC_CHECKSUM_RETRIES; ++i) {
rc = fsi_occ_submit(ctx->sbe, cmd, len, resp, &resp_len);
if (rc >= 0)
break;
if (resp_len) {
if (p9_sbe_occ_save_ffdc(ctx, resp, resp_len))
sysfs_notify(&occ->bus_dev->kobj, NULL,
bin_attr_ffdc.attr.name);
return rc;
}
if (rc != -EBADE)
return rc;
resp_len = original_resp_len;
}
switch (((struct occ_response *)resp)->return_status) {
case OCC_RESP_CMD_IN_PRG:
rc = -ETIMEDOUT;
break;
case OCC_RESP_SUCCESS:
rc = 0;
break;
case OCC_RESP_CMD_INVAL:
case OCC_RESP_CMD_LEN_INVAL:
case OCC_RESP_DATA_INVAL:
case OCC_RESP_CHKSUM_ERR:
rc = -EINVAL;
break;
case OCC_RESP_INT_ERR:
case OCC_RESP_BAD_STATE:
case OCC_RESP_CRIT_EXCEPT:
case OCC_RESP_CRIT_INIT:
case OCC_RESP_CRIT_WATCHDOG:
case OCC_RESP_CRIT_OCB:
case OCC_RESP_CRIT_HW:
rc = -EREMOTEIO;
break;
default:
rc = -EPROTO;
}
return rc;
}
static int p9_sbe_occ_probe(struct platform_device *pdev)
{
int rc;
struct occ *occ;
struct p9_sbe_occ *ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx),
GFP_KERNEL);
if (!ctx)
return -ENOMEM;
mutex_init(&ctx->sbe_error_lock);
ctx->sbe = pdev->dev.parent;
occ = &ctx->occ;
occ->bus_dev = &pdev->dev;
platform_set_drvdata(pdev, occ);
occ->powr_sample_time_us = 500;
occ->poll_cmd_data = 0x20; /* P9 OCC poll data */
occ->send_cmd = p9_sbe_occ_send_cmd;
rc = occ_setup(occ);
if (rc == -ESHUTDOWN)
rc = -ENODEV; /* Host is shutdown, don't spew errors */
if (!rc) {
rc = device_create_bin_file(occ->bus_dev, &bin_attr_ffdc);
if (rc) {
dev_warn(occ->bus_dev,
"failed to create SBE error ffdc file\n");
rc = 0;
}
}
return rc;
}
static void p9_sbe_occ_remove(struct platform_device *pdev)
{
struct occ *occ = platform_get_drvdata(pdev);
struct p9_sbe_occ *ctx = to_p9_sbe_occ(occ);
device_remove_bin_file(occ->bus_dev, &bin_attr_ffdc);
ctx->sbe = NULL;
occ_shutdown(occ);
kvfree(ctx->ffdc);
}
static const struct of_device_id p9_sbe_occ_of_match[] = {
{ .compatible = "ibm,p9-occ-hwmon" },
{ .compatible = "ibm,p10-occ-hwmon" },
{}
};
MODULE_DEVICE_TABLE(of, p9_sbe_occ_of_match);
static struct platform_driver p9_sbe_occ_driver = {
.driver = {
.name = "occ-hwmon",
.of_match_table = p9_sbe_occ_of_match,
},
.probe = p9_sbe_occ_probe,
.remove = p9_sbe_occ_remove,
};
module_platform_driver(p9_sbe_occ_driver);
MODULE_AUTHOR("Eddie James <eajames@linux.ibm.com>");
MODULE_DESCRIPTION("BMC P9 OCC hwmon driver");
MODULE_LICENSE("GPL");
+257
View File
@@ -0,0 +1,257 @@
// SPDX-License-Identifier: GPL-2.0+
// Copyright IBM Corp 2019
#include <linux/bitops.h>
#include <linux/device.h>
#include <linux/export.h>
#include <linux/hwmon-sysfs.h>
#include <linux/kernel.h>
#include <linux/kstrtox.h>
#include <linux/sysfs.h>
#include "common.h"
/* OCC status register */
#define OCC_STAT_MASTER BIT(7)
/* OCC extended status register */
#define OCC_EXT_STAT_DVFS_OT BIT(7)
#define OCC_EXT_STAT_DVFS_POWER BIT(6)
#define OCC_EXT_STAT_MEM_THROTTLE BIT(5)
#define OCC_EXT_STAT_QUICK_DROP BIT(4)
#define OCC_EXT_STAT_DVFS_VDD BIT(3)
#define OCC_EXT_STAT_GPU_THROTTLE GENMASK(2, 0)
static ssize_t occ_active_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
int rc;
bool active;
struct occ *occ = dev_get_drvdata(dev);
rc = kstrtobool(buf, &active);
if (rc)
return rc;
rc = occ_active(occ, active);
if (rc)
return rc;
return count;
}
static ssize_t occ_sysfs_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
int rc;
int val = 0;
struct occ *occ = dev_get_drvdata(dev);
struct occ_poll_response_header *header;
struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
if (occ->active) {
rc = occ_update_response(occ);
if (rc)
return rc;
header = (struct occ_poll_response_header *)occ->resp.data;
switch (sattr->index) {
case 0:
val = !!(header->status & OCC_STAT_MASTER);
break;
case 1:
val = 1;
break;
case 2:
val = !!(header->ext_status & OCC_EXT_STAT_DVFS_OT);
break;
case 3:
val = !!(header->ext_status & OCC_EXT_STAT_DVFS_POWER);
break;
case 4:
val = !!(header->ext_status &
OCC_EXT_STAT_MEM_THROTTLE);
break;
case 5:
val = !!(header->ext_status & OCC_EXT_STAT_QUICK_DROP);
break;
case 6:
val = header->occ_state;
break;
case 7:
if (header->status & OCC_STAT_MASTER)
val = hweight8(header->occs_present);
else
val = 1;
break;
case 8:
val = header->ips_status;
break;
case 9:
val = header->mode;
break;
case 10:
val = !!(header->ext_status & OCC_EXT_STAT_DVFS_VDD);
break;
case 11:
val = header->ext_status & OCC_EXT_STAT_GPU_THROTTLE;
break;
default:
return -EINVAL;
}
} else {
if (sattr->index == 1)
val = 0;
else if (sattr->index <= 11)
val = -ENODATA;
else
return -EINVAL;
}
return sysfs_emit(buf, "%d\n", val);
}
static ssize_t occ_error_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct occ *occ = dev_get_drvdata(dev);
occ_update_response(occ);
return sysfs_emit(buf, "%d\n", occ->error);
}
static SENSOR_DEVICE_ATTR(occ_master, 0444, occ_sysfs_show, NULL, 0);
static SENSOR_DEVICE_ATTR(occ_active, 0644, occ_sysfs_show, occ_active_store,
1);
static SENSOR_DEVICE_ATTR(occ_dvfs_overtemp, 0444, occ_sysfs_show, NULL, 2);
static SENSOR_DEVICE_ATTR(occ_dvfs_power, 0444, occ_sysfs_show, NULL, 3);
static SENSOR_DEVICE_ATTR(occ_mem_throttle, 0444, occ_sysfs_show, NULL, 4);
static SENSOR_DEVICE_ATTR(occ_quick_pwr_drop, 0444, occ_sysfs_show, NULL, 5);
static SENSOR_DEVICE_ATTR(occ_state, 0444, occ_sysfs_show, NULL, 6);
static SENSOR_DEVICE_ATTR(occs_present, 0444, occ_sysfs_show, NULL, 7);
static SENSOR_DEVICE_ATTR(occ_ips_status, 0444, occ_sysfs_show, NULL, 8);
static SENSOR_DEVICE_ATTR(occ_mode, 0444, occ_sysfs_show, NULL, 9);
static SENSOR_DEVICE_ATTR(occ_dvfs_vdd, 0444, occ_sysfs_show, NULL, 10);
static SENSOR_DEVICE_ATTR(occ_gpu_throttle, 0444, occ_sysfs_show, NULL, 11);
static DEVICE_ATTR_RO(occ_error);
static struct attribute *occ_attributes[] = {
&sensor_dev_attr_occ_master.dev_attr.attr,
&sensor_dev_attr_occ_active.dev_attr.attr,
&sensor_dev_attr_occ_dvfs_overtemp.dev_attr.attr,
&sensor_dev_attr_occ_dvfs_power.dev_attr.attr,
&sensor_dev_attr_occ_mem_throttle.dev_attr.attr,
&sensor_dev_attr_occ_quick_pwr_drop.dev_attr.attr,
&sensor_dev_attr_occ_state.dev_attr.attr,
&sensor_dev_attr_occs_present.dev_attr.attr,
&sensor_dev_attr_occ_ips_status.dev_attr.attr,
&sensor_dev_attr_occ_mode.dev_attr.attr,
&sensor_dev_attr_occ_dvfs_vdd.dev_attr.attr,
&sensor_dev_attr_occ_gpu_throttle.dev_attr.attr,
&dev_attr_occ_error.attr,
NULL
};
static const struct attribute_group occ_sysfs = {
.attrs = occ_attributes,
};
void occ_sysfs_poll_done(struct occ *occ)
{
const char *name;
struct occ_poll_response_header *header =
(struct occ_poll_response_header *)occ->resp.data;
/*
* On the first poll response, we haven't yet created the sysfs
* attributes, so don't make any notify calls.
*/
if (!occ->active)
goto done;
if ((header->status & OCC_STAT_MASTER) !=
(occ->prev_stat & OCC_STAT_MASTER)) {
name = sensor_dev_attr_occ_master.dev_attr.attr.name;
sysfs_notify(&occ->bus_dev->kobj, NULL, name);
}
if ((header->ext_status & OCC_EXT_STAT_DVFS_OT) !=
(occ->prev_ext_stat & OCC_EXT_STAT_DVFS_OT)) {
name = sensor_dev_attr_occ_dvfs_overtemp.dev_attr.attr.name;
sysfs_notify(&occ->bus_dev->kobj, NULL, name);
}
if ((header->ext_status & OCC_EXT_STAT_DVFS_POWER) !=
(occ->prev_ext_stat & OCC_EXT_STAT_DVFS_POWER)) {
name = sensor_dev_attr_occ_dvfs_power.dev_attr.attr.name;
sysfs_notify(&occ->bus_dev->kobj, NULL, name);
}
if ((header->ext_status & OCC_EXT_STAT_MEM_THROTTLE) !=
(occ->prev_ext_stat & OCC_EXT_STAT_MEM_THROTTLE)) {
name = sensor_dev_attr_occ_mem_throttle.dev_attr.attr.name;
sysfs_notify(&occ->bus_dev->kobj, NULL, name);
}
if ((header->ext_status & OCC_EXT_STAT_QUICK_DROP) !=
(occ->prev_ext_stat & OCC_EXT_STAT_QUICK_DROP)) {
name = sensor_dev_attr_occ_quick_pwr_drop.dev_attr.attr.name;
sysfs_notify(&occ->bus_dev->kobj, NULL, name);
}
if ((header->ext_status & OCC_EXT_STAT_DVFS_VDD) !=
(occ->prev_ext_stat & OCC_EXT_STAT_DVFS_VDD)) {
name = sensor_dev_attr_occ_dvfs_vdd.dev_attr.attr.name;
sysfs_notify(&occ->bus_dev->kobj, NULL, name);
}
if ((header->ext_status & OCC_EXT_STAT_GPU_THROTTLE) !=
(occ->prev_ext_stat & OCC_EXT_STAT_GPU_THROTTLE)) {
name = sensor_dev_attr_occ_gpu_throttle.dev_attr.attr.name;
sysfs_notify(&occ->bus_dev->kobj, NULL, name);
}
if ((header->status & OCC_STAT_MASTER) &&
header->occs_present != occ->prev_occs_present) {
name = sensor_dev_attr_occs_present.dev_attr.attr.name;
sysfs_notify(&occ->bus_dev->kobj, NULL, name);
}
if (header->ips_status != occ->prev_ips_status) {
name = sensor_dev_attr_occ_ips_status.dev_attr.attr.name;
sysfs_notify(&occ->bus_dev->kobj, NULL, name);
}
if (header->mode != occ->prev_mode) {
name = sensor_dev_attr_occ_mode.dev_attr.attr.name;
sysfs_notify(&occ->bus_dev->kobj, NULL, name);
}
if (occ->error && occ->error != occ->prev_error) {
name = dev_attr_occ_error.attr.name;
sysfs_notify(&occ->bus_dev->kobj, NULL, name);
}
/* no notifications for OCC state; doesn't indicate error condition */
done:
occ->prev_error = occ->error;
occ->prev_stat = header->status;
occ->prev_ext_stat = header->ext_status;
occ->prev_occs_present = header->occs_present;
occ->prev_ips_status = header->ips_status;
occ->prev_mode = header->mode;
}
int occ_setup_sysfs(struct occ *occ)
{
return sysfs_create_group(&occ->bus_dev->kobj, &occ_sysfs);
}
void occ_shutdown_sysfs(struct occ *occ)
{
sysfs_remove_group(&occ->bus_dev->kobj, &occ_sysfs);
}