i2c_mxc: Add I2C support for i.MX27 chip processor.
Subsystems (2)
PATCH 2/2 i2c_mxc: Add I2C support for i.MX27 chip processor.
Add support for I2C in i.MX27 chip.
Tested on imx27_visstrim_m10 board.
Signed-off-by Javier Martin <[email protected]>
--
drivers/i2c/mxc_i2c.c +44 -5
@@ -2,6 +2,8 @@* i2c driver for Freescale mx31 * * (c) 2007 Pengutronix, Sascha Hauer <[email protected]> +* (c) 2009 Vista Silicon, Javier Martin +* <[email protected]> * * See file CREDITS for list of people who contributed to this * project.
@@ -21,13 +23,19 @@* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA */ -#include <common.h> #if defined(CONFIG_HARD_I2C ) +#ifdef CONFIG_MX31 #include <asm/arch/mx31.h> #include <asm/arch/mx31-regs.h> +#elif defined (CONFIG_MX27 ) +#include <asm/arch/imx-regs.h> +#include <asm/arch/asm-offsets.h> +#else +#error "architecture not supported by mxc_i2c driver" +#endif #define IADR 0x00#define IFDR 0x04
@@ -47,6 +55,7 @@#define I2SR_IIF (1 << 1)#define I2SR_RX_NO_AK (1 << 0) +#ifdef CONFIG_MX31 #ifdef CONFIG_SYS_I2C_MX31_PORT1 #define I2C_BASE 0x43f80000#define I2C_CLK_OFFSET 26
@@ -59,6 +68,18 @@#else #error "define CONFIG_SYS_I2C_MX31_PORTx to use the mx31 I2C driver"#endif +#endif /* CONFIG_MX31 */ + +#ifdef CONFIG_MX27 +#ifdef CONFIG_SYS_I2C_MX27_PORT1 +#define I2C_BASE IMX_I2C1_BASE +#elif defined (CONFIG_SYS_I2C_MX27_PORT2 ) +#define I2C_BASE IMX_I2C2_BASE +#else +#error "define CONFIG_SYS_I2C_MX27_PORTx to use the mx27 I2C driver" +#endif +#endif /* CONFIG_MX27 */ +#ifdef DEBUG #define DPRINTF(args...) printf(args)
@@ -70,17 +91,37 @@ static u16 div[] = { 30, 32, 36, 42, 48, 52, 60, 72, 80, 88, 104, 128, 144,160 ,192 ,240 ,288 ,320 ,384 ,480 ,576 ,640 ,768 ,960 , 1152, 1280, 1536, 1920, 2304, 2560, 3072, 3840}; +static void i2c_clken (void ) +{ +#ifdef CONFIG_MX31 +__REG (CCM_CGR0 ) =__REG (CCM_CGR0 ) | (3 <<I2C_CLK_OFFSET ); +#elif defined(CONFIG_MX27 ) +#ifdef CONFIG_SYS_I2C_MX27_PORT1 +__REG (PCCR0 ) =__REG (PCCR0 ) |PCCR0_I2C1_EN ; +#else +__REG (PCCR0 ) =__REG (PCCR0 ) |PCCR0_I2C2_EN ; +#endif +#endif /* CONFIG_MX31 */ +} +void i2c_init (int speed,int unused) { -int freq =mx31_get_ipg_clk (); +int freq;int i; +#ifdef CONFIG_MX31 + freq =mx31_get_ipg_clk (); +#elif defined(CONFIG_MX27 ) + freq =imx_get_ipgclk (); +#endif /* start the required I2C clock */ -__REG (CCM_CGR0 ) =__REG (CCM_CGR0 ) | (3 <<I2C_CLK_OFFSET ); +i2c_clken (); +DPRINTF ("ipg_freq is %d\n" , freq);for (i =0 ; i <0x1f ; i++)if (freq / div[i] <= speed)break ; +DPRINTF ("i2c_clk divisor is %d\n" , div[i]);DPRINTF ("%s: speed: %d\n" ,__FUNCTION__, speed);
@@ -121,7 +162,6 @@ static int rx_byte(void)int i2c_probe (uchar chip) {int ret; -__REG16 (I2C_BASE +I2CR ) =0 ;/* Reset module */ __REG16 (I2C_BASE +I2CR ) =I2CR_IEN ; --
Javier Martin
Vista Silicon S.L.
CDTUC - FASE C - Oficina S-345
Avda de los Castros s/n
39005- Santander. Cantabria. Spain
+34 942 25 32 60
www.vista-silicon.com