1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <interface/spi/spi.h>
20 #include <lib/spi/common/utils.h>
21 #include <lk/compiler.h>
22 
23 __BEGIN_CDECLS
24 
25 /**
26  * struct spi_dev_ctx - opaque SPI device context structure
27  */
28 struct spi_dev_ctx;
29 
30 /**
31  * spi_batch_state - tracks state associated with SPI batch being processed
32  * @cs:       CS state resulting from the SPI batch
33  * @num_cmds: number of commands successfully processed. Also corresponds to the
34  *            index of the failed command if an error occurred.
35  */
36 struct spi_batch_state {
37     bool cs;
38     size_t num_cmds;
39 };
40 
41 /**
42  * spi_srv_handle_batch() - handle batch of SPI requests
43  * @spi:       handle to SPI device
44  * @mb:        memory buffer containing the batch of SPI requests
45  * @batch_req: metadata about the batch of SPI requests
46  * @state:     keeps track of device state as the batch is being processed
47  *
48  * Return: 0 on success, negative error code otherwise
49  */
50 int spi_srv_handle_batch(struct spi_dev_ctx* spi,
51                          struct mem_buf* mb,
52                          struct spi_batch_req* batch_req,
53                          struct spi_batch_state* state);
54 
55 __END_CDECLS
56