Lines Matching +full:0 +full:- +full:indexed

1 // SPDX-License-Identifier: GPL-2.0
27 #define RTQ6056_REG_CONFIG 0x00
28 #define RTQ6056_REG_SHUNTVOLT 0x01
29 #define RTQ6056_REG_BUSVOLT 0x02
30 #define RTQ6056_REG_POWER 0x03
31 #define RTQ6056_REG_CURRENT 0x04
32 #define RTQ6056_REG_CALIBRATION 0x05
33 #define RTQ6056_REG_MASKENABLE 0x06
34 #define RTQ6056_REG_ALERTLIMIT 0x07
35 #define RTQ6056_REG_MANUFACTID 0xFE
36 #define RTQ6056_REG_DIEID 0xFF
38 #define RTQ6056_VENDOR_ID 0x1214
39 #define RTQ6056_DEFAULT_CONFIG 0x4127
42 #define RTQ6059_DEFAULT_CONFIG 0x3C47
47 RTQ6056_CH_VSHUNT = 0,
55 * The enum is to present the 0x00 CONFIG RG bitfield for the 16bit RG value
57 * RTQ6053/6 is OPMODE->VSHUNTCT->VBUSCT->AVG->RESET
58 * RTQ6059 is OPMODE->SADC->BADC->PGA->RESET
61 F_OPMODE = 0,
101 [F_OPMODE] = REG_FIELD(RTQ6056_REG_CONFIG, 0, 2),
109 [F_OPMODE] = REG_FIELD(RTQ6056_REG_CONFIG, 0, 2),
119 .indexed = 1,
120 .channel = 0,
128 .scan_index = 0,
138 .indexed = 1,
157 .indexed = 1,
175 .indexed = 1,
195 * - Fixed sampling conversion time
196 * - Average sample numbers
197 * - Channel scale
198 * - calibration coefficient
203 .indexed = 1,
204 .channel = 0,
211 .scan_index = 0,
221 .indexed = 1,
239 .indexed = 1,
257 .indexed = 1,
279 const struct richtek_dev_data *devdata = priv->devdata; in rtq6056_adc_read_channel()
280 struct device *dev = priv->dev; in rtq6056_adc_read_channel()
281 unsigned int addr = ch->address; in rtq6056_adc_read_channel()
286 ret = regmap_read(priv->regmap, addr, &regval); in rtq6056_adc_read_channel()
292 /* Power and VBUS is unsigned 16-bit, others are signed 16-bit */ in rtq6056_adc_read_channel()
295 regval >>= devdata->vbus_offset; in rtq6056_adc_read_channel()
306 return -EINVAL; in rtq6056_adc_read_channel()
313 switch (ch->address) { in rtq6056_adc_read_scale()
329 return -EINVAL; in rtq6056_adc_read_scale()
336 switch (ch->address) { in rtq6059_adc_read_scale()
351 return -EINVAL; in rtq6059_adc_read_scale()
358 * https://www.richtek.com/assets/product_file/RTQ6056/DSQ6056-00.pdf
372 return -EINVAL; in rtq6056_adc_set_samp_freq()
374 if (ch->address == RTQ6056_REG_SHUNTVOLT) { in rtq6056_adc_set_samp_freq()
375 rm_field = priv->rm_fields[F_VSHUNTCT]; in rtq6056_adc_set_samp_freq()
376 ct = &priv->vshuntct_us; in rtq6056_adc_set_samp_freq()
377 } else if (ch->address == RTQ6056_REG_BUSVOLT) { in rtq6056_adc_set_samp_freq()
378 rm_field = priv->rm_fields[F_VBUSCT]; in rtq6056_adc_set_samp_freq()
379 ct = &priv->vbusct_us; in rtq6056_adc_set_samp_freq()
381 return -EINVAL; in rtq6056_adc_set_samp_freq()
392 return 0; in rtq6056_adc_set_samp_freq()
398 * https://www.richtek.com/assets/product_file/RTQ6056/DSQ6056-00.pdf
414 return -EINVAL; in rtq6056_adc_set_average()
419 ret = regmap_field_write(priv->rm_fields[F_AVG], selector); in rtq6056_adc_set_average()
423 priv->avg_sample = rtq6056_avg_sample_list[selector]; in rtq6056_adc_set_average()
425 return 0; in rtq6056_adc_set_average()
434 return -EINVAL; in rtq6059_adc_set_average()
436 /* The supported average sample is 2^x (x from 0 to 7) */ in rtq6059_adc_set_average()
437 selector = fls(val) - 1; in rtq6059_adc_set_average()
439 ret = regmap_field_write(priv->rm_fields[F_RTQ6059_BADC], in rtq6059_adc_set_average()
444 ret = regmap_field_write(priv->rm_fields[F_RTQ6059_SADC], in rtq6059_adc_set_average()
447 priv->avg_sample = BIT(selector); in rtq6059_adc_set_average()
449 return 0; in rtq6059_adc_set_average()
457 if (ch->address == RTQ6056_REG_SHUNTVOLT) in rtq6056_adc_get_sample_freq()
458 sample_time = priv->vshuntct_us; in rtq6056_adc_get_sample_freq()
459 else if (ch->address == RTQ6056_REG_BUSVOLT) in rtq6056_adc_get_sample_freq()
460 sample_time = priv->vbusct_us; in rtq6056_adc_get_sample_freq()
462 sample_time = priv->vshuntct_us + priv->vbusct_us; in rtq6056_adc_get_sample_freq()
463 sample_time *= priv->avg_sample; in rtq6056_adc_get_sample_freq()
476 const struct richtek_dev_data *devdata = priv->devdata; in rtq6056_adc_read_raw()
482 return devdata->read_scale(chan, val, val2); in rtq6056_adc_read_raw()
484 *val = priv->avg_sample; in rtq6056_adc_read_raw()
489 return -EINVAL; in rtq6056_adc_read_raw()
499 const struct richtek_dev_data *devdata = priv->devdata; in rtq6056_adc_read_avail()
508 *vals = devdata->avg_sample_list; in rtq6056_adc_read_avail()
509 *length = devdata->avg_sample_list_length; in rtq6056_adc_read_avail()
513 return -EINVAL; in rtq6056_adc_read_avail()
522 const struct richtek_dev_data *devdata = priv->devdata; in rtq6056_adc_write_raw()
524 iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { in rtq6056_adc_write_raw()
527 if (devdata->fixed_samp_freq) in rtq6056_adc_write_raw()
528 return -EINVAL; in rtq6056_adc_write_raw()
531 return devdata->set_average(priv, val); in rtq6056_adc_write_raw()
533 return -EINVAL; in rtq6056_adc_write_raw()
550 return sysfs_emit(label, "%s\n", rtq6056_channel_labels[chan->channel]); in rtq6056_adc_read_label()
556 const struct richtek_dev_data *devdata = priv->devdata; in rtq6056_set_shunt_resistor()
560 if (resistor_uohm <= 0) { in rtq6056_set_shunt_resistor()
561 dev_err(priv->dev, "Invalid resistor [%d]\n", resistor_uohm); in rtq6056_set_shunt_resistor()
562 return -EINVAL; in rtq6056_set_shunt_resistor()
566 calib_val = devdata->calib_coefficient / resistor_uohm; in rtq6056_set_shunt_resistor()
567 ret = regmap_write(priv->regmap, RTQ6056_REG_CALIBRATION, calib_val); in rtq6056_set_shunt_resistor()
571 priv->shunt_resistor_uohm = resistor_uohm; in rtq6056_set_shunt_resistor()
573 return 0; in rtq6056_set_shunt_resistor()
580 int vals[2] = { priv->shunt_resistor_uohm, 1000000 }; in shunt_resistor_show()
609 static IIO_DEVICE_ATTR_RW(shunt_resistor, 0);
631 struct iio_dev *indio_dev = pf->indio_dev; in rtq6056_buffer_trigger_handler()
633 const struct richtek_dev_data *devdata = priv->devdata; in rtq6056_buffer_trigger_handler()
634 struct device *dev = priv->dev; in rtq6056_buffer_trigger_handler()
640 int i = 0, bit, ret; in rtq6056_buffer_trigger_handler()
642 memset(&data, 0, sizeof(data)); in rtq6056_buffer_trigger_handler()
649 ret = regmap_read(priv->regmap, addr, &raw); in rtq6056_buffer_trigger_handler()
654 raw >>= devdata->vbus_offset; in rtq6056_buffer_trigger_handler()
665 iio_trigger_notify_done(indio_dev->trig); in rtq6056_buffer_trigger_handler()
675 regmap_field_write(priv->rm_fields[F_OPMODE], 0); in rtq6056_enter_shutdown_state()
713 struct device *dev = &i2c->dev; in rtq6056_probe()
719 if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_WORD_DATA)) in rtq6056_probe()
720 return -EOPNOTSUPP; in rtq6056_probe()
724 return dev_err_probe(dev, -EINVAL, "Invalid dev data\n"); in rtq6056_probe()
728 return -ENOMEM; in rtq6056_probe()
731 priv->dev = dev; in rtq6056_probe()
732 priv->vshuntct_us = priv->vbusct_us = devdata->default_conv_time_us; in rtq6056_probe()
733 priv->avg_sample = 1; in rtq6056_probe()
734 priv->devdata = devdata; in rtq6056_probe()
742 priv->regmap = regmap; in rtq6056_probe()
750 return dev_err_probe(dev, -ENODEV, in rtq6056_probe()
751 "Invalid vendor id 0x%04x\n", vendor_id); in rtq6056_probe()
753 ret = devm_regmap_field_bulk_alloc(dev, regmap, priv->rm_fields, in rtq6056_probe()
754 devdata->reg_fields, F_MAX_FIELDS); in rtq6056_probe()
758 ret = regmap_write(regmap, RTQ6056_REG_CONFIG, devdata->default_config); in rtq6056_probe()
775 /* By default, use 2000 micro-Ohm resistor */ in rtq6056_probe()
777 device_property_read_u32(dev, "shunt-resistor-micro-ohms", in rtq6056_probe()
785 indio_dev->name = "rtq6056"; in rtq6056_probe()
786 indio_dev->modes = INDIO_DIRECT_MODE; in rtq6056_probe()
787 indio_dev->channels = devdata->channels; in rtq6056_probe()
788 indio_dev->num_channels = devdata->num_channels; in rtq6056_probe()
789 indio_dev->info = &rtq6056_info; in rtq6056_probe()
806 return regmap_field_write(priv->rm_fields[F_OPMODE], 0); in rtq6056_runtime_suspend()
814 ret = regmap_field_write(priv->rm_fields[F_OPMODE], RTQ6056_CONT_ALLON); in rtq6056_runtime_resume()
818 sample_rdy_time_us = priv->vbusct_us + priv->vshuntct_us; in rtq6056_runtime_resume()
819 sample_rdy_time_us *= priv->avg_sample; in rtq6056_runtime_resume()
823 return 0; in rtq6056_runtime_resume()