From 811d9e2268a62b830cfe93cd8bc929afcb8b198b Mon Sep 17 00:00:00 2001
From: Felix Fietkau <nbd@nbd.name>
Date: Sat, 15 Jul 2017 21:12:38 +0200
Subject: kernel: move regmap bloat out of the kernel image if it is only being used in modules

lede-commit: 96f39119815028073583e4fca3a9c5fe9141e998
Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
 drivers/base/regmap/Kconfig  | 15 ++++++++++-----
 drivers/base/regmap/Makefile | 12 ++++++++----
 drivers/base/regmap/regmap.c |  3 +++
 include/linux/regmap.h       |  2 +-
 4 files changed, 22 insertions(+), 10 deletions(-)

--- a/drivers/base/regmap/Kconfig
+++ b/drivers/base/regmap/Kconfig
@@ -4,8 +4,7 @@
 # subsystems should select the appropriate symbols.
 
 config REGMAP
-	bool
-	default y if (REGMAP_I2C || REGMAP_SPI || REGMAP_SPMI || REGMAP_W1 || REGMAP_AC97 || REGMAP_MMIO || REGMAP_IRQ || REGMAP_SOUNDWIRE || REGMAP_SOUNDWIRE_MBQ || REGMAP_SCCB || REGMAP_I3C || REGMAP_SPI_AVMM || REGMAP_MDIO || REGMAP_FSI)
+	tristate
 	select IRQ_DOMAIN if REGMAP_IRQ
 	select MDIO_BUS if REGMAP_MDIO
 	help
@@ -19,7 +18,7 @@ config REGMAP
 
 config REGMAP_KUNIT
 	tristate "KUnit tests for regmap"
-	depends on KUNIT && REGMAP
+	depends on KUNIT
 	default KUNIT_ALL_TESTS
 	select REGMAP_RAM
 
@@ -34,60 +33,76 @@ config REGMAP_BUILD
 	  normally enabled.
 
 config REGMAP_AC97
+	select REGMAP
 	tristate
 
 config REGMAP_I2C
+	select REGMAP
 	tristate
 	depends on I2C
 
 config REGMAP_SLIMBUS
+	select REGMAP
 	tristate
 	depends on SLIMBUS
 
 config REGMAP_SPI
+	select REGMAP
 	tristate
 	depends on SPI
 
 config REGMAP_SPMI
+	select REGMAP
 	tristate
 	depends on SPMI
 
 config REGMAP_W1
+	select REGMAP
 	tristate
 	depends on W1
 
 config REGMAP_MDIO
+	select REGMAP
 	tristate
 
 config REGMAP_MMIO
+	select REGMAP
 	tristate
 
 config REGMAP_IRQ
+	select REGMAP
 	bool
 
 config REGMAP_RAM
+	select REGMAP
 	tristate
 
 config REGMAP_SOUNDWIRE
+	select REGMAP
 	tristate
 	depends on SOUNDWIRE
 
 config REGMAP_SOUNDWIRE_MBQ
+	select REGMAP
 	tristate
 	depends on SOUNDWIRE
 
 config REGMAP_SCCB
+	select REGMAP
 	tristate
 	depends on I2C
 
 config REGMAP_I3C
+	select REGMAP
 	tristate
 	depends on I3C
 
 config REGMAP_SPI_AVMM
+	select REGMAP
 	tristate
 	depends on SPI
 
 config REGMAP_FSI
+	select REGMAP
 	tristate
 	depends on FSI
--- a/drivers/base/regmap/Makefile
+++ b/drivers/base/regmap/Makefile
@@ -2,9 +2,11 @@
 # For include/trace/define_trace.h to include trace.h
 CFLAGS_regmap.o := -I$(src)
 
-obj-$(CONFIG_REGMAP) += regmap.o regcache.o
-obj-$(CONFIG_REGMAP) += regcache-rbtree.o regcache-flat.o regcache-maple.o
-obj-$(CONFIG_DEBUG_FS) += regmap-debugfs.o
+regmap-core-objs = regmap.o regcache.o regcache-rbtree.o regcache-flat.o regcache-maple.o
+ifdef CONFIG_DEBUG_FS
+regmap-core-objs += regmap-debugfs.o
+endif
+obj-$(CONFIG_REGMAP) += regmap-core.o
 obj-$(CONFIG_REGMAP_KUNIT) += regmap-kunit.o
 obj-$(CONFIG_REGMAP_AC97) += regmap-ac97.o
 obj-$(CONFIG_REGMAP_I2C) += regmap-i2c.o
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -9,6 +9,7 @@
 #include <linux/device.h>
 #include <linux/slab.h>
 #include <linux/export.h>
+#include <linux/module.h>
 #include <linux/mutex.h>
 #include <linux/err.h>
 #include <linux/property.h>
@@ -3433,3 +3434,5 @@ static int __init regmap_initcall(void)
 	return 0;
 }
 postcore_initcall(regmap_initcall);
+
+MODULE_LICENSE("GPL");
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -197,7 +197,7 @@ struct reg_sequence {
 	__ret ?: __tmp; \
 })
 
-#ifdef CONFIG_REGMAP
+#if IS_REACHABLE(CONFIG_REGMAP)
 
 enum regmap_endian {
 	/* Unspecified -> 0 -> Backwards compatible default */
