1 /* 2 * Copyright (C) 2016 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 #ifndef __SPI_PRIV_H 18 #define __SPI_PRIV_H 19 20 #include <spi.h> 21 #include <seos.h> 22 23 struct SpiDevice { 24 const struct SpiDevice_ops *ops; 25 void *pdata; 26 }; 27 28 struct SpiDevice_ops { 29 int (*masterStartSync)(struct SpiDevice *dev, spi_cs_t cs, 30 const struct SpiMode *mode); 31 int (*masterStartAsync)(struct SpiDevice *dev, spi_cs_t cs, 32 const struct SpiMode *mode); 33 34 int (*masterRxTx)(struct SpiDevice *dev, void *rxBuf, const void *txBuf, 35 size_t size, const struct SpiMode *mode); 36 37 int (*masterStopSync)(struct SpiDevice *dev); 38 int (*masterStopAsync)(struct SpiDevice *dev); 39 40 int (*slaveStartSync)(struct SpiDevice *dev, const struct SpiMode *mode); 41 int (*slaveStartAsync)(struct SpiDevice *dev, const struct SpiMode *mode); 42 43 int (*slaveIdle)(struct SpiDevice *dev, const struct SpiMode *mode); 44 int (*slaveRxTx)(struct SpiDevice *dev, void *rxBuf, const void *txBuf, 45 size_t size, const struct SpiMode *mode); 46 47 void (*slaveSetCsInterrupt)(struct SpiDevice *dev, bool enabled); 48 bool (*slaveCsIsActive)(struct SpiDevice *dev); 49 50 int (*slaveStopSync)(struct SpiDevice *dev); 51 int (*slaveStopAsync)(struct SpiDevice *dev); 52 53 int (*release)(struct SpiDevice *dev); 54 }; 55 56 int spiRequest(struct SpiDevice *dev, uint8_t busId); 57 58 void spi_masterStartAsync_done(struct SpiDevice *dev, int err); 59 void spiMasterRxTxDone(struct SpiDevice *dev, int err); 60 void spiMasterStopAsyncDone(struct SpiDevice *dev, int err); 61 62 void spiSlaveStartAsyncDone(struct SpiDevice *dev, int err); 63 void spiSlaveRxTxDone(struct SpiDevice *dev, int err); 64 void spiSlaveCsInactive(struct SpiDevice *dev); 65 void spiSlaveStopAsyncDone(struct SpiDevice *dev, int err); 66 67 #endif /* __SPI_PRIV_H */ 68