ipack.h 6.4 KB

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