1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * This file is part of wl12xx
4 *
5 * Copyright (C) 2008 Nokia Corporation
6 */
7#ifndef __WL1251_IO_H__
8#define __WL1251_IO_H__
9
10#include "wl1251.h"
11
12#define HW_ACCESS_MEMORY_MAX_RANGE		0x1FFC0
13
14#define HW_ACCESS_PART0_SIZE_ADDR           0x1FFC0
15#define HW_ACCESS_PART0_START_ADDR          0x1FFC4
16#define HW_ACCESS_PART1_SIZE_ADDR           0x1FFC8
17#define HW_ACCESS_PART1_START_ADDR          0x1FFCC
18
19#define HW_ACCESS_REGISTER_SIZE             4
20
21#define HW_ACCESS_PRAM_MAX_RANGE		0x3c000
22
23static inline u32 wl1251_read32(struct wl1251 *wl, int addr)
24{
25	wl->if_ops->read(wl, addr, &wl->buffer_32, sizeof(wl->buffer_32));
26
27	return le32_to_cpu(wl->buffer_32);
28}
29
30static inline void wl1251_write32(struct wl1251 *wl, int addr, u32 val)
31{
32	wl->buffer_32 = cpu_to_le32(val);
33	wl->if_ops->write(wl, addr, &wl->buffer_32, sizeof(wl->buffer_32));
34}
35
36static inline u32 wl1251_read_elp(struct wl1251 *wl, int addr)
37{
38	u32 response;
39
40	if (wl->if_ops->read_elp)
41		wl->if_ops->read_elp(wl, addr, &response);
42	else
43		wl->if_ops->read(wl, addr, &response, sizeof(u32));
44
45	return response;
46}
47
48static inline void wl1251_write_elp(struct wl1251 *wl, int addr, u32 val)
49{
50	if (wl->if_ops->write_elp)
51		wl->if_ops->write_elp(wl, addr, val);
52	else
53		wl->if_ops->write(wl, addr, &val, sizeof(u32));
54}
55
56/* Memory target IO, address is translated to partition 0 */
57void wl1251_mem_read(struct wl1251 *wl, int addr, void *buf, size_t len);
58void wl1251_mem_write(struct wl1251 *wl, int addr, void *buf, size_t len);
59u32 wl1251_mem_read32(struct wl1251 *wl, int addr);
60void wl1251_mem_write32(struct wl1251 *wl, int addr, u32 val);
61/* Registers IO */
62u32 wl1251_reg_read32(struct wl1251 *wl, int addr);
63void wl1251_reg_write32(struct wl1251 *wl, int addr, u32 val);
64
65void wl1251_set_partition(struct wl1251 *wl,
66			  u32 part_start, u32 part_size,
67			  u32 reg_start,  u32 reg_size);
68
69#endif
70