[kernel] fix mini_fo on 2.6.26-rc4
[openwrt.git] / target / linux / ixp4xx / patches-2.6.23 / 294-eeprom_new_notifier.patch
1 Index: linux-2.6.23.17/drivers/i2c/chips/eeprom.c
2 ===================================================================
3 --- linux-2.6.23.17.orig/drivers/i2c/chips/eeprom.c
4 +++ linux-2.6.23.17/drivers/i2c/chips/eeprom.c
5 @@ -33,6 +33,8 @@
6 #include <linux/jiffies.h>
7 #include <linux/i2c.h>
8 #include <linux/mutex.h>
9 +#include <linux/notifier.h>
10 +#include <linux/eeprom.h>
11
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);
17
18 -
19 -/* Size of EEPROM in bytes */
20 -#define EEPROM_SIZE 256
21 -
22 -/* possible types of eeprom devices */
23 -enum eeprom_nature {
24 - UNKNOWN,
25 - VAIO,
26 -};
27 -
28 -/* Each client has this additional data */
29 -struct eeprom_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;
36 -};
37 -
38 +ATOMIC_NOTIFIER_HEAD(eeprom_chain);
39
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
43 data->valid = 0;
44 mutex_init(&data->update_lock);
45 data->nature = UNKNOWN;
46 + data->attr = &eeprom_attr;
47
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
51 if (err)
52 goto exit_detach;
53
54 + /* call the notifier chain */
55 + atomic_notifier_call_chain(&eeprom_chain, EEPROM_REGISTER, data);
56 +
57 return 0;
58
59 exit_detach:
60 @@ -250,6 +237,41 @@ static int eeprom_detach_client(struct i
61 return 0;
62 }
63
64 +/**
65 + * register_eeprom_notifier - register a 'user' of EEPROM devices.
66 + * @nb: pointer to notifier info structure
67 + *
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.
73 + *
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
77 + * code!
78 + */
79 +int register_eeprom_notifier(struct notifier_block *nb)
80 +{
81 + return atomic_notifier_chain_register(&eeprom_chain, nb);
82 +}
83 +
84 +/**
85 + * unregister_eeprom_notifier - unregister a 'user' of EEPROM devices.
86 + * @old: pointer to notifier info structure
87 + *
88 + * Removes a callback function from the list of 'users' to be
89 + * notified upon detection of EEPROM devices.
90 + */
91 +int unregister_eeprom_notifier(struct notifier_block *nb)
92 +{
93 + return atomic_notifier_chain_unregister(&eeprom_chain, nb);
94 +}
95 +
96 +EXPORT_SYMBOL_GPL(register_eeprom_notifier);
97 +EXPORT_SYMBOL_GPL(unregister_eeprom_notifier);
98 +
99 static int __init eeprom_init(void)
100 {
101 return i2c_add_driver(&eeprom_driver);
102 Index: linux-2.6.23.17/include/linux/eeprom.h
103 ===================================================================
104 --- /dev/null
105 +++ linux-2.6.23.17/include/linux/eeprom.h
106 @@ -0,0 +1,71 @@
107 +#ifndef _LINUX_EEPROM_H
108 +#define _LINUX_EEPROM_H
109 +/*
110 + * EEPROM notifier header
111 + *
112 + * Copyright (C) 2006 John Bowler
113 + */
114 +
115 +/*
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.
120 + *
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.
125 + *
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
129 + */
130 +
131 +#ifndef __KERNEL__
132 +#error This is a kernel header
133 +#endif
134 +
135 +#include <linux/list.h>
136 +#include <linux/kobject.h>
137 +#include <linux/sysfs.h>
138 +
139 +/* Size of EEPROM in bytes */
140 +#define EEPROM_SIZE 256
141 +
142 +/* possible types of eeprom devices */
143 +enum eeprom_nature {
144 + UNKNOWN,
145 + VAIO,
146 +};
147 +
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;
157 +};
158 +
159 +/*
160 + * This is very basic.
161 + *
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.
168 + *
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).
172 + */
173 +
174 +extern int register_eeprom_notifier(struct notifier_block *nb);
175 +extern int unregister_eeprom_notifier(struct notifier_block *nb);
176 +
177 +#endif /* _LINUX_EEPROM_H */
178 Index: linux-2.6.23.17/include/linux/notifier.h
179 ===================================================================
180 --- linux-2.6.23.17.orig/include/linux/notifier.h
181 +++ linux-2.6.23.17/include/linux/notifier.h
182 @@ -231,5 +231,8 @@ static inline int notifier_to_errno(int
183 #define PM_SUSPEND_PREPARE 0x0003 /* Going to suspend the system */
184 #define PM_POST_SUSPEND 0x0004 /* Suspend finished */
185
186 +/* eeprom notifier chain */
187 +#define EEPROM_REGISTER 0x0001
188 +
189 #endif /* __KERNEL__ */
190 #endif /* _LINUX_NOTIFIER_H */
This page took 0.0656 seconds and 5 git commands to generate.