From 57a3fc47c21429ef6649de811f80078b15217a9b Mon Sep 17 00:00:00 2001 From: thorpej Date: Fri, 23 Feb 2024 23:45:54 +0000 Subject: [PATCH] Define mode macros for CPOL and CPHA, and define SPI_MODE_* in terms of CPOL and CPHA. Add SPI_FREQ_*() helper macros to make setting the transfer frequency less error prone. --- sys/dev/spi/spivar.h | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/sys/dev/spi/spivar.h b/sys/dev/spi/spivar.h index 807d61b7884d..832da720b6ba 100644 --- a/sys/dev/spi/spivar.h +++ b/sys/dev/spi/spivar.h @@ -1,4 +1,4 @@ -/* $NetBSD: spivar.h,v 1.12 2022/01/19 13:33:11 thorpej Exp $ */ +/* $NetBSD: spivar.h,v 1.13 2024/02/23 23:45:54 thorpej Exp $ */ /*- * Copyright (c) 2006 Urbana-Champaign Independent Media Center. @@ -55,16 +55,24 @@ struct spi_handle; struct spi_transfer; +#define SPI_MODE_CPHA __BIT(0) +#define SPI_MODE_CPOL __BIT(1) + /* * De facto standard latching modes. */ -#define SPI_MODE_0 0 /* CPOL = 0, CPHA = 0 */ -#define SPI_MODE_1 1 /* CPOL = 0, CPHA = 1 */ -#define SPI_MODE_2 2 /* CPOL = 1, CPHA = 0 */ -#define SPI_MODE_3 3 /* CPOL = 1, CPHA = 1 */ +#define SPI_MODE_0 0 +#define SPI_MODE_1 SPI_MODE_CPHA +#define SPI_MODE_2 SPI_MODE_CPOL +#define SPI_MODE_3 (SPI_MODE_CPHA | SPI_MODE_CPOL) + /* Philips' Microwire is just Mode 0 */ #define SPI_MODE_MICROWIRE SPI_MODE_0 +/* SPI transfer speed helper macros -- converts to Hz for spi_configure(). */ +#define SPI_FREQ_kHz(x) ((x) * 1000) +#define SPI_FREQ_MHz(x) ((x) * 1000000) + struct spi_controller { void *sct_cookie; /* controller private data */ int sct_nslaves;