1. 17 Jul, 2019 1 commit
    • Linus Walleij's avatar
      spi: gpio: Add SPI_MASTER_GPIO_SS flag · 2922d1cc
      Linus Walleij authored
      The GPIO SPI master has some code in its local CS
      callback to set the initial sck GPIO value. This was
      lost in the commit converting it to use SPI core
      GPIO handling as this callback isn't called if the
      internal GPIO handling is active.
      
      Add the special SPI_MASTER_GPIO_SS to ascertain it
      gets called anyway so we get the initial SCK setting
      right. There is some platform provided GPIO handling
      there as well but this will be skipped as the cs_gpios
      will be NULL.
      
      My test targets seem not to care about the initial
      SCK value so I am uncertain if this is a regression,
      but to preserve the previous semantic we better do
      this.
      
      Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
      Fixes: 249e2632
      
       ("spi: gpio: Don't request CS GPIO in DT use-case")
      Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Link: https://lore.kernel.org/r/20190716204651.7743-1-linus.walleij@linaro.org
      
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      2922d1cc
  2. 30 May, 2019 1 commit
    • Thomas Gleixner's avatar
      treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 157 · c942fddf
      Thomas Gleixner authored
      Based on 3 normalized pattern(s):
      
        this program is free software you can redistribute it and or modify
        it under the terms of the gnu general public license as published by
        the free software foundation either version 2 of the license or at
        your option any later version this program is distributed in the
        hope that it will be useful but without any warranty without even
        the implied warranty of merchantability or fitness for a particular
        purpose see the gnu general public license for more details
      
        this program is free software you can redistribute it and or modify
        it under the terms of the gnu general public license as published by
        the free software foundation either version 2 of the license or at
        your option any later version [author] [kishon] [vijay] [abraham]
        [i] [kishon]@[ti] [com] this program is distributed in the hope that
        it will be useful but without any warranty without even the implied
        warranty of merchan...
      c942fddf
  3. 08 Apr, 2019 2 commits
  4. 05 Apr, 2019 3 commits
  5. 04 Apr, 2019 1 commit
  6. 03 Apr, 2019 5 commits
  7. 21 Feb, 2019 1 commit
  8. 12 Feb, 2019 1 commit
  9. 07 Nov, 2018 1 commit
  10. 10 Sep, 2018 1 commit
    • Linus Walleij's avatar
      spi: gpio: No MISO does not imply no RX · abf5feef
      Linus Walleij authored
      
      
      There is a logical problem in spi-gpio with host just
      assigning a MOSI line and no MISO: this is interpreted
      as the host cannot do RX and the host is flagged with
      SPI_MASTER_NO_RX.
      
      This is wrong: since GPIO lines can switch direction,
      in 3WIRE operation the host will simply reverse the
      direction of the GPIO line and start reading from it,
      there is even code for doing this in the driver, but
      it went unnoticed because it was tested by using a
      master with 4 wires but a device using just 3 wires.
      
      Remove the offending flag.
      
      Cc: Andrzej Hajda <a.hajda@samsung.com>
      Cc: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
      Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      abf5feef
  11. 06 Sep, 2018 1 commit
  12. 04 Sep, 2018 1 commit
  13. 01 Aug, 2018 2 commits
  14. 12 Jun, 2018 1 commit
    • Kees Cook's avatar
      treewide: devm_kzalloc() -> devm_kcalloc() · a86854d0
      Kees Cook authored
      
      
      The devm_kzalloc() function has a 2-factor argument form, devm_kcalloc().
      This patch replaces cases of:
      
              devm_kzalloc(handle, a * b, gfp)
      
      with:
              devm_kcalloc(handle, a * b, gfp)
      
      as well as handling cases of:
      
              devm_kzalloc(handle, a * b * c, gfp)
      
      with:
      
              devm_kzalloc(handle, array3_size(a, b, c), gfp)
      
      as it's slightly less ugly than:
      
              devm_kcalloc(handle, array_size(a, b), c, gfp)
      
      This does, however, attempt to ignore constant size factors like:
      
              devm_kzalloc(handle, 4 * 1024, gfp)
      
      though any constants defined via macros get caught up in the conversion.
      
      Any factors with a sizeof() of "unsigned char", "char", and "u8" were
      dropped, since they're redundant.
      
      Some manual whitespace fixes were needed in this patch, as Coccinelle
      really liked to write "=devm_kcalloc..." instead of "= devm_kcalloc...".
      
      The Coccinelle script used for this was:
      
      // Fix redundant parens around sizeof().
      @@
      expression HANDLE;
      type TYPE;
      expression THING, E;
      @@
      
      (
        devm_kzalloc(HANDLE,
      -	(sizeof(TYPE)) * E
      +	sizeof(TYPE) * E
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(sizeof(THING)) * E
      +	sizeof(THING) * E
        , ...)
      )
      
      // Drop single-byte sizes and redundant parens.
      @@
      expression HANDLE;
      expression COUNT;
      typedef u8;
      typedef __u8;
      @@
      
      (
        devm_kzalloc(HANDLE,
      -	sizeof(u8) * (COUNT)
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(__u8) * (COUNT)
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(char) * (COUNT)
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(unsigned char) * (COUNT)
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(u8) * COUNT
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(__u8) * COUNT
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(char) * COUNT
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(unsigned char) * COUNT
      +	COUNT
        , ...)
      )
      
      // 2-factor product with sizeof(type/expression) and identifier or constant.
      @@
      expression HANDLE;
      type TYPE;
      expression THING;
      identifier COUNT_ID;
      constant COUNT_CONST;
      @@
      
      (
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * (COUNT_ID)
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * COUNT_ID
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * COUNT_CONST
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * (COUNT_ID)
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * COUNT_ID
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(THING)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * COUNT_CONST
      +	COUNT_CONST, sizeof(THING)
        , ...)
      )
      
      // 2-factor product, only identifiers.
      @@
      expression HANDLE;
      identifier SIZE, COUNT;
      @@
      
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	SIZE * COUNT
      +	COUNT, SIZE
        , ...)
      
      // 3-factor product with 1 sizeof(type) or sizeof(expression), with
      // redundant parens removed.
      @@
      expression HANDLE;
      expression THING;
      identifier STRIDE, COUNT;
      type TYPE;
      @@
      
      (
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      )
      
      // 3-factor product with 2 sizeof(variable), with redundant parens removed.
      @@
      expression HANDLE;
      expression THING1, THING2;
      identifier COUNT;
      type TYPE1, TYPE2;
      @@
      
      (
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE1) * sizeof(TYPE2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      )
      
      // 3-factor product, only identifiers, with redundant parens removed.
      @@
      expression HANDLE;
      identifier STRIDE, SIZE, COUNT;
      @@
      
      (
        devm_kzalloc(HANDLE,
      -	(COUNT) * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	COUNT * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	COUNT * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(COUNT) * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	COUNT * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(COUNT) * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(COUNT) * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	COUNT * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      )
      
      // Any remaining multi-factor products, first at least 3-factor products,
      // when they're not all constants...
      @@
      expression HANDLE;
      expression E1, E2, E3;
      constant C1, C2, C3;
      @@
      
      (
        devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
      |
        devm_kzalloc(HANDLE,
      -	(E1) * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(E1) * (E2) * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(E1) * (E2) * (E3)
      +	array3_size(E1, E2, E3)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	E1 * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      )
      
      // And then all remaining 2 factors products when they're not all constants,
      // keeping sizeof() as the second factor argument.
      @@
      expression HANDLE;
      expression THING, E1, E2;
      type TYPE;
      constant C1, C2, C3;
      @@
      
      (
        devm_kzalloc(HANDLE, sizeof(THING) * C2, ...)
      |
        devm_kzalloc(HANDLE, sizeof(TYPE) * C2, ...)
      |
        devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
      |
        devm_kzalloc(HANDLE, C1 * C2, ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * (E2)
      +	E2, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * E2
      +	E2, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * (E2)
      +	E2, sizeof(THING)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * E2
      +	E2, sizeof(THING)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	(E1) * E2
      +	E1, E2
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	(E1) * (E2)
      +	E1, E2
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	E1 * E2
      +	E1, E2
        , ...)
      )
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      a86854d0
  15. 14 Feb, 2018 1 commit
    • Linus Walleij's avatar
      spi: spi-gpio: Rewrite to use GPIO descriptors · 9b00bc7b
      Linus Walleij authored
      
      
      This converts the bit-banged GPIO SPI driver to looking up and
      using GPIO descriptors to get a handle on GPIO lines for SCK,
      MOSI, MISO and all CS lines.
      
      All existing board files are converted in one go to keep it all
      consistent. With these conversions I rarely find any interrim
      steps that makes any sense.
      
      Device tree probing and GPIO handling should work like before
      also after this patch.
      
      For board files, we stop using controller data to pass the GPIO
      line for chip select, instead we pass this as a GPIO descriptor
      lookup like everything else.
      
      In some s3c24xx machines the names of the SPI devices were set to
      "spi-gpio" rather than "spi_gpio" which can never have worked, I
      fixed it working (I guess) as part of this patch set. Sometimes
      I wonder how this code got upstream in the first place, it
      obviously is not tested.
      
      mach-s3c64xx/mach-smartq.c has the same problem and additionally
      defines the *same* GPIO line for MOSI and MISO which is not going
      to be accepted by gpiolib. As the lines were number 1,2,2 I assumed
      it was a typo and use lines 1,2,3. A comment gives awat that line 0
      is chip select though no actual SPI device is provided for the LCD
      supposed to be on this bit-banged SPI bus. I left it intact instead
      of just deleting the bus though.
      
      Kill off board file code that try to initialize the SPI lines
      to the same values that they will later be set by the spi_gpio
      driver anyways. Given the huge number of weird things in these
      board files I do not think this code is very tested or put in
      with much afterthought anyways.
      
      In order to assert that we do not get performance regressions on
      this crucial bing-banged driver, a ran a script like this dumping the
      Ilitek ILI9322 regmap 10000 times (it has no caching obviously) on
      an otherwise idle system in two iterations before and after the
      patches:
      
       #!/bin/sh
       for run in `seq 10000`
       do
           cat /debug/regmap/spi0.0/registers > /dev/null
       done
      
      Before the patch:
      
      time test.sh
      real    3m 41.03s
      user    0m 29.41s
      sys     3m 7.22s
      
      time test.sh
      real    3m 44.24s
      user    0m 32.31s
      sys     3m 7.60s
      
      After the patch:
      
      time test.sh
      real    3m 41.32s
      user    0m 28.92s
      sys     3m 8.08s
      
      time test.sh
      real    3m 39.92s
      user    0m 30.20s
      sys     3m 5.56s
      
      So any performance differences seems to be in the error margin.
      Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Acked-by: default avatarOlof Johansson <olof@lixom.net>
      Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      9b00bc7b
  16. 05 Jan, 2015 1 commit
  17. 22 Dec, 2014 1 commit
  18. 08 Nov, 2014 1 commit
  19. 04 Nov, 2014 1 commit
  20. 20 Oct, 2014 1 commit
  21. 07 May, 2014 1 commit
  22. 29 Mar, 2014 1 commit
  23. 04 Feb, 2014 1 commit
  24. 03 Feb, 2014 1 commit
  25. 24 Nov, 2013 1 commit
  26. 16 Oct, 2013 1 commit
  27. 07 Oct, 2013 1 commit
    • Axel Lin's avatar
      spi: bitbang: Let spi_bitbang_start() take a reference to master · 702a4879
      Axel Lin authored
      
      
      Many drivers that use bitbang library have a leak on probe error paths.
      This is because once a spi_master_get() call succeeds, we need an additional
      spi_master_put() call to free the memory.
      
      Fix this issue by moving the code taking a reference to master to
      spi_bitbang_start(), so spi_bitbang_start() will take a reference to master on
      success. With this change, the caller is responsible for calling
      spi_bitbang_stop() to decrement the reference and spi_master_put() as
      counterpart of spi_alloc_master() to prevent a memory leak.
      
      So now we have below patten for drivers using bitbang library:
      
      probe:
      spi_alloc_master        -> Init reference count to 1
      spi_bitbang_start       -> Increment reference count
      remove:
      spi_bitbang_stop        -> Decrement reference count
      spi_master_put          -> Decrement reference count (reference count reaches 0)
      
      Fixup all users accordingly.
      Signed-off-by: default avatarAxel Lin <axel.lin@ingics.com>
      Suggested-by: default avatarUwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>
      Acked-by: default avatarUwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>
      Signed-off-by: default avatarMark Brown <broonie@linaro.org>
      702a4879
  28. 17 Sep, 2013 1 commit
    • Axel Lin's avatar
      spi: bitbang: Let spi_bitbang_start() take a reference to master · 94c69f76
      Axel Lin authored
      
      
      Many drivers that use bitbang library have a leak on probe error paths.
      This is because once a spi_master_get() call succeeds, we need an additional
      spi_master_put() call to free the memory.
      
      Fix this issue by moving the code taking a reference to master to
      spi_bitbang_start(), so spi_bitbang_start() will take a reference to master on
      success. With this change, the caller is responsible for calling
      spi_bitbang_stop() to decrement the reference and spi_master_put() as
      counterpart of spi_alloc_master() to prevent a memory leak.
      
      So now we have below patten for drivers using bitbang library:
      
      probe:
      spi_alloc_master        -> Init reference count to 1
      spi_bitbang_start       -> Increment reference count
      remove:
      spi_bitbang_stop        -> Decrement reference count
      spi_master_put          -> Decrement reference count (reference count reaches 0)
      
      Fixup all users accordingly.
      Signed-off-by: default avatarAxel Lin <axel.lin@ingics.com>
      Suggested-by: default avatarUwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>
      Acked-by: default avatarUwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>
      Signed-off-by: default avatarMark Brown <broonie@linaro.org>
      94c69f76
  29. 29 Aug, 2013 1 commit
  30. 29 May, 2013 1 commit
  31. 13 May, 2013 1 commit
  32. 10 Apr, 2013 1 commit