1 // Copyright 2018 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #pragma once
6
7 #include <zircon/compiler.h>
8 #include <ddk/protocol/sdio.h>
9
10 typedef struct sdio_func_tuple {
11 uint8_t t_code;
12 uint8_t t_body_size;
13 uint8_t *t_body;
14 } sdio_func_tuple_t;
15
16 typedef struct sdio_function {
17 sdio_func_hw_info_t hw_info;
18 uint16_t cur_blk_size;
19 bool enabled;
20 bool intr_enabled;
21 } sdio_function_t;
22
23 typedef struct sdio_device {
24 sdio_device_hw_info_t hw_info;
25 sdio_function_t funcs[SDIO_MAX_FUNCS];
26 } sdio_device_t;
27
sdio_fn_idx_valid(uint8_t fn_idx)28 static inline bool sdio_fn_idx_valid(uint8_t fn_idx) {
29 return (fn_idx < SDIO_MAX_FUNCS);
30 }
31
sdio_is_uhs_supported(uint32_t hw_caps)32 static inline bool sdio_is_uhs_supported(uint32_t hw_caps) {
33 return ((hw_caps & SDIO_CARD_UHS_SDR50) || (hw_caps & SDIO_CARD_UHS_SDR104) ||
34 (hw_caps & SDIO_CARD_UHS_DDR50));
35 }
36
update_bits(uint32_t * x,uint32_t mask,uint32_t loc,uint32_t val)37 static inline void update_bits(uint32_t *x, uint32_t mask, uint32_t loc, uint32_t val) {
38 *x &= ~mask;
39 *x |= ((val << loc) & mask);
40 }
41
get_bits(uint32_t x,uint32_t mask,uint32_t loc)42 static inline uint32_t get_bits(uint32_t x, uint32_t mask, uint32_t loc) {
43 return (x & mask) >> loc;
44 }
45
get_bit(uint32_t x,uint32_t mask)46 static inline bool get_bit(uint32_t x, uint32_t mask) {
47 return (x & mask) ? 1 : 0;
48 }
49
update_bits_u8(uint8_t * x,uint8_t mask,uint8_t loc,uint8_t val)50 static inline void update_bits_u8(uint8_t *x, uint8_t mask, uint8_t loc, uint8_t val) {
51 *x &= ~mask;
52 *x |= ((val << loc) & mask);
53 }
54
get_bits_u8(uint8_t x,uint8_t mask,uint8_t loc)55 static inline uint32_t get_bits_u8(uint8_t x, uint8_t mask, uint8_t loc) {
56 return (x & mask) >> loc;
57 }
58
get_bit_u8(uint8_t x,uint8_t mask)59 static inline bool get_bit_u8(uint8_t x, uint8_t mask) {
60 return (x & mask) ? 1 : 0;
61 }
62
63