]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/hwmon/i5k_amb.c
hwmon: (adt7473) Initialize max_duty_at_overheat before use
[karo-tx-linux.git] / drivers / hwmon / i5k_amb.c
index 7fdbe810e8e20496c45cd578fe3902202155da6c..f9e2ed621f7b6b55d0595bf1c9bd2e79bfba634d 100644 (file)
 #define AMB_CONFIG_SIZE                        2048
 #define AMB_FUNC_3_OFFSET              768
 
-#define AMB_REG_TEMP_STATUS(amb)       ((amb) * AMB_CONFIG_SIZE + \
-                       AMB_FUNC_3_OFFSET + AMB_REG_TEMP_STATUS_ADDR)
-#define AMB_REG_TEMP_MIN(amb)          ((amb) * AMB_CONFIG_SIZE + \
-                       AMB_FUNC_3_OFFSET + AMB_REG_TEMP_MIN_ADDR)
-#define AMB_REG_TEMP_MID(amb)          ((amb) * AMB_CONFIG_SIZE + \
-                       AMB_FUNC_3_OFFSET + AMB_REG_TEMP_MID_ADDR)
-#define AMB_REG_TEMP_MAX(amb)          ((amb) * AMB_CONFIG_SIZE + \
-                       AMB_FUNC_3_OFFSET + AMB_REG_TEMP_MAX_ADDR)
-#define AMB_REG_TEMP(amb)              ((amb) * AMB_CONFIG_SIZE + \
-                       AMB_FUNC_3_OFFSET + AMB_REG_TEMP_ADDR)
+static unsigned long amb_reg_temp_status(unsigned int amb)
+{
+       return AMB_FUNC_3_OFFSET + AMB_REG_TEMP_STATUS_ADDR +
+              AMB_CONFIG_SIZE * amb;
+}
+
+static unsigned long amb_reg_temp_min(unsigned int amb)
+{
+       return AMB_FUNC_3_OFFSET + AMB_REG_TEMP_MIN_ADDR +
+              AMB_CONFIG_SIZE * amb;
+}
+
+static unsigned long amb_reg_temp_mid(unsigned int amb)
+{
+       return AMB_FUNC_3_OFFSET + AMB_REG_TEMP_MID_ADDR +
+              AMB_CONFIG_SIZE * amb;
+}
+
+static unsigned long amb_reg_temp_max(unsigned int amb)
+{
+       return AMB_FUNC_3_OFFSET + AMB_REG_TEMP_MAX_ADDR +
+              AMB_CONFIG_SIZE * amb;
+}
+
+static unsigned long amb_reg_temp(unsigned int amb)
+{
+       return AMB_FUNC_3_OFFSET + AMB_REG_TEMP_ADDR +
+              AMB_CONFIG_SIZE * amb;
+}
 
 #define MAX_MEM_CHANNELS               4
 #define MAX_AMBS_PER_CHANNEL           16
 #define REAL_MAX_AMBS_PER_CHANNEL      15
 #define KNOBS_PER_AMB                  5
 
-#define AMB_NUM_FROM_REG(byte_num, bit_num)    ((byte_num) * \
-                       MAX_AMBS_PER_CHANNEL) + (bit_num)
+static unsigned long amb_num_from_reg(unsigned int byte_num, unsigned int bit)
+{
+       return byte_num * MAX_AMBS_PER_CHANNEL + bit;
+}
 
 #define AMB_SYSFS_NAME_LEN             16
 struct i5k_device_attribute {
@@ -90,6 +111,7 @@ struct i5k_amb_data {
        void __iomem *amb_mmio;
        struct i5k_device_attribute *attrs;
        unsigned int num_attrs;
+       unsigned long chipset_id;
 };
 
 static ssize_t show_name(struct device *dev, struct device_attribute *devattr,
@@ -121,8 +143,8 @@ static ssize_t show_amb_alarm(struct device *dev,
        struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct i5k_amb_data *data = dev_get_drvdata(dev);
 
-       if (!(amb_read_byte(data, AMB_REG_TEMP_STATUS(attr->index)) & 0x20) &&
-            (amb_read_byte(data, AMB_REG_TEMP_STATUS(attr->index)) & 0x8))
+       if (!(amb_read_byte(data, amb_reg_temp_status(attr->index)) & 0x20) &&
+            (amb_read_byte(data, amb_reg_temp_status(attr->index)) & 0x8))
                return sprintf(buf, "1\n");
        else
                return sprintf(buf, "0\n");
@@ -140,7 +162,7 @@ static ssize_t store_amb_min(struct device *dev,
        if (temp > 255)
                temp = 255;
 
-       amb_write_byte(data, AMB_REG_TEMP_MIN(attr->index), temp);
+       amb_write_byte(data, amb_reg_temp_min(attr->index), temp);
        return count;
 }
 
@@ -156,7 +178,7 @@ static ssize_t store_amb_mid(struct device *dev,
        if (temp > 255)
                temp = 255;
 
-       amb_write_byte(data, AMB_REG_TEMP_MID(attr->index), temp);
+       amb_write_byte(data, amb_reg_temp_mid(attr->index), temp);
        return count;
 }
 
@@ -172,7 +194,7 @@ static ssize_t store_amb_max(struct device *dev,
        if (temp > 255)
                temp = 255;
 
-       amb_write_byte(data, AMB_REG_TEMP_MAX(attr->index), temp);
+       amb_write_byte(data, amb_reg_temp_max(attr->index), temp);
        return count;
 }
 
@@ -183,7 +205,7 @@ static ssize_t show_amb_min(struct device *dev,
        struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct i5k_amb_data *data = dev_get_drvdata(dev);
        return sprintf(buf, "%d\n",
-               500 * amb_read_byte(data, AMB_REG_TEMP_MIN(attr->index)));
+               500 * amb_read_byte(data, amb_reg_temp_min(attr->index)));
 }
 
 static ssize_t show_amb_mid(struct device *dev,
@@ -193,7 +215,7 @@ static ssize_t show_amb_mid(struct device *dev,
        struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct i5k_amb_data *data = dev_get_drvdata(dev);
        return sprintf(buf, "%d\n",
-               500 * amb_read_byte(data, AMB_REG_TEMP_MID(attr->index)));
+               500 * amb_read_byte(data, amb_reg_temp_mid(attr->index)));
 }
 
 static ssize_t show_amb_max(struct device *dev,
@@ -203,7 +225,7 @@ static ssize_t show_amb_max(struct device *dev,
        struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct i5k_amb_data *data = dev_get_drvdata(dev);
        return sprintf(buf, "%d\n",
-               500 * amb_read_byte(data, AMB_REG_TEMP_MAX(attr->index)));
+               500 * amb_read_byte(data, amb_reg_temp_max(attr->index)));
 }
 
 static ssize_t show_amb_temp(struct device *dev,
@@ -213,7 +235,7 @@ static ssize_t show_amb_temp(struct device *dev,
        struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct i5k_amb_data *data = dev_get_drvdata(dev);
        return sprintf(buf, "%d\n",
-               500 * amb_read_byte(data, AMB_REG_TEMP(attr->index)));
+               500 * amb_read_byte(data, amb_reg_temp(attr->index)));
 }
 
 static int __devinit i5k_amb_hwmon_init(struct platform_device *pdev)
@@ -241,7 +263,7 @@ static int __devinit i5k_amb_hwmon_init(struct platform_device *pdev)
                for (j = 0; j < REAL_MAX_AMBS_PER_CHANNEL; j++, c >>= 1) {
                        struct i5k_device_attribute *iattr;
 
-                       k = AMB_NUM_FROM_REG(i, j);
+                       k = amb_num_from_reg(i, j);
                        if (!(c & 0x1))
                                continue;
                        d++;
@@ -361,7 +383,8 @@ err:
        return res;
 }
 
-static int __devinit i5k_find_amb_registers(struct i5k_amb_data *data)
+static int __devinit i5k_find_amb_registers(struct i5k_amb_data *data,
+                                           unsigned long devid)
 {
        struct pci_dev *pcidev;
        u32 val32;
@@ -369,7 +392,7 @@ static int __devinit i5k_find_amb_registers(struct i5k_amb_data *data)
 
        /* Find AMB register memory space */
        pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
-                               PCI_DEVICE_ID_INTEL_5000_ERR,
+                               devid,
                                NULL);
        if (!pcidev)
                return -ENODEV;
@@ -388,6 +411,8 @@ static int __devinit i5k_find_amb_registers(struct i5k_amb_data *data)
                goto out;
        }
 
+       data->chipset_id = devid;
+
        res = 0;
 out:
        pci_dev_put(pcidev);
@@ -420,10 +445,30 @@ out:
        return res;
 }
 
+static unsigned long i5k_channel_pci_id(struct i5k_amb_data *data,
+                                       unsigned long channel)
+{
+       switch (data->chipset_id) {
+       case PCI_DEVICE_ID_INTEL_5000_ERR:
+               return PCI_DEVICE_ID_INTEL_5000_FBD0 + channel;
+       case PCI_DEVICE_ID_INTEL_5400_ERR:
+               return PCI_DEVICE_ID_INTEL_5400_FBD0 + channel;
+       default:
+               BUG();
+       }
+}
+
+static unsigned long chipset_ids[] = {
+       PCI_DEVICE_ID_INTEL_5000_ERR,
+       PCI_DEVICE_ID_INTEL_5400_ERR,
+       0
+};
+
 static int __devinit i5k_amb_probe(struct platform_device *pdev)
 {
        struct i5k_amb_data *data;
        struct resource *reso;
+       int i;
        int res = -ENODEV;
 
        data = kzalloc(sizeof(*data), GFP_KERNEL);
@@ -431,19 +476,24 @@ static int __devinit i5k_amb_probe(struct platform_device *pdev)
                return -ENOMEM;
 
        /* Figure out where the AMB registers live */
-       res = i5k_find_amb_registers(data);
+       i = 0;
+       do {
+               res = i5k_find_amb_registers(data, chipset_ids[i]);
+               i++;
+       } while (res && chipset_ids[i]);
+
        if (res)
                goto err;
 
        /* Copy the DIMM presence map for the first two channels */
        res = i5k_channel_probe(&data->amb_present[0],
-                               PCI_DEVICE_ID_INTEL_5000_FBD0);
+                               i5k_channel_pci_id(data, 0));
        if (res)
                goto err;
 
        /* Copy the DIMM presence map for the optional second two channels */
        i5k_channel_probe(&data->amb_present[2],
-                         PCI_DEVICE_ID_INTEL_5000_FBD1);
+                         i5k_channel_pci_id(data, 1));
 
        /* Set up resource regions */
        reso = request_mem_region(data->amb_base, data->amb_len, DRVNAME);