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,
12 @@ -35,25 +37,7 @@ static const unsigned short normal_i2c[]
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 mutex update_lock;
29 - u8 valid; /* bitfield, bit!=0 if slice is valid */
30 - unsigned long last_updated[8]; /* In jiffies, 8 slices */
31 - u8 data[EEPROM_SIZE]; /* Register values */
32 - enum eeprom_nature nature;
35 +ATOMIC_NOTIFIER_HEAD(eeprom_chain);
37 static void eeprom_update_client(struct i2c_client *client, u8 slice)
39 @@ -178,6 +162,7 @@ static int eeprom_probe(struct i2c_clien
40 i2c_set_clientdata(client, data);
41 mutex_init(&data->update_lock);
42 data->nature = UNKNOWN;
43 + data->attr = &eeprom_attr;
45 /* Detect the Vaio nature of EEPROMs.
46 We use the "PCG-" or "VGN-" prefix as the signature. */
47 @@ -202,6 +187,9 @@ static int eeprom_probe(struct i2c_clien
51 + /* call the notifier chain */
52 + atomic_notifier_call_chain(&eeprom_chain, EEPROM_REGISTER, data);
57 @@ -236,6 +224,41 @@ static struct i2c_driver eeprom_driver =
58 .address_data = &addr_data,
62 + * register_eeprom_notifier - register a 'user' of EEPROM devices.
63 + * @nb: pointer to notifier info structure
65 + * Registers a callback function to be called upon detection
66 + * of an EEPROM device. Detection invokes the 'add' callback
67 + * with the kobj of the mutex and a bin_attribute which allows
68 + * read from the EEPROM. The intention is that the notifier
69 + * will be able to read system configuration from the notifier.
71 + * Only EEPROMs detected *after* the addition of the notifier
72 + * are notified. I.e. EEPROMs already known to the system
73 + * will not be notified - add the notifier from board level
76 +int register_eeprom_notifier(struct notifier_block *nb)
78 + return atomic_notifier_chain_register(&eeprom_chain, nb);
82 + * unregister_eeprom_notifier - unregister a 'user' of EEPROM devices.
83 + * @old: pointer to notifier info structure
85 + * Removes a callback function from the list of 'users' to be
86 + * notified upon detection of EEPROM devices.
88 +int unregister_eeprom_notifier(struct notifier_block *nb)
90 + return atomic_notifier_chain_unregister(&eeprom_chain, nb);
93 +EXPORT_SYMBOL_GPL(register_eeprom_notifier);
94 +EXPORT_SYMBOL_GPL(unregister_eeprom_notifier);
96 static int __init eeprom_init(void)
98 return i2c_add_driver(&eeprom_driver);
100 +++ b/include/linux/eeprom.h
102 +#ifndef _LINUX_EEPROM_H
103 +#define _LINUX_EEPROM_H
105 + * EEPROM notifier header
107 + * Copyright (C) 2006 John Bowler
111 + * This program is free software; you can redistribute it and/or modify
112 + * it under the terms of the GNU General Public License as published by
113 + * the Free Software Foundation; either version 2 of the License, or
114 + * (at your option) any later version.
116 + * This program is distributed in the hope that it will be useful,
117 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
118 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
119 + * GNU General Public License for more details.
121 + * You should have received a copy of the GNU General Public License
122 + * along with this program; if not, write to the Free Software
123 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
127 +#error This is a kernel header
130 +#include <linux/list.h>
131 +#include <linux/kobject.h>
132 +#include <linux/sysfs.h>
134 +/* Size of EEPROM in bytes */
135 +#define EEPROM_SIZE 256
137 +/* possible types of eeprom devices */
138 +enum eeprom_nature {
143 +/* Each client has this additional data */
144 +struct eeprom_data {
145 + struct i2c_client client;
146 + struct mutex update_lock;
147 + u8 valid; /* bitfield, bit!=0 if slice is valid */
148 + unsigned long last_updated[8]; /* In jiffies, 8 slices */
149 + u8 data[EEPROM_SIZE]; /* Register values */
150 + enum eeprom_nature nature;
151 + struct bin_attribute *attr;
155 + * This is very basic.
157 + * If an EEPROM is detected on the I2C bus (this only works for
158 + * I2C EEPROMs) the notifier chain is called with
159 + * both the I2C information and the kobject for the sysfs
160 + * device which has been registers. It is then possible to
161 + * read from the device via the bin_attribute::read method
162 + * to extract configuration information.
164 + * Register the notifier in the board level code, there is no
165 + * need to unregister it but you can if you want (it will save
166 + * a little bit or kernel memory to do so).
169 +extern int register_eeprom_notifier(struct notifier_block *nb);
170 +extern int unregister_eeprom_notifier(struct notifier_block *nb);
172 +#endif /* _LINUX_EEPROM_H */
173 --- a/include/linux/notifier.h
174 +++ b/include/linux/notifier.h
175 @@ -256,5 +256,8 @@ extern struct blocking_notifier_head reb
176 #define VT_UPDATE 0x0004 /* A bigger update occurred */
177 #define VT_PREWRITE 0x0005 /* A char is about to be written to the console */
179 +/* eeprom notifier chain */
180 +#define EEPROM_REGISTER 0x0001
182 #endif /* __KERNEL__ */
183 #endif /* _LINUX_NOTIFIER_H */