1 From d27ec8bb97db0f60d81ab255d51ac4e967362067 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Thu, 7 Aug 2014 18:34:19 +0200
4 Subject: [PATCH 07/36] MIPS: lantiq: add basic tffs driver
6 Signed-off-by: John Crispin <blogic@openwrt.org>
8 arch/mips/lantiq/xway/Makefile | 2 +-
9 arch/mips/lantiq/xway/tffs.c | 87 ++++++++++++++++++++++++++++++++++++++++
10 2 files changed, 88 insertions(+), 1 deletion(-)
11 create mode 100644 arch/mips/lantiq/xway/tffs.c
13 --- a/arch/mips/lantiq/xway/Makefile
14 +++ b/arch/mips/lantiq/xway/Makefile
16 obj-y := prom.o sysctrl.o clk.o reset.o dma.o gptu.o dcdc.o
19 +obj-y += vmmc.o tffs.o
21 obj-$(CONFIG_XRX200_PHY_FW) += xrx200_phy_fw.o
23 +++ b/arch/mips/lantiq/xway/tffs.c
25 +#include <linux/module.h>
26 +#include <linux/mtd/mtd.h>
27 +#include <linux/errno.h>
28 +#include <linux/slab.h>
35 +static struct tffs_id {
42 + { 0x01A9, "annex" },
45 + { 0x018a, "macwlan" },
46 + { 0x0195, "macwlan2" },
47 + { 0x018b, "macdsl" },
48 + { 0x01C2, "webgui_pass" },
49 + { 0x01AB, "wlan_key" },
52 +static struct mtd_info *tffs1, *tffs2;
54 +static struct tffs_id* tffs_find_id(int id)
58 + for (i = 0; i < ARRAY_SIZE(ids); i++)
59 + if (id == ids[i].id)
65 +static void tffs_index(void)
67 + struct tffs_entry *E = NULL;
68 + struct tffs_entry entry;
71 + while ((unsigned int) E + sizeof(struct tffs_entry) < tffs2->size) {
75 + ret = mtd_read(tffs2, (unsigned int) E, sizeof(struct tffs_entry), &retlen, (unsigned char *)&entry);
79 + if (entry.id == 0xffff)
82 + id = tffs_find_id(entry.id);
84 + id->offset = (uint32_t) E;
85 + id->len = entry.len;
86 + id->val = kzalloc(entry.len + 1, GFP_KERNEL);
87 + mtd_read(tffs2, ((unsigned int) E) + sizeof(struct tffs_entry), entry.len, &retlen, id->val);
90 + //printk(KERN_INFO "found entry at 0x%08X-> [<0x%x> %u bytes]\n", (uint32_t) E, entry.id, entry.len);
92 + printk(KERN_INFO "found entry name -> %s=%s\n", id->name, id->val);
94 + len = (entry.len + 3) & ~0x03;
95 + E = (struct tffs_entry *)(((unsigned int)E) + sizeof(struct tffs_entry) + len);
99 +static int __init tffs_init(void)
101 + tffs1 = get_mtd_device_nm("tffs (1)");
102 + tffs2 = get_mtd_device_nm("tffs (2)");
103 + if (IS_ERR(tffs1) || IS_ERR(tffs2))
110 +late_initcall(tffs_init);