From f18fbc09223234947b22434b5fa7fd684d17f448 Mon Sep 17 00:00:00 2001 From: John Klug Date: Thu, 17 Feb 2022 18:23:05 -0600 Subject: Unload the driver if platform_driver register fails, add README to explain the history of MTS-IO --- README | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 2 +- io-module/mts-io.c | 14 ++++++----- io-module/version.h | 2 +- 4 files changed, 77 insertions(+), 8 deletions(-) diff --git a/README b/README index d4a3df6..980ea75 100644 --- a/README +++ b/README @@ -15,3 +15,70 @@ the on-board EE-PROM. dev_dbg can be turned on when loading the mts-io driver. See debug/README and debug/etc/modprobe.d/mts-io.conf + +HISTORY: +Before the 4.9 kernel, mLinux used a patch +of the GPIO library to add pull up and pull +down capability to the GPIO flags. + +This patch did not easily fit with +newer kernels. So instead, the pull +up and pull down code was moved todata +device tree and AT91Pincontrol +(for Atmel processors) +from the mts-io driver. + +When the mts-io module was loaded, the +device tree was scanned, and the +pinctrl elements in device tree +associated with the mts-io driver +were loaded. + +Before the 4.9 version of the mts-io +driver, on initial load, the probe +function was executed. The probe +function in the device tree model +of the kernel causes a search +of the device tree and when +an element is found with the appropriate +compatible property, that part of the device tree +is loaded. This caused the attached +pinctrl sections to be read and the pins +configured. + +Because the kernel doc suggests adding +a number at the end of a node name, mts-io-0 +was chosen. + +Because the mts-io driver had always allocated +its own platform, it already had a +platform called mts-io. Because of this, we +did a platform_driver_register, followed +immediately by a platform_driver_unregister. +This allowed us to set up the pins using +device tree and allowed us to keep all +the old code that created and used the +platform driver with a minimum of changes. +The device tree used mts-io-0 for the +mts-io driver node which became +/sys/devices/platform/mts-io-0. The +mts-io driver continues to use +/sys/devices/platform/mts-io. + +Now at the 4.9 mts-io version level, +an attempt is made to move towards using +the gpio connection-id's from the +newer gpiod library. These connection-ids +are referred to as "names" in device tree +documentation. It is no longer possible +to free the platform loaded by +platform_driver_register, because +we need to use these device tree +entries later in the driver. + +GPIO pins are then be attached through the GPIO +descriptor found by making a call to +kernel functions like devm_gpiod_get_optional(), +which has a connection-ID as its second +parameter. + diff --git a/configure.ac b/configure.ac index 470aeac..d65d2a5 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([mts-io], [4.9.0]) +AC_INIT([mts-io], [4.9.1]) 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 db736f9..d65c7ea 100644 --- a/io-module/mts-io.c +++ b/io-module/mts-io.c @@ -1347,12 +1347,7 @@ static int __init mts_io_init(void) log_info("init: " DRIVER_VERSION); /* We do a platform_driver_register to do a probe - * of device tree and set the pinctrl. We then - * unregister to remove - * the probe function. If we don't remove the - * probe function, we will do a 2nd probe in - * platform_device_add, which will result in a - * stack trace in the log. */ + * of device tree and set the pinctrl/gpio settings. */ ret = platform_driver_register(&mts_io_driver); if (ret) { printk(KERN_ERR "mts-io: probe failed: %d\n", ret); @@ -1360,6 +1355,13 @@ static int __init mts_io_init(void) return ret; } + /* Without a platform device our EEPROM load will + * not work, and we cannot continue. */ + if (mts_io_platform_device == NULL) { + pr_err("mts-io: probe failed, possible bad device tree\n"); + return -ENODEV; + } + /* request_firmware() requires a device, so call after device allocated */ ret = mts_id_eeprom_load(); diff --git a/io-module/version.h b/io-module/version.h index a97e7df..b72c4b0 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.0" +#define DRIVER_VERSION "v4.9.1" #define DRIVER_AUTHOR "Multitech Systems" #define DRIVER_DESC "MTS-IO Controller" #define DRIVER_NAME "mts-io" -- cgit v1.2.3