This is a patch series for I2C driver for Sunplus SP7021 SoC.
Subsystems (2)
cover This is a patch series for I2C 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
LH.Kuo (2):
I2C: Add I2C driver for Sunplus SP7021
devicetree bindings I2C Add bindings doc for Sunplus SP7021
.../devicetree/bindings/i2c/i2c-sunplus.yaml | 82 + MAINTAINERS | 39 +- drivers/i2c/busses/Kconfig | 10 + drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-sunplus.c | 1936 ++++++++++++++++++++ 5 files changed, 2052 insertions(+), 16 deletions(-) create mode 100644 Documentation/devicetree/bindings/i2c/i2c-sunplus.yaml create mode 100644 drivers/i2c/busses/i2c-sunplus.c
Signature · 1 line
2.7.4
PATCH 1/2 I2C: Add I2C driver for Sunplus SP7021
Add I2C driver for Sunplus SP7021.
--- MAINTAINERS | 38 +- drivers/i2c/busses/Kconfig | 10 + drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-sunplus.c | 1936 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 1969 insertions(+), 16 deletions(-) create mode 100644 drivers/i2c/busses/i2c-sunplus.c
MAINTAINERS +22 -16
@@ -3553,7 +3553,7 @@ N: kona BROADCOM BCM47XX MIPS ARCHITECTURE M: Hauke Mehrtens <[email protected]> -M: Rafał Miłecki <[email protected]> +M: Rafa? Mi?ecki <[email protected]> L: [email protected] S: Maintained F: Documentation/devicetree/bindings/mips/brcm/
@@ -3561,7 +3561,7 @@ F: arch/mips/bcm47xx/* F: arch/mips/include/asm/mach-bcm47xx/* BROADCOM BCM4908 ETHERNET DRIVER -M: Rafał Miłecki <[email protected]> +M: Rafa? Mi?ecki <[email protected]> M: [email protected] L: [email protected] S: Maintained
@@ -3571,7 +3571,7 @@ F: drivers/net/ethernet/broadcom/unimac.h BROADCOM BCM5301X ARM ARCHITECTURE M: Hauke Mehrtens <[email protected]> -M: Rafał Miłecki <[email protected]> +M: Rafa? Mi?ecki <[email protected]> M: [email protected] L: [email protected] (moderated for non-subscribers) S: Maintained
@@ -3581,7 +3581,7 @@ F: arch/arm/boot/dts/bcm953012* F: arch/arm/mach-bcm/bcm_5301x.c BROADCOM BCM53573 ARM ARCHITECTURE -M: Rafał Miłecki <[email protected]> +M: Rafa? Mi?ecki <[email protected]> L: [email protected] L: [email protected] (moderated for non-subscribers) S: Maintained
@@ -3800,7 +3800,7 @@ N: hr2 N: stingray BROADCOM IPROC GBIT ETHERNET DRIVER -M: Rafał Miłecki <[email protected]> +M: Rafa? Mi?ecki <[email protected]> M: [email protected] L: [email protected] S: Maintained
@@ -3835,13 +3835,13 @@ F: drivers/infiniband/hw/bnxt_re/ F: include/uapi/rdma/bnxt_re-abi.h BROADCOM NVRAM DRIVER -M: Rafał Miłecki <[email protected]> +M: Rafa? Mi?ecki <[email protected]> L: [email protected] S: Maintained F: drivers/firmware/broadcom/* BROADCOM PMB (POWER MANAGEMENT BUS) DRIVER -M: Rafał Miłecki <[email protected]> +M: Rafa? Mi?ecki <[email protected]> M: Florian Fainelli <[email protected]> M: [email protected] L: [email protected]
@@ -3851,7 +3851,7 @@ F: drivers/soc/bcm/bcm63xx/bcm-pmb.c F: include/dt-bindings/soc/bcm-pmb.h BROADCOM SPECIFIC AMBA DRIVER (BCMA) -M: Rafał Miłecki <[email protected]> +M: Rafa? Mi?ecki <[email protected]> L: [email protected] S: Maintained F: drivers/bcma/
@@ -6947,7 +6947,7 @@ W: http://www.broadcom.com F: drivers/scsi/elx/ ENE CB710 FLASH CARD READER DRIVER -M: Michał Mirosław <[email protected]> +M: Micha? Miros?aw <[email protected]> S: Maintained F: drivers/misc/cb710/ F: drivers/mmc/host/cb710-mmc.*
@@ -7389,7 +7389,7 @@ F: include/uapi/video/ F: include/video/ FREESCALE CAAM (Cryptographic Acceleration and Assurance Module) DRIVER -M: Horia Geantă <[email protected]> +M: Horia Geant? <[email protected]> M: Pankaj Gupta <[email protected]> L: [email protected] S: Maintained
@@ -7926,7 +7926,7 @@ F: fs/gfs2/ F: include/uapi/linux/gfs2_ondisk.h GIGABYTE WMI DRIVER -M: Thomas Weißschuh <[email protected]> +M: Thomas Wei?schuh <[email protected]> L: [email protected] S: Maintained F: drivers/platform/x86/gigabyte-wmi.c
@@ -8871,7 +8871,7 @@ S: Maintained F: drivers/i2c/i2c-stub.c I3C DRIVER FOR CADENCE I3C MASTER IP -M: Przemysław Gaj <[email protected]> +M: Przemys?aw Gaj <[email protected]> S: Maintained F: Documentation/devicetree/bindings/i3c/cdns,i3c-master.txt F: drivers/i3c/master/i3c-master-cdns.c
@@ -14456,7 +14456,7 @@ F: drivers/pci/controller/pci-v3-semi.c PCI ENDPOINT SUBSYSTEM M: Kishon Vijay Abraham I <[email protected]> M: Lorenzo Pieralisi <[email protected]> -R: Krzysztof Wilczyński <[email protected]> +R: Krzysztof Wilczy?ski <[email protected]> L: [email protected] S: Supported F: Documentation/PCI/endpoint/*
@@ -14504,7 +14504,7 @@ F: drivers/pci/controller/pci-xgene-msi.c PCI NATIVE HOST BRIDGE AND ENDPOINT DRIVERS M: Lorenzo Pieralisi <[email protected]> R: Rob Herring <[email protected]> -R: Krzysztof Wilczyński <[email protected]> +R: Krzysztof Wilczy?ski <[email protected]> L: [email protected] S: Supported Q: http://patchwork.ozlabs.org/project/linux-pci/list/
@@ -16490,7 +16490,7 @@ F: Documentation/devicetree/bindings/rng/samsung,exynos4-rng.yaml F: drivers/crypto/exynos-rng.c SAMSUNG EXYNOS TRUE RANDOM NUMBER GENERATOR (TRNG) DRIVER -M: Łukasz Stelmach <[email protected]> +M: ?ukasz Stelmach <[email protected]> L: [email protected] S: Maintained F: Documentation/devicetree/bindings/rng/samsung,exynos5250-trng.yaml
@@ -16504,7 +16504,7 @@ F: drivers/video/fbdev/s3c-fb.c SAMSUNG INTERCONNECT DRIVERS M: Sylwester Nawrocki <[email protected]> -M: Artur Świgoń <[email protected]> +M: Artur ?wigo? <[email protected]> L: [email protected] L: [email protected] S: Supported
@@ -17947,6 +17947,12 @@ L: [email protected] S: Maintained F: drivers/net/ethernet/dlink/sundance.c +SUNPLUS I2C CONTROLLER INTERFACE DRIVER +M: LH Kuo <[email protected]> +L: [email protected] +S: Maintained +F: drivers/i2c/busses/i2c-sunplus.c + SUPERH M: Yoshinori Sato <[email protected]> M: Rich Felker <[email protected]>
drivers/i2c/busses/Kconfig +10 -0
@@ -1371,6 +1371,16 @@ config SCx200_ACB This support is also available as a module. If so, the module will be called scx200_acb. +config I2C_SUNPLUS + tristate "Sunplus I2C driver" + depends on SOC_SP7021 || SOC_Q645 + help + Say Y here to include support for I2C controller in the + Sunplus SoCs. + + This driver can also be built as a module. If so, the module will be + called as i2c-sunplus. + config I2C_OPAL tristate "IBM OPAL I2C driver" depends on PPC_POWERNV
drivers/i2c/busses/Makefile +1 -0
@@ -146,5 +146,6 @@ obj-$(CONFIG_I2C_XGENE_SLIMPRO) += i2c-xgene-slimpro.o obj-$(CONFIG_SCx200_ACB) += scx200_acb.o obj-$(CONFIG_I2C_FSI) += i2c-fsi.o obj-$(CONFIG_I2C_VIRTIO) += i2c-virtio.o +obj-$(CONFIG_I2C_SUNPLUS) += i2c-sunplus.o ccflags-$(CONFIG_I2C_DEBUG_BUS) := -DDEBUG
drivers/i2c/busses/i2c-sunplus.c new file +1936 -0
1,936 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 2/2 devicetree bindings I2C Add bindings doc for Sunplus SP7021
In reply to LH.KuoAdd devicetree bindings I2C Add bindings doc for Sunplus SP7021
--- .../devicetree/bindings/i2c/i2c-sunplus.yaml | 82 ++++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 83 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/i2c-sunplus.yaml
Documentation/devicetree/bindings/i2c/i2c-sunplus.yaml new file +82 -0
@@ -0,0 +1,82 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +# Copyright (C) Sunplus Co., Ltd. 2021 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/i2c/i2c-sunplus.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Sunplus's I2C controller + +allOf: + - $ref: /schemas/i2c/i2c-controller.yaml# + +maintainers: + - lh.kuo <[email protected]> + +properties: + compatible: + enum: + - sunplus,sp7021-i2cm + - sunplus,q645-i2cm + + reg: + items: + - description: Base address and length of the I2C registers + - description: Base address and length of the I2C DMA registers + + reg-names: + items: + - const: i2cm + - const: i2cmdma + + interrupts: + maxItems: 1 + + clocks: + maxItems: 1 + + resets: + maxItems: 1 + + clock-frequency: + enum: [ 100000, 400000 ] + + pinctrl-names: + description: + A pinctrl state named "default" must be defined. + const: default + + pinctrl-0: + description: + A phandle to the default pinctrl state. + +required: + - compatible + - reg + - reg-names + - interrupts + - clocks + - resets + - pinctrl-names + - pinctrl-0 + +additionalProperties: false + +examples: + - | + #include <dt-bindings/clock/sp-sp7021.h> + #include <dt-bindings/reset/sp-sp7021.h> + #include <dt-bindings/interrupt-controller/irq.h> + i2cm0: i2c@9C004600 { + compatible = "sunplus,sp7021-i2cm"; + reg = <0x9c004600 0x80>, <0x9c004680 0x80>; + reg-names = "i2cm", "i2cmdma"; + interrupt-parent = <&intc>; + interrupts = <174 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clkc I2CM0>; + resets = <&rstc RST_I2CM0>; + clock-frequency = <100000>; + pinctrl-names = "default"; + pinctrl-0 = <&i2cm0_pins>; + }; +...
MAINTAINERS +1 -0
@@ -17951,6 +17951,7 @@ SUNPLUS I2C CONTROLLER INTERFACE DRIVER M: LH Kuo <[email protected]> L: [email protected] S: Maintained +F: Documentation/devicetree/bindings/i2c/i2c-sunplus.yaml F: drivers/i2c/busses/i2c-sunplus.c SUPERH
Signature · 1 line
2.7.4
Rob Herring
maintainerRe: [PATCH 2/2] devicetree bindings I2C Add bindings doc for Sunplus SP7021
Quoted 1 line · LH.Kuo
Add devicetree bindings I2C Add bindings doc for Sunplus SP7021
Please follow the subject convention used by the subsystem. This will be evident running 'git log --oneline'. For this one:
'dt-bindings: i2c: ...'
Quoted 67 lines
Signed-off-by LH.Kuo <[email protected]>--- .../devicetree/bindings/i2c/i2c-sunplus.yaml | 82 ++++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 83 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/i2c-sunplus.yamlDocumentation/devicetree/bindings/i2c/i2c-sunplus.yaml new file +53
-0@@ -0,0 +1,82 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +# Copyright (C) Sunplus Co., Ltd. 2021 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/i2c/i2c-sunplus.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Sunplus's I2C controller + +allOf: + - $ref: /schemas/i2c/i2c-controller.yaml# + +maintainers: + - lh.kuo <[email protected]> + +properties: + compatible: + enum: + - sunplus,sp7021-i2cm + - sunplus,q645-i2cm + + reg: + items: + - description: Base address and length of the I2C registers + - description: Base address and length of the I2C DMA registers + + reg-names: + items: + - const: i2cm + - const: i2cmdma + + interrupts: + maxItems: 1 + + clocks: + maxItems: 1 + + resets: + maxItems: 1 + + clock-frequency: + enum: [ 100000, 400000 ] + + pinctrl-names: + description: + A pinctrl state named "default" must be defined. + const: default + + pinctrl-0: + description: + A phandle to the default pinctrl state. + +required:
Documentation/devicetree/bindings/i2c/i2c-sunplus.yaml line 63
Quoted 10 lines
Documentation/devicetree/bindings/i2c/i2c-sunplus.yaml new file +10
-0+ - compatible + - reg + - reg-names + - interrupts + - clocks + - resets + - pinctrl-names + - pinctrl-0 + +additionalProperties: false
This means you can't have any child nodes which I'd assume you want. You need 'unevaluatedProperties: false' instead.
Documentation/devicetree/bindings/i2c/i2c-sunplus.yaml line 70
Quoted 7 lines
Documentation/devicetree/bindings/i2c/i2c-sunplus.yaml new file +7
-0+ +examples: + - | + #include <dt-bindings/clock/sp-sp7021.h> + #include <dt-bindings/reset/sp-sp7021.h> + #include <dt-bindings/interrupt-controller/irq.h> + i2cm0: i2c@9C004600 {
Drop unused labels.
Quoted 28 lines
Documentation/devicetree/bindings/i2c/i2c-sunplus.yaml new file +12
-0+ compatible = "sunplus,sp7021-i2cm"; + reg = <0x9c004600 0x80>, <0x9c004680 0x80>; + reg-names = "i2cm", "i2cmdma"; + interrupt-parent = <&intc>; + interrupts = <174 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clkc I2CM0>; + resets = <&rstc RST_I2CM0>; + clock-frequency = <100000>; + pinctrl-names = "default"; + pinctrl-0 = <&i2cm0_pins>; + }; +...MAINTAINERS +1
-0@@ -17951,6 +17951,7 @@ SUNPLUS I2C CONTROLLER INTERFACE DRIVER M: LH Kuo <[email protected]> L: [email protected] S: Maintained +F: Documentation/devicetree/bindings/i2c/i2c-sunplus.yaml F: drivers/i2c/busses/i2c-sunplus.c SUPERHSignature · 1 line
2.7.4
v2 cover Add I2C control driver for Sunplus SP7021 SoC
In reply to LH.KuoThis is a patch series for I2C 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
LH.Kuo (2):
I2C: Add I2C driver for Sunplus SP7021
devicetree bindings I2C Add bindings doc for Sunplus SP7021
.../devicetree/bindings/i2c/i2c-sunplus.yaml | 82 + MAINTAINERS | 7 + drivers/i2c/busses/Kconfig | 10 + drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-sunplus.c | 1700 ++++++++++++++++++++ 5 files changed, 1800 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/i2c-sunplus.yaml create mode 100644 drivers/i2c/busses/i2c-sunplus.c
Signature · 1 line
2.7.4
PATCH v2 1/2 I2C: Add I2C driver for Sunplus SP7021
Add I2C driver for Sunplus SP7021.
---
Changes in v2:
- Addressed all comments from Mr. Rob Herring.
- Modified the structure and register access method.
- Modifiedthe path about MAINTAINERS. ( wrong messages PATH in v1).
- Modifiedthe the YAML file.
MAINTAINERS | 6 + drivers/i2c/busses/Kconfig | 10 + drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-sunplus.c | 1700 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 1717 insertions(+) create mode 100644 drivers/i2c/busses/i2c-sunplus.c
MAINTAINERS +6 -0
@@ -18189,6 +18189,12 @@ L: [email protected] S: Maintained F: drivers/net/ethernet/dlink/sundance.c +SUNPLUS I2C CONTROLLER INTERFACE DRIVER +M: LH Kuo <[email protected]> +L: [email protected] +S: Maintained +F: drivers/i2c/busses/i2c-sunplus.c + SUPERH M: Yoshinori Sato <[email protected]> M: Rich Felker <[email protected]>
drivers/i2c/busses/Kconfig +10 -0
@@ -1061,6 +1061,16 @@ config I2C_SUN6I_P2WI This interface is used to connect to specific PMIC devices (like the AXP221). +config I2C_SUNPLUS + tristate "Sunplus I2C driver" + depends on SOC_SP7021 || SOC_Q645 + help + Say Y here to include support for I2C controller in the + Sunplus SoCs. + + This driver can also be built as a module. If so, the module will be + called as i2c-sunplus. + config I2C_SYNQUACER tristate "Socionext SynQuacer I2C controller" depends on ARCH_SYNQUACER || COMPILE_TEST
drivers/i2c/busses/Makefile +1 -0
@@ -107,6 +107,7 @@ obj-$(CONFIG_I2C_STM32F4) += i2c-stm32f4.o i2c-stm32f7-drv-objs := i2c-stm32f7.o i2c-stm32.o obj-$(CONFIG_I2C_STM32F7) += i2c-stm32f7-drv.o obj-$(CONFIG_I2C_SUN6I_P2WI) += i2c-sun6i-p2wi.o +obj-$(CONFIG_I2C_SUNPLUS) += i2c-sunplus.o obj-$(CONFIG_I2C_SYNQUACER) += i2c-synquacer.o obj-$(CONFIG_I2C_TEGRA) += i2c-tegra.o obj-$(CONFIG_I2C_TEGRA_BPMP) += i2c-tegra-bpmp.o
drivers/i2c/busses/i2c-sunplus.c new file +1700 -0
1,700 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH v2 1/2] I2C: Add I2C driver for Sunplus SP7021
On Tue, 2021-11-09 at 14:59 +0800, LH.Kuo wrote:
[...]
Quoted 30 lines
drivers/i2c/busses/i2c-sunplus.c new file +30
-0+static int sp_i2c_probe (struct platform_device *pdev) +{ +struct sp_i2c_dev *sp_i2c_dev_info; +struct i2c_adapter *p_adap; +unsigned int i2c_clk_freq; +int device_id =0 ; +int ret =I2C_SUCCESS ; +struct device *dev = &pdev->dev; +const struct i2c_compatible *dev_mode; + +if (pdev->dev.of_node) { + pdev->id =of_alias_get_id (pdev->dev.of_node,"i2c" ); +dev_err (&pdev->dev,"pdev->id=%d\n" , pdev->id); + device_id = pdev->id; + } + + sp_i2c_dev_info =devm_kzalloc (&pdev->dev,sizeof (*sp_i2c_dev_info),GFP_KERNEL ); +if (!sp_i2c_dev_info) +return -ENOMEM ; + +if (!of_property_read_u32 (pdev->dev.of_node,"clock-frequency" , &i2c_clk_freq)) { +dev_err (&pdev->dev,"clk_freq %d\n" , i2c_clk_freq); + sp_i2c_dev_info->i2c_clk_freq = i2c_clk_freq; + }else { + sp_i2c_dev_info->i2c_clk_freq =SP_I2C_FREQ *1000 ; + } + + sp_i2c_dev_info->dev = &pdev->dev; + + ret =_sp_i2cm_get_resources (pdev, sp_i2c_dev_info);
drivers/i2c/busses/i2c-sunplus.c line 1513
Quoted 10 lines
drivers/i2c/busses/i2c-sunplus.c new file +10
-0+if (ret !=I2C_SUCCESS ) { +dev_err (&pdev->dev," get resources fail !\n" ); +return ret; + } + +/* dma alloc*/ + sp_i2c_dev_info->dma_vir_base =dma_alloc_coherent (&pdev->dev,SP_BUFFER_SIZE , + &sp_i2c_dev_info->dma_phy_base,GFP_ATOMIC ); +if (!sp_i2c_dev_info->dma_vir_base) + goto free_dma;
Please fix your error paths, the driver shouldn't try to revert the action that just failed.
Here you can use dmam_alloc_coherent() and just return -ENOMEM on error.
drivers/i2c/busses/i2c-sunplus.c line 1520
Quoted 7 lines
drivers/i2c/busses/i2c-sunplus.c new file +7
-0+ + sp_i2c_dev_info->clk =devm_clk_get (dev,NULL ); + +if (IS_ERR (sp_i2c_dev_info->clk)) { + ret =PTR_ERR (sp_i2c_dev_info->clk); +dev_err (&pdev->dev,"failed to retrieve clk: %d\n" , ret); + goto err_clk_disable;
Then this could
return ret;
Better, use return dev_err_probe().
drivers/i2c/busses/i2c-sunplus.c line 1528
Quoted 8 lines
drivers/i2c/busses/i2c-sunplus.c new file +8
-0+ } + + sp_i2c_dev_info->rstc =devm_reset_control_get_exclusive (dev,NULL ); + +if (IS_ERR (sp_i2c_dev_info->rstc)) { + ret =PTR_ERR (sp_i2c_dev_info->rstc); +dev_err (&pdev->dev,"failed to retrieve reset controller: %d\n" , ret); + goto err_clk_disable;
Same as above.
drivers/i2c/busses/i2c-sunplus.c line 1534
Quoted 6 lines
drivers/i2c/busses/i2c-sunplus.c new file +6
-0+ } + + ret =clk_prepare_enable (sp_i2c_dev_info->clk); + +if (ret) { +dev_err (&pdev->dev,"failed to enable clk: %d\n" , ret);
Consider using "%pe" and ERR_PTR(ret) to print the error name instead of a number [1].
[1] https://www.kernel.org/doc/html/latest/core-api/printk-formats.html?#error-pointers
Review
Quoted 1 line
(quoted diff) +1
-0+ goto err_clk_disable;
return ret;
drivers/i2c/busses/i2c-sunplus.c line 1542
Quoted 7 lines
drivers/i2c/busses/i2c-sunplus.c new file +7
-0+ } + + ret =reset_control_deassert (sp_i2c_dev_info->rstc); + +if (ret) { +dev_err (&pdev->dev,"failed to deassert reset line: %d\n" , ret); + goto err_reset_assert;
goto err_clk_disable;
Quoted 13 lines
drivers/i2c/busses/i2c-sunplus.c new file +13
-0+ } + +init_waitqueue_head (&sp_i2c_dev_info->wait); + + dev_mode =of_device_get_match_data (&pdev->dev); + sp_i2c_dev_info->mode = dev_mode->mode; + sp_i2c_dev_info->total_port = dev_mode->total_port; + p_adap = &sp_i2c_dev_info->adap; +sprintf (p_adap->name,"%s%d" ,SP_DEVICE_NAME , device_id); + p_adap->algo = &sp_algorithm; + p_adap->algo_data = sp_i2c_dev_info; + p_adap->nr = device_id; + p_adap->class =0 ;
drivers/i2c/busses/i2c-sunplus.c line 1565
Quoted 10 lines
drivers/i2c/busses/i2c-sunplus.c new file +10
-0+ p_adap->retries =5 ; + p_adap->dev.parent = &pdev->dev; + p_adap->dev.of_node = pdev->dev.of_node; + + ret =i2c_add_numbered_adapter (p_adap); + + ret =_sp_i2cm_init (device_id, sp_i2c_dev_info); +if (ret !=0 ) { +dev_err (&pdev->dev,"i2c master %d init error\n" , device_id); + goto err_reset_assert;
This one is correct, but I'd also print ret.
drivers/i2c/busses/i2c-sunplus.c line 1577
Quoted 12 lines
drivers/i2c/busses/i2c-sunplus.c new file +12
-0+ } + +if (ret <0 ) + goto err_reset_assert; +else +platform_set_drvdata (pdev, sp_i2c_dev_info); + + ret =request_irq (sp_i2c_dev_info->irq, _sp_i2cm_irqevent_handler,IRQF_TRIGGER_HIGH , + p_adap->name, sp_i2c_dev_info); +if (ret) { +dev_err (&pdev->dev,"request irq fail !!\n" ); +return I2C_ERR_REQUESET_IRQ ;
Don't return non-standard error codes. This should return ret instead, but not before going through the error cleanup path below. Also, consider using devm_request_irq().
Quoted 9 lines
drivers/i2c/busses/i2c-sunplus.c new file +9
-0+ } + +pm_runtime_set_autosuspend_delay (&pdev->dev,5000 ); +pm_runtime_use_autosuspend (&pdev->dev); +pm_runtime_set_active (&pdev->dev); +pm_runtime_enable (&pdev->dev); + +return ret; +
drivers/i2c/busses/i2c-sunplus.c line 1596
Quoted 10 lines
drivers/i2c/busses/i2c-sunplus.c new file +10
-0+err_reset_assert: +reset_control_assert (sp_i2c_dev_info->rstc); +err_clk_disable: +clk_disable_unprepare (sp_i2c_dev_info->clk); +free_dma: +dma_free_coherent (&pdev->dev,SP_BUFFER_SIZE , + sp_i2c_dev_info->dma_vir_base, sp_i2c_dev_info->dma_phy_base); + +return ret; +}
regards
Philipp
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v2 1/2] I2C: Add I2C driver for Sunplus SP7021
Hi,
On Wed, 2021-11-10 at 05:37 +0000, Lh Kuo 郭力豪 wrote:
[...]
Quoted 12 lines
Quoted 12 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ /* dma alloc*/ + sp_i2c_dev_info->dma_vir_base = dma_alloc_coherent(&pdev->dev,
SP_BUFFER_SIZE,drivers/i2c/busses/i2c-sunplus.c line 1513
Quoted 3 lines
drivers/i2c/busses/i2c-sunplus.c new file +3
-0+ &sp_i2c_dev_info->dma_phy_base, GFP_ATOMIC); +if (!sp_i2c_dev_info->dma_vir_base) + goto free_dma;Please fix your error paths, the driver shouldn't try to revert the action that just failed.
Here you can use
dmam_alloc_coherent()and just return-ENOMEMon error.
Quoted 7 lines
I will make change as below is it OK ?
/* dma alloc*/ sp_i2c_dev_info->dma_vir_base = dmam_alloc_coherent(&pdev->dev, SP_BUFFER_SIZE, &sp_i2c_dev_info->dma_phy_base, GFP_ATOMIC); if (!sp_i2c_dev_info->dma_vir_base) return -ENOMEM;
Yes, this looks good to me. With this change, you can remove the dma_free_coherent() calls below.
Quoted 15 lines
Quoted 10 lines
drivers/i2c/busses/i2c-sunplus.c line 1520
Quoted 7 lines
drivers/i2c/busses/i2c-sunplus.c new file +7
-0+ + sp_i2c_dev_info->clk =devm_clk_get (dev,NULL ); + +if (IS_ERR (sp_i2c_dev_info->clk)) { + ret =PTR_ERR (sp_i2c_dev_info->clk); +dev_err (&pdev->dev,"failed to retrieve clk: %d\n" , ret); + goto err_clk_disable;Then this could
Quoted 4 lines
return ret;Better, use return
dev_err_probe().
Quoted 8 lines
I will make change as below is it OK ?
sp_i2c_dev_info->clk = devm_clk_get(dev, NULL); if (IS_ERR(sp_i2c_dev_info->clk)) { return dev_err_probe(&pdev->dev, PTR_ERR(sp_i2c_dev_info->clk), "Could not get clock\n"); }
Yes.
Quoted 12 lines
Quoted 11 lines
drivers/i2c/busses/i2c-sunplus.c line 1528
Quoted 8 lines
drivers/i2c/busses/i2c-sunplus.c new file +8
-0+ } + + sp_i2c_dev_info->rstc =devm_reset_control_get_exclusive (dev,NULL ); + +if (IS_ERR (sp_i2c_dev_info->rstc)) { + ret =PTR_ERR (sp_i2c_dev_info->rstc); +dev_err (&pdev->dev,"failed to retrieve reset controller: %d\n" , ret); + goto err_clk_disable;Same as above.
Quoted 8 lines
I will make change as below is it OK ?
sp_i2c_dev_info->rstc = devm_reset_control_get_exclusive(dev, NULL); if (IS_ERR(sp_i2c_dev_info->rstc)) { return dev_err_probe(&pdev->dev, PTR_ERR(sp_i2c_dev_info->rstc), "Could not get clock\n"); }
The error message should be "Could not get reset\n" instead.
Quoted 19 lines
Quoted 10 lines
drivers/i2c/busses/i2c-sunplus.c line 1534
Quoted 6 lines
drivers/i2c/busses/i2c-sunplus.c new file +6
-0+ } + + ret =clk_prepare_enable (sp_i2c_dev_info->clk); + +if (ret) { +dev_err (&pdev->dev,"failed to enable clk: %d\n" , ret);Consider using "%pe" and
ERR_PTR(ret)to print the error name instead of a number [1].Quoted 8 lines
[1]
https://www.kernel.org/doc/html/latest/core-api/printk-formats.html?#error-p
ointersReview
Quoted 1 line
(quoted diff) +1
-0+ goto err_clk_disable;return ret;
Quoted 6 lines
I will make change as below is it OK ?
ret = clk_prepare_enable(sp_i2c_dev_info->clk); if (ret) { dev_err(&pdev->dev, "failed to enable clk: %pe\n", ERR_PTR(ret));
Ok. Alternatively, you could also use dev_err_probe() as above.
Quoted 1 line
goto err_clk_disable;
Not ok. If clk_prepare_enable() did not succeed, do not call clk_disable_unprepare(). return ret instead.
Quoted 8 lines
}Quoted 6 lines
drivers/i2c/busses/i2c-sunplus.c line 1541
Quoted 6 lines
drivers/i2c/busses/i2c-sunplus.c new file +6
-0+ } + + ret =reset_control_deassert (sp_i2c_dev_info->rstc); + +if (ret) { +dev_err (&pdev->dev,"failed to deassert reset line: %d\n" , ret);
Consider either changing this to %pe or use dev_err_probe(), for consistency with the above error messages.
Quoted 3 lines
Quoted 3 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ goto err_reset_assert;goto err_clk_disable;
This is required as well.
Quoted 28 lines
Quoted 18 lines
Quoted 18 lines
drivers/i2c/busses/i2c-sunplus.c new file +17
-0+ } + +init_waitqueue_head (&sp_i2c_dev_info->wait); + + dev_mode =of_device_get_match_data (&pdev->dev); + sp_i2c_dev_info->mode = dev_mode->mode; + sp_i2c_dev_info->total_port = dev_mode->total_port; + p_adap = &sp_i2c_dev_info->adap; +sprintf (p_adap->name,"%s%d" ,SP_DEVICE_NAME , device_id); + p_adap->algo = &sp_algorithm; + p_adap->algo_data = sp_i2c_dev_info; + p_adap->nr = device_id; + p_adap->class =0 ; + p_adap->retries =5 ; + p_adap->dev.parent = &pdev->dev; + p_adap->dev.of_node = pdev->dev.of_node; +Quoted 9 lines
drivers/i2c/busses/i2c-sunplus.c line 1565
Quoted 6 lines
drivers/i2c/busses/i2c-sunplus.c new file +6
-0+ ret =i2c_add_numbered_adapter (p_adap); + + ret =_sp_i2cm_init (device_id, sp_i2c_dev_info); +if (ret !=0 ) { +dev_err (&pdev->dev,"i2c master %d init error\n" , device_id); + goto err_reset_assert;This one is correct, but I'd also print ret.
Quoted 7 lines
I will make change as below is it OK ?
ret = _sp_i2cm_init(device_id, sp_i2c_dev_info); if (ret != 0) { dev_err(&pdev->dev, "i2c master %d init error ret %d\n", device_id, ret); goto err_reset_assert; }
Yes, although I'd prefer a consistent style with the error messages above. For example:
dev_err(&pdev->dev, "i2c master %d init error: %pe\n", device_id, ERR_PTR(ret));
or
dev_err_probe(&pdev->dev, ret, "i2c master %d init error", device_id);
Quoted 19 lines
Quoted 9 lines
drivers/i2c/busses/i2c-sunplus.c
Quoted 8 lines
drivers/i2c/busses/i2c-sunplus.c new file +8
-0+ } + +if (ret <0 ) + goto err_reset_assert; +else +platform_set_drvdata (pdev, sp_i2c_dev_info); + + ret = request_irq(sp_i2c_dev_info->irq, _sp_i2cm_irqevent_handler,
IRQF_TRIGGER_HIGH,Quoted 9 lines
drivers/i2c/busses/i2c-sunplus.c line 1577
Quoted 4 lines
drivers/i2c/busses/i2c-sunplus.c new file +4
-0+ p_adap->name, sp_i2c_dev_info); +if (ret) { +dev_err (&pdev->dev,"request irq fail !!\n" ); +return I2C_ERR_REQUESET_IRQ ;Don't return non-standard error codes. This should return ret instead, but not before going through the error cleanup path below. Also, consider using
devm_request_irq().
Quoted 7 lines
I will make change as below is it OK ?
ret = devm_request_irq(&pdev->dev, sp_i2c_dev_info->irq, _sp_i2cm_irqevent_handler, IRQF_TRIGGER_HIGH, p_adap->name, sp_i2c_dev_info); if (ret) { dev_err(&pdev->dev, "request irq fail !!\n"); return ret; }
Yes. With this, you can remove the free_irq() call below.
regards
Philipp
PATCH v2 2/2 devicetree bindings I2C Add bindings doc for Sunplus SP7021
In reply to LH.KuoAdd devicetree bindings I2C Add bindings doc for Sunplus SP7021
---
Changes in v2:
- Addressed all comments from Mr. Rob Herring.
- Modified the structure and register access method.
- Modifiedthe path about MAINTAINERS. ( wrong messages PATH in v1).
- Modifiedthe the YAML file.
.../devicetree/bindings/i2c/i2c-sunplus.yaml | 82 ++++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 83 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/i2c-sunplus.yaml
Documentation/devicetree/bindings/i2c/i2c-sunplus.yaml new file +82 -0
@@ -0,0 +1,82 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +# Copyright (C) Sunplus Co., Ltd. 2021 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/i2c/i2c-sunplus.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Sunplus's I2C controller + +allOf: + - $ref: /schemas/i2c/i2c-controller.yaml# + +maintainers: + - lh.kuo <[email protected]> + +properties: + compatible: + enum: + - sunplus,sp7021-i2cm + - sunplus,q645-i2cm + + reg: + items: + - description: Base address and length of the I2C registers + - description: Base address and length of the I2C DMA registers + + reg-names: + items: + - const: i2cm + - const: i2cmdma + + interrupts: + maxItems: 1 + + clocks: + maxItems: 1 + + resets: + maxItems: 1 + + clock-frequency: + enum: [ 100000, 400000 ] + + pinctrl-names: + description: + A pinctrl state named "default" must be defined. + const: default + + pinctrl-0: + description: + A phandle to the default pinctrl state. + +required: + - compatible + - reg + - reg-names + - interrupts + - clocks + - resets + - pinctrl-names + - pinctrl-0 + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/clock/sp-sp7021.h> + #include <dt-bindings/reset/sp-sp7021.h> + #include <dt-bindings/interrupt-controller/irq.h> + i2c@9C004600 { + compatible = "sunplus,sp7021-i2cm"; + reg = <0x9c004600 0x80>, <0x9c004680 0x80>; + reg-names = "i2cm", "i2cmdma"; + interrupt-parent = <&intc>; + interrupts = <174 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clkc I2CM0>; + resets = <&rstc RST_I2CM0>; + clock-frequency = <100000>; + pinctrl-names = "default"; + pinctrl-0 = <&i2cm0_pins>; + }; +...
MAINTAINERS +1 -0
@@ -18193,6 +18193,7 @@ SUNPLUS I2C CONTROLLER INTERFACE DRIVER M: LH Kuo <[email protected]> L: [email protected] S: Maintained +F: Documentation/devicetree/bindings/i2c/i2c-sunplus.yaml F: drivers/i2c/busses/i2c-sunplus.c SUPERH
Signature · 1 line
2.7.4
Rob Herring
maintainerRe: [PATCH v2 2/2] devicetree bindings I2C Add bindings doc for Sunplus SP7021
Quoted 3 lines · LH.Kuo
Add devicetree bindings I2C Add bindings doc for Sunplus SP7021
Signed-off-by LH.Kuo <[email protected]>
As with other SunPlus patches, author and S-o-b must match.
Quoted 22 lines
---
Changes in v2:
- Addressed all comments from Mr. Rob Herring.
- Modified the structure and register access method.
- Modifiedthe path aboutMAINTAINERS. ( wrong messages PATH in v1).
- Modifiedthe the YAML file..../devicetree/bindings/i2c/i2c-sunplus.yaml | 82 ++++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 83 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/i2c-sunplus.yamlDocumentation/devicetree/bindings/i2c/i2c-sunplus.yaml new file +4
-0@@ -0,0 +1,82 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +# Copyright (C) Sunplus Co., Ltd. 2021 +%YAML 1.2 +---
Documentation/devicetree/bindings/i2c/i2c-sunplus.yaml line 14
Quoted 10 lines
Documentation/devicetree/bindings/i2c/i2c-sunplus.yaml new file +10
-0+$id: http://devicetree.org/schemas/i2c/i2c-sunplus.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Sunplus's I2C controller + +allOf: + - $ref: /schemas/i2c/i2c-controller.yaml# + +maintainers: + - lh.kuo <[email protected]>
Full name here please.
Documentation/devicetree/bindings/i2c/i2c-sunplus.yaml line 25
Quoted 11 lines
Documentation/devicetree/bindings/i2c/i2c-sunplus.yaml new file +11
-0+ +properties: + compatible: + enum: + - sunplus,sp7021-i2cm + - sunplus,q645-i2cm + + reg: + items: + - description: Base address and length of the I2C registers + - description: Base address and length of the I2C DMA registers
Drop 'Base address and length of the '.
Quoted 7 lines
Documentation/devicetree/bindings/i2c/i2c-sunplus.yaml new file +7
-0+ + reg-names: + items: + - const: i2cm + - const: i2cmdma + + interrupts:
Documentation/devicetree/bindings/i2c/i2c-sunplus.yaml line 42
Quoted 10 lines
Documentation/devicetree/bindings/i2c/i2c-sunplus.yaml new file +10
-0+ maxItems: 1 + + clocks: + maxItems: 1 + + resets: + maxItems: 1 + + clock-frequency: + enum: [ 100000, 400000 ]
You can't support other frequencies?
Documentation/devicetree/bindings/i2c/i2c-sunplus.yaml line 51
Quoted 9 lines
Documentation/devicetree/bindings/i2c/i2c-sunplus.yaml new file +9
-0+ + pinctrl-names: + description: + A pinctrl state named "default" must be defined. + const: default + + pinctrl-0: + description: + A phandle to the default pinctrl state.
You don't have to define pinctrl properties when there's only 'default'.
Quoted 47 lines
Documentation/devicetree/bindings/i2c/i2c-sunplus.yaml new file +31
-0+ +required: + - compatible + - reg + - reg-names + - interrupts + - clocks + - resets + - pinctrl-names + - pinctrl-0 + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/clock/sp-sp7021.h> + #include <dt-bindings/reset/sp-sp7021.h> + #include <dt-bindings/interrupt-controller/irq.h> + i2c@9C004600 { + compatible = "sunplus,sp7021-i2cm"; + reg = <0x9c004600 0x80>, <0x9c004680 0x80>; + reg-names = "i2cm", "i2cmdma"; + interrupt-parent = <&intc>; + interrupts = <174 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clkc I2CM0>; + resets = <&rstc RST_I2CM0>; + clock-frequency = <100000>; + pinctrl-names = "default"; + pinctrl-0 = <&i2cm0_pins>; + }; +...MAINTAINERS +1
-0@@ -18193,6 +18193,7 @@ SUNPLUS I2C CONTROLLER INTERFACE DRIVER M: LH Kuo <[email protected]> L: [email protected] S: Maintained +F: Documentation/devicetree/bindings/i2c/i2c-sunplus.yaml F: drivers/i2c/busses/i2c-sunplus.c SUPERHSignature · 1 line
2.7.4