Skip to content
Snippets Groups Projects
Select Git revision
  • 85ec0bcc1bc40a67368461fee0435d79305168b1
  • master default protected
  • stable
  • extraversion
  • early-display
  • variant-emmc-nvme-boot
  • 2024-07-19
  • 2024-06-30
  • 2023-10-18
  • 2023-10-10
  • 2023-07-04
  • 2023-01-25
  • v3
  • variant-emmc-nvme-boot
  • 2020-06-01
15 results

cmd_nand.c

Blame
    • Wolfgang Denk's avatar
      85ec0bcc
      * Patch by Arun Dharankar, 24 Mar 2003: · 85ec0bcc
      Wolfgang Denk authored
        - add threads / scheduler example code
      
      * Add patches by Robert Schwebel, 31 Mar 2003:
        - add ctrl-c support for kermit download
        - align bdinfo output on ARM
      
      * Add CPU ID, version, and clock speed for INCA-IP
      85ec0bcc
      History
      * Patch by Arun Dharankar, 24 Mar 2003:
      Wolfgang Denk authored
        - add threads / scheduler example code
      
      * Add patches by Robert Schwebel, 31 Mar 2003:
        - add ctrl-c support for kermit download
        - align bdinfo output on ARM
      
      * Add CPU ID, version, and clock speed for INCA-IP
    bfin_rtc.c 2.85 KiB
    /*
     * Copyright (c) 2004-2008 Analog Devices Inc.
     *
     * (C) Copyright 2001
     * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
     *
     * Licensed under the GPL-2 or later.
     */
    
    #include <common.h>
    #include <command.h>
    #include <rtc.h>
    
    #if defined(CONFIG_CMD_DATE)
    
    #include <asm/blackfin.h>
    #include <asm/mach-common/bits/rtc.h>
    
    #define pr_stamp() debug("%s:%s:%i: here i am\n", __FILE__, __func__, __LINE__)
    
    #define MIN_TO_SECS(x)    (60 * (x))
    #define HRS_TO_SECS(x)    (60 * MIN_TO_SECS(x))
    #define DAYS_TO_SECS(x)   (24 * HRS_TO_SECS(x))
    
    #define NUM_SECS_IN_MIN   MIN_TO_SECS(1)
    #define NUM_SECS_IN_HR    HRS_TO_SECS(1)
    #define NUM_SECS_IN_DAY   DAYS_TO_SECS(1)
    
    /* Our on-chip RTC has no notion of "reset" */
    void rtc_reset(void)
    {
    	return;
    }
    
    /* Wait for pending writes to complete */
    static void wait_for_complete(void)
    {
    	pr_stamp();
    	while (!(bfin_read_RTC_ISTAT() & WRITE_COMPLETE))
    		if (!(bfin_read_RTC_ISTAT() & WRITE_PENDING))
    			break;
    	bfin_write_RTC_ISTAT(WRITE_COMPLETE);
    }
    
    /* Enable the RTC prescaler enable register */
    int rtc_init(void)
    {
    	pr_stamp();
    	bfin_write_RTC_PREN(0x1);
    	return 0;
    }
    
    /* Set the time. Get the time_in_secs which is the number of seconds since Jan 1970 and set the RTC registers
     * based on this value.
     */
    void rtc_set(struct rtc_time *tmp)
    {
    	unsigned long remain, days, hrs, mins, secs;
    
    	pr_stamp();
    
    	if (tmp == NULL) {
    		puts("Error setting the date/time\n");
    		return;
    	}
    
    	wait_for_complete();
    
    	/* Calculate number of seconds this incoming time represents */
    	remain = mktime(tmp->tm_year, tmp->tm_mon, tmp->tm_mday,
    	                tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
    
    	/* Figure out how many days since epoch */
    	days = remain / NUM_SECS_IN_DAY;
    
    	/* From the remaining secs, compute the hrs(0-23), mins(0-59) and secs(0-59) */
    	remain = remain % NUM_SECS_IN_DAY;
    	hrs = remain / NUM_SECS_IN_HR;
    	remain = remain % NUM_SECS_IN_HR;
    	mins = remain / NUM_SECS_IN_MIN;
    	secs = remain % NUM_SECS_IN_MIN;
    
    	/* Encode these time values into our RTC_STAT register */
    	bfin_write_RTC_STAT(SET_ALARM(days, hrs, mins, secs));
    }
    
    /* Read the time from the RTC_STAT. time_in_seconds is seconds since Jan 1970 */
    int rtc_get(struct rtc_time *tmp)
    {
    	uint32_t cur_rtc_stat;
    	int time_in_sec;
    	int tm_sec, tm_min, tm_hr, tm_day;
    
    	pr_stamp();
    
    	if (tmp == NULL) {
    		puts("Error getting the date/time\n");
    		return -1;
    	}
    
    	wait_for_complete();
    
    	/* Read the RTC_STAT register */
    	cur_rtc_stat = bfin_read_RTC_STAT();
    
    	/* Convert our encoded format into actual time values */
    	tm_sec = (cur_rtc_stat & RTC_SEC) >> RTC_SEC_P;
    	tm_min = (cur_rtc_stat & RTC_MIN) >> RTC_MIN_P;
    	tm_hr  = (cur_rtc_stat & RTC_HR ) >> RTC_HR_P;
    	tm_day = (cur_rtc_stat & RTC_DAY) >> RTC_DAY_P;
    
    	/* Calculate the total number of seconds since epoch */
    	time_in_sec = (tm_sec) + MIN_TO_SECS(tm_min) + HRS_TO_SECS(tm_hr) + DAYS_TO_SECS(tm_day);
    	to_tm(time_in_sec, tmp);
    
    	return 0;
    }
    
    #endif