drivers/hwmon/occ/sysfs.c

Source file repositories/reference/linux-study-clean/drivers/hwmon/occ/sysfs.c

File Facts

System
Linux kernel
Corpus path
drivers/hwmon/occ/sysfs.c
Extension
.c
Size
7326 bytes
Lines
258
Domain
Driver Families
Bucket
drivers/hwmon
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

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,

Annotation

Implementation Notes