device: convert to stopwatch API
Instead of open coding the monotonic timers use the stopwatch
abstraction.
BUG=None
BRANCH=None
TEST=Booted and noted timings work as expected. Built with software_i2c
     and no compilation failures.
Change-Id: Ie5ecdd5bc764c1ab8ba4a923e65a1666aacd22f7
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: c7bffb5aeb41e9b88cd2c99edd6abc38f1dc90af
Original-Change-Id: I0170fe4b93d9976957a2dcb00a6ea41ddc0320ce
Original-Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/219495
Original-Reviewed-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: http://review.coreboot.org/8817
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
			
			
This commit is contained in:
		
				
					committed by
					
						
						Patrick Georgi
					
				
			
			
				
	
			
			
			
						parent
						
							ad5a909740
						
					
				
				
					commit
					46ba4807e9
				
			@@ -1139,10 +1139,8 @@ static void init_dev(struct device *dev)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	if (!dev->initialized && dev->ops && dev->ops->init) {
 | 
						if (!dev->initialized && dev->ops && dev->ops->init) {
 | 
				
			||||||
#if CONFIG_HAVE_MONOTONIC_TIMER
 | 
					#if CONFIG_HAVE_MONOTONIC_TIMER
 | 
				
			||||||
		struct mono_time start_time;
 | 
							struct stopwatch sw;
 | 
				
			||||||
		struct rela_time dev_init_time;
 | 
							stopwatch_init(&sw);
 | 
				
			||||||
 | 
					 | 
				
			||||||
		timer_monotonic_get(&start_time);
 | 
					 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
		if (dev->path.type == DEVICE_PATH_I2C) {
 | 
							if (dev->path.type == DEVICE_PATH_I2C) {
 | 
				
			||||||
			printk(BIOS_DEBUG, "smbus: %s[%d]->",
 | 
								printk(BIOS_DEBUG, "smbus: %s[%d]->",
 | 
				
			||||||
@@ -1153,9 +1151,8 @@ static void init_dev(struct device *dev)
 | 
				
			|||||||
		dev->initialized = 1;
 | 
							dev->initialized = 1;
 | 
				
			||||||
		dev->ops->init(dev);
 | 
							dev->ops->init(dev);
 | 
				
			||||||
#if CONFIG_HAVE_MONOTONIC_TIMER
 | 
					#if CONFIG_HAVE_MONOTONIC_TIMER
 | 
				
			||||||
		dev_init_time = current_time_from(&start_time);
 | 
					 | 
				
			||||||
		printk(BIOS_DEBUG, "%s init %ld usecs\n", dev_path(dev),
 | 
							printk(BIOS_DEBUG, "%s init %ld usecs\n", dev_path(dev),
 | 
				
			||||||
		       rela_time_in_microseconds(&dev_init_time));
 | 
								stopwatch_duration_usecs(&sw));
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -44,20 +44,21 @@ static int __wait(unsigned bus, int timeout_us, int for_scl)
 | 
				
			|||||||
	int us;
 | 
						int us;
 | 
				
			||||||
	int sda = software_i2c[bus]->get_sda(bus);
 | 
						int sda = software_i2c[bus]->get_sda(bus);
 | 
				
			||||||
	int scl = software_i2c[bus]->get_scl(bus);
 | 
						int scl = software_i2c[bus]->get_scl(bus);
 | 
				
			||||||
	struct mono_time start;
 | 
						struct stopwatch sw;
 | 
				
			||||||
	timer_monotonic_get(&start);
 | 
					
 | 
				
			||||||
 | 
						stopwatch_init_usecs_expire(&sw, timeout_us);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	do {
 | 
						do {
 | 
				
			||||||
		int old_sda = sda;
 | 
							int old_sda = sda;
 | 
				
			||||||
		int old_scl = scl;
 | 
							int old_scl = scl;
 | 
				
			||||||
		struct rela_time diff = current_time_from(&start);
 | 
					
 | 
				
			||||||
		us = rela_time_in_microseconds(&diff);
 | 
							us = stopwatch_duration_usecs(&sw);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (old_sda != (sda = software_i2c[bus]->get_sda(bus)))
 | 
							if (old_sda != (sda = software_i2c[bus]->get_sda(bus)))
 | 
				
			||||||
			spew("[SDA transitioned to %d after %dus] ", sda, us);
 | 
								spew("[SDA transitioned to %d after %dus] ", sda, us);
 | 
				
			||||||
		if (old_scl != (scl = software_i2c[bus]->get_scl(bus)))
 | 
							if (old_scl != (scl = software_i2c[bus]->get_scl(bus)))
 | 
				
			||||||
			spew("[SCL transitioned to %d after %dus] ", scl, us);
 | 
								spew("[SCL transitioned to %d after %dus] ", scl, us);
 | 
				
			||||||
	} while (us < timeout_us && (!for_scl || !scl));
 | 
						} while (!stopwatch_expired(&sw) && (!for_scl || !scl));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return scl;
 | 
						return scl;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user