Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp6466314imm; Sun, 20 May 2018 03:51:31 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpbx1ks1/MNpJzIw9V5A+wMaAXjrv7P4aOuFBMoJfyMsJr81d1QMnU9axlv1lou5rmk+JmV X-Received: by 2002:aa7:8084:: with SMTP id v4-v6mr16033496pff.105.1526813490940; Sun, 20 May 2018 03:51:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526813490; cv=none; d=google.com; s=arc-20160816; b=mEyAk2ohu2FYSxi3MzhINYKvgjn93mH4LqSaSSxm2SuAN6Sm23C4RricFZQUN8O8rG oLfemNiXE/L2Re0bSgABPUHNz8P5pcng668nFTOvPWPyXtMW4ndKK+6Vfoj9YRueSc2a Ai38Zr7sPW7gS4/WwBAf7TiQFB1Qm0u6IBxbOaaEcFDaA4fVG2mgUKQEoo/xAKZ8ZV0J 9ew5z+tObQva89DSOvCd/GY3a5E3o6rgBIbOBnGcYHKYtTRPKdADmf67Q9WNKETkblic t//ZgLDW4AR5789FiE+6cL6Us+RFaVY55i+IVm7sUb+SxjxBjCRnJmQTLE6u48HXk4Vd KHeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature:arc-authentication-results; bh=jf3qDxenaoUoE6f5xAshTjmi4QIoLMK8aDOhH3ls59s=; b=p6fWZ+l2a8cfNOox6zd8sI3nCQ0L+YoRHPBCqjeNuvi8QgEGv7fW8dynxC9pYXYUta hxsbAHXWDak72droABRS9526pXWXeMi26zkeHBK9eSbfYQzEn+AWz30zg74gDJtsNoCa CbF/Q5NQZ7po6O4C2r3rEiTI/5VtFbjJMDTeDksgoLqwIFAv5zDTgFcHvQjpjyXEh4b3 gRD7unajlK/Ho+/g9BJ8sE/CZj+sA19J5en4b4DnZeRrURJti76dI8cW7l3k3Z0urKux vxUj+CrykvYgBmxfpZwAsbQSd7VG1jHf11kRpbk7gV/jwvIEQGGnj5AaIcLRsczbHCBm 2DVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PTcQCtX3; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i65-v6si12074079pfb.343.2018.05.20.03.51.03; Sun, 20 May 2018 03:51:30 -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=@kernel.org header.s=default header.b=PTcQCtX3; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751144AbeETKuy (ORCPT + 99 others); Sun, 20 May 2018 06:50:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:46978 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750928AbeETKux (ORCPT ); Sun, 20 May 2018 06:50:53 -0400 Received: from archlinux (cpc91196-cmbg18-2-0-cust659.5-4.cable.virginm.net [81.96.234.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A76512075C; Sun, 20 May 2018 10:50:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1526813452; bh=5LDj88Q5qcSQKGVR7ZI2XENZw5PTfKO/uJHlzvypNdM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=PTcQCtX3K/65aQ55p7DDLD5sGLm0FQa2BE7juO6MA0sBuUcmYgW/5M7HdI/CVHzku ZK7OtQ/I7iwaJ0H64OZ3Drp9GQW/w1+ZqWU2sJJiP/IOq1J/8VXORg44AHQHIrzimf 2eQZCyPwYBxDWIo32NKOO3fO/DXKWroxgPwqUURc= Date: Sun, 20 May 2018 11:50:47 +0100 From: Jonathan Cameron To: Stefan Popa Cc: , , , , , , Subject: Re: [PATCH v2 2/2] iio:dac:ad5686: Add AD5681R/AD5682R/AD5683/AD5683R support Message-ID: <20180520115047.63bd60a2@archlinux> In-Reply-To: <1526657014-28960-1-git-send-email-stefan.popa@analog.com> References: <1526657014-28960-1-git-send-email-stefan.popa@analog.com> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 18 May 2018 18:23:34 +0300 Stefan Popa wrote: > The AD5681R/AD5682R/AD5683/AD5683R are a family of one channel DACs with > 12-bit, 14-bit and 16-bit precision respectively. The devices have either > no built-in reference, or built-in 2.5V reference. > > These devices are similar to AD5691R/AD5692R/AD5693/AD5693R except > with a few notable differences: > * they use the SPI interface instead of I2C > * in the write control register, DB18 and DB17 are used for setting the > power mode, while DB16 is the REF bit. This is why a new regmap type > was defined and checked accordingly. > * the shift register is 24 bits wide, the first four bits are the command > bits followed by the data bits. As the data comprises of 20-bit, 18-bit > or 16-bit input code, this means that 4 LSB bits are don't care. This is > why the data needs to be shifted on the left with four bits. Therefore, > AD5683_REGMAP is checked inside a switch case in the ad5686_spi_write() > function. On the other hand, similar devices such as AD5693R family, > have the 4 MSB command bits followed by 4 don't care bits. > > Datasheet: > http://www.analog.com/media/en/technical-documentation/data-sheets/AD5683R_5682R_5681R_5683.pdf > > Signed-off-by: Stefan Popa A comment inline about how to perhaps improve the future flexibility of the driver if you are looking at adding new parts. Otherwise, looks good to me. Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it. Thanks, Jonathan > --- > Changes in v2: > - Nothing changed, just to follow the patch set version. > > drivers/iio/dac/ad5686-spi.c | 42 ++++++++++++++++++++++++++++++++++-------- > drivers/iio/dac/ad5686.c | 32 ++++++++++++++++++++++++++++++++ > drivers/iio/dac/ad5686.h | 8 ++++++++ > 3 files changed, 74 insertions(+), 8 deletions(-) > > diff --git a/drivers/iio/dac/ad5686-spi.c b/drivers/iio/dac/ad5686-spi.c > index 6bb09e9..1df9143 100644 > --- a/drivers/iio/dac/ad5686-spi.c > +++ b/drivers/iio/dac/ad5686-spi.c > @@ -1,6 +1,7 @@ > // SPDX-License-Identifier: GPL-2.0+ > /* > - * AD5672R, AD5676, AD5676R, AD5684, AD5684R, AD5684R, AD5685R, AD5686, AD5686R > + * AD5672R, AD5676, AD5676R, AD5681R, AD5682R, AD5683, AD5683R, > + * AD5684, AD5684R, AD5685R, AD5686, AD5686R > * Digital to analog converters driver > * > * Copyright 2018 Analog Devices Inc. > @@ -15,12 +16,27 @@ static int ad5686_spi_write(struct ad5686_state *st, > u8 cmd, u8 addr, u16 val) > { > struct spi_device *spi = to_spi_device(st->dev); > - > - st->data[0].d32 = cpu_to_be32(AD5686_CMD(cmd) | > - AD5686_ADDR(addr) | > - val); > - > - return spi_write(spi, &st->data[0].d8[1], 3); > + u8 tx_len, *buf; > + > + switch (st->chip_info->regmap_type) { > + case AD5683_REGMAP: > + st->data[0].d32 = cpu_to_be32(AD5686_CMD(cmd) | > + AD5683_DATA(val)); > + buf = &st->data[0].d8[1]; > + tx_len = 3; > + break; > + case AD5686_REGMAP: > + st->data[0].d32 = cpu_to_be32(AD5686_CMD(cmd) | > + AD5686_ADDR(addr) | > + val); > + buf = &st->data[0].d8[1]; > + tx_len = 3; > + break; > + default: > + return -EINVAL; > + } > + > + return spi_write(spi, buf, tx_len); > } > > static int ad5686_spi_read(struct ad5686_state *st, u8 addr) > @@ -37,9 +53,15 @@ static int ad5686_spi_read(struct ad5686_state *st, u8 addr) > }, > }; > struct spi_device *spi = to_spi_device(st->dev); > + u8 cmd = 0; > int ret; > > - st->data[0].d32 = cpu_to_be32(AD5686_CMD(AD5686_CMD_READBACK_ENABLE) | > + if (st->chip_info->regmap_type == AD5686_REGMAP) > + cmd = AD5686_CMD_READBACK_ENABLE; > + else if (st->chip_info->regmap_type == AD5683_REGMAP) > + cmd = AD5686_CMD_READBACK_ENABLE_V2; We are rapidly heading for the point where we should really be using a lookup table for all these device type specific elements. Something to think about if you add another one.. > + > + st->data[0].d32 = cpu_to_be32(AD5686_CMD(cmd) | > AD5686_ADDR(addr)); > st->data[1].d32 = cpu_to_be32(AD5686_CMD(AD5686_CMD_NOOP)); > > @@ -67,6 +89,10 @@ static const struct spi_device_id ad5686_spi_id[] = { > {"ad5672r", ID_AD5672R}, > {"ad5676", ID_AD5676}, > {"ad5676r", ID_AD5676R}, > + {"ad5681r", ID_AD5681R}, > + {"ad5682r", ID_AD5682R}, > + {"ad5683", ID_AD5683}, > + {"ad5683r", ID_AD5683R}, > {"ad5684", ID_AD5684}, > {"ad5684r", ID_AD5684R}, > {"ad5685", ID_AD5685R}, /* Does not exist */ > diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c > index 1fc0c56..e136f0f 100644 > --- a/drivers/iio/dac/ad5686.c > +++ b/drivers/iio/dac/ad5686.c > @@ -83,6 +83,10 @@ static ssize_t ad5686_write_dac_powerdown(struct iio_dev *indio_dev, > st->pwr_down_mask &= ~(0x3 << (chan->channel * 2)); > > switch (st->chip_info->regmap_type) { > + case AD5683_REGMAP: > + shift = 13; > + ref_bit_msk = AD5683_REF_BIT_MSK; > + break; > case AD5686_REGMAP: > shift = 0; > ref_bit_msk = 0; > @@ -256,6 +260,29 @@ static const struct ad5686_chip_info ad5686_chip_info_tbl[] = { > .num_channels = 8, > .regmap_type = AD5686_REGMAP, > }, > + [ID_AD5681R] = { > + .channels = ad5691r_channels, > + .int_vref_mv = 2500, > + .num_channels = 1, > + .regmap_type = AD5683_REGMAP, > + }, > + [ID_AD5682R] = { > + .channels = ad5692r_channels, > + .int_vref_mv = 2500, > + .num_channels = 1, > + .regmap_type = AD5683_REGMAP, > + }, > + [ID_AD5683] = { > + .channels = ad5693_channels, > + .num_channels = 1, > + .regmap_type = AD5683_REGMAP, > + }, > + [ID_AD5683R] = { > + .channels = ad5693_channels, > + .int_vref_mv = 2500, > + .num_channels = 1, > + .regmap_type = AD5683_REGMAP, > + }, > [ID_AD5684] = { > .channels = ad5684_channels, > .num_channels = 4, > @@ -385,6 +412,11 @@ int ad5686_probe(struct device *dev, > indio_dev->num_channels = st->chip_info->num_channels; > > switch (st->chip_info->regmap_type) { > + case AD5683_REGMAP: > + cmd = AD5686_CMD_CONTROL_REG; > + ref_bit_msk = AD5683_REF_BIT_MSK; > + st->use_internal_vref = !voltage_uv; > + break; > case AD5686_REGMAP: > cmd = AD5686_CMD_INTERNAL_REFER_SETUP; > ref_bit_msk = 0; > diff --git a/drivers/iio/dac/ad5686.h b/drivers/iio/dac/ad5686.h > index 6c6879d..d05cda9 100644 > --- a/drivers/iio/dac/ad5686.h > +++ b/drivers/iio/dac/ad5686.h > @@ -13,6 +13,7 @@ > #include > #include > > +#define AD5683_DATA(x) ((x) << 4) > #define AD5686_ADDR(x) ((x) << 16) > #define AD5686_CMD(x) ((x) << 20) > > @@ -36,6 +37,8 @@ > #define AD5686_LDAC_PWRDN_3STATE 0x3 > > #define AD5686_CMD_CONTROL_REG 0x4 > +#define AD5686_CMD_READBACK_ENABLE_V2 0x5 > +#define AD5683_REF_BIT_MSK BIT(12) > #define AD5693_REF_BIT_MSK BIT(12) > > /** > @@ -47,6 +50,10 @@ enum ad5686_supported_device_ids { > ID_AD5675R, > ID_AD5676, > ID_AD5676R, > + ID_AD5681R, > + ID_AD5682R, > + ID_AD5683, > + ID_AD5683R, > ID_AD5684, > ID_AD5684R, > ID_AD5685R, > @@ -64,6 +71,7 @@ enum ad5686_supported_device_ids { > }; > > enum ad5686_regmap_type { > + AD5683_REGMAP, > AD5686_REGMAP, > AD5693_REGMAP > };