Lines Matching +full:data +full:- +full:shift

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * asc7621.c - Part of lm_sensors, Linux kernel modules for hardware monitoring
13 #include <linux/hwmon-sysfs.h>
71 * and data arrays.
72 * This comes from the data sheet register description table.
110 u8 shift[3]; member
125 dev_err(&client->dev, in read_byte()
132 static inline int write_byte(struct i2c_client *client, u8 reg, u8 data) in write_byte() argument
134 int res = i2c_smbus_write_byte_data(client, reg, data); in write_byte()
136 dev_err(&client->dev, in write_byte()
138 data, reg); in write_byte()
144 * Data Handlers
151 struct asc7621_data *data = asc7621_update_device(d); \
157 struct asc7621_data *data = i2c_get_clientdata(client); \
169 return sprintf(buf, "%u\n", data->reg[param->msb[0]]); in show_u8()
179 return -EINVAL; in store_u8()
183 mutex_lock(&data->update_lock); in store_u8()
184 data->reg[param->msb[0]] = reqval; in store_u8()
185 write_byte(client, param->msb[0], reqval); in store_u8()
186 mutex_unlock(&data->update_lock); in store_u8()
199 (data->reg[param->msb[0]] >> param-> in show_bitmask()
200 shift[0]) & param->mask[0]); in show_bitmask()
212 return -EINVAL; in store_bitmask()
214 reqval = clamp_val(reqval, 0, param->mask[0]); in store_bitmask()
216 reqval = (reqval & param->mask[0]) << param->shift[0]; in store_bitmask()
218 mutex_lock(&data->update_lock); in store_bitmask()
219 currval = read_byte(client, param->msb[0]); in store_bitmask()
220 reqval |= (currval & ~(param->mask[0] << param->shift[0])); in store_bitmask()
221 data->reg[param->msb[0]] = reqval; in store_bitmask()
222 write_byte(client, param->msb[0], reqval); in store_bitmask()
223 mutex_unlock(&data->update_lock); in store_bitmask()
239 mutex_lock(&data->update_lock); in show_fan16()
240 regval = (data->reg[param->msb[0]] << 8) | data->reg[param->lsb[0]]; in show_fan16()
241 mutex_unlock(&data->update_lock); in show_fan16()
244 (regval == 0 ? -1 : (regval) == in show_fan16()
256 return -EINVAL; in store_fan16()
266 mutex_lock(&data->update_lock); in store_fan16()
267 data->reg[param->msb[0]] = (reqval >> 8) & 0xff; in store_fan16()
268 data->reg[param->lsb[0]] = reqval & 0xff; in store_fan16()
269 write_byte(client, param->msb[0], data->reg[param->msb[0]]); in store_fan16()
270 write_byte(client, param->lsb[0], data->reg[param->lsb[0]]); in store_fan16()
271 mutex_unlock(&data->update_lock); in store_fan16()
278 * is 3/4ths of the 0-255 range (i.e. 192).
282 * The data sheet provides us with the 3/4 scale value for each voltage
283 * which is stored in in_scaling. The sda->index parameter value provides
299 u8 nr = sda->index; in show_in10()
301 mutex_lock(&data->update_lock); in show_in10()
302 regval = (data->reg[param->msb[0]] << 8) | (data->reg[param->lsb[0]]); in show_in10()
303 mutex_unlock(&data->update_lock); in show_in10()
305 /* The LSB value is a 2-bit scaling of the MSB's LSbit value. */ in show_in10()
316 u8 nr = sda->index; in show_in8()
319 ((data->reg[param->msb[0]] * in show_in8()
328 u8 nr = sda->index; in store_in8()
331 return -EINVAL; in store_in8()
339 mutex_lock(&data->update_lock); in store_in8()
340 data->reg[param->msb[0]] = reqval; in store_in8()
341 write_byte(client, param->msb[0], reqval); in store_in8()
342 mutex_unlock(&data->update_lock); in store_in8()
352 return sprintf(buf, "%d\n", ((s8) data->reg[param->msb[0]]) * 1000); in show_temp8()
364 return -EINVAL; in store_temp8()
366 reqval = clamp_val(reqval, -127000, 127000); in store_temp8()
370 mutex_lock(&data->update_lock); in store_temp8()
371 data->reg[param->msb[0]] = temp; in store_temp8()
372 write_byte(client, param->msb[0], temp); in store_temp8()
373 mutex_unlock(&data->update_lock); in store_temp8()
391 mutex_lock(&data->update_lock); in show_temp10()
392 msb = data->reg[param->msb[0]]; in show_temp10()
393 lsb = (data->reg[param->lsb[0]] >> 6) & 0x03; in show_temp10()
395 mutex_unlock(&data->update_lock); in show_temp10()
405 u8 regval = data->reg[param->msb[0]]; in show_temp62()
420 return -EINVAL; in store_temp62()
422 reqval = clamp_val(reqval, -32000, 31750); in store_temp62()
424 f = reqval - (i * 1000); in store_temp62()
428 mutex_lock(&data->update_lock); in store_temp62()
429 data->reg[param->msb[0]] = temp; in store_temp62()
430 write_byte(client, param->msb[0], temp); in store_temp62()
431 mutex_unlock(&data->update_lock); in store_temp62()
454 mutex_lock(&data->update_lock); in show_ap2_temp()
455 auto_point1 = ((s8) data->reg[param->msb[1]]) * 1000; in show_ap2_temp()
457 ((data->reg[param->msb[0]] >> param->shift[0]) & param->mask[0]); in show_ap2_temp()
459 mutex_unlock(&data->update_lock); in show_ap2_temp()
475 return -EINVAL; in store_ap2_temp()
477 mutex_lock(&data->update_lock); in store_ap2_temp()
478 auto_point1 = data->reg[param->msb[1]] * 1000; in store_ap2_temp()
481 for (i = ARRAY_SIZE(asc7621_range_map) - 1; i >= 0; i--) { in store_ap2_temp()
488 newval = (newval & param->mask[0]) << param->shift[0]; in store_ap2_temp()
489 currval = read_byte(client, param->msb[0]); in store_ap2_temp()
490 newval |= (currval & ~(param->mask[0] << param->shift[0])); in store_ap2_temp()
491 data->reg[param->msb[0]] = newval; in store_ap2_temp()
492 write_byte(client, param->msb[0], newval); in store_ap2_temp()
493 mutex_unlock(&data->update_lock); in store_ap2_temp()
507 mutex_lock(&data->update_lock); in show_pwm_ac()
508 config = (data->reg[param->msb[0]] >> param->shift[0]) & param->mask[0]; in show_pwm_ac()
509 altbit = (data->reg[param->msb[1]] >> param->shift[1]) & param->mask[1]; in show_pwm_ac()
511 mutex_unlock(&data->update_lock); in show_pwm_ac()
531 return -EINVAL; in store_pwm_ac()
534 return -EINVAL; in store_pwm_ac()
538 return -EINVAL; in store_pwm_ac()
543 config = (config & param->mask[0]) << param->shift[0]; in store_pwm_ac()
544 altbit = (altbit & param->mask[1]) << param->shift[1]; in store_pwm_ac()
546 mutex_lock(&data->update_lock); in store_pwm_ac()
547 currval = read_byte(client, param->msb[0]); in store_pwm_ac()
548 newval = config | (currval & ~(param->mask[0] << param->shift[0])); in store_pwm_ac()
549 newval = altbit | (newval & ~(param->mask[1] << param->shift[1])); in store_pwm_ac()
550 data->reg[param->msb[0]] = newval; in store_pwm_ac()
551 write_byte(client, param->msb[0], newval); in store_pwm_ac()
552 mutex_unlock(&data->update_lock); in store_pwm_ac()
562 mutex_lock(&data->update_lock); in show_pwm_enable()
563 config = (data->reg[param->msb[0]] >> param->shift[0]) & param->mask[0]; in show_pwm_enable()
564 altbit = (data->reg[param->msb[1]] >> param->shift[1]) & param->mask[1]; in show_pwm_enable()
565 minoff = (data->reg[param->msb[2]] >> param->shift[2]) & param->mask[2]; in show_pwm_enable()
566 mutex_unlock(&data->update_lock); in show_pwm_enable()
593 return -EINVAL; in store_pwm_enable()
614 return -EINVAL; in store_pwm_enable()
620 mutex_lock(&data->update_lock); in store_pwm_enable()
621 config = (config & param->mask[0]) << param->shift[0]; in store_pwm_enable()
622 altbit = (altbit & param->mask[1]) << param->shift[1]; in store_pwm_enable()
623 currval = read_byte(client, param->msb[0]); in store_pwm_enable()
624 newval = config | (currval & ~(param->mask[0] << param->shift[0])); in store_pwm_enable()
625 newval = altbit | (newval & ~(param->mask[1] << param->shift[1])); in store_pwm_enable()
626 data->reg[param->msb[0]] = newval; in store_pwm_enable()
627 write_byte(client, param->msb[0], newval); in store_pwm_enable()
629 minoff = (minoff & param->mask[2]) << param->shift[2]; in store_pwm_enable()
630 currval = read_byte(client, param->msb[2]); in store_pwm_enable()
632 minoff | (currval & ~(param->mask[2] << param->shift[2])); in store_pwm_enable()
633 data->reg[param->msb[2]] = newval; in store_pwm_enable()
634 write_byte(client, param->msb[2], newval); in store_pwm_enable()
636 mutex_unlock(&data->update_lock); in store_pwm_enable()
650 (data->reg[param->msb[0]] >> param->shift[0]) & param->mask[0]; in show_pwm_freq()
667 return -EINVAL; in store_pwm_freq()
676 return -EINVAL; in store_pwm_freq()
678 newval = (newval & param->mask[0]) << param->shift[0]; in store_pwm_freq()
680 mutex_lock(&data->update_lock); in store_pwm_freq()
681 currval = read_byte(client, param->msb[0]); in store_pwm_freq()
682 newval |= (currval & ~(param->mask[0] << param->shift[0])); in store_pwm_freq()
683 data->reg[param->msb[0]] = newval; in store_pwm_freq()
684 write_byte(client, param->msb[0], newval); in store_pwm_freq()
685 mutex_unlock(&data->update_lock); in store_pwm_freq()
698 (data->reg[param->msb[0]] >> param->shift[0]) & param->mask[0]; in show_pwm_ast()
716 return -EINVAL; in store_pwm_ast()
725 return -EINVAL; in store_pwm_ast()
727 newval = (newval & param->mask[0]) << param->shift[0]; in store_pwm_ast()
729 mutex_lock(&data->update_lock); in store_pwm_ast()
730 currval = read_byte(client, param->msb[0]); in store_pwm_ast()
731 newval |= (currval & ~(param->mask[0] << param->shift[0])); in store_pwm_ast()
732 data->reg[param->msb[0]] = newval; in store_pwm_ast()
733 write_byte(client, param->msb[0], newval); in store_pwm_ast()
734 mutex_unlock(&data->update_lock); in store_pwm_ast()
747 (data->reg[param->msb[0]] >> param->shift[0]) & param->mask[0]; in show_temp_st()
763 return -EINVAL; in store_temp_st()
773 return -EINVAL; in store_temp_st()
775 newval = (newval & param->mask[0]) << param->shift[0]; in store_temp_st()
777 mutex_lock(&data->update_lock); in store_temp_st()
778 currval = read_byte(client, param->msb[0]); in store_temp_st()
779 newval |= (currval & ~(param->mask[0] << param->shift[0])); in store_temp_st()
780 data->reg[param->msb[0]] = newval; in store_temp_st()
781 write_byte(client, param->msb[0], newval); in store_temp_st()
782 mutex_unlock(&data->update_lock); in store_temp_st()
787 * End of data handlers
802 .shift[0] = s,}
807 .shift[0] = s,}
810 * PWRITEM assumes that the initializers for the .msb, .lsb, .mask and .shift
815 .priority = pri, .msb = rm, .lsb = rl, .mask = m, .shift = s,}
995 struct asc7621_data *data = i2c_get_clientdata(client); in asc7621_update_device() local
999 * The asc7621 chips guarantee consistent reads of multi-byte values in asc7621_update_device()
1005 mutex_lock(&data->update_lock); in asc7621_update_device()
1009 if (!data->valid || in asc7621_update_device()
1010 time_after(jiffies, data->last_high_reading + INTERVAL_HIGH)) { in asc7621_update_device()
1014 data->reg[i] = in asc7621_update_device()
1018 data->last_high_reading = jiffies; in asc7621_update_device()
1023 if (!data->valid || in asc7621_update_device()
1024 time_after(jiffies, data->last_low_reading + INTERVAL_LOW)) { in asc7621_update_device()
1028 data->reg[i] = in asc7621_update_device()
1032 data->last_low_reading = jiffies; in asc7621_update_device()
1035 data->valid = true; in asc7621_update_device()
1037 mutex_unlock(&data->update_lock); in asc7621_update_device()
1039 return data; in asc7621_update_device()
1070 dev_err(&client->dev, in asc7621_init_client()
1072 i2c_adapter_id(client->adapter), client->addr); in asc7621_init_client()
1075 dev_err(&client->dev, "Client (%d,0x%02x) is not ready.\n", in asc7621_init_client()
1076 i2c_adapter_id(client->adapter), client->addr); in asc7621_init_client()
1092 struct asc7621_data *data; in asc7621_probe() local
1095 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) in asc7621_probe()
1096 return -EIO; in asc7621_probe()
1098 data = devm_kzalloc(&client->dev, sizeof(struct asc7621_data), in asc7621_probe()
1100 if (data == NULL) in asc7621_probe()
1101 return -ENOMEM; in asc7621_probe()
1103 i2c_set_clientdata(client, data); in asc7621_probe()
1104 mutex_init(&data->update_lock); in asc7621_probe()
1112 device_create_file(&client->dev, in asc7621_probe()
1118 data->class_dev = hwmon_device_register(&client->dev); in asc7621_probe()
1119 if (IS_ERR(data->class_dev)) { in asc7621_probe()
1120 err = PTR_ERR(data->class_dev); in asc7621_probe()
1128 device_remove_file(&client->dev, in asc7621_probe()
1138 struct i2c_adapter *adapter = client->adapter; in asc7621_detect()
1142 return -ENODEV; in asc7621_detect()
1146 if (!valid_address_for_chip(chip_index, client->addr)) in asc7621_detect()
1156 strscpy(info->type, asc7621_chips[chip_index].name, in asc7621_detect()
1159 dev_info(&adapter->dev, "Matched %s at 0x%02x\n", in asc7621_detect()
1160 asc7621_chips[chip_index].name, client->addr); in asc7621_detect()
1165 return -ENODEV; in asc7621_detect()
1170 struct asc7621_data *data = i2c_get_clientdata(client); in asc7621_remove() local
1173 hwmon_device_unregister(data->class_dev); in asc7621_remove()
1176 device_remove_file(&client->dev, in asc7621_remove()