diff options
author | Hans de Goede <hdegoede@redhat.com> | 2011-09-09 06:12:34 -0400 |
---|---|---|
committer | Guenter Roeck <guenter.roeck@ericsson.com> | 2011-10-24 14:09:37 -0400 |
commit | 9af0794c63ab1fbced7aa6f9d918ee0f7e7c45e5 (patch) | |
tree | ba2b4224b24475e80aef8d16096bfb418a7e8375 /drivers/hwmon/f71882fg.c | |
parent | 5584014256f704e1031d10d0bd291bc52fab5c40 (diff) |
hwmon/f71882fg: Add a f71882fg_create_fan_sysfs_files helper function
This is a preparation patch for not registering fan/pwm attributes for
some fans (rather then register them for all or for none).
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
Diffstat (limited to 'drivers/hwmon/f71882fg.c')
-rw-r--r-- | drivers/hwmon/f71882fg.c | 108 |
1 files changed, 64 insertions, 44 deletions
diff --git a/drivers/hwmon/f71882fg.c b/drivers/hwmon/f71882fg.c index c0805aab117a..47c9b8d425ff 100644 --- a/drivers/hwmon/f71882fg.c +++ b/drivers/hwmon/f71882fg.c | |||
@@ -2154,6 +2154,54 @@ static void f71882fg_remove_sysfs_files(struct platform_device *pdev, | |||
2154 | device_remove_file(&pdev->dev, &attr[i].dev_attr); | 2154 | device_remove_file(&pdev->dev, &attr[i].dev_attr); |
2155 | } | 2155 | } |
2156 | 2156 | ||
2157 | static int __devinit f71882fg_create_fan_sysfs_files( | ||
2158 | struct platform_device *pdev, int idx, bool pwm_auto_point) | ||
2159 | { | ||
2160 | struct f71882fg_data *data = platform_get_drvdata(pdev); | ||
2161 | int err; | ||
2162 | |||
2163 | err = f71882fg_create_sysfs_files(pdev, &fxxxx_fan_attr[idx][0], | ||
2164 | ARRAY_SIZE(fxxxx_fan_attr[0])); | ||
2165 | if (err) | ||
2166 | return err; | ||
2167 | |||
2168 | if (f71882fg_fan_has_beep[data->type]) { | ||
2169 | err = f71882fg_create_sysfs_files(pdev, | ||
2170 | &fxxxx_fan_beep_attr[idx], | ||
2171 | 1); | ||
2172 | if (err) | ||
2173 | return err; | ||
2174 | } | ||
2175 | |||
2176 | if (!pwm_auto_point) | ||
2177 | return 0; /* All done */ | ||
2178 | |||
2179 | switch (data->type) { | ||
2180 | case f71862fg: | ||
2181 | err = f71882fg_create_sysfs_files(pdev, | ||
2182 | &f71862fg_auto_pwm_attr[idx][0], | ||
2183 | ARRAY_SIZE(f71862fg_auto_pwm_attr[0])); | ||
2184 | break; | ||
2185 | case f71808e: | ||
2186 | case f71869: | ||
2187 | err = f71882fg_create_sysfs_files(pdev, | ||
2188 | &f71869_auto_pwm_attr[idx][0], | ||
2189 | ARRAY_SIZE(f71869_auto_pwm_attr[0])); | ||
2190 | break; | ||
2191 | case f8000: | ||
2192 | err = f71882fg_create_sysfs_files(pdev, | ||
2193 | &f8000_auto_pwm_attr[idx][0], | ||
2194 | ARRAY_SIZE(f8000_auto_pwm_attr[0])); | ||
2195 | break; | ||
2196 | default: | ||
2197 | err = f71882fg_create_sysfs_files(pdev, | ||
2198 | &fxxxx_auto_pwm_attr[idx][0], | ||
2199 | ARRAY_SIZE(fxxxx_auto_pwm_attr[0])); | ||
2200 | } | ||
2201 | |||
2202 | return err; | ||
2203 | } | ||
2204 | |||
2157 | static int __devinit f71882fg_probe(struct platform_device *pdev) | 2205 | static int __devinit f71882fg_probe(struct platform_device *pdev) |
2158 | { | 2206 | { |
2159 | struct f71882fg_data *data; | 2207 | struct f71882fg_data *data; |
@@ -2247,6 +2295,8 @@ static int __devinit f71882fg_probe(struct platform_device *pdev) | |||
2247 | } | 2295 | } |
2248 | 2296 | ||
2249 | if (start_reg & 0x02) { | 2297 | if (start_reg & 0x02) { |
2298 | bool pwm_auto_point = true; | ||
2299 | |||
2250 | switch (data->type) { | 2300 | switch (data->type) { |
2251 | case f71808e: | 2301 | case f71808e: |
2252 | case f71808a: | 2302 | case f71808a: |
@@ -2298,18 +2348,6 @@ static int __devinit f71882fg_probe(struct platform_device *pdev) | |||
2298 | goto exit_unregister_sysfs; | 2348 | goto exit_unregister_sysfs; |
2299 | } | 2349 | } |
2300 | 2350 | ||
2301 | err = f71882fg_create_sysfs_files(pdev, &fxxxx_fan_attr[0][0], | ||
2302 | ARRAY_SIZE(fxxxx_fan_attr[0]) * nr_fans); | ||
2303 | if (err) | ||
2304 | goto exit_unregister_sysfs; | ||
2305 | |||
2306 | if (f71882fg_fan_has_beep[data->type]) { | ||
2307 | err = f71882fg_create_sysfs_files(pdev, | ||
2308 | fxxxx_fan_beep_attr, nr_fans); | ||
2309 | if (err) | ||
2310 | goto exit_unregister_sysfs; | ||
2311 | } | ||
2312 | |||
2313 | switch (data->type) { | 2351 | switch (data->type) { |
2314 | case f71808e: | 2352 | case f71808e: |
2315 | case f71808a: | 2353 | case f71808a: |
@@ -2331,59 +2369,41 @@ static int __devinit f71882fg_probe(struct platform_device *pdev) | |||
2331 | "Auto pwm controlled by raw digital " | 2369 | "Auto pwm controlled by raw digital " |
2332 | "data, disabling pwm auto_point " | 2370 | "data, disabling pwm auto_point " |
2333 | "sysfs attributes\n"); | 2371 | "sysfs attributes\n"); |
2334 | goto no_pwm_auto_point; | 2372 | pwm_auto_point = false; |
2335 | } | 2373 | } |
2336 | break; | 2374 | break; |
2337 | default: | 2375 | default: |
2338 | break; | 2376 | break; |
2339 | } | 2377 | } |
2340 | 2378 | ||
2341 | switch (data->type) { | 2379 | for (i = 0; i < nr_fans; i++) { |
2342 | case f71808a: | 2380 | err = f71882fg_create_fan_sysfs_files(pdev, i, |
2343 | err = f71882fg_create_sysfs_files(pdev, | 2381 | pwm_auto_point); |
2344 | &fxxxx_auto_pwm_attr[0][0], | ||
2345 | ARRAY_SIZE(fxxxx_auto_pwm_attr[0]) * nr_fans); | ||
2346 | if (err) | 2382 | if (err) |
2347 | goto exit_unregister_sysfs; | 2383 | 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 | } | ||
2389 | |||
2390 | /* Some types have 1 extra fan with limited functionality */ | ||
2391 | switch (data->type) { | ||
2392 | case f71808a: | ||
2348 | err = f71882fg_create_sysfs_files(pdev, | 2393 | err = f71882fg_create_sysfs_files(pdev, |
2349 | f71808a_fan3_attr, | 2394 | f71808a_fan3_attr, |
2350 | ARRAY_SIZE(f71808a_fan3_attr)); | 2395 | ARRAY_SIZE(f71808a_fan3_attr)); |
2351 | break; | 2396 | break; |
2352 | case f71862fg: | ||
2353 | err = f71882fg_create_sysfs_files(pdev, | ||
2354 | &f71862fg_auto_pwm_attr[0][0], | ||
2355 | ARRAY_SIZE(f71862fg_auto_pwm_attr[0]) * | ||
2356 | nr_fans); | ||
2357 | break; | ||
2358 | case f71808e: | ||
2359 | case f71869: | ||
2360 | err = f71882fg_create_sysfs_files(pdev, | ||
2361 | &f71869_auto_pwm_attr[0][0], | ||
2362 | ARRAY_SIZE(f71869_auto_pwm_attr[0]) * nr_fans); | ||
2363 | break; | ||
2364 | case f8000: | 2397 | case f8000: |
2365 | err = f71882fg_create_sysfs_files(pdev, | 2398 | err = f71882fg_create_sysfs_files(pdev, |
2366 | f8000_fan_attr, | 2399 | f8000_fan_attr, |
2367 | ARRAY_SIZE(f8000_fan_attr)); | 2400 | ARRAY_SIZE(f8000_fan_attr)); |
2368 | if (err) | ||
2369 | goto exit_unregister_sysfs; | ||
2370 | err = f71882fg_create_sysfs_files(pdev, | ||
2371 | &f8000_auto_pwm_attr[0][0], | ||
2372 | ARRAY_SIZE(f8000_auto_pwm_attr[0]) * nr_fans); | ||
2373 | break; | 2401 | break; |
2374 | default: | 2402 | default: |
2375 | err = f71882fg_create_sysfs_files(pdev, | 2403 | break; |
2376 | &fxxxx_auto_pwm_attr[0][0], | ||
2377 | ARRAY_SIZE(fxxxx_auto_pwm_attr[0]) * nr_fans); | ||
2378 | } | 2404 | } |
2379 | if (err) | 2405 | if (err) |
2380 | goto exit_unregister_sysfs; | 2406 | goto exit_unregister_sysfs; |
2381 | |||
2382 | no_pwm_auto_point: | ||
2383 | for (i = 0; i < nr_fans; i++) | ||
2384 | dev_info(&pdev->dev, "Fan: %d is in %s mode\n", i + 1, | ||
2385 | (data->pwm_enable & (1 << 2 * i)) ? | ||
2386 | "duty-cycle" : "RPM"); | ||
2387 | } | 2407 | } |
2388 | 2408 | ||
2389 | data->hwmon_dev = hwmon_device_register(&pdev->dev); | 2409 | data->hwmon_dev = hwmon_device_register(&pdev->dev); |