From: Valentine Fatiev <valentinef@nvidia.com>
Subject: [PATCH] BACKPORT: drivers/base/auxiliary.c

Change-Id: Idaa52f73da647ffc22b4d26316be52a644ef08a1
---
 drivers/base/auxiliary.c | 57 ++++++++++++++++++++++++++++++++++------
 1 file changed, 49 insertions(+), 8 deletions(-)

--- a/drivers/base/auxiliary.c
+++ b/drivers/base/auxiliary.c
@@ -19,7 +19,7 @@
 #include <linux/pm_runtime.h>
 #include <linux/string.h>
 #include <linux/auxiliary_bus.h>
-#include "base.h"
+#include <linux/acpi.h>
 
 /**
  * DOC: PURPOSE
@@ -189,7 +189,7 @@ static int auxiliary_match(struct device
 	return !!auxiliary_match_id(auxdrv->id_table, auxdev);
 }
 
-static int auxiliary_uevent(const struct device *dev, struct kobj_uevent_env *env)
+static int auxiliary_uevent(struct device *dev, struct kobj_uevent_env *env)
 {
 	const char *name, *p;
 
@@ -212,6 +212,14 @@ static int auxiliary_bus_probe(struct de
 	int ret;
 
 	ret = dev_pm_domain_attach(dev, true);
+
+#ifdef HAVE_BASECODE_EXTRAS
+	/* In case of old kernels 4.17 and below do nothing in case of
+	 * failure of ENODEV */
+	if (ret == -ENODEV)
+		ret = 0;
+#endif
+
 	if (ret) {
 		dev_warn(dev, "Failed to attach to PM Domain : %d\n", ret);
 		return ret;
@@ -220,11 +228,14 @@ static int auxiliary_bus_probe(struct de
 	ret = auxdrv->probe(auxdev, auxiliary_match_id(auxdrv->id_table, auxdev));
 	if (ret)
 		dev_pm_domain_detach(dev, true);
-
 	return ret;
 }
 
+#ifdef HAVE_BUS_TYPE_REMOVE_RETURN_VOID
 static void auxiliary_bus_remove(struct device *dev)
+#else
+static int auxiliary_bus_remove(struct device *dev)
+#endif
 {
 	struct auxiliary_driver *auxdrv = to_auxiliary_drv(dev->driver);
 	struct auxiliary_device *auxdev = to_auxiliary_dev(dev);
@@ -232,6 +243,10 @@ static void auxiliary_bus_remove(struct
 	if (auxdrv->remove)
 		auxdrv->remove(auxdev);
 	dev_pm_domain_detach(dev, true);
+
+#ifndef HAVE_BUS_TYPE_REMOVE_RETURN_VOID
+	return 0;
+#endif
 }
 
 static void auxiliary_bus_shutdown(struct device *dev)
@@ -248,7 +263,11 @@ static void auxiliary_bus_shutdown(struc
 		auxdrv->shutdown(auxdev);
 }
 
+#ifdef HAVE_CONST_BUS_TYPE_FOR_STRUCT_DEVICE
 static const struct bus_type auxiliary_bus_type = {
+#else
+static struct bus_type auxiliary_bus_type = {
+#endif
 	.name = "auxiliary",
 	.probe = auxiliary_bus_probe,
 	.remove = auxiliary_bus_remove,
@@ -353,9 +372,17 @@ EXPORT_SYMBOL_GPL(__auxiliary_device_add
  * if it does.  If the callback returns non-zero, this function will
  * return to the caller and not iterate over any more devices.
  */
-struct auxiliary_device *auxiliary_find_device(struct device *start,
-					       const void *data,
-					       int (*match)(struct device *dev, const void *data))
+#if defined(HAVE_LINUX_DEVICE_BUS_H) || defined(HAVE_BUS_FIND_DEVICE_GET_CONST)
+struct auxiliary_device *
+auxiliary_find_device(struct device *start,
+		      const void *data,
+		      int (*match)(struct device *dev, const void *data))
+#else
+struct auxiliary_device *
+auxiliary_find_device(struct device *start,
+		      void *data,
+		      int (*match)(struct device *dev, void *data))
+#endif /* HAVE_BUS_FIND_DEVICE_GET_CONST || HAVE_LINUX_DEVICE_BUS_H */
 {
 	struct device *dev;
 
@@ -417,7 +444,21 @@ void auxiliary_driver_unregister(struct
 }
 EXPORT_SYMBOL_GPL(auxiliary_driver_unregister);
 
-void __init auxiliary_bus_init(void)
+static int __init auxiliary_bus_init(void)
 {
-	WARN_ON(bus_register(&auxiliary_bus_type));
+	return bus_register(&auxiliary_bus_type);
 }
+
+static void __exit auxiliary_bus_exit(void)
+{
+	bus_unregister(&auxiliary_bus_type);
+}
+
+module_init(auxiliary_bus_init);
+module_exit(auxiliary_bus_exit);
+
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("Auxiliary Bus");
+MODULE_INFO(supported, "external");
+MODULE_AUTHOR("David Ertman <david.m.ertman@intel.com>");
+MODULE_AUTHOR("Kiran Patil <kiran.patil@intel.com>");
