From: Tom Knot Date: Fri, 18 May 2018 11:53:22 +0000 (+0200) Subject: Version 0.08 X-Git-Url: http://git.graph-it.com/?a=commitdiff_plain;h=0cd20be850b888b4f3d52b9e27c518dd9754d64a;p=graphit%2Funipi-kernel.git Version 0.08 - Changed reading frequency to be user-specifiable (1-1000 Hz) --- diff --git a/modules/unipi/src/unipi_common.h b/modules/unipi/src/unipi_common.h index feb5c67..52cfdcd 100644 --- a/modules/unipi/src/unipi_common.h +++ b/modules/unipi/src/unipi_common.h @@ -51,7 +51,7 @@ #if NEURONSPI_SCHED_REQUIRED > 0 #include #endif -#define NEURONSPI_MAJOR_VERSIONSTRING "Development Beta Version 0.07:30:04:2018" +#define NEURONSPI_MAJOR_VERSIONSTRING "Development Beta Version 0.08:18:05:2018" #define NEURONSPI_MAX_DEVS 3 #define NEURONSPI_MAX_UART 128 diff --git a/modules/unipi/src/unipi_platform.c b/modules/unipi/src/unipi_platform.c index c4ce390..b0c3813 100644 --- a/modules/unipi/src/unipi_platform.c +++ b/modules/unipi/src/unipi_platform.c @@ -18,6 +18,7 @@ #include "unipi_platform.h" #include "unipi_spi.h" #include "unipi_common.h" +#include "unipi_sysfs.h" /*************************** * Static Data Definitions * @@ -1485,9 +1486,18 @@ struct neuronspi_model_definition NEURONSPI_MODELTABLE[NEURONSPI_MODELTABLE_LEN] s32 neuronspi_regmap_invalidate(void *data) { int i; + u32 reading_freq; int freq_cnt = 0; while (!kthread_should_stop()) { - usleep_range(15000,25000); + if (unipi_use_custom_speed) { + mutex_lock(&unipi_inv_speed_mutex); + reading_freq = unipi_custom_speed_value; + mutex_unlock(&unipi_inv_speed_mutex); + // TODO: This could be moved to sysfs.c so it does not have to be evaluated so often + usleep_range((1000000 / (reading_freq * 4)) * 3, (1000000 / (reading_freq * 4)) * 5); + } else { + usleep_range(15000,25000); + } if (freq_cnt == 450001) freq_cnt = 0; for (i = 0; i < NEURONSPI_MAX_DEVS; i++) { if (neuronspi_s_dev[i] != NULL) { diff --git a/modules/unipi/src/unipi_spi.c b/modules/unipi/src/unipi_spi.c index 4a2ce4e..6bdb005 100644 --- a/modules/unipi/src/unipi_spi.c +++ b/modules/unipi/src/unipi_spi.c @@ -61,6 +61,7 @@ struct neuronspi_char_driver neuronspi_cdrv = }; struct mutex neuronspi_master_mutex; +struct mutex unipi_inv_speed_mutex; struct spinlock* neuronspi_ldisc_spinlock; struct spinlock* neuronspi_spi_w_spinlock; u8 neuronspi_spi_w_flag = 1; @@ -1536,6 +1537,7 @@ static s32 __init neuronspi_init(void) neuronspi_spi_w_spinlock = kzalloc(sizeof(struct spinlock), GFP_KERNEL); spin_lock_init(neuronspi_spi_w_spinlock); mutex_init(&neuronspi_master_mutex); + mutex_init(&unipi_inv_speed_mutex); memset(&neuronspi_s_dev, 0, sizeof(neuronspi_s_dev)); ret = spi_register_driver(&neuronspi_spi_driver); if (ret < 0) { diff --git a/modules/unipi/src/unipi_spi.h b/modules/unipi/src/unipi_spi.h index 4aa4bb8..dbf209b 100644 --- a/modules/unipi/src/unipi_spi.h +++ b/modules/unipi/src/unipi_spi.h @@ -195,6 +195,8 @@ int neuronspi_spi_gpio_di_get(struct spi_device* spi_dev, u32 id); extern struct spi_driver neuronspi_spi_driver; extern struct file_operations file_ops; +extern struct mutex unipi_inv_speed_mutex; + static const struct regmap_bus neuronspi_regmap_bus = { .fast_io = 0, diff --git a/modules/unipi/src/unipi_sysfs.c b/modules/unipi/src/unipi_sysfs.c index de883e0..3374d15 100644 --- a/modules/unipi/src/unipi_sysfs.c +++ b/modules/unipi/src/unipi_sysfs.c @@ -17,6 +17,14 @@ ************/ #include "unipi_sysfs.h" +#include "unipi_spi.h" + +/********************* + * Data Declarations * + *********************/ + +int unipi_use_custom_speed = 0; +u32 unipi_custom_speed_value = NEURONSPI_DEFAULT_SYSFS_SPEED; /************************ * Static Functions * @@ -31,6 +39,36 @@ static ssize_t neuronspi_show_model(struct device *dev, struct device_attribute return ret; } +static ssize_t neuronspi_show_sysfs_speed(struct device *dev, struct device_attribute *attr, char *buf) +{ + ssize_t ret = 0; + mutex_lock(&unipi_inv_speed_mutex); + ret = scnprintf(buf, 255, "%d Hz\n", unipi_custom_speed_value); + mutex_unlock(&unipi_inv_speed_mutex); + return ret; +} + +static ssize_t neuronspi_store_sysfs_speed(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) +{ + ssize_t err = 0; + unsigned int val = 0; + err = kstrtouint(buf, 0, &val); + if (err < 0) goto err_end; + if (val == NEURONSPI_DEFAULT_SYSFS_SPEED) { + unipi_use_custom_speed = 0; + mutex_lock(&unipi_inv_speed_mutex); + unipi_custom_speed_value = 50; + mutex_unlock(&unipi_inv_speed_mutex); + } else if (val > 0) { + unipi_use_custom_speed = 1; + mutex_lock(&unipi_inv_speed_mutex); + unipi_custom_speed_value = val > 1000 ? 1000 : val; + mutex_unlock(&unipi_inv_speed_mutex); + } +err_end: + return count; +} + static ssize_t neuronspi_show_driver_version(struct device *dev, struct device_attribute *attr, char *buf) { ssize_t ret = 0; @@ -797,7 +835,9 @@ static ssize_t neuronspi_spi_gpio_show_di_count(struct device *dev, struct devic n_di = platform_get_drvdata(plat); n_spi = spi_get_drvdata(n_di->spi); if (n_spi->features && n_spi->features->di_count > 0 && n_spi->di_driver) { + spin_lock(&n_spi->sysfs_regmap_lock); ret = scnprintf(buf, 255, "%d\n", n_spi->di_driver[n_di->di_index]->gpio_c.ngpio); + spin_unlock(&n_spi->sysfs_regmap_lock); } return ret; } @@ -939,6 +979,7 @@ err_end: **********************************/ static DEVICE_ATTR(model_name, 0440, neuronspi_show_model, NULL); +static DEVICE_ATTR(sys_reading_freq, 0660, neuronspi_show_sysfs_speed, neuronspi_store_sysfs_speed); static DEVICE_ATTR(sys_eeprom_name, 0440, neuronspi_show_eeprom, NULL); static DEVICE_ATTR(driver_version, 0440, neuronspi_show_driver_version, NULL); static DEVICE_ATTR(register_read, 0660, neuronspi_show_regmap, neuronspi_store_regmap); @@ -980,6 +1021,7 @@ static DEVICE_ATTR(mode_ao_type_b, 0660, neuronspi_iio_show_secondary_ao_mode, n static struct attribute *neuron_plc_attrs[] = { &dev_attr_model_name.attr, + &dev_attr_sysfs_reading_freq.attr, &dev_attr_sys_eeprom_name.attr, &dev_attr_driver_version.attr, NULL, diff --git a/modules/unipi/src/unipi_sysfs.h b/modules/unipi/src/unipi_sysfs.h index bd55896..560b3a8 100644 --- a/modules/unipi/src/unipi_sysfs.h +++ b/modules/unipi/src/unipi_sysfs.h @@ -22,6 +22,11 @@ #include "unipi_common.h" #include "unipi_platform.h" +#define NEURONSPI_DEFAULT_SYSFS_SPEED 50 + +extern int unipi_use_custom_speed; +extern u32 unipi_custom_speed_value; + extern const struct attribute_group neuron_stm_ai_group; extern const struct attribute_group neuron_stm_ao_group; extern const struct attribute_group neuron_sec_ai_group;