diff options
author | Dominik Brodowski <linux@dominikbrodowski.net> | 2008-07-29 02:38:55 -0400 |
---|---|---|
committer | Dominik Brodowski <linux@dominikbrodowski.net> | 2008-08-22 19:20:43 -0400 |
commit | ed58872aa33e16a0d5352080e47c65fa14e6ad1c (patch) | |
tree | 42d0bc7c4cf3bab990ef45c89faf52f3aa4febb3 /drivers | |
parent | 0bac660a77b672f85d713d1898382993299df5de (diff) |
pcmcia: use pcmcia_loop_config in bluetooth drivers
Use the config loop helper in bluetooth pcmcia drivers.
CC: Marcel Holtmann <marcel@holtmann.org>
CC: linux-bluetooth@vger.kernel.org
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/bluetooth/bt3c_cs.c | 119 | ||||
-rw-r--r-- | drivers/bluetooth/btuart_cs.c | 121 | ||||
-rw-r--r-- | drivers/bluetooth/dtl1_cs.c | 62 |
3 files changed, 108 insertions, 194 deletions
diff --git a/drivers/bluetooth/bt3c_cs.c b/drivers/bluetooth/bt3c_cs.c index 593b7c595038..6ec366f1cf74 100644 --- a/drivers/bluetooth/bt3c_cs.c +++ b/drivers/bluetooth/bt3c_cs.c | |||
@@ -678,93 +678,68 @@ static void bt3c_detach(struct pcmcia_device *link) | |||
678 | kfree(info); | 678 | kfree(info); |
679 | } | 679 | } |
680 | 680 | ||
681 | static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse) | 681 | static int bt3c_check_config(struct pcmcia_device *p_dev, |
682 | cistpl_cftable_entry_t *cf, | ||
683 | void *priv_data) | ||
682 | { | 684 | { |
683 | int i; | 685 | unsigned long try = (unsigned long) priv_data; |
684 | 686 | ||
685 | i = pcmcia_get_tuple_data(handle, tuple); | 687 | if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM)) |
686 | if (i != CS_SUCCESS) | 688 | p_dev->conf.Vpp = cf->vpp1.param[CISTPL_POWER_VNOM] / 10000; |
687 | return i; | 689 | if ((cf->io.nwin > 0) && (cf->io.win[0].len == 8) && |
688 | 690 | (cf->io.win[0].base != 0)) { | |
689 | return pcmcia_parse_tuple(handle, tuple, parse); | 691 | p_dev->conf.ConfigIndex = cf->index; |
690 | } | 692 | p_dev->io.BasePort1 = cf->io.win[0].base; |
691 | 693 | p_dev->io.IOAddrLines = (try == 0) ? 16 : | |
692 | static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse) | 694 | cf->io.flags & CISTPL_IO_LINES_MASK; |
693 | { | 695 | if (!pcmcia_request_io(p_dev, &p_dev->io)) |
694 | if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS) | 696 | return 0; |
695 | return CS_NO_MORE_ITEMS; | 697 | } |
696 | return get_tuple(handle, tuple, parse); | 698 | return -ENODEV; |
697 | } | 699 | } |
698 | 700 | ||
699 | static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse) | 701 | static int bt3c_check_config_notpicky(struct pcmcia_device *p_dev, |
702 | cistpl_cftable_entry_t *cf, | ||
703 | void *priv_data) | ||
700 | { | 704 | { |
701 | if (pcmcia_get_next_tuple(handle, tuple) != CS_SUCCESS) | 705 | static unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 }; |
702 | return CS_NO_MORE_ITEMS; | 706 | int j; |
703 | return get_tuple(handle, tuple, parse); | 707 | |
708 | if ((cf->io.nwin > 0) && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) { | ||
709 | p_dev->conf.ConfigIndex = cf->index; | ||
710 | for (j = 0; j < 5; j++) { | ||
711 | p_dev->io.BasePort1 = base[j]; | ||
712 | p_dev->io.IOAddrLines = base[j] ? 16 : 3; | ||
713 | if (!pcmcia_request_io(p_dev, &p_dev->io)) | ||
714 | return 0; | ||
715 | } | ||
716 | } | ||
717 | return -ENODEV; | ||
704 | } | 718 | } |
705 | 719 | ||
706 | static int bt3c_config(struct pcmcia_device *link) | 720 | static int bt3c_config(struct pcmcia_device *link) |
707 | { | 721 | { |
708 | static unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 }; | ||
709 | bt3c_info_t *info = link->priv; | 722 | bt3c_info_t *info = link->priv; |
710 | tuple_t tuple; | 723 | int i; |
711 | u_short buf[256]; | 724 | unsigned long try; |
712 | cisparse_t parse; | 725 | |
713 | cistpl_cftable_entry_t *cf = &parse.cftable_entry; | 726 | /* First pass: look for a config entry that looks normal. |
714 | int i, j, try; | 727 | Two tries: without IO aliases, then with aliases */ |
715 | 728 | for (try = 0; try < 2; try++) | |
716 | /* First pass: look for a config entry that looks normal. */ | 729 | if (!pcmcia_loop_config(link, bt3c_check_config, (void *) try)) |
717 | tuple.TupleData = (cisdata_t *)buf; | 730 | goto found_port; |
718 | tuple.TupleOffset = 0; | ||
719 | tuple.TupleDataMax = 255; | ||
720 | tuple.Attributes = 0; | ||
721 | tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; | ||
722 | /* Two tries: without IO aliases, then with aliases */ | ||
723 | for (try = 0; try < 2; try++) { | ||
724 | i = first_tuple(link, &tuple, &parse); | ||
725 | while (i != CS_NO_MORE_ITEMS) { | ||
726 | if (i != CS_SUCCESS) | ||
727 | goto next_entry; | ||
728 | if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM)) | ||
729 | link->conf.Vpp = cf->vpp1.param[CISTPL_POWER_VNOM] / 10000; | ||
730 | if ((cf->io.nwin > 0) && (cf->io.win[0].len == 8) && (cf->io.win[0].base != 0)) { | ||
731 | link->conf.ConfigIndex = cf->index; | ||
732 | link->io.BasePort1 = cf->io.win[0].base; | ||
733 | link->io.IOAddrLines = (try == 0) ? 16 : cf->io.flags & CISTPL_IO_LINES_MASK; | ||
734 | i = pcmcia_request_io(link, &link->io); | ||
735 | if (i == CS_SUCCESS) | ||
736 | goto found_port; | ||
737 | } | ||
738 | next_entry: | ||
739 | i = next_tuple(link, &tuple, &parse); | ||
740 | } | ||
741 | } | ||
742 | 731 | ||
743 | /* Second pass: try to find an entry that isn't picky about | 732 | /* Second pass: try to find an entry that isn't picky about |
744 | its base address, then try to grab any standard serial port | 733 | its base address, then try to grab any standard serial port |
745 | address, and finally try to get any free port. */ | 734 | address, and finally try to get any free port. */ |
746 | i = first_tuple(link, &tuple, &parse); | 735 | if (!pcmcia_loop_config(link, bt3c_check_config_notpicky, NULL)) |
747 | while (i != CS_NO_MORE_ITEMS) { | 736 | goto found_port; |
748 | if ((i == CS_SUCCESS) && (cf->io.nwin > 0) && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) { | ||
749 | link->conf.ConfigIndex = cf->index; | ||
750 | for (j = 0; j < 5; j++) { | ||
751 | link->io.BasePort1 = base[j]; | ||
752 | link->io.IOAddrLines = base[j] ? 16 : 3; | ||
753 | i = pcmcia_request_io(link, &link->io); | ||
754 | if (i == CS_SUCCESS) | ||
755 | goto found_port; | ||
756 | } | ||
757 | } | ||
758 | i = next_tuple(link, &tuple, &parse); | ||
759 | } | ||
760 | 737 | ||
761 | found_port: | 738 | BT_ERR("No usable port range found"); |
762 | if (i != CS_SUCCESS) { | 739 | cs_error(link, RequestIO, -ENODEV); |
763 | BT_ERR("No usable port range found"); | 740 | goto failed; |
764 | cs_error(link, RequestIO, i); | ||
765 | goto failed; | ||
766 | } | ||
767 | 741 | ||
742 | found_port: | ||
768 | i = pcmcia_request_irq(link, &link->irq); | 743 | i = pcmcia_request_irq(link, &link->irq); |
769 | if (i != CS_SUCCESS) { | 744 | if (i != CS_SUCCESS) { |
770 | cs_error(link, RequestIRQ, i); | 745 | cs_error(link, RequestIRQ, i); |
diff --git a/drivers/bluetooth/btuart_cs.c b/drivers/bluetooth/btuart_cs.c index 68d1d258e6a4..39cca285152d 100644 --- a/drivers/bluetooth/btuart_cs.c +++ b/drivers/bluetooth/btuart_cs.c | |||
@@ -607,94 +607,69 @@ static void btuart_detach(struct pcmcia_device *link) | |||
607 | kfree(info); | 607 | kfree(info); |
608 | } | 608 | } |
609 | 609 | ||
610 | static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse) | 610 | static int btuart_check_config(struct pcmcia_device *p_dev, |
611 | cistpl_cftable_entry_t *cf, | ||
612 | void *priv_data) | ||
611 | { | 613 | { |
612 | int i; | 614 | unsigned long try = (unsigned long) priv_data; |
613 | 615 | ||
614 | i = pcmcia_get_tuple_data(handle, tuple); | 616 | if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM)) |
615 | if (i != CS_SUCCESS) | 617 | p_dev->conf.Vpp = cf->vpp1.param[CISTPL_POWER_VNOM] / 10000; |
616 | return i; | 618 | if ((cf->io.nwin > 0) && (cf->io.win[0].len == 8) && |
617 | 619 | (cf->io.win[0].base != 0)) { | |
618 | return pcmcia_parse_tuple(handle, tuple, parse); | 620 | p_dev->conf.ConfigIndex = cf->index; |
619 | } | 621 | p_dev->io.BasePort1 = cf->io.win[0].base; |
620 | 622 | p_dev->io.IOAddrLines = (try == 0) ? 16 : | |
621 | static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse) | 623 | cf->io.flags & CISTPL_IO_LINES_MASK; |
622 | { | 624 | if (!pcmcia_request_io(p_dev, &p_dev->io)) |
623 | if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS) | 625 | return 0; |
624 | return CS_NO_MORE_ITEMS; | 626 | } |
625 | return get_tuple(handle, tuple, parse); | 627 | return -ENODEV; |
626 | } | 628 | } |
627 | 629 | ||
628 | static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse) | 630 | static int btuart_check_config_notpicky(struct pcmcia_device *p_dev, |
631 | cistpl_cftable_entry_t *cf, | ||
632 | void *priv_data) | ||
629 | { | 633 | { |
630 | if (pcmcia_get_next_tuple(handle, tuple) != CS_SUCCESS) | 634 | static unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 }; |
631 | return CS_NO_MORE_ITEMS; | 635 | int j; |
632 | return get_tuple(handle, tuple, parse); | 636 | |
637 | if ((cf->io.nwin > 0) && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) { | ||
638 | p_dev->conf.ConfigIndex = cf->index; | ||
639 | for (j = 0; j < 5; j++) { | ||
640 | p_dev->io.BasePort1 = base[j]; | ||
641 | p_dev->io.IOAddrLines = base[j] ? 16 : 3; | ||
642 | if (!pcmcia_request_io(p_dev, &p_dev->io)) | ||
643 | return 0; | ||
644 | } | ||
645 | } | ||
646 | return -ENODEV; | ||
633 | } | 647 | } |
634 | 648 | ||
635 | static int btuart_config(struct pcmcia_device *link) | 649 | static int btuart_config(struct pcmcia_device *link) |
636 | { | 650 | { |
637 | static unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 }; | ||
638 | btuart_info_t *info = link->priv; | 651 | btuart_info_t *info = link->priv; |
639 | tuple_t tuple; | 652 | int i; |
640 | u_short buf[256]; | 653 | unsigned long try; |
641 | cisparse_t parse; | 654 | |
642 | cistpl_cftable_entry_t *cf = &parse.cftable_entry; | 655 | /* First pass: look for a config entry that looks normal. |
643 | int i, j, try; | 656 | Two tries: without IO aliases, then with aliases */ |
644 | 657 | for (try = 0; try < 2; try++) | |
645 | /* First pass: look for a config entry that looks normal. */ | 658 | if (!pcmcia_loop_config(link, btuart_check_config, |
646 | tuple.TupleData = (cisdata_t *) buf; | 659 | (void *) try)) |
647 | tuple.TupleOffset = 0; | 660 | goto found_port; |
648 | tuple.TupleDataMax = 255; | ||
649 | tuple.Attributes = 0; | ||
650 | tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; | ||
651 | /* Two tries: without IO aliases, then with aliases */ | ||
652 | for (try = 0; try < 2; try++) { | ||
653 | i = first_tuple(link, &tuple, &parse); | ||
654 | while (i != CS_NO_MORE_ITEMS) { | ||
655 | if (i != CS_SUCCESS) | ||
656 | goto next_entry; | ||
657 | if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM)) | ||
658 | link->conf.Vpp = cf->vpp1.param[CISTPL_POWER_VNOM] / 10000; | ||
659 | if ((cf->io.nwin > 0) && (cf->io.win[0].len == 8) && (cf->io.win[0].base != 0)) { | ||
660 | link->conf.ConfigIndex = cf->index; | ||
661 | link->io.BasePort1 = cf->io.win[0].base; | ||
662 | link->io.IOAddrLines = (try == 0) ? 16 : cf->io.flags & CISTPL_IO_LINES_MASK; | ||
663 | i = pcmcia_request_io(link, &link->io); | ||
664 | if (i == CS_SUCCESS) | ||
665 | goto found_port; | ||
666 | } | ||
667 | next_entry: | ||
668 | i = next_tuple(link, &tuple, &parse); | ||
669 | } | ||
670 | } | ||
671 | 661 | ||
672 | /* Second pass: try to find an entry that isn't picky about | 662 | /* Second pass: try to find an entry that isn't picky about |
673 | its base address, then try to grab any standard serial port | 663 | its base address, then try to grab any standard serial port |
674 | address, and finally try to get any free port. */ | 664 | address, and finally try to get any free port. */ |
675 | i = first_tuple(link, &tuple, &parse); | 665 | if (!pcmcia_loop_config(link, btuart_check_config_notpicky, NULL)) |
676 | while (i != CS_NO_MORE_ITEMS) { | 666 | goto found_port; |
677 | if ((i == CS_SUCCESS) && (cf->io.nwin > 0) | ||
678 | && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) { | ||
679 | link->conf.ConfigIndex = cf->index; | ||
680 | for (j = 0; j < 5; j++) { | ||
681 | link->io.BasePort1 = base[j]; | ||
682 | link->io.IOAddrLines = base[j] ? 16 : 3; | ||
683 | i = pcmcia_request_io(link, &link->io); | ||
684 | if (i == CS_SUCCESS) | ||
685 | goto found_port; | ||
686 | } | ||
687 | } | ||
688 | i = next_tuple(link, &tuple, &parse); | ||
689 | } | ||
690 | 667 | ||
691 | found_port: | 668 | BT_ERR("No usable port range found"); |
692 | if (i != CS_SUCCESS) { | 669 | cs_error(link, RequestIO, -ENODEV); |
693 | BT_ERR("No usable port range found"); | 670 | goto failed; |
694 | cs_error(link, RequestIO, i); | ||
695 | goto failed; | ||
696 | } | ||
697 | 671 | ||
672 | found_port: | ||
698 | i = pcmcia_request_irq(link, &link->irq); | 673 | i = pcmcia_request_irq(link, &link->irq); |
699 | if (i != CS_SUCCESS) { | 674 | if (i != CS_SUCCESS) { |
700 | cs_error(link, RequestIRQ, i); | 675 | cs_error(link, RequestIRQ, i); |
diff --git a/drivers/bluetooth/dtl1_cs.c b/drivers/bluetooth/dtl1_cs.c index dae45cdf02b2..e30a6332c6c6 100644 --- a/drivers/bluetooth/dtl1_cs.c +++ b/drivers/bluetooth/dtl1_cs.c | |||
@@ -590,66 +590,30 @@ static void dtl1_detach(struct pcmcia_device *link) | |||
590 | kfree(info); | 590 | kfree(info); |
591 | } | 591 | } |
592 | 592 | ||
593 | static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse) | 593 | static int dtl1_confcheck(struct pcmcia_device *p_dev, |
594 | cistpl_cftable_entry_t *cf, | ||
595 | void *priv_data) | ||
594 | { | 596 | { |
595 | int i; | 597 | if ((cf->io.nwin == 1) && (cf->io.win[0].len > 8)) { |
596 | 598 | p_dev->conf.ConfigIndex = cf->index; | |
597 | i = pcmcia_get_tuple_data(handle, tuple); | 599 | p_dev->io.BasePort1 = cf->io.win[0].base; |
598 | if (i != CS_SUCCESS) | 600 | p_dev->io.NumPorts1 = cf->io.win[0].len; /*yo */ |
599 | return i; | 601 | p_dev->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK; |
600 | 602 | if (!pcmcia_request_io(p_dev, &p_dev->io)) | |
601 | return pcmcia_parse_tuple(handle, tuple, parse); | 603 | return 0; |
602 | } | 604 | } |
603 | 605 | return -ENODEV; | |
604 | static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse) | ||
605 | { | ||
606 | if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS) | ||
607 | return CS_NO_MORE_ITEMS; | ||
608 | return get_tuple(handle, tuple, parse); | ||
609 | } | ||
610 | |||
611 | static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse) | ||
612 | { | ||
613 | if (pcmcia_get_next_tuple(handle, tuple) != CS_SUCCESS) | ||
614 | return CS_NO_MORE_ITEMS; | ||
615 | return get_tuple(handle, tuple, parse); | ||
616 | } | 606 | } |
617 | 607 | ||
618 | static int dtl1_config(struct pcmcia_device *link) | 608 | static int dtl1_config(struct pcmcia_device *link) |
619 | { | 609 | { |
620 | dtl1_info_t *info = link->priv; | 610 | dtl1_info_t *info = link->priv; |
621 | tuple_t tuple; | ||
622 | u_short buf[256]; | ||
623 | cisparse_t parse; | ||
624 | cistpl_cftable_entry_t *cf = &parse.cftable_entry; | ||
625 | int i; | 611 | int i; |
626 | 612 | ||
627 | tuple.TupleData = (cisdata_t *)buf; | ||
628 | tuple.TupleOffset = 0; | ||
629 | tuple.TupleDataMax = 255; | ||
630 | tuple.Attributes = 0; | ||
631 | tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; | ||
632 | |||
633 | /* Look for a generic full-sized window */ | 613 | /* Look for a generic full-sized window */ |
634 | link->io.NumPorts1 = 8; | 614 | link->io.NumPorts1 = 8; |
635 | i = first_tuple(link, &tuple, &parse); | 615 | if (!pcmcia_loop_config(link, dtl1_confcheck, NULL)) |
636 | while (i != CS_NO_MORE_ITEMS) { | ||
637 | if ((i == CS_SUCCESS) && (cf->io.nwin == 1) && (cf->io.win[0].len > 8)) { | ||
638 | link->conf.ConfigIndex = cf->index; | ||
639 | link->io.BasePort1 = cf->io.win[0].base; | ||
640 | link->io.NumPorts1 = cf->io.win[0].len; /*yo */ | ||
641 | link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK; | ||
642 | i = pcmcia_request_io(link, &link->io); | ||
643 | if (i == CS_SUCCESS) | ||
644 | break; | ||
645 | } | ||
646 | i = next_tuple(link, &tuple, &parse); | ||
647 | } | ||
648 | |||
649 | if (i != CS_SUCCESS) { | ||
650 | cs_error(link, RequestIO, i); | ||
651 | goto failed; | 616 | goto failed; |
652 | } | ||
653 | 617 | ||
654 | i = pcmcia_request_irq(link, &link->irq); | 618 | i = pcmcia_request_irq(link, &link->irq); |
655 | if (i != CS_SUCCESS) { | 619 | if (i != CS_SUCCESS) { |