Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Driver for the media bay on the PowerBook 3400 and 2400. |
| 3 | * |
| 4 | * Copyright (C) 1998 Paul Mackerras. |
| 5 | * |
| 6 | * Various evolutions by Benjamin Herrenschmidt & Henry Worth |
| 7 | * |
| 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. |
| 12 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/stddef.h> |
| 20 | #include <linux/init.h> |
Paul Mackerras | 33f6e79 | 2007-12-13 14:12:58 +1100 | [diff] [blame] | 21 | #include <linux/kthread.h> |
Daniel Walker | 9a24729 | 2008-06-10 09:26:09 +1000 | [diff] [blame] | 22 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <asm/prom.h> |
| 24 | #include <asm/pgtable.h> |
| 25 | #include <asm/io.h> |
| 26 | #include <asm/machdep.h> |
| 27 | #include <asm/pmac_feature.h> |
| 28 | #include <asm/mediabay.h> |
| 29 | #include <asm/sections.h> |
| 30 | #include <asm/ohare.h> |
| 31 | #include <asm/heathrow.h> |
| 32 | #include <asm/keylargo.h> |
| 33 | #include <linux/adb.h> |
| 34 | #include <linux/pmu.h> |
| 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #define MB_FCR32(bay, r) ((bay)->base + ((r) >> 2)) |
| 37 | #define MB_FCR8(bay, r) (((volatile u8 __iomem *)((bay)->base)) + (r)) |
| 38 | |
| 39 | #define MB_IN32(bay,r) (in_le32(MB_FCR32(bay,r))) |
| 40 | #define MB_OUT32(bay,r,v) (out_le32(MB_FCR32(bay,r), (v))) |
| 41 | #define MB_BIS(bay,r,v) (MB_OUT32((bay), (r), MB_IN32((bay), r) | (v))) |
| 42 | #define MB_BIC(bay,r,v) (MB_OUT32((bay), (r), MB_IN32((bay), r) & ~(v))) |
| 43 | #define MB_IN8(bay,r) (in_8(MB_FCR8(bay,r))) |
| 44 | #define MB_OUT8(bay,r,v) (out_8(MB_FCR8(bay,r), (v))) |
| 45 | |
| 46 | struct media_bay_info; |
| 47 | |
| 48 | struct mb_ops { |
| 49 | char* name; |
| 50 | void (*init)(struct media_bay_info *bay); |
| 51 | u8 (*content)(struct media_bay_info *bay); |
| 52 | void (*power)(struct media_bay_info *bay, int on_off); |
| 53 | int (*setup_bus)(struct media_bay_info *bay, u8 device_id); |
| 54 | void (*un_reset)(struct media_bay_info *bay); |
| 55 | void (*un_reset_ide)(struct media_bay_info *bay); |
| 56 | }; |
| 57 | |
| 58 | struct media_bay_info { |
| 59 | u32 __iomem *base; |
| 60 | int content_id; |
| 61 | int state; |
| 62 | int last_value; |
| 63 | int value_count; |
| 64 | int timer; |
| 65 | struct macio_dev *mdev; |
Uwe Kleine-König | 519a651 | 2012-05-21 21:57:39 +0200 | [diff] [blame] | 66 | const struct mb_ops* ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | int index; |
| 68 | int cached_gpio; |
| 69 | int sleeping; |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 70 | int user_lock; |
Daniel Walker | 9a24729 | 2008-06-10 09:26:09 +1000 | [diff] [blame] | 71 | struct mutex lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | #define MAX_BAYS 2 |
| 75 | |
| 76 | static struct media_bay_info media_bays[MAX_BAYS]; |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 77 | static int media_bay_count = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
| 79 | /* |
| 80 | * Wait that number of ms between each step in normal polling mode |
| 81 | */ |
| 82 | #define MB_POLL_DELAY 25 |
| 83 | |
| 84 | /* |
| 85 | * Consider the media-bay ID value stable if it is the same for |
| 86 | * this number of milliseconds |
| 87 | */ |
| 88 | #define MB_STABLE_DELAY 100 |
| 89 | |
| 90 | /* Wait after powering up the media bay this delay in ms |
| 91 | * timeout bumped for some powerbooks |
| 92 | */ |
| 93 | #define MB_POWER_DELAY 200 |
| 94 | |
| 95 | /* |
| 96 | * Hold the media-bay reset signal true for this many ticks |
| 97 | * after a device is inserted before releasing it. |
| 98 | */ |
| 99 | #define MB_RESET_DELAY 50 |
| 100 | |
| 101 | /* |
| 102 | * Wait this long after the reset signal is released and before doing |
| 103 | * further operations. After this delay, the IDE reset signal is released |
| 104 | * too for an IDE device |
| 105 | */ |
| 106 | #define MB_SETUP_DELAY 100 |
| 107 | |
| 108 | /* |
| 109 | * Wait this many ticks after an IDE device (e.g. CD-ROM) is inserted |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 110 | * (or until the device is ready) before calling into the driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | */ |
| 112 | #define MB_IDE_WAIT 1000 |
| 113 | |
| 114 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | * States of a media bay |
| 116 | */ |
| 117 | enum { |
| 118 | mb_empty = 0, /* Idle */ |
| 119 | mb_powering_up, /* power bit set, waiting MB_POWER_DELAY */ |
| 120 | mb_enabling_bay, /* enable bits set, waiting MB_RESET_DELAY */ |
| 121 | mb_resetting, /* reset bit unset, waiting MB_SETUP_DELAY */ |
| 122 | mb_ide_resetting, /* IDE reset bit unser, waiting MB_IDE_WAIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | mb_up, /* Media bay full */ |
| 124 | mb_powering_down /* Powering down (avoid too fast down/up) */ |
| 125 | }; |
| 126 | |
| 127 | #define MB_POWER_SOUND 0x08 |
| 128 | #define MB_POWER_FLOPPY 0x04 |
| 129 | #define MB_POWER_ATA 0x02 |
| 130 | #define MB_POWER_PCI 0x01 |
| 131 | #define MB_POWER_OFF 0x00 |
| 132 | |
| 133 | /* |
| 134 | * Functions for polling content of media bay |
| 135 | */ |
| 136 | |
Jon Loeliger | aacaf9b | 2005-09-17 10:36:54 -0500 | [diff] [blame] | 137 | static u8 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | ohare_mb_content(struct media_bay_info *bay) |
| 139 | { |
| 140 | return (MB_IN32(bay, OHARE_MBCR) >> 12) & 7; |
| 141 | } |
| 142 | |
Jon Loeliger | aacaf9b | 2005-09-17 10:36:54 -0500 | [diff] [blame] | 143 | static u8 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | heathrow_mb_content(struct media_bay_info *bay) |
| 145 | { |
| 146 | return (MB_IN32(bay, HEATHROW_MBCR) >> 12) & 7; |
| 147 | } |
| 148 | |
Jon Loeliger | aacaf9b | 2005-09-17 10:36:54 -0500 | [diff] [blame] | 149 | static u8 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | keylargo_mb_content(struct media_bay_info *bay) |
| 151 | { |
| 152 | int new_gpio; |
| 153 | |
| 154 | new_gpio = MB_IN8(bay, KL_GPIO_MEDIABAY_IRQ) & KEYLARGO_GPIO_INPUT_DATA; |
| 155 | if (new_gpio) { |
| 156 | bay->cached_gpio = new_gpio; |
| 157 | return MB_NO; |
| 158 | } else if (bay->cached_gpio != new_gpio) { |
| 159 | MB_BIS(bay, KEYLARGO_MBCR, KL_MBCR_MB0_ENABLE); |
| 160 | (void)MB_IN32(bay, KEYLARGO_MBCR); |
| 161 | udelay(5); |
| 162 | MB_BIC(bay, KEYLARGO_MBCR, 0x0000000F); |
| 163 | (void)MB_IN32(bay, KEYLARGO_MBCR); |
| 164 | udelay(5); |
| 165 | bay->cached_gpio = new_gpio; |
| 166 | } |
| 167 | return (MB_IN32(bay, KEYLARGO_MBCR) >> 4) & 7; |
| 168 | } |
| 169 | |
| 170 | /* |
| 171 | * Functions for powering up/down the bay, puts the bay device |
| 172 | * into reset state as well |
| 173 | */ |
| 174 | |
Jon Loeliger | aacaf9b | 2005-09-17 10:36:54 -0500 | [diff] [blame] | 175 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | ohare_mb_power(struct media_bay_info* bay, int on_off) |
| 177 | { |
| 178 | if (on_off) { |
| 179 | /* Power up device, assert it's reset line */ |
| 180 | MB_BIC(bay, OHARE_FCR, OH_BAY_RESET_N); |
| 181 | MB_BIC(bay, OHARE_FCR, OH_BAY_POWER_N); |
| 182 | } else { |
| 183 | /* Disable all devices */ |
| 184 | MB_BIC(bay, OHARE_FCR, OH_BAY_DEV_MASK); |
| 185 | MB_BIC(bay, OHARE_FCR, OH_FLOPPY_ENABLE); |
| 186 | /* Cut power from bay, release reset line */ |
| 187 | MB_BIS(bay, OHARE_FCR, OH_BAY_POWER_N); |
| 188 | MB_BIS(bay, OHARE_FCR, OH_BAY_RESET_N); |
| 189 | MB_BIS(bay, OHARE_FCR, OH_IDE1_RESET_N); |
| 190 | } |
| 191 | MB_BIC(bay, OHARE_MBCR, 0x00000F00); |
| 192 | } |
| 193 | |
Jon Loeliger | aacaf9b | 2005-09-17 10:36:54 -0500 | [diff] [blame] | 194 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | heathrow_mb_power(struct media_bay_info* bay, int on_off) |
| 196 | { |
| 197 | if (on_off) { |
| 198 | /* Power up device, assert it's reset line */ |
| 199 | MB_BIC(bay, HEATHROW_FCR, HRW_BAY_RESET_N); |
| 200 | MB_BIC(bay, HEATHROW_FCR, HRW_BAY_POWER_N); |
| 201 | } else { |
| 202 | /* Disable all devices */ |
| 203 | MB_BIC(bay, HEATHROW_FCR, HRW_BAY_DEV_MASK); |
| 204 | MB_BIC(bay, HEATHROW_FCR, HRW_SWIM_ENABLE); |
| 205 | /* Cut power from bay, release reset line */ |
| 206 | MB_BIS(bay, HEATHROW_FCR, HRW_BAY_POWER_N); |
| 207 | MB_BIS(bay, HEATHROW_FCR, HRW_BAY_RESET_N); |
| 208 | MB_BIS(bay, HEATHROW_FCR, HRW_IDE1_RESET_N); |
| 209 | } |
| 210 | MB_BIC(bay, HEATHROW_MBCR, 0x00000F00); |
| 211 | } |
| 212 | |
Jon Loeliger | aacaf9b | 2005-09-17 10:36:54 -0500 | [diff] [blame] | 213 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | keylargo_mb_power(struct media_bay_info* bay, int on_off) |
| 215 | { |
| 216 | if (on_off) { |
| 217 | /* Power up device, assert it's reset line */ |
| 218 | MB_BIC(bay, KEYLARGO_MBCR, KL_MBCR_MB0_DEV_RESET); |
| 219 | MB_BIC(bay, KEYLARGO_MBCR, KL_MBCR_MB0_DEV_POWER); |
| 220 | } else { |
| 221 | /* Disable all devices */ |
| 222 | MB_BIC(bay, KEYLARGO_MBCR, KL_MBCR_MB0_DEV_MASK); |
| 223 | MB_BIC(bay, KEYLARGO_FCR1, KL1_EIDE0_ENABLE); |
| 224 | /* Cut power from bay, release reset line */ |
| 225 | MB_BIS(bay, KEYLARGO_MBCR, KL_MBCR_MB0_DEV_POWER); |
| 226 | MB_BIS(bay, KEYLARGO_MBCR, KL_MBCR_MB0_DEV_RESET); |
| 227 | MB_BIS(bay, KEYLARGO_FCR1, KL1_EIDE0_RESET_N); |
| 228 | } |
| 229 | MB_BIC(bay, KEYLARGO_MBCR, 0x0000000F); |
| 230 | } |
| 231 | |
| 232 | /* |
| 233 | * Functions for configuring the media bay for a given type of device, |
| 234 | * enable the related busses |
| 235 | */ |
| 236 | |
Jon Loeliger | aacaf9b | 2005-09-17 10:36:54 -0500 | [diff] [blame] | 237 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | ohare_mb_setup_bus(struct media_bay_info* bay, u8 device_id) |
| 239 | { |
| 240 | switch(device_id) { |
| 241 | case MB_FD: |
| 242 | case MB_FD1: |
| 243 | MB_BIS(bay, OHARE_FCR, OH_BAY_FLOPPY_ENABLE); |
| 244 | MB_BIS(bay, OHARE_FCR, OH_FLOPPY_ENABLE); |
| 245 | return 0; |
| 246 | case MB_CD: |
| 247 | MB_BIC(bay, OHARE_FCR, OH_IDE1_RESET_N); |
| 248 | MB_BIS(bay, OHARE_FCR, OH_BAY_IDE_ENABLE); |
| 249 | return 0; |
| 250 | case MB_PCI: |
| 251 | MB_BIS(bay, OHARE_FCR, OH_BAY_PCI_ENABLE); |
| 252 | return 0; |
| 253 | } |
| 254 | return -ENODEV; |
| 255 | } |
| 256 | |
Jon Loeliger | aacaf9b | 2005-09-17 10:36:54 -0500 | [diff] [blame] | 257 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | heathrow_mb_setup_bus(struct media_bay_info* bay, u8 device_id) |
| 259 | { |
| 260 | switch(device_id) { |
| 261 | case MB_FD: |
| 262 | case MB_FD1: |
| 263 | MB_BIS(bay, HEATHROW_FCR, HRW_BAY_FLOPPY_ENABLE); |
| 264 | MB_BIS(bay, HEATHROW_FCR, HRW_SWIM_ENABLE); |
| 265 | return 0; |
| 266 | case MB_CD: |
| 267 | MB_BIC(bay, HEATHROW_FCR, HRW_IDE1_RESET_N); |
| 268 | MB_BIS(bay, HEATHROW_FCR, HRW_BAY_IDE_ENABLE); |
| 269 | return 0; |
| 270 | case MB_PCI: |
| 271 | MB_BIS(bay, HEATHROW_FCR, HRW_BAY_PCI_ENABLE); |
| 272 | return 0; |
| 273 | } |
| 274 | return -ENODEV; |
| 275 | } |
| 276 | |
Jon Loeliger | aacaf9b | 2005-09-17 10:36:54 -0500 | [diff] [blame] | 277 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | keylargo_mb_setup_bus(struct media_bay_info* bay, u8 device_id) |
| 279 | { |
| 280 | switch(device_id) { |
| 281 | case MB_CD: |
| 282 | MB_BIS(bay, KEYLARGO_MBCR, KL_MBCR_MB0_IDE_ENABLE); |
| 283 | MB_BIC(bay, KEYLARGO_FCR1, KL1_EIDE0_RESET_N); |
| 284 | MB_BIS(bay, KEYLARGO_FCR1, KL1_EIDE0_ENABLE); |
| 285 | return 0; |
| 286 | case MB_PCI: |
| 287 | MB_BIS(bay, KEYLARGO_MBCR, KL_MBCR_MB0_PCI_ENABLE); |
| 288 | return 0; |
| 289 | case MB_SOUND: |
| 290 | MB_BIS(bay, KEYLARGO_MBCR, KL_MBCR_MB0_SOUND_ENABLE); |
| 291 | return 0; |
| 292 | } |
| 293 | return -ENODEV; |
| 294 | } |
| 295 | |
| 296 | /* |
| 297 | * Functions for tweaking resets |
| 298 | */ |
| 299 | |
Jon Loeliger | aacaf9b | 2005-09-17 10:36:54 -0500 | [diff] [blame] | 300 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | ohare_mb_un_reset(struct media_bay_info* bay) |
| 302 | { |
| 303 | MB_BIS(bay, OHARE_FCR, OH_BAY_RESET_N); |
| 304 | } |
| 305 | |
Jon Loeliger | aacaf9b | 2005-09-17 10:36:54 -0500 | [diff] [blame] | 306 | static void keylargo_mb_init(struct media_bay_info *bay) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | { |
| 308 | MB_BIS(bay, KEYLARGO_MBCR, KL_MBCR_MB0_ENABLE); |
| 309 | } |
| 310 | |
Jon Loeliger | aacaf9b | 2005-09-17 10:36:54 -0500 | [diff] [blame] | 311 | static void heathrow_mb_un_reset(struct media_bay_info* bay) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | { |
| 313 | MB_BIS(bay, HEATHROW_FCR, HRW_BAY_RESET_N); |
| 314 | } |
| 315 | |
Jon Loeliger | aacaf9b | 2005-09-17 10:36:54 -0500 | [diff] [blame] | 316 | static void keylargo_mb_un_reset(struct media_bay_info* bay) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | { |
| 318 | MB_BIS(bay, KEYLARGO_MBCR, KL_MBCR_MB0_DEV_RESET); |
| 319 | } |
| 320 | |
Jon Loeliger | aacaf9b | 2005-09-17 10:36:54 -0500 | [diff] [blame] | 321 | static void ohare_mb_un_reset_ide(struct media_bay_info* bay) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | { |
| 323 | MB_BIS(bay, OHARE_FCR, OH_IDE1_RESET_N); |
| 324 | } |
| 325 | |
Jon Loeliger | aacaf9b | 2005-09-17 10:36:54 -0500 | [diff] [blame] | 326 | static void heathrow_mb_un_reset_ide(struct media_bay_info* bay) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | { |
| 328 | MB_BIS(bay, HEATHROW_FCR, HRW_IDE1_RESET_N); |
| 329 | } |
| 330 | |
Jon Loeliger | aacaf9b | 2005-09-17 10:36:54 -0500 | [diff] [blame] | 331 | static void keylargo_mb_un_reset_ide(struct media_bay_info* bay) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | { |
| 333 | MB_BIS(bay, KEYLARGO_FCR1, KL1_EIDE0_RESET_N); |
| 334 | } |
| 335 | |
Jon Loeliger | aacaf9b | 2005-09-17 10:36:54 -0500 | [diff] [blame] | 336 | static inline void set_mb_power(struct media_bay_info* bay, int onoff) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | { |
| 338 | /* Power up up and assert the bay reset line */ |
| 339 | if (onoff) { |
| 340 | bay->ops->power(bay, 1); |
| 341 | bay->state = mb_powering_up; |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 342 | pr_debug("mediabay%d: powering up\n", bay->index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | } else { |
| 344 | /* Make sure everything is powered down & disabled */ |
| 345 | bay->ops->power(bay, 0); |
| 346 | bay->state = mb_powering_down; |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 347 | pr_debug("mediabay%d: powering down\n", bay->index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | } |
| 349 | bay->timer = msecs_to_jiffies(MB_POWER_DELAY); |
| 350 | } |
| 351 | |
Jon Loeliger | aacaf9b | 2005-09-17 10:36:54 -0500 | [diff] [blame] | 352 | static void poll_media_bay(struct media_bay_info* bay) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | { |
| 354 | int id = bay->ops->content(bay); |
| 355 | |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 356 | static char *mb_content_types[] = { |
| 357 | "a floppy drive", |
| 358 | "a floppy drive", |
Masanari Iida | ec16f3df | 2012-01-24 02:26:36 +0900 | [diff] [blame] | 359 | "an unsupported audio device", |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 360 | "an ATA device", |
| 361 | "an unsupported PCI device", |
| 362 | "an unknown device", |
| 363 | }; |
| 364 | |
| 365 | if (id != bay->last_value) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | bay->last_value = id; |
| 367 | bay->value_count = 0; |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 368 | return; |
| 369 | } |
| 370 | if (id == bay->content_id) |
| 371 | return; |
| 372 | |
| 373 | bay->value_count += msecs_to_jiffies(MB_POLL_DELAY); |
| 374 | if (bay->value_count >= msecs_to_jiffies(MB_STABLE_DELAY)) { |
| 375 | /* If the device type changes without going thru |
| 376 | * "MB_NO", we force a pass by "MB_NO" to make sure |
| 377 | * things are properly reset |
| 378 | */ |
| 379 | if ((id != MB_NO) && (bay->content_id != MB_NO)) { |
| 380 | id = MB_NO; |
| 381 | pr_debug("mediabay%d: forcing MB_NO\n", bay->index); |
| 382 | } |
| 383 | pr_debug("mediabay%d: switching to %d\n", bay->index, id); |
| 384 | set_mb_power(bay, id != MB_NO); |
| 385 | bay->content_id = id; |
| 386 | if (id >= MB_NO || id < 0) |
| 387 | printk(KERN_INFO "mediabay%d: Bay is now empty\n", bay->index); |
| 388 | else |
| 389 | printk(KERN_INFO "mediabay%d: Bay contains %s\n", |
| 390 | bay->index, mb_content_types[id]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | } |
| 392 | } |
| 393 | |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 394 | int check_media_bay(struct macio_dev *baydev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | { |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 396 | struct media_bay_info* bay; |
| 397 | int id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 399 | if (baydev == NULL) |
| 400 | return MB_NO; |
| 401 | |
| 402 | /* This returns an instant snapshot, not locking, sine |
| 403 | * we may be called with the bay lock held. The resulting |
| 404 | * fuzzyness of the result if called at the wrong time is |
| 405 | * not actually a huge deal |
| 406 | */ |
| 407 | bay = macio_get_drvdata(baydev); |
| 408 | if (bay == NULL) |
| 409 | return MB_NO; |
| 410 | id = bay->content_id; |
| 411 | if (bay->state != mb_up) |
| 412 | return MB_NO; |
| 413 | if (id == MB_FD1) |
| 414 | return MB_FD; |
| 415 | return id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | } |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 417 | EXPORT_SYMBOL_GPL(check_media_bay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 419 | void lock_media_bay(struct macio_dev *baydev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | { |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 421 | struct media_bay_info* bay; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 423 | if (baydev == NULL) |
| 424 | return; |
| 425 | bay = macio_get_drvdata(baydev); |
| 426 | if (bay == NULL) |
| 427 | return; |
| 428 | mutex_lock(&bay->lock); |
| 429 | bay->user_lock = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | } |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 431 | EXPORT_SYMBOL_GPL(lock_media_bay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 433 | void unlock_media_bay(struct macio_dev *baydev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | { |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 435 | struct media_bay_info* bay; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 437 | if (baydev == NULL) |
| 438 | return; |
| 439 | bay = macio_get_drvdata(baydev); |
| 440 | if (bay == NULL) |
| 441 | return; |
| 442 | if (bay->user_lock) { |
| 443 | bay->user_lock = 0; |
| 444 | mutex_unlock(&bay->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | } |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 447 | EXPORT_SYMBOL_GPL(unlock_media_bay); |
| 448 | |
| 449 | static int mb_broadcast_hotplug(struct device *dev, void *data) |
| 450 | { |
| 451 | struct media_bay_info* bay = data; |
| 452 | struct macio_dev *mdev; |
| 453 | struct macio_driver *drv; |
| 454 | int state; |
| 455 | |
| 456 | if (dev->bus != &macio_bus_type) |
| 457 | return 0; |
| 458 | |
| 459 | state = bay->state == mb_up ? bay->content_id : MB_NO; |
| 460 | if (state == MB_FD1) |
| 461 | state = MB_FD; |
| 462 | mdev = to_macio_device(dev); |
| 463 | drv = to_macio_driver(dev->driver); |
| 464 | if (dev->driver && drv->mediabay_event) |
| 465 | drv->mediabay_event(mdev, state); |
| 466 | return 0; |
| 467 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | |
Jon Loeliger | aacaf9b | 2005-09-17 10:36:54 -0500 | [diff] [blame] | 469 | static void media_bay_step(int i) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | { |
| 471 | struct media_bay_info* bay = &media_bays[i]; |
| 472 | |
| 473 | /* We don't poll when powering down */ |
| 474 | if (bay->state != mb_powering_down) |
| 475 | poll_media_bay(bay); |
| 476 | |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 477 | /* If timer expired run state machine */ |
| 478 | if (bay->timer != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | bay->timer -= msecs_to_jiffies(MB_POLL_DELAY); |
| 480 | if (bay->timer > 0) |
| 481 | return; |
| 482 | bay->timer = 0; |
| 483 | } |
| 484 | |
| 485 | switch(bay->state) { |
| 486 | case mb_powering_up: |
| 487 | if (bay->ops->setup_bus(bay, bay->last_value) < 0) { |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 488 | pr_debug("mediabay%d: device not supported (kind:%d)\n", |
| 489 | i, bay->content_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | set_mb_power(bay, 0); |
| 491 | break; |
| 492 | } |
| 493 | bay->timer = msecs_to_jiffies(MB_RESET_DELAY); |
| 494 | bay->state = mb_enabling_bay; |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 495 | pr_debug("mediabay%d: enabling (kind:%d)\n", i, bay->content_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | break; |
| 497 | case mb_enabling_bay: |
| 498 | bay->ops->un_reset(bay); |
| 499 | bay->timer = msecs_to_jiffies(MB_SETUP_DELAY); |
| 500 | bay->state = mb_resetting; |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 501 | pr_debug("mediabay%d: releasing bay reset (kind:%d)\n", |
| 502 | i, bay->content_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | case mb_resetting: |
| 505 | if (bay->content_id != MB_CD) { |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 506 | pr_debug("mediabay%d: bay is up (kind:%d)\n", i, |
| 507 | bay->content_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | bay->state = mb_up; |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 509 | device_for_each_child(&bay->mdev->ofdev.dev, |
| 510 | bay, mb_broadcast_hotplug); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | break; |
| 512 | } |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 513 | pr_debug("mediabay%d: releasing ATA reset (kind:%d)\n", |
| 514 | i, bay->content_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | bay->ops->un_reset_ide(bay); |
| 516 | bay->timer = msecs_to_jiffies(MB_IDE_WAIT); |
| 517 | bay->state = mb_ide_resetting; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | break; |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 519 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | case mb_ide_resetting: |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 521 | pr_debug("mediabay%d: bay is up (kind:%d)\n", i, bay->content_id); |
| 522 | bay->state = mb_up; |
| 523 | device_for_each_child(&bay->mdev->ofdev.dev, |
| 524 | bay, mb_broadcast_hotplug); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | break; |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 526 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | case mb_powering_down: |
| 528 | bay->state = mb_empty; |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 529 | device_for_each_child(&bay->mdev->ofdev.dev, |
| 530 | bay, mb_broadcast_hotplug); |
| 531 | pr_debug("mediabay%d: end of power down\n", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | break; |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | /* |
| 537 | * This procedure runs as a kernel thread to poll the media bay |
| 538 | * once each tick and register and unregister the IDE interface |
| 539 | * with the IDE driver. It needs to be a thread because |
| 540 | * ide_register can't be called from interrupt context. |
| 541 | */ |
Jon Loeliger | aacaf9b | 2005-09-17 10:36:54 -0500 | [diff] [blame] | 542 | static int media_bay_task(void *x) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | { |
| 544 | int i; |
| 545 | |
Paul Mackerras | 33f6e79 | 2007-12-13 14:12:58 +1100 | [diff] [blame] | 546 | while (!kthread_should_stop()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | for (i = 0; i < media_bay_count; ++i) { |
Daniel Walker | 9a24729 | 2008-06-10 09:26:09 +1000 | [diff] [blame] | 548 | mutex_lock(&media_bays[i].lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | if (!media_bays[i].sleeping) |
| 550 | media_bay_step(i); |
Daniel Walker | 9a24729 | 2008-06-10 09:26:09 +1000 | [diff] [blame] | 551 | mutex_unlock(&media_bays[i].lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | msleep_interruptible(MB_POLL_DELAY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | } |
Paul Mackerras | 33f6e79 | 2007-12-13 14:12:58 +1100 | [diff] [blame] | 556 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | } |
| 558 | |
Greg Kroah-Hartman | 1da42fb | 2012-12-21 15:03:50 -0800 | [diff] [blame] | 559 | static int media_bay_attach(struct macio_dev *mdev, |
| 560 | const struct of_device_id *match) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | { |
| 562 | struct media_bay_info* bay; |
| 563 | u32 __iomem *regbase; |
| 564 | struct device_node *ofnode; |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 565 | unsigned long base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | int i; |
| 567 | |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 568 | ofnode = mdev->ofdev.dev.of_node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | |
| 570 | if (macio_resource_count(mdev) < 1) |
| 571 | return -ENODEV; |
| 572 | if (macio_request_resources(mdev, "media-bay")) |
| 573 | return -EBUSY; |
| 574 | /* Media bay registers are located at the beginning of the |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 575 | * mac-io chip, for now, we trick and align down the first |
| 576 | * resource passed in |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | */ |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 578 | base = macio_resource_start(mdev, 0) & 0xffff0000u; |
| 579 | regbase = (u32 __iomem *)ioremap(base, 0x100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | if (regbase == NULL) { |
| 581 | macio_release_resources(mdev); |
| 582 | return -ENOMEM; |
| 583 | } |
| 584 | |
| 585 | i = media_bay_count++; |
| 586 | bay = &media_bays[i]; |
| 587 | bay->mdev = mdev; |
| 588 | bay->base = regbase; |
| 589 | bay->index = i; |
| 590 | bay->ops = match->data; |
| 591 | bay->sleeping = 0; |
Daniel Walker | 9a24729 | 2008-06-10 09:26:09 +1000 | [diff] [blame] | 592 | mutex_init(&bay->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | |
| 594 | /* Init HW probing */ |
| 595 | if (bay->ops->init) |
| 596 | bay->ops->init(bay); |
| 597 | |
| 598 | printk(KERN_INFO "mediabay%d: Registered %s media-bay\n", i, bay->ops->name); |
| 599 | |
| 600 | /* Force an immediate detect */ |
| 601 | set_mb_power(bay, 0); |
| 602 | msleep(MB_POWER_DELAY); |
| 603 | bay->content_id = MB_NO; |
| 604 | bay->last_value = bay->ops->content(bay); |
| 605 | bay->value_count = msecs_to_jiffies(MB_STABLE_DELAY); |
| 606 | bay->state = mb_empty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | |
| 608 | /* Mark us ready by filling our mdev data */ |
| 609 | macio_set_drvdata(mdev, bay); |
| 610 | |
| 611 | /* Startup kernel thread */ |
| 612 | if (i == 0) |
Paul Mackerras | 33f6e79 | 2007-12-13 14:12:58 +1100 | [diff] [blame] | 613 | kthread_run(media_bay_task, NULL, "media-bay"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | |
| 615 | return 0; |
| 616 | |
| 617 | } |
| 618 | |
Jon Loeliger | aacaf9b | 2005-09-17 10:36:54 -0500 | [diff] [blame] | 619 | static int media_bay_suspend(struct macio_dev *mdev, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | { |
| 621 | struct media_bay_info *bay = macio_get_drvdata(mdev); |
| 622 | |
Rafael J. Wysocki | 3a2d5b7 | 2008-02-23 19:13:25 +0100 | [diff] [blame] | 623 | if (state.event != mdev->ofdev.dev.power.power_state.event |
| 624 | && (state.event & PM_EVENT_SLEEP)) { |
Daniel Walker | 9a24729 | 2008-06-10 09:26:09 +1000 | [diff] [blame] | 625 | mutex_lock(&bay->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | bay->sleeping = 1; |
| 627 | set_mb_power(bay, 0); |
Daniel Walker | 9a24729 | 2008-06-10 09:26:09 +1000 | [diff] [blame] | 628 | mutex_unlock(&bay->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | msleep(MB_POLL_DELAY); |
| 630 | mdev->ofdev.dev.power.power_state = state; |
| 631 | } |
| 632 | return 0; |
| 633 | } |
| 634 | |
Jon Loeliger | aacaf9b | 2005-09-17 10:36:54 -0500 | [diff] [blame] | 635 | static int media_bay_resume(struct macio_dev *mdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | { |
| 637 | struct media_bay_info *bay = macio_get_drvdata(mdev); |
| 638 | |
Pavel Machek | ca078ba | 2005-09-03 15:56:57 -0700 | [diff] [blame] | 639 | if (mdev->ofdev.dev.power.power_state.event != PM_EVENT_ON) { |
Pavel Machek | 829ca9a | 2005-09-03 15:56:56 -0700 | [diff] [blame] | 640 | mdev->ofdev.dev.power.power_state = PMSG_ON; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | |
| 642 | /* We re-enable the bay using it's previous content |
| 643 | only if it did not change. Note those bozo timings, |
| 644 | they seem to help the 3400 get it right. |
| 645 | */ |
| 646 | /* Force MB power to 0 */ |
Daniel Walker | 9a24729 | 2008-06-10 09:26:09 +1000 | [diff] [blame] | 647 | mutex_lock(&bay->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | set_mb_power(bay, 0); |
| 649 | msleep(MB_POWER_DELAY); |
| 650 | if (bay->ops->content(bay) != bay->content_id) { |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 651 | printk("mediabay%d: Content changed during sleep...\n", bay->index); |
Daniel Walker | 9a24729 | 2008-06-10 09:26:09 +1000 | [diff] [blame] | 652 | mutex_unlock(&bay->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | return 0; |
| 654 | } |
| 655 | set_mb_power(bay, 1); |
| 656 | bay->last_value = bay->content_id; |
| 657 | bay->value_count = msecs_to_jiffies(MB_STABLE_DELAY); |
| 658 | bay->timer = msecs_to_jiffies(MB_POWER_DELAY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | do { |
| 660 | msleep(MB_POLL_DELAY); |
| 661 | media_bay_step(bay->index); |
| 662 | } while((bay->state != mb_empty) && |
| 663 | (bay->state != mb_up)); |
| 664 | bay->sleeping = 0; |
Daniel Walker | 9a24729 | 2008-06-10 09:26:09 +1000 | [diff] [blame] | 665 | mutex_unlock(&bay->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | } |
| 667 | return 0; |
| 668 | } |
| 669 | |
| 670 | |
| 671 | /* Definitions of "ops" structures. |
| 672 | */ |
Arnd Bergmann | 306e352 | 2012-07-13 16:24:26 +0000 | [diff] [blame] | 673 | static const struct mb_ops ohare_mb_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | .name = "Ohare", |
| 675 | .content = ohare_mb_content, |
| 676 | .power = ohare_mb_power, |
| 677 | .setup_bus = ohare_mb_setup_bus, |
| 678 | .un_reset = ohare_mb_un_reset, |
| 679 | .un_reset_ide = ohare_mb_un_reset_ide, |
| 680 | }; |
| 681 | |
Arnd Bergmann | 306e352 | 2012-07-13 16:24:26 +0000 | [diff] [blame] | 682 | static const struct mb_ops heathrow_mb_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | .name = "Heathrow", |
| 684 | .content = heathrow_mb_content, |
| 685 | .power = heathrow_mb_power, |
| 686 | .setup_bus = heathrow_mb_setup_bus, |
| 687 | .un_reset = heathrow_mb_un_reset, |
| 688 | .un_reset_ide = heathrow_mb_un_reset_ide, |
| 689 | }; |
| 690 | |
Arnd Bergmann | 306e352 | 2012-07-13 16:24:26 +0000 | [diff] [blame] | 691 | static const struct mb_ops keylargo_mb_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | .name = "KeyLargo", |
| 693 | .init = keylargo_mb_init, |
| 694 | .content = keylargo_mb_content, |
| 695 | .power = keylargo_mb_power, |
| 696 | .setup_bus = keylargo_mb_setup_bus, |
| 697 | .un_reset = keylargo_mb_un_reset, |
| 698 | .un_reset_ide = keylargo_mb_un_reset_ide, |
| 699 | }; |
| 700 | |
| 701 | /* |
| 702 | * It seems that the bit for the media-bay interrupt in the IRQ_LEVEL |
| 703 | * register is always set when there is something in the media bay. |
| 704 | * This causes problems for the interrupt code if we attach an interrupt |
| 705 | * handler to the media-bay interrupt, because it tends to go into |
| 706 | * an infinite loop calling the media bay interrupt handler. |
| 707 | * Therefore we do it all by polling the media bay once each tick. |
| 708 | */ |
| 709 | |
Jeff Mahoney | 5e65577 | 2005-07-06 15:44:41 -0400 | [diff] [blame] | 710 | static struct of_device_id media_bay_match[] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | { |
| 712 | { |
| 713 | .name = "media-bay", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | .compatible = "keylargo-media-bay", |
| 715 | .data = &keylargo_mb_ops, |
| 716 | }, |
| 717 | { |
| 718 | .name = "media-bay", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | .compatible = "heathrow-media-bay", |
| 720 | .data = &heathrow_mb_ops, |
| 721 | }, |
| 722 | { |
| 723 | .name = "media-bay", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | .compatible = "ohare-media-bay", |
| 725 | .data = &ohare_mb_ops, |
| 726 | }, |
| 727 | {}, |
| 728 | }; |
| 729 | |
| 730 | static struct macio_driver media_bay_driver = |
| 731 | { |
Benjamin Herrenschmidt | c2cdf6a | 2010-06-02 17:09:18 +1000 | [diff] [blame] | 732 | .driver = { |
| 733 | .name = "media-bay", |
| 734 | .of_match_table = media_bay_match, |
| 735 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | .probe = media_bay_attach, |
| 737 | .suspend = media_bay_suspend, |
| 738 | .resume = media_bay_resume |
| 739 | }; |
| 740 | |
| 741 | static int __init media_bay_init(void) |
| 742 | { |
| 743 | int i; |
| 744 | |
| 745 | for (i=0; i<MAX_BAYS; i++) { |
| 746 | memset((char *)&media_bays[i], 0, sizeof(struct media_bay_info)); |
| 747 | media_bays[i].content_id = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | } |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 749 | if (!machine_is(powermac)) |
| 750 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | |
| 752 | macio_register_driver(&media_bay_driver); |
| 753 | |
| 754 | return 0; |
| 755 | } |
| 756 | |
| 757 | device_initcall(media_bay_init); |