fsi-master.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * FSI master definitions. These comprise the core <--> master interface,
  3. * to allow the core to interact with the (hardware-specific) masters.
  4. *
  5. * Copyright (C) IBM Corporation 2016
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. */
  16. #ifndef DRIVERS_FSI_MASTER_H
  17. #define DRIVERS_FSI_MASTER_H
  18. #include <linux/device.h>
  19. #include <linux/mutex.h>
  20. /* Various protocol delays */
  21. #define FSI_ECHO_DELAY_CLOCKS 16 /* Number clocks for echo delay */
  22. #define FSI_SEND_DELAY_CLOCKS 16 /* Number clocks for send delay */
  23. #define FSI_PRE_BREAK_CLOCKS 50 /* Number clocks to prep for break */
  24. #define FSI_BREAK_CLOCKS 256 /* Number of clocks to issue break */
  25. #define FSI_POST_BREAK_CLOCKS 16000 /* Number clocks to set up cfam */
  26. #define FSI_INIT_CLOCKS 5000 /* Clock out any old data */
  27. #define FSI_MASTER_DPOLL_CLOCKS 50 /* < 21 will cause slave to hang */
  28. #define FSI_MASTER_EPOLL_CLOCKS 50 /* Number of clocks for E_POLL retry */
  29. /* Various retry maximums */
  30. #define FSI_CRC_ERR_RETRIES 10
  31. #define FSI_MASTER_MAX_BUSY 200
  32. #define FSI_MASTER_MTOE_COUNT 1000
  33. /* Command encodings */
  34. #define FSI_CMD_DPOLL 0x2
  35. #define FSI_CMD_EPOLL 0x3
  36. #define FSI_CMD_TERM 0x3f
  37. #define FSI_CMD_ABS_AR 0x4
  38. #define FSI_CMD_REL_AR 0x5
  39. #define FSI_CMD_SAME_AR 0x3 /* but only a 2-bit opcode... */
  40. /* Slave responses */
  41. #define FSI_RESP_ACK 0 /* Success */
  42. #define FSI_RESP_BUSY 1 /* Slave busy */
  43. #define FSI_RESP_ERRA 2 /* Any (misc) Error */
  44. #define FSI_RESP_ERRC 3 /* Slave reports master CRC error */
  45. /* Misc */
  46. #define FSI_CRC_SIZE 4
  47. /* fsi-master definition and flags */
  48. #define FSI_MASTER_FLAG_SWCLOCK 0x1
  49. struct fsi_master {
  50. struct device dev;
  51. int idx;
  52. int n_links;
  53. int flags;
  54. struct mutex scan_lock;
  55. int (*read)(struct fsi_master *, int link, uint8_t id,
  56. uint32_t addr, void *val, size_t size);
  57. int (*write)(struct fsi_master *, int link, uint8_t id,
  58. uint32_t addr, const void *val, size_t size);
  59. int (*term)(struct fsi_master *, int link, uint8_t id);
  60. int (*send_break)(struct fsi_master *, int link);
  61. int (*link_enable)(struct fsi_master *, int link);
  62. int (*link_config)(struct fsi_master *, int link,
  63. u8 t_send_delay, u8 t_echo_delay);
  64. };
  65. #define dev_to_fsi_master(d) container_of(d, struct fsi_master, dev)
  66. /**
  67. * fsi_master registration & lifetime: the fsi_master_register() and
  68. * fsi_master_unregister() functions will take ownership of the master, and
  69. * ->dev in particular. The registration path performs a get_device(), which
  70. * takes the first reference on the device. Similarly, the unregistration path
  71. * performs a put_device(), which may well drop the last reference.
  72. *
  73. * This means that master implementations *may* need to hold their own
  74. * reference (via get_device()) on master->dev. In particular, if the device's
  75. * ->release callback frees the fsi_master, then fsi_master_unregister will
  76. * invoke this free if no other reference is held.
  77. *
  78. * The same applies for the error path of fsi_master_register; if the call
  79. * fails, dev->release will have been invoked.
  80. */
  81. extern int fsi_master_register(struct fsi_master *master);
  82. extern void fsi_master_unregister(struct fsi_master *master);
  83. extern int fsi_master_rescan(struct fsi_master *master);
  84. #endif /* DRIVERS_FSI_MASTER_H */