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/config.h>
14 #include <linux/types.h>
15 #include <linux/errno.h>
16 #include <linux/kernel.h>
17 #include <linux/delay.h>
18 #include <linux/sched.h>
19 #include <linux/timer.h>
20 #include <linux/hdreg.h>
21 #include <linux/stddef.h>
22 #include <linux/init.h>
23 #include <linux/ide.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>
39 #define MB_IGNORE_SIGNALS
42 #define MBDBG(fmt, arg...) printk(KERN_INFO fmt , ## arg)
44 #define MBDBG(fmt, arg...) do { } while (0)
47 #define MB_FCR32(bay, r) ((bay)->base + ((r) >> 2))
48 #define MB_FCR8(bay, r) (((volatile u8*)((bay)->base)) + (r))
50 #define MB_IN32(bay,r) (in_le32(MB_FCR32(bay,r)))
51 #define MB_OUT32(bay,r,v) (out_le32(MB_FCR32(bay,r), (v)))
52 #define MB_BIS(bay,r,v) (MB_OUT32((bay), (r), MB_IN32((bay), r) | (v)))
53 #define MB_BIC(bay,r,v) (MB_OUT32((bay), (r), MB_IN32((bay), r) & ~(v)))
54 #define MB_IN8(bay,r) (in_8(MB_FCR8(bay,r)))
55 #define MB_OUT8(bay,r,v) (out_8(MB_FCR8(bay,r), (v)))
57 struct media_bay_info
;
61 void (*init
)(struct media_bay_info
*bay
);
62 u8 (*content
)(struct media_bay_info
*bay
);
63 void (*power
)(struct media_bay_info
*bay
, int on_off
);
64 int (*setup_bus
)(struct media_bay_info
*bay
, u8 device_id
);
65 void (*un_reset
)(struct media_bay_info
*bay
);
66 void (*un_reset_ide
)(struct media_bay_info
*bay
);
69 struct media_bay_info
{
76 struct macio_dev
*mdev
;
81 struct semaphore lock
;
82 #ifdef CONFIG_BLK_DEV_IDE
83 unsigned long cd_base
;
92 static struct media_bay_info media_bays
[MAX_BAYS
];
93 int media_bay_count
= 0;
95 #ifdef CONFIG_BLK_DEV_IDE
96 /* check the busy bit in the media-bay ide interface
97 (assumes the media-bay contains an ide device) */
98 #define MB_IDE_READY(i) ((readb(media_bays[i].cd_base + 0x70) & 0x80) == 0)
101 /* Note: All delays are not in milliseconds and converted to HZ relative
102 * values by the macro below
104 #define MS_TO_HZ(ms) ((ms * HZ + 999) / 1000)
107 * Wait that number of ms between each step in normal polling mode
109 #define MB_POLL_DELAY 25
112 * Consider the media-bay ID value stable if it is the same for
113 * this number of milliseconds
115 #define MB_STABLE_DELAY 100
117 /* Wait after powering up the media bay this delay in ms
118 * timeout bumped for some powerbooks
120 #define MB_POWER_DELAY 200
123 * Hold the media-bay reset signal true for this many ticks
124 * after a device is inserted before releasing it.
126 #define MB_RESET_DELAY 50
129 * Wait this long after the reset signal is released and before doing
130 * further operations. After this delay, the IDE reset signal is released
131 * too for an IDE device
133 #define MB_SETUP_DELAY 100
136 * Wait this many ticks after an IDE device (e.g. CD-ROM) is inserted
137 * (or until the device is ready) before waiting for busy bit to disappear
139 #define MB_IDE_WAIT 1000
142 * Timeout waiting for busy bit of an IDE device to go down
144 #define MB_IDE_TIMEOUT 5000
147 * Max retries of the full power up/down sequence for an IDE device
149 #define MAX_CD_RETRIES 3
152 * States of a media bay
155 mb_empty
= 0, /* Idle */
156 mb_powering_up
, /* power bit set, waiting MB_POWER_DELAY */
157 mb_enabling_bay
, /* enable bits set, waiting MB_RESET_DELAY */
158 mb_resetting
, /* reset bit unset, waiting MB_SETUP_DELAY */
159 mb_ide_resetting
, /* IDE reset bit unser, waiting MB_IDE_WAIT */
160 mb_ide_waiting
, /* Waiting for BUSY bit to go away until MB_IDE_TIMEOUT */
161 mb_up
, /* Media bay full */
162 mb_powering_down
/* Powering down (avoid too fast down/up) */
165 #define MB_POWER_SOUND 0x08
166 #define MB_POWER_FLOPPY 0x04
167 #define MB_POWER_ATA 0x02
168 #define MB_POWER_PCI 0x01
169 #define MB_POWER_OFF 0x00
172 * Functions for polling content of media bay
176 ohare_mb_content(struct media_bay_info
*bay
)
178 return (MB_IN32(bay
, OHARE_MBCR
) >> 12) & 7;
182 heathrow_mb_content(struct media_bay_info
*bay
)
184 return (MB_IN32(bay
, HEATHROW_MBCR
) >> 12) & 7;
188 keylargo_mb_content(struct media_bay_info
*bay
)
192 new_gpio
= MB_IN8(bay
, KL_GPIO_MEDIABAY_IRQ
) & KEYLARGO_GPIO_INPUT_DATA
;
194 bay
->cached_gpio
= new_gpio
;
196 } else if (bay
->cached_gpio
!= new_gpio
) {
197 MB_BIS(bay
, KEYLARGO_MBCR
, KL_MBCR_MB0_ENABLE
);
198 (void)MB_IN32(bay
, KEYLARGO_MBCR
);
200 MB_BIC(bay
, KEYLARGO_MBCR
, 0x0000000F);
201 (void)MB_IN32(bay
, KEYLARGO_MBCR
);
203 bay
->cached_gpio
= new_gpio
;
205 return (MB_IN32(bay
, KEYLARGO_MBCR
) >> 4) & 7;
209 * Functions for powering up/down the bay, puts the bay device
210 * into reset state as well
214 ohare_mb_power(struct media_bay_info
* bay
, int on_off
)
217 /* Power up device, assert it's reset line */
218 MB_BIC(bay
, OHARE_FCR
, OH_BAY_RESET_N
);
219 MB_BIC(bay
, OHARE_FCR
, OH_BAY_POWER_N
);
221 /* Disable all devices */
222 MB_BIC(bay
, OHARE_FCR
, OH_BAY_DEV_MASK
);
223 MB_BIC(bay
, OHARE_FCR
, OH_FLOPPY_ENABLE
);
224 /* Cut power from bay, release reset line */
225 MB_BIS(bay
, OHARE_FCR
, OH_BAY_POWER_N
);
226 MB_BIS(bay
, OHARE_FCR
, OH_BAY_RESET_N
);
227 MB_BIS(bay
, OHARE_FCR
, OH_IDE1_RESET_N
);
229 MB_BIC(bay
, OHARE_MBCR
, 0x00000F00);
233 heathrow_mb_power(struct media_bay_info
* bay
, int on_off
)
236 /* Power up device, assert it's reset line */
237 MB_BIC(bay
, HEATHROW_FCR
, HRW_BAY_RESET_N
);
238 MB_BIC(bay
, HEATHROW_FCR
, HRW_BAY_POWER_N
);
240 /* Disable all devices */
241 MB_BIC(bay
, HEATHROW_FCR
, HRW_BAY_DEV_MASK
);
242 MB_BIC(bay
, HEATHROW_FCR
, HRW_SWIM_ENABLE
);
243 /* Cut power from bay, release reset line */
244 MB_BIS(bay
, HEATHROW_FCR
, HRW_BAY_POWER_N
);
245 MB_BIS(bay
, HEATHROW_FCR
, HRW_BAY_RESET_N
);
246 MB_BIS(bay
, HEATHROW_FCR
, HRW_IDE1_RESET_N
);
248 MB_BIC(bay
, HEATHROW_MBCR
, 0x00000F00);
252 keylargo_mb_power(struct media_bay_info
* bay
, int on_off
)
255 /* Power up device, assert it's reset line */
256 MB_BIC(bay
, KEYLARGO_MBCR
, KL_MBCR_MB0_DEV_RESET
);
257 MB_BIC(bay
, KEYLARGO_MBCR
, KL_MBCR_MB0_DEV_POWER
);
259 /* Disable all devices */
260 MB_BIC(bay
, KEYLARGO_MBCR
, KL_MBCR_MB0_DEV_MASK
);
261 MB_BIC(bay
, KEYLARGO_FCR1
, KL1_EIDE0_ENABLE
);
262 /* Cut power from bay, release reset line */
263 MB_BIS(bay
, KEYLARGO_MBCR
, KL_MBCR_MB0_DEV_POWER
);
264 MB_BIS(bay
, KEYLARGO_MBCR
, KL_MBCR_MB0_DEV_RESET
);
265 MB_BIS(bay
, KEYLARGO_FCR1
, KL1_EIDE0_RESET_N
);
267 MB_BIC(bay
, KEYLARGO_MBCR
, 0x0000000F);
271 * Functions for configuring the media bay for a given type of device,
272 * enable the related busses
276 ohare_mb_setup_bus(struct media_bay_info
* bay
, u8 device_id
)
281 MB_BIS(bay
, OHARE_FCR
, OH_BAY_FLOPPY_ENABLE
);
282 MB_BIS(bay
, OHARE_FCR
, OH_FLOPPY_ENABLE
);
285 MB_BIC(bay
, OHARE_FCR
, OH_IDE1_RESET_N
);
286 MB_BIS(bay
, OHARE_FCR
, OH_BAY_IDE_ENABLE
);
289 MB_BIS(bay
, OHARE_FCR
, OH_BAY_PCI_ENABLE
);
296 heathrow_mb_setup_bus(struct media_bay_info
* bay
, u8 device_id
)
301 MB_BIS(bay
, HEATHROW_FCR
, HRW_BAY_FLOPPY_ENABLE
);
302 MB_BIS(bay
, HEATHROW_FCR
, HRW_SWIM_ENABLE
);
305 MB_BIC(bay
, HEATHROW_FCR
, HRW_IDE1_RESET_N
);
306 MB_BIS(bay
, HEATHROW_FCR
, HRW_BAY_IDE_ENABLE
);
309 MB_BIS(bay
, HEATHROW_FCR
, HRW_BAY_PCI_ENABLE
);
316 keylargo_mb_setup_bus(struct media_bay_info
* bay
, u8 device_id
)
320 MB_BIS(bay
, KEYLARGO_MBCR
, KL_MBCR_MB0_IDE_ENABLE
);
321 MB_BIC(bay
, KEYLARGO_FCR1
, KL1_EIDE0_RESET_N
);
322 MB_BIS(bay
, KEYLARGO_FCR1
, KL1_EIDE0_ENABLE
);
325 MB_BIS(bay
, KEYLARGO_MBCR
, KL_MBCR_MB0_PCI_ENABLE
);
328 MB_BIS(bay
, KEYLARGO_MBCR
, KL_MBCR_MB0_SOUND_ENABLE
);
335 * Functions for tweaking resets
339 ohare_mb_un_reset(struct media_bay_info
* bay
)
341 MB_BIS(bay
, OHARE_FCR
, OH_BAY_RESET_N
);
344 static void __pmac
keylargo_mb_init(struct media_bay_info
*bay
)
346 MB_BIS(bay
, KEYLARGO_MBCR
, KL_MBCR_MB0_ENABLE
);
349 static void __pmac
heathrow_mb_un_reset(struct media_bay_info
* bay
)
351 MB_BIS(bay
, HEATHROW_FCR
, HRW_BAY_RESET_N
);
354 static void __pmac
keylargo_mb_un_reset(struct media_bay_info
* bay
)
356 MB_BIS(bay
, KEYLARGO_MBCR
, KL_MBCR_MB0_DEV_RESET
);
359 static void __pmac
ohare_mb_un_reset_ide(struct media_bay_info
* bay
)
361 MB_BIS(bay
, OHARE_FCR
, OH_IDE1_RESET_N
);
364 static void __pmac
heathrow_mb_un_reset_ide(struct media_bay_info
* bay
)
366 MB_BIS(bay
, HEATHROW_FCR
, HRW_IDE1_RESET_N
);
369 static void __pmac
keylargo_mb_un_reset_ide(struct media_bay_info
* bay
)
371 MB_BIS(bay
, KEYLARGO_FCR1
, KL1_EIDE0_RESET_N
);
374 static inline void __pmac
set_mb_power(struct media_bay_info
* bay
, int onoff
)
376 /* Power up up and assert the bay reset line */
378 bay
->ops
->power(bay
, 1);
379 bay
->state
= mb_powering_up
;
380 MBDBG("mediabay%d: powering up\n", bay
->index
);
382 /* Make sure everything is powered down & disabled */
383 bay
->ops
->power(bay
, 0);
384 bay
->state
= mb_powering_down
;
385 MBDBG("mediabay%d: powering down\n", bay
->index
);
387 bay
->timer
= MS_TO_HZ(MB_POWER_DELAY
);
390 static void __pmac
poll_media_bay(struct media_bay_info
* bay
)
392 int id
= bay
->ops
->content(bay
);
394 if (id
== bay
->last_value
) {
395 if (id
!= bay
->content_id
) {
396 bay
->value_count
+= MS_TO_HZ(MB_POLL_DELAY
);
397 if (bay
->value_count
>= MS_TO_HZ(MB_STABLE_DELAY
)) {
398 /* If the device type changes without going thru
399 * "MB_NO", we force a pass by "MB_NO" to make sure
400 * things are properly reset
402 if ((id
!= MB_NO
) && (bay
->content_id
!= MB_NO
)) {
404 MBDBG("mediabay%d: forcing MB_NO\n", bay
->index
);
406 MBDBG("mediabay%d: switching to %d\n", bay
->index
, id
);
407 set_mb_power(bay
, id
!= MB_NO
);
408 bay
->content_id
= id
;
410 #ifdef CONFIG_BLK_DEV_IDE
413 printk(KERN_INFO
"media bay %d is empty\n", bay
->index
);
418 bay
->last_value
= id
;
419 bay
->value_count
= 0;
423 int __pmac
check_media_bay(struct device_node
*which_bay
, int what
)
425 #ifdef CONFIG_BLK_DEV_IDE
428 for (i
=0; i
<media_bay_count
; i
++)
429 if (media_bays
[i
].mdev
&& which_bay
== media_bays
[i
].mdev
->ofdev
.node
) {
430 if ((what
== media_bays
[i
].content_id
) && media_bays
[i
].state
== mb_up
)
432 media_bays
[i
].cd_index
= -1;
435 #endif /* CONFIG_BLK_DEV_IDE */
438 EXPORT_SYMBOL(check_media_bay
);
440 int __pmac
check_media_bay_by_base(unsigned long base
, int what
)
442 #ifdef CONFIG_BLK_DEV_IDE
445 for (i
=0; i
<media_bay_count
; i
++)
446 if (media_bays
[i
].mdev
&& base
== media_bays
[i
].cd_base
) {
447 if ((what
== media_bays
[i
].content_id
) && media_bays
[i
].state
== mb_up
)
449 media_bays
[i
].cd_index
= -1;
457 int __pmac
media_bay_set_ide_infos(struct device_node
* which_bay
, unsigned long base
,
460 #ifdef CONFIG_BLK_DEV_IDE
463 for (i
=0; i
<media_bay_count
; i
++) {
464 struct media_bay_info
* bay
= &media_bays
[i
];
466 if (bay
->mdev
&& which_bay
== bay
->mdev
->ofdev
.node
) {
474 if ((MB_CD
!= bay
->content_id
) || bay
->state
!= mb_up
) {
478 printk(KERN_DEBUG
"Registered ide%d for media bay %d\n", index
, i
);
480 if (MB_IDE_READY(i
)) {
481 bay
->cd_index
= index
;
487 printk(KERN_DEBUG
"Timeount waiting IDE in bay %d\n", i
);
492 #endif /* CONFIG_BLK_DEV_IDE */
497 static void __pmac
media_bay_step(int i
)
499 struct media_bay_info
* bay
= &media_bays
[i
];
501 /* We don't poll when powering down */
502 if (bay
->state
!= mb_powering_down
)
505 /* If timer expired or polling IDE busy, run state machine */
506 if ((bay
->state
!= mb_ide_waiting
) && (bay
->timer
!= 0)) {
507 bay
->timer
-= MS_TO_HZ(MB_POLL_DELAY
);
515 if (bay
->ops
->setup_bus(bay
, bay
->last_value
) < 0) {
516 MBDBG("mediabay%d: device not supported (kind:%d)\n", i
, bay
->content_id
);
517 set_mb_power(bay
, 0);
520 bay
->timer
= MS_TO_HZ(MB_RESET_DELAY
);
521 bay
->state
= mb_enabling_bay
;
522 MBDBG("mediabay%d: enabling (kind:%d)\n", i
, bay
->content_id
);
524 case mb_enabling_bay
:
525 bay
->ops
->un_reset(bay
);
526 bay
->timer
= MS_TO_HZ(MB_SETUP_DELAY
);
527 bay
->state
= mb_resetting
;
528 MBDBG("mediabay%d: waiting reset (kind:%d)\n", i
, bay
->content_id
);
532 if (bay
->content_id
!= MB_CD
) {
533 MBDBG("mediabay%d: bay is up (kind:%d)\n", i
, bay
->content_id
);
537 #ifdef CONFIG_BLK_DEV_IDE
538 MBDBG("mediabay%d: waiting IDE reset (kind:%d)\n", i
, bay
->content_id
);
539 bay
->ops
->un_reset_ide(bay
);
540 bay
->timer
= MS_TO_HZ(MB_IDE_WAIT
);
541 bay
->state
= mb_ide_resetting
;
543 printk(KERN_DEBUG
"media-bay %d is ide (not compiled in kernel)\n", i
);
544 set_mb_power(bay
, 0);
545 #endif /* CONFIG_BLK_DEV_IDE */
548 #ifdef CONFIG_BLK_DEV_IDE
549 case mb_ide_resetting
:
550 bay
->timer
= MS_TO_HZ(MB_IDE_TIMEOUT
);
551 bay
->state
= mb_ide_waiting
;
552 MBDBG("mediabay%d: waiting IDE ready (kind:%d)\n", i
, bay
->content_id
);
556 if (bay
->cd_base
== 0) {
559 MBDBG("mediabay%d: up before IDE init\n", i
);
561 } else if (MB_IDE_READY(i
)) {
564 if (bay
->cd_index
< 0) {
567 printk("mediabay %d, registering IDE...\n", i
);
569 ide_init_hwif_ports(&hw
, (unsigned long) bay
->cd_base
, (unsigned long) 0, NULL
);
570 hw
.irq
= bay
->cd_irq
;
571 hw
.chipset
= ide_pmac
;
572 bay
->cd_index
= ide_register_hw(&hw
, NULL
);
575 if (bay
->cd_index
== -1) {
576 /* We eventually do a retry */
578 printk("IDE register error\n");
579 set_mb_power(bay
, 0);
581 printk(KERN_DEBUG
"media-bay %d is ide%d\n", i
, bay
->cd_index
);
582 MBDBG("mediabay %d IDE ready\n", i
);
585 } else if (bay
->timer
> 0)
586 bay
->timer
-= MS_TO_HZ(MB_POLL_DELAY
);
587 if (bay
->timer
<= 0) {
588 printk("\nIDE Timeout in bay %d !, IDE state is: 0x%02x\n",
589 i
, readb(bay
->cd_base
+ 0x70));
590 MBDBG("mediabay%d: nIDE Timeout !\n", i
);
591 set_mb_power(bay
, 0);
595 #endif /* CONFIG_BLK_DEV_IDE */
597 case mb_powering_down
:
598 bay
->state
= mb_empty
;
599 #ifdef CONFIG_BLK_DEV_IDE
600 if (bay
->cd_index
>= 0) {
601 printk(KERN_DEBUG
"Unregistering mb %d ide, index:%d\n", i
,
603 ide_unregister(bay
->cd_index
);
607 if (bay
->cd_retry
> MAX_CD_RETRIES
) {
608 /* Should add an error sound (sort of beep in dmasound) */
609 printk("\nmedia-bay %d, IDE device badly inserted or unrecognised\n", i
);
611 /* Force a new power down/up sequence */
612 bay
->content_id
= MB_NO
;
615 #endif /* CONFIG_BLK_DEV_IDE */
616 MBDBG("mediabay%d: end of power down\n", i
);
622 * This procedure runs as a kernel thread to poll the media bay
623 * once each tick and register and unregister the IDE interface
624 * with the IDE driver. It needs to be a thread because
625 * ide_register can't be called from interrupt context.
627 static int __pmac
media_bay_task(void *x
)
631 strcpy(current
->comm
, "media-bay");
632 #ifdef MB_IGNORE_SIGNALS
633 sigfillset(¤t
->blocked
);
637 for (i
= 0; i
< media_bay_count
; ++i
) {
638 down(&media_bays
[i
].lock
);
639 if (!media_bays
[i
].sleeping
)
641 up(&media_bays
[i
].lock
);
644 current
->state
= TASK_INTERRUPTIBLE
;
645 schedule_timeout(MS_TO_HZ(MB_POLL_DELAY
));
646 if (signal_pending(current
))
651 static int __devinit
media_bay_attach(struct macio_dev
*mdev
, const struct of_match
*match
)
653 struct media_bay_info
* bay
;
654 volatile u32
*regbase
;
655 struct device_node
*ofnode
;
658 ofnode
= mdev
->ofdev
.node
;
660 if (macio_resource_count(mdev
) < 1)
662 if (macio_request_resources(mdev
, "media-bay"))
664 /* Media bay registers are located at the beginning of the
665 * mac-io chip, we get the parent address for now (hrm...)
667 regbase
= (volatile u32
*)ioremap(ofnode
->parent
->addrs
[0].address
, 0x100);
668 if (regbase
== NULL
) {
669 macio_release_resources(mdev
);
673 i
= media_bay_count
++;
674 bay
= &media_bays
[i
];
678 bay
->ops
= match
->data
;
680 init_MUTEX(&bay
->lock
);
682 /* Init HW probing */
686 printk(KERN_INFO
"mediabay%d: Registered %s media-bay\n", i
, bay
->ops
->name
);
688 /* Force an immediate detect */
689 set_mb_power(bay
, 0);
690 msleep(MB_POWER_DELAY
);
691 bay
->content_id
= MB_NO
;
692 bay
->last_value
= bay
->ops
->content(bay
);
693 bay
->value_count
= MS_TO_HZ(MB_STABLE_DELAY
);
694 bay
->state
= mb_empty
;
696 msleep(MB_POLL_DELAY
);
698 } while((bay
->state
!= mb_empty
) &&
699 (bay
->state
!= mb_up
));
701 /* Mark us ready by filling our mdev data */
702 macio_set_drvdata(mdev
, bay
);
704 /* Startup kernel thread */
706 kernel_thread(media_bay_task
, NULL
, CLONE_KERNEL
);
712 static int __pmac
media_bay_suspend(struct macio_dev
*mdev
, u32 state
)
714 struct media_bay_info
*bay
= macio_get_drvdata(mdev
);
716 if (state
!= mdev
->ofdev
.dev
.power_state
&& state
>= 2) {
719 set_mb_power(bay
, 0);
721 msleep(MB_POLL_DELAY
);
722 mdev
->ofdev
.dev
.power_state
= state
;
727 static int __pmac
media_bay_resume(struct macio_dev
*mdev
)
729 struct media_bay_info
*bay
= macio_get_drvdata(mdev
);
731 if (mdev
->ofdev
.dev
.power_state
!= 0) {
732 mdev
->ofdev
.dev
.power_state
= 0;
734 /* We re-enable the bay using it's previous content
735 only if it did not change. Note those bozo timings,
736 they seem to help the 3400 get it right.
738 /* Force MB power to 0 */
740 set_mb_power(bay
, 0);
741 msleep(MB_POWER_DELAY
);
742 if (bay
->ops
->content(bay
) != bay
->content_id
) {
743 printk("mediabay%d: content changed during sleep...\n", bay
->index
);
747 set_mb_power(bay
, 1);
748 bay
->last_value
= bay
->content_id
;
749 bay
->value_count
= MS_TO_HZ(MB_STABLE_DELAY
);
750 bay
->timer
= MS_TO_HZ(MB_POWER_DELAY
);
751 #ifdef CONFIG_BLK_DEV_IDE
755 msleep(MB_POLL_DELAY
);
756 media_bay_step(bay
->index
);
757 } while((bay
->state
!= mb_empty
) &&
758 (bay
->state
!= mb_up
));
766 /* Definitions of "ops" structures.
768 static struct mb_ops ohare_mb_ops __pmacdata
= {
770 .content
= ohare_mb_content
,
771 .power
= ohare_mb_power
,
772 .setup_bus
= ohare_mb_setup_bus
,
773 .un_reset
= ohare_mb_un_reset
,
774 .un_reset_ide
= ohare_mb_un_reset_ide
,
777 static struct mb_ops heathrow_mb_ops __pmacdata
= {
779 .content
= heathrow_mb_content
,
780 .power
= heathrow_mb_power
,
781 .setup_bus
= heathrow_mb_setup_bus
,
782 .un_reset
= heathrow_mb_un_reset
,
783 .un_reset_ide
= heathrow_mb_un_reset_ide
,
786 static struct mb_ops keylargo_mb_ops __pmacdata
= {
788 .init
= keylargo_mb_init
,
789 .content
= keylargo_mb_content
,
790 .power
= keylargo_mb_power
,
791 .setup_bus
= keylargo_mb_setup_bus
,
792 .un_reset
= keylargo_mb_un_reset
,
793 .un_reset_ide
= keylargo_mb_un_reset_ide
,
797 * It seems that the bit for the media-bay interrupt in the IRQ_LEVEL
798 * register is always set when there is something in the media bay.
799 * This causes problems for the interrupt code if we attach an interrupt
800 * handler to the media-bay interrupt, because it tends to go into
801 * an infinite loop calling the media bay interrupt handler.
802 * Therefore we do it all by polling the media bay once each tick.
805 static struct of_match media_bay_match
[] =
809 .type
= OF_ANY_MATCH
,
810 .compatible
= "keylargo-media-bay",
811 .data
= &keylargo_mb_ops
,
815 .type
= OF_ANY_MATCH
,
816 .compatible
= "heathrow-media-bay",
817 .data
= &heathrow_mb_ops
,
821 .type
= OF_ANY_MATCH
,
822 .compatible
= "ohare-media-bay",
823 .data
= &ohare_mb_ops
,
828 static struct macio_driver media_bay_driver
=
831 .match_table
= media_bay_match
,
832 .probe
= media_bay_attach
,
833 .suspend
= media_bay_suspend
,
834 .resume
= media_bay_resume
837 static int __init
media_bay_init(void)
841 for (i
=0; i
<MAX_BAYS
; i
++) {
842 memset((char *)&media_bays
[i
], 0, sizeof(struct media_bay_info
));
843 media_bays
[i
].content_id
= -1;
844 #ifdef CONFIG_BLK_DEV_IDE
845 media_bays
[i
].cd_index
= -1;
848 if (_machine
!= _MACH_Pmac
)
851 macio_register_driver(&media_bay_driver
);
856 device_initcall(media_bay_init
);