--- zzzz-none-000/linux-3.10.107/drivers/iio/dac/max517.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/iio/dac/max517.c 2021-02-04 17:41:59.000000000 +0000 @@ -19,7 +19,6 @@ */ #include -#include #include #include #include @@ -40,11 +39,13 @@ ID_MAX517, ID_MAX518, ID_MAX519, + ID_MAX520, + ID_MAX521, }; struct max517_data { struct i2c_client *client; - unsigned short vref_mv[2]; + unsigned short vref_mv[8]; }; /* @@ -82,15 +83,13 @@ long m) { struct max517_data *data = iio_priv(indio_dev); - unsigned int scale_uv; switch (m) { case IIO_CHAN_INFO_SCALE: /* Corresponds to Vref / 2^(bits) */ - scale_uv = (data->vref_mv[chan->channel] * 1000) >> 8; - *val = scale_uv / 1000000; - *val2 = scale_uv % 1000000; - return IIO_VAL_INT_PLUS_MICRO; + *val = data->vref_mv[chan->channel]; + *val2 = 8; + return IIO_VAL_FRACTIONAL_LOG2; default: break; } @@ -148,12 +147,17 @@ .channel = (chan), \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ BIT(IIO_CHAN_INFO_SCALE), \ - .scan_type = IIO_ST('u', 8, 8, 0), \ } static const struct iio_chan_spec max517_channels[] = { MAX517_CHANNEL(0), - MAX517_CHANNEL(1) + MAX517_CHANNEL(1), + MAX517_CHANNEL(2), + MAX517_CHANNEL(3), + MAX517_CHANNEL(4), + MAX517_CHANNEL(5), + MAX517_CHANNEL(6), + MAX517_CHANNEL(7), }; static int max517_probe(struct i2c_client *client, @@ -162,13 +166,11 @@ struct max517_data *data; struct iio_dev *indio_dev; struct max517_platform_data *platform_data = client->dev.platform_data; - int err; + int chan; - indio_dev = iio_device_alloc(sizeof(*data)); - if (indio_dev == NULL) { - err = -ENOMEM; - goto exit; - } + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); + if (!indio_dev) + return -ENOMEM; data = iio_priv(indio_dev); i2c_set_clientdata(client, indio_dev); data->client = client; @@ -176,11 +178,21 @@ /* establish that the iio_dev is a child of the i2c device */ indio_dev->dev.parent = &client->dev; - /* reduced channel set for MAX517 */ - if (id->driver_data == ID_MAX517) - indio_dev->num_channels = 1; - else + switch (id->driver_data) { + case ID_MAX521: + indio_dev->num_channels = 8; + break; + case ID_MAX520: + indio_dev->num_channels = 4; + break; + case ID_MAX519: + case ID_MAX518: indio_dev->num_channels = 2; + break; + default: /* single channel for MAX517 */ + indio_dev->num_channels = 1; + break; + } indio_dev->channels = max517_channels; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->info = &max517_info; @@ -189,32 +201,19 @@ * Reference voltage on MAX518 and default is 5V, else take vref_mv * from platform_data */ - if (id->driver_data == ID_MAX518 || !platform_data) { - data->vref_mv[0] = data->vref_mv[1] = 5000; /* mV */ - } else { - data->vref_mv[0] = platform_data->vref_mv[0]; - data->vref_mv[1] = platform_data->vref_mv[1]; + for (chan = 0; chan < indio_dev->num_channels; chan++) { + if (id->driver_data == ID_MAX518 || !platform_data) + data->vref_mv[chan] = 5000; /* mV */ + else + data->vref_mv[chan] = platform_data->vref_mv[chan]; } - err = iio_device_register(indio_dev); - if (err) - goto exit_free_device; - - dev_info(&client->dev, "DAC registered\n"); - - return 0; - -exit_free_device: - iio_device_free(indio_dev); -exit: - return err; + return iio_device_register(indio_dev); } static int max517_remove(struct i2c_client *client) { iio_device_unregister(i2c_get_clientdata(client)); - iio_device_free(i2c_get_clientdata(client)); - return 0; } @@ -222,6 +221,8 @@ { "max517", ID_MAX517 }, { "max518", ID_MAX518 }, { "max519", ID_MAX519 }, + { "max520", ID_MAX520 }, + { "max521", ID_MAX521 }, { } }; MODULE_DEVICE_TABLE(i2c, max517_id); @@ -238,5 +239,5 @@ module_i2c_driver(max517_driver); MODULE_AUTHOR("Roland Stigge "); -MODULE_DESCRIPTION("MAX517/MAX518/MAX519 8-bit DAC"); +MODULE_DESCRIPTION("MAX517/518/519/520/521 8-bit DAC"); MODULE_LICENSE("GPL");