2 * Driver for the media bay on the PowerBook 3400 and 2400.
4 * Copyright (C) 1998 Paul Mackerras.
6 * Various evolutions by Benjamin Herrenschmidt & Henry Worth
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
13 #include <linux/types.h>
14 #include <linux/errno.h>
15 #include <linux/kernel.h>
16 #include <linux/delay.h>
17 #include <linux/sched.h>
18 #include <linux/timer.h>
19 #include <linux/hdreg.h>
20 #include <linux/stddef.h>
21 #include <linux/init.h>
22 #include <linux/ide.h>
23 #include <linux/kthread.h>
25 #include <asm/pgtable.h>
27 #include <asm/machdep.h>
28 #include <asm/pmac_feature.h>
29 #include <asm/mediabay.h>
30 #include <asm/sections.h>
31 #include <asm/ohare.h>
32 #include <asm/heathrow.h>
33 #include <asm/keylargo.h>
34 #include <linux/adb.h>
35 #include <linux/pmu.h>
41 #define MBDBG(fmt, arg...) printk(KERN_INFO fmt , ## arg)
43 #define MBDBG(fmt, arg...) do { } while (0)
46 #define MB_FCR32(bay, r) ((bay)->base + ((r) >> 2))
47 #define MB_FCR8(bay, r) (((volatile u8 __iomem *)((bay)->base)) + (r))
49 #define MB_IN32(bay,r) (in_le32(MB_FCR32(bay,r)))
50 #define MB_OUT32(bay,r,v) (out_le32(MB_FCR32(bay,r), (v)))
51 #define MB_BIS(bay,r,v) (MB_OUT32((bay), (r), MB_IN32((bay), r) | (v)))
52 #define MB_BIC(bay,r,v) (MB_OUT32((bay), (r), MB_IN32((bay), r) & ~(v)))
53 #define MB_IN8(bay,r) (in_8(MB_FCR8(bay,r)))
54 #define MB_OUT8(bay,r,v) (out_8(MB_FCR8(bay,r), (v)))
56 struct media_bay_info
;
60 void (*init
)(struct media_bay_info
*bay
);
61 u8 (*content
)(struct media_bay_info
*bay
);
62 void (*power
)(struct media_bay_info
*bay
, int on_off
);
63 int (*setup_bus
)(struct media_bay_info
*bay
, u8 device_id
);
64 void (*un_reset
)(struct media_bay_info
*bay
);
65 void (*un_reset_ide
)(struct media_bay_info
*bay
);
68 struct media_bay_info
{
75 struct macio_dev
*mdev
;
80 struct semaphore lock
;
81 #ifdef CONFIG_BLK_DEV_IDE_PMAC
83 void __iomem
*cd_base
;
87 #if defined(CONFIG_BLK_DEV_IDE_PMAC) || defined(CONFIG_MAC_FLOPPY)
94 static struct media_bay_info media_bays
[MAX_BAYS
];
95 int media_bay_count
= 0;
97 #ifdef CONFIG_BLK_DEV_IDE_PMAC
98 /* check the busy bit in the media-bay ide interface
99 (assumes the media-bay contains an ide device) */
100 #define MB_IDE_READY(i) ((readb(media_bays[i].cd_base + 0x70) & 0x80) == 0)
104 * Wait that number of ms between each step in normal polling mode
106 #define MB_POLL_DELAY 25
109 * Consider the media-bay ID value stable if it is the same for
110 * this number of milliseconds
112 #define MB_STABLE_DELAY 100
114 /* Wait after powering up the media bay this delay in ms
115 * timeout bumped for some powerbooks
117 #define MB_POWER_DELAY 200
120 * Hold the media-bay reset signal true for this many ticks
121 * after a device is inserted before releasing it.
123 #define MB_RESET_DELAY 50
126 * Wait this long after the reset signal is released and before doing
127 * further operations. After this delay, the IDE reset signal is released
128 * too for an IDE device
130 #define MB_SETUP_DELAY 100
133 * Wait this many ticks after an IDE device (e.g. CD-ROM) is inserted
134 * (or until the device is ready) before waiting for busy bit to disappear
136 #define MB_IDE_WAIT 1000
139 * Timeout waiting for busy bit of an IDE device to go down
141 #define MB_IDE_TIMEOUT 5000
144 * Max retries of the full power up/down sequence for an IDE device
146 #define MAX_CD_RETRIES 3
149 * States of a media bay
152 mb_empty
= 0, /* Idle */
153 mb_powering_up
, /* power bit set, waiting MB_POWER_DELAY */
154 mb_enabling_bay
, /* enable bits set, waiting MB_RESET_DELAY */
155 mb_resetting
, /* reset bit unset, waiting MB_SETUP_DELAY */
156 mb_ide_resetting
, /* IDE reset bit unser, waiting MB_IDE_WAIT */
157 mb_ide_waiting
, /* Waiting for BUSY bit to go away until MB_IDE_TIMEOUT */
158 mb_up
, /* Media bay full */
159 mb_powering_down
/* Powering down (avoid too fast down/up) */
162 #define MB_POWER_SOUND 0x08
163 #define MB_POWER_FLOPPY 0x04
164 #define MB_POWER_ATA 0x02
165 #define MB_POWER_PCI 0x01
166 #define MB_POWER_OFF 0x00
169 * Functions for polling content of media bay
173 ohare_mb_content(struct media_bay_info
*bay
)
175 return (MB_IN32(bay
, OHARE_MBCR
) >> 12) & 7;
179 heathrow_mb_content(struct media_bay_info
*bay
)
181 return (MB_IN32(bay
, HEATHROW_MBCR
) >> 12) & 7;
185 keylargo_mb_content(struct media_bay_info
*bay
)
189 new_gpio
= MB_IN8(bay
, KL_GPIO_MEDIABAY_IRQ
) & KEYLARGO_GPIO_INPUT_DATA
;
191 bay
->cached_gpio
= new_gpio
;
193 } else if (bay
->cached_gpio
!= new_gpio
) {
194 MB_BIS(bay
, KEYLARGO_MBCR
, KL_MBCR_MB0_ENABLE
);
195 (void)MB_IN32(bay
, KEYLARGO_MBCR
);
197 MB_BIC(bay
, KEYLARGO_MBCR
, 0x0000000F);
198 (void)MB_IN32(bay
, KEYLARGO_MBCR
);
200 bay
->cached_gpio
= new_gpio
;
202 return (MB_IN32(bay
, KEYLARGO_MBCR
) >> 4) & 7;
206 * Functions for powering up/down the bay, puts the bay device
207 * into reset state as well
211 ohare_mb_power(struct media_bay_info
* bay
, int on_off
)
214 /* Power up device, assert it's reset line */
215 MB_BIC(bay
, OHARE_FCR
, OH_BAY_RESET_N
);
216 MB_BIC(bay
, OHARE_FCR
, OH_BAY_POWER_N
);
218 /* Disable all devices */
219 MB_BIC(bay
, OHARE_FCR
, OH_BAY_DEV_MASK
);
220 MB_BIC(bay
, OHARE_FCR
, OH_FLOPPY_ENABLE
);
221 /* Cut power from bay, release reset line */
222 MB_BIS(bay
, OHARE_FCR
, OH_BAY_POWER_N
);
223 MB_BIS(bay
, OHARE_FCR
, OH_BAY_RESET_N
);
224 MB_BIS(bay
, OHARE_FCR
, OH_IDE1_RESET_N
);
226 MB_BIC(bay
, OHARE_MBCR
, 0x00000F00);
230 heathrow_mb_power(struct media_bay_info
* bay
, int on_off
)
233 /* Power up device, assert it's reset line */
234 MB_BIC(bay
, HEATHROW_FCR
, HRW_BAY_RESET_N
);
235 MB_BIC(bay
, HEATHROW_FCR
, HRW_BAY_POWER_N
);
237 /* Disable all devices */
238 MB_BIC(bay
, HEATHROW_FCR
, HRW_BAY_DEV_MASK
);
239 MB_BIC(bay
, HEATHROW_FCR
, HRW_SWIM_ENABLE
);
240 /* Cut power from bay, release reset line */
241 MB_BIS(bay
, HEATHROW_FCR
, HRW_BAY_POWER_N
);
242 MB_BIS(bay
, HEATHROW_FCR
, HRW_BAY_RESET_N
);
243 MB_BIS(bay
, HEATHROW_FCR
, HRW_IDE1_RESET_N
);
245 MB_BIC(bay
, HEATHROW_MBCR
, 0x00000F00);
249 keylargo_mb_power(struct media_bay_info
* bay
, int on_off
)
252 /* Power up device, assert it's reset line */
253 MB_BIC(bay
, KEYLARGO_MBCR
, KL_MBCR_MB0_DEV_RESET
);
254 MB_BIC(bay
, KEYLARGO_MBCR
, KL_MBCR_MB0_DEV_POWER
);
256 /* Disable all devices */
257 MB_BIC(bay
, KEYLARGO_MBCR
, KL_MBCR_MB0_DEV_MASK
);
258 MB_BIC(bay
, KEYLARGO_FCR1
, KL1_EIDE0_ENABLE
);
259 /* Cut power from bay, release reset line */
260 MB_BIS(bay
, KEYLARGO_MBCR
, KL_MBCR_MB0_DEV_POWER
);
261 MB_BIS(bay
, KEYLARGO_MBCR
, KL_MBCR_MB0_DEV_RESET
);
262 MB_BIS(bay
, KEYLARGO_FCR1
, KL1_EIDE0_RESET_N
);
264 MB_BIC(bay
, KEYLARGO_MBCR
, 0x0000000F);
268 * Functions for configuring the media bay for a given type of device,
269 * enable the related busses
273 ohare_mb_setup_bus(struct media_bay_info
* bay
, u8 device_id
)
278 MB_BIS(bay
, OHARE_FCR
, OH_BAY_FLOPPY_ENABLE
);
279 MB_BIS(bay
, OHARE_FCR
, OH_FLOPPY_ENABLE
);
282 MB_BIC(bay
, OHARE_FCR
, OH_IDE1_RESET_N
);
283 MB_BIS(bay
, OHARE_FCR
, OH_BAY_IDE_ENABLE
);
286 MB_BIS(bay
, OHARE_FCR
, OH_BAY_PCI_ENABLE
);
293 heathrow_mb_setup_bus(struct media_bay_info
* bay
, u8 device_id
)
298 MB_BIS(bay
, HEATHROW_FCR
, HRW_BAY_FLOPPY_ENABLE
);
299 MB_BIS(bay
, HEATHROW_FCR
, HRW_SWIM_ENABLE
);
302 MB_BIC(bay
, HEATHROW_FCR
, HRW_IDE1_RESET_N
);
303 MB_BIS(bay
, HEATHROW_FCR
, HRW_BAY_IDE_ENABLE
);
306 MB_BIS(bay
, HEATHROW_FCR
, HRW_BAY_PCI_ENABLE
);
313 keylargo_mb_setup_bus(struct media_bay_info
* bay
, u8 device_id
)
317 MB_BIS(bay
, KEYLARGO_MBCR
, KL_MBCR_MB0_IDE_ENABLE
);
318 MB_BIC(bay
, KEYLARGO_FCR1
, KL1_EIDE0_RESET_N
);
319 MB_BIS(bay
, KEYLARGO_FCR1
, KL1_EIDE0_ENABLE
);
322 MB_BIS(bay
, KEYLARGO_MBCR
, KL_MBCR_MB0_PCI_ENABLE
);
325 MB_BIS(bay
, KEYLARGO_MBCR
, KL_MBCR_MB0_SOUND_ENABLE
);
332 * Functions for tweaking resets
336 ohare_mb_un_reset(struct media_bay_info
* bay
)
338 MB_BIS(bay
, OHARE_FCR
, OH_BAY_RESET_N
);
341 static void keylargo_mb_init(struct media_bay_info
*bay
)
343 MB_BIS(bay
, KEYLARGO_MBCR
, KL_MBCR_MB0_ENABLE
);
346 static void heathrow_mb_un_reset(struct media_bay_info
* bay
)
348 MB_BIS(bay
, HEATHROW_FCR
, HRW_BAY_RESET_N
);
351 static void keylargo_mb_un_reset(struct media_bay_info
* bay
)
353 MB_BIS(bay
, KEYLARGO_MBCR
, KL_MBCR_MB0_DEV_RESET
);
356 static void ohare_mb_un_reset_ide(struct media_bay_info
* bay
)
358 MB_BIS(bay
, OHARE_FCR
, OH_IDE1_RESET_N
);
361 static void heathrow_mb_un_reset_ide(struct media_bay_info
* bay
)
363 MB_BIS(bay
, HEATHROW_FCR
, HRW_IDE1_RESET_N
);
366 static void keylargo_mb_un_reset_ide(struct media_bay_info
* bay
)
368 MB_BIS(bay
, KEYLARGO_FCR1
, KL1_EIDE0_RESET_N
);
371 static inline void set_mb_power(struct media_bay_info
* bay
, int onoff
)
373 /* Power up up and assert the bay reset line */
375 bay
->ops
->power(bay
, 1);
376 bay
->state
= mb_powering_up
;
377 MBDBG("mediabay%d: powering up\n", bay
->index
);
379 /* Make sure everything is powered down & disabled */
380 bay
->ops
->power(bay
, 0);
381 bay
->state
= mb_powering_down
;
382 MBDBG("mediabay%d: powering down\n", bay
->index
);
384 bay
->timer
= msecs_to_jiffies(MB_POWER_DELAY
);
387 static void poll_media_bay(struct media_bay_info
* bay
)
389 int id
= bay
->ops
->content(bay
);
391 if (id
== bay
->last_value
) {
392 if (id
!= bay
->content_id
) {
393 bay
->value_count
+= msecs_to_jiffies(MB_POLL_DELAY
);
394 if (bay
->value_count
>= msecs_to_jiffies(MB_STABLE_DELAY
)) {
395 /* If the device type changes without going thru
396 * "MB_NO", we force a pass by "MB_NO" to make sure
397 * things are properly reset
399 if ((id
!= MB_NO
) && (bay
->content_id
!= MB_NO
)) {
401 MBDBG("mediabay%d: forcing MB_NO\n", bay
->index
);
403 MBDBG("mediabay%d: switching to %d\n", bay
->index
, id
);
404 set_mb_power(bay
, id
!= MB_NO
);
405 bay
->content_id
= id
;
407 #ifdef CONFIG_BLK_DEV_IDE_PMAC
410 printk(KERN_INFO
"media bay %d is empty\n", bay
->index
);
415 bay
->last_value
= id
;
416 bay
->value_count
= 0;
420 int check_media_bay(struct device_node
*which_bay
, int what
)
424 for (i
=0; i
<media_bay_count
; i
++)
425 if (media_bays
[i
].mdev
&& which_bay
== media_bays
[i
].mdev
->ofdev
.node
) {
426 if ((what
== media_bays
[i
].content_id
) && media_bays
[i
].state
== mb_up
)
428 media_bays
[i
].cd_index
= -1;
433 EXPORT_SYMBOL(check_media_bay
);
435 #ifdef CONFIG_BLK_DEV_IDE_PMAC
436 int check_media_bay_by_base(unsigned long base
, int what
)
440 for (i
=0; i
<media_bay_count
; i
++)
441 if (media_bays
[i
].mdev
&& base
== (unsigned long) media_bays
[i
].cd_base
) {
442 if ((what
== media_bays
[i
].content_id
) && media_bays
[i
].state
== mb_up
)
444 media_bays
[i
].cd_index
= -1;
451 int media_bay_set_ide_infos(struct device_node
* which_bay
, unsigned long base
,
452 int irq
, ide_hwif_t
*hwif
)
456 for (i
=0; i
<media_bay_count
; i
++) {
457 struct media_bay_info
* bay
= &media_bays
[i
];
459 if (bay
->mdev
&& which_bay
== bay
->mdev
->ofdev
.node
) {
460 int timeout
= 5000, index
= hwif
->index
;
465 bay
->cd_base
= (void __iomem
*) base
;
468 if ((MB_CD
!= bay
->content_id
) || bay
->state
!= mb_up
) {
472 printk(KERN_DEBUG
"Registered ide%d for media bay %d\n", index
, i
);
474 if (MB_IDE_READY(i
)) {
475 bay
->cd_index
= index
;
481 printk(KERN_DEBUG
"Timeount waiting IDE in bay %d\n", i
);
489 #endif /* CONFIG_BLK_DEV_IDE_PMAC */
491 static void media_bay_step(int i
)
493 struct media_bay_info
* bay
= &media_bays
[i
];
495 /* We don't poll when powering down */
496 if (bay
->state
!= mb_powering_down
)
499 /* If timer expired or polling IDE busy, run state machine */
500 if ((bay
->state
!= mb_ide_waiting
) && (bay
->timer
!= 0)) {
501 bay
->timer
-= msecs_to_jiffies(MB_POLL_DELAY
);
509 if (bay
->ops
->setup_bus(bay
, bay
->last_value
) < 0) {
510 MBDBG("mediabay%d: device not supported (kind:%d)\n", i
, bay
->content_id
);
511 set_mb_power(bay
, 0);
514 bay
->timer
= msecs_to_jiffies(MB_RESET_DELAY
);
515 bay
->state
= mb_enabling_bay
;
516 MBDBG("mediabay%d: enabling (kind:%d)\n", i
, bay
->content_id
);
518 case mb_enabling_bay
:
519 bay
->ops
->un_reset(bay
);
520 bay
->timer
= msecs_to_jiffies(MB_SETUP_DELAY
);
521 bay
->state
= mb_resetting
;
522 MBDBG("mediabay%d: waiting reset (kind:%d)\n", i
, bay
->content_id
);
525 if (bay
->content_id
!= MB_CD
) {
526 MBDBG("mediabay%d: bay is up (kind:%d)\n", i
, bay
->content_id
);
530 #ifdef CONFIG_BLK_DEV_IDE_PMAC
531 MBDBG("mediabay%d: waiting IDE reset (kind:%d)\n", i
, bay
->content_id
);
532 bay
->ops
->un_reset_ide(bay
);
533 bay
->timer
= msecs_to_jiffies(MB_IDE_WAIT
);
534 bay
->state
= mb_ide_resetting
;
536 printk(KERN_DEBUG
"media-bay %d is ide (not compiled in kernel)\n", i
);
537 set_mb_power(bay
, 0);
538 #endif /* CONFIG_BLK_DEV_IDE_PMAC */
540 #ifdef CONFIG_BLK_DEV_IDE_PMAC
541 case mb_ide_resetting
:
542 bay
->timer
= msecs_to_jiffies(MB_IDE_TIMEOUT
);
543 bay
->state
= mb_ide_waiting
;
544 MBDBG("mediabay%d: waiting IDE ready (kind:%d)\n", i
, bay
->content_id
);
547 if (bay
->cd_base
== NULL
) {
550 MBDBG("mediabay%d: up before IDE init\n", i
);
552 } else if (MB_IDE_READY(i
)) {
555 if (bay
->cd_index
< 0) {
556 printk("mediabay %d, registering IDE...\n", i
);
558 ide_port_scan(bay
->cd_port
);
559 bay
->cd_index
= bay
->cd_port
->index
;
562 if (bay
->cd_index
== -1) {
563 /* We eventually do a retry */
565 printk("IDE register error\n");
566 set_mb_power(bay
, 0);
568 printk(KERN_DEBUG
"media-bay %d is ide%d\n", i
, bay
->cd_index
);
569 MBDBG("mediabay %d IDE ready\n", i
);
572 } else if (bay
->timer
> 0)
573 bay
->timer
-= msecs_to_jiffies(MB_POLL_DELAY
);
574 if (bay
->timer
<= 0) {
575 printk("\nIDE Timeout in bay %d !, IDE state is: 0x%02x\n",
576 i
, readb(bay
->cd_base
+ 0x70));
577 MBDBG("mediabay%d: nIDE Timeout !\n", i
);
578 set_mb_power(bay
, 0);
582 #endif /* CONFIG_BLK_DEV_IDE_PMAC */
583 case mb_powering_down
:
584 bay
->state
= mb_empty
;
585 #ifdef CONFIG_BLK_DEV_IDE_PMAC
586 if (bay
->cd_index
>= 0) {
587 printk(KERN_DEBUG
"Unregistering mb %d ide, index:%d\n", i
,
589 ide_port_unregister_devices(bay
->cd_port
);
593 if (bay
->cd_retry
> MAX_CD_RETRIES
) {
594 /* Should add an error sound (sort of beep in dmasound) */
595 printk("\nmedia-bay %d, IDE device badly inserted or unrecognised\n", i
);
597 /* Force a new power down/up sequence */
598 bay
->content_id
= MB_NO
;
601 #endif /* CONFIG_BLK_DEV_IDE_PMAC */
602 MBDBG("mediabay%d: end of power down\n", i
);
608 * This procedure runs as a kernel thread to poll the media bay
609 * once each tick and register and unregister the IDE interface
610 * with the IDE driver. It needs to be a thread because
611 * ide_register can't be called from interrupt context.
613 static int media_bay_task(void *x
)
617 while (!kthread_should_stop()) {
618 for (i
= 0; i
< media_bay_count
; ++i
) {
619 down(&media_bays
[i
].lock
);
620 if (!media_bays
[i
].sleeping
)
622 up(&media_bays
[i
].lock
);
625 msleep_interruptible(MB_POLL_DELAY
);
630 static int __devinit
media_bay_attach(struct macio_dev
*mdev
, const struct of_device_id
*match
)
632 struct media_bay_info
* bay
;
633 u32 __iomem
*regbase
;
634 struct device_node
*ofnode
;
638 ofnode
= mdev
->ofdev
.node
;
640 if (macio_resource_count(mdev
) < 1)
642 if (macio_request_resources(mdev
, "media-bay"))
644 /* Media bay registers are located at the beginning of the
645 * mac-io chip, for now, we trick and align down the first
648 base
= macio_resource_start(mdev
, 0) & 0xffff0000u
;
649 regbase
= (u32 __iomem
*)ioremap(base
, 0x100);
650 if (regbase
== NULL
) {
651 macio_release_resources(mdev
);
655 i
= media_bay_count
++;
656 bay
= &media_bays
[i
];
660 bay
->ops
= match
->data
;
662 init_MUTEX(&bay
->lock
);
664 /* Init HW probing */
668 printk(KERN_INFO
"mediabay%d: Registered %s media-bay\n", i
, bay
->ops
->name
);
670 /* Force an immediate detect */
671 set_mb_power(bay
, 0);
672 msleep(MB_POWER_DELAY
);
673 bay
->content_id
= MB_NO
;
674 bay
->last_value
= bay
->ops
->content(bay
);
675 bay
->value_count
= msecs_to_jiffies(MB_STABLE_DELAY
);
676 bay
->state
= mb_empty
;
678 msleep(MB_POLL_DELAY
);
680 } while((bay
->state
!= mb_empty
) &&
681 (bay
->state
!= mb_up
));
683 /* Mark us ready by filling our mdev data */
684 macio_set_drvdata(mdev
, bay
);
686 /* Startup kernel thread */
688 kthread_run(media_bay_task
, NULL
, "media-bay");
694 static int media_bay_suspend(struct macio_dev
*mdev
, pm_message_t state
)
696 struct media_bay_info
*bay
= macio_get_drvdata(mdev
);
698 if (state
.event
!= mdev
->ofdev
.dev
.power
.power_state
.event
699 && (state
.event
& PM_EVENT_SLEEP
)) {
702 set_mb_power(bay
, 0);
704 msleep(MB_POLL_DELAY
);
705 mdev
->ofdev
.dev
.power
.power_state
= state
;
710 static int media_bay_resume(struct macio_dev
*mdev
)
712 struct media_bay_info
*bay
= macio_get_drvdata(mdev
);
714 if (mdev
->ofdev
.dev
.power
.power_state
.event
!= PM_EVENT_ON
) {
715 mdev
->ofdev
.dev
.power
.power_state
= PMSG_ON
;
717 /* We re-enable the bay using it's previous content
718 only if it did not change. Note those bozo timings,
719 they seem to help the 3400 get it right.
721 /* Force MB power to 0 */
723 set_mb_power(bay
, 0);
724 msleep(MB_POWER_DELAY
);
725 if (bay
->ops
->content(bay
) != bay
->content_id
) {
726 printk("mediabay%d: content changed during sleep...\n", bay
->index
);
730 set_mb_power(bay
, 1);
731 bay
->last_value
= bay
->content_id
;
732 bay
->value_count
= msecs_to_jiffies(MB_STABLE_DELAY
);
733 bay
->timer
= msecs_to_jiffies(MB_POWER_DELAY
);
734 #ifdef CONFIG_BLK_DEV_IDE_PMAC
738 msleep(MB_POLL_DELAY
);
739 media_bay_step(bay
->index
);
740 } while((bay
->state
!= mb_empty
) &&
741 (bay
->state
!= mb_up
));
749 /* Definitions of "ops" structures.
751 static struct mb_ops ohare_mb_ops
= {
753 .content
= ohare_mb_content
,
754 .power
= ohare_mb_power
,
755 .setup_bus
= ohare_mb_setup_bus
,
756 .un_reset
= ohare_mb_un_reset
,
757 .un_reset_ide
= ohare_mb_un_reset_ide
,
760 static struct mb_ops heathrow_mb_ops
= {
762 .content
= heathrow_mb_content
,
763 .power
= heathrow_mb_power
,
764 .setup_bus
= heathrow_mb_setup_bus
,
765 .un_reset
= heathrow_mb_un_reset
,
766 .un_reset_ide
= heathrow_mb_un_reset_ide
,
769 static struct mb_ops keylargo_mb_ops
= {
771 .init
= keylargo_mb_init
,
772 .content
= keylargo_mb_content
,
773 .power
= keylargo_mb_power
,
774 .setup_bus
= keylargo_mb_setup_bus
,
775 .un_reset
= keylargo_mb_un_reset
,
776 .un_reset_ide
= keylargo_mb_un_reset_ide
,
780 * It seems that the bit for the media-bay interrupt in the IRQ_LEVEL
781 * register is always set when there is something in the media bay.
782 * This causes problems for the interrupt code if we attach an interrupt
783 * handler to the media-bay interrupt, because it tends to go into
784 * an infinite loop calling the media bay interrupt handler.
785 * Therefore we do it all by polling the media bay once each tick.
788 static struct of_device_id media_bay_match
[] =
792 .compatible
= "keylargo-media-bay",
793 .data
= &keylargo_mb_ops
,
797 .compatible
= "heathrow-media-bay",
798 .data
= &heathrow_mb_ops
,
802 .compatible
= "ohare-media-bay",
803 .data
= &ohare_mb_ops
,
808 static struct macio_driver media_bay_driver
=
811 .match_table
= media_bay_match
,
812 .probe
= media_bay_attach
,
813 .suspend
= media_bay_suspend
,
814 .resume
= media_bay_resume
817 static int __init
media_bay_init(void)
821 for (i
=0; i
<MAX_BAYS
; i
++) {
822 memset((char *)&media_bays
[i
], 0, sizeof(struct media_bay_info
));
823 media_bays
[i
].content_id
= -1;
824 #ifdef CONFIG_BLK_DEV_IDE_PMAC
825 media_bays
[i
].cd_index
= -1;
828 if (!machine_is(powermac
))
831 macio_register_driver(&media_bay_driver
);
836 device_initcall(media_bay_init
);