Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / net / wireless / ti / wl18xx / io.c
blobce61b4bd1e1e40a8f78ce02368fa095c1828c68b
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * This file is part of wl18xx
5 * Copyright (C) 2011 Texas Instruments
6 */
8 #include "../wlcore/wlcore.h"
9 #include "../wlcore/io.h"
11 #include "io.h"
13 int wl18xx_top_reg_write(struct wl1271 *wl, int addr, u16 val)
15 u32 tmp;
16 int ret;
18 if (WARN_ON(addr % 2))
19 return -EINVAL;
21 if ((addr % 4) == 0) {
22 ret = wlcore_read32(wl, addr, &tmp);
23 if (ret < 0)
24 goto out;
26 tmp = (tmp & 0xffff0000) | val;
27 ret = wlcore_write32(wl, addr, tmp);
28 } else {
29 ret = wlcore_read32(wl, addr - 2, &tmp);
30 if (ret < 0)
31 goto out;
33 tmp = (tmp & 0xffff) | (val << 16);
34 ret = wlcore_write32(wl, addr - 2, tmp);
37 out:
38 return ret;
41 int wl18xx_top_reg_read(struct wl1271 *wl, int addr, u16 *out)
43 u32 val = 0;
44 int ret;
46 if (WARN_ON(addr % 2))
47 return -EINVAL;
49 if ((addr % 4) == 0) {
50 /* address is 4-bytes aligned */
51 ret = wlcore_read32(wl, addr, &val);
52 if (ret >= 0 && out)
53 *out = val & 0xffff;
54 } else {
55 ret = wlcore_read32(wl, addr - 2, &val);
56 if (ret >= 0 && out)
57 *out = (val & 0xffff0000) >> 16;
60 return ret;