ipack.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * Industry-pack bus.
  3. *
  4. * Copyright (C) 2011-2012 CERN (www.cern.ch)
  5. * Author: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the Free
  9. * Software Foundation; version 2 of the License.
  10. */
  11. #include <linux/mod_devicetable.h>
  12. #include <linux/device.h>
  13. #include <linux/interrupt.h>
  14. #define IPACK_IDPROM_OFFSET_I 0x01
  15. #define IPACK_IDPROM_OFFSET_P 0x03
  16. #define IPACK_IDPROM_OFFSET_A 0x05
  17. #define IPACK_IDPROM_OFFSET_C 0x07
  18. #define IPACK_IDPROM_OFFSET_MANUFACTURER_ID 0x09
  19. #define IPACK_IDPROM_OFFSET_MODEL 0x0B
  20. #define IPACK_IDPROM_OFFSET_REVISION 0x0D
  21. #define IPACK_IDPROM_OFFSET_RESERVED 0x0F
  22. #define IPACK_IDPROM_OFFSET_DRIVER_ID_L 0x11
  23. #define IPACK_IDPROM_OFFSET_DRIVER_ID_H 0x13
  24. #define IPACK_IDPROM_OFFSET_NUM_BYTES 0x15
  25. #define IPACK_IDPROM_OFFSET_CRC 0x17
  26. struct ipack_bus_ops;
  27. struct ipack_driver;
  28. enum ipack_space {
  29. IPACK_IO_SPACE = 0,
  30. IPACK_ID_SPACE,
  31. IPACK_INT_SPACE,
  32. IPACK_MEM8_SPACE,
  33. IPACK_MEM16_SPACE,
  34. /* Dummy for counting the number of entries. Must remain the last
  35. * entry */
  36. IPACK_SPACE_COUNT,
  37. };
  38. /**
  39. */
  40. struct ipack_region {
  41. phys_addr_t start;
  42. size_t size;
  43. };
  44. /**
  45. * struct ipack_device
  46. *
  47. * @slot: Slot where the device is plugged in the carrier board
  48. * @bus: ipack_bus_device where the device is plugged to.
  49. * @id_space: Virtual address to ID space.
  50. * @io_space: Virtual address to IO space.
  51. * @mem_space: Virtual address to MEM space.
  52. * @dev: device in kernel representation.
  53. *
  54. * Warning: Direct access to mapped memory is possible but the endianness
  55. * is not the same with PCI carrier or VME carrier. The endianness is managed
  56. * by the carrier board throught bus->ops.
  57. */
  58. struct ipack_device {
  59. unsigned int slot;
  60. struct ipack_bus_device *bus;
  61. struct device dev;
  62. void (*release) (struct ipack_device *dev);
  63. struct ipack_region region[IPACK_SPACE_COUNT];
  64. u8 *id;
  65. size_t id_avail;
  66. u32 id_vendor;
  67. u32 id_device;
  68. u8 id_format;
  69. unsigned int id_crc_correct:1;
  70. unsigned int speed_8mhz:1;
  71. unsigned int speed_32mhz:1;
  72. };
  73. /**
  74. * struct ipack_driver_ops -- Callbacks to IPack device driver
  75. *
  76. * @probe: Probe function
  77. * @remove: Prepare imminent removal of the device. Services provided by the
  78. * device should be revoked.
  79. */
  80. struct ipack_driver_ops {
  81. int (*probe) (struct ipack_device *dev);
  82. void (*remove) (struct ipack_device *dev);
  83. };
  84. /**
  85. * struct ipack_driver -- Specific data to each ipack device driver
  86. *
  87. * @driver: Device driver kernel representation
  88. * @ops: Callbacks provided by the IPack device driver
  89. */
  90. struct ipack_driver {
  91. struct device_driver driver;
  92. const struct ipack_device_id *id_table;
  93. const struct ipack_driver_ops *ops;
  94. };
  95. /**
  96. * struct ipack_bus_ops - available operations on a bridge module
  97. *
  98. * @map_space: map IP address space
  99. * @unmap_space: unmap IP address space
  100. * @request_irq: request IRQ
  101. * @free_irq: free IRQ
  102. * @get_clockrate: Returns the clockrate the carrier is currently
  103. * communicating with the device at.
  104. * @set_clockrate: Sets the clock-rate for carrier / module communication.
  105. * Should return -EINVAL if the requested speed is not supported.
  106. * @get_error: Returns the error state for the slot the device is attached
  107. * to.
  108. * @get_timeout: Returns 1 if the communication with the device has
  109. * previously timed out.
  110. * @reset_timeout: Resets the state returned by get_timeout.
  111. */
  112. struct ipack_bus_ops {
  113. int (*request_irq) (struct ipack_device *dev,
  114. irqreturn_t (*handler)(void *), void *arg);
  115. int (*free_irq) (struct ipack_device *dev);
  116. int (*get_clockrate) (struct ipack_device *dev);
  117. int (*set_clockrate) (struct ipack_device *dev, int mherz);
  118. int (*get_error) (struct ipack_device *dev);
  119. int (*get_timeout) (struct ipack_device *dev);
  120. int (*reset_timeout) (struct ipack_device *dev);
  121. };
  122. /**
  123. * struct ipack_bus_device
  124. *
  125. * @dev: pointer to carrier device
  126. * @slots: number of slots available
  127. * @bus_nr: ipack bus number
  128. * @ops: bus operations for the mezzanine drivers
  129. */
  130. struct ipack_bus_device {
  131. struct device *parent;
  132. int slots;
  133. int bus_nr;
  134. const struct ipack_bus_ops *ops;
  135. };
  136. /**
  137. * ipack_bus_register -- register a new ipack bus
  138. *
  139. * @parent: pointer to the parent device, if any.
  140. * @slots: number of slots available in the bus device.
  141. * @ops: bus operations for the mezzanine drivers.
  142. *
  143. * The carrier board device should call this function to register itself as
  144. * available bus device in ipack.
  145. */
  146. struct ipack_bus_device *ipack_bus_register(struct device *parent, int slots,
  147. const struct ipack_bus_ops *ops);
  148. /**
  149. * ipack_bus_unregister -- unregister an ipack bus
  150. */
  151. int ipack_bus_unregister(struct ipack_bus_device *bus);
  152. /**
  153. * ipack_driver_register -- Register a new ipack device driver
  154. *
  155. * Called by a ipack driver to register itself as a driver
  156. * that can manage ipack devices.
  157. */
  158. int ipack_driver_register(struct ipack_driver *edrv, struct module *owner,
  159. const char *name);
  160. void ipack_driver_unregister(struct ipack_driver *edrv);
  161. /**
  162. * ipack_device_register -- register an IPack device with the kernel
  163. * @dev: the new device to register.
  164. *
  165. * Register a new IPack device ("module" in IndustryPack jargon). The call
  166. * is done by the carrier driver. The carrier should populate the fields
  167. * bus and slot as well as the region array of @dev prior to calling this
  168. * function. The rest of the fields will be allocated and populated
  169. * during registration.
  170. *
  171. * Return zero on success or error code on failure.
  172. */
  173. int ipack_device_register(struct ipack_device *dev);
  174. void ipack_device_unregister(struct ipack_device *dev);
  175. /**
  176. * DEFINE_IPACK_DEVICE_TABLE - macro used to describe a IndustryPack table
  177. * @_table: device table name
  178. *
  179. * This macro is used to create a struct ipack_device_id array (a device table)
  180. * in a generic manner.
  181. */
  182. #define DEFINE_IPACK_DEVICE_TABLE(_table) \
  183. const struct ipack_device_id _table[] __devinitconst
  184. /**
  185. * IPACK_DEVICE - macro used to describe a specific IndustryPack device
  186. * @_format: the format version (currently either 1 or 2, 8 bit value)
  187. * @vend: the 8 or 24 bit IndustryPack Vendor ID
  188. * @dev: the 8 or 16 bit IndustryPack Device ID
  189. *
  190. * This macro is used to create a struct ipack_device_id that matches a specific
  191. * device.
  192. */
  193. #define IPACK_DEVICE(_format, vend, dev) \
  194. .format = (_format), \
  195. .vendor = (vend), \
  196. .device = (dev)