g762.c (e98bdb3059cbf2b1cd4261e126b08429f64466c3) | g762.c (4091fb95b5f8dea37568d1a94c8227244bade891) |
---|---|
1/* 2 * g762 - Driver for the Global Mixed-mode Technology Inc. fan speed 3 * PWM controller chips from G762 family, i.e. G762 and G763 4 * 5 * Copyright (C) 2013, Arnaud EBALARD <arno@natisbad.org> 6 * 7 * This work is based on a basic version for 2.6.31 kernel developed 8 * by Olivier Mouchet for LaCie. Updates and correction have been --- 724 unchanged lines hidden (view full) --- 733/* 734 * sysfs attributes 735 */ 736 737/* 738 * Read function for fan1_input sysfs file. Return current fan RPM value, or 739 * 0 if fan is out of control. 740 */ | 1/* 2 * g762 - Driver for the Global Mixed-mode Technology Inc. fan speed 3 * PWM controller chips from G762 family, i.e. G762 and G763 4 * 5 * Copyright (C) 2013, Arnaud EBALARD <arno@natisbad.org> 6 * 7 * This work is based on a basic version for 2.6.31 kernel developed 8 * by Olivier Mouchet for LaCie. Updates and correction have been --- 724 unchanged lines hidden (view full) --- 733/* 734 * sysfs attributes 735 */ 736 737/* 738 * Read function for fan1_input sysfs file. Return current fan RPM value, or 739 * 0 if fan is out of control. 740 */ |
741static ssize_t get_fan_rpm(struct device *dev, struct device_attribute *da, 742 char *buf) | 741static ssize_t fan1_input_show(struct device *dev, 742 struct device_attribute *da, char *buf) |
743{ 744 struct g762_data *data = g762_update_client(dev); 745 unsigned int rpm = 0; 746 747 if (IS_ERR(data)) 748 return PTR_ERR(data); 749 750 mutex_lock(&data->update_lock); --- 8 unchanged lines hidden (view full) --- 759 760 return sprintf(buf, "%u\n", rpm); 761} 762 763/* 764 * Read and write functions for pwm1_mode sysfs file. Get and set fan speed 765 * control mode i.e. PWM (1) or DC (0). 766 */ | 743{ 744 struct g762_data *data = g762_update_client(dev); 745 unsigned int rpm = 0; 746 747 if (IS_ERR(data)) 748 return PTR_ERR(data); 749 750 mutex_lock(&data->update_lock); --- 8 unchanged lines hidden (view full) --- 759 760 return sprintf(buf, "%u\n", rpm); 761} 762 763/* 764 * Read and write functions for pwm1_mode sysfs file. Get and set fan speed 765 * control mode i.e. PWM (1) or DC (0). 766 */ |
767static ssize_t get_pwm_mode(struct device *dev, struct device_attribute *da, 768 char *buf) | 767static ssize_t pwm1_mode_show(struct device *dev, struct device_attribute *da, 768 char *buf) |
769{ 770 struct g762_data *data = g762_update_client(dev); 771 772 if (IS_ERR(data)) 773 return PTR_ERR(data); 774 775 return sprintf(buf, "%d\n", 776 !!(data->fan_cmd1 & G762_REG_FAN_CMD1_OUT_MODE)); 777} 778 | 769{ 770 struct g762_data *data = g762_update_client(dev); 771 772 if (IS_ERR(data)) 773 return PTR_ERR(data); 774 775 return sprintf(buf, "%d\n", 776 !!(data->fan_cmd1 & G762_REG_FAN_CMD1_OUT_MODE)); 777} 778 |
779static ssize_t set_pwm_mode(struct device *dev, struct device_attribute *da, 780 const char *buf, size_t count) | 779static ssize_t pwm1_mode_store(struct device *dev, 780 struct device_attribute *da, const char *buf, 781 size_t count) |
781{ 782 unsigned long val; 783 int ret; 784 785 if (kstrtoul(buf, 10, &val)) 786 return -EINVAL; 787 788 ret = do_set_pwm_mode(dev, val); 789 if (ret < 0) 790 return ret; 791 792 return count; 793} 794 795/* 796 * Read and write functions for fan1_div sysfs file. Get and set fan 797 * controller prescaler value 798 */ | 782{ 783 unsigned long val; 784 int ret; 785 786 if (kstrtoul(buf, 10, &val)) 787 return -EINVAL; 788 789 ret = do_set_pwm_mode(dev, val); 790 if (ret < 0) 791 return ret; 792 793 return count; 794} 795 796/* 797 * Read and write functions for fan1_div sysfs file. Get and set fan 798 * controller prescaler value 799 */ |
799static ssize_t get_fan_div(struct device *dev, 800 struct device_attribute *da, char *buf) | 800static ssize_t fan1_div_show(struct device *dev, struct device_attribute *da, 801 char *buf) |
801{ 802 struct g762_data *data = g762_update_client(dev); 803 804 if (IS_ERR(data)) 805 return PTR_ERR(data); 806 807 return sprintf(buf, "%d\n", G762_CLKDIV_FROM_REG(data->fan_cmd1)); 808} 809 | 802{ 803 struct g762_data *data = g762_update_client(dev); 804 805 if (IS_ERR(data)) 806 return PTR_ERR(data); 807 808 return sprintf(buf, "%d\n", G762_CLKDIV_FROM_REG(data->fan_cmd1)); 809} 810 |
810static ssize_t set_fan_div(struct device *dev, 811 struct device_attribute *da, 812 const char *buf, size_t count) | 811static ssize_t fan1_div_store(struct device *dev, struct device_attribute *da, 812 const char *buf, size_t count) |
813{ 814 unsigned long val; 815 int ret; 816 817 if (kstrtoul(buf, 10, &val)) 818 return -EINVAL; 819 820 ret = do_set_fan_div(dev, val); 821 if (ret < 0) 822 return ret; 823 824 return count; 825} 826 827/* 828 * Read and write functions for fan1_pulses sysfs file. Get and set number 829 * of tachometer pulses per fan revolution. 830 */ | 813{ 814 unsigned long val; 815 int ret; 816 817 if (kstrtoul(buf, 10, &val)) 818 return -EINVAL; 819 820 ret = do_set_fan_div(dev, val); 821 if (ret < 0) 822 return ret; 823 824 return count; 825} 826 827/* 828 * Read and write functions for fan1_pulses sysfs file. Get and set number 829 * of tachometer pulses per fan revolution. 830 */ |
831static ssize_t get_fan_pulses(struct device *dev, 832 struct device_attribute *da, char *buf) | 831static ssize_t fan1_pulses_show(struct device *dev, 832 struct device_attribute *da, char *buf) |
833{ 834 struct g762_data *data = g762_update_client(dev); 835 836 if (IS_ERR(data)) 837 return PTR_ERR(data); 838 839 return sprintf(buf, "%d\n", G762_PULSE_FROM_REG(data->fan_cmd1)); 840} 841 | 833{ 834 struct g762_data *data = g762_update_client(dev); 835 836 if (IS_ERR(data)) 837 return PTR_ERR(data); 838 839 return sprintf(buf, "%d\n", G762_PULSE_FROM_REG(data->fan_cmd1)); 840} 841 |
842static ssize_t set_fan_pulses(struct device *dev, 843 struct device_attribute *da, 844 const char *buf, size_t count) | 842static ssize_t fan1_pulses_store(struct device *dev, 843 struct device_attribute *da, const char *buf, 844 size_t count) |
845{ 846 unsigned long val; 847 int ret; 848 849 if (kstrtoul(buf, 10, &val)) 850 return -EINVAL; 851 852 ret = do_set_fan_pulses(dev, val); 853 if (ret < 0) 854 return ret; 855 856 return count; 857} 858 859/* 860 * Read and write functions for pwm1_enable. Get and set fan speed control mode 861 * (i.e. closed or open-loop). 862 * 863 * Following documentation about hwmon's sysfs interface, a pwm1_enable node | 845{ 846 unsigned long val; 847 int ret; 848 849 if (kstrtoul(buf, 10, &val)) 850 return -EINVAL; 851 852 ret = do_set_fan_pulses(dev, val); 853 if (ret < 0) 854 return ret; 855 856 return count; 857} 858 859/* 860 * Read and write functions for pwm1_enable. Get and set fan speed control mode 861 * (i.e. closed or open-loop). 862 * 863 * Following documentation about hwmon's sysfs interface, a pwm1_enable node |
864 * should accept followings: | 864 * should accept the following: |
865 * 866 * 0 : no fan speed control (i.e. fan at full speed) 867 * 1 : manual fan speed control enabled (use pwm[1-*]) (open-loop) 868 * 2+: automatic fan speed control enabled (use fan[1-*]_target) (closed-loop) 869 * 870 * but we do not accept 0 as this mode is not natively supported by the chip 871 * and it is not emulated by g762 driver. -EINVAL is returned in this case. 872 */ | 865 * 866 * 0 : no fan speed control (i.e. fan at full speed) 867 * 1 : manual fan speed control enabled (use pwm[1-*]) (open-loop) 868 * 2+: automatic fan speed control enabled (use fan[1-*]_target) (closed-loop) 869 * 870 * but we do not accept 0 as this mode is not natively supported by the chip 871 * and it is not emulated by g762 driver. -EINVAL is returned in this case. 872 */ |
873static ssize_t get_pwm_enable(struct device *dev, 874 struct device_attribute *da, char *buf) | 873static ssize_t pwm1_enable_show(struct device *dev, 874 struct device_attribute *da, char *buf) |
875{ 876 struct g762_data *data = g762_update_client(dev); 877 878 if (IS_ERR(data)) 879 return PTR_ERR(data); 880 881 return sprintf(buf, "%d\n", 882 (!!(data->fan_cmd1 & G762_REG_FAN_CMD1_FAN_MODE)) + 1); 883} 884 | 875{ 876 struct g762_data *data = g762_update_client(dev); 877 878 if (IS_ERR(data)) 879 return PTR_ERR(data); 880 881 return sprintf(buf, "%d\n", 882 (!!(data->fan_cmd1 & G762_REG_FAN_CMD1_FAN_MODE)) + 1); 883} 884 |
885static ssize_t set_pwm_enable(struct device *dev, 886 struct device_attribute *da, 887 const char *buf, size_t count) | 885static ssize_t pwm1_enable_store(struct device *dev, 886 struct device_attribute *da, const char *buf, 887 size_t count) |
888{ 889 unsigned long val; 890 int ret; 891 892 if (kstrtoul(buf, 10, &val)) 893 return -EINVAL; 894 895 ret = do_set_pwm_enable(dev, val); 896 if (ret < 0) 897 return ret; 898 899 return count; 900} 901 902/* 903 * Read and write functions for pwm1 sysfs file. Get and set pwm value 904 * (which affects fan speed) in open-loop mode. 0 stops the fan and 255 905 * makes it run at full speed. 906 */ | 888{ 889 unsigned long val; 890 int ret; 891 892 if (kstrtoul(buf, 10, &val)) 893 return -EINVAL; 894 895 ret = do_set_pwm_enable(dev, val); 896 if (ret < 0) 897 return ret; 898 899 return count; 900} 901 902/* 903 * Read and write functions for pwm1 sysfs file. Get and set pwm value 904 * (which affects fan speed) in open-loop mode. 0 stops the fan and 255 905 * makes it run at full speed. 906 */ |
907static ssize_t get_pwm(struct device *dev, struct device_attribute *da, 908 char *buf) | 907static ssize_t pwm1_show(struct device *dev, struct device_attribute *da, 908 char *buf) |
909{ 910 struct g762_data *data = g762_update_client(dev); 911 912 if (IS_ERR(data)) 913 return PTR_ERR(data); 914 915 return sprintf(buf, "%d\n", data->set_out); 916} 917 | 909{ 910 struct g762_data *data = g762_update_client(dev); 911 912 if (IS_ERR(data)) 913 return PTR_ERR(data); 914 915 return sprintf(buf, "%d\n", data->set_out); 916} 917 |
918static ssize_t set_pwm(struct device *dev, struct device_attribute *da, 919 const char *buf, size_t count) | 918static ssize_t pwm1_store(struct device *dev, struct device_attribute *da, 919 const char *buf, size_t count) |
920{ 921 unsigned long val; 922 int ret; 923 924 if (kstrtoul(buf, 10, &val)) 925 return -EINVAL; 926 927 ret = do_set_pwm(dev, val); --- 9 unchanged lines hidden (view full) --- 937 * the fan speed using pulses from fan tachometer. 938 * 939 * Refer to rpm_from_cnt() implementation above to get info about count number 940 * calculation. 941 * 942 * Also note that due to rounding errors it is possible that you don't read 943 * back exactly the value you have set. 944 */ | 920{ 921 unsigned long val; 922 int ret; 923 924 if (kstrtoul(buf, 10, &val)) 925 return -EINVAL; 926 927 ret = do_set_pwm(dev, val); --- 9 unchanged lines hidden (view full) --- 937 * the fan speed using pulses from fan tachometer. 938 * 939 * Refer to rpm_from_cnt() implementation above to get info about count number 940 * calculation. 941 * 942 * Also note that due to rounding errors it is possible that you don't read 943 * back exactly the value you have set. 944 */ |
945static ssize_t get_fan_target(struct device *dev, struct device_attribute *da, 946 char *buf) | 945static ssize_t fan1_target_show(struct device *dev, 946 struct device_attribute *da, char *buf) |
947{ 948 struct g762_data *data = g762_update_client(dev); 949 unsigned int rpm; 950 951 if (IS_ERR(data)) 952 return PTR_ERR(data); 953 954 mutex_lock(&data->update_lock); 955 rpm = rpm_from_cnt(data->set_cnt, data->clk_freq, 956 G762_PULSE_FROM_REG(data->fan_cmd1), 957 G762_CLKDIV_FROM_REG(data->fan_cmd1), 958 G762_GEARMULT_FROM_REG(data->fan_cmd2)); 959 mutex_unlock(&data->update_lock); 960 961 return sprintf(buf, "%u\n", rpm); 962} 963 | 947{ 948 struct g762_data *data = g762_update_client(dev); 949 unsigned int rpm; 950 951 if (IS_ERR(data)) 952 return PTR_ERR(data); 953 954 mutex_lock(&data->update_lock); 955 rpm = rpm_from_cnt(data->set_cnt, data->clk_freq, 956 G762_PULSE_FROM_REG(data->fan_cmd1), 957 G762_CLKDIV_FROM_REG(data->fan_cmd1), 958 G762_GEARMULT_FROM_REG(data->fan_cmd2)); 959 mutex_unlock(&data->update_lock); 960 961 return sprintf(buf, "%u\n", rpm); 962} 963 |
964static ssize_t set_fan_target(struct device *dev, struct device_attribute *da, 965 const char *buf, size_t count) | 964static ssize_t fan1_target_store(struct device *dev, 965 struct device_attribute *da, const char *buf, 966 size_t count) |
966{ 967 unsigned long val; 968 int ret; 969 970 if (kstrtoul(buf, 10, &val)) 971 return -EINVAL; 972 973 ret = do_set_fan_target(dev, val); 974 if (ret < 0) 975 return ret; 976 977 return count; 978} 979 980/* read function for fan1_fault sysfs file. */ | 967{ 968 unsigned long val; 969 int ret; 970 971 if (kstrtoul(buf, 10, &val)) 972 return -EINVAL; 973 974 ret = do_set_fan_target(dev, val); 975 if (ret < 0) 976 return ret; 977 978 return count; 979} 980 981/* read function for fan1_fault sysfs file. */ |
981static ssize_t get_fan_failure(struct device *dev, struct device_attribute *da, | 982static ssize_t fan1_fault_show(struct device *dev, struct device_attribute *da, |
982 char *buf) 983{ 984 struct g762_data *data = g762_update_client(dev); 985 986 if (IS_ERR(data)) 987 return PTR_ERR(data); 988 989 return sprintf(buf, "%u\n", !!(data->fan_sta & G762_REG_FAN_STA_FAIL)); 990} 991 992/* 993 * read function for fan1_alarm sysfs file. Note that OOC condition is 994 * enabled low 995 */ | 983 char *buf) 984{ 985 struct g762_data *data = g762_update_client(dev); 986 987 if (IS_ERR(data)) 988 return PTR_ERR(data); 989 990 return sprintf(buf, "%u\n", !!(data->fan_sta & G762_REG_FAN_STA_FAIL)); 991} 992 993/* 994 * read function for fan1_alarm sysfs file. Note that OOC condition is 995 * enabled low 996 */ |
996static ssize_t get_fan_ooc(struct device *dev, struct device_attribute *da, 997 char *buf) | 997static ssize_t fan1_alarm_show(struct device *dev, 998 struct device_attribute *da, char *buf) |
998{ 999 struct g762_data *data = g762_update_client(dev); 1000 1001 if (IS_ERR(data)) 1002 return PTR_ERR(data); 1003 1004 return sprintf(buf, "%u\n", !(data->fan_sta & G762_REG_FAN_STA_OOC)); 1005} 1006 | 999{ 1000 struct g762_data *data = g762_update_client(dev); 1001 1002 if (IS_ERR(data)) 1003 return PTR_ERR(data); 1004 1005 return sprintf(buf, "%u\n", !(data->fan_sta & G762_REG_FAN_STA_OOC)); 1006} 1007 |
1007static DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, get_pwm, set_pwm); 1008static DEVICE_ATTR(pwm1_mode, S_IWUSR | S_IRUGO, get_pwm_mode, set_pwm_mode); 1009static DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, 1010 get_pwm_enable, set_pwm_enable); 1011static DEVICE_ATTR(fan1_input, S_IRUGO, get_fan_rpm, NULL); 1012static DEVICE_ATTR(fan1_alarm, S_IRUGO, get_fan_ooc, NULL); 1013static DEVICE_ATTR(fan1_fault, S_IRUGO, get_fan_failure, NULL); 1014static DEVICE_ATTR(fan1_target, S_IWUSR | S_IRUGO, 1015 get_fan_target, set_fan_target); 1016static DEVICE_ATTR(fan1_div, S_IWUSR | S_IRUGO, get_fan_div, set_fan_div); 1017static DEVICE_ATTR(fan1_pulses, S_IWUSR | S_IRUGO, 1018 get_fan_pulses, set_fan_pulses); | 1008static DEVICE_ATTR_RW(pwm1); 1009static DEVICE_ATTR_RW(pwm1_mode); 1010static DEVICE_ATTR_RW(pwm1_enable); 1011static DEVICE_ATTR_RO(fan1_input); 1012static DEVICE_ATTR_RO(fan1_alarm); 1013static DEVICE_ATTR_RO(fan1_fault); 1014static DEVICE_ATTR_RW(fan1_target); 1015static DEVICE_ATTR_RW(fan1_div); 1016static DEVICE_ATTR_RW(fan1_pulses); |
1019 1020/* Driver data */ 1021static struct attribute *g762_attrs[] = { 1022 &dev_attr_fan1_input.attr, 1023 &dev_attr_fan1_alarm.attr, 1024 &dev_attr_fan1_fault.attr, 1025 &dev_attr_fan1_target.attr, 1026 &dev_attr_fan1_div.attr, --- 104 unchanged lines hidden --- | 1017 1018/* Driver data */ 1019static struct attribute *g762_attrs[] = { 1020 &dev_attr_fan1_input.attr, 1021 &dev_attr_fan1_alarm.attr, 1022 &dev_attr_fan1_fault.attr, 1023 &dev_attr_fan1_target.attr, 1024 &dev_attr_fan1_div.attr, --- 104 unchanged lines hidden --- |