Fix sysfs bits
authorMiroslav Ondra <ondra@faster.cz>
Thu, 26 Sep 2019 15:34:05 +0000 (17:34 +0200)
committerMiroslav Ondra <ondra@faster.cz>
Thu, 26 Sep 2019 15:34:05 +0000 (17:34 +0200)
Change irq settings (egde/level) to solve Axon problem with 115200 on ttyNS0

modules/unipi/src/unipi_common.h
modules/unipi/src/unipi_gpio.c
modules/unipi/src/unipi_spi.c
modules/unipi/src/unipi_sysfs.c

index aa511bf267d278ee37dc0544e5e7dfc4d6029e54..72039afdd4d64d8ff5ba14d95f1b0ba50a74687b 100644 (file)
@@ -52,7 +52,7 @@
 #if NEURONSPI_SCHED_REQUIRED > 0
        #include <uapi/linux/sched/types.h>
 #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
index c91326699031883f5320907ce96ecb556410d4d0..3ab41cf16ccc0827fb07c87f3d9459d2c6f69493 100644 (file)
 
 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;
 }
 
index 9f9e7a604bd9d767780a4140a8417d0b9a11f1aa..ad1bdbfb9e5c28dbf41dbd511c8c5a7150715bd6 100644 (file)
@@ -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;
index 1b5ccbb6fdede9c433560afeb5089adae8885515..f34b26927224508105c26e95b4659affc6b580f6 100644 (file)
@@ -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: