1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright (c) 2017-2026 Morse Micro 4 */ 5 6 #ifndef _MM81X_BUS_H_ 7 #define _MM81X_BUS_H_ 8 9 #include <linux/skbuff.h> 10 #include "core.h" 11 12 enum mm81x_bus_type { 13 MM81X_BUS_TYPE_USB, 14 MM81X_BUS_TYPE_SDIO, 15 }; 16 17 struct mm81x_bus_ops { 18 int (*dm_read)(struct mm81x *mors, u32 addr, u8 *data, int len); 19 int (*dm_write)(struct mm81x *mors, u32 addr, const u8 *data, int len); 20 int (*reg32_read)(struct mm81x *mors, u32 addr, u32 *data); 21 int (*reg32_write)(struct mm81x *mors, u32 addr, u32 data); 22 int (*digital_reset)(struct mm81x *mors); 23 void (*set_bus_enable)(struct mm81x *mors, bool enable); 24 void (*config_burst_mode)(struct mm81x *mors, bool enable_burst); 25 void (*claim)(struct mm81x *mors); 26 void (*set_irq)(struct mm81x *mors, bool enable); 27 void (*release)(struct mm81x *mors); 28 unsigned int bulk_alignment; 29 }; 30 31 /* 32 * Default TX alignment for buses which don't care. mac80211 will give us 33 * SKBs aligned to the 2 byte boundary, so 2 is effectively a noop. 34 */ 35 #define MM81X_BUS_DEFAULT_BULK_ALIGNMENT (2) 36 37 /* mm81x_dm_read - len must be rounded up to the nearest 4-byte boundary */ 38 static inline int mm81x_dm_read(struct mm81x *mors, u32 addr, u8 *data, int len) 39 { 40 return mors->bus_ops->dm_read(mors, addr, data, len); 41 } 42 43 static inline int mm81x_dm_write(struct mm81x *mors, u32 addr, const u8 *data, 44 int len) 45 { 46 return mors->bus_ops->dm_write(mors, addr, data, len); 47 } 48 49 static inline int mm81x_reg32_read(struct mm81x *mors, u32 addr, u32 *data) 50 { 51 return mors->bus_ops->reg32_read(mors, addr, data); 52 } 53 54 static inline int mm81x_reg32_write(struct mm81x *mors, u32 addr, u32 data) 55 { 56 return mors->bus_ops->reg32_write(mors, addr, data); 57 } 58 59 static inline int mm81x_bus_digital_reset(struct mm81x *mors) 60 { 61 if (mors->bus_ops->digital_reset) 62 return mors->bus_ops->digital_reset(mors); 63 64 return 0; 65 } 66 67 static inline void mm81x_set_bus_enable(struct mm81x *mors, bool enable) 68 { 69 mors->bus_ops->set_bus_enable(mors, enable); 70 } 71 72 static inline void mm81x_bus_config_burst_mode(struct mm81x *mors, 73 bool enable_burst) 74 { 75 if (mors->bus_ops->config_burst_mode) 76 mors->bus_ops->config_burst_mode(mors, enable_burst); 77 } 78 79 static inline void mm81x_claim_bus(struct mm81x *mors) 80 { 81 mors->bus_ops->claim(mors); 82 } 83 84 static inline void mm81x_bus_set_irq(struct mm81x *mors, bool enable) 85 { 86 mors->bus_ops->set_irq(mors, enable); 87 } 88 89 static inline void mm81x_release_bus(struct mm81x *mors) 90 { 91 mors->bus_ops->release(mors); 92 } 93 94 static inline unsigned int mm81x_bus_get_alignment(struct mm81x *mors) 95 { 96 return mors->bus_ops->bulk_alignment; 97 } 98 99 #endif /* !_MM81X_BUS_H_ */ 100