CINXE.COM

LKML: Vitaly Wool: Re: [PATCH] SPI: add support for PNX/SPI controller

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>LKML: Vitaly Wool: Re: [PATCH] SPI: add support for PNX/SPI controller</title><link href="/css/message.css" rel="stylesheet" type="text/css" /><link href="/css/wrap.css" rel="alternate stylesheet" type="text/css" title="wrap" /><link href="/css/nowrap.css" rel="stylesheet" type="text/css" title="nowrap" /><link href="/favicon.ico" rel="shortcut icon" /><script src="/js/simple-calendar.js" type="text/javascript"></script><script src="/js/styleswitcher.js" type="text/javascript"></script><link rel="alternate" type="application/rss+xml" title="lkml.org : last 100 messages" href="/rss.php" /><link rel="alternate" type="application/rss+xml" title="lkml.org : last messages by Vitaly Wool" href="/groupie.php?aid=29396" /><!--Matomo--><script> var _paq = window._paq = window._paq || []; /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ _paq.push(["setDoNotTrack", true]); _paq.push(["disableCookies"]); _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); (function() { var u="//m.lkml.org/"; _paq.push(['setTrackerUrl', u+'matomo.php']); _paq.push(['setSiteId', '1']); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); })(); </script><!--End Matomo Code--></head><body onload="es.jasper.simpleCalendar.init();" itemscope="itemscope" itemtype="http://schema.org/BlogPosting"><table border="0" cellpadding="0" cellspacing="0"><tr><td width="180" align="center"><a href="/"><img style="border:0;width:135px;height:32px" src="/images/toprowlk.gif" alt="lkml.org" /></a></td><td width="32">聽</td><td class="nb"><div><a class="nb" href="/lkml"> [lkml]</a> 聽 <a class="nb" href="/lkml/2005"> [2005]</a> 聽 <a class="nb" href="/lkml/2005/12"> [Dec]</a> 聽 <a class="nb" href="/lkml/2005/12/27"> [27]</a> 聽 <a class="nb" href="/lkml/last100"> [last100]</a> 聽 <a href="/rss.php"><img src="/images/rss-or.gif" border="0" alt="RSS Feed" /></a></div><div>Views: <a href="#" class="nowrap" onclick="setActiveStyleSheet('wrap');return false;">[wrap]</a><a href="#" class="wrap" onclick="setActiveStyleSheet('nowrap');return false;">[no wrap]</a> 聽 <a class="nb" href="/lkml/mheaders/2005/12/27/122" onclick="this.href='/lkml/headers'+'/2005/12/27/122';">[headers]</a>聽 <a href="/lkml/bounce/2005/12/27/122">[forward]</a>聽 </div></td><td width="32">聽</td></tr><tr><td valign="top"><div class="es-jasper-simpleCalendar" baseurl="/lkml/"></div><div class="threadlist">Messages in this thread</div><ul class="threadlist"><li class="root"><a href="/lkml/2005/12/23/57">First message in thread</a></li><li><a href="/lkml/2005/12/23/57">Vitaly Wool</a><ul><li><a href="/lkml/2005/12/27/106">David Brownell</a><ul><li class="origin"><a href="">Vitaly Wool</a></li></ul></li></ul></li></ul></td><td width="32" rowspan="2" class="c" valign="top"><img src="/images/icornerl.gif" width="32" height="32" alt="/" /></td><td class="c" rowspan="2" valign="top" style="padding-top: 1em"><table><tr><td><table><tr><td class="lp">Date</td><td class="rp" itemprop="datePublished">Tue, 27 Dec 2005 23:21:11 +0300</td></tr><tr><td class="lp">From</td><td class="rp" itemprop="author">Vitaly Wool &lt;&gt;</td></tr><tr><td class="lp">Subject</td><td class="rp" itemprop="name">Re: [PATCH] SPI: add support for PNX/SPI controller</td></tr></table></td><td></td></tr></table><pre itemprop="articleBody">David Brownell wrote:<br /><br />&gt;On Friday 23 December 2005 6:15 am, Vitaly Wool wrote:<br />&gt; <br />&gt;<br />&gt;&gt;(PNX0106 and PNX4008, namely) based on spi_bitbang library <br />&gt;&gt; <br />&gt;&gt;<br />&gt;<br />&gt;Good! Does need work yet though...<br />&gt; <br />&gt;<br />Yup...<br /><br />&gt;&gt; # Add new SPI master controllers in alphabetical order above this line<br />&gt;&gt; <br />&gt;&gt;<br />&gt;<br />&gt;Note how it says "above", yet you've added yours ... below! :(<br />&gt;<br />&gt;<br />&gt; <br />&gt;<br />&gt;&gt; #<br />&gt;&gt; <br />&gt;&gt;+config SPI_PNX<br />&gt;&gt;+ tristate "PNX SPI bus support"<br />&gt;&gt;+ depends on ARCH_PNX4008 &amp;&amp; SPI_BITBANG<br />&gt;&gt; <br />&gt;&gt;<br />&gt;<br />&gt;... also added the eeprom so it shows in the list of controller drivers!!<br />&gt;<br />&gt; <br />&gt;<br />Oh sorry. Stupid me... Not that it matters really since this driver's <br />not yet mature enough anyway.<br /><br />&gt; <br />&gt;<br />&gt;&gt;+config SPI_EEPROM<br />&gt;&gt;+ tristate "SPI EEPROM"<br />&gt;&gt;+ depends on SPI<br />&gt;&gt;+<br />&gt;&gt; <br />&gt;&gt; <br />&gt;&gt;<br />&gt;<br />&gt; <br />&gt;<br />&gt;&gt;+#define lock_device( dev ) /* down( &amp;dev-&gt;sem ); */<br />&gt;&gt;+#define unlock_device( dev ) /* up( &amp;dev-&gt;sem ); */<br />&gt;&gt; <br />&gt;&gt;<br />&gt;<br />&gt;Not clear why you'd want such stuff ... better to just remove<br />&gt;NOPs like that.<br />&gt;<br />&gt; <br />&gt;<br />They caused problems on 2.6.10... I might have uncommented that but I <br />saw no reason. This driver is now is in FYI state :)<br /><br />&gt;<br />&gt; <br />&gt;<br />&gt;&gt;+static void<br />&gt;&gt;+spi_pnx_chipselect(struct spi_device *spi, int is_on)<br />&gt;&gt;+{<br />&gt;&gt;+ spipnx_arch_cs(spi, is_on);<br />&gt;&gt;+}<br />&gt;&gt; <br />&gt;&gt;<br />&gt;<br />&gt;I see that "arch" hook is actually just toggling a DMA line.<br />&gt;Did you notice how Stephen's PXA code handled that? The<br />&gt;"controller_data" was a board-specific GPIO toggle function,<br />&gt;as provided in the board_info that implicitly defines the<br />&gt;relevant device.<br />&gt;<br />&gt;Plus, activating the chip does more than just toggling some<br />&gt;arch-specific GPIO. It has to set the right SPI mode, of<br />&gt;which CPOL must be set _before_ chipselect goes active.<br />&gt;And it has to set the transfer clock, for chips like yours<br />&gt;which are multiplexing devices using software.<br />&gt; <br />&gt;<br />Yep, the current way of doing stuff is a sort of abuse to the driver's <br />model.<br />It's just "put #ifdefs out of the C dode" thing. We're gonna rewrite <br />that using controller_data but in our case that's gonna be a structure <br />with several functions and data needed. We have more arch-specific stuff <br />to care about than Stephen's PXA code, so we just didn't bother at the <br />moment; but anyway you're right.<br /><br />&gt;<br />&gt; <br />&gt;<br />&gt;&gt;+static int spi_pnx_xfer(struct spi_device *spidev, struct spi_transfer *t)<br />&gt;&gt;+{<br />&gt;&gt; <br />&gt;&gt;<br />&gt;...<br />&gt; <br />&gt;<br />&gt;&gt;+ if (spidev-&gt;max_speed_hz)<br />&gt;&gt;+ spi_pnx_set_clock_rate(spidev-&gt;max_speed_hz / 1000, regs);<br />&gt;&gt; <br />&gt;&gt;<br />&gt;<br />&gt;Just do it the one time, when activating that chip's selection.<br />&gt; <br />&gt;<br />Nm really in our case, we have to reset the chip at each direction <br />change due to hardware bug.<br /><br />&gt;<br />&gt;...<br />&gt; <br />&gt;<br />&gt;&gt;+ if (t-&gt;tx_buf) {<br />&gt;&gt;+ dat = (u8 *)t-&gt;tx_buf;<br />&gt;&gt;+ regs-&gt;con |= SPIPNX_CON_RXTX;<br />&gt;&gt;+ regs-&gt;ier |= SPIPNX_IER_EOT;<br />&gt;&gt;+ regs-&gt;con &amp;= ~SPIPNX_CON_SHIFT_OFF;<br />&gt;&gt;+ regs-&gt;frm = len;<br />&gt;&gt;+<br />&gt;&gt;+ if (dd-&gt;dma_mode &amp;&amp; len &gt;= FIFO_CHUNK_SIZE) {<br />&gt;&gt;+ void *dmasafe = NULL;<br />&gt;&gt;+ if (t-&gt;tx_dma)<br />&gt;&gt; <br />&gt;&gt;<br />&gt;<br />&gt;That's not actually correct, since zero might be a legal DMA address.<br />&gt;Unfortunately we have no DMA_ADDR_INVALID to test against, so this<br />&gt;will need to suffice for now. (And I updated the spi_bitbang code<br />&gt;to ensure that address _is_ zeroed when the message didn't set up<br />&gt;the DMA addresses already, matching the default behavior.)<br />&gt; <br />&gt;<br />Hmm, DMA_ADDR_INVALID... (u_long)-1 ?<br /><br />&gt;<br />&gt; <br />&gt;<br />&gt;&gt;+ params.dma_buffer = t-&gt;tx_dma;<br />&gt;&gt;+ else {<br />&gt;&gt;+ dmasafe = kmalloc(len, SLAB_KERNEL);<br />&gt;&gt;+ if (!dmasafe) {<br />&gt;&gt;+ len = 0;<br />&gt;&gt;+ goto out;<br />&gt;&gt;+ }<br />&gt;&gt;+ params.dma_buffer = dma_map_single(dev-&gt;parent, dmasafe, len, DMA_TO_DEVICE);<br />&gt;&gt;+ memcpy(dmasafe, dat, len);<br />&gt;&gt; <br />&gt;&gt;<br />&gt;<br />&gt;You do know this is incorrect don't you? Call dma_map_single()<br />&gt;if you need a dma address. The caller already guaranteed that the<br />&gt;input address is dma-safe.<br />&gt; <br />&gt;<br />Well it didn't :) See eeprom.c.<br />It's not the way to go however, but it's nice to have ability to add DMA <br />safety in some controller drivers working with weird device drivers :/<br /><br />&gt;...<br />&gt; <br />&gt;<br />&gt;&gt;+ }<br />&gt;&gt;+<br />&gt;&gt;+ if (t-&gt;rx_buf) {<br />&gt;&gt; <br />&gt;&gt;<br />&gt;...<br />&gt; <br />&gt;<br />&gt;&gt;+ }<br />&gt;&gt; <br />&gt;&gt;<br />&gt;<br />&gt;That RX bit sure looks wrong to me ... as if, given an spi_transfer<br />&gt;with both TX and RX buffers, it will execute them in sequence (half<br />&gt;duplex) rather than concurrently (full duplex). SPI is full duplex,<br />&gt;and this code should be too. If it can't implement that, then it<br />&gt;should be reporting an error if both rx and tx are requested, rather<br />&gt;than doing the wrong thing.<br />&gt; <br />&gt;<br />This particular controller is full duplex but it has some hw problems <br />working in FD mode.<br />This is a workaround for FD which looks ok to me.<br /><br />&gt; <br />&gt;<br />&gt;&gt;+ if (rc &lt; 0)<br />&gt;&gt;+ goto out;<br />&gt;&gt;+<br />&gt;&gt;+ data = kzalloc(sizeof *data, GFP_KERNEL);<br />&gt;&gt; <br />&gt;&gt;<br />&gt;<br />&gt;You don't need that kzalloc, it was already done for you by virtue of<br />&gt;your telling spi_alloc_master() to do so. But then you saved that<br />&gt;memory into "pnx" not "data" (bug! wrong size!). What you should be<br />&gt;doing is nesting your bitbang structure inside the "data" thing.<br />&gt;<br />&gt; <br />&gt;<br />Agreed.<br /><br />&gt;Likewise, mark this __exit. And I suspect you're using some kernel<br />&gt;older than 2.6.15-rc6 ... ;)<br />&gt; <br />&gt;<br />Definitely, it was quickly ported from 2.6.10.<br /><br />&gt;I notice your header file was mostly inline function declarations,<br />&gt;even for basic parts like clocking and DMA. That's best as part<br />&gt;of the driver itself, if it's not following some framework like<br />&gt;the &lt;asm/hardware/clock.h&gt; API on ARM.<br />&gt; <br />&gt;<br />Well, these all platform-specific functions are gonna be in <br />controller_data some day... hopefully soon.<br /><br />Vitaly<br /><br />-<br />To unsubscribe from this list: send the line "unsubscribe linux-kernel" in<br />the body of a message to majordomo&#64;vger.kernel.org<br />More majordomo info at <a href="http://vger.kernel.org/majordomo-info.html">http://vger.kernel.org/majordomo-info.html</a><br />Please read the FAQ at <a href="http://www.tux.org/lkml/">http://www.tux.org/lkml/</a><br /><br /></pre></td><td width="32" rowspan="2" class="c" valign="top"><img src="/images/icornerr.gif" width="32" height="32" alt="\" /></td></tr><tr><td align="right" valign="bottom"> 聽 </td></tr><tr><td align="right" valign="bottom">聽</td><td class="c" valign="bottom" style="padding-bottom: 0px"><img src="/images/bcornerl.gif" width="32" height="32" alt="\" /></td><td class="c">聽</td><td class="c" valign="bottom" style="padding-bottom: 0px"><img src="/images/bcornerr.gif" width="32" height="32" alt="/" /></td></tr><tr><td align="right" valign="top" colspan="2"> 聽 </td><td class="lm">Last update: 2005-12-27 21:25 聽聽 [from the cache]<br />漏2003-2020 <a href="http://blog.jasper.es/"><span itemprop="editor">Jasper Spaans</span></a>|hosted at <a href="https://www.digitalocean.com/?refcode=9a8e99d24cf9">Digital Ocean</a> and my Meterkast|<a href="http://blog.jasper.es/categories.html#lkml-ref">Read the blog</a></td><td>聽</td></tr></table><script language="javascript" src="/js/styleswitcher.js" type="text/javascript"></script></body></html>

Pages: 1 2 3 4 5 6 7 8 9 10