~ubuntu-branches/ubuntu/quantal/linux-linaro-mx51/quantal

« back to all changes in this revision

Viewing changes to drivers/hwmon/sch5627.c

  • Committer: Package Import Robot
  • Author(s): John Rigby, John Rigby
  • Date: 2011-09-26 10:44:23 UTC
  • Revision ID: package-import@ubuntu.com-20110926104423-3o58a3c1bj7x00rs
Tags: 3.0.0-1007.9
[ John Rigby ]

Enable crypto modules and remove crypto-modules from
exclude-module files
LP: #826021

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
#define SCH5627_COMPANY_ID              0x5c
53
53
#define SCH5627_PRIMARY_ID              0xa0
54
54
 
 
55
#define SCH5627_CMD_READ                0x02
 
56
#define SCH5627_CMD_WRITE               0x03
 
57
 
55
58
#define SCH5627_REG_BUILD_CODE          0x39
56
59
#define SCH5627_REG_BUILD_ID            0x3a
57
60
#define SCH5627_REG_HWMON_ID            0x3c
94
97
struct sch5627_data {
95
98
        unsigned short addr;
96
99
        struct device *hwmon_dev;
 
100
        u8 control;
97
101
        u8 temp_max[SCH5627_NO_TEMPS];
98
102
        u8 temp_crit[SCH5627_NO_TEMPS];
99
103
        u16 fan_min[SCH5627_NO_FANS];
100
104
 
101
105
        struct mutex update_lock;
 
106
        unsigned long last_battery;     /* In jiffies */
102
107
        char valid;                     /* !=0 if following fields are valid */
103
108
        unsigned long last_updated;     /* In jiffies */
104
109
        u16 temp[SCH5627_NO_TEMPS];
140
145
        release_region(base, 2);
141
146
}
142
147
 
143
 
static int sch5627_read_virtual_reg(struct sch5627_data *data, u16 reg)
 
148
static int sch5627_send_cmd(struct sch5627_data *data, u8 cmd, u16 reg, u8 v)
144
149
{
145
150
        u8 val;
146
151
        int i;
163
168
        outb(0x80, data->addr + 3);
164
169
 
165
170
        /* Write Request Packet Header */
166
 
        outb(0x02, data->addr + 4); /* Access Type: VREG read */
 
171
        outb(cmd, data->addr + 4); /* VREG Access Type read:0x02 write:0x03 */
167
172
        outb(0x01, data->addr + 5); /* # of Entries: 1 Byte (8-bit) */
168
173
        outb(0x04, data->addr + 2); /* Mailbox AP to first data entry loc. */
169
174
 
 
175
        /* Write Value field */
 
176
        if (cmd == SCH5627_CMD_WRITE)
 
177
                outb(v, data->addr + 4);
 
178
 
170
179
        /* Write Address field */
171
180
        outb(reg & 0xff, data->addr + 6);
172
181
        outb(reg >> 8, data->addr + 7);
224
233
         * But if we do that things don't work, so let's not.
225
234
         */
226
235
 
227
 
        /* Read Data from Mailbox */
228
 
        return inb(data->addr + 4);
 
236
        /* Read Value field */
 
237
        if (cmd == SCH5627_CMD_READ)
 
238
                return inb(data->addr + 4);
 
239
 
 
240
        return 0;
 
241
}
 
242
 
 
243
static int sch5627_read_virtual_reg(struct sch5627_data *data, u16 reg)
 
244
{
 
245
        return sch5627_send_cmd(data, SCH5627_CMD_READ, reg, 0);
 
246
}
 
247
 
 
248
static int sch5627_write_virtual_reg(struct sch5627_data *data,
 
249
                                     u16 reg, u8 val)
 
250
{
 
251
        return sch5627_send_cmd(data, SCH5627_CMD_WRITE, reg, val);
229
252
}
230
253
 
231
254
static int sch5627_read_virtual_reg16(struct sch5627_data *data, u16 reg)
272
295
 
273
296
        mutex_lock(&data->update_lock);
274
297
 
 
298
        /* Trigger a Vbat voltage measurement every 5 minutes */
 
299
        if (time_after(jiffies, data->last_battery + 300 * HZ)) {
 
300
                sch5627_write_virtual_reg(data, SCH5627_REG_CTRL,
 
301
                                          data->control | 0x10);
 
302
                data->last_battery = jiffies;
 
303
        }
 
304
 
275
305
        /* Cache the values for 1 second */
276
306
        if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
277
307
                for (i = 0; i < SCH5627_NO_TEMPS; i++) {
696
726
                err = val;
697
727
                goto error;
698
728
        }
699
 
        if (!(val & 0x01)) {
 
729
        data->control = val;
 
730
        if (!(data->control & 0x01)) {
700
731
                pr_err("hardware monitoring not enabled\n");
701
732
                err = -ENODEV;
702
733
                goto error;
703
734
        }
 
735
        /* Trigger a Vbat voltage measurement, so that we get a valid reading
 
736
           the first time we read Vbat */
 
737
        sch5627_write_virtual_reg(data, SCH5627_REG_CTRL,
 
738
                                  data->control | 0x10);
 
739
        data->last_battery = jiffies;
704
740
 
705
741
        /*
706
742
         * Read limits, we do this only once as reading a register on
851
887
}
852
888
 
853
889
MODULE_DESCRIPTION("SMSC SCH5627 Hardware Monitoring Driver");
854
 
MODULE_AUTHOR("Hans de Goede (hdegoede@redhat.com)");
 
890
MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
855
891
MODULE_LICENSE("GPL");
856
892
 
857
893
module_init(sch5627_init);