Пример #1
0
size_t i2c::command(uint8_t slaveaddr,
                    uint8_t cmd,
                    const uint8_t* data_addr,
                    size_t data_size)
{
    reset_txfer_done();
    set_slave_address(slaveaddr);
    set_data_len(1 + data_size);
    initiate_write();
    write_byte(cmd);
    size_t bytes_sent=1;
    while (data_size>0)
    {
        if (write_byte(*data_addr))
        {
            data_addr++;
            data_size--;
            bytes_sent++;
        }
        // TODO check for error conditions
    }
    wait_for_done();
    clear_fifo();
    return bytes_sent;
}
Пример #2
0
/* read up to KFUSE_DATA_SZ bytes into dest.
 * always starts at the first kfuse.
 */
int tegra_kfuse_read(void *dest, size_t len)
{
    u32 v;
    unsigned cnt;

    if (len > KFUSE_DATA_SZ)
        return -EINVAL;

    tegra_kfuse_writel(KFUSE_KEYADDR_AUTOINC, KFUSE_KEYADDR);
    wait_for_done();

    if ((tegra_kfuse_readl(KFUSE_STATE) & KFUSE_STATE_CRCPASS) == 0) {
        pr_err("kfuse: crc failed\n");
        return -EIO;
    }

    for (cnt = 0; cnt < len; cnt += 4) {
        v = tegra_kfuse_readl(KFUSE_KEYS);
        memcpy(dest + cnt, &v, sizeof v);
    }

    return 0;
}