コード例 #1
0
ファイル: rtc-m48t59.c プロジェクト: 274914765/C
static int m48t59_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
    struct platform_device *pdev = to_platform_device(dev);
    struct m48t59_plat_data *pdata = pdev->dev.platform_data;
    struct m48t59_private *m48t59 = platform_get_drvdata(pdev);
    unsigned long flags;
    u8 val = 0;

    dev_dbg(dev, "RTC set time %04d-%02d-%02d %02d/%02d/%02d\n",
        tm->tm_year + 1900, tm->tm_mon, tm->tm_mday,
        tm->tm_hour, tm->tm_min, tm->tm_sec);

    spin_lock_irqsave(&m48t59->lock, flags);
    /* Issue the WRITE command */
    M48T59_SET_BITS(M48T59_CNTL_WRITE, M48T59_CNTL);

    M48T59_WRITE((BIN2BCD(tm->tm_sec) & 0x7F), M48T59_SEC);
    M48T59_WRITE((BIN2BCD(tm->tm_min) & 0x7F), M48T59_MIN);
    M48T59_WRITE((BIN2BCD(tm->tm_hour) & 0x3F), M48T59_HOUR);
    M48T59_WRITE((BIN2BCD(tm->tm_mday) & 0x3F), M48T59_MDAY);
    /* tm_mon is 0-11 */
    M48T59_WRITE((BIN2BCD(tm->tm_mon + 1) & 0x1F), M48T59_MONTH);
    M48T59_WRITE(BIN2BCD(tm->tm_year % 100), M48T59_YEAR);

    if (tm->tm_year/100)
        val = (M48T59_WDAY_CEB | M48T59_WDAY_CB);
    val |= (BIN2BCD(tm->tm_wday) & 0x07);
    M48T59_WRITE(val, M48T59_WDAY);

    /* Clear the WRITE bit */
    M48T59_CLEAR_BITS(M48T59_CNTL_WRITE, M48T59_CNTL);
    spin_unlock_irqrestore(&m48t59->lock, flags);
    return 0;
}
コード例 #2
0
ファイル: rtc-m48t59.c プロジェクト: 020gzh/linux
/*
 * Set alarm time and date in RTC
 */
static int m48t59_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
{
	struct platform_device *pdev = to_platform_device(dev);
	struct m48t59_plat_data *pdata = dev_get_platdata(&pdev->dev);
	struct m48t59_private *m48t59 = platform_get_drvdata(pdev);
	struct rtc_time *tm = &alrm->time;
	u8 mday, hour, min, sec;
	unsigned long flags;
	int year = tm->tm_year;

#ifdef CONFIG_SPARC
	/* Sun SPARC machines count years since 1968 */
	year -= 68;
#endif

	/* If no irq, we don't support ALARM */
	if (m48t59->irq == NO_IRQ)
		return -EIO;

	if (year < 0)
		return -EINVAL;

	/*
	 * 0xff means "always match"
	 */
	mday = tm->tm_mday;
	mday = (mday >= 1 && mday <= 31) ? bin2bcd(mday) : 0xff;
	if (mday == 0xff)
		mday = M48T59_READ(M48T59_MDAY);

	hour = tm->tm_hour;
	hour = (hour < 24) ? bin2bcd(hour) : 0x00;

	min = tm->tm_min;
	min = (min < 60) ? bin2bcd(min) : 0x00;

	sec = tm->tm_sec;
	sec = (sec < 60) ? bin2bcd(sec) : 0x00;

	spin_lock_irqsave(&m48t59->lock, flags);
	/* Issue the WRITE command */
	M48T59_SET_BITS(M48T59_CNTL_WRITE, M48T59_CNTL);

	M48T59_WRITE(mday, M48T59_ALARM_DATE);
	M48T59_WRITE(hour, M48T59_ALARM_HOUR);
	M48T59_WRITE(min, M48T59_ALARM_MIN);
	M48T59_WRITE(sec, M48T59_ALARM_SEC);

	/* Clear the WRITE bit */
	M48T59_CLEAR_BITS(M48T59_CNTL_WRITE, M48T59_CNTL);
	spin_unlock_irqrestore(&m48t59->lock, flags);

	dev_dbg(dev, "RTC set alarm time %04d-%02d-%02d %02d/%02d/%02d\n",
		year + 1900, tm->tm_mon, tm->tm_mday,
		tm->tm_hour, tm->tm_min, tm->tm_sec);
	return 0;
}
コード例 #3
0
static int m48t59_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
{
    struct platform_device *pdev = to_platform_device(dev);
    struct m48t59_plat_data *pdata = pdev->dev.platform_data;
    struct m48t59_private *m48t59 = platform_get_drvdata(pdev);
    struct rtc_time *tm = &alrm->time;
    u8 mday, hour, min, sec;
    unsigned long flags;
    int year = tm->tm_year;

#ifdef CONFIG_SPARC

    year -= 68;
#endif


    if (m48t59->irq == NO_IRQ)
        return -EIO;

    if (year < 0)
        return -EINVAL;

    mday = tm->tm_mday;
    mday = (mday >= 1 && mday <= 31) ? bin2bcd(mday) : 0xff;
    if (mday == 0xff)
        mday = M48T59_READ(M48T59_MDAY);

    hour = tm->tm_hour;
    hour = (hour < 24) ? bin2bcd(hour) : 0x00;

    min = tm->tm_min;
    min = (min < 60) ? bin2bcd(min) : 0x00;

    sec = tm->tm_sec;
    sec = (sec < 60) ? bin2bcd(sec) : 0x00;

    spin_lock_irqsave(&m48t59->lock, flags);

    M48T59_SET_BITS(M48T59_CNTL_WRITE, M48T59_CNTL);

    M48T59_WRITE(mday, M48T59_ALARM_DATE);
    M48T59_WRITE(hour, M48T59_ALARM_HOUR);
    M48T59_WRITE(min, M48T59_ALARM_MIN);
    M48T59_WRITE(sec, M48T59_ALARM_SEC);


    M48T59_CLEAR_BITS(M48T59_CNTL_WRITE, M48T59_CNTL);
    spin_unlock_irqrestore(&m48t59->lock, flags);

    dev_dbg(dev, "RTC set alarm time %04d-%02d-%02d %02d/%02d/%02d\n",
            year + 1900, tm->tm_mon, tm->tm_mday,
            tm->tm_hour, tm->tm_min, tm->tm_sec);
    return 0;
}
コード例 #4
0
ファイル: rtc-m48t59.c プロジェクト: 020gzh/linux
/*
 * Read alarm time and date in RTC
 */
static int m48t59_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
{
	struct platform_device *pdev = to_platform_device(dev);
	struct m48t59_plat_data *pdata = dev_get_platdata(&pdev->dev);
	struct m48t59_private *m48t59 = platform_get_drvdata(pdev);
	struct rtc_time *tm = &alrm->time;
	unsigned long flags;
	u8 val;

	/* If no irq, we don't support ALARM */
	if (m48t59->irq == NO_IRQ)
		return -EIO;

	spin_lock_irqsave(&m48t59->lock, flags);
	/* Issue the READ command */
	M48T59_SET_BITS(M48T59_CNTL_READ, M48T59_CNTL);

	tm->tm_year = bcd2bin(M48T59_READ(M48T59_YEAR));
#ifdef CONFIG_SPARC
	/* Sun SPARC machines count years since 1968 */
	tm->tm_year += 68;
#endif
	/* tm_mon is 0-11 */
	tm->tm_mon = bcd2bin(M48T59_READ(M48T59_MONTH)) - 1;

	val = M48T59_READ(M48T59_WDAY);
	if ((val & M48T59_WDAY_CEB) && (val & M48T59_WDAY_CB))
		tm->tm_year += 100;	/* one century */

	tm->tm_mday = bcd2bin(M48T59_READ(M48T59_ALARM_DATE));
	tm->tm_hour = bcd2bin(M48T59_READ(M48T59_ALARM_HOUR));
	tm->tm_min = bcd2bin(M48T59_READ(M48T59_ALARM_MIN));
	tm->tm_sec = bcd2bin(M48T59_READ(M48T59_ALARM_SEC));

	/* Clear the READ bit */
	M48T59_CLEAR_BITS(M48T59_CNTL_READ, M48T59_CNTL);
	spin_unlock_irqrestore(&m48t59->lock, flags);

	dev_dbg(dev, "RTC read alarm time %04d-%02d-%02d %02d/%02d/%02d\n",
		tm->tm_year + 1900, tm->tm_mon, tm->tm_mday,
		tm->tm_hour, tm->tm_min, tm->tm_sec);
	return rtc_valid_tm(tm);
}
コード例 #5
0
ファイル: rtc-m48t59.c プロジェクト: 020gzh/linux
static int m48t59_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
	struct platform_device *pdev = to_platform_device(dev);
	struct m48t59_plat_data *pdata = dev_get_platdata(&pdev->dev);
	struct m48t59_private *m48t59 = platform_get_drvdata(pdev);
	unsigned long flags;
	u8 val = 0;
	int year = tm->tm_year;

#ifdef CONFIG_SPARC
	/* Sun SPARC machines count years since 1968 */
	year -= 68;
#endif

	dev_dbg(dev, "RTC set time %04d-%02d-%02d %02d/%02d/%02d\n",
		year + 1900, tm->tm_mon, tm->tm_mday,
		tm->tm_hour, tm->tm_min, tm->tm_sec);

	if (year < 0)
		return -EINVAL;

	spin_lock_irqsave(&m48t59->lock, flags);
	/* Issue the WRITE command */
	M48T59_SET_BITS(M48T59_CNTL_WRITE, M48T59_CNTL);

	M48T59_WRITE((bin2bcd(tm->tm_sec) & 0x7F), M48T59_SEC);
	M48T59_WRITE((bin2bcd(tm->tm_min) & 0x7F), M48T59_MIN);
	M48T59_WRITE((bin2bcd(tm->tm_hour) & 0x3F), M48T59_HOUR);
	M48T59_WRITE((bin2bcd(tm->tm_mday) & 0x3F), M48T59_MDAY);
	/* tm_mon is 0-11 */
	M48T59_WRITE((bin2bcd(tm->tm_mon + 1) & 0x1F), M48T59_MONTH);
	M48T59_WRITE(bin2bcd(year % 100), M48T59_YEAR);

	if (pdata->type == M48T59RTC_TYPE_M48T59 && (year / 100))
		val = (M48T59_WDAY_CEB | M48T59_WDAY_CB);
	val |= (bin2bcd(tm->tm_wday) & 0x07);
	M48T59_WRITE(val, M48T59_WDAY);

	/* Clear the WRITE bit */
	M48T59_CLEAR_BITS(M48T59_CNTL_WRITE, M48T59_CNTL);
	spin_unlock_irqrestore(&m48t59->lock, flags);
	return 0;
}
コード例 #6
0
static int m48t59_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
{
    struct platform_device *pdev = to_platform_device(dev);
    struct m48t59_plat_data *pdata = pdev->dev.platform_data;
    struct m48t59_private *m48t59 = platform_get_drvdata(pdev);
    struct rtc_time *tm = &alrm->time;
    unsigned long flags;
    u8 val;


    if (m48t59->irq == NO_IRQ)
        return -EIO;

    spin_lock_irqsave(&m48t59->lock, flags);

    M48T59_SET_BITS(M48T59_CNTL_READ, M48T59_CNTL);

    tm->tm_year = bcd2bin(M48T59_READ(M48T59_YEAR));
#ifdef CONFIG_SPARC

    tm->tm_year += 68;
#endif

    tm->tm_mon = bcd2bin(M48T59_READ(M48T59_MONTH)) - 1;

    val = M48T59_READ(M48T59_WDAY);
    if ((val & M48T59_WDAY_CEB) && (val & M48T59_WDAY_CB))
        tm->tm_year += 100;

    tm->tm_mday = bcd2bin(M48T59_READ(M48T59_ALARM_DATE));
    tm->tm_hour = bcd2bin(M48T59_READ(M48T59_ALARM_HOUR));
    tm->tm_min = bcd2bin(M48T59_READ(M48T59_ALARM_MIN));
    tm->tm_sec = bcd2bin(M48T59_READ(M48T59_ALARM_SEC));


    M48T59_CLEAR_BITS(M48T59_CNTL_READ, M48T59_CNTL);
    spin_unlock_irqrestore(&m48t59->lock, flags);

    dev_dbg(dev, "RTC read alarm time %04d-%02d-%02d %02d/%02d/%02d\n",
            tm->tm_year + 1900, tm->tm_mon, tm->tm_mday,
            tm->tm_hour, tm->tm_min, tm->tm_sec);
    return rtc_valid_tm(tm);
}
コード例 #7
0
ファイル: rtc-m48t59.c プロジェクト: 020gzh/linux
/*
 * NOTE: M48T59 only uses BCD mode
 */
static int m48t59_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
	struct platform_device *pdev = to_platform_device(dev);
	struct m48t59_plat_data *pdata = dev_get_platdata(&pdev->dev);
	struct m48t59_private *m48t59 = platform_get_drvdata(pdev);
	unsigned long flags;
	u8 val;

	spin_lock_irqsave(&m48t59->lock, flags);
	/* Issue the READ command */
	M48T59_SET_BITS(M48T59_CNTL_READ, M48T59_CNTL);

	tm->tm_year	= bcd2bin(M48T59_READ(M48T59_YEAR));
	/* tm_mon is 0-11 */
	tm->tm_mon	= bcd2bin(M48T59_READ(M48T59_MONTH)) - 1;
	tm->tm_mday	= bcd2bin(M48T59_READ(M48T59_MDAY));

	val = M48T59_READ(M48T59_WDAY);
	if ((pdata->type == M48T59RTC_TYPE_M48T59) &&
	    (val & M48T59_WDAY_CEB) && (val & M48T59_WDAY_CB)) {
		dev_dbg(dev, "Century bit is enabled\n");
		tm->tm_year += 100;	/* one century */
	}
#ifdef CONFIG_SPARC
	/* Sun SPARC machines count years since 1968 */
	tm->tm_year += 68;
#endif

	tm->tm_wday	= bcd2bin(val & 0x07);
	tm->tm_hour	= bcd2bin(M48T59_READ(M48T59_HOUR) & 0x3F);
	tm->tm_min	= bcd2bin(M48T59_READ(M48T59_MIN) & 0x7F);
	tm->tm_sec	= bcd2bin(M48T59_READ(M48T59_SEC) & 0x7F);

	/* Clear the READ bit */
	M48T59_CLEAR_BITS(M48T59_CNTL_READ, M48T59_CNTL);
	spin_unlock_irqrestore(&m48t59->lock, flags);

	dev_dbg(dev, "RTC read time %04d-%02d-%02d %02d/%02d/%02d\n",
		tm->tm_year + 1900, tm->tm_mon, tm->tm_mday,
		tm->tm_hour, tm->tm_min, tm->tm_sec);
	return rtc_valid_tm(tm);
}
コード例 #8
0
ファイル: rtc-m48t59.c プロジェクト: 274914765/C
/*
 * NOTE: M48T59 only uses BCD mode
 */
static int m48t59_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
    struct platform_device *pdev = to_platform_device(dev);
    struct m48t59_plat_data *pdata = pdev->dev.platform_data;
    struct m48t59_private *m48t59 = platform_get_drvdata(pdev);
    unsigned long flags;
    u8 val;

    spin_lock_irqsave(&m48t59->lock, flags);
    /* Issue the READ command */
    M48T59_SET_BITS(M48T59_CNTL_READ, M48T59_CNTL);

    tm->tm_year    = BCD2BIN(M48T59_READ(M48T59_YEAR));
    /* tm_mon is 0-11 */
    tm->tm_mon    = BCD2BIN(M48T59_READ(M48T59_MONTH)) - 1;
    tm->tm_mday    = BCD2BIN(M48T59_READ(M48T59_MDAY));

    val = M48T59_READ(M48T59_WDAY);
    if ((val & M48T59_WDAY_CEB) && (val & M48T59_WDAY_CB)) {
        dev_dbg(dev, "Century bit is enabled\n");
        tm->tm_year += 100;    /* one century */
    }

    tm->tm_wday    = BCD2BIN(val & 0x07);
    tm->tm_hour    = BCD2BIN(M48T59_READ(M48T59_HOUR) & 0x3F);
    tm->tm_min    = BCD2BIN(M48T59_READ(M48T59_MIN) & 0x7F);
    tm->tm_sec    = BCD2BIN(M48T59_READ(M48T59_SEC) & 0x7F);

    /* Clear the READ bit */
    M48T59_CLEAR_BITS(M48T59_CNTL_READ, M48T59_CNTL);
    spin_unlock_irqrestore(&m48t59->lock, flags);

    dev_dbg(dev, "RTC read time %04d-%02d-%02d %02d/%02d/%02d\n",
        tm->tm_year + 1900, tm->tm_mon, tm->tm_mday,
        tm->tm_hour, tm->tm_min, tm->tm_sec);
    return 0;
}