Debian Codegraph @

drivers/dahdi/wcxb.h

raw
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 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
31 /* The is_pcie member was backported but I'm not sure in which version. */
32 # ifndef RHEL_RELEASE_VERSION
33 #define WCXB_PCI_DEV_DOES_NOT_HAVE_IS_PCIE
34 # endif
35 #else
36 #endif
37
38 struct wcxb;
39
40 struct wcxb_operations {
41 void (*handle_receive)(struct wcxb *xb, void *frame);
42 void (*handle_transmit)(struct wcxb *xb, void *frame);
43 void (*handle_error)(struct wcxb *xb);
44 void (*handle_interrupt)(struct wcxb *xb, u32 pending);
45 };
46
47 struct wcxb_meta_desc;
48 struct wcxb_hw_desc;
49
50 /**
51 * struct wcxb - Interface to wcxb firmware.
52 * @last_retry_count: Running count of times firmware had to retry host DMA
53 * transaction. Debugging aide.
54 */
55 struct wcxb {
56 struct pci_dev *pdev;
57 spinlock_t lock;
58 const struct wcxb_operations *ops;
59 unsigned int *debug;
60 unsigned int max_latency;
61 unsigned int latency;
62 struct {
63 u32 have_msi:1;
64 u32 latency_locked:1;
65 u32 drive_timing_cable:1;
66 #ifdef WCXB_PCI_DEV_DOES_NOT_HAVE_IS_PCIE
67 u32 is_pcie:1;
68 #endif
69 u32 dma_ins:1;
70 } flags;
71 void __iomem *membase;
72 struct wcxb_meta_desc *meta_dring;
73 struct wcxb_hw_desc *hw_dring;
74 unsigned int dma_head;
75 unsigned int dma_tail;
76 dma_addr_t hw_dring_phys;
77 struct dma_pool *pool;
78 unsigned long framecount;
79 #ifdef DEBUG
80 u8 last_retry_count;
81 u8 max_retry_count;
82 u32 last_dma_time;
83 u32 max_dma_time;
84 #endif
85 };
86
87 extern int wcxb_init(struct wcxb *xb, const char *board_name, u32 int_mode);
88 extern void wcxb_release(struct wcxb *xb);
89 extern int wcxb_start(struct wcxb *xb);
90 extern void wcxb_stop(struct wcxb *xb);
91 extern int wcxb_wait_for_stop(struct wcxb *xb, unsigned long timeout_ms);
92 extern bool wcxb_is_stopped(struct wcxb *xb);
93
94 enum wcxb_clock_sources {
95 WCXB_CLOCK_SELF, /* Use the internal oscillator for timing. */
96 WCXB_CLOCK_RECOVER, /* Recover the clock from a framer. */
97 #ifdef RPC_RCLK
98 WCXB_CLOCK_RECOVER_ALT, /* Recover the clock from a framer. */
99 #endif
100 WCXB_CLOCK_SLAVE /* Recover clock from any timing header. */
101 };
102
103 extern enum wcxb_clock_sources wcxb_get_clksrc(struct wcxb *xb);
104 extern void wcxb_set_clksrc(struct wcxb *xb, enum wcxb_clock_sources clksrc);
105
106 static inline void wcxb_enable_timing_header_driver(struct wcxb *xb)
107 {
108 xb->flags.drive_timing_cable = 1;
109 }
110 static inline bool wcxb_is_timing_header_driver_enabled(struct wcxb *xb)
111 {
112 return 1 == xb->flags.drive_timing_cable;
113 }
114
115 static inline void wcxb_disable_timing_header_driver(struct wcxb *xb)
116 {
117 xb->flags.drive_timing_cable = 0;
118 }
119
120 enum wcxb_reset_option {
121 WCXB_RESET_NOW,
122 WCXB_RESET_LATER
123 };
124
125 extern u32 wcxb_get_firmware_version(struct wcxb *xb);
126 extern int wcxb_check_firmware(struct wcxb *xb, const u32 expected_version,
127 const char *firmware_filename,
128 bool force_firmware,
129 enum wcxb_reset_option reset);
130
131 extern void wcxb_stop_dma(struct wcxb *xb);
132 extern void wcxb_disable_interrupts(struct wcxb *xb);
133
134 static inline void wcxb_gpio_set(struct wcxb *xb, u32 bits)
135 {
136 u32 reg;
137 unsigned long flags;
138 spin_lock_irqsave(&xb->lock, flags);
139 reg = ioread32be(xb->membase);
140 iowrite32be(reg | bits, xb->membase);
141 spin_unlock_irqrestore(&xb->lock, flags);
142 }
143
144 static inline void wcxb_gpio_clear(struct wcxb *xb, u32 bits)
145 {
146 u32 reg;
147 unsigned long flags;
148 spin_lock_irqsave(&xb->lock, flags);
149 reg = ioread32be(xb->membase);
150 iowrite32be(reg & (~bits), xb->membase);
151 spin_unlock_irqrestore(&xb->lock, flags);
152 }
153
154 static inline void
155 wcxb_set_maxlatency(struct wcxb *xb, unsigned int max_latency)
156 {
157 unsigned long flags;
158 spin_lock_irqsave(&xb->lock, flags);
159 xb->max_latency = clamp(max_latency,
160 xb->latency,
161 WCXB_DEFAULT_MAXLATENCY);
162 spin_unlock_irqrestore(&xb->lock, flags);
163 }
164
165 static inline void
166 wcxb_set_minlatency(struct wcxb *xb, unsigned int min_latency)
167 {
168 unsigned long flags;
169 spin_lock_irqsave(&xb->lock, flags);
170 xb->latency = clamp(min_latency, WCXB_DEFAULT_LATENCY,
171 WCXB_DEFAULT_MAXLATENCY);
172 spin_unlock_irqrestore(&xb->lock, flags);
173 }
174
175 static inline void
176 wcxb_lock_latency(struct wcxb *xb)
177 {
178 unsigned long flags;
179 spin_lock_irqsave(&xb->lock, flags);
180 xb->flags.latency_locked = 1;
181 spin_unlock_irqrestore(&xb->lock, flags);
182 return;
183 }
184
185 static inline void
186 wcxb_unlock_latency(struct wcxb *xb)
187 {
188 unsigned long flags;
189 spin_lock_irqsave(&xb->lock, flags);
190 xb->flags.latency_locked = 0;
191 spin_unlock_irqrestore(&xb->lock, flags);
192 return;
193 }
194
195 /* Interface for the echocan block */
196 extern void wcxb_enable_echocan(struct wcxb *xb);
197 extern void wcxb_disable_echocan(struct wcxb *xb);
198 extern void wcxb_reset_echocan(struct wcxb *xb);
199 extern void wcxb_enable_echocan_dram(struct wcxb *xb);
200 extern bool wcxb_is_echocan_present(struct wcxb *xb);
201 extern u16 wcxb_get_echocan_reg(struct wcxb *xb, u32 address);
202 extern void wcxb_set_echocan_reg(struct wcxb *xb, u32 address, u16 val);
203
204 #endif