14 #include <linux/kernel.h>
15 #include <linux/device.h>
17 #include <linux/list.h>
19 #include <linux/slab.h>
23 #include <linux/module.h>
24 #include <asm/cacheflush.h>
38 static DECLARE_WORK(maple_dma_process, maple_dma_handler);
39 static DECLARE_WORK(maple_vblank_process, maple_vblank_handler);
48 static struct device maple_bus;
50 static unsigned long *maple_sendbuf, *maple_sendptr, *maple_lastptr;
51 static unsigned long maple_pnp_time;
52 static int started, scanning, fullscan;
96 static void maple_dma_reset(
void)
123 unsigned long interval,
unsigned long function)
132 static int maple_dma_done(
void)
137 static void maple_release_device(
struct device *dev)
175 memcpy(sendbuf + 4, data, (length - 1) * 4);
194 INIT_LIST_HEAD(&mq->
list);
206 dev_err(&mdev->
dev,
"could not allocate memory for device (%d, %d)\n",
225 mdev->
mq = maple_allocq(mdev);
232 mdev->
dev.parent = &maple_bus;
247 static void maple_build_block(
struct mapleq *mq)
250 unsigned long *lsendbuf = mq->
sendbuf;
252 port = mq->
dev->port & 3;
253 unit = mq->
dev->unit;
258 *maple_lastptr &= 0x7fffffff;
259 maple_lastptr = maple_sendptr;
261 *maple_sendptr++ = (port << 16) | len | 0x80000000;
266 *maple_sendptr++ = *lsendbuf++;
270 static void maple_send(
void)
272 int i, maple_packets = 0;
275 if (!maple_dma_done())
281 if (!list_empty(&maple_sentq))
285 if (list_empty(&maple_waitq)) {
290 maple_lastptr = maple_sendbuf;
291 maple_sendptr = maple_sendbuf;
294 maple_build_block(mq);
295 list_del_init(&mq->
list);
301 if (maple_packets > 0) {
325 static void maple_detach_driver(
struct maple_device *mdev)
331 static void maple_attach_driver(
struct maple_device *mdev)
334 unsigned long function;
337 recvbuf = mdev->
mq->recvbuf->buf;
365 dev_info(&mdev->
dev,
"detected %s: function 0x%lX: at (%d, %d)\n",
368 if (
function > 0x200) {
371 mdev->
driver = &maple_unsupported_device;
376 maple_check_matching_driver);
381 mdev->
driver = &maple_unsupported_device;
384 mdev->
unit,
function);
388 mdev->
dev.release = &maple_release_device;
393 dev_warn(&mdev->
dev,
"could not register device at"
394 " (%d, %d), with error 0x%X\n", mdev->
unit,
396 maple_free_dev(mdev);
407 static int check_maple_device(
struct device *
device,
void *portptr)
419 static int setup_maple_commands(
struct device *device,
void *
ignored)
451 if (!maple_dma_done())
456 if (!list_empty(&maple_sentq))
464 setup_maple_commands);
472 if (checked[x] &&
empty[x]) {
492 static void maple_map_subunits(
struct maple_device *mdev,
int submask)
499 for (k = 0; k < 5; k++) {
505 submask = submask >> 1;
508 devcheck = submask & 0x01;
510 mdev_add = maple_alloc_dev(mdev->
port, k + 1);
519 submask = submask >> 1;
524 static void maple_clean_submap(
struct maple_device *mdev)
528 killbit = (mdev->
unit > 0 ? (1 << (mdev->
unit - 1)) & 0x1f : 0x20);
531 subdevice_map[mdev->
port] = subdevice_map[mdev->
port] & killbit;
535 static void maple_response_none(
struct maple_device *mdev)
537 maple_clean_submap(mdev);
557 dev_info(&mdev->
dev,
"detaching device at (%d, %d)\n",
559 maple_detach_driver(mdev);
563 if (checked[mdev->
port] ==
false) {
564 checked[mdev->
port] =
true;
567 " to port %d\n", mdev->
port);
577 static void maple_response_devinfo(
struct maple_device *mdev,
581 if (!
started || (scanning == 2) || !fullscan) {
582 if ((mdev->
unit == 0) && (checked[mdev->
port] ==
false)) {
583 checked[mdev->
port] =
true;
584 maple_attach_driver(mdev);
587 maple_attach_driver(mdev);
588 if (mdev->
unit == 0) {
590 maple_attach_driver(mdev);
594 if (mdev->
unit == 0) {
595 submask = recvbuf[2] & 0x1F;
596 if (submask ^ subdevice_map[mdev->
port]) {
597 maple_map_subunits(mdev, submask);
598 subdevice_map[mdev->
port] = submask;
603 static void maple_response_fileerr(
struct maple_device *mdev,
void *recvbuf)
610 "file error 0x%X\n", mdev->
port, mdev->
unit,
611 ((
int *)recvbuf)[1]);
614 static void maple_port_rescan(
void)
621 if (checked[i] ==
false) {
631 static void maple_dma_handler(
struct work_struct *work)
638 if (!maple_dma_done())
641 if (!list_empty(&maple_sentq)) {
649 list_del_init(&mq->
list);
652 maple_response_none(mdev);
656 maple_response_devinfo(mdev, recvbuf);
668 maple_response_fileerr(mdev, recvbuf);
677 " 0x%X at (%d, %d)\n", code,
683 dev_notice(&mdev->
dev,
"extended"
684 " device information request for (%d, %d)"
685 " but call is not supported\n", mdev->
port,
727 static int maple_set_dma_interrupt_handler(
void)
730 IRQF_SHARED,
"maple bus DMA", &maple_unsupported_device);
733 static int maple_set_vblank_interrupt_handler(
void)
736 IRQF_SHARED,
"maple bus VBLANK", &maple_unsupported_device);
739 static int maple_get_dma_buffer(
void)
749 static int maple_match_bus_driver(
struct device *devptr,
756 if (maple_dev->
devinfo.function == 0xFFFFFFFF)
758 else if (maple_dev->
devinfo.function &
764 static int maple_bus_uevent(
struct device *dev,
770 static void maple_bus_release(
struct device *dev)
776 .name =
"maple_unsupported_device",
785 .match = maple_match_bus_driver,
786 .uevent = maple_bus_uevent,
790 static struct device maple_bus = {
791 .init_name =
"maple",
792 .release = maple_bus_release,
795 static int __init maple_bus_init(
void)
815 retval = maple_get_dma_buffer();
817 dev_err(&maple_bus,
"failed to allocate DMA buffers\n");
822 retval = maple_set_dma_interrupt_handler();
824 dev_err(&maple_bus,
"bus failed to grab maple "
830 retval = maple_set_vblank_interrupt_handler();
832 dev_err(&maple_bus,
"bus failed to grab VBLANK IRQ\n");
838 if (!maple_queue_cache)
839 goto cleanup_bothirqs;
841 INIT_LIST_HEAD(&maple_waitq);
842 INIT_LIST_HEAD(&maple_sentq);
848 mdev[
i] = maple_alloc_dev(i, 0);
851 maple_free_dev(mdev[i]);
854 baseunits[
i] = mdev[
i];
857 subdevice_map[
i] = 0;
863 dev_info(&maple_bus,
"bus core now registered\n");