blob: ff5fd82d9ff004f5287077075a204698f703fed9 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef __MACIO_ASIC_H__
3#define __MACIO_ASIC_H__
Arnd Bergmann88ced032005-12-16 22:43:46 +01004#ifdef __KERNEL__
Linus Torvalds1da177e2005-04-16 15:20:36 -07005
Stephen Rothwell4b1d99b2008-04-14 12:08:47 +10006#include <linux/of_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
8extern struct bus_type macio_bus_type;
9
10/* MacIO device driver is defined later */
11struct macio_driver;
12struct macio_chip;
13
14#define MACIO_DEV_COUNT_RESOURCES 8
15#define MACIO_DEV_COUNT_IRQS 8
16
17/*
18 * the macio_bus structure is used to describe a "virtual" bus
19 * within a MacIO ASIC. It's typically provided by a macio_pci_asic
20 * PCI device, but could be provided differently as well (nubus
21 * machines using a fake OF tree).
22 *
23 * The pdev field can be NULL on non-PCI machines
24 */
25struct macio_bus
26{
27 struct macio_chip *chip; /* macio_chip (private use) */
28 int index; /* macio chip index in system */
29#ifdef CONFIG_PCI
30 struct pci_dev *pdev; /* PCI device hosting this bus */
31#endif
32};
33
34/*
35 * the macio_dev structure is used to describe a device
36 * within an Apple MacIO ASIC.
37 */
38struct macio_dev
39{
40 struct macio_bus *bus; /* macio bus this device is on */
41 struct macio_dev *media_bay; /* Device is part of a media bay */
Grant Likely94a0cb12010-07-22 13:59:23 -060042 struct platform_device ofdev;
Benjamin Herrenschmidt128b4a02009-12-01 14:36:27 +000043 struct device_dma_parameters dma_parms; /* ide needs that */
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 int n_resources;
45 struct resource resource[MACIO_DEV_COUNT_RESOURCES];
46 int n_interrupts;
47 struct resource interrupt[MACIO_DEV_COUNT_IRQS];
48};
49#define to_macio_device(d) container_of(d, struct macio_dev, ofdev.dev)
50#define of_to_macio_device(d) container_of(d, struct macio_dev, ofdev)
51
52extern struct macio_dev *macio_dev_get(struct macio_dev *dev);
53extern void macio_dev_put(struct macio_dev *dev);
54
55/*
56 * Accessors to resources & interrupts and other device
57 * fields
58 */
59
60static inline int macio_resource_count(struct macio_dev *dev)
61{
62 return dev->n_resources;
63}
64
65static inline unsigned long macio_resource_start(struct macio_dev *dev, int resource_no)
66{
67 return dev->resource[resource_no].start;
68}
69
70static inline unsigned long macio_resource_end(struct macio_dev *dev, int resource_no)
71{
72 return dev->resource[resource_no].end;
73}
74
75static inline unsigned long macio_resource_len(struct macio_dev *dev, int resource_no)
76{
77 struct resource *res = &dev->resource[resource_no];
78 if (res->start == 0 || res->end == 0 || res->end < res->start)
79 return 0;
Joe Perches28f65c112011-06-09 09:13:32 -070080 return resource_size(res);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081}
82
Benjamin Herrenschmidt7fb19ea2009-12-01 14:36:26 +000083extern int macio_enable_devres(struct macio_dev *dev);
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085extern int macio_request_resource(struct macio_dev *dev, int resource_no, const char *name);
86extern void macio_release_resource(struct macio_dev *dev, int resource_no);
87extern int macio_request_resources(struct macio_dev *dev, const char *name);
88extern void macio_release_resources(struct macio_dev *dev);
89
90static inline int macio_irq_count(struct macio_dev *dev)
91{
92 return dev->n_interrupts;
93}
94
95static inline int macio_irq(struct macio_dev *dev, int irq_no)
96{
97 return dev->interrupt[irq_no].start;
98}
99
100static inline void macio_set_drvdata(struct macio_dev *dev, void *data)
101{
102 dev_set_drvdata(&dev->ofdev.dev, data);
103}
104
105static inline void* macio_get_drvdata(struct macio_dev *dev)
106{
107 return dev_get_drvdata(&dev->ofdev.dev);
108}
109
110static inline struct device_node *macio_get_of_node(struct macio_dev *mdev)
111{
Grant Likely61c7a082010-04-13 16:12:29 -0700112 return mdev->ofdev.dev.of_node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113}
114
115#ifdef CONFIG_PCI
116static inline struct pci_dev *macio_get_pci_dev(struct macio_dev *mdev)
117{
118 return mdev->bus->pdev;
119}
120#endif
121
122/*
123 * A driver for a mac-io chip based device
124 */
125struct macio_driver
126{
Jeff Mahoney5e655772005-07-06 15:44:41 -0400127 int (*probe)(struct macio_dev* dev, const struct of_device_id *match);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 int (*remove)(struct macio_dev* dev);
129
Pavel Machekb1c42852005-04-16 15:25:34 -0700130 int (*suspend)(struct macio_dev* dev, pm_message_t state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 int (*resume)(struct macio_dev* dev);
132 int (*shutdown)(struct macio_dev* dev);
133
Benjamin Herrenschmidtd58b0c32009-12-01 14:36:28 +0000134#ifdef CONFIG_PMAC_MEDIABAY
135 void (*mediabay_event)(struct macio_dev* dev, int mb_state);
136#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 struct device_driver driver;
138};
139#define to_macio_driver(drv) container_of(drv,struct macio_driver, driver)
140
141extern int macio_register_driver(struct macio_driver *);
142extern void macio_unregister_driver(struct macio_driver *);
143
Arnd Bergmann88ced032005-12-16 22:43:46 +0100144#endif /* __KERNEL__ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#endif /* __MACIO_ASIC_H__ */