Skip to contentSkip to conversation

extcon: ptn5150: Use defines for registers

PATCH In review Krzysztof Kozlowski 2 participants 6 messages Sep 9, 2020 – Sep 11, 2020

Subsystems (2)
lore
Share & tools
lore

Krzysztof Kozlowski

author maintainer
#0 lore raw

PATCH 1/2 extcon: ptn5150: Use defines for registers

The register addresses are not continuous, so use simple defines for them. This also makes it easier to find the address for register.

No functional change.

---
 drivers/extcon/extcon-ptn5150.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/extcon/extcon-ptn5150.c +10 -12
index dda5b3a3a908..1b68f56d8372 100644
@@ -19,18 +19,16 @@
 #include <linux/gpio/consumer.h>
 
 /* PTN5150 registers */
-enum ptn5150_reg {
-	PTN5150_REG_DEVICE_ID = 0x01,
-	PTN5150_REG_CONTROL,
-	PTN5150_REG_INT_STATUS,
-	PTN5150_REG_CC_STATUS,
-	PTN5150_REG_CON_DET = 0x09,
-	PTN5150_REG_VCONN_STATUS,
-	PTN5150_REG_RESET,
-	PTN5150_REG_INT_MASK = 0x18,
-	PTN5150_REG_INT_REG_STATUS,
-	PTN5150_REG_END,
-};
+#define PTN5150_REG_DEVICE_ID			0x01
+#define PTN5150_REG_CONTROL			0x02
+#define PTN5150_REG_INT_STATUS			0x03
+#define PTN5150_REG_CC_STATUS			0x04
+#define PTN5150_REG_CON_DET			0x09
+#define PTN5150_REG_VCONN_STATUS		0x0a
+#define PTN5150_REG_RESET			0x0b
+#define PTN5150_REG_INT_MASK			0x18
+#define PTN5150_REG_INT_REG_STATUS		0x19
+#define PTN5150_REG_END				PTN5150_REG_INT_REG_STATUS
 
 #define PTN5150_DFP_ATTACHED			0x1
 #define PTN5150_UFP_ATTACHED			0x2
Signature · 1 line
2.17.1
author maintainer
#1 lore raw

PATCH 2/2 extcon: ptn5150: Do not print error during probe if nothing is attached

The commit af71b7e384cd ("extcon: ptn5150: Check current USB mode when probing") reused code for checking CC status register in the probe path to determine what is initially connected. However if nothing is connected, the CC status register will have 0x0 value and print an error message:

    ptn5150 1-003d: Unknown Port status : 0

This is not an error. Also any other unknown port status values are not really errors but unhandled cases.

Fixes af71b7e384cd ("extcon: ptn5150: Check current USB mode when probing")
---
 drivers/extcon/extcon-ptn5150.c | 1 -
 1 file changed, 1 deletion(-)
drivers/extcon/extcon-ptn5150.c +0 -1
index 1b68f56d8372..5b9a3cf8df26 100644
@@ -97,7 +97,6 @@ static void ptn5150_check_state(struct ptn5150_info *info)
 		extcon_set_state_sync(info->edev, EXTCON_USB_HOST, true);
 		break;
 	default:
-		dev_err(info->dev, "Unknown Port status : %x\n", port_status);
 		break;
 	}
 }
Signature · 1 line
2.17.1
maintainer
#2 lore raw
In reply to Krzysztof Kozlowski
Quoted 30 lines · Krzysztof Kozlowski

The register addresses are not continuous, so use simple defines for them. This also makes it easier to find the address for register.

No functional change.

---
 drivers/extcon/extcon-ptn5150.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/extcon/extcon-ptn5150.c +0 -12
index dda5b3a3a908..1b68f56d8372 100644
@@ -19,18 +19,16 @@
 #include <linux/gpio/consumer.h>
 
 /* PTN5150 registers */
-enum ptn5150_reg {
-	PTN5150_REG_DEVICE_ID = 0x01,
-	PTN5150_REG_CONTROL,
-	PTN5150_REG_INT_STATUS,
-	PTN5150_REG_CC_STATUS,
-	PTN5150_REG_CON_DET = 0x09,
-	PTN5150_REG_VCONN_STATUS,
-	PTN5150_REG_RESET,
-	PTN5150_REG_INT_MASK = 0x18,
-	PTN5150_REG_INT_REG_STATUS,
-	PTN5150_REG_END,
-};

drivers/extcon/extcon-ptn5150.c line 31

Quoted 10 lines
drivers/extcon/extcon-ptn5150.c +10 -0
+#define PTN5150_REG_DEVICE_ID			0x01
+#define PTN5150_REG_CONTROL			0x02
+#define PTN5150_REG_INT_STATUS			0x03
+#define PTN5150_REG_CC_STATUS			0x04
+#define PTN5150_REG_CON_DET			0x09
+#define PTN5150_REG_VCONN_STATUS		0x0a
+#define PTN5150_REG_RESET			0x0b
+#define PTN5150_REG_INT_MASK			0x18
+#define PTN5150_REG_INT_REG_STATUS		0x19
+#define PTN5150_REG_END				PTN5150_REG_INT_REG_STATUS

PTN5150_REG_END should be (PTN5150_REG_INT_REG_STATUS + 1) for regmap operation of PTN5150_REG_INT_REG_STATUS.

Quoted 4 lines
drivers/extcon/extcon-ptn5150.c +0 -0
 #define PTN5150_DFP_ATTACHED			0x1
 #define PTN5150_UFP_ATTACHED			0x2
 
Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics
author maintainer
#3 lore raw
Quoted 36 lines · Chanwoo Choi
Quoted 35 lines · Krzysztof Kozlowski

The register addresses are not continuous, so use simple defines for them. This also makes it easier to find the address for register.

No functional change.

---
 drivers/extcon/extcon-ptn5150.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/extcon/extcon-ptn5150.c +5 -12
index dda5b3a3a908..1b68f56d8372 100644
@@ -19,18 +19,16 @@
 #include <linux/gpio/consumer.h>
 
 /* PTN5150 registers */
-enum ptn5150_reg {
-	PTN5150_REG_DEVICE_ID = 0x01,
-	PTN5150_REG_CONTROL,
-	PTN5150_REG_INT_STATUS,
-	PTN5150_REG_CC_STATUS,
-	PTN5150_REG_CON_DET = 0x09,
-	PTN5150_REG_VCONN_STATUS,
-	PTN5150_REG_RESET,
-	PTN5150_REG_INT_MASK = 0x18,
-	PTN5150_REG_INT_REG_STATUS,
-	PTN5150_REG_END,
-};
+#define PTN5150_REG_DEVICE_ID			0x01
+#define PTN5150_REG_CONTROL			0x02
+#define PTN5150_REG_INT_STATUS			0x03
+#define PTN5150_REG_CC_STATUS			0x04
+#define PTN5150_REG_CON_DET			0x09
Quoted 8 lines

drivers/extcon/extcon-ptn5150.c line 31

Quoted 5 lines
drivers/extcon/extcon-ptn5150.c +5 -0
+#define PTN5150_REG_VCONN_STATUS		0x0a
+#define PTN5150_REG_RESET			0x0b
+#define PTN5150_REG_INT_MASK			0x18
+#define PTN5150_REG_INT_REG_STATUS		0x19
+#define PTN5150_REG_END				PTN5150_REG_INT_REG_STATUS

PTN5150_REG_END should be (PTN5150_REG_INT_REG_STATUS + 1) for regmap operation of PTN5150_REG_INT_REG_STATUS.

Why? This goes to regmap's max_register which is the last register allowed to read:

  drivers/base/regmap/regmap-debugfs.c:   for (i = 0; i <= map->max_register; i += map->reg_stride) {
  drivers/base/regmap/regmap.c:   if (map->max_register && reg > map->max_register)

regmap_get_max_register() - Report the max register value

Best regards,
Krzysztof

maintainer
#4 lore raw
Quoted 46 lines · Krzysztof Kozlowski
Quoted 36 lines · Chanwoo Choi
Quoted 35 lines · Krzysztof Kozlowski

The register addresses are not continuous, so use simple defines for them. This also makes it easier to find the address for register.

No functional change.

---
 drivers/extcon/extcon-ptn5150.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/extcon/extcon-ptn5150.c +5 -12
index dda5b3a3a908..1b68f56d8372 100644
@@ -19,18 +19,16 @@
 #include <linux/gpio/consumer.h>
 
 /* PTN5150 registers */
-enum ptn5150_reg {
-	PTN5150_REG_DEVICE_ID = 0x01,
-	PTN5150_REG_CONTROL,
-	PTN5150_REG_INT_STATUS,
-	PTN5150_REG_CC_STATUS,
-	PTN5150_REG_CON_DET = 0x09,
-	PTN5150_REG_VCONN_STATUS,
-	PTN5150_REG_RESET,
-	PTN5150_REG_INT_MASK = 0x18,
-	PTN5150_REG_INT_REG_STATUS,
-	PTN5150_REG_END,
-};
+#define PTN5150_REG_DEVICE_ID			0x01
+#define PTN5150_REG_CONTROL			0x02
+#define PTN5150_REG_INT_STATUS			0x03
+#define PTN5150_REG_CC_STATUS			0x04
+#define PTN5150_REG_CON_DET			0x09
Quoted 8 lines

drivers/extcon/extcon-ptn5150.c line 31

Quoted 5 lines
drivers/extcon/extcon-ptn5150.c +5 -0
+#define PTN5150_REG_VCONN_STATUS		0x0a
+#define PTN5150_REG_RESET			0x0b
+#define PTN5150_REG_INT_MASK			0x18
+#define PTN5150_REG_INT_REG_STATUS		0x19
+#define PTN5150_REG_END				PTN5150_REG_INT_REG_STATUS

PTN5150_REG_END should be (PTN5150_REG_INT_REG_STATUS + 1) for regmap operation of PTN5150_REG_INT_REG_STATUS.

Quoted 5 lines

Why? This goes to regmap's max_register which is the last register allowed to read:

  drivers/base/regmap/regmap-debugfs.c:   for (i = 0; i <= map->max_register; i += map->reg_stride) {
  drivers/base/regmap/regmap.c:   if (map->max_register && reg > map->max_register)

It is my mismake. You're right.
Applied them. Thanks.

Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics
author maintainer
#5 lore raw
Quoted 47 lines · Chanwoo Choi
Quoted 46 lines · Krzysztof Kozlowski
Quoted 44 lines · Chanwoo Choi
Quoted 30 lines · Krzysztof Kozlowski

The register addresses are not continuous, so use simple defines for them. This also makes it easier to find the address for register.

No functional change.

---
 drivers/extcon/extcon-ptn5150.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/extcon/extcon-ptn5150.c +0 -12
index dda5b3a3a908..1b68f56d8372 100644
@@ -19,18 +19,16 @@
 #include <linux/gpio/consumer.h>
 
 /* PTN5150 registers */
-enum ptn5150_reg {
-	PTN5150_REG_DEVICE_ID = 0x01,
-	PTN5150_REG_CONTROL,
-	PTN5150_REG_INT_STATUS,
-	PTN5150_REG_CC_STATUS,
-	PTN5150_REG_CON_DET = 0x09,
-	PTN5150_REG_VCONN_STATUS,
-	PTN5150_REG_RESET,
-	PTN5150_REG_INT_MASK = 0x18,
-	PTN5150_REG_INT_REG_STATUS,
-	PTN5150_REG_END,
-};

drivers/extcon/extcon-ptn5150.c line 31

Quoted 10 lines
drivers/extcon/extcon-ptn5150.c +10 -0
+#define PTN5150_REG_DEVICE_ID			0x01
+#define PTN5150_REG_CONTROL			0x02
+#define PTN5150_REG_INT_STATUS			0x03
+#define PTN5150_REG_CC_STATUS			0x04
+#define PTN5150_REG_CON_DET			0x09
+#define PTN5150_REG_VCONN_STATUS		0x0a
+#define PTN5150_REG_RESET			0x0b
+#define PTN5150_REG_INT_MASK			0x18
+#define PTN5150_REG_INT_REG_STATUS		0x19
+#define PTN5150_REG_END				PTN5150_REG_INT_REG_STATUS

PTN5150_REG_END should be (PTN5150_REG_INT_REG_STATUS + 1) for regmap operation of PTN5150_REG_INT_REG_STATUS.

Quoted 8 lines
Quoted 5 lines

Why? This goes to regmap's max_register which is the last register allowed to read:

  drivers/base/regmap/regmap-debugfs.c:   for (i = 0; i <= map->max_register; i += map->reg_stride) {
  drivers/base/regmap/regmap.c:   if (map->max_register && reg > map->max_register)

It is my mismake. You're right.
Applied them. Thanks.

Great, thank you!

Best regards,
Krzysztof