Ejemplo n.º 1
0
fsa9480_dev_t fsa9480_detect_device(uint8_t chip_addr) {
	uint16_t dev_type, int_val;
	int i;
	fsa9480_dev_t ret = FSA9480_UNKNOWN;

	for (i = 0; i < 100; i++) {
		int _ok = smbus_read_word(chip_addr, FSA9480_REG_INT1, &int_val);
		if ((_ok < 0) || !int_val)
		{
			break;
		}
	}
	mdelay(1000);

	if (smbus_read_word(chip_addr, FSA9480_REG_DEV_T1, &dev_type) < 0) {
		printf("%s: failed to get device type\n", __func__);
		goto fail;
	}

	if (dev_type & DEV_USB_MASK) {
		ret = FSA9480_USB;
	}
	else if (dev_type & DEV_UART_MASK) {
		ret = FSA9480_UART;
	}
	else if (dev_type & DEV_JIG_MASK) {
		ret = FSA9480_JIG;
	}
	else if (dev_type & DEV_CHARGER_MASK) {
		ret = FSA9480_CHARGER;
	}
	else if (dev_type & DEV_USB_OTG) {
		ret = FSA9480_USB_HOST;
	}

	fsa9480_print_dev_type(ret);

fail:
	return ret;
}
Ejemplo n.º 2
0
uint8_t max17435_get_current(MAX17435 *max, uint16_t *ma){
  uint16_t mv_read;
  if(smbus_read_word(max->config.i2c, max->config.address, MAX17435_CMD_IINP_VOLTAGE, &mv_read) != 0){
    return ERR_COMMS;
  }

  float mv_sense = (float)mv_read / 20.0f; // The read value is 20x the sense
  float ohms = (float)max->config.css_resistor_mohms / 1000.0f;

  *ma = (uint16_t)(mv_sense / ohms);

  return ERR_OK;
}
Ejemplo n.º 3
0
uint8_t max17435_get_relearn_voltage(MAX17435 *max, uint16_t *mv){
  return smbus_read_word(max->config.i2c, max->config.address, MAX17435_CMD_RELEARN_VOLTAGE, mv);
}
Ejemplo n.º 4
0
uint8_t max17435_get_input_current_limit(MAX17435 *max, uint16_t *ma){
  return smbus_read_word(max->config.i2c, max->config.address, MAX17435_CMD_INPUT_CURRENT, ma);
}
Ejemplo n.º 5
0
uint8_t max17435_get_charge_current(MAX17435 *max, uint16_t *ma){
  return smbus_read_word(max->config.i2c, max->config.address, MAX17435_CMD_CHARGE_CURRENT, ma);
}
Ejemplo n.º 6
0
uint8_t max17435_get_charge_voltage(MAX17435 *max, uint16_t *mv){
  return smbus_read_word(max->config.i2c, max->config.address, MAX17435_CMD_CHARGE_VOLTAGE, mv);
}