summaryrefslogtreecommitdiff
path: root/recipes-kernel/linux/linux-3.19/mtcdt/linux-3.19-eeprom-setup-mtcdt.patch
blob: 349f0da35fe206ae97c126e4356f97b67408c792 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
Index: linux-3.18-rc3/arch/arm/mach-at91/board-dt-sam9.c
===================================================================
--- linux-3.18-rc3.orig/arch/arm/mach-at91/board-dt-sam9.c	2014-11-02 17:01:51.000000000 -0600
+++ linux-3.18-rc3/arch/arm/mach-at91/board-dt-sam9.c	2014-11-03 15:27:22.831959257 -0600
@@ -25,6 +25,87 @@
 #include "board.h"
 #include "generic.h"
 
+#include <linux/mts_at24.h>
+
+uint8_t mts_id_eeprom[512];
+
+EXPORT_SYMBOL(mts_id_eeprom);
+
+static void mts_id_eeprom_load(struct memory_accessor *macc, void *context)
+{
+	int tmp;
+
+	memset(mts_id_eeprom, 0, sizeof(mts_id_eeprom));
+
+	tmp = macc->read(macc, mts_id_eeprom, 0, sizeof(mts_id_eeprom));
+	if (tmp != sizeof(mts_id_eeprom)) {
+		printk(KERN_ERR "sam9x5: id eeprom read failed: %d\n", tmp);
+	} else {
+		printk(KERN_INFO "sam9x5: read %d bytes from id eeprom\n", tmp);
+	}
+}
+
+struct mts_eeprom_callback id_eeprom_callback = {
+	.address = 0x56,
+	.index = -1,
+	.setup = mts_id_eeprom_load,
+};
+
+#ifdef CONFIG_MTS_NUM_ACCESSORY_PORTS
+#define NUM_AP CONFIG_MTS_NUM_ACCESSORY_PORTS
+#else
+#define NUM_AP 0
+#endif
+
+#if NUM_AP > 0
+
+uint8_t mts_ap_eeprom[NUM_AP][512];
+
+EXPORT_SYMBOL(mts_ap_eeprom);
+
+static void mts_ap_eeprom_load(struct memory_accessor *macc, void *context)
+{
+	int tmp;
+	int* index = (int*)context;
+
+	memset(mts_ap_eeprom[*index], 0, sizeof(mts_ap_eeprom[*index]));
+
+	tmp = macc->read(macc, mts_ap_eeprom[*index], 0, sizeof(mts_ap_eeprom[*index]));
+	if (tmp != sizeof(mts_ap_eeprom[*index])) {
+		printk(KERN_INFO "sam9x5: ap%d eeprom read failed: %d\n", *index + 1, tmp);
+	} else {
+		printk(KERN_INFO "sam9x5: read %d bytes from ap%d eeprom\n", tmp, *index + 1);
+	}
+}
+
+struct mts_eeprom_callback ap1_eeprom_callback = {
+	.address = 0x50,
+	.index = 0,
+	.setup = mts_ap_eeprom_load,
+};
+
+struct mts_eeprom_callback ap2_eeprom_callback = {
+	.address = 0x52,
+	.index = 1,
+	.setup = mts_ap_eeprom_load,
+};
+
+struct mts_eeprom_callback* mts_eeprom_callback_lookup[] = {
+	&id_eeprom_callback,
+	&ap1_eeprom_callback,
+	&ap2_eeprom_callback,
+	NULL
+};
+
+#else
+
+struct mts_eeprom_callback* mts_eeprom_callback_lookup[] = {
+	&id_eeprom_callback,
+	NULL
+};
+
+#endif
+
 static const char *at91_dt_board_compat[] __initdata = {
 	"atmel,at91sam9",
 	NULL
Index: linux-3.18-rc3/drivers/misc/eeprom/at24.c
===================================================================
--- linux-3.18-rc3.orig/drivers/misc/eeprom/at24.c	2014-11-02 17:01:51.000000000 -0600
+++ linux-3.18-rc3/drivers/misc/eeprom/at24.c	2014-11-03 15:30:11.867964508 -0600
@@ -24,6 +24,8 @@
 #include <linux/i2c.h>
 #include <linux/platform_data/at24.h>
 
+#include <linux/mts_at24.h>
+
 /*
  * I2C EEPROMs from most vendors are inexpensive and mostly interchangeable.
  * Differences between different vendor product lines (like Atmel AT24C or
@@ -476,6 +478,23 @@
 			chip->page_size = be32_to_cpup(val);
 	}
 }
+
+static void at24_get_setup(struct i2c_client *client,
+		struct at24_platform_data *chip)
+{
+	int i;
+
+	for (i = 0; mts_eeprom_callback_lookup[i] != NULL; i++) {
+		if (mts_eeprom_callback_lookup[i]->address == client->addr) {
+			printk(KERN_INFO "%s: found a match for eeprom at %X\n", __func__, client->addr);
+			chip->setup = mts_eeprom_callback_lookup[i]->setup;
+			if (mts_eeprom_callback_lookup[i]->index > -1) {
+				chip->context = (void*)&mts_eeprom_callback_lookup[i]->index;
+			}
+			break;
+		}
+	}
+}
 #else
 static void at24_get_ofdata(struct i2c_client *client,
 		struct at24_platform_data *chip)
@@ -508,12 +527,14 @@
 		 * is recommended anyhow.
 		 */
 		chip.page_size = 1;
+		chip.setup = NULL;
+		chip.context = NULL;
 
 		/* update chipdata if OF is present */
 		at24_get_ofdata(client, &chip);
 
-		chip.setup = NULL;
-		chip.context = NULL;
+		/* see if we have a setup callback */
+		at24_get_setup(client, &chip);
 	}
 
 	if (!is_power_of_2(chip.byte_len))
Index: linux-3.18-rc3/include/linux/mts_at24.h
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-3.18-rc3/include/linux/mts_at24.h	2014-11-03 15:30:46.051965569 -0600
@@ -0,0 +1,14 @@
+#ifndef _LINUX_MTSAT24_H
+#define _LINUX_MTSAT24_H
+
+#include <linux/memory.h>
+
+struct mts_eeprom_callback {
+    unsigned short      address;
+    int         index;
+    void       (*setup)(struct memory_accessor *, void *context);
+};
+
+extern struct mts_eeprom_callback* mts_eeprom_callback_lookup[];
+
+#endif /* _LINUX_MTSAT24_H */