From 673a40c0350c1700aeef9f5911a6e3ba6dadd112 Mon Sep 17 00:00:00 2001 From: Miroslav Ondra Date: Thu, 26 Sep 2019 17:34:05 +0200 Subject: [PATCH] Fix sysfs bits Change irq settings (egde/level) to solve Axon problem with 115200 on ttyNS0 --- modules/unipi/src/unipi_common.h | 2 +- modules/unipi/src/unipi_gpio.c | 8 +++--- modules/unipi/src/unipi_spi.c | 5 +++- modules/unipi/src/unipi_sysfs.c | 42 +++++++++++++++----------------- 4 files changed, 28 insertions(+), 29 deletions(-) diff --git a/modules/unipi/src/unipi_common.h b/modules/unipi/src/unipi_common.h index aa511bf..72039af 100644 --- a/modules/unipi/src/unipi_common.h +++ b/modules/unipi/src/unipi_common.h @@ -52,7 +52,7 @@ #if NEURONSPI_SCHED_REQUIRED > 0 #include #endif -#define NEURONSPI_MAJOR_VERSIONSTRING "Version 1.32:2019:09:19" +#define NEURONSPI_MAJOR_VERSIONSTRING "Version 1.33:2019:09:26" #define NEURONSPI_MAX_DEVS 3 #define NEURONSPI_MAX_UART 16 diff --git a/modules/unipi/src/unipi_gpio.c b/modules/unipi/src/unipi_gpio.c index c913266..3ab41cf 100644 --- a/modules/unipi/src/unipi_gpio.c +++ b/modules/unipi/src/unipi_gpio.c @@ -25,16 +25,14 @@ int neuronspi_spi_gpio_di_get(struct spi_device* spi_dev, u32 id) { - u8 *recv_buf; + unsigned int recv_buf; bool ret = 0; u32 offset = id / 16; struct neuronspi_driver_data *d_data = spi_get_drvdata(spi_dev); - recv_buf = kzalloc(4, GFP_ATOMIC); - regmap_read(d_data->reg_map, d_data->regstart_table->di_val_reg + offset, (void*)recv_buf); - if (*recv_buf & (0x1 << offset)) { + regmap_read(d_data->reg_map, d_data->regstart_table->di_val_reg + offset, &recv_buf); + if (recv_buf & (0x1 << (id % 16))) { ret = 1; } - kfree(recv_buf); return ret; } diff --git a/modules/unipi/src/unipi_spi.c b/modules/unipi/src/unipi_spi.c index 9f9e7a6..ad1bdbf 100644 --- a/modules/unipi/src/unipi_spi.c +++ b/modules/unipi/src/unipi_spi.c @@ -1371,7 +1371,10 @@ s32 neuronspi_spi_probe(struct spi_device *spi) kthread_init_work(&(n_spi->irq_work), neuronspi_irq_proc); // prepare work function for interrupt status checking if (!no_irq) { n_spi->no_irq = 0; - ret = devm_request_irq(&(spi->dev), spi->irq, neuronspi_spi_irq, 0x81, dev_name(&(spi->dev)), spi); + //ret = devm_request_irq(&(spi->dev), spi->irq, neuronspi_spi_irq, 0x81, dev_name(&(spi->dev)), spi); + //ret = devm_request_irq(&(spi->dev), spi->irq, neuronspi_spi_irq, IRQF_TRIGGER_HIGH, dev_name(&(spi->dev)), spi); + // load setting of EDGE/LEVEL from devicetree + ret = devm_request_irq(&(spi->dev), spi->irq, neuronspi_spi_irq, 0, dev_name(&(spi->dev)), spi); unipi_spi_trace(KERN_DEBUG "UNIPISPI: SPI IRQ %d registration: ret=%d\n", spi->irq, ret); no_irq = (ret !=0); ret = 0; diff --git a/modules/unipi/src/unipi_sysfs.c b/modules/unipi/src/unipi_sysfs.c index 1b5ccbb..f34b269 100644 --- a/modules/unipi/src/unipi_sysfs.c +++ b/modules/unipi/src/unipi_sysfs.c @@ -480,8 +480,7 @@ static ssize_t neuronspi_spi_gpio_di_show_value(struct device *dev, struct devic n_spi = spi_get_drvdata(n_di->spi); if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->di_count > n_di->io_index) { regmap_read(n_spi->reg_map, n_spi->regstart_table->di_val_reg + (n_di->io_index / 16), &val); - val &= 0x1 << (n_di->io_index % 15); - val = val >> (n_di->io_index % 15); + val = val & (0x1 << (n_di->io_index % 16)) ? 1:0; ret = scnprintf(buf, 255, "%d\n", val); } return ret; @@ -498,8 +497,7 @@ static ssize_t neuronspi_spi_gpio_do_show_value(struct device *dev, struct devic n_spi = spi_get_drvdata(n_do->spi); if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->do_count > n_do->io_index) { regmap_read(n_spi->reg_map, n_spi->regstart_table->do_val_reg + (n_do->io_index / 16), &val); - val &= 0x1 << (n_do->io_index % 15); - val = val >> (n_do->io_index % 15); + val = val & (0x1 << (n_do->io_index % 16)) ? 1:0; ret = scnprintf(buf, 255, "%d\n", val); } return ret; @@ -522,8 +520,8 @@ static ssize_t neuronspi_spi_gpio_do_store_value(struct device *dev, struct devi } if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->do_count > n_do->io_index) { regmap_read(n_spi->reg_map, n_spi->regstart_table->do_val_reg + (n_do->io_index / 16), &val); - val &= ~(0x1 << (n_do->io_index % 15)); - val |= inp << (n_do->io_index % 15); + val &= ~(0x1 << (n_do->io_index % 16)); + val |= inp << (n_do->io_index % 16); regmap_write(n_spi->reg_map, n_spi->regstart_table->do_val_reg + (n_do->io_index / 16), val); } err_end: @@ -541,8 +539,8 @@ static ssize_t neuronspi_spi_gpio_ro_show_value(struct device *dev, struct devic n_spi = spi_get_drvdata(n_ro->spi); if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->ro_count > n_ro->io_index) { regmap_read(n_spi->reg_map, n_spi->regstart_table->ro_val_reg + (n_ro->io_index / 16), &val); - val &= 0x1 << (n_ro->io_index % 15); - val = val >> (n_ro->io_index % 15); + val &= 0x1 << (n_ro->io_index % 16); + val = val >> (n_ro->io_index % 16); ret = scnprintf(buf, 255, "%d\n", val); } return ret; @@ -565,8 +563,8 @@ static ssize_t neuronspi_spi_gpio_ro_store_value(struct device *dev, struct devi } if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->ro_count > n_ro->io_index) { regmap_read(n_spi->reg_map, n_spi->regstart_table->ro_val_reg + (n_ro->io_index / 16), &val); - val &= ~(0x1 << (n_ro->io_index % 15)); - val |= inp << (n_ro->io_index % 15); + val &= ~(0x1 << (n_ro->io_index % 16)); + val |= inp << (n_ro->io_index % 16); regmap_write(n_spi->reg_map, n_spi->regstart_table->ro_val_reg + (n_ro->io_index / 16), val); } err_end: @@ -585,8 +583,8 @@ static ssize_t neuronspi_spi_gpio_show_ds_enable(struct device *dev, struct devi n_spi = spi_get_drvdata(n_di->spi); if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->ds_count) { regmap_read(n_spi->reg_map, n_spi->regstart_table->di_direct_reg + (n_di->io_index / 16), &val); - val &= 0x1 << (n_di->io_index % 15); - val = val >> (n_di->io_index % 15); + val &= 0x1 << (n_di->io_index % 16); + val = val >> (n_di->io_index % 16); ret = scnprintf(buf, 255, "%d\n", val); } return ret; @@ -603,8 +601,8 @@ static ssize_t neuronspi_spi_gpio_show_ds_toggle(struct device *dev, struct devi n_spi = spi_get_drvdata(n_di->spi); if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->ds_count) { regmap_read(n_spi->reg_map, n_spi->regstart_table->di_toggle_reg + (n_di->io_index / 16), &val); - val &= 0x1 << (n_di->io_index % 15); - val = val >> (n_di->io_index % 15); + val &= 0x1 << (n_di->io_index % 16); + val = val >> (n_di->io_index % 16); ret = scnprintf(buf, 255, "%d\n", val); } return ret; @@ -621,8 +619,8 @@ static ssize_t neuronspi_spi_gpio_show_ds_polarity(struct device *dev, struct de n_spi = spi_get_drvdata(n_di->spi); if (n_spi && n_spi->combination_id != -1 && n_spi->features && n_spi->features->ds_count) { regmap_read(n_spi->reg_map, n_spi->regstart_table->di_polar_reg + (n_di->io_index / 16), &val); - val &= 0x1 << (n_di->io_index % 15); - val = val >> (n_di->io_index % 15); + val &= 0x1 << (n_di->io_index % 16); + val = val >> (n_di->io_index % 16); ret = scnprintf(buf, 255, "%d\n", val); } return ret; @@ -645,8 +643,8 @@ static ssize_t neuronspi_spi_gpio_store_ds_enable(struct device *dev, struct dev } if (n_spi && n_spi->combination_id != -1 && n_spi->features && n_spi->features->ds_count) { regmap_read(n_spi->reg_map, n_spi->regstart_table->di_direct_reg + (n_di->io_index / 16), &val); - val &= ~(0x1 << (n_di->io_index % 15)); - val |= inp << (n_di->io_index % 15); + val &= ~(0x1 << (n_di->io_index % 16)); + val |= inp << (n_di->io_index % 16); regmap_write(n_spi->reg_map, n_spi->regstart_table->di_direct_reg + (n_di->io_index / 16), val); } err_end: @@ -670,8 +668,8 @@ static ssize_t neuronspi_spi_gpio_store_ds_toggle(struct device *dev, struct dev } if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->ds_count) { regmap_read(n_spi->reg_map, n_spi->regstart_table->di_toggle_reg + (n_di->io_index / 16), &val); - val &= ~(0x1 << (n_di->io_index % 15)); - val |= inp << (n_di->io_index % 15); + val &= ~(0x1 << (n_di->io_index % 16)); + val |= inp << (n_di->io_index % 16); regmap_write(n_spi->reg_map, n_spi->regstart_table->di_toggle_reg + (n_di->io_index / 16), val); } err_end: @@ -695,8 +693,8 @@ static ssize_t neuronspi_spi_gpio_store_ds_polarity(struct device *dev, struct d } if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->ds_count) { regmap_read(n_spi->reg_map, n_spi->regstart_table->di_polar_reg + (n_di->io_index / 16), &val); - val &= ~(0x1 << (n_di->io_index % 15)); - val |= inp << (n_di->io_index % 15); + val &= ~(0x1 << (n_di->io_index % 16)); + val |= inp << (n_di->io_index % 16); regmap_write(n_spi->reg_map, n_spi->regstart_table->di_polar_reg + (n_di->io_index / 16), val); } err_end: -- 2.34.1