Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp2237835imm; Sat, 30 Jun 2018 14:28:45 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKt4qbIlgcq83IjzfmoAJnzr/UK8yGdZ3FtxQEB9j+oC47aadRiyumfNhKtNBYiW7GQwEdt X-Received: by 2002:a17:902:9a01:: with SMTP id v1-v6mr20495814plp.20.1530394125199; Sat, 30 Jun 2018 14:28:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530394125; cv=none; d=google.com; s=arc-20160816; b=qB60dzZY7sskeCIm8k0A6sejhsfN1c/XxGNrHdaOBgomcW7H6WrUQSR2UOKNkSnmjD qTIdkPKrbCX6PXAaDNd1uzMSrPkPc+GApc7EFcPK12vaWhiVLkSAvBWufGXQHlXeJ8yn aKu79MyWq4XfqSNxX8gEAibKsquebLvEqngSzbtB0ddpmVd5Vw0Mvpci39tOWLkAhqIj nLjxOZXo3pva3IBcrZThwgZV4VnRkbsBdq+T8zSKBuIaLXQQ0q5KiOoqI0xASz7SvNhF U40BQM0N3H9STg27Mes2vcpQ2MHh56/aI8oCYtXI+IjsBOVdqM8n7FqcpacxpMJAbgLN PPnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=ZPN3eL2LF4K9QOxpvn5hUAjAYcAZAKR3GwGc4mFNRPw=; b=aXsNRBnSbrMcpE7XthJkJNZ8faCXErJO5abtZkgcy34mUT2bBKSs/YUiz5k8nZ/lxd U/oEHOujtmNrfg6My7zBCP5nJ9Yd4lNY3lrHKmxvot8psNoWldCE+dj7TL8a2HETP0oL fh6EYk4h6zVh8Tu20VhoXZOw7x6s7WWs3kQlLEbaunsd2p9depTrA+YneLV4AqDq4BU8 j6ZhwP1GiMgVfCAnP0XE8jdHHytEeLpjbqGwf6rNxsvvpy8jnIhIwTYBe1YDagdsdYe3 h+P3NvK0Ry/bsVX/A7x1nFCgfVBMQNf8PfnZqYqoaWrFVrqXhyGpKF6m8RDg91G+HPK0 cRuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=b1kn5avy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 23-v6si2037359pge.589.2018.06.30.14.28.17; Sat, 30 Jun 2018 14:28:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=b1kn5avy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752015AbeF3V1B (ORCPT + 99 others); Sat, 30 Jun 2018 17:27:01 -0400 Received: from mail-vk0-f67.google.com ([209.85.213.67]:34070 "EHLO mail-vk0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751702AbeF3V06 (ORCPT ); Sat, 30 Jun 2018 17:26:58 -0400 Received: by mail-vk0-f67.google.com with SMTP id l189-v6so2718303vke.1; Sat, 30 Jun 2018 14:26:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=ZPN3eL2LF4K9QOxpvn5hUAjAYcAZAKR3GwGc4mFNRPw=; b=b1kn5avyEd2QbjeoSM6bKtwh7CkQ5an34hsj+IiQBKaKGrDgHs9X5uiwg3OOp4jNmj EeLLPCy5v53FtzqKZlCRhB0zesp/550yw2cjirattFeOTS0BNFG1BliNynyMTWKpt4nF ehz0DbYlKi9xCjKRCh0Ijw6bSYAC0V2HJRx1jNtHwh2jjX6AYp3iCkwxwGkKx4dlNlzh VKvB2gPt6tDQWRTgqwnMxmUAGEcw3R2VbIs4mOutGkerquBieJUqWvTkDdy9tMG6Y7FL MaHCzqKC5g2Wgb+pcqTM2Q2u1XN7JvOJLW5BWdGxSMlPwhDS+SqHbLfjs2KiZ0J9h5xC Uopw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=ZPN3eL2LF4K9QOxpvn5hUAjAYcAZAKR3GwGc4mFNRPw=; b=AlCDlXGElvRuub2bgffKrQIenF17C/nSCX8ApI53jxjoV/BIVcKLOTWsHvqfd3za4w rpwkjMD4PwrKW4KDndKsgeE2NiY4Zn7ui81nZyZNdnNj0mOSlzNq6HwIO6+X5QLf9Bnz Xw/kJ8w4UZlQqtBo0qfpiksWoTUeqCDt1JYh82gLLscK2EXG+4G3Q4sRXgRL25DAin7m RNHjWzuVk5zGglg1Im+Rw1SIOgOCIbHvibxC/INq0OwehdfH9JnD64bMa8VV7gOudrxm TJjkvHskDB6HUP0SeHDK+ph5Tlqv1FxeqjP/IJQZRRmehEgRhvsj056tSgUrX/qBHqvn 88Bg== X-Gm-Message-State: APt69E24w77pyd4KPy2Q/hGqTl6o8unWXcIB9Lq8fxsMdnxQyUGJ84B+ K3Ve8Civ+a4bgPIEGjPw5S9XMB1or7yW4VGlvdo= X-Received: by 2002:a1f:50c:: with SMTP id 12-v6mr11769350vkf.26.1530394017369; Sat, 30 Jun 2018 14:26:57 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a67:8b02:0:0:0:0:0 with HTTP; Sat, 30 Jun 2018 14:26:56 -0700 (PDT) In-Reply-To: <1530261516-21118-1-git-send-email-stefan.popa@analog.com> References: <1530261516-21118-1-git-send-email-stefan.popa@analog.com> From: Andy Shevchenko Date: Sun, 1 Jul 2018 00:26:56 +0300 Message-ID: Subject: Re: [PATCH v4 1/2] iio: dac: Add AD5758 support To: Stefan Popa Cc: Jonathan Cameron , Michael Hennerich , Lars-Peter Clausen , Hartmut Knaack , Peter Meerwald , Mauro Carvalho Chehab , "David S. Miller" , Greg Kroah-Hartman , Andrew Morton , Linus Walleij , Randy Dunlap , Lukas Wunner , Ismail.Kose@maximintegrated.com, William Breathitt Gray , sean.nyekjaer@prevas.dk, Philippe Ombredanne , linux-iio@vger.kernel.org, Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 29, 2018 at 11:38 AM, Stefan Popa 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 > +#include > +#include > +#include > +#include > +#include Perhaps keep them ordered? > + > +#include > +#include > + > +#include 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