io.c revision be65202a610ca96aa945789c8b0a7bc3529b556e
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
27void wl18xx_top_reg_write(struct wl1271 *wl, int addr, u16 val)
28{
29	u32 tmp;
30
31	if (WARN_ON(addr % 2))
32		return;
33
34	if ((addr % 4) == 0) {
35		tmp = wl1271_read32(wl, addr);
36		tmp = (tmp & 0xffff0000) | val;
37		wl1271_write32(wl, addr, tmp);
38	} else {
39		tmp = wl1271_read32(wl, addr - 2);
40		tmp = (tmp & 0xffff) | (val << 16);
41		wl1271_write32(wl, addr - 2, tmp);
42	}
43}
44
45u16 wl18xx_top_reg_read(struct wl1271 *wl, int addr)
46{
47	u32 val;
48
49	if (WARN_ON(addr % 2))
50		return 0;
51
52	if ((addr % 4) == 0) {
53		/* address is 4-bytes aligned */
54		val = wl1271_read32(wl, addr);
55		return val & 0xffff;
56	} else {
57		val = wl1271_read32(wl, addr - 2);
58		return (val & 0xffff0000) >> 16;
59	}
60}
61