1*6122813fSMike Frysinger /* 2*6122813fSMike Frysinger * Simulate a SPI port and clients (see README.sandbox for details) 3*6122813fSMike Frysinger * 4*6122813fSMike Frysinger * Copyright (c) 2011-2013 The Chromium OS Authors. 5*6122813fSMike Frysinger * See file CREDITS for list of people who contributed to this 6*6122813fSMike Frysinger * project. 7*6122813fSMike Frysinger * 8*6122813fSMike Frysinger * Licensed under the GPL-2 or later. 9*6122813fSMike Frysinger */ 10*6122813fSMike Frysinger 11*6122813fSMike Frysinger #ifndef __ASM_SPI_H__ 12*6122813fSMike Frysinger #define __ASM_SPI_H__ 13*6122813fSMike Frysinger 14*6122813fSMike Frysinger #include <linux/types.h> 15*6122813fSMike Frysinger 16*6122813fSMike Frysinger /* 17*6122813fSMike Frysinger * The interface between the SPI bus and the SPI client. The bus will 18*6122813fSMike Frysinger * instantiate a client, and that then call into it via these entry 19*6122813fSMike Frysinger * points. These should be enough for the client to emulate the SPI 20*6122813fSMike Frysinger * device just like the real hardware. 21*6122813fSMike Frysinger */ 22*6122813fSMike Frysinger struct sandbox_spi_emu_ops { 23*6122813fSMike Frysinger /* The bus wants to instantiate a new client, so setup everything */ 24*6122813fSMike Frysinger int (*setup)(void **priv, const char *spec); 25*6122813fSMike Frysinger /* The bus is done with us, so break things down */ 26*6122813fSMike Frysinger void (*free)(void *priv); 27*6122813fSMike Frysinger /* The CS has been "activated" -- we won't worry about low/high */ 28*6122813fSMike Frysinger void (*cs_activate)(void *priv); 29*6122813fSMike Frysinger /* The CS has been "deactivated" -- we won't worry about low/high */ 30*6122813fSMike Frysinger void (*cs_deactivate)(void *priv); 31*6122813fSMike Frysinger /* The client is rx-ing bytes from the bus, so it should tx some */ 32*6122813fSMike Frysinger int (*xfer)(void *priv, const u8 *rx, u8 *tx, uint bytes); 33*6122813fSMike Frysinger }; 34*6122813fSMike Frysinger 35*6122813fSMike Frysinger /* 36*6122813fSMike Frysinger * There are times when the data lines are allowed to tristate. What 37*6122813fSMike Frysinger * is actually sensed on the line depends on the hardware. It could 38*6122813fSMike Frysinger * always be 0xFF/0x00 (if there are pull ups/downs), or things could 39*6122813fSMike Frysinger * float and so we'd get garbage back. This func encapsulates that 40*6122813fSMike Frysinger * scenario so we can worry about the details here. 41*6122813fSMike Frysinger */ 42*6122813fSMike Frysinger static inline void sandbox_spi_tristate(u8 *buf, uint len) 43*6122813fSMike Frysinger { 44*6122813fSMike Frysinger /* XXX: make this into a user config option ? */ 45*6122813fSMike Frysinger memset(buf, 0xff, len); 46*6122813fSMike Frysinger } 47*6122813fSMike Frysinger 48*6122813fSMike Frysinger /* 49*6122813fSMike Frysinger * Extract the bus/cs from the spi spec and return the start of the spi 50*6122813fSMike Frysinger * client spec. If the bus/cs are invalid for the current config, then 51*6122813fSMike Frysinger * it returns NULL. 52*6122813fSMike Frysinger * 53*6122813fSMike Frysinger * Example: arg="0:1:foo" will set bus to 0, cs to 1, and return "foo" 54*6122813fSMike Frysinger */ 55*6122813fSMike Frysinger const char *sandbox_spi_parse_spec(const char *arg, unsigned long *bus, 56*6122813fSMike Frysinger unsigned long *cs); 57*6122813fSMike Frysinger 58*6122813fSMike Frysinger #endif 59