Skip to contentSkip to conversation

Add iop driver for Sunplus SP7021

PATCH Superseded Tony Huang 5 participants 15 messages Mar 12, 2022 – Mar 15, 2022

Subsystems (2)

v11 of 12 Superseded Latest is v12 →

lore
Share & tools
lore

Tony Huang

author
#0 lore raw

v11 cover Add iop driver for Sunplus SP7021

Add iop driver for Sunplus SP7021 SOC

This is a patch series for iop driver for Sunplus SP7021 SOC.

Sunplus SP7021 is an ARM Cortex A7 (4 cores) based SoC. It integrates many peripherals (ex: UART, I2C, SPI, SDIO, eMMC, USB, SD card and etc.) into a single chip. It is designed for industrial control.

Refer to:
https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
https://tibbo.com/store/plus1.html

Tony Huang (2):
dt-bindings: misc: Add iop yaml file for Sunplus SP7021
misc: Add iop driver for Sunplus SP7021

 .../devicetree/bindings/misc/sunplus,iop.yaml      |  78 ++++
 MAINTAINERS                                        |   6 +
 drivers/misc/Kconfig                               |  23 ++
 drivers/misc/Makefile                              |   1 +
 drivers/misc/sunplus_iop.c                         | 411 +++++++++++++++++++++
 5 files changed, 519 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/misc/sunplus,iop.yaml
 create mode 100644 drivers/misc/sunplus_iop.c
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v11 1/2 dt-bindings: misc: Add iop yaml file for Sunplus SP7021

Add iop yaml file for Sunplus SP7021

---
Changes in v11:
- Addressed comments from krzysztof.

 .../devicetree/bindings/misc/sunplus,iop.yaml      | 78 ++++++++++++++++++++++
 MAINTAINERS                                        |  5 ++
 2 files changed, 83 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/misc/sunplus,iop.yaml
Documentation/devicetree/bindings/misc/sunplus,iop.yaml new file +78 -0
new file mode 100644
index 0000000..ad1c4be
@@ -0,0 +1,78 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) Sunplus Ltd. Co. 2021
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/misc/sunplus-iop.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sunplus IOP(8051) controller
+
+maintainers:
+  - Tony Huang <[email protected]>
+
+description: |
+  Processor for I/O control, RTC wake-up procedure management,
+  and cooperation with CPU&PMC in power management.
+
+properties:
+  compatible:
+    enum:
+      - sunplus,sp7021-iop
+
+  reg:
+    items:
+      - description: IOP registers regions
+      - description: PMC registers regions
+      - description: MOON0 registers regions
+
+  reg-names:
+    items:
+      - const: iop
+      - const: iop_pmc
+      - const: moon0
+
+  interrupts:
+    items:
+      - description: IOP_INT0. IOP to system Interrupt 0.
+                     Sent by IOP to system RISC.
+      - description: IOP_INT1. IOP to System Interrupt 1.
+                     Sent by IOP to system RISC.
+
+  memory-region:
+    maxItems: 1
+
+  wakeup-gpios:
+    description: When the linux kernel system is powered off.
+      8051 is always powered. 8051 cand receive external signals
+      according to this gpio pin. 8051 receives external signal
+      through gpio pin. 8051 can power on linux kernel system.
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - clocks
+  - interrupts
+  - memory-region
+  - wakeup-gpios
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/gpio/gpio.h>
+    iop: iop@9c000400 {
+        compatible = "sunplus,sp7021-iop";
+        reg = <0x9c000400 0x80>, <0x9c003100 0x80>, <0x9c000000 0x80>;
+        reg-names = "iop", "iop_pmc", "moon0";
+        clocks = <&clkc 0x14>;
+        interrupt-parent = <&intc>;
+        interrupts = <41 IRQ_TYPE_LEVEL_HIGH>, <42 IRQ_TYPE_LEVEL_HIGH>;
+        memory-region = <&iop_reserve>;
+        pinctrl-names = "default";
+        pinctrl-0 = <&iop_pins>;
+        wakeup-gpios = <&pctl 1 GPIO_ACTIVE_HIGH>;
+    };
\ No newline at end of file
MAINTAINERS +5 -0
index fb18ce7..d64c8ed 100644
@@ -18242,6 +18242,11 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/net/ethernet/dlink/sundance.c
 
+SUNPLUS IOP DRIVER
+M:	Tony Huang <[email protected]>
+S:	Maintained
+F:	Documentation/devicetree/bindings/misc/sunplus,iop.yaml
+
 SUPERH
 M:	Yoshinori Sato <[email protected]>
 M:	Rich Felker <[email protected]>
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH v11 1/2] dt-bindings: misc: Add iop yaml file for Sunplus SP7021

Quoted 19 lines · Tony Huang

Add iop yaml file for Sunplus SP7021

---
Changes in v11:
- Addressed comments from krzysztof.

 .../devicetree/bindings/misc/sunplus,iop.yaml      | 78 ++++++++++++++++++++++
 MAINTAINERS                                        |  5 ++
 2 files changed, 83 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/misc/sunplus,iop.yaml
Documentation/devicetree/bindings/misc/sunplus,iop.yaml new file +0 -0
new file mode 100644
index 0000000..ad1c4be

Documentation/devicetree/bindings/misc/sunplus,iop.yaml line 5

Quoted 5 lines
Documentation/devicetree/bindings/misc/sunplus,iop.yaml new file +5 -0
@@ -0,0 +1,78 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) Sunplus Ltd. Co. 2021
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/misc/sunplus-iop.yaml#

Still wrong path. This would be easily spotted if you test the bindings. Please run dt_binding_check. It's a requirement.

Quoted 64 lines
Documentation/devicetree/bindings/misc/sunplus,iop.yaml new file +64 -0
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sunplus IOP(8051) controller
+
+maintainers:
+  - Tony Huang <[email protected]>
+
+description: |
+  Processor for I/O control, RTC wake-up procedure management,
+  and cooperation with CPU&PMC in power management.
+
+properties:
+  compatible:
+    enum:
+      - sunplus,sp7021-iop
+
+  reg:
+    items:
+      - description: IOP registers regions
+      - description: PMC registers regions
+      - description: MOON0 registers regions
+
+  reg-names:
+    items:
+      - const: iop
+      - const: iop_pmc
+      - const: moon0
+
+  interrupts:
+    items:
+      - description: IOP_INT0. IOP to system Interrupt 0.
+                     Sent by IOP to system RISC.
+      - description: IOP_INT1. IOP to System Interrupt 1.
+                     Sent by IOP to system RISC.
+
+  memory-region:
+    maxItems: 1
+
+  wakeup-gpios:
+    description: When the linux kernel system is powered off.
+      8051 is always powered. 8051 cand receive external signals
+      according to this gpio pin. 8051 receives external signal
+      through gpio pin. 8051 can power on linux kernel system.
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - clocks
+  - interrupts
+  - memory-region
+  - wakeup-gpios
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/gpio/gpio.h>
+    iop: iop@9c000400 {
+        compatible = "sunplus,sp7021-iop";
+        reg = <0x9c000400 0x80>, <0x9c003100 0x80>, <0x9c000000 0x80>;

Documentation/devicetree/bindings/misc/sunplus,iop.yaml line 78

Quoted 10 lines
Documentation/devicetree/bindings/misc/sunplus,iop.yaml new file +9 -0
+        reg-names = "iop", "iop_pmc", "moon0";
+        clocks = <&clkc 0x14>;
+        interrupt-parent = <&intc>;
+        interrupts = <41 IRQ_TYPE_LEVEL_HIGH>, <42 IRQ_TYPE_LEVEL_HIGH>;
+        memory-region = <&iop_reserve>;
+        pinctrl-names = "default";
+        pinctrl-0 = <&iop_pins>;
+        wakeup-gpios = <&pctl 1 GPIO_ACTIVE_HIGH>;
+    };
\ No newline at end of file

You have a patch warning here.

Best regards,
Krzysztof

#3 lore raw

RE: [PATCH v11 1/2] dt-bindings: misc: Add iop yaml file for Sunplus SP7021

Dear Krzysztof:

Quoted 16 lines · Tony Huang
Quoted 9 lines

Add iop yaml file for Sunplus SP7021

---
Changes in v11:
- Addressed comments from krzysztof.

 .../devicetree/bindings/misc/sunplus,iop.yaml      | 78

++++++++++++++++++++++

Quoted 5 lines
 MAINTAINERS                                        |  5 ++
 2 files changed, 83 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/misc/sunplus,iop.yaml

Quoted 14 lines

Documentation/devicetree/bindings/misc/sunplus,iop.yaml line 4

Quoted 11 lines
Documentation/devicetree/bindings/misc/sunplus,iop.yaml new file +4 -0
new file mode 100644
index 0000000..ad1c4be
@@ -0,0 +1,78 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) # Copyright
+(C) Sunplus Ltd. Co. 2021 %YAML 1.2
+---
+$id: http://devicetree.org/schemas/misc/sunplus-iop.yaml#

Still wrong path. This would be easily spotted if you test the bindings. Please run dt_binding_check. It's a requirement.

I have run dt_binding_check and don't see error. Below is my modification
$id: http://devicetree.org/schemas/misc/sunplus,iop.yaml#

Quoted 66 lines
Quoted 55 lines
Documentation/devicetree/bindings/misc/sunplus,iop.yaml new file +54 -0
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sunplus IOP(8051) controller
+
+maintainers:
+  - Tony Huang <[email protected]>
+
+description: |
+  Processor for I/O control, RTC wake-up procedure management,
+  and cooperation with CPU&PMC in power management.
+
+properties:
+  compatible:
+    enum:
+      - sunplus,sp7021-iop
+
+  reg:
+    items:
+      - description: IOP registers regions
+      - description: PMC registers regions
+      - description: MOON0 registers regions
+
+  reg-names:
+    items:
+      - const: iop
+      - const: iop_pmc
+      - const: moon0
+
+  interrupts:
+    items:
+      - description: IOP_INT0. IOP to system Interrupt 0.
+                     Sent by IOP to system RISC.
+      - description: IOP_INT1. IOP to System Interrupt 1.
+                     Sent by IOP to system RISC.
+
+  memory-region:
+    maxItems: 1
+
+  wakeup-gpios:
+    description: When the linux kernel system is powered off.
+      8051 is always powered. 8051 cand receive external signals
+      according to this gpio pin. 8051 receives external signal
+      through gpio pin. 8051 can power on linux kernel system.
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - clocks
+  - interrupts
+  - memory-region
+  - wakeup-gpios
+

Documentation/devicetree/bindings/misc/sunplus,iop.yaml

Quoted 10 lines
Documentation/devicetree/bindings/misc/sunplus,iop.yaml new file +10 -0
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/gpio/gpio.h>
+    iop: iop@9c000400 {
+        compatible = "sunplus,sp7021-iop";
+        reg = <0x9c000400 0x80>, <0x9c003100 0x80>, <0x9c000000

0x80>;

Quoted 11 lines

Documentation/devicetree/bindings/misc/sunplus,iop.yaml

Quoted 4 lines
Documentation/devicetree/bindings/misc/sunplus,iop.yaml new file +4 -0
+        reg-names = "iop", "iop_pmc", "moon0";
+        clocks = <&clkc 0x14>;
+        interrupt-parent = <&intc>;
+        interrupts = <41 IRQ_TYPE_LEVEL_HIGH>, <42

IRQ_TYPE_LEVEL_HIGH>;

Quoted 6 lines
Documentation/devicetree/bindings/misc/sunplus,iop.yaml new file +5 -0
+        memory-region = <&iop_reserve>;
+        pinctrl-names = "default";
+        pinctrl-0 = <&iop_pins>;
+        wakeup-gpios = <&pctl 1 GPIO_ACTIVE_HIGH>;
+    };
\ No newline at end of file

I will modify.

#4 lore raw

Re: [PATCH v11 1/2] dt-bindings: misc: Add iop yaml file for Sunplus SP7021

In reply to Tony Huang
Quoted 64 lines · Tony Huang

Add iop yaml file for Sunplus SP7021

---
Changes in v11:
- Addressed comments from krzysztof.

 .../devicetree/bindings/misc/sunplus,iop.yaml      | 78 ++++++++++++++++++++++
 MAINTAINERS                                        |  5 ++
 2 files changed, 83 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/misc/sunplus,iop.yaml
Documentation/devicetree/bindings/misc/sunplus,iop.yaml new file +45 -0
new file mode 100644
index 0000000..ad1c4be
@@ -0,0 +1,78 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) Sunplus Ltd. Co. 2021
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/misc/sunplus-iop.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sunplus IOP(8051) controller
+
+maintainers:
+  - Tony Huang <[email protected]>
+
+description: |
+  Processor for I/O control, RTC wake-up procedure management,
+  and cooperation with CPU&PMC in power management.
+
+properties:
+  compatible:
+    enum:
+      - sunplus,sp7021-iop
+
+  reg:
+    items:
+      - description: IOP registers regions
+      - description: PMC registers regions
+      - description: MOON0 registers regions
+
+  reg-names:
+    items:
+      - const: iop
+      - const: iop_pmc
+      - const: moon0
+
+  interrupts:
+    items:
+      - description: IOP_INT0. IOP to system Interrupt 0.
+                     Sent by IOP to system RISC.
+      - description: IOP_INT1. IOP to System Interrupt 1.
+                     Sent by IOP to system RISC.
+
+  memory-region:
+    maxItems: 1
+
+  wakeup-gpios:
+    description: When the linux kernel system is powered off.

Documentation/devicetree/bindings/misc/sunplus,iop.yaml line 55

Quoted 10 lines
Documentation/devicetree/bindings/misc/sunplus,iop.yaml new file +10 -0
+      8051 is always powered. 8051 cand receive external signals
+      according to this gpio pin. 8051 receives external signal
+      through gpio pin. 8051 can power on linux kernel system.
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - clocks

Why do you have clocks here but not in properties?

Best regards,
Krzysztof

#5 lore raw

RE: [PATCH v11 1/2] dt-bindings: misc: Add iop yaml file for Sunplus SP7021

Dear Krzysztof:

Quoted 71 lines · Tony Huang
Quoted 9 lines

Add iop yaml file for Sunplus SP7021

---
Changes in v11:
- Addressed comments from krzysztof.

 .../devicetree/bindings/misc/sunplus,iop.yaml      | 78

++++++++++++++++++++++

Quoted 60 lines
 MAINTAINERS                                        |  5 ++
 2 files changed, 83 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/misc/sunplus,iop.yaml

Documentation/devicetree/bindings/misc/sunplus,iop.yaml new file +48 -0
new file mode 100644
index 0000000..ad1c4be
@@ -0,0 +1,78 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) # Copyright
+(C) Sunplus Ltd. Co. 2021 %YAML 1.2
+---
+$id: http://devicetree.org/schemas/misc/sunplus-iop.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sunplus IOP(8051) controller
+
+maintainers:
+  - Tony Huang <[email protected]>
+
+description: |
+  Processor for I/O control, RTC wake-up procedure management,
+  and cooperation with CPU&PMC in power management.
+
+properties:
+  compatible:
+    enum:
+      - sunplus,sp7021-iop
+
+  reg:
+    items:
+      - description: IOP registers regions
+      - description: PMC registers regions
+      - description: MOON0 registers regions
+
+  reg-names:
+    items:
+      - const: iop
+      - const: iop_pmc
+      - const: moon0
+
+  interrupts:
+    items:
+      - description: IOP_INT0. IOP to system Interrupt 0.
+                     Sent by IOP to system RISC.
+      - description: IOP_INT1. IOP to System Interrupt 1.
+                     Sent by IOP to system RISC.
+
+  memory-region:
+    maxItems: 1
+
+  wakeup-gpios:
+    description: When the linux kernel system is powered off.
+      8051 is always powered. 8051 cand receive external signals
+      according to this gpio pin. 8051 receives external signal
+      through gpio pin. 8051 can power on linux kernel system.
+    maxItems: 1
Quoted 8 lines

Documentation/devicetree/bindings/misc/sunplus,iop.yaml line 55

Quoted 6 lines
Documentation/devicetree/bindings/misc/sunplus,iop.yaml new file +6 -0
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - clocks

Why do you have clocks here but not in properties?

I will modify. Add clocks in properties.

maintainer
#6 lore raw

Re: [PATCH v11 1/2] dt-bindings: misc: Add iop yaml file for Sunplus SP7021

In reply to Tony Huang
Quoted 4 lines · Tony Huang

Add iop yaml file for Sunplus SP7021

Quoted 9 lines

---
Changes in v11:
- Addressed comments from krzysztof.

 .../devicetree/bindings/misc/sunplus,iop.yaml      | 78 ++++++++++++++++++++++
 MAINTAINERS                                        |  5 ++
 2 files changed, 83 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/misc/sunplus,iop.yaml

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:
./Documentation/devicetree/bindings/misc/sunplus,iop.yaml:78:7: [error] no new line character at the end of file (new-line-at-end-of-file)

dtschema/dtc warnings/errors:
./Documentation/devicetree/bindings/misc/sunplus,iop.yaml: $id: relative path/filename doesn't match actual path or filename
expected: http://devicetree.org/schemas/misc/sunplus,iop.yaml#
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/misc/sunplus,iop.example.dt.yaml: iop@9c000400: 'clocks' does not match any of the regexes: 'pinctrl-[0-9]+'
From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/misc/sunplus,iop.yaml

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/patch/1604673

This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit.

author
#7 lore raw

PATCH v11 2/2 misc: Add iop driver for Sunplus SP7021

In reply to Tony Huang

This driver is load 8051 bin code.
The IOP core is DQ8051, so also named IOP8051.
Need Install DQ8051, The DQ8051 bin file generated by keil C. We will provide users with 8051 normal and power off source code.
Path: https://sunplus.atlassian.net/wiki/spaces/doc/pages/610172933/
How+to+use+I+O+processor+8051+of+SP7021#5.-Write-C-or-assembly-source- files-for-IOP
Users can follow the operation steps to generate normal.bin and poweroff.bin.
Path: https://sunplus.atlassian.net/wiki/spaces/doc/pages/466190338
/26.+IOP8051 26.5?How To Create 8051 bin file

PMC in power management purpose:
Add sp_iop_poweroff() function. pm_power_off=sp_iop_poweroff. When the power off command is executed.
The 8051 has a register(DEF_PWR_EN_0=0) to control the power-on and power-off of the system.

---
Changes in v11:
- Addressed comments from Arnd Bergmann.
- Addressed comments from krzysztof.

 MAINTAINERS                |   1 +
 drivers/misc/Kconfig       |  23 +++
 drivers/misc/Makefile      |   1 +
 drivers/misc/sunplus_iop.c | 411 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 436 insertions(+)
 create mode 100644 drivers/misc/sunplus_iop.c
MAINTAINERS +1 -0
index d64c8ed..c282e95 100644
@@ -18246,6 +18246,7 @@ SUNPLUS IOP DRIVER
 M:	Tony Huang <[email protected]>
 S:	Maintained
 F:	Documentation/devicetree/bindings/misc/sunplus,iop.yaml
+F:	drivers/misc/sunplus_iop.c
 
 SUPERH
 M:	Yoshinori Sato <[email protected]>
drivers/misc/Kconfig +23 -0
index 0f5a49f..e5f32d8 100644
@@ -470,6 +470,29 @@ config HISI_HIKEY_USB
 	  switching between the dual-role USB-C port and the USB-A host ports
 	  using only one USB controller.
 
+config SUNPLUS_IOP
+	tristate "Sunplus IOP support"
+	default ARCH_SUNPLUS
+	help
+	  This driver is load 8051 bin code.
+	  The IOP core is DQ8051, so also named IOP8051.
+	  Need Install DQ8051, The DQ8051 bin file generated by keil C.
+	  We will provide users with 8051 normal and power off source code.
+	  Path: https://sunplus.atlassian.net/wiki/spaces/doc/pages/610172933/
+	  How+to+use+I+O+processor+8051+of+SP7021#5.-Write-C-or-assembly-source-files-for-IOP
+	  Users can follow the operation steps to generate normal.bin and poweroff.bin.
+	  Path: https://sunplus.atlassian.net/wiki/spaces/doc/pages/466190338/26.+IOP8051
+	  26.5?How To Create 8051 bin file
+
+	  PMC in power management purpose:
+	  Add sp_iop_poweroff() function. pm_power_off=sp_iop_poweroff.
+	  When the power off command is executed.
+	  The 8051 has a register(DEF_PWR_EN_0=0) to control the power-on and
+	  power-off of the system.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called sunplus_iop.
+
 source "drivers/misc/c2port/Kconfig"
 source "drivers/misc/eeprom/Kconfig"
 source "drivers/misc/cb710/Kconfig"
drivers/misc/Makefile +1 -0
index a086197..eafeab6 100644
@@ -52,6 +52,7 @@ obj-$(CONFIG_DW_XDATA_PCIE)	+= dw-xdata-pcie.o
 obj-$(CONFIG_PCI_ENDPOINT_TEST)	+= pci_endpoint_test.o
 obj-$(CONFIG_OCXL)		+= ocxl/
 obj-$(CONFIG_BCM_VK)		+= bcm-vk/
+obj-$(CONFIG_SUNPLUS_IOP)	+= sunplus_iop.o
 obj-y				+= cardreader/
 obj-$(CONFIG_PVPANIC)   	+= pvpanic/
 obj-$(CONFIG_HABANA_AI)		+= habanalabs/
drivers/misc/sunplus_iop.c new file +411 -0

411 lines not on this page · raw message

Signature · 1 line
2.7.4
#8 lore raw

Re: [PATCH v11 2/2] misc: Add iop driver for Sunplus SP7021

Quoted 18 lines · Tony Huang

This driver is load 8051 bin code.
The IOP core is DQ8051, so also named IOP8051.
Need Install DQ8051, The DQ8051 bin file generated by keil C. We will provide users with 8051 normal and power off source code.
Path: https://sunplus.atlassian.net/wiki/spaces/doc/pages/610172933/
How+to+use+I+O+processor+8051+of+SP7021#5.-Write-C-or-assembly-source- files-for-IOP
Users can follow the operation steps to generate normal.bin and poweroff.bin.
Path: https://sunplus.atlassian.net/wiki/spaces/doc/pages/466190338
/26.+IOP8051 26.5?How To Create 8051 bin file

PMC in power management purpose:
Add sp_iop_poweroff() function. pm_power_off=sp_iop_poweroff. When the power off command is executed.
The 8051 has a register(DEF_PWR_EN_0=0) to control the power-on and power-off of the system.

Quoted 4 lines

---
Changes in v11:
- Addressed comments from Arnd Bergmann.

How did you address Arnd's comments about splitting the driver to proper parts? drivers/clk and drivers/power/reset?

Quoted 6 lines

- Addressed comments from krzysztof.

 MAINTAINERS                |   1 +
 drivers/misc/Kconfig       |  23 +++
 drivers/misc/Makefile      |   1 +
 drivers/misc/sunplus_iop.c | 411 +++++++++++++++++++++++++++++++++++++++++++++

The driver looks like SoC specific driver. Why did you put it in drivers/misc/, not in usual place - drivers/soc/? sp_iop_poweroff is still here.

Quoted 153 lines
 4 files changed, 436 insertions(+)
 create mode 100644 drivers/misc/sunplus_iop.c
MAINTAINERS +1 -0
index d64c8ed..c282e95 100644
@@ -18246,6 +18246,7 @@ SUNPLUS IOP DRIVER
 M:	Tony Huang <[email protected]>
 S:	Maintained
 F:	Documentation/devicetree/bindings/misc/sunplus,iop.yaml
+F:	drivers/misc/sunplus_iop.c
 
 SUPERH
 M:	Yoshinori Sato <[email protected]>
drivers/misc/Kconfig +23 -0
index 0f5a49f..e5f32d8 100644
@@ -470,6 +470,29 @@ config HISI_HIKEY_USB
 	  switching between the dual-role USB-C port and the USB-A host ports
 	  using only one USB controller.
 
+config SUNPLUS_IOP
+	tristate "Sunplus IOP support"
+	default ARCH_SUNPLUS
+	help
+	  This driver is load 8051 bin code.
+	  The IOP core is DQ8051, so also named IOP8051.
+	  Need Install DQ8051, The DQ8051 bin file generated by keil C.
+	  We will provide users with 8051 normal and power off source code.
+	  Path: https://sunplus.atlassian.net/wiki/spaces/doc/pages/610172933/
+	  How+to+use+I+O+processor+8051+of+SP7021#5.-Write-C-or-assembly-source-files-for-IOP
+	  Users can follow the operation steps to generate normal.bin and poweroff.bin.
+	  Path: https://sunplus.atlassian.net/wiki/spaces/doc/pages/466190338/26.+IOP8051
+	  26.5?How To Create 8051 bin file
+
+	  PMC in power management purpose:
+	  Add sp_iop_poweroff() function. pm_power_off=sp_iop_poweroff.
+	  When the power off command is executed.
+	  The 8051 has a register(DEF_PWR_EN_0=0) to control the power-on and
+	  power-off of the system.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called sunplus_iop.
+
 source "drivers/misc/c2port/Kconfig"
 source "drivers/misc/eeprom/Kconfig"
 source "drivers/misc/cb710/Kconfig"
drivers/misc/Makefile +1 -0
index a086197..eafeab6 100644
@@ -52,6 +52,7 @@ obj-$(CONFIG_DW_XDATA_PCIE)	+= dw-xdata-pcie.o
 obj-$(CONFIG_PCI_ENDPOINT_TEST)	+= pci_endpoint_test.o
 obj-$(CONFIG_OCXL)		+= ocxl/
 obj-$(CONFIG_BCM_VK)		+= bcm-vk/
+obj-$(CONFIG_SUNPLUS_IOP)	+= sunplus_iop.o
 obj-y				+= cardreader/
 obj-$(CONFIG_PVPANIC)   	+= pvpanic/
 obj-$(CONFIG_HABANA_AI)		+= habanalabs/
drivers/misc/sunplus_iop.c new file +86 -0
new file mode 100644
index 0000000..5bdce5e
@@ -0,0 +1,411 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * The IOP driver for Sunplus SP7021
+ *
+ * Copyright (C) 2021 Sunplus Technology Inc.
+ *
+ * All Rights Reserved.
+ */
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/dma-mapping.h>
+#include <linux/firmware.h>
+#include <linux/iopoll.h>
+#include <linux/module.h>
+#include <linux/of_platform.h>
+#include <linux/of_address.h>
+#include <linux/of_gpio.h>
+
+/* IOP register offset */
+#define IOP_CONTROL	0x00
+#define IOP_DATA0	0x20
+#define IOP_DATA1	0x24
+#define IOP_DATA2	0x28
+#define IOP_DATA3	0x2c
+#define IOP_DATA4	0x30
+#define IOP_DATA5	0x34
+#define IOP_DATA6	0x38
+#define IOP_DATA7	0x3c
+#define IOP_DATA8	0x40
+#define IOP_DATA9	0x44
+#define IOP_DATA10	0x48
+#define IOP_DATA11	0x4c
+#define IOP_BASE_ADR_L	0x50
+#define IOP_BASE_ADR_H	0x54
+
+/* PMC register offset */
+#define IOP_PMC_TIMER		0x00
+#define IOP_PMC_CTRL		0x04
+#define IOP_XTAL27M_PASSWORD_I	0x08
+#define IOP_XTAL27M_PASSWORD_II	0x0c
+#define IOP_XTAL32K_PASSWORD_I	0x10
+#define IOP_XTAL32K_PASSWORD_II	0x14
+#define IOP_CLK27M_PASSWORD_I	0x18
+#define IOP_CLK27M_PASSWORD_II	0x1c
+#define IOP_PMC_TIMER2		0x20
+
+/* Max size of poweroff.bin that can be received */
+#define POWEROFF_CODE_MAX_SIZE 0x4000
+
+/* 8051 informs linux kerenl. 8051 has been switched to poweroff.bin code. */
+#define IOP_READY	0x0004
+#define RISC_READY	0x0008
+
+/* System linux kernel tells 8051 which  gpio pin to wake-up through. */
+#define WAKEUP_PIN	0xFE02
+
+/*
+ * There are 3 power domains in SP7021, AO domain, IOP domain,
+ * Default domain. Default domain is linux kernel system.
+ * System linux kernel tells 8051 to execute power off.
+ */
+#define DEFAULT_DOMAIN_POWEROFF	0x5331 /* AO&IOP domain on, Default domain off */
+#define DEFAULT_AND_IOP_DOMAIN_POWEROFF	0x5333 /* AO domain on, IOP&Default domain off */
+
+struct sp_iop {
+	struct device *dev;
+	struct clk *iopclk;
+	struct reset_control *rstc;
+	void __iomem *iop_regs;
+	void __iomem *pmc_regs;
+	void __iomem *moon0_regs;
+	int irq;
+	int gpio_wakeup;
+	resource_size_t iop_mem_start;
+	resource_size_t iop_mem_size;
+	unsigned char bin_code_mode;
+};
+
+static struct sp_iop *iop_poweroff;
+
+static void sp_iop_load_normal_code(struct sp_iop *iop)
+{
+	const struct firmware *fw;
+	void __iomem *iop_kernel_base;
+	unsigned int reg, err;
+

drivers/misc/sunplus_iop.c line 96

Quoted 10 lines
drivers/misc/sunplus_iop.c new file +10 -0
+	err = request_firmware(&fw, "normal.bin", iop->dev);
+	if (err)
+		dev_err(iop->dev, "get bin file error\n");
+
+	iop_kernel_base = ioremap(iop->iop_mem_start, fw->size);
+	memset(iop_kernel_base, 0, fw->size);
+	memcpy(iop_kernel_base, fw->data, fw->size);
+	release_firmware(fw);
+
+	clk_prepare_enable(iop->iopclk);

where do you disable the clock?

Quoted 5 lines
drivers/misc/sunplus_iop.c new file +5 -0
+
+	reg = readl(iop->iop_regs + IOP_CONTROL);
+	reg |= 0x01;
+	writel(reg, iop->iop_regs + IOP_CONTROL);
+

(...)

Quoted 15 lines
drivers/misc/sunplus_iop.c new file +15 -0
+static int sp_iop_get_resources(struct platform_device *pdev, struct sp_iop *p_sp_iop_info)
+{
+	struct resource *r;
+
+	r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "iop");
+	p_sp_iop_info->iop_regs = devm_ioremap_resource(&pdev->dev, r);
+	if (IS_ERR(p_sp_iop_info->iop_regs)) {
+		dev_err(&pdev->dev, "ioremap fail\n");
+		return PTR_ERR(p_sp_iop_info->iop_regs);
+	}
+
+	r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "iop_pmc");
+	p_sp_iop_info->pmc_regs = devm_ioremap_resource(&pdev->dev, r);
+	if (IS_ERR(p_sp_iop_info->pmc_regs)) {
+		dev_err(&pdev->dev, "ioremap fail\n");

drivers/misc/sunplus_iop.c line 327

Quoted 10 lines
drivers/misc/sunplus_iop.c new file +10 -0
+		return PTR_ERR(p_sp_iop_info->pmc_regs);
+	}
+
+	r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "moon0");
+	p_sp_iop_info->moon0_regs = devm_ioremap_resource(&pdev->dev, r);
+	if (IS_ERR(p_sp_iop_info->moon0_regs)) {
+		dev_err(&pdev->dev, "ioremap fail\n");
+		return PTR_ERR(p_sp_iop_info->moon0_regs);
+	}
+	return 0;

https://lore.kernel.org/all/[email protected]/
You received a comment about adding blank lines before return. This has to be done everywhere.

drivers/misc/sunplus_iop.c line 330

Quoted 3 lines
drivers/misc/sunplus_iop.c new file +3 -0
+}
+
+static int sp_iop_platform_driver_probe(struct platform_device *pdev)

Do not add "platform_driver" suffix to functions. "_probe" is enough.

Quoted 26 lines
drivers/misc/sunplus_iop.c new file +26 -0
+{
+	int ret = -ENXIO;
+	int rc;
+	struct sp_iop *iop;
+	struct device_node *memnp;
+	struct resource mem_res;
+
+	iop = devm_kzalloc(&pdev->dev, sizeof(struct sp_iop), GFP_KERNEL);
+	if (!iop) {
+		ret = -ENOMEM;
+		goto fail_kmalloc;
+	}
+
+	ret = sp_iop_get_resources(pdev, iop);
+
+	/* Get reserve address. */
+	memnp = of_parse_phandle(pdev->dev.of_node, "memory-region", 0);
+	if (!memnp) {
+		dev_err(&pdev->dev, "no memory-region node\n");
+		return -EINVAL;
+	}
+
+	rc = of_address_to_resource(memnp, 0, &mem_res);
+	of_node_put(memnp);
+	if (rc) {
+		dev_err(&pdev->dev, "failed to translate memory-region to a resource\n");

drivers/misc/sunplus_iop.c line 366

Quoted 10 lines
drivers/misc/sunplus_iop.c new file +10 -0
+		return -EINVAL;
+	}
+
+	iop->dev = &pdev->dev;
+	iop->iop_mem_start = mem_res.start;
+	iop->iop_mem_size = resource_size(&mem_res);
+	iop->iopclk = devm_clk_get(&pdev->dev, NULL);
+	if (IS_ERR(iop->iopclk))
+		return dev_err_probe(&pdev->dev, PTR_ERR(iop->iopclk),
+					    "devm_clk_get fail\n");

Clocks are not documented but required in bindings?

drivers/misc/sunplus_iop.c line 375

Quoted 9 lines
drivers/misc/sunplus_iop.c new file +9 -0
+
+	/*
+	 * 8051 has two bin files, normal.bin and poweroff.bin in rootfs.
+	 * Normally, 8051 executes normal.bin code. Normal.bin code size can exceed 16K.
+	 */
+	sp_iop_load_normal_code(iop);
+
+	platform_set_drvdata(pdev, iop);
+	iop->gpio_wakeup = of_get_named_gpio(pdev->dev.of_node, "iop-wakeup", 0);

It's not in the bindings. Do not add undocumented properties. Everything has to be in the bindings. I don't see usage of generic wakeup-gpios, so this all looks untested. You didn't run this code, did you?

Quoted 26 lines
drivers/misc/sunplus_iop.c new file +26 -0
+	iop_poweroff = iop;
+	pm_power_off = sp_iop_poweroff;
+
+	return 0;
+
+fail_kmalloc:
+	return ret;
+}
+
+static int sp_iop_remove(struct platform_device *pdev)
+{
+	pm_power_off = NULL;
+	return 0;
+}
+
+static const struct of_device_id sp_iop_of_match[] = {
+	{ .compatible = "sunplus,sp7021-iop" },
+	{ /* sentinel */ },
+};
+
+MODULE_DEVICE_TABLE(of, sp_iop_of_match);
+
+static struct platform_driver sp_iop_platform_driver = {
+	.probe		= sp_iop_platform_driver_probe,
+	.remove		= sp_iop_remove,
+	.driver = {

drivers/misc/sunplus_iop.c line 411

Quoted 10 lines
drivers/misc/sunplus_iop.c new file +10 -0
+		.name	= "sunplus,sp7021-iop",
+		.of_match_table = sp_iop_of_match,
+	}
+};
+
+module_platform_driver(sp_iop_platform_driver);
+
+MODULE_AUTHOR("Tony Huang <[email protected]>");
+MODULE_DESCRIPTION("Sunplus IOP Driver");
+MODULE_LICENSE("GPL v2");

Best regards,
Krzysztof

#9 lore raw

RE: [PATCH v11 2/2] misc: Add iop driver for Sunplus SP7021

Dear Krzysztof:

Quoted 20 lines · Tony Huang
Quoted 6 lines

This driver is load 8051 bin code.
The IOP core is DQ8051, so also named IOP8051.
Need Install DQ8051, The DQ8051 bin file generated by keil C. We will provide users with 8051 normal and power off source code.
Path: https://sunplus.atlassian.net/wiki/spaces/doc/pages/610172933/

How+to+use+I+O+processor+8051+of+SP7021#5.-Write-C-or-assembly-source-

Quoted 12 lines

files-for-IOP
Users can follow the operation steps to generate normal.bin and poweroff.bin.
Path: https://sunplus.atlassian.net/wiki/spaces/doc/pages/466190338
/26.+IOP8051 26.5?How To Create 8051 bin file

PMC in power management purpose:
Add sp_iop_poweroff() function. pm_power_off=sp_iop_poweroff. When the power off command is executed.
The 8051 has a register(DEF_PWR_EN_0=0) to control the power-on and power-off of the system.

Quoted 8 lines
Quoted 4 lines

---
Changes in v11:
- Addressed comments from Arnd Bergmann.

How did you address Arnd's comments about splitting the driver to proper parts? drivers/clk and drivers/power/reset?

drivers/clk : SP7021 system has clock device driver (clk-sp7021.c). So I set the IOP clock through the following function. clk_prepare_enable(iop->iopclk); clk_disable_unprepare(iop->iopclk);

drivers/power/reset : SP7021 system does not have a power off device driver.

Quoted 10 lines
Quoted 7 lines

- Addressed comments from krzysztof.

 MAINTAINERS                |   1 +
 drivers/misc/Kconfig       |  23 +++
 drivers/misc/Makefile      |   1 +
 drivers/misc/sunplus_iop.c | 411

+++++++++++++++++++++++++++++++++++++++++++++

The driver looks like SoC specific driver. Why did you put it in drivers/misc/, not in usual place - drivers/soc/?

8051 is designed for processing I/O events, like receiving IR signal from remote controller, taking care of power on or off requests from RTC, or other hardware events of external peripherals even when power of main system is off.
So I put it in drivers/misc.

Quoted 1 line

sp_iop_poweroff is still here.

sp_iop_poweroff(): SP7021 system does not have a power off device driver.
I have to put it here.

Quoted 162 lines
Quoted 22 lines
 4 files changed, 436 insertions(+)
 create mode 100644 drivers/misc/sunplus_iop.c
MAINTAINERS +1 -0
@@ -18246,6 +18246,7 @@ SUNPLUS IOP DRIVER
 M:	Tony Huang <[email protected]>
 S:	Maintained
 F:	Documentation/devicetree/bindings/misc/sunplus,iop.yaml
+F:	drivers/misc/sunplus_iop.c
 
 SUPERH
 M:	Yoshinori Sato <[email protected]>
drivers/misc/Kconfig index renamed from drivers/misc/Kconfig +0 -0

0f5a49f..e5f32d8 100644

drivers/misc/Kconfig +0 -0
@@ -470,6 +470,29 @@ config HISI_HIKEY_USB
 	  switching between the dual-role USB-C port and the USB-A host ports
 	  using only one USB controller.
 

drivers/misc/Kconfig config HISI_HIKEY_USB · line 482

Quoted 10 lines
drivers/misc/Kconfig +10 -0
+config SUNPLUS_IOP
+	tristate "Sunplus IOP support"
+	default ARCH_SUNPLUS
+	help
+	  This driver is load 8051 bin code.
+	  The IOP core is DQ8051, so also named IOP8051.
+	  Need Install DQ8051, The DQ8051 bin file generated by keil C.
+	  We will provide users with 8051 normal and power off source code.
+	  Path: https://sunplus.atlassian.net/wiki/spaces/doc/pages/610172933/
+

How+to+use+I+O+processor+8051+of+SP7021#5.-Write-C-or-assembly-source- files-for-IOP

drivers/misc/Kconfig config HISI_HIKEY_USB · line 483

Quoted 1 line
drivers/misc/Kconfig +1 -0
+	  Users can follow the operation steps to generate normal.bin and

poweroff.bin.

drivers/misc/Kconfig config HISI_HIKEY_USB · line 484

Quoted 1 line
drivers/misc/Kconfig +1 -0
+	  Path:

https://sunplus.atlassian.net/wiki/spaces/doc/pages/466190338/26.+IOP8051

drivers/misc/Kconfig config HISI_HIKEY_USB

Quoted 6 lines
drivers/misc/Kconfig +6 -0
+	  26.5?How To Create 8051 bin file
+
+	  PMC in power management purpose:
+	  Add sp_iop_poweroff() function. pm_power_off=sp_iop_poweroff.
+	  When the power off command is executed.
+	  The 8051 has a register(DEF_PWR_EN_0=0) to control the power-on

and

Quoted 65 lines
drivers/misc/Kconfig +5 -0
+	  power-off of the system.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called sunplus_iop.
+
 source "drivers/misc/c2port/Kconfig"
 source "drivers/misc/eeprom/Kconfig"
 source "drivers/misc/cb710/Kconfig"
drivers/misc/Makefile index renamed from drivers/misc/Makefile +0 -0

a086197..eafeab6 100644

drivers/misc/Makefile +1 -0
@@ -52,6 +52,7 @@ obj-$(CONFIG_DW_XDATA_PCIE)	+= dw-xdata-pcie.o
 obj-$(CONFIG_PCI_ENDPOINT_TEST)	+= pci_endpoint_test.o
 obj-$(CONFIG_OCXL)		+= ocxl/
 obj-$(CONFIG_BCM_VK)		+= bcm-vk/
+obj-$(CONFIG_SUNPLUS_IOP)	+= sunplus_iop.o
 obj-y				+= cardreader/
 obj-$(CONFIG_PVPANIC)   	+= pvpanic/
 obj-$(CONFIG_HABANA_AI)		+= habanalabs/
drivers/misc/sunplus_iop.c new file +40 -0
new file mode 100644 index 0000000..5bdce5e
@@ -0,0 +1,411 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * The IOP driver for Sunplus SP7021
+ *
+ * Copyright (C) 2021 Sunplus Technology Inc.
+ *
+ * All Rights Reserved.
+ */
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/dma-mapping.h>
+#include <linux/firmware.h>
+#include <linux/iopoll.h>
+#include <linux/module.h>
+#include <linux/of_platform.h>
+#include <linux/of_address.h>
+#include <linux/of_gpio.h>
+
+/* IOP register offset */
+#define IOP_CONTROL	0x00
+#define IOP_DATA0	0x20
+#define IOP_DATA1	0x24
+#define IOP_DATA2	0x28
+#define IOP_DATA3	0x2c
+#define IOP_DATA4	0x30
+#define IOP_DATA5	0x34
+#define IOP_DATA6	0x38
+#define IOP_DATA7	0x3c
+#define IOP_DATA8	0x40
+#define IOP_DATA9	0x44
+#define IOP_DATA10	0x48
+#define IOP_DATA11	0x4c
+#define IOP_BASE_ADR_L	0x50
+#define IOP_BASE_ADR_H	0x54
+
+/* PMC register offset */
+#define IOP_PMC_TIMER		0x00
+#define IOP_PMC_CTRL		0x04
+#define IOP_XTAL27M_PASSWORD_I	0x08
+#define IOP_XTAL27M_PASSWORD_II	0x0c

drivers/misc/sunplus_iop.c line 50

Quoted 10 lines
drivers/misc/sunplus_iop.c new file +10 -0
+#define IOP_XTAL32K_PASSWORD_I	0x10
+#define IOP_XTAL32K_PASSWORD_II	0x14
+#define IOP_CLK27M_PASSWORD_I	0x18
+#define IOP_CLK27M_PASSWORD_II	0x1c
+#define IOP_PMC_TIMER2		0x20
+
+/* Max size of poweroff.bin that can be received */ #define
+POWEROFF_CODE_MAX_SIZE 0x4000
+
+/* 8051 informs linux kerenl. 8051 has been switched to poweroff.bin code.

*/

drivers/misc/sunplus_iop.c

Quoted 12 lines
drivers/misc/sunplus_iop.c new file +12 -0
+#define IOP_READY	0x0004
+#define RISC_READY	0x0008
+
+/* System linux kernel tells 8051 which  gpio pin to wake-up through. */
+#define WAKEUP_PIN	0xFE02
+
+/*
+ * There are 3 power domains in SP7021, AO domain, IOP domain,
+ * Default domain. Default domain is linux kernel system.
+ * System linux kernel tells 8051 to execute power off.
+ */
+#define DEFAULT_DOMAIN_POWEROFF	0x5331 /* AO&IOP domain on,

Default domain off */

drivers/misc/sunplus_iop.c line 63

Quoted 1 line
drivers/misc/sunplus_iop.c new file +1 -0
+#define DEFAULT_AND_IOP_DOMAIN_POWEROFF	0x5333 /* AO domain

on, IOP&Default domain off */

Quoted 26 lines
drivers/misc/sunplus_iop.c new file +26 -0
+
+struct sp_iop {
+	struct device *dev;
+	struct clk *iopclk;
+	struct reset_control *rstc;
+	void __iomem *iop_regs;
+	void __iomem *pmc_regs;
+	void __iomem *moon0_regs;
+	int irq;
+	int gpio_wakeup;
+	resource_size_t iop_mem_start;
+	resource_size_t iop_mem_size;
+	unsigned char bin_code_mode;
+};
+
+static struct sp_iop *iop_poweroff;
+
+static void sp_iop_load_normal_code(struct sp_iop *iop) {
+	const struct firmware *fw;
+	void __iomem *iop_kernel_base;
+	unsigned int reg, err;
+
+	err = request_firmware(&fw, "normal.bin", iop->dev);
+	if (err)
+		dev_err(iop->dev, "get bin file error\n");
+
Quoted 8 lines

drivers/misc/sunplus_iop.c line 96

Quoted 6 lines
drivers/misc/sunplus_iop.c new file +6 -0
+	iop_kernel_base = ioremap(iop->iop_mem_start, fw->size);
+	memset(iop_kernel_base, 0, fw->size);
+	memcpy(iop_kernel_base, fw->data, fw->size);
+	release_firmware(fw);
+
+	clk_prepare_enable(iop->iopclk);

where do you disable the clock?

I will add disable clock in sp_iop_remove(). Below is my modification
static int sp_iop_remove(struct platform_device *pdev)

{				
	struct sp_iop *iop = iop_poweroff;			
	pm_power_off = NULL;			
	clk_disable_unprepare(iop->iopclk);			
				
	return 0;			
}				
Quoted 31 lines
Quoted 5 lines
drivers/misc/sunplus_iop.c new file +5 -0
+
+	reg = readl(iop->iop_regs + IOP_CONTROL);
+	reg |= 0x01;
+	writel(reg, iop->iop_regs + IOP_CONTROL);
+

(...)

drivers/misc/sunplus_iop.c

Quoted 12 lines
drivers/misc/sunplus_iop.c new file +12 -0
+static int sp_iop_get_resources(struct platform_device *pdev, struct
+sp_iop *p_sp_iop_info) {
+	struct resource *r;
+
+	r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "iop");
+	p_sp_iop_info->iop_regs = devm_ioremap_resource(&pdev->dev, r);
+	if (IS_ERR(p_sp_iop_info->iop_regs)) {
+		dev_err(&pdev->dev, "ioremap fail\n");
+		return PTR_ERR(p_sp_iop_info->iop_regs);
+	}
+
+	r = platform_get_resource_byname(pdev, IORESOURCE_MEM,

"iop_pmc");

Quoted 10 lines
drivers/misc/sunplus_iop.c new file +10 -0
+	p_sp_iop_info->pmc_regs = devm_ioremap_resource(&pdev->dev, r);
+	if (IS_ERR(p_sp_iop_info->pmc_regs)) {
+		dev_err(&pdev->dev, "ioremap fail\n");
+		return PTR_ERR(p_sp_iop_info->pmc_regs);
+	}
+
+	r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "moon0");
+	p_sp_iop_info->moon0_regs = devm_ioremap_resource(&pdev->dev, r);
+	if (IS_ERR(p_sp_iop_info->moon0_regs)) {
+		dev_err(&pdev->dev, "ioremap fail\n");
Quoted 8 lines

drivers/misc/sunplus_iop.c line 327

Quoted 3 lines
drivers/misc/sunplus_iop.c new file +3 -0
+		return PTR_ERR(p_sp_iop_info->moon0_regs);
+	}
+	return 0;

https://lore.kernel.org/all/16d98dfa-66f9-f9a4-08c9-d68d78c33b23@canonical
.com/
You received a comment about adding blank lines before return. This has to be done everywhere.

OK, I will modify it. Added blank line before return everywhere.

Quoted 6 lines

drivers/misc/sunplus_iop.c line 330

Quoted 3 lines
drivers/misc/sunplus_iop.c new file +3 -0
+}
+
+static int sp_iop_platform_driver_probe(struct platform_device *pdev)

Do not add "platform_driver" suffix to functions. "_probe" is enough.

Below is my modification:
static int sp_iop_probe(struct platform_device *pdev)

Quoted 27 lines
Quoted 16 lines
drivers/misc/sunplus_iop.c new file +16 -0
+{
+	int ret = -ENXIO;
+	int rc;
+	struct sp_iop *iop;
+	struct device_node *memnp;
+	struct resource mem_res;
+
+	iop = devm_kzalloc(&pdev->dev, sizeof(struct sp_iop), GFP_KERNEL);
+	if (!iop) {
+		ret = -ENOMEM;
+		goto fail_kmalloc;
+	}
+
+	ret = sp_iop_get_resources(pdev, iop);
+
+	/* Get reserve address. */

drivers/misc/sunplus_iop.c

Quoted 10 lines
drivers/misc/sunplus_iop.c new file +10 -0
+	memnp = of_parse_phandle(pdev->dev.of_node, "memory-region", 0);
+	if (!memnp) {
+		dev_err(&pdev->dev, "no memory-region node\n");
+		return -EINVAL;
+	}
+
+	rc = of_address_to_resource(memnp, 0, &mem_res);
+	of_node_put(memnp);
+	if (rc) {
+		dev_err(&pdev->dev, "failed to translate memory-region to a

resource\n");

Quoted 13 lines

drivers/misc/sunplus_iop.c line 366

Quoted 10 lines
drivers/misc/sunplus_iop.c new file +10 -0
+		return -EINVAL;
+	}
+
+	iop->dev = &pdev->dev;
+	iop->iop_mem_start = mem_res.start;
+	iop->iop_mem_size = resource_size(&mem_res);
+	iop->iopclk = devm_clk_get(&pdev->dev, NULL);
+	if (IS_ERR(iop->iopclk))
+		return dev_err_probe(&pdev->dev, PTR_ERR(iop->iopclk),
+					    "devm_clk_get fail\n");

Clocks are not documented but required in bindings?

I will added clocks in properties.

Quoted 5 lines

drivers/misc/sunplus_iop.c

Quoted 4 lines
drivers/misc/sunplus_iop.c new file +4 -0
+
+	/*
+	 * 8051 has two bin files, normal.bin and poweroff.bin in rootfs.
+	 * Normally, 8051 executes normal.bin code. Normal.bin code size can

exceed 16K.

Quoted 11 lines

drivers/misc/sunplus_iop.c

Quoted 6 lines
drivers/misc/sunplus_iop.c new file +6 -0
+	 */
+	sp_iop_load_normal_code(iop);
+
+	platform_set_drvdata(pdev, iop);
+	iop->gpio_wakeup = of_get_named_gpio(pdev->dev.of_node,
+"iop-wakeup", 0);

It's not in the bindings. Do not add undocumented properties. Everything has to be in the bindings. I don't see usage of generic wakeup-gpios, so this all looks untested. You didn't run this code, did you?

I wrote the wrong name.
Below is my modification:
iop->gpio_wakeup = of_get_named_gpio(pdev->dev.of_node, "wakeup-gpios", 0);

#10 lore raw

Re: [PATCH v11 2/2] misc: Add iop driver for Sunplus SP7021

Quoted 31 lines · Tony Huang 黃懷厚

Dear Krzysztof:

Quoted 20 lines · Tony Huang
Quoted 6 lines

This driver is load 8051 bin code.
The IOP core is DQ8051, so also named IOP8051.
Need Install DQ8051, The DQ8051 bin file generated by keil C. We will provide users with 8051 normal and power off source code.
Path: https://sunplus.atlassian.net/wiki/spaces/doc/pages/610172933/

How+to+use+I+O+processor+8051+of+SP7021#5.-Write-C-or-assembly-source-

Quoted 12 lines

files-for-IOP
Users can follow the operation steps to generate normal.bin and poweroff.bin.
Path: https://sunplus.atlassian.net/wiki/spaces/doc/pages/466190338
/26.+IOP8051 26.5?How To Create 8051 bin file

PMC in power management purpose:
Add sp_iop_poweroff() function. pm_power_off=sp_iop_poweroff. When the power off command is executed.
The 8051 has a register(DEF_PWR_EN_0=0) to control the power-on and power-off of the system.

Quoted 8 lines
Quoted 4 lines

---
Changes in v11:
- Addressed comments from Arnd Bergmann.

How did you address Arnd's comments about splitting the driver to proper parts? drivers/clk and drivers/power/reset?

Quoted 6 lines

drivers/clk : SP7021 system has clock device driver (clk-sp7021.c). So I set the IOP clock through the following function. clk_prepare_enable(iop->iopclk); clk_disable_unprepare(iop->iopclk);

drivers/power/reset : SP7021 system does not have a power off device driver.

What does it mean? The feedback was to split clk and reset features to separate drivers and I still see only two patches here with a misc driver. So how is his comments addressed? You did not reply in that thread.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

- Addressed comments from krzysztof.

 MAINTAINERS                |   1 +
 drivers/misc/Kconfig       |  23 +++
 drivers/misc/Makefile      |   1 +
 drivers/misc/sunplus_iop.c | 411

+++++++++++++++++++++++++++++++++++++++++++++

Quoted 7 lines
Quoted 2 lines

The driver looks like SoC specific driver. Why did you put it in drivers/misc/, not in usual place - drivers/soc/?

8051 is designed for processing I/O events, like receiving IR signal from remote controller, taking care of power on or off requests from RTC, or other hardware events of external peripherals even when power of main system is off.
So I put it in drivers/misc.

Is IOP8061 a separate device? Your datasheet is saying its embedded in SP7021 SoC, so it is a soc driver. This does not fit misc driver description (a "strange device") but a SoC driver description.

Quoted 5 lines
Quoted 2 lines

sp_iop_poweroff is still here.

sp_iop_poweroff(): SP7021 system does not have a power off device driver.
I have to put it here.

This should be rather in a reset driver, not in a misc one. What is your plan for this driver? You described the hardware and judging by it, there will be quite a lot of separate features so it's reasonable to split the driver into separate logical elements. However keeping all in the same place would be ok, if you do not plan to add any more features. This would mean the driver will handle *only* reset and FW loading.

Quoted 175 lines
Quoted 163 lines
Quoted 23 lines
 4 files changed, 436 insertions(+)
 create mode 100644 drivers/misc/sunplus_iop.c
MAINTAINERS +1 -0
@@ -18246,6 +18246,7 @@ SUNPLUS IOP DRIVER
 M:	Tony Huang <[email protected]>
 S:	Maintained
 F:	Documentation/devicetree/bindings/misc/sunplus,iop.yaml
+F:	drivers/misc/sunplus_iop.c
 
 SUPERH
 M:	Yoshinori Sato <[email protected]>
drivers/misc/Kconfig index renamed from drivers/misc/Kconfig +0 -0

0f5a49f..e5f32d8 100644

drivers/misc/Kconfig +0 -0
@@ -470,6 +470,29 @@ config HISI_HIKEY_USB
 	  switching between the dual-role USB-C port and the USB-A host ports
 	  using only one USB controller.
 

drivers/misc/Kconfig config HISI_HIKEY_USB · line 482

Quoted 10 lines
drivers/misc/Kconfig +10 -0
+config SUNPLUS_IOP
+	tristate "Sunplus IOP support"
+	default ARCH_SUNPLUS
+	help
+	  This driver is load 8051 bin code.
+	  The IOP core is DQ8051, so also named IOP8051.
+	  Need Install DQ8051, The DQ8051 bin file generated by keil C.
+	  We will provide users with 8051 normal and power off source code.
+	  Path: https://sunplus.atlassian.net/wiki/spaces/doc/pages/610172933/
+

How+to+use+I+O+processor+8051+of+SP7021#5.-Write-C-or-assembly-source- files-for-IOP

drivers/misc/Kconfig config HISI_HIKEY_USB · line 483

Quoted 1 line
drivers/misc/Kconfig +1 -0
+	  Users can follow the operation steps to generate normal.bin and

poweroff.bin.

drivers/misc/Kconfig config HISI_HIKEY_USB · line 484

Quoted 1 line
drivers/misc/Kconfig +1 -0
+	  Path:

https://sunplus.atlassian.net/wiki/spaces/doc/pages/466190338/26.+IOP8051

drivers/misc/Kconfig config HISI_HIKEY_USB

Quoted 6 lines
drivers/misc/Kconfig +6 -0
+	  26.5?How To Create 8051 bin file
+
+	  PMC in power management purpose:
+	  Add sp_iop_poweroff() function. pm_power_off=sp_iop_poweroff.
+	  When the power off command is executed.
+	  The 8051 has a register(DEF_PWR_EN_0=0) to control the power-on

and

Quoted 65 lines
drivers/misc/Kconfig +5 -0
+	  power-off of the system.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called sunplus_iop.
+
 source "drivers/misc/c2port/Kconfig"
 source "drivers/misc/eeprom/Kconfig"
 source "drivers/misc/cb710/Kconfig"
drivers/misc/Makefile index renamed from drivers/misc/Makefile +0 -0

a086197..eafeab6 100644

drivers/misc/Makefile +1 -0
@@ -52,6 +52,7 @@ obj-$(CONFIG_DW_XDATA_PCIE)	+= dw-xdata-pcie.o
 obj-$(CONFIG_PCI_ENDPOINT_TEST)	+= pci_endpoint_test.o
 obj-$(CONFIG_OCXL)		+= ocxl/
 obj-$(CONFIG_BCM_VK)		+= bcm-vk/
+obj-$(CONFIG_SUNPLUS_IOP)	+= sunplus_iop.o
 obj-y				+= cardreader/
 obj-$(CONFIG_PVPANIC)   	+= pvpanic/
 obj-$(CONFIG_HABANA_AI)		+= habanalabs/
drivers/misc/sunplus_iop.c new file +40 -0
new file mode 100644 index 0000000..5bdce5e
@@ -0,0 +1,411 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * The IOP driver for Sunplus SP7021
+ *
+ * Copyright (C) 2021 Sunplus Technology Inc.
+ *
+ * All Rights Reserved.
+ */
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/dma-mapping.h>
+#include <linux/firmware.h>
+#include <linux/iopoll.h>
+#include <linux/module.h>
+#include <linux/of_platform.h>
+#include <linux/of_address.h>
+#include <linux/of_gpio.h>
+
+/* IOP register offset */
+#define IOP_CONTROL	0x00
+#define IOP_DATA0	0x20
+#define IOP_DATA1	0x24
+#define IOP_DATA2	0x28
+#define IOP_DATA3	0x2c
+#define IOP_DATA4	0x30
+#define IOP_DATA5	0x34
+#define IOP_DATA6	0x38
+#define IOP_DATA7	0x3c
+#define IOP_DATA8	0x40
+#define IOP_DATA9	0x44
+#define IOP_DATA10	0x48
+#define IOP_DATA11	0x4c
+#define IOP_BASE_ADR_L	0x50
+#define IOP_BASE_ADR_H	0x54
+
+/* PMC register offset */
+#define IOP_PMC_TIMER		0x00
+#define IOP_PMC_CTRL		0x04
+#define IOP_XTAL27M_PASSWORD_I	0x08
+#define IOP_XTAL27M_PASSWORD_II	0x0c

drivers/misc/sunplus_iop.c line 50

Quoted 10 lines
drivers/misc/sunplus_iop.c new file +10 -0
+#define IOP_XTAL32K_PASSWORD_I	0x10
+#define IOP_XTAL32K_PASSWORD_II	0x14
+#define IOP_CLK27M_PASSWORD_I	0x18
+#define IOP_CLK27M_PASSWORD_II	0x1c
+#define IOP_PMC_TIMER2		0x20
+
+/* Max size of poweroff.bin that can be received */ #define
+POWEROFF_CODE_MAX_SIZE 0x4000
+
+/* 8051 informs linux kerenl. 8051 has been switched to poweroff.bin code.

*/

drivers/misc/sunplus_iop.c

Quoted 12 lines
drivers/misc/sunplus_iop.c new file +12 -0
+#define IOP_READY	0x0004
+#define RISC_READY	0x0008
+
+/* System linux kernel tells 8051 which  gpio pin to wake-up through. */
+#define WAKEUP_PIN	0xFE02
+
+/*
+ * There are 3 power domains in SP7021, AO domain, IOP domain,
+ * Default domain. Default domain is linux kernel system.
+ * System linux kernel tells 8051 to execute power off.
+ */
+#define DEFAULT_DOMAIN_POWEROFF	0x5331 /* AO&IOP domain on,

Default domain off */

drivers/misc/sunplus_iop.c line 63

Quoted 1 line
drivers/misc/sunplus_iop.c new file +1 -0
+#define DEFAULT_AND_IOP_DOMAIN_POWEROFF	0x5333 /* AO domain

on, IOP&Default domain off */

Quoted 26 lines
drivers/misc/sunplus_iop.c new file +26 -0
+
+struct sp_iop {
+	struct device *dev;
+	struct clk *iopclk;
+	struct reset_control *rstc;
+	void __iomem *iop_regs;
+	void __iomem *pmc_regs;
+	void __iomem *moon0_regs;
+	int irq;
+	int gpio_wakeup;
+	resource_size_t iop_mem_start;
+	resource_size_t iop_mem_size;
+	unsigned char bin_code_mode;
+};
+
+static struct sp_iop *iop_poweroff;
+
+static void sp_iop_load_normal_code(struct sp_iop *iop) {
+	const struct firmware *fw;
+	void __iomem *iop_kernel_base;
+	unsigned int reg, err;
+
+	err = request_firmware(&fw, "normal.bin", iop->dev);
+	if (err)
+		dev_err(iop->dev, "get bin file error\n");
+
Quoted 8 lines

drivers/misc/sunplus_iop.c line 96

Quoted 6 lines
drivers/misc/sunplus_iop.c new file +6 -0
+	iop_kernel_base = ioremap(iop->iop_mem_start, fw->size);
+	memset(iop_kernel_base, 0, fw->size);
+	memcpy(iop_kernel_base, fw->data, fw->size);
+	release_firmware(fw);
+
+	clk_prepare_enable(iop->iopclk);

where do you disable the clock?

I will add disable clock in sp_iop_remove(). Below is my modification
static int sp_iop_remove(struct platform_device *pdev)

Quoted 7 lines
{				
	struct sp_iop *iop = iop_poweroff;			
	pm_power_off = NULL;			
	clk_disable_unprepare(iop->iopclk);			
				
	return 0;			
}				

How is it balanced then? remove() is symmetric to probe() but you did not enable clocks in the probe(). Instead you enable the clocks each time in load_normal_code() and load_poweroff_code().

This does not seem right at all.

Best regards,
Krzysztof

#11 lore raw

RE: [PATCH v11 2/2] misc: Add iop driver for Sunplus SP7021

Dear Krzysztof:

Quoted 36 lines
Quoted 8 lines
Quoted 8 lines · Tony Huang
Quoted 6 lines

This driver is load 8051 bin code.
The IOP core is DQ8051, so also named IOP8051.
Need Install DQ8051, The DQ8051 bin file generated by keil C. We will provide users with 8051 normal and power off source code.
Path: https://sunplus.atlassian.net/wiki/spaces/doc/pages/610172933/

How+to+use+I+O+processor+8051+of+SP7021#5.-Write-C-or-assembly-source

Quoted 27 lines
Quoted 13 lines

How+to+use+I+O+processor+8051+of+-

Quoted 12 lines

files-for-IOP
Users can follow the operation steps to generate normal.bin and poweroff.bin.
Path: https://sunplus.atlassian.net/wiki/spaces/doc/pages/466190338
/26.+IOP8051 26.5?How To Create 8051 bin file

PMC in power management purpose:
Add sp_iop_poweroff() function. pm_power_off=sp_iop_poweroff. When the power off command is executed.
The 8051 has a register(DEF_PWR_EN_0=0) to control the power-on and power-off of the system.

Quoted 8 lines
Quoted 4 lines

---
Changes in v11:
- Addressed comments from Arnd Bergmann.

How did you address Arnd's comments about splitting the driver to proper parts? drivers/clk and drivers/power/reset?

drivers/clk : SP7021 system has clock device driver (clk-sp7021.c). So I set the IOP clock through the following function. clk_prepare_enable(iop->iopclk); clk_disable_unprepare(iop->iopclk);

Quoted 6 lines
Quoted 1 line

drivers/power/reset : SP7021 system does not have a power off device driver.

What does it mean? The feedback was to split clk and reset features to separate drivers and I still see only two patches here with a misc driver. So how is his comments addressed? You did not reply in that thread.

I finished replying to Arnd.

Quoted 14 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

- Addressed comments from krzysztof.

 MAINTAINERS                |   1 +
 drivers/misc/Kconfig       |  23 +++
 drivers/misc/Makefile      |   1 +
 drivers/misc/sunplus_iop.c | 411

+++++++++++++++++++++++++++++++++++++++++++++

Quoted 4 lines
Quoted 2 lines

The driver looks like SoC specific driver. Why did you put it in drivers/misc/, not in usual place - drivers/soc/?

8051 is designed for processing I/O events, like receiving IR signal from

remote controller,

Quoted 9 lines
Quoted 1 line

taking care of power on or off requests from RTC, or other hardware events

of external peripherals

Quoted 2 lines

even when power of main system is off.
So I put it in drivers/misc.

Is IOP8061 a separate device? Your datasheet is saying its embedded in SP7021 SoC, so it is a soc driver. This does not fit misc driver description (a "strange device") but a SoC driver description.

IOP is a separate device. CPU is 8051. SP7021 contains three kinds of CPU. Quad-core ARM Cortex-A7 (CA7) ARM926 real-time core
8051 low-power core

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

sp_iop_poweroff is still here.

sp_iop_poweroff(): SP7021 system does not have a power off device driver.
I have to put it here.

Quoted 7 lines

This should be rather in a reset driver, not in a misc one. What is your plan for this driver? You described the hardware and judging by it, there will be quite a lot of separate features so it's reasonable to split the driver into separate logical elements. However keeping all in the same place would be ok, if you do not plan to add any more features.
This would mean the driver will handle *only* reset and FW loading.

Can I put sp_iop_poweroff() here for now?
When power off device driver is added in /driver/power/reset is complete, we will move to it.

Quoted 190 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
 4 files changed, 436 insertions(+)
 create mode 100644 drivers/misc/sunplus_iop.c
MAINTAINERS +1 -0
@@ -18246,6 +18246,7 @@ SUNPLUS IOP DRIVER
 M:	Tony Huang <[email protected]>
 S:	Maintained
 F:	Documentation/devicetree/bindings/misc/sunplus,iop.yaml
+F:	drivers/misc/sunplus_iop.c
 
Quoted 8 lines
Quoted 8 lines

drivers/misc/Kconfig config HISI_HIKEY_USB · line 470

Quoted 8 lines
MAINTAINERS +0 -0
 SUPERH
 M:	Yoshinori Sato <[email protected]>
drivers/misc/Kconfig index renamed from drivers/misc/Kconfig +0 -0

0f5a49f..e5f32d8 100644

drivers/misc/Kconfig +0 -0
@@ -470,6 +470,29 @@ config HISI_HIKEY_USB
 	  switching between the dual-role USB-C port and the USB-A host

ports

Quoted 10 lines
Quoted 10 lines

drivers/misc/Kconfig config HISI_HIKEY_USB

Quoted 10 lines
drivers/misc/Kconfig +8 -0
 	  using only one USB controller.
 
+config SUNPLUS_IOP
+	tristate "Sunplus IOP support"
+	default ARCH_SUNPLUS
+	help
+	  This driver is load 8051 bin code.
+	  The IOP core is DQ8051, so also named IOP8051.
+	  Need Install DQ8051, The DQ8051 bin file generated by keil C.
+	  We will provide users with 8051 normal and power off source

code.

Quoted 4 lines
Quoted 4 lines

drivers/misc/Kconfig config HISI_HIKEY_USB · line 483

Quoted 3 lines
drivers/misc/Kconfig +3 -0
+	  Path:
+https://sunplus.atlassian.net/wiki/spaces/doc/pages/610172933/
+

How+to+use+I+O+processor+8051+of+SP7021#5.-Write-C-or-assembly-source

Quoted 7 lines
Quoted 7 lines

How+to+use+I+O+processor+8051+of+-
files-for-IOP

drivers/misc/Kconfig config HISI_HIKEY_USB · line 484

Quoted 1 line
drivers/misc/Kconfig +1 -0
+	  Users can follow the operation steps to generate normal.bin and

poweroff.bin.

drivers/misc/Kconfig config HISI_HIKEY_USB · line 485

Quoted 1 line
drivers/misc/Kconfig +1 -0
+	  Path:

https://sunplus.atlassian.net/wiki/spaces/doc/pages/466190338/26.+IOP
8051

Quoted 6 lines
Quoted 6 lines

drivers/misc/Kconfig config HISI_HIKEY_USB

Quoted 6 lines
drivers/misc/Kconfig +6 -0
+	  26.5?How To Create 8051 bin file
+
+	  PMC in power management purpose:
+	  Add sp_iop_poweroff() function. pm_power_off=sp_iop_poweroff.
+	  When the power off command is executed.
+	  The 8051 has a register(DEF_PWR_EN_0=0) to control the

power-on

Quoted 68 lines
Quoted 68 lines

and

Quoted 67 lines
drivers/misc/Kconfig +5 -0
+	  power-off of the system.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called sunplus_iop.
+
 source "drivers/misc/c2port/Kconfig"
 source "drivers/misc/eeprom/Kconfig"
 source "drivers/misc/cb710/Kconfig"
drivers/misc/Makefile index renamed from drivers/misc/Makefile +0 -0

a086197..eafeab6 100644

drivers/misc/Makefile +1 -0
@@ -52,6 +52,7 @@ obj-$(CONFIG_DW_XDATA_PCIE)	+= dw-xdata-pcie.o
 obj-$(CONFIG_PCI_ENDPOINT_TEST)	+= pci_endpoint_test.o
 obj-$(CONFIG_OCXL)		+= ocxl/
 obj-$(CONFIG_BCM_VK)		+= bcm-vk/
+obj-$(CONFIG_SUNPLUS_IOP)	+= sunplus_iop.o
 obj-y				+= cardreader/
 obj-$(CONFIG_PVPANIC)   	+= pvpanic/
 obj-$(CONFIG_HABANA_AI)		+= habanalabs/
drivers/misc/sunplus_iop.c new file +42 -0
new file mode 100644 index 0000000..5bdce5e
@@ -0,0 +1,411 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * The IOP driver for Sunplus SP7021
+ *
+ * Copyright (C) 2021 Sunplus Technology Inc.
+ *
+ * All Rights Reserved.
+ */
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/dma-mapping.h>
+#include <linux/firmware.h>
+#include <linux/iopoll.h>
+#include <linux/module.h>
+#include <linux/of_platform.h>
+#include <linux/of_address.h>
+#include <linux/of_gpio.h>
+
+/* IOP register offset */
+#define IOP_CONTROL	0x00
+#define IOP_DATA0	0x20
+#define IOP_DATA1	0x24
+#define IOP_DATA2	0x28
+#define IOP_DATA3	0x2c
+#define IOP_DATA4	0x30
+#define IOP_DATA5	0x34
+#define IOP_DATA6	0x38
+#define IOP_DATA7	0x3c
+#define IOP_DATA8	0x40
+#define IOP_DATA9	0x44
+#define IOP_DATA10	0x48
+#define IOP_DATA11	0x4c
+#define IOP_BASE_ADR_L	0x50
+#define IOP_BASE_ADR_H	0x54
+
+/* PMC register offset */
+#define IOP_PMC_TIMER		0x00
+#define IOP_PMC_CTRL		0x04
+#define IOP_XTAL27M_PASSWORD_I	0x08
+#define IOP_XTAL27M_PASSWORD_II	0x0c
+#define IOP_XTAL32K_PASSWORD_I	0x10
+#define IOP_XTAL32K_PASSWORD_II	0x14
Quoted 8 lines
Quoted 8 lines

drivers/misc/sunplus_iop.c

Quoted 8 lines
drivers/misc/sunplus_iop.c new file +8 -0
+#define IOP_CLK27M_PASSWORD_I	0x18
+#define IOP_CLK27M_PASSWORD_II	0x1c
+#define IOP_PMC_TIMER2		0x20
+
+/* Max size of poweroff.bin that can be received */ #define
+POWEROFF_CODE_MAX_SIZE 0x4000
+
+/* 8051 informs linux kerenl. 8051 has been switched to poweroff.bin

code.

Quoted 13 lines
Quoted 13 lines

*/

drivers/misc/sunplus_iop.c

Quoted 12 lines
drivers/misc/sunplus_iop.c new file +12 -0
+#define IOP_READY	0x0004
+#define RISC_READY	0x0008
+
+/* System linux kernel tells 8051 which  gpio pin to wake-up through. */
+#define WAKEUP_PIN	0xFE02
+
+/*
+ * There are 3 power domains in SP7021, AO domain, IOP domain,
+ * Default domain. Default domain is linux kernel system.
+ * System linux kernel tells 8051 to execute power off.
+ */
+#define DEFAULT_DOMAIN_POWEROFF	0x5331 /* AO&IOP domain

on,

Quoted 2 lines
Quoted 2 lines

Default domain off */

Quoted 1 line
drivers/misc/sunplus_iop.c new file +1 -0
+#define DEFAULT_AND_IOP_DOMAIN_POWEROFF	0x5333 /* AO

domain

Quoted 44 lines
Quoted 27 lines

on, IOP&Default domain off */

Quoted 26 lines
drivers/misc/sunplus_iop.c new file +26 -0
+
+struct sp_iop {
+	struct device *dev;
+	struct clk *iopclk;
+	struct reset_control *rstc;
+	void __iomem *iop_regs;
+	void __iomem *pmc_regs;
+	void __iomem *moon0_regs;
+	int irq;
+	int gpio_wakeup;
+	resource_size_t iop_mem_start;
+	resource_size_t iop_mem_size;
+	unsigned char bin_code_mode;
+};
+
+static struct sp_iop *iop_poweroff;
+
+static void sp_iop_load_normal_code(struct sp_iop *iop) {
+	const struct firmware *fw;
+	void __iomem *iop_kernel_base;
+	unsigned int reg, err;
+
+	err = request_firmware(&fw, "normal.bin", iop->dev);
+	if (err)
+		dev_err(iop->dev, "get bin file error\n");
+
Quoted 8 lines

drivers/misc/sunplus_iop.c line 96

Quoted 6 lines
drivers/misc/sunplus_iop.c new file +6 -0
+	iop_kernel_base = ioremap(iop->iop_mem_start, fw->size);
+	memset(iop_kernel_base, 0, fw->size);
+	memcpy(iop_kernel_base, fw->data, fw->size);
+	release_firmware(fw);
+
+	clk_prepare_enable(iop->iopclk);

where do you disable the clock?

I will add disable clock in sp_iop_remove(). Below is my modification
static int sp_iop_remove(struct platform_device *pdev)

{
	struct sp_iop *iop = iop_poweroff;
	pm_power_off = NULL;
	clk_disable_unprepare(iop->iopclk);
Quoted 8 lines
Quoted 2 lines
	return 0;
}

How is it balanced then? remove() is symmetric to probe() but you did not enable clocks in the probe(). Instead you enable the clocks each time in load_normal_code() and load_poweroff_code().

This does not seem right at all.

OK, I will modify it.

#12 lore raw

Re: [PATCH v11 2/2] misc: Add iop driver for Sunplus SP7021

Quoted 92 lines · Tony Huang 黃懷厚

Dear Krzysztof:

Quoted 36 lines
Quoted 8 lines
Quoted 8 lines · Tony Huang
Quoted 6 lines

This driver is load 8051 bin code.
The IOP core is DQ8051, so also named IOP8051.
Need Install DQ8051, The DQ8051 bin file generated by keil C. We will provide users with 8051 normal and power off source code.
Path: https://sunplus.atlassian.net/wiki/spaces/doc/pages/610172933/

How+to+use+I+O+processor+8051+of+SP7021#5.-Write-C-or-assembly-source

Quoted 27 lines
Quoted 13 lines

How+to+use+I+O+processor+8051+of+-

Quoted 12 lines

files-for-IOP
Users can follow the operation steps to generate normal.bin and poweroff.bin.
Path: https://sunplus.atlassian.net/wiki/spaces/doc/pages/466190338
/26.+IOP8051 26.5?How To Create 8051 bin file

PMC in power management purpose:
Add sp_iop_poweroff() function. pm_power_off=sp_iop_poweroff. When the power off command is executed.
The 8051 has a register(DEF_PWR_EN_0=0) to control the power-on and power-off of the system.

Quoted 8 lines
Quoted 4 lines

---
Changes in v11:
- Addressed comments from Arnd Bergmann.

How did you address Arnd's comments about splitting the driver to proper parts? drivers/clk and drivers/power/reset?

drivers/clk : SP7021 system has clock device driver (clk-sp7021.c). So I set the IOP clock through the following function. clk_prepare_enable(iop->iopclk); clk_disable_unprepare(iop->iopclk);

Quoted 6 lines
Quoted 1 line

drivers/power/reset : SP7021 system does not have a power off device driver.

What does it mean? The feedback was to split clk and reset features to separate drivers and I still see only two patches here with a misc driver. So how is his comments addressed? You did not reply in that thread.

I finished replying to Arnd.

Quoted 14 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

- Addressed comments from krzysztof.

 MAINTAINERS                |   1 +
 drivers/misc/Kconfig       |  23 +++
 drivers/misc/Makefile      |   1 +
 drivers/misc/sunplus_iop.c | 411

+++++++++++++++++++++++++++++++++++++++++++++

Quoted 4 lines
Quoted 2 lines

The driver looks like SoC specific driver. Why did you put it in drivers/misc/, not in usual place - drivers/soc/?

8051 is designed for processing I/O events, like receiving IR signal from

remote controller,

Quoted 9 lines
Quoted 1 line

taking care of power on or off requests from RTC, or other hardware events

of external peripherals

Quoted 2 lines

even when power of main system is off.
So I put it in drivers/misc.

Is IOP8061 a separate device? Your datasheet is saying its embedded in SP7021 SoC, so it is a soc driver. This does not fit misc driver description (a "strange device") but a SoC driver description.

IOP is a separate device. CPU is 8051. SP7021 contains three kinds of CPU. Quad-core ARM Cortex-A7 (CA7) ARM926 real-time core
8051 low-power core

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

sp_iop_poweroff is still here.

sp_iop_poweroff(): SP7021 system does not have a power off device driver.
I have to put it here.

Quoted 7 lines

This should be rather in a reset driver, not in a misc one. What is your plan for this driver? You described the hardware and judging by it, there will be quite a lot of separate features so it's reasonable to split the driver into separate logical elements. However keeping all in the same place would be ok, if you do not plan to add any more features.
This would mean the driver will handle *only* reset and FW loading.

Quoted 2 lines

Can I put sp_iop_poweroff() here for now?
When power off device driver is added in /driver/power/reset is complete, we will move to it.

Not really, because misc drivers is not a place for power off drivers. The driver here looks now like responsible only for system power management of a SoC, so most likely drivers/soc. However it has even less sense to add some feature here and immediately move it somewhere more appropriate (instead just add it to the appropriate place).

Your moving of parts of it to drivers/power/reset is now confusing. What will be left here? Please send entire set not just pieces.

Best regards,
Krzysztof

#13 lore raw

RE: [PATCH v11 2/2] misc: Add iop driver for Sunplus SP7021

Dear Krzysztof:

Quoted 101 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 9 lines · Tony Huang
Quoted 7 lines

This driver is load 8051 bin code.
The IOP core is DQ8051, so also named IOP8051.
Need Install DQ8051, The DQ8051 bin file generated by keil C. We will provide users with 8051 normal and power off source code. Path:
https://sunplus.atlassian.net/wiki/spaces/doc/pages/610172933/

How+to+use+I+O+processor+8051+of+SP7021#5.-Write-C-or-assembly-source

Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 22 lines

How+to+use+I+O+processor+8051+of+-

Quoted 13 lines

files-for-IOP
Users can follow the operation steps to generate normal.bin and poweroff.bin.
Path:
https://sunplus.atlassian.net/wiki/spaces/doc/pages/466190338
/26.+IOP8051 26.5?How To Create 8051 bin file

PMC in power management purpose:
Add sp_iop_poweroff() function. pm_power_off=sp_iop_poweroff. When the power off command is executed.
The 8051 has a register(DEF_PWR_EN_0=0) to control the power-on and power-off of the system.

Quoted 4 lines

---
Changes in v11:
- Addressed comments from Arnd Bergmann.

How did you address Arnd's comments about splitting the driver to proper parts? drivers/clk and drivers/power/reset?

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/clk : SP7021 system has clock device driver (clk-sp7021.c). So I set the IOP clock through the following function. clk_prepare_enable(iop->iopclk); clk_disable_unprepare(iop->iopclk);

drivers/power/reset : SP7021 system does not have a power off device

driver.

Quoted 35 lines
Quoted 5 lines

What does it mean? The feedback was to split clk and reset features to separate drivers and I still see only two patches here with a misc driver. So how is his comments addressed? You did not reply in that thread.

I finished replying to Arnd.

Quoted 17 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

- Addressed comments from krzysztof.

 MAINTAINERS                |   1 +
 drivers/misc/Kconfig       |  23 +++
 drivers/misc/Makefile      |   1 +
 drivers/misc/sunplus_iop.c | 411

+++++++++++++++++++++++++++++++++++++++++++++

Quoted 5 lines
Quoted 2 lines

The driver looks like SoC specific driver. Why did you put it in drivers/misc/, not in usual place - drivers/soc/?

8051 is designed for processing I/O events, like receiving IR signal from

remote controller,

Quoted 2 lines

taking care of power on or off requests from RTC, or other hardware events

Quoted 9 lines

of external peripherals

Quoted 2 lines

even when power of main system is off.
So I put it in drivers/misc.

Is IOP8061 a separate device? Your datasheet is saying its embedded in
SP7021 SoC, so it is a soc driver. This does not fit misc driver description (a "strange device") but a SoC driver description.

Quoted 17 lines

IOP is a separate device. CPU is 8051. SP7021 contains three kinds of CPU. Quad-core ARM Cortex-A7 (CA7) ARM926 real-time core
8051 low-power core

Quoted 11 lines
Quoted 5 lines
Quoted 2 lines

sp_iop_poweroff is still here.

sp_iop_poweroff(): SP7021 system does not have a power off device driver.
I have to put it here.

This should be rather in a reset driver, not in a misc one. What is your plan for this driver? You described the hardware and judging by it, there will be quite a lot of separate features so it's reasonable to split the driver into separate logical elements. However keeping all in the same place would be ok, if you do not plan to add any more

features.

Quoted 5 lines
Quoted 2 lines

This would mean the driver will handle *only* reset and FW loading.

Can I put sp_iop_poweroff() here for now?
When power off device driver is added in /driver/power/reset is complete,

we will move to it.

Quoted 9 lines

Not really, because misc drivers is not a place for power off drivers. The driver here looks now like responsible only for system power management of a SoC, so most likely drivers/soc. However it has even less sense to add some feature here and immediately move it somewhere more appropriate (instead just add it to the appropriate place).

Your moving of parts of it to drivers/power/reset is now confusing. What will be left here? Please send entire set not just pieces.

I may not fully understand your requirements.
You: What is your plan for this driver?
< ----- reset driver? Misc driver?
You: However keeping all in the same place would be ok, if you do not plan to add any more features. This would mean the driver will handle *only* reset and FW loading.
< ------ Because system does not have a power off device driver.
sp_iop_poweroff() can be placed in iop driver?

maintainer
#14 lore raw

Re: [PATCH v11 2/2] misc: Add iop driver for Sunplus SP7021

Quoted 1 line · Tony Huang 黃懷厚
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Tony Huang

(note: please use normal quoting style, only quote the parts of the message
that you actually reply to, reave the attributoons in place, etc)

Quoted 14 lines
Quoted 4 lines
Quoted 2 lines

Can I put sp_iop_poweroff() here for now?
When power off device driver is added in /driver/power/reset is complete,

we will move to it.

Quoted 9 lines

Not really, because misc drivers is not a place for power off drivers. The driver here looks now like responsible only for system power management of a SoC, so most likely drivers/soc. However it has even less sense to add some feature here and immediately move it somewhere more appropriate (instead just add it to the appropriate place).

Your moving of parts of it to drivers/power/reset is now confusing. What will be left here? Please send entire set not just pieces.

Quoted 7 lines

I may not fully understand your requirements.
You: What is your plan for this driver?
< ----- reset driver? Misc driver?
You: However keeping all in the same place would be ok, if you do not plan to add any more features. This would mean the driver will handle *only* reset and FW loading.
< ------ Because system does not have a power off device driver.
sp_iop_poweroff() can be placed in iop driver?

It really depends on where you want this driver to head. If you don't have any plans to add features beyond poweroff, having the whole thing in drivers/power/reset/ is the easiest way. If you do have plans to add other features, then explain exactly what those features are, which subsystems they go into, and why you haven't already implemented them in the previous 11 versions.

The common bits of the driver can go into drivers/soc or drivers/mfd, partly depending on what abstraction you use between this driver and its clients, so it's important to figure out the correct abstraction layer first, and then decide where it should go.

One common way to do it is to use the multi-function-device abstraction to automatically create child devices from the hardware device node. Another option is to have high-level functions exported from a soc driver. Or you could just have a 'regmap' exposed from a 'syscon' driver to provide individual registers to devices. Which one of those is best for your system mostly depends on how you end up using it, and we have no idea until you have more than one leaf driver on it. The poweroff driver is not a great example either, because it does not have an interesting interface and just comes down to a single function call.

Arnd