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

From: Vadim Pasternak
Date: Thu Jan 11 2018 - 02:27:32 EST


It allows driver to run on x86 and ARM architecture based systems.
Also some unnecessary includes are removed.

Signed-off-by: Vadim Pasternak <vadimp@xxxxxxxxxxxx>
Acked-by: Andy Shevchenko <andy.shevchenko@xxxxxxxxx>
---
v7->v8
Fixes added by Vadim:
- Drop routines using of_update_property. It causes Kbuild error for
ia64 arch during on modpost, since of_update_property is not exported.
The intension of these routines was the dynamic enabling and disabling
of the device tree node, when relevant signal is received. Such node
has been supposed to set with the property disabled in DTS, and
changing property by using of_update_property just flips the device.
It was OK for arm and sparc, but not for ia64.
v6->v7
Fixes added by Vadim:
- Dont remove include <linux/io.h> in mlxreg-hotplug.c to avoid Kbuild
errors. Make this change in patch 3/3.
v5->v6:
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 | 70 +++++++++++++-----------------
drivers/platform/x86/mlx-platform.c | 16 +++----
include/linux/platform_data/mlxreg.h | 6 ++-
4 files changed, 44 insertions(+), 50 deletions(-)

diff --git a/drivers/platform/mellanox/Kconfig b/drivers/platform/mellanox/Kconfig
index d735292..0267e1d 100644
--- a/drivers/platform/mellanox/Kconfig
+++ b/drivers/platform/mellanox/Kconfig
@@ -5,7 +5,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..556e612 100644
--- a/drivers/platform/mellanox/mlxreg-hotplug.c
+++ b/drivers/platform/mellanox/mlxreg-hotplug.c
@@ -41,8 +41,6 @@
#include <linux/module.h>
#include <linux/platform_data/mlxreg.h>
#include <linux/platform_device.h>
-#include <linux/spinlock.h>
-#include <linux/wait.h>
#include <linux/workqueue.h>

/* Offset of event and mask registers from status register */
@@ -99,6 +97,35 @@ struct mlxreg_hotplug_priv_data {
u8 fan_cache;
};

+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, &data->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 ssize_t mlxreg_hotplug_attr_show(struct device *dev,
struct device_attribute *attr,
char *buf)
@@ -184,41 +211,6 @@ static int mlxreg_hotplug_attr_init(struct mlxreg_hotplug_priv_data *priv)
return 0;
}

-static int mlxreg_hotplug_device_create(struct device *dev,
- struct mlxreg_hotplug_device *item)
-{
- item->adapter = i2c_get_adapter(item->bus);
- if (!item->adapter) {
- dev_err(dev, "Failed to get adapter for bus %d\n",
- item->bus);
- return -EFAULT;
- }
-
- item->client = i2c_new_device(item->adapter, &item->brdinfo);
- if (!item->client) {
- dev_err(dev, "Failed to create client %s at bus %d at addr 0x%02x\n",
- item->brdinfo.type, item->bus, item->brdinfo.addr);
- i2c_put_adapter(item->adapter);
- item->adapter = NULL;
- return -EFAULT;
- }
-
- return 0;
-}
-
-static void mlxreg_hotplug_device_destroy(struct mlxreg_hotplug_device *item)
-{
- if (item->client) {
- i2c_unregister_device(item->client);
- item->client = NULL;
- }
-
- if (item->adapter) {
- i2c_put_adapter(item->adapter);
- item->adapter = NULL;
- }
-}
-
static inline void
mlxreg_hotplug_work_helper(struct device *dev,
struct mlxreg_hotplug_device *item, u8 is_inverse,
@@ -252,10 +244,10 @@ mlxreg_hotplug_work_helper(struct device *dev,
if (is_inverse)
mlxreg_hotplug_device_destroy(item + bit);
else
- mlxreg_hotplug_device_create(dev, item + bit);
+ mlxreg_hotplug_device_create(item + bit);
} else {
if (is_inverse)
- mlxreg_hotplug_device_create(dev, item + bit);
+ mlxreg_hotplug_device_create(item + bit);
else
mlxreg_hotplug_device_destroy(item + bit);
}
diff --git a/drivers/platform/x86/mlx-platform.c b/drivers/platform/x86/mlx-platform.c
index 0fbec1f..5601714 100644
--- a/drivers/platform/x86/mlx-platform.c
+++ b/drivers/platform/x86/mlx-platform.c
@@ -141,41 +141,41 @@ static struct i2c_mux_reg_platform_data mlxplat_mux_data[] = {
static struct mlxreg_hotplug_device mlxplat_mlxcpld_psu[] = {
{
.brdinfo = { I2C_BOARD_INFO("24c02", 0x51) },
- .bus = 10,
+ .nr = 10,
},
{
.brdinfo = { I2C_BOARD_INFO("24c02", 0x50) },
- .bus = 10,
+ .nr = 10,
},
};

static struct mlxreg_hotplug_device mlxplat_mlxcpld_pwr[] = {
{
.brdinfo = { I2C_BOARD_INFO("dps460", 0x59) },
- .bus = 10,
+ .nr = 10,
},
{
.brdinfo = { I2C_BOARD_INFO("dps460", 0x58) },
- .bus = 10,
+ .nr = 10,
},
};

static struct mlxreg_hotplug_device mlxplat_mlxcpld_fan[] = {
{
.brdinfo = { I2C_BOARD_INFO("24c32", 0x50) },
- .bus = 11,
+ .nr = 11,
},
{
.brdinfo = { I2C_BOARD_INFO("24c32", 0x50) },
- .bus = 12,
+ .nr = 12,
},
{
.brdinfo = { I2C_BOARD_INFO("24c32", 0x50) },
- .bus = 13,
+ .nr = 13,
},
{
.brdinfo = { I2C_BOARD_INFO("24c32", 0x50) },
- .bus = 14,
+ .nr = 14,
},
};

diff --git a/include/linux/platform_data/mlxreg.h b/include/linux/platform_data/mlxreg.h
index 8dcbb8e..5c98ad1 100644
--- a/include/linux/platform_data/mlxreg.h
+++ b/include/linux/platform_data/mlxreg.h
@@ -39,7 +39,8 @@
* @adapter: I2C device adapter;
* @client: I2C device client;
* @brdinfo: device board information;
- * @bus: I2C bus, where device is attached;
+ * @nr: I2C device adapter number, to which device is to be attached;
+ * @np - pointer to node platform associated with attribute;
*
* Structure represents I2C hotplug device static data (board topology) and
* dynamic data (related kernel objects handles).
@@ -48,7 +49,8 @@ struct mlxreg_hotplug_device {
struct i2c_adapter *adapter;
struct i2c_client *client;
struct i2c_board_info brdinfo;
- u16 bus;
+ int nr;
+ struct device_node *np;
};

/**
--
2.1.4