/drivers/input/joystick/iforce/iforce.h

http://github.com/mirrors/linux · C Header · 141 lines · 87 code · 25 blank · 29 comment · 0 complexity · 8f752556165ef3af309e8e3a4b2a3a8d MD5 · raw file

  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (c) 2000-2002 Vojtech Pavlik <vojtech@ucw.cz>
  4. * Copyright (c) 2001-2002, 2007 Johann Deneux <johann.deneux@gmail.com>
  5. *
  6. * USB/RS232 I-Force joysticks and wheels.
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/slab.h>
  10. #include <linux/input.h>
  11. #include <linux/module.h>
  12. #include <linux/spinlock.h>
  13. #include <linux/circ_buf.h>
  14. #include <linux/mutex.h>
  15. /* This module provides arbitrary resource management routines.
  16. * I use it to manage the device's memory.
  17. * Despite the name of this module, I am *not* going to access the ioports.
  18. */
  19. #include <linux/ioport.h>
  20. #define IFORCE_MAX_LENGTH 16
  21. #define IFORCE_EFFECTS_MAX 32
  22. /* Each force feedback effect is made of one core effect, which can be
  23. * associated to at most to effect modifiers
  24. */
  25. #define FF_MOD1_IS_USED 0
  26. #define FF_MOD2_IS_USED 1
  27. #define FF_CORE_IS_USED 2
  28. #define FF_CORE_IS_PLAYED 3 /* Effect is currently being played */
  29. #define FF_CORE_SHOULD_PLAY 4 /* User wants the effect to be played */
  30. #define FF_CORE_UPDATE 5 /* Effect is being updated */
  31. #define FF_MODCORE_CNT 6
  32. struct iforce_core_effect {
  33. /* Information about where modifiers are stored in the device's memory */
  34. struct resource mod1_chunk;
  35. struct resource mod2_chunk;
  36. unsigned long flags[BITS_TO_LONGS(FF_MODCORE_CNT)];
  37. };
  38. #define FF_CMD_EFFECT 0x010e
  39. #define FF_CMD_ENVELOPE 0x0208
  40. #define FF_CMD_MAGNITUDE 0x0303
  41. #define FF_CMD_PERIOD 0x0407
  42. #define FF_CMD_CONDITION 0x050a
  43. #define FF_CMD_AUTOCENTER 0x4002
  44. #define FF_CMD_PLAY 0x4103
  45. #define FF_CMD_ENABLE 0x4201
  46. #define FF_CMD_GAIN 0x4301
  47. #define FF_CMD_QUERY 0xff01
  48. /* Buffer for async write */
  49. #define XMIT_SIZE 256
  50. #define XMIT_INC(var, n) (var)+=n; (var)&= XMIT_SIZE -1
  51. /* iforce::xmit_flags */
  52. #define IFORCE_XMIT_RUNNING 0
  53. #define IFORCE_XMIT_AGAIN 1
  54. struct iforce_device {
  55. u16 idvendor;
  56. u16 idproduct;
  57. char *name;
  58. signed short *btn;
  59. signed short *abs;
  60. signed short *ff;
  61. };
  62. struct iforce;
  63. struct iforce_xport_ops {
  64. void (*xmit)(struct iforce *iforce);
  65. int (*get_id)(struct iforce *iforce, u8 id,
  66. u8 *response_data, size_t *response_len);
  67. int (*start_io)(struct iforce *iforce);
  68. void (*stop_io)(struct iforce *iforce);
  69. };
  70. struct iforce {
  71. struct input_dev *dev; /* Input device interface */
  72. struct iforce_device *type;
  73. const struct iforce_xport_ops *xport_ops;
  74. spinlock_t xmit_lock;
  75. /* Buffer used for asynchronous sending of bytes to the device */
  76. struct circ_buf xmit;
  77. unsigned char xmit_data[XMIT_SIZE];
  78. unsigned long xmit_flags[1];
  79. /* Force Feedback */
  80. wait_queue_head_t wait;
  81. struct resource device_memory;
  82. struct iforce_core_effect core_effects[IFORCE_EFFECTS_MAX];
  83. struct mutex mem_mutex;
  84. };
  85. /* Get hi and low bytes of a 16-bits int */
  86. #define HI(a) ((unsigned char)((a) >> 8))
  87. #define LO(a) ((unsigned char)((a) & 0xff))
  88. /* For many parameters, it seems that 0x80 is a special value that should
  89. * be avoided. Instead, we replace this value by 0x7f
  90. */
  91. #define HIFIX80(a) ((unsigned char)(((a)<0? (a)+255 : (a))>>8))
  92. /* Encode a time value */
  93. #define TIME_SCALE(a) (a)
  94. static inline int iforce_get_id_packet(struct iforce *iforce, u8 id,
  95. u8 *response_data, size_t *response_len)
  96. {
  97. return iforce->xport_ops->get_id(iforce, id,
  98. response_data, response_len);
  99. }
  100. /* Public functions */
  101. /* iforce-main.c */
  102. int iforce_init_device(struct device *parent, u16 bustype,
  103. struct iforce *iforce);
  104. /* iforce-packets.c */
  105. int iforce_control_playback(struct iforce*, u16 id, unsigned int);
  106. void iforce_process_packet(struct iforce *iforce,
  107. u8 packet_id, u8 *data, size_t len);
  108. int iforce_send_packet(struct iforce *iforce, u16 cmd, unsigned char* data);
  109. void iforce_dump_packet(struct iforce *iforce, char *msg, u16 cmd, unsigned char *data);
  110. /* iforce-ff.c */
  111. int iforce_upload_periodic(struct iforce *, struct ff_effect *, struct ff_effect *);
  112. int iforce_upload_constant(struct iforce *, struct ff_effect *, struct ff_effect *);
  113. int iforce_upload_condition(struct iforce *, struct ff_effect *, struct ff_effect *);
  114. /* Public variables */
  115. extern struct serio_driver iforce_serio_drv;
  116. extern struct usb_driver iforce_usb_driver;