Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ad2s1210 fixes and updates #123

Merged
merged 8 commits into from
Jun 25, 2018
Merged

ad2s1210 fixes and updates #123

merged 8 commits into from
Jun 25, 2018

Conversation

dbogdan
Copy link
Contributor

@dbogdan dbogdan commented Jun 22, 2018

These changes make the driver usable on AD-FMCMOTCON2-EBZ.

@commodo
Copy link
Contributor

commodo commented Jun 22, 2018

checkpatch has a few pertinent complaints

@@ -15,7 +15,7 @@
#include <linux/slab.h>
#include <linux/sysfs.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/gpio/consumer.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll reference this commit f86b233 since that's where the initial comments were added.
No need to duplicate them here.

gpiod_set_value(st->pdata->a[0], ad2s1210_mode_vals[mode][0]);
gpiod_set_value(st->pdata->a[1], ad2s1210_mode_vals[mode][1]);
st->mode = mode;
if (st->mode != MOD_CONFIG_ONLY) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a nitpick; but another way to do it here is to exit early;
it minimizes the patch size;
so, it could be done as:

if (st->mode == MOD_CONFIG_ONLY)
    return;

return ad2s1210_resolution_value[
(gpiod_get_value(st->pdata->res[0]) << 1) |
gpiod_get_value(st->pdata->res[1])];
int res0 = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could exit early with

if (st->mode == MOD_CONFIG_ONLY)
    return ad2s1210_resolution_value[0];

int index;

if (st->mode != MOD_CONFIG_ONLY) {
index = (st->resolution - 10) / 2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i like the caching of the calculated value here;
so, i guess this could be left as is here [with respect to exiting early, it should be fine as is];

if (st->mode != MOD_CONFIG_ONLY)
ad2s1210_set_mode(MOD_POS, st);
else {
st->rx[0] = ad2s1210_config_read(st,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could assign a reg = AD2S1210_REG_POSITION here and reg = AD2S1210_REG_VELOCITY
and do below:

	if (st->mode != MOD_CONFIG_ONLY) {
		ret = spi_read(st->sdev, st->rx, 2);
		if (ret < 0)
			goto error_ret;
	} else {
			st->rx[0] = ad2s1210_config_read(st, reg);
			st->rx[1] = ad2s1210_config_read(st, reg + 1);
       }

@dbogdan
Copy link
Contributor Author

dbogdan commented Jun 22, 2018

My fault - it seems that if 2 commits are pushed, checkpatch is run only on the second one... I'll do the fixes.

@commodo
Copy link
Contributor

commodo commented Jun 22, 2018

A bit related to this series; should we merge the ad2s1210.h file/struct into the ad2s1210.c file ?
Do we want to keep supporting external platform data in this tree ?

@dbogdan
Copy link
Contributor Author

dbogdan commented Jun 22, 2018

This is a good question. @larsclausen ?

if (ret < 0)
return ret;

return st->rx[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am thinking if this can be done with a single spi_sync_transfer()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be for sure if an array of spi_transfers is used. Each xfer should be initialized in this case, so I decided to simply call spi_sync_transfer() twice.
I'm not really against any of these two options...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A advantage of a single transfer is that it will be locked. If you split it into two transfers other devices might squeeze their own transfers in between.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do the update.

@lclausen-adi
Copy link

@dbogdan Your choice

return NULL;

pdata->gpioin = of_property_read_bool(np,
"adi,gpios-input-direction-enable");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whenever you have a DT property that ends in a verb you've lost the game. The DT is descriptive not imperative.

Think "GPIOs are wired as inputs" and not "GPIOs should be configured as inputs".

@dbogdan dbogdan force-pushed the ad2s1210 branch 2 times, most recently from d012e80 to 72bfd03 Compare June 22, 2018 10:31
@dbogdan
Copy link
Contributor Author

dbogdan commented Jun 22, 2018

v2:

  • move GPIO decriptors from platform_data to state;
  • optimize ad2s1210_setup_gpios() and use gpiod_get_index();
  • exit earlier from the specific functions if MOD_CONFIG_ONLY is used;
  • optimize ad2s1210_read_raw();
  • rename dts attribute.

@dbogdan
Copy link
Contributor Author

dbogdan commented Jun 22, 2018

v3:

  • use an array of spi_transfers instead of calling spi_sync_transfer() twice.

Copy link
Contributor

@commodo commodo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Will merge Monday or Tuesday if no objections

No functional changes.

Signed-off-by: Dragos Bogdan <dragos.bogdan@analog.com>
According to AD2S1210 datasheet, if the serial interface is used, the
8-bit address should be latched using the rising edge of the WR/FSYNC
signal.

Signed-off-by: Dragos Bogdan <dragos.bogdan@analog.com>
Signed-off-by: Dragos Bogdan <dragos.bogdan@analog.com>
The descriptor-based GPIO interface is a safer alternative to the legacy
GPIO interface.

Signed-off-by: Dragos Bogdan <dragos.bogdan@analog.com>
The AD2S1210 can be operated entirely in configuration mode. In this
mode, the only required GPIO is SAMPLE.
The driver will enable MOD_CONFIG_ONLY when any of the other GPIOs is
missing.

AD-FMCMOTCON2-EBZ evaluation board is one example where AD2S1210 is used
in this mode.

Signed-off-by: Dragos Bogdan <dragos.bogdan@analog.com>
The AD2S1210's driver will automatically enable this mode when SAMPLE is
the only GPIO defined.

Signed-off-by: Dragos Bogdan <dragos.bogdan@analog.com>
CLKIN is independent of SPI SCLK. Its default value is
AD2S1210_DEF_CLKIN.

Signed-off-by: Dragos Bogdan <dragos.bogdan@analog.com>
The part is installed on AD-FMCMOTCON2-EBZ evaluation board.

Signed-off-by: Dragos Bogdan <dragos.bogdan@analog.com>
@dbogdan
Copy link
Contributor Author

dbogdan commented Jun 24, 2018

After more testing, v4 appeared. :)
v4:

  • enable .cs_change for the spi_transfers;
  • don't set spi->mode if device tree approach is used;
  • enable the driver in zynq_xcomm_adv7511_defconfig.

@commodo commodo merged commit 2ca7300 into master Jun 25, 2018
@commodo commodo deleted the ad2s1210 branch June 25, 2018 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants