[patch v5 2/3] platform/mellanox: mlxreg-hotplug: allow driver for ARM architecture

2017-10-18 Thread Vadim Pasternak
It allows driver to run on x86 and ARM architecture based systems.
And allows to specify hotplug device parameters through the device
table tree files.
Also some unnecessary includes are removed.

Signed-off-by: Vadim Pasternak 
Acked-by: Andy Shevchenko 
---
v4->v5:
 Comments pointed out by Andy:
 - remove unnessecary logic in Kconfig;
 - remove !COMPILE_TEST in mlxreg-hotplug;
---
 drivers/platform/mellanox/Kconfig  |   2 +-
 drivers/platform/mellanox/mlxreg-hotplug.c | 164 +
 drivers/platform/x86/mlx-platform.c|  16 +--
 include/linux/platform_data/mlxreg.h   |   6 +-
 4 files changed, 132 insertions(+), 56 deletions(-)

diff --git a/drivers/platform/mellanox/Kconfig 
b/drivers/platform/mellanox/Kconfig
index 89ceeb6..57c543e 100644
--- a/drivers/platform/mellanox/Kconfig
+++ b/drivers/platform/mellanox/Kconfig
@@ -4,7 +4,7 @@
 
 menuconfig MELLANOX_PLATFORM
bool "Platform support for Mellanox hardware"
-   depends on X86 || COMPILE_TEST
+   depends on X86 || ARM || COMPILE_TEST
---help---
  Say Y here to get to see options for platform support for
  Mellanox systems. This option alone does not add any kernel code.
diff --git a/drivers/platform/mellanox/mlxreg-hotplug.c 
b/drivers/platform/mellanox/mlxreg-hotplug.c
index 2866c76..53228b2 100644
--- a/drivers/platform/mellanox/mlxreg-hotplug.c
+++ b/drivers/platform/mellanox/mlxreg-hotplug.c
@@ -37,12 +37,9 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
-#include 
-#include 
 #include 
 
 /* Offset of event and mask registers from status register */
@@ -50,6 +47,10 @@
 #define MLXREG_HOTPLUG_MASK_OFF2
 #define MLXREG_HOTPLUG_AGGR_MASK_OFF   1
 
+#define MLXREG_HOTPLUG_PROP_OKAY   "okay"
+#define MLXREG_HOTPLUG_PROP_DISABLED   "disabled"
+#define MLXREG_HOTPLUG_PROP_STATUS "status"
+
 #define MLXREG_HOTPLUG_ATTRS_NUM   8
 
 /**
@@ -99,6 +100,114 @@ struct mlxreg_hotplug_priv_data {
u8 fan_cache;
 };
 
+#if defined(CONFIG_OF_DYNAMIC)
+/**
+ * struct mlxreg_hotplug_device_en - Open Firmware property for enabling device
+ *
+ * @name - property name;
+ * @value - property value string;
+ * @length - length of proprty value string;
+ *
+ * The structure is used for the devices, which require some dynamic
+ * selection operation allowing access to them.
+ */
+static struct property mlxreg_hotplug_device_en = {
+   .name = MLXREG_HOTPLUG_PROP_STATUS,
+   .value = MLXREG_HOTPLUG_PROP_OKAY,
+   .length = sizeof(MLXREG_HOTPLUG_PROP_OKAY),
+};
+
+/**
+ * struct mlxreg_hotplug_device_dis - Open Firmware property for disabling
+ * device
+ *
+ * @name - property name;
+ * @value - property value string;
+ * @length - length of proprty value string;
+ *
+ * The structure is used for the devices, which require some dynamic
+ * selection operation disallowing access to them.
+ */
+static struct property mlxreg_hotplug_device_dis = {
+   .name = MLXREG_HOTPLUG_PROP_STATUS,
+   .value = MLXREG_HOTPLUG_PROP_DISABLED,
+   .length = sizeof(MLXREG_HOTPLUG_PROP_DISABLED),
+};
+
+static int mlxreg_hotplug_of_device_create(struct mlxreg_hotplug_device *data)
+{
+   return of_update_property(data->np, _hotplug_device_en);
+}
+
+static void
+mlxreg_hotplug_of_device_destroy(struct mlxreg_hotplug_device *data)
+{
+   of_update_property(data->np, _hotplug_device_dis);
+   of_node_clear_flag(data->np, OF_POPULATED);
+}
+#else
+static int mlxreg_hotplug_of_device_create(struct mlxreg_hotplug_device *data)
+{
+   return 0;
+}
+
+static void
+mlxreg_hotplug_of_device_destroy(struct mlxreg_hotplug_device *data)
+{
+}
+#endif
+
+static int mlxreg_hotplug_device_create(struct mlxreg_hotplug_device *data)
+{
+   data->adapter = i2c_get_adapter(data->nr);
+   if (!data->adapter)
+   return -EFAULT;
+
+   data->client = i2c_new_device(data->adapter, >brdinfo);
+   if (!data->client) {
+   i2c_put_adapter(data->adapter);
+   data->adapter = NULL;
+   return -EFAULT;
+   }
+
+   return 0;
+}
+
+static void mlxreg_hotplug_device_destroy(struct mlxreg_hotplug_device *data)
+{
+   if (data->client) {
+   i2c_unregister_device(data->client);
+   data->client = NULL;
+   }
+
+   if (data->adapter) {
+   i2c_put_adapter(data->adapter);
+   data->adapter = NULL;
+   }
+}
+
+static int mlxreg_hotplug_dev_enable(struct mlxreg_hotplug_device *data)
+{
+   int err;
+
+   /* Enable and create device. */
+   if (data->np)
+   err = mlxreg_hotplug_of_device_create(data);
+   else
+   err = mlxreg_hotplug_device_create(data);
+
+   return err;
+}
+
+static void mlxreg_hotplug_dev_disable(struct mlxreg_hotplug_device *data)
+{
+   /* Disable and unregister platform device. */
+   if 

[patch v5 2/3] platform/mellanox: mlxreg-hotplug: allow driver for ARM architecture

2017-10-18 Thread Vadim Pasternak
It allows driver to run on x86 and ARM architecture based systems.
And allows to specify hotplug device parameters through the device
table tree files.
Also some unnecessary includes are removed.

Signed-off-by: Vadim Pasternak 
Acked-by: Andy Shevchenko 
---
v4->v5:
 Comments pointed out by Andy:
 - remove unnessecary logic in Kconfig;
 - remove !COMPILE_TEST in mlxreg-hotplug;
---
 drivers/platform/mellanox/Kconfig  |   2 +-
 drivers/platform/mellanox/mlxreg-hotplug.c | 164 +
 drivers/platform/x86/mlx-platform.c|  16 +--
 include/linux/platform_data/mlxreg.h   |   6 +-
 4 files changed, 132 insertions(+), 56 deletions(-)

diff --git a/drivers/platform/mellanox/Kconfig 
b/drivers/platform/mellanox/Kconfig
index 89ceeb6..57c543e 100644
--- a/drivers/platform/mellanox/Kconfig
+++ b/drivers/platform/mellanox/Kconfig
@@ -4,7 +4,7 @@
 
 menuconfig MELLANOX_PLATFORM
bool "Platform support for Mellanox hardware"
-   depends on X86 || COMPILE_TEST
+   depends on X86 || ARM || COMPILE_TEST
---help---
  Say Y here to get to see options for platform support for
  Mellanox systems. This option alone does not add any kernel code.
diff --git a/drivers/platform/mellanox/mlxreg-hotplug.c 
b/drivers/platform/mellanox/mlxreg-hotplug.c
index 2866c76..53228b2 100644
--- a/drivers/platform/mellanox/mlxreg-hotplug.c
+++ b/drivers/platform/mellanox/mlxreg-hotplug.c
@@ -37,12 +37,9 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
-#include 
-#include 
 #include 
 
 /* Offset of event and mask registers from status register */
@@ -50,6 +47,10 @@
 #define MLXREG_HOTPLUG_MASK_OFF2
 #define MLXREG_HOTPLUG_AGGR_MASK_OFF   1
 
+#define MLXREG_HOTPLUG_PROP_OKAY   "okay"
+#define MLXREG_HOTPLUG_PROP_DISABLED   "disabled"
+#define MLXREG_HOTPLUG_PROP_STATUS "status"
+
 #define MLXREG_HOTPLUG_ATTRS_NUM   8
 
 /**
@@ -99,6 +100,114 @@ struct mlxreg_hotplug_priv_data {
u8 fan_cache;
 };
 
+#if defined(CONFIG_OF_DYNAMIC)
+/**
+ * struct mlxreg_hotplug_device_en - Open Firmware property for enabling device
+ *
+ * @name - property name;
+ * @value - property value string;
+ * @length - length of proprty value string;
+ *
+ * The structure is used for the devices, which require some dynamic
+ * selection operation allowing access to them.
+ */
+static struct property mlxreg_hotplug_device_en = {
+   .name = MLXREG_HOTPLUG_PROP_STATUS,
+   .value = MLXREG_HOTPLUG_PROP_OKAY,
+   .length = sizeof(MLXREG_HOTPLUG_PROP_OKAY),
+};
+
+/**
+ * struct mlxreg_hotplug_device_dis - Open Firmware property for disabling
+ * device
+ *
+ * @name - property name;
+ * @value - property value string;
+ * @length - length of proprty value string;
+ *
+ * The structure is used for the devices, which require some dynamic
+ * selection operation disallowing access to them.
+ */
+static struct property mlxreg_hotplug_device_dis = {
+   .name = MLXREG_HOTPLUG_PROP_STATUS,
+   .value = MLXREG_HOTPLUG_PROP_DISABLED,
+   .length = sizeof(MLXREG_HOTPLUG_PROP_DISABLED),
+};
+
+static int mlxreg_hotplug_of_device_create(struct mlxreg_hotplug_device *data)
+{
+   return of_update_property(data->np, _hotplug_device_en);
+}
+
+static void
+mlxreg_hotplug_of_device_destroy(struct mlxreg_hotplug_device *data)
+{
+   of_update_property(data->np, _hotplug_device_dis);
+   of_node_clear_flag(data->np, OF_POPULATED);
+}
+#else
+static int mlxreg_hotplug_of_device_create(struct mlxreg_hotplug_device *data)
+{
+   return 0;
+}
+
+static void
+mlxreg_hotplug_of_device_destroy(struct mlxreg_hotplug_device *data)
+{
+}
+#endif
+
+static int mlxreg_hotplug_device_create(struct mlxreg_hotplug_device *data)
+{
+   data->adapter = i2c_get_adapter(data->nr);
+   if (!data->adapter)
+   return -EFAULT;
+
+   data->client = i2c_new_device(data->adapter, >brdinfo);
+   if (!data->client) {
+   i2c_put_adapter(data->adapter);
+   data->adapter = NULL;
+   return -EFAULT;
+   }
+
+   return 0;
+}
+
+static void mlxreg_hotplug_device_destroy(struct mlxreg_hotplug_device *data)
+{
+   if (data->client) {
+   i2c_unregister_device(data->client);
+   data->client = NULL;
+   }
+
+   if (data->adapter) {
+   i2c_put_adapter(data->adapter);
+   data->adapter = NULL;
+   }
+}
+
+static int mlxreg_hotplug_dev_enable(struct mlxreg_hotplug_device *data)
+{
+   int err;
+
+   /* Enable and create device. */
+   if (data->np)
+   err = mlxreg_hotplug_of_device_create(data);
+   else
+   err = mlxreg_hotplug_device_create(data);
+
+   return err;
+}
+
+static void mlxreg_hotplug_dev_disable(struct mlxreg_hotplug_device *data)
+{
+   /* Disable and unregister platform device. */
+   if (data->np)
+