ata_piix: Fix checkpatch issues

While in here also:
- Switch to debug from custom PRINTF for debugging.
- Use mdelay rather than custom msleep.

Signed-off-by: Tom Rini <trini@ti.com>
This commit is contained in:
Tom Rini 2012-09-29 07:35:12 -07:00
parent e5f24753c9
commit 879a57ac0e
2 changed files with 232 additions and 267 deletions

View File

@ -63,13 +63,13 @@ extern int sata_curr_device;
#define PORT_ENABLED (1<<4) #define PORT_ENABLED (1<<4)
u32 bdf; u32 bdf;
u32 iobase1 = 0; /*Primary cmd block */ u32 iobase1; /* Primary cmd block */
u32 iobase2 = 0; /*Primary ctl block */ u32 iobase2; /* Primary ctl block */
u32 iobase3 = 0; /*Sec cmd block */ u32 iobase3; /* Sec cmd block */
u32 iobase4 = 0; /*sec ctl block */ u32 iobase4; /* sec ctl block */
u32 iobase5 = 0; /*BMDMA*/ u32 iobase5; /* BMDMA*/
int
pci_sata_init (void) int pci_sata_init(void)
{ {
u32 bus = PCI_SATA_BUS; u32 bus = PCI_SATA_BUS;
u32 dev = PCI_SATA_DEV; u32 dev = PCI_SATA_DEV;
@ -89,9 +89,10 @@ pci_sata_init (void)
if ((iobase1 == 0xFFFFFFFF) || (iobase2 == 0xFFFFFFFF) || if ((iobase1 == 0xFFFFFFFF) || (iobase2 == 0xFFFFFFFF) ||
(iobase3 == 0xFFFFFFFF) || (iobase4 == 0xFFFFFFFF) || (iobase3 == 0xFFFFFFFF) || (iobase4 == 0xFFFFFFFF) ||
(iobase5 == 0xFFFFFFFF)) { (iobase5 == 0xFFFFFFFF)) {
/* ERROR */
printf("error no base addr for SATA controller\n"); printf("error no base addr for SATA controller\n");
return 1; return 1;
/*ERROR*/} }
iobase1 &= 0xFFFFFFFE; iobase1 &= 0xFFFFFFFE;
iobase2 &= 0xFFFFFFFE; iobase2 &= 0xFFFFFFFE;
@ -102,17 +103,16 @@ pci_sata_init (void)
/* check for mode */ /* check for mode */
pci_read_config_byte(bdf, PCI_PMR, &pmr); pci_read_config_byte(bdf, PCI_PMR, &pmr);
if (pmr > 1) { if (pmr > 1) {
printf ("combined mode not supported\n"); puts("combined mode not supported\n");
return 1; return 1;
} }
pci_read_config_byte(bdf, PCI_PI, &pi); pci_read_config_byte(bdf, PCI_PI, &pi);
if ((pi & 0x05) != 0x05) { if ((pi & 0x05) != 0x05) {
printf ("Sata is in Legacy mode\n"); puts("Sata is in Legacy mode\n");
return 1; return 1;
} else { } else
printf ("sata is in Native mode\n"); puts("sata is in Native mode\n");
}
/* MASTER CFG AND IO CFG */ /* MASTER CFG AND IO CFG */
pci_read_config_word(bdf, PCI_COMMAND, &cmd); pci_read_config_word(bdf, PCI_COMMAND, &cmd);
@ -129,8 +129,7 @@ pci_sata_init (void)
return 0; return 0;
} }
int int sata_bus_probe(int port_no)
sata_bus_probe (int port_no)
{ {
int orig_mask, mask; int orig_mask, mask;
u16 pcs; u16 pcs;
@ -144,10 +143,9 @@ sata_bus_probe (int port_no)
return 1; return 1;
} }
int int init_sata(int dev)
init_sata (int dev)
{ {
static int done = 0; static int done;
u8 i, rv = 0; u8 i, rv = 0;
if (!done) if (!done)
@ -157,7 +155,7 @@ init_sata (int dev)
rv = pci_sata_init(); rv = pci_sata_init();
if (rv == 1) { if (rv == 1) {
printf ("pci initialization failed\n"); puts("pci initialization failed\n");
return 1; return 1;
} }
@ -182,13 +180,12 @@ init_sata (int dev)
printf("SATA#%d port is not present\n", i); printf("SATA#%d port is not present\n", i);
} else { } else {
printf("SATA#%d port is present\n", i); printf("SATA#%d port is present\n", i);
if (sata_bus_softreset (i)) { if (sata_bus_softreset(i))
port[i].port_state = 0; port[i].port_state = 0;
} else { else
port[i].port_state = 1; port[i].port_state = 1;
} }
} }
}
for (i = 0; i < CONFIG_SYS_SATA_MAXBUS; i++) { for (i = 0; i < CONFIG_SYS_SATA_MAXBUS; i++) {
u8 j, devno; u8 j, devno;
@ -210,33 +207,29 @@ init_sata (int dev)
return 0; return 0;
} }
static u8 __inline__ static inline u8 sata_inb(unsigned long ioaddr)
sata_inb (unsigned long ioaddr)
{ {
return inb(ioaddr); return inb(ioaddr);
} }
static void __inline__ static inline void sata_outb(unsigned char val, unsigned long ioaddr)
sata_outb (unsigned char val, unsigned long ioaddr)
{ {
outb(val, ioaddr); outb(val, ioaddr);
} }
static void static void output_data(struct sata_ioports *ioaddr, ulong * sect_buf,
output_data (struct sata_ioports *ioaddr, ulong * sect_buf, int words) int words)
{ {
outsw(ioaddr->data_addr, sect_buf, words << 1); outsw(ioaddr->data_addr, sect_buf, words << 1);
} }
static int static int input_data(struct sata_ioports *ioaddr, ulong * sect_buf, int words)
input_data (struct sata_ioports *ioaddr, ulong * sect_buf, int words)
{ {
insw(ioaddr->data_addr, sect_buf, words << 1); insw(ioaddr->data_addr, sect_buf, words << 1);
return 0; return 0;
} }
static void static void sata_cpy(unsigned char *dst, unsigned char *src, unsigned int len)
sata_cpy (unsigned char *dst, unsigned char *src, unsigned int len)
{ {
unsigned char *end, *last; unsigned char *end, *last;
@ -261,8 +254,7 @@ sata_cpy (unsigned char *dst, unsigned char *src, unsigned int len)
*last = '\0'; *last = '\0';
} }
int int sata_bus_softreset(int num)
sata_bus_softreset (int num)
{ {
u8 dev = 0, status = 0, i; u8 dev = 0, status = 0, i;
@ -270,10 +262,10 @@ sata_bus_softreset (int num)
for (i = 0; i < CONFIG_SYS_SATA_DEVS_PER_BUS; i++) { for (i = 0; i < CONFIG_SYS_SATA_DEVS_PER_BUS; i++) {
if (!(sata_devchk(&port[num].ioaddr, i))) { if (!(sata_devchk(&port[num].ioaddr, i))) {
PRINTF ("dev_chk failed for dev#%d\n", i); debug("dev_chk failed for dev#%d\n", i);
} else { } else {
port[num].dev_mask |= (1 << i); port[num].dev_mask |= (1 << i);
PRINTF ("dev_chk passed for dev#%d\n", i); debug("dev_chk passed for dev#%d\n", i);
} }
} }
@ -291,7 +283,8 @@ sata_bus_softreset (int num)
udelay(10); udelay(10);
sata_outb(port[num].ctl_reg, port[num].ioaddr.ctl_addr); sata_outb(port[num].ctl_reg, port[num].ioaddr.ctl_addr);
/* spec mandates ">= 2ms" before checking status. /*
* spec mandates ">= 2ms" before checking status.
* We wait 150ms, because that was the magic delay used for * We wait 150ms, because that was the magic delay used for
* ATAPI devices in Hale Landis's ATADRVR, for the period of time * ATAPI devices in Hale Landis's ATADRVR, for the period of time
* between when the ATA command register is written, and then * between when the ATA command register is written, and then
@ -299,10 +292,10 @@ sata_bus_softreset (int num)
* checking status is fine, post SRST, we perform this magic * checking status is fine, post SRST, we perform this magic
* delay here as well. * delay here as well.
*/ */
msleep (150); mdelay(150);
status = sata_busy_wait(&port[num].ioaddr, ATA_BUSY, 300); status = sata_busy_wait(&port[num].ioaddr, ATA_BUSY, 300);
while ((status & ATA_BUSY)) { while ((status & ATA_BUSY)) {
msleep (100); mdelay(100);
status = sata_busy_wait(&port[num].ioaddr, ATA_BUSY, 3); status = sata_busy_wait(&port[num].ioaddr, ATA_BUSY, 3);
} }
@ -310,22 +303,21 @@ sata_bus_softreset (int num)
printf("ata%u is slow to respond,plz be patient\n", num); printf("ata%u is slow to respond,plz be patient\n", num);
while ((status & ATA_BUSY)) { while ((status & ATA_BUSY)) {
msleep (100); mdelay(100);
status = sata_chk_status(&port[num].ioaddr); status = sata_chk_status(&port[num].ioaddr);
} }
if (status & ATA_BUSY) { if (status & ATA_BUSY) {
printf ("ata%u failed to respond : ", num); printf("ata%u failed to respond : bus reset failed\n", num);
printf ("bus reset failed\n");
return 1; return 1;
} }
return 0; return 0;
} }
void void sata_identify(int num, int dev)
sata_identify (int num, int dev)
{ {
u8 cmd = 0, status = 0, devno = num * CONFIG_SYS_SATA_DEVS_PER_BUS + dev; u8 cmd = 0, status = 0;
u8 devno = num * CONFIG_SYS_SATA_DEVS_PER_BUS + dev;
u16 iobuf[ATA_SECT_SIZE]; u16 iobuf[ATA_SECT_SIZE];
u64 n_sectors = 0; u64 n_sectors = 0;
u8 mask = 0; u8 mask = 0;
@ -355,31 +347,29 @@ sata_identify (int num, int dev)
status = sata_busy_wait(&port[num].ioaddr, ATA_BUSY, 1000); status = sata_busy_wait(&port[num].ioaddr, ATA_BUSY, 1000);
if (status & ATA_ERR) { if (status & ATA_ERR) {
printf ("\ndevice not responding\n"); puts("\ndevice not responding\n");
port[num].dev_mask &= ~mask; port[num].dev_mask &= ~mask;
return; return;
} }
input_data(&port[num].ioaddr, (ulong *) iobuf, ATA_SECTORWORDS); input_data(&port[num].ioaddr, (ulong *) iobuf, ATA_SECTORWORDS);
PRINTF ("\nata%u: dev %u cfg 49:%04x 82:%04x 83:%04x 84:%04x85:%04x" debug("\nata%u: dev %u cfg 49:%04x 82:%04x 83:%04x 84:%04x85:%04x"
"86:%04x" "87:%04x 88:%04x\n", num, dev, iobuf[49], "86:%04x" "87:%04x 88:%04x\n", num, dev, iobuf[49],
iobuf[82], iobuf[83], iobuf[84], iobuf[85], iobuf[86], iobuf[82], iobuf[83], iobuf[84], iobuf[85], iobuf[86],
iobuf[87], iobuf[88]); iobuf[87], iobuf[88]);
/* we require LBA and DMA support (bits 8 & 9 of word 49) */ /* we require LBA and DMA support (bits 8 & 9 of word 49) */
if (!ata_id_has_dma (iobuf) || !ata_id_has_lba (iobuf)) { if (!ata_id_has_dma(iobuf) || !ata_id_has_lba(iobuf))
PRINTF ("ata%u: no dma/lba\n", num); debug("ata%u: no dma/lba\n", num);
}
ata_dump_id(iobuf); ata_dump_id(iobuf);
if (ata_id_has_lba48 (iobuf)) { if (ata_id_has_lba48(iobuf))
n_sectors = ata_id_u64(iobuf, 100); n_sectors = ata_id_u64(iobuf, 100);
} else { else
n_sectors = ata_id_u32(iobuf, 60); n_sectors = ata_id_u32(iobuf, 60);
} debug("no. of sectors %u\n", ata_id_u64(iobuf, 100));
PRINTF ("no. of sectors %u\n", ata_id_u64 (iobuf, 100)); debug("no. of sectors %u\n", ata_id_u32(iobuf, 60));
PRINTF ("no. of sectors %u\n", ata_id_u32 (iobuf, 60));
if (n_sectors == 0) { if (n_sectors == 0) {
port[num].dev_mask &= ~mask; port[num].dev_mask &= ~mask;
@ -395,14 +385,13 @@ sata_identify (int num, int dev)
strswab(sata_dev_desc[devno].revision); strswab(sata_dev_desc[devno].revision);
strswab(sata_dev_desc[devno].vendor); strswab(sata_dev_desc[devno].vendor);
if ((iop->config & 0x0080) == 0x0080) { if ((iop->config & 0x0080) == 0x0080)
sata_dev_desc[devno].removable = 1; sata_dev_desc[devno].removable = 1;
} else { else
sata_dev_desc[devno].removable = 0; sata_dev_desc[devno].removable = 0;
}
sata_dev_desc[devno].lba = iop->lba_capacity; sata_dev_desc[devno].lba = iop->lba_capacity;
PRINTF ("lba=0x%x", sata_dev_desc[devno].lba); debug("lba=0x%x", sata_dev_desc[devno].lba);
#ifdef CONFIG_LBA48 #ifdef CONFIG_LBA48
if (iop->command_set_2 & 0x0400) { if (iop->command_set_2 & 0x0400) {
@ -422,8 +411,7 @@ sata_identify (int num, int dev)
sata_dev_desc[devno].lun = 0; /* just to fill something in... */ sata_dev_desc[devno].lun = 0; /* just to fill something in... */
} }
void void set_Feature_cmd(int num, int dev)
set_Feature_cmd (int num, int dev)
{ {
u8 mask = 0x00, status = 0; u8 mask = 0x00, status = 0;
@ -433,7 +421,7 @@ set_Feature_cmd (int num, int dev)
mask = 0x02; mask = 0x02;
if (!(port[num].dev_mask & mask)) { if (!(port[num].dev_mask & mask)) {
PRINTF ("dev%d is not present on port#%d\n", dev, num); debug("dev%d is not present on port#%d\n", dev, num);
return; return;
} }
@ -449,7 +437,7 @@ set_Feature_cmd (int num, int dev)
sata_outb(ATA_CMD_SETF, port[num].ioaddr.command_addr); sata_outb(ATA_CMD_SETF, port[num].ioaddr.command_addr);
udelay(50); udelay(50);
msleep (150); mdelay(150);
status = sata_busy_wait(&port[num].ioaddr, ATA_BUSY, 5000); status = sata_busy_wait(&port[num].ioaddr, ATA_BUSY, 5000);
if ((status & (ATA_STAT_BUSY | ATA_STAT_ERR))) { if ((status & (ATA_STAT_BUSY | ATA_STAT_ERR))) {
@ -458,8 +446,7 @@ set_Feature_cmd (int num, int dev)
} }
} }
void void sata_port(struct sata_ioports *ioport)
sata_port (struct sata_ioports *ioport)
{ {
ioport->data_addr = ioport->cmd_addr + ATA_REG_DATA; ioport->data_addr = ioport->cmd_addr + ATA_REG_DATA;
ioport->error_addr = ioport->cmd_addr + ATA_REG_ERR; ioport->error_addr = ioport->cmd_addr + ATA_REG_ERR;
@ -473,8 +460,7 @@ sata_port (struct sata_ioports *ioport)
ioport->command_addr = ioport->cmd_addr + ATA_REG_CMD; ioport->command_addr = ioport->cmd_addr + ATA_REG_CMD;
} }
int int sata_devchk(struct sata_ioports *ioaddr, int dev)
sata_devchk (struct sata_ioports *ioaddr, int dev)
{ {
u8 nsect, lbal; u8 nsect, lbal;
@ -498,8 +484,7 @@ sata_devchk (struct sata_ioports *ioaddr, int dev)
return 0; /* nothing found */ return 0; /* nothing found */
} }
void void dev_select(struct sata_ioports *ioaddr, int dev)
dev_select (struct sata_ioports *ioaddr, int dev)
{ {
u8 tmp = 0; u8 tmp = 0;
@ -513,8 +498,7 @@ dev_select (struct sata_ioports *ioaddr, int dev)
udelay(5); udelay(5);
} }
u8 u8 sata_busy_wait(struct sata_ioports *ioaddr, int bits, unsigned int max)
sata_busy_wait (struct sata_ioports *ioaddr, int bits, unsigned int max)
{ {
u8 status; u8 status;
@ -527,23 +511,13 @@ sata_busy_wait (struct sata_ioports *ioaddr, int bits, unsigned int max)
return status; return status;
} }
u8 u8 sata_chk_status(struct sata_ioports *ioaddr)
sata_chk_status (struct sata_ioports * ioaddr)
{ {
return sata_inb(ioaddr->status_addr); return sata_inb(ioaddr->status_addr);
} }
void
msleep (int count)
{
int i;
for (i = 0; i < count; i++) ulong sata_read(int device, ulong blknr, lbaint_t blkcnt, void *buff)
udelay (1000);
}
ulong
sata_read (int device, ulong blknr,lbaint_t blkcnt, void * buff)
{ {
ulong n = 0, *buffer = (ulong *)buff; ulong n = 0, *buffer = (ulong *)buff;
u8 dev = 0, num = 0, mask = 0, status = 0; u8 dev = 0, num = 0, mask = 0, status = 0;
@ -624,7 +598,7 @@ sata_read (int device, ulong blknr,lbaint_t blkcnt, void * buff)
port[num].ioaddr.command_addr); port[num].ioaddr.command_addr);
} }
msleep (50); mdelay(50);
/* may take up to 4 sec */ /* may take up to 4 sec */
status = sata_busy_wait(&port[num].ioaddr, ATA_BUSY, 4000); status = sata_busy_wait(&port[num].ioaddr, ATA_BUSY, 4000);
@ -636,7 +610,7 @@ sata_read (int device, ulong blknr,lbaint_t blkcnt, void * buff)
device, (ulong) blknr, status); device, (ulong) blknr, status);
err = sata_inb(port[num].ioaddr.error_addr); err = sata_inb(port[num].ioaddr.error_addr);
printf("Error reg = 0x%x\n", err); printf("Error reg = 0x%x\n", err);
return (n); return n;
} }
input_data(&port[num].ioaddr, buffer, ATA_SECTORWORDS); input_data(&port[num].ioaddr, buffer, ATA_SECTORWORDS);
sata_inb(port[num].ioaddr.altstatus_addr); sata_inb(port[num].ioaddr.altstatus_addr);
@ -649,8 +623,7 @@ sata_read (int device, ulong blknr,lbaint_t blkcnt, void * buff)
return n; return n;
} }
ulong ulong sata_write(int device, ulong blknr, lbaint_t blkcnt, void *buff)
sata_write (int device, ulong blknr,lbaint_t blkcnt, void * buff)
{ {
ulong n = 0, *buffer = (ulong *)buff; ulong n = 0, *buffer = (ulong *)buff;
unsigned char status = 0, num = 0, dev = 0, mask = 0; unsigned char status = 0, num = 0, dev = 0, mask = 0;
@ -726,14 +699,14 @@ sata_write (int device, ulong blknr,lbaint_t blkcnt, void * buff)
port[num].ioaddr.command_addr); port[num].ioaddr.command_addr);
} }
msleep (50); mdelay(50);
/* may take up to 4 sec */ /* may take up to 4 sec */
status = sata_busy_wait(&port[num].ioaddr, ATA_BUSY, 4000); status = sata_busy_wait(&port[num].ioaddr, ATA_BUSY, 4000);
if ((status & (ATA_STAT_DRQ | ATA_STAT_BUSY | ATA_STAT_ERR)) if ((status & (ATA_STAT_DRQ | ATA_STAT_BUSY | ATA_STAT_ERR))
!= ATA_STAT_DRQ) { != ATA_STAT_DRQ) {
printf("Error no DRQ dev %d blk %ld: sts 0x%02x\n", printf("Error no DRQ dev %d blk %ld: sts 0x%02x\n",
device, (ulong) blknr, status); device, (ulong) blknr, status);
return (n); return n;
} }
output_data(&port[num].ioaddr, buffer, ATA_SECTORWORDS); output_data(&port[num].ioaddr, buffer, ATA_SECTORWORDS);

View File

@ -1,12 +1,6 @@
#ifndef __ATA_PIIX_H__ #ifndef __ATA_PIIX_H__
#define __ATA_PIIX_H__ #define __ATA_PIIX_H__
#if (DEBUG_SATA)
#define PRINTF(fmt,args...) printf (fmt ,##args)
#else
#define PRINTF(fmt,args...)
#endif
struct sata_ioports { struct sata_ioports {
unsigned long cmd_addr; unsigned long cmd_addr;
unsigned long data_addr; unsigned long data_addr;
@ -37,20 +31,19 @@ struct sata_port {
/***********SATA LIBRARY SPECIFIC DEFINITIONS AND DECLARATIONS**************/ /***********SATA LIBRARY SPECIFIC DEFINITIONS AND DECLARATIONS**************/
#ifdef SATA_DECL /* SATA library specific declarations */ #ifdef SATA_DECL /* SATA library specific declarations */
inline void inline void ata_dump_id(u16 *id)
ata_dump_id (u16 * id)
{ {
PRINTF ("49 = 0x%04x " debug("49 = 0x%04x "
"53 = 0x%04x " "53 = 0x%04x "
"63 = 0x%04x " "63 = 0x%04x "
"64 = 0x%04x " "64 = 0x%04x "
"75 = 0x%04x\n", id[49], id[53], id[63], id[64], id[75]); "75 = 0x%04x\n", id[49], id[53], id[63], id[64], id[75]);
PRINTF ("80 = 0x%04x " debug("80 = 0x%04x "
"81 = 0x%04x " "81 = 0x%04x "
"82 = 0x%04x " "82 = 0x%04x "
"83 = 0x%04x " "83 = 0x%04x "
"84 = 0x%04x\n", id[80], id[81], id[82], id[83], id[84]); "84 = 0x%04x\n", id[80], id[81], id[82], id[83], id[84]);
PRINTF ("88 = 0x%04x " "93 = 0x%04x\n", id[88], id[93]); debug("88 = 0x%04x " "93 = 0x%04x\n", id[88], id[93]);
} }
#endif #endif
@ -65,7 +58,6 @@ u8 sata_busy_wait (struct sata_ioports *ioaddr, int bits, unsigned int max);
u8 sata_chk_status(struct sata_ioports *ioaddr); u8 sata_chk_status(struct sata_ioports *ioaddr);
ulong sata_read(int device, ulong blknr,lbaint_t blkcnt, void *buffer); ulong sata_read(int device, ulong blknr,lbaint_t blkcnt, void *buffer);
ulong sata_write(int device,ulong blknr, lbaint_t blkcnt, void *buffer); ulong sata_write(int device,ulong blknr, lbaint_t blkcnt, void *buffer);
void msleep (int count);
#endif #endif
/************DRIVER SPECIFIC DEFINITIONS AND DECLARATIONS**************/ /************DRIVER SPECIFIC DEFINITIONS AND DECLARATIONS**************/