riscv: spacemit: add i2c support to K1 SoC
Subsystems (4)
cover riscv: spacemit: add i2c support to K1 SoC
Hi all,
This patch implements I2C driver for the SpacemiT K1 SoC, providing basic support for I2C read/write communication which compatible with standard I2C bus specifications.
In this version, the driver defaults to use fast-speed-mode and interrupts for transmission, and does not support DMA, high-speed mode, or FIFO.
The docs of I2C can be found here, in chapter 16.1 I2C [1]
Troy Mitchell (2):
dt-bindings: i2c: spacemit: add support for K1 SoC
i2c: spacemit: add support for SpacemiT K1 SoC
.../bindings/i2c/spacemit,k1-i2c.yaml | 59 ++ drivers/i2c/busses/Kconfig | 18 + drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-k1.c | 694 ++++++++++++++++++ 4 files changed, 772 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml create mode 100644 drivers/i2c/busses/i2c-k1.c
Signature · 1 line
2.34.1
PATCH 1/2 dt-bindings: i2c: spacemit: add support for K1 SoC
The i2c of K1 supports fast-speed-mode and high-speed-mode, and supports FIFO transmission.
--- .../bindings/i2c/spacemit,k1-i2c.yaml | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml new file +59 -0
@@ -0,0 +1,59 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/i2c/spacemit,k1-i2c.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: I2C controller embedded in SpacemiT's K1 SoC + +maintainers: + - Troy Mitchell <[email protected]> + +properties: + compatible: + const: spacemit,k1-i2c + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + maxItems: 1 + + clock-frequency: + description: + Desired I2C bus clock frequency in Hz. As only fast and high-speed + modes are supported by hardware, possible values are 100000 and 400000. + enum: [100000, 400000] + default: 100000 + + fifo-disable: + type: boolean + description: + Whether to disable FIFO. If FIFO is turned on, it will be interrupted + only when the FIFO depth is reached, which can reduce the frequency + of interruption. + default: false + +unevaluatedProperties: false + +required: + - compatible + - reg + - interrupts + - clocks + +examples: + - | + i2c0: i2c@d4010800 { + compatible = "spacemit,k1-i2c"; + reg = <0x0 0xd4010800 0x0 0x38>; + interrupt-parent = <&plic>; + interrupts = <36>; + clocks = <&ccu 90>; + clock-frequency = <100000>; + }; + +...
Signature · 1 line
2.34.1
PATCH 2/2 i2c: spacemit: add support for SpacemiT K1 SoC
In reply to Troy MitchellThis patch introduces basic I2C support for the SpacemiT K1 SoC, utilizing interrupts for transfers.
The driver has been tested using i2c-tools on a Bananapi-F3 board, and basic I2C read/write operations have been confirmed to work.
--- drivers/i2c/busses/Kconfig | 18 + drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-k1.c | 694 ++++++++++++++++++++++++++++++++++++ 3 files changed, 713 insertions(+) create mode 100644 drivers/i2c/busses/i2c-k1.c
drivers/i2c/busses/Kconfig +18 -0
@@ -800,6 +800,24 @@ config I2C_KEMPLD This driver can also be built as a module. If so, the module will be called i2c-kempld. +config I2C_K1 + tristate "Spacemit K1 I2C adapter" + depends on ARCH_SPACEMIT || COMPILE_TEST + help + This option enables support for the I2C interface on the Spacemit K1 + platform. + + If you enable this configuration, the kernel will include support for + the I2C adapter specific to the Spacemit K1 platform. This driver ca + be used to manage I2C bus transactions, which are necessary for + interfacing with I2C peripherals such as sensors, EEPROMs, and other + devices. + + This driver can also be compiled as a module. If you choose to build + it as a module, the resulting kernel module will be named `i2c-k1`. + Loading this module will enable the I2C functionality for the K1 + platform dynamically, without requiring a rebuild of the kernel. + config I2C_LPC2K tristate "I2C bus support for NXP LPC2K/LPC178x/18xx/43xx" depends on OF && (ARCH_LPC18XX || COMPILE_TEST)
drivers/i2c/busses/Makefile +1 -0
@@ -78,6 +78,7 @@ obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o obj-$(CONFIG_I2C_JZ4780) += i2c-jz4780.o obj-$(CONFIG_I2C_KEBA) += i2c-keba.o obj-$(CONFIG_I2C_KEMPLD) += i2c-kempld.o +obj-$(CONFIG_I2C_K1) += i2c-k1.o obj-$(CONFIG_I2C_LPC2K) += i2c-lpc2k.o obj-$(CONFIG_I2C_LS2X) += i2c-ls2x.o obj-$(CONFIG_I2C_MESON) += i2c-meson.o
drivers/i2c/busses/i2c-k1.c new file +694 -0
694 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v1 1/2] dt-bindings: i2c: spacemit: add support for K1 SoC
In reply to Troy MitchellQuoted 1 line · Troy Mitchell
The i2c of K1 supports fast-speed-mode and high-speed-mode,
s/i2c/I2C/
Quoted 18 lines
and supports FIFO transmission.
Signed-off-by Troy Mitchell <[email protected]>--- .../bindings/i2c/spacemit,k1-i2c.yaml | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yamlDocumentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml new file +4
-0@@ -0,0 +1,59 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/i2c/spacemit,k1-i2c.yaml#
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml line 14
Quoted 10 lines
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml new file +10
-0+$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: I2C controller embedded in SpacemiT's K1 SoC + +maintainers: + - Troy Mitchell <[email protected]> + +properties: + compatible: + const: spacemit,k1-i2c
There is no such vendor prefix.
Quoted 8 lines
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml new file +8
-0+ + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks:
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml line 32
Quoted 10 lines
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml new file +10
-0+ maxItems: 1 + + clock-frequency: + description: + Desired I2C bus clock frequency in Hz. As only fast and high-speed + modes are supported by hardware, possible values are 100000 and 400000. + enum: [100000, 400000] + default: 100000 + + fifo-disable:
Why is this a property of a board?
Also, missing vendor prefix.
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml line 38
Quoted 6 lines
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml new file +6
-0+ type: boolean + description: + Whether to disable FIFO. If FIFO is turned on, it will be interrupted + only when the FIFO depth is reached, which can reduce the frequency + of interruption. + default: false
Drop
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml line 40
Quoted 2 lines
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml new file +2
-0+ +unevaluatedProperties: false
This goes after required: block.
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml line 50
Quoted 10 lines
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml new file +10
-0+ +required: + - compatible + - reg + - interrupts + - clocks + +examples: + - | + i2c0: i2c@d4010800 {
Drop unused alias
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml line 51
Quoted 1 line
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml new file +1
-0+ compatible = "spacemit,k1-i2c";
Best regards,
Krzysztof
Re: [PATCH v1 2/2] i2c: spacemit: add support for SpacemiT K1 SoC
In reply to Troy MitchellQuoted 19 lines · Troy Mitchell
This patch introduces basic I2C support for the SpacemiT K1 SoC, utilizing interrupts for transfers.
The driver has been tested using i2c-tools on a Bananapi-F3 board, and basic I2C read/write operations have been confirmed to work.
Signed-off-by Troy Mitchell <[email protected]>--- drivers/i2c/busses/Kconfig | 18 + drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-k1.c | 694 ++++++++++++++++++++++++++++++++++++ 3 files changed, 713 insertions(+) create mode 100644 drivers/i2c/busses/i2c-k1.cdrivers/i2c/busses/Kconfig +0
-0
drivers/i2c/busses/Kconfig config I2C_KEMPLD · line 805
Quoted 6 lines
drivers/i2c/busses/Kconfig +3
-0@@ -800,6 +800,24 @@ config I2C_KEMPLD This driver can also be built as a module. If so, the module will be called i2c-kempld. +config I2C_K1 + tristate "Spacemit K1 I2C adapter" + depends on ARCH_SPACEMIT || COMPILE_TEST
There is no such thing as ARCH_SPACEMIT. You never mentioned any dependency.
Quoted 23 lines
drivers/i2c/busses/Kconfig +15
-0+ help + This option enables support for the I2C interface on the Spacemit K1 + platform. + + If you enable this configuration, the kernel will include support for + the I2C adapter specific to the Spacemit K1 platform. This driver ca + be used to manage I2C bus transactions, which are necessary for + interfacing with I2C peripherals such as sensors, EEPROMs, and other + devices. + + This driver can also be compiled as a module. If you choose to build + it as a module, the resulting kernel module will be named `i2c-k1`. + Loading this module will enable the I2C functionality for the K1 + platform dynamically, without requiring a rebuild of the kernel. + config I2C_LPC2K tristate "I2C bus support for NXP LPC2K/LPC178x/18xx/43xx" depends on OF && (ARCH_LPC18XX || COMPILE_TEST)drivers/i2c/busses/Makefile +0
-0
drivers/i2c/busses/Makefile obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o · line 81
Quoted 4 lines
drivers/i2c/busses/Makefile +1
-0@@ -78,6 +78,7 @@ obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o obj-$(CONFIG_I2C_JZ4780) += i2c-jz4780.o obj-$(CONFIG_I2C_KEBA) += i2c-keba.o obj-$(CONFIG_I2C_KEMPLD) += i2c-kempld.o +obj-$(CONFIG_I2C_K1) += i2c-k1.o
Are you sure you ordered it alphabetically? The same in Kconfig.
Quoted 13 lines
drivers/i2c/busses/Makefile +0
-0obj-$(CONFIG_I2C_LPC2K) += i2c-lpc2k.o obj-$(CONFIG_I2C_LS2X) += i2c-ls2x.o obj-$(CONFIG_I2C_MESON) += i2c-meson.odrivers/i2c/busses/i2c-k1.c new file +4
-0@@ -0,0 +1,694 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2024 Troy Mitchell <[email protected]> +*/
...
drivers/i2c/busses/i2c-k1.c line 158
Quoted 4 lines
drivers/i2c/busses/i2c-k1.c new file +4
-0+ +static inline u32 spacemit_i2c_read_reg (struct spacemit_i2c_dev *i2c,int reg) +{ +return readl (i2c->base + reg);
So basically short and obvious code like this:
readl(i2c->base + reg);
you replace with:
spacemit_i2c_read_reg(i2c, reg)
how is this helpful?
Quoted 40 lines
drivers/i2c/busses/i2c-k1.c new file +40
-0+} + +static inline void +spacemit_i2c_write_reg (struct spacemit_i2c_dev *i2c,int reg,u32 val) +{ +writel (val, i2c->base + reg); +} + +static void spacemit_i2c_enable (struct spacemit_i2c_dev *i2c) +{ +u32 val; + + val =spacemit_i2c_read_reg (i2c,ICR ); +spacemit_i2c_write_reg (i2c,ICR , val |CR_IUE ); +} + +static void spacemit_i2c_disable (struct spacemit_i2c_dev *i2c) +{ +u32 val; + + val =spacemit_i2c_read_reg (i2c,ICR ); + val &= ~CR_IUE ; +spacemit_i2c_write_reg (i2c,ICR , val); +} + +static void spacemit_i2c_reset (struct spacemit_i2c_dev *i2c) +{ +spacemit_i2c_write_reg (i2c,ICR ,CR_UR ); +udelay (5 ); +spacemit_i2c_write_reg (i2c,ICR ,0 ); +} + +static void spacemit_i2c_bus_reset (struct spacemit_i2c_dev *i2c) +{ +u32 status; + +/* if bus is locked, reset unit. 0: locked */ + status =spacemit_i2c_read_reg (i2c,IBMR ); + +if ((status &BMR_SDA ) && (status &BMR_SCL ))
drivers/i2c/busses/i2c-k1.c line 208
Quoted 10 lines
drivers/i2c/busses/i2c-k1.c new file +10
-0+return ; + +spacemit_i2c_reset (i2c); +usleep_range (10 ,20 ); + +/* check scl status again */ + status =spacemit_i2c_read_reg (i2c,IBMR ); + +if (!(status &BMR_SCL )) +dev_alert (i2c->dev,"unit reset failed\n" );
dev_warn_ratelimited
Quoted 7 lines
drivers/i2c/busses/i2c-k1.c new file +7
-0+} + +static int spacemit_i2c_recover_bus_busy (struct spacemit_i2c_dev *i2c) +{ +int ret =0 ; +u32 val; +
...
Quoted 11 lines
drivers/i2c/busses/i2c-k1.c new file +11
-0+static inline int spacemit_i2c_xfer_core (struct spacemit_i2c_dev *i2c) +{ +int ret =0 ; + +spacemit_i2c_reset (i2c); + +spacemit_i2c_calc_timeout (i2c); + +spacemit_i2c_init (i2c); + +spacemit_i2c_enable (i2c);
drivers/i2c/busses/i2c-k1.c line 555
Quoted 10 lines
drivers/i2c/busses/i2c-k1.c new file +10
-0+enable_irq (i2c->irq); + +/* i2c wait for bus busy */ + ret =spacemit_i2c_recover_bus_busy (i2c); + +if (unlikely (ret)) +return ret; + + ret =spacemit_i2c_xfer_msg (i2c); +
This coding style is poor... further on this in probe function.
Quoted 47 lines
drivers/i2c/busses/i2c-k1.c new file +47
-0+if (unlikely (ret <0 )) { +dev_dbg (i2c->dev,"i2c transfer error\n" ); +/* timeout error should not be overridden, and the transfer +* error will be confirmed by err handle function latter, +* the reset should be invalid argument error. +*/ +if (ret != -ETIMEDOUT ) + ret = -EINVAL ; + } + +return ret; +} + +static int +spacemit_i2c_xfer (struct i2c_adapter *adapt,struct i2c_msg msgs[],int num) +{ +struct spacemit_i2c_dev *i2c =i2c_get_adapdata (adapt); +int ret; + + i2c->msgs = msgs; + i2c->msg_num = num; + + ret =spacemit_i2c_xfer_core (i2c); + +if (likely (!ret)) +spacemit_i2c_check_bus_release (i2c); + +disable_irq (i2c->irq); + +spacemit_i2c_disable (i2c); + +if (unlikely ((ret == -ETIMEDOUT || ret == -EAGAIN ))) +dev_alert (i2c->dev,"i2c transfer failed, ret %d err 0x%x\n" , + ret, i2c->err); + +return ret <0 ? ret : num; +} + +static u32 spacemit_i2c_func (struct i2c_adapter *adap) +{ +return I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK ); +} + +static const struct i2c_algorithm spacemit_i2c_algo = { + .xfer = spacemit_i2c_xfer, + .functionality = spacemit_i2c_func, +};
drivers/i2c/busses/i2c-k1.c line 612
Quoted 10 lines
drivers/i2c/busses/i2c-k1.c new file +10
-0+ +static int spacemit_i2c_probe (struct platform_device *pdev) +{ +struct spacemit_i2c_dev *i2c; +struct device_node *of_node = pdev->dev.of_node; +struct clk *clk; +int ret =0 ; + + i2c = devm_kzalloc(&pdev->dev, + sizeof(struct spacemit_i2c_dev),
sizeof(*) and stop unnecessary wrapping.
drivers/i2c/busses/i2c-k1.c line 621
Quoted 9 lines
drivers/i2c/busses/i2c-k1.c new file +9
-0+ GFP_KERNEL); +if (!i2c) +return -ENOMEM ; + + i2c->dev = &pdev->dev; + + i2c->base =devm_platform_ioremap_resource (pdev,0 ); +if (!i2c->base) { + ret =PTR_ERR (i2c->base);
Drop
drivers/i2c/busses/i2c-k1.c line 622
Quoted 1 line
drivers/i2c/busses/i2c-k1.c new file +1
-0+return dev_err_probe (&pdev->dev, ret,"failed to do ioremap" );
Just use here PTR_ERR
drivers/i2c/busses/i2c-k1.c line 627
Quoted 5 lines
drivers/i2c/busses/i2c-k1.c new file +5
-0+ } + + i2c->irq =platform_get_irq (pdev,0 ); +if (i2c->irq <0 ) { + ret = i2c->irq;
Drop, really useless.
drivers/i2c/busses/i2c-k1.c line 635
Quoted 8 lines
drivers/i2c/busses/i2c-k1.c new file +8
-0+return dev_err_probe (&pdev->dev, ret,"failed to get irq resource" ); + } + + ret =devm_request_irq (i2c->dev, i2c->irq, + spacemit_i2c_irq_handler, +IRQF_NO_SUSPEND |IRQF_ONESHOT , +dev_name (i2c->dev), i2c); +
There is never a blank line between call and it's condition check if() statement.
drivers/i2c/busses/i2c-k1.c line 639
Quoted 4 lines
drivers/i2c/busses/i2c-k1.c new file +4
-0+if (ret) +return dev_err_probe (&pdev->dev, ret,"failed to request irq" ); + +disable_irq (i2c->irq);
Why?
drivers/i2c/busses/i2c-k1.c line 643
Quoted 4 lines
drivers/i2c/busses/i2c-k1.c new file +4
-0+ + clk =devm_clk_get_enabled (&pdev->dev,NULL ); +if (IS_ERR (clk)) { + ret =PTR_ERR (clk);
drop
Quoted 8 lines
drivers/i2c/busses/i2c-k1.c new file +8
-0+return dev_err_probe (&pdev->dev, ret,"failed to enable clock" ); + } + +i2c_set_adapdata (&i2c->adapt, i2c); + i2c->adapt.owner =THIS_MODULE ; + i2c->adapt.algo = &spacemit_i2c_algo; + i2c->adapt.dev.parent = i2c->dev; + i2c->adapt.nr = pdev->id;
drivers/i2c/busses/i2c-k1.c line 661
Quoted 10 lines
drivers/i2c/busses/i2c-k1.c new file +10
-0+ + i2c->adapt.dev.of_node = of_node; + i2c->adapt.algo_data = i2c; + +strscpy (i2c->adapt.name,"spacemit-i2c-adapter" ,sizeof (i2c->adapt.name)); + +init_completion (&i2c->complete); + + ret =i2c_add_numbered_adapter (&i2c->adapt); +
Drop stray blank line
Quoted 23 lines
drivers/i2c/busses/i2c-k1.c new file +23
-0+if (ret) +return dev_err_probe (&pdev->dev, ret,"failed to add i2c adapter" ); + +platform_set_drvdata (pdev, i2c); + +return 0 ; +} + +static void spacemit_i2c_remove (struct platform_device *pdev) +{ +struct spacemit_i2c_dev *i2c =platform_get_drvdata (pdev); + +i2c_del_adapter (&i2c->adapt); +} + +static const struct of_device_id spacemit_i2c_dt_match[] = { + { .compatible ="spacemit,k1-i2c" , }, + {/* sentinel */ } +}; +MODULE_DEVICE_TABLE (of, spacemit_i2c_dt_match); + +static struct platform_driver spacemit_i2c_driver = { + .probe = spacemit_i2c_probe,
drivers/i2c/busses/i2c-k1.c line 694
Quoted 10 lines
drivers/i2c/busses/i2c-k1.c new file +10
-0+ .remove_new = spacemit_i2c_remove, + .driver = { + .name = "i2c-k1", + .of_match_table = spacemit_i2c_dt_match, + }, +}; +module_platform_driver (spacemit_i2c_driver); + +MODULE_LICENSE ("GPL" ); +MODULE_DESCRIPTION ("I2C bus driver for SpacemiT K1 SoC" );
Best regards,
Krzysztof
Re: [PATCH v1 2/2] i2c: spacemit: add support for SpacemiT K1 SoC
In reply to Troy Mitchelldrivers/i2c/busses/i2c-k1.c line 21
Quoted 10 lines
drivers/i2c/busses/i2c-k1.c new file +9
-0+/* spacemit i2c registers */ +#define ICR 0x0/* Control Register */ +#define ISR 0x4/* Status Register */ +#define ISAR 0x8/* Slave Address Register */ +#define IDBR 0xc/* Data Buffer Register */ +#define ILCR 0x10/* Load Count Register */ +#define IWCR 0x14/* Wait Count Register */ +#define IRST_CYC 0x18/* Bus reset cycle counter */ +#define IBMR 0x1c/* Bus monitor register */
These registers look a lot like the ones for i2c-pxa. Can the pxa driver maybe be re-used for your I2C core?
Re: [PATCH v1 2/2] i2c: spacemit: add support for SpacemiT K1 SoC
In reply to Krzysztof KozlowskiQuoted 7 lines
drivers/i2c/busses/i2c-k1.c line 158
Quoted 4 lines
drivers/i2c/busses/i2c-k1.c new file +3
-0+static inline u32 spacemit_i2c_read_reg (struct spacemit_i2c_dev *i2c,int reg) +{ +return readl (i2c->base + reg);So basically short and obvious code like this:
Quoted 7 lines
readl(i2c->base + reg);you replace with:
spacemit_i2c_read_reg(i2c, reg)how is this helpful?
I always have the same question when I see this. However, I don't blame Troy. We have quite some occurances of this in the kernel, so I wouldn't be surprised if people think this is a kernel-style-pattern :/
Rob Herring (Arm)
maintainerRe: [PATCH v1 1/2] dt-bindings: i2c: spacemit: add support for K1 SoC
In reply to Troy MitchellQuoted 9 lines · Troy Mitchell
The i2c of K1 supports fast-speed-mode and high-speed-mode, and supports FIFO transmission.
Signed-off-by Troy Mitchell <[email protected]>--- .../bindings/i2c/spacemit,k1-i2c.yaml | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml
My bot found errors running 'make dt_binding_check' on your patch:
yamllint warnings/errors:
dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.example.dtb: i2c@d4010800: reg: [[0, 3556837376], [0, 56]] is too long
from schema $id: http://devicetree.org/schemas/i2c/spacemit,k1-i2c.yaml#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.example.dtb: i2c@d4010800: Unevaluated properties are not allowed ('reg' was unexpected)
from schema $id: http://devicetree.org/schemas/i2c/spacemit,k1-i2c.yaml#
doc reference errors (make refcheckdocs):
See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]
The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.
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 after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.
Re: [PATCH v1 1/2] dt-bindings: i2c: spacemit: add support for K1 SoC
In reply to Krzysztof KozlowskiQuoted 27 lines · Krzysztof Kozlowski
Quoted 1 line · Troy Mitchell
The i2c of K1 supports fast-speed-mode and high-speed-mode,
s/i2c/I2C/
Quoted 22 lines
and supports FIFO transmission.
Signed-off-by Troy Mitchell <[email protected]>--- .../bindings/i2c/spacemit,k1-i2c.yaml | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yamlDocumentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml new file +8
-0@@ -0,0 +1,59 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/i2c/spacemit,k1-i2c.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: I2C controller embedded in SpacemiT's K1 SoC +
Quoted 8 lines
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml line 14
Quoted 6 lines
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml new file +6
-0+maintainers: + - Troy Mitchell <[email protected]> + +properties: + compatible: + const: spacemit,k1-i2cThere is no such vendor prefix.
7cf3e9bfc63db ("dt-bindings: vendor-prefixes: add spacemit") will be in tomorrow's next.
Re: [PATCH v1 2/2] i2c: spacemit: add support for SpacemiT K1 SoC
In reply to Wolfram SangQuoted 14 lines · Wolfram Sang
drivers/i2c/busses/i2c-k1.c line 21
Quoted 10 lines
drivers/i2c/busses/i2c-k1.c new file +9
-0+/* spacemit i2c registers */ +#define ICR 0x0/* Control Register */ +#define ISR 0x4/* Status Register */ +#define ISAR 0x8/* Slave Address Register */ +#define IDBR 0xc/* Data Buffer Register */ +#define ILCR 0x10/* Load Count Register */ +#define IWCR 0x14/* Wait Count Register */ +#define IRST_CYC 0x18/* Bus reset cycle counter */ +#define IBMR 0x1c/* Bus monitor register */ These registers look a lot like the ones for i2c-pxa. Can the pxa driver maybe be re-used for your I2C core?
Only a small number of bit definitions in the registers are the same [1]. Even if the logic is roughly the same. it still takes a lot of work, and i2c-pxa cannot easily add the fifo and dma functions that k1 has. Just my opinion, I don't think it's worth it.
of course, if you think that multiplexing i2c-pxa is a better decision. I'd be happy to adopt it
Re: [PATCH v1 1/2] dt-bindings: i2c: spacemit: add support for K1 SoC
In reply to Krzysztof KozlowskiQuoted 60 lines · Krzysztof Kozlowski
Quoted 1 line · Troy Mitchell
The i2c of K1 supports fast-speed-mode and high-speed-mode,
s/i2c/I2C/
Quoted 18 lines
and supports FIFO transmission.
Signed-off-by Troy Mitchell <[email protected]>--- .../bindings/i2c/spacemit,k1-i2c.yaml | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yamlDocumentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml new file +4
-0@@ -0,0 +1,59 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/i2c/spacemit,k1-i2c.yaml#Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml line 14
Quoted 10 lines
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml new file +10
-0+$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: I2C controller embedded in SpacemiT's K1 SoC + +maintainers: + - Troy Mitchell <[email protected]> + +properties: + compatible: + const: spacemit,k1-i2cThere is no such vendor prefix.
Quoted 8 lines
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml new file +8
-0+ + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks:Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml line 32
Quoted 10 lines
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml new file +10
-0+ maxItems: 1 + + clock-frequency: + description: + Desired I2C bus clock frequency in Hz. As only fast and high-speed + modes are supported by hardware, possible values are 100000 and 400000. + enum: [100000, 400000] + default: 100000 + + fifo-disable:Why is this a property of a board?
Also, missing vendor prefix.
Quoted 8 lines
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml line 38
Quoted 6 lines
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml new file +6
-0+ type: boolean + description: + Whether to disable FIFO. If FIFO is turned on, it will be interrupted + only when the FIFO depth is reached, which can reduce the frequency + of interruption. + default: falseDrop
It's a hardware FIFO instead of software.
Is it unnecessary in this file?
If is, why dma can be written in dt-binding.
Quoted 20 lines
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml line 40
Quoted 3 lines
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml new file +2
-0+ +unevaluatedProperties: falseThis goes after required: block.
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml line 50
Quoted 10 lines
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml new file +10
-0+ +required: + - compatible + - reg + - interrupts + - clocks + +examples: + - | + i2c0: i2c@d4010800 {Drop unused alias
Quoted 5 lines
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml line 51
Quoted 1 line
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml new file +1
-0+ compatible = "spacemit,k1-i2c";Best regards,
Krzysztof
Best regards,
Troy
Re: [PATCH v1 2/2] i2c: spacemit: add support for SpacemiT K1 SoC
In reply to Troy MitchellQuoted 2 lines
Only a small number of bit definitions in the registers are the same [1].
Oh my gosh, looks like a RNG was tested when shuffling these bits around :/ I agree now, combining this into the existing PXA driver will not only be quite some work, it will also make the code quite unreadable and has a high chance of introducing regressions for a number of platforms which are not easy to test these days. Sigh...
Quoted 1 line
Thanks for this link!
Re: [PATCH v1 1/2] dt-bindings: i2c: spacemit: add support for K1 SoC
In reply to Troy MitchellQuoted 11 lines · Troy Mitchell
Quoted 11 lines
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml line 32
Quoted 9 lines
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml new file +9
-0+ + clock-frequency: + description: + Desired I2C bus clock frequency in Hz. As only fast and high-speed + modes are supported by hardware, possible values are 100000 and 400000. + enum: [100000, 400000] + default: 100000 + + fifo-disable:Why is this a property of a board?
Here, this ^^^^^^
Quoted 11 lines
Quoted 11 lines
Also, missing vendor prefix.
Quoted 6 lines
Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml new file +6
-0+ type: boolean + description: + Whether to disable FIFO. If FIFO is turned on, it will be interrupted + only when the FIFO depth is reached, which can reduce the frequency + of interruption. + default: false
Quoted 5 lines
Quoted 1 line
Drop
It's a hardware FIFO instead of software.
Is it unnecessary in this file?
If is, why dma can be written in dt-binding.
Because of what I asked earlier. Which 'dma' property are you asking about? 'use-dma'? There was rationale provided in favor. I would be more than happy to see similar rationale here.
Best regards,
Krzysztof
Re: [PATCH v1 2/2] i2c: spacemit: add support for SpacemiT K1 SoC
In reply to Troy MitchellHello,
drivers/i2c/busses/i2c-k1.c line 690
Quoted 8 lines · Troy Mitchell
drivers/i2c/busses/i2c-k1.c new file +8
-0+static struct platform_driver spacemit_i2c_driver = { + .probe = spacemit_i2c_probe, + .remove_new = spacemit_i2c_remove, + .driver = { + .name ="i2c-k1" , + .of_match_table = spacemit_i2c_dt_match, + }, +};
After commit 0edb555a65d1 ("platform: Make platform_driver::remove() return void") .remove() is (again) the right callback to implement for platform drivers. Please just drop "_new".
Best regards
Uwe
Re: [PATCH v1 2/2] i2c: spacemit: add support for SpacemiT K1 SoC
In reply to Krzysztof KozlowskiQuoted 2 lines · Krzysztof Kozlowski
Review
Quoted 1 line
(quoted diff) +1
-0+ disable_irq(i2c->irq);Why?
I just want to turn on the interrupt when the transmission starts, and turn off the interrupt after the transmission ends. The interrupt shutdown in the probe is a starting point before the transmission starts.
Is this reasonable? If not, I will modify it.
Re: [PATCH v1 2/2] i2c: spacemit: add support for SpacemiT K1 SoC
Quoted 11 lines · Troy Mitchell
Quoted 2 lines · Krzysztof Kozlowski
Review
Quoted 1 line
(quoted diff) +1
-0+ disable_irq(i2c->irq);Why?
I just want to turn on the interrupt when the transmission starts, and turn off the interrupt after the transmission ends. The interrupt shutdown in the probe is a starting point before the transmission starts.
Is this reasonable? If not, I will modify it.
You cut so much context I don't know what this refers to. I will leave it to I2C maintainers, but toggling interrupt on probe is weird. Toggling it for every transfer as well.
Best regards,
Krzysztof
Re: [PATCH v1 2/2] i2c: spacemit: add support for SpacemiT K1 SoC
Quoted 11 lines · Krzysztof Kozlowski
Quoted 10 lines · Troy Mitchell
Quoted 2 lines · Krzysztof Kozlowski
Review
Quoted 1 line
(quoted diff) +1
-0+ disable_irq(i2c->irq);Why?
I just want to turn on the interrupt when the transmission starts, and turn off the interrupt after the transmission ends. The interrupt shutdown in the probe is a starting point before the transmission starts.
Quoted 9 lines
Quoted 1 line
Is this reasonable? If not, I will modify it.
You cut so much context I don't know what this refers to. I will leave it to I2C maintainers, but toggling interrupt on probe is weird. Toggling it for every transfer as well.
Best regards,
Krzysztof
In addition to this problem, should I send v2 after I fix all the errors pointed out in the email, or should I wait for I2C maintainers?
Re: [PATCH v1 2/2] i2c: spacemit: add support for SpacemiT K1 SoC
Quoted 19 lines · Troy Mitchell
Quoted 17 lines · Krzysztof Kozlowski
Quoted 11 lines · Troy Mitchell
Quoted 2 lines · Krzysztof Kozlowski
Review
Quoted 1 line
(quoted diff) +1
-0+ disable_irq(i2c->irq);Why?
I just want to turn on the interrupt when the transmission starts, and turn off the interrupt after the transmission ends. The interrupt shutdown in the probe is a starting point before the transmission starts.
Is this reasonable? If not, I will modify it.
You cut so much context I don't know what this refers to. I will leave it to I2C maintainers, but toggling interrupt on probe is weird. Toggling it for every transfer as well.
Quoted 7 lines
Quoted 3 lines
Best regards,
KrzysztofIn addition to this problem, should I send v2 after I fix all the errors pointed out in the email, or should I wait for I2C maintainers?
I think you got reviews from them, so I would go ahead with v2.
Best regards,
Krzysztof
Re: [PATCH v1 2/2] i2c: spacemit: add support for SpacemiT K1 SoC
In reply to Troy MitchellHi Troy,
kernel test robot noticed the following build warnings:
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Troy-Mitchell/dt-bindings-i2c-spacemit-add-support-for-K1-SoC/20241015-155402 base: https://git.kernel.org/pub/scm/linux/kernel/git/andi.shyti/linux.git i2c/i2c-host patch link: https://lore.kernel.org/r/20241015075134.1449458-3-TroyMitchell988%40gmail.com patch subject: [PATCH v1 2/2] i2c: spacemit: add support for SpacemiT K1 SoC config: alpha-randconfig-r071-20241019 (https://download.01.org/0day-ci/archive/20241019/[email protected]/config) compiler: alpha-linux-gcc (GCC) 13.3.0
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]> | Reported-by: Dan Carpenter <[email protected]> | Closes: https://lore.kernel.org/r/[email protected]/
smatch warnings:drivers/i2c/busses/i2c-k1.c:621 spacemit_i2c_probe() warn: passing zero to 'PTR_ERR' drivers/i2c/busses/i2c-k1.c:622 spacemit_i2c_probe() warn: passing zero to 'dev_err_probe'
vim +/PTR_ERR +621 drivers/i2c/busses/i2c-k1.c
aede17b17b7dfb Troy Mitchell 2024-10-15 604 static int spacemit_i2c_probe(struct platform_device *pdev)
aede17b17b7dfb Troy Mitchell 2024-10-15 605 {
aede17b17b7dfb Troy Mitchell 2024-10-15 606 struct spacemit_i2c_dev *i2c;
aede17b17b7dfb Troy Mitchell 2024-10-15 607 struct device_node *of_node = pdev->dev.of_node;
aede17b17b7dfb Troy Mitchell 2024-10-15 608 struct clk *clk;
aede17b17b7dfb Troy Mitchell 2024-10-15 609 int ret = 0;
aede17b17b7dfb Troy Mitchell 2024-10-15 610
aede17b17b7dfb Troy Mitchell 2024-10-15 611 i2c = devm_kzalloc(&pdev->dev,
aede17b17b7dfb Troy Mitchell 2024-10-15 612 sizeof(struct spacemit_i2c_dev),
aede17b17b7dfb Troy Mitchell 2024-10-15 613 GFP_KERNEL);
aede17b17b7dfb Troy Mitchell 2024-10-15 614 if (!i2c)
aede17b17b7dfb Troy Mitchell 2024-10-15 615 return -ENOMEM;
aede17b17b7dfb Troy Mitchell 2024-10-15 616
aede17b17b7dfb Troy Mitchell 2024-10-15 617 i2c->dev = &pdev->dev;
aede17b17b7dfb Troy Mitchell 2024-10-15 618
aede17b17b7dfb Troy Mitchell 2024-10-15 619 i2c->base = devm_platform_ioremap_resource(pdev, 0);
aede17b17b7dfb Troy Mitchell 2024-10-15 620 if (!i2c->base) {This should be if (IS_ERR(i2c->base)) {
aede17b17b7dfb Troy Mitchell 2024-10-15 @621 ret = PTR_ERR(i2c->base);
aede17b17b7dfb Troy Mitchell 2024-10-15 @622 return dev_err_probe(&pdev->dev, ret, "failed to do ioremap");
aede17b17b7dfb Troy Mitchell 2024-10-15 623 }
aede17b17b7dfb Troy Mitchell 2024-10-15 624
aede17b17b7dfb Troy Mitchell 2024-10-15 625 i2c->irq = platform_get_irq(pdev, 0);
aede17b17b7dfb Troy Mitchell 2024-10-15 626 if (i2c->irq < 0) {
aede17b17b7dfb Troy Mitchell 2024-10-15 627 ret = i2c->irq;
aede17b17b7dfb Troy Mitchell 2024-10-15 628 return dev_err_probe(&pdev->dev, ret, "failed to get irq resource");
aede17b17b7dfb Troy Mitchell 2024-10-15 629 }
aede17b17b7dfb Troy Mitchell 2024-10-15 630
aede17b17b7dfb Troy Mitchell 2024-10-15 631 ret = devm_request_irq(i2c->dev, i2c->irq,
aede17b17b7dfb Troy Mitchell 2024-10-15 632 spacemit_i2c_irq_handler,
aede17b17b7dfb Troy Mitchell 2024-10-15 633 IRQF_NO_SUSPEND | IRQF_ONESHOT,
aede17b17b7dfb Troy Mitchell 2024-10-15 634 dev_name(i2c->dev), i2c);
aede17b17b7dfb Troy Mitchell 2024-10-15 635
aede17b17b7dfb Troy Mitchell 2024-10-15 636 if (ret)
aede17b17b7dfb Troy Mitchell 2024-10-15 637 return dev_err_probe(&pdev->dev, ret, "failed to request irq");Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki