Re: [OpenWrt-Devel] [PATCH 2/2] ralink: MT7621 add i2c controller driver on linux kernel 3.18

2015-03-21 Thread John Crispin
Hi,

please see comments inline. also please the checkpatch.pl script on this
patch before sending a V2

John

On 21/03/2015 06:06, wengbj wrote:
 ralink i2c driver is not working on MT7621 platform. Porting a new drivers 
 from MTK's source code.
 
 Signed-off-by: wengbj fl.serv...@t-firefly.com
 ---
  .../0111-i2c-MIPS-add-mt7621-I2C-driver.patch  |  390 
 
  1 file changed, 390 insertions(+)
  create mode 100755 
 target/linux/ramips/patches-3.18/0111-i2c-MIPS-add-mt7621-I2C-driver.patch
 
 diff --git 
 a/target/linux/ramips/patches-3.18/0111-i2c-MIPS-add-mt7621-I2C-driver.patch 
 b/target/linux/ramips/patches-3.18/0111-i2c-MIPS-add-mt7621-I2C-driver.patch
 new file mode 100755
 index 000..ec897ee
 --- /dev/null
 +++ 
 b/target/linux/ramips/patches-3.18/0111-i2c-MIPS-add-mt7621-I2C-driver.patch
 @@ -0,0 +1,390 @@
 +Index: linux-3.18.9/drivers/i2c/busses/Kconfig
 +===
 +--- linux-3.18.9.orig/drivers/i2c/busses/Kconfig 2015-03-21 
 11:47:27.387652879 +0800
  linux-3.18.9/drivers/i2c/busses/Kconfig  2015-03-21 11:47:27.587652870 
 +0800
 +@@ -714,6 +714,10 @@
 + tristate Ralink I2C Controller
 + select OF_I2C
 + 
 ++config I2C_MT7621
 ++tristate Mt7621 I2C Controller
 ++select OF_I2C
 ++
 + config HAVE_S3C2410_I2C
 + bool
 + help
 +Index: linux-3.18.9/drivers/i2c/busses/Makefile
 +===
 +--- linux-3.18.9.orig/drivers/i2c/busses/Makefile2015-03-21 
 11:47:27.387652879 +0800
  linux-3.18.9/drivers/i2c/busses/Makefile 2015-03-21 11:47:27.587652870 
 +0800
 +@@ -67,6 +67,7 @@
 + obj-$(CONFIG_I2C_PXA)   += i2c-pxa.o
 + obj-$(CONFIG_I2C_PXA_PCI)   += i2c-pxa-pci.o
 + obj-$(CONFIG_I2C_RALINK)+= i2c-ralink.o
 ++obj-$(CONFIG_I2C_MT7621)+= i2c-mt7621.o
 + obj-$(CONFIG_I2C_QUP)   += i2c-qup.o
 + obj-$(CONFIG_I2C_RIIC)  += i2c-riic.o
 + obj-$(CONFIG_I2C_RK3X)  += i2c-rk3x.o
 +Index: linux-3.18.9/drivers/i2c/busses/i2c-mt7621.c
 +===
 +--- /dev/null1970-01-01 00:00:00.0 +
  linux-3.18.9/drivers/i2c/busses/i2c-mt7621.c 2015-03-21 
 11:48:58.883648615 +0800
 +@@ -0,0 +1,358 @@
 ++/*
 ++ * drivers/i2c/busses/i2c-mt7621.c
 ++ *
 ++ * Copyright (C) 2013 Steven Liu steven_...@mediatek.com
 ++ *
 ++ * Improve driver for i2cdetect from i2c-tools to detect i2c devices on the 
 bus.
 ++ * (C) 2014 Sittisak sittis...@hotmail.com
 ++ *
 ++ * This software is licensed under the terms of the GNU General Public
 ++ * License version 2, as published by the Free Software Foundation, and
 ++ * may be copied, distributed, and modified under those terms.
 ++ *
 ++ * This program is distributed in the hope that it will be useful,
 ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ++ * GNU General Public License for more details.
 ++ *
 ++ */
 ++
 ++#include linux/interrupt.h
 ++#include linux/kernel.h
 ++#include linux/module.h
 ++#include linux/reset.h
 ++#include linux/delay.h
 ++#include linux/slab.h
 ++#include linux/init.h
 ++#include linux/errno.h
 ++#include linux/platform_device.h
 ++#include linux/i2c.h
 ++#include linux/io.h
 ++#include linux/err.h
 ++
 ++#include asm/mach-ralink/ralink_regs.h
 ++
 ++#define REG_CONFIG_REG   0x00
 ++#define REG_CLKDIV_REG   0x04
 ++#define REG_DEVADDR_REG  0x08
 ++#define REG_ADDR_REG 0x0C
 ++#define REG_DATAOUT_REG  0x10
 ++#define REG_DATAIN_REG   0x14
 ++#define REG_STATUS_REG   0x18
 ++#define REG_STARTXFR_REG 0x1C
 ++#define REG_BYTECNT_REG  0x20
 ++#define REG_SM0_IS_AUTOMODE  0x28
 ++#define REG_SM0CTL0  0x40
 ++
 ++
 ++#define I2C_STARTERR 0x10
 ++#define I2C_ACKERR   0x08
 ++#define I2C_DATARDY  0x04
 ++#define I2C_SDOEMPTY 0x02
 ++#define I2C_BUSY 0x01
 ++
 ++/* I2C_CFG register bit field */
 ++#define I2C_CFG_ADDRLEN_8(75) /* 8 bits */
 ++#define I2C_CFG_DEVADLEN_7   (62)
 ++#define I2C_CFG_ADDRDIS  (11)
 ++#define I2C_CFG_DEVADDIS (10)

please use the BIT() macro instead of xy syntax

 ++
 ++#define I2C_CFG_DEFAULT (I2C_CFG_ADDRLEN_8 | \
 ++I2C_CFG_DEVADLEN_7 | \
 ++I2C_CFG_ADDRDIS)
 ++
 ++#define I2C_RETRY0x1000
 ++
 ++#define CLKDIV_VALUE 333
 ++#define i2c_busy_loop(CLKDIV_VALUE*30)
 ++
 ++#define READ_CMD 

[OpenWrt-Devel] [PATCH 2/2] ralink: MT7621 add i2c controller driver on linux kernel 3.18

2015-03-20 Thread wengbj
ralink i2c driver is not working on MT7621 platform. Porting a new drivers from 
MTK's source code.

Signed-off-by: wengbj fl.serv...@t-firefly.com
---
 .../0111-i2c-MIPS-add-mt7621-I2C-driver.patch  |  390 
 1 file changed, 390 insertions(+)
 create mode 100755 
target/linux/ramips/patches-3.18/0111-i2c-MIPS-add-mt7621-I2C-driver.patch

diff --git 
a/target/linux/ramips/patches-3.18/0111-i2c-MIPS-add-mt7621-I2C-driver.patch 
b/target/linux/ramips/patches-3.18/0111-i2c-MIPS-add-mt7621-I2C-driver.patch
new file mode 100755
index 000..ec897ee
--- /dev/null
+++ b/target/linux/ramips/patches-3.18/0111-i2c-MIPS-add-mt7621-I2C-driver.patch
@@ -0,0 +1,390 @@
+Index: linux-3.18.9/drivers/i2c/busses/Kconfig
+===
+--- linux-3.18.9.orig/drivers/i2c/busses/Kconfig   2015-03-21 
11:47:27.387652879 +0800
 linux-3.18.9/drivers/i2c/busses/Kconfig2015-03-21 11:47:27.587652870 
+0800
+@@ -714,6 +714,10 @@
+   tristate Ralink I2C Controller
+   select OF_I2C
+ 
++config I2C_MT7621
++tristate Mt7621 I2C Controller
++select OF_I2C
++
+ config HAVE_S3C2410_I2C
+   bool
+   help
+Index: linux-3.18.9/drivers/i2c/busses/Makefile
+===
+--- linux-3.18.9.orig/drivers/i2c/busses/Makefile  2015-03-21 
11:47:27.387652879 +0800
 linux-3.18.9/drivers/i2c/busses/Makefile   2015-03-21 11:47:27.587652870 
+0800
+@@ -67,6 +67,7 @@
+ obj-$(CONFIG_I2C_PXA) += i2c-pxa.o
+ obj-$(CONFIG_I2C_PXA_PCI) += i2c-pxa-pci.o
+ obj-$(CONFIG_I2C_RALINK)  += i2c-ralink.o
++obj-$(CONFIG_I2C_MT7621)  += i2c-mt7621.o
+ obj-$(CONFIG_I2C_QUP) += i2c-qup.o
+ obj-$(CONFIG_I2C_RIIC)+= i2c-riic.o
+ obj-$(CONFIG_I2C_RK3X)+= i2c-rk3x.o
+Index: linux-3.18.9/drivers/i2c/busses/i2c-mt7621.c
+===
+--- /dev/null  1970-01-01 00:00:00.0 +
 linux-3.18.9/drivers/i2c/busses/i2c-mt7621.c   2015-03-21 
11:48:58.883648615 +0800
+@@ -0,0 +1,358 @@
++/*
++ * drivers/i2c/busses/i2c-mt7621.c
++ *
++ * Copyright (C) 2013 Steven Liu steven_...@mediatek.com
++ *
++ * Improve driver for i2cdetect from i2c-tools to detect i2c devices on the 
bus.
++ * (C) 2014 Sittisak sittis...@hotmail.com
++ *
++ * This software is licensed under the terms of the GNU General Public
++ * License version 2, as published by the Free Software Foundation, and
++ * may be copied, distributed, and modified under those terms.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU General Public License for more details.
++ *
++ */
++
++#include linux/interrupt.h
++#include linux/kernel.h
++#include linux/module.h
++#include linux/reset.h
++#include linux/delay.h
++#include linux/slab.h
++#include linux/init.h
++#include linux/errno.h
++#include linux/platform_device.h
++#include linux/i2c.h
++#include linux/io.h
++#include linux/err.h
++
++#include asm/mach-ralink/ralink_regs.h
++
++#define REG_CONFIG_REG   0x00
++#define REG_CLKDIV_REG   0x04
++#define REG_DEVADDR_REG  0x08
++#define REG_ADDR_REG 0x0C
++#define REG_DATAOUT_REG  0x10
++#define REG_DATAIN_REG   0x14
++#define REG_STATUS_REG   0x18
++#define REG_STARTXFR_REG 0x1C
++#define REG_BYTECNT_REG  0x20
++#define REG_SM0_IS_AUTOMODE  0x28
++#define REG_SM0CTL0  0x40
++
++
++#define I2C_STARTERR 0x10
++#define I2C_ACKERR   0x08
++#define I2C_DATARDY  0x04
++#define I2C_SDOEMPTY 0x02
++#define I2C_BUSY 0x01
++
++/* I2C_CFG register bit field */
++#define I2C_CFG_ADDRLEN_8(75)   /* 8 bits */
++#define I2C_CFG_DEVADLEN_7   (62)
++#define I2C_CFG_ADDRDIS  (11)
++#define I2C_CFG_DEVADDIS (10)
++
++#define I2C_CFG_DEFAULT   (I2C_CFG_ADDRLEN_8 | \
++  I2C_CFG_DEVADLEN_7 | \
++  I2C_CFG_ADDRDIS)
++
++#define I2C_RETRY0x1000
++
++#define CLKDIV_VALUE 333
++#define i2c_busy_loop(CLKDIV_VALUE*30)
++
++#define READ_CMD 0x01
++#define WRITE_CMD0x00
++#define READ_BLOCK   16
++
++#define I2C_OFFSET   0x900
++#define RSTCTRL_OFFSET   0x34
++
++#define MT7621_REG(x)(*((volatile u32 *)(x)))
++
++struct