Source
/*
* Windfarm PowerMac thermal control. SMU "satellite" controller sensors.
*
* Copyright (C) 2005 Paul Mackerras, IBM Corp. <paulus@samba.org>
*
* Released under the terms of the GNU GPL v2.
*/
/* If the cache is older than 800ms we'll refetch it */
struct wf_sat {
struct kref ref;
int nr;
struct mutex mutex;
unsigned long last_read; /* jiffies when cache last updated */
u8 cache[16];
struct list_head sensors;
struct i2c_client *i2c;
struct device_node *node;
};
static struct wf_sat *sats[2];
struct wf_sat_sensor {
struct list_head link;
int index;
int index2; /* used for power sensors */
int shift;
struct wf_sat *sat;
struct wf_sensor sens;
};
struct smu_sdbp_header *smu_sat_get_sdb_partition(unsigned int sat_id, int id,
unsigned int *size)
{
struct wf_sat *sat;
int err;
unsigned int i, len;
u8 *buf;
u8 data[4];
/* TODO: Add the resulting partition to the device-tree */
if (sat_id > 1 || (sat = sats[sat_id]) == NULL)
return NULL;
err = i2c_smbus_write_word_data(sat->i2c, 8, id << 8);
if (err) {
printk(KERN_ERR "smu_sat_get_sdb_part wr error %d\n", err);
return NULL;
}
err = i2c_smbus_read_word_data(sat->i2c, 9);
if (err < 0) {
printk(KERN_ERR "smu_sat_get_sdb_part rd len error\n");
return NULL;
}
len = err;
if (len == 0) {
printk(KERN_ERR "smu_sat_get_sdb_part no partition %x\n", id);
return NULL;
}
len = le16_to_cpu(len);
len = (len + 3) & ~3;
buf = kmalloc(len, GFP_KERNEL);
if (buf == NULL)
return NULL;
for (i = 0; i < len; i += 4) {
err = i2c_smbus_read_i2c_block_data(sat->i2c, 0xa, 4, data);
if (err < 0) {
printk(KERN_ERR "smu_sat_get_sdb_part rd err %d\n",