[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75Vfb_b6FPpnhu4Z_=iBNovNubneCD3cRG9SawRmMCNOVjw@mail.gmail.com>
Date: Sun, 1 Jul 2018 00:26:56 +0300
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: Stefan Popa <stefan.popa@...log.com>
Cc: Jonathan Cameron <jic23@...nel.org>,
Michael Hennerich <Michael.Hennerich@...log.com>,
Lars-Peter Clausen <lars@...afoo.de>,
Hartmut Knaack <knaack.h@....de>,
Peter Meerwald <pmeerw@...erw.net>,
Mauro Carvalho Chehab <mchehab@...nel.org>,
"David S. Miller" <davem@...emloft.net>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Linus Walleij <linus.walleij@...aro.org>,
Randy Dunlap <rdunlap@...radead.org>,
Lukas Wunner <lukas@...ner.de>,
Ismail.Kose@...imintegrated.com,
William Breathitt Gray <vilhelm.gray@...il.com>,
sean.nyekjaer@...vas.dk,
Philippe Ombredanne <pombredanne@...b.com>,
linux-iio@...r.kernel.org,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v4 1/2] iio: dac: Add AD5758 support
On Fri, Jun 29, 2018 at 11:38 AM, Stefan Popa <stefan.popa@...log.com> wrote:
> The AD5758 is a single channel DAC with 16-bit precision which uses the
> SPI interface that operates at clock rates up to 50MHz.
>
> The output can be configured as voltage or current and is available on a
> single terminal.
>
> Datasheet:
> http://www.analog.com/media/en/technical-documentation/data-sheets/ad5758.pdf
Thanks for an update.
Few comments below.
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/spi/spi.h>
> +#include <linux/property.h>
> +#include <linux/delay.h>
> +#include <linux/bsearch.h>
Perhaps keep them ordered?
> +
> +#include <linux/iio/iio.h>
> +#include <linux/iio/sysfs.h>
> +
> +#include <asm/div64.h>
ASM? Hmm...
> +static int cmpfunc(const void *a, const void *b)
> +{
> + return (*(int *)a - *(int *)b);
Surrounding parens are not needed.
> +}
> +
> +static int ad5758_find_closest_match(const int *array,
> + unsigned int size, int val)
> +{
> + int i;
> +
> + for (i = 0; i < size; i++) {
> + if (val <= array[i])
> + return i;
> + }
> +
> + return size - 1;
> +}
Isn't it what bsearch() covers as well?
> + do {
> + ret = ad5758_spi_reg_read(st, reg);
> + if (ret < 0)
> + return ret;
> +
> + if (!(ret & mask))
> + return 0;
> +
> + udelay(100);
If it's not called from atomic context, perhaps switch to usleep_range() ?
> + } while (--timeout);
> +static int ad5758_soft_reset(struct ad5758_state *st)
> +{
> + int ret;
> +
> + ret = ad5758_spi_reg_write(st, AD5758_KEY, AD5758_KEY_CODE_RESET_1);
> + if (ret < 0)
> + return ret;
> +
> + ret = ad5758_spi_reg_write(st, AD5758_KEY, AD5758_KEY_CODE_RESET_2);
> +
> + /* Perform a software reset and wait 100us */
> + udelay(100);
Ditto.
> +
> + return ret;
> +}
> +static int ad5758_find_out_range(struct ad5758_state *st,
> + const struct ad5758_range *range,
> + unsigned int size,
> + int min, int max)
> +{
> + int i;
> +
> + for (i = 0; i < size; i++) {
> + if ((min == range[i].min) && (max == range[i].max)) {
> + st->out_range.reg = range[i].reg;
> + st->out_range.min = range[i].min;
> + st->out_range.max = range[i].max;
> +
> + return 0;
> + }
> + }
One more candidate to use bsearch().
> +
> + return -EINVAL;
> +}
> + index = (int *) bsearch(&tmp, ad5758_dc_dc_ilim,
> + ARRAY_SIZE(ad5758_dc_dc_ilim),
> + sizeof(int), cmpfunc);
I'm not sure you need that casting.
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists