bus.h 4.2 KB

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