1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (C) 2021-2022, Intel Corporation. */
3 
4 #ifndef _ICE_GNSS_H_
5 #define _ICE_GNSS_H_
6 
7 #include <linux/tty.h>
8 #include <linux/tty_flip.h>
9 
10 #define ICE_E810T_GNSS_I2C_BUS		0x2
11 #define ICE_GNSS_TIMER_DELAY_TIME	(HZ / 10) /* 0.1 second per message */
12 /* Create 2 minor devices, both using the same GNSS module. First one is RW,
13  * second one RO.
14  */
15 #define ICE_GNSS_TTY_MINOR_DEVICES	2
16 #define ICE_GNSS_TTY_WRITE_BUF		250
17 #define ICE_MAX_I2C_DATA_SIZE		FIELD_MAX(ICE_AQC_I2C_DATA_SIZE_M)
18 #define ICE_MAX_I2C_WRITE_BYTES		4
19 
20 /* u-blox ZED-F9T specific definitions */
21 #define ICE_GNSS_UBX_I2C_BUS_ADDR	0x42
22 /* Data length register is big endian */
23 #define ICE_GNSS_UBX_DATA_LEN_H		0xFD
24 #define ICE_GNSS_UBX_DATA_LEN_WIDTH	2
25 #define ICE_GNSS_UBX_EMPTY_DATA		0xFF
26 /* For u-blox writes are performed without address so the first byte to write is
27  * passed as I2C addr parameter.
28  */
29 #define ICE_GNSS_UBX_WRITE_BYTES	(ICE_MAX_I2C_WRITE_BYTES + 1)
30 #define ICE_MAX_UBX_READ_TRIES		255
31 #define ICE_MAX_UBX_ACK_READ_TRIES	4095
32 
33 struct gnss_write_buf {
34 	struct list_head queue;
35 	unsigned int size;
36 	unsigned char *buf;
37 };
38 
39 
40 /**
41  * struct gnss_serial - data used to initialize GNSS TTY port
42  * @back: back pointer to PF
43  * @tty: pointer to the tty for this device
44  * @open_count: number of times this port has been opened
45  * @gnss_mutex: gnss_mutex used to protect GNSS serial operations
46  * @kworker: kwork thread for handling periodic work
47  * @read_work: read_work function for handling GNSS reads
48  * @write_work: write_work function for handling GNSS writes
49  * @queue: write buffers queue
50  */
51 struct gnss_serial {
52 	struct ice_pf *back;
53 	struct tty_struct *tty;
54 	int open_count;
55 	struct mutex gnss_mutex; /* protects GNSS serial structure */
56 	struct kthread_worker *kworker;
57 	struct kthread_delayed_work read_work;
58 	struct kthread_work write_work;
59 	struct list_head queue;
60 };
61 
62 #if IS_ENABLED(CONFIG_TTY)
63 void ice_gnss_init(struct ice_pf *pf);
64 void ice_gnss_exit(struct ice_pf *pf);
65 bool ice_gnss_is_gps_present(struct ice_hw *hw);
66 #else
67 static inline void ice_gnss_init(struct ice_pf *pf) { }
68 static inline void ice_gnss_exit(struct ice_pf *pf) { }
69 static inline bool ice_gnss_is_gps_present(struct ice_hw *hw)
70 {
71 	return false;
72 }
73 #endif /* IS_ENABLED(CONFIG_TTY) */
74 #endif /* _ICE_GNSS_H_ */
75