1 --- a/drivers/i2c/chips/eeprom.c
2 +++ b/drivers/i2c/chips/eeprom.c
4 #include <linux/jiffies.h>
6 #include <linux/mutex.h>
7 +#include <linux/notifier.h>
8 +#include <linux/eeprom.h>
10 /* Addresses to scan */
11 static const unsigned short normal_i2c[] = { 0x50, 0x51, 0x52, 0x53, 0x54,
13 /* Insmod parameters */
14 I2C_CLIENT_INSMOD_1(eeprom);
17 -/* Size of EEPROM in bytes */
18 -#define EEPROM_SIZE 256
20 -/* possible types of eeprom devices */
26 -/* Each client has this additional data */
28 - struct i2c_client client;
29 - struct mutex update_lock;
30 - u8 valid; /* bitfield, bit!=0 if slice is valid */
31 - unsigned long last_updated[8]; /* In jiffies, 8 slices */
32 - u8 data[EEPROM_SIZE]; /* Register values */
33 - enum eeprom_nature nature;
36 +ATOMIC_NOTIFIER_HEAD(eeprom_chain);
38 static int eeprom_attach_adapter(struct i2c_adapter *adapter);
39 static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind);
42 mutex_init(&data->update_lock);
43 data->nature = UNKNOWN;
44 + data->attr = &eeprom_attr;
46 /* Tell the I2C layer a new client has arrived */
47 if ((err = i2c_attach_client(new_client)))
52 + /* call the notifier chain */
53 + atomic_notifier_call_chain(&eeprom_chain, EEPROM_REGISTER, data);
63 + * register_eeprom_notifier - register a 'user' of EEPROM devices.
64 + * @nb: pointer to notifier info structure
66 + * Registers a callback function to be called upon detection
67 + * of an EEPROM device. Detection invokes the 'add' callback
68 + * with the kobj of the mutex and a bin_attribute which allows
69 + * read from the EEPROM. The intention is that the notifier
70 + * will be able to read system configuration from the notifier.
72 + * Only EEPROMs detected *after* the addition of the notifier
73 + * are notified. I.e. EEPROMs already known to the system
74 + * will not be notified - add the notifier from board level
77 +int register_eeprom_notifier(struct notifier_block *nb)
79 + return atomic_notifier_chain_register(&eeprom_chain, nb);
83 + * unregister_eeprom_notifier - unregister a 'user' of EEPROM devices.
84 + * @old: pointer to notifier info structure
86 + * Removes a callback function from the list of 'users' to be
87 + * notified upon detection of EEPROM devices.
89 +int unregister_eeprom_notifier(struct notifier_block *nb)
91 + return atomic_notifier_chain_unregister(&eeprom_chain, nb);
94 +EXPORT_SYMBOL_GPL(register_eeprom_notifier);
95 +EXPORT_SYMBOL_GPL(unregister_eeprom_notifier);
97 static int __init eeprom_init(void)
99 return i2c_add_driver(&eeprom_driver);
101 +++ b/include/linux/eeprom.h
103 +#ifndef _LINUX_EEPROM_H
104 +#define _LINUX_EEPROM_H
106 + * EEPROM notifier header
108 + * Copyright (C) 2006 John Bowler
112 + * This program is free software; you can redistribute it and/or modify
113 + * it under the terms of the GNU General Public License as published by
114 + * the Free Software Foundation; either version 2 of the License, or
115 + * (at your option) any later version.
117 + * This program is distributed in the hope that it will be useful,
118 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
119 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
120 + * GNU General Public License for more details.
122 + * You should have received a copy of the GNU General Public License
123 + * along with this program; if not, write to the Free Software
124 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
128 +#error This is a kernel header
131 +#include <linux/list.h>
132 +#include <linux/kobject.h>
133 +#include <linux/sysfs.h>
135 +/* Size of EEPROM in bytes */
136 +#define EEPROM_SIZE 256
138 +/* possible types of eeprom devices */
139 +enum eeprom_nature {
144 +/* Each client has this additional data */
145 +struct eeprom_data {
146 + struct i2c_client client;
147 + struct mutex update_lock;
148 + u8 valid; /* bitfield, bit!=0 if slice is valid */
149 + unsigned long last_updated[8]; /* In jiffies, 8 slices */
150 + u8 data[EEPROM_SIZE]; /* Register values */
151 + enum eeprom_nature nature;
152 + struct bin_attribute *attr;
156 + * This is very basic.
158 + * If an EEPROM is detected on the I2C bus (this only works for
159 + * I2C EEPROMs) the notifier chain is called with
160 + * both the I2C information and the kobject for the sysfs
161 + * device which has been registers. It is then possible to
162 + * read from the device via the bin_attribute::read method
163 + * to extract configuration information.
165 + * Register the notifier in the board level code, there is no
166 + * need to unregister it but you can if you want (it will save
167 + * a little bit or kernel memory to do so).
170 +extern int register_eeprom_notifier(struct notifier_block *nb);
171 +extern int unregister_eeprom_notifier(struct notifier_block *nb);
173 +#endif /* _LINUX_EEPROM_H */
174 --- a/include/linux/notifier.h
175 +++ b/include/linux/notifier.h
177 #define VT_WRITE 0x0003 /* A char got output */
178 #define VT_UPDATE 0x0004 /* A bigger update occurred */
180 +/* eeprom notifier chain */
181 +#define EEPROM_REGISTER 0x0001
183 #endif /* __KERNEL__ */
184 #endif /* _LINUX_NOTIFIER_H */