xref: /openbmc/linux/drivers/staging/pi433/pi433_if.h (revision ba61bb17)
1 /*
2  * include/linux/TODO
3  *
4  * userspace interface for pi433 radio module
5  *
6  * Pi433 is a 433MHz radio module for the Raspberry Pi.
7  * It is based on the HopeRf Module RFM69CW. Therefore inside of this
8  * driver, you'll find an abstraction of the rf69 chip.
9  *
10  * If needed, this driver could be extended, to also support other
11  * devices, basing on HopeRfs rf69.
12  *
13  * The driver can also be extended, to support other modules of
14  * HopeRf with a similar interace - e. g. RFM69HCW, RFM12, RFM95, ...
15  * Copyright (C) 2016 Wolf-Entwicklungen
16  *	Marcus Wolf <linux@wolf-entwicklungen.de>
17  *
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 2 of the License, or
21  * (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  * GNU General Public License for more details.
27  */
28 
29 #ifndef PI433_H
30 #define PI433_H
31 
32 #include <linux/types.h>
33 #include "rf69_enum.h"
34 
35 /*---------------------------------------------------------------------------*/
36 
37 enum option_on_off {
38 	OPTION_OFF,
39 	OPTION_ON
40 };
41 
42 /* IOCTL structs and commands */
43 
44 /**
45  * struct pi433_tx_config - describes the configuration of the radio module for sending
46  * @frequency:
47  * @bit_rate:
48  * @modulation:
49  * @data_mode:
50  * @preamble_length:
51  * @sync_pattern:
52  * @tx_start_condition:
53  * @payload_length:
54  * @repetitions:
55  *
56  * ATTENTION:
57  * If the contents of 'pi433_tx_config' ever change
58  * incompatibly, then the ioctl number (see define below) must change.
59  *
60  * NOTE: struct layout is the same in 64bit and 32bit userspace.
61  */
62 #define PI433_TX_CFG_IOCTL_NR	0
63 struct pi433_tx_cfg {
64 	__u32			frequency;
65 	__u16			bit_rate;
66 	__u32			dev_frequency;
67 	enum modulation		modulation;
68 	enum mod_shaping	mod_shaping;
69 
70 	enum pa_ramp		pa_ramp;
71 
72 	enum tx_start_condition	tx_start_condition;
73 
74 	__u16			repetitions;
75 
76 	/* packet format */
77 	enum option_on_off	enable_preamble;
78 	enum option_on_off	enable_sync;
79 	enum option_on_off	enable_length_byte;
80 	enum option_on_off	enable_address_byte;
81 	enum option_on_off	enable_crc;
82 
83 	__u16			preamble_length;
84 	__u8			sync_length;
85 	__u8			fixed_message_length;
86 
87 	__u8			sync_pattern[8];
88 	__u8			address_byte;
89 };
90 
91 /**
92  * struct pi433_rx_config - describes the configuration of the radio module for sending
93  * @frequency:
94  * @bit_rate:
95  * @modulation:
96  * @data_mode:
97  * @preamble_length:
98  * @sync_pattern:
99  * @tx_start_condition:
100  * @payload_length:
101  * @repetitions:
102  *
103  * ATTENTION:
104  * If the contents of 'pi433_rx_config' ever change
105  * incompatibly, then the ioctl number (see define below) must change
106  *
107  * NOTE: struct layout is the same in 64bit and 32bit userspace.
108  */
109 #define PI433_RX_CFG_IOCTL_NR	1
110 struct pi433_rx_cfg {
111 	__u32			frequency;
112 	__u16			bit_rate;
113 	__u32			dev_frequency;
114 
115 	enum modulation		modulation;
116 
117 	__u8			rssi_threshold;
118 	enum threshold_decrement threshold_decrement;
119 	enum antenna_impedance	antenna_impedance;
120 	enum lna_gain		lna_gain;
121 	enum mantisse		bw_mantisse;	/* normal: 0x50 */
122 	__u8			bw_exponent;	/* during AFC: 0x8b */
123 	enum dagc		dagc;
124 
125 	/* packet format */
126 	enum option_on_off	enable_sync;
127 	enum option_on_off	enable_length_byte;	  /* should be used in combination with sync, only */
128 	enum address_filtering	enable_address_filtering; /* operational with sync, only */
129 	enum option_on_off	enable_crc;		  /* only operational, if sync on and fixed length or length byte is used */
130 
131 	__u8			sync_length;
132 	__u8			fixed_message_length;
133 	__u32			bytes_to_drop;
134 
135 	__u8			sync_pattern[8];
136 	__u8			node_address;
137 	__u8			broadcast_address;
138 };
139 
140 #define PI433_IOC_MAGIC			'r'
141 
142 #define PI433_IOC_RD_TX_CFG	_IOR(PI433_IOC_MAGIC, PI433_TX_CFG_IOCTL_NR, char[sizeof(struct pi433_tx_cfg)])
143 #define PI433_IOC_WR_TX_CFG	_IOW(PI433_IOC_MAGIC, PI433_TX_CFG_IOCTL_NR, char[sizeof(struct pi433_tx_cfg)])
144 
145 #define PI433_IOC_RD_RX_CFG	_IOR(PI433_IOC_MAGIC, PI433_RX_CFG_IOCTL_NR, char[sizeof(struct pi433_rx_cfg)])
146 #define PI433_IOC_WR_RX_CFG	_IOW(PI433_IOC_MAGIC, PI433_RX_CFG_IOCTL_NR, char[sizeof(struct pi433_rx_cfg)])
147 
148 #endif /* PI433_H */
149