/* Convert a PIO mode and cycle time to the required on/off times for the interface. This has protection against runaway timings.  */
static unsigned int get_pio_timings(ide_drive_t *drive, u8 pio)
/* Convert a PIO mode and cycle time to the required on/off times for the interface. This has protection against runaway timings.  */
static unsigned int get_pio_timings(ide_drive_t *drive, u8 pio)
{
	struct ide_timing *t = ide_timing_find_mode(XFER_PIO_0 + pio);
	unsigned int cmd_on, cmd_off;
	u8 iordy = 0;
	cmd_on  = (t->active + 29) / 30;
	cmd_off = (ide_pio_cycle_time(drive, pio) - 30 * cmd_on + 29) / 30;
	if (cmd_on == 0)
		cmd_on = 1;
	if (cmd_off == 0)
		cmd_off = 1;
	if (ide_pio_need_iordy(drive, pio))
		iordy = 0x40;
	return (cmd_on - 1) << 8 | (cmd_off - 1) | iordy;
}