Commit 6543439f19b829f94a37e1ea277ead76e93b917f

Authored by Hans de Goede
Committed by Guenter Roeck
1 parent 9af0794c63

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>

Showing 1 changed file with 54 additions and 65 deletions Side-by-side Diff

drivers/hwmon/f71882fg.c
... ... @@ -2155,11 +2155,37 @@
2155 2155 }
2156 2156  
2157 2157 static 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 2160 struct f71882fg_data *data = platform_get_drvdata(pdev);
2161 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 2189 err = f71882fg_create_sysfs_files(pdev, &fxxxx_fan_attr[idx][0],
2164 2190 ARRAY_SIZE(fxxxx_fan_attr[0]));
2165 2191 if (err)
2166 2192  
2167 2193  
... ... @@ -2173,10 +2199,34 @@
2173 2199 return err;
2174 2200 }
2175 2201  
2176   - if (!pwm_auto_point)
2177   - return 0; /* All done */
  2202 + dev_info(&pdev->dev, "Fan: %d is in %s mode\n", idx + 1,
  2203 + (data->pwm_enable & (1 << (2 * idx))) ? "duty-cycle" : "RPM");
2178 2204  
  2205 + /* Check for unsupported auto pwm settings */
2179 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 + }
  2228 +
  2229 + switch (data->type) {
2180 2230 case f71862fg:
2181 2231 err = f71882fg_create_sysfs_files(pdev,
2182 2232 &f71862fg_auto_pwm_attr[idx][0],
... ... @@ -2295,8 +2345,6 @@
2295 2345 }
2296 2346  
2297 2347 if (start_reg & 0x02) {
2298   - bool pwm_auto_point = true;
2299   -
2300 2348 switch (data->type) {
2301 2349 case f71808e:
2302 2350 case f71808a:
2303 2351  
2304 2352  
... ... @@ -2322,69 +2370,10 @@
2322 2370 data->pwm_enable =
2323 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 2373 for (i = 0; i < nr_fans; i++) {
2380   - err = f71882fg_create_fan_sysfs_files(pdev, i,
2381   - pwm_auto_point);
  2374 + err = f71882fg_create_fan_sysfs_files(pdev, i);
2382 2375 if (err)
2383 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 2379 /* Some types have 1 extra fan with limited functionality */