--- zzzz-none-000/linux-3.10.107/drivers/iio/adc/ad7791.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/iio/adc/ad7791.c 2021-02-04 17:41:59.000000000 +0000 @@ -202,7 +202,6 @@ { struct ad7791_state *st = iio_priv(indio_dev); bool unipolar = !!(st->mode & AD7791_MODE_UNIPOLAR); - unsigned long long scale_pv; switch (info) { case IIO_CHAN_INFO_RAW: @@ -220,23 +219,26 @@ case IIO_CHAN_INFO_SCALE: /* The monitor channel uses an internal reference. */ if (chan->address == AD7791_CH_AVDD_MONITOR) { - scale_pv = 5850000000000ULL; + /* + * The signal is attenuated by a factor of 5 and + * compared against a 1.17V internal reference. + */ + *val = 1170 * 5; } else { int voltage_uv; voltage_uv = regulator_get_voltage(st->reg); if (voltage_uv < 0) return voltage_uv; - scale_pv = (unsigned long long)voltage_uv * 1000000; + + *val = voltage_uv / 1000; } if (unipolar) - scale_pv >>= chan->scan_type.realbits; + *val2 = chan->scan_type.realbits; else - scale_pv >>= chan->scan_type.realbits - 1; - *val2 = do_div(scale_pv, 1000000000); - *val = scale_pv; + *val2 = chan->scan_type.realbits - 1; - return IIO_VAL_INT_PLUS_NANO; + return IIO_VAL_FRACTIONAL_LOG2; } return -EINVAL; @@ -361,21 +363,19 @@ return -ENXIO; } - indio_dev = iio_device_alloc(sizeof(*st)); + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); if (!indio_dev) return -ENOMEM; st = iio_priv(indio_dev); - st->reg = regulator_get(&spi->dev, "refin"); - if (IS_ERR(st->reg)) { - ret = PTR_ERR(st->reg); - goto err_iio_free; - } + st->reg = devm_regulator_get(&spi->dev, "refin"); + if (IS_ERR(st->reg)) + return PTR_ERR(st->reg); ret = regulator_enable(st->reg); if (ret) - goto error_put_reg; + return ret; st->info = &ad7791_chip_infos[spi_get_device_id(spi)->driver_data]; ad_sd_init(&st->sd, indio_dev, spi, &ad7791_sigma_delta_info); @@ -410,10 +410,6 @@ ad_sd_cleanup_buffer_and_trigger(indio_dev); error_disable_reg: regulator_disable(st->reg); -error_put_reg: - regulator_put(st->reg); -err_iio_free: - iio_device_free(indio_dev); return ret; } @@ -427,9 +423,6 @@ ad_sd_cleanup_buffer_and_trigger(indio_dev); regulator_disable(st->reg); - regulator_put(st->reg); - - iio_device_free(indio_dev); return 0; } @@ -447,7 +440,6 @@ static struct spi_driver ad7791_driver = { .driver = { .name = "ad7791", - .owner = THIS_MODULE, }, .probe = ad7791_probe, .remove = ad7791_remove,