#include <linux/module.h>
#include <linux/platform_device.h>
#include <asm/txx9/tx4938.h>
static void tx4938ide_tune_ebusc(unsigned int ebus_ch,
struct ide_timing *t = ide_timing_find_mode(XFER_PIO_0 + pio);
u64 cr = __raw_readq(&tx4938_ebuscptr->cr[ebus_ch]);
unsigned int sp = (cr >> 4) & 3;
unsigned int clock = gbus_clock / (4 - sp);
unsigned int cycle = 1000000000 / clock;
wt = DIV_ROUND_UP(t->act8b, cycle) - 2;
wt = max_t(int, wt, DIV_ROUND_UP(35, cycle));
shwt = DIV_ROUND_UP(t->setup, cycle);
while ((shwt * 4 + wt + (wt ? 2 : 3)) * cycle < t->cycle)
pr_warning("tx4938ide: SHWT violation (%d)\n", shwt);
pr_debug("tx4938ide: ebus %d, bus cycle %dns, WT %d, SHWT %d\n",
ebus_ch, cycle, wt, shwt);
__raw_writeq((cr & ~0x3f007ull) | (wt << 12) | shwt,
&tx4938_ebuscptr->cr[ebus_ch]);
static void tx4938ide_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive)
struct tx4938ide_platform_info *pdata = dev_get_platdata(hwif->dev);
u8 safe = drive->pio_mode - XFER_PIO_0;
pair = ide_get_pair_dev(drive);
safe = min_t(u8, safe, pair->pio_mode - XFER_PIO_0);
tx4938ide_tune_ebusc(pdata->ebus_ch, pdata->gbus_clock, safe);
static void tx4938ide_input_data_swap(ide_drive_t *drive, struct ide_cmd *cmd,
void *buf, unsigned int len)
unsigned long port = drive->hwif->io_ports.data_addr;
unsigned short *ptr = buf;
unsigned int count = (len + 1) / 2;
*ptr++ = cpu_to_le16(__raw_readw((void __iomem *)port));
__ide_flush_dcache_range((unsigned long)buf, roundup(len, 2));
static void tx4938ide_output_data_swap(ide_drive_t *drive, struct ide_cmd *cmd,
void *buf, unsigned int len)
unsigned long port = drive->hwif->io_ports.data_addr;
unsigned short *ptr = buf;
unsigned int count = (len + 1) / 2;