Ejemplo n.º 1
0
static int
nouveau_in_read(struct device *dev, u32 attr, int channel, long *val)
{
	struct drm_device *drm_dev = dev_get_drvdata(dev);
	struct nouveau_drm *drm = nouveau_drm(drm_dev);
	struct nvkm_volt *volt = nvxx_volt(&drm->client.device);
	int ret;

	if (!volt)
		return -EOPNOTSUPP;

	switch (attr) {
	case hwmon_in_input:
		ret = nvkm_volt_get(volt);
		*val = ret < 0 ? ret : (ret / 1000);
		break;
	case hwmon_in_min:
		*val = volt->min_uv > 0 ? (volt->min_uv / 1000) : -ENODEV;
		break;
	case hwmon_in_max:
		*val = volt->max_uv > 0 ? (volt->max_uv / 1000) : -ENODEV;
		break;
	default:
		return -EOPNOTSUPP;
	}

	return 0;
}
Ejemplo n.º 2
0
static ssize_t
nouveau_hwmon_get_in0_max(struct device *d,
			    struct device_attribute *a, char *buf)
{
	struct drm_device *dev = dev_get_drvdata(d);
	struct nouveau_drm *drm = nouveau_drm(dev);
	struct nvkm_volt *volt = nvxx_volt(&drm->client.device);

	if (!volt || !volt->max_uv)
		return -ENODEV;

	return sprintf(buf, "%i\n", volt->max_uv / 1000);
}
Ejemplo n.º 3
0
static ssize_t
nouveau_hwmon_get_in0_input(struct device *d,
			    struct device_attribute *a, char *buf)
{
	struct drm_device *dev = dev_get_drvdata(d);
	struct nouveau_drm *drm = nouveau_drm(dev);
	struct nvkm_volt *volt = nvxx_volt(&drm->device);
	int ret;

	ret = nvkm_volt_get(volt);
	if (ret < 0)
		return ret;

	return sprintf(buf, "%i\n", ret / 1000);
}
Ejemplo n.º 4
0
int
nouveau_hwmon_init(struct drm_device *dev)
{
#if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE))
	struct nouveau_drm *drm = nouveau_drm(dev);
	struct nvkm_iccsense *iccsense = nvxx_iccsense(&drm->client.device);
	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
	struct nvkm_volt *volt = nvxx_volt(&drm->client.device);
	const struct attribute_group *special_groups[N_ATTR_GROUPS];
	struct nouveau_hwmon *hwmon;
	struct device *hwmon_dev;
	int ret = 0;
	int i = 0;

	if (!iccsense && !therm && !volt) {
		NV_DEBUG(drm, "Skipping hwmon registration\n");
		return 0;
	}

	hwmon = drm->hwmon = kzalloc(sizeof(*hwmon), GFP_KERNEL);
	if (!hwmon)
		return -ENOMEM;
	hwmon->dev = dev;

	if (therm && therm->attr_get && therm->attr_set) {
		if (nvkm_therm_temp_get(therm) >= 0)
			special_groups[i++] = &temp1_auto_point_sensor_group;
		if (therm->fan_get && therm->fan_get(therm) >= 0)
			special_groups[i++] = &pwm_fan_sensor_group;
	}

	special_groups[i] = 0;
	hwmon_dev = hwmon_device_register_with_info(dev->dev, "nouveau", dev,
							&nouveau_chip_info,
							special_groups);
	if (IS_ERR(hwmon_dev)) {
		ret = PTR_ERR(hwmon_dev);
		NV_ERROR(drm, "Unable to register hwmon device: %d\n", ret);
		return ret;
	}

	hwmon->hwmon = hwmon_dev;
	return 0;
#else
	return 0;
#endif
}
Ejemplo n.º 5
0
static umode_t
nouveau_input_is_visible(const void *data, u32 attr, int channel)
{
	struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data);
	struct nvkm_volt *volt = nvxx_volt(&drm->client.device);

	if (!volt || nvkm_volt_get(volt) < 0)
		return 0;

	switch (attr) {
	case hwmon_in_input:
	case hwmon_in_label:
	case hwmon_in_min:
	case hwmon_in_max:
		return 0444;
	default:
		return 0;
	}
}
Ejemplo n.º 6
0
int
nouveau_hwmon_init(struct drm_device *dev)
{
#if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE))
	struct nouveau_drm *drm = nouveau_drm(dev);
	struct nvkm_therm *therm = nvxx_therm(&drm->device);
	struct nvkm_volt *volt = nvxx_volt(&drm->device);
	struct nvkm_iccsense *iccsense = nvxx_iccsense(&drm->device);
	struct nouveau_hwmon *hwmon;
	struct device *hwmon_dev;
	int ret = 0;

	hwmon = drm->hwmon = kzalloc(sizeof(*hwmon), GFP_KERNEL);
	if (!hwmon)
		return -ENOMEM;
	hwmon->dev = dev;

	hwmon_dev = hwmon_device_register(dev->dev);
	if (IS_ERR(hwmon_dev)) {
		ret = PTR_ERR(hwmon_dev);
		NV_ERROR(drm, "Unable to register hwmon device: %d\n", ret);
		return ret;
	}
	dev_set_drvdata(hwmon_dev, dev);

	/* set the default attributes */
	ret = sysfs_create_group(&hwmon_dev->kobj, &hwmon_default_attrgroup);
	if (ret)
		goto error;

	if (therm && therm->attr_get && therm->attr_set) {
		/* if the card has a working thermal sensor */
		if (nvkm_therm_temp_get(therm) >= 0) {
			ret = sysfs_create_group(&hwmon_dev->kobj, &hwmon_temp_attrgroup);
			if (ret)
				goto error;
		}

		/* if the card has a pwm fan */
		/*XXX: incorrect, need better detection for this, some boards have
		 *     the gpio entries for pwm fan control even when there's no
		 *     actual fan connected to it... therm table? */
		if (therm->fan_get && therm->fan_get(therm) >= 0) {
			ret = sysfs_create_group(&hwmon_dev->kobj,
						 &hwmon_pwm_fan_attrgroup);
			if (ret)
				goto error;
		}
	}

	/* if the card can read the fan rpm */
	if (therm && nvkm_therm_fan_sense(therm) >= 0) {
		ret = sysfs_create_group(&hwmon_dev->kobj,
					 &hwmon_fan_rpm_attrgroup);
		if (ret)
			goto error;
	}

	if (volt && nvkm_volt_get(volt) >= 0) {
		ret = sysfs_create_group(&hwmon_dev->kobj,
					 &hwmon_in0_attrgroup);

		if (ret)
			goto error;
	}

	if (iccsense && iccsense->data_valid && !list_empty(&iccsense->rails)) {
		ret = sysfs_create_group(&hwmon_dev->kobj,
					 &hwmon_power_attrgroup);
		if (ret)
			goto error;
	}

	hwmon->hwmon = hwmon_dev;

	return 0;

error:
	NV_ERROR(drm, "Unable to create some hwmon sysfs files: %d\n", ret);
	hwmon_device_unregister(hwmon_dev);
	hwmon->hwmon = NULL;
	return ret;
#else
	return 0;
#endif
}