Esempio n. 1
0
/**
 * @INTERNAL
 * Write data to the specified SPI4000 address
 *
 * @param interface Interface the SPI4000 is on. (0 or 1)
 * @param address   Address to write to
 * @param data      Data to write
 */
static void __cvmx_spi4000_write(int interface, int address, uint32_t data)
{
    int status;
    cvmx_twsix_write_ia(0, SPI4000_TWSI_ID(interface), SPI4000_WRITE_ADDRESS_HIGH, 2, 1, address);
    cvmx_twsix_write_ia(0, SPI4000_TWSI_ID(interface), SPI4000_WRITE_DATA0, 4, 1, data);

    status = cvmx_twsi_read8(SPI4000_TWSI_ID(interface), SPI4000_DO_WRITE);
    while ((status == 5) || (status == 0xff))
        status = cvmx_twsi_read8(SPI4000_TWSI_ID(interface), SPI4000_GET_WRITE_STATUS);

    if (status != 4)
        cvmx_dprintf("SPI4000: write failed with status=0x%x\n", status);
}
Esempio n. 2
0
/**
 * @INTERNAL
 * Read data from the SPI4000.
 *
 * @param interface Interface the SPI4000 is on. (0 or 1)
 * @param address   Address to read from
 *
 * @return Value at the specified address
 */
static uint32_t __cvmx_spi4000_read(int interface, int address)
{
    int status;
    uint64_t data;

    cvmx_twsix_write_ia(0, SPI4000_TWSI_ID(interface), SPI4000_READ_ADDRESS_HIGH, 2, 1, address);

    status = cvmx_twsi_read8(SPI4000_TWSI_ID(interface), SPI4000_DO_READ);
    while ((status == 1) || (status == 0xff))
        status = cvmx_twsi_read8(SPI4000_TWSI_ID(interface), SPI4000_GET_READ_STATUS);

    if (status)
    {
        cvmx_dprintf("SPI4000: read failed with %d\n", status);
        return 0;
    }

    status = cvmx_twsix_read_ia(0, SPI4000_TWSI_ID(interface), SPI4000_READ_DATA0, 4, 1, &data);
    if (status != 4)
    {
        cvmx_dprintf("SPI4000: read failed with %d\n", status);
        return 0;
    }

    return data;
}
Esempio n. 3
0
/**
 * Reads bytes from memory and copies to eeprom.
 * Only supports address size of 2 (16 bit internal address.)
 *
 * We can only write two bytes at a time to the eeprom, so in some cases
 * we need to to a read/modify/write.
 *
 * Note: can't do single byte write to last address in EEPROM
 *
 * @param chip   chip address
 * @param addr   internal address
 * @param alen   address length, must be 0, 1, or 2
 * @param buffer memory buffer pointer
 * @param len    number of bytes to write
 *
 * @return 0 on Success
 *         1 on Failure
 */
int i2c_write(uchar chip, uint addr, int alen, uchar * buffer, int len)
{
	int retval;
	unsigned int bus;
#ifdef CONFIG_I2C_MULTI_BUS
	bus = gd->ogd.current_i2c_bus;
#else
	bus = 0;
#endif

	debug("%s: Writing device: %#04x address %#04x data %#04x,"
	      " alen=%d, len=%d\n", __func__, chip, addr, *buffer, alen, len);

	if (alen > 2 || !buffer || !len)
		return (1);

	while (len-- > 0) {
		retval =
		    cvmx_twsix_write_ia(bus, chip, addr++,
					1, alen, *buffer++);
		if (retval < 0)
			return (1);

	}

	return (0);

}