[PATCH V7 0/2] Add support for aw96103/aw96105 proximity sensor

2024-08-13 Thread wangshuaijie
From: shuaijie wang 

Add drivers that support Awinic aw96103/aw96105 proximity sensors.

The aw9610x series are high-sensitivity capacitive proximity detection
sensors. This device detects human proximity and assists electronic devices
in reducing specific absorption rate (SAR) to pass SAR related certifications.
The device reduces RF power and reduces harm when detecting human proximity. 
Increase power and improve signal quality when the human body is far away.

The specific absorption rate (SAR) is a metric that measures the degree of
absorption of electromagnetic radiation emitted by wireless devices,
such as mobile phones and tablets, by human tissue.

This patch implements device initialization, registration,
I/O operation handling and interrupt handling, and passed basic testing.

v1->v2:
---
 - Remove unnecessary log printing.
 - Optimize comment style.
 - Issues with modifying the device tree.
 - Optimize code style.

v2->v3:
---
 - Add a description about the hardware device.
 - Remove inappropriate configuration items.
 - Modify the formatting issues.
 - Modify the structure of the driver.
 - Change the style of the driver's comments.
 - Remove unnecessary log printing.
 - Modify the function used for memory allocation.
 - Modify the driver registration process.
 - Remove the functionality related to updating firmware.
 - Change the input subsystem in the driver to the iio subsystem.
 - Modify the usage of the interrupt pin.
 
v3->v4:
---
The changes in this patch version are quite significant, and I concur
with Krzysztof's viewpoint that this driver is indeed overly complex for
the proximity sensor. Therefore, I have removed the compatibility for the
aw963xx series, and the driver will now exclusively support the aw9610x series.

 - Modify the software architecture to remove compatibility for
   the aw963xx series.
 - Optimize the parsing of register configuration files (.bin).
 - Remove unnecessary log printing.
 - Delete redefinition of true and false.
 - Remove unnecessary interfaces.
 - Optimize regulator usage.
 - Convert the I2C communication interface to regmap.

v4->v5:
---
 - Solve errors that occur when executing the make dt_binding_check 
DT_SCHEMA_FILES.

v5->v6:
---
 - Rename AW9610X to aw96103.
 - Remove the encapsulation of the i2c communication interface.
 - Delete the update node.
 - Modify the usage of regulator.
 - Delete the remove and shutdown interfaces.
 - Add iio's event-related interfaces.
 - Modify the initialization process of iio.
 - Delete power_supply-related operations.
 - Modify the register names.

v6->v7:
---
 - Use __free(kfree) when allocating memory.
 - Modify the way to request the register configuration file,
   using request_firmware_nowait to request the configuration file.

shuaijie wang (2):
  dt-bindings: iio: aw96103: Add bindings for aw96103/aw96105 sensor
  iio: proximity: aw96103: Add support for aw96103/aw96105 proximity
sensor

 .../iio/proximity/awinic,aw96103.yaml |  63 ++
 drivers/iio/proximity/Kconfig |  11 +
 drivers/iio/proximity/Makefile|   1 +
 drivers/iio/proximity/aw96103.c   | 814 ++
 drivers/iio/proximity/aw96103.h   | 116 +++
 5 files changed, 1005 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/iio/proximity/awinic,aw96103.yaml
 create mode 100644 drivers/iio/proximity/aw96103.c
 create mode 100644 drivers/iio/proximity/aw96103.h


base-commit: 6b0f8db921abf0520081d779876d3a41069dab95
-- 
2.45.1




[PATCH V7 1/2] dt-bindings: iio: aw96103: Add bindings for aw96103/aw96105 sensor

2024-08-13 Thread wangshuaijie
From: shuaijie wang 

Add device tree bindings for aw96103/aw96105 proximity sensor.

Reviewed-by: Krzysztof Kozlowski 
Signed-off-by: shuaijie wang 
---
 .../iio/proximity/awinic,aw96103.yaml | 63 +++
 1 file changed, 63 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/iio/proximity/awinic,aw96103.yaml

diff --git 
a/Documentation/devicetree/bindings/iio/proximity/awinic,aw96103.yaml 
b/Documentation/devicetree/bindings/iio/proximity/awinic,aw96103.yaml
new file mode 100644
index ..54b5bc176d5c
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/proximity/awinic,aw96103.yaml
@@ -0,0 +1,63 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/proximity/awinic,aw96103.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Awinic's AW96103 capacitive proximity sensor and similar
+
+maintainers:
+  - Wang Shuaijie 
+
+description: |
+  Awinic's AW96103/AW96105 proximity sensor.
+  The specific absorption rate (SAR) is a metric that measures
+  the degree of absorption of electromagnetic radiation emitted by
+  wireless devices, such as mobile phones and tablets, by human tissue.
+  In mobile phone applications, the proximity sensor is primarily
+  used to detect the proximity of the human body to the phone. When the
+  phone approaches the human body, it will actively reduce the transmit
+  power of the antenna to keep the SAR within a safe range. Therefore,
+  we also refer to the proximity sensor as a SAR sensor.
+
+properties:
+  compatible:
+enum:
+  - awinic,aw96103
+  - awinic,aw96105
+
+  reg:
+maxItems: 1
+
+  interrupts:
+description:
+  Generated by the device to announce that a close/far
+  proximity event has happened.
+maxItems: 1
+
+  vcc-supply:
+description:
+  Optional regulator for chip, 1.7V-3.6V.
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - vcc-supply
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+i2c {
+#address-cells = <1>;
+#size-cells = <0>;
+proximity@12 {
+compatible = "awinic,aw96103";
+reg = <0x12>;
+interrupt-parent = <&gpio>;
+interrupts = <23 IRQ_TYPE_EDGE_FALLING>;
+vcc-supply = <&pp1800_prox>;
+};
+};
-- 
2.45.1




[PATCH V7 2/2] iio: proximity: aw96103: Add support for aw96103/aw96105 proximity sensor

2024-08-13 Thread wangshuaijie
From: shuaijie wang 

AW96103 is a low power consumption capacitive touch and proximity controller.
Each channel can be independently config as sensor input, shield output.

Channel Information:
  aw96103: 3-channel
  aw96105: 5-channel

Signed-off-by: shuaijie wang 
---
 drivers/iio/proximity/Kconfig   |  11 +
 drivers/iio/proximity/Makefile  |   1 +
 drivers/iio/proximity/aw96103.c | 814 
 drivers/iio/proximity/aw96103.h | 116 +
 4 files changed, 942 insertions(+)
 create mode 100644 drivers/iio/proximity/aw96103.c
 create mode 100644 drivers/iio/proximity/aw96103.h

diff --git a/drivers/iio/proximity/Kconfig b/drivers/iio/proximity/Kconfig
index 2ca3b0bc5eba..974aedf0c057 100644
--- a/drivers/iio/proximity/Kconfig
+++ b/drivers/iio/proximity/Kconfig
@@ -219,4 +219,15 @@ config VL53L0X_I2C
  To compile this driver as a module, choose M here: the
  module will be called vl53l0x-i2c.
 
+config AW96103
+   tristate "AW96103/AW96105 Awinic proximity sensor"
+   select REGMAP_I2C
+   depends on I2C
+   help
+ Say Y here to build a driver for Awinic's AW96103/AW96105 capacitive
+ proximity sensor.
+
+ To compile this driver as a module, choose M here: the
+ module will be called aw96103.
+
 endmenu
diff --git a/drivers/iio/proximity/Makefile b/drivers/iio/proximity/Makefile
index f36598380446..b1e32aa93678 100644
--- a/drivers/iio/proximity/Makefile
+++ b/drivers/iio/proximity/Makefile
@@ -21,4 +21,5 @@ obj-$(CONFIG_SX_COMMON)   += sx_common.o
 obj-$(CONFIG_SX9500)   += sx9500.o
 obj-$(CONFIG_VCNL3020) += vcnl3020.o
 obj-$(CONFIG_VL53L0X_I2C)  += vl53l0x-i2c.o
+obj-$(CONFIG_AW96103)  += aw96103.o
 
diff --git a/drivers/iio/proximity/aw96103.c b/drivers/iio/proximity/aw96103.c
new file mode 100644
index ..d8ca138de46e
--- /dev/null
+++ b/drivers/iio/proximity/aw96103.c
@@ -0,0 +1,814 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * AWINIC aw96103 proximity sensor driver
+ *
+ * Author: Wang Shuaijie 
+ *
+ * Copyright (c) 2024 awinic Technology CO., LTD
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "aw96103.h"
+
+static const unsigned int aw96103_reg_default[] = {
+   0x, 0x3f3f, 0x0004, 0x0064, 0x0008, 0x0017c11e,
+   0x000c, 0x0500, 0x0010, 0x00093ffd, 0x0014, 0x19240009,
+   0x0018, 0xd81c0207, 0x001c, 0xff00, 0x0020, 0x00241900,
+   0x0024, 0x00093ff7, 0x0028, 0x58020009, 0x002c, 0xd81c0207,
+   0x0030, 0xff00, 0x0034, 0x00025800, 0x0038, 0x00093fdf,
+   0x003c, 0x7d3b0009, 0x0040, 0xd81c0207, 0x0044, 0xff00,
+   0x0048, 0x003b7d00, 0x004c, 0x00093f7f, 0x0050, 0xe9310009,
+   0x0054, 0xd81c0207, 0x0058, 0xff00, 0x005c, 0x0031e900,
+   0x0060, 0x00093dff, 0x0064, 0x1a0c0009, 0x0068, 0xd81c0207,
+   0x006c, 0xff00, 0x0070, 0x000c1a00, 0x0074, 0x80093fff,
+   0x0078, 0x043d0009, 0x007c, 0xd81c0207, 0x0080, 0xff00,
+   0x0084, 0x003d0400, 0x00a0, 0xe640, 0x00a4, 0x,
+   0x00a8, 0x010408d2, 0x00ac, 0x, 0x00b0, 0x,
+   0x00b8, 0x5fff, 0x00bc, 0x, 0x00c0, 0x,
+   0x00c4, 0x, 0x00c8, 0x, 0x00cc, 0x,
+   0x00d0, 0x, 0x00d4, 0x, 0x00d8, 0x,
+   0x00dc, 0xe6447800, 0x00e0, 0x7800, 0x00e4, 0x010408d2,
+   0x00e8, 0x, 0x00ec, 0x, 0x00f4, 0x5fff,
+   0x00f8, 0x, 0x00fc, 0x, 0x0100, 0x,
+   0x0104, 0x, 0x0108, 0x, 0x010c, 0x0200,
+   0x0110, 0x, 0x0114, 0x, 0x0118, 0xe6447800,
+   0x011c, 0x7800, 0x0120, 0x010408d2, 0x0124, 0x,
+   0x0128, 0x, 0x0130, 0x5fff, 0x0134, 0x,
+   0x0138, 0x, 0x013c, 0x, 0x0140, 0x,
+   0x0144, 0x, 0x0148, 0x0200, 0x014c, 0x,
+   0x0150, 0x, 0x0154, 0xe6447800, 0x0158, 0x7800,
+   0x015c, 0x010408d2, 0x0160, 0x, 0x0164, 0x,
+   0x016c, 0x5fff, 0x0170, 0x, 0x0174, 0x,
+   0x0178, 0x, 0x017c, 0x, 0x0180, 0x,
+   0x0184, 0x0200, 0x0188, 0x, 0x018c, 0x,
+   0x0190, 0xe6447800, 0x0194, 0x7800, 0x0198, 0x010408d2,
+   0x019c, 0x, 0x01a0, 0x, 0x01a8, 0x5fff,
+   0x01ac, 0x, 0x01b0, 0x, 0x01b4, 0x,
+   0x01b8, 0x, 0x01bc, 0x, 0x01c0, 0x0200,
+   0x01c4, 0x, 0x01c8, 0x, 0x01cc, 0xe6407800,
+   0x01d0, 0x7800, 0x01d4, 0x010408d2, 0x01d8, 0x,
+   0x01dc, 0x, 0x01e4, 0x5fff, 0x01e8, 0x,
+   0x01ec, 0x, 0x01f0, 0x, 0x01f4, 0x,
+   0x01f8, 0x, 0x01fc, 0x0200, 0x0200, 0x,
+   0x0204, 0x

[PATCH V8 0/2] Add support for aw96103/aw96105 proximity sensor

2024-08-23 Thread wangshuaijie
From: shuaijie wang 

Add drivers that support Awinic aw96103/aw96105 proximity sensors.

The aw9610x series are high-sensitivity capacitive proximity detection
sensors. This device detects human proximity and assists electronic devices
in reducing specific absorption rate (SAR) to pass SAR related certifications.
The device reduces RF power and reduces harm when detecting human proximity. 
Increase power and improve signal quality when the human body is far away.

The specific absorption rate (SAR) is a metric that measures the degree of
absorption of electromagnetic radiation emitted by wireless devices,
such as mobile phones and tablets, by human tissue.

This patch implements device initialization, registration,
I/O operation handling and interrupt handling, and passed basic testing.

v1->v2:
---
 - Remove unnecessary log printing.
 - Optimize comment style.
 - Issues with modifying the device tree.
 - Optimize code style.

v2->v3:
---
 - Add a description about the hardware device.
 - Remove inappropriate configuration items.
 - Modify the formatting issues.
 - Modify the structure of the driver.
 - Change the style of the driver's comments.
 - Remove unnecessary log printing.
 - Modify the function used for memory allocation.
 - Modify the driver registration process.
 - Remove the functionality related to updating firmware.
 - Change the input subsystem in the driver to the iio subsystem.
 - Modify the usage of the interrupt pin.
 
v3->v4:
---
The changes in this patch version are quite significant, and I concur
with Krzysztof's viewpoint that this driver is indeed overly complex for
the proximity sensor. Therefore, I have removed the compatibility for the
aw963xx series, and the driver will now exclusively support the aw9610x series.

 - Modify the software architecture to remove compatibility for
   the aw963xx series.
 - Optimize the parsing of register configuration files (.bin).
 - Remove unnecessary log printing.
 - Delete redefinition of true and false.
 - Remove unnecessary interfaces.
 - Optimize regulator usage.
 - Convert the I2C communication interface to regmap.

v4->v5:
---
 - Solve errors that occur when executing the make dt_binding_check 
DT_SCHEMA_FILES.

v5->v6:
---
 - Rename AW9610X to aw96103.
 - Remove the encapsulation of the i2c communication interface.
 - Delete the update node.
 - Modify the usage of regulator.
 - Delete the remove and shutdown interfaces.
 - Add iio's event-related interfaces.
 - Modify the initialization process of iio.
 - Delete power_supply-related operations.
 - Modify the register names.

v6->v7:
---
 - Use __free(kfree) when allocating memory.
 - Modify the way to request the register configuration file,
   using request_firmware_nowait to request the configuration file.

v7->v8:
---
 - Delete aw96103.h.
 - Remove the function of dynamically allocating IIO-related resources.
 - Remove non-essential members from the aw96103 structure.
 - Add some comments.
 - Delete the aw96103_interrupt_clear function.
 - Delete the aw96103_version_init function.
 - Optimize code logic.
 - Modify attribute descriptions in the YAML file.

shuaijie wang (2):
  dt-bindings: iio: aw96103: Add bindings for aw96103/aw96105 sensor
  iio: proximity: aw96103: Add support for aw96103/aw96105 proximity
sensor

 .../iio/proximity/awinic,aw96103.yaml |  61 ++
 drivers/iio/proximity/Kconfig |  11 +
 drivers/iio/proximity/Makefile|   1 +
 drivers/iio/proximity/aw96103.c   | 880 ++
 4 files changed, 953 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/iio/proximity/awinic,aw96103.yaml
 create mode 100644 drivers/iio/proximity/aw96103.c


base-commit: b78b25f69a1dfa79798f684ad34707b1da10a48f
-- 
2.45.1




[PATCH V8 2/2] iio: proximity: aw96103: Add support for aw96103/aw96105 proximity sensor

2024-08-23 Thread wangshuaijie
From: shuaijie wang 

AW96103 is a low power consumption capacitive touch and proximity controller.
Each channel can be independently config as sensor input, shield output.

Channel Information:
  aw96103: 3-channel
  aw96105: 5-channel

Signed-off-by: shuaijie wang 
---
 drivers/iio/proximity/Kconfig   |  11 +
 drivers/iio/proximity/Makefile  |   1 +
 drivers/iio/proximity/aw96103.c | 880 
 3 files changed, 892 insertions(+)
 create mode 100644 drivers/iio/proximity/aw96103.c

diff --git a/drivers/iio/proximity/Kconfig b/drivers/iio/proximity/Kconfig
index 2ca3b0bc5eba..974aedf0c057 100644
--- a/drivers/iio/proximity/Kconfig
+++ b/drivers/iio/proximity/Kconfig
@@ -219,4 +219,15 @@ config VL53L0X_I2C
  To compile this driver as a module, choose M here: the
  module will be called vl53l0x-i2c.
 
+config AW96103
+   tristate "AW96103/AW96105 Awinic proximity sensor"
+   select REGMAP_I2C
+   depends on I2C
+   help
+ Say Y here to build a driver for Awinic's AW96103/AW96105 capacitive
+ proximity sensor.
+
+ To compile this driver as a module, choose M here: the
+ module will be called aw96103.
+
 endmenu
diff --git a/drivers/iio/proximity/Makefile b/drivers/iio/proximity/Makefile
index f36598380446..b1e32aa93678 100644
--- a/drivers/iio/proximity/Makefile
+++ b/drivers/iio/proximity/Makefile
@@ -21,4 +21,5 @@ obj-$(CONFIG_SX_COMMON)   += sx_common.o
 obj-$(CONFIG_SX9500)   += sx9500.o
 obj-$(CONFIG_VCNL3020) += vcnl3020.o
 obj-$(CONFIG_VL53L0X_I2C)  += vl53l0x-i2c.o
+obj-$(CONFIG_AW96103)  += aw96103.o
 
diff --git a/drivers/iio/proximity/aw96103.c b/drivers/iio/proximity/aw96103.c
new file mode 100644
index ..c9514712c307
--- /dev/null
+++ b/drivers/iio/proximity/aw96103.c
@@ -0,0 +1,880 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * AWINIC aw96103 proximity sensor driver
+ *
+ * Author: Wang Shuaijie 
+ *
+ * Copyright (c) 2024 awinic Technology CO., LTD
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define AW_DATA_PROCESS_FACTOR 1024
+#define AW96103_CHIP_ID0xa961
+#define AW96103_BIN_VALID_DATA_OFFSET  64
+#define AW96103_BIN_DATA_LEN_OFFSET16
+#define AW96103_BIN_DATA_REG_NUM_SIZE  4
+#define AW96103_BIN_CHIP_TYPE_SIZE 8
+#define AW96103_BIN_CHIP_TYPE_OFFSET   24
+
+#define AW96103_REG_SCANCTRL0  0x
+#define AW96103_REG_STAT0  0x0090
+#define AW96103_REG_BLFILT_CH0 0x00A8
+#define AW96103_REG_BLRSTRNG_CH0   0x00B4
+#define AW96103_REG_DIFF_CH0   0x0240
+#define AW96103_REG_FWVER2 0x0410
+#define AW96103_REG_CMD0xF008
+#define AW96103_REG_IRQSRC 0xF080
+#define AW96103_REG_IRQEN  0xF084
+#define AW96103_REG_RESET  0xFF0C
+#define AW96103_REG_CHIPID 0xFF10
+#define AW96103_REG_EEDA0  0x0408
+#define AW96103_REG_EEDA1  0x040C
+#define AW96103_REG_PROXCTRL_CH0   0x00B0
+#define AW96103_REG_PROXTH0_CH00x00B8
+#define AW96103_PROXTH_CH_STEP 0x3C
+#define AW96103_THHYST_MASKGENMASK(13, 12)
+#define AW96103_INDEB_MASK GENMASK(11, 10)
+#define AW96103_OUTDEB_MASKGENMASK(9, 8)
+#define AW96103_INITOVERIRQ_MASK   BIT(0)
+#define AW96103_BLFILT_CH_STEP 0x3C
+#define AW96103_BLRSTRNG_MASK  GENMASK(5, 0)
+#define AW96103_CHIPID_MASKGENMASK(31, 16)
+#define AW96103_BLERRTRIG_MASK BIT(25)
+#define AW96103_CHAN_EN_MASK   GENMASK(5, 0)
+#define AW96103_REG_PROXCTRL_CH(x) \
+   (AW96103_REG_PROXCTRL_CH0 + (x) * AW96103_PROXTH_CH_STEP)
+
+#define AW96103_REG_PROXTH0_CH(x)  \
+   (AW96103_REG_PROXTH0_CH0 + (x) * AW96103_PROXTH_CH_STEP)
+
+/**
+ * struct aw_bin - Store the data obtained from parsing the configuration file.
+ * @chip_type: Frame header information-chip type
+ * @valid_data_len: Length of valid data obtained after parsing
+ * @valid_data_addr: The offset address of the valid data obtained
+ *  after parsing relative to info
+ * @len: The size of the bin file obtained from the firmware
+ * @data: Store the bin file obtained from the firmware
+ */
+struct aw_bin {
+   unsigned char chip_type[8];
+   unsigned int valid_data_len;
+   unsigned int valid_data_addr;
+   unsigned int len;
+   unsigned char data[] __counted_by(len);
+};
+
+enum aw96103_sar_vers {
+   AW96103 = 2,
+   AW96103A = 6,
+   AW96103B = 0xa,
+};
+
+enum aw96103_operation_mode {
+

[PATCH V8 1/2] dt-bindings: iio: aw96103: Add bindings for aw96103/aw96105 sensor

2024-08-23 Thread wangshuaijie
From: shuaijie wang 

Add device tree bindings for aw96103/aw96105 proximity sensor.

Reviewed-by: Krzysztof Kozlowski 
Signed-off-by: shuaijie wang 
---
 .../iio/proximity/awinic,aw96103.yaml | 61 +++
 1 file changed, 61 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/iio/proximity/awinic,aw96103.yaml

diff --git 
a/Documentation/devicetree/bindings/iio/proximity/awinic,aw96103.yaml 
b/Documentation/devicetree/bindings/iio/proximity/awinic,aw96103.yaml
new file mode 100644
index ..7a83ceced11c
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/proximity/awinic,aw96103.yaml
@@ -0,0 +1,61 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/proximity/awinic,aw96103.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Awinic's AW96103 capacitive proximity sensor and similar
+
+maintainers:
+  - Wang Shuaijie 
+
+description: |
+  Awinic's AW96103/AW96105 proximity sensor.
+  The specific absorption rate (SAR) is a metric that measures
+  the degree of absorption of electromagnetic radiation emitted by
+  wireless devices, such as mobile phones and tablets, by human tissue.
+  In mobile phone applications, the proximity sensor is primarily
+  used to detect the proximity of the human body to the phone. When the
+  phone approaches the human body, it will actively reduce the transmit
+  power of the antenna to keep the SAR within a safe range. Therefore,
+  we also refer to the proximity sensor as a SAR sensor.
+
+properties:
+  compatible:
+enum:
+  - awinic,aw96103
+  - awinic,aw96105
+
+  reg:
+maxItems: 1
+
+  interrupts:
+description:
+  Generated by the device to announce that a close/far
+  proximity event has happened.
+maxItems: 1
+
+  vcc-supply: true
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - vcc-supply
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+i2c {
+#address-cells = <1>;
+#size-cells = <0>;
+proximity@12 {
+compatible = "awinic,aw96103";
+reg = <0x12>;
+interrupt-parent = <&gpio>;
+interrupts = <23 IRQ_TYPE_EDGE_FALLING>;
+vcc-supply = <&pp1800_prox>;
+};
+};
-- 
2.45.1




[PATCH V9 2/2] iio: proximity: aw96103: Add support for aw96103/aw96105 proximity sensor

2024-08-27 Thread wangshuaijie
From: shuaijie wang 

AW96103 is a low power consumption capacitive touch and proximity controller.
Each channel can be independently config as sensor input, shield output.

Channel Information:
  aw96103: 3-channel
  aw96105: 5-channel

Signed-off-by: shuaijie wang 
---
 drivers/iio/proximity/Kconfig   |  11 +
 drivers/iio/proximity/Makefile  |   1 +
 drivers/iio/proximity/aw96103.c | 844 
 3 files changed, 856 insertions(+)
 create mode 100644 drivers/iio/proximity/aw96103.c

diff --git a/drivers/iio/proximity/Kconfig b/drivers/iio/proximity/Kconfig
index 2ca3b0bc5eba..974aedf0c057 100644
--- a/drivers/iio/proximity/Kconfig
+++ b/drivers/iio/proximity/Kconfig
@@ -219,4 +219,15 @@ config VL53L0X_I2C
  To compile this driver as a module, choose M here: the
  module will be called vl53l0x-i2c.
 
+config AW96103
+   tristate "AW96103/AW96105 Awinic proximity sensor"
+   select REGMAP_I2C
+   depends on I2C
+   help
+ Say Y here to build a driver for Awinic's AW96103/AW96105 capacitive
+ proximity sensor.
+
+ To compile this driver as a module, choose M here: the
+ module will be called aw96103.
+
 endmenu
diff --git a/drivers/iio/proximity/Makefile b/drivers/iio/proximity/Makefile
index f36598380446..b1e32aa93678 100644
--- a/drivers/iio/proximity/Makefile
+++ b/drivers/iio/proximity/Makefile
@@ -21,4 +21,5 @@ obj-$(CONFIG_SX_COMMON)   += sx_common.o
 obj-$(CONFIG_SX9500)   += sx9500.o
 obj-$(CONFIG_VCNL3020) += vcnl3020.o
 obj-$(CONFIG_VL53L0X_I2C)  += vl53l0x-i2c.o
+obj-$(CONFIG_AW96103)  += aw96103.o
 
diff --git a/drivers/iio/proximity/aw96103.c b/drivers/iio/proximity/aw96103.c
new file mode 100644
index ..d3eca77f3f15
--- /dev/null
+++ b/drivers/iio/proximity/aw96103.c
@@ -0,0 +1,844 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * AWINIC aw96103 proximity sensor driver
+ *
+ * Author: Wang Shuaijie 
+ *
+ * Copyright (c) 2024 awinic Technology CO., LTD
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define AW_DATA_PROCESS_FACTOR 1024
+#define AW96103_CHIP_ID0xa961
+#define AW96103_BIN_VALID_DATA_OFFSET  64
+#define AW96103_BIN_DATA_LEN_OFFSET16
+#define AW96103_BIN_DATA_REG_NUM_SIZE  4
+#define AW96103_BIN_CHIP_TYPE_SIZE 8
+#define AW96103_BIN_CHIP_TYPE_OFFSET   24
+
+#define AW96103_REG_SCANCTRL0  0x
+#define AW96103_REG_STAT0  0x0090
+#define AW96103_REG_BLFILT_CH0 0x00A8
+#define AW96103_REG_BLRSTRNG_CH0   0x00B4
+#define AW96103_REG_DIFF_CH0   0x0240
+#define AW96103_REG_FWVER2 0x0410
+#define AW96103_REG_CMD0xF008
+#define AW96103_REG_IRQSRC 0xF080
+#define AW96103_REG_IRQEN  0xF084
+#define AW96103_REG_RESET  0xFF0C
+#define AW96103_REG_CHIPID 0xFF10
+#define AW96103_REG_EEDA0  0x0408
+#define AW96103_REG_EEDA1  0x040C
+#define AW96103_REG_PROXCTRL_CH0   0x00B0
+#define AW96103_REG_PROXTH0_CH00x00B8
+#define AW96103_PROXTH_CH_STEP 0x3C
+#define AW96103_THHYST_MASKGENMASK(13, 12)
+#define AW96103_INDEB_MASK GENMASK(11, 10)
+#define AW96103_OUTDEB_MASKGENMASK(9, 8)
+#define AW96103_INITOVERIRQ_MASK   BIT(0)
+#define AW96103_BLFILT_CH_STEP 0x3C
+#define AW96103_BLRSTRNG_MASK  GENMASK(5, 0)
+#define AW96103_CHIPID_MASKGENMASK(31, 16)
+#define AW96103_BLERRTRIG_MASK BIT(25)
+#define AW96103_CHAN_EN_MASK   GENMASK(5, 0)
+#define AW96103_REG_PROXCTRL_CH(x) \
+   (AW96103_REG_PROXCTRL_CH0 + (x) * AW96103_PROXTH_CH_STEP)
+
+#define AW96103_REG_PROXTH0_CH(x)  \
+   (AW96103_REG_PROXTH0_CH0 + (x) * AW96103_PROXTH_CH_STEP)
+
+/**
+ * struct aw_bin - Store the data obtained from parsing the configuration file.
+ * @chip_type: Frame header information-chip type
+ * @valid_data_len: Length of valid data obtained after parsing
+ * @valid_data_addr: The offset address of the valid data obtained
+ *  after parsing relative to info
+ * @len: The size of the bin file obtained from the firmware
+ * @data: Store the bin file obtained from the firmware
+ */
+struct aw_bin {
+   unsigned char chip_type[8];
+   unsigned int valid_data_len;
+   unsigned int valid_data_addr;
+   unsigned int len;
+   unsigned char data[] __counted_by(len);
+};
+
+enum aw96103_sar_vers {
+   AW96103 = 2,
+   AW96103A = 6,
+   AW96103B = 0xa,
+};
+
+enum aw96103_operati

[PATCH V9 0/2] Add support for aw96103/aw96105 proximity sensor

2024-08-27 Thread wangshuaijie
From: shuaijie wang 

Add drivers that support Awinic aw96103/aw96105 proximity sensors.

The aw9610x series are high-sensitivity capacitive proximity detection
sensors. This device detects human proximity and assists electronic devices
in reducing specific absorption rate (SAR) to pass SAR related certifications.
The device reduces RF power and reduces harm when detecting human proximity. 
Increase power and improve signal quality when the human body is far away.

The specific absorption rate (SAR) is a metric that measures the degree of
absorption of electromagnetic radiation emitted by wireless devices,
such as mobile phones and tablets, by human tissue.

This patch implements device initialization, registration,
I/O operation handling and interrupt handling, and passed basic testing.

v1->v2:
---
 - Remove unnecessary log printing.
 - Optimize comment style.
 - Issues with modifying the device tree.
 - Optimize code style.

v2->v3:
---
 - Add a description about the hardware device.
 - Remove inappropriate configuration items.
 - Modify the formatting issues.
 - Modify the structure of the driver.
 - Change the style of the driver's comments.
 - Remove unnecessary log printing.
 - Modify the function used for memory allocation.
 - Modify the driver registration process.
 - Remove the functionality related to updating firmware.
 - Change the input subsystem in the driver to the iio subsystem.
 - Modify the usage of the interrupt pin.
 
v3->v4:
---
The changes in this patch version are quite significant, and I concur
with Krzysztof's viewpoint that this driver is indeed overly complex for
the proximity sensor. Therefore, I have removed the compatibility for the
aw963xx series, and the driver will now exclusively support the aw9610x series.

 - Modify the software architecture to remove compatibility for
   the aw963xx series.
 - Optimize the parsing of register configuration files (.bin).
 - Remove unnecessary log printing.
 - Delete redefinition of true and false.
 - Remove unnecessary interfaces.
 - Optimize regulator usage.
 - Convert the I2C communication interface to regmap.

v4->v5:
---
 - Solve errors that occur when executing the make dt_binding_check 
DT_SCHEMA_FILES.

v5->v6:
---
 - Rename AW9610X to aw96103.
 - Remove the encapsulation of the i2c communication interface.
 - Delete the update node.
 - Modify the usage of regulator.
 - Delete the remove and shutdown interfaces.
 - Add iio's event-related interfaces.
 - Modify the initialization process of iio.
 - Delete power_supply-related operations.
 - Modify the register names.

v6->v7:
---
 - Use __free(kfree) when allocating memory.
 - Modify the way to request the register configuration file,
   using request_firmware_nowait to request the configuration file.

v7->v8:
---
 - Delete aw96103.h.
 - Remove the function of dynamically allocating IIO-related resources.
 - Remove non-essential members from the aw96103 structure.
 - Add some comments.
 - Delete the aw96103_interrupt_clear function.
 - Delete the aw96103_version_init function.
 - Optimize code logic.
 - Modify attribute descriptions in the YAML file.

v8->v9:
---
 - Remove unnecessary function encapsulation. 
 - Use get_unaligned_le16 and get_unaligned_le32 to obtain data. 
 - Use fsleep for delay. 
 - Optimize other issues.

shuaijie wang (2):
  dt-bindings: iio: aw96103: Add bindings for aw96103/aw96105 sensor
  iio: proximity: aw96103: Add support for aw96103/aw96105 proximity
sensor

 .../iio/proximity/awinic,aw96103.yaml |  61 ++
 drivers/iio/proximity/Kconfig |  11 +
 drivers/iio/proximity/Makefile|   1 +
 drivers/iio/proximity/aw96103.c   | 844 ++
 4 files changed, 917 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/iio/proximity/awinic,aw96103.yaml
 create mode 100644 drivers/iio/proximity/aw96103.c


base-commit: 3e9bff3bbe1355805de919f688bef4baefbfd436
-- 
2.45.1




[PATCH V9 1/2] dt-bindings: iio: aw96103: Add bindings for aw96103/aw96105 sensor

2024-08-27 Thread wangshuaijie
From: shuaijie wang 

Add device tree bindings for aw96103/aw96105 proximity sensor.

Reviewed-by: Krzysztof Kozlowski 
Signed-off-by: shuaijie wang 
---
 .../iio/proximity/awinic,aw96103.yaml | 61 +++
 1 file changed, 61 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/iio/proximity/awinic,aw96103.yaml

diff --git 
a/Documentation/devicetree/bindings/iio/proximity/awinic,aw96103.yaml 
b/Documentation/devicetree/bindings/iio/proximity/awinic,aw96103.yaml
new file mode 100644
index ..7a83ceced11c
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/proximity/awinic,aw96103.yaml
@@ -0,0 +1,61 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/proximity/awinic,aw96103.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Awinic's AW96103 capacitive proximity sensor and similar
+
+maintainers:
+  - Wang Shuaijie 
+
+description: |
+  Awinic's AW96103/AW96105 proximity sensor.
+  The specific absorption rate (SAR) is a metric that measures
+  the degree of absorption of electromagnetic radiation emitted by
+  wireless devices, such as mobile phones and tablets, by human tissue.
+  In mobile phone applications, the proximity sensor is primarily
+  used to detect the proximity of the human body to the phone. When the
+  phone approaches the human body, it will actively reduce the transmit
+  power of the antenna to keep the SAR within a safe range. Therefore,
+  we also refer to the proximity sensor as a SAR sensor.
+
+properties:
+  compatible:
+enum:
+  - awinic,aw96103
+  - awinic,aw96105
+
+  reg:
+maxItems: 1
+
+  interrupts:
+description:
+  Generated by the device to announce that a close/far
+  proximity event has happened.
+maxItems: 1
+
+  vcc-supply: true
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - vcc-supply
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+i2c {
+#address-cells = <1>;
+#size-cells = <0>;
+proximity@12 {
+compatible = "awinic,aw96103";
+reg = <0x12>;
+interrupt-parent = <&gpio>;
+interrupts = <23 IRQ_TYPE_EDGE_FALLING>;
+vcc-supply = <&pp1800_prox>;
+};
+};
-- 
2.45.1




Re: [PATCH V9 0/2] Add support for aw96103/aw96105 proximity sensor

2024-09-02 Thread wangshuaijie
On Sat, 31 Aug 2024 15:07:24 +0100, ji...@kernel.org wrote:
>On Tue, 27 Aug 2024 08:02:27 +
>wangshuai...@awinic.com wrote:
>
>> From: shuaijie wang 
>> 
>> Add drivers that support Awinic aw96103/aw96105 proximity sensors.
>> 
>> The aw9610x series are high-sensitivity capacitive proximity detection
>> sensors. This device detects human proximity and assists electronic devices
>> in reducing specific absorption rate (SAR) to pass SAR related 
>> certifications.
>> The device reduces RF power and reduces harm when detecting human proximity. 
>> Increase power and improve signal quality when the human body is far away.
>> 
>> The specific absorption rate (SAR) is a metric that measures the degree of
>> absorption of electromagnetic radiation emitted by wireless devices,
>> such as mobile phones and tablets, by human tissue.
>> 
>> This patch implements device initialization, registration,
>> I/O operation handling and interrupt handling, and passed basic testing.
>I made one trivial tweak to add static to the iio_info declaration and
>applied to the togreg branch of iio.git, initially pushed out as testing
>for 0-day to see if it can find any issues we missed.
>
>Thanks,
>
>Jonathan

Hi Jonathan,

Thank you very much for your help and suggestions, which have been very
beneficial to me. May I ask if I need to continue modifying my patch?
If not, please inform me of the approximate time for review and merging.

I look forward to your reply so that I can better plan my subsequent work.

Kind regards,
Wang Shuaijie


[PATCH V10 0/2] Add support for aw96103/aw96105 proximity sensor

2024-09-04 Thread wangshuaijie
From: shuaijie wang 

Add drivers that support Awinic aw96103/aw96105 proximity sensors.

The aw9610x series are high-sensitivity capacitive proximity detection
sensors. This device detects human proximity and assists electronic devices
in reducing specific absorption rate (SAR) to pass SAR related certifications.
The device reduces RF power and reduces harm when detecting human proximity. 
Increase power and improve signal quality when the human body is far away.

The specific absorption rate (SAR) is a metric that measures the degree of
absorption of electromagnetic radiation emitted by wireless devices,
such as mobile phones and tablets, by human tissue.

This patch implements device initialization, registration,
I/O operation handling and interrupt handling, and passed basic testing.

v1->v2:
---
 - Remove unnecessary log printing.
 - Optimize comment style.
 - Issues with modifying the device tree.
 - Optimize code style.

v2->v3:
---
 - Add a description about the hardware device.
 - Remove inappropriate configuration items.
 - Modify the formatting issues.
 - Modify the structure of the driver.
 - Change the style of the driver's comments.
 - Remove unnecessary log printing.
 - Modify the function used for memory allocation.
 - Modify the driver registration process.
 - Remove the functionality related to updating firmware.
 - Change the input subsystem in the driver to the iio subsystem.
 - Modify the usage of the interrupt pin.
 
v3->v4:
---
The changes in this patch version are quite significant, and I concur
with Krzysztof's viewpoint that this driver is indeed overly complex for
the proximity sensor. Therefore, I have removed the compatibility for the
aw963xx series, and the driver will now exclusively support the aw9610x series.

 - Modify the software architecture to remove compatibility for
   the aw963xx series.
 - Optimize the parsing of register configuration files (.bin).
 - Remove unnecessary log printing.
 - Delete redefinition of true and false.
 - Remove unnecessary interfaces.
 - Optimize regulator usage.
 - Convert the I2C communication interface to regmap.

v4->v5:
---
 - Solve errors that occur when executing the make dt_binding_check 
DT_SCHEMA_FILES.

v5->v6:
---
 - Rename AW9610X to aw96103.
 - Remove the encapsulation of the i2c communication interface.
 - Delete the update node.
 - Modify the usage of regulator.
 - Delete the remove and shutdown interfaces.
 - Add iio's event-related interfaces.
 - Modify the initialization process of iio.
 - Delete power_supply-related operations.
 - Modify the register names.

v6->v7:
---
 - Use __free(kfree) when allocating memory.
 - Modify the way to request the register configuration file,
   using request_firmware_nowait to request the configuration file.

v7->v8:
---
 - Delete aw96103.h.
 - Remove the function of dynamically allocating IIO-related resources.
 - Remove non-essential members from the aw96103 structure.
 - Add some comments.
 - Delete the aw96103_interrupt_clear function.
 - Delete the aw96103_version_init function.
 - Optimize code logic.
 - Modify attribute descriptions in the YAML file.

v8->v9:
---
 - Remove unnecessary function encapsulation. 
 - Use get_unaligned_le16 and get_unaligned_le32 to obtain data. 
 - Use fsleep for delay. 
 - Optimize other issues.

v9->v10:
---
 - Modify the included header files.
 - Optimize the code style.
 - Simplify the function aw96103_wait_chip_init by using the
   function regmap_read_poll_timeout.
 - Optimize the parsing of interrupt flag bits.

shuaijie wang (2):
  dt-bindings: iio: aw96103: Add bindings for aw96103/aw96105 sensor
  iio: proximity: aw96103: Add support for aw96103/aw96105 proximity
sensor

 .../iio/proximity/awinic,aw96103.yaml |  61 ++
 drivers/iio/proximity/Kconfig |  11 +
 drivers/iio/proximity/Makefile|   1 +
 drivers/iio/proximity/aw96103.c   | 835 ++
 4 files changed, 908 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/iio/proximity/awinic,aw96103.yaml
 create mode 100644 drivers/iio/proximity/aw96103.c


base-commit: 88fac17500f4ea49c7bac136cf1b27e7b9980075
-- 
2.45.1




[PATCH V10 1/2] dt-bindings: iio: aw96103: Add bindings for aw96103/aw96105 sensor

2024-09-04 Thread wangshuaijie
From: shuaijie wang 

Add device tree bindings for aw96103/aw96105 proximity sensor.

Reviewed-by: Krzysztof Kozlowski 
Signed-off-by: shuaijie wang 
---
 .../iio/proximity/awinic,aw96103.yaml | 61 +++
 1 file changed, 61 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/iio/proximity/awinic,aw96103.yaml

diff --git 
a/Documentation/devicetree/bindings/iio/proximity/awinic,aw96103.yaml 
b/Documentation/devicetree/bindings/iio/proximity/awinic,aw96103.yaml
new file mode 100644
index ..7a83ceced11c
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/proximity/awinic,aw96103.yaml
@@ -0,0 +1,61 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/proximity/awinic,aw96103.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Awinic's AW96103 capacitive proximity sensor and similar
+
+maintainers:
+  - Wang Shuaijie 
+
+description: |
+  Awinic's AW96103/AW96105 proximity sensor.
+  The specific absorption rate (SAR) is a metric that measures
+  the degree of absorption of electromagnetic radiation emitted by
+  wireless devices, such as mobile phones and tablets, by human tissue.
+  In mobile phone applications, the proximity sensor is primarily
+  used to detect the proximity of the human body to the phone. When the
+  phone approaches the human body, it will actively reduce the transmit
+  power of the antenna to keep the SAR within a safe range. Therefore,
+  we also refer to the proximity sensor as a SAR sensor.
+
+properties:
+  compatible:
+enum:
+  - awinic,aw96103
+  - awinic,aw96105
+
+  reg:
+maxItems: 1
+
+  interrupts:
+description:
+  Generated by the device to announce that a close/far
+  proximity event has happened.
+maxItems: 1
+
+  vcc-supply: true
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - vcc-supply
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+i2c {
+#address-cells = <1>;
+#size-cells = <0>;
+proximity@12 {
+compatible = "awinic,aw96103";
+reg = <0x12>;
+interrupt-parent = <&gpio>;
+interrupts = <23 IRQ_TYPE_EDGE_FALLING>;
+vcc-supply = <&pp1800_prox>;
+};
+};
-- 
2.45.1




[PATCH V10 2/2] iio: proximity: aw96103: Add support for aw96103/aw96105 proximity sensor

2024-09-04 Thread wangshuaijie
From: shuaijie wang 

AW96103 is a low power consumption capacitive touch and proximity controller.
Each channel can be independently config as sensor input, shield output.

Channel Information:
  aw96103: 3-channel
  aw96105: 5-channel

Signed-off-by: shuaijie wang 
---
 drivers/iio/proximity/Kconfig   |  11 +
 drivers/iio/proximity/Makefile  |   1 +
 drivers/iio/proximity/aw96103.c | 835 
 3 files changed, 847 insertions(+)
 create mode 100644 drivers/iio/proximity/aw96103.c

diff --git a/drivers/iio/proximity/Kconfig b/drivers/iio/proximity/Kconfig
index 2ca3b0bc5eba..974aedf0c057 100644
--- a/drivers/iio/proximity/Kconfig
+++ b/drivers/iio/proximity/Kconfig
@@ -219,4 +219,15 @@ config VL53L0X_I2C
  To compile this driver as a module, choose M here: the
  module will be called vl53l0x-i2c.
 
+config AW96103
+   tristate "AW96103/AW96105 Awinic proximity sensor"
+   select REGMAP_I2C
+   depends on I2C
+   help
+ Say Y here to build a driver for Awinic's AW96103/AW96105 capacitive
+ proximity sensor.
+
+ To compile this driver as a module, choose M here: the
+ module will be called aw96103.
+
 endmenu
diff --git a/drivers/iio/proximity/Makefile b/drivers/iio/proximity/Makefile
index f36598380446..b1e32aa93678 100644
--- a/drivers/iio/proximity/Makefile
+++ b/drivers/iio/proximity/Makefile
@@ -21,4 +21,5 @@ obj-$(CONFIG_SX_COMMON)   += sx_common.o
 obj-$(CONFIG_SX9500)   += sx9500.o
 obj-$(CONFIG_VCNL3020) += vcnl3020.o
 obj-$(CONFIG_VL53L0X_I2C)  += vl53l0x-i2c.o
+obj-$(CONFIG_AW96103)  += aw96103.o
 
diff --git a/drivers/iio/proximity/aw96103.c b/drivers/iio/proximity/aw96103.c
new file mode 100644
index ..fc460a742bad
--- /dev/null
+++ b/drivers/iio/proximity/aw96103.c
@@ -0,0 +1,835 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * AWINIC aw96103 proximity sensor driver
+ *
+ * Author: Wang Shuaijie 
+ *
+ * Copyright (c) 2024 awinic Technology CO., LTD
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+
+#define AW_DATA_PROCESS_FACTOR 1024
+#define AW96103_CHIP_ID0xa961
+#define AW96103_BIN_VALID_DATA_OFFSET  64
+#define AW96103_BIN_DATA_LEN_OFFSET16
+#define AW96103_BIN_DATA_REG_NUM_SIZE  4
+#define AW96103_BIN_CHIP_TYPE_SIZE 8
+#define AW96103_BIN_CHIP_TYPE_OFFSET   24
+
+#define AW96103_REG_SCANCTRL0  0x
+#define AW96103_REG_STAT0  0x0090
+#define AW96103_REG_BLFILT_CH0 0x00A8
+#define AW96103_REG_BLRSTRNG_CH0   0x00B4
+#define AW96103_REG_DIFF_CH0   0x0240
+#define AW96103_REG_FWVER2 0x0410
+#define AW96103_REG_CMD0xF008
+#define AW96103_REG_IRQSRC 0xF080
+#define AW96103_REG_IRQEN  0xF084
+#define AW96103_REG_RESET  0xFF0C
+#define AW96103_REG_CHIPID 0xFF10
+#define AW96103_REG_EEDA0  0x0408
+#define AW96103_REG_EEDA1  0x040C
+#define AW96103_REG_PROXCTRL_CH0   0x00B0
+#define AW96103_REG_PROXTH0_CH00x00B8
+#define AW96103_PROXTH_CH_STEP 0x3C
+#define AW96103_THHYST_MASKGENMASK(13, 12)
+#define AW96103_INDEB_MASK GENMASK(11, 10)
+#define AW96103_OUTDEB_MASKGENMASK(9, 8)
+#define AW96103_INITOVERIRQ_MASK   BIT(0)
+#define AW96103_BLFILT_CH_STEP 0x3C
+#define AW96103_BLRSTRNG_MASK  GENMASK(5, 0)
+#define AW96103_CHIPID_MASKGENMASK(31, 16)
+#define AW96103_BLERRTRIG_MASK BIT(25)
+#define AW96103_CHAN_EN_MASK   GENMASK(5, 0)
+#define AW96103_REG_PROXCTRL_CH(x) \
+   (AW96103_REG_PROXCTRL_CH0 + (x) * AW96103_PROXTH_CH_STEP)
+
+#define AW96103_REG_PROXTH0_CH(x)  \
+   (AW96103_REG_PROXTH0_CH0 + (x) * AW96103_PROXTH_CH_STEP)
+
+/**
+ * struct aw_bin - Store the data obtained from parsing the configuration file.
+ * @chip_type: Frame header information-chip type
+ * @valid_data_len: Length of valid data obtained after parsing
+ * @valid_data_addr: The offset address of the valid data obtained
+ *  after parsing relative to info
+ * @len: The size of the bin file obtained from the firmware
+ * @data: Store the bin file obtained from the firmware
+ */
+struct aw_bin {
+   unsigned char chip_type[8];
+   unsigned int valid_data_len;
+   unsigned int valid_data_addr;
+   unsigned int len;
+   unsigned char data[] __counted_by(len);
+};
+
+enum aw96103_sar_vers {
+   AW96103 = 2,
+   AW96103A = 6,
+   AW9610

[PATCH V6 2/2] iio: proximity: aw96103: Add support for aw96103/aw96105 proximity sensor

2024-08-08 Thread wangshuaijie
From: shuaijie wang 

AW96103 is a low power consumption capacitive touch and proximity controller.
Each channel can be independently config as sensor input, shield output.

Channel Information:
  aw96103: 3-channel
  aw96105: 5-channel

Signed-off-by: shuaijie wang 
---
 drivers/iio/proximity/Kconfig   |  11 +
 drivers/iio/proximity/Makefile  |   1 +
 drivers/iio/proximity/aw96103.c | 833 
 drivers/iio/proximity/aw96103.h | 116 +
 4 files changed, 961 insertions(+)
 create mode 100644 drivers/iio/proximity/aw96103.c
 create mode 100644 drivers/iio/proximity/aw96103.h

diff --git a/drivers/iio/proximity/Kconfig b/drivers/iio/proximity/Kconfig
index 2ca3b0bc5eba..974aedf0c057 100644
--- a/drivers/iio/proximity/Kconfig
+++ b/drivers/iio/proximity/Kconfig
@@ -219,4 +219,15 @@ config VL53L0X_I2C
  To compile this driver as a module, choose M here: the
  module will be called vl53l0x-i2c.
 
+config AW96103
+   tristate "AW96103/AW96105 Awinic proximity sensor"
+   select REGMAP_I2C
+   depends on I2C
+   help
+ Say Y here to build a driver for Awinic's AW96103/AW96105 capacitive
+ proximity sensor.
+
+ To compile this driver as a module, choose M here: the
+ module will be called aw96103.
+
 endmenu
diff --git a/drivers/iio/proximity/Makefile b/drivers/iio/proximity/Makefile
index f36598380446..b1e32aa93678 100644
--- a/drivers/iio/proximity/Makefile
+++ b/drivers/iio/proximity/Makefile
@@ -21,4 +21,5 @@ obj-$(CONFIG_SX_COMMON)   += sx_common.o
 obj-$(CONFIG_SX9500)   += sx9500.o
 obj-$(CONFIG_VCNL3020) += vcnl3020.o
 obj-$(CONFIG_VL53L0X_I2C)  += vl53l0x-i2c.o
+obj-$(CONFIG_AW96103)  += aw96103.o
 
diff --git a/drivers/iio/proximity/aw96103.c b/drivers/iio/proximity/aw96103.c
new file mode 100644
index ..4e47776e6514
--- /dev/null
+++ b/drivers/iio/proximity/aw96103.c
@@ -0,0 +1,833 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * AWINIC aw96103 proximity sensor driver
+ *
+ * Author: Wang Shuaijie 
+ *
+ * Copyright (c) 2024 awinic Technology CO., LTD
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "aw96103.h"
+
+static const unsigned int aw96103_reg_default[] = {
+   0x, 0x3f3f, 0x0004, 0x0064, 0x0008, 0x0017c11e,
+   0x000c, 0x0500, 0x0010, 0x00093ffd, 0x0014, 0x19240009,
+   0x0018, 0xd81c0207, 0x001c, 0xff00, 0x0020, 0x00241900,
+   0x0024, 0x00093ff7, 0x0028, 0x58020009, 0x002c, 0xd81c0207,
+   0x0030, 0xff00, 0x0034, 0x00025800, 0x0038, 0x00093fdf,
+   0x003c, 0x7d3b0009, 0x0040, 0xd81c0207, 0x0044, 0xff00,
+   0x0048, 0x003b7d00, 0x004c, 0x00093f7f, 0x0050, 0xe9310009,
+   0x0054, 0xd81c0207, 0x0058, 0xff00, 0x005c, 0x0031e900,
+   0x0060, 0x00093dff, 0x0064, 0x1a0c0009, 0x0068, 0xd81c0207,
+   0x006c, 0xff00, 0x0070, 0x000c1a00, 0x0074, 0x80093fff,
+   0x0078, 0x043d0009, 0x007c, 0xd81c0207, 0x0080, 0xff00,
+   0x0084, 0x003d0400, 0x00a0, 0xe640, 0x00a4, 0x,
+   0x00a8, 0x010408d2, 0x00ac, 0x, 0x00b0, 0x,
+   0x00b8, 0x5fff, 0x00bc, 0x, 0x00c0, 0x,
+   0x00c4, 0x, 0x00c8, 0x, 0x00cc, 0x,
+   0x00d0, 0x, 0x00d4, 0x, 0x00d8, 0x,
+   0x00dc, 0xe6447800, 0x00e0, 0x7800, 0x00e4, 0x010408d2,
+   0x00e8, 0x, 0x00ec, 0x, 0x00f4, 0x5fff,
+   0x00f8, 0x, 0x00fc, 0x, 0x0100, 0x,
+   0x0104, 0x, 0x0108, 0x, 0x010c, 0x0200,
+   0x0110, 0x, 0x0114, 0x, 0x0118, 0xe6447800,
+   0x011c, 0x7800, 0x0120, 0x010408d2, 0x0124, 0x,
+   0x0128, 0x, 0x0130, 0x5fff, 0x0134, 0x,
+   0x0138, 0x, 0x013c, 0x, 0x0140, 0x,
+   0x0144, 0x, 0x0148, 0x0200, 0x014c, 0x,
+   0x0150, 0x, 0x0154, 0xe6447800, 0x0158, 0x7800,
+   0x015c, 0x010408d2, 0x0160, 0x, 0x0164, 0x,
+   0x016c, 0x5fff, 0x0170, 0x, 0x0174, 0x,
+   0x0178, 0x, 0x017c, 0x, 0x0180, 0x,
+   0x0184, 0x0200, 0x0188, 0x, 0x018c, 0x,
+   0x0190, 0xe6447800, 0x0194, 0x7800, 0x0198, 0x010408d2,
+   0x019c, 0x, 0x01a0, 0x, 0x01a8, 0x5fff,
+   0x01ac, 0x, 0x01b0, 0x, 0x01b4, 0x,
+   0x01b8, 0x, 0x01bc, 0x, 0x01c0, 0x0200,
+   0x01c4, 0x, 0x01c8, 0x, 0x01cc, 0xe6407800,
+   0x01d0, 0x7800, 0x01d4, 0x010408d2, 0x01d8, 0x,
+   0x01dc, 0x, 0x01e4, 0x5fff, 0x01e8, 0x,
+   0x01ec, 0x, 0x01f0, 0x, 0x01f4, 0x,
+   0x01f8, 0x, 0x01fc, 0x0200, 0x0200, 0x,
+   0x0204, 0x

[PATCH V6 0/2] Add support for aw96103/aw96105 proximity sensor

2024-08-08 Thread wangshuaijie
From: shuaijie wang 

Add drivers that support Awinic aw96103/aw96105 proximity sensors.

The aw9610x series are high-sensitivity capacitive proximity detection
sensors. This device detects human proximity and assists electronic devices
in reducing specific absorption rate (SAR) to pass SAR related certifications.
The device reduces RF power and reduces harm when detecting human proximity. 
Increase power and improve signal quality when the human body is far away.

The specific absorption rate (SAR) is a metric that measures the degree of
absorption of electromagnetic radiation emitted by wireless devices,
such as mobile phones and tablets, by human tissue.

This patch implements device initialization, registration,
I/O operation handling and interrupt handling, and passed basic testing.

v1->v2:
---
 - Remove unnecessary log printing.
 - Optimize comment style.
 - Issues with modifying the device tree.
 - Optimize code style.

v2->v3:
---
 - Add a description about the hardware device.
 - Remove inappropriate configuration items.
 - Modify the formatting issues.
 - Modify the structure of the driver.
 - Change the style of the driver's comments.
 - Remove unnecessary log printing.
 - Modify the function used for memory allocation.
 - Modify the driver registration process.
 - Remove the functionality related to updating firmware.
 - Change the input subsystem in the driver to the iio subsystem.
 - Modify the usage of the interrupt pin.
 
v3->v4:
---
The changes in this patch version are quite significant, and I concur
with Krzysztof's viewpoint that this driver is indeed overly complex for
the proximity sensor. Therefore, I have removed the compatibility for the
aw963xx series, and the driver will now exclusively support the aw9610x series.

 - Modify the software architecture to remove compatibility for
   the aw963xx series.
 - Optimize the parsing of register configuration files (.bin).
 - Remove unnecessary log printing.
 - Delete redefinition of true and false.
 - Remove unnecessary interfaces.
 - Optimize regulator usage.
 - Convert the I2C communication interface to regmap.

v4->v5:
---
 - Solve errors that occur when executing the make dt_binding_check 
DT_SCHEMA_FILES.

v5->v6:
---
 - Rename AW9610X to aw96103.
 - Remove the encapsulation of the i2c communication interface.
 - Delete the update node.
 - Modify the usage of regulator.
 - Delete the remove and shutdown interfaces.
 - Add iio's event-related interfaces.
 - Modify the initialization process of iio.
 - Delete power_supply-related operations.
 - Modify the register names.

shuaijie wang (2):
  dt-bindings: iio: aw96103: Add bindings for aw96103/aw96105 sensor
  iio: proximity: aw96103: Add support for aw96103/aw96105 proximity
sensor

 .../iio/proximity/awinic,aw96103.yaml |  63 ++
 drivers/iio/proximity/Kconfig |  11 +
 drivers/iio/proximity/Makefile|   1 +
 drivers/iio/proximity/aw96103.c   | 833 ++
 drivers/iio/proximity/aw96103.h   | 116 +++
 5 files changed, 1024 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/iio/proximity/awinic,aw96103.yaml
 create mode 100644 drivers/iio/proximity/aw96103.c
 create mode 100644 drivers/iio/proximity/aw96103.h


base-commit: 6a0e38264012809afa24113ee2162dc07f4ed22b
-- 
2.45.1




[PATCH V6 1/2] dt-bindings: iio: aw96103: Add bindings for aw96103/aw96105 sensor

2024-08-08 Thread wangshuaijie
From: shuaijie wang 

Add device tree bindings for aw96103/aw96105 proximity sensor.

Reviewed-by: Krzysztof Kozlowski 
Signed-off-by: shuaijie wang 
---
 .../iio/proximity/awinic,aw96103.yaml | 63 +++
 1 file changed, 63 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/iio/proximity/awinic,aw96103.yaml

diff --git 
a/Documentation/devicetree/bindings/iio/proximity/awinic,aw96103.yaml 
b/Documentation/devicetree/bindings/iio/proximity/awinic,aw96103.yaml
new file mode 100644
index ..54b5bc176d5c
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/proximity/awinic,aw96103.yaml
@@ -0,0 +1,63 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/proximity/awinic,aw96103.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Awinic's AW96103 capacitive proximity sensor and similar
+
+maintainers:
+  - Wang Shuaijie 
+
+description: |
+  Awinic's AW96103/AW96105 proximity sensor.
+  The specific absorption rate (SAR) is a metric that measures
+  the degree of absorption of electromagnetic radiation emitted by
+  wireless devices, such as mobile phones and tablets, by human tissue.
+  In mobile phone applications, the proximity sensor is primarily
+  used to detect the proximity of the human body to the phone. When the
+  phone approaches the human body, it will actively reduce the transmit
+  power of the antenna to keep the SAR within a safe range. Therefore,
+  we also refer to the proximity sensor as a SAR sensor.
+
+properties:
+  compatible:
+enum:
+  - awinic,aw96103
+  - awinic,aw96105
+
+  reg:
+maxItems: 1
+
+  interrupts:
+description:
+  Generated by the device to announce that a close/far
+  proximity event has happened.
+maxItems: 1
+
+  vcc-supply:
+description:
+  Optional regulator for chip, 1.7V-3.6V.
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - vcc-supply
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+i2c {
+#address-cells = <1>;
+#size-cells = <0>;
+proximity@12 {
+compatible = "awinic,aw96103";
+reg = <0x12>;
+interrupt-parent = <&gpio>;
+interrupts = <23 IRQ_TYPE_EDGE_FALLING>;
+vcc-supply = <&pp1800_prox>;
+};
+};
-- 
2.45.1