Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1831595ybv; Fri, 14 Feb 2020 06:48:22 -0800 (PST) X-Google-Smtp-Source: APXvYqzi5vRjsG4r6R9fMwBFY+I3vLjOE0km3Y8U2tqNKvTSIguSrQZvZ+QFXdwuAr+ny+Ob/FhR X-Received: by 2002:aca:cdd5:: with SMTP id d204mr2086613oig.134.1581691702215; Fri, 14 Feb 2020 06:48:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581691702; cv=none; d=google.com; s=arc-20160816; b=CNZGRtIm0SSRhykcitZKPlF0eu2YaYLSf33lTXIlmDhiCeG9l6GmMrb+e09BWtIutI JHJhtRiMbhH3FrkkGu5sCv55tSb2qZDq9B1xXcCfQQ92Jm3wXGDSdocLfTVs1SU8yUJz ri4k8wnhpGR5p7o05hE8rjcwRkpBscijAnN2htVTvQsnA+P2J8NXmbgbOmCoXF1gWNER j+fvF8eP5qd9BmjKQOYIkPHh2IQCOgNuJEyIW8VcDzaEkiGsbBV4CO8fyICltGhJVMh6 3WkDL2LXDnqCpMsfGmoDoKcsLx312AoSsE9CLxPZgEolBtVStVLHvks8q0l8Pwq0ueca UPQA== 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; bh=+/4MKBgaT5yGSPx017ue63u57D/cQ4dWauEStXb0Xkc=; b=zwiMeUvcOgd0+5exyJRH2qImDPAAS4zm4fOnlkBNs9u0MZG5invqDZytvTNXrOt6YX uflYyzJ+zRF7p20tvdXlKVac8wsU4wLQGWOA8GWvld/YeX++7CJL9fGditcimjJltRGJ sYgC+iGKrXyZD9CmWF6vPqVhazbMX+ssbUHkakqzEDeOe6sweSXGmaR93sXbJLYbtiMp w8wTUOfhmK2PAbaWIaqvp/EwjpkrKk5KN/7Ng2A8gS4swXMtMy6C5XsShVGQULh7wbUe 1cIlzxRz1lHL/olcb1IKQpMq4GRW2Xsr/TzbPzuUIEJ9eqb69iHdZ0FLWWebyJpjmkeF oXGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=alREsvtT; 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 x19si3079604otk.89.2020.02.14.06.48.10; Fri, 14 Feb 2020 06:48:22 -0800 (PST) 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=alREsvtT; 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 S1729320AbgBNOsA (ORCPT + 99 others); Fri, 14 Feb 2020 09:48:00 -0500 Received: from mail.kernel.org ([198.145.29.99]:43766 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729241AbgBNOsA (ORCPT ); Fri, 14 Feb 2020 09:48:00 -0500 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (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 008D5222C2; Fri, 14 Feb 2020 14:47:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581691680; bh=Anl7Lg/k4Apl3KJ8JFDdjtGaJ8emtEZYytqz4kydcDQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=alREsvtTeRgdsXC/qS8aUDcffI+XaygKd/dUn0zQlZuk/y564Rz0aRquMH6W36Gl0 2OU3+b7fnRa6Oru8kHg7JvW+/yD9UtReRZMAODAXR0Jmu1NWZoGVB3tup81V2S00Zd WhgtCMmVKSb7aTPonxbmno1Uo0+3jp4IvugvtfDo= Date: Fri, 14 Feb 2020 14:47:55 +0000 From: Jonathan Cameron To: Mircea Caprioru Cc: , , , , , Subject: Re: [PATCH V4] iio: adc: ad7124: Add direct reg access Message-ID: <20200214144755.617e1aba@archlinux> In-Reply-To: <20200211084453.16866-1-mircea.caprioru@analog.com> References: <20200211084453.16866-1-mircea.caprioru@analog.com> X-Mailer: Claws Mail 3.17.4 (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 Tue, 11 Feb 2020 10:44:53 +0200 Mircea Caprioru wrote: > This patch adds the posibility do read and write registers from userspace > using the kernel debug direct register access option. > > Signed-off-by: Mircea Caprioru Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it. Thanks, Jonathan > --- > Changelog V4: > - verify limit againg ARRAY_SIZE(ad7124_reg_size) > > drivers/iio/adc/ad7124.c | 30 ++++++++++++++++++++++++++++++ > 1 file changed, 30 insertions(+) > > diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c > index f0206d819fda..a3c0647a5391 100644 > --- a/drivers/iio/adc/ad7124.c > +++ b/drivers/iio/adc/ad7124.c > @@ -98,6 +98,14 @@ static const unsigned int ad7124_gain[8] = { > 1, 2, 4, 8, 16, 32, 64, 128 > }; > > +static const unsigned int ad7124_reg_size[] = { > + 1, 2, 3, 3, 2, 1, 3, 3, 1, 2, 2, 2, 2, > + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, > + 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, > + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, > + 3, 3, 3, 3, 3 > +}; > + > static const int ad7124_master_clk_freq_hz[3] = { > [AD7124_LOW_POWER] = 76800, > [AD7124_MID_POWER] = 153600, > @@ -427,6 +435,27 @@ static int ad7124_write_raw(struct iio_dev *indio_dev, > } > } > > +static int ad7124_reg_access(struct iio_dev *indio_dev, > + unsigned int reg, > + unsigned int writeval, > + unsigned int *readval) > +{ > + struct ad7124_state *st = iio_priv(indio_dev); > + int ret; > + > + if (reg >= ARRAY_SIZE(ad7124_reg_size)) > + return -EINVAL; > + > + if (readval) > + ret = ad_sd_read_reg(&st->sd, reg, ad7124_reg_size[reg], > + readval); > + else > + ret = ad_sd_write_reg(&st->sd, reg, ad7124_reg_size[reg], > + writeval); > + > + return ret; > +} > + > static IIO_CONST_ATTR(in_voltage_scale_available, > "0.000001164 0.000002328 0.000004656 0.000009313 0.000018626 0.000037252 0.000074505 0.000149011 0.000298023"); > > @@ -442,6 +471,7 @@ static const struct attribute_group ad7124_attrs_group = { > static const struct iio_info ad7124_info = { > .read_raw = ad7124_read_raw, > .write_raw = ad7124_write_raw, > + .debugfs_reg_access = &ad7124_reg_access, > .validate_trigger = ad_sd_validate_trigger, > .attrs = &ad7124_attrs_group, > };