^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Flash memory access on SA11x0 based devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * (C) 2000 Nicolas Pitre <nico@fluxnic.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/mtd/mtd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/mtd/map.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/mtd/partitions.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/mtd/concat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <mach/hardware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/sizes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <asm/mach/flash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct sa_subdev_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) char name[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct map_info map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct mtd_info *mtd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct flash_platform_data *plat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct sa_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct mtd_info *mtd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) int num_subdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct sa_subdev_info subdev[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) static DEFINE_SPINLOCK(sa1100_vpp_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static int sa1100_vpp_refcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static void sa1100_set_vpp(struct map_info *map, int on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct sa_subdev_info *subdev = container_of(map, struct sa_subdev_info, map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) spin_lock_irqsave(&sa1100_vpp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) if (on) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) if (++sa1100_vpp_refcnt == 1) /* first nested 'on' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) subdev->plat->set_vpp(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) if (--sa1100_vpp_refcnt == 0) /* last nested 'off' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) subdev->plat->set_vpp(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) spin_unlock_irqrestore(&sa1100_vpp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static void sa1100_destroy_subdev(struct sa_subdev_info *subdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) if (subdev->mtd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) map_destroy(subdev->mtd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) if (subdev->map.virt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) iounmap(subdev->map.virt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) release_mem_region(subdev->map.phys, subdev->map.size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static int sa1100_probe_subdev(struct sa_subdev_info *subdev, struct resource *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) unsigned long phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) unsigned int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) phys = res->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) size = res->end - phys + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * Retrieve the bankwidth from the MSC registers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * We currently only implement CS0 and CS1 here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) switch (phys) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) printk(KERN_WARNING "SA1100 flash: unknown base address "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) "0x%08lx, assuming CS0\n", phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) case SA1100_CS0_PHYS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) subdev->map.bankwidth = (MSC0 & MSC_RBW) ? 2 : 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) case SA1100_CS1_PHYS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) subdev->map.bankwidth = ((MSC0 >> 16) & MSC_RBW) ? 2 : 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) if (!request_mem_region(phys, size, subdev->name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) ret = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (subdev->plat->set_vpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) subdev->map.set_vpp = sa1100_set_vpp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) subdev->map.phys = phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) subdev->map.size = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) subdev->map.virt = ioremap(phys, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (!subdev->map.virt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) simple_map_init(&subdev->map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * Now let's probe for the actual flash. Do it here since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * specific machine settings might have been set above.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) subdev->mtd = do_map_probe(subdev->plat->map_name, &subdev->map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (subdev->mtd == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) ret = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) printk(KERN_INFO "SA1100 flash: CFI device at 0x%08lx, %uMiB, %d-bit\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) phys, (unsigned)(subdev->mtd->size >> 20),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) subdev->map.bankwidth * 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) sa1100_destroy_subdev(subdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static void sa1100_destroy(struct sa_info *info, struct flash_platform_data *plat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (info->mtd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) mtd_device_unregister(info->mtd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if (info->mtd != info->subdev[0].mtd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) mtd_concat_destroy(info->mtd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) for (i = info->num_subdev - 1; i >= 0; i--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) sa1100_destroy_subdev(&info->subdev[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) kfree(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (plat->exit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) plat->exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) static struct sa_info *sa1100_setup_mtd(struct platform_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) struct flash_platform_data *plat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct sa_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) int nr, size, i, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * Count number of devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) for (nr = 0; ; nr++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if (!platform_get_resource(pdev, IORESOURCE_MEM, nr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) if (nr == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) size = sizeof(struct sa_info) + sizeof(struct sa_subdev_info) * nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * Allocate the map_info structs in one go.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) info = kzalloc(size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) if (!info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (plat->init) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) ret = plat->init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * Claim and then map the memory regions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) for (i = 0; i < nr; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) struct sa_subdev_info *subdev = &info->subdev[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) res = platform_get_resource(pdev, IORESOURCE_MEM, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (!res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) subdev->map.name = subdev->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) sprintf(subdev->name, "%s-%d", plat->name, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) subdev->plat = plat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) ret = sa1100_probe_subdev(subdev, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) info->num_subdev = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * ENXIO is special. It means we didn't find a chip when we probed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (ret != 0 && !(ret == -ENXIO && info->num_subdev > 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * If we found one device, don't bother with concat support. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * we found multiple devices, use concat if we have it available,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * otherwise fail. Either way, it'll be called "sa1100".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (info->num_subdev == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) strcpy(info->subdev[0].name, plat->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) info->mtd = info->subdev[0].mtd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) } else if (info->num_subdev > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) struct mtd_info **cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) cdev = kmalloc_array(nr, sizeof(*cdev), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if (!cdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * We detected multiple devices. Concatenate them together.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) for (i = 0; i < info->num_subdev; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) cdev[i] = info->subdev[i].mtd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) info->mtd = mtd_concat_create(cdev, info->num_subdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) plat->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) kfree(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (info->mtd == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) ret = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) info->mtd->dev.parent = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) return info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) sa1100_destroy(info, plat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static const char * const part_probes[] = { "cmdlinepart", "RedBoot", NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) static int sa1100_mtd_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) struct flash_platform_data *plat = dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) struct sa_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) if (!plat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) info = sa1100_setup_mtd(pdev, plat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) if (IS_ERR(info)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) err = PTR_ERR(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) * Partition selection stuff.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) mtd_device_parse_register(info->mtd, part_probes, NULL, plat->parts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) plat->nr_parts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) platform_set_drvdata(pdev, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static int sa1100_mtd_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) struct sa_info *info = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) struct flash_platform_data *plat = dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) sa1100_destroy(info, plat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) static struct platform_driver sa1100_mtd_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) .probe = sa1100_mtd_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) .remove = sa1100_mtd_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) .name = "sa1100-mtd",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) module_platform_driver(sa1100_mtd_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) MODULE_AUTHOR("Nicolas Pitre");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) MODULE_DESCRIPTION("SA1100 CFI map driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) MODULE_ALIAS("platform:sa1100-mtd");