dio.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /* header file for DIO boards for the HP300 architecture.
  2. * Maybe this should handle DIO-II later?
  3. * The general structure of this is vaguely based on how
  4. * the Amiga port handles Zorro boards.
  5. * Copyright (C) Peter Maydell 05/1998 <pmaydell@chiark.greenend.org.uk>
  6. * Converted to driver model Jochen Friedrich <jochen@scram.de>
  7. *
  8. * The board IDs are from the NetBSD kernel, which for once provided
  9. * helpful comments...
  10. *
  11. * This goes with drivers/dio/dio.c
  12. */
  13. #ifndef _LINUX_DIO_H
  14. #define _LINUX_DIO_H
  15. /* The DIO boards in a system are distinguished by 'select codes' which
  16. * range from 0-63 (DIO) and 132-255 (DIO-II).
  17. * The DIO board with select code sc is located at physical address
  18. * 0x600000 + sc * 0x10000
  19. * So DIO cards cover [0x600000-0x800000); the areas [0x200000-0x400000) and
  20. * [0x800000-0x1000000) are for additional space required by things
  21. * like framebuffers. [0x400000-0x600000) is for miscellaneous internal I/O.
  22. * On Linux, this is currently all mapped into the virtual address space
  23. * at 0xf0000000 on bootup.
  24. * DIO-II boards are at 0x1000000 + (sc - 132) * 0x400000
  25. * which is address range [0x1000000-0x20000000) -- too big to map completely,
  26. * so currently we just don't handle DIO-II boards. It wouldn't be hard to
  27. * do with ioremap() though.
  28. */
  29. #include <linux/device.h>
  30. #ifdef __KERNEL__
  31. #include <asm/hp300hw.h>
  32. typedef __u16 dio_id;
  33. /*
  34. * DIO devices
  35. */
  36. struct dio_dev {
  37. struct dio_bus *bus;
  38. dio_id id;
  39. int scode;
  40. struct dio_driver *driver; /* which driver has allocated this device */
  41. struct device dev; /* Generic device interface */
  42. u8 ipl;
  43. char name[64];
  44. struct resource resource;
  45. };
  46. #define to_dio_dev(n) container_of(n, struct dio_dev, dev)
  47. /*
  48. * DIO bus
  49. */
  50. struct dio_bus {
  51. struct list_head devices; /* list of devices on this bus */
  52. unsigned int num_resources; /* number of resources */
  53. struct resource resources[2]; /* address space routed to this bus */
  54. struct device dev;
  55. char name[10];
  56. };
  57. extern struct dio_bus dio_bus; /* Single DIO bus */
  58. extern struct bus_type dio_bus_type;
  59. /*
  60. * DIO device IDs
  61. */
  62. struct dio_device_id {
  63. dio_id id; /* Device ID or DIO_WILDCARD */
  64. unsigned long driver_data; /* Data private to the driver */
  65. };
  66. /*
  67. * DIO device drivers
  68. */
  69. struct dio_driver {
  70. struct list_head node;
  71. char *name;
  72. const struct dio_device_id *id_table; /* NULL if wants all devices */
  73. int (*probe)(struct dio_dev *z, const struct dio_device_id *id);
  74. /* New device inserted */
  75. void (*remove)(struct dio_dev *z); /* Device removed (NULL if not a hot-plug capable driver) */
  76. struct device_driver driver;
  77. };
  78. #define to_dio_driver(drv) container_of(drv, struct dio_driver, driver)
  79. /* DIO/DIO-II boards all have the following 8bit registers.
  80. * These are offsets from the base of the device.
  81. */
  82. #define DIO_IDOFF 0x01 /* primary device ID */
  83. #define DIO_IPLOFF 0x03 /* interrupt priority level */
  84. #define DIO_SECIDOFF 0x15 /* secondary device ID */
  85. #define DIOII_SIZEOFF 0x101 /* device size, DIO-II only */
  86. #define DIO_VIRADDRBASE 0xf0000000UL /* vir addr where IOspace is mapped */
  87. #define DIO_BASE 0x600000 /* start of DIO space */
  88. #define DIO_END 0x1000000 /* end of DIO space */
  89. #define DIO_DEVSIZE 0x10000 /* size of a DIO device */
  90. #define DIOII_BASE 0x01000000 /* start of DIO-II space */
  91. #define DIOII_END 0x20000000 /* end of DIO-II space */
  92. #define DIOII_DEVSIZE 0x00400000 /* size of a DIO-II device */
  93. /* Highest valid select code. If we add DIO-II support this should become
  94. * 256 for everything except HP320, which only has DIO.
  95. */
  96. #define DIO_SCMAX (hp300_model == HP_320 ? 32 : 256)
  97. #define DIOII_SCBASE 132 /* lowest DIO-II select code */
  98. #define DIO_SCINHOLE(scode) (((scode) >= 32) && ((scode) < DIOII_SCBASE))
  99. #define DIO_ISDIOII(scode) ((scode) >= 132 && (scode) < 256)
  100. /* macros to read device IDs, given base address */
  101. #define DIO_ID(baseaddr) in_8((baseaddr) + DIO_IDOFF)
  102. #define DIO_SECID(baseaddr) in_8((baseaddr) + DIO_SECIDOFF)
  103. /* extract the interrupt level */
  104. #define DIO_IPL(baseaddr) (((in_8((baseaddr) + DIO_IPLOFF) >> 4) & 0x03) + 3)
  105. /* find the size of a DIO-II board's address space.
  106. * DIO boards are all fixed length.
  107. */
  108. #define DIOII_SIZE(baseaddr) ((in_8((baseaddr) + DIOII_SIZEOFF) + 1) * 0x100000)
  109. /* general purpose macro for both DIO and DIO-II */
  110. #define DIO_SIZE(scode, base) (DIO_ISDIOII((scode)) ? DIOII_SIZE((base)) : DIO_DEVSIZE)
  111. /* The hardware has primary and secondary IDs; we encode these in a single
  112. * int as PRIMARY ID & (SECONDARY ID << 8).
  113. * In practice this is only important for framebuffers,
  114. * and everybody else just sets ID fields equal to the DIO_ID_FOO value.
  115. */
  116. #define DIO_ENCODE_ID(pr,sec) ((((int)sec & 0xff) << 8) | ((int)pr & 0xff))
  117. /* macro to determine whether a given primary ID requires a secondary ID byte */
  118. #define DIO_NEEDSSECID(id) ((id) == DIO_ID_FBUFFER)
  119. #define DIO_WILDCARD 0xff
  120. /* Now a whole slew of macros giving device IDs and descriptive strings: */
  121. #define DIO_ID_DCA0 0x02 /* 98644A serial */
  122. #define DIO_DESC_DCA0 "98644A DCA0 serial"
  123. #define DIO_ID_DCA0REM 0x82 /* 98644A serial */
  124. #define DIO_DESC_DCA0REM "98644A DCA0REM serial"
  125. #define DIO_ID_DCA1 0x42 /* 98644A serial */
  126. #define DIO_DESC_DCA1 "98644A DCA1 serial"
  127. #define DIO_ID_DCA1REM 0xc2 /* 98644A serial */
  128. #define DIO_DESC_DCA1REM "98644A DCA1REM serial"
  129. #define DIO_ID_DCM 0x05 /* 98642A serial MUX */
  130. #define DIO_DESC_DCM "98642A DCM serial MUX"
  131. #define DIO_ID_DCMREM 0x85 /* 98642A serial MUX */
  132. #define DIO_DESC_DCMREM "98642A DCMREM serial MUX"
  133. #define DIO_ID_LAN 0x15 /* 98643A LAN */
  134. #define DIO_DESC_LAN "98643A LANCE ethernet"
  135. #define DIO_ID_FHPIB 0x08 /* 98625A/98625B fast HP-IB */
  136. #define DIO_DESC_FHPIB "98625A/98625B fast HPIB"
  137. #define DIO_ID_NHPIB 0x01 /* 98624A HP-IB (normal ie slow) */
  138. #define DIO_DESC_NHPIB "98624A HPIB"
  139. #define DIO_ID_SCSI0 0x07 /* 98265A SCSI */
  140. #define DIO_DESC_SCSI0 "98265A SCSI0"
  141. #define DIO_ID_SCSI1 0x27 /* ditto */
  142. #define DIO_DESC_SCSI1 "98265A SCSI1"
  143. #define DIO_ID_SCSI2 0x47 /* ditto */
  144. #define DIO_DESC_SCSI2 "98265A SCSI2"
  145. #define DIO_ID_SCSI3 0x67 /* ditto */
  146. #define DIO_DESC_SCSI3 "98265A SCSI3"
  147. #define DIO_ID_FBUFFER 0x39 /* framebuffer: flavour is distinguished by secondary ID */
  148. #define DIO_DESC_FBUFFER "bitmapped display"
  149. /* the NetBSD kernel source is a bit unsure as to what these next IDs actually do :-> */
  150. #define DIO_ID_MISC0 0x03 /* 98622A */
  151. #define DIO_DESC_MISC0 "98622A"
  152. #define DIO_ID_MISC1 0x04 /* 98623A */
  153. #define DIO_DESC_MISC1 "98623A"
  154. #define DIO_ID_PARALLEL 0x06 /* internal parallel */
  155. #define DIO_DESC_PARALLEL "internal parallel"
  156. #define DIO_ID_MISC2 0x09 /* 98287A keyboard */
  157. #define DIO_DESC_MISC2 "98287A keyboard"
  158. #define DIO_ID_MISC3 0x0a /* HP98635A FP accelerator */
  159. #define DIO_DESC_MISC3 "HP98635A FP accelerator"
  160. #define DIO_ID_MISC4 0x0b /* timer */
  161. #define DIO_DESC_MISC4 "timer"
  162. #define DIO_ID_MISC5 0x12 /* 98640A */
  163. #define DIO_DESC_MISC5 "98640A"
  164. #define DIO_ID_MISC6 0x16 /* 98659A */
  165. #define DIO_DESC_MISC6 "98659A"
  166. #define DIO_ID_MISC7 0x19 /* 237 display */
  167. #define DIO_DESC_MISC7 "237 display"
  168. #define DIO_ID_MISC8 0x1a /* quad-wide card */
  169. #define DIO_DESC_MISC8 "quad-wide card"
  170. #define DIO_ID_MISC9 0x1b /* 98253A */
  171. #define DIO_DESC_MISC9 "98253A"
  172. #define DIO_ID_MISC10 0x1c /* 98627A */
  173. #define DIO_DESC_MISC10 "98253A"
  174. #define DIO_ID_MISC11 0x1d /* 98633A */
  175. #define DIO_DESC_MISC11 "98633A"
  176. #define DIO_ID_MISC12 0x1e /* 98259A */
  177. #define DIO_DESC_MISC12 "98259A"
  178. #define DIO_ID_MISC13 0x1f /* 8741 */
  179. #define DIO_DESC_MISC13 "8741"
  180. #define DIO_ID_VME 0x31 /* 98577A VME adapter */
  181. #define DIO_DESC_VME "98577A VME adapter"
  182. #define DIO_ID_DCL 0x34 /* 98628A serial */
  183. #define DIO_DESC_DCL "98628A DCL serial"
  184. #define DIO_ID_DCLREM 0xb4 /* 98628A serial */
  185. #define DIO_DESC_DCLREM "98628A DCLREM serial"
  186. /* These are the secondary IDs for the framebuffers */
  187. #define DIO_ID2_GATORBOX 0x01 /* 98700/98710 "gatorbox" */
  188. #define DIO_DESC2_GATORBOX "98700/98710 \"gatorbox\" display"
  189. #define DIO_ID2_TOPCAT 0x02 /* 98544/98545/98547 "topcat" */
  190. #define DIO_DESC2_TOPCAT "98544/98545/98547 \"topcat\" display"
  191. #define DIO_ID2_RENAISSANCE 0x04 /* 98720/98721 "renaissance" */
  192. #define DIO_DESC2_RENAISSANCE "98720/98721 \"renaissance\" display"
  193. #define DIO_ID2_LRCATSEYE 0x05 /* lowres "catseye" */
  194. #define DIO_DESC2_LRCATSEYE "low-res catseye display"
  195. #define DIO_ID2_HRCCATSEYE 0x06 /* highres colour "catseye" */
  196. #define DIO_DESC2_HRCCATSEYE "high-res color catseye display"
  197. #define DIO_ID2_HRMCATSEYE 0x07 /* highres mono "catseye" */
  198. #define DIO_DESC2_HRMCATSEYE "high-res mono catseye display"
  199. #define DIO_ID2_DAVINCI 0x08 /* 98730/98731 "davinci" */
  200. #define DIO_DESC2_DAVINCI "98730/98731 \"davinci\" display"
  201. #define DIO_ID2_XXXCATSEYE 0x09 /* "catseye" */
  202. #define DIO_DESC2_XXXCATSEYE "catseye display"
  203. #define DIO_ID2_HYPERION 0x0e /* A1096A "hyperion" */
  204. #define DIO_DESC2_HYPERION "A1096A \"hyperion\" display"
  205. #define DIO_ID2_XGENESIS 0x0b /* "x-genesis"; no NetBSD support */
  206. #define DIO_DESC2_XGENESIS "\"x-genesis\" display"
  207. #define DIO_ID2_TIGER 0x0c /* "tiger"; no NetBSD support */
  208. #define DIO_DESC2_TIGER "\"tiger\" display"
  209. #define DIO_ID2_YGENESIS 0x0d /* "y-genesis"; no NetBSD support */
  210. #define DIO_DESC2_YGENESIS "\"y-genesis\" display"
  211. /* if you add new IDs then you should tell dio.c about them so it can
  212. * identify them...
  213. */
  214. extern int dio_find(int deviceid);
  215. extern unsigned long dio_scodetophysaddr(int scode);
  216. extern void dio_create_sysfs_dev_files(struct dio_dev *);
  217. /* New-style probing */
  218. extern int dio_register_driver(struct dio_driver *);
  219. extern void dio_unregister_driver(struct dio_driver *);
  220. extern const struct dio_device_id *dio_match_device(const struct dio_device_id *ids, const struct dio_dev *z);
  221. static inline struct dio_driver *dio_dev_driver(const struct dio_dev *d)
  222. {
  223. return d->driver;
  224. }
  225. #define dio_resource_start(d) ((d)->resource.start)
  226. #define dio_resource_end(d) ((d)->resource.end)
  227. #define dio_resource_len(d) ((d)->resource.end-(d)->resource.start+1)
  228. #define dio_resource_flags(d) ((d)->resource.flags)
  229. #define dio_request_device(d, name) \
  230. request_mem_region(dio_resource_start(d), dio_resource_len(d), name)
  231. #define dio_release_device(d) \
  232. release_mem_region(dio_resource_start(d), dio_resource_len(d))
  233. /* Similar to the helpers above, these manipulate per-dio_dev
  234. * driver-specific data. They are really just a wrapper around
  235. * the generic device structure functions of these calls.
  236. */
  237. static inline void *dio_get_drvdata (struct dio_dev *d)
  238. {
  239. return dev_get_drvdata(&d->dev);
  240. }
  241. static inline void dio_set_drvdata (struct dio_dev *d, void *data)
  242. {
  243. dev_set_drvdata(&d->dev, data);
  244. }
  245. #endif /* __KERNEL__ */
  246. #endif /* ndef _LINUX_DIO_H */