<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><div><div class="Section1">
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Problem:<o:p></o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">When processor dependent macros are 
set to use RTC ie (ppc_md.set_rtc_time = mydriver_set_rtc; ppc_md.get_rtc_time = 
mydriver_get_rtc_time;), then the scheduler gets messed up and prints a message 
“scheduling when atomic”.<o:p></o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">System time is not synced to RTC 
time.<o:p></o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"><o:p>&nbsp;</o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Details:<o:p></o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Processor: 
MPC8245<o:p></o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Kernel version: Linux 
2.6.14<o:p></o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">RTC chip: DS1340 (I2c 
based)<o:p></o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Driver used: Standard kernel version 
2.6.17 or later has a driver for RTC DS1340. I ported it to work with our 
version of the kernel. So it is the driver provided by later version of the 
standard kernel.<o:p></o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"><o:p>&nbsp;</o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">I have added the driver and the read 
and write to the RTC works fine. Time that is set to the rtc remains on the RTC 
even through successive reboots. So the driver is working 
fine.<o:p></o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">However we needed to sync the system 
time with the RTC. For this purpose, I tried to use the drivers/rtc/hctosys.c 
code. This code reads the time from the RTC during bootup, and does a 
do_settimeofday so that system time reflects the time in the RTC. However, with 
this change, as soon as settimeofday happens, I read it back, it displays the 
correct time (same as RTC), but after system boots up, the system time is messed 
up again. <o:p></o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"><o:p>&nbsp;</o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Another thing that I changed was the 
ppc_md.get_rtc_time and ppc_md.set_rtc_time – these function pointers were 
pointed to my driver’s get_rtc_time and 
set_rtc_time.<o:p></o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"><o:p>&nbsp;</o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">In the same function, 
ppc_md.calibrate_decr is set to initialize the decrementer register. However the 
ppc_md.time_init has still not been set. I looked up MPC8349 example and they 
are enabling the ‘time base’ in this function. However for 8245 the time base 
enable is not a bit in a register, but it is a signal. So does the 
ppc_md.time_init need to be pointed to some function – what should that function 
do? Is it needed at all?<o:p></o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Also, having set the 
ppc_md.calibrate_decr, ppc_md.get_rtc_time and ppc_md.set_rtc_time, when the 
system boots up, the scheduler prints a message that says “scheduling when 
atomic” and the system doesn’t boot beyond this 
point.<o:p></o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"><o:p>&nbsp;</o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">I have set these ppc_md function 
pointers late during the bootup because it depends on initialization of the RTC 
driver before these pointers are set. <o:p></o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"><o:p>&nbsp;</o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Now as I understand, before the RTC 
is available, the processor uses the decrementer register to keep time for the 
scheduler. When the ppc_md.get/set_rtc_time are set, the processor starts using 
the RTC to keep time. However the point where the handover from decrementer to 
RTC happens is the point where the scheduler gets messed up. 
<o:p></o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"><o:p>&nbsp;</o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Can you please guide me as to what 
is the right way for me to use the RTC. Which are the places other than the 
driver that I need to modify/add?<o:p></o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"><o:p>&nbsp;</o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Thanks,<o:p></o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Aniket.<o:p></o:p></span></font></p></div></div></div><br>

<hr size=1>Want to start your own business? Learn how on <a href="http://us.rd.yahoo.com/evt=41244/*http://smallbusiness.yahoo.com/r-index">Yahoo! Small Business.</a></body></html>