diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/bootsource.h | 1 | ||||
-rw-r--r-- | include/linux/bitfield.h | 152 | ||||
-rw-r--r-- | include/linux/bug.h | 25 | ||||
-rw-r--r-- | include/linux/build_bug.h | 83 | ||||
-rw-r--r-- | include/linux/mfd/rave-sp.h | 78 | ||||
-rw-r--r-- | include/memory.h | 8 | ||||
-rw-r--r-- | include/mfd/mc13xxx.h | 19 | ||||
-rw-r--r-- | include/reset_source.h | 17 | ||||
-rw-r--r-- | include/serial/lpuart.h | 21 |
9 files changed, 364 insertions, 40 deletions
diff --git a/include/bootsource.h b/include/bootsource.h index c6d3b3a98b..064f6b9a28 100644 --- a/include/bootsource.h +++ b/include/bootsource.h @@ -16,6 +16,7 @@ enum bootsource { BOOTSOURCE_HD, BOOTSOURCE_USB, BOOTSOURCE_NET, + BOOTSOURCE_CAN, }; #define BOOTSOURCE_INSTANCE_UNKNOWN -1 diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h new file mode 100644 index 0000000000..cf2588d811 --- /dev/null +++ b/include/linux/bitfield.h @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2014 Felix Fietkau <nbd@nbd.name> + * Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef _LINUX_BITFIELD_H +#define _LINUX_BITFIELD_H + +#include <linux/build_bug.h> +#include <asm/byteorder.h> + +/* + * Bitfield access macros + * + * FIELD_{GET,PREP} macros take as first parameter shifted mask + * from which they extract the base mask and shift amount. + * Mask must be a compilation time constant. + * + * Example: + * + * #define REG_FIELD_A GENMASK(6, 0) + * #define REG_FIELD_B BIT(7) + * #define REG_FIELD_C GENMASK(15, 8) + * #define REG_FIELD_D GENMASK(31, 16) + * + * Get: + * a = FIELD_GET(REG_FIELD_A, reg); + * b = FIELD_GET(REG_FIELD_B, reg); + * + * Set: + * reg = FIELD_PREP(REG_FIELD_A, 1) | + * FIELD_PREP(REG_FIELD_B, 0) | + * FIELD_PREP(REG_FIELD_C, c) | + * FIELD_PREP(REG_FIELD_D, 0x40); + * + * Modify: + * reg &= ~REG_FIELD_C; + * reg |= FIELD_PREP(REG_FIELD_C, c); + */ + +#define __bf_shf(x) (__builtin_ffsll(x) - 1) + +#define __BF_FIELD_CHECK(_mask, _reg, _val, _pfx) \ + ({ \ + BUILD_BUG_ON_MSG(!__builtin_constant_p(_mask), \ + _pfx "mask is not constant"); \ + BUILD_BUG_ON_MSG(!(_mask), _pfx "mask is zero"); \ + BUILD_BUG_ON_MSG(__builtin_constant_p(_val) ? \ + ~((_mask) >> __bf_shf(_mask)) & (_val) : 0, \ + _pfx "value too large for the field"); \ + BUILD_BUG_ON_MSG((_mask) > (typeof(_reg))~0ull, \ + _pfx "type of reg too small for mask"); \ + __BUILD_BUG_ON_NOT_POWER_OF_2((_mask) + \ + (1ULL << __bf_shf(_mask))); \ + }) + +/** + * FIELD_FIT() - check if value fits in the field + * @_mask: shifted mask defining the field's length and position + * @_val: value to test against the field + * + * Return: true if @_val can fit inside @_mask, false if @_val is too big. + */ +#define FIELD_FIT(_mask, _val) \ + ({ \ + __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_FIT: "); \ + !((((typeof(_mask))_val) << __bf_shf(_mask)) & ~(_mask)); \ + }) + +/** + * FIELD_PREP() - prepare a bitfield element + * @_mask: shifted mask defining the field's length and position + * @_val: value to put in the field + * + * FIELD_PREP() masks and shifts up the value. The result should + * be combined with other fields of the bitfield using logical OR. + */ +#define FIELD_PREP(_mask, _val) \ + ({ \ + __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: "); \ + ((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask); \ + }) + +/** + * FIELD_GET() - extract a bitfield element + * @_mask: shifted mask defining the field's length and position + * @_reg: value of entire bitfield + * + * FIELD_GET() extracts the field specified by @_mask from the + * bitfield passed in as @_reg by masking and shifting it down. + */ +#define FIELD_GET(_mask, _reg) \ + ({ \ + __BF_FIELD_CHECK(_mask, _reg, 0U, "FIELD_GET: "); \ + (typeof(_mask))(((_reg) & (_mask)) >> __bf_shf(_mask)); \ + }) + +extern void __compiletime_warning("value doesn't fit into mask") +__field_overflow(void); +extern void __compiletime_error("bad bitfield mask") +__bad_mask(void); +static __always_inline u64 field_multiplier(u64 field) +{ + if ((field | (field - 1)) & ((field | (field - 1)) + 1)) + __bad_mask(); + return field & -field; +} +static __always_inline u64 field_mask(u64 field) +{ + return field / field_multiplier(field); +} +#define ____MAKE_OP(type,base,to,from) \ +static __always_inline __##type type##_encode_bits(base v, base field) \ +{ \ + if (__builtin_constant_p(v) && (v & ~field_multiplier(field))) \ + __field_overflow(); \ + return to((v & field_mask(field)) * field_multiplier(field)); \ +} \ +static __always_inline __##type type##_replace_bits(__##type old, \ + base val, base field) \ +{ \ + return (old & ~to(field)) | type##_encode_bits(val, field); \ +} \ +static __always_inline void type##p_replace_bits(__##type *p, \ + base val, base field) \ +{ \ + *p = (*p & ~to(field)) | type##_encode_bits(val, field); \ +} \ +static __always_inline base type##_get_bits(__##type v, base field) \ +{ \ + return (from(v) & field)/field_multiplier(field); \ +} +#define __MAKE_OP(size) \ + ____MAKE_OP(le##size,u##size,cpu_to_le##size,le##size##_to_cpu) \ + ____MAKE_OP(be##size,u##size,cpu_to_be##size,be##size##_to_cpu) \ + ____MAKE_OP(u##size,u##size,,) +__MAKE_OP(16) +__MAKE_OP(32) +__MAKE_OP(64) +#undef __MAKE_OP +#undef ____MAKE_OP + +#endif diff --git a/include/linux/bug.h b/include/linux/bug.h index 7295618c98..8367a11ec2 100644 --- a/include/linux/bug.h +++ b/include/linux/bug.h @@ -2,29 +2,6 @@ #define _LINUX_BUG_H #include <asm-generic/bug.h> - -#ifdef __CHECKER__ -#define BUILD_BUG_ON_NOT_POWER_OF_2(n) (0) -#define BUILD_BUG_ON_ZERO(e) (0) -#define BUILD_BUG_ON_NULL(e) ((void*)0) -#define BUILD_BUG_ON(condition) (0) -#else /* __CHECKER__ */ - -/* Force a compilation error if a constant expression is not a power of 2 */ -#define BUILD_BUG_ON_NOT_POWER_OF_2(n) \ - BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0)) - -/* Force a compilation error if condition is true, but also produce a - result (of value 0 and type size_t), so the expression can be used - e.g. in a structure initializer (or where-ever else comma expressions - aren't permitted). */ -#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) -#define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); })) - -/* Force a compilation error if condition is true */ -#define BUILD_BUG_ON(condition) ((void)BUILD_BUG_ON_ZERO(condition)) - -#endif - +#include <linux/build_bug.h> #endif /* _LINUX_BUG_H */ diff --git a/include/linux/build_bug.h b/include/linux/build_bug.h new file mode 100644 index 0000000000..43d1fd50d4 --- /dev/null +++ b/include/linux/build_bug.h @@ -0,0 +1,83 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_BUILD_BUG_H +#define _LINUX_BUILD_BUG_H + +#include <linux/compiler.h> + +#ifdef __CHECKER__ +#define __BUILD_BUG_ON_NOT_POWER_OF_2(n) (0) +#define BUILD_BUG_ON_NOT_POWER_OF_2(n) (0) +#define BUILD_BUG_ON_ZERO(e) (0) +#define BUILD_BUG_ON_INVALID(e) (0) +#define BUILD_BUG_ON_MSG(cond, msg) (0) +#define BUILD_BUG_ON(condition) (0) +#define BUILD_BUG() (0) +#else /* __CHECKER__ */ + +/* Force a compilation error if a constant expression is not a power of 2 */ +#define __BUILD_BUG_ON_NOT_POWER_OF_2(n) \ + BUILD_BUG_ON(((n) & ((n) - 1)) != 0) +#define BUILD_BUG_ON_NOT_POWER_OF_2(n) \ + BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0)) + +/* + * Force a compilation error if condition is true, but also produce a + * result (of value 0 and type size_t), so the expression can be used + * e.g. in a structure initializer (or where-ever else comma expressions + * aren't permitted). + */ +#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) + +/* + * BUILD_BUG_ON_INVALID() permits the compiler to check the validity of the + * expression but avoids the generation of any code, even if that expression + * has side-effects. + */ +#define BUILD_BUG_ON_INVALID(e) ((void)(sizeof((__force long)(e)))) + +/** + * BUILD_BUG_ON_MSG - break compile if a condition is true & emit supplied + * error message. + * @condition: the condition which the compiler should know is false. + * + * See BUILD_BUG_ON for description. + */ +#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg) + +/** + * BUILD_BUG_ON - break compile if a condition is true. + * @condition: the condition which the compiler should know is false. + * + * If you have some code which relies on certain constants being equal, or + * some other compile-time-evaluated condition, you should use BUILD_BUG_ON to + * detect if someone changes it. + * + * The implementation uses gcc's reluctance to create a negative array, but gcc + * (as of 4.4) only emits that error for obvious cases (e.g. not arguments to + * inline functions). Luckily, in 4.3 they added the "error" function + * attribute just for this type of case. Thus, we use a negative sized array + * (should always create an error on gcc versions older than 4.4) and then call + * an undefined function with the error attribute (should always create an + * error on gcc 4.3 and later). If for some reason, neither creates a + * compile-time error, we'll still have a link-time error, which is harder to + * track down. + */ +#ifndef __OPTIMIZE__ +#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) +#else +#define BUILD_BUG_ON(condition) \ + BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition) +#endif + +/** + * BUILD_BUG - break compile if used. + * + * If you have some code that you expect the compiler to eliminate at + * build time, you should use BUILD_BUG to detect if it is + * unexpectedly used. + */ +#define BUILD_BUG() BUILD_BUG_ON_MSG(1, "BUILD_BUG failed") + +#endif /* __CHECKER__ */ + +#endif /* _LINUX_BUILD_BUG_H */ diff --git a/include/linux/mfd/rave-sp.h b/include/linux/mfd/rave-sp.h new file mode 100644 index 0000000000..e0d97a55d9 --- /dev/null +++ b/include/linux/mfd/rave-sp.h @@ -0,0 +1,78 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +/* + * Core definitions for RAVE SP MFD driver. + * + * Copyright (C) 2017 Zodiac Inflight Innovations + */ + +#ifndef _LINUX_RAVE_SP_H_ +#define _LINUX_RAVE_SP_H_ + +/* #include <linux/notifier.h> */ + +enum rave_sp_command { + RAVE_SP_CMD_GET_FIRMWARE_VERSION = 0x20, + RAVE_SP_CMD_GET_BOOTLOADER_VERSION = 0x21, + RAVE_SP_CMD_BOOT_SOURCE = 0x26, + RAVE_SP_CMD_GET_BOARD_COPPER_REV = 0x2B, + RAVE_SP_CMD_GET_GPIO_STATE = 0x2F, + + RAVE_SP_CMD_STATUS = 0xA0, + RAVE_SP_CMD_SW_WDT = 0xA1, + RAVE_SP_CMD_PET_WDT = 0xA2, + RAVE_SP_CMD_SET_BACKLIGHT = 0xA6, + RAVE_SP_CMD_RESET = 0xA7, + RAVE_SP_CMD_RESET_REASON = 0xA8, + + RAVE_SP_CMD_JUMP_TO_BOOTLOADER = 0xB0, + RAVE_SP_CMD_BOOTLOADER = 0xB1, + RAVE_SP_CMD_REQ_COPPER_REV = 0xB6, + RAVE_SP_CMD_GET_I2C_DEVICE_STATUS = 0xBA, + RAVE_SP_CMD_GET_SP_SILICON_REV = 0xB9, + RAVE_SP_CMD_CONTROL_EVENTS = 0xBB, + + RAVE_SP_EVNT_BASE = 0xE0, +}; + +enum rave_sp_bootloader_command { + RAVE_SP_BOOTLOADER_CMD_QUERY_DEVICE = 0xA1, + RAVE_SP_BOOTLOADER_CMD_ERASE_APP = 0xA3, + RAVE_SP_BOOTLOADER_CMD_PROGRAM_DEVICE = 0xA4, + RAVE_SP_BOOTLOADER_CMD_PROGRAM_COMPLETE = 0xA5, + RAVE_SP_BOOTLOADER_CMD_READ_APP = 0xA6, + RAVE_SP_BOOTLOADER_CMD_RESET_DEVICE = 0xA7, + RAVE_SP_BOOTLOADER_CMD_LAUNCH_APP = 0xA8, +}; + +struct rave_sp; + +static inline unsigned long rave_sp_action_pack(u8 event, u8 value) +{ + return ((unsigned long)value << 8) | event; +} + +static inline u8 rave_sp_action_unpack_event(unsigned long action) +{ + return action; +} + +static inline u8 rave_sp_action_unpack_value(unsigned long action) +{ + return action >> 8; +} + +int rave_sp_exec(struct rave_sp *sp, + void *__data, size_t data_size, + void *reply_data, size_t reply_data_size); + +struct device; +/* int devm_rave_sp_register_event_notifier(struct device *dev, */ +/* struct notifier_block *nb); */ + +bool rave_sp_is_in_bootloader_mode(struct rave_sp *sp); +const struct firmware *rave_sp_get_firmware(struct rave_sp *sp); +void rave_sp_release_firmware(struct rave_sp *sp); +void rave_sp_set_update_fw_status(struct rave_sp *sp, int status); + +#endif /* _LINUX_RAVE_SP_H_ */ diff --git a/include/memory.h b/include/memory.h index 56d16d20c8..73ee7661ef 100644 --- a/include/memory.h +++ b/include/memory.h @@ -32,4 +32,12 @@ void memory_bank_find_space(struct memory_bank *bank, resource_size_t *retstart, int memory_bank_first_find_space(resource_size_t *retstart, resource_size_t *retend); +static inline u64 memory_sdram_size(unsigned int cols, + unsigned int rows, + unsigned int banks, + unsigned int width) +{ + return (u64)banks * width << (rows + cols); +} + #endif diff --git a/include/mfd/mc13xxx.h b/include/mfd/mc13xxx.h index d351c473f4..b38918084d 100644 --- a/include/mfd/mc13xxx.h +++ b/include/mfd/mc13xxx.h @@ -16,6 +16,10 @@ #define MC13XXX_REG_IDENTIFICATION 0x07 +#define MC13783_TYPE 1 +#define MC13892_TYPE 2 +#define MC34708_TYPE 3 + #define MC13783_REG_INT_STATUS0 0x00 #define MC13783_REG_INT_MASK0 0x01 #define MC13783_REG_INT_SENSE0 0x02 @@ -168,6 +172,7 @@ struct mc13xxx; #ifdef CONFIG_MFD_MC13XXX extern struct mc13xxx *mc13xxx_get(void); +extern int mc13xxx_type(struct mc13xxx *mc13xxx); extern int mc13xxx_revision(struct mc13xxx *mc13xxx); extern int mc13xxx_reg_read(struct mc13xxx *mc13xxx, u8 reg, u32 *val); extern int mc13xxx_reg_write(struct mc13xxx *mc13xxx, u8 reg, u32 val); @@ -179,6 +184,11 @@ static inline struct mc13xxx *mc13xxx_get(void) return NULL; } +static inline int mc13xxx_type(struct mc13xxx *mc13xxx) +{ + return -ENODEV; +} + static inline int mc13xxx_revision(struct mc13xxx *mc13xxx) { return -ENODEV; @@ -205,4 +215,13 @@ static inline int mc13xxx_register_init_callback(void(*callback)(struct mc13xxx } #endif +#ifdef CONFIG_MC13XXX_ADC +int mc13xxx_adc_probe(struct device_d *dev, struct mc13xxx *mc_dev); +#else +static inline int mc13xxx_adc_probe(struct device_d *dev, struct mc13xxx *mc_dev) +{ + return 0; +} +#endif + #endif /* __MFD_MC13XXX_H */ diff --git a/include/reset_source.h b/include/reset_source.h index 3ff06b70ad..86e415abcf 100644 --- a/include/reset_source.h +++ b/include/reset_source.h @@ -27,22 +27,39 @@ enum reset_src_type { #ifdef CONFIG_RESET_SOURCE void reset_source_set_priority(enum reset_src_type, unsigned int priority); enum reset_src_type reset_source_get(void); +void reset_source_set_instance(enum reset_src_type type, int instance); +int reset_source_get_instance(void); unsigned int of_get_reset_source_priority(struct device_node *node); +const char *reset_source_name(void); #else static inline void reset_source_set_priority(enum reset_src_type type, unsigned int priority) { } +static inline void reset_source_set_instance(enum reset_src_type type, int instance) +{ +} + static inline enum reset_src_type reset_source_get(void) { return RESET_UKWN; } +static inline int reset_source_get_instance(void) +{ + return 0; +} + static inline unsigned int of_get_reset_source_priority(struct device_node *node) { return 0; } + +static inline const char *reset_source_name(void) +{ + return "unknown"; +} #endif #define RESET_SOURCE_DEFAULT_PRIORITY 100 diff --git a/include/serial/lpuart.h b/include/serial/lpuart.h index 917f644a59..a920291dec 100644 --- a/include/serial/lpuart.h +++ b/include/serial/lpuart.h @@ -238,22 +238,17 @@ static inline void lpuart_setbrg(void __iomem *base, writeb(bfra, base + UARTCR4); } -static inline void lpuart_setup_with_fifo(void __iomem *base, - unsigned int refclock, - unsigned int twfifo) +static inline void lpuart_setup(void __iomem *base, + unsigned int refclock) { /* Disable UART */ writeb(0, base + UARTCR2); writeb(0, base + UARTMODEM); writeb(0, base + UARTCR1); - if (twfifo) { - writeb(UARTPFIFO_TXFE | UARTPFIFO_RXFE, base + UARTPFIFO); - writeb((u8)twfifo, base + UARTTWFIFO); - } else { - writeb(0, base + UARTPFIFO); - writeb(0, base + UARTTWFIFO); - } + writeb(0, base + UARTPFIFO); + writeb(0, base + UARTTWFIFO); + writeb(1, base + UARTRWFIFO); writeb(UARTCFIFO_RXFLUSH | UARTCFIFO_TXFLUSH, base + UARTCFIFO); @@ -262,12 +257,6 @@ static inline void lpuart_setup_with_fifo(void __iomem *base, writeb(UARTCR2_TE | UARTCR2_RE, base + UARTCR2); } -static inline void lpuart_setup(void __iomem *base, - unsigned int refclock) -{ - lpuart_setup_with_fifo(base, refclock, 0x00); -} - static inline void lpuart_putc(void __iomem *base, int c) { if (!(readb(base + UARTCR2) & UARTCR2_TE)) |