upgrade avr32 to 2.6.27
[openwrt.git] / target / linux / ixp4xx / patches-2.6.27 / 294-eeprom_new_notifier.patch
1 --- a/drivers/i2c/chips/eeprom.c
2 +++ b/drivers/i2c/chips/eeprom.c
3 @@ -27,6 +27,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 @@ -35,25 +37,7 @@ static const unsigned short normal_i2c[]
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 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;
33 -};
34 -
35 +ATOMIC_NOTIFIER_HEAD(eeprom_chain);
36
37 static void eeprom_update_client(struct i2c_client *client, u8 slice)
38 {
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;
44
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
48 if (err)
49 goto exit_kfree;
50
51 + /* call the notifier chain */
52 + atomic_notifier_call_chain(&eeprom_chain, EEPROM_REGISTER, data);
53 +
54 return 0;
55
56 exit_kfree:
57 @@ -236,6 +224,41 @@ static struct i2c_driver eeprom_driver =
58 .address_data = &addr_data,
59 };
60
61 +/**
62 + * register_eeprom_notifier - register a 'user' of EEPROM devices.
63 + * @nb: pointer to notifier info structure
64 + *
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.
70 + *
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
74 + * code!
75 + */
76 +int register_eeprom_notifier(struct notifier_block *nb)
77 +{
78 + return atomic_notifier_chain_register(&eeprom_chain, nb);
79 +}
80 +
81 +/**
82 + * unregister_eeprom_notifier - unregister a 'user' of EEPROM devices.
83 + * @old: pointer to notifier info structure
84 + *
85 + * Removes a callback function from the list of 'users' to be
86 + * notified upon detection of EEPROM devices.
87 + */
88 +int unregister_eeprom_notifier(struct notifier_block *nb)
89 +{
90 + return atomic_notifier_chain_unregister(&eeprom_chain, nb);
91 +}
92 +
93 +EXPORT_SYMBOL_GPL(register_eeprom_notifier);
94 +EXPORT_SYMBOL_GPL(unregister_eeprom_notifier);
95 +
96 static int __init eeprom_init(void)
97 {
98 return i2c_add_driver(&eeprom_driver);
99 --- /dev/null
100 +++ b/include/linux/eeprom.h
101 @@ -0,0 +1,71 @@
102 +#ifndef _LINUX_EEPROM_H
103 +#define _LINUX_EEPROM_H
104 +/*
105 + * EEPROM notifier header
106 + *
107 + * Copyright (C) 2006 John Bowler
108 + */
109 +
110 +/*
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.
115 + *
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.
120 + *
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
124 + */
125 +
126 +#ifndef __KERNEL__
127 +#error This is a kernel header
128 +#endif
129 +
130 +#include <linux/list.h>
131 +#include <linux/kobject.h>
132 +#include <linux/sysfs.h>
133 +
134 +/* Size of EEPROM in bytes */
135 +#define EEPROM_SIZE 256
136 +
137 +/* possible types of eeprom devices */
138 +enum eeprom_nature {
139 + UNKNOWN,
140 + VAIO,
141 +};
142 +
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;
152 +};
153 +
154 +/*
155 + * This is very basic.
156 + *
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.
163 + *
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).
167 + */
168 +
169 +extern int register_eeprom_notifier(struct notifier_block *nb);
170 +extern int unregister_eeprom_notifier(struct notifier_block *nb);
171 +
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 */
178
179 +/* eeprom notifier chain */
180 +#define EEPROM_REGISTER 0x0001
181 +
182 #endif /* __KERNEL__ */
183 #endif /* _LINUX_NOTIFIER_H */
This page took 0.054003 seconds and 5 git commands to generate.