int __init i2c_init(void) { static int res = 0; static int first = 1; if (!first) { return res; } first = 0; /* Setup and enable the Port B I2C interface */ #ifndef CONFIG_ETRAX_I2C_USES_PB_NOT_PB_I2C if ((res = cris_request_io_interface(if_i2c, "I2C"))) { printk(KERN_CRIT "i2c_init: Failed to get IO interface\n"); return res; } *R_PORT_PB_I2C = port_pb_i2c_shadow |= IO_STATE(R_PORT_PB_I2C, i2c_en, on) | IO_FIELD(R_PORT_PB_I2C, i2c_d, 1) | IO_FIELD(R_PORT_PB_I2C, i2c_clk, 1) | IO_STATE(R_PORT_PB_I2C, i2c_oe_, enable); port_pb_dir_shadow &= ~IO_MASK(R_PORT_PB_DIR, dir0); port_pb_dir_shadow &= ~IO_MASK(R_PORT_PB_DIR, dir1); *R_PORT_PB_DIR = (port_pb_dir_shadow |= IO_STATE(R_PORT_PB_DIR, dir0, input) | IO_STATE(R_PORT_PB_DIR, dir1, output)); #else if ((res = cris_io_interface_allocate_pins(if_i2c, 'b', CONFIG_ETRAX_I2C_DATA_PORT, CONFIG_ETRAX_I2C_DATA_PORT))) { printk(KERN_WARNING "i2c_init: Failed to get IO pin for I2C data port\n"); return res; } else if ((res = cris_io_interface_allocate_pins(if_i2c, 'b', CONFIG_ETRAX_I2C_CLK_PORT, CONFIG_ETRAX_I2C_CLK_PORT))) { cris_io_interface_free_pins(if_i2c, 'b', CONFIG_ETRAX_I2C_DATA_PORT, CONFIG_ETRAX_I2C_DATA_PORT); printk(KERN_WARNING "i2c_init: Failed to get IO pin for I2C clk port\n"); } #endif return res; }
/*#--------------------------------------------------------------------------- *# *# FUNCTION NAME: i2c_init *# *# DESCRIPTION : initialises the I2C device driver *# *# PARAMETERS : *# *#--------------------------------------------------------------------------- */ int __init i2c_init( void ) { static int res = 0; static int first = 1; if ( !first ) { return res; } first = 0; /* Setup and enable the Port B I2C interface */ #ifndef CONFIG_ETRAX_I2C_USES_PB_NOT_PB_I2C /* here, we're using the dedicated I2C pins of FoxBoard */ if ( ( res = cris_request_io_interface( if_i2c, "I2C" ) ) ) { printk( KERN_CRIT "i2c_init: Failed to get IO interface\n" ); return res; } *R_PORT_PB_I2C = port_pb_i2c_shadow |= IO_STATE( R_PORT_PB_I2C, i2c_en, on ) | IO_FIELD( R_PORT_PB_I2C, i2c_d, 1 ) | IO_FIELD( R_PORT_PB_I2C, i2c_set_scl, 1 ) | IO_STATE( R_PORT_PB_I2C, i2c_oe_, enable ); port_pb_dir_shadow &= ~IO_MASK( R_PORT_PB_DIR, dir0 ); port_pb_dir_shadow &= ~IO_MASK( R_PORT_PB_DIR, dir1 ); *R_PORT_PB_DIR = ( port_pb_dir_shadow |= IO_STATE( R_PORT_PB_DIR, dir0, input ) | IO_STATE( R_PORT_PB_DIR, dir1, output ) ); #else /* If everything goes fine, res = 0, meaning "if" fails => * will do the "else" too and as such initialise the clock port... * Clever trick! */ if ( ( res = cris_io_interface_allocate_pins( if_i2c , 'b' , CONFIG_ETRAX_I2C_DATA_PORT , CONFIG_ETRAX_I2C_DATA_PORT ) ) ) { printk( KERN_WARNING "i2c_init: Failed to get IO pin for I2C data port\n" ); return ( res ); } /* Same here...*/ else if ( ( res = cris_io_interface_allocate_pins( if_i2c , 'b' , CONFIG_ETRAX_I2C_CLK_PORT , CONFIG_ETRAX_I2C_CLK_PORT ) ) ) { cris_io_interface_free_pins( if_i2c , 'b' , CONFIG_ETRAX_I2C_DATA_PORT , CONFIG_ETRAX_I2C_DATA_PORT ); printk( KERN_WARNING "i2c_init: Failed to get IO pin for I2C clk port\n" ); } #endif return ( res ); } /* i2c_init */