/* * Channel number definitions for the two channels of the device * - IN Current (INC) * - IN Voltage (INV)
*/ #define TI_LMP92064_CHAN_INC 0 #define TI_LMP92064_CHAN_INV 1
/* * The ADC only latches in new samples if all DATA registers are read * in descending sequential order. * The ADC auto-decrements the register index with each clocked byte. * Read both channels in single SPI transfer by selecting the highest * register using the command below and clocking out all four data * bytes.
*/
ret = regmap_bulk_read(priv->regmap, TI_LMP92064_REG_DATA_COUT_MSB,
&raw, sizeof(raw));
if (gpio_reset) { /* * Perform a hard reset if gpio_reset is available. * The datasheet specifies a very low 3.5ns reset pulse duration and does not * specify how long to wait after a reset to access the device. * Use more conservative pulse lengths to allow analog RC filtering of the * reset line at the board level (as recommended in the datasheet).
*/
gpiod_set_value_cansleep(gpio_reset, 1);
usleep_range(1, 10);
gpiod_set_value_cansleep(gpio_reset, 0);
usleep_range(500, 750);
} else { /* * Perform a soft-reset if not. * Also write default values to the config registers that are not * affected by soft reset.
*/
ret = regmap_write(priv->regmap, TI_LMP92064_REG_CONFIG_A,
TI_LMP92064_VAL_CONFIG_A); if (ret < 0) return ret;
ret = regmap_write(priv->regmap, TI_LMP92064_REG_CONFIG_B,
TI_LMP92064_VAL_CONFIG_B); if (ret < 0) return ret;
}
/* * Wait for the device to signal readiness to prevent reading bogus data * and make sure device is actually connected. * The datasheet does not specify how long this takes but usually it is * not more than 3-4 iterations of this loop.
*/ for (i = 0; i < 10; i++) {
ret = regmap_read(priv->regmap, TI_LMP92064_REG_STATUS, &status); if (ret < 0) return ret;
if (status == TI_LMP92064_VAL_STATUS_OK) return 0;
usleep_range(1000, 2000);
}
/* * No (correct) response received. * Device is mostly likely not connected to the bus.
*/ return -ENXIO;
}
ret = spi_setup(spi); if (ret < 0) return dev_err_probe(dev, ret, "Error in SPI setup\n");
regmap = devm_regmap_init_spi(spi, &lmp92064_spi_regmap_config); if (IS_ERR(regmap)) return dev_err_probe(dev, PTR_ERR(regmap), "Failed to set up SPI regmap\n");
indio_dev = devm_iio_device_alloc(dev, sizeof(*priv)); if (!indio_dev) return -ENOMEM;
priv = iio_priv(indio_dev);
priv->spi = spi;
priv->regmap = regmap;
ret = device_property_read_u32(dev, "shunt-resistor-micro-ohms",
&shunt_resistor_uohm); if (ret < 0) return dev_err_probe(dev, ret, "Failed to get shunt-resistor value\n");
/* * The shunt resistance is passed to userspace as the denominator of an iio * fraction. Make sure it is in range for that.
*/ if (shunt_resistor_uohm == 0 || shunt_resistor_uohm > INT_MAX) {
dev_err(dev, "Shunt resistance is out of range\n"); return -EINVAL;
}
priv->shunt_resistor_uohm = shunt_resistor_uohm;
ret = devm_regulator_get_enable(dev, "vdd"); if (ret) return ret;
ret = devm_regulator_get_enable(dev, "vdig"); if (ret) return ret;
gpio_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); if (IS_ERR(gpio_reset)) return dev_err_probe(dev, PTR_ERR(gpio_reset), "Failed to get GPIO reset pin\n");
ret = lmp92064_reset(priv, gpio_reset); if (ret < 0) return dev_err_probe(dev, ret, "Failed to reset device\n");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.