spi.h 1.9 KB

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