nvmem.c reads and writes cells on UCLASS_MISC devices with misc_read() and misc_write(), so a build with NVMEM but without MISC fails to link, even when every cell it uses is on an RTC or an I2C EEPROM. The headers of those two providers have stubs for this case; give misc.h the same.
Signed-off-by: Ryan Brue <[email protected]> --- Ran into this while working on the Amazon Fire HD 10 (2017, MediaTek MT8173), whose U-Boot port is not upstream yet: it keeps its reboot mode in an RTC spare byte through nvmem-reboot-mode and has no misc devices, and with NVMEM and DM_RTC but no MISC, the link fails on misc_read() and misc_write() from nvmem.c. With this patch it links and the mode is read and cleared on the board. Developed this patch with the help of an LLM. --- include/misc.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/include/misc.h b/include/misc.h index 6f042625c9f..78cde11c38d 100644 --- a/include/misc.h +++ b/include/misc.h @@ -6,8 +6,12 @@ #ifndef _MISC_H_ #define _MISC_H_ +#include <linux/errno.h> + struct udevice; +#if CONFIG_IS_ENABLED(MISC) + /** * misc_read() - Read the device to buffer, optional. * @dev: the device @@ -78,6 +82,39 @@ int misc_call(struct udevice *dev, int msgid, void *tx_msg, int tx_size, */ int misc_set_enabled(struct udevice *dev, bool val); +#else /* !MISC */ + +static inline int misc_read(struct udevice *dev, int offset, void *buf, + int size) +{ + return -ENOSYS; +} + +static inline int misc_write(struct udevice *dev, int offset, + const void *buf, int size) +{ + return -ENOSYS; +} + +static inline int misc_ioctl(struct udevice *dev, unsigned long request, + void *buf) +{ + return -ENOSYS; +} + +static inline int misc_call(struct udevice *dev, int msgid, void *tx_msg, + int tx_size, void *rx_msg, int rx_size) +{ + return -ENOSYS; +} + +static inline int misc_set_enabled(struct udevice *dev, bool val) +{ + return -ENOSYS; +} + +#endif /* MISC */ + /* * struct misc_ops - Driver model Misc operations * --- base-commit: 8649a54d301a4d0ac526324c7a7ad2574939ff27 change-id: 20261024-b4-rbrue-suez-upstreaming-misc-stubs-d8f9b8f0079f Best regards, -- Ryan Brue <[email protected]>
