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