static int acpi_fan_add(struct acpi_device *device) { int result = 0; int state = 0; struct thermal_cooling_device *cdev; if (!device) return -EINVAL; strcpy(acpi_device_name(device), "Fan"); strcpy(acpi_device_class(device), ACPI_FAN_CLASS); result = acpi_bus_get_power(device->handle, &state); if (result) { printk(KERN_ERR PREFIX "Reading power state\n"); goto end; } device->flags.force_power_state = 1; acpi_bus_set_power(device->handle, state); device->flags.force_power_state = 0; cdev = thermal_cooling_device_register("Fan", device, &fan_cooling_ops); if (IS_ERR(cdev)) { result = PTR_ERR(cdev); goto end; } dev_dbg(&device->dev, "registered as cooling_device%d\n", cdev->id); device->driver_data = cdev; result = sysfs_create_link(&device->dev.kobj, &cdev->device.kobj, "thermal_cooling"); if (result) dev_err(&device->dev, "Failed to create sysfs link " "'thermal_cooling'\n"); result = sysfs_create_link(&cdev->device.kobj, &device->dev.kobj, "device"); if (result) dev_err(&device->dev, "Failed to create sysfs link " "'device'\n"); result = acpi_fan_add_fs(device); if (result) goto end; printk(KERN_INFO PREFIX "%s [%s] (%s)\n", acpi_device_name(device), acpi_device_bid(device), !device->power.state ? "on" : "off"); end: return result; }
int acpi_fan_add ( struct acpi_device *device) { int result = 0; struct acpi_fan *fan = NULL; int state = 0; ACPI_FUNCTION_TRACE("acpi_fan_add"); if (!device) return_VALUE(-EINVAL); fan = kmalloc(sizeof(struct acpi_fan), GFP_KERNEL); if (!fan) return_VALUE(-ENOMEM); memset(fan, 0, sizeof(struct acpi_fan)); fan->handle = device->handle; sprintf(acpi_device_name(device), "%s", ACPI_FAN_DEVICE_NAME); sprintf(acpi_device_class(device), "%s", ACPI_FAN_CLASS); acpi_driver_data(device) = fan; result = acpi_bus_get_power(fan->handle, &state); if (result) { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error reading power state\n")); goto end; } result = acpi_fan_add_fs(device); if (result) goto end; printk(KERN_INFO PREFIX "%s [%s] (%s)\n", acpi_device_name(device), acpi_device_bid(device), !device->power.state?"on":"off"); end: if (result) kfree(fan); return_VALUE(result); }