From 10ec966f7ba7471a8af437c317cdcc5ef8865e8d Mon Sep 17 00:00:00 2001
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 18 Oct 2018 11:30:27 +0200
Subject: [PATCH] gemini: Break out USB to packages

This creates a new kernel package for the fotg210 host
controller and uses that with the gemini to shrink the
kernel. The SQ201 needs the USB2 PCI package as well.

The build system required me to make kernel_oldconfig
beofore it would build without errors so some minor
unrelated Kconfig entries are changed.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 package/kernel/linux/modules/usb.mk | 11 +++++++++++
 target/linux/gemini/Makefile        |  2 ++
 target/linux/gemini/config-4.14     | 10 +++-------
 target/linux/gemini/image/Makefile  |  2 +-
 4 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/package/kernel/linux/modules/usb.mk b/package/kernel/linux/modules/usb.mk
index 8a4915712b..61a876b4d9 100644
--- a/package/kernel/linux/modules/usb.mk
+++ b/package/kernel/linux/modules/usb.mk
@@ -318,6 +318,17 @@ define KernelPackage/usb-bcma
 endef
 $(eval $(call KernelPackage,usb-bcma))
 
+define KernelPackage/usb-fotg210
+  TITLE:=Support for FOTG210 USB host controllers
+  DEPENDS:=@USB_SUPPORT @TARGET_gemini
+  KCONFIG:=CONFIG_USB_FOTG210_HCD
+  FILES:= \
+	$(if $(CONFIG_USB_FOTG210_HCD),$(LINUX_DIR)/drivers/usb/host/fotg210-hcd.ko)
+  AUTOLOAD:=$(call AutoLoad,50,fotg210-hcd,1)
+  $(call AddDepends/usb)
+endef
+$(eval $(call KernelPackage,usb-fotg210))
+
 define KernelPackage/usb-ssb
   TITLE:=Support for SSB USB controllers
   DEPENDS:=@USB_SUPPORT @TARGET_brcm47xx
diff --git a/target/linux/gemini/Makefile b/target/linux/gemini/Makefile
index 4b46bc23a1..3204b3f5d8 100644
--- a/target/linux/gemini/Makefile
+++ b/target/linux/gemini/Makefile
@@ -24,6 +24,8 @@ KERNELNAME:=zImage dtbs
 include $(INCLUDE_DIR)/target.mk
 
 DEFAULT_PACKAGES += \
+	kmod-usb-core kmod-usb-fotg210 \
+	kmod-usb-ledtrig-usbport \
 	kmod-leds-gpio kmod-led-trig-heartbeat \
 	kmod-gpio-button-hotplug
 
diff --git a/target/linux/gemini/config-4.14 b/target/linux/gemini/config-4.14
index 95e6b0c2c6..8866a576be 100644
--- a/target/linux/gemini/config-4.14
+++ b/target/linux/gemini/config-4.14
@@ -51,13 +51,15 @@ CONFIG_BLK_SCSI_REQUEST=y
 CONFIG_BOUNCE=y
 # CONFIG_BPF_SYSCALL is not set
 # CONFIG_CACHE_L2X0 is not set
+CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE=y
+# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
 CONFIG_CLKDEV_LOOKUP=y
 CONFIG_CLKSRC_MMIO=y
 CONFIG_CLONE_BACKWARDS=y
 CONFIG_CMDLINE="console=ttyS0,19200n8"
+CONFIG_CMDLINE_FROM_BOOTLOADER=y
 CONFIG_COMMON_CLK=y
 CONFIG_COMMON_CLK_GEMINI=y
-CONFIG_COMPACTION=y
 CONFIG_COMPAT_BRK=y
 CONFIG_CONSOLE_TRANSLATIONS=y
 CONFIG_COREDUMP=y
@@ -235,7 +237,6 @@ CONFIG_I2C_BOARDINFO=y
 CONFIG_I2C_COMPAT=y
 CONFIG_I2C_GPIO=y
 CONFIG_I2C_HELPER_AUTO=y
-# CONFIG_INITRAMFS_FORCE is not set
 CONFIG_INITRAMFS_SOURCE=""
 CONFIG_INPUT=y
 CONFIG_IOMMU_HELPER=y
@@ -414,11 +415,6 @@ CONFIG_TMPFS_POSIX_ACL=y
 CONFIG_TREE_SRCU=y
 CONFIG_UNCOMPRESS_INCLUDE="debug/uncompress.h"
 CONFIG_UNINLINE_SPIN_UNLOCK=y
-CONFIG_USB=y
-CONFIG_USB_COMMON=y
-# CONFIG_USB_EHCI_HCD is not set
-CONFIG_USB_FOTG210_HCD=y
-CONFIG_USB_SUPPORT=y
 # CONFIG_USERIO is not set
 CONFIG_USER_NS=y
 CONFIG_USE_OF=y
diff --git a/target/linux/gemini/image/Makefile b/target/linux/gemini/image/Makefile
index a05b7111b5..9e7daea03a 100644
--- a/target/linux/gemini/image/Makefile
+++ b/target/linux/gemini/image/Makefile
@@ -137,7 +137,7 @@ define Device/sq201
 	DEVICE_TITLE := ITian Square One SQ201
 	IMAGES += sq201-image
 	IMAGE/sq201-image := sq201-images
-	DEVICE_PACKAGES := $(GEMINI_NAS_PACKAGES) rt61-pci
+	DEVICE_PACKAGES := $(GEMINI_NAS_PACKAGES) rt61-pci usb2-pci
 endef
 TARGET_DEVICES += sq201
 
-- 
2.30.2