Re: [PATCH] iio: sx9310: Fixes dropped on initial commit

2020-07-26 Thread Jonathan Cameron
On Fri, 24 Jul 2020 18:40:26 -0600
Daniel Campello  wrote:

> This patch brings back fixes on v9 of initial patch that got dropped
> when v8 was taken instead.

Oops. Not quite sure what happened there and I can't even find a record
of me saying I was applying v8.  Sorry about that.

>   - Updated Copyright
>   - Updated macro definitions
>   - Simplified return condition checks
>   - Removed ACPI and of table macros
> 
> Signed-off-by: Daniel Campello 

A few minor things I noticed whilst going through this.
As Andy pointed out it needs breaking down into a series of patches.

Please order any changes that are bug fixes at the front.

Given we also have Stephen's series in flight, it would be great if you
also pick up his patches to send me one combined series.  That way
all the merge issues should be resolved by people who can test
the changes!

Thanks,

Jonathan

> ---
> 
>  drivers/iio/proximity/sx9310.c | 377 -
>  1 file changed, 177 insertions(+), 200 deletions(-)
> 
> diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c
> index d161f3061e353d..55b3d5b83e5a6a 100644
> --- a/drivers/iio/proximity/sx9310.c
> +++ b/drivers/iio/proximity/sx9310.c
> @@ -1,13 +1,13 @@
>  // SPDX-License-Identifier: GPL-2.0
>  /*
> - * Copyright 2018 Google LLC.
> + * Copyright 2020 Google LLC.
>   *
>   * Driver for Semtech's SX9310/SX9311 capacitive proximity/button solution.
>   * Based on SX9500 driver and Semtech driver using the input framework
>   *    *  linux-driver-SX9310_NoSmartHSensing>.
> - * Reworked April 2019 by Evan Green 
> - * and January 2020 by Daniel Campello 
> + * Reworked in April 2019 by Evan Green 
> + * and in January 2020 by Daniel Campello .
>   */
> 
>  #include 
> @@ -16,7 +16,6 @@
>  #include 
>  #include 
>  #include 
> -#include 
>  #include 
>  #include 
>  #include 
> @@ -33,45 +32,45 @@
>  #define SX9310_REG_IRQ_SRC   0x00
>  #define SX9310_REG_STAT0 0x01
>  #define SX9310_REG_STAT1 0x02
> +#define SX9310_REG_STAT1_COMPSTAT_MASK   GENMASK(3, 0)
>  #define SX9310_REG_IRQ_MSK   0x03
>  #define   SX9310_CONVDONE_IRQBIT(3)
>  #define   SX9310_FAR_IRQ BIT(5)
>  #define   SX9310_CLOSE_IRQ   BIT(6)
> -#define   SX9310_EVENT_IRQ   (SX9310_FAR_IRQ | \
> -  SX9310_CLOSE_IRQ)
>  #define SX9310_REG_IRQ_FUNC  0x04
> 
>  #define SX9310_REG_PROX_CTRL00x10
> -#define   SX9310_REG_PROX_CTRL0_PROXSTAT20x10
> -#define   SX9310_REG_PROX_CTRL0_EN_MASK  0x0F
> +#define   SX9310_REG_PROX_CTRL0_SENSOREN_MASKGENMASK(3, 0)
> +#define   SX9310_REG_PROX_CTRL0_SCANPERIOD_MASK  GENMASK(7, 4)
> +#define   SX9310_REG_PROX_CTRL0_SCANPERIOD_SHIFT 4
> +#define   SX9310_REG_PROX_CTRL0_SCANPERIOD_15MS  0x01
>  #define SX9310_REG_PROX_CTRL10x11
>  #define SX9310_REG_PROX_CTRL20x12
> -#define   SX9310_REG_PROX_CTRL2_COMBMODE_ALL 0x80
> -#define   SX9310_REG_PROX_CTRL2_SHIELDEN_DYNAMIC 0x04
> +#define   SX9310_REG_PROX_CTRL2_COMBMODE_CS1_CS2 (0x02 << 6)
> +#define   SX9310_REG_PROX_CTRL2_SHIELDEN_DYNAMIC (0x01 << 2)
>  #define SX9310_REG_PROX_CTRL30x13
> -#define   SX9310_REG_PROX_CTRL3_GAIN0_X8 0x0c
> +#define   SX9310_REG_PROX_CTRL3_GAIN0_X8 (0x03 << 2)
>  #define   SX9310_REG_PROX_CTRL3_GAIN12_X40x02
>  #define SX9310_REG_PROX_CTRL40x14
>  #define   SX9310_REG_PROX_CTRL4_RESOLUTION_FINEST0x07
>  #define SX9310_REG_PROX_CTRL50x15
> -#define   SX9310_REG_PROX_CTRL5_RANGE_SMALL  0xc0
> -#define   SX9310_REG_PROX_CTRL5_STARTUPSENS_CS1  0x04
> +#define   SX9310_REG_PROX_CTRL5_RANGE_SMALL  (0x03 << 6)
> +#define   SX9310_REG_PROX_CTRL5_STARTUPSENS_CS1  (0x01 << 2)
>  #define   SX9310_REG_PROX_CTRL5_RAWFILT_1P25 0x02
>  #define SX9310_REG_PROX_CTRL60x16
> -#define   SX9310_REG_PROX_CTRL6_COMP_COMMON  0x20
> +#define   SX9310_REG_PROX_CTRL6_AVGTHRESH_DEFAULT0x20
>  #define SX9310_REG_PROX_CTRL70x17
> -#define   SX9310_REG_PROX_CTRL7_AVGNEGFILT_2 0x08
> +#define   SX9310_REG_PROX_CTRL7_AVGNEGFILT_2 (0x01 << 3)
>  #define   SX9310_REG_PROX_CTRL7_AVGPOSFILT_512   0x05
>  #define SX9310_REG_PROX_CTRL80x18
>  #define SX9310_REG_PROX_CTRL90x19
> -#define   

Re: [PATCH] iio: sx9310: Fixes dropped on initial commit

2020-07-26 Thread Andy Shevchenko
On Sat, Jul 25, 2020 at 3:41 AM Daniel Campello  wrote:
>
> This patch brings back fixes on v9 of initial patch that got dropped
> when v8 was taken instead.
>   - Updated Copyright
>   - Updated macro definitions
>   - Simplified return condition checks
>   - Removed ACPI and of table macros

Please, split to a series of patches.
I see at least ~4-5 by the changes below.

-- 
With Best Regards,
Andy Shevchenko


[PATCH] iio: sx9310: Fixes dropped on initial commit

2020-07-24 Thread Daniel Campello
This patch brings back fixes on v9 of initial patch that got dropped
when v8 was taken instead.
  - Updated Copyright
  - Updated macro definitions
  - Simplified return condition checks
  - Removed ACPI and of table macros

Signed-off-by: Daniel Campello 
---

 drivers/iio/proximity/sx9310.c | 377 -
 1 file changed, 177 insertions(+), 200 deletions(-)

diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c
index d161f3061e353d..55b3d5b83e5a6a 100644
--- a/drivers/iio/proximity/sx9310.c
+++ b/drivers/iio/proximity/sx9310.c
@@ -1,13 +1,13 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Copyright 2018 Google LLC.
+ * Copyright 2020 Google LLC.
  *
  * Driver for Semtech's SX9310/SX9311 capacitive proximity/button solution.
  * Based on SX9500 driver and Semtech driver using the input framework
  * .
- * Reworked April 2019 by Evan Green 
- * and January 2020 by Daniel Campello 
+ * Reworked in April 2019 by Evan Green 
+ * and in January 2020 by Daniel Campello .
  */

 #include 
@@ -16,7 +16,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -33,45 +32,45 @@
 #define SX9310_REG_IRQ_SRC 0x00
 #define SX9310_REG_STAT0   0x01
 #define SX9310_REG_STAT1   0x02
+#define SX9310_REG_STAT1_COMPSTAT_MASK GENMASK(3, 0)
 #define SX9310_REG_IRQ_MSK 0x03
 #define   SX9310_CONVDONE_IRQ  BIT(3)
 #define   SX9310_FAR_IRQ   BIT(5)
 #define   SX9310_CLOSE_IRQ BIT(6)
-#define   SX9310_EVENT_IRQ (SX9310_FAR_IRQ | \
-SX9310_CLOSE_IRQ)
 #define SX9310_REG_IRQ_FUNC0x04

 #define SX9310_REG_PROX_CTRL0  0x10
-#define   SX9310_REG_PROX_CTRL0_PROXSTAT2  0x10
-#define   SX9310_REG_PROX_CTRL0_EN_MASK0x0F
+#define   SX9310_REG_PROX_CTRL0_SENSOREN_MASK  GENMASK(3, 0)
+#define   SX9310_REG_PROX_CTRL0_SCANPERIOD_MASKGENMASK(7, 4)
+#define   SX9310_REG_PROX_CTRL0_SCANPERIOD_SHIFT   4
+#define   SX9310_REG_PROX_CTRL0_SCANPERIOD_15MS0x01
 #define SX9310_REG_PROX_CTRL1  0x11
 #define SX9310_REG_PROX_CTRL2  0x12
-#define   SX9310_REG_PROX_CTRL2_COMBMODE_ALL   0x80
-#define   SX9310_REG_PROX_CTRL2_SHIELDEN_DYNAMIC   0x04
+#define   SX9310_REG_PROX_CTRL2_COMBMODE_CS1_CS2   (0x02 << 6)
+#define   SX9310_REG_PROX_CTRL2_SHIELDEN_DYNAMIC   (0x01 << 2)
 #define SX9310_REG_PROX_CTRL3  0x13
-#define   SX9310_REG_PROX_CTRL3_GAIN0_X8   0x0c
+#define   SX9310_REG_PROX_CTRL3_GAIN0_X8   (0x03 << 2)
 #define   SX9310_REG_PROX_CTRL3_GAIN12_X4  0x02
 #define SX9310_REG_PROX_CTRL4  0x14
 #define   SX9310_REG_PROX_CTRL4_RESOLUTION_FINEST  0x07
 #define SX9310_REG_PROX_CTRL5  0x15
-#define   SX9310_REG_PROX_CTRL5_RANGE_SMALL0xc0
-#define   SX9310_REG_PROX_CTRL5_STARTUPSENS_CS10x04
+#define   SX9310_REG_PROX_CTRL5_RANGE_SMALL(0x03 << 6)
+#define   SX9310_REG_PROX_CTRL5_STARTUPSENS_CS1(0x01 << 2)
 #define   SX9310_REG_PROX_CTRL5_RAWFILT_1P25   0x02
 #define SX9310_REG_PROX_CTRL6  0x16
-#define   SX9310_REG_PROX_CTRL6_COMP_COMMON0x20
+#define   SX9310_REG_PROX_CTRL6_AVGTHRESH_DEFAULT  0x20
 #define SX9310_REG_PROX_CTRL7  0x17
-#define   SX9310_REG_PROX_CTRL7_AVGNEGFILT_2   0x08
+#define   SX9310_REG_PROX_CTRL7_AVGNEGFILT_2   (0x01 << 3)
 #define   SX9310_REG_PROX_CTRL7_AVGPOSFILT_512 0x05
 #define SX9310_REG_PROX_CTRL8  0x18
 #define SX9310_REG_PROX_CTRL9  0x19
-#define   SX9310_REG_PROX_CTRL8_9_PTHRESH12_28 0x40
-#define   SX9310_REG_PROX_CTRL8_9_PTHRESH_96   0x88
+#define   SX9310_REG_PROX_CTRL8_9_PTHRESH_28   (0x08 << 3)
+#define   SX9310_REG_PROX_CTRL8_9_PTHRESH_96   (0x11 << 3)
 #define   SX9310_REG_PROX_CTRL8_9_BODYTHRESH_900   0x03
 #define   SX9310_REG_PROX_CTRL8_9_BODYTHRESH_1500  0x05
 #define SX9310_REG_PROX_CTRL10 0x1a
-#define   SX9310_REG_PROX_CTRL10_HYST_6PCT 0x10
-#define   SX9310_REG_PROX_CTRL10_CLOSE_DEBOUNCE_8  0x12
-#define   SX9310_REG_PROX_CTRL10_FAR_DEBOUNCE_80x03
+#define   SX9310_REG_PROX_CTRL10_HYST_6PCT (0x01 << 4)
+#define   SX9310_REG_PROX_CTRL10_FAR_DEBOUNCE_20x01
 #define SX9310_REG_PROX_CTRL11 0x1b
 #define