[kernel] refresh patches against 2.6.27 final
[openwrt.git] / target / linux / ixp4xx / patches-2.6.26 / 294-eeprom_new_notifier.patch
1 --- a/drivers/i2c/chips/eeprom.c
2 +++ b/drivers/i2c/chips/eeprom.c
3 @@ -33,6 +33,8 @@
4 #include <linux/jiffies.h>
5 #include <linux/i2c.h>
6 #include <linux/mutex.h>
7 +#include <linux/notifier.h>
8 +#include <linux/eeprom.h>
9
10 /* Addresses to scan */
11 static const unsigned short normal_i2c[] = { 0x50, 0x51, 0x52, 0x53, 0x54,
12 @@ -41,26 +43,7 @@
13 /* Insmod parameters */
14 I2C_CLIENT_INSMOD_1(eeprom);
15
16 -
17 -/* Size of EEPROM in bytes */
18 -#define EEPROM_SIZE 256
19 -
20 -/* possible types of eeprom devices */
21 -enum eeprom_nature {
22 - UNKNOWN,
23 - VAIO,
24 -};
25 -
26 -/* Each client has this additional data */
27 -struct eeprom_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;
34 -};
35 -
36 +ATOMIC_NOTIFIER_HEAD(eeprom_chain);
37
38 static int eeprom_attach_adapter(struct i2c_adapter *adapter);
39 static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind);
40 @@ -197,6 +180,7 @@
41 data->valid = 0;
42 mutex_init(&data->update_lock);
43 data->nature = UNKNOWN;
44 + data->attr = &eeprom_attr;
45
46 /* Tell the I2C layer a new client has arrived */
47 if ((err = i2c_attach_client(new_client)))
48 @@ -224,6 +208,9 @@
49 if (err)
50 goto exit_detach;
51
52 + /* call the notifier chain */
53 + atomic_notifier_call_chain(&eeprom_chain, EEPROM_REGISTER, data);
54 +
55 return 0;
56
57 exit_detach:
58 @@ -249,6 +236,41 @@
59 return 0;
60 }
61
62 +/**
63 + * register_eeprom_notifier - register a 'user' of EEPROM devices.
64 + * @nb: pointer to notifier info structure
65 + *
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.
71 + *
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
75 + * code!
76 + */
77 +int register_eeprom_notifier(struct notifier_block *nb)
78 +{
79 + return atomic_notifier_chain_register(&eeprom_chain, nb);
80 +}
81 +
82 +/**
83 + * unregister_eeprom_notifier - unregister a 'user' of EEPROM devices.
84 + * @old: pointer to notifier info structure
85 + *
86 + * Removes a callback function from the list of 'users' to be
87 + * notified upon detection of EEPROM devices.
88 + */
89 +int unregister_eeprom_notifier(struct notifier_block *nb)
90 +{
91 + return atomic_notifier_chain_unregister(&eeprom_chain, nb);
92 +}
93 +
94 +EXPORT_SYMBOL_GPL(register_eeprom_notifier);
95 +EXPORT_SYMBOL_GPL(unregister_eeprom_notifier);
96 +
97 static int __init eeprom_init(void)
98 {
99 return i2c_add_driver(&eeprom_driver);
100 --- /dev/null
101 +++ b/include/linux/eeprom.h
102 @@ -0,0 +1,71 @@
103 +#ifndef _LINUX_EEPROM_H
104 +#define _LINUX_EEPROM_H
105 +/*
106 + * EEPROM notifier header
107 + *
108 + * Copyright (C) 2006 John Bowler
109 + */
110 +
111 +/*
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.
116 + *
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.
121 + *
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
125 + */
126 +
127 +#ifndef __KERNEL__
128 +#error This is a kernel header
129 +#endif
130 +
131 +#include <linux/list.h>
132 +#include <linux/kobject.h>
133 +#include <linux/sysfs.h>
134 +
135 +/* Size of EEPROM in bytes */
136 +#define EEPROM_SIZE 256
137 +
138 +/* possible types of eeprom devices */
139 +enum eeprom_nature {
140 + UNKNOWN,
141 + VAIO,
142 +};
143 +
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;
153 +};
154 +
155 +/*
156 + * This is very basic.
157 + *
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.
164 + *
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).
168 + */
169 +
170 +extern int register_eeprom_notifier(struct notifier_block *nb);
171 +extern int unregister_eeprom_notifier(struct notifier_block *nb);
172 +
173 +#endif /* _LINUX_EEPROM_H */
174 --- a/include/linux/notifier.h
175 +++ b/include/linux/notifier.h
176 @@ -253,5 +253,8 @@
177 #define VT_UPDATE 0x0004 /* A bigger update occurred */
178 #define VT_PREWRITE 0x0005 /* A char is about to be written to the console */
179
180 +/* eeprom notifier chain */
181 +#define EEPROM_REGISTER 0x0001
182 +
183 #endif /* __KERNEL__ */
184 #endif /* _LINUX_NOTIFIER_H */
This page took 0.058092 seconds and 5 git commands to generate.