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
10typedef 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
16typedef 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
23typedef struct sdio_device {
24    sdio_device_hw_info_t hw_info;
25    sdio_function_t funcs[SDIO_MAX_FUNCS];
26} sdio_device_t;
27
28
29static inline bool sdio_is_uhs_supported(uint32_t hw_caps) {
30    return ((hw_caps & SDIO_CARD_UHS_SDR50) || (hw_caps & SDIO_CARD_UHS_SDR104) ||
31           (hw_caps & SDIO_CARD_UHS_DDR50));
32}
33
34static inline void update_bits(uint32_t *x, uint32_t mask, uint32_t loc, uint32_t val) {
35    *x &= ~mask;
36    *x |= ((val << loc) & mask);
37}
38
39static inline uint32_t get_bits(uint32_t x, uint32_t mask, uint32_t loc) {
40    return (x & mask) >> loc;
41}
42
43static inline bool get_bit(uint32_t x, uint32_t mask) {
44    return (x & mask) ? 1 : 0;
45}
46
47static inline void update_bits_u8(uint8_t *x, uint8_t mask, uint8_t loc, uint8_t val) {
48    *x &= ~mask;
49    *x |= ((val << loc) & mask);
50}
51
52static inline uint32_t get_bits_u8(uint8_t x, uint8_t mask, uint8_t loc) {
53    return (x & mask) >> loc;
54}
55
56static inline bool get_bit_u8(uint8_t x, uint8_t mask) {
57    return (x & mask) ? 1 : 0;
58}
59
60