コード例 #1
0
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;
}
コード例 #2
0
ファイル: ds1302.c プロジェクト: ManiacTwister/linux-hnd
int __init
ds1302_init(void) 
{
#ifdef CONFIG_ETRAX_I2C
	i2c_init();
#endif

	if (!ds1302_probe()) {
#ifdef CONFIG_ETRAX_DS1302_RST_ON_GENERIC_PORT
#if CONFIG_ETRAX_DS1302_RSTBIT == 27
		/*
		 * The only way to set g27 to output is to enable ATA.
		 *
		 * Make sure that R_GEN_CONFIG is setup correct.
		 */
		/* Allocating the ATA interface will grab almost all
		 * pins in I/O groups a, b, c and d.  A consequence of
		 * allocating the ATA interface is that the fixed
		 * interfaces shared RAM, parallel port 0, parallel
		 * port 1, parallel port W, SCSI-8 port 0, SCSI-8 port
		 * 1, SCSI-W, serial port 2, serial port 3,
		 * synchronous serial port 3 and USB port 2 and almost
		 * all GPIO pins on port g cannot be used.
		 */
		if (cris_request_io_interface(if_ata, "ds1302/ATA")) {
			printk(KERN_WARNING "ds1302: Failed to get IO interface\n");
			return -1;
		}

#elif CONFIG_ETRAX_DS1302_RSTBIT == 0
		if (cris_io_interface_allocate_pins(if_gpio_grp_a,
						    'g',
						    CONFIG_ETRAX_DS1302_RSTBIT,
						    CONFIG_ETRAX_DS1302_RSTBIT)) {
			printk(KERN_WARNING "ds1302: Failed to get IO interface\n");
			return -1;
		}

		/* Set the direction of this bit to out. */
		genconfig_shadow = ((genconfig_shadow &
 				     ~IO_MASK(R_GEN_CONFIG, g0dir)) |
 				   (IO_STATE(R_GEN_CONFIG, g0dir, out)));
		*R_GEN_CONFIG = genconfig_shadow;
#endif
		if (!ds1302_probe()) {
			printk(KERN_WARNING "%s: RTC not found.\n", ds1302_name);
			return -1;
		}
#else
		printk(KERN_WARNING "%s: RTC not found.\n", ds1302_name);
		return -1;
#endif
  	}
	/* Initialise trickle charger */
	ds1302_writereg(RTC_TRICKLECHARGER,
			RTC_TCR_PATTERN |(CONFIG_ETRAX_DS1302_TRICKLE_CHARGE & 0x0F));
        /* Start clock by resetting CLOCK_HALT */
	ds1302_writereg(RTC_SECONDS, (ds1302_readreg(RTC_SECONDS) & 0x7F));
	return 0;
}
コード例 #3
0
ファイル: i2c_gvc.c プロジェクト: 7LK/McWRT
/*#---------------------------------------------------------------------------
 *#
 *# 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 */