1be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho/*
2be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho * This file is part of wl18xx
3be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho *
4be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho * Copyright (C) 2011 Texas Instruments
5be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho *
6be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho * This program is free software; you can redistribute it and/or
7be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho * modify it under the terms of the GNU General Public License
8be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho * version 2 as published by the Free Software Foundation.
9be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho *
10be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho * This program is distributed in the hope that it will be useful, but
11be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho * WITHOUT ANY WARRANTY; without even the implied warranty of
12be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho * General Public License for more details.
14be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho *
15be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho * You should have received a copy of the GNU General Public License
16be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho * along with this program; if not, write to the Free Software
17be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho * 02110-1301 USA
19be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho *
20be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho */
21be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho
22be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho#include "../wlcore/wlcore.h"
23be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho#include "../wlcore/io.h"
24be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho
25be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho#include "io.h"
26be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho
276134323f42b0dbae8e8206414d26cb167b9bedfcIdo Yarivint wl18xx_top_reg_write(struct wl1271 *wl, int addr, u16 val)
28be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho{
29be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho	u32 tmp;
306134323f42b0dbae8e8206414d26cb167b9bedfcIdo Yariv	int ret;
31be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho
32be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho	if (WARN_ON(addr % 2))
336134323f42b0dbae8e8206414d26cb167b9bedfcIdo Yariv		return -EINVAL;
34be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho
35be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho	if ((addr % 4) == 0) {
366134323f42b0dbae8e8206414d26cb167b9bedfcIdo Yariv		ret = wlcore_read32(wl, addr, &tmp);
376134323f42b0dbae8e8206414d26cb167b9bedfcIdo Yariv		if (ret < 0)
386134323f42b0dbae8e8206414d26cb167b9bedfcIdo Yariv			goto out;
396134323f42b0dbae8e8206414d26cb167b9bedfcIdo Yariv
40be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho		tmp = (tmp & 0xffff0000) | val;
41b0f0ad39e3d2716fe9ca6e50ce4cda87eb409ee0Ido Yariv		ret = wlcore_write32(wl, addr, tmp);
42be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho	} else {
436134323f42b0dbae8e8206414d26cb167b9bedfcIdo Yariv		ret = wlcore_read32(wl, addr - 2, &tmp);
446134323f42b0dbae8e8206414d26cb167b9bedfcIdo Yariv		if (ret < 0)
456134323f42b0dbae8e8206414d26cb167b9bedfcIdo Yariv			goto out;
466134323f42b0dbae8e8206414d26cb167b9bedfcIdo Yariv
47be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho		tmp = (tmp & 0xffff) | (val << 16);
48b0f0ad39e3d2716fe9ca6e50ce4cda87eb409ee0Ido Yariv		ret = wlcore_write32(wl, addr - 2, tmp);
49be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho	}
506134323f42b0dbae8e8206414d26cb167b9bedfcIdo Yariv
516134323f42b0dbae8e8206414d26cb167b9bedfcIdo Yarivout:
526134323f42b0dbae8e8206414d26cb167b9bedfcIdo Yariv	return ret;
53be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho}
54be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho
556134323f42b0dbae8e8206414d26cb167b9bedfcIdo Yarivint wl18xx_top_reg_read(struct wl1271 *wl, int addr, u16 *out)
56be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho{
57602c7595a1560c0dea795759193b6e3a6246ea31Arik Nemtsov	u32 val = 0;
586134323f42b0dbae8e8206414d26cb167b9bedfcIdo Yariv	int ret;
59be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho
60be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho	if (WARN_ON(addr % 2))
616134323f42b0dbae8e8206414d26cb167b9bedfcIdo Yariv		return -EINVAL;
62be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho
63be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho	if ((addr % 4) == 0) {
64be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho		/* address is 4-bytes aligned */
656134323f42b0dbae8e8206414d26cb167b9bedfcIdo Yariv		ret = wlcore_read32(wl, addr, &val);
666134323f42b0dbae8e8206414d26cb167b9bedfcIdo Yariv		if (ret >= 0 && out)
676134323f42b0dbae8e8206414d26cb167b9bedfcIdo Yariv			*out = val & 0xffff;
68be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho	} else {
696134323f42b0dbae8e8206414d26cb167b9bedfcIdo Yariv		ret = wlcore_read32(wl, addr - 2, &val);
706134323f42b0dbae8e8206414d26cb167b9bedfcIdo Yariv		if (ret >= 0 && out)
716134323f42b0dbae8e8206414d26cb167b9bedfcIdo Yariv			*out = (val & 0xffff0000) >> 16;
72be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho	}
736134323f42b0dbae8e8206414d26cb167b9bedfcIdo Yariv
746134323f42b0dbae8e8206414d26cb167b9bedfcIdo Yariv	return ret;
75be65202a610ca96aa945789c8b0a7bc3529b556eLuciano Coelho}
76