| 
									
										
										
										
											2010-05-31 23:54:16 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * TI OMAP2 32kHz sync timer emulation. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (C) 2007-2008 Nokia Corporation | 
					
						
							|  |  |  |  * Written by Andrzej Zaborowski <andrew@openedhand.com> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License as | 
					
						
							|  |  |  |  * published by the Free Software Foundation; either version 2 or | 
					
						
							|  |  |  |  * (at your option) any later version of the License. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License along | 
					
						
							|  |  |  |  * with this program; if not, see <http://www.gnu.org/licenses/>.
 | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-01-26 18:17:18 +00:00
										 |  |  | #include "qemu/osdep.h"
 | 
					
						
							| 
									
										
										
										
											2013-02-04 15:40:22 +01:00
										 |  |  | #include "hw/hw.h"
 | 
					
						
							| 
									
										
										
										
											2012-12-17 18:20:00 +01:00
										 |  |  | #include "qemu/timer.h"
 | 
					
						
							| 
									
										
										
										
											2013-02-05 17:06:20 +01:00
										 |  |  | #include "hw/arm/omap.h"
 | 
					
						
							| 
									
										
										
										
											2010-05-31 23:54:16 +08:00
										 |  |  | struct omap_synctimer_s { | 
					
						
							| 
									
										
										
										
											2011-11-24 14:32:34 +02:00
										 |  |  |     MemoryRegion iomem; | 
					
						
							| 
									
										
										
										
											2010-05-31 23:54:16 +08:00
										 |  |  |     uint32_t val; | 
					
						
							|  |  |  |     uint16_t readh; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* 32-kHz Sync Timer of the OMAP2 */ | 
					
						
							|  |  |  | static uint32_t omap_synctimer_read(struct omap_synctimer_s *s) { | 
					
						
							| 
									
										
										
										
											2016-03-21 21:32:30 +05:30
										 |  |  |     return muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), 0x8000, | 
					
						
							|  |  |  |                     NANOSECONDS_PER_SECOND); | 
					
						
							| 
									
										
										
										
											2010-05-31 23:54:16 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void omap_synctimer_reset(struct omap_synctimer_s *s) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     s->val = omap_synctimer_read(s); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-23 12:30:10 +02:00
										 |  |  | static uint32_t omap_synctimer_readw(void *opaque, hwaddr addr) | 
					
						
							| 
									
										
										
										
											2010-05-31 23:54:16 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     struct omap_synctimer_s *s = (struct omap_synctimer_s *) opaque; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     switch (addr) { | 
					
						
							|  |  |  |     case 0x00:	/* 32KSYNCNT_REV */ | 
					
						
							|  |  |  |         return 0x21; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     case 0x10:	/* CR */ | 
					
						
							|  |  |  |         return omap_synctimer_read(s) - s->val; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     OMAP_BAD_REG(addr); | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-23 12:30:10 +02:00
										 |  |  | static uint32_t omap_synctimer_readh(void *opaque, hwaddr addr) | 
					
						
							| 
									
										
										
										
											2010-05-31 23:54:16 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     struct omap_synctimer_s *s = (struct omap_synctimer_s *) opaque; | 
					
						
							|  |  |  |     uint32_t ret; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (addr & 2) | 
					
						
							|  |  |  |         return s->readh; | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |         ret = omap_synctimer_readw(opaque, addr); | 
					
						
							|  |  |  |         s->readh = ret >> 16; | 
					
						
							|  |  |  |         return ret & 0xffff; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-23 12:30:10 +02:00
										 |  |  | static void omap_synctimer_write(void *opaque, hwaddr addr, | 
					
						
							| 
									
										
										
										
											2010-05-31 23:54:16 +08:00
										 |  |  |                 uint32_t value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     OMAP_BAD_REG(addr); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-24 14:32:34 +02:00
										 |  |  | static const MemoryRegionOps omap_synctimer_ops = { | 
					
						
							|  |  |  |     .old_mmio = { | 
					
						
							|  |  |  |         .read = { | 
					
						
							|  |  |  |             omap_badwidth_read32, | 
					
						
							|  |  |  |             omap_synctimer_readh, | 
					
						
							|  |  |  |             omap_synctimer_readw, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         .write = { | 
					
						
							|  |  |  |             omap_badwidth_write32, | 
					
						
							|  |  |  |             omap_synctimer_write, | 
					
						
							|  |  |  |             omap_synctimer_write, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     .endianness = DEVICE_NATIVE_ENDIAN, | 
					
						
							| 
									
										
										
										
											2010-05-31 23:54:16 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct omap_synctimer_s *omap_synctimer_init(struct omap_target_agent_s *ta, | 
					
						
							|  |  |  |                 struct omap_mpu_state_s *mpu, omap_clk fclk, omap_clk iclk) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-08-20 22:09:37 -05:00
										 |  |  |     struct omap_synctimer_s *s = g_malloc0(sizeof(*s)); | 
					
						
							| 
									
										
										
										
											2010-05-31 23:54:16 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     omap_synctimer_reset(s); | 
					
						
							| 
									
										
										
										
											2013-06-06 05:41:28 -04:00
										 |  |  |     memory_region_init_io(&s->iomem, NULL, &omap_synctimer_ops, s, "omap.synctimer", | 
					
						
							| 
									
										
										
										
											2011-11-24 14:32:34 +02:00
										 |  |  |                           omap_l4_region_size(ta, 0)); | 
					
						
							| 
									
										
										
										
											2011-11-28 15:40:49 +02:00
										 |  |  |     omap_l4_attach(ta, 0, &s->iomem); | 
					
						
							| 
									
										
										
										
											2010-05-31 23:54:16 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return s; | 
					
						
							|  |  |  | } |