]> git.sur5r.net Git - groeck-nct6775/blobdiff - nct6775.c
Drop read/write lock
[groeck-nct6775] / nct6775.c
index 955c7fbdb1bc960481f74b86bf223b3cae581120..c15eb2752e42e65c91c1a27df022c254d8e49afc 100644 (file)
--- a/nct6775.c
+++ b/nct6775.c
@@ -243,14 +243,14 @@ static const u16 NCT6775_REG_FAN_PULSES[] = { 0x641, 0x642, 0x643, 0x644, 0 };
 static const u16 NCT6775_REG_TEMP[] = {
        0x27, 0x150, 0x250, 0x62b, 0x62c, 0x62d };
 
-static const u16 NCT6775_REG_TEMP_CONFIG[] = {
+static const u16 NCT6775_REG_TEMP_CONFIG[ARRAY_SIZE(NCT6775_REG_TEMP)] = {
        0, 0x152, 0x252, 0x628, 0x629, 0x62A };
-static const u16 NCT6775_REG_TEMP_HYST[] = {
+static const u16 NCT6775_REG_TEMP_HYST[ARRAY_SIZE(NCT6775_REG_TEMP)] = {
        0x3a, 0x153, 0x253, 0x673, 0x678, 0x67D };
-static const u16 NCT6775_REG_TEMP_OVER[] = {
+static const u16 NCT6775_REG_TEMP_OVER[ARRAY_SIZE(NCT6775_REG_TEMP)] = {
        0x39, 0x155, 0x255, 0x672, 0x677, 0x67C };
 
-static const u16 NCT6775_REG_TEMP_SOURCE[] = {
+static const u16 NCT6775_REG_TEMP_SOURCE[ARRAY_SIZE(NCT6775_REG_TEMP)] = {
        0x621, 0x622, 0x623, 0x624, 0x625, 0x626 };
 
 static const u16 NCT6775_REG_TEMP_SEL[] = {
@@ -338,7 +338,7 @@ static const u16 NCT6776_REG_FAN_PULSES[] = { 0x644, 0x645, 0x646, 0, 0 };
 static const u16 NCT6776_REG_WEIGHT_DUTY_BASE[] = {
        0x13e, 0x23e, 0x33e, 0x83e, 0x93e };
 
-static const u16 NCT6776_REG_TEMP_CONFIG[11] = {
+static const u16 NCT6776_REG_TEMP_CONFIG[ARRAY_SIZE(NCT6775_REG_TEMP)] = {
        0x18, 0x152, 0x252, 0x628, 0x629, 0x62A };
 
 static const char *const nct6776_temp_label[] = {
@@ -401,13 +401,16 @@ static const u16 NCT6779_REG_CRITICAL_PWM[] = {
        0x137, 0x237, 0x337, 0x837, 0x937 };
 
 static const u16 NCT6779_REG_TEMP[] = { 0x27, 0x150 };
-static const u16 NCT6779_REG_TEMP_HYST[] = { 0x3a, 0x153, 0, 0, 0, 0 };
-static const u16 NCT6779_REG_TEMP_OVER[] = { 0x39, 0x155, 0, 0, 0, 0 };
+static const u16 NCT6779_REG_TEMP_CONFIG[ARRAY_SIZE(NCT6779_REG_TEMP)] = {
+       0x18, 0x152 };
+static const u16 NCT6779_REG_TEMP_HYST[ARRAY_SIZE(NCT6779_REG_TEMP)] = {
+       0x3a, 0x153 };
+static const u16 NCT6779_REG_TEMP_OVER[ARRAY_SIZE(NCT6779_REG_TEMP)] = {
+       0x39, 0x155 };
+
 static const u16 NCT6779_REG_TEMP_OFFSET[] = {
        0x454, 0x455, 0x456, 0x44a, 0x44b, 0x44c };
 
-static const u16 NCT6779_REG_TEMP_CONFIG[11] = { 0x18, 0x152 };
-
 static const char *const nct6779_temp_label[] = {
        "",
        "SYSTIN",
@@ -473,7 +476,7 @@ static unsigned int step_time_from_reg(u8 reg, u8 mode)
 
 static u8 step_time_to_reg(unsigned int msec, u8 mode)
 {
-       return SENSORS_LIMIT((mode ? (msec + 200) / 400 :
+       return clamp_val((mode ? (msec + 200) / 400 :
                                        (msec + 50) / 100), 1, 255);
 }
 
@@ -539,8 +542,7 @@ static inline long in_from_reg(u8 reg, u8 nr)
 
 static inline u8 in_to_reg(u32 val, u8 nr)
 {
-       return SENSORS_LIMIT(DIV_ROUND_CLOSEST(val * 100, scale_in[nr]), 0,
-                            255);
+       return clamp_val(DIV_ROUND_CLOSEST(val * 100, scale_in[nr]), 0, 255);
 }
 
 /*
@@ -553,7 +555,6 @@ struct nct6775_data {
        const char *name;
 
        struct device *hwmon_dev;
-       struct mutex lock;
 
        u16 reg_temp[4][NUM_TEMP]; /* 0=temp, 1=temp_over, 2=temp_hyst,
                                    * 3=temp_crit
@@ -744,8 +745,6 @@ static u16 nct6775_read_value(struct nct6775_data *data, u16 reg)
 {
        int res, word_sized = is_word_sized(data, reg);
 
-       mutex_lock(&data->lock);
-
        nct6775_set_bank(data, reg);
        outb_p(reg & 0xff, data->addr + ADDR_REG_OFFSET);
        res = inb_p(data->addr + DATA_REG_OFFSET);
@@ -754,8 +753,6 @@ static u16 nct6775_read_value(struct nct6775_data *data, u16 reg)
                       data->addr + ADDR_REG_OFFSET);
                res = (res << 8) + inb_p(data->addr + DATA_REG_OFFSET);
        }
-
-       mutex_unlock(&data->lock);
        return res;
 }
 
@@ -763,8 +760,6 @@ static int nct6775_write_value(struct nct6775_data *data, u16 reg, u16 value)
 {
        int word_sized = is_word_sized(data, reg);
 
-       mutex_lock(&data->lock);
-
        nct6775_set_bank(data, reg);
        outb_p(reg & 0xff, data->addr + ADDR_REG_OFFSET);
        if (word_sized) {
@@ -773,8 +768,6 @@ static int nct6775_write_value(struct nct6775_data *data, u16 reg, u16 value)
                       data->addr + ADDR_REG_OFFSET);
        }
        outb_p(value & 0xff, data->addr + DATA_REG_OFFSET);
-
-       mutex_unlock(&data->lock);
        return 0;
 }
 
@@ -1695,7 +1688,7 @@ store_temp_offset(struct device *dev, struct device_attribute *attr,
        if (err < 0)
                return err;
 
-       val = SENSORS_LIMIT(DIV_ROUND_CLOSEST(val, 1000), -128, 127);
+       val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), -128, 127);
 
        mutex_lock(&data->update_lock);
        data->temp_offset[nr] = val;
@@ -1982,7 +1975,7 @@ store_pwm(struct device *dev, struct device_attribute *attr, const char *buf,
        err = kstrtoul(buf, 10, &val);
        if (err < 0)
                return err;
-       val = SENSORS_LIMIT(val, minval[index], maxval[index]);
+       val = clamp_val(val, minval[index], maxval[index]);
 
        mutex_lock(&data->update_lock);
        data->pwm[index][nr] = val;
@@ -2242,8 +2235,8 @@ store_target_temp(struct device *dev, struct device_attribute *attr,
        if (err < 0)
                return err;
 
-       val = SENSORS_LIMIT(DIV_ROUND_CLOSEST(val, 1000), 0,
-                           data->target_temp_mask);
+       val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 0,
+                       data->target_temp_mask);
 
        mutex_lock(&data->update_lock);
        data->target_temp[nr] = val;
@@ -2279,7 +2272,7 @@ store_target_speed(struct device *dev, struct device_attribute *attr,
        if (err < 0)
                return err;
 
-       val = SENSORS_LIMIT(val, 0, 1350000U);
+       val = clamp_val(val, 0, 1350000U);
        speed = fan_to_reg(val, data->fan_div[nr]);
 
        mutex_lock(&data->update_lock);
@@ -2317,8 +2310,7 @@ store_temp_tolerance(struct device *dev, struct device_attribute *attr,
                return err;
 
        /* Limit tolerance as needed */
-       val = SENSORS_LIMIT(DIV_ROUND_CLOSEST(val, 1000), 0,
-                           data->tolerance_mask);
+       val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 0, data->tolerance_mask);
 
        mutex_lock(&data->update_lock);
        data->temp_tolerance[index][nr] = val;
@@ -2389,7 +2381,7 @@ store_speed_tolerance(struct device *dev, struct device_attribute *attr,
               fan_to_reg(high, data->fan_div[nr])) / 2;
 
        /* Limit tolerance as needed */
-       val = SENSORS_LIMIT(val, 0, data->speed_tolerance_limit);
+       val = clamp_val(val, 0, data->speed_tolerance_limit);
 
        mutex_lock(&data->update_lock);
        data->target_speed_tolerance[nr] = val;
@@ -2498,7 +2490,7 @@ store_weight_temp(struct device *dev, struct device_attribute *attr,
        if (err < 0)
                return err;
 
-       val = SENSORS_LIMIT(DIV_ROUND_CLOSEST(val, 1000), 0, 255);
+       val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 0, 255);
 
        mutex_lock(&data->update_lock);
        data->weight_temp[index][nr] = val;
@@ -3401,6 +3393,8 @@ static int nct6775_probe(struct platform_device *pdev)
        const u16 *reg_temp, *reg_temp_over, *reg_temp_hyst, *reg_temp_config;
        const u16 *reg_temp_alternate, *reg_temp_crit;
        int num_reg_temp;
+       bool have_vid = false;
+       u8 cr2a;
 
        res = platform_get_resource(pdev, IORESOURCE_IO, 0);
        if (!devm_request_region(&pdev->dev, res->start, IOREGION_LENGTH,
@@ -3414,7 +3408,6 @@ static int nct6775_probe(struct platform_device *pdev)
 
        data->kind = sio_data->kind;
        data->addr = res->start;
-       mutex_init(&data->lock);
        mutex_init(&data->update_lock);
        data->name = nct6775_device_names[data->kind];
        data->bank = 0xff;              /* Force initial bank selection */
@@ -3769,17 +3762,31 @@ static int nct6775_probe(struct platform_device *pdev)
        /* Initialize the chip */
        nct6775_init_device(data);
 
-       data->vrm = vid_which_vrm();
        err = superio_enter(sio_data->sioreg);
        if (err)
                return err;
 
+       cr2a = superio_inb(sio_data->sioreg, 0x2a);
+       switch (data->kind) {
+       case nct6775:
+               have_vid = (cr2a & 0x40);
+               break;
+       case nct6776:
+               have_vid = (cr2a & 0x60) == 0x40;
+               break;
+       case nct6779:
+               break;
+       }
+
        /*
         * Read VID value
         * We can get the VID input values directly at logical device D 0xe3.
         */
-       superio_select(sio_data->sioreg, NCT6775_LD_VID);
-       data->vid = superio_inb(sio_data->sioreg, 0xe3);
+       if (have_vid) {
+               superio_select(sio_data->sioreg, NCT6775_LD_VID);
+               data->vid = superio_inb(sio_data->sioreg, 0xe3);
+               data->vrm = vid_which_vrm();
+       }
 
        if (fan_debounce) {
                u8 tmp;
@@ -3804,9 +3811,11 @@ static int nct6775_probe(struct platform_device *pdev)
 
        superio_exit(sio_data->sioreg);
 
-       err = device_create_file(dev, &dev_attr_cpu0_vid);
-       if (err)
-               return err;
+       if (have_vid) {
+               err = device_create_file(dev, &dev_attr_cpu0_vid);
+               if (err)
+                       return err;
+       }
 
        err = nct6775_check_fan_inputs(sio_data, data);
        if (err)