static int __cpuinit acpi_processor_add(struct acpi_device *device) { struct acpi_processor *pr = NULL; int result = 0; struct sys_device *sysdev; pr = kzalloc(sizeof(struct acpi_processor), GFP_KERNEL); if (!pr) return -ENOMEM; if (!zalloc_cpumask_var(&pr->throttling.shared_cpu_map, GFP_KERNEL)) { kfree(pr); return -ENOMEM; } pr->handle = device->handle; strcpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME); strcpy(acpi_device_class(device), ACPI_PROCESSOR_CLASS); device->driver_data = pr; result = acpi_processor_get_info(device); if (result) { /* Processor is physically not present */ return 0; } #ifdef CONFIG_SMP if (pr->id >= setup_max_cpus && pr->id != 0) return 0; #endif BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0)); /* * Buggy BIOS check * ACPI id of processors can be reported wrongly by the BIOS. * Don't trust it blindly */ if (per_cpu(processor_device_array, pr->id) != NULL && per_cpu(processor_device_array, pr->id) != device) { printk(KERN_WARNING "BIOS reported wrong ACPI id " "for the processor\n"); result = -ENODEV; goto err_free_cpumask; } per_cpu(processor_device_array, pr->id) = device; per_cpu(processors, pr->id) = pr; sysdev = get_cpu_sysdev(pr->id); if (sysfs_create_link(&device->dev.kobj, &sysdev->kobj, "sysdev")) { result = -EFAULT; goto err_free_cpumask; } #ifdef CONFIG_CPU_FREQ acpi_processor_ppc_has_changed(pr, 0); #endif acpi_processor_get_throttling_info(pr); acpi_processor_get_limit_info(pr); if (cpuidle_get_driver() == &acpi_idle_driver) acpi_processor_power_init(pr, device); pr->cdev = thermal_cooling_device_register("Processor", device, &processor_cooling_ops); if (IS_ERR(pr->cdev)) { result = PTR_ERR(pr->cdev); goto err_power_exit; } dev_dbg(&device->dev, "registered as cooling_device%d\n", pr->cdev->id); result = sysfs_create_link(&device->dev.kobj, &pr->cdev->device.kobj, "thermal_cooling"); if (result) { printk(KERN_ERR PREFIX "Create sysfs link\n"); goto err_thermal_unregister; } result = sysfs_create_link(&pr->cdev->device.kobj, &device->dev.kobj, "device"); if (result) { printk(KERN_ERR PREFIX "Create sysfs link\n"); goto err_remove_sysfs; } return 0; err_remove_sysfs: sysfs_remove_link(&device->dev.kobj, "thermal_cooling"); err_thermal_unregister: thermal_cooling_device_unregister(pr->cdev); err_power_exit: acpi_processor_power_exit(pr, device); err_free_cpumask: free_cpumask_var(pr->throttling.shared_cpu_map); return result; }
static int pwm_fan_probe(struct platform_device *pdev) { int i; struct fan_dev_data *fan_data = NULL; int *rpm_data; int *rru_data; int *rrd_data; int *lookup_data; int *pwm_data; int err = 0; int of_err = 0; struct device_node *node = NULL; struct device_node *data_node = NULL; u32 value; int pwm_fan_gpio; int gpio_free_flag = 0; if (!pdev) return -EINVAL; node = pdev->dev.of_node; if (!node) { pr_err("FAN: dev of_node NULL\n"); return -EINVAL; } data_node = of_parse_phandle(node, "shared_data", 0); if (!data_node) { pr_err("PWM shared data node NULL, parse phandle failed\n"); return -EINVAL; } fan_data = devm_kzalloc(&pdev->dev, sizeof(struct fan_dev_data), GFP_KERNEL); if (!fan_data) return -ENOMEM; fan_data->dev = &pdev->dev; fan_data->fan_reg = regulator_get(fan_data->dev, "vdd-fan"); if (IS_ERR_OR_NULL(fan_data->fan_reg)) { pr_err("FAN: coudln't get the regulator\n"); devm_kfree(&pdev->dev, (void *)fan_data); return -ENODEV; } of_err |= of_property_read_string(node, "name", &fan_data->name); pr_info("FAN dev name: %s\n", fan_data->name); of_err |= of_property_read_u32(data_node, "pwm_gpio", &value); pwm_fan_gpio = (int)value; err = gpio_request(pwm_fan_gpio, "pwm-fan"); if (err < 0) { pr_err("FAN:gpio request failed\n"); err = -EINVAL; goto gpio_request_fail; } else { pr_info("FAN:gpio request success.\n"); } of_err |= of_property_read_u32(data_node, "active_steps", &value); fan_data->active_steps = (int)value; of_err |= of_property_read_u32(data_node, "pwm_period", &value); fan_data->pwm_period = (int)value; of_err |= of_property_read_u32(data_node, "pwm_id", &value); fan_data->pwm_id = (int)value; of_err |= of_property_read_u32(data_node, "step_time", &value); fan_data->step_time = (int)value; of_err |= of_property_read_u32(data_node, "active_pwm_max", &value); fan_data->fan_pwm_max = (int)value; of_err |= of_property_read_u32(data_node, "state_cap", &value); fan_data->fan_state_cap = (int)value; fan_data->pwm_gpio = pwm_fan_gpio; if (of_err) { err = -ENXIO; goto rpm_alloc_fail; } if (of_property_read_u32(data_node, "tach_gpio", &value)) { fan_data->tach_gpio = -1; pr_info("FAN: can't find tach_gpio\n"); } else fan_data->tach_gpio = (int)value; /* rpm array */ rpm_data = devm_kzalloc(&pdev->dev, sizeof(int) * (fan_data->active_steps), GFP_KERNEL); if (!rpm_data) { err = -ENOMEM; goto rpm_alloc_fail; } of_err |= of_property_read_u32_array(data_node, "active_rpm", rpm_data, (size_t) fan_data->active_steps); fan_data->fan_rpm = rpm_data; /* rru array */ rru_data = devm_kzalloc(&pdev->dev, sizeof(int) * (fan_data->active_steps), GFP_KERNEL); if (!rru_data) { err = -ENOMEM; goto rru_alloc_fail; } of_err |= of_property_read_u32_array(data_node, "active_rru", rru_data, (size_t) fan_data->active_steps); fan_data->fan_rru = rru_data; /* rrd array */ rrd_data = devm_kzalloc(&pdev->dev, sizeof(int) * (fan_data->active_steps), GFP_KERNEL); if (!rrd_data) { err = -ENOMEM; goto rrd_alloc_fail; } of_err |= of_property_read_u32_array(data_node, "active_rrd", rrd_data, (size_t) fan_data->active_steps); fan_data->fan_rrd = rrd_data; /* state_cap_lookup array */ lookup_data = devm_kzalloc(&pdev->dev, sizeof(int) * (fan_data->active_steps), GFP_KERNEL); if (!lookup_data) { err = -ENOMEM; goto lookup_alloc_fail; } of_err |= of_property_read_u32_array(data_node, "state_cap_lookup", lookup_data, (size_t) fan_data->active_steps); fan_data->fan_state_cap_lookup = lookup_data; /* pwm array */ pwm_data = devm_kzalloc(&pdev->dev, sizeof(int) * (fan_data->active_steps), GFP_KERNEL); if (!pwm_data) { err = -ENOMEM; goto pwm_alloc_fail; } of_err |= of_property_read_u32_array(node, "active_pwm", pwm_data, (size_t) fan_data->active_steps); fan_data->fan_pwm = pwm_data; if (of_err) { err = -ENXIO; goto workqueue_alloc_fail; } mutex_init(&fan_data->fan_state_lock); fan_data->workqueue = alloc_workqueue(dev_name(&pdev->dev), WQ_HIGHPRI | WQ_UNBOUND, 1); if (!fan_data->workqueue) { err = -ENOMEM; goto workqueue_alloc_fail; } INIT_DELAYED_WORK(&(fan_data->fan_ramp_work), fan_ramping_work_func); fan_data->fan_cap_pwm = fan_data->fan_pwm[fan_data->fan_state_cap]; fan_data->precision_multiplier = fan_data->pwm_period / fan_data->fan_pwm_max; dev_info(&pdev->dev, "cap state:%d, cap pwm:%d\n", fan_data->fan_state_cap, fan_data->fan_cap_pwm); fan_data->cdev = thermal_cooling_device_register("pwm-fan", fan_data, &pwm_fan_cooling_ops); if (IS_ERR_OR_NULL(fan_data->cdev)) { dev_err(&pdev->dev, "Failed to register cooling device\n"); err = -EINVAL; goto cdev_register_fail; } fan_data->pwm_dev = pwm_request(fan_data->pwm_id, dev_name(&pdev->dev)); if (IS_ERR_OR_NULL(fan_data->pwm_dev)) { dev_err(&pdev->dev, "unable to request PWM for fan\n"); err = -ENODEV; goto pwm_req_fail; } else { dev_info(&pdev->dev, "got pwm for fan\n"); } fan_data->tach_enabled = 0; gpio_free(fan_data->pwm_gpio); gpio_free_flag = 1; if (fan_data->tach_gpio != -1) { /* init fan tach */ fan_data->tach_irq = gpio_to_irq(fan_data->tach_gpio); err = gpio_request(fan_data->tach_gpio, "pwm-fan-tach"); if (err < 0) { dev_err(&pdev->dev, "fan tach gpio request failed\n"); goto tach_gpio_request_fail; } gpio_free_flag = 0; err = gpio_direction_input(fan_data->tach_gpio); if (err < 0) { dev_err(&pdev->dev, "fan tach set gpio direction input failed\n"); goto tach_request_irq_fail; } err = gpio_sysfs_set_active_low(fan_data->tach_gpio, 1); if (err < 0) { dev_err(&pdev->dev, "fan tach set gpio active low failed\n"); goto tach_request_irq_fail; } err = request_irq(fan_data->tach_irq, fan_tach_isr, IRQF_TRIGGER_RISING, "pwm-fan-tach", NULL); if (err < 0) { dev_err(&pdev->dev, "fan request irq failed\n"); goto tach_request_irq_fail; } dev_info(&pdev->dev, "fan tach request irq: %d. success\n", fan_data->tach_irq); disable_irq_nosync(fan_data->tach_irq); } of_err |= of_property_read_u32(data_node, "tach_period", &value); if (of_err < 0) dev_err(&pdev->dev, "parsing tach_period error: %d\n", of_err); else { fan_data->tach_period = (int) value; dev_info(&pdev->dev, "tach period: %d\n", fan_data->tach_period); /* init tach work related */ fan_data->tach_workqueue = alloc_workqueue(fan_data->name, WQ_HIGHPRI | WQ_UNBOUND, 1); if (!fan_data->tach_workqueue) { err = -ENOMEM; goto tach_workqueue_alloc_fail; } INIT_DELAYED_WORK(&(fan_data->fan_tach_work), fan_tach_work_func); queue_delayed_work(fan_data->tach_workqueue, &(fan_data->fan_tach_work), msecs_to_jiffies(fan_data->tach_period)); } /* init rpm related values */ spin_lock_init(&irq_lock); irq_count = 0; fan_data->rpm_measured = 0; /*turn temp control on*/ fan_data->fan_temp_control_flag = 1; set_pwm_duty_cycle(fan_data->fan_pwm[0], fan_data); platform_set_drvdata(pdev, fan_data); if (add_sysfs_entry(&pdev->dev) < 0) { dev_err(&pdev->dev, "FAN:Can't create syfs node"); err = -ENOMEM; goto sysfs_fail; } if (pwm_fan_debug_init(fan_data) < 0) { dev_err(&pdev->dev, "FAN:Can't create debug fs nodes"); /*Just continue without debug fs*/ } /* print out initialized info */ for (i = 0; i < fan_data->active_steps; i++) { dev_info(&pdev->dev, "index %d: pwm=%d, rpm=%d, rru=%d, rrd=%d, state:%d\n", i, fan_data->fan_pwm[i], fan_data->fan_rpm[i], fan_data->fan_rru[i], fan_data->fan_rrd[i], fan_data->fan_state_cap_lookup[i]); } return err; sysfs_fail: destroy_workqueue(fan_data->tach_workqueue); tach_workqueue_alloc_fail: free_irq(fan_data->tach_irq, NULL); tach_request_irq_fail: tach_gpio_request_fail: pwm_free(fan_data->pwm_dev); pwm_req_fail: thermal_cooling_device_unregister(fan_data->cdev); cdev_register_fail: destroy_workqueue(fan_data->workqueue); workqueue_alloc_fail: devm_kfree(&pdev->dev, (void *)pwm_data); pwm_alloc_fail: devm_kfree(&pdev->dev, (void *)lookup_data); lookup_alloc_fail: devm_kfree(&pdev->dev, (void *)rrd_data); rrd_alloc_fail: devm_kfree(&pdev->dev, (void *)rru_data); rru_alloc_fail: devm_kfree(&pdev->dev, (void *)rpm_data); rpm_alloc_fail: if (!gpio_free_flag) gpio_free(fan_data->pwm_gpio); gpio_request_fail: devm_kfree(&pdev->dev, (void *)fan_data); if (err == -ENXIO) pr_err("FAN: of_property_read failed\n"); else if (err == -ENOMEM) pr_err("FAN: memery allocation failed\n"); return err; }
static int __cpuinit acpi_processor_add(struct acpi_device *device) { struct acpi_processor *pr = NULL; int result = 0; struct sys_device *sysdev; pr = kzalloc(sizeof(struct acpi_processor), GFP_KERNEL); if (!pr) return -ENOMEM; if (!zalloc_cpumask_var(&pr->throttling.shared_cpu_map, GFP_KERNEL)) { kfree(pr); return -ENOMEM; } pr->handle = device->handle; strcpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME); strcpy(acpi_device_class(device), ACPI_PROCESSOR_CLASS); device->driver_data = pr; processor_extcntl_init(); result = acpi_processor_get_info(device); if (result || ((pr->id == -1) && !processor_cntl_external())) { /* Processor is physically not present */ return 0; } BUG_ON(!processor_cntl_external() && ((pr->id >= nr_cpu_ids) || (pr->id < 0))); /* * Buggy BIOS check * ACPI id of processors can be reported wrongly by the BIOS. * Don't trust it blindly */ #ifndef CONFIG_XEN if (per_cpu(processor_device_array, pr->id) != NULL && per_cpu(processor_device_array, pr->id) != device) { #else BUG_ON(pr->acpi_id >= NR_ACPI_CPUS); if (processor_device_array[pr->acpi_id] != NULL && processor_device_array[pr->acpi_id] != device) { #endif printk(KERN_WARNING "BIOS reported wrong ACPI id " "for the processor\n"); result = -ENODEV; goto err_free_cpumask; } #ifndef CONFIG_XEN per_cpu(processor_device_array, pr->id) = device; per_cpu(processors, pr->id) = pr; #else processor_device_array[pr->acpi_id] = device; if (pr->id != -1) per_cpu(processors, pr->id) = pr; #endif result = acpi_processor_add_fs(device); if (result) goto err_free_cpumask; if (pr->id != -1) { sysdev = get_cpu_sysdev(pr->id); if (sysfs_create_link(&device->dev.kobj, &sysdev->kobj, "sysdev")) { result = -EFAULT; goto err_remove_fs; } } /* _PDC call should be done before doing anything else (if reqd.). */ arch_acpi_processor_init_pdc(pr); acpi_processor_set_pdc(pr); arch_acpi_processor_cleanup_pdc(pr); #if defined(CONFIG_CPU_FREQ) || defined(CONFIG_PROCESSOR_EXTERNAL_CONTROL) acpi_processor_ppc_has_changed(pr); #endif /* * pr->id may equal to -1 while processor_cntl_external enabled. * throttle and thermal module don't support this case. * Tx only works when dom0 vcpu == pcpu num by far, as we give * control to dom0. */ if (pr->id != -1) { acpi_processor_get_throttling_info(pr); acpi_processor_get_limit_info(pr); } acpi_processor_power_init(pr, device); result = processor_extcntl_prepare(pr); if (result) goto err_power_exit; pr->cdev = thermal_cooling_device_register("Processor", device, &processor_cooling_ops); if (IS_ERR(pr->cdev)) { result = PTR_ERR(pr->cdev); goto err_power_exit; } dev_info(&device->dev, "registered as cooling_device%d\n", pr->cdev->id); result = sysfs_create_link(&device->dev.kobj, &pr->cdev->device.kobj, "thermal_cooling"); if (result) { printk(KERN_ERR PREFIX "Create sysfs link\n"); goto err_thermal_unregister; } result = sysfs_create_link(&pr->cdev->device.kobj, &device->dev.kobj, "device"); if (result) { printk(KERN_ERR PREFIX "Create sysfs link\n"); goto err_remove_sysfs; } return 0; err_remove_sysfs: sysfs_remove_link(&device->dev.kobj, "thermal_cooling"); err_thermal_unregister: thermal_cooling_device_unregister(pr->cdev); err_power_exit: acpi_processor_power_exit(pr, device); err_remove_fs: acpi_processor_remove_fs(device); err_free_cpumask: free_cpumask_var(pr->throttling.shared_cpu_map); return result; } static int acpi_processor_remove(struct acpi_device *device, int type) { struct acpi_processor *pr = NULL; if (!device || !acpi_driver_data(device)) return -EINVAL; pr = acpi_driver_data(device); if (!processor_cntl_external() && pr->id >= nr_cpu_ids) goto free; if (type == ACPI_BUS_REMOVAL_EJECT) { if (acpi_processor_handle_eject(pr)) return -EINVAL; } acpi_processor_power_exit(pr, device); if (pr->id != -1) sysfs_remove_link(&device->dev.kobj, "sysdev"); acpi_processor_remove_fs(device); if (pr->cdev) { sysfs_remove_link(&device->dev.kobj, "thermal_cooling"); sysfs_remove_link(&pr->cdev->device.kobj, "device"); thermal_cooling_device_unregister(pr->cdev); pr->cdev = NULL; } #ifndef CONFIG_XEN per_cpu(processors, pr->id) = NULL; per_cpu(processor_device_array, pr->id) = NULL; #else if (pr->id != -1) per_cpu(processors, pr->id) = NULL; processor_device_array[pr->acpi_id] = NULL; #endif free: free_cpumask_var(pr->throttling.shared_cpu_map); kfree(pr); return 0; } #ifdef CONFIG_ACPI_HOTPLUG_CPU /**************************************************************************** * Acpi processor hotplug support * ****************************************************************************/ static int is_processor_present(acpi_handle handle) { acpi_status status; unsigned long long sta = 0; status = acpi_evaluate_integer(handle, "_STA", NULL, &sta); if (ACPI_SUCCESS(status) && (sta & ACPI_STA_DEVICE_PRESENT)) return 1; /* * _STA is mandatory for a processor that supports hot plug */ if (status == AE_NOT_FOUND) ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Processor does not support hot plug\n")); else ACPI_EXCEPTION((AE_INFO, status, "Processor Device is not present")); return 0; }
/** * cpufreq_cooling_register - function to create cpufreq cooling device. * @clip_cpus: cpumask of cpus where the frequency constraints will happen. * * This interface function registers the cpufreq cooling device with the name * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq * cooling devices. * * Return: a valid struct thermal_cooling_device pointer on success, * on failure, it returns a corresponding ERR_PTR(). */ struct thermal_cooling_device * cpufreq_cooling_register(const struct cpumask *clip_cpus) { struct thermal_cooling_device *cool_dev; struct cpufreq_cooling_device *cpufreq_dev = NULL; unsigned int min = 0, max = 0; char dev_name[THERMAL_NAME_LENGTH]; int ret = 0, i; struct cpufreq_policy policy; /* Verify that all the clip cpus have same freq_min, freq_max limit */ for_each_cpu(i, clip_cpus) { /* continue if cpufreq policy not found and not return error */ if (!cpufreq_get_policy(&policy, i)) continue; if (min == 0 && max == 0) { min = policy.cpuinfo.min_freq; max = policy.cpuinfo.max_freq; } else { if (min != policy.cpuinfo.min_freq || max != policy.cpuinfo.max_freq) return ERR_PTR(-EINVAL); } } cpufreq_dev = kzalloc(sizeof(struct cpufreq_cooling_device), GFP_KERNEL); if (!cpufreq_dev) return ERR_PTR(-ENOMEM); cpumask_copy(&cpufreq_dev->allowed_cpus, clip_cpus); ret = get_idr(&cpufreq_idr, &cpufreq_dev->id); if (ret) { kfree(cpufreq_dev); return ERR_PTR(-EINVAL); } snprintf(dev_name, sizeof(dev_name), "thermal-cpufreq-%d", cpufreq_dev->id); cool_dev = thermal_cooling_device_register(dev_name, cpufreq_dev, &cpufreq_cooling_ops); if (!cool_dev) { release_idr(&cpufreq_idr, cpufreq_dev->id); kfree(cpufreq_dev); return ERR_PTR(-EINVAL); } cpufreq_dev->cool_dev = cool_dev; cpufreq_dev->cpufreq_state = 0; mutex_lock(&cooling_cpufreq_lock); /* Register the notifier for first cpufreq cooling device */ if (cpufreq_dev_count == 0) cpufreq_register_notifier(&thermal_cpufreq_notifier_block, CPUFREQ_POLICY_NOTIFIER); cpufreq_dev_count++; mutex_unlock(&cooling_cpufreq_lock); return cool_dev; }
static int __cpuinit acpi_processor_start(struct acpi_device *device) { int result = 0; struct acpi_processor *pr; struct sys_device *sysdev; pr = acpi_driver_data(device); result = acpi_processor_get_info(device); if (result) { /* Processor is physically not present */ return 0; } BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0)); /* * Buggy BIOS check * ACPI id of processors can be reported wrongly by the BIOS. * Don't trust it blindly */ if (per_cpu(processor_device_array, pr->id) != NULL && per_cpu(processor_device_array, pr->id) != device) { printk(KERN_WARNING "BIOS reported wrong ACPI id " "for the processor\n"); return -ENODEV; } per_cpu(processor_device_array, pr->id) = device; per_cpu(processors, pr->id) = pr; result = acpi_processor_add_fs(device); if (result) goto end; sysdev = get_cpu_sysdev(pr->id); if (sysfs_create_link(&device->dev.kobj, &sysdev->kobj, "sysdev")) return -EFAULT; /* _PDC call should be done before doing anything else (if reqd.). */ arch_acpi_processor_init_pdc(pr); acpi_processor_set_pdc(pr); #ifdef CONFIG_CPU_FREQ acpi_processor_ppc_has_changed(pr); #endif acpi_processor_get_throttling_info(pr); acpi_processor_get_limit_info(pr); acpi_processor_power_init(pr, device); pr->cdev = thermal_cooling_device_register("Processor", device, &processor_cooling_ops); if (IS_ERR(pr->cdev)) { result = PTR_ERR(pr->cdev); goto end; } dev_info(&device->dev, "registered as cooling_device%d\n", pr->cdev->id); result = sysfs_create_link(&device->dev.kobj, &pr->cdev->device.kobj, "thermal_cooling"); if (result) printk(KERN_ERR PREFIX "Create sysfs link\n"); result = sysfs_create_link(&pr->cdev->device.kobj, &device->dev.kobj, "device"); if (result) printk(KERN_ERR PREFIX "Create sysfs link\n"); if (pr->flags.throttling) { printk(KERN_INFO PREFIX "%s [%s] (supports", acpi_device_name(device), acpi_device_bid(device)); printk(" %d throttling states", pr->throttling.state_count); printk(")\n"); } end: return result; }
static int pwm_fan_probe(struct platform_device *pdev) { int i; struct pwm_fan_platform_data *data; struct fan_dev_data *fan_data; int *rpm_data; int err = 0; data = dev_get_platdata(&pdev->dev); if (!data) { dev_err(&pdev->dev, "platform data is null\n"); return -EINVAL; } fan_data = devm_kzalloc(&pdev->dev, sizeof(struct fan_dev_data), GFP_KERNEL); if (!fan_data) return -ENOMEM; rpm_data = devm_kzalloc(&pdev->dev, 5 * sizeof(int) * data->active_steps, GFP_KERNEL); if (!rpm_data) return -ENOMEM; fan_data->fan_rpm = rpm_data; fan_data->fan_pwm = rpm_data + data->active_steps; fan_data->fan_rru = fan_data->fan_pwm + data->active_steps; fan_data->fan_rrd = fan_data->fan_rru + data->active_steps; fan_data->fan_state_cap_lookup = fan_data->fan_rrd + data->active_steps; mutex_init(&fan_data->fan_state_lock); fan_data->workqueue = alloc_workqueue(dev_name(&pdev->dev), WQ_HIGHPRI | WQ_UNBOUND, 1); if (!fan_data->workqueue) return -ENOMEM; INIT_DELAYED_WORK(&(fan_data->fan_ramp_work), fan_ramping_work_func); fan_data->step_time = data->step_time; fan_data->active_steps = data->active_steps; fan_data->pwm_period = data->pwm_period; fan_data->fan_pwm_max = data->active_pwm_max; fan_data->dev = &pdev->dev; fan_data->fan_state_cap = data->state_cap; fan_data->pwm_gpio = data->pwm_gpio; fan_data->pwm_id = data->pwm_id; for (i = 0; i < fan_data->active_steps; i++) { fan_data->fan_rpm[i] = data->active_rpm[i]; fan_data->fan_pwm[i] = data->active_pwm[i]; fan_data->fan_rru[i] = data->active_rru[i]; fan_data->fan_rrd[i] = data->active_rrd[i]; fan_data->fan_state_cap_lookup[i] = data->state_cap_lookup[i]; dev_info(&pdev->dev, "rpm=%d, pwm=%d, rru=%d, rrd=%d state:%d\n", fan_data->fan_rpm[i], fan_data->fan_pwm[i], fan_data->fan_rru[i], fan_data->fan_rrd[i], fan_data->fan_state_cap_lookup[i]); } fan_data->fan_cap_pwm = data->active_pwm[data->state_cap]; fan_data->precision_multiplier = data->pwm_period / data->active_pwm_max; dev_info(&pdev->dev, "cap state:%d, cap pwm:%d\n", fan_data->fan_state_cap, fan_data->fan_cap_pwm); fan_data->cdev = thermal_cooling_device_register((char *)dev_name(&pdev->dev), fan_data, &pwm_fan_cooling_ops); if (IS_ERR_OR_NULL(fan_data->cdev)) { dev_err(&pdev->dev, "Failed to register cooling device\n"); return -EINVAL; } gpio_free(fan_data->pwm_gpio); fan_data->pwm_dev = pwm_request(data->pwm_id, dev_name(&pdev->dev)); if (IS_ERR_OR_NULL(fan_data->pwm_dev)) { dev_err(&pdev->dev, "unable to request PWM for fan\n"); err = -ENODEV; goto pwm_req_fail; } else { dev_info(&pdev->dev, "got pwm for fan\n"); } fan_data->tach_gpio = data->tach_gpio; fan_data->tach_enabled = 0; if (fan_data->tach_gpio != -1) { /* init fan tach */ fan_data->tach_irq = gpio_to_irq(fan_data->tach_gpio); err = gpio_request(fan_data->tach_gpio, "pwm-fan-tach"); if (err < 0) { dev_err(&pdev->dev, "fan tach gpio request failed\n"); goto tach_gpio_request_fail; } err = gpio_direction_input(fan_data->tach_gpio); if (err < 0) { dev_err(&pdev->dev, "fan tach set gpio direction input failed\n"); goto tach_request_irq_fail; } err = gpio_sysfs_set_active_low(fan_data->tach_gpio, 1); if (err < 0) { dev_err(&pdev->dev, "fan tach set gpio active low failed\n"); goto tach_request_irq_fail; } err = request_irq(fan_data->tach_irq, fan_tach_isr, IRQF_TRIGGER_FALLING , "pwm-fan-tach", NULL); if (err < 0) goto tach_request_irq_fail; disable_irq_nosync(fan_data->tach_irq); } platform_set_drvdata(pdev, fan_data); /*turn temp control on*/ fan_data->fan_temp_control_flag = 1; set_pwm_duty_cycle(fan_data->fan_pwm[0], fan_data); if (add_sysfs_entry(&pdev->dev) < 0) { dev_err(&pdev->dev, "FAN:Can't create syfs node"); err = -ENOMEM; goto sysfs_fail; } if (pwm_fan_debug_init(fan_data) < 0) { dev_err(&pdev->dev, "FAN:Can't create debug fs nodes"); /*Just continue without debug fs*/ } return err; sysfs_fail: pwm_free(fan_data->pwm_dev); free_irq(fan_data->tach_irq, NULL); tach_request_irq_fail: gpio_free(fan_data->tach_gpio); tach_gpio_request_fail: pwm_req_fail: thermal_cooling_device_unregister(fan_data->cdev); return err; }