Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp469054ybl; Tue, 28 Jan 2020 06:27:14 -0800 (PST) X-Google-Smtp-Source: APXvYqz/x8qJYEXFpa7cCXUixJB8JVGCdKN7B+BlBzJgF7Ku7JR3VJO5Gsl+JtIC4W6+z61IGU+X X-Received: by 2002:a05:6830:1498:: with SMTP id s24mr9132691otq.79.1580221633951; Tue, 28 Jan 2020 06:27:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580221633; cv=none; d=google.com; s=arc-20160816; b=DOOfXBncQLWbEjACauORNSVD8ds3ZZWH6wmArXC5ifMw8MY3RBitCgPn9/RG/3hSt7 adlp0Li21B3GoHrlPVjJmarujNRm134wbsx++O+UeY9LiamTJuqgZVgy2edCWqRZnkEH RVb8W/yYaJLjY5Y7sJZXOnXBhchaWju6BqvvjfSBJJ9VQji8osBkjmsUkMceOKCWV5F6 rwGzUQf6Hoq/c68FQMYHKFSJcizY90rmk/cXxfMsCNvrz+ylv1UujjD+Zp464Bm+EwIo YD2HsryeZ1uGm4gI2JiJjy+g2dNjLtlTxKfsH01G4UUCDVxmDy193bp+4IIAUR5Vay9f ExGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=MXWK8uZW3Ixc9KwIMmDxDxyWCDUCZ+VZ800dHmHR5p8=; b=r3xHH4qJTe3ge3PkkfSUc6GUx8Ge856ZF3ybaEc36xmrDP0SxCljltDVmBS9qEzobe QHHCCg63E+IC0aeY/t2/t169rhd8c70VTDm1drl1LGkxQwIIcWnhUYADzD1QxDmiy7qv WC1CX2JM6HQqEmXZ6lfGBVfnaj+qmNkSyIgdEwRu+jokd2TRAWmb8B3AsGtBrrN8Cku6 qMH4+XMOrbQHNu2P0N6Mz0pHxG6vW4kHMQMZPXBCtN576MYZoQkOhTYtAHMz/OGGHtig AhcFajg0VUO6VKj9KtAYh9sWwnLEGjEtnkEjVCv36R3HPDBLBzwy4wsf6bm813Rb8yci hSvQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m12si130756oim.195.2020.01.28.06.27.01; Tue, 28 Jan 2020 06:27:13 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733131AbgA1O0E (ORCPT + 99 others); Tue, 28 Jan 2020 09:26:04 -0500 Received: from mx0a-00128a01.pphosted.com ([148.163.135.77]:59696 "EHLO mx0a-00128a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733098AbgA1O0C (ORCPT ); Tue, 28 Jan 2020 09:26:02 -0500 Received: from pps.filterd (m0167089.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 00SEHZhb008962; Tue, 28 Jan 2020 09:25:48 -0500 Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com with ESMTP id 2xrkfah3e8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 Jan 2020 09:25:47 -0500 Received: from ASHBMBX9.ad.analog.com (ashbmbx9.ad.analog.com [10.64.17.10]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 00SEPkJo028606 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=FAIL); Tue, 28 Jan 2020 09:25:46 -0500 Received: from SCSQMBX11.ad.analog.com (10.77.17.10) by ASHBMBX9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1779.2; Tue, 28 Jan 2020 09:25:45 -0500 Received: from zeus.spd.analog.com (10.64.82.11) by SCSQMBX11.ad.analog.com (10.77.17.10) with Microsoft SMTP Server id 15.1.1779.2 via Frontend Transport; Tue, 28 Jan 2020 06:25:45 -0800 Received: from mircea-Precision-5530-2-in-1.ad.analog.com ([10.48.65.114]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 00SEPgIx007832; Tue, 28 Jan 2020 09:25:42 -0500 From: Mircea Caprioru To: CC: , , , , , , Mircea Subject: [PATCH] iio: adc: ad7124: Add direct reg access Date: Tue, 28 Jan 2020 16:25:49 +0200 Message-ID: <20200128142549.1370-1-mircea.caprioru@analog.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-ADIRoutedOnPrem: True X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-01-28_03:2020-01-28,2020-01-28 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 malwarescore=0 suspectscore=1 mlxlogscore=818 clxscore=1011 phishscore=0 spamscore=0 adultscore=0 priorityscore=1501 bulkscore=0 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1911200001 definitions=main-2001280115 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mircea This patch adds the posibility do read and write registers from userspace using the kernel debug direct register access option. Signed-off-by: Mircea --- drivers/iio/adc/ad7124.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c index 52f45b13da4a..38e67e08a79a 100644 --- a/drivers/iio/adc/ad7124.c +++ b/drivers/iio/adc/ad7124.c @@ -93,6 +93,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, @@ -360,6 +368,25 @@ 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 (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"); @@ -375,6 +402,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, }; -- 2.17.1