Debian Codegraph @

drivers/dahdi/oct612x/oct612x-user.c

raw symbols SCIP
1 /*
2 * Octasic OCT6100 Interface
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 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/slab.h>
26
27 #include <dahdi/kernel.h>
28
29 #include "oct612x.h"
30
31 UINT32 Oct6100UserGetTime(tPOCT6100_GET_TIME f_pTime)
32 {
33 /* Why couldn't they just take a timeval like everyone else? */
34 struct timeval tv;
35 unsigned long long total_usecs;
36 unsigned int mask = ~0;
37
38 do_gettimeofday(&tv);
39 total_usecs = (((unsigned long long)(tv.tv_sec)) * 1000000) +
40 (((unsigned long long)(tv.tv_usec)));
41 f_pTime->aulWallTimeUs[0] = (total_usecs & mask);
42 f_pTime->aulWallTimeUs[1] = (total_usecs >> 32);
43 return cOCT6100_ERR_OK;
44 }
45
46 UINT32 Oct6100UserMemSet(PVOID f_pAddress, UINT32 f_ulPattern,
47 UINT32 f_ulLength)
48 {
49 memset(f_pAddress, f_ulPattern, f_ulLength);
50 return cOCT6100_ERR_OK;
51 }
52
53 UINT32 Oct6100UserMemCopy(PVOID f_pDestination, const void *f_pSource,
54 UINT32 f_ulLength)
55 {
56 memcpy(f_pDestination, f_pSource, f_ulLength);
57 return cOCT6100_ERR_OK;
58 }
59
60 UINT32 Oct6100UserCreateSerializeObject(
61 tPOCT6100_CREATE_SERIALIZE_OBJECT f_pCreate)
62 {
63 struct oct612x_context *context = f_pCreate->pProcessContext;
64 struct mutex *lock = kzalloc(sizeof(*lock), GFP_KERNEL);
65 if (!lock) {
66 dev_err(context->dev, "Out of memory in %s.\n", __func__);
67 return cOCT6100_ERR_BASE;
68 }
69 mutex_init(lock);
70 f_pCreate->ulSerialObjHndl = lock;
71 return cOCT6100_ERR_OK;
72 }
73
74 UINT32 Oct6100UserDestroySerializeObject(
75 tPOCT6100_DESTROY_SERIALIZE_OBJECT f_pDestroy)
76 {
77 struct mutex *lock = f_pDestroy->ulSerialObjHndl;
78 kfree(lock);
79 return cOCT6100_ERR_OK;
80 }
81
82 UINT32 Oct6100UserSeizeSerializeObject(
83 tPOCT6100_SEIZE_SERIALIZE_OBJECT f_pSeize)
84 {
85 struct mutex *lock = f_pSeize->ulSerialObjHndl;
86 mutex_lock(lock);
87 return cOCT6100_ERR_OK;
88 }
89
90 UINT32 Oct6100UserReleaseSerializeObject(
91 tPOCT6100_RELEASE_SERIALIZE_OBJECT f_pRelease)
92 {
93 struct mutex *lock = f_pRelease->ulSerialObjHndl;
94 mutex_unlock(lock);
95 return cOCT6100_ERR_OK;
96 }
97
98 UINT32 Oct6100UserDriverWriteApi(tPOCT6100_WRITE_PARAMS f_pWriteParams)
99 {
100 struct oct612x_context *context = f_pWriteParams->pProcessContext;
101 #ifdef OCTASIC_DEBUG
102 if (!context || !context->ops || !context->ops->write) {
103 pr_debug("Invalid call to %s\n", __func__);
104 return cOCT6100_ERR_BASE;
105 }
106 #endif
107 context->ops->write(context, f_pWriteParams->ulWriteAddress,
108 f_pWriteParams->usWriteData);
109 return cOCT6100_ERR_OK;
110 }
111
112 UINT32 Oct6100UserDriverWriteSmearApi(tPOCT6100_WRITE_SMEAR_PARAMS f_pSmearParams)
113 {
114 struct oct612x_context *context = f_pSmearParams->pProcessContext;
115 #ifdef OCTASIC_DEBUG
116 if (!context || !context->ops || !context->ops->write_smear) {
117 pr_debug("Invalid call to %s\n", __func__);
118 return cOCT6100_ERR_BASE;
119 }
120 #endif
121 context->ops->write_smear(context, f_pSmearParams->ulWriteAddress,
122 f_pSmearParams->usWriteData,
123 f_pSmearParams->ulWriteLength);
124 return cOCT6100_ERR_OK;
125 }
126
127 UINT32 Oct6100UserDriverWriteBurstApi(
128 tPOCT6100_WRITE_BURST_PARAMS f_pBurstParams)
129 {
130 struct oct612x_context *context = f_pBurstParams->pProcessContext;
131 #ifdef OCTASIC_DEBUG
132 if (!context || !context->ops || !context->ops->write_burst) {
133 pr_debug("Invalid call to %s\n", __func__);
134 return cOCT6100_ERR_BASE;
135 }
136 #endif
137 context->ops->write_burst(context, f_pBurstParams->ulWriteAddress,
138 f_pBurstParams->pusWriteData,
139 f_pBurstParams->ulWriteLength);
140 return cOCT6100_ERR_OK;
141 }
142
143 UINT32 Oct6100UserDriverReadApi(tPOCT6100_READ_PARAMS f_pReadParams)
144 {
145 struct oct612x_context *context = f_pReadParams->pProcessContext;
146 #ifdef OCTASIC_DEBUG
147 if (!context || !context->ops || !context->ops->read) {
148 pr_debug("Invalid call to %s\n", __func__);
149 return cOCT6100_ERR_BASE;
150 }
151 #endif
152 context->ops->read(context, f_pReadParams->ulReadAddress,
153 f_pReadParams->pusReadData);
154 return cOCT6100_ERR_OK;
155 }
156
157 UINT32 Oct6100UserDriverReadBurstApi(tPOCT6100_READ_BURST_PARAMS f_pBurstParams)
158 {
159 struct oct612x_context *context = f_pBurstParams->pProcessContext;
160 #ifdef OCTASIC_DEBUG
161 if (!context || !context->ops || !context->ops->read_burst) {
162 pr_debug("Invalid call to %s\n", __func__);
163 return cOCT6100_ERR_BASE;
164 }
165 #endif
166 context->ops->read_burst(context, f_pBurstParams->ulReadAddress,
167 f_pBurstParams->pusReadData,
168 f_pBurstParams->ulReadLength);
169 return cOCT6100_ERR_OK;
170 }
171
172 EXPORT_SYMBOL(Oct6100ChipOpen);
173 EXPORT_SYMBOL(Oct6100ChipClose);
174 EXPORT_SYMBOL(Oct6100ChipCloseDef);
175 EXPORT_SYMBOL(Oct6100GetInstanceSize);
176 EXPORT_SYMBOL(Oct6100GetInstanceSizeDef);
177 EXPORT_SYMBOL(Oct6100ChipOpenDef);
178 EXPORT_SYMBOL(Oct6100ChannelModify);
179 EXPORT_SYMBOL(Oct6100ToneDetectionEnableDef);
180 EXPORT_SYMBOL(Oct6100InterruptServiceRoutine);
181 EXPORT_SYMBOL(Oct6100InterruptServiceRoutineDef);
182 EXPORT_SYMBOL(Oct6100ApiGetCapacityPins);
183 EXPORT_SYMBOL(Oct6100ToneDetectionEnable);
184 EXPORT_SYMBOL(Oct6100EventGetToneDef);
185 EXPORT_SYMBOL(Oct6100EventGetTone);
186 EXPORT_SYMBOL(Oct6100ApiGetCapacityPinsDef);
187 EXPORT_SYMBOL(Oct6100ChannelOpen);
188 EXPORT_SYMBOL(Oct6100ChannelOpenDef);
189 EXPORT_SYMBOL(Oct6100ChannelModifyDef);
190
191 static int __init oct612x_module_init(void)
192 {
193 /* This registration with dahdi.ko will fail since the span is not
194 * defined, but it will make sure that this module is a dependency of
195 * dahdi.ko, so that when it is being unloded, this module will be
196 * unloaded as well. */
197 dahdi_register_device(NULL, NULL);
198 return 0;
199 }
200 module_init(oct612x_module_init);
201
202 static void __exit oct612x_module_cleanup(void)
203 {
204 /* Nothing to do */;
205 }
206 module_exit(oct612x_module_cleanup);
207
208 MODULE_AUTHOR("Digium Incorporated <[email protected]>");
209 MODULE_DESCRIPTION("Octasic OCT6100 Hardware Echocan Library");
210 MODULE_LICENSE("GPL v2");