[ALSA] intel8x0 - Use pci_iomap

Use pci_iomap and ioread*/iowrite*() functions for accessing
hardwares.  pci_iomap is suitable for hardwares like ICH and
compatible that have both PIO and MMIO.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@suse.cz>
This commit is contained in:
Takashi Iwai 2006-10-06 17:06:39 +02:00 коммит произвёл Jaroslav Kysela
Родитель c7132aeb72
Коммит 3388c37e04
2 изменённых файлов: 82 добавлений и 154 удалений

Просмотреть файл

@ -368,12 +368,8 @@ struct intel8x0 {
int irq; int irq;
unsigned int mmio; void __iomem *addr;
unsigned long addr; void __iomem *bmaddr;
void __iomem *remap_addr;
unsigned int bm_mmio;
unsigned long bmaddr;
void __iomem *remap_bmaddr;
struct pci_dev *pci; struct pci_dev *pci;
struct snd_card *card; struct snd_card *card;
@ -446,72 +442,48 @@ MODULE_DEVICE_TABLE(pci, snd_intel8x0_ids);
* Lowlevel I/O - busmaster * Lowlevel I/O - busmaster
*/ */
static u8 igetbyte(struct intel8x0 *chip, u32 offset) static inline u8 igetbyte(struct intel8x0 *chip, u32 offset)
{ {
if (chip->bm_mmio) return ioread8(chip->bmaddr + offset);
return readb(chip->remap_bmaddr + offset);
else
return inb(chip->bmaddr + offset);
} }
static u16 igetword(struct intel8x0 *chip, u32 offset) static inline u16 igetword(struct intel8x0 *chip, u32 offset)
{ {
if (chip->bm_mmio) return ioread16(chip->bmaddr + offset);
return readw(chip->remap_bmaddr + offset);
else
return inw(chip->bmaddr + offset);
} }
static u32 igetdword(struct intel8x0 *chip, u32 offset) static inline u32 igetdword(struct intel8x0 *chip, u32 offset)
{ {
if (chip->bm_mmio) return ioread32(chip->bmaddr + offset);
return readl(chip->remap_bmaddr + offset);
else
return inl(chip->bmaddr + offset);
} }
static void iputbyte(struct intel8x0 *chip, u32 offset, u8 val) static inline void iputbyte(struct intel8x0 *chip, u32 offset, u8 val)
{ {
if (chip->bm_mmio) iowrite8(val, chip->bmaddr + offset);
writeb(val, chip->remap_bmaddr + offset);
else
outb(val, chip->bmaddr + offset);
} }
static void iputword(struct intel8x0 *chip, u32 offset, u16 val) static inline void iputword(struct intel8x0 *chip, u32 offset, u16 val)
{ {
if (chip->bm_mmio) iowrite16(val, chip->bmaddr + offset);
writew(val, chip->remap_bmaddr + offset);
else
outw(val, chip->bmaddr + offset);
} }
static void iputdword(struct intel8x0 *chip, u32 offset, u32 val) static inline void iputdword(struct intel8x0 *chip, u32 offset, u32 val)
{ {
if (chip->bm_mmio) iowrite32(val, chip->bmaddr + offset);
writel(val, chip->remap_bmaddr + offset);
else
outl(val, chip->bmaddr + offset);
} }
/* /*
* Lowlevel I/O - AC'97 registers * Lowlevel I/O - AC'97 registers
*/ */
static u16 iagetword(struct intel8x0 *chip, u32 offset) static inline u16 iagetword(struct intel8x0 *chip, u32 offset)
{ {
if (chip->mmio) return ioread16(chip->addr + offset);
return readw(chip->remap_addr + offset);
else
return inw(chip->addr + offset);
} }
static void iaputword(struct intel8x0 *chip, u32 offset, u16 val) static inline void iaputword(struct intel8x0 *chip, u32 offset, u16 val)
{ {
if (chip->mmio) iowrite16(val, chip->addr + offset);
writew(val, chip->remap_addr + offset);
else
outw(val, chip->addr + offset);
} }
/* /*
@ -2443,10 +2415,10 @@ static int snd_intel8x0_free(struct intel8x0 *chip)
fill_nocache(chip->bdbars.area, chip->bdbars.bytes, 0); fill_nocache(chip->bdbars.area, chip->bdbars.bytes, 0);
snd_dma_free_pages(&chip->bdbars); snd_dma_free_pages(&chip->bdbars);
} }
if (chip->remap_addr) if (chip->addr)
iounmap(chip->remap_addr); pci_iounmap(chip->pci, chip->addr);
if (chip->remap_bmaddr) if (chip->bmaddr)
iounmap(chip->remap_bmaddr); pci_iounmap(chip->pci, chip->bmaddr);
pci_release_regions(chip->pci); pci_release_regions(chip->pci);
pci_disable_device(chip->pci); pci_disable_device(chip->pci);
kfree(chip); kfree(chip);
@ -2793,35 +2765,27 @@ static int __devinit snd_intel8x0_create(struct snd_card *card,
if (device_type == DEVICE_ALI) { if (device_type == DEVICE_ALI) {
/* ALI5455 has no ac97 region */ /* ALI5455 has no ac97 region */
chip->bmaddr = pci_resource_start(pci, 0); chip->bmaddr = pci_iomap(pci, 0, 0);
goto port_inited; goto port_inited;
} }
if (pci_resource_flags(pci, 2) & IORESOURCE_MEM) { /* ICH4 and Nforce */ if (pci_resource_flags(pci, 2) & IORESOURCE_MEM) /* ICH4 and Nforce */
chip->mmio = 1; chip->addr = pci_iomap(pci, 2, 0);
chip->addr = pci_resource_start(pci, 2); else
chip->remap_addr = ioremap_nocache(chip->addr, chip->addr = pci_iomap(pci, 0, 0);
pci_resource_len(pci, 2)); if (!chip->addr) {
if (chip->remap_addr == NULL) { snd_printk(KERN_ERR "AC'97 space ioremap problem\n");
snd_printk(KERN_ERR "AC'97 space ioremap problem\n"); snd_intel8x0_free(chip);
snd_intel8x0_free(chip); return -EIO;
return -EIO;
}
} else {
chip->addr = pci_resource_start(pci, 0);
} }
if (pci_resource_flags(pci, 3) & IORESOURCE_MEM) { /* ICH4 */ if (pci_resource_flags(pci, 3) & IORESOURCE_MEM) /* ICH4 */
chip->bm_mmio = 1; chip->bmaddr = pci_iomap(pci, 3, 0);
chip->bmaddr = pci_resource_start(pci, 3); else
chip->remap_bmaddr = ioremap_nocache(chip->bmaddr, chip->bmaddr = pci_iomap(pci, 1, 0);
pci_resource_len(pci, 3)); if (!chip->bmaddr) {
if (chip->remap_bmaddr == NULL) { snd_printk(KERN_ERR "Controller space ioremap problem\n");
snd_printk(KERN_ERR "Controller space ioremap problem\n"); snd_intel8x0_free(chip);
snd_intel8x0_free(chip); return -EIO;
return -EIO;
}
} else {
chip->bmaddr = pci_resource_start(pci, 1);
} }
port_inited: port_inited:
@ -3025,8 +2989,8 @@ static int __devinit snd_intel8x0_probe(struct pci_dev *pci,
snd_intel8x0_proc_init(chip); snd_intel8x0_proc_init(chip);
snprintf(card->longname, sizeof(card->longname), snprintf(card->longname, sizeof(card->longname),
"%s with %s at %#lx, irq %i", card->shortname, "%s with %s at irq %i", card->shortname,
snd_ac97_get_short_name(chip->ac97[0]), chip->addr, chip->irq); snd_ac97_get_short_name(chip->ac97[0]), chip->irq);
if (! ac97_clock) if (! ac97_clock)
intel8x0_measure_ac97_clock(chip); intel8x0_measure_ac97_clock(chip);

Просмотреть файл

@ -196,12 +196,8 @@ struct intel8x0m {
int irq; int irq;
unsigned int mmio; void __iomem *addr;
unsigned long addr; void __iomem *bmaddr;
void __iomem *remap_addr;
unsigned int bm_mmio;
unsigned long bmaddr;
void __iomem *remap_bmaddr;
struct pci_dev *pci; struct pci_dev *pci;
struct snd_card *card; struct snd_card *card;
@ -253,72 +249,48 @@ MODULE_DEVICE_TABLE(pci, snd_intel8x0m_ids);
* Lowlevel I/O - busmaster * Lowlevel I/O - busmaster
*/ */
static u8 igetbyte(struct intel8x0m *chip, u32 offset) static inline u8 igetbyte(struct intel8x0m *chip, u32 offset)
{ {
if (chip->bm_mmio) return ioread8(chip->bmaddr + offset);
return readb(chip->remap_bmaddr + offset);
else
return inb(chip->bmaddr + offset);
} }
static u16 igetword(struct intel8x0m *chip, u32 offset) static inline u16 igetword(struct intel8x0m *chip, u32 offset)
{ {
if (chip->bm_mmio) return ioread16(chip->bmaddr + offset);
return readw(chip->remap_bmaddr + offset);
else
return inw(chip->bmaddr + offset);
} }
static u32 igetdword(struct intel8x0m *chip, u32 offset) static inline u32 igetdword(struct intel8x0m *chip, u32 offset)
{ {
if (chip->bm_mmio) return ioread32(chip->bmaddr + offset);
return readl(chip->remap_bmaddr + offset);
else
return inl(chip->bmaddr + offset);
} }
static void iputbyte(struct intel8x0m *chip, u32 offset, u8 val) static inline void iputbyte(struct intel8x0m *chip, u32 offset, u8 val)
{ {
if (chip->bm_mmio) iowrite8(val, chip->bmaddr + offset);
writeb(val, chip->remap_bmaddr + offset);
else
outb(val, chip->bmaddr + offset);
} }
static void iputword(struct intel8x0m *chip, u32 offset, u16 val) static inline void iputword(struct intel8x0m *chip, u32 offset, u16 val)
{ {
if (chip->bm_mmio) iowrite16(val, chip->bmaddr + offset);
writew(val, chip->remap_bmaddr + offset);
else
outw(val, chip->bmaddr + offset);
} }
static void iputdword(struct intel8x0m *chip, u32 offset, u32 val) static inline void iputdword(struct intel8x0m *chip, u32 offset, u32 val)
{ {
if (chip->bm_mmio) iowrite32(val, chip->bmaddr + offset);
writel(val, chip->remap_bmaddr + offset);
else
outl(val, chip->bmaddr + offset);
} }
/* /*
* Lowlevel I/O - AC'97 registers * Lowlevel I/O - AC'97 registers
*/ */
static u16 iagetword(struct intel8x0m *chip, u32 offset) static inline u16 iagetword(struct intel8x0m *chip, u32 offset)
{ {
if (chip->mmio) return ioread16(chip->addr + offset);
return readw(chip->remap_addr + offset);
else
return inw(chip->addr + offset);
} }
static void iaputword(struct intel8x0m *chip, u32 offset, u16 val) static inline void iaputword(struct intel8x0m *chip, u32 offset, u16 val)
{ {
if (chip->mmio) iowrite16(val, chip->addr + offset);
writew(val, chip->remap_addr + offset);
else
outw(val, chip->addr + offset);
} }
/* /*
@ -1019,10 +991,10 @@ static int snd_intel8x0_free(struct intel8x0m *chip)
__hw_end: __hw_end:
if (chip->bdbars.area) if (chip->bdbars.area)
snd_dma_free_pages(&chip->bdbars); snd_dma_free_pages(&chip->bdbars);
if (chip->remap_addr) if (chip->addr)
iounmap(chip->remap_addr); pci_iounmap(chip->pci, chip->addr);
if (chip->remap_bmaddr) if (chip->bmaddr)
iounmap(chip->remap_bmaddr); pci_iounmap(chip->pci, chip->bmaddr);
if (chip->irq >= 0) if (chip->irq >= 0)
free_irq(chip->irq, chip); free_irq(chip->irq, chip);
pci_release_regions(chip->pci); pci_release_regions(chip->pci);
@ -1173,35 +1145,27 @@ static int __devinit snd_intel8x0m_create(struct snd_card *card,
if (device_type == DEVICE_ALI) { if (device_type == DEVICE_ALI) {
/* ALI5455 has no ac97 region */ /* ALI5455 has no ac97 region */
chip->bmaddr = pci_resource_start(pci, 0); chip->bmaddr = pci_iomap(pci, 0, 0);
goto port_inited; goto port_inited;
} }
if (pci_resource_flags(pci, 2) & IORESOURCE_MEM) { /* ICH4 and Nforce */ if (pci_resource_flags(pci, 2) & IORESOURCE_MEM) /* ICH4 and Nforce */
chip->mmio = 1; chip->addr = pci_iomap(pci, 2, 0);
chip->addr = pci_resource_start(pci, 2); else
chip->remap_addr = ioremap_nocache(chip->addr, chip->addr = pci_iomap(pci, 0, 0);
pci_resource_len(pci, 2)); if (!chip->addr) {
if (chip->remap_addr == NULL) { snd_printk(KERN_ERR "AC'97 space ioremap problem\n");
snd_printk(KERN_ERR "AC'97 space ioremap problem\n"); snd_intel8x0_free(chip);
snd_intel8x0_free(chip); return -EIO;
return -EIO;
}
} else {
chip->addr = pci_resource_start(pci, 0);
} }
if (pci_resource_flags(pci, 3) & IORESOURCE_MEM) { /* ICH4 */ if (pci_resource_flags(pci, 3) & IORESOURCE_MEM) /* ICH4 */
chip->bm_mmio = 1; chip->bmaddr = pci_iomap(pci, 3, 0);
chip->bmaddr = pci_resource_start(pci, 3); else
chip->remap_bmaddr = ioremap_nocache(chip->bmaddr, chip->bmaddr = pci_iomap(pci, 1, 0);
pci_resource_len(pci, 3)); if (!chip->bmaddr) {
if (chip->remap_bmaddr == NULL) { snd_printk(KERN_ERR "Controller space ioremap problem\n");
snd_printk(KERN_ERR "Controller space ioremap problem\n"); snd_intel8x0_free(chip);
snd_intel8x0_free(chip); return -EIO;
return -EIO;
}
} else {
chip->bmaddr = pci_resource_start(pci, 1);
} }
port_inited: port_inited:
@ -1339,8 +1303,8 @@ static int __devinit snd_intel8x0m_probe(struct pci_dev *pci,
snd_intel8x0m_proc_init(chip); snd_intel8x0m_proc_init(chip);
sprintf(card->longname, "%s at 0x%lx, irq %i", sprintf(card->longname, "%s at irq %i",
card->shortname, chip->addr, chip->irq); card->shortname, chip->irq);
if ((err = snd_card_register(card)) < 0) { if ((err = snd_card_register(card)) < 0) {
snd_card_free(card); snd_card_free(card);