mirror of
				https://review.coreboot.org/flashrom.git
				synced 2025-10-31 05:10:41 +01:00 
			
		
		
		
	linux_spi: Hardcode default spispeed of 2MHz
Leaving the `linux_spi` driver's unknown default is almost never what we want and resulted in many support requests since Raspbian switched to a default that is too high for most applications. Change-Id: I9361b7c1a1ab8900a619b06e1dae14cd87eb56c2 Signed-off-by: Nico Huber <nico.h@gmx.de> Reviewed-on: https://review.coreboot.org/c/30371 Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
		
							
								
								
									
										23
									
								
								linux_spi.c
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								linux_spi.c
									
									
									
									
									
								
							| @@ -22,6 +22,8 @@ | |||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| #include <string.h> | #include <string.h> | ||||||
| #include <stdlib.h> | #include <stdlib.h> | ||||||
|  | #include <stdint.h> | ||||||
|  | #include <inttypes.h> | ||||||
| #include <fcntl.h> | #include <fcntl.h> | ||||||
| #include <errno.h> | #include <errno.h> | ||||||
| #include <ctype.h> | #include <ctype.h> | ||||||
| @@ -67,7 +69,7 @@ static const struct spi_master spi_master_linux = { | |||||||
| int linux_spi_init(void) | int linux_spi_init(void) | ||||||
| { | { | ||||||
| 	char *p, *endp, *dev; | 	char *p, *endp, *dev; | ||||||
| 	uint32_t speed_hz = 0; | 	uint32_t speed_hz = 2 * 1000 * 1000; | ||||||
| 	/* FIXME: make the following configurable by CLI options. */ | 	/* FIXME: make the following configurable by CLI options. */ | ||||||
| 	/* SPI mode 0 (beware this also includes: MSB first, CS active low and others */ | 	/* SPI mode 0 (beware this also includes: MSB first, CS active low and others */ | ||||||
| 	const uint8_t mode = SPI_MODE_0; | 	const uint8_t mode = SPI_MODE_0; | ||||||
| @@ -76,11 +78,15 @@ int linux_spi_init(void) | |||||||
| 	p = extract_programmer_param("spispeed"); | 	p = extract_programmer_param("spispeed"); | ||||||
| 	if (p && strlen(p)) { | 	if (p && strlen(p)) { | ||||||
| 		speed_hz = (uint32_t)strtoul(p, &endp, 10) * 1000; | 		speed_hz = (uint32_t)strtoul(p, &endp, 10) * 1000; | ||||||
| 		if (p == endp) { | 		if (p == endp || speed_hz == 0) { | ||||||
| 			msg_perr("%s: invalid clock: %s kHz\n", __func__, p); | 			msg_perr("%s: invalid clock: %s kHz\n", __func__, p); | ||||||
| 			free(p); | 			free(p); | ||||||
| 			return 1; | 			return 1; | ||||||
| 		} | 		} | ||||||
|  | 	} else { | ||||||
|  | 		msg_pinfo("Using default %"PRIu32 | ||||||
|  | 			  "kHz clock. Use 'spispeed' parameter to override.\n", | ||||||
|  | 			  speed_hz / 1000); | ||||||
| 	} | 	} | ||||||
| 	free(p); | 	free(p); | ||||||
|  |  | ||||||
| @@ -105,15 +111,12 @@ int linux_spi_init(void) | |||||||
| 		return 1; | 		return 1; | ||||||
| 	/* We rely on the shutdown function for cleanup from here on. */ | 	/* We rely on the shutdown function for cleanup from here on. */ | ||||||
|  |  | ||||||
| 	if (speed_hz > 0) { | 	if (ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed_hz) == -1) { | ||||||
| 		if (ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed_hz) == -1) { | 		msg_perr("%s: failed to set speed to %"PRIu32"Hz: %s\n", | ||||||
| 			msg_perr("%s: failed to set speed to %d Hz: %s\n", | 			 __func__, speed_hz, strerror(errno)); | ||||||
| 				 __func__, speed_hz, strerror(errno)); | 		return 1; | ||||||
| 			return 1; |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		msg_pdbg("Using %d kHz clock\n", speed_hz/1000); |  | ||||||
| 	} | 	} | ||||||
|  | 	msg_pdbg("Using %"PRIu32"kHz clock\n", speed_hz / 1000); | ||||||
|  |  | ||||||
| 	if (ioctl(fd, SPI_IOC_WR_MODE, &mode) == -1) { | 	if (ioctl(fd, SPI_IOC_WR_MODE, &mode) == -1) { | ||||||
| 		msg_perr("%s: failed to set SPI mode to 0x%02x: %s\n", | 		msg_perr("%s: failed to set SPI mode to 0x%02x: %s\n", | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Nico Huber
					Nico Huber