<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>7267</bug_id>
          
          <creation_ts>2015-01-29 23:35:16 +0000</creation_ts>
          <short_desc>unable to switch SPI SS to active-high in a board file</short_desc>
          <delta_ts>2016-05-19 22:24:57 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>7</classification_id>
          <classification>Build System, Metadata &amp; Runtime</classification>
          <product>BSPs</product>
          <component>bsps-oe-core</component>
          <version>1.7</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>2.2</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Kevin Shelton">kmshelton</reporter>
          <assigned_to name="California Sullivan">california.l.sullivan</assigned_to>
          <cc>dvhart</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>Don&apos;t know</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>48413</commentid>
    <comment_count>0</comment_count>
    <who name="Kevin Shelton">kmshelton</who>
    <bug_when>2015-01-29 23:35:16 +0000</bug_when>
    <thetext>End goal is to have a board file that inverts the SPI SS signal.

Building off of the low-speed-spidev.c template, we have found that having 
.mode = SPI_MODE_3 | SPI_CS_HIGH
in the spi_board_info struct does not exercise drivers/spi/spi-pxa2xx.c&apos;s gpio_cs_inverted code.  setup_cs gets called, but setup_cs returns before it can set
gpio_cs_inverted because chip_info is NULL

We added the following to our board file:
#include &lt;linux/spi/pxa2xx_spi.h&gt;

static struct pxa2xx_spi_chip mbm = {
  .gpio_cs = 220
};

as well as
  .controller_data = &amp;mbm
to the spi_board_info struct

And the gpio_cs_inverted code now gets exercised, but fails to create a device because it attempts to put gpio 220 (in our 3.17 environment, pin 5 is linux gpio 220) into gpio mode (but it is necessarily set as SPI mode in the fw settings).

test environment:
3.17 yocto kernel
rev 76 uefi
debian userspace
&quot;LPSS &amp; SCC Devices Mode&quot; BIOS option is set to ACPI</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>48560</commentid>
    <comment_count>1</comment_count>
    <who name="Kevin Shelton">kmshelton</who>
    <bug_when>2015-02-04 19:38:23 +0000</bug_when>
    <thetext>For spi-pxa2xx.c&apos;s gpio_request(chip_info-&gt;gpio_cs, &quot;SPI_CS&quot;) call in setup_cs to succeed it looks like the mux state of pin 5 (GPIO220 in my environment) will have to change.  How do you change the mux state of a pin (there is an empty page about it on the wiki http://elinux.org/Minnowboard:MaxLPSSSetup)?  Using the option in the BIOS to disable SPI will change the mux state, but of course the other SPI lines will be hosed and the master won&apos;t be initialized.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>48618</commentid>
    <comment_count>2</comment_count>
    <who name="Kevin Shelton">kmshelton</who>
    <bug_when>2015-02-06 21:48:35 +0000</bug_when>
    <thetext>I see that drivers/pinctrl/pinctrl-baytrail.c doesn&apos;t have any functions to modify mux state consistent with Mathias Nyman&apos;s comment here: http://lwn.net/Articles/552203/ &quot;This driver does not touch the pin muxing and expect firmare to set pin muxing and pullup/down properties properly.&quot; (I think that is in reference to code that became pinctrl-baytrail.c).

I suspect the pxa2xx can do active-high CS with the mux state at 1, so maybe the checking for mux state 1 in the byt_gpio_request function in pinctrl-baytrail.c should have an exception for the SPI CS pin?  Otherwise this will require a FW cahnge, correct?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>48619</commentid>
    <comment_count>3</comment_count>
    <who name="Kevin Shelton">kmshelton</who>
    <bug_when>2015-02-06 22:59:43 +0000</bug_when>
    <thetext>I was able to validate my SPI device that needs active-high, by inserting a call to writel(0, reg) in drivers/pinctrl/pinctrl-baytrail.c&apos;s
byt_gpio_request

What is a clean way to support active-high SPI SS on physical pin 5?  Let me know the best approach and I will try my hand at sending a patch.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>48620</commentid>
    <comment_count>4</comment_count>
    <who name="Darren Hart">dvhart</who>
    <bug_when>2015-02-06 23:08:20 +0000</bug_when>
    <thetext>(In reply to comment #3)
&gt; I was able to validate my SPI device that needs active-high, by inserting a
&gt; call to writel(0, reg) in drivers/pinctrl/pinctrl-baytrail.c&apos;s
&gt; byt_gpio_request
&gt; 
&gt; What is a clean way to support active-high SPI SS on physical pin 5?  Let me
&gt; know the best approach and I will try my hand at sending a patch.

Thank you for the updates Kevin. I&apos;ve asked Mathias to take a look at this bug and comment.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>50757</commentid>
    <comment_count>5</comment_count>
    <who name="Darren Hart">dvhart</who>
    <bug_when>2015-05-04 16:22:19 +0000</bug_when>
    <thetext>Moving to 1.9 as we didn&apos;t get to this. I&apos;ll follow up with Matthias again.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>50797</commentid>
    <comment_count>6</comment_count>
    <who name="Darren Hart">dvhart</who>
    <bug_when>2015-05-05 16:40:09 +0000</bug_when>
    <thetext>Kevin, does this patch address the issue for you (from Mika W, untested):

diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c
index e3223ac75a7c..9729a3ac1407 100644
--- a/drivers/spi/spi-pxa2xx.c
+++ b/drivers/spi/spi-pxa2xx.c
@@ -241,8 +241,12 @@ detection_done:
static void lpss_ssp_cs_control(struct driver_data *drv_data, bool enable)
{
+	const struct spi_device *spi = drv_data-&gt;cur_msg-&gt;spi;
	u32 value;
+	if (spi-&gt;mode &amp; SPI_CS_HIGH)
+		enable = !enable;
+
	value = __lpss_ssp_read_priv(drv_data, SPI_CS_CONTROL);
	if (enable)
		value &amp;= ~SPI_CS_CONTROL_CS_HIGH;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>50799</commentid>
    <comment_count>7</comment_count>
    <who name="Kevin Shelton">kmshelton</who>
    <bug_when>2015-05-05 16:59:28 +0000</bug_when>
    <thetext>Thanks!  Will need a few days to get set back up to test this on hw.  Will update when I have results.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>51432</commentid>
    <comment_count>8</comment_count>
    <who name="Kevin Shelton">kmshelton</who>
    <bug_when>2015-06-02 19:34:03 +0000</bug_when>
    <thetext>won&apos;t have access to hw to test this until 6/17, so should have an update around then</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>52768</commentid>
    <comment_count>9</comment_count>
    <who name="Kevin Shelton">kmshelton</who>
    <bug_when>2015-08-03 07:02:06 +0000</bug_when>
    <thetext>Alrighty, have hw set back up.

Just after the call to spi_new_device, I get:
[  151.646913] spi spi0.0: failed to request chip select GPIO220
[  151.646923] pxa2xx-spi 80860F0E:00: can&apos;t setup spi0.0, status -517

test environment:
clean 4.1 yocto kernel with change to spi-pxa2xx.c applied
rev 76 uefi
debian 8.1 userspace
&quot;LPSS &amp; SCC Devices Mode&quot; BIOS option is set to ACPI

I will test whether my new setup is valid by applying the writel(0, reg) hack to a 3.17 yocto kernel.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>52769</commentid>
    <comment_count>10</comment_count>
    <who name="Kevin Shelton">kmshelton</who>
    <bug_when>2015-08-03 07:36:35 +0000</bug_when>
    <thetext>I see the pin enumeration changed, so I updated from 220 to 476 and things are looking good now (IIUC, the below warning is now expected).  I confirmed I was able to send a message to my SPI device.

[  223.346990] ------------[ cut here ]------------
[  223.347002] WARNING: CPU: 0 PID: 1940 at drivers/pinctrl/intel/pinctrl-baytrail.c:216 byt_gpio_request+0x91/0xe0()
[  223.347005] Modules linked in: [snip](O+) dw_dmac dw_dmac_core i2c_designware_platform i2c_i801 i2c_designware_core spi_pxa2xx_platform
[  223.347025] CPU: 0 PID: 1940 Comm: insmod Tainted: G        W  O    4.1.2+ #5
[  223.347029] Hardware name: Circuitco MinnowBoard MAX B3 PLATFORM/MinnowBoard MAX, BIOS MNW2MAX1.X64.0076.R01.1412081258 12/08/2014
[  223.347033]  ffffffff81bdd760 ffff88006f0f3ae8 ffffffff818eae47 0000000000000007
[  223.347041]  0000000000000000 ffff88006f0f3b28 ffffffff810521c5 ffff88006f0f3b30
[  223.347048]  ffffc9000034a110 ffff88007aa69828 ffff88007aa69908 0000000000000042
[  223.347055] Call Trace:
[  223.347067]  [&lt;ffffffff818eae47&gt;] dump_stack+0x45/0x57
[  223.347075]  [&lt;ffffffff810521c5&gt;] warn_slowpath_common+0x85/0xc0
[  223.347081]  [&lt;ffffffff810522a5&gt;] warn_slowpath_null+0x15/0x20
[  223.347087]  [&lt;ffffffff81339f41&gt;] byt_gpio_request+0x91/0xe0
[  223.347094]  [&lt;ffffffff8133ae22&gt;] __gpiod_request+0x82/0x110
[  223.347101]  [&lt;ffffffff8133d2eb&gt;] gpiod_request+0x4b/0x80
[  223.347107]  [&lt;ffffffff8133da3e&gt;] gpio_request+0x2e/0x40
[  223.347116]  [&lt;ffffffffa0000ef8&gt;] setup+0x358/0x480 [spi_pxa2xx_platform]
[  223.347124]  [&lt;ffffffff815450f3&gt;] spi_setup+0xb3/0x160
[  223.347131]  [&lt;ffffffff81545286&gt;] spi_add_device+0xe6/0x1e0
[  223.347136]  [&lt;ffffffffa0054000&gt;] ? 0xffffffffa0054000
[  223.347143]  [&lt;ffffffff81546feb&gt;] spi_new_device+0x9b/0xf0
[  223.347150]  [&lt;ffffffffa00540cc&gt;] low_speed_spidev_module_init+0xcc/0x13c [nh_display]
[  223.347157]  [&lt;ffffffff810002c4&gt;] do_one_initcall+0x84/0x1b0
[  223.347163]  [&lt;ffffffff818f0489&gt;] ? _cond_resched+0x19/0x20
[  223.347171]  [&lt;ffffffff81164840&gt;] ? kmem_cache_alloc_trace+0x30/0x130
[  223.347179]  [&lt;ffffffff818e949d&gt;] do_init_module+0x5c/0x1bf
[  223.347186]  [&lt;ffffffff810c3d0e&gt;] load_module+0x1cde/0x2000
[  223.347192]  [&lt;ffffffff810c05d0&gt;] ? m_show+0x1a0/0x1a0
[  223.347199]  [&lt;ffffffff810c41c6&gt;] SyS_finit_module+0x76/0x80
[  223.347207]  [&lt;ffffffff818f3d57&gt;] system_call_fastpath+0x12/0x6a
[  223.347212] ---[ end trace 41fc9c2c493de6f3 ]---
[  223.347215] in the baytrail if block
[  223.347225] byt_gpio INT33FC:00: pin 66 forcibly re-configured as GPIO
[  223.349972] low-speed-spidev: dev=ffff880037b9a400
[  223.349980] low-speed-spidev: SPI mode=7
[  223.349984] low-speed-spidev: spidev registered</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>62357</commentid>
    <comment_count>11</comment_count>
    <who name="California Sullivan">california.l.sullivan</who>
    <bug_when>2016-05-19 22:24:57 +0000</bug_when>
    <thetext>User claims its fixed.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>