kernel: update 3.10 to 3.10.36
[openwrt.git] / target / linux / lantiq / patches-3.10 / 0103-tffs.patch
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
5
6 ---
7 --- a/arch/mips/lantiq/xway/Makefile
8 +++ b/arch/mips/lantiq/xway/Makefile
9 @@ -1,6 +1,6 @@
10  obj-y := prom.o sysctrl.o clk.o reset.o dma.o timer.o dcdc.o
11  
12 -obj-y += vmmc.o mtd_split.o
13 +obj-y += vmmc.o mtd_split.o tffs.o
14  
15  obj-$(CONFIG_PCI) += ath_eep.o rt_eep.o pci-ath-fixup.o
16  
17 --- /dev/null
18 +++ b/arch/mips/lantiq/xway/tffs.c
19 @@ -0,0 +1,87 @@
20 +#include <linux/module.h>
21 +#include <linux/mtd/mtd.h>
22 +#include <linux/errno.h>
23 +#include <linux/slab.h>
24 +
25 +struct tffs_entry {
26 +    uint16_t id;
27 +    uint16_t len;
28 +};
29 +
30 +static struct tffs_id {
31 +       uint32_t id;
32 +       char *name;
33 +       unsigned char *val;
34 +       uint32_t offset;
35 +       uint32_t len;
36 +} ids[] = {
37 +       { 0x01A9, "annex" },
38 +       { 0x0188, "maca" },
39 +       { 0x0189, "macb" },
40 +       { 0x018a, "macwlan" },
41 +       { 0x0195, "macwlan2" },
42 +       { 0x018b, "macdsl" },
43 +       { 0x01C2, "webgui_pass" },
44 +       { 0x01AB, "wlan_key" },
45 +};
46 +
47 +static struct mtd_info *tffs1, *tffs2;
48 +
49 +static struct tffs_id* tffs_find_id(int id)
50 +{
51 +       int i;
52 +
53 +       for (i = 0; i < ARRAY_SIZE(ids); i++)
54 +               if (id == ids[i].id)
55 +                       return &ids[i];
56 +
57 +       return NULL;
58 +}
59 +
60 +static void tffs_index(void)
61 +{
62 +       struct tffs_entry *E = NULL;
63 +       struct tffs_entry entry;
64 +       int ret, retlen;
65 +
66 +       while ((unsigned int) E + sizeof(struct tffs_entry) < tffs2->size) {
67 +               struct tffs_id *id;
68 +               int len;
69 +
70 +               ret = mtd_read(tffs2, (unsigned int) E, sizeof(struct tffs_entry), &retlen, (unsigned char *)&entry);
71 +               if (ret)
72 +                       return;
73 +
74 +               if (entry.id == 0xffff)
75 +                       return;
76 +
77 +               id = tffs_find_id(entry.id);
78 +               if (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);
83 +
84 +               }
85 +               //printk(KERN_INFO "found entry at 0x%08X-> [<0x%x> %u bytes]\n", (uint32_t) E, entry.id, entry.len);
86 +               if (id && id->name)
87 +                       printk(KERN_INFO "found entry name -> %s=%s\n", id->name, id->val);
88 +
89 +               len = (entry.len + 3) & ~0x03;
90 +               E = (struct tffs_entry *)(((unsigned int)E) + sizeof(struct tffs_entry) + len);
91 +       }
92 +}
93 +
94 +static int __init tffs_init(void)
95 +{
96 +       tffs1 = get_mtd_device_nm("tffs (1)");
97 +       tffs2 = get_mtd_device_nm("tffs (2)");
98 +       if (IS_ERR(tffs1) || IS_ERR(tffs2))
99 +               return -1;
100 +
101 +       tffs_index();
102 +
103 +       return 0;
104 +}
105 +late_initcall(tffs_init);
106 +