1 From e98005f02af333e0bf905a1e53caef009a37fc55 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Sun, 14 Jul 2013 22:26:43 +0200
4 Subject: add basic tffs driver
7 --- a/arch/mips/lantiq/xway/Makefile
8 +++ b/arch/mips/lantiq/xway/Makefile
10 obj-y := prom.o sysctrl.o clk.o reset.o dma.o timer.o dcdc.o
12 -obj-y += vmmc.o mtd_split.o
13 +obj-y += vmmc.o mtd_split.o tffs.o
15 obj-$(CONFIG_PCI) += ath_eep.o rt_eep.o pci-ath-fixup.o
18 +++ b/arch/mips/lantiq/xway/tffs.c
20 +#include <linux/module.h>
21 +#include <linux/mtd/mtd.h>
22 +#include <linux/errno.h>
23 +#include <linux/slab.h>
30 +static struct tffs_id {
37 + { 0x01A9, "annex" },
40 + { 0x018a, "macwlan" },
41 + { 0x0195, "macwlan2" },
42 + { 0x018b, "macdsl" },
43 + { 0x01C2, "webgui_pass" },
44 + { 0x01AB, "wlan_key" },
47 +static struct mtd_info *tffs1, *tffs2;
49 +static struct tffs_id* tffs_find_id(int id)
53 + for (i = 0; i < ARRAY_SIZE(ids); i++)
54 + if (id == ids[i].id)
60 +static void tffs_index(void)
62 + struct tffs_entry *E = NULL;
63 + struct tffs_entry entry;
66 + while ((unsigned int) E + sizeof(struct tffs_entry) < tffs2->size) {
70 + ret = mtd_read(tffs2, (unsigned int) E, sizeof(struct tffs_entry), &retlen, (unsigned char *)&entry);
74 + if (entry.id == 0xffff)
77 + id = tffs_find_id(entry.id);
79 + id->offset = (uint32_t) E;
80 + id->len = entry.len;
81 + id->val = kzalloc(entry.len + 1, GFP_KERNEL);
82 + mtd_read(tffs2, ((unsigned int) E) + sizeof(struct tffs_entry), entry.len, &retlen, id->val);
85 + //printk(KERN_INFO "found entry at 0x%08X-> [<0x%x> %u bytes]\n", (uint32_t) E, entry.id, entry.len);
87 + printk(KERN_INFO "found entry name -> %s=%s\n", id->name, id->val);
89 + len = (entry.len + 3) & ~0x03;
90 + E = (struct tffs_entry *)(((unsigned int)E) + sizeof(struct tffs_entry) + len);
94 +static int __init tffs_init(void)
96 + tffs1 = get_mtd_device_nm("tffs (1)");
97 + tffs2 = get_mtd_device_nm("tffs (2)");
98 + if (IS_ERR(tffs1) || IS_ERR(tffs2))
105 +late_initcall(tffs_init);