Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cc66b303 authored by Guenter Roeck's avatar Guenter Roeck
Browse files

hwmon: (nct6775) Rework temperature source and label handling



Instead of checking if a temperature source has a label, use a bit mask
to determine if a temperature source is valid for a given chip.
This simplifies the code and, if necessary, lets us support chips with
unknown or incomplete labels.

Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent d1bb2186
Loading
Loading
Loading
Loading
+65 −31
Original line number Original line Diff line number Diff line
@@ -361,12 +361,24 @@ static const char *const nct6775_temp_label[] = {
	"PCH_DIM3_TEMP"
	"PCH_DIM3_TEMP"
};
};


static const u16 NCT6775_REG_TEMP_ALTERNATE[ARRAY_SIZE(nct6775_temp_label) - 1]
#define NCT6775_TEMP_MASK	0x001ffffe
	= { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x661, 0x662, 0x664 };


static const u16 NCT6775_REG_TEMP_CRIT[ARRAY_SIZE(nct6775_temp_label) - 1]
static const u16 NCT6775_REG_TEMP_ALTERNATE[32] = {
	= { 0, 0, 0, 0, 0xa00, 0xa01, 0xa02, 0xa03, 0xa04, 0xa05, 0xa06,
	[13] = 0x661,
	    0xa07 };
	[14] = 0x662,
	[15] = 0x664,
};

static const u16 NCT6775_REG_TEMP_CRIT[32] = {
	[4] = 0xa00,
	[5] = 0xa01,
	[6] = 0xa02,
	[7] = 0xa03,
	[8] = 0xa04,
	[9] = 0xa05,
	[10] = 0xa06,
	[11] = 0xa07
};


/* NCT6776 specific data */
/* NCT6776 specific data */


@@ -435,11 +447,18 @@ static const char *const nct6776_temp_label[] = {
	"BYTE_TEMP"
	"BYTE_TEMP"
};
};


static const u16 NCT6776_REG_TEMP_ALTERNATE[ARRAY_SIZE(nct6776_temp_label) - 1]
#define NCT6776_TEMP_MASK	0x007ffffe
	= { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x401, 0x402, 0x404 };


static const u16 NCT6776_REG_TEMP_CRIT[ARRAY_SIZE(nct6776_temp_label) - 1]
static const u16 NCT6776_REG_TEMP_ALTERNATE[32] = {
	= { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x709, 0x70a };
	[14] = 0x401,
	[15] = 0x402,
	[16] = 0x404,
};

static const u16 NCT6776_REG_TEMP_CRIT[32] = {
	[11] = 0x709,
	[12] = 0x70a,
};


/* NCT6779 specific data */
/* NCT6779 specific data */


@@ -526,17 +545,19 @@ static const char *const nct6779_temp_label[] = {
	"Virtual_TEMP"
	"Virtual_TEMP"
};
};


#define NCT6779_NUM_LABELS	(ARRAY_SIZE(nct6779_temp_label) - 5)
#define NCT6779_TEMP_MASK	0x07ffff7e
#define NCT6791_NUM_LABELS	ARRAY_SIZE(nct6779_temp_label)
#define NCT6791_TEMP_MASK	0x87ffff7e


static const u16 NCT6779_REG_TEMP_ALTERNATE[NCT6791_NUM_LABELS - 1]
static const u16 NCT6779_REG_TEMP_ALTERNATE[32]
	= { 0x490, 0x491, 0x492, 0x493, 0x494, 0x495, 0, 0,
	= { 0x490, 0x491, 0x492, 0x493, 0x494, 0x495, 0, 0,
	    0, 0, 0, 0, 0, 0, 0, 0,
	    0, 0, 0, 0, 0, 0, 0, 0,
	    0, 0x400, 0x401, 0x402, 0x404, 0x405, 0x406, 0x407,
	    0, 0x400, 0x401, 0x402, 0x404, 0x405, 0x406, 0x407,
	    0x408, 0 };
	    0x408, 0 };


static const u16 NCT6779_REG_TEMP_CRIT[NCT6791_NUM_LABELS - 1]
static const u16 NCT6779_REG_TEMP_CRIT[32] = {
	= { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x709, 0x70a };
	[15] = 0x709,
	[16] = 0x70a,
};


/* NCT6791 specific data */
/* NCT6791 specific data */


@@ -603,6 +624,8 @@ static const char *const nct6792_temp_label[] = {
	"Virtual_TEMP"
	"Virtual_TEMP"
};
};


#define NCT6792_TEMP_MASK	0x9fffff7e

static const char *const nct6793_temp_label[] = {
static const char *const nct6793_temp_label[] = {
	"",
	"",
	"SYSTIN",
	"SYSTIN",
@@ -638,6 +661,8 @@ static const char *const nct6793_temp_label[] = {
	"Virtual_TEMP"
	"Virtual_TEMP"
};
};


#define NCT6793_TEMP_MASK	0xbfff037e

/* NCT6102D/NCT6106D specific data */
/* NCT6102D/NCT6106D specific data */


#define NCT6106_REG_VBAT	0x318
#define NCT6106_REG_VBAT	0x318
@@ -732,11 +757,16 @@ static const s8 NCT6106_BEEP_BITS[] = {
	34, -1				/* intrusion0, intrusion1 */
	34, -1				/* intrusion0, intrusion1 */
};
};


static const u16 NCT6106_REG_TEMP_ALTERNATE[ARRAY_SIZE(nct6776_temp_label) - 1]
static const u16 NCT6106_REG_TEMP_ALTERNATE[32] = {
	= { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x51, 0x52, 0x54 };
	[14] = 0x51,
	[15] = 0x52,
	[16] = 0x54,
};


static const u16 NCT6106_REG_TEMP_CRIT[ARRAY_SIZE(nct6776_temp_label) - 1]
static const u16 NCT6106_REG_TEMP_CRIT[32] = {
	= { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x204, 0x205 };
	[11] = 0x204,
	[12] = 0x205,
};


static enum pwm_enable reg_to_pwm_enable(int pwm, int mode)
static enum pwm_enable reg_to_pwm_enable(int pwm, int mode)
{
{
@@ -851,7 +881,7 @@ struct nct6775_data {
	u8 temp_src[NUM_TEMP];
	u8 temp_src[NUM_TEMP];
	u16 reg_temp_config[NUM_TEMP];
	u16 reg_temp_config[NUM_TEMP];
	const char * const *temp_label;
	const char * const *temp_label;
	int temp_label_num;
	u32 temp_mask;


	u16 REG_CONFIG;
	u16 REG_CONFIG;
	u16 REG_VBAT;
	u16 REG_VBAT;
@@ -2197,6 +2227,9 @@ static umode_t nct6775_temp_is_visible(struct kobject *kobj,
	if (!(data->have_temp & BIT(temp)))
	if (!(data->have_temp & BIT(temp)))
		return 0;
		return 0;


	if (nr == 1 && !data->temp_label)
		return 0;

	if (nr == 2 && find_temp_source(data, temp, data->num_temp_alarms) < 0)
	if (nr == 2 && find_temp_source(data, temp, data->num_temp_alarms) < 0)
		return 0;				/* alarm */
		return 0;				/* alarm */


@@ -3406,8 +3439,7 @@ static void add_temp_sensors(struct nct6775_data *data, const u16 *regp,
		src &= 0x1f;
		src &= 0x1f;
		if (!src || (*mask & BIT(src)))
		if (!src || (*mask & BIT(src)))
			continue;
			continue;
		if (src >= data->temp_label_num ||
		if (!(data->temp_mask & BIT(src)))
		    !strlen(data->temp_label[src]))
			continue;
			continue;


		index = __ffs(*available);
		index = __ffs(*available);
@@ -3465,7 +3497,7 @@ static int nct6775_probe(struct platform_device *pdev)
		data->fan_from_reg_min = fan_from_reg13;
		data->fan_from_reg_min = fan_from_reg13;


		data->temp_label = nct6776_temp_label;
		data->temp_label = nct6776_temp_label;
		data->temp_label_num = ARRAY_SIZE(nct6776_temp_label);
		data->temp_mask = NCT6776_TEMP_MASK;


		data->REG_VBAT = NCT6106_REG_VBAT;
		data->REG_VBAT = NCT6106_REG_VBAT;
		data->REG_DIODE = NCT6106_REG_DIODE;
		data->REG_DIODE = NCT6106_REG_DIODE;
@@ -3543,7 +3575,7 @@ static int nct6775_probe(struct platform_device *pdev)
		data->speed_tolerance_limit = 15;
		data->speed_tolerance_limit = 15;


		data->temp_label = nct6775_temp_label;
		data->temp_label = nct6775_temp_label;
		data->temp_label_num = ARRAY_SIZE(nct6775_temp_label);
		data->temp_mask = NCT6775_TEMP_MASK;


		data->REG_CONFIG = NCT6775_REG_CONFIG;
		data->REG_CONFIG = NCT6775_REG_CONFIG;
		data->REG_VBAT = NCT6775_REG_VBAT;
		data->REG_VBAT = NCT6775_REG_VBAT;
@@ -3615,7 +3647,7 @@ static int nct6775_probe(struct platform_device *pdev)
		data->speed_tolerance_limit = 63;
		data->speed_tolerance_limit = 63;


		data->temp_label = nct6776_temp_label;
		data->temp_label = nct6776_temp_label;
		data->temp_label_num = ARRAY_SIZE(nct6776_temp_label);
		data->temp_mask = NCT6776_TEMP_MASK;


		data->REG_CONFIG = NCT6775_REG_CONFIG;
		data->REG_CONFIG = NCT6775_REG_CONFIG;
		data->REG_VBAT = NCT6775_REG_VBAT;
		data->REG_VBAT = NCT6775_REG_VBAT;
@@ -3687,7 +3719,7 @@ static int nct6775_probe(struct platform_device *pdev)
		data->speed_tolerance_limit = 63;
		data->speed_tolerance_limit = 63;


		data->temp_label = nct6779_temp_label;
		data->temp_label = nct6779_temp_label;
		data->temp_label_num = NCT6779_NUM_LABELS;
		data->temp_mask = NCT6779_TEMP_MASK;


		data->REG_CONFIG = NCT6775_REG_CONFIG;
		data->REG_CONFIG = NCT6775_REG_CONFIG;
		data->REG_VBAT = NCT6775_REG_VBAT;
		data->REG_VBAT = NCT6775_REG_VBAT;
@@ -3768,15 +3800,17 @@ static int nct6775_probe(struct platform_device *pdev)
		default:
		default:
		case nct6791:
		case nct6791:
			data->temp_label = nct6779_temp_label;
			data->temp_label = nct6779_temp_label;
			data->temp_mask = NCT6791_TEMP_MASK;
			break;
			break;
		case nct6792:
		case nct6792:
			data->temp_label = nct6792_temp_label;
			data->temp_label = nct6792_temp_label;
			data->temp_mask = NCT6792_TEMP_MASK;
			break;
			break;
		case nct6793:
		case nct6793:
			data->temp_label = nct6793_temp_label;
			data->temp_label = nct6793_temp_label;
			data->temp_mask = NCT6793_TEMP_MASK;
			break;
			break;
		}
		}
		data->temp_label_num = NCT6791_NUM_LABELS;


		data->REG_CONFIG = NCT6775_REG_CONFIG;
		data->REG_CONFIG = NCT6775_REG_CONFIG;
		data->REG_VBAT = NCT6775_REG_VBAT;
		data->REG_VBAT = NCT6775_REG_VBAT;
@@ -3885,8 +3919,7 @@ static int nct6775_probe(struct platform_device *pdev)
		if (!src || (mask & BIT(src)))
		if (!src || (mask & BIT(src)))
			continue;
			continue;


		if (src >= data->temp_label_num ||
		if (!(data->temp_mask & BIT(src))) {
		    !strlen(data->temp_label[src])) {
			dev_info(dev,
			dev_info(dev,
				 "Invalid temperature source %d at index %d, source register 0x%x, temp register 0x%x\n",
				 "Invalid temperature source %d at index %d, source register 0x%x, temp register 0x%x\n",
				 src, i, data->REG_TEMP_SOURCE[i], reg_temp[i]);
				 src, i, data->REG_TEMP_SOURCE[i], reg_temp[i]);
@@ -3946,8 +3979,7 @@ static int nct6775_probe(struct platform_device *pdev)
		if (!src)
		if (!src)
			continue;
			continue;


		if (src >= data->temp_label_num ||
		if (!(data->temp_mask & BIT(src))) {
		    !strlen(data->temp_label[src])) {
			dev_info(dev,
			dev_info(dev,
				 "Invalid temperature source %d at index %d, source register 0x%x, temp register 0x%x\n",
				 "Invalid temperature source %d at index %d, source register 0x%x, temp register 0x%x\n",
				 src, i, data->REG_TEMP_SEL[i],
				 src, i, data->REG_TEMP_SEL[i],
@@ -3994,7 +4026,9 @@ static int nct6775_probe(struct platform_device *pdev)
	 * The temperature is already monitored if the respective bit in <mask>
	 * The temperature is already monitored if the respective bit in <mask>
	 * is set.
	 * is set.
	 */
	 */
	for (i = 0; i < data->temp_label_num - 1; i++) {
	for (i = 0; i < 32; i++) {
		if (!(data->temp_mask & BIT(i + 1)))
			continue;
		if (!reg_temp_alternate[i])
		if (!reg_temp_alternate[i])
			continue;
			continue;
		if (mask & BIT(i + 1))
		if (mask & BIT(i + 1))