2 * carlu - userspace testing utility for ar9170 devices
4 * register/memory/command access functions
6 * Copyright 2009-2011 Christian Lamparter <chunkeey@googlemail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #ifndef __CARL9170USER_CMD_H
24 #define __CARL9170USER_CMD_H
28 int carlu_cmd_echo(struct carlu *ar, const uint32_t message);
29 int carlu_cmd_reboot(struct carlu *ar);
30 int carlu_cmd_read_eeprom(struct carlu *ar);
31 int carlu_cmd_mem_dump(struct carlu *ar, const uint32_t start,
32 const unsigned int len, void *_buf);
33 int carlu_cmd_write_mem(struct carlu *ar, const uint32_t addr,
35 int carlu_cmd_mem_watch(struct carlu *ar, const uint32_t mem,
36 const unsigned int len, void *_buf);
38 struct carl9170_cmd *carlu_cmd_buf(struct carlu *ar,
39 const enum carl9170_cmd_oids cmd, const unsigned int len);
41 #define PAYLOAD_MAX (CARL9170_MAX_CMD_LEN / 4 - 1)
43 * Macros to facilitate writing multiple registers in a single
44 * write-combining USB command. Note that when the first group
45 * fails the whole thing will fail without any others attempted,
46 * but you won't know which write in the group failed.
48 #define carlu_regwrite_begin(ar) \
50 struct carlu *__ar = ar; \
51 unsigned int __nreg = 0; \
55 #define carlu_regwrite_flush() \
57 __err = carlusb_cmd(__ar, CARL9170_CMD_WREG, \
58 (u8 *)&__ar->cmd.cmd.data, 8 * __nreg, \
59 (u8 *)&__dummy, sizeof(__dummy)); \
62 goto __regwrite_out; \
65 #define carlu_regwrite(r, v) do { \
66 __ar->cmd.buf4[2 * __nreg + 1] = cpu_to_le32(r); \
67 __ar->cmd.buf4[2 * __nreg + 2] = cpu_to_le32(v); \
69 if ((__nreg >= PAYLOAD_MAX / 2)) { \
70 __err = carlusb_cmd(__ar, CARL9170_CMD_WREG, \
71 (u8 *)&__ar->cmd.cmd.data, 8 * __nreg, \
72 (u8 *)&__dummy, sizeof(__dummy)); \
76 goto __regwrite_out; \
80 #define carlu_regwrite_finish() \
82 if (__err == 0 && __nreg) \
83 carlu_regwrite_flush();
85 #define carlu_regwrite_result() \
90 #define carlu_async_get_buf() \
92 __cmd = carlu_cmd_buf(__carl, CARL9170_CMD_WREG_ASYNC, \
93 CARL9170_MAX_CMD_PAYLOAD_LEN); \
94 if (IS_ERR_OR_NULL(__cmd)) { \
95 __err = __cmd ? PTR_ERR(__cmd) : -ENOMEM; \
96 goto __async_regwrite_out; \
100 #define carlu_async_regwrite_begin(carl) \
102 int __nreg = 0, __err = 0; \
103 struct carlu *__carl = carl; \
104 struct carl9170_cmd *__cmd; \
105 carlu_async_get_buf(); \
107 #define carlu_async_regwrite_flush() \
109 __cmd->hdr.len = 8 * __nreg; \
110 __err = carlusb_cmd_async(__carl, __cmd, true); \
113 goto __async_regwrite_out; \
115 carlu_async_get_buf(); \
118 #define carlu_async_regwrite(r, v) do { \
119 __cmd->wreg.regs[__nreg].addr = cpu_to_le32(r); \
120 __cmd->wreg.regs[__nreg].val = cpu_to_le32(v); \
122 if ((__nreg >= PAYLOAD_MAX / 2)) \
123 carlu_async_regwrite_flush(); \
126 #define carlu_async_regwrite_finish() \
127 __async_regwrite_out : \
128 if (__err == 0 && __nreg) \
129 carlu_async_regwrite_flush();
131 #define carlu_async_regwrite_result() \
135 #endif /* __CARL9170USER_CMD_H */