diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/ata/ide-sff.c | 98 | ||||
-rw-r--r-- | drivers/ata/intf_platform_ide.c | 37 | ||||
-rw-r--r-- | drivers/base/driver.c | 16 | ||||
-rw-r--r-- | drivers/gpio/gpio-generic.c | 4 | ||||
-rw-r--r-- | drivers/mfd/syscon.c | 2 | ||||
-rw-r--r-- | drivers/misc/sram.c | 2 | ||||
-rw-r--r-- | drivers/serial/serial_ns16550.c | 123 |
7 files changed, 234 insertions, 48 deletions
diff --git a/drivers/ata/ide-sff.c b/drivers/ata/ide-sff.c index 3d5932e278..a8f2b26c55 100644 --- a/drivers/ata/ide-sff.c +++ b/drivers/ata/ide-sff.c @@ -15,13 +15,74 @@ #define DISK_SLAVE 1 /** + * Read a byte from the ATA controller + * @param ide IDE port structure + * @param addr Register adress + * @return Register's content + */ +static inline uint8_t ata_rd_byte(struct ide_port *ide, void __iomem *addr) +{ + if (ide->io.mmio) + return readb(addr); + else + return (uint8_t) inb((int) addr); +} + +/** + * Write a byte to the ATA controller + * @param ide IDE port structure + * @param value Value to write + * @param addr Register adress + * @return Register's content + */ +static inline void ata_wr_byte(struct ide_port *ide, uint8_t value, + void __iomem *addr) +{ + if (ide->io.mmio) + writeb(value, addr); + else + outb(value, (int) addr); +} + +/** + * Read a word from the ATA controller + * @param ide IDE port structure + * @param addr Register adress + * @return Register's content + */ +static inline uint16_t ata_rd_word(struct ide_port *ide, + void __iomem *addr) +{ + if (ide->io.mmio) + return readw(addr); + else + return (uint16_t) inw((int) addr); +} + +/** + * Write a word to the ATA controller + * @param ide IDE port structure + * @param value Value to write + * @param addr Register adress + * @return Register's content + */ +static inline void ata_wr_word(struct ide_port *ide, uint16_t value, + void __iomem *addr) +{ + if (ide->io.mmio) + writew(value, addr); + else + outw(value, (int) addr); +} + +/** * Read the status register of the ATA drive * @param io Register file * @return Register's content */ static uint8_t ata_rd_status(struct ide_port *ide) { - return readb(ide->io.status_addr); + return ata_rd_byte(ide, ide->io.status_addr); } /** @@ -83,12 +144,13 @@ static int ata_set_lba_sector(struct ide_port *ide, unsigned drive, uint64_t num if (num > 0x0FFFFFFF || drive > 1) return -EINVAL; - writeb(0xA0 | LBA_FLAG | drive << 4 | num >> 24, ide->io.device_addr); - writeb(0x00, ide->io.error_addr); - writeb(0x01, ide->io.nsect_addr); - writeb(num, ide->io.lbal_addr); /* 0 ... 7 */ - writeb(num >> 8, ide->io.lbam_addr); /* 8 ... 15 */ - writeb(num >> 16, ide->io.lbah_addr); /* 16 ... 23 */ + ata_wr_byte(ide, 0xA0 | LBA_FLAG | drive << 4 | num >> 24, + ide->io.device_addr); + ata_wr_byte(ide, 0x00, ide->io.error_addr); + ata_wr_byte(ide, 0x01, ide->io.nsect_addr); + ata_wr_byte(ide, num, ide->io.lbal_addr); /* 0 ... 7 */ + ata_wr_byte(ide, num >> 8, ide->io.lbam_addr); /* 8 ... 15 */ + ata_wr_byte(ide, num >> 16, ide->io.lbah_addr); /* 16 ... 23 */ return 0; } @@ -107,7 +169,7 @@ static int ata_wr_cmd(struct ide_port *ide, uint8_t cmd) if (rc != 0) return rc; - writeb(cmd, ide->io.command_addr); + ata_wr_byte(ide, cmd, ide->io.command_addr); return 0; } @@ -118,7 +180,7 @@ static int ata_wr_cmd(struct ide_port *ide, uint8_t cmd) */ static void ata_wr_dev_ctrl(struct ide_port *ide, uint8_t val) { - writeb(val, ide->io.ctl_addr); + ata_wr_byte(ide, val, ide->io.ctl_addr); } /** @@ -133,10 +195,10 @@ static void ata_rd_sector(struct ide_port *ide, void *buf) if (ide->io.dataif_be) { for (; u > 0; u--) - *b++ = be16_to_cpu(readw(ide->io.data_addr)); + *b++ = be16_to_cpu(ata_rd_word(ide, ide->io.data_addr)); } else { for (; u > 0; u--) - *b++ = le16_to_cpu(readw(ide->io.data_addr)); + *b++ = le16_to_cpu(ata_rd_word(ide, ide->io.data_addr)); } } @@ -152,10 +214,10 @@ static void ata_wr_sector(struct ide_port *ide, const void *buf) if (ide->io.dataif_be) { for (; u > 0; u--) - writew(cpu_to_be16(*b++), ide->io.data_addr); + ata_wr_word(ide, cpu_to_be16(*b++), ide->io.data_addr); } else { for (; u > 0; u--) - writew(cpu_to_le16(*b++), ide->io.data_addr); + ata_wr_word(ide, cpu_to_le16(*b++), ide->io.data_addr); } } @@ -169,10 +231,10 @@ static int ide_read_id(struct ata_port *port, void *buf) struct ide_port *ide = to_ata_drive_access(port); int rc; - writeb(0xA0, ide->io.device_addr); /* FIXME drive */ - writeb(0x00, ide->io.lbal_addr); - writeb(0x00, ide->io.lbam_addr); - writeb(0x00, ide->io.lbah_addr); + ata_wr_byte(ide, 0xA0, ide->io.device_addr); /* FIXME drive */ + ata_wr_byte(ide, 0x00, ide->io.lbal_addr); + ata_wr_byte(ide, 0x00, ide->io.lbam_addr); + ata_wr_byte(ide, 0x00, ide->io.lbah_addr); rc = ata_wr_cmd(ide, ATA_CMD_ID_ATA); if (rc != 0) @@ -327,6 +389,8 @@ int ide_port_register(struct ide_port *ide) ide->port.ops = &ide_ops; ret = ata_port_register(&ide->port); + if (!ret) + ata_port_detect(&ide->port); if (ret) free(ide); diff --git a/drivers/ata/intf_platform_ide.c b/drivers/ata/intf_platform_ide.c index 8ae0f054c3..ecc2546d84 100644 --- a/drivers/ata/intf_platform_ide.c +++ b/drivers/ata/intf_platform_ide.c @@ -82,15 +82,46 @@ static int platform_ide_probe(struct device_d *dev) struct ide_port_info *pdata = dev->platform_data; struct ide_port *ide; void *reg_base, *alt_base; + struct resource *reg, *alt; + int mmio; if (pdata == NULL) { dev_err(dev, "No platform data. Cannot continue\n"); return -EINVAL; } + alt = NULL; + reg = dev_get_resource(dev, IORESOURCE_MEM, 0); + mmio = (reg != NULL); + if (reg != NULL) { + reg = request_iomem_region(dev_name(dev), reg->start, + reg->end); + alt = dev_get_resource(dev, IORESOURCE_MEM, 1); + if (alt != NULL) + alt = request_iomem_region(dev_name(dev), alt->start, + alt->end); + } else { + reg = dev_get_resource(dev, IORESOURCE_IO, 0); + if (reg != NULL) { + reg = request_ioport_region(dev_name(dev), reg->start, + reg->end); + alt = dev_get_resource(dev, IORESOURCE_IO, 1); + if (alt != NULL) + alt = request_ioport_region(dev_name(dev), + alt->start, + alt->end); + } + } + + reg_base = (reg != NULL ? (void __force __iomem *) reg->start : NULL); + alt_base = (alt != NULL ? (void __force __iomem *) alt->start : NULL); + + if (!reg_base) + return -ENODEV; + ide = xzalloc(sizeof(*ide)); - reg_base = dev_request_mem_region(dev, 0); - alt_base = dev_request_mem_region(dev, 1); + ide->io.mmio = mmio; + platform_ide_setup_port(reg_base, alt_base, &ide->io, pdata->ioport_shift); ide->io.reset = pdata->reset; ide->io.dataif_be = pdata->dataif_be; @@ -125,6 +156,4 @@ device_platform_driver(platform_ide_driver); * * This driver does not change any access timings due to the fact it has no idea * how to do so. So, do not expect an impressive data throughput. - * - * @todo Support also the IO port access method, the x86 architecture is using */ diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 37560fd46f..2cf3ee6892 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -241,13 +241,14 @@ int register_driver(struct driver_d *drv) } EXPORT_SYMBOL(register_driver); -struct resource *dev_get_resource(struct device_d *dev, int num) +struct resource *dev_get_resource(struct device_d *dev, unsigned long type, + int num) { int i, n = 0; for (i = 0; i < dev->num_resources; i++) { struct resource *res = &dev->resource[i]; - if (resource_type(res) == IORESOURCE_MEM) { + if (resource_type(res) == type) { if (n == num) return res; n++; @@ -261,7 +262,7 @@ void *dev_get_mem_region(struct device_d *dev, int num) { struct resource *res; - res = dev_get_resource(dev, num); + res = dev_get_resource(dev, IORESOURCE_MEM, num); if (!res) return NULL; @@ -270,13 +271,14 @@ void *dev_get_mem_region(struct device_d *dev, int num) EXPORT_SYMBOL(dev_get_mem_region); struct resource *dev_get_resource_by_name(struct device_d *dev, + unsigned long type, const char *name) { int i; for (i = 0; i < dev->num_resources; i++) { struct resource *res = &dev->resource[i]; - if (resource_type(res) != IORESOURCE_MEM) + if (resource_type(res) != type) continue; if (!res->name) continue; @@ -291,7 +293,7 @@ void *dev_get_mem_region_by_name(struct device_d *dev, const char *name) { struct resource *res; - res = dev_get_resource_by_name(dev, name); + res = dev_get_resource_by_name(dev, IORESOURCE_MEM, name); if (!res) return NULL; @@ -303,7 +305,7 @@ void __iomem *dev_request_mem_region_by_name(struct device_d *dev, const char *n { struct resource *res; - res = dev_get_resource_by_name(dev, name); + res = dev_get_resource_by_name(dev, IORESOURCE_MEM, name); if (!res) return NULL; @@ -319,7 +321,7 @@ void __iomem *dev_request_mem_region(struct device_d *dev, int num) { struct resource *res; - res = dev_get_resource(dev, num); + res = dev_get_resource(dev, IORESOURCE_MEM, num); if (!res) return NULL; diff --git a/drivers/gpio/gpio-generic.c b/drivers/gpio/gpio-generic.c index a2fc400431..5c46282045 100644 --- a/drivers/gpio/gpio-generic.c +++ b/drivers/gpio/gpio-generic.c @@ -310,7 +310,7 @@ static void __iomem *bgpio_map(struct device_d *dev, const char *name, *err = 0; - r = dev_get_resource_by_name(dev, name); + r = dev_get_resource_by_name(dev, IORESOURCE_MEM, name); if (!r) return NULL; @@ -342,7 +342,7 @@ static int bgpio_dev_probe(struct device_d *dev) struct bgpio_chip *bgc; struct bgpio_pdata *pdata = dev->platform_data; - r = dev_get_resource_by_name(dev, "dat"); + r = dev_get_resource_by_name(dev, IORESOURCE_MEM, "dat"); if (!r) return -EINVAL; diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c index 8fc84c34d8..e6722e1916 100644 --- a/drivers/mfd/syscon.c +++ b/drivers/mfd/syscon.c @@ -70,7 +70,7 @@ static int syscon_probe(struct device_d *dev) if (!syscon) return -ENOMEM; - res = dev_get_resource(dev, 0); + res = dev_get_resource(dev, IORESOURCE_MEM, 0); if (!res) { free(syscon); return -ENOENT; diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c index 7ea23b7b0c..0466a15289 100644 --- a/drivers/misc/sram.c +++ b/drivers/misc/sram.c @@ -47,7 +47,7 @@ static int sram_probe(struct device_d *dev) sram->cdev.name = asprintf("sram%d", cdev_find_free_index("sram")); - res = dev_get_resource(dev, 0); + res = dev_get_resource(dev, IORESOURCE_MEM, 0); sram->cdev.size = (unsigned long)resource_size(res); sram->cdev.ops = &memops; diff --git a/drivers/serial/serial_ns16550.c b/drivers/serial/serial_ns16550.c index a2a25fa678..709f704cb4 100644 --- a/drivers/serial/serial_ns16550.c +++ b/drivers/serial/serial_ns16550.c @@ -47,6 +47,7 @@ struct ns16550_priv { struct console_device cdev; struct NS16550_plat plat; int access_width; + int mmio; struct clk *clk; uint32_t fcrval; }; @@ -62,6 +63,90 @@ struct ns16550_drvdata { }; /** + * @brief read system i/o (byte) + * @param[in] addr address to read + * @param[in] mmio memory i/o space or i/o port space + */ +static inline uint8_t ns16550_sys_readb(void __iomem *addr, int mmio) +{ + if (mmio) + return readb(addr); + else + return (uint8_t) inb((int) addr); +} + +/** + * @brief read system i/o (word) + * @param[in] addr address to read + * @param[in] mmio memory i/o space or i/o port space + */ +static inline uint16_t ns16550_sys_readw(void __iomem *addr, int mmio) +{ + if (mmio) + return readw(addr); + else + return (uint16_t) inw((int) addr); +} + +/** + * @brief read system i/o (dword) + * @param[in] addr address to read + * @param[in] mmio memory i/o space or i/o port space + */ +static inline uint32_t ns16550_sys_readl(void __iomem *addr, int mmio) +{ + if (mmio) + return readl(addr); + else + return (uint32_t) inl((int) addr); +} + +/** + * @brief write system i/o (byte) + * @param[in] val data to write + * @param[in] addr address to write to + * @param[in] mmio memory i/o space or i/o port space + */ +static inline void ns16550_sys_writeb(uint8_t val, void __iomem *addr, + int mmio) +{ + if (mmio) + writeb(val, addr); + else + outb(val, (int) addr); +} + +/** + * @brief read system i/o (word) + * @param[in] val data to write + * @param[in] addr address to write to + * @param[in] mmio memory i/o space or i/o port space + */ +static inline void ns16550_sys_writew(uint16_t val, void __iomem *addr, + int mmio) +{ + if (mmio) + writew(val, addr); + else + outw(val, (int) addr); +} + +/** + * @brief read system i/o (dword) + * @param[in] val data to write + * @param[in] addr address to write to + * @param[in] mmio memory i/o space or i/o port space + */ +static inline void ns16550_sys_writel(uint32_t val, void __iomem *addr, + int mmio) +{ + if (mmio) + writel(val, addr); + else + outl(val, (int) addr); +} + +/** * @brief read register * * @param[in] cdev pointer to console device @@ -78,16 +163,13 @@ static uint32_t ns16550_read(struct console_device *cdev, uint32_t off) off <<= plat->shift; - if (plat->reg_read) - return plat->reg_read((unsigned long)dev->priv, off); - switch (width) { case IORESOURCE_MEM_8BIT: - return readb(dev->priv + off); + return ns16550_sys_readb(dev->priv + off, priv->mmio); case IORESOURCE_MEM_16BIT: - return readw(dev->priv + off); + return ns16550_sys_readw(dev->priv + off, priv->mmio); case IORESOURCE_MEM_32BIT: - return readl(dev->priv + off); + return ns16550_sys_readl(dev->priv + off, priv->mmio); } return -1; } @@ -109,20 +191,15 @@ static void ns16550_write(struct console_device *cdev, uint32_t val, off <<= plat->shift; - if (plat->reg_write) { - plat->reg_write(val, (unsigned long)dev->priv, off); - return; - } - switch (width) { case IORESOURCE_MEM_8BIT: - writeb(val & 0xff, dev->priv + off); + ns16550_sys_writeb(val & 0xff, dev->priv + off, priv->mmio); break; case IORESOURCE_MEM_16BIT: - writew(val & 0xffff, dev->priv + off); + ns16550_sys_writew(val & 0xffff, dev->priv + off, priv->mmio); break; case IORESOURCE_MEM_32BIT: - writel(val, dev->priv + off); + ns16550_sys_writel(val, dev->priv + off, priv->mmio); break; } } @@ -297,16 +374,30 @@ static int ns16550_probe(struct device_d *dev) struct console_device *cdev; struct NS16550_plat *plat = (struct NS16550_plat *)dev->platform_data; struct ns16550_drvdata *devtype; + struct resource *res; int ret; ret = dev_get_drvdata(dev, (unsigned long *)&devtype); if (ret) devtype = &ns16550_drvdata; - dev->priv = dev_request_mem_region(dev, 0); - priv = xzalloc(sizeof(*priv)); + res = dev_get_resource(dev, IORESOURCE_MEM, 0); + priv->mmio = (res != NULL); + if (res) { + res = request_iomem_region(dev_name(dev), res->start, res->end); + } else { + res = dev_get_resource(dev, IORESOURCE_IO, 0); + if (res) + res = request_ioport_region(dev_name(dev), res->start, + res->end); + } + if (!res) + goto err; + dev->priv = (void __force __iomem *) res->start; + + if (plat) priv->plat = *plat; else |