X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=nct6775.c;h=c15eb2752e42e65c91c1a27df022c254d8e49afc;hb=33a206276bf692be5081423ce5e7b4cc6bf0d7fd;hp=b47ec0bb8039c8ae5f4a07012c6e5175546b1cdf;hpb=bd0a8ec4f0a8daf0365062c79952afd0a13b3488;p=groeck-nct6775 diff --git a/nct6775.c b/nct6775.c index b47ec0b..c15eb27 100644 --- a/nct6775.c +++ b/nct6775.c @@ -56,6 +56,7 @@ #include #include #include "lm75.h" +#include "compat.h" #define USE_ALTERNATE @@ -242,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[] = { @@ -337,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[] = { @@ -400,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", @@ -472,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); } @@ -538,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); } /* @@ -552,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 @@ -743,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); @@ -753,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; } @@ -762,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) { @@ -772,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; } @@ -857,7 +851,7 @@ static void nct6775_init_fan_div(struct nct6775_data *data) nct6775_update_fan_div_common(data); /* * For all fans, start with highest divider value if the divider - * register is not innitialized. This ensures that we get a + * register is not initialized. This ensures that we get a * reading from the fan count register, even if it is not optimal. * We'll compute a better divider later on. */ @@ -889,7 +883,8 @@ static void nct6775_init_fan_common(struct device *dev, reg = nct6775_read_value(data, data->REG_FAN_MIN[i]); if (!reg) nct6775_write_value(data, data->REG_FAN_MIN[i], - 0xff); + data->has_fan_div ? 0xff + : 0xff1f); } } } @@ -1693,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; @@ -1980,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; @@ -2240,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; @@ -2277,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); @@ -2315,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; @@ -2387,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; @@ -2496,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; @@ -3399,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, @@ -3412,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 */ @@ -3767,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; @@ -3802,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)