1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __MACIO_ASIC_H__
3 #define __MACIO_ASIC_H__
7 #include <linux/platform_device.h>
9 extern const struct bus_type macio_bus_type
;
11 /* MacIO device driver is defined later */
15 #define MACIO_DEV_COUNT_RESOURCES 8
16 #define MACIO_DEV_COUNT_IRQS 8
19 * the macio_bus structure is used to describe a "virtual" bus
20 * within a MacIO ASIC. It's typically provided by a macio_pci_asic
21 * PCI device, but could be provided differently as well (nubus
22 * machines using a fake OF tree).
24 * The pdev field can be NULL on non-PCI machines
28 struct macio_chip
*chip
; /* macio_chip (private use) */
29 int index
; /* macio chip index in system */
31 struct pci_dev
*pdev
; /* PCI device hosting this bus */
36 * the macio_dev structure is used to describe a device
37 * within an Apple MacIO ASIC.
41 struct macio_bus
*bus
; /* macio bus this device is on */
42 struct macio_dev
*media_bay
; /* Device is part of a media bay */
43 struct platform_device ofdev
;
44 struct device_dma_parameters dma_parms
; /* ide needs that */
46 struct resource resource
[MACIO_DEV_COUNT_RESOURCES
];
48 struct resource interrupt
[MACIO_DEV_COUNT_IRQS
];
50 #define to_macio_device(d) container_of(d, struct macio_dev, ofdev.dev)
51 #define of_to_macio_device(d) container_of(d, struct macio_dev, ofdev)
53 extern struct macio_dev
*macio_dev_get(struct macio_dev
*dev
);
54 extern void macio_dev_put(struct macio_dev
*dev
);
57 * Accessors to resources & interrupts and other device
61 static inline int macio_resource_count(struct macio_dev
*dev
)
63 return dev
->n_resources
;
66 static inline unsigned long macio_resource_start(struct macio_dev
*dev
, int resource_no
)
68 return dev
->resource
[resource_no
].start
;
71 static inline unsigned long macio_resource_end(struct macio_dev
*dev
, int resource_no
)
73 return dev
->resource
[resource_no
].end
;
76 static inline unsigned long macio_resource_len(struct macio_dev
*dev
, int resource_no
)
78 struct resource
*res
= &dev
->resource
[resource_no
];
79 if (res
->start
== 0 || res
->end
== 0 || res
->end
< res
->start
)
81 return resource_size(res
);
84 extern int macio_enable_devres(struct macio_dev
*dev
);
86 extern int macio_request_resource(struct macio_dev
*dev
, int resource_no
, const char *name
);
87 extern void macio_release_resource(struct macio_dev
*dev
, int resource_no
);
88 extern int macio_request_resources(struct macio_dev
*dev
, const char *name
);
89 extern void macio_release_resources(struct macio_dev
*dev
);
91 static inline int macio_irq_count(struct macio_dev
*dev
)
93 return dev
->n_interrupts
;
96 static inline int macio_irq(struct macio_dev
*dev
, int irq_no
)
98 return dev
->interrupt
[irq_no
].start
;
101 static inline void macio_set_drvdata(struct macio_dev
*dev
, void *data
)
103 dev_set_drvdata(&dev
->ofdev
.dev
, data
);
106 static inline void* macio_get_drvdata(struct macio_dev
*dev
)
108 return dev_get_drvdata(&dev
->ofdev
.dev
);
111 static inline struct device_node
*macio_get_of_node(struct macio_dev
*mdev
)
113 return mdev
->ofdev
.dev
.of_node
;
117 static inline struct pci_dev
*macio_get_pci_dev(struct macio_dev
*mdev
)
119 return mdev
->bus
->pdev
;
124 * A driver for a mac-io chip based device
128 int (*probe
)(struct macio_dev
* dev
, const struct of_device_id
*match
);
129 void (*remove
)(struct macio_dev
*dev
);
131 int (*suspend
)(struct macio_dev
* dev
, pm_message_t state
);
132 int (*resume
)(struct macio_dev
* dev
);
133 int (*shutdown
)(struct macio_dev
* dev
);
135 #ifdef CONFIG_PMAC_MEDIABAY
136 void (*mediabay_event
)(struct macio_dev
* dev
, int mb_state
);
138 struct device_driver driver
;
140 #define to_macio_driver(drv) container_of(drv,struct macio_driver, driver)
142 extern int macio_register_driver(struct macio_driver
*);
143 extern void macio_unregister_driver(struct macio_driver
*);
145 #endif /* __KERNEL__ */
146 #endif /* __MACIO_ASIC_H__ */