static int hdmi_read_block(uint8_t page, uint8_t reg, uint8_t * buf, size_t buflen) { int r; minix_i2c_ioctl_exec_t ioctl_exec; if (buf == NULL || buflen > I2C_EXEC_MAX_BUFLEN) { log_warn(&log, "Read block called with NULL pointer or invalid buflen.\n"); return EINVAL; } if (page != HDMI_PAGELESS) { r = set_page(page); if (r != OK) { log_warn(&log, "Unable to set page to 0x%x\n", page); return r; } } memset(&ioctl_exec, '\0', sizeof(minix_i2c_ioctl_exec_t)); /* Read from HDMI */ ioctl_exec.iie_op = I2C_OP_READ_WITH_STOP; ioctl_exec.iie_addr = hdmi_address; /* write the register address */ ioctl_exec.iie_cmd[0] = reg; ioctl_exec.iie_cmdlen = 1; /* read bytes */ ioctl_exec.iie_buflen = buflen; r = i2cdriver_exec(hdmi_bus_endpoint, &ioctl_exec); if (r != OK) { log_warn(&log, "hdmi_read() failed (r=%d)\n", r); return -1; } memcpy(buf, ioctl_exec.iie_buf, buflen); log_trace(&log, "Read %d bytes from reg 0x%x in page 0x%x\n", buflen, reg, page); return OK; }
static int reg_write(uint8_t reg, uint8_t val) { int r; minix_i2c_ioctl_exec_t ioctl_exec; if (reg >= 0x0d) { /* TODO: writes to password protected registers hasn't * been implemented since nothing in this driver needs to * write to them. When needed, it should be implemented. */ log_warn(&log, "Cannot write to protected registers."); return -1; } memset(&ioctl_exec, '\0', sizeof(minix_i2c_ioctl_exec_t)); /* Write to chip */ ioctl_exec.iie_op = I2C_OP_WRITE_WITH_STOP; ioctl_exec.iie_addr = address; /* write the register address and value */ ioctl_exec.iie_buf[0] = reg; ioctl_exec.iie_buf[1] = val; ioctl_exec.iie_buflen = 2; r = i2cdriver_exec(bus_endpoint, &ioctl_exec); if (r != OK) { log_warn(&log, "reg_write() failed (r=%d)\n", r); return -1; } log_trace(&log, "Successfully wrote 0x%x to reg 0x%x\n", val, reg); return OK; }
static int reg_read(uint8_t reg, uint8_t * val) { int r; minix_i2c_ioctl_exec_t ioctl_exec; if (val == NULL) { log_warn(&log, "Read called with NULL pointer\n"); return EINVAL; } memset(&ioctl_exec, '\0', sizeof(minix_i2c_ioctl_exec_t)); /* Read from chip */ ioctl_exec.iie_op = I2C_OP_READ_WITH_STOP; ioctl_exec.iie_addr = address; /* write the register address */ ioctl_exec.iie_cmd[0] = reg; ioctl_exec.iie_cmdlen = 1; /* read 1 byte */ ioctl_exec.iie_buflen = 1; r = i2cdriver_exec(bus_endpoint, &ioctl_exec); if (r != OK) { log_warn(&log, "reg_read() failed (r=%d)\n", r); return -1; } *val = ioctl_exec.iie_buf[0]; log_trace(&log, "Read 0x%x from reg 0x%x", *val, reg); return OK; }