diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/nand/nand.c | 69 | ||||
-rw-r--r-- | drivers/net/miiphy.c | 52 | ||||
-rw-r--r-- | drivers/nor/cfi_flash.c | 64 | ||||
-rw-r--r-- | drivers/nor/cfi_flash_new.c | 62 | ||||
-rw-r--r-- | drivers/spi/mc13783.c | 13 |
5 files changed, 134 insertions, 126 deletions
diff --git a/drivers/nand/nand.c b/drivers/nand/nand.c index 399d0ad86a..5f5e83a841 100644 --- a/drivers/nand/nand.c +++ b/drivers/nand/nand.c @@ -20,7 +20,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA */ - #include <common.h> #include <linux/mtd/nand.h> #include <linux/mtd/mtd.h> @@ -31,9 +30,9 @@ #include <ioctl.h> #include <nand.h> -static ssize_t nand_read(struct device_d *dev, void* buf, size_t count, ulong offset, ulong flags) +static ssize_t nand_read(struct cdev *cdev, void* buf, size_t count, ulong offset, ulong flags) { - struct mtd_info *info = dev->priv; + struct mtd_info *info = cdev->priv; size_t retlen; int ret; @@ -41,16 +40,18 @@ static ssize_t nand_read(struct device_d *dev, void* buf, size_t count, ulong o ret = info->read(info, offset, count, &retlen, buf); - if(ret) + if(ret) { + printf("err %d\n", ret); return ret; + } return retlen; } #define NOTALIGNED(x) (x & (info->writesize - 1)) != 0 -static ssize_t nand_write(struct device_d* dev, const void* buf, size_t _count, ulong offset, ulong flags) +static ssize_t nand_write(struct cdev* cdev, const void *buf, size_t _count, ulong offset, ulong flags) { - struct mtd_info *info = dev->priv; + struct mtd_info *info = cdev->priv; size_t retlen, now; int ret; void *wrbuf = NULL; @@ -86,9 +87,9 @@ out: return ret ? ret : _count; } -static int nand_ioctl(struct device_d *dev, int request, void *buf) +static int nand_ioctl(struct cdev *cdev, int request, void *buf) { - struct mtd_info *info = dev->priv; + struct mtd_info *info = cdev->priv; struct mtd_info_user *user = buf; switch (request) { @@ -113,9 +114,9 @@ static int nand_ioctl(struct device_d *dev, int request, void *buf) return 0; } -static ssize_t nand_erase(struct device_d *dev, size_t count, unsigned long offset) +static ssize_t nand_erase(struct cdev *cdev, size_t count, unsigned long offset) { - struct mtd_info *info = dev->priv; + struct mtd_info *info = cdev->priv; struct erase_info erase; int ret; @@ -143,6 +144,14 @@ static ssize_t nand_erase(struct device_d *dev, size_t count, unsigned long offs return 0; } +static struct file_operations nand_ops = { + .read = nand_read, + .write = nand_write, + .ioctl = nand_ioctl, + .lseek = dev_lseek_default, + .erase = nand_erase, +}; + static int nand_device_probe(struct device_d *dev) { return 0; @@ -151,13 +160,6 @@ static int nand_device_probe(struct device_d *dev) static struct driver_d nand_device_driver = { .name = "nand_device", .probe = nand_device_probe, - .read = nand_read, - .write = nand_write, - .ioctl = nand_ioctl, - .open = dev_open_default, - .close = dev_close_default, - .lseek = dev_lseek_default, - .erase = nand_erase, .type = DEVICE_TYPE_NAND, }; @@ -170,36 +172,27 @@ static int nand_init(void) device_initcall(nand_init); -int add_mtd_device(struct mtd_info *mtd) { - struct device_d *dev; - int ret; - - dev = xzalloc(sizeof(*dev)); +int add_mtd_device(struct mtd_info *mtd) +{ + struct device_d *dev = &mtd->class_dev; + char name[MAX_DRIVER_NAME]; - strcpy(dev->name, "nand_device"); - get_free_deviceid(dev->id, "nand"); + get_free_deviceid(name, "nand"); - dev->size = mtd->size; - dev->type = DEVICE_TYPE_NAND; - dev->priv = mtd; - mtd->dev = dev; + mtd->cdev.ops = &nand_ops; + mtd->cdev.size = mtd->size; + mtd->cdev.name = strdup(name); + mtd->cdev.dev = dev; + mtd->cdev.priv = mtd; - ret = register_device(dev); - if (ret) - goto out; + devfs_create(&mtd->cdev); return 0; - -out: - free(dev); - return ret; } int del_mtd_device (struct mtd_info *mtd) { - unregister_device(mtd->dev); - free(mtd->dev); - + unregister_device(&mtd->class_dev); return 0; } diff --git a/drivers/net/miiphy.c b/drivers/net/miiphy.c index ccb274bd0d..b4e6756a93 100644 --- a/drivers/net/miiphy.c +++ b/drivers/net/miiphy.c @@ -25,6 +25,7 @@ #include <init.h> #include <miiphy.h> #include <clock.h> +#include <net.h> int miiphy_restart_aneg(struct miiphy_device *mdev) { @@ -84,12 +85,12 @@ int miiphy_wait_aneg(struct miiphy_device *mdev) start = get_time_ns(); do { if (is_timeout(start, 5 * SECOND)) { - printf("%s: Autonegotiation timeout\n", mdev->dev.id); + printf("%s: Autonegotiation timeout\n", mdev->cdev.name); return -1; } if (mdev->read(mdev, mdev->address, MII_BMSR, &status)) { - printf("%s: Autonegotiation failed. status: 0x%04x\n", mdev->dev.id, status); + printf("%s: Autonegotiation failed. status: 0x%04x\n", mdev->cdev.name, status); return -1; } } while (!(status & BMSR_LSTATUS)); @@ -115,7 +116,7 @@ int miiphy_print_status(struct miiphy_device *mdev) if (mdev->read(mdev, mdev->address, MII_LPA, &lpa) != 0) goto err_out; - printf("%s: Link is %s", mdev->dev.id, + printf("%s: Link is %s", mdev->cdev.name, bmsr & BMSR_LSTATUS ? "up" : "down"); if (bmcr & BMCR_ANENABLE) { @@ -130,15 +131,15 @@ int miiphy_print_status(struct miiphy_device *mdev) return 0; err_out: - printf("%s: failed to read\n", mdev->dev.id); + printf("%s: failed to read\n", mdev->cdev.name); return -1; } -static ssize_t miiphy_read(struct device_d *dev, void *_buf, size_t count, ulong offset, ulong flags) +static ssize_t miiphy_read(struct cdev *cdev, void *_buf, size_t count, ulong offset, ulong flags) { int i = count; uint16_t *buf = _buf; - struct miiphy_device *mdev = dev->priv; + struct miiphy_device *mdev = cdev->priv; while (i > 1) { mdev->read(mdev, mdev->address, offset, buf); @@ -150,11 +151,11 @@ static ssize_t miiphy_read(struct device_d *dev, void *_buf, size_t count, ulong return count; } -static ssize_t miiphy_write(struct device_d *dev, const void *_buf, size_t count, ulong offset, ulong flags) +static ssize_t miiphy_write(struct cdev *cdev, const void *_buf, size_t count, ulong offset, ulong flags) { int i = count; const uint16_t *buf = _buf; - struct miiphy_device *mdev = dev->priv; + struct miiphy_device *mdev = cdev->priv; while (i > 1) { mdev->write(mdev, mdev->address, offset, *buf); @@ -166,41 +167,36 @@ static ssize_t miiphy_write(struct device_d *dev, const void *_buf, size_t count return count; } +static struct file_operations miiphy_ops = { + .read = miiphy_read, + .write = miiphy_write, +}; + static int miiphy_probe(struct device_d *dev) { + struct miiphy_device *mdev = dev->priv; + char name[MAX_DRIVER_NAME]; + + get_free_deviceid(name, "phy"); + mdev->cdev.name = strdup(name); + mdev->cdev.size = 32; + mdev->cdev.ops = &miiphy_ops; + mdev->cdev.priv = mdev; + devfs_create(&mdev->cdev); return 0; } -static void miiphy_remove(struct device_d *dev) -{ -} - int miiphy_register(struct miiphy_device *mdev) { - strcpy(mdev->dev.name, "miiphy"); - get_free_deviceid(mdev->dev.id, "phy"); - mdev->dev.type = DEVICE_TYPE_MIIPHY; mdev->dev.priv = mdev; - mdev->dev.size = 32; + strcpy(mdev->dev.name, "miiphy"); return register_device(&mdev->dev); } -void miiphy_unregister(struct miiphy_device *mdev) -{ - unregister_device(&mdev->dev); -} - static struct driver_d miiphy_drv = { .name = "miiphy", .probe = miiphy_probe, - .remove = miiphy_remove, - .open = dev_open_default, - .close = dev_close_default, - .read = miiphy_read, - .write = miiphy_write, - .lseek = dev_lseek_default, - .type = DEVICE_TYPE_MIIPHY, }; static int miiphy_init(void) diff --git a/drivers/nor/cfi_flash.c b/drivers/nor/cfi_flash.c index 930d4a8504..b38d291415 100644 --- a/drivers/nor/cfi_flash.c +++ b/drivers/nor/cfi_flash.c @@ -42,6 +42,7 @@ #include <init.h> #include <malloc.h> #include <cfi_flash.h> +#include <errno.h> #define FLASH_CMD_CFI 0x98 #define FLASH_CMD_READ_ID 0x90 @@ -352,16 +353,16 @@ static int flash_erase_one (flash_info_t * info, long sect) return rcode; } -static int cfi_erase(struct device_d *dev, size_t count, unsigned long offset) +static int cfi_erase(struct cdev *cdev, size_t count, unsigned long offset) { - flash_info_t *finfo = (flash_info_t *)dev->priv; + flash_info_t *finfo = (flash_info_t *)cdev->priv; unsigned long start, end; int i, ret = 0; debug("%s: erase 0x%08x (size %d)\n", __FUNCTION__, offset, count); - start = flash_find_sector(finfo, dev->map_base + offset); - end = flash_find_sector(finfo, dev->map_base + offset + count - 1); + start = flash_find_sector(finfo, cdev->dev->map_base + offset); + end = flash_find_sector(finfo, cdev->dev->map_base + offset + count - 1); for (i = start; i <= end; i++) { ret = flash_erase_one (finfo, i); @@ -373,16 +374,16 @@ out: return ret; } -static int cfi_protect(struct device_d *dev, size_t count, unsigned long offset, int prot) +static int cfi_protect(struct cdev *cdev, size_t count, unsigned long offset, int prot) { - flash_info_t *finfo = (flash_info_t *)dev->priv; + flash_info_t *finfo = (flash_info_t *)cdev->priv; unsigned long start, end; int i, ret = 0; debug("%s: protect 0x%08x (size %d)\n", __FUNCTION__, offset, count); - start = flash_find_sector(finfo, dev->map_base + offset); - end = flash_find_sector(finfo, dev->map_base + offset + count - 1); + start = flash_find_sector(finfo, cdev->dev->map_base + offset); + end = flash_find_sector(finfo, cdev->dev->map_base + offset + count - 1); for (i = start; i <= end; i++) { ret = flash_real_protect (finfo, i, prot); @@ -394,14 +395,14 @@ out: return ret; } -static ssize_t cfi_write(struct device_d* dev, const void* buf, size_t count, unsigned long offset, ulong flags) +static ssize_t cfi_write(struct cdev *cdev, const void* buf, size_t count, unsigned long offset, ulong flags) { - flash_info_t *finfo = (flash_info_t *)dev->priv; + flash_info_t *finfo = (flash_info_t *)cdev->priv; int ret; - debug("cfi_write: buf=0x%08x addr=0x%08x count=0x%08x\n",buf, dev->map_base + offset, count); + debug("cfi_write: buf=0x%08x addr=0x%08x count=0x%08x\n",buf, cdev->dev->map_base + offset, count); - ret = write_buff (finfo, buf, dev->map_base + offset, count); + ret = write_buff (finfo, buf, cdev->dev->map_base + offset, count); return ret == 0 ? count : -1; } @@ -1437,43 +1438,48 @@ static int flash_write_cfibuffer (flash_info_t * info, ulong dest, const uchar * } #endif /* CONFIG_CFI_BUFFER_WRITE */ +struct file_operations cfi_ops = { + .read = mem_read, + .write = cfi_write, + .lseek = dev_lseek_default, + .erase = cfi_erase, + .protect = cfi_protect, + .memmap = generic_memmap_ro, +}; + static int cfi_probe (struct device_d *dev) { unsigned long size = 0; - flash_info_t *info = malloc(sizeof(flash_info_t)); + flash_info_t *info = xzalloc(sizeof(flash_info_t)); + char name[MAX_DRIVER_NAME]; dev->priv = (void *)info; - debug ("cfi_probe: %s base: 0x%08x size: 0x%08x\n", dev->name, dev->map_base, dev->size); + printf("cfi_probe: %s base: 0x%08x size: 0x%08x\n", dev->name, dev->map_base, dev->size); /* Init: no FLASHes known */ info->flash_id = FLASH_UNKNOWN; size += info->size = flash_get_size(info, dev->map_base); - - if (dev->size > size) { - dev_dbg(dev, "limiting size from 0x%08x to 0x%08x\n", dev->size, size); - dev->size = size; - } - if (info->flash_id == FLASH_UNKNOWN) { - debug ("## Unknown FLASH on Bank at 0x%08x - Size = 0x%08lx = %ld MB\n", + printf ("## Unknown FLASH on Bank at 0x%08x - Size = 0x%08lx = %ld MB\n", dev->map_base, info->size, info->size << 20); + return -ENODEV; } + get_free_deviceid(name, "nor"); + info->cdev.name = strdup(name); + info->cdev.size = info->size; + info->cdev.dev = dev; + info->cdev.ops = &cfi_ops; + info->cdev.priv = info; + devfs_create(&info->cdev); + return 0; } static struct driver_d cfi_driver = { .name = "cfi_flash", .probe = cfi_probe, - .read = mem_read, - .write = cfi_write, - .lseek = dev_lseek_default, - .open = dev_open_default, - .close = dev_close_default, - .erase = cfi_erase, - .protect= cfi_protect, - .memmap = generic_memmap_ro, .info = cfi_info, }; diff --git a/drivers/nor/cfi_flash_new.c b/drivers/nor/cfi_flash_new.c index b64f057222..f45b97b839 100644 --- a/drivers/nor/cfi_flash_new.c +++ b/drivers/nor/cfi_flash_new.c @@ -42,6 +42,7 @@ #include <malloc.h> #include <cfi_flash_new.h> #include <asm/io.h> +#include <errno.h> /* * This file implements a Common Flash Interface (CFI) driver for U-Boot. @@ -348,8 +349,8 @@ static ulong flash_get_size (flash_info_t *info, ulong base) break; #endif default: - printf("unsopported vendor\n"); - break; + printf("unsupported vendor\n"); + return 0; } info->cfi_cmd_set->flash_read_jedec_ids (info); flash_write_cmd (info, 0, info->cfi_offset, FLASH_CMD_CFI); @@ -505,16 +506,16 @@ flash_sect_t find_sector (flash_info_t * info, ulong addr) return sector; } -static int cfi_erase(struct device_d *dev, size_t count, unsigned long offset) +static int cfi_erase(struct cdev *cdev, size_t count, unsigned long offset) { - flash_info_t *finfo = (flash_info_t *)dev->priv; + flash_info_t *finfo = (flash_info_t *)cdev->priv; unsigned long start, end; int i, ret = 0; printf("%s: erase 0x%08x (size %d)\n", __FUNCTION__, offset, count); - start = find_sector(finfo, dev->map_base + offset); - end = find_sector(finfo, dev->map_base + offset + count - 1); + start = find_sector(finfo, cdev->dev->map_base + offset); + end = find_sector(finfo, cdev->dev->map_base + offset + count - 1); for (i = start; i <= end; i++) { ret = finfo->cfi_cmd_set->flash_erase_one(finfo, i); @@ -658,16 +659,16 @@ static int flash_real_protect (flash_info_t * info, long sector, int prot) return retcode; } -static int cfi_protect(struct device_d *dev, size_t count, unsigned long offset, int prot) +static int cfi_protect(struct cdev *cdev, size_t count, unsigned long offset, int prot) { - flash_info_t *finfo = (flash_info_t *)dev->priv; + flash_info_t *finfo = (flash_info_t *)cdev->priv; unsigned long start, end; int i, ret = 0; - debug("%s: protect 0x%08x (size %d)\n", __FUNCTION__, offset, count); + printf("%s: protect 0x%08x (size %d)\n", __FUNCTION__, cdev->dev->map_base + offset, count); - start = find_sector(finfo, dev->map_base + offset); - end = find_sector(finfo, dev->map_base + offset + count - 1); + start = find_sector(finfo, cdev->dev->map_base + offset); + end = find_sector(finfo, cdev->dev->map_base + offset + count - 1); for (i = start; i <= end; i++) { ret = flash_real_protect (finfo, i, prot); @@ -679,14 +680,14 @@ out: return ret; } -static ssize_t cfi_write(struct device_d* dev, const void* buf, size_t count, unsigned long offset, ulong flags) +static ssize_t cfi_write(struct cdev *cdev, const void *buf, size_t count, unsigned long offset, ulong flags) { - flash_info_t *finfo = (flash_info_t *)dev->priv; + flash_info_t *finfo = (flash_info_t *)cdev->priv; int ret; - debug("cfi_write: buf=0x%08x addr=0x%08x count=0x%08x\n",buf, dev->map_base + offset, count); + debug("cfi_write: buf=0x%08x addr=0x%08x count=0x%08x\n",buf, cdev->dev->map_base + offset, count); - ret = write_buff (finfo, buf, dev->map_base + offset, count); + ret = write_buff (finfo, buf, cdev->dev->map_base + offset, count); return ret == 0 ? count : -1; } @@ -934,10 +935,20 @@ int flash_isset (flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd) return retval; } +struct file_operations cfi_ops = { + .read = mem_read, + .write = cfi_write, + .lseek = dev_lseek_default, + .erase = cfi_erase, + .protect = cfi_protect, + .memmap = generic_memmap_ro, +}; + static int cfi_probe (struct device_d *dev) { unsigned long size = 0; - flash_info_t *info = malloc(sizeof(flash_info_t)); + flash_info_t *info = xzalloc(sizeof(flash_info_t)); + char name[MAX_DRIVER_NAME]; dev->priv = (void *)info; @@ -953,27 +964,26 @@ static int cfi_probe (struct device_d *dev) } if (info->flash_id == FLASH_UNKNOWN) { -#ifndef CFG_FLASH_QUIET_TEST printf ("## Unknown FLASH on Bank at 0x%08x - Size = 0x%08lx = %ld MB\n", dev->map_base, info->size, info->size << 20); -#endif /* CFG_FLASH_QUIET_TEST */ + return -ENODEV; } + get_free_deviceid(name, "nor"); + info->cdev.name = strdup(name); + info->cdev.size = info->size; + info->cdev.dev = dev; + info->cdev.ops = &cfi_ops; + info->cdev.priv = info; + devfs_create(&info->cdev); + return 0; } static struct driver_d cfi_driver = { .name = "cfi_flash", .probe = cfi_probe, - .read = mem_read, - .write = cfi_write, - .lseek = dev_lseek_default, - .open = dev_open_default, - .close = dev_close_default, - .erase = cfi_erase, .info = cfi_info, - .protect = cfi_protect, - .memmap = generic_memmap_ro, }; static int cfi_init(void) diff --git a/drivers/spi/mc13783.c b/drivers/spi/mc13783.c index e9085a2aa9..d57ae5c110 100644 --- a/drivers/spi/mc13783.c +++ b/drivers/spi/mc13783.c @@ -206,14 +206,17 @@ static int pmic_probe(struct device_d *dev) return 0; } +static struct file_operations pmic_fops = { + .open = dev_open_default, + .lseek = dev_lseek_default, + .close = dev_close_default, + .read = pmic_read, + .write = pmic_write, +}; + static struct driver_d pmic_driver = { .name = "mc13783", .probe = pmic_probe, - .open = dev_open_default, - .lseek = dev_lseek_default, - .close = dev_close_default, - .read = pmic_read, - .write = pmic_write, }; static int pmic_init(void) |