static int hwmon_init(void) { int res; pwm1_value = -1; #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,9,0) lensl_hwmon_device = hwmon_device_register_with_info(&lensl_pdev->dev, "lenovo_sl_laptop", NULL, NULL, NULL); #else lensl_hwmon_device = hwmon_device_register(&lensl_pdev->dev); #endif if (!lensl_hwmon_device) { vdbg_printk(LENSL_ERR, "Failed to register hwmon device\n"); return -ENODEV; } res = sysfs_create_group(&lensl_hwmon_device->kobj, &hwmon_attr_group); if (res < 0) { vdbg_printk(LENSL_ERR, "Failed to create hwmon sysfs group\n"); hwmon_device_unregister(lensl_hwmon_device); lensl_hwmon_device = NULL; return -ENODEV; } vdbg_printk(LENSL_DEBUG, "Initialized hwmon subdriver\n"); return 0; }
static int as7716_24sc_expansion_card_probe(struct i2c_client *client, const struct i2c_device_id *dev_id) { struct as7716_24sc_expansion_card_data *data; int status; if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { status = -EIO; goto exit; } data = kzalloc(sizeof(struct as7716_24sc_expansion_card_data), GFP_KERNEL); if (!data) { status = -ENOMEM; goto exit; } i2c_set_clientdata(client, data); data->valid = 0; data->driver_slot = dev_id->driver_data; mutex_init(&data->update_lock); dev_info(&client->dev, "chip found\n"); /* Register sysfs hooks */ status = sysfs_create_group(&client->dev.kobj, &as7716_24sc_expansion_card_group); if (status) { goto exit_free; } data->hwmon_dev = hwmon_device_register_with_info(&client->dev, "as7716_24sc_expansion_card", NULL, NULL, NULL); if (IS_ERR(data->hwmon_dev)) { status = PTR_ERR(data->hwmon_dev); goto exit_remove; } dev_info(&client->dev, "%s: expansion card '%s'\n", dev_name(data->hwmon_dev), client->name); return 0; exit_remove: sysfs_remove_group(&client->dev.kobj, &as7716_24sc_expansion_card_group); exit_free: kfree(data); exit: return status; }
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 }