bus.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. unsigned int cid;
  65. struct amba_cs_uci_id uci;
  66. unsigned int irq[AMBA_NR_IRQS];
  67. char *driver_override;
  68. ANDROID_KABI_RESERVE(1);
  69. };
  70. struct amba_driver {
  71. struct device_driver drv;
  72. int (*probe)(struct amba_device *, const struct amba_id *);
  73. void (*remove)(struct amba_device *);
  74. void (*shutdown)(struct amba_device *);
  75. const struct amba_id *id_table;
  76. ANDROID_KABI_RESERVE(1);
  77. };
  78. /*
  79. * Constants for the designer field of the Peripheral ID register. When bit 7
  80. * is set to '1', bits [6:0] should be the JEP106 manufacturer identity code.
  81. */
  82. enum amba_vendor {
  83. AMBA_VENDOR_ARM = 0x41,
  84. AMBA_VENDOR_ST = 0x80,
  85. AMBA_VENDOR_QCOM = 0x51,
  86. AMBA_VENDOR_LSI = 0xb6,
  87. AMBA_VENDOR_LINUX = 0xfe, /* This value is not official */
  88. };
  89. /* This is used to generate pseudo-ID for AMBA device */
  90. #define AMBA_LINUX_ID(conf, rev, part) \
  91. (((conf) & 0xff) << 24 | ((rev) & 0xf) << 20 | \
  92. AMBA_VENDOR_LINUX << 12 | ((part) & 0xfff))
  93. extern struct bus_type amba_bustype;
  94. #define to_amba_device(d) container_of(d, struct amba_device, dev)
  95. #define amba_get_drvdata(d) dev_get_drvdata(&d->dev)
  96. #define amba_set_drvdata(d,p) dev_set_drvdata(&d->dev, p)
  97. int amba_driver_register(struct amba_driver *);
  98. void amba_driver_unregister(struct amba_driver *);
  99. struct amba_device *amba_device_alloc(const char *, resource_size_t, size_t);
  100. void amba_device_put(struct amba_device *);
  101. int amba_device_add(struct amba_device *, struct resource *);
  102. int amba_device_register(struct amba_device *, struct resource *);
  103. struct amba_device *amba_apb_device_add(struct device *parent, const char *name,
  104. resource_size_t base, size_t size,
  105. int irq1, int irq2, void *pdata,
  106. unsigned int periphid);
  107. struct amba_device *amba_ahb_device_add(struct device *parent, const char *name,
  108. resource_size_t base, size_t size,
  109. int irq1, int irq2, void *pdata,
  110. unsigned int periphid);
  111. struct amba_device *
  112. amba_apb_device_add_res(struct device *parent, const char *name,
  113. resource_size_t base, size_t size, int irq1,
  114. int irq2, void *pdata, unsigned int periphid,
  115. struct resource *resbase);
  116. struct amba_device *
  117. amba_ahb_device_add_res(struct device *parent, const char *name,
  118. resource_size_t base, size_t size, int irq1,
  119. int irq2, void *pdata, unsigned int periphid,
  120. struct resource *resbase);
  121. void amba_device_unregister(struct amba_device *);
  122. struct amba_device *amba_find_device(const char *, struct device *, unsigned int, unsigned int);
  123. int amba_request_regions(struct amba_device *, const char *);
  124. void amba_release_regions(struct amba_device *);
  125. static inline int amba_pclk_enable(struct amba_device *dev)
  126. {
  127. return clk_enable(dev->pclk);
  128. }
  129. static inline void amba_pclk_disable(struct amba_device *dev)
  130. {
  131. clk_disable(dev->pclk);
  132. }
  133. static inline int amba_pclk_prepare(struct amba_device *dev)
  134. {
  135. return clk_prepare(dev->pclk);
  136. }
  137. static inline void amba_pclk_unprepare(struct amba_device *dev)
  138. {
  139. clk_unprepare(dev->pclk);
  140. }
  141. /* Some drivers don't use the struct amba_device */
  142. #define AMBA_CONFIG_BITS(a) (((a) >> 24) & 0xff)
  143. #define AMBA_REV_BITS(a) (((a) >> 20) & 0x0f)
  144. #define AMBA_MANF_BITS(a) (((a) >> 12) & 0xff)
  145. #define AMBA_PART_BITS(a) ((a) & 0xfff)
  146. #define amba_config(d) AMBA_CONFIG_BITS((d)->periphid)
  147. #define amba_rev(d) AMBA_REV_BITS((d)->periphid)
  148. #define amba_manf(d) AMBA_MANF_BITS((d)->periphid)
  149. #define amba_part(d) AMBA_PART_BITS((d)->periphid)
  150. #define __AMBA_DEV(busid, data, mask) \
  151. { \
  152. .coherent_dma_mask = mask, \
  153. .init_name = busid, \
  154. .platform_data = data, \
  155. }
  156. /*
  157. * APB devices do not themselves have the ability to address memory,
  158. * so DMA masks should be zero (much like USB peripheral devices.)
  159. * The DMA controller DMA masks should be used instead (much like
  160. * USB host controllers in conventional PCs.)
  161. */
  162. #define AMBA_APB_DEVICE(name, busid, id, base, irqs, data) \
  163. struct amba_device name##_device = { \
  164. .dev = __AMBA_DEV(busid, data, 0), \
  165. .res = DEFINE_RES_MEM(base, SZ_4K), \
  166. .irq = irqs, \
  167. .periphid = id, \
  168. }
  169. /*
  170. * AHB devices are DMA capable, so set their DMA masks
  171. */
  172. #define AMBA_AHB_DEVICE(name, busid, id, base, irqs, data) \
  173. struct amba_device name##_device = { \
  174. .dev = __AMBA_DEV(busid, data, ~0ULL), \
  175. .res = DEFINE_RES_MEM(base, SZ_4K), \
  176. .irq = irqs, \
  177. .periphid = id, \
  178. }
  179. /*
  180. * module_amba_driver() - Helper macro for drivers that don't do anything
  181. * special in module init/exit. This eliminates a lot of boilerplate. Each
  182. * module may only use this macro once, and calling it replaces module_init()
  183. * and module_exit()
  184. */
  185. #define module_amba_driver(__amba_drv) \
  186. module_driver(__amba_drv, amba_driver_register, amba_driver_unregister)
  187. /*
  188. * builtin_amba_driver() - Helper macro for drivers that don't do anything
  189. * special in driver initcall. This eliminates a lot of boilerplate. Each
  190. * driver may only use this macro once, and calling it replaces the instance
  191. * device_initcall().
  192. */
  193. #define builtin_amba_driver(__amba_drv) \
  194. builtin_driver(__amba_drv, amba_driver_register)
  195. #endif