diff options
author | Darwin Rambo <drambo@broadcom.com> | 2014-02-11 11:06:34 -0800 |
---|---|---|
committer | Albert ARIBAUD <albert.u.boot@aribaud.net> | 2014-02-22 19:30:24 +0100 |
commit | 989ce049997daefc25c15e1d5bf5307cdca25abb (patch) | |
tree | 52066caa3d0e37e471d7fd0c7a9dadf1d2329db6 /include/bitfield.h | |
parent | b3134fce890754ceb33fe79d7b0d8f78ee83129f (diff) | |
download | u-boot-989ce049997daefc25c15e1d5bf5307cdca25abb.zip u-boot-989ce049997daefc25c15e1d5bf5307cdca25abb.tar.gz u-boot-989ce049997daefc25c15e1d5bf5307cdca25abb.tar.bz2 |
arch: bcm281xx: Initial commit of bcm281xx architecture code
Add bcm281xx architecture support code including a clock framework and
chip reset. Define register block base addresses for the bcm281xx
architecture and create an empty gpio header file required when
CONFIG_CMD_GPIO is set.
Signed-off-by: Darwin Rambo <drambo@broadcom.com>
Reviewed-by: Steve Rae <srae@broadcom.com>
Reviewed-by: Tim Kryger <tkryger@linaro.org>
Diffstat (limited to 'include/bitfield.h')
-rw-r--r-- | include/bitfield.h | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/include/bitfield.h b/include/bitfield.h new file mode 100644 index 0000000..ec4815c --- /dev/null +++ b/include/bitfield.h @@ -0,0 +1,58 @@ +/* + * Copyright 2013 Broadcom Corporation. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +/* + * Bitfield operations + * + * These are generic bitfield operations which allow manipulation of variable + * width bitfields within a word. One use of this would be to use data tables + * to determine how to reprogram fields within R/W hardware registers. + * + * Example: + * + * old_reg_val + * +--------+----+---+--+-----+----------+ + * | | | | | old | | + * +--------+----+---+--+-----+----------+ + * + * new_reg_val + * +--------+----+---+--+-----+----------+ + * | | | | | new | | + * +--------+----+---+--+-----+----------+ + * + * mask = bitfield_mask(10, 5); + * old = bitfield_extract(old_reg_val, 10, 5); + * new_reg_val = bitfield_replace(old_reg_val, 10, 5, new); + * + * The numbers 10 and 5 could for example come from data + * tables which describe all bitfields in all registers. + */ + +#include <linux/types.h> + +/* Produces a mask of set bits covering a range of a uint value */ +static inline uint bitfield_mask(uint shift, uint width) +{ + return ((1 << width) - 1) << shift; +} + +/* Extract the value of a bitfield found within a given register value */ +static inline uint bitfield_extract(uint reg_val, uint shift, uint width) +{ + return (reg_val & bitfield_mask(shift, width)) >> shift; +} + +/* + * Replace the value of a bitfield found within a given register value + * Returns the newly modified uint value with the replaced field. + */ +static inline uint bitfield_replace(uint reg_val, uint shift, uint width, + uint bitfield_val) +{ + uint mask = bitfield_mask(shift, width); + + return (reg_val & ~mask) | (bitfield_val << shift); +} |