aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/hwmon/coretemp.c86
1 files changed, 29 insertions, 57 deletions
diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
index 1bcc90a20ed1..984c02334910 100644
--- a/drivers/hwmon/coretemp.c
+++ b/drivers/hwmon/coretemp.c
@@ -649,7 +649,7 @@ static void coretemp_device_remove(unsigned int cpu)
649 mutex_unlock(&pdev_list_mutex); 649 mutex_unlock(&pdev_list_mutex);
650} 650}
651 651
652static void get_core_online(unsigned int cpu) 652static int coretemp_cpu_online(unsigned int cpu)
653{ 653{
654 struct platform_device *pdev = coretemp_get_pdev(cpu); 654 struct platform_device *pdev = coretemp_get_pdev(cpu);
655 struct cpuinfo_x86 *c = &cpu_data(cpu); 655 struct cpuinfo_x86 *c = &cpu_data(cpu);
@@ -662,12 +662,12 @@ static void get_core_online(unsigned int cpu)
662 * without thermal sensors will be filtered out. 662 * without thermal sensors will be filtered out.
663 */ 663 */
664 if (!cpu_has(c, X86_FEATURE_DTHERM)) 664 if (!cpu_has(c, X86_FEATURE_DTHERM))
665 return; 665 return 0;
666 666
667 if (!pdev) { 667 if (!pdev) {
668 /* Check the microcode version of the CPU */ 668 /* Check the microcode version of the CPU */
669 if (chk_ucode_version(cpu)) 669 if (chk_ucode_version(cpu))
670 return; 670 return 0;
671 671
672 /* 672 /*
673 * Alright, we have DTS support. 673 * Alright, we have DTS support.
@@ -677,7 +677,7 @@ static void get_core_online(unsigned int cpu)
677 */ 677 */
678 err = coretemp_device_add(cpu); 678 err = coretemp_device_add(cpu);
679 if (err) 679 if (err)
680 return; 680 return 0;
681 681
682 pdev = coretemp_get_pdev(cpu); 682 pdev = coretemp_get_pdev(cpu);
683 /* 683 /*
@@ -697,9 +697,10 @@ static void get_core_online(unsigned int cpu)
697 coretemp_add_core(pdev, cpu, 0); 697 coretemp_add_core(pdev, cpu, 0);
698 698
699 cpumask_set_cpu(cpu, &pdata->cpumask); 699 cpumask_set_cpu(cpu, &pdata->cpumask);
700 return 0;
700} 701}
701 702
702static void put_core_offline(unsigned int cpu) 703static int coretemp_cpu_offline(unsigned int cpu)
703{ 704{
704 struct platform_device *pdev = coretemp_get_pdev(cpu); 705 struct platform_device *pdev = coretemp_get_pdev(cpu);
705 struct platform_data *pd; 706 struct platform_data *pd;
@@ -708,12 +709,12 @@ static void put_core_offline(unsigned int cpu)
708 709
709 /* If the physical CPU device does not exist, just return */ 710 /* If the physical CPU device does not exist, just return */
710 if (!pdev) 711 if (!pdev)
711 return; 712 return 0;
712 713
713 /* The core id is too big, just return */ 714 /* The core id is too big, just return */
714 indx = TO_ATTR_NO(cpu); 715 indx = TO_ATTR_NO(cpu);
715 if (indx > MAX_CORE_DATA - 1) 716 if (indx > MAX_CORE_DATA - 1)
716 return; 717 return 0;
717 718
718 pd = platform_get_drvdata(pdev); 719 pd = platform_get_drvdata(pdev);
719 tdata = pd->core_data[indx]; 720 tdata = pd->core_data[indx];
@@ -742,7 +743,7 @@ static void put_core_offline(unsigned int cpu)
742 */ 743 */
743 if (cpumask_empty(&pd->cpumask)) { 744 if (cpumask_empty(&pd->cpumask)) {
744 coretemp_device_remove(cpu); 745 coretemp_device_remove(cpu);
745 return; 746 return 0;
746 } 747 }
747 /* 748 /*
748 * Check whether this core is the target for the package 749 * Check whether this core is the target for the package
@@ -755,38 +756,19 @@ static void put_core_offline(unsigned int cpu)
755 tdata->cpu = target; 756 tdata->cpu = target;
756 mutex_unlock(&tdata->update_lock); 757 mutex_unlock(&tdata->update_lock);
757 } 758 }
759 return 0;
758} 760}
759
760static int coretemp_cpu_callback(struct notifier_block *nfb,
761 unsigned long action, void *hcpu)
762{
763 unsigned int cpu = (unsigned long) hcpu;
764
765 switch (action) {
766 case CPU_ONLINE:
767 case CPU_DOWN_FAILED:
768 get_core_online(cpu);
769 break;
770 case CPU_DOWN_PREPARE:
771 put_core_offline(cpu);
772 break;
773 }
774 return NOTIFY_OK;
775}
776
777static struct notifier_block coretemp_cpu_notifier __refdata = {
778 .notifier_call = coretemp_cpu_callback,
779};
780
781static const struct x86_cpu_id __initconst coretemp_ids[] = { 761static const struct x86_cpu_id __initconst coretemp_ids[] = {
782 { X86_VENDOR_INTEL, X86_FAMILY_ANY, X86_MODEL_ANY, X86_FEATURE_DTHERM }, 762 { X86_VENDOR_INTEL, X86_FAMILY_ANY, X86_MODEL_ANY, X86_FEATURE_DTHERM },
783 {} 763 {}
784}; 764};
785MODULE_DEVICE_TABLE(x86cpu, coretemp_ids); 765MODULE_DEVICE_TABLE(x86cpu, coretemp_ids);
786 766
767static enum cpuhp_state coretemp_hp_online;
768
787static int __init coretemp_init(void) 769static int __init coretemp_init(void)
788{ 770{
789 int i, err; 771 int err;
790 772
791 /* 773 /*
792 * CPUID.06H.EAX[0] indicates whether the CPU has thermal 774 * CPUID.06H.EAX[0] indicates whether the CPU has thermal
@@ -798,52 +780,42 @@ static int __init coretemp_init(void)
798 780
799 err = platform_driver_register(&coretemp_driver); 781 err = platform_driver_register(&coretemp_driver);
800 if (err) 782 if (err)
801 goto exit; 783 return err;
802 784
803 cpu_notifier_register_begin(); 785 get_online_cpus();
804 for_each_online_cpu(i) 786 err = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "hwmon/coretemp:online",
805 get_core_online(i); 787 coretemp_cpu_online, coretemp_cpu_offline);
788 if (err < 0)
789 goto exit_driver_unreg;
790 coretemp_hp_online = err;
806 791
807#ifndef CONFIG_HOTPLUG_CPU 792#ifndef CONFIG_HOTPLUG_CPU
808 if (list_empty(&pdev_list)) { 793 if (list_empty(&pdev_list)) {
809 cpu_notifier_register_done();
810 err = -ENODEV; 794 err = -ENODEV;
811 goto exit_driver_unreg; 795 goto exit_hp_unreg;
812 } 796 }
813#endif 797#endif
814 798 put_online_cpus();
815 __register_hotcpu_notifier(&coretemp_cpu_notifier);
816 cpu_notifier_register_done();
817 return 0; 799 return 0;
818 800
819#ifndef CONFIG_HOTPLUG_CPU 801#ifndef CONFIG_HOTPLUG_CPU
802exit_hp_unreg:
803 cpuhp_remove_state(coretemp_hp_online);
804 put_online_cpus();
805#endif
820exit_driver_unreg: 806exit_driver_unreg:
821 platform_driver_unregister(&coretemp_driver); 807 platform_driver_unregister(&coretemp_driver);
822#endif
823exit:
824 return err; 808 return err;
825} 809}
810module_init(coretemp_init)
826 811
827static void __exit coretemp_exit(void) 812static void __exit coretemp_exit(void)
828{ 813{
829 struct pdev_entry *p, *n; 814 cpuhp_remove_state(coretemp_hp_online);
830
831 cpu_notifier_register_begin();
832 __unregister_hotcpu_notifier(&coretemp_cpu_notifier);
833 mutex_lock(&pdev_list_mutex);
834 list_for_each_entry_safe(p, n, &pdev_list, list) {
835 platform_device_unregister(p->pdev);
836 list_del(&p->list);
837 kfree(p);
838 }
839 mutex_unlock(&pdev_list_mutex);
840 cpu_notifier_register_done();
841 platform_driver_unregister(&coretemp_driver); 815 platform_driver_unregister(&coretemp_driver);
842} 816}
817module_exit(coretemp_exit)
843 818
844MODULE_AUTHOR("Rudolf Marek <r.marek@assembler.cz>"); 819MODULE_AUTHOR("Rudolf Marek <r.marek@assembler.cz>");
845MODULE_DESCRIPTION("Intel Core temperature monitor"); 820MODULE_DESCRIPTION("Intel Core temperature monitor");
846MODULE_LICENSE("GPL"); 821MODULE_LICENSE("GPL");
847
848module_init(coretemp_init)
849module_exit(coretemp_exit)