diff options
Diffstat (limited to 'drivers')
28 files changed, 1272 insertions, 596 deletions
diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c index bfc31cb0dd3e..e78c2a52ea46 100644 --- a/drivers/acpi/processor_driver.c +++ b/drivers/acpi/processor_driver.c | |||
@@ -475,7 +475,7 @@ static __ref int acpi_processor_start(struct acpi_processor *pr) | |||
475 | acpi_processor_get_limit_info(pr); | 475 | acpi_processor_get_limit_info(pr); |
476 | 476 | ||
477 | if (!cpuidle_get_driver() || cpuidle_get_driver() == &acpi_idle_driver) | 477 | if (!cpuidle_get_driver() || cpuidle_get_driver() == &acpi_idle_driver) |
478 | acpi_processor_power_init(pr, device); | 478 | acpi_processor_power_init(pr); |
479 | 479 | ||
480 | pr->cdev = thermal_cooling_device_register("Processor", device, | 480 | pr->cdev = thermal_cooling_device_register("Processor", device, |
481 | &processor_cooling_ops); | 481 | &processor_cooling_ops); |
@@ -509,7 +509,7 @@ err_remove_sysfs_thermal: | |||
509 | err_thermal_unregister: | 509 | err_thermal_unregister: |
510 | thermal_cooling_device_unregister(pr->cdev); | 510 | thermal_cooling_device_unregister(pr->cdev); |
511 | err_power_exit: | 511 | err_power_exit: |
512 | acpi_processor_power_exit(pr, device); | 512 | acpi_processor_power_exit(pr); |
513 | 513 | ||
514 | return result; | 514 | return result; |
515 | } | 515 | } |
@@ -620,7 +620,7 @@ static int acpi_processor_remove(struct acpi_device *device, int type) | |||
620 | return -EINVAL; | 620 | return -EINVAL; |
621 | } | 621 | } |
622 | 622 | ||
623 | acpi_processor_power_exit(pr, device); | 623 | acpi_processor_power_exit(pr); |
624 | 624 | ||
625 | sysfs_remove_link(&device->dev.kobj, "sysdev"); | 625 | sysfs_remove_link(&device->dev.kobj, "sysdev"); |
626 | 626 | ||
@@ -905,8 +905,6 @@ static int __init acpi_processor_init(void) | |||
905 | if (acpi_disabled) | 905 | if (acpi_disabled) |
906 | return 0; | 906 | return 0; |
907 | 907 | ||
908 | memset(&errata, 0, sizeof(errata)); | ||
909 | |||
910 | result = acpi_bus_register_driver(&acpi_processor_driver); | 908 | result = acpi_bus_register_driver(&acpi_processor_driver); |
911 | if (result < 0) | 909 | if (result < 0) |
912 | return result; | 910 | return result; |
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index ad3730b4038b..3655ab923812 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c | |||
@@ -79,6 +79,8 @@ module_param(bm_check_disable, uint, 0000); | |||
79 | static unsigned int latency_factor __read_mostly = 2; | 79 | static unsigned int latency_factor __read_mostly = 2; |
80 | module_param(latency_factor, uint, 0644); | 80 | module_param(latency_factor, uint, 0644); |
81 | 81 | ||
82 | static DEFINE_PER_CPU(struct cpuidle_device *, acpi_cpuidle_device); | ||
83 | |||
82 | static int disabled_by_idle_boot_param(void) | 84 | static int disabled_by_idle_boot_param(void) |
83 | { | 85 | { |
84 | return boot_option_idle_override == IDLE_POLL || | 86 | return boot_option_idle_override == IDLE_POLL || |
@@ -483,8 +485,6 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr) | |||
483 | if (obj->type != ACPI_TYPE_INTEGER) | 485 | if (obj->type != ACPI_TYPE_INTEGER) |
484 | continue; | 486 | continue; |
485 | 487 | ||
486 | cx.power = obj->integer.value; | ||
487 | |||
488 | current_count++; | 488 | current_count++; |
489 | memcpy(&(pr->power.states[current_count]), &cx, sizeof(cx)); | 489 | memcpy(&(pr->power.states[current_count]), &cx, sizeof(cx)); |
490 | 490 | ||
@@ -1000,7 +1000,7 @@ static int acpi_processor_setup_cpuidle_cx(struct acpi_processor *pr) | |||
1000 | int i, count = CPUIDLE_DRIVER_STATE_START; | 1000 | int i, count = CPUIDLE_DRIVER_STATE_START; |
1001 | struct acpi_processor_cx *cx; | 1001 | struct acpi_processor_cx *cx; |
1002 | struct cpuidle_state_usage *state_usage; | 1002 | struct cpuidle_state_usage *state_usage; |
1003 | struct cpuidle_device *dev = &pr->power.dev; | 1003 | struct cpuidle_device *dev = per_cpu(acpi_cpuidle_device, pr->id); |
1004 | 1004 | ||
1005 | if (!pr->flags.power_setup_done) | 1005 | if (!pr->flags.power_setup_done) |
1006 | return -EINVAL; | 1006 | return -EINVAL; |
@@ -1132,6 +1132,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr) | |||
1132 | int acpi_processor_hotplug(struct acpi_processor *pr) | 1132 | int acpi_processor_hotplug(struct acpi_processor *pr) |
1133 | { | 1133 | { |
1134 | int ret = 0; | 1134 | int ret = 0; |
1135 | struct cpuidle_device *dev = per_cpu(acpi_cpuidle_device, pr->id); | ||
1135 | 1136 | ||
1136 | if (disabled_by_idle_boot_param()) | 1137 | if (disabled_by_idle_boot_param()) |
1137 | return 0; | 1138 | return 0; |
@@ -1147,11 +1148,11 @@ int acpi_processor_hotplug(struct acpi_processor *pr) | |||
1147 | return -ENODEV; | 1148 | return -ENODEV; |
1148 | 1149 | ||
1149 | cpuidle_pause_and_lock(); | 1150 | cpuidle_pause_and_lock(); |
1150 | cpuidle_disable_device(&pr->power.dev); | 1151 | cpuidle_disable_device(dev); |
1151 | acpi_processor_get_power_info(pr); | 1152 | acpi_processor_get_power_info(pr); |
1152 | if (pr->flags.power) { | 1153 | if (pr->flags.power) { |
1153 | acpi_processor_setup_cpuidle_cx(pr); | 1154 | acpi_processor_setup_cpuidle_cx(pr); |
1154 | ret = cpuidle_enable_device(&pr->power.dev); | 1155 | ret = cpuidle_enable_device(dev); |
1155 | } | 1156 | } |
1156 | cpuidle_resume_and_unlock(); | 1157 | cpuidle_resume_and_unlock(); |
1157 | 1158 | ||
@@ -1162,6 +1163,7 @@ int acpi_processor_cst_has_changed(struct acpi_processor *pr) | |||
1162 | { | 1163 | { |
1163 | int cpu; | 1164 | int cpu; |
1164 | struct acpi_processor *_pr; | 1165 | struct acpi_processor *_pr; |
1166 | struct cpuidle_device *dev; | ||
1165 | 1167 | ||
1166 | if (disabled_by_idle_boot_param()) | 1168 | if (disabled_by_idle_boot_param()) |
1167 | return 0; | 1169 | return 0; |
@@ -1192,7 +1194,8 @@ int acpi_processor_cst_has_changed(struct acpi_processor *pr) | |||
1192 | _pr = per_cpu(processors, cpu); | 1194 | _pr = per_cpu(processors, cpu); |
1193 | if (!_pr || !_pr->flags.power_setup_done) | 1195 | if (!_pr || !_pr->flags.power_setup_done) |
1194 | continue; | 1196 | continue; |
1195 | cpuidle_disable_device(&_pr->power.dev); | 1197 | dev = per_cpu(acpi_cpuidle_device, cpu); |
1198 | cpuidle_disable_device(dev); | ||
1196 | } | 1199 | } |
1197 | 1200 | ||
1198 | /* Populate Updated C-state information */ | 1201 | /* Populate Updated C-state information */ |
@@ -1206,7 +1209,8 @@ int acpi_processor_cst_has_changed(struct acpi_processor *pr) | |||
1206 | acpi_processor_get_power_info(_pr); | 1209 | acpi_processor_get_power_info(_pr); |
1207 | if (_pr->flags.power) { | 1210 | if (_pr->flags.power) { |
1208 | acpi_processor_setup_cpuidle_cx(_pr); | 1211 | acpi_processor_setup_cpuidle_cx(_pr); |
1209 | cpuidle_enable_device(&_pr->power.dev); | 1212 | dev = per_cpu(acpi_cpuidle_device, cpu); |
1213 | cpuidle_enable_device(dev); | ||
1210 | } | 1214 | } |
1211 | } | 1215 | } |
1212 | put_online_cpus(); | 1216 | put_online_cpus(); |
@@ -1218,11 +1222,11 @@ int acpi_processor_cst_has_changed(struct acpi_processor *pr) | |||
1218 | 1222 | ||
1219 | static int acpi_processor_registered; | 1223 | static int acpi_processor_registered; |
1220 | 1224 | ||
1221 | int __cpuinit acpi_processor_power_init(struct acpi_processor *pr, | 1225 | int __cpuinit acpi_processor_power_init(struct acpi_processor *pr) |
1222 | struct acpi_device *device) | ||
1223 | { | 1226 | { |
1224 | acpi_status status = 0; | 1227 | acpi_status status = 0; |
1225 | int retval; | 1228 | int retval; |
1229 | struct cpuidle_device *dev; | ||
1226 | static int first_run; | 1230 | static int first_run; |
1227 | 1231 | ||
1228 | if (disabled_by_idle_boot_param()) | 1232 | if (disabled_by_idle_boot_param()) |
@@ -1268,11 +1272,18 @@ int __cpuinit acpi_processor_power_init(struct acpi_processor *pr, | |||
1268 | printk(KERN_DEBUG "ACPI: %s registered with cpuidle\n", | 1272 | printk(KERN_DEBUG "ACPI: %s registered with cpuidle\n", |
1269 | acpi_idle_driver.name); | 1273 | acpi_idle_driver.name); |
1270 | } | 1274 | } |
1275 | |||
1276 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | ||
1277 | if (!dev) | ||
1278 | return -ENOMEM; | ||
1279 | per_cpu(acpi_cpuidle_device, pr->id) = dev; | ||
1280 | |||
1281 | acpi_processor_setup_cpuidle_cx(pr); | ||
1282 | |||
1271 | /* Register per-cpu cpuidle_device. Cpuidle driver | 1283 | /* Register per-cpu cpuidle_device. Cpuidle driver |
1272 | * must already be registered before registering device | 1284 | * must already be registered before registering device |
1273 | */ | 1285 | */ |
1274 | acpi_processor_setup_cpuidle_cx(pr); | 1286 | retval = cpuidle_register_device(dev); |
1275 | retval = cpuidle_register_device(&pr->power.dev); | ||
1276 | if (retval) { | 1287 | if (retval) { |
1277 | if (acpi_processor_registered == 0) | 1288 | if (acpi_processor_registered == 0) |
1278 | cpuidle_unregister_driver(&acpi_idle_driver); | 1289 | cpuidle_unregister_driver(&acpi_idle_driver); |
@@ -1283,14 +1294,15 @@ int __cpuinit acpi_processor_power_init(struct acpi_processor *pr, | |||
1283 | return 0; | 1294 | return 0; |
1284 | } | 1295 | } |
1285 | 1296 | ||
1286 | int acpi_processor_power_exit(struct acpi_processor *pr, | 1297 | int acpi_processor_power_exit(struct acpi_processor *pr) |
1287 | struct acpi_device *device) | ||
1288 | { | 1298 | { |
1299 | struct cpuidle_device *dev = per_cpu(acpi_cpuidle_device, pr->id); | ||
1300 | |||
1289 | if (disabled_by_idle_boot_param()) | 1301 | if (disabled_by_idle_boot_param()) |
1290 | return 0; | 1302 | return 0; |
1291 | 1303 | ||
1292 | if (pr->flags.power) { | 1304 | if (pr->flags.power) { |
1293 | cpuidle_unregister_device(&pr->power.dev); | 1305 | cpuidle_unregister_device(dev); |
1294 | acpi_processor_registered--; | 1306 | acpi_processor_registered--; |
1295 | if (acpi_processor_registered == 0) | 1307 | if (acpi_processor_registered == 0) |
1296 | cpuidle_unregister_driver(&acpi_idle_driver); | 1308 | cpuidle_unregister_driver(&acpi_idle_driver); |
diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c index a093dc163a42..836bfe069042 100644 --- a/drivers/acpi/processor_perflib.c +++ b/drivers/acpi/processor_perflib.c | |||
@@ -324,6 +324,34 @@ static int acpi_processor_get_performance_control(struct acpi_processor *pr) | |||
324 | return result; | 324 | return result; |
325 | } | 325 | } |
326 | 326 | ||
327 | #ifdef CONFIG_X86 | ||
328 | /* | ||
329 | * Some AMDs have 50MHz frequency multiples, but only provide 100MHz rounding | ||
330 | * in their ACPI data. Calculate the real values and fix up the _PSS data. | ||
331 | */ | ||
332 | static void amd_fixup_frequency(struct acpi_processor_px *px, int i) | ||
333 | { | ||
334 | u32 hi, lo, fid, did; | ||
335 | int index = px->control & 0x00000007; | ||
336 | |||
337 | if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD) | ||
338 | return; | ||
339 | |||
340 | if ((boot_cpu_data.x86 == 0x10 && boot_cpu_data.x86_model < 10) | ||
341 | || boot_cpu_data.x86 == 0x11) { | ||
342 | rdmsr(MSR_AMD_PSTATE_DEF_BASE + index, lo, hi); | ||
343 | fid = lo & 0x3f; | ||
344 | did = (lo >> 6) & 7; | ||
345 | if (boot_cpu_data.x86 == 0x10) | ||
346 | px->core_frequency = (100 * (fid + 0x10)) >> did; | ||
347 | else | ||
348 | px->core_frequency = (100 * (fid + 8)) >> did; | ||
349 | } | ||
350 | } | ||
351 | #else | ||
352 | static void amd_fixup_frequency(struct acpi_processor_px *px, int i) {}; | ||
353 | #endif | ||
354 | |||
327 | static int acpi_processor_get_performance_states(struct acpi_processor *pr) | 355 | static int acpi_processor_get_performance_states(struct acpi_processor *pr) |
328 | { | 356 | { |
329 | int result = 0; | 357 | int result = 0; |
@@ -379,6 +407,8 @@ static int acpi_processor_get_performance_states(struct acpi_processor *pr) | |||
379 | goto end; | 407 | goto end; |
380 | } | 408 | } |
381 | 409 | ||
410 | amd_fixup_frequency(px, i); | ||
411 | |||
382 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 412 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
383 | "State [%d]: core_frequency[%d] power[%d] transition_latency[%d] bus_master_latency[%d] control[0x%x] status[0x%x]\n", | 413 | "State [%d]: core_frequency[%d] power[%d] transition_latency[%d] bus_master_latency[%d] control[0x%x] status[0x%x]\n", |
384 | i, | 414 | i, |
diff --git a/drivers/base/platform.c b/drivers/base/platform.c index ddeca142293c..8727e9c5eea4 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <linux/idr.h> | 23 | #include <linux/idr.h> |
24 | 24 | ||
25 | #include "base.h" | 25 | #include "base.h" |
26 | #include "power/power.h" | ||
26 | 27 | ||
27 | /* For automatically allocated device IDs */ | 28 | /* For automatically allocated device IDs */ |
28 | static DEFINE_IDA(platform_devid_ida); | 29 | static DEFINE_IDA(platform_devid_ida); |
@@ -983,6 +984,7 @@ void __init early_platform_add_devices(struct platform_device **devs, int num) | |||
983 | dev = &devs[i]->dev; | 984 | dev = &devs[i]->dev; |
984 | 985 | ||
985 | if (!dev->devres_head.next) { | 986 | if (!dev->devres_head.next) { |
987 | pm_runtime_early_init(dev); | ||
986 | INIT_LIST_HEAD(&dev->devres_head); | 988 | INIT_LIST_HEAD(&dev->devres_head); |
987 | list_add_tail(&dev->devres_head, | 989 | list_add_tail(&dev->devres_head, |
988 | &early_platform_device_list); | 990 | &early_platform_device_list); |
diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index ba3487c9835b..c22b869245d9 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c | |||
@@ -53,6 +53,24 @@ | |||
53 | static LIST_HEAD(gpd_list); | 53 | static LIST_HEAD(gpd_list); |
54 | static DEFINE_MUTEX(gpd_list_lock); | 54 | static DEFINE_MUTEX(gpd_list_lock); |
55 | 55 | ||
56 | static struct generic_pm_domain *pm_genpd_lookup_name(const char *domain_name) | ||
57 | { | ||
58 | struct generic_pm_domain *genpd = NULL, *gpd; | ||
59 | |||
60 | if (IS_ERR_OR_NULL(domain_name)) | ||
61 | return NULL; | ||
62 | |||
63 | mutex_lock(&gpd_list_lock); | ||
64 | list_for_each_entry(gpd, &gpd_list, gpd_list_node) { | ||
65 | if (!strcmp(gpd->name, domain_name)) { | ||
66 | genpd = gpd; | ||
67 | break; | ||
68 | } | ||
69 | } | ||
70 | mutex_unlock(&gpd_list_lock); | ||
71 | return genpd; | ||
72 | } | ||
73 | |||
56 | #ifdef CONFIG_PM | 74 | #ifdef CONFIG_PM |
57 | 75 | ||
58 | struct generic_pm_domain *dev_to_genpd(struct device *dev) | 76 | struct generic_pm_domain *dev_to_genpd(struct device *dev) |
@@ -256,10 +274,28 @@ int pm_genpd_poweron(struct generic_pm_domain *genpd) | |||
256 | return ret; | 274 | return ret; |
257 | } | 275 | } |
258 | 276 | ||
277 | /** | ||
278 | * pm_genpd_name_poweron - Restore power to a given PM domain and its masters. | ||
279 | * @domain_name: Name of the PM domain to power up. | ||
280 | */ | ||
281 | int pm_genpd_name_poweron(const char *domain_name) | ||
282 | { | ||
283 | struct generic_pm_domain *genpd; | ||
284 | |||
285 | genpd = pm_genpd_lookup_name(domain_name); | ||
286 | return genpd ? pm_genpd_poweron(genpd) : -EINVAL; | ||
287 | } | ||
288 | |||
259 | #endif /* CONFIG_PM */ | 289 | #endif /* CONFIG_PM */ |
260 | 290 | ||
261 | #ifdef CONFIG_PM_RUNTIME | 291 | #ifdef CONFIG_PM_RUNTIME |
262 | 292 | ||
293 | static int genpd_start_dev_no_timing(struct generic_pm_domain *genpd, | ||
294 | struct device *dev) | ||
295 | { | ||
296 | return GENPD_DEV_CALLBACK(genpd, int, start, dev); | ||
297 | } | ||
298 | |||
263 | static int genpd_save_dev(struct generic_pm_domain *genpd, struct device *dev) | 299 | static int genpd_save_dev(struct generic_pm_domain *genpd, struct device *dev) |
264 | { | 300 | { |
265 | return GENPD_DEV_TIMED_CALLBACK(genpd, int, save_state, dev, | 301 | return GENPD_DEV_TIMED_CALLBACK(genpd, int, save_state, dev, |
@@ -436,7 +472,7 @@ static int pm_genpd_poweroff(struct generic_pm_domain *genpd) | |||
436 | not_suspended = 0; | 472 | not_suspended = 0; |
437 | list_for_each_entry(pdd, &genpd->dev_list, list_node) | 473 | list_for_each_entry(pdd, &genpd->dev_list, list_node) |
438 | if (pdd->dev->driver && (!pm_runtime_suspended(pdd->dev) | 474 | if (pdd->dev->driver && (!pm_runtime_suspended(pdd->dev) |
439 | || pdd->dev->power.irq_safe || to_gpd_data(pdd)->always_on)) | 475 | || pdd->dev->power.irq_safe)) |
440 | not_suspended++; | 476 | not_suspended++; |
441 | 477 | ||
442 | if (not_suspended > genpd->in_progress) | 478 | if (not_suspended > genpd->in_progress) |
@@ -578,9 +614,6 @@ static int pm_genpd_runtime_suspend(struct device *dev) | |||
578 | 614 | ||
579 | might_sleep_if(!genpd->dev_irq_safe); | 615 | might_sleep_if(!genpd->dev_irq_safe); |
580 | 616 | ||
581 | if (dev_gpd_data(dev)->always_on) | ||
582 | return -EBUSY; | ||
583 | |||
584 | stop_ok = genpd->gov ? genpd->gov->stop_ok : NULL; | 617 | stop_ok = genpd->gov ? genpd->gov->stop_ok : NULL; |
585 | if (stop_ok && !stop_ok(dev)) | 618 | if (stop_ok && !stop_ok(dev)) |
586 | return -EBUSY; | 619 | return -EBUSY; |
@@ -629,7 +662,7 @@ static int pm_genpd_runtime_resume(struct device *dev) | |||
629 | 662 | ||
630 | /* If power.irq_safe, the PM domain is never powered off. */ | 663 | /* If power.irq_safe, the PM domain is never powered off. */ |
631 | if (dev->power.irq_safe) | 664 | if (dev->power.irq_safe) |
632 | return genpd_start_dev(genpd, dev); | 665 | return genpd_start_dev_no_timing(genpd, dev); |
633 | 666 | ||
634 | mutex_lock(&genpd->lock); | 667 | mutex_lock(&genpd->lock); |
635 | ret = __pm_genpd_poweron(genpd); | 668 | ret = __pm_genpd_poweron(genpd); |
@@ -697,6 +730,24 @@ static inline void genpd_power_off_work_fn(struct work_struct *work) {} | |||
697 | 730 | ||
698 | #ifdef CONFIG_PM_SLEEP | 731 | #ifdef CONFIG_PM_SLEEP |
699 | 732 | ||
733 | /** | ||
734 | * pm_genpd_present - Check if the given PM domain has been initialized. | ||
735 | * @genpd: PM domain to check. | ||
736 | */ | ||
737 | static bool pm_genpd_present(struct generic_pm_domain *genpd) | ||
738 | { | ||
739 | struct generic_pm_domain *gpd; | ||
740 | |||
741 | if (IS_ERR_OR_NULL(genpd)) | ||
742 | return false; | ||
743 | |||
744 | list_for_each_entry(gpd, &gpd_list, gpd_list_node) | ||
745 | if (gpd == genpd) | ||
746 | return true; | ||
747 | |||
748 | return false; | ||
749 | } | ||
750 | |||
700 | static bool genpd_dev_active_wakeup(struct generic_pm_domain *genpd, | 751 | static bool genpd_dev_active_wakeup(struct generic_pm_domain *genpd, |
701 | struct device *dev) | 752 | struct device *dev) |
702 | { | 753 | { |
@@ -750,9 +801,10 @@ static int genpd_thaw_dev(struct generic_pm_domain *genpd, struct device *dev) | |||
750 | * Check if the given PM domain can be powered off (during system suspend or | 801 | * Check if the given PM domain can be powered off (during system suspend or |
751 | * hibernation) and do that if so. Also, in that case propagate to its masters. | 802 | * hibernation) and do that if so. Also, in that case propagate to its masters. |
752 | * | 803 | * |
753 | * This function is only called in "noirq" stages of system power transitions, | 804 | * This function is only called in "noirq" and "syscore" stages of system power |
754 | * so it need not acquire locks (all of the "noirq" callbacks are executed | 805 | * transitions, so it need not acquire locks (all of the "noirq" callbacks are |
755 | * sequentially, so it is guaranteed that it will never run twice in parallel). | 806 | * executed sequentially, so it is guaranteed that it will never run twice in |
807 | * parallel). | ||
756 | */ | 808 | */ |
757 | static void pm_genpd_sync_poweroff(struct generic_pm_domain *genpd) | 809 | static void pm_genpd_sync_poweroff(struct generic_pm_domain *genpd) |
758 | { | 810 | { |
@@ -777,6 +829,33 @@ static void pm_genpd_sync_poweroff(struct generic_pm_domain *genpd) | |||
777 | } | 829 | } |
778 | 830 | ||
779 | /** | 831 | /** |
832 | * pm_genpd_sync_poweron - Synchronously power on a PM domain and its masters. | ||
833 | * @genpd: PM domain to power on. | ||
834 | * | ||
835 | * This function is only called in "noirq" and "syscore" stages of system power | ||
836 | * transitions, so it need not acquire locks (all of the "noirq" callbacks are | ||
837 | * executed sequentially, so it is guaranteed that it will never run twice in | ||
838 | * parallel). | ||
839 | */ | ||
840 | static void pm_genpd_sync_poweron(struct generic_pm_domain *genpd) | ||
841 | { | ||
842 | struct gpd_link *link; | ||
843 | |||
844 | if (genpd->status != GPD_STATE_POWER_OFF) | ||
845 | return; | ||
846 | |||
847 | list_for_each_entry(link, &genpd->slave_links, slave_node) { | ||
848 | pm_genpd_sync_poweron(link->master); | ||
849 | genpd_sd_counter_inc(link->master); | ||
850 | } | ||
851 | |||
852 | if (genpd->power_on) | ||
853 | genpd->power_on(genpd); | ||
854 | |||
855 | genpd->status = GPD_STATE_ACTIVE; | ||
856 | } | ||
857 | |||
858 | /** | ||
780 | * resume_needed - Check whether to resume a device before system suspend. | 859 | * resume_needed - Check whether to resume a device before system suspend. |
781 | * @dev: Device to check. | 860 | * @dev: Device to check. |
782 | * @genpd: PM domain the device belongs to. | 861 | * @genpd: PM domain the device belongs to. |
@@ -937,7 +1016,7 @@ static int pm_genpd_suspend_noirq(struct device *dev) | |||
937 | if (IS_ERR(genpd)) | 1016 | if (IS_ERR(genpd)) |
938 | return -EINVAL; | 1017 | return -EINVAL; |
939 | 1018 | ||
940 | if (genpd->suspend_power_off || dev_gpd_data(dev)->always_on | 1019 | if (genpd->suspend_power_off |
941 | || (dev->power.wakeup_path && genpd_dev_active_wakeup(genpd, dev))) | 1020 | || (dev->power.wakeup_path && genpd_dev_active_wakeup(genpd, dev))) |
942 | return 0; | 1021 | return 0; |
943 | 1022 | ||
@@ -970,7 +1049,7 @@ static int pm_genpd_resume_noirq(struct device *dev) | |||
970 | if (IS_ERR(genpd)) | 1049 | if (IS_ERR(genpd)) |
971 | return -EINVAL; | 1050 | return -EINVAL; |
972 | 1051 | ||
973 | if (genpd->suspend_power_off || dev_gpd_data(dev)->always_on | 1052 | if (genpd->suspend_power_off |
974 | || (dev->power.wakeup_path && genpd_dev_active_wakeup(genpd, dev))) | 1053 | || (dev->power.wakeup_path && genpd_dev_active_wakeup(genpd, dev))) |
975 | return 0; | 1054 | return 0; |
976 | 1055 | ||
@@ -979,7 +1058,7 @@ static int pm_genpd_resume_noirq(struct device *dev) | |||
979 | * guaranteed that this function will never run twice in parallel for | 1058 | * guaranteed that this function will never run twice in parallel for |
980 | * the same PM domain, so it is not necessary to use locking here. | 1059 | * the same PM domain, so it is not necessary to use locking here. |
981 | */ | 1060 | */ |
982 | pm_genpd_poweron(genpd); | 1061 | pm_genpd_sync_poweron(genpd); |
983 | genpd->suspended_count--; | 1062 | genpd->suspended_count--; |
984 | 1063 | ||
985 | return genpd_start_dev(genpd, dev); | 1064 | return genpd_start_dev(genpd, dev); |
@@ -1090,8 +1169,7 @@ static int pm_genpd_freeze_noirq(struct device *dev) | |||
1090 | if (IS_ERR(genpd)) | 1169 | if (IS_ERR(genpd)) |
1091 | return -EINVAL; | 1170 | return -EINVAL; |
1092 | 1171 | ||
1093 | return genpd->suspend_power_off || dev_gpd_data(dev)->always_on ? | 1172 | return genpd->suspend_power_off ? 0 : genpd_stop_dev(genpd, dev); |
1094 | 0 : genpd_stop_dev(genpd, dev); | ||
1095 | } | 1173 | } |
1096 | 1174 | ||
1097 | /** | 1175 | /** |
@@ -1111,8 +1189,7 @@ static int pm_genpd_thaw_noirq(struct device *dev) | |||
1111 | if (IS_ERR(genpd)) | 1189 | if (IS_ERR(genpd)) |
1112 | return -EINVAL; | 1190 | return -EINVAL; |
1113 | 1191 | ||
1114 | return genpd->suspend_power_off || dev_gpd_data(dev)->always_on ? | 1192 | return genpd->suspend_power_off ? 0 : genpd_start_dev(genpd, dev); |
1115 | 0 : genpd_start_dev(genpd, dev); | ||
1116 | } | 1193 | } |
1117 | 1194 | ||
1118 | /** | 1195 | /** |
@@ -1186,8 +1263,8 @@ static int pm_genpd_restore_noirq(struct device *dev) | |||
1186 | if (genpd->suspended_count++ == 0) { | 1263 | if (genpd->suspended_count++ == 0) { |
1187 | /* | 1264 | /* |
1188 | * The boot kernel might put the domain into arbitrary state, | 1265 | * The boot kernel might put the domain into arbitrary state, |
1189 | * so make it appear as powered off to pm_genpd_poweron(), so | 1266 | * so make it appear as powered off to pm_genpd_sync_poweron(), |
1190 | * that it tries to power it on in case it was really off. | 1267 | * so that it tries to power it on in case it was really off. |
1191 | */ | 1268 | */ |
1192 | genpd->status = GPD_STATE_POWER_OFF; | 1269 | genpd->status = GPD_STATE_POWER_OFF; |
1193 | if (genpd->suspend_power_off) { | 1270 | if (genpd->suspend_power_off) { |
@@ -1205,9 +1282,9 @@ static int pm_genpd_restore_noirq(struct device *dev) | |||
1205 | if (genpd->suspend_power_off) | 1282 | if (genpd->suspend_power_off) |
1206 | return 0; | 1283 | return 0; |
1207 | 1284 | ||
1208 | pm_genpd_poweron(genpd); | 1285 | pm_genpd_sync_poweron(genpd); |
1209 | 1286 | ||
1210 | return dev_gpd_data(dev)->always_on ? 0 : genpd_start_dev(genpd, dev); | 1287 | return genpd_start_dev(genpd, dev); |
1211 | } | 1288 | } |
1212 | 1289 | ||
1213 | /** | 1290 | /** |
@@ -1246,6 +1323,31 @@ static void pm_genpd_complete(struct device *dev) | |||
1246 | } | 1323 | } |
1247 | } | 1324 | } |
1248 | 1325 | ||
1326 | /** | ||
1327 | * pm_genpd_syscore_switch - Switch power during system core suspend or resume. | ||
1328 | * @dev: Device that normally is marked as "always on" to switch power for. | ||
1329 | * | ||
1330 | * This routine may only be called during the system core (syscore) suspend or | ||
1331 | * resume phase for devices whose "always on" flags are set. | ||
1332 | */ | ||
1333 | void pm_genpd_syscore_switch(struct device *dev, bool suspend) | ||
1334 | { | ||
1335 | struct generic_pm_domain *genpd; | ||
1336 | |||
1337 | genpd = dev_to_genpd(dev); | ||
1338 | if (!pm_genpd_present(genpd)) | ||
1339 | return; | ||
1340 | |||
1341 | if (suspend) { | ||
1342 | genpd->suspended_count++; | ||
1343 | pm_genpd_sync_poweroff(genpd); | ||
1344 | } else { | ||
1345 | pm_genpd_sync_poweron(genpd); | ||
1346 | genpd->suspended_count--; | ||
1347 | } | ||
1348 | } | ||
1349 | EXPORT_SYMBOL_GPL(pm_genpd_syscore_switch); | ||
1350 | |||
1249 | #else | 1351 | #else |
1250 | 1352 | ||
1251 | #define pm_genpd_prepare NULL | 1353 | #define pm_genpd_prepare NULL |
@@ -1393,6 +1495,19 @@ int __pm_genpd_of_add_device(struct device_node *genpd_node, struct device *dev, | |||
1393 | return __pm_genpd_add_device(genpd, dev, td); | 1495 | return __pm_genpd_add_device(genpd, dev, td); |
1394 | } | 1496 | } |
1395 | 1497 | ||
1498 | |||
1499 | /** | ||
1500 | * __pm_genpd_name_add_device - Find I/O PM domain and add a device to it. | ||
1501 | * @domain_name: Name of the PM domain to add the device to. | ||
1502 | * @dev: Device to be added. | ||
1503 | * @td: Set of PM QoS timing parameters to attach to the device. | ||
1504 | */ | ||
1505 | int __pm_genpd_name_add_device(const char *domain_name, struct device *dev, | ||
1506 | struct gpd_timing_data *td) | ||
1507 | { | ||
1508 | return __pm_genpd_add_device(pm_genpd_lookup_name(domain_name), dev, td); | ||
1509 | } | ||
1510 | |||
1396 | /** | 1511 | /** |
1397 | * pm_genpd_remove_device - Remove a device from an I/O PM domain. | 1512 | * pm_genpd_remove_device - Remove a device from an I/O PM domain. |
1398 | * @genpd: PM domain to remove the device from. | 1513 | * @genpd: PM domain to remove the device from. |
@@ -1455,26 +1570,6 @@ int pm_genpd_remove_device(struct generic_pm_domain *genpd, | |||
1455 | } | 1570 | } |
1456 | 1571 | ||
1457 | /** | 1572 | /** |
1458 | * pm_genpd_dev_always_on - Set/unset the "always on" flag for a given device. | ||
1459 | * @dev: Device to set/unset the flag for. | ||
1460 | * @val: The new value of the device's "always on" flag. | ||
1461 | */ | ||
1462 | void pm_genpd_dev_always_on(struct device *dev, bool val) | ||
1463 | { | ||
1464 | struct pm_subsys_data *psd; | ||
1465 | unsigned long flags; | ||
1466 | |||
1467 | spin_lock_irqsave(&dev->power.lock, flags); | ||
1468 | |||
1469 | psd = dev_to_psd(dev); | ||
1470 | if (psd && psd->domain_data) | ||
1471 | to_gpd_data(psd->domain_data)->always_on = val; | ||
1472 | |||
1473 | spin_unlock_irqrestore(&dev->power.lock, flags); | ||
1474 | } | ||
1475 | EXPORT_SYMBOL_GPL(pm_genpd_dev_always_on); | ||
1476 | |||
1477 | /** | ||
1478 | * pm_genpd_dev_need_restore - Set/unset the device's "need restore" flag. | 1573 | * pm_genpd_dev_need_restore - Set/unset the device's "need restore" flag. |
1479 | * @dev: Device to set/unset the flag for. | 1574 | * @dev: Device to set/unset the flag for. |
1480 | * @val: The new value of the device's "need restore" flag. | 1575 | * @val: The new value of the device's "need restore" flag. |
@@ -1505,7 +1600,8 @@ int pm_genpd_add_subdomain(struct generic_pm_domain *genpd, | |||
1505 | struct gpd_link *link; | 1600 | struct gpd_link *link; |
1506 | int ret = 0; | 1601 | int ret = 0; |
1507 | 1602 | ||
1508 | if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(subdomain)) | 1603 | if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(subdomain) |
1604 | || genpd == subdomain) | ||
1509 | return -EINVAL; | 1605 | return -EINVAL; |
1510 | 1606 | ||
1511 | start: | 1607 | start: |
@@ -1552,6 +1648,35 @@ int pm_genpd_add_subdomain(struct generic_pm_domain *genpd, | |||
1552 | } | 1648 | } |
1553 | 1649 | ||
1554 | /** | 1650 | /** |
1651 | * pm_genpd_add_subdomain_names - Add a subdomain to an I/O PM domain. | ||
1652 | * @master_name: Name of the master PM domain to add the subdomain to. | ||
1653 | * @subdomain_name: Name of the subdomain to be added. | ||
1654 | */ | ||
1655 | int pm_genpd_add_subdomain_names(const char *master_name, | ||
1656 | const char *subdomain_name) | ||
1657 | { | ||
1658 | struct generic_pm_domain *master = NULL, *subdomain = NULL, *gpd; | ||
1659 | |||
1660 | if (IS_ERR_OR_NULL(master_name) || IS_ERR_OR_NULL(subdomain_name)) | ||
1661 | return -EINVAL; | ||
1662 | |||
1663 | mutex_lock(&gpd_list_lock); | ||
1664 | list_for_each_entry(gpd, &gpd_list, gpd_list_node) { | ||
1665 | if (!master && !strcmp(gpd->name, master_name)) | ||
1666 | master = gpd; | ||
1667 | |||
1668 | if (!subdomain && !strcmp(gpd->name, subdomain_name)) | ||
1669 | subdomain = gpd; | ||
1670 | |||
1671 | if (master && subdomain) | ||
1672 | break; | ||
1673 | } | ||
1674 | mutex_unlock(&gpd_list_lock); | ||
1675 | |||
1676 | return pm_genpd_add_subdomain(master, subdomain); | ||
1677 | } | ||
1678 | |||
1679 | /** | ||
1555 | * pm_genpd_remove_subdomain - Remove a subdomain from an I/O PM domain. | 1680 | * pm_genpd_remove_subdomain - Remove a subdomain from an I/O PM domain. |
1556 | * @genpd: Master PM domain to remove the subdomain from. | 1681 | * @genpd: Master PM domain to remove the subdomain from. |
1557 | * @subdomain: Subdomain to be removed. | 1682 | * @subdomain: Subdomain to be removed. |
@@ -1704,7 +1829,16 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td) | |||
1704 | } | 1829 | } |
1705 | EXPORT_SYMBOL_GPL(__pm_genpd_remove_callbacks); | 1830 | EXPORT_SYMBOL_GPL(__pm_genpd_remove_callbacks); |
1706 | 1831 | ||
1707 | int genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state) | 1832 | /** |
1833 | * pm_genpd_attach_cpuidle - Connect the given PM domain with cpuidle. | ||
1834 | * @genpd: PM domain to be connected with cpuidle. | ||
1835 | * @state: cpuidle state this domain can disable/enable. | ||
1836 | * | ||
1837 | * Make a PM domain behave as though it contained a CPU core, that is, instead | ||
1838 | * of calling its power down routine it will enable the given cpuidle state so | ||
1839 | * that the cpuidle subsystem can power it down (if possible and desirable). | ||
1840 | */ | ||
1841 | int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state) | ||
1708 | { | 1842 | { |
1709 | struct cpuidle_driver *cpuidle_drv; | 1843 | struct cpuidle_driver *cpuidle_drv; |
1710 | struct gpd_cpu_data *cpu_data; | 1844 | struct gpd_cpu_data *cpu_data; |
@@ -1753,7 +1887,24 @@ int genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state) | |||
1753 | goto out; | 1887 | goto out; |
1754 | } | 1888 | } |
1755 | 1889 | ||
1756 | int genpd_detach_cpuidle(struct generic_pm_domain *genpd) | 1890 | /** |
1891 | * pm_genpd_name_attach_cpuidle - Find PM domain and connect cpuidle to it. | ||
1892 | * @name: Name of the domain to connect to cpuidle. | ||
1893 | * @state: cpuidle state this domain can manipulate. | ||
1894 | */ | ||
1895 | int pm_genpd_name_attach_cpuidle(const char *name, int state) | ||
1896 | { | ||
1897 | return pm_genpd_attach_cpuidle(pm_genpd_lookup_name(name), state); | ||
1898 | } | ||
1899 | |||
1900 | /** | ||
1901 | * pm_genpd_detach_cpuidle - Remove the cpuidle connection from a PM domain. | ||
1902 | * @genpd: PM domain to remove the cpuidle connection from. | ||
1903 | * | ||
1904 | * Remove the cpuidle connection set up by pm_genpd_attach_cpuidle() from the | ||
1905 | * given PM domain. | ||
1906 | */ | ||
1907 | int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd) | ||
1757 | { | 1908 | { |
1758 | struct gpd_cpu_data *cpu_data; | 1909 | struct gpd_cpu_data *cpu_data; |
1759 | struct cpuidle_state *idle_state; | 1910 | struct cpuidle_state *idle_state; |
@@ -1784,6 +1935,15 @@ int genpd_detach_cpuidle(struct generic_pm_domain *genpd) | |||
1784 | return ret; | 1935 | return ret; |
1785 | } | 1936 | } |
1786 | 1937 | ||
1938 | /** | ||
1939 | * pm_genpd_name_detach_cpuidle - Find PM domain and disconnect cpuidle from it. | ||
1940 | * @name: Name of the domain to disconnect cpuidle from. | ||
1941 | */ | ||
1942 | int pm_genpd_name_detach_cpuidle(const char *name) | ||
1943 | { | ||
1944 | return pm_genpd_detach_cpuidle(pm_genpd_lookup_name(name)); | ||
1945 | } | ||
1946 | |||
1787 | /* Default device callbacks for generic PM domains. */ | 1947 | /* Default device callbacks for generic PM domains. */ |
1788 | 1948 | ||
1789 | /** | 1949 | /** |
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index b0b072a88f5f..a3c1404c7933 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c | |||
@@ -57,20 +57,17 @@ static pm_message_t pm_transition; | |||
57 | static int async_error; | 57 | static int async_error; |
58 | 58 | ||
59 | /** | 59 | /** |
60 | * device_pm_init - Initialize the PM-related part of a device object. | 60 | * device_pm_sleep_init - Initialize system suspend-related device fields. |
61 | * @dev: Device object being initialized. | 61 | * @dev: Device object being initialized. |
62 | */ | 62 | */ |
63 | void device_pm_init(struct device *dev) | 63 | void device_pm_sleep_init(struct device *dev) |
64 | { | 64 | { |
65 | dev->power.is_prepared = false; | 65 | dev->power.is_prepared = false; |
66 | dev->power.is_suspended = false; | 66 | dev->power.is_suspended = false; |
67 | init_completion(&dev->power.completion); | 67 | init_completion(&dev->power.completion); |
68 | complete_all(&dev->power.completion); | 68 | complete_all(&dev->power.completion); |
69 | dev->power.wakeup = NULL; | 69 | dev->power.wakeup = NULL; |
70 | spin_lock_init(&dev->power.lock); | ||
71 | pm_runtime_init(dev); | ||
72 | INIT_LIST_HEAD(&dev->power.entry); | 70 | INIT_LIST_HEAD(&dev->power.entry); |
73 | dev->power.power_state = PMSG_INVALID; | ||
74 | } | 71 | } |
75 | 72 | ||
76 | /** | 73 | /** |
@@ -408,6 +405,9 @@ static int device_resume_noirq(struct device *dev, pm_message_t state) | |||
408 | TRACE_DEVICE(dev); | 405 | TRACE_DEVICE(dev); |
409 | TRACE_RESUME(0); | 406 | TRACE_RESUME(0); |
410 | 407 | ||
408 | if (dev->power.syscore) | ||
409 | goto Out; | ||
410 | |||
411 | if (dev->pm_domain) { | 411 | if (dev->pm_domain) { |
412 | info = "noirq power domain "; | 412 | info = "noirq power domain "; |
413 | callback = pm_noirq_op(&dev->pm_domain->ops, state); | 413 | callback = pm_noirq_op(&dev->pm_domain->ops, state); |
@@ -429,6 +429,7 @@ static int device_resume_noirq(struct device *dev, pm_message_t state) | |||
429 | 429 | ||
430 | error = dpm_run_callback(callback, dev, state, info); | 430 | error = dpm_run_callback(callback, dev, state, info); |
431 | 431 | ||
432 | Out: | ||
432 | TRACE_RESUME(error); | 433 | TRACE_RESUME(error); |
433 | return error; | 434 | return error; |
434 | } | 435 | } |
@@ -486,6 +487,9 @@ static int device_resume_early(struct device *dev, pm_message_t state) | |||
486 | TRACE_DEVICE(dev); | 487 | TRACE_DEVICE(dev); |
487 | TRACE_RESUME(0); | 488 | TRACE_RESUME(0); |
488 | 489 | ||
490 | if (dev->power.syscore) | ||
491 | goto Out; | ||
492 | |||
489 | if (dev->pm_domain) { | 493 | if (dev->pm_domain) { |
490 | info = "early power domain "; | 494 | info = "early power domain "; |
491 | callback = pm_late_early_op(&dev->pm_domain->ops, state); | 495 | callback = pm_late_early_op(&dev->pm_domain->ops, state); |
@@ -507,6 +511,7 @@ static int device_resume_early(struct device *dev, pm_message_t state) | |||
507 | 511 | ||
508 | error = dpm_run_callback(callback, dev, state, info); | 512 | error = dpm_run_callback(callback, dev, state, info); |
509 | 513 | ||
514 | Out: | ||
510 | TRACE_RESUME(error); | 515 | TRACE_RESUME(error); |
511 | return error; | 516 | return error; |
512 | } | 517 | } |
@@ -565,11 +570,13 @@ static int device_resume(struct device *dev, pm_message_t state, bool async) | |||
565 | pm_callback_t callback = NULL; | 570 | pm_callback_t callback = NULL; |
566 | char *info = NULL; | 571 | char *info = NULL; |
567 | int error = 0; | 572 | int error = 0; |
568 | bool put = false; | ||
569 | 573 | ||
570 | TRACE_DEVICE(dev); | 574 | TRACE_DEVICE(dev); |
571 | TRACE_RESUME(0); | 575 | TRACE_RESUME(0); |
572 | 576 | ||
577 | if (dev->power.syscore) | ||
578 | goto Complete; | ||
579 | |||
573 | dpm_wait(dev->parent, async); | 580 | dpm_wait(dev->parent, async); |
574 | device_lock(dev); | 581 | device_lock(dev); |
575 | 582 | ||
@@ -583,7 +590,6 @@ static int device_resume(struct device *dev, pm_message_t state, bool async) | |||
583 | goto Unlock; | 590 | goto Unlock; |
584 | 591 | ||
585 | pm_runtime_enable(dev); | 592 | pm_runtime_enable(dev); |
586 | put = true; | ||
587 | 593 | ||
588 | if (dev->pm_domain) { | 594 | if (dev->pm_domain) { |
589 | info = "power domain "; | 595 | info = "power domain "; |
@@ -632,13 +638,12 @@ static int device_resume(struct device *dev, pm_message_t state, bool async) | |||
632 | 638 | ||
633 | Unlock: | 639 | Unlock: |
634 | device_unlock(dev); | 640 | device_unlock(dev); |
641 | |||
642 | Complete: | ||
635 | complete_all(&dev->power.completion); | 643 | complete_all(&dev->power.completion); |
636 | 644 | ||
637 | TRACE_RESUME(error); | 645 | TRACE_RESUME(error); |
638 | 646 | ||
639 | if (put) | ||
640 | pm_runtime_put_sync(dev); | ||
641 | |||
642 | return error; | 647 | return error; |
643 | } | 648 | } |
644 | 649 | ||
@@ -722,6 +727,9 @@ static void device_complete(struct device *dev, pm_message_t state) | |||
722 | void (*callback)(struct device *) = NULL; | 727 | void (*callback)(struct device *) = NULL; |
723 | char *info = NULL; | 728 | char *info = NULL; |
724 | 729 | ||
730 | if (dev->power.syscore) | ||
731 | return; | ||
732 | |||
725 | device_lock(dev); | 733 | device_lock(dev); |
726 | 734 | ||
727 | if (dev->pm_domain) { | 735 | if (dev->pm_domain) { |
@@ -749,6 +757,8 @@ static void device_complete(struct device *dev, pm_message_t state) | |||
749 | } | 757 | } |
750 | 758 | ||
751 | device_unlock(dev); | 759 | device_unlock(dev); |
760 | |||
761 | pm_runtime_put_sync(dev); | ||
752 | } | 762 | } |
753 | 763 | ||
754 | /** | 764 | /** |
@@ -834,6 +844,9 @@ static int device_suspend_noirq(struct device *dev, pm_message_t state) | |||
834 | pm_callback_t callback = NULL; | 844 | pm_callback_t callback = NULL; |
835 | char *info = NULL; | 845 | char *info = NULL; |
836 | 846 | ||
847 | if (dev->power.syscore) | ||
848 | return 0; | ||
849 | |||
837 | if (dev->pm_domain) { | 850 | if (dev->pm_domain) { |
838 | info = "noirq power domain "; | 851 | info = "noirq power domain "; |
839 | callback = pm_noirq_op(&dev->pm_domain->ops, state); | 852 | callback = pm_noirq_op(&dev->pm_domain->ops, state); |
@@ -917,6 +930,9 @@ static int device_suspend_late(struct device *dev, pm_message_t state) | |||
917 | pm_callback_t callback = NULL; | 930 | pm_callback_t callback = NULL; |
918 | char *info = NULL; | 931 | char *info = NULL; |
919 | 932 | ||
933 | if (dev->power.syscore) | ||
934 | return 0; | ||
935 | |||
920 | if (dev->pm_domain) { | 936 | if (dev->pm_domain) { |
921 | info = "late power domain "; | 937 | info = "late power domain "; |
922 | callback = pm_late_early_op(&dev->pm_domain->ops, state); | 938 | callback = pm_late_early_op(&dev->pm_domain->ops, state); |
@@ -996,7 +1012,7 @@ int dpm_suspend_end(pm_message_t state) | |||
996 | 1012 | ||
997 | error = dpm_suspend_noirq(state); | 1013 | error = dpm_suspend_noirq(state); |
998 | if (error) { | 1014 | if (error) { |
999 | dpm_resume_early(state); | 1015 | dpm_resume_early(resume_event(state)); |
1000 | return error; | 1016 | return error; |
1001 | } | 1017 | } |
1002 | 1018 | ||
@@ -1043,16 +1059,23 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async) | |||
1043 | if (async_error) | 1059 | if (async_error) |
1044 | goto Complete; | 1060 | goto Complete; |
1045 | 1061 | ||
1046 | pm_runtime_get_noresume(dev); | 1062 | /* |
1063 | * If a device configured to wake up the system from sleep states | ||
1064 | * has been suspended at run time and there's a resume request pending | ||
1065 | * for it, this is equivalent to the device signaling wakeup, so the | ||
1066 | * system suspend operation should be aborted. | ||
1067 | */ | ||
1047 | if (pm_runtime_barrier(dev) && device_may_wakeup(dev)) | 1068 | if (pm_runtime_barrier(dev) && device_may_wakeup(dev)) |
1048 | pm_wakeup_event(dev, 0); | 1069 | pm_wakeup_event(dev, 0); |
1049 | 1070 | ||
1050 | if (pm_wakeup_pending()) { | 1071 | if (pm_wakeup_pending()) { |
1051 | pm_runtime_put_sync(dev); | ||
1052 | async_error = -EBUSY; | 1072 | async_error = -EBUSY; |
1053 | goto Complete; | 1073 | goto Complete; |
1054 | } | 1074 | } |
1055 | 1075 | ||
1076 | if (dev->power.syscore) | ||
1077 | goto Complete; | ||
1078 | |||
1056 | device_lock(dev); | 1079 | device_lock(dev); |
1057 | 1080 | ||
1058 | if (dev->pm_domain) { | 1081 | if (dev->pm_domain) { |
@@ -1111,12 +1134,10 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async) | |||
1111 | Complete: | 1134 | Complete: |
1112 | complete_all(&dev->power.completion); | 1135 | complete_all(&dev->power.completion); |
1113 | 1136 | ||
1114 | if (error) { | 1137 | if (error) |
1115 | pm_runtime_put_sync(dev); | ||
1116 | async_error = error; | 1138 | async_error = error; |
1117 | } else if (dev->power.is_suspended) { | 1139 | else if (dev->power.is_suspended) |
1118 | __pm_runtime_disable(dev, false); | 1140 | __pm_runtime_disable(dev, false); |
1119 | } | ||
1120 | 1141 | ||
1121 | return error; | 1142 | return error; |
1122 | } | 1143 | } |
@@ -1209,6 +1230,17 @@ static int device_prepare(struct device *dev, pm_message_t state) | |||
1209 | char *info = NULL; | 1230 | char *info = NULL; |
1210 | int error = 0; | 1231 | int error = 0; |
1211 | 1232 | ||
1233 | if (dev->power.syscore) | ||
1234 | return 0; | ||
1235 | |||
1236 | /* | ||
1237 | * If a device's parent goes into runtime suspend at the wrong time, | ||
1238 | * it won't be possible to resume the device. To prevent this we | ||
1239 | * block runtime suspend here, during the prepare phase, and allow | ||
1240 | * it again during the complete phase. | ||
1241 | */ | ||
1242 | pm_runtime_get_noresume(dev); | ||
1243 | |||
1212 | device_lock(dev); | 1244 | device_lock(dev); |
1213 | 1245 | ||
1214 | dev->power.wakeup_path = device_may_wakeup(dev); | 1246 | dev->power.wakeup_path = device_may_wakeup(dev); |
diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c index ac993eafec82..d9468642fc41 100644 --- a/drivers/base/power/opp.c +++ b/drivers/base/power/opp.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <linux/rculist.h> | 22 | #include <linux/rculist.h> |
23 | #include <linux/rcupdate.h> | 23 | #include <linux/rcupdate.h> |
24 | #include <linux/opp.h> | 24 | #include <linux/opp.h> |
25 | #include <linux/of.h> | ||
25 | 26 | ||
26 | /* | 27 | /* |
27 | * Internal data structure organization with the OPP layer library is as | 28 | * Internal data structure organization with the OPP layer library is as |
@@ -674,3 +675,49 @@ struct srcu_notifier_head *opp_get_notifier(struct device *dev) | |||
674 | 675 | ||
675 | return &dev_opp->head; | 676 | return &dev_opp->head; |
676 | } | 677 | } |
678 | |||
679 | #ifdef CONFIG_OF | ||
680 | /** | ||
681 | * of_init_opp_table() - Initialize opp table from device tree | ||
682 | * @dev: device pointer used to lookup device OPPs. | ||
683 | * | ||
684 | * Register the initial OPP table with the OPP library for given device. | ||
685 | */ | ||
686 | int of_init_opp_table(struct device *dev) | ||
687 | { | ||
688 | const struct property *prop; | ||
689 | const __be32 *val; | ||
690 | int nr; | ||
691 | |||
692 | prop = of_find_property(dev->of_node, "operating-points", NULL); | ||
693 | if (!prop) | ||
694 | return -ENODEV; | ||
695 | if (!prop->value) | ||
696 | return -ENODATA; | ||
697 | |||
698 | /* | ||
699 | * Each OPP is a set of tuples consisting of frequency and | ||
700 | * voltage like <freq-kHz vol-uV>. | ||
701 | */ | ||
702 | nr = prop->length / sizeof(u32); | ||
703 | if (nr % 2) { | ||
704 | dev_err(dev, "%s: Invalid OPP list\n", __func__); | ||
705 | return -EINVAL; | ||
706 | } | ||
707 | |||
708 | val = prop->value; | ||
709 | while (nr) { | ||
710 | unsigned long freq = be32_to_cpup(val++) * 1000; | ||
711 | unsigned long volt = be32_to_cpup(val++); | ||
712 | |||
713 | if (opp_add(dev, freq, volt)) { | ||
714 | dev_warn(dev, "%s: Failed to add OPP %ld\n", | ||
715 | __func__, freq); | ||
716 | continue; | ||
717 | } | ||
718 | nr -= 2; | ||
719 | } | ||
720 | |||
721 | return 0; | ||
722 | } | ||
723 | #endif | ||
diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h index eeb4bff9505c..0dbfdf4419af 100644 --- a/drivers/base/power/power.h +++ b/drivers/base/power/power.h | |||
@@ -1,12 +1,32 @@ | |||
1 | #include <linux/pm_qos.h> | 1 | #include <linux/pm_qos.h> |
2 | 2 | ||
3 | static inline void device_pm_init_common(struct device *dev) | ||
4 | { | ||
5 | if (!dev->power.early_init) { | ||
6 | spin_lock_init(&dev->power.lock); | ||
7 | dev->power.power_state = PMSG_INVALID; | ||
8 | dev->power.early_init = true; | ||
9 | } | ||
10 | } | ||
11 | |||
3 | #ifdef CONFIG_PM_RUNTIME | 12 | #ifdef CONFIG_PM_RUNTIME |
4 | 13 | ||
14 | static inline void pm_runtime_early_init(struct device *dev) | ||
15 | { | ||
16 | dev->power.disable_depth = 1; | ||
17 | device_pm_init_common(dev); | ||
18 | } | ||
19 | |||
5 | extern void pm_runtime_init(struct device *dev); | 20 | extern void pm_runtime_init(struct device *dev); |
6 | extern void pm_runtime_remove(struct device *dev); | 21 | extern void pm_runtime_remove(struct device *dev); |
7 | 22 | ||
8 | #else /* !CONFIG_PM_RUNTIME */ | 23 | #else /* !CONFIG_PM_RUNTIME */ |
9 | 24 | ||
25 | static inline void pm_runtime_early_init(struct device *dev) | ||
26 | { | ||
27 | device_pm_init_common(dev); | ||
28 | } | ||
29 | |||
10 | static inline void pm_runtime_init(struct device *dev) {} | 30 | static inline void pm_runtime_init(struct device *dev) {} |
11 | static inline void pm_runtime_remove(struct device *dev) {} | 31 | static inline void pm_runtime_remove(struct device *dev) {} |
12 | 32 | ||
@@ -25,7 +45,7 @@ static inline struct device *to_device(struct list_head *entry) | |||
25 | return container_of(entry, struct device, power.entry); | 45 | return container_of(entry, struct device, power.entry); |
26 | } | 46 | } |
27 | 47 | ||
28 | extern void device_pm_init(struct device *dev); | 48 | extern void device_pm_sleep_init(struct device *dev); |
29 | extern void device_pm_add(struct device *); | 49 | extern void device_pm_add(struct device *); |
30 | extern void device_pm_remove(struct device *); | 50 | extern void device_pm_remove(struct device *); |
31 | extern void device_pm_move_before(struct device *, struct device *); | 51 | extern void device_pm_move_before(struct device *, struct device *); |
@@ -34,12 +54,7 @@ extern void device_pm_move_last(struct device *); | |||
34 | 54 | ||
35 | #else /* !CONFIG_PM_SLEEP */ | 55 | #else /* !CONFIG_PM_SLEEP */ |
36 | 56 | ||
37 | static inline void device_pm_init(struct device *dev) | 57 | static inline void device_pm_sleep_init(struct device *dev) {} |
38 | { | ||
39 | spin_lock_init(&dev->power.lock); | ||
40 | dev->power.power_state = PMSG_INVALID; | ||
41 | pm_runtime_init(dev); | ||
42 | } | ||
43 | 58 | ||
44 | static inline void device_pm_add(struct device *dev) | 59 | static inline void device_pm_add(struct device *dev) |
45 | { | 60 | { |
@@ -60,6 +75,13 @@ static inline void device_pm_move_last(struct device *dev) {} | |||
60 | 75 | ||
61 | #endif /* !CONFIG_PM_SLEEP */ | 76 | #endif /* !CONFIG_PM_SLEEP */ |
62 | 77 | ||
78 | static inline void device_pm_init(struct device *dev) | ||
79 | { | ||
80 | device_pm_init_common(dev); | ||
81 | device_pm_sleep_init(dev); | ||
82 | pm_runtime_init(dev); | ||
83 | } | ||
84 | |||
63 | #ifdef CONFIG_PM | 85 | #ifdef CONFIG_PM |
64 | 86 | ||
65 | /* | 87 | /* |
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 7d9c1cb1c39a..3148b10dc2e5 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c | |||
@@ -509,6 +509,9 @@ static int rpm_resume(struct device *dev, int rpmflags) | |||
509 | repeat: | 509 | repeat: |
510 | if (dev->power.runtime_error) | 510 | if (dev->power.runtime_error) |
511 | retval = -EINVAL; | 511 | retval = -EINVAL; |
512 | else if (dev->power.disable_depth == 1 && dev->power.is_suspended | ||
513 | && dev->power.runtime_status == RPM_ACTIVE) | ||
514 | retval = 1; | ||
512 | else if (dev->power.disable_depth > 0) | 515 | else if (dev->power.disable_depth > 0) |
513 | retval = -EACCES; | 516 | retval = -EACCES; |
514 | if (retval) | 517 | if (retval) |
diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c index cbb463b3a750..e6ee5e80e546 100644 --- a/drivers/base/power/wakeup.c +++ b/drivers/base/power/wakeup.c | |||
@@ -127,6 +127,8 @@ EXPORT_SYMBOL_GPL(wakeup_source_destroy); | |||
127 | */ | 127 | */ |
128 | void wakeup_source_add(struct wakeup_source *ws) | 128 | void wakeup_source_add(struct wakeup_source *ws) |
129 | { | 129 | { |
130 | unsigned long flags; | ||
131 | |||
130 | if (WARN_ON(!ws)) | 132 | if (WARN_ON(!ws)) |
131 | return; | 133 | return; |
132 | 134 | ||
@@ -135,9 +137,9 @@ void wakeup_source_add(struct wakeup_source *ws) | |||
135 | ws->active = false; | 137 | ws->active = false; |
136 | ws->last_time = ktime_get(); | 138 | ws->last_time = ktime_get(); |
137 | 139 | ||
138 | spin_lock_irq(&events_lock); | 140 | spin_lock_irqsave(&events_lock, flags); |
139 | list_add_rcu(&ws->entry, &wakeup_sources); | 141 | list_add_rcu(&ws->entry, &wakeup_sources); |
140 | spin_unlock_irq(&events_lock); | 142 | spin_unlock_irqrestore(&events_lock, flags); |
141 | } | 143 | } |
142 | EXPORT_SYMBOL_GPL(wakeup_source_add); | 144 | EXPORT_SYMBOL_GPL(wakeup_source_add); |
143 | 145 | ||
@@ -147,12 +149,14 @@ EXPORT_SYMBOL_GPL(wakeup_source_add); | |||
147 | */ | 149 | */ |
148 | void wakeup_source_remove(struct wakeup_source *ws) | 150 | void wakeup_source_remove(struct wakeup_source *ws) |
149 | { | 151 | { |
152 | unsigned long flags; | ||
153 | |||
150 | if (WARN_ON(!ws)) | 154 | if (WARN_ON(!ws)) |
151 | return; | 155 | return; |
152 | 156 | ||
153 | spin_lock_irq(&events_lock); | 157 | spin_lock_irqsave(&events_lock, flags); |
154 | list_del_rcu(&ws->entry); | 158 | list_del_rcu(&ws->entry); |
155 | spin_unlock_irq(&events_lock); | 159 | spin_unlock_irqrestore(&events_lock, flags); |
156 | synchronize_rcu(); | 160 | synchronize_rcu(); |
157 | } | 161 | } |
158 | EXPORT_SYMBOL_GPL(wakeup_source_remove); | 162 | EXPORT_SYMBOL_GPL(wakeup_source_remove); |
@@ -649,6 +653,31 @@ void pm_wakeup_event(struct device *dev, unsigned int msec) | |||
649 | } | 653 | } |
650 | EXPORT_SYMBOL_GPL(pm_wakeup_event); | 654 | EXPORT_SYMBOL_GPL(pm_wakeup_event); |
651 | 655 | ||
656 | static void print_active_wakeup_sources(void) | ||
657 | { | ||
658 | struct wakeup_source *ws; | ||
659 | int active = 0; | ||
660 | struct wakeup_source *last_activity_ws = NULL; | ||
661 | |||
662 | rcu_read_lock(); | ||
663 | list_for_each_entry_rcu(ws, &wakeup_sources, entry) { | ||
664 | if (ws->active) { | ||
665 | pr_info("active wakeup source: %s\n", ws->name); | ||
666 | active = 1; | ||
667 | } else if (!active && | ||
668 | (!last_activity_ws || | ||
669 | ktime_to_ns(ws->last_time) > | ||
670 | ktime_to_ns(last_activity_ws->last_time))) { | ||
671 | last_activity_ws = ws; | ||
672 | } | ||
673 | } | ||
674 | |||
675 | if (!active && last_activity_ws) | ||
676 | pr_info("last active wakeup source: %s\n", | ||
677 | last_activity_ws->name); | ||
678 | rcu_read_unlock(); | ||
679 | } | ||
680 | |||
652 | /** | 681 | /** |
653 | * pm_wakeup_pending - Check if power transition in progress should be aborted. | 682 | * pm_wakeup_pending - Check if power transition in progress should be aborted. |
654 | * | 683 | * |
@@ -671,6 +700,10 @@ bool pm_wakeup_pending(void) | |||
671 | events_check_enabled = !ret; | 700 | events_check_enabled = !ret; |
672 | } | 701 | } |
673 | spin_unlock_irqrestore(&events_lock, flags); | 702 | spin_unlock_irqrestore(&events_lock, flags); |
703 | |||
704 | if (ret) | ||
705 | print_active_wakeup_sources(); | ||
706 | |||
674 | return ret; | 707 | return ret; |
675 | } | 708 | } |
676 | 709 | ||
@@ -723,15 +756,16 @@ bool pm_get_wakeup_count(unsigned int *count, bool block) | |||
723 | bool pm_save_wakeup_count(unsigned int count) | 756 | bool pm_save_wakeup_count(unsigned int count) |
724 | { | 757 | { |
725 | unsigned int cnt, inpr; | 758 | unsigned int cnt, inpr; |
759 | unsigned long flags; | ||
726 | 760 | ||
727 | events_check_enabled = false; | 761 | events_check_enabled = false; |
728 | spin_lock_irq(&events_lock); | 762 | spin_lock_irqsave(&events_lock, flags); |
729 | split_counters(&cnt, &inpr); | 763 | split_counters(&cnt, &inpr); |
730 | if (cnt == count && inpr == 0) { | 764 | if (cnt == count && inpr == 0) { |
731 | saved_count = count; | 765 | saved_count = count; |
732 | events_check_enabled = true; | 766 | events_check_enabled = true; |
733 | } | 767 | } |
734 | spin_unlock_irq(&events_lock); | 768 | spin_unlock_irqrestore(&events_lock, flags); |
735 | return events_check_enabled; | 769 | return events_check_enabled; |
736 | } | 770 | } |
737 | 771 | ||
diff --git a/drivers/clocksource/sh_cmt.c b/drivers/clocksource/sh_cmt.c index 98b06baafcc6..a5f7829f2799 100644 --- a/drivers/clocksource/sh_cmt.c +++ b/drivers/clocksource/sh_cmt.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <linux/slab.h> | 33 | #include <linux/slab.h> |
34 | #include <linux/module.h> | 34 | #include <linux/module.h> |
35 | #include <linux/pm_domain.h> | 35 | #include <linux/pm_domain.h> |
36 | #include <linux/pm_runtime.h> | ||
36 | 37 | ||
37 | struct sh_cmt_priv { | 38 | struct sh_cmt_priv { |
38 | void __iomem *mapbase; | 39 | void __iomem *mapbase; |
@@ -52,6 +53,7 @@ struct sh_cmt_priv { | |||
52 | struct clock_event_device ced; | 53 | struct clock_event_device ced; |
53 | struct clocksource cs; | 54 | struct clocksource cs; |
54 | unsigned long total_cycles; | 55 | unsigned long total_cycles; |
56 | bool cs_enabled; | ||
55 | }; | 57 | }; |
56 | 58 | ||
57 | static DEFINE_RAW_SPINLOCK(sh_cmt_lock); | 59 | static DEFINE_RAW_SPINLOCK(sh_cmt_lock); |
@@ -155,6 +157,9 @@ static int sh_cmt_enable(struct sh_cmt_priv *p, unsigned long *rate) | |||
155 | { | 157 | { |
156 | int k, ret; | 158 | int k, ret; |
157 | 159 | ||
160 | pm_runtime_get_sync(&p->pdev->dev); | ||
161 | dev_pm_syscore_device(&p->pdev->dev, true); | ||
162 | |||
158 | /* enable clock */ | 163 | /* enable clock */ |
159 | ret = clk_enable(p->clk); | 164 | ret = clk_enable(p->clk); |
160 | if (ret) { | 165 | if (ret) { |
@@ -221,6 +226,9 @@ static void sh_cmt_disable(struct sh_cmt_priv *p) | |||
221 | 226 | ||
222 | /* stop clock */ | 227 | /* stop clock */ |
223 | clk_disable(p->clk); | 228 | clk_disable(p->clk); |
229 | |||
230 | dev_pm_syscore_device(&p->pdev->dev, false); | ||
231 | pm_runtime_put(&p->pdev->dev); | ||
224 | } | 232 | } |
225 | 233 | ||
226 | /* private flags */ | 234 | /* private flags */ |
@@ -451,22 +459,42 @@ static int sh_cmt_clocksource_enable(struct clocksource *cs) | |||
451 | int ret; | 459 | int ret; |
452 | struct sh_cmt_priv *p = cs_to_sh_cmt(cs); | 460 | struct sh_cmt_priv *p = cs_to_sh_cmt(cs); |
453 | 461 | ||
462 | WARN_ON(p->cs_enabled); | ||
463 | |||
454 | p->total_cycles = 0; | 464 | p->total_cycles = 0; |
455 | 465 | ||
456 | ret = sh_cmt_start(p, FLAG_CLOCKSOURCE); | 466 | ret = sh_cmt_start(p, FLAG_CLOCKSOURCE); |
457 | if (!ret) | 467 | if (!ret) { |
458 | __clocksource_updatefreq_hz(cs, p->rate); | 468 | __clocksource_updatefreq_hz(cs, p->rate); |
469 | p->cs_enabled = true; | ||
470 | } | ||
459 | return ret; | 471 | return ret; |
460 | } | 472 | } |
461 | 473 | ||
462 | static void sh_cmt_clocksource_disable(struct clocksource *cs) | 474 | static void sh_cmt_clocksource_disable(struct clocksource *cs) |
463 | { | 475 | { |
464 | sh_cmt_stop(cs_to_sh_cmt(cs), FLAG_CLOCKSOURCE); | 476 | struct sh_cmt_priv *p = cs_to_sh_cmt(cs); |
477 | |||
478 | WARN_ON(!p->cs_enabled); | ||
479 | |||
480 | sh_cmt_stop(p, FLAG_CLOCKSOURCE); | ||
481 | p->cs_enabled = false; | ||
482 | } | ||
483 | |||
484 | static void sh_cmt_clocksource_suspend(struct clocksource *cs) | ||
485 | { | ||
486 | struct sh_cmt_priv *p = cs_to_sh_cmt(cs); | ||
487 | |||
488 | sh_cmt_stop(p, FLAG_CLOCKSOURCE); | ||
489 | pm_genpd_syscore_poweroff(&p->pdev->dev); | ||
465 | } | 490 | } |
466 | 491 | ||
467 | static void sh_cmt_clocksource_resume(struct clocksource *cs) | 492 | static void sh_cmt_clocksource_resume(struct clocksource *cs) |
468 | { | 493 | { |
469 | sh_cmt_start(cs_to_sh_cmt(cs), FLAG_CLOCKSOURCE); | 494 | struct sh_cmt_priv *p = cs_to_sh_cmt(cs); |
495 | |||
496 | pm_genpd_syscore_poweron(&p->pdev->dev); | ||
497 | sh_cmt_start(p, FLAG_CLOCKSOURCE); | ||
470 | } | 498 | } |
471 | 499 | ||
472 | static int sh_cmt_register_clocksource(struct sh_cmt_priv *p, | 500 | static int sh_cmt_register_clocksource(struct sh_cmt_priv *p, |
@@ -479,7 +507,7 @@ static int sh_cmt_register_clocksource(struct sh_cmt_priv *p, | |||
479 | cs->read = sh_cmt_clocksource_read; | 507 | cs->read = sh_cmt_clocksource_read; |
480 | cs->enable = sh_cmt_clocksource_enable; | 508 | cs->enable = sh_cmt_clocksource_enable; |
481 | cs->disable = sh_cmt_clocksource_disable; | 509 | cs->disable = sh_cmt_clocksource_disable; |
482 | cs->suspend = sh_cmt_clocksource_disable; | 510 | cs->suspend = sh_cmt_clocksource_suspend; |
483 | cs->resume = sh_cmt_clocksource_resume; | 511 | cs->resume = sh_cmt_clocksource_resume; |
484 | cs->mask = CLOCKSOURCE_MASK(sizeof(unsigned long) * 8); | 512 | cs->mask = CLOCKSOURCE_MASK(sizeof(unsigned long) * 8); |
485 | cs->flags = CLOCK_SOURCE_IS_CONTINUOUS; | 513 | cs->flags = CLOCK_SOURCE_IS_CONTINUOUS; |
@@ -562,6 +590,16 @@ static int sh_cmt_clock_event_next(unsigned long delta, | |||
562 | return 0; | 590 | return 0; |
563 | } | 591 | } |
564 | 592 | ||
593 | static void sh_cmt_clock_event_suspend(struct clock_event_device *ced) | ||
594 | { | ||
595 | pm_genpd_syscore_poweroff(&ced_to_sh_cmt(ced)->pdev->dev); | ||
596 | } | ||
597 | |||
598 | static void sh_cmt_clock_event_resume(struct clock_event_device *ced) | ||
599 | { | ||
600 | pm_genpd_syscore_poweron(&ced_to_sh_cmt(ced)->pdev->dev); | ||
601 | } | ||
602 | |||
565 | static void sh_cmt_register_clockevent(struct sh_cmt_priv *p, | 603 | static void sh_cmt_register_clockevent(struct sh_cmt_priv *p, |
566 | char *name, unsigned long rating) | 604 | char *name, unsigned long rating) |
567 | { | 605 | { |
@@ -576,6 +614,8 @@ static void sh_cmt_register_clockevent(struct sh_cmt_priv *p, | |||
576 | ced->cpumask = cpumask_of(0); | 614 | ced->cpumask = cpumask_of(0); |
577 | ced->set_next_event = sh_cmt_clock_event_next; | 615 | ced->set_next_event = sh_cmt_clock_event_next; |
578 | ced->set_mode = sh_cmt_clock_event_mode; | 616 | ced->set_mode = sh_cmt_clock_event_mode; |
617 | ced->suspend = sh_cmt_clock_event_suspend; | ||
618 | ced->resume = sh_cmt_clock_event_resume; | ||
579 | 619 | ||
580 | dev_info(&p->pdev->dev, "used for clock events\n"); | 620 | dev_info(&p->pdev->dev, "used for clock events\n"); |
581 | clockevents_register_device(ced); | 621 | clockevents_register_device(ced); |
@@ -670,6 +710,7 @@ static int sh_cmt_setup(struct sh_cmt_priv *p, struct platform_device *pdev) | |||
670 | dev_err(&p->pdev->dev, "registration failed\n"); | 710 | dev_err(&p->pdev->dev, "registration failed\n"); |
671 | goto err1; | 711 | goto err1; |
672 | } | 712 | } |
713 | p->cs_enabled = false; | ||
673 | 714 | ||
674 | ret = setup_irq(irq, &p->irqaction); | 715 | ret = setup_irq(irq, &p->irqaction); |
675 | if (ret) { | 716 | if (ret) { |
@@ -688,14 +729,17 @@ err0: | |||
688 | static int __devinit sh_cmt_probe(struct platform_device *pdev) | 729 | static int __devinit sh_cmt_probe(struct platform_device *pdev) |
689 | { | 730 | { |
690 | struct sh_cmt_priv *p = platform_get_drvdata(pdev); | 731 | struct sh_cmt_priv *p = platform_get_drvdata(pdev); |
732 | struct sh_timer_config *cfg = pdev->dev.platform_data; | ||
691 | int ret; | 733 | int ret; |
692 | 734 | ||
693 | if (!is_early_platform_device(pdev)) | 735 | if (!is_early_platform_device(pdev)) { |
694 | pm_genpd_dev_always_on(&pdev->dev, true); | 736 | pm_runtime_set_active(&pdev->dev); |
737 | pm_runtime_enable(&pdev->dev); | ||
738 | } | ||
695 | 739 | ||
696 | if (p) { | 740 | if (p) { |
697 | dev_info(&pdev->dev, "kept as earlytimer\n"); | 741 | dev_info(&pdev->dev, "kept as earlytimer\n"); |
698 | return 0; | 742 | goto out; |
699 | } | 743 | } |
700 | 744 | ||
701 | p = kmalloc(sizeof(*p), GFP_KERNEL); | 745 | p = kmalloc(sizeof(*p), GFP_KERNEL); |
@@ -708,8 +752,19 @@ static int __devinit sh_cmt_probe(struct platform_device *pdev) | |||
708 | if (ret) { | 752 | if (ret) { |
709 | kfree(p); | 753 | kfree(p); |
710 | platform_set_drvdata(pdev, NULL); | 754 | platform_set_drvdata(pdev, NULL); |
755 | pm_runtime_idle(&pdev->dev); | ||
756 | return ret; | ||
711 | } | 757 | } |
712 | return ret; | 758 | if (is_early_platform_device(pdev)) |
759 | return 0; | ||
760 | |||
761 | out: | ||
762 | if (cfg->clockevent_rating || cfg->clocksource_rating) | ||
763 | pm_runtime_irq_safe(&pdev->dev); | ||
764 | else | ||
765 | pm_runtime_idle(&pdev->dev); | ||
766 | |||
767 | return 0; | ||
713 | } | 768 | } |
714 | 769 | ||
715 | static int __devexit sh_cmt_remove(struct platform_device *pdev) | 770 | static int __devexit sh_cmt_remove(struct platform_device *pdev) |
diff --git a/drivers/clocksource/sh_mtu2.c b/drivers/clocksource/sh_mtu2.c index d9b76ca64a61..c5eea858054a 100644 --- a/drivers/clocksource/sh_mtu2.c +++ b/drivers/clocksource/sh_mtu2.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include <linux/slab.h> | 32 | #include <linux/slab.h> |
33 | #include <linux/module.h> | 33 | #include <linux/module.h> |
34 | #include <linux/pm_domain.h> | 34 | #include <linux/pm_domain.h> |
35 | #include <linux/pm_runtime.h> | ||
35 | 36 | ||
36 | struct sh_mtu2_priv { | 37 | struct sh_mtu2_priv { |
37 | void __iomem *mapbase; | 38 | void __iomem *mapbase; |
@@ -123,6 +124,9 @@ static int sh_mtu2_enable(struct sh_mtu2_priv *p) | |||
123 | { | 124 | { |
124 | int ret; | 125 | int ret; |
125 | 126 | ||
127 | pm_runtime_get_sync(&p->pdev->dev); | ||
128 | dev_pm_syscore_device(&p->pdev->dev, true); | ||
129 | |||
126 | /* enable clock */ | 130 | /* enable clock */ |
127 | ret = clk_enable(p->clk); | 131 | ret = clk_enable(p->clk); |
128 | if (ret) { | 132 | if (ret) { |
@@ -157,6 +161,9 @@ static void sh_mtu2_disable(struct sh_mtu2_priv *p) | |||
157 | 161 | ||
158 | /* stop clock */ | 162 | /* stop clock */ |
159 | clk_disable(p->clk); | 163 | clk_disable(p->clk); |
164 | |||
165 | dev_pm_syscore_device(&p->pdev->dev, false); | ||
166 | pm_runtime_put(&p->pdev->dev); | ||
160 | } | 167 | } |
161 | 168 | ||
162 | static irqreturn_t sh_mtu2_interrupt(int irq, void *dev_id) | 169 | static irqreturn_t sh_mtu2_interrupt(int irq, void *dev_id) |
@@ -208,6 +215,16 @@ static void sh_mtu2_clock_event_mode(enum clock_event_mode mode, | |||
208 | } | 215 | } |
209 | } | 216 | } |
210 | 217 | ||
218 | static void sh_mtu2_clock_event_suspend(struct clock_event_device *ced) | ||
219 | { | ||
220 | pm_genpd_syscore_poweroff(&ced_to_sh_mtu2(ced)->pdev->dev); | ||
221 | } | ||
222 | |||
223 | static void sh_mtu2_clock_event_resume(struct clock_event_device *ced) | ||
224 | { | ||
225 | pm_genpd_syscore_poweron(&ced_to_sh_mtu2(ced)->pdev->dev); | ||
226 | } | ||
227 | |||
211 | static void sh_mtu2_register_clockevent(struct sh_mtu2_priv *p, | 228 | static void sh_mtu2_register_clockevent(struct sh_mtu2_priv *p, |
212 | char *name, unsigned long rating) | 229 | char *name, unsigned long rating) |
213 | { | 230 | { |
@@ -221,6 +238,8 @@ static void sh_mtu2_register_clockevent(struct sh_mtu2_priv *p, | |||
221 | ced->rating = rating; | 238 | ced->rating = rating; |
222 | ced->cpumask = cpumask_of(0); | 239 | ced->cpumask = cpumask_of(0); |
223 | ced->set_mode = sh_mtu2_clock_event_mode; | 240 | ced->set_mode = sh_mtu2_clock_event_mode; |
241 | ced->suspend = sh_mtu2_clock_event_suspend; | ||
242 | ced->resume = sh_mtu2_clock_event_resume; | ||
224 | 243 | ||
225 | dev_info(&p->pdev->dev, "used for clock events\n"); | 244 | dev_info(&p->pdev->dev, "used for clock events\n"); |
226 | clockevents_register_device(ced); | 245 | clockevents_register_device(ced); |
@@ -305,14 +324,17 @@ static int sh_mtu2_setup(struct sh_mtu2_priv *p, struct platform_device *pdev) | |||
305 | static int __devinit sh_mtu2_probe(struct platform_device *pdev) | 324 | static int __devinit sh_mtu2_probe(struct platform_device *pdev) |
306 | { | 325 | { |
307 | struct sh_mtu2_priv *p = platform_get_drvdata(pdev); | 326 | struct sh_mtu2_priv *p = platform_get_drvdata(pdev); |
327 | struct sh_timer_config *cfg = pdev->dev.platform_data; | ||
308 | int ret; | 328 | int ret; |
309 | 329 | ||
310 | if (!is_early_platform_device(pdev)) | 330 | if (!is_early_platform_device(pdev)) { |
311 | pm_genpd_dev_always_on(&pdev->dev, true); | 331 | pm_runtime_set_active(&pdev->dev); |
332 | pm_runtime_enable(&pdev->dev); | ||
333 | } | ||
312 | 334 | ||
313 | if (p) { | 335 | if (p) { |
314 | dev_info(&pdev->dev, "kept as earlytimer\n"); | 336 | dev_info(&pdev->dev, "kept as earlytimer\n"); |
315 | return 0; | 337 | goto out; |
316 | } | 338 | } |
317 | 339 | ||
318 | p = kmalloc(sizeof(*p), GFP_KERNEL); | 340 | p = kmalloc(sizeof(*p), GFP_KERNEL); |
@@ -325,8 +347,19 @@ static int __devinit sh_mtu2_probe(struct platform_device *pdev) | |||
325 | if (ret) { | 347 | if (ret) { |
326 | kfree(p); | 348 | kfree(p); |
327 | platform_set_drvdata(pdev, NULL); | 349 | platform_set_drvdata(pdev, NULL); |
350 | pm_runtime_idle(&pdev->dev); | ||
351 | return ret; | ||
328 | } | 352 | } |
329 | return ret; | 353 | if (is_early_platform_device(pdev)) |
354 | return 0; | ||
355 | |||
356 | out: | ||
357 | if (cfg->clockevent_rating) | ||
358 | pm_runtime_irq_safe(&pdev->dev); | ||
359 | else | ||
360 | pm_runtime_idle(&pdev->dev); | ||
361 | |||
362 | return 0; | ||
330 | } | 363 | } |
331 | 364 | ||
332 | static int __devexit sh_mtu2_remove(struct platform_device *pdev) | 365 | static int __devexit sh_mtu2_remove(struct platform_device *pdev) |
diff --git a/drivers/clocksource/sh_tmu.c b/drivers/clocksource/sh_tmu.c index c1b51d49d106..0cc4add88279 100644 --- a/drivers/clocksource/sh_tmu.c +++ b/drivers/clocksource/sh_tmu.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <linux/slab.h> | 33 | #include <linux/slab.h> |
34 | #include <linux/module.h> | 34 | #include <linux/module.h> |
35 | #include <linux/pm_domain.h> | 35 | #include <linux/pm_domain.h> |
36 | #include <linux/pm_runtime.h> | ||
36 | 37 | ||
37 | struct sh_tmu_priv { | 38 | struct sh_tmu_priv { |
38 | void __iomem *mapbase; | 39 | void __iomem *mapbase; |
@@ -43,6 +44,8 @@ struct sh_tmu_priv { | |||
43 | unsigned long periodic; | 44 | unsigned long periodic; |
44 | struct clock_event_device ced; | 45 | struct clock_event_device ced; |
45 | struct clocksource cs; | 46 | struct clocksource cs; |
47 | bool cs_enabled; | ||
48 | unsigned int enable_count; | ||
46 | }; | 49 | }; |
47 | 50 | ||
48 | static DEFINE_RAW_SPINLOCK(sh_tmu_lock); | 51 | static DEFINE_RAW_SPINLOCK(sh_tmu_lock); |
@@ -107,7 +110,7 @@ static void sh_tmu_start_stop_ch(struct sh_tmu_priv *p, int start) | |||
107 | raw_spin_unlock_irqrestore(&sh_tmu_lock, flags); | 110 | raw_spin_unlock_irqrestore(&sh_tmu_lock, flags); |
108 | } | 111 | } |
109 | 112 | ||
110 | static int sh_tmu_enable(struct sh_tmu_priv *p) | 113 | static int __sh_tmu_enable(struct sh_tmu_priv *p) |
111 | { | 114 | { |
112 | int ret; | 115 | int ret; |
113 | 116 | ||
@@ -135,7 +138,18 @@ static int sh_tmu_enable(struct sh_tmu_priv *p) | |||
135 | return 0; | 138 | return 0; |
136 | } | 139 | } |
137 | 140 | ||
138 | static void sh_tmu_disable(struct sh_tmu_priv *p) | 141 | static int sh_tmu_enable(struct sh_tmu_priv *p) |
142 | { | ||
143 | if (p->enable_count++ > 0) | ||
144 | return 0; | ||
145 | |||
146 | pm_runtime_get_sync(&p->pdev->dev); | ||
147 | dev_pm_syscore_device(&p->pdev->dev, true); | ||
148 | |||
149 | return __sh_tmu_enable(p); | ||
150 | } | ||
151 | |||
152 | static void __sh_tmu_disable(struct sh_tmu_priv *p) | ||
139 | { | 153 | { |
140 | /* disable channel */ | 154 | /* disable channel */ |
141 | sh_tmu_start_stop_ch(p, 0); | 155 | sh_tmu_start_stop_ch(p, 0); |
@@ -147,6 +161,20 @@ static void sh_tmu_disable(struct sh_tmu_priv *p) | |||
147 | clk_disable(p->clk); | 161 | clk_disable(p->clk); |
148 | } | 162 | } |
149 | 163 | ||
164 | static void sh_tmu_disable(struct sh_tmu_priv *p) | ||
165 | { | ||
166 | if (WARN_ON(p->enable_count == 0)) | ||
167 | return; | ||
168 | |||
169 | if (--p->enable_count > 0) | ||
170 | return; | ||
171 | |||
172 | __sh_tmu_disable(p); | ||
173 | |||
174 | dev_pm_syscore_device(&p->pdev->dev, false); | ||
175 | pm_runtime_put(&p->pdev->dev); | ||
176 | } | ||
177 | |||
150 | static void sh_tmu_set_next(struct sh_tmu_priv *p, unsigned long delta, | 178 | static void sh_tmu_set_next(struct sh_tmu_priv *p, unsigned long delta, |
151 | int periodic) | 179 | int periodic) |
152 | { | 180 | { |
@@ -203,15 +231,53 @@ static int sh_tmu_clocksource_enable(struct clocksource *cs) | |||
203 | struct sh_tmu_priv *p = cs_to_sh_tmu(cs); | 231 | struct sh_tmu_priv *p = cs_to_sh_tmu(cs); |
204 | int ret; | 232 | int ret; |
205 | 233 | ||
234 | if (WARN_ON(p->cs_enabled)) | ||
235 | return 0; | ||
236 | |||
206 | ret = sh_tmu_enable(p); | 237 | ret = sh_tmu_enable(p); |
207 | if (!ret) | 238 | if (!ret) { |
208 | __clocksource_updatefreq_hz(cs, p->rate); | 239 | __clocksource_updatefreq_hz(cs, p->rate); |
240 | p->cs_enabled = true; | ||
241 | } | ||
242 | |||
209 | return ret; | 243 | return ret; |
210 | } | 244 | } |
211 | 245 | ||
212 | static void sh_tmu_clocksource_disable(struct clocksource *cs) | 246 | static void sh_tmu_clocksource_disable(struct clocksource *cs) |
213 | { | 247 | { |
214 | sh_tmu_disable(cs_to_sh_tmu(cs)); | 248 | struct sh_tmu_priv *p = cs_to_sh_tmu(cs); |
249 | |||
250 | if (WARN_ON(!p->cs_enabled)) | ||
251 | return; | ||
252 | |||
253 | sh_tmu_disable(p); | ||
254 | p->cs_enabled = false; | ||
255 | } | ||
256 | |||
257 | static void sh_tmu_clocksource_suspend(struct clocksource *cs) | ||
258 | { | ||
259 | struct sh_tmu_priv *p = cs_to_sh_tmu(cs); | ||
260 | |||
261 | if (!p->cs_enabled) | ||
262 | return; | ||
263 | |||
264 | if (--p->enable_count == 0) { | ||
265 | __sh_tmu_disable(p); | ||
266 | pm_genpd_syscore_poweroff(&p->pdev->dev); | ||
267 | } | ||
268 | } | ||
269 | |||
270 | static void sh_tmu_clocksource_resume(struct clocksource *cs) | ||
271 | { | ||
272 | struct sh_tmu_priv *p = cs_to_sh_tmu(cs); | ||
273 | |||
274 | if (!p->cs_enabled) | ||
275 | return; | ||
276 | |||
277 | if (p->enable_count++ == 0) { | ||
278 | pm_genpd_syscore_poweron(&p->pdev->dev); | ||
279 | __sh_tmu_enable(p); | ||
280 | } | ||
215 | } | 281 | } |
216 | 282 | ||
217 | static int sh_tmu_register_clocksource(struct sh_tmu_priv *p, | 283 | static int sh_tmu_register_clocksource(struct sh_tmu_priv *p, |
@@ -224,6 +290,8 @@ static int sh_tmu_register_clocksource(struct sh_tmu_priv *p, | |||
224 | cs->read = sh_tmu_clocksource_read; | 290 | cs->read = sh_tmu_clocksource_read; |
225 | cs->enable = sh_tmu_clocksource_enable; | 291 | cs->enable = sh_tmu_clocksource_enable; |
226 | cs->disable = sh_tmu_clocksource_disable; | 292 | cs->disable = sh_tmu_clocksource_disable; |
293 | cs->suspend = sh_tmu_clocksource_suspend; | ||
294 | cs->resume = sh_tmu_clocksource_resume; | ||
227 | cs->mask = CLOCKSOURCE_MASK(32); | 295 | cs->mask = CLOCKSOURCE_MASK(32); |
228 | cs->flags = CLOCK_SOURCE_IS_CONTINUOUS; | 296 | cs->flags = CLOCK_SOURCE_IS_CONTINUOUS; |
229 | 297 | ||
@@ -301,6 +369,16 @@ static int sh_tmu_clock_event_next(unsigned long delta, | |||
301 | return 0; | 369 | return 0; |
302 | } | 370 | } |
303 | 371 | ||
372 | static void sh_tmu_clock_event_suspend(struct clock_event_device *ced) | ||
373 | { | ||
374 | pm_genpd_syscore_poweroff(&ced_to_sh_tmu(ced)->pdev->dev); | ||
375 | } | ||
376 | |||
377 | static void sh_tmu_clock_event_resume(struct clock_event_device *ced) | ||
378 | { | ||
379 | pm_genpd_syscore_poweron(&ced_to_sh_tmu(ced)->pdev->dev); | ||
380 | } | ||
381 | |||
304 | static void sh_tmu_register_clockevent(struct sh_tmu_priv *p, | 382 | static void sh_tmu_register_clockevent(struct sh_tmu_priv *p, |
305 | char *name, unsigned long rating) | 383 | char *name, unsigned long rating) |
306 | { | 384 | { |
@@ -316,6 +394,8 @@ static void sh_tmu_register_clockevent(struct sh_tmu_priv *p, | |||
316 | ced->cpumask = cpumask_of(0); | 394 | ced->cpumask = cpumask_of(0); |
317 | ced->set_next_event = sh_tmu_clock_event_next; | 395 | ced->set_next_event = sh_tmu_clock_event_next; |
318 | ced->set_mode = sh_tmu_clock_event_mode; | 396 | ced->set_mode = sh_tmu_clock_event_mode; |
397 | ced->suspend = sh_tmu_clock_event_suspend; | ||
398 | ced->resume = sh_tmu_clock_event_resume; | ||
319 | 399 | ||
320 | dev_info(&p->pdev->dev, "used for clock events\n"); | 400 | dev_info(&p->pdev->dev, "used for clock events\n"); |
321 | 401 | ||
@@ -392,6 +472,8 @@ static int sh_tmu_setup(struct sh_tmu_priv *p, struct platform_device *pdev) | |||
392 | ret = PTR_ERR(p->clk); | 472 | ret = PTR_ERR(p->clk); |
393 | goto err1; | 473 | goto err1; |
394 | } | 474 | } |
475 | p->cs_enabled = false; | ||
476 | p->enable_count = 0; | ||
395 | 477 | ||
396 | return sh_tmu_register(p, (char *)dev_name(&p->pdev->dev), | 478 | return sh_tmu_register(p, (char *)dev_name(&p->pdev->dev), |
397 | cfg->clockevent_rating, | 479 | cfg->clockevent_rating, |
@@ -405,14 +487,17 @@ static int sh_tmu_setup(struct sh_tmu_priv *p, struct platform_device *pdev) | |||
405 | static int __devinit sh_tmu_probe(struct platform_device *pdev) | 487 | static int __devinit sh_tmu_probe(struct platform_device *pdev) |
406 | { | 488 | { |
407 | struct sh_tmu_priv *p = platform_get_drvdata(pdev); | 489 | struct sh_tmu_priv *p = platform_get_drvdata(pdev); |
490 | struct sh_timer_config *cfg = pdev->dev.platform_data; | ||
408 | int ret; | 491 | int ret; |
409 | 492 | ||
410 | if (!is_early_platform_device(pdev)) | 493 | if (!is_early_platform_device(pdev)) { |
411 | pm_genpd_dev_always_on(&pdev->dev, true); | 494 | pm_runtime_set_active(&pdev->dev); |
495 | pm_runtime_enable(&pdev->dev); | ||
496 | } | ||
412 | 497 | ||
413 | if (p) { | 498 | if (p) { |
414 | dev_info(&pdev->dev, "kept as earlytimer\n"); | 499 | dev_info(&pdev->dev, "kept as earlytimer\n"); |
415 | return 0; | 500 | goto out; |
416 | } | 501 | } |
417 | 502 | ||
418 | p = kmalloc(sizeof(*p), GFP_KERNEL); | 503 | p = kmalloc(sizeof(*p), GFP_KERNEL); |
@@ -425,8 +510,19 @@ static int __devinit sh_tmu_probe(struct platform_device *pdev) | |||
425 | if (ret) { | 510 | if (ret) { |
426 | kfree(p); | 511 | kfree(p); |
427 | platform_set_drvdata(pdev, NULL); | 512 | platform_set_drvdata(pdev, NULL); |
513 | pm_runtime_idle(&pdev->dev); | ||
514 | return ret; | ||
428 | } | 515 | } |
429 | return ret; | 516 | if (is_early_platform_device(pdev)) |
517 | return 0; | ||
518 | |||
519 | out: | ||
520 | if (cfg->clockevent_rating || cfg->clocksource_rating) | ||
521 | pm_runtime_irq_safe(&pdev->dev); | ||
522 | else | ||
523 | pm_runtime_idle(&pdev->dev); | ||
524 | |||
525 | return 0; | ||
430 | } | 526 | } |
431 | 527 | ||
432 | static int __devexit sh_tmu_remove(struct platform_device *pdev) | 528 | static int __devexit sh_tmu_remove(struct platform_device *pdev) |
diff --git a/drivers/cpufreq/Kconfig b/drivers/cpufreq/Kconfig index e24a2a1b6666..ea512f47b789 100644 --- a/drivers/cpufreq/Kconfig +++ b/drivers/cpufreq/Kconfig | |||
@@ -179,6 +179,17 @@ config CPU_FREQ_GOV_CONSERVATIVE | |||
179 | 179 | ||
180 | If in doubt, say N. | 180 | If in doubt, say N. |
181 | 181 | ||
182 | config GENERIC_CPUFREQ_CPU0 | ||
183 | bool "Generic CPU0 cpufreq driver" | ||
184 | depends on HAVE_CLK && REGULATOR && PM_OPP && OF | ||
185 | select CPU_FREQ_TABLE | ||
186 | help | ||
187 | This adds a generic cpufreq driver for CPU0 frequency management. | ||
188 | It supports both uniprocessor (UP) and symmetric multiprocessor (SMP) | ||
189 | systems which share clock and voltage across all CPUs. | ||
190 | |||
191 | If in doubt, say N. | ||
192 | |||
182 | menu "x86 CPU frequency scaling drivers" | 193 | menu "x86 CPU frequency scaling drivers" |
183 | depends on X86 | 194 | depends on X86 |
184 | source "drivers/cpufreq/Kconfig.x86" | 195 | source "drivers/cpufreq/Kconfig.x86" |
diff --git a/drivers/cpufreq/Kconfig.x86 b/drivers/cpufreq/Kconfig.x86 index 78ff7ee48951..934854ae5eb4 100644 --- a/drivers/cpufreq/Kconfig.x86 +++ b/drivers/cpufreq/Kconfig.x86 | |||
@@ -23,7 +23,8 @@ config X86_ACPI_CPUFREQ | |||
23 | help | 23 | help |
24 | This driver adds a CPUFreq driver which utilizes the ACPI | 24 | This driver adds a CPUFreq driver which utilizes the ACPI |
25 | Processor Performance States. | 25 | Processor Performance States. |
26 | This driver also supports Intel Enhanced Speedstep. | 26 | This driver also supports Intel Enhanced Speedstep and newer |
27 | AMD CPUs. | ||
27 | 28 | ||
28 | To compile this driver as a module, choose M here: the | 29 | To compile this driver as a module, choose M here: the |
29 | module will be called acpi-cpufreq. | 30 | module will be called acpi-cpufreq. |
@@ -32,6 +33,18 @@ config X86_ACPI_CPUFREQ | |||
32 | 33 | ||
33 | If in doubt, say N. | 34 | If in doubt, say N. |
34 | 35 | ||
36 | config X86_ACPI_CPUFREQ_CPB | ||
37 | default y | ||
38 | bool "Legacy cpb sysfs knob support for AMD CPUs" | ||
39 | depends on X86_ACPI_CPUFREQ && CPU_SUP_AMD | ||
40 | help | ||
41 | The powernow-k8 driver used to provide a sysfs knob called "cpb" | ||
42 | to disable the Core Performance Boosting feature of AMD CPUs. This | ||
43 | file has now been superseeded by the more generic "boost" entry. | ||
44 | |||
45 | By enabling this option the acpi_cpufreq driver provides the old | ||
46 | entry in addition to the new boost ones, for compatibility reasons. | ||
47 | |||
35 | config ELAN_CPUFREQ | 48 | config ELAN_CPUFREQ |
36 | tristate "AMD Elan SC400 and SC410" | 49 | tristate "AMD Elan SC400 and SC410" |
37 | select CPU_FREQ_TABLE | 50 | select CPU_FREQ_TABLE |
@@ -95,7 +108,8 @@ config X86_POWERNOW_K8 | |||
95 | select CPU_FREQ_TABLE | 108 | select CPU_FREQ_TABLE |
96 | depends on ACPI && ACPI_PROCESSOR | 109 | depends on ACPI && ACPI_PROCESSOR |
97 | help | 110 | help |
98 | This adds the CPUFreq driver for K8/K10 Opteron/Athlon64 processors. | 111 | This adds the CPUFreq driver for K8/early Opteron/Athlon64 processors. |
112 | Support for K10 and newer processors is now in acpi-cpufreq. | ||
99 | 113 | ||
100 | To compile this driver as a module, choose M here: the | 114 | To compile this driver as a module, choose M here: the |
101 | module will be called powernow-k8. | 115 | module will be called powernow-k8. |
diff --git a/drivers/cpufreq/Makefile b/drivers/cpufreq/Makefile index 9531fc2eda22..1bc90e1306d8 100644 --- a/drivers/cpufreq/Makefile +++ b/drivers/cpufreq/Makefile | |||
@@ -13,13 +13,15 @@ obj-$(CONFIG_CPU_FREQ_GOV_CONSERVATIVE) += cpufreq_conservative.o | |||
13 | # CPUfreq cross-arch helpers | 13 | # CPUfreq cross-arch helpers |
14 | obj-$(CONFIG_CPU_FREQ_TABLE) += freq_table.o | 14 | obj-$(CONFIG_CPU_FREQ_TABLE) += freq_table.o |
15 | 15 | ||
16 | obj-$(CONFIG_GENERIC_CPUFREQ_CPU0) += cpufreq-cpu0.o | ||
17 | |||
16 | ################################################################################## | 18 | ################################################################################## |
17 | # x86 drivers. | 19 | # x86 drivers. |
18 | # Link order matters. K8 is preferred to ACPI because of firmware bugs in early | 20 | # Link order matters. K8 is preferred to ACPI because of firmware bugs in early |
19 | # K8 systems. ACPI is preferred to all other hardware-specific drivers. | 21 | # K8 systems. ACPI is preferred to all other hardware-specific drivers. |
20 | # speedstep-* is preferred over p4-clockmod. | 22 | # speedstep-* is preferred over p4-clockmod. |
21 | 23 | ||
22 | obj-$(CONFIG_X86_POWERNOW_K8) += powernow-k8.o mperf.o | 24 | obj-$(CONFIG_X86_POWERNOW_K8) += powernow-k8.o |
23 | obj-$(CONFIG_X86_ACPI_CPUFREQ) += acpi-cpufreq.o mperf.o | 25 | obj-$(CONFIG_X86_ACPI_CPUFREQ) += acpi-cpufreq.o mperf.o |
24 | obj-$(CONFIG_X86_PCC_CPUFREQ) += pcc-cpufreq.o | 26 | obj-$(CONFIG_X86_PCC_CPUFREQ) += pcc-cpufreq.o |
25 | obj-$(CONFIG_X86_POWERNOW_K6) += powernow-k6.o | 27 | obj-$(CONFIG_X86_POWERNOW_K6) += powernow-k6.o |
diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c index 56c6c6b4eb4d..0d048f6a2b23 100644 --- a/drivers/cpufreq/acpi-cpufreq.c +++ b/drivers/cpufreq/acpi-cpufreq.c | |||
@@ -51,13 +51,19 @@ MODULE_AUTHOR("Paul Diefenbaugh, Dominik Brodowski"); | |||
51 | MODULE_DESCRIPTION("ACPI Processor P-States Driver"); | 51 | MODULE_DESCRIPTION("ACPI Processor P-States Driver"); |
52 | MODULE_LICENSE("GPL"); | 52 | MODULE_LICENSE("GPL"); |
53 | 53 | ||
54 | #define PFX "acpi-cpufreq: " | ||
55 | |||
54 | enum { | 56 | enum { |
55 | UNDEFINED_CAPABLE = 0, | 57 | UNDEFINED_CAPABLE = 0, |
56 | SYSTEM_INTEL_MSR_CAPABLE, | 58 | SYSTEM_INTEL_MSR_CAPABLE, |
59 | SYSTEM_AMD_MSR_CAPABLE, | ||
57 | SYSTEM_IO_CAPABLE, | 60 | SYSTEM_IO_CAPABLE, |
58 | }; | 61 | }; |
59 | 62 | ||
60 | #define INTEL_MSR_RANGE (0xffff) | 63 | #define INTEL_MSR_RANGE (0xffff) |
64 | #define AMD_MSR_RANGE (0x7) | ||
65 | |||
66 | #define MSR_K7_HWCR_CPB_DIS (1ULL << 25) | ||
61 | 67 | ||
62 | struct acpi_cpufreq_data { | 68 | struct acpi_cpufreq_data { |
63 | struct acpi_processor_performance *acpi_data; | 69 | struct acpi_processor_performance *acpi_data; |
@@ -74,6 +80,116 @@ static struct acpi_processor_performance __percpu *acpi_perf_data; | |||
74 | static struct cpufreq_driver acpi_cpufreq_driver; | 80 | static struct cpufreq_driver acpi_cpufreq_driver; |
75 | 81 | ||
76 | static unsigned int acpi_pstate_strict; | 82 | static unsigned int acpi_pstate_strict; |
83 | static bool boost_enabled, boost_supported; | ||
84 | static struct msr __percpu *msrs; | ||
85 | |||
86 | static bool boost_state(unsigned int cpu) | ||
87 | { | ||
88 | u32 lo, hi; | ||
89 | u64 msr; | ||
90 | |||
91 | switch (boot_cpu_data.x86_vendor) { | ||
92 | case X86_VENDOR_INTEL: | ||
93 | rdmsr_on_cpu(cpu, MSR_IA32_MISC_ENABLE, &lo, &hi); | ||
94 | msr = lo | ((u64)hi << 32); | ||
95 | return !(msr & MSR_IA32_MISC_ENABLE_TURBO_DISABLE); | ||
96 | case X86_VENDOR_AMD: | ||
97 | rdmsr_on_cpu(cpu, MSR_K7_HWCR, &lo, &hi); | ||
98 | msr = lo | ((u64)hi << 32); | ||
99 | return !(msr & MSR_K7_HWCR_CPB_DIS); | ||
100 | } | ||
101 | return false; | ||
102 | } | ||
103 | |||
104 | static void boost_set_msrs(bool enable, const struct cpumask *cpumask) | ||
105 | { | ||
106 | u32 cpu; | ||
107 | u32 msr_addr; | ||
108 | u64 msr_mask; | ||
109 | |||
110 | switch (boot_cpu_data.x86_vendor) { | ||
111 | case X86_VENDOR_INTEL: | ||
112 | msr_addr = MSR_IA32_MISC_ENABLE; | ||
113 | msr_mask = MSR_IA32_MISC_ENABLE_TURBO_DISABLE; | ||
114 | break; | ||
115 | case X86_VENDOR_AMD: | ||
116 | msr_addr = MSR_K7_HWCR; | ||
117 | msr_mask = MSR_K7_HWCR_CPB_DIS; | ||
118 | break; | ||
119 | default: | ||
120 | return; | ||
121 | } | ||
122 | |||
123 | rdmsr_on_cpus(cpumask, msr_addr, msrs); | ||
124 | |||
125 | for_each_cpu(cpu, cpumask) { | ||
126 | struct msr *reg = per_cpu_ptr(msrs, cpu); | ||
127 | if (enable) | ||
128 | reg->q &= ~msr_mask; | ||
129 | else | ||
130 | reg->q |= msr_mask; | ||
131 | } | ||
132 | |||
133 | wrmsr_on_cpus(cpumask, msr_addr, msrs); | ||
134 | } | ||
135 | |||
136 | static ssize_t _store_boost(const char *buf, size_t count) | ||
137 | { | ||
138 | int ret; | ||
139 | unsigned long val = 0; | ||
140 | |||
141 | if (!boost_supported) | ||
142 | return -EINVAL; | ||
143 | |||
144 | ret = kstrtoul(buf, 10, &val); | ||
145 | if (ret || (val > 1)) | ||
146 | return -EINVAL; | ||
147 | |||
148 | if ((val && boost_enabled) || (!val && !boost_enabled)) | ||
149 | return count; | ||
150 | |||
151 | get_online_cpus(); | ||
152 | |||
153 | boost_set_msrs(val, cpu_online_mask); | ||
154 | |||
155 | put_online_cpus(); | ||
156 | |||
157 | boost_enabled = val; | ||
158 | pr_debug("Core Boosting %sabled.\n", val ? "en" : "dis"); | ||
159 | |||
160 | return count; | ||
161 | } | ||
162 | |||
163 | static ssize_t store_global_boost(struct kobject *kobj, struct attribute *attr, | ||
164 | const char *buf, size_t count) | ||
165 | { | ||
166 | return _store_boost(buf, count); | ||
167 | } | ||
168 | |||
169 | static ssize_t show_global_boost(struct kobject *kobj, | ||
170 | struct attribute *attr, char *buf) | ||
171 | { | ||
172 | return sprintf(buf, "%u\n", boost_enabled); | ||
173 | } | ||
174 | |||
175 | static struct global_attr global_boost = __ATTR(boost, 0644, | ||
176 | show_global_boost, | ||
177 | store_global_boost); | ||
178 | |||
179 | #ifdef CONFIG_X86_ACPI_CPUFREQ_CPB | ||
180 | static ssize_t store_cpb(struct cpufreq_policy *policy, const char *buf, | ||
181 | size_t count) | ||
182 | { | ||
183 | return _store_boost(buf, count); | ||
184 | } | ||
185 | |||
186 | static ssize_t show_cpb(struct cpufreq_policy *policy, char *buf) | ||
187 | { | ||
188 | return sprintf(buf, "%u\n", boost_enabled); | ||
189 | } | ||
190 | |||
191 | static struct freq_attr cpb = __ATTR(cpb, 0644, show_cpb, store_cpb); | ||
192 | #endif | ||
77 | 193 | ||
78 | static int check_est_cpu(unsigned int cpuid) | 194 | static int check_est_cpu(unsigned int cpuid) |
79 | { | 195 | { |
@@ -82,6 +198,13 @@ static int check_est_cpu(unsigned int cpuid) | |||
82 | return cpu_has(cpu, X86_FEATURE_EST); | 198 | return cpu_has(cpu, X86_FEATURE_EST); |
83 | } | 199 | } |
84 | 200 | ||
201 | static int check_amd_hwpstate_cpu(unsigned int cpuid) | ||
202 | { | ||
203 | struct cpuinfo_x86 *cpu = &cpu_data(cpuid); | ||
204 | |||
205 | return cpu_has(cpu, X86_FEATURE_HW_PSTATE); | ||
206 | } | ||
207 | |||
85 | static unsigned extract_io(u32 value, struct acpi_cpufreq_data *data) | 208 | static unsigned extract_io(u32 value, struct acpi_cpufreq_data *data) |
86 | { | 209 | { |
87 | struct acpi_processor_performance *perf; | 210 | struct acpi_processor_performance *perf; |
@@ -101,7 +224,11 @@ static unsigned extract_msr(u32 msr, struct acpi_cpufreq_data *data) | |||
101 | int i; | 224 | int i; |
102 | struct acpi_processor_performance *perf; | 225 | struct acpi_processor_performance *perf; |
103 | 226 | ||
104 | msr &= INTEL_MSR_RANGE; | 227 | if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) |
228 | msr &= AMD_MSR_RANGE; | ||
229 | else | ||
230 | msr &= INTEL_MSR_RANGE; | ||
231 | |||
105 | perf = data->acpi_data; | 232 | perf = data->acpi_data; |
106 | 233 | ||
107 | for (i = 0; data->freq_table[i].frequency != CPUFREQ_TABLE_END; i++) { | 234 | for (i = 0; data->freq_table[i].frequency != CPUFREQ_TABLE_END; i++) { |
@@ -115,6 +242,7 @@ static unsigned extract_freq(u32 val, struct acpi_cpufreq_data *data) | |||
115 | { | 242 | { |
116 | switch (data->cpu_feature) { | 243 | switch (data->cpu_feature) { |
117 | case SYSTEM_INTEL_MSR_CAPABLE: | 244 | case SYSTEM_INTEL_MSR_CAPABLE: |
245 | case SYSTEM_AMD_MSR_CAPABLE: | ||
118 | return extract_msr(val, data); | 246 | return extract_msr(val, data); |
119 | case SYSTEM_IO_CAPABLE: | 247 | case SYSTEM_IO_CAPABLE: |
120 | return extract_io(val, data); | 248 | return extract_io(val, data); |
@@ -150,6 +278,7 @@ static void do_drv_read(void *_cmd) | |||
150 | 278 | ||
151 | switch (cmd->type) { | 279 | switch (cmd->type) { |
152 | case SYSTEM_INTEL_MSR_CAPABLE: | 280 | case SYSTEM_INTEL_MSR_CAPABLE: |
281 | case SYSTEM_AMD_MSR_CAPABLE: | ||
153 | rdmsr(cmd->addr.msr.reg, cmd->val, h); | 282 | rdmsr(cmd->addr.msr.reg, cmd->val, h); |
154 | break; | 283 | break; |
155 | case SYSTEM_IO_CAPABLE: | 284 | case SYSTEM_IO_CAPABLE: |
@@ -174,6 +303,9 @@ static void do_drv_write(void *_cmd) | |||
174 | lo = (lo & ~INTEL_MSR_RANGE) | (cmd->val & INTEL_MSR_RANGE); | 303 | lo = (lo & ~INTEL_MSR_RANGE) | (cmd->val & INTEL_MSR_RANGE); |
175 | wrmsr(cmd->addr.msr.reg, lo, hi); | 304 | wrmsr(cmd->addr.msr.reg, lo, hi); |
176 | break; | 305 | break; |
306 | case SYSTEM_AMD_MSR_CAPABLE: | ||
307 | wrmsr(cmd->addr.msr.reg, cmd->val, 0); | ||
308 | break; | ||
177 | case SYSTEM_IO_CAPABLE: | 309 | case SYSTEM_IO_CAPABLE: |
178 | acpi_os_write_port((acpi_io_address)cmd->addr.io.port, | 310 | acpi_os_write_port((acpi_io_address)cmd->addr.io.port, |
179 | cmd->val, | 311 | cmd->val, |
@@ -217,6 +349,10 @@ static u32 get_cur_val(const struct cpumask *mask) | |||
217 | cmd.type = SYSTEM_INTEL_MSR_CAPABLE; | 349 | cmd.type = SYSTEM_INTEL_MSR_CAPABLE; |
218 | cmd.addr.msr.reg = MSR_IA32_PERF_STATUS; | 350 | cmd.addr.msr.reg = MSR_IA32_PERF_STATUS; |
219 | break; | 351 | break; |
352 | case SYSTEM_AMD_MSR_CAPABLE: | ||
353 | cmd.type = SYSTEM_AMD_MSR_CAPABLE; | ||
354 | cmd.addr.msr.reg = MSR_AMD_PERF_STATUS; | ||
355 | break; | ||
220 | case SYSTEM_IO_CAPABLE: | 356 | case SYSTEM_IO_CAPABLE: |
221 | cmd.type = SYSTEM_IO_CAPABLE; | 357 | cmd.type = SYSTEM_IO_CAPABLE; |
222 | perf = per_cpu(acfreq_data, cpumask_first(mask))->acpi_data; | 358 | perf = per_cpu(acfreq_data, cpumask_first(mask))->acpi_data; |
@@ -326,6 +462,11 @@ static int acpi_cpufreq_target(struct cpufreq_policy *policy, | |||
326 | cmd.addr.msr.reg = MSR_IA32_PERF_CTL; | 462 | cmd.addr.msr.reg = MSR_IA32_PERF_CTL; |
327 | cmd.val = (u32) perf->states[next_perf_state].control; | 463 | cmd.val = (u32) perf->states[next_perf_state].control; |
328 | break; | 464 | break; |
465 | case SYSTEM_AMD_MSR_CAPABLE: | ||
466 | cmd.type = SYSTEM_AMD_MSR_CAPABLE; | ||
467 | cmd.addr.msr.reg = MSR_AMD_PERF_CTL; | ||
468 | cmd.val = (u32) perf->states[next_perf_state].control; | ||
469 | break; | ||
329 | case SYSTEM_IO_CAPABLE: | 470 | case SYSTEM_IO_CAPABLE: |
330 | cmd.type = SYSTEM_IO_CAPABLE; | 471 | cmd.type = SYSTEM_IO_CAPABLE; |
331 | cmd.addr.io.port = perf->control_register.address; | 472 | cmd.addr.io.port = perf->control_register.address; |
@@ -419,6 +560,44 @@ static void free_acpi_perf_data(void) | |||
419 | free_percpu(acpi_perf_data); | 560 | free_percpu(acpi_perf_data); |
420 | } | 561 | } |
421 | 562 | ||
563 | static int boost_notify(struct notifier_block *nb, unsigned long action, | ||
564 | void *hcpu) | ||
565 | { | ||
566 | unsigned cpu = (long)hcpu; | ||
567 | const struct cpumask *cpumask; | ||
568 | |||
569 | cpumask = get_cpu_mask(cpu); | ||
570 | |||
571 | /* | ||
572 | * Clear the boost-disable bit on the CPU_DOWN path so that | ||
573 | * this cpu cannot block the remaining ones from boosting. On | ||
574 | * the CPU_UP path we simply keep the boost-disable flag in | ||
575 | * sync with the current global state. | ||
576 | */ | ||
577 | |||
578 | switch (action) { | ||
579 | case CPU_UP_PREPARE: | ||
580 | case CPU_UP_PREPARE_FROZEN: | ||
581 | boost_set_msrs(boost_enabled, cpumask); | ||
582 | break; | ||
583 | |||
584 | case CPU_DOWN_PREPARE: | ||
585 | case CPU_DOWN_PREPARE_FROZEN: | ||
586 | boost_set_msrs(1, cpumask); | ||
587 | break; | ||
588 | |||
589 | default: | ||
590 | break; | ||
591 | } | ||
592 | |||
593 | return NOTIFY_OK; | ||
594 | } | ||
595 | |||
596 | |||
597 | static struct notifier_block boost_nb = { | ||
598 | .notifier_call = boost_notify, | ||
599 | }; | ||
600 | |||
422 | /* | 601 | /* |
423 | * acpi_cpufreq_early_init - initialize ACPI P-States library | 602 | * acpi_cpufreq_early_init - initialize ACPI P-States library |
424 | * | 603 | * |
@@ -559,6 +738,14 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy) | |||
559 | policy->shared_type = CPUFREQ_SHARED_TYPE_ALL; | 738 | policy->shared_type = CPUFREQ_SHARED_TYPE_ALL; |
560 | cpumask_copy(policy->cpus, cpu_core_mask(cpu)); | 739 | cpumask_copy(policy->cpus, cpu_core_mask(cpu)); |
561 | } | 740 | } |
741 | |||
742 | if (check_amd_hwpstate_cpu(cpu) && !acpi_pstate_strict) { | ||
743 | cpumask_clear(policy->cpus); | ||
744 | cpumask_set_cpu(cpu, policy->cpus); | ||
745 | cpumask_copy(policy->related_cpus, cpu_sibling_mask(cpu)); | ||
746 | policy->shared_type = CPUFREQ_SHARED_TYPE_HW; | ||
747 | pr_info_once(PFX "overriding BIOS provided _PSD data\n"); | ||
748 | } | ||
562 | #endif | 749 | #endif |
563 | 750 | ||
564 | /* capability check */ | 751 | /* capability check */ |
@@ -580,12 +767,16 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy) | |||
580 | break; | 767 | break; |
581 | case ACPI_ADR_SPACE_FIXED_HARDWARE: | 768 | case ACPI_ADR_SPACE_FIXED_HARDWARE: |
582 | pr_debug("HARDWARE addr space\n"); | 769 | pr_debug("HARDWARE addr space\n"); |
583 | if (!check_est_cpu(cpu)) { | 770 | if (check_est_cpu(cpu)) { |
584 | result = -ENODEV; | 771 | data->cpu_feature = SYSTEM_INTEL_MSR_CAPABLE; |
585 | goto err_unreg; | 772 | break; |
586 | } | 773 | } |
587 | data->cpu_feature = SYSTEM_INTEL_MSR_CAPABLE; | 774 | if (check_amd_hwpstate_cpu(cpu)) { |
588 | break; | 775 | data->cpu_feature = SYSTEM_AMD_MSR_CAPABLE; |
776 | break; | ||
777 | } | ||
778 | result = -ENODEV; | ||
779 | goto err_unreg; | ||
589 | default: | 780 | default: |
590 | pr_debug("Unknown addr space %d\n", | 781 | pr_debug("Unknown addr space %d\n", |
591 | (u32) (perf->control_register.space_id)); | 782 | (u32) (perf->control_register.space_id)); |
@@ -718,6 +909,7 @@ static int acpi_cpufreq_resume(struct cpufreq_policy *policy) | |||
718 | 909 | ||
719 | static struct freq_attr *acpi_cpufreq_attr[] = { | 910 | static struct freq_attr *acpi_cpufreq_attr[] = { |
720 | &cpufreq_freq_attr_scaling_available_freqs, | 911 | &cpufreq_freq_attr_scaling_available_freqs, |
912 | NULL, /* this is a placeholder for cpb, do not remove */ | ||
721 | NULL, | 913 | NULL, |
722 | }; | 914 | }; |
723 | 915 | ||
@@ -733,6 +925,49 @@ static struct cpufreq_driver acpi_cpufreq_driver = { | |||
733 | .attr = acpi_cpufreq_attr, | 925 | .attr = acpi_cpufreq_attr, |
734 | }; | 926 | }; |
735 | 927 | ||
928 | static void __init acpi_cpufreq_boost_init(void) | ||
929 | { | ||
930 | if (boot_cpu_has(X86_FEATURE_CPB) || boot_cpu_has(X86_FEATURE_IDA)) { | ||
931 | msrs = msrs_alloc(); | ||
932 | |||
933 | if (!msrs) | ||
934 | return; | ||
935 | |||
936 | boost_supported = true; | ||
937 | boost_enabled = boost_state(0); | ||
938 | |||
939 | get_online_cpus(); | ||
940 | |||
941 | /* Force all MSRs to the same value */ | ||
942 | boost_set_msrs(boost_enabled, cpu_online_mask); | ||
943 | |||
944 | register_cpu_notifier(&boost_nb); | ||
945 | |||
946 | put_online_cpus(); | ||
947 | } else | ||
948 | global_boost.attr.mode = 0444; | ||
949 | |||
950 | /* We create the boost file in any case, though for systems without | ||
951 | * hardware support it will be read-only and hardwired to return 0. | ||
952 | */ | ||
953 | if (sysfs_create_file(cpufreq_global_kobject, &(global_boost.attr))) | ||
954 | pr_warn(PFX "could not register global boost sysfs file\n"); | ||
955 | else | ||
956 | pr_debug("registered global boost sysfs file\n"); | ||
957 | } | ||
958 | |||
959 | static void __exit acpi_cpufreq_boost_exit(void) | ||
960 | { | ||
961 | sysfs_remove_file(cpufreq_global_kobject, &(global_boost.attr)); | ||
962 | |||
963 | if (msrs) { | ||
964 | unregister_cpu_notifier(&boost_nb); | ||
965 | |||
966 | msrs_free(msrs); | ||
967 | msrs = NULL; | ||
968 | } | ||
969 | } | ||
970 | |||
736 | static int __init acpi_cpufreq_init(void) | 971 | static int __init acpi_cpufreq_init(void) |
737 | { | 972 | { |
738 | int ret; | 973 | int ret; |
@@ -746,9 +981,32 @@ static int __init acpi_cpufreq_init(void) | |||
746 | if (ret) | 981 | if (ret) |
747 | return ret; | 982 | return ret; |
748 | 983 | ||
984 | #ifdef CONFIG_X86_ACPI_CPUFREQ_CPB | ||
985 | /* this is a sysfs file with a strange name and an even stranger | ||
986 | * semantic - per CPU instantiation, but system global effect. | ||
987 | * Lets enable it only on AMD CPUs for compatibility reasons and | ||
988 | * only if configured. This is considered legacy code, which | ||
989 | * will probably be removed at some point in the future. | ||
990 | */ | ||
991 | if (check_amd_hwpstate_cpu(0)) { | ||
992 | struct freq_attr **iter; | ||
993 | |||
994 | pr_debug("adding sysfs entry for cpb\n"); | ||
995 | |||
996 | for (iter = acpi_cpufreq_attr; *iter != NULL; iter++) | ||
997 | ; | ||
998 | |||
999 | /* make sure there is a terminator behind it */ | ||
1000 | if (iter[1] == NULL) | ||
1001 | *iter = &cpb; | ||
1002 | } | ||
1003 | #endif | ||
1004 | |||
749 | ret = cpufreq_register_driver(&acpi_cpufreq_driver); | 1005 | ret = cpufreq_register_driver(&acpi_cpufreq_driver); |
750 | if (ret) | 1006 | if (ret) |
751 | free_acpi_perf_data(); | 1007 | free_acpi_perf_data(); |
1008 | else | ||
1009 | acpi_cpufreq_boost_init(); | ||
752 | 1010 | ||
753 | return ret; | 1011 | return ret; |
754 | } | 1012 | } |
@@ -757,6 +1015,8 @@ static void __exit acpi_cpufreq_exit(void) | |||
757 | { | 1015 | { |
758 | pr_debug("acpi_cpufreq_exit\n"); | 1016 | pr_debug("acpi_cpufreq_exit\n"); |
759 | 1017 | ||
1018 | acpi_cpufreq_boost_exit(); | ||
1019 | |||
760 | cpufreq_unregister_driver(&acpi_cpufreq_driver); | 1020 | cpufreq_unregister_driver(&acpi_cpufreq_driver); |
761 | 1021 | ||
762 | free_acpi_perf_data(); | 1022 | free_acpi_perf_data(); |
diff --git a/drivers/cpufreq/cpufreq-cpu0.c b/drivers/cpufreq/cpufreq-cpu0.c new file mode 100644 index 000000000000..e9158278c71d --- /dev/null +++ b/drivers/cpufreq/cpufreq-cpu0.c | |||
@@ -0,0 +1,269 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2012 Freescale Semiconductor, Inc. | ||
3 | * | ||
4 | * The OPP code in function cpu0_set_target() is reused from | ||
5 | * drivers/cpufreq/omap-cpufreq.c | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
13 | |||
14 | #include <linux/clk.h> | ||
15 | #include <linux/cpu.h> | ||
16 | #include <linux/cpufreq.h> | ||
17 | #include <linux/err.h> | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/of.h> | ||
20 | #include <linux/opp.h> | ||
21 | #include <linux/regulator/consumer.h> | ||
22 | #include <linux/slab.h> | ||
23 | |||
24 | static unsigned int transition_latency; | ||
25 | static unsigned int voltage_tolerance; /* in percentage */ | ||
26 | |||
27 | static struct device *cpu_dev; | ||
28 | static struct clk *cpu_clk; | ||
29 | static struct regulator *cpu_reg; | ||
30 | static struct cpufreq_frequency_table *freq_table; | ||
31 | |||
32 | static int cpu0_verify_speed(struct cpufreq_policy *policy) | ||
33 | { | ||
34 | return cpufreq_frequency_table_verify(policy, freq_table); | ||
35 | } | ||
36 | |||
37 | static unsigned int cpu0_get_speed(unsigned int cpu) | ||
38 | { | ||
39 | return clk_get_rate(cpu_clk) / 1000; | ||
40 | } | ||
41 | |||
42 | static int cpu0_set_target(struct cpufreq_policy *policy, | ||
43 | unsigned int target_freq, unsigned int relation) | ||
44 | { | ||
45 | struct cpufreq_freqs freqs; | ||
46 | struct opp *opp; | ||
47 | unsigned long freq_Hz, volt = 0, volt_old = 0, tol = 0; | ||
48 | unsigned int index, cpu; | ||
49 | int ret; | ||
50 | |||
51 | ret = cpufreq_frequency_table_target(policy, freq_table, target_freq, | ||
52 | relation, &index); | ||
53 | if (ret) { | ||
54 | pr_err("failed to match target freqency %d: %d\n", | ||
55 | target_freq, ret); | ||
56 | return ret; | ||
57 | } | ||
58 | |||
59 | freq_Hz = clk_round_rate(cpu_clk, freq_table[index].frequency * 1000); | ||
60 | if (freq_Hz < 0) | ||
61 | freq_Hz = freq_table[index].frequency * 1000; | ||
62 | freqs.new = freq_Hz / 1000; | ||
63 | freqs.old = clk_get_rate(cpu_clk) / 1000; | ||
64 | |||
65 | if (freqs.old == freqs.new) | ||
66 | return 0; | ||
67 | |||
68 | for_each_online_cpu(cpu) { | ||
69 | freqs.cpu = cpu; | ||
70 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
71 | } | ||
72 | |||
73 | if (cpu_reg) { | ||
74 | opp = opp_find_freq_ceil(cpu_dev, &freq_Hz); | ||
75 | if (IS_ERR(opp)) { | ||
76 | pr_err("failed to find OPP for %ld\n", freq_Hz); | ||
77 | return PTR_ERR(opp); | ||
78 | } | ||
79 | volt = opp_get_voltage(opp); | ||
80 | tol = volt * voltage_tolerance / 100; | ||
81 | volt_old = regulator_get_voltage(cpu_reg); | ||
82 | } | ||
83 | |||
84 | pr_debug("%u MHz, %ld mV --> %u MHz, %ld mV\n", | ||
85 | freqs.old / 1000, volt_old ? volt_old / 1000 : -1, | ||
86 | freqs.new / 1000, volt ? volt / 1000 : -1); | ||
87 | |||
88 | /* scaling up? scale voltage before frequency */ | ||
89 | if (cpu_reg && freqs.new > freqs.old) { | ||
90 | ret = regulator_set_voltage_tol(cpu_reg, volt, tol); | ||
91 | if (ret) { | ||
92 | pr_err("failed to scale voltage up: %d\n", ret); | ||
93 | freqs.new = freqs.old; | ||
94 | return ret; | ||
95 | } | ||
96 | } | ||
97 | |||
98 | ret = clk_set_rate(cpu_clk, freqs.new * 1000); | ||
99 | if (ret) { | ||
100 | pr_err("failed to set clock rate: %d\n", ret); | ||
101 | if (cpu_reg) | ||
102 | regulator_set_voltage_tol(cpu_reg, volt_old, tol); | ||
103 | return ret; | ||
104 | } | ||
105 | |||
106 | /* scaling down? scale voltage after frequency */ | ||
107 | if (cpu_reg && freqs.new < freqs.old) { | ||
108 | ret = regulator_set_voltage_tol(cpu_reg, volt, tol); | ||
109 | if (ret) { | ||
110 | pr_err("failed to scale voltage down: %d\n", ret); | ||
111 | clk_set_rate(cpu_clk, freqs.old * 1000); | ||
112 | freqs.new = freqs.old; | ||
113 | return ret; | ||
114 | } | ||
115 | } | ||
116 | |||
117 | for_each_online_cpu(cpu) { | ||
118 | freqs.cpu = cpu; | ||
119 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
120 | } | ||
121 | |||
122 | return 0; | ||
123 | } | ||
124 | |||
125 | static int cpu0_cpufreq_init(struct cpufreq_policy *policy) | ||
126 | { | ||
127 | int ret; | ||
128 | |||
129 | if (policy->cpu != 0) | ||
130 | return -EINVAL; | ||
131 | |||
132 | ret = cpufreq_frequency_table_cpuinfo(policy, freq_table); | ||
133 | if (ret) { | ||
134 | pr_err("invalid frequency table: %d\n", ret); | ||
135 | return ret; | ||
136 | } | ||
137 | |||
138 | policy->cpuinfo.transition_latency = transition_latency; | ||
139 | policy->cur = clk_get_rate(cpu_clk) / 1000; | ||
140 | |||
141 | /* | ||
142 | * The driver only supports the SMP configuartion where all processors | ||
143 | * share the clock and voltage and clock. Use cpufreq affected_cpus | ||
144 | * interface to have all CPUs scaled together. | ||
145 | */ | ||
146 | policy->shared_type = CPUFREQ_SHARED_TYPE_ANY; | ||
147 | cpumask_setall(policy->cpus); | ||
148 | |||
149 | cpufreq_frequency_table_get_attr(freq_table, policy->cpu); | ||
150 | |||
151 | return 0; | ||
152 | } | ||
153 | |||
154 | static int cpu0_cpufreq_exit(struct cpufreq_policy *policy) | ||
155 | { | ||
156 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
157 | |||
158 | return 0; | ||
159 | } | ||
160 | |||
161 | static struct freq_attr *cpu0_cpufreq_attr[] = { | ||
162 | &cpufreq_freq_attr_scaling_available_freqs, | ||
163 | NULL, | ||
164 | }; | ||
165 | |||
166 | static struct cpufreq_driver cpu0_cpufreq_driver = { | ||
167 | .flags = CPUFREQ_STICKY, | ||
168 | .verify = cpu0_verify_speed, | ||
169 | .target = cpu0_set_target, | ||
170 | .get = cpu0_get_speed, | ||
171 | .init = cpu0_cpufreq_init, | ||
172 | .exit = cpu0_cpufreq_exit, | ||
173 | .name = "generic_cpu0", | ||
174 | .attr = cpu0_cpufreq_attr, | ||
175 | }; | ||
176 | |||
177 | static int __devinit cpu0_cpufreq_driver_init(void) | ||
178 | { | ||
179 | struct device_node *np; | ||
180 | int ret; | ||
181 | |||
182 | np = of_find_node_by_path("/cpus/cpu@0"); | ||
183 | if (!np) { | ||
184 | pr_err("failed to find cpu0 node\n"); | ||
185 | return -ENOENT; | ||
186 | } | ||
187 | |||
188 | cpu_dev = get_cpu_device(0); | ||
189 | if (!cpu_dev) { | ||
190 | pr_err("failed to get cpu0 device\n"); | ||
191 | ret = -ENODEV; | ||
192 | goto out_put_node; | ||
193 | } | ||
194 | |||
195 | cpu_dev->of_node = np; | ||
196 | |||
197 | cpu_clk = clk_get(cpu_dev, NULL); | ||
198 | if (IS_ERR(cpu_clk)) { | ||
199 | ret = PTR_ERR(cpu_clk); | ||
200 | pr_err("failed to get cpu0 clock: %d\n", ret); | ||
201 | goto out_put_node; | ||
202 | } | ||
203 | |||
204 | cpu_reg = regulator_get(cpu_dev, "cpu0"); | ||
205 | if (IS_ERR(cpu_reg)) { | ||
206 | pr_warn("failed to get cpu0 regulator\n"); | ||
207 | cpu_reg = NULL; | ||
208 | } | ||
209 | |||
210 | ret = of_init_opp_table(cpu_dev); | ||
211 | if (ret) { | ||
212 | pr_err("failed to init OPP table: %d\n", ret); | ||
213 | goto out_put_node; | ||
214 | } | ||
215 | |||
216 | ret = opp_init_cpufreq_table(cpu_dev, &freq_table); | ||
217 | if (ret) { | ||
218 | pr_err("failed to init cpufreq table: %d\n", ret); | ||
219 | goto out_put_node; | ||
220 | } | ||
221 | |||
222 | of_property_read_u32(np, "voltage-tolerance", &voltage_tolerance); | ||
223 | |||
224 | if (of_property_read_u32(np, "clock-latency", &transition_latency)) | ||
225 | transition_latency = CPUFREQ_ETERNAL; | ||
226 | |||
227 | if (cpu_reg) { | ||
228 | struct opp *opp; | ||
229 | unsigned long min_uV, max_uV; | ||
230 | int i; | ||
231 | |||
232 | /* | ||
233 | * OPP is maintained in order of increasing frequency, and | ||
234 | * freq_table initialised from OPP is therefore sorted in the | ||
235 | * same order. | ||
236 | */ | ||
237 | for (i = 0; freq_table[i].frequency != CPUFREQ_TABLE_END; i++) | ||
238 | ; | ||
239 | opp = opp_find_freq_exact(cpu_dev, | ||
240 | freq_table[0].frequency * 1000, true); | ||
241 | min_uV = opp_get_voltage(opp); | ||
242 | opp = opp_find_freq_exact(cpu_dev, | ||
243 | freq_table[i-1].frequency * 1000, true); | ||
244 | max_uV = opp_get_voltage(opp); | ||
245 | ret = regulator_set_voltage_time(cpu_reg, min_uV, max_uV); | ||
246 | if (ret > 0) | ||
247 | transition_latency += ret * 1000; | ||
248 | } | ||
249 | |||
250 | ret = cpufreq_register_driver(&cpu0_cpufreq_driver); | ||
251 | if (ret) { | ||
252 | pr_err("failed register driver: %d\n", ret); | ||
253 | goto out_free_table; | ||
254 | } | ||
255 | |||
256 | of_node_put(np); | ||
257 | return 0; | ||
258 | |||
259 | out_free_table: | ||
260 | opp_free_cpufreq_table(cpu_dev, &freq_table); | ||
261 | out_put_node: | ||
262 | of_node_put(np); | ||
263 | return ret; | ||
264 | } | ||
265 | late_initcall(cpu0_cpufreq_driver_init); | ||
266 | |||
267 | MODULE_AUTHOR("Shawn Guo <shawn.guo@linaro.org>"); | ||
268 | MODULE_DESCRIPTION("Generic CPU0 cpufreq driver"); | ||
269 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c index 55f0354864e2..a152af7e1991 100644 --- a/drivers/cpufreq/cpufreq_conservative.c +++ b/drivers/cpufreq/cpufreq_conservative.c | |||
@@ -504,6 +504,7 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy, | |||
504 | j_dbs_info->prev_cpu_nice = | 504 | j_dbs_info->prev_cpu_nice = |
505 | kcpustat_cpu(j).cpustat[CPUTIME_NICE]; | 505 | kcpustat_cpu(j).cpustat[CPUTIME_NICE]; |
506 | } | 506 | } |
507 | this_dbs_info->cpu = cpu; | ||
507 | this_dbs_info->down_skip = 0; | 508 | this_dbs_info->down_skip = 0; |
508 | this_dbs_info->requested_freq = policy->cur; | 509 | this_dbs_info->requested_freq = policy->cur; |
509 | 510 | ||
@@ -583,6 +584,7 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy, | |||
583 | __cpufreq_driver_target( | 584 | __cpufreq_driver_target( |
584 | this_dbs_info->cur_policy, | 585 | this_dbs_info->cur_policy, |
585 | policy->min, CPUFREQ_RELATION_L); | 586 | policy->min, CPUFREQ_RELATION_L); |
587 | dbs_check_cpu(this_dbs_info); | ||
586 | mutex_unlock(&this_dbs_info->timer_mutex); | 588 | mutex_unlock(&this_dbs_info->timer_mutex); |
587 | 589 | ||
588 | break; | 590 | break; |
diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c index 14c1af5a264f..396322f2a83f 100644 --- a/drivers/cpufreq/cpufreq_ondemand.c +++ b/drivers/cpufreq/cpufreq_ondemand.c | |||
@@ -761,6 +761,7 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy, | |||
761 | else if (policy->min > this_dbs_info->cur_policy->cur) | 761 | else if (policy->min > this_dbs_info->cur_policy->cur) |
762 | __cpufreq_driver_target(this_dbs_info->cur_policy, | 762 | __cpufreq_driver_target(this_dbs_info->cur_policy, |
763 | policy->min, CPUFREQ_RELATION_L); | 763 | policy->min, CPUFREQ_RELATION_L); |
764 | dbs_check_cpu(this_dbs_info); | ||
764 | mutex_unlock(&this_dbs_info->timer_mutex); | 765 | mutex_unlock(&this_dbs_info->timer_mutex); |
765 | break; | 766 | break; |
766 | } | 767 | } |
diff --git a/drivers/cpufreq/longhaul.h b/drivers/cpufreq/longhaul.h index cbf48fbca881..e2dc436099d1 100644 --- a/drivers/cpufreq/longhaul.h +++ b/drivers/cpufreq/longhaul.h | |||
@@ -56,7 +56,7 @@ union msr_longhaul { | |||
56 | /* | 56 | /* |
57 | * VIA C3 Samuel 1 & Samuel 2 (stepping 0) | 57 | * VIA C3 Samuel 1 & Samuel 2 (stepping 0) |
58 | */ | 58 | */ |
59 | static const int __cpuinitdata samuel1_mults[16] = { | 59 | static const int __cpuinitconst samuel1_mults[16] = { |
60 | -1, /* 0000 -> RESERVED */ | 60 | -1, /* 0000 -> RESERVED */ |
61 | 30, /* 0001 -> 3.0x */ | 61 | 30, /* 0001 -> 3.0x */ |
62 | 40, /* 0010 -> 4.0x */ | 62 | 40, /* 0010 -> 4.0x */ |
@@ -75,7 +75,7 @@ static const int __cpuinitdata samuel1_mults[16] = { | |||
75 | -1, /* 1111 -> RESERVED */ | 75 | -1, /* 1111 -> RESERVED */ |
76 | }; | 76 | }; |
77 | 77 | ||
78 | static const int __cpuinitdata samuel1_eblcr[16] = { | 78 | static const int __cpuinitconst samuel1_eblcr[16] = { |
79 | 50, /* 0000 -> RESERVED */ | 79 | 50, /* 0000 -> RESERVED */ |
80 | 30, /* 0001 -> 3.0x */ | 80 | 30, /* 0001 -> 3.0x */ |
81 | 40, /* 0010 -> 4.0x */ | 81 | 40, /* 0010 -> 4.0x */ |
@@ -97,7 +97,7 @@ static const int __cpuinitdata samuel1_eblcr[16] = { | |||
97 | /* | 97 | /* |
98 | * VIA C3 Samuel2 Stepping 1->15 | 98 | * VIA C3 Samuel2 Stepping 1->15 |
99 | */ | 99 | */ |
100 | static const int __cpuinitdata samuel2_eblcr[16] = { | 100 | static const int __cpuinitconst samuel2_eblcr[16] = { |
101 | 50, /* 0000 -> 5.0x */ | 101 | 50, /* 0000 -> 5.0x */ |
102 | 30, /* 0001 -> 3.0x */ | 102 | 30, /* 0001 -> 3.0x */ |
103 | 40, /* 0010 -> 4.0x */ | 103 | 40, /* 0010 -> 4.0x */ |
@@ -119,7 +119,7 @@ static const int __cpuinitdata samuel2_eblcr[16] = { | |||
119 | /* | 119 | /* |
120 | * VIA C3 Ezra | 120 | * VIA C3 Ezra |
121 | */ | 121 | */ |
122 | static const int __cpuinitdata ezra_mults[16] = { | 122 | static const int __cpuinitconst ezra_mults[16] = { |
123 | 100, /* 0000 -> 10.0x */ | 123 | 100, /* 0000 -> 10.0x */ |
124 | 30, /* 0001 -> 3.0x */ | 124 | 30, /* 0001 -> 3.0x */ |
125 | 40, /* 0010 -> 4.0x */ | 125 | 40, /* 0010 -> 4.0x */ |
@@ -138,7 +138,7 @@ static const int __cpuinitdata ezra_mults[16] = { | |||
138 | 120, /* 1111 -> 12.0x */ | 138 | 120, /* 1111 -> 12.0x */ |
139 | }; | 139 | }; |
140 | 140 | ||
141 | static const int __cpuinitdata ezra_eblcr[16] = { | 141 | static const int __cpuinitconst ezra_eblcr[16] = { |
142 | 50, /* 0000 -> 5.0x */ | 142 | 50, /* 0000 -> 5.0x */ |
143 | 30, /* 0001 -> 3.0x */ | 143 | 30, /* 0001 -> 3.0x */ |
144 | 40, /* 0010 -> 4.0x */ | 144 | 40, /* 0010 -> 4.0x */ |
@@ -160,7 +160,7 @@ static const int __cpuinitdata ezra_eblcr[16] = { | |||
160 | /* | 160 | /* |
161 | * VIA C3 (Ezra-T) [C5M]. | 161 | * VIA C3 (Ezra-T) [C5M]. |
162 | */ | 162 | */ |
163 | static const int __cpuinitdata ezrat_mults[32] = { | 163 | static const int __cpuinitconst ezrat_mults[32] = { |
164 | 100, /* 0000 -> 10.0x */ | 164 | 100, /* 0000 -> 10.0x */ |
165 | 30, /* 0001 -> 3.0x */ | 165 | 30, /* 0001 -> 3.0x */ |
166 | 40, /* 0010 -> 4.0x */ | 166 | 40, /* 0010 -> 4.0x */ |
@@ -196,7 +196,7 @@ static const int __cpuinitdata ezrat_mults[32] = { | |||
196 | -1, /* 1111 -> RESERVED (12.0x) */ | 196 | -1, /* 1111 -> RESERVED (12.0x) */ |
197 | }; | 197 | }; |
198 | 198 | ||
199 | static const int __cpuinitdata ezrat_eblcr[32] = { | 199 | static const int __cpuinitconst ezrat_eblcr[32] = { |
200 | 50, /* 0000 -> 5.0x */ | 200 | 50, /* 0000 -> 5.0x */ |
201 | 30, /* 0001 -> 3.0x */ | 201 | 30, /* 0001 -> 3.0x */ |
202 | 40, /* 0010 -> 4.0x */ | 202 | 40, /* 0010 -> 4.0x */ |
@@ -235,7 +235,7 @@ static const int __cpuinitdata ezrat_eblcr[32] = { | |||
235 | /* | 235 | /* |
236 | * VIA C3 Nehemiah */ | 236 | * VIA C3 Nehemiah */ |
237 | 237 | ||
238 | static const int __cpuinitdata nehemiah_mults[32] = { | 238 | static const int __cpuinitconst nehemiah_mults[32] = { |
239 | 100, /* 0000 -> 10.0x */ | 239 | 100, /* 0000 -> 10.0x */ |
240 | -1, /* 0001 -> 16.0x */ | 240 | -1, /* 0001 -> 16.0x */ |
241 | 40, /* 0010 -> 4.0x */ | 241 | 40, /* 0010 -> 4.0x */ |
@@ -270,7 +270,7 @@ static const int __cpuinitdata nehemiah_mults[32] = { | |||
270 | -1, /* 1111 -> 12.0x */ | 270 | -1, /* 1111 -> 12.0x */ |
271 | }; | 271 | }; |
272 | 272 | ||
273 | static const int __cpuinitdata nehemiah_eblcr[32] = { | 273 | static const int __cpuinitconst nehemiah_eblcr[32] = { |
274 | 50, /* 0000 -> 5.0x */ | 274 | 50, /* 0000 -> 5.0x */ |
275 | 160, /* 0001 -> 16.0x */ | 275 | 160, /* 0001 -> 16.0x */ |
276 | 40, /* 0010 -> 4.0x */ | 276 | 40, /* 0010 -> 4.0x */ |
@@ -315,7 +315,7 @@ struct mV_pos { | |||
315 | unsigned short pos; | 315 | unsigned short pos; |
316 | }; | 316 | }; |
317 | 317 | ||
318 | static const struct mV_pos __cpuinitdata vrm85_mV[32] = { | 318 | static const struct mV_pos __cpuinitconst vrm85_mV[32] = { |
319 | {1250, 8}, {1200, 6}, {1150, 4}, {1100, 2}, | 319 | {1250, 8}, {1200, 6}, {1150, 4}, {1100, 2}, |
320 | {1050, 0}, {1800, 30}, {1750, 28}, {1700, 26}, | 320 | {1050, 0}, {1800, 30}, {1750, 28}, {1700, 26}, |
321 | {1650, 24}, {1600, 22}, {1550, 20}, {1500, 18}, | 321 | {1650, 24}, {1600, 22}, {1550, 20}, {1500, 18}, |
@@ -326,14 +326,14 @@ static const struct mV_pos __cpuinitdata vrm85_mV[32] = { | |||
326 | {1475, 17}, {1425, 15}, {1375, 13}, {1325, 11} | 326 | {1475, 17}, {1425, 15}, {1375, 13}, {1325, 11} |
327 | }; | 327 | }; |
328 | 328 | ||
329 | static const unsigned char __cpuinitdata mV_vrm85[32] = { | 329 | static const unsigned char __cpuinitconst mV_vrm85[32] = { |
330 | 0x04, 0x14, 0x03, 0x13, 0x02, 0x12, 0x01, 0x11, | 330 | 0x04, 0x14, 0x03, 0x13, 0x02, 0x12, 0x01, 0x11, |
331 | 0x00, 0x10, 0x0f, 0x1f, 0x0e, 0x1e, 0x0d, 0x1d, | 331 | 0x00, 0x10, 0x0f, 0x1f, 0x0e, 0x1e, 0x0d, 0x1d, |
332 | 0x0c, 0x1c, 0x0b, 0x1b, 0x0a, 0x1a, 0x09, 0x19, | 332 | 0x0c, 0x1c, 0x0b, 0x1b, 0x0a, 0x1a, 0x09, 0x19, |
333 | 0x08, 0x18, 0x07, 0x17, 0x06, 0x16, 0x05, 0x15 | 333 | 0x08, 0x18, 0x07, 0x17, 0x06, 0x16, 0x05, 0x15 |
334 | }; | 334 | }; |
335 | 335 | ||
336 | static const struct mV_pos __cpuinitdata mobilevrm_mV[32] = { | 336 | static const struct mV_pos __cpuinitconst mobilevrm_mV[32] = { |
337 | {1750, 31}, {1700, 30}, {1650, 29}, {1600, 28}, | 337 | {1750, 31}, {1700, 30}, {1650, 29}, {1600, 28}, |
338 | {1550, 27}, {1500, 26}, {1450, 25}, {1400, 24}, | 338 | {1550, 27}, {1500, 26}, {1450, 25}, {1400, 24}, |
339 | {1350, 23}, {1300, 22}, {1250, 21}, {1200, 20}, | 339 | {1350, 23}, {1300, 22}, {1250, 21}, {1200, 20}, |
@@ -344,7 +344,7 @@ static const struct mV_pos __cpuinitdata mobilevrm_mV[32] = { | |||
344 | {675, 3}, {650, 2}, {625, 1}, {600, 0} | 344 | {675, 3}, {650, 2}, {625, 1}, {600, 0} |
345 | }; | 345 | }; |
346 | 346 | ||
347 | static const unsigned char __cpuinitdata mV_mobilevrm[32] = { | 347 | static const unsigned char __cpuinitconst mV_mobilevrm[32] = { |
348 | 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, | 348 | 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, |
349 | 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, | 349 | 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, |
350 | 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, | 350 | 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, |
diff --git a/drivers/cpufreq/omap-cpufreq.c b/drivers/cpufreq/omap-cpufreq.c index b47034e650a5..65f8e9a54975 100644 --- a/drivers/cpufreq/omap-cpufreq.c +++ b/drivers/cpufreq/omap-cpufreq.c | |||
@@ -40,16 +40,6 @@ | |||
40 | /* OPP tolerance in percentage */ | 40 | /* OPP tolerance in percentage */ |
41 | #define OPP_TOLERANCE 4 | 41 | #define OPP_TOLERANCE 4 |
42 | 42 | ||
43 | #ifdef CONFIG_SMP | ||
44 | struct lpj_info { | ||
45 | unsigned long ref; | ||
46 | unsigned int freq; | ||
47 | }; | ||
48 | |||
49 | static DEFINE_PER_CPU(struct lpj_info, lpj_ref); | ||
50 | static struct lpj_info global_lpj_ref; | ||
51 | #endif | ||
52 | |||
53 | static struct cpufreq_frequency_table *freq_table; | 43 | static struct cpufreq_frequency_table *freq_table; |
54 | static atomic_t freq_table_users = ATOMIC_INIT(0); | 44 | static atomic_t freq_table_users = ATOMIC_INIT(0); |
55 | static struct clk *mpu_clk; | 45 | static struct clk *mpu_clk; |
@@ -161,31 +151,6 @@ static int omap_target(struct cpufreq_policy *policy, | |||
161 | } | 151 | } |
162 | 152 | ||
163 | freqs.new = omap_getspeed(policy->cpu); | 153 | freqs.new = omap_getspeed(policy->cpu); |
164 | #ifdef CONFIG_SMP | ||
165 | /* | ||
166 | * Note that loops_per_jiffy is not updated on SMP systems in | ||
167 | * cpufreq driver. So, update the per-CPU loops_per_jiffy value | ||
168 | * on frequency transition. We need to update all dependent CPUs. | ||
169 | */ | ||
170 | for_each_cpu(i, policy->cpus) { | ||
171 | struct lpj_info *lpj = &per_cpu(lpj_ref, i); | ||
172 | if (!lpj->freq) { | ||
173 | lpj->ref = per_cpu(cpu_data, i).loops_per_jiffy; | ||
174 | lpj->freq = freqs.old; | ||
175 | } | ||
176 | |||
177 | per_cpu(cpu_data, i).loops_per_jiffy = | ||
178 | cpufreq_scale(lpj->ref, lpj->freq, freqs.new); | ||
179 | } | ||
180 | |||
181 | /* And don't forget to adjust the global one */ | ||
182 | if (!global_lpj_ref.freq) { | ||
183 | global_lpj_ref.ref = loops_per_jiffy; | ||
184 | global_lpj_ref.freq = freqs.old; | ||
185 | } | ||
186 | loops_per_jiffy = cpufreq_scale(global_lpj_ref.ref, global_lpj_ref.freq, | ||
187 | freqs.new); | ||
188 | #endif | ||
189 | 154 | ||
190 | done: | 155 | done: |
191 | /* notifiers */ | 156 | /* notifiers */ |
@@ -301,9 +266,9 @@ static int __init omap_cpufreq_init(void) | |||
301 | } | 266 | } |
302 | 267 | ||
303 | mpu_dev = omap_device_get_by_hwmod_name("mpu"); | 268 | mpu_dev = omap_device_get_by_hwmod_name("mpu"); |
304 | if (!mpu_dev) { | 269 | if (IS_ERR(mpu_dev)) { |
305 | pr_warning("%s: unable to get the mpu device\n", __func__); | 270 | pr_warning("%s: unable to get the mpu device\n", __func__); |
306 | return -EINVAL; | 271 | return PTR_ERR(mpu_dev); |
307 | } | 272 | } |
308 | 273 | ||
309 | mpu_reg = regulator_get(mpu_dev, "vcc"); | 274 | mpu_reg = regulator_get(mpu_dev, "vcc"); |
diff --git a/drivers/cpufreq/powernow-k8.c b/drivers/cpufreq/powernow-k8.c index 1a40935c85fd..129e80bfff22 100644 --- a/drivers/cpufreq/powernow-k8.c +++ b/drivers/cpufreq/powernow-k8.c | |||
@@ -48,22 +48,12 @@ | |||
48 | #define PFX "powernow-k8: " | 48 | #define PFX "powernow-k8: " |
49 | #define VERSION "version 2.20.00" | 49 | #define VERSION "version 2.20.00" |
50 | #include "powernow-k8.h" | 50 | #include "powernow-k8.h" |
51 | #include "mperf.h" | ||
52 | 51 | ||
53 | /* serialize freq changes */ | 52 | /* serialize freq changes */ |
54 | static DEFINE_MUTEX(fidvid_mutex); | 53 | static DEFINE_MUTEX(fidvid_mutex); |
55 | 54 | ||
56 | static DEFINE_PER_CPU(struct powernow_k8_data *, powernow_data); | 55 | static DEFINE_PER_CPU(struct powernow_k8_data *, powernow_data); |
57 | 56 | ||
58 | static int cpu_family = CPU_OPTERON; | ||
59 | |||
60 | /* array to map SW pstate number to acpi state */ | ||
61 | static u32 ps_to_as[8]; | ||
62 | |||
63 | /* core performance boost */ | ||
64 | static bool cpb_capable, cpb_enabled; | ||
65 | static struct msr __percpu *msrs; | ||
66 | |||
67 | static struct cpufreq_driver cpufreq_amd64_driver; | 57 | static struct cpufreq_driver cpufreq_amd64_driver; |
68 | 58 | ||
69 | #ifndef CONFIG_SMP | 59 | #ifndef CONFIG_SMP |
@@ -85,12 +75,6 @@ static u32 find_khz_freq_from_fid(u32 fid) | |||
85 | return 1000 * find_freq_from_fid(fid); | 75 | return 1000 * find_freq_from_fid(fid); |
86 | } | 76 | } |
87 | 77 | ||
88 | static u32 find_khz_freq_from_pstate(struct cpufreq_frequency_table *data, | ||
89 | u32 pstate) | ||
90 | { | ||
91 | return data[ps_to_as[pstate]].frequency; | ||
92 | } | ||
93 | |||
94 | /* Return the vco fid for an input fid | 78 | /* Return the vco fid for an input fid |
95 | * | 79 | * |
96 | * Each "low" fid has corresponding "high" fid, and you can get to "low" fids | 80 | * Each "low" fid has corresponding "high" fid, and you can get to "low" fids |
@@ -113,9 +97,6 @@ static int pending_bit_stuck(void) | |||
113 | { | 97 | { |
114 | u32 lo, hi; | 98 | u32 lo, hi; |
115 | 99 | ||
116 | if (cpu_family == CPU_HW_PSTATE) | ||
117 | return 0; | ||
118 | |||
119 | rdmsr(MSR_FIDVID_STATUS, lo, hi); | 100 | rdmsr(MSR_FIDVID_STATUS, lo, hi); |
120 | return lo & MSR_S_LO_CHANGE_PENDING ? 1 : 0; | 101 | return lo & MSR_S_LO_CHANGE_PENDING ? 1 : 0; |
121 | } | 102 | } |
@@ -129,20 +110,6 @@ static int query_current_values_with_pending_wait(struct powernow_k8_data *data) | |||
129 | u32 lo, hi; | 110 | u32 lo, hi; |
130 | u32 i = 0; | 111 | u32 i = 0; |
131 | 112 | ||
132 | if (cpu_family == CPU_HW_PSTATE) { | ||
133 | rdmsr(MSR_PSTATE_STATUS, lo, hi); | ||
134 | i = lo & HW_PSTATE_MASK; | ||
135 | data->currpstate = i; | ||
136 | |||
137 | /* | ||
138 | * a workaround for family 11h erratum 311 might cause | ||
139 | * an "out-of-range Pstate if the core is in Pstate-0 | ||
140 | */ | ||
141 | if ((boot_cpu_data.x86 == 0x11) && (i >= data->numps)) | ||
142 | data->currpstate = HW_PSTATE_0; | ||
143 | |||
144 | return 0; | ||
145 | } | ||
146 | do { | 113 | do { |
147 | if (i++ > 10000) { | 114 | if (i++ > 10000) { |
148 | pr_debug("detected change pending stuck\n"); | 115 | pr_debug("detected change pending stuck\n"); |
@@ -299,14 +266,6 @@ static int decrease_vid_code_by_step(struct powernow_k8_data *data, | |||
299 | return 0; | 266 | return 0; |
300 | } | 267 | } |
301 | 268 | ||
302 | /* Change hardware pstate by single MSR write */ | ||
303 | static int transition_pstate(struct powernow_k8_data *data, u32 pstate) | ||
304 | { | ||
305 | wrmsr(MSR_PSTATE_CTRL, pstate, 0); | ||
306 | data->currpstate = pstate; | ||
307 | return 0; | ||
308 | } | ||
309 | |||
310 | /* Change Opteron/Athlon64 fid and vid, by the 3 phases. */ | 269 | /* Change Opteron/Athlon64 fid and vid, by the 3 phases. */ |
311 | static int transition_fid_vid(struct powernow_k8_data *data, | 270 | static int transition_fid_vid(struct powernow_k8_data *data, |
312 | u32 reqfid, u32 reqvid) | 271 | u32 reqfid, u32 reqvid) |
@@ -523,8 +482,6 @@ static int core_voltage_post_transition(struct powernow_k8_data *data, | |||
523 | static const struct x86_cpu_id powernow_k8_ids[] = { | 482 | static const struct x86_cpu_id powernow_k8_ids[] = { |
524 | /* IO based frequency switching */ | 483 | /* IO based frequency switching */ |
525 | { X86_VENDOR_AMD, 0xf }, | 484 | { X86_VENDOR_AMD, 0xf }, |
526 | /* MSR based frequency switching supported */ | ||
527 | X86_FEATURE_MATCH(X86_FEATURE_HW_PSTATE), | ||
528 | {} | 485 | {} |
529 | }; | 486 | }; |
530 | MODULE_DEVICE_TABLE(x86cpu, powernow_k8_ids); | 487 | MODULE_DEVICE_TABLE(x86cpu, powernow_k8_ids); |
@@ -560,15 +517,8 @@ static void check_supported_cpu(void *_rc) | |||
560 | "Power state transitions not supported\n"); | 517 | "Power state transitions not supported\n"); |
561 | return; | 518 | return; |
562 | } | 519 | } |
563 | } else { /* must be a HW Pstate capable processor */ | 520 | *rc = 0; |
564 | cpuid(CPUID_FREQ_VOLT_CAPABILITIES, &eax, &ebx, &ecx, &edx); | ||
565 | if ((edx & USE_HW_PSTATE) == USE_HW_PSTATE) | ||
566 | cpu_family = CPU_HW_PSTATE; | ||
567 | else | ||
568 | return; | ||
569 | } | 521 | } |
570 | |||
571 | *rc = 0; | ||
572 | } | 522 | } |
573 | 523 | ||
574 | static int check_pst_table(struct powernow_k8_data *data, struct pst_s *pst, | 524 | static int check_pst_table(struct powernow_k8_data *data, struct pst_s *pst, |
@@ -632,18 +582,11 @@ static void print_basics(struct powernow_k8_data *data) | |||
632 | for (j = 0; j < data->numps; j++) { | 582 | for (j = 0; j < data->numps; j++) { |
633 | if (data->powernow_table[j].frequency != | 583 | if (data->powernow_table[j].frequency != |
634 | CPUFREQ_ENTRY_INVALID) { | 584 | CPUFREQ_ENTRY_INVALID) { |
635 | if (cpu_family == CPU_HW_PSTATE) { | ||
636 | printk(KERN_INFO PFX | ||
637 | " %d : pstate %d (%d MHz)\n", j, | ||
638 | data->powernow_table[j].index, | ||
639 | data->powernow_table[j].frequency/1000); | ||
640 | } else { | ||
641 | printk(KERN_INFO PFX | 585 | printk(KERN_INFO PFX |
642 | "fid 0x%x (%d MHz), vid 0x%x\n", | 586 | "fid 0x%x (%d MHz), vid 0x%x\n", |
643 | data->powernow_table[j].index & 0xff, | 587 | data->powernow_table[j].index & 0xff, |
644 | data->powernow_table[j].frequency/1000, | 588 | data->powernow_table[j].frequency/1000, |
645 | data->powernow_table[j].index >> 8); | 589 | data->powernow_table[j].index >> 8); |
646 | } | ||
647 | } | 590 | } |
648 | } | 591 | } |
649 | if (data->batps) | 592 | if (data->batps) |
@@ -651,20 +594,6 @@ static void print_basics(struct powernow_k8_data *data) | |||
651 | data->batps); | 594 | data->batps); |
652 | } | 595 | } |
653 | 596 | ||
654 | static u32 freq_from_fid_did(u32 fid, u32 did) | ||
655 | { | ||
656 | u32 mhz = 0; | ||
657 | |||
658 | if (boot_cpu_data.x86 == 0x10) | ||
659 | mhz = (100 * (fid + 0x10)) >> did; | ||
660 | else if (boot_cpu_data.x86 == 0x11) | ||
661 | mhz = (100 * (fid + 8)) >> did; | ||
662 | else | ||
663 | BUG(); | ||
664 | |||
665 | return mhz * 1000; | ||
666 | } | ||
667 | |||
668 | static int fill_powernow_table(struct powernow_k8_data *data, | 597 | static int fill_powernow_table(struct powernow_k8_data *data, |
669 | struct pst_s *pst, u8 maxvid) | 598 | struct pst_s *pst, u8 maxvid) |
670 | { | 599 | { |
@@ -824,7 +753,7 @@ static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, | |||
824 | { | 753 | { |
825 | u64 control; | 754 | u64 control; |
826 | 755 | ||
827 | if (!data->acpi_data.state_count || (cpu_family == CPU_HW_PSTATE)) | 756 | if (!data->acpi_data.state_count) |
828 | return; | 757 | return; |
829 | 758 | ||
830 | control = data->acpi_data.states[index].control; | 759 | control = data->acpi_data.states[index].control; |
@@ -875,10 +804,7 @@ static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data) | |||
875 | data->numps = data->acpi_data.state_count; | 804 | data->numps = data->acpi_data.state_count; |
876 | powernow_k8_acpi_pst_values(data, 0); | 805 | powernow_k8_acpi_pst_values(data, 0); |
877 | 806 | ||
878 | if (cpu_family == CPU_HW_PSTATE) | 807 | ret_val = fill_powernow_table_fidvid(data, powernow_table); |
879 | ret_val = fill_powernow_table_pstate(data, powernow_table); | ||
880 | else | ||
881 | ret_val = fill_powernow_table_fidvid(data, powernow_table); | ||
882 | if (ret_val) | 808 | if (ret_val) |
883 | goto err_out_mem; | 809 | goto err_out_mem; |
884 | 810 | ||
@@ -915,51 +841,6 @@ err_out: | |||
915 | return ret_val; | 841 | return ret_val; |
916 | } | 842 | } |
917 | 843 | ||
918 | static int fill_powernow_table_pstate(struct powernow_k8_data *data, | ||
919 | struct cpufreq_frequency_table *powernow_table) | ||
920 | { | ||
921 | int i; | ||
922 | u32 hi = 0, lo = 0; | ||
923 | rdmsr(MSR_PSTATE_CUR_LIMIT, lo, hi); | ||
924 | data->max_hw_pstate = (lo & HW_PSTATE_MAX_MASK) >> HW_PSTATE_MAX_SHIFT; | ||
925 | |||
926 | for (i = 0; i < data->acpi_data.state_count; i++) { | ||
927 | u32 index; | ||
928 | |||
929 | index = data->acpi_data.states[i].control & HW_PSTATE_MASK; | ||
930 | if (index > data->max_hw_pstate) { | ||
931 | printk(KERN_ERR PFX "invalid pstate %d - " | ||
932 | "bad value %d.\n", i, index); | ||
933 | printk(KERN_ERR PFX "Please report to BIOS " | ||
934 | "manufacturer\n"); | ||
935 | invalidate_entry(powernow_table, i); | ||
936 | continue; | ||
937 | } | ||
938 | |||
939 | ps_to_as[index] = i; | ||
940 | |||
941 | /* Frequency may be rounded for these */ | ||
942 | if ((boot_cpu_data.x86 == 0x10 && boot_cpu_data.x86_model < 10) | ||
943 | || boot_cpu_data.x86 == 0x11) { | ||
944 | |||
945 | rdmsr(MSR_PSTATE_DEF_BASE + index, lo, hi); | ||
946 | if (!(hi & HW_PSTATE_VALID_MASK)) { | ||
947 | pr_debug("invalid pstate %d, ignoring\n", index); | ||
948 | invalidate_entry(powernow_table, i); | ||
949 | continue; | ||
950 | } | ||
951 | |||
952 | powernow_table[i].frequency = | ||
953 | freq_from_fid_did(lo & 0x3f, (lo >> 6) & 7); | ||
954 | } else | ||
955 | powernow_table[i].frequency = | ||
956 | data->acpi_data.states[i].core_frequency * 1000; | ||
957 | |||
958 | powernow_table[i].index = index; | ||
959 | } | ||
960 | return 0; | ||
961 | } | ||
962 | |||
963 | static int fill_powernow_table_fidvid(struct powernow_k8_data *data, | 844 | static int fill_powernow_table_fidvid(struct powernow_k8_data *data, |
964 | struct cpufreq_frequency_table *powernow_table) | 845 | struct cpufreq_frequency_table *powernow_table) |
965 | { | 846 | { |
@@ -1036,15 +917,7 @@ static int get_transition_latency(struct powernow_k8_data *data) | |||
1036 | max_latency = cur_latency; | 917 | max_latency = cur_latency; |
1037 | } | 918 | } |
1038 | if (max_latency == 0) { | 919 | if (max_latency == 0) { |
1039 | /* | 920 | pr_err(FW_WARN PFX "Invalid zero transition latency\n"); |
1040 | * Fam 11h and later may return 0 as transition latency. This | ||
1041 | * is intended and means "very fast". While cpufreq core and | ||
1042 | * governors currently can handle that gracefully, better set it | ||
1043 | * to 1 to avoid problems in the future. | ||
1044 | */ | ||
1045 | if (boot_cpu_data.x86 < 0x11) | ||
1046 | printk(KERN_ERR FW_WARN PFX "Invalid zero transition " | ||
1047 | "latency\n"); | ||
1048 | max_latency = 1; | 921 | max_latency = 1; |
1049 | } | 922 | } |
1050 | /* value in usecs, needs to be in nanoseconds */ | 923 | /* value in usecs, needs to be in nanoseconds */ |
@@ -1104,40 +977,6 @@ static int transition_frequency_fidvid(struct powernow_k8_data *data, | |||
1104 | return res; | 977 | return res; |
1105 | } | 978 | } |
1106 | 979 | ||
1107 | /* Take a frequency, and issue the hardware pstate transition command */ | ||
1108 | static int transition_frequency_pstate(struct powernow_k8_data *data, | ||
1109 | unsigned int index) | ||
1110 | { | ||
1111 | u32 pstate = 0; | ||
1112 | int res, i; | ||
1113 | struct cpufreq_freqs freqs; | ||
1114 | |||
1115 | pr_debug("cpu %d transition to index %u\n", smp_processor_id(), index); | ||
1116 | |||
1117 | /* get MSR index for hardware pstate transition */ | ||
1118 | pstate = index & HW_PSTATE_MASK; | ||
1119 | if (pstate > data->max_hw_pstate) | ||
1120 | return -EINVAL; | ||
1121 | |||
1122 | freqs.old = find_khz_freq_from_pstate(data->powernow_table, | ||
1123 | data->currpstate); | ||
1124 | freqs.new = find_khz_freq_from_pstate(data->powernow_table, pstate); | ||
1125 | |||
1126 | for_each_cpu(i, data->available_cores) { | ||
1127 | freqs.cpu = i; | ||
1128 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
1129 | } | ||
1130 | |||
1131 | res = transition_pstate(data, pstate); | ||
1132 | freqs.new = find_khz_freq_from_pstate(data->powernow_table, pstate); | ||
1133 | |||
1134 | for_each_cpu(i, data->available_cores) { | ||
1135 | freqs.cpu = i; | ||
1136 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
1137 | } | ||
1138 | return res; | ||
1139 | } | ||
1140 | |||
1141 | struct powernowk8_target_arg { | 980 | struct powernowk8_target_arg { |
1142 | struct cpufreq_policy *pol; | 981 | struct cpufreq_policy *pol; |
1143 | unsigned targfreq; | 982 | unsigned targfreq; |
@@ -1173,18 +1012,15 @@ static long powernowk8_target_fn(void *arg) | |||
1173 | if (query_current_values_with_pending_wait(data)) | 1012 | if (query_current_values_with_pending_wait(data)) |
1174 | return -EIO; | 1013 | return -EIO; |
1175 | 1014 | ||
1176 | if (cpu_family != CPU_HW_PSTATE) { | 1015 | pr_debug("targ: curr fid 0x%x, vid 0x%x\n", |
1177 | pr_debug("targ: curr fid 0x%x, vid 0x%x\n", | 1016 | data->currfid, data->currvid); |
1178 | data->currfid, data->currvid); | ||
1179 | 1017 | ||
1180 | if ((checkvid != data->currvid) || | 1018 | if ((checkvid != data->currvid) || |
1181 | (checkfid != data->currfid)) { | 1019 | (checkfid != data->currfid)) { |
1182 | printk(KERN_INFO PFX | 1020 | pr_info(PFX |
1183 | "error - out of sync, fix 0x%x 0x%x, " | 1021 | "error - out of sync, fix 0x%x 0x%x, vid 0x%x 0x%x\n", |
1184 | "vid 0x%x 0x%x\n", | 1022 | checkfid, data->currfid, |
1185 | checkfid, data->currfid, | 1023 | checkvid, data->currvid); |
1186 | checkvid, data->currvid); | ||
1187 | } | ||
1188 | } | 1024 | } |
1189 | 1025 | ||
1190 | if (cpufreq_frequency_table_target(pol, data->powernow_table, | 1026 | if (cpufreq_frequency_table_target(pol, data->powernow_table, |
@@ -1195,11 +1031,8 @@ static long powernowk8_target_fn(void *arg) | |||
1195 | 1031 | ||
1196 | powernow_k8_acpi_pst_values(data, newstate); | 1032 | powernow_k8_acpi_pst_values(data, newstate); |
1197 | 1033 | ||
1198 | if (cpu_family == CPU_HW_PSTATE) | 1034 | ret = transition_frequency_fidvid(data, newstate); |
1199 | ret = transition_frequency_pstate(data, | 1035 | |
1200 | data->powernow_table[newstate].index); | ||
1201 | else | ||
1202 | ret = transition_frequency_fidvid(data, newstate); | ||
1203 | if (ret) { | 1036 | if (ret) { |
1204 | printk(KERN_ERR PFX "transition frequency failed\n"); | 1037 | printk(KERN_ERR PFX "transition frequency failed\n"); |
1205 | mutex_unlock(&fidvid_mutex); | 1038 | mutex_unlock(&fidvid_mutex); |
@@ -1207,11 +1040,7 @@ static long powernowk8_target_fn(void *arg) | |||
1207 | } | 1040 | } |
1208 | mutex_unlock(&fidvid_mutex); | 1041 | mutex_unlock(&fidvid_mutex); |
1209 | 1042 | ||
1210 | if (cpu_family == CPU_HW_PSTATE) | 1043 | pol->cur = find_khz_freq_from_fid(data->currfid); |
1211 | pol->cur = find_khz_freq_from_pstate(data->powernow_table, | ||
1212 | data->powernow_table[newstate].index); | ||
1213 | else | ||
1214 | pol->cur = find_khz_freq_from_fid(data->currfid); | ||
1215 | 1044 | ||
1216 | return 0; | 1045 | return 0; |
1217 | } | 1046 | } |
@@ -1264,22 +1093,23 @@ static void __cpuinit powernowk8_cpu_init_on_cpu(void *_init_on_cpu) | |||
1264 | return; | 1093 | return; |
1265 | } | 1094 | } |
1266 | 1095 | ||
1267 | if (cpu_family == CPU_OPTERON) | 1096 | fidvid_msr_init(); |
1268 | fidvid_msr_init(); | ||
1269 | 1097 | ||
1270 | init_on_cpu->rc = 0; | 1098 | init_on_cpu->rc = 0; |
1271 | } | 1099 | } |
1272 | 1100 | ||
1101 | static const char missing_pss_msg[] = | ||
1102 | KERN_ERR | ||
1103 | FW_BUG PFX "No compatible ACPI _PSS objects found.\n" | ||
1104 | FW_BUG PFX "First, make sure Cool'N'Quiet is enabled in the BIOS.\n" | ||
1105 | FW_BUG PFX "If that doesn't help, try upgrading your BIOS.\n"; | ||
1106 | |||
1273 | /* per CPU init entry point to the driver */ | 1107 | /* per CPU init entry point to the driver */ |
1274 | static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol) | 1108 | static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol) |
1275 | { | 1109 | { |
1276 | static const char ACPI_PSS_BIOS_BUG_MSG[] = | ||
1277 | KERN_ERR FW_BUG PFX "No compatible ACPI _PSS objects found.\n" | ||
1278 | FW_BUG PFX "Try again with latest BIOS.\n"; | ||
1279 | struct powernow_k8_data *data; | 1110 | struct powernow_k8_data *data; |
1280 | struct init_on_cpu init_on_cpu; | 1111 | struct init_on_cpu init_on_cpu; |
1281 | int rc; | 1112 | int rc; |
1282 | struct cpuinfo_x86 *c = &cpu_data(pol->cpu); | ||
1283 | 1113 | ||
1284 | if (!cpu_online(pol->cpu)) | 1114 | if (!cpu_online(pol->cpu)) |
1285 | return -ENODEV; | 1115 | return -ENODEV; |
@@ -1295,7 +1125,6 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol) | |||
1295 | } | 1125 | } |
1296 | 1126 | ||
1297 | data->cpu = pol->cpu; | 1127 | data->cpu = pol->cpu; |
1298 | data->currpstate = HW_PSTATE_INVALID; | ||
1299 | 1128 | ||
1300 | if (powernow_k8_cpu_init_acpi(data)) { | 1129 | if (powernow_k8_cpu_init_acpi(data)) { |
1301 | /* | 1130 | /* |
@@ -1303,7 +1132,7 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol) | |||
1303 | * an UP version, and is deprecated by AMD. | 1132 | * an UP version, and is deprecated by AMD. |
1304 | */ | 1133 | */ |
1305 | if (num_online_cpus() != 1) { | 1134 | if (num_online_cpus() != 1) { |
1306 | printk_once(ACPI_PSS_BIOS_BUG_MSG); | 1135 | printk_once(missing_pss_msg); |
1307 | goto err_out; | 1136 | goto err_out; |
1308 | } | 1137 | } |
1309 | if (pol->cpu != 0) { | 1138 | if (pol->cpu != 0) { |
@@ -1332,17 +1161,10 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol) | |||
1332 | if (rc != 0) | 1161 | if (rc != 0) |
1333 | goto err_out_exit_acpi; | 1162 | goto err_out_exit_acpi; |
1334 | 1163 | ||
1335 | if (cpu_family == CPU_HW_PSTATE) | 1164 | cpumask_copy(pol->cpus, cpu_core_mask(pol->cpu)); |
1336 | cpumask_copy(pol->cpus, cpumask_of(pol->cpu)); | ||
1337 | else | ||
1338 | cpumask_copy(pol->cpus, cpu_core_mask(pol->cpu)); | ||
1339 | data->available_cores = pol->cpus; | 1165 | data->available_cores = pol->cpus; |
1340 | 1166 | ||
1341 | if (cpu_family == CPU_HW_PSTATE) | 1167 | pol->cur = find_khz_freq_from_fid(data->currfid); |
1342 | pol->cur = find_khz_freq_from_pstate(data->powernow_table, | ||
1343 | data->currpstate); | ||
1344 | else | ||
1345 | pol->cur = find_khz_freq_from_fid(data->currfid); | ||
1346 | pr_debug("policy current frequency %d kHz\n", pol->cur); | 1168 | pr_debug("policy current frequency %d kHz\n", pol->cur); |
1347 | 1169 | ||
1348 | /* min/max the cpu is capable of */ | 1170 | /* min/max the cpu is capable of */ |
@@ -1354,18 +1176,10 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol) | |||
1354 | return -EINVAL; | 1176 | return -EINVAL; |
1355 | } | 1177 | } |
1356 | 1178 | ||
1357 | /* Check for APERF/MPERF support in hardware */ | ||
1358 | if (cpu_has(c, X86_FEATURE_APERFMPERF)) | ||
1359 | cpufreq_amd64_driver.getavg = cpufreq_get_measured_perf; | ||
1360 | |||
1361 | cpufreq_frequency_table_get_attr(data->powernow_table, pol->cpu); | 1179 | cpufreq_frequency_table_get_attr(data->powernow_table, pol->cpu); |
1362 | 1180 | ||
1363 | if (cpu_family == CPU_HW_PSTATE) | 1181 | pr_debug("cpu_init done, current fid 0x%x, vid 0x%x\n", |
1364 | pr_debug("cpu_init done, current pstate 0x%x\n", | 1182 | data->currfid, data->currvid); |
1365 | data->currpstate); | ||
1366 | else | ||
1367 | pr_debug("cpu_init done, current fid 0x%x, vid 0x%x\n", | ||
1368 | data->currfid, data->currvid); | ||
1369 | 1183 | ||
1370 | per_cpu(powernow_data, pol->cpu) = data; | 1184 | per_cpu(powernow_data, pol->cpu) = data; |
1371 | 1185 | ||
@@ -1418,88 +1232,15 @@ static unsigned int powernowk8_get(unsigned int cpu) | |||
1418 | if (err) | 1232 | if (err) |
1419 | goto out; | 1233 | goto out; |
1420 | 1234 | ||
1421 | if (cpu_family == CPU_HW_PSTATE) | 1235 | khz = find_khz_freq_from_fid(data->currfid); |
1422 | khz = find_khz_freq_from_pstate(data->powernow_table, | ||
1423 | data->currpstate); | ||
1424 | else | ||
1425 | khz = find_khz_freq_from_fid(data->currfid); | ||
1426 | 1236 | ||
1427 | 1237 | ||
1428 | out: | 1238 | out: |
1429 | return khz; | 1239 | return khz; |
1430 | } | 1240 | } |
1431 | 1241 | ||
1432 | static void _cpb_toggle_msrs(bool t) | ||
1433 | { | ||
1434 | int cpu; | ||
1435 | |||
1436 | get_online_cpus(); | ||
1437 | |||
1438 | rdmsr_on_cpus(cpu_online_mask, MSR_K7_HWCR, msrs); | ||
1439 | |||
1440 | for_each_cpu(cpu, cpu_online_mask) { | ||
1441 | struct msr *reg = per_cpu_ptr(msrs, cpu); | ||
1442 | if (t) | ||
1443 | reg->l &= ~BIT(25); | ||
1444 | else | ||
1445 | reg->l |= BIT(25); | ||
1446 | } | ||
1447 | wrmsr_on_cpus(cpu_online_mask, MSR_K7_HWCR, msrs); | ||
1448 | |||
1449 | put_online_cpus(); | ||
1450 | } | ||
1451 | |||
1452 | /* | ||
1453 | * Switch on/off core performance boosting. | ||
1454 | * | ||
1455 | * 0=disable | ||
1456 | * 1=enable. | ||
1457 | */ | ||
1458 | static void cpb_toggle(bool t) | ||
1459 | { | ||
1460 | if (!cpb_capable) | ||
1461 | return; | ||
1462 | |||
1463 | if (t && !cpb_enabled) { | ||
1464 | cpb_enabled = true; | ||
1465 | _cpb_toggle_msrs(t); | ||
1466 | printk(KERN_INFO PFX "Core Boosting enabled.\n"); | ||
1467 | } else if (!t && cpb_enabled) { | ||
1468 | cpb_enabled = false; | ||
1469 | _cpb_toggle_msrs(t); | ||
1470 | printk(KERN_INFO PFX "Core Boosting disabled.\n"); | ||
1471 | } | ||
1472 | } | ||
1473 | |||
1474 | static ssize_t store_cpb(struct cpufreq_policy *policy, const char *buf, | ||
1475 | size_t count) | ||
1476 | { | ||
1477 | int ret = -EINVAL; | ||
1478 | unsigned long val = 0; | ||
1479 | |||
1480 | ret = strict_strtoul(buf, 10, &val); | ||
1481 | if (!ret && (val == 0 || val == 1) && cpb_capable) | ||
1482 | cpb_toggle(val); | ||
1483 | else | ||
1484 | return -EINVAL; | ||
1485 | |||
1486 | return count; | ||
1487 | } | ||
1488 | |||
1489 | static ssize_t show_cpb(struct cpufreq_policy *policy, char *buf) | ||
1490 | { | ||
1491 | return sprintf(buf, "%u\n", cpb_enabled); | ||
1492 | } | ||
1493 | |||
1494 | #define define_one_rw(_name) \ | ||
1495 | static struct freq_attr _name = \ | ||
1496 | __ATTR(_name, 0644, show_##_name, store_##_name) | ||
1497 | |||
1498 | define_one_rw(cpb); | ||
1499 | |||
1500 | static struct freq_attr *powernow_k8_attr[] = { | 1242 | static struct freq_attr *powernow_k8_attr[] = { |
1501 | &cpufreq_freq_attr_scaling_available_freqs, | 1243 | &cpufreq_freq_attr_scaling_available_freqs, |
1502 | &cpb, | ||
1503 | NULL, | 1244 | NULL, |
1504 | }; | 1245 | }; |
1505 | 1246 | ||
@@ -1515,53 +1256,18 @@ static struct cpufreq_driver cpufreq_amd64_driver = { | |||
1515 | .attr = powernow_k8_attr, | 1256 | .attr = powernow_k8_attr, |
1516 | }; | 1257 | }; |
1517 | 1258 | ||
1518 | /* | ||
1519 | * Clear the boost-disable flag on the CPU_DOWN path so that this cpu | ||
1520 | * cannot block the remaining ones from boosting. On the CPU_UP path we | ||
1521 | * simply keep the boost-disable flag in sync with the current global | ||
1522 | * state. | ||
1523 | */ | ||
1524 | static int cpb_notify(struct notifier_block *nb, unsigned long action, | ||
1525 | void *hcpu) | ||
1526 | { | ||
1527 | unsigned cpu = (long)hcpu; | ||
1528 | u32 lo, hi; | ||
1529 | |||
1530 | switch (action) { | ||
1531 | case CPU_UP_PREPARE: | ||
1532 | case CPU_UP_PREPARE_FROZEN: | ||
1533 | |||
1534 | if (!cpb_enabled) { | ||
1535 | rdmsr_on_cpu(cpu, MSR_K7_HWCR, &lo, &hi); | ||
1536 | lo |= BIT(25); | ||
1537 | wrmsr_on_cpu(cpu, MSR_K7_HWCR, lo, hi); | ||
1538 | } | ||
1539 | break; | ||
1540 | |||
1541 | case CPU_DOWN_PREPARE: | ||
1542 | case CPU_DOWN_PREPARE_FROZEN: | ||
1543 | rdmsr_on_cpu(cpu, MSR_K7_HWCR, &lo, &hi); | ||
1544 | lo &= ~BIT(25); | ||
1545 | wrmsr_on_cpu(cpu, MSR_K7_HWCR, lo, hi); | ||
1546 | break; | ||
1547 | |||
1548 | default: | ||
1549 | break; | ||
1550 | } | ||
1551 | |||
1552 | return NOTIFY_OK; | ||
1553 | } | ||
1554 | |||
1555 | static struct notifier_block cpb_nb = { | ||
1556 | .notifier_call = cpb_notify, | ||
1557 | }; | ||
1558 | |||
1559 | /* driver entry point for init */ | 1259 | /* driver entry point for init */ |
1560 | static int __cpuinit powernowk8_init(void) | 1260 | static int __cpuinit powernowk8_init(void) |
1561 | { | 1261 | { |
1562 | unsigned int i, supported_cpus = 0, cpu; | 1262 | unsigned int i, supported_cpus = 0; |
1563 | int rv; | 1263 | int rv; |
1564 | 1264 | ||
1265 | if (static_cpu_has(X86_FEATURE_HW_PSTATE)) { | ||
1266 | pr_warn(PFX "this CPU is not supported anymore, using acpi-cpufreq instead.\n"); | ||
1267 | request_module("acpi-cpufreq"); | ||
1268 | return -ENODEV; | ||
1269 | } | ||
1270 | |||
1565 | if (!x86_match_cpu(powernow_k8_ids)) | 1271 | if (!x86_match_cpu(powernow_k8_ids)) |
1566 | return -ENODEV; | 1272 | return -ENODEV; |
1567 | 1273 | ||
@@ -1575,38 +1281,13 @@ static int __cpuinit powernowk8_init(void) | |||
1575 | if (supported_cpus != num_online_cpus()) | 1281 | if (supported_cpus != num_online_cpus()) |
1576 | return -ENODEV; | 1282 | return -ENODEV; |
1577 | 1283 | ||
1578 | printk(KERN_INFO PFX "Found %d %s (%d cpu cores) (" VERSION ")\n", | 1284 | rv = cpufreq_register_driver(&cpufreq_amd64_driver); |
1579 | num_online_nodes(), boot_cpu_data.x86_model_id, supported_cpus); | ||
1580 | |||
1581 | if (boot_cpu_has(X86_FEATURE_CPB)) { | ||
1582 | |||
1583 | cpb_capable = true; | ||
1584 | |||
1585 | msrs = msrs_alloc(); | ||
1586 | if (!msrs) { | ||
1587 | printk(KERN_ERR "%s: Error allocating msrs!\n", __func__); | ||
1588 | return -ENOMEM; | ||
1589 | } | ||
1590 | |||
1591 | register_cpu_notifier(&cpb_nb); | ||
1592 | |||
1593 | rdmsr_on_cpus(cpu_online_mask, MSR_K7_HWCR, msrs); | ||
1594 | 1285 | ||
1595 | for_each_cpu(cpu, cpu_online_mask) { | 1286 | if (!rv) |
1596 | struct msr *reg = per_cpu_ptr(msrs, cpu); | 1287 | pr_info(PFX "Found %d %s (%d cpu cores) (" VERSION ")\n", |
1597 | cpb_enabled |= !(!!(reg->l & BIT(25))); | 1288 | num_online_nodes(), boot_cpu_data.x86_model_id, |
1598 | } | 1289 | supported_cpus); |
1599 | 1290 | ||
1600 | printk(KERN_INFO PFX "Core Performance Boosting: %s.\n", | ||
1601 | (cpb_enabled ? "on" : "off")); | ||
1602 | } | ||
1603 | |||
1604 | rv = cpufreq_register_driver(&cpufreq_amd64_driver); | ||
1605 | if (rv < 0 && boot_cpu_has(X86_FEATURE_CPB)) { | ||
1606 | unregister_cpu_notifier(&cpb_nb); | ||
1607 | msrs_free(msrs); | ||
1608 | msrs = NULL; | ||
1609 | } | ||
1610 | return rv; | 1291 | return rv; |
1611 | } | 1292 | } |
1612 | 1293 | ||
@@ -1615,13 +1296,6 @@ static void __exit powernowk8_exit(void) | |||
1615 | { | 1296 | { |
1616 | pr_debug("exit\n"); | 1297 | pr_debug("exit\n"); |
1617 | 1298 | ||
1618 | if (boot_cpu_has(X86_FEATURE_CPB)) { | ||
1619 | msrs_free(msrs); | ||
1620 | msrs = NULL; | ||
1621 | |||
1622 | unregister_cpu_notifier(&cpb_nb); | ||
1623 | } | ||
1624 | |||
1625 | cpufreq_unregister_driver(&cpufreq_amd64_driver); | 1299 | cpufreq_unregister_driver(&cpufreq_amd64_driver); |
1626 | } | 1300 | } |
1627 | 1301 | ||
diff --git a/drivers/cpufreq/powernow-k8.h b/drivers/cpufreq/powernow-k8.h index 3744d26cdc2b..79329d4d5abe 100644 --- a/drivers/cpufreq/powernow-k8.h +++ b/drivers/cpufreq/powernow-k8.h | |||
@@ -5,24 +5,11 @@ | |||
5 | * http://www.gnu.org/licenses/gpl.html | 5 | * http://www.gnu.org/licenses/gpl.html |
6 | */ | 6 | */ |
7 | 7 | ||
8 | enum pstate { | ||
9 | HW_PSTATE_INVALID = 0xff, | ||
10 | HW_PSTATE_0 = 0, | ||
11 | HW_PSTATE_1 = 1, | ||
12 | HW_PSTATE_2 = 2, | ||
13 | HW_PSTATE_3 = 3, | ||
14 | HW_PSTATE_4 = 4, | ||
15 | HW_PSTATE_5 = 5, | ||
16 | HW_PSTATE_6 = 6, | ||
17 | HW_PSTATE_7 = 7, | ||
18 | }; | ||
19 | |||
20 | struct powernow_k8_data { | 8 | struct powernow_k8_data { |
21 | unsigned int cpu; | 9 | unsigned int cpu; |
22 | 10 | ||
23 | u32 numps; /* number of p-states */ | 11 | u32 numps; /* number of p-states */ |
24 | u32 batps; /* number of p-states supported on battery */ | 12 | u32 batps; /* number of p-states supported on battery */ |
25 | u32 max_hw_pstate; /* maximum legal hardware pstate */ | ||
26 | 13 | ||
27 | /* these values are constant when the PSB is used to determine | 14 | /* these values are constant when the PSB is used to determine |
28 | * vid/fid pairings, but are modified during the ->target() call | 15 | * vid/fid pairings, but are modified during the ->target() call |
@@ -37,7 +24,6 @@ struct powernow_k8_data { | |||
37 | /* keep track of the current fid / vid or pstate */ | 24 | /* keep track of the current fid / vid or pstate */ |
38 | u32 currvid; | 25 | u32 currvid; |
39 | u32 currfid; | 26 | u32 currfid; |
40 | enum pstate currpstate; | ||
41 | 27 | ||
42 | /* the powernow_table includes all frequency and vid/fid pairings: | 28 | /* the powernow_table includes all frequency and vid/fid pairings: |
43 | * fid are the lower 8 bits of the index, vid are the upper 8 bits. | 29 | * fid are the lower 8 bits of the index, vid are the upper 8 bits. |
@@ -97,23 +83,6 @@ struct powernow_k8_data { | |||
97 | #define MSR_S_HI_CURRENT_VID 0x0000003f | 83 | #define MSR_S_HI_CURRENT_VID 0x0000003f |
98 | #define MSR_C_HI_STP_GNT_BENIGN 0x00000001 | 84 | #define MSR_C_HI_STP_GNT_BENIGN 0x00000001 |
99 | 85 | ||
100 | |||
101 | /* Hardware Pstate _PSS and MSR definitions */ | ||
102 | #define USE_HW_PSTATE 0x00000080 | ||
103 | #define HW_PSTATE_MASK 0x00000007 | ||
104 | #define HW_PSTATE_VALID_MASK 0x80000000 | ||
105 | #define HW_PSTATE_MAX_MASK 0x000000f0 | ||
106 | #define HW_PSTATE_MAX_SHIFT 4 | ||
107 | #define MSR_PSTATE_DEF_BASE 0xc0010064 /* base of Pstate MSRs */ | ||
108 | #define MSR_PSTATE_STATUS 0xc0010063 /* Pstate Status MSR */ | ||
109 | #define MSR_PSTATE_CTRL 0xc0010062 /* Pstate control MSR */ | ||
110 | #define MSR_PSTATE_CUR_LIMIT 0xc0010061 /* pstate current limit MSR */ | ||
111 | |||
112 | /* define the two driver architectures */ | ||
113 | #define CPU_OPTERON 0 | ||
114 | #define CPU_HW_PSTATE 1 | ||
115 | |||
116 | |||
117 | /* | 86 | /* |
118 | * There are restrictions frequencies have to follow: | 87 | * There are restrictions frequencies have to follow: |
119 | * - only 1 entry in the low fid table ( <=1.4GHz ) | 88 | * - only 1 entry in the low fid table ( <=1.4GHz ) |
@@ -218,5 +187,4 @@ static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid); | |||
218 | 187 | ||
219 | static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, unsigned int index); | 188 | static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, unsigned int index); |
220 | 189 | ||
221 | static int fill_powernow_table_pstate(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table); | ||
222 | static int fill_powernow_table_fidvid(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table); | 190 | static int fill_powernow_table_fidvid(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table); |
diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c index 58bf3b1ac9c4..87db3877fead 100644 --- a/drivers/cpuidle/driver.c +++ b/drivers/cpuidle/driver.c | |||
@@ -18,9 +18,10 @@ static struct cpuidle_driver *cpuidle_curr_driver; | |||
18 | DEFINE_SPINLOCK(cpuidle_driver_lock); | 18 | DEFINE_SPINLOCK(cpuidle_driver_lock); |
19 | int cpuidle_driver_refcount; | 19 | int cpuidle_driver_refcount; |
20 | 20 | ||
21 | static void __cpuidle_register_driver(struct cpuidle_driver *drv) | 21 | static void set_power_states(struct cpuidle_driver *drv) |
22 | { | 22 | { |
23 | int i; | 23 | int i; |
24 | |||
24 | /* | 25 | /* |
25 | * cpuidle driver should set the drv->power_specified bit | 26 | * cpuidle driver should set the drv->power_specified bit |
26 | * before registering if the driver provides | 27 | * before registering if the driver provides |
@@ -35,13 +36,10 @@ static void __cpuidle_register_driver(struct cpuidle_driver *drv) | |||
35 | * an power value of -1. So we use -2, -3, etc, for other | 36 | * an power value of -1. So we use -2, -3, etc, for other |
36 | * c-states. | 37 | * c-states. |
37 | */ | 38 | */ |
38 | if (!drv->power_specified) { | 39 | for (i = CPUIDLE_DRIVER_STATE_START; i < drv->state_count; i++) |
39 | for (i = CPUIDLE_DRIVER_STATE_START; i < drv->state_count; i++) | 40 | drv->states[i].power_usage = -1 - i; |
40 | drv->states[i].power_usage = -1 - i; | ||
41 | } | ||
42 | } | 41 | } |
43 | 42 | ||
44 | |||
45 | /** | 43 | /** |
46 | * cpuidle_register_driver - registers a driver | 44 | * cpuidle_register_driver - registers a driver |
47 | * @drv: the driver | 45 | * @drv: the driver |
@@ -59,13 +57,16 @@ int cpuidle_register_driver(struct cpuidle_driver *drv) | |||
59 | spin_unlock(&cpuidle_driver_lock); | 57 | spin_unlock(&cpuidle_driver_lock); |
60 | return -EBUSY; | 58 | return -EBUSY; |
61 | } | 59 | } |
62 | __cpuidle_register_driver(drv); | 60 | |
61 | if (!drv->power_specified) | ||
62 | set_power_states(drv); | ||
63 | |||
63 | cpuidle_curr_driver = drv; | 64 | cpuidle_curr_driver = drv; |
65 | |||
64 | spin_unlock(&cpuidle_driver_lock); | 66 | spin_unlock(&cpuidle_driver_lock); |
65 | 67 | ||
66 | return 0; | 68 | return 0; |
67 | } | 69 | } |
68 | |||
69 | EXPORT_SYMBOL_GPL(cpuidle_register_driver); | 70 | EXPORT_SYMBOL_GPL(cpuidle_register_driver); |
70 | 71 | ||
71 | /** | 72 | /** |
@@ -96,7 +97,6 @@ void cpuidle_unregister_driver(struct cpuidle_driver *drv) | |||
96 | 97 | ||
97 | spin_unlock(&cpuidle_driver_lock); | 98 | spin_unlock(&cpuidle_driver_lock); |
98 | } | 99 | } |
99 | |||
100 | EXPORT_SYMBOL_GPL(cpuidle_unregister_driver); | 100 | EXPORT_SYMBOL_GPL(cpuidle_unregister_driver); |
101 | 101 | ||
102 | struct cpuidle_driver *cpuidle_driver_ref(void) | 102 | struct cpuidle_driver *cpuidle_driver_ref(void) |
diff --git a/drivers/cpuidle/governors/ladder.c b/drivers/cpuidle/governors/ladder.c index b6a09ea859b1..9b784051ec12 100644 --- a/drivers/cpuidle/governors/ladder.c +++ b/drivers/cpuidle/governors/ladder.c | |||
@@ -88,6 +88,8 @@ static int ladder_select_state(struct cpuidle_driver *drv, | |||
88 | 88 | ||
89 | /* consider promotion */ | 89 | /* consider promotion */ |
90 | if (last_idx < drv->state_count - 1 && | 90 | if (last_idx < drv->state_count - 1 && |
91 | !drv->states[last_idx + 1].disabled && | ||
92 | !dev->states_usage[last_idx + 1].disable && | ||
91 | last_residency > last_state->threshold.promotion_time && | 93 | last_residency > last_state->threshold.promotion_time && |
92 | drv->states[last_idx + 1].exit_latency <= latency_req) { | 94 | drv->states[last_idx + 1].exit_latency <= latency_req) { |
93 | last_state->stats.promotion_count++; | 95 | last_state->stats.promotion_count++; |
@@ -100,7 +102,9 @@ static int ladder_select_state(struct cpuidle_driver *drv, | |||
100 | 102 | ||
101 | /* consider demotion */ | 103 | /* consider demotion */ |
102 | if (last_idx > CPUIDLE_DRIVER_STATE_START && | 104 | if (last_idx > CPUIDLE_DRIVER_STATE_START && |
103 | drv->states[last_idx].exit_latency > latency_req) { | 105 | (drv->states[last_idx].disabled || |
106 | dev->states_usage[last_idx].disable || | ||
107 | drv->states[last_idx].exit_latency > latency_req)) { | ||
104 | int i; | 108 | int i; |
105 | 109 | ||
106 | for (i = last_idx - 1; i > CPUIDLE_DRIVER_STATE_START; i--) { | 110 | for (i = last_idx - 1; i > CPUIDLE_DRIVER_STATE_START; i--) { |
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index 9e1d2959e226..94c6e2aa03d6 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c | |||
@@ -607,21 +607,6 @@ static int pci_pm_prepare(struct device *dev) | |||
607 | int error = 0; | 607 | int error = 0; |
608 | 608 | ||
609 | /* | 609 | /* |
610 | * If a PCI device configured to wake up the system from sleep states | ||
611 | * has been suspended at run time and there's a resume request pending | ||
612 | * for it, this is equivalent to the device signaling wakeup, so the | ||
613 | * system suspend operation should be aborted. | ||
614 | */ | ||
615 | pm_runtime_get_noresume(dev); | ||
616 | if (pm_runtime_barrier(dev) && device_may_wakeup(dev)) | ||
617 | pm_wakeup_event(dev, 0); | ||
618 | |||
619 | if (pm_wakeup_pending()) { | ||
620 | pm_runtime_put_sync(dev); | ||
621 | return -EBUSY; | ||
622 | } | ||
623 | |||
624 | /* | ||
625 | * PCI devices suspended at run time need to be resumed at this | 610 | * PCI devices suspended at run time need to be resumed at this |
626 | * point, because in general it is necessary to reconfigure them for | 611 | * point, because in general it is necessary to reconfigure them for |
627 | * system suspend. Namely, if the device is supposed to wake up the | 612 | * system suspend. Namely, if the device is supposed to wake up the |
@@ -644,8 +629,6 @@ static void pci_pm_complete(struct device *dev) | |||
644 | 629 | ||
645 | if (drv && drv->pm && drv->pm->complete) | 630 | if (drv && drv->pm && drv->pm->complete) |
646 | drv->pm->complete(dev); | 631 | drv->pm->complete(dev); |
647 | |||
648 | pm_runtime_put_sync(dev); | ||
649 | } | 632 | } |
650 | 633 | ||
651 | #else /* !CONFIG_PM_SLEEP */ | 634 | #else /* !CONFIG_PM_SLEEP */ |
diff --git a/drivers/xen/xen-acpi-processor.c b/drivers/xen/xen-acpi-processor.c index b590ee067fcd..316df65163cf 100644 --- a/drivers/xen/xen-acpi-processor.c +++ b/drivers/xen/xen-acpi-processor.c | |||
@@ -98,7 +98,6 @@ static int push_cxx_to_hypervisor(struct acpi_processor *_pr) | |||
98 | 98 | ||
99 | dst_cx->type = cx->type; | 99 | dst_cx->type = cx->type; |
100 | dst_cx->latency = cx->latency; | 100 | dst_cx->latency = cx->latency; |
101 | dst_cx->power = cx->power; | ||
102 | 101 | ||
103 | dst_cx->dpcnt = 0; | 102 | dst_cx->dpcnt = 0; |
104 | set_xen_guest_handle(dst_cx->dp, NULL); | 103 | set_xen_guest_handle(dst_cx->dp, NULL); |