bus.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * linux/include/amba/bus.h
  4. *
  5. * This device type deals with ARM PrimeCells and anything else that
  6. * presents a proper CID (0xB105F00D) at the end of the I/O register
  7. * region or that is derived from a PrimeCell.
  8. *
  9. * Copyright (C) 2003 Deep Blue Solutions Ltd, All Rights Reserved.
  10. */
  11. #ifndef ASMARM_AMBA_H
  12. #define ASMARM_AMBA_H
  13. #include <linux/clk.h>
  14. #include <linux/device.h>
  15. #include <linux/mod_devicetable.h>
  16. #include <linux/err.h>
  17. #include <linux/resource.h>
  18. #include <linux/regulator/consumer.h>
  19. #include <linux/android_kabi.h>
  20. #define AMBA_NR_IRQS 9
  21. #define AMBA_CID 0xb105f00d
  22. #define CORESIGHT_CID 0xb105900d
  23. /*
  24. * CoreSight Architecture specification updates the ID specification
  25. * for components on the AMBA bus. (ARM IHI 0029E)
  26. *
  27. * Bits 15:12 of the CID are the device class.
  28. *
  29. * Class 0xF remains for PrimeCell and legacy components. (AMBA_CID above)
  30. * Class 0x9 defines the component as CoreSight (CORESIGHT_CID above)
  31. * Class 0x0, 0x1, 0xB, 0xE define components that do not have driver support
  32. * at present.
  33. * Class 0x2-0x8,0xA and 0xD-0xD are presently reserved.
  34. *
  35. * Remaining CID bits stay as 0xb105-00d
  36. */
  37. /**
  38. * Class 0x9 components use additional values to form a Unique Component
  39. * Identifier (UCI), where peripheral ID values are identical for different
  40. * components. Passed to the amba bus code from the component driver via
  41. * the amba_id->data pointer.
  42. * @devarch : coresight devarch register value
  43. * @devarch_mask: mask bits used for matching. 0 indicates UCI not used.
  44. * @devtype : coresight device type value
  45. * @data : additional driver data. As we have usurped the original
  46. * pointer some devices may still need additional data
  47. */
  48. struct amba_cs_uci_id {
  49. unsigned int devarch;
  50. unsigned int devarch_mask;
  51. unsigned int devtype;
  52. void *data;
  53. };
  54. /* define offsets for registers used by UCI */
  55. #define UCI_REG_DEVTYPE_OFFSET 0xFCC
  56. #define UCI_REG_DEVARCH_OFFSET 0xFBC
  57. struct clk;
  58. struct amba_device {
  59. struct device dev;
  60. struct resource res;
  61. struct clk *pclk;
  62. struct device_dma_parameters dma_parms;
  63. unsigned int periphid;
  64. struct mutex periphid_lock;
  65. unsigned int cid;
  66. struct amba_cs_uci_id uci;
  67. unsigned int irq[AMBA_NR_IRQS];
  68. /*
  69. * Driver name to force a match. Do not set directly, because core
  70. * frees it. Use driver_set_override() to set or clear it.
  71. */
  72. const char *driver_override;
  73. ANDROID_KABI_RESERVE(1);
  74. };
  75. struct amba_driver {
  76. struct device_driver drv;
  77. int (*probe)(struct amba_device *, const struct amba_id *);
  78. void (*remove)(struct amba_device *);
  79. void (*shutdown)(struct amba_device *);
  80. const struct amba_id *id_table;
  81. /*
  82. * For most device drivers, no need to care about this flag as long as
  83. * all DMAs are handled through the kernel DMA API. For some special
  84. * ones, for example VFIO drivers, they know how to manage the DMA
  85. * themselves and set this flag so that the IOMMU layer will allow them
  86. * to setup and manage their own I/O address space.
  87. */
  88. bool driver_managed_dma;
  89. ANDROID_KABI_RESERVE(1);
  90. };
  91. /*
  92. * Constants for the designer field of the Peripheral ID register. When bit 7
  93. * is set to '1', bits [6:0] should be the JEP106 manufacturer identity code.
  94. */
  95. enum amba_vendor {
  96. AMBA_VENDOR_ARM = 0x41,
  97. AMBA_VENDOR_ST = 0x80,
  98. AMBA_VENDOR_QCOM = 0x51,
  99. AMBA_VENDOR_LSI = 0xb6,
  100. };
  101. extern struct bus_type amba_bustype;
  102. #define to_amba_device(d) container_of(d, struct amba_device, dev)
  103. #define amba_get_drvdata(d) dev_get_drvdata(&d->dev)
  104. #define amba_set_drvdata(d,p) dev_set_drvdata(&d->dev, p)
  105. #ifdef CONFIG_ARM_AMBA
  106. int amba_driver_register(struct amba_driver *);
  107. void amba_driver_unregister(struct amba_driver *);
  108. #else
  109. static inline int amba_driver_register(struct amba_driver *drv)
  110. {
  111. return -EINVAL;
  112. }
  113. static inline void amba_driver_unregister(struct amba_driver *drv)
  114. {
  115. }
  116. #endif
  117. struct amba_device *amba_device_alloc(const char *, resource_size_t, size_t);
  118. void amba_device_put(struct amba_device *);
  119. int amba_device_add(struct amba_device *, struct resource *);
  120. int amba_device_register(struct amba_device *, struct resource *);
  121. void amba_device_unregister(struct amba_device *);
  122. int amba_request_regions(struct amba_device *, const char *);
  123. void amba_release_regions(struct amba_device *);
  124. /* Some drivers don't use the struct amba_device */
  125. #define AMBA_CONFIG_BITS(a) (((a) >> 24) & 0xff)
  126. #define AMBA_REV_BITS(a) (((a) >> 20) & 0x0f)
  127. #define AMBA_MANF_BITS(a) (((a) >> 12) & 0xff)
  128. #define AMBA_PART_BITS(a) ((a) & 0xfff)
  129. #define amba_config(d) AMBA_CONFIG_BITS((d)->periphid)
  130. #define amba_rev(d) AMBA_REV_BITS((d)->periphid)
  131. #define amba_manf(d) AMBA_MANF_BITS((d)->periphid)
  132. #define amba_part(d) AMBA_PART_BITS((d)->periphid)
  133. #define __AMBA_DEV(busid, data, mask) \
  134. { \
  135. .coherent_dma_mask = mask, \
  136. .init_name = busid, \
  137. .platform_data = data, \
  138. }
  139. /*
  140. * APB devices do not themselves have the ability to address memory,
  141. * so DMA masks should be zero (much like USB peripheral devices.)
  142. * The DMA controller DMA masks should be used instead (much like
  143. * USB host controllers in conventional PCs.)
  144. */
  145. #define AMBA_APB_DEVICE(name, busid, id, base, irqs, data) \
  146. struct amba_device name##_device = { \
  147. .dev = __AMBA_DEV(busid, data, 0), \
  148. .res = DEFINE_RES_MEM(base, SZ_4K), \
  149. .irq = irqs, \
  150. .periphid = id, \
  151. }
  152. /*
  153. * AHB devices are DMA capable, so set their DMA masks
  154. */
  155. #define AMBA_AHB_DEVICE(name, busid, id, base, irqs, data) \
  156. struct amba_device name##_device = { \
  157. .dev = __AMBA_DEV(busid, data, ~0ULL), \
  158. .res = DEFINE_RES_MEM(base, SZ_4K), \
  159. .irq = irqs, \
  160. .periphid = id, \
  161. }
  162. /*
  163. * module_amba_driver() - Helper macro for drivers that don't do anything
  164. * special in module init/exit. This eliminates a lot of boilerplate. Each
  165. * module may only use this macro once, and calling it replaces module_init()
  166. * and module_exit()
  167. */
  168. #define module_amba_driver(__amba_drv) \
  169. module_driver(__amba_drv, amba_driver_register, amba_driver_unregister)
  170. /*
  171. * builtin_amba_driver() - Helper macro for drivers that don't do anything
  172. * special in driver initcall. This eliminates a lot of boilerplate. Each
  173. * driver may only use this macro once, and calling it replaces the instance
  174. * device_initcall().
  175. */
  176. #define builtin_amba_driver(__amba_drv) \
  177. builtin_driver(__amba_drv, amba_driver_register)
  178. #endif