1 /*
2  * Copyright (c) 2021 Microchip Technology Inc.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_DRIVERS_ESPI_MCHP_XEC_ESPI_V2_H_
8 #define ZEPHYR_DRIVERS_ESPI_MCHP_XEC_ESPI_V2_H_
9 
10 #include <stdint.h>
11 #include <zephyr/device.h>
12 #include <zephyr/drivers/espi.h>
13 #include <zephyr/drivers/pinctrl.h>
14 
15 /* #define ESPI_XEC_V2_DEBUG	1 */
16 
17 struct espi_isr {
18 	uint8_t girq_id;
19 	uint8_t girq_pos;
20 	void (*the_isr)(const struct device *dev);
21 };
22 
23 struct espi_vw_isr {
24 	uint8_t signal;
25 	uint8_t girq_id;
26 	uint8_t girq_pos;
27 	void (*the_isr)(int girq, int bpos, void *dev);
28 };
29 
30 struct espi_xec_irq_info {
31 	uint8_t gid;	/* GIRQ id [8, 26] */
32 	uint8_t gpos;	/* bit position in GIRQ [0, 31] */
33 	uint8_t anid;	/* Aggregated GIRQ NVIC number */
34 	uint8_t dnid;	/* Direct GIRQ NVIC number */
35 };
36 
37 struct espi_xec_config {
38 	uint32_t base_addr;
39 	uint32_t vw_base_addr;
40 	uint8_t pcr_idx;
41 	uint8_t pcr_bitpos;
42 	uint8_t irq_info_size;
43 	uint8_t rsvd[1];
44 	const struct espi_xec_irq_info *irq_info_list;
45 	const struct pinctrl_dev_config *pcfg;
46 };
47 
48 #define ESPI_XEC_CONFIG(dev)						\
49 	((struct espi_xec_config * const)(dev)->config)
50 
51 struct espi_xec_data {
52 	sys_slist_t callbacks;
53 	struct k_sem tx_lock;
54 	struct k_sem rx_lock;
55 	struct k_sem flash_lock;
56 #ifdef ESPI_XEC_V2_DEBUG
57 	uint32_t espi_rst_count;
58 #endif
59 };
60 
61 #define ESPI_XEC_DATA(dev)						\
62 	((struct espi_xec_data * const)(dev)->data)
63 
64 struct xec_signal {
65 	uint8_t host_idx;
66 	uint8_t bit;
67 	uint8_t xec_reg_idx;
68 	uint8_t flags;
69 };
70 
71 enum mchp_msvw_regs {
72 	MCHP_MSVW00,
73 	MCHP_MSVW01,
74 	MCHP_MSVW02,
75 	MCHP_MSVW03,
76 	MCHP_MSVW04,
77 	MCHP_MSVW05,
78 	MCHP_MSVW06,
79 	MCHP_MSVW07,
80 	MCHP_MSVW08,
81 };
82 
83 enum mchp_smvw_regs {
84 	MCHP_SMVW00,
85 	MCHP_SMVW01,
86 	MCHP_SMVW02,
87 	MCHP_SMVW03,
88 	MCHP_SMVW04,
89 	MCHP_SMVW05,
90 	MCHP_SMVW06,
91 	MCHP_SMVW07,
92 	MCHP_SMVW08,
93 };
94 
95 enum xec_espi_girq_idx {
96 	pc_girq_idx = 0,
97 	bm1_girq_idx,
98 	bm2_girq_idx,
99 	ltr_girq_idx,
100 	oob_up_girq_idx,
101 	oob_dn_girq_idx,
102 	fc_girq_idx,
103 	rst_girq_idx,
104 	vw_ch_en_girq_idx,
105 	max_girq_idx,
106 };
107 
108 int xec_host_dev_init(const struct device *dev);
109 int xec_host_dev_connect_irqs(const struct device *dev);
110 
111 int espi_xec_read_lpc_request(const struct device *dev,
112 			      enum lpc_peripheral_opcode op,
113 			      uint32_t  *data);
114 
115 int espi_xec_write_lpc_request(const struct device *dev,
116 			       enum lpc_peripheral_opcode op,
117 			       uint32_t *data);
118 
119 #endif /* ZEPHYR_DRIVERS_ESPI_MCHP_XEC_ESPI_V2_H_ */
120