• Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. bazsi77
    3. Best
    B
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 6
    • Best 1
    • Controversial 0
    • Groups 0

    Best posts made by bazsi77

    • RE: sysfs issue, high numbered digital input port does not get updated (di_3_16)

      I don't get it, when issuing this command:

      # perf_4.18 trace  --no-syscalls -e regmap:* cat /sys/devices/platform/unipi_plc/io_group2/di_2_16/di_value
      0
           0.000 regmap:regmap_hw_read_start:spi0.2 reg=0 count=1
           0.215 regmap:regmap_hw_read_done:spi0.2 reg=0 count=1
           0.227 regmap:regmap_reg_read:spi0.2 reg=0 val=8000
      

      I can see that regmap_reg_read() returned 0x8000, e.g. the MSB of the 16 bit register set, at least when the input is on. When turning off the voltage, the same says:

      # perf_4.18 trace  --no-syscalls -e regmap:* cat /sys/devices/platform/unipi_plc/io_group2/di_2_16/di_value
      0
           0.000 regmap:regmap_hw_read_start:spi0.2 reg=0 count=1
           0.215 regmap:regmap_hw_read_done:spi0.2 reg=0 count=1
           0.226 regmap:regmap_reg_read:spi0.2 reg=0 val=0
      
      

      which means that the input was properly reported by the underlying hardware. The code that seemingly triggers this regmap_reg_read() is as follows:

      static ssize_t neuronspi_spi_gpio_di_show_value(struct device *dev, struct device_attribute *attr, char *buf)
      {
              # ... setup code deleted ...
                  
              int val;
      
              # ... setup code deleted ...
              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);
                      ret = scnprintf(buf, 255, "%d\n", val);
              }
              return ret;
      }
      

      I originally wanted to write that I can't see the issue, but I just realized:

      The remainder function is using modulo 15 instead of 16. The io_index is of course 15 for di_2_16, which will result in "0" to be used, thus di_2_16 would yield the input value of the first input, that is di_2_01. Let me check.

      Bingo, results with di_2_01 set:

      root@L203-sn190:/usr/src/unipi-1.32/unipi/src# perf_4.18 trace  --no-syscalls -e regmap:* cat /sys/devices/platform/unipi_plc/io_group2/di_2_16/di_value 
      1
           0.000 regmap:regmap_hw_read_start:spi0.2 reg=0 count=1
           0.199 regmap:regmap_hw_read_done:spi0.2 reg=0 count=1
           0.208 regmap:regmap_reg_read:spi0.2 reg=0 val=1
      
      posted in Neuron Series
      B
      bazsi77