Lines Matching +full:- +full:75 +full:mv
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * lm93.c - Part of lm_sensors, Linux kernel modules for hardware monitoring
13 * Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de>
16 * Copyright (c) 2003-2004 Jean Delvare <jdelvare@suse.de>
33 #include <linux/hwmon-sysfs.h>
34 #include <linux/hwmon-vid.h>
51 /* voltage inputs: in1-in16 (nr => 0-15) */
56 /* temperature inputs: temp1-temp4 (nr => 0-3) */
61 /* temp[1-4]_auto_boost (nr => 0-3) */
64 /* #PROCHOT inputs: prochot1-prochot2 (nr => 0-1) */
69 /* fan tach inputs: fan1-fan4 (nr => 0-3) */
73 /* pwm outputs: pwm1-pwm2 (nr => 0-1, reg => 0-3) */
83 /* vid inputs: vid1-vid2 (nr => 0-1) */
86 /* vccp1 & vccp2: VID relative inputs (nr => 0-1) */
89 /* temp[1-4]_auto_boost_hyst */
94 /* temp[1-4]_auto_pwm_[min|hyst] */
103 /* temp[1-4]_auto_base (nr => 0-3) */
106 /* temp[1-4]_auto_offsets (step => 0-11) */
145 "Set to non-zero to disable SMBus block data transactions.");
149 MODULE_PARM_DESC(init, "Set to non-zero to force chip initialization.");
194 * Client-specific data
211 * temp1 - temp4: unfiltered readings
212 * temp1 - temp2: filtered readings
216 /* vin1 - vin16: readings */
219 /* prochot1 - prochot2: readings */
225 /* fan counts 1-4 => 14-bits, LE, *left* justified */
234 /* vin1 - vin16: low and high limits */
240 /* fan count limits 1-4 => same format as block5 */
255 /* VID1 & VID2 => register format, 6-bits, right justified */
258 /* prochot1 - prochot2: limits */
293 * save the user-commanded value here.
299 * VID: mV
300 * REG: 6-bits, right justified, *always* using Intel VRM/VRD 10
324 /* min, max, and nominal voltage readings, per channel (mV)*/
347 const long slope = (uv_max - uv_min) / in LM93_IN_FROM_REG()
348 (lm93_vin_reg_max[nr] - lm93_vin_reg_min[nr]); in LM93_IN_FROM_REG()
349 const long intercept = uv_min - slope * lm93_vin_reg_min[nr]; in LM93_IN_FROM_REG()
355 * IN: mV, limits determined by channel nr
361 const long mv = clamp_val(val, in LM93_IN_TO_REG() local
365 const long uv = mv * 1000; in LM93_IN_TO_REG()
370 const long slope = (uv_max - uv_min) / in LM93_IN_TO_REG()
371 (lm93_vin_reg_max[nr] - lm93_vin_reg_min[nr]); in LM93_IN_TO_REG()
372 const long intercept = uv_min - slope * lm93_vin_reg_min[nr]; in LM93_IN_TO_REG()
374 u8 result = ((uv - intercept + (slope/2)) / slope); in LM93_IN_TO_REG()
380 /* vid in mV, upper == 0 indicates low limit, otherwise upper limit */
384 (((reg >> 0 & 0x0f) + 1) * -25000); in LM93_IN_REL_FROM_REG()
393 * vid in mV , upper == 0 indicates low limit, otherwise upper limit
399 long uv_offset = vid * 1000 - val * 10000; in LM93_IN_REL_TO_REG()
402 return (u8)((uv_offset / 12500 - 1) << 4); in LM93_IN_REL_TO_REG()
404 uv_offset = clamp_val(uv_offset, -400000, -25000); in LM93_IN_REL_TO_REG()
405 return (u8)((uv_offset / -25000 - 1) << 0); in LM93_IN_REL_TO_REG()
410 * TEMP: 1/1000 degrees C (-128C to +127C)
418 #define LM93_TEMP_MIN (-128000)
422 * TEMP: 1/1000 degrees C (-128C to +127C)
428 ntemp += (ntemp < 0 ? -500 : 500); in LM93_TEMP_TO_REG()
432 /* Determine 4-bit temperature offset resolution */
440 * This function is common to all 4-bit temperature offsets
451 #define LM93_TEMP_OFFSET_MAX1 (75)
454 * This function is common to all 4-bit temperature offsets
470 /* temp1-temp2 (nr=0,1) use lower nibble */ in LM93_TEMP_AUTO_OFFSET_FROM_REG()
474 /* temp3-temp4 (nr=2,3) use upper nibble */ in LM93_TEMP_AUTO_OFFSET_FROM_REG()
480 * TEMP: 1/10 degrees C (0C to +15C (mode 0) or +7.5C (mode non-zero))
481 * REG: 1.0C/bit (mode 0) or 0.5C/bit (mode non-zero)
488 /* temp1-temp2 (nr=0,1) use lower nibble */ in LM93_TEMP_AUTO_OFFSET_TO_REG()
492 /* temp3-temp4 (nr=2,3) use upper nibble */ in LM93_TEMP_AUTO_OFFSET_TO_REG()
504 reg = data->boost_hyst[0] & 0x0f; in LM93_AUTO_BOOST_HYST_FROM_REGS()
507 reg = data->boost_hyst[0] >> 4 & 0x0f; in LM93_AUTO_BOOST_HYST_FROM_REGS()
510 reg = data->boost_hyst[1] & 0x0f; in LM93_AUTO_BOOST_HYST_FROM_REGS()
514 reg = data->boost_hyst[1] >> 4 & 0x0f; in LM93_AUTO_BOOST_HYST_FROM_REGS()
518 return LM93_TEMP_FROM_REG(data->boost[nr]) - in LM93_AUTO_BOOST_HYST_FROM_REGS()
526 (LM93_TEMP_FROM_REG(data->boost[nr]) - hyst), mode); in LM93_AUTO_BOOST_HYST_TO_REG()
530 reg = (data->boost_hyst[0] & 0xf0) | (reg & 0x0f); in LM93_AUTO_BOOST_HYST_TO_REG()
533 reg = (reg << 4 & 0xf0) | (data->boost_hyst[0] & 0x0f); in LM93_AUTO_BOOST_HYST_TO_REG()
536 reg = (data->boost_hyst[1] & 0xf0) | (reg & 0x0f); in LM93_AUTO_BOOST_HYST_TO_REG()
540 reg = (reg << 4 & 0xf0) | (data->boost_hyst[1] & 0x0f); in LM93_AUTO_BOOST_HYST_TO_REG()
548 * PWM: 0-255 per sensors documentation
549 * REG: 0-13 as mapped below... right justified
596 return count == 0 ? -1 : count == 0x3fff ? 0 : 1350000 / count; in LM93_FAN_FROM_REG()
601 * REG: 14-bits, LE, *left* justified
620 * REG: 0-7 as mapped below
635 for (i = 7; i > 0; i--) in LM93_PWM_FREQ_TO_REG()
645 * REG: 0-7 as mapped below
669 #define LM93_RAMP_MAX 75
678 * REG: 50mS/bit 4-bits right justified
687 * PROCHOT: 0-255, 0 => 0%, 255 => > 96.6%
697 * PROCHOT-INTERVAL: 73 - 37200 (1/100 seconds)
698 * REG: 0-9 as mapped below
722 * GPIO: 0-255, GPIO0 is LSB
808 dev_warn(&client->dev, in lm93_read_byte()
817 dev_err(&client->dev, "lm93: All read byte retries failed!!\n"); in lm93_read_byte()
829 dev_warn(&client->dev, in lm93_write_byte()
846 dev_warn(&client->dev, in lm93_read_word()
855 dev_err(&client->dev, "lm93: All read word retries failed!!\n"); in lm93_read_word()
867 dev_warn(&client->dev, in lm93_write_word()
879 * (Fixed Block Number - section 14.5.2 of LM93 datasheet)
892 dev_warn(&client->dev, in lm93_read_block()
910 struct i2c_client *client = data->client; in lm93_update_device()
913 mutex_lock(&data->update_lock); in lm93_update_device()
915 if (time_after(jiffies, data->last_updated + interval) || in lm93_update_device()
916 !data->valid) { in lm93_update_device()
918 data->update(data, client); in lm93_update_device()
919 data->last_updated = jiffies; in lm93_update_device()
920 data->valid = true; in lm93_update_device()
923 mutex_unlock(&data->update_lock); in lm93_update_device()
934 /* temp1 - temp4: limits */ in lm93_update_client_common()
936 data->temp_lim[i].min = in lm93_update_client_common()
938 data->temp_lim[i].max = in lm93_update_client_common()
943 data->config = lm93_read_byte(client, LM93_REG_CONFIG); in lm93_update_client_common()
945 /* vid1 - vid2: values */ in lm93_update_client_common()
947 data->vid[i] = lm93_read_byte(client, LM93_REG_VID(i)); in lm93_update_client_common()
949 /* prochot1 - prochot2: limits */ in lm93_update_client_common()
951 data->prochot_max[i] = lm93_read_byte(client, in lm93_update_client_common()
954 /* vccp1 - vccp2: VID relative limits */ in lm93_update_client_common()
956 data->vccp_limits[i] = lm93_read_byte(client, in lm93_update_client_common()
960 data->gpi = lm93_read_byte(client, LM93_REG_GPI); in lm93_update_client_common()
963 data->prochot_override = lm93_read_byte(client, in lm93_update_client_common()
967 data->prochot_interval = lm93_read_byte(client, in lm93_update_client_common()
972 data->boost[i] = lm93_read_byte(client, LM93_REG_BOOST(i)); in lm93_update_client_common()
975 data->boost_hyst[0] = lm93_read_byte(client, LM93_REG_BOOST_HYST_12); in lm93_update_client_common()
976 data->boost_hyst[1] = lm93_read_byte(client, LM93_REG_BOOST_HYST_34); in lm93_update_client_common()
979 data->auto_pwm_min_hyst[0] = in lm93_update_client_common()
981 data->auto_pwm_min_hyst[1] = in lm93_update_client_common()
985 data->pwm_ramp_ctl = lm93_read_byte(client, LM93_REG_PWM_RAMP_CTL); in lm93_update_client_common()
988 data->sfc1 = lm93_read_byte(client, LM93_REG_SFC1); in lm93_update_client_common()
989 data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); in lm93_update_client_common()
990 data->sf_tach_to_pwm = lm93_read_byte(client, in lm93_update_client_common()
994 for (i = 0, ptr = (u8 *)(&data->block1); i < 8; i++) in lm93_update_client_common()
1002 dev_dbg(&client->dev, "starting device update (block data enabled)\n"); in lm93_update_client_full()
1004 /* in1 - in16: values & limits */ in lm93_update_client_full()
1005 lm93_read_block(client, 3, (u8 *)(data->block3)); in lm93_update_client_full()
1006 lm93_read_block(client, 7, (u8 *)(data->block7)); in lm93_update_client_full()
1008 /* temp1 - temp4: values */ in lm93_update_client_full()
1009 lm93_read_block(client, 2, (u8 *)(data->block2)); in lm93_update_client_full()
1011 /* prochot1 - prochot2: values */ in lm93_update_client_full()
1012 lm93_read_block(client, 4, (u8 *)(data->block4)); in lm93_update_client_full()
1014 /* fan1 - fan4: values & limits */ in lm93_update_client_full()
1015 lm93_read_block(client, 5, (u8 *)(data->block5)); in lm93_update_client_full()
1016 lm93_read_block(client, 8, (u8 *)(data->block8)); in lm93_update_client_full()
1019 lm93_read_block(client, 9, (u8 *)(data->block9)); in lm93_update_client_full()
1022 lm93_read_block(client, 1, (u8 *)(&data->block1)); in lm93_update_client_full()
1025 lm93_read_block(client, 10, (u8 *)(&data->block10)); in lm93_update_client_full()
1037 dev_dbg(&client->dev, "starting device update (block data disabled)\n"); in lm93_update_client_min()
1039 /* in1 - in16: values & limits */ in lm93_update_client_min()
1041 data->block3[i] = in lm93_update_client_min()
1043 data->block7[i].min = in lm93_update_client_min()
1045 data->block7[i].max = in lm93_update_client_min()
1049 /* temp1 - temp4: values */ in lm93_update_client_min()
1051 data->block2[i] = in lm93_update_client_min()
1055 /* prochot1 - prochot2: values */ in lm93_update_client_min()
1057 data->block4[i].cur = in lm93_update_client_min()
1059 data->block4[i].avg = in lm93_update_client_min()
1063 /* fan1 - fan4: values & limits */ in lm93_update_client_min()
1065 data->block5[i] = in lm93_update_client_min()
1067 data->block8[i] = in lm93_update_client_min()
1074 data->block9[i][j] = in lm93_update_client_min()
1080 for (i = 0, ptr = (u8 *)(&data->block1); i < 8; i++) { in lm93_update_client_min()
1087 data->block10.base[i] = in lm93_update_client_min()
1093 data->block10.offset[i] = in lm93_update_client_min()
1104 int nr = (to_sensor_dev_attr(attr))->index; in in_show()
1107 return sprintf(buf, "%d\n", LM93_IN_FROM_REG(nr, data->block3[nr])); in in_show()
1130 int nr = (to_sensor_dev_attr(attr))->index; in in_min_show()
1132 int vccp = nr - 6; in in_min_show()
1136 vid = LM93_VID_FROM_REG(data->vid[vccp]); in in_min_show()
1137 rc = LM93_IN_MIN_FROM_REG(data->vccp_limits[vccp], vid); in in_min_show()
1139 rc = LM93_IN_FROM_REG(nr, data->block7[nr].min); in in_min_show()
1147 int nr = (to_sensor_dev_attr(attr))->index; in in_min_store()
1149 struct i2c_client *client = data->client; in in_min_store()
1150 int vccp = nr - 6; in in_min_store()
1159 mutex_lock(&data->update_lock); in in_min_store()
1161 vid = LM93_VID_FROM_REG(data->vid[vccp]); in in_min_store()
1162 data->vccp_limits[vccp] = (data->vccp_limits[vccp] & 0xf0) | in in_min_store()
1165 data->vccp_limits[vccp]); in in_min_store()
1167 data->block7[nr].min = LM93_IN_TO_REG(nr, val); in in_min_store()
1169 data->block7[nr].min); in in_min_store()
1171 mutex_unlock(&data->update_lock); in in_min_store()
1195 int nr = (to_sensor_dev_attr(attr))->index; in in_max_show()
1197 int vccp = nr - 6; in in_max_show()
1201 vid = LM93_VID_FROM_REG(data->vid[vccp]); in in_max_show()
1202 rc = LM93_IN_MAX_FROM_REG(data->vccp_limits[vccp], vid); in in_max_show()
1204 rc = LM93_IN_FROM_REG(nr, data->block7[nr].max); in in_max_show()
1212 int nr = (to_sensor_dev_attr(attr))->index; in in_max_store()
1214 struct i2c_client *client = data->client; in in_max_store()
1215 int vccp = nr - 6; in in_max_store()
1224 mutex_lock(&data->update_lock); in in_max_store()
1226 vid = LM93_VID_FROM_REG(data->vid[vccp]); in in_max_store()
1227 data->vccp_limits[vccp] = (data->vccp_limits[vccp] & 0x0f) | in in_max_store()
1230 data->vccp_limits[vccp]); in in_max_store()
1232 data->block7[nr].max = LM93_IN_TO_REG(nr, val); in in_max_store()
1234 data->block7[nr].max); in in_max_store()
1236 mutex_unlock(&data->update_lock); in in_max_store()
1260 int nr = (to_sensor_dev_attr(attr))->index; in temp_show()
1262 return sprintf(buf, "%d\n", LM93_TEMP_FROM_REG(data->block2[nr])); in temp_show()
1272 int nr = (to_sensor_dev_attr(attr))->index; in temp_min_show()
1274 return sprintf(buf, "%d\n", LM93_TEMP_FROM_REG(data->temp_lim[nr].min)); in temp_min_show()
1281 int nr = (to_sensor_dev_attr(attr))->index; in temp_min_store()
1283 struct i2c_client *client = data->client; in temp_min_store()
1291 mutex_lock(&data->update_lock); in temp_min_store()
1292 data->temp_lim[nr].min = LM93_TEMP_TO_REG(val); in temp_min_store()
1293 lm93_write_byte(client, LM93_REG_TEMP_MIN(nr), data->temp_lim[nr].min); in temp_min_store()
1294 mutex_unlock(&data->update_lock); in temp_min_store()
1305 int nr = (to_sensor_dev_attr(attr))->index; in temp_max_show()
1307 return sprintf(buf, "%d\n", LM93_TEMP_FROM_REG(data->temp_lim[nr].max)); in temp_max_show()
1314 int nr = (to_sensor_dev_attr(attr))->index; in temp_max_store()
1316 struct i2c_client *client = data->client; in temp_max_store()
1324 mutex_lock(&data->update_lock); in temp_max_store()
1325 data->temp_lim[nr].max = LM93_TEMP_TO_REG(val); in temp_max_store()
1326 lm93_write_byte(client, LM93_REG_TEMP_MAX(nr), data->temp_lim[nr].max); in temp_max_store()
1327 mutex_unlock(&data->update_lock); in temp_max_store()
1338 int nr = (to_sensor_dev_attr(attr))->index; in temp_auto_base_show()
1340 return sprintf(buf, "%d\n", LM93_TEMP_FROM_REG(data->block10.base[nr])); in temp_auto_base_show()
1347 int nr = (to_sensor_dev_attr(attr))->index; in temp_auto_base_store()
1349 struct i2c_client *client = data->client; in temp_auto_base_store()
1357 mutex_lock(&data->update_lock); in temp_auto_base_store()
1358 data->block10.base[nr] = LM93_TEMP_TO_REG(val); in temp_auto_base_store()
1359 lm93_write_byte(client, LM93_REG_TEMP_BASE(nr), data->block10.base[nr]); in temp_auto_base_store()
1360 mutex_unlock(&data->update_lock); in temp_auto_base_store()
1371 int nr = (to_sensor_dev_attr(attr))->index; in temp_auto_boost_show()
1373 return sprintf(buf, "%d\n", LM93_TEMP_FROM_REG(data->boost[nr])); in temp_auto_boost_show()
1380 int nr = (to_sensor_dev_attr(attr))->index; in temp_auto_boost_store()
1382 struct i2c_client *client = data->client; in temp_auto_boost_store()
1390 mutex_lock(&data->update_lock); in temp_auto_boost_store()
1391 data->boost[nr] = LM93_TEMP_TO_REG(val); in temp_auto_boost_store()
1392 lm93_write_byte(client, LM93_REG_BOOST(nr), data->boost[nr]); in temp_auto_boost_store()
1393 mutex_unlock(&data->update_lock); in temp_auto_boost_store()
1405 int nr = (to_sensor_dev_attr(attr))->index; in temp_auto_boost_hyst_show()
1407 int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr); in temp_auto_boost_hyst_show()
1416 int nr = (to_sensor_dev_attr(attr))->index; in temp_auto_boost_hyst_store()
1418 struct i2c_client *client = data->client; in temp_auto_boost_hyst_store()
1426 mutex_lock(&data->update_lock); in temp_auto_boost_hyst_store()
1428 data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); in temp_auto_boost_hyst_store()
1429 data->sfc2 |= ((nr < 2) ? 0x10 : 0x20); in temp_auto_boost_hyst_store()
1430 lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); in temp_auto_boost_hyst_store()
1431 data->boost_hyst[nr/2] = LM93_AUTO_BOOST_HYST_TO_REG(data, val, nr, 1); in temp_auto_boost_hyst_store()
1433 data->boost_hyst[nr/2]); in temp_auto_boost_hyst_store()
1434 mutex_unlock(&data->update_lock); in temp_auto_boost_hyst_store()
1446 int nr = s_attr->index; in temp_auto_offset_show()
1447 int ofs = s_attr->nr; in temp_auto_offset_show()
1449 int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr); in temp_auto_offset_show()
1451 LM93_TEMP_AUTO_OFFSET_FROM_REG(data->block10.offset[ofs], in temp_auto_offset_show()
1460 int nr = s_attr->index; in temp_auto_offset_store()
1461 int ofs = s_attr->nr; in temp_auto_offset_store()
1463 struct i2c_client *client = data->client; in temp_auto_offset_store()
1471 mutex_lock(&data->update_lock); in temp_auto_offset_store()
1473 data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); in temp_auto_offset_store()
1474 data->sfc2 |= ((nr < 2) ? 0x10 : 0x20); in temp_auto_offset_store()
1475 lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); in temp_auto_offset_store()
1476 data->block10.offset[ofs] = LM93_TEMP_AUTO_OFFSET_TO_REG( in temp_auto_offset_store()
1477 data->block10.offset[ofs], val, nr, 1); in temp_auto_offset_store()
1479 data->block10.offset[ofs]); in temp_auto_offset_store()
1480 mutex_unlock(&data->update_lock); in temp_auto_offset_store()
1525 int nr = (to_sensor_dev_attr(attr))->index; in temp_auto_pwm_min_show()
1528 reg = data->auto_pwm_min_hyst[nr/2] >> 4 & 0x0f; in temp_auto_pwm_min_show()
1529 ctl4 = data->block9[nr][LM93_PWM_CTL4]; in temp_auto_pwm_min_show()
1538 int nr = (to_sensor_dev_attr(attr))->index; in temp_auto_pwm_min_store()
1540 struct i2c_client *client = data->client; in temp_auto_pwm_min_store()
1549 mutex_lock(&data->update_lock); in temp_auto_pwm_min_store()
1556 data->auto_pwm_min_hyst[nr/2] = reg; in temp_auto_pwm_min_store()
1558 mutex_unlock(&data->update_lock); in temp_auto_pwm_min_store()
1570 int nr = (to_sensor_dev_attr(attr))->index; in temp_auto_offset_hyst_show()
1572 int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr); in temp_auto_offset_hyst_show()
1574 data->auto_pwm_min_hyst[nr / 2], mode)); in temp_auto_offset_hyst_show()
1581 int nr = (to_sensor_dev_attr(attr))->index; in temp_auto_offset_hyst_store()
1583 struct i2c_client *client = data->client; in temp_auto_offset_hyst_store()
1592 mutex_lock(&data->update_lock); in temp_auto_offset_hyst_store()
1594 data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); in temp_auto_offset_hyst_store()
1595 data->sfc2 |= ((nr < 2) ? 0x10 : 0x20); in temp_auto_offset_hyst_store()
1596 lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); in temp_auto_offset_hyst_store()
1597 reg = data->auto_pwm_min_hyst[nr/2]; in temp_auto_offset_hyst_store()
1599 data->auto_pwm_min_hyst[nr/2] = reg; in temp_auto_offset_hyst_store()
1601 mutex_unlock(&data->update_lock); in temp_auto_offset_hyst_store()
1613 int nr = s_attr->index; in fan_input_show()
1616 return sprintf(buf, "%d\n", LM93_FAN_FROM_REG(data->block5[nr])); in fan_input_show()
1627 int nr = (to_sensor_dev_attr(attr))->index; in fan_min_show()
1630 return sprintf(buf, "%d\n", LM93_FAN_FROM_REG(data->block8[nr])); in fan_min_show()
1637 int nr = (to_sensor_dev_attr(attr))->index; in fan_min_store()
1639 struct i2c_client *client = data->client; in fan_min_store()
1647 mutex_lock(&data->update_lock); in fan_min_store()
1648 data->block8[nr] = LM93_FAN_TO_REG(val); in fan_min_store()
1649 lm93_write_word(client, LM93_REG_FAN_MIN(nr), data->block8[nr]); in fan_min_store()
1650 mutex_unlock(&data->update_lock); in fan_min_store()
1660 * some tedious bit-twiddling here to deal with the register format:
1662 * data->sf_tach_to_pwm: (tach to pwm mapping bits)
1667 * data->sfc2: (enable bits)
1676 int nr = (to_sensor_dev_attr(attr))->index; in fan_smart_tach_show()
1682 mapping = (data->sf_tach_to_pwm >> (nr * 2)) & 0x03; in fan_smart_tach_show()
1685 if (mapping && ((data->sfc2 >> nr) & 0x01)) in fan_smart_tach_show()
1691 * helper function - must grab data->update_lock before calling
1692 * fan is 0-3, indicating fan1-fan4
1698 data->sf_tach_to_pwm = lm93_read_byte(client, LM93_REG_SF_TACH_TO_PWM); in lm93_write_fan_smart_tach()
1699 data->sf_tach_to_pwm &= ~(0x3 << fan * 2); in lm93_write_fan_smart_tach()
1700 data->sf_tach_to_pwm |= value << fan * 2; in lm93_write_fan_smart_tach()
1701 lm93_write_byte(client, LM93_REG_SF_TACH_TO_PWM, data->sf_tach_to_pwm); in lm93_write_fan_smart_tach()
1704 data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); in lm93_write_fan_smart_tach()
1706 data->sfc2 |= 1 << fan; in lm93_write_fan_smart_tach()
1708 data->sfc2 &= ~(1 << fan); in lm93_write_fan_smart_tach()
1709 lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); in lm93_write_fan_smart_tach()
1716 int nr = (to_sensor_dev_attr(attr))->index; in fan_smart_tach_store()
1718 struct i2c_client *client = data->client; in fan_smart_tach_store()
1726 mutex_lock(&data->update_lock); in fan_smart_tach_store()
1732 LM93_REG_PWM_CTL(val - 1, LM93_PWM_CTL4)); in fan_smart_tach_store()
1738 mutex_unlock(&data->update_lock); in fan_smart_tach_store()
1750 int nr = (to_sensor_dev_attr(attr))->index; in pwm_show()
1755 ctl2 = data->block9[nr][LM93_PWM_CTL2]; in pwm_show()
1756 ctl4 = data->block9[nr][LM93_PWM_CTL4]; in pwm_show()
1758 rc = data->pwm_override[nr]; in pwm_show()
1768 int nr = (to_sensor_dev_attr(attr))->index; in pwm_store()
1770 struct i2c_client *client = data->client; in pwm_store()
1779 mutex_lock(&data->update_lock); in pwm_store()
1785 data->pwm_override[nr] = LM93_PWM_FROM_REG(ctl2 >> 4, in pwm_store()
1789 mutex_unlock(&data->update_lock); in pwm_store()
1799 int nr = (to_sensor_dev_attr(attr))->index; in pwm_enable_show()
1804 ctl2 = data->block9[nr][LM93_PWM_CTL2]; in pwm_enable_show()
1816 int nr = (to_sensor_dev_attr(attr))->index; in pwm_enable_store()
1818 struct i2c_client *client = data->client; in pwm_enable_store()
1827 mutex_lock(&data->update_lock); in pwm_enable_store()
1841 mutex_unlock(&data->update_lock); in pwm_enable_store()
1842 return -EINVAL; in pwm_enable_store()
1846 mutex_unlock(&data->update_lock); in pwm_enable_store()
1856 int nr = (to_sensor_dev_attr(attr))->index; in pwm_freq_show()
1860 ctl4 = data->block9[nr][LM93_PWM_CTL4]; in pwm_freq_show()
1865 * helper function - must grab data->update_lock before calling
1866 * pwm is 0-1, indicating pwm1-pwm2
1883 data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); in lm93_disable_fan_smart_tach()
1884 data->sfc2 &= ~mask; in lm93_disable_fan_smart_tach()
1885 lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); in lm93_disable_fan_smart_tach()
1892 int nr = (to_sensor_dev_attr(attr))->index; in pwm_freq_store()
1894 struct i2c_client *client = data->client; in pwm_freq_store()
1903 mutex_lock(&data->update_lock); in pwm_freq_store()
1906 data->block9[nr][LM93_PWM_CTL4] = ctl4; in pwm_freq_store()
1907 /* ctl4 == 0 -> 22.5KHz -> disable smart tach */ in pwm_freq_store()
1911 mutex_unlock(&data->update_lock); in pwm_freq_store()
1922 int nr = (to_sensor_dev_attr(attr))->index; in pwm_auto_channels_show()
1924 return sprintf(buf, "%d\n", data->block9[nr][LM93_PWM_CTL1]); in pwm_auto_channels_show()
1931 int nr = (to_sensor_dev_attr(attr))->index; in pwm_auto_channels_store()
1933 struct i2c_client *client = data->client; in pwm_auto_channels_store()
1941 mutex_lock(&data->update_lock); in pwm_auto_channels_store()
1942 data->block9[nr][LM93_PWM_CTL1] = clamp_val(val, 0, 255); in pwm_auto_channels_store()
1944 data->block9[nr][LM93_PWM_CTL1]); in pwm_auto_channels_store()
1945 mutex_unlock(&data->update_lock); in pwm_auto_channels_store()
1956 int nr = (to_sensor_dev_attr(attr))->index; in pwm_auto_spinup_min_show()
1960 ctl3 = data->block9[nr][LM93_PWM_CTL3]; in pwm_auto_spinup_min_show()
1961 ctl4 = data->block9[nr][LM93_PWM_CTL4]; in pwm_auto_spinup_min_show()
1971 int nr = (to_sensor_dev_attr(attr))->index; in pwm_auto_spinup_min_store()
1973 struct i2c_client *client = data->client; in pwm_auto_spinup_min_store()
1982 mutex_lock(&data->update_lock); in pwm_auto_spinup_min_store()
1988 data->block9[nr][LM93_PWM_CTL3] = ctl3; in pwm_auto_spinup_min_store()
1990 mutex_unlock(&data->update_lock); in pwm_auto_spinup_min_store()
2001 int nr = (to_sensor_dev_attr(attr))->index; in pwm_auto_spinup_time_show()
2004 data->block9[nr][LM93_PWM_CTL3])); in pwm_auto_spinup_time_show()
2011 int nr = (to_sensor_dev_attr(attr))->index; in pwm_auto_spinup_time_store()
2013 struct i2c_client *client = data->client; in pwm_auto_spinup_time_store()
2022 mutex_lock(&data->update_lock); in pwm_auto_spinup_time_store()
2025 data->block9[nr][LM93_PWM_CTL3] = ctl3; in pwm_auto_spinup_time_store()
2027 mutex_unlock(&data->update_lock); in pwm_auto_spinup_time_store()
2039 LM93_RAMP_FROM_REG(data->pwm_ramp_ctl >> 4 & 0x0f)); in pwm_auto_prochot_ramp_show()
2047 struct i2c_client *client = data->client; in pwm_auto_prochot_ramp_store()
2056 mutex_lock(&data->update_lock); in pwm_auto_prochot_ramp_store()
2060 mutex_unlock(&data->update_lock); in pwm_auto_prochot_ramp_store()
2071 LM93_RAMP_FROM_REG(data->pwm_ramp_ctl & 0x0f)); in pwm_auto_vrdhot_ramp_show()
2079 struct i2c_client *client = data->client; in pwm_auto_vrdhot_ramp_store()
2088 mutex_lock(&data->update_lock); in pwm_auto_vrdhot_ramp_store()
2092 mutex_unlock(&data->update_lock); in pwm_auto_vrdhot_ramp_store()
2101 int nr = (to_sensor_dev_attr(attr))->index; in vid_show()
2103 return sprintf(buf, "%d\n", LM93_VID_FROM_REG(data->vid[nr])); in vid_show()
2112 int nr = (to_sensor_dev_attr(attr))->index; in prochot_show()
2114 return sprintf(buf, "%d\n", data->block4[nr].cur); in prochot_show()
2123 int nr = (to_sensor_dev_attr(attr))->index; in prochot_avg_show()
2125 return sprintf(buf, "%d\n", data->block4[nr].avg); in prochot_avg_show()
2134 int nr = (to_sensor_dev_attr(attr))->index; in prochot_max_show()
2136 return sprintf(buf, "%d\n", data->prochot_max[nr]); in prochot_max_show()
2143 int nr = (to_sensor_dev_attr(attr))->index; in prochot_max_store()
2145 struct i2c_client *client = data->client; in prochot_max_store()
2153 mutex_lock(&data->update_lock); in prochot_max_store()
2154 data->prochot_max[nr] = LM93_PROCHOT_TO_REG(val); in prochot_max_store()
2156 data->prochot_max[nr]); in prochot_max_store()
2157 mutex_unlock(&data->update_lock); in prochot_max_store()
2169 int nr = (to_sensor_dev_attr(attr))->index; in prochot_override_show()
2172 (data->prochot_override & prochot_override_mask[nr]) ? 1 : 0); in prochot_override_show()
2179 int nr = (to_sensor_dev_attr(attr))->index; in prochot_override_store()
2181 struct i2c_client *client = data->client; in prochot_override_store()
2189 mutex_lock(&data->update_lock); in prochot_override_store()
2191 data->prochot_override |= prochot_override_mask[nr]; in prochot_override_store()
2193 data->prochot_override &= (~prochot_override_mask[nr]); in prochot_override_store()
2195 data->prochot_override); in prochot_override_store()
2196 mutex_unlock(&data->update_lock); in prochot_override_store()
2206 int nr = (to_sensor_dev_attr(attr))->index; in prochot_interval_show()
2210 tmp = (data->prochot_interval & 0xf0) >> 4; in prochot_interval_show()
2212 tmp = data->prochot_interval & 0x0f; in prochot_interval_show()
2220 int nr = (to_sensor_dev_attr(attr))->index; in prochot_interval_store()
2222 struct i2c_client *client = data->client; in prochot_interval_store()
2231 mutex_lock(&data->update_lock); in prochot_interval_store()
2237 data->prochot_interval = tmp; in prochot_interval_store()
2239 mutex_unlock(&data->update_lock); in prochot_interval_store()
2251 return sprintf(buf, "%d\n", data->prochot_override & 0x0f); in prochot_override_duty_cycle_show()
2259 struct i2c_client *client = data->client; in prochot_override_duty_cycle_store()
2267 mutex_lock(&data->update_lock); in prochot_override_duty_cycle_store()
2268 data->prochot_override = (data->prochot_override & 0xf0) | in prochot_override_duty_cycle_store()
2271 data->prochot_override); in prochot_override_duty_cycle_store()
2272 mutex_unlock(&data->update_lock); in prochot_override_duty_cycle_store()
2282 return sprintf(buf, "%d\n", (data->config & 0x10) ? 1 : 0); in prochot_short_show()
2290 struct i2c_client *client = data->client; in prochot_short_store()
2298 mutex_lock(&data->update_lock); in prochot_short_store()
2300 data->config |= 0x10; in prochot_short_store()
2302 data->config &= ~0x10; in prochot_short_store()
2303 lm93_write_byte(client, LM93_REG_CONFIG, data->config); in prochot_short_store()
2304 mutex_unlock(&data->update_lock); in prochot_short_store()
2313 int nr = (to_sensor_dev_attr(attr))->index; in vrdhot_show()
2316 data->block1.host_status_1 & (1 << (nr + 4)) ? 1 : 0); in vrdhot_show()
2326 return sprintf(buf, "%d\n", LM93_GPI_FROM_REG(data->gpi)); in gpio_show()
2335 return sprintf(buf, "%d\n", LM93_ALARMS_FROM_REG(data->block1)); in alarms_show()
2539 dev_warn(&client->dev, in lm93_init_client()
2543 /* Return 0 if detection is successful, -ENODEV otherwise */
2546 struct i2c_adapter *adapter = client->adapter; in lm93_detect()
2551 return -ENODEV; in lm93_detect()
2556 dev_dbg(&adapter->dev, in lm93_detect()
2558 return -ENODEV; in lm93_detect()
2573 dev_dbg(&adapter->dev, in lm93_detect()
2575 return -ENODEV; in lm93_detect()
2578 strscpy(info->type, name, I2C_NAME_SIZE); in lm93_detect()
2579 dev_dbg(&adapter->dev, "loading %s at %d, 0x%02x\n", in lm93_detect()
2580 client->name, i2c_adapter_id(client->adapter), in lm93_detect()
2581 client->addr); in lm93_detect()
2588 struct device *dev = &client->dev; in lm93_probe()
2595 func = i2c_get_functionality(client->adapter); in lm93_probe()
2605 return -ENODEV; in lm93_probe()
2610 return -ENOMEM; in lm93_probe()
2613 data->client = client; in lm93_probe()
2614 data->update = update; in lm93_probe()
2615 mutex_init(&data->update_lock); in lm93_probe()
2620 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, in lm93_probe()