3 These help board level code by allowing a callback when EEPROMs are
4 loaded, this permits system level configuration to be loaded from the
5 EEPROM. This is particularly useful when the ethernet MAC ids are
6 stored in EEPROM and when the ethernet hardware is generic (so it
7 has no board level knowledge), then the MACs can be loaded into
8 the 'maclist' code and read out by the ethernet config.
10 Signed-off-by: John Bowler <jbowler@acm.org>
12 Index: linux-2.6.21.7/drivers/i2c/chips/eeprom.c
13 ===================================================================
14 --- linux-2.6.21.7.orig/drivers/i2c/chips/eeprom.c
15 +++ linux-2.6.21.7/drivers/i2c/chips/eeprom.c
17 #include <linux/jiffies.h>
18 #include <linux/i2c.h>
19 #include <linux/mutex.h>
20 +#include <linux/notifier.h>
21 +#include <linux/eeprom.h>
23 /* Addresses to scan */
24 static unsigned short normal_i2c[] = { 0x50, 0x51, 0x52, 0x53, 0x54,
25 @@ -41,26 +43,7 @@ static unsigned short normal_i2c[] = { 0
26 /* Insmod parameters */
27 I2C_CLIENT_INSMOD_1(eeprom);
30 -/* Size of EEPROM in bytes */
31 -#define EEPROM_SIZE 256
33 -/* possible types of eeprom devices */
39 -/* Each client has this additional data */
41 - struct i2c_client client;
42 - struct mutex update_lock;
43 - u8 valid; /* bitfield, bit!=0 if slice is valid */
44 - unsigned long last_updated[8]; /* In jiffies, 8 slices */
45 - u8 data[EEPROM_SIZE]; /* Register values */
46 - enum eeprom_nature nature;
49 +ATOMIC_NOTIFIER_HEAD(eeprom_chain);
51 static int eeprom_attach_adapter(struct i2c_adapter *adapter);
52 static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind);
53 @@ -189,6 +172,7 @@ static int eeprom_detect(struct i2c_adap
55 mutex_init(&data->update_lock);
56 data->nature = UNKNOWN;
57 + data->attr = &eeprom_attr;
59 /* Tell the I2C layer a new client has arrived */
60 if ((err = i2c_attach_client(new_client)))
61 @@ -212,6 +196,9 @@ static int eeprom_detect(struct i2c_adap
65 + /* call the notifier chain */
66 + atomic_notifier_call_chain(&eeprom_chain, EEPROM_REGISTER, data);
71 @@ -237,6 +224,41 @@ static int eeprom_detach_client(struct i
76 + * register_eeprom_notifier - register a 'user' of EEPROM devices.
77 + * @nb: pointer to notifier info structure
79 + * Registers a callback function to be called upon detection
80 + * of an EEPROM device. Detection invokes the 'add' callback
81 + * with the kobj of the mutex and a bin_attribute which allows
82 + * read from the EEPROM. The intention is that the notifier
83 + * will be able to read system configuration from the notifier.
85 + * Only EEPROMs detected *after* the addition of the notifier
86 + * are notified. I.e. EEPROMs already known to the system
87 + * will not be notified - add the notifier from board level
90 +int register_eeprom_notifier(struct notifier_block *nb)
92 + return atomic_notifier_chain_register(&eeprom_chain, nb);
96 + * unregister_eeprom_notifier - unregister a 'user' of EEPROM devices.
97 + * @old: pointer to notifier info structure
99 + * Removes a callback function from the list of 'users' to be
100 + * notified upon detection of EEPROM devices.
102 +int unregister_eeprom_notifier(struct notifier_block *nb)
104 + return atomic_notifier_chain_unregister(&eeprom_chain, nb);
107 +EXPORT_SYMBOL_GPL(register_eeprom_notifier);
108 +EXPORT_SYMBOL_GPL(unregister_eeprom_notifier);
110 static int __init eeprom_init(void)
112 return i2c_add_driver(&eeprom_driver);
113 Index: linux-2.6.21.7/include/linux/eeprom.h
114 ===================================================================
116 +++ linux-2.6.21.7/include/linux/eeprom.h
118 +#ifndef _LINUX_EEPROM_H
119 +#define _LINUX_EEPROM_H
121 + * $Id: 45-eeprom-new-notifier.patch,v 1.2 2006/03/27 11:10:19 azummo Exp $
123 + * Copyright (C) 2006 John Bowler
127 + * This program is free software; you can redistribute it and/or modify
128 + * it under the terms of the GNU General Public License as published by
129 + * the Free Software Foundation; either version 2 of the License, or
130 + * (at your option) any later version.
132 + * This program is distributed in the hope that it will be useful,
133 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
134 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
135 + * GNU General Public License for more details.
137 + * You should have received a copy of the GNU General Public License
138 + * along with this program; if not, write to the Free Software
139 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
143 +#error This is a kernel header
146 +#include <linux/list.h>
147 +#include <linux/kobject.h>
148 +#include <linux/sysfs.h>
150 +/* Size of EEPROM in bytes */
151 +#define EEPROM_SIZE 256
153 +/* possible types of eeprom devices */
154 +enum eeprom_nature {
159 +/* Each client has this additional data */
160 +struct eeprom_data {
161 + struct i2c_client client;
162 + struct mutex update_lock;
163 + u8 valid; /* bitfield, bit!=0 if slice is valid */
164 + unsigned long last_updated[8]; /* In jiffies, 8 slices */
165 + u8 data[EEPROM_SIZE]; /* Register values */
166 + enum eeprom_nature nature;
167 + struct bin_attribute *attr;
171 + * This is very basic.
173 + * If an EEPROM is detected on the I2C bus (this only works for
174 + * I2C EEPROMs) the notifier chain is called with
175 + * both the I2C information and the kobject for the sysfs
176 + * device which has been registers. It is then possible to
177 + * read from the device via the bin_attribute::read method
178 + * to extract configuration information.
180 + * Register the notifier in the board level code, there is no
181 + * need to unregister it but you can if you want (it will save
182 + * a little bit or kernel memory to do so).
185 +extern int register_eeprom_notifier(struct notifier_block *nb);
186 +extern int unregister_eeprom_notifier(struct notifier_block *nb);
188 +#endif /* _LINUX_EEPROM_H */
189 Index: linux-2.6.21.7/include/linux/notifier.h
190 ===================================================================
191 --- linux-2.6.21.7.orig/include/linux/notifier.h
192 +++ linux-2.6.21.7/include/linux/notifier.h
193 @@ -187,5 +187,8 @@ extern int srcu_notifier_call_chain(stru
194 #define CPU_DOWN_FAILED 0x0006 /* CPU (unsigned)v NOT going down */
195 #define CPU_DEAD 0x0007 /* CPU (unsigned)v dead */
197 +/* eeprom notifier chain */
198 +#define EEPROM_REGISTER 0x0001
200 #endif /* __KERNEL__ */
201 #endif /* _LINUX_NOTIFIER_H */