a41d48ed322f57aa4a15d5ea4ee0251d0ca54479
[openwrt/openwrt.git] / target / linux / lantiq / patches-3.14 / 0007-MIPS-lantiq-add-basic-tffs-driver.patch
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
5
6 Signed-off-by: John Crispin <blogic@openwrt.org>
7 ---
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
12
13 diff --git a/arch/mips/lantiq/xway/Makefile b/arch/mips/lantiq/xway/Makefile
14 index a2edc53..c73d3f2 100644
15 --- a/arch/mips/lantiq/xway/Makefile
16 +++ b/arch/mips/lantiq/xway/Makefile
17 @@ -1,5 +1,5 @@
18 obj-y := prom.o sysctrl.o clk.o reset.o dma.o gptu.o dcdc.o
19
20 -obj-y += vmmc.o
21 +obj-y += vmmc.o tffs.o
22
23 obj-$(CONFIG_XRX200_PHY_FW) += xrx200_phy_fw.o
24 diff --git a/arch/mips/lantiq/xway/tffs.c b/arch/mips/lantiq/xway/tffs.c
25 new file mode 100644
26 index 0000000..c9c6e19
27 --- /dev/null
28 +++ b/arch/mips/lantiq/xway/tffs.c
29 @@ -0,0 +1,87 @@
30 +#include <linux/module.h>
31 +#include <linux/mtd/mtd.h>
32 +#include <linux/errno.h>
33 +#include <linux/slab.h>
34 +
35 +struct tffs_entry {
36 + uint16_t id;
37 + uint16_t len;
38 +};
39 +
40 +static struct tffs_id {
41 + uint32_t id;
42 + char *name;
43 + unsigned char *val;
44 + uint32_t offset;
45 + uint32_t len;
46 +} ids[] = {
47 + { 0x01A9, "annex" },
48 + { 0x0188, "maca" },
49 + { 0x0189, "macb" },
50 + { 0x018a, "macwlan" },
51 + { 0x0195, "macwlan2" },
52 + { 0x018b, "macdsl" },
53 + { 0x01C2, "webgui_pass" },
54 + { 0x01AB, "wlan_key" },
55 +};
56 +
57 +static struct mtd_info *tffs1, *tffs2;
58 +
59 +static struct tffs_id* tffs_find_id(int id)
60 +{
61 + int i;
62 +
63 + for (i = 0; i < ARRAY_SIZE(ids); i++)
64 + if (id == ids[i].id)
65 + return &ids[i];
66 +
67 + return NULL;
68 +}
69 +
70 +static void tffs_index(void)
71 +{
72 + struct tffs_entry *E = NULL;
73 + struct tffs_entry entry;
74 + int ret, retlen;
75 +
76 + while ((unsigned int) E + sizeof(struct tffs_entry) < tffs2->size) {
77 + struct tffs_id *id;
78 + int len;
79 +
80 + ret = mtd_read(tffs2, (unsigned int) E, sizeof(struct tffs_entry), &retlen, (unsigned char *)&entry);
81 + if (ret)
82 + return;
83 +
84 + if (entry.id == 0xffff)
85 + return;
86 +
87 + id = tffs_find_id(entry.id);
88 + if (id) {
89 + id->offset = (uint32_t) E;
90 + id->len = entry.len;
91 + id->val = kzalloc(entry.len + 1, GFP_KERNEL);
92 + mtd_read(tffs2, ((unsigned int) E) + sizeof(struct tffs_entry), entry.len, &retlen, id->val);
93 +
94 + }
95 + //printk(KERN_INFO "found entry at 0x%08X-> [<0x%x> %u bytes]\n", (uint32_t) E, entry.id, entry.len);
96 + if (id && id->name)
97 + printk(KERN_INFO "found entry name -> %s=%s\n", id->name, id->val);
98 +
99 + len = (entry.len + 3) & ~0x03;
100 + E = (struct tffs_entry *)(((unsigned int)E) + sizeof(struct tffs_entry) + len);
101 + }
102 +}
103 +
104 +static int __init tffs_init(void)
105 +{
106 + tffs1 = get_mtd_device_nm("tffs (1)");
107 + tffs2 = get_mtd_device_nm("tffs (2)");
108 + if (IS_ERR(tffs1) || IS_ERR(tffs2))
109 + return -1;
110 +
111 + tffs_index();
112 +
113 + return 0;
114 +}
115 +late_initcall(tffs_init);
116 +
117 --
118 1.7.10.4
119