xref: /linux/drivers/net/wireless/ti/wl18xx/io.c (revision ca55b2fef3a9373fcfc30f82fd26bc7fccbda732)
1 /*
2  * This file is part of wl18xx
3  *
4  * Copyright (C) 2011 Texas Instruments
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * version 2 as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18  * 02110-1301 USA
19  *
20  */
21 
22 #include "../wlcore/wlcore.h"
23 #include "../wlcore/io.h"
24 
25 #include "io.h"
26 
27 int wl18xx_top_reg_write(struct wl1271 *wl, int addr, u16 val)
28 {
29 	u32 tmp;
30 	int ret;
31 
32 	if (WARN_ON(addr % 2))
33 		return -EINVAL;
34 
35 	if ((addr % 4) == 0) {
36 		ret = wlcore_read32(wl, addr, &tmp);
37 		if (ret < 0)
38 			goto out;
39 
40 		tmp = (tmp & 0xffff0000) | val;
41 		ret = wlcore_write32(wl, addr, tmp);
42 	} else {
43 		ret = wlcore_read32(wl, addr - 2, &tmp);
44 		if (ret < 0)
45 			goto out;
46 
47 		tmp = (tmp & 0xffff) | (val << 16);
48 		ret = wlcore_write32(wl, addr - 2, tmp);
49 	}
50 
51 out:
52 	return ret;
53 }
54 
55 int wl18xx_top_reg_read(struct wl1271 *wl, int addr, u16 *out)
56 {
57 	u32 val = 0;
58 	int ret;
59 
60 	if (WARN_ON(addr % 2))
61 		return -EINVAL;
62 
63 	if ((addr % 4) == 0) {
64 		/* address is 4-bytes aligned */
65 		ret = wlcore_read32(wl, addr, &val);
66 		if (ret >= 0 && out)
67 			*out = val & 0xffff;
68 	} else {
69 		ret = wlcore_read32(wl, addr - 2, &val);
70 		if (ret >= 0 && out)
71 			*out = (val & 0xffff0000) >> 16;
72 	}
73 
74 	return ret;
75 }
76