linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RESEND PATCH] iio: adc: ad7124: Add direct reg access
@ 2020-01-29  5:14 Mircea Caprioru
  2020-01-29  5:51 ` Greg KH
  2020-01-29  7:18 ` Lars-Peter Clausen
  0 siblings, 2 replies; 3+ messages in thread
From: Mircea Caprioru @ 2020-01-29  5:14 UTC (permalink / raw)
  To: jic23
  Cc: Michael.Hennerich, alexandru.ardelean, lars, gregkh,
	linux-kernel, linux-iio, Mircea

From: Mircea <mircea.caprioru@analog.com>

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 <mircea.caprioru@analog.com>
---
 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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [RESEND PATCH] iio: adc: ad7124: Add direct reg access
  2020-01-29  5:14 [RESEND PATCH] iio: adc: ad7124: Add direct reg access Mircea Caprioru
@ 2020-01-29  5:51 ` Greg KH
  2020-01-29  7:18 ` Lars-Peter Clausen
  1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2020-01-29  5:51 UTC (permalink / raw)
  To: Mircea Caprioru
  Cc: jic23, Michael.Hennerich, alexandru.ardelean, lars, linux-kernel,
	linux-iio

On Wed, Jan 29, 2020 at 07:14:35AM +0200, Mircea Caprioru wrote:
> From: Mircea <mircea.caprioru@analog.com>
> 
> 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 <mircea.caprioru@analog.com>

Now this line doesn't match the name you use above on the "From:" line
:(

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RESEND PATCH] iio: adc: ad7124: Add direct reg access
  2020-01-29  5:14 [RESEND PATCH] iio: adc: ad7124: Add direct reg access Mircea Caprioru
  2020-01-29  5:51 ` Greg KH
@ 2020-01-29  7:18 ` Lars-Peter Clausen
  1 sibling, 0 replies; 3+ messages in thread
From: Lars-Peter Clausen @ 2020-01-29  7:18 UTC (permalink / raw)
  To: Mircea Caprioru, jic23
  Cc: Michael.Hennerich, alexandru.ardelean, gregkh, linux-kernel, linux-iio

On 1/29/20 6:14 AM, Mircea Caprioru wrote:
> From: Mircea <mircea.caprioru@analog.com>
> 
> This patch adds the posibility do read and write registers from userspace
> using the kernel debug direct register access option.

Typo: possibility

> 
> Signed-off-by: Mircea Caprioru <mircea.caprioru@analog.com>
[...]
>   
> +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);

Needs a bounds check to make sure that reg is less then the number of 
entries in ad7124_reg_size.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-01-29  7:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-29  5:14 [RESEND PATCH] iio: adc: ad7124: Add direct reg access Mircea Caprioru
2020-01-29  5:51 ` Greg KH
2020-01-29  7:18 ` Lars-Peter Clausen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).