aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@ingics.com>2014-07-02 21:49:21 -0400
committerGuenter Roeck <linux@roeck-us.net>2014-08-04 10:01:36 -0400
commitdf51f2d7bc8bf99a7f9c29b2f334e412613c2efc (patch)
treeb59235e237083646f2e49d76cfc7f98aa308448d /drivers/hwmon
parent18faf5b9befa0009ab796990eaa25af81f0f3b6f (diff)
hwmon: (gl520sm) Avoid forward declaration
Reorder functions to avoid forward declaration. Signed-off-by: Axel Lin <axel.lin@ingics.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/gl520sm.c317
1 files changed, 150 insertions, 167 deletions
diff --git a/drivers/hwmon/gl520sm.c b/drivers/hwmon/gl520sm.c
index ed56e09c3dd7..86c08a17210d 100644
--- a/drivers/hwmon/gl520sm.c
+++ b/drivers/hwmon/gl520sm.c
@@ -73,38 +73,6 @@ static const u8 GL520_REG_TEMP_MAX_HYST[] = { 0x06, 0x18 };
73#define GL520_REG_BEEP_MASK 0x10 73#define GL520_REG_BEEP_MASK 0x10
74#define GL520_REG_BEEP_ENABLE GL520_REG_CONF 74#define GL520_REG_BEEP_ENABLE GL520_REG_CONF
75 75
76/*
77 * Function declarations
78 */
79
80static int gl520_probe(struct i2c_client *client,
81 const struct i2c_device_id *id);
82static int gl520_detect(struct i2c_client *client, struct i2c_board_info *info);
83static void gl520_init_client(struct i2c_client *client);
84static int gl520_remove(struct i2c_client *client);
85static int gl520_read_value(struct i2c_client *client, u8 reg);
86static int gl520_write_value(struct i2c_client *client, u8 reg, u16 value);
87static struct gl520_data *gl520_update_device(struct device *dev);
88
89/* Driver data */
90static const struct i2c_device_id gl520_id[] = {
91 { "gl520sm", 0 },
92 { }
93};
94MODULE_DEVICE_TABLE(i2c, gl520_id);
95
96static struct i2c_driver gl520_driver = {
97 .class = I2C_CLASS_HWMON,
98 .driver = {
99 .name = "gl520sm",
100 },
101 .probe = gl520_probe,
102 .remove = gl520_remove,
103 .id_table = gl520_id,
104 .detect = gl520_detect,
105 .address_list = normal_i2c,
106};
107
108/* Client data */ 76/* Client data */
109struct gl520_data { 77struct gl520_data {
110 struct device *hwmon_dev; 78 struct device *hwmon_dev;
@@ -132,6 +100,102 @@ struct gl520_data {
132}; 100};
133 101
134/* 102/*
103 * Registers 0x07 to 0x0c are word-sized, others are byte-sized
104 * GL520 uses a high-byte first convention
105 */
106static int gl520_read_value(struct i2c_client *client, u8 reg)
107{
108 if ((reg >= 0x07) && (reg <= 0x0c))
109 return i2c_smbus_read_word_swapped(client, reg);
110 else
111 return i2c_smbus_read_byte_data(client, reg);
112}
113
114static int gl520_write_value(struct i2c_client *client, u8 reg, u16 value)
115{
116 if ((reg >= 0x07) && (reg <= 0x0c))
117 return i2c_smbus_write_word_swapped(client, reg, value);
118 else
119 return i2c_smbus_write_byte_data(client, reg, value);
120}
121
122static struct gl520_data *gl520_update_device(struct device *dev)
123{
124 struct i2c_client *client = to_i2c_client(dev);
125 struct gl520_data *data = i2c_get_clientdata(client);
126 int val, i;
127
128 mutex_lock(&data->update_lock);
129
130 if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) {
131
132 dev_dbg(&client->dev, "Starting gl520sm update\n");
133
134 data->alarms = gl520_read_value(client, GL520_REG_ALARMS);
135 data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK);
136 data->vid = gl520_read_value(client,
137 GL520_REG_VID_INPUT) & 0x1f;
138
139 for (i = 0; i < 4; i++) {
140 data->in_input[i] = gl520_read_value(client,
141 GL520_REG_IN_INPUT[i]);
142 val = gl520_read_value(client, GL520_REG_IN_LIMIT[i]);
143 data->in_min[i] = val & 0xff;
144 data->in_max[i] = (val >> 8) & 0xff;
145 }
146
147 val = gl520_read_value(client, GL520_REG_FAN_INPUT);
148 data->fan_input[0] = (val >> 8) & 0xff;
149 data->fan_input[1] = val & 0xff;
150
151 val = gl520_read_value(client, GL520_REG_FAN_MIN);
152 data->fan_min[0] = (val >> 8) & 0xff;
153 data->fan_min[1] = val & 0xff;
154
155 data->temp_input[0] = gl520_read_value(client,
156 GL520_REG_TEMP_INPUT[0]);
157 data->temp_max[0] = gl520_read_value(client,
158 GL520_REG_TEMP_MAX[0]);
159 data->temp_max_hyst[0] = gl520_read_value(client,
160 GL520_REG_TEMP_MAX_HYST[0]);
161
162 val = gl520_read_value(client, GL520_REG_FAN_DIV);
163 data->fan_div[0] = (val >> 6) & 0x03;
164 data->fan_div[1] = (val >> 4) & 0x03;
165 data->fan_off = (val >> 2) & 0x01;
166
167 data->alarms &= data->alarm_mask;
168
169 val = gl520_read_value(client, GL520_REG_CONF);
170 data->beep_enable = !((val >> 2) & 1);
171
172 /* Temp1 and Vin4 are the same input */
173 if (data->two_temps) {
174 data->temp_input[1] = gl520_read_value(client,
175 GL520_REG_TEMP_INPUT[1]);
176 data->temp_max[1] = gl520_read_value(client,
177 GL520_REG_TEMP_MAX[1]);
178 data->temp_max_hyst[1] = gl520_read_value(client,
179 GL520_REG_TEMP_MAX_HYST[1]);
180 } else {
181 data->in_input[4] = gl520_read_value(client,
182 GL520_REG_IN_INPUT[4]);
183 data->in_min[4] = gl520_read_value(client,
184 GL520_REG_IN_MIN[4]);
185 data->in_max[4] = gl520_read_value(client,
186 GL520_REG_IN_MAX[4]);
187 }
188
189 data->last_updated = jiffies;
190 data->valid = 1;
191 }
192
193 mutex_unlock(&data->update_lock);
194
195 return data;
196}
197
198/*
135 * Sysfs stuff 199 * Sysfs stuff
136 */ 200 */
137 201
@@ -772,6 +836,44 @@ static int gl520_detect(struct i2c_client *client, struct i2c_board_info *info)
772 return 0; 836 return 0;
773} 837}
774 838
839/* Called when we have found a new GL520SM. */
840static void gl520_init_client(struct i2c_client *client)
841{
842 struct gl520_data *data = i2c_get_clientdata(client);
843 u8 oldconf, conf;
844
845 conf = oldconf = gl520_read_value(client, GL520_REG_CONF);
846
847 data->alarm_mask = 0xff;
848 data->vrm = vid_which_vrm();
849
850 if (extra_sensor_type == 1)
851 conf &= ~0x10;
852 else if (extra_sensor_type == 2)
853 conf |= 0x10;
854 data->two_temps = !(conf & 0x10);
855
856 /* If IRQ# is disabled, we can safely force comparator mode */
857 if (!(conf & 0x20))
858 conf &= 0xf7;
859
860 /* Enable monitoring if needed */
861 conf |= 0x40;
862
863 if (conf != oldconf)
864 gl520_write_value(client, GL520_REG_CONF, conf);
865
866 gl520_update_device(&(client->dev));
867
868 if (data->fan_min[0] == 0)
869 data->alarm_mask &= ~0x20;
870 if (data->fan_min[1] == 0)
871 data->alarm_mask &= ~0x40;
872
873 data->beep_mask &= data->alarm_mask;
874 gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask);
875}
876
775static int gl520_probe(struct i2c_client *client, 877static int gl520_probe(struct i2c_client *client,
776 const struct i2c_device_id *id) 878 const struct i2c_device_id *id)
777{ 879{
@@ -817,45 +919,6 @@ exit_remove_files:
817 return err; 919 return err;
818} 920}
819 921
820
821/* Called when we have found a new GL520SM. */
822static void gl520_init_client(struct i2c_client *client)
823{
824 struct gl520_data *data = i2c_get_clientdata(client);
825 u8 oldconf, conf;
826
827 conf = oldconf = gl520_read_value(client, GL520_REG_CONF);
828
829 data->alarm_mask = 0xff;
830 data->vrm = vid_which_vrm();
831
832 if (extra_sensor_type == 1)
833 conf &= ~0x10;
834 else if (extra_sensor_type == 2)
835 conf |= 0x10;
836 data->two_temps = !(conf & 0x10);
837
838 /* If IRQ# is disabled, we can safely force comparator mode */
839 if (!(conf & 0x20))
840 conf &= 0xf7;
841
842 /* Enable monitoring if needed */
843 conf |= 0x40;
844
845 if (conf != oldconf)
846 gl520_write_value(client, GL520_REG_CONF, conf);
847
848 gl520_update_device(&(client->dev));
849
850 if (data->fan_min[0] == 0)
851 data->alarm_mask &= ~0x20;
852 if (data->fan_min[1] == 0)
853 data->alarm_mask &= ~0x40;
854
855 data->beep_mask &= data->alarm_mask;
856 gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask);
857}
858
859static int gl520_remove(struct i2c_client *client) 922static int gl520_remove(struct i2c_client *client)
860{ 923{
861 struct gl520_data *data = i2c_get_clientdata(client); 924 struct gl520_data *data = i2c_get_clientdata(client);
@@ -868,103 +931,23 @@ static int gl520_remove(struct i2c_client *client)
868 return 0; 931 return 0;
869} 932}
870 933
934static const struct i2c_device_id gl520_id[] = {
935 { "gl520sm", 0 },
936 { }
937};
938MODULE_DEVICE_TABLE(i2c, gl520_id);
871 939
872/* 940static struct i2c_driver gl520_driver = {
873 * Registers 0x07 to 0x0c are word-sized, others are byte-sized 941 .class = I2C_CLASS_HWMON,
874 * GL520 uses a high-byte first convention 942 .driver = {
875 */ 943 .name = "gl520sm",
876static int gl520_read_value(struct i2c_client *client, u8 reg) 944 },
877{ 945 .probe = gl520_probe,
878 if ((reg >= 0x07) && (reg <= 0x0c)) 946 .remove = gl520_remove,
879 return i2c_smbus_read_word_swapped(client, reg); 947 .id_table = gl520_id,
880 else 948 .detect = gl520_detect,
881 return i2c_smbus_read_byte_data(client, reg); 949 .address_list = normal_i2c,
882} 950};
883
884static int gl520_write_value(struct i2c_client *client, u8 reg, u16 value)
885{
886 if ((reg >= 0x07) && (reg <= 0x0c))
887 return i2c_smbus_write_word_swapped(client, reg, value);
888 else
889 return i2c_smbus_write_byte_data(client, reg, value);
890}
891
892
893static struct gl520_data *gl520_update_device(struct device *dev)
894{
895 struct i2c_client *client = to_i2c_client(dev);
896 struct gl520_data *data = i2c_get_clientdata(client);
897 int val, i;
898
899 mutex_lock(&data->update_lock);
900
901 if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) {
902
903 dev_dbg(&client->dev, "Starting gl520sm update\n");
904
905 data->alarms = gl520_read_value(client, GL520_REG_ALARMS);
906 data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK);
907 data->vid = gl520_read_value(client,
908 GL520_REG_VID_INPUT) & 0x1f;
909
910 for (i = 0; i < 4; i++) {
911 data->in_input[i] = gl520_read_value(client,
912 GL520_REG_IN_INPUT[i]);
913 val = gl520_read_value(client, GL520_REG_IN_LIMIT[i]);
914 data->in_min[i] = val & 0xff;
915 data->in_max[i] = (val >> 8) & 0xff;
916 }
917
918 val = gl520_read_value(client, GL520_REG_FAN_INPUT);
919 data->fan_input[0] = (val >> 8) & 0xff;
920 data->fan_input[1] = val & 0xff;
921
922 val = gl520_read_value(client, GL520_REG_FAN_MIN);
923 data->fan_min[0] = (val >> 8) & 0xff;
924 data->fan_min[1] = val & 0xff;
925
926 data->temp_input[0] = gl520_read_value(client,
927 GL520_REG_TEMP_INPUT[0]);
928 data->temp_max[0] = gl520_read_value(client,
929 GL520_REG_TEMP_MAX[0]);
930 data->temp_max_hyst[0] = gl520_read_value(client,
931 GL520_REG_TEMP_MAX_HYST[0]);
932
933 val = gl520_read_value(client, GL520_REG_FAN_DIV);
934 data->fan_div[0] = (val >> 6) & 0x03;
935 data->fan_div[1] = (val >> 4) & 0x03;
936 data->fan_off = (val >> 2) & 0x01;
937
938 data->alarms &= data->alarm_mask;
939
940 val = gl520_read_value(client, GL520_REG_CONF);
941 data->beep_enable = !((val >> 2) & 1);
942
943 /* Temp1 and Vin4 are the same input */
944 if (data->two_temps) {
945 data->temp_input[1] = gl520_read_value(client,
946 GL520_REG_TEMP_INPUT[1]);
947 data->temp_max[1] = gl520_read_value(client,
948 GL520_REG_TEMP_MAX[1]);
949 data->temp_max_hyst[1] = gl520_read_value(client,
950 GL520_REG_TEMP_MAX_HYST[1]);
951 } else {
952 data->in_input[4] = gl520_read_value(client,
953 GL520_REG_IN_INPUT[4]);
954 data->in_min[4] = gl520_read_value(client,
955 GL520_REG_IN_MIN[4]);
956 data->in_max[4] = gl520_read_value(client,
957 GL520_REG_IN_MAX[4]);
958 }
959
960 data->last_updated = jiffies;
961 data->valid = 1;
962 }
963
964 mutex_unlock(&data->update_lock);
965
966 return data;
967}
968 951
969module_i2c_driver(gl520_driver); 952module_i2c_driver(gl520_driver);
970 953