aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/drivers/net/wireless/morsemicro/mm81x/bus.h
blob: d2ccabc037fb9baf534e6e795af05759a1fbca04 (plain)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright (c) 2017-2026 Morse Micro
 */

#ifndef _MM81X_BUS_H_
#define _MM81X_BUS_H_

#include <linux/skbuff.h>
#include "core.h"

enum mm81x_bus_type {
	MM81X_BUS_TYPE_USB,
	MM81X_BUS_TYPE_SDIO,
};

struct mm81x_bus_ops {
	int (*dm_read)(struct mm81x *mors, u32 addr, u8 *data, int len);
	int (*dm_write)(struct mm81x *mors, u32 addr, const u8 *data, int len);
	int (*reg32_read)(struct mm81x *mors, u32 addr, u32 *data);
	int (*reg32_write)(struct mm81x *mors, u32 addr, u32 data);
	int (*digital_reset)(struct mm81x *mors);
	void (*set_bus_enable)(struct mm81x *mors, bool enable);
	void (*config_burst_mode)(struct mm81x *mors, bool enable_burst);
	void (*claim)(struct mm81x *mors);
	void (*set_irq)(struct mm81x *mors, bool enable);
	void (*release)(struct mm81x *mors);
	unsigned int bulk_alignment;
};

/*
 * Default TX alignment for buses which don't care. mac80211 will give us
 * SKBs aligned to the 2 byte boundary, so 2 is effectively a noop.
 */
#define MM81X_BUS_DEFAULT_BULK_ALIGNMENT (2)

/* mm81x_dm_read - len must be rounded up to the nearest 4-byte boundary */
static inline int mm81x_dm_read(struct mm81x *mors, u32 addr, u8 *data, int len)
{
	return mors->bus_ops->dm_read(mors, addr, data, len);
}

static inline int mm81x_dm_write(struct mm81x *mors, u32 addr, const u8 *data,
				 int len)
{
	return mors->bus_ops->dm_write(mors, addr, data, len);
}

static inline int mm81x_reg32_read(struct mm81x *mors, u32 addr, u32 *data)
{
	return mors->bus_ops->reg32_read(mors, addr, data);
}

static inline int mm81x_reg32_write(struct mm81x *mors, u32 addr, u32 data)
{
	return mors->bus_ops->reg32_write(mors, addr, data);
}

static inline int mm81x_bus_digital_reset(struct mm81x *mors)
{
	if (mors->bus_ops->digital_reset)
		return mors->bus_ops->digital_reset(mors);

	return 0;
}

static inline void mm81x_set_bus_enable(struct mm81x *mors, bool enable)
{
	mors->bus_ops->set_bus_enable(mors, enable);
}

static inline void mm81x_bus_config_burst_mode(struct mm81x *mors,
					       bool enable_burst)
{
	if (mors->bus_ops->config_burst_mode)
		mors->bus_ops->config_burst_mode(mors, enable_burst);
}

static inline void mm81x_claim_bus(struct mm81x *mors)
{
	mors->bus_ops->claim(mors);
}

static inline void mm81x_bus_set_irq(struct mm81x *mors, bool enable)
{
	mors->bus_ops->set_irq(mors, enable);
}

static inline void mm81x_release_bus(struct mm81x *mors)
{
	mors->bus_ops->release(mors);
}

static inline unsigned int mm81x_bus_get_alignment(struct mm81x *mors)
{
	return mors->bus_ops->bulk_alignment;
}

#endif /* !_MM81X_BUS_H_ */