bus.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. struct clk;
  25. struct amba_device {
  26. struct device dev;
  27. struct resource res;
  28. struct clk *pclk;
  29. unsigned int periphid;
  30. unsigned int irq[AMBA_NR_IRQS];
  31. };
  32. struct amba_driver {
  33. struct device_driver drv;
  34. int (*probe)(struct amba_device *, const struct amba_id *);
  35. int (*remove)(struct amba_device *);
  36. void (*shutdown)(struct amba_device *);
  37. int (*suspend)(struct amba_device *, pm_message_t);
  38. int (*resume)(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. };
  51. extern struct bus_type amba_bustype;
  52. #define to_amba_device(d) container_of(d, struct amba_device, dev)
  53. #define amba_get_drvdata(d) dev_get_drvdata(&d->dev)
  54. #define amba_set_drvdata(d,p) dev_set_drvdata(&d->dev, p)
  55. int amba_driver_register(struct amba_driver *);
  56. void amba_driver_unregister(struct amba_driver *);
  57. struct amba_device *amba_device_alloc(const char *, resource_size_t, size_t);
  58. void amba_device_put(struct amba_device *);
  59. int amba_device_add(struct amba_device *, struct resource *);
  60. int amba_device_register(struct amba_device *, struct resource *);
  61. struct amba_device *amba_apb_device_add(struct device *parent, const char *name,
  62. resource_size_t base, size_t size,
  63. int irq1, int irq2, void *pdata,
  64. unsigned int periphid);
  65. struct amba_device *amba_ahb_device_add(struct device *parent, const char *name,
  66. resource_size_t base, size_t size,
  67. int irq1, int irq2, void *pdata,
  68. unsigned int periphid);
  69. struct amba_device *
  70. amba_apb_device_add_res(struct device *parent, const char *name,
  71. resource_size_t base, size_t size, int irq1,
  72. int irq2, void *pdata, unsigned int periphid,
  73. struct resource *resbase);
  74. struct amba_device *
  75. amba_ahb_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. void amba_device_unregister(struct amba_device *);
  80. struct amba_device *amba_find_device(const char *, struct device *, unsigned int, unsigned int);
  81. int amba_request_regions(struct amba_device *, const char *);
  82. void amba_release_regions(struct amba_device *);
  83. #define amba_pclk_enable(d) \
  84. (IS_ERR((d)->pclk) ? 0 : clk_enable((d)->pclk))
  85. #define amba_pclk_disable(d) \
  86. do { if (!IS_ERR((d)->pclk)) clk_disable((d)->pclk); } while (0)
  87. /* Some drivers don't use the struct amba_device */
  88. #define AMBA_CONFIG_BITS(a) (((a) >> 24) & 0xff)
  89. #define AMBA_REV_BITS(a) (((a) >> 20) & 0x0f)
  90. #define AMBA_MANF_BITS(a) (((a) >> 12) & 0xff)
  91. #define AMBA_PART_BITS(a) ((a) & 0xfff)
  92. #define amba_config(d) AMBA_CONFIG_BITS((d)->periphid)
  93. #define amba_rev(d) AMBA_REV_BITS((d)->periphid)
  94. #define amba_manf(d) AMBA_MANF_BITS((d)->periphid)
  95. #define amba_part(d) AMBA_PART_BITS((d)->periphid)
  96. #define __AMBA_DEV(busid, data, mask) \
  97. { \
  98. .coherent_dma_mask = mask, \
  99. .init_name = busid, \
  100. .platform_data = data, \
  101. }
  102. /*
  103. * APB devices do not themselves have the ability to address memory,
  104. * so DMA masks should be zero (much like USB peripheral devices.)
  105. * The DMA controller DMA masks should be used instead (much like
  106. * USB host controllers in conventional PCs.)
  107. */
  108. #define AMBA_APB_DEVICE(name, busid, id, base, irqs, data) \
  109. struct amba_device name##_device = { \
  110. .dev = __AMBA_DEV(busid, data, 0), \
  111. .res = DEFINE_RES_MEM(base, SZ_4K), \
  112. .irq = irqs, \
  113. .periphid = id, \
  114. }
  115. /*
  116. * AHB devices are DMA capable, so set their DMA masks
  117. */
  118. #define AMBA_AHB_DEVICE(name, busid, id, base, irqs, data) \
  119. struct amba_device name##_device = { \
  120. .dev = __AMBA_DEV(busid, data, ~0ULL), \
  121. .res = DEFINE_RES_MEM(base, SZ_4K), \
  122. .irq = irqs, \
  123. .periphid = id, \
  124. }
  125. /*
  126. * module_amba_driver() - Helper macro for drivers that don't do anything
  127. * special in module init/exit. This eliminates a lot of boilerplate. Each
  128. * module may only use this macro once, and calling it replaces module_init()
  129. * and module_exit()
  130. */
  131. #define module_amba_driver(__amba_drv) \
  132. module_driver(__amba_drv, amba_driver_register, amba_driver_unregister)
  133. #endif