macio.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #ifndef __MACIO_ASIC_H__
  2. #define __MACIO_ASIC_H__
  3. #ifdef __KERNEL__
  4. #include <linux/of_device.h>
  5. extern struct bus_type macio_bus_type;
  6. /* MacIO device driver is defined later */
  7. struct macio_driver;
  8. struct macio_chip;
  9. #define MACIO_DEV_COUNT_RESOURCES 8
  10. #define MACIO_DEV_COUNT_IRQS 8
  11. /*
  12. * the macio_bus structure is used to describe a "virtual" bus
  13. * within a MacIO ASIC. It's typically provided by a macio_pci_asic
  14. * PCI device, but could be provided differently as well (nubus
  15. * machines using a fake OF tree).
  16. *
  17. * The pdev field can be NULL on non-PCI machines
  18. */
  19. struct macio_bus
  20. {
  21. struct macio_chip *chip; /* macio_chip (private use) */
  22. int index; /* macio chip index in system */
  23. #ifdef CONFIG_PCI
  24. struct pci_dev *pdev; /* PCI device hosting this bus */
  25. #endif
  26. };
  27. /*
  28. * the macio_dev structure is used to describe a device
  29. * within an Apple MacIO ASIC.
  30. */
  31. struct macio_dev
  32. {
  33. struct macio_bus *bus; /* macio bus this device is on */
  34. struct macio_dev *media_bay; /* Device is part of a media bay */
  35. struct platform_device ofdev;
  36. struct device_dma_parameters dma_parms; /* ide needs that */
  37. int n_resources;
  38. struct resource resource[MACIO_DEV_COUNT_RESOURCES];
  39. int n_interrupts;
  40. struct resource interrupt[MACIO_DEV_COUNT_IRQS];
  41. };
  42. #define to_macio_device(d) container_of(d, struct macio_dev, ofdev.dev)
  43. #define of_to_macio_device(d) container_of(d, struct macio_dev, ofdev)
  44. extern struct macio_dev *macio_dev_get(struct macio_dev *dev);
  45. extern void macio_dev_put(struct macio_dev *dev);
  46. /*
  47. * Accessors to resources & interrupts and other device
  48. * fields
  49. */
  50. static inline int macio_resource_count(struct macio_dev *dev)
  51. {
  52. return dev->n_resources;
  53. }
  54. static inline unsigned long macio_resource_start(struct macio_dev *dev, int resource_no)
  55. {
  56. return dev->resource[resource_no].start;
  57. }
  58. static inline unsigned long macio_resource_end(struct macio_dev *dev, int resource_no)
  59. {
  60. return dev->resource[resource_no].end;
  61. }
  62. static inline unsigned long macio_resource_len(struct macio_dev *dev, int resource_no)
  63. {
  64. struct resource *res = &dev->resource[resource_no];
  65. if (res->start == 0 || res->end == 0 || res->end < res->start)
  66. return 0;
  67. return resource_size(res);
  68. }
  69. extern int macio_enable_devres(struct macio_dev *dev);
  70. extern int macio_request_resource(struct macio_dev *dev, int resource_no, const char *name);
  71. extern void macio_release_resource(struct macio_dev *dev, int resource_no);
  72. extern int macio_request_resources(struct macio_dev *dev, const char *name);
  73. extern void macio_release_resources(struct macio_dev *dev);
  74. static inline int macio_irq_count(struct macio_dev *dev)
  75. {
  76. return dev->n_interrupts;
  77. }
  78. static inline int macio_irq(struct macio_dev *dev, int irq_no)
  79. {
  80. return dev->interrupt[irq_no].start;
  81. }
  82. static inline void macio_set_drvdata(struct macio_dev *dev, void *data)
  83. {
  84. dev_set_drvdata(&dev->ofdev.dev, data);
  85. }
  86. static inline void* macio_get_drvdata(struct macio_dev *dev)
  87. {
  88. return dev_get_drvdata(&dev->ofdev.dev);
  89. }
  90. static inline struct device_node *macio_get_of_node(struct macio_dev *mdev)
  91. {
  92. return mdev->ofdev.dev.of_node;
  93. }
  94. #ifdef CONFIG_PCI
  95. static inline struct pci_dev *macio_get_pci_dev(struct macio_dev *mdev)
  96. {
  97. return mdev->bus->pdev;
  98. }
  99. #endif
  100. /*
  101. * A driver for a mac-io chip based device
  102. */
  103. struct macio_driver
  104. {
  105. int (*probe)(struct macio_dev* dev, const struct of_device_id *match);
  106. int (*remove)(struct macio_dev* dev);
  107. int (*suspend)(struct macio_dev* dev, pm_message_t state);
  108. int (*resume)(struct macio_dev* dev);
  109. int (*shutdown)(struct macio_dev* dev);
  110. #ifdef CONFIG_PMAC_MEDIABAY
  111. void (*mediabay_event)(struct macio_dev* dev, int mb_state);
  112. #endif
  113. struct device_driver driver;
  114. };
  115. #define to_macio_driver(drv) container_of(drv,struct macio_driver, driver)
  116. extern int macio_register_driver(struct macio_driver *);
  117. extern void macio_unregister_driver(struct macio_driver *);
  118. #endif /* __KERNEL__ */
  119. #endif /* __MACIO_ASIC_H__ */