~ubuntu-branches/debian/wheezy/linux-2.6/wheezy

« back to all changes in this revision

Viewing changes to drivers/hwmon/lm85.c

  • Committer: Bazaar Package Importer
  • Author(s): Ben Hutchings, Ben Hutchings, Aurelien Jarno, Martin Michlmayr
  • Date: 2011-04-06 13:53:30 UTC
  • mfrom: (43.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20110406135330-wjufxhd0tvn3zx4z
Tags: 2.6.38-3
[ Ben Hutchings ]
* [ppc64] Add to linux-tools package architectures (Closes: #620124)
* [amd64] Save cr4 to mmu_cr4_features at boot time (Closes: #620284)
* appletalk: Fix bugs introduced when removing use of BKL
* ALSA: Fix yet another race in disconnection
* cciss: Fix lost command issue
* ath9k: Fix kernel panic in AR2427
* ses: Avoid kernel panic when lun 0 is not mapped
* PCI/ACPI: Report ASPM support to BIOS if not disabled from command line

[ Aurelien Jarno ]
* rtlwifi: fix build when PCI is not enabled.

[ Martin Michlmayr ]
* rtlwifi: Eliminate udelay calls with too large values (Closes: #620204)

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
    Copyright (c) 2002, 2003  Philip Pokorny <ppokorny@penguincomputing.com>
6
6
    Copyright (c) 2003        Margit Schubert-While <margitsw@t-online.de>
7
7
    Copyright (c) 2004        Justin Thiessen <jthiessen@penguincomputing.com>
8
 
    Copyright (C) 2007, 2008  Jean Delvare <khali@linux-fr.org>
 
8
    Copyright (C) 2007--2009  Jean Delvare <khali@linux-fr.org>
9
9
 
10
10
    Chip details at           <http://www.national.com/ds/LM/LM85.pdf>
11
11
 
38
38
/* Addresses to scan */
39
39
static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
40
40
 
41
 
/* Insmod parameters */
42
 
I2C_CLIENT_INSMOD_7(lm85b, lm85c, adm1027, adt7463, adt7468, emc6d100,
43
 
                    emc6d102);
 
41
enum chips {
 
42
        any_chip, lm85b, lm85c,
 
43
        adm1027, adt7463, adt7468,
 
44
        emc6d100, emc6d102, emc6d103
 
45
};
44
46
 
45
47
/* The LM85 registers */
46
48
 
62
64
#define LM85_REG_VERSTEP                0x3f
63
65
 
64
66
#define ADT7468_REG_CFG5                0x7c
65
 
#define         ADT7468_OFF64           0x01
 
67
#define         ADT7468_OFF64           (1 << 0)
 
68
#define         ADT7468_HFPWM           (1 << 1)
66
69
#define IS_ADT7468_OFF64(data)          \
67
70
        ((data)->type == adt7468 && !((data)->cfg5 & ADT7468_OFF64))
 
71
#define IS_ADT7468_HFPWM(data)          \
 
72
        ((data)->type == adt7468 && !((data)->cfg5 & ADT7468_HFPWM))
68
73
 
69
74
/* These are the recognized values for the above regs */
70
75
#define LM85_COMPANY_NATIONAL           0x01
85
90
#define LM85_VERSTEP_EMC6D100_A0        0x60
86
91
#define LM85_VERSTEP_EMC6D100_A1        0x61
87
92
#define LM85_VERSTEP_EMC6D102           0x65
 
93
#define LM85_VERSTEP_EMC6D103_A0        0x68
 
94
#define LM85_VERSTEP_EMC6D103_A1        0x69
 
95
#define LM85_VERSTEP_EMC6D103S          0x6A    /* Also known as EMC6D103:A2 */
88
96
 
89
97
#define LM85_REG_CONFIG                 0x40
90
98
 
323
331
        struct lm85_zone zone[3];
324
332
};
325
333
 
326
 
static int lm85_detect(struct i2c_client *client, int kind,
327
 
                       struct i2c_board_info *info);
 
334
static int lm85_detect(struct i2c_client *client, struct i2c_board_info *info);
328
335
static int lm85_probe(struct i2c_client *client,
329
336
                      const struct i2c_device_id *id);
330
337
static int lm85_remove(struct i2c_client *client);
344
351
        { "emc6d100", emc6d100 },
345
352
        { "emc6d101", emc6d100 },
346
353
        { "emc6d102", emc6d102 },
 
354
        { "emc6d103", emc6d103 },
347
355
        { }
348
356
};
349
357
MODULE_DEVICE_TABLE(i2c, lm85_id);
357
365
        .remove         = lm85_remove,
358
366
        .id_table       = lm85_id,
359
367
        .detect         = lm85_detect,
360
 
        .address_data   = &addr_data,
 
368
        .address_list   = normal_i2c,
361
369
};
362
370
 
363
371
 
566
574
{
567
575
        int nr = to_sensor_dev_attr(attr)->index;
568
576
        struct lm85_data *data = lm85_update_device(dev);
569
 
        return sprintf(buf, "%d\n", FREQ_FROM_REG(data->freq_map,
570
 
                                                  data->pwm_freq[nr]));
 
577
        int freq;
 
578
 
 
579
        if (IS_ADT7468_HFPWM(data))
 
580
                freq = 22500;
 
581
        else
 
582
                freq = FREQ_FROM_REG(data->freq_map, data->pwm_freq[nr]);
 
583
 
 
584
        return sprintf(buf, "%d\n", freq);
571
585
}
572
586
 
573
587
static ssize_t set_pwm_freq(struct device *dev,
579
593
        long val = simple_strtol(buf, NULL, 10);
580
594
 
581
595
        mutex_lock(&data->update_lock);
582
 
        data->pwm_freq[nr] = FREQ_TO_REG(data->freq_map, val);
583
 
        lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
584
 
                (data->zone[nr].range << 4)
585
 
                | data->pwm_freq[nr]);
 
596
        /* The ADT7468 has a special high-frequency PWM output mode,
 
597
         * where all PWM outputs are driven by a 22.5 kHz clock.
 
598
         * This might confuse the user, but there's not much we can do. */
 
599
        if (data->type == adt7468 && val >= 11300) {    /* High freq. mode */
 
600
                data->cfg5 &= ~ADT7468_HFPWM;
 
601
                lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5);
 
602
        } else {                                        /* Low freq. mode */
 
603
                data->pwm_freq[nr] = FREQ_TO_REG(data->freq_map, val);
 
604
                lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
 
605
                                 (data->zone[nr].range << 4)
 
606
                                 | data->pwm_freq[nr]);
 
607
                if (data->type == adt7468) {
 
608
                        data->cfg5 |= ADT7468_HFPWM;
 
609
                        lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5);
 
610
                }
 
611
        }
586
612
        mutex_unlock(&data->update_lock);
587
613
        return count;
588
614
}
1156
1182
}
1157
1183
 
1158
1184
/* Return 0 if detection is successful, -ENODEV otherwise */
1159
 
static int lm85_detect(struct i2c_client *client, int kind,
1160
 
                       struct i2c_board_info *info)
 
1185
static int lm85_detect(struct i2c_client *client, struct i2c_board_info *info)
1161
1186
{
1162
1187
        struct i2c_adapter *adapter = client->adapter;
1163
1188
        int address = client->addr;
1164
1189
        const char *type_name;
 
1190
        int company, verstep;
1165
1191
 
1166
1192
        if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
1167
1193
                /* We need to be able to do byte I/O */
1168
1194
                return -ENODEV;
1169
1195
        }
1170
1196
 
1171
 
        /* If auto-detecting, determine the chip type */
1172
 
        if (kind < 0) {
1173
 
                int company = lm85_read_value(client, LM85_REG_COMPANY);
1174
 
                int verstep = lm85_read_value(client, LM85_REG_VERSTEP);
1175
 
 
1176
 
                dev_dbg(&adapter->dev, "Detecting device at 0x%02x with "
1177
 
                        "COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
1178
 
                        address, company, verstep);
1179
 
 
1180
 
                /* All supported chips have the version in common */
1181
 
                if ((verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC &&
1182
 
                    (verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC2) {
1183
 
                        dev_dbg(&adapter->dev, "Autodetection failed: "
1184
 
                                "unsupported version\n");
1185
 
                        return -ENODEV;
1186
 
                }
1187
 
                kind = any_chip;
1188
 
 
1189
 
                /* Now, refine the detection */
1190
 
                if (company == LM85_COMPANY_NATIONAL) {
1191
 
                        switch (verstep) {
1192
 
                        case LM85_VERSTEP_LM85C:
1193
 
                                kind = lm85c;
1194
 
                                break;
1195
 
                        case LM85_VERSTEP_LM85B:
1196
 
                                kind = lm85b;
1197
 
                                break;
1198
 
                        case LM85_VERSTEP_LM96000_1:
1199
 
                        case LM85_VERSTEP_LM96000_2:
1200
 
                                /* Check for Winbond WPCD377I */
1201
 
                                if (lm85_is_fake(client)) {
1202
 
                                        dev_dbg(&adapter->dev,
1203
 
                                                "Found Winbond WPCD377I, "
1204
 
                                                "ignoring\n");
1205
 
                                        return -ENODEV;
1206
 
                                }
1207
 
                                break;
1208
 
                        }
1209
 
                } else if (company == LM85_COMPANY_ANALOG_DEV) {
1210
 
                        switch (verstep) {
1211
 
                        case LM85_VERSTEP_ADM1027:
1212
 
                                kind = adm1027;
1213
 
                                break;
1214
 
                        case LM85_VERSTEP_ADT7463:
1215
 
                        case LM85_VERSTEP_ADT7463C:
1216
 
                                kind = adt7463;
1217
 
                                break;
1218
 
                        case LM85_VERSTEP_ADT7468_1:
1219
 
                        case LM85_VERSTEP_ADT7468_2:
1220
 
                                kind = adt7468;
1221
 
                                break;
1222
 
                        }
1223
 
                } else if (company == LM85_COMPANY_SMSC) {
1224
 
                        switch (verstep) {
1225
 
                        case LM85_VERSTEP_EMC6D100_A0:
1226
 
                        case LM85_VERSTEP_EMC6D100_A1:
1227
 
                                /* Note: we can't tell a '100 from a '101 */
1228
 
                                kind = emc6d100;
1229
 
                                break;
1230
 
                        case LM85_VERSTEP_EMC6D102:
1231
 
                                kind = emc6d102;
1232
 
                                break;
1233
 
                        }
1234
 
                } else {
1235
 
                        dev_dbg(&adapter->dev, "Autodetection failed: "
1236
 
                                "unknown vendor\n");
1237
 
                        return -ENODEV;
1238
 
                }
1239
 
        }
1240
 
 
1241
 
        switch (kind) {
1242
 
        case lm85b:
1243
 
                type_name = "lm85b";
1244
 
                break;
1245
 
        case lm85c:
1246
 
                type_name = "lm85c";
1247
 
                break;
1248
 
        case adm1027:
1249
 
                type_name = "adm1027";
1250
 
                break;
1251
 
        case adt7463:
1252
 
                type_name = "adt7463";
1253
 
                break;
1254
 
        case adt7468:
1255
 
                type_name = "adt7468";
1256
 
                break;
1257
 
        case emc6d100:
1258
 
                type_name = "emc6d100";
1259
 
                break;
1260
 
        case emc6d102:
1261
 
                type_name = "emc6d102";
1262
 
                break;
1263
 
        default:
1264
 
                type_name = "lm85";
1265
 
        }
 
1197
        /* Determine the chip type */
 
1198
        company = lm85_read_value(client, LM85_REG_COMPANY);
 
1199
        verstep = lm85_read_value(client, LM85_REG_VERSTEP);
 
1200
 
 
1201
        dev_dbg(&adapter->dev, "Detecting device at 0x%02x with "
 
1202
                "COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
 
1203
                address, company, verstep);
 
1204
 
 
1205
        /* All supported chips have the version in common */
 
1206
        if ((verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC &&
 
1207
            (verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC2) {
 
1208
                dev_dbg(&adapter->dev,
 
1209
                        "Autodetection failed: unsupported version\n");
 
1210
                return -ENODEV;
 
1211
        }
 
1212
        type_name = "lm85";
 
1213
 
 
1214
        /* Now, refine the detection */
 
1215
        if (company == LM85_COMPANY_NATIONAL) {
 
1216
                switch (verstep) {
 
1217
                case LM85_VERSTEP_LM85C:
 
1218
                        type_name = "lm85c";
 
1219
                        break;
 
1220
                case LM85_VERSTEP_LM85B:
 
1221
                        type_name = "lm85b";
 
1222
                        break;
 
1223
                case LM85_VERSTEP_LM96000_1:
 
1224
                case LM85_VERSTEP_LM96000_2:
 
1225
                        /* Check for Winbond WPCD377I */
 
1226
                        if (lm85_is_fake(client)) {
 
1227
                                dev_dbg(&adapter->dev,
 
1228
                                        "Found Winbond WPCD377I, ignoring\n");
 
1229
                                return -ENODEV;
 
1230
                        }
 
1231
                        break;
 
1232
                }
 
1233
        } else if (company == LM85_COMPANY_ANALOG_DEV) {
 
1234
                switch (verstep) {
 
1235
                case LM85_VERSTEP_ADM1027:
 
1236
                        type_name = "adm1027";
 
1237
                        break;
 
1238
                case LM85_VERSTEP_ADT7463:
 
1239
                case LM85_VERSTEP_ADT7463C:
 
1240
                        type_name = "adt7463";
 
1241
                        break;
 
1242
                case LM85_VERSTEP_ADT7468_1:
 
1243
                case LM85_VERSTEP_ADT7468_2:
 
1244
                        type_name = "adt7468";
 
1245
                        break;
 
1246
                }
 
1247
        } else if (company == LM85_COMPANY_SMSC) {
 
1248
                switch (verstep) {
 
1249
                case LM85_VERSTEP_EMC6D100_A0:
 
1250
                case LM85_VERSTEP_EMC6D100_A1:
 
1251
                        /* Note: we can't tell a '100 from a '101 */
 
1252
                        type_name = "emc6d100";
 
1253
                        break;
 
1254
                case LM85_VERSTEP_EMC6D102:
 
1255
                        type_name = "emc6d102";
 
1256
                        break;
 
1257
                case LM85_VERSTEP_EMC6D103_A0:
 
1258
                case LM85_VERSTEP_EMC6D103_A1:
 
1259
                        type_name = "emc6d103";
 
1260
                        break;
 
1261
                /*
 
1262
                 * Registers apparently missing in EMC6D103S/EMC6D103:A2
 
1263
                 * compared to EMC6D103:A0, EMC6D103:A1, and EMC6D102
 
1264
                 * (according to the data sheets), but used unconditionally
 
1265
                 * in the driver: 62[5:7], 6D[0:7], and 6E[0:7].
 
1266
                 * So skip EMC6D103S for now.
 
1267
                case LM85_VERSTEP_EMC6D103S:
 
1268
                        type_name = "emc6d103s";
 
1269
                        break;
 
1270
                 */
 
1271
                }
 
1272
        } else {
 
1273
                dev_dbg(&adapter->dev,
 
1274
                        "Autodetection failed: unknown vendor\n");
 
1275
                return -ENODEV;
 
1276
        }
 
1277
 
1266
1278
        strlcpy(info->type, type_name, I2C_NAME_SIZE);
1267
1279
 
1268
1280
        return 0;
1286
1298
        switch (data->type) {
1287
1299
        case adm1027:
1288
1300
        case adt7463:
 
1301
        case adt7468:
1289
1302
        case emc6d100:
1290
1303
        case emc6d102:
 
1304
        case emc6d103:
1291
1305
                data->freq_map = adm1027_freq_map;
1292
1306
                break;
1293
1307
        default:
1473
1487
                        /* More alarm bits */
1474
1488
                        data->alarms |= lm85_read_value(client,
1475
1489
                                                EMC6D100_REG_ALARM3) << 16;
1476
 
                } else if (data->type == emc6d102) {
 
1490
                } else if (data->type == emc6d102 || data->type == emc6d103) {
1477
1491
                        /* Have to read LSB bits after the MSB ones because
1478
1492
                           the reading of the MSB bits has frozen the
1479
1493
                           LSBs (backward from the ADM1027).