]> git.sur5r.net Git - u-boot/commitdiff
sunxi: Add i2c support
authorHans de Goede <hdegoede@redhat.com>
Fri, 13 Jun 2014 20:55:49 +0000 (22:55 +0200)
committerIan Campbell <ijc@hellion.org.uk>
Fri, 18 Jul 2014 18:41:30 +0000 (19:41 +0100)
Add support for the i2c controller found on all Allwinner sunxi SoCs,
this is the same controller as found on the Marvell orion5x and kirkwood
SoC families, with a slightly different register layout, so this patch uses
the existing mvtwsi code.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Ian Campbell <ijc@hellion.org.uk>
Acked-By: Prafulla Wadaskar <prafulla@marvell.com>
Acked-by: Heiko Schocher <hs@denx.de>
[ ijc -- updated u-boot-spl-fel.lds ]

arch/arm/cpu/armv7/sunxi/board.c
arch/arm/cpu/armv7/sunxi/u-boot-spl-fel.lds
arch/arm/cpu/armv7/sunxi/u-boot-spl.lds
arch/arm/include/asm/arch-sunxi/i2c.h [new file with mode: 0644]
board/sunxi/board.c
drivers/i2c/mvtwsi.c
include/configs/sunxi-common.h

index 538ffa70a3a6f376722ad024d94569e073017a6c..701f9195e211dcbbd78643c6972e6757e166a6b1 100644 (file)
@@ -11,6 +11,7 @@
  */
 
 #include <common.h>
+#include <i2c.h>
 #include <netdev.h>
 #include <miiphy.h>
 #include <serial.h>
@@ -93,11 +94,16 @@ void s_init(void)
        clock_init();
        timer_init();
        gpio_init();
+       i2c_init_board();
 
 #ifdef CONFIG_SPL_BUILD
        gd = &gdata;
        preloader_console_init();
 
+#ifdef CONFIG_SPL_I2C_SUPPORT
+       /* Needed early by sunxi_board_init if PMU is enabled */
+       i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
+#endif
        sunxi_board_init();
 #endif
 }
index 364e35c32fea03c8947705d7969af04302ae6b37..928b7c19e031c69f40ab0ba7f23d4a549df041f6 100644 (file)
@@ -26,6 +26,11 @@ SECTIONS
                *(.data*)
        }
 
+       . = ALIGN(4);
+       .u_boot_list : {
+               KEEP(*(SORT(.u_boot_list*)));
+       }
+
        . = ALIGN(4);
        . = .;
 
index c1ae227f06d6905268dcec3ae89a284a3e4f12ea..53f0cbd2b7eac2b6496dfcd27da23226760637b5 100644 (file)
@@ -38,6 +38,11 @@ SECTIONS
        . = ALIGN(4);
        .data : { *(SORT_BY_ALIGNMENT(.data*)) } >.sram
 
+       . = ALIGN(4);
+       .u_boot_list : {
+               KEEP(*(SORT(.u_boot_list*)));
+       } > .sram
+
        . = ALIGN(4);
        __image_copy_end = .;
        _end = .;
diff --git a/arch/arm/include/asm/arch-sunxi/i2c.h b/arch/arm/include/asm/arch-sunxi/i2c.h
new file mode 100644 (file)
index 0000000..dc5406b
--- /dev/null
@@ -0,0 +1,15 @@
+/*
+ * Copyright 2014 - Hans de Goede <hdegoede@redhat.com>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+#ifndef _SUNXI_I2C_H_
+#define _SUNXI_I2C_H_
+
+#include <asm/arch/cpu.h>
+
+#define CONFIG_I2C_MVTWSI_BASE SUNXI_TWI0_BASE
+/* This is abp0-clk on sun4i/5i/7i / abp1-clk on sun6i/sun8i which is 24MHz */
+#define CONFIG_SYS_TCLK                24000000
+
+#endif
index b05d0b9b18c9a5fdc7442de3286edb9838da95bd..543b8098e938ff60d62f92b95be62f15229d41e3 100644 (file)
@@ -106,6 +106,13 @@ int board_mmc_init(bd_t *bis)
 }
 #endif
 
+void i2c_init_board(void)
+{
+       sunxi_gpio_set_cfgpin(SUNXI_GPB(0), SUNXI_GPB0_TWI0);
+       sunxi_gpio_set_cfgpin(SUNXI_GPB(1), SUNXI_GPB0_TWI0);
+       clock_twi_onoff(0, 1);
+}
+
 #ifdef CONFIG_SPL_BUILD
 void sunxi_board_init(void)
 {
index c8b5425a0152ab2d0b50991e6df5100a89fac213..ab3ffa0fc1535b89101f40877b5e4355b69ea1f2 100644 (file)
@@ -22,6 +22,8 @@
 #include <asm/arch/orion5x.h>
 #elif defined(CONFIG_KIRKWOOD)
 #include <asm/arch/kirkwood.h>
+#elif defined(CONFIG_SUNXI)
+#include <asm/arch/i2c.h>
 #else
 #error Driver mvtwsi not supported by SoC or board
 #endif
  * TWSI register structure
  */
 
+#ifdef CONFIG_SUNXI
+
+struct  mvtwsi_registers {
+       u32 slave_address;
+       u32 xtnd_slave_addr;
+       u32 data;
+       u32 control;
+       u32 status;
+       u32 baudrate;
+       u32 soft_reset;
+};
+
+#else
+
 struct  mvtwsi_registers {
        u32 slave_address;
        u32 data;
@@ -43,6 +59,8 @@ struct  mvtwsi_registers {
        u32 soft_reset;
 };
 
+#endif
+
 /*
  * Control register fields
  */
index 3f04890526b1d7b51234353b85aa602f0095789c..42b0d2e51b4cacda0135ec27437cfac6cca648b0 100644 (file)
 #undef CONFIG_CMD_NET
 #undef CONFIG_CMD_NFS
 
+/* I2C */
+#define CONFIG_SPL_I2C_SUPPORT
+#define CONFIG_SYS_I2C
+#define CONFIG_SYS_I2C_MVTWSI
+#define CONFIG_SYS_I2C_SPEED           400000
+#define CONFIG_SYS_I2C_SLAVE           0x7f
+#define CONFIG_CMD_I2C
+
 #ifndef CONFIG_CONS_INDEX
 #define CONFIG_CONS_INDEX              1       /* UART0 */
 #endif