io.c 1.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*
 * This file is part of wl18xx
 *
 * Copyright (C) 2011 Texas Instruments
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

#include "../wlcore/wlcore.h"
#include "../wlcore/io.h"

#include "io.h"

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 37 38 39
		ret = wlcore_read32(wl, addr, &tmp);
		if (ret < 0)
			goto out;

40
		tmp = (tmp & 0xffff0000) | val;
41
		ret = wlcore_write32(wl, addr, tmp);
42
	} else {
43 44 45 46
		ret = wlcore_read32(wl, addr - 2, &tmp);
		if (ret < 0)
			goto out;

47
		tmp = (tmp & 0xffff) | (val << 16);
48
		ret = wlcore_write32(wl, addr - 2, tmp);
49
	}
50 51 52

out:
	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 64

	if ((addr % 4) == 0) {
		/* address is 4-bytes aligned */
65 66 67
		ret = wlcore_read32(wl, addr, &val);
		if (ret >= 0 && out)
			*out = val & 0xffff;
68
	} else {
69 70 71
		ret = wlcore_read32(wl, addr - 2, &val);
		if (ret >= 0 && out)
			*out = (val & 0xffff0000) >> 16;
72
	}
73 74

	return ret;
75
}