19904f22a7202c6b54e96b0cc9870817013c350a1David Brownell/* 2ca632f556697d45d67ed5cada7cedf3ddfe0db4bGrant Likely * polling/bitbanging SPI master controller driver utilities 39904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * 49904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * This program is free software; you can redistribute it and/or modify 59904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * it under the terms of the GNU General Public License as published by 69904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * the Free Software Foundation; either version 2 of the License, or 79904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * (at your option) any later version. 89904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * 99904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * This program is distributed in the hope that it will be useful, 109904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * but WITHOUT ANY WARRANTY; without even the implied warranty of 119904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 129904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * GNU General Public License for more details. 139904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * 149904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * You should have received a copy of the GNU General Public License 159904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * along with this program; if not, write to the Free Software 169904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 179904f22a7202c6b54e96b0cc9870817013c350a1David Brownell */ 189904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 199904f22a7202c6b54e96b0cc9870817013c350a1David Brownell#include <linux/spinlock.h> 209904f22a7202c6b54e96b0cc9870817013c350a1David Brownell#include <linux/workqueue.h> 219904f22a7202c6b54e96b0cc9870817013c350a1David Brownell#include <linux/interrupt.h> 22d7614de422c0b55db0c1013a6c72330187536004Paul Gortmaker#include <linux/module.h> 239904f22a7202c6b54e96b0cc9870817013c350a1David Brownell#include <linux/delay.h> 249904f22a7202c6b54e96b0cc9870817013c350a1David Brownell#include <linux/errno.h> 259904f22a7202c6b54e96b0cc9870817013c350a1David Brownell#include <linux/platform_device.h> 265a0e3ad6af8660be21ca98a971cd00f331318c05Tejun Heo#include <linux/slab.h> 279904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 289904f22a7202c6b54e96b0cc9870817013c350a1David Brownell#include <linux/spi/spi.h> 299904f22a7202c6b54e96b0cc9870817013c350a1David Brownell#include <linux/spi/spi_bitbang.h> 309904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 319904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 329904f22a7202c6b54e96b0cc9870817013c350a1David Brownell/*----------------------------------------------------------------------*/ 339904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 349904f22a7202c6b54e96b0cc9870817013c350a1David Brownell/* 359904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * FIRST PART (OPTIONAL): word-at-a-time spi_transfer support. 369904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * Use this for GPIO or shift-register level hardware APIs. 379904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * 389904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * spi_bitbang_cs is in spi_device->controller_state, which is unavailable 399904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * to glue code. These bitbang setup() and cleanup() routines are always 409904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * used, though maybe they're called from controller-aware code. 419904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * 4203ddcbc5d80443c9e0cf1b263b68b4df9759af18Uwe Kleine-König * chipselect() and friends may use spi_device->controller_data and 439904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * controller registers as appropriate. 449904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * 459904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * 469904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * NOTE: SPI controller pins can often be used as GPIO pins instead, 479904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * which means you could use a bitbang driver either to get hardware 489904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * working quickly, or testing for differences that aren't speed related. 499904f22a7202c6b54e96b0cc9870817013c350a1David Brownell */ 509904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 519904f22a7202c6b54e96b0cc9870817013c350a1David Brownellstruct spi_bitbang_cs { 529904f22a7202c6b54e96b0cc9870817013c350a1David Brownell unsigned nsecs; /* (clock cycle time)/2 */ 539904f22a7202c6b54e96b0cc9870817013c350a1David Brownell u32 (*txrx_word)(struct spi_device *spi, unsigned nsecs, 549904f22a7202c6b54e96b0cc9870817013c350a1David Brownell u32 word, u8 bits); 559904f22a7202c6b54e96b0cc9870817013c350a1David Brownell unsigned (*txrx_bufs)(struct spi_device *, 569904f22a7202c6b54e96b0cc9870817013c350a1David Brownell u32 (*txrx_word)( 579904f22a7202c6b54e96b0cc9870817013c350a1David Brownell struct spi_device *spi, 589904f22a7202c6b54e96b0cc9870817013c350a1David Brownell unsigned nsecs, 599904f22a7202c6b54e96b0cc9870817013c350a1David Brownell u32 word, u8 bits), 609904f22a7202c6b54e96b0cc9870817013c350a1David Brownell unsigned, struct spi_transfer *); 619904f22a7202c6b54e96b0cc9870817013c350a1David Brownell}; 629904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 639904f22a7202c6b54e96b0cc9870817013c350a1David Brownellstatic unsigned bitbang_txrx_8( 649904f22a7202c6b54e96b0cc9870817013c350a1David Brownell struct spi_device *spi, 659904f22a7202c6b54e96b0cc9870817013c350a1David Brownell u32 (*txrx_word)(struct spi_device *spi, 669904f22a7202c6b54e96b0cc9870817013c350a1David Brownell unsigned nsecs, 679904f22a7202c6b54e96b0cc9870817013c350a1David Brownell u32 word, u8 bits), 689904f22a7202c6b54e96b0cc9870817013c350a1David Brownell unsigned ns, 699904f22a7202c6b54e96b0cc9870817013c350a1David Brownell struct spi_transfer *t 709904f22a7202c6b54e96b0cc9870817013c350a1David Brownell) { 71766ed70447e0a9cfb23d068a4a929e18e54b0022Laxman Dewangan unsigned bits = t->bits_per_word; 729904f22a7202c6b54e96b0cc9870817013c350a1David Brownell unsigned count = t->len; 739904f22a7202c6b54e96b0cc9870817013c350a1David Brownell const u8 *tx = t->tx_buf; 749904f22a7202c6b54e96b0cc9870817013c350a1David Brownell u8 *rx = t->rx_buf; 759904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 769904f22a7202c6b54e96b0cc9870817013c350a1David Brownell while (likely(count > 0)) { 779904f22a7202c6b54e96b0cc9870817013c350a1David Brownell u8 word = 0; 789904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 799904f22a7202c6b54e96b0cc9870817013c350a1David Brownell if (tx) 809904f22a7202c6b54e96b0cc9870817013c350a1David Brownell word = *tx++; 819904f22a7202c6b54e96b0cc9870817013c350a1David Brownell word = txrx_word(spi, ns, word, bits); 829904f22a7202c6b54e96b0cc9870817013c350a1David Brownell if (rx) 839904f22a7202c6b54e96b0cc9870817013c350a1David Brownell *rx++ = word; 849904f22a7202c6b54e96b0cc9870817013c350a1David Brownell count -= 1; 859904f22a7202c6b54e96b0cc9870817013c350a1David Brownell } 869904f22a7202c6b54e96b0cc9870817013c350a1David Brownell return t->len - count; 879904f22a7202c6b54e96b0cc9870817013c350a1David Brownell} 889904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 899904f22a7202c6b54e96b0cc9870817013c350a1David Brownellstatic unsigned bitbang_txrx_16( 909904f22a7202c6b54e96b0cc9870817013c350a1David Brownell struct spi_device *spi, 919904f22a7202c6b54e96b0cc9870817013c350a1David Brownell u32 (*txrx_word)(struct spi_device *spi, 929904f22a7202c6b54e96b0cc9870817013c350a1David Brownell unsigned nsecs, 939904f22a7202c6b54e96b0cc9870817013c350a1David Brownell u32 word, u8 bits), 949904f22a7202c6b54e96b0cc9870817013c350a1David Brownell unsigned ns, 959904f22a7202c6b54e96b0cc9870817013c350a1David Brownell struct spi_transfer *t 969904f22a7202c6b54e96b0cc9870817013c350a1David Brownell) { 97766ed70447e0a9cfb23d068a4a929e18e54b0022Laxman Dewangan unsigned bits = t->bits_per_word; 989904f22a7202c6b54e96b0cc9870817013c350a1David Brownell unsigned count = t->len; 999904f22a7202c6b54e96b0cc9870817013c350a1David Brownell const u16 *tx = t->tx_buf; 1009904f22a7202c6b54e96b0cc9870817013c350a1David Brownell u16 *rx = t->rx_buf; 1019904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 1029904f22a7202c6b54e96b0cc9870817013c350a1David Brownell while (likely(count > 1)) { 1039904f22a7202c6b54e96b0cc9870817013c350a1David Brownell u16 word = 0; 1049904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 1059904f22a7202c6b54e96b0cc9870817013c350a1David Brownell if (tx) 1069904f22a7202c6b54e96b0cc9870817013c350a1David Brownell word = *tx++; 1079904f22a7202c6b54e96b0cc9870817013c350a1David Brownell word = txrx_word(spi, ns, word, bits); 1089904f22a7202c6b54e96b0cc9870817013c350a1David Brownell if (rx) 1099904f22a7202c6b54e96b0cc9870817013c350a1David Brownell *rx++ = word; 1109904f22a7202c6b54e96b0cc9870817013c350a1David Brownell count -= 2; 1119904f22a7202c6b54e96b0cc9870817013c350a1David Brownell } 1129904f22a7202c6b54e96b0cc9870817013c350a1David Brownell return t->len - count; 1139904f22a7202c6b54e96b0cc9870817013c350a1David Brownell} 1149904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 1159904f22a7202c6b54e96b0cc9870817013c350a1David Brownellstatic unsigned bitbang_txrx_32( 1169904f22a7202c6b54e96b0cc9870817013c350a1David Brownell struct spi_device *spi, 1179904f22a7202c6b54e96b0cc9870817013c350a1David Brownell u32 (*txrx_word)(struct spi_device *spi, 1189904f22a7202c6b54e96b0cc9870817013c350a1David Brownell unsigned nsecs, 1199904f22a7202c6b54e96b0cc9870817013c350a1David Brownell u32 word, u8 bits), 1209904f22a7202c6b54e96b0cc9870817013c350a1David Brownell unsigned ns, 1219904f22a7202c6b54e96b0cc9870817013c350a1David Brownell struct spi_transfer *t 1229904f22a7202c6b54e96b0cc9870817013c350a1David Brownell) { 123766ed70447e0a9cfb23d068a4a929e18e54b0022Laxman Dewangan unsigned bits = t->bits_per_word; 1249904f22a7202c6b54e96b0cc9870817013c350a1David Brownell unsigned count = t->len; 1259904f22a7202c6b54e96b0cc9870817013c350a1David Brownell const u32 *tx = t->tx_buf; 1269904f22a7202c6b54e96b0cc9870817013c350a1David Brownell u32 *rx = t->rx_buf; 1279904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 1289904f22a7202c6b54e96b0cc9870817013c350a1David Brownell while (likely(count > 3)) { 1299904f22a7202c6b54e96b0cc9870817013c350a1David Brownell u32 word = 0; 1309904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 1319904f22a7202c6b54e96b0cc9870817013c350a1David Brownell if (tx) 1329904f22a7202c6b54e96b0cc9870817013c350a1David Brownell word = *tx++; 1339904f22a7202c6b54e96b0cc9870817013c350a1David Brownell word = txrx_word(spi, ns, word, bits); 1349904f22a7202c6b54e96b0cc9870817013c350a1David Brownell if (rx) 1359904f22a7202c6b54e96b0cc9870817013c350a1David Brownell *rx++ = word; 1369904f22a7202c6b54e96b0cc9870817013c350a1David Brownell count -= 4; 1379904f22a7202c6b54e96b0cc9870817013c350a1David Brownell } 1389904f22a7202c6b54e96b0cc9870817013c350a1David Brownell return t->len - count; 1399904f22a7202c6b54e96b0cc9870817013c350a1David Brownell} 1409904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 141ff9f4771b5f017ee0f57629488b6cd7a6ef3d19bKumar Galaint spi_bitbang_setup_transfer(struct spi_device *spi, struct spi_transfer *t) 1424cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak{ 1434cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak struct spi_bitbang_cs *cs = spi->controller_state; 1444cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak u8 bits_per_word; 1454cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak u32 hz; 1464cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak 1474cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak if (t) { 1484cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak bits_per_word = t->bits_per_word; 1494cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak hz = t->speed_hz; 1504cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak } else { 1514cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak bits_per_word = 0; 1524cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak hz = 0; 1534cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak } 1544cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak 1554cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak /* spi_transfer level calls that work per-word */ 1564cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak if (!bits_per_word) 1574cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak bits_per_word = spi->bits_per_word; 1584cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak if (bits_per_word <= 8) 1594cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak cs->txrx_bufs = bitbang_txrx_8; 1604cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak else if (bits_per_word <= 16) 1614cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak cs->txrx_bufs = bitbang_txrx_16; 1624cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak else if (bits_per_word <= 32) 1634cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak cs->txrx_bufs = bitbang_txrx_32; 1644cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak else 1654cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak return -EINVAL; 1664cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak 1674cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak /* nsecs = (clock period)/2 */ 1684cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak if (!hz) 1694cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak hz = spi->max_speed_hz; 1701e316d7566b63767aa18902235c719e9e95465d0David Brownell if (hz) { 1711e316d7566b63767aa18902235c719e9e95465d0David Brownell cs->nsecs = (1000000000/2) / hz; 1721e316d7566b63767aa18902235c719e9e95465d0David Brownell if (cs->nsecs > (MAX_UDELAY_MS * 1000 * 1000)) 1731e316d7566b63767aa18902235c719e9e95465d0David Brownell return -EINVAL; 1741e316d7566b63767aa18902235c719e9e95465d0David Brownell } 1754cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak 1764cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak return 0; 1774cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak} 178ff9f4771b5f017ee0f57629488b6cd7a6ef3d19bKumar GalaEXPORT_SYMBOL_GPL(spi_bitbang_setup_transfer); 1794cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak 1809904f22a7202c6b54e96b0cc9870817013c350a1David Brownell/** 1819904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * spi_bitbang_setup - default setup for per-word I/O loops 1829904f22a7202c6b54e96b0cc9870817013c350a1David Brownell */ 1839904f22a7202c6b54e96b0cc9870817013c350a1David Brownellint spi_bitbang_setup(struct spi_device *spi) 1849904f22a7202c6b54e96b0cc9870817013c350a1David Brownell{ 1859904f22a7202c6b54e96b0cc9870817013c350a1David Brownell struct spi_bitbang_cs *cs = spi->controller_state; 1869904f22a7202c6b54e96b0cc9870817013c350a1David Brownell struct spi_bitbang *bitbang; 1874cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak int retval; 188d52df2e2ea2d881b1439bbdec7f67c27e0f47941David Brownell unsigned long flags; 1899904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 190ccf77cc4af5b048e20cfd9327fcc286cb69c34ccDavid Brownell bitbang = spi_master_get_devdata(spi->master); 191ccf77cc4af5b048e20cfd9327fcc286cb69c34ccDavid Brownell 1929904f22a7202c6b54e96b0cc9870817013c350a1David Brownell if (!cs) { 193cff93c58f7a99b3bf2fc3b343a1b6ca0546120daJingoo Han cs = kzalloc(sizeof(*cs), GFP_KERNEL); 1949904f22a7202c6b54e96b0cc9870817013c350a1David Brownell if (!cs) 1959904f22a7202c6b54e96b0cc9870817013c350a1David Brownell return -ENOMEM; 1969904f22a7202c6b54e96b0cc9870817013c350a1David Brownell spi->controller_state = cs; 1979904f22a7202c6b54e96b0cc9870817013c350a1David Brownell } 1989904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 1999904f22a7202c6b54e96b0cc9870817013c350a1David Brownell /* per-word shift register access, in hardware or bitbanging */ 2009904f22a7202c6b54e96b0cc9870817013c350a1David Brownell cs->txrx_word = bitbang->txrx_word[spi->mode & (SPI_CPOL|SPI_CPHA)]; 2019904f22a7202c6b54e96b0cc9870817013c350a1David Brownell if (!cs->txrx_word) 2029904f22a7202c6b54e96b0cc9870817013c350a1David Brownell return -EINVAL; 2039904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 2047f8c7619ea1ff5ab8e0b08c8120d629834ef4253Hans-Peter Nilsson retval = bitbang->setup_transfer(spi, NULL); 2054cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak if (retval < 0) 2064cff33f94fefcce1b3c01a9d1da6bb85fe3cbdfaImre Deak return retval; 2079904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 2087d0771970c51e736758525dd71fb82dd036b823aDavid Brownell dev_dbg(&spi->dev, "%s, %u nsec/bit\n", __func__, 2 * cs->nsecs); 2099904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 2109904f22a7202c6b54e96b0cc9870817013c350a1David Brownell /* NOTE we _need_ to call chipselect() early, ideally with adapter 2119904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * setup, unless the hardware defaults cooperate to avoid confusion 2129904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * between normal (active low) and inverted chipselects. 2139904f22a7202c6b54e96b0cc9870817013c350a1David Brownell */ 2149904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 2159904f22a7202c6b54e96b0cc9870817013c350a1David Brownell /* deselect chip (low or high) */ 216d52df2e2ea2d881b1439bbdec7f67c27e0f47941David Brownell spin_lock_irqsave(&bitbang->lock, flags); 2179904f22a7202c6b54e96b0cc9870817013c350a1David Brownell if (!bitbang->busy) { 2188275c642ccdce09a2146d0a9eb022e3698ee927eVitaly Wool bitbang->chipselect(spi, BITBANG_CS_INACTIVE); 2199904f22a7202c6b54e96b0cc9870817013c350a1David Brownell ndelay(cs->nsecs); 2209904f22a7202c6b54e96b0cc9870817013c350a1David Brownell } 221d52df2e2ea2d881b1439bbdec7f67c27e0f47941David Brownell spin_unlock_irqrestore(&bitbang->lock, flags); 2229904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 2239904f22a7202c6b54e96b0cc9870817013c350a1David Brownell return 0; 2249904f22a7202c6b54e96b0cc9870817013c350a1David Brownell} 2259904f22a7202c6b54e96b0cc9870817013c350a1David BrownellEXPORT_SYMBOL_GPL(spi_bitbang_setup); 2269904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 2279904f22a7202c6b54e96b0cc9870817013c350a1David Brownell/** 2289904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * spi_bitbang_cleanup - default cleanup for per-word I/O loops 2299904f22a7202c6b54e96b0cc9870817013c350a1David Brownell */ 2300ffa0285052607513a29f529ddb5061c907fd8a6Hans-Peter Nilssonvoid spi_bitbang_cleanup(struct spi_device *spi) 2319904f22a7202c6b54e96b0cc9870817013c350a1David Brownell{ 2329904f22a7202c6b54e96b0cc9870817013c350a1David Brownell kfree(spi->controller_state); 2339904f22a7202c6b54e96b0cc9870817013c350a1David Brownell} 2349904f22a7202c6b54e96b0cc9870817013c350a1David BrownellEXPORT_SYMBOL_GPL(spi_bitbang_cleanup); 2359904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 2369904f22a7202c6b54e96b0cc9870817013c350a1David Brownellstatic int spi_bitbang_bufs(struct spi_device *spi, struct spi_transfer *t) 2379904f22a7202c6b54e96b0cc9870817013c350a1David Brownell{ 2389904f22a7202c6b54e96b0cc9870817013c350a1David Brownell struct spi_bitbang_cs *cs = spi->controller_state; 2399904f22a7202c6b54e96b0cc9870817013c350a1David Brownell unsigned nsecs = cs->nsecs; 2409904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 2419904f22a7202c6b54e96b0cc9870817013c350a1David Brownell return cs->txrx_bufs(spi, cs->txrx_word, nsecs, t); 2429904f22a7202c6b54e96b0cc9870817013c350a1David Brownell} 2439904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 2449904f22a7202c6b54e96b0cc9870817013c350a1David Brownell/*----------------------------------------------------------------------*/ 2459904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 2469904f22a7202c6b54e96b0cc9870817013c350a1David Brownell/* 2479904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * SECOND PART ... simple transfer queue runner. 2489904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * 2499904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * This costs a task context per controller, running the queue by 2509904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * performing each transfer in sequence. Smarter hardware can queue 2519904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * several DMA transfers at once, and process several controller queues 2529904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * in parallel; this driver doesn't match such hardware very well. 2539904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * 2549904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * Drivers can provide word-at-a-time i/o primitives, or provide 2559904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * transfer-at-a-time ones to leverage dma or fifo hardware. 2569904f22a7202c6b54e96b0cc9870817013c350a1David Brownell */ 2572025172e32808a327b00f968c72baa79adc594c2Mark Brown 2582025172e32808a327b00f968c72baa79adc594c2Mark Brownstatic int spi_bitbang_prepare_hardware(struct spi_master *spi) 2592025172e32808a327b00f968c72baa79adc594c2Mark Brown{ 260cff93c58f7a99b3bf2fc3b343a1b6ca0546120daJingoo Han struct spi_bitbang *bitbang; 2612025172e32808a327b00f968c72baa79adc594c2Mark Brown unsigned long flags; 2622025172e32808a327b00f968c72baa79adc594c2Mark Brown 2632025172e32808a327b00f968c72baa79adc594c2Mark Brown bitbang = spi_master_get_devdata(spi); 2642025172e32808a327b00f968c72baa79adc594c2Mark Brown 2652025172e32808a327b00f968c72baa79adc594c2Mark Brown spin_lock_irqsave(&bitbang->lock, flags); 2662025172e32808a327b00f968c72baa79adc594c2Mark Brown bitbang->busy = 1; 2672025172e32808a327b00f968c72baa79adc594c2Mark Brown spin_unlock_irqrestore(&bitbang->lock, flags); 2682025172e32808a327b00f968c72baa79adc594c2Mark Brown 2692025172e32808a327b00f968c72baa79adc594c2Mark Brown return 0; 2702025172e32808a327b00f968c72baa79adc594c2Mark Brown} 2712025172e32808a327b00f968c72baa79adc594c2Mark Brown 272d60990d597bfa2816dfe28a5c5c6787610b423e6Fabio Estevamstatic int spi_bitbang_transfer_one(struct spi_master *master, 27391b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown struct spi_message *m) 2749904f22a7202c6b54e96b0cc9870817013c350a1David Brownell{ 275cff93c58f7a99b3bf2fc3b343a1b6ca0546120daJingoo Han struct spi_bitbang *bitbang; 27691b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown unsigned nsecs; 27791b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown struct spi_transfer *t = NULL; 27891b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown unsigned cs_change; 27991b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown int status; 28091b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown int do_setup = -1; 281d60990d597bfa2816dfe28a5c5c6787610b423e6Fabio Estevam struct spi_device *spi = m->spi; 2829904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 283d60990d597bfa2816dfe28a5c5c6787610b423e6Fabio Estevam bitbang = spi_master_get_devdata(master); 2849904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 28591b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown /* FIXME this is made-up ... the correct value is known to 28691b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown * word-at-a-time bitbang code, and presumably chipselect() 28791b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown * should enforce these requirements too? 28891b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown */ 28991b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown nsecs = 100; 2909904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 29191b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown cs_change = 1; 29291b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown status = 0; 2939904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 294cff93c58f7a99b3bf2fc3b343a1b6ca0546120daJingoo Han list_for_each_entry(t, &m->transfers, transfer_list) { 2959904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 29691b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown /* override speed or wordsize? */ 29791b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown if (t->speed_hz || t->bits_per_word) 29891b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown do_setup = 1; 2999904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 30091b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown /* init (-1) or override (1) transfer params */ 30191b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown if (do_setup != 0) { 30291b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown status = bitbang->setup_transfer(spi, t); 30391b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown if (status < 0) 3049904f22a7202c6b54e96b0cc9870817013c350a1David Brownell break; 30591b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown if (do_setup == -1) 30691b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown do_setup = 0; 3079904f22a7202c6b54e96b0cc9870817013c350a1David Brownell } 3089904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 30991b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown /* set up default clock polarity, and activate chip; 31091b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown * this implicitly updates clock and spi modes as 31191b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown * previously recorded for this device via setup(). 31291b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown * (and also deselects any other chip that might be 31391b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown * selected ...) 31491b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown */ 31591b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown if (cs_change) { 31691b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown bitbang->chipselect(spi, BITBANG_CS_ACTIVE); 31791b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown ndelay(nsecs); 31891b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown } 31991b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown cs_change = t->cs_change; 32091b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown if (!t->tx_buf && !t->rx_buf && t->len) { 32191b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown status = -EINVAL; 32291b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown break; 32391b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown } 3249904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 32591b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown /* transfer data. the lower level code handles any 32691b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown * new dma mappings it needs. our caller always gave 32791b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown * us dma-safe buffers. 3288275c642ccdce09a2146d0a9eb022e3698ee927eVitaly Wool */ 32991b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown if (t->len) { 33091b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown /* REVISIT dma API still needs a designated 33191b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown * DMA_ADDR_INVALID; ~0 might be better. 33291b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown */ 33391b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown if (!m->is_dma_mapped) 33491b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown t->rx_dma = t->tx_dma = 0; 33591b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown status = bitbang->txrx_bufs(spi, t); 33691b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown } 33791b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown if (status > 0) 33891b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown m->actual_length += status; 33991b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown if (status != t->len) { 34091b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown /* always report some kind of error */ 34191b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown if (status >= 0) 34291b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown status = -EREMOTEIO; 34391b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown break; 34491b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown } 34591b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown status = 0; 34691b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown 34791b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown /* protocol tweaks before next transfer */ 34891b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown if (t->delay_usecs) 34991b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown udelay(t->delay_usecs); 35091b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown 351cff93c58f7a99b3bf2fc3b343a1b6ca0546120daJingoo Han if (cs_change && 352cff93c58f7a99b3bf2fc3b343a1b6ca0546120daJingoo Han !list_is_last(&t->transfer_list, &m->transfers)) { 35391b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown /* sometimes a short mid-message deselect of the chip 35491b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown * may be needed to terminate a mode or command 35591b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown */ 3568275c642ccdce09a2146d0a9eb022e3698ee927eVitaly Wool ndelay(nsecs); 3578275c642ccdce09a2146d0a9eb022e3698ee927eVitaly Wool bitbang->chipselect(spi, BITBANG_CS_INACTIVE); 3588275c642ccdce09a2146d0a9eb022e3698ee927eVitaly Wool ndelay(nsecs); 3598275c642ccdce09a2146d0a9eb022e3698ee927eVitaly Wool } 36091b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown } 36191b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown 36291b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown m->status = status; 36391b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown 36491b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown /* normally deactivate chipselect ... unless no error and 36591b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown * cs_change has hinted that the next message will probably 36691b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown * be for this chip too. 36791b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown */ 36891b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown if (!(status == 0 && cs_change)) { 36991b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown ndelay(nsecs); 37091b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown bitbang->chipselect(spi, BITBANG_CS_INACTIVE); 37191b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown ndelay(nsecs); 37291b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown } 37391b308586793b48c590c9ac3528bbacb8ef53e15Mark Brown 374d60990d597bfa2816dfe28a5c5c6787610b423e6Fabio Estevam spi_finalize_current_message(master); 3759904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 3762025172e32808a327b00f968c72baa79adc594c2Mark Brown return status; 3779904f22a7202c6b54e96b0cc9870817013c350a1David Brownell} 3789904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 3792025172e32808a327b00f968c72baa79adc594c2Mark Brownstatic int spi_bitbang_unprepare_hardware(struct spi_master *spi) 3809904f22a7202c6b54e96b0cc9870817013c350a1David Brownell{ 381cff93c58f7a99b3bf2fc3b343a1b6ca0546120daJingoo Han struct spi_bitbang *bitbang; 3829904f22a7202c6b54e96b0cc9870817013c350a1David Brownell unsigned long flags; 3839904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 3842025172e32808a327b00f968c72baa79adc594c2Mark Brown bitbang = spi_master_get_devdata(spi); 3859904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 3869904f22a7202c6b54e96b0cc9870817013c350a1David Brownell spin_lock_irqsave(&bitbang->lock, flags); 3872025172e32808a327b00f968c72baa79adc594c2Mark Brown bitbang->busy = 0; 3889904f22a7202c6b54e96b0cc9870817013c350a1David Brownell spin_unlock_irqrestore(&bitbang->lock, flags); 3899904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 3902025172e32808a327b00f968c72baa79adc594c2Mark Brown return 0; 3919904f22a7202c6b54e96b0cc9870817013c350a1David Brownell} 3929904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 3939904f22a7202c6b54e96b0cc9870817013c350a1David Brownell/*----------------------------------------------------------------------*/ 3949904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 3959904f22a7202c6b54e96b0cc9870817013c350a1David Brownell/** 3969904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * spi_bitbang_start - start up a polled/bitbanging SPI master driver 3979904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * @bitbang: driver handle 3989904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * 3999904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * Caller should have zero-initialized all parts of the structure, and then 4009904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * provided callbacks for chip selection and I/O loops. If the master has 4019904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * a transfer method, its final step should call spi_bitbang_transfer; or, 4029904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * that's the default if the transfer routine is not initialized. It should 4039904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * also set up the bus number and number of chipselects. 4049904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * 4059904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * For i/o loops, provide callbacks either per-word (for bitbanging, or for 4069904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * hardware that basically exposes a shift register) or per-spi_transfer 4079904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * (which takes better advantage of hardware like fifos or DMA engines). 4089904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * 4097f8c7619ea1ff5ab8e0b08c8120d629834ef4253Hans-Peter Nilsson * Drivers using per-word I/O loops should use (or call) spi_bitbang_setup, 4107f8c7619ea1ff5ab8e0b08c8120d629834ef4253Hans-Peter Nilsson * spi_bitbang_cleanup and spi_bitbang_setup_transfer to handle those spi 4117f8c7619ea1ff5ab8e0b08c8120d629834ef4253Hans-Peter Nilsson * master methods. Those methods are the defaults if the bitbang->txrx_bufs 4127f8c7619ea1ff5ab8e0b08c8120d629834ef4253Hans-Peter Nilsson * routine isn't initialized. 4139904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * 4149904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * This routine registers the spi_master, which will process requests in a 4159904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * dedicated task, keeping IRQs unblocked most of the time. To stop 4169904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * processing those requests, call spi_bitbang_stop(). 417702a4879ec337463f858c8ab467482cce260bf18Axel Lin * 418702a4879ec337463f858c8ab467482cce260bf18Axel Lin * On success, this routine will take a reference to master. The caller is 419702a4879ec337463f858c8ab467482cce260bf18Axel Lin * responsible for calling spi_bitbang_stop() to decrement the reference and 420702a4879ec337463f858c8ab467482cce260bf18Axel Lin * spi_master_put() as counterpart of spi_alloc_master() to prevent a memory 421702a4879ec337463f858c8ab467482cce260bf18Axel Lin * leak. 4229904f22a7202c6b54e96b0cc9870817013c350a1David Brownell */ 4239904f22a7202c6b54e96b0cc9870817013c350a1David Brownellint spi_bitbang_start(struct spi_bitbang *bitbang) 4249904f22a7202c6b54e96b0cc9870817013c350a1David Brownell{ 4257a5d8ca12aece480e0fe5eda8ce4236dddf55363Guennadi Liakhovetski struct spi_master *master = bitbang->master; 426702a4879ec337463f858c8ab467482cce260bf18Axel Lin int ret; 4279904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 4287a5d8ca12aece480e0fe5eda8ce4236dddf55363Guennadi Liakhovetski if (!master || !bitbang->chipselect) 4299904f22a7202c6b54e96b0cc9870817013c350a1David Brownell return -EINVAL; 4309904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 4319904f22a7202c6b54e96b0cc9870817013c350a1David Brownell spin_lock_init(&bitbang->lock); 4329904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 4337a5d8ca12aece480e0fe5eda8ce4236dddf55363Guennadi Liakhovetski if (!master->mode_bits) 4347a5d8ca12aece480e0fe5eda8ce4236dddf55363Guennadi Liakhovetski master->mode_bits = SPI_CPOL | SPI_CPHA | bitbang->flags; 435e7db06b5d5afcef15c4c3e61c3a7441ed7ad1407David Brownell 4362025172e32808a327b00f968c72baa79adc594c2Mark Brown if (master->transfer || master->transfer_one_message) 4372025172e32808a327b00f968c72baa79adc594c2Mark Brown return -EINVAL; 4382025172e32808a327b00f968c72baa79adc594c2Mark Brown 4392025172e32808a327b00f968c72baa79adc594c2Mark Brown master->prepare_transfer_hardware = spi_bitbang_prepare_hardware; 4402025172e32808a327b00f968c72baa79adc594c2Mark Brown master->unprepare_transfer_hardware = spi_bitbang_unprepare_hardware; 4412025172e32808a327b00f968c72baa79adc594c2Mark Brown master->transfer_one_message = spi_bitbang_transfer_one; 4422025172e32808a327b00f968c72baa79adc594c2Mark Brown 4439904f22a7202c6b54e96b0cc9870817013c350a1David Brownell if (!bitbang->txrx_bufs) { 4449904f22a7202c6b54e96b0cc9870817013c350a1David Brownell bitbang->use_dma = 0; 4459904f22a7202c6b54e96b0cc9870817013c350a1David Brownell bitbang->txrx_bufs = spi_bitbang_bufs; 4467a5d8ca12aece480e0fe5eda8ce4236dddf55363Guennadi Liakhovetski if (!master->setup) { 447ff9f4771b5f017ee0f57629488b6cd7a6ef3d19bKumar Gala if (!bitbang->setup_transfer) 448ff9f4771b5f017ee0f57629488b6cd7a6ef3d19bKumar Gala bitbang->setup_transfer = 449ff9f4771b5f017ee0f57629488b6cd7a6ef3d19bKumar Gala spi_bitbang_setup_transfer; 4507a5d8ca12aece480e0fe5eda8ce4236dddf55363Guennadi Liakhovetski master->setup = spi_bitbang_setup; 4517a5d8ca12aece480e0fe5eda8ce4236dddf55363Guennadi Liakhovetski master->cleanup = spi_bitbang_cleanup; 4529904f22a7202c6b54e96b0cc9870817013c350a1David Brownell } 45352ade736215fb4421a6dc2b6900703a6fadba9e9Uwe Kleine-König } 4549904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 4559904f22a7202c6b54e96b0cc9870817013c350a1David Brownell /* driver may get busy before register() returns, especially 4569904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * if someone registered boardinfo for devices 4579904f22a7202c6b54e96b0cc9870817013c350a1David Brownell */ 458702a4879ec337463f858c8ab467482cce260bf18Axel Lin ret = spi_register_master(spi_master_get(master)); 459702a4879ec337463f858c8ab467482cce260bf18Axel Lin if (ret) 460702a4879ec337463f858c8ab467482cce260bf18Axel Lin spi_master_put(master); 461702a4879ec337463f858c8ab467482cce260bf18Axel Lin 462702a4879ec337463f858c8ab467482cce260bf18Axel Lin return 0; 4639904f22a7202c6b54e96b0cc9870817013c350a1David Brownell} 4649904f22a7202c6b54e96b0cc9870817013c350a1David BrownellEXPORT_SYMBOL_GPL(spi_bitbang_start); 4659904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 4669904f22a7202c6b54e96b0cc9870817013c350a1David Brownell/** 4679904f22a7202c6b54e96b0cc9870817013c350a1David Brownell * spi_bitbang_stop - stops the task providing spi communication 4689904f22a7202c6b54e96b0cc9870817013c350a1David Brownell */ 469d9721ae1493725bb14dcd1a3c19bbb5795e4a42fAxel Linvoid spi_bitbang_stop(struct spi_bitbang *bitbang) 4709904f22a7202c6b54e96b0cc9870817013c350a1David Brownell{ 471a836f5856ae46ccb2464ea76031ea05ae967b832Chris Lesiak spi_unregister_master(bitbang->master); 4729904f22a7202c6b54e96b0cc9870817013c350a1David Brownell} 4739904f22a7202c6b54e96b0cc9870817013c350a1David BrownellEXPORT_SYMBOL_GPL(spi_bitbang_stop); 4749904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 4759904f22a7202c6b54e96b0cc9870817013c350a1David BrownellMODULE_LICENSE("GPL"); 4769904f22a7202c6b54e96b0cc9870817013c350a1David Brownell 477