cmd640: remove cmd_drives[]

* Pass 'ide_drive_t *drive' to check_prefetch(), set_prefetch_mode(),
  program_drive_counts() and cmd640_set_mode().

* Remove no longer needed cmd_drives[].

* Inline setup_device_ptrs() helper in cmd640x_init().
Signed-off-by: default avatarBartlomiej Zolnierkiewicz <bzolnier@gmail.com>
parent 4f7bada2
...@@ -185,7 +185,6 @@ static DEFINE_SPINLOCK(cmd640_lock); ...@@ -185,7 +185,6 @@ static DEFINE_SPINLOCK(cmd640_lock);
* These are initialized to point at the devices we control * These are initialized to point at the devices we control
*/ */
static ide_hwif_t *cmd_hwif0, *cmd_hwif1; static ide_hwif_t *cmd_hwif0, *cmd_hwif1;
static ide_drive_t *cmd_drives[4];
/* /*
* Interface to access cmd640x registers * Interface to access cmd640x registers
...@@ -386,9 +385,8 @@ static void cmd640_dump_regs (void) ...@@ -386,9 +385,8 @@ static void cmd640_dump_regs (void)
* Check whether prefetch is on for a drive, * Check whether prefetch is on for a drive,
* and initialize the unmask flags for safe operation. * and initialize the unmask flags for safe operation.
*/ */
static void __init check_prefetch (unsigned int index) static void __init check_prefetch(ide_drive_t *drive, unsigned int index)
{ {
ide_drive_t *drive = cmd_drives[index];
u8 b = get_cmd640_reg(prefetch_regs[index]); u8 b = get_cmd640_reg(prefetch_regs[index]);
if (b & prefetch_masks[index]) { /* is prefetch off? */ if (b & prefetch_masks[index]) { /* is prefetch off? */
...@@ -404,28 +402,13 @@ static void __init check_prefetch (unsigned int index) ...@@ -404,28 +402,13 @@ static void __init check_prefetch (unsigned int index)
} }
} }
/*
* Figure out which devices we control
*/
static void __init setup_device_ptrs (void)
{
cmd_hwif0 = &ide_hwifs[0];
cmd_hwif1 = &ide_hwifs[1];
cmd_drives[0] = &cmd_hwif0->drives[0];
cmd_drives[1] = &cmd_hwif0->drives[1];
cmd_drives[2] = &cmd_hwif1->drives[0];
cmd_drives[3] = &cmd_hwif1->drives[1];
}
#ifdef CONFIG_BLK_DEV_CMD640_ENHANCED #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED
/* /*
* Sets prefetch mode for a drive. * Sets prefetch mode for a drive.
*/ */
static void set_prefetch_mode (unsigned int index, int mode) static void set_prefetch_mode(ide_drive_t *drive, unsigned int index, int mode)
{ {
ide_drive_t *drive = cmd_drives[index];
unsigned long flags; unsigned long flags;
int reg = prefetch_regs[index]; int reg = prefetch_regs[index];
u8 b; u8 b;
...@@ -508,7 +491,7 @@ static void __init retrieve_drive_counts (unsigned int index) ...@@ -508,7 +491,7 @@ static void __init retrieve_drive_counts (unsigned int index)
* This routine writes the prepared setup/active/recovery counts * This routine writes the prepared setup/active/recovery counts
* for a drive into the cmd640 chipset registers to active them. * for a drive into the cmd640 chipset registers to active them.
*/ */
static void program_drive_counts (unsigned int index) static void program_drive_counts(ide_drive_t *drive, unsigned int index)
{ {
unsigned long flags; unsigned long flags;
u8 setup_count = setup_counts[index]; u8 setup_count = setup_counts[index];
...@@ -522,8 +505,11 @@ static void program_drive_counts (unsigned int index) ...@@ -522,8 +505,11 @@ static void program_drive_counts (unsigned int index)
* so we merge the timings, using the slowest value for each timing. * so we merge the timings, using the slowest value for each timing.
*/ */
if (index > 1) { if (index > 1) {
unsigned int mate; ide_hwif_t *hwif = drive->hwif;
if (cmd_drives[mate = index ^ 1]->present) { ide_drive_t *peer = &hwif->drives[!drive->select.b.unit];
unsigned int mate = index ^ 1;
if (peer->present) {
if (setup_count < setup_counts[mate]) if (setup_count < setup_counts[mate])
setup_count = setup_counts[mate]; setup_count = setup_counts[mate];
if (active_count < active_counts[mate]) if (active_count < active_counts[mate])
...@@ -562,7 +548,8 @@ static void program_drive_counts (unsigned int index) ...@@ -562,7 +548,8 @@ static void program_drive_counts (unsigned int index)
/* /*
* Set a specific pio_mode for a drive * Set a specific pio_mode for a drive
*/ */
static void cmd640_set_mode (unsigned int index, u8 pio_mode, unsigned int cycle_time) static void cmd640_set_mode(ide_drive_t *drive, unsigned int index,
u8 pio_mode, unsigned int cycle_time)
{ {
int setup_time, active_time, recovery_time, clock_time; int setup_time, active_time, recovery_time, clock_time;
u8 setup_count, active_count, recovery_count, recovery_count2, cycle_count; u8 setup_count, active_count, recovery_count, recovery_count2, cycle_count;
...@@ -611,7 +598,7 @@ static void cmd640_set_mode (unsigned int index, u8 pio_mode, unsigned int cycle ...@@ -611,7 +598,7 @@ static void cmd640_set_mode (unsigned int index, u8 pio_mode, unsigned int cycle
* 1) this is the wrong place to do it (proper is do_special() in ide.c) * 1) this is the wrong place to do it (proper is do_special() in ide.c)
* 2) in practice this is rarely, if ever, necessary * 2) in practice this is rarely, if ever, necessary
*/ */
program_drive_counts (index); program_drive_counts(drive, index);
} }
static void cmd640_set_pio_mode(ide_drive_t *drive, const u8 pio) static void cmd640_set_pio_mode(ide_drive_t *drive, const u8 pio)
...@@ -619,13 +606,6 @@ static void cmd640_set_pio_mode(ide_drive_t *drive, const u8 pio) ...@@ -619,13 +606,6 @@ static void cmd640_set_pio_mode(ide_drive_t *drive, const u8 pio)
unsigned int index = 0, cycle_time; unsigned int index = 0, cycle_time;
u8 b; u8 b;
while (drive != cmd_drives[index]) {
if (++index > 3) {
printk(KERN_ERR "%s: bad news in %s\n",
drive->name, __FUNCTION__);
return;
}
}
switch (pio) { switch (pio) {
case 6: /* set fast-devsel off */ case 6: /* set fast-devsel off */
case 7: /* set fast-devsel on */ case 7: /* set fast-devsel on */
...@@ -638,13 +618,13 @@ static void cmd640_set_pio_mode(ide_drive_t *drive, const u8 pio) ...@@ -638,13 +618,13 @@ static void cmd640_set_pio_mode(ide_drive_t *drive, const u8 pio)
case 8: /* set prefetch off */ case 8: /* set prefetch off */
case 9: /* set prefetch on */ case 9: /* set prefetch on */
set_prefetch_mode(index, pio & 1); set_prefetch_mode(drive, index, pio & 1);
printk("%s: %sabled cmd640 prefetch\n", drive->name, (pio & 1) ? "en" : "dis"); printk("%s: %sabled cmd640 prefetch\n", drive->name, (pio & 1) ? "en" : "dis");
return; return;
} }
cycle_time = ide_pio_cycle_time(drive, pio); cycle_time = ide_pio_cycle_time(drive, pio);
cmd640_set_mode(index, pio, cycle_time); cmd640_set_mode(drive, index, pio, cycle_time);
printk("%s: selected cmd640 PIO mode%d (%dns)", printk("%s: selected cmd640 PIO mode%d (%dns)",
drive->name, pio, cycle_time); drive->name, pio, cycle_time);
...@@ -764,11 +744,12 @@ static int __init cmd640x_init(void) ...@@ -764,11 +744,12 @@ static int __init cmd640x_init(void)
printk(KERN_INFO "cmd640: buggy cmd640%c interface on %s, config=0x%02x" printk(KERN_INFO "cmd640: buggy cmd640%c interface on %s, config=0x%02x"
"\n", 'a' + cmd640_chip_version - 1, bus_type, cfr); "\n", 'a' + cmd640_chip_version - 1, bus_type, cfr);
cmd_hwif0 = &ide_hwifs[0];
cmd_hwif1 = &ide_hwifs[1];
/* /*
* Initialize data for primary port * Initialize data for primary port
*/ */
setup_device_ptrs ();
ide_init_port_hw(cmd_hwif0, &hw[0]); ide_init_port_hw(cmd_hwif0, &hw[0]);
#ifdef CONFIG_BLK_DEV_CMD640_ENHANCED #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED
cmd_hwif0->set_pio_mode = &cmd640_set_pio_mode; cmd_hwif0->set_pio_mode = &cmd640_set_pio_mode;
...@@ -836,7 +817,13 @@ static int __init cmd640x_init(void) ...@@ -836,7 +817,13 @@ static int __init cmd640x_init(void)
* Do not unnecessarily disturb any prior BIOS setup of these. * Do not unnecessarily disturb any prior BIOS setup of these.
*/ */
for (index = 0; index < (2 + (second_port_cmd640 << 1)); index++) { for (index = 0; index < (2 + (second_port_cmd640 << 1)); index++) {
ide_drive_t *drive = cmd_drives[index]; ide_drive_t *drive;
if (index > 1)
drive = &cmd_hwif1->drives[index & 1];
else
drive = &cmd_hwif0->drives[index & 1];
#ifdef CONFIG_BLK_DEV_CMD640_ENHANCED #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED
if (drive->autotune || ((index > 1) && second_port_toggled)) { if (drive->autotune || ((index > 1) && second_port_toggled)) {
/* /*
...@@ -846,8 +833,8 @@ static int __init cmd640x_init(void) ...@@ -846,8 +833,8 @@ static int __init cmd640x_init(void)
setup_counts [index] = 4; /* max possible */ setup_counts [index] = 4; /* max possible */
active_counts [index] = 16; /* max possible */ active_counts [index] = 16; /* max possible */
recovery_counts [index] = 16; /* max possible */ recovery_counts [index] = 16; /* max possible */
program_drive_counts (index); program_drive_counts(drive, index);
set_prefetch_mode (index, 0); set_prefetch_mode(drive, index, 0);
printk("cmd640: drive%d timings/prefetch cleared\n", index); printk("cmd640: drive%d timings/prefetch cleared\n", index);
} else { } else {
/* /*
...@@ -855,7 +842,7 @@ static int __init cmd640x_init(void) ...@@ -855,7 +842,7 @@ static int __init cmd640x_init(void)
* This preserves any prior BIOS setup. * This preserves any prior BIOS setup.
*/ */
retrieve_drive_counts (index); retrieve_drive_counts (index);
check_prefetch (index); check_prefetch(drive, index);
printk("cmd640: drive%d timings/prefetch(%s) preserved", printk("cmd640: drive%d timings/prefetch(%s) preserved",
index, drive->no_io_32bit ? "off" : "on"); index, drive->no_io_32bit ? "off" : "on");
display_clocks(index); display_clocks(index);
...@@ -864,7 +851,7 @@ static int __init cmd640x_init(void) ...@@ -864,7 +851,7 @@ static int __init cmd640x_init(void)
/* /*
* Set the drive unmask flags to match the prefetch setting * Set the drive unmask flags to match the prefetch setting
*/ */
check_prefetch (index); check_prefetch(drive, index);
printk("cmd640: drive%d timings/prefetch(%s) preserved\n", printk("cmd640: drive%d timings/prefetch(%s) preserved\n",
index, drive->no_io_32bit ? "off" : "on"); index, drive->no_io_32bit ? "off" : "on");
#endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ #endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment