Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
/*	$NetBSD: plumpcmcia.c,v 1.30 2021/08/07 16:18:54 thorpej Exp $ */

/*
 * Copyright (c) 1999, 2000 UCHIYAMA Yasushi. All rights reserved.
 * Copyright (c) 1997 Marc Horowitz. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by Marc Horowitz.
 * 4. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: plumpcmcia.c,v 1.30 2021/08/07 16:18:54 thorpej Exp $");

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/kthread.h>

#include <machine/bus.h>
#include <machine/config_hook.h>
#include <machine/bus_space_hpcmips.h>

#include <dev/pcmcia/pcmciareg.h>
#include <dev/pcmcia/pcmciavar.h>
#include <dev/pcmcia/pcmciachip.h>

#include <hpcmips/tx/tx39var.h>
#include <hpcmips/dev/plumvar.h>
#include <hpcmips/dev/plumicuvar.h>
#include <hpcmips/dev/plumpowervar.h>
#include <hpcmips/dev/plumpcmciareg.h>

#ifdef	PLUMPCMCIA_DEBUG
#define DPRINTF_ENABLE
#define DPRINTF_DEBUG	plumpcmcia_debug
#endif
#include <machine/debug.h>

int	plumpcmcia_match(device_t, cfdata_t, void *);
void	plumpcmcia_attach(device_t, device_t, void *);
int	plumpcmcia_print(void *, const char *);

int	plumpcmcia_power(void *, int, long, void *);

struct plumpcmcia_softc;

struct plumpcmcia_handle {
	/* parent */
	device_t ph_parent;
	/* child */
	device_t ph_pcmcia;

	/* PCMCIA controller register space */
	bus_space_tag_t ph_regt;
	bus_space_handle_t ph_regh;

	/* I/O port space */
	int ph_ioarea;	/* not PCMCIA window */
	struct {
		bus_addr_t	pi_addr;
		bus_size_t	pi_size;
		int		pi_width;
	} ph_io[PLUM_PCMCIA_IO_WINS];
	int ph_ioalloc;
	bus_space_tag_t ph_iot;
	bus_space_handle_t ph_ioh;
	bus_addr_t ph_iobase;
	bus_size_t ph_iosize;

	/* I/O Memory space */
	int ph_memarea;	/* not PCMCIA window */
	struct {
		bus_addr_t	pm_addr;
		bus_size_t	pm_size;
		int32_t		pm_offset;
		int		pm_kind;
	} ph_mem[PLUM_PCMCIA_MEM_WINS];
	int ph_memalloc;
	bus_space_tag_t ph_memt;
	bus_space_handle_t ph_memh;
	bus_addr_t ph_membase;
	bus_size_t ph_memsize;

	/* Card interrupt handler */
	int ph_plum_irq;
	void *ph_card_ih;
};

enum plumpcmcia_event_type {
	PLUM_PCMCIA_EVENT_INSERT,
	PLUM_PCMCIA_EVENT_REMOVE,
};

struct plumpcmcia_event {
	int __queued;
	enum plumpcmcia_event_type pe_type;
	struct plumpcmcia_handle *pe_ph;
	SIMPLEQ_ENTRY(plumpcmcia_event) pe_link;
};

struct plumpcmcia_softc {
	device_t	sc_dev;
	plum_chipset_tag_t sc_pc;

	/* Register space */
	bus_space_tag_t sc_regt;
	bus_space_handle_t sc_regh;

	/* power management hook */
	void *sc_powerhook;

	/* CSC event */
	lwp_t *sc_event_thread;
	SIMPLEQ_HEAD (, plumpcmcia_event) sc_event_head;

	/* for each slot */
	struct plumpcmcia_handle sc_ph[PLUMPCMCIA_NSLOTS];
};

static void plumpcmcia_attach_socket(struct plumpcmcia_handle *);
static int plumpcmcia_chip_mem_alloc(pcmcia_chipset_handle_t, bus_size_t,
    struct pcmcia_mem_handle *);
static void plumpcmcia_chip_mem_free(pcmcia_chipset_handle_t,
    struct pcmcia_mem_handle *);
static int plumpcmcia_chip_mem_map(pcmcia_chipset_handle_t, int, bus_addr_t,
    bus_size_t, struct pcmcia_mem_handle *,  bus_size_t *, int *);
static void plumpcmcia_chip_mem_unmap(pcmcia_chipset_handle_t, int);
static int plumpcmcia_chip_io_alloc(pcmcia_chipset_handle_t, bus_addr_t,
    bus_size_t, bus_size_t, struct pcmcia_io_handle *);
static void plumpcmcia_chip_io_free(pcmcia_chipset_handle_t,
    struct pcmcia_io_handle *);
static int plumpcmcia_chip_io_map(pcmcia_chipset_handle_t, int, bus_addr_t,
    bus_size_t, struct pcmcia_io_handle *, int *);
static void plumpcmcia_chip_io_unmap(pcmcia_chipset_handle_t, int);
static void plumpcmcia_chip_socket_enable(pcmcia_chipset_handle_t);
static void plumpcmcia_chip_socket_disable(pcmcia_chipset_handle_t);
static void plumpcmcia_chip_socket_settype(pcmcia_chipset_handle_t, int);
static void *plumpcmcia_chip_intr_establish(pcmcia_chipset_handle_t,
    struct pcmcia_function *, int, int (*)(void *), void *);
static void plumpcmcia_chip_intr_disestablish(pcmcia_chipset_handle_t, void *);
static void plumpcmcia_wait_ready(	struct plumpcmcia_handle *);
static void plumpcmcia_chip_do_mem_map(struct plumpcmcia_handle *, int);
static void plumpcmcia_chip_do_io_map(struct plumpcmcia_handle *, int);

static struct pcmcia_chip_functions plumpcmcia_functions = {
	plumpcmcia_chip_mem_alloc,
	plumpcmcia_chip_mem_free,
	plumpcmcia_chip_mem_map,
	plumpcmcia_chip_mem_unmap,
	plumpcmcia_chip_io_alloc,
	plumpcmcia_chip_io_free,
	plumpcmcia_chip_io_map,
	plumpcmcia_chip_io_unmap,
	plumpcmcia_chip_intr_establish,
	plumpcmcia_chip_intr_disestablish,
	plumpcmcia_chip_socket_enable,
	plumpcmcia_chip_socket_disable,
	plumpcmcia_chip_socket_settype,
};

/* CSC */
#define PLUM_PCMCIA_EVENT_QUEUE_MAX		5
static struct plumpcmcia_event __event_queue_pool[PLUM_PCMCIA_EVENT_QUEUE_MAX];
static struct plumpcmcia_event *plumpcmcia_event_alloc(void);
static void plumpcmcia_event_free(struct plumpcmcia_event *);
static void plum_csc_intr_setup(struct plumpcmcia_softc *,
    struct plumpcmcia_handle *, int);
static int plum_csc_intr(void *);
static void plumpcmcia_event_thread(void *);

#ifdef PLUMPCMCIA_DEBUG
/* debug */
#define __DEBUG_FUNC	__attribute__((__unused__))
static void __ioareadump(plumreg_t) __DEBUG_FUNC;
static void __memareadump(plumreg_t) __DEBUG_FUNC;
static void plumpcmcia_dump(struct plumpcmcia_softc *) __DEBUG_FUNC;
#endif /* PLUMPCMCIA_DEBUG */

CFATTACH_DECL_NEW(plumpcmcia, sizeof(struct plumpcmcia_softc),
    plumpcmcia_match, plumpcmcia_attach, NULL, NULL);

int
plumpcmcia_match(device_t parent, cfdata_t cf, void *aux)
{
	return (1);
}

void
plumpcmcia_attach(device_t parent, device_t self, void *aux)
{
	struct plum_attach_args *pa = aux;
	struct plumpcmcia_softc *sc = device_private(self);
	struct plumpcmcia_handle *ph;
	int error __diagused;

	sc->sc_dev = self;
	sc->sc_pc	= pa->pa_pc;
	sc->sc_regt	= pa->pa_regt;

	/* map register area */
	if (bus_space_map(sc->sc_regt, PLUM_PCMCIA_REGBASE, 
	    PLUM_PCMCIA_REGSIZE, 0, &sc->sc_regh)) {
		printf(": register map failed\n");
	}

	/* power control */
	plumpcmcia_power(sc, 0, 0, (void *)PWR_RESUME);
	/* Add a hard power hook to power saving */
#if notyet
	sc->sc_powerhook = config_hook(CONFIG_HOOK_PMEVENT,
	    CONFIG_HOOK_PMEVENT_HARDPOWER,
	    CONFIG_HOOK_SHARE,
	    plumpcmcia_power, sc);
	if (sc->sc_powerhook == 0)
		printf(": WARNING unable to establish hard power hook");
#endif
	printf("\n");

	/* Slot0/1 CSC event queue */
	SIMPLEQ_INIT (&sc->sc_event_head);
	error = kthread_create(PRI_NONE, 0, NULL, plumpcmcia_event_thread,
	    sc, &sc->sc_event_thread, "%s", device_xname(self));
	KASSERT(error == 0);

	/* Slot 0 */
	ph = &sc->sc_ph[0];
	ph->ph_plum_irq	= PLUM_INT_C1IO;
	ph->ph_memarea	= PLUM_PCMCIA_MEMWINCTRL_MAP_AREA1;
	ph->ph_membase	= PLUM_PCMCIA_MEMBASE1;
	ph->ph_memsize	= PLUM_PCMCIA_MEMSIZE1;
	ph->ph_ioarea	= PLUM_PCMCIA_IOWINADDRCTRL_AREA1;
	ph->ph_iobase	= PLUM_PCMCIA_IOBASE1;
	ph->ph_iosize	= PLUM_PCMCIA_IOSIZE1;
	ph->ph_regt = sc->sc_regt;
	bus_space_subregion(sc->sc_regt, sc->sc_regh, 
	    PLUM_PCMCIA_REGSPACE_SLOT0,
	    PLUM_PCMCIA_REGSPACE_SIZE,
	    &ph->ph_regh);
	ph->ph_iot	= pa->pa_iot;
	ph->ph_memt	= pa->pa_iot;
	ph->ph_parent = self;

	plum_csc_intr_setup(sc, ph, PLUM_INT_C1SC);
	plum_power_establish(sc->sc_pc, PLUM_PWR_PCC1);
	plumpcmcia_attach_socket(ph);

	/* Slot 1 */
	ph = &sc->sc_ph[1];
	ph->ph_plum_irq	= PLUM_INT_C2IO;
	ph->ph_memarea	= PLUM_PCMCIA_MEMWINCTRL_MAP_AREA2;
	ph->ph_membase	= PLUM_PCMCIA_MEMBASE2;
	ph->ph_memsize	= PLUM_PCMCIA_MEMSIZE2;
	ph->ph_ioarea	= PLUM_PCMCIA_IOWINADDRCTRL_AREA2;
	ph->ph_iobase	= PLUM_PCMCIA_IOBASE2;
	ph->ph_iosize	= PLUM_PCMCIA_IOSIZE2;
	ph->ph_regt = sc->sc_regt;
	bus_space_subregion(sc->sc_regt, sc->sc_regh, 
	    PLUM_PCMCIA_REGSPACE_SLOT1,
	    PLUM_PCMCIA_REGSPACE_SIZE,
	    &ph->ph_regh);
	ph->ph_iot	= pa->pa_iot;
	ph->ph_memt	= pa->pa_iot;
	ph->ph_parent = self;

	plum_csc_intr_setup(sc, ph, PLUM_INT_C2SC);
	plum_power_establish(sc->sc_pc, PLUM_PWR_PCC2);
	plumpcmcia_attach_socket(ph);
}

int
plumpcmcia_print(void *arg, const char *pnp)
{
	if (pnp) {
		aprint_normal("pcmcia at %s", pnp);
	}

	return (UNCONF);
}

static void
plumpcmcia_attach_socket(struct plumpcmcia_handle *ph)
{
	struct pcmciabus_attach_args paa;

	paa.paa_busname = "pcmcia";
	paa.pct = (pcmcia_chipset_tag_t)&plumpcmcia_functions;
	paa.pch = (pcmcia_chipset_handle_t)ph;

	if ((ph->ph_pcmcia = config_found(ph->ph_parent, &paa, plumpcmcia_print,
					  CFARGS_NONE))) {
		/* Enable slot */
		plum_conf_write(ph->ph_regt, ph->ph_regh,
		    PLUM_PCMCIA_SLOTCTRL,
		    PLUM_PCMCIA_SLOTCTRL_ENABLE);
		/* Support 3.3V card & enable Voltage Sense Status */
		plum_conf_write(ph->ph_regt, ph->ph_regh,
		    PLUM_PCMCIA_FUNCCTRL,
		    PLUM_PCMCIA_FUNCCTRL_VSSEN |
		    PLUM_PCMCIA_FUNCCTRL_3VSUPPORT);
		pcmcia_card_attach(ph->ph_pcmcia);		
	}
}

static void *
plumpcmcia_chip_intr_establish(pcmcia_chipset_handle_t pch,
    struct pcmcia_function *pf, int ipl,
    int (*ih_fun)(void *), void *ih_arg)
{
	struct plumpcmcia_handle *ph = (void *)pch;
	struct plumpcmcia_softc *sc = device_private(ph->ph_parent);

	if (!(ph->ph_card_ih = 
	    plum_intr_establish(sc->sc_pc, ph->ph_plum_irq,
		IST_EDGE, IPL_BIO, ih_fun, ih_arg))) {
		printf("plumpcmcia_chip_intr_establish: can't establish\n");
		return (0);
	}

	return (ph->ph_card_ih);
}

static void 
plumpcmcia_chip_intr_disestablish(pcmcia_chipset_handle_t pch, void *ih)
{
	struct plumpcmcia_handle *ph = pch;
	struct plumpcmcia_softc *sc = device_private(ph->ph_parent);

	plum_intr_disestablish(sc->sc_pc, ih);
}

static int
plumpcmcia_chip_mem_alloc(pcmcia_chipset_handle_t pch, bus_size_t size,
    struct pcmcia_mem_handle *pcmhp)
{
	struct plumpcmcia_handle *ph = (void*)pch;
	bus_size_t realsize;

	/* convert size to PCIC pages */
	realsize = ((size + (PLUM_PCMCIA_MEM_PAGESIZE - 1)) / 
	    PLUM_PCMCIA_MEM_PAGESIZE) * PLUM_PCMCIA_MEM_PAGESIZE;

	if (bus_space_alloc(ph->ph_memt, ph->ph_membase,
	    ph->ph_membase + ph->ph_memsize, 
	    realsize, PLUM_PCMCIA_MEM_PAGESIZE, 
	    0, 0, 0, &pcmhp->memh)) {
		return (1);
	}

	pcmhp->memt = ph->ph_memt;
	/* Address offset from MEM area base */
	pcmhp->addr = pcmhp->memh - ph->ph_membase - 
	    ((struct bus_space_tag_hpcmips*)ph->ph_memt)->base;
	pcmhp->size = size;
	pcmhp->realsize = realsize;

	DPRINTF(("plumpcmcia_chip_mem_alloc: size %#x->%#x addr %#x->%#x\n", 
	    (unsigned)size, (unsigned)realsize, (unsigned)pcmhp->addr,
	    (unsigned)pcmhp->memh));

	return (0);
}

static void
plumpcmcia_chip_mem_free(pcmcia_chipset_handle_t pch,
    struct pcmcia_mem_handle *pcmhp)
{

	bus_space_free(pcmhp->memt, pcmhp->memh, pcmhp->size);
}

static int
plumpcmcia_chip_mem_map(pcmcia_chipset_handle_t pch, int kind,
    bus_addr_t card_addr, bus_size_t size,
    struct pcmcia_mem_handle *pcmhp,
    bus_size_t *offsetp, int *windowp)
{
	struct plumpcmcia_handle *ph = (void*)pch;
	bus_addr_t busaddr;
	int32_t card_offset;
	int i, win;

	for (win = -1, i = 0; i < PLUM_PCMCIA_MEM_WINS; i++) {
		if ((ph->ph_memalloc & (1 << i)) == 0) {
			win = i;
			ph->ph_memalloc |= (1 << i);
			break;
		}
	}
	if (win == -1) {
		DPRINTF(("plumpcmcia_chip_mem_map: no window\n"));
		return (1);
	}

	busaddr = pcmhp->addr;

	*offsetp = card_addr % PLUM_PCMCIA_MEM_PAGESIZE;
	card_addr -= *offsetp;
	size += *offsetp - 1;
	*windowp = win;
	card_offset = (((int32_t)card_addr) - ((int32_t)busaddr));

	DPRINTF(("plumpcmcia_chip_mem_map window %d bus %#x(kv:%#x)+%#x"
	    " size %#x at card addr %#x offset %#x\n", win,
	    (unsigned)busaddr, (unsigned)pcmhp->memh, (unsigned)*offsetp,
	    (unsigned)size, (unsigned)card_addr, (unsigned)card_offset));

	ph->ph_mem[win].pm_addr = busaddr;
	ph->ph_mem[win].pm_size = size;
	ph->ph_mem[win].pm_offset = card_offset;
	ph->ph_mem[win].pm_kind = kind;
	ph->ph_memalloc |= (1 << win);

	plumpcmcia_chip_do_mem_map(ph, win);

	return (0);
}

static void
plumpcmcia_chip_do_mem_map(struct plumpcmcia_handle *ph, int win)
{
	bus_space_tag_t regt = ph->ph_regt;
	bus_space_handle_t regh = ph->ph_regh;
	plumreg_t reg, addr, offset, size;
	
	if (win < 0 || win > 4) {
		panic("plumpcmcia_chip_do_mem_map: bogus window %d", win);
	}

	addr = (ph->ph_mem[win].pm_addr) >> PLUM_PCMCIA_MEM_SHIFT;
	size = (ph->ph_mem[win].pm_size) >> PLUM_PCMCIA_MEM_SHIFT;
	offset = (ph->ph_mem[win].pm_offset) >> PLUM_PCMCIA_MEM_SHIFT;
	
	/* Attribute memory or not */
	reg = ph->ph_mem[win].pm_kind == PCMCIA_MEM_ATTR ?
	    PLUM_PCMCIA_MEMWINCTRL_REGACTIVE : 0;

	/* Notify I/O area to select for PCMCIA controller */
	reg = PLUM_PCMCIA_MEMWINCTRL_MAP_SET(reg, ph->ph_memarea);

	/* Zero wait & 16bit access */
	reg |= (PLUM_PCMCIA_MEMWINCTRL_ZERO_WS |
	    PLUM_PCMCIA_MEMWINCTRL_DATASIZE16);
	plum_conf_write(regt, regh, PLUM_PCMCIA_MEMWINCTRL(win), reg);

	/* Map Host <-> PC-Card address */

	/* host-side */
	plum_conf_write(regt, regh, PLUM_PCMCIA_MEMWINSTARTADDR(win), 
	    addr);
	plum_conf_write(regt, regh, PLUM_PCMCIA_MEMWINSTOPADDR(win), 
	    addr + size);

	/* card-side */
	plum_conf_write(regt, regh, PLUM_PCMCIA_MEMWINOFSADDR(win), offset);

	/* Enable memory window */
	reg = plum_conf_read(regt, regh, PLUM_PCMCIA_WINEN);
	reg |= PLUM_PCMCIA_WINEN_MEM(win);
	plum_conf_write(regt, regh, PLUM_PCMCIA_WINEN, reg);
	
	DPRINTF(("plumpcmcia_chip_do_mem_map: window:%d %#x(%#x)+%#x\n",
	    win, offset, addr, size));

	delay(100);
}

static void
plumpcmcia_chip_mem_unmap(pcmcia_chipset_handle_t pch, int window)
{
	struct plumpcmcia_handle *ph = (void*)pch;
	bus_space_tag_t regt = ph->ph_regt;
	bus_space_handle_t regh = ph->ph_regh;
	plumreg_t reg;
	
	reg = plum_conf_read(regt, regh, PLUM_PCMCIA_WINEN);
	reg &= ~PLUM_PCMCIA_WINEN_MEM(window);
	plum_conf_write(regt, regh, PLUM_PCMCIA_WINEN, reg);

	ph->ph_memalloc &= ~(1 << window);
}

static int
plumpcmcia_chip_io_alloc(pcmcia_chipset_handle_t pch, bus_addr_t start,
    bus_size_t size, bus_size_t align,
    struct pcmcia_io_handle *pcihp)
{
	struct plumpcmcia_handle *ph = (void*)pch;

	DPRINTF(("plumpcmcia_chip_io_alloc: start=%#x size=%#x ",
	    (unsigned)start, (unsigned)size));
	if (start) {
		if (bus_space_map(ph->ph_iot, ph->ph_iobase + start, 
		    size, 0, &pcihp->ioh)) {
			DPRINTF(("bus_space_map failed\n"));
			return (1);
		}
		pcihp->flags = 0;
		pcihp->addr = start;
		DPRINTF(("(mapped) %#x+%#x\n", (unsigned)start,
		    (unsigned)size));
	} else {
		if (bus_space_alloc(ph->ph_iot, ph->ph_iobase,
		    ph->ph_iobase + ph->ph_iosize, size, 
		    align, 0, 0, 0, &pcihp->ioh)) {
			DPRINTF(("bus_space_alloc failed\n"));
			return 1;
		}
		/* Address offset from IO area base */
		pcihp->addr = pcihp->ioh - ph->ph_iobase - 
		    ((struct bus_space_tag_hpcmips*)ph->ph_iot)->base;
		pcihp->flags = PCMCIA_IO_ALLOCATED;
		DPRINTF(("(allocated) %#x+%#x\n", (unsigned)pcihp->addr,
		    (unsigned)size));
	}
	
	pcihp->iot = ph->ph_iot;
	pcihp->size = size;
	
	return (0);
}

static int
plumpcmcia_chip_io_map(pcmcia_chipset_handle_t pch, int width,
    bus_addr_t offset, bus_size_t size,
    struct pcmcia_io_handle *pcihp, int *windowp)
{
#ifdef PLUMPCMCIA_DEBUG
	static char *width_names[] = { "auto", "io8", "io16" };
#endif /* PLUMPCMCIA_DEBUG */
	struct plumpcmcia_handle *ph = (void*)pch;
	bus_addr_t winofs;
	int i, win;

	winofs = pcihp->addr + offset;

	if (winofs > 0x3ff) {
		printf("plumpcmcia_chip_io_map: WARNING port %#lx > 0x3ff\n",
		    winofs);
	}

	for (win = -1, i = 0; i < PLUM_PCMCIA_IO_WINS; i++) {
		if ((ph->ph_ioalloc & (1 << i)) == 0) {
			win = i;
			ph->ph_ioalloc |= (1 << i);
			break;
		}
	}
	if (win == -1) {
		DPRINTF(("plumpcmcia_chip_io_map: no window\n"));
		return (1);
	}
	*windowp = win;

	ph->ph_io[win].pi_addr = winofs;
	ph->ph_io[win].pi_size = size;
	ph->ph_io[win].pi_width = width;

	plumpcmcia_chip_do_io_map(ph, win);

	DPRINTF(("plumpcmcia_chip_io_map: %#x(kv:%#x)+%#x %s\n", 
	    (unsigned)offset, (unsigned)pcihp->ioh, (unsigned)size,
	    width_names[width]));

	return (0);
}

static void
plumpcmcia_chip_do_io_map(struct plumpcmcia_handle *ph, int win)
{
	bus_space_tag_t regt = ph->ph_regt;
	bus_space_handle_t regh = ph->ph_regh;
	plumreg_t reg;
	bus_addr_t addr;
	bus_size_t size;
	int shift;
	plumreg_t ioctlbits[3] = {
		PLUM_PCMCIA_IOWINCTRL_IOCS16SRC,
		0,
		PLUM_PCMCIA_IOWINCTRL_DATASIZE16
	};
	
	if (win < 0 || win > 1) {
		panic("plumpcmcia_chip_do_io_map: bogus window %d", win);
	}

	addr = ph->ph_io[win].pi_addr;
	size = ph->ph_io[win].pi_size;

	/* Notify I/O area to select for PCMCIA controller */
	plum_conf_write(regt, regh, PLUM_PCMCIA_IOWINADDRCTRL(win), 
	    ph->ph_ioarea);

	/* Start/Stop addr */
	plum_conf_write(regt, regh, PLUM_PCMCIA_IOWINSTARTADDR(win), addr);
	plum_conf_write(regt, regh, PLUM_PCMCIA_IOWINSTOPADDR(win), 
	    addr + size - 1);
	
	/* Set bus width */
	reg = plum_conf_read(regt, regh, PLUM_PCMCIA_IOWINCTRL);
	shift = win == 0 ? PLUM_PCMCIA_IOWINCTRL_WIN0SHIFT :
	    PLUM_PCMCIA_IOWINCTRL_WIN1SHIFT;
	
	reg &= ~(PLUM_PCMCIA_IOWINCTRL_WINMASK << shift);
	reg |= ((ioctlbits[ph->ph_io[win].pi_width] |
	    PLUM_PCMCIA_IOWINCTRL_ZEROWAIT) << shift);
	plum_conf_write(regt, regh, PLUM_PCMCIA_IOWINCTRL, reg);
	
	/* Enable window */
	reg = plum_conf_read(regt, regh, PLUM_PCMCIA_WINEN);
	reg |= (win == 0 ? PLUM_PCMCIA_WINEN_IO0 :
	    PLUM_PCMCIA_WINEN_IO1);
	plum_conf_write(regt, regh, PLUM_PCMCIA_WINEN, reg);

	delay(100);
}

static void
plumpcmcia_chip_io_free(pcmcia_chipset_handle_t pch,
    struct pcmcia_io_handle *pcihp)
{
	if (pcihp->flags & PCMCIA_IO_ALLOCATED) {
		bus_space_free(pcihp->iot, pcihp->ioh, pcihp->size);
	} else {
		bus_space_unmap(pcihp->iot, pcihp->ioh, pcihp->size);
	}

	DPRINTF(("plumpcmcia_chip_io_free %#x+%#x\n", pcihp->ioh, 
	    (unsigned)pcihp->size));
}

static void
plumpcmcia_chip_io_unmap(pcmcia_chipset_handle_t pch, int window)
{
	struct plumpcmcia_handle *ph = (void*)pch;
	bus_space_tag_t regt = ph->ph_regt;
	bus_space_handle_t regh = ph->ph_regh;
	plumreg_t reg;
	
	reg = plum_conf_read(regt, regh, PLUM_PCMCIA_WINEN);
	switch (window) {
	default:
		panic("plumpcmcia_chip_io_unmap: bogus window");
	case 0:
		reg &= ~PLUM_PCMCIA_WINEN_IO0;
		break;
	case 1:
		reg &= ~PLUM_PCMCIA_WINEN_IO1;
		break;
	}
	plum_conf_write(regt, regh, PLUM_PCMCIA_WINEN, reg);
	ph->ph_ioalloc &= ~(1 << window);
}

static void
plumpcmcia_wait_ready(struct plumpcmcia_handle *ph)
{
	bus_space_tag_t regt = ph->ph_regt;
	bus_space_handle_t regh = ph->ph_regh;
	int i;

	for (i = 0; i < 10000; i++) {
		if ((plum_conf_read(regt, regh, PLUM_PCMCIA_STATUS) & 
		    PLUM_PCMCIA_STATUS_READY) &&
		    (plum_conf_read(regt, regh, PLUM_PCMCIA_STATUS) &
			PLUM_PCMCIA_STATUS_PWROK)) {
			return;
		}
		delay(500);

		if ((i > 5000) && (i % 100 == 99)) {
			printf(".");
		}
	}
	printf("plumpcmcia_wait_ready: failed\n");
}

static void
plumpcmcia_chip_socket_enable(pcmcia_chipset_handle_t pch)
{
	struct plumpcmcia_handle *ph = (void *)pch;
	bus_space_tag_t regt = ph->ph_regt;
	bus_space_handle_t regh = ph->ph_regh;
	plumreg_t reg, power;
	int win;

	/* this bit is mostly stolen from pcic_attach_card */

	/* set card type to memory to disable interrupts */
	reg = plum_conf_read(regt, regh, PLUM_PCMCIA_GENCTRL);
	reg &= ~PLUM_PCMCIA_GENCTRL_CARDTYPE_MASK;
	plum_conf_write(regt, regh, PLUM_PCMCIA_GENCTRL, reg);

	/* zero out the address windows */
	plum_conf_write(regt, regh, PLUM_PCMCIA_WINEN, 0);

	/* power down the socket to reset it, clear the card reset pin */
	plum_conf_write(regt, regh, PLUM_PCMCIA_PWRCTRL, 0);

	/* 
	 * wait 300ms until power fails (Tpf).  Then, wait 100ms since
	 * we are changing Vcc (Toff).
	 */
	delay((300 + 100) * 1000);

	/* 
	 *  power up the socket 
	 */
	/* detect voltage */
	reg = plum_conf_read(regt, regh, PLUM_PCMCIA_GENCTRL2);
	if ((reg & PLUM_PCMCIA_GENCTRL2_VCC5V) == 
	    PLUM_PCMCIA_GENCTRL2_VCC5V) {
		power = PLUM_PCMCIA_PWRCTRL_VCC_CTRLBIT1; /* 5V */
	} else {
		power = PLUM_PCMCIA_PWRCTRL_VCC_CTRLBIT0; /* 3.3V */
	}

	plum_conf_write(regt, regh, PLUM_PCMCIA_PWRCTRL, 
	    PLUM_PCMCIA_PWRCTRL_DISABLE_RESETDRV |
	    power |
	    PLUM_PCMCIA_PWRCTRL_PWR_ENABLE);
	
	/*
	 * wait 100ms until power raise (Tpr) and 20ms to become
	 * stable (Tsu(Vcc)).
	 *
	 * some machines require some more time to be settled
	 * (300ms is added here).
	 */
	delay((100 + 20 + 300) * 1000);

	plum_conf_write(regt, regh, PLUM_PCMCIA_PWRCTRL, 
	    PLUM_PCMCIA_PWRCTRL_DISABLE_RESETDRV |
	    power |
	    PLUM_PCMCIA_PWRCTRL_OE |
	    PLUM_PCMCIA_PWRCTRL_PWR_ENABLE);
	plum_conf_write(regt, regh, PLUM_PCMCIA_GENCTRL, 0);

	/*
	 * hold RESET at least 10us.
	 */
	delay(10);

	/* clear the reset flag */
	plum_conf_write(regt, regh, PLUM_PCMCIA_GENCTRL,
	    PLUM_PCMCIA_GENCTRL_RESET);

	/* wait 20ms as per pc card standard (r2.01) section 4.3.6 */

	delay(20000);

	/* wait for the chip to finish initializing */
	plumpcmcia_wait_ready(ph);

	/* reinstall all the memory and io mappings */
	for (win = 0; win < PLUM_PCMCIA_MEM_WINS; win++) {
		if (ph->ph_memalloc & (1 << win)) {
			plumpcmcia_chip_do_mem_map(ph, win);
		}
	}

	for (win = 0; win < PLUM_PCMCIA_IO_WINS; win++) {
		if (ph->ph_ioalloc & (1 << win)) {
			plumpcmcia_chip_do_io_map(ph, win);
		}
	}
}

static void
plumpcmcia_chip_socket_settype(pcmcia_chipset_handle_t pch, int type)
{
	struct plumpcmcia_handle *ph = (void *)pch;
	bus_space_tag_t regt = ph->ph_regt;
	bus_space_handle_t regh = ph->ph_regh;
	plumreg_t reg;

	/* set the card type */

	reg = plum_conf_read(regt, regh, PLUM_PCMCIA_GENCTRL);
	reg &= ~PLUM_PCMCIA_GENCTRL_CARDTYPE_MASK;
	if (type == PCMCIA_IFTYPE_IO)
		reg |= PLUM_PCMCIA_GENCTRL_CARDTYPE_IO;
	else
		reg |= PLUM_PCMCIA_GENCTRL_CARDTYPE_MEM;

	DPRINTF(("%s: plumpcmcia_chip_socket_enable type %s %02x\n",
	    device_xname(ph->ph_parent), 
	    ((cardtype == PCMCIA_IFTYPE_IO) ? "io" : "mem"), reg));

	plum_conf_write(regt, regh, PLUM_PCMCIA_GENCTRL, reg);
}

static void
plumpcmcia_chip_socket_disable(pcmcia_chipset_handle_t pch)
{
	struct plumpcmcia_handle *ph = (void *)pch;
	bus_space_tag_t regt = ph->ph_regt;
	bus_space_handle_t regh = ph->ph_regh;
	plumreg_t reg;

	/* set card type to memory to disable interrupts */
	reg = plum_conf_read(regt, regh, PLUM_PCMCIA_GENCTRL);
	reg &= ~PLUM_PCMCIA_GENCTRL_CARDTYPE_MASK;
	plum_conf_write(regt, regh, PLUM_PCMCIA_GENCTRL, reg);

	/* zero out the address windows */
	plum_conf_write(regt, regh, PLUM_PCMCIA_WINEN, 0);

	/* power down the socket */
	plum_conf_write(regt, regh, PLUM_PCMCIA_PWRCTRL, 0);

	/*
	 * wait 300ms until power fails (Tpf).
	 */
	delay(300 * 1000);
}

static void
plum_csc_intr_setup(struct plumpcmcia_softc *sc, struct plumpcmcia_handle *ph,
    int irq)
{
	bus_space_tag_t regt = ph->ph_regt;
	bus_space_handle_t regh = ph->ph_regh;
	plumreg_t reg;
	void *ih __diagused;
	
	/* enable CARD DETECT ENABLE only */
	plum_conf_write(regt, regh, PLUM_PCMCIA_CSCINT,
	    PLUM_PCMCIA_CSCINT_CARD_DETECT);

	/* don't use explicit writeback csc interrupt status */
	reg = plum_conf_read(regt, regh, PLUM_PCMCIA_GLOBALCTRL);
	reg &= ~PLUM_PCMCIA_GLOBALCTRL_EXPLICIT_WB_CSC_INT;
	plum_conf_write(regt, regh, PLUM_PCMCIA_GLOBALCTRL, reg);
	
	/* install interrupt handler (don't fail) */
	ih = plum_intr_establish(sc->sc_pc, irq, IST_EDGE, IPL_TTY,
	    plum_csc_intr, ph);
	KASSERT(ih != 0);
}

static int
plum_csc_intr(void *arg)
{
	struct plumpcmcia_handle *ph = arg;
	struct plumpcmcia_softc *sc = device_private(ph->ph_parent);
	struct plumpcmcia_event *pe;
	bus_space_tag_t regt = ph->ph_regt;
	bus_space_handle_t regh = ph->ph_regh;
	plumreg_t reg;
	int flag;

	/* read and clear interrupt status */
	reg = plum_conf_read(regt, regh, PLUM_PCMCIA_CSCINT_STAT);
	if (reg & PLUM_PCMCIA_CSCINT_CARD_DETECT) {
		DPRINTF(("%s: card status change.\n", __func__));
	} else {
		DPRINTF(("%s: unhandled csc event. 0x%02x\n",
		    __func__, reg));
		return (0);
	}

	/* inquire card status (insert or remove) */
	reg = plum_conf_read(regt, regh, PLUM_PCMCIA_STATUS);
	reg &= (PLUM_PCMCIA_STATUS_CD1 | PLUM_PCMCIA_STATUS_CD2);
	if (reg == (PLUM_PCMCIA_STATUS_CD1 | PLUM_PCMCIA_STATUS_CD2)) {
		/* insert */
		flag = PLUM_PCMCIA_EVENT_INSERT;
	} else {
		/* remove */
		flag = PLUM_PCMCIA_EVENT_REMOVE;
	}

	/* queue event to event thread and wakeup. */
	pe = plumpcmcia_event_alloc();
	if (pe == 0) {
		printf("%s: event FIFO overflow (%d).\n", __func__,
		    PLUM_PCMCIA_EVENT_QUEUE_MAX);
		return (0);
	}
	pe->pe_type = flag;
	pe->pe_ph = ph;
	SIMPLEQ_INSERT_TAIL(&sc->sc_event_head, pe, pe_link);
	wakeup(sc);

	return (0);
}

static struct plumpcmcia_event *
plumpcmcia_event_alloc(void)
{
	int i;
	/* I assume called from interrupt context only. so don't lock */
	for (i = 0; i < PLUM_PCMCIA_EVENT_QUEUE_MAX; i++) {
		if (!__event_queue_pool[i].__queued) {
			__event_queue_pool[i].__queued = 1;
			return (&__event_queue_pool[i]);
		}
	}
	return NULL;
}

static void
plumpcmcia_event_free(struct plumpcmcia_event *pe)
{
	/* I assume context is already locked */
	pe->__queued = 0;
}

static void
plumpcmcia_event_thread(void *arg)
{
	struct plumpcmcia_softc *sc = arg;
	struct plumpcmcia_event *pe;
	int s;
	
	while (/*CONSTCOND*/1) { /* XXX shutdown. -uch */
		tsleep(sc, PWAIT, "CSC wait", 0);
		s = spltty();
		while ((pe = SIMPLEQ_FIRST(&sc->sc_event_head))) {
			splx(s);
			switch (pe->pe_type) {
			default:
				printf("%s: unknown event.\n", __func__);
				break;
			case PLUM_PCMCIA_EVENT_INSERT:
				DPRINTF(("%s: insert event.\n", __func__));
				pcmcia_card_attach(pe->pe_ph->ph_pcmcia);
				break;
			case PLUM_PCMCIA_EVENT_REMOVE:
				DPRINTF(("%s: remove event.\n", __func__));
				pcmcia_card_detach(pe->pe_ph->ph_pcmcia,
				    DETACH_FORCE);
				break;
			}
			s = spltty();
			SIMPLEQ_REMOVE_HEAD(&sc->sc_event_head, pe_link);
			plumpcmcia_event_free(pe);
		}
		splx(s);
	}
	/* NOTREACHED */
}

/* power XXX notyet */
int
plumpcmcia_power(void *ctx, int type, long id, void *msg)
{
	struct plumpcmcia_softc *sc = ctx;
	bus_space_tag_t regt = sc->sc_regt;
	bus_space_handle_t regh = sc->sc_regh;
	int why = (int)msg;

	switch (why) {
	case PWR_RESUME:
		DPRINTF(("%s: ON\n", device_xname(sc->sc_dev)));
		/* power on */
		plum_conf_write(regt, regh, PLUM_PCMCIA_CARDPWRCTRL,
		    PLUM_PCMCIA_CARDPWRCTRL_ON);
		break;
	case PWR_SUSPEND:
		/* FALLTHROUGH */
	case PWR_STANDBY:
		plum_conf_write(regt, regh, PLUM_PCMCIA_CARDPWRCTRL,
		    PLUM_PCMCIA_CARDPWRCTRL_OFF);
		DPRINTF(("%s: OFF\n", device_xname(sc->sc_dev)));
		break;
	}

	return (0);
}

#ifdef PLUMPCMCIA_DEBUG
static void
__ioareadump(plumreg_t reg)
{

	if (reg & PLUM_PCMCIA_IOWINADDRCTRL_AREA2) {
		printf("I/O Area 2\n");
	} else {
		printf("I/O Area 1\n");
	}
}

static void
__memareadump(plumreg_t reg)
{
	int maparea;

	maparea = PLUM_PCMCIA_MEMWINCTRL_MAP(reg);
	switch (maparea) {
	case PLUM_PCMCIA_MEMWINCTRL_MAP_AREA1:
		printf("MEM Area1\n");
		break;
	case PLUM_PCMCIA_MEMWINCTRL_MAP_AREA2:
		printf("MEM Area2\n");
		break;
	case PLUM_PCMCIA_MEMWINCTRL_MAP_AREA3:
		printf("MEM Area3\n");
		break;
	case PLUM_PCMCIA_MEMWINCTRL_MAP_AREA4:
		printf("MEM Area4\n");
		break;
	}
}	

static void
plumpcmcia_dump(struct plumpcmcia_softc *sc)
{
	bus_space_tag_t regt = sc->sc_regt;
	bus_space_handle_t regh = sc->sc_regh;
	plumreg_t reg;

	int i, j;
	
	__memareadump(plum_conf_read(regt, regh, PLUM_PCMCIA_MEMWIN0CTRL));
	__memareadump(plum_conf_read(regt, regh, PLUM_PCMCIA_MEMWIN1CTRL));
	__memareadump(plum_conf_read(regt, regh, PLUM_PCMCIA_MEMWIN2CTRL));
	__memareadump(plum_conf_read(regt, regh, PLUM_PCMCIA_MEMWIN3CTRL));
	__memareadump(plum_conf_read(regt, regh, PLUM_PCMCIA_MEMWIN4CTRL));

	__ioareadump(plum_conf_read(regt, regh, PLUM_PCMCIA_IOWIN0ADDRCTRL));
	__ioareadump(plum_conf_read(regt, regh, PLUM_PCMCIA_IOWIN1ADDRCTRL));

	for (j = 0; j < 2; j++) {
		printf("[slot %d]\n", j);
		for (i = 0; i < 0x120; i += 4) {
			reg = plum_conf_read(sc->sc_regt, sc->sc_regh,
			    i + 0x800 * j);
			printf("%03x %08x", i, reg);
			dbg_bit_print(reg);
		}
	}
	printf("\n");
}
#endif /* PLUMPCMCIA_DEBUG */