1 Index: linux-2.6.24.7/drivers/i2c/chips/eeprom.c
2 ===================================================================
3 --- linux-2.6.24.7.orig/drivers/i2c/chips/eeprom.c
4 +++ linux-2.6.24.7/drivers/i2c/chips/eeprom.c
6 #include <linux/jiffies.h>
8 #include <linux/mutex.h>
9 +#include <linux/notifier.h>
10 +#include <linux/eeprom.h>
12 /* Addresses to scan */
13 static unsigned short normal_i2c[] = { 0x50, 0x51, 0x52, 0x53, 0x54,
14 @@ -41,26 +43,7 @@ static unsigned short normal_i2c[] = { 0
15 /* Insmod parameters */
16 I2C_CLIENT_INSMOD_1(eeprom);
19 -/* Size of EEPROM in bytes */
20 -#define EEPROM_SIZE 256
22 -/* possible types of eeprom devices */
28 -/* Each client has this additional data */
30 - struct i2c_client client;
31 - struct mutex update_lock;
32 - u8 valid; /* bitfield, bit!=0 if slice is valid */
33 - unsigned long last_updated[8]; /* In jiffies, 8 slices */
34 - u8 data[EEPROM_SIZE]; /* Register values */
35 - enum eeprom_nature nature;
38 +ATOMIC_NOTIFIER_HEAD(eeprom_chain);
40 static int eeprom_attach_adapter(struct i2c_adapter *adapter);
41 static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind);
42 @@ -198,6 +181,7 @@ static int eeprom_detect(struct i2c_adap
44 mutex_init(&data->update_lock);
45 data->nature = UNKNOWN;
46 + data->attr = &eeprom_attr;
48 /* Tell the I2C layer a new client has arrived */
49 if ((err = i2c_attach_client(new_client)))
50 @@ -225,6 +209,9 @@ static int eeprom_detect(struct i2c_adap
54 + /* call the notifier chain */
55 + atomic_notifier_call_chain(&eeprom_chain, EEPROM_REGISTER, data);
60 @@ -250,6 +237,41 @@ static int eeprom_detach_client(struct i
65 + * register_eeprom_notifier - register a 'user' of EEPROM devices.
66 + * @nb: pointer to notifier info structure
68 + * Registers a callback function to be called upon detection
69 + * of an EEPROM device. Detection invokes the 'add' callback
70 + * with the kobj of the mutex and a bin_attribute which allows
71 + * read from the EEPROM. The intention is that the notifier
72 + * will be able to read system configuration from the notifier.
74 + * Only EEPROMs detected *after* the addition of the notifier
75 + * are notified. I.e. EEPROMs already known to the system
76 + * will not be notified - add the notifier from board level
79 +int register_eeprom_notifier(struct notifier_block *nb)
81 + return atomic_notifier_chain_register(&eeprom_chain, nb);
85 + * unregister_eeprom_notifier - unregister a 'user' of EEPROM devices.
86 + * @old: pointer to notifier info structure
88 + * Removes a callback function from the list of 'users' to be
89 + * notified upon detection of EEPROM devices.
91 +int unregister_eeprom_notifier(struct notifier_block *nb)
93 + return atomic_notifier_chain_unregister(&eeprom_chain, nb);
96 +EXPORT_SYMBOL_GPL(register_eeprom_notifier);
97 +EXPORT_SYMBOL_GPL(unregister_eeprom_notifier);
99 static int __init eeprom_init(void)
101 return i2c_add_driver(&eeprom_driver);
102 Index: linux-2.6.24.7/include/linux/eeprom.h
103 ===================================================================
105 +++ linux-2.6.24.7/include/linux/eeprom.h
107 +#ifndef _LINUX_EEPROM_H
108 +#define _LINUX_EEPROM_H
110 + * EEPROM notifier header
112 + * Copyright (C) 2006 John Bowler
116 + * This program is free software; you can redistribute it and/or modify
117 + * it under the terms of the GNU General Public License as published by
118 + * the Free Software Foundation; either version 2 of the License, or
119 + * (at your option) any later version.
121 + * This program is distributed in the hope that it will be useful,
122 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
123 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
124 + * GNU General Public License for more details.
126 + * You should have received a copy of the GNU General Public License
127 + * along with this program; if not, write to the Free Software
128 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
132 +#error This is a kernel header
135 +#include <linux/list.h>
136 +#include <linux/kobject.h>
137 +#include <linux/sysfs.h>
139 +/* Size of EEPROM in bytes */
140 +#define EEPROM_SIZE 256
142 +/* possible types of eeprom devices */
143 +enum eeprom_nature {
148 +/* Each client has this additional data */
149 +struct eeprom_data {
150 + struct i2c_client client;
151 + struct mutex update_lock;
152 + u8 valid; /* bitfield, bit!=0 if slice is valid */
153 + unsigned long last_updated[8]; /* In jiffies, 8 slices */
154 + u8 data[EEPROM_SIZE]; /* Register values */
155 + enum eeprom_nature nature;
156 + struct bin_attribute *attr;
160 + * This is very basic.
162 + * If an EEPROM is detected on the I2C bus (this only works for
163 + * I2C EEPROMs) the notifier chain is called with
164 + * both the I2C information and the kobject for the sysfs
165 + * device which has been registers. It is then possible to
166 + * read from the device via the bin_attribute::read method
167 + * to extract configuration information.
169 + * Register the notifier in the board level code, there is no
170 + * need to unregister it but you can if you want (it will save
171 + * a little bit or kernel memory to do so).
174 +extern int register_eeprom_notifier(struct notifier_block *nb);
175 +extern int unregister_eeprom_notifier(struct notifier_block *nb);
177 +#endif /* _LINUX_EEPROM_H */
178 Index: linux-2.6.24.7/include/linux/notifier.h
179 ===================================================================
180 --- linux-2.6.24.7.orig/include/linux/notifier.h
181 +++ linux-2.6.24.7/include/linux/notifier.h
182 @@ -248,5 +248,8 @@ extern struct blocking_notifier_head reb
183 #define VT_WRITE 0x0003 /* A char got output */
184 #define VT_UPDATE 0x0004 /* A bigger update occurred */
186 +/* eeprom notifier chain */
187 +#define EEPROM_REGISTER 0x0001
189 #endif /* __KERNEL__ */
190 #endif /* _LINUX_NOTIFIER_H */