Skip to content

Commit

Permalink
iio: adc: cf_axi_adc: use common fpga AXI reg defs
Browse files Browse the repository at this point in the history
The ADI AXI common register definitions have been added in
`include/linux/fpga/adi-axi-common.h` some time ago. Some small parts have
also been upstreamed.

This change makes use of these definitions for all AXI ADC code (except the
cf_axi_tdd driver).

Signed-off-by: Alexandru Ardelean <[email protected]>
  • Loading branch information
commodo committed Jul 3, 2019
1 parent 7f9f60f commit 342823f
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 53 deletions.
18 changes: 9 additions & 9 deletions drivers/iio/adc/ad9361_conv.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,15 +344,15 @@ int ad9361_hdl_loopback(struct ad9361_rf_phy *phy, bool enable)
version = axiadc_read(st, 0x4000);

/* Still there but implemented a bit different */
if (PCORE_VERSION_MAJOR(version) > 7)
if (ADI_AXI_PCORE_VER_MAJOR(version) > 7)
addr = 0x4418;
else
addr = 0x4414;

for (chan = 0; chan < conv->chip_info->num_channels; chan++) {
reg = axiadc_read(st, addr + (chan) * 0x40);

if (PCORE_VERSION_MAJOR(version) > 7) {
if (ADI_AXI_PCORE_VER_MAJOR(version) > 7) {
if (enable && reg != 0x8) {
conv->scratch_reg[chan] = reg;
reg = 0x8;
Expand All @@ -377,7 +377,7 @@ static int ad9361_iodelay_set(struct axiadc_state *st, unsigned lane,
unsigned val, bool tx)
{
if (tx) {
if (PCORE_VERSION_MAJOR(st->pcore_version) > 8)
if (ADI_AXI_PCORE_VER_MAJOR(st->pcore_version) > 8)
axiadc_write(st, 0x4000 + ADI_REG_DELAY(lane), val);
else
return -ENODEV;
Expand Down Expand Up @@ -563,7 +563,7 @@ static int ad9361_dig_tune_tx(struct ad9361_rf_phy *phy, unsigned long max_freq,
ADI_ENABLE | ADI_IQCOR_ENB);
axiadc_set_pnsel(st, chan, ADC_PN_CUSTOM);
saved_chan_ctrl6[chan] = axiadc_read(st, 0x4414 + (chan) * 0x40);
if (PCORE_VERSION_MAJOR(hdl_dac_version) > 7) {
if (ADI_AXI_PCORE_VER_MAJOR(hdl_dac_version) > 7) {
saved_dsel[chan] = axiadc_read(st, 0x4418 + (chan) * 0x40);
axiadc_write(st, 0x4418 + (chan) * 0x40, 9);
axiadc_write(st, 0x4414 + (chan) * 0x40, 0); /* !IQCOR_ENB */
Expand All @@ -572,7 +572,7 @@ static int ad9361_dig_tune_tx(struct ad9361_rf_phy *phy, unsigned long max_freq,
axiadc_write(st, 0x4414 + (chan) * 0x40, 1); /* DAC_PN_ENB */
}
}
if (PCORE_VERSION_MAJOR(hdl_dac_version) < 8) {
if (ADI_AXI_PCORE_VER_MAJOR(hdl_dac_version) < 8) {
saved = tmp = axiadc_read(st, 0x4048);
tmp &= ~0xF;
tmp |= 1;
Expand All @@ -583,14 +583,14 @@ static int ad9361_dig_tune_tx(struct ad9361_rf_phy *phy, unsigned long max_freq,
if (flags & DO_ODELAY)
ad9361_dig_tune_iodelay(phy, true);

if (PCORE_VERSION_MAJOR(hdl_dac_version) < 8)
if (ADI_AXI_PCORE_VER_MAJOR(hdl_dac_version) < 8)
axiadc_write(st, 0x4048, saved);

for (chan = 0; chan < num_chan; chan++) {
axiadc_write(st, ADI_REG_CHAN_CNTRL(chan),
saved_chan_ctrl0[chan]);
axiadc_set_pnsel(st, chan, ADC_PN9);
if (PCORE_VERSION_MAJOR(hdl_dac_version) > 7) {
if (ADI_AXI_PCORE_VER_MAJOR(hdl_dac_version) > 7) {
axiadc_write(st, 0x4418 + chan * 0x40,
saved_dsel[chan]);
axiadc_write(st, 0x4044, 1);
Expand Down Expand Up @@ -709,13 +709,13 @@ static int ad9361_post_setup(struct iio_dev *indio_dev)

flags = 0;

ret = ad9361_dig_tune(phy, (axiadc_read(st, ADI_REG_ID)) ?
ret = ad9361_dig_tune(phy, (axiadc_read(st, ADI_AXI_REG_ID)) ?
0 : 61440000, flags);
if (ret < 0)
goto error;

if (flags & (DO_IDELAY | DO_ODELAY)) {
ret = ad9361_dig_tune(phy, (axiadc_read(st, ADI_REG_ID)) ?
ret = ad9361_dig_tune(phy, (axiadc_read(st, ADI_AXI_REG_ID)) ?
0 : 61440000, flags & BE_VERBOSE);
if (ret < 0)
goto error;
Expand Down
4 changes: 2 additions & 2 deletions drivers/iio/adc/ad9371_conv.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ int ad9371_hdl_loopback(struct ad9371_rf_phy *phy, bool enable)
version = axiadc_read(st, 0x4000);

/* Still there but implemented a bit different */
if (PCORE_VERSION_MAJOR(version) > 7)
if (ADI_AXI_PCORE_VER_MAJOR(version) > 7)
addr = 0x4418;
else
addr = 0x4414;

for (chan = 0; chan < conv->chip_info->num_channels; chan++) {
reg = axiadc_read(st, addr + (chan) * 0x40);

if (PCORE_VERSION_MAJOR(version) > 7) {
if (ADI_AXI_PCORE_VER_MAJOR(version) > 7) {
if (enable && reg != 0x8) {
conv->scratch_reg[chan] = reg;
reg = 0x8;
Expand Down
2 changes: 1 addition & 1 deletion drivers/iio/adc/ad_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ static int adc_probe(struct platform_device *pdev)
adc_write(st, ADI_REG_RSTN, 0);
adc_write(st, ADI_REG_RSTN, ADI_RSTN);

st->pcore_version = adc_read(st, ADI_REG_VERSION);
st->pcore_version = adc_read(st, ADI_AXI_REG_VERSION);

if (info->has_frontend) {
st->frontend = iio_hw_consumer_alloc(&pdev->dev);
Expand Down
4 changes: 2 additions & 2 deletions drivers/iio/adc/admc_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static int axiadc_probe(struct platform_device *pdev)
axiadc_write(st, ADI_REG_RSTN, 0);
axiadc_write(st, ADI_REG_RSTN, ADI_RSTN);

st->pcore_version = axiadc_read(st, ADI_REG_VERSION);
st->pcore_version = axiadc_read(st, ADI_AXI_REG_VERSION);

indio_dev->dev.parent = &pdev->dev;
indio_dev->name = pdev->dev.of_node->name;
Expand All @@ -148,7 +148,7 @@ static int axiadc_probe(struct platform_device *pdev)
dev_info(&pdev->dev, "ADI AIM (0x%X) at 0x%08llX mapped to 0x%p, probed ADC %s as %s\n",
st->pcore_version,
(unsigned long long)mem->start, st->regs, chip_info->name,
axiadc_read(st, ADI_REG_ID) ? "SLAVE" : "MASTER");
axiadc_read(st, ADI_AXI_REG_ID) ? "SLAVE" : "MASTER");

return 0;

Expand Down
2 changes: 1 addition & 1 deletion drivers/iio/adc/admc_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ static int mc_ctrl_probe(struct platform_device *pdev)
mc_ctrl_write(st, ADI_REG_RSTN, 0);
mc_ctrl_write(st, ADI_REG_RSTN, ADI_RSTN);

st->pcore_version = axiadc_read(st, ADI_REG_VERSION);
st->pcore_version = axiadc_read(st, ADI_AXI_REG_ID);

ret = iio_device_register(indio_dev);

Expand Down
4 changes: 2 additions & 2 deletions drivers/iio/adc/admc_speed.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ static int axiadc_probe(struct platform_device *pdev)
axiadc_write(st, ADI_REG_RSTN, 0);
axiadc_write(st, ADI_REG_RSTN, ADI_RSTN);

st->pcore_version = axiadc_read(st, ADI_REG_VERSION);
st->pcore_version = axiadc_read(st, ADI_AXI_REG_VERSION);

indio_dev->dev.parent = &pdev->dev;
indio_dev->name = pdev->dev.of_node->name;
Expand All @@ -143,7 +143,7 @@ static int axiadc_probe(struct platform_device *pdev)

dev_info(&pdev->dev, "ADI AIM (0x%X) at 0x%08llX mapped to 0x%p, probed ADC %s as %s\n",
st->pcore_version, (unsigned long long)mem->start, st->regs,
chip_info->name, axiadc_read(st, ADI_REG_ID) ? "SLAVE" : "MASTER");
chip_info->name, axiadc_read(st, ADI_AXI_REG_ID) ? "SLAVE" : "MASTER");

return 0;

Expand Down
4 changes: 2 additions & 2 deletions drivers/iio/adc/adrv9009_conv.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ int adrv9009_hdl_loopback(struct adrv9009_rf_phy *phy, bool enable)
version = axiadc_read(st, 0x4000);

/* Still there but implemented a bit different */
if (PCORE_VERSION_MAJOR(version) > 7)
if (ADI_AXI_PCORE_VER_MAJOR(version) > 7)
addr = 0x4418;
else
addr = 0x4414;

for (chan = 0; chan < conv->chip_info->num_channels; chan++) {
reg = axiadc_read(st, addr + (chan) * 0x40);

if (PCORE_VERSION_MAJOR(version) > 7) {
if (ADI_AXI_PCORE_VER_MAJOR(version) > 7) {
if (enable && reg != 0x8) {
conv->scratch_reg[chan] = reg;
reg = 0x8;
Expand Down
15 changes: 2 additions & 13 deletions drivers/iio/adc/cf_axi_adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,7 @@
#ifndef ADI_AXI_ADC_H_
#define ADI_AXI_ADC_H_

#define ADI_REG_VERSION 0x0000 /*Version and Scratch Registers */
#define ADI_VERSION(x) (((x) & 0xffffffff) << 0) /* RO, Version number. */
#define VERSION_IS(x,y,z) ((x) << 16 | (y) << 8 | (z))
#define ADI_REG_ID 0x0004 /*Version and Scratch Registers */
#define ADI_ID(x) (((x) & 0xffffffff) << 0) /* RO, Instance identifier number. */
#define ADI_REG_SCRATCH 0x0008 /*Version and Scratch Registers */
#define ADI_SCRATCH(x) (((x) & 0xffffffff) << 0) /* RW, Scratch register. */

#define PCORE_VERSION(major, minor, letter) ((major << 16) | (minor << 8) | letter)
#define PCORE_VERSION_MAJOR(version) (version >> 16)
#define PCORE_VERSION_MINOR(version) ((version >> 8) & 0xff)
#define PCORE_VERSION_LETTER(version) (version & 0xff)
#include <linux/fpga/adi-axi-common.h>

/* ADC COMMON */

Expand Down Expand Up @@ -337,7 +326,7 @@ static inline unsigned int axiadc_slave_read(struct axiadc_state *st, unsigned r
static inline void axiadc_idelay_set(struct axiadc_state *st,
unsigned lane, unsigned val)
{
if (PCORE_VERSION_MAJOR(st->pcore_version) > 8) {
if (ADI_AXI_PCORE_VER_MAJOR(st->pcore_version) > 8) {
axiadc_write(st, ADI_REG_DELAY(lane), val);
} else {
axiadc_write(st, ADI_REG_DELAY_CNTRL, 0);
Expand Down
42 changes: 21 additions & 21 deletions drivers/iio/adc/cf_axi_adc_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int axiadc_set_pnsel(struct axiadc_state *st, int channel, enum adc_pn_sel sel)
{
unsigned reg;

if (PCORE_VERSION_MAJOR(st->pcore_version) > 7) {
if (ADI_AXI_PCORE_VER_MAJOR(st->pcore_version) > 7) {
reg = axiadc_read(st, ADI_REG_CHAN_CNTRL_3(channel));
reg &= ~ADI_ADC_PN_SEL(~0);
reg |= ADI_ADC_PN_SEL(sel);
Expand Down Expand Up @@ -78,7 +78,7 @@ enum adc_pn_sel axiadc_get_pnsel(struct axiadc_state *st,
{
unsigned val;

if (PCORE_VERSION_MAJOR(st->pcore_version) > 7) {
if (ADI_AXI_PCORE_VER_MAJOR(st->pcore_version) > 7) {
const char *ident[] = {"PN9", "PN23A", "UNDEF", "UNDEF",
"PN7", "PN15", "PN23", "PN31", "UNDEF", "PN_CUSTOM"};

Expand Down Expand Up @@ -686,19 +686,19 @@ static int axiadc_attach_spi_client(struct device *dev, void *data)
}

static const struct axiadc_core_info ad9467_core_1_00_a_info = {
.version = PCORE_VERSION(10, 0, 'a'),
.version = ADI_AXI_PCORE_VER(10, 0, 'a'),
};

static const struct axiadc_core_info ad9361_6_00_a_info = {
.version = PCORE_VERSION(10, 0, 'a'),
.version = ADI_AXI_PCORE_VER(10, 0, 'a'),
};

static const struct axiadc_core_info ad9643_6_00_a_info = {
.version = PCORE_VERSION(10, 0, 'a'),
.version = ADI_AXI_PCORE_VER(10, 0, 'a'),
};

static const struct axiadc_core_info ad9680_6_00_a_info = {
.version = PCORE_VERSION(10, 0, 'a'),
.version = ADI_AXI_PCORE_VER(10, 0, 'a'),
};

/* Match table for of_platform binding */
Expand Down Expand Up @@ -820,17 +820,17 @@ static int axiadc_probe(struct platform_device *pdev)
mdelay(10);
axiadc_write(st, ADI_REG_RSTN, ADI_RSTN | ADI_MMCM_RSTN);

st->pcore_version = axiadc_read(st, ADI_REG_VERSION);
st->pcore_version = axiadc_read(st, ADI_AXI_REG_VERSION);

if (PCORE_VERSION_MAJOR(st->pcore_version) >
PCORE_VERSION_MAJOR(info->version)) {
if (ADI_AXI_PCORE_VER_MAJOR(st->pcore_version) >
ADI_AXI_PCORE_VER_MAJOR(info->version)) {
dev_err(&pdev->dev, "Major version mismatch between PCORE and driver. Driver expected %d.%.2d.%c, PCORE reported %d.%.2d.%c\n",
PCORE_VERSION_MAJOR(info->version),
PCORE_VERSION_MINOR(info->version),
PCORE_VERSION_LETTER(info->version),
PCORE_VERSION_MAJOR(st->pcore_version),
PCORE_VERSION_MINOR(st->pcore_version),
PCORE_VERSION_LETTER(st->pcore_version));
ADI_AXI_PCORE_VER_MAJOR(info->version),
ADI_AXI_PCORE_VER_MINOR(info->version),
ADI_AXI_PCORE_VER_PATCH(info->version),
ADI_AXI_PCORE_VER_MAJOR(st->pcore_version),
ADI_AXI_PCORE_VER_MINOR(st->pcore_version),
ADI_AXI_PCORE_VER_PATCH(st->pcore_version));
ret = -ENODEV;
goto err_put_converter;
}
Expand All @@ -853,7 +853,7 @@ static int axiadc_probe(struct platform_device *pdev)
goto err_put_converter;
}

if (!st->dp_disable && !axiadc_read(st, ADI_REG_ID) &&
if (!st->dp_disable && !axiadc_read(st, ADI_AXI_REG_ID) &&
of_find_property(pdev->dev.of_node, "dmas", NULL)) {
ret = axiadc_configure_ring_stream(indio_dev, NULL);
if (ret < 0)
Expand All @@ -872,12 +872,12 @@ static int axiadc_probe(struct platform_device *pdev)

dev_info(&pdev->dev, "ADI AIM (%d.%.2d.%c) at 0x%08llX mapped to 0x%p,"
" probed ADC %s as %s\n",
PCORE_VERSION_MAJOR(st->pcore_version),
PCORE_VERSION_MINOR(st->pcore_version),
PCORE_VERSION_LETTER(st->pcore_version),
ADI_AXI_PCORE_VER_MAJOR(st->pcore_version),
ADI_AXI_PCORE_VER_MINOR(st->pcore_version),
ADI_AXI_PCORE_VER_PATCH(st->pcore_version),
(unsigned long long)mem->start, st->regs,
conv->chip_info->name,
axiadc_read(st, ADI_REG_ID) ? "SLAVE" : "MASTER");
axiadc_read(st, ADI_AXI_REG_ID) ? "SLAVE" : "MASTER");

if (iio_get_debugfs_dentry(indio_dev))
debugfs_create_file("pseudorandom_err_check", 0644,
Expand Down Expand Up @@ -917,7 +917,7 @@ static int axiadc_remove(struct platform_device *pdev)
struct axiadc_state *st = iio_priv(indio_dev);

iio_device_unregister(indio_dev);
if (!st->dp_disable && !axiadc_read(st, ADI_REG_ID) &&
if (!st->dp_disable && !axiadc_read(st, ADI_AXI_REG_ID) &&
of_find_property(pdev->dev.of_node, "dmas", NULL))
axiadc_unconfigure_ring_stream(indio_dev);

Expand Down

0 comments on commit 342823f

Please sign in to comment.