Example #1
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;
}
Example #2
0
/**
 * Reads bytes from eeprom and copies to DRAM.
 * Only supports address size of 2 (16 bit internal address.)
 *
 * @param chip   chip address
 * @param addr   internal address
 * @param alen   address length
 * @param buffer memory buffer pointer
 * @param len    number of bytes to read
 *
 * @return 0 on Success
 *         1 on Failure
 */
int i2c_read(uchar chip, uint addr, int alen, uchar * buffer, int len)
{
	unsigned int bus;
#ifdef CONFIG_I2C_MULTI_BUS
	bus = gd->ogd.current_i2c_bus;
#else
	bus = 0;
#endif
	
	debug("%s: Reading device: %#04x address %#04x.\n"
	      " alen=%d, len=%d", __func__, chip, addr, alen, len);

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

	while (len--) {
		uint64_t data;
		int tmp;
		tmp = cvmx_twsix_read_ia(bus, chip, addr++,
					 1, alen, &data);
		if (tmp < 0)
			return (1);
		*buffer++ = (uchar) (data & 0xff);
	}

	return (0);

}