extcon: add Realtek DHC RTD SoC Type-C driver
Subsystems (2)
PATCH 2/2 dt-bindings: extcon: Add Realtek DHC RTD SoC Type-C
In reply to Stanley ChangDocument the device-tree bindings for Realtek SoCs Type-C. Realtek DHC (digital home center) RTD SoCs support a Type-C module.
--- .../bindings/extcon/extcon-rtk-type-c.yaml | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +77 -0
@@ -0,0 +1,77 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# Copyright 2023 Realtek Semiconductor Corporation +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/extcon/extcon-rtk-type-c.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Realtek DHC RTD SoCs USB Type-C detection + +maintainers: + - Stanley Chang <[email protected]> + +description: | + Realtek digital home center (DHC) RTD series SoCs include a type c module. + This module is able to detect the state of type c connector. + +properties: + compatible: + enum: + - realtek,rtd1295-type-c + - realtek,rtd1312c-type-c + - realtek,rtd1315e-type-c + - realtek,rtd1319-type-c + - realtek,rtd1319d-type-c + - realtek,rtd1395-type-c + - realtek,rtd1619-type-c + - realtek,rtd1619b-type-c + + reg: + maxItems: 1 + description: Address and length of register set for type-c module. + + interrupts: + maxItems: 1 + + nvmem-cells: + maxItems: 1 + description: + The phandle to nvmem cell that contains the trimming data. + If unspecified, default value is used. + + pinctrl-names: + const: default + description: A pinctrl state names "default" must be defined. + + pinctrl-0: + description: + Should contain default pinctrl. + + nvmem-cell-names: + const: usb-cal + description: + The type c parameter trimming data specified via efuse. + + realtek,rd-ctrl-gpio: + description: The gpio node to control external Rd on board. + maxItems: 1 + +required: + - compatible + - reg + - interrupts + +additionalProperties: false + +examples: + - | + type-c@7220 { + compatible = "realtek,rtd1619b-type-c"; + reg = <0x7220 0x20>; + interrupts = <0 60 4>; + + pinctrl-names = "default"; + pinctrl-0 = <&usb_cc1_pins>, <&usb_cc2_pins>; + nvmem-cells = <&otp_usb_cal>; + nvmem-cell-names = "usb-cal"; + };
Signature · 1 line
2.34.1
PATCH 1/2 extcon: add Realtek DHC RTD SoC Type-C driver
This patch adds the extcon driver for Realtek DHC (digital home center) RTD SoCs type-c module. This can be used to detect whether the port is configured as a downstream or upstream facing port. And notify the status of extcon to listeners.
--- drivers/extcon/Kconfig | 9 + drivers/extcon/Makefile | 1 + drivers/extcon/extcon-rtk-type-c.c | 1799 ++++++++++++++++++++++++++++ 3 files changed, 1809 insertions(+) create mode 100644 drivers/extcon/extcon-rtk-type-c.c
drivers/extcon/Kconfig +9 -0
@@ -190,4 +190,13 @@ config EXTCON_USBC_TUSB320 Say Y here to enable support for USB Type C cable detection extcon support using a TUSB320. +config EXTCON_RTK_TYPE_C + tristate "Realtek RTD SoC extcon Type-C Driver" + depends on ARCH_REALTEK || COMPILE_TEST + help + Say Y here to enable extcon support for USB Type C cable detection + when using the Realtek RTD SoC USB Type-C port. + The DHC (Digital Home Hub) RTD series SoC contains a type c module. + This driver will detect the status of the type-c port. + endif
drivers/extcon/Makefile +1 -0
@@ -25,3 +25,4 @@ obj-$(CONFIG_EXTCON_SM5502) += extcon-sm5502.o obj-$(CONFIG_EXTCON_USB_GPIO) += extcon-usb-gpio.o obj-$(CONFIG_EXTCON_USBC_CROS_EC) += extcon-usbc-cros-ec.o obj-$(CONFIG_EXTCON_USBC_TUSB320) += extcon-usbc-tusb320.o +obj-$(CONFIG_EXTCON_RTK_TYPE_C) += extcon-rtk-type-c.o
drivers/extcon/extcon-rtk-type-c.c new file +1799 -0
1,799 lines not on this page · raw message
Signature · 1 line
2.34.1
Quoted 19 lines · Stanley Chang
This patch adds the extcon driver for Realtek DHC (digital home center) RTD SoCs type-c module. This can be used to detect whether the port is configured as a downstream or upstream facing port. And notify the status of extcon to listeners.
Signed-off-by Stanley Chang <[email protected]>--- drivers/extcon/Kconfig | 9 + drivers/extcon/Makefile | 1 + drivers/extcon/extcon-rtk-type-c.c | 1799 ++++++++++++++++++++++++++++ 3 files changed, 1809 insertions(+) create mode 100644 drivers/extcon/extcon-rtk-type-c.cdrivers/extcon/extcon-rtk-type-c.c new file +4
-0+static struct platform_driver extcon_rtk_type_c_driver = { + .probe = extcon_rtk_type_c_probe, + .remove_new = extcon_rtk_type_c_remove, + .driver = {
drivers/extcon/extcon-rtk-type-c.c line 1797
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+ .name = "extcon-rtk-type_c", + .of_match_table = extcon_rtk_type_c_match, + .pm = DEV_PM_OPS, + }, +}; + +module_platform_driver (extcon_rtk_type_c_driver); + +MODULE_DESCRIPTION ("Realtek Extcon Type C driver" ); +MODULE_ALIAS ("platform:extcon-rtk-type-c" );
Drop alias. You have something really missing here if you need it.
drivers/extcon/extcon-rtk-type-c.c line 1799
Quoted 2 lines
drivers/extcon/extcon-rtk-type-c.c new file +2
-0+MODULE_AUTHOR ("Stanley Chang <[email protected]>" ); +MODULE_LICENSE ("GPL" );
Best regards,
Krzysztof
Re: [PATCH v1 2/2] dt-bindings: extcon: Add Realtek DHC RTD SoC Type-C
In reply to Stanley ChangQuoted 8 lines · Stanley Chang
Document the device-tree bindings for Realtek SoCs Type-C. Realtek DHC (digital home center) RTD SoCs support a Type-C module.
Signed-off-by Stanley Chang <[email protected]>--- .../bindings/extcon/extcon-rtk-type-c.yaml | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml
Filename like compatible.
Quoted 7 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +0
-0
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 8
Quoted 8 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +8
-0@@ -0,0 +1,77 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# Copyright 2023 Realtek Semiconductor Corporation +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/extcon/extcon-rtk-type-c.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Realtek DHC RTD SoCs USB Type-C detection
Type-c usually go to usb directory.
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 13
Quoted 5 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +5
-0+ +maintainers: + - Stanley Chang <[email protected]> + +description: |
Do not need '|' unless you need to preserve formatting.
Quoted 8 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +8
-0+ Realtek digital home center (DHC) RTD series SoCs include a type c module. + This module is able to detect the state of type c connector. + +properties: + compatible: + enum: + - realtek,rtd1295-type-c + - realtek,rtd1312c-type-c
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 31
Quoted 10 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +10
-0+ - realtek,rtd1315e-type-c + - realtek,rtd1319-type-c + - realtek,rtd1319d-type-c + - realtek,rtd1395-type-c + - realtek,rtd1619-type-c + - realtek,rtd1619b-type-c + + reg: + maxItems: 1 + description: Address and length of register set for type-c module.
Drop description, it's obvious.
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 44
Quoted 13 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +13
-0+ + interrupts: + maxItems: 1 + + nvmem-cells: + maxItems: 1 + description: + The phandle to nvmem cell that contains the trimming data. + If unspecified, default value is used. + + pinctrl-names: + const: default + description: A pinctrl state names "default" must be defined.
Drop, property not needed.
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 48
Quoted 4 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +4
-0+ + pinctrl-0: + description: + Should contain default pinctrl.
Drop, property not needed.
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 51
Quoted 3 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +3
-0+ + nvmem-cell-names: + const: usb-cal
items:
- const: usb-cal
and move description to nvmem-cells.
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 53
Quoted 2 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +2
-0+ description: + The type c parameter trimming data specified via efuse.
Keep same properties next to each other. nvmem-cells should be followed by nvmem-cell-names.
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 56
Quoted 3 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +3
-0+ + realtek,rd-ctrl-gpio: + description: The gpio node to control external Rd on board.
The names are always "gpios".
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 58
Quoted 2 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +2
-0+ maxItems: 1 +
You miss here connector. Probably also VBUS supply and other supplies.
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 71
Quoted 13 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +13
-0+required: + - compatible + - reg + - interrupts + +additionalProperties: false + +examples: + - | + type-c@7220 { + compatible = "realtek,rtd1619b-type-c"; + reg = <0x7220 0x20>; + interrupts = <0 60 4>;
Use proper defines for common constants.
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 76
Quoted 5 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +5
-0+ + pinctrl-names = "default"; + pinctrl-0 = <&usb_cc1_pins>, <&usb_cc2_pins>; + nvmem-cells = <&otp_usb_cal>; + nvmem-cell-names = "usb-cal";
Type-c without connector? This is incomplete.
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 77
Quoted 1 line
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +1
-0+ };
Best regards,
Krzysztof
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Stanley,
kernel test robot noticed the following build errors:
[auto build test ERROR on chanwoo-extcon/extcon-next]
[also build test ERROR on linus/master v6.5-rc7 next-20230822] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Stanley-Chang/dt-bindings-extcon-Add-Realtek-DHC-RTD-SoC-Type-C/20230822-183332 base: https://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/extcon.git extcon-next patch link: https://lore.kernel.org/r/20230822102846.4683-1-stanley_chang%40realtek.com patch subject: [PATCH v1 1/2] extcon: add Realtek DHC RTD SoC Type-C driver config: m68k-randconfig-r024-20230823 (https://download.01.org/0day-ci/archive/20230823/[email protected]/config) compiler: m68k-linux-gcc (GCC) 13.2.0 reproduce: (https://download.01.org/0day-ci/archive/20230823/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
m68k-linux-ld: drivers/extcon/extcon-rtk-type-c.o: in function `create_debug_files':
>> drivers/extcon/extcon-rtk-type-c.c:873:(.text+0x1948): undefined reference to `usb_debug_root'
vim +873 drivers/extcon/extcon-rtk-type-c.c
870
871 static inline void create_debug_files(struct type_c_data *type_c)
872 {
> 873 type_c->debug_dir = debugfs_create_dir("type_c", usb_debug_root); 874 if (!type_c->debug_dir)
875 return;
876
877 if (!debugfs_create_file("parameter", 0444, type_c->debug_dir, type_c,
878 &type_c_parameter_fops))
879 goto file_error;
880
881 if (!debugfs_create_file("status", 0444, type_c->debug_dir, type_c,
882 &type_c_status_fops))
883 goto file_error;
884
885 return;
886
887 file_error:
888 debugfs_remove_recursive(type_c->debug_dir);
889 }
890
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Stanley,
kernel test robot noticed the following build errors:
[auto build test ERROR on chanwoo-extcon/extcon-next]
[also build test ERROR on linus/master v6.5-rc7 next-20230823] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Stanley-Chang/dt-bindings-extcon-Add-Realtek-DHC-RTD-SoC-Type-C/20230822-183332 base: https://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/extcon.git extcon-next patch link: https://lore.kernel.org/r/20230822102846.4683-1-stanley_chang%40realtek.com patch subject: [PATCH v1 1/2] extcon: add Realtek DHC RTD SoC Type-C driver config: loongarch-randconfig-r053-20230823 (https://download.01.org/0day-ci/archive/20230823/[email protected]/config) compiler: loongarch64-linux-gcc (GCC) 13.2.0 reproduce: (https://download.01.org/0day-ci/archive/20230823/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
loongarch64-linux-ld: drivers/extcon/extcon-rtk-type-c.o: in function `.L394':
>> extcon-rtk-type-c.c:(.text+0x2a18): undefined reference to `usb_debug_root' >> loongarch64-linux-ld: extcon-rtk-type-c.c:(.text+0x2a1c): undefined reference to `usb_debug_root'
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
RE: [PATCH v1 2/2] dt-bindings: extcon: Add Realtek DHC RTD SoC Type-C
In reply to Krzysztof KozlowskiHi Krzysztof,
Quoted 12 lines · Stanley Chang
Quoted 9 lines
Document the device-tree bindings for Realtek SoCs Type-C. Realtek DHC (digital home center) RTD SoCs support a Type-C module.
Signed-off-by Stanley Chang <[email protected]>--- .../bindings/extcon/extcon-rtk-type-c.yaml | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yamlFilename like compatible.
I will rename.
Quoted 10 lines
Quoted 10 lines
diff --git
a/Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yamlb/Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yamlnew file mode 100644
index 000000000000..d14b9ee544b9Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +1
-0@@ -0,0 +1,77 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) # Copyright
Quoted 8 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 8
Quoted 6 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +6
-0+2023 Realtek Semiconductor Corporation %YAML 1.2 +--- +$id: http://devicetree.org/schemas/extcon/extcon-rtk-type-c.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Realtek DHC RTD SoCs USB Type-C detectionType-c usually go to usb directory.
This binding is not for a type-c controller. It is an extcon device for type-c connector detection. So I put it at extcon directory.
And I will add “connector” to the title.
title: Realtek DHC RTD SoCs USB Type-C Connector detection
Quoted 6 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 13
Quoted 4 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +4
-0+maintainers: + - Stanley Chang <[email protected]> + +description: |Do not need '|' unless you need to preserve formatting.
Ok
Quoted 13 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 12
Quoted 1 line
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +1
-0+ Realtek digital home center (DHC) RTD series SoCs include a type cmodule.
Quoted 11 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +11
-0+ This module is able to detect the state of type c connector. + +properties: + compatible: + enum: + - realtek,rtd1295-type-c + - realtek,rtd1312c-type-c + - realtek,rtd1315e-type-c + - realtek,rtd1319-type-c + - realtek,rtd1319d-type-c + - realtek,rtd1395-type-c
Quoted 8 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 31
Quoted 6 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +6
-0+ - realtek,rtd1619-type-c + - realtek,rtd1619b-type-c + + reg: + maxItems: 1 + description: Address and length of register set for type-c module.Drop description, it's obvious.
Ok.
Quoted 7 lines
Quoted 7 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +7
-0+ + interrupts: + maxItems: 1 + + nvmem-cells: + maxItems: 1 + description:
Quoted 8 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 44
Quoted 6 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +6
-0+ The phandle to nvmem cell that contains the trimming data. + If unspecified, default value is used. + + pinctrl-names: + const: default + description: A pinctrl state names "default" must be defined.Drop, property not needed.
Ok
Quoted 7 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 48
Quoted 4 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +4
-0+ + pinctrl-0: + description: + Should contain default pinctrl.Drop, property not needed.
Ok.
Quoted 14 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 51
Quoted 4 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +3
-0+ + nvmem-cell-names: + const: usb-calitems:
- const: usb-caland move description to nvmem-cells.
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 51
Quoted 2 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +2
-0+ description: + The type c parameter trimming data specified via efuse.
Quoted 8 lines
Keep same properties next to each other. nvmem-cells should be followed by nvmem-cell-names.
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 56
Quoted 3 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +3
-0+ + realtek,rd-ctrl-gpio: + description: The gpio node to control external Rd on board.The names are always "gpios".
Do you mean "realtek,rd-ctrl-gpios" ?
Quoted 6 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 56
Quoted 3 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +2
-0+ maxItems: 1 +You miss here connector. Probably also VBUS supply and other supplies.
Ok, I will add connector.
Quoted 7 lines
Quoted 7 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +7
-0+required: + - compatible + - reg + - interrupts + +additionalProperties: false +
Quoted 8 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 71
Quoted 6 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +6
-0+examples: + - | + type-c@7220 { + compatible = "realtek,rtd1619b-type-c"; + reg = <0x7220 0x20>; + interrupts = <0 60 4>;Use proper defines for common constants.
Ok, I will revise this.
Quoted 3 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 74
Quoted 3 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +3
-0+ + pinctrl-names = "default"; + pinctrl-0 = <&usb_cc1_pins>, <&usb_cc2_pins>;
You mention that the property of pinctrl not need in doc. Do I need to add the property of pintrl in example?
Quoted 4 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 76
Quoted 2 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +2
-0+ nvmem-cells = <&otp_usb_cal>; + nvmem-cell-names = "usb-cal";Type-c without connector? This is incomplete.
Ok, I will add connector.
Thanks,
Stanley
Hi Krzysztof,
Quoted 18 lines
Quoted 6 lines
drivers/extcon/extcon-rtk-type-c.c new file +4
-0+static struct platform_driver extcon_rtk_type_c_driver = { + .probe = extcon_rtk_type_c_probe, + .remove_new = extcon_rtk_type_c_remove, + .driver = {drivers/extcon/extcon-rtk-type-c.c line 1797
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+ .name = "extcon-rtk-type_c", + .of_match_table = extcon_rtk_type_c_match, + .pm = DEV_PM_OPS, + }, +}; + +module_platform_driver (extcon_rtk_type_c_driver); + +MODULE_DESCRIPTION ("Realtek Extcon Type C driver" ); +MODULE_ALIAS ("platform:extcon-rtk-type-c" );Drop alias. You have something really missing here if you need it.
Okay. I will remove.
Quoted 3 lines
drivers/extcon/extcon-rtk-type-c.c line 1799
Quoted 2 lines
drivers/extcon/extcon-rtk-type-c.c new file +2
-0+MODULE_AUTHOR ("Stanley Chang <[email protected]>" ); +MODULE_LICENSE ("GPL" );
Thanks,
Stanley
Re: [PATCH v1 2/2] dt-bindings: extcon: Add Realtek DHC RTD SoC Type-C
In reply to Stanley Chang[昌育德]Quoted 36 lines · Stanley Chang[昌育德]
Hi Krzysztof,
Quoted 12 lines · Stanley Chang
Quoted 9 lines
Document the device-tree bindings for Realtek SoCs Type-C. Realtek DHC (digital home center) RTD SoCs support a Type-C module.
Signed-off-by Stanley Chang <[email protected]>--- .../bindings/extcon/extcon-rtk-type-c.yaml | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yamlFilename like compatible.
I will rename.
Quoted 10 lines
Quoted 10 lines
diff --git
a/Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yamlb/Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yamlnew file mode 100644
index 000000000000..d14b9ee544b9Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +1
-0@@ -0,0 +1,77 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) # CopyrightQuoted 8 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 8
Quoted 6 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +6
-0+2023 Realtek Semiconductor Corporation %YAML 1.2 +--- +$id: http://devicetree.org/schemas/extcon/extcon-rtk-type-c.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Realtek DHC RTD SoCs USB Type-C detectionType-c usually go to usb directory.
Quoted 3 lines
This binding is not for a type-c controller. It is an extcon device for type-c connector detection. So I put it at extcon directory.
If this is not a type-c controller, then what is it? Explain me please what is an "extcon device" without using any Linux subsystem naming.
Quoted 3 lines
And I will add “connector” to the title.
title: Realtek DHC RTD SoCs USB Type-C Connector detection
So usb...
Quoted 8 lines
Quoted 6 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 56
Quoted 4 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +3
-0+ + realtek,rd-ctrl-gpio: + description: The gpio node to control external Rd on board.The names are always "gpios".
Do you mean "realtek,rd-ctrl-gpios" ?
Yes, like all of such properties in DTS and bindings. Everywhere.
Quoted 24 lines
Quoted 6 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 12
Quoted 3 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +2
-0+ maxItems: 1 +You miss here connector. Probably also VBUS supply and other supplies.
Ok, I will add connector.
Quoted 7 lines
Quoted 7 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +7
-0+required: + - compatible + - reg + - interrupts + +additionalProperties: false +Quoted 8 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 71
Quoted 6 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +6
-0+examples: + - | + type-c@7220 { + compatible = "realtek,rtd1619b-type-c"; + reg = <0x7220 0x20>; + interrupts = <0 60 4>;Use proper defines for common constants.
Quoted 8 lines
Ok, I will revise this.
Quoted 3 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 74
Quoted 3 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +3
-0+ + pinctrl-names = "default"; + pinctrl-0 = <&usb_cc1_pins>, <&usb_cc2_pins>;You mention that the property of pinctrl not need in doc. Do I need to add the property of pintrl in example?
Does not matter.
Best regards,
Krzysztof
RE: [PATCH v1 2/2] dt-bindings: extcon: Add Realtek DHC RTD SoC Type-C
Hi Krzysztof,
Quoted 11 lines
Quoted 8 lines
Quoted 4 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 8
Quoted 2 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +2
-0+ +title: Realtek DHC RTD SoCs USB Type-C detectionType-c usually go to usb directory.
This binding is not for a type-c controller. It is an extcon device for type-c connector detection. So I put it at extcon directory.
If this is not a type-c controller, then what is it? Explain me please what is an "extcon device" without using any Linux subsystem naming.
Sorry. "extcon device" may be the wrong name I'm using.
As far as I know, type-c controller supports PD detection, role detection, role swap and cc configuration. But in our SoC, type c module only supports role detection.
So I don't think it's a type-c controller.
I found a similar driver at drivers/extcon/extcon-usbc-cros-ec.c
It belongs to External Connector, which can detect USB Type C cables.
So our driver is an external connector driver.
Quoted 5 lines
Quoted 3 lines
And I will add “connector” to the title.
title: Realtek DHC RTD SoCs USB Type-C Connector detectionSo usb...
I refer to this binding, and it is in folder bindings/extcon. docs/devicetree/bindings/extcon/extcon-usbc-cros-ec.yaml
Title: ChromeOS EC USB Type-C Cable and Accessory Detection
Thank,
Stanley
Re: [PATCH v1 2/2] dt-bindings: extcon: Add Realtek DHC RTD SoC Type-C
Quoted 11 lines · Stanley Chang[昌育德]
Hi Krzysztof,
Quoted 9 lines
Quoted 8 lines
Quoted 4 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 8
Quoted 2 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +2
-0+ +title: Realtek DHC RTD SoCs USB Type-C detectionType-c usually go to usb directory.
This binding is not for a type-c controller. It is an extcon device for type-c connector detection. So I put it at extcon directory.
Quoted 8 lines
Quoted 2 lines
If this is not a type-c controller, then what is it? Explain me please what is an "extcon device" without using any Linux subsystem naming.
Sorry. "extcon device" may be the wrong name I'm using.
As far as I know, type-c controller supports PD detection, role detection, role swap and cc configuration. But in our SoC, type c module only supports role detection.
So I don't think it's a type-c controller.
So module handling some parts of "Type-C" is not a "Type-C controller" but if such module handles a bit more, it becomes Type-C?
Quoted 4 lines
I found a similar driver at
drivers/extcon/extcon-usbc-cros-ec.c
It belongs to External Connector, which can detect USB Type C cables.
That's a driver, not a binding...
Quoted 2 lines
So our driver is an external connector driver.
Driver yes, not binding.
Quoted 10 lines
Quoted 6 lines
Quoted 4 lines
And I will add “connector” to the title.
title: Realtek DHC RTD SoCs USB Type-C Connector detectionSo usb...
I refer to this binding, and it is in folder bindings/extcon.
docs/devicetree/bindings/extcon/extcon-usbc-cros-ec.yaml
Title: ChromeOS EC USB Type-C Cable and Accessory Detection
So maybe it should be moved as well?
extcon is a Linux framework. If you think extcon is a type of hardware, then please tell me what it is exactly. Please define it. And then I wonder why the name "extcon" is anyhow connected to Type-C USB.
Best regards,
Krzysztof
RE: [PATCH v1 2/2] dt-bindings: extcon: Add Realtek DHC RTD SoC Type-C
Hi Krzysztof,
Quoted 35 lines
-----Original Message-----
From: Krzysztof Kozlowski <[email protected]>
Sent: Thursday, August 24, 2023 4:43 PM
To: Stanley Chang[昌育德] <[email protected]>; MyungJoo Ham <[email protected]>
Cc: Chanwoo Choi <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH v1 2/2] dt-bindings: extcon: Add Realtek DHC RTD SoC Type-CExternal mail.
Quoted 13 lines · Stanley Chang[昌育德]
Hi Krzysztof,
Quoted 11 lines
Quoted 8 lines
Quoted 4 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml line 8
Quoted 2 lines
Documentation/devicetree/bindings/extcon/extcon-rtk-type-c.yaml new file +2
-0+ +title: Realtek DHC RTD SoCs USB Type-C detectionType-c usually go to usb directory.
This binding is not for a type-c controller. It is an extcon device for type-c connector detection. So I put it at extcon directory.
If this is not a type-c controller, then what is it? Explain me please what is an "extcon device" without using any Linux subsystem
naming.
Quoted 3 lines
Sorry. "extcon device" may be the wrong name I'm using.
Quoted 7 lines
Quoted 1 line
As far as I know, type-c controller supports PD detection, role detection, role
swap and cc configuration.
Quoted 2 lines
But in our SoC, type c module only supports role detection. So I don't think it's a type-c controller.
So module handling some parts of "Type-C" is not a "Type-C controller" but if such module handles a bit more, it becomes Type-C?
Due to hardware function limitation, it can't handle the full function of type-c.
Quoted 23 lines
Quoted 4 lines
I found a similar driver at
drivers/extcon/extcon-usbc-cros-ec.c
It belongs to External Connector, which can detect USB Type C cables.That's a driver, not a binding...
Quoted 2 lines
So our driver is an external connector driver.
Driver yes, not binding.
Quoted 10 lines
Quoted 6 lines
Quoted 4 lines
And I will add “connector” to the title.
title: Realtek DHC RTD SoCs USB Type-C Connector detectionSo usb...
I refer to this binding, and it is in folder bindings/extcon.
docs/devicetree/bindings/extcon/extcon-usbc-cros-ec.yaml
Title: ChromeOS EC USB Type-C Cable and Accessory Detection
Quoted 6 lines
So maybe it should be moved as well?
extcon is a Linux framework. If you think extcon is a type of hardware, then please tell me what it is exactly. Please define it. And then I wonder why the name "extcon" is anyhow connected to Type-C USB.
Well, from my point of view. extcon stands for External Connector.
HDMI connector, micro USB connector, type-c connector are all a kind of hardware, they are external connectors. I think the Type-C connector is a kind of extcon.
Of course, I agree that Type-C is part of USB.
So this binding can be usb or extcon, I don't think it is strictly restricted.
Thanks,
Stanley
Re: [PATCH v1 2/2] dt-bindings: extcon: Add Realtek DHC RTD SoC Type-C
Quoted 11 lines · Stanley Chang[昌育德]
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
Quoted 4 lines
And I will add “connector” to the title.
title: Realtek DHC RTD SoCs USB Type-C Connector detectionSo usb...
I refer to this binding, and it is in folder bindings/extcon.
docs/devicetree/bindings/extcon/extcon-usbc-cros-ec.yaml
Title: ChromeOS EC USB Type-C Cable and Accessory Detection
Quoted 8 lines
Quoted 6 lines
So maybe it should be moved as well?
extcon is a Linux framework. If you think extcon is a type of hardware, then please tell me what it is exactly. Please define it. And then I wonder why the name "extcon" is anyhow connected to Type-C USB.
Well, from my point of view. extcon stands for External Connector.
For connectors we have separate directory - connector. So no, it is not an external connector.
Anyway type "external connector" to Wikipedia or some hardware manufacturer website and find me examples of such hardware. It does not exist.
Quoted 1 line
HDMI connector, micro USB connector, type-c connector are all a kind of hardware, they are external connectors.
You did not write here bindings for connector...
Quoted 1 line
I think the Type-C connector is a kind of extcon.
There is no such thing as extcon. Otherwise please show me datasheets using this name. Show me Wikipedia article.
Quoted 3 lines
Of course, I agree that Type-C is part of USB.
So this binding can be usb or extcon, I don't think it is strictly restricted.
Best regards,
Krzysztof
RE: [PATCH v1 2/2] dt-bindings: extcon: Add Realtek DHC RTD SoC Type-C
Hi Krzysztof,
Quoted 30 lines · Stanley Chang[昌育德]
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
Quoted 4 lines
And I will add “connector” to the title.
title: Realtek DHC RTD SoCs USB Type-C Connector detectionSo usb...
I refer to this binding, and it is in folder bindings/extcon.
docs/devicetree/bindings/extcon/extcon-usbc-cros-ec.yaml
Title: ChromeOS EC USB Type-C Cable and Accessory DetectionQuoted 5 lines
Quoted 5 lines
So maybe it should be moved as well?
extcon is a Linux framework. If you think extcon is a type of hardware, then please tell me what it is exactly. Please define it. And then I wonder why the name "extcon" is anyhow connected to Type-C
USB.
Quoted 3 lines
Quoted 1 line
Well, from my point of view. extcon stands for External Connector.
For connectors we have separate directory - connector. So no, it is not an external connector.
Anyway type "external connector" to Wikipedia or some hardware manufacturer website and find me examples of such hardware. It does not exist.
Quoted 1 line
HDMI connector, micro USB connector, type-c connector are all a kind of
Quoted 13 lines
hardware, they are external connectors.
You did not write here bindings for connector...
Quoted 1 line
I think the Type-C connector is a kind of extcon.
There is no such thing as extcon. Otherwise please show me datasheets using this name. Show me Wikipedia article.
Quoted 3 lines
Of course, I agree that Type-C is part of USB.
So this binding can be usb or extcon, I don't think it is strictly restricted.
Well~
I have no position to argue this issue.
I agree to move this binding to usb directory
But what's up with this directory "Documentation/devicetree/bindings/extcon/" ? What binding can be placed in this directory?
Thanks,
Stanley
Hi,
Almost code looks good to me. I add some comment below. Please check them.
Quoted 149 lines · Stanley Chang
This patch adds the extcon driver for Realtek DHC (digital home center) RTD SoCs type-c module. This can be used to detect whether the port is configured as a downstream or upstream facing port. And notify the status of extcon to listeners.
Signed-off-by Stanley Chang <[email protected]>--- drivers/extcon/Kconfig | 9 + drivers/extcon/Makefile | 1 + drivers/extcon/extcon-rtk-type-c.c | 1799 ++++++++++++++++++++++++++++ 3 files changed, 1809 insertions(+) create mode 100644 drivers/extcon/extcon-rtk-type-c.cdrivers/extcon/Kconfig +9
-0@@ -190,4 +190,13 @@ config EXTCON_USBC_TUSB320 Say Y here to enable support for USB Type C cable detection extcon support using a TUSB320. +config EXTCON_RTK_TYPE_C + tristate "Realtek RTD SoC extcon Type-C Driver" + depends on ARCH_REALTEK || COMPILE_TEST + help + Say Y here to enable extcon support for USB Type C cable detection + when using the Realtek RTD SoC USB Type-C port. + The DHC (Digital Home Hub) RTD series SoC contains a type c module. + This driver will detect the status of the type-c port. + endifdrivers/extcon/Makefile +1
-0@@ -25,3 +25,4 @@ obj-$(CONFIG_EXTCON_SM5502) += extcon-sm5502.o obj-$(CONFIG_EXTCON_USB_GPIO) += extcon-usb-gpio.o obj-$(CONFIG_EXTCON_USBC_CROS_EC) += extcon-usbc-cros-ec.o obj-$(CONFIG_EXTCON_USBC_TUSB320) += extcon-usbc-tusb320.o +obj-$(CONFIG_EXTCON_RTK_TYPE_C) += extcon-rtk-type-c.odrivers/extcon/extcon-rtk-type-c.c new file +103
-0@@ -0,0 +1,1799 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* * extcon-rtk-type-c.c - Realtek Extcon Type C driver +* +* Copyright (C) 2023 Realtek Semiconductor Corporation +* +*/ + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/platform_device.h> +#include <linux/of.h> +#include <linux/of_address.h> +#include <linux/of_irq.h> +#include <linux/of_gpio.h> +#include <linux/io.h> +#include <linux/interrupt.h> +#include <linux/syscalls.h> +#include <linux/suspend.h> +#include <linux/debugfs.h> +#include <linux/extcon.h> +#include <linux/extcon-provider.h> +#include <linux/sys_soc.h> +#include <linux/nvmem-consumer.h> +#include <linux/usb/otg.h> +#include <linux/usb/typec.h> + +struct cc_param { +u32 rp_4p7k_code; +u32 rp_36k_code; +u32 rp_12k_code; +u32 rd_code; +u32 ra_code; +u32 vref_2p6v; +u32 vref_1p23v; +u32 vref_0p8v; +u32 vref_0p66v; +u32 vref_0p4v; +u32 vref_0p2v; +u32 vref_1_1p6v; +u32 vref_0_1p6v; +}; + +struct type_c_cfg { +int parameter_ver;/* Parameter version */ +int cc_dfp_mode; +struct cc_param cc1_param; +struct cc_param cc2_param; + +u32 debounce_val; +bool use_defalut_parameter; +}; + +struct type_c_data { +void __iomem *reg_base; +struct device *dev; +struct extcon_dev *edev; + +u32 irq; + +/* rd control GPIO only for rtd1295 */ +unsigned int rd_ctrl_gpio; + +/* Parameters */ +struct type_c_cfg *type_c_cfg; +u32 dfp_mode_rp_en; +u32 ufp_mode_rd_en; +u32 cc1_code; +u32 cc2_code; +u32 cc1_vref; +u32 cc2_vref; +u32 debounce;/* 1b,1us 7f,4.7us */ + +/* type_c state */ +int connect_change; +#define CONNECT_CHANGE 1 +#define CONNECT_NO_CHANGE 0 +int cc_mode;/* cc is host or device */ +#define IN_HOST_MODE 0x10 +#define IN_DEVICE_MODE 0x20 +int is_attach; +#define IN_ATTACH 1 +#define TO_ATTACH 1 +#define IN_DETACH 0 +#define TO_DETACH 0 +int at_cc1; +#define AT_CC1 1 +#define AT_CC2 0 + +u32 int_status; +u32 cc_status; +/* protect the data member */ +spinlock_t lock; +struct delayed_work delayed_work; + +bool rd_en_at_first; + +struct dentry *debug_dir; + +#ifdef CONFIG_TYPEC +struct typec_port *port; +#endif /* CONFIG_TYPEC */
drivers/extcon/extcon-rtk-type-c.c line 113
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+}; + +/* Type C register offset */ +#define USB_TYPEC_CTRL_CC1_0 0x0 +#define USB_TYPEC_CTRL_CC1_1 0x4 +#define USB_TYPEC_CTRL_CC2_0 0x8 +#define USB_TYPEC_CTRL_CC2_1 0xC +#define USB_TYPEC_STS 0x10 +#define USB_TYPEC_CTRL 0x14 +#define USB_DBUS_PWR_CTRL 0x18
nitpick.
Above defintions uses 'space' to keep the left-aligned of value. But, below defintions doesn't keep the left-aligned of value.
I recommend that you better to use the same style for the readability.
Quoted 132 lines
drivers/extcon/extcon-rtk-type-c.c new file +132
-0+ +#define ENABLE_CC1 0x1 +#define ENABLE_CC2 0x2 +#define DISABLE_CC 0x0 + +/* Bit mapping USB_TYPEC_CTRL_CC1_0 and USB_TYPEC_CTRL_CC2_0 */ +#define PLR_EN BIT(29) +#define CC_SWITCH_MASK (BIT(29) | BIT(28) | BIT(27)) +#define CC_CODE_MASK (0xfffff << 7) +#define rp4pk_code (val) ((0x1f & (val)) << 22) +#define code_rp4pk (val) (((val) >> 22) & 0x1f) +#define rp36k_code (val) ((0x1f & (val)) << 17) +#define code_rp36k (val) (((val) >> 17) & 0x1f) +#define rp12k_code (val) ((0x1f & (val)) << 12) +#define code_rp12k (val) (((val) >> 12) & 0x1f) +#define rd_code (val) ((0x1f & (val)) << 7) +#define code_rd (val) (((val) >> 7) & 0x1f) +#define dfp_mode (val) ((0x3 & (val)) << 5) +#define EN_RP4P7K BIT(4) +#define EN_RP36K BIT(3) +#define EN_RP12K BIT(2) +#define EN_RD BIT(1) +#define EN_CC_DET BIT(0) + +#define CC_MODE_UFP 0x0 +#define CC_MODE_DFP_USB 0x1 +#define CC_MODE_DFP_1_5 0x2 +#define CC_MODE_DFP_3_0 0x3 + +/* +* PARAMETER_V0: +* Realtek Kylin rtd1295 +* Realtek Hercules rtd1395 +* Realtek Thor rtd1619 +* Realtek Hank rtd1319 +* Realtek Groot rtd1312c +* PARAMETER_V1: +* Realtek Stark rtd1619b +* Realtek Parker rtd1319d +* Realtek Danvers rtd1315e +*/ +enum parameter_version { +PARAMETER_V0 =0 , +PARAMETER_V1 =1 , +}; + +/* Bit mapping USB_TYPEC_CTRL_CC1_1 and USB_TYPEC_CTRL_CC2_1 */ +#define V0_vref_2p6v (val) ((0xf & (val)) << 26)/* Bit 29 for groot */ +#define V0_vref_1p23v (val) ((0xf & (val)) << 22) +#define V0_vref_0p8v (val) ((0xf & (val)) << 18) +#define V0_vref_0p66v (val) ((0xf & (val)) << 14) +#define V0_vref_0p4v (val) ((0x7 & (val)) << 11) +#define V0_vref_0p2v (val) ((0x7 & (val)) << 8) +#define V0_vref_1_1p6v (val) ((0xf & (val)) << 4) +#define V0_vref_0_1p6v (val) ((0xf & (val)) << 0) + +#define V0_decode_2p6v (val) (((val) >> 26) & 0xf)/* Bit 29 for groot */ +#define V0_decode_1p23v (val) (((val) >> 22) & 0xf) +#define V0_decode_0p8v (val) (((val) >> 18) & 0xf) +#define V0_decode_0p66v (val) (((val) >> 14) & 0xf) +#define V0_decode_0p4v (val) (((val) >> 11) & 0x7) +#define V0_decode_0p2v (val) (((val) >> 8) & 0x7) +#define V0_decode_1_1p6v (val) (((val) >> 4) & 0xf) +#define V0_decode_0_1p6v (val) (((val) >> 0) & 0xf) + +/* new Bit mapping USB_TYPEC_CTRL_CC1_1 and USB_TYPEC_CTRL_CC2_1 */ +#define V1_vref_2p6v (val) ((0xf & (val)) << 28) +#define V1_vref_1p23v (val) ((0xf & (val)) << 24) +#define V1_vref_0p8v (val) ((0xf & (val)) << 20) +#define V1_vref_0p66v (val) ((0xf & (val)) << 16) +#define V1_vref_0p4v (val) ((0xf & (val)) << 12) +#define V1_vref_0p2v (val) ((0xf & (val)) << 8) +#define V1_vref_1_1p6v (val) ((0xf & (val)) << 4) +#define V1_vref_0_1p6v (val) ((0xf & (val)) << 0) + +#define V1_decode_2p6v (val) (((val) >> 28) & 0xf) +#define V1_decode_1p23v (val) (((val) >> 24) & 0xf) +#define V1_decode_0p8v (val) (((val) >> 20) & 0xf) +#define V1_decode_0p66v (val) (((val) >> 16) & 0xf) +#define V1_decode_0p4v (val) (((val) >> 12) & 0xf) +#define V1_decode_0p2v (val) (((val) >> 8) & 0xf) +#define V1_decode_1_1p6v (val) (((val) >> 4) & 0xf) +#define V1_decode_0_1p6v (val) (((val) >> 0) & 0xf) + +/* Bit mapping USB_TYPEC_STS */ +#define DET_STS 0x7 +#define CC1_DET_STS (DET_STS) +#define CC2_DET_STS (DET_STS << 3) +#define DET_STS_RA 0x1 +#define DET_STS_RD 0x3 +#define DET_STS_RP 0x1 +#define CC1_DET_STS_RA (DET_STS_RA) +#define CC1_DET_STS_RD (DET_STS_RD) +#define CC1_DET_STS_RP (DET_STS_RP) +#define CC2_DET_STS_RA (DET_STS_RA << 3) +#define CC2_DET_STS_RD (DET_STS_RD << 3) +#define CC2_DET_STS_RP (DET_STS_RP << 3) + +/* Bit mapping USB_TYPEC_CTRL */ +#define CC2_INT_EN BIT(11) +#define CC1_INT_EN BIT(10) +#define CC2_INT_STS BIT(9) +#define CC1_INT_STS BIT(8) +#define DEBOUNCE_TIME_MASK 0xff +#define DEBOUNCE_EN BIT(0) +#define ENABLE_TYPE_C_DETECT (CC1_INT_EN | CC2_INT_EN) +#define ALL_CC_INT_STS (CC1_INT_STS | CC2_INT_STS) + +/* Parameter */ +#define DETECT_TIME 50/* ms */ + +static const unsigned int usb_type_c_cable[] = { +EXTCON_USB , +EXTCON_USB_HOST , +EXTCON_NONE , +}; + +enum usb_data_roles { +DR_NONE , +DR_HOST , +DR_DEVICE , +}; + +static const struct soc_device_attribute rtk_soc_kylin[] = { + { .family ="Realtek Kylin" , }, + {/* empty */ } +}; + +static int rtd129x_switch_type_c_plug_config (struct type_c_data *type_c, +int dr_mode,int cc) +{ +void __iomem *reg = type_c->reg_base +USB_TYPEC_CTRL_CC1_0 ;
drivers/extcon/extcon-rtk-type-c.c line 255
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+int val_cc; + +#define TYPE_C_EN_SWITCH BIT(29) +#define TYPE_C_TXRX_SEL (BIT(28) | BIT(27)) +#define TYPE_C_SWITCH_MASK (TYPE_C_EN_SWITCH | TYPE_C_TXRX_SEL) +#define TYPE_C_ENABLE_CC1 TYPE_C_EN_SWITCH +#define TYPE_C_ENABLE_CC2 (TYPE_C_EN_SWITCH | TYPE_C_TXRX_SEL) +#define TYPE_C_DISABLE_CC ~TYPE_C_SWITCH_MASK + + val_cc =readl (reg);
I'd like you to use regmap interface to access the register by using regmap_read, regmap_write. You can create the regmap instance via devm_regmap_init_mmio() on probe instead of using 'type_c->reg_base' at the multipe point.
For example,
struct regmap_config rtk_regmap_config = {
.reg_bits = 32,
.val_bits = 32,
};
void __iomem *base;
base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
if (IS_ERR(base))
return PTR_ERR(base);
regmap = devm_regmap_init_mmio(dev, base, &rtk_regmap_config);
---
And then just call regmap_read without any calculation between
base address and specific register.
regmap_read(regmap, USB_TYPEC_CTRL_CC1_0)Quoted 5 lines
drivers/extcon/extcon-rtk-type-c.c new file +5
-0+ val_cc &= ~TYPE_C_SWITCH_MASK ; + +if (cc ==DISABLE_CC ) { + val_cc &=TYPE_C_DISABLE_CC ; + }else if (cc ==ENABLE_CC1 ) {
drivers/extcon/extcon-rtk-type-c.c line 270
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+ val_cc |=TYPE_C_ENABLE_CC1 ; + }else if (cc ==ENABLE_CC2 ) { + val_cc |=TYPE_C_ENABLE_CC2 ; + }else { +dev_err (type_c->dev,"%s: Error cc setting cc=0x%x\n" , __func__, cc); +return -EINVAL ; + } +writel (val_cc, reg); + +mdelay (1 );
Maybe, it depends on h/w constraints. Better to explain the comment of why adding delay at here. Also, this patch uses mdelay/msleep at the multiple point. I recommend that add the comment of reason to add mdelay/msleep.
Quoted 99 lines
drivers/extcon/extcon-rtk-type-c.c new file +99
-0+ +dev_dbg (type_c->dev,"%s: cc=0x%x val_cc=0x%x usb_typec_ctrl_cc1_0=0x%x\n" , + __func__, cc, val_cc,readl (reg)); + +return 0 ; +} + +static inline void switch_type_c_plug_config (struct type_c_data *type_c, +int dr_mode,int cc) +{ +int ret =0 ; + +if (soc_device_match (rtk_soc_kylin)) + ret =rtd129x_switch_type_c_plug_config (type_c, dr_mode, cc); + +if (ret <0 ) +dev_err (type_c->dev,"%s: Error set type c plug config\n" , + __func__); +} + +static void switch_type_c_dr_mode (struct type_c_data *type_c,int dr_mode,int cc) +{ +bool is_host = false; +bool is_device = false; +bool polarity = false; +bool vbus = false; +bool ss = true; + +switch_type_c_plug_config (type_c, dr_mode, cc); +if (cc ==ENABLE_CC2 ) + polarity = true; + +switch (dr_mode) { +case USB_DR_MODE_HOST : + is_host = true; +break ; +case USB_DR_MODE_PERIPHERAL : + is_device = true; + vbus = true; +break ; +default : +dev_dbg (type_c->dev,"%s dr_mode=%d ==> no host or device\n" , + __func__, dr_mode); +break ; + } + +dev_dbg (type_c->dev,"%s is_host=%d is_device=%d vbus=%d polarity=%d\n" , + __func__, is_host, is_device, vbus, polarity); + +/* for EXTCON_USB device mode */ +extcon_set_state (type_c->edev,EXTCON_USB , is_device); +extcon_set_property (type_c->edev,EXTCON_USB , +EXTCON_PROP_USB_VBUS , + (union extcon_property_value )(int )vbus); +extcon_set_property (type_c->edev,EXTCON_USB , +EXTCON_PROP_USB_TYPEC_POLARITY , + (union extcon_property_value )(int )polarity); +extcon_set_property (type_c->edev,EXTCON_USB , +EXTCON_PROP_USB_SS , + (union extcon_property_value )(int )ss); + +/* for EXTCON_USB_HOST host mode */ +extcon_set_state (type_c->edev,EXTCON_USB_HOST , is_host); +extcon_set_property (type_c->edev,EXTCON_USB_HOST , +EXTCON_PROP_USB_VBUS , + (union extcon_property_value )(int )vbus); +extcon_set_property (type_c->edev,EXTCON_USB_HOST , +EXTCON_PROP_USB_TYPEC_POLARITY , + (union extcon_property_value )(int )polarity); +extcon_set_property (type_c->edev,EXTCON_USB_HOST , +EXTCON_PROP_USB_SS , + (union extcon_property_value )(int )ss); + +/* sync EXTCON_USB and EXTCON_USB_HOST */ +extcon_sync (type_c->edev,EXTCON_USB ); +extcon_sync (type_c->edev,EXTCON_USB_HOST ); + +#ifdef CONFIG_TYPEC> + if (type_c->port) { +switch (dr_mode) { +case USB_DR_MODE_HOST : +typec_set_data_role (type_c->port,TYPEC_HOST ); +typec_set_pwr_role (type_c->port,TYPEC_SOURCE ); +break ; +case USB_DR_MODE_PERIPHERAL : +typec_set_data_role (type_c->port,TYPEC_DEVICE ); +typec_set_pwr_role (type_c->port,TYPEC_SINK ); +break ; +default : +dev_dbg (type_c->dev,"%s unknown dr_mode=%d\n" , + __func__, dr_mode); +break ; + } + } +#endif +} + +/* device attached/detached */ +static int device_attached (struct type_c_data *type_c,u32 cc) +{
drivers/extcon/extcon-rtk-type-c.c line 380
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+void __iomem *reg = type_c->reg_base +USB_TYPEC_CTRL ; + +cancel_delayed_work (&type_c->delayed_work); + +switch_type_c_dr_mode (type_c,USB_DR_MODE_HOST , cc); + +writel (ENABLE_TYPE_C_DETECT |readl (reg), reg); + +return 0 ; +}
device_attached() funciton is same with host_connected() except for USR_BR_MODE_HOST, USB_DR_MODE_PERIPHERAL setting.
You can use only one function with 3rd paramer (dr_mode) as following in order to reduce the duplicated code.
For example,
static int connector_attached(struct type_c_data *type_c, u32 cc, int dr_mode)
drivers/extcon/extcon-rtk-type-c.c line 393
Quoted 13 lines
drivers/extcon/extcon-rtk-type-c.c new file +13
-0+ +static int device_detached (struct type_c_data *type_c,u32 cc) +{ +void __iomem *reg = type_c->reg_base +USB_TYPEC_CTRL ; + +writel (~ENABLE_TYPE_C_DETECT &readl (reg), reg); + +switch_type_c_dr_mode (type_c,0 , cc); + +schedule_delayed_work (&type_c->delayed_work,msecs_to_jiffies (DETECT_TIME )); + +return 0 ; +}
device_detached is perfectly same with host_disconnected. You can use the only one function to reduce the duplicated code
Quoted 125 lines
drivers/extcon/extcon-rtk-type-c.c new file +125
-0+ +/* host connect/disconnect*/ +static int host_connected (struct type_c_data *type_c,u32 cc) +{ +void __iomem *reg = type_c->reg_base +USB_TYPEC_CTRL ; + +cancel_delayed_work (&type_c->delayed_work); + +switch_type_c_dr_mode (type_c,USB_DR_MODE_PERIPHERAL , cc); + +writel (ENABLE_TYPE_C_DETECT |readl (reg), reg); +return 0 ; +} + +static int host_disconnected (struct type_c_data *type_c,u32 cc) +{ +void __iomem *reg = type_c->reg_base +USB_TYPEC_CTRL ; + +writel (~ENABLE_TYPE_C_DETECT &readl (reg), reg); + +switch_type_c_dr_mode (type_c,0 , cc); + +schedule_delayed_work (&type_c->delayed_work,msecs_to_jiffies (DETECT_TIME )); + +return 0 ; +} + +/* detect host device switch */ +static int __detect_host_device (struct type_c_data *type_c,u32 rp_or_rd_en) +{ +struct device *dev = type_c->dev; +void __iomem *reg_base = type_c->reg_base; +unsigned int gpio = type_c->rd_ctrl_gpio; +u32 cc1_config, cc2_config, default_ctrl; +u32 cc1_switch =0 ; + + default_ctrl =readl (reg_base +USB_TYPEC_CTRL ) &DEBOUNCE_TIME_MASK ; +writel (default_ctrl, reg_base +USB_TYPEC_CTRL ); + + cc1_config =readl (reg_base +USB_TYPEC_CTRL_CC1_0 ); + cc2_config =readl (reg_base +USB_TYPEC_CTRL_CC2_0 ); + + cc1_config &= ~EN_CC_DET ; + cc2_config &= ~EN_CC_DET ; +writel (cc1_config, reg_base +USB_TYPEC_CTRL_CC1_0 ); +writel (cc2_config, reg_base +USB_TYPEC_CTRL_CC2_0 ); + +if (soc_device_match (rtk_soc_kylin)) + cc1_switch = cc1_config &CC_SWITCH_MASK ; + + cc1_config &=CC_CODE_MASK ; + cc1_config |= rp_or_rd_en | cc1_switch; + cc2_config &=CC_CODE_MASK ; + cc2_config |= rp_or_rd_en; +writel (cc2_config, reg_base +USB_TYPEC_CTRL_CC2_0 ); +writel (cc1_config, reg_base +USB_TYPEC_CTRL_CC1_0 ); + +/* For kylin to disable external rd control gpio */ +if (soc_device_match (rtk_soc_kylin)) { +if (gpio !=-1 &&gpio_is_valid (gpio)) { +if (gpio_direction_output (gpio,1 )) +dev_err (dev,"%s ERROR rd_ctrl_gpio=1 fail\n" , __func__); + } + } + + cc1_config |=EN_CC_DET ; + cc2_config |=EN_CC_DET ; +writel (cc1_config, reg_base +USB_TYPEC_CTRL_CC1_0 ); +writel (cc2_config, reg_base +USB_TYPEC_CTRL_CC2_0 ); + +return 0 ; +} + +static int detect_device (struct type_c_data *type_c) +{ +return __detect_host_device (type_c, type_c->dfp_mode_rp_en); +} + +static int detect_host (struct type_c_data *type_c) +{ +return __detect_host_device (type_c, type_c->ufp_mode_rd_en); +} + +static int host_device_switch_detection (struct type_c_data *type_c) +{ +if (type_c->cc_mode ==IN_HOST_MODE ) { + type_c->cc_mode =IN_DEVICE_MODE ; +detect_host (type_c); + }else { + type_c->cc_mode =IN_HOST_MODE ; +detect_device (type_c); + } + +return 0 ; +} + +static int detect_type_c_state (struct type_c_data *type_c) +{ +struct device *dev = type_c->dev; +void __iomem *reg_base = type_c->reg_base; +u32 int_status, cc_status, cc_status_check; +unsigned long flags; + +spin_lock_irqsave (&type_c->lock, flags); + + int_status =readl (reg_base +USB_TYPEC_CTRL ); + cc_status =readl (reg_base +USB_TYPEC_STS ); + + type_c->connect_change =CONNECT_NO_CHANGE ; + +switch (type_c->cc_mode | type_c->is_attach) { +case IN_HOST_MODE |IN_ATTACH : +if (((cc_status &CC1_DET_STS ) ==CC1_DET_STS ) && type_c->at_cc1 ==AT_CC1 ) { +dev_dbg (dev,"IN host mode and cc1 device detach (cc_status=0x%x)" , + cc_status); + type_c->is_attach =TO_DETACH ; + type_c->connect_change =CONNECT_CHANGE ; + }else if (((cc_status &CC2_DET_STS ) ==CC2_DET_STS ) && + type_c->at_cc1 ==AT_CC2 ) { +dev_dbg (dev,"IN host mode and cc2 device detach (cc_status=0x%x)" , + cc_status); + type_c->is_attach =TO_DETACH ; + type_c->connect_change =CONNECT_CHANGE ; + } +break ;
drivers/extcon/extcon-rtk-type-c.c line 528
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+case IN_HOST_MODE |IN_DETACH : + cc_status_check =readl (reg_base +USB_TYPEC_STS ); +if (cc_status_check != (CC1_DET_STS |CC2_DET_STS )) { +if (in_interrupt ()) { +mdelay (300 ); + }else { +spin_unlock_irqrestore (&type_c->lock, flags); +msleep (300 ); +spin_lock_irqsave (&type_c->lock, flags); + }
As I commented above, it seems that there are some hardware constrains which requires the some delay when changing the h/w state.
I recommend that you need to add the comment of why adding the delays/sleep.
Quoted 49 lines
drivers/extcon/extcon-rtk-type-c.c new file +49
-0+ cc_status_check =readl (reg_base +USB_TYPEC_STS ); + } +if (cc_status != cc_status_check) { +dev_warn (dev,"IN_HOST_MODE: cc_status (0x%x) != cc_status_check (0x%x)\n" , + cc_status, cc_status_check); + cc_status =readl (reg_base +USB_TYPEC_STS ); + } + +if ((cc_status &CC1_DET_STS ) ==CC1_DET_STS_RD ) { +dev_dbg (dev,"IN host mode and cc1 device attach (cc_status=0x%x)" , + cc_status); + type_c->is_attach =TO_ATTACH ; + type_c->at_cc1 =AT_CC1 ; + type_c->connect_change =CONNECT_CHANGE ; + }else if ((cc_status &CC2_DET_STS ) ==CC2_DET_STS_RD ) { +dev_dbg (dev,"In host mode and cc2 device attach (cc_status=0x%x)" , + cc_status); + type_c->is_attach =TO_ATTACH ; + type_c->at_cc1 =AT_CC2 ; + type_c->connect_change =CONNECT_CHANGE ; + } +break ; +case IN_DEVICE_MODE |IN_ATTACH : +if ((cc_status &CC1_DET_STS ) <CC1_DET_STS_RP || + (cc_status &CC2_DET_STS ) <CC2_DET_STS_RP ) { +/* Add a sw debounce to filter cc signal sent from apple pd adapter */ +mdelay (5 ); + cc_status_check =readl (reg_base +USB_TYPEC_STS ); + +if (cc_status != cc_status_check) { +dev_dbg (dev,"IN_DEVICE_MODE: cc_status (0x%x) != cc_status_check (0x%x) maybe use a pd adapter\n" , + cc_status, cc_status_check); + cc_status = cc_status_check; + } + } + +if ((cc_status &CC1_DET_STS ) <CC1_DET_STS_RP && type_c->at_cc1 ==AT_CC1 ) { +dev_dbg (dev,"IN device mode and cc1 host disconnect (cc_status=0x%x)" , + cc_status); + type_c->is_attach =TO_DETACH ; + type_c->connect_change =CONNECT_CHANGE ; + }else if ((cc_status &CC2_DET_STS ) <CC2_DET_STS_RP && + type_c->at_cc1 ==AT_CC2 ) { +dev_dbg (dev,"IN device mode and cc2 host disconnect (cc_status=0x%x)" , + cc_status); + type_c->is_attach =TO_DETACH ; + type_c->connect_change =CONNECT_CHANGE ; + } +break ;
drivers/extcon/extcon-rtk-type-c.c line 587
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+case IN_DEVICE_MODE |IN_DETACH : + cc_status_check =readl (reg_base +USB_TYPEC_STS ); +if (cc_status_check !=0x0 ) { +if (in_interrupt ()) { +mdelay (300 ); + }else { +spin_unlock_irqrestore (&type_c->lock, flags); +msleep (300 ); +spin_lock_irqsave (&type_c->lock, flags); + }
ditto.
Quoted 40 lines
drivers/extcon/extcon-rtk-type-c.c new file +40
-0+ cc_status_check =readl (reg_base +USB_TYPEC_STS ); + } + +if (cc_status != cc_status_check) { +dev_warn (dev,"IN_DEVICE_MODE: cc_status (0x%x) != cc_status_check (0x%x)\n" , + cc_status, cc_status_check); + cc_status =readl (reg_base +USB_TYPEC_STS ); + } + +if ((cc_status &CC1_DET_STS ) >=CC1_DET_STS_RP ) { +dev_dbg (dev,"IN device mode and cc1 host connect (cc_status=0x%x)" , + cc_status); + type_c->at_cc1 =AT_CC1 ; + type_c->is_attach =TO_ATTACH ; + type_c->connect_change =CONNECT_CHANGE ; + }else if ((cc_status &CC2_DET_STS ) >=CC2_DET_STS_RP ) { +dev_dbg (dev,"IN device mode and cc2 host connect (cc_status=0x%x)" , + cc_status); + type_c->at_cc1 =AT_CC2 ; + type_c->is_attach =TO_ATTACH ; + type_c->connect_change =CONNECT_CHANGE ; + } +break ; +default : +dev_err (dev,"error host or device mode (cc_mode=%d, is_attach=%d) " , + type_c->cc_mode, type_c->is_attach); + } + + type_c->int_status = int_status; + type_c->cc_status = cc_status; + +spin_unlock_irqrestore (&type_c->lock, flags); +return 0 ; +} + +static void host_device_switch (struct work_struct *work) +{ + struct type_c_data *type_c = container_of(work, struct type_c_data, + delayed_work.work); +struct device *dev = type_c->dev;
drivers/extcon/extcon-rtk-type-c.c line 637
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+unsigned long flags; +int connect_change =0 ; +int cc_mode =0 ; +int is_attach =0 ; +int at_cc1 =0 ; + +spin_lock_irqsave (&type_c->lock, flags); +if (type_c->connect_change) + connect_change = type_c->connect_change; +spin_unlock_irqrestore (&type_c->lock, flags);
Better to convert this code as following if type_c->connect_change is NULL, you can reduce the lock/unlok operation of spin_lock. As you knew, spin_lock is expensive.
if (type_c->connect_change) {
spin_lock_irqsave(&type_c->lock, flags);
connect_change = type_c->connect_change;
spin_unlock_irqrestore(&type_c->lock, flags);
}Quoted 9 lines
drivers/extcon/extcon-rtk-type-c.c new file +9
-0+ +if (!connect_change) +detect_type_c_state (type_c); + +spin_lock_irqsave (&type_c->lock, flags); +if (type_c->connect_change) { + connect_change = type_c->connect_change; + cc_mode = type_c->cc_mode; + is_attach = type_c->is_attach;
drivers/extcon/extcon-rtk-type-c.c line 656
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+ at_cc1 = type_c->at_cc1; + type_c->connect_change =CONNECT_NO_CHANGE ; + }else { +host_device_switch_detection (type_c); + +schedule_delayed_work (&type_c->delayed_work,msecs_to_jiffies (DETECT_TIME )); + } +spin_unlock_irqrestore (&type_c->lock, flags); + +if (connect_change) {
nitpick.
You can reduce the depth of indentation when connector_change is 0 by changing the code as following: If possible, I always to try to reduce the indentation depth for the readability.
if (!connect_change)
return
dev_dbg(dev, "%s: usb cable connection change\n", __func__);
if (cc_mode == IN_HOST_MODE) {
......Quoted 45 lines
drivers/extcon/extcon-rtk-type-c.c new file +45
-0+dev_dbg (dev,"%s: usb cable connection change\n" , __func__); +if (cc_mode ==IN_HOST_MODE ) { +if (is_attach && at_cc1) +device_attached (type_c,ENABLE_CC1 ); +else if (is_attach && !at_cc1) +device_attached (type_c,ENABLE_CC2 ); +else +device_detached (type_c,DISABLE_CC ); + }else if (cc_mode ==IN_DEVICE_MODE ) { +if (is_attach && at_cc1) +host_connected (type_c,ENABLE_CC1 ); +else if (is_attach && !at_cc1) +host_connected (type_c,ENABLE_CC2 ); +else +host_disconnected (type_c,DISABLE_CC ); + }else { +dev_err (dev,"Error: IN unknown mode %d to %s at %s (cc_status=0x%x)\n" , + cc_mode, is_attach ?"attach" :"detach" , + at_cc1 ?"cc1" :"cc2" , type_c->cc_status); + } +dev_info (dev,"Connection change OK: IN %s mode to %s at %s (cc_status=0x%x)\n" , + cc_mode ==IN_HOST_MODE ?"host" :"device" , + is_attach ?"attach" :"detach" , + at_cc1 ?"cc1" :"cc2" , type_c->cc_status); + } +} + +static irqreturn_t type_c_detect_irq (int irq,void *__data) +{ +struct type_c_data *type_c = (struct type_c_data *)__data; +struct device *dev = type_c->dev; +void __iomem *reg = type_c->reg_base +USB_TYPEC_CTRL ; +unsigned long flags; + +detect_type_c_state (type_c); + +spin_lock_irqsave (&type_c->lock, flags); + +if (type_c->connect_change) { +dev_dbg (dev,"%s: IN %s mode to %s (at %s interrupt) int_status=0x%x, cc_status=0x%x" , + __func__, + type_c->cc_mode ==IN_HOST_MODE ?"host" :"device" , + type_c->is_attach ?"attach" :"detach" , + type_c->at_cc1 ?"cc1" :"cc2" , + type_c->int_status, type_c->cc_status);
drivers/extcon/extcon-rtk-type-c.c line 711
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+ +/* clear interrupt status */ +writel (~ALL_CC_INT_STS &readl (reg), reg); + +cancel_delayed_work (&type_c->delayed_work); +schedule_delayed_work (&type_c->delayed_work,msecs_to_jiffies (0 )); + }else { +static int local_count; + +if (local_count++ >10 ) {
It seems that clear interrupt status once every 10 times.
I think that it is not generic. You need to add the comment of why trying to clear interrupt once every 10 times.
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+/* clear interrupt status */ +writel (~ALL_CC_INT_STS &readl (reg), reg); + local_count =0 ; + } + } + +spin_unlock_irqrestore (&type_c->lock, flags); + +return IRQ_HANDLED ; +}
(snip)
drivers/extcon/extcon-rtk-type-c.c line 1238
Quoted 9 lines
drivers/extcon/extcon-rtk-type-c.c new file +9
-0+ +static int extcon_rtk_type_c_init (struct type_c_data *type_c) +{ +struct device *dev = type_c->dev; +unsigned long flags; +void __iomem *reg; +int val; + + if ((type_c->rd_ctrl_gpio != -1) &&
nitpick.
After getting the gpio number by using of_get_named_gpio() function, type_c->rd_ctrl_gpio is error number which is returned of_get_named_gpio().
In order to specify the more correctly, how about changing it as following? Because I don't use the '-1' constant variable without any constant defintion. Someone cannot understand the meaning of '-1'.
if (!(type_c->rd_ctrl_gpio < 0))
Quoted 28 lines
drivers/extcon/extcon-rtk-type-c.c new file +28
-0+ gpio_request(type_c->rd_ctrl_gpio, dev->of_node->name)) +dev_err (dev,"%s ERROR Request rd_ctrl_gpio (id=%d) fail\n" , + __func__, type_c->rd_ctrl_gpio); + +spin_lock_irqsave (&type_c->lock, flags); + +/* set parameter */ + reg = type_c->reg_base +USB_TYPEC_CTRL_CC1_0 ; + val =readl (reg); + val = (~CC_CODE_MASK & val) | (type_c->cc1_code &CC_CODE_MASK ); +writel (val, reg); + + reg = type_c->reg_base +USB_TYPEC_CTRL_CC2_0 ; + val =readl (reg); + val = (~CC_CODE_MASK & val) | (type_c->cc2_code &CC_CODE_MASK ); + + reg = type_c->reg_base +USB_TYPEC_CTRL_CC1_1 ; +writel (type_c->cc1_vref, reg); + + reg = type_c->reg_base +USB_TYPEC_CTRL_CC2_1 ; +writel (type_c->cc2_vref, reg); + + reg = type_c->reg_base +USB_TYPEC_CTRL ; + val =readl (reg); + val = (~DEBOUNCE_TIME_MASK & val) | (type_c->debounce &DEBOUNCE_TIME_MASK ); + +dev_info (dev,"First check USB_DR_MODE_PERIPHERAL" ); + type_c->cc_mode =IN_DEVICE_MODE ;
drivers/extcon/extcon-rtk-type-c.c line 1276
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+ type_c->is_attach =IN_DETACH ; + type_c->connect_change =CONNECT_NO_CHANGE ; + +detect_host (type_c); + +spin_unlock_irqrestore (&type_c->lock, flags); + +schedule_delayed_work (&type_c->delayed_work,msecs_to_jiffies (0 )); + +#ifdef CONFIG_TYPEC
Don'n need to check 'CONFIG_TYPEC' defintion wiht ifdef. 'ifdef' might make the code more complicated.
If type_c is optional, just print warning message
when typec_regiser_port returns error.
This patch is already check whether 'type_c->port' is NULL or not to handle the code related to typec.
Quoted 1 line
drivers/extcon/extcon-rtk-type-c.c new file +1
-0+if (!type_c->port) {
(snip)
Quoted 460 lines
drivers/extcon/extcon-rtk-type-c.c new file +460
-0+ + type_c->port =typec_register_port (type_c->dev, &typec_cap); +if (IS_ERR (type_c->port)) +return PTR_ERR (type_c->port); + }> +#endif /* CONFIG_TYPEC */ + +return 0 ; +} + +static int extcon_rtk_type_c_edev_register (struct type_c_data *type_c) +{ +struct device *dev = type_c->dev; +int ret =0 ; + + type_c->edev =devm_extcon_dev_allocate (dev, usb_type_c_cable); +if (IS_ERR (type_c->edev)) { +dev_err (dev,"failed to allocate extcon device\n" ); +return -ENOMEM ; + } + + ret =devm_extcon_dev_register (dev, type_c->edev); +if (ret <0 ) { +dev_err (dev,"failed to register extcon device\n" ); +return ret; + } + +extcon_set_property_capability (type_c->edev,EXTCON_USB , +EXTCON_PROP_USB_VBUS ); +extcon_set_property_capability (type_c->edev,EXTCON_USB , +EXTCON_PROP_USB_TYPEC_POLARITY ); +extcon_set_property_capability (type_c->edev,EXTCON_USB , +EXTCON_PROP_USB_SS ); + +extcon_set_property_capability (type_c->edev,EXTCON_USB_HOST , +EXTCON_PROP_USB_VBUS ); +extcon_set_property_capability (type_c->edev,EXTCON_USB_HOST , +EXTCON_PROP_USB_TYPEC_POLARITY ); +extcon_set_property_capability (type_c->edev,EXTCON_USB_HOST , +EXTCON_PROP_USB_SS ); + +return ret; +} + +static int extcon_rtk_type_c_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct type_c_data *type_c; +const struct type_c_cfg *type_c_cfg; +unsigned int gpio; +int ret =0 ; + + type_c =devm_kzalloc (dev,sizeof (*type_c),GFP_KERNEL ); +if (!type_c) +return -ENOMEM ; + + type_c->reg_base =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (type_c->reg_base)) +return PTR_ERR (type_c->reg_base); + + type_c->dev = dev; + + type_c->irq =irq_of_parse_and_map (pdev->dev.of_node,0 ); +if (type_c->irq <=0 ) { +dev_err (&pdev->dev,"Type C driver with no IRQ. Check %s setup!\n" , +dev_name (&pdev->dev)); + ret = -ENODEV ; + goto err1; + } + + ret =devm_request_irq (dev, type_c->irq, type_c_detect_irq, +IRQF_SHARED ,"type_c_detect" , type_c); + +spin_lock_init (&type_c->lock); + + type_c->rd_ctrl_gpio =-1 ; +if (soc_device_match (rtk_soc_kylin)) { + gpio =of_get_named_gpio (dev->of_node,"realtek,rd-ctrl-gpio" ,0 ); +if (gpio_is_valid (gpio)) { + type_c->rd_ctrl_gpio = gpio; +dev_dbg (dev,"%s get rd-ctrl-gpio (id=%d) OK\n" , __func__, gpio); + }else { +dev_err (dev,"Error rd_ctrl-gpio no found" ); + } + } + + type_c_cfg =of_device_get_match_data (dev); +if (!type_c_cfg) { +dev_err (dev,"type_c config are not assigned!\n" ); +return -EINVAL ; + } + + type_c->type_c_cfg =devm_kzalloc (dev,sizeof (*type_c_cfg),GFP_KERNEL ); + +memcpy (type_c->type_c_cfg, type_c_cfg,sizeof (*type_c_cfg)); + +if (setup_type_c_parameter (type_c)) { +dev_err (dev,"ERROR: %s to setup type c parameter!!" , __func__); + ret = -EINVAL ; + goto err1; + } + +INIT_DELAYED_WORK (&type_c->delayed_work, host_device_switch); + + ret =extcon_rtk_type_c_init (type_c); +if (ret) { +dev_err (dev,"%s failed to init type_c\n" , __func__); + goto err1; + } + +platform_set_drvdata (pdev, type_c); + + ret =extcon_rtk_type_c_edev_register (type_c); + +create_debug_files (type_c); + +return 0 ; + +err1: +dev_err (&pdev->dev,"%s: Probe fail, %d\n" , __func__, ret); + +return ret; +} + +static void extcon_rtk_type_c_remove (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct type_c_data *type_c =dev_get_drvdata (dev); +u32 default_ctrl; +unsigned long flags; + +remove_debug_files (type_c); + +#ifdef CONFIG_TYPEC +if (type_c->port) { +typec_unregister_port (type_c->port); + type_c->port =NULL ; + } +#endif + +cancel_delayed_work_sync (&type_c->delayed_work); +flush_delayed_work (&type_c->delayed_work); +WARN_ON_ONCE (delayed_work_pending (&type_c->delayed_work)); + +spin_lock_irqsave (&type_c->lock, flags); +/* disable interrupt */ + default_ctrl =readl (type_c->reg_base +USB_TYPEC_CTRL ) & +DEBOUNCE_TIME_MASK ; +writel (default_ctrl, type_c->reg_base +USB_TYPEC_CTRL ); + +/* disable cc detect, rp, rd */ +writel (PLR_EN , type_c->reg_base +USB_TYPEC_CTRL_CC1_0 ); +writel (0 , type_c->reg_base +USB_TYPEC_CTRL_CC2_0 ); + +spin_unlock_irqrestore (&type_c->lock, flags); + +free_irq (type_c->irq, type_c); +} + +static const struct type_c_cfg rtd1295_type_c_cfg = { + .parameter_ver =PARAMETER_V0 , + .cc_dfp_mode =CC_MODE_DFP_3_0 , + .cc1_param = { .rp_4p7k_code =0xb , + .rp_36k_code =0x17 , + .rp_12k_code =0x10 , + .rd_code =0 , + .ra_code =0 , + .vref_2p6v =0x0 , + .vref_1p23v =0x0 , + .vref_0p8v =0x3 , + .vref_0p66v =0x0 , + .vref_0p4v =0x0 , + .vref_0p2v =0x4 , + .vref_1_1p6v =0 , + .vref_0_1p6v =0 }, + .cc2_param = { .rp_4p7k_code =0xc , + .rp_36k_code =0x17 , + .rp_12k_code =0x12 , + .rd_code =0 , + .ra_code =0 , + .vref_2p6v =0x2 , + .vref_1p23v =0x0 , + .vref_0p8v =0x3 , + .vref_0p66v =0x0 , + .vref_0p4v =0x0 , + .vref_0p2v =0x5 , + .vref_1_1p6v =0 , + .vref_0_1p6v =0 }, + .debounce_val =0x7f ,/* 1b,1us 7f,4.7us */ + .use_defalut_parameter = false, +}; + +static const struct type_c_cfg rtd1395_type_c_cfg = { + .parameter_ver =PARAMETER_V0 , + .cc_dfp_mode =CC_MODE_DFP_3_0 , + .cc1_param = { .rp_4p7k_code =0xc , + .rp_36k_code =0xb , + .rp_12k_code =0xe , + .rd_code =0x10 , + .ra_code =0x0 , + .vref_2p6v =0x0 , + .vref_1p23v =0x1 , + .vref_0p8v =0x0 , + .vref_0p66v =0x0 , + .vref_0p4v =0x3 , + .vref_0p2v =0x0 , + .vref_1_1p6v =0x7 , + .vref_0_1p6v =0x7 }, + .cc2_param = { .rp_4p7k_code =0xb , + .rp_36k_code =0x9 , + .rp_12k_code =0xe , + .rd_code =0xf , + .ra_code =0x0 , + .vref_2p6v =0x1 , + .vref_1p23v =0x3 , + .vref_0p8v =0x3 , + .vref_0p66v =0x2 , + .vref_0p4v =0x3 , + .vref_0p2v =0x2 , + .vref_1_1p6v =0x7 , + .vref_0_1p6v =0x7 }, + .debounce_val =0x7f ,/* 1b,1us 7f,4.7us */ + .use_defalut_parameter = false, +}; + +static const struct type_c_cfg rtd1619_type_c_cfg = { + .parameter_ver =PARAMETER_V0 , + .cc_dfp_mode =CC_MODE_DFP_3_0 , + .cc1_param = { .rp_4p7k_code =0xc , + .rp_36k_code =0xf , + .rp_12k_code =0xe , + .rd_code =0x11 , + .ra_code =0x0 , + .vref_2p6v =0x5 , + .vref_1p23v =0x7 , + .vref_0p8v =0xa , + .vref_0p66v =0xa , + .vref_0p4v =0x3 , + .vref_0p2v =0x2 , + .vref_1_1p6v =0x7 , + .vref_0_1p6v =0x7 }, + .cc2_param = { .rp_4p7k_code =0xc , + .rp_36k_code =0xf , + .rp_12k_code =0xe , + .rd_code =0xf , + .ra_code =0x0 , + .vref_2p6v =0x5 , + .vref_1p23v =0x8 , + .vref_0p8v =0xa , + .vref_0p66v =0xa , + .vref_0p4v =0x3 , + .vref_0p2v =0x2 , + .vref_1_1p6v =0x7 , + .vref_0_1p6v =0x7 }, + .debounce_val =0x7f ,/* 1b,1us 7f,4.7us */ + .use_defalut_parameter = false, +}; + +static const struct type_c_cfg rtd1319_type_c_cfg = { + .parameter_ver =PARAMETER_V0 , + .cc_dfp_mode =CC_MODE_DFP_1_5 , + .cc1_param = { .rp_4p7k_code =0x9 , + .rp_36k_code =0xe , + .rp_12k_code =0x9 , + .rd_code =0x9 , + .ra_code =0x7 , + .vref_2p6v =0x3 , + .vref_1p23v =0x7 , + .vref_0p8v =0x7 , + .vref_0p66v =0x6 , + .vref_0p4v =0x2 , + .vref_0p2v =0x3 , + .vref_1_1p6v =0x4 , + .vref_0_1p6v =0x7 }, + .cc2_param = { .rp_4p7k_code =0x8 , + .rp_36k_code =0xe , + .rp_12k_code =0x9 , + .rd_code =0x9 , + .ra_code =0x7 , + .vref_2p6v =0x3 , + .vref_1p23v =0x7 , + .vref_0p8v =0x7 , + .vref_0p66v =0x6 , + .vref_0p4v =0x3 , + .vref_0p2v =0x3 , + .vref_1_1p6v =0x6 , + .vref_0_1p6v =0x7 }, + .debounce_val =0x7f ,/* 1b,1us 7f,4.7us */ + .use_defalut_parameter = false, +}; + +static const struct type_c_cfg rtd1312c_type_c_cfg = { + .parameter_ver =PARAMETER_V0 , + .cc_dfp_mode =CC_MODE_DFP_1_5 , + .cc1_param = { .rp_4p7k_code =0xe , + .rp_36k_code =0xc , + .rp_12k_code =0xc , + .rd_code =0xa , + .ra_code =0x3 , + .vref_2p6v =0xa , + .vref_1p23v =0x7 , + .vref_0p8v =0x7 , + .vref_0p66v =0x7 , + .vref_0p4v =0x4 , + .vref_0p2v =0x4 , + .vref_1_1p6v =0x7 , + .vref_0_1p6v =0x7 }, + .cc2_param = { .rp_4p7k_code =0xe , + .rp_36k_code =0xc , + .rp_12k_code =0xc , + .rd_code =0xa , + .ra_code =0x3 , + .vref_2p6v =0xa , + .vref_1p23v =0x7 , + .vref_0p8v =0x7 , + .vref_0p66v =0x7 , + .vref_0p4v =0x4 , + .vref_0p2v =0x4 , + .vref_1_1p6v =0x7 , + .vref_0_1p6v =0x7 }, + .debounce_val =0x7f ,/* 1b,1us 7f,4.7us */ + .use_defalut_parameter = false, +}; + +static const struct type_c_cfg rtd1619b_type_c_cfg = { + .parameter_ver =PARAMETER_V1 , + .cc_dfp_mode =CC_MODE_DFP_1_5 , + .cc1_param = { .rp_4p7k_code =0xf , + .rp_36k_code =0xf , + .rp_12k_code =0xf , + .rd_code =0xf , + .ra_code =0x7 , + .vref_2p6v =0x9 , + .vref_1p23v =0x7 , + .vref_0p8v =0x9 , + .vref_0p66v =0x8 , + .vref_0p4v =0x7 , + .vref_0p2v =0x9 , + .vref_1_1p6v =0x7 , + .vref_0_1p6v =0x7 }, + .cc2_param = { .rp_4p7k_code =0xf , + .rp_36k_code =0xf , + .rp_12k_code =0xf , + .rd_code =0xf , + .ra_code =0x7 , + .vref_1p23v =0x7 , + .vref_0p8v =0x9 , + .vref_0p66v =0x8 , + .vref_0p4v =0x7 , + .vref_0p2v =0x8 , + .vref_1_1p6v =0x7 , + .vref_0_1p6v =0x7 }, + .debounce_val =0x7f ,/* 1b,1us 7f,4.7us */ + .use_defalut_parameter = false, +}; + +static const struct type_c_cfg rtd1319d_type_c_cfg = { + .parameter_ver =PARAMETER_V1 , + .cc_dfp_mode =CC_MODE_DFP_1_5 , + .cc1_param = { .rp_4p7k_code =0xe , + .rp_36k_code =0x3 , + .rp_12k_code =0xe , + .rd_code =0xf , + .ra_code =0x6 , + .vref_2p6v =0x7 , + .vref_1p23v =0x7 , + .vref_0p8v =0x8 , + .vref_0p66v =0x7 , + .vref_0p4v =0x7 , + .vref_0p2v =0x7 , + .vref_1_1p6v =0x7 , + .vref_0_1p6v =0x7 }, + .cc2_param = { .rp_4p7k_code =0xe , + .rp_36k_code =0x3 , + .rp_12k_code =0xe , + .rd_code =0xf , + .ra_code =0x6 , + .vref_2p6v =0x7 , + .vref_1p23v =0x7 , + .vref_0p8v =0x8 , + .vref_0p66v =0x7 , + .vref_0p4v =0x7 , + .vref_0p2v =0x8 , + .vref_1_1p6v =0x7 , + .vref_0_1p6v =0x7 }, + .debounce_val =0x7f ,/* 1b,1us 7f,4.7us */ + .use_defalut_parameter = false, +}; + +static const struct type_c_cfg rtd1315e_type_c_cfg = { + .parameter_ver =PARAMETER_V1 , + .cc_dfp_mode =CC_MODE_DFP_1_5 , + .cc1_param = { .rp_4p7k_code =0xe , + .rp_36k_code =0x3 , + .rp_12k_code =0xe , + .rd_code =0xf , + .ra_code =0x6 , + .vref_2p6v =0x7 , + .vref_1p23v =0x7 , + .vref_0p8v =0x8 , + .vref_0p66v =0x7 , + .vref_0p4v =0x7 , + .vref_0p2v =0x7 , + .vref_1_1p6v =0x7 , + .vref_0_1p6v =0x7 }, + .cc2_param = { .rp_4p7k_code =0xe , + .rp_36k_code =0x3 , + .rp_12k_code =0xe , + .rd_code =0xf , + .ra_code =0x6 , + .vref_2p6v =0x7 , + .vref_1p23v =0x7 , + .vref_0p8v =0x8 , + .vref_0p66v =0x7 , + .vref_0p4v =0x7 , + .vref_0p2v =0x8 , + .vref_1_1p6v =0x7 , + .vref_0_1p6v =0x7 }, + .debounce_val =0x7f ,/* 1b,1us 7f,4.7us */ + .use_defalut_parameter = false, +}; + +static const struct of_device_id extcon_rtk_type_c_match[] = { + { .compatible ="realtek,rtd1295-type-c" , .data = &rtd1295_type_c_cfg }, + { .compatible ="realtek,rtd1312c-type-c" , .data = &rtd1312c_type_c_cfg }, + { .compatible ="realtek,rtd1315e-type-c" , .data = &rtd1315e_type_c_cfg }, + { .compatible ="realtek,rtd1319-type-c" , .data = &rtd1319_type_c_cfg }, + { .compatible ="realtek,rtd1319d-type-c" , .data = &rtd1319d_type_c_cfg }, + { .compatible ="realtek,rtd1395-type-c" , .data = &rtd1395_type_c_cfg }, + { .compatible ="realtek,rtd1619-type-c" , .data = &rtd1619_type_c_cfg }, + { .compatible ="realtek,rtd1619b-type-c" , .data = &rtd1619b_type_c_cfg }, + {}, +}; +MODULE_DEVICE_TABLE (of, extcon_rtk_type_c_match); + +#ifdef CONFIG_PM_SLEEP +static int extcon_rtk_type_c_prepare (struct device *dev) +{ +struct type_c_data *type_c =dev_get_drvdata (dev); +u32 default_ctrl; +unsigned long flags; + +cancel_delayed_work_sync (&type_c->delayed_work); +flush_delayed_work (&type_c->delayed_work); +WARN_ON_ONCE (delayed_work_pending (&type_c->delayed_work)); + +spin_lock_irqsave (&type_c->lock, flags); +/* disable interrupt */ + default_ctrl =readl (type_c->reg_base +USB_TYPEC_CTRL ) & +DEBOUNCE_TIME_MASK ; +writel (default_ctrl, type_c->reg_base +USB_TYPEC_CTRL ); + +/* disable cc detect, rp, rd */ +writel (PLR_EN , type_c->reg_base +USB_TYPEC_CTRL_CC1_0 ); +writel (0 , type_c->reg_base +USB_TYPEC_CTRL_CC2_0 ); + +spin_unlock_irqrestore (&type_c->lock, flags); + +return 0 ; +} +
drivers/extcon/extcon-rtk-type-c.c line 1758
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+static void extcon_rtk_type_c_complete (struct device *dev) +{ +/* nothing */ +} + +static int extcon_rtk_type_c_suspend (struct device *dev) +{ +struct type_c_data *type_c =dev_get_drvdata (dev); + +if (type_c->rd_ctrl_gpio !=-1 )
ditto.
Quoted 41 lines
drivers/extcon/extcon-rtk-type-c.c new file +41
-0+gpio_free (type_c->rd_ctrl_gpio); + +return 0 ; +} + +static int extcon_rtk_type_c_resume (struct device *dev) +{ +struct type_c_data *type_c =dev_get_drvdata (dev); + +extcon_rtk_type_c_init (type_c); + +return 0 ; +} + +static const struct dev_pm_ops extcon_rtk_type_c_pm_ops = { +SET_LATE_SYSTEM_SLEEP_PM_OPS (extcon_rtk_type_c_suspend, extcon_rtk_type_c_resume) + .prepare = extcon_rtk_type_c_prepare, + .complete = extcon_rtk_type_c_complete, +}; + +#define DEV_PM_OPS (&extcon_rtk_type_c_pm_ops) +#else +#define DEV_PM_OPS NULL +#endif /* CONFIG_PM_SLEEP */ + +static struct platform_driver extcon_rtk_type_c_driver = { + .probe = extcon_rtk_type_c_probe, + .remove_new = extcon_rtk_type_c_remove, + .driver = { + .name ="extcon-rtk-type_c" , + .of_match_table = extcon_rtk_type_c_match, + .pm =DEV_PM_OPS , + }, +}; + +module_platform_driver (extcon_rtk_type_c_driver); + +MODULE_DESCRIPTION ("Realtek Extcon Type C driver" ); +MODULE_ALIAS ("platform:extcon-rtk-type-c" ); +MODULE_AUTHOR ("Stanley Chang <[email protected]>" ); +MODULE_LICENSE ("GPL" );
Signature · 3 lines
Best Regards, Samsung Electronics Chanwoo Choi
Hi Chanwoo,
Quoted 4 lines
Almost code looks good to me. I add some comment below. Please check them.
Thanks for your review.
Quoted 170 lines · Stanley Chang
Quoted 10 lines
This patch adds the extcon driver for Realtek DHC (digital home center) RTD SoCs type-c module. This can be used to detect whether the port is configured as a downstream or upstream facing port. And notify the status of extcon to listeners.
Signed-off-by Stanley Chang <[email protected]>--- drivers/extcon/Kconfig | 9 + drivers/extcon/Makefile | 1 + drivers/extcon/extcon-rtk-type-c.c | 1799++++++++++++++++++++++++++++
drivers/extcon/Kconfig config EXTCON_USBC_TUSB320 · line 190
Quoted 9 lines
3 files changed, 1809 insertions(+) create mode 100644 drivers/extcon/extcon-rtk-type-c.cdrivers/extcon/Kconfig +0
-0@@ -190,4 +190,13 @@ config EXTCON_USBC_TUSB320 Say Y here to enable support for USB Type C cable detectionextcon
drivers/extcon/Kconfig config EXTCON_USBC_TUSB320
Quoted 9 lines
drivers/extcon/Kconfig +7
-0support using a TUSB320. +config EXTCON_RTK_TYPE_C + tristate "Realtek RTD SoC extcon Type-C Driver" + depends on ARCH_REALTEK || COMPILE_TEST + help + Say Y here to enable extcon support for USB Type C cable detection + when using the Realtek RTD SoC USB Type-C port. + The DHC (Digital Home Hub) RTD series SoC contains a type cmodule.
Review
Quoted 13 lines
drivers/extcon/Kconfig +2
-0+ This driver will detect the status of the type-c port. + endifdrivers/extcon/Makefile +1
-0@@ -25,3 +25,4 @@ obj-$(CONFIG_EXTCON_SM5502) += extcon-sm5502.o obj-$(CONFIG_EXTCON_USB_GPIO) += extcon-usb-gpio.o obj-$(CONFIG_EXTCON_USBC_CROS_EC) += extcon-usbc-cros-ec.o obj-$(CONFIG_EXTCON_USBC_TUSB320) += extcon-usbc-tusb320.o +obj-$(CONFIG_EXTCON_RTK_TYPE_C) += extcon-rtk-type-c.o(quoted diff) +0
-0
b/drivers/extcon/extcon-rtk-type-c.cQuoted 108 lines
new file mode 100644
index 000000000000..04d4d5128bdbdrivers/extcon/extcon-rtk-type-c.c new file +103
-0@@ -0,0 +1,1799 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* * extcon-rtk-type-c.c - Realtek Extcon Type C driver +* +* Copyright (C) 2023 Realtek Semiconductor Corporation +* +*/ + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/platform_device.h> +#include <linux/of.h> +#include <linux/of_address.h> +#include <linux/of_irq.h> +#include <linux/of_gpio.h> +#include <linux/io.h> +#include <linux/interrupt.h> +#include <linux/syscalls.h> +#include <linux/suspend.h> +#include <linux/debugfs.h> +#include <linux/extcon.h> +#include <linux/extcon-provider.h> +#include <linux/sys_soc.h> +#include <linux/nvmem-consumer.h> +#include <linux/usb/otg.h> +#include <linux/usb/typec.h> + +struct cc_param { +u32 rp_4p7k_code; +u32 rp_36k_code; +u32 rp_12k_code; +u32 rd_code; +u32 ra_code; +u32 vref_2p6v; +u32 vref_1p23v; +u32 vref_0p8v; +u32 vref_0p66v; +u32 vref_0p4v; +u32 vref_0p2v; +u32 vref_1_1p6v; +u32 vref_0_1p6v; +}; + +struct type_c_cfg { +int parameter_ver;/* Parameter version */ +int cc_dfp_mode; +struct cc_param cc1_param; +struct cc_param cc2_param; + +u32 debounce_val; +bool use_defalut_parameter; +}; + +struct type_c_data { +void __iomem *reg_base; +struct device *dev; +struct extcon_dev *edev; + +u32 irq; + +/* rd control GPIO only for rtd1295 */ +unsigned int rd_ctrl_gpio; + +/* Parameters */ +struct type_c_cfg *type_c_cfg; +u32 dfp_mode_rp_en; +u32 ufp_mode_rd_en; +u32 cc1_code; +u32 cc2_code; +u32 cc1_vref; +u32 cc2_vref; +u32 debounce;/* 1b,1us 7f,4.7us */ + +/* type_c state */ +int connect_change; +#define CONNECT_CHANGE 1 +#define CONNECT_NO_CHANGE 0 +int cc_mode;/* cc is host or device */ +#define IN_HOST_MODE 0x10 +#define IN_DEVICE_MODE 0x20 +int is_attach; +#define IN_ATTACH 1 +#define TO_ATTACH 1 +#define IN_DETACH 0 +#define TO_DETACH 0 +int at_cc1; +#define AT_CC1 1 +#define AT_CC2 0 + +u32 int_status; +u32 cc_status; +/* protect the data member */ +spinlock_t lock; +struct delayed_work delayed_work; + +bool rd_en_at_first; + +struct dentry *debug_dir; + +#ifdef CONFIG_TYPEC +struct typec_port *port; +#endif /* CONFIG_TYPEC */ drivers/extcon/extcon-rtk-type-c.c line 113
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+}; + +/* Type C register offset */ +#define USB_TYPEC_CTRL_CC1_0 0x0 +#define USB_TYPEC_CTRL_CC1_1 0x4 +#define USB_TYPEC_CTRL_CC2_0 0x8 +#define USB_TYPEC_CTRL_CC2_1 0xC +#define USB_TYPEC_STS 0x10 +#define USB_TYPEC_CTRL 0x14 +#define USB_DBUS_PWR_CTRL 0x18nitpick.
Above defintions uses 'space' to keep the left-aligned of value. But, below defintions doesn't keep the left-aligned of value.
Quoted 1 line
I recommend that you better to use the same style for the readability.
Ok, I will revise.
Quoted 162 lines
Quoted 56 lines
drivers/extcon/extcon-rtk-type-c.c new file +56
-0+ +#define ENABLE_CC1 0x1 +#define ENABLE_CC2 0x2 +#define DISABLE_CC 0x0 + +/* Bit mapping USB_TYPEC_CTRL_CC1_0 and USB_TYPEC_CTRL_CC2_0 */ +#define PLR_EN BIT(29) +#define CC_SWITCH_MASK (BIT(29) | BIT(28) | BIT(27)) +#define CC_CODE_MASK (0xfffff << 7) +#define rp4pk_code (val) ((0x1f & (val)) << 22) +#define code_rp4pk (val) (((val) >> 22) & 0x1f) +#define rp36k_code (val) ((0x1f & (val)) << 17) +#define code_rp36k (val) (((val) >> 17) & 0x1f) +#define rp12k_code (val) ((0x1f & (val)) << 12) +#define code_rp12k (val) (((val) >> 12) & 0x1f) +#define rd_code (val) ((0x1f & (val)) << 7) +#define code_rd (val) (((val) >> 7) & 0x1f) +#define dfp_mode (val) ((0x3 & (val)) << 5) +#define EN_RP4P7K BIT(4) +#define EN_RP36K BIT(3) +#define EN_RP12K BIT(2) +#define EN_RD BIT(1) +#define EN_CC_DET BIT(0) + +#define CC_MODE_UFP 0x0 +#define CC_MODE_DFP_USB 0x1 +#define CC_MODE_DFP_1_5 0x2 +#define CC_MODE_DFP_3_0 0x3 + +/* +* PARAMETER_V0: +* Realtek Kylin rtd1295 +* Realtek Hercules rtd1395 +* Realtek Thor rtd1619 +* Realtek Hank rtd1319 +* Realtek Groot rtd1312c +* PARAMETER_V1: +* Realtek Stark rtd1619b +* Realtek Parker rtd1319d +* Realtek Danvers rtd1315e +*/ +enum parameter_version { +PARAMETER_V0 =0 , +PARAMETER_V1 =1 , +}; + +/* Bit mapping USB_TYPEC_CTRL_CC1_1 and USB_TYPEC_CTRL_CC2_1 */ +#define V0_vref_2p6v (val) ((0xf & (val)) << 26)/* Bit 29 for groot */ +#define V0_vref_1p23v (val) ((0xf & (val)) << 22) +#define V0_vref_0p8v (val) ((0xf & (val)) << 18) +#define V0_vref_0p66v (val) ((0xf & (val)) << 14) +#define V0_vref_0p4v (val) ((0x7 & (val)) << 11) +#define V0_vref_0p2v (val) ((0x7 & (val)) << 8) +#define V0_vref_1_1p6v (val) ((0xf & (val)) << 4) +#define V0_vref_0_1p6v (val) ((0xf & (val)) << 0) +drivers/extcon/extcon-rtk-type-c.c
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+#define V0_decode_2p6v (val) (((val) >> 26) & 0xf)/* Bit 29 for groot */ +#define V0_decode_1p23v (val) (((val) >> 22) & 0xf) +#define V0_decode_0p8v (val) (((val) >> 18) & 0xf) +#define V0_decode_0p66v (val) (((val) >> 14) & 0xf) +#define V0_decode_0p4v (val) (((val) >> 11) & 0x7) +#define V0_decode_0p2v (val) (((val) >> 8) & 0x7) +#define V0_decode_1_1p6v (val) (((val) >> 4) & 0xf) +#define V0_decode_0_1p6v (val) (((val) >> 0) & 0xf) + +/* new Bit mapping USB_TYPEC_CTRL_CC1_1 and
USB_TYPEC_CTRL_CC2_1*/Quoted 66 lines
drivers/extcon/extcon-rtk-type-c.c new file +66
-0+#define V1_vref_2p6v (val) ((0xf & (val)) << 28) +#define V1_vref_1p23v (val) ((0xf & (val)) << 24) +#define V1_vref_0p8v (val) ((0xf & (val)) << 20) +#define V1_vref_0p66v (val) ((0xf & (val)) << 16) +#define V1_vref_0p4v (val) ((0xf & (val)) << 12) +#define V1_vref_0p2v (val) ((0xf & (val)) << 8) +#define V1_vref_1_1p6v (val) ((0xf & (val)) << 4) +#define V1_vref_0_1p6v (val) ((0xf & (val)) << 0) + +#define V1_decode_2p6v (val) (((val) >> 28) & 0xf) +#define V1_decode_1p23v (val) (((val) >> 24) & 0xf) +#define V1_decode_0p8v (val) (((val) >> 20) & 0xf) +#define V1_decode_0p66v (val) (((val) >> 16) & 0xf) +#define V1_decode_0p4v (val) (((val) >> 12) & 0xf) +#define V1_decode_0p2v (val) (((val) >> 8) & 0xf) +#define V1_decode_1_1p6v (val) (((val) >> 4) & 0xf) +#define V1_decode_0_1p6v (val) (((val) >> 0) & 0xf) + +/* Bit mapping USB_TYPEC_STS */ +#define DET_STS 0x7 +#define CC1_DET_STS (DET_STS) +#define CC2_DET_STS (DET_STS << 3) +#define DET_STS_RA 0x1 +#define DET_STS_RD 0x3 +#define DET_STS_RP 0x1 +#define CC1_DET_STS_RA (DET_STS_RA) +#define CC1_DET_STS_RD (DET_STS_RD) +#define CC1_DET_STS_RP (DET_STS_RP) +#define CC2_DET_STS_RA (DET_STS_RA << 3) +#define CC2_DET_STS_RD (DET_STS_RD << 3) +#define CC2_DET_STS_RP (DET_STS_RP << 3) + +/* Bit mapping USB_TYPEC_CTRL */ +#define CC2_INT_EN BIT(11) +#define CC1_INT_EN BIT(10) +#define CC2_INT_STS BIT(9) +#define CC1_INT_STS BIT(8) +#define DEBOUNCE_TIME_MASK 0xff +#define DEBOUNCE_EN BIT(0) +#define ENABLE_TYPE_C_DETECT (CC1_INT_EN | CC2_INT_EN) +#define ALL_CC_INT_STS (CC1_INT_STS | CC2_INT_STS) + +/* Parameter */ +#define DETECT_TIME 50/* ms */ + +static const unsigned int usb_type_c_cable[] = { +EXTCON_USB , +EXTCON_USB_HOST , +EXTCON_NONE , +}; + +enum usb_data_roles { +DR_NONE , +DR_HOST , +DR_DEVICE , +}; + +static const struct soc_device_attribute rtk_soc_kylin[] = { + { .family ="Realtek Kylin" , }, + {/* empty */ } +}; + +static int rtd129x_switch_type_c_plug_config (struct type_c_data *type_c, +int dr_mode,int cc) +{ +void __iomem *reg = type_c->reg_base +USB_TYPEC_CTRL_CC1_0 ;drivers/extcon/extcon-rtk-type-c.c line 255
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+int val_cc; + +#define TYPE_C_EN_SWITCH BIT(29) +#define TYPE_C_TXRX_SEL (BIT(28) | BIT(27)) +#define TYPE_C_SWITCH_MASK (TYPE_C_EN_SWITCH | TYPE_C_TXRX_SEL) +#define TYPE_C_ENABLE_CC1 TYPE_C_EN_SWITCH +#define TYPE_C_ENABLE_CC2 (TYPE_C_EN_SWITCH | TYPE_C_TXRX_SEL) +#define TYPE_C_DISABLE_CC ~TYPE_C_SWITCH_MASK + + val_cc =readl (reg);I'd like you to use regmap interface to access the register by using
regmap_read,regmap_write. You can create the regmap instance viadevm_regmap_init_mmio()on probe instead of using 'type_c->reg_base' at the multipe point.For example,
struct regmap_config rtk_regmap_config = { .reg_bits = 32, .val_bits = 32, }; void __iomem *base; base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); if (IS_ERR(base)) return PTR_ERR(base); regmap = devm_regmap_init_mmio(dev, base,
Quoted 8 lines
&rtk_regmap_config);---
And then just call
regmap_readwithout any calculation between base address and specific register.
regmap_read(regmap, USB_TYPEC_CTRL_CC1_0)
I will study this method.
Quoted 17 lines
drivers/extcon/extcon-rtk-type-c.c
Quoted 11 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+ val_cc &= ~TYPE_C_SWITCH_MASK ; + +if (cc ==DISABLE_CC ) { + val_cc &=TYPE_C_DISABLE_CC ; + }else if (cc ==ENABLE_CC1 ) { + val_cc |=TYPE_C_ENABLE_CC1 ; + }else if (cc ==ENABLE_CC2 ) { + val_cc |=TYPE_C_ENABLE_CC2 ; + }else { + dev_err(type_c->dev, "%s: Error cc setting cc=0x%x\n",
__func__, cc);drivers/extcon/extcon-rtk-type-c.c line 270
Quoted 5 lines
drivers/extcon/extcon-rtk-type-c.c new file +5
-0+return -EINVAL ; + } +writel (val_cc, reg); + +mdelay (1 );
Quoted 4 lines
Maybe, it depends on h/w constraints. Better to explain the comment of why adding delay at here. Also, this patch uses mdelay/msleep at the multiple point. I recommend that add the comment of reason to add mdelay/msleep.
Ok, I will add.
Quoted 122 lines
drivers/extcon/extcon-rtk-type-c.c line 272
Quoted 3 lines
drivers/extcon/extcon-rtk-type-c.c new file +2
-0+ + dev_dbg(type_c->dev, "%s: cc=0x%x val_cc=0x%xusb_typec_ctrl_cc1_0=0x%x\n",
drivers/extcon/extcon-rtk-type-c.c
Quoted 12 lines
drivers/extcon/extcon-rtk-type-c.c new file +12
-0+ __func__, cc, val_cc, readl(reg)); + +return 0 ; +} + +static inline void switch_type_c_plug_config (struct type_c_data *type_c, +int dr_mode,int cc) +{ +int ret =0 ; + +if (soc_device_match (rtk_soc_kylin)) + ret = rtd129x_switch_type_c_plug_config(type_c, dr_mode,cc);
drivers/extcon/extcon-rtk-type-c.c
Quoted 7 lines
drivers/extcon/extcon-rtk-type-c.c new file +7
-0+ +if (ret <0 ) +dev_err (type_c->dev,"%s: Error set type c plug config\n" , + __func__); +} + +static void switch_type_c_dr_mode(struct type_c_data *type_c, int
dr_mode, int cc)Quoted 11 lines
drivers/extcon/extcon-rtk-type-c.c new file +11
-0+{ +bool is_host = false; +bool is_device = false; +bool polarity = false; +bool vbus = false; +bool ss = true; + +switch_type_c_plug_config (type_c, dr_mode, cc); +if (cc ==ENABLE_CC2 ) + polarity = true; +drivers/extcon/extcon-rtk-type-c.c
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+switch (dr_mode) { +case USB_DR_MODE_HOST : + is_host = true; +break ; +case USB_DR_MODE_PERIPHERAL : + is_device = true; + vbus = true; +break ; +default : + dev_dbg(type_c->dev, "%s dr_mode=%d ==> no host ordevice\n",
drivers/extcon/extcon-rtk-type-c.c
Quoted 5 lines
drivers/extcon/extcon-rtk-type-c.c new file +5
-0+ __func__, dr_mode); +break ; + } + + dev_dbg(type_c->dev, "%s is_host=%d is_device=%d vbus=%dpolarity=%d\n",
Quoted 25 lines
drivers/extcon/extcon-rtk-type-c.c new file +25
-0+ __func__, is_host, is_device, vbus, polarity); + +/* for EXTCON_USB device mode */ +extcon_set_state (type_c->edev,EXTCON_USB , is_device); +extcon_set_property (type_c->edev,EXTCON_USB , +EXTCON_PROP_USB_VBUS , + (union extcon_property_value )(int )vbus); +extcon_set_property (type_c->edev,EXTCON_USB , +EXTCON_PROP_USB_TYPEC_POLARITY , + (union extcon_property_value )(int )polarity); +extcon_set_property (type_c->edev,EXTCON_USB , +EXTCON_PROP_USB_SS , + (union extcon_property_value )(int )ss); + +/* for EXTCON_USB_HOST host mode */ +extcon_set_state (type_c->edev,EXTCON_USB_HOST , is_host); +extcon_set_property (type_c->edev,EXTCON_USB_HOST , +EXTCON_PROP_USB_VBUS , + (union extcon_property_value )(int )vbus); +extcon_set_property (type_c->edev,EXTCON_USB_HOST , +EXTCON_PROP_USB_TYPEC_POLARITY , + (union extcon_property_value )(int )polarity); +extcon_set_property (type_c->edev,EXTCON_USB_HOST , +EXTCON_PROP_USB_SS , + (union extcon_property_value )(int )ss);drivers/extcon/extcon-rtk-type-c.c
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+ +/* sync EXTCON_USB and EXTCON_USB_HOST */ +extcon_sync (type_c->edev,EXTCON_USB ); +extcon_sync (type_c->edev,EXTCON_USB_HOST ); + +#ifdef CONFIG_TYPEC> + if (type_c->port) { +switch (dr_mode) { +case USB_DR_MODE_HOST : +typec_set_data_role (type_c->port,TYPEC_HOST ); + typec_set_pwr_role(type_c->port,
TYPEC_SOURCE);drivers/extcon/extcon-rtk-type-c.c
Quoted 3 lines
drivers/extcon/extcon-rtk-type-c.c new file +3
-0+break ; +case USB_DR_MODE_PERIPHERAL : + typec_set_data_role(type_c->port,
TYPEC_DEVICE);drivers/extcon/extcon-rtk-type-c.c
Quoted 4 lines
drivers/extcon/extcon-rtk-type-c.c new file +4
-0+typec_set_pwr_role (type_c->port,TYPEC_SINK ); +break ; +default : + dev_dbg(type_c->dev, "%s unknowndr_mode=%d\n",
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+ __func__, dr_mode); + break; + } + } +#endif +} + +/* device attached/detached */ +static int device_attached (struct type_c_data *type_c,u32 cc) +{drivers/extcon/extcon-rtk-type-c.c line 380
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+void __iomem *reg = type_c->reg_base +USB_TYPEC_CTRL ; + +cancel_delayed_work (&type_c->delayed_work); + +switch_type_c_dr_mode (type_c,USB_DR_MODE_HOST , cc); + +writel (ENABLE_TYPE_C_DETECT |readl (reg), reg); + +return 0 ; +}
device_attached()funciton is same withhost_connected()except forUSR_BR_MODE_HOST,USB_DR_MODE_PERIPHERALsetting.
Quoted 5 lines
You can use only one function with 3rd paramer (
dr_mode) as following in order to reduce the duplicated code.
For example,
static intconnector_attached(struct type_c_data *type_c, u32 cc, int dr_mode)
I will simplify this.
Quoted 158 lines
drivers/extcon/extcon-rtk-type-c.c
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+ +static int device_detached (struct type_c_data *type_c,u32 cc) +{ +void __iomem *reg = type_c->reg_base +USB_TYPEC_CTRL ; + +writel (~ENABLE_TYPE_C_DETECT &readl (reg), reg); + +switch_type_c_dr_mode (type_c,0 , cc); + + schedule_delayed_work(&type_c->delayed_work,
msecs_to_jiffies(DETECT_TIME));drivers/extcon/extcon-rtk-type-c.c line 276
Quoted 3 lines
drivers/extcon/extcon-rtk-type-c.c new file +3
-0+ +return 0 ; +}
device_detachedis perfectly same withhost_disconnected. You can use the only one function to reduce the duplicated codeQuoted 13 lines
drivers/extcon/extcon-rtk-type-c.c new file +13
-0+ +/* host connect/disconnect*/ +static int host_connected (struct type_c_data *type_c,u32 cc) +{ +void __iomem *reg = type_c->reg_base +USB_TYPEC_CTRL ; + +cancel_delayed_work (&type_c->delayed_work); + +switch_type_c_dr_mode (type_c,USB_DR_MODE_PERIPHERAL , cc); + +writel (ENABLE_TYPE_C_DETECT |readl (reg), reg); +return 0 ; +}drivers/extcon/extcon-rtk-type-c.c
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+ +static int host_disconnected (struct type_c_data *type_c,u32 cc) +{ +void __iomem *reg = type_c->reg_base +USB_TYPEC_CTRL ; + +writel (~ENABLE_TYPE_C_DETECT &readl (reg), reg); + +switch_type_c_dr_mode (type_c,0 , cc); + + schedule_delayed_work(&type_c->delayed_work,
msecs_to_jiffies(DETECT_TIME));drivers/extcon/extcon-rtk-type-c.c
Quoted 6 lines
drivers/extcon/extcon-rtk-type-c.c new file +6
-0+ +return 0 ; +} + +/* detect host device switch */ +static int __detect_host_device(struct type_c_data *type_c, u32
rp_or_rd_en)drivers/extcon/extcon-rtk-type-c.c
Quoted 8 lines
drivers/extcon/extcon-rtk-type-c.c new file +8
-0+{ +struct device *dev = type_c->dev; +void __iomem *reg_base = type_c->reg_base; +unsigned int gpio = type_c->rd_ctrl_gpio; +u32 cc1_config, cc2_config, default_ctrl; +u32 cc1_switch =0 ; + + default_ctrl = readl(reg_base + USB_TYPEC_CTRL) &
DEBOUNCE_TIME_MASK;Quoted 15 lines
drivers/extcon/extcon-rtk-type-c.c new file +15
-0+writel (default_ctrl, reg_base +USB_TYPEC_CTRL ); + + cc1_config =readl (reg_base +USB_TYPEC_CTRL_CC1_0 ); + cc2_config =readl (reg_base +USB_TYPEC_CTRL_CC2_0 ); + + cc1_config &= ~EN_CC_DET ; + cc2_config &= ~EN_CC_DET ; +writel (cc1_config, reg_base +USB_TYPEC_CTRL_CC1_0 ); +writel (cc2_config, reg_base +USB_TYPEC_CTRL_CC2_0 ); + +if (soc_device_match (rtk_soc_kylin)) + cc1_switch = cc1_config &CC_SWITCH_MASK ; + + cc1_config &=CC_CODE_MASK ; + cc1_config |= rp_or_rd_en | cc1_switch;drivers/extcon/extcon-rtk-type-c.c
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+ cc2_config &=CC_CODE_MASK ; + cc2_config |= rp_or_rd_en; +writel (cc2_config, reg_base +USB_TYPEC_CTRL_CC2_0 ); +writel (cc1_config, reg_base +USB_TYPEC_CTRL_CC1_0 ); + +/* For kylin to disable external rd control gpio */ +if (soc_device_match (rtk_soc_kylin)) { +if (gpio !=-1 &&gpio_is_valid (gpio)) { +if (gpio_direction_output (gpio,1 )) + dev_err(dev, "%s ERROR rd_ctrl_gpio=1fail\n",
__func__);Quoted 41 lines
drivers/extcon/extcon-rtk-type-c.c new file +41
-0+ } + } + + cc1_config |=EN_CC_DET ; + cc2_config |=EN_CC_DET ; +writel (cc1_config, reg_base +USB_TYPEC_CTRL_CC1_0 ); +writel (cc2_config, reg_base +USB_TYPEC_CTRL_CC2_0 ); + +return 0 ; +} + +static int detect_device (struct type_c_data *type_c) +{ +return __detect_host_device (type_c, type_c->dfp_mode_rp_en); +} + +static int detect_host (struct type_c_data *type_c) +{ +return __detect_host_device (type_c, type_c->ufp_mode_rd_en); +} + +static int host_device_switch_detection (struct type_c_data *type_c) +{ +if (type_c->cc_mode ==IN_HOST_MODE ) { + type_c->cc_mode =IN_DEVICE_MODE ; +detect_host (type_c); + }else { + type_c->cc_mode =IN_HOST_MODE ; +detect_device (type_c); + } + +return 0 ; +} + +static int detect_type_c_state (struct type_c_data *type_c) +{ +struct device *dev = type_c->dev; +void __iomem *reg_base = type_c->reg_base; +u32 int_status, cc_status, cc_status_check; +unsigned long flags; +drivers/extcon/extcon-rtk-type-c.c
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+spin_lock_irqsave (&type_c->lock, flags); + + int_status =readl (reg_base +USB_TYPEC_CTRL ); + cc_status =readl (reg_base +USB_TYPEC_STS ); + + type_c->connect_change =CONNECT_NO_CHANGE ; + +switch (type_c->cc_mode | type_c->is_attach) { +case IN_HOST_MODE |IN_ATTACH : + if (((cc_status & CC1_DET_STS) == CC1_DET_STS) &&
type_c->at_cc1==AT_CC1) {drivers/extcon/extcon-rtk-type-c.c line 506
Quoted 1 line
drivers/extcon/extcon-rtk-type-c.c new file +1
-0+ dev_dbg(dev, "IN host mode and cc1 devicedetach (cc_status=0x%x)",
drivers/extcon/extcon-rtk-type-c.c
Quoted 6 lines
drivers/extcon/extcon-rtk-type-c.c new file +6
-0+ cc_status); + type_c->is_attach =TO_DETACH ; + type_c->connect_change =CONNECT_CHANGE ; + }else if (((cc_status &CC2_DET_STS ) ==CC2_DET_STS ) && + type_c->at_cc1 ==AT_CC2 ) { + dev_dbg(dev, "IN host mode and cc2 devicedetach (cc_status=0x%x)",
drivers/extcon/extcon-rtk-type-c.c
Quoted 12 lines
drivers/extcon/extcon-rtk-type-c.c new file +12
-0+ cc_status); + type_c->is_attach =TO_DETACH ; + type_c->connect_change =CONNECT_CHANGE ; + } +break ; +case IN_HOST_MODE |IN_DETACH : + cc_status_check =readl (reg_base +USB_TYPEC_STS ); +if (cc_status_check != (CC1_DET_STS |CC2_DET_STS )) { +if (in_interrupt ()) { +mdelay (300 ); + }else { + spin_unlock_irqrestore(&type_c->lock,flags);
Quoted 8 lines
drivers/extcon/extcon-rtk-type-c.c line 528
Quoted 3 lines
drivers/extcon/extcon-rtk-type-c.c new file +3
-0+msleep (300 ); +spin_lock_irqsave (&type_c->lock, flags); + }As I commented above, it seems that there are some hardware constrains which requires the some delay when changing the h/w state. I recommend that you need to add the comment of why adding the delays/sleep.
Ok, I will add.
Quoted 136 lines
drivers/extcon/extcon-rtk-type-c.c line 528
Quoted 1 line
drivers/extcon/extcon-rtk-type-c.c new file +1
-0+ cc_status_check = readl(reg_base +
USB_TYPEC_STS);drivers/extcon/extcon-rtk-type-c.c
Quoted 3 lines
drivers/extcon/extcon-rtk-type-c.c new file +3
-0+ } +if (cc_status != cc_status_check) { + dev_warn(dev, "IN_HOST_MODE: cc_status(0x%x) !=
cc_status_check(0x%x)\n",drivers/extcon/extcon-rtk-type-c.c
Quoted 6 lines
drivers/extcon/extcon-rtk-type-c.c new file +6
-0+ cc_status, cc_status_check); + cc_status =readl (reg_base +USB_TYPEC_STS ); + } + +if ((cc_status &CC1_DET_STS ) ==CC1_DET_STS_RD ) { + dev_dbg(dev, "IN host mode and cc1 deviceattach (cc_status=0x%x)",
drivers/extcon/extcon-rtk-type-c.c
Quoted 5 lines
drivers/extcon/extcon-rtk-type-c.c new file +5
-0+ cc_status); + type_c->is_attach =TO_ATTACH ; + type_c->at_cc1 =AT_CC1 ; + type_c->connect_change =CONNECT_CHANGE ; + }else if ((cc_status &CC2_DET_STS ) ==CC2_DET_STS_RD ){
drivers/extcon/extcon-rtk-type-c.c line 543
Quoted 1 line
drivers/extcon/extcon-rtk-type-c.c new file +1
-0+ dev_dbg(dev, "In host mode and cc2 device attach(cc_status=0x%x)",
drivers/extcon/extcon-rtk-type-c.c
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+ cc_status); + type_c->is_attach =TO_ATTACH ; + type_c->at_cc1 =AT_CC2 ; + type_c->connect_change =CONNECT_CHANGE ; + } +break ; +case IN_DEVICE_MODE |IN_ATTACH : +if ((cc_status &CC1_DET_STS ) <CC1_DET_STS_RP || + (cc_status &CC2_DET_STS ) <CC2_DET_STS_RP ) { +/* Add a sw debounce to filter cc signal sent from apple pd adapter */
drivers/extcon/extcon-rtk-type-c.c line 555
Quoted 2 lines
drivers/extcon/extcon-rtk-type-c.c new file +2
-0+mdelay (5 ); + cc_status_check = readl(reg_base +
USB_TYPEC_STS);drivers/extcon/extcon-rtk-type-c.c
Quoted 3 lines
drivers/extcon/extcon-rtk-type-c.c new file +3
-0+ +if (cc_status != cc_status_check) { + dev_dbg(dev, "IN_DEVICE_MODE:
cc_status(0x%x) !=cc_status_check(0x%x) maybe use a pd adapter\n",drivers/extcon/extcon-rtk-type-c.c
Quoted 6 lines
drivers/extcon/extcon-rtk-type-c.c new file +6
-0+ cc_status, cc_status_check); + cc_status = cc_status_check; + } + } + + if ((cc_status & CC1_DET_STS) < CC1_DET_STS_RP &&
type_c->at_cc1==AT_CC1) {drivers/extcon/extcon-rtk-type-c.c line 565
Quoted 1 line
drivers/extcon/extcon-rtk-type-c.c new file +1
-0+ dev_dbg(dev, "IN device mode and cc1 hostdisconnect (cc_status=0x%x)",
drivers/extcon/extcon-rtk-type-c.c
Quoted 4 lines
drivers/extcon/extcon-rtk-type-c.c new file +4
-0+ cc_status); + type_c->is_attach =TO_DETACH ; + type_c->connect_change =CONNECT_CHANGE ; + } else if ((cc_status & CC2_DET_STS) < CC2_DET_STS_RP&&
drivers/extcon/extcon-rtk-type-c.c line 571
Quoted 2 lines
drivers/extcon/extcon-rtk-type-c.c new file +2
-0+ type_c->at_cc1 == AT_CC2) { + dev_dbg(dev, "IN device mode and cc2 hostdisconnect (cc_status=0x%x)",
drivers/extcon/extcon-rtk-type-c.c
Quoted 12 lines
drivers/extcon/extcon-rtk-type-c.c new file +12
-0+ cc_status); + type_c->is_attach =TO_DETACH ; + type_c->connect_change =CONNECT_CHANGE ; + } +break ; +case IN_DEVICE_MODE |IN_DETACH : + cc_status_check =readl (reg_base +USB_TYPEC_STS ); +if (cc_status_check !=0x0 ) { +if (in_interrupt ()) { +mdelay (300 ); + }else { + spin_unlock_irqrestore(&type_c->lock,flags);
drivers/extcon/extcon-rtk-type-c.c line 528
Quoted 3 lines
drivers/extcon/extcon-rtk-type-c.c new file +3
-0+msleep (300 ); +spin_lock_irqsave (&type_c->lock, flags); + }ditto.
drivers/extcon/extcon-rtk-type-c.c line 587
Quoted 1 line
drivers/extcon/extcon-rtk-type-c.c new file +1
-0+ cc_status_check = readl(reg_base +
USB_TYPEC_STS);drivers/extcon/extcon-rtk-type-c.c
Quoted 4 lines
drivers/extcon/extcon-rtk-type-c.c new file +4
-0+ } + +if (cc_status != cc_status_check) { + dev_warn(dev, "IN_DEVICE_MODE: cc_status(0x%x) !=
cc_status_check(0x%x)\n",drivers/extcon/extcon-rtk-type-c.c
Quoted 6 lines
drivers/extcon/extcon-rtk-type-c.c new file +6
-0+ cc_status, cc_status_check); + cc_status =readl (reg_base +USB_TYPEC_STS ); + } + +if ((cc_status &CC1_DET_STS ) >=CC1_DET_STS_RP ) { + dev_dbg(dev, "IN device mode and cc1 hostconnect (cc_status=0x%x)",
drivers/extcon/extcon-rtk-type-c.c
Quoted 6 lines
drivers/extcon/extcon-rtk-type-c.c new file +6
-0+ cc_status); + type_c->at_cc1 =AT_CC1 ; + type_c->is_attach =TO_ATTACH ; + type_c->connect_change =CONNECT_CHANGE ; + }else if ((cc_status &CC2_DET_STS ) >=CC2_DET_STS_RP ) { + dev_dbg(dev, "IN device mode and cc2 hostconnect (cc_status=0x%x)",
drivers/extcon/extcon-rtk-type-c.c
Quoted 8 lines
drivers/extcon/extcon-rtk-type-c.c new file +8
-0+ cc_status); + type_c->at_cc1 =AT_CC2 ; + type_c->is_attach =TO_ATTACH ; + type_c->connect_change =CONNECT_CHANGE ; + } +break ; +default : + dev_err(dev, "error host or device mode (cc_mode=%d,is_attach=%d) ",
Quoted 4 lines
drivers/extcon/extcon-rtk-type-c.c new file +4
-0+ type_c->cc_mode, type_c->is_attach); + } + + type_c->int_status = int_status;drivers/extcon/extcon-rtk-type-c.c line 633
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+ type_c->cc_status = cc_status; + +spin_unlock_irqrestore (&type_c->lock, flags); +return 0 ; +} + +static void host_device_switch (struct work_struct *work) +{ + struct type_c_data *type_c = container_of(work, struct type_c_data, +delayed_work.work);
drivers/extcon/extcon-rtk-type-c.c line 637
Quoted 11 lines
drivers/extcon/extcon-rtk-type-c.c new file +11
-0+struct device *dev = type_c->dev; +unsigned long flags; +int connect_change =0 ; +int cc_mode =0 ; +int is_attach =0 ; +int at_cc1 =0 ; + +spin_lock_irqsave (&type_c->lock, flags); +if (type_c->connect_change) + connect_change = type_c->connect_change; +spin_unlock_irqrestore (&type_c->lock, flags);Better to convert this code as following if
type_c->connect_changeis NULL, you can reduce the lock/unlok operation ofspin_lock. As you knew,spin_lockis expensive.
Quoted 5 lines
if (type_c->connect_change) {
spin_lock_irqsave(&type_c->lock, flags);
connect_change = type_c->connect_change;
spin_unlock_irqrestore(&type_c->lock, flags);
}I want to protect type_c->connect_change.
Moving the lock to the if statement loses its original purpose.
Quoted 26 lines
Quoted 5 lines
drivers/extcon/extcon-rtk-type-c.c new file +5
-0+ +if (!connect_change) +detect_type_c_state (type_c); + +spin_lock_irqsave (&type_c->lock, flags);drivers/extcon/extcon-rtk-type-c.c
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+if (type_c->connect_change) { + connect_change = type_c->connect_change; + cc_mode = type_c->cc_mode; + is_attach = type_c->is_attach; + at_cc1 = type_c->at_cc1; + type_c->connect_change =CONNECT_NO_CHANGE ; + }else { +host_device_switch_detection (type_c); + + schedule_delayed_work(&type_c->delayed_work,
msecs_to_jiffies(DETECT_TIME));drivers/extcon/extcon-rtk-type-c.c line 656
Quoted 4 lines
drivers/extcon/extcon-rtk-type-c.c new file +4
-0+ } +spin_unlock_irqrestore (&type_c->lock, flags); + +if (connect_change) {nitpick.
You can reduce the depth of indentation whenconnector_changeis 0 by changing the code as following: If possible, I always to try to reduce the indentation depth for the readability.
Quoted 7 lines
if (!connect_change)
return
dev_dbg(dev, "%s: usb cable connection change\n", __func__);
if (cc_mode == IN_HOST_MODE) {
......Ok, I will revise.
Quoted 65 lines
drivers/extcon/extcon-rtk-type-c.c line 656
Quoted 1 line
drivers/extcon/extcon-rtk-type-c.c new file +1
-0+ dev_dbg(dev, "%s: usb cable connection change\n",
__func__);Quoted 4 lines
drivers/extcon/extcon-rtk-type-c.c new file +4
-0+if (cc_mode ==IN_HOST_MODE ) { +if (is_attach && at_cc1) +device_attached (type_c,ENABLE_CC1 ); +else if (is_attach && !at_cc1)drivers/extcon/extcon-rtk-type-c.c
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+device_attached (type_c,ENABLE_CC2 ); + else +device_detached (type_c ,DISABLE_CC ); + }else if (cc_mode ==IN_DEVICE_MODE ) { +if (is_attach && at_cc1) +host_connected (type_c,ENABLE_CC1 ); +else if (is_attach && !at_cc1) +host_connected (type_c,ENABLE_CC2 ); +else + host_disconnected(type_c,
DISABLE_CC);drivers/extcon/extcon-rtk-type-c.c line 672
Quoted 2 lines
drivers/extcon/extcon-rtk-type-c.c new file +2
-0+ }else { + dev_err(dev, "Error: IN unknown mode %d to %sat %s (cc_status=0x%x)\n",
drivers/extcon/extcon-rtk-type-c.c line 673
Quoted 1 line
drivers/extcon/extcon-rtk-type-c.c new file +1
-0+ cc_mode, is_attach ? "attach" :"detach",
drivers/extcon/extcon-rtk-type-c.c line 674
Quoted 1 line
drivers/extcon/extcon-rtk-type-c.c new file +1
-0+ at_cc1 ? "cc1" : "cc2",
type_c->cc_status);drivers/extcon/extcon-rtk-type-c.c line 676
Quoted 2 lines
drivers/extcon/extcon-rtk-type-c.c new file +2
-0+ } + dev_info(dev, "Connection change OK: IN %s mode to %s at%s (cc_status=0x%x)\n",
Quoted 9 lines
drivers/extcon/extcon-rtk-type-c.c new file +9
-0+ cc_mode ==IN_HOST_MODE ?"host" :"device" , + is_attach ?"attach" :"detach" , + at_cc1 ? "cc1" : "cc2", type_c->cc_status); + } +} + +static irqreturn_t type_c_detect_irq (int irq,void *__data) +{ +struct type_c_data *type_c = (struct type_c_data *)__data;drivers/extcon/extcon-rtk-type-c.c
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+struct device *dev = type_c->dev; +void __iomem *reg = type_c->reg_base +USB_TYPEC_CTRL ; +unsigned long flags; + +detect_type_c_state (type_c); + +spin_lock_irqsave (&type_c->lock, flags); + +if (type_c->connect_change) { + dev_dbg(dev, "%s: IN %s mode to %s (at %s interrupt)int_status=0x%x, cc_status=0x%x",
drivers/extcon/extcon-rtk-type-c.c line 697
Quoted 2 lines
drivers/extcon/extcon-rtk-type-c.c new file +2
-0+ __func__, + type_c->cc_mode == IN_HOST_MODE ? "host" :"device",
drivers/extcon/extcon-rtk-type-c.c
Quoted 9 lines
drivers/extcon/extcon-rtk-type-c.c new file +9
-0+ type_c->is_attach ?"attach" :"detach" , + type_c->at_cc1 ?"cc1" :"cc2" , + type_c->int_status, type_c->cc_status); + +/* clear interrupt status */ +writel (~ALL_CC_INT_STS &readl (reg), reg); + +cancel_delayed_work (&type_c->delayed_work); + schedule_delayed_work(&type_c->delayed_work,
msecs_to_jiffies(0));drivers/extcon/extcon-rtk-type-c.c line 711
Quoted 4 lines
drivers/extcon/extcon-rtk-type-c.c new file +4
-0+ }else { +static int local_count; + +if (local_count++ >10 ) {
Quoted 4 lines
It seems that clear interrupt status once every 10 times.
I think that it is not generic. You need to add the comment of why trying to clear
interrupt once every 10 times.
I will add the comment.
Quoted 27 lines
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+/* clear interrupt status */ +writel (~ALL_CC_INT_STS &readl (reg), reg); + local_count =0 ; + } + } + +spin_unlock_irqrestore (&type_c->lock, flags); + +return IRQ_HANDLED ; +}(snip)
drivers/extcon/extcon-rtk-type-c.c line 1238
Quoted 9 lines
drivers/extcon/extcon-rtk-type-c.c new file +9
-0+ +static int extcon_rtk_type_c_init (struct type_c_data *type_c) +{ +struct device *dev = type_c->dev; +unsigned long flags; +void __iomem *reg; +int val; + + if ((type_c->rd_ctrl_gpio != -1) &&nitpick.
After getting the gpio number by usingof_get_named_gpio()function,type_c->rd_ctrl_gpiois error number which is returnedof_get_named_gpio().
Quoted 5 lines
In order to specify the more correctly, how about changing it as following? Because I don't use the '-1' constant variable without any constant defintion. Someone cannot understand the meaning of '-1'.
if (!(type_c->rd_ctrl_gpio < 0))
I will revise.
Quoted 47 lines
drivers/extcon/extcon-rtk-type-c.c
Quoted 2 lines
drivers/extcon/extcon-rtk-type-c.c new file +2
-0+ gpio_request(type_c->rd_ctrl_gpio, dev->of_node->name)) + dev_err(dev, "%s ERROR Request rd_ctrl_gpio (id=%d)fail\n",
drivers/extcon/extcon-rtk-type-c.c
Quoted 8 lines
drivers/extcon/extcon-rtk-type-c.c new file +8
-0+ __func__, type_c->rd_ctrl_gpio); + +spin_lock_irqsave (&type_c->lock, flags); + +/* set parameter */ + reg = type_c->reg_base +USB_TYPEC_CTRL_CC1_0 ; + val =readl (reg); + val = (~CC_CODE_MASK & val) | (type_c->cc1_code &
CC_CODE_MASK);drivers/extcon/extcon-rtk-type-c.c
Quoted 5 lines
drivers/extcon/extcon-rtk-type-c.c new file +5
-0+writel (val, reg); + + reg = type_c->reg_base +USB_TYPEC_CTRL_CC2_0 ; + val =readl (reg); + val = (~CC_CODE_MASK & val) | (type_c->cc2_code &
CC_CODE_MASK);drivers/extcon/extcon-rtk-type-c.c
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+ + reg = type_c->reg_base +USB_TYPEC_CTRL_CC1_1 ; +writel (type_c->cc1_vref, reg); + + reg = type_c->reg_base +USB_TYPEC_CTRL_CC2_1 ; +writel (type_c->cc2_vref, reg); + + reg = type_c->reg_base +USB_TYPEC_CTRL ; + val =readl (reg); + val = (~DEBOUNCE_TIME_MASK & val) | (type_c->debounce &
DEBOUNCE_TIME_MASK);drivers/extcon/extcon-rtk-type-c.c
Quoted 11 lines
drivers/extcon/extcon-rtk-type-c.c new file +11
-0+ +dev_info (dev,"First check USB_DR_MODE_PERIPHERAL" ); + type_c->cc_mode =IN_DEVICE_MODE ; + type_c->is_attach =IN_DETACH ; + type_c->connect_change =CONNECT_NO_CHANGE ; + +detect_host (type_c); + +spin_unlock_irqrestore (&type_c->lock, flags); + + schedule_delayed_work(&type_c->delayed_work,
msecs_to_jiffies(0));drivers/extcon/extcon-rtk-type-c.c
Quoted 2 lines
drivers/extcon/extcon-rtk-type-c.c new file +2
-0+ +#ifdef CONFIG_TYPEC Don'n need to check '
CONFIG_TYPEC' defintion wiht ifdef. 'ifdef' might make the code more complicated.
Quoted 5 lines
If
type_cis optional, just print warning message
whentypec_regiser_portreturns error.This patch is already check whether '
type_c->port' is NULL or not to handle the code related to typec.
If I remove check 'CONFIG_TYPEC' definition, it will fail the build when CONFIG_TYPEC=n. Another option is to select CONFIG_TYPEC in Kconfig.
Quoted 527 lines
Quoted 1 line
+ if (!type_c->port) {
(snip)
drivers/extcon/extcon-rtk-type-c.c
Quoted 2 lines
drivers/extcon/extcon-rtk-type-c.c new file +2
-0+ + type_c->port = typec_register_port(type_c->dev,
&typec_cap);Quoted 18 lines
drivers/extcon/extcon-rtk-type-c.c new file +18
-0+if (IS_ERR (type_c->port)) +return PTR_ERR (type_c->port); + }> +#endif /* CONFIG_TYPEC */ + +return 0 ; +} + +static int extcon_rtk_type_c_edev_register (struct type_c_data *type_c) +{ +struct device *dev = type_c->dev; +int ret =0 ; + + type_c->edev =devm_extcon_dev_allocate (dev, usb_type_c_cable); +if (IS_ERR (type_c->edev)) { +dev_err (dev,"failed to allocate extcon device\n" ); +return -ENOMEM ; + } +drivers/extcon/extcon-rtk-type-c.c line 1321
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+ ret =devm_extcon_dev_register (dev, type_c->edev); +if (ret <0 ) { +dev_err (dev,"failed to register extcon device\n" ); +return ret; + } + +extcon_set_property_capability (type_c->edev,EXTCON_USB , +EXTCON_PROP_USB_VBUS ); + extcon_set_property_capability(type_c->edev, EXTCON_USB, +
EXTCON_PROP_USB_TYPEC_POLARITY);drivers/extcon/extcon-rtk-type-c.c line 1328
Quoted 7 lines
drivers/extcon/extcon-rtk-type-c.c new file +7
-0+extcon_set_property_capability (type_c->edev,EXTCON_USB , +EXTCON_PROP_USB_SS ); + +extcon_set_property_capability (type_c->edev,EXTCON_USB_HOST , +EXTCON_PROP_USB_VBUS ); + extcon_set_property_capability(type_c->edev, EXTCON_USB_HOST, +
EXTCON_PROP_USB_TYPEC_POLARITY);Quoted 17 lines
drivers/extcon/extcon-rtk-type-c.c new file +17
-0+extcon_set_property_capability (type_c->edev,EXTCON_USB_HOST , +EXTCON_PROP_USB_SS ); + +return ret; +} + +static int extcon_rtk_type_c_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct type_c_data *type_c; +const struct type_c_cfg *type_c_cfg; +unsigned int gpio; +int ret =0 ; + + type_c =devm_kzalloc (dev,sizeof (*type_c),GFP_KERNEL ); +if (!type_c) +return -ENOMEM ;drivers/extcon/extcon-rtk-type-c.c
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+ + type_c->reg_base =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (type_c->reg_base)) +return PTR_ERR (type_c->reg_base); + + type_c->dev = dev; + + type_c->irq =irq_of_parse_and_map (pdev->dev.of_node,0 ); +if (type_c->irq <=0 ) { + dev_err(&pdev->dev, "Type C driver with no IRQ. Check %ssetup!\n",
drivers/extcon/extcon-rtk-type-c.c
Quoted 13 lines
drivers/extcon/extcon-rtk-type-c.c new file +13
-0+ dev_name(&pdev->dev)); + ret = -ENODEV ; + goto err1; + } + + ret =devm_request_irq (dev, type_c->irq, type_c_detect_irq, +IRQF_SHARED ,"type_c_detect" , type_c); + +spin_lock_init (&type_c->lock); + + type_c->rd_ctrl_gpio =-1 ; +if (soc_device_match (rtk_soc_kylin)) { + gpio = of_get_named_gpio(dev->of_node,"realtek,rd-ctrl-gpio", 0);
drivers/extcon/extcon-rtk-type-c.c
Quoted 3 lines
drivers/extcon/extcon-rtk-type-c.c new file +3
-0+if (gpio_is_valid (gpio)) { + type_c->rd_ctrl_gpio = gpio; + dev_dbg(dev, "%s get rd-ctrl-gpio (id=%d) OK\n",
__func__, gpio);drivers/extcon/extcon-rtk-type-c.c
Quoted 12 lines
drivers/extcon/extcon-rtk-type-c.c new file +12
-0+ }else { +dev_err (dev,"Error rd_ctrl-gpio no found" ); + } + } + + type_c_cfg =of_device_get_match_data (dev); +if (!type_c_cfg) { +dev_err (dev,"type_c config are not assigned!\n" ); +return -EINVAL ; + } + + type_c->type_c_cfg = devm_kzalloc(dev, sizeof(*type_c_cfg),
GFP_KERNEL);drivers/extcon/extcon-rtk-type-c.c
Quoted 5 lines
drivers/extcon/extcon-rtk-type-c.c new file +5
-0+ +memcpy (type_c->type_c_cfg, type_c_cfg,sizeof (*type_c_cfg)); + +if (setup_type_c_parameter (type_c)) { + dev_err(dev, "ERROR: %s to setup type c parameter!!",
__func__);Quoted 316 lines
drivers/extcon/extcon-rtk-type-c.c new file +316
-0+ ret = -EINVAL ; + goto err1; + } + +INIT_DELAYED_WORK (&type_c->delayed_work, host_device_switch); + + ret =extcon_rtk_type_c_init (type_c); +if (ret) { +dev_err (dev,"%s failed to init type_c\n" , __func__); + goto err1; + } + +platform_set_drvdata (pdev, type_c); + + ret =extcon_rtk_type_c_edev_register (type_c); + +create_debug_files (type_c); + +return 0 ; + +err1: +dev_err (&pdev->dev,"%s: Probe fail, %d\n" , __func__, ret); + +return ret; +} + +static void extcon_rtk_type_c_remove (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct type_c_data *type_c =dev_get_drvdata (dev); +u32 default_ctrl; +unsigned long flags; + +remove_debug_files (type_c); + +#ifdef CONFIG_TYPEC +if (type_c->port) { +typec_unregister_port (type_c->port); + type_c->port =NULL ; + } +#endif + +cancel_delayed_work_sync (&type_c->delayed_work); +flush_delayed_work (&type_c->delayed_work); +WARN_ON_ONCE (delayed_work_pending (&type_c->delayed_work)); + +spin_lock_irqsave (&type_c->lock, flags); +/* disable interrupt */ + default_ctrl =readl (type_c->reg_base +USB_TYPEC_CTRL ) & +DEBOUNCE_TIME_MASK ; +writel (default_ctrl, type_c->reg_base +USB_TYPEC_CTRL ); + +/* disable cc detect, rp, rd */ +writel (PLR_EN , type_c->reg_base +USB_TYPEC_CTRL_CC1_0 ); +writel (0 , type_c->reg_base +USB_TYPEC_CTRL_CC2_0 ); + +spin_unlock_irqrestore (&type_c->lock, flags); + +free_irq (type_c->irq, type_c); +} + +static const struct type_c_cfg rtd1295_type_c_cfg = { + .parameter_ver =PARAMETER_V0 , + .cc_dfp_mode =CC_MODE_DFP_3_0 , + .cc1_param = { .rp_4p7k_code =0xb , + .rp_36k_code =0x17 , + .rp_12k_code =0x10 , + .rd_code =0 , + .ra_code =0 , + .vref_2p6v =0x0 , + .vref_1p23v =0x0 , + .vref_0p8v =0x3 , + .vref_0p66v =0x0 , + .vref_0p4v =0x0 , + .vref_0p2v =0x4 , + .vref_1_1p6v =0 , + .vref_0_1p6v =0 }, + .cc2_param = { .rp_4p7k_code =0xc , + .rp_36k_code =0x17 , + .rp_12k_code =0x12 , + .rd_code =0 , + .ra_code =0 , + .vref_2p6v =0x2 , + .vref_1p23v =0x0 , + .vref_0p8v =0x3 , + .vref_0p66v =0x0 , + .vref_0p4v =0x0 , + .vref_0p2v =0x5 , + .vref_1_1p6v =0 , + .vref_0_1p6v =0 }, + .debounce_val =0x7f ,/* 1b,1us 7f,4.7us */ + .use_defalut_parameter = false, +}; + +static const struct type_c_cfg rtd1395_type_c_cfg = { + .parameter_ver =PARAMETER_V0 , + .cc_dfp_mode =CC_MODE_DFP_3_0 , + .cc1_param = { .rp_4p7k_code =0xc , + .rp_36k_code =0xb , + .rp_12k_code =0xe , + .rd_code =0x10 , + .ra_code =0x0 , + .vref_2p6v =0x0 , + .vref_1p23v =0x1 , + .vref_0p8v =0x0 , + .vref_0p66v =0x0 , + .vref_0p4v =0x3 , + .vref_0p2v =0x0 , + .vref_1_1p6v =0x7 , + .vref_0_1p6v =0x7 }, + .cc2_param = { .rp_4p7k_code =0xb , + .rp_36k_code =0x9 , + .rp_12k_code =0xe , + .rd_code =0xf , + .ra_code =0x0 , + .vref_2p6v =0x1 , + .vref_1p23v =0x3 , + .vref_0p8v =0x3 , + .vref_0p66v =0x2 , + .vref_0p4v =0x3 , + .vref_0p2v =0x2 , + .vref_1_1p6v =0x7 , + .vref_0_1p6v =0x7 }, + .debounce_val =0x7f ,/* 1b,1us 7f,4.7us */ + .use_defalut_parameter = false, +}; + +static const struct type_c_cfg rtd1619_type_c_cfg = { + .parameter_ver =PARAMETER_V0 , + .cc_dfp_mode =CC_MODE_DFP_3_0 , + .cc1_param = { .rp_4p7k_code =0xc , + .rp_36k_code =0xf , + .rp_12k_code =0xe , + .rd_code =0x11 , + .ra_code =0x0 , + .vref_2p6v =0x5 , + .vref_1p23v =0x7 , + .vref_0p8v =0xa , + .vref_0p66v =0xa , + .vref_0p4v =0x3 , + .vref_0p2v =0x2 , + .vref_1_1p6v =0x7 , + .vref_0_1p6v =0x7 }, + .cc2_param = { .rp_4p7k_code =0xc , + .rp_36k_code =0xf , + .rp_12k_code =0xe , + .rd_code =0xf , + .ra_code =0x0 , + .vref_2p6v =0x5 , + .vref_1p23v =0x8 , + .vref_0p8v =0xa , + .vref_0p66v =0xa , + .vref_0p4v =0x3 , + .vref_0p2v =0x2 , + .vref_1_1p6v =0x7 , + .vref_0_1p6v =0x7 }, + .debounce_val =0x7f ,/* 1b,1us 7f,4.7us */ + .use_defalut_parameter = false, +}; + +static const struct type_c_cfg rtd1319_type_c_cfg = { + .parameter_ver =PARAMETER_V0 , + .cc_dfp_mode =CC_MODE_DFP_1_5 , + .cc1_param = { .rp_4p7k_code =0x9 , + .rp_36k_code =0xe , + .rp_12k_code =0x9 , + .rd_code =0x9 , + .ra_code =0x7 , + .vref_2p6v =0x3 , + .vref_1p23v =0x7 , + .vref_0p8v =0x7 , + .vref_0p66v =0x6 , + .vref_0p4v =0x2 , + .vref_0p2v =0x3 , + .vref_1_1p6v =0x4 , + .vref_0_1p6v =0x7 }, + .cc2_param = { .rp_4p7k_code =0x8 , + .rp_36k_code =0xe , + .rp_12k_code =0x9 , + .rd_code =0x9 , + .ra_code =0x7 , + .vref_2p6v =0x3 , + .vref_1p23v =0x7 , + .vref_0p8v =0x7 , + .vref_0p66v =0x6 , + .vref_0p4v =0x3 , + .vref_0p2v =0x3 , + .vref_1_1p6v =0x6 , + .vref_0_1p6v =0x7 }, + .debounce_val =0x7f ,/* 1b,1us 7f,4.7us */ + .use_defalut_parameter = false, +}; + +static const struct type_c_cfg rtd1312c_type_c_cfg = { + .parameter_ver =PARAMETER_V0 , + .cc_dfp_mode =CC_MODE_DFP_1_5 , + .cc1_param = { .rp_4p7k_code =0xe , + .rp_36k_code =0xc , + .rp_12k_code =0xc , + .rd_code =0xa , + .ra_code =0x3 , + .vref_2p6v =0xa , + .vref_1p23v =0x7 , + .vref_0p8v =0x7 , + .vref_0p66v =0x7 , + .vref_0p4v =0x4 , + .vref_0p2v =0x4 , + .vref_1_1p6v =0x7 , + .vref_0_1p6v =0x7 }, + .cc2_param = { .rp_4p7k_code =0xe , + .rp_36k_code =0xc , + .rp_12k_code =0xc , + .rd_code =0xa , + .ra_code =0x3 , + .vref_2p6v =0xa , + .vref_1p23v =0x7 , + .vref_0p8v =0x7 , + .vref_0p66v =0x7 , + .vref_0p4v =0x4 , + .vref_0p2v =0x4 , + .vref_1_1p6v =0x7 , + .vref_0_1p6v =0x7 }, + .debounce_val =0x7f ,/* 1b,1us 7f,4.7us */ + .use_defalut_parameter = false, +}; + +static const struct type_c_cfg rtd1619b_type_c_cfg = { + .parameter_ver =PARAMETER_V1 , + .cc_dfp_mode =CC_MODE_DFP_1_5 , + .cc1_param = { .rp_4p7k_code =0xf , + .rp_36k_code =0xf , + .rp_12k_code =0xf , + .rd_code =0xf , + .ra_code =0x7 , + .vref_2p6v =0x9 , + .vref_1p23v =0x7 , + .vref_0p8v =0x9 , + .vref_0p66v =0x8 , + .vref_0p4v =0x7 , + .vref_0p2v =0x9 , + .vref_1_1p6v =0x7 , + .vref_0_1p6v =0x7 }, + .cc2_param = { .rp_4p7k_code =0xf , + .rp_36k_code =0xf , + .rp_12k_code =0xf , + .rd_code =0xf , + .ra_code =0x7 , + .vref_1p23v =0x7 , + .vref_0p8v =0x9 , + .vref_0p66v =0x8 , + .vref_0p4v =0x7 , + .vref_0p2v =0x8 , + .vref_1_1p6v =0x7 , + .vref_0_1p6v =0x7 }, + .debounce_val =0x7f ,/* 1b,1us 7f,4.7us */ + .use_defalut_parameter = false, +}; + +static const struct type_c_cfg rtd1319d_type_c_cfg = { + .parameter_ver =PARAMETER_V1 , + .cc_dfp_mode =CC_MODE_DFP_1_5 , + .cc1_param = { .rp_4p7k_code =0xe , + .rp_36k_code =0x3 , + .rp_12k_code =0xe , + .rd_code =0xf , + .ra_code =0x6 , + .vref_2p6v =0x7 , + .vref_1p23v =0x7 , + .vref_0p8v =0x8 , + .vref_0p66v =0x7 , + .vref_0p4v =0x7 , + .vref_0p2v =0x7 , + .vref_1_1p6v =0x7 , + .vref_0_1p6v =0x7 }, + .cc2_param = { .rp_4p7k_code =0xe , + .rp_36k_code =0x3 , + .rp_12k_code =0xe , + .rd_code =0xf , + .ra_code =0x6 , + .vref_2p6v =0x7 , + .vref_1p23v =0x7 , + .vref_0p8v =0x8 , + .vref_0p66v =0x7 , + .vref_0p4v =0x7 , + .vref_0p2v =0x8 , + .vref_1_1p6v =0x7 , + .vref_0_1p6v =0x7 }, + .debounce_val =0x7f ,/* 1b,1us 7f,4.7us */ + .use_defalut_parameter = false, +}; + +static const struct type_c_cfg rtd1315e_type_c_cfg = { + .parameter_ver =PARAMETER_V1 , + .cc_dfp_mode =CC_MODE_DFP_1_5 , + .cc1_param = { .rp_4p7k_code =0xe , + .rp_36k_code =0x3 , + .rp_12k_code =0xe , + .rd_code =0xf , + .ra_code =0x6 , + .vref_2p6v =0x7 , + .vref_1p23v =0x7 , + .vref_0p8v =0x8 , + .vref_0p66v =0x7 , + .vref_0p4v =0x7 , + .vref_0p2v =0x7 , + .vref_1_1p6v =0x7 , + .vref_0_1p6v =0x7 }, + .cc2_param = { .rp_4p7k_code =0xe , + .rp_36k_code =0x3 , + .rp_12k_code =0xe , + .rd_code =0xf , + .ra_code =0x6 , + .vref_2p6v =0x7 , + .vref_1p23v =0x7 , + .vref_0p8v =0x8 , + .vref_0p66v =0x7 ,drivers/extcon/extcon-rtk-type-c.c
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+ .vref_0p4v = 0x7, + .vref_0p2v = 0x8, + .vref_1_1p6v = 0x7, + .vref_0_1p6v = 0x7 }, + .debounce_val = 0x7f, /* 1b,1us 7f,4.7us */ + .use_defalut_parameter = false, +}; + +static const struct of_device_id extcon_rtk_type_c_match[] = { + { .compatible = "realtek,rtd1295-type-c", .data =
&rtd1295_type_c_cfg},Quoted 1 line
+ { .compatible = "realtek,rtd1312c-type-c", .data =
&rtd1312c_type_c_cfg},Quoted 1 line
+ { .compatible = "realtek,rtd1315e-type-c", .data =
&rtd1315e_type_c_cfg},Quoted 1 line
+ { .compatible = "realtek,rtd1319-type-c", .data =
&rtd1319_type_c_cfg},Quoted 1 line
+ { .compatible = "realtek,rtd1319d-type-c", .data =
&rtd1319d_type_c_cfg},Quoted 1 line
+ { .compatible = "realtek,rtd1395-type-c", .data =
&rtd1395_type_c_cfg},Quoted 1 line
+ { .compatible = "realtek,rtd1619-type-c", .data =
&rtd1619_type_c_cfg},Quoted 1 line
+ { .compatible = "realtek,rtd1619b-type-c", .data =
&rtd1619b_type_c_cfg},Quoted 30 lines
drivers/extcon/extcon-rtk-type-c.c new file +30
-0+ {}, +}; +MODULE_DEVICE_TABLE (of, extcon_rtk_type_c_match); + +#ifdef CONFIG_PM_SLEEP +static int extcon_rtk_type_c_prepare (struct device *dev) +{ +struct type_c_data *type_c =dev_get_drvdata (dev); +u32 default_ctrl; +unsigned long flags; + +cancel_delayed_work_sync (&type_c->delayed_work); +flush_delayed_work (&type_c->delayed_work); +WARN_ON_ONCE (delayed_work_pending (&type_c->delayed_work)); + +spin_lock_irqsave (&type_c->lock, flags); +/* disable interrupt */ + default_ctrl =readl (type_c->reg_base +USB_TYPEC_CTRL ) & +DEBOUNCE_TIME_MASK ; +writel (default_ctrl, type_c->reg_base +USB_TYPEC_CTRL ); + +/* disable cc detect, rp, rd */ +writel (PLR_EN , type_c->reg_base +USB_TYPEC_CTRL_CC1_0 ); +writel (0 , type_c->reg_base +USB_TYPEC_CTRL_CC2_0 ); + +spin_unlock_irqrestore (&type_c->lock, flags); + +return 0 ; +} +drivers/extcon/extcon-rtk-type-c.c line 1758
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+static void extcon_rtk_type_c_complete (struct device *dev) +{ +/* nothing */ +} + +static int extcon_rtk_type_c_suspend (struct device *dev) +{ +struct type_c_data *type_c =dev_get_drvdata (dev); + +if (type_c->rd_ctrl_gpio !=-1 )ditto.
Quoted 6 lines
drivers/extcon/extcon-rtk-type-c.c new file +6
-0+gpio_free (type_c->rd_ctrl_gpio); + +return 0 ; +} + +static int extcon_rtk_type_c_resume (struct device *dev)drivers/extcon/extcon-rtk-type-c.c
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+{ +struct type_c_data *type_c =dev_get_drvdata (dev); + +extcon_rtk_type_c_init (type_c); + +return 0 ; +} + +static const struct dev_pm_ops extcon_rtk_type_c_pm_ops = { + SET_LATE_SYSTEM_SLEEP_PM_OPS(extcon_rtk_type_c_suspend,
extcon_rtk_type_c_resume)Quoted 17 lines
drivers/extcon/extcon-rtk-type-c.c new file +17
-0+ .prepare = extcon_rtk_type_c_prepare, + .complete = extcon_rtk_type_c_complete, +}; + +#define DEV_PM_OPS (&extcon_rtk_type_c_pm_ops) +#else +#define DEV_PM_OPS NULL +#endif /* CONFIG_PM_SLEEP */ + +static struct platform_driver extcon_rtk_type_c_driver = { + .probe = extcon_rtk_type_c_probe, + .remove_new = extcon_rtk_type_c_remove, + .driver = { + .name ="extcon-rtk-type_c" , + .of_match_table = extcon_rtk_type_c_match, + .pm =DEV_PM_OPS , + },
Quoted 9 lines
drivers/extcon/extcon-rtk-type-c.c line 1799
Quoted 8 lines
drivers/extcon/extcon-rtk-type-c.c new file +8
-0+}; + +module_platform_driver (extcon_rtk_type_c_driver); + +MODULE_DESCRIPTION ("Realtek Extcon Type C driver" ); +MODULE_ALIAS ("platform:extcon-rtk-type-c" ); +MODULE_AUTHOR ("Stanley Chang <[email protected]>" ); +MODULE_LICENSE ("GPL" );
Thanks,
Stanley
Hi Chanwoo,
Quoted 33 lines
Quoted 4 lines
drivers/extcon/extcon-rtk-type-c.c new file +4
-0+static int rtd129x_switch_type_c_plug_config (struct type_c_data *type_c, +int dr_mode,int cc) +{ +void __iomem *reg = type_c->reg_base +USB_TYPEC_CTRL_CC1_0 ;drivers/extcon/extcon-rtk-type-c.c line 255
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+int val_cc; + +#define TYPE_C_EN_SWITCH BIT(29) +#define TYPE_C_TXRX_SEL (BIT(28) | BIT(27)) +#define TYPE_C_SWITCH_MASK (TYPE_C_EN_SWITCH | TYPE_C_TXRX_SEL) +#define TYPE_C_ENABLE_CC1 TYPE_C_EN_SWITCH +#define TYPE_C_ENABLE_CC2 (TYPE_C_EN_SWITCH | TYPE_C_TXRX_SEL) +#define TYPE_C_DISABLE_CC ~TYPE_C_SWITCH_MASK + + val_cc =readl (reg);I'd like you to use regmap interface to access the register by using
regmap_read,regmap_write. You can create the regmap instance viadevm_regmap_init_mmio()on probe instead of using 'type_c->reg_base' at the multipe point.For example,
struct regmap_config rtk_regmap_config = { .reg_bits = 32, .val_bits = 32, }; void __iomem *base; base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); if (IS_ERR(base)) return PTR_ERR(base); regmap = devm_regmap_init_mmio(dev, base,
Quoted 9 lines
&rtk_regmap_config);---
And then just call
regmap_readwithout any calculation between base address and specific register.
regmap_read(regmap, USB_TYPEC_CTRL_CC1_0)
I studied mmio's regmap.
It only changed one encoding method. And simplifies the calculation between the base address and the specific register. If the register is 32-bit aligned, other operations look the same as readl/writel.
I think regmap is more simplified if the read registers are not 32-bit aligned, e.g. nvmem read/write.
So it would be more intuitive for me to keep writel/readl here
Quoted 11 lines
drivers/extcon/extcon-rtk-type-c.c
Quoted 11 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+ val_cc &= ~TYPE_C_SWITCH_MASK ; + +if (cc ==DISABLE_CC ) { + val_cc &=TYPE_C_DISABLE_CC ; + }else if (cc ==ENABLE_CC1 ) { + val_cc |=TYPE_C_ENABLE_CC1 ; + }else if (cc ==ENABLE_CC2 ) { + val_cc |=TYPE_C_ENABLE_CC2 ; + }else { + dev_err(type_c->dev, "%s: Error cc setting cc=0x%x\n",
Quoted 5 lines
__func__, cc);Quoted 4 lines
drivers/extcon/extcon-rtk-type-c.c new file +4
-0+return -EINVAL ; + } +writel (val_cc, reg); +
Thanks,
Stanley
Hi Stanley,
Quoted 42 lines · Stanley Chang[昌育德]
Hi Chanwoo,
Quoted 40 lines
Quoted 4 lines
drivers/extcon/extcon-rtk-type-c.c new file +4
-0+static int rtd129x_switch_type_c_plug_config (struct type_c_data *type_c, +int dr_mode,int cc) +{ +void __iomem *reg = type_c->reg_base +USB_TYPEC_CTRL_CC1_0 ;drivers/extcon/extcon-rtk-type-c.c line 255
Quoted 10 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+int val_cc; + +#define TYPE_C_EN_SWITCH BIT(29) +#define TYPE_C_TXRX_SEL (BIT(28) | BIT(27)) +#define TYPE_C_SWITCH_MASK (TYPE_C_EN_SWITCH | TYPE_C_TXRX_SEL) +#define TYPE_C_ENABLE_CC1 TYPE_C_EN_SWITCH +#define TYPE_C_ENABLE_CC2 (TYPE_C_EN_SWITCH | TYPE_C_TXRX_SEL) +#define TYPE_C_DISABLE_CC ~TYPE_C_SWITCH_MASK + + val_cc =readl (reg);I'd like you to use regmap interface to access the register by using
regmap_read,regmap_write. You can create the regmap instance viadevm_regmap_init_mmio()on probe instead of using 'type_c->reg_base' at the multipe point.For example,
struct regmap_config rtk_regmap_config = { .reg_bits = 32, .val_bits = 32, }; void __iomem *base; base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); if (IS_ERR(base)) return PTR_ERR(base); regmap = devm_regmap_init_mmio(dev, base,
&rtk_regmap_config);---
And then just call
regmap_readwithout any calculation between base address and specific register.
Quoted 6 lines
Quoted 2 lines
regmap_read(regmap, USB_TYPEC_CTRL_CC1_0)I studied mmio's regmap.
It only changed one encoding method. And simplifies the calculation between the base address and the specific register.
The regmap provides the consistent interface to access register regardless of mmio/i2c/spi and so on. It is the advantage of regmap.
And regmap provides the like register dump via debugfs,
is able to specify the kind of register like writable, readable, volatile type. It is possible to specify the more detailed register information in device driver in order to improve the readability. It allows you to express more detail of this device than just working.
Quoted 2 lines
If the register is 32-bit aligned, other operations look the same as readl/writel.
I think regmap is more simplified if the read registers are not 32-bit aligned, e.g. nvmem read/write.
I'm sorry. I don't understand of what is accurate meaning.
Could you please explain your opinion more detailed with example of this patch?
Quoted 21 lines
So it would be more intuitive for me to keep writel/readl here
Quoted 11 lines
drivers/extcon/extcon-rtk-type-c.c
Quoted 11 lines
drivers/extcon/extcon-rtk-type-c.c new file +10
-0+ val_cc &= ~TYPE_C_SWITCH_MASK ; + +if (cc ==DISABLE_CC ) { + val_cc &=TYPE_C_DISABLE_CC ; + }else if (cc ==ENABLE_CC1 ) { + val_cc |=TYPE_C_ENABLE_CC1 ; + }else if (cc ==ENABLE_CC2 ) { + val_cc |=TYPE_C_ENABLE_CC2 ; + }else { + dev_err(type_c->dev, "%s: Error cc setting cc=0x%x\n",Quoted 5 lines
__func__, cc);Quoted 4 lines
drivers/extcon/extcon-rtk-type-c.c new file +4
-0+return -EINVAL ; + } +writel (val_cc, reg); +Thanks,
Stanley
Signature · 3 lines
Best Regards, Samsung Electronics Chanwoo Choi
Hi Chanwoo,
Quoted 45 lines
Quoted 3 lines
Quoted 3 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+#define TYPE_C_EN_SWITCH BIT(29) +#define TYPE_C_TXRX_SEL (BIT(28) | BIT(27)) #define +TYPE_C_SWITCH_MASK (TYPE_C_EN_SWITCH | TYPE_C_TXRX_SEL)#define
Quoted 1 line
Quoted 1 line
Quoted 1 line
+TYPE_C_ENABLE_CC1
TYPE_C_EN_SWITCH#define
TYPE_C_ENABLE_CC2Quoted 16 lines
Quoted 16 lines
drivers/extcon/extcon-rtk-type-c.c line 255
Quoted 4 lines
drivers/extcon/extcon-rtk-type-c.c new file +4
-0+(TYPE_C_EN_SWITCH | TYPE_C_TXRX_SEL) #define TYPE_C_DISABLE_CC +~TYPE_C_SWITCH_MASK + + val_cc = readl(reg);I'd like you to use regmap interface to access the register by using
regmap_read,regmap_write. You can create the regmap instance viadevm_regmap_init_mmio()on probe instead of using 'type_c->reg_base' at the multipe point.For example,
struct regmap_config rtk_regmap_config = { .reg_bits = 32, .val_bits = 32, };Quoted 3 lines
Quoted 3 lines
void
__iomem*base;base = devm_platform_get_and_ioremap_resource(pdev, 0,
&res);
Quoted 11 lines
Quoted 11 lines
if (IS_ERR(base)) return PTR_ERR(base); regmap = devm_regmap_init_mmio(dev, base,
&rtk_regmap_config);---
And then just call
regmap_readwithout any calculation between base address and specific register.Quoted 6 lines
Quoted 2 lines
regmap_read(regmap, USB_TYPEC_CTRL_CC1_0)I studied mmio's regmap.
It only changed one encoding method. And simplifies the calculation
between the base address and the specific register.
Quoted 8 lines
The regmap provides the consistent interface to access register regardless of mmio/i2c/spi and so on. It is the advantage of regmap.
And regmap provides the like register dump via debugfs, is able to specify the kind of register like writable, readable, volatile type.
It is possible to specify the more detailed register information in device driver in order to improve the readability. It allows you to express more detail of this device than just working.
These are all advantages of regmap, I agree.
I haven't delved into regmap yet.
Quoted 9 lines
Quoted 2 lines
If the register is 32-bit aligned, other operations look the same as
readl/writel.
Quoted 1 line
I think regmap is more simplified if the read registers are not 32-bit aligned,
e.g. nvmem read/write.
I'm sorry. I don't understand of what is accurate meaning. Could you please explain your opinion more detailed with example of this patch?
Sorry, I misunderstood regmap, I thought he could read register like read otp tables by nvmem regardless of his bitness and size. So my answer should be incorrect.
Thank,
Stanley