All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@jic23.retrosnub.co.uk>
To: "Michał Mirosław" <mirq-linux@rere.qmqm.pl>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	linux-iio@vger.kernel.org
Subject: Re: [PATCH 4/4] iio: magnetometer: ak8974: debug AMI306 calibration data
Date: Sun, 20 Aug 2017 11:28:29 +0100	[thread overview]
Message-ID: <20170820112829.011bf027@archlinux> (raw)
In-Reply-To: <20170820112552.7c287701@archlinux>

On Sun, 20 Aug 2017 11:25:52 +0100
Jonathan Cameron <jic23@kernel.org> wrote:

> On Thu, 17 Aug 2017 15:56:12 +0200
> Michał Mirosław <mirq-linux@rere.qmqm.pl> wrote:
> 
> > Use AMI306 calibration data for randomness and debugging.
> > 
> > Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>  
> Applied to the togreg branch of iio.git and pushed out as testing for the
> autobuilders to play with it.
> 
> Thanks,
> 
> Jonathan
> > ---
> >  drivers/iio/magnetometer/ak8974.c | 41 +++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 41 insertions(+)
> > 
> > diff --git a/drivers/iio/magnetometer/ak8974.c b/drivers/iio/magnetometer/ak8974.c
> > index d8c45206ba00..b3221b34606b 100644
> > --- a/drivers/iio/magnetometer/ak8974.c
> > +++ b/drivers/iio/magnetometer/ak8974.c
> > @@ -445,6 +445,20 @@ static int ak8974_selftest(struct ak8974 *ak8974)
> >  	return 0;
> >  }
> >  
> > +static void ak8974_read_calib_data(struct ak8974 *ak8974, unsigned int reg,
> > +				   __le16 *tab, size_t tab_size)
> > +{
> > +	int ret = regmap_bulk_read(ak8974->map, reg, tab, tab_size);
> > +	if (ret) {
> > +		memset(tab, 0xFF, tab_size);
> > +		dev_warn(&ak8974->i2c->dev,
> > +			 "can't read calibration data (regs %u..%u): %d\n",
> > +			 reg, reg + tab_size - 1, ret);
Slight tweak made to avoid the warning:

drivers/iio/magnetometer/ak8974.c: In function ‘ak8974_read_calib_data’:
drivers/iio/magnetometer/ak8974.c:455:45: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 4 has type ‘size_t {aka long unsigned int}’ [-Wformat=]
     "can't read calibration data (regs %u..%u): %d\n",
                                            ~^
                                            %lu
     reg, reg + tab_size - 1, ret);
          ~~~~~~~~~~~~~~~~~~                  

Did the obvious ;)

Jonathan

> > +	} else {
> > +		add_device_randomness(tab, tab_size);
> > +	}
> > +}
> > +
> >  static int ak8974_detect(struct ak8974 *ak8974)
> >  {
> >  	unsigned int whoami;
> > @@ -490,6 +504,33 @@ static int ak8974_detect(struct ak8974 *ak8974)
> >  	ak8974->name = name;
> >  	ak8974->variant = whoami;
> >  
> > +	if (whoami == AK8974_WHOAMI_VALUE_AMI306) {
> > +		__le16 fab_data1[9], fab_data2[3];
> > +		int i;
> > +
> > +		ak8974_read_calib_data(ak8974, AMI306_FINEOUTPUT_X,
> > +				       fab_data1, sizeof(fab_data1));
> > +		ak8974_read_calib_data(ak8974, AMI306_OFFZERO_X,
> > +				       fab_data2, sizeof(fab_data2));
> > +
> > +		for (i = 0; i < 3; ++i) {
> > +			static const char axis[3] = "XYZ";
> > +			static const char pgaxis[6] = "ZYZXYX";
> > +			unsigned offz = le16_to_cpu(fab_data2[i]) & 0x7F;
> > +			unsigned fine = le16_to_cpu(fab_data1[i]);
> > +			unsigned sens = le16_to_cpu(fab_data1[i + 3]);
> > +			unsigned pgain1 = le16_to_cpu(fab_data1[i + 6]);
> > +			unsigned pgain2 = pgain1 >> 8;
> > +
> > +			pgain1 &= 0xFF;
> > +
> > +			dev_info(&ak8974->i2c->dev,
> > +				 "factory calibration for axis %c: offz=%u sens=%u fine=%u pga%c=%u pga%c=%u\n",
> > +				 axis[i], offz, sens, fine, pgaxis[i * 2],
> > +				 pgain1, pgaxis[i * 2 + 1], pgain2);
> > +		}
> > +	}
> > +
> >  	return 0;
> >  }
> >    
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


  reply	other threads:[~2017-08-20 10:28 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-17 13:56 [PATCH 0/4] iio: magnetometer: ak8974: support AMI306 Michał Mirosław
2017-08-17 13:56 ` [PATCH 1/4] iio: magnetometer: ak8974: support AMI306 variant Michał Mirosław
2017-08-20 10:19   ` Jonathan Cameron
2017-08-17 13:56 ` [PATCH 3/4] iio: magnetometer: ak8974: mark INT_CLEAR as precious Michał Mirosław
2017-08-17 13:56 ` [PATCH 2/4] iio: magnetometer: ak8974: add_device_randomness(fw + serial) Michał Mirosław
2017-08-20 10:22   ` Jonathan Cameron
2017-08-20 11:10     ` Linus Walleij
2017-08-20 14:18       ` Jonathan Cameron
2017-08-17 13:56 ` [PATCH 4/4] iio: magnetometer: ak8974: debug AMI306 calibration data Michał Mirosław
2017-08-20 10:25   ` Jonathan Cameron
2017-08-20 10:28     ` Jonathan Cameron [this message]
2017-08-20 14:40       ` Jonathan Cameron
2017-08-18 21:42 ` [PATCH 0/4] iio: magnetometer: ak8974: support AMI306 Linus Walleij

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170820112829.011bf027@archlinux \
    --to=jic23@jic23.retrosnub.co.uk \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=mirq-linux@rere.qmqm.pl \
    --cc=pmeerw@pmeerw.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.