xref: /optee_os/core/include/spi.h (revision 1bb929836182ecb96d2d9d268daa807c67596396)
1*1bb92983SJerome Forissier /* SPDX-License-Identifier: BSD-2-Clause */
2aca1545dSVictor Chong /*
3aca1545dSVictor Chong  * Copyright (c) 2016, Linaro Limited
4aca1545dSVictor Chong  * All rights reserved.
5aca1545dSVictor Chong  *
6aca1545dSVictor Chong  * Redistribution and use in source and binary forms, with or without
7aca1545dSVictor Chong  * modification, are permitted provided that the following conditions are met:
8aca1545dSVictor Chong  *
9aca1545dSVictor Chong  * 1. Redistributions of source code must retain the above copyright notice,
10aca1545dSVictor Chong  * this list of conditions and the following disclaimer.
11aca1545dSVictor Chong  *
12aca1545dSVictor Chong  * 2. Redistributions in binary form must reproduce the above copyright notice,
13aca1545dSVictor Chong  * this list of conditions and the following disclaimer in the documentation
14aca1545dSVictor Chong  * and/or other materials provided with the distribution.
15aca1545dSVictor Chong  *
16aca1545dSVictor Chong  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17aca1545dSVictor Chong  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18aca1545dSVictor Chong  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19aca1545dSVictor Chong  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20aca1545dSVictor Chong  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21aca1545dSVictor Chong  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22aca1545dSVictor Chong  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23aca1545dSVictor Chong  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24aca1545dSVictor Chong  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25aca1545dSVictor Chong  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26aca1545dSVictor Chong  * POSSIBILITY OF SUCH DAMAGE.
27aca1545dSVictor Chong  */
28aca1545dSVictor Chong 
29aca1545dSVictor Chong #ifndef __SPI_H__
30aca1545dSVictor Chong #define __SPI_H__
31aca1545dSVictor Chong 
32aca1545dSVictor Chong #include <types_ext.h>
33aca1545dSVictor Chong 
34aca1545dSVictor Chong enum spi_mode {
35aca1545dSVictor Chong 	SPI_MODE0,
36aca1545dSVictor Chong 	SPI_MODE1,
37aca1545dSVictor Chong 	SPI_MODE2,
38aca1545dSVictor Chong 	SPI_MODE3
39aca1545dSVictor Chong };
40aca1545dSVictor Chong 
419a2efe04SVictor Chong enum spi_result {
429a2efe04SVictor Chong 	SPI_OK,
439a2efe04SVictor Chong 	SPI_ERR_CFG,
449a2efe04SVictor Chong 	SPI_ERR_PKTCNT,
459a2efe04SVictor Chong 	SPI_ERR_GENERIC
469a2efe04SVictor Chong };
479a2efe04SVictor Chong 
48aca1545dSVictor Chong struct spi_chip {
49aca1545dSVictor Chong 	const struct spi_ops *ops;
50aca1545dSVictor Chong };
51aca1545dSVictor Chong 
52aca1545dSVictor Chong struct spi_ops {
536356eeb2SVictor Chong 	void (*configure)(struct spi_chip *chip);
546356eeb2SVictor Chong 	void (*start)(struct spi_chip *chip);
559a2efe04SVictor Chong 	enum spi_result (*txrx8)(struct spi_chip *chip, uint8_t *wdat,
569a2efe04SVictor Chong 		uint8_t *rdat, size_t num_pkts);
579a2efe04SVictor Chong 	enum spi_result (*txrx16)(struct spi_chip *chip, uint16_t *wdat,
589a2efe04SVictor Chong 		uint16_t *rdat, size_t num_pkts);
596356eeb2SVictor Chong 	void (*end)(struct spi_chip *chip);
60aca1545dSVictor Chong };
61aca1545dSVictor Chong 
62aca1545dSVictor Chong #endif	/* __SPI_H__ */
63aca1545dSVictor Chong 
64