--- zzzz-none-000/linux-3.10.107/drivers/iio/dac/ad5764.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/iio/dac/ad5764.c 2021-02-04 17:41:59.000000000 +0000 @@ -83,7 +83,12 @@ BIT(IIO_CHAN_INFO_CALIBSCALE) | \ BIT(IIO_CHAN_INFO_CALIBBIAS), \ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET), \ - .scan_type = IIO_ST('u', (_bits), 16, 16 - (_bits)) \ + .scan_type = { \ + .sign = 'u', \ + .realbits = (_bits), \ + .storagebits = 16, \ + .shift = 16 - (_bits), \ + }, \ } #define DECLARE_AD5764_CHANNELS(_name, _bits) \ @@ -217,7 +222,6 @@ struct iio_chan_spec const *chan, int *val, int *val2, long info) { struct ad5764_state *st = iio_priv(indio_dev); - unsigned long scale_uv; unsigned int reg; int vref; int ret; @@ -245,15 +249,14 @@ *val = sign_extend32(*val, 5); return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: - /* vout = 4 * vref + ((dac_code / 65535) - 0.5) */ + /* vout = 4 * vref + ((dac_code / 65536) - 0.5) */ vref = ad5764_get_channel_vref(st, chan->channel); if (vref < 0) return vref; - scale_uv = (vref * 4 * 100) >> chan->scan_type.realbits; - *val = scale_uv / 100000; - *val2 = (scale_uv % 100000) * 10; - return IIO_VAL_INT_PLUS_MICRO; + *val = vref * 4 / 1000; + *val2 = chan->scan_type.realbits; + return IIO_VAL_FRACTIONAL_LOG2; case IIO_CHAN_INFO_OFFSET: *val = -(1 << chan->scan_type.realbits) / 2; return IIO_VAL_INT; @@ -275,7 +278,7 @@ struct ad5764_state *st; int ret; - indio_dev = iio_device_alloc(sizeof(*st)); + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); if (indio_dev == NULL) { dev_err(&spi->dev, "Failed to allocate iio device\n"); return -ENOMEM; @@ -298,12 +301,12 @@ st->vref_reg[0].supply = "vrefAB"; st->vref_reg[1].supply = "vrefCD"; - ret = regulator_bulk_get(&st->spi->dev, + ret = devm_regulator_bulk_get(&st->spi->dev, ARRAY_SIZE(st->vref_reg), st->vref_reg); if (ret) { dev_err(&spi->dev, "Failed to request vref regulators: %d\n", ret); - goto error_free; + return ret; } ret = regulator_bulk_enable(ARRAY_SIZE(st->vref_reg), @@ -311,7 +314,7 @@ if (ret) { dev_err(&spi->dev, "Failed to enable vref regulators: %d\n", ret); - goto error_free_reg; + return ret; } } @@ -326,12 +329,6 @@ error_disable_reg: if (st->chip_info->int_vref == 0) regulator_bulk_disable(ARRAY_SIZE(st->vref_reg), st->vref_reg); -error_free_reg: - if (st->chip_info->int_vref == 0) - regulator_bulk_free(ARRAY_SIZE(st->vref_reg), st->vref_reg); -error_free: - iio_device_free(indio_dev); - return ret; } @@ -342,12 +339,8 @@ iio_device_unregister(indio_dev); - if (st->chip_info->int_vref == 0) { + if (st->chip_info->int_vref == 0) regulator_bulk_disable(ARRAY_SIZE(st->vref_reg), st->vref_reg); - regulator_bulk_free(ARRAY_SIZE(st->vref_reg), st->vref_reg); - } - - iio_device_free(indio_dev); return 0; } @@ -364,7 +357,6 @@ static struct spi_driver ad5764_driver = { .driver = { .name = "ad5764", - .owner = THIS_MODULE, }, .probe = ad5764_probe, .remove = ad5764_remove,