1 /*
2  * Copyright (c) 2006-2024 RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author        Notes
8  * 2024-08-16     zhujiale     first version
9  */
10 #ifndef __RT_SDHCI_MISC_H__
11 #define __RT_SDHCI_MISC_H__
12 
13 
14 #define __BF_FIELD_CHECK(...)
15 #define __bf_shf(x) (__builtin_ffsll(x) - 1)
16 #define FIELD_GET(_mask, _reg)                                  \
17     ({                                                          \
18         __BF_FIELD_CHECK(_mask, _reg, 0U, "FIELD_GET: ");       \
19         (typeof(_mask))(((_reg) & (_mask)) >> __bf_shf(_mask)); \
20     })
21 
22 #define FIELD_PREP(_mask, _val)                               \
23     ({                                                        \
24         __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: ");  \
25         ((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask); \
26     })
27 
28 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
29 
30 #define min_t(type, x, y) (((type)x < (type)y) ? x : y)
31 #define max_t(type, x, y) (((type)x > (type)y) ? x : y)
32 #define min(x, y)         ((x) < (y) ? (x) : (y))
33 
34 #define from_timer(var, callback_timer, timer_fieldname) \
35     container_of(callback_timer, typeof(*var), timer_fieldname)
36 
37 
38 #define le32_to_cpu(x)   (x)
39 #define le16_to_cpu(x)   (x)
40 #define cpu_to_le16(x)   (x)
41 #define cpu_to_le32(x)   (x)
42 #define lower_32_bits(n) ((rt_uint32_t)((n) & 0xffffffff))
43 #define upper_32_bits(n) ((rt_uint32_t)(((n) >> 16) >> 16))
44 
45 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
46 
47 #define do_div(n, base) ({            \
48     uint32_t __base = (base);         \
49     uint32_t __rem;                   \
50     __rem = ((uint64_t)(n)) % __base; \
51     (n)   = ((uint64_t)(n)) / __base; \
52     __rem;                            \
53 })
54 
55 #define fallthrough \
56     do {            \
57     } while (0)
58 
59 int       regulator_is_supported_voltage(struct regulator *regulator,
60                                          int min_uV, int max_uV);
61 rt_bool_t rt_mmc_can_gpio_cd(struct rt_mmc_host *host);
62 
63 struct regulator
64 {
65     const char *supply_name;
66 };
67 
68 int regulator_get_current_limit(struct regulator *regulator);
69 
70 #endif
71