blob: d629915129c4cc8825ad9b89abeff10a73894fb4 [file] [log] [blame]
developere0cea0f2021-12-16 16:08:26 +08001/* SPDX-License-Identifier: GPL-2.0 */
2
3#ifndef __PROSLIC_SYS_HDR__
4#define __PROSLIC_SYS_HDR__ 1
5#include <linux/types.h>
6#include <linux/time64.h> /* for struct timespec */
7
8#include <linux/spi/spi.h>
9
10#include "proslic_sys_cfg.h"
11
12
13
14/* Do a quick sanity check on channel setting */
15#define SILABS_MAX_CHAN 32
16#if (SILABS_MAX_CHANNELS > SILABS_MAX_CHAN)
17#error "ProSLIC only supports up to 32 channels"
18#endif
19
20#define PROSLIC_BCAST 0xFF
21#define PROSLIC_SPI_OK 0
22#define PROSLIC_SPI_NOK 8 /* This is what the ProSLIC API calls SPI_FAIL */
23#define PROSLIC_TIMER_ERROR 15
24
25/* Debug macros */
26#define PROSLIC_API_HDR "PROSLIC_API "
27
28#define proslic_trace(fmt, arg...) if(proslic_debug_setting & 0x1) printk( KERN_NOTICE PROSLIC_API_HDR "TRC: " fmt "\n", ##arg)
29#define proslic_debug(fmt, arg...) if(proslic_debug_setting & 0x2) printk( KERN_DEBUG PROSLIC_API_HDR "DBG: " fmt "\n", ##arg)
30#define proslic_error(fmt, arg...) if(proslic_debug_setting & 0x4) printk( KERN_ERR PROSLIC_API_HDR "ERR: " fmt "\n", ##arg)
31
32/* Data types compatible with the ProSLIC API system services layer */
33typedef u_int8_t BOOLEAN;
34typedef int8_t int8;
35typedef u_int8_t uInt8;
36typedef uInt8 uChar;
37typedef int16_t int16;
38typedef u_int16_t uInt16;
39typedef int32_t int32;
40typedef u_int32_t uInt32;
41typedef u_int32_t ramData;
42
43
44#ifndef CTRL_H
45/* Function prototypes compatible with the ProSLIC API system services layer */
46typedef int (*ctrl_Reset_fptr) (void *hCtrl, int in_reset);
47
48typedef int (*ctrl_WriteRegister_fptr) (void *hCtrl, uInt8 channel, uInt8 regAddr, uInt8 data);
49typedef int (*ctrl_WriteRAM_fptr) (void *hCtrl, uInt8 channel, uInt16 ramAddr, ramData data);
50
51typedef uInt8 (*ctrl_ReadRegister_fptr) (void *hCtrl, uInt8 channel, uInt8 regAddr);
52typedef ramData (*ctrl_ReadRAM_fptr) (void *hCtrl, uInt8 channel, uInt16 ramAddr);
53
54typedef int (*ctrl_Semaphore_fptr) (void *hCtrl, int in_critical_section);
55#endif
56
57typedef void *(*get_hctrl) (uInt8 channel); /* Get a pointer to the control interface */
58
59typedef int (*system_delay_fptr) (void *hTimer, int timeInMs);
60typedef int (*system_timeElapsed_fptr) (void *hTimer, void *startTime, int *timeInMs);
61typedef int (*system_getTime_fptr) (void *hTimer, void *time);
62typedef void *(get_Timer)(void); /* return a pointer to "the" hTimer */
63
64/* Function table entries to reduce namespace pollution */
65typedef struct
66{
67 ctrl_Reset_fptr reset;
68
69 ctrl_WriteRegister_fptr write_reg;
70 ctrl_WriteRAM_fptr write_ram;
71
72 ctrl_ReadRegister_fptr read_reg;
73 ctrl_ReadRAM_fptr read_ram;
74
75 ctrl_Semaphore_fptr sem;
76} proslic_spi_fptrs_t;
77
78typedef struct
79{
80 system_delay_fptr slic_delay;
81 system_timeElapsed_fptr elapsed_time;
82 system_getTime_fptr get_time;
83} proslic_timer_fptrs_t;
84
85/* Timer container */
86typedef struct
87{
88 struct timespec64 timerObj;
89} proslic_timeStamp;
90
91extern int proslic_channel_count;
92extern int proslic_debug_setting;
93int proslic_spi_setup(void);
94void proslic_spi_shutdown(void);
95
96typedef enum
97{
98 PROSLIC_IS_UNKNOWN,
99 PROSLIC_IS_PROSLIC,
100 PROSLIC_IS_DAA
101} proslic_dev_t;
102
103/* Exported functions/values */
104extern proslic_timer_fptrs_t proslic_timer_if;
105extern proslic_spi_fptrs_t proslic_spi_if;
106int proslic_reset(void *hCtrl, int in_reset);
107int proslic_write_register(void *hCtrl, uInt8 channel, uInt8 regAddr, uInt8 data);
108int proslic_write_ram(void *hCtrl, uInt8 channel, uInt16 ramAddr, ramData data);
109uInt8 proslic_read_register(void *hCtrl, uInt8 channel, uInt8 regAddr);
110ramData proslic_read_ram(void *hCtrl, uInt8 channel, uInt16 ramAddr);
111
112int proslic_get_channel_count(void);
113proslic_dev_t proslic_get_device_type(uint8_t channel);
114void *proslic_get_hCtrl(uint8_t channel);
115int proslic_spi_probe(struct spi_device *spi, struct spi_driver *spi_drv);
116int proslic_spi_remove(struct spi_device *spi);
117
118
119#endif /* End of __PROSLIC_SYS_HDR__ */
120