Ejemplo n.º 1
0
static void bq2429x_irq_workfunc(struct work_struct *work)
{
	struct bq2429x *bq = container_of(work, struct bq2429x, irq_work);
	u8 status;
	u8 fault;
	int ret;

	/* Disable the watchdog timer forcedly */
	bq2429x_disable_watchdog_timer(bq);

	/* Read STATUS and FAULT registers */
	ret = bq2429x_read_byte(bq, &status, BQ2429X_STATUS);
	if (ret) {
		dev_err(bq->dev, "i2c failure:%d\n", ret);
		return;
	}

	ret = bq2429x_read_byte(bq, &fault, BQ2429X_FAULT);
	if (ret) {
		dev_err(bq->dev, "i2c failure: %d\n", ret);
		return;
	}

	dev_info(bq->dev, "IRQ status=0x%.2x, fault=0x%.2x\n", status, fault);

	/* Set charging parameters: VINDPM, IINLIM and ICHG */
	bq2429x_update_charge_params(bq);
}
Ejemplo n.º 2
0
static enum bq2429x_vbus_type bq2429x_get_vbus_type(struct bq2429x *bq)
{
	u8 val = 0;

	bq2429x_read_byte(bq, &val, BQ2429X_STATUS);
	val &= BQ2429X_VBUS_STATUS_MASK;
	val >>= BQ2429X_VBUS_STATUS_SHIFT;

	return val;
}
/**********************************************************
*  Function:       bq2429x_read_mask
*  Discription:    register read mask interface
*  Parameters:   reg:register name
*                      MASK:mask value of the function
*                      SHIFT:shift number of the function
*                      value:register value
*  return value:  0-sucess or others-fail
**********************************************************/
static int bq2429x_read_mask(u8 reg, u8 MASK, u8 SHIFT, u8 *value)
{
    int ret = 0;
    u8 val = 0;

    ret = bq2429x_read_byte(reg,&val);
    if(ret < 0)
        return ret;
    val &= MASK;
    val >>= SHIFT;
    *value = val;

    return 0;
}
Ejemplo n.º 4
0
static ssize_t bq2429x_show_registers(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	struct bq2429x *bq = dev_get_drvdata(dev);
	u8 addr;
	u8 val;

	for (addr = 0x0; addr <= 0x0A; addr++) {
		bq2429x_read_byte(bq, &val, addr);
		dev_info(bq->dev, "[0x%.2x] = 0x%.2x\n", addr, val);
	}

	return 0;
}
Ejemplo n.º 5
0
static int bq2429x_update_bits(struct bq2429x *bq, u8 reg, u8 mask, u8 data)
{
	int ret;
	u8 tmp;

	ret = bq2429x_read_byte(bq, &tmp, reg);
	if (ret)
		return ret;

	tmp &= ~mask;
	tmp |= data & mask;

	return bq2429x_write_byte(bq, reg, tmp);
}
/**********************************************************
*  Function:       bq2429x_write_mask
*  Discription:    register write mask interface
*  Parameters:   reg:register name
*                      MASK:mask value of the function
*                      SHIFT:shift number of the function
*                      value:register value
*  return value:  0-sucess or others-fail
**********************************************************/
static int bq2429x_write_mask(u8 reg, u8 MASK, u8 SHIFT, u8 value)
{
    int ret = 0;
    u8 val = 0;

    ret = bq2429x_read_byte(reg,&val);
    if(ret < 0)
        return ret;

    val &= ~MASK;
    val |= ((value << SHIFT) & MASK);

    ret = bq2429x_write_byte(reg,val);

    return ret;
}
Ejemplo n.º 7
0
static int bq2429x_charge_status(struct bq2429x *bq)
{
	u8 val = 0;

	bq2429x_read_byte(bq, &val, BQ2429X_STATUS);
	val &= BQ2429X_CHG_STAT_MASK;
	val >>= BQ2429X_CHG_STAT_SHIFT;

	switch (val) {
	case BQ2429X_FAST_CHARGING:
		return POWER_SUPPLY_CHARGE_TYPE_FAST;
	case BQ2429X_NOT_CHARGING:
		return POWER_SUPPLY_CHARGE_TYPE_NONE;
	default:
		return POWER_SUPPLY_CHARGE_TYPE_UNKNOWN;
	}
}