developer | e0cea0f | 2021-12-16 16:08:26 +0800 | [diff] [blame] | 1 | /* 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 */ |
| 33 | typedef u_int8_t BOOLEAN; |
| 34 | typedef int8_t int8; |
| 35 | typedef u_int8_t uInt8; |
| 36 | typedef uInt8 uChar; |
| 37 | typedef int16_t int16; |
| 38 | typedef u_int16_t uInt16; |
| 39 | typedef int32_t int32; |
| 40 | typedef u_int32_t uInt32; |
| 41 | typedef u_int32_t ramData; |
| 42 | |
| 43 | |
| 44 | #ifndef CTRL_H |
| 45 | /* Function prototypes compatible with the ProSLIC API system services layer */ |
| 46 | typedef int (*ctrl_Reset_fptr) (void *hCtrl, int in_reset); |
| 47 | |
| 48 | typedef int (*ctrl_WriteRegister_fptr) (void *hCtrl, uInt8 channel, uInt8 regAddr, uInt8 data); |
| 49 | typedef int (*ctrl_WriteRAM_fptr) (void *hCtrl, uInt8 channel, uInt16 ramAddr, ramData data); |
| 50 | |
| 51 | typedef uInt8 (*ctrl_ReadRegister_fptr) (void *hCtrl, uInt8 channel, uInt8 regAddr); |
| 52 | typedef ramData (*ctrl_ReadRAM_fptr) (void *hCtrl, uInt8 channel, uInt16 ramAddr); |
| 53 | |
| 54 | typedef int (*ctrl_Semaphore_fptr) (void *hCtrl, int in_critical_section); |
| 55 | #endif |
| 56 | |
| 57 | typedef void *(*get_hctrl) (uInt8 channel); /* Get a pointer to the control interface */ |
| 58 | |
| 59 | typedef int (*system_delay_fptr) (void *hTimer, int timeInMs); |
| 60 | typedef int (*system_timeElapsed_fptr) (void *hTimer, void *startTime, int *timeInMs); |
| 61 | typedef int (*system_getTime_fptr) (void *hTimer, void *time); |
| 62 | typedef void *(get_Timer)(void); /* return a pointer to "the" hTimer */ |
| 63 | |
| 64 | /* Function table entries to reduce namespace pollution */ |
| 65 | typedef 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 | |
| 78 | typedef 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 */ |
| 86 | typedef struct |
| 87 | { |
| 88 | struct timespec64 timerObj; |
| 89 | } proslic_timeStamp; |
| 90 | |
| 91 | extern int proslic_channel_count; |
| 92 | extern int proslic_debug_setting; |
| 93 | int proslic_spi_setup(void); |
| 94 | void proslic_spi_shutdown(void); |
| 95 | |
| 96 | typedef enum |
| 97 | { |
| 98 | PROSLIC_IS_UNKNOWN, |
| 99 | PROSLIC_IS_PROSLIC, |
| 100 | PROSLIC_IS_DAA |
| 101 | } proslic_dev_t; |
| 102 | |
| 103 | /* Exported functions/values */ |
| 104 | extern proslic_timer_fptrs_t proslic_timer_if; |
| 105 | extern proslic_spi_fptrs_t proslic_spi_if; |
| 106 | int proslic_reset(void *hCtrl, int in_reset); |
| 107 | int proslic_write_register(void *hCtrl, uInt8 channel, uInt8 regAddr, uInt8 data); |
| 108 | int proslic_write_ram(void *hCtrl, uInt8 channel, uInt16 ramAddr, ramData data); |
| 109 | uInt8 proslic_read_register(void *hCtrl, uInt8 channel, uInt8 regAddr); |
| 110 | ramData proslic_read_ram(void *hCtrl, uInt8 channel, uInt16 ramAddr); |
| 111 | |
| 112 | int proslic_get_channel_count(void); |
| 113 | proslic_dev_t proslic_get_device_type(uint8_t channel); |
| 114 | void *proslic_get_hCtrl(uint8_t channel); |
| 115 | int proslic_spi_probe(struct spi_device *spi, struct spi_driver *spi_drv); |
| 116 | int proslic_spi_remove(struct spi_device *spi); |
| 117 | |
| 118 | |
| 119 | #endif /* End of __PROSLIC_SYS_HDR__ */ |
| 120 | |