aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2011-09-09 06:12:35 -0400
committerGuenter Roeck <guenter.roeck@ericsson.com>2011-10-24 14:09:38 -0400
commit6543439f19b829f94a37e1ea277ead76e93b917f (patch)
treed3f27ab8c12de502458cc326d21d5ce7c28e762e
parent9af0794c63ab1fbced7aa6f9d918ee0f7e7c45e5 (diff)
hwmon/f71882fg: Make the decision wether to register fan attr. per fan
Before this patch the f71882fg driver completely fails to initialize on systems which have reserved settings in the pwm enable register, and it disables all auto pwm sysfs attributes if any fan is controlled by a digital sensor reading. This patch changes the fail to initialize into don't register any attributes for the fan for which there are reserved settings in the pwm enable register and also makes the not registering of auto pwm sysfs attributes a per fan thing. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
-rw-r--r--drivers/hwmon/f71882fg.c119
1 files changed, 54 insertions, 65 deletions
diff --git a/drivers/hwmon/f71882fg.c b/drivers/hwmon/f71882fg.c
index 47c9b8d425ff..59dd881c71d8 100644
--- a/drivers/hwmon/f71882fg.c
+++ b/drivers/hwmon/f71882fg.c
@@ -2155,11 +2155,37 @@ static void f71882fg_remove_sysfs_files(struct platform_device *pdev,
2155} 2155}
2156 2156
2157static int __devinit f71882fg_create_fan_sysfs_files( 2157static int __devinit f71882fg_create_fan_sysfs_files(
2158 struct platform_device *pdev, int idx, bool pwm_auto_point) 2158 struct platform_device *pdev, int idx)
2159{ 2159{
2160 struct f71882fg_data *data = platform_get_drvdata(pdev); 2160 struct f71882fg_data *data = platform_get_drvdata(pdev);
2161 int err; 2161 int err;
2162 2162
2163 /* Sanity check the pwm setting */
2164 err = 0;
2165 switch (data->type) {
2166 case f71858fg:
2167 if (((data->pwm_enable >> (idx * 2)) & 3) == 3)
2168 err = 1;
2169 break;
2170 case f71862fg:
2171 if (((data->pwm_enable >> (idx * 2)) & 1) != 1)
2172 err = 1;
2173 break;
2174 case f8000:
2175 if (idx == 2)
2176 err = data->pwm_enable & 0x20;
2177 break;
2178 default:
2179 break;
2180 }
2181 if (err) {
2182 dev_err(&pdev->dev,
2183 "Invalid (reserved) pwm settings: 0x%02x, "
2184 "skipping fan %d\n",
2185 (data->pwm_enable >> (idx * 2)) & 3, idx + 1);
2186 return 0; /* This is a non fatal condition */
2187 }
2188
2163 err = f71882fg_create_sysfs_files(pdev, &fxxxx_fan_attr[idx][0], 2189 err = f71882fg_create_sysfs_files(pdev, &fxxxx_fan_attr[idx][0],
2164 ARRAY_SIZE(fxxxx_fan_attr[0])); 2190 ARRAY_SIZE(fxxxx_fan_attr[0]));
2165 if (err) 2191 if (err)
@@ -2173,8 +2199,32 @@ static int __devinit f71882fg_create_fan_sysfs_files(
2173 return err; 2199 return err;
2174 } 2200 }
2175 2201
2176 if (!pwm_auto_point) 2202 dev_info(&pdev->dev, "Fan: %d is in %s mode\n", idx + 1,
2177 return 0; /* All done */ 2203 (data->pwm_enable & (1 << (2 * idx))) ? "duty-cycle" : "RPM");
2204
2205 /* Check for unsupported auto pwm settings */
2206 switch (data->type) {
2207 case f71808e:
2208 case f71808a:
2209 case f71869:
2210 case f71869a:
2211 case f71889fg:
2212 case f71889ed:
2213 case f71889a:
2214 data->pwm_auto_point_mapping[idx] =
2215 f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(idx));
2216 if ((data->pwm_auto_point_mapping[idx] & 0x80) ||
2217 (data->pwm_auto_point_mapping[idx] & 3) == 0) {
2218 dev_warn(&pdev->dev,
2219 "Auto pwm controlled by raw digital "
2220 "data, disabling pwm auto_point "
2221 "sysfs attributes for fan %d\n", idx + 1);
2222 return 0; /* This is a non fatal condition */
2223 }
2224 break;
2225 default:
2226 break;
2227 }
2178 2228
2179 switch (data->type) { 2229 switch (data->type) {
2180 case f71862fg: 2230 case f71862fg:
@@ -2295,8 +2345,6 @@ static int __devinit f71882fg_probe(struct platform_device *pdev)
2295 } 2345 }
2296 2346
2297 if (start_reg & 0x02) { 2347 if (start_reg & 0x02) {
2298 bool pwm_auto_point = true;
2299
2300 switch (data->type) { 2348 switch (data->type) {
2301 case f71808e: 2349 case f71808e:
2302 case f71808a: 2350 case f71808a:
@@ -2322,69 +2370,10 @@ static int __devinit f71882fg_probe(struct platform_device *pdev)
2322 data->pwm_enable = 2370 data->pwm_enable =
2323 f71882fg_read8(data, F71882FG_REG_PWM_ENABLE); 2371 f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
2324 2372
2325 /* Sanity check the pwm settings */
2326 switch (data->type) {
2327 case f71858fg:
2328 err = 0;
2329 for (i = 0; i < nr_fans; i++)
2330 if (((data->pwm_enable >> (i * 2)) & 3) == 3)
2331 err = 1;
2332 break;
2333 case f71862fg:
2334 err = (data->pwm_enable & 0x15) != 0x15;
2335 break;
2336 case f8000:
2337 err = data->pwm_enable & 0x20;
2338 break;
2339 default:
2340 err = 0;
2341 break;
2342 }
2343 if (err) {
2344 dev_err(&pdev->dev,
2345 "Invalid (reserved) pwm settings: 0x%02x\n",
2346 (unsigned int)data->pwm_enable);
2347 err = -ENODEV;
2348 goto exit_unregister_sysfs;
2349 }
2350
2351 switch (data->type) {
2352 case f71808e:
2353 case f71808a:
2354 case f71869:
2355 case f71869a:
2356 case f71889fg:
2357 case f71889ed:
2358 case f71889a:
2359 for (i = 0; i < nr_fans; i++) {
2360 data->pwm_auto_point_mapping[i] =
2361 f71882fg_read8(data,
2362 F71882FG_REG_POINT_MAPPING(i));
2363 if ((data->pwm_auto_point_mapping[i] & 0x80) ||
2364 (data->pwm_auto_point_mapping[i] & 3) == 0)
2365 break;
2366 }
2367 if (i != nr_fans) {
2368 dev_warn(&pdev->dev,
2369 "Auto pwm controlled by raw digital "
2370 "data, disabling pwm auto_point "
2371 "sysfs attributes\n");
2372 pwm_auto_point = false;
2373 }
2374 break;
2375 default:
2376 break;
2377 }
2378
2379 for (i = 0; i < nr_fans; i++) { 2373 for (i = 0; i < nr_fans; i++) {
2380 err = f71882fg_create_fan_sysfs_files(pdev, i, 2374 err = f71882fg_create_fan_sysfs_files(pdev, i);
2381 pwm_auto_point);
2382 if (err) 2375 if (err)
2383 goto exit_unregister_sysfs; 2376 goto exit_unregister_sysfs;
2384
2385 dev_info(&pdev->dev, "Fan: %d is in %s mode\n", i + 1,
2386 (data->pwm_enable & (1 << 2 * i)) ?
2387 "duty-cycle" : "RPM");
2388 } 2377 }
2389 2378
2390 /* Some types have 1 extra fan with limited functionality */ 2379 /* Some types have 1 extra fan with limited functionality */