i2c: npcm7xx: new driver for I2C controller
Tali Perry
maintainercover i2c: npcm7xx: new driver for I2C controller
Nuvoton NPCM7XX I2C Controller
NPCM7xx includes 16 I2C contollers. THis driver operates the controller. This module also includes a slave mode, which will be submitted later on.
Any feedback would be appreciated.
---
Tali Perry (2):
dt-binding: i2c: npcm7xx: add binding for i2c controller
i2c: npcm7xx: add i2c controller master mode only
.../devicetree/bindings/i2c/i2c-npcm7xx.txt | 27 + MAINTAINERS | 9 + drivers/i2c/busses/Kconfig | 11 + drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-npcm7xx.c | 2574 ++++++++++++++++++++ 5 files changed, 2622 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/i2c-npcm7xx.txt create mode 100644 drivers/i2c/busses/i2c-npcm7xx.c
Signature · 1 line
2.14.1
Tali Perry
maintainerPATCH 1/2 dt-binding: i2c: npcm7xx: add binding for i2c
Nuvoton NPCM7XX I2C Controller
NPCM7xx includes 16 I2C contollers. This driver operates the controller. This module also includes a slave mode, which will be submitted later on.
Any feedback would be appreciated.
--- .../devicetree/bindings/i2c/i2c-npcm7xx.txt | 27 ++++++++++++++++++++++ MAINTAINERS | 9 ++++++++ 2 files changed, 36 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/i2c-npcm7xx.txt
Documentation/devicetree/bindings/i2c/i2c-npcm7xx.txt new file +27 -0
@@ -0,0 +1,27 @@ +Nuvoton NPCM7XX I2C bus + +The NPCM750x includes sixteen I2C busses + +Required properties: +- compatible : must be "nuvoton,npcm750-i2c-bus" +- reg : Offset and length of the register set for the device. +- interrupts : Contain the I2C interrupt with flags for falling edge. +- clocks : phandle of I2C reference clock. + +Optional: +- bus-frequency : Contain the I2C bus frequency, + the default I2C bus frequency is 100000. +- pinctrl-0 : must be <&smbX_pins>, X is module number + (on NPCM7XX it's 0 to 15) +- pinctrl-names : should be set to "default" +Example: + + i2c0: i2c-bus@80000 { + compatible = "nuvoton,npcm750-i2c-bus"; + reg = <0x80000 0x1000>; + clocks = <&clk NPCM7XX_CLK_APB2>; + bus-frequency = <100000>; + interrupts = <GIC_SPI 64 IRQ_TYPE_LEVEL_HIGH>; + pinctrl-names = "default"; + pinctrl-0 = <&smb0_pins>; + };
MAINTAINERS +9 -0
@@ -1735,6 +1735,15 @@ F: drivers/*/*npcm* F: Documentation/devicetree/bindings/*/*npcm* F: Documentation/devicetree/bindings/*/*/*npcm* +ARM/NUVOTON I2C DRIVER +M: Tali Perry <[email protected]> +M: Avi Fishman <[email protected]> +L: [email protected] +L: [email protected] (moderated for non-subscribers) +S: Supported +F: drivers/i2c/busses/i2c-npcm7xx.c +F: Documentation/devicetree/bindings/i2c/i2c-npcm7xx.txt + ARM/NUVOTON W90X900 ARM ARCHITECTURE M: Wan ZongShun <[email protected]> L: [email protected] (moderated for non-subscribers)
Signature · 1 line
2.14.1
Tali Perry
maintainerPATCH 2/2 i2c: npcm7xx: add i2c controller master mode only
In reply to Tali PerryNuvoton NPCM7XX I2C Controller
NPCM7xx includes 16 I2C contollers. THis driver operates the controller. This module also includes a slave mode, which will be submitted later on.
Any feedback would be appreciated.
--- drivers/i2c/busses/Kconfig | 11 + drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-npcm7xx.c | 2574 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 2586 insertions(+) create mode 100644 drivers/i2c/busses/i2c-npcm7xx.c
drivers/i2c/busses/Kconfig +11 -0
@@ -742,6 +742,17 @@ config I2C_NOMADIK I2C interface from ST-Ericsson's Nomadik and Ux500 architectures, as well as the STA2X11 PCIe I/O HUB. +config I2C_NPCM7XX + tristate "Nuvoton I2C Controller" + depends on ARCH_NPCM7XX + select I2C_SLAVE + help + If you say yes to this option, support will be included for the + Nuvoton I2C controller. + + This driver can also be built as a module. If so, the module + will be called i2c-npcm7xx. + config I2C_OCORES tristate "OpenCores I2C Controller" help
drivers/i2c/busses/Makefile +1 -0
@@ -74,6 +74,7 @@ obj-$(CONFIG_I2C_MT65XX) += i2c-mt65xx.o obj-$(CONFIG_I2C_MV64XXX) += i2c-mv64xxx.o obj-$(CONFIG_I2C_MXS) += i2c-mxs.o obj-$(CONFIG_I2C_NOMADIK) += i2c-nomadik.o +obj-$(CONFIG_I2C_NPCM7XX) += i2c-npcm7xx.o obj-$(CONFIG_I2C_OCORES) += i2c-ocores.o obj-$(CONFIG_I2C_OMAP) += i2c-omap.o obj-$(CONFIG_I2C_PASEMI) += i2c-pasemi.o
drivers/i2c/busses/i2c-npcm7xx.c new file +2574 -0
2,574 lines not on this page · raw message
Signature · 1 line
2.14.1
Re: [PATCH v1 2/2] i2c: npcm7xx: add i2c controller master mode only
Quoted 5 lines · Tali Perry
Nuvoton NPCM7XX I2C Controller
NPCM7xx includes 16 I2C contollers. THis driver operates the controller. This module also includes a slave mode, which will be submitted later on.Any feedback would be appreciated.
Too much lines of code as for I2C driver.
Briefly looking it seems it doesn't utilize what kernel already has (e.g. crc8 already is in kernel library) and doesn't follow modern style of drivers there.
Quoted 23 lines
drivers/i2c/busses/i2c-npcm7xx.c new file +23
-0+#include <linux/kernel.h> +#include <linux/clk.h> +#include <linux/jiffies.h> +#include <linux/completion.h> +#include <linux/err.h> +#include <linux/errno.h> +#include <linux/i2c.h> +#include <linux/init.h> +#include <linux/delay.h> + +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/irq.h> +#include <linux/irqchip/chained_irq.h> +#include <linux/irqdomain.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/delay.h> +#include <linux/of_address.h> +#include <linux/of_irq.h> +#include <linux/of_platform.h> +#include <linux/platform_device.h> +#include <linux/slab.h>
drivers/i2c/busses/i2c-npcm7xx.c line 40
Quoted 10 lines
drivers/i2c/busses/i2c-npcm7xx.c new file +10
-0+#include <linux/clk/nuvoton.h> +#include <linux/bitops.h> +#include <linux/bitfield.h> + +#include <linux/of.h> +#include <linux/of_device.h> +#include <linux/dma-mapping.h> + +#include <linux/regmap.h> +#include <linux/mfd/syscon.h>
Just wow. Are you sure you need all of them? (Also, to see better what it's used, keep them in order)
drivers/i2c/busses/i2c-npcm7xx.c line 53
Quoted 2 lines
drivers/i2c/busses/i2c-npcm7xx.c new file +2
-0+#define ENABLE 1 +#define DISABLE 0
So, what's wrong with 1, 0 or true, false?
drivers/i2c/busses/i2c-npcm7xx.c line 58
Quoted 4 lines
drivers/i2c/busses/i2c-npcm7xx.c new file +4
-0+#define _1Hz_ (u32)1UL +#define _1KHz_ (1000 * _1Hz_) +#define _1MHz_ (1000 * _1KHz_) +#define _1GHz_ (1000 * _1MHz_)
If you need such constants it would be something like for time periods we have
HZ_PER_KHZ 1000HZ_PER_MHZ 1000000
etc.
I saw in a code some of those predefined. If they are not yet generic (in scope of kernel) it might be worth to do in the future.
drivers/i2c/busses/i2c-npcm7xx.c line 66
Quoted 7 lines
drivers/i2c/busses/i2c-npcm7xx.c new file +7
-0+#ifndef ASSERT +#ifdef DEBUG +#define ASSERT (cond) {if (!(cond)) for (;;) ; } +#else +#define ASSERT (cond) +#endif +#endif
Hmm... In production code?!
drivers/i2c/busses/i2c-npcm7xx.c line 69
Quoted 3 lines
drivers/i2c/busses/i2c-npcm7xx.c new file +3
-0+ +#define ROUND_UP (val, n) (((val)+(n)-1) & ~((n)-1)) +#define DIV_CEILING (a, b) (((a) + ((b)-1)) / (b))
You really need to check what kernel provides.
Quoted 1 line
+#define
I2C_DEBUG2(f, x...)
???
drivers/i2c/busses/i2c-npcm7xx.c line 38
Quoted 4 lines
drivers/i2c/busses/i2c-npcm7xx.c new file +4
-0+ + + +
Why to have so many blank lines?
Review
Quoted 2 lines
(quoted diff) +2
-0+ +
Ditto.
drivers/i2c/busses/i2c-npcm7xx.c line 178
Quoted 12 lines
drivers/i2c/busses/i2c-npcm7xx.c new file +12
-0+// Common regs +#define NPCM7XX_SMBSDA (bus) (bus->base + 0x000) +#define NPCM7XX_SMBST (bus) (bus->base + 0x002) +#define NPCM7XX_SMBCST (bus) (bus->base + 0x004) +#define NPCM7XX_SMBCTL1 (bus) (bus->base + 0x006) +#define NPCM7XX_SMBADDR1 (bus) (bus->base + 0x008) +#define NPCM7XX_SMBCTL2 (bus) (bus->base + 0x00A) +#define NPCM7XX_SMBADDR2 (bus) (bus->base + 0x00C) +#define NPCM7XX_SMBCTL3 (bus) (bus->base + 0x00E) +#define NPCM7XX_SMBCST2 (bus) (bus->base + 0x018) // Control Status 2 +#define NPCM7XX_SMBCST3 (bus) (bus->base + 0x019) // Control Status 3 +#define SMB_VER (bus) (bus->base + 0x01F) // SMB Version reg
Usually we put just numbers here and use custom I/O accessors which take bus as a parameter.
Quoted 4 lines
drivers/i2c/busses/i2c-npcm7xx.c new file +4
-0+ +// BANK 0 regs +#define NPCM7XX_SMBADDR3 (bus) (bus->base + 0x010) +#define NPCM7XX_SMBADDR7 (bus) (bus->base + 0x011)
drivers/i2c/busses/i2c-npcm7xx.c line 191
Quoted 10 lines
drivers/i2c/busses/i2c-npcm7xx.c new file +9
-0+#define NPCM7XX_SMBADDR4 (bus) (bus->base + 0x012) +#define NPCM7XX_SMBADDR8 (bus) (bus->base + 0x013) +#define NPCM7XX_SMBADDR5 (bus) (bus->base + 0x014) +#define NPCM7XX_SMBADDR9 (bus) (bus->base + 0x015) +#define NPCM7XX_SMBADDR6 (bus) (bus->base + 0x016) +#define NPCM7XX_SMBADDR10 (bus) (bus->base + 0x017) +#define NPCM7XX_SMBADDR (bus, i) (bus->base + 0x008 + \ + (u32)(((int)i * 4) + (((int)i < 2) ? 0 : \ + ((int)i - 2)*(-2)) + (((int)i < 6) ? 0 : (-7))))
It's rather complicated.
Quoted 1 line
+ // Current state of SMBus
I guess more compact is to put a kernel doc descriprion.
Review
Quoted 5 lines
(quoted diff) +3
-0+ enum smb_state state; +static bool NPCM7XX_smb_init_module(struct NPCM7XX_i2c *bus, + enum smb_mode mode, u16 bus_freq);
Do you need all forward declarations? Why?
So, I stopped here.
Try to make your code twice less in a lenght (looking at it I think it's doable).
drivers/i2c/busses/i2c-npcm7xx.c line 2556
Quoted 4 lines
drivers/i2c/busses/i2c-npcm7xx.c new file +3
-0+static const struct of_device_id NPCM7XX_i2c_bus_of_table[] = { + { .compatible ="nuvoton,npcm750-i2c-bus" , }, + {},
Slightly better without comma for terminator lines.
Quoted 2 lines
drivers/i2c/busses/i2c-npcm7xx.c new file +2
-0+}; +MODULE_DEVICE_TABLE (of, NPCM7XX_i2c_bus_of_table);
Signature · 2 lines
With Best Regards, Andy Shevchenko