Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 39 additions & 24 deletions drivers/iio/dac/ad5064.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LTC2617, LTC2619, LTC2626, LTC2627, LTC2629, LTC2631, LTC2633, LTC2635
* Digital to analog converters driver
*
* Copyright 2011, 2014 Analog Devices Inc.
* Copyright 2011 Analog Devices Inc.
*
* Licensed under the GPL-2.
*/
Expand All @@ -24,8 +24,6 @@
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>

#include <linux/platform_data/ad5064.h>

#define AD5064_MAX_DAC_CHANNELS 8
#define AD5064_MAX_VREFS 4

Expand Down Expand Up @@ -811,10 +809,43 @@ static int ad5064_set_config(struct ad5064_state *st, unsigned int val)
return ad5064_write(st, cmd, 0, val, 0);
}

static int ad5064_request_vref(struct ad5064_state *st, struct device *dev)
{
unsigned int i;
int ret;

for (i = 0; i < ad5064_num_vref(st); ++i)
st->vref_reg[i].supply = ad5064_vref_name(st, i);

if (!st->chip_info->internal_vref)
return devm_regulator_bulk_get(dev, ad5064_num_vref(st),
st->vref_reg);

/*
* This assumes that when the regulator has an internal VREF
* there is only one external VREF connection, which is
* currently the case for all supported devices.
*/
st->vref_reg[0].consumer = devm_regulator_get_optional(dev, "vref");
if (!IS_ERR(st->vref_reg[0].consumer))
return 0;

ret = PTR_ERR(st->vref_reg[0].consumer);
if (ret != -ENODEV)
return ret;

/* If no external regulator was supplied use the internal VREF */
st->use_internal_vref = true;
ret = ad5064_set_config(st, AD5064_CONFIG_INT_VREF_ENABLE);
if (ret)
dev_err(dev, "Failed to enable internal vref: %d\n", ret);

return ret;
}

static int ad5064_probe(struct device *dev, enum ad5064_type type,
const char *name, ad5064_write_func write)
{
struct ad5064_platform_data *pdata = dev->platform_data;
struct iio_dev *indio_dev;
struct ad5064_state *st;
unsigned int midscale;
Expand All @@ -832,30 +863,14 @@ static int ad5064_probe(struct device *dev, enum ad5064_type type,
st->dev = dev;
st->write = write;

for (i = 0; i < ad5064_num_vref(st); ++i)
st->vref_reg[i].supply = ad5064_vref_name(st, i);
ret = ad5064_request_vref(st, dev);
if (ret)
return ret;

if (pdata && pdata->use_external_ref) {
ret = devm_regulator_bulk_get(dev, ad5064_num_vref(st),
st->vref_reg);
if (ret)
return ret;
if (!st->use_internal_vref) {
ret = regulator_bulk_enable(ad5064_num_vref(st), st->vref_reg);
if (ret)
return ret;
} else {
if (!st->chip_info->internal_vref) {
dev_err(dev, "No vref available\n");
return -ENXIO;
}

st->use_internal_vref = true;
ret = ad5064_set_config(st, AD5064_CONFIG_INT_VREF_ENABLE);
if (ret) {
dev_err(dev, "Failed to enable internal vref: %d\n",
ret);
return ret;
}
}

indio_dev->dev.parent = dev;
Expand Down
21 changes: 0 additions & 21 deletions include/linux/platform_data/ad5064.h

This file was deleted.