Re: [PATCH] RTC: DaVinci RTC driver

From: Andrew Morton
Date: Mon Mar 15 2010 - 17:21:17 EST


On Fri, 12 Mar 2010 11:08:33 -0800
Kevin Hilman <khilman@xxxxxxxxxxxxxxxxxxx> wrote:

> +static int convertfromdays(u16 days, struct rtc_time *tm)
> +{
> + int tmp_days, year, mon;
> +
> + for (year = 2000;; year++) {
> + tmp_days = rtc_year_days(1, 12, year);
> + if (days >= tmp_days)
> + days -= tmp_days;
> + else {
> + for (mon = 0;; mon++) {
> + tmp_days = rtc_month_days(mon, year);
> + if (days >= tmp_days) {
> + days -= tmp_days;
> + } else {
> + tm->tm_year = year - 1900;
> + tm->tm_mon = mon;
> + tm->tm_mday = days + 1;
> + break;
> + }
> + }
> + break;
> + }
> + }
> + return 0;
> +}
> +
> +static int convert2days(u16 *days, struct rtc_time *tm)
> +{
> + int i;
> + *days = 0;
> +
> + /* epoch == 1900 */
> + if (tm->tm_year < 100 || tm->tm_year > 199)
> + return -EINVAL;
> +
> + for (i = 2000; i < 1900 + tm->tm_year; i++)
> + *days += rtc_year_days(1, 12, i);
> +
> + *days += rtc_year_days(tm->tm_mday, tm->tm_mon, 1900 + tm->tm_year);
> +
> + return 0;
> +}

I'm looking suspiciously at these (slow-looking) functions. Are they
really specific to this device, or could we be making better use of
library code, or adding functionality to library code?

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/