bus.h 4.8 KB

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