Beispiel #1
0
static int clear_alarm_int_status(struct device *dev, struct tps80031_rtc *rtc)
{
	int ret;
	u8 buf;

	/**
	 * As per datasheet, A dummy read of this  RTC_STATUS_REG register
	 * is necessary before each I2C read in order to update the status
	 * register value.
	 */
	ret = tps80031_read(dev->parent, TPS80031_SLAVE_ID1,
				TPS80031_RTC_STATUS_REG, &buf);
	if (ret < 0) {
		dev_err(dev, "reading RTC_STATUS failed. err = %d\n", ret);
		return ret;
	}

	/* clear Alarm status bits.*/
	ret = tps80031_set_bits(dev->parent, TPS80031_SLAVE_ID1,
			TPS80031_RTC_STATUS_REG, ALARM_INT_STATUS);
	if (ret < 0) {
		dev_err(dev, "clear Alarm INT failed, err = %d\n", ret);
		return ret;
	}
	return 0;
}
Beispiel #2
0
static int tps80031_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
	u8 buff[7];
	int ret;

	buff[0] = bin2bcd(tm->tm_sec);
	buff[1] = bin2bcd(tm->tm_min);
	buff[2] = bin2bcd(tm->tm_hour);
	buff[3] = bin2bcd(tm->tm_mday);
	buff[4] = bin2bcd(tm->tm_mon + 1);
	buff[5] = bin2bcd(tm->tm_year % RTC_YEAR_OFFSET);
	buff[6] = bin2bcd(tm->tm_wday);

	/* Stop RTC while updating the RTC time registers */
	ret = tps80031_clr_bits(dev->parent, TPS80031_SLAVE_ID1,
				TPS80031_RTC_CTRL_REG, STOP_RTC);
	if (ret < 0) {
		dev_err(dev->parent, "Stop RTC failed, err = %d\n", ret);
		return ret;
	}

	ret = tps80031_writes(dev->parent, TPS80031_SLAVE_ID1,
			TPS80031_SECONDS_REG,
			TPS80031_RTC_TIME_NUM_REGS, buff);
	if (ret < 0) {
		dev_err(dev, "writing RTC_SECONDS_REG failed, err %d\n", ret);
		return ret;
	}

	ret = tps80031_set_bits(dev->parent, TPS80031_SLAVE_ID1,
				TPS80031_RTC_CTRL_REG, STOP_RTC);
	if (ret < 0)
		dev_err(dev->parent, "Start RTC failed, err = %d\n", ret);
	return ret;
}
static int tps80031_rtc_alarm_irq_enable(struct device *dev,
					 unsigned int enable)
{
	struct tps80031_rtc *rtc = dev_get_drvdata(dev);
	int err;
	struct device *p = dev->parent;

	if (rtc->irq == -1)
		return -EIO;

	if (enable) {
		if (rtc->irq_en == true)
			return 0;

		err = tps80031_set_bits(p, 1, RTC_INT, ENABLE_ALARM_INT);
		if (err < 0) {
			dev_err(p, "failed to set ALRM int. err: %d\n", err);
			return err;
		}
		rtc->irq_en = true;
	} else {
		if (rtc->irq_en == false)
			return 0;
		err = tps80031_clr_bits(p, 1, RTC_INT, ENABLE_ALARM_INT);
		if (err < 0) {
			dev_err(p, "failed to clear ALRM int. err: %d\n", err);
			return err;
		}
		rtc->irq_en = false;
	}
	return 0;
}
static int tps80031_rtc_start(struct device *dev)
{
	int err;
	err = tps80031_set_bits(dev->parent, 1, RTC_CTRL, STOP_RTC);
	if (err < 0)
		dev_err(dev->parent, "failed to start RTC. err: %d\n", err);
	return err;
}
Beispiel #5
0
static int tps80031_vbus_enable(struct regulator_dev *rdev)
{
	struct tps80031_regulator *ri = rdev_get_drvdata(rdev);
	struct device *parent = to_tps80031_dev(rdev);
	int ret;

	ret = tps80031_set_bits(parent, TPS80031_SLAVE_ID2,
				TPS80031_CHARGERUSB_CTRL1, OPA_MODE_EN);
	if (ret < 0) {
		dev_err(ri->dev, "reg 0x%02x read failed, e = %d\n",
					TPS80031_CHARGERUSB_CTRL1, ret);
		return ret;
	}

	ret = tps80031_set_bits(parent, TPS80031_SLAVE_ID2,
				TPS80031_CHARGERUSB_CTRL3, BOOST_HW_PWR_EN);
	if (ret < 0) {
		dev_err(ri->dev, "reg 0x%02x read failed, e = %d\n",
			TPS80031_CHARGERUSB_CTRL3, ret);
		return ret;
	}
	return ret;
}
Beispiel #6
0
static int tps80031_rtc_alarm_irq_enable(struct device *dev,
					 unsigned int enable)
{
	int ret;

	if (enable)
		ret = tps80031_set_bits(dev->parent, TPS80031_SLAVE_ID1,
				TPS80031_RTC_INTERRUPTS_REG, ENABLE_ALARM_INT);
	else
		ret = tps80031_clr_bits(dev->parent, TPS80031_SLAVE_ID1,
				TPS80031_RTC_INTERRUPTS_REG, ENABLE_ALARM_INT);
	if (ret < 0) {
		dev_err(dev, "Update on RTC_INT failed, err = %d\n", ret);
		return ret;
	}
	return 0;
}
static int configure_charging_parameter(struct tps80031_charger *charger)
{
	int ret;
	int max_charge_current;
	int max_charge_volt;
	int term_current;

	/* Disable watchdog timer */
	ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
				CONTROLLER_WDG, 0x0);
	if (ret < 0) {
		dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
				__func__, CONTROLLER_WDG);
		return ret;
	}

	/* Disable the charging if any */
	ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
				CONTROLLER_CTRL1, 0x0);
	if (ret < 0) {
		dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
				__func__, CONTROLLER_CTRL1);
		return ret;
	}

	if (charger->board_init) {
		ret = charger->board_init(charger->board_data);
		if (ret < 0) {
			dev_err(charger->dev, "%s(): Failed in board init\n",
				__func__);
			return ret;
		}
	}

	/* Unlock value */
	ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
			CHARGERUSB_CTRLLIMIT2, 0);
	if (ret < 0) {
		dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
				__func__, CHARGERUSB_CTRLLIMIT2);
		return ret;
	}

	/* Set max current limit */
	max_charge_current = min(1500, charger->max_charge_current_mA);
	if (max_charge_current < 100)
		max_charge_current = 0;
	else
		max_charge_current = (max_charge_current - 100)/100;
	max_charge_current &= 0xF;
	ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
		CHARGERUSB_CTRLLIMIT2, (uint8_t)max_charge_current);
	if (ret < 0) {
		dev_err(charger->dev, "%s(): Failed in writing register "
				"0x%02x\n", __func__, CHARGERUSB_CTRLLIMIT2);
		return ret;
	}

	/* Set max voltage limit */
	max_charge_volt = min(4760, charger->max_charge_volt_mV);
	max_charge_volt = max(3500, max_charge_volt);
	max_charge_volt -= 3500;
	max_charge_volt = max_charge_volt/20;
	ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
		CHARGERUSB_CTRLLIMIT1, (uint8_t)max_charge_volt);
	if (ret < 0) {
		dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
				__func__, CHARGERUSB_CTRLLIMIT1);
		return ret;
	}

	/* Lock value */
	ret = tps80031_set_bits(charger->dev->parent, SLAVE_ID2,
			CHARGERUSB_CTRLLIMIT2, (1 << 4));
	if (ret < 0) {
		dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
				__func__, CHARGERUSB_CTRLLIMIT2);
		return ret;
	}

	/* set Pre Charge current to 400mA */
	ret = tps80031_write(charger->dev->parent, SLAVE_ID2, 0xDE, 0x3);
	if (ret < 0) {
		dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
				__func__, 0xDD);
		return ret;
	}

	/* set charging termination current*/
	if (charger->charging_term_current_mA > 400)
		term_current =  7;
	else
		term_current = (charger->charging_term_current_mA - 50)/50;
	term_current = term_current << 5;
	ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
			CHARGERUSB_CTRL2, term_current);
	if (ret < 0) {
		dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
				__func__, CHARGERUSB_CTRL2);
		return ret;
	}

	return 0;
}
static int __devinit tps80031_rtc_probe(struct platform_device *pdev)
{
	struct tps80031_platform_data *tps80031_pdata;
	struct tps80031_rtc_platform_data *pdata;
	struct tps80031_rtc *rtc;
	struct rtc_time tm;
	int err;
	u8 reg;

	tps80031_pdata = dev_get_platdata(pdev->dev.parent);
	if (!tps80031_pdata) {
		dev_err(&pdev->dev, "no tps80031 platform_data specified\n");
		return -EINVAL;
	}

	pdata = tps80031_pdata->rtc_pdata;
	if (!pdata) {
		dev_err(&pdev->dev, "no platform_data specified\n");
		return -EINVAL;
	}

	rtc = kzalloc(sizeof(*rtc), GFP_KERNEL);
	if (!rtc)
		return -ENOMEM;

	rtc->irq = -1;
	if (pdata->irq < 0)
		dev_err(&pdev->dev, "no IRQ specified, wakeup is disabled\n");

	rtc->msecure_gpio = -1;
	if (gpio_is_valid(pdata->msecure_gpio)) {
		err = gpio_request(pdata->msecure_gpio, "tps80031 msecure");
		if (err == 0) {
			rtc->msecure_gpio = pdata->msecure_gpio;
			gpio_direction_output(rtc->msecure_gpio, 0);
		} else
			dev_warn(&pdev->dev, "could not get msecure GPIO\n");
	}

	rtc->rtc = rtc_device_register(pdev->name, &pdev->dev,
				       &tps80031_rtc_ops, THIS_MODULE);
	dev_set_drvdata(&pdev->dev, rtc);

	if (IS_ERR(rtc->rtc)) {
		err = PTR_ERR(rtc->rtc);
		goto fail;
	}

	if ((int)pdev && (int)&pdev->dev)
		err = tps80031_read_regs(&pdev->dev, RTC_STATUS, 1, &reg);
	else {
		dev_err(&pdev->dev, "%s Input params incorrect\n", __func__);
		err = -EBUSY;
		goto fail;
	}

	if (err) {
		dev_err(&pdev->dev, "%s unable to read status\n", __func__);
		err = -EBUSY;
		goto fail;
	}

	/* If RTC have POR values, set time using platform data*/
	tps80031_rtc_read_time(&pdev->dev, &tm);
	if ((tm.tm_year == RTC_YEAR_OFFSET + RTC_POR_YEAR) &&
		(tm.tm_mon == (RTC_POR_MONTH - 1)) &&
		(tm.tm_mday == RTC_POR_DAY)) {
		if (pdata->time.tm_year < 2000 ||
			pdata->time.tm_year > 2100) {
			dev_err(&pdev->dev, "Invalid platform data\n");
			memset(&pdata->time, 0, sizeof(pdata->time));
			pdata->time.tm_year = 2011;
			pdata->time.tm_mday = 1;
		}
		tps80031_rtc_set_time(&pdev->dev, &pdata->time);
	}

	reg = ALARM_INT_STATUS;
	err = tps80031_write_regs(&pdev->dev, RTC_STATUS, 1, &reg);
	if (err) {
		dev_err(&pdev->dev, "unable to program RTC_STATUS reg\n");
		return -EBUSY;
	}

	tps80031_enable_rtc_write(&pdev->dev);
	err = tps80031_set_bits(pdev->dev.parent, 1, RTC_INT, ENABLE_ALARM_INT);
	tps80031_disable_rtc_write(&pdev->dev);
	if (err) {
		dev_err(&pdev->dev, "unable to program Interrupt Mask reg\n");
		err = -EBUSY;
		rtc->alarm_irq_enabled = 0;
		goto fail;
	} else
		rtc->alarm_irq_enabled = 1;

	if (pdata && (pdata->irq >= 0)) {
		rtc->irq = pdata->irq;
		err = request_threaded_irq(pdata->irq, NULL, tps80031_rtc_irq,
					IRQF_ONESHOT, "rtc_tps80031",
					&pdev->dev);
		if (err) {
			dev_err(&pdev->dev, "request IRQ:%d fail\n", rtc->irq);
			rtc->irq = -1;
		} else {
			device_init_wakeup(&pdev->dev, 1);
			enable_irq_wake(rtc->irq);
		}
	}
	return 0;

fail:
	if (!IS_ERR_OR_NULL(rtc->rtc))
		rtc_device_unregister(rtc->rtc);
	kfree(rtc);
	return err;
}
Beispiel #9
0
static int tps80031_rtc_probe(struct platform_device *pdev)
{
	struct tps80031_rtc *rtc;
	struct rtc_time tm;
	int ret;

	rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
	if (!rtc)
		return -ENOMEM;

	rtc->irq = platform_get_irq(pdev, 0);
	platform_set_drvdata(pdev, rtc);

	/* Start RTC */
	ret = tps80031_set_bits(pdev->dev.parent, TPS80031_SLAVE_ID1,
			TPS80031_RTC_CTRL_REG, STOP_RTC);
	if (ret < 0) {
		dev_err(&pdev->dev, "failed to start RTC. err = %d\n", ret);
		return ret;
	}

	/* If RTC have POR values, set time 01:01:2000 */
	tps80031_rtc_read_time(&pdev->dev, &tm);
	if ((tm.tm_year == RTC_YEAR_OFFSET + TPS80031_RTC_POR_YEAR) &&
		(tm.tm_mon == (TPS80031_RTC_POR_MONTH - 1)) &&
		(tm.tm_mday == TPS80031_RTC_POR_DAY)) {
		tm.tm_year = 2000;
		tm.tm_mday = 1;
		tm.tm_mon = 1;
		ret = tps80031_rtc_set_time(&pdev->dev, &tm);
		if (ret < 0) {
			dev_err(&pdev->dev,
				"RTC set time failed, err = %d\n", ret);
			return ret;
		}
	}

	/* Clear alarm intretupt status if it is there */
	ret = clear_alarm_int_status(&pdev->dev, rtc);
	if (ret < 0) {
		dev_err(&pdev->dev, "Clear alarm int failed, err = %d\n", ret);
		return ret;
	}

	rtc->rtc = rtc_device_register(pdev->name, &pdev->dev,
			       &tps80031_rtc_ops, THIS_MODULE);
	if (IS_ERR(rtc->rtc)) {
		ret = PTR_ERR(rtc->rtc);
		dev_err(&pdev->dev, "RTC registration failed, err %d\n", ret);
		return ret;
	}

	ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL,
			tps80031_rtc_irq,
			IRQF_ONESHOT | IRQF_EARLY_RESUME,
			dev_name(&pdev->dev), rtc);
	if (ret < 0) {
		dev_err(&pdev->dev, "request IRQ:%d failed, err = %d\n",
			 rtc->irq, ret);
		rtc_device_unregister(rtc->rtc);
		return ret;
	}
	device_set_wakeup_capable(&pdev->dev, 1);
	return 0;
}
Beispiel #10
0
/*ZTE:add by caixiaoguang 20120531 for charge--*/
static int configure_charging_parameter(struct tps80031_charger *charger)
{
    int ret;
    int max_charge_current;
    int max_charge_volt;
    int term_current;
    uint8_t chargerusb_vichrg_reg;
    uint8_t chargerusb_int__mask_reg;
    int vbus_preset = -1;
    int chargertype = -1;
    /* Disable watchdog timer */
    ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                         CONTROLLER_WDG, 0x0);
    if (ret < 0) {
        dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                __func__, CONTROLLER_WDG);
        return ret;
    }

    /* Disable the charging if any */
    ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                         CONTROLLER_CTRL1, 0x0);
    if (ret < 0) {
        dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                __func__, CONTROLLER_CTRL1);
        return ret;
    }

    if (charger->board_init) {
        ret = charger->board_init(charger->board_data);
        if (ret < 0) {
            dev_err(charger->dev, "%s(): Failed in board init\n",
                    __func__);
            return ret;
        }
    }

    /* Unlock value */
    ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                         CHARGERUSB_CTRLLIMIT2, 0);
    if (ret < 0) {
        dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                __func__, CHARGERUSB_CTRLLIMIT2);
        return ret;
    }

    /* Set max current limit */
#if 0
    max_charge_current = min(1500, charger->max_charge_current_mA);
    if (max_charge_current < 100)
        max_charge_current = 0;
    else
        max_charge_current = (max_charge_current - 100)/100;
    max_charge_current &= 0xF;
    ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                         CHARGERUSB_CTRLLIMIT2, (uint8_t)max_charge_current);
    if (ret < 0) {
        dev_err(charger->dev, "%s(): Failed in writing register "
                "0x%02x\n", __func__, CHARGERUSB_CTRLLIMIT2);
        return ret;
    }
#endif

    /* Set max voltage limit */
    max_charge_volt = min(4760, charger->max_charge_volt_mV);
    max_charge_volt = max(3500, max_charge_volt);
    max_charge_volt -= 3500;
    max_charge_volt = max_charge_volt/20;
    ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                         CHARGERUSB_CTRLLIMIT1, (uint8_t)max_charge_volt);
    if (ret < 0) {
        dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                __func__, CHARGERUSB_CTRLLIMIT1);
        return ret;
    }
#if 0
    /* Lock value */
    ret = tps80031_set_bits(charger->dev->parent, SLAVE_ID2,
                            CHARGERUSB_CTRLLIMIT2, (1 << 4));
    if (ret < 0) {
        dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                __func__, CHARGERUSB_CTRLLIMIT2);
        return ret;
    }
#endif
    /* set Pre Charge current to 400mA */
    ret = tps80031_write(charger->dev->parent, SLAVE_ID2, 0xDE, 0x3);
    if (ret < 0) {
        dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                __func__, 0xDD);
        return ret;
    }

    /* set charging termination current*/
    if (charger->charging_term_current_mA > 400)
        term_current =  7;
    else
        term_current = (charger->charging_term_current_mA - 50)/50;
    term_current = term_current << 5;
    ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                         CHARGERUSB_CTRL2, term_current);
    if (ret < 0) {
        dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                __func__, CHARGERUSB_CTRL2);
        return ret;
    }
    /*ZTE:add by caixiaoguang 20120531 for charge++*/
#if 0
    vbus_preset = tps80031_get_vbus_status();
    chargertype = fsl_charger_detect();
    if(1 == vbus_preset)
    {
        ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                             CONTROLLER_CTRL1, 0x30);
        if (ret < 0) {
            dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                    __func__, CONTROLLER_CTRL1);
            return ret;
        }
        //AC set CINLIMIT 1000mA,USB set 500mA
        if(1==chargertype)
        {
            ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                                 CHARGERUSB_CINLIMIT, 0x29);
        }
        else
        {
            ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                                 CHARGERUSB_CINLIMIT, 0x09);
        }
        if (ret < 0) {
            dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                    __func__, CHARGERUSB_CINLIMIT);
            return ret;
        }

    }
#endif
    //mask CHARGERUSB_STAT interrupt in CHARGERUSB_INT
    ret = tps80031_read(charger->dev->parent, SLAVE_ID2,
                        0xE5, &chargerusb_int__mask_reg);
    if (ret < 0) {
        dev_err(charger->dev, "%s(): Failed in reading register 0x%02x\n",
                __func__, 0xE5);
    }
    chargerusb_int__mask_reg |= 0x1E;
    ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                         0xE5, chargerusb_int__mask_reg);
    if (ret < 0) {
        dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                __func__, 0xE5);
        return ret;
    }
    return 0;
}