bus.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * linux/include/amba/bus.h
  3. *
  4. * This device type deals with ARM PrimeCells and anything else that
  5. * presents a proper CID (0xB105F00D) at the end of the I/O register
  6. * region or that is derived from a PrimeCell.
  7. *
  8. * Copyright (C) 2003 Deep Blue Solutions Ltd, All Rights Reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #ifndef ASMARM_AMBA_H
  15. #define ASMARM_AMBA_H
  16. #include <linux/clk.h>
  17. #include <linux/device.h>
  18. #include <linux/mod_devicetable.h>
  19. #include <linux/err.h>
  20. #include <linux/resource.h>
  21. #include <linux/regulator/consumer.h>
  22. #define AMBA_NR_IRQS 9
  23. #define AMBA_CID 0xb105f00d
  24. #define CORESIGHT_CID 0xb105900d
  25. struct clk;
  26. struct amba_device {
  27. struct device dev;
  28. struct resource res;
  29. struct clk *pclk;
  30. unsigned int periphid;
  31. unsigned int irq[AMBA_NR_IRQS];
  32. char *driver_override;
  33. };
  34. struct amba_driver {
  35. struct device_driver drv;
  36. int (*probe)(struct amba_device *, const struct amba_id *);
  37. int (*remove)(struct amba_device *);
  38. void (*shutdown)(struct amba_device *);
  39. const struct amba_id *id_table;
  40. };
  41. /*
  42. * Constants for the designer field of the Peripheral ID register. When bit 7
  43. * is set to '1', bits [6:0] should be the JEP106 manufacturer identity code.
  44. */
  45. enum amba_vendor {
  46. AMBA_VENDOR_ARM = 0x41,
  47. AMBA_VENDOR_ST = 0x80,
  48. AMBA_VENDOR_QCOM = 0x51,
  49. AMBA_VENDOR_LSI = 0xb6,
  50. AMBA_VENDOR_LINUX = 0xfe, /* This value is not official */
  51. };
  52. /* This is used to generate pseudo-ID for AMBA device */
  53. #define AMBA_LINUX_ID(conf, rev, part) \
  54. (((conf) & 0xff) << 24 | ((rev) & 0xf) << 20 | \
  55. AMBA_VENDOR_LINUX << 12 | ((part) & 0xfff))
  56. extern struct bus_type amba_bustype;
  57. #define to_amba_device(d) container_of(d, struct amba_device, dev)
  58. #define amba_get_drvdata(d) dev_get_drvdata(&d->dev)
  59. #define amba_set_drvdata(d,p) dev_set_drvdata(&d->dev, p)
  60. int amba_driver_register(struct amba_driver *);
  61. void amba_driver_unregister(struct amba_driver *);
  62. struct amba_device *amba_device_alloc(const char *, resource_size_t, size_t);
  63. void amba_device_put(struct amba_device *);
  64. int amba_device_add(struct amba_device *, struct resource *);
  65. int amba_device_register(struct amba_device *, struct resource *);
  66. struct amba_device *amba_apb_device_add(struct device *parent, const char *name,
  67. resource_size_t base, size_t size,
  68. int irq1, int irq2, void *pdata,
  69. unsigned int periphid);
  70. struct amba_device *amba_ahb_device_add(struct device *parent, const char *name,
  71. resource_size_t base, size_t size,
  72. int irq1, int irq2, void *pdata,
  73. unsigned int periphid);
  74. struct amba_device *
  75. amba_apb_device_add_res(struct device *parent, const char *name,
  76. resource_size_t base, size_t size, int irq1,
  77. int irq2, void *pdata, unsigned int periphid,
  78. struct resource *resbase);
  79. struct amba_device *
  80. amba_ahb_device_add_res(struct device *parent, const char *name,
  81. resource_size_t base, size_t size, int irq1,
  82. int irq2, void *pdata, unsigned int periphid,
  83. struct resource *resbase);
  84. void amba_device_unregister(struct amba_device *);
  85. struct amba_device *amba_find_device(const char *, struct device *, unsigned int, unsigned int);
  86. int amba_request_regions(struct amba_device *, const char *);
  87. void amba_release_regions(struct amba_device *);
  88. static inline int amba_pclk_enable(struct amba_device *dev)
  89. {
  90. return clk_enable(dev->pclk);
  91. }
  92. static inline void amba_pclk_disable(struct amba_device *dev)
  93. {
  94. clk_disable(dev->pclk);
  95. }
  96. static inline int amba_pclk_prepare(struct amba_device *dev)
  97. {
  98. return clk_prepare(dev->pclk);
  99. }
  100. static inline void amba_pclk_unprepare(struct amba_device *dev)
  101. {
  102. clk_unprepare(dev->pclk);
  103. }
  104. /* Some drivers don't use the struct amba_device */
  105. #define AMBA_CONFIG_BITS(a) (((a) >> 24) & 0xff)
  106. #define AMBA_REV_BITS(a) (((a) >> 20) & 0x0f)
  107. #define AMBA_MANF_BITS(a) (((a) >> 12) & 0xff)
  108. #define AMBA_PART_BITS(a) ((a) & 0xfff)
  109. #define amba_config(d) AMBA_CONFIG_BITS((d)->periphid)
  110. #define amba_rev(d) AMBA_REV_BITS((d)->periphid)
  111. #define amba_manf(d) AMBA_MANF_BITS((d)->periphid)
  112. #define amba_part(d) AMBA_PART_BITS((d)->periphid)
  113. #define __AMBA_DEV(busid, data, mask) \
  114. { \
  115. .coherent_dma_mask = mask, \
  116. .init_name = busid, \
  117. .platform_data = data, \
  118. }
  119. /*
  120. * APB devices do not themselves have the ability to address memory,
  121. * so DMA masks should be zero (much like USB peripheral devices.)
  122. * The DMA controller DMA masks should be used instead (much like
  123. * USB host controllers in conventional PCs.)
  124. */
  125. #define AMBA_APB_DEVICE(name, busid, id, base, irqs, data) \
  126. struct amba_device name##_device = { \
  127. .dev = __AMBA_DEV(busid, data, 0), \
  128. .res = DEFINE_RES_MEM(base, SZ_4K), \
  129. .irq = irqs, \
  130. .periphid = id, \
  131. }
  132. /*
  133. * AHB devices are DMA capable, so set their DMA masks
  134. */
  135. #define AMBA_AHB_DEVICE(name, busid, id, base, irqs, data) \
  136. struct amba_device name##_device = { \
  137. .dev = __AMBA_DEV(busid, data, ~0ULL), \
  138. .res = DEFINE_RES_MEM(base, SZ_4K), \
  139. .irq = irqs, \
  140. .periphid = id, \
  141. }
  142. /*
  143. * module_amba_driver() - Helper macro for drivers that don't do anything
  144. * special in module init/exit. This eliminates a lot of boilerplate. Each
  145. * module may only use this macro once, and calling it replaces module_init()
  146. * and module_exit()
  147. */
  148. #define module_amba_driver(__amba_drv) \
  149. module_driver(__amba_drv, amba_driver_register, amba_driver_unregister)
  150. /*
  151. * builtin_amba_driver() - Helper macro for drivers that don't do anything
  152. * special in driver initcall. This eliminates a lot of boilerplate. Each
  153. * driver may only use this macro once, and calling it replaces the instance
  154. * device_initcall().
  155. */
  156. #define builtin_amba_driver(__amba_drv) \
  157. builtin_driver(__amba_drv, amba_driver_register)
  158. #endif