Debian Codegraph @

drivers/dahdi/wcxb.h

raw symbols SCIP
1 /*
2 * wcxb SPI library
3 *
4 * Copyright (C) 2013 Digium, Inc.
5 *
6 * All rights reserved.
7 *
8 */
9
10 /*
11 * See http://www.asterisk.org for more information about
12 * the Asterisk project. Please do not directly contact
13 * any of the maintainers of this project for assistance;
14 * the project provides a web site, mailing lists and IRC
15 * channels for your use.
16 *
17 * This program is free software, distributed under the terms of
18 * the GNU General Public License Version 2 as published by the
19 * Free Software Foundation. See the LICENSE file included with
20 * this program for more details.
21 */
22
23 #ifndef __WCXB_H__
24 #define __WCXB_H__
25
26 #define WCXB_DEFAULT_LATENCY 3U
27 #define WCXB_DEFAULT_MAXLATENCY 12U
28 #define WCXB_DMA_CHAN_SIZE 128
29
30 struct wcxb;
31
32 struct wcxb_operations {
33 void (*handle_receive)(struct wcxb *xb, void *frame);
34 void (*handle_transmit)(struct wcxb *xb, void *frame);
35 void (*handle_error)(struct wcxb *xb);
36 void (*handle_interrupt)(struct wcxb *xb, u32 pending);
37 };
38
39 struct wcxb_meta_desc;
40 struct wcxb_hw_desc;
41
42 /**
43 * struct wcxb - Interface to wcxb firmware.
44 * @last_retry_count: Running count of times firmware had to retry host DMA
45 * transaction. Debugging aide.
46 */
47 struct wcxb {
48 struct pci_dev *pdev;
49 spinlock_t lock;
50 const struct wcxb_operations *ops;
51 unsigned int *debug;
52 unsigned int max_latency;
53 unsigned int latency;
54 struct {
55 u32 have_msi:1;
56 u32 latency_locked:1;
57 u32 drive_timing_cable:1;
58 u32 dma_ins:1;
59 } flags;
60 void __iomem *membase;
61 struct wcxb_meta_desc *meta_dring;
62 struct wcxb_hw_desc *hw_dring;
63 unsigned int dma_head;
64 unsigned int dma_tail;
65 dma_addr_t hw_dring_phys;
66 struct dma_pool *pool;
67 unsigned long framecount;
68 #ifdef DEBUG
69 u8 last_retry_count;
70 u8 max_retry_count;
71 u32 last_dma_time;
72 u32 max_dma_time;
73 #endif
74 };
75
76 extern int wcxb_init(struct wcxb *xb, const char *board_name, u32 int_mode);
77 extern void wcxb_release(struct wcxb *xb);
78 extern int wcxb_start(struct wcxb *xb);
79 extern void wcxb_stop(struct wcxb *xb);
80 extern int wcxb_wait_for_stop(struct wcxb *xb, unsigned long timeout_ms);
81 extern bool wcxb_is_stopped(struct wcxb *xb);
82
83 enum wcxb_clock_sources {
84 WCXB_CLOCK_SELF, /* Use the internal oscillator for timing. */
85 WCXB_CLOCK_RECOVER, /* Recover the clock from a framer. */
86 #ifdef RPC_RCLK
87 WCXB_CLOCK_RECOVER_ALT, /* Recover the clock from a framer. */
88 #endif
89 WCXB_CLOCK_SLAVE /* Recover clock from any timing header. */
90 };
91
92 extern enum wcxb_clock_sources wcxb_get_clksrc(struct wcxb *xb);
93 extern void wcxb_set_clksrc(struct wcxb *xb, enum wcxb_clock_sources clksrc);
94
95 static inline void wcxb_enable_timing_header_driver(struct wcxb *xb)
96 {
97 xb->flags.drive_timing_cable = 1;
98 }
99 static inline bool wcxb_is_timing_header_driver_enabled(struct wcxb *xb)
100 {
101 return 1 == xb->flags.drive_timing_cable;
102 }
103
104 static inline void wcxb_disable_timing_header_driver(struct wcxb *xb)
105 {
106 xb->flags.drive_timing_cable = 0;
107 }
108
109 enum wcxb_reset_option {
110 WCXB_RESET_NOW,
111 WCXB_RESET_LATER
112 };
113
114 extern u32 wcxb_get_firmware_version(struct wcxb *xb);
115 extern int wcxb_check_firmware(struct wcxb *xb, const u32 expected_version,
116 const char *firmware_filename,
117 bool force_firmware,
118 enum wcxb_reset_option reset);
119
120 extern void wcxb_stop_dma(struct wcxb *xb);
121 extern void wcxb_disable_interrupts(struct wcxb *xb);
122
123 static inline void wcxb_gpio_set(struct wcxb *xb, u32 bits)
124 {
125 u32 reg;
126 unsigned long flags;
127 spin_lock_irqsave(&xb->lock, flags);
128 reg = ioread32be(xb->membase);
129 iowrite32be(reg | bits, xb->membase);
130 spin_unlock_irqrestore(&xb->lock, flags);
131 }
132
133 static inline void wcxb_gpio_clear(struct wcxb *xb, u32 bits)
134 {
135 u32 reg;
136 unsigned long flags;
137 spin_lock_irqsave(&xb->lock, flags);
138 reg = ioread32be(xb->membase);
139 iowrite32be(reg & (~bits), xb->membase);
140 spin_unlock_irqrestore(&xb->lock, flags);
141 }
142
143 static inline void
144 wcxb_set_maxlatency(struct wcxb *xb, unsigned int max_latency)
145 {
146 unsigned long flags;
147 spin_lock_irqsave(&xb->lock, flags);
148 xb->max_latency = clamp(max_latency,
149 xb->latency,
150 WCXB_DEFAULT_MAXLATENCY);
151 spin_unlock_irqrestore(&xb->lock, flags);
152 }
153
154 static inline void
155 wcxb_set_minlatency(struct wcxb *xb, unsigned int min_latency)
156 {
157 unsigned long flags;
158 spin_lock_irqsave(&xb->lock, flags);
159 xb->latency = clamp(min_latency, WCXB_DEFAULT_LATENCY,
160 WCXB_DEFAULT_MAXLATENCY);
161 spin_unlock_irqrestore(&xb->lock, flags);
162 }
163
164 static inline void
165 wcxb_lock_latency(struct wcxb *xb)
166 {
167 unsigned long flags;
168 spin_lock_irqsave(&xb->lock, flags);
169 xb->flags.latency_locked = 1;
170 spin_unlock_irqrestore(&xb->lock, flags);
171 return;
172 }
173
174 static inline void
175 wcxb_unlock_latency(struct wcxb *xb)
176 {
177 unsigned long flags;
178 spin_lock_irqsave(&xb->lock, flags);
179 xb->flags.latency_locked = 0;
180 spin_unlock_irqrestore(&xb->lock, flags);
181 return;
182 }
183
184 /* Interface for the echocan block */
185 extern void wcxb_enable_echocan(struct wcxb *xb);
186 extern void wcxb_disable_echocan(struct wcxb *xb);
187 extern void wcxb_reset_echocan(struct wcxb *xb);
188 extern void wcxb_enable_echocan_dram(struct wcxb *xb);
189 extern bool wcxb_is_echocan_present(struct wcxb *xb);
190 extern u16 wcxb_get_echocan_reg(struct wcxb *xb, u32 address);
191 extern void wcxb_set_echocan_reg(struct wcxb *xb, u32 address, u16 val);
192
193 #endif