1457c8996SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2e84de0c6SThomas Bogendoerfer #include <linux/export.h>
3e84de0c6SThomas Bogendoerfer #include <linux/kernel.h>
4e84de0c6SThomas Bogendoerfer #include <linux/init.h>
5e84de0c6SThomas Bogendoerfer #include <linux/slab.h>
6e84de0c6SThomas Bogendoerfer
7e84de0c6SThomas Bogendoerfer #include <asm/addrspace.h>
8e84de0c6SThomas Bogendoerfer #include <asm/paccess.h>
9e84de0c6SThomas Bogendoerfer #include <asm/gio_device.h>
10e84de0c6SThomas Bogendoerfer #include <asm/sgi/gio.h>
11e84de0c6SThomas Bogendoerfer #include <asm/sgi/hpc3.h>
12e84de0c6SThomas Bogendoerfer #include <asm/sgi/mc.h>
13e84de0c6SThomas Bogendoerfer #include <asm/sgi/ip22.h>
14e84de0c6SThomas Bogendoerfer
15fa494c01SRicardo B. Marliere static const struct bus_type gio_bus_type;
16e84de0c6SThomas Bogendoerfer
17e84de0c6SThomas Bogendoerfer static struct {
18e84de0c6SThomas Bogendoerfer const char *name;
19e84de0c6SThomas Bogendoerfer __u8 id;
20e84de0c6SThomas Bogendoerfer } gio_name_table[] = {
21e84de0c6SThomas Bogendoerfer { .name = "SGI Impact", .id = 0x10 },
22e84de0c6SThomas Bogendoerfer { .name = "Phobos G160", .id = 0x35 },
231d421ca9SThomas Bogendoerfer { .name = "Phobos G130", .id = 0x36 },
241d421ca9SThomas Bogendoerfer { .name = "Phobos G100", .id = 0x37 },
251d421ca9SThomas Bogendoerfer { .name = "Set Engineering GFE", .id = 0x38 },
26e84de0c6SThomas Bogendoerfer /* fake IDs */
27e84de0c6SThomas Bogendoerfer { .name = "SGI Newport", .id = 0x7e },
28e84de0c6SThomas Bogendoerfer { .name = "SGI GR2/GR3", .id = 0x7f },
29e84de0c6SThomas Bogendoerfer };
30e84de0c6SThomas Bogendoerfer
gio_bus_release(struct device * dev)3182242d28SLevente Kurusa static void gio_bus_release(struct device *dev)
3282242d28SLevente Kurusa {
3382242d28SLevente Kurusa kfree(dev);
3482242d28SLevente Kurusa }
3582242d28SLevente Kurusa
36e84de0c6SThomas Bogendoerfer static struct device gio_bus = {
37e84de0c6SThomas Bogendoerfer .init_name = "gio",
3882242d28SLevente Kurusa .release = &gio_bus_release,
39e84de0c6SThomas Bogendoerfer };
40e84de0c6SThomas Bogendoerfer
41e84de0c6SThomas Bogendoerfer /**
42e84de0c6SThomas Bogendoerfer * gio_match_device - Tell if an of_device structure has a matching
43e84de0c6SThomas Bogendoerfer * gio_match structure
44e84de0c6SThomas Bogendoerfer * @ids: array of of device match structures to search in
45e84de0c6SThomas Bogendoerfer * @dev: the of device structure to match against
46e84de0c6SThomas Bogendoerfer *
47e84de0c6SThomas Bogendoerfer * Used by a driver to check whether an of_device present in the
48e84de0c6SThomas Bogendoerfer * system is in its list of supported devices.
49e84de0c6SThomas Bogendoerfer */
5070eec920SGeert Uytterhoeven static const struct gio_device_id *
gio_match_device(const struct gio_device_id * match,const struct gio_device * dev)5170eec920SGeert Uytterhoeven gio_match_device(const struct gio_device_id *match,
52e84de0c6SThomas Bogendoerfer const struct gio_device *dev)
53e84de0c6SThomas Bogendoerfer {
54e84de0c6SThomas Bogendoerfer const struct gio_device_id *ids;
55e84de0c6SThomas Bogendoerfer
56e84de0c6SThomas Bogendoerfer for (ids = match; ids->id != 0xff; ids++)
57e84de0c6SThomas Bogendoerfer if (ids->id == dev->id.id)
58e84de0c6SThomas Bogendoerfer return ids;
59e84de0c6SThomas Bogendoerfer
60e84de0c6SThomas Bogendoerfer return NULL;
61e84de0c6SThomas Bogendoerfer }
62e84de0c6SThomas Bogendoerfer
gio_dev_get(struct gio_device * dev)63e84de0c6SThomas Bogendoerfer struct gio_device *gio_dev_get(struct gio_device *dev)
64e84de0c6SThomas Bogendoerfer {
65e84de0c6SThomas Bogendoerfer struct device *tmp;
66e84de0c6SThomas Bogendoerfer
67e84de0c6SThomas Bogendoerfer if (!dev)
68e84de0c6SThomas Bogendoerfer return NULL;
69e84de0c6SThomas Bogendoerfer tmp = get_device(&dev->dev);
70e84de0c6SThomas Bogendoerfer if (tmp)
71e84de0c6SThomas Bogendoerfer return to_gio_device(tmp);
72e84de0c6SThomas Bogendoerfer else
73e84de0c6SThomas Bogendoerfer return NULL;
74e84de0c6SThomas Bogendoerfer }
75e84de0c6SThomas Bogendoerfer EXPORT_SYMBOL_GPL(gio_dev_get);
76e84de0c6SThomas Bogendoerfer
gio_dev_put(struct gio_device * dev)77e84de0c6SThomas Bogendoerfer void gio_dev_put(struct gio_device *dev)
78e84de0c6SThomas Bogendoerfer {
79e84de0c6SThomas Bogendoerfer if (dev)
80e84de0c6SThomas Bogendoerfer put_device(&dev->dev);
81e84de0c6SThomas Bogendoerfer }
82e84de0c6SThomas Bogendoerfer EXPORT_SYMBOL_GPL(gio_dev_put);
83e84de0c6SThomas Bogendoerfer
84e84de0c6SThomas Bogendoerfer /**
85e84de0c6SThomas Bogendoerfer * gio_release_dev - free an gio device structure when all users of it are finished.
86e84de0c6SThomas Bogendoerfer * @dev: device that's been disconnected
87e84de0c6SThomas Bogendoerfer *
88e84de0c6SThomas Bogendoerfer * Will be called only by the device core when all users of this gio device are
89e84de0c6SThomas Bogendoerfer * done.
90e84de0c6SThomas Bogendoerfer */
gio_release_dev(struct device * dev)91e84de0c6SThomas Bogendoerfer void gio_release_dev(struct device *dev)
92e84de0c6SThomas Bogendoerfer {
93e84de0c6SThomas Bogendoerfer struct gio_device *giodev;
94e84de0c6SThomas Bogendoerfer
95e84de0c6SThomas Bogendoerfer giodev = to_gio_device(dev);
96e84de0c6SThomas Bogendoerfer kfree(giodev);
97e84de0c6SThomas Bogendoerfer }
98e84de0c6SThomas Bogendoerfer EXPORT_SYMBOL_GPL(gio_release_dev);
99e84de0c6SThomas Bogendoerfer
gio_device_register(struct gio_device * giodev)100e84de0c6SThomas Bogendoerfer int gio_device_register(struct gio_device *giodev)
101e84de0c6SThomas Bogendoerfer {
102e84de0c6SThomas Bogendoerfer giodev->dev.bus = &gio_bus_type;
103e84de0c6SThomas Bogendoerfer giodev->dev.parent = &gio_bus;
104e84de0c6SThomas Bogendoerfer return device_register(&giodev->dev);
105e84de0c6SThomas Bogendoerfer }
106e84de0c6SThomas Bogendoerfer EXPORT_SYMBOL_GPL(gio_device_register);
107e84de0c6SThomas Bogendoerfer
gio_device_unregister(struct gio_device * giodev)108e84de0c6SThomas Bogendoerfer void gio_device_unregister(struct gio_device *giodev)
109e84de0c6SThomas Bogendoerfer {
110e84de0c6SThomas Bogendoerfer device_unregister(&giodev->dev);
111e84de0c6SThomas Bogendoerfer }
112e84de0c6SThomas Bogendoerfer EXPORT_SYMBOL_GPL(gio_device_unregister);
113e84de0c6SThomas Bogendoerfer
gio_bus_match(struct device * dev,const struct device_driver * drv)114*cdd1fa91SBart Van Assche static int gio_bus_match(struct device *dev, const struct device_driver *drv)
115e84de0c6SThomas Bogendoerfer {
116e84de0c6SThomas Bogendoerfer struct gio_device *gio_dev = to_gio_device(dev);
117e84de0c6SThomas Bogendoerfer struct gio_driver *gio_drv = to_gio_driver(drv);
118e84de0c6SThomas Bogendoerfer
119e84de0c6SThomas Bogendoerfer return gio_match_device(gio_drv->id_table, gio_dev) != NULL;
120e84de0c6SThomas Bogendoerfer }
121e84de0c6SThomas Bogendoerfer
gio_device_probe(struct device * dev)122e84de0c6SThomas Bogendoerfer static int gio_device_probe(struct device *dev)
123e84de0c6SThomas Bogendoerfer {
124e84de0c6SThomas Bogendoerfer int error = -ENODEV;
125e84de0c6SThomas Bogendoerfer struct gio_driver *drv;
126e84de0c6SThomas Bogendoerfer struct gio_device *gio_dev;
127e84de0c6SThomas Bogendoerfer const struct gio_device_id *match;
128e84de0c6SThomas Bogendoerfer
129e84de0c6SThomas Bogendoerfer drv = to_gio_driver(dev->driver);
130e84de0c6SThomas Bogendoerfer gio_dev = to_gio_device(dev);
131e84de0c6SThomas Bogendoerfer
132e84de0c6SThomas Bogendoerfer if (!drv->probe)
133e84de0c6SThomas Bogendoerfer return error;
134e84de0c6SThomas Bogendoerfer
135e84de0c6SThomas Bogendoerfer gio_dev_get(gio_dev);
136e84de0c6SThomas Bogendoerfer
137e84de0c6SThomas Bogendoerfer match = gio_match_device(drv->id_table, gio_dev);
138e84de0c6SThomas Bogendoerfer if (match)
139e84de0c6SThomas Bogendoerfer error = drv->probe(gio_dev, match);
140e84de0c6SThomas Bogendoerfer if (error)
141e84de0c6SThomas Bogendoerfer gio_dev_put(gio_dev);
142e84de0c6SThomas Bogendoerfer
143e84de0c6SThomas Bogendoerfer return error;
144e84de0c6SThomas Bogendoerfer }
145e84de0c6SThomas Bogendoerfer
gio_device_remove(struct device * dev)146fc7a6209SUwe Kleine-König static void gio_device_remove(struct device *dev)
147e84de0c6SThomas Bogendoerfer {
148e84de0c6SThomas Bogendoerfer struct gio_device *gio_dev = to_gio_device(dev);
149e84de0c6SThomas Bogendoerfer struct gio_driver *drv = to_gio_driver(dev->driver);
150e84de0c6SThomas Bogendoerfer
1513bc5342cSUwe Kleine-König if (drv->remove)
152e84de0c6SThomas Bogendoerfer drv->remove(gio_dev);
153e84de0c6SThomas Bogendoerfer }
154e84de0c6SThomas Bogendoerfer
gio_device_shutdown(struct device * dev)155e84de0c6SThomas Bogendoerfer static void gio_device_shutdown(struct device *dev)
156e84de0c6SThomas Bogendoerfer {
157e84de0c6SThomas Bogendoerfer struct gio_device *gio_dev = to_gio_device(dev);
158e84de0c6SThomas Bogendoerfer struct gio_driver *drv = to_gio_driver(dev->driver);
159e84de0c6SThomas Bogendoerfer
160e84de0c6SThomas Bogendoerfer if (dev->driver && drv->shutdown)
161e84de0c6SThomas Bogendoerfer drv->shutdown(gio_dev);
162e84de0c6SThomas Bogendoerfer }
163e84de0c6SThomas Bogendoerfer
modalias_show(struct device * dev,struct device_attribute * a,char * buf)164e84de0c6SThomas Bogendoerfer static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
165e84de0c6SThomas Bogendoerfer char *buf)
166e84de0c6SThomas Bogendoerfer {
167e84de0c6SThomas Bogendoerfer struct gio_device *gio_dev = to_gio_device(dev);
168e84de0c6SThomas Bogendoerfer int len = snprintf(buf, PAGE_SIZE, "gio:%x\n", gio_dev->id.id);
169e84de0c6SThomas Bogendoerfer
170e84de0c6SThomas Bogendoerfer return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len;
171e84de0c6SThomas Bogendoerfer }
172136e882fSGreg Kroah-Hartman static DEVICE_ATTR_RO(modalias);
173e84de0c6SThomas Bogendoerfer
name_show(struct device * dev,struct device_attribute * attr,char * buf)174e84de0c6SThomas Bogendoerfer static ssize_t name_show(struct device *dev,
175e84de0c6SThomas Bogendoerfer struct device_attribute *attr, char *buf)
176e84de0c6SThomas Bogendoerfer {
177e84de0c6SThomas Bogendoerfer struct gio_device *giodev;
178e84de0c6SThomas Bogendoerfer
179e84de0c6SThomas Bogendoerfer giodev = to_gio_device(dev);
180e84de0c6SThomas Bogendoerfer return sprintf(buf, "%s", giodev->name);
181e84de0c6SThomas Bogendoerfer }
182136e882fSGreg Kroah-Hartman static DEVICE_ATTR_RO(name);
183e84de0c6SThomas Bogendoerfer
id_show(struct device * dev,struct device_attribute * attr,char * buf)184e84de0c6SThomas Bogendoerfer static ssize_t id_show(struct device *dev,
185e84de0c6SThomas Bogendoerfer struct device_attribute *attr, char *buf)
186e84de0c6SThomas Bogendoerfer {
187e84de0c6SThomas Bogendoerfer struct gio_device *giodev;
188e84de0c6SThomas Bogendoerfer
189e84de0c6SThomas Bogendoerfer giodev = to_gio_device(dev);
190e84de0c6SThomas Bogendoerfer return sprintf(buf, "%x", giodev->id.id);
191e84de0c6SThomas Bogendoerfer }
192136e882fSGreg Kroah-Hartman static DEVICE_ATTR_RO(id);
193e84de0c6SThomas Bogendoerfer
194136e882fSGreg Kroah-Hartman static struct attribute *gio_dev_attrs[] = {
195136e882fSGreg Kroah-Hartman &dev_attr_modalias.attr,
196136e882fSGreg Kroah-Hartman &dev_attr_name.attr,
197136e882fSGreg Kroah-Hartman &dev_attr_id.attr,
198136e882fSGreg Kroah-Hartman NULL,
199e84de0c6SThomas Bogendoerfer };
200136e882fSGreg Kroah-Hartman ATTRIBUTE_GROUPS(gio_dev);
201e84de0c6SThomas Bogendoerfer
gio_device_uevent(const struct device * dev,struct kobj_uevent_env * env)2022a81ada3SGreg Kroah-Hartman static int gio_device_uevent(const struct device *dev, struct kobj_uevent_env *env)
203e84de0c6SThomas Bogendoerfer {
2042a81ada3SGreg Kroah-Hartman const struct gio_device *gio_dev = to_gio_device(dev);
205e84de0c6SThomas Bogendoerfer
206e84de0c6SThomas Bogendoerfer add_uevent_var(env, "MODALIAS=gio:%x", gio_dev->id.id);
207e84de0c6SThomas Bogendoerfer return 0;
208e84de0c6SThomas Bogendoerfer }
209e84de0c6SThomas Bogendoerfer
gio_register_driver(struct gio_driver * drv)210e84de0c6SThomas Bogendoerfer int gio_register_driver(struct gio_driver *drv)
211e84de0c6SThomas Bogendoerfer {
212e84de0c6SThomas Bogendoerfer /* initialize common driver fields */
213e84de0c6SThomas Bogendoerfer if (!drv->driver.name)
214e84de0c6SThomas Bogendoerfer drv->driver.name = drv->name;
215e84de0c6SThomas Bogendoerfer if (!drv->driver.owner)
216e84de0c6SThomas Bogendoerfer drv->driver.owner = drv->owner;
217e84de0c6SThomas Bogendoerfer drv->driver.bus = &gio_bus_type;
218e84de0c6SThomas Bogendoerfer
219e84de0c6SThomas Bogendoerfer /* register with core */
220e84de0c6SThomas Bogendoerfer return driver_register(&drv->driver);
221e84de0c6SThomas Bogendoerfer }
222e84de0c6SThomas Bogendoerfer EXPORT_SYMBOL_GPL(gio_register_driver);
223e84de0c6SThomas Bogendoerfer
gio_unregister_driver(struct gio_driver * drv)224e84de0c6SThomas Bogendoerfer void gio_unregister_driver(struct gio_driver *drv)
225e84de0c6SThomas Bogendoerfer {
226e84de0c6SThomas Bogendoerfer driver_unregister(&drv->driver);
227e84de0c6SThomas Bogendoerfer }
228e84de0c6SThomas Bogendoerfer EXPORT_SYMBOL_GPL(gio_unregister_driver);
229e84de0c6SThomas Bogendoerfer
gio_set_master(struct gio_device * dev)230e84de0c6SThomas Bogendoerfer void gio_set_master(struct gio_device *dev)
231e84de0c6SThomas Bogendoerfer {
232e84de0c6SThomas Bogendoerfer u32 tmp = sgimc->giopar;
233e84de0c6SThomas Bogendoerfer
234e84de0c6SThomas Bogendoerfer switch (dev->slotno) {
235e84de0c6SThomas Bogendoerfer case 0:
236e84de0c6SThomas Bogendoerfer tmp |= SGIMC_GIOPAR_MASTERGFX;
237e84de0c6SThomas Bogendoerfer break;
238e84de0c6SThomas Bogendoerfer case 1:
239e84de0c6SThomas Bogendoerfer tmp |= SGIMC_GIOPAR_MASTEREXP0;
240e84de0c6SThomas Bogendoerfer break;
241e84de0c6SThomas Bogendoerfer case 2:
242e84de0c6SThomas Bogendoerfer tmp |= SGIMC_GIOPAR_MASTEREXP1;
243e84de0c6SThomas Bogendoerfer break;
244e84de0c6SThomas Bogendoerfer }
245e84de0c6SThomas Bogendoerfer sgimc->giopar = tmp;
246e84de0c6SThomas Bogendoerfer }
247e84de0c6SThomas Bogendoerfer EXPORT_SYMBOL_GPL(gio_set_master);
248e84de0c6SThomas Bogendoerfer
ip22_gio_set_64bit(int slotno)2493ee1167aSGenjian Zhang static void ip22_gio_set_64bit(int slotno)
250e84de0c6SThomas Bogendoerfer {
251e84de0c6SThomas Bogendoerfer u32 tmp = sgimc->giopar;
252e84de0c6SThomas Bogendoerfer
253e84de0c6SThomas Bogendoerfer switch (slotno) {
254e84de0c6SThomas Bogendoerfer case 0:
255e84de0c6SThomas Bogendoerfer tmp |= SGIMC_GIOPAR_GFX64;
256e84de0c6SThomas Bogendoerfer break;
257e84de0c6SThomas Bogendoerfer case 1:
258e84de0c6SThomas Bogendoerfer tmp |= SGIMC_GIOPAR_EXP064;
259e84de0c6SThomas Bogendoerfer break;
260e84de0c6SThomas Bogendoerfer case 2:
261e84de0c6SThomas Bogendoerfer tmp |= SGIMC_GIOPAR_EXP164;
262e84de0c6SThomas Bogendoerfer break;
263e84de0c6SThomas Bogendoerfer }
264e84de0c6SThomas Bogendoerfer sgimc->giopar = tmp;
265e84de0c6SThomas Bogendoerfer }
266e84de0c6SThomas Bogendoerfer
ip22_gio_id(unsigned long addr,u32 * res)267e84de0c6SThomas Bogendoerfer static int ip22_gio_id(unsigned long addr, u32 *res)
268e84de0c6SThomas Bogendoerfer {
269e84de0c6SThomas Bogendoerfer u8 tmp8;
270e84de0c6SThomas Bogendoerfer u8 tmp16;
271e84de0c6SThomas Bogendoerfer u32 tmp32;
272e84de0c6SThomas Bogendoerfer u8 *ptr8;
273e84de0c6SThomas Bogendoerfer u16 *ptr16;
274e84de0c6SThomas Bogendoerfer u32 *ptr32;
275e84de0c6SThomas Bogendoerfer
276e84de0c6SThomas Bogendoerfer ptr32 = (void *)CKSEG1ADDR(addr);
277e84de0c6SThomas Bogendoerfer if (!get_dbe(tmp32, ptr32)) {
278e84de0c6SThomas Bogendoerfer /*
279e84de0c6SThomas Bogendoerfer * We got no DBE, but this doesn't mean anything.
280e84de0c6SThomas Bogendoerfer * If GIO is pipelined (which can't be disabled
281e84de0c6SThomas Bogendoerfer * for GFX slot) we don't get a DBE, but we see
282e84de0c6SThomas Bogendoerfer * the transfer size as data. So we do an 8bit
283e84de0c6SThomas Bogendoerfer * and a 16bit access and check whether the common
284e84de0c6SThomas Bogendoerfer * data matches
285e84de0c6SThomas Bogendoerfer */
286e84de0c6SThomas Bogendoerfer ptr8 = (void *)CKSEG1ADDR(addr + 3);
2871d421ca9SThomas Bogendoerfer if (get_dbe(tmp8, ptr8)) {
2881d421ca9SThomas Bogendoerfer /*
2891d421ca9SThomas Bogendoerfer * 32bit access worked, but 8bit doesn't
2901d421ca9SThomas Bogendoerfer * so we don't see phantom reads on
2911d421ca9SThomas Bogendoerfer * a pipelined bus, but a real card which
2921d421ca9SThomas Bogendoerfer * doesn't support 8 bit reads
2931d421ca9SThomas Bogendoerfer */
2941d421ca9SThomas Bogendoerfer *res = tmp32;
2951d421ca9SThomas Bogendoerfer return 1;
2961d421ca9SThomas Bogendoerfer }
297e84de0c6SThomas Bogendoerfer ptr16 = (void *)CKSEG1ADDR(addr + 2);
298e84de0c6SThomas Bogendoerfer get_dbe(tmp16, ptr16);
299e84de0c6SThomas Bogendoerfer if (tmp8 == (tmp16 & 0xff) &&
300e84de0c6SThomas Bogendoerfer tmp8 == (tmp32 & 0xff) &&
301e84de0c6SThomas Bogendoerfer tmp16 == (tmp32 & 0xffff)) {
302e84de0c6SThomas Bogendoerfer *res = tmp32;
303e84de0c6SThomas Bogendoerfer return 1;
304e84de0c6SThomas Bogendoerfer }
305e84de0c6SThomas Bogendoerfer }
306e84de0c6SThomas Bogendoerfer return 0; /* nothing here */
307e84de0c6SThomas Bogendoerfer }
308e84de0c6SThomas Bogendoerfer
309e84de0c6SThomas Bogendoerfer #define HQ2_MYSTERY_OFFS 0x6A07C
310e84de0c6SThomas Bogendoerfer #define NEWPORT_USTATUS_OFFS 0xF133C
311e84de0c6SThomas Bogendoerfer
ip22_is_gr2(unsigned long addr)312e84de0c6SThomas Bogendoerfer static int ip22_is_gr2(unsigned long addr)
313e84de0c6SThomas Bogendoerfer {
314e84de0c6SThomas Bogendoerfer u32 tmp;
315e84de0c6SThomas Bogendoerfer u32 *ptr;
316e84de0c6SThomas Bogendoerfer
317e84de0c6SThomas Bogendoerfer /* HQ2 only allows 32bit accesses */
318e84de0c6SThomas Bogendoerfer ptr = (void *)CKSEG1ADDR(addr + HQ2_MYSTERY_OFFS);
319e84de0c6SThomas Bogendoerfer if (!get_dbe(tmp, ptr)) {
320e84de0c6SThomas Bogendoerfer if (tmp == 0xdeadbeef)
321e84de0c6SThomas Bogendoerfer return 1;
322e84de0c6SThomas Bogendoerfer }
323e84de0c6SThomas Bogendoerfer return 0;
324e84de0c6SThomas Bogendoerfer }
325e84de0c6SThomas Bogendoerfer
326e84de0c6SThomas Bogendoerfer
ip22_check_gio(int slotno,unsigned long addr,int irq)3271d421ca9SThomas Bogendoerfer static void ip22_check_gio(int slotno, unsigned long addr, int irq)
328e84de0c6SThomas Bogendoerfer {
329e84de0c6SThomas Bogendoerfer const char *name = "Unknown";
330e84de0c6SThomas Bogendoerfer struct gio_device *gio_dev;
331e84de0c6SThomas Bogendoerfer u32 tmp;
332e84de0c6SThomas Bogendoerfer __u8 id;
333e84de0c6SThomas Bogendoerfer int i;
334e84de0c6SThomas Bogendoerfer
335e84de0c6SThomas Bogendoerfer /* first look for GR2/GR3 by checking mystery register */
336e84de0c6SThomas Bogendoerfer if (ip22_is_gr2(addr))
337e84de0c6SThomas Bogendoerfer tmp = 0x7f;
338e84de0c6SThomas Bogendoerfer else {
339e84de0c6SThomas Bogendoerfer if (!ip22_gio_id(addr, &tmp)) {
340e84de0c6SThomas Bogendoerfer /*
3411d421ca9SThomas Bogendoerfer * no GIO signature at start address of slot
3421d421ca9SThomas Bogendoerfer * since Newport doesn't have one, we check if
3431d421ca9SThomas Bogendoerfer * user status register is readable
344e84de0c6SThomas Bogendoerfer */
345e84de0c6SThomas Bogendoerfer if (ip22_gio_id(addr + NEWPORT_USTATUS_OFFS, &tmp))
346e84de0c6SThomas Bogendoerfer tmp = 0x7e;
347e84de0c6SThomas Bogendoerfer else
348e84de0c6SThomas Bogendoerfer tmp = 0;
349e84de0c6SThomas Bogendoerfer }
350e84de0c6SThomas Bogendoerfer }
351e84de0c6SThomas Bogendoerfer if (tmp) {
352e84de0c6SThomas Bogendoerfer id = GIO_ID(tmp);
353e84de0c6SThomas Bogendoerfer if (tmp & GIO_32BIT_ID) {
354e84de0c6SThomas Bogendoerfer if (tmp & GIO_64BIT_IFACE)
355e84de0c6SThomas Bogendoerfer ip22_gio_set_64bit(slotno);
356e84de0c6SThomas Bogendoerfer }
357e84de0c6SThomas Bogendoerfer for (i = 0; i < ARRAY_SIZE(gio_name_table); i++) {
358e84de0c6SThomas Bogendoerfer if (id == gio_name_table[i].id) {
359e84de0c6SThomas Bogendoerfer name = gio_name_table[i].name;
360e84de0c6SThomas Bogendoerfer break;
361e84de0c6SThomas Bogendoerfer }
362e84de0c6SThomas Bogendoerfer }
363e84de0c6SThomas Bogendoerfer printk(KERN_INFO "GIO: slot %d : %s (id %x)\n",
364e84de0c6SThomas Bogendoerfer slotno, name, id);
365e84de0c6SThomas Bogendoerfer gio_dev = kzalloc(sizeof *gio_dev, GFP_KERNEL);
366f93e2a10SXiaoke Wang if (!gio_dev)
367f93e2a10SXiaoke Wang return;
368e84de0c6SThomas Bogendoerfer gio_dev->name = name;
369e84de0c6SThomas Bogendoerfer gio_dev->slotno = slotno;
370e84de0c6SThomas Bogendoerfer gio_dev->id.id = id;
371e84de0c6SThomas Bogendoerfer gio_dev->resource.start = addr;
372e84de0c6SThomas Bogendoerfer gio_dev->resource.end = addr + 0x3fffff;
373e84de0c6SThomas Bogendoerfer gio_dev->resource.flags = IORESOURCE_MEM;
3741d421ca9SThomas Bogendoerfer gio_dev->irq = irq;
375e84de0c6SThomas Bogendoerfer dev_set_name(&gio_dev->dev, "%d", slotno);
376e84de0c6SThomas Bogendoerfer gio_device_register(gio_dev);
377e84de0c6SThomas Bogendoerfer } else
378e84de0c6SThomas Bogendoerfer printk(KERN_INFO "GIO: slot %d : Empty\n", slotno);
379e84de0c6SThomas Bogendoerfer }
380e84de0c6SThomas Bogendoerfer
381fa494c01SRicardo B. Marliere static const struct bus_type gio_bus_type = {
382e84de0c6SThomas Bogendoerfer .name = "gio",
383136e882fSGreg Kroah-Hartman .dev_groups = gio_dev_groups,
384e84de0c6SThomas Bogendoerfer .match = gio_bus_match,
385e84de0c6SThomas Bogendoerfer .probe = gio_device_probe,
386e84de0c6SThomas Bogendoerfer .remove = gio_device_remove,
387e84de0c6SThomas Bogendoerfer .shutdown = gio_device_shutdown,
388e84de0c6SThomas Bogendoerfer .uevent = gio_device_uevent,
389e84de0c6SThomas Bogendoerfer };
390e84de0c6SThomas Bogendoerfer
391e84de0c6SThomas Bogendoerfer static struct resource gio_bus_resource = {
392e84de0c6SThomas Bogendoerfer .start = GIO_SLOT_GFX_BASE,
393e84de0c6SThomas Bogendoerfer .end = GIO_SLOT_GFX_BASE + 0x9fffff,
394e84de0c6SThomas Bogendoerfer .name = "GIO Bus",
395e84de0c6SThomas Bogendoerfer .flags = IORESOURCE_MEM,
396e84de0c6SThomas Bogendoerfer };
397e84de0c6SThomas Bogendoerfer
ip22_gio_init(void)3983ee1167aSGenjian Zhang static int __init ip22_gio_init(void)
399e84de0c6SThomas Bogendoerfer {
400e84de0c6SThomas Bogendoerfer unsigned int pbdma __maybe_unused;
401e84de0c6SThomas Bogendoerfer int ret;
402e84de0c6SThomas Bogendoerfer
403e84de0c6SThomas Bogendoerfer ret = device_register(&gio_bus);
40482242d28SLevente Kurusa if (ret) {
40582242d28SLevente Kurusa put_device(&gio_bus);
406e84de0c6SThomas Bogendoerfer return ret;
40782242d28SLevente Kurusa }
408e84de0c6SThomas Bogendoerfer
409e84de0c6SThomas Bogendoerfer ret = bus_register(&gio_bus_type);
410e84de0c6SThomas Bogendoerfer if (!ret) {
411e84de0c6SThomas Bogendoerfer request_resource(&iomem_resource, &gio_bus_resource);
412e84de0c6SThomas Bogendoerfer printk(KERN_INFO "GIO: Probing bus...\n");
413e84de0c6SThomas Bogendoerfer
4141d421ca9SThomas Bogendoerfer if (ip22_is_fullhouse()) {
4151d421ca9SThomas Bogendoerfer /* Indigo2 */
4161d421ca9SThomas Bogendoerfer ip22_check_gio(0, GIO_SLOT_GFX_BASE, SGI_GIO_1_IRQ);
4171d421ca9SThomas Bogendoerfer ip22_check_gio(1, GIO_SLOT_EXP0_BASE, SGI_GIO_1_IRQ);
418e84de0c6SThomas Bogendoerfer } else {
4191d421ca9SThomas Bogendoerfer /* Indy/Challenge S */
4201d421ca9SThomas Bogendoerfer if (get_dbe(pbdma, (unsigned int *)&hpc3c1->pbdma[1]))
4211d421ca9SThomas Bogendoerfer ip22_check_gio(0, GIO_SLOT_GFX_BASE,
4221d421ca9SThomas Bogendoerfer SGI_GIO_0_IRQ);
4231d421ca9SThomas Bogendoerfer ip22_check_gio(1, GIO_SLOT_EXP0_BASE, SGI_GIOEXP0_IRQ);
4241d421ca9SThomas Bogendoerfer ip22_check_gio(2, GIO_SLOT_EXP1_BASE, SGI_GIOEXP1_IRQ);
425e84de0c6SThomas Bogendoerfer }
426e84de0c6SThomas Bogendoerfer } else
427e84de0c6SThomas Bogendoerfer device_unregister(&gio_bus);
428e84de0c6SThomas Bogendoerfer
429e84de0c6SThomas Bogendoerfer return ret;
430e84de0c6SThomas Bogendoerfer }
431e84de0c6SThomas Bogendoerfer
432e84de0c6SThomas Bogendoerfer subsys_initcall(ip22_gio_init);
433