]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/ide/pci/cmd640.c
ide: use DIV_ROUND_UP
[linux-2.6-omap-h63xx.git] / drivers / ide / pci / cmd640.c
index 3303ffb327a7e659f20854f12a37d118b433b1a3..662099a98a72e24688c8e071f709c58328d72eb7 100644 (file)
@@ -561,15 +561,15 @@ static void cmd640_set_mode(ide_drive_t *drive, unsigned int index,
        active_time = ide_pio_timings[pio_mode].active_time;
        recovery_time = cycle_time - (setup_time + active_time);
        clock_time = 1000 / bus_speed;
-       cycle_count = (cycle_time + clock_time - 1) / clock_time;
+       cycle_count = DIV_ROUND_UP(cycle_time, clock_time);
 
-       setup_count = (setup_time + clock_time - 1) / clock_time;
+       setup_count = DIV_ROUND_UP(setup_time, clock_time);
 
-       active_count = (active_time + clock_time - 1) / clock_time;
+       active_count = DIV_ROUND_UP(active_time, clock_time);
        if (active_count < 2)
                active_count = 2; /* minimum allowed by cmd640 */
 
-       recovery_count = (recovery_time + clock_time - 1) / clock_time;
+       recovery_count = DIV_ROUND_UP(recovery_time, clock_time);
        recovery_count2 = cycle_count - (setup_count + active_count);
        if (recovery_count2 > recovery_count)
                recovery_count = recovery_count2;
@@ -744,18 +744,19 @@ static int __init cmd640x_init(void)
        printk(KERN_INFO "cmd640: buggy cmd640%c interface on %s, config=0x%02x"
                         "\n", 'a' + cmd640_chip_version - 1, bus_type, cfr);
 
-       cmd_hwif0 = &ide_hwifs[0];
-       cmd_hwif1 = &ide_hwifs[1];
+       cmd_hwif0 = ide_find_port();
 
        /*
         * Initialize data for primary port
         */
-       ide_init_port_hw(cmd_hwif0, &hw[0]);
+       if (cmd_hwif0) {
+               ide_init_port_hw(cmd_hwif0, &hw[0]);
 #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED
-       cmd_hwif0->set_pio_mode = &cmd640_set_pio_mode;
+               cmd_hwif0->set_pio_mode = &cmd640_set_pio_mode;
 #endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */
 
-       idx[0] = cmd_hwif0->index;
+               idx[0] = cmd_hwif0->index;
+       }
 
        /*
         * Ensure compatibility by always using the slowest timings
@@ -767,10 +768,13 @@ static int __init cmd640x_init(void)
        put_cmd640_reg(CMDTIM, 0);
        put_cmd640_reg(BRST, 0x40);
 
+       cmd_hwif1 = ide_find_port();
+
        /*
         * Try to enable the secondary interface, if not already enabled
         */
-       if (cmd_hwif1->drives[0].noprobe && cmd_hwif1->drives[1].noprobe) {
+       if (cmd_hwif1 &&
+           cmd_hwif1->drives[0].noprobe && cmd_hwif1->drives[1].noprobe) {
                port2 = "not probed";
        } else {
                b = get_cmd640_reg(CNTRL);
@@ -801,7 +805,7 @@ static int __init cmd640x_init(void)
        /*
         * Initialize data for secondary cmd640 port, if enabled
         */
-       if (second_port_cmd640) {
+       if (second_port_cmd640 && cmd_hwif1) {
                ide_init_port_hw(cmd_hwif1, &hw[1]);
 #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED
                cmd_hwif1->set_pio_mode = &cmd640_set_pio_mode;
@@ -809,7 +813,7 @@ static int __init cmd640x_init(void)
 
                idx[1] = cmd_hwif1->index;
        }
-       printk(KERN_INFO "%s: %sserialized, secondary interface %s\n", cmd_hwif1->name,
+       printk(KERN_INFO "cmd640: %sserialized, secondary interface %s\n",
                         second_port_cmd640 ? "" : "not ", port2);
 
        /*
@@ -819,10 +823,15 @@ static int __init cmd640x_init(void)
        for (index = 0; index < (2 + (second_port_cmd640 << 1)); index++) {
                ide_drive_t *drive;
 
-               if (index > 1)
+               if (index > 1) {
+                       if (cmd_hwif1 == NULL)
+                               continue;
                        drive = &cmd_hwif1->drives[index & 1];
-               else
+               } else  {
+                       if (cmd_hwif0 == NULL)
+                               continue;
                        drive = &cmd_hwif0->drives[index & 1];
+               }
 
 #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED
                if (drive->autotune || ((index > 1) && second_port_toggled)) {