From a672ca37ab530c3d8c88144ebcd9cb51b8cd9739 Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Wed, 11 Sep 2019 21:27:37 +0200 Subject: state: drop unused code and declarations for non-existing functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit state_get_name() is not used and so can be removed. state_backend_dtb_file() and state_backend_raw_file() were dropped in c999b507da98 ("state: Refactor state framework"). Signed-off-by: Uwe Kleine-König Signed-off-by: Sascha Hauer --- include/state.h | 5 ----- 1 file changed, 5 deletions(-) (limited to 'include') diff --git a/include/state.h b/include/state.h index 4e995a19ef..a49155ef27 100644 --- a/include/state.h +++ b/include/state.h @@ -5,17 +5,12 @@ struct state; -int state_backend_dtb_file(struct state *state, const char *of_path, - const char *path); -int state_backend_raw_file(struct state *state, const char *of_path, - const char *path, off_t offset, size_t size); struct state *state_new_from_node(struct device_node *node, bool readonly); void state_release(struct state *state); struct state *state_by_name(const char *name); struct state *state_by_node(const struct device_node *node); -int state_get_name(const struct state *state, char const **name); int state_load_no_auth(struct state *state); int state_load(struct state *state); -- cgit v1.2.3 From 9bbaa740f6a86f04a27b5ed79ed7d6697123eae5 Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Wed, 11 Sep 2019 21:27:38 +0200 Subject: state: provide dummy implementations for some functions when STATE is disabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows to simplify some callers as can be seen from the phytec-som-am335x/board.c change. (The check for state != NULL could be dropped already before.) Signed-off-by: Uwe Kleine-König Signed-off-by: Sascha Hauer --- arch/arm/boards/phytec-som-am335x/board.c | 14 +++++------- include/state.h | 36 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/arch/arm/boards/phytec-som-am335x/board.c b/arch/arm/boards/phytec-som-am335x/board.c index 441d56348c..c25f33ae20 100644 --- a/arch/arm/boards/phytec-som-am335x/board.c +++ b/arch/arm/boards/phytec-som-am335x/board.c @@ -124,15 +124,11 @@ static int physom_devices_init(void) ARRAY_SIZE(nandslots)); am33xx_bbu_emmc_mlo_register_handler("MLO.emmc", "/dev/mmc1"); - if (IS_ENABLED(CONFIG_STATE)) { - state = state_by_name("am335x_phytec_mac_state"); - if (state) - for (state_i = 0; state_i < 2; state_i++) { - state_ret = state_read_mac(state, - eth_names[state_i], &mac[0]); - if (!state_ret && is_valid_ether_addr(&mac[0])) - eth_register_ethaddr(state_i, mac); - } + state = state_by_name("am335x_phytec_mac_state"); + for (state_i = 0; state_i < 2; state_i++) { + state_ret = state_read_mac(state, eth_names[state_i], &mac[0]); + if (!state_ret && is_valid_ether_addr(&mac[0])) + eth_register_ethaddr(state_i, mac); } if (IS_ENABLED(CONFIG_PHYTEC_SOM_AM335X_OF_AUTOENABLE)) { diff --git a/include/state.h b/include/state.h index a49155ef27..d98b781c20 100644 --- a/include/state.h +++ b/include/state.h @@ -5,6 +5,7 @@ struct state; +#if IS_ENABLED(CONFIG_STATE) struct state *state_new_from_node(struct device_node *node, bool readonly); void state_release(struct state *state); @@ -19,4 +20,39 @@ void state_info(void); int state_read_mac(struct state *state, const char *name, u8 *buf); +#else /* #if IS_ENABLED(CONFIG_STATE) */ + +static inline struct state *state_new_from_node(struct device_node *node, + bool readonly) +{ + return ERR_PTR(-ENOSYS); +} + +static inline struct state *state_by_name(const char *name) +{ + return NULL; +} + +static inline struct state *state_by_node(const struct device_node *node) +{ + return NULL; +}; + +static inline int state_load(struct state *state) +{ + return -ENOSYS; +} + +static inline int state_save(struct state *state) +{ + return -ENOSYS; +} + +static inline int state_read_mac(struct state *state, const char *name, u8 *buf) +{ + return -ENOSYS; +} + +#endif /* #if IS_ENABLED(CONFIG_STATE) / #else */ + #endif /* __STATE_H */ -- cgit v1.2.3 From 9a198b0054742d07a84f67b8e86a537b9c836f63 Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Tue, 17 Sep 2019 12:29:32 +0200 Subject: trivial: fix typo lenght -> length MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Generated by perl -p -i -e 's/lenghte?/length/' arch/arm/boards/chumby_falconwing/falconwing.c arch/arm/mach-samsung/mem-s3c64xx.c fs/ext4/ext_common.h lib/gui/lodepng.c include/jtag.h There is another instance in dts/Bindings/usb/s3c2410-usb.txt, this is fixed in Linux v5.3-rc1 so supposed to be fixed soon in barebox, too. Signed-off-by: Uwe Kleine-König Signed-off-by: Sascha Hauer --- arch/arm/boards/chumby_falconwing/falconwing.c | 2 +- arch/arm/mach-samsung/mem-s3c64xx.c | 2 +- fs/ext4/ext_common.h | 2 +- include/jtag.h | 2 +- lib/gui/lodepng.c | 16 ++++++++-------- 5 files changed, 12 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/arch/arm/boards/chumby_falconwing/falconwing.c b/arch/arm/boards/chumby_falconwing/falconwing.c index 42dd838d75..fb4a5d1cf0 100644 --- a/arch/arm/boards/chumby_falconwing/falconwing.c +++ b/arch/arm/boards/chumby_falconwing/falconwing.c @@ -65,7 +65,7 @@ static struct fb_videomode falconwing_vmode = { .xres = 320, .yres = 240, .pixclock = KHZ2PICOS(6250), /* max. 10 MHz */ - /* line lenght should be 64 µs */ + /* line length should be 64 µs */ .left_margin = 28, .hsync_len = 24, .right_margin = 28, diff --git a/arch/arm/mach-samsung/mem-s3c64xx.c b/arch/arm/mach-samsung/mem-s3c64xx.c index aca2cf5066..c51245a378 100644 --- a/arch/arm/mach-samsung/mem-s3c64xx.c +++ b/arch/arm/mach-samsung/mem-s3c64xx.c @@ -39,7 +39,7 @@ int s3c6410_setup_chipselect(int no, const struct s3c6410_chipselect *c) tacs = DIV_ROUND_UP(c->adr_setup_t, per_t); /* start of CS to read/write assertion (= access setup) */ tcos = DIV_ROUND_UP(c->access_setup_t, per_t); - /* length of read/write assertion (= access lenght) */ + /* length of read/write assertion (= access length) */ tacc = DIV_ROUND_UP(c->access_t, per_t) - 1; /* CS hold after access is finished */ tcoh = DIV_ROUND_UP(c->cs_hold_t, per_t); diff --git a/fs/ext4/ext_common.h b/fs/ext4/ext_common.h index c084cf9a32..a28f591bc4 100644 --- a/fs/ext4/ext_common.h +++ b/fs/ext4/ext_common.h @@ -37,7 +37,7 @@ /* Amount of indirect blocks in an inode. */ #define INDIRECT_BLOCKS 12 -/* Maximum lenght of a pathname. */ +/* Maximum length of a pathname. */ #define EXT2_PATH_MAX 4096 /* Maximum nesting of symlinks, used to prevent a loop. */ #define EXT2_MAX_SYMLINKCNT 8 diff --git a/include/jtag.h b/include/jtag.h index 26c95fb307..4cc4eaca91 100644 --- a/include/jtag.h +++ b/include/jtag.h @@ -28,7 +28,7 @@ * (repeat for each chip in the chain) * - ioctl JTAG_GET_ID identifies the chip * - ioctl JTAG_SET_IR_LENGTH sets the instruction register length - * Before accessing the data registers, instruction registers' lenghtes + * Before accessing the data registers, instruction registers' lengths * MUST be programmed for all chips. * After this initialization, you can execute JTAG_IR_WR, JTAG_DR_RD, JTAG_DR_WR * commands in any sequence. diff --git a/lib/gui/lodepng.c b/lib/gui/lodepng.c index 78a34db473..82fa90ab23 100644 --- a/lib/gui/lodepng.c +++ b/lib/gui/lodepng.c @@ -822,7 +822,7 @@ unsigned lodepng_huffman_code_lengths(unsigned* lengths, const unsigned* frequen if(!error) { - /*calculate the lenghts of each symbol, as the amount of times a coin of each symbol is used*/ + /*calculate the lengths of each symbol, as the amount of times a coin of each symbol is used*/ for(i = 0; i < numpresent - 1; i++) { Coin* coin = &coins[i]; @@ -1678,7 +1678,7 @@ static unsigned deflateDynamic(ucvector* out, size_t* bp, Hash* hash, another huffman tree is used for the dist values ("d"). These two trees are stored using their code lengths, and to compress even more these code lengths are also run-length encoded and huffman compressed. This gives a huffman tree - of code lengths "cl". The code lenghts used to describe this third tree are + of code lengths "cl". The code lengths used to describe this third tree are the code length code lengths ("clcl"). */ @@ -1690,7 +1690,7 @@ static unsigned deflateDynamic(ucvector* out, size_t* bp, Hash* hash, uivector frequencies_ll; /*frequency of lit,len codes*/ uivector frequencies_d; /*frequency of dist codes*/ uivector frequencies_cl; /*frequency of code length codes*/ - uivector bitlen_lld; /*lit,len,dist code lenghts (int bits), literally (without repeat codes).*/ + uivector bitlen_lld; /*lit,len,dist code lengths (int bits), literally (without repeat codes).*/ uivector bitlen_lld_e; /*bitlen_lld encoded with repeat codes (this is a rudemtary run length compression)*/ /*bitlen_cl is the code length code lengths ("clcl"). The bit lengths of codes to represent tree_cl (these are written as is in the file, it would be crazy to compress these using yet another huffman @@ -1828,7 +1828,7 @@ static unsigned deflateDynamic(ucvector* out, size_t* bp, Hash* hash, if(!uivector_resize(&bitlen_cl, NUM_CODE_LENGTH_CODES)) ERROR_BREAK(83 /*alloc fail*/); for(i = 0; i < NUM_CODE_LENGTH_CODES; i++) { - /*lenghts of code length tree is in the order as specified by deflate*/ + /*lengths of code length tree is in the order as specified by deflate*/ bitlen_cl.data[i] = HuffmanTree_getLength(&tree_cl, CLCL_ORDER[i]); } while(bitlen_cl.data[bitlen_cl.size - 1] == 0 && bitlen_cl.size > 4) @@ -1844,7 +1844,7 @@ static unsigned deflateDynamic(ucvector* out, size_t* bp, Hash* hash, After the BFINAL and BTYPE, the dynamic block consists out of the following: - 5 bits HLIT, 5 bits HDIST, 4 bits HCLEN - (HCLEN+4)*3 bits code lengths of code length alphabet - - HLIT + 257 code lenghts of lit/length alphabet (encoded using the code length + - HLIT + 257 code lengths of lit/length alphabet (encoded using the code length alphabet, + possible repetition codes 16, 17, 18) - HDIST + 1 code lengths of distance alphabet (encoded using the code length alphabet, + possible repetition codes 16, 17, 18) @@ -1865,10 +1865,10 @@ static unsigned deflateDynamic(ucvector* out, size_t* bp, Hash* hash, addBitsToStream(bp, out, HDIST, 5); addBitsToStream(bp, out, HCLEN, 4); - /*write the code lenghts of the code length alphabet*/ + /*write the code lengths of the code length alphabet*/ for(i = 0; i < HCLEN + 4; i++) addBitsToStream(bp, out, bitlen_cl.data[i], 3); - /*write the lenghts of the lit/len AND the dist alphabet*/ + /*write the lengths of the lit/len AND the dist alphabet*/ for(i = 0; i < bitlen_lld_e.size; i++) { addHuffmanSymbol(bp, out, HuffmanTree_getCode(&tree_cl, bitlen_lld_e.data[i]), @@ -5608,7 +5608,7 @@ const char* lodepng_error_text(unsigned code) /*jumped past tree while generating huffman tree, this could be when the tree will have more leaves than symbols after generating it out of the - given lenghts. They call this an oversubscribed dynamic bit lengths tree in zlib.*/ + given lengths. They call this an oversubscribed dynamic bit lengths tree in zlib.*/ case 55: return "jumped past tree while generating huffman tree"; case 56: return "given output image colortype or bitdepth not supported for color conversion"; -- cgit v1.2.3 From efd517c35f122bb08ebc1fc29e741a5211553acc Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Fri, 11 Oct 2019 18:27:50 +0200 Subject: mfd: add basic Super I/O chip helpers Super I/O chips are ICs common to x86 that are used for interfacing to low-bandwidth peripherals. They often contain serial ports, watchdog timers and hardware monitoring units. They are usually addressable via one of two I/O port pairs, either 0x2e-0x2f or 0x4e-0x4f, but they don't typically respond to reads from their range unless a device-specific 'password' has been poked in. After this is done, they are read and written in the same manner however. On Linux, these devices aren't subject to any device/driver model. Each driver for some function (e.g. watchdog or GPIO) duplicates the device probe in the module_init and board-specific configuration is handled via module parameters. Lets do it a bit fancier in barebox and add a helper to register chips and a regmap for the control and configuration registers as well as a helper to register child devices for each function contained within the Super I/O chip. Board-specific configuration, e.g. which pin to use as a watchdog reset, can then be realized using barebox device-specific parameters. The regmap will be more of a debugging aid, however. For ease of porting from Linux, it's expected that access to the I/O ports won't happen via the regmap. For this reason, the new header offers functions to read/write these chips' registers as well. Signed-off-by: Ahmad Fatoum Signed-off-by: Sascha Hauer --- drivers/mfd/Kconfig | 3 ++ drivers/mfd/Makefile | 1 + drivers/mfd/superio.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/superio.h | 64 +++++++++++++++++++++++++++++++++ 4 files changed, 166 insertions(+) create mode 100644 drivers/mfd/superio.c create mode 100644 include/superio.h (limited to 'include') diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 7d924cfca1..bd6f14a59f 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -67,4 +67,7 @@ config MFD_STPMIC1 help Select this to support communication with the STPMIC1. +config MFD_SUPERIO + bool + endmenu diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 16a74abd77..690788eefb 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -12,3 +12,4 @@ obj-$(CONFIG_MFD_TWL4030) += twl4030.o obj-$(CONFIG_MFD_TWL6030) += twl6030.o obj-$(CONFIG_RAVE_SP_CORE) += rave-sp.o obj-$(CONFIG_MFD_STPMIC1) += stpmic1.o +obj-$(CONFIG_MFD_SUPERIO) += superio.o diff --git a/drivers/mfd/superio.c b/drivers/mfd/superio.c new file mode 100644 index 0000000000..0f08d56cb3 --- /dev/null +++ b/drivers/mfd/superio.c @@ -0,0 +1,98 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2019 Ahmad Fatoum, Pengutronix + */ + +#define pr_fmt(fmt) "superio: " fmt + +#include +#include +#include + +struct device_d *superio_func_add(struct superio_chip *siochip, const char *name) +{ + struct device_d *dev; + int ret; + + dev = device_alloc(name, DEVICE_ID_DYNAMIC); + dev->parent = siochip->dev; + + + ret = platform_device_register(dev); + if (ret) + return NULL; + + return dev; +} +EXPORT_SYMBOL(superio_func_add) + +static int superio_reg_read(void *ctx, unsigned int reg, unsigned int *val) +{ + struct superio_chip *siochip = ctx; + + siochip->enter(siochip->sioaddr); + + *val = superio_inb(siochip->sioaddr, reg); + + siochip->exit(siochip->sioaddr); + + return 0; +} + +static int superio_reg_write(void *ctx, unsigned int reg, unsigned int val) +{ + struct superio_chip *siochip = ctx; + + siochip->enter(siochip->sioaddr); + + superio_outb(siochip->sioaddr, reg, val); + + siochip->exit(siochip->sioaddr); + + return 0; +} + +static struct regmap_bus superio_regmap_bus = { + .reg_write = superio_reg_write, + .reg_read = superio_reg_read, +}; + +static struct regmap_config superio_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .reg_stride = 1, + .max_register = 0xff, +}; + +void superio_chip_add(struct superio_chip *siochip) +{ + struct regmap *regmap; + char *chipname; + char str[5]; + int ret; + + chipname = xasprintf("superio-%04x:%04x@%02x", + siochip->vid, siochip->devid, siochip->sioaddr); + siochip->dev = add_generic_device(chipname, DEVICE_ID_SINGLE, NULL, + siochip->sioaddr, 2, IORESOURCE_IO, + NULL); + + siochip->dev->priv = siochip; + + sprintf(str, "%04x", siochip->vid); + dev_add_param_fixed(siochip->dev, "vendor", str); + sprintf(str, "%04x", siochip->devid); + dev_add_param_fixed(siochip->dev, "device", str); + + regmap = regmap_init(siochip->dev, &superio_regmap_bus, siochip, + &superio_regmap_config); + if (IS_ERR(regmap)) + pr_warn("creating %s regmap failed: %s\n", + chipname, strerror(-PTR_ERR(regmap))); + + ret = regmap_register_cdev(regmap, chipname); + if (ret) + pr_warn("registering %s regmap cdev failed: %s\n", + chipname, strerror(-ret)); +} +EXPORT_SYMBOL(superio_chip_add) diff --git a/include/superio.h b/include/superio.h new file mode 100644 index 0000000000..12bff58b6b --- /dev/null +++ b/include/superio.h @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2019 Ahmad Fatoum, Pengutronix + */ + +#ifndef _SUPERIO_H_ +#define _SUPERIO_H_ + +#include +#include +#include +#include + +#define SIO_REG_DEVID 0x20 /* Device ID (2 bytes) */ +#define SIO_REG_DEVREV 0x22 /* Device revision */ +#define SIO_REG_MANID 0x23 /* Vendor ID (2 bytes) */ + +static inline u8 superio_inb(u16 base, u8 reg) +{ + outb(reg, base); + return inb(base + 1); +} + +static inline u16 superio_inw(u16 base, u8 reg) +{ + u16 val; + val = superio_inb(base, reg) << 8; + val |= superio_inb(base, reg + 1); + return val; +} + +static inline void superio_outb(u16 base, u8 reg, u8 val) +{ + outb(reg, base); + outb(val, base + 1); +} + +static inline void superio_set_bit(u16 base, u8 reg, unsigned bit) +{ + unsigned long val = superio_inb(base, reg); + __set_bit(bit, &val); + superio_outb(base, reg, val); +} + +static inline void superio_clear_bit(u16 base, u8 reg, unsigned bit) +{ + unsigned long val = superio_inb(base, reg); + __clear_bit(bit, &val); + superio_outb(base, reg, val); +} + +struct superio_chip { + struct device_d *dev; + u16 vid; + u16 devid; + u16 sioaddr; + void (*enter)(u16 sioaddr); + void (*exit)(u16 sioaddr); +}; + +void superio_chip_add(struct superio_chip *chip); +struct device_d *superio_func_add(struct superio_chip *chip, const char *name); + +#endif -- cgit v1.2.3