From 5e681baa71e96d1ae1de317c4ee74dfdc9b72b1c Mon Sep 17 00:00:00 2001 From: Vyacheslav Pedash Date: Tue, 22 Mar 2022 12:18:25 -0500 Subject: Create symlink in /sys/devices/platform to mts-io node in case it is placed in other directory in sysfs --- configure.ac | 2 +- io-module/mts-io.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ io-module/version.h | 2 +- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index d65d2a5..010f2ac 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([mts-io], [4.9.1]) +AC_INIT([mts-io], [4.9.3]) AC_CONFIG_SRCDIR([util/mts_util_lora2_reset.c]) AM_INIT_AUTOMAKE AM_CONFIG_HEADER([config.h]) diff --git a/io-module/mts-io.c b/io-module/mts-io.c index ca7fdcb..a6e5204 100644 --- a/io-module/mts-io.c +++ b/io-module/mts-io.c @@ -93,16 +93,63 @@ EXPORT_SYMBOL(mts_get_hw_version); struct platform_device *mts_io_platform_device; EXPORT_SYMBOL(mts_io_platform_device); +#ifdef PLATFORM_BUS_SYMLINK +struct mts_io_drvdata { + bool f_platform_bus_symlink; +}; +#endif // PLATFORM_BUS_SYMLINK static int mts_io_probe(struct platform_device *pdev) { +#ifdef PLATFORM_BUS_SYMLINK + struct device *dev = &pdev->dev; + const char *symlink_name = kobject_name(&pdev->dev.kobj); + struct mts_io_drvdata *mts_io_dd; + int res; +#endif // PLATFORM_BUS_SYMLINK + mts_io_platform_device = pdev; dev_dbg(&pdev->dev,"%s: ENTER\n",__func__); + +#ifdef PLATFORM_BUS_SYMLINK + mts_io_dd = devm_kzalloc(dev, sizeof(*mts_io_dd), GFP_KERNEL); + if (!mts_io_dd) { + return -ENOMEM; + }; + mts_io_dd->f_platform_bus_symlink = false; + platform_set_drvdata(pdev, mts_io_dd); + + if (!dev->parent) { + log_warning("Parent device is not found"); + } else if (dev->parent == &platform_bus) { + log_info("Parent device is platform_bus. No need to create symlink"); + goto exit; + } + log_info("Creating symlink on platform_bus to %s", symlink_name); + + res = sysfs_create_link(&platform_bus.kobj, &dev->kobj, symlink_name); + if (!res) { + mts_io_dd->f_platform_bus_symlink = true; + } else { + log_warning("Failed to create symlink"); + } + +exit: +#endif // PLATFORM_BUS_SYMLINK + return 0; } static int mts_io_remove(struct platform_device *pdev) { +#ifdef PLATFORM_BUS_SYMLINK + struct mts_io_drvdata *mts_io_dd = platform_get_drvdata(pdev); + const char *symlink_name = kobject_name(&pdev->dev.kobj); + if (mts_io_dd && mts_io_dd->f_platform_bus_symlink) { + log_info("Removing %s symlink from platform_bus", symlink_name); + sysfs_remove_link(&platform_bus.kobj, symlink_name); + } +#endif // PLATFORM_BUS_SYMLINK return 0; } diff --git a/io-module/version.h b/io-module/version.h index e61e6ed..5b6304b 100644 --- a/io-module/version.h +++ b/io-module/version.h @@ -1,7 +1,7 @@ #ifndef __VERSION_H #define __VERSION_H -#define DRIVER_VERSION "v4.9.2" +#define DRIVER_VERSION "v4.9.3" #define DRIVER_AUTHOR "Multitech Systems" #define DRIVER_DESC "MTS-IO Controller" #define DRIVER_NAME "mts-io" -- cgit v1.2.3