• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #ifndef I2S_CORE_H
10 #define I2S_CORE_H
11 
12 #include "hdf_base.h"
13 #include "hdf_device_desc.h"
14 #include "hdf_dlist.h"
15 #include "i2s_if.h"
16 #include "osal_mutex.h"
17 
18 
19 struct I2sCntlr;
20 
21 struct I2sCntlrMethod {
22     int32_t (*GetCfg)(struct I2sCntlr *cntlr, struct I2sCfg *cfg);
23     int32_t (*SetCfg)(struct I2sCntlr *cntlr, struct I2sCfg *cfg);
24     int32_t (*Transfer)(struct I2sCntlr *cntlr, struct I2sMsg *msg);
25     int32_t (*Open)(struct I2sCntlr *cntlr);
26     int32_t (*Close)(struct I2sCntlr *cntlr);
27     int32_t (*Enable)(struct I2sCntlr *cntlr);
28     int32_t (*Disable)(struct I2sCntlr *cntlr);
29     int32_t (*StartWrite)(struct I2sCntlr *cntlr);
30     int32_t (*StopWrite)(struct I2sCntlr *cntlr);
31     int32_t (*StartRead)(struct I2sCntlr *cntlr);
32     int32_t (*StopRead)(struct I2sCntlr *cntlr);
33 };
34 
35 struct I2sCntlr {
36     struct IDeviceIoService service;
37     struct HdfDeviceObject *device;
38     uint32_t busNum;
39     uint32_t irqNum;
40     struct OsalMutex lock;
41     struct I2sCntlrMethod *method;
42     void *priv; // private data
43 };
44 
45 /**
46  * @brief Turn HdfDeviceObject to an I2sCntlr.
47  *
48  * @param device Indicates a HdfDeviceObject.
49  *
50  * @return Retrns the pointer of the I2sCntlr on success; returns NULL otherwise.
51  * @since 1.0
52  */
I2sCntlrFromDevice(const struct HdfDeviceObject * device)53 static inline struct I2sCntlr *I2sCntlrFromDevice(const struct HdfDeviceObject *device)
54 {
55     return (device == NULL) ? NULL : (struct I2sCntlr *)device->service;
56 }
57 
58 struct I2sCntlr *I2sCntlrCreate(struct HdfDeviceObject *device);
59 void I2sCntlrDestroy(struct I2sCntlr *cntlr);
60 int32_t I2sCntlrStartRead(struct I2sCntlr *cntlr);
61 int32_t I2sCntlrStopRead(struct I2sCntlr *cntlr);
62 int32_t I2sCntlrStartWrite(struct I2sCntlr *cntlr);
63 int32_t I2sCntlrStopWrite(struct I2sCntlr *cntlr);
64 int32_t I2sCntlrOpen(struct I2sCntlr *cntlr);
65 int32_t I2sCntlrClose(struct I2sCntlr *cntlr);
66 int32_t I2sCntlrEnable(struct I2sCntlr *cntlr);
67 int32_t I2sCntlrDisable(struct I2sCntlr *cntlr);
68 int32_t I2sCntlrSetCfg(struct I2sCntlr *cntlr, struct I2sCfg *cfg);
69 int32_t I2sCntlrGetCfg(struct I2sCntlr *cntlr, struct I2sCfg *cfg);
70 int32_t I2sCntlrTransfer(struct I2sCntlr *cntlr, struct I2sMsg *msg);
71 #endif /* I2S_CORE_H */
72