diff options
286 files changed, 26558 insertions, 6895 deletions
diff --git a/Documentation/ABI/testing/sysfs-class-regulator b/Documentation/ABI/testing/sysfs-class-regulator index 79a4a75b2d2c..3731f6f29bcb 100644 --- a/Documentation/ABI/testing/sysfs-class-regulator +++ b/Documentation/ABI/testing/sysfs-class-regulator | |||
@@ -1,7 +1,7 @@ | |||
1 | What: /sys/class/regulator/.../state | 1 | What: /sys/class/regulator/.../state |
2 | Date: April 2008 | 2 | Date: April 2008 |
3 | KernelVersion: 2.6.26 | 3 | KernelVersion: 2.6.26 |
4 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | 4 | Contact: Liam Girdwood <lrg@slimlogic.co.uk> |
5 | Description: | 5 | Description: |
6 | Each regulator directory will contain a field called | 6 | Each regulator directory will contain a field called |
7 | state. This holds the regulator output state. | 7 | state. This holds the regulator output state. |
@@ -27,7 +27,7 @@ Description: | |||
27 | What: /sys/class/regulator/.../type | 27 | What: /sys/class/regulator/.../type |
28 | Date: April 2008 | 28 | Date: April 2008 |
29 | KernelVersion: 2.6.26 | 29 | KernelVersion: 2.6.26 |
30 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | 30 | Contact: Liam Girdwood <lrg@slimlogic.co.uk> |
31 | Description: | 31 | Description: |
32 | Each regulator directory will contain a field called | 32 | Each regulator directory will contain a field called |
33 | type. This holds the regulator type. | 33 | type. This holds the regulator type. |
@@ -51,7 +51,7 @@ Description: | |||
51 | What: /sys/class/regulator/.../microvolts | 51 | What: /sys/class/regulator/.../microvolts |
52 | Date: April 2008 | 52 | Date: April 2008 |
53 | KernelVersion: 2.6.26 | 53 | KernelVersion: 2.6.26 |
54 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | 54 | Contact: Liam Girdwood <lrg@slimlogic.co.uk> |
55 | Description: | 55 | Description: |
56 | Each regulator directory will contain a field called | 56 | Each regulator directory will contain a field called |
57 | microvolts. This holds the regulator output voltage setting | 57 | microvolts. This holds the regulator output voltage setting |
@@ -65,7 +65,7 @@ Description: | |||
65 | What: /sys/class/regulator/.../microamps | 65 | What: /sys/class/regulator/.../microamps |
66 | Date: April 2008 | 66 | Date: April 2008 |
67 | KernelVersion: 2.6.26 | 67 | KernelVersion: 2.6.26 |
68 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | 68 | Contact: Liam Girdwood <lrg@slimlogic.co.uk> |
69 | Description: | 69 | Description: |
70 | Each regulator directory will contain a field called | 70 | Each regulator directory will contain a field called |
71 | microamps. This holds the regulator output current limit | 71 | microamps. This holds the regulator output current limit |
@@ -79,7 +79,7 @@ Description: | |||
79 | What: /sys/class/regulator/.../opmode | 79 | What: /sys/class/regulator/.../opmode |
80 | Date: April 2008 | 80 | Date: April 2008 |
81 | KernelVersion: 2.6.26 | 81 | KernelVersion: 2.6.26 |
82 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | 82 | Contact: Liam Girdwood <lrg@slimlogic.co.uk> |
83 | Description: | 83 | Description: |
84 | Each regulator directory will contain a field called | 84 | Each regulator directory will contain a field called |
85 | opmode. This holds the regulator operating mode setting. | 85 | opmode. This holds the regulator operating mode setting. |
@@ -102,7 +102,7 @@ Description: | |||
102 | What: /sys/class/regulator/.../min_microvolts | 102 | What: /sys/class/regulator/.../min_microvolts |
103 | Date: April 2008 | 103 | Date: April 2008 |
104 | KernelVersion: 2.6.26 | 104 | KernelVersion: 2.6.26 |
105 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | 105 | Contact: Liam Girdwood <lrg@slimlogic.co.uk> |
106 | Description: | 106 | Description: |
107 | Each regulator directory will contain a field called | 107 | Each regulator directory will contain a field called |
108 | min_microvolts. This holds the minimum safe working regulator | 108 | min_microvolts. This holds the minimum safe working regulator |
@@ -116,7 +116,7 @@ Description: | |||
116 | What: /sys/class/regulator/.../max_microvolts | 116 | What: /sys/class/regulator/.../max_microvolts |
117 | Date: April 2008 | 117 | Date: April 2008 |
118 | KernelVersion: 2.6.26 | 118 | KernelVersion: 2.6.26 |
119 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | 119 | Contact: Liam Girdwood <lrg@slimlogic.co.uk> |
120 | Description: | 120 | Description: |
121 | Each regulator directory will contain a field called | 121 | Each regulator directory will contain a field called |
122 | max_microvolts. This holds the maximum safe working regulator | 122 | max_microvolts. This holds the maximum safe working regulator |
@@ -130,7 +130,7 @@ Description: | |||
130 | What: /sys/class/regulator/.../min_microamps | 130 | What: /sys/class/regulator/.../min_microamps |
131 | Date: April 2008 | 131 | Date: April 2008 |
132 | KernelVersion: 2.6.26 | 132 | KernelVersion: 2.6.26 |
133 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | 133 | Contact: Liam Girdwood <lrg@slimlogic.co.uk> |
134 | Description: | 134 | Description: |
135 | Each regulator directory will contain a field called | 135 | Each regulator directory will contain a field called |
136 | min_microamps. This holds the minimum safe working regulator | 136 | min_microamps. This holds the minimum safe working regulator |
@@ -145,7 +145,7 @@ Description: | |||
145 | What: /sys/class/regulator/.../max_microamps | 145 | What: /sys/class/regulator/.../max_microamps |
146 | Date: April 2008 | 146 | Date: April 2008 |
147 | KernelVersion: 2.6.26 | 147 | KernelVersion: 2.6.26 |
148 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | 148 | Contact: Liam Girdwood <lrg@slimlogic.co.uk> |
149 | Description: | 149 | Description: |
150 | Each regulator directory will contain a field called | 150 | Each regulator directory will contain a field called |
151 | max_microamps. This holds the maximum safe working regulator | 151 | max_microamps. This holds the maximum safe working regulator |
@@ -157,10 +157,23 @@ Description: | |||
157 | platform code. | 157 | platform code. |
158 | 158 | ||
159 | 159 | ||
160 | What: /sys/class/regulator/.../name | ||
161 | Date: October 2008 | ||
162 | KernelVersion: 2.6.28 | ||
163 | Contact: Liam Girdwood <lrg@slimlogic.co.uk> | ||
164 | Description: | ||
165 | Each regulator directory will contain a field called | ||
166 | name. This holds a string identifying the regulator for | ||
167 | display purposes. | ||
168 | |||
169 | NOTE: this will be empty if no suitable name is provided | ||
170 | by platform or regulator drivers. | ||
171 | |||
172 | |||
160 | What: /sys/class/regulator/.../num_users | 173 | What: /sys/class/regulator/.../num_users |
161 | Date: April 2008 | 174 | Date: April 2008 |
162 | KernelVersion: 2.6.26 | 175 | KernelVersion: 2.6.26 |
163 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | 176 | Contact: Liam Girdwood <lrg@slimlogic.co.uk> |
164 | Description: | 177 | Description: |
165 | Each regulator directory will contain a field called | 178 | Each regulator directory will contain a field called |
166 | num_users. This holds the number of consumer devices that | 179 | num_users. This holds the number of consumer devices that |
@@ -170,7 +183,7 @@ Description: | |||
170 | What: /sys/class/regulator/.../requested_microamps | 183 | What: /sys/class/regulator/.../requested_microamps |
171 | Date: April 2008 | 184 | Date: April 2008 |
172 | KernelVersion: 2.6.26 | 185 | KernelVersion: 2.6.26 |
173 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | 186 | Contact: Liam Girdwood <lrg@slimlogic.co.uk> |
174 | Description: | 187 | Description: |
175 | Each regulator directory will contain a field called | 188 | Each regulator directory will contain a field called |
176 | requested_microamps. This holds the total requested load | 189 | requested_microamps. This holds the total requested load |
@@ -181,7 +194,7 @@ Description: | |||
181 | What: /sys/class/regulator/.../parent | 194 | What: /sys/class/regulator/.../parent |
182 | Date: April 2008 | 195 | Date: April 2008 |
183 | KernelVersion: 2.6.26 | 196 | KernelVersion: 2.6.26 |
184 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | 197 | Contact: Liam Girdwood <lrg@slimlogic.co.uk> |
185 | Description: | 198 | Description: |
186 | Some regulator directories will contain a link called parent. | 199 | Some regulator directories will contain a link called parent. |
187 | This points to the parent or supply regulator if one exists. | 200 | This points to the parent or supply regulator if one exists. |
@@ -189,7 +202,7 @@ Description: | |||
189 | What: /sys/class/regulator/.../suspend_mem_microvolts | 202 | What: /sys/class/regulator/.../suspend_mem_microvolts |
190 | Date: May 2008 | 203 | Date: May 2008 |
191 | KernelVersion: 2.6.26 | 204 | KernelVersion: 2.6.26 |
192 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | 205 | Contact: Liam Girdwood <lrg@slimlogic.co.uk> |
193 | Description: | 206 | Description: |
194 | Each regulator directory will contain a field called | 207 | Each regulator directory will contain a field called |
195 | suspend_mem_microvolts. This holds the regulator output | 208 | suspend_mem_microvolts. This holds the regulator output |
@@ -203,7 +216,7 @@ Description: | |||
203 | What: /sys/class/regulator/.../suspend_disk_microvolts | 216 | What: /sys/class/regulator/.../suspend_disk_microvolts |
204 | Date: May 2008 | 217 | Date: May 2008 |
205 | KernelVersion: 2.6.26 | 218 | KernelVersion: 2.6.26 |
206 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | 219 | Contact: Liam Girdwood <lrg@slimlogic.co.uk> |
207 | Description: | 220 | Description: |
208 | Each regulator directory will contain a field called | 221 | Each regulator directory will contain a field called |
209 | suspend_disk_microvolts. This holds the regulator output | 222 | suspend_disk_microvolts. This holds the regulator output |
@@ -217,7 +230,7 @@ Description: | |||
217 | What: /sys/class/regulator/.../suspend_standby_microvolts | 230 | What: /sys/class/regulator/.../suspend_standby_microvolts |
218 | Date: May 2008 | 231 | Date: May 2008 |
219 | KernelVersion: 2.6.26 | 232 | KernelVersion: 2.6.26 |
220 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | 233 | Contact: Liam Girdwood <lrg@slimlogic.co.uk> |
221 | Description: | 234 | Description: |
222 | Each regulator directory will contain a field called | 235 | Each regulator directory will contain a field called |
223 | suspend_standby_microvolts. This holds the regulator output | 236 | suspend_standby_microvolts. This holds the regulator output |
@@ -231,7 +244,7 @@ Description: | |||
231 | What: /sys/class/regulator/.../suspend_mem_mode | 244 | What: /sys/class/regulator/.../suspend_mem_mode |
232 | Date: May 2008 | 245 | Date: May 2008 |
233 | KernelVersion: 2.6.26 | 246 | KernelVersion: 2.6.26 |
234 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | 247 | Contact: Liam Girdwood <lrg@slimlogic.co.uk> |
235 | Description: | 248 | Description: |
236 | Each regulator directory will contain a field called | 249 | Each regulator directory will contain a field called |
237 | suspend_mem_mode. This holds the regulator operating mode | 250 | suspend_mem_mode. This holds the regulator operating mode |
@@ -245,7 +258,7 @@ Description: | |||
245 | What: /sys/class/regulator/.../suspend_disk_mode | 258 | What: /sys/class/regulator/.../suspend_disk_mode |
246 | Date: May 2008 | 259 | Date: May 2008 |
247 | KernelVersion: 2.6.26 | 260 | KernelVersion: 2.6.26 |
248 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | 261 | Contact: Liam Girdwood <lrg@slimlogic.co.uk> |
249 | Description: | 262 | Description: |
250 | Each regulator directory will contain a field called | 263 | Each regulator directory will contain a field called |
251 | suspend_disk_mode. This holds the regulator operating mode | 264 | suspend_disk_mode. This holds the regulator operating mode |
@@ -258,7 +271,7 @@ Description: | |||
258 | What: /sys/class/regulator/.../suspend_standby_mode | 271 | What: /sys/class/regulator/.../suspend_standby_mode |
259 | Date: May 2008 | 272 | Date: May 2008 |
260 | KernelVersion: 2.6.26 | 273 | KernelVersion: 2.6.26 |
261 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | 274 | Contact: Liam Girdwood <lrg@slimlogic.co.uk> |
262 | Description: | 275 | Description: |
263 | Each regulator directory will contain a field called | 276 | Each regulator directory will contain a field called |
264 | suspend_standby_mode. This holds the regulator operating mode | 277 | suspend_standby_mode. This holds the regulator operating mode |
@@ -272,7 +285,7 @@ Description: | |||
272 | What: /sys/class/regulator/.../suspend_mem_state | 285 | What: /sys/class/regulator/.../suspend_mem_state |
273 | Date: May 2008 | 286 | Date: May 2008 |
274 | KernelVersion: 2.6.26 | 287 | KernelVersion: 2.6.26 |
275 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | 288 | Contact: Liam Girdwood <lrg@slimlogic.co.uk> |
276 | Description: | 289 | Description: |
277 | Each regulator directory will contain a field called | 290 | Each regulator directory will contain a field called |
278 | suspend_mem_state. This holds the regulator operating state | 291 | suspend_mem_state. This holds the regulator operating state |
@@ -287,7 +300,7 @@ Description: | |||
287 | What: /sys/class/regulator/.../suspend_disk_state | 300 | What: /sys/class/regulator/.../suspend_disk_state |
288 | Date: May 2008 | 301 | Date: May 2008 |
289 | KernelVersion: 2.6.26 | 302 | KernelVersion: 2.6.26 |
290 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | 303 | Contact: Liam Girdwood <lrg@slimlogic.co.uk> |
291 | Description: | 304 | Description: |
292 | Each regulator directory will contain a field called | 305 | Each regulator directory will contain a field called |
293 | suspend_disk_state. This holds the regulator operating state | 306 | suspend_disk_state. This holds the regulator operating state |
@@ -302,7 +315,7 @@ Description: | |||
302 | What: /sys/class/regulator/.../suspend_standby_state | 315 | What: /sys/class/regulator/.../suspend_standby_state |
303 | Date: May 2008 | 316 | Date: May 2008 |
304 | KernelVersion: 2.6.26 | 317 | KernelVersion: 2.6.26 |
305 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | 318 | Contact: Liam Girdwood <lrg@slimlogic.co.uk> |
306 | Description: | 319 | Description: |
307 | Each regulator directory will contain a field called | 320 | Each regulator directory will contain a field called |
308 | suspend_standby_state. This holds the regulator operating | 321 | suspend_standby_state. This holds the regulator operating |
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt index cc8093c15cf5..4d2566a7d168 100644 --- a/Documentation/feature-removal-schedule.txt +++ b/Documentation/feature-removal-schedule.txt | |||
@@ -287,6 +287,13 @@ Who: Glauber Costa <gcosta@redhat.com> | |||
287 | 287 | ||
288 | --------------------------- | 288 | --------------------------- |
289 | 289 | ||
290 | What: remove HID compat support | ||
291 | When: 2.6.29 | ||
292 | Why: needed only as a temporary solution until distros fix themselves up | ||
293 | Who: Jiri Slaby <jirislaby@gmail.com> | ||
294 | |||
295 | --------------------------- | ||
296 | |||
290 | What: /sys/o2cb symlink | 297 | What: /sys/o2cb symlink |
291 | When: January 2010 | 298 | When: January 2010 |
292 | Why: /sys/fs/o2cb is the proper location for this information - /sys/o2cb | 299 | Why: /sys/fs/o2cb is the proper location for this information - /sys/o2cb |
diff --git a/Documentation/filesystems/ocfs2.txt b/Documentation/filesystems/ocfs2.txt index c318a8bbb1ef..4340cc825796 100644 --- a/Documentation/filesystems/ocfs2.txt +++ b/Documentation/filesystems/ocfs2.txt | |||
@@ -76,3 +76,9 @@ localalloc=8(*) Allows custom localalloc size in MB. If the value is too | |||
76 | large, the fs will silently revert it to the default. | 76 | large, the fs will silently revert it to the default. |
77 | Localalloc is not enabled for local mounts. | 77 | Localalloc is not enabled for local mounts. |
78 | localflocks This disables cluster aware flock. | 78 | localflocks This disables cluster aware flock. |
79 | inode64 Indicates that Ocfs2 is allowed to create inodes at | ||
80 | any location in the filesystem, including those which | ||
81 | will result in inode numbers occupying more than 32 | ||
82 | bits of significance. | ||
83 | user_xattr (*) Enables Extended User Attributes. | ||
84 | nouser_xattr Disables Extended User Attributes. | ||
diff --git a/Documentation/power/regulator/machine.txt b/Documentation/power/regulator/machine.txt index c9a35665cf70..ce3487d99abe 100644 --- a/Documentation/power/regulator/machine.txt +++ b/Documentation/power/regulator/machine.txt | |||
@@ -2,17 +2,8 @@ Regulator Machine Driver Interface | |||
2 | =================================== | 2 | =================================== |
3 | 3 | ||
4 | The regulator machine driver interface is intended for board/machine specific | 4 | The regulator machine driver interface is intended for board/machine specific |
5 | initialisation code to configure the regulator subsystem. Typical things that | 5 | initialisation code to configure the regulator subsystem. |
6 | machine drivers would do are :- | ||
7 | 6 | ||
8 | 1. Regulator -> Device mapping. | ||
9 | 2. Regulator supply configuration. | ||
10 | 3. Power Domain constraint setting. | ||
11 | |||
12 | |||
13 | |||
14 | 1. Regulator -> device mapping | ||
15 | ============================== | ||
16 | Consider the following machine :- | 7 | Consider the following machine :- |
17 | 8 | ||
18 | Regulator-1 -+-> Regulator-2 --> [Consumer A @ 1.8 - 2.0V] | 9 | Regulator-1 -+-> Regulator-2 --> [Consumer A @ 1.8 - 2.0V] |
@@ -21,81 +12,82 @@ Consider the following machine :- | |||
21 | 12 | ||
22 | The drivers for consumers A & B must be mapped to the correct regulator in | 13 | The drivers for consumers A & B must be mapped to the correct regulator in |
23 | order to control their power supply. This mapping can be achieved in machine | 14 | order to control their power supply. This mapping can be achieved in machine |
24 | initialisation code by calling :- | 15 | initialisation code by creating a struct regulator_consumer_supply for |
16 | each regulator. | ||
17 | |||
18 | struct regulator_consumer_supply { | ||
19 | struct device *dev; /* consumer */ | ||
20 | const char *supply; /* consumer supply - e.g. "vcc" */ | ||
21 | }; | ||
25 | 22 | ||
26 | int regulator_set_device_supply(const char *regulator, struct device *dev, | 23 | e.g. for the machine above |
27 | const char *supply); | ||
28 | 24 | ||
29 | and is shown with the following code :- | 25 | static struct regulator_consumer_supply regulator1_consumers[] = { |
26 | { | ||
27 | .dev = &platform_consumerB_device.dev, | ||
28 | .supply = "Vcc", | ||
29 | },}; | ||
30 | 30 | ||
31 | regulator_set_device_supply("Regulator-1", devB, "Vcc"); | 31 | static struct regulator_consumer_supply regulator2_consumers[] = { |
32 | regulator_set_device_supply("Regulator-2", devA, "Vcc"); | 32 | { |
33 | .dev = &platform_consumerA_device.dev, | ||
34 | .supply = "Vcc", | ||
35 | },}; | ||
33 | 36 | ||
34 | This maps Regulator-1 to the 'Vcc' supply for Consumer B and maps Regulator-2 | 37 | This maps Regulator-1 to the 'Vcc' supply for Consumer B and maps Regulator-2 |
35 | to the 'Vcc' supply for Consumer A. | 38 | to the 'Vcc' supply for Consumer A. |
36 | 39 | ||
37 | 40 | Constraints can now be registered by defining a struct regulator_init_data | |
38 | 2. Regulator supply configuration. | 41 | for each regulator power domain. This structure also maps the consumers |
39 | ================================== | 42 | to their supply regulator :- |
40 | Consider the following machine (again) :- | 43 | |
41 | 44 | static struct regulator_init_data regulator1_data = { | |
42 | Regulator-1 -+-> Regulator-2 --> [Consumer A @ 1.8 - 2.0V] | 45 | .constraints = { |
43 | | | 46 | .min_uV = 3300000, |
44 | +-> [Consumer B @ 3.3V] | 47 | .max_uV = 3300000, |
48 | .valid_modes_mask = REGULATOR_MODE_NORMAL, | ||
49 | }, | ||
50 | .num_consumer_supplies = ARRAY_SIZE(regulator1_consumers), | ||
51 | .consumer_supplies = regulator1_consumers, | ||
52 | }; | ||
45 | 53 | ||
46 | Regulator-1 supplies power to Regulator-2. This relationship must be registered | 54 | Regulator-1 supplies power to Regulator-2. This relationship must be registered |
47 | with the core so that Regulator-1 is also enabled when Consumer A enables it's | 55 | with the core so that Regulator-1 is also enabled when Consumer A enables it's |
48 | supply (Regulator-2). | 56 | supply (Regulator-2). The supply regulator is set by the supply_regulator_dev |
49 | 57 | field below:- | |
50 | This relationship can be register with the core via :- | 58 | |
51 | 59 | static struct regulator_init_data regulator2_data = { | |
52 | int regulator_set_supply(const char *regulator, const char *regulator_supply); | 60 | .supply_regulator_dev = &platform_regulator1_device.dev, |
53 | 61 | .constraints = { | |
54 | In this example we would use the following code :- | 62 | .min_uV = 1800000, |
55 | 63 | .max_uV = 2000000, | |
56 | regulator_set_supply("Regulator-2", "Regulator-1"); | 64 | .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE, |
57 | 65 | .valid_modes_mask = REGULATOR_MODE_NORMAL, | |
58 | Relationships can be queried by calling :- | 66 | }, |
59 | 67 | .num_consumer_supplies = ARRAY_SIZE(regulator2_consumers), | |
60 | const char *regulator_get_supply(const char *regulator); | 68 | .consumer_supplies = regulator2_consumers, |
61 | |||
62 | |||
63 | 3. Power Domain constraint setting. | ||
64 | =================================== | ||
65 | Each power domain within a system has physical constraints on voltage and | ||
66 | current. This must be defined in software so that the power domain is always | ||
67 | operated within specifications. | ||
68 | |||
69 | Consider the following machine (again) :- | ||
70 | |||
71 | Regulator-1 -+-> Regulator-2 --> [Consumer A @ 1.8 - 2.0V] | ||
72 | | | ||
73 | +-> [Consumer B @ 3.3V] | ||
74 | |||
75 | This gives us two regulators and two power domains: | ||
76 | |||
77 | Domain 1: Regulator-2, Consumer B. | ||
78 | Domain 2: Consumer A. | ||
79 | |||
80 | Constraints can be registered by calling :- | ||
81 | |||
82 | int regulator_set_platform_constraints(const char *regulator, | ||
83 | struct regulation_constraints *constraints); | ||
84 | |||
85 | The example is defined as follows :- | ||
86 | |||
87 | struct regulation_constraints domain_1 = { | ||
88 | .min_uV = 3300000, | ||
89 | .max_uV = 3300000, | ||
90 | .valid_modes_mask = REGULATOR_MODE_NORMAL, | ||
91 | }; | 69 | }; |
92 | 70 | ||
93 | struct regulation_constraints domain_2 = { | 71 | Finally the regulator devices must be registered in the usual manner. |
94 | .min_uV = 1800000, | 72 | |
95 | .max_uV = 2000000, | 73 | static struct platform_device regulator_devices[] = { |
96 | .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE, | 74 | { |
97 | .valid_modes_mask = REGULATOR_MODE_NORMAL, | 75 | .name = "regulator", |
76 | .id = DCDC_1, | ||
77 | .dev = { | ||
78 | .platform_data = ®ulator1_data, | ||
79 | }, | ||
80 | }, | ||
81 | { | ||
82 | .name = "regulator", | ||
83 | .id = DCDC_2, | ||
84 | .dev = { | ||
85 | .platform_data = ®ulator2_data, | ||
86 | }, | ||
87 | }, | ||
98 | }; | 88 | }; |
89 | /* register regulator 1 device */ | ||
90 | platform_device_register(&wm8350_regulator_devices[0]); | ||
99 | 91 | ||
100 | regulator_set_platform_constraints("Regulator-1", &domain_1); | 92 | /* register regulator 2 device */ |
101 | regulator_set_platform_constraints("Regulator-2", &domain_2); | 93 | platform_device_register(&wm8350_regulator_devices[1]); |
diff --git a/Documentation/power/regulator/regulator.txt b/Documentation/power/regulator/regulator.txt index a69050143592..4200accb9bba 100644 --- a/Documentation/power/regulator/regulator.txt +++ b/Documentation/power/regulator/regulator.txt | |||
@@ -10,11 +10,11 @@ Registration | |||
10 | 10 | ||
11 | Drivers can register a regulator by calling :- | 11 | Drivers can register a regulator by calling :- |
12 | 12 | ||
13 | struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, | 13 | struct regulator_dev *regulator_register(struct device *dev, |
14 | void *reg_data); | 14 | struct regulator_desc *regulator_desc); |
15 | 15 | ||
16 | This will register the regulators capabilities and operations the regulator | 16 | This will register the regulators capabilities and operations to the regulator |
17 | core. The core does not touch reg_data (private to regulator driver). | 17 | core. |
18 | 18 | ||
19 | Regulators can be unregistered by calling :- | 19 | Regulators can be unregistered by calling :- |
20 | 20 | ||
diff --git a/MAINTAINERS b/MAINTAINERS index 988b0a852890..5d0b8a23d639 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
@@ -4520,10 +4520,11 @@ S: Maintained | |||
4520 | 4520 | ||
4521 | VOLTAGE AND CURRENT REGULATOR FRAMEWORK | 4521 | VOLTAGE AND CURRENT REGULATOR FRAMEWORK |
4522 | P: Liam Girdwood | 4522 | P: Liam Girdwood |
4523 | M: lg@opensource.wolfsonmicro.com | 4523 | M: lrg@slimlogic.co.uk |
4524 | P: Mark Brown | 4524 | P: Mark Brown |
4525 | M: broonie@opensource.wolfsonmicro.com | 4525 | M: broonie@opensource.wolfsonmicro.com |
4526 | W: http://opensource.wolfsonmicro.com/node/15 | 4526 | W: http://opensource.wolfsonmicro.com/node/15 |
4527 | W: http://www.slimlogic.co.uk/?page_id=5 | ||
4527 | T: git kernel.org/pub/scm/linux/kernel/git/lrg/voltage-2.6.git | 4528 | T: git kernel.org/pub/scm/linux/kernel/git/lrg/voltage-2.6.git |
4528 | S: Supported | 4529 | S: Supported |
4529 | 4530 | ||
diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig index 41e5bf02e230..677c93a490f6 100644 --- a/arch/m68k/Kconfig +++ b/arch/m68k/Kconfig | |||
@@ -105,21 +105,9 @@ config PCMCIA | |||
105 | To compile this driver as modules, choose M here: the | 105 | To compile this driver as modules, choose M here: the |
106 | modules will be called pcmcia_core and ds. | 106 | modules will be called pcmcia_core and ds. |
107 | 107 | ||
108 | config SUN3 | ||
109 | bool "Sun3 support" | ||
110 | select M68020 | ||
111 | select MMU_SUN3 if MMU | ||
112 | help | ||
113 | This option enables support for the Sun 3 series of workstations | ||
114 | (3/50, 3/60, 3/1xx, 3/2xx systems). Enabling this option requires | ||
115 | that all other hardware types must be disabled, as Sun 3 kernels | ||
116 | are incompatible with all other m68k targets (including Sun 3x!). | ||
117 | |||
118 | If you don't want to compile a kernel exclusively for a Sun 3, say N. | ||
119 | |||
120 | config AMIGA | 108 | config AMIGA |
121 | bool "Amiga support" | 109 | bool "Amiga support" |
122 | depends on !MMU_SUN3 | 110 | select MMU_MOTOROLA if MMU |
123 | help | 111 | help |
124 | This option enables support for the Amiga series of computers. If | 112 | This option enables support for the Amiga series of computers. If |
125 | you plan to use this kernel on an Amiga, say Y here and browse the | 113 | you plan to use this kernel on an Amiga, say Y here and browse the |
@@ -127,33 +115,16 @@ config AMIGA | |||
127 | 115 | ||
128 | config ATARI | 116 | config ATARI |
129 | bool "Atari support" | 117 | bool "Atari support" |
130 | depends on !MMU_SUN3 | 118 | select MMU_MOTOROLA if MMU |
131 | help | 119 | help |
132 | This option enables support for the 68000-based Atari series of | 120 | This option enables support for the 68000-based Atari series of |
133 | computers (including the TT, Falcon and Medusa). If you plan to use | 121 | computers (including the TT, Falcon and Medusa). If you plan to use |
134 | this kernel on an Atari, say Y here and browse the material | 122 | this kernel on an Atari, say Y here and browse the material |
135 | available in <file:Documentation/m68k>; otherwise say N. | 123 | available in <file:Documentation/m68k>; otherwise say N. |
136 | 124 | ||
137 | config HADES | ||
138 | bool "Hades support" | ||
139 | depends on ATARI && BROKEN | ||
140 | help | ||
141 | This option enables support for the Hades Atari clone. If you plan | ||
142 | to use this kernel on a Hades, say Y here; otherwise say N. | ||
143 | |||
144 | config PCI | ||
145 | bool | ||
146 | depends on HADES | ||
147 | default y | ||
148 | help | ||
149 | Find out whether you have a PCI motherboard. PCI is the name of a | ||
150 | bus system, i.e. the way the CPU talks to the other stuff inside | ||
151 | your box. Other bus systems are ISA, EISA, MicroChannel (MCA) or | ||
152 | VESA. If you have PCI, say Y, otherwise N. | ||
153 | |||
154 | config MAC | 125 | config MAC |
155 | bool "Macintosh support" | 126 | bool "Macintosh support" |
156 | depends on !MMU_SUN3 | 127 | select MMU_MOTOROLA if MMU |
157 | help | 128 | help |
158 | This option enables support for the Apple Macintosh series of | 129 | This option enables support for the Apple Macintosh series of |
159 | computers (yes, there is experimental support now, at least for part | 130 | computers (yes, there is experimental support now, at least for part |
@@ -174,14 +145,14 @@ config M68K_L2_CACHE | |||
174 | 145 | ||
175 | config APOLLO | 146 | config APOLLO |
176 | bool "Apollo support" | 147 | bool "Apollo support" |
177 | depends on !MMU_SUN3 | 148 | select MMU_MOTOROLA if MMU |
178 | help | 149 | help |
179 | Say Y here if you want to run Linux on an MC680x0-based Apollo | 150 | Say Y here if you want to run Linux on an MC680x0-based Apollo |
180 | Domain workstation such as the DN3500. | 151 | Domain workstation such as the DN3500. |
181 | 152 | ||
182 | config VME | 153 | config VME |
183 | bool "VME (Motorola and BVM) support" | 154 | bool "VME (Motorola and BVM) support" |
184 | depends on !MMU_SUN3 | 155 | select MMU_MOTOROLA if MMU |
185 | help | 156 | help |
186 | Say Y here if you want to build a kernel for a 680x0 based VME | 157 | Say Y here if you want to build a kernel for a 680x0 based VME |
187 | board. Boards currently supported include Motorola boards MVME147, | 158 | board. Boards currently supported include Motorola boards MVME147, |
@@ -218,7 +189,7 @@ config BVME6000 | |||
218 | 189 | ||
219 | config HP300 | 190 | config HP300 |
220 | bool "HP9000/300 and HP9000/400 support" | 191 | bool "HP9000/300 and HP9000/400 support" |
221 | depends on !MMU_SUN3 | 192 | select MMU_MOTOROLA if MMU |
222 | help | 193 | help |
223 | This option enables support for the HP9000/300 and HP9000/400 series | 194 | This option enables support for the HP9000/300 and HP9000/400 series |
224 | of workstations. Support for these machines is still somewhat | 195 | of workstations. Support for these machines is still somewhat |
@@ -237,7 +208,7 @@ config DIO | |||
237 | 208 | ||
238 | config SUN3X | 209 | config SUN3X |
239 | bool "Sun3x support" | 210 | bool "Sun3x support" |
240 | depends on !MMU_SUN3 | 211 | select MMU_MOTOROLA if MMU |
241 | select M68030 | 212 | select M68030 |
242 | help | 213 | help |
243 | This option enables support for the Sun 3x series of workstations. | 214 | This option enables support for the Sun 3x series of workstations. |
@@ -250,7 +221,7 @@ config SUN3X | |||
250 | 221 | ||
251 | config Q40 | 222 | config Q40 |
252 | bool "Q40/Q60 support" | 223 | bool "Q40/Q60 support" |
253 | depends on !MMU_SUN3 | 224 | select MMU_MOTOROLA if MMU |
254 | help | 225 | help |
255 | The Q40 is a Motorola 68040-based successor to the Sinclair QL | 226 | The Q40 is a Motorola 68040-based successor to the Sinclair QL |
256 | manufactured in Germany. There is an official Q40 home page at | 227 | manufactured in Germany. There is an official Q40 home page at |
@@ -258,6 +229,19 @@ config Q40 | |||
258 | Q60. Select your CPU below. For 68LC060 don't forget to enable FPU | 229 | Q60. Select your CPU below. For 68LC060 don't forget to enable FPU |
259 | emulation. | 230 | emulation. |
260 | 231 | ||
232 | config SUN3 | ||
233 | bool "Sun3 support" | ||
234 | depends on !MMU_MOTOROLA | ||
235 | select MMU_SUN3 if MMU | ||
236 | select M68020 | ||
237 | help | ||
238 | This option enables support for the Sun 3 series of workstations | ||
239 | (3/50, 3/60, 3/1xx, 3/2xx systems). Enabling this option requires | ||
240 | that all other hardware types must be disabled, as Sun 3 kernels | ||
241 | are incompatible with all other m68k targets (including Sun 3x!). | ||
242 | |||
243 | If you don't want to compile a kernel exclusively for a Sun 3, say N. | ||
244 | |||
261 | comment "Processor type" | 245 | comment "Processor type" |
262 | 246 | ||
263 | config M68020 | 247 | config M68020 |
@@ -295,10 +279,10 @@ config M68060 | |||
295 | config MMU_MOTOROLA | 279 | config MMU_MOTOROLA |
296 | bool | 280 | bool |
297 | depends on MMU && !MMU_SUN3 | 281 | depends on MMU && !MMU_SUN3 |
298 | default y | ||
299 | 282 | ||
300 | config MMU_SUN3 | 283 | config MMU_SUN3 |
301 | bool | 284 | bool |
285 | depends on MMU && !MMU_MOTOROLA | ||
302 | 286 | ||
303 | config M68KFPU_EMU | 287 | config M68KFPU_EMU |
304 | bool "Math emulation support (EXPERIMENTAL)" | 288 | bool "Math emulation support (EXPERIMENTAL)" |
diff --git a/arch/m68k/amiga/config.c b/arch/m68k/amiga/config.c index df679d96b1cb..0a3f9e8ebde0 100644 --- a/arch/m68k/amiga/config.c +++ b/arch/m68k/amiga/config.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/interrupt.h> | 24 | #include <linux/interrupt.h> |
25 | #include <linux/zorro.h> | 25 | #include <linux/zorro.h> |
26 | #include <linux/module.h> | 26 | #include <linux/module.h> |
27 | #include <linux/keyboard.h> | ||
27 | 28 | ||
28 | #include <asm/bootinfo.h> | 29 | #include <asm/bootinfo.h> |
29 | #include <asm/setup.h> | 30 | #include <asm/setup.h> |
@@ -984,3 +985,11 @@ static int amiga_get_hardware_list(char *buffer) | |||
984 | 985 | ||
985 | return len; | 986 | return len; |
986 | } | 987 | } |
988 | |||
989 | /* | ||
990 | * The Amiga keyboard driver needs key_maps, but we cannot export it in | ||
991 | * drivers/char/defkeymap.c, as it is autogenerated | ||
992 | */ | ||
993 | #ifdef CONFIG_HW_CONSOLE | ||
994 | EXPORT_SYMBOL_GPL(key_maps); | ||
995 | #endif | ||
diff --git a/arch/m68k/atari/Makefile b/arch/m68k/atari/Makefile index 2cd905efe63a..0cac723306f9 100644 --- a/arch/m68k/atari/Makefile +++ b/arch/m68k/atari/Makefile | |||
@@ -5,7 +5,4 @@ | |||
5 | obj-y := config.o time.o debug.o ataints.o stdma.o \ | 5 | obj-y := config.o time.o debug.o ataints.o stdma.o \ |
6 | atasound.o stram.o | 6 | atasound.o stram.o |
7 | 7 | ||
8 | ifeq ($(CONFIG_PCI),y) | ||
9 | obj-$(CONFIG_HADES) += hades-pci.o | ||
10 | endif | ||
11 | obj-$(CONFIG_ATARI_KBD_CORE) += atakeyb.o | 8 | obj-$(CONFIG_ATARI_KBD_CORE) += atakeyb.o |
diff --git a/arch/m68k/atari/ataints.c b/arch/m68k/atari/ataints.c index b45593a60bdd..dba4afabb444 100644 --- a/arch/m68k/atari/ataints.c +++ b/arch/m68k/atari/ataints.c | |||
@@ -407,10 +407,8 @@ void __init atari_init_IRQ(void) | |||
407 | * gets overruns) | 407 | * gets overruns) |
408 | */ | 408 | */ |
409 | 409 | ||
410 | if (!MACH_IS_HADES) { | 410 | vectors[VEC_INT2] = falcon_hblhandler; |
411 | vectors[VEC_INT2] = falcon_hblhandler; | 411 | vectors[VEC_INT4] = falcon_hblhandler; |
412 | vectors[VEC_INT4] = falcon_hblhandler; | ||
413 | } | ||
414 | } | 412 | } |
415 | 413 | ||
416 | if (ATARIHW_PRESENT(PCM_8BIT) && ATARIHW_PRESENT(MICROWIRE)) { | 414 | if (ATARIHW_PRESENT(PCM_8BIT) && ATARIHW_PRESENT(MICROWIRE)) { |
diff --git a/arch/m68k/atari/atakeyb.c b/arch/m68k/atari/atakeyb.c index bb959fbab2dc..c038b7c7eff0 100644 --- a/arch/m68k/atari/atakeyb.c +++ b/arch/m68k/atari/atakeyb.c | |||
@@ -635,15 +635,3 @@ int atari_keyb_init(void) | |||
635 | return 0; | 635 | return 0; |
636 | } | 636 | } |
637 | EXPORT_SYMBOL_GPL(atari_keyb_init); | 637 | EXPORT_SYMBOL_GPL(atari_keyb_init); |
638 | |||
639 | int atari_kbd_translate(unsigned char keycode, unsigned char *keycodep, char raw_mode) | ||
640 | { | ||
641 | #ifdef CONFIG_MAGIC_SYSRQ | ||
642 | /* ALT+HELP pressed? */ | ||
643 | if ((keycode == 98) && ((shift_state & 0xff) == 8)) | ||
644 | *keycodep = 0xff; | ||
645 | else | ||
646 | #endif | ||
647 | *keycodep = keycode; | ||
648 | return 1; | ||
649 | } | ||
diff --git a/arch/m68k/atari/config.c b/arch/m68k/atari/config.c index 5945e1505558..af031855f796 100644 --- a/arch/m68k/atari/config.c +++ b/arch/m68k/atari/config.c | |||
@@ -231,7 +231,7 @@ void __init config_atari(void) | |||
231 | */ | 231 | */ |
232 | 232 | ||
233 | printk("Atari hardware found: "); | 233 | printk("Atari hardware found: "); |
234 | if (MACH_IS_MEDUSA || MACH_IS_HADES) { | 234 | if (MACH_IS_MEDUSA) { |
235 | /* There's no Atari video hardware on the Medusa, but all the | 235 | /* There's no Atari video hardware on the Medusa, but all the |
236 | * addresses below generate a DTACK so no bus error occurs! */ | 236 | * addresses below generate a DTACK so no bus error occurs! */ |
237 | } else if (hwreg_present(f030_xreg)) { | 237 | } else if (hwreg_present(f030_xreg)) { |
@@ -269,10 +269,6 @@ void __init config_atari(void) | |||
269 | ATARIHW_SET(SCSI_DMA); | 269 | ATARIHW_SET(SCSI_DMA); |
270 | printk("TT_SCSI_DMA "); | 270 | printk("TT_SCSI_DMA "); |
271 | } | 271 | } |
272 | if (!MACH_IS_HADES && hwreg_present(&st_dma.dma_hi)) { | ||
273 | ATARIHW_SET(STND_DMA); | ||
274 | printk("STND_DMA "); | ||
275 | } | ||
276 | /* | 272 | /* |
277 | * The ST-DMA address registers aren't readable | 273 | * The ST-DMA address registers aren't readable |
278 | * on all Medusas, so the test below may fail | 274 | * on all Medusas, so the test below may fail |
@@ -294,12 +290,11 @@ void __init config_atari(void) | |||
294 | ATARIHW_SET(YM_2149); | 290 | ATARIHW_SET(YM_2149); |
295 | printk("YM2149 "); | 291 | printk("YM2149 "); |
296 | } | 292 | } |
297 | if (!MACH_IS_MEDUSA && !MACH_IS_HADES && | 293 | if (!MACH_IS_MEDUSA && hwreg_present(&tt_dmasnd.ctrl)) { |
298 | hwreg_present(&tt_dmasnd.ctrl)) { | ||
299 | ATARIHW_SET(PCM_8BIT); | 294 | ATARIHW_SET(PCM_8BIT); |
300 | printk("PCM "); | 295 | printk("PCM "); |
301 | } | 296 | } |
302 | if (!MACH_IS_HADES && hwreg_present(&falcon_codec.unused5)) { | 297 | if (hwreg_present(&falcon_codec.unused5)) { |
303 | ATARIHW_SET(CODEC); | 298 | ATARIHW_SET(CODEC); |
304 | printk("CODEC "); | 299 | printk("CODEC "); |
305 | } | 300 | } |
@@ -313,7 +308,7 @@ void __init config_atari(void) | |||
313 | (tt_scc_dma.dma_ctrl = 0x01, (tt_scc_dma.dma_ctrl & 1) == 1) && | 308 | (tt_scc_dma.dma_ctrl = 0x01, (tt_scc_dma.dma_ctrl & 1) == 1) && |
314 | (tt_scc_dma.dma_ctrl = 0x00, (tt_scc_dma.dma_ctrl & 1) == 0) | 309 | (tt_scc_dma.dma_ctrl = 0x00, (tt_scc_dma.dma_ctrl & 1) == 0) |
315 | #else | 310 | #else |
316 | !MACH_IS_MEDUSA && !MACH_IS_HADES | 311 | !MACH_IS_MEDUSA |
317 | #endif | 312 | #endif |
318 | ) { | 313 | ) { |
319 | ATARIHW_SET(SCC_DMA); | 314 | ATARIHW_SET(SCC_DMA); |
@@ -327,10 +322,7 @@ void __init config_atari(void) | |||
327 | ATARIHW_SET(ST_ESCC); | 322 | ATARIHW_SET(ST_ESCC); |
328 | printk("ST_ESCC "); | 323 | printk("ST_ESCC "); |
329 | } | 324 | } |
330 | if (MACH_IS_HADES) { | 325 | if (hwreg_present(&tt_scu.sys_mask)) { |
331 | ATARIHW_SET(VME); | ||
332 | printk("VME "); | ||
333 | } else if (hwreg_present(&tt_scu.sys_mask)) { | ||
334 | ATARIHW_SET(SCU); | 326 | ATARIHW_SET(SCU); |
335 | /* Assume a VME bus if there's a SCU */ | 327 | /* Assume a VME bus if there's a SCU */ |
336 | ATARIHW_SET(VME); | 328 | ATARIHW_SET(VME); |
@@ -340,7 +332,7 @@ void __init config_atari(void) | |||
340 | ATARIHW_SET(ANALOG_JOY); | 332 | ATARIHW_SET(ANALOG_JOY); |
341 | printk("ANALOG_JOY "); | 333 | printk("ANALOG_JOY "); |
342 | } | 334 | } |
343 | if (!MACH_IS_HADES && hwreg_present(blitter.halftone)) { | 335 | if (hwreg_present(blitter.halftone)) { |
344 | ATARIHW_SET(BLITTER); | 336 | ATARIHW_SET(BLITTER); |
345 | printk("BLITTER "); | 337 | printk("BLITTER "); |
346 | } | 338 | } |
@@ -349,8 +341,7 @@ void __init config_atari(void) | |||
349 | printk("IDE "); | 341 | printk("IDE "); |
350 | } | 342 | } |
351 | #if 1 /* This maybe wrong */ | 343 | #if 1 /* This maybe wrong */ |
352 | if (!MACH_IS_MEDUSA && !MACH_IS_HADES && | 344 | if (!MACH_IS_MEDUSA && hwreg_present(&tt_microwire.data) && |
353 | hwreg_present(&tt_microwire.data) && | ||
354 | hwreg_present(&tt_microwire.mask) && | 345 | hwreg_present(&tt_microwire.mask) && |
355 | (tt_microwire.mask = 0x7ff, | 346 | (tt_microwire.mask = 0x7ff, |
356 | udelay(1), | 347 | udelay(1), |
@@ -369,19 +360,18 @@ void __init config_atari(void) | |||
369 | mach_hwclk = atari_tt_hwclk; | 360 | mach_hwclk = atari_tt_hwclk; |
370 | mach_set_clock_mmss = atari_tt_set_clock_mmss; | 361 | mach_set_clock_mmss = atari_tt_set_clock_mmss; |
371 | } | 362 | } |
372 | if (!MACH_IS_HADES && hwreg_present(&mste_rtc.sec_ones)) { | 363 | if (hwreg_present(&mste_rtc.sec_ones)) { |
373 | ATARIHW_SET(MSTE_CLK); | 364 | ATARIHW_SET(MSTE_CLK); |
374 | printk("MSTE_CLK "); | 365 | printk("MSTE_CLK "); |
375 | mach_hwclk = atari_mste_hwclk; | 366 | mach_hwclk = atari_mste_hwclk; |
376 | mach_set_clock_mmss = atari_mste_set_clock_mmss; | 367 | mach_set_clock_mmss = atari_mste_set_clock_mmss; |
377 | } | 368 | } |
378 | if (!MACH_IS_MEDUSA && !MACH_IS_HADES && | 369 | if (!MACH_IS_MEDUSA && hwreg_present(&dma_wd.fdc_speed) && |
379 | hwreg_present(&dma_wd.fdc_speed) && | ||
380 | hwreg_write(&dma_wd.fdc_speed, 0)) { | 370 | hwreg_write(&dma_wd.fdc_speed, 0)) { |
381 | ATARIHW_SET(FDCSPEED); | 371 | ATARIHW_SET(FDCSPEED); |
382 | printk("FDC_SPEED "); | 372 | printk("FDC_SPEED "); |
383 | } | 373 | } |
384 | if (!MACH_IS_HADES && !ATARIHW_PRESENT(ST_SCSI)) { | 374 | if (!ATARIHW_PRESENT(ST_SCSI)) { |
385 | ATARIHW_SET(ACSI); | 375 | ATARIHW_SET(ACSI); |
386 | printk("ACSI "); | 376 | printk("ACSI "); |
387 | } | 377 | } |
@@ -449,7 +439,7 @@ void __init config_atari(void) | |||
449 | * 0xFFxxxxxx -> 0x00xxxxxx, so that the first 16MB is accessible | 439 | * 0xFFxxxxxx -> 0x00xxxxxx, so that the first 16MB is accessible |
450 | * in the last 16MB of the address space. | 440 | * in the last 16MB of the address space. |
451 | */ | 441 | */ |
452 | tos_version = (MACH_IS_MEDUSA || MACH_IS_HADES) ? | 442 | tos_version = (MACH_IS_MEDUSA) ? |
453 | 0xfff : *(unsigned short *)0xff000002; | 443 | 0xfff : *(unsigned short *)0xff000002; |
454 | atari_rtc_year_offset = (tos_version < 0x306) ? 70 : 68; | 444 | atari_rtc_year_offset = (tos_version < 0x306) ? 70 : 68; |
455 | } | 445 | } |
@@ -511,8 +501,7 @@ static void atari_reset(void) | |||
511 | * On the Medusa, phys. 0x4 may contain garbage because it's no | 501 | * On the Medusa, phys. 0x4 may contain garbage because it's no |
512 | * ROM. See above for explanation why we cannot use PTOV(4). | 502 | * ROM. See above for explanation why we cannot use PTOV(4). |
513 | */ | 503 | */ |
514 | reset_addr = MACH_IS_HADES ? 0x7fe00030 : | 504 | reset_addr = MACH_IS_MEDUSA || MACH_IS_AB40 ? 0xe00030 : |
515 | MACH_IS_MEDUSA || MACH_IS_AB40 ? 0xe00030 : | ||
516 | *(unsigned long *) 0xff000004; | 505 | *(unsigned long *) 0xff000004; |
517 | 506 | ||
518 | /* reset ACIA for switch off OverScan, if it's active */ | 507 | /* reset ACIA for switch off OverScan, if it's active */ |
@@ -606,8 +595,6 @@ static void atari_get_model(char *model) | |||
606 | if (MACH_IS_MEDUSA) | 595 | if (MACH_IS_MEDUSA) |
607 | /* Medusa has TT _MCH cookie */ | 596 | /* Medusa has TT _MCH cookie */ |
608 | strcat(model, "Medusa"); | 597 | strcat(model, "Medusa"); |
609 | else if (MACH_IS_HADES) | ||
610 | strcat(model, "Hades"); | ||
611 | else | 598 | else |
612 | strcat(model, "TT"); | 599 | strcat(model, "TT"); |
613 | break; | 600 | break; |
diff --git a/arch/m68k/atari/hades-pci.c b/arch/m68k/atari/hades-pci.c deleted file mode 100644 index 2bbabc008708..000000000000 --- a/arch/m68k/atari/hades-pci.c +++ /dev/null | |||
@@ -1,440 +0,0 @@ | |||
1 | /* | ||
2 | * hades-pci.c - Hardware specific PCI BIOS functions the Hades Atari clone. | ||
3 | * | ||
4 | * Written by Wout Klaren. | ||
5 | */ | ||
6 | |||
7 | #include <linux/init.h> | ||
8 | #include <linux/kernel.h> | ||
9 | #include <asm/io.h> | ||
10 | |||
11 | #if 0 | ||
12 | # define DBG_DEVS(args) printk args | ||
13 | #else | ||
14 | # define DBG_DEVS(args) | ||
15 | #endif | ||
16 | |||
17 | #if defined(CONFIG_PCI) && defined(CONFIG_HADES) | ||
18 | |||
19 | #include <linux/slab.h> | ||
20 | #include <linux/mm.h> | ||
21 | #include <linux/pci.h> | ||
22 | |||
23 | #include <asm/atarihw.h> | ||
24 | #include <asm/atariints.h> | ||
25 | #include <asm/byteorder.h> | ||
26 | #include <asm/pci.h> | ||
27 | |||
28 | #define HADES_MEM_BASE 0x80000000 | ||
29 | #define HADES_MEM_SIZE 0x20000000 | ||
30 | #define HADES_CONFIG_BASE 0xA0000000 | ||
31 | #define HADES_CONFIG_SIZE 0x10000000 | ||
32 | #define HADES_IO_BASE 0xB0000000 | ||
33 | #define HADES_IO_SIZE 0x10000000 | ||
34 | #define HADES_VIRT_IO_SIZE 0x00010000 /* Only 64k is remapped and actually used. */ | ||
35 | |||
36 | #define N_SLOTS 4 /* Number of PCI slots. */ | ||
37 | |||
38 | static const char pci_mem_name[] = "PCI memory space"; | ||
39 | static const char pci_io_name[] = "PCI I/O space"; | ||
40 | static const char pci_config_name[] = "PCI config space"; | ||
41 | |||
42 | static struct resource config_space = { | ||
43 | .name = pci_config_name, | ||
44 | .start = HADES_CONFIG_BASE, | ||
45 | .end = HADES_CONFIG_BASE + HADES_CONFIG_SIZE - 1 | ||
46 | }; | ||
47 | static struct resource io_space = { | ||
48 | .name = pci_io_name, | ||
49 | .start = HADES_IO_BASE, | ||
50 | .end = HADES_IO_BASE + HADES_IO_SIZE - 1 | ||
51 | }; | ||
52 | |||
53 | static const unsigned long pci_conf_base_phys[] = { | ||
54 | 0xA0080000, 0xA0040000, 0xA0020000, 0xA0010000 | ||
55 | }; | ||
56 | static unsigned long pci_conf_base_virt[N_SLOTS]; | ||
57 | static unsigned long pci_io_base_virt; | ||
58 | |||
59 | /* | ||
60 | * static void *mk_conf_addr(unsigned char bus, unsigned char device_fn, | ||
61 | * unsigned char where) | ||
62 | * | ||
63 | * Calculate the address of the PCI configuration area of the given | ||
64 | * device. | ||
65 | * | ||
66 | * BUG: boards with multiple functions are probably not correctly | ||
67 | * supported. | ||
68 | */ | ||
69 | |||
70 | static void *mk_conf_addr(struct pci_dev *dev, int where) | ||
71 | { | ||
72 | int device = dev->devfn >> 3, function = dev->devfn & 7; | ||
73 | void *result; | ||
74 | |||
75 | DBG_DEVS(("mk_conf_addr(bus=%d ,device_fn=0x%x, where=0x%x, pci_addr=0x%p)\n", | ||
76 | dev->bus->number, dev->devfn, where, pci_addr)); | ||
77 | |||
78 | if (device > 3) | ||
79 | { | ||
80 | DBG_DEVS(("mk_conf_addr: device (%d) > 3, returning NULL\n", device)); | ||
81 | return NULL; | ||
82 | } | ||
83 | |||
84 | if (dev->bus->number != 0) | ||
85 | { | ||
86 | DBG_DEVS(("mk_conf_addr: bus (%d) > 0, returning NULL\n", device)); | ||
87 | return NULL; | ||
88 | } | ||
89 | |||
90 | result = (void *) (pci_conf_base_virt[device] | (function << 8) | (where)); | ||
91 | DBG_DEVS(("mk_conf_addr: returning pci_addr 0x%lx\n", (unsigned long) result)); | ||
92 | return result; | ||
93 | } | ||
94 | |||
95 | static int hades_read_config_byte(struct pci_dev *dev, int where, u8 *value) | ||
96 | { | ||
97 | volatile unsigned char *pci_addr; | ||
98 | |||
99 | *value = 0xff; | ||
100 | |||
101 | if ((pci_addr = (unsigned char *) mk_conf_addr(dev, where)) == NULL) | ||
102 | return PCIBIOS_DEVICE_NOT_FOUND; | ||
103 | |||
104 | *value = *pci_addr; | ||
105 | |||
106 | return PCIBIOS_SUCCESSFUL; | ||
107 | } | ||
108 | |||
109 | static int hades_read_config_word(struct pci_dev *dev, int where, u16 *value) | ||
110 | { | ||
111 | volatile unsigned short *pci_addr; | ||
112 | |||
113 | *value = 0xffff; | ||
114 | |||
115 | if (where & 0x1) | ||
116 | return PCIBIOS_BAD_REGISTER_NUMBER; | ||
117 | |||
118 | if ((pci_addr = (unsigned short *) mk_conf_addr(dev, where)) == NULL) | ||
119 | return PCIBIOS_DEVICE_NOT_FOUND; | ||
120 | |||
121 | *value = le16_to_cpu(*pci_addr); | ||
122 | |||
123 | return PCIBIOS_SUCCESSFUL; | ||
124 | } | ||
125 | |||
126 | static int hades_read_config_dword(struct pci_dev *dev, int where, u32 *value) | ||
127 | { | ||
128 | volatile unsigned int *pci_addr; | ||
129 | unsigned char header_type; | ||
130 | int result; | ||
131 | |||
132 | *value = 0xffffffff; | ||
133 | |||
134 | if (where & 0x3) | ||
135 | return PCIBIOS_BAD_REGISTER_NUMBER; | ||
136 | |||
137 | if ((pci_addr = (unsigned int *) mk_conf_addr(dev, where)) == NULL) | ||
138 | return PCIBIOS_DEVICE_NOT_FOUND; | ||
139 | |||
140 | *value = le32_to_cpu(*pci_addr); | ||
141 | |||
142 | /* | ||
143 | * Check if the value is an address on the bus. If true, add the | ||
144 | * base address of the PCI memory or PCI I/O area on the Hades. | ||
145 | */ | ||
146 | |||
147 | if ((result = hades_read_config_byte(dev, PCI_HEADER_TYPE, | ||
148 | &header_type)) != PCIBIOS_SUCCESSFUL) | ||
149 | return result; | ||
150 | |||
151 | if (((where >= PCI_BASE_ADDRESS_0) && (where <= PCI_BASE_ADDRESS_1)) || | ||
152 | ((header_type != PCI_HEADER_TYPE_BRIDGE) && ((where >= PCI_BASE_ADDRESS_2) && | ||
153 | (where <= PCI_BASE_ADDRESS_5)))) | ||
154 | { | ||
155 | if ((*value & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_IO) | ||
156 | { | ||
157 | /* | ||
158 | * Base address register that contains an I/O address. If the | ||
159 | * address is valid on the Hades (0 <= *value < HADES_VIRT_IO_SIZE), | ||
160 | * add 'pci_io_base_virt' to the value. | ||
161 | */ | ||
162 | |||
163 | if (*value < HADES_VIRT_IO_SIZE) | ||
164 | *value += pci_io_base_virt; | ||
165 | } | ||
166 | else | ||
167 | { | ||
168 | /* | ||
169 | * Base address register that contains an memory address. If the | ||
170 | * address is valid on the Hades (0 <= *value < HADES_MEM_SIZE), | ||
171 | * add HADES_MEM_BASE to the value. | ||
172 | */ | ||
173 | |||
174 | if (*value == 0) | ||
175 | { | ||
176 | /* | ||
177 | * Base address is 0. Test if this base | ||
178 | * address register is used. | ||
179 | */ | ||
180 | |||
181 | *pci_addr = 0xffffffff; | ||
182 | if (*pci_addr != 0) | ||
183 | { | ||
184 | *pci_addr = *value; | ||
185 | if (*value < HADES_MEM_SIZE) | ||
186 | *value += HADES_MEM_BASE; | ||
187 | } | ||
188 | } | ||
189 | else | ||
190 | { | ||
191 | if (*value < HADES_MEM_SIZE) | ||
192 | *value += HADES_MEM_BASE; | ||
193 | } | ||
194 | } | ||
195 | } | ||
196 | |||
197 | return PCIBIOS_SUCCESSFUL; | ||
198 | } | ||
199 | |||
200 | static int hades_write_config_byte(struct pci_dev *dev, int where, u8 value) | ||
201 | { | ||
202 | volatile unsigned char *pci_addr; | ||
203 | |||
204 | if ((pci_addr = (unsigned char *) mk_conf_addr(dev, where)) == NULL) | ||
205 | return PCIBIOS_DEVICE_NOT_FOUND; | ||
206 | |||
207 | *pci_addr = value; | ||
208 | |||
209 | return PCIBIOS_SUCCESSFUL; | ||
210 | } | ||
211 | |||
212 | static int hades_write_config_word(struct pci_dev *dev, int where, u16 value) | ||
213 | { | ||
214 | volatile unsigned short *pci_addr; | ||
215 | |||
216 | if ((pci_addr = (unsigned short *) mk_conf_addr(dev, where)) == NULL) | ||
217 | return PCIBIOS_DEVICE_NOT_FOUND; | ||
218 | |||
219 | *pci_addr = cpu_to_le16(value); | ||
220 | |||
221 | return PCIBIOS_SUCCESSFUL; | ||
222 | } | ||
223 | |||
224 | static int hades_write_config_dword(struct pci_dev *dev, int where, u32 value) | ||
225 | { | ||
226 | volatile unsigned int *pci_addr; | ||
227 | unsigned char header_type; | ||
228 | int result; | ||
229 | |||
230 | if ((pci_addr = (unsigned int *) mk_conf_addr(dev, where)) == NULL) | ||
231 | return PCIBIOS_DEVICE_NOT_FOUND; | ||
232 | |||
233 | /* | ||
234 | * Check if the value is an address on the bus. If true, subtract the | ||
235 | * base address of the PCI memory or PCI I/O area on the Hades. | ||
236 | */ | ||
237 | |||
238 | if ((result = hades_read_config_byte(dev, PCI_HEADER_TYPE, | ||
239 | &header_type)) != PCIBIOS_SUCCESSFUL) | ||
240 | return result; | ||
241 | |||
242 | if (((where >= PCI_BASE_ADDRESS_0) && (where <= PCI_BASE_ADDRESS_1)) || | ||
243 | ((header_type != PCI_HEADER_TYPE_BRIDGE) && ((where >= PCI_BASE_ADDRESS_2) && | ||
244 | (where <= PCI_BASE_ADDRESS_5)))) | ||
245 | { | ||
246 | if ((value & PCI_BASE_ADDRESS_SPACE) == | ||
247 | PCI_BASE_ADDRESS_SPACE_IO) | ||
248 | { | ||
249 | /* | ||
250 | * I/O address. Check if the address is valid address on | ||
251 | * the Hades (pci_io_base_virt <= value < pci_io_base_virt + | ||
252 | * HADES_VIRT_IO_SIZE) or if the value is 0xffffffff. If not | ||
253 | * true do not write the base address register. If it is a | ||
254 | * valid base address subtract 'pci_io_base_virt' from the value. | ||
255 | */ | ||
256 | |||
257 | if ((value >= pci_io_base_virt) && (value < (pci_io_base_virt + | ||
258 | HADES_VIRT_IO_SIZE))) | ||
259 | value -= pci_io_base_virt; | ||
260 | else | ||
261 | { | ||
262 | if (value != 0xffffffff) | ||
263 | return PCIBIOS_SET_FAILED; | ||
264 | } | ||
265 | } | ||
266 | else | ||
267 | { | ||
268 | /* | ||
269 | * Memory address. Check if the address is valid address on | ||
270 | * the Hades (HADES_MEM_BASE <= value < HADES_MEM_BASE + HADES_MEM_SIZE) or | ||
271 | * if the value is 0xffffffff. If not true do not write | ||
272 | * the base address register. If it is a valid base address | ||
273 | * subtract HADES_MEM_BASE from the value. | ||
274 | */ | ||
275 | |||
276 | if ((value >= HADES_MEM_BASE) && (value < (HADES_MEM_BASE + HADES_MEM_SIZE))) | ||
277 | value -= HADES_MEM_BASE; | ||
278 | else | ||
279 | { | ||
280 | if (value != 0xffffffff) | ||
281 | return PCIBIOS_SET_FAILED; | ||
282 | } | ||
283 | } | ||
284 | } | ||
285 | |||
286 | *pci_addr = cpu_to_le32(value); | ||
287 | |||
288 | return PCIBIOS_SUCCESSFUL; | ||
289 | } | ||
290 | |||
291 | /* | ||
292 | * static inline void hades_fixup(void) | ||
293 | * | ||
294 | * Assign IRQ numbers as used by Linux to the interrupt pins | ||
295 | * of the PCI cards. | ||
296 | */ | ||
297 | |||
298 | static void __init hades_fixup(int pci_modify) | ||
299 | { | ||
300 | char irq_tab[4] = { | ||
301 | [0] = IRQ_TT_MFP_IO0, /* Slot 0. */ | ||
302 | [1] = IRQ_TT_MFP_IO1, /* Slot 1. */ | ||
303 | [2] = IRQ_TT_MFP_SCC, /* Slot 2. */ | ||
304 | [3] = IRQ_TT_MFP_SCSIDMA /* Slot 3. */ | ||
305 | }; | ||
306 | struct pci_dev *dev = NULL; | ||
307 | unsigned char slot; | ||
308 | |||
309 | /* | ||
310 | * Go through all devices, fixing up irqs as we see fit: | ||
311 | */ | ||
312 | |||
313 | while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) | ||
314 | { | ||
315 | if (dev->class >> 16 != PCI_BASE_CLASS_BRIDGE) | ||
316 | { | ||
317 | slot = PCI_SLOT(dev->devfn); /* Determine slot number. */ | ||
318 | dev->irq = irq_tab[slot]; | ||
319 | if (pci_modify) | ||
320 | pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq); | ||
321 | } | ||
322 | } | ||
323 | } | ||
324 | |||
325 | /* | ||
326 | * static void hades_conf_device(struct pci_dev *dev) | ||
327 | * | ||
328 | * Machine dependent Configure the given device. | ||
329 | * | ||
330 | * Parameters: | ||
331 | * | ||
332 | * dev - the pci device. | ||
333 | */ | ||
334 | |||
335 | static void __init hades_conf_device(struct pci_dev *dev) | ||
336 | { | ||
337 | pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, 0); | ||
338 | } | ||
339 | |||
340 | static struct pci_ops hades_pci_ops = { | ||
341 | .read_byte = hades_read_config_byte, | ||
342 | .read_word = hades_read_config_word, | ||
343 | .read_dword = hades_read_config_dword, | ||
344 | .write_byte = hades_write_config_byte, | ||
345 | .write_word = hades_write_config_word, | ||
346 | .write_dword = hades_write_config_dword | ||
347 | }; | ||
348 | |||
349 | /* | ||
350 | * struct pci_bus_info *init_hades_pci(void) | ||
351 | * | ||
352 | * Machine specific initialisation: | ||
353 | * | ||
354 | * - Allocate and initialise a 'pci_bus_info' structure | ||
355 | * - Initialise hardware | ||
356 | * | ||
357 | * Result: pointer to 'pci_bus_info' structure. | ||
358 | */ | ||
359 | |||
360 | struct pci_bus_info * __init init_hades_pci(void) | ||
361 | { | ||
362 | struct pci_bus_info *bus; | ||
363 | int i; | ||
364 | |||
365 | /* | ||
366 | * Remap I/O and configuration space. | ||
367 | */ | ||
368 | |||
369 | pci_io_base_virt = (unsigned long) ioremap(HADES_IO_BASE, HADES_VIRT_IO_SIZE); | ||
370 | |||
371 | for (i = 0; i < N_SLOTS; i++) | ||
372 | pci_conf_base_virt[i] = (unsigned long) ioremap(pci_conf_base_phys[i], 0x10000); | ||
373 | |||
374 | /* | ||
375 | * Allocate memory for bus info structure. | ||
376 | */ | ||
377 | |||
378 | bus = kzalloc(sizeof(struct pci_bus_info), GFP_KERNEL); | ||
379 | if (unlikely(!bus)) | ||
380 | goto iounmap_base_virt; | ||
381 | |||
382 | /* | ||
383 | * Claim resources. The m68k has no separate I/O space, both | ||
384 | * PCI memory space and PCI I/O space are in memory space. Therefore | ||
385 | * the I/O resources are requested in memory space as well. | ||
386 | */ | ||
387 | |||
388 | if (unlikely(request_resource(&iomem_resource, &config_space) != 0)) | ||
389 | goto free_bus; | ||
390 | |||
391 | if (unlikely(request_resource(&iomem_resource, &io_space) != 0)) | ||
392 | goto release_config_space; | ||
393 | |||
394 | bus->mem_space.start = HADES_MEM_BASE; | ||
395 | bus->mem_space.end = HADES_MEM_BASE + HADES_MEM_SIZE - 1; | ||
396 | bus->mem_space.name = pci_mem_name; | ||
397 | #if 1 | ||
398 | if (unlikely(request_resource(&iomem_resource, &bus->mem_space) != 0)) | ||
399 | goto release_io_space; | ||
400 | #endif | ||
401 | bus->io_space.start = pci_io_base_virt; | ||
402 | bus->io_space.end = pci_io_base_virt + HADES_VIRT_IO_SIZE - 1; | ||
403 | bus->io_space.name = pci_io_name; | ||
404 | #if 1 | ||
405 | if (unlikely(request_resource(&ioport_resource, &bus->io_space) != 0)) | ||
406 | goto release_bus_mem_space; | ||
407 | #endif | ||
408 | /* | ||
409 | * Set hardware dependent functions. | ||
410 | */ | ||
411 | |||
412 | bus->m68k_pci_ops = &hades_pci_ops; | ||
413 | bus->fixup = hades_fixup; | ||
414 | bus->conf_device = hades_conf_device; | ||
415 | |||
416 | /* | ||
417 | * Select high to low edge for PCI interrupts. | ||
418 | */ | ||
419 | |||
420 | tt_mfp.active_edge &= ~0x27; | ||
421 | |||
422 | return bus; | ||
423 | |||
424 | release_bus_mem_space: | ||
425 | release_resource(&bus->mem_space); | ||
426 | release_io_space: | ||
427 | release_resource(&io_space); | ||
428 | release_config_space: | ||
429 | release_resource(&config_space); | ||
430 | free_bus: | ||
431 | kfree(bus); | ||
432 | iounmap_base_virt: | ||
433 | iounmap((void *)pci_io_base_virt); | ||
434 | |||
435 | for (i = 0; i < N_SLOTS; i++) | ||
436 | iounmap((void *)pci_conf_base_virt[i]); | ||
437 | |||
438 | return NULL; | ||
439 | } | ||
440 | #endif | ||
diff --git a/arch/m68k/atari/time.c b/arch/m68k/atari/time.c index e0d3c8bfb408..1edde27fa32d 100644 --- a/arch/m68k/atari/time.c +++ b/arch/m68k/atari/time.c | |||
@@ -20,6 +20,9 @@ | |||
20 | 20 | ||
21 | #include <asm/atariints.h> | 21 | #include <asm/atariints.h> |
22 | 22 | ||
23 | DEFINE_SPINLOCK(rtc_lock); | ||
24 | EXPORT_SYMBOL_GPL(rtc_lock); | ||
25 | |||
23 | void __init | 26 | void __init |
24 | atari_sched_init(irq_handler_t timer_routine) | 27 | atari_sched_init(irq_handler_t timer_routine) |
25 | { | 28 | { |
@@ -191,13 +194,14 @@ int atari_tt_hwclk( int op, struct rtc_time *t ) | |||
191 | } | 194 | } |
192 | 195 | ||
193 | if (!(ctrl & RTC_DM_BINARY)) { | 196 | if (!(ctrl & RTC_DM_BINARY)) { |
194 | BIN_TO_BCD(sec); | 197 | sec = bin2bcd(sec); |
195 | BIN_TO_BCD(min); | 198 | min = bin2bcd(min); |
196 | BIN_TO_BCD(hour); | 199 | hour = bin2bcd(hour); |
197 | BIN_TO_BCD(day); | 200 | day = bin2bcd(day); |
198 | BIN_TO_BCD(mon); | 201 | mon = bin2bcd(mon); |
199 | BIN_TO_BCD(year); | 202 | year = bin2bcd(year); |
200 | if (wday >= 0) BIN_TO_BCD(wday); | 203 | if (wday >= 0) |
204 | wday = bin2bcd(wday); | ||
201 | } | 205 | } |
202 | } | 206 | } |
203 | 207 | ||
@@ -252,13 +256,13 @@ int atari_tt_hwclk( int op, struct rtc_time *t ) | |||
252 | } | 256 | } |
253 | 257 | ||
254 | if (!(ctrl & RTC_DM_BINARY)) { | 258 | if (!(ctrl & RTC_DM_BINARY)) { |
255 | BCD_TO_BIN(sec); | 259 | sec = bcd2bin(sec); |
256 | BCD_TO_BIN(min); | 260 | min = bcd2bin(min); |
257 | BCD_TO_BIN(hour); | 261 | hour = bcd2bin(hour); |
258 | BCD_TO_BIN(day); | 262 | day = bcd2bin(day); |
259 | BCD_TO_BIN(mon); | 263 | mon = bcd2bin(mon); |
260 | BCD_TO_BIN(year); | 264 | year = bcd2bin(year); |
261 | BCD_TO_BIN(wday); | 265 | wday = bcd2bin(wday); |
262 | } | 266 | } |
263 | 267 | ||
264 | if (!(ctrl & RTC_24H)) { | 268 | if (!(ctrl & RTC_24H)) { |
@@ -318,7 +322,7 @@ int atari_tt_set_clock_mmss (unsigned long nowtime) | |||
318 | 322 | ||
319 | rtc_minutes = RTC_READ (RTC_MINUTES); | 323 | rtc_minutes = RTC_READ (RTC_MINUTES); |
320 | if (!(save_control & RTC_DM_BINARY)) | 324 | if (!(save_control & RTC_DM_BINARY)) |
321 | BCD_TO_BIN (rtc_minutes); | 325 | rtc_minutes = bcd2bin(rtc_minutes); |
322 | 326 | ||
323 | /* Since we're only adjusting minutes and seconds, don't interfere | 327 | /* Since we're only adjusting minutes and seconds, don't interfere |
324 | with hour overflow. This avoids messing with unknown time zones | 328 | with hour overflow. This avoids messing with unknown time zones |
@@ -329,8 +333,8 @@ int atari_tt_set_clock_mmss (unsigned long nowtime) | |||
329 | { | 333 | { |
330 | if (!(save_control & RTC_DM_BINARY)) | 334 | if (!(save_control & RTC_DM_BINARY)) |
331 | { | 335 | { |
332 | BIN_TO_BCD (real_seconds); | 336 | real_seconds = bin2bcd(real_seconds); |
333 | BIN_TO_BCD (real_minutes); | 337 | real_minutes = bin2bcd(real_minutes); |
334 | } | 338 | } |
335 | RTC_WRITE (RTC_SECONDS, real_seconds); | 339 | RTC_WRITE (RTC_SECONDS, real_seconds); |
336 | RTC_WRITE (RTC_MINUTES, real_minutes); | 340 | RTC_WRITE (RTC_MINUTES, real_minutes); |
diff --git a/arch/m68k/bvme6000/config.c b/arch/m68k/bvme6000/config.c index 9433a88a33c4..65c9204ab9ac 100644 --- a/arch/m68k/bvme6000/config.c +++ b/arch/m68k/bvme6000/config.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/genhd.h> | 25 | #include <linux/genhd.h> |
26 | #include <linux/rtc.h> | 26 | #include <linux/rtc.h> |
27 | #include <linux/interrupt.h> | 27 | #include <linux/interrupt.h> |
28 | #include <linux/bcd.h> | ||
28 | 29 | ||
29 | #include <asm/bootinfo.h> | 30 | #include <asm/bootinfo.h> |
30 | #include <asm/system.h> | 31 | #include <asm/system.h> |
@@ -46,9 +47,6 @@ extern void bvme6000_reset (void); | |||
46 | extern void bvme6000_waitbut(void); | 47 | extern void bvme6000_waitbut(void); |
47 | void bvme6000_set_vectors (void); | 48 | void bvme6000_set_vectors (void); |
48 | 49 | ||
49 | static unsigned char bcd2bin (unsigned char b); | ||
50 | static unsigned char bin2bcd (unsigned char b); | ||
51 | |||
52 | /* Save tick handler routine pointer, will point to do_timer() in | 50 | /* Save tick handler routine pointer, will point to do_timer() in |
53 | * kernel/sched.c, called via bvme6000_process_int() */ | 51 | * kernel/sched.c, called via bvme6000_process_int() */ |
54 | 52 | ||
@@ -264,17 +262,6 @@ unsigned long bvme6000_gettimeoffset (void) | |||
264 | return v; | 262 | return v; |
265 | } | 263 | } |
266 | 264 | ||
267 | static unsigned char bcd2bin (unsigned char b) | ||
268 | { | ||
269 | return ((b>>4)*10 + (b&15)); | ||
270 | } | ||
271 | |||
272 | static unsigned char bin2bcd (unsigned char b) | ||
273 | { | ||
274 | return (((b/10)*16) + (b%10)); | ||
275 | } | ||
276 | |||
277 | |||
278 | /* | 265 | /* |
279 | * Looks like op is non-zero for setting the clock, and zero for | 266 | * Looks like op is non-zero for setting the clock, and zero for |
280 | * reading the clock. | 267 | * reading the clock. |
diff --git a/arch/m68k/bvme6000/rtc.c b/arch/m68k/bvme6000/rtc.c index e8ac3f7d72df..808c9018b115 100644 --- a/arch/m68k/bvme6000/rtc.c +++ b/arch/m68k/bvme6000/rtc.c | |||
@@ -57,16 +57,16 @@ static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd, | |||
57 | rtc->msr = 0x40; | 57 | rtc->msr = 0x40; |
58 | memset(&wtime, 0, sizeof(struct rtc_time)); | 58 | memset(&wtime, 0, sizeof(struct rtc_time)); |
59 | do { | 59 | do { |
60 | wtime.tm_sec = BCD2BIN(rtc->bcd_sec); | 60 | wtime.tm_sec = bcd2bin(rtc->bcd_sec); |
61 | wtime.tm_min = BCD2BIN(rtc->bcd_min); | 61 | wtime.tm_min = bcd2bin(rtc->bcd_min); |
62 | wtime.tm_hour = BCD2BIN(rtc->bcd_hr); | 62 | wtime.tm_hour = bcd2bin(rtc->bcd_hr); |
63 | wtime.tm_mday = BCD2BIN(rtc->bcd_dom); | 63 | wtime.tm_mday = bcd2bin(rtc->bcd_dom); |
64 | wtime.tm_mon = BCD2BIN(rtc->bcd_mth)-1; | 64 | wtime.tm_mon = bcd2bin(rtc->bcd_mth)-1; |
65 | wtime.tm_year = BCD2BIN(rtc->bcd_year); | 65 | wtime.tm_year = bcd2bin(rtc->bcd_year); |
66 | if (wtime.tm_year < 70) | 66 | if (wtime.tm_year < 70) |
67 | wtime.tm_year += 100; | 67 | wtime.tm_year += 100; |
68 | wtime.tm_wday = BCD2BIN(rtc->bcd_dow)-1; | 68 | wtime.tm_wday = bcd2bin(rtc->bcd_dow)-1; |
69 | } while (wtime.tm_sec != BCD2BIN(rtc->bcd_sec)); | 69 | } while (wtime.tm_sec != bcd2bin(rtc->bcd_sec)); |
70 | rtc->msr = msr; | 70 | rtc->msr = msr; |
71 | local_irq_restore(flags); | 71 | local_irq_restore(flags); |
72 | return copy_to_user(argp, &wtime, sizeof wtime) ? | 72 | return copy_to_user(argp, &wtime, sizeof wtime) ? |
@@ -114,14 +114,14 @@ static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd, | |||
114 | 114 | ||
115 | rtc->t0cr_rtmr = yrs%4; | 115 | rtc->t0cr_rtmr = yrs%4; |
116 | rtc->bcd_tenms = 0; | 116 | rtc->bcd_tenms = 0; |
117 | rtc->bcd_sec = BIN2BCD(sec); | 117 | rtc->bcd_sec = bin2bcd(sec); |
118 | rtc->bcd_min = BIN2BCD(min); | 118 | rtc->bcd_min = bin2bcd(min); |
119 | rtc->bcd_hr = BIN2BCD(hrs); | 119 | rtc->bcd_hr = bin2bcd(hrs); |
120 | rtc->bcd_dom = BIN2BCD(day); | 120 | rtc->bcd_dom = bin2bcd(day); |
121 | rtc->bcd_mth = BIN2BCD(mon); | 121 | rtc->bcd_mth = bin2bcd(mon); |
122 | rtc->bcd_year = BIN2BCD(yrs%100); | 122 | rtc->bcd_year = bin2bcd(yrs%100); |
123 | if (rtc_tm.tm_wday >= 0) | 123 | if (rtc_tm.tm_wday >= 0) |
124 | rtc->bcd_dow = BIN2BCD(rtc_tm.tm_wday+1); | 124 | rtc->bcd_dow = bin2bcd(rtc_tm.tm_wday+1); |
125 | rtc->t0cr_rtmr = yrs%4 | 0x08; | 125 | rtc->t0cr_rtmr = yrs%4 | 0x08; |
126 | 126 | ||
127 | rtc->msr = msr; | 127 | rtc->msr = msr; |
diff --git a/arch/m68k/kernel/Makefile b/arch/m68k/kernel/Makefile index 3a7f62225504..55d5d6b680a2 100644 --- a/arch/m68k/kernel/Makefile +++ b/arch/m68k/kernel/Makefile | |||
@@ -14,5 +14,4 @@ obj-y := entry.o process.o traps.o ints.o signal.o ptrace.o module.o \ | |||
14 | 14 | ||
15 | devres-y = ../../../kernel/irq/devres.o | 15 | devres-y = ../../../kernel/irq/devres.o |
16 | 16 | ||
17 | obj-$(CONFIG_PCI) += bios32.o | ||
18 | obj-y$(CONFIG_MMU_SUN3) += dma.o # no, it's not a typo | 17 | obj-y$(CONFIG_MMU_SUN3) += dma.o # no, it's not a typo |
diff --git a/arch/m68k/kernel/bios32.c b/arch/m68k/kernel/bios32.c deleted file mode 100644 index af170c2be735..000000000000 --- a/arch/m68k/kernel/bios32.c +++ /dev/null | |||
@@ -1,514 +0,0 @@ | |||
1 | /* | ||
2 | * bios32.c - PCI BIOS functions for m68k systems. | ||
3 | * | ||
4 | * Written by Wout Klaren. | ||
5 | * | ||
6 | * Based on the DEC Alpha bios32.c by Dave Rusling and David Mosberger. | ||
7 | */ | ||
8 | |||
9 | #include <linux/init.h> | ||
10 | #include <linux/kernel.h> | ||
11 | |||
12 | #if 0 | ||
13 | # define DBG_DEVS(args) printk args | ||
14 | #else | ||
15 | # define DBG_DEVS(args) | ||
16 | #endif | ||
17 | |||
18 | #ifdef CONFIG_PCI | ||
19 | |||
20 | /* | ||
21 | * PCI support for Linux/m68k. Currently only the Hades is supported. | ||
22 | * | ||
23 | * The support for PCI bridges in the DEC Alpha version has | ||
24 | * been removed in this version. | ||
25 | */ | ||
26 | |||
27 | #include <linux/pci.h> | ||
28 | #include <linux/slab.h> | ||
29 | #include <linux/mm.h> | ||
30 | |||
31 | #include <asm/io.h> | ||
32 | #include <asm/pci.h> | ||
33 | #include <asm/uaccess.h> | ||
34 | |||
35 | #define KB 1024 | ||
36 | #define MB (1024*KB) | ||
37 | #define GB (1024*MB) | ||
38 | |||
39 | #define MAJOR_REV 0 | ||
40 | #define MINOR_REV 5 | ||
41 | |||
42 | /* | ||
43 | * Align VAL to ALIGN, which must be a power of two. | ||
44 | */ | ||
45 | |||
46 | #define ALIGN(val,align) (((val) + ((align) - 1)) & ~((align) - 1)) | ||
47 | |||
48 | /* | ||
49 | * Offsets relative to the I/O and memory base addresses from where resources | ||
50 | * are allocated. | ||
51 | */ | ||
52 | |||
53 | #define IO_ALLOC_OFFSET 0x00004000 | ||
54 | #define MEM_ALLOC_OFFSET 0x04000000 | ||
55 | |||
56 | /* | ||
57 | * Declarations of hardware specific initialisation functions. | ||
58 | */ | ||
59 | |||
60 | extern struct pci_bus_info *init_hades_pci(void); | ||
61 | |||
62 | /* | ||
63 | * Bus info structure of the PCI bus. A pointer to this structure is | ||
64 | * put in the sysdata member of the pci_bus structure. | ||
65 | */ | ||
66 | |||
67 | static struct pci_bus_info *bus_info; | ||
68 | |||
69 | static int pci_modify = 1; /* If set, layout the PCI bus ourself. */ | ||
70 | static int skip_vga; /* If set do not modify base addresses | ||
71 | of vga cards.*/ | ||
72 | static int disable_pci_burst; /* If set do not allow PCI bursts. */ | ||
73 | |||
74 | static unsigned int io_base; | ||
75 | static unsigned int mem_base; | ||
76 | |||
77 | /* | ||
78 | * static void disable_dev(struct pci_dev *dev) | ||
79 | * | ||
80 | * Disable PCI device DEV so that it does not respond to I/O or memory | ||
81 | * accesses. | ||
82 | * | ||
83 | * Parameters: | ||
84 | * | ||
85 | * dev - device to disable. | ||
86 | */ | ||
87 | |||
88 | static void __init disable_dev(struct pci_dev *dev) | ||
89 | { | ||
90 | unsigned short cmd; | ||
91 | |||
92 | if (((dev->class >> 8 == PCI_CLASS_NOT_DEFINED_VGA) || | ||
93 | (dev->class >> 8 == PCI_CLASS_DISPLAY_VGA) || | ||
94 | (dev->class >> 8 == PCI_CLASS_DISPLAY_XGA)) && skip_vga) | ||
95 | return; | ||
96 | |||
97 | pci_read_config_word(dev, PCI_COMMAND, &cmd); | ||
98 | |||
99 | cmd &= (~PCI_COMMAND_IO & ~PCI_COMMAND_MEMORY & ~PCI_COMMAND_MASTER); | ||
100 | pci_write_config_word(dev, PCI_COMMAND, cmd); | ||
101 | } | ||
102 | |||
103 | /* | ||
104 | * static void layout_dev(struct pci_dev *dev) | ||
105 | * | ||
106 | * Layout memory and I/O for a device. | ||
107 | * | ||
108 | * Parameters: | ||
109 | * | ||
110 | * device - device to layout memory and I/O for. | ||
111 | */ | ||
112 | |||
113 | static void __init layout_dev(struct pci_dev *dev) | ||
114 | { | ||
115 | unsigned short cmd; | ||
116 | unsigned int base, mask, size, reg; | ||
117 | unsigned int alignto; | ||
118 | int i; | ||
119 | |||
120 | /* | ||
121 | * Skip video cards if requested. | ||
122 | */ | ||
123 | |||
124 | if (((dev->class >> 8 == PCI_CLASS_NOT_DEFINED_VGA) || | ||
125 | (dev->class >> 8 == PCI_CLASS_DISPLAY_VGA) || | ||
126 | (dev->class >> 8 == PCI_CLASS_DISPLAY_XGA)) && skip_vga) | ||
127 | return; | ||
128 | |||
129 | pci_read_config_word(dev, PCI_COMMAND, &cmd); | ||
130 | |||
131 | for (reg = PCI_BASE_ADDRESS_0, i = 0; reg <= PCI_BASE_ADDRESS_5; reg += 4, i++) | ||
132 | { | ||
133 | /* | ||
134 | * Figure out how much space and of what type this | ||
135 | * device wants. | ||
136 | */ | ||
137 | |||
138 | pci_write_config_dword(dev, reg, 0xffffffff); | ||
139 | pci_read_config_dword(dev, reg, &base); | ||
140 | |||
141 | if (!base) | ||
142 | { | ||
143 | /* this base-address register is unused */ | ||
144 | dev->resource[i].start = 0; | ||
145 | dev->resource[i].end = 0; | ||
146 | dev->resource[i].flags = 0; | ||
147 | continue; | ||
148 | } | ||
149 | |||
150 | /* | ||
151 | * We've read the base address register back after | ||
152 | * writing all ones and so now we must decode it. | ||
153 | */ | ||
154 | |||
155 | if (base & PCI_BASE_ADDRESS_SPACE_IO) | ||
156 | { | ||
157 | /* | ||
158 | * I/O space base address register. | ||
159 | */ | ||
160 | |||
161 | cmd |= PCI_COMMAND_IO; | ||
162 | |||
163 | base &= PCI_BASE_ADDRESS_IO_MASK; | ||
164 | mask = (~base << 1) | 0x1; | ||
165 | size = (mask & base) & 0xffffffff; | ||
166 | |||
167 | /* | ||
168 | * Align to multiple of size of minimum base. | ||
169 | */ | ||
170 | |||
171 | alignto = max_t(unsigned int, 0x040, size); | ||
172 | base = ALIGN(io_base, alignto); | ||
173 | io_base = base + size; | ||
174 | pci_write_config_dword(dev, reg, base | PCI_BASE_ADDRESS_SPACE_IO); | ||
175 | |||
176 | dev->resource[i].start = base; | ||
177 | dev->resource[i].end = dev->resource[i].start + size - 1; | ||
178 | dev->resource[i].flags = IORESOURCE_IO | PCI_BASE_ADDRESS_SPACE_IO; | ||
179 | |||
180 | DBG_DEVS(("layout_dev: IO address: %lX\n", base)); | ||
181 | } | ||
182 | else | ||
183 | { | ||
184 | unsigned int type; | ||
185 | |||
186 | /* | ||
187 | * Memory space base address register. | ||
188 | */ | ||
189 | |||
190 | cmd |= PCI_COMMAND_MEMORY; | ||
191 | type = base & PCI_BASE_ADDRESS_MEM_TYPE_MASK; | ||
192 | base &= PCI_BASE_ADDRESS_MEM_MASK; | ||
193 | mask = (~base << 1) | 0x1; | ||
194 | size = (mask & base) & 0xffffffff; | ||
195 | switch (type) | ||
196 | { | ||
197 | case PCI_BASE_ADDRESS_MEM_TYPE_32: | ||
198 | case PCI_BASE_ADDRESS_MEM_TYPE_64: | ||
199 | break; | ||
200 | |||
201 | case PCI_BASE_ADDRESS_MEM_TYPE_1M: | ||
202 | printk("bios32 WARNING: slot %d, function %d " | ||
203 | "requests memory below 1MB---don't " | ||
204 | "know how to do that.\n", | ||
205 | PCI_SLOT(dev->devfn), | ||
206 | PCI_FUNC(dev->devfn)); | ||
207 | continue; | ||
208 | } | ||
209 | |||
210 | /* | ||
211 | * Align to multiple of size of minimum base. | ||
212 | */ | ||
213 | |||
214 | alignto = max_t(unsigned int, 0x1000, size); | ||
215 | base = ALIGN(mem_base, alignto); | ||
216 | mem_base = base + size; | ||
217 | pci_write_config_dword(dev, reg, base); | ||
218 | |||
219 | dev->resource[i].start = base; | ||
220 | dev->resource[i].end = dev->resource[i].start + size - 1; | ||
221 | dev->resource[i].flags = IORESOURCE_MEM; | ||
222 | |||
223 | if (type == PCI_BASE_ADDRESS_MEM_TYPE_64) | ||
224 | { | ||
225 | /* | ||
226 | * 64-bit address, set the highest 32 bits | ||
227 | * to zero. | ||
228 | */ | ||
229 | |||
230 | reg += 4; | ||
231 | pci_write_config_dword(dev, reg, 0); | ||
232 | |||
233 | i++; | ||
234 | dev->resource[i].start = 0; | ||
235 | dev->resource[i].end = 0; | ||
236 | dev->resource[i].flags = 0; | ||
237 | } | ||
238 | } | ||
239 | } | ||
240 | |||
241 | /* | ||
242 | * Enable device: | ||
243 | */ | ||
244 | |||
245 | if (dev->class >> 8 == PCI_CLASS_NOT_DEFINED || | ||
246 | dev->class >> 8 == PCI_CLASS_NOT_DEFINED_VGA || | ||
247 | dev->class >> 8 == PCI_CLASS_DISPLAY_VGA || | ||
248 | dev->class >> 8 == PCI_CLASS_DISPLAY_XGA) | ||
249 | { | ||
250 | /* | ||
251 | * All of these (may) have I/O scattered all around | ||
252 | * and may not use i/o-base address registers at all. | ||
253 | * So we just have to always enable I/O to these | ||
254 | * devices. | ||
255 | */ | ||
256 | cmd |= PCI_COMMAND_IO; | ||
257 | } | ||
258 | |||
259 | pci_write_config_word(dev, PCI_COMMAND, cmd | PCI_COMMAND_MASTER); | ||
260 | |||
261 | pci_write_config_byte(dev, PCI_LATENCY_TIMER, (disable_pci_burst) ? 0 : 32); | ||
262 | |||
263 | if (bus_info != NULL) | ||
264 | bus_info->conf_device(dev); /* Machine dependent configuration. */ | ||
265 | |||
266 | DBG_DEVS(("layout_dev: bus %d slot 0x%x VID 0x%x DID 0x%x class 0x%x\n", | ||
267 | dev->bus->number, PCI_SLOT(dev->devfn), dev->vendor, dev->device, dev->class)); | ||
268 | } | ||
269 | |||
270 | /* | ||
271 | * static void layout_bus(struct pci_bus *bus) | ||
272 | * | ||
273 | * Layout memory and I/O for all devices on the given bus. | ||
274 | * | ||
275 | * Parameters: | ||
276 | * | ||
277 | * bus - bus. | ||
278 | */ | ||
279 | |||
280 | static void __init layout_bus(struct pci_bus *bus) | ||
281 | { | ||
282 | unsigned int bio, bmem; | ||
283 | struct pci_dev *dev; | ||
284 | |||
285 | DBG_DEVS(("layout_bus: starting bus %d\n", bus->number)); | ||
286 | |||
287 | if (!bus->devices && !bus->children) | ||
288 | return; | ||
289 | |||
290 | /* | ||
291 | * Align the current bases on appropriate boundaries (4K for | ||
292 | * IO and 1MB for memory). | ||
293 | */ | ||
294 | |||
295 | bio = io_base = ALIGN(io_base, 4*KB); | ||
296 | bmem = mem_base = ALIGN(mem_base, 1*MB); | ||
297 | |||
298 | /* | ||
299 | * PCI devices might have been setup by a PCI BIOS emulation | ||
300 | * running under TOS. In these cases there is a | ||
301 | * window during which two devices may have an overlapping | ||
302 | * address range. To avoid this causing trouble, we first | ||
303 | * turn off the I/O and memory address decoders for all PCI | ||
304 | * devices. They'll be re-enabled only once all address | ||
305 | * decoders are programmed consistently. | ||
306 | */ | ||
307 | |||
308 | DBG_DEVS(("layout_bus: disable_dev for bus %d\n", bus->number)); | ||
309 | |||
310 | for (dev = bus->devices; dev; dev = dev->sibling) | ||
311 | { | ||
312 | if ((dev->class >> 16 != PCI_BASE_CLASS_BRIDGE) || | ||
313 | (dev->class >> 8 == PCI_CLASS_BRIDGE_PCMCIA)) | ||
314 | disable_dev(dev); | ||
315 | } | ||
316 | |||
317 | /* | ||
318 | * Allocate space to each device: | ||
319 | */ | ||
320 | |||
321 | DBG_DEVS(("layout_bus: starting bus %d devices\n", bus->number)); | ||
322 | |||
323 | for (dev = bus->devices; dev; dev = dev->sibling) | ||
324 | { | ||
325 | if ((dev->class >> 16 != PCI_BASE_CLASS_BRIDGE) || | ||
326 | (dev->class >> 8 == PCI_CLASS_BRIDGE_PCMCIA)) | ||
327 | layout_dev(dev); | ||
328 | } | ||
329 | |||
330 | DBG_DEVS(("layout_bus: bus %d finished\n", bus->number)); | ||
331 | } | ||
332 | |||
333 | /* | ||
334 | * static void pcibios_fixup(void) | ||
335 | * | ||
336 | * Layout memory and I/O of all devices on the PCI bus if 'pci_modify' is | ||
337 | * true. This might be necessary because not every m68k machine with a PCI | ||
338 | * bus has a PCI BIOS. This function should be called right after | ||
339 | * pci_scan_bus() in pcibios_init(). | ||
340 | */ | ||
341 | |||
342 | static void __init pcibios_fixup(void) | ||
343 | { | ||
344 | if (pci_modify) | ||
345 | { | ||
346 | /* | ||
347 | * Set base addresses for allocation of I/O and memory space. | ||
348 | */ | ||
349 | |||
350 | io_base = bus_info->io_space.start + IO_ALLOC_OFFSET; | ||
351 | mem_base = bus_info->mem_space.start + MEM_ALLOC_OFFSET; | ||
352 | |||
353 | /* | ||
354 | * Scan the tree, allocating PCI memory and I/O space. | ||
355 | */ | ||
356 | |||
357 | layout_bus(pci_bus_b(pci_root.next)); | ||
358 | } | ||
359 | |||
360 | /* | ||
361 | * Fix interrupt assignments, etc. | ||
362 | */ | ||
363 | |||
364 | bus_info->fixup(pci_modify); | ||
365 | } | ||
366 | |||
367 | /* | ||
368 | * static void pcibios_claim_resources(struct pci_bus *bus) | ||
369 | * | ||
370 | * Claim all resources that are assigned to devices on the given bus. | ||
371 | * | ||
372 | * Parameters: | ||
373 | * | ||
374 | * bus - bus. | ||
375 | */ | ||
376 | |||
377 | static void __init pcibios_claim_resources(struct pci_bus *bus) | ||
378 | { | ||
379 | struct pci_dev *dev; | ||
380 | int i; | ||
381 | |||
382 | while (bus) | ||
383 | { | ||
384 | for (dev = bus->devices; (dev != NULL); dev = dev->sibling) | ||
385 | { | ||
386 | for (i = 0; i < PCI_NUM_RESOURCES; i++) | ||
387 | { | ||
388 | struct resource *r = &dev->resource[i]; | ||
389 | struct resource *pr; | ||
390 | struct pci_bus_info *bus_info = (struct pci_bus_info *) dev->sysdata; | ||
391 | |||
392 | if ((r->start == 0) || (r->parent != NULL)) | ||
393 | continue; | ||
394 | #if 1 | ||
395 | if (r->flags & IORESOURCE_IO) | ||
396 | pr = &bus_info->io_space; | ||
397 | else | ||
398 | pr = &bus_info->mem_space; | ||
399 | #else | ||
400 | if (r->flags & IORESOURCE_IO) | ||
401 | pr = &ioport_resource; | ||
402 | else | ||
403 | pr = &iomem_resource; | ||
404 | #endif | ||
405 | if (request_resource(pr, r) < 0) | ||
406 | { | ||
407 | printk(KERN_ERR "PCI: Address space collision on region %d of device %s\n", i, dev->name); | ||
408 | } | ||
409 | } | ||
410 | } | ||
411 | |||
412 | if (bus->children) | ||
413 | pcibios_claim_resources(bus->children); | ||
414 | |||
415 | bus = bus->next; | ||
416 | } | ||
417 | } | ||
418 | |||
419 | /* | ||
420 | * int pcibios_assign_resource(struct pci_dev *dev, int i) | ||
421 | * | ||
422 | * Assign a new address to a PCI resource. | ||
423 | * | ||
424 | * Parameters: | ||
425 | * | ||
426 | * dev - device. | ||
427 | * i - resource. | ||
428 | * | ||
429 | * Result: 0 if successful. | ||
430 | */ | ||
431 | |||
432 | int __init pcibios_assign_resource(struct pci_dev *dev, int i) | ||
433 | { | ||
434 | struct resource *r = &dev->resource[i]; | ||
435 | struct resource *pr = pci_find_parent_resource(dev, r); | ||
436 | unsigned long size = r->end + 1; | ||
437 | |||
438 | if (!pr) | ||
439 | return -EINVAL; | ||
440 | |||
441 | if (r->flags & IORESOURCE_IO) | ||
442 | { | ||
443 | if (size > 0x100) | ||
444 | return -EFBIG; | ||
445 | |||
446 | if (allocate_resource(pr, r, size, bus_info->io_space.start + | ||
447 | IO_ALLOC_OFFSET, bus_info->io_space.end, 1024)) | ||
448 | return -EBUSY; | ||
449 | } | ||
450 | else | ||
451 | { | ||
452 | if (allocate_resource(pr, r, size, bus_info->mem_space.start + | ||
453 | MEM_ALLOC_OFFSET, bus_info->mem_space.end, size)) | ||
454 | return -EBUSY; | ||
455 | } | ||
456 | |||
457 | if (i < 6) | ||
458 | pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + 4 * i, r->start); | ||
459 | |||
460 | return 0; | ||
461 | } | ||
462 | |||
463 | void __init pcibios_fixup_bus(struct pci_bus *bus) | ||
464 | { | ||
465 | struct pci_dev *dev; | ||
466 | void *sysdata; | ||
467 | |||
468 | sysdata = (bus->parent) ? bus->parent->sysdata : bus->sysdata; | ||
469 | |||
470 | for (dev = bus->devices; (dev != NULL); dev = dev->sibling) | ||
471 | dev->sysdata = sysdata; | ||
472 | } | ||
473 | |||
474 | void __init pcibios_init(void) | ||
475 | { | ||
476 | printk("Linux/m68k PCI BIOS32 revision %x.%02x\n", MAJOR_REV, MINOR_REV); | ||
477 | |||
478 | bus_info = NULL; | ||
479 | #ifdef CONFIG_HADES | ||
480 | if (MACH_IS_HADES) | ||
481 | bus_info = init_hades_pci(); | ||
482 | #endif | ||
483 | if (bus_info != NULL) | ||
484 | { | ||
485 | printk("PCI: Probing PCI hardware\n"); | ||
486 | pci_scan_bus(0, bus_info->m68k_pci_ops, bus_info); | ||
487 | pcibios_fixup(); | ||
488 | pcibios_claim_resources(pci_root); | ||
489 | } | ||
490 | else | ||
491 | printk("PCI: No PCI bus detected\n"); | ||
492 | } | ||
493 | |||
494 | char * __init pcibios_setup(char *str) | ||
495 | { | ||
496 | if (!strcmp(str, "nomodify")) | ||
497 | { | ||
498 | pci_modify = 0; | ||
499 | return NULL; | ||
500 | } | ||
501 | else if (!strcmp(str, "skipvga")) | ||
502 | { | ||
503 | skip_vga = 1; | ||
504 | return NULL; | ||
505 | } | ||
506 | else if (!strcmp(str, "noburst")) | ||
507 | { | ||
508 | disable_pci_burst = 1; | ||
509 | return NULL; | ||
510 | } | ||
511 | |||
512 | return str; | ||
513 | } | ||
514 | #endif /* CONFIG_PCI */ | ||
diff --git a/arch/m68k/kernel/dma.c b/arch/m68k/kernel/dma.c index 6f8c080dd9f9..2bb4245404d8 100644 --- a/arch/m68k/kernel/dma.c +++ b/arch/m68k/kernel/dma.c | |||
@@ -66,8 +66,8 @@ void dma_free_coherent(struct device *dev, size_t size, | |||
66 | } | 66 | } |
67 | EXPORT_SYMBOL(dma_free_coherent); | 67 | EXPORT_SYMBOL(dma_free_coherent); |
68 | 68 | ||
69 | inline void dma_sync_single_for_device(struct device *dev, dma_addr_t handle, size_t size, | 69 | void dma_sync_single_for_device(struct device *dev, dma_addr_t handle, |
70 | enum dma_data_direction dir) | 70 | size_t size, enum dma_data_direction dir) |
71 | { | 71 | { |
72 | switch (dir) { | 72 | switch (dir) { |
73 | case DMA_TO_DEVICE: | 73 | case DMA_TO_DEVICE: |
diff --git a/arch/m68k/kernel/ints.c b/arch/m68k/kernel/ints.c index ded7dd2f67b2..7e8a0d394e61 100644 --- a/arch/m68k/kernel/ints.c +++ b/arch/m68k/kernel/ints.c | |||
@@ -429,8 +429,9 @@ int show_interrupts(struct seq_file *p, void *v) | |||
429 | return 0; | 429 | return 0; |
430 | } | 430 | } |
431 | 431 | ||
432 | #ifdef CONFIG_PROC_FS | ||
432 | void init_irq_proc(void) | 433 | void init_irq_proc(void) |
433 | { | 434 | { |
434 | /* Insert /proc/irq driver here */ | 435 | /* Insert /proc/irq driver here */ |
435 | } | 436 | } |
436 | 437 | #endif | |
diff --git a/arch/m68k/kernel/process.c b/arch/m68k/kernel/process.c index 7888cdf91f5d..3042c2bc8c58 100644 --- a/arch/m68k/kernel/process.c +++ b/arch/m68k/kernel/process.c | |||
@@ -78,7 +78,7 @@ unsigned long thread_saved_pc(struct task_struct *tsk) | |||
78 | static void default_idle(void) | 78 | static void default_idle(void) |
79 | { | 79 | { |
80 | if (!need_resched()) | 80 | if (!need_resched()) |
81 | #if defined(MACH_ATARI_ONLY) && !defined(CONFIG_HADES) | 81 | #if defined(MACH_ATARI_ONLY) |
82 | /* block out HSYNC on the atari (falcon) */ | 82 | /* block out HSYNC on the atari (falcon) */ |
83 | __asm__("stop #0x2200" : : : "cc"); | 83 | __asm__("stop #0x2200" : : : "cc"); |
84 | #else | 84 | #else |
diff --git a/arch/m68k/kernel/traps.c b/arch/m68k/kernel/traps.c index 75b8340b254b..6d813de2baf1 100644 --- a/arch/m68k/kernel/traps.c +++ b/arch/m68k/kernel/traps.c | |||
@@ -883,8 +883,7 @@ void show_trace(unsigned long *stack) | |||
883 | if (i % 5 == 0) | 883 | if (i % 5 == 0) |
884 | printk("\n "); | 884 | printk("\n "); |
885 | #endif | 885 | #endif |
886 | printk(" [<%08lx>]", addr); | 886 | printk(" [<%08lx>] %pS\n", addr, (void *)addr); |
887 | print_symbol(" %s\n", addr); | ||
888 | i++; | 887 | i++; |
889 | } | 888 | } |
890 | } | 889 | } |
@@ -900,10 +899,8 @@ void show_registers(struct pt_regs *regs) | |||
900 | int i; | 899 | int i; |
901 | 900 | ||
902 | print_modules(); | 901 | print_modules(); |
903 | printk("PC: [<%08lx>]",regs->pc); | 902 | printk("PC: [<%08lx>] %pS\n", regs->pc, (void *)regs->pc); |
904 | print_symbol(" %s", regs->pc); | 903 | printk("SR: %04x SP: %p a2: %08lx\n", regs->sr, regs, regs->a2); |
905 | printk("\nSR: %04x SP: %p a2: %08lx\n", | ||
906 | regs->sr, regs, regs->a2); | ||
907 | printk("d0: %08lx d1: %08lx d2: %08lx d3: %08lx\n", | 904 | printk("d0: %08lx d1: %08lx d2: %08lx d3: %08lx\n", |
908 | regs->d0, regs->d1, regs->d2, regs->d3); | 905 | regs->d0, regs->d1, regs->d2, regs->d3); |
909 | printk("d4: %08lx d5: %08lx a0: %08lx a1: %08lx\n", | 906 | printk("d4: %08lx d5: %08lx a0: %08lx a1: %08lx\n", |
diff --git a/arch/m68k/kernel/vmlinux-std.lds b/arch/m68k/kernel/vmlinux-std.lds index 99b0784c0552..f846d4e3e5e1 100644 --- a/arch/m68k/kernel/vmlinux-std.lds +++ b/arch/m68k/kernel/vmlinux-std.lds | |||
@@ -34,10 +34,10 @@ SECTIONS | |||
34 | CONSTRUCTORS | 34 | CONSTRUCTORS |
35 | } | 35 | } |
36 | 36 | ||
37 | .bss : { *(.bss) } /* BSS */ | ||
38 | |||
39 | . = ALIGN(16); | 37 | . = ALIGN(16); |
40 | .data.cacheline_aligned : { *(.data.cacheline_aligned) } :data | 38 | .data.cacheline_aligned : { *(.data.cacheline_aligned) } |
39 | |||
40 | .bss : { *(.bss) } /* BSS */ | ||
41 | 41 | ||
42 | _edata = .; /* End of data section */ | 42 | _edata = .; /* End of data section */ |
43 | 43 | ||
@@ -48,7 +48,7 @@ SECTIONS | |||
48 | _sinittext = .; | 48 | _sinittext = .; |
49 | INIT_TEXT | 49 | INIT_TEXT |
50 | _einittext = .; | 50 | _einittext = .; |
51 | } | 51 | } :data |
52 | .init.data : { INIT_DATA } | 52 | .init.data : { INIT_DATA } |
53 | . = ALIGN(16); | 53 | . = ALIGN(16); |
54 | __setup_start = .; | 54 | __setup_start = .; |
@@ -74,6 +74,7 @@ SECTIONS | |||
74 | .init.ramfs : { *(.init.ramfs) } | 74 | .init.ramfs : { *(.init.ramfs) } |
75 | __initramfs_end = .; | 75 | __initramfs_end = .; |
76 | #endif | 76 | #endif |
77 | NOTES | ||
77 | . = ALIGN(8192); | 78 | . = ALIGN(8192); |
78 | __init_end = .; | 79 | __init_end = .; |
79 | 80 | ||
diff --git a/arch/m68k/mm/kmap.c b/arch/m68k/mm/kmap.c index 46b7d6035aab..df620ac2a296 100644 --- a/arch/m68k/mm/kmap.c +++ b/arch/m68k/mm/kmap.c | |||
@@ -66,8 +66,10 @@ static struct vm_struct *get_io_area(unsigned long size) | |||
66 | for (p = &iolist; (tmp = *p) ; p = &tmp->next) { | 66 | for (p = &iolist; (tmp = *p) ; p = &tmp->next) { |
67 | if (size + addr < (unsigned long)tmp->addr) | 67 | if (size + addr < (unsigned long)tmp->addr) |
68 | break; | 68 | break; |
69 | if (addr > KMAP_END-size) | 69 | if (addr > KMAP_END-size) { |
70 | kfree(area); | ||
70 | return NULL; | 71 | return NULL; |
72 | } | ||
71 | addr = tmp->size + (unsigned long)tmp->addr; | 73 | addr = tmp->size + (unsigned long)tmp->addr; |
72 | } | 74 | } |
73 | area->addr = (void *)addr; | 75 | area->addr = (void *)addr; |
diff --git a/arch/m68k/mvme16x/rtc.c b/arch/m68k/mvme16x/rtc.c index 432a9f13b2ed..cea5e3e4e636 100644 --- a/arch/m68k/mvme16x/rtc.c +++ b/arch/m68k/mvme16x/rtc.c | |||
@@ -52,15 +52,15 @@ static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd, | |||
52 | /* Ensure clock and real-time-mode-register are accessible */ | 52 | /* Ensure clock and real-time-mode-register are accessible */ |
53 | rtc->ctrl = RTC_READ; | 53 | rtc->ctrl = RTC_READ; |
54 | memset(&wtime, 0, sizeof(struct rtc_time)); | 54 | memset(&wtime, 0, sizeof(struct rtc_time)); |
55 | wtime.tm_sec = BCD2BIN(rtc->bcd_sec); | 55 | wtime.tm_sec = bcd2bin(rtc->bcd_sec); |
56 | wtime.tm_min = BCD2BIN(rtc->bcd_min); | 56 | wtime.tm_min = bcd2bin(rtc->bcd_min); |
57 | wtime.tm_hour = BCD2BIN(rtc->bcd_hr); | 57 | wtime.tm_hour = bcd2bin(rtc->bcd_hr); |
58 | wtime.tm_mday = BCD2BIN(rtc->bcd_dom); | 58 | wtime.tm_mday = bcd2bin(rtc->bcd_dom); |
59 | wtime.tm_mon = BCD2BIN(rtc->bcd_mth)-1; | 59 | wtime.tm_mon = bcd2bin(rtc->bcd_mth)-1; |
60 | wtime.tm_year = BCD2BIN(rtc->bcd_year); | 60 | wtime.tm_year = bcd2bin(rtc->bcd_year); |
61 | if (wtime.tm_year < 70) | 61 | if (wtime.tm_year < 70) |
62 | wtime.tm_year += 100; | 62 | wtime.tm_year += 100; |
63 | wtime.tm_wday = BCD2BIN(rtc->bcd_dow)-1; | 63 | wtime.tm_wday = bcd2bin(rtc->bcd_dow)-1; |
64 | rtc->ctrl = 0; | 64 | rtc->ctrl = 0; |
65 | local_irq_restore(flags); | 65 | local_irq_restore(flags); |
66 | return copy_to_user(argp, &wtime, sizeof wtime) ? | 66 | return copy_to_user(argp, &wtime, sizeof wtime) ? |
@@ -104,12 +104,12 @@ static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd, | |||
104 | local_irq_save(flags); | 104 | local_irq_save(flags); |
105 | rtc->ctrl = RTC_WRITE; | 105 | rtc->ctrl = RTC_WRITE; |
106 | 106 | ||
107 | rtc->bcd_sec = BIN2BCD(sec); | 107 | rtc->bcd_sec = bin2bcd(sec); |
108 | rtc->bcd_min = BIN2BCD(min); | 108 | rtc->bcd_min = bin2bcd(min); |
109 | rtc->bcd_hr = BIN2BCD(hrs); | 109 | rtc->bcd_hr = bin2bcd(hrs); |
110 | rtc->bcd_dom = BIN2BCD(day); | 110 | rtc->bcd_dom = bin2bcd(day); |
111 | rtc->bcd_mth = BIN2BCD(mon); | 111 | rtc->bcd_mth = bin2bcd(mon); |
112 | rtc->bcd_year = BIN2BCD(yrs%100); | 112 | rtc->bcd_year = bin2bcd(yrs%100); |
113 | 113 | ||
114 | rtc->ctrl = 0; | 114 | rtc->ctrl = 0; |
115 | local_irq_restore(flags); | 115 | local_irq_restore(flags); |
diff --git a/arch/m68k/q40/config.c b/arch/m68k/q40/config.c index be9de2f3dc48..9c7eefa3f98a 100644 --- a/arch/m68k/q40/config.c +++ b/arch/m68k/q40/config.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <linux/serial_reg.h> | 23 | #include <linux/serial_reg.h> |
24 | #include <linux/rtc.h> | 24 | #include <linux/rtc.h> |
25 | #include <linux/vt_kern.h> | 25 | #include <linux/vt_kern.h> |
26 | #include <linux/bcd.h> | ||
26 | 27 | ||
27 | #include <asm/io.h> | 28 | #include <asm/io.h> |
28 | #include <asm/rtc.h> | 29 | #include <asm/rtc.h> |
@@ -216,17 +217,6 @@ int q40_parse_bootinfo(const struct bi_record *rec) | |||
216 | } | 217 | } |
217 | 218 | ||
218 | 219 | ||
219 | static inline unsigned char bcd2bin(unsigned char b) | ||
220 | { | ||
221 | return (b >> 4) * 10 + (b & 15); | ||
222 | } | ||
223 | |||
224 | static inline unsigned char bin2bcd(unsigned char b) | ||
225 | { | ||
226 | return (b / 10) * 16 + (b % 10); | ||
227 | } | ||
228 | |||
229 | |||
230 | static unsigned long q40_gettimeoffset(void) | 220 | static unsigned long q40_gettimeoffset(void) |
231 | { | 221 | { |
232 | return 5000 * (ql_ticks != 0); | 222 | return 5000 * (ql_ticks != 0); |
diff --git a/arch/m68k/sun3x/time.c b/arch/m68k/sun3x/time.c index f5eaafb00d21..536a04aaf22f 100644 --- a/arch/m68k/sun3x/time.c +++ b/arch/m68k/sun3x/time.c | |||
@@ -47,23 +47,23 @@ int sun3x_hwclk(int set, struct rtc_time *t) | |||
47 | 47 | ||
48 | if(set) { | 48 | if(set) { |
49 | h->csr |= C_WRITE; | 49 | h->csr |= C_WRITE; |
50 | h->sec = BIN2BCD(t->tm_sec); | 50 | h->sec = bin2bcd(t->tm_sec); |
51 | h->min = BIN2BCD(t->tm_min); | 51 | h->min = bin2bcd(t->tm_min); |
52 | h->hour = BIN2BCD(t->tm_hour); | 52 | h->hour = bin2bcd(t->tm_hour); |
53 | h->wday = BIN2BCD(t->tm_wday); | 53 | h->wday = bin2bcd(t->tm_wday); |
54 | h->mday = BIN2BCD(t->tm_mday); | 54 | h->mday = bin2bcd(t->tm_mday); |
55 | h->month = BIN2BCD(t->tm_mon); | 55 | h->month = bin2bcd(t->tm_mon); |
56 | h->year = BIN2BCD(t->tm_year); | 56 | h->year = bin2bcd(t->tm_year); |
57 | h->csr &= ~C_WRITE; | 57 | h->csr &= ~C_WRITE; |
58 | } else { | 58 | } else { |
59 | h->csr |= C_READ; | 59 | h->csr |= C_READ; |
60 | t->tm_sec = BCD2BIN(h->sec); | 60 | t->tm_sec = bcd2bin(h->sec); |
61 | t->tm_min = BCD2BIN(h->min); | 61 | t->tm_min = bcd2bin(h->min); |
62 | t->tm_hour = BCD2BIN(h->hour); | 62 | t->tm_hour = bcd2bin(h->hour); |
63 | t->tm_wday = BCD2BIN(h->wday); | 63 | t->tm_wday = bcd2bin(h->wday); |
64 | t->tm_mday = BCD2BIN(h->mday); | 64 | t->tm_mday = bcd2bin(h->mday); |
65 | t->tm_mon = BCD2BIN(h->month); | 65 | t->tm_mon = bcd2bin(h->month); |
66 | t->tm_year = BCD2BIN(h->year); | 66 | t->tm_year = bcd2bin(h->year); |
67 | h->csr &= ~C_READ; | 67 | h->csr &= ~C_READ; |
68 | } | 68 | } |
69 | 69 | ||
diff --git a/arch/x86/kernel/rtc.c b/arch/x86/kernel/rtc.c index 05191bbc68b8..0a23b5795b25 100644 --- a/arch/x86/kernel/rtc.c +++ b/arch/x86/kernel/rtc.c | |||
@@ -223,11 +223,25 @@ static struct platform_device rtc_device = { | |||
223 | static __init int add_rtc_cmos(void) | 223 | static __init int add_rtc_cmos(void) |
224 | { | 224 | { |
225 | #ifdef CONFIG_PNP | 225 | #ifdef CONFIG_PNP |
226 | if (!pnp_platform_devices) | 226 | static const char *ids[] __initconst = |
227 | platform_device_register(&rtc_device); | 227 | { "PNP0b00", "PNP0b01", "PNP0b02", }; |
228 | #else | 228 | struct pnp_dev *dev; |
229 | struct pnp_id *id; | ||
230 | int i; | ||
231 | |||
232 | pnp_for_each_dev(dev) { | ||
233 | for (id = dev->id; id; id = id->next) { | ||
234 | for (i = 0; i < ARRAY_SIZE(ids); i++) { | ||
235 | if (compare_pnp_id(id, ids[i]) != 0) | ||
236 | return 0; | ||
237 | } | ||
238 | } | ||
239 | } | ||
240 | #endif | ||
241 | |||
229 | platform_device_register(&rtc_device); | 242 | platform_device_register(&rtc_device); |
230 | #endif /* CONFIG_PNP */ | 243 | dev_info(&rtc_device.dev, |
244 | "registered platform RTC device (no PNP device found)\n"); | ||
231 | return 0; | 245 | return 0; |
232 | } | 246 | } |
233 | device_initcall(add_rtc_cmos); | 247 | device_initcall(add_rtc_cmos); |
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c index 3c578ef78c48..24649ada08df 100644 --- a/drivers/acpi/glue.c +++ b/drivers/acpi/glue.c | |||
@@ -260,115 +260,3 @@ static int __init init_acpi_device_notify(void) | |||
260 | } | 260 | } |
261 | 261 | ||
262 | arch_initcall(init_acpi_device_notify); | 262 | arch_initcall(init_acpi_device_notify); |
263 | |||
264 | |||
265 | #if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE) | ||
266 | |||
267 | #ifdef CONFIG_PM | ||
268 | static u32 rtc_handler(void *context) | ||
269 | { | ||
270 | acpi_clear_event(ACPI_EVENT_RTC); | ||
271 | acpi_disable_event(ACPI_EVENT_RTC, 0); | ||
272 | return ACPI_INTERRUPT_HANDLED; | ||
273 | } | ||
274 | |||
275 | static inline void rtc_wake_setup(void) | ||
276 | { | ||
277 | acpi_install_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler, NULL); | ||
278 | /* | ||
279 | * After the RTC handler is installed, the Fixed_RTC event should | ||
280 | * be disabled. Only when the RTC alarm is set will it be enabled. | ||
281 | */ | ||
282 | acpi_clear_event(ACPI_EVENT_RTC); | ||
283 | acpi_disable_event(ACPI_EVENT_RTC, 0); | ||
284 | } | ||
285 | |||
286 | static void rtc_wake_on(struct device *dev) | ||
287 | { | ||
288 | acpi_clear_event(ACPI_EVENT_RTC); | ||
289 | acpi_enable_event(ACPI_EVENT_RTC, 0); | ||
290 | } | ||
291 | |||
292 | static void rtc_wake_off(struct device *dev) | ||
293 | { | ||
294 | acpi_disable_event(ACPI_EVENT_RTC, 0); | ||
295 | } | ||
296 | #else | ||
297 | #define rtc_wake_setup() do{}while(0) | ||
298 | #define rtc_wake_on NULL | ||
299 | #define rtc_wake_off NULL | ||
300 | #endif | ||
301 | |||
302 | /* Every ACPI platform has a mc146818 compatible "cmos rtc". Here we find | ||
303 | * its device node and pass extra config data. This helps its driver use | ||
304 | * capabilities that the now-obsolete mc146818 didn't have, and informs it | ||
305 | * that this board's RTC is wakeup-capable (per ACPI spec). | ||
306 | */ | ||
307 | #include <linux/mc146818rtc.h> | ||
308 | |||
309 | static struct cmos_rtc_board_info rtc_info; | ||
310 | |||
311 | |||
312 | /* PNP devices are registered in a subsys_initcall(); | ||
313 | * ACPI specifies the PNP IDs to use. | ||
314 | */ | ||
315 | #include <linux/pnp.h> | ||
316 | |||
317 | static int __init pnp_match(struct device *dev, void *data) | ||
318 | { | ||
319 | static const char *ids[] = { "PNP0b00", "PNP0b01", "PNP0b02", }; | ||
320 | struct pnp_dev *pnp = to_pnp_dev(dev); | ||
321 | int i; | ||
322 | |||
323 | for (i = 0; i < ARRAY_SIZE(ids); i++) { | ||
324 | if (compare_pnp_id(pnp->id, ids[i]) != 0) | ||
325 | return 1; | ||
326 | } | ||
327 | return 0; | ||
328 | } | ||
329 | |||
330 | static struct device *__init get_rtc_dev(void) | ||
331 | { | ||
332 | return bus_find_device(&pnp_bus_type, NULL, NULL, pnp_match); | ||
333 | } | ||
334 | |||
335 | static int __init acpi_rtc_init(void) | ||
336 | { | ||
337 | struct device *dev = get_rtc_dev(); | ||
338 | |||
339 | if (acpi_disabled) | ||
340 | return 0; | ||
341 | |||
342 | if (dev) { | ||
343 | rtc_wake_setup(); | ||
344 | rtc_info.wake_on = rtc_wake_on; | ||
345 | rtc_info.wake_off = rtc_wake_off; | ||
346 | |||
347 | /* workaround bug in some ACPI tables */ | ||
348 | if (acpi_gbl_FADT.month_alarm && !acpi_gbl_FADT.day_alarm) { | ||
349 | DBG("bogus FADT month_alarm\n"); | ||
350 | acpi_gbl_FADT.month_alarm = 0; | ||
351 | } | ||
352 | |||
353 | rtc_info.rtc_day_alarm = acpi_gbl_FADT.day_alarm; | ||
354 | rtc_info.rtc_mon_alarm = acpi_gbl_FADT.month_alarm; | ||
355 | rtc_info.rtc_century = acpi_gbl_FADT.century; | ||
356 | |||
357 | /* NOTE: S4_RTC_WAKE is NOT currently useful to Linux */ | ||
358 | if (acpi_gbl_FADT.flags & ACPI_FADT_S4_RTC_WAKE) | ||
359 | printk(PREFIX "RTC can wake from S4\n"); | ||
360 | |||
361 | |||
362 | dev->platform_data = &rtc_info; | ||
363 | |||
364 | /* RTC always wakes from S1/S2/S3, and often S4/STD */ | ||
365 | device_init_wakeup(dev, 1); | ||
366 | |||
367 | put_device(dev); | ||
368 | } else | ||
369 | DBG("RTC unavailable?\n"); | ||
370 | return 0; | ||
371 | } | ||
372 | module_init(acpi_rtc_init); | ||
373 | |||
374 | #endif | ||
diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c index 49f274197b16..432cf4018291 100644 --- a/drivers/block/ataflop.c +++ b/drivers/block/ataflop.c | |||
@@ -1882,10 +1882,6 @@ static int __init atari_floppy_init (void) | |||
1882 | /* Amiga, Mac, ... don't have Atari-compatible floppy :-) */ | 1882 | /* Amiga, Mac, ... don't have Atari-compatible floppy :-) */ |
1883 | return -ENODEV; | 1883 | return -ENODEV; |
1884 | 1884 | ||
1885 | if (MACH_IS_HADES) | ||
1886 | /* Hades doesn't have Atari-compatible floppy */ | ||
1887 | return -ENODEV; | ||
1888 | |||
1889 | if (register_blkdev(FLOPPY_MAJOR,"fd")) | 1885 | if (register_blkdev(FLOPPY_MAJOR,"fd")) |
1890 | return -EBUSY; | 1886 | return -EBUSY; |
1891 | 1887 | ||
diff --git a/drivers/char/vt.c b/drivers/char/vt.c index 57029fefd64a..a0f7ffb68087 100644 --- a/drivers/char/vt.c +++ b/drivers/char/vt.c | |||
@@ -301,7 +301,7 @@ static void scrup(struct vc_data *vc, unsigned int t, unsigned int b, int nr) | |||
301 | d = (unsigned short *)(vc->vc_origin + vc->vc_size_row * t); | 301 | d = (unsigned short *)(vc->vc_origin + vc->vc_size_row * t); |
302 | s = (unsigned short *)(vc->vc_origin + vc->vc_size_row * (t + nr)); | 302 | s = (unsigned short *)(vc->vc_origin + vc->vc_size_row * (t + nr)); |
303 | scr_memmovew(d, s, (b - t - nr) * vc->vc_size_row); | 303 | scr_memmovew(d, s, (b - t - nr) * vc->vc_size_row); |
304 | scr_memsetw(d + (b - t - nr) * vc->vc_cols, vc->vc_scrl_erase_char, | 304 | scr_memsetw(d + (b - t - nr) * vc->vc_cols, vc->vc_video_erase_char, |
305 | vc->vc_size_row * nr); | 305 | vc->vc_size_row * nr); |
306 | } | 306 | } |
307 | 307 | ||
@@ -319,7 +319,7 @@ static void scrdown(struct vc_data *vc, unsigned int t, unsigned int b, int nr) | |||
319 | s = (unsigned short *)(vc->vc_origin + vc->vc_size_row * t); | 319 | s = (unsigned short *)(vc->vc_origin + vc->vc_size_row * t); |
320 | step = vc->vc_cols * nr; | 320 | step = vc->vc_cols * nr; |
321 | scr_memmovew(s + step, s, (b - t - nr) * vc->vc_size_row); | 321 | scr_memmovew(s + step, s, (b - t - nr) * vc->vc_size_row); |
322 | scr_memsetw(s, vc->vc_scrl_erase_char, 2 * step); | 322 | scr_memsetw(s, vc->vc_video_erase_char, 2 * step); |
323 | } | 323 | } |
324 | 324 | ||
325 | static void do_update_region(struct vc_data *vc, unsigned long start, int count) | 325 | static void do_update_region(struct vc_data *vc, unsigned long start, int count) |
@@ -434,7 +434,6 @@ static void update_attr(struct vc_data *vc) | |||
434 | vc->vc_blink, vc->vc_underline, | 434 | vc->vc_blink, vc->vc_underline, |
435 | vc->vc_reverse ^ vc->vc_decscnm, vc->vc_italic); | 435 | vc->vc_reverse ^ vc->vc_decscnm, vc->vc_italic); |
436 | vc->vc_video_erase_char = (build_attr(vc, vc->vc_color, 1, vc->vc_blink, 0, vc->vc_decscnm, 0) << 8) | ' '; | 436 | vc->vc_video_erase_char = (build_attr(vc, vc->vc_color, 1, vc->vc_blink, 0, vc->vc_decscnm, 0) << 8) | ' '; |
437 | vc->vc_scrl_erase_char = (build_attr(vc, vc->vc_def_color, 1, false, false, vc->vc_decscnm, false) << 8) | ' '; | ||
438 | } | 437 | } |
439 | 438 | ||
440 | /* Note: inverting the screen twice should revert to the original state */ | 439 | /* Note: inverting the screen twice should revert to the original state */ |
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index cacf89e65af4..da64108de775 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig | |||
@@ -17,6 +17,25 @@ config HID | |||
17 | tristate "Generic HID support" | 17 | tristate "Generic HID support" |
18 | depends on INPUT | 18 | depends on INPUT |
19 | default y | 19 | default y |
20 | select HID_A4TECH if !EMBEDDED | ||
21 | select HID_APPLE if !EMBEDDED | ||
22 | select HID_BELKIN if !EMBEDDED | ||
23 | select HID_BRIGHT if !EMBEDDED | ||
24 | select HID_CHERRY if !EMBEDDED | ||
25 | select HID_CHICONY if !EMBEDDED | ||
26 | select HID_CYPRESS if !EMBEDDED | ||
27 | select HID_DELL if !EMBEDDED | ||
28 | select HID_EZKEY if !EMBEDDED | ||
29 | select HID_GYRATION if !EMBEDDED | ||
30 | select HID_LOGITECH if !EMBEDDED | ||
31 | select HID_MICROSOFT if !EMBEDDED | ||
32 | select HID_MONTEREY if !EMBEDDED | ||
33 | select HID_PANTHERLORD if !EMBEDDED | ||
34 | select HID_PETALYNX if !EMBEDDED | ||
35 | select HID_SAMSUNG if !EMBEDDED | ||
36 | select HID_SONY if !EMBEDDED | ||
37 | select HID_SUNPLUS if !EMBEDDED | ||
38 | |||
20 | ---help--- | 39 | ---help--- |
21 | A human interface device (HID) is a type of computer device that | 40 | A human interface device (HID) is a type of computer device that |
22 | interacts directly with and takes input from humans. The term "HID" | 41 | interacts directly with and takes input from humans. The term "HID" |
@@ -67,4 +86,206 @@ config HIDRAW | |||
67 | 86 | ||
68 | source "drivers/hid/usbhid/Kconfig" | 87 | source "drivers/hid/usbhid/Kconfig" |
69 | 88 | ||
89 | menu "Special HID drivers" | ||
90 | depends on HID | ||
91 | |||
92 | config HID_COMPAT | ||
93 | bool "Load all HID drivers on hid core load" | ||
94 | default y | ||
95 | ---help--- | ||
96 | Compatible option for older userspace. If you have system without udev | ||
97 | support of module loading through aliases and also old | ||
98 | module-init-tools which can't handle hid bus, choose Y here. Otherwise | ||
99 | say N. If you say N and your userspace is old enough, the only | ||
100 | functionality you lose is modules autoloading. | ||
101 | |||
102 | If unsure, say Y. | ||
103 | |||
104 | config HID_A4TECH | ||
105 | tristate "A4 tech" | ||
106 | default m | ||
107 | depends on USB_HID | ||
108 | ---help--- | ||
109 | Support for A4 tech X5 and WOP-35 / Trust 450L mice. | ||
110 | |||
111 | config HID_APPLE | ||
112 | tristate "Apple" | ||
113 | default m | ||
114 | depends on (USB_HID || BT_HIDP) | ||
115 | ---help--- | ||
116 | Support for some Apple devices which less or more break | ||
117 | HID specification. | ||
118 | |||
119 | Say Y here if you want support for the special keys (Fn, Numlock) on | ||
120 | Apple iBooks, PowerBooks, MacBooks, MacBook Pros and aluminum USB | ||
121 | keyboards. | ||
122 | |||
123 | If unsure, say M. | ||
124 | |||
125 | config HID_BELKIN | ||
126 | tristate "Belkin" | ||
127 | default m | ||
128 | depends on USB_HID | ||
129 | ---help--- | ||
130 | Support for Belkin Flip KVM and Wireless keyboard. | ||
131 | |||
132 | config HID_BRIGHT | ||
133 | tristate "Bright" | ||
134 | default m | ||
135 | depends on USB_HID | ||
136 | ---help--- | ||
137 | Support for Bright ABNT-2 keyboard. | ||
138 | |||
139 | config HID_CHERRY | ||
140 | tristate "Cherry" | ||
141 | default m | ||
142 | depends on USB_HID | ||
143 | ---help--- | ||
144 | Support for Cherry Cymotion. | ||
145 | |||
146 | config HID_CHICONY | ||
147 | tristate "Chicony" | ||
148 | default m | ||
149 | depends on USB_HID | ||
150 | ---help--- | ||
151 | Support for Chicony Tactical pad. | ||
152 | |||
153 | config HID_CYPRESS | ||
154 | tristate "Cypress" | ||
155 | default m | ||
156 | depends on USB_HID | ||
157 | ---help--- | ||
158 | Support for Cypress mouse and barcodes. | ||
159 | |||
160 | config HID_DELL | ||
161 | tristate "Dell" | ||
162 | default m | ||
163 | depends on USB_HID | ||
164 | ---help--- | ||
165 | Support for Dell W7658. | ||
166 | |||
167 | config HID_EZKEY | ||
168 | tristate "Ezkey" | ||
169 | default m | ||
170 | depends on USB_HID | ||
171 | ---help--- | ||
172 | Support for Ezkey mouse and barcodes. | ||
173 | |||
174 | config HID_GYRATION | ||
175 | tristate "Gyration" | ||
176 | default m | ||
177 | depends on USB_HID | ||
178 | ---help--- | ||
179 | Support for Gyration remote. | ||
180 | |||
181 | config HID_LOGITECH | ||
182 | tristate "Logitech" | ||
183 | default m | ||
184 | depends on USB_HID | ||
185 | ---help--- | ||
186 | Support for some Logitech devices which breaks less or more | ||
187 | HID specification. | ||
188 | |||
189 | config LOGITECH_FF | ||
190 | bool "Logitech force feedback" | ||
191 | depends on HID_LOGITECH | ||
192 | select INPUT_FF_MEMLESS | ||
193 | help | ||
194 | Say Y here if you have one of these devices: | ||
195 | - Logitech WingMan Cordless RumblePad | ||
196 | - Logitech WingMan Cordless RumblePad 2 | ||
197 | - Logitech WingMan Force 3D | ||
198 | - Logitech Formula Force EX | ||
199 | - Logitech MOMO Force wheel | ||
200 | |||
201 | and if you want to enable force feedback for them. | ||
202 | Note: if you say N here, this device will still be supported, but without | ||
203 | force feedback. | ||
204 | |||
205 | config LOGIRUMBLEPAD2_FF | ||
206 | bool "Logitech Rumblepad 2 force feedback" | ||
207 | depends on HID_LOGITECH | ||
208 | select INPUT_FF_MEMLESS | ||
209 | help | ||
210 | Say Y here if you want to enable force feedback support for Logitech | ||
211 | Rumblepad 2 devices. | ||
212 | |||
213 | config HID_MICROSOFT | ||
214 | tristate "Microsoft" | ||
215 | default m | ||
216 | depends on USB_HID | ||
217 | ---help--- | ||
218 | Support for some Microsoft devices which breaks less or more | ||
219 | HID specification. | ||
220 | |||
221 | config HID_MONTEREY | ||
222 | tristate "Monterey" | ||
223 | default m | ||
224 | depends on USB_HID | ||
225 | ---help--- | ||
226 | Support for Monterey Genius KB29E. | ||
227 | |||
228 | config HID_PANTHERLORD | ||
229 | tristate "Pantherlord devices support" | ||
230 | default m | ||
231 | depends on USB_HID | ||
232 | ---help--- | ||
233 | Support for PantherLord/GreenAsia based device support. | ||
234 | |||
235 | |||
236 | config PANTHERLORD_FF | ||
237 | bool "Pantherlord force feedback support" | ||
238 | depends on HID_PANTHERLORD | ||
239 | select INPUT_FF_MEMLESS | ||
240 | help | ||
241 | Say Y here if you have a PantherLord/GreenAsia based game controller | ||
242 | or adapter and want to enable force feedback support for it. | ||
243 | |||
244 | config HID_PETALYNX | ||
245 | tristate "Petalynx" | ||
246 | default m | ||
247 | depends on USB_HID | ||
248 | ---help--- | ||
249 | Support for Petalynx Maxter remote. | ||
250 | |||
251 | config HID_SAMSUNG | ||
252 | tristate "Samsung" | ||
253 | default m | ||
254 | depends on USB_HID | ||
255 | ---help--- | ||
256 | Support for Samsung IR remote. | ||
257 | |||
258 | config HID_SONY | ||
259 | tristate "Sony" | ||
260 | default m | ||
261 | depends on USB_HID | ||
262 | ---help--- | ||
263 | Support for Sony PS3 controller. | ||
264 | |||
265 | config HID_SUNPLUS | ||
266 | tristate "Sunplus" | ||
267 | default m | ||
268 | depends on USB_HID | ||
269 | ---help--- | ||
270 | Support for Sunplus WDesktop input device. | ||
271 | |||
272 | config THRUSTMASTER_FF | ||
273 | tristate "ThrustMaster devices support" | ||
274 | default m | ||
275 | depends on USB_HID | ||
276 | select INPUT_FF_MEMLESS | ||
277 | help | ||
278 | Say Y here if you have a THRUSTMASTER FireStore Dual Power 2 or | ||
279 | a THRUSTMASTER Ferrari GT Rumble Force or Force Feedback Wheel. | ||
280 | |||
281 | config ZEROPLUS_FF | ||
282 | tristate "Zeroplus based game controller support" | ||
283 | default m | ||
284 | depends on USB_HID | ||
285 | select INPUT_FF_MEMLESS | ||
286 | help | ||
287 | Say Y here if you have a Zeroplus based game controller. | ||
288 | |||
289 | endmenu | ||
290 | |||
70 | endif # HID_SUPPORT | 291 | endif # HID_SUPPORT |
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile index 275dc522c738..b09e43e7413e 100644 --- a/drivers/hid/Makefile +++ b/drivers/hid/Makefile | |||
@@ -1,13 +1,46 @@ | |||
1 | # | 1 | # |
2 | # Makefile for the HID driver | 2 | # Makefile for the HID driver |
3 | # | 3 | # |
4 | hid-objs := hid-core.o hid-input.o hid-input-quirks.o | 4 | hid-objs := hid-core.o hid-input.o |
5 | 5 | ||
6 | obj-$(CONFIG_HID) += hid.o | 6 | obj-$(CONFIG_HID) += hid.o |
7 | 7 | ||
8 | hid-$(CONFIG_HID_DEBUG) += hid-debug.o | 8 | hid-$(CONFIG_HID_DEBUG) += hid-debug.o |
9 | hid-$(CONFIG_HIDRAW) += hidraw.o | 9 | hid-$(CONFIG_HIDRAW) += hidraw.o |
10 | 10 | ||
11 | ifdef CONFIG_HID_COMPAT | ||
12 | obj-m += hid-dummy.o | ||
13 | endif | ||
14 | |||
15 | hid-logitech-objs := hid-lg.o | ||
16 | ifdef CONFIG_LOGITECH_FF | ||
17 | hid-logitech-objs += hid-lgff.o | ||
18 | endif | ||
19 | ifdef CONFIG_LOGIRUMBLEPAD2_FF | ||
20 | hid-logitech-objs += hid-lg2ff.o | ||
21 | endif | ||
22 | |||
23 | obj-$(CONFIG_HID_A4TECH) += hid-a4tech.o | ||
24 | obj-$(CONFIG_HID_APPLE) += hid-apple.o | ||
25 | obj-$(CONFIG_HID_BELKIN) += hid-belkin.o | ||
26 | obj-$(CONFIG_HID_BRIGHT) += hid-bright.o | ||
27 | obj-$(CONFIG_HID_CHERRY) += hid-cherry.o | ||
28 | obj-$(CONFIG_HID_CHICONY) += hid-chicony.o | ||
29 | obj-$(CONFIG_HID_CYPRESS) += hid-cypress.o | ||
30 | obj-$(CONFIG_HID_DELL) += hid-dell.o | ||
31 | obj-$(CONFIG_HID_EZKEY) += hid-ezkey.o | ||
32 | obj-$(CONFIG_HID_GYRATION) += hid-gyration.o | ||
33 | obj-$(CONFIG_HID_LOGITECH) += hid-logitech.o | ||
34 | obj-$(CONFIG_HID_MICROSOFT) += hid-microsoft.o | ||
35 | obj-$(CONFIG_HID_MONTEREY) += hid-monterey.o | ||
36 | obj-$(CONFIG_HID_PANTHERLORD) += hid-pl.o | ||
37 | obj-$(CONFIG_HID_PETALYNX) += hid-petalynx.o | ||
38 | obj-$(CONFIG_HID_SAMSUNG) += hid-samsung.o | ||
39 | obj-$(CONFIG_HID_SONY) += hid-sony.o | ||
40 | obj-$(CONFIG_HID_SUNPLUS) += hid-sunplus.o | ||
41 | obj-$(CONFIG_THRUSTMASTER_FF) += hid-tmff.o | ||
42 | obj-$(CONFIG_ZEROPLUS_FF) += hid-zpff.o | ||
43 | |||
11 | obj-$(CONFIG_USB_HID) += usbhid/ | 44 | obj-$(CONFIG_USB_HID) += usbhid/ |
12 | obj-$(CONFIG_USB_MOUSE) += usbhid/ | 45 | obj-$(CONFIG_USB_MOUSE) += usbhid/ |
13 | obj-$(CONFIG_USB_KBD) += usbhid/ | 46 | obj-$(CONFIG_USB_KBD) += usbhid/ |
diff --git a/drivers/hid/hid-a4tech.c b/drivers/hid/hid-a4tech.c new file mode 100644 index 000000000000..ebca00e6c103 --- /dev/null +++ b/drivers/hid/hid-a4tech.c | |||
@@ -0,0 +1,162 @@ | |||
1 | /* | ||
2 | * HID driver for some a4tech "special" devices | ||
3 | * | ||
4 | * Copyright (c) 1999 Andreas Gal | ||
5 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> | ||
6 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc | ||
7 | * Copyright (c) 2006-2007 Jiri Kosina | ||
8 | * Copyright (c) 2007 Paul Walmsley | ||
9 | * Copyright (c) 2008 Jiri Slaby | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * This program is free software; you can redistribute it and/or modify it | ||
14 | * under the terms of the GNU General Public License as published by the Free | ||
15 | * Software Foundation; either version 2 of the License, or (at your option) | ||
16 | * any later version. | ||
17 | */ | ||
18 | |||
19 | #include <linux/device.h> | ||
20 | #include <linux/input.h> | ||
21 | #include <linux/hid.h> | ||
22 | #include <linux/module.h> | ||
23 | |||
24 | #include "hid-ids.h" | ||
25 | |||
26 | #define A4_2WHEEL_MOUSE_HACK_7 0x01 | ||
27 | #define A4_2WHEEL_MOUSE_HACK_B8 0x02 | ||
28 | |||
29 | struct a4tech_sc { | ||
30 | unsigned long quirks; | ||
31 | unsigned int hw_wheel; | ||
32 | __s32 delayed_value; | ||
33 | }; | ||
34 | |||
35 | static int a4_input_mapped(struct hid_device *hdev, struct hid_input *hi, | ||
36 | struct hid_field *field, struct hid_usage *usage, | ||
37 | unsigned long **bit, int *max) | ||
38 | { | ||
39 | struct a4tech_sc *a4 = hid_get_drvdata(hdev); | ||
40 | |||
41 | if (usage->type == EV_REL && usage->code == REL_WHEEL) | ||
42 | set_bit(REL_HWHEEL, *bit); | ||
43 | |||
44 | if ((a4->quirks & A4_2WHEEL_MOUSE_HACK_7) && usage->hid == 0x00090007) | ||
45 | return -1; | ||
46 | |||
47 | return 0; | ||
48 | } | ||
49 | |||
50 | static int a4_event(struct hid_device *hdev, struct hid_field *field, | ||
51 | struct hid_usage *usage, __s32 value) | ||
52 | { | ||
53 | struct a4tech_sc *a4 = hid_get_drvdata(hdev); | ||
54 | struct input_dev *input; | ||
55 | |||
56 | if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput || | ||
57 | !usage->type) | ||
58 | return 0; | ||
59 | |||
60 | input = field->hidinput->input; | ||
61 | |||
62 | if (a4->quirks & A4_2WHEEL_MOUSE_HACK_B8) { | ||
63 | if (usage->type == EV_REL && usage->code == REL_WHEEL) { | ||
64 | a4->delayed_value = value; | ||
65 | return 1; | ||
66 | } | ||
67 | |||
68 | if (usage->hid == 0x000100b8) { | ||
69 | input_event(input, EV_REL, value ? REL_HWHEEL : | ||
70 | REL_WHEEL, a4->delayed_value); | ||
71 | return 1; | ||
72 | } | ||
73 | } | ||
74 | |||
75 | if ((a4->quirks & A4_2WHEEL_MOUSE_HACK_7) && usage->hid == 0x00090007) { | ||
76 | a4->hw_wheel = !!value; | ||
77 | return 1; | ||
78 | } | ||
79 | |||
80 | if (usage->code == REL_WHEEL && a4->hw_wheel) { | ||
81 | input_event(input, usage->type, REL_HWHEEL, value); | ||
82 | return 1; | ||
83 | } | ||
84 | |||
85 | return 0; | ||
86 | } | ||
87 | |||
88 | static int a4_probe(struct hid_device *hdev, const struct hid_device_id *id) | ||
89 | { | ||
90 | struct a4tech_sc *a4; | ||
91 | int ret; | ||
92 | |||
93 | a4 = kzalloc(sizeof(*a4), GFP_KERNEL); | ||
94 | if (a4 == NULL) { | ||
95 | dev_err(&hdev->dev, "can't alloc device descriptor\n"); | ||
96 | ret = -ENOMEM; | ||
97 | goto err_free; | ||
98 | } | ||
99 | |||
100 | a4->quirks = id->driver_data; | ||
101 | |||
102 | hid_set_drvdata(hdev, a4); | ||
103 | |||
104 | ret = hid_parse(hdev); | ||
105 | if (ret) { | ||
106 | dev_err(&hdev->dev, "parse failed\n"); | ||
107 | goto err_free; | ||
108 | } | ||
109 | |||
110 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); | ||
111 | if (ret) { | ||
112 | dev_err(&hdev->dev, "hw start failed\n"); | ||
113 | goto err_free; | ||
114 | } | ||
115 | |||
116 | return 0; | ||
117 | err_free: | ||
118 | kfree(a4); | ||
119 | return ret; | ||
120 | } | ||
121 | |||
122 | static void a4_remove(struct hid_device *hdev) | ||
123 | { | ||
124 | struct a4tech_sc *a4 = hid_get_drvdata(hdev); | ||
125 | |||
126 | hid_hw_stop(hdev); | ||
127 | kfree(a4); | ||
128 | } | ||
129 | |||
130 | static const struct hid_device_id a4_devices[] = { | ||
131 | { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU), | ||
132 | .driver_data = A4_2WHEEL_MOUSE_HACK_7 }, | ||
133 | { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D), | ||
134 | .driver_data = A4_2WHEEL_MOUSE_HACK_B8 }, | ||
135 | { } | ||
136 | }; | ||
137 | MODULE_DEVICE_TABLE(hid, a4_devices); | ||
138 | |||
139 | static struct hid_driver a4_driver = { | ||
140 | .name = "a4tech", | ||
141 | .id_table = a4_devices, | ||
142 | .input_mapped = a4_input_mapped, | ||
143 | .event = a4_event, | ||
144 | .probe = a4_probe, | ||
145 | .remove = a4_remove, | ||
146 | }; | ||
147 | |||
148 | static int a4_init(void) | ||
149 | { | ||
150 | return hid_register_driver(&a4_driver); | ||
151 | } | ||
152 | |||
153 | static void a4_exit(void) | ||
154 | { | ||
155 | hid_unregister_driver(&a4_driver); | ||
156 | } | ||
157 | |||
158 | module_init(a4_init); | ||
159 | module_exit(a4_exit); | ||
160 | MODULE_LICENSE("GPL"); | ||
161 | |||
162 | HID_COMPAT_LOAD_DRIVER(a4tech); | ||
diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c new file mode 100644 index 000000000000..fd7f896b34f7 --- /dev/null +++ b/drivers/hid/hid-apple.c | |||
@@ -0,0 +1,484 @@ | |||
1 | /* | ||
2 | * USB HID quirks support for Linux | ||
3 | * | ||
4 | * Copyright (c) 1999 Andreas Gal | ||
5 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> | ||
6 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc | ||
7 | * Copyright (c) 2006-2007 Jiri Kosina | ||
8 | * Copyright (c) 2007 Paul Walmsley | ||
9 | * Copyright (c) 2008 Jiri Slaby <jirislaby@gmail.com> | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * This program is free software; you can redistribute it and/or modify it | ||
14 | * under the terms of the GNU General Public License as published by the Free | ||
15 | * Software Foundation; either version 2 of the License, or (at your option) | ||
16 | * any later version. | ||
17 | */ | ||
18 | |||
19 | #include <linux/device.h> | ||
20 | #include <linux/hid.h> | ||
21 | #include <linux/module.h> | ||
22 | #include <linux/usb.h> | ||
23 | |||
24 | #include "hid-ids.h" | ||
25 | |||
26 | #define APPLE_RDESC_JIS 0x0001 | ||
27 | #define APPLE_IGNORE_MOUSE 0x0002 | ||
28 | #define APPLE_HAS_FN 0x0004 | ||
29 | #define APPLE_HIDDEV 0x0008 | ||
30 | #define APPLE_ISO_KEYBOARD 0x0010 | ||
31 | #define APPLE_MIGHTYMOUSE 0x0020 | ||
32 | #define APPLE_INVERT_HWHEEL 0x0040 | ||
33 | #define APPLE_IGNORE_HIDINPUT 0x0080 | ||
34 | #define APPLE_NUMLOCK_EMULATION 0x0100 | ||
35 | |||
36 | #define APPLE_FLAG_FKEY 0x01 | ||
37 | |||
38 | static unsigned int fnmode = 1; | ||
39 | module_param(fnmode, uint, 0644); | ||
40 | MODULE_PARM_DESC(fnmode, "Mode of fn key on Apple keyboards (0 = disabled, " | ||
41 | "[1] = fkeyslast, 2 = fkeysfirst)"); | ||
42 | |||
43 | struct apple_sc { | ||
44 | unsigned long quirks; | ||
45 | unsigned int fn_on; | ||
46 | DECLARE_BITMAP(pressed_fn, KEY_CNT); | ||
47 | DECLARE_BITMAP(pressed_numlock, KEY_CNT); | ||
48 | }; | ||
49 | |||
50 | struct apple_key_translation { | ||
51 | u16 from; | ||
52 | u16 to; | ||
53 | u8 flags; | ||
54 | }; | ||
55 | |||
56 | static struct apple_key_translation apple_fn_keys[] = { | ||
57 | { KEY_BACKSPACE, KEY_DELETE }, | ||
58 | { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY }, | ||
59 | { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY }, | ||
60 | { KEY_F3, KEY_FN_F5, APPLE_FLAG_FKEY }, /* Exposé */ | ||
61 | { KEY_F4, KEY_FN_F4, APPLE_FLAG_FKEY }, /* Dashboard */ | ||
62 | { KEY_F5, KEY_KBDILLUMDOWN, APPLE_FLAG_FKEY }, | ||
63 | { KEY_F6, KEY_KBDILLUMUP, APPLE_FLAG_FKEY }, | ||
64 | { KEY_F7, KEY_PREVIOUSSONG, APPLE_FLAG_FKEY }, | ||
65 | { KEY_F8, KEY_PLAYPAUSE, APPLE_FLAG_FKEY }, | ||
66 | { KEY_F9, KEY_NEXTSONG, APPLE_FLAG_FKEY }, | ||
67 | { KEY_F10, KEY_MUTE, APPLE_FLAG_FKEY }, | ||
68 | { KEY_F11, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY }, | ||
69 | { KEY_F12, KEY_VOLUMEUP, APPLE_FLAG_FKEY }, | ||
70 | { KEY_UP, KEY_PAGEUP }, | ||
71 | { KEY_DOWN, KEY_PAGEDOWN }, | ||
72 | { KEY_LEFT, KEY_HOME }, | ||
73 | { KEY_RIGHT, KEY_END }, | ||
74 | { } | ||
75 | }; | ||
76 | |||
77 | static struct apple_key_translation powerbook_fn_keys[] = { | ||
78 | { KEY_BACKSPACE, KEY_DELETE }, | ||
79 | { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY }, | ||
80 | { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY }, | ||
81 | { KEY_F3, KEY_MUTE, APPLE_FLAG_FKEY }, | ||
82 | { KEY_F4, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY }, | ||
83 | { KEY_F5, KEY_VOLUMEUP, APPLE_FLAG_FKEY }, | ||
84 | { KEY_F6, KEY_NUMLOCK, APPLE_FLAG_FKEY }, | ||
85 | { KEY_F7, KEY_SWITCHVIDEOMODE, APPLE_FLAG_FKEY }, | ||
86 | { KEY_F8, KEY_KBDILLUMTOGGLE, APPLE_FLAG_FKEY }, | ||
87 | { KEY_F9, KEY_KBDILLUMDOWN, APPLE_FLAG_FKEY }, | ||
88 | { KEY_F10, KEY_KBDILLUMUP, APPLE_FLAG_FKEY }, | ||
89 | { KEY_UP, KEY_PAGEUP }, | ||
90 | { KEY_DOWN, KEY_PAGEDOWN }, | ||
91 | { KEY_LEFT, KEY_HOME }, | ||
92 | { KEY_RIGHT, KEY_END }, | ||
93 | { } | ||
94 | }; | ||
95 | |||
96 | static struct apple_key_translation powerbook_numlock_keys[] = { | ||
97 | { KEY_J, KEY_KP1 }, | ||
98 | { KEY_K, KEY_KP2 }, | ||
99 | { KEY_L, KEY_KP3 }, | ||
100 | { KEY_U, KEY_KP4 }, | ||
101 | { KEY_I, KEY_KP5 }, | ||
102 | { KEY_O, KEY_KP6 }, | ||
103 | { KEY_7, KEY_KP7 }, | ||
104 | { KEY_8, KEY_KP8 }, | ||
105 | { KEY_9, KEY_KP9 }, | ||
106 | { KEY_M, KEY_KP0 }, | ||
107 | { KEY_DOT, KEY_KPDOT }, | ||
108 | { KEY_SLASH, KEY_KPPLUS }, | ||
109 | { KEY_SEMICOLON, KEY_KPMINUS }, | ||
110 | { KEY_P, KEY_KPASTERISK }, | ||
111 | { KEY_MINUS, KEY_KPEQUAL }, | ||
112 | { KEY_0, KEY_KPSLASH }, | ||
113 | { KEY_F6, KEY_NUMLOCK }, | ||
114 | { KEY_KPENTER, KEY_KPENTER }, | ||
115 | { KEY_BACKSPACE, KEY_BACKSPACE }, | ||
116 | { } | ||
117 | }; | ||
118 | |||
119 | static struct apple_key_translation apple_iso_keyboard[] = { | ||
120 | { KEY_GRAVE, KEY_102ND }, | ||
121 | { KEY_102ND, KEY_GRAVE }, | ||
122 | { } | ||
123 | }; | ||
124 | |||
125 | static struct apple_key_translation *apple_find_translation( | ||
126 | struct apple_key_translation *table, u16 from) | ||
127 | { | ||
128 | struct apple_key_translation *trans; | ||
129 | |||
130 | /* Look for the translation */ | ||
131 | for (trans = table; trans->from; trans++) | ||
132 | if (trans->from == from) | ||
133 | return trans; | ||
134 | |||
135 | return NULL; | ||
136 | } | ||
137 | |||
138 | static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input, | ||
139 | struct hid_usage *usage, __s32 value) | ||
140 | { | ||
141 | struct apple_sc *asc = hid_get_drvdata(hid); | ||
142 | struct apple_key_translation *trans; | ||
143 | |||
144 | if (usage->code == KEY_FN) { | ||
145 | asc->fn_on = !!value; | ||
146 | input_event(input, usage->type, usage->code, value); | ||
147 | return 1; | ||
148 | } | ||
149 | |||
150 | if (fnmode) { | ||
151 | int do_translate; | ||
152 | |||
153 | trans = apple_find_translation((hid->product < 0x220 || | ||
154 | hid->product >= 0x300) ? | ||
155 | powerbook_fn_keys : apple_fn_keys, | ||
156 | usage->code); | ||
157 | if (trans) { | ||
158 | if (test_bit(usage->code, asc->pressed_fn)) | ||
159 | do_translate = 1; | ||
160 | else if (trans->flags & APPLE_FLAG_FKEY) | ||
161 | do_translate = (fnmode == 2 && asc->fn_on) || | ||
162 | (fnmode == 1 && !asc->fn_on); | ||
163 | else | ||
164 | do_translate = asc->fn_on; | ||
165 | |||
166 | if (do_translate) { | ||
167 | if (value) | ||
168 | set_bit(usage->code, asc->pressed_fn); | ||
169 | else | ||
170 | clear_bit(usage->code, asc->pressed_fn); | ||
171 | |||
172 | input_event(input, usage->type, trans->to, | ||
173 | value); | ||
174 | |||
175 | return 1; | ||
176 | } | ||
177 | } | ||
178 | |||
179 | if (asc->quirks & APPLE_NUMLOCK_EMULATION && | ||
180 | (test_bit(usage->code, asc->pressed_numlock) || | ||
181 | test_bit(LED_NUML, input->led))) { | ||
182 | trans = apple_find_translation(powerbook_numlock_keys, | ||
183 | usage->code); | ||
184 | |||
185 | if (trans) { | ||
186 | if (value) | ||
187 | set_bit(usage->code, | ||
188 | asc->pressed_numlock); | ||
189 | else | ||
190 | clear_bit(usage->code, | ||
191 | asc->pressed_numlock); | ||
192 | |||
193 | input_event(input, usage->type, trans->to, | ||
194 | value); | ||
195 | } | ||
196 | |||
197 | return 1; | ||
198 | } | ||
199 | } | ||
200 | |||
201 | if (asc->quirks & APPLE_ISO_KEYBOARD) { | ||
202 | trans = apple_find_translation(apple_iso_keyboard, usage->code); | ||
203 | if (trans) { | ||
204 | input_event(input, usage->type, trans->to, value); | ||
205 | return 1; | ||
206 | } | ||
207 | } | ||
208 | |||
209 | return 0; | ||
210 | } | ||
211 | |||
212 | static int apple_event(struct hid_device *hdev, struct hid_field *field, | ||
213 | struct hid_usage *usage, __s32 value) | ||
214 | { | ||
215 | struct apple_sc *asc = hid_get_drvdata(hdev); | ||
216 | |||
217 | if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput || | ||
218 | !usage->type) | ||
219 | return 0; | ||
220 | |||
221 | if ((asc->quirks & APPLE_INVERT_HWHEEL) && | ||
222 | usage->code == REL_HWHEEL) { | ||
223 | input_event(field->hidinput->input, usage->type, usage->code, | ||
224 | -value); | ||
225 | return 1; | ||
226 | } | ||
227 | |||
228 | if ((asc->quirks & APPLE_HAS_FN) && | ||
229 | hidinput_apple_event(hdev, field->hidinput->input, | ||
230 | usage, value)) | ||
231 | return 1; | ||
232 | |||
233 | |||
234 | return 0; | ||
235 | } | ||
236 | |||
237 | /* | ||
238 | * MacBook JIS keyboard has wrong logical maximum | ||
239 | */ | ||
240 | static void apple_report_fixup(struct hid_device *hdev, __u8 *rdesc, | ||
241 | unsigned int rsize) | ||
242 | { | ||
243 | struct apple_sc *asc = hid_get_drvdata(hdev); | ||
244 | |||
245 | if ((asc->quirks & APPLE_RDESC_JIS) && rsize >= 60 && | ||
246 | rdesc[53] == 0x65 && rdesc[59] == 0x65) { | ||
247 | dev_info(&hdev->dev, "fixing up MacBook JIS keyboard report " | ||
248 | "descriptor\n"); | ||
249 | rdesc[53] = rdesc[59] = 0xe7; | ||
250 | } | ||
251 | } | ||
252 | |||
253 | static void apple_setup_input(struct input_dev *input) | ||
254 | { | ||
255 | struct apple_key_translation *trans; | ||
256 | |||
257 | set_bit(KEY_NUMLOCK, input->keybit); | ||
258 | |||
259 | /* Enable all needed keys */ | ||
260 | for (trans = apple_fn_keys; trans->from; trans++) | ||
261 | set_bit(trans->to, input->keybit); | ||
262 | |||
263 | for (trans = powerbook_fn_keys; trans->from; trans++) | ||
264 | set_bit(trans->to, input->keybit); | ||
265 | |||
266 | for (trans = powerbook_numlock_keys; trans->from; trans++) | ||
267 | set_bit(trans->to, input->keybit); | ||
268 | |||
269 | for (trans = apple_iso_keyboard; trans->from; trans++) | ||
270 | set_bit(trans->to, input->keybit); | ||
271 | } | ||
272 | |||
273 | static int apple_input_mapping(struct hid_device *hdev, struct hid_input *hi, | ||
274 | struct hid_field *field, struct hid_usage *usage, | ||
275 | unsigned long **bit, int *max) | ||
276 | { | ||
277 | if (usage->hid == (HID_UP_CUSTOM | 0x0003)) { | ||
278 | /* The fn key on Apple USB keyboards */ | ||
279 | set_bit(EV_REP, hi->input->evbit); | ||
280 | hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_FN); | ||
281 | apple_setup_input(hi->input); | ||
282 | return 1; | ||
283 | } | ||
284 | |||
285 | /* we want the hid layer to go through standard path (set and ignore) */ | ||
286 | return 0; | ||
287 | } | ||
288 | |||
289 | static int apple_input_mapped(struct hid_device *hdev, struct hid_input *hi, | ||
290 | struct hid_field *field, struct hid_usage *usage, | ||
291 | unsigned long **bit, int *max) | ||
292 | { | ||
293 | struct apple_sc *asc = hid_get_drvdata(hdev); | ||
294 | |||
295 | if (asc->quirks & APPLE_MIGHTYMOUSE) { | ||
296 | if (usage->hid == HID_GD_Z) | ||
297 | hid_map_usage(hi, usage, bit, max, EV_REL, REL_HWHEEL); | ||
298 | else if (usage->code == BTN_1) | ||
299 | hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_2); | ||
300 | else if (usage->code == BTN_2) | ||
301 | hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_1); | ||
302 | } | ||
303 | |||
304 | return 0; | ||
305 | } | ||
306 | |||
307 | static int apple_probe(struct hid_device *hdev, | ||
308 | const struct hid_device_id *id) | ||
309 | { | ||
310 | unsigned long quirks = id->driver_data; | ||
311 | struct apple_sc *asc; | ||
312 | unsigned int connect_mask = HID_CONNECT_DEFAULT; | ||
313 | int ret; | ||
314 | |||
315 | /* return something else or move to hid layer? device will reside | ||
316 | allocated */ | ||
317 | if (id->bus == BUS_USB && (quirks & APPLE_IGNORE_MOUSE) && | ||
318 | to_usb_interface(hdev->dev.parent)->cur_altsetting-> | ||
319 | desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_MOUSE) | ||
320 | return -ENODEV; | ||
321 | |||
322 | asc = kzalloc(sizeof(*asc), GFP_KERNEL); | ||
323 | if (asc == NULL) { | ||
324 | dev_err(&hdev->dev, "can't alloc apple descriptor\n"); | ||
325 | return -ENOMEM; | ||
326 | } | ||
327 | |||
328 | asc->quirks = quirks; | ||
329 | |||
330 | hid_set_drvdata(hdev, asc); | ||
331 | |||
332 | ret = hid_parse(hdev); | ||
333 | if (ret) { | ||
334 | dev_err(&hdev->dev, "parse failed\n"); | ||
335 | goto err_free; | ||
336 | } | ||
337 | |||
338 | if (quirks & APPLE_HIDDEV) | ||
339 | connect_mask |= HID_CONNECT_HIDDEV_FORCE; | ||
340 | if (quirks & APPLE_IGNORE_HIDINPUT) | ||
341 | connect_mask &= ~HID_CONNECT_HIDINPUT; | ||
342 | |||
343 | ret = hid_hw_start(hdev, connect_mask); | ||
344 | if (ret) { | ||
345 | dev_err(&hdev->dev, "hw start failed\n"); | ||
346 | goto err_free; | ||
347 | } | ||
348 | |||
349 | return 0; | ||
350 | err_free: | ||
351 | kfree(asc); | ||
352 | return ret; | ||
353 | } | ||
354 | |||
355 | static void apple_remove(struct hid_device *hdev) | ||
356 | { | ||
357 | hid_hw_stop(hdev); | ||
358 | kfree(hid_get_drvdata(hdev)); | ||
359 | } | ||
360 | |||
361 | static const struct hid_device_id apple_devices[] = { | ||
362 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL), | ||
363 | .driver_data = APPLE_HIDDEV | APPLE_IGNORE_HIDINPUT }, | ||
364 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4), | ||
365 | .driver_data = APPLE_HIDDEV | APPLE_IGNORE_HIDINPUT }, | ||
366 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE), | ||
367 | .driver_data = APPLE_MIGHTYMOUSE | APPLE_INVERT_HWHEEL }, | ||
368 | |||
369 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI), | ||
370 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN | | ||
371 | APPLE_IGNORE_MOUSE }, | ||
372 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO), | ||
373 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN | | ||
374 | APPLE_IGNORE_MOUSE }, | ||
375 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI), | ||
376 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN | | ||
377 | APPLE_IGNORE_MOUSE }, | ||
378 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO), | ||
379 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN | | ||
380 | APPLE_IGNORE_MOUSE | APPLE_ISO_KEYBOARD }, | ||
381 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS), | ||
382 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN | | ||
383 | APPLE_IGNORE_MOUSE }, | ||
384 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI), | ||
385 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN | | ||
386 | APPLE_IGNORE_MOUSE }, | ||
387 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO), | ||
388 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN | | ||
389 | APPLE_IGNORE_MOUSE | APPLE_ISO_KEYBOARD }, | ||
390 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS), | ||
391 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN | | ||
392 | APPLE_IGNORE_MOUSE | APPLE_RDESC_JIS }, | ||
393 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI), | ||
394 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN | | ||
395 | APPLE_IGNORE_MOUSE }, | ||
396 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO), | ||
397 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN | | ||
398 | APPLE_IGNORE_MOUSE | APPLE_ISO_KEYBOARD }, | ||
399 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS), | ||
400 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN | | ||
401 | APPLE_IGNORE_MOUSE | APPLE_RDESC_JIS}, | ||
402 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI), | ||
403 | .driver_data = APPLE_HAS_FN }, | ||
404 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO), | ||
405 | .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD }, | ||
406 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS), | ||
407 | .driver_data = APPLE_HAS_FN }, | ||
408 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI), | ||
409 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN | | ||
410 | APPLE_IGNORE_MOUSE }, | ||
411 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO), | ||
412 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN | | ||
413 | APPLE_IGNORE_MOUSE }, | ||
414 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS), | ||
415 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN | | ||
416 | APPLE_IGNORE_MOUSE | APPLE_RDESC_JIS }, | ||
417 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI), | ||
418 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, | ||
419 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO), | ||
420 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN | | ||
421 | APPLE_ISO_KEYBOARD }, | ||
422 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS), | ||
423 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, | ||
424 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI), | ||
425 | .driver_data = APPLE_HAS_FN | APPLE_IGNORE_MOUSE }, | ||
426 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO), | ||
427 | .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD | | ||
428 | APPLE_IGNORE_MOUSE }, | ||
429 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS), | ||
430 | .driver_data = APPLE_HAS_FN | APPLE_IGNORE_MOUSE | APPLE_RDESC_JIS }, | ||
431 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI), | ||
432 | .driver_data = APPLE_HAS_FN | APPLE_IGNORE_MOUSE }, | ||
433 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO), | ||
434 | .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD | | ||
435 | APPLE_IGNORE_MOUSE }, | ||
436 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS), | ||
437 | .driver_data = APPLE_HAS_FN | APPLE_IGNORE_MOUSE | APPLE_RDESC_JIS }, | ||
438 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY), | ||
439 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN | | ||
440 | APPLE_IGNORE_MOUSE }, | ||
441 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY), | ||
442 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN | | ||
443 | APPLE_IGNORE_MOUSE }, | ||
444 | |||
445 | /* Apple wireless Mighty Mouse */ | ||
446 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 0x030c), | ||
447 | .driver_data = APPLE_MIGHTYMOUSE | APPLE_INVERT_HWHEEL }, | ||
448 | |||
449 | { } | ||
450 | }; | ||
451 | MODULE_DEVICE_TABLE(hid, apple_devices); | ||
452 | |||
453 | static struct hid_driver apple_driver = { | ||
454 | .name = "apple", | ||
455 | .id_table = apple_devices, | ||
456 | .report_fixup = apple_report_fixup, | ||
457 | .probe = apple_probe, | ||
458 | .remove = apple_remove, | ||
459 | .event = apple_event, | ||
460 | .input_mapping = apple_input_mapping, | ||
461 | .input_mapped = apple_input_mapped, | ||
462 | }; | ||
463 | |||
464 | static int apple_init(void) | ||
465 | { | ||
466 | int ret; | ||
467 | |||
468 | ret = hid_register_driver(&apple_driver); | ||
469 | if (ret) | ||
470 | printk(KERN_ERR "can't register apple driver\n"); | ||
471 | |||
472 | return ret; | ||
473 | } | ||
474 | |||
475 | static void apple_exit(void) | ||
476 | { | ||
477 | hid_unregister_driver(&apple_driver); | ||
478 | } | ||
479 | |||
480 | module_init(apple_init); | ||
481 | module_exit(apple_exit); | ||
482 | MODULE_LICENSE("GPL"); | ||
483 | |||
484 | HID_COMPAT_LOAD_DRIVER(apple); | ||
diff --git a/drivers/hid/hid-belkin.c b/drivers/hid/hid-belkin.c new file mode 100644 index 000000000000..12c8a9ba6ed6 --- /dev/null +++ b/drivers/hid/hid-belkin.c | |||
@@ -0,0 +1,105 @@ | |||
1 | /* | ||
2 | * HID driver for some belkin "special" devices | ||
3 | * | ||
4 | * Copyright (c) 1999 Andreas Gal | ||
5 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> | ||
6 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc | ||
7 | * Copyright (c) 2006-2007 Jiri Kosina | ||
8 | * Copyright (c) 2007 Paul Walmsley | ||
9 | * Copyright (c) 2008 Jiri Slaby | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * This program is free software; you can redistribute it and/or modify it | ||
14 | * under the terms of the GNU General Public License as published by the Free | ||
15 | * Software Foundation; either version 2 of the License, or (at your option) | ||
16 | * any later version. | ||
17 | */ | ||
18 | |||
19 | #include <linux/device.h> | ||
20 | #include <linux/hid.h> | ||
21 | #include <linux/module.h> | ||
22 | |||
23 | #include "hid-ids.h" | ||
24 | |||
25 | #define BELKIN_HIDDEV 0x01 | ||
26 | #define BELKIN_WKBD 0x02 | ||
27 | |||
28 | #define belkin_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \ | ||
29 | EV_KEY, (c)) | ||
30 | static int belkin_input_mapping(struct hid_device *hdev, struct hid_input *hi, | ||
31 | struct hid_field *field, struct hid_usage *usage, | ||
32 | unsigned long **bit, int *max) | ||
33 | { | ||
34 | unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); | ||
35 | |||
36 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER || | ||
37 | !(quirks & BELKIN_WKBD)) | ||
38 | return 0; | ||
39 | |||
40 | switch (usage->hid & HID_USAGE) { | ||
41 | case 0x03a: belkin_map_key_clear(KEY_SOUND); break; | ||
42 | case 0x03b: belkin_map_key_clear(KEY_CAMERA); break; | ||
43 | case 0x03c: belkin_map_key_clear(KEY_DOCUMENTS); break; | ||
44 | default: | ||
45 | return 0; | ||
46 | } | ||
47 | return 1; | ||
48 | } | ||
49 | |||
50 | static int belkin_probe(struct hid_device *hdev, const struct hid_device_id *id) | ||
51 | { | ||
52 | unsigned long quirks = id->driver_data; | ||
53 | int ret; | ||
54 | |||
55 | hid_set_drvdata(hdev, (void *)quirks); | ||
56 | |||
57 | ret = hid_parse(hdev); | ||
58 | if (ret) { | ||
59 | dev_err(&hdev->dev, "parse failed\n"); | ||
60 | goto err_free; | ||
61 | } | ||
62 | |||
63 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT | | ||
64 | ((quirks & BELKIN_HIDDEV) ? HID_CONNECT_HIDDEV_FORCE : 0)); | ||
65 | if (ret) { | ||
66 | dev_err(&hdev->dev, "hw start failed\n"); | ||
67 | goto err_free; | ||
68 | } | ||
69 | |||
70 | return 0; | ||
71 | err_free: | ||
72 | return ret; | ||
73 | } | ||
74 | |||
75 | static const struct hid_device_id belkin_devices[] = { | ||
76 | { HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM), | ||
77 | .driver_data = BELKIN_HIDDEV }, | ||
78 | { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD), | ||
79 | .driver_data = BELKIN_WKBD }, | ||
80 | { } | ||
81 | }; | ||
82 | MODULE_DEVICE_TABLE(hid, belkin_devices); | ||
83 | |||
84 | static struct hid_driver belkin_driver = { | ||
85 | .name = "belkin", | ||
86 | .id_table = belkin_devices, | ||
87 | .input_mapping = belkin_input_mapping, | ||
88 | .probe = belkin_probe, | ||
89 | }; | ||
90 | |||
91 | static int belkin_init(void) | ||
92 | { | ||
93 | return hid_register_driver(&belkin_driver); | ||
94 | } | ||
95 | |||
96 | static void belkin_exit(void) | ||
97 | { | ||
98 | hid_unregister_driver(&belkin_driver); | ||
99 | } | ||
100 | |||
101 | module_init(belkin_init); | ||
102 | module_exit(belkin_exit); | ||
103 | MODULE_LICENSE("GPL"); | ||
104 | |||
105 | HID_COMPAT_LOAD_DRIVER(belkin); | ||
diff --git a/drivers/hid/hid-bright.c b/drivers/hid/hid-bright.c new file mode 100644 index 000000000000..38517a117dfd --- /dev/null +++ b/drivers/hid/hid-bright.c | |||
@@ -0,0 +1,71 @@ | |||
1 | /* | ||
2 | * HID driver for some bright "special" devices | ||
3 | * | ||
4 | * Copyright (c) 2008 Mauro Carvalho Chehab <mchehab@redhat.com> | ||
5 | * | ||
6 | * Based on hid-dell driver | ||
7 | */ | ||
8 | |||
9 | /* | ||
10 | * This program is free software; you can redistribute it and/or modify it | ||
11 | * under the terms of the GNU General Public License as published by the Free | ||
12 | * Software Foundation; either version 2 of the License, or (at your option) | ||
13 | * any later version. | ||
14 | */ | ||
15 | |||
16 | #include <linux/device.h> | ||
17 | #include <linux/hid.h> | ||
18 | #include <linux/module.h> | ||
19 | |||
20 | #include "hid-ids.h" | ||
21 | |||
22 | static int bright_probe(struct hid_device *hdev, const struct hid_device_id *id) | ||
23 | { | ||
24 | int ret; | ||
25 | |||
26 | ret = hid_parse(hdev); | ||
27 | if (ret) { | ||
28 | dev_err(&hdev->dev, "parse failed\n"); | ||
29 | goto err_free; | ||
30 | } | ||
31 | |||
32 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); | ||
33 | if (ret) { | ||
34 | dev_err(&hdev->dev, "hw start failed\n"); | ||
35 | goto err_free; | ||
36 | } | ||
37 | |||
38 | usbhid_set_leds(hdev); | ||
39 | |||
40 | return 0; | ||
41 | err_free: | ||
42 | return ret; | ||
43 | } | ||
44 | |||
45 | static const struct hid_device_id bright_devices[] = { | ||
46 | { HID_USB_DEVICE(USB_VENDOR_ID_BRIGHT, USB_DEVICE_ID_BRIGHT_ABNT2) }, | ||
47 | { } | ||
48 | }; | ||
49 | MODULE_DEVICE_TABLE(hid, bright_devices); | ||
50 | |||
51 | static struct hid_driver bright_driver = { | ||
52 | .name = "bright", | ||
53 | .id_table = bright_devices, | ||
54 | .probe = bright_probe, | ||
55 | }; | ||
56 | |||
57 | static int bright_init(void) | ||
58 | { | ||
59 | return hid_register_driver(&bright_driver); | ||
60 | } | ||
61 | |||
62 | static void bright_exit(void) | ||
63 | { | ||
64 | hid_unregister_driver(&bright_driver); | ||
65 | } | ||
66 | |||
67 | module_init(bright_init); | ||
68 | module_exit(bright_exit); | ||
69 | MODULE_LICENSE("GPL"); | ||
70 | |||
71 | HID_COMPAT_LOAD_DRIVER(bright); | ||
diff --git a/drivers/hid/hid-cherry.c b/drivers/hid/hid-cherry.c new file mode 100644 index 000000000000..b833b9769aba --- /dev/null +++ b/drivers/hid/hid-cherry.c | |||
@@ -0,0 +1,87 @@ | |||
1 | /* | ||
2 | * HID driver for some cherry "special" devices | ||
3 | * | ||
4 | * Copyright (c) 1999 Andreas Gal | ||
5 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> | ||
6 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc | ||
7 | * Copyright (c) 2006-2007 Jiri Kosina | ||
8 | * Copyright (c) 2007 Paul Walmsley | ||
9 | * Copyright (c) 2008 Jiri Slaby | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * This program is free software; you can redistribute it and/or modify it | ||
14 | * under the terms of the GNU General Public License as published by the Free | ||
15 | * Software Foundation; either version 2 of the License, or (at your option) | ||
16 | * any later version. | ||
17 | */ | ||
18 | |||
19 | #include <linux/device.h> | ||
20 | #include <linux/hid.h> | ||
21 | #include <linux/module.h> | ||
22 | |||
23 | #include "hid-ids.h" | ||
24 | |||
25 | /* | ||
26 | * Cherry Cymotion keyboard have an invalid HID report descriptor, | ||
27 | * that needs fixing before we can parse it. | ||
28 | */ | ||
29 | static void ch_report_fixup(struct hid_device *hdev, __u8 *rdesc, | ||
30 | unsigned int rsize) | ||
31 | { | ||
32 | if (rsize >= 17 && rdesc[11] == 0x3c && rdesc[12] == 0x02) { | ||
33 | dev_info(&hdev->dev, "fixing up Cherry Cymotion report " | ||
34 | "descriptor\n"); | ||
35 | rdesc[11] = rdesc[16] = 0xff; | ||
36 | rdesc[12] = rdesc[17] = 0x03; | ||
37 | } | ||
38 | } | ||
39 | |||
40 | #define ch_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \ | ||
41 | EV_KEY, (c)) | ||
42 | static int ch_input_mapping(struct hid_device *hdev, struct hid_input *hi, | ||
43 | struct hid_field *field, struct hid_usage *usage, | ||
44 | unsigned long **bit, int *max) | ||
45 | { | ||
46 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER) | ||
47 | return 0; | ||
48 | |||
49 | switch (usage->hid & HID_USAGE) { | ||
50 | case 0x301: ch_map_key_clear(KEY_PROG1); break; | ||
51 | case 0x302: ch_map_key_clear(KEY_PROG2); break; | ||
52 | case 0x303: ch_map_key_clear(KEY_PROG3); break; | ||
53 | default: | ||
54 | return 0; | ||
55 | } | ||
56 | |||
57 | return 1; | ||
58 | } | ||
59 | |||
60 | static const struct hid_device_id ch_devices[] = { | ||
61 | { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) }, | ||
62 | { } | ||
63 | }; | ||
64 | MODULE_DEVICE_TABLE(hid, ch_devices); | ||
65 | |||
66 | static struct hid_driver ch_driver = { | ||
67 | .name = "cherry", | ||
68 | .id_table = ch_devices, | ||
69 | .report_fixup = ch_report_fixup, | ||
70 | .input_mapping = ch_input_mapping, | ||
71 | }; | ||
72 | |||
73 | static int ch_init(void) | ||
74 | { | ||
75 | return hid_register_driver(&ch_driver); | ||
76 | } | ||
77 | |||
78 | static void ch_exit(void) | ||
79 | { | ||
80 | hid_unregister_driver(&ch_driver); | ||
81 | } | ||
82 | |||
83 | module_init(ch_init); | ||
84 | module_exit(ch_exit); | ||
85 | MODULE_LICENSE("GPL"); | ||
86 | |||
87 | HID_COMPAT_LOAD_DRIVER(cherry); | ||
diff --git a/drivers/hid/hid-chicony.c b/drivers/hid/hid-chicony.c new file mode 100644 index 000000000000..a54d4096e0f7 --- /dev/null +++ b/drivers/hid/hid-chicony.c | |||
@@ -0,0 +1,80 @@ | |||
1 | /* | ||
2 | * HID driver for some chicony "special" devices | ||
3 | * | ||
4 | * Copyright (c) 1999 Andreas Gal | ||
5 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> | ||
6 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc | ||
7 | * Copyright (c) 2006-2007 Jiri Kosina | ||
8 | * Copyright (c) 2007 Paul Walmsley | ||
9 | * Copyright (c) 2008 Jiri Slaby | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * This program is free software; you can redistribute it and/or modify it | ||
14 | * under the terms of the GNU General Public License as published by the Free | ||
15 | * Software Foundation; either version 2 of the License, or (at your option) | ||
16 | * any later version. | ||
17 | */ | ||
18 | |||
19 | #include <linux/device.h> | ||
20 | #include <linux/input.h> | ||
21 | #include <linux/hid.h> | ||
22 | #include <linux/module.h> | ||
23 | |||
24 | #include "hid-ids.h" | ||
25 | |||
26 | #define ch_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \ | ||
27 | EV_KEY, (c)) | ||
28 | static int ch_input_mapping(struct hid_device *hdev, struct hid_input *hi, | ||
29 | struct hid_field *field, struct hid_usage *usage, | ||
30 | unsigned long **bit, int *max) | ||
31 | { | ||
32 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR) | ||
33 | return 0; | ||
34 | |||
35 | set_bit(EV_REP, hi->input->evbit); | ||
36 | switch (usage->hid & HID_USAGE) { | ||
37 | case 0xff01: ch_map_key_clear(BTN_1); break; | ||
38 | case 0xff02: ch_map_key_clear(BTN_2); break; | ||
39 | case 0xff03: ch_map_key_clear(BTN_3); break; | ||
40 | case 0xff04: ch_map_key_clear(BTN_4); break; | ||
41 | case 0xff05: ch_map_key_clear(BTN_5); break; | ||
42 | case 0xff06: ch_map_key_clear(BTN_6); break; | ||
43 | case 0xff07: ch_map_key_clear(BTN_7); break; | ||
44 | case 0xff08: ch_map_key_clear(BTN_8); break; | ||
45 | case 0xff09: ch_map_key_clear(BTN_9); break; | ||
46 | case 0xff0a: ch_map_key_clear(BTN_A); break; | ||
47 | case 0xff0b: ch_map_key_clear(BTN_B); break; | ||
48 | default: | ||
49 | return 0; | ||
50 | } | ||
51 | return 1; | ||
52 | } | ||
53 | |||
54 | static const struct hid_device_id ch_devices[] = { | ||
55 | { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) }, | ||
56 | { } | ||
57 | }; | ||
58 | MODULE_DEVICE_TABLE(hid, ch_devices); | ||
59 | |||
60 | static struct hid_driver ch_driver = { | ||
61 | .name = "chicony", | ||
62 | .id_table = ch_devices, | ||
63 | .input_mapping = ch_input_mapping, | ||
64 | }; | ||
65 | |||
66 | static int ch_init(void) | ||
67 | { | ||
68 | return hid_register_driver(&ch_driver); | ||
69 | } | ||
70 | |||
71 | static void ch_exit(void) | ||
72 | { | ||
73 | hid_unregister_driver(&ch_driver); | ||
74 | } | ||
75 | |||
76 | module_init(ch_init); | ||
77 | module_exit(ch_exit); | ||
78 | MODULE_LICENSE("GPL"); | ||
79 | |||
80 | HID_COMPAT_LOAD_DRIVER(chicony); | ||
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index 426ac5add585..8a7d9dbb4d07 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c | |||
@@ -33,6 +33,8 @@ | |||
33 | #include <linux/hid-debug.h> | 33 | #include <linux/hid-debug.h> |
34 | #include <linux/hidraw.h> | 34 | #include <linux/hidraw.h> |
35 | 35 | ||
36 | #include "hid-ids.h" | ||
37 | |||
36 | /* | 38 | /* |
37 | * Version Information | 39 | * Version Information |
38 | */ | 40 | */ |
@@ -268,9 +270,9 @@ static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsign | |||
268 | static u32 item_udata(struct hid_item *item) | 270 | static u32 item_udata(struct hid_item *item) |
269 | { | 271 | { |
270 | switch (item->size) { | 272 | switch (item->size) { |
271 | case 1: return item->data.u8; | 273 | case 1: return item->data.u8; |
272 | case 2: return item->data.u16; | 274 | case 2: return item->data.u16; |
273 | case 4: return item->data.u32; | 275 | case 4: return item->data.u32; |
274 | } | 276 | } |
275 | return 0; | 277 | return 0; |
276 | } | 278 | } |
@@ -278,9 +280,9 @@ static u32 item_udata(struct hid_item *item) | |||
278 | static s32 item_sdata(struct hid_item *item) | 280 | static s32 item_sdata(struct hid_item *item) |
279 | { | 281 | { |
280 | switch (item->size) { | 282 | switch (item->size) { |
281 | case 1: return item->data.s8; | 283 | case 1: return item->data.s8; |
282 | case 2: return item->data.s16; | 284 | case 2: return item->data.s16; |
283 | case 4: return item->data.s32; | 285 | case 4: return item->data.s32; |
284 | } | 286 | } |
285 | return 0; | 287 | return 0; |
286 | } | 288 | } |
@@ -292,87 +294,91 @@ static s32 item_sdata(struct hid_item *item) | |||
292 | static int hid_parser_global(struct hid_parser *parser, struct hid_item *item) | 294 | static int hid_parser_global(struct hid_parser *parser, struct hid_item *item) |
293 | { | 295 | { |
294 | switch (item->tag) { | 296 | switch (item->tag) { |
297 | case HID_GLOBAL_ITEM_TAG_PUSH: | ||
295 | 298 | ||
296 | case HID_GLOBAL_ITEM_TAG_PUSH: | 299 | if (parser->global_stack_ptr == HID_GLOBAL_STACK_SIZE) { |
297 | 300 | dbg_hid("global enviroment stack overflow\n"); | |
298 | if (parser->global_stack_ptr == HID_GLOBAL_STACK_SIZE) { | 301 | return -1; |
299 | dbg_hid("global enviroment stack overflow\n"); | 302 | } |
300 | return -1; | ||
301 | } | ||
302 | 303 | ||
303 | memcpy(parser->global_stack + parser->global_stack_ptr++, | 304 | memcpy(parser->global_stack + parser->global_stack_ptr++, |
304 | &parser->global, sizeof(struct hid_global)); | 305 | &parser->global, sizeof(struct hid_global)); |
305 | return 0; | 306 | return 0; |
306 | 307 | ||
307 | case HID_GLOBAL_ITEM_TAG_POP: | 308 | case HID_GLOBAL_ITEM_TAG_POP: |
308 | 309 | ||
309 | if (!parser->global_stack_ptr) { | 310 | if (!parser->global_stack_ptr) { |
310 | dbg_hid("global enviroment stack underflow\n"); | 311 | dbg_hid("global enviroment stack underflow\n"); |
311 | return -1; | 312 | return -1; |
312 | } | 313 | } |
313 | |||
314 | memcpy(&parser->global, parser->global_stack + --parser->global_stack_ptr, | ||
315 | sizeof(struct hid_global)); | ||
316 | return 0; | ||
317 | 314 | ||
318 | case HID_GLOBAL_ITEM_TAG_USAGE_PAGE: | 315 | memcpy(&parser->global, parser->global_stack + |
319 | parser->global.usage_page = item_udata(item); | 316 | --parser->global_stack_ptr, sizeof(struct hid_global)); |
320 | return 0; | 317 | return 0; |
321 | 318 | ||
322 | case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM: | 319 | case HID_GLOBAL_ITEM_TAG_USAGE_PAGE: |
323 | parser->global.logical_minimum = item_sdata(item); | 320 | parser->global.usage_page = item_udata(item); |
324 | return 0; | 321 | return 0; |
325 | 322 | ||
326 | case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM: | 323 | case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM: |
327 | if (parser->global.logical_minimum < 0) | 324 | parser->global.logical_minimum = item_sdata(item); |
328 | parser->global.logical_maximum = item_sdata(item); | 325 | return 0; |
329 | else | ||
330 | parser->global.logical_maximum = item_udata(item); | ||
331 | return 0; | ||
332 | 326 | ||
333 | case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM: | 327 | case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM: |
334 | parser->global.physical_minimum = item_sdata(item); | 328 | if (parser->global.logical_minimum < 0) |
335 | return 0; | 329 | parser->global.logical_maximum = item_sdata(item); |
330 | else | ||
331 | parser->global.logical_maximum = item_udata(item); | ||
332 | return 0; | ||
336 | 333 | ||
337 | case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM: | 334 | case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM: |
338 | if (parser->global.physical_minimum < 0) | 335 | parser->global.physical_minimum = item_sdata(item); |
339 | parser->global.physical_maximum = item_sdata(item); | 336 | return 0; |
340 | else | ||
341 | parser->global.physical_maximum = item_udata(item); | ||
342 | return 0; | ||
343 | 337 | ||
344 | case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT: | 338 | case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM: |
345 | parser->global.unit_exponent = item_sdata(item); | 339 | if (parser->global.physical_minimum < 0) |
346 | return 0; | 340 | parser->global.physical_maximum = item_sdata(item); |
341 | else | ||
342 | parser->global.physical_maximum = item_udata(item); | ||
343 | return 0; | ||
347 | 344 | ||
348 | case HID_GLOBAL_ITEM_TAG_UNIT: | 345 | case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT: |
349 | parser->global.unit = item_udata(item); | 346 | parser->global.unit_exponent = item_sdata(item); |
350 | return 0; | 347 | return 0; |
351 | 348 | ||
352 | case HID_GLOBAL_ITEM_TAG_REPORT_SIZE: | 349 | case HID_GLOBAL_ITEM_TAG_UNIT: |
353 | if ((parser->global.report_size = item_udata(item)) > 32) { | 350 | parser->global.unit = item_udata(item); |
354 | dbg_hid("invalid report_size %d\n", parser->global.report_size); | 351 | return 0; |
355 | return -1; | ||
356 | } | ||
357 | return 0; | ||
358 | 352 | ||
359 | case HID_GLOBAL_ITEM_TAG_REPORT_COUNT: | 353 | case HID_GLOBAL_ITEM_TAG_REPORT_SIZE: |
360 | if ((parser->global.report_count = item_udata(item)) > HID_MAX_USAGES) { | 354 | parser->global.report_size = item_udata(item); |
361 | dbg_hid("invalid report_count %d\n", parser->global.report_count); | 355 | if (parser->global.report_size > 32) { |
362 | return -1; | 356 | dbg_hid("invalid report_size %d\n", |
363 | } | 357 | parser->global.report_size); |
364 | return 0; | 358 | return -1; |
359 | } | ||
360 | return 0; | ||
365 | 361 | ||
366 | case HID_GLOBAL_ITEM_TAG_REPORT_ID: | 362 | case HID_GLOBAL_ITEM_TAG_REPORT_COUNT: |
367 | if ((parser->global.report_id = item_udata(item)) == 0) { | 363 | parser->global.report_count = item_udata(item); |
368 | dbg_hid("report_id 0 is invalid\n"); | 364 | if (parser->global.report_count > HID_MAX_USAGES) { |
369 | return -1; | 365 | dbg_hid("invalid report_count %d\n", |
370 | } | 366 | parser->global.report_count); |
371 | return 0; | 367 | return -1; |
368 | } | ||
369 | return 0; | ||
372 | 370 | ||
373 | default: | 371 | case HID_GLOBAL_ITEM_TAG_REPORT_ID: |
374 | dbg_hid("unknown global tag 0x%x\n", item->tag); | 372 | parser->global.report_id = item_udata(item); |
373 | if (parser->global.report_id == 0) { | ||
374 | dbg_hid("report_id 0 is invalid\n"); | ||
375 | return -1; | 375 | return -1; |
376 | } | ||
377 | return 0; | ||
378 | |||
379 | default: | ||
380 | dbg_hid("unknown global tag 0x%x\n", item->tag); | ||
381 | return -1; | ||
376 | } | 382 | } |
377 | } | 383 | } |
378 | 384 | ||
@@ -393,77 +399,76 @@ static int hid_parser_local(struct hid_parser *parser, struct hid_item *item) | |||
393 | data = item_udata(item); | 399 | data = item_udata(item); |
394 | 400 | ||
395 | switch (item->tag) { | 401 | switch (item->tag) { |
396 | 402 | case HID_LOCAL_ITEM_TAG_DELIMITER: | |
397 | case HID_LOCAL_ITEM_TAG_DELIMITER: | 403 | |
398 | 404 | if (data) { | |
399 | if (data) { | 405 | /* |
400 | /* | 406 | * We treat items before the first delimiter |
401 | * We treat items before the first delimiter | 407 | * as global to all usage sets (branch 0). |
402 | * as global to all usage sets (branch 0). | 408 | * In the moment we process only these global |
403 | * In the moment we process only these global | 409 | * items and the first delimiter set. |
404 | * items and the first delimiter set. | 410 | */ |
405 | */ | 411 | if (parser->local.delimiter_depth != 0) { |
406 | if (parser->local.delimiter_depth != 0) { | 412 | dbg_hid("nested delimiters\n"); |
407 | dbg_hid("nested delimiters\n"); | 413 | return -1; |
408 | return -1; | ||
409 | } | ||
410 | parser->local.delimiter_depth++; | ||
411 | parser->local.delimiter_branch++; | ||
412 | } else { | ||
413 | if (parser->local.delimiter_depth < 1) { | ||
414 | dbg_hid("bogus close delimiter\n"); | ||
415 | return -1; | ||
416 | } | ||
417 | parser->local.delimiter_depth--; | ||
418 | } | 414 | } |
419 | return 1; | 415 | parser->local.delimiter_depth++; |
420 | 416 | parser->local.delimiter_branch++; | |
421 | case HID_LOCAL_ITEM_TAG_USAGE: | 417 | } else { |
422 | 418 | if (parser->local.delimiter_depth < 1) { | |
423 | if (parser->local.delimiter_branch > 1) { | 419 | dbg_hid("bogus close delimiter\n"); |
424 | dbg_hid("alternative usage ignored\n"); | 420 | return -1; |
425 | return 0; | ||
426 | } | 421 | } |
422 | parser->local.delimiter_depth--; | ||
423 | } | ||
424 | return 1; | ||
427 | 425 | ||
428 | if (item->size <= 2) | 426 | case HID_LOCAL_ITEM_TAG_USAGE: |
429 | data = (parser->global.usage_page << 16) + data; | ||
430 | 427 | ||
431 | return hid_add_usage(parser, data); | 428 | if (parser->local.delimiter_branch > 1) { |
429 | dbg_hid("alternative usage ignored\n"); | ||
430 | return 0; | ||
431 | } | ||
432 | 432 | ||
433 | case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM: | 433 | if (item->size <= 2) |
434 | data = (parser->global.usage_page << 16) + data; | ||
434 | 435 | ||
435 | if (parser->local.delimiter_branch > 1) { | 436 | return hid_add_usage(parser, data); |
436 | dbg_hid("alternative usage ignored\n"); | ||
437 | return 0; | ||
438 | } | ||
439 | 437 | ||
440 | if (item->size <= 2) | 438 | case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM: |
441 | data = (parser->global.usage_page << 16) + data; | ||
442 | 439 | ||
443 | parser->local.usage_minimum = data; | 440 | if (parser->local.delimiter_branch > 1) { |
441 | dbg_hid("alternative usage ignored\n"); | ||
444 | return 0; | 442 | return 0; |
443 | } | ||
445 | 444 | ||
446 | case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM: | 445 | if (item->size <= 2) |
446 | data = (parser->global.usage_page << 16) + data; | ||
447 | 447 | ||
448 | if (parser->local.delimiter_branch > 1) { | 448 | parser->local.usage_minimum = data; |
449 | dbg_hid("alternative usage ignored\n"); | 449 | return 0; |
450 | return 0; | ||
451 | } | ||
452 | 450 | ||
453 | if (item->size <= 2) | 451 | case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM: |
454 | data = (parser->global.usage_page << 16) + data; | ||
455 | 452 | ||
456 | for (n = parser->local.usage_minimum; n <= data; n++) | 453 | if (parser->local.delimiter_branch > 1) { |
457 | if (hid_add_usage(parser, n)) { | 454 | dbg_hid("alternative usage ignored\n"); |
458 | dbg_hid("hid_add_usage failed\n"); | ||
459 | return -1; | ||
460 | } | ||
461 | return 0; | 455 | return 0; |
456 | } | ||
462 | 457 | ||
463 | default: | 458 | if (item->size <= 2) |
459 | data = (parser->global.usage_page << 16) + data; | ||
464 | 460 | ||
465 | dbg_hid("unknown local item tag 0x%x\n", item->tag); | 461 | for (n = parser->local.usage_minimum; n <= data; n++) |
466 | return 0; | 462 | if (hid_add_usage(parser, n)) { |
463 | dbg_hid("hid_add_usage failed\n"); | ||
464 | return -1; | ||
465 | } | ||
466 | return 0; | ||
467 | |||
468 | default: | ||
469 | |||
470 | dbg_hid("unknown local item tag 0x%x\n", item->tag); | ||
471 | return 0; | ||
467 | } | 472 | } |
468 | return 0; | 473 | return 0; |
469 | } | 474 | } |
@@ -480,24 +485,24 @@ static int hid_parser_main(struct hid_parser *parser, struct hid_item *item) | |||
480 | data = item_udata(item); | 485 | data = item_udata(item); |
481 | 486 | ||
482 | switch (item->tag) { | 487 | switch (item->tag) { |
483 | case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION: | 488 | case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION: |
484 | ret = open_collection(parser, data & 0xff); | 489 | ret = open_collection(parser, data & 0xff); |
485 | break; | 490 | break; |
486 | case HID_MAIN_ITEM_TAG_END_COLLECTION: | 491 | case HID_MAIN_ITEM_TAG_END_COLLECTION: |
487 | ret = close_collection(parser); | 492 | ret = close_collection(parser); |
488 | break; | 493 | break; |
489 | case HID_MAIN_ITEM_TAG_INPUT: | 494 | case HID_MAIN_ITEM_TAG_INPUT: |
490 | ret = hid_add_field(parser, HID_INPUT_REPORT, data); | 495 | ret = hid_add_field(parser, HID_INPUT_REPORT, data); |
491 | break; | 496 | break; |
492 | case HID_MAIN_ITEM_TAG_OUTPUT: | 497 | case HID_MAIN_ITEM_TAG_OUTPUT: |
493 | ret = hid_add_field(parser, HID_OUTPUT_REPORT, data); | 498 | ret = hid_add_field(parser, HID_OUTPUT_REPORT, data); |
494 | break; | 499 | break; |
495 | case HID_MAIN_ITEM_TAG_FEATURE: | 500 | case HID_MAIN_ITEM_TAG_FEATURE: |
496 | ret = hid_add_field(parser, HID_FEATURE_REPORT, data); | 501 | ret = hid_add_field(parser, HID_FEATURE_REPORT, data); |
497 | break; | 502 | break; |
498 | default: | 503 | default: |
499 | dbg_hid("unknown main item tag 0x%x\n", item->tag); | 504 | dbg_hid("unknown main item tag 0x%x\n", item->tag); |
500 | ret = 0; | 505 | ret = 0; |
501 | } | 506 | } |
502 | 507 | ||
503 | memset(&parser->local, 0, sizeof(parser->local)); /* Reset the local parser environment */ | 508 | memset(&parser->local, 0, sizeof(parser->local)); /* Reset the local parser environment */ |
@@ -534,9 +539,10 @@ static void hid_free_report(struct hid_report *report) | |||
534 | * Free a device structure, all reports, and all fields. | 539 | * Free a device structure, all reports, and all fields. |
535 | */ | 540 | */ |
536 | 541 | ||
537 | void hid_free_device(struct hid_device *device) | 542 | static void hid_device_release(struct device *dev) |
538 | { | 543 | { |
539 | unsigned i,j; | 544 | struct hid_device *device = container_of(dev, struct hid_device, dev); |
545 | unsigned i, j; | ||
540 | 546 | ||
541 | for (i = 0; i < HID_REPORT_TYPES; i++) { | 547 | for (i = 0; i < HID_REPORT_TYPES; i++) { |
542 | struct hid_report_enum *report_enum = device->report_enum + i; | 548 | struct hid_report_enum *report_enum = device->report_enum + i; |
@@ -552,7 +558,6 @@ void hid_free_device(struct hid_device *device) | |||
552 | kfree(device->collection); | 558 | kfree(device->collection); |
553 | kfree(device); | 559 | kfree(device); |
554 | } | 560 | } |
555 | EXPORT_SYMBOL_GPL(hid_free_device); | ||
556 | 561 | ||
557 | /* | 562 | /* |
558 | * Fetch a report description item from the data stream. We support long | 563 | * Fetch a report description item from the data stream. We support long |
@@ -593,47 +598,52 @@ static u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item) | |||
593 | item->size = b & 3; | 598 | item->size = b & 3; |
594 | 599 | ||
595 | switch (item->size) { | 600 | switch (item->size) { |
601 | case 0: | ||
602 | return start; | ||
596 | 603 | ||
597 | case 0: | 604 | case 1: |
598 | return start; | 605 | if ((end - start) < 1) |
599 | 606 | return NULL; | |
600 | case 1: | 607 | item->data.u8 = *start++; |
601 | if ((end - start) < 1) | 608 | return start; |
602 | return NULL; | ||
603 | item->data.u8 = *start++; | ||
604 | return start; | ||
605 | 609 | ||
606 | case 2: | 610 | case 2: |
607 | if ((end - start) < 2) | 611 | if ((end - start) < 2) |
608 | return NULL; | 612 | return NULL; |
609 | item->data.u16 = get_unaligned_le16(start); | 613 | item->data.u16 = get_unaligned_le16(start); |
610 | start = (__u8 *)((__le16 *)start + 1); | 614 | start = (__u8 *)((__le16 *)start + 1); |
611 | return start; | 615 | return start; |
612 | 616 | ||
613 | case 3: | 617 | case 3: |
614 | item->size++; | 618 | item->size++; |
615 | if ((end - start) < 4) | 619 | if ((end - start) < 4) |
616 | return NULL; | 620 | return NULL; |
617 | item->data.u32 = get_unaligned_le32(start); | 621 | item->data.u32 = get_unaligned_le32(start); |
618 | start = (__u8 *)((__le32 *)start + 1); | 622 | start = (__u8 *)((__le32 *)start + 1); |
619 | return start; | 623 | return start; |
620 | } | 624 | } |
621 | 625 | ||
622 | return NULL; | 626 | return NULL; |
623 | } | 627 | } |
624 | 628 | ||
625 | /* | 629 | /** |
630 | * hid_parse_report - parse device report | ||
631 | * | ||
632 | * @device: hid device | ||
633 | * @start: report start | ||
634 | * @size: report size | ||
635 | * | ||
626 | * Parse a report description into a hid_device structure. Reports are | 636 | * Parse a report description into a hid_device structure. Reports are |
627 | * enumerated, fields are attached to these reports. | 637 | * enumerated, fields are attached to these reports. |
638 | * 0 returned on success, otherwise nonzero error value. | ||
628 | */ | 639 | */ |
629 | 640 | int hid_parse_report(struct hid_device *device, __u8 *start, | |
630 | struct hid_device *hid_parse_report(__u8 *start, unsigned size) | 641 | unsigned size) |
631 | { | 642 | { |
632 | struct hid_device *device; | ||
633 | struct hid_parser *parser; | 643 | struct hid_parser *parser; |
634 | struct hid_item item; | 644 | struct hid_item item; |
635 | __u8 *end; | 645 | __u8 *end; |
636 | unsigned i; | 646 | int ret; |
637 | static int (*dispatch_type[])(struct hid_parser *parser, | 647 | static int (*dispatch_type[])(struct hid_parser *parser, |
638 | struct hid_item *item) = { | 648 | struct hid_item *item) = { |
639 | hid_parser_main, | 649 | hid_parser_main, |
@@ -642,76 +652,57 @@ struct hid_device *hid_parse_report(__u8 *start, unsigned size) | |||
642 | hid_parser_reserved | 652 | hid_parser_reserved |
643 | }; | 653 | }; |
644 | 654 | ||
645 | if (!(device = kzalloc(sizeof(struct hid_device), GFP_KERNEL))) | 655 | if (device->driver->report_fixup) |
646 | return NULL; | 656 | device->driver->report_fixup(device, start, size); |
647 | 657 | ||
648 | if (!(device->collection = kzalloc(sizeof(struct hid_collection) * | 658 | device->rdesc = kmalloc(size, GFP_KERNEL); |
649 | HID_DEFAULT_NUM_COLLECTIONS, GFP_KERNEL))) { | 659 | if (device->rdesc == NULL) |
650 | kfree(device); | 660 | return -ENOMEM; |
651 | return NULL; | ||
652 | } | ||
653 | device->collection_size = HID_DEFAULT_NUM_COLLECTIONS; | ||
654 | |||
655 | for (i = 0; i < HID_REPORT_TYPES; i++) | ||
656 | INIT_LIST_HEAD(&device->report_enum[i].report_list); | ||
657 | |||
658 | if (!(device->rdesc = kmalloc(size, GFP_KERNEL))) { | ||
659 | kfree(device->collection); | ||
660 | kfree(device); | ||
661 | return NULL; | ||
662 | } | ||
663 | memcpy(device->rdesc, start, size); | 661 | memcpy(device->rdesc, start, size); |
664 | device->rsize = size; | 662 | device->rsize = size; |
665 | 663 | ||
666 | if (!(parser = vmalloc(sizeof(struct hid_parser)))) { | 664 | parser = vmalloc(sizeof(struct hid_parser)); |
667 | kfree(device->rdesc); | 665 | if (!parser) { |
668 | kfree(device->collection); | 666 | ret = -ENOMEM; |
669 | kfree(device); | 667 | goto err; |
670 | return NULL; | ||
671 | } | 668 | } |
669 | |||
672 | memset(parser, 0, sizeof(struct hid_parser)); | 670 | memset(parser, 0, sizeof(struct hid_parser)); |
673 | parser->device = device; | 671 | parser->device = device; |
674 | 672 | ||
675 | end = start + size; | 673 | end = start + size; |
674 | ret = -EINVAL; | ||
676 | while ((start = fetch_item(start, end, &item)) != NULL) { | 675 | while ((start = fetch_item(start, end, &item)) != NULL) { |
677 | 676 | ||
678 | if (item.format != HID_ITEM_FORMAT_SHORT) { | 677 | if (item.format != HID_ITEM_FORMAT_SHORT) { |
679 | dbg_hid("unexpected long global item\n"); | 678 | dbg_hid("unexpected long global item\n"); |
680 | hid_free_device(device); | 679 | goto err; |
681 | vfree(parser); | ||
682 | return NULL; | ||
683 | } | 680 | } |
684 | 681 | ||
685 | if (dispatch_type[item.type](parser, &item)) { | 682 | if (dispatch_type[item.type](parser, &item)) { |
686 | dbg_hid("item %u %u %u %u parsing failed\n", | 683 | dbg_hid("item %u %u %u %u parsing failed\n", |
687 | item.format, (unsigned)item.size, (unsigned)item.type, (unsigned)item.tag); | 684 | item.format, (unsigned)item.size, (unsigned)item.type, (unsigned)item.tag); |
688 | hid_free_device(device); | 685 | goto err; |
689 | vfree(parser); | ||
690 | return NULL; | ||
691 | } | 686 | } |
692 | 687 | ||
693 | if (start == end) { | 688 | if (start == end) { |
694 | if (parser->collection_stack_ptr) { | 689 | if (parser->collection_stack_ptr) { |
695 | dbg_hid("unbalanced collection at end of report description\n"); | 690 | dbg_hid("unbalanced collection at end of report description\n"); |
696 | hid_free_device(device); | 691 | goto err; |
697 | vfree(parser); | ||
698 | return NULL; | ||
699 | } | 692 | } |
700 | if (parser->local.delimiter_depth) { | 693 | if (parser->local.delimiter_depth) { |
701 | dbg_hid("unbalanced delimiter at end of report description\n"); | 694 | dbg_hid("unbalanced delimiter at end of report description\n"); |
702 | hid_free_device(device); | 695 | goto err; |
703 | vfree(parser); | ||
704 | return NULL; | ||
705 | } | 696 | } |
706 | vfree(parser); | 697 | vfree(parser); |
707 | return device; | 698 | return 0; |
708 | } | 699 | } |
709 | } | 700 | } |
710 | 701 | ||
711 | dbg_hid("item fetching failed at offset %d\n", (int)(end - start)); | 702 | dbg_hid("item fetching failed at offset %d\n", (int)(end - start)); |
712 | hid_free_device(device); | 703 | err: |
713 | vfree(parser); | 704 | vfree(parser); |
714 | return NULL; | 705 | return ret; |
715 | } | 706 | } |
716 | EXPORT_SYMBOL_GPL(hid_parse_report); | 707 | EXPORT_SYMBOL_GPL(hid_parse_report); |
717 | 708 | ||
@@ -724,9 +715,9 @@ EXPORT_SYMBOL_GPL(hid_parse_report); | |||
724 | static s32 snto32(__u32 value, unsigned n) | 715 | static s32 snto32(__u32 value, unsigned n) |
725 | { | 716 | { |
726 | switch (n) { | 717 | switch (n) { |
727 | case 8: return ((__s8)value); | 718 | case 8: return ((__s8)value); |
728 | case 16: return ((__s16)value); | 719 | case 16: return ((__s16)value); |
729 | case 32: return ((__s32)value); | 720 | case 32: return ((__s32)value); |
730 | } | 721 | } |
731 | return value & (1 << (n - 1)) ? value | (-1 << n) : value; | 722 | return value & (1 << (n - 1)) ? value | (-1 << n) : value; |
732 | } | 723 | } |
@@ -815,9 +806,73 @@ static __inline__ int search(__s32 *array, __s32 value, unsigned n) | |||
815 | return -1; | 806 | return -1; |
816 | } | 807 | } |
817 | 808 | ||
818 | static void hid_process_event(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value, int interrupt) | 809 | /** |
810 | * hid_match_report - check if driver's raw_event should be called | ||
811 | * | ||
812 | * @hid: hid device | ||
813 | * @report_type: type to match against | ||
814 | * | ||
815 | * compare hid->driver->report_table->report_type to report->type | ||
816 | */ | ||
817 | static int hid_match_report(struct hid_device *hid, struct hid_report *report) | ||
818 | { | ||
819 | const struct hid_report_id *id = hid->driver->report_table; | ||
820 | |||
821 | if (!id) /* NULL means all */ | ||
822 | return 1; | ||
823 | |||
824 | for (; id->report_type != HID_TERMINATOR; id++) | ||
825 | if (id->report_type == HID_ANY_ID || | ||
826 | id->report_type == report->type) | ||
827 | return 1; | ||
828 | return 0; | ||
829 | } | ||
830 | |||
831 | /** | ||
832 | * hid_match_usage - check if driver's event should be called | ||
833 | * | ||
834 | * @hid: hid device | ||
835 | * @usage: usage to match against | ||
836 | * | ||
837 | * compare hid->driver->usage_table->usage_{type,code} to | ||
838 | * usage->usage_{type,code} | ||
839 | */ | ||
840 | static int hid_match_usage(struct hid_device *hid, struct hid_usage *usage) | ||
819 | { | 841 | { |
842 | const struct hid_usage_id *id = hid->driver->usage_table; | ||
843 | |||
844 | if (!id) /* NULL means all */ | ||
845 | return 1; | ||
846 | |||
847 | for (; id->usage_type != HID_ANY_ID - 1; id++) | ||
848 | if ((id->usage_hid == HID_ANY_ID || | ||
849 | id->usage_hid == usage->hid) && | ||
850 | (id->usage_type == HID_ANY_ID || | ||
851 | id->usage_type == usage->type) && | ||
852 | (id->usage_code == HID_ANY_ID || | ||
853 | id->usage_code == usage->code)) | ||
854 | return 1; | ||
855 | return 0; | ||
856 | } | ||
857 | |||
858 | static void hid_process_event(struct hid_device *hid, struct hid_field *field, | ||
859 | struct hid_usage *usage, __s32 value, int interrupt) | ||
860 | { | ||
861 | struct hid_driver *hdrv = hid->driver; | ||
862 | int ret; | ||
863 | |||
820 | hid_dump_input(usage, value); | 864 | hid_dump_input(usage, value); |
865 | |||
866 | if (hdrv && hdrv->event && hid_match_usage(hid, usage)) { | ||
867 | ret = hdrv->event(hid, field, usage, value); | ||
868 | if (ret != 0) { | ||
869 | if (ret < 0) | ||
870 | dbg_hid("%s's event failed with %d\n", | ||
871 | hdrv->name, ret); | ||
872 | return; | ||
873 | } | ||
874 | } | ||
875 | |||
821 | if (hid->claimed & HID_CLAIMED_INPUT) | 876 | if (hid->claimed & HID_CLAIMED_INPUT) |
822 | hidinput_hid_event(hid, field, usage, value); | 877 | hidinput_hid_event(hid, field, usage, value); |
823 | if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event) | 878 | if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event) |
@@ -946,44 +1001,47 @@ int hid_set_field(struct hid_field *field, unsigned offset, __s32 value) | |||
946 | } | 1001 | } |
947 | EXPORT_SYMBOL_GPL(hid_set_field); | 1002 | EXPORT_SYMBOL_GPL(hid_set_field); |
948 | 1003 | ||
949 | int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int interrupt) | 1004 | static struct hid_report *hid_get_report(struct hid_report_enum *report_enum, |
1005 | const u8 *data) | ||
950 | { | 1006 | { |
951 | struct hid_report_enum *report_enum = hid->report_enum + type; | ||
952 | struct hid_report *report; | 1007 | struct hid_report *report; |
953 | int n, rsize, i; | 1008 | unsigned int n = 0; /* Normally report number is 0 */ |
954 | 1009 | ||
955 | if (!hid) | 1010 | /* Device uses numbered reports, data[0] is report number */ |
956 | return -ENODEV; | 1011 | if (report_enum->numbered) |
1012 | n = *data; | ||
957 | 1013 | ||
958 | if (!size) { | 1014 | report = report_enum->report_id_hash[n]; |
959 | dbg_hid("empty report\n"); | 1015 | if (report == NULL) |
960 | return -1; | 1016 | dbg_hid("undefined report_id %u received\n", n); |
961 | } | ||
962 | 1017 | ||
963 | dbg_hid("report (size %u) (%snumbered)\n", size, report_enum->numbered ? "" : "un"); | 1018 | return report; |
1019 | } | ||
964 | 1020 | ||
965 | n = 0; /* Normally report number is 0 */ | 1021 | void hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size, |
966 | if (report_enum->numbered) { /* Device uses numbered reports, data[0] is report number */ | 1022 | int interrupt) |
967 | n = *data++; | 1023 | { |
968 | size--; | 1024 | struct hid_report_enum *report_enum = hid->report_enum + type; |
969 | } | 1025 | struct hid_report *report; |
1026 | unsigned int a; | ||
1027 | int rsize, csize = size; | ||
1028 | u8 *cdata = data; | ||
970 | 1029 | ||
971 | /* dump the report */ | 1030 | report = hid_get_report(report_enum, data); |
972 | dbg_hid("report %d (size %u) = ", n, size); | 1031 | if (!report) |
973 | for (i = 0; i < size; i++) | 1032 | return; |
974 | dbg_hid_line(" %02x", data[i]); | ||
975 | dbg_hid_line("\n"); | ||
976 | 1033 | ||
977 | if (!(report = report_enum->report_id_hash[n])) { | 1034 | if (report_enum->numbered) { |
978 | dbg_hid("undefined report_id %d received\n", n); | 1035 | cdata++; |
979 | return -1; | 1036 | csize--; |
980 | } | 1037 | } |
981 | 1038 | ||
982 | rsize = ((report->size - 1) >> 3) + 1; | 1039 | rsize = ((report->size - 1) >> 3) + 1; |
983 | 1040 | ||
984 | if (size < rsize) { | 1041 | if (csize < rsize) { |
985 | dbg_hid("report %d is too short, (%d < %d)\n", report->id, size, rsize); | 1042 | dbg_hid("report %d is too short, (%d < %d)\n", report->id, |
986 | memset(data + size, 0, rsize - size); | 1043 | csize, rsize); |
1044 | memset(cdata + csize, 0, rsize - csize); | ||
987 | } | 1045 | } |
988 | 1046 | ||
989 | if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event) | 1047 | if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event) |
@@ -996,24 +1054,661 @@ int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int i | |||
996 | hidraw_report_event(hid, data, size); | 1054 | hidraw_report_event(hid, data, size); |
997 | } | 1055 | } |
998 | 1056 | ||
999 | for (n = 0; n < report->maxfield; n++) | 1057 | for (a = 0; a < report->maxfield; a++) |
1000 | hid_input_field(hid, report->field[n], data, interrupt); | 1058 | hid_input_field(hid, report->field[a], cdata, interrupt); |
1001 | 1059 | ||
1002 | if (hid->claimed & HID_CLAIMED_INPUT) | 1060 | if (hid->claimed & HID_CLAIMED_INPUT) |
1003 | hidinput_report_event(hid, report); | 1061 | hidinput_report_event(hid, report); |
1062 | } | ||
1063 | EXPORT_SYMBOL_GPL(hid_report_raw_event); | ||
1064 | |||
1065 | /** | ||
1066 | * hid_input_report - report data from lower layer (usb, bt...) | ||
1067 | * | ||
1068 | * @hid: hid device | ||
1069 | * @type: HID report type (HID_*_REPORT) | ||
1070 | * @data: report contents | ||
1071 | * @size: size of data parameter | ||
1072 | * @interrupt: called from atomic? | ||
1073 | * | ||
1074 | * This is data entry for lower layers. | ||
1075 | */ | ||
1076 | int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int interrupt) | ||
1077 | { | ||
1078 | struct hid_report_enum *report_enum = hid->report_enum + type; | ||
1079 | struct hid_driver *hdrv = hid->driver; | ||
1080 | struct hid_report *report; | ||
1081 | unsigned int i; | ||
1082 | int ret; | ||
1083 | |||
1084 | if (!hid || !hid->driver) | ||
1085 | return -ENODEV; | ||
1086 | |||
1087 | if (!size) { | ||
1088 | dbg_hid("empty report\n"); | ||
1089 | return -1; | ||
1090 | } | ||
1091 | |||
1092 | dbg_hid("report (size %u) (%snumbered)\n", size, report_enum->numbered ? "" : "un"); | ||
1093 | |||
1094 | report = hid_get_report(report_enum, data); | ||
1095 | if (!report) | ||
1096 | return -1; | ||
1097 | |||
1098 | /* dump the report */ | ||
1099 | dbg_hid("report %d (size %u) = ", report->id, size); | ||
1100 | for (i = 0; i < size; i++) | ||
1101 | dbg_hid_line(" %02x", data[i]); | ||
1102 | dbg_hid_line("\n"); | ||
1103 | |||
1104 | if (hdrv && hdrv->raw_event && hid_match_report(hid, report)) { | ||
1105 | ret = hdrv->raw_event(hid, report, data, size); | ||
1106 | if (ret != 0) | ||
1107 | return ret < 0 ? ret : 0; | ||
1108 | } | ||
1109 | |||
1110 | hid_report_raw_event(hid, type, data, size, interrupt); | ||
1004 | 1111 | ||
1005 | return 0; | 1112 | return 0; |
1006 | } | 1113 | } |
1007 | EXPORT_SYMBOL_GPL(hid_input_report); | 1114 | EXPORT_SYMBOL_GPL(hid_input_report); |
1008 | 1115 | ||
1116 | static bool hid_match_one_id(struct hid_device *hdev, | ||
1117 | const struct hid_device_id *id) | ||
1118 | { | ||
1119 | return id->bus == hdev->bus && | ||
1120 | (id->vendor == HID_ANY_ID || id->vendor == hdev->vendor) && | ||
1121 | (id->product == HID_ANY_ID || id->product == hdev->product); | ||
1122 | } | ||
1123 | |||
1124 | static const struct hid_device_id *hid_match_id(struct hid_device *hdev, | ||
1125 | const struct hid_device_id *id) | ||
1126 | { | ||
1127 | for (; id->bus; id++) | ||
1128 | if (hid_match_one_id(hdev, id)) | ||
1129 | return id; | ||
1130 | |||
1131 | return NULL; | ||
1132 | } | ||
1133 | |||
1134 | static const struct hid_device_id hid_hiddev_list[] = { | ||
1135 | { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS) }, | ||
1136 | { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1) }, | ||
1137 | { } | ||
1138 | }; | ||
1139 | |||
1140 | static bool hid_hiddev(struct hid_device *hdev) | ||
1141 | { | ||
1142 | return !!hid_match_id(hdev, hid_hiddev_list); | ||
1143 | } | ||
1144 | |||
1145 | int hid_connect(struct hid_device *hdev, unsigned int connect_mask) | ||
1146 | { | ||
1147 | static const char *types[] = { "Device", "Pointer", "Mouse", "Device", | ||
1148 | "Joystick", "Gamepad", "Keyboard", "Keypad", | ||
1149 | "Multi-Axis Controller" | ||
1150 | }; | ||
1151 | const char *type, *bus; | ||
1152 | char buf[64]; | ||
1153 | unsigned int i; | ||
1154 | int len; | ||
1155 | |||
1156 | if (hdev->bus != BUS_USB) | ||
1157 | connect_mask &= ~HID_CONNECT_HIDDEV; | ||
1158 | if (hid_hiddev(hdev)) | ||
1159 | connect_mask |= HID_CONNECT_HIDDEV_FORCE; | ||
1160 | |||
1161 | if ((connect_mask & HID_CONNECT_HIDINPUT) && !hidinput_connect(hdev, | ||
1162 | connect_mask & HID_CONNECT_HIDINPUT_FORCE)) | ||
1163 | hdev->claimed |= HID_CLAIMED_INPUT; | ||
1164 | if ((connect_mask & HID_CONNECT_HIDDEV) && hdev->hiddev_connect && | ||
1165 | !hdev->hiddev_connect(hdev, | ||
1166 | connect_mask & HID_CONNECT_HIDDEV_FORCE)) | ||
1167 | hdev->claimed |= HID_CLAIMED_HIDDEV; | ||
1168 | if ((connect_mask & HID_CONNECT_HIDRAW) && !hidraw_connect(hdev)) | ||
1169 | hdev->claimed |= HID_CLAIMED_HIDRAW; | ||
1170 | |||
1171 | if (!hdev->claimed) { | ||
1172 | dev_err(&hdev->dev, "claimed by neither input, hiddev nor " | ||
1173 | "hidraw\n"); | ||
1174 | return -ENODEV; | ||
1175 | } | ||
1176 | |||
1177 | if ((hdev->claimed & HID_CLAIMED_INPUT) && | ||
1178 | (connect_mask & HID_CONNECT_FF) && hdev->ff_init) | ||
1179 | hdev->ff_init(hdev); | ||
1180 | |||
1181 | len = 0; | ||
1182 | if (hdev->claimed & HID_CLAIMED_INPUT) | ||
1183 | len += sprintf(buf + len, "input"); | ||
1184 | if (hdev->claimed & HID_CLAIMED_HIDDEV) | ||
1185 | len += sprintf(buf + len, "%shiddev%d", len ? "," : "", | ||
1186 | hdev->minor); | ||
1187 | if (hdev->claimed & HID_CLAIMED_HIDRAW) | ||
1188 | len += sprintf(buf + len, "%shidraw%d", len ? "," : "", | ||
1189 | ((struct hidraw *)hdev->hidraw)->minor); | ||
1190 | |||
1191 | type = "Device"; | ||
1192 | for (i = 0; i < hdev->maxcollection; i++) { | ||
1193 | struct hid_collection *col = &hdev->collection[i]; | ||
1194 | if (col->type == HID_COLLECTION_APPLICATION && | ||
1195 | (col->usage & HID_USAGE_PAGE) == HID_UP_GENDESK && | ||
1196 | (col->usage & 0xffff) < ARRAY_SIZE(types)) { | ||
1197 | type = types[col->usage & 0xffff]; | ||
1198 | break; | ||
1199 | } | ||
1200 | } | ||
1201 | |||
1202 | switch (hdev->bus) { | ||
1203 | case BUS_USB: | ||
1204 | bus = "USB"; | ||
1205 | break; | ||
1206 | case BUS_BLUETOOTH: | ||
1207 | bus = "BLUETOOTH"; | ||
1208 | break; | ||
1209 | default: | ||
1210 | bus = "<UNKNOWN>"; | ||
1211 | } | ||
1212 | |||
1213 | dev_info(&hdev->dev, "%s: %s HID v%x.%02x %s [%s] on %s\n", | ||
1214 | buf, bus, hdev->version >> 8, hdev->version & 0xff, | ||
1215 | type, hdev->name, hdev->phys); | ||
1216 | |||
1217 | return 0; | ||
1218 | } | ||
1219 | EXPORT_SYMBOL_GPL(hid_connect); | ||
1220 | |||
1221 | static const struct hid_device_id hid_blacklist[] = { | ||
1222 | { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) }, | ||
1223 | { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) }, | ||
1224 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL) }, | ||
1225 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) }, | ||
1226 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) }, | ||
1227 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) }, | ||
1228 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) }, | ||
1229 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) }, | ||
1230 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) }, | ||
1231 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) }, | ||
1232 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) }, | ||
1233 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) }, | ||
1234 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) }, | ||
1235 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) }, | ||
1236 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) }, | ||
1237 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) }, | ||
1238 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI) }, | ||
1239 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO) }, | ||
1240 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS) }, | ||
1241 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) }, | ||
1242 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) }, | ||
1243 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) }, | ||
1244 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI) }, | ||
1245 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO) }, | ||
1246 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS) }, | ||
1247 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) }, | ||
1248 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) }, | ||
1249 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) }, | ||
1250 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) }, | ||
1251 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) }, | ||
1252 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) }, | ||
1253 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) }, | ||
1254 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) }, | ||
1255 | { HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) }, | ||
1256 | { HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM) }, | ||
1257 | { HID_USB_DEVICE(USB_VENDOR_ID_BRIGHT, USB_DEVICE_ID_BRIGHT_ABNT2) }, | ||
1258 | { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) }, | ||
1259 | { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) }, | ||
1260 | { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) }, | ||
1261 | { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) }, | ||
1262 | { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE) }, | ||
1263 | { HID_USB_DEVICE(USB_VENDOR_ID_DELL, USB_DEVICE_ID_DELL_W7658) }, | ||
1264 | { HID_USB_DEVICE(USB_VENDOR_ID_DELL, USB_DEVICE_ID_DELL_SK8115) }, | ||
1265 | { HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) }, | ||
1266 | { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) }, | ||
1267 | { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) }, | ||
1268 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) }, | ||
1269 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) }, | ||
1270 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) }, | ||
1271 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER) }, | ||
1272 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP) }, | ||
1273 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE) }, | ||
1274 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI) }, | ||
1275 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_KBD) }, | ||
1276 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD) }, | ||
1277 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500) }, | ||
1278 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_LX3) }, | ||
1279 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_V150) }, | ||
1280 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D) }, | ||
1281 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL) }, | ||
1282 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD) }, | ||
1283 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2) }, | ||
1284 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D) }, | ||
1285 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO) }, | ||
1286 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL) }, | ||
1287 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2) }, | ||
1288 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2) }, | ||
1289 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV) }, | ||
1290 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K) }, | ||
1291 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K) }, | ||
1292 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB) }, | ||
1293 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) }, | ||
1294 | { HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) }, | ||
1295 | { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) }, | ||
1296 | { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) }, | ||
1297 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) }, | ||
1298 | { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) }, | ||
1299 | |||
1300 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 0x030c) }, | ||
1301 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT) }, | ||
1302 | { } | ||
1303 | }; | ||
1304 | |||
1305 | static int hid_bus_match(struct device *dev, struct device_driver *drv) | ||
1306 | { | ||
1307 | struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver); | ||
1308 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); | ||
1309 | |||
1310 | if (!hid_match_id(hdev, hdrv->id_table)) | ||
1311 | return 0; | ||
1312 | |||
1313 | /* generic wants all non-blacklisted */ | ||
1314 | if (!strncmp(hdrv->name, "generic-", 8)) | ||
1315 | return !hid_match_id(hdev, hid_blacklist); | ||
1316 | |||
1317 | return 1; | ||
1318 | } | ||
1319 | |||
1320 | static int hid_device_probe(struct device *dev) | ||
1321 | { | ||
1322 | struct hid_driver *hdrv = container_of(dev->driver, | ||
1323 | struct hid_driver, driver); | ||
1324 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); | ||
1325 | const struct hid_device_id *id; | ||
1326 | int ret = 0; | ||
1327 | |||
1328 | if (!hdev->driver) { | ||
1329 | id = hid_match_id(hdev, hdrv->id_table); | ||
1330 | if (id == NULL) | ||
1331 | return -ENODEV; | ||
1332 | |||
1333 | hdev->driver = hdrv; | ||
1334 | if (hdrv->probe) { | ||
1335 | ret = hdrv->probe(hdev, id); | ||
1336 | } else { /* default probe */ | ||
1337 | ret = hid_parse(hdev); | ||
1338 | if (!ret) | ||
1339 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); | ||
1340 | } | ||
1341 | if (ret) | ||
1342 | hdev->driver = NULL; | ||
1343 | } | ||
1344 | return ret; | ||
1345 | } | ||
1346 | |||
1347 | static int hid_device_remove(struct device *dev) | ||
1348 | { | ||
1349 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); | ||
1350 | struct hid_driver *hdrv = hdev->driver; | ||
1351 | |||
1352 | if (hdrv) { | ||
1353 | if (hdrv->remove) | ||
1354 | hdrv->remove(hdev); | ||
1355 | else /* default remove */ | ||
1356 | hid_hw_stop(hdev); | ||
1357 | hdev->driver = NULL; | ||
1358 | } | ||
1359 | |||
1360 | return 0; | ||
1361 | } | ||
1362 | |||
1363 | static int hid_uevent(struct device *dev, struct kobj_uevent_env *env) | ||
1364 | { | ||
1365 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); | ||
1366 | |||
1367 | if (add_uevent_var(env, "HID_ID=%04X:%08X:%08X", | ||
1368 | hdev->bus, hdev->vendor, hdev->product)) | ||
1369 | return -ENOMEM; | ||
1370 | |||
1371 | if (add_uevent_var(env, "HID_NAME=%s", hdev->name)) | ||
1372 | return -ENOMEM; | ||
1373 | |||
1374 | if (add_uevent_var(env, "HID_PHYS=%s", hdev->phys)) | ||
1375 | return -ENOMEM; | ||
1376 | |||
1377 | if (add_uevent_var(env, "HID_UNIQ=%s", hdev->uniq)) | ||
1378 | return -ENOMEM; | ||
1379 | |||
1380 | if (add_uevent_var(env, "MODALIAS=hid:b%04Xv%08Xp%08X", | ||
1381 | hdev->bus, hdev->vendor, hdev->product)) | ||
1382 | return -ENOMEM; | ||
1383 | |||
1384 | return 0; | ||
1385 | } | ||
1386 | |||
1387 | static struct bus_type hid_bus_type = { | ||
1388 | .name = "hid", | ||
1389 | .match = hid_bus_match, | ||
1390 | .probe = hid_device_probe, | ||
1391 | .remove = hid_device_remove, | ||
1392 | .uevent = hid_uevent, | ||
1393 | }; | ||
1394 | |||
1395 | static const struct hid_device_id hid_ignore_list[] = { | ||
1396 | { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR) }, | ||
1397 | { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302) }, | ||
1398 | { HID_USB_DEVICE(USB_VENDOR_ID_ADS_TECH, USB_DEVICE_ID_ADS_TECH_RADIO_SI470X) }, | ||
1399 | { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01) }, | ||
1400 | { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10) }, | ||
1401 | { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20) }, | ||
1402 | { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21) }, | ||
1403 | { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22) }, | ||
1404 | { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23) }, | ||
1405 | { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) }, | ||
1406 | { HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) }, | ||
1407 | { HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) }, | ||
1408 | { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_LCM)}, | ||
1409 | { HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) }, | ||
1410 | { HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) }, | ||
1411 | { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X) }, | ||
1412 | { HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109) }, | ||
1413 | { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM) }, | ||
1414 | { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE) }, | ||
1415 | { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE) }, | ||
1416 | { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20) }, | ||
1417 | { HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) }, | ||
1418 | { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) }, | ||
1419 | { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0001) }, | ||
1420 | { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0002) }, | ||
1421 | { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0003) }, | ||
1422 | { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0004) }, | ||
1423 | { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30) }, | ||
1424 | { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30) }, | ||
1425 | { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT) }, | ||
1426 | { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT) }, | ||
1427 | { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT) }, | ||
1428 | { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT) }, | ||
1429 | { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT) }, | ||
1430 | { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL) }, | ||
1431 | { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_SUPER_Q2) }, | ||
1432 | { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_GOGOPEN) }, | ||
1433 | { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_PENPOWER) }, | ||
1434 | { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003) }, | ||
1435 | { HID_USB_DEVICE(USB_VENDOR_ID_GRETAGMACBETH, USB_DEVICE_ID_GRETAGMACBETH_HUEY) }, | ||
1436 | { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE) }, | ||
1437 | { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB) }, | ||
1438 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90) }, | ||
1439 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100) }, | ||
1440 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101) }, | ||
1441 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103) }, | ||
1442 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104) }, | ||
1443 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105) }, | ||
1444 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106) }, | ||
1445 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107) }, | ||
1446 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108) }, | ||
1447 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200) }, | ||
1448 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201) }, | ||
1449 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202) }, | ||
1450 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203) }, | ||
1451 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204) }, | ||
1452 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205) }, | ||
1453 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206) }, | ||
1454 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207) }, | ||
1455 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300) }, | ||
1456 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301) }, | ||
1457 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302) }, | ||
1458 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303) }, | ||
1459 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304) }, | ||
1460 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305) }, | ||
1461 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306) }, | ||
1462 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307) }, | ||
1463 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308) }, | ||
1464 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309) }, | ||
1465 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400) }, | ||
1466 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401) }, | ||
1467 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402) }, | ||
1468 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403) }, | ||
1469 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404) }, | ||
1470 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405) }, | ||
1471 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500) }, | ||
1472 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501) }, | ||
1473 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502) }, | ||
1474 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503) }, | ||
1475 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504) }, | ||
1476 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000) }, | ||
1477 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001) }, | ||
1478 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002) }, | ||
1479 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003) }, | ||
1480 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004) }, | ||
1481 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005) }, | ||
1482 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006) }, | ||
1483 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1007) }, | ||
1484 | { HID_USB_DEVICE(USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA) }, | ||
1485 | { HID_USB_DEVICE(USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO) }, | ||
1486 | { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_GPEN_560) }, | ||
1487 | { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) }, | ||
1488 | { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) }, | ||
1489 | { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) }, | ||
1490 | { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) }, | ||
1491 | { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) }, | ||
1492 | { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) }, | ||
1493 | { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY1) }, | ||
1494 | { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2) }, | ||
1495 | { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM) }, | ||
1496 | { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB) }, | ||
1497 | { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT) }, | ||
1498 | { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER) }, | ||
1499 | { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL) }, | ||
1500 | { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST) }, | ||
1501 | { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) }, | ||
1502 | { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) }, | ||
1503 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1) }, | ||
1504 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT2) }, | ||
1505 | { HID_USB_DEVICE(USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR, USB_DEVICE_ID_N_S_HARMONY) }, | ||
1506 | { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100) }, | ||
1507 | { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20) }, | ||
1508 | { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30) }, | ||
1509 | { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100) }, | ||
1510 | { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108) }, | ||
1511 | { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118) }, | ||
1512 | { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200) }, | ||
1513 | { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300) }, | ||
1514 | { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400) }, | ||
1515 | { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500) }, | ||
1516 | { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0001) }, | ||
1517 | { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0002) }, | ||
1518 | { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0003) }, | ||
1519 | { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0004) }, | ||
1520 | { HID_USB_DEVICE(USB_VENDOR_ID_SOUNDGRAPH, USB_DEVICE_ID_SOUNDGRAPH_IMON_LCD) }, | ||
1521 | { HID_USB_DEVICE(USB_VENDOR_ID_TENX, USB_DEVICE_ID_TENX_IBUDDY1) }, | ||
1522 | { HID_USB_DEVICE(USB_VENDOR_ID_TENX, USB_DEVICE_ID_TENX_IBUDDY2) }, | ||
1523 | { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) }, | ||
1524 | { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) }, | ||
1525 | { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) }, | ||
1526 | { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) }, | ||
1527 | { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) }, | ||
1528 | { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) }, | ||
1529 | { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) }, | ||
1530 | { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) }, | ||
1531 | { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LCSPEC) }, | ||
1532 | { HID_USB_DEVICE(USB_VENDOR_ID_WACOM, HID_ANY_ID) }, | ||
1533 | { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20) }, | ||
1534 | { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20) }, | ||
1535 | { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT) }, | ||
1536 | { HID_USB_DEVICE(USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K) }, | ||
1537 | { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) }, | ||
1538 | { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) }, | ||
1539 | { } | ||
1540 | }; | ||
1541 | |||
1542 | static bool hid_ignore(struct hid_device *hdev) | ||
1543 | { | ||
1544 | switch (hdev->vendor) { | ||
1545 | case USB_VENDOR_ID_CODEMERCS: | ||
1546 | /* ignore all Code Mercenaries IOWarrior devices */ | ||
1547 | if (hdev->product >= USB_DEVICE_ID_CODEMERCS_IOW_FIRST && | ||
1548 | hdev->product <= USB_DEVICE_ID_CODEMERCS_IOW_LAST) | ||
1549 | return true; | ||
1550 | break; | ||
1551 | case USB_VENDOR_ID_LOGITECH: | ||
1552 | if (hdev->product >= USB_DEVICE_ID_LOGITECH_HARMONY_FIRST && | ||
1553 | hdev->product <= USB_DEVICE_ID_LOGITECH_HARMONY_LAST) | ||
1554 | return true; | ||
1555 | break; | ||
1556 | } | ||
1557 | |||
1558 | return !!hid_match_id(hdev, hid_ignore_list); | ||
1559 | } | ||
1560 | |||
1561 | int hid_add_device(struct hid_device *hdev) | ||
1562 | { | ||
1563 | static atomic_t id = ATOMIC_INIT(0); | ||
1564 | int ret; | ||
1565 | |||
1566 | if (WARN_ON(hdev->status & HID_STAT_ADDED)) | ||
1567 | return -EBUSY; | ||
1568 | |||
1569 | /* we need to kill them here, otherwise they will stay allocated to | ||
1570 | * wait for coming driver */ | ||
1571 | if (hid_ignore(hdev)) | ||
1572 | return -ENODEV; | ||
1573 | |||
1574 | /* XXX hack, any other cleaner solution < 20 bus_id bytes? */ | ||
1575 | sprintf(hdev->dev.bus_id, "%04X:%04X:%04X.%04X", hdev->bus, | ||
1576 | hdev->vendor, hdev->product, atomic_inc_return(&id)); | ||
1577 | |||
1578 | ret = device_add(&hdev->dev); | ||
1579 | if (!ret) | ||
1580 | hdev->status |= HID_STAT_ADDED; | ||
1581 | |||
1582 | return ret; | ||
1583 | } | ||
1584 | EXPORT_SYMBOL_GPL(hid_add_device); | ||
1585 | |||
1586 | /** | ||
1587 | * hid_allocate_device - allocate new hid device descriptor | ||
1588 | * | ||
1589 | * Allocate and initialize hid device, so that hid_destroy_device might be | ||
1590 | * used to free it. | ||
1591 | * | ||
1592 | * New hid_device pointer is returned on success, otherwise ERR_PTR encoded | ||
1593 | * error value. | ||
1594 | */ | ||
1595 | struct hid_device *hid_allocate_device(void) | ||
1596 | { | ||
1597 | struct hid_device *hdev; | ||
1598 | unsigned int i; | ||
1599 | int ret = -ENOMEM; | ||
1600 | |||
1601 | hdev = kzalloc(sizeof(*hdev), GFP_KERNEL); | ||
1602 | if (hdev == NULL) | ||
1603 | return ERR_PTR(ret); | ||
1604 | |||
1605 | device_initialize(&hdev->dev); | ||
1606 | hdev->dev.release = hid_device_release; | ||
1607 | hdev->dev.bus = &hid_bus_type; | ||
1608 | |||
1609 | hdev->collection = kcalloc(HID_DEFAULT_NUM_COLLECTIONS, | ||
1610 | sizeof(struct hid_collection), GFP_KERNEL); | ||
1611 | if (hdev->collection == NULL) | ||
1612 | goto err; | ||
1613 | hdev->collection_size = HID_DEFAULT_NUM_COLLECTIONS; | ||
1614 | |||
1615 | for (i = 0; i < HID_REPORT_TYPES; i++) | ||
1616 | INIT_LIST_HEAD(&hdev->report_enum[i].report_list); | ||
1617 | |||
1618 | return hdev; | ||
1619 | err: | ||
1620 | put_device(&hdev->dev); | ||
1621 | return ERR_PTR(ret); | ||
1622 | } | ||
1623 | EXPORT_SYMBOL_GPL(hid_allocate_device); | ||
1624 | |||
1625 | static void hid_remove_device(struct hid_device *hdev) | ||
1626 | { | ||
1627 | if (hdev->status & HID_STAT_ADDED) { | ||
1628 | device_del(&hdev->dev); | ||
1629 | hdev->status &= ~HID_STAT_ADDED; | ||
1630 | } | ||
1631 | } | ||
1632 | |||
1633 | /** | ||
1634 | * hid_destroy_device - free previously allocated device | ||
1635 | * | ||
1636 | * @hdev: hid device | ||
1637 | * | ||
1638 | * If you allocate hid_device through hid_allocate_device, you should ever | ||
1639 | * free by this function. | ||
1640 | */ | ||
1641 | void hid_destroy_device(struct hid_device *hdev) | ||
1642 | { | ||
1643 | hid_remove_device(hdev); | ||
1644 | put_device(&hdev->dev); | ||
1645 | } | ||
1646 | EXPORT_SYMBOL_GPL(hid_destroy_device); | ||
1647 | |||
1648 | int __hid_register_driver(struct hid_driver *hdrv, struct module *owner, | ||
1649 | const char *mod_name) | ||
1650 | { | ||
1651 | hdrv->driver.name = hdrv->name; | ||
1652 | hdrv->driver.bus = &hid_bus_type; | ||
1653 | hdrv->driver.owner = owner; | ||
1654 | hdrv->driver.mod_name = mod_name; | ||
1655 | |||
1656 | return driver_register(&hdrv->driver); | ||
1657 | } | ||
1658 | EXPORT_SYMBOL_GPL(__hid_register_driver); | ||
1659 | |||
1660 | void hid_unregister_driver(struct hid_driver *hdrv) | ||
1661 | { | ||
1662 | driver_unregister(&hdrv->driver); | ||
1663 | } | ||
1664 | EXPORT_SYMBOL_GPL(hid_unregister_driver); | ||
1665 | |||
1666 | #ifdef CONFIG_HID_COMPAT | ||
1667 | static void hid_compat_load(struct work_struct *ws) | ||
1668 | { | ||
1669 | request_module("hid-dummy"); | ||
1670 | } | ||
1671 | static DECLARE_WORK(hid_compat_work, hid_compat_load); | ||
1672 | static struct workqueue_struct *hid_compat_wq; | ||
1673 | #endif | ||
1674 | |||
1009 | static int __init hid_init(void) | 1675 | static int __init hid_init(void) |
1010 | { | 1676 | { |
1011 | return hidraw_init(); | 1677 | int ret; |
1678 | |||
1679 | ret = bus_register(&hid_bus_type); | ||
1680 | if (ret) { | ||
1681 | printk(KERN_ERR "HID: can't register hid bus\n"); | ||
1682 | goto err; | ||
1683 | } | ||
1684 | |||
1685 | ret = hidraw_init(); | ||
1686 | if (ret) | ||
1687 | goto err_bus; | ||
1688 | |||
1689 | #ifdef CONFIG_HID_COMPAT | ||
1690 | hid_compat_wq = create_workqueue("hid_compat"); | ||
1691 | if (!hid_compat_wq) { | ||
1692 | hidraw_exit(); | ||
1693 | goto err; | ||
1694 | } | ||
1695 | queue_work(hid_compat_wq, &hid_compat_work); | ||
1696 | #endif | ||
1697 | |||
1698 | return 0; | ||
1699 | err_bus: | ||
1700 | bus_unregister(&hid_bus_type); | ||
1701 | err: | ||
1702 | return ret; | ||
1012 | } | 1703 | } |
1013 | 1704 | ||
1014 | static void __exit hid_exit(void) | 1705 | static void __exit hid_exit(void) |
1015 | { | 1706 | { |
1707 | #ifdef CONFIG_HID_COMPAT | ||
1708 | destroy_workqueue(hid_compat_wq); | ||
1709 | #endif | ||
1016 | hidraw_exit(); | 1710 | hidraw_exit(); |
1711 | bus_unregister(&hid_bus_type); | ||
1017 | } | 1712 | } |
1018 | 1713 | ||
1019 | module_init(hid_init); | 1714 | module_init(hid_init); |
diff --git a/drivers/hid/hid-cypress.c b/drivers/hid/hid-cypress.c new file mode 100644 index 000000000000..5d69d27b935d --- /dev/null +++ b/drivers/hid/hid-cypress.c | |||
@@ -0,0 +1,158 @@ | |||
1 | /* | ||
2 | * HID driver for some cypress "special" devices | ||
3 | * | ||
4 | * Copyright (c) 1999 Andreas Gal | ||
5 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> | ||
6 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc | ||
7 | * Copyright (c) 2006-2007 Jiri Kosina | ||
8 | * Copyright (c) 2007 Paul Walmsley | ||
9 | * Copyright (c) 2008 Jiri Slaby | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * This program is free software; you can redistribute it and/or modify it | ||
14 | * under the terms of the GNU General Public License as published by the Free | ||
15 | * Software Foundation; either version 2 of the License, or (at your option) | ||
16 | * any later version. | ||
17 | */ | ||
18 | |||
19 | #include <linux/device.h> | ||
20 | #include <linux/hid.h> | ||
21 | #include <linux/input.h> | ||
22 | #include <linux/module.h> | ||
23 | |||
24 | #include "hid-ids.h" | ||
25 | |||
26 | #define CP_RDESC_SWAPPED_MIN_MAX 0x01 | ||
27 | #define CP_2WHEEL_MOUSE_HACK 0x02 | ||
28 | #define CP_2WHEEL_MOUSE_HACK_ON 0x04 | ||
29 | |||
30 | /* | ||
31 | * Some USB barcode readers from cypress have usage min and usage max in | ||
32 | * the wrong order | ||
33 | */ | ||
34 | static void cp_report_fixup(struct hid_device *hdev, __u8 *rdesc, | ||
35 | unsigned int rsize) | ||
36 | { | ||
37 | unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); | ||
38 | unsigned int i; | ||
39 | |||
40 | if (!(quirks & CP_RDESC_SWAPPED_MIN_MAX)) | ||
41 | return; | ||
42 | |||
43 | for (i = 0; i < rsize - 4; i++) | ||
44 | if (rdesc[i] == 0x29 && rdesc[i + 2] == 0x19) { | ||
45 | __u8 tmp; | ||
46 | |||
47 | rdesc[i] = 0x19; | ||
48 | rdesc[i + 2] = 0x29; | ||
49 | tmp = rdesc[i + 3]; | ||
50 | rdesc[i + 3] = rdesc[i + 1]; | ||
51 | rdesc[i + 1] = tmp; | ||
52 | } | ||
53 | } | ||
54 | |||
55 | static int cp_input_mapped(struct hid_device *hdev, struct hid_input *hi, | ||
56 | struct hid_field *field, struct hid_usage *usage, | ||
57 | unsigned long **bit, int *max) | ||
58 | { | ||
59 | unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); | ||
60 | |||
61 | if (!(quirks & CP_2WHEEL_MOUSE_HACK)) | ||
62 | return 0; | ||
63 | |||
64 | if (usage->type == EV_REL && usage->code == REL_WHEEL) | ||
65 | set_bit(REL_HWHEEL, *bit); | ||
66 | if (usage->hid == 0x00090005) | ||
67 | return -1; | ||
68 | |||
69 | return 0; | ||
70 | } | ||
71 | |||
72 | static int cp_event(struct hid_device *hdev, struct hid_field *field, | ||
73 | struct hid_usage *usage, __s32 value) | ||
74 | { | ||
75 | unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); | ||
76 | |||
77 | if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput || | ||
78 | !usage->type || !(quirks & CP_2WHEEL_MOUSE_HACK)) | ||
79 | return 0; | ||
80 | |||
81 | if (usage->hid == 0x00090005) { | ||
82 | if (value) | ||
83 | quirks |= CP_2WHEEL_MOUSE_HACK_ON; | ||
84 | else | ||
85 | quirks &= ~CP_2WHEEL_MOUSE_HACK_ON; | ||
86 | hid_set_drvdata(hdev, (void *)quirks); | ||
87 | return 1; | ||
88 | } | ||
89 | |||
90 | if (usage->code == REL_WHEEL && (quirks & CP_2WHEEL_MOUSE_HACK_ON)) { | ||
91 | struct input_dev *input = field->hidinput->input; | ||
92 | |||
93 | input_event(input, usage->type, REL_HWHEEL, value); | ||
94 | return 1; | ||
95 | } | ||
96 | |||
97 | return 0; | ||
98 | } | ||
99 | |||
100 | static int cp_probe(struct hid_device *hdev, const struct hid_device_id *id) | ||
101 | { | ||
102 | unsigned long quirks = id->driver_data; | ||
103 | int ret; | ||
104 | |||
105 | hid_set_drvdata(hdev, (void *)quirks); | ||
106 | |||
107 | ret = hid_parse(hdev); | ||
108 | if (ret) { | ||
109 | dev_err(&hdev->dev, "parse failed\n"); | ||
110 | goto err_free; | ||
111 | } | ||
112 | |||
113 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); | ||
114 | if (ret) { | ||
115 | dev_err(&hdev->dev, "hw start failed\n"); | ||
116 | goto err_free; | ||
117 | } | ||
118 | |||
119 | return 0; | ||
120 | err_free: | ||
121 | return ret; | ||
122 | } | ||
123 | |||
124 | static const struct hid_device_id cp_devices[] = { | ||
125 | { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1), | ||
126 | .driver_data = CP_RDESC_SWAPPED_MIN_MAX }, | ||
127 | { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2), | ||
128 | .driver_data = CP_RDESC_SWAPPED_MIN_MAX }, | ||
129 | { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE), | ||
130 | .driver_data = CP_2WHEEL_MOUSE_HACK }, | ||
131 | { } | ||
132 | }; | ||
133 | MODULE_DEVICE_TABLE(hid, cp_devices); | ||
134 | |||
135 | static struct hid_driver cp_driver = { | ||
136 | .name = "cypress", | ||
137 | .id_table = cp_devices, | ||
138 | .report_fixup = cp_report_fixup, | ||
139 | .input_mapped = cp_input_mapped, | ||
140 | .event = cp_event, | ||
141 | .probe = cp_probe, | ||
142 | }; | ||
143 | |||
144 | static int cp_init(void) | ||
145 | { | ||
146 | return hid_register_driver(&cp_driver); | ||
147 | } | ||
148 | |||
149 | static void cp_exit(void) | ||
150 | { | ||
151 | hid_unregister_driver(&cp_driver); | ||
152 | } | ||
153 | |||
154 | module_init(cp_init); | ||
155 | module_exit(cp_exit); | ||
156 | MODULE_LICENSE("GPL"); | ||
157 | |||
158 | HID_COMPAT_LOAD_DRIVER(cypress); | ||
diff --git a/drivers/hid/hid-dell.c b/drivers/hid/hid-dell.c new file mode 100644 index 000000000000..1a0d0dfc62fc --- /dev/null +++ b/drivers/hid/hid-dell.c | |||
@@ -0,0 +1,75 @@ | |||
1 | /* | ||
2 | * HID driver for some dell "special" devices | ||
3 | * | ||
4 | * Copyright (c) 1999 Andreas Gal | ||
5 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> | ||
6 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc | ||
7 | * Copyright (c) 2006-2007 Jiri Kosina | ||
8 | * Copyright (c) 2007 Paul Walmsley | ||
9 | * Copyright (c) 2008 Jiri Slaby | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * This program is free software; you can redistribute it and/or modify it | ||
14 | * under the terms of the GNU General Public License as published by the Free | ||
15 | * Software Foundation; either version 2 of the License, or (at your option) | ||
16 | * any later version. | ||
17 | */ | ||
18 | |||
19 | #include <linux/device.h> | ||
20 | #include <linux/hid.h> | ||
21 | #include <linux/module.h> | ||
22 | |||
23 | #include "hid-ids.h" | ||
24 | |||
25 | static int dell_probe(struct hid_device *hdev, const struct hid_device_id *id) | ||
26 | { | ||
27 | int ret; | ||
28 | |||
29 | ret = hid_parse(hdev); | ||
30 | if (ret) { | ||
31 | dev_err(&hdev->dev, "parse failed\n"); | ||
32 | goto err_free; | ||
33 | } | ||
34 | |||
35 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); | ||
36 | if (ret) { | ||
37 | dev_err(&hdev->dev, "hw start failed\n"); | ||
38 | goto err_free; | ||
39 | } | ||
40 | |||
41 | usbhid_set_leds(hdev); | ||
42 | |||
43 | return 0; | ||
44 | err_free: | ||
45 | return ret; | ||
46 | } | ||
47 | |||
48 | static const struct hid_device_id dell_devices[] = { | ||
49 | { HID_USB_DEVICE(USB_VENDOR_ID_DELL, USB_DEVICE_ID_DELL_W7658) }, | ||
50 | { HID_USB_DEVICE(USB_VENDOR_ID_DELL, USB_DEVICE_ID_DELL_SK8115) }, | ||
51 | { } | ||
52 | }; | ||
53 | MODULE_DEVICE_TABLE(hid, dell_devices); | ||
54 | |||
55 | static struct hid_driver dell_driver = { | ||
56 | .name = "dell", | ||
57 | .id_table = dell_devices, | ||
58 | .probe = dell_probe, | ||
59 | }; | ||
60 | |||
61 | static int dell_init(void) | ||
62 | { | ||
63 | return hid_register_driver(&dell_driver); | ||
64 | } | ||
65 | |||
66 | static void dell_exit(void) | ||
67 | { | ||
68 | hid_unregister_driver(&dell_driver); | ||
69 | } | ||
70 | |||
71 | module_init(dell_init); | ||
72 | module_exit(dell_exit); | ||
73 | MODULE_LICENSE("GPL"); | ||
74 | |||
75 | HID_COMPAT_LOAD_DRIVER(dell); | ||
diff --git a/drivers/hid/hid-dummy.c b/drivers/hid/hid-dummy.c new file mode 100644 index 000000000000..e148f86fb58e --- /dev/null +++ b/drivers/hid/hid-dummy.c | |||
@@ -0,0 +1,72 @@ | |||
1 | #include <linux/autoconf.h> | ||
2 | #include <linux/module.h> | ||
3 | #include <linux/hid.h> | ||
4 | |||
5 | static int __init hid_dummy_init(void) | ||
6 | { | ||
7 | #ifdef CONFIG_HID_A4TECH_MODULE | ||
8 | HID_COMPAT_CALL_DRIVER(a4tech); | ||
9 | #endif | ||
10 | #ifdef CONFIG_HID_APPLE_MODULE | ||
11 | HID_COMPAT_CALL_DRIVER(apple); | ||
12 | #endif | ||
13 | #ifdef CONFIG_HID_BELKIN_MODULE | ||
14 | HID_COMPAT_CALL_DRIVER(belkin); | ||
15 | #endif | ||
16 | #ifdef CONFIG_HID_BRIGHT_MODULE | ||
17 | HID_COMPAT_CALL_DRIVER(bright); | ||
18 | #endif | ||
19 | #ifdef CONFIG_HID_CHERRY_MODULE | ||
20 | HID_COMPAT_CALL_DRIVER(cherry); | ||
21 | #endif | ||
22 | #ifdef CONFIG_HID_CHICONY_MODULE | ||
23 | HID_COMPAT_CALL_DRIVER(chicony); | ||
24 | #endif | ||
25 | #ifdef CONFIG_HID_CYPRESS_MODULE | ||
26 | HID_COMPAT_CALL_DRIVER(cypress); | ||
27 | #endif | ||
28 | #ifdef CONFIG_HID_DELL_MODULE | ||
29 | HID_COMPAT_CALL_DRIVER(dell); | ||
30 | #endif | ||
31 | #ifdef CONFIG_HID_EZKEY_MODULE | ||
32 | HID_COMPAT_CALL_DRIVER(ezkey); | ||
33 | #endif | ||
34 | #ifdef CONFIG_HID_GYRATION_MODULE | ||
35 | HID_COMPAT_CALL_DRIVER(gyration); | ||
36 | #endif | ||
37 | #ifdef CONFIG_HID_LOGITECH_MODULE | ||
38 | HID_COMPAT_CALL_DRIVER(logitech); | ||
39 | #endif | ||
40 | #ifdef CONFIG_HID_MICROSOFT_MODULE | ||
41 | HID_COMPAT_CALL_DRIVER(microsoft); | ||
42 | #endif | ||
43 | #ifdef CONFIG_HID_MONTEREY_MODULE | ||
44 | HID_COMPAT_CALL_DRIVER(monterey); | ||
45 | #endif | ||
46 | #ifdef CONFIG_HID_PANTHERLORD_MODULE | ||
47 | HID_COMPAT_CALL_DRIVER(pantherlord); | ||
48 | #endif | ||
49 | #ifdef CONFIG_HID_PETALYNX_MODULE | ||
50 | HID_COMPAT_CALL_DRIVER(petalynx); | ||
51 | #endif | ||
52 | #ifdef CONFIG_HID_SAMSUNG_MODULE | ||
53 | HID_COMPAT_CALL_DRIVER(samsung); | ||
54 | #endif | ||
55 | #ifdef CONFIG_HID_SONY_MODULE | ||
56 | HID_COMPAT_CALL_DRIVER(sony); | ||
57 | #endif | ||
58 | #ifdef CONFIG_HID_SUNPLUS_MODULE | ||
59 | HID_COMPAT_CALL_DRIVER(sunplus); | ||
60 | #endif | ||
61 | #ifdef CONFIG_THRUSTMASTER_FF_MODULE | ||
62 | HID_COMPAT_CALL_DRIVER(thrustmaster); | ||
63 | #endif | ||
64 | #ifdef CONFIG_ZEROPLUS_FF_MODULE | ||
65 | HID_COMPAT_CALL_DRIVER(zeroplus); | ||
66 | #endif | ||
67 | |||
68 | return -EIO; | ||
69 | } | ||
70 | module_init(hid_dummy_init); | ||
71 | |||
72 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/hid/hid-ezkey.c b/drivers/hid/hid-ezkey.c new file mode 100644 index 000000000000..deb42f931b7e --- /dev/null +++ b/drivers/hid/hid-ezkey.c | |||
@@ -0,0 +1,95 @@ | |||
1 | /* | ||
2 | * HID driver for some ezkey "special" devices | ||
3 | * | ||
4 | * Copyright (c) 1999 Andreas Gal | ||
5 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> | ||
6 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc | ||
7 | * Copyright (c) 2006-2007 Jiri Kosina | ||
8 | * Copyright (c) 2007 Paul Walmsley | ||
9 | * Copyright (c) 2008 Jiri Slaby | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * This program is free software; you can redistribute it and/or modify it | ||
14 | * under the terms of the GNU General Public License as published by the Free | ||
15 | * Software Foundation; either version 2 of the License, or (at your option) | ||
16 | * any later version. | ||
17 | */ | ||
18 | |||
19 | #include <linux/device.h> | ||
20 | #include <linux/input.h> | ||
21 | #include <linux/hid.h> | ||
22 | #include <linux/module.h> | ||
23 | |||
24 | #include "hid-ids.h" | ||
25 | |||
26 | #define ez_map_rel(c) hid_map_usage(hi, usage, bit, max, EV_REL, (c)) | ||
27 | #define ez_map_key(c) hid_map_usage(hi, usage, bit, max, EV_KEY, (c)) | ||
28 | |||
29 | static int ez_input_mapping(struct hid_device *hdev, struct hid_input *hi, | ||
30 | struct hid_field *field, struct hid_usage *usage, | ||
31 | unsigned long **bit, int *max) | ||
32 | { | ||
33 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER) | ||
34 | return 0; | ||
35 | |||
36 | switch (usage->hid & HID_USAGE) { | ||
37 | case 0x230: ez_map_key(BTN_MOUSE); break; | ||
38 | case 0x231: ez_map_rel(REL_WHEEL); break; | ||
39 | /* | ||
40 | * this keyboard has a scrollwheel implemented in | ||
41 | * totally broken way. We map this usage temporarily | ||
42 | * to HWHEEL and handle it in the event quirk handler | ||
43 | */ | ||
44 | case 0x232: ez_map_rel(REL_HWHEEL); break; | ||
45 | default: | ||
46 | return 0; | ||
47 | } | ||
48 | return 1; | ||
49 | } | ||
50 | |||
51 | static int ez_event(struct hid_device *hdev, struct hid_field *field, | ||
52 | struct hid_usage *usage, __s32 value) | ||
53 | { | ||
54 | if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput || | ||
55 | !usage->type) | ||
56 | return 0; | ||
57 | |||
58 | /* handle the temporary quirky mapping to HWHEEL */ | ||
59 | if (usage->type == EV_REL && usage->code == REL_HWHEEL) { | ||
60 | struct input_dev *input = field->hidinput->input; | ||
61 | input_event(input, usage->type, REL_WHEEL, -value); | ||
62 | return 1; | ||
63 | } | ||
64 | |||
65 | return 0; | ||
66 | } | ||
67 | |||
68 | static const struct hid_device_id ez_devices[] = { | ||
69 | { HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) }, | ||
70 | { } | ||
71 | }; | ||
72 | MODULE_DEVICE_TABLE(hid, ez_devices); | ||
73 | |||
74 | static struct hid_driver ez_driver = { | ||
75 | .name = "ezkey", | ||
76 | .id_table = ez_devices, | ||
77 | .input_mapping = ez_input_mapping, | ||
78 | .event = ez_event, | ||
79 | }; | ||
80 | |||
81 | static int ez_init(void) | ||
82 | { | ||
83 | return hid_register_driver(&ez_driver); | ||
84 | } | ||
85 | |||
86 | static void ez_exit(void) | ||
87 | { | ||
88 | hid_unregister_driver(&ez_driver); | ||
89 | } | ||
90 | |||
91 | module_init(ez_init); | ||
92 | module_exit(ez_exit); | ||
93 | MODULE_LICENSE("GPL"); | ||
94 | |||
95 | HID_COMPAT_LOAD_DRIVER(ezkey); | ||
diff --git a/drivers/hid/hid-gyration.c b/drivers/hid/hid-gyration.c new file mode 100644 index 000000000000..ac5120f542cc --- /dev/null +++ b/drivers/hid/hid-gyration.c | |||
@@ -0,0 +1,96 @@ | |||
1 | /* | ||
2 | * HID driver for some gyration "special" devices | ||
3 | * | ||
4 | * Copyright (c) 1999 Andreas Gal | ||
5 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> | ||
6 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc | ||
7 | * Copyright (c) 2006-2007 Jiri Kosina | ||
8 | * Copyright (c) 2007 Paul Walmsley | ||
9 | * Copyright (c) 2008 Jiri Slaby | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * This program is free software; you can redistribute it and/or modify it | ||
14 | * under the terms of the GNU General Public License as published by the Free | ||
15 | * Software Foundation; either version 2 of the License, or (at your option) | ||
16 | * any later version. | ||
17 | */ | ||
18 | |||
19 | #include <linux/device.h> | ||
20 | #include <linux/input.h> | ||
21 | #include <linux/hid.h> | ||
22 | #include <linux/module.h> | ||
23 | |||
24 | #include "hid-ids.h" | ||
25 | |||
26 | #define gy_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \ | ||
27 | EV_KEY, (c)) | ||
28 | static int gyration_input_mapping(struct hid_device *hdev, struct hid_input *hi, | ||
29 | struct hid_field *field, struct hid_usage *usage, | ||
30 | unsigned long **bit, int *max) | ||
31 | { | ||
32 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR) | ||
33 | return 0; | ||
34 | |||
35 | set_bit(EV_REP, hi->input->evbit); | ||
36 | switch (usage->hid & HID_USAGE) { | ||
37 | /* Reported on Gyration MCE Remote */ | ||
38 | case 0x00d: gy_map_key_clear(KEY_HOME); break; | ||
39 | case 0x024: gy_map_key_clear(KEY_DVD); break; | ||
40 | case 0x025: gy_map_key_clear(KEY_PVR); break; | ||
41 | case 0x046: gy_map_key_clear(KEY_MEDIA); break; | ||
42 | case 0x047: gy_map_key_clear(KEY_MP3); break; | ||
43 | case 0x049: gy_map_key_clear(KEY_CAMERA); break; | ||
44 | case 0x04a: gy_map_key_clear(KEY_VIDEO); break; | ||
45 | |||
46 | default: | ||
47 | return 0; | ||
48 | } | ||
49 | return 1; | ||
50 | } | ||
51 | |||
52 | static int gyration_event(struct hid_device *hdev, struct hid_field *field, | ||
53 | struct hid_usage *usage, __s32 value) | ||
54 | { | ||
55 | struct input_dev *input = field->hidinput->input; | ||
56 | |||
57 | if ((usage->hid & HID_USAGE_PAGE) == HID_UP_GENDESK && | ||
58 | (usage->hid & 0xff) == 0x82) { | ||
59 | input_event(input, usage->type, usage->code, 1); | ||
60 | input_sync(input); | ||
61 | input_event(input, usage->type, usage->code, 0); | ||
62 | input_sync(input); | ||
63 | return 1; | ||
64 | } | ||
65 | |||
66 | return 0; | ||
67 | } | ||
68 | |||
69 | static const struct hid_device_id gyration_devices[] = { | ||
70 | { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) }, | ||
71 | { } | ||
72 | }; | ||
73 | MODULE_DEVICE_TABLE(hid, gyration_devices); | ||
74 | |||
75 | static struct hid_driver gyration_driver = { | ||
76 | .name = "gyration", | ||
77 | .id_table = gyration_devices, | ||
78 | .input_mapping = gyration_input_mapping, | ||
79 | .event = gyration_event, | ||
80 | }; | ||
81 | |||
82 | static int gyration_init(void) | ||
83 | { | ||
84 | return hid_register_driver(&gyration_driver); | ||
85 | } | ||
86 | |||
87 | static void gyration_exit(void) | ||
88 | { | ||
89 | hid_unregister_driver(&gyration_driver); | ||
90 | } | ||
91 | |||
92 | module_init(gyration_init); | ||
93 | module_exit(gyration_exit); | ||
94 | MODULE_LICENSE("GPL"); | ||
95 | |||
96 | HID_COMPAT_LOAD_DRIVER(gyration); | ||
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h new file mode 100644 index 000000000000..aad9ed1b406e --- /dev/null +++ b/drivers/hid/hid-ids.h | |||
@@ -0,0 +1,404 @@ | |||
1 | /* | ||
2 | * USB HID quirks support for Linux | ||
3 | * | ||
4 | * Copyright (c) 1999 Andreas Gal | ||
5 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> | ||
6 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc | ||
7 | * Copyright (c) 2006-2007 Jiri Kosina | ||
8 | * Copyright (c) 2007 Paul Walmsley | ||
9 | */ | ||
10 | |||
11 | /* | ||
12 | * This program is free software; you can redistribute it and/or modify it | ||
13 | * under the terms of the GNU General Public License as published by the Free | ||
14 | * Software Foundation; either version 2 of the License, or (at your option) | ||
15 | * any later version. | ||
16 | */ | ||
17 | |||
18 | #ifndef HID_IDS_H_FILE | ||
19 | #define HID_IDS_H_FILE | ||
20 | |||
21 | #define USB_VENDOR_ID_A4TECH 0x09da | ||
22 | #define USB_DEVICE_ID_A4TECH_WCP32PU 0x0006 | ||
23 | #define USB_DEVICE_ID_A4TECH_X5_005D 0x000a | ||
24 | |||
25 | #define USB_VENDOR_ID_AASHIMA 0x06d6 | ||
26 | #define USB_DEVICE_ID_AASHIMA_GAMEPAD 0x0025 | ||
27 | #define USB_DEVICE_ID_AASHIMA_PREDATOR 0x0026 | ||
28 | |||
29 | #define USB_VENDOR_ID_ACECAD 0x0460 | ||
30 | #define USB_DEVICE_ID_ACECAD_FLAIR 0x0004 | ||
31 | #define USB_DEVICE_ID_ACECAD_302 0x0008 | ||
32 | |||
33 | #define USB_VENDOR_ID_ADS_TECH 0x06e1 | ||
34 | #define USB_DEVICE_ID_ADS_TECH_RADIO_SI470X 0xa155 | ||
35 | |||
36 | #define USB_VENDOR_ID_AFATECH 0x15a4 | ||
37 | #define USB_DEVICE_ID_AFATECH_AF9016 0x9016 | ||
38 | |||
39 | #define USB_VENDOR_ID_AIPTEK 0x08ca | ||
40 | #define USB_DEVICE_ID_AIPTEK_01 0x0001 | ||
41 | #define USB_DEVICE_ID_AIPTEK_10 0x0010 | ||
42 | #define USB_DEVICE_ID_AIPTEK_20 0x0020 | ||
43 | #define USB_DEVICE_ID_AIPTEK_21 0x0021 | ||
44 | #define USB_DEVICE_ID_AIPTEK_22 0x0022 | ||
45 | #define USB_DEVICE_ID_AIPTEK_23 0x0023 | ||
46 | #define USB_DEVICE_ID_AIPTEK_24 0x0024 | ||
47 | |||
48 | #define USB_VENDOR_ID_AIRCABLE 0x16CA | ||
49 | #define USB_DEVICE_ID_AIRCABLE1 0x1502 | ||
50 | |||
51 | #define USB_VENDOR_ID_ALCOR 0x058f | ||
52 | #define USB_DEVICE_ID_ALCOR_USBRS232 0x9720 | ||
53 | |||
54 | #define USB_VENDOR_ID_ALPS 0x0433 | ||
55 | #define USB_DEVICE_ID_IBM_GAMEPAD 0x1101 | ||
56 | |||
57 | #define USB_VENDOR_ID_APPLE 0x05ac | ||
58 | #define USB_DEVICE_ID_APPLE_MIGHTYMOUSE 0x0304 | ||
59 | #define USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI 0x020e | ||
60 | #define USB_DEVICE_ID_APPLE_FOUNTAIN_ISO 0x020f | ||
61 | #define USB_DEVICE_ID_APPLE_GEYSER_ANSI 0x0214 | ||
62 | #define USB_DEVICE_ID_APPLE_GEYSER_ISO 0x0215 | ||
63 | #define USB_DEVICE_ID_APPLE_GEYSER_JIS 0x0216 | ||
64 | #define USB_DEVICE_ID_APPLE_GEYSER3_ANSI 0x0217 | ||
65 | #define USB_DEVICE_ID_APPLE_GEYSER3_ISO 0x0218 | ||
66 | #define USB_DEVICE_ID_APPLE_GEYSER3_JIS 0x0219 | ||
67 | #define USB_DEVICE_ID_APPLE_GEYSER4_ANSI 0x021a | ||
68 | #define USB_DEVICE_ID_APPLE_GEYSER4_ISO 0x021b | ||
69 | #define USB_DEVICE_ID_APPLE_GEYSER4_JIS 0x021c | ||
70 | #define USB_DEVICE_ID_APPLE_ALU_ANSI 0x0220 | ||
71 | #define USB_DEVICE_ID_APPLE_ALU_ISO 0x0221 | ||
72 | #define USB_DEVICE_ID_APPLE_ALU_JIS 0x0222 | ||
73 | #define USB_DEVICE_ID_APPLE_WELLSPRING_ANSI 0x0223 | ||
74 | #define USB_DEVICE_ID_APPLE_WELLSPRING_ISO 0x0224 | ||
75 | #define USB_DEVICE_ID_APPLE_WELLSPRING_JIS 0x0225 | ||
76 | #define USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI 0x0229 | ||
77 | #define USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO 0x022a | ||
78 | #define USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS 0x022b | ||
79 | #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI 0x022c | ||
80 | #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO 0x022d | ||
81 | #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS 0x022e | ||
82 | #define USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI 0x0230 | ||
83 | #define USB_DEVICE_ID_APPLE_WELLSPRING2_ISO 0x0231 | ||
84 | #define USB_DEVICE_ID_APPLE_WELLSPRING2_JIS 0x0232 | ||
85 | #define USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY 0x030a | ||
86 | #define USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY 0x030b | ||
87 | #define USB_DEVICE_ID_APPLE_ATV_IRCONTROL 0x8241 | ||
88 | #define USB_DEVICE_ID_APPLE_IRCONTROL4 0x8242 | ||
89 | |||
90 | #define USB_VENDOR_ID_ASUS 0x0b05 | ||
91 | #define USB_DEVICE_ID_ASUS_LCM 0x1726 | ||
92 | |||
93 | #define USB_VENDOR_ID_ATEN 0x0557 | ||
94 | #define USB_DEVICE_ID_ATEN_UC100KM 0x2004 | ||
95 | #define USB_DEVICE_ID_ATEN_CS124U 0x2202 | ||
96 | #define USB_DEVICE_ID_ATEN_2PORTKVM 0x2204 | ||
97 | #define USB_DEVICE_ID_ATEN_4PORTKVM 0x2205 | ||
98 | #define USB_DEVICE_ID_ATEN_4PORTKVMC 0x2208 | ||
99 | |||
100 | #define USB_VENDOR_ID_AVERMEDIA 0x07ca | ||
101 | #define USB_DEVICE_ID_AVER_FM_MR800 0xb800 | ||
102 | |||
103 | #define USB_VENDOR_ID_BELKIN 0x050d | ||
104 | #define USB_DEVICE_ID_FLIP_KVM 0x3201 | ||
105 | |||
106 | #define USB_VENDOR_ID_BRIGHT 0x1241 | ||
107 | #define USB_DEVICE_ID_BRIGHT_ABNT2 0x1503 | ||
108 | |||
109 | #define USB_VENDOR_ID_BERKSHIRE 0x0c98 | ||
110 | #define USB_DEVICE_ID_BERKSHIRE_PCWD 0x1140 | ||
111 | |||
112 | #define USB_VENDOR_ID_CHERRY 0x046a | ||
113 | #define USB_DEVICE_ID_CHERRY_CYMOTION 0x0023 | ||
114 | |||
115 | #define USB_VENDOR_ID_CHIC 0x05fe | ||
116 | #define USB_DEVICE_ID_CHIC_GAMEPAD 0x0014 | ||
117 | |||
118 | #define USB_VENDOR_ID_CHICONY 0x04f2 | ||
119 | #define USB_DEVICE_ID_CHICONY_TACTICAL_PAD 0x0418 | ||
120 | |||
121 | #define USB_VENDOR_ID_CIDC 0x1677 | ||
122 | |||
123 | #define USB_VENDOR_ID_CMEDIA 0x0d8c | ||
124 | #define USB_DEVICE_ID_CM109 0x000e | ||
125 | |||
126 | #define USB_VENDOR_ID_CODEMERCS 0x07c0 | ||
127 | #define USB_DEVICE_ID_CODEMERCS_IOW_FIRST 0x1500 | ||
128 | #define USB_DEVICE_ID_CODEMERCS_IOW_LAST 0x15ff | ||
129 | |||
130 | #define USB_VENDOR_ID_CYGNAL 0x10c4 | ||
131 | #define USB_DEVICE_ID_CYGNAL_RADIO_SI470X 0x818a | ||
132 | |||
133 | #define USB_VENDOR_ID_CYPRESS 0x04b4 | ||
134 | #define USB_DEVICE_ID_CYPRESS_MOUSE 0x0001 | ||
135 | #define USB_DEVICE_ID_CYPRESS_HIDCOM 0x5500 | ||
136 | #define USB_DEVICE_ID_CYPRESS_ULTRAMOUSE 0x7417 | ||
137 | #define USB_DEVICE_ID_CYPRESS_BARCODE_1 0xde61 | ||
138 | #define USB_DEVICE_ID_CYPRESS_BARCODE_2 0xde64 | ||
139 | |||
140 | #define USB_VENDOR_ID_DELL 0x413c | ||
141 | #define USB_DEVICE_ID_DELL_W7658 0x2005 | ||
142 | #define USB_DEVICE_ID_DELL_SK8115 0x2105 | ||
143 | |||
144 | #define USB_VENDOR_ID_DELORME 0x1163 | ||
145 | #define USB_DEVICE_ID_DELORME_EARTHMATE 0x0100 | ||
146 | #define USB_DEVICE_ID_DELORME_EM_LT20 0x0200 | ||
147 | |||
148 | #define USB_VENDOR_ID_DMI 0x0c0b | ||
149 | #define USB_DEVICE_ID_DMI_ENC 0x5fab | ||
150 | |||
151 | #define USB_VENDOR_ID_ELO 0x04E7 | ||
152 | #define USB_DEVICE_ID_ELO_TS2700 0x0020 | ||
153 | |||
154 | #define USB_VENDOR_ID_ESSENTIAL_REALITY 0x0d7f | ||
155 | #define USB_DEVICE_ID_ESSENTIAL_REALITY_P5 0x0100 | ||
156 | |||
157 | #define USB_VENDOR_ID_EZKEY 0x0518 | ||
158 | #define USB_DEVICE_ID_BTC_8193 0x0002 | ||
159 | |||
160 | #define USB_VENDOR_ID_GAMERON 0x0810 | ||
161 | #define USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR 0x0001 | ||
162 | |||
163 | #define USB_VENDOR_ID_GENERAL_TOUCH 0x0dfc | ||
164 | |||
165 | #define USB_VENDOR_ID_GLAB 0x06c2 | ||
166 | #define USB_DEVICE_ID_4_PHIDGETSERVO_30 0x0038 | ||
167 | #define USB_DEVICE_ID_1_PHIDGETSERVO_30 0x0039 | ||
168 | #define USB_DEVICE_ID_0_0_4_IF_KIT 0x0040 | ||
169 | #define USB_DEVICE_ID_0_16_16_IF_KIT 0x0044 | ||
170 | #define USB_DEVICE_ID_8_8_8_IF_KIT 0x0045 | ||
171 | #define USB_DEVICE_ID_0_8_7_IF_KIT 0x0051 | ||
172 | #define USB_DEVICE_ID_0_8_8_IF_KIT 0x0053 | ||
173 | #define USB_DEVICE_ID_PHIDGET_MOTORCONTROL 0x0058 | ||
174 | |||
175 | #define USB_VENDOR_ID_GOTOP 0x08f2 | ||
176 | #define USB_DEVICE_ID_SUPER_Q2 0x007f | ||
177 | #define USB_DEVICE_ID_GOGOPEN 0x00ce | ||
178 | #define USB_DEVICE_ID_PENPOWER 0x00f4 | ||
179 | |||
180 | #define USB_VENDOR_ID_GREENASIA 0x0e8f | ||
181 | |||
182 | #define USB_VENDOR_ID_GRETAGMACBETH 0x0971 | ||
183 | #define USB_DEVICE_ID_GRETAGMACBETH_HUEY 0x2005 | ||
184 | |||
185 | #define USB_VENDOR_ID_GRIFFIN 0x077d | ||
186 | #define USB_DEVICE_ID_POWERMATE 0x0410 | ||
187 | #define USB_DEVICE_ID_SOUNDKNOB 0x04AA | ||
188 | |||
189 | #define USB_VENDOR_ID_GTCO 0x078c | ||
190 | #define USB_DEVICE_ID_GTCO_90 0x0090 | ||
191 | #define USB_DEVICE_ID_GTCO_100 0x0100 | ||
192 | #define USB_DEVICE_ID_GTCO_101 0x0101 | ||
193 | #define USB_DEVICE_ID_GTCO_103 0x0103 | ||
194 | #define USB_DEVICE_ID_GTCO_104 0x0104 | ||
195 | #define USB_DEVICE_ID_GTCO_105 0x0105 | ||
196 | #define USB_DEVICE_ID_GTCO_106 0x0106 | ||
197 | #define USB_DEVICE_ID_GTCO_107 0x0107 | ||
198 | #define USB_DEVICE_ID_GTCO_108 0x0108 | ||
199 | #define USB_DEVICE_ID_GTCO_200 0x0200 | ||
200 | #define USB_DEVICE_ID_GTCO_201 0x0201 | ||
201 | #define USB_DEVICE_ID_GTCO_202 0x0202 | ||
202 | #define USB_DEVICE_ID_GTCO_203 0x0203 | ||
203 | #define USB_DEVICE_ID_GTCO_204 0x0204 | ||
204 | #define USB_DEVICE_ID_GTCO_205 0x0205 | ||
205 | #define USB_DEVICE_ID_GTCO_206 0x0206 | ||
206 | #define USB_DEVICE_ID_GTCO_207 0x0207 | ||
207 | #define USB_DEVICE_ID_GTCO_300 0x0300 | ||
208 | #define USB_DEVICE_ID_GTCO_301 0x0301 | ||
209 | #define USB_DEVICE_ID_GTCO_302 0x0302 | ||
210 | #define USB_DEVICE_ID_GTCO_303 0x0303 | ||
211 | #define USB_DEVICE_ID_GTCO_304 0x0304 | ||
212 | #define USB_DEVICE_ID_GTCO_305 0x0305 | ||
213 | #define USB_DEVICE_ID_GTCO_306 0x0306 | ||
214 | #define USB_DEVICE_ID_GTCO_307 0x0307 | ||
215 | #define USB_DEVICE_ID_GTCO_308 0x0308 | ||
216 | #define USB_DEVICE_ID_GTCO_309 0x0309 | ||
217 | #define USB_DEVICE_ID_GTCO_400 0x0400 | ||
218 | #define USB_DEVICE_ID_GTCO_401 0x0401 | ||
219 | #define USB_DEVICE_ID_GTCO_402 0x0402 | ||
220 | #define USB_DEVICE_ID_GTCO_403 0x0403 | ||
221 | #define USB_DEVICE_ID_GTCO_404 0x0404 | ||
222 | #define USB_DEVICE_ID_GTCO_405 0x0405 | ||
223 | #define USB_DEVICE_ID_GTCO_500 0x0500 | ||
224 | #define USB_DEVICE_ID_GTCO_501 0x0501 | ||
225 | #define USB_DEVICE_ID_GTCO_502 0x0502 | ||
226 | #define USB_DEVICE_ID_GTCO_503 0x0503 | ||
227 | #define USB_DEVICE_ID_GTCO_504 0x0504 | ||
228 | #define USB_DEVICE_ID_GTCO_1000 0x1000 | ||
229 | #define USB_DEVICE_ID_GTCO_1001 0x1001 | ||
230 | #define USB_DEVICE_ID_GTCO_1002 0x1002 | ||
231 | #define USB_DEVICE_ID_GTCO_1003 0x1003 | ||
232 | #define USB_DEVICE_ID_GTCO_1004 0x1004 | ||
233 | #define USB_DEVICE_ID_GTCO_1005 0x1005 | ||
234 | #define USB_DEVICE_ID_GTCO_1006 0x1006 | ||
235 | #define USB_DEVICE_ID_GTCO_1007 0x1007 | ||
236 | |||
237 | #define USB_VENDOR_ID_GYRATION 0x0c16 | ||
238 | #define USB_DEVICE_ID_GYRATION_REMOTE 0x0002 | ||
239 | |||
240 | #define USB_VENDOR_ID_HAPP 0x078b | ||
241 | #define USB_DEVICE_ID_UGCI_DRIVING 0x0010 | ||
242 | #define USB_DEVICE_ID_UGCI_FLYING 0x0020 | ||
243 | #define USB_DEVICE_ID_UGCI_FIGHTING 0x0030 | ||
244 | |||
245 | #define USB_VENDOR_ID_IMATION 0x0718 | ||
246 | #define USB_DEVICE_ID_DISC_STAKKA 0xd000 | ||
247 | |||
248 | #define USB_VENDOR_ID_KBGEAR 0x084e | ||
249 | #define USB_DEVICE_ID_KBGEAR_JAMSTUDIO 0x1001 | ||
250 | |||
251 | #define USB_VENDOR_ID_LABTEC 0x1020 | ||
252 | #define USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD 0x0006 | ||
253 | |||
254 | #define USB_VENDOR_ID_LD 0x0f11 | ||
255 | #define USB_DEVICE_ID_LD_CASSY 0x1000 | ||
256 | #define USB_DEVICE_ID_LD_POCKETCASSY 0x1010 | ||
257 | #define USB_DEVICE_ID_LD_MOBILECASSY 0x1020 | ||
258 | #define USB_DEVICE_ID_LD_JWM 0x1080 | ||
259 | #define USB_DEVICE_ID_LD_DMMP 0x1081 | ||
260 | #define USB_DEVICE_ID_LD_UMIP 0x1090 | ||
261 | #define USB_DEVICE_ID_LD_XRAY1 0x1100 | ||
262 | #define USB_DEVICE_ID_LD_XRAY2 0x1101 | ||
263 | #define USB_DEVICE_ID_LD_VIDEOCOM 0x1200 | ||
264 | #define USB_DEVICE_ID_LD_COM3LAB 0x2000 | ||
265 | #define USB_DEVICE_ID_LD_TELEPORT 0x2010 | ||
266 | #define USB_DEVICE_ID_LD_NETWORKANALYSER 0x2020 | ||
267 | #define USB_DEVICE_ID_LD_POWERCONTROL 0x2030 | ||
268 | #define USB_DEVICE_ID_LD_MACHINETEST 0x2040 | ||
269 | |||
270 | #define USB_VENDOR_ID_LOGITECH 0x046d | ||
271 | #define USB_DEVICE_ID_LOGITECH_LX3 0xc044 | ||
272 | #define USB_DEVICE_ID_LOGITECH_V150 0xc047 | ||
273 | #define USB_DEVICE_ID_LOGITECH_RECEIVER 0xc101 | ||
274 | #define USB_DEVICE_ID_LOGITECH_HARMONY_FIRST 0xc110 | ||
275 | #define USB_DEVICE_ID_LOGITECH_HARMONY_LAST 0xc14f | ||
276 | #define USB_DEVICE_ID_LOGITECH_RUMBLEPAD 0xc211 | ||
277 | #define USB_DEVICE_ID_LOGITECH_EXTREME_3D 0xc215 | ||
278 | #define USB_DEVICE_ID_LOGITECH_RUMBLEPAD2 0xc218 | ||
279 | #define USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2 0xc219 | ||
280 | #define USB_DEVICE_ID_LOGITECH_WINGMAN_F3D 0xc283 | ||
281 | #define USB_DEVICE_ID_LOGITECH_FORCE3D_PRO 0xc286 | ||
282 | #define USB_DEVICE_ID_LOGITECH_WHEEL 0xc294 | ||
283 | #define USB_DEVICE_ID_LOGITECH_MOMO_WHEEL 0xc295 | ||
284 | #define USB_DEVICE_ID_LOGITECH_ELITE_KBD 0xc30a | ||
285 | #define USB_DEVICE_ID_LOGITECH_KBD 0xc311 | ||
286 | #define USB_DEVICE_ID_S510_RECEIVER 0xc50c | ||
287 | #define USB_DEVICE_ID_S510_RECEIVER_2 0xc517 | ||
288 | #define USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500 0xc512 | ||
289 | #define USB_DEVICE_ID_MX3000_RECEIVER 0xc513 | ||
290 | #define USB_DEVICE_ID_DINOVO_DESKTOP 0xc704 | ||
291 | #define USB_DEVICE_ID_DINOVO_EDGE 0xc714 | ||
292 | #define USB_DEVICE_ID_DINOVO_MINI 0xc71f | ||
293 | #define USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2 0xca03 | ||
294 | |||
295 | #define USB_VENDOR_ID_MCC 0x09db | ||
296 | #define USB_DEVICE_ID_MCC_PMD1024LS 0x0076 | ||
297 | #define USB_DEVICE_ID_MCC_PMD1208LS 0x007a | ||
298 | |||
299 | #define USB_VENDOR_ID_MGE 0x0463 | ||
300 | #define USB_DEVICE_ID_MGE_UPS 0xffff | ||
301 | #define USB_DEVICE_ID_MGE_UPS1 0x0001 | ||
302 | |||
303 | #define USB_VENDOR_ID_MICROCHIP 0x04d8 | ||
304 | #define USB_DEVICE_ID_PICKIT1 0x0032 | ||
305 | #define USB_DEVICE_ID_PICKIT2 0x0033 | ||
306 | |||
307 | #define USB_VENDOR_ID_MICROSOFT 0x045e | ||
308 | #define USB_DEVICE_ID_SIDEWINDER_GV 0x003b | ||
309 | #define USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0 0x009d | ||
310 | #define USB_DEVICE_ID_MS_NE4K 0x00db | ||
311 | #define USB_DEVICE_ID_MS_LK6K 0x00f9 | ||
312 | #define USB_DEVICE_ID_MS_PRESENTER_8K_BT 0x0701 | ||
313 | #define USB_DEVICE_ID_MS_PRESENTER_8K_USB 0x0713 | ||
314 | |||
315 | |||
316 | #define USB_VENDOR_ID_MONTEREY 0x0566 | ||
317 | #define USB_DEVICE_ID_GENIUS_KB29E 0x3004 | ||
318 | |||
319 | #define USB_VENDOR_ID_NCR 0x0404 | ||
320 | #define USB_DEVICE_ID_NCR_FIRST 0x0300 | ||
321 | #define USB_DEVICE_ID_NCR_LAST 0x03ff | ||
322 | |||
323 | #define USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR 0x0400 | ||
324 | #define USB_DEVICE_ID_N_S_HARMONY 0xc359 | ||
325 | |||
326 | #define USB_VENDOR_ID_NATSU 0x08b7 | ||
327 | #define USB_DEVICE_ID_NATSU_GAMEPAD 0x0001 | ||
328 | |||
329 | #define USB_VENDOR_ID_NEC 0x073e | ||
330 | #define USB_DEVICE_ID_NEC_USB_GAME_PAD 0x0301 | ||
331 | |||
332 | #define USB_VENDOR_ID_ONTRAK 0x0a07 | ||
333 | #define USB_DEVICE_ID_ONTRAK_ADU100 0x0064 | ||
334 | |||
335 | #define USB_VENDOR_ID_PANJIT 0x134c | ||
336 | |||
337 | #define USB_VENDOR_ID_PANTHERLORD 0x0810 | ||
338 | #define USB_DEVICE_ID_PANTHERLORD_TWIN_USB_JOYSTICK 0x0001 | ||
339 | |||
340 | #define USB_VENDOR_ID_PETALYNX 0x18b1 | ||
341 | #define USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE 0x0037 | ||
342 | |||
343 | #define USB_VENDOR_ID_PLAYDOTCOM 0x0b43 | ||
344 | #define USB_DEVICE_ID_PLAYDOTCOM_EMS_USBII 0x0003 | ||
345 | |||
346 | #define USB_VENDOR_ID_SAITEK 0x06a3 | ||
347 | #define USB_DEVICE_ID_SAITEK_RUMBLEPAD 0xff17 | ||
348 | |||
349 | #define USB_VENDOR_ID_SAMSUNG 0x0419 | ||
350 | #define USB_DEVICE_ID_SAMSUNG_IR_REMOTE 0x0001 | ||
351 | |||
352 | #define USB_VENDOR_ID_SONY 0x054c | ||
353 | #define USB_DEVICE_ID_SONY_PS3_CONTROLLER 0x0268 | ||
354 | |||
355 | #define USB_VENDOR_ID_SOUNDGRAPH 0x15c2 | ||
356 | #define USB_DEVICE_ID_SOUNDGRAPH_IMON_LCD 0x0038 | ||
357 | |||
358 | #define USB_VENDOR_ID_SUN 0x0430 | ||
359 | #define USB_DEVICE_ID_RARITAN_KVM_DONGLE 0xcdab | ||
360 | |||
361 | #define USB_VENDOR_ID_SUNPLUS 0x04fc | ||
362 | #define USB_DEVICE_ID_SUNPLUS_WDESKTOP 0x05d8 | ||
363 | |||
364 | #define USB_VENDOR_ID_TENX 0x1130 | ||
365 | #define USB_DEVICE_ID_TENX_IBUDDY1 0x0001 | ||
366 | #define USB_DEVICE_ID_TENX_IBUDDY2 0x0002 | ||
367 | |||
368 | #define USB_VENDOR_ID_THRUSTMASTER 0x044f | ||
369 | |||
370 | #define USB_VENDOR_ID_TOPMAX 0x0663 | ||
371 | #define USB_DEVICE_ID_TOPMAX_COBRAPAD 0x0103 | ||
372 | |||
373 | #define USB_VENDOR_ID_TURBOX 0x062a | ||
374 | #define USB_DEVICE_ID_TURBOX_KEYBOARD 0x0201 | ||
375 | |||
376 | #define USB_VENDOR_ID_VERNIER 0x08f7 | ||
377 | #define USB_DEVICE_ID_VERNIER_LABPRO 0x0001 | ||
378 | #define USB_DEVICE_ID_VERNIER_GOTEMP 0x0002 | ||
379 | #define USB_DEVICE_ID_VERNIER_SKIP 0x0003 | ||
380 | #define USB_DEVICE_ID_VERNIER_CYCLOPS 0x0004 | ||
381 | #define USB_DEVICE_ID_VERNIER_LCSPEC 0x0006 | ||
382 | |||
383 | #define USB_VENDOR_ID_WACOM 0x056a | ||
384 | |||
385 | #define USB_VENDOR_ID_WISEGROUP 0x0925 | ||
386 | #define USB_DEVICE_ID_1_PHIDGETSERVO_20 0x8101 | ||
387 | #define USB_DEVICE_ID_4_PHIDGETSERVO_20 0x8104 | ||
388 | #define USB_DEVICE_ID_8_8_4_IF_KIT 0x8201 | ||
389 | #define USB_DEVICE_ID_QUAD_USB_JOYPAD 0x8800 | ||
390 | #define USB_DEVICE_ID_DUAL_USB_JOYPAD 0x8866 | ||
391 | |||
392 | #define USB_VENDOR_ID_WISEGROUP_LTD 0x6666 | ||
393 | #define USB_VENDOR_ID_WISEGROUP_LTD2 0x6677 | ||
394 | #define USB_DEVICE_ID_SMARTJOY_DUAL_PLUS 0x8802 | ||
395 | |||
396 | #define USB_VENDOR_ID_YEALINK 0x6993 | ||
397 | #define USB_DEVICE_ID_YEALINK_P1K_P4K_B2K 0xb001 | ||
398 | |||
399 | #define USB_VENDOR_ID_ZEROPLUS 0x0c12 | ||
400 | |||
401 | #define USB_VENDOR_ID_KYE 0x0458 | ||
402 | #define USB_DEVICE_ID_KYE_GPEN_560 0x5003 | ||
403 | |||
404 | #endif | ||
diff --git a/drivers/hid/hid-input-quirks.c b/drivers/hid/hid-input-quirks.c deleted file mode 100644 index 16feea014494..000000000000 --- a/drivers/hid/hid-input-quirks.c +++ /dev/null | |||
@@ -1,484 +0,0 @@ | |||
1 | /* | ||
2 | * HID-input usage mapping quirks | ||
3 | * | ||
4 | * This is used to handle HID-input mappings for devices violating | ||
5 | * HUT 1.12 specification. | ||
6 | * | ||
7 | * Copyright (c) 2007-2008 Jiri Kosina | ||
8 | */ | ||
9 | |||
10 | /* | ||
11 | * This program is free software; you can redistribute it and/or modify it | ||
12 | * under the terms of the GNU General Public License as published by the Free | ||
13 | * Software Foundation; either version 2 of the License | ||
14 | */ | ||
15 | |||
16 | #include <linux/input.h> | ||
17 | #include <linux/hid.h> | ||
18 | |||
19 | #define map_abs(c) do { usage->code = c; usage->type = EV_ABS; *bit = input->absbit; *max = ABS_MAX; } while (0) | ||
20 | #define map_rel(c) do { usage->code = c; usage->type = EV_REL; *bit = input->relbit; *max = REL_MAX; } while (0) | ||
21 | #define map_key(c) do { usage->code = c; usage->type = EV_KEY; *bit = input->keybit; *max = KEY_MAX; } while (0) | ||
22 | #define map_led(c) do { usage->code = c; usage->type = EV_LED; *bit = input->ledbit; *max = LED_MAX; } while (0) | ||
23 | |||
24 | #define map_abs_clear(c) do { map_abs(c); clear_bit(c, *bit); } while (0) | ||
25 | #define map_key_clear(c) do { map_key(c); clear_bit(c, *bit); } while (0) | ||
26 | |||
27 | static int quirk_belkin_wkbd(struct hid_usage *usage, struct input_dev *input, | ||
28 | unsigned long **bit, int *max) | ||
29 | { | ||
30 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER) | ||
31 | return 0; | ||
32 | |||
33 | switch (usage->hid & HID_USAGE) { | ||
34 | case 0x03a: map_key_clear(KEY_SOUND); break; | ||
35 | case 0x03b: map_key_clear(KEY_CAMERA); break; | ||
36 | case 0x03c: map_key_clear(KEY_DOCUMENTS); break; | ||
37 | default: | ||
38 | return 0; | ||
39 | } | ||
40 | return 1; | ||
41 | } | ||
42 | |||
43 | static int quirk_cherry_cymotion(struct hid_usage *usage, struct input_dev *input, | ||
44 | unsigned long **bit, int *max) | ||
45 | { | ||
46 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER) | ||
47 | return 0; | ||
48 | |||
49 | switch (usage->hid & HID_USAGE) { | ||
50 | case 0x301: map_key_clear(KEY_PROG1); break; | ||
51 | case 0x302: map_key_clear(KEY_PROG2); break; | ||
52 | case 0x303: map_key_clear(KEY_PROG3); break; | ||
53 | default: | ||
54 | return 0; | ||
55 | } | ||
56 | return 1; | ||
57 | } | ||
58 | |||
59 | static int quirk_logitech_ultrax_remote(struct hid_usage *usage, struct input_dev *input, | ||
60 | unsigned long **bit, int *max) | ||
61 | { | ||
62 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR) | ||
63 | return 0; | ||
64 | |||
65 | set_bit(EV_REP, input->evbit); | ||
66 | switch(usage->hid & HID_USAGE) { | ||
67 | /* Reported on Logitech Ultra X Media Remote */ | ||
68 | case 0x004: map_key_clear(KEY_AGAIN); break; | ||
69 | case 0x00d: map_key_clear(KEY_HOME); break; | ||
70 | case 0x024: map_key_clear(KEY_SHUFFLE); break; | ||
71 | case 0x025: map_key_clear(KEY_TV); break; | ||
72 | case 0x026: map_key_clear(KEY_MENU); break; | ||
73 | case 0x031: map_key_clear(KEY_AUDIO); break; | ||
74 | case 0x032: map_key_clear(KEY_TEXT); break; | ||
75 | case 0x033: map_key_clear(KEY_LAST); break; | ||
76 | case 0x047: map_key_clear(KEY_MP3); break; | ||
77 | case 0x048: map_key_clear(KEY_DVD); break; | ||
78 | case 0x049: map_key_clear(KEY_MEDIA); break; | ||
79 | case 0x04a: map_key_clear(KEY_VIDEO); break; | ||
80 | case 0x04b: map_key_clear(KEY_ANGLE); break; | ||
81 | case 0x04c: map_key_clear(KEY_LANGUAGE); break; | ||
82 | case 0x04d: map_key_clear(KEY_SUBTITLE); break; | ||
83 | case 0x051: map_key_clear(KEY_RED); break; | ||
84 | case 0x052: map_key_clear(KEY_CLOSE); break; | ||
85 | |||
86 | default: | ||
87 | return 0; | ||
88 | } | ||
89 | return 1; | ||
90 | } | ||
91 | |||
92 | static int quirk_gyration_remote(struct hid_usage *usage, struct input_dev *input, | ||
93 | unsigned long **bit, int *max) | ||
94 | { | ||
95 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR) | ||
96 | return 0; | ||
97 | |||
98 | set_bit(EV_REP, input->evbit); | ||
99 | switch(usage->hid & HID_USAGE) { | ||
100 | /* Reported on Gyration MCE Remote */ | ||
101 | case 0x00d: map_key_clear(KEY_HOME); break; | ||
102 | case 0x024: map_key_clear(KEY_DVD); break; | ||
103 | case 0x025: map_key_clear(KEY_PVR); break; | ||
104 | case 0x046: map_key_clear(KEY_MEDIA); break; | ||
105 | case 0x047: map_key_clear(KEY_MP3); break; | ||
106 | case 0x049: map_key_clear(KEY_CAMERA); break; | ||
107 | case 0x04a: map_key_clear(KEY_VIDEO); break; | ||
108 | |||
109 | default: | ||
110 | return 0; | ||
111 | } | ||
112 | return 1; | ||
113 | } | ||
114 | |||
115 | static int quirk_chicony_tactical_pad(struct hid_usage *usage, struct input_dev *input, | ||
116 | unsigned long **bit, int *max) | ||
117 | { | ||
118 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR) | ||
119 | return 0; | ||
120 | |||
121 | set_bit(EV_REP, input->evbit); | ||
122 | switch (usage->hid & HID_USAGE) { | ||
123 | case 0xff01: map_key_clear(BTN_1); break; | ||
124 | case 0xff02: map_key_clear(BTN_2); break; | ||
125 | case 0xff03: map_key_clear(BTN_3); break; | ||
126 | case 0xff04: map_key_clear(BTN_4); break; | ||
127 | case 0xff05: map_key_clear(BTN_5); break; | ||
128 | case 0xff06: map_key_clear(BTN_6); break; | ||
129 | case 0xff07: map_key_clear(BTN_7); break; | ||
130 | case 0xff08: map_key_clear(BTN_8); break; | ||
131 | case 0xff09: map_key_clear(BTN_9); break; | ||
132 | case 0xff0a: map_key_clear(BTN_A); break; | ||
133 | case 0xff0b: map_key_clear(BTN_B); break; | ||
134 | default: | ||
135 | return 0; | ||
136 | } | ||
137 | return 1; | ||
138 | } | ||
139 | |||
140 | static int quirk_microsoft_ergonomy_kb(struct hid_usage *usage, struct input_dev *input, | ||
141 | unsigned long **bit, int *max) | ||
142 | { | ||
143 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR) | ||
144 | return 0; | ||
145 | |||
146 | switch(usage->hid & HID_USAGE) { | ||
147 | case 0xfd06: map_key_clear(KEY_CHAT); break; | ||
148 | case 0xfd07: map_key_clear(KEY_PHONE); break; | ||
149 | case 0xff05: | ||
150 | set_bit(EV_REP, input->evbit); | ||
151 | map_key_clear(KEY_F13); | ||
152 | set_bit(KEY_F14, input->keybit); | ||
153 | set_bit(KEY_F15, input->keybit); | ||
154 | set_bit(KEY_F16, input->keybit); | ||
155 | set_bit(KEY_F17, input->keybit); | ||
156 | set_bit(KEY_F18, input->keybit); | ||
157 | default: | ||
158 | return 0; | ||
159 | } | ||
160 | return 1; | ||
161 | } | ||
162 | |||
163 | static int quirk_microsoft_presenter_8k(struct hid_usage *usage, struct input_dev *input, | ||
164 | unsigned long **bit, int *max) | ||
165 | { | ||
166 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR) | ||
167 | return 0; | ||
168 | |||
169 | set_bit(EV_REP, input->evbit); | ||
170 | switch(usage->hid & HID_USAGE) { | ||
171 | case 0xfd08: map_key_clear(KEY_FORWARD); break; | ||
172 | case 0xfd09: map_key_clear(KEY_BACK); break; | ||
173 | case 0xfd0b: map_key_clear(KEY_PLAYPAUSE); break; | ||
174 | case 0xfd0e: map_key_clear(KEY_CLOSE); break; | ||
175 | case 0xfd0f: map_key_clear(KEY_PLAY); break; | ||
176 | default: | ||
177 | return 0; | ||
178 | } | ||
179 | return 1; | ||
180 | } | ||
181 | |||
182 | static int quirk_petalynx_remote(struct hid_usage *usage, struct input_dev *input, | ||
183 | unsigned long **bit, int *max) | ||
184 | { | ||
185 | if (((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR) && | ||
186 | ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)) | ||
187 | return 0; | ||
188 | |||
189 | if ((usage->hid & HID_USAGE_PAGE) == HID_UP_LOGIVENDOR) | ||
190 | switch(usage->hid & HID_USAGE) { | ||
191 | case 0x05a: map_key_clear(KEY_TEXT); break; | ||
192 | case 0x05b: map_key_clear(KEY_RED); break; | ||
193 | case 0x05c: map_key_clear(KEY_GREEN); break; | ||
194 | case 0x05d: map_key_clear(KEY_YELLOW); break; | ||
195 | case 0x05e: map_key_clear(KEY_BLUE); break; | ||
196 | default: | ||
197 | return 0; | ||
198 | } | ||
199 | |||
200 | if ((usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER) | ||
201 | switch(usage->hid & HID_USAGE) { | ||
202 | case 0x0f6: map_key_clear(KEY_NEXT); break; | ||
203 | case 0x0fa: map_key_clear(KEY_BACK); break; | ||
204 | default: | ||
205 | return 0; | ||
206 | } | ||
207 | return 1; | ||
208 | } | ||
209 | |||
210 | static int quirk_logitech_wireless(struct hid_usage *usage, struct input_dev *input, | ||
211 | unsigned long **bit, int *max) | ||
212 | { | ||
213 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER) | ||
214 | return 0; | ||
215 | |||
216 | switch (usage->hid & HID_USAGE) { | ||
217 | case 0x1001: map_key_clear(KEY_MESSENGER); break; | ||
218 | case 0x1003: map_key_clear(KEY_SOUND); break; | ||
219 | case 0x1004: map_key_clear(KEY_VIDEO); break; | ||
220 | case 0x1005: map_key_clear(KEY_AUDIO); break; | ||
221 | case 0x100a: map_key_clear(KEY_DOCUMENTS); break; | ||
222 | case 0x1011: map_key_clear(KEY_PREVIOUSSONG); break; | ||
223 | case 0x1012: map_key_clear(KEY_NEXTSONG); break; | ||
224 | case 0x1013: map_key_clear(KEY_CAMERA); break; | ||
225 | case 0x1014: map_key_clear(KEY_MESSENGER); break; | ||
226 | case 0x1015: map_key_clear(KEY_RECORD); break; | ||
227 | case 0x1016: map_key_clear(KEY_PLAYER); break; | ||
228 | case 0x1017: map_key_clear(KEY_EJECTCD); break; | ||
229 | case 0x1018: map_key_clear(KEY_MEDIA); break; | ||
230 | case 0x1019: map_key_clear(KEY_PROG1); break; | ||
231 | case 0x101a: map_key_clear(KEY_PROG2); break; | ||
232 | case 0x101b: map_key_clear(KEY_PROG3); break; | ||
233 | case 0x101f: map_key_clear(KEY_ZOOMIN); break; | ||
234 | case 0x1020: map_key_clear(KEY_ZOOMOUT); break; | ||
235 | case 0x1021: map_key_clear(KEY_ZOOMRESET); break; | ||
236 | case 0x1023: map_key_clear(KEY_CLOSE); break; | ||
237 | case 0x1027: map_key_clear(KEY_MENU); break; | ||
238 | /* this one is marked as 'Rotate' */ | ||
239 | case 0x1028: map_key_clear(KEY_ANGLE); break; | ||
240 | case 0x1029: map_key_clear(KEY_SHUFFLE); break; | ||
241 | case 0x102a: map_key_clear(KEY_BACK); break; | ||
242 | case 0x102b: map_key_clear(KEY_CYCLEWINDOWS); break; | ||
243 | case 0x1041: map_key_clear(KEY_BATTERY); break; | ||
244 | case 0x1042: map_key_clear(KEY_WORDPROCESSOR); break; | ||
245 | case 0x1043: map_key_clear(KEY_SPREADSHEET); break; | ||
246 | case 0x1044: map_key_clear(KEY_PRESENTATION); break; | ||
247 | case 0x1045: map_key_clear(KEY_UNDO); break; | ||
248 | case 0x1046: map_key_clear(KEY_REDO); break; | ||
249 | case 0x1047: map_key_clear(KEY_PRINT); break; | ||
250 | case 0x1048: map_key_clear(KEY_SAVE); break; | ||
251 | case 0x1049: map_key_clear(KEY_PROG1); break; | ||
252 | case 0x104a: map_key_clear(KEY_PROG2); break; | ||
253 | case 0x104b: map_key_clear(KEY_PROG3); break; | ||
254 | case 0x104c: map_key_clear(KEY_PROG4); break; | ||
255 | |||
256 | default: | ||
257 | return 0; | ||
258 | } | ||
259 | return 1; | ||
260 | } | ||
261 | |||
262 | static int quirk_cherry_genius_29e(struct hid_usage *usage, struct input_dev *input, | ||
263 | unsigned long **bit, int *max) | ||
264 | { | ||
265 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER) | ||
266 | return 0; | ||
267 | |||
268 | switch (usage->hid & HID_USAGE) { | ||
269 | case 0x156: map_key_clear(KEY_WORDPROCESSOR); break; | ||
270 | case 0x157: map_key_clear(KEY_SPREADSHEET); break; | ||
271 | case 0x158: map_key_clear(KEY_PRESENTATION); break; | ||
272 | case 0x15c: map_key_clear(KEY_STOP); break; | ||
273 | |||
274 | default: | ||
275 | return 0; | ||
276 | } | ||
277 | return 1; | ||
278 | } | ||
279 | |||
280 | static int quirk_btc_8193(struct hid_usage *usage, struct input_dev *input, | ||
281 | unsigned long **bit, int *max) | ||
282 | { | ||
283 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER) | ||
284 | return 0; | ||
285 | |||
286 | switch (usage->hid & HID_USAGE) { | ||
287 | case 0x230: map_key(BTN_MOUSE); break; | ||
288 | case 0x231: map_rel(REL_WHEEL); break; | ||
289 | /* | ||
290 | * this keyboard has a scrollwheel implemented in | ||
291 | * totally broken way. We map this usage temporarily | ||
292 | * to HWHEEL and handle it in the event quirk handler | ||
293 | */ | ||
294 | case 0x232: map_rel(REL_HWHEEL); break; | ||
295 | |||
296 | default: | ||
297 | return 0; | ||
298 | } | ||
299 | return 1; | ||
300 | } | ||
301 | |||
302 | static int quirk_sunplus_wdesktop(struct hid_usage *usage, struct input_dev *input, | ||
303 | unsigned long **bit, int *max) | ||
304 | { | ||
305 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER) | ||
306 | return 0; | ||
307 | |||
308 | switch (usage->hid & HID_USAGE) { | ||
309 | case 0x2003: map_key_clear(KEY_ZOOMIN); break; | ||
310 | case 0x2103: map_key_clear(KEY_ZOOMOUT); break; | ||
311 | default: | ||
312 | return 0; | ||
313 | } | ||
314 | return 1; | ||
315 | } | ||
316 | |||
317 | #define VENDOR_ID_BELKIN 0x1020 | ||
318 | #define DEVICE_ID_BELKIN_WIRELESS_KEYBOARD 0x0006 | ||
319 | |||
320 | #define VENDOR_ID_CHERRY 0x046a | ||
321 | #define DEVICE_ID_CHERRY_CYMOTION 0x0023 | ||
322 | |||
323 | #define VENDOR_ID_CHICONY 0x04f2 | ||
324 | #define DEVICE_ID_CHICONY_TACTICAL_PAD 0x0418 | ||
325 | |||
326 | #define VENDOR_ID_EZKEY 0x0518 | ||
327 | #define DEVICE_ID_BTC_8193 0x0002 | ||
328 | |||
329 | #define VENDOR_ID_GYRATION 0x0c16 | ||
330 | #define DEVICE_ID_GYRATION_REMOTE 0x0002 | ||
331 | |||
332 | #define VENDOR_ID_LOGITECH 0x046d | ||
333 | #define DEVICE_ID_LOGITECH_RECEIVER 0xc101 | ||
334 | #define DEVICE_ID_S510_RECEIVER 0xc50c | ||
335 | #define DEVICE_ID_S510_RECEIVER_2 0xc517 | ||
336 | #define DEVICE_ID_MX3000_RECEIVER 0xc513 | ||
337 | |||
338 | #define VENDOR_ID_MICROSOFT 0x045e | ||
339 | #define DEVICE_ID_MS4K 0x00db | ||
340 | #define DEVICE_ID_MS6K 0x00f9 | ||
341 | #define DEVICE_IS_MS_PRESENTER_8K_BT 0x0701 | ||
342 | #define DEVICE_ID_MS_PRESENTER_8K_USB 0x0713 | ||
343 | |||
344 | #define VENDOR_ID_MONTEREY 0x0566 | ||
345 | #define DEVICE_ID_GENIUS_KB29E 0x3004 | ||
346 | |||
347 | #define VENDOR_ID_PETALYNX 0x18b1 | ||
348 | #define DEVICE_ID_PETALYNX_MAXTER_REMOTE 0x0037 | ||
349 | |||
350 | #define VENDOR_ID_SUNPLUS 0x04fc | ||
351 | #define DEVICE_ID_SUNPLUS_WDESKTOP 0x05d8 | ||
352 | |||
353 | static const struct hid_input_blacklist { | ||
354 | __u16 idVendor; | ||
355 | __u16 idProduct; | ||
356 | int (*quirk)(struct hid_usage *, struct input_dev *, unsigned long **, int *); | ||
357 | } hid_input_blacklist[] = { | ||
358 | { VENDOR_ID_BELKIN, DEVICE_ID_BELKIN_WIRELESS_KEYBOARD, quirk_belkin_wkbd }, | ||
359 | |||
360 | { VENDOR_ID_CHERRY, DEVICE_ID_CHERRY_CYMOTION, quirk_cherry_cymotion }, | ||
361 | |||
362 | { VENDOR_ID_CHICONY, DEVICE_ID_CHICONY_TACTICAL_PAD, quirk_chicony_tactical_pad }, | ||
363 | |||
364 | { VENDOR_ID_EZKEY, DEVICE_ID_BTC_8193, quirk_btc_8193 }, | ||
365 | |||
366 | { VENDOR_ID_GYRATION, DEVICE_ID_GYRATION_REMOTE, quirk_gyration_remote }, | ||
367 | |||
368 | { VENDOR_ID_LOGITECH, DEVICE_ID_LOGITECH_RECEIVER, quirk_logitech_ultrax_remote }, | ||
369 | { VENDOR_ID_LOGITECH, DEVICE_ID_S510_RECEIVER, quirk_logitech_wireless }, | ||
370 | { VENDOR_ID_LOGITECH, DEVICE_ID_S510_RECEIVER_2, quirk_logitech_wireless }, | ||
371 | { VENDOR_ID_LOGITECH, DEVICE_ID_MX3000_RECEIVER, quirk_logitech_wireless }, | ||
372 | |||
373 | { VENDOR_ID_MICROSOFT, DEVICE_ID_MS4K, quirk_microsoft_ergonomy_kb }, | ||
374 | { VENDOR_ID_MICROSOFT, DEVICE_ID_MS6K, quirk_microsoft_ergonomy_kb }, | ||
375 | { VENDOR_ID_MICROSOFT, DEVICE_IS_MS_PRESENTER_8K_BT, quirk_microsoft_presenter_8k }, | ||
376 | { VENDOR_ID_MICROSOFT, DEVICE_ID_MS_PRESENTER_8K_USB, quirk_microsoft_presenter_8k }, | ||
377 | |||
378 | { VENDOR_ID_MONTEREY, DEVICE_ID_GENIUS_KB29E, quirk_cherry_genius_29e }, | ||
379 | |||
380 | { VENDOR_ID_PETALYNX, DEVICE_ID_PETALYNX_MAXTER_REMOTE, quirk_petalynx_remote }, | ||
381 | |||
382 | { VENDOR_ID_SUNPLUS, DEVICE_ID_SUNPLUS_WDESKTOP, quirk_sunplus_wdesktop }, | ||
383 | |||
384 | { 0, 0, NULL } | ||
385 | }; | ||
386 | |||
387 | int hidinput_mapping_quirks(struct hid_usage *usage, | ||
388 | struct input_dev *input, | ||
389 | unsigned long **bit, int *max) | ||
390 | { | ||
391 | struct hid_device *device = input_get_drvdata(input); | ||
392 | int i = 0; | ||
393 | |||
394 | while (hid_input_blacklist[i].quirk) { | ||
395 | if (hid_input_blacklist[i].idVendor == device->vendor && | ||
396 | hid_input_blacklist[i].idProduct == device->product) | ||
397 | return hid_input_blacklist[i].quirk(usage, input, bit, max); | ||
398 | i++; | ||
399 | } | ||
400 | return 0; | ||
401 | } | ||
402 | |||
403 | int hidinput_event_quirks(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value) | ||
404 | { | ||
405 | struct input_dev *input; | ||
406 | |||
407 | input = field->hidinput->input; | ||
408 | |||
409 | if (((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_5) && (usage->hid == 0x00090005)) | ||
410 | || ((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_7) && (usage->hid == 0x00090007))) { | ||
411 | if (value) hid->quirks |= HID_QUIRK_2WHEEL_MOUSE_HACK_ON; | ||
412 | else hid->quirks &= ~HID_QUIRK_2WHEEL_MOUSE_HACK_ON; | ||
413 | return 1; | ||
414 | } | ||
415 | |||
416 | if ((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_B8) && | ||
417 | (usage->type == EV_REL) && | ||
418 | (usage->code == REL_WHEEL)) { | ||
419 | hid->delayed_value = value; | ||
420 | return 1; | ||
421 | } | ||
422 | |||
423 | if ((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_B8) && | ||
424 | (usage->hid == 0x000100b8)) { | ||
425 | input_event(input, EV_REL, value ? REL_HWHEEL : REL_WHEEL, hid->delayed_value); | ||
426 | return 1; | ||
427 | } | ||
428 | |||
429 | if ((hid->quirks & HID_QUIRK_INVERT_HWHEEL) && (usage->code == REL_HWHEEL)) { | ||
430 | input_event(input, usage->type, usage->code, -value); | ||
431 | return 1; | ||
432 | } | ||
433 | |||
434 | if ((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_ON) && (usage->code == REL_WHEEL)) { | ||
435 | input_event(input, usage->type, REL_HWHEEL, value); | ||
436 | return 1; | ||
437 | } | ||
438 | |||
439 | if ((hid->quirks & HID_QUIRK_APPLE_HAS_FN) && hidinput_apple_event(hid, input, usage, value)) | ||
440 | return 1; | ||
441 | |||
442 | /* Handling MS keyboards special buttons */ | ||
443 | if (hid->quirks & HID_QUIRK_MICROSOFT_KEYS && | ||
444 | usage->hid == (HID_UP_MSVENDOR | 0xff05)) { | ||
445 | int key = 0; | ||
446 | static int last_key = 0; | ||
447 | switch (value) { | ||
448 | case 0x01: key = KEY_F14; break; | ||
449 | case 0x02: key = KEY_F15; break; | ||
450 | case 0x04: key = KEY_F16; break; | ||
451 | case 0x08: key = KEY_F17; break; | ||
452 | case 0x10: key = KEY_F18; break; | ||
453 | default: break; | ||
454 | } | ||
455 | if (key) { | ||
456 | input_event(input, usage->type, key, 1); | ||
457 | last_key = key; | ||
458 | } else { | ||
459 | input_event(input, usage->type, last_key, 0); | ||
460 | } | ||
461 | } | ||
462 | |||
463 | /* handle the temporary quirky mapping to HWHEEL */ | ||
464 | if (hid->quirks & HID_QUIRK_HWHEEL_WHEEL_INVERT && | ||
465 | usage->type == EV_REL && usage->code == REL_HWHEEL) { | ||
466 | input_event(input, usage->type, REL_WHEEL, -value); | ||
467 | return 1; | ||
468 | } | ||
469 | |||
470 | /* Gyration MCE remote "Sleep" key */ | ||
471 | if (hid->vendor == VENDOR_ID_GYRATION && | ||
472 | hid->product == DEVICE_ID_GYRATION_REMOTE && | ||
473 | (usage->hid & HID_USAGE_PAGE) == HID_UP_GENDESK && | ||
474 | (usage->hid & 0xff) == 0x82) { | ||
475 | input_event(input, usage->type, usage->code, 1); | ||
476 | input_sync(input); | ||
477 | input_event(input, usage->type, usage->code, 0); | ||
478 | input_sync(input); | ||
479 | return 1; | ||
480 | } | ||
481 | return 0; | ||
482 | } | ||
483 | |||
484 | |||
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index 1b2e8dc3398d..7f183b7147e1 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c | |||
@@ -32,11 +32,6 @@ | |||
32 | #include <linux/hid.h> | 32 | #include <linux/hid.h> |
33 | #include <linux/hid-debug.h> | 33 | #include <linux/hid-debug.h> |
34 | 34 | ||
35 | static int hid_apple_fnmode = 1; | ||
36 | module_param_named(pb_fnmode, hid_apple_fnmode, int, 0644); | ||
37 | MODULE_PARM_DESC(pb_fnmode, | ||
38 | "Mode of fn key on Apple keyboards (0 = disabled, 1 = fkeyslast, 2 = fkeysfirst)"); | ||
39 | |||
40 | #define unk KEY_UNKNOWN | 35 | #define unk KEY_UNKNOWN |
41 | 36 | ||
42 | static const unsigned char hid_keyboard[256] = { | 37 | static const unsigned char hid_keyboard[256] = { |
@@ -58,227 +53,20 @@ static const unsigned char hid_keyboard[256] = { | |||
58 | 150,158,159,128,136,177,178,176,142,152,173,140,unk,unk,unk,unk | 53 | 150,158,159,128,136,177,178,176,142,152,173,140,unk,unk,unk,unk |
59 | }; | 54 | }; |
60 | 55 | ||
61 | /* extended mapping for certain Logitech hardware (Logitech cordless desktop LX500) */ | ||
62 | #define LOGITECH_EXPANDED_KEYMAP_SIZE 80 | ||
63 | static int logitech_expanded_keymap[LOGITECH_EXPANDED_KEYMAP_SIZE] = { | ||
64 | 0,216, 0,213,175,156, 0, 0, 0, 0, | ||
65 | 144, 0, 0, 0, 0, 0, 0, 0, 0,212, | ||
66 | 174,167,152,161,112, 0, 0, 0,154, 0, | ||
67 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
68 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
69 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
70 | 0, 0, 0, 0, 0,183,184,185,186,187, | ||
71 | 188,189,190,191,192,193,194, 0, 0, 0 | ||
72 | }; | ||
73 | |||
74 | static const struct { | 56 | static const struct { |
75 | __s32 x; | 57 | __s32 x; |
76 | __s32 y; | 58 | __s32 y; |
77 | } hid_hat_to_axis[] = {{ 0, 0}, { 0,-1}, { 1,-1}, { 1, 0}, { 1, 1}, { 0, 1}, {-1, 1}, {-1, 0}, {-1,-1}}; | 59 | } hid_hat_to_axis[] = {{ 0, 0}, { 0,-1}, { 1,-1}, { 1, 0}, { 1, 1}, { 0, 1}, {-1, 1}, {-1, 0}, {-1,-1}}; |
78 | 60 | ||
79 | #define map_abs(c) do { usage->code = c; usage->type = EV_ABS; bit = input->absbit; max = ABS_MAX; } while (0) | 61 | #define map_abs(c) hid_map_usage(hidinput, usage, &bit, &max, EV_ABS, (c)) |
80 | #define map_rel(c) do { usage->code = c; usage->type = EV_REL; bit = input->relbit; max = REL_MAX; } while (0) | 62 | #define map_rel(c) hid_map_usage(hidinput, usage, &bit, &max, EV_REL, (c)) |
81 | #define map_key(c) do { usage->code = c; usage->type = EV_KEY; bit = input->keybit; max = KEY_MAX; } while (0) | 63 | #define map_key(c) hid_map_usage(hidinput, usage, &bit, &max, EV_KEY, (c)) |
82 | #define map_led(c) do { usage->code = c; usage->type = EV_LED; bit = input->ledbit; max = LED_MAX; } while (0) | 64 | #define map_led(c) hid_map_usage(hidinput, usage, &bit, &max, EV_LED, (c)) |
83 | |||
84 | #define map_abs_clear(c) do { map_abs(c); clear_bit(c, bit); } while (0) | ||
85 | #define map_key_clear(c) do { map_key(c); clear_bit(c, bit); } while (0) | ||
86 | |||
87 | #ifdef CONFIG_USB_HIDINPUT_POWERBOOK | ||
88 | |||
89 | struct hidinput_key_translation { | ||
90 | u16 from; | ||
91 | u16 to; | ||
92 | u8 flags; | ||
93 | }; | ||
94 | |||
95 | #define APPLE_FLAG_FKEY 0x01 | ||
96 | |||
97 | static struct hidinput_key_translation apple_fn_keys[] = { | ||
98 | { KEY_BACKSPACE, KEY_DELETE }, | ||
99 | { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY }, | ||
100 | { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY }, | ||
101 | { KEY_F3, KEY_FN_F5, APPLE_FLAG_FKEY }, /* Exposé */ | ||
102 | { KEY_F4, KEY_FN_F4, APPLE_FLAG_FKEY }, /* Dashboard */ | ||
103 | { KEY_F5, KEY_KBDILLUMDOWN, APPLE_FLAG_FKEY }, | ||
104 | { KEY_F6, KEY_KBDILLUMUP, APPLE_FLAG_FKEY }, | ||
105 | { KEY_F7, KEY_PREVIOUSSONG, APPLE_FLAG_FKEY }, | ||
106 | { KEY_F8, KEY_PLAYPAUSE, APPLE_FLAG_FKEY }, | ||
107 | { KEY_F9, KEY_NEXTSONG, APPLE_FLAG_FKEY }, | ||
108 | { KEY_F10, KEY_MUTE, APPLE_FLAG_FKEY }, | ||
109 | { KEY_F11, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY }, | ||
110 | { KEY_F12, KEY_VOLUMEUP, APPLE_FLAG_FKEY }, | ||
111 | { KEY_UP, KEY_PAGEUP }, | ||
112 | { KEY_DOWN, KEY_PAGEDOWN }, | ||
113 | { KEY_LEFT, KEY_HOME }, | ||
114 | { KEY_RIGHT, KEY_END }, | ||
115 | { } | ||
116 | }; | ||
117 | |||
118 | static struct hidinput_key_translation powerbook_fn_keys[] = { | ||
119 | { KEY_BACKSPACE, KEY_DELETE }, | ||
120 | { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY }, | ||
121 | { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY }, | ||
122 | { KEY_F3, KEY_MUTE, APPLE_FLAG_FKEY }, | ||
123 | { KEY_F4, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY }, | ||
124 | { KEY_F5, KEY_VOLUMEUP, APPLE_FLAG_FKEY }, | ||
125 | { KEY_F6, KEY_NUMLOCK, APPLE_FLAG_FKEY }, | ||
126 | { KEY_F7, KEY_SWITCHVIDEOMODE, APPLE_FLAG_FKEY }, | ||
127 | { KEY_F8, KEY_KBDILLUMTOGGLE, APPLE_FLAG_FKEY }, | ||
128 | { KEY_F9, KEY_KBDILLUMDOWN, APPLE_FLAG_FKEY }, | ||
129 | { KEY_F10, KEY_KBDILLUMUP, APPLE_FLAG_FKEY }, | ||
130 | { KEY_UP, KEY_PAGEUP }, | ||
131 | { KEY_DOWN, KEY_PAGEDOWN }, | ||
132 | { KEY_LEFT, KEY_HOME }, | ||
133 | { KEY_RIGHT, KEY_END }, | ||
134 | { } | ||
135 | }; | ||
136 | |||
137 | static struct hidinput_key_translation powerbook_numlock_keys[] = { | ||
138 | { KEY_J, KEY_KP1 }, | ||
139 | { KEY_K, KEY_KP2 }, | ||
140 | { KEY_L, KEY_KP3 }, | ||
141 | { KEY_U, KEY_KP4 }, | ||
142 | { KEY_I, KEY_KP5 }, | ||
143 | { KEY_O, KEY_KP6 }, | ||
144 | { KEY_7, KEY_KP7 }, | ||
145 | { KEY_8, KEY_KP8 }, | ||
146 | { KEY_9, KEY_KP9 }, | ||
147 | { KEY_M, KEY_KP0 }, | ||
148 | { KEY_DOT, KEY_KPDOT }, | ||
149 | { KEY_SLASH, KEY_KPPLUS }, | ||
150 | { KEY_SEMICOLON, KEY_KPMINUS }, | ||
151 | { KEY_P, KEY_KPASTERISK }, | ||
152 | { KEY_MINUS, KEY_KPEQUAL }, | ||
153 | { KEY_0, KEY_KPSLASH }, | ||
154 | { KEY_F6, KEY_NUMLOCK }, | ||
155 | { KEY_KPENTER, KEY_KPENTER }, | ||
156 | { KEY_BACKSPACE, KEY_BACKSPACE }, | ||
157 | { } | ||
158 | }; | ||
159 | |||
160 | static struct hidinput_key_translation apple_iso_keyboard[] = { | ||
161 | { KEY_GRAVE, KEY_102ND }, | ||
162 | { KEY_102ND, KEY_GRAVE }, | ||
163 | { } | ||
164 | }; | ||
165 | 65 | ||
166 | static struct hidinput_key_translation *find_translation(struct hidinput_key_translation *table, u16 from) | 66 | #define map_abs_clear(c) hid_map_usage_clear(hidinput, usage, &bit, \ |
167 | { | 67 | &max, EV_ABS, (c)) |
168 | struct hidinput_key_translation *trans; | 68 | #define map_key_clear(c) hid_map_usage_clear(hidinput, usage, &bit, \ |
169 | 69 | &max, EV_KEY, (c)) | |
170 | /* Look for the translation */ | ||
171 | for (trans = table; trans->from; trans++) | ||
172 | if (trans->from == from) | ||
173 | return trans; | ||
174 | |||
175 | return NULL; | ||
176 | } | ||
177 | |||
178 | int hidinput_apple_event(struct hid_device *hid, struct input_dev *input, | ||
179 | struct hid_usage *usage, __s32 value) | ||
180 | { | ||
181 | struct hidinput_key_translation *trans; | ||
182 | |||
183 | if (usage->code == KEY_FN) { | ||
184 | if (value) hid->quirks |= HID_QUIRK_APPLE_FN_ON; | ||
185 | else hid->quirks &= ~HID_QUIRK_APPLE_FN_ON; | ||
186 | |||
187 | input_event(input, usage->type, usage->code, value); | ||
188 | |||
189 | return 1; | ||
190 | } | ||
191 | |||
192 | if (hid_apple_fnmode) { | ||
193 | int do_translate; | ||
194 | |||
195 | trans = find_translation((hid->product < 0x220 || | ||
196 | hid->product >= 0x300) ? | ||
197 | powerbook_fn_keys : apple_fn_keys, | ||
198 | usage->code); | ||
199 | if (trans) { | ||
200 | if (test_bit(usage->code, hid->apple_pressed_fn)) | ||
201 | do_translate = 1; | ||
202 | else if (trans->flags & APPLE_FLAG_FKEY) | ||
203 | do_translate = | ||
204 | (hid_apple_fnmode == 2 && (hid->quirks & HID_QUIRK_APPLE_FN_ON)) || | ||
205 | (hid_apple_fnmode == 1 && !(hid->quirks & HID_QUIRK_APPLE_FN_ON)); | ||
206 | else | ||
207 | do_translate = (hid->quirks & HID_QUIRK_APPLE_FN_ON); | ||
208 | |||
209 | if (do_translate) { | ||
210 | if (value) | ||
211 | set_bit(usage->code, hid->apple_pressed_fn); | ||
212 | else | ||
213 | clear_bit(usage->code, hid->apple_pressed_fn); | ||
214 | |||
215 | input_event(input, usage->type, trans->to, value); | ||
216 | |||
217 | return 1; | ||
218 | } | ||
219 | } | ||
220 | |||
221 | if (hid->quirks & HID_QUIRK_APPLE_NUMLOCK_EMULATION && ( | ||
222 | test_bit(usage->code, hid->pb_pressed_numlock) || | ||
223 | test_bit(LED_NUML, input->led))) { | ||
224 | trans = find_translation(powerbook_numlock_keys, usage->code); | ||
225 | |||
226 | if (trans) { | ||
227 | if (value) | ||
228 | set_bit(usage->code, hid->pb_pressed_numlock); | ||
229 | else | ||
230 | clear_bit(usage->code, hid->pb_pressed_numlock); | ||
231 | |||
232 | input_event(input, usage->type, trans->to, value); | ||
233 | } | ||
234 | |||
235 | return 1; | ||
236 | } | ||
237 | } | ||
238 | |||
239 | if (hid->quirks & HID_QUIRK_APPLE_ISO_KEYBOARD) { | ||
240 | trans = find_translation(apple_iso_keyboard, usage->code); | ||
241 | if (trans) { | ||
242 | input_event(input, usage->type, trans->to, value); | ||
243 | return 1; | ||
244 | } | ||
245 | } | ||
246 | |||
247 | return 0; | ||
248 | } | ||
249 | |||
250 | static void hidinput_apple_setup(struct input_dev *input) | ||
251 | { | ||
252 | struct hidinput_key_translation *trans; | ||
253 | |||
254 | set_bit(KEY_NUMLOCK, input->keybit); | ||
255 | |||
256 | /* Enable all needed keys */ | ||
257 | for (trans = apple_fn_keys; trans->from; trans++) | ||
258 | set_bit(trans->to, input->keybit); | ||
259 | |||
260 | for (trans = powerbook_fn_keys; trans->from; trans++) | ||
261 | set_bit(trans->to, input->keybit); | ||
262 | |||
263 | for (trans = powerbook_numlock_keys; trans->from; trans++) | ||
264 | set_bit(trans->to, input->keybit); | ||
265 | |||
266 | for (trans = apple_iso_keyboard; trans->from; trans++) | ||
267 | set_bit(trans->to, input->keybit); | ||
268 | |||
269 | } | ||
270 | #else | ||
271 | inline int hidinput_apple_event(struct hid_device *hid, | ||
272 | struct input_dev *input, | ||
273 | struct hid_usage *usage, __s32 value) | ||
274 | { | ||
275 | return 0; | ||
276 | } | ||
277 | |||
278 | static inline void hidinput_apple_setup(struct input_dev *input) | ||
279 | { | ||
280 | } | ||
281 | #endif | ||
282 | 70 | ||
283 | static inline int match_scancode(int code, int scancode) | 71 | static inline int match_scancode(int code, int scancode) |
284 | { | 72 | { |
@@ -366,7 +154,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel | |||
366 | { | 154 | { |
367 | struct input_dev *input = hidinput->input; | 155 | struct input_dev *input = hidinput->input; |
368 | struct hid_device *device = input_get_drvdata(input); | 156 | struct hid_device *device = input_get_drvdata(input); |
369 | int max = 0, code, ret; | 157 | int max = 0, code; |
370 | unsigned long *bit = NULL; | 158 | unsigned long *bit = NULL; |
371 | 159 | ||
372 | field->hidinput = hidinput; | 160 | field->hidinput = hidinput; |
@@ -385,406 +173,345 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel | |||
385 | goto ignore; | 173 | goto ignore; |
386 | } | 174 | } |
387 | 175 | ||
388 | /* handle input mappings for quirky devices */ | 176 | if (device->driver->input_mapping) { |
389 | ret = hidinput_mapping_quirks(usage, input, &bit, &max); | 177 | int ret = device->driver->input_mapping(device, hidinput, field, |
390 | if (ret) | 178 | usage, &bit, &max); |
391 | goto mapped; | 179 | if (ret > 0) |
180 | goto mapped; | ||
181 | if (ret < 0) | ||
182 | goto ignore; | ||
183 | } | ||
392 | 184 | ||
393 | switch (usage->hid & HID_USAGE_PAGE) { | 185 | switch (usage->hid & HID_USAGE_PAGE) { |
186 | case HID_UP_UNDEFINED: | ||
187 | goto ignore; | ||
394 | 188 | ||
395 | case HID_UP_UNDEFINED: | 189 | case HID_UP_KEYBOARD: |
396 | goto ignore; | 190 | set_bit(EV_REP, input->evbit); |
397 | |||
398 | case HID_UP_KEYBOARD: | ||
399 | 191 | ||
400 | set_bit(EV_REP, input->evbit); | 192 | if ((usage->hid & HID_USAGE) < 256) { |
193 | if (!hid_keyboard[usage->hid & HID_USAGE]) goto ignore; | ||
194 | map_key_clear(hid_keyboard[usage->hid & HID_USAGE]); | ||
195 | } else | ||
196 | map_key(KEY_UNKNOWN); | ||
401 | 197 | ||
402 | if ((usage->hid & HID_USAGE) < 256) { | 198 | break; |
403 | if (!hid_keyboard[usage->hid & HID_USAGE]) goto ignore; | ||
404 | map_key_clear(hid_keyboard[usage->hid & HID_USAGE]); | ||
405 | } else | ||
406 | map_key(KEY_UNKNOWN); | ||
407 | 199 | ||
408 | break; | 200 | case HID_UP_BUTTON: |
201 | code = ((usage->hid - 1) & 0xf); | ||
409 | 202 | ||
410 | case HID_UP_BUTTON: | 203 | switch (field->application) { |
411 | 204 | case HID_GD_MOUSE: | |
412 | code = ((usage->hid - 1) & 0xf); | 205 | case HID_GD_POINTER: code += 0x110; break; |
413 | 206 | case HID_GD_JOYSTICK: code += 0x120; break; | |
414 | switch (field->application) { | 207 | case HID_GD_GAMEPAD: code += 0x130; break; |
415 | case HID_GD_MOUSE: | 208 | default: |
416 | case HID_GD_POINTER: code += 0x110; break; | 209 | switch (field->physical) { |
417 | case HID_GD_JOYSTICK: code += 0x120; break; | 210 | case HID_GD_MOUSE: |
418 | case HID_GD_GAMEPAD: code += 0x130; break; | 211 | case HID_GD_POINTER: code += 0x110; break; |
419 | default: | 212 | case HID_GD_JOYSTICK: code += 0x120; break; |
420 | switch (field->physical) { | 213 | case HID_GD_GAMEPAD: code += 0x130; break; |
421 | case HID_GD_MOUSE: | 214 | default: code += 0x100; |
422 | case HID_GD_POINTER: code += 0x110; break; | ||
423 | case HID_GD_JOYSTICK: code += 0x120; break; | ||
424 | case HID_GD_GAMEPAD: code += 0x130; break; | ||
425 | default: code += 0x100; | ||
426 | } | ||
427 | } | ||
428 | |||
429 | /* Special handling for Logitech Cordless Desktop */ | ||
430 | if (field->application != HID_GD_MOUSE) { | ||
431 | if (device->quirks & HID_QUIRK_LOGITECH_EXPANDED_KEYMAP) { | ||
432 | int hid = usage->hid & HID_USAGE; | ||
433 | if (hid < LOGITECH_EXPANDED_KEYMAP_SIZE && logitech_expanded_keymap[hid] != 0) | ||
434 | code = logitech_expanded_keymap[hid]; | ||
435 | } | ||
436 | } else { | ||
437 | if (device->quirks & HID_QUIRK_LOGITECH_IGNORE_DOUBLED_WHEEL) { | ||
438 | int hid = usage->hid & HID_USAGE; | ||
439 | if (hid == 7 || hid == 8) | ||
440 | goto ignore; | ||
441 | } | ||
442 | } | 215 | } |
216 | } | ||
443 | 217 | ||
444 | map_key(code); | 218 | map_key(code); |
445 | break; | 219 | break; |
446 | 220 | ||
447 | 221 | case HID_UP_SIMULATION: | |
448 | case HID_UP_SIMULATION: | 222 | switch (usage->hid & 0xffff) { |
449 | 223 | case 0xba: map_abs(ABS_RUDDER); break; | |
450 | switch (usage->hid & 0xffff) { | 224 | case 0xbb: map_abs(ABS_THROTTLE); break; |
451 | case 0xba: map_abs(ABS_RUDDER); break; | 225 | case 0xc4: map_abs(ABS_GAS); break; |
452 | case 0xbb: map_abs(ABS_THROTTLE); break; | 226 | case 0xc5: map_abs(ABS_BRAKE); break; |
453 | case 0xc4: map_abs(ABS_GAS); break; | 227 | case 0xc8: map_abs(ABS_WHEEL); break; |
454 | case 0xc5: map_abs(ABS_BRAKE); break; | 228 | default: goto ignore; |
455 | case 0xc8: map_abs(ABS_WHEEL); break; | 229 | } |
456 | default: goto ignore; | 230 | break; |
231 | |||
232 | case HID_UP_GENDESK: | ||
233 | if ((usage->hid & 0xf0) == 0x80) { /* SystemControl */ | ||
234 | switch (usage->hid & 0xf) { | ||
235 | case 0x1: map_key_clear(KEY_POWER); break; | ||
236 | case 0x2: map_key_clear(KEY_SLEEP); break; | ||
237 | case 0x3: map_key_clear(KEY_WAKEUP); break; | ||
238 | default: goto unknown; | ||
457 | } | 239 | } |
458 | break; | 240 | break; |
241 | } | ||
459 | 242 | ||
460 | case HID_UP_GENDESK: | 243 | if ((usage->hid & 0xf0) == 0x90) { /* D-pad */ |
461 | |||
462 | if ((usage->hid & 0xf0) == 0x80) { /* SystemControl */ | ||
463 | switch (usage->hid & 0xf) { | ||
464 | case 0x1: map_key_clear(KEY_POWER); break; | ||
465 | case 0x2: map_key_clear(KEY_SLEEP); break; | ||
466 | case 0x3: map_key_clear(KEY_WAKEUP); break; | ||
467 | default: goto unknown; | ||
468 | } | ||
469 | break; | ||
470 | } | ||
471 | |||
472 | if ((usage->hid & 0xf0) == 0x90) { /* D-pad */ | ||
473 | switch (usage->hid) { | ||
474 | case HID_GD_UP: usage->hat_dir = 1; break; | ||
475 | case HID_GD_DOWN: usage->hat_dir = 5; break; | ||
476 | case HID_GD_RIGHT: usage->hat_dir = 3; break; | ||
477 | case HID_GD_LEFT: usage->hat_dir = 7; break; | ||
478 | default: goto unknown; | ||
479 | } | ||
480 | if (field->dpad) { | ||
481 | map_abs(field->dpad); | ||
482 | goto ignore; | ||
483 | } | ||
484 | map_abs(ABS_HAT0X); | ||
485 | break; | ||
486 | } | ||
487 | |||
488 | switch (usage->hid) { | 244 | switch (usage->hid) { |
489 | 245 | case HID_GD_UP: usage->hat_dir = 1; break; | |
490 | /* These usage IDs map directly to the usage codes. */ | 246 | case HID_GD_DOWN: usage->hat_dir = 5; break; |
491 | case HID_GD_X: case HID_GD_Y: case HID_GD_Z: | 247 | case HID_GD_RIGHT: usage->hat_dir = 3; break; |
492 | case HID_GD_RX: case HID_GD_RY: case HID_GD_RZ: | 248 | case HID_GD_LEFT: usage->hat_dir = 7; break; |
493 | case HID_GD_SLIDER: case HID_GD_DIAL: case HID_GD_WHEEL: | 249 | default: goto unknown; |
494 | if (field->flags & HID_MAIN_ITEM_RELATIVE) | ||
495 | map_rel(usage->hid & 0xf); | ||
496 | else | ||
497 | map_abs(usage->hid & 0xf); | ||
498 | break; | ||
499 | |||
500 | case HID_GD_HATSWITCH: | ||
501 | usage->hat_min = field->logical_minimum; | ||
502 | usage->hat_max = field->logical_maximum; | ||
503 | map_abs(ABS_HAT0X); | ||
504 | break; | ||
505 | |||
506 | case HID_GD_START: map_key_clear(BTN_START); break; | ||
507 | case HID_GD_SELECT: map_key_clear(BTN_SELECT); break; | ||
508 | |||
509 | default: goto unknown; | ||
510 | } | 250 | } |
511 | 251 | if (field->dpad) { | |
512 | break; | 252 | map_abs(field->dpad); |
513 | 253 | goto ignore; | |
514 | case HID_UP_LED: | ||
515 | |||
516 | switch (usage->hid & 0xffff) { /* HID-Value: */ | ||
517 | case 0x01: map_led (LED_NUML); break; /* "Num Lock" */ | ||
518 | case 0x02: map_led (LED_CAPSL); break; /* "Caps Lock" */ | ||
519 | case 0x03: map_led (LED_SCROLLL); break; /* "Scroll Lock" */ | ||
520 | case 0x04: map_led (LED_COMPOSE); break; /* "Compose" */ | ||
521 | case 0x05: map_led (LED_KANA); break; /* "Kana" */ | ||
522 | case 0x27: map_led (LED_SLEEP); break; /* "Stand-By" */ | ||
523 | case 0x4c: map_led (LED_SUSPEND); break; /* "System Suspend" */ | ||
524 | case 0x09: map_led (LED_MUTE); break; /* "Mute" */ | ||
525 | case 0x4b: map_led (LED_MISC); break; /* "Generic Indicator" */ | ||
526 | case 0x19: map_led (LED_MAIL); break; /* "Message Waiting" */ | ||
527 | case 0x4d: map_led (LED_CHARGING); break; /* "External Power Connected" */ | ||
528 | |||
529 | default: goto ignore; | ||
530 | } | 254 | } |
255 | map_abs(ABS_HAT0X); | ||
531 | break; | 256 | break; |
257 | } | ||
532 | 258 | ||
533 | case HID_UP_DIGITIZER: | 259 | switch (usage->hid) { |
534 | 260 | /* These usage IDs map directly to the usage codes. */ | |
535 | switch (usage->hid & 0xff) { | 261 | case HID_GD_X: case HID_GD_Y: case HID_GD_Z: |
536 | 262 | case HID_GD_RX: case HID_GD_RY: case HID_GD_RZ: | |
537 | case 0x30: /* TipPressure */ | 263 | case HID_GD_SLIDER: case HID_GD_DIAL: case HID_GD_WHEEL: |
538 | if (!test_bit(BTN_TOUCH, input->keybit)) { | 264 | if (field->flags & HID_MAIN_ITEM_RELATIVE) |
539 | device->quirks |= HID_QUIRK_NOTOUCH; | 265 | map_rel(usage->hid & 0xf); |
540 | set_bit(EV_KEY, input->evbit); | 266 | else |
541 | set_bit(BTN_TOUCH, input->keybit); | 267 | map_abs(usage->hid & 0xf); |
542 | } | 268 | break; |
543 | |||
544 | map_abs_clear(ABS_PRESSURE); | ||
545 | break; | ||
546 | |||
547 | case 0x32: /* InRange */ | ||
548 | switch (field->physical & 0xff) { | ||
549 | case 0x21: map_key(BTN_TOOL_MOUSE); break; | ||
550 | case 0x22: map_key(BTN_TOOL_FINGER); break; | ||
551 | default: map_key(BTN_TOOL_PEN); break; | ||
552 | } | ||
553 | break; | ||
554 | 269 | ||
555 | case 0x3c: /* Invert */ | 270 | case HID_GD_HATSWITCH: |
556 | map_key_clear(BTN_TOOL_RUBBER); | 271 | usage->hat_min = field->logical_minimum; |
557 | break; | 272 | usage->hat_max = field->logical_maximum; |
273 | map_abs(ABS_HAT0X); | ||
274 | break; | ||
558 | 275 | ||
559 | case 0x33: /* Touch */ | 276 | case HID_GD_START: map_key_clear(BTN_START); break; |
560 | case 0x42: /* TipSwitch */ | 277 | case HID_GD_SELECT: map_key_clear(BTN_SELECT); break; |
561 | case 0x43: /* TipSwitch2 */ | ||
562 | device->quirks &= ~HID_QUIRK_NOTOUCH; | ||
563 | map_key_clear(BTN_TOUCH); | ||
564 | break; | ||
565 | 278 | ||
566 | case 0x44: /* BarrelSwitch */ | 279 | default: goto unknown; |
567 | map_key_clear(BTN_STYLUS); | 280 | } |
568 | break; | ||
569 | 281 | ||
570 | default: goto unknown; | 282 | break; |
283 | |||
284 | case HID_UP_LED: | ||
285 | switch (usage->hid & 0xffff) { /* HID-Value: */ | ||
286 | case 0x01: map_led (LED_NUML); break; /* "Num Lock" */ | ||
287 | case 0x02: map_led (LED_CAPSL); break; /* "Caps Lock" */ | ||
288 | case 0x03: map_led (LED_SCROLLL); break; /* "Scroll Lock" */ | ||
289 | case 0x04: map_led (LED_COMPOSE); break; /* "Compose" */ | ||
290 | case 0x05: map_led (LED_KANA); break; /* "Kana" */ | ||
291 | case 0x27: map_led (LED_SLEEP); break; /* "Stand-By" */ | ||
292 | case 0x4c: map_led (LED_SUSPEND); break; /* "System Suspend" */ | ||
293 | case 0x09: map_led (LED_MUTE); break; /* "Mute" */ | ||
294 | case 0x4b: map_led (LED_MISC); break; /* "Generic Indicator" */ | ||
295 | case 0x19: map_led (LED_MAIL); break; /* "Message Waiting" */ | ||
296 | case 0x4d: map_led (LED_CHARGING); break; /* "External Power Connected" */ | ||
297 | |||
298 | default: goto ignore; | ||
299 | } | ||
300 | break; | ||
301 | |||
302 | case HID_UP_DIGITIZER: | ||
303 | switch (usage->hid & 0xff) { | ||
304 | case 0x30: /* TipPressure */ | ||
305 | if (!test_bit(BTN_TOUCH, input->keybit)) { | ||
306 | device->quirks |= HID_QUIRK_NOTOUCH; | ||
307 | set_bit(EV_KEY, input->evbit); | ||
308 | set_bit(BTN_TOUCH, input->keybit); | ||
571 | } | 309 | } |
310 | map_abs_clear(ABS_PRESSURE); | ||
572 | break; | 311 | break; |
573 | 312 | ||
574 | case HID_UP_CONSUMER: /* USB HUT v1.1, pages 56-62 */ | 313 | case 0x32: /* InRange */ |
575 | 314 | switch (field->physical & 0xff) { | |
576 | switch (usage->hid & HID_USAGE) { | 315 | case 0x21: map_key(BTN_TOOL_MOUSE); break; |
577 | case 0x000: goto ignore; | 316 | case 0x22: map_key(BTN_TOOL_FINGER); break; |
578 | case 0x034: map_key_clear(KEY_SLEEP); break; | 317 | default: map_key(BTN_TOOL_PEN); break; |
579 | case 0x036: map_key_clear(BTN_MISC); break; | ||
580 | |||
581 | case 0x040: map_key_clear(KEY_MENU); break; | ||
582 | case 0x045: map_key_clear(KEY_RADIO); break; | ||
583 | |||
584 | case 0x083: map_key_clear(KEY_LAST); break; | ||
585 | case 0x088: map_key_clear(KEY_PC); break; | ||
586 | case 0x089: map_key_clear(KEY_TV); break; | ||
587 | case 0x08a: map_key_clear(KEY_WWW); break; | ||
588 | case 0x08b: map_key_clear(KEY_DVD); break; | ||
589 | case 0x08c: map_key_clear(KEY_PHONE); break; | ||
590 | case 0x08d: map_key_clear(KEY_PROGRAM); break; | ||
591 | case 0x08e: map_key_clear(KEY_VIDEOPHONE); break; | ||
592 | case 0x08f: map_key_clear(KEY_GAMES); break; | ||
593 | case 0x090: map_key_clear(KEY_MEMO); break; | ||
594 | case 0x091: map_key_clear(KEY_CD); break; | ||
595 | case 0x092: map_key_clear(KEY_VCR); break; | ||
596 | case 0x093: map_key_clear(KEY_TUNER); break; | ||
597 | case 0x094: map_key_clear(KEY_EXIT); break; | ||
598 | case 0x095: map_key_clear(KEY_HELP); break; | ||
599 | case 0x096: map_key_clear(KEY_TAPE); break; | ||
600 | case 0x097: map_key_clear(KEY_TV2); break; | ||
601 | case 0x098: map_key_clear(KEY_SAT); break; | ||
602 | case 0x09a: map_key_clear(KEY_PVR); break; | ||
603 | |||
604 | case 0x09c: map_key_clear(KEY_CHANNELUP); break; | ||
605 | case 0x09d: map_key_clear(KEY_CHANNELDOWN); break; | ||
606 | case 0x0a0: map_key_clear(KEY_VCR2); break; | ||
607 | |||
608 | case 0x0b0: map_key_clear(KEY_PLAY); break; | ||
609 | case 0x0b1: map_key_clear(KEY_PAUSE); break; | ||
610 | case 0x0b2: map_key_clear(KEY_RECORD); break; | ||
611 | case 0x0b3: map_key_clear(KEY_FASTFORWARD); break; | ||
612 | case 0x0b4: map_key_clear(KEY_REWIND); break; | ||
613 | case 0x0b5: map_key_clear(KEY_NEXTSONG); break; | ||
614 | case 0x0b6: map_key_clear(KEY_PREVIOUSSONG); break; | ||
615 | case 0x0b7: map_key_clear(KEY_STOPCD); break; | ||
616 | case 0x0b8: map_key_clear(KEY_EJECTCD); break; | ||
617 | case 0x0bc: map_key_clear(KEY_MEDIA_REPEAT); break; | ||
618 | |||
619 | case 0x0cd: map_key_clear(KEY_PLAYPAUSE); break; | ||
620 | case 0x0e0: map_abs_clear(ABS_VOLUME); break; | ||
621 | case 0x0e2: map_key_clear(KEY_MUTE); break; | ||
622 | case 0x0e5: map_key_clear(KEY_BASSBOOST); break; | ||
623 | case 0x0e9: map_key_clear(KEY_VOLUMEUP); break; | ||
624 | case 0x0ea: map_key_clear(KEY_VOLUMEDOWN); break; | ||
625 | |||
626 | case 0x182: map_key_clear(KEY_BOOKMARKS); break; | ||
627 | case 0x183: map_key_clear(KEY_CONFIG); break; | ||
628 | case 0x184: map_key_clear(KEY_WORDPROCESSOR); break; | ||
629 | case 0x185: map_key_clear(KEY_EDITOR); break; | ||
630 | case 0x186: map_key_clear(KEY_SPREADSHEET); break; | ||
631 | case 0x187: map_key_clear(KEY_GRAPHICSEDITOR); break; | ||
632 | case 0x188: map_key_clear(KEY_PRESENTATION); break; | ||
633 | case 0x189: map_key_clear(KEY_DATABASE); break; | ||
634 | case 0x18a: map_key_clear(KEY_MAIL); break; | ||
635 | case 0x18b: map_key_clear(KEY_NEWS); break; | ||
636 | case 0x18c: map_key_clear(KEY_VOICEMAIL); break; | ||
637 | case 0x18d: map_key_clear(KEY_ADDRESSBOOK); break; | ||
638 | case 0x18e: map_key_clear(KEY_CALENDAR); break; | ||
639 | case 0x191: map_key_clear(KEY_FINANCE); break; | ||
640 | case 0x192: map_key_clear(KEY_CALC); break; | ||
641 | case 0x194: map_key_clear(KEY_FILE); break; | ||
642 | case 0x196: map_key_clear(KEY_WWW); break; | ||
643 | case 0x19c: map_key_clear(KEY_LOGOFF); break; | ||
644 | case 0x19e: map_key_clear(KEY_COFFEE); break; | ||
645 | case 0x1a6: map_key_clear(KEY_HELP); break; | ||
646 | case 0x1a7: map_key_clear(KEY_DOCUMENTS); break; | ||
647 | case 0x1ab: map_key_clear(KEY_SPELLCHECK); break; | ||
648 | case 0x1b6: map_key_clear(KEY_MEDIA); break; | ||
649 | case 0x1b7: map_key_clear(KEY_SOUND); break; | ||
650 | case 0x1bc: map_key_clear(KEY_MESSENGER); break; | ||
651 | case 0x1bd: map_key_clear(KEY_INFO); break; | ||
652 | case 0x201: map_key_clear(KEY_NEW); break; | ||
653 | case 0x202: map_key_clear(KEY_OPEN); break; | ||
654 | case 0x203: map_key_clear(KEY_CLOSE); break; | ||
655 | case 0x204: map_key_clear(KEY_EXIT); break; | ||
656 | case 0x207: map_key_clear(KEY_SAVE); break; | ||
657 | case 0x208: map_key_clear(KEY_PRINT); break; | ||
658 | case 0x209: map_key_clear(KEY_PROPS); break; | ||
659 | case 0x21a: map_key_clear(KEY_UNDO); break; | ||
660 | case 0x21b: map_key_clear(KEY_COPY); break; | ||
661 | case 0x21c: map_key_clear(KEY_CUT); break; | ||
662 | case 0x21d: map_key_clear(KEY_PASTE); break; | ||
663 | case 0x21f: map_key_clear(KEY_FIND); break; | ||
664 | case 0x221: map_key_clear(KEY_SEARCH); break; | ||
665 | case 0x222: map_key_clear(KEY_GOTO); break; | ||
666 | case 0x223: map_key_clear(KEY_HOMEPAGE); break; | ||
667 | case 0x224: map_key_clear(KEY_BACK); break; | ||
668 | case 0x225: map_key_clear(KEY_FORWARD); break; | ||
669 | case 0x226: map_key_clear(KEY_STOP); break; | ||
670 | case 0x227: map_key_clear(KEY_REFRESH); break; | ||
671 | case 0x22a: map_key_clear(KEY_BOOKMARKS); break; | ||
672 | case 0x22d: map_key_clear(KEY_ZOOMIN); break; | ||
673 | case 0x22e: map_key_clear(KEY_ZOOMOUT); break; | ||
674 | case 0x22f: map_key_clear(KEY_ZOOMRESET); break; | ||
675 | case 0x233: map_key_clear(KEY_SCROLLUP); break; | ||
676 | case 0x234: map_key_clear(KEY_SCROLLDOWN); break; | ||
677 | case 0x238: map_rel(REL_HWHEEL); break; | ||
678 | case 0x25f: map_key_clear(KEY_CANCEL); break; | ||
679 | case 0x279: map_key_clear(KEY_REDO); break; | ||
680 | |||
681 | case 0x289: map_key_clear(KEY_REPLY); break; | ||
682 | case 0x28b: map_key_clear(KEY_FORWARDMAIL); break; | ||
683 | case 0x28c: map_key_clear(KEY_SEND); break; | ||
684 | |||
685 | default: goto ignore; | ||
686 | } | 318 | } |
687 | break; | 319 | break; |
688 | 320 | ||
689 | case HID_UP_HPVENDOR: /* Reported on a Dutch layout HP5308 */ | 321 | case 0x3c: /* Invert */ |
690 | 322 | map_key_clear(BTN_TOOL_RUBBER); | |
691 | set_bit(EV_REP, input->evbit); | ||
692 | switch (usage->hid & HID_USAGE) { | ||
693 | case 0x021: map_key_clear(KEY_PRINT); break; | ||
694 | case 0x070: map_key_clear(KEY_HP); break; | ||
695 | case 0x071: map_key_clear(KEY_CAMERA); break; | ||
696 | case 0x072: map_key_clear(KEY_SOUND); break; | ||
697 | case 0x073: map_key_clear(KEY_QUESTION); break; | ||
698 | case 0x080: map_key_clear(KEY_EMAIL); break; | ||
699 | case 0x081: map_key_clear(KEY_CHAT); break; | ||
700 | case 0x082: map_key_clear(KEY_SEARCH); break; | ||
701 | case 0x083: map_key_clear(KEY_CONNECT); break; | ||
702 | case 0x084: map_key_clear(KEY_FINANCE); break; | ||
703 | case 0x085: map_key_clear(KEY_SPORT); break; | ||
704 | case 0x086: map_key_clear(KEY_SHOP); break; | ||
705 | default: goto ignore; | ||
706 | } | ||
707 | break; | 323 | break; |
708 | 324 | ||
709 | case HID_UP_MSVENDOR: | 325 | case 0x33: /* Touch */ |
710 | 326 | case 0x42: /* TipSwitch */ | |
711 | goto ignore; | 327 | case 0x43: /* TipSwitch2 */ |
712 | 328 | device->quirks &= ~HID_QUIRK_NOTOUCH; | |
713 | case HID_UP_CUSTOM: /* Reported on Logitech and Apple USB keyboards */ | 329 | map_key_clear(BTN_TOUCH); |
714 | 330 | break; | |
715 | set_bit(EV_REP, input->evbit); | ||
716 | switch(usage->hid & HID_USAGE) { | ||
717 | case 0x003: | ||
718 | /* The fn key on Apple USB keyboards */ | ||
719 | map_key_clear(KEY_FN); | ||
720 | hidinput_apple_setup(input); | ||
721 | break; | ||
722 | 331 | ||
723 | default: goto ignore; | 332 | case 0x44: /* BarrelSwitch */ |
724 | } | 333 | map_key_clear(BTN_STYLUS); |
725 | break; | 334 | break; |
726 | 335 | ||
727 | case HID_UP_LOGIVENDOR: | 336 | default: goto unknown; |
337 | } | ||
338 | break; | ||
339 | |||
340 | case HID_UP_CONSUMER: /* USB HUT v1.1, pages 56-62 */ | ||
341 | switch (usage->hid & HID_USAGE) { | ||
342 | case 0x000: goto ignore; | ||
343 | case 0x034: map_key_clear(KEY_SLEEP); break; | ||
344 | case 0x036: map_key_clear(BTN_MISC); break; | ||
345 | |||
346 | case 0x040: map_key_clear(KEY_MENU); break; | ||
347 | case 0x045: map_key_clear(KEY_RADIO); break; | ||
348 | |||
349 | case 0x083: map_key_clear(KEY_LAST); break; | ||
350 | case 0x088: map_key_clear(KEY_PC); break; | ||
351 | case 0x089: map_key_clear(KEY_TV); break; | ||
352 | case 0x08a: map_key_clear(KEY_WWW); break; | ||
353 | case 0x08b: map_key_clear(KEY_DVD); break; | ||
354 | case 0x08c: map_key_clear(KEY_PHONE); break; | ||
355 | case 0x08d: map_key_clear(KEY_PROGRAM); break; | ||
356 | case 0x08e: map_key_clear(KEY_VIDEOPHONE); break; | ||
357 | case 0x08f: map_key_clear(KEY_GAMES); break; | ||
358 | case 0x090: map_key_clear(KEY_MEMO); break; | ||
359 | case 0x091: map_key_clear(KEY_CD); break; | ||
360 | case 0x092: map_key_clear(KEY_VCR); break; | ||
361 | case 0x093: map_key_clear(KEY_TUNER); break; | ||
362 | case 0x094: map_key_clear(KEY_EXIT); break; | ||
363 | case 0x095: map_key_clear(KEY_HELP); break; | ||
364 | case 0x096: map_key_clear(KEY_TAPE); break; | ||
365 | case 0x097: map_key_clear(KEY_TV2); break; | ||
366 | case 0x098: map_key_clear(KEY_SAT); break; | ||
367 | case 0x09a: map_key_clear(KEY_PVR); break; | ||
368 | |||
369 | case 0x09c: map_key_clear(KEY_CHANNELUP); break; | ||
370 | case 0x09d: map_key_clear(KEY_CHANNELDOWN); break; | ||
371 | case 0x0a0: map_key_clear(KEY_VCR2); break; | ||
372 | |||
373 | case 0x0b0: map_key_clear(KEY_PLAY); break; | ||
374 | case 0x0b1: map_key_clear(KEY_PAUSE); break; | ||
375 | case 0x0b2: map_key_clear(KEY_RECORD); break; | ||
376 | case 0x0b3: map_key_clear(KEY_FASTFORWARD); break; | ||
377 | case 0x0b4: map_key_clear(KEY_REWIND); break; | ||
378 | case 0x0b5: map_key_clear(KEY_NEXTSONG); break; | ||
379 | case 0x0b6: map_key_clear(KEY_PREVIOUSSONG); break; | ||
380 | case 0x0b7: map_key_clear(KEY_STOPCD); break; | ||
381 | case 0x0b8: map_key_clear(KEY_EJECTCD); break; | ||
382 | case 0x0bc: map_key_clear(KEY_MEDIA_REPEAT); break; | ||
383 | |||
384 | case 0x0cd: map_key_clear(KEY_PLAYPAUSE); break; | ||
385 | case 0x0e0: map_abs_clear(ABS_VOLUME); break; | ||
386 | case 0x0e2: map_key_clear(KEY_MUTE); break; | ||
387 | case 0x0e5: map_key_clear(KEY_BASSBOOST); break; | ||
388 | case 0x0e9: map_key_clear(KEY_VOLUMEUP); break; | ||
389 | case 0x0ea: map_key_clear(KEY_VOLUMEDOWN); break; | ||
390 | |||
391 | case 0x182: map_key_clear(KEY_BOOKMARKS); break; | ||
392 | case 0x183: map_key_clear(KEY_CONFIG); break; | ||
393 | case 0x184: map_key_clear(KEY_WORDPROCESSOR); break; | ||
394 | case 0x185: map_key_clear(KEY_EDITOR); break; | ||
395 | case 0x186: map_key_clear(KEY_SPREADSHEET); break; | ||
396 | case 0x187: map_key_clear(KEY_GRAPHICSEDITOR); break; | ||
397 | case 0x188: map_key_clear(KEY_PRESENTATION); break; | ||
398 | case 0x189: map_key_clear(KEY_DATABASE); break; | ||
399 | case 0x18a: map_key_clear(KEY_MAIL); break; | ||
400 | case 0x18b: map_key_clear(KEY_NEWS); break; | ||
401 | case 0x18c: map_key_clear(KEY_VOICEMAIL); break; | ||
402 | case 0x18d: map_key_clear(KEY_ADDRESSBOOK); break; | ||
403 | case 0x18e: map_key_clear(KEY_CALENDAR); break; | ||
404 | case 0x191: map_key_clear(KEY_FINANCE); break; | ||
405 | case 0x192: map_key_clear(KEY_CALC); break; | ||
406 | case 0x194: map_key_clear(KEY_FILE); break; | ||
407 | case 0x196: map_key_clear(KEY_WWW); break; | ||
408 | case 0x19c: map_key_clear(KEY_LOGOFF); break; | ||
409 | case 0x19e: map_key_clear(KEY_COFFEE); break; | ||
410 | case 0x1a6: map_key_clear(KEY_HELP); break; | ||
411 | case 0x1a7: map_key_clear(KEY_DOCUMENTS); break; | ||
412 | case 0x1ab: map_key_clear(KEY_SPELLCHECK); break; | ||
413 | case 0x1b6: map_key_clear(KEY_MEDIA); break; | ||
414 | case 0x1b7: map_key_clear(KEY_SOUND); break; | ||
415 | case 0x1bc: map_key_clear(KEY_MESSENGER); break; | ||
416 | case 0x1bd: map_key_clear(KEY_INFO); break; | ||
417 | case 0x201: map_key_clear(KEY_NEW); break; | ||
418 | case 0x202: map_key_clear(KEY_OPEN); break; | ||
419 | case 0x203: map_key_clear(KEY_CLOSE); break; | ||
420 | case 0x204: map_key_clear(KEY_EXIT); break; | ||
421 | case 0x207: map_key_clear(KEY_SAVE); break; | ||
422 | case 0x208: map_key_clear(KEY_PRINT); break; | ||
423 | case 0x209: map_key_clear(KEY_PROPS); break; | ||
424 | case 0x21a: map_key_clear(KEY_UNDO); break; | ||
425 | case 0x21b: map_key_clear(KEY_COPY); break; | ||
426 | case 0x21c: map_key_clear(KEY_CUT); break; | ||
427 | case 0x21d: map_key_clear(KEY_PASTE); break; | ||
428 | case 0x21f: map_key_clear(KEY_FIND); break; | ||
429 | case 0x221: map_key_clear(KEY_SEARCH); break; | ||
430 | case 0x222: map_key_clear(KEY_GOTO); break; | ||
431 | case 0x223: map_key_clear(KEY_HOMEPAGE); break; | ||
432 | case 0x224: map_key_clear(KEY_BACK); break; | ||
433 | case 0x225: map_key_clear(KEY_FORWARD); break; | ||
434 | case 0x226: map_key_clear(KEY_STOP); break; | ||
435 | case 0x227: map_key_clear(KEY_REFRESH); break; | ||
436 | case 0x22a: map_key_clear(KEY_BOOKMARKS); break; | ||
437 | case 0x22d: map_key_clear(KEY_ZOOMIN); break; | ||
438 | case 0x22e: map_key_clear(KEY_ZOOMOUT); break; | ||
439 | case 0x22f: map_key_clear(KEY_ZOOMRESET); break; | ||
440 | case 0x233: map_key_clear(KEY_SCROLLUP); break; | ||
441 | case 0x234: map_key_clear(KEY_SCROLLDOWN); break; | ||
442 | case 0x238: map_rel(REL_HWHEEL); break; | ||
443 | case 0x25f: map_key_clear(KEY_CANCEL); break; | ||
444 | case 0x279: map_key_clear(KEY_REDO); break; | ||
445 | |||
446 | case 0x289: map_key_clear(KEY_REPLY); break; | ||
447 | case 0x28b: map_key_clear(KEY_FORWARDMAIL); break; | ||
448 | case 0x28c: map_key_clear(KEY_SEND); break; | ||
449 | |||
450 | default: goto ignore; | ||
451 | } | ||
452 | break; | ||
453 | |||
454 | case HID_UP_HPVENDOR: /* Reported on a Dutch layout HP5308 */ | ||
455 | set_bit(EV_REP, input->evbit); | ||
456 | switch (usage->hid & HID_USAGE) { | ||
457 | case 0x021: map_key_clear(KEY_PRINT); break; | ||
458 | case 0x070: map_key_clear(KEY_HP); break; | ||
459 | case 0x071: map_key_clear(KEY_CAMERA); break; | ||
460 | case 0x072: map_key_clear(KEY_SOUND); break; | ||
461 | case 0x073: map_key_clear(KEY_QUESTION); break; | ||
462 | case 0x080: map_key_clear(KEY_EMAIL); break; | ||
463 | case 0x081: map_key_clear(KEY_CHAT); break; | ||
464 | case 0x082: map_key_clear(KEY_SEARCH); break; | ||
465 | case 0x083: map_key_clear(KEY_CONNECT); break; | ||
466 | case 0x084: map_key_clear(KEY_FINANCE); break; | ||
467 | case 0x085: map_key_clear(KEY_SPORT); break; | ||
468 | case 0x086: map_key_clear(KEY_SHOP); break; | ||
469 | default: goto ignore; | ||
470 | } | ||
471 | break; | ||
728 | 472 | ||
729 | goto ignore; | 473 | case HID_UP_MSVENDOR: |
730 | 474 | goto ignore; | |
731 | case HID_UP_PID: | ||
732 | 475 | ||
733 | switch(usage->hid & HID_USAGE) { | 476 | case HID_UP_CUSTOM: /* Reported on Logitech and Apple USB keyboards */ |
734 | case 0xa4: map_key_clear(BTN_DEAD); break; | 477 | set_bit(EV_REP, input->evbit); |
735 | default: goto ignore; | 478 | goto ignore; |
736 | } | ||
737 | break; | ||
738 | 479 | ||
739 | default: | 480 | case HID_UP_LOGIVENDOR: |
740 | unknown: | 481 | goto ignore; |
741 | if (field->report_size == 1) { | 482 | |
742 | if (field->report->type == HID_OUTPUT_REPORT) { | 483 | case HID_UP_PID: |
743 | map_led(LED_MISC); | 484 | switch (usage->hid & HID_USAGE) { |
744 | break; | 485 | case 0xa4: map_key_clear(BTN_DEAD); break; |
745 | } | 486 | default: goto ignore; |
746 | map_key(BTN_MISC); | 487 | } |
747 | break; | 488 | break; |
748 | } | 489 | |
749 | if (field->flags & HID_MAIN_ITEM_RELATIVE) { | 490 | default: |
750 | map_rel(REL_MISC); | 491 | unknown: |
492 | if (field->report_size == 1) { | ||
493 | if (field->report->type == HID_OUTPUT_REPORT) { | ||
494 | map_led(LED_MISC); | ||
751 | break; | 495 | break; |
752 | } | 496 | } |
753 | map_abs(ABS_MISC); | 497 | map_key(BTN_MISC); |
498 | break; | ||
499 | } | ||
500 | if (field->flags & HID_MAIN_ITEM_RELATIVE) { | ||
501 | map_rel(REL_MISC); | ||
754 | break; | 502 | break; |
503 | } | ||
504 | map_abs(ABS_MISC); | ||
505 | break; | ||
755 | } | 506 | } |
756 | 507 | ||
757 | mapped: | 508 | mapped: |
758 | if (device->quirks & HID_QUIRK_MIGHTYMOUSE) { | 509 | if (device->driver->input_mapped && device->driver->input_mapped(device, |
759 | if (usage->hid == HID_GD_Z) | 510 | hidinput, field, usage, &bit, &max) < 0) |
760 | map_rel(REL_HWHEEL); | ||
761 | else if (usage->code == BTN_1) | ||
762 | map_key(BTN_2); | ||
763 | else if (usage->code == BTN_2) | ||
764 | map_key(BTN_1); | ||
765 | } | ||
766 | |||
767 | if ((device->quirks & (HID_QUIRK_2WHEEL_MOUSE_HACK_7 | HID_QUIRK_2WHEEL_MOUSE_HACK_5 | | ||
768 | HID_QUIRK_2WHEEL_MOUSE_HACK_B8)) && (usage->type == EV_REL) && | ||
769 | (usage->code == REL_WHEEL)) | ||
770 | set_bit(REL_HWHEEL, bit); | ||
771 | |||
772 | if (((device->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_5) && (usage->hid == 0x00090005)) | ||
773 | || ((device->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_7) && (usage->hid == 0x00090007))) | ||
774 | goto ignore; | 511 | goto ignore; |
775 | 512 | ||
776 | if ((device->quirks & HID_QUIRK_BAD_RELATIVE_KEYS) && | ||
777 | usage->type == EV_KEY && (field->flags & HID_MAIN_ITEM_RELATIVE)) | ||
778 | field->flags &= ~HID_MAIN_ITEM_RELATIVE; | ||
779 | |||
780 | set_bit(usage->type, input->evbit); | 513 | set_bit(usage->type, input->evbit); |
781 | 514 | ||
782 | if (device->quirks & HID_QUIRK_DUPLICATE_USAGES && | ||
783 | (usage->type == EV_KEY || | ||
784 | usage->type == EV_REL || | ||
785 | usage->type == EV_ABS)) | ||
786 | clear_bit(usage->code, bit); | ||
787 | |||
788 | while (usage->code <= max && test_and_set_bit(usage->code, bit)) | 515 | while (usage->code <= max && test_and_set_bit(usage->code, bit)) |
789 | usage->code = find_next_zero_bit(bit, max + 1, usage->code); | 516 | usage->code = find_next_zero_bit(bit, max + 1, usage->code); |
790 | 517 | ||
@@ -858,10 +585,6 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct | |||
858 | if (!usage->type) | 585 | if (!usage->type) |
859 | return; | 586 | return; |
860 | 587 | ||
861 | /* handle input events for quirky devices */ | ||
862 | if (hidinput_event_quirks(hid, field, usage, value)) | ||
863 | return; | ||
864 | |||
865 | if (usage->hat_min < usage->hat_max || usage->hat_dir) { | 588 | if (usage->hat_min < usage->hat_max || usage->hat_dir) { |
866 | int hat_dir = usage->hat_dir; | 589 | int hat_dir = usage->hat_dir; |
867 | if (!hat_dir) | 590 | if (!hat_dir) |
@@ -961,14 +684,14 @@ static int hidinput_open(struct input_dev *dev) | |||
961 | { | 684 | { |
962 | struct hid_device *hid = input_get_drvdata(dev); | 685 | struct hid_device *hid = input_get_drvdata(dev); |
963 | 686 | ||
964 | return hid->hid_open(hid); | 687 | return hid->ll_driver->open(hid); |
965 | } | 688 | } |
966 | 689 | ||
967 | static void hidinput_close(struct input_dev *dev) | 690 | static void hidinput_close(struct input_dev *dev) |
968 | { | 691 | { |
969 | struct hid_device *hid = input_get_drvdata(dev); | 692 | struct hid_device *hid = input_get_drvdata(dev); |
970 | 693 | ||
971 | hid->hid_close(hid); | 694 | hid->ll_driver->close(hid); |
972 | } | 695 | } |
973 | 696 | ||
974 | /* | 697 | /* |
@@ -977,7 +700,7 @@ static void hidinput_close(struct input_dev *dev) | |||
977 | * Read all reports and initialize the absolute field values. | 700 | * Read all reports and initialize the absolute field values. |
978 | */ | 701 | */ |
979 | 702 | ||
980 | int hidinput_connect(struct hid_device *hid) | 703 | int hidinput_connect(struct hid_device *hid, unsigned int force) |
981 | { | 704 | { |
982 | struct hid_report *report; | 705 | struct hid_report *report; |
983 | struct hid_input *hidinput = NULL; | 706 | struct hid_input *hidinput = NULL; |
@@ -985,19 +708,20 @@ int hidinput_connect(struct hid_device *hid) | |||
985 | int i, j, k; | 708 | int i, j, k; |
986 | int max_report_type = HID_OUTPUT_REPORT; | 709 | int max_report_type = HID_OUTPUT_REPORT; |
987 | 710 | ||
988 | if (hid->quirks & HID_QUIRK_IGNORE_HIDINPUT) | ||
989 | return -1; | ||
990 | |||
991 | INIT_LIST_HEAD(&hid->inputs); | 711 | INIT_LIST_HEAD(&hid->inputs); |
992 | 712 | ||
993 | for (i = 0; i < hid->maxcollection; i++) | 713 | if (!force) { |
994 | if (hid->collection[i].type == HID_COLLECTION_APPLICATION || | 714 | for (i = 0; i < hid->maxcollection; i++) { |
995 | hid->collection[i].type == HID_COLLECTION_PHYSICAL) | 715 | struct hid_collection *col = &hid->collection[i]; |
996 | if (IS_INPUT_APPLICATION(hid->collection[i].usage)) | 716 | if (col->type == HID_COLLECTION_APPLICATION || |
997 | break; | 717 | col->type == HID_COLLECTION_PHYSICAL) |
718 | if (IS_INPUT_APPLICATION(col->usage)) | ||
719 | break; | ||
720 | } | ||
998 | 721 | ||
999 | if (i == hid->maxcollection && (hid->quirks & HID_QUIRK_HIDINPUT) == 0) | 722 | if (i == hid->maxcollection) |
1000 | return -1; | 723 | return -1; |
724 | } | ||
1001 | 725 | ||
1002 | if (hid->quirks & HID_QUIRK_SKIP_OUTPUT_REPORTS) | 726 | if (hid->quirks & HID_QUIRK_SKIP_OUTPUT_REPORTS) |
1003 | max_report_type = HID_INPUT_REPORT; | 727 | max_report_type = HID_INPUT_REPORT; |
@@ -1019,7 +743,8 @@ int hidinput_connect(struct hid_device *hid) | |||
1019 | } | 743 | } |
1020 | 744 | ||
1021 | input_set_drvdata(input_dev, hid); | 745 | input_set_drvdata(input_dev, hid); |
1022 | input_dev->event = hid->hidinput_input_event; | 746 | input_dev->event = |
747 | hid->ll_driver->hidinput_input_event; | ||
1023 | input_dev->open = hidinput_open; | 748 | input_dev->open = hidinput_open; |
1024 | input_dev->close = hidinput_close; | 749 | input_dev->close = hidinput_close; |
1025 | input_dev->setkeycode = hidinput_setkeycode; | 750 | input_dev->setkeycode = hidinput_setkeycode; |
@@ -1032,7 +757,7 @@ int hidinput_connect(struct hid_device *hid) | |||
1032 | input_dev->id.vendor = hid->vendor; | 757 | input_dev->id.vendor = hid->vendor; |
1033 | input_dev->id.product = hid->product; | 758 | input_dev->id.product = hid->product; |
1034 | input_dev->id.version = hid->version; | 759 | input_dev->id.version = hid->version; |
1035 | input_dev->dev.parent = hid->dev; | 760 | input_dev->dev.parent = hid->dev.parent; |
1036 | hidinput->input = input_dev; | 761 | hidinput->input = input_dev; |
1037 | list_add_tail(&hidinput->list, &hid->inputs); | 762 | list_add_tail(&hidinput->list, &hid->inputs); |
1038 | } | 763 | } |
diff --git a/drivers/hid/hid-lg.c b/drivers/hid/hid-lg.c new file mode 100644 index 000000000000..406d8c82abf1 --- /dev/null +++ b/drivers/hid/hid-lg.c | |||
@@ -0,0 +1,342 @@ | |||
1 | /* | ||
2 | * HID driver for some logitech "special" devices | ||
3 | * | ||
4 | * Copyright (c) 1999 Andreas Gal | ||
5 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> | ||
6 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc | ||
7 | * Copyright (c) 2006-2007 Jiri Kosina | ||
8 | * Copyright (c) 2007 Paul Walmsley | ||
9 | * Copyright (c) 2008 Jiri Slaby | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * This program is free software; you can redistribute it and/or modify it | ||
14 | * under the terms of the GNU General Public License as published by the Free | ||
15 | * Software Foundation; either version 2 of the License, or (at your option) | ||
16 | * any later version. | ||
17 | */ | ||
18 | |||
19 | #include <linux/device.h> | ||
20 | #include <linux/hid.h> | ||
21 | #include <linux/module.h> | ||
22 | |||
23 | #include "hid-ids.h" | ||
24 | #include "hid-lg.h" | ||
25 | |||
26 | #define LG_RDESC 0x001 | ||
27 | #define LG_BAD_RELATIVE_KEYS 0x002 | ||
28 | #define LG_DUPLICATE_USAGES 0x004 | ||
29 | #define LG_RESET_LEDS 0x008 | ||
30 | #define LG_EXPANDED_KEYMAP 0x010 | ||
31 | #define LG_IGNORE_DOUBLED_WHEEL 0x020 | ||
32 | #define LG_WIRELESS 0x040 | ||
33 | #define LG_INVERT_HWHEEL 0x080 | ||
34 | #define LG_NOGET 0x100 | ||
35 | #define LG_FF 0x200 | ||
36 | #define LG_FF2 0x400 | ||
37 | |||
38 | /* | ||
39 | * Certain Logitech keyboards send in report #3 keys which are far | ||
40 | * above the logical maximum described in descriptor. This extends | ||
41 | * the original value of 0x28c of logical maximum to 0x104d | ||
42 | */ | ||
43 | static void lg_report_fixup(struct hid_device *hdev, __u8 *rdesc, | ||
44 | unsigned int rsize) | ||
45 | { | ||
46 | unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); | ||
47 | |||
48 | if ((quirks & LG_RDESC) && rsize >= 90 && rdesc[83] == 0x26 && | ||
49 | rdesc[84] == 0x8c && rdesc[85] == 0x02) { | ||
50 | dev_info(&hdev->dev, "fixing up Logitech keyboard report " | ||
51 | "descriptor\n"); | ||
52 | rdesc[84] = rdesc[89] = 0x4d; | ||
53 | rdesc[85] = rdesc[90] = 0x10; | ||
54 | } | ||
55 | } | ||
56 | |||
57 | #define lg_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \ | ||
58 | EV_KEY, (c)) | ||
59 | |||
60 | static int lg_ultrax_remote_mapping(struct hid_input *hi, | ||
61 | struct hid_usage *usage, unsigned long **bit, int *max) | ||
62 | { | ||
63 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR) | ||
64 | return 0; | ||
65 | |||
66 | set_bit(EV_REP, hi->input->evbit); | ||
67 | switch (usage->hid & HID_USAGE) { | ||
68 | /* Reported on Logitech Ultra X Media Remote */ | ||
69 | case 0x004: lg_map_key_clear(KEY_AGAIN); break; | ||
70 | case 0x00d: lg_map_key_clear(KEY_HOME); break; | ||
71 | case 0x024: lg_map_key_clear(KEY_SHUFFLE); break; | ||
72 | case 0x025: lg_map_key_clear(KEY_TV); break; | ||
73 | case 0x026: lg_map_key_clear(KEY_MENU); break; | ||
74 | case 0x031: lg_map_key_clear(KEY_AUDIO); break; | ||
75 | case 0x032: lg_map_key_clear(KEY_TEXT); break; | ||
76 | case 0x033: lg_map_key_clear(KEY_LAST); break; | ||
77 | case 0x047: lg_map_key_clear(KEY_MP3); break; | ||
78 | case 0x048: lg_map_key_clear(KEY_DVD); break; | ||
79 | case 0x049: lg_map_key_clear(KEY_MEDIA); break; | ||
80 | case 0x04a: lg_map_key_clear(KEY_VIDEO); break; | ||
81 | case 0x04b: lg_map_key_clear(KEY_ANGLE); break; | ||
82 | case 0x04c: lg_map_key_clear(KEY_LANGUAGE); break; | ||
83 | case 0x04d: lg_map_key_clear(KEY_SUBTITLE); break; | ||
84 | case 0x051: lg_map_key_clear(KEY_RED); break; | ||
85 | case 0x052: lg_map_key_clear(KEY_CLOSE); break; | ||
86 | |||
87 | default: | ||
88 | return 0; | ||
89 | } | ||
90 | return 1; | ||
91 | } | ||
92 | |||
93 | static int lg_wireless_mapping(struct hid_input *hi, struct hid_usage *usage, | ||
94 | unsigned long **bit, int *max) | ||
95 | { | ||
96 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER) | ||
97 | return 0; | ||
98 | |||
99 | switch (usage->hid & HID_USAGE) { | ||
100 | case 0x1001: lg_map_key_clear(KEY_MESSENGER); break; | ||
101 | case 0x1003: lg_map_key_clear(KEY_SOUND); break; | ||
102 | case 0x1004: lg_map_key_clear(KEY_VIDEO); break; | ||
103 | case 0x1005: lg_map_key_clear(KEY_AUDIO); break; | ||
104 | case 0x100a: lg_map_key_clear(KEY_DOCUMENTS); break; | ||
105 | case 0x1011: lg_map_key_clear(KEY_PREVIOUSSONG); break; | ||
106 | case 0x1012: lg_map_key_clear(KEY_NEXTSONG); break; | ||
107 | case 0x1013: lg_map_key_clear(KEY_CAMERA); break; | ||
108 | case 0x1014: lg_map_key_clear(KEY_MESSENGER); break; | ||
109 | case 0x1015: lg_map_key_clear(KEY_RECORD); break; | ||
110 | case 0x1016: lg_map_key_clear(KEY_PLAYER); break; | ||
111 | case 0x1017: lg_map_key_clear(KEY_EJECTCD); break; | ||
112 | case 0x1018: lg_map_key_clear(KEY_MEDIA); break; | ||
113 | case 0x1019: lg_map_key_clear(KEY_PROG1); break; | ||
114 | case 0x101a: lg_map_key_clear(KEY_PROG2); break; | ||
115 | case 0x101b: lg_map_key_clear(KEY_PROG3); break; | ||
116 | case 0x101f: lg_map_key_clear(KEY_ZOOMIN); break; | ||
117 | case 0x1020: lg_map_key_clear(KEY_ZOOMOUT); break; | ||
118 | case 0x1021: lg_map_key_clear(KEY_ZOOMRESET); break; | ||
119 | case 0x1023: lg_map_key_clear(KEY_CLOSE); break; | ||
120 | case 0x1027: lg_map_key_clear(KEY_MENU); break; | ||
121 | /* this one is marked as 'Rotate' */ | ||
122 | case 0x1028: lg_map_key_clear(KEY_ANGLE); break; | ||
123 | case 0x1029: lg_map_key_clear(KEY_SHUFFLE); break; | ||
124 | case 0x102a: lg_map_key_clear(KEY_BACK); break; | ||
125 | case 0x102b: lg_map_key_clear(KEY_CYCLEWINDOWS); break; | ||
126 | case 0x1041: lg_map_key_clear(KEY_BATTERY); break; | ||
127 | case 0x1042: lg_map_key_clear(KEY_WORDPROCESSOR); break; | ||
128 | case 0x1043: lg_map_key_clear(KEY_SPREADSHEET); break; | ||
129 | case 0x1044: lg_map_key_clear(KEY_PRESENTATION); break; | ||
130 | case 0x1045: lg_map_key_clear(KEY_UNDO); break; | ||
131 | case 0x1046: lg_map_key_clear(KEY_REDO); break; | ||
132 | case 0x1047: lg_map_key_clear(KEY_PRINT); break; | ||
133 | case 0x1048: lg_map_key_clear(KEY_SAVE); break; | ||
134 | case 0x1049: lg_map_key_clear(KEY_PROG1); break; | ||
135 | case 0x104a: lg_map_key_clear(KEY_PROG2); break; | ||
136 | case 0x104b: lg_map_key_clear(KEY_PROG3); break; | ||
137 | case 0x104c: lg_map_key_clear(KEY_PROG4); break; | ||
138 | |||
139 | default: | ||
140 | return 0; | ||
141 | } | ||
142 | return 1; | ||
143 | } | ||
144 | |||
145 | static int lg_input_mapping(struct hid_device *hdev, struct hid_input *hi, | ||
146 | struct hid_field *field, struct hid_usage *usage, | ||
147 | unsigned long **bit, int *max) | ||
148 | { | ||
149 | /* extended mapping for certain Logitech hardware (Logitech cordless | ||
150 | desktop LX500) */ | ||
151 | static const u8 e_keymap[] = { | ||
152 | 0,216, 0,213,175,156, 0, 0, 0, 0, | ||
153 | 144, 0, 0, 0, 0, 0, 0, 0, 0,212, | ||
154 | 174,167,152,161,112, 0, 0, 0,154, 0, | ||
155 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
156 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
157 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
158 | 0, 0, 0, 0, 0,183,184,185,186,187, | ||
159 | 188,189,190,191,192,193,194, 0, 0, 0 | ||
160 | }; | ||
161 | unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); | ||
162 | unsigned int hid = usage->hid; | ||
163 | |||
164 | if (hdev->product == USB_DEVICE_ID_LOGITECH_RECEIVER && | ||
165 | lg_ultrax_remote_mapping(hi, usage, bit, max)) | ||
166 | return 1; | ||
167 | |||
168 | if ((quirks & LG_WIRELESS) && lg_wireless_mapping(hi, usage, bit, max)) | ||
169 | return 1; | ||
170 | |||
171 | if ((hid & HID_USAGE_PAGE) != HID_UP_BUTTON) | ||
172 | return 0; | ||
173 | |||
174 | hid &= HID_USAGE; | ||
175 | |||
176 | /* Special handling for Logitech Cordless Desktop */ | ||
177 | if (field->application == HID_GD_MOUSE) { | ||
178 | if ((quirks & LG_IGNORE_DOUBLED_WHEEL) && | ||
179 | (hid == 7 || hid == 8)) | ||
180 | return -1; | ||
181 | } else { | ||
182 | if ((quirks & LG_EXPANDED_KEYMAP) && | ||
183 | hid < ARRAY_SIZE(e_keymap) && | ||
184 | e_keymap[hid] != 0) { | ||
185 | hid_map_usage(hi, usage, bit, max, EV_KEY, | ||
186 | e_keymap[hid]); | ||
187 | return 1; | ||
188 | } | ||
189 | } | ||
190 | |||
191 | return 0; | ||
192 | } | ||
193 | |||
194 | static int lg_input_mapped(struct hid_device *hdev, struct hid_input *hi, | ||
195 | struct hid_field *field, struct hid_usage *usage, | ||
196 | unsigned long **bit, int *max) | ||
197 | { | ||
198 | unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); | ||
199 | |||
200 | if ((quirks & LG_BAD_RELATIVE_KEYS) && usage->type == EV_KEY && | ||
201 | (field->flags & HID_MAIN_ITEM_RELATIVE)) | ||
202 | field->flags &= ~HID_MAIN_ITEM_RELATIVE; | ||
203 | |||
204 | if ((quirks & LG_DUPLICATE_USAGES) && (usage->type == EV_KEY || | ||
205 | usage->type == EV_REL || usage->type == EV_ABS)) | ||
206 | clear_bit(usage->code, *bit); | ||
207 | |||
208 | return 0; | ||
209 | } | ||
210 | |||
211 | static int lg_event(struct hid_device *hdev, struct hid_field *field, | ||
212 | struct hid_usage *usage, __s32 value) | ||
213 | { | ||
214 | unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); | ||
215 | |||
216 | if ((quirks & LG_INVERT_HWHEEL) && usage->code == REL_HWHEEL) { | ||
217 | input_event(field->hidinput->input, usage->type, usage->code, | ||
218 | -value); | ||
219 | return 1; | ||
220 | } | ||
221 | |||
222 | return 0; | ||
223 | } | ||
224 | |||
225 | static int lg_probe(struct hid_device *hdev, const struct hid_device_id *id) | ||
226 | { | ||
227 | unsigned long quirks = id->driver_data; | ||
228 | unsigned int connect_mask = HID_CONNECT_DEFAULT; | ||
229 | int ret; | ||
230 | |||
231 | hid_set_drvdata(hdev, (void *)quirks); | ||
232 | |||
233 | if (quirks & LG_NOGET) | ||
234 | hdev->quirks |= HID_QUIRK_NOGET; | ||
235 | |||
236 | ret = hid_parse(hdev); | ||
237 | if (ret) { | ||
238 | dev_err(&hdev->dev, "parse failed\n"); | ||
239 | goto err_free; | ||
240 | } | ||
241 | |||
242 | if (quirks & (LG_FF | LG_FF2)) | ||
243 | connect_mask &= ~HID_CONNECT_FF; | ||
244 | |||
245 | ret = hid_hw_start(hdev, connect_mask); | ||
246 | if (ret) { | ||
247 | dev_err(&hdev->dev, "hw start failed\n"); | ||
248 | goto err_free; | ||
249 | } | ||
250 | |||
251 | if (quirks & LG_RESET_LEDS) | ||
252 | usbhid_set_leds(hdev); | ||
253 | |||
254 | if (quirks & LG_FF) | ||
255 | lgff_init(hdev); | ||
256 | if (quirks & LG_FF2) | ||
257 | lg2ff_init(hdev); | ||
258 | |||
259 | return 0; | ||
260 | err_free: | ||
261 | return ret; | ||
262 | } | ||
263 | |||
264 | static const struct hid_device_id lg_devices[] = { | ||
265 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER), | ||
266 | .driver_data = LG_RDESC | LG_WIRELESS }, | ||
267 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER), | ||
268 | .driver_data = LG_RDESC | LG_WIRELESS }, | ||
269 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2), | ||
270 | .driver_data = LG_RDESC | LG_WIRELESS }, | ||
271 | |||
272 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER), | ||
273 | .driver_data = LG_BAD_RELATIVE_KEYS }, | ||
274 | |||
275 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP), | ||
276 | .driver_data = LG_DUPLICATE_USAGES }, | ||
277 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE), | ||
278 | .driver_data = LG_DUPLICATE_USAGES }, | ||
279 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI), | ||
280 | .driver_data = LG_DUPLICATE_USAGES }, | ||
281 | |||
282 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_KBD), | ||
283 | .driver_data = LG_RESET_LEDS }, | ||
284 | |||
285 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD), | ||
286 | .driver_data = LG_IGNORE_DOUBLED_WHEEL | LG_EXPANDED_KEYMAP }, | ||
287 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500), | ||
288 | .driver_data = LG_IGNORE_DOUBLED_WHEEL | LG_EXPANDED_KEYMAP }, | ||
289 | |||
290 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_LX3), | ||
291 | .driver_data = LG_INVERT_HWHEEL }, | ||
292 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_V150), | ||
293 | .driver_data = LG_INVERT_HWHEEL }, | ||
294 | |||
295 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D), | ||
296 | .driver_data = LG_NOGET }, | ||
297 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL), | ||
298 | .driver_data = LG_NOGET | LG_FF }, | ||
299 | |||
300 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD), | ||
301 | .driver_data = LG_FF }, | ||
302 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2), | ||
303 | .driver_data = LG_FF }, | ||
304 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D), | ||
305 | .driver_data = LG_FF }, | ||
306 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO), | ||
307 | .driver_data = LG_FF }, | ||
308 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL), | ||
309 | .driver_data = LG_FF }, | ||
310 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2), | ||
311 | .driver_data = LG_FF }, | ||
312 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2), | ||
313 | .driver_data = LG_FF2 }, | ||
314 | { } | ||
315 | }; | ||
316 | MODULE_DEVICE_TABLE(hid, lg_devices); | ||
317 | |||
318 | static struct hid_driver lg_driver = { | ||
319 | .name = "logitech", | ||
320 | .id_table = lg_devices, | ||
321 | .report_fixup = lg_report_fixup, | ||
322 | .input_mapping = lg_input_mapping, | ||
323 | .input_mapped = lg_input_mapped, | ||
324 | .event = lg_event, | ||
325 | .probe = lg_probe, | ||
326 | }; | ||
327 | |||
328 | static int lg_init(void) | ||
329 | { | ||
330 | return hid_register_driver(&lg_driver); | ||
331 | } | ||
332 | |||
333 | static void lg_exit(void) | ||
334 | { | ||
335 | hid_unregister_driver(&lg_driver); | ||
336 | } | ||
337 | |||
338 | module_init(lg_init); | ||
339 | module_exit(lg_exit); | ||
340 | MODULE_LICENSE("GPL"); | ||
341 | |||
342 | HID_COMPAT_LOAD_DRIVER(logitech); | ||
diff --git a/drivers/hid/hid-lg.h b/drivers/hid/hid-lg.h new file mode 100644 index 000000000000..27ae750ca878 --- /dev/null +++ b/drivers/hid/hid-lg.h | |||
@@ -0,0 +1,18 @@ | |||
1 | #ifndef __HID_LG_H | ||
2 | #define __HID_LG_H | ||
3 | |||
4 | #include <linux/autoconf.h> | ||
5 | |||
6 | #ifdef CONFIG_LOGITECH_FF | ||
7 | int lgff_init(struct hid_device *hdev); | ||
8 | #else | ||
9 | static inline int lgff_init(struct hid_device *hdev) { return -1; } | ||
10 | #endif | ||
11 | |||
12 | #ifdef CONFIG_LOGIRUMBLEPAD2_FF | ||
13 | int lg2ff_init(struct hid_device *hdev); | ||
14 | #else | ||
15 | static inline int lg2ff_init(struct hid_device *hdev) { return -1; } | ||
16 | #endif | ||
17 | |||
18 | #endif | ||
diff --git a/drivers/hid/usbhid/hid-lg2ff.c b/drivers/hid/hid-lg2ff.c index d469bd0061c9..4e6dc6e26523 100644 --- a/drivers/hid/usbhid/hid-lg2ff.c +++ b/drivers/hid/hid-lg2ff.c | |||
@@ -24,7 +24,9 @@ | |||
24 | #include <linux/input.h> | 24 | #include <linux/input.h> |
25 | #include <linux/usb.h> | 25 | #include <linux/usb.h> |
26 | #include <linux/hid.h> | 26 | #include <linux/hid.h> |
27 | #include "usbhid.h" | 27 | |
28 | #include "usbhid/usbhid.h" | ||
29 | #include "hid-lg.h" | ||
28 | 30 | ||
29 | struct lg2ff_device { | 31 | struct lg2ff_device { |
30 | struct hid_report *report; | 32 | struct hid_report *report; |
@@ -57,7 +59,7 @@ static int play_effect(struct input_dev *dev, void *data, | |||
57 | return 0; | 59 | return 0; |
58 | } | 60 | } |
59 | 61 | ||
60 | int hid_lg2ff_init(struct hid_device *hid) | 62 | int lg2ff_init(struct hid_device *hid) |
61 | { | 63 | { |
62 | struct lg2ff_device *lg2ff; | 64 | struct lg2ff_device *lg2ff; |
63 | struct hid_report *report; | 65 | struct hid_report *report; |
@@ -69,18 +71,18 @@ int hid_lg2ff_init(struct hid_device *hid) | |||
69 | int error; | 71 | int error; |
70 | 72 | ||
71 | if (list_empty(report_list)) { | 73 | if (list_empty(report_list)) { |
72 | printk(KERN_ERR "hid-lg2ff: no output report found\n"); | 74 | dev_err(&hid->dev, "no output report found\n"); |
73 | return -ENODEV; | 75 | return -ENODEV; |
74 | } | 76 | } |
75 | 77 | ||
76 | report = list_entry(report_list->next, struct hid_report, list); | 78 | report = list_entry(report_list->next, struct hid_report, list); |
77 | 79 | ||
78 | if (report->maxfield < 1) { | 80 | if (report->maxfield < 1) { |
79 | printk(KERN_ERR "hid-lg2ff: output report is empty\n"); | 81 | dev_err(&hid->dev, "output report is empty\n"); |
80 | return -ENODEV; | 82 | return -ENODEV; |
81 | } | 83 | } |
82 | if (report->field[0]->report_count < 7) { | 84 | if (report->field[0]->report_count < 7) { |
83 | printk(KERN_ERR "hid-lg2ff: not enough values in the field\n"); | 85 | dev_err(&hid->dev, "not enough values in the field\n"); |
84 | return -ENODEV; | 86 | return -ENODEV; |
85 | } | 87 | } |
86 | 88 | ||
@@ -107,7 +109,7 @@ int hid_lg2ff_init(struct hid_device *hid) | |||
107 | 109 | ||
108 | usbhid_submit_report(hid, report, USB_DIR_OUT); | 110 | usbhid_submit_report(hid, report, USB_DIR_OUT); |
109 | 111 | ||
110 | printk(KERN_INFO "Force feedback for Logitech Rumblepad 2 by " | 112 | dev_info(&hid->dev, "Force feedback for Logitech Rumblepad 2 by " |
111 | "Anssi Hannula <anssi.hannula@gmail.com>\n"); | 113 | "Anssi Hannula <anssi.hannula@gmail.com>\n"); |
112 | 114 | ||
113 | return 0; | 115 | return 0; |
diff --git a/drivers/hid/usbhid/hid-lgff.c b/drivers/hid/hid-lgff.c index 4b7ab6a46d93..51aff08e10ce 100644 --- a/drivers/hid/usbhid/hid-lgff.c +++ b/drivers/hid/hid-lgff.c | |||
@@ -30,7 +30,9 @@ | |||
30 | #include <linux/input.h> | 30 | #include <linux/input.h> |
31 | #include <linux/usb.h> | 31 | #include <linux/usb.h> |
32 | #include <linux/hid.h> | 32 | #include <linux/hid.h> |
33 | #include "usbhid.h" | 33 | |
34 | #include "usbhid/usbhid.h" | ||
35 | #include "hid-lg.h" | ||
34 | 36 | ||
35 | struct dev_type { | 37 | struct dev_type { |
36 | u16 idVendor; | 38 | u16 idVendor; |
@@ -48,6 +50,12 @@ static const signed short ff_joystick[] = { | |||
48 | -1 | 50 | -1 |
49 | }; | 51 | }; |
50 | 52 | ||
53 | static const signed short ff_wheel[] = { | ||
54 | FF_CONSTANT, | ||
55 | FF_AUTOCENTER, | ||
56 | -1 | ||
57 | }; | ||
58 | |||
51 | static const struct dev_type devices[] = { | 59 | static const struct dev_type devices[] = { |
52 | { 0x046d, 0xc211, ff_rumble }, | 60 | { 0x046d, 0xc211, ff_rumble }, |
53 | { 0x046d, 0xc219, ff_rumble }, | 61 | { 0x046d, 0xc219, ff_rumble }, |
@@ -55,7 +63,7 @@ static const struct dev_type devices[] = { | |||
55 | { 0x046d, 0xc286, ff_joystick }, | 63 | { 0x046d, 0xc286, ff_joystick }, |
56 | { 0x046d, 0xc294, ff_joystick }, | 64 | { 0x046d, 0xc294, ff_joystick }, |
57 | { 0x046d, 0xc295, ff_joystick }, | 65 | { 0x046d, 0xc295, ff_joystick }, |
58 | { 0x046d, 0xca03, ff_joystick }, | 66 | { 0x046d, 0xca03, ff_wheel }, |
59 | }; | 67 | }; |
60 | 68 | ||
61 | static int hid_lgff_play(struct input_dev *dev, void *data, struct ff_effect *effect) | 69 | static int hid_lgff_play(struct input_dev *dev, void *data, struct ff_effect *effect) |
@@ -100,7 +108,24 @@ static int hid_lgff_play(struct input_dev *dev, void *data, struct ff_effect *ef | |||
100 | return 0; | 108 | return 0; |
101 | } | 109 | } |
102 | 110 | ||
103 | int hid_lgff_init(struct hid_device* hid) | 111 | static void hid_lgff_set_autocenter(struct input_dev *dev, u16 magnitude) |
112 | { | ||
113 | struct hid_device *hid = input_get_drvdata(dev); | ||
114 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; | ||
115 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); | ||
116 | __s32 *value = report->field[0]->value; | ||
117 | magnitude = (magnitude >> 12) & 0xf; | ||
118 | *value++ = 0xfe; | ||
119 | *value++ = 0x0d; | ||
120 | *value++ = magnitude; /* clockwise strength */ | ||
121 | *value++ = magnitude; /* counter-clockwise strength */ | ||
122 | *value++ = 0x80; | ||
123 | *value++ = 0x00; | ||
124 | *value = 0x00; | ||
125 | usbhid_submit_report(hid, report, USB_DIR_OUT); | ||
126 | } | ||
127 | |||
128 | int lgff_init(struct hid_device* hid) | ||
104 | { | 129 | { |
105 | struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); | 130 | struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); |
106 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; | 131 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; |
@@ -145,6 +170,9 @@ int hid_lgff_init(struct hid_device* hid) | |||
145 | if (error) | 170 | if (error) |
146 | return error; | 171 | return error; |
147 | 172 | ||
173 | if ( test_bit(FF_AUTOCENTER, dev->ffbit) ) | ||
174 | dev->ff->set_autocenter = hid_lgff_set_autocenter; | ||
175 | |||
148 | printk(KERN_INFO "Force feedback for Logitech force feedback devices by Johann Deneux <johann.deneux@it.uu.se>\n"); | 176 | printk(KERN_INFO "Force feedback for Logitech force feedback devices by Johann Deneux <johann.deneux@it.uu.se>\n"); |
149 | 177 | ||
150 | return 0; | 178 | return 0; |
diff --git a/drivers/hid/hid-microsoft.c b/drivers/hid/hid-microsoft.c new file mode 100644 index 000000000000..d718b1607d0f --- /dev/null +++ b/drivers/hid/hid-microsoft.c | |||
@@ -0,0 +1,219 @@ | |||
1 | /* | ||
2 | * HID driver for some microsoft "special" devices | ||
3 | * | ||
4 | * Copyright (c) 1999 Andreas Gal | ||
5 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> | ||
6 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc | ||
7 | * Copyright (c) 2006-2007 Jiri Kosina | ||
8 | * Copyright (c) 2007 Paul Walmsley | ||
9 | * Copyright (c) 2008 Jiri Slaby | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * This program is free software; you can redistribute it and/or modify it | ||
14 | * under the terms of the GNU General Public License as published by the Free | ||
15 | * Software Foundation; either version 2 of the License, or (at your option) | ||
16 | * any later version. | ||
17 | */ | ||
18 | |||
19 | #include <linux/device.h> | ||
20 | #include <linux/input.h> | ||
21 | #include <linux/hid.h> | ||
22 | #include <linux/module.h> | ||
23 | |||
24 | #include "hid-ids.h" | ||
25 | |||
26 | #define MS_HIDINPUT 0x01 | ||
27 | #define MS_ERGONOMY 0x02 | ||
28 | #define MS_PRESENTER 0x04 | ||
29 | #define MS_RDESC 0x08 | ||
30 | #define MS_NOGET 0x10 | ||
31 | |||
32 | /* | ||
33 | * Microsoft Wireless Desktop Receiver (Model 1028) has several | ||
34 | * 'Usage Min/Max' where it ought to have 'Physical Min/Max' | ||
35 | */ | ||
36 | static void ms_report_fixup(struct hid_device *hdev, __u8 *rdesc, | ||
37 | unsigned int rsize) | ||
38 | { | ||
39 | unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); | ||
40 | |||
41 | if ((quirks & MS_RDESC) && rsize == 571 && rdesc[284] == 0x19 && | ||
42 | rdesc[286] == 0x2a && rdesc[304] == 0x19 && | ||
43 | rdesc[306] == 0x29 && rdesc[352] == 0x1a && | ||
44 | rdesc[355] == 0x2a && rdesc[557] == 0x19 && | ||
45 | rdesc[559] == 0x29) { | ||
46 | dev_info(&hdev->dev, "fixing up Microsoft Wireless Receiver " | ||
47 | "Model 1028 report descriptor\n"); | ||
48 | rdesc[284] = rdesc[304] = rdesc[557] = 0x35; | ||
49 | rdesc[352] = 0x36; | ||
50 | rdesc[286] = rdesc[355] = 0x46; | ||
51 | rdesc[306] = rdesc[559] = 0x45; | ||
52 | } | ||
53 | } | ||
54 | |||
55 | #define ms_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \ | ||
56 | EV_KEY, (c)) | ||
57 | static int ms_ergonomy_kb_quirk(struct hid_input *hi, struct hid_usage *usage, | ||
58 | unsigned long **bit, int *max) | ||
59 | { | ||
60 | struct input_dev *input = hi->input; | ||
61 | |||
62 | switch (usage->hid & HID_USAGE) { | ||
63 | case 0xfd06: ms_map_key_clear(KEY_CHAT); break; | ||
64 | case 0xfd07: ms_map_key_clear(KEY_PHONE); break; | ||
65 | case 0xff05: | ||
66 | set_bit(EV_REP, input->evbit); | ||
67 | ms_map_key_clear(KEY_F13); | ||
68 | set_bit(KEY_F14, input->keybit); | ||
69 | set_bit(KEY_F15, input->keybit); | ||
70 | set_bit(KEY_F16, input->keybit); | ||
71 | set_bit(KEY_F17, input->keybit); | ||
72 | set_bit(KEY_F18, input->keybit); | ||
73 | default: | ||
74 | return 0; | ||
75 | } | ||
76 | return 1; | ||
77 | } | ||
78 | |||
79 | static int ms_presenter_8k_quirk(struct hid_input *hi, struct hid_usage *usage, | ||
80 | unsigned long **bit, int *max) | ||
81 | { | ||
82 | set_bit(EV_REP, hi->input->evbit); | ||
83 | switch (usage->hid & HID_USAGE) { | ||
84 | case 0xfd08: ms_map_key_clear(KEY_FORWARD); break; | ||
85 | case 0xfd09: ms_map_key_clear(KEY_BACK); break; | ||
86 | case 0xfd0b: ms_map_key_clear(KEY_PLAYPAUSE); break; | ||
87 | case 0xfd0e: ms_map_key_clear(KEY_CLOSE); break; | ||
88 | case 0xfd0f: ms_map_key_clear(KEY_PLAY); break; | ||
89 | default: | ||
90 | return 0; | ||
91 | } | ||
92 | return 1; | ||
93 | } | ||
94 | |||
95 | static int ms_input_mapping(struct hid_device *hdev, struct hid_input *hi, | ||
96 | struct hid_field *field, struct hid_usage *usage, | ||
97 | unsigned long **bit, int *max) | ||
98 | { | ||
99 | unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); | ||
100 | |||
101 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR) | ||
102 | return 0; | ||
103 | |||
104 | if (quirks & MS_ERGONOMY) { | ||
105 | int ret = ms_ergonomy_kb_quirk(hi, usage, bit, max); | ||
106 | if (ret) | ||
107 | return ret; | ||
108 | } | ||
109 | |||
110 | if ((quirks & MS_PRESENTER) && | ||
111 | ms_presenter_8k_quirk(hi, usage, bit, max)) | ||
112 | return 1; | ||
113 | |||
114 | return 0; | ||
115 | } | ||
116 | |||
117 | static int ms_event(struct hid_device *hdev, struct hid_field *field, | ||
118 | struct hid_usage *usage, __s32 value) | ||
119 | { | ||
120 | unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); | ||
121 | |||
122 | if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput || | ||
123 | !usage->type) | ||
124 | return 0; | ||
125 | |||
126 | /* Handling MS keyboards special buttons */ | ||
127 | if (quirks & MS_ERGONOMY && usage->hid == (HID_UP_MSVENDOR | 0xff05)) { | ||
128 | struct input_dev *input = field->hidinput->input; | ||
129 | static unsigned int last_key = 0; | ||
130 | unsigned int key = 0; | ||
131 | switch (value) { | ||
132 | case 0x01: key = KEY_F14; break; | ||
133 | case 0x02: key = KEY_F15; break; | ||
134 | case 0x04: key = KEY_F16; break; | ||
135 | case 0x08: key = KEY_F17; break; | ||
136 | case 0x10: key = KEY_F18; break; | ||
137 | } | ||
138 | if (key) { | ||
139 | input_event(input, usage->type, key, 1); | ||
140 | last_key = key; | ||
141 | } else | ||
142 | input_event(input, usage->type, last_key, 0); | ||
143 | |||
144 | return 1; | ||
145 | } | ||
146 | |||
147 | return 0; | ||
148 | } | ||
149 | |||
150 | static int ms_probe(struct hid_device *hdev, const struct hid_device_id *id) | ||
151 | { | ||
152 | unsigned long quirks = id->driver_data; | ||
153 | int ret; | ||
154 | |||
155 | hid_set_drvdata(hdev, (void *)quirks); | ||
156 | |||
157 | if (quirks & MS_NOGET) | ||
158 | hdev->quirks |= HID_QUIRK_NOGET; | ||
159 | |||
160 | ret = hid_parse(hdev); | ||
161 | if (ret) { | ||
162 | dev_err(&hdev->dev, "parse failed\n"); | ||
163 | goto err_free; | ||
164 | } | ||
165 | |||
166 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT | ((quirks & MS_HIDINPUT) ? | ||
167 | HID_CONNECT_HIDINPUT_FORCE : 0)); | ||
168 | if (ret) { | ||
169 | dev_err(&hdev->dev, "hw start failed\n"); | ||
170 | goto err_free; | ||
171 | } | ||
172 | |||
173 | return 0; | ||
174 | err_free: | ||
175 | return ret; | ||
176 | } | ||
177 | |||
178 | static const struct hid_device_id ms_devices[] = { | ||
179 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV), | ||
180 | .driver_data = MS_HIDINPUT }, | ||
181 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K), | ||
182 | .driver_data = MS_ERGONOMY }, | ||
183 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K), | ||
184 | .driver_data = MS_ERGONOMY | MS_RDESC }, | ||
185 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB), | ||
186 | .driver_data = MS_PRESENTER }, | ||
187 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0), | ||
188 | .driver_data = MS_NOGET }, | ||
189 | |||
190 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT), | ||
191 | .driver_data = MS_PRESENTER }, | ||
192 | { } | ||
193 | }; | ||
194 | MODULE_DEVICE_TABLE(hid, ms_devices); | ||
195 | |||
196 | static struct hid_driver ms_driver = { | ||
197 | .name = "microsoft", | ||
198 | .id_table = ms_devices, | ||
199 | .report_fixup = ms_report_fixup, | ||
200 | .input_mapping = ms_input_mapping, | ||
201 | .event = ms_event, | ||
202 | .probe = ms_probe, | ||
203 | }; | ||
204 | |||
205 | static int ms_init(void) | ||
206 | { | ||
207 | return hid_register_driver(&ms_driver); | ||
208 | } | ||
209 | |||
210 | static void ms_exit(void) | ||
211 | { | ||
212 | hid_unregister_driver(&ms_driver); | ||
213 | } | ||
214 | |||
215 | module_init(ms_init); | ||
216 | module_exit(ms_exit); | ||
217 | MODULE_LICENSE("GPL"); | ||
218 | |||
219 | HID_COMPAT_LOAD_DRIVER(microsoft); | ||
diff --git a/drivers/hid/hid-monterey.c b/drivers/hid/hid-monterey.c new file mode 100644 index 000000000000..f3a85a065f18 --- /dev/null +++ b/drivers/hid/hid-monterey.c | |||
@@ -0,0 +1,82 @@ | |||
1 | /* | ||
2 | * HID driver for some monterey "special" devices | ||
3 | * | ||
4 | * Copyright (c) 1999 Andreas Gal | ||
5 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> | ||
6 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc | ||
7 | * Copyright (c) 2006-2007 Jiri Kosina | ||
8 | * Copyright (c) 2007 Paul Walmsley | ||
9 | * Copyright (c) 2008 Jiri Slaby | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * This program is free software; you can redistribute it and/or modify it | ||
14 | * under the terms of the GNU General Public License as published by the Free | ||
15 | * Software Foundation; either version 2 of the License, or (at your option) | ||
16 | * any later version. | ||
17 | */ | ||
18 | |||
19 | #include <linux/device.h> | ||
20 | #include <linux/hid.h> | ||
21 | #include <linux/module.h> | ||
22 | |||
23 | #include "hid-ids.h" | ||
24 | |||
25 | static void mr_report_fixup(struct hid_device *hdev, __u8 *rdesc, | ||
26 | unsigned int rsize) | ||
27 | { | ||
28 | if (rsize >= 30 && rdesc[29] == 0x05 && rdesc[30] == 0x09) { | ||
29 | dev_info(&hdev->dev, "fixing up button/consumer in HID report " | ||
30 | "descriptor\n"); | ||
31 | rdesc[30] = 0x0c; | ||
32 | } | ||
33 | } | ||
34 | |||
35 | #define mr_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \ | ||
36 | EV_KEY, (c)) | ||
37 | static int mr_input_mapping(struct hid_device *hdev, struct hid_input *hi, | ||
38 | struct hid_field *field, struct hid_usage *usage, | ||
39 | unsigned long **bit, int *max) | ||
40 | { | ||
41 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER) | ||
42 | return 0; | ||
43 | |||
44 | switch (usage->hid & HID_USAGE) { | ||
45 | case 0x156: mr_map_key_clear(KEY_WORDPROCESSOR); break; | ||
46 | case 0x157: mr_map_key_clear(KEY_SPREADSHEET); break; | ||
47 | case 0x158: mr_map_key_clear(KEY_PRESENTATION); break; | ||
48 | case 0x15c: mr_map_key_clear(KEY_STOP); break; | ||
49 | default: | ||
50 | return 0; | ||
51 | } | ||
52 | return 1; | ||
53 | } | ||
54 | |||
55 | static const struct hid_device_id mr_devices[] = { | ||
56 | { HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) }, | ||
57 | { } | ||
58 | }; | ||
59 | MODULE_DEVICE_TABLE(hid, mr_devices); | ||
60 | |||
61 | static struct hid_driver mr_driver = { | ||
62 | .name = "monterey", | ||
63 | .id_table = mr_devices, | ||
64 | .report_fixup = mr_report_fixup, | ||
65 | .input_mapping = mr_input_mapping, | ||
66 | }; | ||
67 | |||
68 | static int mr_init(void) | ||
69 | { | ||
70 | return hid_register_driver(&mr_driver); | ||
71 | } | ||
72 | |||
73 | static void mr_exit(void) | ||
74 | { | ||
75 | hid_unregister_driver(&mr_driver); | ||
76 | } | ||
77 | |||
78 | module_init(mr_init); | ||
79 | module_exit(mr_exit); | ||
80 | MODULE_LICENSE("GPL"); | ||
81 | |||
82 | HID_COMPAT_LOAD_DRIVER(monterey); | ||
diff --git a/drivers/hid/hid-petalynx.c b/drivers/hid/hid-petalynx.c new file mode 100644 index 000000000000..10945fe12d50 --- /dev/null +++ b/drivers/hid/hid-petalynx.c | |||
@@ -0,0 +1,122 @@ | |||
1 | /* | ||
2 | * HID driver for some petalynx "special" devices | ||
3 | * | ||
4 | * Copyright (c) 1999 Andreas Gal | ||
5 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> | ||
6 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc | ||
7 | * Copyright (c) 2006-2007 Jiri Kosina | ||
8 | * Copyright (c) 2007 Paul Walmsley | ||
9 | * Copyright (c) 2008 Jiri Slaby | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * This program is free software; you can redistribute it and/or modify it | ||
14 | * under the terms of the GNU General Public License as published by the Free | ||
15 | * Software Foundation; either version 2 of the License, or (at your option) | ||
16 | * any later version. | ||
17 | */ | ||
18 | |||
19 | #include <linux/device.h> | ||
20 | #include <linux/hid.h> | ||
21 | #include <linux/module.h> | ||
22 | |||
23 | #include "hid-ids.h" | ||
24 | |||
25 | /* Petalynx Maxter Remote has maximum for consumer page set too low */ | ||
26 | static void pl_report_fixup(struct hid_device *hdev, __u8 *rdesc, | ||
27 | unsigned int rsize) | ||
28 | { | ||
29 | if (rsize >= 60 && rdesc[39] == 0x2a && rdesc[40] == 0xf5 && | ||
30 | rdesc[41] == 0x00 && rdesc[59] == 0x26 && | ||
31 | rdesc[60] == 0xf9 && rdesc[61] == 0x00) { | ||
32 | dev_info(&hdev->dev, "fixing up Petalynx Maxter Remote report " | ||
33 | "descriptor\n"); | ||
34 | rdesc[60] = 0xfa; | ||
35 | rdesc[40] = 0xfa; | ||
36 | } | ||
37 | } | ||
38 | |||
39 | #define pl_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \ | ||
40 | EV_KEY, (c)) | ||
41 | static int pl_input_mapping(struct hid_device *hdev, struct hid_input *hi, | ||
42 | struct hid_field *field, struct hid_usage *usage, | ||
43 | unsigned long **bit, int *max) | ||
44 | { | ||
45 | if ((usage->hid & HID_USAGE_PAGE) == HID_UP_LOGIVENDOR) { | ||
46 | switch (usage->hid & HID_USAGE) { | ||
47 | case 0x05a: pl_map_key_clear(KEY_TEXT); break; | ||
48 | case 0x05b: pl_map_key_clear(KEY_RED); break; | ||
49 | case 0x05c: pl_map_key_clear(KEY_GREEN); break; | ||
50 | case 0x05d: pl_map_key_clear(KEY_YELLOW); break; | ||
51 | case 0x05e: pl_map_key_clear(KEY_BLUE); break; | ||
52 | default: | ||
53 | return 0; | ||
54 | } | ||
55 | return 1; | ||
56 | } | ||
57 | |||
58 | if ((usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER) { | ||
59 | switch (usage->hid & HID_USAGE) { | ||
60 | case 0x0f6: pl_map_key_clear(KEY_NEXT); break; | ||
61 | case 0x0fa: pl_map_key_clear(KEY_BACK); break; | ||
62 | default: | ||
63 | return 0; | ||
64 | } | ||
65 | return 1; | ||
66 | } | ||
67 | |||
68 | return 0; | ||
69 | } | ||
70 | |||
71 | static int pl_probe(struct hid_device *hdev, const struct hid_device_id *id) | ||
72 | { | ||
73 | int ret; | ||
74 | |||
75 | hdev->quirks |= HID_QUIRK_NOGET; | ||
76 | |||
77 | ret = hid_parse(hdev); | ||
78 | if (ret) { | ||
79 | dev_err(&hdev->dev, "parse failed\n"); | ||
80 | goto err_free; | ||
81 | } | ||
82 | |||
83 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); | ||
84 | if (ret) { | ||
85 | dev_err(&hdev->dev, "hw start failed\n"); | ||
86 | goto err_free; | ||
87 | } | ||
88 | |||
89 | return 0; | ||
90 | err_free: | ||
91 | return ret; | ||
92 | } | ||
93 | |||
94 | static const struct hid_device_id pl_devices[] = { | ||
95 | { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) }, | ||
96 | { } | ||
97 | }; | ||
98 | MODULE_DEVICE_TABLE(hid, pl_devices); | ||
99 | |||
100 | static struct hid_driver pl_driver = { | ||
101 | .name = "petalynx", | ||
102 | .id_table = pl_devices, | ||
103 | .report_fixup = pl_report_fixup, | ||
104 | .input_mapping = pl_input_mapping, | ||
105 | .probe = pl_probe, | ||
106 | }; | ||
107 | |||
108 | static int pl_init(void) | ||
109 | { | ||
110 | return hid_register_driver(&pl_driver); | ||
111 | } | ||
112 | |||
113 | static void pl_exit(void) | ||
114 | { | ||
115 | hid_unregister_driver(&pl_driver); | ||
116 | } | ||
117 | |||
118 | module_init(pl_init); | ||
119 | module_exit(pl_exit); | ||
120 | MODULE_LICENSE("GPL"); | ||
121 | |||
122 | HID_COMPAT_LOAD_DRIVER(petalynx); | ||
diff --git a/drivers/hid/usbhid/hid-plff.c b/drivers/hid/hid-pl.c index 9eb83cf9d22b..acd815586182 100644 --- a/drivers/hid/usbhid/hid-plff.c +++ b/drivers/hid/hid-pl.c | |||
@@ -9,7 +9,7 @@ | |||
9 | * - contains two reports, one for each port (HID_QUIRK_MULTI_INPUT) | 9 | * - contains two reports, one for each port (HID_QUIRK_MULTI_INPUT) |
10 | * | 10 | * |
11 | * 0e8f:0003 "GreenAsia Inc. USB Joystick " | 11 | * 0e8f:0003 "GreenAsia Inc. USB Joystick " |
12 | * - tested with Köng Gaming gamepad | 12 | * - tested with K??ng Gaming gamepad |
13 | * | 13 | * |
14 | * Copyright (c) 2007 Anssi Hannula <anssi.hannula@gmail.com> | 14 | * Copyright (c) 2007 Anssi Hannula <anssi.hannula@gmail.com> |
15 | */ | 15 | */ |
@@ -38,7 +38,11 @@ | |||
38 | #include <linux/input.h> | 38 | #include <linux/input.h> |
39 | #include <linux/usb.h> | 39 | #include <linux/usb.h> |
40 | #include <linux/hid.h> | 40 | #include <linux/hid.h> |
41 | #include "usbhid.h" | 41 | |
42 | #include "hid-ids.h" | ||
43 | |||
44 | #ifdef CONFIG_PANTHERLORD_FF | ||
45 | #include "usbhid/usbhid.h" | ||
42 | 46 | ||
43 | struct plff_device { | 47 | struct plff_device { |
44 | struct hid_report *report; | 48 | struct hid_report *report; |
@@ -66,7 +70,7 @@ static int hid_plff_play(struct input_dev *dev, void *data, | |||
66 | return 0; | 70 | return 0; |
67 | } | 71 | } |
68 | 72 | ||
69 | int hid_plff_init(struct hid_device *hid) | 73 | static int plff_init(struct hid_device *hid) |
70 | { | 74 | { |
71 | struct plff_device *plff; | 75 | struct plff_device *plff; |
72 | struct hid_report *report; | 76 | struct hid_report *report; |
@@ -86,7 +90,7 @@ int hid_plff_init(struct hid_device *hid) | |||
86 | currently unknown. */ | 90 | currently unknown. */ |
87 | 91 | ||
88 | if (list_empty(report_list)) { | 92 | if (list_empty(report_list)) { |
89 | printk(KERN_ERR "hid-plff: no output reports found\n"); | 93 | dev_err(&hid->dev, "no output reports found\n"); |
90 | return -ENODEV; | 94 | return -ENODEV; |
91 | } | 95 | } |
92 | 96 | ||
@@ -95,18 +99,19 @@ int hid_plff_init(struct hid_device *hid) | |||
95 | report_ptr = report_ptr->next; | 99 | report_ptr = report_ptr->next; |
96 | 100 | ||
97 | if (report_ptr == report_list) { | 101 | if (report_ptr == report_list) { |
98 | printk(KERN_ERR "hid-plff: required output report is missing\n"); | 102 | dev_err(&hid->dev, "required output report is " |
103 | "missing\n"); | ||
99 | return -ENODEV; | 104 | return -ENODEV; |
100 | } | 105 | } |
101 | 106 | ||
102 | report = list_entry(report_ptr, struct hid_report, list); | 107 | report = list_entry(report_ptr, struct hid_report, list); |
103 | if (report->maxfield < 1) { | 108 | if (report->maxfield < 1) { |
104 | printk(KERN_ERR "hid-plff: no fields in the report\n"); | 109 | dev_err(&hid->dev, "no fields in the report\n"); |
105 | return -ENODEV; | 110 | return -ENODEV; |
106 | } | 111 | } |
107 | 112 | ||
108 | if (report->field[0]->report_count < 4) { | 113 | if (report->field[0]->report_count < 4) { |
109 | printk(KERN_ERR "hid-plff: not enough values in the field\n"); | 114 | dev_err(&hid->dev, "not enough values in the field\n"); |
110 | return -ENODEV; | 115 | return -ENODEV; |
111 | } | 116 | } |
112 | 117 | ||
@@ -132,8 +137,70 @@ int hid_plff_init(struct hid_device *hid) | |||
132 | usbhid_submit_report(hid, plff->report, USB_DIR_OUT); | 137 | usbhid_submit_report(hid, plff->report, USB_DIR_OUT); |
133 | } | 138 | } |
134 | 139 | ||
135 | printk(KERN_INFO "hid-plff: Force feedback for PantherLord/GreenAsia " | 140 | dev_info(&hid->dev, "Force feedback for PantherLord/GreenAsia " |
136 | "devices by Anssi Hannula <anssi.hannula@gmail.com>\n"); | 141 | "devices by Anssi Hannula <anssi.hannula@gmail.com>\n"); |
137 | 142 | ||
138 | return 0; | 143 | return 0; |
139 | } | 144 | } |
145 | #else | ||
146 | static inline int plff_init(struct hid_device *hid) | ||
147 | { | ||
148 | return 0; | ||
149 | } | ||
150 | #endif | ||
151 | |||
152 | static int pl_probe(struct hid_device *hdev, const struct hid_device_id *id) | ||
153 | { | ||
154 | int ret; | ||
155 | |||
156 | if (id->driver_data) | ||
157 | hdev->quirks |= HID_QUIRK_MULTI_INPUT; | ||
158 | |||
159 | ret = hid_parse(hdev); | ||
160 | if (ret) { | ||
161 | dev_err(&hdev->dev, "parse failed\n"); | ||
162 | goto err; | ||
163 | } | ||
164 | |||
165 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); | ||
166 | if (ret) { | ||
167 | dev_err(&hdev->dev, "hw start failed\n"); | ||
168 | goto err; | ||
169 | } | ||
170 | |||
171 | plff_init(hdev); | ||
172 | |||
173 | return 0; | ||
174 | err: | ||
175 | return ret; | ||
176 | } | ||
177 | |||
178 | static const struct hid_device_id pl_devices[] = { | ||
179 | { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR), | ||
180 | .driver_data = 1 }, /* Twin USB Joystick */ | ||
181 | { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003), }, /* GreenAsia Inc. USB Joystick */ | ||
182 | { } | ||
183 | }; | ||
184 | MODULE_DEVICE_TABLE(hid, pl_devices); | ||
185 | |||
186 | static struct hid_driver pl_driver = { | ||
187 | .name = "pantherlord", | ||
188 | .id_table = pl_devices, | ||
189 | .probe = pl_probe, | ||
190 | }; | ||
191 | |||
192 | static int pl_init(void) | ||
193 | { | ||
194 | return hid_register_driver(&pl_driver); | ||
195 | } | ||
196 | |||
197 | static void pl_exit(void) | ||
198 | { | ||
199 | hid_unregister_driver(&pl_driver); | ||
200 | } | ||
201 | |||
202 | module_init(pl_init); | ||
203 | module_exit(pl_exit); | ||
204 | MODULE_LICENSE("GPL"); | ||
205 | |||
206 | HID_COMPAT_LOAD_DRIVER(pantherlord); | ||
diff --git a/drivers/hid/hid-samsung.c b/drivers/hid/hid-samsung.c new file mode 100644 index 000000000000..15f3c0492450 --- /dev/null +++ b/drivers/hid/hid-samsung.c | |||
@@ -0,0 +1,100 @@ | |||
1 | /* | ||
2 | * HID driver for some samsung "special" devices | ||
3 | * | ||
4 | * Copyright (c) 1999 Andreas Gal | ||
5 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> | ||
6 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc | ||
7 | * Copyright (c) 2006-2007 Jiri Kosina | ||
8 | * Copyright (c) 2007 Paul Walmsley | ||
9 | * Copyright (c) 2008 Jiri Slaby | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * This program is free software; you can redistribute it and/or modify it | ||
14 | * under the terms of the GNU General Public License as published by the Free | ||
15 | * Software Foundation; either version 2 of the License, or (at your option) | ||
16 | * any later version. | ||
17 | */ | ||
18 | |||
19 | #include <linux/device.h> | ||
20 | #include <linux/hid.h> | ||
21 | #include <linux/module.h> | ||
22 | |||
23 | #include "hid-ids.h" | ||
24 | |||
25 | /* | ||
26 | * Samsung IrDA remote controller (reports as Cypress USB Mouse). | ||
27 | * | ||
28 | * Vendor specific report #4 has a size of 48 bit, | ||
29 | * and therefore is not accepted when inspecting the descriptors. | ||
30 | * As a workaround we reinterpret the report as: | ||
31 | * Variable type, count 6, size 8 bit, log. maximum 255 | ||
32 | * The burden to reconstruct the data is moved into user space. | ||
33 | */ | ||
34 | static void samsung_report_fixup(struct hid_device *hdev, __u8 *rdesc, | ||
35 | unsigned int rsize) | ||
36 | { | ||
37 | if (rsize >= 182 && rdesc[175] == 0x25 && rdesc[176] == 0x40 && | ||
38 | rdesc[177] == 0x75 && rdesc[178] == 0x30 && | ||
39 | rdesc[179] == 0x95 && rdesc[180] == 0x01 && | ||
40 | rdesc[182] == 0x40) { | ||
41 | dev_info(&hdev->dev, "fixing up Samsung IrDA report " | ||
42 | "descriptor\n"); | ||
43 | rdesc[176] = 0xff; | ||
44 | rdesc[178] = 0x08; | ||
45 | rdesc[180] = 0x06; | ||
46 | rdesc[182] = 0x42; | ||
47 | } | ||
48 | } | ||
49 | |||
50 | static int samsung_probe(struct hid_device *hdev, | ||
51 | const struct hid_device_id *id) | ||
52 | { | ||
53 | int ret; | ||
54 | |||
55 | ret = hid_parse(hdev); | ||
56 | if (ret) { | ||
57 | dev_err(&hdev->dev, "parse failed\n"); | ||
58 | goto err_free; | ||
59 | } | ||
60 | |||
61 | ret = hid_hw_start(hdev, (HID_CONNECT_DEFAULT & ~HID_CONNECT_HIDINPUT) | | ||
62 | HID_CONNECT_HIDDEV_FORCE); | ||
63 | if (ret) { | ||
64 | dev_err(&hdev->dev, "hw start failed\n"); | ||
65 | goto err_free; | ||
66 | } | ||
67 | |||
68 | return 0; | ||
69 | err_free: | ||
70 | return ret; | ||
71 | } | ||
72 | |||
73 | static const struct hid_device_id samsung_devices[] = { | ||
74 | { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) }, | ||
75 | { } | ||
76 | }; | ||
77 | MODULE_DEVICE_TABLE(hid, samsung_devices); | ||
78 | |||
79 | static struct hid_driver samsung_driver = { | ||
80 | .name = "samsung", | ||
81 | .id_table = samsung_devices, | ||
82 | .report_fixup = samsung_report_fixup, | ||
83 | .probe = samsung_probe, | ||
84 | }; | ||
85 | |||
86 | static int samsung_init(void) | ||
87 | { | ||
88 | return hid_register_driver(&samsung_driver); | ||
89 | } | ||
90 | |||
91 | static void samsung_exit(void) | ||
92 | { | ||
93 | hid_unregister_driver(&samsung_driver); | ||
94 | } | ||
95 | |||
96 | module_init(samsung_init); | ||
97 | module_exit(samsung_exit); | ||
98 | MODULE_LICENSE("GPL"); | ||
99 | |||
100 | HID_COMPAT_LOAD_DRIVER(samsung); | ||
diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c new file mode 100644 index 000000000000..3af8095a7de1 --- /dev/null +++ b/drivers/hid/hid-sony.c | |||
@@ -0,0 +1,110 @@ | |||
1 | /* | ||
2 | * HID driver for some sony "special" devices | ||
3 | * | ||
4 | * Copyright (c) 1999 Andreas Gal | ||
5 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> | ||
6 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc | ||
7 | * Copyright (c) 2006-2007 Jiri Kosina | ||
8 | * Copyright (c) 2007 Paul Walmsley | ||
9 | * Copyright (c) 2008 Jiri Slaby | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * This program is free software; you can redistribute it and/or modify it | ||
14 | * under the terms of the GNU General Public License as published by the Free | ||
15 | * Software Foundation; either version 2 of the License, or (at your option) | ||
16 | * any later version. | ||
17 | */ | ||
18 | |||
19 | #include <linux/device.h> | ||
20 | #include <linux/hid.h> | ||
21 | #include <linux/module.h> | ||
22 | #include <linux/usb.h> | ||
23 | |||
24 | #include "hid-ids.h" | ||
25 | |||
26 | /* | ||
27 | * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller | ||
28 | * to "operational". Without this, the ps3 controller will not report any | ||
29 | * events. | ||
30 | */ | ||
31 | static int sony_set_operational(struct hid_device *hdev) | ||
32 | { | ||
33 | struct usb_interface *intf = to_usb_interface(hdev->dev.parent); | ||
34 | struct usb_device *dev = interface_to_usbdev(intf); | ||
35 | __u16 ifnum = intf->cur_altsetting->desc.bInterfaceNumber; | ||
36 | int ret; | ||
37 | char *buf = kmalloc(18, GFP_KERNEL); | ||
38 | |||
39 | if (!buf) | ||
40 | return -ENOMEM; | ||
41 | |||
42 | ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), | ||
43 | HID_REQ_GET_REPORT, | ||
44 | USB_DIR_IN | USB_TYPE_CLASS | | ||
45 | USB_RECIP_INTERFACE, | ||
46 | (3 << 8) | 0xf2, ifnum, buf, 17, | ||
47 | USB_CTRL_GET_TIMEOUT); | ||
48 | if (ret < 0) | ||
49 | dev_err(&hdev->dev, "can't set operational mode\n"); | ||
50 | |||
51 | kfree(buf); | ||
52 | |||
53 | return ret; | ||
54 | } | ||
55 | |||
56 | static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) | ||
57 | { | ||
58 | int ret; | ||
59 | |||
60 | ret = hid_parse(hdev); | ||
61 | if (ret) { | ||
62 | dev_err(&hdev->dev, "parse failed\n"); | ||
63 | goto err_free; | ||
64 | } | ||
65 | |||
66 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT | | ||
67 | HID_CONNECT_HIDDEV_FORCE); | ||
68 | if (ret) { | ||
69 | dev_err(&hdev->dev, "hw start failed\n"); | ||
70 | goto err_free; | ||
71 | } | ||
72 | |||
73 | ret = sony_set_operational(hdev); | ||
74 | if (ret) | ||
75 | goto err_stop; | ||
76 | |||
77 | return 0; | ||
78 | err_stop: | ||
79 | hid_hw_stop(hdev); | ||
80 | err_free: | ||
81 | return ret; | ||
82 | } | ||
83 | |||
84 | static const struct hid_device_id sony_devices[] = { | ||
85 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) }, | ||
86 | { } | ||
87 | }; | ||
88 | MODULE_DEVICE_TABLE(hid, sony_devices); | ||
89 | |||
90 | static struct hid_driver sony_driver = { | ||
91 | .name = "sony", | ||
92 | .id_table = sony_devices, | ||
93 | .probe = sony_probe, | ||
94 | }; | ||
95 | |||
96 | static int sony_init(void) | ||
97 | { | ||
98 | return hid_register_driver(&sony_driver); | ||
99 | } | ||
100 | |||
101 | static void sony_exit(void) | ||
102 | { | ||
103 | hid_unregister_driver(&sony_driver); | ||
104 | } | ||
105 | |||
106 | module_init(sony_init); | ||
107 | module_exit(sony_exit); | ||
108 | MODULE_LICENSE("GPL"); | ||
109 | |||
110 | HID_COMPAT_LOAD_DRIVER(sony); | ||
diff --git a/drivers/hid/hid-sunplus.c b/drivers/hid/hid-sunplus.c new file mode 100644 index 000000000000..5ba68f7dbb78 --- /dev/null +++ b/drivers/hid/hid-sunplus.c | |||
@@ -0,0 +1,82 @@ | |||
1 | /* | ||
2 | * HID driver for some sunplus "special" devices | ||
3 | * | ||
4 | * Copyright (c) 1999 Andreas Gal | ||
5 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> | ||
6 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc | ||
7 | * Copyright (c) 2006-2007 Jiri Kosina | ||
8 | * Copyright (c) 2007 Paul Walmsley | ||
9 | * Copyright (c) 2008 Jiri Slaby | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * This program is free software; you can redistribute it and/or modify it | ||
14 | * under the terms of the GNU General Public License as published by the Free | ||
15 | * Software Foundation; either version 2 of the License, or (at your option) | ||
16 | * any later version. | ||
17 | */ | ||
18 | |||
19 | #include <linux/device.h> | ||
20 | #include <linux/hid.h> | ||
21 | #include <linux/module.h> | ||
22 | |||
23 | #include "hid-ids.h" | ||
24 | |||
25 | static void sp_report_fixup(struct hid_device *hdev, __u8 *rdesc, | ||
26 | unsigned int rsize) | ||
27 | { | ||
28 | if (rsize >= 107 && rdesc[104] == 0x26 && rdesc[105] == 0x80 && | ||
29 | rdesc[106] == 0x03) { | ||
30 | dev_info(&hdev->dev, "fixing up Sunplus Wireless Desktop " | ||
31 | "report descriptor\n"); | ||
32 | rdesc[105] = rdesc[110] = 0x03; | ||
33 | rdesc[106] = rdesc[111] = 0x21; | ||
34 | } | ||
35 | } | ||
36 | |||
37 | #define sp_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \ | ||
38 | EV_KEY, (c)) | ||
39 | static int sp_input_mapping(struct hid_device *hdev, struct hid_input *hi, | ||
40 | struct hid_field *field, struct hid_usage *usage, | ||
41 | unsigned long **bit, int *max) | ||
42 | { | ||
43 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER) | ||
44 | return 0; | ||
45 | |||
46 | switch (usage->hid & HID_USAGE) { | ||
47 | case 0x2003: sp_map_key_clear(KEY_ZOOMIN); break; | ||
48 | case 0x2103: sp_map_key_clear(KEY_ZOOMOUT); break; | ||
49 | default: | ||
50 | return 0; | ||
51 | } | ||
52 | return 1; | ||
53 | } | ||
54 | |||
55 | static const struct hid_device_id sp_devices[] = { | ||
56 | { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) }, | ||
57 | { } | ||
58 | }; | ||
59 | MODULE_DEVICE_TABLE(hid, sp_devices); | ||
60 | |||
61 | static struct hid_driver sp_driver = { | ||
62 | .name = "sunplus", | ||
63 | .id_table = sp_devices, | ||
64 | .report_fixup = sp_report_fixup, | ||
65 | .input_mapping = sp_input_mapping, | ||
66 | }; | ||
67 | |||
68 | static int sp_init(void) | ||
69 | { | ||
70 | return hid_register_driver(&sp_driver); | ||
71 | } | ||
72 | |||
73 | static void sp_exit(void) | ||
74 | { | ||
75 | hid_unregister_driver(&sp_driver); | ||
76 | } | ||
77 | |||
78 | module_init(sp_init); | ||
79 | module_exit(sp_exit); | ||
80 | MODULE_LICENSE("GPL"); | ||
81 | |||
82 | HID_COMPAT_LOAD_DRIVER(sunplus); | ||
diff --git a/drivers/hid/usbhid/hid-tmff.c b/drivers/hid/hid-tmff.c index 144578b1a00c..1b7cba0f7e1f 100644 --- a/drivers/hid/usbhid/hid-tmff.c +++ b/drivers/hid/hid-tmff.c | |||
@@ -27,23 +27,17 @@ | |||
27 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 27 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include <linux/hid.h> | ||
30 | #include <linux/input.h> | 31 | #include <linux/input.h> |
31 | |||
32 | #undef DEBUG | ||
33 | #include <linux/usb.h> | 32 | #include <linux/usb.h> |
34 | 33 | ||
35 | #include <linux/hid.h> | 34 | #include "hid-ids.h" |
36 | #include "usbhid.h" | 35 | |
36 | #include "usbhid/usbhid.h" | ||
37 | 37 | ||
38 | /* Usages for thrustmaster devices I know about */ | 38 | /* Usages for thrustmaster devices I know about */ |
39 | #define THRUSTMASTER_USAGE_FF (HID_UP_GENDESK | 0xbb) | 39 | #define THRUSTMASTER_USAGE_FF (HID_UP_GENDESK | 0xbb) |
40 | 40 | ||
41 | struct dev_type { | ||
42 | u16 idVendor; | ||
43 | u16 idProduct; | ||
44 | const signed short *ff; | ||
45 | }; | ||
46 | |||
47 | static const signed short ff_rumble[] = { | 41 | static const signed short ff_rumble[] = { |
48 | FF_RUMBLE, | 42 | FF_RUMBLE, |
49 | -1 | 43 | -1 |
@@ -54,21 +48,13 @@ static const signed short ff_joystick[] = { | |||
54 | -1 | 48 | -1 |
55 | }; | 49 | }; |
56 | 50 | ||
57 | static const struct dev_type devices[] = { | ||
58 | { 0x44f, 0xb300, ff_rumble }, | ||
59 | { 0x44f, 0xb304, ff_rumble }, | ||
60 | { 0x44f, 0xb651, ff_rumble }, /* FGT Rumble Force Wheel */ | ||
61 | { 0x44f, 0xb654, ff_joystick }, /* FGT Force Feedback Wheel */ | ||
62 | }; | ||
63 | |||
64 | struct tmff_device { | 51 | struct tmff_device { |
65 | struct hid_report *report; | 52 | struct hid_report *report; |
66 | struct hid_field *ff_field; | 53 | struct hid_field *ff_field; |
67 | }; | 54 | }; |
68 | 55 | ||
69 | /* Changes values from 0 to 0xffff into values from minimum to maximum */ | 56 | /* Changes values from 0 to 0xffff into values from minimum to maximum */ |
70 | static inline int hid_tmff_scale_u16(unsigned int in, | 57 | static inline int tmff_scale_u16(unsigned int in, int minimum, int maximum) |
71 | int minimum, int maximum) | ||
72 | { | 58 | { |
73 | int ret; | 59 | int ret; |
74 | 60 | ||
@@ -81,8 +67,7 @@ static inline int hid_tmff_scale_u16(unsigned int in, | |||
81 | } | 67 | } |
82 | 68 | ||
83 | /* Changes values from -0x80 to 0x7f into values from minimum to maximum */ | 69 | /* Changes values from -0x80 to 0x7f into values from minimum to maximum */ |
84 | static inline int hid_tmff_scale_s8(int in, | 70 | static inline int tmff_scale_s8(int in, int minimum, int maximum) |
85 | int minimum, int maximum) | ||
86 | { | 71 | { |
87 | int ret; | 72 | int ret; |
88 | 73 | ||
@@ -94,7 +79,8 @@ static inline int hid_tmff_scale_s8(int in, | |||
94 | return ret; | 79 | return ret; |
95 | } | 80 | } |
96 | 81 | ||
97 | static int hid_tmff_play(struct input_dev *dev, void *data, struct ff_effect *effect) | 82 | static int tmff_play(struct input_dev *dev, void *data, |
83 | struct ff_effect *effect) | ||
98 | { | 84 | { |
99 | struct hid_device *hid = input_get_drvdata(dev); | 85 | struct hid_device *hid = input_get_drvdata(dev); |
100 | struct tmff_device *tmff = data; | 86 | struct tmff_device *tmff = data; |
@@ -104,10 +90,10 @@ static int hid_tmff_play(struct input_dev *dev, void *data, struct ff_effect *ef | |||
104 | 90 | ||
105 | switch (effect->type) { | 91 | switch (effect->type) { |
106 | case FF_CONSTANT: | 92 | case FF_CONSTANT: |
107 | x = hid_tmff_scale_s8(effect->u.ramp.start_level, | 93 | x = tmff_scale_s8(effect->u.ramp.start_level, |
108 | ff_field->logical_minimum, | 94 | ff_field->logical_minimum, |
109 | ff_field->logical_maximum); | 95 | ff_field->logical_maximum); |
110 | y = hid_tmff_scale_s8(effect->u.ramp.end_level, | 96 | y = tmff_scale_s8(effect->u.ramp.end_level, |
111 | ff_field->logical_minimum, | 97 | ff_field->logical_minimum, |
112 | ff_field->logical_maximum); | 98 | ff_field->logical_maximum); |
113 | 99 | ||
@@ -118,10 +104,10 @@ static int hid_tmff_play(struct input_dev *dev, void *data, struct ff_effect *ef | |||
118 | break; | 104 | break; |
119 | 105 | ||
120 | case FF_RUMBLE: | 106 | case FF_RUMBLE: |
121 | left = hid_tmff_scale_u16(effect->u.rumble.weak_magnitude, | 107 | left = tmff_scale_u16(effect->u.rumble.weak_magnitude, |
122 | ff_field->logical_minimum, | 108 | ff_field->logical_minimum, |
123 | ff_field->logical_maximum); | 109 | ff_field->logical_maximum); |
124 | right = hid_tmff_scale_u16(effect->u.rumble.strong_magnitude, | 110 | right = tmff_scale_u16(effect->u.rumble.strong_magnitude, |
125 | ff_field->logical_minimum, | 111 | ff_field->logical_minimum, |
126 | ff_field->logical_maximum); | 112 | ff_field->logical_maximum); |
127 | 113 | ||
@@ -134,14 +120,14 @@ static int hid_tmff_play(struct input_dev *dev, void *data, struct ff_effect *ef | |||
134 | return 0; | 120 | return 0; |
135 | } | 121 | } |
136 | 122 | ||
137 | int hid_tmff_init(struct hid_device *hid) | 123 | static int tmff_init(struct hid_device *hid, const signed short *ff_bits) |
138 | { | 124 | { |
139 | struct tmff_device *tmff; | 125 | struct tmff_device *tmff; |
140 | struct hid_report *report; | 126 | struct hid_report *report; |
141 | struct list_head *report_list; | 127 | struct list_head *report_list; |
142 | struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); | 128 | struct hid_input *hidinput = list_entry(hid->inputs.next, |
129 | struct hid_input, list); | ||
143 | struct input_dev *input_dev = hidinput->input; | 130 | struct input_dev *input_dev = hidinput->input; |
144 | const signed short *ff_bits = ff_joystick; | ||
145 | int error; | 131 | int error; |
146 | int i; | 132 | int i; |
147 | 133 | ||
@@ -163,63 +149,121 @@ int hid_tmff_init(struct hid_device *hid) | |||
163 | switch (field->usage[0].hid) { | 149 | switch (field->usage[0].hid) { |
164 | case THRUSTMASTER_USAGE_FF: | 150 | case THRUSTMASTER_USAGE_FF: |
165 | if (field->report_count < 2) { | 151 | if (field->report_count < 2) { |
166 | warn("ignoring FF field with report_count < 2"); | 152 | dev_warn(&hid->dev, "ignoring FF field " |
153 | "with report_count < 2\n"); | ||
167 | continue; | 154 | continue; |
168 | } | 155 | } |
169 | 156 | ||
170 | if (field->logical_maximum == field->logical_minimum) { | 157 | if (field->logical_maximum == |
171 | warn("ignoring FF field with logical_maximum == logical_minimum"); | 158 | field->logical_minimum) { |
159 | dev_warn(&hid->dev, "ignoring FF field " | ||
160 | "with logical_maximum " | ||
161 | "== logical_minimum\n"); | ||
172 | continue; | 162 | continue; |
173 | } | 163 | } |
174 | 164 | ||
175 | if (tmff->report && tmff->report != report) { | 165 | if (tmff->report && tmff->report != report) { |
176 | warn("ignoring FF field in other report"); | 166 | dev_warn(&hid->dev, "ignoring FF field " |
167 | "in other report\n"); | ||
177 | continue; | 168 | continue; |
178 | } | 169 | } |
179 | 170 | ||
180 | if (tmff->ff_field && tmff->ff_field != field) { | 171 | if (tmff->ff_field && tmff->ff_field != field) { |
181 | warn("ignoring duplicate FF field"); | 172 | dev_warn(&hid->dev, "ignoring " |
173 | "duplicate FF field\n"); | ||
182 | continue; | 174 | continue; |
183 | } | 175 | } |
184 | 176 | ||
185 | tmff->report = report; | 177 | tmff->report = report; |
186 | tmff->ff_field = field; | 178 | tmff->ff_field = field; |
187 | 179 | ||
188 | for (i = 0; i < ARRAY_SIZE(devices); i++) { | ||
189 | if (input_dev->id.vendor == devices[i].idVendor && | ||
190 | input_dev->id.product == devices[i].idProduct) { | ||
191 | ff_bits = devices[i].ff; | ||
192 | break; | ||
193 | } | ||
194 | } | ||
195 | |||
196 | for (i = 0; ff_bits[i] >= 0; i++) | 180 | for (i = 0; ff_bits[i] >= 0; i++) |
197 | set_bit(ff_bits[i], input_dev->ffbit); | 181 | set_bit(ff_bits[i], input_dev->ffbit); |
198 | 182 | ||
199 | break; | 183 | break; |
200 | 184 | ||
201 | default: | 185 | default: |
202 | warn("ignoring unknown output usage %08x", field->usage[0].hid); | 186 | dev_warn(&hid->dev, "ignoring unknown output " |
187 | "usage %08x\n", | ||
188 | field->usage[0].hid); | ||
203 | continue; | 189 | continue; |
204 | } | 190 | } |
205 | } | 191 | } |
206 | } | 192 | } |
207 | 193 | ||
208 | if (!tmff->report) { | 194 | if (!tmff->report) { |
209 | err("cant find FF field in output reports\n"); | 195 | dev_err(&hid->dev, "can't find FF field in output reports\n"); |
210 | error = -ENODEV; | 196 | error = -ENODEV; |
211 | goto fail; | 197 | goto fail; |
212 | } | 198 | } |
213 | 199 | ||
214 | error = input_ff_create_memless(input_dev, tmff, hid_tmff_play); | 200 | error = input_ff_create_memless(input_dev, tmff, tmff_play); |
215 | if (error) | 201 | if (error) |
216 | goto fail; | 202 | goto fail; |
217 | 203 | ||
218 | info("Force feedback for ThrustMaster devices by Zinx Verituse <zinx@epicsol.org>"); | 204 | dev_info(&hid->dev, "force feedback for ThrustMaster devices by Zinx " |
205 | "Verituse <zinx@epicsol.org>"); | ||
219 | return 0; | 206 | return 0; |
220 | 207 | ||
221 | fail: | 208 | fail: |
222 | kfree(tmff); | 209 | kfree(tmff); |
223 | return error; | 210 | return error; |
224 | } | 211 | } |
225 | 212 | ||
213 | static int tm_probe(struct hid_device *hdev, const struct hid_device_id *id) | ||
214 | { | ||
215 | int ret; | ||
216 | |||
217 | ret = hid_parse(hdev); | ||
218 | if (ret) { | ||
219 | dev_err(&hdev->dev, "parse failed\n"); | ||
220 | goto err; | ||
221 | } | ||
222 | |||
223 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); | ||
224 | if (ret) { | ||
225 | dev_err(&hdev->dev, "hw start failed\n"); | ||
226 | goto err; | ||
227 | } | ||
228 | |||
229 | tmff_init(hdev, (void *)id->driver_data); | ||
230 | |||
231 | return 0; | ||
232 | err: | ||
233 | return ret; | ||
234 | } | ||
235 | |||
236 | static const struct hid_device_id tm_devices[] = { | ||
237 | { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300), | ||
238 | .driver_data = (unsigned long)ff_rumble }, | ||
239 | { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304), | ||
240 | .driver_data = (unsigned long)ff_rumble }, | ||
241 | { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651), /* FGT Rumble Force Wheel */ | ||
242 | .driver_data = (unsigned long)ff_rumble }, | ||
243 | { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654), /* FGT Force Feedback Wheel */ | ||
244 | .driver_data = (unsigned long)ff_joystick }, | ||
245 | { } | ||
246 | }; | ||
247 | MODULE_DEVICE_TABLE(hid, tm_devices); | ||
248 | |||
249 | static struct hid_driver tm_driver = { | ||
250 | .name = "thrustmaster", | ||
251 | .id_table = tm_devices, | ||
252 | .probe = tm_probe, | ||
253 | }; | ||
254 | |||
255 | static int tm_init(void) | ||
256 | { | ||
257 | return hid_register_driver(&tm_driver); | ||
258 | } | ||
259 | |||
260 | static void tm_exit(void) | ||
261 | { | ||
262 | hid_unregister_driver(&tm_driver); | ||
263 | } | ||
264 | |||
265 | module_init(tm_init); | ||
266 | module_exit(tm_exit); | ||
267 | MODULE_LICENSE("GPL"); | ||
268 | |||
269 | HID_COMPAT_LOAD_DRIVER(thrustmaster); | ||
diff --git a/drivers/hid/usbhid/hid-zpff.c b/drivers/hid/hid-zpff.c index 5a688274f6a3..ea82f3718b21 100644 --- a/drivers/hid/usbhid/hid-zpff.c +++ b/drivers/hid/hid-zpff.c | |||
@@ -21,16 +21,19 @@ | |||
21 | */ | 21 | */ |
22 | 22 | ||
23 | 23 | ||
24 | #include <linux/hid.h> | ||
24 | #include <linux/input.h> | 25 | #include <linux/input.h> |
25 | #include <linux/usb.h> | 26 | #include <linux/usb.h> |
26 | #include <linux/hid.h> | 27 | |
27 | #include "usbhid.h" | 28 | #include "hid-ids.h" |
29 | |||
30 | #include "usbhid/usbhid.h" | ||
28 | 31 | ||
29 | struct zpff_device { | 32 | struct zpff_device { |
30 | struct hid_report *report; | 33 | struct hid_report *report; |
31 | }; | 34 | }; |
32 | 35 | ||
33 | static int hid_zpff_play(struct input_dev *dev, void *data, | 36 | static int zpff_play(struct input_dev *dev, void *data, |
34 | struct ff_effect *effect) | 37 | struct ff_effect *effect) |
35 | { | 38 | { |
36 | struct hid_device *hid = input_get_drvdata(dev); | 39 | struct hid_device *hid = input_get_drvdata(dev); |
@@ -58,7 +61,7 @@ static int hid_zpff_play(struct input_dev *dev, void *data, | |||
58 | return 0; | 61 | return 0; |
59 | } | 62 | } |
60 | 63 | ||
61 | int hid_zpff_init(struct hid_device *hid) | 64 | static int zpff_init(struct hid_device *hid) |
62 | { | 65 | { |
63 | struct zpff_device *zpff; | 66 | struct zpff_device *zpff; |
64 | struct hid_report *report; | 67 | struct hid_report *report; |
@@ -70,14 +73,14 @@ int hid_zpff_init(struct hid_device *hid) | |||
70 | int error; | 73 | int error; |
71 | 74 | ||
72 | if (list_empty(report_list)) { | 75 | if (list_empty(report_list)) { |
73 | printk(KERN_ERR "hid-zpff: no output report found\n"); | 76 | dev_err(&hid->dev, "no output report found\n"); |
74 | return -ENODEV; | 77 | return -ENODEV; |
75 | } | 78 | } |
76 | 79 | ||
77 | report = list_entry(report_list->next, struct hid_report, list); | 80 | report = list_entry(report_list->next, struct hid_report, list); |
78 | 81 | ||
79 | if (report->maxfield < 4) { | 82 | if (report->maxfield < 4) { |
80 | printk(KERN_ERR "hid-zpff: not enough fields in report\n"); | 83 | dev_err(&hid->dev, "not enough fields in report\n"); |
81 | return -ENODEV; | 84 | return -ENODEV; |
82 | } | 85 | } |
83 | 86 | ||
@@ -87,7 +90,7 @@ int hid_zpff_init(struct hid_device *hid) | |||
87 | 90 | ||
88 | set_bit(FF_RUMBLE, dev->ffbit); | 91 | set_bit(FF_RUMBLE, dev->ffbit); |
89 | 92 | ||
90 | error = input_ff_create_memless(dev, zpff, hid_zpff_play); | 93 | error = input_ff_create_memless(dev, zpff, zpff_play); |
91 | if (error) { | 94 | if (error) { |
92 | kfree(zpff); | 95 | kfree(zpff); |
93 | return error; | 96 | return error; |
@@ -100,8 +103,60 @@ int hid_zpff_init(struct hid_device *hid) | |||
100 | zpff->report->field[3]->value[0] = 0x00; | 103 | zpff->report->field[3]->value[0] = 0x00; |
101 | usbhid_submit_report(hid, zpff->report, USB_DIR_OUT); | 104 | usbhid_submit_report(hid, zpff->report, USB_DIR_OUT); |
102 | 105 | ||
103 | printk(KERN_INFO "Force feedback for Zeroplus based devices by " | 106 | dev_info(&hid->dev, "force feedback for Zeroplus based devices by " |
104 | "Anssi Hannula <anssi.hannula@gmail.com>\n"); | 107 | "Anssi Hannula <anssi.hannula@gmail.com>\n"); |
105 | 108 | ||
106 | return 0; | 109 | return 0; |
107 | } | 110 | } |
111 | |||
112 | static int zp_probe(struct hid_device *hdev, const struct hid_device_id *id) | ||
113 | { | ||
114 | int ret; | ||
115 | |||
116 | ret = hid_parse(hdev); | ||
117 | if (ret) { | ||
118 | dev_err(&hdev->dev, "parse failed\n"); | ||
119 | goto err; | ||
120 | } | ||
121 | |||
122 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); | ||
123 | if (ret) { | ||
124 | dev_err(&hdev->dev, "hw start failed\n"); | ||
125 | goto err; | ||
126 | } | ||
127 | |||
128 | zpff_init(hdev); | ||
129 | |||
130 | return 0; | ||
131 | err: | ||
132 | return ret; | ||
133 | } | ||
134 | |||
135 | static const struct hid_device_id zp_devices[] = { | ||
136 | { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) }, | ||
137 | { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) }, | ||
138 | { } | ||
139 | }; | ||
140 | MODULE_DEVICE_TABLE(hid, zp_devices); | ||
141 | |||
142 | static struct hid_driver zp_driver = { | ||
143 | .name = "zeroplus", | ||
144 | .id_table = zp_devices, | ||
145 | .probe = zp_probe, | ||
146 | }; | ||
147 | |||
148 | static int zp_init(void) | ||
149 | { | ||
150 | return hid_register_driver(&zp_driver); | ||
151 | } | ||
152 | |||
153 | static void zp_exit(void) | ||
154 | { | ||
155 | hid_unregister_driver(&zp_driver); | ||
156 | } | ||
157 | |||
158 | module_init(zp_init); | ||
159 | module_exit(zp_exit); | ||
160 | MODULE_LICENSE("GPL"); | ||
161 | |||
162 | HID_COMPAT_LOAD_DRIVER(zeroplus); | ||
diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c index c40f0403edaf..497e0d1dd3c3 100644 --- a/drivers/hid/hidraw.c +++ b/drivers/hid/hidraw.c | |||
@@ -113,7 +113,7 @@ static ssize_t hidraw_write(struct file *file, const char __user *buffer, size_t | |||
113 | if (!dev->hid_output_raw_report) | 113 | if (!dev->hid_output_raw_report) |
114 | return -ENODEV; | 114 | return -ENODEV; |
115 | 115 | ||
116 | if (count > HID_MIN_BUFFER_SIZE) { | 116 | if (count > HID_MAX_BUFFER_SIZE) { |
117 | printk(KERN_WARNING "hidraw: pid %d passed too large report\n", | 117 | printk(KERN_WARNING "hidraw: pid %d passed too large report\n", |
118 | task_pid_nr(current)); | 118 | task_pid_nr(current)); |
119 | return -EINVAL; | 119 | return -EINVAL; |
@@ -181,7 +181,7 @@ static int hidraw_open(struct inode *inode, struct file *file) | |||
181 | 181 | ||
182 | dev = hidraw_table[minor]; | 182 | dev = hidraw_table[minor]; |
183 | if (!dev->open++) | 183 | if (!dev->open++) |
184 | dev->hid->hid_open(dev->hid); | 184 | dev->hid->ll_driver->open(dev->hid); |
185 | 185 | ||
186 | out_unlock: | 186 | out_unlock: |
187 | spin_unlock(&minors_lock); | 187 | spin_unlock(&minors_lock); |
@@ -207,7 +207,7 @@ static int hidraw_release(struct inode * inode, struct file * file) | |||
207 | dev = hidraw_table[minor]; | 207 | dev = hidraw_table[minor]; |
208 | if (!dev->open--) { | 208 | if (!dev->open--) { |
209 | if (list->hidraw->exist) | 209 | if (list->hidraw->exist) |
210 | dev->hid->hid_close(dev->hid); | 210 | dev->hid->ll_driver->close(dev->hid); |
211 | else | 211 | else |
212 | kfree(list->hidraw); | 212 | kfree(list->hidraw); |
213 | } | 213 | } |
@@ -367,7 +367,7 @@ void hidraw_disconnect(struct hid_device *hid) | |||
367 | device_destroy(hidraw_class, MKDEV(hidraw_major, hidraw->minor)); | 367 | device_destroy(hidraw_class, MKDEV(hidraw_major, hidraw->minor)); |
368 | 368 | ||
369 | if (hidraw->open) { | 369 | if (hidraw->open) { |
370 | hid->hid_close(hid); | 370 | hid->ll_driver->close(hid); |
371 | wake_up_interruptible(&hidraw->wait); | 371 | wake_up_interruptible(&hidraw->wait); |
372 | } else { | 372 | } else { |
373 | kfree(hidraw); | 373 | kfree(hidraw); |
diff --git a/drivers/hid/usbhid/Kconfig b/drivers/hid/usbhid/Kconfig index 18f09104765c..5d9aa95fc3ef 100644 --- a/drivers/hid/usbhid/Kconfig +++ b/drivers/hid/usbhid/Kconfig | |||
@@ -24,88 +24,13 @@ config USB_HID | |||
24 | comment "Input core support is needed for USB HID input layer or HIDBP support" | 24 | comment "Input core support is needed for USB HID input layer or HIDBP support" |
25 | depends on USB_HID && INPUT=n | 25 | depends on USB_HID && INPUT=n |
26 | 26 | ||
27 | config USB_HIDINPUT_POWERBOOK | ||
28 | bool "Enable support for Apple laptop/aluminum USB special keys" | ||
29 | default n | ||
30 | depends on USB_HID | ||
31 | help | ||
32 | Say Y here if you want support for the special keys (Fn, Numlock) on | ||
33 | Apple iBooks, PowerBooks, MacBooks, MacBook Pros and aluminum USB | ||
34 | keyboards. | ||
35 | |||
36 | If unsure, say N. | ||
37 | |||
38 | config HID_FF | ||
39 | bool "Force feedback support (EXPERIMENTAL)" | ||
40 | depends on USB_HID && EXPERIMENTAL | ||
41 | help | ||
42 | Say Y here is you want force feedback support for a few HID devices. | ||
43 | See below for a list of supported devices. | ||
44 | |||
45 | See <file:Documentation/input/ff.txt> for a description of the force | ||
46 | feedback API. | ||
47 | |||
48 | If unsure, say N. | ||
49 | |||
50 | config HID_PID | 27 | config HID_PID |
51 | bool "PID device support" | 28 | bool "PID device support" |
52 | depends on HID_FF | ||
53 | help | 29 | help |
54 | Say Y here if you have a PID-compliant device and wish to enable force | 30 | Say Y here if you have a PID-compliant device and wish to enable force |
55 | feedback for it. Microsoft Sidewinder Force Feedback 2 is one of such | 31 | feedback for it. Microsoft Sidewinder Force Feedback 2 is one of such |
56 | devices. | 32 | devices. |
57 | 33 | ||
58 | config LOGITECH_FF | ||
59 | bool "Logitech devices support" | ||
60 | depends on HID_FF | ||
61 | select INPUT_FF_MEMLESS if USB_HID | ||
62 | help | ||
63 | Say Y here if you have one of these devices: | ||
64 | - Logitech WingMan Cordless RumblePad | ||
65 | - Logitech WingMan Cordless RumblePad 2 | ||
66 | - Logitech WingMan Force 3D | ||
67 | - Logitech Formula Force EX | ||
68 | - Logitech MOMO Force wheel | ||
69 | |||
70 | and if you want to enable force feedback for them. | ||
71 | Note: if you say N here, this device will still be supported, but without | ||
72 | force feedback. | ||
73 | |||
74 | config LOGIRUMBLEPAD2_FF | ||
75 | bool "Logitech Rumblepad 2 support" | ||
76 | depends on HID_FF | ||
77 | select INPUT_FF_MEMLESS if USB_HID | ||
78 | help | ||
79 | Say Y here if you want to enable force feedback support for Logitech | ||
80 | Rumblepad 2 devices. | ||
81 | |||
82 | config PANTHERLORD_FF | ||
83 | bool "PantherLord/GreenAsia based device support" | ||
84 | depends on HID_FF | ||
85 | select INPUT_FF_MEMLESS if USB_HID | ||
86 | help | ||
87 | Say Y here if you have a PantherLord/GreenAsia based game controller | ||
88 | or adapter and want to enable force feedback support for it. | ||
89 | |||
90 | config THRUSTMASTER_FF | ||
91 | bool "ThrustMaster devices support" | ||
92 | depends on HID_FF | ||
93 | select INPUT_FF_MEMLESS if USB_HID | ||
94 | help | ||
95 | Say Y here if you have a THRUSTMASTER FireStore Dual Power 2 or | ||
96 | a THRUSTMASTER Ferrari GT Rumble Force or Force Feedback Wheel, | ||
97 | and want to enable force feedback support for it. | ||
98 | Note: if you say N here, this device will still be supported, but without | ||
99 | force feedback. | ||
100 | |||
101 | config ZEROPLUS_FF | ||
102 | bool "Zeroplus based game controller support" | ||
103 | depends on HID_FF | ||
104 | select INPUT_FF_MEMLESS if USB_HID | ||
105 | help | ||
106 | Say Y here if you have a Zeroplus based game controller and want to | ||
107 | enable force feedback for it. | ||
108 | |||
109 | config USB_HIDDEV | 34 | config USB_HIDDEV |
110 | bool "/dev/hiddev raw HID device support" | 35 | bool "/dev/hiddev raw HID device support" |
111 | depends on USB_HID | 36 | depends on USB_HID |
diff --git a/drivers/hid/usbhid/Makefile b/drivers/hid/usbhid/Makefile index 00a7b7090192..1329ecb37a1c 100644 --- a/drivers/hid/usbhid/Makefile +++ b/drivers/hid/usbhid/Makefile | |||
@@ -13,24 +13,6 @@ endif | |||
13 | ifeq ($(CONFIG_HID_PID),y) | 13 | ifeq ($(CONFIG_HID_PID),y) |
14 | usbhid-objs += hid-pidff.o | 14 | usbhid-objs += hid-pidff.o |
15 | endif | 15 | endif |
16 | ifeq ($(CONFIG_LOGITECH_FF),y) | ||
17 | usbhid-objs += hid-lgff.o | ||
18 | endif | ||
19 | ifeq ($(CONFIG_LOGIRUMBLEPAD2_FF),y) | ||
20 | usbhid-objs += hid-lg2ff.o | ||
21 | endif | ||
22 | ifeq ($(CONFIG_PANTHERLORD_FF),y) | ||
23 | usbhid-objs += hid-plff.o | ||
24 | endif | ||
25 | ifeq ($(CONFIG_THRUSTMASTER_FF),y) | ||
26 | usbhid-objs += hid-tmff.o | ||
27 | endif | ||
28 | ifeq ($(CONFIG_ZEROPLUS_FF),y) | ||
29 | usbhid-objs += hid-zpff.o | ||
30 | endif | ||
31 | ifeq ($(CONFIG_HID_FF),y) | ||
32 | usbhid-objs += hid-ff.o | ||
33 | endif | ||
34 | 16 | ||
35 | obj-$(CONFIG_USB_HID) += usbhid.o | 17 | obj-$(CONFIG_USB_HID) += usbhid.o |
36 | obj-$(CONFIG_USB_KBD) += usbkbd.o | 18 | obj-$(CONFIG_USB_KBD) += usbkbd.o |
diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c index 27fe4d8912cb..1d3b8a394d46 100644 --- a/drivers/hid/usbhid/hid-core.c +++ b/drivers/hid/usbhid/hid-core.c | |||
@@ -44,8 +44,6 @@ | |||
44 | #define DRIVER_DESC "USB HID core driver" | 44 | #define DRIVER_DESC "USB HID core driver" |
45 | #define DRIVER_LICENSE "GPL" | 45 | #define DRIVER_LICENSE "GPL" |
46 | 46 | ||
47 | static char *hid_types[] = {"Device", "Pointer", "Mouse", "Device", "Joystick", | ||
48 | "Gamepad", "Keyboard", "Keypad", "Multi-Axis Controller"}; | ||
49 | /* | 47 | /* |
50 | * Module parameters. | 48 | * Module parameters. |
51 | */ | 49 | */ |
@@ -61,12 +59,6 @@ MODULE_PARM_DESC(quirks, "Add/modify USB HID quirks by specifying " | |||
61 | " quirks=vendorID:productID:quirks" | 59 | " quirks=vendorID:productID:quirks" |
62 | " where vendorID, productID, and quirks are all in" | 60 | " where vendorID, productID, and quirks are all in" |
63 | " 0x-prefixed hex"); | 61 | " 0x-prefixed hex"); |
64 | static char *rdesc_quirks_param[MAX_USBHID_BOOT_QUIRKS] = { [ 0 ... (MAX_USBHID_BOOT_QUIRKS - 1) ] = NULL }; | ||
65 | module_param_array_named(rdesc_quirks, rdesc_quirks_param, charp, NULL, 0444); | ||
66 | MODULE_PARM_DESC(rdesc_quirks, "Add/modify report descriptor quirks by specifying " | ||
67 | " rdesc_quirks=vendorID:productID:rdesc_quirks" | ||
68 | " where vendorID, productID, and rdesc_quirks are all in" | ||
69 | " 0x-prefixed hex"); | ||
70 | /* | 62 | /* |
71 | * Input submission and I/O error handler. | 63 | * Input submission and I/O error handler. |
72 | */ | 64 | */ |
@@ -197,31 +189,32 @@ static void hid_irq_in(struct urb *urb) | |||
197 | int status; | 189 | int status; |
198 | 190 | ||
199 | switch (urb->status) { | 191 | switch (urb->status) { |
200 | case 0: /* success */ | 192 | case 0: /* success */ |
201 | usbhid->retry_delay = 0; | 193 | usbhid->retry_delay = 0; |
202 | hid_input_report(urb->context, HID_INPUT_REPORT, | 194 | hid_input_report(urb->context, HID_INPUT_REPORT, |
203 | urb->transfer_buffer, | 195 | urb->transfer_buffer, |
204 | urb->actual_length, 1); | 196 | urb->actual_length, 1); |
205 | break; | 197 | break; |
206 | case -EPIPE: /* stall */ | 198 | case -EPIPE: /* stall */ |
207 | clear_bit(HID_IN_RUNNING, &usbhid->iofl); | 199 | clear_bit(HID_IN_RUNNING, &usbhid->iofl); |
208 | set_bit(HID_CLEAR_HALT, &usbhid->iofl); | 200 | set_bit(HID_CLEAR_HALT, &usbhid->iofl); |
209 | schedule_work(&usbhid->reset_work); | 201 | schedule_work(&usbhid->reset_work); |
210 | return; | 202 | return; |
211 | case -ECONNRESET: /* unlink */ | 203 | case -ECONNRESET: /* unlink */ |
212 | case -ENOENT: | 204 | case -ENOENT: |
213 | case -ESHUTDOWN: /* unplug */ | 205 | case -ESHUTDOWN: /* unplug */ |
214 | clear_bit(HID_IN_RUNNING, &usbhid->iofl); | 206 | clear_bit(HID_IN_RUNNING, &usbhid->iofl); |
215 | return; | 207 | return; |
216 | case -EILSEQ: /* protocol error or unplug */ | 208 | case -EILSEQ: /* protocol error or unplug */ |
217 | case -EPROTO: /* protocol error or unplug */ | 209 | case -EPROTO: /* protocol error or unplug */ |
218 | case -ETIME: /* protocol error or unplug */ | 210 | case -ETIME: /* protocol error or unplug */ |
219 | case -ETIMEDOUT: /* Should never happen, but... */ | 211 | case -ETIMEDOUT: /* Should never happen, but... */ |
220 | clear_bit(HID_IN_RUNNING, &usbhid->iofl); | 212 | clear_bit(HID_IN_RUNNING, &usbhid->iofl); |
221 | hid_io_error(hid); | 213 | hid_io_error(hid); |
222 | return; | 214 | return; |
223 | default: /* error */ | 215 | default: /* error */ |
224 | warn("input irq status %d received", urb->status); | 216 | dev_warn(&urb->dev->dev, "input irq status %d " |
217 | "received\n", urb->status); | ||
225 | } | 218 | } |
226 | 219 | ||
227 | status = usb_submit_urb(urb, GFP_ATOMIC); | 220 | status = usb_submit_urb(urb, GFP_ATOMIC); |
@@ -240,13 +233,16 @@ static void hid_irq_in(struct urb *urb) | |||
240 | static int hid_submit_out(struct hid_device *hid) | 233 | static int hid_submit_out(struct hid_device *hid) |
241 | { | 234 | { |
242 | struct hid_report *report; | 235 | struct hid_report *report; |
236 | char *raw_report; | ||
243 | struct usbhid_device *usbhid = hid->driver_data; | 237 | struct usbhid_device *usbhid = hid->driver_data; |
244 | 238 | ||
245 | report = usbhid->out[usbhid->outtail]; | 239 | report = usbhid->out[usbhid->outtail].report; |
240 | raw_report = usbhid->out[usbhid->outtail].raw_report; | ||
246 | 241 | ||
247 | hid_output_report(report, usbhid->outbuf); | ||
248 | usbhid->urbout->transfer_buffer_length = ((report->size - 1) >> 3) + 1 + (report->id > 0); | 242 | usbhid->urbout->transfer_buffer_length = ((report->size - 1) >> 3) + 1 + (report->id > 0); |
249 | usbhid->urbout->dev = hid_to_usb_dev(hid); | 243 | usbhid->urbout->dev = hid_to_usb_dev(hid); |
244 | memcpy(usbhid->outbuf, raw_report, usbhid->urbout->transfer_buffer_length); | ||
245 | kfree(raw_report); | ||
250 | 246 | ||
251 | dbg_hid("submitting out urb\n"); | 247 | dbg_hid("submitting out urb\n"); |
252 | 248 | ||
@@ -262,17 +258,20 @@ static int hid_submit_ctrl(struct hid_device *hid) | |||
262 | { | 258 | { |
263 | struct hid_report *report; | 259 | struct hid_report *report; |
264 | unsigned char dir; | 260 | unsigned char dir; |
261 | char *raw_report; | ||
265 | int len; | 262 | int len; |
266 | struct usbhid_device *usbhid = hid->driver_data; | 263 | struct usbhid_device *usbhid = hid->driver_data; |
267 | 264 | ||
268 | report = usbhid->ctrl[usbhid->ctrltail].report; | 265 | report = usbhid->ctrl[usbhid->ctrltail].report; |
266 | raw_report = usbhid->ctrl[usbhid->ctrltail].raw_report; | ||
269 | dir = usbhid->ctrl[usbhid->ctrltail].dir; | 267 | dir = usbhid->ctrl[usbhid->ctrltail].dir; |
270 | 268 | ||
271 | len = ((report->size - 1) >> 3) + 1 + (report->id > 0); | 269 | len = ((report->size - 1) >> 3) + 1 + (report->id > 0); |
272 | if (dir == USB_DIR_OUT) { | 270 | if (dir == USB_DIR_OUT) { |
273 | hid_output_report(report, usbhid->ctrlbuf); | ||
274 | usbhid->urbctrl->pipe = usb_sndctrlpipe(hid_to_usb_dev(hid), 0); | 271 | usbhid->urbctrl->pipe = usb_sndctrlpipe(hid_to_usb_dev(hid), 0); |
275 | usbhid->urbctrl->transfer_buffer_length = len; | 272 | usbhid->urbctrl->transfer_buffer_length = len; |
273 | memcpy(usbhid->ctrlbuf, raw_report, len); | ||
274 | kfree(raw_report); | ||
276 | } else { | 275 | } else { |
277 | int maxpacket, padlen; | 276 | int maxpacket, padlen; |
278 | 277 | ||
@@ -319,17 +318,18 @@ static void hid_irq_out(struct urb *urb) | |||
319 | int unplug = 0; | 318 | int unplug = 0; |
320 | 319 | ||
321 | switch (urb->status) { | 320 | switch (urb->status) { |
322 | case 0: /* success */ | 321 | case 0: /* success */ |
323 | break; | 322 | break; |
324 | case -ESHUTDOWN: /* unplug */ | 323 | case -ESHUTDOWN: /* unplug */ |
325 | unplug = 1; | 324 | unplug = 1; |
326 | case -EILSEQ: /* protocol error or unplug */ | 325 | case -EILSEQ: /* protocol error or unplug */ |
327 | case -EPROTO: /* protocol error or unplug */ | 326 | case -EPROTO: /* protocol error or unplug */ |
328 | case -ECONNRESET: /* unlink */ | 327 | case -ECONNRESET: /* unlink */ |
329 | case -ENOENT: | 328 | case -ENOENT: |
330 | break; | 329 | break; |
331 | default: /* error */ | 330 | default: /* error */ |
332 | warn("output irq status %d received", urb->status); | 331 | dev_warn(&urb->dev->dev, "output irq status %d " |
332 | "received\n", urb->status); | ||
333 | } | 333 | } |
334 | 334 | ||
335 | spin_lock_irqsave(&usbhid->outlock, flags); | 335 | spin_lock_irqsave(&usbhid->outlock, flags); |
@@ -367,21 +367,23 @@ static void hid_ctrl(struct urb *urb) | |||
367 | spin_lock_irqsave(&usbhid->ctrllock, flags); | 367 | spin_lock_irqsave(&usbhid->ctrllock, flags); |
368 | 368 | ||
369 | switch (urb->status) { | 369 | switch (urb->status) { |
370 | case 0: /* success */ | 370 | case 0: /* success */ |
371 | if (usbhid->ctrl[usbhid->ctrltail].dir == USB_DIR_IN) | 371 | if (usbhid->ctrl[usbhid->ctrltail].dir == USB_DIR_IN) |
372 | hid_input_report(urb->context, usbhid->ctrl[usbhid->ctrltail].report->type, | 372 | hid_input_report(urb->context, |
373 | urb->transfer_buffer, urb->actual_length, 0); | 373 | usbhid->ctrl[usbhid->ctrltail].report->type, |
374 | break; | 374 | urb->transfer_buffer, urb->actual_length, 0); |
375 | case -ESHUTDOWN: /* unplug */ | 375 | break; |
376 | unplug = 1; | 376 | case -ESHUTDOWN: /* unplug */ |
377 | case -EILSEQ: /* protocol error or unplug */ | 377 | unplug = 1; |
378 | case -EPROTO: /* protocol error or unplug */ | 378 | case -EILSEQ: /* protocol error or unplug */ |
379 | case -ECONNRESET: /* unlink */ | 379 | case -EPROTO: /* protocol error or unplug */ |
380 | case -ENOENT: | 380 | case -ECONNRESET: /* unlink */ |
381 | case -EPIPE: /* report not available */ | 381 | case -ENOENT: |
382 | break; | 382 | case -EPIPE: /* report not available */ |
383 | default: /* error */ | 383 | break; |
384 | warn("ctrl urb status %d received", urb->status); | 384 | default: /* error */ |
385 | dev_warn(&urb->dev->dev, "ctrl urb status %d " | ||
386 | "received\n", urb->status); | ||
385 | } | 387 | } |
386 | 388 | ||
387 | if (unplug) | 389 | if (unplug) |
@@ -408,6 +410,7 @@ void usbhid_submit_report(struct hid_device *hid, struct hid_report *report, uns | |||
408 | int head; | 410 | int head; |
409 | unsigned long flags; | 411 | unsigned long flags; |
410 | struct usbhid_device *usbhid = hid->driver_data; | 412 | struct usbhid_device *usbhid = hid->driver_data; |
413 | int len = ((report->size - 1) >> 3) + 1 + (report->id > 0); | ||
411 | 414 | ||
412 | if ((hid->quirks & HID_QUIRK_NOGET) && dir == USB_DIR_IN) | 415 | if ((hid->quirks & HID_QUIRK_NOGET) && dir == USB_DIR_IN) |
413 | return; | 416 | return; |
@@ -418,11 +421,18 @@ void usbhid_submit_report(struct hid_device *hid, struct hid_report *report, uns | |||
418 | 421 | ||
419 | if ((head = (usbhid->outhead + 1) & (HID_OUTPUT_FIFO_SIZE - 1)) == usbhid->outtail) { | 422 | if ((head = (usbhid->outhead + 1) & (HID_OUTPUT_FIFO_SIZE - 1)) == usbhid->outtail) { |
420 | spin_unlock_irqrestore(&usbhid->outlock, flags); | 423 | spin_unlock_irqrestore(&usbhid->outlock, flags); |
421 | warn("output queue full"); | 424 | dev_warn(&hid->dev, "output queue full\n"); |
422 | return; | 425 | return; |
423 | } | 426 | } |
424 | 427 | ||
425 | usbhid->out[usbhid->outhead] = report; | 428 | usbhid->out[usbhid->outhead].raw_report = kmalloc(len, GFP_ATOMIC); |
429 | if (!usbhid->out[usbhid->outhead].raw_report) { | ||
430 | spin_unlock_irqrestore(&usbhid->outlock, flags); | ||
431 | warn("output queueing failed"); | ||
432 | return; | ||
433 | } | ||
434 | hid_output_report(report, usbhid->out[usbhid->outhead].raw_report); | ||
435 | usbhid->out[usbhid->outhead].report = report; | ||
426 | usbhid->outhead = head; | 436 | usbhid->outhead = head; |
427 | 437 | ||
428 | if (!test_and_set_bit(HID_OUT_RUNNING, &usbhid->iofl)) | 438 | if (!test_and_set_bit(HID_OUT_RUNNING, &usbhid->iofl)) |
@@ -437,10 +447,19 @@ void usbhid_submit_report(struct hid_device *hid, struct hid_report *report, uns | |||
437 | 447 | ||
438 | if ((head = (usbhid->ctrlhead + 1) & (HID_CONTROL_FIFO_SIZE - 1)) == usbhid->ctrltail) { | 448 | if ((head = (usbhid->ctrlhead + 1) & (HID_CONTROL_FIFO_SIZE - 1)) == usbhid->ctrltail) { |
439 | spin_unlock_irqrestore(&usbhid->ctrllock, flags); | 449 | spin_unlock_irqrestore(&usbhid->ctrllock, flags); |
440 | warn("control queue full"); | 450 | dev_warn(&hid->dev, "control queue full\n"); |
441 | return; | 451 | return; |
442 | } | 452 | } |
443 | 453 | ||
454 | if (dir == USB_DIR_OUT) { | ||
455 | usbhid->ctrl[usbhid->ctrlhead].raw_report = kmalloc(len, GFP_ATOMIC); | ||
456 | if (!usbhid->ctrl[usbhid->ctrlhead].raw_report) { | ||
457 | spin_unlock_irqrestore(&usbhid->ctrllock, flags); | ||
458 | warn("control queueing failed"); | ||
459 | return; | ||
460 | } | ||
461 | hid_output_report(report, usbhid->ctrl[usbhid->ctrlhead].raw_report); | ||
462 | } | ||
444 | usbhid->ctrl[usbhid->ctrlhead].report = report; | 463 | usbhid->ctrl[usbhid->ctrlhead].report = report; |
445 | usbhid->ctrl[usbhid->ctrlhead].dir = dir; | 464 | usbhid->ctrl[usbhid->ctrlhead].dir = dir; |
446 | usbhid->ctrlhead = head; | 465 | usbhid->ctrlhead = head; |
@@ -451,6 +470,7 @@ void usbhid_submit_report(struct hid_device *hid, struct hid_report *report, uns | |||
451 | 470 | ||
452 | spin_unlock_irqrestore(&usbhid->ctrllock, flags); | 471 | spin_unlock_irqrestore(&usbhid->ctrllock, flags); |
453 | } | 472 | } |
473 | EXPORT_SYMBOL_GPL(usbhid_submit_report); | ||
454 | 474 | ||
455 | static int usb_hidinput_input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) | 475 | static int usb_hidinput_input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) |
456 | { | 476 | { |
@@ -465,7 +485,7 @@ static int usb_hidinput_input_event(struct input_dev *dev, unsigned int type, un | |||
465 | return -1; | 485 | return -1; |
466 | 486 | ||
467 | if ((offset = hidinput_find_field(hid, type, code, &field)) == -1) { | 487 | if ((offset = hidinput_find_field(hid, type, code, &field)) == -1) { |
468 | warn("event field not found"); | 488 | dev_warn(&dev->dev, "event field not found\n"); |
469 | return -1; | 489 | return -1; |
470 | } | 490 | } |
471 | 491 | ||
@@ -568,7 +588,7 @@ void usbhid_init_reports(struct hid_device *hid) | |||
568 | } | 588 | } |
569 | 589 | ||
570 | if (err) | 590 | if (err) |
571 | warn("timeout initializing reports"); | 591 | dev_warn(&hid->dev, "timeout initializing reports\n"); |
572 | } | 592 | } |
573 | 593 | ||
574 | /* | 594 | /* |
@@ -598,7 +618,7 @@ static int hid_find_field_early(struct hid_device *hid, unsigned int page, | |||
598 | return -1; | 618 | return -1; |
599 | } | 619 | } |
600 | 620 | ||
601 | static void usbhid_set_leds(struct hid_device *hid) | 621 | void usbhid_set_leds(struct hid_device *hid) |
602 | { | 622 | { |
603 | struct hid_field *field; | 623 | struct hid_field *field; |
604 | int offset; | 624 | int offset; |
@@ -608,6 +628,7 @@ static void usbhid_set_leds(struct hid_device *hid) | |||
608 | usbhid_submit_report(hid, field->report, USB_DIR_OUT); | 628 | usbhid_submit_report(hid, field->report, USB_DIR_OUT); |
609 | } | 629 | } |
610 | } | 630 | } |
631 | EXPORT_SYMBOL_GPL(usbhid_set_leds); | ||
611 | 632 | ||
612 | /* | 633 | /* |
613 | * Traverse the supplied list of reports and find the longest | 634 | * Traverse the supplied list of reports and find the longest |
@@ -675,43 +696,16 @@ static void hid_free_buffers(struct usb_device *dev, struct hid_device *hid) | |||
675 | usb_buffer_free(dev, usbhid->bufsize, usbhid->ctrlbuf, usbhid->ctrlbuf_dma); | 696 | usb_buffer_free(dev, usbhid->bufsize, usbhid->ctrlbuf, usbhid->ctrlbuf_dma); |
676 | } | 697 | } |
677 | 698 | ||
678 | /* | 699 | static int usbhid_parse(struct hid_device *hid) |
679 | * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller | ||
680 | * to "operational". Without this, the ps3 controller will not report any | ||
681 | * events. | ||
682 | */ | ||
683 | static void hid_fixup_sony_ps3_controller(struct usb_device *dev, int ifnum) | ||
684 | { | ||
685 | int result; | ||
686 | char *buf = kmalloc(18, GFP_KERNEL); | ||
687 | |||
688 | if (!buf) | ||
689 | return; | ||
690 | |||
691 | result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), | ||
692 | HID_REQ_GET_REPORT, | ||
693 | USB_DIR_IN | USB_TYPE_CLASS | | ||
694 | USB_RECIP_INTERFACE, | ||
695 | (3 << 8) | 0xf2, ifnum, buf, 17, | ||
696 | USB_CTRL_GET_TIMEOUT); | ||
697 | |||
698 | if (result < 0) | ||
699 | err_hid("%s failed: %d\n", __func__, result); | ||
700 | |||
701 | kfree(buf); | ||
702 | } | ||
703 | |||
704 | static struct hid_device *usb_hid_configure(struct usb_interface *intf) | ||
705 | { | 700 | { |
701 | struct usb_interface *intf = to_usb_interface(hid->dev.parent); | ||
706 | struct usb_host_interface *interface = intf->cur_altsetting; | 702 | struct usb_host_interface *interface = intf->cur_altsetting; |
707 | struct usb_device *dev = interface_to_usbdev (intf); | 703 | struct usb_device *dev = interface_to_usbdev (intf); |
708 | struct hid_descriptor *hdesc; | 704 | struct hid_descriptor *hdesc; |
709 | struct hid_device *hid; | ||
710 | u32 quirks = 0; | 705 | u32 quirks = 0; |
711 | unsigned int insize = 0, rsize = 0; | 706 | unsigned int rsize = 0; |
712 | char *rdesc; | 707 | char *rdesc; |
713 | int n, len; | 708 | int ret, n; |
714 | struct usbhid_device *usbhid; | ||
715 | 709 | ||
716 | quirks = usbhid_lookup_quirk(le16_to_cpu(dev->descriptor.idVendor), | 710 | quirks = usbhid_lookup_quirk(le16_to_cpu(dev->descriptor.idVendor), |
717 | le16_to_cpu(dev->descriptor.idProduct)); | 711 | le16_to_cpu(dev->descriptor.idProduct)); |
@@ -724,63 +718,75 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf) | |||
724 | quirks |= HID_QUIRK_NOGET; | 718 | quirks |= HID_QUIRK_NOGET; |
725 | } | 719 | } |
726 | 720 | ||
727 | if (quirks & HID_QUIRK_IGNORE) | ||
728 | return NULL; | ||
729 | |||
730 | if ((quirks & HID_QUIRK_IGNORE_MOUSE) && | ||
731 | (interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_MOUSE)) | ||
732 | return NULL; | ||
733 | |||
734 | |||
735 | if (usb_get_extra_descriptor(interface, HID_DT_HID, &hdesc) && | 721 | if (usb_get_extra_descriptor(interface, HID_DT_HID, &hdesc) && |
736 | (!interface->desc.bNumEndpoints || | 722 | (!interface->desc.bNumEndpoints || |
737 | usb_get_extra_descriptor(&interface->endpoint[0], HID_DT_HID, &hdesc))) { | 723 | usb_get_extra_descriptor(&interface->endpoint[0], HID_DT_HID, &hdesc))) { |
738 | dbg_hid("class descriptor not present\n"); | 724 | dbg_hid("class descriptor not present\n"); |
739 | return NULL; | 725 | return -ENODEV; |
740 | } | 726 | } |
741 | 727 | ||
728 | hid->version = le16_to_cpu(hdesc->bcdHID); | ||
729 | hid->country = hdesc->bCountryCode; | ||
730 | |||
742 | for (n = 0; n < hdesc->bNumDescriptors; n++) | 731 | for (n = 0; n < hdesc->bNumDescriptors; n++) |
743 | if (hdesc->desc[n].bDescriptorType == HID_DT_REPORT) | 732 | if (hdesc->desc[n].bDescriptorType == HID_DT_REPORT) |
744 | rsize = le16_to_cpu(hdesc->desc[n].wDescriptorLength); | 733 | rsize = le16_to_cpu(hdesc->desc[n].wDescriptorLength); |
745 | 734 | ||
746 | if (!rsize || rsize > HID_MAX_DESCRIPTOR_SIZE) { | 735 | if (!rsize || rsize > HID_MAX_DESCRIPTOR_SIZE) { |
747 | dbg_hid("weird size of report descriptor (%u)\n", rsize); | 736 | dbg_hid("weird size of report descriptor (%u)\n", rsize); |
748 | return NULL; | 737 | return -EINVAL; |
749 | } | 738 | } |
750 | 739 | ||
751 | if (!(rdesc = kmalloc(rsize, GFP_KERNEL))) { | 740 | if (!(rdesc = kmalloc(rsize, GFP_KERNEL))) { |
752 | dbg_hid("couldn't allocate rdesc memory\n"); | 741 | dbg_hid("couldn't allocate rdesc memory\n"); |
753 | return NULL; | 742 | return -ENOMEM; |
754 | } | 743 | } |
755 | 744 | ||
756 | hid_set_idle(dev, interface->desc.bInterfaceNumber, 0, 0); | 745 | hid_set_idle(dev, interface->desc.bInterfaceNumber, 0, 0); |
757 | 746 | ||
758 | if ((n = hid_get_class_descriptor(dev, interface->desc.bInterfaceNumber, HID_DT_REPORT, rdesc, rsize)) < 0) { | 747 | ret = hid_get_class_descriptor(dev, interface->desc.bInterfaceNumber, |
748 | HID_DT_REPORT, rdesc, rsize); | ||
749 | if (ret < 0) { | ||
759 | dbg_hid("reading report descriptor failed\n"); | 750 | dbg_hid("reading report descriptor failed\n"); |
760 | kfree(rdesc); | 751 | kfree(rdesc); |
761 | return NULL; | 752 | goto err; |
762 | } | 753 | } |
763 | 754 | ||
764 | usbhid_fixup_report_descriptor(le16_to_cpu(dev->descriptor.idVendor), | ||
765 | le16_to_cpu(dev->descriptor.idProduct), rdesc, | ||
766 | rsize, rdesc_quirks_param); | ||
767 | |||
768 | dbg_hid("report descriptor (size %u, read %d) = ", rsize, n); | 755 | dbg_hid("report descriptor (size %u, read %d) = ", rsize, n); |
769 | for (n = 0; n < rsize; n++) | 756 | for (n = 0; n < rsize; n++) |
770 | dbg_hid_line(" %02x", (unsigned char) rdesc[n]); | 757 | dbg_hid_line(" %02x", (unsigned char) rdesc[n]); |
771 | dbg_hid_line("\n"); | 758 | dbg_hid_line("\n"); |
772 | 759 | ||
773 | if (!(hid = hid_parse_report(rdesc, n))) { | 760 | ret = hid_parse_report(hid, rdesc, rsize); |
761 | kfree(rdesc); | ||
762 | if (ret) { | ||
774 | dbg_hid("parsing report descriptor failed\n"); | 763 | dbg_hid("parsing report descriptor failed\n"); |
775 | kfree(rdesc); | 764 | goto err; |
776 | return NULL; | ||
777 | } | 765 | } |
778 | 766 | ||
779 | kfree(rdesc); | ||
780 | hid->quirks = quirks; | 767 | hid->quirks = quirks; |
781 | 768 | ||
782 | if (!(usbhid = kzalloc(sizeof(struct usbhid_device), GFP_KERNEL))) | 769 | return 0; |
783 | goto fail_no_usbhid; | 770 | err: |
771 | return ret; | ||
772 | } | ||
773 | |||
774 | static int usbhid_start(struct hid_device *hid) | ||
775 | { | ||
776 | struct usb_interface *intf = to_usb_interface(hid->dev.parent); | ||
777 | struct usb_host_interface *interface = intf->cur_altsetting; | ||
778 | struct usb_device *dev = interface_to_usbdev(intf); | ||
779 | struct usbhid_device *usbhid; | ||
780 | unsigned int n, insize = 0; | ||
781 | int ret; | ||
782 | |||
783 | WARN_ON(hid->driver_data); | ||
784 | |||
785 | usbhid = kzalloc(sizeof(struct usbhid_device), GFP_KERNEL); | ||
786 | if (usbhid == NULL) { | ||
787 | ret = -ENOMEM; | ||
788 | goto err; | ||
789 | } | ||
784 | 790 | ||
785 | hid->driver_data = usbhid; | 791 | hid->driver_data = usbhid; |
786 | usbhid->hid = hid; | 792 | usbhid->hid = hid; |
@@ -799,28 +805,11 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf) | |||
799 | insize = HID_MAX_BUFFER_SIZE; | 805 | insize = HID_MAX_BUFFER_SIZE; |
800 | 806 | ||
801 | if (hid_alloc_buffers(dev, hid)) { | 807 | if (hid_alloc_buffers(dev, hid)) { |
802 | hid_free_buffers(dev, hid); | 808 | ret = -ENOMEM; |
803 | goto fail; | 809 | goto fail; |
804 | } | 810 | } |
805 | 811 | ||
806 | hid->name[0] = 0; | ||
807 | |||
808 | if (dev->manufacturer) | ||
809 | strlcpy(hid->name, dev->manufacturer, sizeof(hid->name)); | ||
810 | |||
811 | if (dev->product) { | ||
812 | if (dev->manufacturer) | ||
813 | strlcat(hid->name, " ", sizeof(hid->name)); | ||
814 | strlcat(hid->name, dev->product, sizeof(hid->name)); | ||
815 | } | ||
816 | |||
817 | if (!strlen(hid->name)) | ||
818 | snprintf(hid->name, sizeof(hid->name), "HID %04x:%04x", | ||
819 | le16_to_cpu(dev->descriptor.idVendor), | ||
820 | le16_to_cpu(dev->descriptor.idProduct)); | ||
821 | |||
822 | for (n = 0; n < interface->desc.bNumEndpoints; n++) { | 812 | for (n = 0; n < interface->desc.bNumEndpoints; n++) { |
823 | |||
824 | struct usb_endpoint_descriptor *endpoint; | 813 | struct usb_endpoint_descriptor *endpoint; |
825 | int pipe; | 814 | int pipe; |
826 | int interval; | 815 | int interval; |
@@ -832,7 +821,7 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf) | |||
832 | interval = endpoint->bInterval; | 821 | interval = endpoint->bInterval; |
833 | 822 | ||
834 | /* Some vendors give fullspeed interval on highspeed devides */ | 823 | /* Some vendors give fullspeed interval on highspeed devides */ |
835 | if (quirks & HID_QUIRK_FULLSPEED_INTERVAL && | 824 | if (hid->quirks & HID_QUIRK_FULLSPEED_INTERVAL && |
836 | dev->speed == USB_SPEED_HIGH) { | 825 | dev->speed == USB_SPEED_HIGH) { |
837 | interval = fls(endpoint->bInterval*8); | 826 | interval = fls(endpoint->bInterval*8); |
838 | printk(KERN_INFO "%s: Fixing fullspeed to highspeed interval: %d -> %d\n", | 827 | printk(KERN_INFO "%s: Fixing fullspeed to highspeed interval: %d -> %d\n", |
@@ -843,6 +832,7 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf) | |||
843 | if (hid->collection->usage == HID_GD_MOUSE && hid_mousepoll_interval > 0) | 832 | if (hid->collection->usage == HID_GD_MOUSE && hid_mousepoll_interval > 0) |
844 | interval = hid_mousepoll_interval; | 833 | interval = hid_mousepoll_interval; |
845 | 834 | ||
835 | ret = -ENOMEM; | ||
846 | if (usb_endpoint_dir_in(endpoint)) { | 836 | if (usb_endpoint_dir_in(endpoint)) { |
847 | if (usbhid->urbin) | 837 | if (usbhid->urbin) |
848 | continue; | 838 | continue; |
@@ -868,6 +858,7 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf) | |||
868 | 858 | ||
869 | if (!usbhid->urbin) { | 859 | if (!usbhid->urbin) { |
870 | err_hid("couldn't find an input interrupt endpoint"); | 860 | err_hid("couldn't find an input interrupt endpoint"); |
861 | ret = -ENODEV; | ||
871 | goto fail; | 862 | goto fail; |
872 | } | 863 | } |
873 | 864 | ||
@@ -879,44 +870,25 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf) | |||
879 | spin_lock_init(&usbhid->outlock); | 870 | spin_lock_init(&usbhid->outlock); |
880 | spin_lock_init(&usbhid->ctrllock); | 871 | spin_lock_init(&usbhid->ctrllock); |
881 | 872 | ||
882 | hid->version = le16_to_cpu(hdesc->bcdHID); | ||
883 | hid->country = hdesc->bCountryCode; | ||
884 | hid->dev = &intf->dev; | ||
885 | usbhid->intf = intf; | 873 | usbhid->intf = intf; |
886 | usbhid->ifnum = interface->desc.bInterfaceNumber; | 874 | usbhid->ifnum = interface->desc.bInterfaceNumber; |
887 | 875 | ||
888 | hid->bus = BUS_USB; | ||
889 | hid->vendor = le16_to_cpu(dev->descriptor.idVendor); | ||
890 | hid->product = le16_to_cpu(dev->descriptor.idProduct); | ||
891 | |||
892 | usb_make_path(dev, hid->phys, sizeof(hid->phys)); | ||
893 | strlcat(hid->phys, "/input", sizeof(hid->phys)); | ||
894 | len = strlen(hid->phys); | ||
895 | if (len < sizeof(hid->phys) - 1) | ||
896 | snprintf(hid->phys + len, sizeof(hid->phys) - len, | ||
897 | "%d", intf->altsetting[0].desc.bInterfaceNumber); | ||
898 | |||
899 | if (usb_string(dev, dev->descriptor.iSerialNumber, hid->uniq, 64) <= 0) | ||
900 | hid->uniq[0] = 0; | ||
901 | |||
902 | usbhid->urbctrl = usb_alloc_urb(0, GFP_KERNEL); | 876 | usbhid->urbctrl = usb_alloc_urb(0, GFP_KERNEL); |
903 | if (!usbhid->urbctrl) | 877 | if (!usbhid->urbctrl) { |
878 | ret = -ENOMEM; | ||
904 | goto fail; | 879 | goto fail; |
880 | } | ||
905 | 881 | ||
906 | usb_fill_control_urb(usbhid->urbctrl, dev, 0, (void *) usbhid->cr, | 882 | usb_fill_control_urb(usbhid->urbctrl, dev, 0, (void *) usbhid->cr, |
907 | usbhid->ctrlbuf, 1, hid_ctrl, hid); | 883 | usbhid->ctrlbuf, 1, hid_ctrl, hid); |
908 | usbhid->urbctrl->setup_dma = usbhid->cr_dma; | 884 | usbhid->urbctrl->setup_dma = usbhid->cr_dma; |
909 | usbhid->urbctrl->transfer_dma = usbhid->ctrlbuf_dma; | 885 | usbhid->urbctrl->transfer_dma = usbhid->ctrlbuf_dma; |
910 | usbhid->urbctrl->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP); | 886 | usbhid->urbctrl->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP); |
911 | hid->hidinput_input_event = usb_hidinput_input_event; | 887 | |
912 | hid->hid_open = usbhid_open; | 888 | usbhid_init_reports(hid); |
913 | hid->hid_close = usbhid_close; | 889 | hid_dump_device(hid); |
914 | #ifdef CONFIG_USB_HIDDEV | 890 | |
915 | hid->hiddev_hid_event = hiddev_hid_event; | 891 | return 0; |
916 | hid->hiddev_report_event = hiddev_report_event; | ||
917 | #endif | ||
918 | hid->hid_output_raw_report = usbhid_output_raw_report; | ||
919 | return hid; | ||
920 | 892 | ||
921 | fail: | 893 | fail: |
922 | usb_free_urb(usbhid->urbin); | 894 | usb_free_urb(usbhid->urbin); |
@@ -924,24 +896,18 @@ fail: | |||
924 | usb_free_urb(usbhid->urbctrl); | 896 | usb_free_urb(usbhid->urbctrl); |
925 | hid_free_buffers(dev, hid); | 897 | hid_free_buffers(dev, hid); |
926 | kfree(usbhid); | 898 | kfree(usbhid); |
927 | fail_no_usbhid: | 899 | err: |
928 | hid_free_device(hid); | 900 | return ret; |
929 | |||
930 | return NULL; | ||
931 | } | 901 | } |
932 | 902 | ||
933 | static void hid_disconnect(struct usb_interface *intf) | 903 | static void usbhid_stop(struct hid_device *hid) |
934 | { | 904 | { |
935 | struct hid_device *hid = usb_get_intfdata (intf); | 905 | struct usbhid_device *usbhid = hid->driver_data; |
936 | struct usbhid_device *usbhid; | ||
937 | 906 | ||
938 | if (!hid) | 907 | if (WARN_ON(!usbhid)) |
939 | return; | 908 | return; |
940 | 909 | ||
941 | usbhid = hid->driver_data; | ||
942 | |||
943 | spin_lock_irq(&usbhid->inlock); /* Sync with error handler */ | 910 | spin_lock_irq(&usbhid->inlock); /* Sync with error handler */ |
944 | usb_set_intfdata(intf, NULL); | ||
945 | set_bit(HID_DISCONNECTED, &usbhid->iofl); | 911 | set_bit(HID_DISCONNECTED, &usbhid->iofl); |
946 | spin_unlock_irq(&usbhid->inlock); | 912 | spin_unlock_irq(&usbhid->inlock); |
947 | usb_kill_urb(usbhid->urbin); | 913 | usb_kill_urb(usbhid->urbin); |
@@ -958,86 +924,100 @@ static void hid_disconnect(struct usb_interface *intf) | |||
958 | if (hid->claimed & HID_CLAIMED_HIDRAW) | 924 | if (hid->claimed & HID_CLAIMED_HIDRAW) |
959 | hidraw_disconnect(hid); | 925 | hidraw_disconnect(hid); |
960 | 926 | ||
927 | hid->claimed = 0; | ||
928 | |||
961 | usb_free_urb(usbhid->urbin); | 929 | usb_free_urb(usbhid->urbin); |
962 | usb_free_urb(usbhid->urbctrl); | 930 | usb_free_urb(usbhid->urbctrl); |
963 | usb_free_urb(usbhid->urbout); | 931 | usb_free_urb(usbhid->urbout); |
964 | 932 | ||
965 | hid_free_buffers(hid_to_usb_dev(hid), hid); | 933 | hid_free_buffers(hid_to_usb_dev(hid), hid); |
966 | kfree(usbhid); | 934 | kfree(usbhid); |
967 | hid_free_device(hid); | 935 | hid->driver_data = NULL; |
968 | } | 936 | } |
969 | 937 | ||
938 | static struct hid_ll_driver usb_hid_driver = { | ||
939 | .parse = usbhid_parse, | ||
940 | .start = usbhid_start, | ||
941 | .stop = usbhid_stop, | ||
942 | .open = usbhid_open, | ||
943 | .close = usbhid_close, | ||
944 | .hidinput_input_event = usb_hidinput_input_event, | ||
945 | }; | ||
946 | |||
970 | static int hid_probe(struct usb_interface *intf, const struct usb_device_id *id) | 947 | static int hid_probe(struct usb_interface *intf, const struct usb_device_id *id) |
971 | { | 948 | { |
949 | struct usb_device *dev = interface_to_usbdev(intf); | ||
972 | struct hid_device *hid; | 950 | struct hid_device *hid; |
973 | char path[64]; | 951 | size_t len; |
974 | int i; | 952 | int ret; |
975 | char *c; | ||
976 | 953 | ||
977 | dbg_hid("HID probe called for ifnum %d\n", | 954 | dbg_hid("HID probe called for ifnum %d\n", |
978 | intf->altsetting->desc.bInterfaceNumber); | 955 | intf->altsetting->desc.bInterfaceNumber); |
979 | 956 | ||
980 | if (!(hid = usb_hid_configure(intf))) | 957 | hid = hid_allocate_device(); |
981 | return -ENODEV; | 958 | if (IS_ERR(hid)) |
982 | 959 | return PTR_ERR(hid); | |
983 | usbhid_init_reports(hid); | ||
984 | hid_dump_device(hid); | ||
985 | if (hid->quirks & HID_QUIRK_RESET_LEDS) | ||
986 | usbhid_set_leds(hid); | ||
987 | |||
988 | if (!hidinput_connect(hid)) | ||
989 | hid->claimed |= HID_CLAIMED_INPUT; | ||
990 | if (!hiddev_connect(hid)) | ||
991 | hid->claimed |= HID_CLAIMED_HIDDEV; | ||
992 | if (!hidraw_connect(hid)) | ||
993 | hid->claimed |= HID_CLAIMED_HIDRAW; | ||
994 | 960 | ||
995 | usb_set_intfdata(intf, hid); | 961 | usb_set_intfdata(intf, hid); |
962 | hid->ll_driver = &usb_hid_driver; | ||
963 | hid->hid_output_raw_report = usbhid_output_raw_report; | ||
964 | hid->ff_init = hid_pidff_init; | ||
965 | #ifdef CONFIG_USB_HIDDEV | ||
966 | hid->hiddev_connect = hiddev_connect; | ||
967 | hid->hiddev_hid_event = hiddev_hid_event; | ||
968 | hid->hiddev_report_event = hiddev_report_event; | ||
969 | #endif | ||
970 | hid->dev.parent = &intf->dev; | ||
971 | hid->bus = BUS_USB; | ||
972 | hid->vendor = le16_to_cpu(dev->descriptor.idVendor); | ||
973 | hid->product = le16_to_cpu(dev->descriptor.idProduct); | ||
974 | hid->name[0] = 0; | ||
996 | 975 | ||
997 | if (!hid->claimed) { | 976 | if (dev->manufacturer) |
998 | printk ("HID device claimed by neither input, hiddev nor hidraw\n"); | 977 | strlcpy(hid->name, dev->manufacturer, sizeof(hid->name)); |
999 | hid_disconnect(intf); | 978 | |
1000 | return -ENODEV; | 979 | if (dev->product) { |
980 | if (dev->manufacturer) | ||
981 | strlcat(hid->name, " ", sizeof(hid->name)); | ||
982 | strlcat(hid->name, dev->product, sizeof(hid->name)); | ||
1001 | } | 983 | } |
1002 | 984 | ||
1003 | if ((hid->claimed & HID_CLAIMED_INPUT)) | 985 | if (!strlen(hid->name)) |
1004 | hid_ff_init(hid); | 986 | snprintf(hid->name, sizeof(hid->name), "HID %04x:%04x", |
987 | le16_to_cpu(dev->descriptor.idVendor), | ||
988 | le16_to_cpu(dev->descriptor.idProduct)); | ||
1005 | 989 | ||
1006 | if (hid->quirks & HID_QUIRK_SONY_PS3_CONTROLLER) | 990 | usb_make_path(dev, hid->phys, sizeof(hid->phys)); |
1007 | hid_fixup_sony_ps3_controller(interface_to_usbdev(intf), | 991 | strlcat(hid->phys, "/input", sizeof(hid->phys)); |
1008 | intf->cur_altsetting->desc.bInterfaceNumber); | 992 | len = strlen(hid->phys); |
993 | if (len < sizeof(hid->phys) - 1) | ||
994 | snprintf(hid->phys + len, sizeof(hid->phys) - len, | ||
995 | "%d", intf->altsetting[0].desc.bInterfaceNumber); | ||
1009 | 996 | ||
1010 | printk(KERN_INFO); | 997 | if (usb_string(dev, dev->descriptor.iSerialNumber, hid->uniq, 64) <= 0) |
998 | hid->uniq[0] = 0; | ||
1011 | 999 | ||
1012 | if (hid->claimed & HID_CLAIMED_INPUT) | 1000 | ret = hid_add_device(hid); |
1013 | printk("input"); | 1001 | if (ret) { |
1014 | if ((hid->claimed & HID_CLAIMED_INPUT) && ((hid->claimed & HID_CLAIMED_HIDDEV) || | 1002 | if (ret != -ENODEV) |
1015 | hid->claimed & HID_CLAIMED_HIDRAW)) | 1003 | dev_err(&intf->dev, "can't add hid device: %d\n", ret); |
1016 | printk(","); | 1004 | goto err; |
1017 | if (hid->claimed & HID_CLAIMED_HIDDEV) | ||
1018 | printk("hiddev%d", hid->minor); | ||
1019 | if ((hid->claimed & HID_CLAIMED_INPUT) && (hid->claimed & HID_CLAIMED_HIDDEV) && | ||
1020 | (hid->claimed & HID_CLAIMED_HIDRAW)) | ||
1021 | printk(","); | ||
1022 | if (hid->claimed & HID_CLAIMED_HIDRAW) | ||
1023 | printk("hidraw%d", ((struct hidraw*)hid->hidraw)->minor); | ||
1024 | |||
1025 | c = "Device"; | ||
1026 | for (i = 0; i < hid->maxcollection; i++) { | ||
1027 | if (hid->collection[i].type == HID_COLLECTION_APPLICATION && | ||
1028 | (hid->collection[i].usage & HID_USAGE_PAGE) == HID_UP_GENDESK && | ||
1029 | (hid->collection[i].usage & 0xffff) < ARRAY_SIZE(hid_types)) { | ||
1030 | c = hid_types[hid->collection[i].usage & 0xffff]; | ||
1031 | break; | ||
1032 | } | ||
1033 | } | 1005 | } |
1034 | 1006 | ||
1035 | usb_make_path(interface_to_usbdev(intf), path, 63); | 1007 | return 0; |
1008 | err: | ||
1009 | hid_destroy_device(hid); | ||
1010 | return ret; | ||
1011 | } | ||
1036 | 1012 | ||
1037 | printk(": USB HID v%x.%02x %s [%s] on %s\n", | 1013 | static void hid_disconnect(struct usb_interface *intf) |
1038 | hid->version >> 8, hid->version & 0xff, c, hid->name, path); | 1014 | { |
1015 | struct hid_device *hid = usb_get_intfdata(intf); | ||
1039 | 1016 | ||
1040 | return 0; | 1017 | if (WARN_ON(!hid)) |
1018 | return; | ||
1019 | |||
1020 | hid_destroy_device(hid); | ||
1041 | } | 1021 | } |
1042 | 1022 | ||
1043 | static int hid_suspend(struct usb_interface *intf, pm_message_t message) | 1023 | static int hid_suspend(struct usb_interface *intf, pm_message_t message) |
@@ -1107,9 +1087,22 @@ static struct usb_driver hid_driver = { | |||
1107 | .supports_autosuspend = 1, | 1087 | .supports_autosuspend = 1, |
1108 | }; | 1088 | }; |
1109 | 1089 | ||
1090 | static const struct hid_device_id hid_usb_table[] = { | ||
1091 | { HID_USB_DEVICE(HID_ANY_ID, HID_ANY_ID) }, | ||
1092 | { } | ||
1093 | }; | ||
1094 | |||
1095 | static struct hid_driver hid_usb_driver = { | ||
1096 | .name = "generic-usb", | ||
1097 | .id_table = hid_usb_table, | ||
1098 | }; | ||
1099 | |||
1110 | static int __init hid_init(void) | 1100 | static int __init hid_init(void) |
1111 | { | 1101 | { |
1112 | int retval; | 1102 | int retval; |
1103 | retval = hid_register_driver(&hid_usb_driver); | ||
1104 | if (retval) | ||
1105 | goto hid_register_fail; | ||
1113 | retval = usbhid_quirks_init(quirks_param); | 1106 | retval = usbhid_quirks_init(quirks_param); |
1114 | if (retval) | 1107 | if (retval) |
1115 | goto usbhid_quirks_init_fail; | 1108 | goto usbhid_quirks_init_fail; |
@@ -1119,7 +1112,8 @@ static int __init hid_init(void) | |||
1119 | retval = usb_register(&hid_driver); | 1112 | retval = usb_register(&hid_driver); |
1120 | if (retval) | 1113 | if (retval) |
1121 | goto usb_register_fail; | 1114 | goto usb_register_fail; |
1122 | info(DRIVER_VERSION ":" DRIVER_DESC); | 1115 | printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" |
1116 | DRIVER_DESC "\n"); | ||
1123 | 1117 | ||
1124 | return 0; | 1118 | return 0; |
1125 | usb_register_fail: | 1119 | usb_register_fail: |
@@ -1127,6 +1121,8 @@ usb_register_fail: | |||
1127 | hiddev_init_fail: | 1121 | hiddev_init_fail: |
1128 | usbhid_quirks_exit(); | 1122 | usbhid_quirks_exit(); |
1129 | usbhid_quirks_init_fail: | 1123 | usbhid_quirks_init_fail: |
1124 | hid_unregister_driver(&hid_usb_driver); | ||
1125 | hid_register_fail: | ||
1130 | return retval; | 1126 | return retval; |
1131 | } | 1127 | } |
1132 | 1128 | ||
@@ -1135,6 +1131,7 @@ static void __exit hid_exit(void) | |||
1135 | usb_deregister(&hid_driver); | 1131 | usb_deregister(&hid_driver); |
1136 | hiddev_exit(); | 1132 | hiddev_exit(); |
1137 | usbhid_quirks_exit(); | 1133 | usbhid_quirks_exit(); |
1134 | hid_unregister_driver(&hid_usb_driver); | ||
1138 | } | 1135 | } |
1139 | 1136 | ||
1140 | module_init(hid_init); | 1137 | module_init(hid_init); |
diff --git a/drivers/hid/usbhid/hid-ff.c b/drivers/hid/usbhid/hid-ff.c deleted file mode 100644 index 1d0dac52f166..000000000000 --- a/drivers/hid/usbhid/hid-ff.c +++ /dev/null | |||
@@ -1,95 +0,0 @@ | |||
1 | /* | ||
2 | * Force feedback support for hid devices. | ||
3 | * Not all hid devices use the same protocol. For example, some use PID, | ||
4 | * other use their own proprietary procotol. | ||
5 | * | ||
6 | * Copyright (c) 2002-2004 Johann Deneux | ||
7 | */ | ||
8 | |||
9 | /* | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License as published by | ||
12 | * the Free Software Foundation; either version 2 of the License, or | ||
13 | * (at your option) any later version. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program; if not, write to the Free Software | ||
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
23 | * | ||
24 | * Should you need to contact me, the author, you can do so by | ||
25 | * e-mail - mail your message to <johann.deneux@it.uu.se> | ||
26 | */ | ||
27 | |||
28 | #include <linux/input.h> | ||
29 | |||
30 | #undef DEBUG | ||
31 | #include <linux/usb.h> | ||
32 | |||
33 | #include <linux/hid.h> | ||
34 | #include "usbhid.h" | ||
35 | |||
36 | /* | ||
37 | * This table contains pointers to initializers. To add support for new | ||
38 | * devices, you need to add the USB vendor and product ids here. | ||
39 | */ | ||
40 | struct hid_ff_initializer { | ||
41 | u16 idVendor; | ||
42 | u16 idProduct; | ||
43 | int (*init)(struct hid_device*); | ||
44 | }; | ||
45 | |||
46 | /* | ||
47 | * We try pidff when no other driver is found because PID is the | ||
48 | * standards compliant way of implementing force feedback in HID. | ||
49 | * pidff_init() will quickly abort if the device doesn't appear to | ||
50 | * be a PID device | ||
51 | */ | ||
52 | static struct hid_ff_initializer inits[] = { | ||
53 | #ifdef CONFIG_LOGITECH_FF | ||
54 | { 0x46d, 0xc211, hid_lgff_init }, /* Logitech Cordless rumble pad */ | ||
55 | { 0x46d, 0xc219, hid_lgff_init }, /* Logitech Cordless rumble pad 2 */ | ||
56 | { 0x46d, 0xc283, hid_lgff_init }, /* Logitech Wingman Force 3d */ | ||
57 | { 0x46d, 0xc286, hid_lgff_init }, /* Logitech Force 3D Pro Joystick */ | ||
58 | { 0x46d, 0xc294, hid_lgff_init }, /* Logitech Formula Force EX */ | ||
59 | { 0x46d, 0xc295, hid_lgff_init }, /* Logitech MOMO force wheel */ | ||
60 | { 0x46d, 0xca03, hid_lgff_init }, /* Logitech MOMO force wheel */ | ||
61 | #endif | ||
62 | #ifdef CONFIG_LOGIRUMBLEPAD2_FF | ||
63 | { 0x46d, 0xc218, hid_lg2ff_init }, /* Logitech Rumblepad 2 */ | ||
64 | #endif | ||
65 | #ifdef CONFIG_PANTHERLORD_FF | ||
66 | { 0x810, 0x0001, hid_plff_init }, /* "Twin USB Joystick" */ | ||
67 | { 0xe8f, 0x0003, hid_plff_init }, /* "GreenAsia Inc. USB Joystick " */ | ||
68 | #endif | ||
69 | #ifdef CONFIG_THRUSTMASTER_FF | ||
70 | { 0x44f, 0xb300, hid_tmff_init }, | ||
71 | { 0x44f, 0xb304, hid_tmff_init }, | ||
72 | { 0x44f, 0xb651, hid_tmff_init }, /* FGT Rumble Force Wheel */ | ||
73 | { 0x44f, 0xb654, hid_tmff_init }, /* FGT Force Feedback Wheel */ | ||
74 | #endif | ||
75 | #ifdef CONFIG_ZEROPLUS_FF | ||
76 | { 0xc12, 0x0005, hid_zpff_init }, | ||
77 | { 0xc12, 0x0030, hid_zpff_init }, | ||
78 | #endif | ||
79 | { 0, 0, hid_pidff_init} /* Matches anything */ | ||
80 | }; | ||
81 | |||
82 | int hid_ff_init(struct hid_device* hid) | ||
83 | { | ||
84 | struct hid_ff_initializer *init; | ||
85 | int vendor = le16_to_cpu(hid_to_usb_dev(hid)->descriptor.idVendor); | ||
86 | int product = le16_to_cpu(hid_to_usb_dev(hid)->descriptor.idProduct); | ||
87 | |||
88 | for (init = inits; init->idVendor; init++) | ||
89 | if (init->idVendor == vendor && init->idProduct == product) | ||
90 | break; | ||
91 | |||
92 | return init->init(hid); | ||
93 | } | ||
94 | EXPORT_SYMBOL_GPL(hid_ff_init); | ||
95 | |||
diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 011326178c06..484e3eec2f88 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c | |||
@@ -397,7 +397,6 @@ static void pidff_set_condition_report(struct pidff_device *pidff, | |||
397 | effect->u.condition[i].left_saturation); | 397 | effect->u.condition[i].left_saturation); |
398 | pidff_set(&pidff->set_condition[PID_DEAD_BAND], | 398 | pidff_set(&pidff->set_condition[PID_DEAD_BAND], |
399 | effect->u.condition[i].deadband); | 399 | effect->u.condition[i].deadband); |
400 | usbhid_wait_io(pidff->hid); | ||
401 | usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_CONDITION], | 400 | usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_CONDITION], |
402 | USB_DIR_OUT); | 401 | USB_DIR_OUT); |
403 | } | 402 | } |
@@ -512,7 +511,6 @@ static void pidff_playback_pid(struct pidff_device *pidff, int pid_id, int n) | |||
512 | pidff->effect_operation[PID_LOOP_COUNT].value[0] = n; | 511 | pidff->effect_operation[PID_LOOP_COUNT].value[0] = n; |
513 | } | 512 | } |
514 | 513 | ||
515 | usbhid_wait_io(pidff->hid); | ||
516 | usbhid_submit_report(pidff->hid, pidff->reports[PID_EFFECT_OPERATION], | 514 | usbhid_submit_report(pidff->hid, pidff->reports[PID_EFFECT_OPERATION], |
517 | USB_DIR_OUT); | 515 | USB_DIR_OUT); |
518 | } | 516 | } |
@@ -548,6 +546,9 @@ static int pidff_erase_effect(struct input_dev *dev, int effect_id) | |||
548 | int pid_id = pidff->pid_id[effect_id]; | 546 | int pid_id = pidff->pid_id[effect_id]; |
549 | 547 | ||
550 | debug("starting to erase %d/%d", effect_id, pidff->pid_id[effect_id]); | 548 | debug("starting to erase %d/%d", effect_id, pidff->pid_id[effect_id]); |
549 | /* Wait for the queue to clear. We do not want a full fifo to | ||
550 | prevent the effect removal. */ | ||
551 | usbhid_wait_io(pidff->hid); | ||
551 | pidff_playback_pid(pidff, pid_id, 0); | 552 | pidff_playback_pid(pidff, pid_id, 0); |
552 | pidff_erase_pid(pidff, pid_id); | 553 | pidff_erase_pid(pidff, pid_id); |
553 | 554 | ||
diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c index b15f88249639..47ebe045f9b5 100644 --- a/drivers/hid/usbhid/hid-quirks.c +++ b/drivers/hid/usbhid/hid-quirks.c | |||
@@ -17,412 +17,7 @@ | |||
17 | 17 | ||
18 | #include <linux/hid.h> | 18 | #include <linux/hid.h> |
19 | 19 | ||
20 | #define USB_VENDOR_ID_A4TECH 0x09da | 20 | #include "../hid-ids.h" |
21 | #define USB_DEVICE_ID_A4TECH_WCP32PU 0x0006 | ||
22 | #define USB_DEVICE_ID_A4TECH_X5_005D 0x000a | ||
23 | |||
24 | #define USB_VENDOR_ID_AASHIMA 0x06d6 | ||
25 | #define USB_DEVICE_ID_AASHIMA_GAMEPAD 0x0025 | ||
26 | #define USB_DEVICE_ID_AASHIMA_PREDATOR 0x0026 | ||
27 | |||
28 | #define USB_VENDOR_ID_ACECAD 0x0460 | ||
29 | #define USB_DEVICE_ID_ACECAD_FLAIR 0x0004 | ||
30 | #define USB_DEVICE_ID_ACECAD_302 0x0008 | ||
31 | |||
32 | #define USB_VENDOR_ID_ADS_TECH 0x06e1 | ||
33 | #define USB_DEVICE_ID_ADS_TECH_RADIO_SI470X 0xa155 | ||
34 | |||
35 | #define USB_VENDOR_ID_AFATECH 0x15a4 | ||
36 | #define USB_DEVICE_ID_AFATECH_AF9016 0x9016 | ||
37 | |||
38 | #define USB_VENDOR_ID_AIPTEK 0x08ca | ||
39 | #define USB_DEVICE_ID_AIPTEK_01 0x0001 | ||
40 | #define USB_DEVICE_ID_AIPTEK_10 0x0010 | ||
41 | #define USB_DEVICE_ID_AIPTEK_20 0x0020 | ||
42 | #define USB_DEVICE_ID_AIPTEK_21 0x0021 | ||
43 | #define USB_DEVICE_ID_AIPTEK_22 0x0022 | ||
44 | #define USB_DEVICE_ID_AIPTEK_23 0x0023 | ||
45 | #define USB_DEVICE_ID_AIPTEK_24 0x0024 | ||
46 | |||
47 | #define USB_VENDOR_ID_AIRCABLE 0x16CA | ||
48 | #define USB_DEVICE_ID_AIRCABLE1 0x1502 | ||
49 | |||
50 | #define USB_VENDOR_ID_ALCOR 0x058f | ||
51 | #define USB_DEVICE_ID_ALCOR_USBRS232 0x9720 | ||
52 | |||
53 | #define USB_VENDOR_ID_ALPS 0x0433 | ||
54 | #define USB_DEVICE_ID_IBM_GAMEPAD 0x1101 | ||
55 | |||
56 | #define USB_VENDOR_ID_APPLE 0x05ac | ||
57 | #define USB_DEVICE_ID_APPLE_MIGHTYMOUSE 0x0304 | ||
58 | #define USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI 0x020e | ||
59 | #define USB_DEVICE_ID_APPLE_FOUNTAIN_ISO 0x020f | ||
60 | #define USB_DEVICE_ID_APPLE_GEYSER_ANSI 0x0214 | ||
61 | #define USB_DEVICE_ID_APPLE_GEYSER_ISO 0x0215 | ||
62 | #define USB_DEVICE_ID_APPLE_GEYSER_JIS 0x0216 | ||
63 | #define USB_DEVICE_ID_APPLE_GEYSER3_ANSI 0x0217 | ||
64 | #define USB_DEVICE_ID_APPLE_GEYSER3_ISO 0x0218 | ||
65 | #define USB_DEVICE_ID_APPLE_GEYSER3_JIS 0x0219 | ||
66 | #define USB_DEVICE_ID_APPLE_GEYSER4_ANSI 0x021a | ||
67 | #define USB_DEVICE_ID_APPLE_GEYSER4_ISO 0x021b | ||
68 | #define USB_DEVICE_ID_APPLE_GEYSER4_JIS 0x021c | ||
69 | #define USB_DEVICE_ID_APPLE_ALU_ANSI 0x0220 | ||
70 | #define USB_DEVICE_ID_APPLE_ALU_ISO 0x0221 | ||
71 | #define USB_DEVICE_ID_APPLE_ALU_JIS 0x0222 | ||
72 | #define USB_DEVICE_ID_APPLE_WELLSPRING_ANSI 0x0223 | ||
73 | #define USB_DEVICE_ID_APPLE_WELLSPRING_ISO 0x0224 | ||
74 | #define USB_DEVICE_ID_APPLE_WELLSPRING_JIS 0x0225 | ||
75 | #define USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI 0x0229 | ||
76 | #define USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO 0x022a | ||
77 | #define USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS 0x022b | ||
78 | #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI 0x022c | ||
79 | #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO 0x022d | ||
80 | #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS 0x022e | ||
81 | #define USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI 0x0230 | ||
82 | #define USB_DEVICE_ID_APPLE_WELLSPRING2_ISO 0x0231 | ||
83 | #define USB_DEVICE_ID_APPLE_WELLSPRING2_JIS 0x0232 | ||
84 | #define USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY 0x030a | ||
85 | #define USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY 0x030b | ||
86 | #define USB_DEVICE_ID_APPLE_IRCONTROL4 0x8242 | ||
87 | |||
88 | #define USB_VENDOR_ID_ASUS 0x0b05 | ||
89 | #define USB_DEVICE_ID_ASUS_LCM 0x1726 | ||
90 | |||
91 | #define USB_VENDOR_ID_ATEN 0x0557 | ||
92 | #define USB_DEVICE_ID_ATEN_UC100KM 0x2004 | ||
93 | #define USB_DEVICE_ID_ATEN_CS124U 0x2202 | ||
94 | #define USB_DEVICE_ID_ATEN_2PORTKVM 0x2204 | ||
95 | #define USB_DEVICE_ID_ATEN_4PORTKVM 0x2205 | ||
96 | #define USB_DEVICE_ID_ATEN_4PORTKVMC 0x2208 | ||
97 | |||
98 | #define USB_VENDOR_ID_BELKIN 0x050d | ||
99 | #define USB_DEVICE_ID_FLIP_KVM 0x3201 | ||
100 | |||
101 | #define USB_VENDOR_ID_BERKSHIRE 0x0c98 | ||
102 | #define USB_DEVICE_ID_BERKSHIRE_PCWD 0x1140 | ||
103 | |||
104 | #define USB_VENDOR_ID_CHERRY 0x046a | ||
105 | #define USB_DEVICE_ID_CHERRY_CYMOTION 0x0023 | ||
106 | |||
107 | #define USB_VENDOR_ID_CHIC 0x05fe | ||
108 | #define USB_DEVICE_ID_CHIC_GAMEPAD 0x0014 | ||
109 | |||
110 | #define USB_VENDOR_ID_CIDC 0x1677 | ||
111 | |||
112 | #define USB_VENDOR_ID_CMEDIA 0x0d8c | ||
113 | #define USB_DEVICE_ID_CM109 0x000e | ||
114 | |||
115 | #define USB_VENDOR_ID_CODEMERCS 0x07c0 | ||
116 | #define USB_DEVICE_ID_CODEMERCS_IOW_FIRST 0x1500 | ||
117 | #define USB_DEVICE_ID_CODEMERCS_IOW_LAST 0x15ff | ||
118 | |||
119 | #define USB_VENDOR_ID_CYGNAL 0x10c4 | ||
120 | #define USB_DEVICE_ID_CYGNAL_RADIO_SI470X 0x818a | ||
121 | |||
122 | #define USB_VENDOR_ID_CYPRESS 0x04b4 | ||
123 | #define USB_DEVICE_ID_CYPRESS_MOUSE 0x0001 | ||
124 | #define USB_DEVICE_ID_CYPRESS_HIDCOM 0x5500 | ||
125 | #define USB_DEVICE_ID_CYPRESS_ULTRAMOUSE 0x7417 | ||
126 | #define USB_DEVICE_ID_CYPRESS_BARCODE_1 0xde61 | ||
127 | #define USB_DEVICE_ID_CYPRESS_BARCODE_2 0xde64 | ||
128 | |||
129 | #define USB_VENDOR_ID_DELL 0x413c | ||
130 | #define USB_DEVICE_ID_DELL_W7658 0x2005 | ||
131 | |||
132 | #define USB_VENDOR_ID_DELORME 0x1163 | ||
133 | #define USB_DEVICE_ID_DELORME_EARTHMATE 0x0100 | ||
134 | #define USB_DEVICE_ID_DELORME_EM_LT20 0x0200 | ||
135 | |||
136 | #define USB_VENDOR_ID_DMI 0x0c0b | ||
137 | #define USB_DEVICE_ID_DMI_ENC 0x5fab | ||
138 | |||
139 | #define USB_VENDOR_ID_ELO 0x04E7 | ||
140 | #define USB_DEVICE_ID_ELO_TS2700 0x0020 | ||
141 | |||
142 | #define USB_VENDOR_ID_ESSENTIAL_REALITY 0x0d7f | ||
143 | #define USB_DEVICE_ID_ESSENTIAL_REALITY_P5 0x0100 | ||
144 | |||
145 | #define USB_VENDOR_ID_EZKEY 0x0518 | ||
146 | #define USB_DEVICE_ID_BTC_8193 0x0002 | ||
147 | |||
148 | #define USB_VENDOR_ID_GAMERON 0x0810 | ||
149 | #define USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR 0x0001 | ||
150 | |||
151 | #define USB_VENDOR_ID_GENERAL_TOUCH 0x0dfc | ||
152 | |||
153 | #define USB_VENDOR_ID_GLAB 0x06c2 | ||
154 | #define USB_DEVICE_ID_4_PHIDGETSERVO_30 0x0038 | ||
155 | #define USB_DEVICE_ID_1_PHIDGETSERVO_30 0x0039 | ||
156 | #define USB_DEVICE_ID_0_0_4_IF_KIT 0x0040 | ||
157 | #define USB_DEVICE_ID_0_16_16_IF_KIT 0x0044 | ||
158 | #define USB_DEVICE_ID_8_8_8_IF_KIT 0x0045 | ||
159 | #define USB_DEVICE_ID_0_8_7_IF_KIT 0x0051 | ||
160 | #define USB_DEVICE_ID_0_8_8_IF_KIT 0x0053 | ||
161 | #define USB_DEVICE_ID_PHIDGET_MOTORCONTROL 0x0058 | ||
162 | |||
163 | #define USB_VENDOR_ID_GOTOP 0x08f2 | ||
164 | #define USB_DEVICE_ID_SUPER_Q2 0x007f | ||
165 | #define USB_DEVICE_ID_GOGOPEN 0x00ce | ||
166 | #define USB_DEVICE_ID_PENPOWER 0x00f4 | ||
167 | |||
168 | #define USB_VENDOR_ID_GRETAGMACBETH 0x0971 | ||
169 | #define USB_DEVICE_ID_GRETAGMACBETH_HUEY 0x2005 | ||
170 | |||
171 | #define USB_VENDOR_ID_GRIFFIN 0x077d | ||
172 | #define USB_DEVICE_ID_POWERMATE 0x0410 | ||
173 | #define USB_DEVICE_ID_SOUNDKNOB 0x04AA | ||
174 | |||
175 | #define USB_VENDOR_ID_GTCO 0x078c | ||
176 | #define USB_DEVICE_ID_GTCO_90 0x0090 | ||
177 | #define USB_DEVICE_ID_GTCO_100 0x0100 | ||
178 | #define USB_DEVICE_ID_GTCO_101 0x0101 | ||
179 | #define USB_DEVICE_ID_GTCO_103 0x0103 | ||
180 | #define USB_DEVICE_ID_GTCO_104 0x0104 | ||
181 | #define USB_DEVICE_ID_GTCO_105 0x0105 | ||
182 | #define USB_DEVICE_ID_GTCO_106 0x0106 | ||
183 | #define USB_DEVICE_ID_GTCO_107 0x0107 | ||
184 | #define USB_DEVICE_ID_GTCO_108 0x0108 | ||
185 | #define USB_DEVICE_ID_GTCO_200 0x0200 | ||
186 | #define USB_DEVICE_ID_GTCO_201 0x0201 | ||
187 | #define USB_DEVICE_ID_GTCO_202 0x0202 | ||
188 | #define USB_DEVICE_ID_GTCO_203 0x0203 | ||
189 | #define USB_DEVICE_ID_GTCO_204 0x0204 | ||
190 | #define USB_DEVICE_ID_GTCO_205 0x0205 | ||
191 | #define USB_DEVICE_ID_GTCO_206 0x0206 | ||
192 | #define USB_DEVICE_ID_GTCO_207 0x0207 | ||
193 | #define USB_DEVICE_ID_GTCO_300 0x0300 | ||
194 | #define USB_DEVICE_ID_GTCO_301 0x0301 | ||
195 | #define USB_DEVICE_ID_GTCO_302 0x0302 | ||
196 | #define USB_DEVICE_ID_GTCO_303 0x0303 | ||
197 | #define USB_DEVICE_ID_GTCO_304 0x0304 | ||
198 | #define USB_DEVICE_ID_GTCO_305 0x0305 | ||
199 | #define USB_DEVICE_ID_GTCO_306 0x0306 | ||
200 | #define USB_DEVICE_ID_GTCO_307 0x0307 | ||
201 | #define USB_DEVICE_ID_GTCO_308 0x0308 | ||
202 | #define USB_DEVICE_ID_GTCO_309 0x0309 | ||
203 | #define USB_DEVICE_ID_GTCO_400 0x0400 | ||
204 | #define USB_DEVICE_ID_GTCO_401 0x0401 | ||
205 | #define USB_DEVICE_ID_GTCO_402 0x0402 | ||
206 | #define USB_DEVICE_ID_GTCO_403 0x0403 | ||
207 | #define USB_DEVICE_ID_GTCO_404 0x0404 | ||
208 | #define USB_DEVICE_ID_GTCO_405 0x0405 | ||
209 | #define USB_DEVICE_ID_GTCO_500 0x0500 | ||
210 | #define USB_DEVICE_ID_GTCO_501 0x0501 | ||
211 | #define USB_DEVICE_ID_GTCO_502 0x0502 | ||
212 | #define USB_DEVICE_ID_GTCO_503 0x0503 | ||
213 | #define USB_DEVICE_ID_GTCO_504 0x0504 | ||
214 | #define USB_DEVICE_ID_GTCO_1000 0x1000 | ||
215 | #define USB_DEVICE_ID_GTCO_1001 0x1001 | ||
216 | #define USB_DEVICE_ID_GTCO_1002 0x1002 | ||
217 | #define USB_DEVICE_ID_GTCO_1003 0x1003 | ||
218 | #define USB_DEVICE_ID_GTCO_1004 0x1004 | ||
219 | #define USB_DEVICE_ID_GTCO_1005 0x1005 | ||
220 | #define USB_DEVICE_ID_GTCO_1006 0x1006 | ||
221 | #define USB_DEVICE_ID_GTCO_1007 0x1007 | ||
222 | #define USB_VENDOR_ID_HAPP 0x078b | ||
223 | #define USB_DEVICE_ID_UGCI_DRIVING 0x0010 | ||
224 | #define USB_DEVICE_ID_UGCI_FLYING 0x0020 | ||
225 | #define USB_DEVICE_ID_UGCI_FIGHTING 0x0030 | ||
226 | |||
227 | #define USB_VENDOR_ID_IMATION 0x0718 | ||
228 | #define USB_DEVICE_ID_DISC_STAKKA 0xd000 | ||
229 | |||
230 | #define USB_VENDOR_ID_KBGEAR 0x084e | ||
231 | #define USB_DEVICE_ID_KBGEAR_JAMSTUDIO 0x1001 | ||
232 | |||
233 | #define USB_VENDOR_ID_LD 0x0f11 | ||
234 | #define USB_DEVICE_ID_LD_CASSY 0x1000 | ||
235 | #define USB_DEVICE_ID_LD_POCKETCASSY 0x1010 | ||
236 | #define USB_DEVICE_ID_LD_MOBILECASSY 0x1020 | ||
237 | #define USB_DEVICE_ID_LD_JWM 0x1080 | ||
238 | #define USB_DEVICE_ID_LD_DMMP 0x1081 | ||
239 | #define USB_DEVICE_ID_LD_UMIP 0x1090 | ||
240 | #define USB_DEVICE_ID_LD_XRAY1 0x1100 | ||
241 | #define USB_DEVICE_ID_LD_XRAY2 0x1101 | ||
242 | #define USB_DEVICE_ID_LD_VIDEOCOM 0x1200 | ||
243 | #define USB_DEVICE_ID_LD_COM3LAB 0x2000 | ||
244 | #define USB_DEVICE_ID_LD_TELEPORT 0x2010 | ||
245 | #define USB_DEVICE_ID_LD_NETWORKANALYSER 0x2020 | ||
246 | #define USB_DEVICE_ID_LD_POWERCONTROL 0x2030 | ||
247 | #define USB_DEVICE_ID_LD_MACHINETEST 0x2040 | ||
248 | |||
249 | #define USB_VENDOR_ID_LOGITECH 0x046d | ||
250 | #define USB_DEVICE_ID_LOGITECH_LX3 0xc044 | ||
251 | #define USB_DEVICE_ID_LOGITECH_V150 0xc047 | ||
252 | #define USB_DEVICE_ID_LOGITECH_RECEIVER 0xc101 | ||
253 | #define USB_DEVICE_ID_LOGITECH_HARMONY 0xc110 | ||
254 | #define USB_DEVICE_ID_LOGITECH_HARMONY_2 0xc111 | ||
255 | #define USB_DEVICE_ID_LOGITECH_HARMONY_3 0xc112 | ||
256 | #define USB_DEVICE_ID_LOGITECH_HARMONY_4 0xc113 | ||
257 | #define USB_DEVICE_ID_LOGITECH_HARMONY_5 0xc114 | ||
258 | #define USB_DEVICE_ID_LOGITECH_HARMONY_6 0xc115 | ||
259 | #define USB_DEVICE_ID_LOGITECH_HARMONY_7 0xc116 | ||
260 | #define USB_DEVICE_ID_LOGITECH_HARMONY_8 0xc117 | ||
261 | #define USB_DEVICE_ID_LOGITECH_HARMONY_9 0xc118 | ||
262 | #define USB_DEVICE_ID_LOGITECH_HARMONY_10 0xc119 | ||
263 | #define USB_DEVICE_ID_LOGITECH_HARMONY_11 0xc11a | ||
264 | #define USB_DEVICE_ID_LOGITECH_HARMONY_12 0xc11b | ||
265 | #define USB_DEVICE_ID_LOGITECH_HARMONY_13 0xc11c | ||
266 | #define USB_DEVICE_ID_LOGITECH_HARMONY_14 0xc11d | ||
267 | #define USB_DEVICE_ID_LOGITECH_HARMONY_15 0xc11e | ||
268 | #define USB_DEVICE_ID_LOGITECH_HARMONY_16 0xc11f | ||
269 | #define USB_DEVICE_ID_LOGITECH_HARMONY_17 0xc120 | ||
270 | #define USB_DEVICE_ID_LOGITECH_HARMONY_18 0xc121 | ||
271 | #define USB_DEVICE_ID_LOGITECH_HARMONY_19 0xc122 | ||
272 | #define USB_DEVICE_ID_LOGITECH_HARMONY_20 0xc123 | ||
273 | #define USB_DEVICE_ID_LOGITECH_HARMONY_21 0xc124 | ||
274 | #define USB_DEVICE_ID_LOGITECH_HARMONY_22 0xc125 | ||
275 | #define USB_DEVICE_ID_LOGITECH_HARMONY_23 0xc126 | ||
276 | #define USB_DEVICE_ID_LOGITECH_HARMONY_24 0xc127 | ||
277 | #define USB_DEVICE_ID_LOGITECH_HARMONY_25 0xc128 | ||
278 | #define USB_DEVICE_ID_LOGITECH_HARMONY_26 0xc129 | ||
279 | #define USB_DEVICE_ID_LOGITECH_HARMONY_27 0xc12a | ||
280 | #define USB_DEVICE_ID_LOGITECH_HARMONY_28 0xc12b | ||
281 | #define USB_DEVICE_ID_LOGITECH_HARMONY_29 0xc12c | ||
282 | #define USB_DEVICE_ID_LOGITECH_HARMONY_30 0xc12d | ||
283 | #define USB_DEVICE_ID_LOGITECH_HARMONY_31 0xc12e | ||
284 | #define USB_DEVICE_ID_LOGITECH_HARMONY_32 0xc12f | ||
285 | #define USB_DEVICE_ID_LOGITECH_HARMONY_33 0xc130 | ||
286 | #define USB_DEVICE_ID_LOGITECH_HARMONY_34 0xc131 | ||
287 | #define USB_DEVICE_ID_LOGITECH_HARMONY_35 0xc132 | ||
288 | #define USB_DEVICE_ID_LOGITECH_HARMONY_36 0xc133 | ||
289 | #define USB_DEVICE_ID_LOGITECH_HARMONY_37 0xc134 | ||
290 | #define USB_DEVICE_ID_LOGITECH_HARMONY_38 0xc135 | ||
291 | #define USB_DEVICE_ID_LOGITECH_HARMONY_39 0xc136 | ||
292 | #define USB_DEVICE_ID_LOGITECH_HARMONY_40 0xc137 | ||
293 | #define USB_DEVICE_ID_LOGITECH_HARMONY_41 0xc138 | ||
294 | #define USB_DEVICE_ID_LOGITECH_HARMONY_42 0xc139 | ||
295 | #define USB_DEVICE_ID_LOGITECH_HARMONY_43 0xc13a | ||
296 | #define USB_DEVICE_ID_LOGITECH_HARMONY_44 0xc13b | ||
297 | #define USB_DEVICE_ID_LOGITECH_HARMONY_45 0xc13c | ||
298 | #define USB_DEVICE_ID_LOGITECH_HARMONY_46 0xc13d | ||
299 | #define USB_DEVICE_ID_LOGITECH_HARMONY_47 0xc13e | ||
300 | #define USB_DEVICE_ID_LOGITECH_HARMONY_48 0xc13f | ||
301 | #define USB_DEVICE_ID_LOGITECH_HARMONY_49 0xc140 | ||
302 | #define USB_DEVICE_ID_LOGITECH_HARMONY_50 0xc141 | ||
303 | #define USB_DEVICE_ID_LOGITECH_HARMONY_51 0xc142 | ||
304 | #define USB_DEVICE_ID_LOGITECH_HARMONY_52 0xc143 | ||
305 | #define USB_DEVICE_ID_LOGITECH_HARMONY_53 0xc144 | ||
306 | #define USB_DEVICE_ID_LOGITECH_HARMONY_54 0xc145 | ||
307 | #define USB_DEVICE_ID_LOGITECH_HARMONY_55 0xc146 | ||
308 | #define USB_DEVICE_ID_LOGITECH_HARMONY_56 0xc147 | ||
309 | #define USB_DEVICE_ID_LOGITECH_HARMONY_57 0xc148 | ||
310 | #define USB_DEVICE_ID_LOGITECH_HARMONY_58 0xc149 | ||
311 | #define USB_DEVICE_ID_LOGITECH_HARMONY_59 0xc14a | ||
312 | #define USB_DEVICE_ID_LOGITECH_HARMONY_60 0xc14b | ||
313 | #define USB_DEVICE_ID_LOGITECH_HARMONY_61 0xc14c | ||
314 | #define USB_DEVICE_ID_LOGITECH_HARMONY_62 0xc14d | ||
315 | #define USB_DEVICE_ID_LOGITECH_HARMONY_63 0xc14e | ||
316 | #define USB_DEVICE_ID_LOGITECH_HARMONY_64 0xc14f | ||
317 | #define USB_DEVICE_ID_LOGITECH_EXTREME_3D 0xc215 | ||
318 | #define USB_DEVICE_ID_LOGITECH_WHEEL 0xc294 | ||
319 | #define USB_DEVICE_ID_LOGITECH_ELITE_KBD 0xc30a | ||
320 | #define USB_DEVICE_ID_LOGITECH_KBD 0xc311 | ||
321 | #define USB_DEVICE_ID_S510_RECEIVER 0xc50c | ||
322 | #define USB_DEVICE_ID_S510_RECEIVER_2 0xc517 | ||
323 | #define USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500 0xc512 | ||
324 | #define USB_DEVICE_ID_MX3000_RECEIVER 0xc513 | ||
325 | #define USB_DEVICE_ID_DINOVO_DESKTOP 0xc704 | ||
326 | #define USB_DEVICE_ID_DINOVO_EDGE 0xc714 | ||
327 | #define USB_DEVICE_ID_DINOVO_MINI 0xc71f | ||
328 | |||
329 | #define USB_VENDOR_ID_MCC 0x09db | ||
330 | #define USB_DEVICE_ID_MCC_PMD1024LS 0x0076 | ||
331 | #define USB_DEVICE_ID_MCC_PMD1208LS 0x007a | ||
332 | |||
333 | #define USB_VENDOR_ID_MGE 0x0463 | ||
334 | #define USB_DEVICE_ID_MGE_UPS 0xffff | ||
335 | #define USB_DEVICE_ID_MGE_UPS1 0x0001 | ||
336 | |||
337 | #define USB_VENDOR_ID_MICROCHIP 0x04d8 | ||
338 | #define USB_DEVICE_ID_PICKIT1 0x0032 | ||
339 | #define USB_DEVICE_ID_PICKIT2 0x0033 | ||
340 | |||
341 | #define USB_VENDOR_ID_MICROSOFT 0x045e | ||
342 | #define USB_DEVICE_ID_SIDEWINDER_GV 0x003b | ||
343 | #define USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0 0x009d | ||
344 | #define USB_DEVICE_ID_DESKTOP_RECV_1028 0x00f9 | ||
345 | #define USB_DEVICE_ID_MS_NE4K 0x00db | ||
346 | #define USB_DEVICE_ID_MS_LK6K 0x00f9 | ||
347 | |||
348 | #define USB_VENDOR_ID_MONTEREY 0x0566 | ||
349 | #define USB_DEVICE_ID_GENIUS_KB29E 0x3004 | ||
350 | |||
351 | #define USB_VENDOR_ID_NCR 0x0404 | ||
352 | #define USB_DEVICE_ID_NCR_FIRST 0x0300 | ||
353 | #define USB_DEVICE_ID_NCR_LAST 0x03ff | ||
354 | |||
355 | #define USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR 0x0400 | ||
356 | #define USB_DEVICE_ID_N_S_HARMONY 0xc359 | ||
357 | |||
358 | #define USB_VENDOR_ID_NATSU 0x08b7 | ||
359 | #define USB_DEVICE_ID_NATSU_GAMEPAD 0x0001 | ||
360 | |||
361 | #define USB_VENDOR_ID_NEC 0x073e | ||
362 | #define USB_DEVICE_ID_NEC_USB_GAME_PAD 0x0301 | ||
363 | |||
364 | #define USB_VENDOR_ID_ONTRAK 0x0a07 | ||
365 | #define USB_DEVICE_ID_ONTRAK_ADU100 0x0064 | ||
366 | |||
367 | #define USB_VENDOR_ID_PANJIT 0x134c | ||
368 | |||
369 | #define USB_VENDOR_ID_PANTHERLORD 0x0810 | ||
370 | #define USB_DEVICE_ID_PANTHERLORD_TWIN_USB_JOYSTICK 0x0001 | ||
371 | |||
372 | #define USB_VENDOR_ID_PETALYNX 0x18b1 | ||
373 | #define USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE 0x0037 | ||
374 | |||
375 | #define USB_VENDOR_ID_PLAYDOTCOM 0x0b43 | ||
376 | #define USB_DEVICE_ID_PLAYDOTCOM_EMS_USBII 0x0003 | ||
377 | |||
378 | #define USB_VENDOR_ID_SAITEK 0x06a3 | ||
379 | #define USB_DEVICE_ID_SAITEK_RUMBLEPAD 0xff17 | ||
380 | |||
381 | #define USB_VENDOR_ID_SAMSUNG 0x0419 | ||
382 | #define USB_DEVICE_ID_SAMSUNG_IR_REMOTE 0x0001 | ||
383 | |||
384 | #define USB_VENDOR_ID_SONY 0x054c | ||
385 | #define USB_DEVICE_ID_SONY_PS3_CONTROLLER 0x0268 | ||
386 | |||
387 | #define USB_VENDOR_ID_SOUNDGRAPH 0x15c2 | ||
388 | #define USB_DEVICE_ID_SOUNDGRAPH_IMON_LCD 0x0038 | ||
389 | |||
390 | #define USB_VENDOR_ID_SUN 0x0430 | ||
391 | #define USB_DEVICE_ID_RARITAN_KVM_DONGLE 0xcdab | ||
392 | |||
393 | #define USB_VENDOR_ID_SUNPLUS 0x04fc | ||
394 | #define USB_DEVICE_ID_SUNPLUS_WDESKTOP 0x05d8 | ||
395 | |||
396 | #define USB_VENDOR_ID_TOPMAX 0x0663 | ||
397 | #define USB_DEVICE_ID_TOPMAX_COBRAPAD 0x0103 | ||
398 | |||
399 | #define USB_VENDOR_ID_TURBOX 0x062a | ||
400 | #define USB_DEVICE_ID_TURBOX_KEYBOARD 0x0201 | ||
401 | |||
402 | #define USB_VENDOR_ID_VERNIER 0x08f7 | ||
403 | #define USB_DEVICE_ID_VERNIER_LABPRO 0x0001 | ||
404 | #define USB_DEVICE_ID_VERNIER_GOTEMP 0x0002 | ||
405 | #define USB_DEVICE_ID_VERNIER_SKIP 0x0003 | ||
406 | #define USB_DEVICE_ID_VERNIER_CYCLOPS 0x0004 | ||
407 | #define USB_DEVICE_ID_VERNIER_LCSPEC 0x0006 | ||
408 | |||
409 | #define USB_VENDOR_ID_WACOM 0x056a | ||
410 | |||
411 | #define USB_VENDOR_ID_WISEGROUP 0x0925 | ||
412 | #define USB_DEVICE_ID_1_PHIDGETSERVO_20 0x8101 | ||
413 | #define USB_DEVICE_ID_4_PHIDGETSERVO_20 0x8104 | ||
414 | #define USB_DEVICE_ID_8_8_4_IF_KIT 0x8201 | ||
415 | #define USB_DEVICE_ID_QUAD_USB_JOYPAD 0x8800 | ||
416 | #define USB_DEVICE_ID_DUAL_USB_JOYPAD 0x8866 | ||
417 | |||
418 | #define USB_VENDOR_ID_WISEGROUP_LTD 0x6677 | ||
419 | #define USB_DEVICE_ID_SMARTJOY_DUAL_PLUS 0x8802 | ||
420 | |||
421 | #define USB_VENDOR_ID_YEALINK 0x6993 | ||
422 | #define USB_DEVICE_ID_YEALINK_P1K_P4K_B2K 0xb001 | ||
423 | |||
424 | #define USB_VENDOR_ID_KYE 0x0458 | ||
425 | #define USB_DEVICE_ID_KYE_GPEN_560 0x5003 | ||
426 | 21 | ||
427 | /* | 22 | /* |
428 | * Alphabetically sorted blacklist by quirk type. | 23 | * Alphabetically sorted blacklist by quirk type. |
@@ -433,18 +28,10 @@ static const struct hid_blacklist { | |||
433 | __u16 idProduct; | 28 | __u16 idProduct; |
434 | __u32 quirks; | 29 | __u32 quirks; |
435 | } hid_blacklist[] = { | 30 | } hid_blacklist[] = { |
436 | |||
437 | { USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU, HID_QUIRK_2WHEEL_MOUSE_HACK_7 }, | ||
438 | { USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D, HID_QUIRK_2WHEEL_MOUSE_HACK_B8 }, | ||
439 | { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE, HID_QUIRK_2WHEEL_MOUSE_HACK_5 }, | ||
440 | |||
441 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER, HID_QUIRK_BAD_RELATIVE_KEYS }, | ||
442 | |||
443 | { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_GAMEPAD, HID_QUIRK_BADPAD }, | 31 | { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_GAMEPAD, HID_QUIRK_BADPAD }, |
444 | { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_PREDATOR, HID_QUIRK_BADPAD }, | 32 | { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_PREDATOR, HID_QUIRK_BADPAD }, |
445 | { USB_VENDOR_ID_ALPS, USB_DEVICE_ID_IBM_GAMEPAD, HID_QUIRK_BADPAD }, | 33 | { USB_VENDOR_ID_ALPS, USB_DEVICE_ID_IBM_GAMEPAD, HID_QUIRK_BADPAD }, |
446 | { USB_VENDOR_ID_CHIC, USB_DEVICE_ID_CHIC_GAMEPAD, HID_QUIRK_BADPAD }, | 34 | { USB_VENDOR_ID_CHIC, USB_DEVICE_ID_CHIC_GAMEPAD, HID_QUIRK_BADPAD }, |
447 | { USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR, HID_QUIRK_MULTI_INPUT }, | ||
448 | { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_DRIVING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT }, | 35 | { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_DRIVING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT }, |
449 | { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FLYING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT }, | 36 | { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FLYING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT }, |
450 | { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FIGHTING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT }, | 37 | { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FIGHTING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT }, |
@@ -453,169 +40,11 @@ static const struct hid_blacklist { | |||
453 | { USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RUMBLEPAD, HID_QUIRK_BADPAD }, | 40 | { USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RUMBLEPAD, HID_QUIRK_BADPAD }, |
454 | { USB_VENDOR_ID_TOPMAX, USB_DEVICE_ID_TOPMAX_COBRAPAD, HID_QUIRK_BADPAD }, | 41 | { USB_VENDOR_ID_TOPMAX, USB_DEVICE_ID_TOPMAX_COBRAPAD, HID_QUIRK_BADPAD }, |
455 | 42 | ||
456 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP, HID_QUIRK_DUPLICATE_USAGES }, | ||
457 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE, HID_QUIRK_DUPLICATE_USAGES }, | ||
458 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI, HID_QUIRK_DUPLICATE_USAGES }, | ||
459 | |||
460 | { USB_VENDOR_ID_AFATECH, USB_DEVICE_ID_AFATECH_AF9016, HID_QUIRK_FULLSPEED_INTERVAL }, | 43 | { USB_VENDOR_ID_AFATECH, USB_DEVICE_ID_AFATECH_AF9016, HID_QUIRK_FULLSPEED_INTERVAL }, |
461 | 44 | ||
462 | { USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM, HID_QUIRK_HIDDEV }, | ||
463 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4, HID_QUIRK_HIDDEV | HID_QUIRK_IGNORE_HIDINPUT }, | ||
464 | { USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE, HID_QUIRK_HIDDEV | HID_QUIRK_IGNORE_HIDINPUT }, | ||
465 | { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV, HID_QUIRK_HIDINPUT }, | ||
466 | |||
467 | { USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193, HID_QUIRK_HWHEEL_WHEEL_INVERT }, | ||
468 | |||
469 | { USB_VENDOR_ID_ADS_TECH, USB_DEVICE_ID_ADS_TECH_RADIO_SI470X, HID_QUIRK_IGNORE }, | ||
470 | { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01, HID_QUIRK_IGNORE }, | ||
471 | { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10, HID_QUIRK_IGNORE }, | ||
472 | { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20, HID_QUIRK_IGNORE }, | ||
473 | { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21, HID_QUIRK_IGNORE }, | ||
474 | { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22, HID_QUIRK_IGNORE }, | ||
475 | { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23, HID_QUIRK_IGNORE }, | ||
476 | { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24, HID_QUIRK_IGNORE }, | ||
477 | { USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1, HID_QUIRK_IGNORE }, | ||
478 | { USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232, HID_QUIRK_IGNORE }, | ||
479 | { USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_LCM, HID_QUIRK_IGNORE}, | ||
480 | { USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD, HID_QUIRK_IGNORE }, | ||
481 | { USB_VENDOR_ID_CIDC, 0x0103, HID_QUIRK_IGNORE }, | ||
482 | { USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X, HID_QUIRK_IGNORE }, | ||
483 | { USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109, HID_QUIRK_IGNORE }, | ||
484 | { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM, HID_QUIRK_IGNORE }, | ||
485 | { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE, HID_QUIRK_IGNORE }, | ||
486 | { USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE, HID_QUIRK_IGNORE }, | ||
487 | { USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20, HID_QUIRK_IGNORE }, | ||
488 | { USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5, HID_QUIRK_IGNORE }, | ||
489 | { USB_VENDOR_ID_GENERAL_TOUCH, 0x0001, HID_QUIRK_IGNORE }, | ||
490 | { USB_VENDOR_ID_GENERAL_TOUCH, 0x0002, HID_QUIRK_IGNORE }, | ||
491 | { USB_VENDOR_ID_GENERAL_TOUCH, 0x0003, HID_QUIRK_IGNORE }, | ||
492 | { USB_VENDOR_ID_GENERAL_TOUCH, 0x0004, HID_QUIRK_IGNORE }, | ||
493 | { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30, HID_QUIRK_IGNORE }, | ||
494 | { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30, HID_QUIRK_IGNORE }, | ||
495 | { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT, HID_QUIRK_IGNORE }, | ||
496 | { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT, HID_QUIRK_IGNORE }, | ||
497 | { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT, HID_QUIRK_IGNORE }, | ||
498 | { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT, HID_QUIRK_IGNORE }, | ||
499 | { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT, HID_QUIRK_IGNORE }, | ||
500 | { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL, HID_QUIRK_IGNORE }, | ||
501 | { USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_SUPER_Q2, HID_QUIRK_IGNORE }, | ||
502 | { USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_GOGOPEN, HID_QUIRK_IGNORE }, | ||
503 | { USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_PENPOWER, HID_QUIRK_IGNORE }, | ||
504 | { USB_VENDOR_ID_GRETAGMACBETH, USB_DEVICE_ID_GRETAGMACBETH_HUEY, HID_QUIRK_IGNORE }, | ||
505 | { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE, HID_QUIRK_IGNORE }, | ||
506 | { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB, HID_QUIRK_IGNORE }, | ||
507 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90, HID_QUIRK_IGNORE }, | ||
508 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100, HID_QUIRK_IGNORE }, | ||
509 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101, HID_QUIRK_IGNORE }, | ||
510 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103, HID_QUIRK_IGNORE }, | ||
511 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104, HID_QUIRK_IGNORE }, | ||
512 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105, HID_QUIRK_IGNORE }, | ||
513 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106, HID_QUIRK_IGNORE }, | ||
514 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107, HID_QUIRK_IGNORE }, | ||
515 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108, HID_QUIRK_IGNORE }, | ||
516 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200, HID_QUIRK_IGNORE }, | ||
517 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201, HID_QUIRK_IGNORE }, | ||
518 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202, HID_QUIRK_IGNORE }, | ||
519 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203, HID_QUIRK_IGNORE }, | ||
520 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204, HID_QUIRK_IGNORE }, | ||
521 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205, HID_QUIRK_IGNORE }, | ||
522 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206, HID_QUIRK_IGNORE }, | ||
523 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207, HID_QUIRK_IGNORE }, | ||
524 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300, HID_QUIRK_IGNORE }, | ||
525 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301, HID_QUIRK_IGNORE }, | ||
526 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302, HID_QUIRK_IGNORE }, | ||
527 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303, HID_QUIRK_IGNORE }, | ||
528 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304, HID_QUIRK_IGNORE }, | ||
529 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305, HID_QUIRK_IGNORE }, | ||
530 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306, HID_QUIRK_IGNORE }, | ||
531 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307, HID_QUIRK_IGNORE }, | ||
532 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308, HID_QUIRK_IGNORE }, | ||
533 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309, HID_QUIRK_IGNORE }, | ||
534 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400, HID_QUIRK_IGNORE }, | ||
535 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401, HID_QUIRK_IGNORE }, | ||
536 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402, HID_QUIRK_IGNORE }, | ||
537 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403, HID_QUIRK_IGNORE }, | ||
538 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404, HID_QUIRK_IGNORE }, | ||
539 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405, HID_QUIRK_IGNORE }, | ||
540 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500, HID_QUIRK_IGNORE }, | ||
541 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501, HID_QUIRK_IGNORE }, | ||
542 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502, HID_QUIRK_IGNORE }, | ||
543 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503, HID_QUIRK_IGNORE }, | ||
544 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504, HID_QUIRK_IGNORE }, | ||
545 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000, HID_QUIRK_IGNORE }, | ||
546 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001, HID_QUIRK_IGNORE }, | ||
547 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002, HID_QUIRK_IGNORE }, | ||
548 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003, HID_QUIRK_IGNORE }, | ||
549 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004, HID_QUIRK_IGNORE }, | ||
550 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005, HID_QUIRK_IGNORE }, | ||
551 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006, HID_QUIRK_IGNORE }, | ||
552 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1007, HID_QUIRK_IGNORE }, | ||
553 | { USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA, HID_QUIRK_IGNORE }, | ||
554 | { USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO, HID_QUIRK_IGNORE }, | ||
555 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY, HID_QUIRK_IGNORE }, | ||
556 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY, HID_QUIRK_IGNORE }, | ||
557 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY, HID_QUIRK_IGNORE }, | ||
558 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM, HID_QUIRK_IGNORE }, | ||
559 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP, HID_QUIRK_IGNORE }, | ||
560 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP, HID_QUIRK_IGNORE }, | ||
561 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY1, HID_QUIRK_IGNORE }, | ||
562 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2, HID_QUIRK_IGNORE }, | ||
563 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM, HID_QUIRK_IGNORE }, | ||
564 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB, HID_QUIRK_IGNORE }, | ||
565 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT, HID_QUIRK_IGNORE }, | ||
566 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER, HID_QUIRK_IGNORE }, | ||
567 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL, HID_QUIRK_IGNORE }, | ||
568 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST, HID_QUIRK_IGNORE }, | ||
569 | { USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS, HID_QUIRK_IGNORE }, | ||
570 | { USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS, HID_QUIRK_IGNORE }, | ||
571 | { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS, HID_QUIRK_IGNORE }, | ||
572 | { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1, HID_QUIRK_IGNORE }, | ||
573 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100, HID_QUIRK_IGNORE }, | ||
574 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20, HID_QUIRK_IGNORE }, | ||
575 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30, HID_QUIRK_IGNORE }, | ||
576 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100, HID_QUIRK_IGNORE }, | ||
577 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108, HID_QUIRK_IGNORE }, | ||
578 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118, HID_QUIRK_IGNORE }, | ||
579 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200, HID_QUIRK_IGNORE }, | ||
580 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300, HID_QUIRK_IGNORE }, | ||
581 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400, HID_QUIRK_IGNORE }, | ||
582 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500, HID_QUIRK_IGNORE }, | ||
583 | { USB_VENDOR_ID_PANJIT, 0x0001, HID_QUIRK_IGNORE }, | ||
584 | { USB_VENDOR_ID_PANJIT, 0x0002, HID_QUIRK_IGNORE }, | ||
585 | { USB_VENDOR_ID_PANJIT, 0x0003, HID_QUIRK_IGNORE }, | ||
586 | { USB_VENDOR_ID_PANJIT, 0x0004, HID_QUIRK_IGNORE }, | ||
587 | { USB_VENDOR_ID_SOUNDGRAPH, USB_DEVICE_ID_SOUNDGRAPH_IMON_LCD, HID_QUIRK_IGNORE }, | ||
588 | { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO, HID_QUIRK_IGNORE }, | ||
589 | { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP, HID_QUIRK_IGNORE }, | ||
590 | { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP, HID_QUIRK_IGNORE }, | ||
591 | { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS, HID_QUIRK_IGNORE }, | ||
592 | { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LCSPEC, HID_QUIRK_IGNORE }, | ||
593 | { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20, HID_QUIRK_IGNORE }, | ||
594 | { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20, HID_QUIRK_IGNORE }, | ||
595 | { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT, HID_QUIRK_IGNORE }, | ||
596 | { USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K, HID_QUIRK_IGNORE }, | ||
597 | |||
598 | { USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR, HID_QUIRK_IGNORE }, | ||
599 | { USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302, HID_QUIRK_IGNORE }, | ||
600 | |||
601 | { USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1, HID_QUIRK_IGNORE }, | ||
602 | { USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT2, HID_QUIRK_IGNORE }, | ||
603 | |||
604 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD, HID_QUIRK_LOGITECH_IGNORE_DOUBLED_WHEEL | HID_QUIRK_LOGITECH_EXPANDED_KEYMAP }, | ||
605 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500, HID_QUIRK_LOGITECH_IGNORE_DOUBLED_WHEEL | HID_QUIRK_LOGITECH_EXPANDED_KEYMAP }, | ||
606 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_LX3, HID_QUIRK_INVERT_HWHEEL }, | ||
607 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_V150, HID_QUIRK_INVERT_HWHEEL }, | ||
608 | |||
609 | { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K, HID_QUIRK_MICROSOFT_KEYS }, | ||
610 | { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K, HID_QUIRK_MICROSOFT_KEYS }, | ||
611 | |||
612 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE, HID_QUIRK_MIGHTYMOUSE | HID_QUIRK_INVERT_HWHEEL }, | ||
613 | |||
614 | { USB_VENDOR_ID_PANTHERLORD, USB_DEVICE_ID_PANTHERLORD_TWIN_USB_JOYSTICK, HID_QUIRK_MULTI_INPUT | HID_QUIRK_SKIP_OUTPUT_REPORTS }, | 45 | { USB_VENDOR_ID_PANTHERLORD, USB_DEVICE_ID_PANTHERLORD_TWIN_USB_JOYSTICK, HID_QUIRK_MULTI_INPUT | HID_QUIRK_SKIP_OUTPUT_REPORTS }, |
615 | { USB_VENDOR_ID_PLAYDOTCOM, USB_DEVICE_ID_PLAYDOTCOM_EMS_USBII, HID_QUIRK_MULTI_INPUT }, | 46 | { USB_VENDOR_ID_PLAYDOTCOM, USB_DEVICE_ID_PLAYDOTCOM_EMS_USBII, HID_QUIRK_MULTI_INPUT }, |
616 | 47 | ||
617 | { USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER, HID_QUIRK_SONY_PS3_CONTROLLER | HID_QUIRK_HIDDEV }, | ||
618 | |||
619 | { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_UC100KM, HID_QUIRK_NOGET }, | 48 | { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_UC100KM, HID_QUIRK_NOGET }, |
620 | { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_CS124U, HID_QUIRK_NOGET }, | 49 | { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_CS124U, HID_QUIRK_NOGET }, |
621 | { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_2PORTKVM, HID_QUIRK_NOGET }, | 50 | { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_2PORTKVM, HID_QUIRK_NOGET }, |
@@ -623,144 +52,13 @@ static const struct hid_blacklist { | |||
623 | { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVMC, HID_QUIRK_NOGET }, | 52 | { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVMC, HID_QUIRK_NOGET }, |
624 | { USB_VENDOR_ID_DMI, USB_DEVICE_ID_DMI_ENC, HID_QUIRK_NOGET }, | 53 | { USB_VENDOR_ID_DMI, USB_DEVICE_ID_DMI_ENC, HID_QUIRK_NOGET }, |
625 | { USB_VENDOR_ID_ELO, USB_DEVICE_ID_ELO_TS2700, HID_QUIRK_NOGET }, | 54 | { USB_VENDOR_ID_ELO, USB_DEVICE_ID_ELO_TS2700, HID_QUIRK_NOGET }, |
626 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D, HID_QUIRK_NOGET }, | ||
627 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL, HID_QUIRK_NOGET }, | ||
628 | { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0, HID_QUIRK_NOGET }, | ||
629 | { USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE, HID_QUIRK_NOGET }, | ||
630 | { USB_VENDOR_ID_SUN, USB_DEVICE_ID_RARITAN_KVM_DONGLE, HID_QUIRK_NOGET }, | 55 | { USB_VENDOR_ID_SUN, USB_DEVICE_ID_RARITAN_KVM_DONGLE, HID_QUIRK_NOGET }, |
631 | { USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_KEYBOARD, HID_QUIRK_NOGET }, | 56 | { USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_KEYBOARD, HID_QUIRK_NOGET }, |
632 | { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT | HID_QUIRK_SKIP_OUTPUT_REPORTS }, | 57 | { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT | HID_QUIRK_SKIP_OUTPUT_REPORTS }, |
633 | { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_QUAD_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT }, | 58 | { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_QUAD_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT }, |
634 | 59 | ||
635 | { USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SMARTJOY_DUAL_PLUS, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT }, | 60 | { USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SMARTJOY_DUAL_PLUS, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT }, |
636 | 61 | { USB_VENDOR_ID_WISEGROUP_LTD2, USB_DEVICE_ID_SMARTJOY_DUAL_PLUS, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT }, | |
637 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE }, | ||
638 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE }, | ||
639 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE }, | ||
640 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE | HID_QUIRK_APPLE_ISO_KEYBOARD}, | ||
641 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE }, | ||
642 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE }, | ||
643 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE | HID_QUIRK_APPLE_ISO_KEYBOARD}, | ||
644 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE }, | ||
645 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE }, | ||
646 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE | HID_QUIRK_APPLE_ISO_KEYBOARD}, | ||
647 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE }, | ||
648 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI, HID_QUIRK_APPLE_HAS_FN }, | ||
649 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO, HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_APPLE_ISO_KEYBOARD }, | ||
650 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS, HID_QUIRK_APPLE_HAS_FN }, | ||
651 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE }, | ||
652 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE }, | ||
653 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE }, | ||
654 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN }, | ||
655 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_APPLE_ISO_KEYBOARD }, | ||
656 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN }, | ||
657 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI, HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE }, | ||
658 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO, HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_APPLE_ISO_KEYBOARD | HID_QUIRK_IGNORE_MOUSE}, | ||
659 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS, HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE}, | ||
660 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI, HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE}, | ||
661 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO, HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_APPLE_ISO_KEYBOARD | HID_QUIRK_IGNORE_MOUSE }, | ||
662 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS, HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE }, | ||
663 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE }, | ||
664 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE }, | ||
665 | |||
666 | { USB_VENDOR_ID_DELL, USB_DEVICE_ID_DELL_W7658, HID_QUIRK_RESET_LEDS }, | ||
667 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_KBD, HID_QUIRK_RESET_LEDS }, | ||
668 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY, HID_QUIRK_IGNORE }, | ||
669 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_2, HID_QUIRK_IGNORE }, | ||
670 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_3, HID_QUIRK_IGNORE }, | ||
671 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_4, HID_QUIRK_IGNORE }, | ||
672 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_5, HID_QUIRK_IGNORE }, | ||
673 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_6, HID_QUIRK_IGNORE }, | ||
674 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_7, HID_QUIRK_IGNORE }, | ||
675 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_8, HID_QUIRK_IGNORE }, | ||
676 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_9, HID_QUIRK_IGNORE }, | ||
677 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_10, HID_QUIRK_IGNORE }, | ||
678 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_11, HID_QUIRK_IGNORE }, | ||
679 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_12, HID_QUIRK_IGNORE }, | ||
680 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_13, HID_QUIRK_IGNORE }, | ||
681 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_14, HID_QUIRK_IGNORE }, | ||
682 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_15, HID_QUIRK_IGNORE }, | ||
683 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_16, HID_QUIRK_IGNORE }, | ||
684 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_17, HID_QUIRK_IGNORE }, | ||
685 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_18, HID_QUIRK_IGNORE }, | ||
686 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_19, HID_QUIRK_IGNORE }, | ||
687 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_20, HID_QUIRK_IGNORE }, | ||
688 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_21, HID_QUIRK_IGNORE }, | ||
689 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_22, HID_QUIRK_IGNORE }, | ||
690 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_23, HID_QUIRK_IGNORE }, | ||
691 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_24, HID_QUIRK_IGNORE }, | ||
692 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_25, HID_QUIRK_IGNORE }, | ||
693 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_26, HID_QUIRK_IGNORE }, | ||
694 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_27, HID_QUIRK_IGNORE }, | ||
695 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_28, HID_QUIRK_IGNORE }, | ||
696 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_29, HID_QUIRK_IGNORE }, | ||
697 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_30, HID_QUIRK_IGNORE }, | ||
698 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_31, HID_QUIRK_IGNORE }, | ||
699 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_32, HID_QUIRK_IGNORE }, | ||
700 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_33, HID_QUIRK_IGNORE }, | ||
701 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_34, HID_QUIRK_IGNORE }, | ||
702 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_35, HID_QUIRK_IGNORE }, | ||
703 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_36, HID_QUIRK_IGNORE }, | ||
704 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_37, HID_QUIRK_IGNORE }, | ||
705 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_38, HID_QUIRK_IGNORE }, | ||
706 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_39, HID_QUIRK_IGNORE }, | ||
707 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_40, HID_QUIRK_IGNORE }, | ||
708 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_41, HID_QUIRK_IGNORE }, | ||
709 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_42, HID_QUIRK_IGNORE }, | ||
710 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_43, HID_QUIRK_IGNORE }, | ||
711 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_44, HID_QUIRK_IGNORE }, | ||
712 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_45, HID_QUIRK_IGNORE }, | ||
713 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_46, HID_QUIRK_IGNORE }, | ||
714 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_47, HID_QUIRK_IGNORE }, | ||
715 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_48, HID_QUIRK_IGNORE }, | ||
716 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_49, HID_QUIRK_IGNORE }, | ||
717 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_50, HID_QUIRK_IGNORE }, | ||
718 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_51, HID_QUIRK_IGNORE }, | ||
719 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_52, HID_QUIRK_IGNORE }, | ||
720 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_53, HID_QUIRK_IGNORE }, | ||
721 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_54, HID_QUIRK_IGNORE }, | ||
722 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_55, HID_QUIRK_IGNORE }, | ||
723 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_56, HID_QUIRK_IGNORE }, | ||
724 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_57, HID_QUIRK_IGNORE }, | ||
725 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_58, HID_QUIRK_IGNORE }, | ||
726 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_59, HID_QUIRK_IGNORE }, | ||
727 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_60, HID_QUIRK_IGNORE }, | ||
728 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_61, HID_QUIRK_IGNORE }, | ||
729 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_62, HID_QUIRK_IGNORE }, | ||
730 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_63, HID_QUIRK_IGNORE }, | ||
731 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_64, HID_QUIRK_IGNORE }, | ||
732 | { USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR, USB_DEVICE_ID_N_S_HARMONY, HID_QUIRK_IGNORE }, | ||
733 | { USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_GPEN_560, HID_QUIRK_IGNORE }, | ||
734 | |||
735 | { 0, 0 } | ||
736 | }; | ||
737 | |||
738 | /* Quirks for devices which require report descriptor fixup go here */ | ||
739 | static const struct hid_rdesc_blacklist { | ||
740 | __u16 idVendor; | ||
741 | __u16 idProduct; | ||
742 | __u32 quirks; | ||
743 | } hid_rdesc_blacklist[] = { | ||
744 | |||
745 | { USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION, HID_QUIRK_RDESC_CYMOTION }, | ||
746 | |||
747 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER, HID_QUIRK_RDESC_LOGITECH }, | ||
748 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER, HID_QUIRK_RDESC_LOGITECH }, | ||
749 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2, HID_QUIRK_RDESC_LOGITECH }, | ||
750 | { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_DESKTOP_RECV_1028, HID_QUIRK_RDESC_MICROSOFT_RECV_1028 }, | ||
751 | |||
752 | { USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E, HID_QUIRK_RDESC_BUTTON_CONSUMER }, | ||
753 | |||
754 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS, HID_QUIRK_RDESC_MACBOOK_JIS }, | ||
755 | |||
756 | { USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE, HID_QUIRK_RDESC_PETALYNX }, | ||
757 | |||
758 | { USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE, HID_QUIRK_RDESC_SAMSUNG_REMOTE }, | ||
759 | |||
760 | { USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP, HID_QUIRK_RDESC_SUNPLUS_WDESKTOP }, | ||
761 | |||
762 | { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1, HID_QUIRK_RDESC_SWAPPED_MIN_MAX }, | ||
763 | { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2, HID_QUIRK_RDESC_SWAPPED_MIN_MAX }, | ||
764 | 62 | ||
765 | { 0, 0 } | 63 | { 0, 0 } |
766 | }; | 64 | }; |
@@ -974,16 +272,6 @@ u32 usbhid_lookup_quirk(const u16 idVendor, const u16 idProduct) | |||
974 | u32 quirks = 0; | 272 | u32 quirks = 0; |
975 | const struct hid_blacklist *bl_entry = NULL; | 273 | const struct hid_blacklist *bl_entry = NULL; |
976 | 274 | ||
977 | /* Ignore all Wacom devices */ | ||
978 | if (idVendor == USB_VENDOR_ID_WACOM) | ||
979 | return HID_QUIRK_IGNORE; | ||
980 | |||
981 | /* ignore all Code Mercenaries IOWarrior devices */ | ||
982 | if (idVendor == USB_VENDOR_ID_CODEMERCS) | ||
983 | if (idProduct >= USB_DEVICE_ID_CODEMERCS_IOW_FIRST && | ||
984 | idProduct <= USB_DEVICE_ID_CODEMERCS_IOW_LAST) | ||
985 | return HID_QUIRK_IGNORE; | ||
986 | |||
987 | /* NCR devices must not be queried for reports */ | 275 | /* NCR devices must not be queried for reports */ |
988 | if (idVendor == USB_VENDOR_ID_NCR && | 276 | if (idVendor == USB_VENDOR_ID_NCR && |
989 | idProduct >= USB_DEVICE_ID_NCR_FIRST && | 277 | idProduct >= USB_DEVICE_ID_NCR_FIRST && |
@@ -1002,221 +290,3 @@ u32 usbhid_lookup_quirk(const u16 idVendor, const u16 idProduct) | |||
1002 | } | 290 | } |
1003 | 291 | ||
1004 | EXPORT_SYMBOL_GPL(usbhid_lookup_quirk); | 292 | EXPORT_SYMBOL_GPL(usbhid_lookup_quirk); |
1005 | |||
1006 | /* | ||
1007 | * Cherry Cymotion keyboard have an invalid HID report descriptor, | ||
1008 | * that needs fixing before we can parse it. | ||
1009 | */ | ||
1010 | static void usbhid_fixup_cymotion_descriptor(char *rdesc, int rsize) | ||
1011 | { | ||
1012 | if (rsize >= 17 && rdesc[11] == 0x3c && rdesc[12] == 0x02) { | ||
1013 | printk(KERN_INFO "Fixing up Cherry Cymotion report descriptor\n"); | ||
1014 | rdesc[11] = rdesc[16] = 0xff; | ||
1015 | rdesc[12] = rdesc[17] = 0x03; | ||
1016 | } | ||
1017 | } | ||
1018 | |||
1019 | |||
1020 | /* | ||
1021 | * Certain Logitech keyboards send in report #3 keys which are far | ||
1022 | * above the logical maximum described in descriptor. This extends | ||
1023 | * the original value of 0x28c of logical maximum to 0x104d | ||
1024 | */ | ||
1025 | static void usbhid_fixup_logitech_descriptor(unsigned char *rdesc, int rsize) | ||
1026 | { | ||
1027 | if (rsize >= 90 && rdesc[83] == 0x26 | ||
1028 | && rdesc[84] == 0x8c | ||
1029 | && rdesc[85] == 0x02) { | ||
1030 | printk(KERN_INFO "Fixing up Logitech keyboard report descriptor\n"); | ||
1031 | rdesc[84] = rdesc[89] = 0x4d; | ||
1032 | rdesc[85] = rdesc[90] = 0x10; | ||
1033 | } | ||
1034 | } | ||
1035 | |||
1036 | static void usbhid_fixup_sunplus_wdesktop(unsigned char *rdesc, int rsize) | ||
1037 | { | ||
1038 | if (rsize >= 107 && rdesc[104] == 0x26 | ||
1039 | && rdesc[105] == 0x80 | ||
1040 | && rdesc[106] == 0x03) { | ||
1041 | printk(KERN_INFO "Fixing up Sunplus Wireless Desktop report descriptor\n"); | ||
1042 | rdesc[105] = rdesc[110] = 0x03; | ||
1043 | rdesc[106] = rdesc[111] = 0x21; | ||
1044 | } | ||
1045 | } | ||
1046 | |||
1047 | /* | ||
1048 | * Samsung IrDA remote controller (reports as Cypress USB Mouse). | ||
1049 | * | ||
1050 | * Vendor specific report #4 has a size of 48 bit, | ||
1051 | * and therefore is not accepted when inspecting the descriptors. | ||
1052 | * As a workaround we reinterpret the report as: | ||
1053 | * Variable type, count 6, size 8 bit, log. maximum 255 | ||
1054 | * The burden to reconstruct the data is moved into user space. | ||
1055 | */ | ||
1056 | static void usbhid_fixup_samsung_irda_descriptor(unsigned char *rdesc, | ||
1057 | int rsize) | ||
1058 | { | ||
1059 | if (rsize >= 182 && rdesc[175] == 0x25 | ||
1060 | && rdesc[176] == 0x40 | ||
1061 | && rdesc[177] == 0x75 | ||
1062 | && rdesc[178] == 0x30 | ||
1063 | && rdesc[179] == 0x95 | ||
1064 | && rdesc[180] == 0x01 | ||
1065 | && rdesc[182] == 0x40) { | ||
1066 | printk(KERN_INFO "Fixing up Samsung IrDA report descriptor\n"); | ||
1067 | rdesc[176] = 0xff; | ||
1068 | rdesc[178] = 0x08; | ||
1069 | rdesc[180] = 0x06; | ||
1070 | rdesc[182] = 0x42; | ||
1071 | } | ||
1072 | } | ||
1073 | |||
1074 | /* Petalynx Maxter Remote has maximum for consumer page set too low */ | ||
1075 | static void usbhid_fixup_petalynx_descriptor(unsigned char *rdesc, int rsize) | ||
1076 | { | ||
1077 | if (rsize >= 60 && rdesc[39] == 0x2a | ||
1078 | && rdesc[40] == 0xf5 | ||
1079 | && rdesc[41] == 0x00 | ||
1080 | && rdesc[59] == 0x26 | ||
1081 | && rdesc[60] == 0xf9 | ||
1082 | && rdesc[61] == 0x00) { | ||
1083 | printk(KERN_INFO "Fixing up Petalynx Maxter Remote report descriptor\n"); | ||
1084 | rdesc[60] = 0xfa; | ||
1085 | rdesc[40] = 0xfa; | ||
1086 | } | ||
1087 | } | ||
1088 | |||
1089 | /* | ||
1090 | * Some USB barcode readers from cypress have usage min and usage max in | ||
1091 | * the wrong order | ||
1092 | */ | ||
1093 | static void usbhid_fixup_cypress_descriptor(unsigned char *rdesc, int rsize) | ||
1094 | { | ||
1095 | short fixed = 0; | ||
1096 | int i; | ||
1097 | |||
1098 | for (i = 0; i < rsize - 4; i++) { | ||
1099 | if (rdesc[i] == 0x29 && rdesc [i+2] == 0x19) { | ||
1100 | unsigned char tmp; | ||
1101 | |||
1102 | rdesc[i] = 0x19; rdesc[i+2] = 0x29; | ||
1103 | tmp = rdesc[i+3]; | ||
1104 | rdesc[i+3] = rdesc[i+1]; | ||
1105 | rdesc[i+1] = tmp; | ||
1106 | } | ||
1107 | } | ||
1108 | |||
1109 | if (fixed) | ||
1110 | printk(KERN_INFO "Fixing up Cypress report descriptor\n"); | ||
1111 | } | ||
1112 | |||
1113 | /* | ||
1114 | * MacBook JIS keyboard has wrong logical maximum | ||
1115 | */ | ||
1116 | static void usbhid_fixup_macbook_descriptor(unsigned char *rdesc, int rsize) | ||
1117 | { | ||
1118 | if (rsize >= 60 && rdesc[53] == 0x65 | ||
1119 | && rdesc[59] == 0x65) { | ||
1120 | printk(KERN_INFO "Fixing up MacBook JIS keyboard report descriptor\n"); | ||
1121 | rdesc[53] = rdesc[59] = 0xe7; | ||
1122 | } | ||
1123 | } | ||
1124 | |||
1125 | static void usbhid_fixup_button_consumer_descriptor(unsigned char *rdesc, int rsize) | ||
1126 | { | ||
1127 | if (rsize >= 30 && rdesc[29] == 0x05 | ||
1128 | && rdesc[30] == 0x09) { | ||
1129 | printk(KERN_INFO "Fixing up button/consumer in HID report descriptor\n"); | ||
1130 | rdesc[30] = 0x0c; | ||
1131 | } | ||
1132 | } | ||
1133 | |||
1134 | /* | ||
1135 | * Microsoft Wireless Desktop Receiver (Model 1028) has several | ||
1136 | * 'Usage Min/Max' where it ought to have 'Physical Min/Max' | ||
1137 | */ | ||
1138 | static void usbhid_fixup_microsoft_descriptor(unsigned char *rdesc, int rsize) | ||
1139 | { | ||
1140 | if (rsize == 571 && rdesc[284] == 0x19 | ||
1141 | && rdesc[286] == 0x2a | ||
1142 | && rdesc[304] == 0x19 | ||
1143 | && rdesc[306] == 0x29 | ||
1144 | && rdesc[352] == 0x1a | ||
1145 | && rdesc[355] == 0x2a | ||
1146 | && rdesc[557] == 0x19 | ||
1147 | && rdesc[559] == 0x29) { | ||
1148 | printk(KERN_INFO "Fixing up Microsoft Wireless Receiver Model 1028 report descriptor\n"); | ||
1149 | rdesc[284] = rdesc[304] = rdesc[557] = 0x35; | ||
1150 | rdesc[352] = 0x36; | ||
1151 | rdesc[286] = rdesc[355] = 0x46; | ||
1152 | rdesc[306] = rdesc[559] = 0x45; | ||
1153 | } | ||
1154 | } | ||
1155 | |||
1156 | static void __usbhid_fixup_report_descriptor(__u32 quirks, char *rdesc, unsigned rsize) | ||
1157 | { | ||
1158 | if ((quirks & HID_QUIRK_RDESC_CYMOTION)) | ||
1159 | usbhid_fixup_cymotion_descriptor(rdesc, rsize); | ||
1160 | |||
1161 | if (quirks & HID_QUIRK_RDESC_LOGITECH) | ||
1162 | usbhid_fixup_logitech_descriptor(rdesc, rsize); | ||
1163 | |||
1164 | if (quirks & HID_QUIRK_RDESC_SWAPPED_MIN_MAX) | ||
1165 | usbhid_fixup_cypress_descriptor(rdesc, rsize); | ||
1166 | |||
1167 | if (quirks & HID_QUIRK_RDESC_PETALYNX) | ||
1168 | usbhid_fixup_petalynx_descriptor(rdesc, rsize); | ||
1169 | |||
1170 | if (quirks & HID_QUIRK_RDESC_MACBOOK_JIS) | ||
1171 | usbhid_fixup_macbook_descriptor(rdesc, rsize); | ||
1172 | |||
1173 | if (quirks & HID_QUIRK_RDESC_BUTTON_CONSUMER) | ||
1174 | usbhid_fixup_button_consumer_descriptor(rdesc, rsize); | ||
1175 | |||
1176 | if (quirks & HID_QUIRK_RDESC_SAMSUNG_REMOTE) | ||
1177 | usbhid_fixup_samsung_irda_descriptor(rdesc, rsize); | ||
1178 | |||
1179 | if (quirks & HID_QUIRK_RDESC_MICROSOFT_RECV_1028) | ||
1180 | usbhid_fixup_microsoft_descriptor(rdesc, rsize); | ||
1181 | |||
1182 | if (quirks & HID_QUIRK_RDESC_SUNPLUS_WDESKTOP) | ||
1183 | usbhid_fixup_sunplus_wdesktop(rdesc, rsize); | ||
1184 | } | ||
1185 | |||
1186 | /** | ||
1187 | * usbhid_fixup_report_descriptor: check if report descriptor needs fixup | ||
1188 | * | ||
1189 | * Description: | ||
1190 | * Walks the hid_rdesc_blacklist[] array and checks whether the device | ||
1191 | * is known to have broken report descriptor that needs to be fixed up | ||
1192 | * prior to entering the HID parser | ||
1193 | * | ||
1194 | * Returns: nothing | ||
1195 | */ | ||
1196 | void usbhid_fixup_report_descriptor(const u16 idVendor, const u16 idProduct, | ||
1197 | char *rdesc, unsigned rsize, char **quirks_param) | ||
1198 | { | ||
1199 | int n, m; | ||
1200 | u16 paramVendor, paramProduct; | ||
1201 | u32 quirks; | ||
1202 | |||
1203 | /* static rdesc quirk entries */ | ||
1204 | for (n = 0; hid_rdesc_blacklist[n].idVendor; n++) | ||
1205 | if (hid_rdesc_blacklist[n].idVendor == idVendor && | ||
1206 | hid_rdesc_blacklist[n].idProduct == idProduct) | ||
1207 | __usbhid_fixup_report_descriptor(hid_rdesc_blacklist[n].quirks, | ||
1208 | rdesc, rsize); | ||
1209 | |||
1210 | /* runtime rdesc quirk entries handling */ | ||
1211 | for (n = 0; quirks_param[n] && n < MAX_USBHID_BOOT_QUIRKS; n++) { | ||
1212 | m = sscanf(quirks_param[n], "0x%hx:0x%hx:0x%x", | ||
1213 | ¶mVendor, ¶mProduct, &quirks); | ||
1214 | |||
1215 | if (m != 3) | ||
1216 | printk(KERN_WARNING | ||
1217 | "Could not parse HID quirk module param %s\n", | ||
1218 | quirks_param[n]); | ||
1219 | else if (paramVendor == idVendor && paramProduct == idProduct) | ||
1220 | __usbhid_fixup_report_descriptor(quirks, rdesc, rsize); | ||
1221 | } | ||
1222 | } | ||
diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c index 842e9edb888e..babd65dd46ad 100644 --- a/drivers/hid/usbhid/hiddev.c +++ b/drivers/hid/usbhid/hiddev.c | |||
@@ -790,21 +790,23 @@ static struct usb_class_driver hiddev_class = { | |||
790 | /* | 790 | /* |
791 | * This is where hid.c calls us to connect a hid device to the hiddev driver | 791 | * This is where hid.c calls us to connect a hid device to the hiddev driver |
792 | */ | 792 | */ |
793 | int hiddev_connect(struct hid_device *hid) | 793 | int hiddev_connect(struct hid_device *hid, unsigned int force) |
794 | { | 794 | { |
795 | struct hiddev *hiddev; | 795 | struct hiddev *hiddev; |
796 | struct usbhid_device *usbhid = hid->driver_data; | 796 | struct usbhid_device *usbhid = hid->driver_data; |
797 | int i; | ||
798 | int retval; | 797 | int retval; |
799 | 798 | ||
800 | for (i = 0; i < hid->maxcollection; i++) | 799 | if (!force) { |
801 | if (hid->collection[i].type == | 800 | unsigned int i; |
802 | HID_COLLECTION_APPLICATION && | 801 | for (i = 0; i < hid->maxcollection; i++) |
803 | !IS_INPUT_APPLICATION(hid->collection[i].usage)) | 802 | if (hid->collection[i].type == |
804 | break; | 803 | HID_COLLECTION_APPLICATION && |
804 | !IS_INPUT_APPLICATION(hid->collection[i].usage)) | ||
805 | break; | ||
805 | 806 | ||
806 | if (i == hid->maxcollection && (hid->quirks & HID_QUIRK_HIDDEV) == 0) | 807 | if (i == hid->maxcollection) |
807 | return -1; | 808 | return -1; |
809 | } | ||
808 | 810 | ||
809 | if (!(hiddev = kzalloc(sizeof(struct hiddev), GFP_KERNEL))) | 811 | if (!(hiddev = kzalloc(sizeof(struct hiddev), GFP_KERNEL))) |
810 | return -1; | 812 | return -1; |
diff --git a/drivers/hid/usbhid/usbhid.h b/drivers/hid/usbhid/usbhid.h index 62d2d7c925bd..abedb13c623e 100644 --- a/drivers/hid/usbhid/usbhid.h +++ b/drivers/hid/usbhid/usbhid.h | |||
@@ -67,7 +67,7 @@ struct usbhid_device { | |||
67 | spinlock_t ctrllock; /* Control fifo spinlock */ | 67 | spinlock_t ctrllock; /* Control fifo spinlock */ |
68 | 68 | ||
69 | struct urb *urbout; /* Output URB */ | 69 | struct urb *urbout; /* Output URB */ |
70 | struct hid_report *out[HID_CONTROL_FIFO_SIZE]; /* Output pipe fifo */ | 70 | struct hid_output_fifo out[HID_CONTROL_FIFO_SIZE]; /* Output pipe fifo */ |
71 | unsigned char outhead, outtail; /* Output pipe fifo head & tail */ | 71 | unsigned char outhead, outtail; /* Output pipe fifo head & tail */ |
72 | char *outbuf; /* Output buffer */ | 72 | char *outbuf; /* Output buffer */ |
73 | dma_addr_t outbuf_dma; /* Output buffer dma */ | 73 | dma_addr_t outbuf_dma; /* Output buffer dma */ |
@@ -82,7 +82,7 @@ struct usbhid_device { | |||
82 | }; | 82 | }; |
83 | 83 | ||
84 | #define hid_to_usb_dev(hid_dev) \ | 84 | #define hid_to_usb_dev(hid_dev) \ |
85 | container_of(hid_dev->dev->parent, struct usb_device, dev) | 85 | container_of(hid_dev->dev.parent->parent, struct usb_device, dev) |
86 | 86 | ||
87 | #endif | 87 | #endif |
88 | 88 | ||
diff --git a/drivers/hid/usbhid/usbkbd.c b/drivers/hid/usbhid/usbkbd.c index 0caaafe01843..b342926dd7fc 100644 --- a/drivers/hid/usbhid/usbkbd.c +++ b/drivers/hid/usbhid/usbkbd.c | |||
@@ -105,14 +105,16 @@ static void usb_kbd_irq(struct urb *urb) | |||
105 | if (usb_kbd_keycode[kbd->old[i]]) | 105 | if (usb_kbd_keycode[kbd->old[i]]) |
106 | input_report_key(kbd->dev, usb_kbd_keycode[kbd->old[i]], 0); | 106 | input_report_key(kbd->dev, usb_kbd_keycode[kbd->old[i]], 0); |
107 | else | 107 | else |
108 | info("Unknown key (scancode %#x) released.", kbd->old[i]); | 108 | dev_info(&urb->dev->dev, |
109 | "Unknown key (scancode %#x) released.\n", kbd->old[i]); | ||
109 | } | 110 | } |
110 | 111 | ||
111 | if (kbd->new[i] > 3 && memscan(kbd->old + 2, kbd->new[i], 6) == kbd->old + 8) { | 112 | if (kbd->new[i] > 3 && memscan(kbd->old + 2, kbd->new[i], 6) == kbd->old + 8) { |
112 | if (usb_kbd_keycode[kbd->new[i]]) | 113 | if (usb_kbd_keycode[kbd->new[i]]) |
113 | input_report_key(kbd->dev, usb_kbd_keycode[kbd->new[i]], 1); | 114 | input_report_key(kbd->dev, usb_kbd_keycode[kbd->new[i]], 1); |
114 | else | 115 | else |
115 | info("Unknown key (scancode %#x) pressed.", kbd->new[i]); | 116 | dev_info(&urb->dev->dev, |
117 | "Unknown key (scancode %#x) released.\n", kbd->new[i]); | ||
116 | } | 118 | } |
117 | } | 119 | } |
118 | 120 | ||
@@ -159,7 +161,8 @@ static void usb_kbd_led(struct urb *urb) | |||
159 | struct usb_kbd *kbd = urb->context; | 161 | struct usb_kbd *kbd = urb->context; |
160 | 162 | ||
161 | if (urb->status) | 163 | if (urb->status) |
162 | warn("led urb status %d received", urb->status); | 164 | dev_warn(&urb->dev->dev, "led urb status %d received\n", |
165 | urb->status); | ||
163 | 166 | ||
164 | if (*(kbd->leds) == kbd->newleds) | 167 | if (*(kbd->leds) == kbd->newleds) |
165 | return; | 168 | return; |
@@ -352,7 +355,8 @@ static int __init usb_kbd_init(void) | |||
352 | { | 355 | { |
353 | int result = usb_register(&usb_kbd_driver); | 356 | int result = usb_register(&usb_kbd_driver); |
354 | if (result == 0) | 357 | if (result == 0) |
355 | info(DRIVER_VERSION ":" DRIVER_DESC); | 358 | printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" |
359 | DRIVER_DESC "\n"); | ||
356 | return result; | 360 | return result; |
357 | } | 361 | } |
358 | 362 | ||
diff --git a/drivers/hid/usbhid/usbmouse.c b/drivers/hid/usbhid/usbmouse.c index 35689ef172cc..72ab4b268096 100644 --- a/drivers/hid/usbhid/usbmouse.c +++ b/drivers/hid/usbhid/usbmouse.c | |||
@@ -31,6 +31,11 @@ | |||
31 | #include <linux/usb/input.h> | 31 | #include <linux/usb/input.h> |
32 | #include <linux/hid.h> | 32 | #include <linux/hid.h> |
33 | 33 | ||
34 | /* for apple IDs */ | ||
35 | #ifdef CONFIG_USB_HID_MODULE | ||
36 | #include "../hid-ids.h" | ||
37 | #endif | ||
38 | |||
34 | /* | 39 | /* |
35 | * Version Information | 40 | * Version Information |
36 | */ | 41 | */ |
@@ -240,7 +245,8 @@ static int __init usb_mouse_init(void) | |||
240 | { | 245 | { |
241 | int retval = usb_register(&usb_mouse_driver); | 246 | int retval = usb_register(&usb_mouse_driver); |
242 | if (retval == 0) | 247 | if (retval == 0) |
243 | info(DRIVER_VERSION ":" DRIVER_DESC); | 248 | printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" |
249 | DRIVER_DESC "\n"); | ||
244 | return retval; | 250 | return retval; |
245 | } | 251 | } |
246 | 252 | ||
diff --git a/drivers/input/misc/hp_sdc_rtc.c b/drivers/input/misc/hp_sdc_rtc.c index daa9d4220331..82ec6b1b6467 100644 --- a/drivers/input/misc/hp_sdc_rtc.c +++ b/drivers/input/misc/hp_sdc_rtc.c | |||
@@ -458,35 +458,35 @@ static int hp_sdc_rtc_proc_output (char *buf) | |||
458 | p += sprintf(p, "i8042 rtc\t: READ FAILED!\n"); | 458 | p += sprintf(p, "i8042 rtc\t: READ FAILED!\n"); |
459 | } else { | 459 | } else { |
460 | p += sprintf(p, "i8042 rtc\t: %ld.%02d seconds\n", | 460 | p += sprintf(p, "i8042 rtc\t: %ld.%02d seconds\n", |
461 | tv.tv_sec, tv.tv_usec/1000); | 461 | tv.tv_sec, (int)tv.tv_usec/1000); |
462 | } | 462 | } |
463 | 463 | ||
464 | if (hp_sdc_rtc_read_fhs(&tv)) { | 464 | if (hp_sdc_rtc_read_fhs(&tv)) { |
465 | p += sprintf(p, "handshake\t: READ FAILED!\n"); | 465 | p += sprintf(p, "handshake\t: READ FAILED!\n"); |
466 | } else { | 466 | } else { |
467 | p += sprintf(p, "handshake\t: %ld.%02d seconds\n", | 467 | p += sprintf(p, "handshake\t: %ld.%02d seconds\n", |
468 | tv.tv_sec, tv.tv_usec/1000); | 468 | tv.tv_sec, (int)tv.tv_usec/1000); |
469 | } | 469 | } |
470 | 470 | ||
471 | if (hp_sdc_rtc_read_mt(&tv)) { | 471 | if (hp_sdc_rtc_read_mt(&tv)) { |
472 | p += sprintf(p, "alarm\t\t: READ FAILED!\n"); | 472 | p += sprintf(p, "alarm\t\t: READ FAILED!\n"); |
473 | } else { | 473 | } else { |
474 | p += sprintf(p, "alarm\t\t: %ld.%02d seconds\n", | 474 | p += sprintf(p, "alarm\t\t: %ld.%02d seconds\n", |
475 | tv.tv_sec, tv.tv_usec/1000); | 475 | tv.tv_sec, (int)tv.tv_usec/1000); |
476 | } | 476 | } |
477 | 477 | ||
478 | if (hp_sdc_rtc_read_dt(&tv)) { | 478 | if (hp_sdc_rtc_read_dt(&tv)) { |
479 | p += sprintf(p, "delay\t\t: READ FAILED!\n"); | 479 | p += sprintf(p, "delay\t\t: READ FAILED!\n"); |
480 | } else { | 480 | } else { |
481 | p += sprintf(p, "delay\t\t: %ld.%02d seconds\n", | 481 | p += sprintf(p, "delay\t\t: %ld.%02d seconds\n", |
482 | tv.tv_sec, tv.tv_usec/1000); | 482 | tv.tv_sec, (int)tv.tv_usec/1000); |
483 | } | 483 | } |
484 | 484 | ||
485 | if (hp_sdc_rtc_read_ct(&tv)) { | 485 | if (hp_sdc_rtc_read_ct(&tv)) { |
486 | p += sprintf(p, "periodic\t: READ FAILED!\n"); | 486 | p += sprintf(p, "periodic\t: READ FAILED!\n"); |
487 | } else { | 487 | } else { |
488 | p += sprintf(p, "periodic\t: %ld.%02d seconds\n", | 488 | p += sprintf(p, "periodic\t: %ld.%02d seconds\n", |
489 | tv.tv_sec, tv.tv_usec/1000); | 489 | tv.tv_sec, (int)tv.tv_usec/1000); |
490 | } | 490 | } |
491 | 491 | ||
492 | p += sprintf(p, | 492 | p += sprintf(p, |
diff --git a/drivers/input/serio/hp_sdc.c b/drivers/input/serio/hp_sdc.c index 0d395979b2d1..bfe49243f38b 100644 --- a/drivers/input/serio/hp_sdc.c +++ b/drivers/input/serio/hp_sdc.c | |||
@@ -323,7 +323,7 @@ static void hp_sdc_tasklet(unsigned long foo) | |||
323 | * it back to the application. and be less verbose. | 323 | * it back to the application. and be less verbose. |
324 | */ | 324 | */ |
325 | printk(KERN_WARNING PREFIX "read timeout (%ius)!\n", | 325 | printk(KERN_WARNING PREFIX "read timeout (%ius)!\n", |
326 | tv.tv_usec - hp_sdc.rtv.tv_usec); | 326 | (int)(tv.tv_usec - hp_sdc.rtv.tv_usec)); |
327 | curr->idx += hp_sdc.rqty; | 327 | curr->idx += hp_sdc.rqty; |
328 | hp_sdc.rqty = 0; | 328 | hp_sdc.rqty = 0; |
329 | tmp = curr->seq[curr->actidx]; | 329 | tmp = curr->seq[curr->actidx]; |
diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c index e92b1ba4b45e..c2f51cc50760 100644 --- a/drivers/isdn/mISDN/dsp_cmx.c +++ b/drivers/isdn/mISDN/dsp_cmx.c | |||
@@ -452,10 +452,10 @@ one_member: | |||
452 | if (finddsp->features.pcm_id == dsp->features.pcm_id) { | 452 | if (finddsp->features.pcm_id == dsp->features.pcm_id) { |
453 | if (finddsp->pcm_slot_rx >= 0 && | 453 | if (finddsp->pcm_slot_rx >= 0 && |
454 | finddsp->pcm_slot_rx < sizeof(freeslots)) | 454 | finddsp->pcm_slot_rx < sizeof(freeslots)) |
455 | freeslots[finddsp->pcm_slot_tx] = 0; | 455 | freeslots[finddsp->pcm_slot_rx] = 0; |
456 | if (finddsp->pcm_slot_tx >= 0 && | 456 | if (finddsp->pcm_slot_tx >= 0 && |
457 | finddsp->pcm_slot_tx < sizeof(freeslots)) | 457 | finddsp->pcm_slot_tx < sizeof(freeslots)) |
458 | freeslots[finddsp->pcm_slot_rx] = 0; | 458 | freeslots[finddsp->pcm_slot_tx] = 0; |
459 | } | 459 | } |
460 | } | 460 | } |
461 | i = 0; | 461 | i = 0; |
diff --git a/drivers/isdn/mISDN/timerdev.c b/drivers/isdn/mISDN/timerdev.c index e7462924b505..875fabe16e36 100644 --- a/drivers/isdn/mISDN/timerdev.c +++ b/drivers/isdn/mISDN/timerdev.c | |||
@@ -61,7 +61,7 @@ mISDN_open(struct inode *ino, struct file *filep) | |||
61 | init_waitqueue_head(&dev->wait); | 61 | init_waitqueue_head(&dev->wait); |
62 | filep->private_data = dev; | 62 | filep->private_data = dev; |
63 | __module_get(THIS_MODULE); | 63 | __module_get(THIS_MODULE); |
64 | return 0; | 64 | return nonseekable_open(ino, filep); |
65 | } | 65 | } |
66 | 66 | ||
67 | static int | 67 | static int |
diff --git a/drivers/md/Kconfig b/drivers/md/Kconfig index 07d92c11b5d8..2281b5098e95 100644 --- a/drivers/md/Kconfig +++ b/drivers/md/Kconfig | |||
@@ -30,6 +30,20 @@ config BLK_DEV_MD | |||
30 | 30 | ||
31 | If unsure, say N. | 31 | If unsure, say N. |
32 | 32 | ||
33 | config MD_AUTODETECT | ||
34 | bool "Autodetect RAID arrays during kernel boot" | ||
35 | depends on BLK_DEV_MD=y | ||
36 | default y | ||
37 | ---help--- | ||
38 | If you say Y here, then the kernel will try to autodetect raid | ||
39 | arrays as part of its boot process. | ||
40 | |||
41 | If you don't use raid and say Y, this autodetection can cause | ||
42 | a several-second delay in the boot time due to various | ||
43 | synchronisation steps that are part of this step. | ||
44 | |||
45 | If unsure, say Y. | ||
46 | |||
33 | config MD_LINEAR | 47 | config MD_LINEAR |
34 | tristate "Linear (append) mode" | 48 | tristate "Linear (append) mode" |
35 | depends on BLK_DEV_MD | 49 | depends on BLK_DEV_MD |
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 0dae245c6259..5eff8ad834d6 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig | |||
@@ -87,6 +87,44 @@ config MFD_TC6393XB | |||
87 | help | 87 | help |
88 | Support for Toshiba Mobile IO Controller TC6393XB | 88 | Support for Toshiba Mobile IO Controller TC6393XB |
89 | 89 | ||
90 | config MFD_WM8400 | ||
91 | tristate "Support Wolfson Microelectronics WM8400" | ||
92 | help | ||
93 | Support for the Wolfson Microelecronics WM8400 PMIC and audio | ||
94 | CODEC. This driver adds provides common support for accessing | ||
95 | the device, additional drivers must be enabled in order to use | ||
96 | the functionality of the device. | ||
97 | |||
98 | config MFD_WM8350 | ||
99 | tristate | ||
100 | |||
101 | config MFD_WM8350_CONFIG_MODE_0 | ||
102 | bool | ||
103 | depends on MFD_WM8350 | ||
104 | |||
105 | config MFD_WM8350_CONFIG_MODE_1 | ||
106 | bool | ||
107 | depends on MFD_WM8350 | ||
108 | |||
109 | config MFD_WM8350_CONFIG_MODE_2 | ||
110 | bool | ||
111 | depends on MFD_WM8350 | ||
112 | |||
113 | config MFD_WM8350_CONFIG_MODE_3 | ||
114 | bool | ||
115 | depends on MFD_WM8350 | ||
116 | |||
117 | config MFD_WM8350_I2C | ||
118 | tristate "Support Wolfson Microelectronics WM8350 with I2C" | ||
119 | select MFD_WM8350 | ||
120 | depends on I2C | ||
121 | help | ||
122 | The WM8350 is an integrated audio and power management | ||
123 | subsystem with watchdog and RTC functionality for embedded | ||
124 | systems. This option enables core support for the WM8350 with | ||
125 | I2C as the control interface. Additional options must be | ||
126 | selected to enable support for the functionality of the chip. | ||
127 | |||
90 | endmenu | 128 | endmenu |
91 | 129 | ||
92 | menu "Multimedia Capabilities Port drivers" | 130 | menu "Multimedia Capabilities Port drivers" |
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 6abebe364419..759b1fe1c891 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile | |||
@@ -12,6 +12,11 @@ obj-$(CONFIG_MFD_T7L66XB) += t7l66xb.o | |||
12 | obj-$(CONFIG_MFD_TC6387XB) += tc6387xb.o | 12 | obj-$(CONFIG_MFD_TC6387XB) += tc6387xb.o |
13 | obj-$(CONFIG_MFD_TC6393XB) += tc6393xb.o | 13 | obj-$(CONFIG_MFD_TC6393XB) += tc6393xb.o |
14 | 14 | ||
15 | obj-$(CONFIG_MFD_WM8400) += wm8400-core.o | ||
16 | wm8350-objs := wm8350-core.o wm8350-regmap.o wm8350-gpio.o | ||
17 | obj-$(CONFIG_MFD_WM8350) += wm8350.o | ||
18 | obj-$(CONFIG_MFD_WM8350_I2C) += wm8350-i2c.o | ||
19 | |||
15 | obj-$(CONFIG_MFD_CORE) += mfd-core.o | 20 | obj-$(CONFIG_MFD_CORE) += mfd-core.o |
16 | 21 | ||
17 | obj-$(CONFIG_MCP) += mcp-core.o | 22 | obj-$(CONFIG_MCP) += mcp-core.o |
diff --git a/drivers/mfd/wm8350-core.c b/drivers/mfd/wm8350-core.c new file mode 100644 index 000000000000..25a7a5d08bce --- /dev/null +++ b/drivers/mfd/wm8350-core.c | |||
@@ -0,0 +1,1273 @@ | |||
1 | /* | ||
2 | * wm8350-core.c -- Device access for Wolfson WM8350 | ||
3 | * | ||
4 | * Copyright 2007, 2008 Wolfson Microelectronics PLC. | ||
5 | * | ||
6 | * Author: Liam Girdwood, Mark Brown | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | * | ||
13 | */ | ||
14 | |||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/module.h> | ||
17 | #include <linux/init.h> | ||
18 | #include <linux/bug.h> | ||
19 | #include <linux/device.h> | ||
20 | #include <linux/delay.h> | ||
21 | #include <linux/interrupt.h> | ||
22 | #include <linux/workqueue.h> | ||
23 | |||
24 | #include <linux/mfd/wm8350/core.h> | ||
25 | #include <linux/mfd/wm8350/audio.h> | ||
26 | #include <linux/mfd/wm8350/comparator.h> | ||
27 | #include <linux/mfd/wm8350/gpio.h> | ||
28 | #include <linux/mfd/wm8350/pmic.h> | ||
29 | #include <linux/mfd/wm8350/rtc.h> | ||
30 | #include <linux/mfd/wm8350/supply.h> | ||
31 | #include <linux/mfd/wm8350/wdt.h> | ||
32 | |||
33 | #define WM8350_UNLOCK_KEY 0x0013 | ||
34 | #define WM8350_LOCK_KEY 0x0000 | ||
35 | |||
36 | #define WM8350_CLOCK_CONTROL_1 0x28 | ||
37 | #define WM8350_AIF_TEST 0x74 | ||
38 | |||
39 | /* debug */ | ||
40 | #define WM8350_BUS_DEBUG 0 | ||
41 | #if WM8350_BUS_DEBUG | ||
42 | #define dump(regs, src) do { \ | ||
43 | int i_; \ | ||
44 | u16 *src_ = src; \ | ||
45 | printk(KERN_DEBUG); \ | ||
46 | for (i_ = 0; i_ < regs; i_++) \ | ||
47 | printk(" 0x%4.4x", *src_++); \ | ||
48 | printk("\n"); \ | ||
49 | } while (0); | ||
50 | #else | ||
51 | #define dump(bytes, src) | ||
52 | #endif | ||
53 | |||
54 | #define WM8350_LOCK_DEBUG 0 | ||
55 | #if WM8350_LOCK_DEBUG | ||
56 | #define ldbg(format, arg...) printk(format, ## arg) | ||
57 | #else | ||
58 | #define ldbg(format, arg...) | ||
59 | #endif | ||
60 | |||
61 | /* | ||
62 | * WM8350 Device IO | ||
63 | */ | ||
64 | static DEFINE_MUTEX(io_mutex); | ||
65 | static DEFINE_MUTEX(reg_lock_mutex); | ||
66 | static DEFINE_MUTEX(auxadc_mutex); | ||
67 | |||
68 | /* Perform a physical read from the device. | ||
69 | */ | ||
70 | static int wm8350_phys_read(struct wm8350 *wm8350, u8 reg, int num_regs, | ||
71 | u16 *dest) | ||
72 | { | ||
73 | int i, ret; | ||
74 | int bytes = num_regs * 2; | ||
75 | |||
76 | dev_dbg(wm8350->dev, "volatile read\n"); | ||
77 | ret = wm8350->read_dev(wm8350, reg, bytes, (char *)dest); | ||
78 | |||
79 | for (i = reg; i < reg + num_regs; i++) { | ||
80 | /* Cache is CPU endian */ | ||
81 | dest[i - reg] = be16_to_cpu(dest[i - reg]); | ||
82 | |||
83 | /* Satisfy non-volatile bits from cache */ | ||
84 | dest[i - reg] &= wm8350_reg_io_map[i].vol; | ||
85 | dest[i - reg] |= wm8350->reg_cache[i]; | ||
86 | |||
87 | /* Mask out non-readable bits */ | ||
88 | dest[i - reg] &= wm8350_reg_io_map[i].readable; | ||
89 | } | ||
90 | |||
91 | dump(num_regs, dest); | ||
92 | |||
93 | return ret; | ||
94 | } | ||
95 | |||
96 | static int wm8350_read(struct wm8350 *wm8350, u8 reg, int num_regs, u16 *dest) | ||
97 | { | ||
98 | int i; | ||
99 | int end = reg + num_regs; | ||
100 | int ret = 0; | ||
101 | int bytes = num_regs * 2; | ||
102 | |||
103 | if (wm8350->read_dev == NULL) | ||
104 | return -ENODEV; | ||
105 | |||
106 | if ((reg + num_regs - 1) > WM8350_MAX_REGISTER) { | ||
107 | dev_err(wm8350->dev, "invalid reg %x\n", | ||
108 | reg + num_regs - 1); | ||
109 | return -EINVAL; | ||
110 | } | ||
111 | |||
112 | dev_dbg(wm8350->dev, | ||
113 | "%s R%d(0x%2.2x) %d regs\n", __func__, reg, reg, num_regs); | ||
114 | |||
115 | #if WM8350_BUS_DEBUG | ||
116 | /* we can _safely_ read any register, but warn if read not supported */ | ||
117 | for (i = reg; i < end; i++) { | ||
118 | if (!wm8350_reg_io_map[i].readable) | ||
119 | dev_warn(wm8350->dev, | ||
120 | "reg R%d is not readable\n", i); | ||
121 | } | ||
122 | #endif | ||
123 | |||
124 | /* if any volatile registers are required, then read back all */ | ||
125 | for (i = reg; i < end; i++) | ||
126 | if (wm8350_reg_io_map[i].vol) | ||
127 | return wm8350_phys_read(wm8350, reg, num_regs, dest); | ||
128 | |||
129 | /* no volatiles, then cache is good */ | ||
130 | dev_dbg(wm8350->dev, "cache read\n"); | ||
131 | memcpy(dest, &wm8350->reg_cache[reg], bytes); | ||
132 | dump(num_regs, dest); | ||
133 | return ret; | ||
134 | } | ||
135 | |||
136 | static inline int is_reg_locked(struct wm8350 *wm8350, u8 reg) | ||
137 | { | ||
138 | if (reg == WM8350_SECURITY || | ||
139 | wm8350->reg_cache[WM8350_SECURITY] == WM8350_UNLOCK_KEY) | ||
140 | return 0; | ||
141 | |||
142 | if ((reg == WM8350_GPIO_CONFIGURATION_I_O) || | ||
143 | (reg >= WM8350_GPIO_FUNCTION_SELECT_1 && | ||
144 | reg <= WM8350_GPIO_FUNCTION_SELECT_4) || | ||
145 | (reg >= WM8350_BATTERY_CHARGER_CONTROL_1 && | ||
146 | reg <= WM8350_BATTERY_CHARGER_CONTROL_3)) | ||
147 | return 1; | ||
148 | return 0; | ||
149 | } | ||
150 | |||
151 | static int wm8350_write(struct wm8350 *wm8350, u8 reg, int num_regs, u16 *src) | ||
152 | { | ||
153 | int i; | ||
154 | int end = reg + num_regs; | ||
155 | int bytes = num_regs * 2; | ||
156 | |||
157 | if (wm8350->write_dev == NULL) | ||
158 | return -ENODEV; | ||
159 | |||
160 | if ((reg + num_regs - 1) > WM8350_MAX_REGISTER) { | ||
161 | dev_err(wm8350->dev, "invalid reg %x\n", | ||
162 | reg + num_regs - 1); | ||
163 | return -EINVAL; | ||
164 | } | ||
165 | |||
166 | /* it's generally not a good idea to write to RO or locked registers */ | ||
167 | for (i = reg; i < end; i++) { | ||
168 | if (!wm8350_reg_io_map[i].writable) { | ||
169 | dev_err(wm8350->dev, | ||
170 | "attempted write to read only reg R%d\n", i); | ||
171 | return -EINVAL; | ||
172 | } | ||
173 | |||
174 | if (is_reg_locked(wm8350, i)) { | ||
175 | dev_err(wm8350->dev, | ||
176 | "attempted write to locked reg R%d\n", i); | ||
177 | return -EINVAL; | ||
178 | } | ||
179 | |||
180 | src[i - reg] &= wm8350_reg_io_map[i].writable; | ||
181 | |||
182 | wm8350->reg_cache[i] = | ||
183 | (wm8350->reg_cache[i] & ~wm8350_reg_io_map[i].writable) | ||
184 | | src[i - reg]; | ||
185 | |||
186 | src[i - reg] = cpu_to_be16(src[i - reg]); | ||
187 | } | ||
188 | |||
189 | /* Actually write it out */ | ||
190 | return wm8350->write_dev(wm8350, reg, bytes, (char *)src); | ||
191 | } | ||
192 | |||
193 | /* | ||
194 | * Safe read, modify, write methods | ||
195 | */ | ||
196 | int wm8350_clear_bits(struct wm8350 *wm8350, u16 reg, u16 mask) | ||
197 | { | ||
198 | u16 data; | ||
199 | int err; | ||
200 | |||
201 | mutex_lock(&io_mutex); | ||
202 | err = wm8350_read(wm8350, reg, 1, &data); | ||
203 | if (err) { | ||
204 | dev_err(wm8350->dev, "read from reg R%d failed\n", reg); | ||
205 | goto out; | ||
206 | } | ||
207 | |||
208 | data &= ~mask; | ||
209 | err = wm8350_write(wm8350, reg, 1, &data); | ||
210 | if (err) | ||
211 | dev_err(wm8350->dev, "write to reg R%d failed\n", reg); | ||
212 | out: | ||
213 | mutex_unlock(&io_mutex); | ||
214 | return err; | ||
215 | } | ||
216 | EXPORT_SYMBOL_GPL(wm8350_clear_bits); | ||
217 | |||
218 | int wm8350_set_bits(struct wm8350 *wm8350, u16 reg, u16 mask) | ||
219 | { | ||
220 | u16 data; | ||
221 | int err; | ||
222 | |||
223 | mutex_lock(&io_mutex); | ||
224 | err = wm8350_read(wm8350, reg, 1, &data); | ||
225 | if (err) { | ||
226 | dev_err(wm8350->dev, "read from reg R%d failed\n", reg); | ||
227 | goto out; | ||
228 | } | ||
229 | |||
230 | data |= mask; | ||
231 | err = wm8350_write(wm8350, reg, 1, &data); | ||
232 | if (err) | ||
233 | dev_err(wm8350->dev, "write to reg R%d failed\n", reg); | ||
234 | out: | ||
235 | mutex_unlock(&io_mutex); | ||
236 | return err; | ||
237 | } | ||
238 | EXPORT_SYMBOL_GPL(wm8350_set_bits); | ||
239 | |||
240 | u16 wm8350_reg_read(struct wm8350 *wm8350, int reg) | ||
241 | { | ||
242 | u16 data; | ||
243 | int err; | ||
244 | |||
245 | mutex_lock(&io_mutex); | ||
246 | err = wm8350_read(wm8350, reg, 1, &data); | ||
247 | if (err) | ||
248 | dev_err(wm8350->dev, "read from reg R%d failed\n", reg); | ||
249 | |||
250 | mutex_unlock(&io_mutex); | ||
251 | return data; | ||
252 | } | ||
253 | EXPORT_SYMBOL_GPL(wm8350_reg_read); | ||
254 | |||
255 | int wm8350_reg_write(struct wm8350 *wm8350, int reg, u16 val) | ||
256 | { | ||
257 | int ret; | ||
258 | u16 data = val; | ||
259 | |||
260 | mutex_lock(&io_mutex); | ||
261 | ret = wm8350_write(wm8350, reg, 1, &data); | ||
262 | if (ret) | ||
263 | dev_err(wm8350->dev, "write to reg R%d failed\n", reg); | ||
264 | mutex_unlock(&io_mutex); | ||
265 | return ret; | ||
266 | } | ||
267 | EXPORT_SYMBOL_GPL(wm8350_reg_write); | ||
268 | |||
269 | int wm8350_block_read(struct wm8350 *wm8350, int start_reg, int regs, | ||
270 | u16 *dest) | ||
271 | { | ||
272 | int err = 0; | ||
273 | |||
274 | mutex_lock(&io_mutex); | ||
275 | err = wm8350_read(wm8350, start_reg, regs, dest); | ||
276 | if (err) | ||
277 | dev_err(wm8350->dev, "block read starting from R%d failed\n", | ||
278 | start_reg); | ||
279 | mutex_unlock(&io_mutex); | ||
280 | return err; | ||
281 | } | ||
282 | EXPORT_SYMBOL_GPL(wm8350_block_read); | ||
283 | |||
284 | int wm8350_block_write(struct wm8350 *wm8350, int start_reg, int regs, | ||
285 | u16 *src) | ||
286 | { | ||
287 | int ret = 0; | ||
288 | |||
289 | mutex_lock(&io_mutex); | ||
290 | ret = wm8350_write(wm8350, start_reg, regs, src); | ||
291 | if (ret) | ||
292 | dev_err(wm8350->dev, "block write starting at R%d failed\n", | ||
293 | start_reg); | ||
294 | mutex_unlock(&io_mutex); | ||
295 | return ret; | ||
296 | } | ||
297 | EXPORT_SYMBOL_GPL(wm8350_block_write); | ||
298 | |||
299 | int wm8350_reg_lock(struct wm8350 *wm8350) | ||
300 | { | ||
301 | u16 key = WM8350_LOCK_KEY; | ||
302 | int ret; | ||
303 | |||
304 | ldbg(__func__); | ||
305 | mutex_lock(&io_mutex); | ||
306 | ret = wm8350_write(wm8350, WM8350_SECURITY, 1, &key); | ||
307 | if (ret) | ||
308 | dev_err(wm8350->dev, "lock failed\n"); | ||
309 | mutex_unlock(&io_mutex); | ||
310 | return ret; | ||
311 | } | ||
312 | EXPORT_SYMBOL_GPL(wm8350_reg_lock); | ||
313 | |||
314 | int wm8350_reg_unlock(struct wm8350 *wm8350) | ||
315 | { | ||
316 | u16 key = WM8350_UNLOCK_KEY; | ||
317 | int ret; | ||
318 | |||
319 | ldbg(__func__); | ||
320 | mutex_lock(&io_mutex); | ||
321 | ret = wm8350_write(wm8350, WM8350_SECURITY, 1, &key); | ||
322 | if (ret) | ||
323 | dev_err(wm8350->dev, "unlock failed\n"); | ||
324 | mutex_unlock(&io_mutex); | ||
325 | return ret; | ||
326 | } | ||
327 | EXPORT_SYMBOL_GPL(wm8350_reg_unlock); | ||
328 | |||
329 | static void wm8350_irq_call_handler(struct wm8350 *wm8350, int irq) | ||
330 | { | ||
331 | mutex_lock(&wm8350->irq_mutex); | ||
332 | |||
333 | if (wm8350->irq[irq].handler) | ||
334 | wm8350->irq[irq].handler(wm8350, irq, wm8350->irq[irq].data); | ||
335 | else { | ||
336 | dev_err(wm8350->dev, "irq %d nobody cared. now masked.\n", | ||
337 | irq); | ||
338 | wm8350_mask_irq(wm8350, irq); | ||
339 | } | ||
340 | |||
341 | mutex_unlock(&wm8350->irq_mutex); | ||
342 | } | ||
343 | |||
344 | /* | ||
345 | * wm8350_irq_worker actually handles the interrupts. Since all | ||
346 | * interrupts are clear on read the IRQ line will be reasserted and | ||
347 | * the physical IRQ will be handled again if another interrupt is | ||
348 | * asserted while we run - in the normal course of events this is a | ||
349 | * rare occurrence so we save I2C/SPI reads. | ||
350 | */ | ||
351 | static void wm8350_irq_worker(struct work_struct *work) | ||
352 | { | ||
353 | struct wm8350 *wm8350 = container_of(work, struct wm8350, irq_work); | ||
354 | u16 level_one, status1, status2, comp; | ||
355 | |||
356 | /* TODO: Use block reads to improve performance? */ | ||
357 | level_one = wm8350_reg_read(wm8350, WM8350_SYSTEM_INTERRUPTS) | ||
358 | & ~wm8350_reg_read(wm8350, WM8350_SYSTEM_INTERRUPTS_MASK); | ||
359 | status1 = wm8350_reg_read(wm8350, WM8350_INT_STATUS_1) | ||
360 | & ~wm8350_reg_read(wm8350, WM8350_INT_STATUS_1_MASK); | ||
361 | status2 = wm8350_reg_read(wm8350, WM8350_INT_STATUS_2) | ||
362 | & ~wm8350_reg_read(wm8350, WM8350_INT_STATUS_2_MASK); | ||
363 | comp = wm8350_reg_read(wm8350, WM8350_COMPARATOR_INT_STATUS) | ||
364 | & ~wm8350_reg_read(wm8350, WM8350_COMPARATOR_INT_STATUS_MASK); | ||
365 | |||
366 | /* over current */ | ||
367 | if (level_one & WM8350_OC_INT) { | ||
368 | u16 oc; | ||
369 | |||
370 | oc = wm8350_reg_read(wm8350, WM8350_OVER_CURRENT_INT_STATUS); | ||
371 | oc &= ~wm8350_reg_read(wm8350, | ||
372 | WM8350_OVER_CURRENT_INT_STATUS_MASK); | ||
373 | |||
374 | if (oc & WM8350_OC_LS_EINT) /* limit switch */ | ||
375 | wm8350_irq_call_handler(wm8350, WM8350_IRQ_OC_LS); | ||
376 | } | ||
377 | |||
378 | /* under voltage */ | ||
379 | if (level_one & WM8350_UV_INT) { | ||
380 | u16 uv; | ||
381 | |||
382 | uv = wm8350_reg_read(wm8350, WM8350_UNDER_VOLTAGE_INT_STATUS); | ||
383 | uv &= ~wm8350_reg_read(wm8350, | ||
384 | WM8350_UNDER_VOLTAGE_INT_STATUS_MASK); | ||
385 | |||
386 | if (uv & WM8350_UV_DC1_EINT) | ||
387 | wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_DC1); | ||
388 | if (uv & WM8350_UV_DC2_EINT) | ||
389 | wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_DC2); | ||
390 | if (uv & WM8350_UV_DC3_EINT) | ||
391 | wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_DC3); | ||
392 | if (uv & WM8350_UV_DC4_EINT) | ||
393 | wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_DC4); | ||
394 | if (uv & WM8350_UV_DC5_EINT) | ||
395 | wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_DC5); | ||
396 | if (uv & WM8350_UV_DC6_EINT) | ||
397 | wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_DC6); | ||
398 | if (uv & WM8350_UV_LDO1_EINT) | ||
399 | wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_LDO1); | ||
400 | if (uv & WM8350_UV_LDO2_EINT) | ||
401 | wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_LDO2); | ||
402 | if (uv & WM8350_UV_LDO3_EINT) | ||
403 | wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_LDO3); | ||
404 | if (uv & WM8350_UV_LDO4_EINT) | ||
405 | wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_LDO4); | ||
406 | } | ||
407 | |||
408 | /* charger, RTC */ | ||
409 | if (status1) { | ||
410 | if (status1 & WM8350_CHG_BAT_HOT_EINT) | ||
411 | wm8350_irq_call_handler(wm8350, | ||
412 | WM8350_IRQ_CHG_BAT_HOT); | ||
413 | if (status1 & WM8350_CHG_BAT_COLD_EINT) | ||
414 | wm8350_irq_call_handler(wm8350, | ||
415 | WM8350_IRQ_CHG_BAT_COLD); | ||
416 | if (status1 & WM8350_CHG_BAT_FAIL_EINT) | ||
417 | wm8350_irq_call_handler(wm8350, | ||
418 | WM8350_IRQ_CHG_BAT_FAIL); | ||
419 | if (status1 & WM8350_CHG_TO_EINT) | ||
420 | wm8350_irq_call_handler(wm8350, WM8350_IRQ_CHG_TO); | ||
421 | if (status1 & WM8350_CHG_END_EINT) | ||
422 | wm8350_irq_call_handler(wm8350, WM8350_IRQ_CHG_END); | ||
423 | if (status1 & WM8350_CHG_START_EINT) | ||
424 | wm8350_irq_call_handler(wm8350, WM8350_IRQ_CHG_START); | ||
425 | if (status1 & WM8350_CHG_FAST_RDY_EINT) | ||
426 | wm8350_irq_call_handler(wm8350, | ||
427 | WM8350_IRQ_CHG_FAST_RDY); | ||
428 | if (status1 & WM8350_CHG_VBATT_LT_3P9_EINT) | ||
429 | wm8350_irq_call_handler(wm8350, | ||
430 | WM8350_IRQ_CHG_VBATT_LT_3P9); | ||
431 | if (status1 & WM8350_CHG_VBATT_LT_3P1_EINT) | ||
432 | wm8350_irq_call_handler(wm8350, | ||
433 | WM8350_IRQ_CHG_VBATT_LT_3P1); | ||
434 | if (status1 & WM8350_CHG_VBATT_LT_2P85_EINT) | ||
435 | wm8350_irq_call_handler(wm8350, | ||
436 | WM8350_IRQ_CHG_VBATT_LT_2P85); | ||
437 | if (status1 & WM8350_RTC_ALM_EINT) | ||
438 | wm8350_irq_call_handler(wm8350, WM8350_IRQ_RTC_ALM); | ||
439 | if (status1 & WM8350_RTC_SEC_EINT) | ||
440 | wm8350_irq_call_handler(wm8350, WM8350_IRQ_RTC_SEC); | ||
441 | if (status1 & WM8350_RTC_PER_EINT) | ||
442 | wm8350_irq_call_handler(wm8350, WM8350_IRQ_RTC_PER); | ||
443 | } | ||
444 | |||
445 | /* current sink, system, aux adc */ | ||
446 | if (status2) { | ||
447 | if (status2 & WM8350_CS1_EINT) | ||
448 | wm8350_irq_call_handler(wm8350, WM8350_IRQ_CS1); | ||
449 | if (status2 & WM8350_CS2_EINT) | ||
450 | wm8350_irq_call_handler(wm8350, WM8350_IRQ_CS2); | ||
451 | |||
452 | if (status2 & WM8350_SYS_HYST_COMP_FAIL_EINT) | ||
453 | wm8350_irq_call_handler(wm8350, | ||
454 | WM8350_IRQ_SYS_HYST_COMP_FAIL); | ||
455 | if (status2 & WM8350_SYS_CHIP_GT115_EINT) | ||
456 | wm8350_irq_call_handler(wm8350, | ||
457 | WM8350_IRQ_SYS_CHIP_GT115); | ||
458 | if (status2 & WM8350_SYS_CHIP_GT140_EINT) | ||
459 | wm8350_irq_call_handler(wm8350, | ||
460 | WM8350_IRQ_SYS_CHIP_GT140); | ||
461 | if (status2 & WM8350_SYS_WDOG_TO_EINT) | ||
462 | wm8350_irq_call_handler(wm8350, | ||
463 | WM8350_IRQ_SYS_WDOG_TO); | ||
464 | |||
465 | if (status2 & WM8350_AUXADC_DATARDY_EINT) | ||
466 | wm8350_irq_call_handler(wm8350, | ||
467 | WM8350_IRQ_AUXADC_DATARDY); | ||
468 | if (status2 & WM8350_AUXADC_DCOMP4_EINT) | ||
469 | wm8350_irq_call_handler(wm8350, | ||
470 | WM8350_IRQ_AUXADC_DCOMP4); | ||
471 | if (status2 & WM8350_AUXADC_DCOMP3_EINT) | ||
472 | wm8350_irq_call_handler(wm8350, | ||
473 | WM8350_IRQ_AUXADC_DCOMP3); | ||
474 | if (status2 & WM8350_AUXADC_DCOMP2_EINT) | ||
475 | wm8350_irq_call_handler(wm8350, | ||
476 | WM8350_IRQ_AUXADC_DCOMP2); | ||
477 | if (status2 & WM8350_AUXADC_DCOMP1_EINT) | ||
478 | wm8350_irq_call_handler(wm8350, | ||
479 | WM8350_IRQ_AUXADC_DCOMP1); | ||
480 | |||
481 | if (status2 & WM8350_USB_LIMIT_EINT) | ||
482 | wm8350_irq_call_handler(wm8350, WM8350_IRQ_USB_LIMIT); | ||
483 | } | ||
484 | |||
485 | /* wake, codec, ext */ | ||
486 | if (comp) { | ||
487 | if (comp & WM8350_WKUP_OFF_STATE_EINT) | ||
488 | wm8350_irq_call_handler(wm8350, | ||
489 | WM8350_IRQ_WKUP_OFF_STATE); | ||
490 | if (comp & WM8350_WKUP_HIB_STATE_EINT) | ||
491 | wm8350_irq_call_handler(wm8350, | ||
492 | WM8350_IRQ_WKUP_HIB_STATE); | ||
493 | if (comp & WM8350_WKUP_CONV_FAULT_EINT) | ||
494 | wm8350_irq_call_handler(wm8350, | ||
495 | WM8350_IRQ_WKUP_CONV_FAULT); | ||
496 | if (comp & WM8350_WKUP_WDOG_RST_EINT) | ||
497 | wm8350_irq_call_handler(wm8350, | ||
498 | WM8350_IRQ_WKUP_WDOG_RST); | ||
499 | if (comp & WM8350_WKUP_GP_PWR_ON_EINT) | ||
500 | wm8350_irq_call_handler(wm8350, | ||
501 | WM8350_IRQ_WKUP_GP_PWR_ON); | ||
502 | if (comp & WM8350_WKUP_ONKEY_EINT) | ||
503 | wm8350_irq_call_handler(wm8350, WM8350_IRQ_WKUP_ONKEY); | ||
504 | if (comp & WM8350_WKUP_GP_WAKEUP_EINT) | ||
505 | wm8350_irq_call_handler(wm8350, | ||
506 | WM8350_IRQ_WKUP_GP_WAKEUP); | ||
507 | |||
508 | if (comp & WM8350_CODEC_JCK_DET_L_EINT) | ||
509 | wm8350_irq_call_handler(wm8350, | ||
510 | WM8350_IRQ_CODEC_JCK_DET_L); | ||
511 | if (comp & WM8350_CODEC_JCK_DET_R_EINT) | ||
512 | wm8350_irq_call_handler(wm8350, | ||
513 | WM8350_IRQ_CODEC_JCK_DET_R); | ||
514 | if (comp & WM8350_CODEC_MICSCD_EINT) | ||
515 | wm8350_irq_call_handler(wm8350, | ||
516 | WM8350_IRQ_CODEC_MICSCD); | ||
517 | if (comp & WM8350_CODEC_MICD_EINT) | ||
518 | wm8350_irq_call_handler(wm8350, WM8350_IRQ_CODEC_MICD); | ||
519 | |||
520 | if (comp & WM8350_EXT_USB_FB_EINT) | ||
521 | wm8350_irq_call_handler(wm8350, WM8350_IRQ_EXT_USB_FB); | ||
522 | if (comp & WM8350_EXT_WALL_FB_EINT) | ||
523 | wm8350_irq_call_handler(wm8350, | ||
524 | WM8350_IRQ_EXT_WALL_FB); | ||
525 | if (comp & WM8350_EXT_BAT_FB_EINT) | ||
526 | wm8350_irq_call_handler(wm8350, WM8350_IRQ_EXT_BAT_FB); | ||
527 | } | ||
528 | |||
529 | if (level_one & WM8350_GP_INT) { | ||
530 | int i; | ||
531 | u16 gpio; | ||
532 | |||
533 | gpio = wm8350_reg_read(wm8350, WM8350_GPIO_INT_STATUS); | ||
534 | gpio &= ~wm8350_reg_read(wm8350, | ||
535 | WM8350_GPIO_INT_STATUS_MASK); | ||
536 | |||
537 | for (i = 0; i < 12; i++) { | ||
538 | if (gpio & (1 << i)) | ||
539 | wm8350_irq_call_handler(wm8350, | ||
540 | WM8350_IRQ_GPIO(i)); | ||
541 | } | ||
542 | } | ||
543 | |||
544 | enable_irq(wm8350->chip_irq); | ||
545 | } | ||
546 | |||
547 | static irqreturn_t wm8350_irq(int irq, void *data) | ||
548 | { | ||
549 | struct wm8350 *wm8350 = data; | ||
550 | |||
551 | disable_irq_nosync(irq); | ||
552 | schedule_work(&wm8350->irq_work); | ||
553 | |||
554 | return IRQ_HANDLED; | ||
555 | } | ||
556 | |||
557 | int wm8350_register_irq(struct wm8350 *wm8350, int irq, | ||
558 | void (*handler) (struct wm8350 *, int, void *), | ||
559 | void *data) | ||
560 | { | ||
561 | if (irq < 0 || irq > WM8350_NUM_IRQ || !handler) | ||
562 | return -EINVAL; | ||
563 | |||
564 | if (wm8350->irq[irq].handler) | ||
565 | return -EBUSY; | ||
566 | |||
567 | mutex_lock(&wm8350->irq_mutex); | ||
568 | wm8350->irq[irq].handler = handler; | ||
569 | wm8350->irq[irq].data = data; | ||
570 | mutex_unlock(&wm8350->irq_mutex); | ||
571 | |||
572 | return 0; | ||
573 | } | ||
574 | EXPORT_SYMBOL_GPL(wm8350_register_irq); | ||
575 | |||
576 | int wm8350_free_irq(struct wm8350 *wm8350, int irq) | ||
577 | { | ||
578 | if (irq < 0 || irq > WM8350_NUM_IRQ) | ||
579 | return -EINVAL; | ||
580 | |||
581 | mutex_lock(&wm8350->irq_mutex); | ||
582 | wm8350->irq[irq].handler = NULL; | ||
583 | mutex_unlock(&wm8350->irq_mutex); | ||
584 | return 0; | ||
585 | } | ||
586 | EXPORT_SYMBOL_GPL(wm8350_free_irq); | ||
587 | |||
588 | int wm8350_mask_irq(struct wm8350 *wm8350, int irq) | ||
589 | { | ||
590 | switch (irq) { | ||
591 | case WM8350_IRQ_CHG_BAT_HOT: | ||
592 | return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK, | ||
593 | WM8350_IM_CHG_BAT_HOT_EINT); | ||
594 | case WM8350_IRQ_CHG_BAT_COLD: | ||
595 | return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK, | ||
596 | WM8350_IM_CHG_BAT_COLD_EINT); | ||
597 | case WM8350_IRQ_CHG_BAT_FAIL: | ||
598 | return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK, | ||
599 | WM8350_IM_CHG_BAT_FAIL_EINT); | ||
600 | case WM8350_IRQ_CHG_TO: | ||
601 | return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK, | ||
602 | WM8350_IM_CHG_TO_EINT); | ||
603 | case WM8350_IRQ_CHG_END: | ||
604 | return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK, | ||
605 | WM8350_IM_CHG_END_EINT); | ||
606 | case WM8350_IRQ_CHG_START: | ||
607 | return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK, | ||
608 | WM8350_IM_CHG_START_EINT); | ||
609 | case WM8350_IRQ_CHG_FAST_RDY: | ||
610 | return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK, | ||
611 | WM8350_IM_CHG_FAST_RDY_EINT); | ||
612 | case WM8350_IRQ_RTC_PER: | ||
613 | return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK, | ||
614 | WM8350_IM_RTC_PER_EINT); | ||
615 | case WM8350_IRQ_RTC_SEC: | ||
616 | return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK, | ||
617 | WM8350_IM_RTC_SEC_EINT); | ||
618 | case WM8350_IRQ_RTC_ALM: | ||
619 | return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK, | ||
620 | WM8350_IM_RTC_ALM_EINT); | ||
621 | case WM8350_IRQ_CHG_VBATT_LT_3P9: | ||
622 | return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK, | ||
623 | WM8350_IM_CHG_VBATT_LT_3P9_EINT); | ||
624 | case WM8350_IRQ_CHG_VBATT_LT_3P1: | ||
625 | return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK, | ||
626 | WM8350_IM_CHG_VBATT_LT_3P1_EINT); | ||
627 | case WM8350_IRQ_CHG_VBATT_LT_2P85: | ||
628 | return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK, | ||
629 | WM8350_IM_CHG_VBATT_LT_2P85_EINT); | ||
630 | case WM8350_IRQ_CS1: | ||
631 | return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK, | ||
632 | WM8350_IM_CS1_EINT); | ||
633 | case WM8350_IRQ_CS2: | ||
634 | return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK, | ||
635 | WM8350_IM_CS2_EINT); | ||
636 | case WM8350_IRQ_USB_LIMIT: | ||
637 | return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK, | ||
638 | WM8350_IM_USB_LIMIT_EINT); | ||
639 | case WM8350_IRQ_AUXADC_DATARDY: | ||
640 | return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK, | ||
641 | WM8350_IM_AUXADC_DATARDY_EINT); | ||
642 | case WM8350_IRQ_AUXADC_DCOMP4: | ||
643 | return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK, | ||
644 | WM8350_IM_AUXADC_DCOMP4_EINT); | ||
645 | case WM8350_IRQ_AUXADC_DCOMP3: | ||
646 | return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK, | ||
647 | WM8350_IM_AUXADC_DCOMP3_EINT); | ||
648 | case WM8350_IRQ_AUXADC_DCOMP2: | ||
649 | return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK, | ||
650 | WM8350_IM_AUXADC_DCOMP2_EINT); | ||
651 | case WM8350_IRQ_AUXADC_DCOMP1: | ||
652 | return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK, | ||
653 | WM8350_IM_AUXADC_DCOMP1_EINT); | ||
654 | case WM8350_IRQ_SYS_HYST_COMP_FAIL: | ||
655 | return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK, | ||
656 | WM8350_IM_SYS_HYST_COMP_FAIL_EINT); | ||
657 | case WM8350_IRQ_SYS_CHIP_GT115: | ||
658 | return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK, | ||
659 | WM8350_IM_SYS_CHIP_GT115_EINT); | ||
660 | case WM8350_IRQ_SYS_CHIP_GT140: | ||
661 | return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK, | ||
662 | WM8350_IM_SYS_CHIP_GT140_EINT); | ||
663 | case WM8350_IRQ_SYS_WDOG_TO: | ||
664 | return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK, | ||
665 | WM8350_IM_SYS_WDOG_TO_EINT); | ||
666 | case WM8350_IRQ_UV_LDO4: | ||
667 | return wm8350_set_bits(wm8350, | ||
668 | WM8350_UNDER_VOLTAGE_INT_STATUS_MASK, | ||
669 | WM8350_IM_UV_LDO4_EINT); | ||
670 | case WM8350_IRQ_UV_LDO3: | ||
671 | return wm8350_set_bits(wm8350, | ||
672 | WM8350_UNDER_VOLTAGE_INT_STATUS_MASK, | ||
673 | WM8350_IM_UV_LDO3_EINT); | ||
674 | case WM8350_IRQ_UV_LDO2: | ||
675 | return wm8350_set_bits(wm8350, | ||
676 | WM8350_UNDER_VOLTAGE_INT_STATUS_MASK, | ||
677 | WM8350_IM_UV_LDO2_EINT); | ||
678 | case WM8350_IRQ_UV_LDO1: | ||
679 | return wm8350_set_bits(wm8350, | ||
680 | WM8350_UNDER_VOLTAGE_INT_STATUS_MASK, | ||
681 | WM8350_IM_UV_LDO1_EINT); | ||
682 | case WM8350_IRQ_UV_DC6: | ||
683 | return wm8350_set_bits(wm8350, | ||
684 | WM8350_UNDER_VOLTAGE_INT_STATUS_MASK, | ||
685 | WM8350_IM_UV_DC6_EINT); | ||
686 | case WM8350_IRQ_UV_DC5: | ||
687 | return wm8350_set_bits(wm8350, | ||
688 | WM8350_UNDER_VOLTAGE_INT_STATUS_MASK, | ||
689 | WM8350_IM_UV_DC5_EINT); | ||
690 | case WM8350_IRQ_UV_DC4: | ||
691 | return wm8350_set_bits(wm8350, | ||
692 | WM8350_UNDER_VOLTAGE_INT_STATUS_MASK, | ||
693 | WM8350_IM_UV_DC4_EINT); | ||
694 | case WM8350_IRQ_UV_DC3: | ||
695 | return wm8350_set_bits(wm8350, | ||
696 | WM8350_UNDER_VOLTAGE_INT_STATUS_MASK, | ||
697 | WM8350_IM_UV_DC3_EINT); | ||
698 | case WM8350_IRQ_UV_DC2: | ||
699 | return wm8350_set_bits(wm8350, | ||
700 | WM8350_UNDER_VOLTAGE_INT_STATUS_MASK, | ||
701 | WM8350_IM_UV_DC2_EINT); | ||
702 | case WM8350_IRQ_UV_DC1: | ||
703 | return wm8350_set_bits(wm8350, | ||
704 | WM8350_UNDER_VOLTAGE_INT_STATUS_MASK, | ||
705 | WM8350_IM_UV_DC1_EINT); | ||
706 | case WM8350_IRQ_OC_LS: | ||
707 | return wm8350_set_bits(wm8350, | ||
708 | WM8350_OVER_CURRENT_INT_STATUS_MASK, | ||
709 | WM8350_IM_OC_LS_EINT); | ||
710 | case WM8350_IRQ_EXT_USB_FB: | ||
711 | return wm8350_set_bits(wm8350, | ||
712 | WM8350_COMPARATOR_INT_STATUS_MASK, | ||
713 | WM8350_IM_EXT_USB_FB_EINT); | ||
714 | case WM8350_IRQ_EXT_WALL_FB: | ||
715 | return wm8350_set_bits(wm8350, | ||
716 | WM8350_COMPARATOR_INT_STATUS_MASK, | ||
717 | WM8350_IM_EXT_WALL_FB_EINT); | ||
718 | case WM8350_IRQ_EXT_BAT_FB: | ||
719 | return wm8350_set_bits(wm8350, | ||
720 | WM8350_COMPARATOR_INT_STATUS_MASK, | ||
721 | WM8350_IM_EXT_BAT_FB_EINT); | ||
722 | case WM8350_IRQ_CODEC_JCK_DET_L: | ||
723 | return wm8350_set_bits(wm8350, | ||
724 | WM8350_COMPARATOR_INT_STATUS_MASK, | ||
725 | WM8350_IM_CODEC_JCK_DET_L_EINT); | ||
726 | case WM8350_IRQ_CODEC_JCK_DET_R: | ||
727 | return wm8350_set_bits(wm8350, | ||
728 | WM8350_COMPARATOR_INT_STATUS_MASK, | ||
729 | WM8350_IM_CODEC_JCK_DET_R_EINT); | ||
730 | case WM8350_IRQ_CODEC_MICSCD: | ||
731 | return wm8350_set_bits(wm8350, | ||
732 | WM8350_COMPARATOR_INT_STATUS_MASK, | ||
733 | WM8350_IM_CODEC_MICSCD_EINT); | ||
734 | case WM8350_IRQ_CODEC_MICD: | ||
735 | return wm8350_set_bits(wm8350, | ||
736 | WM8350_COMPARATOR_INT_STATUS_MASK, | ||
737 | WM8350_IM_CODEC_MICD_EINT); | ||
738 | case WM8350_IRQ_WKUP_OFF_STATE: | ||
739 | return wm8350_set_bits(wm8350, | ||
740 | WM8350_COMPARATOR_INT_STATUS_MASK, | ||
741 | WM8350_IM_WKUP_OFF_STATE_EINT); | ||
742 | case WM8350_IRQ_WKUP_HIB_STATE: | ||
743 | return wm8350_set_bits(wm8350, | ||
744 | WM8350_COMPARATOR_INT_STATUS_MASK, | ||
745 | WM8350_IM_WKUP_HIB_STATE_EINT); | ||
746 | case WM8350_IRQ_WKUP_CONV_FAULT: | ||
747 | return wm8350_set_bits(wm8350, | ||
748 | WM8350_COMPARATOR_INT_STATUS_MASK, | ||
749 | WM8350_IM_WKUP_CONV_FAULT_EINT); | ||
750 | case WM8350_IRQ_WKUP_WDOG_RST: | ||
751 | return wm8350_set_bits(wm8350, | ||
752 | WM8350_COMPARATOR_INT_STATUS_MASK, | ||
753 | WM8350_IM_WKUP_OFF_STATE_EINT); | ||
754 | case WM8350_IRQ_WKUP_GP_PWR_ON: | ||
755 | return wm8350_set_bits(wm8350, | ||
756 | WM8350_COMPARATOR_INT_STATUS_MASK, | ||
757 | WM8350_IM_WKUP_GP_PWR_ON_EINT); | ||
758 | case WM8350_IRQ_WKUP_ONKEY: | ||
759 | return wm8350_set_bits(wm8350, | ||
760 | WM8350_COMPARATOR_INT_STATUS_MASK, | ||
761 | WM8350_IM_WKUP_ONKEY_EINT); | ||
762 | case WM8350_IRQ_WKUP_GP_WAKEUP: | ||
763 | return wm8350_set_bits(wm8350, | ||
764 | WM8350_COMPARATOR_INT_STATUS_MASK, | ||
765 | WM8350_IM_WKUP_GP_WAKEUP_EINT); | ||
766 | case WM8350_IRQ_GPIO(0): | ||
767 | return wm8350_set_bits(wm8350, | ||
768 | WM8350_GPIO_INT_STATUS_MASK, | ||
769 | WM8350_IM_GP0_EINT); | ||
770 | case WM8350_IRQ_GPIO(1): | ||
771 | return wm8350_set_bits(wm8350, | ||
772 | WM8350_GPIO_INT_STATUS_MASK, | ||
773 | WM8350_IM_GP1_EINT); | ||
774 | case WM8350_IRQ_GPIO(2): | ||
775 | return wm8350_set_bits(wm8350, | ||
776 | WM8350_GPIO_INT_STATUS_MASK, | ||
777 | WM8350_IM_GP2_EINT); | ||
778 | case WM8350_IRQ_GPIO(3): | ||
779 | return wm8350_set_bits(wm8350, | ||
780 | WM8350_GPIO_INT_STATUS_MASK, | ||
781 | WM8350_IM_GP3_EINT); | ||
782 | case WM8350_IRQ_GPIO(4): | ||
783 | return wm8350_set_bits(wm8350, | ||
784 | WM8350_GPIO_INT_STATUS_MASK, | ||
785 | WM8350_IM_GP4_EINT); | ||
786 | case WM8350_IRQ_GPIO(5): | ||
787 | return wm8350_set_bits(wm8350, | ||
788 | WM8350_GPIO_INT_STATUS_MASK, | ||
789 | WM8350_IM_GP5_EINT); | ||
790 | case WM8350_IRQ_GPIO(6): | ||
791 | return wm8350_set_bits(wm8350, | ||
792 | WM8350_GPIO_INT_STATUS_MASK, | ||
793 | WM8350_IM_GP6_EINT); | ||
794 | case WM8350_IRQ_GPIO(7): | ||
795 | return wm8350_set_bits(wm8350, | ||
796 | WM8350_GPIO_INT_STATUS_MASK, | ||
797 | WM8350_IM_GP7_EINT); | ||
798 | case WM8350_IRQ_GPIO(8): | ||
799 | return wm8350_set_bits(wm8350, | ||
800 | WM8350_GPIO_INT_STATUS_MASK, | ||
801 | WM8350_IM_GP8_EINT); | ||
802 | case WM8350_IRQ_GPIO(9): | ||
803 | return wm8350_set_bits(wm8350, | ||
804 | WM8350_GPIO_INT_STATUS_MASK, | ||
805 | WM8350_IM_GP9_EINT); | ||
806 | case WM8350_IRQ_GPIO(10): | ||
807 | return wm8350_set_bits(wm8350, | ||
808 | WM8350_GPIO_INT_STATUS_MASK, | ||
809 | WM8350_IM_GP10_EINT); | ||
810 | case WM8350_IRQ_GPIO(11): | ||
811 | return wm8350_set_bits(wm8350, | ||
812 | WM8350_GPIO_INT_STATUS_MASK, | ||
813 | WM8350_IM_GP11_EINT); | ||
814 | case WM8350_IRQ_GPIO(12): | ||
815 | return wm8350_set_bits(wm8350, | ||
816 | WM8350_GPIO_INT_STATUS_MASK, | ||
817 | WM8350_IM_GP12_EINT); | ||
818 | default: | ||
819 | dev_warn(wm8350->dev, "Attempting to mask unknown IRQ %d\n", | ||
820 | irq); | ||
821 | return -EINVAL; | ||
822 | } | ||
823 | return 0; | ||
824 | } | ||
825 | EXPORT_SYMBOL_GPL(wm8350_mask_irq); | ||
826 | |||
827 | int wm8350_unmask_irq(struct wm8350 *wm8350, int irq) | ||
828 | { | ||
829 | switch (irq) { | ||
830 | case WM8350_IRQ_CHG_BAT_HOT: | ||
831 | return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK, | ||
832 | WM8350_IM_CHG_BAT_HOT_EINT); | ||
833 | case WM8350_IRQ_CHG_BAT_COLD: | ||
834 | return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK, | ||
835 | WM8350_IM_CHG_BAT_COLD_EINT); | ||
836 | case WM8350_IRQ_CHG_BAT_FAIL: | ||
837 | return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK, | ||
838 | WM8350_IM_CHG_BAT_FAIL_EINT); | ||
839 | case WM8350_IRQ_CHG_TO: | ||
840 | return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK, | ||
841 | WM8350_IM_CHG_TO_EINT); | ||
842 | case WM8350_IRQ_CHG_END: | ||
843 | return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK, | ||
844 | WM8350_IM_CHG_END_EINT); | ||
845 | case WM8350_IRQ_CHG_START: | ||
846 | return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK, | ||
847 | WM8350_IM_CHG_START_EINT); | ||
848 | case WM8350_IRQ_CHG_FAST_RDY: | ||
849 | return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK, | ||
850 | WM8350_IM_CHG_FAST_RDY_EINT); | ||
851 | case WM8350_IRQ_RTC_PER: | ||
852 | return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK, | ||
853 | WM8350_IM_RTC_PER_EINT); | ||
854 | case WM8350_IRQ_RTC_SEC: | ||
855 | return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK, | ||
856 | WM8350_IM_RTC_SEC_EINT); | ||
857 | case WM8350_IRQ_RTC_ALM: | ||
858 | return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK, | ||
859 | WM8350_IM_RTC_ALM_EINT); | ||
860 | case WM8350_IRQ_CHG_VBATT_LT_3P9: | ||
861 | return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK, | ||
862 | WM8350_IM_CHG_VBATT_LT_3P9_EINT); | ||
863 | case WM8350_IRQ_CHG_VBATT_LT_3P1: | ||
864 | return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK, | ||
865 | WM8350_IM_CHG_VBATT_LT_3P1_EINT); | ||
866 | case WM8350_IRQ_CHG_VBATT_LT_2P85: | ||
867 | return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK, | ||
868 | WM8350_IM_CHG_VBATT_LT_2P85_EINT); | ||
869 | case WM8350_IRQ_CS1: | ||
870 | return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK, | ||
871 | WM8350_IM_CS1_EINT); | ||
872 | case WM8350_IRQ_CS2: | ||
873 | return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK, | ||
874 | WM8350_IM_CS2_EINT); | ||
875 | case WM8350_IRQ_USB_LIMIT: | ||
876 | return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK, | ||
877 | WM8350_IM_USB_LIMIT_EINT); | ||
878 | case WM8350_IRQ_AUXADC_DATARDY: | ||
879 | return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK, | ||
880 | WM8350_IM_AUXADC_DATARDY_EINT); | ||
881 | case WM8350_IRQ_AUXADC_DCOMP4: | ||
882 | return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK, | ||
883 | WM8350_IM_AUXADC_DCOMP4_EINT); | ||
884 | case WM8350_IRQ_AUXADC_DCOMP3: | ||
885 | return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK, | ||
886 | WM8350_IM_AUXADC_DCOMP3_EINT); | ||
887 | case WM8350_IRQ_AUXADC_DCOMP2: | ||
888 | return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK, | ||
889 | WM8350_IM_AUXADC_DCOMP2_EINT); | ||
890 | case WM8350_IRQ_AUXADC_DCOMP1: | ||
891 | return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK, | ||
892 | WM8350_IM_AUXADC_DCOMP1_EINT); | ||
893 | case WM8350_IRQ_SYS_HYST_COMP_FAIL: | ||
894 | return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK, | ||
895 | WM8350_IM_SYS_HYST_COMP_FAIL_EINT); | ||
896 | case WM8350_IRQ_SYS_CHIP_GT115: | ||
897 | return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK, | ||
898 | WM8350_IM_SYS_CHIP_GT115_EINT); | ||
899 | case WM8350_IRQ_SYS_CHIP_GT140: | ||
900 | return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK, | ||
901 | WM8350_IM_SYS_CHIP_GT140_EINT); | ||
902 | case WM8350_IRQ_SYS_WDOG_TO: | ||
903 | return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK, | ||
904 | WM8350_IM_SYS_WDOG_TO_EINT); | ||
905 | case WM8350_IRQ_UV_LDO4: | ||
906 | return wm8350_clear_bits(wm8350, | ||
907 | WM8350_UNDER_VOLTAGE_INT_STATUS_MASK, | ||
908 | WM8350_IM_UV_LDO4_EINT); | ||
909 | case WM8350_IRQ_UV_LDO3: | ||
910 | return wm8350_clear_bits(wm8350, | ||
911 | WM8350_UNDER_VOLTAGE_INT_STATUS_MASK, | ||
912 | WM8350_IM_UV_LDO3_EINT); | ||
913 | case WM8350_IRQ_UV_LDO2: | ||
914 | return wm8350_clear_bits(wm8350, | ||
915 | WM8350_UNDER_VOLTAGE_INT_STATUS_MASK, | ||
916 | WM8350_IM_UV_LDO2_EINT); | ||
917 | case WM8350_IRQ_UV_LDO1: | ||
918 | return wm8350_clear_bits(wm8350, | ||
919 | WM8350_UNDER_VOLTAGE_INT_STATUS_MASK, | ||
920 | WM8350_IM_UV_LDO1_EINT); | ||
921 | case WM8350_IRQ_UV_DC6: | ||
922 | return wm8350_clear_bits(wm8350, | ||
923 | WM8350_UNDER_VOLTAGE_INT_STATUS_MASK, | ||
924 | WM8350_IM_UV_DC6_EINT); | ||
925 | case WM8350_IRQ_UV_DC5: | ||
926 | return wm8350_clear_bits(wm8350, | ||
927 | WM8350_UNDER_VOLTAGE_INT_STATUS_MASK, | ||
928 | WM8350_IM_UV_DC5_EINT); | ||
929 | case WM8350_IRQ_UV_DC4: | ||
930 | return wm8350_clear_bits(wm8350, | ||
931 | WM8350_UNDER_VOLTAGE_INT_STATUS_MASK, | ||
932 | WM8350_IM_UV_DC4_EINT); | ||
933 | case WM8350_IRQ_UV_DC3: | ||
934 | return wm8350_clear_bits(wm8350, | ||
935 | WM8350_UNDER_VOLTAGE_INT_STATUS_MASK, | ||
936 | WM8350_IM_UV_DC3_EINT); | ||
937 | case WM8350_IRQ_UV_DC2: | ||
938 | return wm8350_clear_bits(wm8350, | ||
939 | WM8350_UNDER_VOLTAGE_INT_STATUS_MASK, | ||
940 | WM8350_IM_UV_DC2_EINT); | ||
941 | case WM8350_IRQ_UV_DC1: | ||
942 | return wm8350_clear_bits(wm8350, | ||
943 | WM8350_UNDER_VOLTAGE_INT_STATUS_MASK, | ||
944 | WM8350_IM_UV_DC1_EINT); | ||
945 | case WM8350_IRQ_OC_LS: | ||
946 | return wm8350_clear_bits(wm8350, | ||
947 | WM8350_OVER_CURRENT_INT_STATUS_MASK, | ||
948 | WM8350_IM_OC_LS_EINT); | ||
949 | case WM8350_IRQ_EXT_USB_FB: | ||
950 | return wm8350_clear_bits(wm8350, | ||
951 | WM8350_COMPARATOR_INT_STATUS_MASK, | ||
952 | WM8350_IM_EXT_USB_FB_EINT); | ||
953 | case WM8350_IRQ_EXT_WALL_FB: | ||
954 | return wm8350_clear_bits(wm8350, | ||
955 | WM8350_COMPARATOR_INT_STATUS_MASK, | ||
956 | WM8350_IM_EXT_WALL_FB_EINT); | ||
957 | case WM8350_IRQ_EXT_BAT_FB: | ||
958 | return wm8350_clear_bits(wm8350, | ||
959 | WM8350_COMPARATOR_INT_STATUS_MASK, | ||
960 | WM8350_IM_EXT_BAT_FB_EINT); | ||
961 | case WM8350_IRQ_CODEC_JCK_DET_L: | ||
962 | return wm8350_clear_bits(wm8350, | ||
963 | WM8350_COMPARATOR_INT_STATUS_MASK, | ||
964 | WM8350_IM_CODEC_JCK_DET_L_EINT); | ||
965 | case WM8350_IRQ_CODEC_JCK_DET_R: | ||
966 | return wm8350_clear_bits(wm8350, | ||
967 | WM8350_COMPARATOR_INT_STATUS_MASK, | ||
968 | WM8350_IM_CODEC_JCK_DET_R_EINT); | ||
969 | case WM8350_IRQ_CODEC_MICSCD: | ||
970 | return wm8350_clear_bits(wm8350, | ||
971 | WM8350_COMPARATOR_INT_STATUS_MASK, | ||
972 | WM8350_IM_CODEC_MICSCD_EINT); | ||
973 | case WM8350_IRQ_CODEC_MICD: | ||
974 | return wm8350_clear_bits(wm8350, | ||
975 | WM8350_COMPARATOR_INT_STATUS_MASK, | ||
976 | WM8350_IM_CODEC_MICD_EINT); | ||
977 | case WM8350_IRQ_WKUP_OFF_STATE: | ||
978 | return wm8350_clear_bits(wm8350, | ||
979 | WM8350_COMPARATOR_INT_STATUS_MASK, | ||
980 | WM8350_IM_WKUP_OFF_STATE_EINT); | ||
981 | case WM8350_IRQ_WKUP_HIB_STATE: | ||
982 | return wm8350_clear_bits(wm8350, | ||
983 | WM8350_COMPARATOR_INT_STATUS_MASK, | ||
984 | WM8350_IM_WKUP_HIB_STATE_EINT); | ||
985 | case WM8350_IRQ_WKUP_CONV_FAULT: | ||
986 | return wm8350_clear_bits(wm8350, | ||
987 | WM8350_COMPARATOR_INT_STATUS_MASK, | ||
988 | WM8350_IM_WKUP_CONV_FAULT_EINT); | ||
989 | case WM8350_IRQ_WKUP_WDOG_RST: | ||
990 | return wm8350_clear_bits(wm8350, | ||
991 | WM8350_COMPARATOR_INT_STATUS_MASK, | ||
992 | WM8350_IM_WKUP_OFF_STATE_EINT); | ||
993 | case WM8350_IRQ_WKUP_GP_PWR_ON: | ||
994 | return wm8350_clear_bits(wm8350, | ||
995 | WM8350_COMPARATOR_INT_STATUS_MASK, | ||
996 | WM8350_IM_WKUP_GP_PWR_ON_EINT); | ||
997 | case WM8350_IRQ_WKUP_ONKEY: | ||
998 | return wm8350_clear_bits(wm8350, | ||
999 | WM8350_COMPARATOR_INT_STATUS_MASK, | ||
1000 | WM8350_IM_WKUP_ONKEY_EINT); | ||
1001 | case WM8350_IRQ_WKUP_GP_WAKEUP: | ||
1002 | return wm8350_clear_bits(wm8350, | ||
1003 | WM8350_COMPARATOR_INT_STATUS_MASK, | ||
1004 | WM8350_IM_WKUP_GP_WAKEUP_EINT); | ||
1005 | case WM8350_IRQ_GPIO(0): | ||
1006 | return wm8350_clear_bits(wm8350, | ||
1007 | WM8350_GPIO_INT_STATUS_MASK, | ||
1008 | WM8350_IM_GP0_EINT); | ||
1009 | case WM8350_IRQ_GPIO(1): | ||
1010 | return wm8350_clear_bits(wm8350, | ||
1011 | WM8350_GPIO_INT_STATUS_MASK, | ||
1012 | WM8350_IM_GP1_EINT); | ||
1013 | case WM8350_IRQ_GPIO(2): | ||
1014 | return wm8350_clear_bits(wm8350, | ||
1015 | WM8350_GPIO_INT_STATUS_MASK, | ||
1016 | WM8350_IM_GP2_EINT); | ||
1017 | case WM8350_IRQ_GPIO(3): | ||
1018 | return wm8350_clear_bits(wm8350, | ||
1019 | WM8350_GPIO_INT_STATUS_MASK, | ||
1020 | WM8350_IM_GP3_EINT); | ||
1021 | case WM8350_IRQ_GPIO(4): | ||
1022 | return wm8350_clear_bits(wm8350, | ||
1023 | WM8350_GPIO_INT_STATUS_MASK, | ||
1024 | WM8350_IM_GP4_EINT); | ||
1025 | case WM8350_IRQ_GPIO(5): | ||
1026 | return wm8350_clear_bits(wm8350, | ||
1027 | WM8350_GPIO_INT_STATUS_MASK, | ||
1028 | WM8350_IM_GP5_EINT); | ||
1029 | case WM8350_IRQ_GPIO(6): | ||
1030 | return wm8350_clear_bits(wm8350, | ||
1031 | WM8350_GPIO_INT_STATUS_MASK, | ||
1032 | WM8350_IM_GP6_EINT); | ||
1033 | case WM8350_IRQ_GPIO(7): | ||
1034 | return wm8350_clear_bits(wm8350, | ||
1035 | WM8350_GPIO_INT_STATUS_MASK, | ||
1036 | WM8350_IM_GP7_EINT); | ||
1037 | case WM8350_IRQ_GPIO(8): | ||
1038 | return wm8350_clear_bits(wm8350, | ||
1039 | WM8350_GPIO_INT_STATUS_MASK, | ||
1040 | WM8350_IM_GP8_EINT); | ||
1041 | case WM8350_IRQ_GPIO(9): | ||
1042 | return wm8350_clear_bits(wm8350, | ||
1043 | WM8350_GPIO_INT_STATUS_MASK, | ||
1044 | WM8350_IM_GP9_EINT); | ||
1045 | case WM8350_IRQ_GPIO(10): | ||
1046 | return wm8350_clear_bits(wm8350, | ||
1047 | WM8350_GPIO_INT_STATUS_MASK, | ||
1048 | WM8350_IM_GP10_EINT); | ||
1049 | case WM8350_IRQ_GPIO(11): | ||
1050 | return wm8350_clear_bits(wm8350, | ||
1051 | WM8350_GPIO_INT_STATUS_MASK, | ||
1052 | WM8350_IM_GP11_EINT); | ||
1053 | case WM8350_IRQ_GPIO(12): | ||
1054 | return wm8350_clear_bits(wm8350, | ||
1055 | WM8350_GPIO_INT_STATUS_MASK, | ||
1056 | WM8350_IM_GP12_EINT); | ||
1057 | default: | ||
1058 | dev_warn(wm8350->dev, "Attempting to unmask unknown IRQ %d\n", | ||
1059 | irq); | ||
1060 | return -EINVAL; | ||
1061 | } | ||
1062 | return 0; | ||
1063 | } | ||
1064 | EXPORT_SYMBOL_GPL(wm8350_unmask_irq); | ||
1065 | |||
1066 | /* | ||
1067 | * Cache is always host endian. | ||
1068 | */ | ||
1069 | static int wm8350_create_cache(struct wm8350 *wm8350, int mode) | ||
1070 | { | ||
1071 | int i, ret = 0; | ||
1072 | u16 value; | ||
1073 | const u16 *reg_map; | ||
1074 | |||
1075 | switch (mode) { | ||
1076 | #ifdef CONFIG_MFD_WM8350_CONFIG_MODE_0 | ||
1077 | case 0: | ||
1078 | reg_map = wm8350_mode0_defaults; | ||
1079 | break; | ||
1080 | #endif | ||
1081 | #ifdef CONFIG_MFD_WM8350_CONFIG_MODE_1 | ||
1082 | case 1: | ||
1083 | reg_map = wm8350_mode1_defaults; | ||
1084 | break; | ||
1085 | #endif | ||
1086 | #ifdef CONFIG_MFD_WM8350_CONFIG_MODE_2 | ||
1087 | case 2: | ||
1088 | reg_map = wm8350_mode2_defaults; | ||
1089 | break; | ||
1090 | #endif | ||
1091 | #ifdef CONFIG_MFD_WM8350_CONFIG_MODE_3 | ||
1092 | case 3: | ||
1093 | reg_map = wm8350_mode3_defaults; | ||
1094 | break; | ||
1095 | #endif | ||
1096 | default: | ||
1097 | dev_err(wm8350->dev, "Configuration mode %d not supported\n", | ||
1098 | mode); | ||
1099 | return -EINVAL; | ||
1100 | } | ||
1101 | |||
1102 | wm8350->reg_cache = | ||
1103 | kzalloc(sizeof(u16) * (WM8350_MAX_REGISTER + 1), GFP_KERNEL); | ||
1104 | if (wm8350->reg_cache == NULL) | ||
1105 | return -ENOMEM; | ||
1106 | |||
1107 | /* Read the initial cache state back from the device - this is | ||
1108 | * a PMIC so the device many not be in a virgin state and we | ||
1109 | * can't rely on the silicon values. | ||
1110 | */ | ||
1111 | for (i = 0; i < WM8350_MAX_REGISTER; i++) { | ||
1112 | /* audio register range */ | ||
1113 | if (wm8350_reg_io_map[i].readable && | ||
1114 | (i < WM8350_CLOCK_CONTROL_1 || i > WM8350_AIF_TEST)) { | ||
1115 | ret = wm8350->read_dev(wm8350, i, 2, (char *)&value); | ||
1116 | if (ret < 0) { | ||
1117 | dev_err(wm8350->dev, | ||
1118 | "failed to read initial cache value\n"); | ||
1119 | goto out; | ||
1120 | } | ||
1121 | value = be16_to_cpu(value); | ||
1122 | value &= wm8350_reg_io_map[i].readable; | ||
1123 | wm8350->reg_cache[i] = value; | ||
1124 | } else | ||
1125 | wm8350->reg_cache[i] = reg_map[i]; | ||
1126 | } | ||
1127 | |||
1128 | out: | ||
1129 | return ret; | ||
1130 | } | ||
1131 | EXPORT_SYMBOL_GPL(wm8350_create_cache); | ||
1132 | |||
1133 | /* | ||
1134 | * Register a client device. This is non-fatal since there is no need to | ||
1135 | * fail the entire device init due to a single platform device failing. | ||
1136 | */ | ||
1137 | static void wm8350_client_dev_register(struct wm8350 *wm8350, | ||
1138 | const char *name, | ||
1139 | struct platform_device **pdev) | ||
1140 | { | ||
1141 | int ret; | ||
1142 | |||
1143 | *pdev = platform_device_alloc(name, -1); | ||
1144 | if (pdev == NULL) { | ||
1145 | dev_err(wm8350->dev, "Failed to allocate %s\n", name); | ||
1146 | return; | ||
1147 | } | ||
1148 | |||
1149 | (*pdev)->dev.parent = wm8350->dev; | ||
1150 | platform_set_drvdata(*pdev, wm8350); | ||
1151 | ret = platform_device_add(*pdev); | ||
1152 | if (ret != 0) { | ||
1153 | dev_err(wm8350->dev, "Failed to register %s: %d\n", name, ret); | ||
1154 | platform_device_put(*pdev); | ||
1155 | *pdev = NULL; | ||
1156 | } | ||
1157 | } | ||
1158 | |||
1159 | int wm8350_device_init(struct wm8350 *wm8350, int irq, | ||
1160 | struct wm8350_platform_data *pdata) | ||
1161 | { | ||
1162 | int ret = -EINVAL; | ||
1163 | u16 id1, id2, mask, mode; | ||
1164 | |||
1165 | /* get WM8350 revision and config mode */ | ||
1166 | wm8350->read_dev(wm8350, WM8350_RESET_ID, sizeof(id1), &id1); | ||
1167 | wm8350->read_dev(wm8350, WM8350_ID, sizeof(id2), &id2); | ||
1168 | |||
1169 | id1 = be16_to_cpu(id1); | ||
1170 | id2 = be16_to_cpu(id2); | ||
1171 | |||
1172 | if (id1 == 0x6143) { | ||
1173 | switch ((id2 & WM8350_CHIP_REV_MASK) >> 12) { | ||
1174 | case WM8350_REV_E: | ||
1175 | dev_info(wm8350->dev, "Found Rev E device\n"); | ||
1176 | wm8350->rev = WM8350_REV_E; | ||
1177 | break; | ||
1178 | case WM8350_REV_F: | ||
1179 | dev_info(wm8350->dev, "Found Rev F device\n"); | ||
1180 | wm8350->rev = WM8350_REV_F; | ||
1181 | break; | ||
1182 | case WM8350_REV_G: | ||
1183 | dev_info(wm8350->dev, "Found Rev G device\n"); | ||
1184 | wm8350->rev = WM8350_REV_G; | ||
1185 | break; | ||
1186 | default: | ||
1187 | /* For safety we refuse to run on unknown hardware */ | ||
1188 | dev_info(wm8350->dev, "Found unknown rev\n"); | ||
1189 | ret = -ENODEV; | ||
1190 | goto err; | ||
1191 | } | ||
1192 | } else { | ||
1193 | dev_info(wm8350->dev, "Device with ID %x is not a WM8350\n", | ||
1194 | id1); | ||
1195 | ret = -ENODEV; | ||
1196 | goto err; | ||
1197 | } | ||
1198 | |||
1199 | mode = id2 & WM8350_CONF_STS_MASK >> 10; | ||
1200 | mask = id2 & WM8350_CUST_ID_MASK; | ||
1201 | dev_info(wm8350->dev, "Config mode %d, ROM mask %d\n", mode, mask); | ||
1202 | |||
1203 | ret = wm8350_create_cache(wm8350, mode); | ||
1204 | if (ret < 0) { | ||
1205 | printk(KERN_ERR "wm8350: failed to create register cache\n"); | ||
1206 | return ret; | ||
1207 | } | ||
1208 | |||
1209 | if (pdata->init) { | ||
1210 | ret = pdata->init(wm8350); | ||
1211 | if (ret != 0) { | ||
1212 | dev_err(wm8350->dev, "Platform init() failed: %d\n", | ||
1213 | ret); | ||
1214 | goto err; | ||
1215 | } | ||
1216 | } | ||
1217 | |||
1218 | mutex_init(&wm8350->irq_mutex); | ||
1219 | INIT_WORK(&wm8350->irq_work, wm8350_irq_worker); | ||
1220 | if (irq != NO_IRQ) { | ||
1221 | ret = request_irq(irq, wm8350_irq, 0, | ||
1222 | "wm8350", wm8350); | ||
1223 | if (ret != 0) { | ||
1224 | dev_err(wm8350->dev, "Failed to request IRQ: %d\n", | ||
1225 | ret); | ||
1226 | goto err; | ||
1227 | } | ||
1228 | } else { | ||
1229 | dev_err(wm8350->dev, "No IRQ configured\n"); | ||
1230 | goto err; | ||
1231 | } | ||
1232 | wm8350->chip_irq = irq; | ||
1233 | |||
1234 | wm8350_reg_write(wm8350, WM8350_SYSTEM_INTERRUPTS_MASK, 0x0); | ||
1235 | |||
1236 | wm8350_client_dev_register(wm8350, "wm8350-codec", | ||
1237 | &(wm8350->codec.pdev)); | ||
1238 | wm8350_client_dev_register(wm8350, "wm8350-gpio", | ||
1239 | &(wm8350->gpio.pdev)); | ||
1240 | wm8350_client_dev_register(wm8350, "wm8350-power", | ||
1241 | &(wm8350->power.pdev)); | ||
1242 | wm8350_client_dev_register(wm8350, "wm8350-rtc", &(wm8350->rtc.pdev)); | ||
1243 | wm8350_client_dev_register(wm8350, "wm8350-wdt", &(wm8350->wdt.pdev)); | ||
1244 | |||
1245 | return 0; | ||
1246 | |||
1247 | err: | ||
1248 | kfree(wm8350->reg_cache); | ||
1249 | return ret; | ||
1250 | } | ||
1251 | EXPORT_SYMBOL_GPL(wm8350_device_init); | ||
1252 | |||
1253 | void wm8350_device_exit(struct wm8350 *wm8350) | ||
1254 | { | ||
1255 | int i; | ||
1256 | |||
1257 | for (i = 0; i < ARRAY_SIZE(wm8350->pmic.pdev); i++) | ||
1258 | platform_device_unregister(wm8350->pmic.pdev[i]); | ||
1259 | |||
1260 | platform_device_unregister(wm8350->wdt.pdev); | ||
1261 | platform_device_unregister(wm8350->rtc.pdev); | ||
1262 | platform_device_unregister(wm8350->power.pdev); | ||
1263 | platform_device_unregister(wm8350->gpio.pdev); | ||
1264 | platform_device_unregister(wm8350->codec.pdev); | ||
1265 | |||
1266 | free_irq(wm8350->chip_irq, wm8350); | ||
1267 | flush_work(&wm8350->irq_work); | ||
1268 | kfree(wm8350->reg_cache); | ||
1269 | } | ||
1270 | EXPORT_SYMBOL_GPL(wm8350_device_exit); | ||
1271 | |||
1272 | MODULE_DESCRIPTION("WM8350 AudioPlus PMIC core driver"); | ||
1273 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/mfd/wm8350-gpio.c b/drivers/mfd/wm8350-gpio.c new file mode 100644 index 000000000000..ebf99bef392f --- /dev/null +++ b/drivers/mfd/wm8350-gpio.c | |||
@@ -0,0 +1,222 @@ | |||
1 | /* | ||
2 | * wm8350-core.c -- Device access for Wolfson WM8350 | ||
3 | * | ||
4 | * Copyright 2007, 2008 Wolfson Microelectronics PLC. | ||
5 | * | ||
6 | * Author: Liam Girdwood | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | * | ||
13 | */ | ||
14 | |||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/module.h> | ||
17 | #include <linux/errno.h> | ||
18 | |||
19 | #include <linux/mfd/wm8350/core.h> | ||
20 | #include <linux/mfd/wm8350/gpio.h> | ||
21 | #include <linux/mfd/wm8350/pmic.h> | ||
22 | |||
23 | static int gpio_set_dir(struct wm8350 *wm8350, int gpio, int dir) | ||
24 | { | ||
25 | int ret; | ||
26 | |||
27 | wm8350_reg_unlock(wm8350); | ||
28 | if (dir == WM8350_GPIO_DIR_OUT) | ||
29 | ret = wm8350_clear_bits(wm8350, | ||
30 | WM8350_GPIO_CONFIGURATION_I_O, | ||
31 | 1 << gpio); | ||
32 | else | ||
33 | ret = wm8350_set_bits(wm8350, | ||
34 | WM8350_GPIO_CONFIGURATION_I_O, | ||
35 | 1 << gpio); | ||
36 | wm8350_reg_lock(wm8350); | ||
37 | return ret; | ||
38 | } | ||
39 | |||
40 | static int gpio_set_debounce(struct wm8350 *wm8350, int gpio, int db) | ||
41 | { | ||
42 | if (db == WM8350_GPIO_DEBOUNCE_ON) | ||
43 | return wm8350_set_bits(wm8350, WM8350_GPIO_DEBOUNCE, | ||
44 | 1 << gpio); | ||
45 | else | ||
46 | return wm8350_clear_bits(wm8350, | ||
47 | WM8350_GPIO_DEBOUNCE, 1 << gpio); | ||
48 | } | ||
49 | |||
50 | static int gpio_set_func(struct wm8350 *wm8350, int gpio, int func) | ||
51 | { | ||
52 | u16 reg; | ||
53 | |||
54 | wm8350_reg_unlock(wm8350); | ||
55 | switch (gpio) { | ||
56 | case 0: | ||
57 | reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_1) | ||
58 | & ~WM8350_GP0_FN_MASK; | ||
59 | wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_1, | ||
60 | reg | ((func & 0xf) << 0)); | ||
61 | break; | ||
62 | case 1: | ||
63 | reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_1) | ||
64 | & ~WM8350_GP1_FN_MASK; | ||
65 | wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_1, | ||
66 | reg | ((func & 0xf) << 4)); | ||
67 | break; | ||
68 | case 2: | ||
69 | reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_1) | ||
70 | & ~WM8350_GP2_FN_MASK; | ||
71 | wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_1, | ||
72 | reg | ((func & 0xf) << 8)); | ||
73 | break; | ||
74 | case 3: | ||
75 | reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_1) | ||
76 | & ~WM8350_GP3_FN_MASK; | ||
77 | wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_1, | ||
78 | reg | ((func & 0xf) << 12)); | ||
79 | break; | ||
80 | case 4: | ||
81 | reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_2) | ||
82 | & ~WM8350_GP4_FN_MASK; | ||
83 | wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_2, | ||
84 | reg | ((func & 0xf) << 0)); | ||
85 | break; | ||
86 | case 5: | ||
87 | reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_2) | ||
88 | & ~WM8350_GP5_FN_MASK; | ||
89 | wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_2, | ||
90 | reg | ((func & 0xf) << 4)); | ||
91 | break; | ||
92 | case 6: | ||
93 | reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_2) | ||
94 | & ~WM8350_GP6_FN_MASK; | ||
95 | wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_2, | ||
96 | reg | ((func & 0xf) << 8)); | ||
97 | break; | ||
98 | case 7: | ||
99 | reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_2) | ||
100 | & ~WM8350_GP7_FN_MASK; | ||
101 | wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_2, | ||
102 | reg | ((func & 0xf) << 12)); | ||
103 | break; | ||
104 | case 8: | ||
105 | reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_3) | ||
106 | & ~WM8350_GP8_FN_MASK; | ||
107 | wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_3, | ||
108 | reg | ((func & 0xf) << 0)); | ||
109 | break; | ||
110 | case 9: | ||
111 | reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_3) | ||
112 | & ~WM8350_GP9_FN_MASK; | ||
113 | wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_3, | ||
114 | reg | ((func & 0xf) << 4)); | ||
115 | break; | ||
116 | case 10: | ||
117 | reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_3) | ||
118 | & ~WM8350_GP10_FN_MASK; | ||
119 | wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_3, | ||
120 | reg | ((func & 0xf) << 8)); | ||
121 | break; | ||
122 | case 11: | ||
123 | reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_3) | ||
124 | & ~WM8350_GP11_FN_MASK; | ||
125 | wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_3, | ||
126 | reg | ((func & 0xf) << 12)); | ||
127 | break; | ||
128 | case 12: | ||
129 | reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_4) | ||
130 | & ~WM8350_GP12_FN_MASK; | ||
131 | wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_4, | ||
132 | reg | ((func & 0xf) << 0)); | ||
133 | break; | ||
134 | default: | ||
135 | wm8350_reg_lock(wm8350); | ||
136 | return -EINVAL; | ||
137 | } | ||
138 | |||
139 | wm8350_reg_lock(wm8350); | ||
140 | return 0; | ||
141 | } | ||
142 | |||
143 | static int gpio_set_pull_up(struct wm8350 *wm8350, int gpio, int up) | ||
144 | { | ||
145 | if (up) | ||
146 | return wm8350_set_bits(wm8350, | ||
147 | WM8350_GPIO_PIN_PULL_UP_CONTROL, | ||
148 | 1 << gpio); | ||
149 | else | ||
150 | return wm8350_clear_bits(wm8350, | ||
151 | WM8350_GPIO_PIN_PULL_UP_CONTROL, | ||
152 | 1 << gpio); | ||
153 | } | ||
154 | |||
155 | static int gpio_set_pull_down(struct wm8350 *wm8350, int gpio, int down) | ||
156 | { | ||
157 | if (down) | ||
158 | return wm8350_set_bits(wm8350, | ||
159 | WM8350_GPIO_PULL_DOWN_CONTROL, | ||
160 | 1 << gpio); | ||
161 | else | ||
162 | return wm8350_clear_bits(wm8350, | ||
163 | WM8350_GPIO_PULL_DOWN_CONTROL, | ||
164 | 1 << gpio); | ||
165 | } | ||
166 | |||
167 | static int gpio_set_polarity(struct wm8350 *wm8350, int gpio, int pol) | ||
168 | { | ||
169 | if (pol == WM8350_GPIO_ACTIVE_HIGH) | ||
170 | return wm8350_set_bits(wm8350, | ||
171 | WM8350_GPIO_PIN_POLARITY_TYPE, | ||
172 | 1 << gpio); | ||
173 | else | ||
174 | return wm8350_clear_bits(wm8350, | ||
175 | WM8350_GPIO_PIN_POLARITY_TYPE, | ||
176 | 1 << gpio); | ||
177 | } | ||
178 | |||
179 | static int gpio_set_invert(struct wm8350 *wm8350, int gpio, int invert) | ||
180 | { | ||
181 | if (invert == WM8350_GPIO_INVERT_ON) | ||
182 | return wm8350_set_bits(wm8350, WM8350_GPIO_INT_MODE, 1 << gpio); | ||
183 | else | ||
184 | return wm8350_clear_bits(wm8350, | ||
185 | WM8350_GPIO_INT_MODE, 1 << gpio); | ||
186 | } | ||
187 | |||
188 | int wm8350_gpio_config(struct wm8350 *wm8350, int gpio, int dir, int func, | ||
189 | int pol, int pull, int invert, int debounce) | ||
190 | { | ||
191 | /* make sure we never pull up and down at the same time */ | ||
192 | if (pull == WM8350_GPIO_PULL_NONE) { | ||
193 | if (gpio_set_pull_up(wm8350, gpio, 0)) | ||
194 | goto err; | ||
195 | if (gpio_set_pull_down(wm8350, gpio, 0)) | ||
196 | goto err; | ||
197 | } else if (pull == WM8350_GPIO_PULL_UP) { | ||
198 | if (gpio_set_pull_down(wm8350, gpio, 0)) | ||
199 | goto err; | ||
200 | if (gpio_set_pull_up(wm8350, gpio, 1)) | ||
201 | goto err; | ||
202 | } else if (pull == WM8350_GPIO_PULL_DOWN) { | ||
203 | if (gpio_set_pull_up(wm8350, gpio, 0)) | ||
204 | goto err; | ||
205 | if (gpio_set_pull_down(wm8350, gpio, 1)) | ||
206 | goto err; | ||
207 | } | ||
208 | |||
209 | if (gpio_set_invert(wm8350, gpio, invert)) | ||
210 | goto err; | ||
211 | if (gpio_set_polarity(wm8350, gpio, pol)) | ||
212 | goto err; | ||
213 | if (gpio_set_debounce(wm8350, gpio, debounce)) | ||
214 | goto err; | ||
215 | if (gpio_set_dir(wm8350, gpio, dir)) | ||
216 | goto err; | ||
217 | return gpio_set_func(wm8350, gpio, func); | ||
218 | |||
219 | err: | ||
220 | return -EIO; | ||
221 | } | ||
222 | EXPORT_SYMBOL_GPL(wm8350_gpio_config); | ||
diff --git a/drivers/mfd/wm8350-i2c.c b/drivers/mfd/wm8350-i2c.c new file mode 100644 index 000000000000..8dfe21bb3bd1 --- /dev/null +++ b/drivers/mfd/wm8350-i2c.c | |||
@@ -0,0 +1,120 @@ | |||
1 | /* | ||
2 | * wm8350-i2c.c -- Generic I2C driver for Wolfson WM8350 PMIC | ||
3 | * | ||
4 | * This driver defines and configures the WM8350 for the Freescale i.MX32ADS. | ||
5 | * | ||
6 | * Copyright 2007, 2008 Wolfson Microelectronics PLC. | ||
7 | * | ||
8 | * Author: Liam Girdwood | ||
9 | * linux@wolfsonmicro.com | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify it | ||
12 | * under the terms of the GNU General Public License as published by the | ||
13 | * Free Software Foundation; either version 2 of the License, or (at your | ||
14 | * option) any later version. | ||
15 | * | ||
16 | */ | ||
17 | |||
18 | #include <linux/module.h> | ||
19 | #include <linux/moduleparam.h> | ||
20 | #include <linux/init.h> | ||
21 | #include <linux/i2c.h> | ||
22 | #include <linux/platform_device.h> | ||
23 | #include <linux/mfd/wm8350/core.h> | ||
24 | |||
25 | static int wm8350_i2c_read_device(struct wm8350 *wm8350, char reg, | ||
26 | int bytes, void *dest) | ||
27 | { | ||
28 | int ret; | ||
29 | |||
30 | ret = i2c_master_send(wm8350->i2c_client, ®, 1); | ||
31 | if (ret < 0) | ||
32 | return ret; | ||
33 | return i2c_master_recv(wm8350->i2c_client, dest, bytes); | ||
34 | } | ||
35 | |||
36 | static int wm8350_i2c_write_device(struct wm8350 *wm8350, char reg, | ||
37 | int bytes, void *src) | ||
38 | { | ||
39 | /* we add 1 byte for device register */ | ||
40 | u8 msg[(WM8350_MAX_REGISTER << 1) + 1]; | ||
41 | |||
42 | if (bytes > ((WM8350_MAX_REGISTER << 1) + 1)) | ||
43 | return -EINVAL; | ||
44 | |||
45 | msg[0] = reg; | ||
46 | memcpy(&msg[1], src, bytes); | ||
47 | return i2c_master_send(wm8350->i2c_client, msg, bytes + 1); | ||
48 | } | ||
49 | |||
50 | static int wm8350_i2c_probe(struct i2c_client *i2c, | ||
51 | const struct i2c_device_id *id) | ||
52 | { | ||
53 | struct wm8350 *wm8350; | ||
54 | int ret = 0; | ||
55 | |||
56 | wm8350 = kzalloc(sizeof(struct wm8350), GFP_KERNEL); | ||
57 | if (wm8350 == NULL) { | ||
58 | kfree(i2c); | ||
59 | return -ENOMEM; | ||
60 | } | ||
61 | |||
62 | i2c_set_clientdata(i2c, wm8350); | ||
63 | wm8350->dev = &i2c->dev; | ||
64 | wm8350->i2c_client = i2c; | ||
65 | wm8350->read_dev = wm8350_i2c_read_device; | ||
66 | wm8350->write_dev = wm8350_i2c_write_device; | ||
67 | |||
68 | ret = wm8350_device_init(wm8350, i2c->irq, i2c->dev.platform_data); | ||
69 | if (ret < 0) | ||
70 | goto err; | ||
71 | |||
72 | return ret; | ||
73 | |||
74 | err: | ||
75 | kfree(wm8350); | ||
76 | return ret; | ||
77 | } | ||
78 | |||
79 | static int wm8350_i2c_remove(struct i2c_client *i2c) | ||
80 | { | ||
81 | struct wm8350 *wm8350 = i2c_get_clientdata(i2c); | ||
82 | |||
83 | wm8350_device_exit(wm8350); | ||
84 | kfree(wm8350); | ||
85 | |||
86 | return 0; | ||
87 | } | ||
88 | |||
89 | static const struct i2c_device_id wm8350_i2c_id[] = { | ||
90 | { "wm8350", 0 }, | ||
91 | { } | ||
92 | }; | ||
93 | MODULE_DEVICE_TABLE(i2c, wm8350_i2c_id); | ||
94 | |||
95 | |||
96 | static struct i2c_driver wm8350_i2c_driver = { | ||
97 | .driver = { | ||
98 | .name = "wm8350", | ||
99 | .owner = THIS_MODULE, | ||
100 | }, | ||
101 | .probe = wm8350_i2c_probe, | ||
102 | .remove = wm8350_i2c_remove, | ||
103 | .id_table = wm8350_i2c_id, | ||
104 | }; | ||
105 | |||
106 | static int __init wm8350_i2c_init(void) | ||
107 | { | ||
108 | return i2c_add_driver(&wm8350_i2c_driver); | ||
109 | } | ||
110 | /* init early so consumer devices can complete system boot */ | ||
111 | subsys_initcall(wm8350_i2c_init); | ||
112 | |||
113 | static void __exit wm8350_i2c_exit(void) | ||
114 | { | ||
115 | i2c_del_driver(&wm8350_i2c_driver); | ||
116 | } | ||
117 | module_exit(wm8350_i2c_exit); | ||
118 | |||
119 | MODULE_DESCRIPTION("I2C support for the WM8350 AudioPlus PMIC"); | ||
120 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/mfd/wm8350-regmap.c b/drivers/mfd/wm8350-regmap.c new file mode 100644 index 000000000000..974678db22cd --- /dev/null +++ b/drivers/mfd/wm8350-regmap.c | |||
@@ -0,0 +1,1347 @@ | |||
1 | /* | ||
2 | * wm8350-regmap.c -- Wolfson Microelectronics WM8350 register map | ||
3 | * | ||
4 | * This file splits out the tables describing the defaults and access | ||
5 | * status of the WM8350 registers since they are rather large. | ||
6 | * | ||
7 | * Copyright 2007, 2008 Wolfson Microelectronics PLC. | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify it | ||
10 | * under the terms of the GNU General Public License as published by the | ||
11 | * Free Software Foundation; either version 2 of the License, or (at your | ||
12 | * option) any later version. | ||
13 | */ | ||
14 | |||
15 | #include <linux/mfd/wm8350/core.h> | ||
16 | |||
17 | #ifdef CONFIG_MFD_WM8350_CONFIG_MODE_0 | ||
18 | |||
19 | #undef WM8350_HAVE_CONFIG_MODE | ||
20 | #define WM8350_HAVE_CONFIG_MODE | ||
21 | |||
22 | const u16 wm8350_mode0_defaults[] = { | ||
23 | 0x17FF, /* R0 - Reset/ID */ | ||
24 | 0x1000, /* R1 - ID */ | ||
25 | 0x0000, /* R2 */ | ||
26 | 0x1002, /* R3 - System Control 1 */ | ||
27 | 0x0004, /* R4 - System Control 2 */ | ||
28 | 0x0000, /* R5 - System Hibernate */ | ||
29 | 0x8A00, /* R6 - Interface Control */ | ||
30 | 0x0000, /* R7 */ | ||
31 | 0x8000, /* R8 - Power mgmt (1) */ | ||
32 | 0x0000, /* R9 - Power mgmt (2) */ | ||
33 | 0x0000, /* R10 - Power mgmt (3) */ | ||
34 | 0x2000, /* R11 - Power mgmt (4) */ | ||
35 | 0x0E00, /* R12 - Power mgmt (5) */ | ||
36 | 0x0000, /* R13 - Power mgmt (6) */ | ||
37 | 0x0000, /* R14 - Power mgmt (7) */ | ||
38 | 0x0000, /* R15 */ | ||
39 | 0x0000, /* R16 - RTC Seconds/Minutes */ | ||
40 | 0x0100, /* R17 - RTC Hours/Day */ | ||
41 | 0x0101, /* R18 - RTC Date/Month */ | ||
42 | 0x1400, /* R19 - RTC Year */ | ||
43 | 0x0000, /* R20 - Alarm Seconds/Minutes */ | ||
44 | 0x0000, /* R21 - Alarm Hours/Day */ | ||
45 | 0x0000, /* R22 - Alarm Date/Month */ | ||
46 | 0x0320, /* R23 - RTC Time Control */ | ||
47 | 0x0000, /* R24 - System Interrupts */ | ||
48 | 0x0000, /* R25 - Interrupt Status 1 */ | ||
49 | 0x0000, /* R26 - Interrupt Status 2 */ | ||
50 | 0x0000, /* R27 - Power Up Interrupt Status */ | ||
51 | 0x0000, /* R28 - Under Voltage Interrupt status */ | ||
52 | 0x0000, /* R29 - Over Current Interrupt status */ | ||
53 | 0x0000, /* R30 - GPIO Interrupt Status */ | ||
54 | 0x0000, /* R31 - Comparator Interrupt Status */ | ||
55 | 0x3FFF, /* R32 - System Interrupts Mask */ | ||
56 | 0x0000, /* R33 - Interrupt Status 1 Mask */ | ||
57 | 0x0000, /* R34 - Interrupt Status 2 Mask */ | ||
58 | 0x0000, /* R35 - Power Up Interrupt Status Mask */ | ||
59 | 0x0000, /* R36 - Under Voltage Interrupt status Mask */ | ||
60 | 0x0000, /* R37 - Over Current Interrupt status Mask */ | ||
61 | 0x0000, /* R38 - GPIO Interrupt Status Mask */ | ||
62 | 0x0000, /* R39 - Comparator Interrupt Status Mask */ | ||
63 | 0x0040, /* R40 - Clock Control 1 */ | ||
64 | 0x0000, /* R41 - Clock Control 2 */ | ||
65 | 0x3B00, /* R42 - FLL Control 1 */ | ||
66 | 0x7086, /* R43 - FLL Control 2 */ | ||
67 | 0xC226, /* R44 - FLL Control 3 */ | ||
68 | 0x0000, /* R45 - FLL Control 4 */ | ||
69 | 0x0000, /* R46 */ | ||
70 | 0x0000, /* R47 */ | ||
71 | 0x0000, /* R48 - DAC Control */ | ||
72 | 0x0000, /* R49 */ | ||
73 | 0x00C0, /* R50 - DAC Digital Volume L */ | ||
74 | 0x00C0, /* R51 - DAC Digital Volume R */ | ||
75 | 0x0000, /* R52 */ | ||
76 | 0x0040, /* R53 - DAC LR Rate */ | ||
77 | 0x0000, /* R54 - DAC Clock Control */ | ||
78 | 0x0000, /* R55 */ | ||
79 | 0x0000, /* R56 */ | ||
80 | 0x0000, /* R57 */ | ||
81 | 0x4000, /* R58 - DAC Mute */ | ||
82 | 0x0000, /* R59 - DAC Mute Volume */ | ||
83 | 0x0000, /* R60 - DAC Side */ | ||
84 | 0x0000, /* R61 */ | ||
85 | 0x0000, /* R62 */ | ||
86 | 0x0000, /* R63 */ | ||
87 | 0x8000, /* R64 - ADC Control */ | ||
88 | 0x0000, /* R65 */ | ||
89 | 0x00C0, /* R66 - ADC Digital Volume L */ | ||
90 | 0x00C0, /* R67 - ADC Digital Volume R */ | ||
91 | 0x0000, /* R68 - ADC Divider */ | ||
92 | 0x0000, /* R69 */ | ||
93 | 0x0040, /* R70 - ADC LR Rate */ | ||
94 | 0x0000, /* R71 */ | ||
95 | 0x0303, /* R72 - Input Control */ | ||
96 | 0x0000, /* R73 - IN3 Input Control */ | ||
97 | 0x0000, /* R74 - Mic Bias Control */ | ||
98 | 0x0000, /* R75 */ | ||
99 | 0x0000, /* R76 - Output Control */ | ||
100 | 0x0000, /* R77 - Jack Detect */ | ||
101 | 0x0000, /* R78 - Anti Pop Control */ | ||
102 | 0x0000, /* R79 */ | ||
103 | 0x0040, /* R80 - Left Input Volume */ | ||
104 | 0x0040, /* R81 - Right Input Volume */ | ||
105 | 0x0000, /* R82 */ | ||
106 | 0x0000, /* R83 */ | ||
107 | 0x0000, /* R84 */ | ||
108 | 0x0000, /* R85 */ | ||
109 | 0x0000, /* R86 */ | ||
110 | 0x0000, /* R87 */ | ||
111 | 0x0800, /* R88 - Left Mixer Control */ | ||
112 | 0x1000, /* R89 - Right Mixer Control */ | ||
113 | 0x0000, /* R90 */ | ||
114 | 0x0000, /* R91 */ | ||
115 | 0x0000, /* R92 - OUT3 Mixer Control */ | ||
116 | 0x0000, /* R93 - OUT4 Mixer Control */ | ||
117 | 0x0000, /* R94 */ | ||
118 | 0x0000, /* R95 */ | ||
119 | 0x0000, /* R96 - Output Left Mixer Volume */ | ||
120 | 0x0000, /* R97 - Output Right Mixer Volume */ | ||
121 | 0x0000, /* R98 - Input Mixer Volume L */ | ||
122 | 0x0000, /* R99 - Input Mixer Volume R */ | ||
123 | 0x0000, /* R100 - Input Mixer Volume */ | ||
124 | 0x0000, /* R101 */ | ||
125 | 0x0000, /* R102 */ | ||
126 | 0x0000, /* R103 */ | ||
127 | 0x00E4, /* R104 - LOUT1 Volume */ | ||
128 | 0x00E4, /* R105 - ROUT1 Volume */ | ||
129 | 0x00E4, /* R106 - LOUT2 Volume */ | ||
130 | 0x02E4, /* R107 - ROUT2 Volume */ | ||
131 | 0x0000, /* R108 */ | ||
132 | 0x0000, /* R109 */ | ||
133 | 0x0000, /* R110 */ | ||
134 | 0x0000, /* R111 - BEEP Volume */ | ||
135 | 0x0A00, /* R112 - AI Formating */ | ||
136 | 0x0000, /* R113 - ADC DAC COMP */ | ||
137 | 0x0020, /* R114 - AI ADC Control */ | ||
138 | 0x0020, /* R115 - AI DAC Control */ | ||
139 | 0x0000, /* R116 - AIF Test */ | ||
140 | 0x0000, /* R117 */ | ||
141 | 0x0000, /* R118 */ | ||
142 | 0x0000, /* R119 */ | ||
143 | 0x0000, /* R120 */ | ||
144 | 0x0000, /* R121 */ | ||
145 | 0x0000, /* R122 */ | ||
146 | 0x0000, /* R123 */ | ||
147 | 0x0000, /* R124 */ | ||
148 | 0x0000, /* R125 */ | ||
149 | 0x0000, /* R126 */ | ||
150 | 0x0000, /* R127 */ | ||
151 | 0x1FFF, /* R128 - GPIO Debounce */ | ||
152 | 0x0000, /* R129 - GPIO Pin pull up Control */ | ||
153 | 0x03FC, /* R130 - GPIO Pull down Control */ | ||
154 | 0x0000, /* R131 - GPIO Interrupt Mode */ | ||
155 | 0x0000, /* R132 */ | ||
156 | 0x0000, /* R133 - GPIO Control */ | ||
157 | 0x0FFC, /* R134 - GPIO Configuration (i/o) */ | ||
158 | 0x0FFC, /* R135 - GPIO Pin Polarity / Type */ | ||
159 | 0x0000, /* R136 */ | ||
160 | 0x0000, /* R137 */ | ||
161 | 0x0000, /* R138 */ | ||
162 | 0x0000, /* R139 */ | ||
163 | 0x0013, /* R140 - GPIO Function Select 1 */ | ||
164 | 0x0000, /* R141 - GPIO Function Select 2 */ | ||
165 | 0x0000, /* R142 - GPIO Function Select 3 */ | ||
166 | 0x0003, /* R143 - GPIO Function Select 4 */ | ||
167 | 0x0000, /* R144 - Digitiser Control (1) */ | ||
168 | 0x0002, /* R145 - Digitiser Control (2) */ | ||
169 | 0x0000, /* R146 */ | ||
170 | 0x0000, /* R147 */ | ||
171 | 0x0000, /* R148 */ | ||
172 | 0x0000, /* R149 */ | ||
173 | 0x0000, /* R150 */ | ||
174 | 0x0000, /* R151 */ | ||
175 | 0x7000, /* R152 - AUX1 Readback */ | ||
176 | 0x7000, /* R153 - AUX2 Readback */ | ||
177 | 0x7000, /* R154 - AUX3 Readback */ | ||
178 | 0x7000, /* R155 - AUX4 Readback */ | ||
179 | 0x0000, /* R156 - USB Voltage Readback */ | ||
180 | 0x0000, /* R157 - LINE Voltage Readback */ | ||
181 | 0x0000, /* R158 - BATT Voltage Readback */ | ||
182 | 0x0000, /* R159 - Chip Temp Readback */ | ||
183 | 0x0000, /* R160 */ | ||
184 | 0x0000, /* R161 */ | ||
185 | 0x0000, /* R162 */ | ||
186 | 0x0000, /* R163 - Generic Comparator Control */ | ||
187 | 0x0000, /* R164 - Generic comparator 1 */ | ||
188 | 0x0000, /* R165 - Generic comparator 2 */ | ||
189 | 0x0000, /* R166 - Generic comparator 3 */ | ||
190 | 0x0000, /* R167 - Generic comparator 4 */ | ||
191 | 0xA00F, /* R168 - Battery Charger Control 1 */ | ||
192 | 0x0B06, /* R169 - Battery Charger Control 2 */ | ||
193 | 0x0000, /* R170 - Battery Charger Control 3 */ | ||
194 | 0x0000, /* R171 */ | ||
195 | 0x0000, /* R172 - Current Sink Driver A */ | ||
196 | 0x0000, /* R173 - CSA Flash control */ | ||
197 | 0x0000, /* R174 - Current Sink Driver B */ | ||
198 | 0x0000, /* R175 - CSB Flash control */ | ||
199 | 0x0000, /* R176 - DCDC/LDO requested */ | ||
200 | 0x002D, /* R177 - DCDC Active options */ | ||
201 | 0x0000, /* R178 - DCDC Sleep options */ | ||
202 | 0x0025, /* R179 - Power-check comparator */ | ||
203 | 0x000E, /* R180 - DCDC1 Control */ | ||
204 | 0x0000, /* R181 - DCDC1 Timeouts */ | ||
205 | 0x1006, /* R182 - DCDC1 Low Power */ | ||
206 | 0x0018, /* R183 - DCDC2 Control */ | ||
207 | 0x0000, /* R184 - DCDC2 Timeouts */ | ||
208 | 0x0000, /* R185 */ | ||
209 | 0x0000, /* R186 - DCDC3 Control */ | ||
210 | 0x0000, /* R187 - DCDC3 Timeouts */ | ||
211 | 0x0006, /* R188 - DCDC3 Low Power */ | ||
212 | 0x0000, /* R189 - DCDC4 Control */ | ||
213 | 0x0000, /* R190 - DCDC4 Timeouts */ | ||
214 | 0x0006, /* R191 - DCDC4 Low Power */ | ||
215 | 0x0008, /* R192 - DCDC5 Control */ | ||
216 | 0x0000, /* R193 - DCDC5 Timeouts */ | ||
217 | 0x0000, /* R194 */ | ||
218 | 0x0000, /* R195 - DCDC6 Control */ | ||
219 | 0x0000, /* R196 - DCDC6 Timeouts */ | ||
220 | 0x0006, /* R197 - DCDC6 Low Power */ | ||
221 | 0x0000, /* R198 */ | ||
222 | 0x0003, /* R199 - Limit Switch Control */ | ||
223 | 0x001C, /* R200 - LDO1 Control */ | ||
224 | 0x0000, /* R201 - LDO1 Timeouts */ | ||
225 | 0x001C, /* R202 - LDO1 Low Power */ | ||
226 | 0x001B, /* R203 - LDO2 Control */ | ||
227 | 0x0000, /* R204 - LDO2 Timeouts */ | ||
228 | 0x001C, /* R205 - LDO2 Low Power */ | ||
229 | 0x001B, /* R206 - LDO3 Control */ | ||
230 | 0x0000, /* R207 - LDO3 Timeouts */ | ||
231 | 0x001C, /* R208 - LDO3 Low Power */ | ||
232 | 0x001B, /* R209 - LDO4 Control */ | ||
233 | 0x0000, /* R210 - LDO4 Timeouts */ | ||
234 | 0x001C, /* R211 - LDO4 Low Power */ | ||
235 | 0x0000, /* R212 */ | ||
236 | 0x0000, /* R213 */ | ||
237 | 0x0000, /* R214 */ | ||
238 | 0x0000, /* R215 - VCC_FAULT Masks */ | ||
239 | 0x001F, /* R216 - Main Bandgap Control */ | ||
240 | 0x0000, /* R217 - OSC Control */ | ||
241 | 0x9000, /* R218 - RTC Tick Control */ | ||
242 | 0x0000, /* R219 */ | ||
243 | 0x4000, /* R220 - RAM BIST 1 */ | ||
244 | 0x0000, /* R221 */ | ||
245 | 0x0000, /* R222 */ | ||
246 | 0x0000, /* R223 */ | ||
247 | 0x0000, /* R224 */ | ||
248 | 0x0000, /* R225 - DCDC/LDO status */ | ||
249 | 0x0000, /* R226 */ | ||
250 | 0x0000, /* R227 */ | ||
251 | 0x0000, /* R228 */ | ||
252 | 0x0000, /* R229 */ | ||
253 | 0xE000, /* R230 - GPIO Pin Status */ | ||
254 | 0x0000, /* R231 */ | ||
255 | 0x0000, /* R232 */ | ||
256 | 0x0000, /* R233 */ | ||
257 | 0x0000, /* R234 */ | ||
258 | 0x0000, /* R235 */ | ||
259 | 0x0000, /* R236 */ | ||
260 | 0x0000, /* R237 */ | ||
261 | 0x0000, /* R238 */ | ||
262 | 0x0000, /* R239 */ | ||
263 | 0x0000, /* R240 */ | ||
264 | 0x0000, /* R241 */ | ||
265 | 0x0000, /* R242 */ | ||
266 | 0x0000, /* R243 */ | ||
267 | 0x0000, /* R244 */ | ||
268 | 0x0000, /* R245 */ | ||
269 | 0x0000, /* R246 */ | ||
270 | 0x0000, /* R247 */ | ||
271 | 0x0000, /* R248 */ | ||
272 | 0x0000, /* R249 */ | ||
273 | 0x0000, /* R250 */ | ||
274 | 0x0000, /* R251 */ | ||
275 | 0x0000, /* R252 */ | ||
276 | 0x0000, /* R253 */ | ||
277 | 0x0000, /* R254 */ | ||
278 | 0x0000, /* R255 */ | ||
279 | }; | ||
280 | #endif | ||
281 | |||
282 | #ifdef CONFIG_MFD_WM8350_CONFIG_MODE_1 | ||
283 | |||
284 | #undef WM8350_HAVE_CONFIG_MODE | ||
285 | #define WM8350_HAVE_CONFIG_MODE | ||
286 | |||
287 | const u16 wm8350_mode1_defaults[] = { | ||
288 | 0x17FF, /* R0 - Reset/ID */ | ||
289 | 0x1000, /* R1 - ID */ | ||
290 | 0x0000, /* R2 */ | ||
291 | 0x1002, /* R3 - System Control 1 */ | ||
292 | 0x0014, /* R4 - System Control 2 */ | ||
293 | 0x0000, /* R5 - System Hibernate */ | ||
294 | 0x8A00, /* R6 - Interface Control */ | ||
295 | 0x0000, /* R7 */ | ||
296 | 0x8000, /* R8 - Power mgmt (1) */ | ||
297 | 0x0000, /* R9 - Power mgmt (2) */ | ||
298 | 0x0000, /* R10 - Power mgmt (3) */ | ||
299 | 0x2000, /* R11 - Power mgmt (4) */ | ||
300 | 0x0E00, /* R12 - Power mgmt (5) */ | ||
301 | 0x0000, /* R13 - Power mgmt (6) */ | ||
302 | 0x0000, /* R14 - Power mgmt (7) */ | ||
303 | 0x0000, /* R15 */ | ||
304 | 0x0000, /* R16 - RTC Seconds/Minutes */ | ||
305 | 0x0100, /* R17 - RTC Hours/Day */ | ||
306 | 0x0101, /* R18 - RTC Date/Month */ | ||
307 | 0x1400, /* R19 - RTC Year */ | ||
308 | 0x0000, /* R20 - Alarm Seconds/Minutes */ | ||
309 | 0x0000, /* R21 - Alarm Hours/Day */ | ||
310 | 0x0000, /* R22 - Alarm Date/Month */ | ||
311 | 0x0320, /* R23 - RTC Time Control */ | ||
312 | 0x0000, /* R24 - System Interrupts */ | ||
313 | 0x0000, /* R25 - Interrupt Status 1 */ | ||
314 | 0x0000, /* R26 - Interrupt Status 2 */ | ||
315 | 0x0000, /* R27 - Power Up Interrupt Status */ | ||
316 | 0x0000, /* R28 - Under Voltage Interrupt status */ | ||
317 | 0x0000, /* R29 - Over Current Interrupt status */ | ||
318 | 0x0000, /* R30 - GPIO Interrupt Status */ | ||
319 | 0x0000, /* R31 - Comparator Interrupt Status */ | ||
320 | 0x3FFF, /* R32 - System Interrupts Mask */ | ||
321 | 0x0000, /* R33 - Interrupt Status 1 Mask */ | ||
322 | 0x0000, /* R34 - Interrupt Status 2 Mask */ | ||
323 | 0x0000, /* R35 - Power Up Interrupt Status Mask */ | ||
324 | 0x0000, /* R36 - Under Voltage Interrupt status Mask */ | ||
325 | 0x0000, /* R37 - Over Current Interrupt status Mask */ | ||
326 | 0x0000, /* R38 - GPIO Interrupt Status Mask */ | ||
327 | 0x0000, /* R39 - Comparator Interrupt Status Mask */ | ||
328 | 0x0040, /* R40 - Clock Control 1 */ | ||
329 | 0x0000, /* R41 - Clock Control 2 */ | ||
330 | 0x3B00, /* R42 - FLL Control 1 */ | ||
331 | 0x7086, /* R43 - FLL Control 2 */ | ||
332 | 0xC226, /* R44 - FLL Control 3 */ | ||
333 | 0x0000, /* R45 - FLL Control 4 */ | ||
334 | 0x0000, /* R46 */ | ||
335 | 0x0000, /* R47 */ | ||
336 | 0x0000, /* R48 - DAC Control */ | ||
337 | 0x0000, /* R49 */ | ||
338 | 0x00C0, /* R50 - DAC Digital Volume L */ | ||
339 | 0x00C0, /* R51 - DAC Digital Volume R */ | ||
340 | 0x0000, /* R52 */ | ||
341 | 0x0040, /* R53 - DAC LR Rate */ | ||
342 | 0x0000, /* R54 - DAC Clock Control */ | ||
343 | 0x0000, /* R55 */ | ||
344 | 0x0000, /* R56 */ | ||
345 | 0x0000, /* R57 */ | ||
346 | 0x4000, /* R58 - DAC Mute */ | ||
347 | 0x0000, /* R59 - DAC Mute Volume */ | ||
348 | 0x0000, /* R60 - DAC Side */ | ||
349 | 0x0000, /* R61 */ | ||
350 | 0x0000, /* R62 */ | ||
351 | 0x0000, /* R63 */ | ||
352 | 0x8000, /* R64 - ADC Control */ | ||
353 | 0x0000, /* R65 */ | ||
354 | 0x00C0, /* R66 - ADC Digital Volume L */ | ||
355 | 0x00C0, /* R67 - ADC Digital Volume R */ | ||
356 | 0x0000, /* R68 - ADC Divider */ | ||
357 | 0x0000, /* R69 */ | ||
358 | 0x0040, /* R70 - ADC LR Rate */ | ||
359 | 0x0000, /* R71 */ | ||
360 | 0x0303, /* R72 - Input Control */ | ||
361 | 0x0000, /* R73 - IN3 Input Control */ | ||
362 | 0x0000, /* R74 - Mic Bias Control */ | ||
363 | 0x0000, /* R75 */ | ||
364 | 0x0000, /* R76 - Output Control */ | ||
365 | 0x0000, /* R77 - Jack Detect */ | ||
366 | 0x0000, /* R78 - Anti Pop Control */ | ||
367 | 0x0000, /* R79 */ | ||
368 | 0x0040, /* R80 - Left Input Volume */ | ||
369 | 0x0040, /* R81 - Right Input Volume */ | ||
370 | 0x0000, /* R82 */ | ||
371 | 0x0000, /* R83 */ | ||
372 | 0x0000, /* R84 */ | ||
373 | 0x0000, /* R85 */ | ||
374 | 0x0000, /* R86 */ | ||
375 | 0x0000, /* R87 */ | ||
376 | 0x0800, /* R88 - Left Mixer Control */ | ||
377 | 0x1000, /* R89 - Right Mixer Control */ | ||
378 | 0x0000, /* R90 */ | ||
379 | 0x0000, /* R91 */ | ||
380 | 0x0000, /* R92 - OUT3 Mixer Control */ | ||
381 | 0x0000, /* R93 - OUT4 Mixer Control */ | ||
382 | 0x0000, /* R94 */ | ||
383 | 0x0000, /* R95 */ | ||
384 | 0x0000, /* R96 - Output Left Mixer Volume */ | ||
385 | 0x0000, /* R97 - Output Right Mixer Volume */ | ||
386 | 0x0000, /* R98 - Input Mixer Volume L */ | ||
387 | 0x0000, /* R99 - Input Mixer Volume R */ | ||
388 | 0x0000, /* R100 - Input Mixer Volume */ | ||
389 | 0x0000, /* R101 */ | ||
390 | 0x0000, /* R102 */ | ||
391 | 0x0000, /* R103 */ | ||
392 | 0x00E4, /* R104 - LOUT1 Volume */ | ||
393 | 0x00E4, /* R105 - ROUT1 Volume */ | ||
394 | 0x00E4, /* R106 - LOUT2 Volume */ | ||
395 | 0x02E4, /* R107 - ROUT2 Volume */ | ||
396 | 0x0000, /* R108 */ | ||
397 | 0x0000, /* R109 */ | ||
398 | 0x0000, /* R110 */ | ||
399 | 0x0000, /* R111 - BEEP Volume */ | ||
400 | 0x0A00, /* R112 - AI Formating */ | ||
401 | 0x0000, /* R113 - ADC DAC COMP */ | ||
402 | 0x0020, /* R114 - AI ADC Control */ | ||
403 | 0x0020, /* R115 - AI DAC Control */ | ||
404 | 0x0000, /* R116 - AIF Test */ | ||
405 | 0x0000, /* R117 */ | ||
406 | 0x0000, /* R118 */ | ||
407 | 0x0000, /* R119 */ | ||
408 | 0x0000, /* R120 */ | ||
409 | 0x0000, /* R121 */ | ||
410 | 0x0000, /* R122 */ | ||
411 | 0x0000, /* R123 */ | ||
412 | 0x0000, /* R124 */ | ||
413 | 0x0000, /* R125 */ | ||
414 | 0x0000, /* R126 */ | ||
415 | 0x0000, /* R127 */ | ||
416 | 0x1FFF, /* R128 - GPIO Debounce */ | ||
417 | 0x0000, /* R129 - GPIO Pin pull up Control */ | ||
418 | 0x03FC, /* R130 - GPIO Pull down Control */ | ||
419 | 0x0000, /* R131 - GPIO Interrupt Mode */ | ||
420 | 0x0000, /* R132 */ | ||
421 | 0x0000, /* R133 - GPIO Control */ | ||
422 | 0x00FB, /* R134 - GPIO Configuration (i/o) */ | ||
423 | 0x04FE, /* R135 - GPIO Pin Polarity / Type */ | ||
424 | 0x0000, /* R136 */ | ||
425 | 0x0000, /* R137 */ | ||
426 | 0x0000, /* R138 */ | ||
427 | 0x0000, /* R139 */ | ||
428 | 0x0312, /* R140 - GPIO Function Select 1 */ | ||
429 | 0x1003, /* R141 - GPIO Function Select 2 */ | ||
430 | 0x1331, /* R142 - GPIO Function Select 3 */ | ||
431 | 0x0003, /* R143 - GPIO Function Select 4 */ | ||
432 | 0x0000, /* R144 - Digitiser Control (1) */ | ||
433 | 0x0002, /* R145 - Digitiser Control (2) */ | ||
434 | 0x0000, /* R146 */ | ||
435 | 0x0000, /* R147 */ | ||
436 | 0x0000, /* R148 */ | ||
437 | 0x0000, /* R149 */ | ||
438 | 0x0000, /* R150 */ | ||
439 | 0x0000, /* R151 */ | ||
440 | 0x7000, /* R152 - AUX1 Readback */ | ||
441 | 0x7000, /* R153 - AUX2 Readback */ | ||
442 | 0x7000, /* R154 - AUX3 Readback */ | ||
443 | 0x7000, /* R155 - AUX4 Readback */ | ||
444 | 0x0000, /* R156 - USB Voltage Readback */ | ||
445 | 0x0000, /* R157 - LINE Voltage Readback */ | ||
446 | 0x0000, /* R158 - BATT Voltage Readback */ | ||
447 | 0x0000, /* R159 - Chip Temp Readback */ | ||
448 | 0x0000, /* R160 */ | ||
449 | 0x0000, /* R161 */ | ||
450 | 0x0000, /* R162 */ | ||
451 | 0x0000, /* R163 - Generic Comparator Control */ | ||
452 | 0x0000, /* R164 - Generic comparator 1 */ | ||
453 | 0x0000, /* R165 - Generic comparator 2 */ | ||
454 | 0x0000, /* R166 - Generic comparator 3 */ | ||
455 | 0x0000, /* R167 - Generic comparator 4 */ | ||
456 | 0xA00F, /* R168 - Battery Charger Control 1 */ | ||
457 | 0x0B06, /* R169 - Battery Charger Control 2 */ | ||
458 | 0x0000, /* R170 - Battery Charger Control 3 */ | ||
459 | 0x0000, /* R171 */ | ||
460 | 0x0000, /* R172 - Current Sink Driver A */ | ||
461 | 0x0000, /* R173 - CSA Flash control */ | ||
462 | 0x0000, /* R174 - Current Sink Driver B */ | ||
463 | 0x0000, /* R175 - CSB Flash control */ | ||
464 | 0x0000, /* R176 - DCDC/LDO requested */ | ||
465 | 0x002D, /* R177 - DCDC Active options */ | ||
466 | 0x0000, /* R178 - DCDC Sleep options */ | ||
467 | 0x0025, /* R179 - Power-check comparator */ | ||
468 | 0x0062, /* R180 - DCDC1 Control */ | ||
469 | 0x0400, /* R181 - DCDC1 Timeouts */ | ||
470 | 0x1006, /* R182 - DCDC1 Low Power */ | ||
471 | 0x0018, /* R183 - DCDC2 Control */ | ||
472 | 0x0000, /* R184 - DCDC2 Timeouts */ | ||
473 | 0x0000, /* R185 */ | ||
474 | 0x0026, /* R186 - DCDC3 Control */ | ||
475 | 0x0400, /* R187 - DCDC3 Timeouts */ | ||
476 | 0x0006, /* R188 - DCDC3 Low Power */ | ||
477 | 0x0062, /* R189 - DCDC4 Control */ | ||
478 | 0x0400, /* R190 - DCDC4 Timeouts */ | ||
479 | 0x0006, /* R191 - DCDC4 Low Power */ | ||
480 | 0x0008, /* R192 - DCDC5 Control */ | ||
481 | 0x0000, /* R193 - DCDC5 Timeouts */ | ||
482 | 0x0000, /* R194 */ | ||
483 | 0x0026, /* R195 - DCDC6 Control */ | ||
484 | 0x0800, /* R196 - DCDC6 Timeouts */ | ||
485 | 0x0006, /* R197 - DCDC6 Low Power */ | ||
486 | 0x0000, /* R198 */ | ||
487 | 0x0003, /* R199 - Limit Switch Control */ | ||
488 | 0x0006, /* R200 - LDO1 Control */ | ||
489 | 0x0400, /* R201 - LDO1 Timeouts */ | ||
490 | 0x001C, /* R202 - LDO1 Low Power */ | ||
491 | 0x0006, /* R203 - LDO2 Control */ | ||
492 | 0x0400, /* R204 - LDO2 Timeouts */ | ||
493 | 0x001C, /* R205 - LDO2 Low Power */ | ||
494 | 0x001B, /* R206 - LDO3 Control */ | ||
495 | 0x0000, /* R207 - LDO3 Timeouts */ | ||
496 | 0x001C, /* R208 - LDO3 Low Power */ | ||
497 | 0x001B, /* R209 - LDO4 Control */ | ||
498 | 0x0000, /* R210 - LDO4 Timeouts */ | ||
499 | 0x001C, /* R211 - LDO4 Low Power */ | ||
500 | 0x0000, /* R212 */ | ||
501 | 0x0000, /* R213 */ | ||
502 | 0x0000, /* R214 */ | ||
503 | 0x0000, /* R215 - VCC_FAULT Masks */ | ||
504 | 0x001F, /* R216 - Main Bandgap Control */ | ||
505 | 0x0000, /* R217 - OSC Control */ | ||
506 | 0x9000, /* R218 - RTC Tick Control */ | ||
507 | 0x0000, /* R219 */ | ||
508 | 0x4000, /* R220 - RAM BIST 1 */ | ||
509 | 0x0000, /* R221 */ | ||
510 | 0x0000, /* R222 */ | ||
511 | 0x0000, /* R223 */ | ||
512 | 0x0000, /* R224 */ | ||
513 | 0x0000, /* R225 - DCDC/LDO status */ | ||
514 | 0x0000, /* R226 */ | ||
515 | 0x0000, /* R227 */ | ||
516 | 0x0000, /* R228 */ | ||
517 | 0x0000, /* R229 */ | ||
518 | 0xE000, /* R230 - GPIO Pin Status */ | ||
519 | 0x0000, /* R231 */ | ||
520 | 0x0000, /* R232 */ | ||
521 | 0x0000, /* R233 */ | ||
522 | 0x0000, /* R234 */ | ||
523 | 0x0000, /* R235 */ | ||
524 | 0x0000, /* R236 */ | ||
525 | 0x0000, /* R237 */ | ||
526 | 0x0000, /* R238 */ | ||
527 | 0x0000, /* R239 */ | ||
528 | 0x0000, /* R240 */ | ||
529 | 0x0000, /* R241 */ | ||
530 | 0x0000, /* R242 */ | ||
531 | 0x0000, /* R243 */ | ||
532 | 0x0000, /* R244 */ | ||
533 | 0x0000, /* R245 */ | ||
534 | 0x0000, /* R246 */ | ||
535 | 0x0000, /* R247 */ | ||
536 | 0x0000, /* R248 */ | ||
537 | 0x0000, /* R249 */ | ||
538 | 0x0000, /* R250 */ | ||
539 | 0x0000, /* R251 */ | ||
540 | 0x0000, /* R252 */ | ||
541 | 0x0000, /* R253 */ | ||
542 | 0x0000, /* R254 */ | ||
543 | 0x0000, /* R255 */ | ||
544 | }; | ||
545 | #endif | ||
546 | |||
547 | #ifdef CONFIG_MFD_WM8350_CONFIG_MODE_2 | ||
548 | |||
549 | #undef WM8350_HAVE_CONFIG_MODE | ||
550 | #define WM8350_HAVE_CONFIG_MODE | ||
551 | |||
552 | const u16 wm8350_mode2_defaults[] = { | ||
553 | 0x17FF, /* R0 - Reset/ID */ | ||
554 | 0x1000, /* R1 - ID */ | ||
555 | 0x0000, /* R2 */ | ||
556 | 0x1002, /* R3 - System Control 1 */ | ||
557 | 0x0014, /* R4 - System Control 2 */ | ||
558 | 0x0000, /* R5 - System Hibernate */ | ||
559 | 0x8A00, /* R6 - Interface Control */ | ||
560 | 0x0000, /* R7 */ | ||
561 | 0x8000, /* R8 - Power mgmt (1) */ | ||
562 | 0x0000, /* R9 - Power mgmt (2) */ | ||
563 | 0x0000, /* R10 - Power mgmt (3) */ | ||
564 | 0x2000, /* R11 - Power mgmt (4) */ | ||
565 | 0x0E00, /* R12 - Power mgmt (5) */ | ||
566 | 0x0000, /* R13 - Power mgmt (6) */ | ||
567 | 0x0000, /* R14 - Power mgmt (7) */ | ||
568 | 0x0000, /* R15 */ | ||
569 | 0x0000, /* R16 - RTC Seconds/Minutes */ | ||
570 | 0x0100, /* R17 - RTC Hours/Day */ | ||
571 | 0x0101, /* R18 - RTC Date/Month */ | ||
572 | 0x1400, /* R19 - RTC Year */ | ||
573 | 0x0000, /* R20 - Alarm Seconds/Minutes */ | ||
574 | 0x0000, /* R21 - Alarm Hours/Day */ | ||
575 | 0x0000, /* R22 - Alarm Date/Month */ | ||
576 | 0x0320, /* R23 - RTC Time Control */ | ||
577 | 0x0000, /* R24 - System Interrupts */ | ||
578 | 0x0000, /* R25 - Interrupt Status 1 */ | ||
579 | 0x0000, /* R26 - Interrupt Status 2 */ | ||
580 | 0x0000, /* R27 - Power Up Interrupt Status */ | ||
581 | 0x0000, /* R28 - Under Voltage Interrupt status */ | ||
582 | 0x0000, /* R29 - Over Current Interrupt status */ | ||
583 | 0x0000, /* R30 - GPIO Interrupt Status */ | ||
584 | 0x0000, /* R31 - Comparator Interrupt Status */ | ||
585 | 0x3FFF, /* R32 - System Interrupts Mask */ | ||
586 | 0x0000, /* R33 - Interrupt Status 1 Mask */ | ||
587 | 0x0000, /* R34 - Interrupt Status 2 Mask */ | ||
588 | 0x0000, /* R35 - Power Up Interrupt Status Mask */ | ||
589 | 0x0000, /* R36 - Under Voltage Interrupt status Mask */ | ||
590 | 0x0000, /* R37 - Over Current Interrupt status Mask */ | ||
591 | 0x0000, /* R38 - GPIO Interrupt Status Mask */ | ||
592 | 0x0000, /* R39 - Comparator Interrupt Status Mask */ | ||
593 | 0x0040, /* R40 - Clock Control 1 */ | ||
594 | 0x0000, /* R41 - Clock Control 2 */ | ||
595 | 0x3B00, /* R42 - FLL Control 1 */ | ||
596 | 0x7086, /* R43 - FLL Control 2 */ | ||
597 | 0xC226, /* R44 - FLL Control 3 */ | ||
598 | 0x0000, /* R45 - FLL Control 4 */ | ||
599 | 0x0000, /* R46 */ | ||
600 | 0x0000, /* R47 */ | ||
601 | 0x0000, /* R48 - DAC Control */ | ||
602 | 0x0000, /* R49 */ | ||
603 | 0x00C0, /* R50 - DAC Digital Volume L */ | ||
604 | 0x00C0, /* R51 - DAC Digital Volume R */ | ||
605 | 0x0000, /* R52 */ | ||
606 | 0x0040, /* R53 - DAC LR Rate */ | ||
607 | 0x0000, /* R54 - DAC Clock Control */ | ||
608 | 0x0000, /* R55 */ | ||
609 | 0x0000, /* R56 */ | ||
610 | 0x0000, /* R57 */ | ||
611 | 0x4000, /* R58 - DAC Mute */ | ||
612 | 0x0000, /* R59 - DAC Mute Volume */ | ||
613 | 0x0000, /* R60 - DAC Side */ | ||
614 | 0x0000, /* R61 */ | ||
615 | 0x0000, /* R62 */ | ||
616 | 0x0000, /* R63 */ | ||
617 | 0x8000, /* R64 - ADC Control */ | ||
618 | 0x0000, /* R65 */ | ||
619 | 0x00C0, /* R66 - ADC Digital Volume L */ | ||
620 | 0x00C0, /* R67 - ADC Digital Volume R */ | ||
621 | 0x0000, /* R68 - ADC Divider */ | ||
622 | 0x0000, /* R69 */ | ||
623 | 0x0040, /* R70 - ADC LR Rate */ | ||
624 | 0x0000, /* R71 */ | ||
625 | 0x0303, /* R72 - Input Control */ | ||
626 | 0x0000, /* R73 - IN3 Input Control */ | ||
627 | 0x0000, /* R74 - Mic Bias Control */ | ||
628 | 0x0000, /* R75 */ | ||
629 | 0x0000, /* R76 - Output Control */ | ||
630 | 0x0000, /* R77 - Jack Detect */ | ||
631 | 0x0000, /* R78 - Anti Pop Control */ | ||
632 | 0x0000, /* R79 */ | ||
633 | 0x0040, /* R80 - Left Input Volume */ | ||
634 | 0x0040, /* R81 - Right Input Volume */ | ||
635 | 0x0000, /* R82 */ | ||
636 | 0x0000, /* R83 */ | ||
637 | 0x0000, /* R84 */ | ||
638 | 0x0000, /* R85 */ | ||
639 | 0x0000, /* R86 */ | ||
640 | 0x0000, /* R87 */ | ||
641 | 0x0800, /* R88 - Left Mixer Control */ | ||
642 | 0x1000, /* R89 - Right Mixer Control */ | ||
643 | 0x0000, /* R90 */ | ||
644 | 0x0000, /* R91 */ | ||
645 | 0x0000, /* R92 - OUT3 Mixer Control */ | ||
646 | 0x0000, /* R93 - OUT4 Mixer Control */ | ||
647 | 0x0000, /* R94 */ | ||
648 | 0x0000, /* R95 */ | ||
649 | 0x0000, /* R96 - Output Left Mixer Volume */ | ||
650 | 0x0000, /* R97 - Output Right Mixer Volume */ | ||
651 | 0x0000, /* R98 - Input Mixer Volume L */ | ||
652 | 0x0000, /* R99 - Input Mixer Volume R */ | ||
653 | 0x0000, /* R100 - Input Mixer Volume */ | ||
654 | 0x0000, /* R101 */ | ||
655 | 0x0000, /* R102 */ | ||
656 | 0x0000, /* R103 */ | ||
657 | 0x00E4, /* R104 - LOUT1 Volume */ | ||
658 | 0x00E4, /* R105 - ROUT1 Volume */ | ||
659 | 0x00E4, /* R106 - LOUT2 Volume */ | ||
660 | 0x02E4, /* R107 - ROUT2 Volume */ | ||
661 | 0x0000, /* R108 */ | ||
662 | 0x0000, /* R109 */ | ||
663 | 0x0000, /* R110 */ | ||
664 | 0x0000, /* R111 - BEEP Volume */ | ||
665 | 0x0A00, /* R112 - AI Formating */ | ||
666 | 0x0000, /* R113 - ADC DAC COMP */ | ||
667 | 0x0020, /* R114 - AI ADC Control */ | ||
668 | 0x0020, /* R115 - AI DAC Control */ | ||
669 | 0x0000, /* R116 - AIF Test */ | ||
670 | 0x0000, /* R117 */ | ||
671 | 0x0000, /* R118 */ | ||
672 | 0x0000, /* R119 */ | ||
673 | 0x0000, /* R120 */ | ||
674 | 0x0000, /* R121 */ | ||
675 | 0x0000, /* R122 */ | ||
676 | 0x0000, /* R123 */ | ||
677 | 0x0000, /* R124 */ | ||
678 | 0x0000, /* R125 */ | ||
679 | 0x0000, /* R126 */ | ||
680 | 0x0000, /* R127 */ | ||
681 | 0x1FFF, /* R128 - GPIO Debounce */ | ||
682 | 0x0000, /* R129 - GPIO Pin pull up Control */ | ||
683 | 0x03FC, /* R130 - GPIO Pull down Control */ | ||
684 | 0x0000, /* R131 - GPIO Interrupt Mode */ | ||
685 | 0x0000, /* R132 */ | ||
686 | 0x0000, /* R133 - GPIO Control */ | ||
687 | 0x08FB, /* R134 - GPIO Configuration (i/o) */ | ||
688 | 0x0CFE, /* R135 - GPIO Pin Polarity / Type */ | ||
689 | 0x0000, /* R136 */ | ||
690 | 0x0000, /* R137 */ | ||
691 | 0x0000, /* R138 */ | ||
692 | 0x0000, /* R139 */ | ||
693 | 0x0312, /* R140 - GPIO Function Select 1 */ | ||
694 | 0x0003, /* R141 - GPIO Function Select 2 */ | ||
695 | 0x2331, /* R142 - GPIO Function Select 3 */ | ||
696 | 0x0003, /* R143 - GPIO Function Select 4 */ | ||
697 | 0x0000, /* R144 - Digitiser Control (1) */ | ||
698 | 0x0002, /* R145 - Digitiser Control (2) */ | ||
699 | 0x0000, /* R146 */ | ||
700 | 0x0000, /* R147 */ | ||
701 | 0x0000, /* R148 */ | ||
702 | 0x0000, /* R149 */ | ||
703 | 0x0000, /* R150 */ | ||
704 | 0x0000, /* R151 */ | ||
705 | 0x7000, /* R152 - AUX1 Readback */ | ||
706 | 0x7000, /* R153 - AUX2 Readback */ | ||
707 | 0x7000, /* R154 - AUX3 Readback */ | ||
708 | 0x7000, /* R155 - AUX4 Readback */ | ||
709 | 0x0000, /* R156 - USB Voltage Readback */ | ||
710 | 0x0000, /* R157 - LINE Voltage Readback */ | ||
711 | 0x0000, /* R158 - BATT Voltage Readback */ | ||
712 | 0x0000, /* R159 - Chip Temp Readback */ | ||
713 | 0x0000, /* R160 */ | ||
714 | 0x0000, /* R161 */ | ||
715 | 0x0000, /* R162 */ | ||
716 | 0x0000, /* R163 - Generic Comparator Control */ | ||
717 | 0x0000, /* R164 - Generic comparator 1 */ | ||
718 | 0x0000, /* R165 - Generic comparator 2 */ | ||
719 | 0x0000, /* R166 - Generic comparator 3 */ | ||
720 | 0x0000, /* R167 - Generic comparator 4 */ | ||
721 | 0xA00F, /* R168 - Battery Charger Control 1 */ | ||
722 | 0x0B06, /* R169 - Battery Charger Control 2 */ | ||
723 | 0x0000, /* R170 - Battery Charger Control 3 */ | ||
724 | 0x0000, /* R171 */ | ||
725 | 0x0000, /* R172 - Current Sink Driver A */ | ||
726 | 0x0000, /* R173 - CSA Flash control */ | ||
727 | 0x0000, /* R174 - Current Sink Driver B */ | ||
728 | 0x0000, /* R175 - CSB Flash control */ | ||
729 | 0x0000, /* R176 - DCDC/LDO requested */ | ||
730 | 0x002D, /* R177 - DCDC Active options */ | ||
731 | 0x0000, /* R178 - DCDC Sleep options */ | ||
732 | 0x0025, /* R179 - Power-check comparator */ | ||
733 | 0x000E, /* R180 - DCDC1 Control */ | ||
734 | 0x0400, /* R181 - DCDC1 Timeouts */ | ||
735 | 0x1006, /* R182 - DCDC1 Low Power */ | ||
736 | 0x0018, /* R183 - DCDC2 Control */ | ||
737 | 0x0000, /* R184 - DCDC2 Timeouts */ | ||
738 | 0x0000, /* R185 */ | ||
739 | 0x002E, /* R186 - DCDC3 Control */ | ||
740 | 0x0800, /* R187 - DCDC3 Timeouts */ | ||
741 | 0x0006, /* R188 - DCDC3 Low Power */ | ||
742 | 0x000E, /* R189 - DCDC4 Control */ | ||
743 | 0x0800, /* R190 - DCDC4 Timeouts */ | ||
744 | 0x0006, /* R191 - DCDC4 Low Power */ | ||
745 | 0x0008, /* R192 - DCDC5 Control */ | ||
746 | 0x0000, /* R193 - DCDC5 Timeouts */ | ||
747 | 0x0000, /* R194 */ | ||
748 | 0x0026, /* R195 - DCDC6 Control */ | ||
749 | 0x0C00, /* R196 - DCDC6 Timeouts */ | ||
750 | 0x0006, /* R197 - DCDC6 Low Power */ | ||
751 | 0x0000, /* R198 */ | ||
752 | 0x0003, /* R199 - Limit Switch Control */ | ||
753 | 0x001A, /* R200 - LDO1 Control */ | ||
754 | 0x0800, /* R201 - LDO1 Timeouts */ | ||
755 | 0x001C, /* R202 - LDO1 Low Power */ | ||
756 | 0x0010, /* R203 - LDO2 Control */ | ||
757 | 0x0800, /* R204 - LDO2 Timeouts */ | ||
758 | 0x001C, /* R205 - LDO2 Low Power */ | ||
759 | 0x000A, /* R206 - LDO3 Control */ | ||
760 | 0x0C00, /* R207 - LDO3 Timeouts */ | ||
761 | 0x001C, /* R208 - LDO3 Low Power */ | ||
762 | 0x001A, /* R209 - LDO4 Control */ | ||
763 | 0x0800, /* R210 - LDO4 Timeouts */ | ||
764 | 0x001C, /* R211 - LDO4 Low Power */ | ||
765 | 0x0000, /* R212 */ | ||
766 | 0x0000, /* R213 */ | ||
767 | 0x0000, /* R214 */ | ||
768 | 0x0000, /* R215 - VCC_FAULT Masks */ | ||
769 | 0x001F, /* R216 - Main Bandgap Control */ | ||
770 | 0x0000, /* R217 - OSC Control */ | ||
771 | 0x9000, /* R218 - RTC Tick Control */ | ||
772 | 0x0000, /* R219 */ | ||
773 | 0x4000, /* R220 - RAM BIST 1 */ | ||
774 | 0x0000, /* R221 */ | ||
775 | 0x0000, /* R222 */ | ||
776 | 0x0000, /* R223 */ | ||
777 | 0x0000, /* R224 */ | ||
778 | 0x0000, /* R225 - DCDC/LDO status */ | ||
779 | 0x0000, /* R226 */ | ||
780 | 0x0000, /* R227 */ | ||
781 | 0x0000, /* R228 */ | ||
782 | 0x0000, /* R229 */ | ||
783 | 0xE000, /* R230 - GPIO Pin Status */ | ||
784 | 0x0000, /* R231 */ | ||
785 | 0x0000, /* R232 */ | ||
786 | 0x0000, /* R233 */ | ||
787 | 0x0000, /* R234 */ | ||
788 | 0x0000, /* R235 */ | ||
789 | 0x0000, /* R236 */ | ||
790 | 0x0000, /* R237 */ | ||
791 | 0x0000, /* R238 */ | ||
792 | 0x0000, /* R239 */ | ||
793 | 0x0000, /* R240 */ | ||
794 | 0x0000, /* R241 */ | ||
795 | 0x0000, /* R242 */ | ||
796 | 0x0000, /* R243 */ | ||
797 | 0x0000, /* R244 */ | ||
798 | 0x0000, /* R245 */ | ||
799 | 0x0000, /* R246 */ | ||
800 | 0x0000, /* R247 */ | ||
801 | 0x0000, /* R248 */ | ||
802 | 0x0000, /* R249 */ | ||
803 | 0x0000, /* R250 */ | ||
804 | 0x0000, /* R251 */ | ||
805 | 0x0000, /* R252 */ | ||
806 | 0x0000, /* R253 */ | ||
807 | 0x0000, /* R254 */ | ||
808 | 0x0000, /* R255 */ | ||
809 | }; | ||
810 | #endif | ||
811 | |||
812 | #ifdef CONFIG_MFD_WM8350_CONFIG_MODE_3 | ||
813 | |||
814 | #undef WM8350_HAVE_CONFIG_MODE | ||
815 | #define WM8350_HAVE_CONFIG_MODE | ||
816 | |||
817 | const u16 wm8350_mode3_defaults[] = { | ||
818 | 0x17FF, /* R0 - Reset/ID */ | ||
819 | 0x1000, /* R1 - ID */ | ||
820 | 0x0000, /* R2 */ | ||
821 | 0x1000, /* R3 - System Control 1 */ | ||
822 | 0x0004, /* R4 - System Control 2 */ | ||
823 | 0x0000, /* R5 - System Hibernate */ | ||
824 | 0x8A00, /* R6 - Interface Control */ | ||
825 | 0x0000, /* R7 */ | ||
826 | 0x8000, /* R8 - Power mgmt (1) */ | ||
827 | 0x0000, /* R9 - Power mgmt (2) */ | ||
828 | 0x0000, /* R10 - Power mgmt (3) */ | ||
829 | 0x2000, /* R11 - Power mgmt (4) */ | ||
830 | 0x0E00, /* R12 - Power mgmt (5) */ | ||
831 | 0x0000, /* R13 - Power mgmt (6) */ | ||
832 | 0x0000, /* R14 - Power mgmt (7) */ | ||
833 | 0x0000, /* R15 */ | ||
834 | 0x0000, /* R16 - RTC Seconds/Minutes */ | ||
835 | 0x0100, /* R17 - RTC Hours/Day */ | ||
836 | 0x0101, /* R18 - RTC Date/Month */ | ||
837 | 0x1400, /* R19 - RTC Year */ | ||
838 | 0x0000, /* R20 - Alarm Seconds/Minutes */ | ||
839 | 0x0000, /* R21 - Alarm Hours/Day */ | ||
840 | 0x0000, /* R22 - Alarm Date/Month */ | ||
841 | 0x0320, /* R23 - RTC Time Control */ | ||
842 | 0x0000, /* R24 - System Interrupts */ | ||
843 | 0x0000, /* R25 - Interrupt Status 1 */ | ||
844 | 0x0000, /* R26 - Interrupt Status 2 */ | ||
845 | 0x0000, /* R27 - Power Up Interrupt Status */ | ||
846 | 0x0000, /* R28 - Under Voltage Interrupt status */ | ||
847 | 0x0000, /* R29 - Over Current Interrupt status */ | ||
848 | 0x0000, /* R30 - GPIO Interrupt Status */ | ||
849 | 0x0000, /* R31 - Comparator Interrupt Status */ | ||
850 | 0x3FFF, /* R32 - System Interrupts Mask */ | ||
851 | 0x0000, /* R33 - Interrupt Status 1 Mask */ | ||
852 | 0x0000, /* R34 - Interrupt Status 2 Mask */ | ||
853 | 0x0000, /* R35 - Power Up Interrupt Status Mask */ | ||
854 | 0x0000, /* R36 - Under Voltage Interrupt status Mask */ | ||
855 | 0x0000, /* R37 - Over Current Interrupt status Mask */ | ||
856 | 0x0000, /* R38 - GPIO Interrupt Status Mask */ | ||
857 | 0x0000, /* R39 - Comparator Interrupt Status Mask */ | ||
858 | 0x0040, /* R40 - Clock Control 1 */ | ||
859 | 0x0000, /* R41 - Clock Control 2 */ | ||
860 | 0x3B00, /* R42 - FLL Control 1 */ | ||
861 | 0x7086, /* R43 - FLL Control 2 */ | ||
862 | 0xC226, /* R44 - FLL Control 3 */ | ||
863 | 0x0000, /* R45 - FLL Control 4 */ | ||
864 | 0x0000, /* R46 */ | ||
865 | 0x0000, /* R47 */ | ||
866 | 0x0000, /* R48 - DAC Control */ | ||
867 | 0x0000, /* R49 */ | ||
868 | 0x00C0, /* R50 - DAC Digital Volume L */ | ||
869 | 0x00C0, /* R51 - DAC Digital Volume R */ | ||
870 | 0x0000, /* R52 */ | ||
871 | 0x0040, /* R53 - DAC LR Rate */ | ||
872 | 0x0000, /* R54 - DAC Clock Control */ | ||
873 | 0x0000, /* R55 */ | ||
874 | 0x0000, /* R56 */ | ||
875 | 0x0000, /* R57 */ | ||
876 | 0x4000, /* R58 - DAC Mute */ | ||
877 | 0x0000, /* R59 - DAC Mute Volume */ | ||
878 | 0x0000, /* R60 - DAC Side */ | ||
879 | 0x0000, /* R61 */ | ||
880 | 0x0000, /* R62 */ | ||
881 | 0x0000, /* R63 */ | ||
882 | 0x8000, /* R64 - ADC Control */ | ||
883 | 0x0000, /* R65 */ | ||
884 | 0x00C0, /* R66 - ADC Digital Volume L */ | ||
885 | 0x00C0, /* R67 - ADC Digital Volume R */ | ||
886 | 0x0000, /* R68 - ADC Divider */ | ||
887 | 0x0000, /* R69 */ | ||
888 | 0x0040, /* R70 - ADC LR Rate */ | ||
889 | 0x0000, /* R71 */ | ||
890 | 0x0303, /* R72 - Input Control */ | ||
891 | 0x0000, /* R73 - IN3 Input Control */ | ||
892 | 0x0000, /* R74 - Mic Bias Control */ | ||
893 | 0x0000, /* R75 */ | ||
894 | 0x0000, /* R76 - Output Control */ | ||
895 | 0x0000, /* R77 - Jack Detect */ | ||
896 | 0x0000, /* R78 - Anti Pop Control */ | ||
897 | 0x0000, /* R79 */ | ||
898 | 0x0040, /* R80 - Left Input Volume */ | ||
899 | 0x0040, /* R81 - Right Input Volume */ | ||
900 | 0x0000, /* R82 */ | ||
901 | 0x0000, /* R83 */ | ||
902 | 0x0000, /* R84 */ | ||
903 | 0x0000, /* R85 */ | ||
904 | 0x0000, /* R86 */ | ||
905 | 0x0000, /* R87 */ | ||
906 | 0x0800, /* R88 - Left Mixer Control */ | ||
907 | 0x1000, /* R89 - Right Mixer Control */ | ||
908 | 0x0000, /* R90 */ | ||
909 | 0x0000, /* R91 */ | ||
910 | 0x0000, /* R92 - OUT3 Mixer Control */ | ||
911 | 0x0000, /* R93 - OUT4 Mixer Control */ | ||
912 | 0x0000, /* R94 */ | ||
913 | 0x0000, /* R95 */ | ||
914 | 0x0000, /* R96 - Output Left Mixer Volume */ | ||
915 | 0x0000, /* R97 - Output Right Mixer Volume */ | ||
916 | 0x0000, /* R98 - Input Mixer Volume L */ | ||
917 | 0x0000, /* R99 - Input Mixer Volume R */ | ||
918 | 0x0000, /* R100 - Input Mixer Volume */ | ||
919 | 0x0000, /* R101 */ | ||
920 | 0x0000, /* R102 */ | ||
921 | 0x0000, /* R103 */ | ||
922 | 0x00E4, /* R104 - LOUT1 Volume */ | ||
923 | 0x00E4, /* R105 - ROUT1 Volume */ | ||
924 | 0x00E4, /* R106 - LOUT2 Volume */ | ||
925 | 0x02E4, /* R107 - ROUT2 Volume */ | ||
926 | 0x0000, /* R108 */ | ||
927 | 0x0000, /* R109 */ | ||
928 | 0x0000, /* R110 */ | ||
929 | 0x0000, /* R111 - BEEP Volume */ | ||
930 | 0x0A00, /* R112 - AI Formating */ | ||
931 | 0x0000, /* R113 - ADC DAC COMP */ | ||
932 | 0x0020, /* R114 - AI ADC Control */ | ||
933 | 0x0020, /* R115 - AI DAC Control */ | ||
934 | 0x0000, /* R116 - AIF Test */ | ||
935 | 0x0000, /* R117 */ | ||
936 | 0x0000, /* R118 */ | ||
937 | 0x0000, /* R119 */ | ||
938 | 0x0000, /* R120 */ | ||
939 | 0x0000, /* R121 */ | ||
940 | 0x0000, /* R122 */ | ||
941 | 0x0000, /* R123 */ | ||
942 | 0x0000, /* R124 */ | ||
943 | 0x0000, /* R125 */ | ||
944 | 0x0000, /* R126 */ | ||
945 | 0x0000, /* R127 */ | ||
946 | 0x1FFF, /* R128 - GPIO Debounce */ | ||
947 | 0x0000, /* R129 - GPIO Pin pull up Control */ | ||
948 | 0x03FC, /* R130 - GPIO Pull down Control */ | ||
949 | 0x0000, /* R131 - GPIO Interrupt Mode */ | ||
950 | 0x0000, /* R132 */ | ||
951 | 0x0000, /* R133 - GPIO Control */ | ||
952 | 0x0A7B, /* R134 - GPIO Configuration (i/o) */ | ||
953 | 0x06FE, /* R135 - GPIO Pin Polarity / Type */ | ||
954 | 0x0000, /* R136 */ | ||
955 | 0x0000, /* R137 */ | ||
956 | 0x0000, /* R138 */ | ||
957 | 0x0000, /* R139 */ | ||
958 | 0x1312, /* R140 - GPIO Function Select 1 */ | ||
959 | 0x1030, /* R141 - GPIO Function Select 2 */ | ||
960 | 0x2231, /* R142 - GPIO Function Select 3 */ | ||
961 | 0x0003, /* R143 - GPIO Function Select 4 */ | ||
962 | 0x0000, /* R144 - Digitiser Control (1) */ | ||
963 | 0x0002, /* R145 - Digitiser Control (2) */ | ||
964 | 0x0000, /* R146 */ | ||
965 | 0x0000, /* R147 */ | ||
966 | 0x0000, /* R148 */ | ||
967 | 0x0000, /* R149 */ | ||
968 | 0x0000, /* R150 */ | ||
969 | 0x0000, /* R151 */ | ||
970 | 0x7000, /* R152 - AUX1 Readback */ | ||
971 | 0x7000, /* R153 - AUX2 Readback */ | ||
972 | 0x7000, /* R154 - AUX3 Readback */ | ||
973 | 0x7000, /* R155 - AUX4 Readback */ | ||
974 | 0x0000, /* R156 - USB Voltage Readback */ | ||
975 | 0x0000, /* R157 - LINE Voltage Readback */ | ||
976 | 0x0000, /* R158 - BATT Voltage Readback */ | ||
977 | 0x0000, /* R159 - Chip Temp Readback */ | ||
978 | 0x0000, /* R160 */ | ||
979 | 0x0000, /* R161 */ | ||
980 | 0x0000, /* R162 */ | ||
981 | 0x0000, /* R163 - Generic Comparator Control */ | ||
982 | 0x0000, /* R164 - Generic comparator 1 */ | ||
983 | 0x0000, /* R165 - Generic comparator 2 */ | ||
984 | 0x0000, /* R166 - Generic comparator 3 */ | ||
985 | 0x0000, /* R167 - Generic comparator 4 */ | ||
986 | 0xA00F, /* R168 - Battery Charger Control 1 */ | ||
987 | 0x0B06, /* R169 - Battery Charger Control 2 */ | ||
988 | 0x0000, /* R170 - Battery Charger Control 3 */ | ||
989 | 0x0000, /* R171 */ | ||
990 | 0x0000, /* R172 - Current Sink Driver A */ | ||
991 | 0x0000, /* R173 - CSA Flash control */ | ||
992 | 0x0000, /* R174 - Current Sink Driver B */ | ||
993 | 0x0000, /* R175 - CSB Flash control */ | ||
994 | 0x0000, /* R176 - DCDC/LDO requested */ | ||
995 | 0x002D, /* R177 - DCDC Active options */ | ||
996 | 0x0000, /* R178 - DCDC Sleep options */ | ||
997 | 0x0025, /* R179 - Power-check comparator */ | ||
998 | 0x000E, /* R180 - DCDC1 Control */ | ||
999 | 0x0400, /* R181 - DCDC1 Timeouts */ | ||
1000 | 0x1006, /* R182 - DCDC1 Low Power */ | ||
1001 | 0x0018, /* R183 - DCDC2 Control */ | ||
1002 | 0x0000, /* R184 - DCDC2 Timeouts */ | ||
1003 | 0x0000, /* R185 */ | ||
1004 | 0x000E, /* R186 - DCDC3 Control */ | ||
1005 | 0x0400, /* R187 - DCDC3 Timeouts */ | ||
1006 | 0x0006, /* R188 - DCDC3 Low Power */ | ||
1007 | 0x0026, /* R189 - DCDC4 Control */ | ||
1008 | 0x0400, /* R190 - DCDC4 Timeouts */ | ||
1009 | 0x0006, /* R191 - DCDC4 Low Power */ | ||
1010 | 0x0008, /* R192 - DCDC5 Control */ | ||
1011 | 0x0000, /* R193 - DCDC5 Timeouts */ | ||
1012 | 0x0000, /* R194 */ | ||
1013 | 0x0026, /* R195 - DCDC6 Control */ | ||
1014 | 0x0400, /* R196 - DCDC6 Timeouts */ | ||
1015 | 0x0006, /* R197 - DCDC6 Low Power */ | ||
1016 | 0x0000, /* R198 */ | ||
1017 | 0x0003, /* R199 - Limit Switch Control */ | ||
1018 | 0x001C, /* R200 - LDO1 Control */ | ||
1019 | 0x0000, /* R201 - LDO1 Timeouts */ | ||
1020 | 0x001C, /* R202 - LDO1 Low Power */ | ||
1021 | 0x001C, /* R203 - LDO2 Control */ | ||
1022 | 0x0400, /* R204 - LDO2 Timeouts */ | ||
1023 | 0x001C, /* R205 - LDO2 Low Power */ | ||
1024 | 0x001C, /* R206 - LDO3 Control */ | ||
1025 | 0x0400, /* R207 - LDO3 Timeouts */ | ||
1026 | 0x001C, /* R208 - LDO3 Low Power */ | ||
1027 | 0x001F, /* R209 - LDO4 Control */ | ||
1028 | 0x0400, /* R210 - LDO4 Timeouts */ | ||
1029 | 0x001C, /* R211 - LDO4 Low Power */ | ||
1030 | 0x0000, /* R212 */ | ||
1031 | 0x0000, /* R213 */ | ||
1032 | 0x0000, /* R214 */ | ||
1033 | 0x0000, /* R215 - VCC_FAULT Masks */ | ||
1034 | 0x001F, /* R216 - Main Bandgap Control */ | ||
1035 | 0x0000, /* R217 - OSC Control */ | ||
1036 | 0x9000, /* R218 - RTC Tick Control */ | ||
1037 | 0x0000, /* R219 */ | ||
1038 | 0x4000, /* R220 - RAM BIST 1 */ | ||
1039 | 0x0000, /* R221 */ | ||
1040 | 0x0000, /* R222 */ | ||
1041 | 0x0000, /* R223 */ | ||
1042 | 0x0000, /* R224 */ | ||
1043 | 0x0000, /* R225 - DCDC/LDO status */ | ||
1044 | 0x0000, /* R226 */ | ||
1045 | 0x0000, /* R227 */ | ||
1046 | 0x0000, /* R228 */ | ||
1047 | 0x0000, /* R229 */ | ||
1048 | 0xE000, /* R230 - GPIO Pin Status */ | ||
1049 | 0x0000, /* R231 */ | ||
1050 | 0x0000, /* R232 */ | ||
1051 | 0x0000, /* R233 */ | ||
1052 | 0x0000, /* R234 */ | ||
1053 | 0x0000, /* R235 */ | ||
1054 | 0x0000, /* R236 */ | ||
1055 | 0x0000, /* R237 */ | ||
1056 | 0x0000, /* R238 */ | ||
1057 | 0x0000, /* R239 */ | ||
1058 | 0x0000, /* R240 */ | ||
1059 | 0x0000, /* R241 */ | ||
1060 | 0x0000, /* R242 */ | ||
1061 | 0x0000, /* R243 */ | ||
1062 | 0x0000, /* R244 */ | ||
1063 | 0x0000, /* R245 */ | ||
1064 | 0x0000, /* R246 */ | ||
1065 | 0x0000, /* R247 */ | ||
1066 | 0x0000, /* R248 */ | ||
1067 | 0x0000, /* R249 */ | ||
1068 | 0x0000, /* R250 */ | ||
1069 | 0x0000, /* R251 */ | ||
1070 | 0x0000, /* R252 */ | ||
1071 | 0x0000, /* R253 */ | ||
1072 | 0x0000, /* R254 */ | ||
1073 | 0x0000, /* R255 */ | ||
1074 | }; | ||
1075 | #endif | ||
1076 | |||
1077 | /* The register defaults for the config mode used must be compiled in but | ||
1078 | * due to the impact on kernel size it is possible to disable | ||
1079 | */ | ||
1080 | #ifndef WM8350_HAVE_CONFIG_MODE | ||
1081 | #warning No WM8350 config modes supported - select at least one of the | ||
1082 | #warning MFD_WM8350_CONFIG_MODE_n options from the board driver. | ||
1083 | #endif | ||
1084 | |||
1085 | /* | ||
1086 | * Access masks. | ||
1087 | */ | ||
1088 | |||
1089 | const struct wm8350_reg_access wm8350_reg_io_map[] = { | ||
1090 | /* read write volatile */ | ||
1091 | { 0xFFFF, 0xFFFF, 0xFFFF }, /* R0 - Reset/ID */ | ||
1092 | { 0x7CFF, 0x0C00, 0x7FFF }, /* R1 - ID */ | ||
1093 | { 0x0000, 0x0000, 0x0000 }, /* R2 */ | ||
1094 | { 0xBE3B, 0xBE3B, 0x8000 }, /* R3 - System Control 1 */ | ||
1095 | { 0xFCF7, 0xFCF7, 0xF800 }, /* R4 - System Control 2 */ | ||
1096 | { 0x80FF, 0x80FF, 0x8000 }, /* R5 - System Hibernate */ | ||
1097 | { 0xFB0E, 0xFB0E, 0x0000 }, /* R6 - Interface Control */ | ||
1098 | { 0x0000, 0x0000, 0x0000 }, /* R7 */ | ||
1099 | { 0xE537, 0xE537, 0xFFFF }, /* R8 - Power mgmt (1) */ | ||
1100 | { 0x0FF3, 0x0FF3, 0xFFFF }, /* R9 - Power mgmt (2) */ | ||
1101 | { 0x008F, 0x008F, 0xFFFF }, /* R10 - Power mgmt (3) */ | ||
1102 | { 0x6D3C, 0x6D3C, 0xFFFF }, /* R11 - Power mgmt (4) */ | ||
1103 | { 0x1F8F, 0x1F8F, 0xFFFF }, /* R12 - Power mgmt (5) */ | ||
1104 | { 0x8F3F, 0x8F3F, 0xFFFF }, /* R13 - Power mgmt (6) */ | ||
1105 | { 0x0003, 0x0003, 0xFFFF }, /* R14 - Power mgmt (7) */ | ||
1106 | { 0x0000, 0x0000, 0x0000 }, /* R15 */ | ||
1107 | { 0x7F7F, 0x7F7F, 0xFFFF }, /* R16 - RTC Seconds/Minutes */ | ||
1108 | { 0x073F, 0x073F, 0xFFFF }, /* R17 - RTC Hours/Day */ | ||
1109 | { 0x1F3F, 0x1F3F, 0xFFFF }, /* R18 - RTC Date/Month */ | ||
1110 | { 0x3FFF, 0x00FF, 0xFFFF }, /* R19 - RTC Year */ | ||
1111 | { 0x7F7F, 0x7F7F, 0x0000 }, /* R20 - Alarm Seconds/Minutes */ | ||
1112 | { 0x0F3F, 0x0F3F, 0x0000 }, /* R21 - Alarm Hours/Day */ | ||
1113 | { 0x1F3F, 0x1F3F, 0x0000 }, /* R22 - Alarm Date/Month */ | ||
1114 | { 0xEF7F, 0xEA7F, 0xFFFF }, /* R23 - RTC Time Control */ | ||
1115 | { 0x3BFF, 0x0000, 0xFFFF }, /* R24 - System Interrupts */ | ||
1116 | { 0xFEE7, 0x0000, 0xFFFF }, /* R25 - Interrupt Status 1 */ | ||
1117 | { 0x35FF, 0x0000, 0xFFFF }, /* R26 - Interrupt Status 2 */ | ||
1118 | { 0x0F3F, 0x0000, 0xFFFF }, /* R27 - Power Up Interrupt Status */ | ||
1119 | { 0x0F3F, 0x0000, 0xFFFF }, /* R28 - Under Voltage Interrupt status */ | ||
1120 | { 0x8000, 0x0000, 0xFFFF }, /* R29 - Over Current Interrupt status */ | ||
1121 | { 0x1FFF, 0x0000, 0xFFFF }, /* R30 - GPIO Interrupt Status */ | ||
1122 | { 0xEF7F, 0x0000, 0xFFFF }, /* R31 - Comparator Interrupt Status */ | ||
1123 | { 0x3FFF, 0x3FFF, 0x0000 }, /* R32 - System Interrupts Mask */ | ||
1124 | { 0xFEE7, 0xFEE7, 0x0000 }, /* R33 - Interrupt Status 1 Mask */ | ||
1125 | { 0xF5FF, 0xF5FF, 0x0000 }, /* R34 - Interrupt Status 2 Mask */ | ||
1126 | { 0x0F3F, 0x0F3F, 0x0000 }, /* R35 - Power Up Interrupt Status Mask */ | ||
1127 | { 0x0F3F, 0x0F3F, 0x0000 }, /* R36 - Under Voltage Int status Mask */ | ||
1128 | { 0x8000, 0x8000, 0x0000 }, /* R37 - Over Current Int status Mask */ | ||
1129 | { 0x1FFF, 0x1FFF, 0x0000 }, /* R38 - GPIO Interrupt Status Mask */ | ||
1130 | { 0xEF7F, 0xEF7F, 0x0000 }, /* R39 - Comparator IntStatus Mask */ | ||
1131 | { 0xC9F7, 0xC9F7, 0xFFFF }, /* R40 - Clock Control 1 */ | ||
1132 | { 0x8001, 0x8001, 0x0000 }, /* R41 - Clock Control 2 */ | ||
1133 | { 0xFFF7, 0xFFF7, 0xFFFF }, /* R42 - FLL Control 1 */ | ||
1134 | { 0xFBFF, 0xFBFF, 0x0000 }, /* R43 - FLL Control 2 */ | ||
1135 | { 0xFFFF, 0xFFFF, 0x0000 }, /* R44 - FLL Control 3 */ | ||
1136 | { 0x0033, 0x0033, 0x0000 }, /* R45 - FLL Control 4 */ | ||
1137 | { 0x0000, 0x0000, 0x0000 }, /* R46 */ | ||
1138 | { 0x0000, 0x0000, 0x0000 }, /* R47 */ | ||
1139 | { 0x3033, 0x3033, 0x0000 }, /* R48 - DAC Control */ | ||
1140 | { 0x0000, 0x0000, 0x0000 }, /* R49 */ | ||
1141 | { 0x81FF, 0x81FF, 0xFFFF }, /* R50 - DAC Digital Volume L */ | ||
1142 | { 0x81FF, 0x81FF, 0xFFFF }, /* R51 - DAC Digital Volume R */ | ||
1143 | { 0x0000, 0x0000, 0x0000 }, /* R52 */ | ||
1144 | { 0x0FFF, 0x0FFF, 0xFFFF }, /* R53 - DAC LR Rate */ | ||
1145 | { 0x0017, 0x0017, 0x0000 }, /* R54 - DAC Clock Control */ | ||
1146 | { 0x0000, 0x0000, 0x0000 }, /* R55 */ | ||
1147 | { 0x0000, 0x0000, 0x0000 }, /* R56 */ | ||
1148 | { 0x0000, 0x0000, 0x0000 }, /* R57 */ | ||
1149 | { 0x4000, 0x4000, 0x0000 }, /* R58 - DAC Mute */ | ||
1150 | { 0x7000, 0x7000, 0x0000 }, /* R59 - DAC Mute Volume */ | ||
1151 | { 0x3C00, 0x3C00, 0x0000 }, /* R60 - DAC Side */ | ||
1152 | { 0x0000, 0x0000, 0x0000 }, /* R61 */ | ||
1153 | { 0x0000, 0x0000, 0x0000 }, /* R62 */ | ||
1154 | { 0x0000, 0x0000, 0x0000 }, /* R63 */ | ||
1155 | { 0x8303, 0x8303, 0xFFFF }, /* R64 - ADC Control */ | ||
1156 | { 0x0000, 0x0000, 0x0000 }, /* R65 */ | ||
1157 | { 0x81FF, 0x81FF, 0xFFFF }, /* R66 - ADC Digital Volume L */ | ||
1158 | { 0x81FF, 0x81FF, 0xFFFF }, /* R67 - ADC Digital Volume R */ | ||
1159 | { 0x0FFF, 0x0FFF, 0x0000 }, /* R68 - ADC Divider */ | ||
1160 | { 0x0000, 0x0000, 0x0000 }, /* R69 */ | ||
1161 | { 0x0FFF, 0x0FFF, 0xFFFF }, /* R70 - ADC LR Rate */ | ||
1162 | { 0x0000, 0x0000, 0x0000 }, /* R71 */ | ||
1163 | { 0x0707, 0x0707, 0xFFFF }, /* R72 - Input Control */ | ||
1164 | { 0xC0C0, 0xC0C0, 0xFFFF }, /* R73 - IN3 Input Control */ | ||
1165 | { 0xC09F, 0xC09F, 0xFFFF }, /* R74 - Mic Bias Control */ | ||
1166 | { 0x0000, 0x0000, 0x0000 }, /* R75 */ | ||
1167 | { 0x0F15, 0x0F15, 0xFFFF }, /* R76 - Output Control */ | ||
1168 | { 0xC000, 0xC000, 0xFFFF }, /* R77 - Jack Detect */ | ||
1169 | { 0x03FF, 0x03FF, 0x0000 }, /* R78 - Anti Pop Control */ | ||
1170 | { 0x0000, 0x0000, 0x0000 }, /* R79 */ | ||
1171 | { 0xE1FC, 0xE1FC, 0x8000 }, /* R80 - Left Input Volume */ | ||
1172 | { 0xE1FC, 0xE1FC, 0x8000 }, /* R81 - Right Input Volume */ | ||
1173 | { 0x0000, 0x0000, 0x0000 }, /* R82 */ | ||
1174 | { 0x0000, 0x0000, 0x0000 }, /* R83 */ | ||
1175 | { 0x0000, 0x0000, 0x0000 }, /* R84 */ | ||
1176 | { 0x0000, 0x0000, 0x0000 }, /* R85 */ | ||
1177 | { 0x0000, 0x0000, 0x0000 }, /* R86 */ | ||
1178 | { 0x0000, 0x0000, 0x0000 }, /* R87 */ | ||
1179 | { 0x9807, 0x9807, 0xFFFF }, /* R88 - Left Mixer Control */ | ||
1180 | { 0x980B, 0x980B, 0xFFFF }, /* R89 - Right Mixer Control */ | ||
1181 | { 0x0000, 0x0000, 0x0000 }, /* R90 */ | ||
1182 | { 0x0000, 0x0000, 0x0000 }, /* R91 */ | ||
1183 | { 0x8909, 0x8909, 0xFFFF }, /* R92 - OUT3 Mixer Control */ | ||
1184 | { 0x9E07, 0x9E07, 0xFFFF }, /* R93 - OUT4 Mixer Control */ | ||
1185 | { 0x0000, 0x0000, 0x0000 }, /* R94 */ | ||
1186 | { 0x0000, 0x0000, 0x0000 }, /* R95 */ | ||
1187 | { 0x0EEE, 0x0EEE, 0x0000 }, /* R96 - Output Left Mixer Volume */ | ||
1188 | { 0xE0EE, 0xE0EE, 0x0000 }, /* R97 - Output Right Mixer Volume */ | ||
1189 | { 0x0E0F, 0x0E0F, 0x0000 }, /* R98 - Input Mixer Volume L */ | ||
1190 | { 0xE0E1, 0xE0E1, 0x0000 }, /* R99 - Input Mixer Volume R */ | ||
1191 | { 0x800E, 0x800E, 0x0000 }, /* R100 - Input Mixer Volume */ | ||
1192 | { 0x0000, 0x0000, 0x0000 }, /* R101 */ | ||
1193 | { 0x0000, 0x0000, 0x0000 }, /* R102 */ | ||
1194 | { 0x0000, 0x0000, 0x0000 }, /* R103 */ | ||
1195 | { 0xE1FC, 0xE1FC, 0xFFFF }, /* R104 - LOUT1 Volume */ | ||
1196 | { 0xE1FC, 0xE1FC, 0xFFFF }, /* R105 - ROUT1 Volume */ | ||
1197 | { 0xE1FC, 0xE1FC, 0xFFFF }, /* R106 - LOUT2 Volume */ | ||
1198 | { 0xE7FC, 0xE7FC, 0xFFFF }, /* R107 - ROUT2 Volume */ | ||
1199 | { 0x0000, 0x0000, 0x0000 }, /* R108 */ | ||
1200 | { 0x0000, 0x0000, 0x0000 }, /* R109 */ | ||
1201 | { 0x0000, 0x0000, 0x0000 }, /* R110 */ | ||
1202 | { 0x80E0, 0x80E0, 0xFFFF }, /* R111 - BEEP Volume */ | ||
1203 | { 0xBF00, 0xBF00, 0x0000 }, /* R112 - AI Formating */ | ||
1204 | { 0x00F1, 0x00F1, 0x0000 }, /* R113 - ADC DAC COMP */ | ||
1205 | { 0x00F8, 0x00F8, 0x0000 }, /* R114 - AI ADC Control */ | ||
1206 | { 0x40FB, 0x40FB, 0x0000 }, /* R115 - AI DAC Control */ | ||
1207 | { 0x7C30, 0x7C30, 0x0000 }, /* R116 - AIF Test */ | ||
1208 | { 0x0000, 0x0000, 0x0000 }, /* R117 */ | ||
1209 | { 0x0000, 0x0000, 0x0000 }, /* R118 */ | ||
1210 | { 0x0000, 0x0000, 0x0000 }, /* R119 */ | ||
1211 | { 0x0000, 0x0000, 0x0000 }, /* R120 */ | ||
1212 | { 0x0000, 0x0000, 0x0000 }, /* R121 */ | ||
1213 | { 0x0000, 0x0000, 0x0000 }, /* R122 */ | ||
1214 | { 0x0000, 0x0000, 0x0000 }, /* R123 */ | ||
1215 | { 0x0000, 0x0000, 0x0000 }, /* R124 */ | ||
1216 | { 0x0000, 0x0000, 0x0000 }, /* R125 */ | ||
1217 | { 0x0000, 0x0000, 0x0000 }, /* R126 */ | ||
1218 | { 0x0000, 0x0000, 0x0000 }, /* R127 */ | ||
1219 | { 0x1FFF, 0x1FFF, 0x0000 }, /* R128 - GPIO Debounce */ | ||
1220 | { 0x1FFF, 0x1FFF, 0x0000 }, /* R129 - GPIO Pin pull up Control */ | ||
1221 | { 0x1FFF, 0x1FFF, 0x0000 }, /* R130 - GPIO Pull down Control */ | ||
1222 | { 0x1FFF, 0x1FFF, 0x0000 }, /* R131 - GPIO Interrupt Mode */ | ||
1223 | { 0x0000, 0x0000, 0x0000 }, /* R132 */ | ||
1224 | { 0x00C0, 0x00C0, 0x0000 }, /* R133 - GPIO Control */ | ||
1225 | { 0x1FFF, 0x1FFF, 0x0000 }, /* R134 - GPIO Configuration (i/o) */ | ||
1226 | { 0x1FFF, 0x1FFF, 0x0000 }, /* R135 - GPIO Pin Polarity / Type */ | ||
1227 | { 0x0000, 0x0000, 0x0000 }, /* R136 */ | ||
1228 | { 0x0000, 0x0000, 0x0000 }, /* R137 */ | ||
1229 | { 0x0000, 0x0000, 0x0000 }, /* R138 */ | ||
1230 | { 0x0000, 0x0000, 0x0000 }, /* R139 */ | ||
1231 | { 0xFFFF, 0xFFFF, 0x0000 }, /* R140 - GPIO Function Select 1 */ | ||
1232 | { 0xFFFF, 0xFFFF, 0x0000 }, /* R141 - GPIO Function Select 2 */ | ||
1233 | { 0xFFFF, 0xFFFF, 0x0000 }, /* R142 - GPIO Function Select 3 */ | ||
1234 | { 0x000F, 0x000F, 0x0000 }, /* R143 - GPIO Function Select 4 */ | ||
1235 | { 0xF0FF, 0xF0FF, 0xA000 }, /* R144 - Digitiser Control (1) */ | ||
1236 | { 0x3707, 0x3707, 0x0000 }, /* R145 - Digitiser Control (2) */ | ||
1237 | { 0x0000, 0x0000, 0x0000 }, /* R146 */ | ||
1238 | { 0x0000, 0x0000, 0x0000 }, /* R147 */ | ||
1239 | { 0x0000, 0x0000, 0x0000 }, /* R148 */ | ||
1240 | { 0x0000, 0x0000, 0x0000 }, /* R149 */ | ||
1241 | { 0x0000, 0x0000, 0x0000 }, /* R150 */ | ||
1242 | { 0x0000, 0x0000, 0x0000 }, /* R151 */ | ||
1243 | { 0x7FFF, 0x7000, 0xFFFF }, /* R152 - AUX1 Readback */ | ||
1244 | { 0x7FFF, 0x7000, 0xFFFF }, /* R153 - AUX2 Readback */ | ||
1245 | { 0x7FFF, 0x7000, 0xFFFF }, /* R154 - AUX3 Readback */ | ||
1246 | { 0x7FFF, 0x7000, 0xFFFF }, /* R155 - AUX4 Readback */ | ||
1247 | { 0x0FFF, 0x0000, 0xFFFF }, /* R156 - USB Voltage Readback */ | ||
1248 | { 0x0FFF, 0x0000, 0xFFFF }, /* R157 - LINE Voltage Readback */ | ||
1249 | { 0x0FFF, 0x0000, 0xFFFF }, /* R158 - BATT Voltage Readback */ | ||
1250 | { 0x0FFF, 0x0000, 0xFFFF }, /* R159 - Chip Temp Readback */ | ||
1251 | { 0x0000, 0x0000, 0x0000 }, /* R160 */ | ||
1252 | { 0x0000, 0x0000, 0x0000 }, /* R161 */ | ||
1253 | { 0x0000, 0x0000, 0x0000 }, /* R162 */ | ||
1254 | { 0x000F, 0x000F, 0x0000 }, /* R163 - Generic Comparator Control */ | ||
1255 | { 0xFFFF, 0xFFFF, 0x0000 }, /* R164 - Generic comparator 1 */ | ||
1256 | { 0xFFFF, 0xFFFF, 0x0000 }, /* R165 - Generic comparator 2 */ | ||
1257 | { 0xFFFF, 0xFFFF, 0x0000 }, /* R166 - Generic comparator 3 */ | ||
1258 | { 0xFFFF, 0xFFFF, 0x0000 }, /* R167 - Generic comparator 4 */ | ||
1259 | { 0xBFFF, 0xBFFF, 0x8000 }, /* R168 - Battery Charger Control 1 */ | ||
1260 | { 0xFFFF, 0x4FFF, 0xB000 }, /* R169 - Battery Charger Control 2 */ | ||
1261 | { 0x007F, 0x007F, 0x0000 }, /* R170 - Battery Charger Control 3 */ | ||
1262 | { 0x0000, 0x0000, 0x0000 }, /* R171 */ | ||
1263 | { 0x903F, 0x903F, 0xFFFF }, /* R172 - Current Sink Driver A */ | ||
1264 | { 0xE333, 0xE333, 0xFFFF }, /* R173 - CSA Flash control */ | ||
1265 | { 0x903F, 0x903F, 0xFFFF }, /* R174 - Current Sink Driver B */ | ||
1266 | { 0xE333, 0xE333, 0xFFFF }, /* R175 - CSB Flash control */ | ||
1267 | { 0x8F3F, 0x8F3F, 0xFFFF }, /* R176 - DCDC/LDO requested */ | ||
1268 | { 0x332D, 0x332D, 0x0000 }, /* R177 - DCDC Active options */ | ||
1269 | { 0x002D, 0x002D, 0x0000 }, /* R178 - DCDC Sleep options */ | ||
1270 | { 0x5177, 0x5177, 0x8000 }, /* R179 - Power-check comparator */ | ||
1271 | { 0x047F, 0x047F, 0x0000 }, /* R180 - DCDC1 Control */ | ||
1272 | { 0xFFC0, 0xFFC0, 0x0000 }, /* R181 - DCDC1 Timeouts */ | ||
1273 | { 0x737F, 0x737F, 0x0000 }, /* R182 - DCDC1 Low Power */ | ||
1274 | { 0x535B, 0x535B, 0x0000 }, /* R183 - DCDC2 Control */ | ||
1275 | { 0xFFC0, 0xFFC0, 0x0000 }, /* R184 - DCDC2 Timeouts */ | ||
1276 | { 0x0000, 0x0000, 0x0000 }, /* R185 */ | ||
1277 | { 0x047F, 0x047F, 0x0000 }, /* R186 - DCDC3 Control */ | ||
1278 | { 0xFFC0, 0xFFC0, 0x0000 }, /* R187 - DCDC3 Timeouts */ | ||
1279 | { 0x737F, 0x737F, 0x0000 }, /* R188 - DCDC3 Low Power */ | ||
1280 | { 0x047F, 0x047F, 0x0000 }, /* R189 - DCDC4 Control */ | ||
1281 | { 0xFFC0, 0xFFC0, 0x0000 }, /* R190 - DCDC4 Timeouts */ | ||
1282 | { 0x737F, 0x737F, 0x0000 }, /* R191 - DCDC4 Low Power */ | ||
1283 | { 0x535B, 0x535B, 0x0000 }, /* R192 - DCDC5 Control */ | ||
1284 | { 0xFFC0, 0xFFC0, 0x0000 }, /* R193 - DCDC5 Timeouts */ | ||
1285 | { 0x0000, 0x0000, 0x0000 }, /* R194 */ | ||
1286 | { 0x047F, 0x047F, 0x0000 }, /* R195 - DCDC6 Control */ | ||
1287 | { 0xFFC0, 0xFFC0, 0x0000 }, /* R196 - DCDC6 Timeouts */ | ||
1288 | { 0x737F, 0x737F, 0x0000 }, /* R197 - DCDC6 Low Power */ | ||
1289 | { 0x0000, 0x0000, 0x0000 }, /* R198 */ | ||
1290 | { 0xFFD3, 0xFFD3, 0x0000 }, /* R199 - Limit Switch Control */ | ||
1291 | { 0x441F, 0x441F, 0x0000 }, /* R200 - LDO1 Control */ | ||
1292 | { 0xFFC0, 0xFFC0, 0x0000 }, /* R201 - LDO1 Timeouts */ | ||
1293 | { 0x331F, 0x331F, 0x0000 }, /* R202 - LDO1 Low Power */ | ||
1294 | { 0x441F, 0x441F, 0x0000 }, /* R203 - LDO2 Control */ | ||
1295 | { 0xFFC0, 0xFFC0, 0x0000 }, /* R204 - LDO2 Timeouts */ | ||
1296 | { 0x331F, 0x331F, 0x0000 }, /* R205 - LDO2 Low Power */ | ||
1297 | { 0x441F, 0x441F, 0x0000 }, /* R206 - LDO3 Control */ | ||
1298 | { 0xFFC0, 0xFFC0, 0x0000 }, /* R207 - LDO3 Timeouts */ | ||
1299 | { 0x331F, 0x331F, 0x0000 }, /* R208 - LDO3 Low Power */ | ||
1300 | { 0x441F, 0x441F, 0x0000 }, /* R209 - LDO4 Control */ | ||
1301 | { 0xFFC0, 0xFFC0, 0x0000 }, /* R210 - LDO4 Timeouts */ | ||
1302 | { 0x331F, 0x331F, 0x0000 }, /* R211 - LDO4 Low Power */ | ||
1303 | { 0x0000, 0x0000, 0x0000 }, /* R212 */ | ||
1304 | { 0x0000, 0x0000, 0x0000 }, /* R213 */ | ||
1305 | { 0x0000, 0x0000, 0x0000 }, /* R214 */ | ||
1306 | { 0x8F3F, 0x8F3F, 0x0000 }, /* R215 - VCC_FAULT Masks */ | ||
1307 | { 0xFF3F, 0xE03F, 0x0000 }, /* R216 - Main Bandgap Control */ | ||
1308 | { 0xEF2F, 0xE02F, 0x0000 }, /* R217 - OSC Control */ | ||
1309 | { 0xF3FF, 0xB3FF, 0xc000 }, /* R218 - RTC Tick Control */ | ||
1310 | { 0xFFFF, 0xFFFF, 0xFFFF }, /* R219 */ | ||
1311 | { 0x09FF, 0x01FF, 0x0000 }, /* R220 - RAM BIST 1 */ | ||
1312 | { 0x0000, 0x0000, 0x0000 }, /* R221 */ | ||
1313 | { 0xFFFF, 0xFFFF, 0xFFFF }, /* R222 */ | ||
1314 | { 0xFFFF, 0xFFFF, 0xFFFF }, /* R223 */ | ||
1315 | { 0x0000, 0x0000, 0x0000 }, /* R224 */ | ||
1316 | { 0x8F3F, 0x0000, 0xFFFF }, /* R225 - DCDC/LDO status */ | ||
1317 | { 0x0000, 0x0000, 0x0000 }, /* R226 */ | ||
1318 | { 0x0000, 0x0000, 0xFFFF }, /* R227 */ | ||
1319 | { 0x0000, 0x0000, 0x0000 }, /* R228 */ | ||
1320 | { 0x0000, 0x0000, 0x0000 }, /* R229 */ | ||
1321 | { 0xFFFF, 0x1FFF, 0xFFFF }, /* R230 - GPIO Pin Status */ | ||
1322 | { 0xFFFF, 0x1FFF, 0xFFFF }, /* R231 */ | ||
1323 | { 0xFFFF, 0x1FFF, 0xFFFF }, /* R232 */ | ||
1324 | { 0xFFFF, 0x1FFF, 0xFFFF }, /* R233 */ | ||
1325 | { 0x0000, 0x0000, 0x0000 }, /* R234 */ | ||
1326 | { 0x0000, 0x0000, 0x0000 }, /* R235 */ | ||
1327 | { 0x0000, 0x0000, 0x0000 }, /* R236 */ | ||
1328 | { 0x0000, 0x0000, 0x0000 }, /* R237 */ | ||
1329 | { 0x0000, 0x0000, 0x0000 }, /* R238 */ | ||
1330 | { 0x0000, 0x0000, 0x0000 }, /* R239 */ | ||
1331 | { 0x0000, 0x0000, 0x0000 }, /* R240 */ | ||
1332 | { 0x0000, 0x0000, 0x0000 }, /* R241 */ | ||
1333 | { 0x0000, 0x0000, 0x0000 }, /* R242 */ | ||
1334 | { 0x0000, 0x0000, 0x0000 }, /* R243 */ | ||
1335 | { 0x0000, 0x0000, 0x0000 }, /* R244 */ | ||
1336 | { 0x0000, 0x0000, 0x0000 }, /* R245 */ | ||
1337 | { 0x0000, 0x0000, 0x0000 }, /* R246 */ | ||
1338 | { 0x0000, 0x0000, 0x0000 }, /* R247 */ | ||
1339 | { 0xFFFF, 0x0010, 0xFFFF }, /* R248 */ | ||
1340 | { 0x0000, 0x0000, 0x0000 }, /* R249 */ | ||
1341 | { 0xFFFF, 0x0010, 0xFFFF }, /* R250 */ | ||
1342 | { 0xFFFF, 0x0010, 0xFFFF }, /* R251 */ | ||
1343 | { 0x0000, 0x0000, 0x0000 }, /* R252 */ | ||
1344 | { 0xFFFF, 0x0010, 0xFFFF }, /* R253 */ | ||
1345 | { 0x0000, 0x0000, 0x0000 }, /* R254 */ | ||
1346 | { 0x0000, 0x0000, 0x0000 }, /* R255 */ | ||
1347 | }; | ||
diff --git a/drivers/mfd/wm8400-core.c b/drivers/mfd/wm8400-core.c new file mode 100644 index 000000000000..6a0cedb5bb8a --- /dev/null +++ b/drivers/mfd/wm8400-core.c | |||
@@ -0,0 +1,455 @@ | |||
1 | /* | ||
2 | * Core driver for WM8400. | ||
3 | * | ||
4 | * Copyright 2008 Wolfson Microelectronics PLC. | ||
5 | * | ||
6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU General Public License as | ||
10 | * published by the Free Software Foundation; either version 2 of the | ||
11 | * License, or (at your option) any later version. | ||
12 | * | ||
13 | */ | ||
14 | |||
15 | #include <linux/bug.h> | ||
16 | #include <linux/i2c.h> | ||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/mfd/wm8400-private.h> | ||
19 | #include <linux/mfd/wm8400-audio.h> | ||
20 | |||
21 | static struct { | ||
22 | u16 readable; /* Mask of readable bits */ | ||
23 | u16 writable; /* Mask of writable bits */ | ||
24 | u16 vol; /* Mask of volatile bits */ | ||
25 | int is_codec; /* Register controlled by codec reset */ | ||
26 | u16 default_val; /* Value on reset */ | ||
27 | } reg_data[] = { | ||
28 | { 0xFFFF, 0xFFFF, 0x0000, 0, 0x6172 }, /* R0 */ | ||
29 | { 0x7000, 0x0000, 0x8000, 0, 0x0000 }, /* R1 */ | ||
30 | { 0xFF17, 0xFF17, 0x0000, 0, 0x0000 }, /* R2 */ | ||
31 | { 0xEBF3, 0xEBF3, 0x0000, 1, 0x6000 }, /* R3 */ | ||
32 | { 0x3CF3, 0x3CF3, 0x0000, 1, 0x0000 }, /* R4 */ | ||
33 | { 0xF1F8, 0xF1F8, 0x0000, 1, 0x4050 }, /* R5 */ | ||
34 | { 0xFC1F, 0xFC1F, 0x0000, 1, 0x4000 }, /* R6 */ | ||
35 | { 0xDFDE, 0xDFDE, 0x0000, 1, 0x01C8 }, /* R7 */ | ||
36 | { 0xFCFC, 0xFCFC, 0x0000, 1, 0x0000 }, /* R8 */ | ||
37 | { 0xEFFF, 0xEFFF, 0x0000, 1, 0x0040 }, /* R9 */ | ||
38 | { 0xEFFF, 0xEFFF, 0x0000, 1, 0x0040 }, /* R10 */ | ||
39 | { 0x27F7, 0x27F7, 0x0000, 1, 0x0004 }, /* R11 */ | ||
40 | { 0x01FF, 0x01FF, 0x0000, 1, 0x00C0 }, /* R12 */ | ||
41 | { 0x01FF, 0x01FF, 0x0000, 1, 0x00C0 }, /* R13 */ | ||
42 | { 0x1FEF, 0x1FEF, 0x0000, 1, 0x0000 }, /* R14 */ | ||
43 | { 0x0163, 0x0163, 0x0000, 1, 0x0100 }, /* R15 */ | ||
44 | { 0x01FF, 0x01FF, 0x0000, 1, 0x00C0 }, /* R16 */ | ||
45 | { 0x01FF, 0x01FF, 0x0000, 1, 0x00C0 }, /* R17 */ | ||
46 | { 0x1FFF, 0x0FFF, 0x0000, 1, 0x0000 }, /* R18 */ | ||
47 | { 0xFFFF, 0xFFFF, 0x0000, 1, 0x1000 }, /* R19 */ | ||
48 | { 0xFFFF, 0xFFFF, 0x0000, 1, 0x1010 }, /* R20 */ | ||
49 | { 0xFFFF, 0xFFFF, 0x0000, 1, 0x1010 }, /* R21 */ | ||
50 | { 0x0FDD, 0x0FDD, 0x0000, 1, 0x8000 }, /* R22 */ | ||
51 | { 0x1FFF, 0x1FFF, 0x0000, 1, 0x0800 }, /* R23 */ | ||
52 | { 0x0000, 0x01DF, 0x0000, 1, 0x008B }, /* R24 */ | ||
53 | { 0x0000, 0x01DF, 0x0000, 1, 0x008B }, /* R25 */ | ||
54 | { 0x0000, 0x01DF, 0x0000, 1, 0x008B }, /* R26 */ | ||
55 | { 0x0000, 0x01DF, 0x0000, 1, 0x008B }, /* R27 */ | ||
56 | { 0x0000, 0x01FF, 0x0000, 1, 0x0000 }, /* R28 */ | ||
57 | { 0x0000, 0x01FF, 0x0000, 1, 0x0000 }, /* R29 */ | ||
58 | { 0x0000, 0x0077, 0x0000, 1, 0x0066 }, /* R30 */ | ||
59 | { 0x0000, 0x0033, 0x0000, 1, 0x0022 }, /* R31 */ | ||
60 | { 0x0000, 0x01FF, 0x0000, 1, 0x0079 }, /* R32 */ | ||
61 | { 0x0000, 0x01FF, 0x0000, 1, 0x0079 }, /* R33 */ | ||
62 | { 0x0000, 0x0003, 0x0000, 1, 0x0003 }, /* R34 */ | ||
63 | { 0x0000, 0x01FF, 0x0000, 1, 0x0003 }, /* R35 */ | ||
64 | { 0x0000, 0x0000, 0x0000, 0, 0x0000 }, /* R36 */ | ||
65 | { 0x0000, 0x003F, 0x0000, 1, 0x0100 }, /* R37 */ | ||
66 | { 0x0000, 0x0000, 0x0000, 0, 0x0000 }, /* R38 */ | ||
67 | { 0x0000, 0x000F, 0x0000, 0, 0x0000 }, /* R39 */ | ||
68 | { 0x0000, 0x00FF, 0x0000, 1, 0x0000 }, /* R40 */ | ||
69 | { 0x0000, 0x01B7, 0x0000, 1, 0x0000 }, /* R41 */ | ||
70 | { 0x0000, 0x01B7, 0x0000, 1, 0x0000 }, /* R42 */ | ||
71 | { 0x0000, 0x01FF, 0x0000, 1, 0x0000 }, /* R43 */ | ||
72 | { 0x0000, 0x01FF, 0x0000, 1, 0x0000 }, /* R44 */ | ||
73 | { 0x0000, 0x00FD, 0x0000, 1, 0x0000 }, /* R45 */ | ||
74 | { 0x0000, 0x00FD, 0x0000, 1, 0x0000 }, /* R46 */ | ||
75 | { 0x0000, 0x01FF, 0x0000, 1, 0x0000 }, /* R47 */ | ||
76 | { 0x0000, 0x01FF, 0x0000, 1, 0x0000 }, /* R48 */ | ||
77 | { 0x0000, 0x01FF, 0x0000, 1, 0x0000 }, /* R49 */ | ||
78 | { 0x0000, 0x01FF, 0x0000, 1, 0x0000 }, /* R50 */ | ||
79 | { 0x0000, 0x01B3, 0x0000, 1, 0x0180 }, /* R51 */ | ||
80 | { 0x0000, 0x0077, 0x0000, 1, 0x0000 }, /* R52 */ | ||
81 | { 0x0000, 0x0077, 0x0000, 1, 0x0000 }, /* R53 */ | ||
82 | { 0x0000, 0x00FF, 0x0000, 1, 0x0000 }, /* R54 */ | ||
83 | { 0x0000, 0x0001, 0x0000, 1, 0x0000 }, /* R55 */ | ||
84 | { 0x0000, 0x003F, 0x0000, 1, 0x0000 }, /* R56 */ | ||
85 | { 0x0000, 0x004F, 0x0000, 1, 0x0000 }, /* R57 */ | ||
86 | { 0x0000, 0x00FD, 0x0000, 1, 0x0000 }, /* R58 */ | ||
87 | { 0x0000, 0x0000, 0x0000, 0, 0x0000 }, /* R59 */ | ||
88 | { 0x1FFF, 0x1FFF, 0x0000, 1, 0x0000 }, /* R60 */ | ||
89 | { 0xFFFF, 0xFFFF, 0x0000, 1, 0x0000 }, /* R61 */ | ||
90 | { 0x03FF, 0x03FF, 0x0000, 1, 0x0000 }, /* R62 */ | ||
91 | { 0x007F, 0x007F, 0x0000, 1, 0x0000 }, /* R63 */ | ||
92 | { 0x0000, 0x0000, 0x0000, 0, 0x0000 }, /* R64 */ | ||
93 | { 0xDFFF, 0xDFFF, 0x0000, 0, 0x0000 }, /* R65 */ | ||
94 | { 0xDFFF, 0xDFFF, 0x0000, 0, 0x0000 }, /* R66 */ | ||
95 | { 0xDFFF, 0xDFFF, 0x0000, 0, 0x0000 }, /* R67 */ | ||
96 | { 0xDFFF, 0xDFFF, 0x0000, 0, 0x0000 }, /* R68 */ | ||
97 | { 0x0000, 0x0000, 0x0000, 0, 0x0000 }, /* R69 */ | ||
98 | { 0xFFFF, 0xFFFF, 0x0000, 0, 0x4400 }, /* R70 */ | ||
99 | { 0x23FF, 0x23FF, 0x0000, 0, 0x0000 }, /* R71 */ | ||
100 | { 0xFFFF, 0xFFFF, 0x0000, 0, 0x4400 }, /* R72 */ | ||
101 | { 0x23FF, 0x23FF, 0x0000, 0, 0x0000 }, /* R73 */ | ||
102 | { 0x0000, 0x0000, 0x0000, 0, 0x0000 }, /* R74 */ | ||
103 | { 0x000E, 0x000E, 0x0000, 0, 0x0008 }, /* R75 */ | ||
104 | { 0xE00F, 0xE00F, 0x0000, 0, 0x0000 }, /* R76 */ | ||
105 | { 0x0000, 0x0000, 0x0000, 0, 0x0000 }, /* R77 */ | ||
106 | { 0x03C0, 0x03C0, 0x0000, 0, 0x02C0 }, /* R78 */ | ||
107 | { 0xFFFF, 0x0000, 0xffff, 0, 0x0000 }, /* R79 */ | ||
108 | { 0xFFFF, 0xFFFF, 0x0000, 0, 0x0000 }, /* R80 */ | ||
109 | { 0xFFFF, 0x0000, 0xffff, 0, 0x0000 }, /* R81 */ | ||
110 | { 0x2BFF, 0x0000, 0xffff, 0, 0x0000 }, /* R82 */ | ||
111 | { 0x0000, 0x0000, 0x0000, 0, 0x0000 }, /* R83 */ | ||
112 | { 0x80FF, 0x80FF, 0x0000, 0, 0x00ff }, /* R84 */ | ||
113 | }; | ||
114 | |||
115 | static int wm8400_read(struct wm8400 *wm8400, u8 reg, int num_regs, u16 *dest) | ||
116 | { | ||
117 | int i, ret = 0; | ||
118 | |||
119 | BUG_ON(reg + num_regs - 1 > ARRAY_SIZE(wm8400->reg_cache)); | ||
120 | |||
121 | /* If there are any volatile reads then read back the entire block */ | ||
122 | for (i = reg; i < reg + num_regs; i++) | ||
123 | if (reg_data[i].vol) { | ||
124 | ret = wm8400->read_dev(wm8400->io_data, reg, | ||
125 | num_regs, dest); | ||
126 | if (ret != 0) | ||
127 | return ret; | ||
128 | for (i = 0; i < num_regs; i++) | ||
129 | dest[i] = be16_to_cpu(dest[i]); | ||
130 | |||
131 | return 0; | ||
132 | } | ||
133 | |||
134 | /* Otherwise use the cache */ | ||
135 | memcpy(dest, &wm8400->reg_cache[reg], num_regs * sizeof(u16)); | ||
136 | |||
137 | return 0; | ||
138 | } | ||
139 | |||
140 | static int wm8400_write(struct wm8400 *wm8400, u8 reg, int num_regs, | ||
141 | u16 *src) | ||
142 | { | ||
143 | int ret, i; | ||
144 | |||
145 | BUG_ON(reg + num_regs - 1 > ARRAY_SIZE(wm8400->reg_cache)); | ||
146 | |||
147 | for (i = 0; i < num_regs; i++) { | ||
148 | BUG_ON(!reg_data[reg + i].writable); | ||
149 | wm8400->reg_cache[reg + i] = src[i]; | ||
150 | src[i] = cpu_to_be16(src[i]); | ||
151 | } | ||
152 | |||
153 | /* Do the actual I/O */ | ||
154 | ret = wm8400->write_dev(wm8400->io_data, reg, num_regs, src); | ||
155 | if (ret != 0) | ||
156 | return -EIO; | ||
157 | |||
158 | return 0; | ||
159 | } | ||
160 | |||
161 | /** | ||
162 | * wm8400_reg_read - Single register read | ||
163 | * | ||
164 | * @wm8400: Pointer to wm8400 control structure | ||
165 | * @reg: Register to read | ||
166 | * | ||
167 | * @return Read value | ||
168 | */ | ||
169 | u16 wm8400_reg_read(struct wm8400 *wm8400, u8 reg) | ||
170 | { | ||
171 | u16 val; | ||
172 | |||
173 | mutex_lock(&wm8400->io_lock); | ||
174 | |||
175 | wm8400_read(wm8400, reg, 1, &val); | ||
176 | |||
177 | mutex_unlock(&wm8400->io_lock); | ||
178 | |||
179 | return val; | ||
180 | } | ||
181 | EXPORT_SYMBOL_GPL(wm8400_reg_read); | ||
182 | |||
183 | int wm8400_block_read(struct wm8400 *wm8400, u8 reg, int count, u16 *data) | ||
184 | { | ||
185 | int ret; | ||
186 | |||
187 | mutex_lock(&wm8400->io_lock); | ||
188 | |||
189 | ret = wm8400_read(wm8400, reg, count, data); | ||
190 | |||
191 | mutex_unlock(&wm8400->io_lock); | ||
192 | |||
193 | return ret; | ||
194 | } | ||
195 | EXPORT_SYMBOL_GPL(wm8400_block_read); | ||
196 | |||
197 | /** | ||
198 | * wm8400_set_bits - Bitmask write | ||
199 | * | ||
200 | * @wm8400: Pointer to wm8400 control structure | ||
201 | * @reg: Register to access | ||
202 | * @mask: Mask of bits to change | ||
203 | * @val: Value to set for masked bits | ||
204 | */ | ||
205 | int wm8400_set_bits(struct wm8400 *wm8400, u8 reg, u16 mask, u16 val) | ||
206 | { | ||
207 | u16 tmp; | ||
208 | int ret; | ||
209 | |||
210 | mutex_lock(&wm8400->io_lock); | ||
211 | |||
212 | ret = wm8400_read(wm8400, reg, 1, &tmp); | ||
213 | tmp = (tmp & ~mask) | val; | ||
214 | if (ret == 0) | ||
215 | ret = wm8400_write(wm8400, reg, 1, &tmp); | ||
216 | |||
217 | mutex_unlock(&wm8400->io_lock); | ||
218 | |||
219 | return ret; | ||
220 | } | ||
221 | EXPORT_SYMBOL_GPL(wm8400_set_bits); | ||
222 | |||
223 | /** | ||
224 | * wm8400_reset_codec_reg_cache - Reset cached codec registers to | ||
225 | * their default values. | ||
226 | */ | ||
227 | void wm8400_reset_codec_reg_cache(struct wm8400 *wm8400) | ||
228 | { | ||
229 | int i; | ||
230 | |||
231 | mutex_lock(&wm8400->io_lock); | ||
232 | |||
233 | /* Reset all codec registers to their initial value */ | ||
234 | for (i = 0; i < ARRAY_SIZE(wm8400->reg_cache); i++) | ||
235 | if (reg_data[i].is_codec) | ||
236 | wm8400->reg_cache[i] = reg_data[i].default_val; | ||
237 | |||
238 | mutex_unlock(&wm8400->io_lock); | ||
239 | } | ||
240 | EXPORT_SYMBOL_GPL(wm8400_reset_codec_reg_cache); | ||
241 | |||
242 | /* | ||
243 | * wm8400_init - Generic initialisation | ||
244 | * | ||
245 | * The WM8400 can be configured as either an I2C or SPI device. Probe | ||
246 | * functions for each bus set up the accessors then call into this to | ||
247 | * set up the device itself. | ||
248 | */ | ||
249 | static int wm8400_init(struct wm8400 *wm8400, | ||
250 | struct wm8400_platform_data *pdata) | ||
251 | { | ||
252 | u16 reg; | ||
253 | int ret, i; | ||
254 | |||
255 | mutex_init(&wm8400->io_lock); | ||
256 | |||
257 | wm8400->dev->driver_data = wm8400; | ||
258 | |||
259 | /* Check that this is actually a WM8400 */ | ||
260 | ret = wm8400->read_dev(wm8400->io_data, WM8400_RESET_ID, 1, ®); | ||
261 | if (ret != 0) { | ||
262 | dev_err(wm8400->dev, "Chip ID register read failed\n"); | ||
263 | return -EIO; | ||
264 | } | ||
265 | if (be16_to_cpu(reg) != reg_data[WM8400_RESET_ID].default_val) { | ||
266 | dev_err(wm8400->dev, "Device is not a WM8400, ID is %x\n", | ||
267 | be16_to_cpu(reg)); | ||
268 | return -ENODEV; | ||
269 | } | ||
270 | |||
271 | /* We don't know what state the hardware is in and since this | ||
272 | * is a PMIC we can't reset it safely so initialise the register | ||
273 | * cache from the hardware. | ||
274 | */ | ||
275 | ret = wm8400->read_dev(wm8400->io_data, 0, | ||
276 | ARRAY_SIZE(wm8400->reg_cache), | ||
277 | wm8400->reg_cache); | ||
278 | if (ret != 0) { | ||
279 | dev_err(wm8400->dev, "Register cache read failed\n"); | ||
280 | return -EIO; | ||
281 | } | ||
282 | for (i = 0; i < ARRAY_SIZE(wm8400->reg_cache); i++) | ||
283 | wm8400->reg_cache[i] = be16_to_cpu(wm8400->reg_cache[i]); | ||
284 | |||
285 | /* If the codec is in reset use hard coded values */ | ||
286 | if (!(wm8400->reg_cache[WM8400_POWER_MANAGEMENT_1] & WM8400_CODEC_ENA)) | ||
287 | for (i = 0; i < ARRAY_SIZE(wm8400->reg_cache); i++) | ||
288 | if (reg_data[i].is_codec) | ||
289 | wm8400->reg_cache[i] = reg_data[i].default_val; | ||
290 | |||
291 | ret = wm8400_read(wm8400, WM8400_ID, 1, ®); | ||
292 | if (ret != 0) { | ||
293 | dev_err(wm8400->dev, "ID register read failed: %d\n", ret); | ||
294 | return ret; | ||
295 | } | ||
296 | reg = (reg & WM8400_CHIP_REV_MASK) >> WM8400_CHIP_REV_SHIFT; | ||
297 | dev_info(wm8400->dev, "WM8400 revision %x\n", reg); | ||
298 | |||
299 | if (pdata && pdata->platform_init) { | ||
300 | ret = pdata->platform_init(wm8400->dev); | ||
301 | if (ret != 0) | ||
302 | dev_err(wm8400->dev, "Platform init failed: %d\n", | ||
303 | ret); | ||
304 | } else | ||
305 | dev_warn(wm8400->dev, "No platform initialisation supplied\n"); | ||
306 | |||
307 | return ret; | ||
308 | } | ||
309 | |||
310 | static void wm8400_release(struct wm8400 *wm8400) | ||
311 | { | ||
312 | int i; | ||
313 | |||
314 | for (i = 0; i < ARRAY_SIZE(wm8400->regulators); i++) | ||
315 | if (wm8400->regulators[i].name) | ||
316 | platform_device_unregister(&wm8400->regulators[i]); | ||
317 | } | ||
318 | |||
319 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | ||
320 | static int wm8400_i2c_read(void *io_data, char reg, int count, u16 *dest) | ||
321 | { | ||
322 | struct i2c_client *i2c = io_data; | ||
323 | struct i2c_msg xfer[2]; | ||
324 | int ret; | ||
325 | |||
326 | /* Write register */ | ||
327 | xfer[0].addr = i2c->addr; | ||
328 | xfer[0].flags = 0; | ||
329 | xfer[0].len = 1; | ||
330 | xfer[0].buf = ® | ||
331 | |||
332 | /* Read data */ | ||
333 | xfer[1].addr = i2c->addr; | ||
334 | xfer[1].flags = I2C_M_RD; | ||
335 | xfer[1].len = count * sizeof(u16); | ||
336 | xfer[1].buf = (u8 *)dest; | ||
337 | |||
338 | ret = i2c_transfer(i2c->adapter, xfer, 2); | ||
339 | if (ret == 2) | ||
340 | ret = 0; | ||
341 | else if (ret >= 0) | ||
342 | ret = -EIO; | ||
343 | |||
344 | return ret; | ||
345 | } | ||
346 | |||
347 | static int wm8400_i2c_write(void *io_data, char reg, int count, const u16 *src) | ||
348 | { | ||
349 | struct i2c_client *i2c = io_data; | ||
350 | u8 *msg; | ||
351 | int ret; | ||
352 | |||
353 | /* We add 1 byte for device register - ideally I2C would gather. */ | ||
354 | msg = kmalloc((count * sizeof(u16)) + 1, GFP_KERNEL); | ||
355 | if (msg == NULL) | ||
356 | return -ENOMEM; | ||
357 | |||
358 | msg[0] = reg; | ||
359 | memcpy(&msg[1], src, count * sizeof(u16)); | ||
360 | |||
361 | ret = i2c_master_send(i2c, msg, (count * sizeof(u16)) + 1); | ||
362 | |||
363 | if (ret == (count * 2) + 1) | ||
364 | ret = 0; | ||
365 | else if (ret >= 0) | ||
366 | ret = -EIO; | ||
367 | |||
368 | kfree(msg); | ||
369 | |||
370 | return ret; | ||
371 | } | ||
372 | |||
373 | static int wm8400_i2c_probe(struct i2c_client *i2c, | ||
374 | const struct i2c_device_id *id) | ||
375 | { | ||
376 | struct wm8400 *wm8400; | ||
377 | int ret; | ||
378 | |||
379 | wm8400 = kzalloc(sizeof(struct wm8400), GFP_KERNEL); | ||
380 | if (wm8400 == NULL) { | ||
381 | ret = -ENOMEM; | ||
382 | goto err; | ||
383 | } | ||
384 | |||
385 | wm8400->io_data = i2c; | ||
386 | wm8400->read_dev = wm8400_i2c_read; | ||
387 | wm8400->write_dev = wm8400_i2c_write; | ||
388 | wm8400->dev = &i2c->dev; | ||
389 | i2c_set_clientdata(i2c, wm8400); | ||
390 | |||
391 | ret = wm8400_init(wm8400, i2c->dev.platform_data); | ||
392 | if (ret != 0) | ||
393 | goto struct_err; | ||
394 | |||
395 | return 0; | ||
396 | |||
397 | struct_err: | ||
398 | i2c_set_clientdata(i2c, NULL); | ||
399 | kfree(wm8400); | ||
400 | err: | ||
401 | return ret; | ||
402 | } | ||
403 | |||
404 | static int wm8400_i2c_remove(struct i2c_client *i2c) | ||
405 | { | ||
406 | struct wm8400 *wm8400 = i2c_get_clientdata(i2c); | ||
407 | |||
408 | wm8400_release(wm8400); | ||
409 | i2c_set_clientdata(i2c, NULL); | ||
410 | kfree(wm8400); | ||
411 | |||
412 | return 0; | ||
413 | } | ||
414 | |||
415 | static const struct i2c_device_id wm8400_i2c_id[] = { | ||
416 | { "wm8400", 0 }, | ||
417 | { } | ||
418 | }; | ||
419 | MODULE_DEVICE_TABLE(i2c, wm8400_i2c_id); | ||
420 | |||
421 | static struct i2c_driver wm8400_i2c_driver = { | ||
422 | .driver = { | ||
423 | .name = "WM8400", | ||
424 | .owner = THIS_MODULE, | ||
425 | }, | ||
426 | .probe = wm8400_i2c_probe, | ||
427 | .remove = wm8400_i2c_remove, | ||
428 | .id_table = wm8400_i2c_id, | ||
429 | }; | ||
430 | #endif | ||
431 | |||
432 | static int __init wm8400_module_init(void) | ||
433 | { | ||
434 | int ret = -ENODEV; | ||
435 | |||
436 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | ||
437 | ret = i2c_add_driver(&wm8400_i2c_driver); | ||
438 | if (ret != 0) | ||
439 | pr_err("Failed to register I2C driver: %d\n", ret); | ||
440 | #endif | ||
441 | |||
442 | return ret; | ||
443 | } | ||
444 | module_init(wm8400_module_init); | ||
445 | |||
446 | static void __exit wm8400_module_exit(void) | ||
447 | { | ||
448 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | ||
449 | i2c_del_driver(&wm8400_i2c_driver); | ||
450 | #endif | ||
451 | } | ||
452 | module_exit(wm8400_module_exit); | ||
453 | |||
454 | MODULE_LICENSE("GPL"); | ||
455 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); | ||
diff --git a/drivers/net/3c501.c b/drivers/net/3c501.c index 5ba4bab6d43e..7d15e7c6bcad 100644 --- a/drivers/net/3c501.c +++ b/drivers/net/3c501.c | |||
@@ -17,7 +17,7 @@ | |||
17 | Annapolis MD 21403 | 17 | Annapolis MD 21403 |
18 | 18 | ||
19 | Fixed (again!) the missing interrupt locking on TX/RX shifting. | 19 | Fixed (again!) the missing interrupt locking on TX/RX shifting. |
20 | Alan Cox <Alan.Cox@linux.org> | 20 | Alan Cox <alan@lxorguk.ukuu.org.uk> |
21 | 21 | ||
22 | Removed calls to init_etherdev since they are no longer needed, and | 22 | Removed calls to init_etherdev since they are no longer needed, and |
23 | cleaned up modularization just a bit. The driver still allows only | 23 | cleaned up modularization just a bit. The driver still allows only |
@@ -29,16 +29,16 @@ | |||
29 | the board. Now getting 150K/second FTP with a 3c501 card. Still playing | 29 | the board. Now getting 150K/second FTP with a 3c501 card. Still playing |
30 | with a TX-TX optimisation to see if we can touch 180-200K/second as seems | 30 | with a TX-TX optimisation to see if we can touch 180-200K/second as seems |
31 | theoretically maximum. | 31 | theoretically maximum. |
32 | 19950402 Alan Cox <Alan.Cox@linux.org> | 32 | 19950402 Alan Cox <alan@lxorguk.ukuu.org.uk> |
33 | 33 | ||
34 | Cleaned up for 2.3.x because we broke SMP now. | 34 | Cleaned up for 2.3.x because we broke SMP now. |
35 | 20000208 Alan Cox <alan@redhat.com> | 35 | 20000208 Alan Cox <alan@lxorguk.ukuu.org.uk> |
36 | 36 | ||
37 | Check up pass for 2.5. Nothing significant changed | 37 | Check up pass for 2.5. Nothing significant changed |
38 | 20021009 Alan Cox <alan@redhat.com> | 38 | 20021009 Alan Cox <alan@lxorguk.ukuu.org.uk> |
39 | 39 | ||
40 | Fixed zero fill corner case | 40 | Fixed zero fill corner case |
41 | 20030104 Alan Cox <alan@redhat.com> | 41 | 20030104 Alan Cox <alan@lxorguk.ukuu.org.uk> |
42 | 42 | ||
43 | 43 | ||
44 | For the avoidance of doubt the "preferred form" of this code is one which | 44 | For the avoidance of doubt the "preferred form" of this code is one which |
@@ -104,7 +104,7 @@ | |||
104 | 104 | ||
105 | 105 | ||
106 | static const char version[] = | 106 | static const char version[] = |
107 | DRV_NAME ".c: " DRV_VERSION " Alan Cox (alan@redhat.com).\n"; | 107 | DRV_NAME ".c: " DRV_VERSION " Alan Cox (alan@lxorguk.ukuu.org.uk).\n"; |
108 | 108 | ||
109 | /* | 109 | /* |
110 | * Braindamage remaining: | 110 | * Braindamage remaining: |
diff --git a/drivers/net/3c515.c b/drivers/net/3c515.c index e4e3241628d6..a0f8b6e2d0af 100644 --- a/drivers/net/3c515.c +++ b/drivers/net/3c515.c | |||
@@ -18,7 +18,7 @@ | |||
18 | 18 | ||
19 | 2001/11/17 - Added ethtool support (jgarzik) | 19 | 2001/11/17 - Added ethtool support (jgarzik) |
20 | 20 | ||
21 | 2002/10/28 - Locking updates for 2.5 (alan@redhat.com) | 21 | 2002/10/28 - Locking updates for 2.5 (alan@lxorguk.ukuu.org.uk) |
22 | 22 | ||
23 | */ | 23 | */ |
24 | 24 | ||
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index e9d529442b06..1d8af3348331 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig | |||
@@ -2400,7 +2400,7 @@ config EHEA | |||
2400 | will be called ehea. | 2400 | will be called ehea. |
2401 | 2401 | ||
2402 | config ENIC | 2402 | config ENIC |
2403 | tristate "E, the Cisco 10G Ethernet NIC" | 2403 | tristate "Cisco 10G Ethernet NIC support" |
2404 | depends on PCI && INET | 2404 | depends on PCI && INET |
2405 | select INET_LRO | 2405 | select INET_LRO |
2406 | help | 2406 | help |
diff --git a/drivers/net/appletalk/cops.c b/drivers/net/appletalk/cops.c index a0b4c8516073..735fc9476403 100644 --- a/drivers/net/appletalk/cops.c +++ b/drivers/net/appletalk/cops.c | |||
@@ -4,7 +4,7 @@ | |||
4 | * - Jay Schulist <jschlst@samba.org> | 4 | * - Jay Schulist <jschlst@samba.org> |
5 | * | 5 | * |
6 | * With more than a little help from; | 6 | * With more than a little help from; |
7 | * - Alan Cox <Alan.Cox@linux.org> | 7 | * - Alan Cox <alan@lxorguk.ukuu.org.uk> |
8 | * | 8 | * |
9 | * Derived from: | 9 | * Derived from: |
10 | * - skeleton.c: A network driver outline for linux. | 10 | * - skeleton.c: A network driver outline for linux. |
diff --git a/drivers/net/cxgb3/adapter.h b/drivers/net/cxgb3/adapter.h index 455ef529cd62..bc8e2413abd2 100644 --- a/drivers/net/cxgb3/adapter.h +++ b/drivers/net/cxgb3/adapter.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved. | 2 | * Copyright (c) 2003-2008 Chelsio, Inc. All rights reserved. |
3 | * | 3 | * |
4 | * This software is available to you under a choice of one of two | 4 | * This software is available to you under a choice of one of two |
5 | * licenses. You may choose to be licensed under the terms of the GNU | 5 | * licenses. You may choose to be licensed under the terms of the GNU |
diff --git a/drivers/net/cxgb3/ael1002.c b/drivers/net/cxgb3/ael1002.c index 744fac0b1617..5c3c05da4d96 100644 --- a/drivers/net/cxgb3/ael1002.c +++ b/drivers/net/cxgb3/ael1002.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2005-2007 Chelsio, Inc. All rights reserved. | 2 | * Copyright (c) 2005-2008 Chelsio, Inc. All rights reserved. |
3 | * | 3 | * |
4 | * This software is available to you under a choice of one of two | 4 | * This software is available to you under a choice of one of two |
5 | * licenses. You may choose to be licensed under the terms of the GNU | 5 | * licenses. You may choose to be licensed under the terms of the GNU |
diff --git a/drivers/net/cxgb3/common.h b/drivers/net/cxgb3/common.h index 593fb643a615..e312d315a42d 100644 --- a/drivers/net/cxgb3/common.h +++ b/drivers/net/cxgb3/common.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2005-2007 Chelsio, Inc. All rights reserved. | 2 | * Copyright (c) 2005-2008 Chelsio, Inc. All rights reserved. |
3 | * | 3 | * |
4 | * This software is available to you under a choice of one of two | 4 | * This software is available to you under a choice of one of two |
5 | * licenses. You may choose to be licensed under the terms of the GNU | 5 | * licenses. You may choose to be licensed under the terms of the GNU |
diff --git a/drivers/net/cxgb3/cxgb3_ctl_defs.h b/drivers/net/cxgb3/cxgb3_ctl_defs.h index 6ad92405d9a0..1d8d46eb3c96 100644 --- a/drivers/net/cxgb3/cxgb3_ctl_defs.h +++ b/drivers/net/cxgb3/cxgb3_ctl_defs.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved. | 2 | * Copyright (c) 2003-2008 Chelsio, Inc. All rights reserved. |
3 | * | 3 | * |
4 | * This software is available to you under a choice of one of two | 4 | * This software is available to you under a choice of one of two |
5 | * licenses. You may choose to be licensed under the terms of the GNU | 5 | * licenses. You may choose to be licensed under the terms of the GNU |
diff --git a/drivers/net/cxgb3/cxgb3_defs.h b/drivers/net/cxgb3/cxgb3_defs.h index 45e92164c260..47e53769af5b 100644 --- a/drivers/net/cxgb3/cxgb3_defs.h +++ b/drivers/net/cxgb3/cxgb3_defs.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2006-2007 Chelsio, Inc. All rights reserved. | 2 | * Copyright (c) 2006-2008 Chelsio, Inc. All rights reserved. |
3 | * | 3 | * |
4 | * This software is available to you under a choice of one of two | 4 | * This software is available to you under a choice of one of two |
5 | * licenses. You may choose to be licensed under the terms of the GNU | 5 | * licenses. You may choose to be licensed under the terms of the GNU |
diff --git a/drivers/net/cxgb3/cxgb3_ioctl.h b/drivers/net/cxgb3/cxgb3_ioctl.h index 3e8d5faec3a4..b19e4376ba76 100644 --- a/drivers/net/cxgb3/cxgb3_ioctl.h +++ b/drivers/net/cxgb3/cxgb3_ioctl.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved. | 2 | * Copyright (c) 2003-2008 Chelsio, Inc. All rights reserved. |
3 | * | 3 | * |
4 | * This software is available to you under a choice of one of two | 4 | * This software is available to you under a choice of one of two |
5 | * licenses. You may choose to be licensed under the terms of the GNU | 5 | * licenses. You may choose to be licensed under the terms of the GNU |
diff --git a/drivers/net/cxgb3/cxgb3_main.c b/drivers/net/cxgb3/cxgb3_main.c index f31985df0bb9..1ace41a13ac3 100644 --- a/drivers/net/cxgb3/cxgb3_main.c +++ b/drivers/net/cxgb3/cxgb3_main.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved. | 2 | * Copyright (c) 2003-2008 Chelsio, Inc. All rights reserved. |
3 | * | 3 | * |
4 | * This software is available to you under a choice of one of two | 4 | * This software is available to you under a choice of one of two |
5 | * licenses. You may choose to be licensed under the terms of the GNU | 5 | * licenses. You may choose to be licensed under the terms of the GNU |
diff --git a/drivers/net/cxgb3/cxgb3_offload.c b/drivers/net/cxgb3/cxgb3_offload.c index 0f6fd63b2847..265aa8a15afa 100644 --- a/drivers/net/cxgb3/cxgb3_offload.c +++ b/drivers/net/cxgb3/cxgb3_offload.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2006-2007 Chelsio, Inc. All rights reserved. | 2 | * Copyright (c) 2006-2008 Chelsio, Inc. All rights reserved. |
3 | * | 3 | * |
4 | * This software is available to you under a choice of one of two | 4 | * This software is available to you under a choice of one of two |
5 | * licenses. You may choose to be licensed under the terms of the GNU | 5 | * licenses. You may choose to be licensed under the terms of the GNU |
diff --git a/drivers/net/cxgb3/cxgb3_offload.h b/drivers/net/cxgb3/cxgb3_offload.h index 7a379138b5a6..d514e5019dfc 100644 --- a/drivers/net/cxgb3/cxgb3_offload.h +++ b/drivers/net/cxgb3/cxgb3_offload.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2006-2007 Chelsio, Inc. All rights reserved. | 2 | * Copyright (c) 2006-2008 Chelsio, Inc. All rights reserved. |
3 | * | 3 | * |
4 | * This software is available to you under a choice of one of two | 4 | * This software is available to you under a choice of one of two |
5 | * licenses. You may choose to be licensed under the terms of the GNU | 5 | * licenses. You may choose to be licensed under the terms of the GNU |
diff --git a/drivers/net/cxgb3/firmware_exports.h b/drivers/net/cxgb3/firmware_exports.h index b75ddd8777fe..0d9b0e6dccff 100644 --- a/drivers/net/cxgb3/firmware_exports.h +++ b/drivers/net/cxgb3/firmware_exports.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2004-2007 Chelsio, Inc. All rights reserved. | 2 | * Copyright (c) 2004-2008 Chelsio, Inc. All rights reserved. |
3 | * | 3 | * |
4 | * This software is available to you under a choice of one of two | 4 | * This software is available to you under a choice of one of two |
5 | * licenses. You may choose to be licensed under the terms of the GNU | 5 | * licenses. You may choose to be licensed under the terms of the GNU |
diff --git a/drivers/net/cxgb3/l2t.c b/drivers/net/cxgb3/l2t.c index b2c5314582aa..4407ac9bb555 100644 --- a/drivers/net/cxgb3/l2t.c +++ b/drivers/net/cxgb3/l2t.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved. | 2 | * Copyright (c) 2003-2008 Chelsio, Inc. All rights reserved. |
3 | * | 3 | * |
4 | * This software is available to you under a choice of one of two | 4 | * This software is available to you under a choice of one of two |
5 | * licenses. You may choose to be licensed under the terms of the GNU | 5 | * licenses. You may choose to be licensed under the terms of the GNU |
diff --git a/drivers/net/cxgb3/l2t.h b/drivers/net/cxgb3/l2t.h index 42ce65f76a87..fd3eb07e3f40 100644 --- a/drivers/net/cxgb3/l2t.h +++ b/drivers/net/cxgb3/l2t.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved. | 2 | * Copyright (c) 2003-2008 Chelsio, Inc. All rights reserved. |
3 | * | 3 | * |
4 | * This software is available to you under a choice of one of two | 4 | * This software is available to you under a choice of one of two |
5 | * licenses. You may choose to be licensed under the terms of the GNU | 5 | * licenses. You may choose to be licensed under the terms of the GNU |
diff --git a/drivers/net/cxgb3/mc5.c b/drivers/net/cxgb3/mc5.c index 4c4d6e877ea6..3b5517b8fbde 100644 --- a/drivers/net/cxgb3/mc5.c +++ b/drivers/net/cxgb3/mc5.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved. | 2 | * Copyright (c) 2003-2008 Chelsio, Inc. All rights reserved. |
3 | * | 3 | * |
4 | * This software is available to you under a choice of one of two | 4 | * This software is available to you under a choice of one of two |
5 | * licenses. You may choose to be licensed under the terms of the GNU | 5 | * licenses. You may choose to be licensed under the terms of the GNU |
diff --git a/drivers/net/cxgb3/sge.c b/drivers/net/cxgb3/sge.c index 87919419b707..c6480be0bc1f 100644 --- a/drivers/net/cxgb3/sge.c +++ b/drivers/net/cxgb3/sge.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2005-2007 Chelsio, Inc. All rights reserved. | 2 | * Copyright (c) 2005-2008 Chelsio, Inc. All rights reserved. |
3 | * | 3 | * |
4 | * This software is available to you under a choice of one of two | 4 | * This software is available to you under a choice of one of two |
5 | * licenses. You may choose to be licensed under the terms of the GNU | 5 | * licenses. You may choose to be licensed under the terms of the GNU |
diff --git a/drivers/net/cxgb3/t3_cpl.h b/drivers/net/cxgb3/t3_cpl.h index 917970ed24a1..852c399a8b0a 100644 --- a/drivers/net/cxgb3/t3_cpl.h +++ b/drivers/net/cxgb3/t3_cpl.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2004-2007 Chelsio, Inc. All rights reserved. | 2 | * Copyright (c) 2004-2008 Chelsio, Inc. All rights reserved. |
3 | * | 3 | * |
4 | * This software is available to you under a choice of one of two | 4 | * This software is available to you under a choice of one of two |
5 | * licenses. You may choose to be licensed under the terms of the GNU | 5 | * licenses. You may choose to be licensed under the terms of the GNU |
diff --git a/drivers/net/cxgb3/t3_hw.c b/drivers/net/cxgb3/t3_hw.c index 4da5b09b9bc2..968f64be3743 100644 --- a/drivers/net/cxgb3/t3_hw.c +++ b/drivers/net/cxgb3/t3_hw.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved. | 2 | * Copyright (c) 2003-2008 Chelsio, Inc. All rights reserved. |
3 | * | 3 | * |
4 | * This software is available to you under a choice of one of two | 4 | * This software is available to you under a choice of one of two |
5 | * licenses. You may choose to be licensed under the terms of the GNU | 5 | * licenses. You may choose to be licensed under the terms of the GNU |
diff --git a/drivers/net/cxgb3/t3cdev.h b/drivers/net/cxgb3/t3cdev.h index 0a21cfbd2b21..be55e9ae74d1 100644 --- a/drivers/net/cxgb3/t3cdev.h +++ b/drivers/net/cxgb3/t3cdev.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2006-2007 Chelsio Communications. All rights reserved. | 2 | * Copyright (C) 2006-2008 Chelsio Communications. All rights reserved. |
3 | * | 3 | * |
4 | * This software is available to you under a choice of one of two | 4 | * This software is available to you under a choice of one of two |
5 | * licenses. You may choose to be licensed under the terms of the GNU | 5 | * licenses. You may choose to be licensed under the terms of the GNU |
diff --git a/drivers/net/cxgb3/version.h b/drivers/net/cxgb3/version.h index 29db711303b9..bb8698a86754 100644 --- a/drivers/net/cxgb3/version.h +++ b/drivers/net/cxgb3/version.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved. | 2 | * Copyright (c) 2003-2008 Chelsio, Inc. All rights reserved. |
3 | * | 3 | * |
4 | * This software is available to you under a choice of one of two | 4 | * This software is available to you under a choice of one of two |
5 | * licenses. You may choose to be licensed under the terms of the GNU | 5 | * licenses. You may choose to be licensed under the terms of the GNU |
@@ -35,7 +35,7 @@ | |||
35 | #define DRV_DESC "Chelsio T3 Network Driver" | 35 | #define DRV_DESC "Chelsio T3 Network Driver" |
36 | #define DRV_NAME "cxgb3" | 36 | #define DRV_NAME "cxgb3" |
37 | /* Driver version */ | 37 | /* Driver version */ |
38 | #define DRV_VERSION "1.0-ko" | 38 | #define DRV_VERSION "1.1.0-ko" |
39 | 39 | ||
40 | /* Firmware version */ | 40 | /* Firmware version */ |
41 | #define FW_VERSION_MAJOR 7 | 41 | #define FW_VERSION_MAJOR 7 |
diff --git a/drivers/net/cxgb3/vsc8211.c b/drivers/net/cxgb3/vsc8211.c index 306c2dc4ab34..33f956bd6b59 100644 --- a/drivers/net/cxgb3/vsc8211.c +++ b/drivers/net/cxgb3/vsc8211.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2005-2007 Chelsio, Inc. All rights reserved. | 2 | * Copyright (c) 2005-2008 Chelsio, Inc. All rights reserved. |
3 | * | 3 | * |
4 | * This software is available to you under a choice of one of two | 4 | * This software is available to you under a choice of one of two |
5 | * licenses. You may choose to be licensed under the terms of the GNU | 5 | * licenses. You may choose to be licensed under the terms of the GNU |
diff --git a/drivers/net/cxgb3/xgmac.c b/drivers/net/cxgb3/xgmac.c index ffdc0a1892bd..9d7786937aad 100644 --- a/drivers/net/cxgb3/xgmac.c +++ b/drivers/net/cxgb3/xgmac.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2005-2007 Chelsio, Inc. All rights reserved. | 2 | * Copyright (c) 2005-2008 Chelsio, Inc. All rights reserved. |
3 | * | 3 | * |
4 | * This software is available to you under a choice of one of two | 4 | * This software is available to you under a choice of one of two |
5 | * licenses. You may choose to be licensed under the terms of the GNU | 5 | * licenses. You may choose to be licensed under the terms of the GNU |
diff --git a/drivers/net/eexpress.c b/drivers/net/eexpress.c index 795c594a4b7c..b751c1b96cfa 100644 --- a/drivers/net/eexpress.c +++ b/drivers/net/eexpress.c | |||
@@ -8,7 +8,7 @@ | |||
8 | * | 8 | * |
9 | * Many modifications, and currently maintained, by | 9 | * Many modifications, and currently maintained, by |
10 | * Philip Blundell <philb@gnu.org> | 10 | * Philip Blundell <philb@gnu.org> |
11 | * Added the Compaq LTE Alan Cox <alan@redhat.com> | 11 | * Added the Compaq LTE Alan Cox <alan@lxorguk.ukuu.org.uk> |
12 | * Added MCA support Adam Fritzler | 12 | * Added MCA support Adam Fritzler |
13 | * | 13 | * |
14 | * Note - this driver is experimental still - it has problems on faster | 14 | * Note - this driver is experimental still - it has problems on faster |
diff --git a/drivers/net/enic/enic_main.c b/drivers/net/enic/enic_main.c index f3a47a87dbbe..180e968dc54d 100644 --- a/drivers/net/enic/enic_main.c +++ b/drivers/net/enic/enic_main.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include <linux/ip.h> | 34 | #include <linux/ip.h> |
35 | #include <linux/ipv6.h> | 35 | #include <linux/ipv6.h> |
36 | #include <linux/tcp.h> | 36 | #include <linux/tcp.h> |
37 | #include <net/ip6_checksum.h> | ||
37 | 38 | ||
38 | #include "cq_enet_desc.h" | 39 | #include "cq_enet_desc.h" |
39 | #include "vnic_dev.h" | 40 | #include "vnic_dev.h" |
diff --git a/drivers/net/ibmlana.c b/drivers/net/ibmlana.c index 95e3464068db..f02764725a22 100644 --- a/drivers/net/ibmlana.c +++ b/drivers/net/ibmlana.c | |||
@@ -71,7 +71,7 @@ History: | |||
71 | June 1st, 2000 | 71 | June 1st, 2000 |
72 | corrected version codes, added support for the latest 2.3 changes | 72 | corrected version codes, added support for the latest 2.3 changes |
73 | Oct 28th, 2002 | 73 | Oct 28th, 2002 |
74 | cleaned up for the 2.5 tree <alan@redhat.com> | 74 | cleaned up for the 2.5 tree <alan@lxorguk.ukuu.org.uk> |
75 | 75 | ||
76 | *************************************************************************/ | 76 | *************************************************************************/ |
77 | 77 | ||
diff --git a/drivers/net/jme.c b/drivers/net/jme.c index 156f159aafbb..81c6cdc3851f 100644 --- a/drivers/net/jme.c +++ b/drivers/net/jme.c | |||
@@ -37,6 +37,7 @@ | |||
37 | #include <linux/tcp.h> | 37 | #include <linux/tcp.h> |
38 | #include <linux/udp.h> | 38 | #include <linux/udp.h> |
39 | #include <linux/if_vlan.h> | 39 | #include <linux/if_vlan.h> |
40 | #include <net/ip6_checksum.h> | ||
40 | #include "jme.h" | 41 | #include "jme.h" |
41 | 42 | ||
42 | static int force_pseudohp = -1; | 43 | static int force_pseudohp = -1; |
diff --git a/drivers/net/macmace.c b/drivers/net/macmace.c index 51ad3765e075..85587a6667b9 100644 --- a/drivers/net/macmace.c +++ b/drivers/net/macmace.c | |||
@@ -9,7 +9,7 @@ | |||
9 | * 2 of the License, or (at your option) any later version. | 9 | * 2 of the License, or (at your option) any later version. |
10 | * | 10 | * |
11 | * Copyright (C) 1996 Paul Mackerras. | 11 | * Copyright (C) 1996 Paul Mackerras. |
12 | * Copyright (C) 1998 Alan Cox <alan@redhat.com> | 12 | * Copyright (C) 1998 Alan Cox <alan@lxorguk.ukuu.org.uk> |
13 | * | 13 | * |
14 | * Modified heavily by Joshua M. Thompson based on Dave Huang's NetBSD driver | 14 | * Modified heavily by Joshua M. Thompson based on Dave Huang's NetBSD driver |
15 | * | 15 | * |
diff --git a/drivers/net/pcmcia/3c589_cs.c b/drivers/net/pcmcia/3c589_cs.c index 0b28d0d8ffa8..c235cdba69c6 100644 --- a/drivers/net/pcmcia/3c589_cs.c +++ b/drivers/net/pcmcia/3c589_cs.c | |||
@@ -15,7 +15,7 @@ | |||
15 | incorporated herein by reference. | 15 | incorporated herein by reference. |
16 | Donald Becker may be reached at becker@scyld.com | 16 | Donald Becker may be reached at becker@scyld.com |
17 | 17 | ||
18 | Updated for 2.5.x by Alan Cox <alan@redhat.com> | 18 | Updated for 2.5.x by Alan Cox <alan@lxorguk.ukuu.org.uk> |
19 | 19 | ||
20 | ======================================================================*/ | 20 | ======================================================================*/ |
21 | 21 | ||
diff --git a/drivers/net/pcmcia/nmclan_cs.c b/drivers/net/pcmcia/nmclan_cs.c index 54df34f21c5f..448cd40aeba5 100644 --- a/drivers/net/pcmcia/nmclan_cs.c +++ b/drivers/net/pcmcia/nmclan_cs.c | |||
@@ -69,7 +69,7 @@ Driver Notes and Issues | |||
69 | History | 69 | History |
70 | ------------------------------------------------------------------------------- | 70 | ------------------------------------------------------------------------------- |
71 | Log: nmclan_cs.c,v | 71 | Log: nmclan_cs.c,v |
72 | * 2.5.75-ac1 2003/07/11 Alan Cox <alan@redhat.com> | 72 | * 2.5.75-ac1 2003/07/11 Alan Cox <alan@lxorguk.ukuu.org.uk> |
73 | * Fixed hang on card eject as we probe it | 73 | * Fixed hang on card eject as we probe it |
74 | * Cleaned up to use new style locking. | 74 | * Cleaned up to use new style locking. |
75 | * | 75 | * |
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index 6671e2da0d57..d0ed1ef284a8 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c | |||
@@ -55,6 +55,7 @@ EXPORT_SYMBOL(mdiobus_alloc); | |||
55 | 55 | ||
56 | /** | 56 | /** |
57 | * mdiobus_release - mii_bus device release callback | 57 | * mdiobus_release - mii_bus device release callback |
58 | * @d: the target struct device that contains the mii_bus | ||
58 | * | 59 | * |
59 | * Description: called when the last reference to an mii_bus is | 60 | * Description: called when the last reference to an mii_bus is |
60 | * dropped, to free the underlying memory. | 61 | * dropped, to free the underlying memory. |
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 171627480058..f11e900b437b 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c | |||
@@ -557,6 +557,7 @@ int genphy_restart_aneg(struct phy_device *phydev) | |||
557 | 557 | ||
558 | return ctl; | 558 | return ctl; |
559 | } | 559 | } |
560 | EXPORT_SYMBOL(genphy_restart_aneg); | ||
560 | 561 | ||
561 | 562 | ||
562 | /** | 563 | /** |
diff --git a/drivers/net/qlge/qlge.h b/drivers/net/qlge/qlge.h index c37ea436c918..38116f9d4163 100644 --- a/drivers/net/qlge/qlge.h +++ b/drivers/net/qlge/qlge.h | |||
@@ -58,7 +58,7 @@ | |||
58 | */ | 58 | */ |
59 | #if (PAGE_SHIFT == 12) || (PAGE_SHIFT == 13) /* 4k & 8k pages */ | 59 | #if (PAGE_SHIFT == 12) || (PAGE_SHIFT == 13) /* 4k & 8k pages */ |
60 | #define TX_DESC_PER_OAL ((MAX_SKB_FRAGS - TX_DESC_PER_IOCB) + 2) | 60 | #define TX_DESC_PER_OAL ((MAX_SKB_FRAGS - TX_DESC_PER_IOCB) + 2) |
61 | #elif (PAGE_SHIFT == 16) /* 64k pages */ | 61 | #else /* all other page sizes */ |
62 | #define TX_DESC_PER_OAL 0 | 62 | #define TX_DESC_PER_OAL 0 |
63 | #endif | 63 | #endif |
64 | 64 | ||
diff --git a/drivers/net/qlge/qlge_main.c b/drivers/net/qlge/qlge_main.c index 297877b68c46..4b2caa6b7ac5 100644 --- a/drivers/net/qlge/qlge_main.c +++ b/drivers/net/qlge/qlge_main.c | |||
@@ -39,6 +39,7 @@ | |||
39 | #include <linux/delay.h> | 39 | #include <linux/delay.h> |
40 | #include <linux/mm.h> | 40 | #include <linux/mm.h> |
41 | #include <linux/vmalloc.h> | 41 | #include <linux/vmalloc.h> |
42 | #include <net/ip6_checksum.h> | ||
42 | 43 | ||
43 | #include "qlge.h" | 44 | #include "qlge.h" |
44 | 45 | ||
diff --git a/drivers/net/tlan.c b/drivers/net/tlan.c index ec871f646766..c41d68761364 100644 --- a/drivers/net/tlan.c +++ b/drivers/net/tlan.c | |||
@@ -29,7 +29,8 @@ | |||
29 | * | 29 | * |
30 | * Tigran Aivazian <tigran@sco.com>: TLan_PciProbe() now uses | 30 | * Tigran Aivazian <tigran@sco.com>: TLan_PciProbe() now uses |
31 | * new PCI BIOS interface. | 31 | * new PCI BIOS interface. |
32 | * Alan Cox <alan@redhat.com>: Fixed the out of memory | 32 | * Alan Cox <alan@lxorguk.ukuu.org.uk>: |
33 | * Fixed the out of memory | ||
33 | * handling. | 34 | * handling. |
34 | * | 35 | * |
35 | * Torben Mathiasen <torben.mathiasen@compaq.com> New Maintainer! | 36 | * Torben Mathiasen <torben.mathiasen@compaq.com> New Maintainer! |
diff --git a/drivers/net/tokenring/smctr.c b/drivers/net/tokenring/smctr.c index fa73e6eed6be..ed50d288e494 100644 --- a/drivers/net/tokenring/smctr.c +++ b/drivers/net/tokenring/smctr.c | |||
@@ -25,7 +25,7 @@ | |||
25 | * To do: | 25 | * To do: |
26 | * 1. Multicast support. | 26 | * 1. Multicast support. |
27 | * | 27 | * |
28 | * Initial 2.5 cleanup Alan Cox <alan@redhat.com> 2002/10/28 | 28 | * Initial 2.5 cleanup Alan Cox <alan@lxorguk.ukuu.org.uk> 2002/10/28 |
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include <linux/module.h> | 31 | #include <linux/module.h> |
diff --git a/drivers/net/tulip/de2104x.c b/drivers/net/tulip/de2104x.c index f54c45049d50..124d5d690dde 100644 --- a/drivers/net/tulip/de2104x.c +++ b/drivers/net/tulip/de2104x.c | |||
@@ -1688,6 +1688,7 @@ static void __devinit de21040_get_mac_address (struct de_private *de) | |||
1688 | unsigned i; | 1688 | unsigned i; |
1689 | 1689 | ||
1690 | dw32 (ROMCmd, 0); /* Reset the pointer with a dummy write. */ | 1690 | dw32 (ROMCmd, 0); /* Reset the pointer with a dummy write. */ |
1691 | udelay(5); | ||
1691 | 1692 | ||
1692 | for (i = 0; i < 6; i++) { | 1693 | for (i = 0; i < 6; i++) { |
1693 | int value, boguscnt = 100000; | 1694 | int value, boguscnt = 100000; |
diff --git a/drivers/net/tulip/dmfe.c b/drivers/net/tulip/dmfe.c index 656200472fa1..8e46a513a252 100644 --- a/drivers/net/tulip/dmfe.c +++ b/drivers/net/tulip/dmfe.c | |||
@@ -23,7 +23,7 @@ | |||
23 | Marcelo Tosatti <marcelo@conectiva.com.br> : | 23 | Marcelo Tosatti <marcelo@conectiva.com.br> : |
24 | Made it compile in 2.3 (device to net_device) | 24 | Made it compile in 2.3 (device to net_device) |
25 | 25 | ||
26 | Alan Cox <alan@redhat.com> : | 26 | Alan Cox <alan@lxorguk.ukuu.org.uk> : |
27 | Cleaned up for kernel merge. | 27 | Cleaned up for kernel merge. |
28 | Removed the back compatibility support | 28 | Removed the back compatibility support |
29 | Reformatted, fixing spelling etc as I went | 29 | Reformatted, fixing spelling etc as I went |
@@ -49,7 +49,7 @@ | |||
49 | support. Updated PCI resource allocation. Do not | 49 | support. Updated PCI resource allocation. Do not |
50 | forget to unmap PCI mapped skbs. | 50 | forget to unmap PCI mapped skbs. |
51 | 51 | ||
52 | Alan Cox <alan@redhat.com> | 52 | Alan Cox <alan@lxorguk.ukuu.org.uk> |
53 | Added new PCI identifiers provided by Clear Zhang at ALi | 53 | Added new PCI identifiers provided by Clear Zhang at ALi |
54 | for their 1563 ethernet device. | 54 | for their 1563 ethernet device. |
55 | 55 | ||
diff --git a/drivers/net/via-velocity.c b/drivers/net/via-velocity.c index ad20f96edfa1..2dced383bcfb 100644 --- a/drivers/net/via-velocity.c +++ b/drivers/net/via-velocity.c | |||
@@ -12,7 +12,7 @@ | |||
12 | * Scatter gather | 12 | * Scatter gather |
13 | * More testing | 13 | * More testing |
14 | * | 14 | * |
15 | * The changes are (c) Copyright 2004, Red Hat Inc. <alan@redhat.com> | 15 | * The changes are (c) Copyright 2004, Red Hat Inc. <alan@lxorguk.ukuu.org.uk> |
16 | * Additional fixes and clean up: Francois Romieu | 16 | * Additional fixes and clean up: Francois Romieu |
17 | * | 17 | * |
18 | * This source has not been verified for use in safety critical systems. | 18 | * This source has not been verified for use in safety critical systems. |
diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c index 243bd8d918fe..ccd9cd35ecbe 100644 --- a/drivers/net/wan/z85230.c +++ b/drivers/net/wan/z85230.c | |||
@@ -18,7 +18,8 @@ | |||
18 | * DMA now uses get_free_page as kmalloc buffers may span a 64K | 18 | * DMA now uses get_free_page as kmalloc buffers may span a 64K |
19 | * boundary. | 19 | * boundary. |
20 | * | 20 | * |
21 | * Modified for SMP safety and SMP locking by Alan Cox <alan@redhat.com> | 21 | * Modified for SMP safety and SMP locking by Alan Cox |
22 | * <alan@lxorguk.ukuu.org.uk> | ||
22 | * | 23 | * |
23 | * Performance | 24 | * Performance |
24 | * | 25 | * |
diff --git a/drivers/net/wan/z85230.h b/drivers/net/wan/z85230.h index 4f372396c512..85b3e785d484 100644 --- a/drivers/net/wan/z85230.h +++ b/drivers/net/wan/z85230.h | |||
@@ -2,7 +2,7 @@ | |||
2 | * Description of Z8530 Z85C30 and Z85230 communications chips | 2 | * Description of Z8530 Z85C30 and Z85230 communications chips |
3 | * | 3 | * |
4 | * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) | 4 | * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) |
5 | * Copyright (C) 1998 Alan Cox <alan@redhat.com> | 5 | * Copyright (C) 1998 Alan Cox <alan@lxorguk.ukuu.org.uk> |
6 | */ | 6 | */ |
7 | 7 | ||
8 | #ifndef _Z8530_H | 8 | #ifndef _Z8530_H |
diff --git a/drivers/net/wireless/wavelan.c b/drivers/net/wireless/wavelan.c index 136220b5ca81..e939a73ff794 100644 --- a/drivers/net/wireless/wavelan.c +++ b/drivers/net/wireless/wavelan.c | |||
@@ -4387,7 +4387,7 @@ MODULE_LICENSE("GPL"); | |||
4387 | * | 4387 | * |
4388 | * Thanks go also to: | 4388 | * Thanks go also to: |
4389 | * James Ashton (jaa101@syseng.anu.edu.au), | 4389 | * James Ashton (jaa101@syseng.anu.edu.au), |
4390 | * Alan Cox (alan@redhat.com), | 4390 | * Alan Cox (alan@lxorguk.ukuu.org.uk), |
4391 | * Allan Creighton (allanc@cs.usyd.edu.au), | 4391 | * Allan Creighton (allanc@cs.usyd.edu.au), |
4392 | * Matthew Geier (matthew@cs.usyd.edu.au), | 4392 | * Matthew Geier (matthew@cs.usyd.edu.au), |
4393 | * Remo di Giovanni (remo@cs.usyd.edu.au), | 4393 | * Remo di Giovanni (remo@cs.usyd.edu.au), |
diff --git a/drivers/net/wireless/wavelan.p.h b/drivers/net/wireless/wavelan.p.h index b33ac47dd8df..44d31bbf39e4 100644 --- a/drivers/net/wireless/wavelan.p.h +++ b/drivers/net/wireless/wavelan.p.h | |||
@@ -186,7 +186,7 @@ | |||
186 | * | 186 | * |
187 | * Thanks go also to: | 187 | * Thanks go also to: |
188 | * James Ashton <jaa101@syseng.anu.edu.au>, | 188 | * James Ashton <jaa101@syseng.anu.edu.au>, |
189 | * Alan Cox <alan@redhat.com>, | 189 | * Alan Cox <alan@lxorguk.ukuu.org.uk>, |
190 | * Allan Creighton <allanc@cs.usyd.edu.au>, | 190 | * Allan Creighton <allanc@cs.usyd.edu.au>, |
191 | * Matthew Geier <matthew@cs.usyd.edu.au>, | 191 | * Matthew Geier <matthew@cs.usyd.edu.au>, |
192 | * Remo di Giovanni <remo@cs.usyd.edu.au>, | 192 | * Remo di Giovanni <remo@cs.usyd.edu.au>, |
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index a656128f1fdd..4dada6ee1119 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig | |||
@@ -56,4 +56,28 @@ config REGULATOR_BQ24022 | |||
56 | charging select between 100 mA and 500 mA charging current | 56 | charging select between 100 mA and 500 mA charging current |
57 | limit. | 57 | limit. |
58 | 58 | ||
59 | config REGULATOR_WM8350 | ||
60 | tristate "Wolfson Microelectroncis WM8350 AudioPlus PMIC" | ||
61 | depends on MFD_WM8350 | ||
62 | select REGULATOR | ||
63 | help | ||
64 | This driver provides support for the voltage and current regulators | ||
65 | of the WM8350 AudioPlus PMIC. | ||
66 | |||
67 | config REGULATOR_WM8400 | ||
68 | tristate "Wolfson Microelectroncis WM8400 AudioPlus PMIC" | ||
69 | depends on MFD_WM8400 | ||
70 | select REGULATOR | ||
71 | help | ||
72 | This driver provides support for the voltage regulators of the | ||
73 | WM8400 AudioPlus PMIC. | ||
74 | |||
75 | config REGULATOR_DA903X | ||
76 | tristate "Support regulators on Dialog Semiconductor DA9030/DA9034 PMIC" | ||
77 | depends on PMIC_DA903X | ||
78 | select REGULATOR | ||
79 | help | ||
80 | Say y here to support the BUCKs and LDOs regulators found on | ||
81 | Dialog Semiconductor DA9030/DA9034 PMIC. | ||
82 | |||
59 | endmenu | 83 | endmenu |
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index ac2c64efe65c..254d40c02ee8 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile | |||
@@ -8,5 +8,8 @@ obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o | |||
8 | obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o | 8 | obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o |
9 | 9 | ||
10 | obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o | 10 | obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o |
11 | obj-$(CONFIG_REGULATOR_WM8350) += wm8350-regulator.o | ||
12 | obj-$(CONFIG_REGULATOR_WM8400) += wm8400-regulator.o | ||
13 | obj-$(CONFIG_REGULATOR_DA903X) += da903x.o | ||
11 | 14 | ||
12 | ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG | 15 | ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG |
diff --git a/drivers/regulator/bq24022.c b/drivers/regulator/bq24022.c index 263699d6152d..366565aba865 100644 --- a/drivers/regulator/bq24022.c +++ b/drivers/regulator/bq24022.c | |||
@@ -18,13 +18,13 @@ | |||
18 | #include <linux/regulator/bq24022.h> | 18 | #include <linux/regulator/bq24022.h> |
19 | #include <linux/regulator/driver.h> | 19 | #include <linux/regulator/driver.h> |
20 | 20 | ||
21 | |||
21 | static int bq24022_set_current_limit(struct regulator_dev *rdev, | 22 | static int bq24022_set_current_limit(struct regulator_dev *rdev, |
22 | int min_uA, int max_uA) | 23 | int min_uA, int max_uA) |
23 | { | 24 | { |
24 | struct platform_device *pdev = rdev_get_drvdata(rdev); | 25 | struct bq24022_mach_info *pdata = rdev_get_drvdata(rdev); |
25 | struct bq24022_mach_info *pdata = pdev->dev.platform_data; | ||
26 | 26 | ||
27 | dev_dbg(&pdev->dev, "setting current limit to %s mA\n", | 27 | dev_dbg(rdev_get_dev(rdev), "setting current limit to %s mA\n", |
28 | max_uA >= 500000 ? "500" : "100"); | 28 | max_uA >= 500000 ? "500" : "100"); |
29 | 29 | ||
30 | /* REVISIT: maybe return error if min_uA != 0 ? */ | 30 | /* REVISIT: maybe return error if min_uA != 0 ? */ |
@@ -34,18 +34,16 @@ static int bq24022_set_current_limit(struct regulator_dev *rdev, | |||
34 | 34 | ||
35 | static int bq24022_get_current_limit(struct regulator_dev *rdev) | 35 | static int bq24022_get_current_limit(struct regulator_dev *rdev) |
36 | { | 36 | { |
37 | struct platform_device *pdev = rdev_get_drvdata(rdev); | 37 | struct bq24022_mach_info *pdata = rdev_get_drvdata(rdev); |
38 | struct bq24022_mach_info *pdata = pdev->dev.platform_data; | ||
39 | 38 | ||
40 | return gpio_get_value(pdata->gpio_iset2) ? 500000 : 100000; | 39 | return gpio_get_value(pdata->gpio_iset2) ? 500000 : 100000; |
41 | } | 40 | } |
42 | 41 | ||
43 | static int bq24022_enable(struct regulator_dev *rdev) | 42 | static int bq24022_enable(struct regulator_dev *rdev) |
44 | { | 43 | { |
45 | struct platform_device *pdev = rdev_get_drvdata(rdev); | 44 | struct bq24022_mach_info *pdata = rdev_get_drvdata(rdev); |
46 | struct bq24022_mach_info *pdata = pdev->dev.platform_data; | ||
47 | 45 | ||
48 | dev_dbg(&pdev->dev, "enabling charger\n"); | 46 | dev_dbg(rdev_get_dev(rdev), "enabling charger\n"); |
49 | 47 | ||
50 | gpio_set_value(pdata->gpio_nce, 0); | 48 | gpio_set_value(pdata->gpio_nce, 0); |
51 | return 0; | 49 | return 0; |
@@ -53,10 +51,9 @@ static int bq24022_enable(struct regulator_dev *rdev) | |||
53 | 51 | ||
54 | static int bq24022_disable(struct regulator_dev *rdev) | 52 | static int bq24022_disable(struct regulator_dev *rdev) |
55 | { | 53 | { |
56 | struct platform_device *pdev = rdev_get_drvdata(rdev); | 54 | struct bq24022_mach_info *pdata = rdev_get_drvdata(rdev); |
57 | struct bq24022_mach_info *pdata = pdev->dev.platform_data; | ||
58 | 55 | ||
59 | dev_dbg(&pdev->dev, "disabling charger\n"); | 56 | dev_dbg(rdev_get_dev(rdev), "disabling charger\n"); |
60 | 57 | ||
61 | gpio_set_value(pdata->gpio_nce, 1); | 58 | gpio_set_value(pdata->gpio_nce, 1); |
62 | return 0; | 59 | return 0; |
@@ -108,7 +105,7 @@ static int __init bq24022_probe(struct platform_device *pdev) | |||
108 | ret = gpio_direction_output(pdata->gpio_iset2, 0); | 105 | ret = gpio_direction_output(pdata->gpio_iset2, 0); |
109 | ret = gpio_direction_output(pdata->gpio_nce, 1); | 106 | ret = gpio_direction_output(pdata->gpio_nce, 1); |
110 | 107 | ||
111 | bq24022 = regulator_register(&bq24022_desc, pdev); | 108 | bq24022 = regulator_register(&bq24022_desc, &pdev->dev, pdata); |
112 | if (IS_ERR(bq24022)) { | 109 | if (IS_ERR(bq24022)) { |
113 | dev_dbg(&pdev->dev, "couldn't register regulator\n"); | 110 | dev_dbg(&pdev->dev, "couldn't register regulator\n"); |
114 | ret = PTR_ERR(bq24022); | 111 | ret = PTR_ERR(bq24022); |
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 9c7986261568..02a774424e8d 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c | |||
@@ -2,8 +2,9 @@ | |||
2 | * core.c -- Voltage/Current Regulator framework. | 2 | * core.c -- Voltage/Current Regulator framework. |
3 | * | 3 | * |
4 | * Copyright 2007, 2008 Wolfson Microelectronics PLC. | 4 | * Copyright 2007, 2008 Wolfson Microelectronics PLC. |
5 | * Copyright 2008 SlimLogic Ltd. | ||
5 | * | 6 | * |
6 | * Author: Liam Girdwood <liam.girdwood@wolfsonmicro.com> | 7 | * Author: Liam Girdwood <lrg@slimlogic.co.uk> |
7 | * | 8 | * |
8 | * This program is free software; you can redistribute it and/or modify it | 9 | * This program is free software; you can redistribute it and/or modify it |
9 | * under the terms of the GNU General Public License as published by the | 10 | * under the terms of the GNU General Public License as published by the |
@@ -64,14 +65,9 @@ struct regulator_map { | |||
64 | struct list_head list; | 65 | struct list_head list; |
65 | struct device *dev; | 66 | struct device *dev; |
66 | const char *supply; | 67 | const char *supply; |
67 | const char *regulator; | 68 | struct regulator_dev *regulator; |
68 | }; | 69 | }; |
69 | 70 | ||
70 | static inline struct regulator_dev *to_rdev(struct device *d) | ||
71 | { | ||
72 | return container_of(d, struct regulator_dev, dev); | ||
73 | } | ||
74 | |||
75 | /* | 71 | /* |
76 | * struct regulator | 72 | * struct regulator |
77 | * | 73 | * |
@@ -227,7 +223,7 @@ static ssize_t device_requested_uA_show(struct device *dev, | |||
227 | static ssize_t regulator_uV_show(struct device *dev, | 223 | static ssize_t regulator_uV_show(struct device *dev, |
228 | struct device_attribute *attr, char *buf) | 224 | struct device_attribute *attr, char *buf) |
229 | { | 225 | { |
230 | struct regulator_dev *rdev = to_rdev(dev); | 226 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
231 | ssize_t ret; | 227 | ssize_t ret; |
232 | 228 | ||
233 | mutex_lock(&rdev->mutex); | 229 | mutex_lock(&rdev->mutex); |
@@ -240,15 +236,31 @@ static ssize_t regulator_uV_show(struct device *dev, | |||
240 | static ssize_t regulator_uA_show(struct device *dev, | 236 | static ssize_t regulator_uA_show(struct device *dev, |
241 | struct device_attribute *attr, char *buf) | 237 | struct device_attribute *attr, char *buf) |
242 | { | 238 | { |
243 | struct regulator_dev *rdev = to_rdev(dev); | 239 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
244 | 240 | ||
245 | return sprintf(buf, "%d\n", _regulator_get_current_limit(rdev)); | 241 | return sprintf(buf, "%d\n", _regulator_get_current_limit(rdev)); |
246 | } | 242 | } |
247 | 243 | ||
244 | static ssize_t regulator_name_show(struct device *dev, | ||
245 | struct device_attribute *attr, char *buf) | ||
246 | { | ||
247 | struct regulator_dev *rdev = dev_get_drvdata(dev); | ||
248 | const char *name; | ||
249 | |||
250 | if (rdev->constraints->name) | ||
251 | name = rdev->constraints->name; | ||
252 | else if (rdev->desc->name) | ||
253 | name = rdev->desc->name; | ||
254 | else | ||
255 | name = ""; | ||
256 | |||
257 | return sprintf(buf, "%s\n", name); | ||
258 | } | ||
259 | |||
248 | static ssize_t regulator_opmode_show(struct device *dev, | 260 | static ssize_t regulator_opmode_show(struct device *dev, |
249 | struct device_attribute *attr, char *buf) | 261 | struct device_attribute *attr, char *buf) |
250 | { | 262 | { |
251 | struct regulator_dev *rdev = to_rdev(dev); | 263 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
252 | int mode = _regulator_get_mode(rdev); | 264 | int mode = _regulator_get_mode(rdev); |
253 | 265 | ||
254 | switch (mode) { | 266 | switch (mode) { |
@@ -267,7 +279,7 @@ static ssize_t regulator_opmode_show(struct device *dev, | |||
267 | static ssize_t regulator_state_show(struct device *dev, | 279 | static ssize_t regulator_state_show(struct device *dev, |
268 | struct device_attribute *attr, char *buf) | 280 | struct device_attribute *attr, char *buf) |
269 | { | 281 | { |
270 | struct regulator_dev *rdev = to_rdev(dev); | 282 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
271 | int state = _regulator_is_enabled(rdev); | 283 | int state = _regulator_is_enabled(rdev); |
272 | 284 | ||
273 | if (state > 0) | 285 | if (state > 0) |
@@ -281,7 +293,7 @@ static ssize_t regulator_state_show(struct device *dev, | |||
281 | static ssize_t regulator_min_uA_show(struct device *dev, | 293 | static ssize_t regulator_min_uA_show(struct device *dev, |
282 | struct device_attribute *attr, char *buf) | 294 | struct device_attribute *attr, char *buf) |
283 | { | 295 | { |
284 | struct regulator_dev *rdev = to_rdev(dev); | 296 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
285 | 297 | ||
286 | if (!rdev->constraints) | 298 | if (!rdev->constraints) |
287 | return sprintf(buf, "constraint not defined\n"); | 299 | return sprintf(buf, "constraint not defined\n"); |
@@ -292,7 +304,7 @@ static ssize_t regulator_min_uA_show(struct device *dev, | |||
292 | static ssize_t regulator_max_uA_show(struct device *dev, | 304 | static ssize_t regulator_max_uA_show(struct device *dev, |
293 | struct device_attribute *attr, char *buf) | 305 | struct device_attribute *attr, char *buf) |
294 | { | 306 | { |
295 | struct regulator_dev *rdev = to_rdev(dev); | 307 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
296 | 308 | ||
297 | if (!rdev->constraints) | 309 | if (!rdev->constraints) |
298 | return sprintf(buf, "constraint not defined\n"); | 310 | return sprintf(buf, "constraint not defined\n"); |
@@ -303,7 +315,7 @@ static ssize_t regulator_max_uA_show(struct device *dev, | |||
303 | static ssize_t regulator_min_uV_show(struct device *dev, | 315 | static ssize_t regulator_min_uV_show(struct device *dev, |
304 | struct device_attribute *attr, char *buf) | 316 | struct device_attribute *attr, char *buf) |
305 | { | 317 | { |
306 | struct regulator_dev *rdev = to_rdev(dev); | 318 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
307 | 319 | ||
308 | if (!rdev->constraints) | 320 | if (!rdev->constraints) |
309 | return sprintf(buf, "constraint not defined\n"); | 321 | return sprintf(buf, "constraint not defined\n"); |
@@ -314,7 +326,7 @@ static ssize_t regulator_min_uV_show(struct device *dev, | |||
314 | static ssize_t regulator_max_uV_show(struct device *dev, | 326 | static ssize_t regulator_max_uV_show(struct device *dev, |
315 | struct device_attribute *attr, char *buf) | 327 | struct device_attribute *attr, char *buf) |
316 | { | 328 | { |
317 | struct regulator_dev *rdev = to_rdev(dev); | 329 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
318 | 330 | ||
319 | if (!rdev->constraints) | 331 | if (!rdev->constraints) |
320 | return sprintf(buf, "constraint not defined\n"); | 332 | return sprintf(buf, "constraint not defined\n"); |
@@ -325,7 +337,7 @@ static ssize_t regulator_max_uV_show(struct device *dev, | |||
325 | static ssize_t regulator_total_uA_show(struct device *dev, | 337 | static ssize_t regulator_total_uA_show(struct device *dev, |
326 | struct device_attribute *attr, char *buf) | 338 | struct device_attribute *attr, char *buf) |
327 | { | 339 | { |
328 | struct regulator_dev *rdev = to_rdev(dev); | 340 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
329 | struct regulator *regulator; | 341 | struct regulator *regulator; |
330 | int uA = 0; | 342 | int uA = 0; |
331 | 343 | ||
@@ -339,14 +351,14 @@ static ssize_t regulator_total_uA_show(struct device *dev, | |||
339 | static ssize_t regulator_num_users_show(struct device *dev, | 351 | static ssize_t regulator_num_users_show(struct device *dev, |
340 | struct device_attribute *attr, char *buf) | 352 | struct device_attribute *attr, char *buf) |
341 | { | 353 | { |
342 | struct regulator_dev *rdev = to_rdev(dev); | 354 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
343 | return sprintf(buf, "%d\n", rdev->use_count); | 355 | return sprintf(buf, "%d\n", rdev->use_count); |
344 | } | 356 | } |
345 | 357 | ||
346 | static ssize_t regulator_type_show(struct device *dev, | 358 | static ssize_t regulator_type_show(struct device *dev, |
347 | struct device_attribute *attr, char *buf) | 359 | struct device_attribute *attr, char *buf) |
348 | { | 360 | { |
349 | struct regulator_dev *rdev = to_rdev(dev); | 361 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
350 | 362 | ||
351 | switch (rdev->desc->type) { | 363 | switch (rdev->desc->type) { |
352 | case REGULATOR_VOLTAGE: | 364 | case REGULATOR_VOLTAGE: |
@@ -360,7 +372,7 @@ static ssize_t regulator_type_show(struct device *dev, | |||
360 | static ssize_t regulator_suspend_mem_uV_show(struct device *dev, | 372 | static ssize_t regulator_suspend_mem_uV_show(struct device *dev, |
361 | struct device_attribute *attr, char *buf) | 373 | struct device_attribute *attr, char *buf) |
362 | { | 374 | { |
363 | struct regulator_dev *rdev = to_rdev(dev); | 375 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
364 | 376 | ||
365 | if (!rdev->constraints) | 377 | if (!rdev->constraints) |
366 | return sprintf(buf, "not defined\n"); | 378 | return sprintf(buf, "not defined\n"); |
@@ -370,7 +382,7 @@ static ssize_t regulator_suspend_mem_uV_show(struct device *dev, | |||
370 | static ssize_t regulator_suspend_disk_uV_show(struct device *dev, | 382 | static ssize_t regulator_suspend_disk_uV_show(struct device *dev, |
371 | struct device_attribute *attr, char *buf) | 383 | struct device_attribute *attr, char *buf) |
372 | { | 384 | { |
373 | struct regulator_dev *rdev = to_rdev(dev); | 385 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
374 | 386 | ||
375 | if (!rdev->constraints) | 387 | if (!rdev->constraints) |
376 | return sprintf(buf, "not defined\n"); | 388 | return sprintf(buf, "not defined\n"); |
@@ -380,7 +392,7 @@ static ssize_t regulator_suspend_disk_uV_show(struct device *dev, | |||
380 | static ssize_t regulator_suspend_standby_uV_show(struct device *dev, | 392 | static ssize_t regulator_suspend_standby_uV_show(struct device *dev, |
381 | struct device_attribute *attr, char *buf) | 393 | struct device_attribute *attr, char *buf) |
382 | { | 394 | { |
383 | struct regulator_dev *rdev = to_rdev(dev); | 395 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
384 | 396 | ||
385 | if (!rdev->constraints) | 397 | if (!rdev->constraints) |
386 | return sprintf(buf, "not defined\n"); | 398 | return sprintf(buf, "not defined\n"); |
@@ -406,7 +418,7 @@ static ssize_t suspend_opmode_show(struct regulator_dev *rdev, | |||
406 | static ssize_t regulator_suspend_mem_mode_show(struct device *dev, | 418 | static ssize_t regulator_suspend_mem_mode_show(struct device *dev, |
407 | struct device_attribute *attr, char *buf) | 419 | struct device_attribute *attr, char *buf) |
408 | { | 420 | { |
409 | struct regulator_dev *rdev = to_rdev(dev); | 421 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
410 | 422 | ||
411 | if (!rdev->constraints) | 423 | if (!rdev->constraints) |
412 | return sprintf(buf, "not defined\n"); | 424 | return sprintf(buf, "not defined\n"); |
@@ -417,7 +429,7 @@ static ssize_t regulator_suspend_mem_mode_show(struct device *dev, | |||
417 | static ssize_t regulator_suspend_disk_mode_show(struct device *dev, | 429 | static ssize_t regulator_suspend_disk_mode_show(struct device *dev, |
418 | struct device_attribute *attr, char *buf) | 430 | struct device_attribute *attr, char *buf) |
419 | { | 431 | { |
420 | struct regulator_dev *rdev = to_rdev(dev); | 432 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
421 | 433 | ||
422 | if (!rdev->constraints) | 434 | if (!rdev->constraints) |
423 | return sprintf(buf, "not defined\n"); | 435 | return sprintf(buf, "not defined\n"); |
@@ -428,7 +440,7 @@ static ssize_t regulator_suspend_disk_mode_show(struct device *dev, | |||
428 | static ssize_t regulator_suspend_standby_mode_show(struct device *dev, | 440 | static ssize_t regulator_suspend_standby_mode_show(struct device *dev, |
429 | struct device_attribute *attr, char *buf) | 441 | struct device_attribute *attr, char *buf) |
430 | { | 442 | { |
431 | struct regulator_dev *rdev = to_rdev(dev); | 443 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
432 | 444 | ||
433 | if (!rdev->constraints) | 445 | if (!rdev->constraints) |
434 | return sprintf(buf, "not defined\n"); | 446 | return sprintf(buf, "not defined\n"); |
@@ -439,7 +451,7 @@ static ssize_t regulator_suspend_standby_mode_show(struct device *dev, | |||
439 | static ssize_t regulator_suspend_mem_state_show(struct device *dev, | 451 | static ssize_t regulator_suspend_mem_state_show(struct device *dev, |
440 | struct device_attribute *attr, char *buf) | 452 | struct device_attribute *attr, char *buf) |
441 | { | 453 | { |
442 | struct regulator_dev *rdev = to_rdev(dev); | 454 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
443 | 455 | ||
444 | if (!rdev->constraints) | 456 | if (!rdev->constraints) |
445 | return sprintf(buf, "not defined\n"); | 457 | return sprintf(buf, "not defined\n"); |
@@ -453,7 +465,7 @@ static ssize_t regulator_suspend_mem_state_show(struct device *dev, | |||
453 | static ssize_t regulator_suspend_disk_state_show(struct device *dev, | 465 | static ssize_t regulator_suspend_disk_state_show(struct device *dev, |
454 | struct device_attribute *attr, char *buf) | 466 | struct device_attribute *attr, char *buf) |
455 | { | 467 | { |
456 | struct regulator_dev *rdev = to_rdev(dev); | 468 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
457 | 469 | ||
458 | if (!rdev->constraints) | 470 | if (!rdev->constraints) |
459 | return sprintf(buf, "not defined\n"); | 471 | return sprintf(buf, "not defined\n"); |
@@ -467,7 +479,7 @@ static ssize_t regulator_suspend_disk_state_show(struct device *dev, | |||
467 | static ssize_t regulator_suspend_standby_state_show(struct device *dev, | 479 | static ssize_t regulator_suspend_standby_state_show(struct device *dev, |
468 | struct device_attribute *attr, char *buf) | 480 | struct device_attribute *attr, char *buf) |
469 | { | 481 | { |
470 | struct regulator_dev *rdev = to_rdev(dev); | 482 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
471 | 483 | ||
472 | if (!rdev->constraints) | 484 | if (!rdev->constraints) |
473 | return sprintf(buf, "not defined\n"); | 485 | return sprintf(buf, "not defined\n"); |
@@ -477,7 +489,9 @@ static ssize_t regulator_suspend_standby_state_show(struct device *dev, | |||
477 | else | 489 | else |
478 | return sprintf(buf, "disabled\n"); | 490 | return sprintf(buf, "disabled\n"); |
479 | } | 491 | } |
492 | |||
480 | static struct device_attribute regulator_dev_attrs[] = { | 493 | static struct device_attribute regulator_dev_attrs[] = { |
494 | __ATTR(name, 0444, regulator_name_show, NULL), | ||
481 | __ATTR(microvolts, 0444, regulator_uV_show, NULL), | 495 | __ATTR(microvolts, 0444, regulator_uV_show, NULL), |
482 | __ATTR(microamps, 0444, regulator_uA_show, NULL), | 496 | __ATTR(microamps, 0444, regulator_uA_show, NULL), |
483 | __ATTR(opmode, 0444, regulator_opmode_show, NULL), | 497 | __ATTR(opmode, 0444, regulator_opmode_show, NULL), |
@@ -512,7 +526,7 @@ static struct device_attribute regulator_dev_attrs[] = { | |||
512 | 526 | ||
513 | static void regulator_dev_release(struct device *dev) | 527 | static void regulator_dev_release(struct device *dev) |
514 | { | 528 | { |
515 | struct regulator_dev *rdev = to_rdev(dev); | 529 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
516 | kfree(rdev); | 530 | kfree(rdev); |
517 | } | 531 | } |
518 | 532 | ||
@@ -569,8 +583,11 @@ static int suspend_set_state(struct regulator_dev *rdev, | |||
569 | 583 | ||
570 | /* enable & disable are mandatory for suspend control */ | 584 | /* enable & disable are mandatory for suspend control */ |
571 | if (!rdev->desc->ops->set_suspend_enable || | 585 | if (!rdev->desc->ops->set_suspend_enable || |
572 | !rdev->desc->ops->set_suspend_disable) | 586 | !rdev->desc->ops->set_suspend_disable) { |
587 | printk(KERN_ERR "%s: no way to set suspend state\n", | ||
588 | __func__); | ||
573 | return -EINVAL; | 589 | return -EINVAL; |
590 | } | ||
574 | 591 | ||
575 | if (rstate->enabled) | 592 | if (rstate->enabled) |
576 | ret = rdev->desc->ops->set_suspend_enable(rdev); | 593 | ret = rdev->desc->ops->set_suspend_enable(rdev); |
@@ -656,6 +673,155 @@ static void print_constraints(struct regulator_dev *rdev) | |||
656 | printk(KERN_INFO "regulator: %s: %s\n", rdev->desc->name, buf); | 673 | printk(KERN_INFO "regulator: %s: %s\n", rdev->desc->name, buf); |
657 | } | 674 | } |
658 | 675 | ||
676 | /** | ||
677 | * set_machine_constraints - sets regulator constraints | ||
678 | * @regulator: regulator source | ||
679 | * | ||
680 | * Allows platform initialisation code to define and constrain | ||
681 | * regulator circuits e.g. valid voltage/current ranges, etc. NOTE: | ||
682 | * Constraints *must* be set by platform code in order for some | ||
683 | * regulator operations to proceed i.e. set_voltage, set_current_limit, | ||
684 | * set_mode. | ||
685 | */ | ||
686 | static int set_machine_constraints(struct regulator_dev *rdev, | ||
687 | struct regulation_constraints *constraints) | ||
688 | { | ||
689 | int ret = 0; | ||
690 | const char *name; | ||
691 | struct regulator_ops *ops = rdev->desc->ops; | ||
692 | |||
693 | if (constraints->name) | ||
694 | name = constraints->name; | ||
695 | else if (rdev->desc->name) | ||
696 | name = rdev->desc->name; | ||
697 | else | ||
698 | name = "regulator"; | ||
699 | |||
700 | rdev->constraints = constraints; | ||
701 | |||
702 | /* do we need to apply the constraint voltage */ | ||
703 | if (rdev->constraints->apply_uV && | ||
704 | rdev->constraints->min_uV == rdev->constraints->max_uV && | ||
705 | ops->set_voltage) { | ||
706 | ret = ops->set_voltage(rdev, | ||
707 | rdev->constraints->min_uV, rdev->constraints->max_uV); | ||
708 | if (ret < 0) { | ||
709 | printk(KERN_ERR "%s: failed to apply %duV constraint to %s\n", | ||
710 | __func__, | ||
711 | rdev->constraints->min_uV, name); | ||
712 | rdev->constraints = NULL; | ||
713 | goto out; | ||
714 | } | ||
715 | } | ||
716 | |||
717 | /* are we enabled at boot time by firmware / bootloader */ | ||
718 | if (rdev->constraints->boot_on) | ||
719 | rdev->use_count = 1; | ||
720 | |||
721 | /* do we need to setup our suspend state */ | ||
722 | if (constraints->initial_state) { | ||
723 | ret = suspend_prepare(rdev, constraints->initial_state); | ||
724 | if (ret < 0) { | ||
725 | printk(KERN_ERR "%s: failed to set suspend state for %s\n", | ||
726 | __func__, name); | ||
727 | rdev->constraints = NULL; | ||
728 | goto out; | ||
729 | } | ||
730 | } | ||
731 | |||
732 | /* if always_on is set then turn the regulator on if it's not | ||
733 | * already on. */ | ||
734 | if (constraints->always_on && ops->enable && | ||
735 | ((ops->is_enabled && !ops->is_enabled(rdev)) || | ||
736 | (!ops->is_enabled && !constraints->boot_on))) { | ||
737 | ret = ops->enable(rdev); | ||
738 | if (ret < 0) { | ||
739 | printk(KERN_ERR "%s: failed to enable %s\n", | ||
740 | __func__, name); | ||
741 | rdev->constraints = NULL; | ||
742 | goto out; | ||
743 | } | ||
744 | } | ||
745 | |||
746 | print_constraints(rdev); | ||
747 | out: | ||
748 | return ret; | ||
749 | } | ||
750 | |||
751 | /** | ||
752 | * set_supply - set regulator supply regulator | ||
753 | * @regulator: regulator name | ||
754 | * @supply: supply regulator name | ||
755 | * | ||
756 | * Called by platform initialisation code to set the supply regulator for this | ||
757 | * regulator. This ensures that a regulators supply will also be enabled by the | ||
758 | * core if it's child is enabled. | ||
759 | */ | ||
760 | static int set_supply(struct regulator_dev *rdev, | ||
761 | struct regulator_dev *supply_rdev) | ||
762 | { | ||
763 | int err; | ||
764 | |||
765 | err = sysfs_create_link(&rdev->dev.kobj, &supply_rdev->dev.kobj, | ||
766 | "supply"); | ||
767 | if (err) { | ||
768 | printk(KERN_ERR | ||
769 | "%s: could not add device link %s err %d\n", | ||
770 | __func__, supply_rdev->dev.kobj.name, err); | ||
771 | goto out; | ||
772 | } | ||
773 | rdev->supply = supply_rdev; | ||
774 | list_add(&rdev->slist, &supply_rdev->supply_list); | ||
775 | out: | ||
776 | return err; | ||
777 | } | ||
778 | |||
779 | /** | ||
780 | * set_consumer_device_supply: Bind a regulator to a symbolic supply | ||
781 | * @regulator: regulator source | ||
782 | * @dev: device the supply applies to | ||
783 | * @supply: symbolic name for supply | ||
784 | * | ||
785 | * Allows platform initialisation code to map physical regulator | ||
786 | * sources to symbolic names for supplies for use by devices. Devices | ||
787 | * should use these symbolic names to request regulators, avoiding the | ||
788 | * need to provide board-specific regulator names as platform data. | ||
789 | */ | ||
790 | static int set_consumer_device_supply(struct regulator_dev *rdev, | ||
791 | struct device *consumer_dev, const char *supply) | ||
792 | { | ||
793 | struct regulator_map *node; | ||
794 | |||
795 | if (supply == NULL) | ||
796 | return -EINVAL; | ||
797 | |||
798 | node = kmalloc(sizeof(struct regulator_map), GFP_KERNEL); | ||
799 | if (node == NULL) | ||
800 | return -ENOMEM; | ||
801 | |||
802 | node->regulator = rdev; | ||
803 | node->dev = consumer_dev; | ||
804 | node->supply = supply; | ||
805 | |||
806 | list_add(&node->list, ®ulator_map_list); | ||
807 | return 0; | ||
808 | } | ||
809 | |||
810 | static void unset_consumer_device_supply(struct regulator_dev *rdev, | ||
811 | struct device *consumer_dev) | ||
812 | { | ||
813 | struct regulator_map *node, *n; | ||
814 | |||
815 | list_for_each_entry_safe(node, n, ®ulator_map_list, list) { | ||
816 | if (rdev == node->regulator && | ||
817 | consumer_dev == node->dev) { | ||
818 | list_del(&node->list); | ||
819 | kfree(node); | ||
820 | return; | ||
821 | } | ||
822 | } | ||
823 | } | ||
824 | |||
659 | #define REG_STR_SIZE 32 | 825 | #define REG_STR_SIZE 32 |
660 | 826 | ||
661 | static struct regulator *create_regulator(struct regulator_dev *rdev, | 827 | static struct regulator *create_regulator(struct regulator_dev *rdev, |
@@ -746,7 +912,6 @@ struct regulator *regulator_get(struct device *dev, const char *id) | |||
746 | struct regulator_dev *rdev; | 912 | struct regulator_dev *rdev; |
747 | struct regulator_map *map; | 913 | struct regulator_map *map; |
748 | struct regulator *regulator = ERR_PTR(-ENODEV); | 914 | struct regulator *regulator = ERR_PTR(-ENODEV); |
749 | const char *supply = id; | ||
750 | 915 | ||
751 | if (id == NULL) { | 916 | if (id == NULL) { |
752 | printk(KERN_ERR "regulator: get() with no identifier\n"); | 917 | printk(KERN_ERR "regulator: get() with no identifier\n"); |
@@ -758,15 +923,9 @@ struct regulator *regulator_get(struct device *dev, const char *id) | |||
758 | list_for_each_entry(map, ®ulator_map_list, list) { | 923 | list_for_each_entry(map, ®ulator_map_list, list) { |
759 | if (dev == map->dev && | 924 | if (dev == map->dev && |
760 | strcmp(map->supply, id) == 0) { | 925 | strcmp(map->supply, id) == 0) { |
761 | supply = map->regulator; | 926 | rdev = map->regulator; |
762 | break; | ||
763 | } | ||
764 | } | ||
765 | |||
766 | list_for_each_entry(rdev, ®ulator_list, list) { | ||
767 | if (strcmp(supply, rdev->desc->name) == 0 && | ||
768 | try_module_get(rdev->owner)) | ||
769 | goto found; | 927 | goto found; |
928 | } | ||
770 | } | 929 | } |
771 | printk(KERN_ERR "regulator: Unable to get requested regulator: %s\n", | 930 | printk(KERN_ERR "regulator: Unable to get requested regulator: %s\n", |
772 | id); | 931 | id); |
@@ -774,12 +933,16 @@ struct regulator *regulator_get(struct device *dev, const char *id) | |||
774 | return regulator; | 933 | return regulator; |
775 | 934 | ||
776 | found: | 935 | found: |
936 | if (!try_module_get(rdev->owner)) | ||
937 | goto out; | ||
938 | |||
777 | regulator = create_regulator(rdev, dev, id); | 939 | regulator = create_regulator(rdev, dev, id); |
778 | if (regulator == NULL) { | 940 | if (regulator == NULL) { |
779 | regulator = ERR_PTR(-ENOMEM); | 941 | regulator = ERR_PTR(-ENOMEM); |
780 | module_put(rdev->owner); | 942 | module_put(rdev->owner); |
781 | } | 943 | } |
782 | 944 | ||
945 | out: | ||
783 | mutex_unlock(®ulator_list_mutex); | 946 | mutex_unlock(®ulator_list_mutex); |
784 | return regulator; | 947 | return regulator; |
785 | } | 948 | } |
@@ -1559,11 +1722,12 @@ EXPORT_SYMBOL_GPL(regulator_notifier_call_chain); | |||
1559 | * Returns 0 on success. | 1722 | * Returns 0 on success. |
1560 | */ | 1723 | */ |
1561 | struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, | 1724 | struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, |
1562 | void *reg_data) | 1725 | struct device *dev, void *driver_data) |
1563 | { | 1726 | { |
1564 | static atomic_t regulator_no = ATOMIC_INIT(0); | 1727 | static atomic_t regulator_no = ATOMIC_INIT(0); |
1565 | struct regulator_dev *rdev; | 1728 | struct regulator_dev *rdev; |
1566 | int ret; | 1729 | struct regulator_init_data *init_data = dev->platform_data; |
1730 | int ret, i; | ||
1567 | 1731 | ||
1568 | if (regulator_desc == NULL) | 1732 | if (regulator_desc == NULL) |
1569 | return ERR_PTR(-EINVAL); | 1733 | return ERR_PTR(-EINVAL); |
@@ -1575,6 +1739,9 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, | |||
1575 | !regulator_desc->type == REGULATOR_CURRENT) | 1739 | !regulator_desc->type == REGULATOR_CURRENT) |
1576 | return ERR_PTR(-EINVAL); | 1740 | return ERR_PTR(-EINVAL); |
1577 | 1741 | ||
1742 | if (!init_data) | ||
1743 | return ERR_PTR(-EINVAL); | ||
1744 | |||
1578 | rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL); | 1745 | rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL); |
1579 | if (rdev == NULL) | 1746 | if (rdev == NULL) |
1580 | return ERR_PTR(-ENOMEM); | 1747 | return ERR_PTR(-ENOMEM); |
@@ -1582,7 +1749,7 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, | |||
1582 | mutex_lock(®ulator_list_mutex); | 1749 | mutex_lock(®ulator_list_mutex); |
1583 | 1750 | ||
1584 | mutex_init(&rdev->mutex); | 1751 | mutex_init(&rdev->mutex); |
1585 | rdev->reg_data = reg_data; | 1752 | rdev->reg_data = driver_data; |
1586 | rdev->owner = regulator_desc->owner; | 1753 | rdev->owner = regulator_desc->owner; |
1587 | rdev->desc = regulator_desc; | 1754 | rdev->desc = regulator_desc; |
1588 | INIT_LIST_HEAD(&rdev->consumer_list); | 1755 | INIT_LIST_HEAD(&rdev->consumer_list); |
@@ -1591,20 +1758,68 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, | |||
1591 | INIT_LIST_HEAD(&rdev->slist); | 1758 | INIT_LIST_HEAD(&rdev->slist); |
1592 | BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier); | 1759 | BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier); |
1593 | 1760 | ||
1761 | /* preform any regulator specific init */ | ||
1762 | if (init_data->regulator_init) { | ||
1763 | ret = init_data->regulator_init(rdev->reg_data); | ||
1764 | if (ret < 0) { | ||
1765 | kfree(rdev); | ||
1766 | rdev = ERR_PTR(ret); | ||
1767 | goto out; | ||
1768 | } | ||
1769 | } | ||
1770 | |||
1771 | /* set regulator constraints */ | ||
1772 | ret = set_machine_constraints(rdev, &init_data->constraints); | ||
1773 | if (ret < 0) { | ||
1774 | kfree(rdev); | ||
1775 | rdev = ERR_PTR(ret); | ||
1776 | goto out; | ||
1777 | } | ||
1778 | |||
1779 | /* register with sysfs */ | ||
1594 | rdev->dev.class = ®ulator_class; | 1780 | rdev->dev.class = ®ulator_class; |
1595 | device_initialize(&rdev->dev); | 1781 | rdev->dev.parent = dev; |
1596 | snprintf(rdev->dev.bus_id, sizeof(rdev->dev.bus_id), | 1782 | snprintf(rdev->dev.bus_id, sizeof(rdev->dev.bus_id), |
1597 | "regulator_%ld_%s", | 1783 | "regulator.%d", atomic_inc_return(®ulator_no) - 1); |
1598 | (unsigned long)atomic_inc_return(®ulator_no) - 1, | 1784 | ret = device_register(&rdev->dev); |
1599 | regulator_desc->name); | 1785 | if (ret != 0) { |
1600 | |||
1601 | ret = device_add(&rdev->dev); | ||
1602 | if (ret == 0) | ||
1603 | list_add(&rdev->list, ®ulator_list); | ||
1604 | else { | ||
1605 | kfree(rdev); | 1786 | kfree(rdev); |
1606 | rdev = ERR_PTR(ret); | 1787 | rdev = ERR_PTR(ret); |
1788 | goto out; | ||
1789 | } | ||
1790 | |||
1791 | dev_set_drvdata(&rdev->dev, rdev); | ||
1792 | |||
1793 | /* set supply regulator if it exists */ | ||
1794 | if (init_data->supply_regulator_dev) { | ||
1795 | ret = set_supply(rdev, | ||
1796 | dev_get_drvdata(init_data->supply_regulator_dev)); | ||
1797 | if (ret < 0) { | ||
1798 | device_unregister(&rdev->dev); | ||
1799 | kfree(rdev); | ||
1800 | rdev = ERR_PTR(ret); | ||
1801 | goto out; | ||
1802 | } | ||
1607 | } | 1803 | } |
1804 | |||
1805 | /* add consumers devices */ | ||
1806 | for (i = 0; i < init_data->num_consumer_supplies; i++) { | ||
1807 | ret = set_consumer_device_supply(rdev, | ||
1808 | init_data->consumer_supplies[i].dev, | ||
1809 | init_data->consumer_supplies[i].supply); | ||
1810 | if (ret < 0) { | ||
1811 | for (--i; i >= 0; i--) | ||
1812 | unset_consumer_device_supply(rdev, | ||
1813 | init_data->consumer_supplies[i].dev); | ||
1814 | device_unregister(&rdev->dev); | ||
1815 | kfree(rdev); | ||
1816 | rdev = ERR_PTR(ret); | ||
1817 | goto out; | ||
1818 | } | ||
1819 | } | ||
1820 | |||
1821 | list_add(&rdev->list, ®ulator_list); | ||
1822 | out: | ||
1608 | mutex_unlock(®ulator_list_mutex); | 1823 | mutex_unlock(®ulator_list_mutex); |
1609 | return rdev; | 1824 | return rdev; |
1610 | } | 1825 | } |
@@ -1631,187 +1846,6 @@ void regulator_unregister(struct regulator_dev *rdev) | |||
1631 | EXPORT_SYMBOL_GPL(regulator_unregister); | 1846 | EXPORT_SYMBOL_GPL(regulator_unregister); |
1632 | 1847 | ||
1633 | /** | 1848 | /** |
1634 | * regulator_set_supply - set regulator supply regulator | ||
1635 | * @regulator: regulator name | ||
1636 | * @supply: supply regulator name | ||
1637 | * | ||
1638 | * Called by platform initialisation code to set the supply regulator for this | ||
1639 | * regulator. This ensures that a regulators supply will also be enabled by the | ||
1640 | * core if it's child is enabled. | ||
1641 | */ | ||
1642 | int regulator_set_supply(const char *regulator, const char *supply) | ||
1643 | { | ||
1644 | struct regulator_dev *rdev, *supply_rdev; | ||
1645 | int err; | ||
1646 | |||
1647 | if (regulator == NULL || supply == NULL) | ||
1648 | return -EINVAL; | ||
1649 | |||
1650 | mutex_lock(®ulator_list_mutex); | ||
1651 | |||
1652 | list_for_each_entry(rdev, ®ulator_list, list) { | ||
1653 | if (!strcmp(rdev->desc->name, regulator)) | ||
1654 | goto found_regulator; | ||
1655 | } | ||
1656 | mutex_unlock(®ulator_list_mutex); | ||
1657 | return -ENODEV; | ||
1658 | |||
1659 | found_regulator: | ||
1660 | list_for_each_entry(supply_rdev, ®ulator_list, list) { | ||
1661 | if (!strcmp(supply_rdev->desc->name, supply)) | ||
1662 | goto found_supply; | ||
1663 | } | ||
1664 | mutex_unlock(®ulator_list_mutex); | ||
1665 | return -ENODEV; | ||
1666 | |||
1667 | found_supply: | ||
1668 | err = sysfs_create_link(&rdev->dev.kobj, &supply_rdev->dev.kobj, | ||
1669 | "supply"); | ||
1670 | if (err) { | ||
1671 | printk(KERN_ERR | ||
1672 | "%s: could not add device link %s err %d\n", | ||
1673 | __func__, supply_rdev->dev.kobj.name, err); | ||
1674 | goto out; | ||
1675 | } | ||
1676 | rdev->supply = supply_rdev; | ||
1677 | list_add(&rdev->slist, &supply_rdev->supply_list); | ||
1678 | out: | ||
1679 | mutex_unlock(®ulator_list_mutex); | ||
1680 | return err; | ||
1681 | } | ||
1682 | EXPORT_SYMBOL_GPL(regulator_set_supply); | ||
1683 | |||
1684 | /** | ||
1685 | * regulator_get_supply - get regulator supply regulator | ||
1686 | * @regulator: regulator name | ||
1687 | * | ||
1688 | * Returns the supply supply regulator name or NULL if no supply regulator | ||
1689 | * exists (i.e the regulator is supplied directly from USB, Line, Battery, etc) | ||
1690 | */ | ||
1691 | const char *regulator_get_supply(const char *regulator) | ||
1692 | { | ||
1693 | struct regulator_dev *rdev; | ||
1694 | |||
1695 | if (regulator == NULL) | ||
1696 | return NULL; | ||
1697 | |||
1698 | mutex_lock(®ulator_list_mutex); | ||
1699 | list_for_each_entry(rdev, ®ulator_list, list) { | ||
1700 | if (!strcmp(rdev->desc->name, regulator)) | ||
1701 | goto found; | ||
1702 | } | ||
1703 | mutex_unlock(®ulator_list_mutex); | ||
1704 | return NULL; | ||
1705 | |||
1706 | found: | ||
1707 | mutex_unlock(®ulator_list_mutex); | ||
1708 | if (rdev->supply) | ||
1709 | return rdev->supply->desc->name; | ||
1710 | else | ||
1711 | return NULL; | ||
1712 | } | ||
1713 | EXPORT_SYMBOL_GPL(regulator_get_supply); | ||
1714 | |||
1715 | /** | ||
1716 | * regulator_set_machine_constraints - sets regulator constraints | ||
1717 | * @regulator: regulator source | ||
1718 | * | ||
1719 | * Allows platform initialisation code to define and constrain | ||
1720 | * regulator circuits e.g. valid voltage/current ranges, etc. NOTE: | ||
1721 | * Constraints *must* be set by platform code in order for some | ||
1722 | * regulator operations to proceed i.e. set_voltage, set_current_limit, | ||
1723 | * set_mode. | ||
1724 | */ | ||
1725 | int regulator_set_machine_constraints(const char *regulator_name, | ||
1726 | struct regulation_constraints *constraints) | ||
1727 | { | ||
1728 | struct regulator_dev *rdev; | ||
1729 | int ret = 0; | ||
1730 | |||
1731 | if (regulator_name == NULL) | ||
1732 | return -EINVAL; | ||
1733 | |||
1734 | mutex_lock(®ulator_list_mutex); | ||
1735 | |||
1736 | list_for_each_entry(rdev, ®ulator_list, list) { | ||
1737 | if (!strcmp(regulator_name, rdev->desc->name)) | ||
1738 | goto found; | ||
1739 | } | ||
1740 | ret = -ENODEV; | ||
1741 | goto out; | ||
1742 | |||
1743 | found: | ||
1744 | mutex_lock(&rdev->mutex); | ||
1745 | rdev->constraints = constraints; | ||
1746 | |||
1747 | /* do we need to apply the constraint voltage */ | ||
1748 | if (rdev->constraints->apply_uV && | ||
1749 | rdev->constraints->min_uV == rdev->constraints->max_uV && | ||
1750 | rdev->desc->ops->set_voltage) { | ||
1751 | ret = rdev->desc->ops->set_voltage(rdev, | ||
1752 | rdev->constraints->min_uV, rdev->constraints->max_uV); | ||
1753 | if (ret < 0) { | ||
1754 | printk(KERN_ERR "%s: failed to apply %duV" | ||
1755 | " constraint\n", __func__, | ||
1756 | rdev->constraints->min_uV); | ||
1757 | rdev->constraints = NULL; | ||
1758 | goto out; | ||
1759 | } | ||
1760 | } | ||
1761 | |||
1762 | /* are we enabled at boot time by firmware / bootloader */ | ||
1763 | if (rdev->constraints->boot_on) | ||
1764 | rdev->use_count = 1; | ||
1765 | |||
1766 | /* do we need to setup our suspend state */ | ||
1767 | if (constraints->initial_state) | ||
1768 | ret = suspend_prepare(rdev, constraints->initial_state); | ||
1769 | |||
1770 | print_constraints(rdev); | ||
1771 | mutex_unlock(&rdev->mutex); | ||
1772 | |||
1773 | out: | ||
1774 | mutex_unlock(®ulator_list_mutex); | ||
1775 | return ret; | ||
1776 | } | ||
1777 | EXPORT_SYMBOL_GPL(regulator_set_machine_constraints); | ||
1778 | |||
1779 | |||
1780 | /** | ||
1781 | * regulator_set_device_supply: Bind a regulator to a symbolic supply | ||
1782 | * @regulator: regulator source | ||
1783 | * @dev: device the supply applies to | ||
1784 | * @supply: symbolic name for supply | ||
1785 | * | ||
1786 | * Allows platform initialisation code to map physical regulator | ||
1787 | * sources to symbolic names for supplies for use by devices. Devices | ||
1788 | * should use these symbolic names to request regulators, avoiding the | ||
1789 | * need to provide board-specific regulator names as platform data. | ||
1790 | */ | ||
1791 | int regulator_set_device_supply(const char *regulator, struct device *dev, | ||
1792 | const char *supply) | ||
1793 | { | ||
1794 | struct regulator_map *node; | ||
1795 | |||
1796 | if (regulator == NULL || supply == NULL) | ||
1797 | return -EINVAL; | ||
1798 | |||
1799 | node = kmalloc(sizeof(struct regulator_map), GFP_KERNEL); | ||
1800 | if (node == NULL) | ||
1801 | return -ENOMEM; | ||
1802 | |||
1803 | node->regulator = regulator; | ||
1804 | node->dev = dev; | ||
1805 | node->supply = supply; | ||
1806 | |||
1807 | mutex_lock(®ulator_list_mutex); | ||
1808 | list_add(&node->list, ®ulator_map_list); | ||
1809 | mutex_unlock(®ulator_list_mutex); | ||
1810 | return 0; | ||
1811 | } | ||
1812 | EXPORT_SYMBOL_GPL(regulator_set_device_supply); | ||
1813 | |||
1814 | /** | ||
1815 | * regulator_suspend_prepare: prepare regulators for system wide suspend | 1849 | * regulator_suspend_prepare: prepare regulators for system wide suspend |
1816 | * @state: system suspend state | 1850 | * @state: system suspend state |
1817 | * | 1851 | * |
@@ -1893,6 +1927,18 @@ int rdev_get_id(struct regulator_dev *rdev) | |||
1893 | } | 1927 | } |
1894 | EXPORT_SYMBOL_GPL(rdev_get_id); | 1928 | EXPORT_SYMBOL_GPL(rdev_get_id); |
1895 | 1929 | ||
1930 | struct device *rdev_get_dev(struct regulator_dev *rdev) | ||
1931 | { | ||
1932 | return &rdev->dev; | ||
1933 | } | ||
1934 | EXPORT_SYMBOL_GPL(rdev_get_dev); | ||
1935 | |||
1936 | void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data) | ||
1937 | { | ||
1938 | return reg_init_data->driver_data; | ||
1939 | } | ||
1940 | EXPORT_SYMBOL_GPL(regulator_get_init_drvdata); | ||
1941 | |||
1896 | static int __init regulator_init(void) | 1942 | static int __init regulator_init(void) |
1897 | { | 1943 | { |
1898 | printk(KERN_INFO "regulator: core version %s\n", REGULATOR_VERSION); | 1944 | printk(KERN_INFO "regulator: core version %s\n", REGULATOR_VERSION); |
diff --git a/drivers/regulator/da903x.c b/drivers/regulator/da903x.c new file mode 100644 index 000000000000..3688e339db87 --- /dev/null +++ b/drivers/regulator/da903x.c | |||
@@ -0,0 +1,513 @@ | |||
1 | /* | ||
2 | * Regulators driver for Dialog Semiconductor DA903x | ||
3 | * | ||
4 | * Copyright (C) 2006-2008 Marvell International Ltd. | ||
5 | * Copyright (C) 2008 Compulab Ltd. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #include <linux/kernel.h> | ||
13 | #include <linux/init.h> | ||
14 | #include <linux/err.h> | ||
15 | #include <linux/platform_device.h> | ||
16 | #include <linux/regulator/driver.h> | ||
17 | #include <linux/regulator/machine.h> | ||
18 | #include <linux/mfd/da903x.h> | ||
19 | |||
20 | /* DA9030 Registers */ | ||
21 | #define DA9030_INVAL (-1) | ||
22 | #define DA9030_LDO1011 (0x10) | ||
23 | #define DA9030_LDO15 (0x11) | ||
24 | #define DA9030_LDO1416 (0x12) | ||
25 | #define DA9030_LDO1819 (0x13) | ||
26 | #define DA9030_LDO17 (0x14) | ||
27 | #define DA9030_BUCK2DVM1 (0x15) | ||
28 | #define DA9030_BUCK2DVM2 (0x16) | ||
29 | #define DA9030_RCTL11 (0x17) | ||
30 | #define DA9030_RCTL21 (0x18) | ||
31 | #define DA9030_LDO1 (0x90) | ||
32 | #define DA9030_LDO23 (0x91) | ||
33 | #define DA9030_LDO45 (0x92) | ||
34 | #define DA9030_LDO6 (0x93) | ||
35 | #define DA9030_LDO78 (0x94) | ||
36 | #define DA9030_LDO912 (0x95) | ||
37 | #define DA9030_BUCK (0x96) | ||
38 | #define DA9030_RCTL12 (0x97) | ||
39 | #define DA9030_RCTL22 (0x98) | ||
40 | #define DA9030_LDO_UNLOCK (0xa0) | ||
41 | #define DA9030_LDO_UNLOCK_MASK (0xe0) | ||
42 | #define DA9034_OVER1 (0x10) | ||
43 | |||
44 | /* DA9034 Registers */ | ||
45 | #define DA9034_INVAL (-1) | ||
46 | #define DA9034_OVER2 (0x11) | ||
47 | #define DA9034_OVER3 (0x12) | ||
48 | #define DA9034_LDO643 (0x13) | ||
49 | #define DA9034_LDO987 (0x14) | ||
50 | #define DA9034_LDO1110 (0x15) | ||
51 | #define DA9034_LDO1312 (0x16) | ||
52 | #define DA9034_LDO1514 (0x17) | ||
53 | #define DA9034_VCC1 (0x20) | ||
54 | #define DA9034_ADTV1 (0x23) | ||
55 | #define DA9034_ADTV2 (0x24) | ||
56 | #define DA9034_AVRC (0x25) | ||
57 | #define DA9034_CDTV1 (0x26) | ||
58 | #define DA9034_CDTV2 (0x27) | ||
59 | #define DA9034_CVRC (0x28) | ||
60 | #define DA9034_SDTV1 (0x29) | ||
61 | #define DA9034_SDTV2 (0x2a) | ||
62 | #define DA9034_SVRC (0x2b) | ||
63 | #define DA9034_MDTV1 (0x32) | ||
64 | #define DA9034_MDTV2 (0x33) | ||
65 | #define DA9034_MVRC (0x34) | ||
66 | |||
67 | struct da903x_regulator_info { | ||
68 | struct regulator_desc desc; | ||
69 | |||
70 | int min_uV; | ||
71 | int max_uV; | ||
72 | int step_uV; | ||
73 | int vol_reg; | ||
74 | int vol_shift; | ||
75 | int vol_nbits; | ||
76 | int update_reg; | ||
77 | int update_bit; | ||
78 | int enable_reg; | ||
79 | int enable_bit; | ||
80 | }; | ||
81 | |||
82 | static inline int check_range(struct da903x_regulator_info *info, | ||
83 | int min_uV, int max_uV) | ||
84 | { | ||
85 | if (min_uV < info->min_uV || min_uV > info->max_uV) | ||
86 | return -EINVAL; | ||
87 | |||
88 | return 0; | ||
89 | } | ||
90 | |||
91 | /* DA9030/DA9034 common operations */ | ||
92 | static int da903x_set_ldo_voltage(struct regulator_dev *rdev, | ||
93 | int min_uV, int max_uV) | ||
94 | { | ||
95 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | ||
96 | struct device *da9034_dev = rdev_get_dev(rdev)->parent; | ||
97 | uint8_t val, mask; | ||
98 | |||
99 | if (check_range(info, min_uV, max_uV)) { | ||
100 | pr_err("invalid voltage range (%d, %d) uV", min_uV, max_uV); | ||
101 | return -EINVAL; | ||
102 | } | ||
103 | |||
104 | val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV; | ||
105 | val <<= info->vol_shift; | ||
106 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; | ||
107 | |||
108 | return da903x_update(da9034_dev, info->vol_reg, val, mask); | ||
109 | } | ||
110 | |||
111 | static int da903x_get_voltage(struct regulator_dev *rdev) | ||
112 | { | ||
113 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | ||
114 | struct device *da9034_dev = rdev_get_dev(rdev)->parent; | ||
115 | uint8_t val, mask; | ||
116 | int ret; | ||
117 | |||
118 | ret = da903x_read(da9034_dev, info->vol_reg, &val); | ||
119 | if (ret) | ||
120 | return ret; | ||
121 | |||
122 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; | ||
123 | val = (val & mask) >> info->vol_shift; | ||
124 | |||
125 | return info->min_uV + info->step_uV * val; | ||
126 | } | ||
127 | |||
128 | static int da903x_enable(struct regulator_dev *rdev) | ||
129 | { | ||
130 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | ||
131 | struct device *da9034_dev = rdev_get_dev(rdev)->parent; | ||
132 | |||
133 | return da903x_set_bits(da9034_dev, info->enable_reg, | ||
134 | 1 << info->enable_bit); | ||
135 | } | ||
136 | |||
137 | static int da903x_disable(struct regulator_dev *rdev) | ||
138 | { | ||
139 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | ||
140 | struct device *da9034_dev = rdev_get_dev(rdev)->parent; | ||
141 | |||
142 | return da903x_clr_bits(da9034_dev, info->enable_reg, | ||
143 | 1 << info->enable_bit); | ||
144 | } | ||
145 | |||
146 | static int da903x_is_enabled(struct regulator_dev *rdev) | ||
147 | { | ||
148 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | ||
149 | struct device *da9034_dev = rdev_get_dev(rdev)->parent; | ||
150 | uint8_t reg_val; | ||
151 | int ret; | ||
152 | |||
153 | ret = da903x_read(da9034_dev, info->enable_reg, ®_val); | ||
154 | if (ret) | ||
155 | return ret; | ||
156 | |||
157 | return reg_val & (1 << info->enable_bit); | ||
158 | } | ||
159 | |||
160 | /* DA9030 specific operations */ | ||
161 | static int da9030_set_ldo1_15_voltage(struct regulator_dev *rdev, | ||
162 | int min_uV, int max_uV) | ||
163 | { | ||
164 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | ||
165 | struct device *da903x_dev = rdev_get_dev(rdev)->parent; | ||
166 | uint8_t val, mask; | ||
167 | int ret; | ||
168 | |||
169 | if (check_range(info, min_uV, max_uV)) { | ||
170 | pr_err("invalid voltage range (%d, %d) uV", min_uV, max_uV); | ||
171 | return -EINVAL; | ||
172 | } | ||
173 | |||
174 | val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV; | ||
175 | val <<= info->vol_shift; | ||
176 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; | ||
177 | val |= DA9030_LDO_UNLOCK; /* have to set UNLOCK bits */ | ||
178 | mask |= DA9030_LDO_UNLOCK_MASK; | ||
179 | |||
180 | /* write twice */ | ||
181 | ret = da903x_update(da903x_dev, info->vol_reg, val, mask); | ||
182 | if (ret) | ||
183 | return ret; | ||
184 | |||
185 | return da903x_update(da903x_dev, info->vol_reg, val, mask); | ||
186 | } | ||
187 | |||
188 | static int da9030_set_ldo14_voltage(struct regulator_dev *rdev, | ||
189 | int min_uV, int max_uV) | ||
190 | { | ||
191 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | ||
192 | struct device *da903x_dev = rdev_get_dev(rdev)->parent; | ||
193 | uint8_t val, mask; | ||
194 | int thresh; | ||
195 | |||
196 | if (check_range(info, min_uV, max_uV)) { | ||
197 | pr_err("invalid voltage range (%d, %d) uV", min_uV, max_uV); | ||
198 | return -EINVAL; | ||
199 | } | ||
200 | |||
201 | thresh = (info->max_uV + info->min_uV) / 2; | ||
202 | if (min_uV < thresh) { | ||
203 | val = (thresh - min_uV + info->step_uV - 1) / info->step_uV; | ||
204 | val |= 0x4; | ||
205 | } else { | ||
206 | val = (min_uV - thresh + info->step_uV - 1) / info->step_uV; | ||
207 | } | ||
208 | |||
209 | val <<= info->vol_shift; | ||
210 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; | ||
211 | |||
212 | return da903x_update(da903x_dev, info->vol_reg, val, mask); | ||
213 | } | ||
214 | |||
215 | static int da9030_get_ldo14_voltage(struct regulator_dev *rdev) | ||
216 | { | ||
217 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | ||
218 | struct device *da903x_dev = rdev_get_dev(rdev)->parent; | ||
219 | uint8_t val, mask; | ||
220 | int ret; | ||
221 | |||
222 | ret = da903x_read(da903x_dev, info->vol_reg, &val); | ||
223 | if (ret) | ||
224 | return ret; | ||
225 | |||
226 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; | ||
227 | val = (val & mask) >> info->vol_shift; | ||
228 | |||
229 | if (val & 0x4) | ||
230 | return info->min_uV + info->step_uV * (3 - (val & ~0x4)); | ||
231 | else | ||
232 | return (info->max_uV + info->min_uV) / 2 + | ||
233 | info->step_uV * (val & ~0x4); | ||
234 | } | ||
235 | |||
236 | /* DA9034 specific operations */ | ||
237 | static int da9034_set_dvc_voltage(struct regulator_dev *rdev, | ||
238 | int min_uV, int max_uV) | ||
239 | { | ||
240 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | ||
241 | struct device *da9034_dev = rdev_get_dev(rdev)->parent; | ||
242 | uint8_t val, mask; | ||
243 | int ret; | ||
244 | |||
245 | if (check_range(info, min_uV, max_uV)) { | ||
246 | pr_err("invalid voltage range (%d, %d) uV", min_uV, max_uV); | ||
247 | return -EINVAL; | ||
248 | } | ||
249 | |||
250 | val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV; | ||
251 | val <<= info->vol_shift; | ||
252 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; | ||
253 | |||
254 | ret = da903x_update(da9034_dev, info->vol_reg, val, mask); | ||
255 | if (ret) | ||
256 | return ret; | ||
257 | |||
258 | ret = da903x_set_bits(da9034_dev, info->update_reg, | ||
259 | 1 << info->update_bit); | ||
260 | return ret; | ||
261 | } | ||
262 | |||
263 | static int da9034_set_ldo12_voltage(struct regulator_dev *rdev, | ||
264 | int min_uV, int max_uV) | ||
265 | { | ||
266 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | ||
267 | struct device *da9034_dev = rdev_get_dev(rdev)->parent; | ||
268 | uint8_t val, mask; | ||
269 | |||
270 | if (check_range(info, min_uV, max_uV)) { | ||
271 | pr_err("invalid voltage range (%d, %d) uV", min_uV, max_uV); | ||
272 | return -EINVAL; | ||
273 | } | ||
274 | |||
275 | val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV; | ||
276 | val = (val > 7 || val < 20) ? 8 : val - 12; | ||
277 | val <<= info->vol_shift; | ||
278 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; | ||
279 | |||
280 | return da903x_update(da9034_dev, info->vol_reg, val, mask); | ||
281 | } | ||
282 | |||
283 | static int da9034_get_ldo12_voltage(struct regulator_dev *rdev) | ||
284 | { | ||
285 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | ||
286 | struct device *da9034_dev = rdev_get_dev(rdev)->parent; | ||
287 | uint8_t val, mask; | ||
288 | int ret; | ||
289 | |||
290 | ret = da903x_read(da9034_dev, info->vol_reg, &val); | ||
291 | if (ret) | ||
292 | return ret; | ||
293 | |||
294 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; | ||
295 | val = (val & mask) >> info->vol_shift; | ||
296 | |||
297 | if (val >= 8) | ||
298 | return 2700000 + info->step_uV * (val - 8); | ||
299 | |||
300 | return info->min_uV + info->step_uV * val; | ||
301 | } | ||
302 | |||
303 | static struct regulator_ops da903x_regulator_ldo_ops = { | ||
304 | .set_voltage = da903x_set_ldo_voltage, | ||
305 | .get_voltage = da903x_get_voltage, | ||
306 | .enable = da903x_enable, | ||
307 | .disable = da903x_disable, | ||
308 | .is_enabled = da903x_is_enabled, | ||
309 | }; | ||
310 | |||
311 | /* NOTE: this is dedicated for the insane DA9030 LDO14 */ | ||
312 | static struct regulator_ops da9030_regulator_ldo14_ops = { | ||
313 | .set_voltage = da9030_set_ldo14_voltage, | ||
314 | .get_voltage = da9030_get_ldo14_voltage, | ||
315 | .enable = da903x_enable, | ||
316 | .disable = da903x_disable, | ||
317 | .is_enabled = da903x_is_enabled, | ||
318 | }; | ||
319 | |||
320 | /* NOTE: this is dedicated for the DA9030 LDO1 and LDO15 that have locks */ | ||
321 | static struct regulator_ops da9030_regulator_ldo1_15_ops = { | ||
322 | .set_voltage = da9030_set_ldo1_15_voltage, | ||
323 | .get_voltage = da903x_get_voltage, | ||
324 | .enable = da903x_enable, | ||
325 | .disable = da903x_disable, | ||
326 | .is_enabled = da903x_is_enabled, | ||
327 | }; | ||
328 | |||
329 | static struct regulator_ops da9034_regulator_dvc_ops = { | ||
330 | .set_voltage = da9034_set_dvc_voltage, | ||
331 | .get_voltage = da903x_get_voltage, | ||
332 | .enable = da903x_enable, | ||
333 | .disable = da903x_disable, | ||
334 | .is_enabled = da903x_is_enabled, | ||
335 | }; | ||
336 | |||
337 | /* NOTE: this is dedicated for the insane LDO12 */ | ||
338 | static struct regulator_ops da9034_regulator_ldo12_ops = { | ||
339 | .set_voltage = da9034_set_ldo12_voltage, | ||
340 | .get_voltage = da9034_get_ldo12_voltage, | ||
341 | .enable = da903x_enable, | ||
342 | .disable = da903x_disable, | ||
343 | .is_enabled = da903x_is_enabled, | ||
344 | }; | ||
345 | |||
346 | #define DA903x_LDO(_pmic, _id, min, max, step, vreg, shift, nbits, ereg, ebit) \ | ||
347 | { \ | ||
348 | .desc = { \ | ||
349 | .name = "LDO" #_id, \ | ||
350 | .ops = &da903x_regulator_ldo_ops, \ | ||
351 | .type = REGULATOR_VOLTAGE, \ | ||
352 | .id = _pmic##_ID_LDO##_id, \ | ||
353 | .owner = THIS_MODULE, \ | ||
354 | }, \ | ||
355 | .min_uV = (min) * 1000, \ | ||
356 | .max_uV = (max) * 1000, \ | ||
357 | .step_uV = (step) * 1000, \ | ||
358 | .vol_reg = _pmic##_##vreg, \ | ||
359 | .vol_shift = (shift), \ | ||
360 | .vol_nbits = (nbits), \ | ||
361 | .enable_reg = _pmic##_##ereg, \ | ||
362 | .enable_bit = (ebit), \ | ||
363 | } | ||
364 | |||
365 | #define DA9034_DVC(_id, min, max, step, vreg, nbits, ureg, ubit, ereg, ebit) \ | ||
366 | { \ | ||
367 | .desc = { \ | ||
368 | .name = #_id, \ | ||
369 | .ops = &da9034_regulator_dvc_ops, \ | ||
370 | .type = REGULATOR_VOLTAGE, \ | ||
371 | .id = DA9034_ID_##_id, \ | ||
372 | .owner = THIS_MODULE, \ | ||
373 | }, \ | ||
374 | .min_uV = (min) * 1000, \ | ||
375 | .max_uV = (max) * 1000, \ | ||
376 | .step_uV = (step) * 1000, \ | ||
377 | .vol_reg = DA9034_##vreg, \ | ||
378 | .vol_shift = (0), \ | ||
379 | .vol_nbits = (nbits), \ | ||
380 | .update_reg = DA9034_##ureg, \ | ||
381 | .update_bit = (ubit), \ | ||
382 | .enable_reg = DA9034_##ereg, \ | ||
383 | .enable_bit = (ebit), \ | ||
384 | } | ||
385 | |||
386 | #define DA9034_LDO(_id, min, max, step, vreg, shift, nbits, ereg, ebit) \ | ||
387 | DA903x_LDO(DA9034, _id, min, max, step, vreg, shift, nbits, ereg, ebit) | ||
388 | |||
389 | #define DA9030_LDO(_id, min, max, step, vreg, shift, nbits, ereg, ebit) \ | ||
390 | DA903x_LDO(DA9030, _id, min, max, step, vreg, shift, nbits, ereg, ebit) | ||
391 | |||
392 | static struct da903x_regulator_info da903x_regulator_info[] = { | ||
393 | /* DA9030 */ | ||
394 | DA9030_LDO( 1, 1200, 3200, 100, LDO1, 0, 5, RCTL12, 1), | ||
395 | DA9030_LDO( 2, 1800, 3200, 100, LDO23, 0, 4, RCTL12, 2), | ||
396 | DA9030_LDO( 3, 1800, 3200, 100, LDO23, 4, 4, RCTL12, 3), | ||
397 | DA9030_LDO( 4, 1800, 3200, 100, LDO45, 0, 4, RCTL12, 4), | ||
398 | DA9030_LDO( 5, 1800, 3200, 100, LDO45, 4, 4, RCTL12, 5), | ||
399 | DA9030_LDO( 6, 1800, 3200, 100, LDO6, 0, 4, RCTL12, 6), | ||
400 | DA9030_LDO( 7, 1800, 3200, 100, LDO78, 0, 4, RCTL12, 7), | ||
401 | DA9030_LDO( 8, 1800, 3200, 100, LDO78, 4, 4, RCTL22, 0), | ||
402 | DA9030_LDO( 9, 1800, 3200, 100, LDO912, 0, 4, RCTL22, 1), | ||
403 | DA9030_LDO(10, 1800, 3200, 100, LDO1011, 0, 4, RCTL22, 2), | ||
404 | DA9030_LDO(11, 1800, 3200, 100, LDO1011, 4, 4, RCTL22, 3), | ||
405 | DA9030_LDO(12, 1800, 3200, 100, LDO912, 4, 4, RCTL22, 4), | ||
406 | DA9030_LDO(14, 2760, 2940, 30, LDO1416, 0, 3, RCTL11, 4), | ||
407 | DA9030_LDO(15, 1100, 2650, 50, LDO15, 0, 5, RCTL11, 5), | ||
408 | DA9030_LDO(16, 1100, 2650, 50, LDO1416, 3, 5, RCTL11, 6), | ||
409 | DA9030_LDO(17, 1800, 3200, 100, LDO17, 0, 4, RCTL11, 7), | ||
410 | DA9030_LDO(18, 1800, 3200, 100, LDO1819, 0, 4, RCTL21, 2), | ||
411 | DA9030_LDO(19, 1800, 3200, 100, LDO1819, 4, 4, RCTL21, 1), | ||
412 | DA9030_LDO(13, 2100, 2100, 0, INVAL, 0, 0, RCTL11, 3), /* fixed @2.1V */ | ||
413 | |||
414 | /* DA9034 */ | ||
415 | DA9034_DVC(BUCK1, 725, 1500, 25, ADTV1, 5, VCC1, 0, OVER1, 0), | ||
416 | DA9034_DVC(BUCK2, 725, 1500, 25, CDTV1, 5, VCC1, 2, OVER1, 1), | ||
417 | DA9034_DVC(LDO2, 725, 1500, 25, SDTV1, 5, VCC1, 4, OVER1, 2), | ||
418 | DA9034_DVC(LDO1, 1700, 2075, 25, MDTV1, 4, VCC1, 6, OVER3, 4), | ||
419 | |||
420 | DA9034_LDO( 3, 1800, 3300, 100, LDO643, 0, 4, OVER3, 5), | ||
421 | DA9034_LDO( 4, 1800, 2900,1100, LDO643, 4, 1, OVER3, 6), | ||
422 | DA9034_LDO( 6, 2500, 2850, 50, LDO643, 5, 3, OVER2, 0), | ||
423 | DA9034_LDO( 7, 2700, 3050, 50, LDO987, 0, 3, OVER2, 1), | ||
424 | DA9034_LDO( 8, 2700, 2850, 50, LDO987, 3, 2, OVER2, 2), | ||
425 | DA9034_LDO( 9, 2700, 3050, 50, LDO987, 5, 3, OVER2, 3), | ||
426 | DA9034_LDO(10, 2700, 3050, 50, LDO1110, 0, 3, OVER2, 4), | ||
427 | DA9034_LDO(11, 1800, 3300, 100, LDO1110, 4, 4, OVER2, 5), | ||
428 | DA9034_LDO(12, 1700, 3050, 50, LDO1312, 0, 4, OVER3, 6), | ||
429 | DA9034_LDO(13, 1800, 3300, 100, LDO1312, 4, 4, OVER2, 7), | ||
430 | DA9034_LDO(14, 1800, 3300, 100, LDO1514, 0, 4, OVER3, 0), | ||
431 | DA9034_LDO(15, 1800, 3300, 100, LDO1514, 4, 4, OVER3, 1), | ||
432 | DA9034_LDO(5, 3100, 3100, 0, INVAL, 0, 0, OVER3, 7), /* fixed @3.1V */ | ||
433 | }; | ||
434 | |||
435 | static inline struct da903x_regulator_info *find_regulator_info(int id) | ||
436 | { | ||
437 | struct da903x_regulator_info *ri; | ||
438 | int i; | ||
439 | |||
440 | for (i = 0; i < ARRAY_SIZE(da903x_regulator_info); i++) { | ||
441 | ri = &da903x_regulator_info[i]; | ||
442 | if (ri->desc.id == id) | ||
443 | return ri; | ||
444 | } | ||
445 | return NULL; | ||
446 | } | ||
447 | |||
448 | static int __devinit da903x_regulator_probe(struct platform_device *pdev) | ||
449 | { | ||
450 | struct da903x_regulator_info *ri = NULL; | ||
451 | struct regulator_dev *rdev; | ||
452 | |||
453 | ri = find_regulator_info(pdev->id); | ||
454 | if (ri == NULL) { | ||
455 | dev_err(&pdev->dev, "invalid regulator ID specified\n"); | ||
456 | return -EINVAL; | ||
457 | } | ||
458 | |||
459 | /* Workaround for the weird LDO12 voltage setting */ | ||
460 | if (ri->desc.id == DA9034_ID_LDO12) | ||
461 | ri->desc.ops = &da9034_regulator_ldo12_ops; | ||
462 | |||
463 | if (ri->desc.id == DA9030_ID_LDO14) | ||
464 | ri->desc.ops = &da9030_regulator_ldo14_ops; | ||
465 | |||
466 | if (ri->desc.id == DA9030_ID_LDO1 || ri->desc.id == DA9030_ID_LDO15) | ||
467 | ri->desc.ops = &da9030_regulator_ldo1_15_ops; | ||
468 | |||
469 | rdev = regulator_register(&ri->desc, pdev->dev.parent, ri); | ||
470 | if (IS_ERR(rdev)) { | ||
471 | dev_err(&pdev->dev, "failed to register regulator %s\n", | ||
472 | ri->desc.name); | ||
473 | return PTR_ERR(rdev); | ||
474 | } | ||
475 | |||
476 | platform_set_drvdata(pdev, rdev); | ||
477 | return 0; | ||
478 | } | ||
479 | |||
480 | static int __devexit da903x_regulator_remove(struct platform_device *pdev) | ||
481 | { | ||
482 | struct regulator_dev *rdev = platform_get_drvdata(pdev); | ||
483 | |||
484 | regulator_unregister(rdev); | ||
485 | return 0; | ||
486 | } | ||
487 | |||
488 | static struct platform_driver da903x_regulator_driver = { | ||
489 | .driver = { | ||
490 | .name = "da903x-regulator", | ||
491 | .owner = THIS_MODULE, | ||
492 | }, | ||
493 | .probe = da903x_regulator_probe, | ||
494 | .remove = da903x_regulator_remove, | ||
495 | }; | ||
496 | |||
497 | static int __init da903x_regulator_init(void) | ||
498 | { | ||
499 | return platform_driver_register(&da903x_regulator_driver); | ||
500 | } | ||
501 | module_init(da903x_regulator_init); | ||
502 | |||
503 | static void __exit da903x_regulator_exit(void) | ||
504 | { | ||
505 | platform_driver_unregister(&da903x_regulator_driver); | ||
506 | } | ||
507 | module_exit(da903x_regulator_exit); | ||
508 | |||
509 | MODULE_LICENSE("GPL"); | ||
510 | MODULE_AUTHOR("Eric Miao <eric.miao@marvell.com>" | ||
511 | "Mike Rapoport <mike@compulab.co.il>"); | ||
512 | MODULE_DESCRIPTION("Regulator Driver for Dialog Semiconductor DA903X PMIC"); | ||
513 | MODULE_ALIAS("platform:da903x-regulator"); | ||
diff --git a/drivers/regulator/wm8350-regulator.c b/drivers/regulator/wm8350-regulator.c new file mode 100644 index 000000000000..1f44b17e23b1 --- /dev/null +++ b/drivers/regulator/wm8350-regulator.c | |||
@@ -0,0 +1,1431 @@ | |||
1 | /* | ||
2 | * wm8350.c -- Voltage and current regulation for the Wolfson WM8350 PMIC | ||
3 | * | ||
4 | * Copyright 2007, 2008 Wolfson Microelectronics PLC. | ||
5 | * | ||
6 | * Author: Liam Girdwood | ||
7 | * linux@wolfsonmicro.com | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify it | ||
10 | * under the terms of the GNU General Public License as published by the | ||
11 | * Free Software Foundation; either version 2 of the License, or (at your | ||
12 | * option) any later version. | ||
13 | */ | ||
14 | |||
15 | #include <linux/module.h> | ||
16 | #include <linux/moduleparam.h> | ||
17 | #include <linux/init.h> | ||
18 | #include <linux/bitops.h> | ||
19 | #include <linux/err.h> | ||
20 | #include <linux/i2c.h> | ||
21 | #include <linux/mfd/wm8350/core.h> | ||
22 | #include <linux/mfd/wm8350/pmic.h> | ||
23 | #include <linux/platform_device.h> | ||
24 | #include <linux/regulator/driver.h> | ||
25 | #include <linux/regulator/machine.h> | ||
26 | |||
27 | /* Microamps */ | ||
28 | static const int isink_cur[] = { | ||
29 | 4, | ||
30 | 5, | ||
31 | 6, | ||
32 | 7, | ||
33 | 8, | ||
34 | 10, | ||
35 | 11, | ||
36 | 14, | ||
37 | 16, | ||
38 | 19, | ||
39 | 23, | ||
40 | 27, | ||
41 | 32, | ||
42 | 39, | ||
43 | 46, | ||
44 | 54, | ||
45 | 65, | ||
46 | 77, | ||
47 | 92, | ||
48 | 109, | ||
49 | 130, | ||
50 | 154, | ||
51 | 183, | ||
52 | 218, | ||
53 | 259, | ||
54 | 308, | ||
55 | 367, | ||
56 | 436, | ||
57 | 518, | ||
58 | 616, | ||
59 | 733, | ||
60 | 872, | ||
61 | 1037, | ||
62 | 1233, | ||
63 | 1466, | ||
64 | 1744, | ||
65 | 2073, | ||
66 | 2466, | ||
67 | 2933, | ||
68 | 3487, | ||
69 | 4147, | ||
70 | 4932, | ||
71 | 5865, | ||
72 | 6975, | ||
73 | 8294, | ||
74 | 9864, | ||
75 | 11730, | ||
76 | 13949, | ||
77 | 16589, | ||
78 | 19728, | ||
79 | 23460, | ||
80 | 27899, | ||
81 | 33178, | ||
82 | 39455, | ||
83 | 46920, | ||
84 | 55798, | ||
85 | 66355, | ||
86 | 78910, | ||
87 | 93840, | ||
88 | 111596, | ||
89 | 132710, | ||
90 | 157820, | ||
91 | 187681, | ||
92 | 223191 | ||
93 | }; | ||
94 | |||
95 | static int get_isink_val(int min_uA, int max_uA, u16 *setting) | ||
96 | { | ||
97 | int i; | ||
98 | |||
99 | for (i = ARRAY_SIZE(isink_cur) - 1; i >= 0; i--) { | ||
100 | if (min_uA <= isink_cur[i] && max_uA >= isink_cur[i]) { | ||
101 | *setting = i; | ||
102 | return 0; | ||
103 | } | ||
104 | } | ||
105 | return -EINVAL; | ||
106 | } | ||
107 | |||
108 | static inline int wm8350_ldo_val_to_mvolts(unsigned int val) | ||
109 | { | ||
110 | if (val < 16) | ||
111 | return (val * 50) + 900; | ||
112 | else | ||
113 | return ((val - 16) * 100) + 1800; | ||
114 | |||
115 | } | ||
116 | |||
117 | static inline unsigned int wm8350_ldo_mvolts_to_val(int mV) | ||
118 | { | ||
119 | if (mV < 1800) | ||
120 | return (mV - 900) / 50; | ||
121 | else | ||
122 | return ((mV - 1800) / 100) + 16; | ||
123 | } | ||
124 | |||
125 | static inline int wm8350_dcdc_val_to_mvolts(unsigned int val) | ||
126 | { | ||
127 | return (val * 25) + 850; | ||
128 | } | ||
129 | |||
130 | static inline unsigned int wm8350_dcdc_mvolts_to_val(int mV) | ||
131 | { | ||
132 | return (mV - 850) / 25; | ||
133 | } | ||
134 | |||
135 | static int wm8350_isink_set_current(struct regulator_dev *rdev, int min_uA, | ||
136 | int max_uA) | ||
137 | { | ||
138 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
139 | int isink = rdev_get_id(rdev); | ||
140 | u16 val, setting; | ||
141 | int ret; | ||
142 | |||
143 | ret = get_isink_val(min_uA, max_uA, &setting); | ||
144 | if (ret != 0) | ||
145 | return ret; | ||
146 | |||
147 | switch (isink) { | ||
148 | case WM8350_ISINK_A: | ||
149 | val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_A) & | ||
150 | ~WM8350_CS1_ISEL_MASK; | ||
151 | wm8350_reg_write(wm8350, WM8350_CURRENT_SINK_DRIVER_A, | ||
152 | val | setting); | ||
153 | break; | ||
154 | case WM8350_ISINK_B: | ||
155 | val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_B) & | ||
156 | ~WM8350_CS1_ISEL_MASK; | ||
157 | wm8350_reg_write(wm8350, WM8350_CURRENT_SINK_DRIVER_B, | ||
158 | val | setting); | ||
159 | break; | ||
160 | default: | ||
161 | return -EINVAL; | ||
162 | } | ||
163 | |||
164 | return 0; | ||
165 | } | ||
166 | |||
167 | static int wm8350_isink_get_current(struct regulator_dev *rdev) | ||
168 | { | ||
169 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
170 | int isink = rdev_get_id(rdev); | ||
171 | u16 val; | ||
172 | |||
173 | switch (isink) { | ||
174 | case WM8350_ISINK_A: | ||
175 | val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_A) & | ||
176 | WM8350_CS1_ISEL_MASK; | ||
177 | break; | ||
178 | case WM8350_ISINK_B: | ||
179 | val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_B) & | ||
180 | WM8350_CS1_ISEL_MASK; | ||
181 | break; | ||
182 | default: | ||
183 | return 0; | ||
184 | } | ||
185 | |||
186 | return (isink_cur[val] + 50) / 100; | ||
187 | } | ||
188 | |||
189 | /* turn on ISINK followed by DCDC */ | ||
190 | static int wm8350_isink_enable(struct regulator_dev *rdev) | ||
191 | { | ||
192 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
193 | int isink = rdev_get_id(rdev); | ||
194 | |||
195 | switch (isink) { | ||
196 | case WM8350_ISINK_A: | ||
197 | switch (wm8350->pmic.isink_A_dcdc) { | ||
198 | case WM8350_DCDC_2: | ||
199 | case WM8350_DCDC_5: | ||
200 | wm8350_set_bits(wm8350, WM8350_POWER_MGMT_7, | ||
201 | WM8350_CS1_ENA); | ||
202 | wm8350_set_bits(wm8350, WM8350_CSA_FLASH_CONTROL, | ||
203 | WM8350_CS1_DRIVE); | ||
204 | wm8350_set_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, | ||
205 | 1 << (wm8350->pmic.isink_A_dcdc - | ||
206 | WM8350_DCDC_1)); | ||
207 | break; | ||
208 | default: | ||
209 | return -EINVAL; | ||
210 | } | ||
211 | break; | ||
212 | case WM8350_ISINK_B: | ||
213 | switch (wm8350->pmic.isink_B_dcdc) { | ||
214 | case WM8350_DCDC_2: | ||
215 | case WM8350_DCDC_5: | ||
216 | wm8350_set_bits(wm8350, WM8350_POWER_MGMT_7, | ||
217 | WM8350_CS2_ENA); | ||
218 | wm8350_set_bits(wm8350, WM8350_CSB_FLASH_CONTROL, | ||
219 | WM8350_CS2_DRIVE); | ||
220 | wm8350_set_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, | ||
221 | 1 << (wm8350->pmic.isink_B_dcdc - | ||
222 | WM8350_DCDC_1)); | ||
223 | break; | ||
224 | default: | ||
225 | return -EINVAL; | ||
226 | } | ||
227 | break; | ||
228 | default: | ||
229 | return -EINVAL; | ||
230 | } | ||
231 | return 0; | ||
232 | } | ||
233 | |||
234 | static int wm8350_isink_disable(struct regulator_dev *rdev) | ||
235 | { | ||
236 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
237 | int isink = rdev_get_id(rdev); | ||
238 | |||
239 | switch (isink) { | ||
240 | case WM8350_ISINK_A: | ||
241 | switch (wm8350->pmic.isink_A_dcdc) { | ||
242 | case WM8350_DCDC_2: | ||
243 | case WM8350_DCDC_5: | ||
244 | wm8350_clear_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, | ||
245 | 1 << (wm8350->pmic.isink_A_dcdc - | ||
246 | WM8350_DCDC_1)); | ||
247 | wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_7, | ||
248 | WM8350_CS1_ENA); | ||
249 | break; | ||
250 | default: | ||
251 | return -EINVAL; | ||
252 | } | ||
253 | break; | ||
254 | case WM8350_ISINK_B: | ||
255 | switch (wm8350->pmic.isink_B_dcdc) { | ||
256 | case WM8350_DCDC_2: | ||
257 | case WM8350_DCDC_5: | ||
258 | wm8350_clear_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, | ||
259 | 1 << (wm8350->pmic.isink_B_dcdc - | ||
260 | WM8350_DCDC_1)); | ||
261 | wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_7, | ||
262 | WM8350_CS2_ENA); | ||
263 | break; | ||
264 | default: | ||
265 | return -EINVAL; | ||
266 | } | ||
267 | break; | ||
268 | default: | ||
269 | return -EINVAL; | ||
270 | } | ||
271 | return 0; | ||
272 | } | ||
273 | |||
274 | static int wm8350_isink_is_enabled(struct regulator_dev *rdev) | ||
275 | { | ||
276 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
277 | int isink = rdev_get_id(rdev); | ||
278 | |||
279 | switch (isink) { | ||
280 | case WM8350_ISINK_A: | ||
281 | return wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_A) & | ||
282 | 0x8000; | ||
283 | case WM8350_ISINK_B: | ||
284 | return wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_B) & | ||
285 | 0x8000; | ||
286 | } | ||
287 | return -EINVAL; | ||
288 | } | ||
289 | |||
290 | int wm8350_isink_set_flash(struct wm8350 *wm8350, int isink, u16 mode, | ||
291 | u16 trigger, u16 duration, u16 on_ramp, u16 off_ramp, | ||
292 | u16 drive) | ||
293 | { | ||
294 | switch (isink) { | ||
295 | case WM8350_ISINK_A: | ||
296 | wm8350_reg_write(wm8350, WM8350_CSA_FLASH_CONTROL, | ||
297 | (mode ? WM8350_CS1_FLASH_MODE : 0) | | ||
298 | (trigger ? WM8350_CS1_TRIGSRC : 0) | | ||
299 | duration | on_ramp | off_ramp | drive); | ||
300 | break; | ||
301 | case WM8350_ISINK_B: | ||
302 | wm8350_reg_write(wm8350, WM8350_CSB_FLASH_CONTROL, | ||
303 | (mode ? WM8350_CS2_FLASH_MODE : 0) | | ||
304 | (trigger ? WM8350_CS2_TRIGSRC : 0) | | ||
305 | duration | on_ramp | off_ramp | drive); | ||
306 | break; | ||
307 | default: | ||
308 | return -EINVAL; | ||
309 | } | ||
310 | return 0; | ||
311 | } | ||
312 | EXPORT_SYMBOL_GPL(wm8350_isink_set_flash); | ||
313 | |||
314 | static int wm8350_dcdc_set_voltage(struct regulator_dev *rdev, int min_uV, | ||
315 | int max_uV) | ||
316 | { | ||
317 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
318 | int volt_reg, dcdc = rdev_get_id(rdev), mV, | ||
319 | min_mV = min_uV / 1000, max_mV = max_uV / 1000; | ||
320 | u16 val; | ||
321 | |||
322 | if (min_mV < 850 || min_mV > 4025) | ||
323 | return -EINVAL; | ||
324 | if (max_mV < 850 || max_mV > 4025) | ||
325 | return -EINVAL; | ||
326 | |||
327 | /* step size is 25mV */ | ||
328 | mV = (min_mV - 826) / 25; | ||
329 | if (wm8350_dcdc_val_to_mvolts(mV) > max_mV) | ||
330 | return -EINVAL; | ||
331 | BUG_ON(wm8350_dcdc_val_to_mvolts(mV) < min_mV); | ||
332 | |||
333 | switch (dcdc) { | ||
334 | case WM8350_DCDC_1: | ||
335 | volt_reg = WM8350_DCDC1_CONTROL; | ||
336 | break; | ||
337 | case WM8350_DCDC_3: | ||
338 | volt_reg = WM8350_DCDC3_CONTROL; | ||
339 | break; | ||
340 | case WM8350_DCDC_4: | ||
341 | volt_reg = WM8350_DCDC4_CONTROL; | ||
342 | break; | ||
343 | case WM8350_DCDC_6: | ||
344 | volt_reg = WM8350_DCDC6_CONTROL; | ||
345 | break; | ||
346 | case WM8350_DCDC_2: | ||
347 | case WM8350_DCDC_5: | ||
348 | default: | ||
349 | return -EINVAL; | ||
350 | } | ||
351 | |||
352 | /* all DCDCs have same mV bits */ | ||
353 | val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_DC1_VSEL_MASK; | ||
354 | wm8350_reg_write(wm8350, volt_reg, val | mV); | ||
355 | return 0; | ||
356 | } | ||
357 | |||
358 | static int wm8350_dcdc_get_voltage(struct regulator_dev *rdev) | ||
359 | { | ||
360 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
361 | int volt_reg, dcdc = rdev_get_id(rdev); | ||
362 | u16 val; | ||
363 | |||
364 | switch (dcdc) { | ||
365 | case WM8350_DCDC_1: | ||
366 | volt_reg = WM8350_DCDC1_CONTROL; | ||
367 | break; | ||
368 | case WM8350_DCDC_3: | ||
369 | volt_reg = WM8350_DCDC3_CONTROL; | ||
370 | break; | ||
371 | case WM8350_DCDC_4: | ||
372 | volt_reg = WM8350_DCDC4_CONTROL; | ||
373 | break; | ||
374 | case WM8350_DCDC_6: | ||
375 | volt_reg = WM8350_DCDC6_CONTROL; | ||
376 | break; | ||
377 | case WM8350_DCDC_2: | ||
378 | case WM8350_DCDC_5: | ||
379 | default: | ||
380 | return -EINVAL; | ||
381 | } | ||
382 | |||
383 | /* all DCDCs have same mV bits */ | ||
384 | val = wm8350_reg_read(wm8350, volt_reg) & WM8350_DC1_VSEL_MASK; | ||
385 | return wm8350_dcdc_val_to_mvolts(val) * 1000; | ||
386 | } | ||
387 | |||
388 | static int wm8350_dcdc_set_suspend_voltage(struct regulator_dev *rdev, int uV) | ||
389 | { | ||
390 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
391 | int volt_reg, mV = uV / 1000, dcdc = rdev_get_id(rdev); | ||
392 | u16 val; | ||
393 | |||
394 | dev_dbg(wm8350->dev, "%s %d mV %d\n", __func__, dcdc, mV); | ||
395 | |||
396 | if (mV && (mV < 850 || mV > 4025)) { | ||
397 | dev_err(wm8350->dev, | ||
398 | "DCDC%d suspend voltage %d mV out of range\n", | ||
399 | dcdc, mV); | ||
400 | return -EINVAL; | ||
401 | } | ||
402 | if (mV == 0) | ||
403 | mV = 850; | ||
404 | |||
405 | switch (dcdc) { | ||
406 | case WM8350_DCDC_1: | ||
407 | volt_reg = WM8350_DCDC1_LOW_POWER; | ||
408 | break; | ||
409 | case WM8350_DCDC_3: | ||
410 | volt_reg = WM8350_DCDC3_LOW_POWER; | ||
411 | break; | ||
412 | case WM8350_DCDC_4: | ||
413 | volt_reg = WM8350_DCDC4_LOW_POWER; | ||
414 | break; | ||
415 | case WM8350_DCDC_6: | ||
416 | volt_reg = WM8350_DCDC6_LOW_POWER; | ||
417 | break; | ||
418 | case WM8350_DCDC_2: | ||
419 | case WM8350_DCDC_5: | ||
420 | default: | ||
421 | return -EINVAL; | ||
422 | } | ||
423 | |||
424 | /* all DCDCs have same mV bits */ | ||
425 | val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_DC1_VSEL_MASK; | ||
426 | wm8350_reg_write(wm8350, volt_reg, | ||
427 | val | wm8350_dcdc_mvolts_to_val(mV)); | ||
428 | return 0; | ||
429 | } | ||
430 | |||
431 | static int wm8350_dcdc_set_suspend_enable(struct regulator_dev *rdev) | ||
432 | { | ||
433 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
434 | int dcdc = rdev_get_id(rdev); | ||
435 | u16 val; | ||
436 | |||
437 | switch (dcdc) { | ||
438 | case WM8350_DCDC_1: | ||
439 | val = wm8350_reg_read(wm8350, WM8350_DCDC1_LOW_POWER) | ||
440 | & ~WM8350_DCDC_HIB_MODE_MASK; | ||
441 | wm8350_reg_write(wm8350, WM8350_DCDC1_LOW_POWER, | ||
442 | wm8350->pmic.dcdc1_hib_mode); | ||
443 | break; | ||
444 | case WM8350_DCDC_3: | ||
445 | val = wm8350_reg_read(wm8350, WM8350_DCDC3_LOW_POWER) | ||
446 | & ~WM8350_DCDC_HIB_MODE_MASK; | ||
447 | wm8350_reg_write(wm8350, WM8350_DCDC3_LOW_POWER, | ||
448 | wm8350->pmic.dcdc3_hib_mode); | ||
449 | break; | ||
450 | case WM8350_DCDC_4: | ||
451 | val = wm8350_reg_read(wm8350, WM8350_DCDC4_LOW_POWER) | ||
452 | & ~WM8350_DCDC_HIB_MODE_MASK; | ||
453 | wm8350_reg_write(wm8350, WM8350_DCDC4_LOW_POWER, | ||
454 | wm8350->pmic.dcdc4_hib_mode); | ||
455 | break; | ||
456 | case WM8350_DCDC_6: | ||
457 | val = wm8350_reg_read(wm8350, WM8350_DCDC6_LOW_POWER) | ||
458 | & ~WM8350_DCDC_HIB_MODE_MASK; | ||
459 | wm8350_reg_write(wm8350, WM8350_DCDC6_LOW_POWER, | ||
460 | wm8350->pmic.dcdc6_hib_mode); | ||
461 | break; | ||
462 | case WM8350_DCDC_2: | ||
463 | case WM8350_DCDC_5: | ||
464 | default: | ||
465 | return -EINVAL; | ||
466 | } | ||
467 | |||
468 | return 0; | ||
469 | } | ||
470 | |||
471 | static int wm8350_dcdc_set_suspend_disable(struct regulator_dev *rdev) | ||
472 | { | ||
473 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
474 | int dcdc = rdev_get_id(rdev); | ||
475 | u16 val; | ||
476 | |||
477 | switch (dcdc) { | ||
478 | case WM8350_DCDC_1: | ||
479 | val = wm8350_reg_read(wm8350, WM8350_DCDC1_LOW_POWER); | ||
480 | wm8350->pmic.dcdc1_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK; | ||
481 | wm8350_reg_write(wm8350, WM8350_DCDC1_LOW_POWER, | ||
482 | WM8350_DCDC_HIB_MODE_DIS); | ||
483 | break; | ||
484 | case WM8350_DCDC_3: | ||
485 | val = wm8350_reg_read(wm8350, WM8350_DCDC3_LOW_POWER); | ||
486 | wm8350->pmic.dcdc3_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK; | ||
487 | wm8350_reg_write(wm8350, WM8350_DCDC3_LOW_POWER, | ||
488 | WM8350_DCDC_HIB_MODE_DIS); | ||
489 | break; | ||
490 | case WM8350_DCDC_4: | ||
491 | val = wm8350_reg_read(wm8350, WM8350_DCDC4_LOW_POWER); | ||
492 | wm8350->pmic.dcdc4_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK; | ||
493 | wm8350_reg_write(wm8350, WM8350_DCDC4_LOW_POWER, | ||
494 | WM8350_DCDC_HIB_MODE_DIS); | ||
495 | break; | ||
496 | case WM8350_DCDC_6: | ||
497 | val = wm8350_reg_read(wm8350, WM8350_DCDC6_LOW_POWER); | ||
498 | wm8350->pmic.dcdc6_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK; | ||
499 | wm8350_reg_write(wm8350, WM8350_DCDC6_LOW_POWER, | ||
500 | WM8350_DCDC_HIB_MODE_DIS); | ||
501 | break; | ||
502 | case WM8350_DCDC_2: | ||
503 | case WM8350_DCDC_5: | ||
504 | default: | ||
505 | return -EINVAL; | ||
506 | } | ||
507 | |||
508 | return 0; | ||
509 | } | ||
510 | |||
511 | static int wm8350_dcdc25_set_suspend_enable(struct regulator_dev *rdev) | ||
512 | { | ||
513 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
514 | int dcdc = rdev_get_id(rdev); | ||
515 | u16 val; | ||
516 | |||
517 | switch (dcdc) { | ||
518 | case WM8350_DCDC_2: | ||
519 | val = wm8350_reg_read(wm8350, WM8350_DCDC2_CONTROL) | ||
520 | & ~WM8350_DC2_HIB_MODE_MASK; | ||
521 | wm8350_reg_write(wm8350, WM8350_DCDC2_CONTROL, val | | ||
522 | WM8350_DC2_HIB_MODE_ACTIVE); | ||
523 | break; | ||
524 | case WM8350_DCDC_5: | ||
525 | val = wm8350_reg_read(wm8350, WM8350_DCDC5_CONTROL) | ||
526 | & ~WM8350_DC2_HIB_MODE_MASK; | ||
527 | wm8350_reg_write(wm8350, WM8350_DCDC5_CONTROL, val | | ||
528 | WM8350_DC5_HIB_MODE_ACTIVE); | ||
529 | break; | ||
530 | default: | ||
531 | return -EINVAL; | ||
532 | } | ||
533 | return 0; | ||
534 | } | ||
535 | |||
536 | static int wm8350_dcdc25_set_suspend_disable(struct regulator_dev *rdev) | ||
537 | { | ||
538 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
539 | int dcdc = rdev_get_id(rdev); | ||
540 | u16 val; | ||
541 | |||
542 | switch (dcdc) { | ||
543 | case WM8350_DCDC_2: | ||
544 | val = wm8350_reg_read(wm8350, WM8350_DCDC2_CONTROL) | ||
545 | & ~WM8350_DC2_HIB_MODE_MASK; | ||
546 | wm8350_reg_write(wm8350, WM8350_DCDC2_CONTROL, val | | ||
547 | WM8350_DC2_HIB_MODE_DISABLE); | ||
548 | break; | ||
549 | case WM8350_DCDC_5: | ||
550 | val = wm8350_reg_read(wm8350, WM8350_DCDC5_CONTROL) | ||
551 | & ~WM8350_DC2_HIB_MODE_MASK; | ||
552 | wm8350_reg_write(wm8350, WM8350_DCDC5_CONTROL, val | | ||
553 | WM8350_DC2_HIB_MODE_DISABLE); | ||
554 | break; | ||
555 | default: | ||
556 | return -EINVAL; | ||
557 | } | ||
558 | return 0; | ||
559 | } | ||
560 | |||
561 | static int wm8350_dcdc_set_suspend_mode(struct regulator_dev *rdev, | ||
562 | unsigned int mode) | ||
563 | { | ||
564 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
565 | int dcdc = rdev_get_id(rdev); | ||
566 | u16 *hib_mode; | ||
567 | |||
568 | switch (dcdc) { | ||
569 | case WM8350_DCDC_1: | ||
570 | hib_mode = &wm8350->pmic.dcdc1_hib_mode; | ||
571 | break; | ||
572 | case WM8350_DCDC_3: | ||
573 | hib_mode = &wm8350->pmic.dcdc3_hib_mode; | ||
574 | break; | ||
575 | case WM8350_DCDC_4: | ||
576 | hib_mode = &wm8350->pmic.dcdc4_hib_mode; | ||
577 | break; | ||
578 | case WM8350_DCDC_6: | ||
579 | hib_mode = &wm8350->pmic.dcdc6_hib_mode; | ||
580 | break; | ||
581 | case WM8350_DCDC_2: | ||
582 | case WM8350_DCDC_5: | ||
583 | default: | ||
584 | return -EINVAL; | ||
585 | } | ||
586 | |||
587 | switch (mode) { | ||
588 | case REGULATOR_MODE_NORMAL: | ||
589 | *hib_mode = WM8350_DCDC_HIB_MODE_IMAGE; | ||
590 | break; | ||
591 | case REGULATOR_MODE_IDLE: | ||
592 | *hib_mode = WM8350_DCDC_HIB_MODE_STANDBY; | ||
593 | break; | ||
594 | case REGULATOR_MODE_STANDBY: | ||
595 | *hib_mode = WM8350_DCDC_HIB_MODE_LDO_IM; | ||
596 | break; | ||
597 | default: | ||
598 | return -EINVAL; | ||
599 | } | ||
600 | |||
601 | return 0; | ||
602 | } | ||
603 | |||
604 | static int wm8350_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV) | ||
605 | { | ||
606 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
607 | int volt_reg, mV = uV / 1000, ldo = rdev_get_id(rdev); | ||
608 | u16 val; | ||
609 | |||
610 | dev_dbg(wm8350->dev, "%s %d mV %d\n", __func__, ldo, mV); | ||
611 | |||
612 | if (mV < 900 || mV > 3300) { | ||
613 | dev_err(wm8350->dev, "LDO%d voltage %d mV out of range\n", | ||
614 | ldo, mV); | ||
615 | return -EINVAL; | ||
616 | } | ||
617 | |||
618 | switch (ldo) { | ||
619 | case WM8350_LDO_1: | ||
620 | volt_reg = WM8350_LDO1_LOW_POWER; | ||
621 | break; | ||
622 | case WM8350_LDO_2: | ||
623 | volt_reg = WM8350_LDO2_LOW_POWER; | ||
624 | break; | ||
625 | case WM8350_LDO_3: | ||
626 | volt_reg = WM8350_LDO3_LOW_POWER; | ||
627 | break; | ||
628 | case WM8350_LDO_4: | ||
629 | volt_reg = WM8350_LDO4_LOW_POWER; | ||
630 | break; | ||
631 | default: | ||
632 | return -EINVAL; | ||
633 | } | ||
634 | |||
635 | /* all LDOs have same mV bits */ | ||
636 | val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_VSEL_MASK; | ||
637 | wm8350_reg_write(wm8350, volt_reg, | ||
638 | val | wm8350_ldo_mvolts_to_val(mV)); | ||
639 | return 0; | ||
640 | } | ||
641 | |||
642 | static int wm8350_ldo_set_suspend_enable(struct regulator_dev *rdev) | ||
643 | { | ||
644 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
645 | int volt_reg, ldo = rdev_get_id(rdev); | ||
646 | u16 val; | ||
647 | |||
648 | switch (ldo) { | ||
649 | case WM8350_LDO_1: | ||
650 | volt_reg = WM8350_LDO1_LOW_POWER; | ||
651 | break; | ||
652 | case WM8350_LDO_2: | ||
653 | volt_reg = WM8350_LDO2_LOW_POWER; | ||
654 | break; | ||
655 | case WM8350_LDO_3: | ||
656 | volt_reg = WM8350_LDO3_LOW_POWER; | ||
657 | break; | ||
658 | case WM8350_LDO_4: | ||
659 | volt_reg = WM8350_LDO4_LOW_POWER; | ||
660 | break; | ||
661 | default: | ||
662 | return -EINVAL; | ||
663 | } | ||
664 | |||
665 | /* all LDOs have same mV bits */ | ||
666 | val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_HIB_MODE_MASK; | ||
667 | wm8350_reg_write(wm8350, volt_reg, val); | ||
668 | return 0; | ||
669 | } | ||
670 | |||
671 | static int wm8350_ldo_set_suspend_disable(struct regulator_dev *rdev) | ||
672 | { | ||
673 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
674 | int volt_reg, ldo = rdev_get_id(rdev); | ||
675 | u16 val; | ||
676 | |||
677 | switch (ldo) { | ||
678 | case WM8350_LDO_1: | ||
679 | volt_reg = WM8350_LDO1_LOW_POWER; | ||
680 | break; | ||
681 | case WM8350_LDO_2: | ||
682 | volt_reg = WM8350_LDO2_LOW_POWER; | ||
683 | break; | ||
684 | case WM8350_LDO_3: | ||
685 | volt_reg = WM8350_LDO3_LOW_POWER; | ||
686 | break; | ||
687 | case WM8350_LDO_4: | ||
688 | volt_reg = WM8350_LDO4_LOW_POWER; | ||
689 | break; | ||
690 | default: | ||
691 | return -EINVAL; | ||
692 | } | ||
693 | |||
694 | /* all LDOs have same mV bits */ | ||
695 | val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_HIB_MODE_MASK; | ||
696 | wm8350_reg_write(wm8350, volt_reg, WM8350_LDO1_HIB_MODE_DIS); | ||
697 | return 0; | ||
698 | } | ||
699 | |||
700 | static int wm8350_ldo_set_voltage(struct regulator_dev *rdev, int min_uV, | ||
701 | int max_uV) | ||
702 | { | ||
703 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
704 | int volt_reg, ldo = rdev_get_id(rdev), mV, min_mV = min_uV / 1000, | ||
705 | max_mV = max_uV / 1000; | ||
706 | u16 val; | ||
707 | |||
708 | if (min_mV < 900 || min_mV > 3300) | ||
709 | return -EINVAL; | ||
710 | if (max_mV < 900 || max_mV > 3300) | ||
711 | return -EINVAL; | ||
712 | |||
713 | if (min_mV < 1800) { | ||
714 | /* step size is 50mV < 1800mV */ | ||
715 | mV = (min_mV - 851) / 50; | ||
716 | if (wm8350_ldo_val_to_mvolts(mV) > max_mV) | ||
717 | return -EINVAL; | ||
718 | BUG_ON(wm8350_ldo_val_to_mvolts(mV) < min_mV); | ||
719 | } else { | ||
720 | /* step size is 100mV > 1800mV */ | ||
721 | mV = ((min_mV - 1701) / 100) + 16; | ||
722 | if (wm8350_ldo_val_to_mvolts(mV) > max_mV) | ||
723 | return -EINVAL; | ||
724 | BUG_ON(wm8350_ldo_val_to_mvolts(mV) < min_mV); | ||
725 | } | ||
726 | |||
727 | switch (ldo) { | ||
728 | case WM8350_LDO_1: | ||
729 | volt_reg = WM8350_LDO1_CONTROL; | ||
730 | break; | ||
731 | case WM8350_LDO_2: | ||
732 | volt_reg = WM8350_LDO2_CONTROL; | ||
733 | break; | ||
734 | case WM8350_LDO_3: | ||
735 | volt_reg = WM8350_LDO3_CONTROL; | ||
736 | break; | ||
737 | case WM8350_LDO_4: | ||
738 | volt_reg = WM8350_LDO4_CONTROL; | ||
739 | break; | ||
740 | default: | ||
741 | return -EINVAL; | ||
742 | } | ||
743 | |||
744 | /* all LDOs have same mV bits */ | ||
745 | val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_VSEL_MASK; | ||
746 | wm8350_reg_write(wm8350, volt_reg, val | mV); | ||
747 | return 0; | ||
748 | } | ||
749 | |||
750 | static int wm8350_ldo_get_voltage(struct regulator_dev *rdev) | ||
751 | { | ||
752 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
753 | int volt_reg, ldo = rdev_get_id(rdev); | ||
754 | u16 val; | ||
755 | |||
756 | switch (ldo) { | ||
757 | case WM8350_LDO_1: | ||
758 | volt_reg = WM8350_LDO1_CONTROL; | ||
759 | break; | ||
760 | case WM8350_LDO_2: | ||
761 | volt_reg = WM8350_LDO2_CONTROL; | ||
762 | break; | ||
763 | case WM8350_LDO_3: | ||
764 | volt_reg = WM8350_LDO3_CONTROL; | ||
765 | break; | ||
766 | case WM8350_LDO_4: | ||
767 | volt_reg = WM8350_LDO4_CONTROL; | ||
768 | break; | ||
769 | default: | ||
770 | return -EINVAL; | ||
771 | } | ||
772 | |||
773 | /* all LDOs have same mV bits */ | ||
774 | val = wm8350_reg_read(wm8350, volt_reg) & WM8350_LDO1_VSEL_MASK; | ||
775 | return wm8350_ldo_val_to_mvolts(val) * 1000; | ||
776 | } | ||
777 | |||
778 | int wm8350_dcdc_set_slot(struct wm8350 *wm8350, int dcdc, u16 start, | ||
779 | u16 stop, u16 fault) | ||
780 | { | ||
781 | int slot_reg; | ||
782 | u16 val; | ||
783 | |||
784 | dev_dbg(wm8350->dev, "%s %d start %d stop %d\n", | ||
785 | __func__, dcdc, start, stop); | ||
786 | |||
787 | /* slot valid ? */ | ||
788 | if (start > 15 || stop > 15) | ||
789 | return -EINVAL; | ||
790 | |||
791 | switch (dcdc) { | ||
792 | case WM8350_DCDC_1: | ||
793 | slot_reg = WM8350_DCDC1_TIMEOUTS; | ||
794 | break; | ||
795 | case WM8350_DCDC_2: | ||
796 | slot_reg = WM8350_DCDC2_TIMEOUTS; | ||
797 | break; | ||
798 | case WM8350_DCDC_3: | ||
799 | slot_reg = WM8350_DCDC3_TIMEOUTS; | ||
800 | break; | ||
801 | case WM8350_DCDC_4: | ||
802 | slot_reg = WM8350_DCDC4_TIMEOUTS; | ||
803 | break; | ||
804 | case WM8350_DCDC_5: | ||
805 | slot_reg = WM8350_DCDC5_TIMEOUTS; | ||
806 | break; | ||
807 | case WM8350_DCDC_6: | ||
808 | slot_reg = WM8350_DCDC6_TIMEOUTS; | ||
809 | break; | ||
810 | default: | ||
811 | return -EINVAL; | ||
812 | } | ||
813 | |||
814 | val = wm8350_reg_read(wm8350, slot_reg) & | ||
815 | ~(WM8350_DC1_ENSLOT_MASK | WM8350_DC1_SDSLOT_MASK | | ||
816 | WM8350_DC1_ERRACT_MASK); | ||
817 | wm8350_reg_write(wm8350, slot_reg, | ||
818 | val | (start << WM8350_DC1_ENSLOT_SHIFT) | | ||
819 | (stop << WM8350_DC1_SDSLOT_SHIFT) | | ||
820 | (fault << WM8350_DC1_ERRACT_SHIFT)); | ||
821 | |||
822 | return 0; | ||
823 | } | ||
824 | EXPORT_SYMBOL_GPL(wm8350_dcdc_set_slot); | ||
825 | |||
826 | int wm8350_ldo_set_slot(struct wm8350 *wm8350, int ldo, u16 start, u16 stop) | ||
827 | { | ||
828 | int slot_reg; | ||
829 | u16 val; | ||
830 | |||
831 | dev_dbg(wm8350->dev, "%s %d start %d stop %d\n", | ||
832 | __func__, ldo, start, stop); | ||
833 | |||
834 | /* slot valid ? */ | ||
835 | if (start > 15 || stop > 15) | ||
836 | return -EINVAL; | ||
837 | |||
838 | switch (ldo) { | ||
839 | case WM8350_LDO_1: | ||
840 | slot_reg = WM8350_LDO1_TIMEOUTS; | ||
841 | break; | ||
842 | case WM8350_LDO_2: | ||
843 | slot_reg = WM8350_LDO2_TIMEOUTS; | ||
844 | break; | ||
845 | case WM8350_LDO_3: | ||
846 | slot_reg = WM8350_LDO3_TIMEOUTS; | ||
847 | break; | ||
848 | case WM8350_LDO_4: | ||
849 | slot_reg = WM8350_LDO4_TIMEOUTS; | ||
850 | break; | ||
851 | default: | ||
852 | return -EINVAL; | ||
853 | } | ||
854 | |||
855 | val = wm8350_reg_read(wm8350, slot_reg) & ~WM8350_LDO1_SDSLOT_MASK; | ||
856 | wm8350_reg_write(wm8350, slot_reg, val | ((start << 10) | (stop << 6))); | ||
857 | return 0; | ||
858 | } | ||
859 | EXPORT_SYMBOL_GPL(wm8350_ldo_set_slot); | ||
860 | |||
861 | int wm8350_dcdc25_set_mode(struct wm8350 *wm8350, int dcdc, u16 mode, | ||
862 | u16 ilim, u16 ramp, u16 feedback) | ||
863 | { | ||
864 | u16 val; | ||
865 | |||
866 | dev_dbg(wm8350->dev, "%s %d mode: %s %s\n", __func__, dcdc, | ||
867 | mode ? "normal" : "boost", ilim ? "low" : "normal"); | ||
868 | |||
869 | switch (dcdc) { | ||
870 | case WM8350_DCDC_2: | ||
871 | val = wm8350_reg_read(wm8350, WM8350_DCDC2_CONTROL) | ||
872 | & ~(WM8350_DC2_MODE_MASK | WM8350_DC2_ILIM_MASK | | ||
873 | WM8350_DC2_RMP_MASK | WM8350_DC2_FBSRC_MASK); | ||
874 | wm8350_reg_write(wm8350, WM8350_DCDC2_CONTROL, val | | ||
875 | (mode << WM8350_DC2_MODE_SHIFT) | | ||
876 | (ilim << WM8350_DC2_ILIM_SHIFT) | | ||
877 | (ramp << WM8350_DC2_RMP_SHIFT) | | ||
878 | (feedback << WM8350_DC2_FBSRC_SHIFT)); | ||
879 | break; | ||
880 | case WM8350_DCDC_5: | ||
881 | val = wm8350_reg_read(wm8350, WM8350_DCDC5_CONTROL) | ||
882 | & ~(WM8350_DC5_MODE_MASK | WM8350_DC5_ILIM_MASK | | ||
883 | WM8350_DC5_RMP_MASK | WM8350_DC5_FBSRC_MASK); | ||
884 | wm8350_reg_write(wm8350, WM8350_DCDC5_CONTROL, val | | ||
885 | (mode << WM8350_DC5_MODE_SHIFT) | | ||
886 | (ilim << WM8350_DC5_ILIM_SHIFT) | | ||
887 | (ramp << WM8350_DC5_RMP_SHIFT) | | ||
888 | (feedback << WM8350_DC5_FBSRC_SHIFT)); | ||
889 | break; | ||
890 | default: | ||
891 | return -EINVAL; | ||
892 | } | ||
893 | |||
894 | return 0; | ||
895 | } | ||
896 | EXPORT_SYMBOL_GPL(wm8350_dcdc25_set_mode); | ||
897 | |||
898 | static int wm8350_dcdc_enable(struct regulator_dev *rdev) | ||
899 | { | ||
900 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
901 | int dcdc = rdev_get_id(rdev); | ||
902 | u16 shift; | ||
903 | |||
904 | if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6) | ||
905 | return -EINVAL; | ||
906 | |||
907 | shift = dcdc - WM8350_DCDC_1; | ||
908 | wm8350_set_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, 1 << shift); | ||
909 | return 0; | ||
910 | } | ||
911 | |||
912 | static int wm8350_dcdc_disable(struct regulator_dev *rdev) | ||
913 | { | ||
914 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
915 | int dcdc = rdev_get_id(rdev); | ||
916 | u16 shift; | ||
917 | |||
918 | if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6) | ||
919 | return -EINVAL; | ||
920 | |||
921 | shift = dcdc - WM8350_DCDC_1; | ||
922 | wm8350_clear_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, 1 << shift); | ||
923 | |||
924 | return 0; | ||
925 | } | ||
926 | |||
927 | static int wm8350_ldo_enable(struct regulator_dev *rdev) | ||
928 | { | ||
929 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
930 | int ldo = rdev_get_id(rdev); | ||
931 | u16 shift; | ||
932 | |||
933 | if (ldo < WM8350_LDO_1 || ldo > WM8350_LDO_4) | ||
934 | return -EINVAL; | ||
935 | |||
936 | shift = (ldo - WM8350_LDO_1) + 8; | ||
937 | wm8350_set_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, 1 << shift); | ||
938 | return 0; | ||
939 | } | ||
940 | |||
941 | static int wm8350_ldo_disable(struct regulator_dev *rdev) | ||
942 | { | ||
943 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
944 | int ldo = rdev_get_id(rdev); | ||
945 | u16 shift; | ||
946 | |||
947 | if (ldo < WM8350_LDO_1 || ldo > WM8350_LDO_4) | ||
948 | return -EINVAL; | ||
949 | |||
950 | shift = (ldo - WM8350_LDO_1) + 8; | ||
951 | wm8350_clear_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, 1 << shift); | ||
952 | return 0; | ||
953 | } | ||
954 | |||
955 | static int force_continuous_enable(struct wm8350 *wm8350, int dcdc, int enable) | ||
956 | { | ||
957 | int reg = 0, ret; | ||
958 | |||
959 | switch (dcdc) { | ||
960 | case WM8350_DCDC_1: | ||
961 | reg = WM8350_DCDC1_FORCE_PWM; | ||
962 | break; | ||
963 | case WM8350_DCDC_3: | ||
964 | reg = WM8350_DCDC3_FORCE_PWM; | ||
965 | break; | ||
966 | case WM8350_DCDC_4: | ||
967 | reg = WM8350_DCDC4_FORCE_PWM; | ||
968 | break; | ||
969 | case WM8350_DCDC_6: | ||
970 | reg = WM8350_DCDC6_FORCE_PWM; | ||
971 | break; | ||
972 | default: | ||
973 | return -EINVAL; | ||
974 | } | ||
975 | |||
976 | if (enable) | ||
977 | ret = wm8350_set_bits(wm8350, reg, | ||
978 | WM8350_DCDC1_FORCE_PWM_ENA); | ||
979 | else | ||
980 | ret = wm8350_clear_bits(wm8350, reg, | ||
981 | WM8350_DCDC1_FORCE_PWM_ENA); | ||
982 | return ret; | ||
983 | } | ||
984 | |||
985 | static int wm8350_dcdc_set_mode(struct regulator_dev *rdev, unsigned int mode) | ||
986 | { | ||
987 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
988 | int dcdc = rdev_get_id(rdev); | ||
989 | u16 val; | ||
990 | |||
991 | if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6) | ||
992 | return -EINVAL; | ||
993 | |||
994 | if (dcdc == WM8350_DCDC_2 || dcdc == WM8350_DCDC_5) | ||
995 | return -EINVAL; | ||
996 | |||
997 | val = 1 << (dcdc - WM8350_DCDC_1); | ||
998 | |||
999 | switch (mode) { | ||
1000 | case REGULATOR_MODE_FAST: | ||
1001 | /* force continuous mode */ | ||
1002 | wm8350_set_bits(wm8350, WM8350_DCDC_ACTIVE_OPTIONS, val); | ||
1003 | wm8350_clear_bits(wm8350, WM8350_DCDC_SLEEP_OPTIONS, val); | ||
1004 | force_continuous_enable(wm8350, dcdc, 1); | ||
1005 | break; | ||
1006 | case REGULATOR_MODE_NORMAL: | ||
1007 | /* active / pulse skipping */ | ||
1008 | wm8350_set_bits(wm8350, WM8350_DCDC_ACTIVE_OPTIONS, val); | ||
1009 | wm8350_clear_bits(wm8350, WM8350_DCDC_SLEEP_OPTIONS, val); | ||
1010 | force_continuous_enable(wm8350, dcdc, 0); | ||
1011 | break; | ||
1012 | case REGULATOR_MODE_IDLE: | ||
1013 | /* standby mode */ | ||
1014 | force_continuous_enable(wm8350, dcdc, 0); | ||
1015 | wm8350_clear_bits(wm8350, WM8350_DCDC_SLEEP_OPTIONS, val); | ||
1016 | wm8350_clear_bits(wm8350, WM8350_DCDC_ACTIVE_OPTIONS, val); | ||
1017 | break; | ||
1018 | case REGULATOR_MODE_STANDBY: | ||
1019 | /* LDO mode */ | ||
1020 | force_continuous_enable(wm8350, dcdc, 0); | ||
1021 | wm8350_set_bits(wm8350, WM8350_DCDC_SLEEP_OPTIONS, val); | ||
1022 | break; | ||
1023 | } | ||
1024 | |||
1025 | return 0; | ||
1026 | } | ||
1027 | |||
1028 | static unsigned int wm8350_dcdc_get_mode(struct regulator_dev *rdev) | ||
1029 | { | ||
1030 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
1031 | int dcdc = rdev_get_id(rdev); | ||
1032 | u16 mask, sleep, active, force; | ||
1033 | int mode = REGULATOR_MODE_NORMAL; | ||
1034 | |||
1035 | if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6) | ||
1036 | return -EINVAL; | ||
1037 | |||
1038 | if (dcdc == WM8350_DCDC_2 || dcdc == WM8350_DCDC_5) | ||
1039 | return -EINVAL; | ||
1040 | |||
1041 | mask = 1 << (dcdc - WM8350_DCDC_1); | ||
1042 | active = wm8350_reg_read(wm8350, WM8350_DCDC_ACTIVE_OPTIONS) & mask; | ||
1043 | sleep = wm8350_reg_read(wm8350, WM8350_DCDC_SLEEP_OPTIONS) & mask; | ||
1044 | force = wm8350_reg_read(wm8350, WM8350_DCDC1_FORCE_PWM) | ||
1045 | & WM8350_DCDC1_FORCE_PWM_ENA; | ||
1046 | dev_dbg(wm8350->dev, "mask %x active %x sleep %x force %x", | ||
1047 | mask, active, sleep, force); | ||
1048 | |||
1049 | if (active && !sleep) { | ||
1050 | if (force) | ||
1051 | mode = REGULATOR_MODE_FAST; | ||
1052 | else | ||
1053 | mode = REGULATOR_MODE_NORMAL; | ||
1054 | } else if (!active && !sleep) | ||
1055 | mode = REGULATOR_MODE_IDLE; | ||
1056 | else if (!sleep) | ||
1057 | mode = REGULATOR_MODE_STANDBY; | ||
1058 | |||
1059 | return mode; | ||
1060 | } | ||
1061 | |||
1062 | static unsigned int wm8350_ldo_get_mode(struct regulator_dev *rdev) | ||
1063 | { | ||
1064 | return REGULATOR_MODE_NORMAL; | ||
1065 | } | ||
1066 | |||
1067 | struct wm8350_dcdc_efficiency { | ||
1068 | int uA_load_min; | ||
1069 | int uA_load_max; | ||
1070 | unsigned int mode; | ||
1071 | }; | ||
1072 | |||
1073 | static const struct wm8350_dcdc_efficiency dcdc1_6_efficiency[] = { | ||
1074 | {0, 10000, REGULATOR_MODE_STANDBY}, /* 0 - 10mA - LDO */ | ||
1075 | {10000, 100000, REGULATOR_MODE_IDLE}, /* 10mA - 100mA - Standby */ | ||
1076 | {100000, 1000000, REGULATOR_MODE_NORMAL}, /* > 100mA - Active */ | ||
1077 | {-1, -1, REGULATOR_MODE_NORMAL}, | ||
1078 | }; | ||
1079 | |||
1080 | static const struct wm8350_dcdc_efficiency dcdc3_4_efficiency[] = { | ||
1081 | {0, 10000, REGULATOR_MODE_STANDBY}, /* 0 - 10mA - LDO */ | ||
1082 | {10000, 100000, REGULATOR_MODE_IDLE}, /* 10mA - 100mA - Standby */ | ||
1083 | {100000, 800000, REGULATOR_MODE_NORMAL}, /* > 100mA - Active */ | ||
1084 | {-1, -1, REGULATOR_MODE_NORMAL}, | ||
1085 | }; | ||
1086 | |||
1087 | static unsigned int get_mode(int uA, const struct wm8350_dcdc_efficiency *eff) | ||
1088 | { | ||
1089 | int i = 0; | ||
1090 | |||
1091 | while (eff[i].uA_load_min != -1) { | ||
1092 | if (uA >= eff[i].uA_load_min && uA <= eff[i].uA_load_max) | ||
1093 | return eff[i].mode; | ||
1094 | } | ||
1095 | return REGULATOR_MODE_NORMAL; | ||
1096 | } | ||
1097 | |||
1098 | /* Query the regulator for it's most efficient mode @ uV,uA | ||
1099 | * WM8350 regulator efficiency is pretty similar over | ||
1100 | * different input and output uV. | ||
1101 | */ | ||
1102 | static unsigned int wm8350_dcdc_get_optimum_mode(struct regulator_dev *rdev, | ||
1103 | int input_uV, int output_uV, | ||
1104 | int output_uA) | ||
1105 | { | ||
1106 | int dcdc = rdev_get_id(rdev), mode; | ||
1107 | |||
1108 | switch (dcdc) { | ||
1109 | case WM8350_DCDC_1: | ||
1110 | case WM8350_DCDC_6: | ||
1111 | mode = get_mode(output_uA, dcdc1_6_efficiency); | ||
1112 | break; | ||
1113 | case WM8350_DCDC_3: | ||
1114 | case WM8350_DCDC_4: | ||
1115 | mode = get_mode(output_uA, dcdc3_4_efficiency); | ||
1116 | break; | ||
1117 | default: | ||
1118 | mode = REGULATOR_MODE_NORMAL; | ||
1119 | break; | ||
1120 | } | ||
1121 | return mode; | ||
1122 | } | ||
1123 | |||
1124 | static int wm8350_dcdc_is_enabled(struct regulator_dev *rdev) | ||
1125 | { | ||
1126 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
1127 | int dcdc = rdev_get_id(rdev), shift; | ||
1128 | |||
1129 | if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6) | ||
1130 | return -EINVAL; | ||
1131 | |||
1132 | shift = dcdc - WM8350_DCDC_1; | ||
1133 | return wm8350_reg_read(wm8350, WM8350_DCDC_LDO_REQUESTED) | ||
1134 | & (1 << shift); | ||
1135 | } | ||
1136 | |||
1137 | static int wm8350_ldo_is_enabled(struct regulator_dev *rdev) | ||
1138 | { | ||
1139 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
1140 | int ldo = rdev_get_id(rdev), shift; | ||
1141 | |||
1142 | if (ldo < WM8350_LDO_1 || ldo > WM8350_LDO_4) | ||
1143 | return -EINVAL; | ||
1144 | |||
1145 | shift = (ldo - WM8350_LDO_1) + 8; | ||
1146 | return wm8350_reg_read(wm8350, WM8350_DCDC_LDO_REQUESTED) | ||
1147 | & (1 << shift); | ||
1148 | } | ||
1149 | |||
1150 | static struct regulator_ops wm8350_dcdc_ops = { | ||
1151 | .set_voltage = wm8350_dcdc_set_voltage, | ||
1152 | .get_voltage = wm8350_dcdc_get_voltage, | ||
1153 | .enable = wm8350_dcdc_enable, | ||
1154 | .disable = wm8350_dcdc_disable, | ||
1155 | .get_mode = wm8350_dcdc_get_mode, | ||
1156 | .set_mode = wm8350_dcdc_set_mode, | ||
1157 | .get_optimum_mode = wm8350_dcdc_get_optimum_mode, | ||
1158 | .is_enabled = wm8350_dcdc_is_enabled, | ||
1159 | .set_suspend_voltage = wm8350_dcdc_set_suspend_voltage, | ||
1160 | .set_suspend_enable = wm8350_dcdc_set_suspend_enable, | ||
1161 | .set_suspend_disable = wm8350_dcdc_set_suspend_disable, | ||
1162 | .set_suspend_mode = wm8350_dcdc_set_suspend_mode, | ||
1163 | }; | ||
1164 | |||
1165 | static struct regulator_ops wm8350_dcdc2_5_ops = { | ||
1166 | .enable = wm8350_dcdc_enable, | ||
1167 | .disable = wm8350_dcdc_disable, | ||
1168 | .is_enabled = wm8350_dcdc_is_enabled, | ||
1169 | .set_suspend_enable = wm8350_dcdc25_set_suspend_enable, | ||
1170 | .set_suspend_disable = wm8350_dcdc25_set_suspend_disable, | ||
1171 | }; | ||
1172 | |||
1173 | static struct regulator_ops wm8350_ldo_ops = { | ||
1174 | .set_voltage = wm8350_ldo_set_voltage, | ||
1175 | .get_voltage = wm8350_ldo_get_voltage, | ||
1176 | .enable = wm8350_ldo_enable, | ||
1177 | .disable = wm8350_ldo_disable, | ||
1178 | .is_enabled = wm8350_ldo_is_enabled, | ||
1179 | .get_mode = wm8350_ldo_get_mode, | ||
1180 | .set_suspend_voltage = wm8350_ldo_set_suspend_voltage, | ||
1181 | .set_suspend_enable = wm8350_ldo_set_suspend_enable, | ||
1182 | .set_suspend_disable = wm8350_ldo_set_suspend_disable, | ||
1183 | }; | ||
1184 | |||
1185 | static struct regulator_ops wm8350_isink_ops = { | ||
1186 | .set_current_limit = wm8350_isink_set_current, | ||
1187 | .get_current_limit = wm8350_isink_get_current, | ||
1188 | .enable = wm8350_isink_enable, | ||
1189 | .disable = wm8350_isink_disable, | ||
1190 | .is_enabled = wm8350_isink_is_enabled, | ||
1191 | }; | ||
1192 | |||
1193 | static struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | ||
1194 | { | ||
1195 | .name = "DCDC1", | ||
1196 | .id = WM8350_DCDC_1, | ||
1197 | .ops = &wm8350_dcdc_ops, | ||
1198 | .irq = WM8350_IRQ_UV_DC1, | ||
1199 | .type = REGULATOR_VOLTAGE, | ||
1200 | .owner = THIS_MODULE, | ||
1201 | }, | ||
1202 | { | ||
1203 | .name = "DCDC2", | ||
1204 | .id = WM8350_DCDC_2, | ||
1205 | .ops = &wm8350_dcdc2_5_ops, | ||
1206 | .irq = WM8350_IRQ_UV_DC2, | ||
1207 | .type = REGULATOR_VOLTAGE, | ||
1208 | .owner = THIS_MODULE, | ||
1209 | }, | ||
1210 | { | ||
1211 | .name = "DCDC3", | ||
1212 | .id = WM8350_DCDC_3, | ||
1213 | .ops = &wm8350_dcdc_ops, | ||
1214 | .irq = WM8350_IRQ_UV_DC3, | ||
1215 | .type = REGULATOR_VOLTAGE, | ||
1216 | .owner = THIS_MODULE, | ||
1217 | }, | ||
1218 | { | ||
1219 | .name = "DCDC4", | ||
1220 | .id = WM8350_DCDC_4, | ||
1221 | .ops = &wm8350_dcdc_ops, | ||
1222 | .irq = WM8350_IRQ_UV_DC4, | ||
1223 | .type = REGULATOR_VOLTAGE, | ||
1224 | .owner = THIS_MODULE, | ||
1225 | }, | ||
1226 | { | ||
1227 | .name = "DCDC5", | ||
1228 | .id = WM8350_DCDC_5, | ||
1229 | .ops = &wm8350_dcdc2_5_ops, | ||
1230 | .irq = WM8350_IRQ_UV_DC5, | ||
1231 | .type = REGULATOR_VOLTAGE, | ||
1232 | .owner = THIS_MODULE, | ||
1233 | }, | ||
1234 | { | ||
1235 | .name = "DCDC6", | ||
1236 | .id = WM8350_DCDC_6, | ||
1237 | .ops = &wm8350_dcdc_ops, | ||
1238 | .irq = WM8350_IRQ_UV_DC6, | ||
1239 | .type = REGULATOR_VOLTAGE, | ||
1240 | .owner = THIS_MODULE, | ||
1241 | }, | ||
1242 | { | ||
1243 | .name = "LDO1", | ||
1244 | .id = WM8350_LDO_1, | ||
1245 | .ops = &wm8350_ldo_ops, | ||
1246 | .irq = WM8350_IRQ_UV_LDO1, | ||
1247 | .type = REGULATOR_VOLTAGE, | ||
1248 | .owner = THIS_MODULE, | ||
1249 | }, | ||
1250 | { | ||
1251 | .name = "LDO2", | ||
1252 | .id = WM8350_LDO_2, | ||
1253 | .ops = &wm8350_ldo_ops, | ||
1254 | .irq = WM8350_IRQ_UV_LDO2, | ||
1255 | .type = REGULATOR_VOLTAGE, | ||
1256 | .owner = THIS_MODULE, | ||
1257 | }, | ||
1258 | { | ||
1259 | .name = "LDO3", | ||
1260 | .id = WM8350_LDO_3, | ||
1261 | .ops = &wm8350_ldo_ops, | ||
1262 | .irq = WM8350_IRQ_UV_LDO3, | ||
1263 | .type = REGULATOR_VOLTAGE, | ||
1264 | .owner = THIS_MODULE, | ||
1265 | }, | ||
1266 | { | ||
1267 | .name = "LDO4", | ||
1268 | .id = WM8350_LDO_4, | ||
1269 | .ops = &wm8350_ldo_ops, | ||
1270 | .irq = WM8350_IRQ_UV_LDO4, | ||
1271 | .type = REGULATOR_VOLTAGE, | ||
1272 | .owner = THIS_MODULE, | ||
1273 | }, | ||
1274 | { | ||
1275 | .name = "ISINKA", | ||
1276 | .id = WM8350_ISINK_A, | ||
1277 | .ops = &wm8350_isink_ops, | ||
1278 | .irq = WM8350_IRQ_CS1, | ||
1279 | .type = REGULATOR_CURRENT, | ||
1280 | .owner = THIS_MODULE, | ||
1281 | }, | ||
1282 | { | ||
1283 | .name = "ISINKB", | ||
1284 | .id = WM8350_ISINK_B, | ||
1285 | .ops = &wm8350_isink_ops, | ||
1286 | .irq = WM8350_IRQ_CS2, | ||
1287 | .type = REGULATOR_CURRENT, | ||
1288 | .owner = THIS_MODULE, | ||
1289 | }, | ||
1290 | }; | ||
1291 | |||
1292 | static void pmic_uv_handler(struct wm8350 *wm8350, int irq, void *data) | ||
1293 | { | ||
1294 | struct regulator_dev *rdev = (struct regulator_dev *)data; | ||
1295 | |||
1296 | if (irq == WM8350_IRQ_CS1 || irq == WM8350_IRQ_CS2) | ||
1297 | regulator_notifier_call_chain(rdev, | ||
1298 | REGULATOR_EVENT_REGULATION_OUT, | ||
1299 | wm8350); | ||
1300 | else | ||
1301 | regulator_notifier_call_chain(rdev, | ||
1302 | REGULATOR_EVENT_UNDER_VOLTAGE, | ||
1303 | wm8350); | ||
1304 | } | ||
1305 | |||
1306 | static int wm8350_regulator_probe(struct platform_device *pdev) | ||
1307 | { | ||
1308 | struct wm8350 *wm8350 = dev_get_drvdata(&pdev->dev); | ||
1309 | struct regulator_dev *rdev; | ||
1310 | int ret; | ||
1311 | u16 val; | ||
1312 | |||
1313 | if (pdev->id < WM8350_DCDC_1 || pdev->id > WM8350_ISINK_B) | ||
1314 | return -ENODEV; | ||
1315 | |||
1316 | /* do any regulatior specific init */ | ||
1317 | switch (pdev->id) { | ||
1318 | case WM8350_DCDC_1: | ||
1319 | val = wm8350_reg_read(wm8350, WM8350_DCDC1_LOW_POWER); | ||
1320 | wm8350->pmic.dcdc1_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK; | ||
1321 | break; | ||
1322 | case WM8350_DCDC_3: | ||
1323 | val = wm8350_reg_read(wm8350, WM8350_DCDC3_LOW_POWER); | ||
1324 | wm8350->pmic.dcdc3_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK; | ||
1325 | break; | ||
1326 | case WM8350_DCDC_4: | ||
1327 | val = wm8350_reg_read(wm8350, WM8350_DCDC4_LOW_POWER); | ||
1328 | wm8350->pmic.dcdc4_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK; | ||
1329 | break; | ||
1330 | case WM8350_DCDC_6: | ||
1331 | val = wm8350_reg_read(wm8350, WM8350_DCDC6_LOW_POWER); | ||
1332 | wm8350->pmic.dcdc6_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK; | ||
1333 | break; | ||
1334 | } | ||
1335 | |||
1336 | |||
1337 | /* register regulator */ | ||
1338 | rdev = regulator_register(&wm8350_reg[pdev->id], &pdev->dev, | ||
1339 | dev_get_drvdata(&pdev->dev)); | ||
1340 | if (IS_ERR(rdev)) { | ||
1341 | dev_err(&pdev->dev, "failed to register %s\n", | ||
1342 | wm8350_reg[pdev->id].name); | ||
1343 | return PTR_ERR(rdev); | ||
1344 | } | ||
1345 | |||
1346 | /* register regulator IRQ */ | ||
1347 | ret = wm8350_register_irq(wm8350, wm8350_reg[pdev->id].irq, | ||
1348 | pmic_uv_handler, rdev); | ||
1349 | if (ret < 0) { | ||
1350 | regulator_unregister(rdev); | ||
1351 | dev_err(&pdev->dev, "failed to register regulator %s IRQ\n", | ||
1352 | wm8350_reg[pdev->id].name); | ||
1353 | return ret; | ||
1354 | } | ||
1355 | |||
1356 | wm8350_unmask_irq(wm8350, wm8350_reg[pdev->id].irq); | ||
1357 | |||
1358 | return 0; | ||
1359 | } | ||
1360 | |||
1361 | static int wm8350_regulator_remove(struct platform_device *pdev) | ||
1362 | { | ||
1363 | struct regulator_dev *rdev = platform_get_drvdata(pdev); | ||
1364 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
1365 | |||
1366 | wm8350_mask_irq(wm8350, wm8350_reg[pdev->id].irq); | ||
1367 | wm8350_free_irq(wm8350, wm8350_reg[pdev->id].irq); | ||
1368 | |||
1369 | regulator_unregister(rdev); | ||
1370 | |||
1371 | return 0; | ||
1372 | } | ||
1373 | |||
1374 | int wm8350_register_regulator(struct wm8350 *wm8350, int reg, | ||
1375 | struct regulator_init_data *initdata) | ||
1376 | { | ||
1377 | struct platform_device *pdev; | ||
1378 | int ret; | ||
1379 | |||
1380 | if (wm8350->pmic.pdev[reg]) | ||
1381 | return -EBUSY; | ||
1382 | |||
1383 | pdev = platform_device_alloc("wm8350-regulator", reg); | ||
1384 | if (!pdev) | ||
1385 | return -ENOMEM; | ||
1386 | |||
1387 | wm8350->pmic.pdev[reg] = pdev; | ||
1388 | |||
1389 | initdata->driver_data = wm8350; | ||
1390 | |||
1391 | pdev->dev.platform_data = initdata; | ||
1392 | pdev->dev.parent = wm8350->dev; | ||
1393 | platform_set_drvdata(pdev, wm8350); | ||
1394 | |||
1395 | ret = platform_device_add(pdev); | ||
1396 | |||
1397 | if (ret != 0) { | ||
1398 | dev_err(wm8350->dev, "Failed to register regulator %d: %d\n", | ||
1399 | reg, ret); | ||
1400 | platform_device_del(pdev); | ||
1401 | wm8350->pmic.pdev[reg] = NULL; | ||
1402 | } | ||
1403 | |||
1404 | return ret; | ||
1405 | } | ||
1406 | EXPORT_SYMBOL_GPL(wm8350_register_regulator); | ||
1407 | |||
1408 | static struct platform_driver wm8350_regulator_driver = { | ||
1409 | .probe = wm8350_regulator_probe, | ||
1410 | .remove = wm8350_regulator_remove, | ||
1411 | .driver = { | ||
1412 | .name = "wm8350-regulator", | ||
1413 | }, | ||
1414 | }; | ||
1415 | |||
1416 | static int __init wm8350_regulator_init(void) | ||
1417 | { | ||
1418 | return platform_driver_register(&wm8350_regulator_driver); | ||
1419 | } | ||
1420 | subsys_initcall(wm8350_regulator_init); | ||
1421 | |||
1422 | static void __exit wm8350_regulator_exit(void) | ||
1423 | { | ||
1424 | platform_driver_unregister(&wm8350_regulator_driver); | ||
1425 | } | ||
1426 | module_exit(wm8350_regulator_exit); | ||
1427 | |||
1428 | /* Module information */ | ||
1429 | MODULE_AUTHOR("Liam Girdwood"); | ||
1430 | MODULE_DESCRIPTION("WM8350 voltage and current regulator driver"); | ||
1431 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/regulator/wm8400-regulator.c b/drivers/regulator/wm8400-regulator.c new file mode 100644 index 000000000000..48b372e038a8 --- /dev/null +++ b/drivers/regulator/wm8400-regulator.c | |||
@@ -0,0 +1,368 @@ | |||
1 | /* | ||
2 | * Regulator support for WM8400 | ||
3 | * | ||
4 | * Copyright 2008 Wolfson Microelectronics PLC. | ||
5 | * | ||
6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU General Public License as | ||
10 | * published by the Free Software Foundation; either version 2 of the | ||
11 | * License, or (at your option) any later version. | ||
12 | * | ||
13 | */ | ||
14 | |||
15 | #include <linux/bug.h> | ||
16 | #include <linux/err.h> | ||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/regulator/driver.h> | ||
19 | #include <linux/mfd/wm8400-private.h> | ||
20 | |||
21 | static int wm8400_ldo_is_enabled(struct regulator_dev *dev) | ||
22 | { | ||
23 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
24 | u16 val; | ||
25 | |||
26 | val = wm8400_reg_read(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev)); | ||
27 | return (val & WM8400_LDO1_ENA) != 0; | ||
28 | } | ||
29 | |||
30 | static int wm8400_ldo_enable(struct regulator_dev *dev) | ||
31 | { | ||
32 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
33 | |||
34 | return wm8400_set_bits(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev), | ||
35 | WM8400_LDO1_ENA, WM8400_LDO1_ENA); | ||
36 | } | ||
37 | |||
38 | static int wm8400_ldo_disable(struct regulator_dev *dev) | ||
39 | { | ||
40 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
41 | |||
42 | return wm8400_set_bits(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev), | ||
43 | WM8400_LDO1_ENA, 0); | ||
44 | } | ||
45 | |||
46 | static int wm8400_ldo_get_voltage(struct regulator_dev *dev) | ||
47 | { | ||
48 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
49 | u16 val; | ||
50 | |||
51 | val = wm8400_reg_read(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev)); | ||
52 | val &= WM8400_LDO1_VSEL_MASK; | ||
53 | |||
54 | if (val < 15) | ||
55 | return 900000 + (val * 50000); | ||
56 | else | ||
57 | return 1600000 + ((val - 14) * 100000); | ||
58 | } | ||
59 | |||
60 | static int wm8400_ldo_set_voltage(struct regulator_dev *dev, | ||
61 | int min_uV, int max_uV) | ||
62 | { | ||
63 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
64 | u16 val; | ||
65 | |||
66 | if (min_uV < 900000 || min_uV > 3300000) | ||
67 | return -EINVAL; | ||
68 | |||
69 | if (min_uV < 1700000) { | ||
70 | /* Steps of 50mV from 900mV; */ | ||
71 | val = (min_uV - 850001) / 50000; | ||
72 | |||
73 | if ((val * 50000) + 900000 > max_uV) | ||
74 | return -EINVAL; | ||
75 | BUG_ON((val * 50000) + 900000 < min_uV); | ||
76 | } else { | ||
77 | /* Steps of 100mV from 1700mV */ | ||
78 | val = ((min_uV - 1600001) / 100000); | ||
79 | |||
80 | if ((val * 100000) + 1700000 > max_uV) | ||
81 | return -EINVAL; | ||
82 | BUG_ON((val * 100000) + 1700000 < min_uV); | ||
83 | |||
84 | val += 0xf; | ||
85 | } | ||
86 | |||
87 | return wm8400_set_bits(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev), | ||
88 | WM8400_LDO1_VSEL_MASK, val); | ||
89 | } | ||
90 | |||
91 | static struct regulator_ops wm8400_ldo_ops = { | ||
92 | .is_enabled = wm8400_ldo_is_enabled, | ||
93 | .enable = wm8400_ldo_enable, | ||
94 | .disable = wm8400_ldo_disable, | ||
95 | .get_voltage = wm8400_ldo_get_voltage, | ||
96 | .set_voltage = wm8400_ldo_set_voltage, | ||
97 | }; | ||
98 | |||
99 | static int wm8400_dcdc_is_enabled(struct regulator_dev *dev) | ||
100 | { | ||
101 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
102 | int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2; | ||
103 | u16 val; | ||
104 | |||
105 | val = wm8400_reg_read(wm8400, WM8400_DCDC1_CONTROL_1 + offset); | ||
106 | return (val & WM8400_DC1_ENA) != 0; | ||
107 | } | ||
108 | |||
109 | static int wm8400_dcdc_enable(struct regulator_dev *dev) | ||
110 | { | ||
111 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
112 | int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2; | ||
113 | |||
114 | return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset, | ||
115 | WM8400_DC1_ENA, WM8400_DC1_ENA); | ||
116 | } | ||
117 | |||
118 | static int wm8400_dcdc_disable(struct regulator_dev *dev) | ||
119 | { | ||
120 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
121 | int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2; | ||
122 | |||
123 | return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset, | ||
124 | WM8400_DC1_ENA, 0); | ||
125 | } | ||
126 | |||
127 | static int wm8400_dcdc_get_voltage(struct regulator_dev *dev) | ||
128 | { | ||
129 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
130 | u16 val; | ||
131 | int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2; | ||
132 | |||
133 | val = wm8400_reg_read(wm8400, WM8400_DCDC1_CONTROL_1 + offset); | ||
134 | val &= WM8400_DC1_VSEL_MASK; | ||
135 | |||
136 | return 850000 + (25000 * val); | ||
137 | } | ||
138 | |||
139 | static int wm8400_dcdc_set_voltage(struct regulator_dev *dev, | ||
140 | int min_uV, int max_uV) | ||
141 | { | ||
142 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
143 | u16 val; | ||
144 | int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2; | ||
145 | |||
146 | if (min_uV < 850000) | ||
147 | return -EINVAL; | ||
148 | |||
149 | val = (min_uV - 825001) / 25000; | ||
150 | |||
151 | if (850000 + (25000 * val) > max_uV) | ||
152 | return -EINVAL; | ||
153 | BUG_ON(850000 + (25000 * val) < min_uV); | ||
154 | |||
155 | return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset, | ||
156 | WM8400_DC1_VSEL_MASK, val); | ||
157 | } | ||
158 | |||
159 | static unsigned int wm8400_dcdc_get_mode(struct regulator_dev *dev) | ||
160 | { | ||
161 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
162 | int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2; | ||
163 | u16 data[2]; | ||
164 | int ret; | ||
165 | |||
166 | ret = wm8400_block_read(wm8400, WM8400_DCDC1_CONTROL_1 + offset, 2, | ||
167 | data); | ||
168 | if (ret != 0) | ||
169 | return 0; | ||
170 | |||
171 | /* Datasheet: hibernate */ | ||
172 | if (data[0] & WM8400_DC1_SLEEP) | ||
173 | return REGULATOR_MODE_STANDBY; | ||
174 | |||
175 | /* Datasheet: standby */ | ||
176 | if (!(data[0] & WM8400_DC1_ACTIVE)) | ||
177 | return REGULATOR_MODE_IDLE; | ||
178 | |||
179 | /* Datasheet: active with or without force PWM */ | ||
180 | if (data[1] & WM8400_DC1_FRC_PWM) | ||
181 | return REGULATOR_MODE_FAST; | ||
182 | else | ||
183 | return REGULATOR_MODE_NORMAL; | ||
184 | } | ||
185 | |||
186 | static int wm8400_dcdc_set_mode(struct regulator_dev *dev, unsigned int mode) | ||
187 | { | ||
188 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
189 | int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2; | ||
190 | int ret; | ||
191 | |||
192 | switch (mode) { | ||
193 | case REGULATOR_MODE_FAST: | ||
194 | /* Datasheet: active with force PWM */ | ||
195 | ret = wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_2 + offset, | ||
196 | WM8400_DC1_FRC_PWM, WM8400_DC1_FRC_PWM); | ||
197 | if (ret != 0) | ||
198 | return ret; | ||
199 | |||
200 | return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset, | ||
201 | WM8400_DC1_ACTIVE | WM8400_DC1_SLEEP, | ||
202 | WM8400_DC1_ACTIVE); | ||
203 | |||
204 | case REGULATOR_MODE_NORMAL: | ||
205 | /* Datasheet: active */ | ||
206 | ret = wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_2 + offset, | ||
207 | WM8400_DC1_FRC_PWM, 0); | ||
208 | if (ret != 0) | ||
209 | return ret; | ||
210 | |||
211 | return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset, | ||
212 | WM8400_DC1_ACTIVE | WM8400_DC1_SLEEP, | ||
213 | WM8400_DC1_ACTIVE); | ||
214 | |||
215 | case REGULATOR_MODE_IDLE: | ||
216 | /* Datasheet: standby */ | ||
217 | ret = wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset, | ||
218 | WM8400_DC1_ACTIVE, 0); | ||
219 | if (ret != 0) | ||
220 | return ret; | ||
221 | return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset, | ||
222 | WM8400_DC1_SLEEP, 0); | ||
223 | |||
224 | default: | ||
225 | return -EINVAL; | ||
226 | } | ||
227 | } | ||
228 | |||
229 | static unsigned int wm8400_dcdc_get_optimum_mode(struct regulator_dev *dev, | ||
230 | int input_uV, int output_uV, | ||
231 | int load_uA) | ||
232 | { | ||
233 | return REGULATOR_MODE_NORMAL; | ||
234 | } | ||
235 | |||
236 | static struct regulator_ops wm8400_dcdc_ops = { | ||
237 | .is_enabled = wm8400_dcdc_is_enabled, | ||
238 | .enable = wm8400_dcdc_enable, | ||
239 | .disable = wm8400_dcdc_disable, | ||
240 | .get_voltage = wm8400_dcdc_get_voltage, | ||
241 | .set_voltage = wm8400_dcdc_set_voltage, | ||
242 | .get_mode = wm8400_dcdc_get_mode, | ||
243 | .set_mode = wm8400_dcdc_set_mode, | ||
244 | .get_optimum_mode = wm8400_dcdc_get_optimum_mode, | ||
245 | }; | ||
246 | |||
247 | static struct regulator_desc regulators[] = { | ||
248 | { | ||
249 | .name = "LDO1", | ||
250 | .id = WM8400_LDO1, | ||
251 | .ops = &wm8400_ldo_ops, | ||
252 | .type = REGULATOR_VOLTAGE, | ||
253 | .owner = THIS_MODULE, | ||
254 | }, | ||
255 | { | ||
256 | .name = "LDO2", | ||
257 | .id = WM8400_LDO2, | ||
258 | .ops = &wm8400_ldo_ops, | ||
259 | .type = REGULATOR_VOLTAGE, | ||
260 | .owner = THIS_MODULE, | ||
261 | }, | ||
262 | { | ||
263 | .name = "LDO3", | ||
264 | .id = WM8400_LDO3, | ||
265 | .ops = &wm8400_ldo_ops, | ||
266 | .type = REGULATOR_VOLTAGE, | ||
267 | .owner = THIS_MODULE, | ||
268 | }, | ||
269 | { | ||
270 | .name = "LDO4", | ||
271 | .id = WM8400_LDO4, | ||
272 | .ops = &wm8400_ldo_ops, | ||
273 | .type = REGULATOR_VOLTAGE, | ||
274 | .owner = THIS_MODULE, | ||
275 | }, | ||
276 | { | ||
277 | .name = "DCDC1", | ||
278 | .id = WM8400_DCDC1, | ||
279 | .ops = &wm8400_dcdc_ops, | ||
280 | .type = REGULATOR_VOLTAGE, | ||
281 | .owner = THIS_MODULE, | ||
282 | }, | ||
283 | { | ||
284 | .name = "DCDC2", | ||
285 | .id = WM8400_DCDC2, | ||
286 | .ops = &wm8400_dcdc_ops, | ||
287 | .type = REGULATOR_VOLTAGE, | ||
288 | .owner = THIS_MODULE, | ||
289 | }, | ||
290 | }; | ||
291 | |||
292 | static int __init wm8400_regulator_probe(struct platform_device *pdev) | ||
293 | { | ||
294 | struct regulator_dev *rdev; | ||
295 | |||
296 | rdev = regulator_register(®ulators[pdev->id], &pdev->dev, | ||
297 | pdev->dev.driver_data); | ||
298 | |||
299 | if (IS_ERR(rdev)) | ||
300 | return PTR_ERR(rdev); | ||
301 | |||
302 | return 0; | ||
303 | } | ||
304 | |||
305 | static int __devexit wm8400_regulator_remove(struct platform_device *pdev) | ||
306 | { | ||
307 | struct regulator_dev *rdev = platform_get_drvdata(pdev); | ||
308 | |||
309 | regulator_unregister(rdev); | ||
310 | |||
311 | return 0; | ||
312 | } | ||
313 | |||
314 | static struct platform_driver wm8400_regulator_driver = { | ||
315 | .driver = { | ||
316 | .name = "wm8400-regulator", | ||
317 | }, | ||
318 | .probe = wm8400_regulator_probe, | ||
319 | .remove = __devexit_p(wm8400_regulator_remove), | ||
320 | }; | ||
321 | |||
322 | /** | ||
323 | * wm8400_register_regulator - enable software control of a WM8400 regulator | ||
324 | * | ||
325 | * This function enables software control of a WM8400 regulator via | ||
326 | * the regulator API. It is intended to be called from the | ||
327 | * platform_init() callback of the WM8400 MFD driver. | ||
328 | * | ||
329 | * @param dev The WM8400 device to operate on. | ||
330 | * @param reg The regulator to control. | ||
331 | * @param initdata Regulator initdata for the regulator. | ||
332 | */ | ||
333 | int wm8400_register_regulator(struct device *dev, int reg, | ||
334 | struct regulator_init_data *initdata) | ||
335 | { | ||
336 | struct wm8400 *wm8400 = dev->driver_data; | ||
337 | |||
338 | if (wm8400->regulators[reg].name) | ||
339 | return -EBUSY; | ||
340 | |||
341 | initdata->driver_data = wm8400; | ||
342 | |||
343 | wm8400->regulators[reg].name = "wm8400-regulator"; | ||
344 | wm8400->regulators[reg].id = reg; | ||
345 | wm8400->regulators[reg].dev.parent = dev; | ||
346 | wm8400->regulators[reg].dev.driver_data = wm8400; | ||
347 | wm8400->regulators[reg].dev.platform_data = initdata; | ||
348 | |||
349 | return platform_device_register(&wm8400->regulators[reg]); | ||
350 | } | ||
351 | EXPORT_SYMBOL_GPL(wm8400_register_regulator); | ||
352 | |||
353 | static int __init wm8400_regulator_init(void) | ||
354 | { | ||
355 | return platform_driver_register(&wm8400_regulator_driver); | ||
356 | } | ||
357 | module_init(wm8400_regulator_init); | ||
358 | |||
359 | static void __exit wm8400_regulator_exit(void) | ||
360 | { | ||
361 | platform_driver_unregister(&wm8400_regulator_driver); | ||
362 | } | ||
363 | module_exit(wm8400_regulator_exit); | ||
364 | |||
365 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); | ||
366 | MODULE_DESCRIPTION("WM8400 regulator driver"); | ||
367 | MODULE_LICENSE("GPL"); | ||
368 | MODULE_ALIAS("platform:wm8400-regulator"); | ||
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c index b23af0c2a869..963ad0b6a4e9 100644 --- a/drivers/rtc/rtc-cmos.c +++ b/drivers/rtc/rtc-cmos.c | |||
@@ -913,6 +913,92 @@ static inline int cmos_poweroff(struct device *dev) | |||
913 | * predate even PNPBIOS should set up platform_bus devices. | 913 | * predate even PNPBIOS should set up platform_bus devices. |
914 | */ | 914 | */ |
915 | 915 | ||
916 | #ifdef CONFIG_ACPI | ||
917 | |||
918 | #include <linux/acpi.h> | ||
919 | |||
920 | #ifdef CONFIG_PM | ||
921 | static u32 rtc_handler(void *context) | ||
922 | { | ||
923 | acpi_clear_event(ACPI_EVENT_RTC); | ||
924 | acpi_disable_event(ACPI_EVENT_RTC, 0); | ||
925 | return ACPI_INTERRUPT_HANDLED; | ||
926 | } | ||
927 | |||
928 | static inline void rtc_wake_setup(void) | ||
929 | { | ||
930 | acpi_install_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler, NULL); | ||
931 | /* | ||
932 | * After the RTC handler is installed, the Fixed_RTC event should | ||
933 | * be disabled. Only when the RTC alarm is set will it be enabled. | ||
934 | */ | ||
935 | acpi_clear_event(ACPI_EVENT_RTC); | ||
936 | acpi_disable_event(ACPI_EVENT_RTC, 0); | ||
937 | } | ||
938 | |||
939 | static void rtc_wake_on(struct device *dev) | ||
940 | { | ||
941 | acpi_clear_event(ACPI_EVENT_RTC); | ||
942 | acpi_enable_event(ACPI_EVENT_RTC, 0); | ||
943 | } | ||
944 | |||
945 | static void rtc_wake_off(struct device *dev) | ||
946 | { | ||
947 | acpi_disable_event(ACPI_EVENT_RTC, 0); | ||
948 | } | ||
949 | #else | ||
950 | #define rtc_wake_setup() do{}while(0) | ||
951 | #define rtc_wake_on NULL | ||
952 | #define rtc_wake_off NULL | ||
953 | #endif | ||
954 | |||
955 | /* Every ACPI platform has a mc146818 compatible "cmos rtc". Here we find | ||
956 | * its device node and pass extra config data. This helps its driver use | ||
957 | * capabilities that the now-obsolete mc146818 didn't have, and informs it | ||
958 | * that this board's RTC is wakeup-capable (per ACPI spec). | ||
959 | */ | ||
960 | static struct cmos_rtc_board_info acpi_rtc_info; | ||
961 | |||
962 | static void __devinit | ||
963 | cmos_wake_setup(struct device *dev) | ||
964 | { | ||
965 | if (acpi_disabled) | ||
966 | return; | ||
967 | |||
968 | rtc_wake_setup(); | ||
969 | acpi_rtc_info.wake_on = rtc_wake_on; | ||
970 | acpi_rtc_info.wake_off = rtc_wake_off; | ||
971 | |||
972 | /* workaround bug in some ACPI tables */ | ||
973 | if (acpi_gbl_FADT.month_alarm && !acpi_gbl_FADT.day_alarm) { | ||
974 | dev_dbg(dev, "bogus FADT month_alarm (%d)\n", | ||
975 | acpi_gbl_FADT.month_alarm); | ||
976 | acpi_gbl_FADT.month_alarm = 0; | ||
977 | } | ||
978 | |||
979 | acpi_rtc_info.rtc_day_alarm = acpi_gbl_FADT.day_alarm; | ||
980 | acpi_rtc_info.rtc_mon_alarm = acpi_gbl_FADT.month_alarm; | ||
981 | acpi_rtc_info.rtc_century = acpi_gbl_FADT.century; | ||
982 | |||
983 | /* NOTE: S4_RTC_WAKE is NOT currently useful to Linux */ | ||
984 | if (acpi_gbl_FADT.flags & ACPI_FADT_S4_RTC_WAKE) | ||
985 | dev_info(dev, "RTC can wake from S4\n"); | ||
986 | |||
987 | dev->platform_data = &acpi_rtc_info; | ||
988 | |||
989 | /* RTC always wakes from S1/S2/S3, and often S4/STD */ | ||
990 | device_init_wakeup(dev, 1); | ||
991 | } | ||
992 | |||
993 | #else | ||
994 | |||
995 | static void __devinit | ||
996 | cmos_wake_setup(struct device *dev) | ||
997 | { | ||
998 | } | ||
999 | |||
1000 | #endif | ||
1001 | |||
916 | #ifdef CONFIG_PNP | 1002 | #ifdef CONFIG_PNP |
917 | 1003 | ||
918 | #include <linux/pnp.h> | 1004 | #include <linux/pnp.h> |
@@ -920,6 +1006,8 @@ static inline int cmos_poweroff(struct device *dev) | |||
920 | static int __devinit | 1006 | static int __devinit |
921 | cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id) | 1007 | cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id) |
922 | { | 1008 | { |
1009 | cmos_wake_setup(&pnp->dev); | ||
1010 | |||
923 | if (pnp_port_start(pnp,0) == 0x70 && !pnp_irq_valid(pnp,0)) | 1011 | if (pnp_port_start(pnp,0) == 0x70 && !pnp_irq_valid(pnp,0)) |
924 | /* Some machines contain a PNP entry for the RTC, but | 1012 | /* Some machines contain a PNP entry for the RTC, but |
925 | * don't define the IRQ. It should always be safe to | 1013 | * don't define the IRQ. It should always be safe to |
@@ -997,6 +1085,7 @@ static struct pnp_driver cmos_pnp_driver = { | |||
997 | 1085 | ||
998 | static int __init cmos_platform_probe(struct platform_device *pdev) | 1086 | static int __init cmos_platform_probe(struct platform_device *pdev) |
999 | { | 1087 | { |
1088 | cmos_wake_setup(&pdev->dev); | ||
1000 | return cmos_do_probe(&pdev->dev, | 1089 | return cmos_do_probe(&pdev->dev, |
1001 | platform_get_resource(pdev, IORESOURCE_IO, 0), | 1090 | platform_get_resource(pdev, IORESOURCE_IO, 0), |
1002 | platform_get_irq(pdev, 0)); | 1091 | platform_get_irq(pdev, 0)); |
@@ -1031,29 +1120,32 @@ static struct platform_driver cmos_platform_driver = { | |||
1031 | 1120 | ||
1032 | static int __init cmos_init(void) | 1121 | static int __init cmos_init(void) |
1033 | { | 1122 | { |
1123 | int retval = 0; | ||
1124 | |||
1034 | #ifdef CONFIG_PNP | 1125 | #ifdef CONFIG_PNP |
1035 | if (pnp_platform_devices) | 1126 | pnp_register_driver(&cmos_pnp_driver); |
1036 | return pnp_register_driver(&cmos_pnp_driver); | 1127 | #endif |
1037 | else | 1128 | |
1038 | return platform_driver_probe(&cmos_platform_driver, | 1129 | if (!cmos_rtc.dev) |
1039 | cmos_platform_probe); | 1130 | retval = platform_driver_probe(&cmos_platform_driver, |
1040 | #else | 1131 | cmos_platform_probe); |
1041 | return platform_driver_probe(&cmos_platform_driver, | 1132 | |
1042 | cmos_platform_probe); | 1133 | if (retval == 0) |
1043 | #endif /* CONFIG_PNP */ | 1134 | return 0; |
1135 | |||
1136 | #ifdef CONFIG_PNP | ||
1137 | pnp_unregister_driver(&cmos_pnp_driver); | ||
1138 | #endif | ||
1139 | return retval; | ||
1044 | } | 1140 | } |
1045 | module_init(cmos_init); | 1141 | module_init(cmos_init); |
1046 | 1142 | ||
1047 | static void __exit cmos_exit(void) | 1143 | static void __exit cmos_exit(void) |
1048 | { | 1144 | { |
1049 | #ifdef CONFIG_PNP | 1145 | #ifdef CONFIG_PNP |
1050 | if (pnp_platform_devices) | 1146 | pnp_unregister_driver(&cmos_pnp_driver); |
1051 | pnp_unregister_driver(&cmos_pnp_driver); | 1147 | #endif |
1052 | else | ||
1053 | platform_driver_unregister(&cmos_platform_driver); | ||
1054 | #else | ||
1055 | platform_driver_unregister(&cmos_platform_driver); | 1148 | platform_driver_unregister(&cmos_platform_driver); |
1056 | #endif /* CONFIG_PNP */ | ||
1057 | } | 1149 | } |
1058 | module_exit(cmos_exit); | 1150 | module_exit(cmos_exit); |
1059 | 1151 | ||
diff --git a/drivers/s390/net/claw.c b/drivers/s390/net/claw.c index 8f83fc994f50..f5e618562c5f 100644 --- a/drivers/s390/net/claw.c +++ b/drivers/s390/net/claw.c | |||
@@ -2913,7 +2913,7 @@ claw_new_device(struct ccwgroup_device *cgdev) | |||
2913 | if (ret != 0) { | 2913 | if (ret != 0) { |
2914 | printk(KERN_WARNING | 2914 | printk(KERN_WARNING |
2915 | "claw: ccw_device_set_online %s WRITE failed " | 2915 | "claw: ccw_device_set_online %s WRITE failed " |
2916 | "with ret = %d\n", dev_name(&cgdev->cdev[WRITE]->dev) | 2916 | "with ret = %d\n", dev_name(&cgdev->cdev[WRITE]->dev), |
2917 | ret); | 2917 | ret); |
2918 | goto out; | 2918 | goto out; |
2919 | } | 2919 | } |
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig index d3b211af4e1c..403ecad48d4b 100644 --- a/drivers/scsi/Kconfig +++ b/drivers/scsi/Kconfig | |||
@@ -1640,6 +1640,7 @@ config ATARI_SCSI | |||
1640 | tristate "Atari native SCSI support" | 1640 | tristate "Atari native SCSI support" |
1641 | depends on ATARI && SCSI | 1641 | depends on ATARI && SCSI |
1642 | select SCSI_SPI_ATTRS | 1642 | select SCSI_SPI_ATTRS |
1643 | select NVRAM | ||
1643 | ---help--- | 1644 | ---help--- |
1644 | If you have an Atari with built-in NCR5380 SCSI controller (TT, | 1645 | If you have an Atari with built-in NCR5380 SCSI controller (TT, |
1645 | Falcon, ...) say Y to get it supported. Of course also, if you have | 1646 | Falcon, ...) say Y to get it supported. Of course also, if you have |
@@ -1670,14 +1671,6 @@ config ATARI_SCSI_RESET_BOOT | |||
1670 | boot process fractionally longer but may assist recovery from errors | 1671 | boot process fractionally longer but may assist recovery from errors |
1671 | that leave the devices with SCSI operations partway completed. | 1672 | that leave the devices with SCSI operations partway completed. |
1672 | 1673 | ||
1673 | config TT_DMA_EMUL | ||
1674 | bool "Hades SCSI DMA emulator" | ||
1675 | depends on ATARI_SCSI && HADES | ||
1676 | help | ||
1677 | This option enables code which emulates the TT SCSI DMA chip on the | ||
1678 | Hades. This increases the SCSI transfer rates at least ten times | ||
1679 | compared to PIO transfers. | ||
1680 | |||
1681 | config MAC_SCSI | 1674 | config MAC_SCSI |
1682 | bool "Macintosh NCR5380 SCSI" | 1675 | bool "Macintosh NCR5380 SCSI" |
1683 | depends on MAC && SCSI=y | 1676 | depends on MAC && SCSI=y |
diff --git a/drivers/scsi/atari_dma_emul.c b/drivers/scsi/atari_dma_emul.c deleted file mode 100644 index cdc710ea00fa..000000000000 --- a/drivers/scsi/atari_dma_emul.c +++ /dev/null | |||
@@ -1,468 +0,0 @@ | |||
1 | /* | ||
2 | * atari_dma_emul.c -- TT SCSI DMA emulator for the Hades. | ||
3 | * | ||
4 | * Copyright 1997 Wout Klaren <W.Klaren@inter.nl.net> | ||
5 | * | ||
6 | * This file is subject to the terms and conditions of the GNU General Public | ||
7 | * License. See the file COPYING in the main directory of this archive | ||
8 | * for more details. | ||
9 | * | ||
10 | * This code was written using the Hades TOS source code as a | ||
11 | * reference. This source code can be found on the home page | ||
12 | * of Medusa Computer Systems. | ||
13 | * | ||
14 | * Version 0.1, 1997-09-24. | ||
15 | * | ||
16 | * This code should be considered experimental. It has only been | ||
17 | * tested on a Hades with a 68060. It might not work on a Hades | ||
18 | * with a 68040. Make backups of your hard drives before using | ||
19 | * this code. | ||
20 | */ | ||
21 | |||
22 | #include <linux/compiler.h> | ||
23 | #include <asm/thread_info.h> | ||
24 | #include <asm/uaccess.h> | ||
25 | |||
26 | #define hades_dma_ctrl (*(unsigned char *) 0xffff8717) | ||
27 | #define hades_psdm_reg (*(unsigned char *) 0xffff8741) | ||
28 | |||
29 | #define TRANSFER_SIZE 16 | ||
30 | |||
31 | struct m68040_frame { | ||
32 | unsigned long effaddr; /* effective address */ | ||
33 | unsigned short ssw; /* special status word */ | ||
34 | unsigned short wb3s; /* write back 3 status */ | ||
35 | unsigned short wb2s; /* write back 2 status */ | ||
36 | unsigned short wb1s; /* write back 1 status */ | ||
37 | unsigned long faddr; /* fault address */ | ||
38 | unsigned long wb3a; /* write back 3 address */ | ||
39 | unsigned long wb3d; /* write back 3 data */ | ||
40 | unsigned long wb2a; /* write back 2 address */ | ||
41 | unsigned long wb2d; /* write back 2 data */ | ||
42 | unsigned long wb1a; /* write back 1 address */ | ||
43 | unsigned long wb1dpd0; /* write back 1 data/push data 0*/ | ||
44 | unsigned long pd1; /* push data 1*/ | ||
45 | unsigned long pd2; /* push data 2*/ | ||
46 | unsigned long pd3; /* push data 3*/ | ||
47 | }; | ||
48 | |||
49 | static void writeback (unsigned short wbs, unsigned long wba, | ||
50 | unsigned long wbd, void *old_buserr) | ||
51 | { | ||
52 | mm_segment_t fs = get_fs(); | ||
53 | static void *save_buserr; | ||
54 | |||
55 | __asm__ __volatile__ ("movec.l %%vbr,%%a0\n\t" | ||
56 | "move.l %0,8(%%a0)\n\t" | ||
57 | : | ||
58 | : "r" (&&bus_error) | ||
59 | : "a0" ); | ||
60 | |||
61 | save_buserr = old_buserr; | ||
62 | |||
63 | set_fs (MAKE_MM_SEG(wbs & WBTM_040)); | ||
64 | |||
65 | switch (wbs & WBSIZ_040) { | ||
66 | case BA_SIZE_BYTE: | ||
67 | put_user (wbd & 0xff, (char *)wba); | ||
68 | break; | ||
69 | case BA_SIZE_WORD: | ||
70 | put_user (wbd & 0xffff, (short *)wba); | ||
71 | break; | ||
72 | case BA_SIZE_LONG: | ||
73 | put_user (wbd, (int *)wba); | ||
74 | break; | ||
75 | } | ||
76 | |||
77 | set_fs (fs); | ||
78 | return; | ||
79 | |||
80 | bus_error: | ||
81 | __asm__ __volatile__ ("cmp.l %0,2(%%sp)\n\t" | ||
82 | "bcs.s .jump_old\n\t" | ||
83 | "cmp.l %1,2(%%sp)\n\t" | ||
84 | "bls.s .restore_old\n" | ||
85 | ".jump_old:\n\t" | ||
86 | "move.l %2,-(%%sp)\n\t" | ||
87 | "rts\n" | ||
88 | ".restore_old:\n\t" | ||
89 | "move.l %%a0,-(%%sp)\n\t" | ||
90 | "movec.l %%vbr,%%a0\n\t" | ||
91 | "move.l %2,8(%%a0)\n\t" | ||
92 | "move.l (%%sp)+,%%a0\n\t" | ||
93 | "rte\n\t" | ||
94 | : | ||
95 | : "i" (writeback), "i" (&&bus_error), | ||
96 | "m" (save_buserr) ); | ||
97 | } | ||
98 | |||
99 | /* | ||
100 | * static inline void set_restdata_reg(unsigned char *cur_addr) | ||
101 | * | ||
102 | * Set the rest data register if necessary. | ||
103 | */ | ||
104 | |||
105 | static inline void set_restdata_reg(unsigned char *cur_addr) | ||
106 | { | ||
107 | if (((long) cur_addr & ~3) != 0) | ||
108 | tt_scsi_dma.dma_restdata = | ||
109 | *((unsigned long *) ((long) cur_addr & ~3)); | ||
110 | } | ||
111 | |||
112 | /* | ||
113 | * void hades_dma_emulator(int irq, void *dummy) | ||
114 | * | ||
115 | * This code emulates TT SCSI DMA on the Hades. | ||
116 | * | ||
117 | * Note the following: | ||
118 | * | ||
119 | * 1. When there is no byte available to read from the SCSI bus, or | ||
120 | * when a byte cannot yet bet written to the SCSI bus, a bus | ||
121 | * error occurs when reading or writing the pseudo DMA data | ||
122 | * register (hades_psdm_reg). We have to catch this bus error | ||
123 | * and try again to read or write the byte. If after several tries | ||
124 | * we still get a bus error, the interrupt handler is left. When | ||
125 | * the byte can be read or written, the interrupt handler is | ||
126 | * called again. | ||
127 | * | ||
128 | * 2. The SCSI interrupt must be disabled in this interrupt handler. | ||
129 | * | ||
130 | * 3. If we set the EOP signal, the SCSI controller still expects one | ||
131 | * byte to be read or written. Therefore the last byte is transferred | ||
132 | * separately, after setting the EOP signal. | ||
133 | * | ||
134 | * 4. When this function is left, the address pointer (start_addr) is | ||
135 | * converted to a physical address. Because it points one byte | ||
136 | * further than the last transferred byte, it can point outside the | ||
137 | * current page. If virt_to_phys() is called with this address we | ||
138 | * might get an access error. Therefore virt_to_phys() is called with | ||
139 | * start_addr - 1 if the count has reached zero. The result is | ||
140 | * increased with one. | ||
141 | */ | ||
142 | |||
143 | static irqreturn_t hades_dma_emulator(int irq, void *dummy) | ||
144 | { | ||
145 | unsigned long dma_base; | ||
146 | register unsigned long dma_cnt asm ("d3"); | ||
147 | static long save_buserr; | ||
148 | register unsigned long save_sp asm ("d4"); | ||
149 | register int tries asm ("d5"); | ||
150 | register unsigned char *start_addr asm ("a3"), *end_addr asm ("a4"); | ||
151 | register unsigned char *eff_addr; | ||
152 | register unsigned char *psdm_reg; | ||
153 | unsigned long rem; | ||
154 | |||
155 | atari_disable_irq(IRQ_TT_MFP_SCSI); | ||
156 | |||
157 | /* | ||
158 | * Read the dma address and count registers. | ||
159 | */ | ||
160 | |||
161 | dma_base = SCSI_DMA_READ_P(dma_addr); | ||
162 | dma_cnt = SCSI_DMA_READ_P(dma_cnt); | ||
163 | |||
164 | /* | ||
165 | * Check if DMA is still enabled. | ||
166 | */ | ||
167 | |||
168 | if ((tt_scsi_dma.dma_ctrl & 2) == 0) | ||
169 | { | ||
170 | atari_enable_irq(IRQ_TT_MFP_SCSI); | ||
171 | return IRQ_HANDLED; | ||
172 | } | ||
173 | |||
174 | if (dma_cnt == 0) | ||
175 | { | ||
176 | printk(KERN_NOTICE "DMA emulation: count is zero.\n"); | ||
177 | tt_scsi_dma.dma_ctrl &= 0xfd; /* DMA ready. */ | ||
178 | atari_enable_irq(IRQ_TT_MFP_SCSI); | ||
179 | return IRQ_HANDLED; | ||
180 | } | ||
181 | |||
182 | /* | ||
183 | * Install new bus error routine. | ||
184 | */ | ||
185 | |||
186 | __asm__ __volatile__ ("movec.l %%vbr,%%a0\n\t" | ||
187 | "move.l 8(%%a0),%0\n\t" | ||
188 | "move.l %1,8(%%a0)\n\t" | ||
189 | : "=&r" (save_buserr) | ||
190 | : "r" (&&scsi_bus_error) | ||
191 | : "a0" ); | ||
192 | |||
193 | hades_dma_ctrl &= 0xfc; /* Bus error and EOP off. */ | ||
194 | |||
195 | /* | ||
196 | * Save the stack pointer. | ||
197 | */ | ||
198 | |||
199 | __asm__ __volatile__ ("move.l %%sp,%0\n\t" | ||
200 | : "=&r" (save_sp) ); | ||
201 | |||
202 | tries = 100; /* Maximum number of bus errors. */ | ||
203 | start_addr = phys_to_virt(dma_base); | ||
204 | end_addr = start_addr + dma_cnt; | ||
205 | |||
206 | scsi_loop: | ||
207 | dma_cnt--; | ||
208 | rem = dma_cnt & (TRANSFER_SIZE - 1); | ||
209 | dma_cnt &= ~(TRANSFER_SIZE - 1); | ||
210 | psdm_reg = &hades_psdm_reg; | ||
211 | |||
212 | if (tt_scsi_dma.dma_ctrl & 1) /* Read or write? */ | ||
213 | { | ||
214 | /* | ||
215 | * SCSI write. Abort when count is zero. | ||
216 | */ | ||
217 | |||
218 | switch (rem) | ||
219 | { | ||
220 | case 0: | ||
221 | while (dma_cnt > 0) | ||
222 | { | ||
223 | dma_cnt -= TRANSFER_SIZE; | ||
224 | |||
225 | *psdm_reg = *start_addr++; | ||
226 | case 15: | ||
227 | *psdm_reg = *start_addr++; | ||
228 | case 14: | ||
229 | *psdm_reg = *start_addr++; | ||
230 | case 13: | ||
231 | *psdm_reg = *start_addr++; | ||
232 | case 12: | ||
233 | *psdm_reg = *start_addr++; | ||
234 | case 11: | ||
235 | *psdm_reg = *start_addr++; | ||
236 | case 10: | ||
237 | *psdm_reg = *start_addr++; | ||
238 | case 9: | ||
239 | *psdm_reg = *start_addr++; | ||
240 | case 8: | ||
241 | *psdm_reg = *start_addr++; | ||
242 | case 7: | ||
243 | *psdm_reg = *start_addr++; | ||
244 | case 6: | ||
245 | *psdm_reg = *start_addr++; | ||
246 | case 5: | ||
247 | *psdm_reg = *start_addr++; | ||
248 | case 4: | ||
249 | *psdm_reg = *start_addr++; | ||
250 | case 3: | ||
251 | *psdm_reg = *start_addr++; | ||
252 | case 2: | ||
253 | *psdm_reg = *start_addr++; | ||
254 | case 1: | ||
255 | *psdm_reg = *start_addr++; | ||
256 | } | ||
257 | } | ||
258 | |||
259 | hades_dma_ctrl |= 1; /* Set EOP. */ | ||
260 | udelay(10); | ||
261 | *psdm_reg = *start_addr++; /* Dummy byte. */ | ||
262 | tt_scsi_dma.dma_ctrl &= 0xfd; /* DMA ready. */ | ||
263 | } | ||
264 | else | ||
265 | { | ||
266 | /* | ||
267 | * SCSI read. Abort when count is zero. | ||
268 | */ | ||
269 | |||
270 | switch (rem) | ||
271 | { | ||
272 | case 0: | ||
273 | while (dma_cnt > 0) | ||
274 | { | ||
275 | dma_cnt -= TRANSFER_SIZE; | ||
276 | |||
277 | *start_addr++ = *psdm_reg; | ||
278 | case 15: | ||
279 | *start_addr++ = *psdm_reg; | ||
280 | case 14: | ||
281 | *start_addr++ = *psdm_reg; | ||
282 | case 13: | ||
283 | *start_addr++ = *psdm_reg; | ||
284 | case 12: | ||
285 | *start_addr++ = *psdm_reg; | ||
286 | case 11: | ||
287 | *start_addr++ = *psdm_reg; | ||
288 | case 10: | ||
289 | *start_addr++ = *psdm_reg; | ||
290 | case 9: | ||
291 | *start_addr++ = *psdm_reg; | ||
292 | case 8: | ||
293 | *start_addr++ = *psdm_reg; | ||
294 | case 7: | ||
295 | *start_addr++ = *psdm_reg; | ||
296 | case 6: | ||
297 | *start_addr++ = *psdm_reg; | ||
298 | case 5: | ||
299 | *start_addr++ = *psdm_reg; | ||
300 | case 4: | ||
301 | *start_addr++ = *psdm_reg; | ||
302 | case 3: | ||
303 | *start_addr++ = *psdm_reg; | ||
304 | case 2: | ||
305 | *start_addr++ = *psdm_reg; | ||
306 | case 1: | ||
307 | *start_addr++ = *psdm_reg; | ||
308 | } | ||
309 | } | ||
310 | |||
311 | hades_dma_ctrl |= 1; /* Set EOP. */ | ||
312 | udelay(10); | ||
313 | *start_addr++ = *psdm_reg; | ||
314 | tt_scsi_dma.dma_ctrl &= 0xfd; /* DMA ready. */ | ||
315 | |||
316 | set_restdata_reg(start_addr); | ||
317 | } | ||
318 | |||
319 | if (start_addr != end_addr) | ||
320 | printk(KERN_CRIT "DMA emulation: FATAL: Count is not zero at end of transfer.\n"); | ||
321 | |||
322 | dma_cnt = end_addr - start_addr; | ||
323 | |||
324 | scsi_end: | ||
325 | dma_base = (dma_cnt == 0) ? virt_to_phys(start_addr - 1) + 1 : | ||
326 | virt_to_phys(start_addr); | ||
327 | |||
328 | SCSI_DMA_WRITE_P(dma_addr, dma_base); | ||
329 | SCSI_DMA_WRITE_P(dma_cnt, dma_cnt); | ||
330 | |||
331 | /* | ||
332 | * Restore old bus error routine. | ||
333 | */ | ||
334 | |||
335 | __asm__ __volatile__ ("movec.l %%vbr,%%a0\n\t" | ||
336 | "move.l %0,8(%%a0)\n\t" | ||
337 | : | ||
338 | : "r" (save_buserr) | ||
339 | : "a0" ); | ||
340 | |||
341 | atari_enable_irq(IRQ_TT_MFP_SCSI); | ||
342 | |||
343 | return IRQ_HANDLED; | ||
344 | |||
345 | scsi_bus_error: | ||
346 | /* | ||
347 | * First check if the bus error is caused by our code. | ||
348 | * If not, call the original handler. | ||
349 | */ | ||
350 | |||
351 | __asm__ __volatile__ ("cmp.l %0,2(%%sp)\n\t" | ||
352 | "bcs.s .old_vector\n\t" | ||
353 | "cmp.l %1,2(%%sp)\n\t" | ||
354 | "bls.s .scsi_buserr\n" | ||
355 | ".old_vector:\n\t" | ||
356 | "move.l %2,-(%%sp)\n\t" | ||
357 | "rts\n" | ||
358 | ".scsi_buserr:\n\t" | ||
359 | : | ||
360 | : "i" (&&scsi_loop), "i" (&&scsi_end), | ||
361 | "m" (save_buserr) ); | ||
362 | |||
363 | if (CPU_IS_060) | ||
364 | { | ||
365 | /* | ||
366 | * Get effective address and restore the stack. | ||
367 | */ | ||
368 | |||
369 | __asm__ __volatile__ ("move.l 8(%%sp),%0\n\t" | ||
370 | "move.l %1,%%sp\n\t" | ||
371 | : "=a&" (eff_addr) | ||
372 | : "r" (save_sp) ); | ||
373 | } | ||
374 | else | ||
375 | { | ||
376 | register struct m68040_frame *frame; | ||
377 | |||
378 | __asm__ __volatile__ ("lea 8(%%sp),%0\n\t" | ||
379 | : "=a&" (frame) ); | ||
380 | |||
381 | if (tt_scsi_dma.dma_ctrl & 1) | ||
382 | { | ||
383 | /* | ||
384 | * Bus error while writing. | ||
385 | */ | ||
386 | |||
387 | if (frame->wb3s & WBV_040) | ||
388 | { | ||
389 | if (frame->wb3a == (long) &hades_psdm_reg) | ||
390 | start_addr--; | ||
391 | else | ||
392 | writeback(frame->wb3s, frame->wb3a, | ||
393 | frame->wb3d, &&scsi_bus_error); | ||
394 | } | ||
395 | |||
396 | if (frame->wb2s & WBV_040) | ||
397 | { | ||
398 | if (frame->wb2a == (long) &hades_psdm_reg) | ||
399 | start_addr--; | ||
400 | else | ||
401 | writeback(frame->wb2s, frame->wb2a, | ||
402 | frame->wb2d, &&scsi_bus_error); | ||
403 | } | ||
404 | |||
405 | if (frame->wb1s & WBV_040) | ||
406 | { | ||
407 | if (frame->wb1a == (long) &hades_psdm_reg) | ||
408 | start_addr--; | ||
409 | } | ||
410 | } | ||
411 | else | ||
412 | { | ||
413 | /* | ||
414 | * Bus error while reading. | ||
415 | */ | ||
416 | |||
417 | if (frame->wb3s & WBV_040) | ||
418 | writeback(frame->wb3s, frame->wb3a, | ||
419 | frame->wb3d, &&scsi_bus_error); | ||
420 | } | ||
421 | |||
422 | eff_addr = (unsigned char *) frame->faddr; | ||
423 | |||
424 | __asm__ __volatile__ ("move.l %0,%%sp\n\t" | ||
425 | : | ||
426 | : "r" (save_sp) ); | ||
427 | } | ||
428 | |||
429 | dma_cnt = end_addr - start_addr; | ||
430 | |||
431 | if (eff_addr == &hades_psdm_reg) | ||
432 | { | ||
433 | /* | ||
434 | * Bus error occurred while reading the pseudo | ||
435 | * DMA register. Time out. | ||
436 | */ | ||
437 | |||
438 | tries--; | ||
439 | |||
440 | if (tries <= 0) | ||
441 | { | ||
442 | if ((tt_scsi_dma.dma_ctrl & 1) == 0) /* Read or write? */ | ||
443 | set_restdata_reg(start_addr); | ||
444 | |||
445 | if (dma_cnt <= 1) | ||
446 | printk(KERN_CRIT "DMA emulation: Fatal " | ||
447 | "error while %s the last byte.\n", | ||
448 | (tt_scsi_dma.dma_ctrl & 1) | ||
449 | ? "writing" : "reading"); | ||
450 | |||
451 | goto scsi_end; | ||
452 | } | ||
453 | else | ||
454 | goto scsi_loop; | ||
455 | } | ||
456 | else | ||
457 | { | ||
458 | /* | ||
459 | * Bus error during pseudo DMA transfer. | ||
460 | * Terminate the DMA transfer. | ||
461 | */ | ||
462 | |||
463 | hades_dma_ctrl |= 3; /* Set EOP and bus error. */ | ||
464 | if ((tt_scsi_dma.dma_ctrl & 1) == 0) /* Read or write? */ | ||
465 | set_restdata_reg(start_addr); | ||
466 | goto scsi_end; | ||
467 | } | ||
468 | } | ||
diff --git a/drivers/scsi/atari_scsi.c b/drivers/scsi/atari_scsi.c index f5732d8f67fe..21fe07f9df87 100644 --- a/drivers/scsi/atari_scsi.c +++ b/drivers/scsi/atari_scsi.c | |||
@@ -249,10 +249,6 @@ static int setup_hostid = -1; | |||
249 | module_param(setup_hostid, int, 0); | 249 | module_param(setup_hostid, int, 0); |
250 | 250 | ||
251 | 251 | ||
252 | #if defined(CONFIG_TT_DMA_EMUL) | ||
253 | #include "atari_dma_emul.c" | ||
254 | #endif | ||
255 | |||
256 | #if defined(REAL_DMA) | 252 | #if defined(REAL_DMA) |
257 | 253 | ||
258 | static int scsi_dma_is_ignored_buserr(unsigned char dma_stat) | 254 | static int scsi_dma_is_ignored_buserr(unsigned char dma_stat) |
@@ -695,21 +691,8 @@ int atari_scsi_detect(struct scsi_host_template *host) | |||
695 | #ifdef REAL_DMA | 691 | #ifdef REAL_DMA |
696 | tt_scsi_dma.dma_ctrl = 0; | 692 | tt_scsi_dma.dma_ctrl = 0; |
697 | atari_dma_residual = 0; | 693 | atari_dma_residual = 0; |
698 | #ifdef CONFIG_TT_DMA_EMUL | 694 | |
699 | if (MACH_IS_HADES) { | 695 | if (MACH_IS_MEDUSA) { |
700 | if (request_irq(IRQ_AUTO_2, hades_dma_emulator, | ||
701 | IRQ_TYPE_PRIO, "Hades DMA emulator", | ||
702 | hades_dma_emulator)) { | ||
703 | printk(KERN_ERR "atari_scsi_detect: cannot allocate irq %d, aborting (MACH_IS_HADES)",IRQ_AUTO_2); | ||
704 | free_irq(IRQ_TT_MFP_SCSI, instance); | ||
705 | scsi_unregister(atari_scsi_host); | ||
706 | atari_stram_free(atari_dma_buffer); | ||
707 | atari_dma_buffer = 0; | ||
708 | return 0; | ||
709 | } | ||
710 | } | ||
711 | #endif | ||
712 | if (MACH_IS_MEDUSA || MACH_IS_HADES) { | ||
713 | /* While the read overruns (described by Drew Eckhardt in | 696 | /* While the read overruns (described by Drew Eckhardt in |
714 | * NCR5380.c) never happened on TTs, they do in fact on the Medusa | 697 | * NCR5380.c) never happened on TTs, they do in fact on the Medusa |
715 | * (This was the cause why SCSI didn't work right for so long | 698 | * (This was the cause why SCSI didn't work right for so long |
@@ -1007,11 +990,7 @@ static unsigned long atari_dma_xfer_len(unsigned long wanted_len, | |||
1007 | Scsi_Cmnd *cmd, int write_flag) | 990 | Scsi_Cmnd *cmd, int write_flag) |
1008 | { | 991 | { |
1009 | unsigned long possible_len, limit; | 992 | unsigned long possible_len, limit; |
1010 | #ifndef CONFIG_TT_DMA_EMUL | 993 | |
1011 | if (MACH_IS_HADES) | ||
1012 | /* Hades has no SCSI DMA at all :-( Always force use of PIO */ | ||
1013 | return 0; | ||
1014 | #endif | ||
1015 | if (IS_A_TT()) | 994 | if (IS_A_TT()) |
1016 | /* TT SCSI DMA can transfer arbitrary #bytes */ | 995 | /* TT SCSI DMA can transfer arbitrary #bytes */ |
1017 | return wanted_len; | 996 | return wanted_len; |
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c index d4104a3bbe87..d3ca7d32abe0 100644 --- a/drivers/serial/8250.c +++ b/drivers/serial/8250.c | |||
@@ -2969,6 +2969,9 @@ static int __init serial8250_init(void) | |||
2969 | "%d ports, IRQ sharing %sabled\n", nr_uarts, | 2969 | "%d ports, IRQ sharing %sabled\n", nr_uarts, |
2970 | share_irqs ? "en" : "dis"); | 2970 | share_irqs ? "en" : "dis"); |
2971 | 2971 | ||
2972 | for (i = 0; i < NR_IRQS; i++) | ||
2973 | spin_lock_init(&irq_lists[i].lock); | ||
2974 | |||
2972 | #ifdef CONFIG_SPARC | 2975 | #ifdef CONFIG_SPARC |
2973 | ret = sunserial_register_minors(&serial8250_reg, UART_NR); | 2976 | ret = sunserial_register_minors(&serial8250_reg, UART_NR); |
2974 | #else | 2977 | #else |
diff --git a/drivers/video/console/fbcon.c b/drivers/video/console/fbcon.c index 9cbff84b787d..da91bb16da8a 100644 --- a/drivers/video/console/fbcon.c +++ b/drivers/video/console/fbcon.c | |||
@@ -1855,8 +1855,6 @@ static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir, | |||
1855 | struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; | 1855 | struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; |
1856 | struct display *p = &fb_display[vc->vc_num]; | 1856 | struct display *p = &fb_display[vc->vc_num]; |
1857 | int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK; | 1857 | int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK; |
1858 | unsigned short saved_ec; | ||
1859 | int ret; | ||
1860 | 1858 | ||
1861 | if (fbcon_is_inactive(vc, info)) | 1859 | if (fbcon_is_inactive(vc, info)) |
1862 | return -EINVAL; | 1860 | return -EINVAL; |
@@ -1869,11 +1867,6 @@ static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir, | |||
1869 | * whole screen (prevents flicker). | 1867 | * whole screen (prevents flicker). |
1870 | */ | 1868 | */ |
1871 | 1869 | ||
1872 | saved_ec = vc->vc_video_erase_char; | ||
1873 | vc->vc_video_erase_char = vc->vc_scrl_erase_char; | ||
1874 | |||
1875 | ret = 0; | ||
1876 | |||
1877 | switch (dir) { | 1870 | switch (dir) { |
1878 | case SM_UP: | 1871 | case SM_UP: |
1879 | if (count > vc->vc_rows) /* Maximum realistic size */ | 1872 | if (count > vc->vc_rows) /* Maximum realistic size */ |
@@ -1890,9 +1883,9 @@ static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir, | |||
1890 | scr_memsetw((unsigned short *) (vc->vc_origin + | 1883 | scr_memsetw((unsigned short *) (vc->vc_origin + |
1891 | vc->vc_size_row * | 1884 | vc->vc_size_row * |
1892 | (b - count)), | 1885 | (b - count)), |
1893 | vc->vc_scrl_erase_char, | 1886 | vc->vc_video_erase_char, |
1894 | vc->vc_size_row * count); | 1887 | vc->vc_size_row * count); |
1895 | ret = 1; | 1888 | return 1; |
1896 | break; | 1889 | break; |
1897 | 1890 | ||
1898 | case SCROLL_WRAP_MOVE: | 1891 | case SCROLL_WRAP_MOVE: |
@@ -1962,10 +1955,9 @@ static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir, | |||
1962 | scr_memsetw((unsigned short *) (vc->vc_origin + | 1955 | scr_memsetw((unsigned short *) (vc->vc_origin + |
1963 | vc->vc_size_row * | 1956 | vc->vc_size_row * |
1964 | (b - count)), | 1957 | (b - count)), |
1965 | vc->vc_scrl_erase_char, | 1958 | vc->vc_video_erase_char, |
1966 | vc->vc_size_row * count); | 1959 | vc->vc_size_row * count); |
1967 | ret = 1; | 1960 | return 1; |
1968 | break; | ||
1969 | } | 1961 | } |
1970 | break; | 1962 | break; |
1971 | 1963 | ||
@@ -1982,9 +1974,9 @@ static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir, | |||
1982 | scr_memsetw((unsigned short *) (vc->vc_origin + | 1974 | scr_memsetw((unsigned short *) (vc->vc_origin + |
1983 | vc->vc_size_row * | 1975 | vc->vc_size_row * |
1984 | t), | 1976 | t), |
1985 | vc->vc_scrl_erase_char, | 1977 | vc->vc_video_erase_char, |
1986 | vc->vc_size_row * count); | 1978 | vc->vc_size_row * count); |
1987 | ret = 1; | 1979 | return 1; |
1988 | break; | 1980 | break; |
1989 | 1981 | ||
1990 | case SCROLL_WRAP_MOVE: | 1982 | case SCROLL_WRAP_MOVE: |
@@ -2052,15 +2044,12 @@ static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir, | |||
2052 | scr_memsetw((unsigned short *) (vc->vc_origin + | 2044 | scr_memsetw((unsigned short *) (vc->vc_origin + |
2053 | vc->vc_size_row * | 2045 | vc->vc_size_row * |
2054 | t), | 2046 | t), |
2055 | vc->vc_scrl_erase_char, | 2047 | vc->vc_video_erase_char, |
2056 | vc->vc_size_row * count); | 2048 | vc->vc_size_row * count); |
2057 | ret = 1; | 2049 | return 1; |
2058 | break; | ||
2059 | } | 2050 | } |
2060 | break; | ||
2061 | } | 2051 | } |
2062 | vc->vc_video_erase_char = saved_ec; | 2052 | return 0; |
2063 | return ret; | ||
2064 | } | 2053 | } |
2065 | 2054 | ||
2066 | 2055 | ||
@@ -2522,9 +2511,6 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h, | |||
2522 | c = vc->vc_video_erase_char; | 2511 | c = vc->vc_video_erase_char; |
2523 | vc->vc_video_erase_char = | 2512 | vc->vc_video_erase_char = |
2524 | ((c & 0xfe00) >> 1) | (c & 0xff); | 2513 | ((c & 0xfe00) >> 1) | (c & 0xff); |
2525 | c = vc->vc_scrl_erase_char; | ||
2526 | vc->vc_scrl_erase_char = | ||
2527 | ((c & 0xFE00) >> 1) | (c & 0xFF); | ||
2528 | vc->vc_attr >>= 1; | 2514 | vc->vc_attr >>= 1; |
2529 | } | 2515 | } |
2530 | } else if (!vc->vc_hi_font_mask && cnt == 512) { | 2516 | } else if (!vc->vc_hi_font_mask && cnt == 512) { |
@@ -2555,14 +2541,9 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h, | |||
2555 | if (vc->vc_can_do_color) { | 2541 | if (vc->vc_can_do_color) { |
2556 | vc->vc_video_erase_char = | 2542 | vc->vc_video_erase_char = |
2557 | ((c & 0xff00) << 1) | (c & 0xff); | 2543 | ((c & 0xff00) << 1) | (c & 0xff); |
2558 | c = vc->vc_scrl_erase_char; | ||
2559 | vc->vc_scrl_erase_char = | ||
2560 | ((c & 0xFF00) << 1) | (c & 0xFF); | ||
2561 | vc->vc_attr <<= 1; | 2544 | vc->vc_attr <<= 1; |
2562 | } else { | 2545 | } else |
2563 | vc->vc_video_erase_char = c & ~0x100; | 2546 | vc->vc_video_erase_char = c & ~0x100; |
2564 | vc->vc_scrl_erase_char = c & ~0x100; | ||
2565 | } | ||
2566 | } | 2547 | } |
2567 | 2548 | ||
2568 | } | 2549 | } |
diff --git a/drivers/video/console/mdacon.c b/drivers/video/console/mdacon.c index 9901064199bd..dd3eaaad4441 100644 --- a/drivers/video/console/mdacon.c +++ b/drivers/video/console/mdacon.c | |||
@@ -533,7 +533,7 @@ static void mdacon_cursor(struct vc_data *c, int mode) | |||
533 | 533 | ||
534 | static int mdacon_scroll(struct vc_data *c, int t, int b, int dir, int lines) | 534 | static int mdacon_scroll(struct vc_data *c, int t, int b, int dir, int lines) |
535 | { | 535 | { |
536 | u16 eattr = mda_convert_attr(c->vc_scrl_erase_char); | 536 | u16 eattr = mda_convert_attr(c->vc_video_erase_char); |
537 | 537 | ||
538 | if (!lines) | 538 | if (!lines) |
539 | return 0; | 539 | return 0; |
diff --git a/drivers/video/console/sticon.c b/drivers/video/console/sticon.c index 4055dbdd1b42..491c1c1baf4c 100644 --- a/drivers/video/console/sticon.c +++ b/drivers/video/console/sticon.c | |||
@@ -170,12 +170,12 @@ static int sticon_scroll(struct vc_data *conp, int t, int b, int dir, int count) | |||
170 | switch (dir) { | 170 | switch (dir) { |
171 | case SM_UP: | 171 | case SM_UP: |
172 | sti_bmove(sti, t + count, 0, t, 0, b - t - count, conp->vc_cols); | 172 | sti_bmove(sti, t + count, 0, t, 0, b - t - count, conp->vc_cols); |
173 | sti_clear(sti, b - count, 0, count, conp->vc_cols, conp->vc_scrl_erase_char); | 173 | sti_clear(sti, b - count, 0, count, conp->vc_cols, conp->vc_video_erase_char); |
174 | break; | 174 | break; |
175 | 175 | ||
176 | case SM_DOWN: | 176 | case SM_DOWN: |
177 | sti_bmove(sti, t, 0, t + count, 0, b - t - count, conp->vc_cols); | 177 | sti_bmove(sti, t, 0, t + count, 0, b - t - count, conp->vc_cols); |
178 | sti_clear(sti, t, 0, count, conp->vc_cols, conp->vc_scrl_erase_char); | 178 | sti_clear(sti, t, 0, count, conp->vc_cols, conp->vc_video_erase_char); |
179 | break; | 179 | break; |
180 | } | 180 | } |
181 | 181 | ||
diff --git a/drivers/video/console/vgacon.c b/drivers/video/console/vgacon.c index bd1f57b259d9..6df29a62d720 100644 --- a/drivers/video/console/vgacon.c +++ b/drivers/video/console/vgacon.c | |||
@@ -1350,7 +1350,7 @@ static int vgacon_scroll(struct vc_data *c, int t, int b, int dir, | |||
1350 | } else | 1350 | } else |
1351 | c->vc_origin += delta; | 1351 | c->vc_origin += delta; |
1352 | scr_memsetw((u16 *) (c->vc_origin + c->vc_screenbuf_size - | 1352 | scr_memsetw((u16 *) (c->vc_origin + c->vc_screenbuf_size - |
1353 | delta), c->vc_scrl_erase_char, | 1353 | delta), c->vc_video_erase_char, |
1354 | delta); | 1354 | delta); |
1355 | } else { | 1355 | } else { |
1356 | if (oldo - delta < vga_vram_base) { | 1356 | if (oldo - delta < vga_vram_base) { |
@@ -1363,7 +1363,7 @@ static int vgacon_scroll(struct vc_data *c, int t, int b, int dir, | |||
1363 | } else | 1363 | } else |
1364 | c->vc_origin -= delta; | 1364 | c->vc_origin -= delta; |
1365 | c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size; | 1365 | c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size; |
1366 | scr_memsetw((u16 *) (c->vc_origin), c->vc_scrl_erase_char, | 1366 | scr_memsetw((u16 *) (c->vc_origin), c->vc_video_erase_char, |
1367 | delta); | 1367 | delta); |
1368 | } | 1368 | } |
1369 | c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size; | 1369 | c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size; |
diff --git a/fs/Kconfig b/fs/Kconfig index f54a157a0296..9e9d70c02a07 100644 --- a/fs/Kconfig +++ b/fs/Kconfig | |||
@@ -220,17 +220,16 @@ config JBD | |||
220 | tristate | 220 | tristate |
221 | help | 221 | help |
222 | This is a generic journalling layer for block devices. It is | 222 | This is a generic journalling layer for block devices. It is |
223 | currently used by the ext3 and OCFS2 file systems, but it could | 223 | currently used by the ext3 file system, but it could also be |
224 | also be used to add journal support to other file systems or block | 224 | used to add journal support to other file systems or block |
225 | devices such as RAID or LVM. | 225 | devices such as RAID or LVM. |
226 | 226 | ||
227 | If you are using the ext3 or OCFS2 file systems, you need to | 227 | If you are using the ext3 file system, you need to say Y here. |
228 | say Y here. If you are not using ext3 OCFS2 then you will probably | 228 | If you are not using ext3 then you will probably want to say N. |
229 | want to say N. | ||
230 | 229 | ||
231 | To compile this device as a module, choose M here: the module will be | 230 | To compile this device as a module, choose M here: the module will be |
232 | called jbd. If you are compiling ext3 or OCFS2 into the kernel, | 231 | called jbd. If you are compiling ext3 into the kernel, you |
233 | you cannot compile this code as a module. | 232 | cannot compile this code as a module. |
234 | 233 | ||
235 | config JBD_DEBUG | 234 | config JBD_DEBUG |
236 | bool "JBD (ext3) debugging support" | 235 | bool "JBD (ext3) debugging support" |
@@ -254,15 +253,16 @@ config JBD2 | |||
254 | help | 253 | help |
255 | This is a generic journaling layer for block devices that support | 254 | This is a generic journaling layer for block devices that support |
256 | both 32-bit and 64-bit block numbers. It is currently used by | 255 | both 32-bit and 64-bit block numbers. It is currently used by |
257 | the ext4 filesystem, but it could also be used to add | 256 | the ext4 and OCFS2 filesystems, but it could also be used to add |
258 | journal support to other file systems or block devices such | 257 | journal support to other file systems or block devices such |
259 | as RAID or LVM. | 258 | as RAID or LVM. |
260 | 259 | ||
261 | If you are using ext4, you need to say Y here. If you are not | 260 | If you are using ext4 or OCFS2, you need to say Y here. |
262 | using ext4 then you will probably want to say N. | 261 | If you are not using ext4 or OCFS2 then you will |
262 | probably want to say N. | ||
263 | 263 | ||
264 | To compile this device as a module, choose M here. The module will be | 264 | To compile this device as a module, choose M here. The module will be |
265 | called jbd2. If you are compiling ext4 into the kernel, | 265 | called jbd2. If you are compiling ext4 or OCFS2 into the kernel, |
266 | you cannot compile this code as a module. | 266 | you cannot compile this code as a module. |
267 | 267 | ||
268 | config JBD2_DEBUG | 268 | config JBD2_DEBUG |
@@ -433,6 +433,14 @@ config FS_POSIX_ACL | |||
433 | bool | 433 | bool |
434 | default n | 434 | default n |
435 | 435 | ||
436 | config FILE_LOCKING | ||
437 | bool "Enable POSIX file locking API" if EMBEDDED | ||
438 | default y | ||
439 | help | ||
440 | This option enables standard file locking support, required | ||
441 | for filesystems like NFS and for the flock() system | ||
442 | call. Disabling this option saves about 11k. | ||
443 | |||
436 | source "fs/xfs/Kconfig" | 444 | source "fs/xfs/Kconfig" |
437 | source "fs/gfs2/Kconfig" | 445 | source "fs/gfs2/Kconfig" |
438 | 446 | ||
@@ -440,7 +448,7 @@ config OCFS2_FS | |||
440 | tristate "OCFS2 file system support" | 448 | tristate "OCFS2 file system support" |
441 | depends on NET && SYSFS | 449 | depends on NET && SYSFS |
442 | select CONFIGFS_FS | 450 | select CONFIGFS_FS |
443 | select JBD | 451 | select JBD2 |
444 | select CRC32 | 452 | select CRC32 |
445 | help | 453 | help |
446 | OCFS2 is a general purpose extent based shared disk cluster file | 454 | OCFS2 is a general purpose extent based shared disk cluster file |
@@ -511,6 +519,16 @@ config OCFS2_DEBUG_FS | |||
511 | this option for debugging only as it is likely to decrease | 519 | this option for debugging only as it is likely to decrease |
512 | performance of the filesystem. | 520 | performance of the filesystem. |
513 | 521 | ||
522 | config OCFS2_COMPAT_JBD | ||
523 | bool "Use JBD for compatibility" | ||
524 | depends on OCFS2_FS | ||
525 | default n | ||
526 | select JBD | ||
527 | help | ||
528 | The ocfs2 filesystem now uses JBD2 for its journalling. JBD2 | ||
529 | is backwards compatible with JBD. It is safe to say N here. | ||
530 | However, if you really want to use the original JBD, say Y here. | ||
531 | |||
514 | endif # BLOCK | 532 | endif # BLOCK |
515 | 533 | ||
516 | config DNOTIFY | 534 | config DNOTIFY |
@@ -1779,6 +1797,28 @@ config SUNRPC_XPRT_RDMA | |||
1779 | 1797 | ||
1780 | If unsure, say N. | 1798 | If unsure, say N. |
1781 | 1799 | ||
1800 | config SUNRPC_REGISTER_V4 | ||
1801 | bool "Register local RPC services via rpcbind v4 (EXPERIMENTAL)" | ||
1802 | depends on SUNRPC && EXPERIMENTAL | ||
1803 | default n | ||
1804 | help | ||
1805 | Sun added support for registering RPC services at an IPv6 | ||
1806 | address by creating two new versions of the rpcbind protocol | ||
1807 | (RFC 1833). | ||
1808 | |||
1809 | This option enables support in the kernel RPC server for | ||
1810 | registering kernel RPC services via version 4 of the rpcbind | ||
1811 | protocol. If you enable this option, you must run a portmapper | ||
1812 | daemon that supports rpcbind protocol version 4. | ||
1813 | |||
1814 | Serving NFS over IPv6 from knfsd (the kernel's NFS server) | ||
1815 | requires that you enable this option and use a portmapper that | ||
1816 | supports rpcbind version 4. | ||
1817 | |||
1818 | If unsure, say N to get traditional behavior (register kernel | ||
1819 | RPC services using only rpcbind version 2). Distributions | ||
1820 | using the legacy Linux portmapper daemon must say N here. | ||
1821 | |||
1782 | config RPCSEC_GSS_KRB5 | 1822 | config RPCSEC_GSS_KRB5 |
1783 | tristate "Secure RPC: Kerberos V mechanism (EXPERIMENTAL)" | 1823 | tristate "Secure RPC: Kerberos V mechanism (EXPERIMENTAL)" |
1784 | depends on SUNRPC && EXPERIMENTAL | 1824 | depends on SUNRPC && EXPERIMENTAL |
diff --git a/fs/Makefile b/fs/Makefile index de404b00eb0c..b6f27dc26b72 100644 --- a/fs/Makefile +++ b/fs/Makefile | |||
@@ -7,7 +7,7 @@ | |||
7 | 7 | ||
8 | obj-y := open.o read_write.o file_table.o super.o \ | 8 | obj-y := open.o read_write.o file_table.o super.o \ |
9 | char_dev.o stat.o exec.o pipe.o namei.o fcntl.o \ | 9 | char_dev.o stat.o exec.o pipe.o namei.o fcntl.o \ |
10 | ioctl.o readdir.o select.o fifo.o locks.o dcache.o inode.o \ | 10 | ioctl.o readdir.o select.o fifo.o dcache.o inode.o \ |
11 | attr.o bad_inode.o file.o filesystems.o namespace.o aio.o \ | 11 | attr.o bad_inode.o file.o filesystems.o namespace.o aio.o \ |
12 | seq_file.o xattr.o libfs.o fs-writeback.o \ | 12 | seq_file.o xattr.o libfs.o fs-writeback.o \ |
13 | pnode.o drop_caches.o splice.o sync.o utimes.o \ | 13 | pnode.o drop_caches.o splice.o sync.o utimes.o \ |
@@ -27,6 +27,7 @@ obj-$(CONFIG_ANON_INODES) += anon_inodes.o | |||
27 | obj-$(CONFIG_SIGNALFD) += signalfd.o | 27 | obj-$(CONFIG_SIGNALFD) += signalfd.o |
28 | obj-$(CONFIG_TIMERFD) += timerfd.o | 28 | obj-$(CONFIG_TIMERFD) += timerfd.o |
29 | obj-$(CONFIG_EVENTFD) += eventfd.o | 29 | obj-$(CONFIG_EVENTFD) += eventfd.o |
30 | obj-$(CONFIG_FILE_LOCKING) += locks.o | ||
30 | obj-$(CONFIG_COMPAT) += compat.o compat_ioctl.o | 31 | obj-$(CONFIG_COMPAT) += compat.o compat_ioctl.o |
31 | 32 | ||
32 | nfsd-$(CONFIG_NFSD) := nfsctl.o | 33 | nfsd-$(CONFIG_NFSD) := nfsctl.o |
diff --git a/fs/lockd/Makefile b/fs/lockd/Makefile index 7725a0a9a555..97f6073ab339 100644 --- a/fs/lockd/Makefile +++ b/fs/lockd/Makefile | |||
@@ -5,6 +5,6 @@ | |||
5 | obj-$(CONFIG_LOCKD) += lockd.o | 5 | obj-$(CONFIG_LOCKD) += lockd.o |
6 | 6 | ||
7 | lockd-objs-y := clntlock.o clntproc.o host.o svc.o svclock.o svcshare.o \ | 7 | lockd-objs-y := clntlock.o clntproc.o host.o svc.o svclock.o svcshare.o \ |
8 | svcproc.o svcsubs.o mon.o xdr.o | 8 | svcproc.o svcsubs.o mon.o xdr.o grace.o |
9 | lockd-objs-$(CONFIG_LOCKD_V4) += xdr4.o svc4proc.o | 9 | lockd-objs-$(CONFIG_LOCKD_V4) += xdr4.o svc4proc.o |
10 | lockd-objs := $(lockd-objs-y) | 10 | lockd-objs := $(lockd-objs-y) |
diff --git a/fs/lockd/clntlock.c b/fs/lockd/clntlock.c index 0b45fd3a4bfd..8307dd64bf46 100644 --- a/fs/lockd/clntlock.c +++ b/fs/lockd/clntlock.c | |||
@@ -54,14 +54,13 @@ struct nlm_host *nlmclnt_init(const struct nlmclnt_initdata *nlm_init) | |||
54 | u32 nlm_version = (nlm_init->nfs_version == 2) ? 1 : 4; | 54 | u32 nlm_version = (nlm_init->nfs_version == 2) ? 1 : 4; |
55 | int status; | 55 | int status; |
56 | 56 | ||
57 | status = lockd_up(nlm_init->protocol); | 57 | status = lockd_up(); |
58 | if (status < 0) | 58 | if (status < 0) |
59 | return ERR_PTR(status); | 59 | return ERR_PTR(status); |
60 | 60 | ||
61 | host = nlmclnt_lookup_host((struct sockaddr_in *)nlm_init->address, | 61 | host = nlmclnt_lookup_host(nlm_init->address, nlm_init->addrlen, |
62 | nlm_init->protocol, nlm_version, | 62 | nlm_init->protocol, nlm_version, |
63 | nlm_init->hostname, | 63 | nlm_init->hostname); |
64 | strlen(nlm_init->hostname)); | ||
65 | if (host == NULL) { | 64 | if (host == NULL) { |
66 | lockd_down(); | 65 | lockd_down(); |
67 | return ERR_PTR(-ENOLCK); | 66 | return ERR_PTR(-ENOLCK); |
@@ -142,7 +141,7 @@ int nlmclnt_block(struct nlm_wait *block, struct nlm_rqst *req, long timeout) | |||
142 | /* | 141 | /* |
143 | * The server lockd has called us back to tell us the lock was granted | 142 | * The server lockd has called us back to tell us the lock was granted |
144 | */ | 143 | */ |
145 | __be32 nlmclnt_grant(const struct sockaddr_in *addr, const struct nlm_lock *lock) | 144 | __be32 nlmclnt_grant(const struct sockaddr *addr, const struct nlm_lock *lock) |
146 | { | 145 | { |
147 | const struct file_lock *fl = &lock->fl; | 146 | const struct file_lock *fl = &lock->fl; |
148 | const struct nfs_fh *fh = &lock->fh; | 147 | const struct nfs_fh *fh = &lock->fh; |
@@ -166,7 +165,7 @@ __be32 nlmclnt_grant(const struct sockaddr_in *addr, const struct nlm_lock *lock | |||
166 | */ | 165 | */ |
167 | if (fl_blocked->fl_u.nfs_fl.owner->pid != lock->svid) | 166 | if (fl_blocked->fl_u.nfs_fl.owner->pid != lock->svid) |
168 | continue; | 167 | continue; |
169 | if (!nlm_cmp_addr(&block->b_host->h_addr, addr)) | 168 | if (!nlm_cmp_addr(nlm_addr(block->b_host), addr)) |
170 | continue; | 169 | continue; |
171 | if (nfs_compare_fh(NFS_FH(fl_blocked->fl_file->f_path.dentry->d_inode) ,fh) != 0) | 170 | if (nfs_compare_fh(NFS_FH(fl_blocked->fl_file->f_path.dentry->d_inode) ,fh) != 0) |
172 | continue; | 171 | continue; |
@@ -216,7 +215,7 @@ reclaimer(void *ptr) | |||
216 | /* This one ensures that our parent doesn't terminate while the | 215 | /* This one ensures that our parent doesn't terminate while the |
217 | * reclaim is in progress */ | 216 | * reclaim is in progress */ |
218 | lock_kernel(); | 217 | lock_kernel(); |
219 | lockd_up(0); /* note: this cannot fail as lockd is already running */ | 218 | lockd_up(); /* note: this cannot fail as lockd is already running */ |
220 | 219 | ||
221 | dprintk("lockd: reclaiming locks for host %s\n", host->h_name); | 220 | dprintk("lockd: reclaiming locks for host %s\n", host->h_name); |
222 | 221 | ||
diff --git a/fs/lockd/grace.c b/fs/lockd/grace.c new file mode 100644 index 000000000000..183cc1f0af1c --- /dev/null +++ b/fs/lockd/grace.c | |||
@@ -0,0 +1,59 @@ | |||
1 | /* | ||
2 | * Common code for control of lockd and nfsv4 grace periods. | ||
3 | */ | ||
4 | |||
5 | #include <linux/module.h> | ||
6 | #include <linux/lockd/bind.h> | ||
7 | |||
8 | static LIST_HEAD(grace_list); | ||
9 | static DEFINE_SPINLOCK(grace_lock); | ||
10 | |||
11 | /** | ||
12 | * locks_start_grace | ||
13 | * @lm: who this grace period is for | ||
14 | * | ||
15 | * A grace period is a period during which locks should not be given | ||
16 | * out. Currently grace periods are only enforced by the two lock | ||
17 | * managers (lockd and nfsd), using the locks_in_grace() function to | ||
18 | * check when they are in a grace period. | ||
19 | * | ||
20 | * This function is called to start a grace period. | ||
21 | */ | ||
22 | void locks_start_grace(struct lock_manager *lm) | ||
23 | { | ||
24 | spin_lock(&grace_lock); | ||
25 | list_add(&lm->list, &grace_list); | ||
26 | spin_unlock(&grace_lock); | ||
27 | } | ||
28 | EXPORT_SYMBOL_GPL(locks_start_grace); | ||
29 | |||
30 | /** | ||
31 | * locks_end_grace | ||
32 | * @lm: who this grace period is for | ||
33 | * | ||
34 | * Call this function to state that the given lock manager is ready to | ||
35 | * resume regular locking. The grace period will not end until all lock | ||
36 | * managers that called locks_start_grace() also call locks_end_grace(). | ||
37 | * Note that callers count on it being safe to call this more than once, | ||
38 | * and the second call should be a no-op. | ||
39 | */ | ||
40 | void locks_end_grace(struct lock_manager *lm) | ||
41 | { | ||
42 | spin_lock(&grace_lock); | ||
43 | list_del_init(&lm->list); | ||
44 | spin_unlock(&grace_lock); | ||
45 | } | ||
46 | EXPORT_SYMBOL_GPL(locks_end_grace); | ||
47 | |||
48 | /** | ||
49 | * locks_in_grace | ||
50 | * | ||
51 | * Lock managers call this function to determine when it is OK for them | ||
52 | * to answer ordinary lock requests, and when they should accept only | ||
53 | * lock reclaims. | ||
54 | */ | ||
55 | int locks_in_grace(void) | ||
56 | { | ||
57 | return !list_empty(&grace_list); | ||
58 | } | ||
59 | EXPORT_SYMBOL_GPL(locks_in_grace); | ||
diff --git a/fs/lockd/host.c b/fs/lockd/host.c index a17664c7eacc..9fd8889097b7 100644 --- a/fs/lockd/host.c +++ b/fs/lockd/host.c | |||
@@ -11,16 +11,17 @@ | |||
11 | #include <linux/types.h> | 11 | #include <linux/types.h> |
12 | #include <linux/slab.h> | 12 | #include <linux/slab.h> |
13 | #include <linux/in.h> | 13 | #include <linux/in.h> |
14 | #include <linux/in6.h> | ||
14 | #include <linux/sunrpc/clnt.h> | 15 | #include <linux/sunrpc/clnt.h> |
15 | #include <linux/sunrpc/svc.h> | 16 | #include <linux/sunrpc/svc.h> |
16 | #include <linux/lockd/lockd.h> | 17 | #include <linux/lockd/lockd.h> |
17 | #include <linux/lockd/sm_inter.h> | 18 | #include <linux/lockd/sm_inter.h> |
18 | #include <linux/mutex.h> | 19 | #include <linux/mutex.h> |
19 | 20 | ||
21 | #include <net/ipv6.h> | ||
20 | 22 | ||
21 | #define NLMDBG_FACILITY NLMDBG_HOSTCACHE | 23 | #define NLMDBG_FACILITY NLMDBG_HOSTCACHE |
22 | #define NLM_HOST_NRHASH 32 | 24 | #define NLM_HOST_NRHASH 32 |
23 | #define NLM_ADDRHASH(addr) (ntohl(addr) & (NLM_HOST_NRHASH-1)) | ||
24 | #define NLM_HOST_REBIND (60 * HZ) | 25 | #define NLM_HOST_REBIND (60 * HZ) |
25 | #define NLM_HOST_EXPIRE (300 * HZ) | 26 | #define NLM_HOST_EXPIRE (300 * HZ) |
26 | #define NLM_HOST_COLLECT (120 * HZ) | 27 | #define NLM_HOST_COLLECT (120 * HZ) |
@@ -30,42 +31,115 @@ static unsigned long next_gc; | |||
30 | static int nrhosts; | 31 | static int nrhosts; |
31 | static DEFINE_MUTEX(nlm_host_mutex); | 32 | static DEFINE_MUTEX(nlm_host_mutex); |
32 | 33 | ||
33 | |||
34 | static void nlm_gc_hosts(void); | 34 | static void nlm_gc_hosts(void); |
35 | static struct nsm_handle * __nsm_find(const struct sockaddr_in *, | 35 | static struct nsm_handle *nsm_find(const struct sockaddr *sap, |
36 | const char *, unsigned int, int); | 36 | const size_t salen, |
37 | static struct nsm_handle * nsm_find(const struct sockaddr_in *sin, | 37 | const char *hostname, |
38 | const char *hostname, | 38 | const size_t hostname_len, |
39 | unsigned int hostname_len); | 39 | const int create); |
40 | |||
41 | struct nlm_lookup_host_info { | ||
42 | const int server; /* search for server|client */ | ||
43 | const struct sockaddr *sap; /* address to search for */ | ||
44 | const size_t salen; /* it's length */ | ||
45 | const unsigned short protocol; /* transport to search for*/ | ||
46 | const u32 version; /* NLM version to search for */ | ||
47 | const char *hostname; /* remote's hostname */ | ||
48 | const size_t hostname_len; /* it's length */ | ||
49 | const struct sockaddr *src_sap; /* our address (optional) */ | ||
50 | const size_t src_len; /* it's length */ | ||
51 | }; | ||
52 | |||
53 | /* | ||
54 | * Hash function must work well on big- and little-endian platforms | ||
55 | */ | ||
56 | static unsigned int __nlm_hash32(const __be32 n) | ||
57 | { | ||
58 | unsigned int hash = (__force u32)n ^ ((__force u32)n >> 16); | ||
59 | return hash ^ (hash >> 8); | ||
60 | } | ||
61 | |||
62 | static unsigned int __nlm_hash_addr4(const struct sockaddr *sap) | ||
63 | { | ||
64 | const struct sockaddr_in *sin = (struct sockaddr_in *)sap; | ||
65 | return __nlm_hash32(sin->sin_addr.s_addr); | ||
66 | } | ||
67 | |||
68 | static unsigned int __nlm_hash_addr6(const struct sockaddr *sap) | ||
69 | { | ||
70 | const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap; | ||
71 | const struct in6_addr addr = sin6->sin6_addr; | ||
72 | return __nlm_hash32(addr.s6_addr32[0]) ^ | ||
73 | __nlm_hash32(addr.s6_addr32[1]) ^ | ||
74 | __nlm_hash32(addr.s6_addr32[2]) ^ | ||
75 | __nlm_hash32(addr.s6_addr32[3]); | ||
76 | } | ||
77 | |||
78 | static unsigned int nlm_hash_address(const struct sockaddr *sap) | ||
79 | { | ||
80 | unsigned int hash; | ||
81 | |||
82 | switch (sap->sa_family) { | ||
83 | case AF_INET: | ||
84 | hash = __nlm_hash_addr4(sap); | ||
85 | break; | ||
86 | case AF_INET6: | ||
87 | hash = __nlm_hash_addr6(sap); | ||
88 | break; | ||
89 | default: | ||
90 | hash = 0; | ||
91 | } | ||
92 | return hash & (NLM_HOST_NRHASH - 1); | ||
93 | } | ||
94 | |||
95 | static void nlm_clear_port(struct sockaddr *sap) | ||
96 | { | ||
97 | switch (sap->sa_family) { | ||
98 | case AF_INET: | ||
99 | ((struct sockaddr_in *)sap)->sin_port = 0; | ||
100 | break; | ||
101 | case AF_INET6: | ||
102 | ((struct sockaddr_in6 *)sap)->sin6_port = 0; | ||
103 | break; | ||
104 | } | ||
105 | } | ||
106 | |||
107 | static void nlm_display_address(const struct sockaddr *sap, | ||
108 | char *buf, const size_t len) | ||
109 | { | ||
110 | const struct sockaddr_in *sin = (struct sockaddr_in *)sap; | ||
111 | const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap; | ||
112 | |||
113 | switch (sap->sa_family) { | ||
114 | case AF_UNSPEC: | ||
115 | snprintf(buf, len, "unspecified"); | ||
116 | break; | ||
117 | case AF_INET: | ||
118 | snprintf(buf, len, NIPQUAD_FMT, NIPQUAD(sin->sin_addr.s_addr)); | ||
119 | break; | ||
120 | case AF_INET6: | ||
121 | if (ipv6_addr_v4mapped(&sin6->sin6_addr)) | ||
122 | snprintf(buf, len, NIPQUAD_FMT, | ||
123 | NIPQUAD(sin6->sin6_addr.s6_addr32[3])); | ||
124 | else | ||
125 | snprintf(buf, len, NIP6_FMT, NIP6(sin6->sin6_addr)); | ||
126 | break; | ||
127 | default: | ||
128 | snprintf(buf, len, "unsupported address family"); | ||
129 | break; | ||
130 | } | ||
131 | } | ||
40 | 132 | ||
41 | /* | 133 | /* |
42 | * Common host lookup routine for server & client | 134 | * Common host lookup routine for server & client |
43 | */ | 135 | */ |
44 | static struct nlm_host *nlm_lookup_host(int server, | 136 | static struct nlm_host *nlm_lookup_host(struct nlm_lookup_host_info *ni) |
45 | const struct sockaddr_in *sin, | ||
46 | int proto, u32 version, | ||
47 | const char *hostname, | ||
48 | unsigned int hostname_len, | ||
49 | const struct sockaddr_in *ssin) | ||
50 | { | 137 | { |
51 | struct hlist_head *chain; | 138 | struct hlist_head *chain; |
52 | struct hlist_node *pos; | 139 | struct hlist_node *pos; |
53 | struct nlm_host *host; | 140 | struct nlm_host *host; |
54 | struct nsm_handle *nsm = NULL; | 141 | struct nsm_handle *nsm = NULL; |
55 | int hash; | ||
56 | |||
57 | dprintk("lockd: nlm_lookup_host("NIPQUAD_FMT"->"NIPQUAD_FMT | ||
58 | ", p=%d, v=%u, my role=%s, name=%.*s)\n", | ||
59 | NIPQUAD(ssin->sin_addr.s_addr), | ||
60 | NIPQUAD(sin->sin_addr.s_addr), proto, version, | ||
61 | server? "server" : "client", | ||
62 | hostname_len, | ||
63 | hostname? hostname : "<none>"); | ||
64 | 142 | ||
65 | |||
66 | hash = NLM_ADDRHASH(sin->sin_addr.s_addr); | ||
67 | |||
68 | /* Lock hash table */ | ||
69 | mutex_lock(&nlm_host_mutex); | 143 | mutex_lock(&nlm_host_mutex); |
70 | 144 | ||
71 | if (time_after_eq(jiffies, next_gc)) | 145 | if (time_after_eq(jiffies, next_gc)) |
@@ -78,22 +152,22 @@ static struct nlm_host *nlm_lookup_host(int server, | |||
78 | * different NLM rpc_clients into one single nlm_host object. | 152 | * different NLM rpc_clients into one single nlm_host object. |
79 | * This would allow us to have one nlm_host per address. | 153 | * This would allow us to have one nlm_host per address. |
80 | */ | 154 | */ |
81 | chain = &nlm_hosts[hash]; | 155 | chain = &nlm_hosts[nlm_hash_address(ni->sap)]; |
82 | hlist_for_each_entry(host, pos, chain, h_hash) { | 156 | hlist_for_each_entry(host, pos, chain, h_hash) { |
83 | if (!nlm_cmp_addr(&host->h_addr, sin)) | 157 | if (!nlm_cmp_addr(nlm_addr(host), ni->sap)) |
84 | continue; | 158 | continue; |
85 | 159 | ||
86 | /* See if we have an NSM handle for this client */ | 160 | /* See if we have an NSM handle for this client */ |
87 | if (!nsm) | 161 | if (!nsm) |
88 | nsm = host->h_nsmhandle; | 162 | nsm = host->h_nsmhandle; |
89 | 163 | ||
90 | if (host->h_proto != proto) | 164 | if (host->h_proto != ni->protocol) |
91 | continue; | 165 | continue; |
92 | if (host->h_version != version) | 166 | if (host->h_version != ni->version) |
93 | continue; | 167 | continue; |
94 | if (host->h_server != server) | 168 | if (host->h_server != ni->server) |
95 | continue; | 169 | continue; |
96 | if (!nlm_cmp_addr(&host->h_saddr, ssin)) | 170 | if (!nlm_cmp_addr(nlm_srcaddr(host), ni->src_sap)) |
97 | continue; | 171 | continue; |
98 | 172 | ||
99 | /* Move to head of hash chain. */ | 173 | /* Move to head of hash chain. */ |
@@ -101,30 +175,41 @@ static struct nlm_host *nlm_lookup_host(int server, | |||
101 | hlist_add_head(&host->h_hash, chain); | 175 | hlist_add_head(&host->h_hash, chain); |
102 | 176 | ||
103 | nlm_get_host(host); | 177 | nlm_get_host(host); |
178 | dprintk("lockd: nlm_lookup_host found host %s (%s)\n", | ||
179 | host->h_name, host->h_addrbuf); | ||
104 | goto out; | 180 | goto out; |
105 | } | 181 | } |
106 | if (nsm) | ||
107 | atomic_inc(&nsm->sm_count); | ||
108 | |||
109 | host = NULL; | ||
110 | 182 | ||
111 | /* Sadly, the host isn't in our hash table yet. See if | 183 | /* |
112 | * we have an NSM handle for it. If not, create one. | 184 | * The host wasn't in our hash table. If we don't |
185 | * have an NSM handle for it yet, create one. | ||
113 | */ | 186 | */ |
114 | if (!nsm && !(nsm = nsm_find(sin, hostname, hostname_len))) | 187 | if (nsm) |
115 | goto out; | 188 | atomic_inc(&nsm->sm_count); |
189 | else { | ||
190 | host = NULL; | ||
191 | nsm = nsm_find(ni->sap, ni->salen, | ||
192 | ni->hostname, ni->hostname_len, 1); | ||
193 | if (!nsm) { | ||
194 | dprintk("lockd: nlm_lookup_host failed; " | ||
195 | "no nsm handle\n"); | ||
196 | goto out; | ||
197 | } | ||
198 | } | ||
116 | 199 | ||
117 | host = kzalloc(sizeof(*host), GFP_KERNEL); | 200 | host = kzalloc(sizeof(*host), GFP_KERNEL); |
118 | if (!host) { | 201 | if (!host) { |
119 | nsm_release(nsm); | 202 | nsm_release(nsm); |
203 | dprintk("lockd: nlm_lookup_host failed; no memory\n"); | ||
120 | goto out; | 204 | goto out; |
121 | } | 205 | } |
122 | host->h_name = nsm->sm_name; | 206 | host->h_name = nsm->sm_name; |
123 | host->h_addr = *sin; | 207 | memcpy(nlm_addr(host), ni->sap, ni->salen); |
124 | host->h_addr.sin_port = 0; /* ouch! */ | 208 | host->h_addrlen = ni->salen; |
125 | host->h_saddr = *ssin; | 209 | nlm_clear_port(nlm_addr(host)); |
126 | host->h_version = version; | 210 | memcpy(nlm_srcaddr(host), ni->src_sap, ni->src_len); |
127 | host->h_proto = proto; | 211 | host->h_version = ni->version; |
212 | host->h_proto = ni->protocol; | ||
128 | host->h_rpcclnt = NULL; | 213 | host->h_rpcclnt = NULL; |
129 | mutex_init(&host->h_mutex); | 214 | mutex_init(&host->h_mutex); |
130 | host->h_nextrebind = jiffies + NLM_HOST_REBIND; | 215 | host->h_nextrebind = jiffies + NLM_HOST_REBIND; |
@@ -135,7 +220,7 @@ static struct nlm_host *nlm_lookup_host(int server, | |||
135 | host->h_state = 0; /* pseudo NSM state */ | 220 | host->h_state = 0; /* pseudo NSM state */ |
136 | host->h_nsmstate = 0; /* real NSM state */ | 221 | host->h_nsmstate = 0; /* real NSM state */ |
137 | host->h_nsmhandle = nsm; | 222 | host->h_nsmhandle = nsm; |
138 | host->h_server = server; | 223 | host->h_server = ni->server; |
139 | hlist_add_head(&host->h_hash, chain); | 224 | hlist_add_head(&host->h_hash, chain); |
140 | INIT_LIST_HEAD(&host->h_lockowners); | 225 | INIT_LIST_HEAD(&host->h_lockowners); |
141 | spin_lock_init(&host->h_lock); | 226 | spin_lock_init(&host->h_lock); |
@@ -143,6 +228,15 @@ static struct nlm_host *nlm_lookup_host(int server, | |||
143 | INIT_LIST_HEAD(&host->h_reclaim); | 228 | INIT_LIST_HEAD(&host->h_reclaim); |
144 | 229 | ||
145 | nrhosts++; | 230 | nrhosts++; |
231 | |||
232 | nlm_display_address((struct sockaddr *)&host->h_addr, | ||
233 | host->h_addrbuf, sizeof(host->h_addrbuf)); | ||
234 | nlm_display_address((struct sockaddr *)&host->h_srcaddr, | ||
235 | host->h_srcaddrbuf, sizeof(host->h_srcaddrbuf)); | ||
236 | |||
237 | dprintk("lockd: nlm_lookup_host created host %s\n", | ||
238 | host->h_name); | ||
239 | |||
146 | out: | 240 | out: |
147 | mutex_unlock(&nlm_host_mutex); | 241 | mutex_unlock(&nlm_host_mutex); |
148 | return host; | 242 | return host; |
@@ -170,33 +264,103 @@ nlm_destroy_host(struct nlm_host *host) | |||
170 | kfree(host); | 264 | kfree(host); |
171 | } | 265 | } |
172 | 266 | ||
173 | /* | 267 | /** |
174 | * Find an NLM server handle in the cache. If there is none, create it. | 268 | * nlmclnt_lookup_host - Find an NLM host handle matching a remote server |
269 | * @sap: network address of server | ||
270 | * @salen: length of server address | ||
271 | * @protocol: transport protocol to use | ||
272 | * @version: NLM protocol version | ||
273 | * @hostname: '\0'-terminated hostname of server | ||
274 | * | ||
275 | * Returns an nlm_host structure that matches the passed-in | ||
276 | * [server address, transport protocol, NLM version, server hostname]. | ||
277 | * If one doesn't already exist in the host cache, a new handle is | ||
278 | * created and returned. | ||
175 | */ | 279 | */ |
176 | struct nlm_host *nlmclnt_lookup_host(const struct sockaddr_in *sin, | 280 | struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap, |
177 | int proto, u32 version, | 281 | const size_t salen, |
178 | const char *hostname, | 282 | const unsigned short protocol, |
179 | unsigned int hostname_len) | 283 | const u32 version, const char *hostname) |
180 | { | 284 | { |
181 | struct sockaddr_in ssin = {0}; | 285 | const struct sockaddr source = { |
182 | 286 | .sa_family = AF_UNSPEC, | |
183 | return nlm_lookup_host(0, sin, proto, version, | 287 | }; |
184 | hostname, hostname_len, &ssin); | 288 | struct nlm_lookup_host_info ni = { |
289 | .server = 0, | ||
290 | .sap = sap, | ||
291 | .salen = salen, | ||
292 | .protocol = protocol, | ||
293 | .version = version, | ||
294 | .hostname = hostname, | ||
295 | .hostname_len = strlen(hostname), | ||
296 | .src_sap = &source, | ||
297 | .src_len = sizeof(source), | ||
298 | }; | ||
299 | |||
300 | dprintk("lockd: %s(host='%s', vers=%u, proto=%s)\n", __func__, | ||
301 | (hostname ? hostname : "<none>"), version, | ||
302 | (protocol == IPPROTO_UDP ? "udp" : "tcp")); | ||
303 | |||
304 | return nlm_lookup_host(&ni); | ||
185 | } | 305 | } |
186 | 306 | ||
187 | /* | 307 | /** |
188 | * Find an NLM client handle in the cache. If there is none, create it. | 308 | * nlmsvc_lookup_host - Find an NLM host handle matching a remote client |
309 | * @rqstp: incoming NLM request | ||
310 | * @hostname: name of client host | ||
311 | * @hostname_len: length of client hostname | ||
312 | * | ||
313 | * Returns an nlm_host structure that matches the [client address, | ||
314 | * transport protocol, NLM version, client hostname] of the passed-in | ||
315 | * NLM request. If one doesn't already exist in the host cache, a | ||
316 | * new handle is created and returned. | ||
317 | * | ||
318 | * Before possibly creating a new nlm_host, construct a sockaddr | ||
319 | * for a specific source address in case the local system has | ||
320 | * multiple network addresses. The family of the address in | ||
321 | * rq_daddr is guaranteed to be the same as the family of the | ||
322 | * address in rq_addr, so it's safe to use the same family for | ||
323 | * the source address. | ||
189 | */ | 324 | */ |
190 | struct nlm_host * | 325 | struct nlm_host *nlmsvc_lookup_host(const struct svc_rqst *rqstp, |
191 | nlmsvc_lookup_host(struct svc_rqst *rqstp, | 326 | const char *hostname, |
192 | const char *hostname, unsigned int hostname_len) | 327 | const size_t hostname_len) |
193 | { | 328 | { |
194 | struct sockaddr_in ssin = {0}; | 329 | struct sockaddr_in sin = { |
330 | .sin_family = AF_INET, | ||
331 | }; | ||
332 | struct sockaddr_in6 sin6 = { | ||
333 | .sin6_family = AF_INET6, | ||
334 | }; | ||
335 | struct nlm_lookup_host_info ni = { | ||
336 | .server = 1, | ||
337 | .sap = svc_addr(rqstp), | ||
338 | .salen = rqstp->rq_addrlen, | ||
339 | .protocol = rqstp->rq_prot, | ||
340 | .version = rqstp->rq_vers, | ||
341 | .hostname = hostname, | ||
342 | .hostname_len = hostname_len, | ||
343 | .src_len = rqstp->rq_addrlen, | ||
344 | }; | ||
345 | |||
346 | dprintk("lockd: %s(host='%*s', vers=%u, proto=%s)\n", __func__, | ||
347 | (int)hostname_len, hostname, rqstp->rq_vers, | ||
348 | (rqstp->rq_prot == IPPROTO_UDP ? "udp" : "tcp")); | ||
349 | |||
350 | switch (ni.sap->sa_family) { | ||
351 | case AF_INET: | ||
352 | sin.sin_addr.s_addr = rqstp->rq_daddr.addr.s_addr; | ||
353 | ni.src_sap = (struct sockaddr *)&sin; | ||
354 | break; | ||
355 | case AF_INET6: | ||
356 | ipv6_addr_copy(&sin6.sin6_addr, &rqstp->rq_daddr.addr6); | ||
357 | ni.src_sap = (struct sockaddr *)&sin6; | ||
358 | break; | ||
359 | default: | ||
360 | return NULL; | ||
361 | } | ||
195 | 362 | ||
196 | ssin.sin_addr = rqstp->rq_daddr.addr; | 363 | return nlm_lookup_host(&ni); |
197 | return nlm_lookup_host(1, svc_addr_in(rqstp), | ||
198 | rqstp->rq_prot, rqstp->rq_vers, | ||
199 | hostname, hostname_len, &ssin); | ||
200 | } | 364 | } |
201 | 365 | ||
202 | /* | 366 | /* |
@@ -207,9 +371,8 @@ nlm_bind_host(struct nlm_host *host) | |||
207 | { | 371 | { |
208 | struct rpc_clnt *clnt; | 372 | struct rpc_clnt *clnt; |
209 | 373 | ||
210 | dprintk("lockd: nlm_bind_host("NIPQUAD_FMT"->"NIPQUAD_FMT")\n", | 374 | dprintk("lockd: nlm_bind_host %s (%s), my addr=%s\n", |
211 | NIPQUAD(host->h_saddr.sin_addr), | 375 | host->h_name, host->h_addrbuf, host->h_srcaddrbuf); |
212 | NIPQUAD(host->h_addr.sin_addr)); | ||
213 | 376 | ||
214 | /* Lock host handle */ | 377 | /* Lock host handle */ |
215 | mutex_lock(&host->h_mutex); | 378 | mutex_lock(&host->h_mutex); |
@@ -221,7 +384,7 @@ nlm_bind_host(struct nlm_host *host) | |||
221 | if (time_after_eq(jiffies, host->h_nextrebind)) { | 384 | if (time_after_eq(jiffies, host->h_nextrebind)) { |
222 | rpc_force_rebind(clnt); | 385 | rpc_force_rebind(clnt); |
223 | host->h_nextrebind = jiffies + NLM_HOST_REBIND; | 386 | host->h_nextrebind = jiffies + NLM_HOST_REBIND; |
224 | dprintk("lockd: next rebind in %ld jiffies\n", | 387 | dprintk("lockd: next rebind in %lu jiffies\n", |
225 | host->h_nextrebind - jiffies); | 388 | host->h_nextrebind - jiffies); |
226 | } | 389 | } |
227 | } else { | 390 | } else { |
@@ -234,9 +397,9 @@ nlm_bind_host(struct nlm_host *host) | |||
234 | }; | 397 | }; |
235 | struct rpc_create_args args = { | 398 | struct rpc_create_args args = { |
236 | .protocol = host->h_proto, | 399 | .protocol = host->h_proto, |
237 | .address = (struct sockaddr *)&host->h_addr, | 400 | .address = nlm_addr(host), |
238 | .addrsize = sizeof(host->h_addr), | 401 | .addrsize = host->h_addrlen, |
239 | .saddress = (struct sockaddr *)&host->h_saddr, | 402 | .saddress = nlm_srcaddr(host), |
240 | .timeout = &timeparms, | 403 | .timeout = &timeparms, |
241 | .servername = host->h_name, | 404 | .servername = host->h_name, |
242 | .program = &nlm_program, | 405 | .program = &nlm_program, |
@@ -324,12 +487,16 @@ void nlm_host_rebooted(const struct sockaddr_in *sin, | |||
324 | struct nsm_handle *nsm; | 487 | struct nsm_handle *nsm; |
325 | struct nlm_host *host; | 488 | struct nlm_host *host; |
326 | 489 | ||
327 | dprintk("lockd: nlm_host_rebooted(%s, %u.%u.%u.%u)\n", | 490 | nsm = nsm_find((struct sockaddr *)sin, sizeof(*sin), |
328 | hostname, NIPQUAD(sin->sin_addr)); | 491 | hostname, hostname_len, 0); |
329 | 492 | if (nsm == NULL) { | |
330 | /* Find the NSM handle for this peer */ | 493 | dprintk("lockd: never saw rebooted peer '%.*s' before\n", |
331 | if (!(nsm = __nsm_find(sin, hostname, hostname_len, 0))) | 494 | hostname_len, hostname); |
332 | return; | 495 | return; |
496 | } | ||
497 | |||
498 | dprintk("lockd: nlm_host_rebooted(%.*s, %s)\n", | ||
499 | hostname_len, hostname, nsm->sm_addrbuf); | ||
333 | 500 | ||
334 | /* When reclaiming locks on this peer, make sure that | 501 | /* When reclaiming locks on this peer, make sure that |
335 | * we set up a new notification */ | 502 | * we set up a new notification */ |
@@ -461,22 +628,23 @@ nlm_gc_hosts(void) | |||
461 | static LIST_HEAD(nsm_handles); | 628 | static LIST_HEAD(nsm_handles); |
462 | static DEFINE_SPINLOCK(nsm_lock); | 629 | static DEFINE_SPINLOCK(nsm_lock); |
463 | 630 | ||
464 | static struct nsm_handle * | 631 | static struct nsm_handle *nsm_find(const struct sockaddr *sap, |
465 | __nsm_find(const struct sockaddr_in *sin, | 632 | const size_t salen, |
466 | const char *hostname, unsigned int hostname_len, | 633 | const char *hostname, |
467 | int create) | 634 | const size_t hostname_len, |
635 | const int create) | ||
468 | { | 636 | { |
469 | struct nsm_handle *nsm = NULL; | 637 | struct nsm_handle *nsm = NULL; |
470 | struct nsm_handle *pos; | 638 | struct nsm_handle *pos; |
471 | 639 | ||
472 | if (!sin) | 640 | if (!sap) |
473 | return NULL; | 641 | return NULL; |
474 | 642 | ||
475 | if (hostname && memchr(hostname, '/', hostname_len) != NULL) { | 643 | if (hostname && memchr(hostname, '/', hostname_len) != NULL) { |
476 | if (printk_ratelimit()) { | 644 | if (printk_ratelimit()) { |
477 | printk(KERN_WARNING "Invalid hostname \"%.*s\" " | 645 | printk(KERN_WARNING "Invalid hostname \"%.*s\" " |
478 | "in NFS lock request\n", | 646 | "in NFS lock request\n", |
479 | hostname_len, hostname); | 647 | (int)hostname_len, hostname); |
480 | } | 648 | } |
481 | return NULL; | 649 | return NULL; |
482 | } | 650 | } |
@@ -489,7 +657,7 @@ retry: | |||
489 | if (strlen(pos->sm_name) != hostname_len | 657 | if (strlen(pos->sm_name) != hostname_len |
490 | || memcmp(pos->sm_name, hostname, hostname_len)) | 658 | || memcmp(pos->sm_name, hostname, hostname_len)) |
491 | continue; | 659 | continue; |
492 | } else if (!nlm_cmp_addr(&pos->sm_addr, sin)) | 660 | } else if (!nlm_cmp_addr(nsm_addr(pos), sap)) |
493 | continue; | 661 | continue; |
494 | atomic_inc(&pos->sm_count); | 662 | atomic_inc(&pos->sm_count); |
495 | kfree(nsm); | 663 | kfree(nsm); |
@@ -509,10 +677,13 @@ retry: | |||
509 | if (nsm == NULL) | 677 | if (nsm == NULL) |
510 | return NULL; | 678 | return NULL; |
511 | 679 | ||
512 | nsm->sm_addr = *sin; | 680 | memcpy(nsm_addr(nsm), sap, salen); |
681 | nsm->sm_addrlen = salen; | ||
513 | nsm->sm_name = (char *) (nsm + 1); | 682 | nsm->sm_name = (char *) (nsm + 1); |
514 | memcpy(nsm->sm_name, hostname, hostname_len); | 683 | memcpy(nsm->sm_name, hostname, hostname_len); |
515 | nsm->sm_name[hostname_len] = '\0'; | 684 | nsm->sm_name[hostname_len] = '\0'; |
685 | nlm_display_address((struct sockaddr *)&nsm->sm_addr, | ||
686 | nsm->sm_addrbuf, sizeof(nsm->sm_addrbuf)); | ||
516 | atomic_set(&nsm->sm_count, 1); | 687 | atomic_set(&nsm->sm_count, 1); |
517 | goto retry; | 688 | goto retry; |
518 | 689 | ||
@@ -521,13 +692,6 @@ found: | |||
521 | return nsm; | 692 | return nsm; |
522 | } | 693 | } |
523 | 694 | ||
524 | static struct nsm_handle * | ||
525 | nsm_find(const struct sockaddr_in *sin, const char *hostname, | ||
526 | unsigned int hostname_len) | ||
527 | { | ||
528 | return __nsm_find(sin, hostname, hostname_len, 1); | ||
529 | } | ||
530 | |||
531 | /* | 695 | /* |
532 | * Release an NSM handle | 696 | * Release an NSM handle |
533 | */ | 697 | */ |
diff --git a/fs/lockd/mon.c b/fs/lockd/mon.c index e4d563543b11..4e7e958e8f67 100644 --- a/fs/lockd/mon.c +++ b/fs/lockd/mon.c | |||
@@ -51,7 +51,7 @@ nsm_mon_unmon(struct nsm_handle *nsm, u32 proc, struct nsm_res *res) | |||
51 | 51 | ||
52 | memset(&args, 0, sizeof(args)); | 52 | memset(&args, 0, sizeof(args)); |
53 | args.mon_name = nsm->sm_name; | 53 | args.mon_name = nsm->sm_name; |
54 | args.addr = nsm->sm_addr.sin_addr.s_addr; | 54 | args.addr = nsm_addr_in(nsm)->sin_addr.s_addr; |
55 | args.prog = NLM_PROGRAM; | 55 | args.prog = NLM_PROGRAM; |
56 | args.vers = 3; | 56 | args.vers = 3; |
57 | args.proc = NLMPROC_NSM_NOTIFY; | 57 | args.proc = NLMPROC_NSM_NOTIFY; |
diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c index 5bd9bf0fa9df..c631a83931ce 100644 --- a/fs/lockd/svc.c +++ b/fs/lockd/svc.c | |||
@@ -51,7 +51,6 @@ static DEFINE_MUTEX(nlmsvc_mutex); | |||
51 | static unsigned int nlmsvc_users; | 51 | static unsigned int nlmsvc_users; |
52 | static struct task_struct *nlmsvc_task; | 52 | static struct task_struct *nlmsvc_task; |
53 | static struct svc_rqst *nlmsvc_rqst; | 53 | static struct svc_rqst *nlmsvc_rqst; |
54 | int nlmsvc_grace_period; | ||
55 | unsigned long nlmsvc_timeout; | 54 | unsigned long nlmsvc_timeout; |
56 | 55 | ||
57 | /* | 56 | /* |
@@ -85,27 +84,23 @@ static unsigned long get_lockd_grace_period(void) | |||
85 | return nlm_timeout * 5 * HZ; | 84 | return nlm_timeout * 5 * HZ; |
86 | } | 85 | } |
87 | 86 | ||
88 | unsigned long get_nfs_grace_period(void) | 87 | static struct lock_manager lockd_manager = { |
89 | { | 88 | }; |
90 | unsigned long lockdgrace = get_lockd_grace_period(); | ||
91 | unsigned long nfsdgrace = 0; | ||
92 | |||
93 | if (nlmsvc_ops) | ||
94 | nfsdgrace = nlmsvc_ops->get_grace_period(); | ||
95 | |||
96 | return max(lockdgrace, nfsdgrace); | ||
97 | } | ||
98 | EXPORT_SYMBOL(get_nfs_grace_period); | ||
99 | 89 | ||
100 | static unsigned long set_grace_period(void) | 90 | static void grace_ender(struct work_struct *not_used) |
101 | { | 91 | { |
102 | nlmsvc_grace_period = 1; | 92 | locks_end_grace(&lockd_manager); |
103 | return get_nfs_grace_period() + jiffies; | ||
104 | } | 93 | } |
105 | 94 | ||
106 | static inline void clear_grace_period(void) | 95 | static DECLARE_DELAYED_WORK(grace_period_end, grace_ender); |
96 | |||
97 | static void set_grace_period(void) | ||
107 | { | 98 | { |
108 | nlmsvc_grace_period = 0; | 99 | unsigned long grace_period = get_lockd_grace_period(); |
100 | |||
101 | locks_start_grace(&lockd_manager); | ||
102 | cancel_delayed_work_sync(&grace_period_end); | ||
103 | schedule_delayed_work(&grace_period_end, grace_period); | ||
109 | } | 104 | } |
110 | 105 | ||
111 | /* | 106 | /* |
@@ -116,7 +111,6 @@ lockd(void *vrqstp) | |||
116 | { | 111 | { |
117 | int err = 0, preverr = 0; | 112 | int err = 0, preverr = 0; |
118 | struct svc_rqst *rqstp = vrqstp; | 113 | struct svc_rqst *rqstp = vrqstp; |
119 | unsigned long grace_period_expire; | ||
120 | 114 | ||
121 | /* try_to_freeze() is called from svc_recv() */ | 115 | /* try_to_freeze() is called from svc_recv() */ |
122 | set_freezable(); | 116 | set_freezable(); |
@@ -139,7 +133,7 @@ lockd(void *vrqstp) | |||
139 | nlm_timeout = LOCKD_DFLT_TIMEO; | 133 | nlm_timeout = LOCKD_DFLT_TIMEO; |
140 | nlmsvc_timeout = nlm_timeout * HZ; | 134 | nlmsvc_timeout = nlm_timeout * HZ; |
141 | 135 | ||
142 | grace_period_expire = set_grace_period(); | 136 | set_grace_period(); |
143 | 137 | ||
144 | /* | 138 | /* |
145 | * The main request loop. We don't terminate until the last | 139 | * The main request loop. We don't terminate until the last |
@@ -153,21 +147,12 @@ lockd(void *vrqstp) | |||
153 | flush_signals(current); | 147 | flush_signals(current); |
154 | if (nlmsvc_ops) { | 148 | if (nlmsvc_ops) { |
155 | nlmsvc_invalidate_all(); | 149 | nlmsvc_invalidate_all(); |
156 | grace_period_expire = set_grace_period(); | 150 | set_grace_period(); |
157 | } | 151 | } |
158 | continue; | 152 | continue; |
159 | } | 153 | } |
160 | 154 | ||
161 | /* | 155 | timeout = nlmsvc_retry_blocked(); |
162 | * Retry any blocked locks that have been notified by | ||
163 | * the VFS. Don't do this during grace period. | ||
164 | * (Theoretically, there shouldn't even be blocked locks | ||
165 | * during grace period). | ||
166 | */ | ||
167 | if (!nlmsvc_grace_period) { | ||
168 | timeout = nlmsvc_retry_blocked(); | ||
169 | } else if (time_before(grace_period_expire, jiffies)) | ||
170 | clear_grace_period(); | ||
171 | 156 | ||
172 | /* | 157 | /* |
173 | * Find a socket with data available and call its | 158 | * Find a socket with data available and call its |
@@ -195,6 +180,7 @@ lockd(void *vrqstp) | |||
195 | svc_process(rqstp); | 180 | svc_process(rqstp); |
196 | } | 181 | } |
197 | flush_signals(current); | 182 | flush_signals(current); |
183 | cancel_delayed_work_sync(&grace_period_end); | ||
198 | if (nlmsvc_ops) | 184 | if (nlmsvc_ops) |
199 | nlmsvc_invalidate_all(); | 185 | nlmsvc_invalidate_all(); |
200 | nlm_shutdown_hosts(); | 186 | nlm_shutdown_hosts(); |
@@ -203,25 +189,28 @@ lockd(void *vrqstp) | |||
203 | } | 189 | } |
204 | 190 | ||
205 | /* | 191 | /* |
206 | * Make any sockets that are needed but not present. | 192 | * Ensure there are active UDP and TCP listeners for lockd. |
207 | * If nlm_udpport or nlm_tcpport were set as module | 193 | * |
208 | * options, make those sockets unconditionally | 194 | * Even if we have only TCP NFS mounts and/or TCP NFSDs, some |
195 | * local services (such as rpc.statd) still require UDP, and | ||
196 | * some NFS servers do not yet support NLM over TCP. | ||
197 | * | ||
198 | * Returns zero if all listeners are available; otherwise a | ||
199 | * negative errno value is returned. | ||
209 | */ | 200 | */ |
210 | static int make_socks(struct svc_serv *serv, int proto) | 201 | static int make_socks(struct svc_serv *serv) |
211 | { | 202 | { |
212 | static int warned; | 203 | static int warned; |
213 | struct svc_xprt *xprt; | 204 | struct svc_xprt *xprt; |
214 | int err = 0; | 205 | int err = 0; |
215 | 206 | ||
216 | if (proto == IPPROTO_UDP || nlm_udpport) { | 207 | xprt = svc_find_xprt(serv, "udp", 0, 0); |
217 | xprt = svc_find_xprt(serv, "udp", 0, 0); | 208 | if (!xprt) |
218 | if (!xprt) | 209 | err = svc_create_xprt(serv, "udp", nlm_udpport, |
219 | err = svc_create_xprt(serv, "udp", nlm_udpport, | 210 | SVC_SOCK_DEFAULTS); |
220 | SVC_SOCK_DEFAULTS); | 211 | else |
221 | else | 212 | svc_xprt_put(xprt); |
222 | svc_xprt_put(xprt); | 213 | if (err >= 0) { |
223 | } | ||
224 | if (err >= 0 && (proto == IPPROTO_TCP || nlm_tcpport)) { | ||
225 | xprt = svc_find_xprt(serv, "tcp", 0, 0); | 214 | xprt = svc_find_xprt(serv, "tcp", 0, 0); |
226 | if (!xprt) | 215 | if (!xprt) |
227 | err = svc_create_xprt(serv, "tcp", nlm_tcpport, | 216 | err = svc_create_xprt(serv, "tcp", nlm_tcpport, |
@@ -241,8 +230,7 @@ static int make_socks(struct svc_serv *serv, int proto) | |||
241 | /* | 230 | /* |
242 | * Bring up the lockd process if it's not already up. | 231 | * Bring up the lockd process if it's not already up. |
243 | */ | 232 | */ |
244 | int | 233 | int lockd_up(void) |
245 | lockd_up(int proto) /* Maybe add a 'family' option when IPv6 is supported ?? */ | ||
246 | { | 234 | { |
247 | struct svc_serv *serv; | 235 | struct svc_serv *serv; |
248 | int error = 0; | 236 | int error = 0; |
@@ -251,11 +239,8 @@ lockd_up(int proto) /* Maybe add a 'family' option when IPv6 is supported ?? */ | |||
251 | /* | 239 | /* |
252 | * Check whether we're already up and running. | 240 | * Check whether we're already up and running. |
253 | */ | 241 | */ |
254 | if (nlmsvc_rqst) { | 242 | if (nlmsvc_rqst) |
255 | if (proto) | ||
256 | error = make_socks(nlmsvc_rqst->rq_server, proto); | ||
257 | goto out; | 243 | goto out; |
258 | } | ||
259 | 244 | ||
260 | /* | 245 | /* |
261 | * Sanity check: if there's no pid, | 246 | * Sanity check: if there's no pid, |
@@ -266,13 +251,14 @@ lockd_up(int proto) /* Maybe add a 'family' option when IPv6 is supported ?? */ | |||
266 | "lockd_up: no pid, %d users??\n", nlmsvc_users); | 251 | "lockd_up: no pid, %d users??\n", nlmsvc_users); |
267 | 252 | ||
268 | error = -ENOMEM; | 253 | error = -ENOMEM; |
269 | serv = svc_create(&nlmsvc_program, LOCKD_BUFSIZE, NULL); | 254 | serv = svc_create(&nlmsvc_program, LOCKD_BUFSIZE, AF_INET, NULL); |
270 | if (!serv) { | 255 | if (!serv) { |
271 | printk(KERN_WARNING "lockd_up: create service failed\n"); | 256 | printk(KERN_WARNING "lockd_up: create service failed\n"); |
272 | goto out; | 257 | goto out; |
273 | } | 258 | } |
274 | 259 | ||
275 | if ((error = make_socks(serv, proto)) < 0) | 260 | error = make_socks(serv); |
261 | if (error < 0) | ||
276 | goto destroy_and_out; | 262 | goto destroy_and_out; |
277 | 263 | ||
278 | /* | 264 | /* |
diff --git a/fs/lockd/svc4proc.c b/fs/lockd/svc4proc.c index 4a714f64515b..014f6ce48172 100644 --- a/fs/lockd/svc4proc.c +++ b/fs/lockd/svc4proc.c | |||
@@ -88,12 +88,6 @@ nlm4svc_proc_test(struct svc_rqst *rqstp, struct nlm_args *argp, | |||
88 | dprintk("lockd: TEST4 called\n"); | 88 | dprintk("lockd: TEST4 called\n"); |
89 | resp->cookie = argp->cookie; | 89 | resp->cookie = argp->cookie; |
90 | 90 | ||
91 | /* Don't accept test requests during grace period */ | ||
92 | if (nlmsvc_grace_period) { | ||
93 | resp->status = nlm_lck_denied_grace_period; | ||
94 | return rc; | ||
95 | } | ||
96 | |||
97 | /* Obtain client and file */ | 91 | /* Obtain client and file */ |
98 | if ((resp->status = nlm4svc_retrieve_args(rqstp, argp, &host, &file))) | 92 | if ((resp->status = nlm4svc_retrieve_args(rqstp, argp, &host, &file))) |
99 | return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; | 93 | return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; |
@@ -122,12 +116,6 @@ nlm4svc_proc_lock(struct svc_rqst *rqstp, struct nlm_args *argp, | |||
122 | 116 | ||
123 | resp->cookie = argp->cookie; | 117 | resp->cookie = argp->cookie; |
124 | 118 | ||
125 | /* Don't accept new lock requests during grace period */ | ||
126 | if (nlmsvc_grace_period && !argp->reclaim) { | ||
127 | resp->status = nlm_lck_denied_grace_period; | ||
128 | return rc; | ||
129 | } | ||
130 | |||
131 | /* Obtain client and file */ | 119 | /* Obtain client and file */ |
132 | if ((resp->status = nlm4svc_retrieve_args(rqstp, argp, &host, &file))) | 120 | if ((resp->status = nlm4svc_retrieve_args(rqstp, argp, &host, &file))) |
133 | return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; | 121 | return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; |
@@ -146,7 +134,8 @@ nlm4svc_proc_lock(struct svc_rqst *rqstp, struct nlm_args *argp, | |||
146 | 134 | ||
147 | /* Now try to lock the file */ | 135 | /* Now try to lock the file */ |
148 | resp->status = nlmsvc_lock(rqstp, file, host, &argp->lock, | 136 | resp->status = nlmsvc_lock(rqstp, file, host, &argp->lock, |
149 | argp->block, &argp->cookie); | 137 | argp->block, &argp->cookie, |
138 | argp->reclaim); | ||
150 | if (resp->status == nlm_drop_reply) | 139 | if (resp->status == nlm_drop_reply) |
151 | rc = rpc_drop_reply; | 140 | rc = rpc_drop_reply; |
152 | else | 141 | else |
@@ -169,7 +158,7 @@ nlm4svc_proc_cancel(struct svc_rqst *rqstp, struct nlm_args *argp, | |||
169 | resp->cookie = argp->cookie; | 158 | resp->cookie = argp->cookie; |
170 | 159 | ||
171 | /* Don't accept requests during grace period */ | 160 | /* Don't accept requests during grace period */ |
172 | if (nlmsvc_grace_period) { | 161 | if (locks_in_grace()) { |
173 | resp->status = nlm_lck_denied_grace_period; | 162 | resp->status = nlm_lck_denied_grace_period; |
174 | return rpc_success; | 163 | return rpc_success; |
175 | } | 164 | } |
@@ -202,7 +191,7 @@ nlm4svc_proc_unlock(struct svc_rqst *rqstp, struct nlm_args *argp, | |||
202 | resp->cookie = argp->cookie; | 191 | resp->cookie = argp->cookie; |
203 | 192 | ||
204 | /* Don't accept new lock requests during grace period */ | 193 | /* Don't accept new lock requests during grace period */ |
205 | if (nlmsvc_grace_period) { | 194 | if (locks_in_grace()) { |
206 | resp->status = nlm_lck_denied_grace_period; | 195 | resp->status = nlm_lck_denied_grace_period; |
207 | return rpc_success; | 196 | return rpc_success; |
208 | } | 197 | } |
@@ -231,7 +220,7 @@ nlm4svc_proc_granted(struct svc_rqst *rqstp, struct nlm_args *argp, | |||
231 | resp->cookie = argp->cookie; | 220 | resp->cookie = argp->cookie; |
232 | 221 | ||
233 | dprintk("lockd: GRANTED called\n"); | 222 | dprintk("lockd: GRANTED called\n"); |
234 | resp->status = nlmclnt_grant(svc_addr_in(rqstp), &argp->lock); | 223 | resp->status = nlmclnt_grant(svc_addr(rqstp), &argp->lock); |
235 | dprintk("lockd: GRANTED status %d\n", ntohl(resp->status)); | 224 | dprintk("lockd: GRANTED status %d\n", ntohl(resp->status)); |
236 | return rpc_success; | 225 | return rpc_success; |
237 | } | 226 | } |
@@ -341,7 +330,7 @@ nlm4svc_proc_share(struct svc_rqst *rqstp, struct nlm_args *argp, | |||
341 | resp->cookie = argp->cookie; | 330 | resp->cookie = argp->cookie; |
342 | 331 | ||
343 | /* Don't accept new lock requests during grace period */ | 332 | /* Don't accept new lock requests during grace period */ |
344 | if (nlmsvc_grace_period && !argp->reclaim) { | 333 | if (locks_in_grace() && !argp->reclaim) { |
345 | resp->status = nlm_lck_denied_grace_period; | 334 | resp->status = nlm_lck_denied_grace_period; |
346 | return rpc_success; | 335 | return rpc_success; |
347 | } | 336 | } |
@@ -374,7 +363,7 @@ nlm4svc_proc_unshare(struct svc_rqst *rqstp, struct nlm_args *argp, | |||
374 | resp->cookie = argp->cookie; | 363 | resp->cookie = argp->cookie; |
375 | 364 | ||
376 | /* Don't accept requests during grace period */ | 365 | /* Don't accept requests during grace period */ |
377 | if (nlmsvc_grace_period) { | 366 | if (locks_in_grace()) { |
378 | resp->status = nlm_lck_denied_grace_period; | 367 | resp->status = nlm_lck_denied_grace_period; |
379 | return rpc_success; | 368 | return rpc_success; |
380 | } | 369 | } |
@@ -432,11 +421,9 @@ nlm4svc_proc_sm_notify(struct svc_rqst *rqstp, struct nlm_reboot *argp, | |||
432 | { | 421 | { |
433 | struct sockaddr_in saddr; | 422 | struct sockaddr_in saddr; |
434 | 423 | ||
435 | memcpy(&saddr, svc_addr_in(rqstp), sizeof(saddr)); | ||
436 | |||
437 | dprintk("lockd: SM_NOTIFY called\n"); | 424 | dprintk("lockd: SM_NOTIFY called\n"); |
438 | if (saddr.sin_addr.s_addr != htonl(INADDR_LOOPBACK) | 425 | |
439 | || ntohs(saddr.sin_port) >= 1024) { | 426 | if (!nlm_privileged_requester(rqstp)) { |
440 | char buf[RPC_MAX_ADDRBUFLEN]; | 427 | char buf[RPC_MAX_ADDRBUFLEN]; |
441 | printk(KERN_WARNING "lockd: rejected NSM callback from %s\n", | 428 | printk(KERN_WARNING "lockd: rejected NSM callback from %s\n", |
442 | svc_print_addr(rqstp, buf, sizeof(buf))); | 429 | svc_print_addr(rqstp, buf, sizeof(buf))); |
diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c index cf0d5c2c318d..6063a8e4b9f3 100644 --- a/fs/lockd/svclock.c +++ b/fs/lockd/svclock.c | |||
@@ -360,7 +360,7 @@ nlmsvc_defer_lock_rqst(struct svc_rqst *rqstp, struct nlm_block *block) | |||
360 | __be32 | 360 | __be32 |
361 | nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file, | 361 | nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file, |
362 | struct nlm_host *host, struct nlm_lock *lock, int wait, | 362 | struct nlm_host *host, struct nlm_lock *lock, int wait, |
363 | struct nlm_cookie *cookie) | 363 | struct nlm_cookie *cookie, int reclaim) |
364 | { | 364 | { |
365 | struct nlm_block *block = NULL; | 365 | struct nlm_block *block = NULL; |
366 | int error; | 366 | int error; |
@@ -406,6 +406,15 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file, | |||
406 | goto out; | 406 | goto out; |
407 | } | 407 | } |
408 | 408 | ||
409 | if (locks_in_grace() && !reclaim) { | ||
410 | ret = nlm_lck_denied_grace_period; | ||
411 | goto out; | ||
412 | } | ||
413 | if (reclaim && !locks_in_grace()) { | ||
414 | ret = nlm_lck_denied_grace_period; | ||
415 | goto out; | ||
416 | } | ||
417 | |||
409 | if (!wait) | 418 | if (!wait) |
410 | lock->fl.fl_flags &= ~FL_SLEEP; | 419 | lock->fl.fl_flags &= ~FL_SLEEP; |
411 | error = vfs_lock_file(file->f_file, F_SETLK, &lock->fl, NULL); | 420 | error = vfs_lock_file(file->f_file, F_SETLK, &lock->fl, NULL); |
@@ -502,6 +511,10 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file, | |||
502 | goto out; | 511 | goto out; |
503 | } | 512 | } |
504 | 513 | ||
514 | if (locks_in_grace()) { | ||
515 | ret = nlm_lck_denied_grace_period; | ||
516 | goto out; | ||
517 | } | ||
505 | error = vfs_test_lock(file->f_file, &lock->fl); | 518 | error = vfs_test_lock(file->f_file, &lock->fl); |
506 | if (error == FILE_LOCK_DEFERRED) { | 519 | if (error == FILE_LOCK_DEFERRED) { |
507 | ret = nlmsvc_defer_lock_rqst(rqstp, block); | 520 | ret = nlmsvc_defer_lock_rqst(rqstp, block); |
@@ -582,6 +595,9 @@ nlmsvc_cancel_blocked(struct nlm_file *file, struct nlm_lock *lock) | |||
582 | (long long)lock->fl.fl_start, | 595 | (long long)lock->fl.fl_start, |
583 | (long long)lock->fl.fl_end); | 596 | (long long)lock->fl.fl_end); |
584 | 597 | ||
598 | if (locks_in_grace()) | ||
599 | return nlm_lck_denied_grace_period; | ||
600 | |||
585 | mutex_lock(&file->f_mutex); | 601 | mutex_lock(&file->f_mutex); |
586 | block = nlmsvc_lookup_block(file, lock); | 602 | block = nlmsvc_lookup_block(file, lock); |
587 | mutex_unlock(&file->f_mutex); | 603 | mutex_unlock(&file->f_mutex); |
diff --git a/fs/lockd/svcproc.c b/fs/lockd/svcproc.c index 76262c1986f2..548b0bb2b84d 100644 --- a/fs/lockd/svcproc.c +++ b/fs/lockd/svcproc.c | |||
@@ -117,12 +117,6 @@ nlmsvc_proc_test(struct svc_rqst *rqstp, struct nlm_args *argp, | |||
117 | dprintk("lockd: TEST called\n"); | 117 | dprintk("lockd: TEST called\n"); |
118 | resp->cookie = argp->cookie; | 118 | resp->cookie = argp->cookie; |
119 | 119 | ||
120 | /* Don't accept test requests during grace period */ | ||
121 | if (nlmsvc_grace_period) { | ||
122 | resp->status = nlm_lck_denied_grace_period; | ||
123 | return rc; | ||
124 | } | ||
125 | |||
126 | /* Obtain client and file */ | 120 | /* Obtain client and file */ |
127 | if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file))) | 121 | if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file))) |
128 | return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; | 122 | return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; |
@@ -152,12 +146,6 @@ nlmsvc_proc_lock(struct svc_rqst *rqstp, struct nlm_args *argp, | |||
152 | 146 | ||
153 | resp->cookie = argp->cookie; | 147 | resp->cookie = argp->cookie; |
154 | 148 | ||
155 | /* Don't accept new lock requests during grace period */ | ||
156 | if (nlmsvc_grace_period && !argp->reclaim) { | ||
157 | resp->status = nlm_lck_denied_grace_period; | ||
158 | return rc; | ||
159 | } | ||
160 | |||
161 | /* Obtain client and file */ | 149 | /* Obtain client and file */ |
162 | if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file))) | 150 | if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file))) |
163 | return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; | 151 | return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; |
@@ -176,7 +164,8 @@ nlmsvc_proc_lock(struct svc_rqst *rqstp, struct nlm_args *argp, | |||
176 | 164 | ||
177 | /* Now try to lock the file */ | 165 | /* Now try to lock the file */ |
178 | resp->status = cast_status(nlmsvc_lock(rqstp, file, host, &argp->lock, | 166 | resp->status = cast_status(nlmsvc_lock(rqstp, file, host, &argp->lock, |
179 | argp->block, &argp->cookie)); | 167 | argp->block, &argp->cookie, |
168 | argp->reclaim)); | ||
180 | if (resp->status == nlm_drop_reply) | 169 | if (resp->status == nlm_drop_reply) |
181 | rc = rpc_drop_reply; | 170 | rc = rpc_drop_reply; |
182 | else | 171 | else |
@@ -199,7 +188,7 @@ nlmsvc_proc_cancel(struct svc_rqst *rqstp, struct nlm_args *argp, | |||
199 | resp->cookie = argp->cookie; | 188 | resp->cookie = argp->cookie; |
200 | 189 | ||
201 | /* Don't accept requests during grace period */ | 190 | /* Don't accept requests during grace period */ |
202 | if (nlmsvc_grace_period) { | 191 | if (locks_in_grace()) { |
203 | resp->status = nlm_lck_denied_grace_period; | 192 | resp->status = nlm_lck_denied_grace_period; |
204 | return rpc_success; | 193 | return rpc_success; |
205 | } | 194 | } |
@@ -232,7 +221,7 @@ nlmsvc_proc_unlock(struct svc_rqst *rqstp, struct nlm_args *argp, | |||
232 | resp->cookie = argp->cookie; | 221 | resp->cookie = argp->cookie; |
233 | 222 | ||
234 | /* Don't accept new lock requests during grace period */ | 223 | /* Don't accept new lock requests during grace period */ |
235 | if (nlmsvc_grace_period) { | 224 | if (locks_in_grace()) { |
236 | resp->status = nlm_lck_denied_grace_period; | 225 | resp->status = nlm_lck_denied_grace_period; |
237 | return rpc_success; | 226 | return rpc_success; |
238 | } | 227 | } |
@@ -261,7 +250,7 @@ nlmsvc_proc_granted(struct svc_rqst *rqstp, struct nlm_args *argp, | |||
261 | resp->cookie = argp->cookie; | 250 | resp->cookie = argp->cookie; |
262 | 251 | ||
263 | dprintk("lockd: GRANTED called\n"); | 252 | dprintk("lockd: GRANTED called\n"); |
264 | resp->status = nlmclnt_grant(svc_addr_in(rqstp), &argp->lock); | 253 | resp->status = nlmclnt_grant(svc_addr(rqstp), &argp->lock); |
265 | dprintk("lockd: GRANTED status %d\n", ntohl(resp->status)); | 254 | dprintk("lockd: GRANTED status %d\n", ntohl(resp->status)); |
266 | return rpc_success; | 255 | return rpc_success; |
267 | } | 256 | } |
@@ -373,7 +362,7 @@ nlmsvc_proc_share(struct svc_rqst *rqstp, struct nlm_args *argp, | |||
373 | resp->cookie = argp->cookie; | 362 | resp->cookie = argp->cookie; |
374 | 363 | ||
375 | /* Don't accept new lock requests during grace period */ | 364 | /* Don't accept new lock requests during grace period */ |
376 | if (nlmsvc_grace_period && !argp->reclaim) { | 365 | if (locks_in_grace() && !argp->reclaim) { |
377 | resp->status = nlm_lck_denied_grace_period; | 366 | resp->status = nlm_lck_denied_grace_period; |
378 | return rpc_success; | 367 | return rpc_success; |
379 | } | 368 | } |
@@ -406,7 +395,7 @@ nlmsvc_proc_unshare(struct svc_rqst *rqstp, struct nlm_args *argp, | |||
406 | resp->cookie = argp->cookie; | 395 | resp->cookie = argp->cookie; |
407 | 396 | ||
408 | /* Don't accept requests during grace period */ | 397 | /* Don't accept requests during grace period */ |
409 | if (nlmsvc_grace_period) { | 398 | if (locks_in_grace()) { |
410 | resp->status = nlm_lck_denied_grace_period; | 399 | resp->status = nlm_lck_denied_grace_period; |
411 | return rpc_success; | 400 | return rpc_success; |
412 | } | 401 | } |
@@ -464,11 +453,9 @@ nlmsvc_proc_sm_notify(struct svc_rqst *rqstp, struct nlm_reboot *argp, | |||
464 | { | 453 | { |
465 | struct sockaddr_in saddr; | 454 | struct sockaddr_in saddr; |
466 | 455 | ||
467 | memcpy(&saddr, svc_addr_in(rqstp), sizeof(saddr)); | ||
468 | |||
469 | dprintk("lockd: SM_NOTIFY called\n"); | 456 | dprintk("lockd: SM_NOTIFY called\n"); |
470 | if (saddr.sin_addr.s_addr != htonl(INADDR_LOOPBACK) | 457 | |
471 | || ntohs(saddr.sin_port) >= 1024) { | 458 | if (!nlm_privileged_requester(rqstp)) { |
472 | char buf[RPC_MAX_ADDRBUFLEN]; | 459 | char buf[RPC_MAX_ADDRBUFLEN]; |
473 | printk(KERN_WARNING "lockd: rejected NSM callback from %s\n", | 460 | printk(KERN_WARNING "lockd: rejected NSM callback from %s\n", |
474 | svc_print_addr(rqstp, buf, sizeof(buf))); | 461 | svc_print_addr(rqstp, buf, sizeof(buf))); |
diff --git a/fs/lockd/svcsubs.c b/fs/lockd/svcsubs.c index 198b4e55b373..34c2766e27c7 100644 --- a/fs/lockd/svcsubs.c +++ b/fs/lockd/svcsubs.c | |||
@@ -418,7 +418,7 @@ EXPORT_SYMBOL_GPL(nlmsvc_unlock_all_by_sb); | |||
418 | static int | 418 | static int |
419 | nlmsvc_match_ip(void *datap, struct nlm_host *host) | 419 | nlmsvc_match_ip(void *datap, struct nlm_host *host) |
420 | { | 420 | { |
421 | return nlm_cmp_addr(&host->h_saddr, datap); | 421 | return nlm_cmp_addr(nlm_srcaddr(host), datap); |
422 | } | 422 | } |
423 | 423 | ||
424 | /** | 424 | /** |
diff --git a/fs/lockd/xdr.c b/fs/lockd/xdr.c index 3e459e18cc31..1f226290c67c 100644 --- a/fs/lockd/xdr.c +++ b/fs/lockd/xdr.c | |||
@@ -351,8 +351,6 @@ nlmsvc_decode_reboot(struct svc_rqst *rqstp, __be32 *p, struct nlm_reboot *argp) | |||
351 | argp->state = ntohl(*p++); | 351 | argp->state = ntohl(*p++); |
352 | /* Preserve the address in network byte order */ | 352 | /* Preserve the address in network byte order */ |
353 | argp->addr = *p++; | 353 | argp->addr = *p++; |
354 | argp->vers = *p++; | ||
355 | argp->proto = *p++; | ||
356 | return xdr_argsize_check(rqstp, p); | 354 | return xdr_argsize_check(rqstp, p); |
357 | } | 355 | } |
358 | 356 | ||
diff --git a/fs/lockd/xdr4.c b/fs/lockd/xdr4.c index 43ff9397e6c6..50c493a8ad8e 100644 --- a/fs/lockd/xdr4.c +++ b/fs/lockd/xdr4.c | |||
@@ -358,8 +358,6 @@ nlm4svc_decode_reboot(struct svc_rqst *rqstp, __be32 *p, struct nlm_reboot *argp | |||
358 | argp->state = ntohl(*p++); | 358 | argp->state = ntohl(*p++); |
359 | /* Preserve the address in network byte order */ | 359 | /* Preserve the address in network byte order */ |
360 | argp->addr = *p++; | 360 | argp->addr = *p++; |
361 | argp->vers = *p++; | ||
362 | argp->proto = *p++; | ||
363 | return xdr_argsize_check(rqstp, p); | 361 | return xdr_argsize_check(rqstp, p); |
364 | } | 362 | } |
365 | 363 | ||
diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c index f447f4b4476c..6a09760c5960 100644 --- a/fs/nfs/callback.c +++ b/fs/nfs/callback.c | |||
@@ -105,7 +105,8 @@ int nfs_callback_up(void) | |||
105 | mutex_lock(&nfs_callback_mutex); | 105 | mutex_lock(&nfs_callback_mutex); |
106 | if (nfs_callback_info.users++ || nfs_callback_info.task != NULL) | 106 | if (nfs_callback_info.users++ || nfs_callback_info.task != NULL) |
107 | goto out; | 107 | goto out; |
108 | serv = svc_create(&nfs4_callback_program, NFS4_CALLBACK_BUFSIZE, NULL); | 108 | serv = svc_create(&nfs4_callback_program, NFS4_CALLBACK_BUFSIZE, |
109 | AF_INET, NULL); | ||
109 | ret = -ENOMEM; | 110 | ret = -ENOMEM; |
110 | if (!serv) | 111 | if (!serv) |
111 | goto out_err; | 112 | goto out_err; |
diff --git a/fs/nfsd/lockd.c b/fs/nfsd/lockd.c index 15c6faeec77c..b2786a5f9afe 100644 --- a/fs/nfsd/lockd.c +++ b/fs/nfsd/lockd.c | |||
@@ -70,7 +70,6 @@ nlm_fclose(struct file *filp) | |||
70 | static struct nlmsvc_binding nfsd_nlm_ops = { | 70 | static struct nlmsvc_binding nfsd_nlm_ops = { |
71 | .fopen = nlm_fopen, /* open file for locking */ | 71 | .fopen = nlm_fopen, /* open file for locking */ |
72 | .fclose = nlm_fclose, /* close file */ | 72 | .fclose = nlm_fclose, /* close file */ |
73 | .get_grace_period = get_nfs4_grace_period, | ||
74 | }; | 73 | }; |
75 | 74 | ||
76 | void | 75 | void |
diff --git a/fs/nfsd/nfs3proc.c b/fs/nfsd/nfs3proc.c index 4d617ea28cfc..9dbd2eb91281 100644 --- a/fs/nfsd/nfs3proc.c +++ b/fs/nfsd/nfs3proc.c | |||
@@ -63,7 +63,8 @@ nfsd3_proc_getattr(struct svc_rqst *rqstp, struct nfsd_fhandle *argp, | |||
63 | SVCFH_fmt(&argp->fh)); | 63 | SVCFH_fmt(&argp->fh)); |
64 | 64 | ||
65 | fh_copy(&resp->fh, &argp->fh); | 65 | fh_copy(&resp->fh, &argp->fh); |
66 | nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP); | 66 | nfserr = fh_verify(rqstp, &resp->fh, 0, |
67 | NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT); | ||
67 | if (nfserr) | 68 | if (nfserr) |
68 | RETURN_STATUS(nfserr); | 69 | RETURN_STATUS(nfserr); |
69 | 70 | ||
@@ -530,7 +531,7 @@ nfsd3_proc_fsstat(struct svc_rqst * rqstp, struct nfsd_fhandle *argp, | |||
530 | dprintk("nfsd: FSSTAT(3) %s\n", | 531 | dprintk("nfsd: FSSTAT(3) %s\n", |
531 | SVCFH_fmt(&argp->fh)); | 532 | SVCFH_fmt(&argp->fh)); |
532 | 533 | ||
533 | nfserr = nfsd_statfs(rqstp, &argp->fh, &resp->stats); | 534 | nfserr = nfsd_statfs(rqstp, &argp->fh, &resp->stats, 0); |
534 | fh_put(&argp->fh); | 535 | fh_put(&argp->fh); |
535 | RETURN_STATUS(nfserr); | 536 | RETURN_STATUS(nfserr); |
536 | } | 537 | } |
@@ -558,7 +559,8 @@ nfsd3_proc_fsinfo(struct svc_rqst * rqstp, struct nfsd_fhandle *argp, | |||
558 | resp->f_maxfilesize = ~(u32) 0; | 559 | resp->f_maxfilesize = ~(u32) 0; |
559 | resp->f_properties = NFS3_FSF_DEFAULT; | 560 | resp->f_properties = NFS3_FSF_DEFAULT; |
560 | 561 | ||
561 | nfserr = fh_verify(rqstp, &argp->fh, 0, NFSD_MAY_NOP); | 562 | nfserr = fh_verify(rqstp, &argp->fh, 0, |
563 | NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT); | ||
562 | 564 | ||
563 | /* Check special features of the file system. May request | 565 | /* Check special features of the file system. May request |
564 | * different read/write sizes for file systems known to have | 566 | * different read/write sizes for file systems known to have |
diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c index 702fa577aa6e..094747a1227c 100644 --- a/fs/nfsd/nfs4callback.c +++ b/fs/nfsd/nfs4callback.c | |||
@@ -225,7 +225,8 @@ encode_cb_recall(struct xdr_stream *xdr, struct nfs4_cb_recall *cb_rec) | |||
225 | 225 | ||
226 | RESERVE_SPACE(12+sizeof(cb_rec->cbr_stateid) + len); | 226 | RESERVE_SPACE(12+sizeof(cb_rec->cbr_stateid) + len); |
227 | WRITE32(OP_CB_RECALL); | 227 | WRITE32(OP_CB_RECALL); |
228 | WRITEMEM(&cb_rec->cbr_stateid, sizeof(stateid_t)); | 228 | WRITE32(cb_rec->cbr_stateid.si_generation); |
229 | WRITEMEM(&cb_rec->cbr_stateid.si_opaque, sizeof(stateid_opaque_t)); | ||
229 | WRITE32(cb_rec->cbr_trunc); | 230 | WRITE32(cb_rec->cbr_trunc); |
230 | WRITE32(len); | 231 | WRITE32(len); |
231 | WRITEMEM(cb_rec->cbr_fhval, len); | 232 | WRITEMEM(cb_rec->cbr_fhval, len); |
@@ -379,6 +380,7 @@ static int do_probe_callback(void *data) | |||
379 | .addrsize = sizeof(addr), | 380 | .addrsize = sizeof(addr), |
380 | .timeout = &timeparms, | 381 | .timeout = &timeparms, |
381 | .program = &cb_program, | 382 | .program = &cb_program, |
383 | .prognumber = cb->cb_prog, | ||
382 | .version = nfs_cb_version[1]->number, | 384 | .version = nfs_cb_version[1]->number, |
383 | .authflavor = RPC_AUTH_UNIX, /* XXX: need AUTH_GSS... */ | 385 | .authflavor = RPC_AUTH_UNIX, /* XXX: need AUTH_GSS... */ |
384 | .flags = (RPC_CLNT_CREATE_NOPING | RPC_CLNT_CREATE_QUIET), | 386 | .flags = (RPC_CLNT_CREATE_NOPING | RPC_CLNT_CREATE_QUIET), |
@@ -396,9 +398,6 @@ static int do_probe_callback(void *data) | |||
396 | addr.sin_port = htons(cb->cb_port); | 398 | addr.sin_port = htons(cb->cb_port); |
397 | addr.sin_addr.s_addr = htonl(cb->cb_addr); | 399 | addr.sin_addr.s_addr = htonl(cb->cb_addr); |
398 | 400 | ||
399 | /* Initialize rpc_stat */ | ||
400 | memset(args.program->stats, 0, sizeof(struct rpc_stat)); | ||
401 | |||
402 | /* Create RPC client */ | 401 | /* Create RPC client */ |
403 | client = rpc_create(&args); | 402 | client = rpc_create(&args); |
404 | if (IS_ERR(client)) { | 403 | if (IS_ERR(client)) { |
diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index e5b51ffafc6c..669461e291ae 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c | |||
@@ -201,10 +201,10 @@ nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, | |||
201 | /* Openowner is now set, so sequence id will get bumped. Now we need | 201 | /* Openowner is now set, so sequence id will get bumped. Now we need |
202 | * these checks before we do any creates: */ | 202 | * these checks before we do any creates: */ |
203 | status = nfserr_grace; | 203 | status = nfserr_grace; |
204 | if (nfs4_in_grace() && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS) | 204 | if (locks_in_grace() && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS) |
205 | goto out; | 205 | goto out; |
206 | status = nfserr_no_grace; | 206 | status = nfserr_no_grace; |
207 | if (!nfs4_in_grace() && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS) | 207 | if (!locks_in_grace() && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS) |
208 | goto out; | 208 | goto out; |
209 | 209 | ||
210 | switch (open->op_claim_type) { | 210 | switch (open->op_claim_type) { |
@@ -575,7 +575,7 @@ nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, | |||
575 | { | 575 | { |
576 | __be32 status; | 576 | __be32 status; |
577 | 577 | ||
578 | if (nfs4_in_grace()) | 578 | if (locks_in_grace()) |
579 | return nfserr_grace; | 579 | return nfserr_grace; |
580 | status = nfsd_unlink(rqstp, &cstate->current_fh, 0, | 580 | status = nfsd_unlink(rqstp, &cstate->current_fh, 0, |
581 | remove->rm_name, remove->rm_namelen); | 581 | remove->rm_name, remove->rm_namelen); |
@@ -596,7 +596,7 @@ nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, | |||
596 | 596 | ||
597 | if (!cstate->save_fh.fh_dentry) | 597 | if (!cstate->save_fh.fh_dentry) |
598 | return status; | 598 | return status; |
599 | if (nfs4_in_grace() && !(cstate->save_fh.fh_export->ex_flags | 599 | if (locks_in_grace() && !(cstate->save_fh.fh_export->ex_flags |
600 | & NFSEXP_NOSUBTREECHECK)) | 600 | & NFSEXP_NOSUBTREECHECK)) |
601 | return nfserr_grace; | 601 | return nfserr_grace; |
602 | status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname, | 602 | status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname, |
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 1578d7a2667e..0cc7ff5d5ab5 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c | |||
@@ -61,7 +61,6 @@ | |||
61 | static time_t lease_time = 90; /* default lease time */ | 61 | static time_t lease_time = 90; /* default lease time */ |
62 | static time_t user_lease_time = 90; | 62 | static time_t user_lease_time = 90; |
63 | static time_t boot_time; | 63 | static time_t boot_time; |
64 | static int in_grace = 1; | ||
65 | static u32 current_ownerid = 1; | 64 | static u32 current_ownerid = 1; |
66 | static u32 current_fileid = 1; | 65 | static u32 current_fileid = 1; |
67 | static u32 current_delegid = 1; | 66 | static u32 current_delegid = 1; |
@@ -1640,7 +1639,7 @@ nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open, struct nfs4_sta | |||
1640 | case NFS4_OPEN_CLAIM_NULL: | 1639 | case NFS4_OPEN_CLAIM_NULL: |
1641 | /* Let's not give out any delegations till everyone's | 1640 | /* Let's not give out any delegations till everyone's |
1642 | * had the chance to reclaim theirs.... */ | 1641 | * had the chance to reclaim theirs.... */ |
1643 | if (nfs4_in_grace()) | 1642 | if (locks_in_grace()) |
1644 | goto out; | 1643 | goto out; |
1645 | if (!atomic_read(&cb->cb_set) || !sop->so_confirmed) | 1644 | if (!atomic_read(&cb->cb_set) || !sop->so_confirmed) |
1646 | goto out; | 1645 | goto out; |
@@ -1816,12 +1815,15 @@ out: | |||
1816 | return status; | 1815 | return status; |
1817 | } | 1816 | } |
1818 | 1817 | ||
1818 | struct lock_manager nfsd4_manager = { | ||
1819 | }; | ||
1820 | |||
1819 | static void | 1821 | static void |
1820 | end_grace(void) | 1822 | nfsd4_end_grace(void) |
1821 | { | 1823 | { |
1822 | dprintk("NFSD: end of grace period\n"); | 1824 | dprintk("NFSD: end of grace period\n"); |
1823 | nfsd4_recdir_purge_old(); | 1825 | nfsd4_recdir_purge_old(); |
1824 | in_grace = 0; | 1826 | locks_end_grace(&nfsd4_manager); |
1825 | } | 1827 | } |
1826 | 1828 | ||
1827 | static time_t | 1829 | static time_t |
@@ -1838,8 +1840,8 @@ nfs4_laundromat(void) | |||
1838 | nfs4_lock_state(); | 1840 | nfs4_lock_state(); |
1839 | 1841 | ||
1840 | dprintk("NFSD: laundromat service - starting\n"); | 1842 | dprintk("NFSD: laundromat service - starting\n"); |
1841 | if (in_grace) | 1843 | if (locks_in_grace()) |
1842 | end_grace(); | 1844 | nfsd4_end_grace(); |
1843 | list_for_each_safe(pos, next, &client_lru) { | 1845 | list_for_each_safe(pos, next, &client_lru) { |
1844 | clp = list_entry(pos, struct nfs4_client, cl_lru); | 1846 | clp = list_entry(pos, struct nfs4_client, cl_lru); |
1845 | if (time_after((unsigned long)clp->cl_time, (unsigned long)cutoff)) { | 1847 | if (time_after((unsigned long)clp->cl_time, (unsigned long)cutoff)) { |
@@ -1974,7 +1976,7 @@ check_special_stateids(svc_fh *current_fh, stateid_t *stateid, int flags) | |||
1974 | return nfserr_bad_stateid; | 1976 | return nfserr_bad_stateid; |
1975 | else if (ONE_STATEID(stateid) && (flags & RD_STATE)) | 1977 | else if (ONE_STATEID(stateid) && (flags & RD_STATE)) |
1976 | return nfs_ok; | 1978 | return nfs_ok; |
1977 | else if (nfs4_in_grace()) { | 1979 | else if (locks_in_grace()) { |
1978 | /* Answer in remaining cases depends on existance of | 1980 | /* Answer in remaining cases depends on existance of |
1979 | * conflicting state; so we must wait out the grace period. */ | 1981 | * conflicting state; so we must wait out the grace period. */ |
1980 | return nfserr_grace; | 1982 | return nfserr_grace; |
@@ -1993,7 +1995,7 @@ check_special_stateids(svc_fh *current_fh, stateid_t *stateid, int flags) | |||
1993 | static inline int | 1995 | static inline int |
1994 | io_during_grace_disallowed(struct inode *inode, int flags) | 1996 | io_during_grace_disallowed(struct inode *inode, int flags) |
1995 | { | 1997 | { |
1996 | return nfs4_in_grace() && (flags & (RD_STATE | WR_STATE)) | 1998 | return locks_in_grace() && (flags & (RD_STATE | WR_STATE)) |
1997 | && mandatory_lock(inode); | 1999 | && mandatory_lock(inode); |
1998 | } | 2000 | } |
1999 | 2001 | ||
@@ -2693,10 +2695,10 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, | |||
2693 | filp = lock_stp->st_vfs_file; | 2695 | filp = lock_stp->st_vfs_file; |
2694 | 2696 | ||
2695 | status = nfserr_grace; | 2697 | status = nfserr_grace; |
2696 | if (nfs4_in_grace() && !lock->lk_reclaim) | 2698 | if (locks_in_grace() && !lock->lk_reclaim) |
2697 | goto out; | 2699 | goto out; |
2698 | status = nfserr_no_grace; | 2700 | status = nfserr_no_grace; |
2699 | if (!nfs4_in_grace() && lock->lk_reclaim) | 2701 | if (!locks_in_grace() && lock->lk_reclaim) |
2700 | goto out; | 2702 | goto out; |
2701 | 2703 | ||
2702 | locks_init_lock(&file_lock); | 2704 | locks_init_lock(&file_lock); |
@@ -2779,7 +2781,7 @@ nfsd4_lockt(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, | |||
2779 | int error; | 2781 | int error; |
2780 | __be32 status; | 2782 | __be32 status; |
2781 | 2783 | ||
2782 | if (nfs4_in_grace()) | 2784 | if (locks_in_grace()) |
2783 | return nfserr_grace; | 2785 | return nfserr_grace; |
2784 | 2786 | ||
2785 | if (check_lock_length(lockt->lt_offset, lockt->lt_length)) | 2787 | if (check_lock_length(lockt->lt_offset, lockt->lt_length)) |
@@ -3192,9 +3194,9 @@ __nfs4_state_start(void) | |||
3192 | unsigned long grace_time; | 3194 | unsigned long grace_time; |
3193 | 3195 | ||
3194 | boot_time = get_seconds(); | 3196 | boot_time = get_seconds(); |
3195 | grace_time = get_nfs_grace_period(); | 3197 | grace_time = get_nfs4_grace_period(); |
3196 | lease_time = user_lease_time; | 3198 | lease_time = user_lease_time; |
3197 | in_grace = 1; | 3199 | locks_start_grace(&nfsd4_manager); |
3198 | printk(KERN_INFO "NFSD: starting %ld-second grace period\n", | 3200 | printk(KERN_INFO "NFSD: starting %ld-second grace period\n", |
3199 | grace_time/HZ); | 3201 | grace_time/HZ); |
3200 | laundry_wq = create_singlethread_workqueue("nfsd4"); | 3202 | laundry_wq = create_singlethread_workqueue("nfsd4"); |
@@ -3213,12 +3215,6 @@ nfs4_state_start(void) | |||
3213 | return; | 3215 | return; |
3214 | } | 3216 | } |
3215 | 3217 | ||
3216 | int | ||
3217 | nfs4_in_grace(void) | ||
3218 | { | ||
3219 | return in_grace; | ||
3220 | } | ||
3221 | |||
3222 | time_t | 3218 | time_t |
3223 | nfs4_lease_time(void) | 3219 | nfs4_lease_time(void) |
3224 | { | 3220 | { |
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 14ba4d9b2859..afcdf4b76843 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c | |||
@@ -413,6 +413,18 @@ out_nfserr: | |||
413 | } | 413 | } |
414 | 414 | ||
415 | static __be32 | 415 | static __be32 |
416 | nfsd4_decode_stateid(struct nfsd4_compoundargs *argp, stateid_t *sid) | ||
417 | { | ||
418 | DECODE_HEAD; | ||
419 | |||
420 | READ_BUF(sizeof(stateid_t)); | ||
421 | READ32(sid->si_generation); | ||
422 | COPYMEM(&sid->si_opaque, sizeof(stateid_opaque_t)); | ||
423 | |||
424 | DECODE_TAIL; | ||
425 | } | ||
426 | |||
427 | static __be32 | ||
416 | nfsd4_decode_access(struct nfsd4_compoundargs *argp, struct nfsd4_access *access) | 428 | nfsd4_decode_access(struct nfsd4_compoundargs *argp, struct nfsd4_access *access) |
417 | { | 429 | { |
418 | DECODE_HEAD; | 430 | DECODE_HEAD; |
@@ -429,10 +441,9 @@ nfsd4_decode_close(struct nfsd4_compoundargs *argp, struct nfsd4_close *close) | |||
429 | DECODE_HEAD; | 441 | DECODE_HEAD; |
430 | 442 | ||
431 | close->cl_stateowner = NULL; | 443 | close->cl_stateowner = NULL; |
432 | READ_BUF(4 + sizeof(stateid_t)); | 444 | READ_BUF(4); |
433 | READ32(close->cl_seqid); | 445 | READ32(close->cl_seqid); |
434 | READ32(close->cl_stateid.si_generation); | 446 | return nfsd4_decode_stateid(argp, &close->cl_stateid); |
435 | COPYMEM(&close->cl_stateid.si_opaque, sizeof(stateid_opaque_t)); | ||
436 | 447 | ||
437 | DECODE_TAIL; | 448 | DECODE_TAIL; |
438 | } | 449 | } |
@@ -493,13 +504,7 @@ nfsd4_decode_create(struct nfsd4_compoundargs *argp, struct nfsd4_create *create | |||
493 | static inline __be32 | 504 | static inline __be32 |
494 | nfsd4_decode_delegreturn(struct nfsd4_compoundargs *argp, struct nfsd4_delegreturn *dr) | 505 | nfsd4_decode_delegreturn(struct nfsd4_compoundargs *argp, struct nfsd4_delegreturn *dr) |
495 | { | 506 | { |
496 | DECODE_HEAD; | 507 | return nfsd4_decode_stateid(argp, &dr->dr_stateid); |
497 | |||
498 | READ_BUF(sizeof(stateid_t)); | ||
499 | READ32(dr->dr_stateid.si_generation); | ||
500 | COPYMEM(&dr->dr_stateid.si_opaque, sizeof(stateid_opaque_t)); | ||
501 | |||
502 | DECODE_TAIL; | ||
503 | } | 508 | } |
504 | 509 | ||
505 | static inline __be32 | 510 | static inline __be32 |
@@ -542,20 +547,22 @@ nfsd4_decode_lock(struct nfsd4_compoundargs *argp, struct nfsd4_lock *lock) | |||
542 | READ32(lock->lk_is_new); | 547 | READ32(lock->lk_is_new); |
543 | 548 | ||
544 | if (lock->lk_is_new) { | 549 | if (lock->lk_is_new) { |
545 | READ_BUF(36); | 550 | READ_BUF(4); |
546 | READ32(lock->lk_new_open_seqid); | 551 | READ32(lock->lk_new_open_seqid); |
547 | READ32(lock->lk_new_open_stateid.si_generation); | 552 | status = nfsd4_decode_stateid(argp, &lock->lk_new_open_stateid); |
548 | 553 | if (status) | |
549 | COPYMEM(&lock->lk_new_open_stateid.si_opaque, sizeof(stateid_opaque_t)); | 554 | return status; |
555 | READ_BUF(8 + sizeof(clientid_t)); | ||
550 | READ32(lock->lk_new_lock_seqid); | 556 | READ32(lock->lk_new_lock_seqid); |
551 | COPYMEM(&lock->lk_new_clientid, sizeof(clientid_t)); | 557 | COPYMEM(&lock->lk_new_clientid, sizeof(clientid_t)); |
552 | READ32(lock->lk_new_owner.len); | 558 | READ32(lock->lk_new_owner.len); |
553 | READ_BUF(lock->lk_new_owner.len); | 559 | READ_BUF(lock->lk_new_owner.len); |
554 | READMEM(lock->lk_new_owner.data, lock->lk_new_owner.len); | 560 | READMEM(lock->lk_new_owner.data, lock->lk_new_owner.len); |
555 | } else { | 561 | } else { |
556 | READ_BUF(20); | 562 | status = nfsd4_decode_stateid(argp, &lock->lk_old_lock_stateid); |
557 | READ32(lock->lk_old_lock_stateid.si_generation); | 563 | if (status) |
558 | COPYMEM(&lock->lk_old_lock_stateid.si_opaque, sizeof(stateid_opaque_t)); | 564 | return status; |
565 | READ_BUF(4); | ||
559 | READ32(lock->lk_old_lock_seqid); | 566 | READ32(lock->lk_old_lock_seqid); |
560 | } | 567 | } |
561 | 568 | ||
@@ -587,13 +594,15 @@ nfsd4_decode_locku(struct nfsd4_compoundargs *argp, struct nfsd4_locku *locku) | |||
587 | DECODE_HEAD; | 594 | DECODE_HEAD; |
588 | 595 | ||
589 | locku->lu_stateowner = NULL; | 596 | locku->lu_stateowner = NULL; |
590 | READ_BUF(24 + sizeof(stateid_t)); | 597 | READ_BUF(8); |
591 | READ32(locku->lu_type); | 598 | READ32(locku->lu_type); |
592 | if ((locku->lu_type < NFS4_READ_LT) || (locku->lu_type > NFS4_WRITEW_LT)) | 599 | if ((locku->lu_type < NFS4_READ_LT) || (locku->lu_type > NFS4_WRITEW_LT)) |
593 | goto xdr_error; | 600 | goto xdr_error; |
594 | READ32(locku->lu_seqid); | 601 | READ32(locku->lu_seqid); |
595 | READ32(locku->lu_stateid.si_generation); | 602 | status = nfsd4_decode_stateid(argp, &locku->lu_stateid); |
596 | COPYMEM(&locku->lu_stateid.si_opaque, sizeof(stateid_opaque_t)); | 603 | if (status) |
604 | return status; | ||
605 | READ_BUF(16); | ||
597 | READ64(locku->lu_offset); | 606 | READ64(locku->lu_offset); |
598 | READ64(locku->lu_length); | 607 | READ64(locku->lu_length); |
599 | 608 | ||
@@ -678,8 +687,10 @@ nfsd4_decode_open(struct nfsd4_compoundargs *argp, struct nfsd4_open *open) | |||
678 | READ32(open->op_delegate_type); | 687 | READ32(open->op_delegate_type); |
679 | break; | 688 | break; |
680 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: | 689 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
681 | READ_BUF(sizeof(stateid_t) + 4); | 690 | status = nfsd4_decode_stateid(argp, &open->op_delegate_stateid); |
682 | COPYMEM(&open->op_delegate_stateid, sizeof(stateid_t)); | 691 | if (status) |
692 | return status; | ||
693 | READ_BUF(4); | ||
683 | READ32(open->op_fname.len); | 694 | READ32(open->op_fname.len); |
684 | READ_BUF(open->op_fname.len); | 695 | READ_BUF(open->op_fname.len); |
685 | SAVEMEM(open->op_fname.data, open->op_fname.len); | 696 | SAVEMEM(open->op_fname.data, open->op_fname.len); |
@@ -699,9 +710,10 @@ nfsd4_decode_open_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_open_con | |||
699 | DECODE_HEAD; | 710 | DECODE_HEAD; |
700 | 711 | ||
701 | open_conf->oc_stateowner = NULL; | 712 | open_conf->oc_stateowner = NULL; |
702 | READ_BUF(4 + sizeof(stateid_t)); | 713 | status = nfsd4_decode_stateid(argp, &open_conf->oc_req_stateid); |
703 | READ32(open_conf->oc_req_stateid.si_generation); | 714 | if (status) |
704 | COPYMEM(&open_conf->oc_req_stateid.si_opaque, sizeof(stateid_opaque_t)); | 715 | return status; |
716 | READ_BUF(4); | ||
705 | READ32(open_conf->oc_seqid); | 717 | READ32(open_conf->oc_seqid); |
706 | 718 | ||
707 | DECODE_TAIL; | 719 | DECODE_TAIL; |
@@ -713,9 +725,10 @@ nfsd4_decode_open_downgrade(struct nfsd4_compoundargs *argp, struct nfsd4_open_d | |||
713 | DECODE_HEAD; | 725 | DECODE_HEAD; |
714 | 726 | ||
715 | open_down->od_stateowner = NULL; | 727 | open_down->od_stateowner = NULL; |
716 | READ_BUF(12 + sizeof(stateid_t)); | 728 | status = nfsd4_decode_stateid(argp, &open_down->od_stateid); |
717 | READ32(open_down->od_stateid.si_generation); | 729 | if (status) |
718 | COPYMEM(&open_down->od_stateid.si_opaque, sizeof(stateid_opaque_t)); | 730 | return status; |
731 | READ_BUF(12); | ||
719 | READ32(open_down->od_seqid); | 732 | READ32(open_down->od_seqid); |
720 | READ32(open_down->od_share_access); | 733 | READ32(open_down->od_share_access); |
721 | READ32(open_down->od_share_deny); | 734 | READ32(open_down->od_share_deny); |
@@ -743,9 +756,10 @@ nfsd4_decode_read(struct nfsd4_compoundargs *argp, struct nfsd4_read *read) | |||
743 | { | 756 | { |
744 | DECODE_HEAD; | 757 | DECODE_HEAD; |
745 | 758 | ||
746 | READ_BUF(sizeof(stateid_t) + 12); | 759 | status = nfsd4_decode_stateid(argp, &read->rd_stateid); |
747 | READ32(read->rd_stateid.si_generation); | 760 | if (status) |
748 | COPYMEM(&read->rd_stateid.si_opaque, sizeof(stateid_opaque_t)); | 761 | return status; |
762 | READ_BUF(12); | ||
749 | READ64(read->rd_offset); | 763 | READ64(read->rd_offset); |
750 | READ32(read->rd_length); | 764 | READ32(read->rd_length); |
751 | 765 | ||
@@ -834,15 +848,13 @@ nfsd4_decode_secinfo(struct nfsd4_compoundargs *argp, | |||
834 | static __be32 | 848 | static __be32 |
835 | nfsd4_decode_setattr(struct nfsd4_compoundargs *argp, struct nfsd4_setattr *setattr) | 849 | nfsd4_decode_setattr(struct nfsd4_compoundargs *argp, struct nfsd4_setattr *setattr) |
836 | { | 850 | { |
837 | DECODE_HEAD; | 851 | __be32 status; |
838 | |||
839 | READ_BUF(sizeof(stateid_t)); | ||
840 | READ32(setattr->sa_stateid.si_generation); | ||
841 | COPYMEM(&setattr->sa_stateid.si_opaque, sizeof(stateid_opaque_t)); | ||
842 | if ((status = nfsd4_decode_fattr(argp, setattr->sa_bmval, &setattr->sa_iattr, &setattr->sa_acl))) | ||
843 | goto out; | ||
844 | 852 | ||
845 | DECODE_TAIL; | 853 | status = nfsd4_decode_stateid(argp, &setattr->sa_stateid); |
854 | if (status) | ||
855 | return status; | ||
856 | return nfsd4_decode_fattr(argp, setattr->sa_bmval, | ||
857 | &setattr->sa_iattr, &setattr->sa_acl); | ||
846 | } | 858 | } |
847 | 859 | ||
848 | static __be32 | 860 | static __be32 |
@@ -927,9 +939,10 @@ nfsd4_decode_write(struct nfsd4_compoundargs *argp, struct nfsd4_write *write) | |||
927 | int len; | 939 | int len; |
928 | DECODE_HEAD; | 940 | DECODE_HEAD; |
929 | 941 | ||
930 | READ_BUF(sizeof(stateid_opaque_t) + 20); | 942 | status = nfsd4_decode_stateid(argp, &write->wr_stateid); |
931 | READ32(write->wr_stateid.si_generation); | 943 | if (status) |
932 | COPYMEM(&write->wr_stateid.si_opaque, sizeof(stateid_opaque_t)); | 944 | return status; |
945 | READ_BUF(16); | ||
933 | READ64(write->wr_offset); | 946 | READ64(write->wr_offset); |
934 | READ32(write->wr_stable_how); | 947 | READ32(write->wr_stable_how); |
935 | if (write->wr_stable_how > 2) | 948 | if (write->wr_stable_how > 2) |
@@ -1183,7 +1196,6 @@ nfsd4_decode_compound(struct nfsd4_compoundargs *argp) | |||
1183 | * Header routine to setup seqid operation replay cache | 1196 | * Header routine to setup seqid operation replay cache |
1184 | */ | 1197 | */ |
1185 | #define ENCODE_SEQID_OP_HEAD \ | 1198 | #define ENCODE_SEQID_OP_HEAD \ |
1186 | __be32 *p; \ | ||
1187 | __be32 *save; \ | 1199 | __be32 *save; \ |
1188 | \ | 1200 | \ |
1189 | save = resp->p; | 1201 | save = resp->p; |
@@ -1950,6 +1962,17 @@ fail: | |||
1950 | return -EINVAL; | 1962 | return -EINVAL; |
1951 | } | 1963 | } |
1952 | 1964 | ||
1965 | static void | ||
1966 | nfsd4_encode_stateid(struct nfsd4_compoundres *resp, stateid_t *sid) | ||
1967 | { | ||
1968 | ENCODE_HEAD; | ||
1969 | |||
1970 | RESERVE_SPACE(sizeof(stateid_t)); | ||
1971 | WRITE32(sid->si_generation); | ||
1972 | WRITEMEM(&sid->si_opaque, sizeof(stateid_opaque_t)); | ||
1973 | ADJUST_ARGS(); | ||
1974 | } | ||
1975 | |||
1953 | static __be32 | 1976 | static __be32 |
1954 | nfsd4_encode_access(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_access *access) | 1977 | nfsd4_encode_access(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_access *access) |
1955 | { | 1978 | { |
@@ -1969,12 +1992,9 @@ nfsd4_encode_close(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_c | |||
1969 | { | 1992 | { |
1970 | ENCODE_SEQID_OP_HEAD; | 1993 | ENCODE_SEQID_OP_HEAD; |
1971 | 1994 | ||
1972 | if (!nfserr) { | 1995 | if (!nfserr) |
1973 | RESERVE_SPACE(sizeof(stateid_t)); | 1996 | nfsd4_encode_stateid(resp, &close->cl_stateid); |
1974 | WRITE32(close->cl_stateid.si_generation); | 1997 | |
1975 | WRITEMEM(&close->cl_stateid.si_opaque, sizeof(stateid_opaque_t)); | ||
1976 | ADJUST_ARGS(); | ||
1977 | } | ||
1978 | ENCODE_SEQID_OP_TAIL(close->cl_stateowner); | 1998 | ENCODE_SEQID_OP_TAIL(close->cl_stateowner); |
1979 | return nfserr; | 1999 | return nfserr; |
1980 | } | 2000 | } |
@@ -2074,12 +2094,9 @@ nfsd4_encode_lock(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_lo | |||
2074 | { | 2094 | { |
2075 | ENCODE_SEQID_OP_HEAD; | 2095 | ENCODE_SEQID_OP_HEAD; |
2076 | 2096 | ||
2077 | if (!nfserr) { | 2097 | if (!nfserr) |
2078 | RESERVE_SPACE(4 + sizeof(stateid_t)); | 2098 | nfsd4_encode_stateid(resp, &lock->lk_resp_stateid); |
2079 | WRITE32(lock->lk_resp_stateid.si_generation); | 2099 | else if (nfserr == nfserr_denied) |
2080 | WRITEMEM(&lock->lk_resp_stateid.si_opaque, sizeof(stateid_opaque_t)); | ||
2081 | ADJUST_ARGS(); | ||
2082 | } else if (nfserr == nfserr_denied) | ||
2083 | nfsd4_encode_lock_denied(resp, &lock->lk_denied); | 2100 | nfsd4_encode_lock_denied(resp, &lock->lk_denied); |
2084 | 2101 | ||
2085 | ENCODE_SEQID_OP_TAIL(lock->lk_replay_owner); | 2102 | ENCODE_SEQID_OP_TAIL(lock->lk_replay_owner); |
@@ -2099,13 +2116,9 @@ nfsd4_encode_locku(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_l | |||
2099 | { | 2116 | { |
2100 | ENCODE_SEQID_OP_HEAD; | 2117 | ENCODE_SEQID_OP_HEAD; |
2101 | 2118 | ||
2102 | if (!nfserr) { | 2119 | if (!nfserr) |
2103 | RESERVE_SPACE(sizeof(stateid_t)); | 2120 | nfsd4_encode_stateid(resp, &locku->lu_stateid); |
2104 | WRITE32(locku->lu_stateid.si_generation); | 2121 | |
2105 | WRITEMEM(&locku->lu_stateid.si_opaque, sizeof(stateid_opaque_t)); | ||
2106 | ADJUST_ARGS(); | ||
2107 | } | ||
2108 | |||
2109 | ENCODE_SEQID_OP_TAIL(locku->lu_stateowner); | 2122 | ENCODE_SEQID_OP_TAIL(locku->lu_stateowner); |
2110 | return nfserr; | 2123 | return nfserr; |
2111 | } | 2124 | } |
@@ -2128,14 +2141,14 @@ nfsd4_encode_link(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_li | |||
2128 | static __be32 | 2141 | static __be32 |
2129 | nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open *open) | 2142 | nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open *open) |
2130 | { | 2143 | { |
2144 | ENCODE_HEAD; | ||
2131 | ENCODE_SEQID_OP_HEAD; | 2145 | ENCODE_SEQID_OP_HEAD; |
2132 | 2146 | ||
2133 | if (nfserr) | 2147 | if (nfserr) |
2134 | goto out; | 2148 | goto out; |
2135 | 2149 | ||
2136 | RESERVE_SPACE(36 + sizeof(stateid_t)); | 2150 | nfsd4_encode_stateid(resp, &open->op_stateid); |
2137 | WRITE32(open->op_stateid.si_generation); | 2151 | RESERVE_SPACE(40); |
2138 | WRITEMEM(&open->op_stateid.si_opaque, sizeof(stateid_opaque_t)); | ||
2139 | WRITECINFO(open->op_cinfo); | 2152 | WRITECINFO(open->op_cinfo); |
2140 | WRITE32(open->op_rflags); | 2153 | WRITE32(open->op_rflags); |
2141 | WRITE32(2); | 2154 | WRITE32(2); |
@@ -2148,8 +2161,8 @@ nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_op | |||
2148 | case NFS4_OPEN_DELEGATE_NONE: | 2161 | case NFS4_OPEN_DELEGATE_NONE: |
2149 | break; | 2162 | break; |
2150 | case NFS4_OPEN_DELEGATE_READ: | 2163 | case NFS4_OPEN_DELEGATE_READ: |
2151 | RESERVE_SPACE(20 + sizeof(stateid_t)); | 2164 | nfsd4_encode_stateid(resp, &open->op_delegate_stateid); |
2152 | WRITEMEM(&open->op_delegate_stateid, sizeof(stateid_t)); | 2165 | RESERVE_SPACE(20); |
2153 | WRITE32(open->op_recall); | 2166 | WRITE32(open->op_recall); |
2154 | 2167 | ||
2155 | /* | 2168 | /* |
@@ -2162,8 +2175,8 @@ nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_op | |||
2162 | ADJUST_ARGS(); | 2175 | ADJUST_ARGS(); |
2163 | break; | 2176 | break; |
2164 | case NFS4_OPEN_DELEGATE_WRITE: | 2177 | case NFS4_OPEN_DELEGATE_WRITE: |
2165 | RESERVE_SPACE(32 + sizeof(stateid_t)); | 2178 | nfsd4_encode_stateid(resp, &open->op_delegate_stateid); |
2166 | WRITEMEM(&open->op_delegate_stateid, sizeof(stateid_t)); | 2179 | RESERVE_SPACE(32); |
2167 | WRITE32(0); | 2180 | WRITE32(0); |
2168 | 2181 | ||
2169 | /* | 2182 | /* |
@@ -2195,13 +2208,9 @@ static __be32 | |||
2195 | nfsd4_encode_open_confirm(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open_confirm *oc) | 2208 | nfsd4_encode_open_confirm(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open_confirm *oc) |
2196 | { | 2209 | { |
2197 | ENCODE_SEQID_OP_HEAD; | 2210 | ENCODE_SEQID_OP_HEAD; |
2198 | 2211 | ||
2199 | if (!nfserr) { | 2212 | if (!nfserr) |
2200 | RESERVE_SPACE(sizeof(stateid_t)); | 2213 | nfsd4_encode_stateid(resp, &oc->oc_resp_stateid); |
2201 | WRITE32(oc->oc_resp_stateid.si_generation); | ||
2202 | WRITEMEM(&oc->oc_resp_stateid.si_opaque, sizeof(stateid_opaque_t)); | ||
2203 | ADJUST_ARGS(); | ||
2204 | } | ||
2205 | 2214 | ||
2206 | ENCODE_SEQID_OP_TAIL(oc->oc_stateowner); | 2215 | ENCODE_SEQID_OP_TAIL(oc->oc_stateowner); |
2207 | return nfserr; | 2216 | return nfserr; |
@@ -2211,13 +2220,9 @@ static __be32 | |||
2211 | nfsd4_encode_open_downgrade(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open_downgrade *od) | 2220 | nfsd4_encode_open_downgrade(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open_downgrade *od) |
2212 | { | 2221 | { |
2213 | ENCODE_SEQID_OP_HEAD; | 2222 | ENCODE_SEQID_OP_HEAD; |
2214 | 2223 | ||
2215 | if (!nfserr) { | 2224 | if (!nfserr) |
2216 | RESERVE_SPACE(sizeof(stateid_t)); | 2225 | nfsd4_encode_stateid(resp, &od->od_stateid); |
2217 | WRITE32(od->od_stateid.si_generation); | ||
2218 | WRITEMEM(&od->od_stateid.si_opaque, sizeof(stateid_opaque_t)); | ||
2219 | ADJUST_ARGS(); | ||
2220 | } | ||
2221 | 2226 | ||
2222 | ENCODE_SEQID_OP_TAIL(od->od_stateowner); | 2227 | ENCODE_SEQID_OP_TAIL(od->od_stateowner); |
2223 | return nfserr; | 2228 | return nfserr; |
diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c index c53e65f8f3a2..97543df58242 100644 --- a/fs/nfsd/nfsctl.c +++ b/fs/nfsd/nfsctl.c | |||
@@ -614,10 +614,9 @@ static ssize_t __write_ports(struct file *file, char *buf, size_t size) | |||
614 | return -EINVAL; | 614 | return -EINVAL; |
615 | err = nfsd_create_serv(); | 615 | err = nfsd_create_serv(); |
616 | if (!err) { | 616 | if (!err) { |
617 | int proto = 0; | 617 | err = svc_addsock(nfsd_serv, fd, buf); |
618 | err = svc_addsock(nfsd_serv, fd, buf, &proto); | ||
619 | if (err >= 0) { | 618 | if (err >= 0) { |
620 | err = lockd_up(proto); | 619 | err = lockd_up(); |
621 | if (err < 0) | 620 | if (err < 0) |
622 | svc_sock_names(buf+strlen(buf)+1, nfsd_serv, buf); | 621 | svc_sock_names(buf+strlen(buf)+1, nfsd_serv, buf); |
623 | } | 622 | } |
diff --git a/fs/nfsd/nfsfh.c b/fs/nfsd/nfsfh.c index ea37c96f0445..cd25d91895a1 100644 --- a/fs/nfsd/nfsfh.c +++ b/fs/nfsd/nfsfh.c | |||
@@ -302,17 +302,27 @@ fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, int access) | |||
302 | if (error) | 302 | if (error) |
303 | goto out; | 303 | goto out; |
304 | 304 | ||
305 | if (!(access & NFSD_MAY_LOCK)) { | 305 | /* |
306 | /* | 306 | * pseudoflavor restrictions are not enforced on NLM, |
307 | * pseudoflavor restrictions are not enforced on NLM, | 307 | * which clients virtually always use auth_sys for, |
308 | * which clients virtually always use auth_sys for, | 308 | * even while using RPCSEC_GSS for NFS. |
309 | * even while using RPCSEC_GSS for NFS. | 309 | */ |
310 | */ | 310 | if (access & NFSD_MAY_LOCK) |
311 | error = check_nfsd_access(exp, rqstp); | 311 | goto skip_pseudoflavor_check; |
312 | if (error) | 312 | /* |
313 | goto out; | 313 | * Clients may expect to be able to use auth_sys during mount, |
314 | } | 314 | * even if they use gss for everything else; see section 2.3.2 |
315 | * of rfc 2623. | ||
316 | */ | ||
317 | if (access & NFSD_MAY_BYPASS_GSS_ON_ROOT | ||
318 | && exp->ex_path.dentry == dentry) | ||
319 | goto skip_pseudoflavor_check; | ||
320 | |||
321 | error = check_nfsd_access(exp, rqstp); | ||
322 | if (error) | ||
323 | goto out; | ||
315 | 324 | ||
325 | skip_pseudoflavor_check: | ||
316 | /* Finally, check access permissions. */ | 326 | /* Finally, check access permissions. */ |
317 | error = nfsd_permission(rqstp, exp, dentry, access); | 327 | error = nfsd_permission(rqstp, exp, dentry, access); |
318 | 328 | ||
diff --git a/fs/nfsd/nfsproc.c b/fs/nfsd/nfsproc.c index 0766f95d236a..5cffeca7acef 100644 --- a/fs/nfsd/nfsproc.c +++ b/fs/nfsd/nfsproc.c | |||
@@ -65,7 +65,8 @@ nfsd_proc_getattr(struct svc_rqst *rqstp, struct nfsd_fhandle *argp, | |||
65 | dprintk("nfsd: GETATTR %s\n", SVCFH_fmt(&argp->fh)); | 65 | dprintk("nfsd: GETATTR %s\n", SVCFH_fmt(&argp->fh)); |
66 | 66 | ||
67 | fh_copy(&resp->fh, &argp->fh); | 67 | fh_copy(&resp->fh, &argp->fh); |
68 | nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP); | 68 | nfserr = fh_verify(rqstp, &resp->fh, 0, |
69 | NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT); | ||
69 | return nfsd_return_attrs(nfserr, resp); | 70 | return nfsd_return_attrs(nfserr, resp); |
70 | } | 71 | } |
71 | 72 | ||
@@ -521,7 +522,8 @@ nfsd_proc_statfs(struct svc_rqst * rqstp, struct nfsd_fhandle *argp, | |||
521 | 522 | ||
522 | dprintk("nfsd: STATFS %s\n", SVCFH_fmt(&argp->fh)); | 523 | dprintk("nfsd: STATFS %s\n", SVCFH_fmt(&argp->fh)); |
523 | 524 | ||
524 | nfserr = nfsd_statfs(rqstp, &argp->fh, &resp->stats); | 525 | nfserr = nfsd_statfs(rqstp, &argp->fh, &resp->stats, |
526 | NFSD_MAY_BYPASS_GSS_ON_ROOT); | ||
525 | fh_put(&argp->fh); | 527 | fh_put(&argp->fh); |
526 | return nfserr; | 528 | return nfserr; |
527 | } | 529 | } |
diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c index 80292ff5e924..59eeb46f82c5 100644 --- a/fs/nfsd/nfssvc.c +++ b/fs/nfsd/nfssvc.c | |||
@@ -229,6 +229,7 @@ int nfsd_create_serv(void) | |||
229 | 229 | ||
230 | atomic_set(&nfsd_busy, 0); | 230 | atomic_set(&nfsd_busy, 0); |
231 | nfsd_serv = svc_create_pooled(&nfsd_program, nfsd_max_blksize, | 231 | nfsd_serv = svc_create_pooled(&nfsd_program, nfsd_max_blksize, |
232 | AF_INET, | ||
232 | nfsd_last_thread, nfsd, THIS_MODULE); | 233 | nfsd_last_thread, nfsd, THIS_MODULE); |
233 | if (nfsd_serv == NULL) | 234 | if (nfsd_serv == NULL) |
234 | err = -ENOMEM; | 235 | err = -ENOMEM; |
@@ -243,25 +244,20 @@ static int nfsd_init_socks(int port) | |||
243 | if (!list_empty(&nfsd_serv->sv_permsocks)) | 244 | if (!list_empty(&nfsd_serv->sv_permsocks)) |
244 | return 0; | 245 | return 0; |
245 | 246 | ||
246 | error = lockd_up(IPPROTO_UDP); | 247 | error = svc_create_xprt(nfsd_serv, "udp", port, |
247 | if (error >= 0) { | ||
248 | error = svc_create_xprt(nfsd_serv, "udp", port, | ||
249 | SVC_SOCK_DEFAULTS); | 248 | SVC_SOCK_DEFAULTS); |
250 | if (error < 0) | ||
251 | lockd_down(); | ||
252 | } | ||
253 | if (error < 0) | 249 | if (error < 0) |
254 | return error; | 250 | return error; |
255 | 251 | ||
256 | error = lockd_up(IPPROTO_TCP); | 252 | error = svc_create_xprt(nfsd_serv, "tcp", port, |
257 | if (error >= 0) { | ||
258 | error = svc_create_xprt(nfsd_serv, "tcp", port, | ||
259 | SVC_SOCK_DEFAULTS); | 253 | SVC_SOCK_DEFAULTS); |
260 | if (error < 0) | ||
261 | lockd_down(); | ||
262 | } | ||
263 | if (error < 0) | 254 | if (error < 0) |
264 | return error; | 255 | return error; |
256 | |||
257 | error = lockd_up(); | ||
258 | if (error < 0) | ||
259 | return error; | ||
260 | |||
265 | return 0; | 261 | return 0; |
266 | } | 262 | } |
267 | 263 | ||
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 18060bed5267..aa1d0d6489a1 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c | |||
@@ -83,7 +83,6 @@ struct raparm_hbucket { | |||
83 | spinlock_t pb_lock; | 83 | spinlock_t pb_lock; |
84 | } ____cacheline_aligned_in_smp; | 84 | } ____cacheline_aligned_in_smp; |
85 | 85 | ||
86 | static struct raparms * raparml; | ||
87 | #define RAPARM_HASH_BITS 4 | 86 | #define RAPARM_HASH_BITS 4 |
88 | #define RAPARM_HASH_SIZE (1<<RAPARM_HASH_BITS) | 87 | #define RAPARM_HASH_SIZE (1<<RAPARM_HASH_BITS) |
89 | #define RAPARM_HASH_MASK (RAPARM_HASH_SIZE-1) | 88 | #define RAPARM_HASH_MASK (RAPARM_HASH_SIZE-1) |
@@ -1866,9 +1865,9 @@ out: | |||
1866 | * N.B. After this call fhp needs an fh_put | 1865 | * N.B. After this call fhp needs an fh_put |
1867 | */ | 1866 | */ |
1868 | __be32 | 1867 | __be32 |
1869 | nfsd_statfs(struct svc_rqst *rqstp, struct svc_fh *fhp, struct kstatfs *stat) | 1868 | nfsd_statfs(struct svc_rqst *rqstp, struct svc_fh *fhp, struct kstatfs *stat, int access) |
1870 | { | 1869 | { |
1871 | __be32 err = fh_verify(rqstp, fhp, 0, NFSD_MAY_NOP); | 1870 | __be32 err = fh_verify(rqstp, fhp, 0, NFSD_MAY_NOP | access); |
1872 | if (!err && vfs_statfs(fhp->fh_dentry,stat)) | 1871 | if (!err && vfs_statfs(fhp->fh_dentry,stat)) |
1873 | err = nfserr_io; | 1872 | err = nfserr_io; |
1874 | return err; | 1873 | return err; |
@@ -1966,11 +1965,20 @@ nfsd_permission(struct svc_rqst *rqstp, struct svc_export *exp, | |||
1966 | void | 1965 | void |
1967 | nfsd_racache_shutdown(void) | 1966 | nfsd_racache_shutdown(void) |
1968 | { | 1967 | { |
1969 | if (!raparml) | 1968 | struct raparms *raparm, *last_raparm; |
1970 | return; | 1969 | unsigned int i; |
1970 | |||
1971 | dprintk("nfsd: freeing readahead buffers.\n"); | 1971 | dprintk("nfsd: freeing readahead buffers.\n"); |
1972 | kfree(raparml); | 1972 | |
1973 | raparml = NULL; | 1973 | for (i = 0; i < RAPARM_HASH_SIZE; i++) { |
1974 | raparm = raparm_hash[i].pb_head; | ||
1975 | while(raparm) { | ||
1976 | last_raparm = raparm; | ||
1977 | raparm = raparm->p_next; | ||
1978 | kfree(last_raparm); | ||
1979 | } | ||
1980 | raparm_hash[i].pb_head = NULL; | ||
1981 | } | ||
1974 | } | 1982 | } |
1975 | /* | 1983 | /* |
1976 | * Initialize readahead param cache | 1984 | * Initialize readahead param cache |
@@ -1981,35 +1989,38 @@ nfsd_racache_init(int cache_size) | |||
1981 | int i; | 1989 | int i; |
1982 | int j = 0; | 1990 | int j = 0; |
1983 | int nperbucket; | 1991 | int nperbucket; |
1992 | struct raparms **raparm = NULL; | ||
1984 | 1993 | ||
1985 | 1994 | ||
1986 | if (raparml) | 1995 | if (raparm_hash[0].pb_head) |
1987 | return 0; | 1996 | return 0; |
1988 | if (cache_size < 2*RAPARM_HASH_SIZE) | 1997 | nperbucket = DIV_ROUND_UP(cache_size, RAPARM_HASH_SIZE); |
1989 | cache_size = 2*RAPARM_HASH_SIZE; | 1998 | if (nperbucket < 2) |
1990 | raparml = kcalloc(cache_size, sizeof(struct raparms), GFP_KERNEL); | 1999 | nperbucket = 2; |
1991 | 2000 | cache_size = nperbucket * RAPARM_HASH_SIZE; | |
1992 | if (!raparml) { | ||
1993 | printk(KERN_WARNING | ||
1994 | "nfsd: Could not allocate memory read-ahead cache.\n"); | ||
1995 | return -ENOMEM; | ||
1996 | } | ||
1997 | 2001 | ||
1998 | dprintk("nfsd: allocating %d readahead buffers.\n", cache_size); | 2002 | dprintk("nfsd: allocating %d readahead buffers.\n", cache_size); |
1999 | for (i = 0 ; i < RAPARM_HASH_SIZE ; i++) { | 2003 | |
2000 | raparm_hash[i].pb_head = NULL; | 2004 | for (i = 0; i < RAPARM_HASH_SIZE; i++) { |
2001 | spin_lock_init(&raparm_hash[i].pb_lock); | 2005 | spin_lock_init(&raparm_hash[i].pb_lock); |
2002 | } | 2006 | |
2003 | nperbucket = DIV_ROUND_UP(cache_size, RAPARM_HASH_SIZE); | 2007 | raparm = &raparm_hash[i].pb_head; |
2004 | for (i = 0; i < cache_size - 1; i++) { | 2008 | for (j = 0; j < nperbucket; j++) { |
2005 | if (i % nperbucket == 0) | 2009 | *raparm = kzalloc(sizeof(struct raparms), GFP_KERNEL); |
2006 | raparm_hash[j++].pb_head = raparml + i; | 2010 | if (!*raparm) |
2007 | if (i % nperbucket < nperbucket-1) | 2011 | goto out_nomem; |
2008 | raparml[i].p_next = raparml + i + 1; | 2012 | raparm = &(*raparm)->p_next; |
2013 | } | ||
2014 | *raparm = NULL; | ||
2009 | } | 2015 | } |
2010 | 2016 | ||
2011 | nfsdstats.ra_size = cache_size; | 2017 | nfsdstats.ra_size = cache_size; |
2012 | return 0; | 2018 | return 0; |
2019 | |||
2020 | out_nomem: | ||
2021 | dprintk("nfsd: kmalloc failed, freeing readahead buffers\n"); | ||
2022 | nfsd_racache_shutdown(); | ||
2023 | return -ENOMEM; | ||
2013 | } | 2024 | } |
2014 | 2025 | ||
2015 | #if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL) | 2026 | #if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL) |
diff --git a/fs/ocfs2/Makefile b/fs/ocfs2/Makefile index f6956de56fdb..589dcdfdfe3c 100644 --- a/fs/ocfs2/Makefile +++ b/fs/ocfs2/Makefile | |||
@@ -34,7 +34,8 @@ ocfs2-objs := \ | |||
34 | symlink.o \ | 34 | symlink.o \ |
35 | sysfile.o \ | 35 | sysfile.o \ |
36 | uptodate.o \ | 36 | uptodate.o \ |
37 | ver.o | 37 | ver.o \ |
38 | xattr.o | ||
38 | 39 | ||
39 | ocfs2_stackglue-objs := stackglue.o | 40 | ocfs2_stackglue-objs := stackglue.o |
40 | ocfs2_stack_o2cb-objs := stack_o2cb.o | 41 | ocfs2_stack_o2cb-objs := stack_o2cb.o |
diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c index 29ff57ec5d1f..0cc2deb9394c 100644 --- a/fs/ocfs2/alloc.c +++ b/fs/ocfs2/alloc.c | |||
@@ -49,6 +49,340 @@ | |||
49 | 49 | ||
50 | #include "buffer_head_io.h" | 50 | #include "buffer_head_io.h" |
51 | 51 | ||
52 | |||
53 | /* | ||
54 | * Operations for a specific extent tree type. | ||
55 | * | ||
56 | * To implement an on-disk btree (extent tree) type in ocfs2, add | ||
57 | * an ocfs2_extent_tree_operations structure and the matching | ||
58 | * ocfs2_init_<thingy>_extent_tree() function. That's pretty much it | ||
59 | * for the allocation portion of the extent tree. | ||
60 | */ | ||
61 | struct ocfs2_extent_tree_operations { | ||
62 | /* | ||
63 | * last_eb_blk is the block number of the right most leaf extent | ||
64 | * block. Most on-disk structures containing an extent tree store | ||
65 | * this value for fast access. The ->eo_set_last_eb_blk() and | ||
66 | * ->eo_get_last_eb_blk() operations access this value. They are | ||
67 | * both required. | ||
68 | */ | ||
69 | void (*eo_set_last_eb_blk)(struct ocfs2_extent_tree *et, | ||
70 | u64 blkno); | ||
71 | u64 (*eo_get_last_eb_blk)(struct ocfs2_extent_tree *et); | ||
72 | |||
73 | /* | ||
74 | * The on-disk structure usually keeps track of how many total | ||
75 | * clusters are stored in this extent tree. This function updates | ||
76 | * that value. new_clusters is the delta, and must be | ||
77 | * added to the total. Required. | ||
78 | */ | ||
79 | void (*eo_update_clusters)(struct inode *inode, | ||
80 | struct ocfs2_extent_tree *et, | ||
81 | u32 new_clusters); | ||
82 | |||
83 | /* | ||
84 | * If ->eo_insert_check() exists, it is called before rec is | ||
85 | * inserted into the extent tree. It is optional. | ||
86 | */ | ||
87 | int (*eo_insert_check)(struct inode *inode, | ||
88 | struct ocfs2_extent_tree *et, | ||
89 | struct ocfs2_extent_rec *rec); | ||
90 | int (*eo_sanity_check)(struct inode *inode, struct ocfs2_extent_tree *et); | ||
91 | |||
92 | /* | ||
93 | * -------------------------------------------------------------- | ||
94 | * The remaining are internal to ocfs2_extent_tree and don't have | ||
95 | * accessor functions | ||
96 | */ | ||
97 | |||
98 | /* | ||
99 | * ->eo_fill_root_el() takes et->et_object and sets et->et_root_el. | ||
100 | * It is required. | ||
101 | */ | ||
102 | void (*eo_fill_root_el)(struct ocfs2_extent_tree *et); | ||
103 | |||
104 | /* | ||
105 | * ->eo_fill_max_leaf_clusters sets et->et_max_leaf_clusters if | ||
106 | * it exists. If it does not, et->et_max_leaf_clusters is set | ||
107 | * to 0 (unlimited). Optional. | ||
108 | */ | ||
109 | void (*eo_fill_max_leaf_clusters)(struct inode *inode, | ||
110 | struct ocfs2_extent_tree *et); | ||
111 | }; | ||
112 | |||
113 | |||
114 | /* | ||
115 | * Pre-declare ocfs2_dinode_et_ops so we can use it as a sanity check | ||
116 | * in the methods. | ||
117 | */ | ||
118 | static u64 ocfs2_dinode_get_last_eb_blk(struct ocfs2_extent_tree *et); | ||
119 | static void ocfs2_dinode_set_last_eb_blk(struct ocfs2_extent_tree *et, | ||
120 | u64 blkno); | ||
121 | static void ocfs2_dinode_update_clusters(struct inode *inode, | ||
122 | struct ocfs2_extent_tree *et, | ||
123 | u32 clusters); | ||
124 | static int ocfs2_dinode_insert_check(struct inode *inode, | ||
125 | struct ocfs2_extent_tree *et, | ||
126 | struct ocfs2_extent_rec *rec); | ||
127 | static int ocfs2_dinode_sanity_check(struct inode *inode, | ||
128 | struct ocfs2_extent_tree *et); | ||
129 | static void ocfs2_dinode_fill_root_el(struct ocfs2_extent_tree *et); | ||
130 | static struct ocfs2_extent_tree_operations ocfs2_dinode_et_ops = { | ||
131 | .eo_set_last_eb_blk = ocfs2_dinode_set_last_eb_blk, | ||
132 | .eo_get_last_eb_blk = ocfs2_dinode_get_last_eb_blk, | ||
133 | .eo_update_clusters = ocfs2_dinode_update_clusters, | ||
134 | .eo_insert_check = ocfs2_dinode_insert_check, | ||
135 | .eo_sanity_check = ocfs2_dinode_sanity_check, | ||
136 | .eo_fill_root_el = ocfs2_dinode_fill_root_el, | ||
137 | }; | ||
138 | |||
139 | static void ocfs2_dinode_set_last_eb_blk(struct ocfs2_extent_tree *et, | ||
140 | u64 blkno) | ||
141 | { | ||
142 | struct ocfs2_dinode *di = et->et_object; | ||
143 | |||
144 | BUG_ON(et->et_ops != &ocfs2_dinode_et_ops); | ||
145 | di->i_last_eb_blk = cpu_to_le64(blkno); | ||
146 | } | ||
147 | |||
148 | static u64 ocfs2_dinode_get_last_eb_blk(struct ocfs2_extent_tree *et) | ||
149 | { | ||
150 | struct ocfs2_dinode *di = et->et_object; | ||
151 | |||
152 | BUG_ON(et->et_ops != &ocfs2_dinode_et_ops); | ||
153 | return le64_to_cpu(di->i_last_eb_blk); | ||
154 | } | ||
155 | |||
156 | static void ocfs2_dinode_update_clusters(struct inode *inode, | ||
157 | struct ocfs2_extent_tree *et, | ||
158 | u32 clusters) | ||
159 | { | ||
160 | struct ocfs2_dinode *di = et->et_object; | ||
161 | |||
162 | le32_add_cpu(&di->i_clusters, clusters); | ||
163 | spin_lock(&OCFS2_I(inode)->ip_lock); | ||
164 | OCFS2_I(inode)->ip_clusters = le32_to_cpu(di->i_clusters); | ||
165 | spin_unlock(&OCFS2_I(inode)->ip_lock); | ||
166 | } | ||
167 | |||
168 | static int ocfs2_dinode_insert_check(struct inode *inode, | ||
169 | struct ocfs2_extent_tree *et, | ||
170 | struct ocfs2_extent_rec *rec) | ||
171 | { | ||
172 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
173 | |||
174 | BUG_ON(OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL); | ||
175 | mlog_bug_on_msg(!ocfs2_sparse_alloc(osb) && | ||
176 | (OCFS2_I(inode)->ip_clusters != rec->e_cpos), | ||
177 | "Device %s, asking for sparse allocation: inode %llu, " | ||
178 | "cpos %u, clusters %u\n", | ||
179 | osb->dev_str, | ||
180 | (unsigned long long)OCFS2_I(inode)->ip_blkno, | ||
181 | rec->e_cpos, | ||
182 | OCFS2_I(inode)->ip_clusters); | ||
183 | |||
184 | return 0; | ||
185 | } | ||
186 | |||
187 | static int ocfs2_dinode_sanity_check(struct inode *inode, | ||
188 | struct ocfs2_extent_tree *et) | ||
189 | { | ||
190 | int ret = 0; | ||
191 | struct ocfs2_dinode *di; | ||
192 | |||
193 | BUG_ON(et->et_ops != &ocfs2_dinode_et_ops); | ||
194 | |||
195 | di = et->et_object; | ||
196 | if (!OCFS2_IS_VALID_DINODE(di)) { | ||
197 | ret = -EIO; | ||
198 | ocfs2_error(inode->i_sb, | ||
199 | "Inode %llu has invalid path root", | ||
200 | (unsigned long long)OCFS2_I(inode)->ip_blkno); | ||
201 | } | ||
202 | |||
203 | return ret; | ||
204 | } | ||
205 | |||
206 | static void ocfs2_dinode_fill_root_el(struct ocfs2_extent_tree *et) | ||
207 | { | ||
208 | struct ocfs2_dinode *di = et->et_object; | ||
209 | |||
210 | et->et_root_el = &di->id2.i_list; | ||
211 | } | ||
212 | |||
213 | |||
214 | static void ocfs2_xattr_value_fill_root_el(struct ocfs2_extent_tree *et) | ||
215 | { | ||
216 | struct ocfs2_xattr_value_root *xv = et->et_object; | ||
217 | |||
218 | et->et_root_el = &xv->xr_list; | ||
219 | } | ||
220 | |||
221 | static void ocfs2_xattr_value_set_last_eb_blk(struct ocfs2_extent_tree *et, | ||
222 | u64 blkno) | ||
223 | { | ||
224 | struct ocfs2_xattr_value_root *xv = | ||
225 | (struct ocfs2_xattr_value_root *)et->et_object; | ||
226 | |||
227 | xv->xr_last_eb_blk = cpu_to_le64(blkno); | ||
228 | } | ||
229 | |||
230 | static u64 ocfs2_xattr_value_get_last_eb_blk(struct ocfs2_extent_tree *et) | ||
231 | { | ||
232 | struct ocfs2_xattr_value_root *xv = | ||
233 | (struct ocfs2_xattr_value_root *) et->et_object; | ||
234 | |||
235 | return le64_to_cpu(xv->xr_last_eb_blk); | ||
236 | } | ||
237 | |||
238 | static void ocfs2_xattr_value_update_clusters(struct inode *inode, | ||
239 | struct ocfs2_extent_tree *et, | ||
240 | u32 clusters) | ||
241 | { | ||
242 | struct ocfs2_xattr_value_root *xv = | ||
243 | (struct ocfs2_xattr_value_root *)et->et_object; | ||
244 | |||
245 | le32_add_cpu(&xv->xr_clusters, clusters); | ||
246 | } | ||
247 | |||
248 | static struct ocfs2_extent_tree_operations ocfs2_xattr_value_et_ops = { | ||
249 | .eo_set_last_eb_blk = ocfs2_xattr_value_set_last_eb_blk, | ||
250 | .eo_get_last_eb_blk = ocfs2_xattr_value_get_last_eb_blk, | ||
251 | .eo_update_clusters = ocfs2_xattr_value_update_clusters, | ||
252 | .eo_fill_root_el = ocfs2_xattr_value_fill_root_el, | ||
253 | }; | ||
254 | |||
255 | static void ocfs2_xattr_tree_fill_root_el(struct ocfs2_extent_tree *et) | ||
256 | { | ||
257 | struct ocfs2_xattr_block *xb = et->et_object; | ||
258 | |||
259 | et->et_root_el = &xb->xb_attrs.xb_root.xt_list; | ||
260 | } | ||
261 | |||
262 | static void ocfs2_xattr_tree_fill_max_leaf_clusters(struct inode *inode, | ||
263 | struct ocfs2_extent_tree *et) | ||
264 | { | ||
265 | et->et_max_leaf_clusters = | ||
266 | ocfs2_clusters_for_bytes(inode->i_sb, | ||
267 | OCFS2_MAX_XATTR_TREE_LEAF_SIZE); | ||
268 | } | ||
269 | |||
270 | static void ocfs2_xattr_tree_set_last_eb_blk(struct ocfs2_extent_tree *et, | ||
271 | u64 blkno) | ||
272 | { | ||
273 | struct ocfs2_xattr_block *xb = et->et_object; | ||
274 | struct ocfs2_xattr_tree_root *xt = &xb->xb_attrs.xb_root; | ||
275 | |||
276 | xt->xt_last_eb_blk = cpu_to_le64(blkno); | ||
277 | } | ||
278 | |||
279 | static u64 ocfs2_xattr_tree_get_last_eb_blk(struct ocfs2_extent_tree *et) | ||
280 | { | ||
281 | struct ocfs2_xattr_block *xb = et->et_object; | ||
282 | struct ocfs2_xattr_tree_root *xt = &xb->xb_attrs.xb_root; | ||
283 | |||
284 | return le64_to_cpu(xt->xt_last_eb_blk); | ||
285 | } | ||
286 | |||
287 | static void ocfs2_xattr_tree_update_clusters(struct inode *inode, | ||
288 | struct ocfs2_extent_tree *et, | ||
289 | u32 clusters) | ||
290 | { | ||
291 | struct ocfs2_xattr_block *xb = et->et_object; | ||
292 | |||
293 | le32_add_cpu(&xb->xb_attrs.xb_root.xt_clusters, clusters); | ||
294 | } | ||
295 | |||
296 | static struct ocfs2_extent_tree_operations ocfs2_xattr_tree_et_ops = { | ||
297 | .eo_set_last_eb_blk = ocfs2_xattr_tree_set_last_eb_blk, | ||
298 | .eo_get_last_eb_blk = ocfs2_xattr_tree_get_last_eb_blk, | ||
299 | .eo_update_clusters = ocfs2_xattr_tree_update_clusters, | ||
300 | .eo_fill_root_el = ocfs2_xattr_tree_fill_root_el, | ||
301 | .eo_fill_max_leaf_clusters = ocfs2_xattr_tree_fill_max_leaf_clusters, | ||
302 | }; | ||
303 | |||
304 | static void __ocfs2_init_extent_tree(struct ocfs2_extent_tree *et, | ||
305 | struct inode *inode, | ||
306 | struct buffer_head *bh, | ||
307 | void *obj, | ||
308 | struct ocfs2_extent_tree_operations *ops) | ||
309 | { | ||
310 | et->et_ops = ops; | ||
311 | et->et_root_bh = bh; | ||
312 | if (!obj) | ||
313 | obj = (void *)bh->b_data; | ||
314 | et->et_object = obj; | ||
315 | |||
316 | et->et_ops->eo_fill_root_el(et); | ||
317 | if (!et->et_ops->eo_fill_max_leaf_clusters) | ||
318 | et->et_max_leaf_clusters = 0; | ||
319 | else | ||
320 | et->et_ops->eo_fill_max_leaf_clusters(inode, et); | ||
321 | } | ||
322 | |||
323 | void ocfs2_init_dinode_extent_tree(struct ocfs2_extent_tree *et, | ||
324 | struct inode *inode, | ||
325 | struct buffer_head *bh) | ||
326 | { | ||
327 | __ocfs2_init_extent_tree(et, inode, bh, NULL, &ocfs2_dinode_et_ops); | ||
328 | } | ||
329 | |||
330 | void ocfs2_init_xattr_tree_extent_tree(struct ocfs2_extent_tree *et, | ||
331 | struct inode *inode, | ||
332 | struct buffer_head *bh) | ||
333 | { | ||
334 | __ocfs2_init_extent_tree(et, inode, bh, NULL, | ||
335 | &ocfs2_xattr_tree_et_ops); | ||
336 | } | ||
337 | |||
338 | void ocfs2_init_xattr_value_extent_tree(struct ocfs2_extent_tree *et, | ||
339 | struct inode *inode, | ||
340 | struct buffer_head *bh, | ||
341 | struct ocfs2_xattr_value_root *xv) | ||
342 | { | ||
343 | __ocfs2_init_extent_tree(et, inode, bh, xv, | ||
344 | &ocfs2_xattr_value_et_ops); | ||
345 | } | ||
346 | |||
347 | static inline void ocfs2_et_set_last_eb_blk(struct ocfs2_extent_tree *et, | ||
348 | u64 new_last_eb_blk) | ||
349 | { | ||
350 | et->et_ops->eo_set_last_eb_blk(et, new_last_eb_blk); | ||
351 | } | ||
352 | |||
353 | static inline u64 ocfs2_et_get_last_eb_blk(struct ocfs2_extent_tree *et) | ||
354 | { | ||
355 | return et->et_ops->eo_get_last_eb_blk(et); | ||
356 | } | ||
357 | |||
358 | static inline void ocfs2_et_update_clusters(struct inode *inode, | ||
359 | struct ocfs2_extent_tree *et, | ||
360 | u32 clusters) | ||
361 | { | ||
362 | et->et_ops->eo_update_clusters(inode, et, clusters); | ||
363 | } | ||
364 | |||
365 | static inline int ocfs2_et_insert_check(struct inode *inode, | ||
366 | struct ocfs2_extent_tree *et, | ||
367 | struct ocfs2_extent_rec *rec) | ||
368 | { | ||
369 | int ret = 0; | ||
370 | |||
371 | if (et->et_ops->eo_insert_check) | ||
372 | ret = et->et_ops->eo_insert_check(inode, et, rec); | ||
373 | return ret; | ||
374 | } | ||
375 | |||
376 | static inline int ocfs2_et_sanity_check(struct inode *inode, | ||
377 | struct ocfs2_extent_tree *et) | ||
378 | { | ||
379 | int ret = 0; | ||
380 | |||
381 | if (et->et_ops->eo_sanity_check) | ||
382 | ret = et->et_ops->eo_sanity_check(inode, et); | ||
383 | return ret; | ||
384 | } | ||
385 | |||
52 | static void ocfs2_free_truncate_context(struct ocfs2_truncate_context *tc); | 386 | static void ocfs2_free_truncate_context(struct ocfs2_truncate_context *tc); |
53 | static int ocfs2_cache_extent_block_free(struct ocfs2_cached_dealloc_ctxt *ctxt, | 387 | static int ocfs2_cache_extent_block_free(struct ocfs2_cached_dealloc_ctxt *ctxt, |
54 | struct ocfs2_extent_block *eb); | 388 | struct ocfs2_extent_block *eb); |
@@ -205,17 +539,6 @@ static struct ocfs2_path *ocfs2_new_path(struct buffer_head *root_bh, | |||
205 | } | 539 | } |
206 | 540 | ||
207 | /* | 541 | /* |
208 | * Allocate and initialize a new path based on a disk inode tree. | ||
209 | */ | ||
210 | static struct ocfs2_path *ocfs2_new_inode_path(struct buffer_head *di_bh) | ||
211 | { | ||
212 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; | ||
213 | struct ocfs2_extent_list *el = &di->id2.i_list; | ||
214 | |||
215 | return ocfs2_new_path(di_bh, el); | ||
216 | } | ||
217 | |||
218 | /* | ||
219 | * Convenience function to journal all components in a path. | 542 | * Convenience function to journal all components in a path. |
220 | */ | 543 | */ |
221 | static int ocfs2_journal_access_path(struct inode *inode, handle_t *handle, | 544 | static int ocfs2_journal_access_path(struct inode *inode, handle_t *handle, |
@@ -368,39 +691,35 @@ struct ocfs2_merge_ctxt { | |||
368 | */ | 691 | */ |
369 | int ocfs2_num_free_extents(struct ocfs2_super *osb, | 692 | int ocfs2_num_free_extents(struct ocfs2_super *osb, |
370 | struct inode *inode, | 693 | struct inode *inode, |
371 | struct ocfs2_dinode *fe) | 694 | struct ocfs2_extent_tree *et) |
372 | { | 695 | { |
373 | int retval; | 696 | int retval; |
374 | struct ocfs2_extent_list *el; | 697 | struct ocfs2_extent_list *el = NULL; |
375 | struct ocfs2_extent_block *eb; | 698 | struct ocfs2_extent_block *eb; |
376 | struct buffer_head *eb_bh = NULL; | 699 | struct buffer_head *eb_bh = NULL; |
700 | u64 last_eb_blk = 0; | ||
377 | 701 | ||
378 | mlog_entry_void(); | 702 | mlog_entry_void(); |
379 | 703 | ||
380 | if (!OCFS2_IS_VALID_DINODE(fe)) { | 704 | el = et->et_root_el; |
381 | OCFS2_RO_ON_INVALID_DINODE(inode->i_sb, fe); | 705 | last_eb_blk = ocfs2_et_get_last_eb_blk(et); |
382 | retval = -EIO; | ||
383 | goto bail; | ||
384 | } | ||
385 | 706 | ||
386 | if (fe->i_last_eb_blk) { | 707 | if (last_eb_blk) { |
387 | retval = ocfs2_read_block(osb, le64_to_cpu(fe->i_last_eb_blk), | 708 | retval = ocfs2_read_block(inode, last_eb_blk, |
388 | &eb_bh, OCFS2_BH_CACHED, inode); | 709 | &eb_bh); |
389 | if (retval < 0) { | 710 | if (retval < 0) { |
390 | mlog_errno(retval); | 711 | mlog_errno(retval); |
391 | goto bail; | 712 | goto bail; |
392 | } | 713 | } |
393 | eb = (struct ocfs2_extent_block *) eb_bh->b_data; | 714 | eb = (struct ocfs2_extent_block *) eb_bh->b_data; |
394 | el = &eb->h_list; | 715 | el = &eb->h_list; |
395 | } else | 716 | } |
396 | el = &fe->id2.i_list; | ||
397 | 717 | ||
398 | BUG_ON(el->l_tree_depth != 0); | 718 | BUG_ON(el->l_tree_depth != 0); |
399 | 719 | ||
400 | retval = le16_to_cpu(el->l_count) - le16_to_cpu(el->l_next_free_rec); | 720 | retval = le16_to_cpu(el->l_count) - le16_to_cpu(el->l_next_free_rec); |
401 | bail: | 721 | bail: |
402 | if (eb_bh) | 722 | brelse(eb_bh); |
403 | brelse(eb_bh); | ||
404 | 723 | ||
405 | mlog_exit(retval); | 724 | mlog_exit(retval); |
406 | return retval; | 725 | return retval; |
@@ -486,8 +805,7 @@ static int ocfs2_create_new_meta_bhs(struct ocfs2_super *osb, | |||
486 | bail: | 805 | bail: |
487 | if (status < 0) { | 806 | if (status < 0) { |
488 | for(i = 0; i < wanted; i++) { | 807 | for(i = 0; i < wanted; i++) { |
489 | if (bhs[i]) | 808 | brelse(bhs[i]); |
490 | brelse(bhs[i]); | ||
491 | bhs[i] = NULL; | 809 | bhs[i] = NULL; |
492 | } | 810 | } |
493 | } | 811 | } |
@@ -531,7 +849,7 @@ static inline u32 ocfs2_sum_rightmost_rec(struct ocfs2_extent_list *el) | |||
531 | static int ocfs2_add_branch(struct ocfs2_super *osb, | 849 | static int ocfs2_add_branch(struct ocfs2_super *osb, |
532 | handle_t *handle, | 850 | handle_t *handle, |
533 | struct inode *inode, | 851 | struct inode *inode, |
534 | struct buffer_head *fe_bh, | 852 | struct ocfs2_extent_tree *et, |
535 | struct buffer_head *eb_bh, | 853 | struct buffer_head *eb_bh, |
536 | struct buffer_head **last_eb_bh, | 854 | struct buffer_head **last_eb_bh, |
537 | struct ocfs2_alloc_context *meta_ac) | 855 | struct ocfs2_alloc_context *meta_ac) |
@@ -540,7 +858,6 @@ static int ocfs2_add_branch(struct ocfs2_super *osb, | |||
540 | u64 next_blkno, new_last_eb_blk; | 858 | u64 next_blkno, new_last_eb_blk; |
541 | struct buffer_head *bh; | 859 | struct buffer_head *bh; |
542 | struct buffer_head **new_eb_bhs = NULL; | 860 | struct buffer_head **new_eb_bhs = NULL; |
543 | struct ocfs2_dinode *fe; | ||
544 | struct ocfs2_extent_block *eb; | 861 | struct ocfs2_extent_block *eb; |
545 | struct ocfs2_extent_list *eb_el; | 862 | struct ocfs2_extent_list *eb_el; |
546 | struct ocfs2_extent_list *el; | 863 | struct ocfs2_extent_list *el; |
@@ -550,13 +867,11 @@ static int ocfs2_add_branch(struct ocfs2_super *osb, | |||
550 | 867 | ||
551 | BUG_ON(!last_eb_bh || !*last_eb_bh); | 868 | BUG_ON(!last_eb_bh || !*last_eb_bh); |
552 | 869 | ||
553 | fe = (struct ocfs2_dinode *) fe_bh->b_data; | ||
554 | |||
555 | if (eb_bh) { | 870 | if (eb_bh) { |
556 | eb = (struct ocfs2_extent_block *) eb_bh->b_data; | 871 | eb = (struct ocfs2_extent_block *) eb_bh->b_data; |
557 | el = &eb->h_list; | 872 | el = &eb->h_list; |
558 | } else | 873 | } else |
559 | el = &fe->id2.i_list; | 874 | el = et->et_root_el; |
560 | 875 | ||
561 | /* we never add a branch to a leaf. */ | 876 | /* we never add a branch to a leaf. */ |
562 | BUG_ON(!el->l_tree_depth); | 877 | BUG_ON(!el->l_tree_depth); |
@@ -646,7 +961,7 @@ static int ocfs2_add_branch(struct ocfs2_super *osb, | |||
646 | mlog_errno(status); | 961 | mlog_errno(status); |
647 | goto bail; | 962 | goto bail; |
648 | } | 963 | } |
649 | status = ocfs2_journal_access(handle, inode, fe_bh, | 964 | status = ocfs2_journal_access(handle, inode, et->et_root_bh, |
650 | OCFS2_JOURNAL_ACCESS_WRITE); | 965 | OCFS2_JOURNAL_ACCESS_WRITE); |
651 | if (status < 0) { | 966 | if (status < 0) { |
652 | mlog_errno(status); | 967 | mlog_errno(status); |
@@ -662,7 +977,7 @@ static int ocfs2_add_branch(struct ocfs2_super *osb, | |||
662 | } | 977 | } |
663 | 978 | ||
664 | /* Link the new branch into the rest of the tree (el will | 979 | /* Link the new branch into the rest of the tree (el will |
665 | * either be on the fe, or the extent block passed in. */ | 980 | * either be on the root_bh, or the extent block passed in. */ |
666 | i = le16_to_cpu(el->l_next_free_rec); | 981 | i = le16_to_cpu(el->l_next_free_rec); |
667 | el->l_recs[i].e_blkno = cpu_to_le64(next_blkno); | 982 | el->l_recs[i].e_blkno = cpu_to_le64(next_blkno); |
668 | el->l_recs[i].e_cpos = cpu_to_le32(new_cpos); | 983 | el->l_recs[i].e_cpos = cpu_to_le32(new_cpos); |
@@ -671,7 +986,7 @@ static int ocfs2_add_branch(struct ocfs2_super *osb, | |||
671 | 986 | ||
672 | /* fe needs a new last extent block pointer, as does the | 987 | /* fe needs a new last extent block pointer, as does the |
673 | * next_leaf on the previously last-extent-block. */ | 988 | * next_leaf on the previously last-extent-block. */ |
674 | fe->i_last_eb_blk = cpu_to_le64(new_last_eb_blk); | 989 | ocfs2_et_set_last_eb_blk(et, new_last_eb_blk); |
675 | 990 | ||
676 | eb = (struct ocfs2_extent_block *) (*last_eb_bh)->b_data; | 991 | eb = (struct ocfs2_extent_block *) (*last_eb_bh)->b_data; |
677 | eb->h_next_leaf_blk = cpu_to_le64(new_last_eb_blk); | 992 | eb->h_next_leaf_blk = cpu_to_le64(new_last_eb_blk); |
@@ -679,7 +994,7 @@ static int ocfs2_add_branch(struct ocfs2_super *osb, | |||
679 | status = ocfs2_journal_dirty(handle, *last_eb_bh); | 994 | status = ocfs2_journal_dirty(handle, *last_eb_bh); |
680 | if (status < 0) | 995 | if (status < 0) |
681 | mlog_errno(status); | 996 | mlog_errno(status); |
682 | status = ocfs2_journal_dirty(handle, fe_bh); | 997 | status = ocfs2_journal_dirty(handle, et->et_root_bh); |
683 | if (status < 0) | 998 | if (status < 0) |
684 | mlog_errno(status); | 999 | mlog_errno(status); |
685 | if (eb_bh) { | 1000 | if (eb_bh) { |
@@ -700,8 +1015,7 @@ static int ocfs2_add_branch(struct ocfs2_super *osb, | |||
700 | bail: | 1015 | bail: |
701 | if (new_eb_bhs) { | 1016 | if (new_eb_bhs) { |
702 | for (i = 0; i < new_blocks; i++) | 1017 | for (i = 0; i < new_blocks; i++) |
703 | if (new_eb_bhs[i]) | 1018 | brelse(new_eb_bhs[i]); |
704 | brelse(new_eb_bhs[i]); | ||
705 | kfree(new_eb_bhs); | 1019 | kfree(new_eb_bhs); |
706 | } | 1020 | } |
707 | 1021 | ||
@@ -717,16 +1031,15 @@ bail: | |||
717 | static int ocfs2_shift_tree_depth(struct ocfs2_super *osb, | 1031 | static int ocfs2_shift_tree_depth(struct ocfs2_super *osb, |
718 | handle_t *handle, | 1032 | handle_t *handle, |
719 | struct inode *inode, | 1033 | struct inode *inode, |
720 | struct buffer_head *fe_bh, | 1034 | struct ocfs2_extent_tree *et, |
721 | struct ocfs2_alloc_context *meta_ac, | 1035 | struct ocfs2_alloc_context *meta_ac, |
722 | struct buffer_head **ret_new_eb_bh) | 1036 | struct buffer_head **ret_new_eb_bh) |
723 | { | 1037 | { |
724 | int status, i; | 1038 | int status, i; |
725 | u32 new_clusters; | 1039 | u32 new_clusters; |
726 | struct buffer_head *new_eb_bh = NULL; | 1040 | struct buffer_head *new_eb_bh = NULL; |
727 | struct ocfs2_dinode *fe; | ||
728 | struct ocfs2_extent_block *eb; | 1041 | struct ocfs2_extent_block *eb; |
729 | struct ocfs2_extent_list *fe_el; | 1042 | struct ocfs2_extent_list *root_el; |
730 | struct ocfs2_extent_list *eb_el; | 1043 | struct ocfs2_extent_list *eb_el; |
731 | 1044 | ||
732 | mlog_entry_void(); | 1045 | mlog_entry_void(); |
@@ -746,8 +1059,7 @@ static int ocfs2_shift_tree_depth(struct ocfs2_super *osb, | |||
746 | } | 1059 | } |
747 | 1060 | ||
748 | eb_el = &eb->h_list; | 1061 | eb_el = &eb->h_list; |
749 | fe = (struct ocfs2_dinode *) fe_bh->b_data; | 1062 | root_el = et->et_root_el; |
750 | fe_el = &fe->id2.i_list; | ||
751 | 1063 | ||
752 | status = ocfs2_journal_access(handle, inode, new_eb_bh, | 1064 | status = ocfs2_journal_access(handle, inode, new_eb_bh, |
753 | OCFS2_JOURNAL_ACCESS_CREATE); | 1065 | OCFS2_JOURNAL_ACCESS_CREATE); |
@@ -756,11 +1068,11 @@ static int ocfs2_shift_tree_depth(struct ocfs2_super *osb, | |||
756 | goto bail; | 1068 | goto bail; |
757 | } | 1069 | } |
758 | 1070 | ||
759 | /* copy the fe data into the new extent block */ | 1071 | /* copy the root extent list data into the new extent block */ |
760 | eb_el->l_tree_depth = fe_el->l_tree_depth; | 1072 | eb_el->l_tree_depth = root_el->l_tree_depth; |
761 | eb_el->l_next_free_rec = fe_el->l_next_free_rec; | 1073 | eb_el->l_next_free_rec = root_el->l_next_free_rec; |
762 | for(i = 0; i < le16_to_cpu(fe_el->l_next_free_rec); i++) | 1074 | for (i = 0; i < le16_to_cpu(root_el->l_next_free_rec); i++) |
763 | eb_el->l_recs[i] = fe_el->l_recs[i]; | 1075 | eb_el->l_recs[i] = root_el->l_recs[i]; |
764 | 1076 | ||
765 | status = ocfs2_journal_dirty(handle, new_eb_bh); | 1077 | status = ocfs2_journal_dirty(handle, new_eb_bh); |
766 | if (status < 0) { | 1078 | if (status < 0) { |
@@ -768,7 +1080,7 @@ static int ocfs2_shift_tree_depth(struct ocfs2_super *osb, | |||
768 | goto bail; | 1080 | goto bail; |
769 | } | 1081 | } |
770 | 1082 | ||
771 | status = ocfs2_journal_access(handle, inode, fe_bh, | 1083 | status = ocfs2_journal_access(handle, inode, et->et_root_bh, |
772 | OCFS2_JOURNAL_ACCESS_WRITE); | 1084 | OCFS2_JOURNAL_ACCESS_WRITE); |
773 | if (status < 0) { | 1085 | if (status < 0) { |
774 | mlog_errno(status); | 1086 | mlog_errno(status); |
@@ -777,21 +1089,21 @@ static int ocfs2_shift_tree_depth(struct ocfs2_super *osb, | |||
777 | 1089 | ||
778 | new_clusters = ocfs2_sum_rightmost_rec(eb_el); | 1090 | new_clusters = ocfs2_sum_rightmost_rec(eb_el); |
779 | 1091 | ||
780 | /* update fe now */ | 1092 | /* update root_bh now */ |
781 | le16_add_cpu(&fe_el->l_tree_depth, 1); | 1093 | le16_add_cpu(&root_el->l_tree_depth, 1); |
782 | fe_el->l_recs[0].e_cpos = 0; | 1094 | root_el->l_recs[0].e_cpos = 0; |
783 | fe_el->l_recs[0].e_blkno = eb->h_blkno; | 1095 | root_el->l_recs[0].e_blkno = eb->h_blkno; |
784 | fe_el->l_recs[0].e_int_clusters = cpu_to_le32(new_clusters); | 1096 | root_el->l_recs[0].e_int_clusters = cpu_to_le32(new_clusters); |
785 | for(i = 1; i < le16_to_cpu(fe_el->l_next_free_rec); i++) | 1097 | for (i = 1; i < le16_to_cpu(root_el->l_next_free_rec); i++) |
786 | memset(&fe_el->l_recs[i], 0, sizeof(struct ocfs2_extent_rec)); | 1098 | memset(&root_el->l_recs[i], 0, sizeof(struct ocfs2_extent_rec)); |
787 | fe_el->l_next_free_rec = cpu_to_le16(1); | 1099 | root_el->l_next_free_rec = cpu_to_le16(1); |
788 | 1100 | ||
789 | /* If this is our 1st tree depth shift, then last_eb_blk | 1101 | /* If this is our 1st tree depth shift, then last_eb_blk |
790 | * becomes the allocated extent block */ | 1102 | * becomes the allocated extent block */ |
791 | if (fe_el->l_tree_depth == cpu_to_le16(1)) | 1103 | if (root_el->l_tree_depth == cpu_to_le16(1)) |
792 | fe->i_last_eb_blk = eb->h_blkno; | 1104 | ocfs2_et_set_last_eb_blk(et, le64_to_cpu(eb->h_blkno)); |
793 | 1105 | ||
794 | status = ocfs2_journal_dirty(handle, fe_bh); | 1106 | status = ocfs2_journal_dirty(handle, et->et_root_bh); |
795 | if (status < 0) { | 1107 | if (status < 0) { |
796 | mlog_errno(status); | 1108 | mlog_errno(status); |
797 | goto bail; | 1109 | goto bail; |
@@ -801,8 +1113,7 @@ static int ocfs2_shift_tree_depth(struct ocfs2_super *osb, | |||
801 | new_eb_bh = NULL; | 1113 | new_eb_bh = NULL; |
802 | status = 0; | 1114 | status = 0; |
803 | bail: | 1115 | bail: |
804 | if (new_eb_bh) | 1116 | brelse(new_eb_bh); |
805 | brelse(new_eb_bh); | ||
806 | 1117 | ||
807 | mlog_exit(status); | 1118 | mlog_exit(status); |
808 | return status; | 1119 | return status; |
@@ -817,22 +1128,21 @@ bail: | |||
817 | * 1) a lowest extent block is found, then we pass it back in | 1128 | * 1) a lowest extent block is found, then we pass it back in |
818 | * *lowest_eb_bh and return '0' | 1129 | * *lowest_eb_bh and return '0' |
819 | * | 1130 | * |
820 | * 2) the search fails to find anything, but the dinode has room. We | 1131 | * 2) the search fails to find anything, but the root_el has room. We |
821 | * pass NULL back in *lowest_eb_bh, but still return '0' | 1132 | * pass NULL back in *lowest_eb_bh, but still return '0' |
822 | * | 1133 | * |
823 | * 3) the search fails to find anything AND the dinode is full, in | 1134 | * 3) the search fails to find anything AND the root_el is full, in |
824 | * which case we return > 0 | 1135 | * which case we return > 0 |
825 | * | 1136 | * |
826 | * return status < 0 indicates an error. | 1137 | * return status < 0 indicates an error. |
827 | */ | 1138 | */ |
828 | static int ocfs2_find_branch_target(struct ocfs2_super *osb, | 1139 | static int ocfs2_find_branch_target(struct ocfs2_super *osb, |
829 | struct inode *inode, | 1140 | struct inode *inode, |
830 | struct buffer_head *fe_bh, | 1141 | struct ocfs2_extent_tree *et, |
831 | struct buffer_head **target_bh) | 1142 | struct buffer_head **target_bh) |
832 | { | 1143 | { |
833 | int status = 0, i; | 1144 | int status = 0, i; |
834 | u64 blkno; | 1145 | u64 blkno; |
835 | struct ocfs2_dinode *fe; | ||
836 | struct ocfs2_extent_block *eb; | 1146 | struct ocfs2_extent_block *eb; |
837 | struct ocfs2_extent_list *el; | 1147 | struct ocfs2_extent_list *el; |
838 | struct buffer_head *bh = NULL; | 1148 | struct buffer_head *bh = NULL; |
@@ -842,8 +1152,7 @@ static int ocfs2_find_branch_target(struct ocfs2_super *osb, | |||
842 | 1152 | ||
843 | *target_bh = NULL; | 1153 | *target_bh = NULL; |
844 | 1154 | ||
845 | fe = (struct ocfs2_dinode *) fe_bh->b_data; | 1155 | el = et->et_root_el; |
846 | el = &fe->id2.i_list; | ||
847 | 1156 | ||
848 | while(le16_to_cpu(el->l_tree_depth) > 1) { | 1157 | while(le16_to_cpu(el->l_tree_depth) > 1) { |
849 | if (le16_to_cpu(el->l_next_free_rec) == 0) { | 1158 | if (le16_to_cpu(el->l_next_free_rec) == 0) { |
@@ -864,13 +1173,10 @@ static int ocfs2_find_branch_target(struct ocfs2_super *osb, | |||
864 | goto bail; | 1173 | goto bail; |
865 | } | 1174 | } |
866 | 1175 | ||
867 | if (bh) { | 1176 | brelse(bh); |
868 | brelse(bh); | 1177 | bh = NULL; |
869 | bh = NULL; | ||
870 | } | ||
871 | 1178 | ||
872 | status = ocfs2_read_block(osb, blkno, &bh, OCFS2_BH_CACHED, | 1179 | status = ocfs2_read_block(inode, blkno, &bh); |
873 | inode); | ||
874 | if (status < 0) { | 1180 | if (status < 0) { |
875 | mlog_errno(status); | 1181 | mlog_errno(status); |
876 | goto bail; | 1182 | goto bail; |
@@ -886,8 +1192,7 @@ static int ocfs2_find_branch_target(struct ocfs2_super *osb, | |||
886 | 1192 | ||
887 | if (le16_to_cpu(el->l_next_free_rec) < | 1193 | if (le16_to_cpu(el->l_next_free_rec) < |
888 | le16_to_cpu(el->l_count)) { | 1194 | le16_to_cpu(el->l_count)) { |
889 | if (lowest_bh) | 1195 | brelse(lowest_bh); |
890 | brelse(lowest_bh); | ||
891 | lowest_bh = bh; | 1196 | lowest_bh = bh; |
892 | get_bh(lowest_bh); | 1197 | get_bh(lowest_bh); |
893 | } | 1198 | } |
@@ -895,14 +1200,13 @@ static int ocfs2_find_branch_target(struct ocfs2_super *osb, | |||
895 | 1200 | ||
896 | /* If we didn't find one and the fe doesn't have any room, | 1201 | /* If we didn't find one and the fe doesn't have any room, |
897 | * then return '1' */ | 1202 | * then return '1' */ |
898 | if (!lowest_bh | 1203 | el = et->et_root_el; |
899 | && (fe->id2.i_list.l_next_free_rec == fe->id2.i_list.l_count)) | 1204 | if (!lowest_bh && (el->l_next_free_rec == el->l_count)) |
900 | status = 1; | 1205 | status = 1; |
901 | 1206 | ||
902 | *target_bh = lowest_bh; | 1207 | *target_bh = lowest_bh; |
903 | bail: | 1208 | bail: |
904 | if (bh) | 1209 | brelse(bh); |
905 | brelse(bh); | ||
906 | 1210 | ||
907 | mlog_exit(status); | 1211 | mlog_exit(status); |
908 | return status; | 1212 | return status; |
@@ -919,19 +1223,19 @@ bail: | |||
919 | * *last_eb_bh will be updated by ocfs2_add_branch(). | 1223 | * *last_eb_bh will be updated by ocfs2_add_branch(). |
920 | */ | 1224 | */ |
921 | static int ocfs2_grow_tree(struct inode *inode, handle_t *handle, | 1225 | static int ocfs2_grow_tree(struct inode *inode, handle_t *handle, |
922 | struct buffer_head *di_bh, int *final_depth, | 1226 | struct ocfs2_extent_tree *et, int *final_depth, |
923 | struct buffer_head **last_eb_bh, | 1227 | struct buffer_head **last_eb_bh, |
924 | struct ocfs2_alloc_context *meta_ac) | 1228 | struct ocfs2_alloc_context *meta_ac) |
925 | { | 1229 | { |
926 | int ret, shift; | 1230 | int ret, shift; |
927 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; | 1231 | struct ocfs2_extent_list *el = et->et_root_el; |
928 | int depth = le16_to_cpu(di->id2.i_list.l_tree_depth); | 1232 | int depth = le16_to_cpu(el->l_tree_depth); |
929 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | 1233 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); |
930 | struct buffer_head *bh = NULL; | 1234 | struct buffer_head *bh = NULL; |
931 | 1235 | ||
932 | BUG_ON(meta_ac == NULL); | 1236 | BUG_ON(meta_ac == NULL); |
933 | 1237 | ||
934 | shift = ocfs2_find_branch_target(osb, inode, di_bh, &bh); | 1238 | shift = ocfs2_find_branch_target(osb, inode, et, &bh); |
935 | if (shift < 0) { | 1239 | if (shift < 0) { |
936 | ret = shift; | 1240 | ret = shift; |
937 | mlog_errno(ret); | 1241 | mlog_errno(ret); |
@@ -948,7 +1252,7 @@ static int ocfs2_grow_tree(struct inode *inode, handle_t *handle, | |||
948 | /* ocfs2_shift_tree_depth will return us a buffer with | 1252 | /* ocfs2_shift_tree_depth will return us a buffer with |
949 | * the new extent block (so we can pass that to | 1253 | * the new extent block (so we can pass that to |
950 | * ocfs2_add_branch). */ | 1254 | * ocfs2_add_branch). */ |
951 | ret = ocfs2_shift_tree_depth(osb, handle, inode, di_bh, | 1255 | ret = ocfs2_shift_tree_depth(osb, handle, inode, et, |
952 | meta_ac, &bh); | 1256 | meta_ac, &bh); |
953 | if (ret < 0) { | 1257 | if (ret < 0) { |
954 | mlog_errno(ret); | 1258 | mlog_errno(ret); |
@@ -975,7 +1279,7 @@ static int ocfs2_grow_tree(struct inode *inode, handle_t *handle, | |||
975 | /* call ocfs2_add_branch to add the final part of the tree with | 1279 | /* call ocfs2_add_branch to add the final part of the tree with |
976 | * the new data. */ | 1280 | * the new data. */ |
977 | mlog(0, "add branch. bh = %p\n", bh); | 1281 | mlog(0, "add branch. bh = %p\n", bh); |
978 | ret = ocfs2_add_branch(osb, handle, inode, di_bh, bh, last_eb_bh, | 1282 | ret = ocfs2_add_branch(osb, handle, inode, et, bh, last_eb_bh, |
979 | meta_ac); | 1283 | meta_ac); |
980 | if (ret < 0) { | 1284 | if (ret < 0) { |
981 | mlog_errno(ret); | 1285 | mlog_errno(ret); |
@@ -1236,8 +1540,7 @@ static int __ocfs2_find_path(struct inode *inode, | |||
1236 | 1540 | ||
1237 | brelse(bh); | 1541 | brelse(bh); |
1238 | bh = NULL; | 1542 | bh = NULL; |
1239 | ret = ocfs2_read_block(OCFS2_SB(inode->i_sb), blkno, | 1543 | ret = ocfs2_read_block(inode, blkno, &bh); |
1240 | &bh, OCFS2_BH_CACHED, inode); | ||
1241 | if (ret) { | 1544 | if (ret) { |
1242 | mlog_errno(ret); | 1545 | mlog_errno(ret); |
1243 | goto out; | 1546 | goto out; |
@@ -2058,11 +2361,11 @@ static int ocfs2_rotate_subtree_left(struct inode *inode, handle_t *handle, | |||
2058 | struct ocfs2_path *right_path, | 2361 | struct ocfs2_path *right_path, |
2059 | int subtree_index, | 2362 | int subtree_index, |
2060 | struct ocfs2_cached_dealloc_ctxt *dealloc, | 2363 | struct ocfs2_cached_dealloc_ctxt *dealloc, |
2061 | int *deleted) | 2364 | int *deleted, |
2365 | struct ocfs2_extent_tree *et) | ||
2062 | { | 2366 | { |
2063 | int ret, i, del_right_subtree = 0, right_has_empty = 0; | 2367 | int ret, i, del_right_subtree = 0, right_has_empty = 0; |
2064 | struct buffer_head *root_bh, *di_bh = path_root_bh(right_path); | 2368 | struct buffer_head *root_bh, *et_root_bh = path_root_bh(right_path); |
2065 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; | ||
2066 | struct ocfs2_extent_list *right_leaf_el, *left_leaf_el; | 2369 | struct ocfs2_extent_list *right_leaf_el, *left_leaf_el; |
2067 | struct ocfs2_extent_block *eb; | 2370 | struct ocfs2_extent_block *eb; |
2068 | 2371 | ||
@@ -2114,7 +2417,7 @@ static int ocfs2_rotate_subtree_left(struct inode *inode, handle_t *handle, | |||
2114 | * We have to update i_last_eb_blk during the meta | 2417 | * We have to update i_last_eb_blk during the meta |
2115 | * data delete. | 2418 | * data delete. |
2116 | */ | 2419 | */ |
2117 | ret = ocfs2_journal_access(handle, inode, di_bh, | 2420 | ret = ocfs2_journal_access(handle, inode, et_root_bh, |
2118 | OCFS2_JOURNAL_ACCESS_WRITE); | 2421 | OCFS2_JOURNAL_ACCESS_WRITE); |
2119 | if (ret) { | 2422 | if (ret) { |
2120 | mlog_errno(ret); | 2423 | mlog_errno(ret); |
@@ -2189,7 +2492,7 @@ static int ocfs2_rotate_subtree_left(struct inode *inode, handle_t *handle, | |||
2189 | ocfs2_update_edge_lengths(inode, handle, left_path); | 2492 | ocfs2_update_edge_lengths(inode, handle, left_path); |
2190 | 2493 | ||
2191 | eb = (struct ocfs2_extent_block *)path_leaf_bh(left_path)->b_data; | 2494 | eb = (struct ocfs2_extent_block *)path_leaf_bh(left_path)->b_data; |
2192 | di->i_last_eb_blk = eb->h_blkno; | 2495 | ocfs2_et_set_last_eb_blk(et, le64_to_cpu(eb->h_blkno)); |
2193 | 2496 | ||
2194 | /* | 2497 | /* |
2195 | * Removal of the extent in the left leaf was skipped | 2498 | * Removal of the extent in the left leaf was skipped |
@@ -2199,7 +2502,7 @@ static int ocfs2_rotate_subtree_left(struct inode *inode, handle_t *handle, | |||
2199 | if (right_has_empty) | 2502 | if (right_has_empty) |
2200 | ocfs2_remove_empty_extent(left_leaf_el); | 2503 | ocfs2_remove_empty_extent(left_leaf_el); |
2201 | 2504 | ||
2202 | ret = ocfs2_journal_dirty(handle, di_bh); | 2505 | ret = ocfs2_journal_dirty(handle, et_root_bh); |
2203 | if (ret) | 2506 | if (ret) |
2204 | mlog_errno(ret); | 2507 | mlog_errno(ret); |
2205 | 2508 | ||
@@ -2322,7 +2625,8 @@ static int __ocfs2_rotate_tree_left(struct inode *inode, | |||
2322 | handle_t *handle, int orig_credits, | 2625 | handle_t *handle, int orig_credits, |
2323 | struct ocfs2_path *path, | 2626 | struct ocfs2_path *path, |
2324 | struct ocfs2_cached_dealloc_ctxt *dealloc, | 2627 | struct ocfs2_cached_dealloc_ctxt *dealloc, |
2325 | struct ocfs2_path **empty_extent_path) | 2628 | struct ocfs2_path **empty_extent_path, |
2629 | struct ocfs2_extent_tree *et) | ||
2326 | { | 2630 | { |
2327 | int ret, subtree_root, deleted; | 2631 | int ret, subtree_root, deleted; |
2328 | u32 right_cpos; | 2632 | u32 right_cpos; |
@@ -2395,7 +2699,7 @@ static int __ocfs2_rotate_tree_left(struct inode *inode, | |||
2395 | 2699 | ||
2396 | ret = ocfs2_rotate_subtree_left(inode, handle, left_path, | 2700 | ret = ocfs2_rotate_subtree_left(inode, handle, left_path, |
2397 | right_path, subtree_root, | 2701 | right_path, subtree_root, |
2398 | dealloc, &deleted); | 2702 | dealloc, &deleted, et); |
2399 | if (ret == -EAGAIN) { | 2703 | if (ret == -EAGAIN) { |
2400 | /* | 2704 | /* |
2401 | * The rotation has to temporarily stop due to | 2705 | * The rotation has to temporarily stop due to |
@@ -2438,29 +2742,20 @@ out: | |||
2438 | } | 2742 | } |
2439 | 2743 | ||
2440 | static int ocfs2_remove_rightmost_path(struct inode *inode, handle_t *handle, | 2744 | static int ocfs2_remove_rightmost_path(struct inode *inode, handle_t *handle, |
2441 | struct ocfs2_path *path, | 2745 | struct ocfs2_path *path, |
2442 | struct ocfs2_cached_dealloc_ctxt *dealloc) | 2746 | struct ocfs2_cached_dealloc_ctxt *dealloc, |
2747 | struct ocfs2_extent_tree *et) | ||
2443 | { | 2748 | { |
2444 | int ret, subtree_index; | 2749 | int ret, subtree_index; |
2445 | u32 cpos; | 2750 | u32 cpos; |
2446 | struct ocfs2_path *left_path = NULL; | 2751 | struct ocfs2_path *left_path = NULL; |
2447 | struct ocfs2_dinode *di; | ||
2448 | struct ocfs2_extent_block *eb; | 2752 | struct ocfs2_extent_block *eb; |
2449 | struct ocfs2_extent_list *el; | 2753 | struct ocfs2_extent_list *el; |
2450 | 2754 | ||
2451 | /* | ||
2452 | * XXX: This code assumes that the root is an inode, which is | ||
2453 | * true for now but may change as tree code gets generic. | ||
2454 | */ | ||
2455 | di = (struct ocfs2_dinode *)path_root_bh(path)->b_data; | ||
2456 | if (!OCFS2_IS_VALID_DINODE(di)) { | ||
2457 | ret = -EIO; | ||
2458 | ocfs2_error(inode->i_sb, | ||
2459 | "Inode %llu has invalid path root", | ||
2460 | (unsigned long long)OCFS2_I(inode)->ip_blkno); | ||
2461 | goto out; | ||
2462 | } | ||
2463 | 2755 | ||
2756 | ret = ocfs2_et_sanity_check(inode, et); | ||
2757 | if (ret) | ||
2758 | goto out; | ||
2464 | /* | 2759 | /* |
2465 | * There's two ways we handle this depending on | 2760 | * There's two ways we handle this depending on |
2466 | * whether path is the only existing one. | 2761 | * whether path is the only existing one. |
@@ -2517,7 +2812,7 @@ static int ocfs2_remove_rightmost_path(struct inode *inode, handle_t *handle, | |||
2517 | ocfs2_update_edge_lengths(inode, handle, left_path); | 2812 | ocfs2_update_edge_lengths(inode, handle, left_path); |
2518 | 2813 | ||
2519 | eb = (struct ocfs2_extent_block *)path_leaf_bh(left_path)->b_data; | 2814 | eb = (struct ocfs2_extent_block *)path_leaf_bh(left_path)->b_data; |
2520 | di->i_last_eb_blk = eb->h_blkno; | 2815 | ocfs2_et_set_last_eb_blk(et, le64_to_cpu(eb->h_blkno)); |
2521 | } else { | 2816 | } else { |
2522 | /* | 2817 | /* |
2523 | * 'path' is also the leftmost path which | 2818 | * 'path' is also the leftmost path which |
@@ -2528,12 +2823,12 @@ static int ocfs2_remove_rightmost_path(struct inode *inode, handle_t *handle, | |||
2528 | */ | 2823 | */ |
2529 | ocfs2_unlink_path(inode, handle, dealloc, path, 1); | 2824 | ocfs2_unlink_path(inode, handle, dealloc, path, 1); |
2530 | 2825 | ||
2531 | el = &di->id2.i_list; | 2826 | el = et->et_root_el; |
2532 | el->l_tree_depth = 0; | 2827 | el->l_tree_depth = 0; |
2533 | el->l_next_free_rec = 0; | 2828 | el->l_next_free_rec = 0; |
2534 | memset(&el->l_recs[0], 0, sizeof(struct ocfs2_extent_rec)); | 2829 | memset(&el->l_recs[0], 0, sizeof(struct ocfs2_extent_rec)); |
2535 | 2830 | ||
2536 | di->i_last_eb_blk = 0; | 2831 | ocfs2_et_set_last_eb_blk(et, 0); |
2537 | } | 2832 | } |
2538 | 2833 | ||
2539 | ocfs2_journal_dirty(handle, path_root_bh(path)); | 2834 | ocfs2_journal_dirty(handle, path_root_bh(path)); |
@@ -2561,7 +2856,8 @@ out: | |||
2561 | */ | 2856 | */ |
2562 | static int ocfs2_rotate_tree_left(struct inode *inode, handle_t *handle, | 2857 | static int ocfs2_rotate_tree_left(struct inode *inode, handle_t *handle, |
2563 | struct ocfs2_path *path, | 2858 | struct ocfs2_path *path, |
2564 | struct ocfs2_cached_dealloc_ctxt *dealloc) | 2859 | struct ocfs2_cached_dealloc_ctxt *dealloc, |
2860 | struct ocfs2_extent_tree *et) | ||
2565 | { | 2861 | { |
2566 | int ret, orig_credits = handle->h_buffer_credits; | 2862 | int ret, orig_credits = handle->h_buffer_credits; |
2567 | struct ocfs2_path *tmp_path = NULL, *restart_path = NULL; | 2863 | struct ocfs2_path *tmp_path = NULL, *restart_path = NULL; |
@@ -2575,7 +2871,7 @@ static int ocfs2_rotate_tree_left(struct inode *inode, handle_t *handle, | |||
2575 | if (path->p_tree_depth == 0) { | 2871 | if (path->p_tree_depth == 0) { |
2576 | rightmost_no_delete: | 2872 | rightmost_no_delete: |
2577 | /* | 2873 | /* |
2578 | * In-inode extents. This is trivially handled, so do | 2874 | * Inline extents. This is trivially handled, so do |
2579 | * it up front. | 2875 | * it up front. |
2580 | */ | 2876 | */ |
2581 | ret = ocfs2_rotate_rightmost_leaf_left(inode, handle, | 2877 | ret = ocfs2_rotate_rightmost_leaf_left(inode, handle, |
@@ -2629,7 +2925,7 @@ rightmost_no_delete: | |||
2629 | */ | 2925 | */ |
2630 | 2926 | ||
2631 | ret = ocfs2_remove_rightmost_path(inode, handle, path, | 2927 | ret = ocfs2_remove_rightmost_path(inode, handle, path, |
2632 | dealloc); | 2928 | dealloc, et); |
2633 | if (ret) | 2929 | if (ret) |
2634 | mlog_errno(ret); | 2930 | mlog_errno(ret); |
2635 | goto out; | 2931 | goto out; |
@@ -2641,7 +2937,7 @@ rightmost_no_delete: | |||
2641 | */ | 2937 | */ |
2642 | try_rotate: | 2938 | try_rotate: |
2643 | ret = __ocfs2_rotate_tree_left(inode, handle, orig_credits, path, | 2939 | ret = __ocfs2_rotate_tree_left(inode, handle, orig_credits, path, |
2644 | dealloc, &restart_path); | 2940 | dealloc, &restart_path, et); |
2645 | if (ret && ret != -EAGAIN) { | 2941 | if (ret && ret != -EAGAIN) { |
2646 | mlog_errno(ret); | 2942 | mlog_errno(ret); |
2647 | goto out; | 2943 | goto out; |
@@ -2653,7 +2949,7 @@ try_rotate: | |||
2653 | 2949 | ||
2654 | ret = __ocfs2_rotate_tree_left(inode, handle, orig_credits, | 2950 | ret = __ocfs2_rotate_tree_left(inode, handle, orig_credits, |
2655 | tmp_path, dealloc, | 2951 | tmp_path, dealloc, |
2656 | &restart_path); | 2952 | &restart_path, et); |
2657 | if (ret && ret != -EAGAIN) { | 2953 | if (ret && ret != -EAGAIN) { |
2658 | mlog_errno(ret); | 2954 | mlog_errno(ret); |
2659 | goto out; | 2955 | goto out; |
@@ -2939,6 +3235,7 @@ static int ocfs2_merge_rec_left(struct inode *inode, | |||
2939 | handle_t *handle, | 3235 | handle_t *handle, |
2940 | struct ocfs2_extent_rec *split_rec, | 3236 | struct ocfs2_extent_rec *split_rec, |
2941 | struct ocfs2_cached_dealloc_ctxt *dealloc, | 3237 | struct ocfs2_cached_dealloc_ctxt *dealloc, |
3238 | struct ocfs2_extent_tree *et, | ||
2942 | int index) | 3239 | int index) |
2943 | { | 3240 | { |
2944 | int ret, i, subtree_index = 0, has_empty_extent = 0; | 3241 | int ret, i, subtree_index = 0, has_empty_extent = 0; |
@@ -3059,7 +3356,8 @@ static int ocfs2_merge_rec_left(struct inode *inode, | |||
3059 | le16_to_cpu(el->l_next_free_rec) == 1) { | 3356 | le16_to_cpu(el->l_next_free_rec) == 1) { |
3060 | 3357 | ||
3061 | ret = ocfs2_remove_rightmost_path(inode, handle, | 3358 | ret = ocfs2_remove_rightmost_path(inode, handle, |
3062 | right_path, dealloc); | 3359 | right_path, |
3360 | dealloc, et); | ||
3063 | if (ret) { | 3361 | if (ret) { |
3064 | mlog_errno(ret); | 3362 | mlog_errno(ret); |
3065 | goto out; | 3363 | goto out; |
@@ -3086,7 +3384,8 @@ static int ocfs2_try_to_merge_extent(struct inode *inode, | |||
3086 | int split_index, | 3384 | int split_index, |
3087 | struct ocfs2_extent_rec *split_rec, | 3385 | struct ocfs2_extent_rec *split_rec, |
3088 | struct ocfs2_cached_dealloc_ctxt *dealloc, | 3386 | struct ocfs2_cached_dealloc_ctxt *dealloc, |
3089 | struct ocfs2_merge_ctxt *ctxt) | 3387 | struct ocfs2_merge_ctxt *ctxt, |
3388 | struct ocfs2_extent_tree *et) | ||
3090 | 3389 | ||
3091 | { | 3390 | { |
3092 | int ret = 0; | 3391 | int ret = 0; |
@@ -3104,7 +3403,7 @@ static int ocfs2_try_to_merge_extent(struct inode *inode, | |||
3104 | * illegal. | 3403 | * illegal. |
3105 | */ | 3404 | */ |
3106 | ret = ocfs2_rotate_tree_left(inode, handle, path, | 3405 | ret = ocfs2_rotate_tree_left(inode, handle, path, |
3107 | dealloc); | 3406 | dealloc, et); |
3108 | if (ret) { | 3407 | if (ret) { |
3109 | mlog_errno(ret); | 3408 | mlog_errno(ret); |
3110 | goto out; | 3409 | goto out; |
@@ -3147,7 +3446,8 @@ static int ocfs2_try_to_merge_extent(struct inode *inode, | |||
3147 | BUG_ON(!ocfs2_is_empty_extent(&el->l_recs[0])); | 3446 | BUG_ON(!ocfs2_is_empty_extent(&el->l_recs[0])); |
3148 | 3447 | ||
3149 | /* The merge left us with an empty extent, remove it. */ | 3448 | /* The merge left us with an empty extent, remove it. */ |
3150 | ret = ocfs2_rotate_tree_left(inode, handle, path, dealloc); | 3449 | ret = ocfs2_rotate_tree_left(inode, handle, path, |
3450 | dealloc, et); | ||
3151 | if (ret) { | 3451 | if (ret) { |
3152 | mlog_errno(ret); | 3452 | mlog_errno(ret); |
3153 | goto out; | 3453 | goto out; |
@@ -3161,7 +3461,7 @@ static int ocfs2_try_to_merge_extent(struct inode *inode, | |||
3161 | */ | 3461 | */ |
3162 | ret = ocfs2_merge_rec_left(inode, path, | 3462 | ret = ocfs2_merge_rec_left(inode, path, |
3163 | handle, rec, | 3463 | handle, rec, |
3164 | dealloc, | 3464 | dealloc, et, |
3165 | split_index); | 3465 | split_index); |
3166 | 3466 | ||
3167 | if (ret) { | 3467 | if (ret) { |
@@ -3170,7 +3470,7 @@ static int ocfs2_try_to_merge_extent(struct inode *inode, | |||
3170 | } | 3470 | } |
3171 | 3471 | ||
3172 | ret = ocfs2_rotate_tree_left(inode, handle, path, | 3472 | ret = ocfs2_rotate_tree_left(inode, handle, path, |
3173 | dealloc); | 3473 | dealloc, et); |
3174 | /* | 3474 | /* |
3175 | * Error from this last rotate is not critical, so | 3475 | * Error from this last rotate is not critical, so |
3176 | * print but don't bubble it up. | 3476 | * print but don't bubble it up. |
@@ -3190,7 +3490,7 @@ static int ocfs2_try_to_merge_extent(struct inode *inode, | |||
3190 | ret = ocfs2_merge_rec_left(inode, | 3490 | ret = ocfs2_merge_rec_left(inode, |
3191 | path, | 3491 | path, |
3192 | handle, split_rec, | 3492 | handle, split_rec, |
3193 | dealloc, | 3493 | dealloc, et, |
3194 | split_index); | 3494 | split_index); |
3195 | if (ret) { | 3495 | if (ret) { |
3196 | mlog_errno(ret); | 3496 | mlog_errno(ret); |
@@ -3213,7 +3513,7 @@ static int ocfs2_try_to_merge_extent(struct inode *inode, | |||
3213 | * our leaf. Try to rotate it away. | 3513 | * our leaf. Try to rotate it away. |
3214 | */ | 3514 | */ |
3215 | ret = ocfs2_rotate_tree_left(inode, handle, path, | 3515 | ret = ocfs2_rotate_tree_left(inode, handle, path, |
3216 | dealloc); | 3516 | dealloc, et); |
3217 | if (ret) | 3517 | if (ret) |
3218 | mlog_errno(ret); | 3518 | mlog_errno(ret); |
3219 | ret = 0; | 3519 | ret = 0; |
@@ -3347,16 +3647,6 @@ rotate: | |||
3347 | ocfs2_rotate_leaf(el, insert_rec); | 3647 | ocfs2_rotate_leaf(el, insert_rec); |
3348 | } | 3648 | } |
3349 | 3649 | ||
3350 | static inline void ocfs2_update_dinode_clusters(struct inode *inode, | ||
3351 | struct ocfs2_dinode *di, | ||
3352 | u32 clusters) | ||
3353 | { | ||
3354 | le32_add_cpu(&di->i_clusters, clusters); | ||
3355 | spin_lock(&OCFS2_I(inode)->ip_lock); | ||
3356 | OCFS2_I(inode)->ip_clusters = le32_to_cpu(di->i_clusters); | ||
3357 | spin_unlock(&OCFS2_I(inode)->ip_lock); | ||
3358 | } | ||
3359 | |||
3360 | static void ocfs2_adjust_rightmost_records(struct inode *inode, | 3650 | static void ocfs2_adjust_rightmost_records(struct inode *inode, |
3361 | handle_t *handle, | 3651 | handle_t *handle, |
3362 | struct ocfs2_path *path, | 3652 | struct ocfs2_path *path, |
@@ -3558,8 +3848,8 @@ static void ocfs2_split_record(struct inode *inode, | |||
3558 | } | 3848 | } |
3559 | 3849 | ||
3560 | /* | 3850 | /* |
3561 | * This function only does inserts on an allocation b-tree. For dinode | 3851 | * This function only does inserts on an allocation b-tree. For tree |
3562 | * lists, ocfs2_insert_at_leaf() is called directly. | 3852 | * depth = 0, ocfs2_insert_at_leaf() is called directly. |
3563 | * | 3853 | * |
3564 | * right_path is the path we want to do the actual insert | 3854 | * right_path is the path we want to do the actual insert |
3565 | * in. left_path should only be passed in if we need to update that | 3855 | * in. left_path should only be passed in if we need to update that |
@@ -3656,7 +3946,7 @@ out: | |||
3656 | 3946 | ||
3657 | static int ocfs2_do_insert_extent(struct inode *inode, | 3947 | static int ocfs2_do_insert_extent(struct inode *inode, |
3658 | handle_t *handle, | 3948 | handle_t *handle, |
3659 | struct buffer_head *di_bh, | 3949 | struct ocfs2_extent_tree *et, |
3660 | struct ocfs2_extent_rec *insert_rec, | 3950 | struct ocfs2_extent_rec *insert_rec, |
3661 | struct ocfs2_insert_type *type) | 3951 | struct ocfs2_insert_type *type) |
3662 | { | 3952 | { |
@@ -3664,13 +3954,11 @@ static int ocfs2_do_insert_extent(struct inode *inode, | |||
3664 | u32 cpos; | 3954 | u32 cpos; |
3665 | struct ocfs2_path *right_path = NULL; | 3955 | struct ocfs2_path *right_path = NULL; |
3666 | struct ocfs2_path *left_path = NULL; | 3956 | struct ocfs2_path *left_path = NULL; |
3667 | struct ocfs2_dinode *di; | ||
3668 | struct ocfs2_extent_list *el; | 3957 | struct ocfs2_extent_list *el; |
3669 | 3958 | ||
3670 | di = (struct ocfs2_dinode *) di_bh->b_data; | 3959 | el = et->et_root_el; |
3671 | el = &di->id2.i_list; | ||
3672 | 3960 | ||
3673 | ret = ocfs2_journal_access(handle, inode, di_bh, | 3961 | ret = ocfs2_journal_access(handle, inode, et->et_root_bh, |
3674 | OCFS2_JOURNAL_ACCESS_WRITE); | 3962 | OCFS2_JOURNAL_ACCESS_WRITE); |
3675 | if (ret) { | 3963 | if (ret) { |
3676 | mlog_errno(ret); | 3964 | mlog_errno(ret); |
@@ -3682,7 +3970,7 @@ static int ocfs2_do_insert_extent(struct inode *inode, | |||
3682 | goto out_update_clusters; | 3970 | goto out_update_clusters; |
3683 | } | 3971 | } |
3684 | 3972 | ||
3685 | right_path = ocfs2_new_inode_path(di_bh); | 3973 | right_path = ocfs2_new_path(et->et_root_bh, et->et_root_el); |
3686 | if (!right_path) { | 3974 | if (!right_path) { |
3687 | ret = -ENOMEM; | 3975 | ret = -ENOMEM; |
3688 | mlog_errno(ret); | 3976 | mlog_errno(ret); |
@@ -3732,7 +4020,7 @@ static int ocfs2_do_insert_extent(struct inode *inode, | |||
3732 | * ocfs2_rotate_tree_right() might have extended the | 4020 | * ocfs2_rotate_tree_right() might have extended the |
3733 | * transaction without re-journaling our tree root. | 4021 | * transaction without re-journaling our tree root. |
3734 | */ | 4022 | */ |
3735 | ret = ocfs2_journal_access(handle, inode, di_bh, | 4023 | ret = ocfs2_journal_access(handle, inode, et->et_root_bh, |
3736 | OCFS2_JOURNAL_ACCESS_WRITE); | 4024 | OCFS2_JOURNAL_ACCESS_WRITE); |
3737 | if (ret) { | 4025 | if (ret) { |
3738 | mlog_errno(ret); | 4026 | mlog_errno(ret); |
@@ -3757,10 +4045,10 @@ static int ocfs2_do_insert_extent(struct inode *inode, | |||
3757 | 4045 | ||
3758 | out_update_clusters: | 4046 | out_update_clusters: |
3759 | if (type->ins_split == SPLIT_NONE) | 4047 | if (type->ins_split == SPLIT_NONE) |
3760 | ocfs2_update_dinode_clusters(inode, di, | 4048 | ocfs2_et_update_clusters(inode, et, |
3761 | le16_to_cpu(insert_rec->e_leaf_clusters)); | 4049 | le16_to_cpu(insert_rec->e_leaf_clusters)); |
3762 | 4050 | ||
3763 | ret = ocfs2_journal_dirty(handle, di_bh); | 4051 | ret = ocfs2_journal_dirty(handle, et->et_root_bh); |
3764 | if (ret) | 4052 | if (ret) |
3765 | mlog_errno(ret); | 4053 | mlog_errno(ret); |
3766 | 4054 | ||
@@ -3890,7 +4178,8 @@ out: | |||
3890 | static void ocfs2_figure_contig_type(struct inode *inode, | 4178 | static void ocfs2_figure_contig_type(struct inode *inode, |
3891 | struct ocfs2_insert_type *insert, | 4179 | struct ocfs2_insert_type *insert, |
3892 | struct ocfs2_extent_list *el, | 4180 | struct ocfs2_extent_list *el, |
3893 | struct ocfs2_extent_rec *insert_rec) | 4181 | struct ocfs2_extent_rec *insert_rec, |
4182 | struct ocfs2_extent_tree *et) | ||
3894 | { | 4183 | { |
3895 | int i; | 4184 | int i; |
3896 | enum ocfs2_contig_type contig_type = CONTIG_NONE; | 4185 | enum ocfs2_contig_type contig_type = CONTIG_NONE; |
@@ -3906,6 +4195,21 @@ static void ocfs2_figure_contig_type(struct inode *inode, | |||
3906 | } | 4195 | } |
3907 | } | 4196 | } |
3908 | insert->ins_contig = contig_type; | 4197 | insert->ins_contig = contig_type; |
4198 | |||
4199 | if (insert->ins_contig != CONTIG_NONE) { | ||
4200 | struct ocfs2_extent_rec *rec = | ||
4201 | &el->l_recs[insert->ins_contig_index]; | ||
4202 | unsigned int len = le16_to_cpu(rec->e_leaf_clusters) + | ||
4203 | le16_to_cpu(insert_rec->e_leaf_clusters); | ||
4204 | |||
4205 | /* | ||
4206 | * Caller might want us to limit the size of extents, don't | ||
4207 | * calculate contiguousness if we might exceed that limit. | ||
4208 | */ | ||
4209 | if (et->et_max_leaf_clusters && | ||
4210 | (len > et->et_max_leaf_clusters)) | ||
4211 | insert->ins_contig = CONTIG_NONE; | ||
4212 | } | ||
3909 | } | 4213 | } |
3910 | 4214 | ||
3911 | /* | 4215 | /* |
@@ -3914,8 +4218,8 @@ static void ocfs2_figure_contig_type(struct inode *inode, | |||
3914 | * ocfs2_figure_appending_type() will figure out whether we'll have to | 4218 | * ocfs2_figure_appending_type() will figure out whether we'll have to |
3915 | * insert at the tail of the rightmost leaf. | 4219 | * insert at the tail of the rightmost leaf. |
3916 | * | 4220 | * |
3917 | * This should also work against the dinode list for tree's with 0 | 4221 | * This should also work against the root extent list for tree's with 0 |
3918 | * depth. If we consider the dinode list to be the rightmost leaf node | 4222 | * depth. If we consider the root extent list to be the rightmost leaf node |
3919 | * then the logic here makes sense. | 4223 | * then the logic here makes sense. |
3920 | */ | 4224 | */ |
3921 | static void ocfs2_figure_appending_type(struct ocfs2_insert_type *insert, | 4225 | static void ocfs2_figure_appending_type(struct ocfs2_insert_type *insert, |
@@ -3966,14 +4270,13 @@ set_tail_append: | |||
3966 | * structure. | 4270 | * structure. |
3967 | */ | 4271 | */ |
3968 | static int ocfs2_figure_insert_type(struct inode *inode, | 4272 | static int ocfs2_figure_insert_type(struct inode *inode, |
3969 | struct buffer_head *di_bh, | 4273 | struct ocfs2_extent_tree *et, |
3970 | struct buffer_head **last_eb_bh, | 4274 | struct buffer_head **last_eb_bh, |
3971 | struct ocfs2_extent_rec *insert_rec, | 4275 | struct ocfs2_extent_rec *insert_rec, |
3972 | int *free_records, | 4276 | int *free_records, |
3973 | struct ocfs2_insert_type *insert) | 4277 | struct ocfs2_insert_type *insert) |
3974 | { | 4278 | { |
3975 | int ret; | 4279 | int ret; |
3976 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; | ||
3977 | struct ocfs2_extent_block *eb; | 4280 | struct ocfs2_extent_block *eb; |
3978 | struct ocfs2_extent_list *el; | 4281 | struct ocfs2_extent_list *el; |
3979 | struct ocfs2_path *path = NULL; | 4282 | struct ocfs2_path *path = NULL; |
@@ -3981,7 +4284,7 @@ static int ocfs2_figure_insert_type(struct inode *inode, | |||
3981 | 4284 | ||
3982 | insert->ins_split = SPLIT_NONE; | 4285 | insert->ins_split = SPLIT_NONE; |
3983 | 4286 | ||
3984 | el = &di->id2.i_list; | 4287 | el = et->et_root_el; |
3985 | insert->ins_tree_depth = le16_to_cpu(el->l_tree_depth); | 4288 | insert->ins_tree_depth = le16_to_cpu(el->l_tree_depth); |
3986 | 4289 | ||
3987 | if (el->l_tree_depth) { | 4290 | if (el->l_tree_depth) { |
@@ -3991,9 +4294,7 @@ static int ocfs2_figure_insert_type(struct inode *inode, | |||
3991 | * ocfs2_figure_insert_type() and ocfs2_add_branch() | 4294 | * ocfs2_figure_insert_type() and ocfs2_add_branch() |
3992 | * may want it later. | 4295 | * may want it later. |
3993 | */ | 4296 | */ |
3994 | ret = ocfs2_read_block(OCFS2_SB(inode->i_sb), | 4297 | ret = ocfs2_read_block(inode, ocfs2_et_get_last_eb_blk(et), &bh); |
3995 | le64_to_cpu(di->i_last_eb_blk), &bh, | ||
3996 | OCFS2_BH_CACHED, inode); | ||
3997 | if (ret) { | 4298 | if (ret) { |
3998 | mlog_exit(ret); | 4299 | mlog_exit(ret); |
3999 | goto out; | 4300 | goto out; |
@@ -4014,12 +4315,12 @@ static int ocfs2_figure_insert_type(struct inode *inode, | |||
4014 | le16_to_cpu(el->l_next_free_rec); | 4315 | le16_to_cpu(el->l_next_free_rec); |
4015 | 4316 | ||
4016 | if (!insert->ins_tree_depth) { | 4317 | if (!insert->ins_tree_depth) { |
4017 | ocfs2_figure_contig_type(inode, insert, el, insert_rec); | 4318 | ocfs2_figure_contig_type(inode, insert, el, insert_rec, et); |
4018 | ocfs2_figure_appending_type(insert, el, insert_rec); | 4319 | ocfs2_figure_appending_type(insert, el, insert_rec); |
4019 | return 0; | 4320 | return 0; |
4020 | } | 4321 | } |
4021 | 4322 | ||
4022 | path = ocfs2_new_inode_path(di_bh); | 4323 | path = ocfs2_new_path(et->et_root_bh, et->et_root_el); |
4023 | if (!path) { | 4324 | if (!path) { |
4024 | ret = -ENOMEM; | 4325 | ret = -ENOMEM; |
4025 | mlog_errno(ret); | 4326 | mlog_errno(ret); |
@@ -4048,7 +4349,7 @@ static int ocfs2_figure_insert_type(struct inode *inode, | |||
4048 | * into two types of appends: simple record append, or a | 4349 | * into two types of appends: simple record append, or a |
4049 | * rotate inside the tail leaf. | 4350 | * rotate inside the tail leaf. |
4050 | */ | 4351 | */ |
4051 | ocfs2_figure_contig_type(inode, insert, el, insert_rec); | 4352 | ocfs2_figure_contig_type(inode, insert, el, insert_rec, et); |
4052 | 4353 | ||
4053 | /* | 4354 | /* |
4054 | * The insert code isn't quite ready to deal with all cases of | 4355 | * The insert code isn't quite ready to deal with all cases of |
@@ -4069,7 +4370,8 @@ static int ocfs2_figure_insert_type(struct inode *inode, | |||
4069 | * the case that we're doing a tail append, so maybe we can | 4370 | * the case that we're doing a tail append, so maybe we can |
4070 | * take advantage of that information somehow. | 4371 | * take advantage of that information somehow. |
4071 | */ | 4372 | */ |
4072 | if (le64_to_cpu(di->i_last_eb_blk) == path_leaf_bh(path)->b_blocknr) { | 4373 | if (ocfs2_et_get_last_eb_blk(et) == |
4374 | path_leaf_bh(path)->b_blocknr) { | ||
4073 | /* | 4375 | /* |
4074 | * Ok, ocfs2_find_path() returned us the rightmost | 4376 | * Ok, ocfs2_find_path() returned us the rightmost |
4075 | * tree path. This might be an appending insert. There are | 4377 | * tree path. This might be an appending insert. There are |
@@ -4099,7 +4401,7 @@ out: | |||
4099 | int ocfs2_insert_extent(struct ocfs2_super *osb, | 4401 | int ocfs2_insert_extent(struct ocfs2_super *osb, |
4100 | handle_t *handle, | 4402 | handle_t *handle, |
4101 | struct inode *inode, | 4403 | struct inode *inode, |
4102 | struct buffer_head *fe_bh, | 4404 | struct ocfs2_extent_tree *et, |
4103 | u32 cpos, | 4405 | u32 cpos, |
4104 | u64 start_blk, | 4406 | u64 start_blk, |
4105 | u32 new_clusters, | 4407 | u32 new_clusters, |
@@ -4112,26 +4414,21 @@ int ocfs2_insert_extent(struct ocfs2_super *osb, | |||
4112 | struct ocfs2_insert_type insert = {0, }; | 4414 | struct ocfs2_insert_type insert = {0, }; |
4113 | struct ocfs2_extent_rec rec; | 4415 | struct ocfs2_extent_rec rec; |
4114 | 4416 | ||
4115 | BUG_ON(OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL); | ||
4116 | |||
4117 | mlog(0, "add %u clusters at position %u to inode %llu\n", | 4417 | mlog(0, "add %u clusters at position %u to inode %llu\n", |
4118 | new_clusters, cpos, (unsigned long long)OCFS2_I(inode)->ip_blkno); | 4418 | new_clusters, cpos, (unsigned long long)OCFS2_I(inode)->ip_blkno); |
4119 | 4419 | ||
4120 | mlog_bug_on_msg(!ocfs2_sparse_alloc(osb) && | ||
4121 | (OCFS2_I(inode)->ip_clusters != cpos), | ||
4122 | "Device %s, asking for sparse allocation: inode %llu, " | ||
4123 | "cpos %u, clusters %u\n", | ||
4124 | osb->dev_str, | ||
4125 | (unsigned long long)OCFS2_I(inode)->ip_blkno, cpos, | ||
4126 | OCFS2_I(inode)->ip_clusters); | ||
4127 | |||
4128 | memset(&rec, 0, sizeof(rec)); | 4420 | memset(&rec, 0, sizeof(rec)); |
4129 | rec.e_cpos = cpu_to_le32(cpos); | 4421 | rec.e_cpos = cpu_to_le32(cpos); |
4130 | rec.e_blkno = cpu_to_le64(start_blk); | 4422 | rec.e_blkno = cpu_to_le64(start_blk); |
4131 | rec.e_leaf_clusters = cpu_to_le16(new_clusters); | 4423 | rec.e_leaf_clusters = cpu_to_le16(new_clusters); |
4132 | rec.e_flags = flags; | 4424 | rec.e_flags = flags; |
4425 | status = ocfs2_et_insert_check(inode, et, &rec); | ||
4426 | if (status) { | ||
4427 | mlog_errno(status); | ||
4428 | goto bail; | ||
4429 | } | ||
4133 | 4430 | ||
4134 | status = ocfs2_figure_insert_type(inode, fe_bh, &last_eb_bh, &rec, | 4431 | status = ocfs2_figure_insert_type(inode, et, &last_eb_bh, &rec, |
4135 | &free_records, &insert); | 4432 | &free_records, &insert); |
4136 | if (status < 0) { | 4433 | if (status < 0) { |
4137 | mlog_errno(status); | 4434 | mlog_errno(status); |
@@ -4145,7 +4442,7 @@ int ocfs2_insert_extent(struct ocfs2_super *osb, | |||
4145 | free_records, insert.ins_tree_depth); | 4442 | free_records, insert.ins_tree_depth); |
4146 | 4443 | ||
4147 | if (insert.ins_contig == CONTIG_NONE && free_records == 0) { | 4444 | if (insert.ins_contig == CONTIG_NONE && free_records == 0) { |
4148 | status = ocfs2_grow_tree(inode, handle, fe_bh, | 4445 | status = ocfs2_grow_tree(inode, handle, et, |
4149 | &insert.ins_tree_depth, &last_eb_bh, | 4446 | &insert.ins_tree_depth, &last_eb_bh, |
4150 | meta_ac); | 4447 | meta_ac); |
4151 | if (status) { | 4448 | if (status) { |
@@ -4155,17 +4452,124 @@ int ocfs2_insert_extent(struct ocfs2_super *osb, | |||
4155 | } | 4452 | } |
4156 | 4453 | ||
4157 | /* Finally, we can add clusters. This might rotate the tree for us. */ | 4454 | /* Finally, we can add clusters. This might rotate the tree for us. */ |
4158 | status = ocfs2_do_insert_extent(inode, handle, fe_bh, &rec, &insert); | 4455 | status = ocfs2_do_insert_extent(inode, handle, et, &rec, &insert); |
4159 | if (status < 0) | 4456 | if (status < 0) |
4160 | mlog_errno(status); | 4457 | mlog_errno(status); |
4161 | else | 4458 | else if (et->et_ops == &ocfs2_dinode_et_ops) |
4162 | ocfs2_extent_map_insert_rec(inode, &rec); | 4459 | ocfs2_extent_map_insert_rec(inode, &rec); |
4163 | 4460 | ||
4164 | bail: | 4461 | bail: |
4165 | if (last_eb_bh) | 4462 | brelse(last_eb_bh); |
4166 | brelse(last_eb_bh); | 4463 | |
4464 | mlog_exit(status); | ||
4465 | return status; | ||
4466 | } | ||
4467 | |||
4468 | /* | ||
4469 | * Allcate and add clusters into the extent b-tree. | ||
4470 | * The new clusters(clusters_to_add) will be inserted at logical_offset. | ||
4471 | * The extent b-tree's root is specified by et, and | ||
4472 | * it is not limited to the file storage. Any extent tree can use this | ||
4473 | * function if it implements the proper ocfs2_extent_tree. | ||
4474 | */ | ||
4475 | int ocfs2_add_clusters_in_btree(struct ocfs2_super *osb, | ||
4476 | struct inode *inode, | ||
4477 | u32 *logical_offset, | ||
4478 | u32 clusters_to_add, | ||
4479 | int mark_unwritten, | ||
4480 | struct ocfs2_extent_tree *et, | ||
4481 | handle_t *handle, | ||
4482 | struct ocfs2_alloc_context *data_ac, | ||
4483 | struct ocfs2_alloc_context *meta_ac, | ||
4484 | enum ocfs2_alloc_restarted *reason_ret) | ||
4485 | { | ||
4486 | int status = 0; | ||
4487 | int free_extents; | ||
4488 | enum ocfs2_alloc_restarted reason = RESTART_NONE; | ||
4489 | u32 bit_off, num_bits; | ||
4490 | u64 block; | ||
4491 | u8 flags = 0; | ||
4492 | |||
4493 | BUG_ON(!clusters_to_add); | ||
4494 | |||
4495 | if (mark_unwritten) | ||
4496 | flags = OCFS2_EXT_UNWRITTEN; | ||
4497 | |||
4498 | free_extents = ocfs2_num_free_extents(osb, inode, et); | ||
4499 | if (free_extents < 0) { | ||
4500 | status = free_extents; | ||
4501 | mlog_errno(status); | ||
4502 | goto leave; | ||
4503 | } | ||
4504 | |||
4505 | /* there are two cases which could cause us to EAGAIN in the | ||
4506 | * we-need-more-metadata case: | ||
4507 | * 1) we haven't reserved *any* | ||
4508 | * 2) we are so fragmented, we've needed to add metadata too | ||
4509 | * many times. */ | ||
4510 | if (!free_extents && !meta_ac) { | ||
4511 | mlog(0, "we haven't reserved any metadata!\n"); | ||
4512 | status = -EAGAIN; | ||
4513 | reason = RESTART_META; | ||
4514 | goto leave; | ||
4515 | } else if ((!free_extents) | ||
4516 | && (ocfs2_alloc_context_bits_left(meta_ac) | ||
4517 | < ocfs2_extend_meta_needed(et->et_root_el))) { | ||
4518 | mlog(0, "filesystem is really fragmented...\n"); | ||
4519 | status = -EAGAIN; | ||
4520 | reason = RESTART_META; | ||
4521 | goto leave; | ||
4522 | } | ||
4523 | |||
4524 | status = __ocfs2_claim_clusters(osb, handle, data_ac, 1, | ||
4525 | clusters_to_add, &bit_off, &num_bits); | ||
4526 | if (status < 0) { | ||
4527 | if (status != -ENOSPC) | ||
4528 | mlog_errno(status); | ||
4529 | goto leave; | ||
4530 | } | ||
4531 | |||
4532 | BUG_ON(num_bits > clusters_to_add); | ||
4167 | 4533 | ||
4534 | /* reserve our write early -- insert_extent may update the inode */ | ||
4535 | status = ocfs2_journal_access(handle, inode, et->et_root_bh, | ||
4536 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
4537 | if (status < 0) { | ||
4538 | mlog_errno(status); | ||
4539 | goto leave; | ||
4540 | } | ||
4541 | |||
4542 | block = ocfs2_clusters_to_blocks(osb->sb, bit_off); | ||
4543 | mlog(0, "Allocating %u clusters at block %u for inode %llu\n", | ||
4544 | num_bits, bit_off, (unsigned long long)OCFS2_I(inode)->ip_blkno); | ||
4545 | status = ocfs2_insert_extent(osb, handle, inode, et, | ||
4546 | *logical_offset, block, | ||
4547 | num_bits, flags, meta_ac); | ||
4548 | if (status < 0) { | ||
4549 | mlog_errno(status); | ||
4550 | goto leave; | ||
4551 | } | ||
4552 | |||
4553 | status = ocfs2_journal_dirty(handle, et->et_root_bh); | ||
4554 | if (status < 0) { | ||
4555 | mlog_errno(status); | ||
4556 | goto leave; | ||
4557 | } | ||
4558 | |||
4559 | clusters_to_add -= num_bits; | ||
4560 | *logical_offset += num_bits; | ||
4561 | |||
4562 | if (clusters_to_add) { | ||
4563 | mlog(0, "need to alloc once more, wanted = %u\n", | ||
4564 | clusters_to_add); | ||
4565 | status = -EAGAIN; | ||
4566 | reason = RESTART_TRANS; | ||
4567 | } | ||
4568 | |||
4569 | leave: | ||
4168 | mlog_exit(status); | 4570 | mlog_exit(status); |
4571 | if (reason_ret) | ||
4572 | *reason_ret = reason; | ||
4169 | return status; | 4573 | return status; |
4170 | } | 4574 | } |
4171 | 4575 | ||
@@ -4192,7 +4596,7 @@ static void ocfs2_make_right_split_rec(struct super_block *sb, | |||
4192 | static int ocfs2_split_and_insert(struct inode *inode, | 4596 | static int ocfs2_split_and_insert(struct inode *inode, |
4193 | handle_t *handle, | 4597 | handle_t *handle, |
4194 | struct ocfs2_path *path, | 4598 | struct ocfs2_path *path, |
4195 | struct buffer_head *di_bh, | 4599 | struct ocfs2_extent_tree *et, |
4196 | struct buffer_head **last_eb_bh, | 4600 | struct buffer_head **last_eb_bh, |
4197 | int split_index, | 4601 | int split_index, |
4198 | struct ocfs2_extent_rec *orig_split_rec, | 4602 | struct ocfs2_extent_rec *orig_split_rec, |
@@ -4206,7 +4610,6 @@ static int ocfs2_split_and_insert(struct inode *inode, | |||
4206 | struct ocfs2_extent_rec split_rec = *orig_split_rec; | 4610 | struct ocfs2_extent_rec split_rec = *orig_split_rec; |
4207 | struct ocfs2_insert_type insert; | 4611 | struct ocfs2_insert_type insert; |
4208 | struct ocfs2_extent_block *eb; | 4612 | struct ocfs2_extent_block *eb; |
4209 | struct ocfs2_dinode *di; | ||
4210 | 4613 | ||
4211 | leftright: | 4614 | leftright: |
4212 | /* | 4615 | /* |
@@ -4215,8 +4618,7 @@ leftright: | |||
4215 | */ | 4618 | */ |
4216 | rec = path_leaf_el(path)->l_recs[split_index]; | 4619 | rec = path_leaf_el(path)->l_recs[split_index]; |
4217 | 4620 | ||
4218 | di = (struct ocfs2_dinode *)di_bh->b_data; | 4621 | rightmost_el = et->et_root_el; |
4219 | rightmost_el = &di->id2.i_list; | ||
4220 | 4622 | ||
4221 | depth = le16_to_cpu(rightmost_el->l_tree_depth); | 4623 | depth = le16_to_cpu(rightmost_el->l_tree_depth); |
4222 | if (depth) { | 4624 | if (depth) { |
@@ -4227,8 +4629,8 @@ leftright: | |||
4227 | 4629 | ||
4228 | if (le16_to_cpu(rightmost_el->l_next_free_rec) == | 4630 | if (le16_to_cpu(rightmost_el->l_next_free_rec) == |
4229 | le16_to_cpu(rightmost_el->l_count)) { | 4631 | le16_to_cpu(rightmost_el->l_count)) { |
4230 | ret = ocfs2_grow_tree(inode, handle, di_bh, &depth, last_eb_bh, | 4632 | ret = ocfs2_grow_tree(inode, handle, et, |
4231 | meta_ac); | 4633 | &depth, last_eb_bh, meta_ac); |
4232 | if (ret) { | 4634 | if (ret) { |
4233 | mlog_errno(ret); | 4635 | mlog_errno(ret); |
4234 | goto out; | 4636 | goto out; |
@@ -4265,8 +4667,7 @@ leftright: | |||
4265 | do_leftright = 1; | 4667 | do_leftright = 1; |
4266 | } | 4668 | } |
4267 | 4669 | ||
4268 | ret = ocfs2_do_insert_extent(inode, handle, di_bh, &split_rec, | 4670 | ret = ocfs2_do_insert_extent(inode, handle, et, &split_rec, &insert); |
4269 | &insert); | ||
4270 | if (ret) { | 4671 | if (ret) { |
4271 | mlog_errno(ret); | 4672 | mlog_errno(ret); |
4272 | goto out; | 4673 | goto out; |
@@ -4308,8 +4709,9 @@ out: | |||
4308 | * of the tree is required. All other cases will degrade into a less | 4709 | * of the tree is required. All other cases will degrade into a less |
4309 | * optimal tree layout. | 4710 | * optimal tree layout. |
4310 | * | 4711 | * |
4311 | * last_eb_bh should be the rightmost leaf block for any inode with a | 4712 | * last_eb_bh should be the rightmost leaf block for any extent |
4312 | * btree. Since a split may grow the tree or a merge might shrink it, the caller cannot trust the contents of that buffer after this call. | 4713 | * btree. Since a split may grow the tree or a merge might shrink it, |
4714 | * the caller cannot trust the contents of that buffer after this call. | ||
4313 | * | 4715 | * |
4314 | * This code is optimized for readability - several passes might be | 4716 | * This code is optimized for readability - several passes might be |
4315 | * made over certain portions of the tree. All of those blocks will | 4717 | * made over certain portions of the tree. All of those blocks will |
@@ -4317,7 +4719,7 @@ out: | |||
4317 | * extra overhead is not expressed in terms of disk reads. | 4719 | * extra overhead is not expressed in terms of disk reads. |
4318 | */ | 4720 | */ |
4319 | static int __ocfs2_mark_extent_written(struct inode *inode, | 4721 | static int __ocfs2_mark_extent_written(struct inode *inode, |
4320 | struct buffer_head *di_bh, | 4722 | struct ocfs2_extent_tree *et, |
4321 | handle_t *handle, | 4723 | handle_t *handle, |
4322 | struct ocfs2_path *path, | 4724 | struct ocfs2_path *path, |
4323 | int split_index, | 4725 | int split_index, |
@@ -4357,11 +4759,9 @@ static int __ocfs2_mark_extent_written(struct inode *inode, | |||
4357 | */ | 4759 | */ |
4358 | if (path->p_tree_depth) { | 4760 | if (path->p_tree_depth) { |
4359 | struct ocfs2_extent_block *eb; | 4761 | struct ocfs2_extent_block *eb; |
4360 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; | ||
4361 | 4762 | ||
4362 | ret = ocfs2_read_block(OCFS2_SB(inode->i_sb), | 4763 | ret = ocfs2_read_block(inode, ocfs2_et_get_last_eb_blk(et), |
4363 | le64_to_cpu(di->i_last_eb_blk), | 4764 | &last_eb_bh); |
4364 | &last_eb_bh, OCFS2_BH_CACHED, inode); | ||
4365 | if (ret) { | 4765 | if (ret) { |
4366 | mlog_exit(ret); | 4766 | mlog_exit(ret); |
4367 | goto out; | 4767 | goto out; |
@@ -4394,7 +4794,7 @@ static int __ocfs2_mark_extent_written(struct inode *inode, | |||
4394 | if (ctxt.c_split_covers_rec) | 4794 | if (ctxt.c_split_covers_rec) |
4395 | el->l_recs[split_index] = *split_rec; | 4795 | el->l_recs[split_index] = *split_rec; |
4396 | else | 4796 | else |
4397 | ret = ocfs2_split_and_insert(inode, handle, path, di_bh, | 4797 | ret = ocfs2_split_and_insert(inode, handle, path, et, |
4398 | &last_eb_bh, split_index, | 4798 | &last_eb_bh, split_index, |
4399 | split_rec, meta_ac); | 4799 | split_rec, meta_ac); |
4400 | if (ret) | 4800 | if (ret) |
@@ -4402,7 +4802,7 @@ static int __ocfs2_mark_extent_written(struct inode *inode, | |||
4402 | } else { | 4802 | } else { |
4403 | ret = ocfs2_try_to_merge_extent(inode, handle, path, | 4803 | ret = ocfs2_try_to_merge_extent(inode, handle, path, |
4404 | split_index, split_rec, | 4804 | split_index, split_rec, |
4405 | dealloc, &ctxt); | 4805 | dealloc, &ctxt, et); |
4406 | if (ret) | 4806 | if (ret) |
4407 | mlog_errno(ret); | 4807 | mlog_errno(ret); |
4408 | } | 4808 | } |
@@ -4420,7 +4820,8 @@ out: | |||
4420 | * | 4820 | * |
4421 | * The caller is responsible for passing down meta_ac if we'll need it. | 4821 | * The caller is responsible for passing down meta_ac if we'll need it. |
4422 | */ | 4822 | */ |
4423 | int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *di_bh, | 4823 | int ocfs2_mark_extent_written(struct inode *inode, |
4824 | struct ocfs2_extent_tree *et, | ||
4424 | handle_t *handle, u32 cpos, u32 len, u32 phys, | 4825 | handle_t *handle, u32 cpos, u32 len, u32 phys, |
4425 | struct ocfs2_alloc_context *meta_ac, | 4826 | struct ocfs2_alloc_context *meta_ac, |
4426 | struct ocfs2_cached_dealloc_ctxt *dealloc) | 4827 | struct ocfs2_cached_dealloc_ctxt *dealloc) |
@@ -4446,10 +4847,14 @@ int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *di_bh, | |||
4446 | /* | 4847 | /* |
4447 | * XXX: This should be fixed up so that we just re-insert the | 4848 | * XXX: This should be fixed up so that we just re-insert the |
4448 | * next extent records. | 4849 | * next extent records. |
4850 | * | ||
4851 | * XXX: This is a hack on the extent tree, maybe it should be | ||
4852 | * an op? | ||
4449 | */ | 4853 | */ |
4450 | ocfs2_extent_map_trunc(inode, 0); | 4854 | if (et->et_ops == &ocfs2_dinode_et_ops) |
4855 | ocfs2_extent_map_trunc(inode, 0); | ||
4451 | 4856 | ||
4452 | left_path = ocfs2_new_inode_path(di_bh); | 4857 | left_path = ocfs2_new_path(et->et_root_bh, et->et_root_el); |
4453 | if (!left_path) { | 4858 | if (!left_path) { |
4454 | ret = -ENOMEM; | 4859 | ret = -ENOMEM; |
4455 | mlog_errno(ret); | 4860 | mlog_errno(ret); |
@@ -4480,8 +4885,9 @@ int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *di_bh, | |||
4480 | split_rec.e_flags = path_leaf_el(left_path)->l_recs[index].e_flags; | 4885 | split_rec.e_flags = path_leaf_el(left_path)->l_recs[index].e_flags; |
4481 | split_rec.e_flags &= ~OCFS2_EXT_UNWRITTEN; | 4886 | split_rec.e_flags &= ~OCFS2_EXT_UNWRITTEN; |
4482 | 4887 | ||
4483 | ret = __ocfs2_mark_extent_written(inode, di_bh, handle, left_path, | 4888 | ret = __ocfs2_mark_extent_written(inode, et, handle, left_path, |
4484 | index, &split_rec, meta_ac, dealloc); | 4889 | index, &split_rec, meta_ac, |
4890 | dealloc); | ||
4485 | if (ret) | 4891 | if (ret) |
4486 | mlog_errno(ret); | 4892 | mlog_errno(ret); |
4487 | 4893 | ||
@@ -4490,13 +4896,12 @@ out: | |||
4490 | return ret; | 4896 | return ret; |
4491 | } | 4897 | } |
4492 | 4898 | ||
4493 | static int ocfs2_split_tree(struct inode *inode, struct buffer_head *di_bh, | 4899 | static int ocfs2_split_tree(struct inode *inode, struct ocfs2_extent_tree *et, |
4494 | handle_t *handle, struct ocfs2_path *path, | 4900 | handle_t *handle, struct ocfs2_path *path, |
4495 | int index, u32 new_range, | 4901 | int index, u32 new_range, |
4496 | struct ocfs2_alloc_context *meta_ac) | 4902 | struct ocfs2_alloc_context *meta_ac) |
4497 | { | 4903 | { |
4498 | int ret, depth, credits = handle->h_buffer_credits; | 4904 | int ret, depth, credits = handle->h_buffer_credits; |
4499 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; | ||
4500 | struct buffer_head *last_eb_bh = NULL; | 4905 | struct buffer_head *last_eb_bh = NULL; |
4501 | struct ocfs2_extent_block *eb; | 4906 | struct ocfs2_extent_block *eb; |
4502 | struct ocfs2_extent_list *rightmost_el, *el; | 4907 | struct ocfs2_extent_list *rightmost_el, *el; |
@@ -4513,9 +4918,8 @@ static int ocfs2_split_tree(struct inode *inode, struct buffer_head *di_bh, | |||
4513 | 4918 | ||
4514 | depth = path->p_tree_depth; | 4919 | depth = path->p_tree_depth; |
4515 | if (depth > 0) { | 4920 | if (depth > 0) { |
4516 | ret = ocfs2_read_block(OCFS2_SB(inode->i_sb), | 4921 | ret = ocfs2_read_block(inode, ocfs2_et_get_last_eb_blk(et), |
4517 | le64_to_cpu(di->i_last_eb_blk), | 4922 | &last_eb_bh); |
4518 | &last_eb_bh, OCFS2_BH_CACHED, inode); | ||
4519 | if (ret < 0) { | 4923 | if (ret < 0) { |
4520 | mlog_errno(ret); | 4924 | mlog_errno(ret); |
4521 | goto out; | 4925 | goto out; |
@@ -4526,7 +4930,8 @@ static int ocfs2_split_tree(struct inode *inode, struct buffer_head *di_bh, | |||
4526 | } else | 4930 | } else |
4527 | rightmost_el = path_leaf_el(path); | 4931 | rightmost_el = path_leaf_el(path); |
4528 | 4932 | ||
4529 | credits += path->p_tree_depth + ocfs2_extend_meta_needed(di); | 4933 | credits += path->p_tree_depth + |
4934 | ocfs2_extend_meta_needed(et->et_root_el); | ||
4530 | ret = ocfs2_extend_trans(handle, credits); | 4935 | ret = ocfs2_extend_trans(handle, credits); |
4531 | if (ret) { | 4936 | if (ret) { |
4532 | mlog_errno(ret); | 4937 | mlog_errno(ret); |
@@ -4535,7 +4940,7 @@ static int ocfs2_split_tree(struct inode *inode, struct buffer_head *di_bh, | |||
4535 | 4940 | ||
4536 | if (le16_to_cpu(rightmost_el->l_next_free_rec) == | 4941 | if (le16_to_cpu(rightmost_el->l_next_free_rec) == |
4537 | le16_to_cpu(rightmost_el->l_count)) { | 4942 | le16_to_cpu(rightmost_el->l_count)) { |
4538 | ret = ocfs2_grow_tree(inode, handle, di_bh, &depth, &last_eb_bh, | 4943 | ret = ocfs2_grow_tree(inode, handle, et, &depth, &last_eb_bh, |
4539 | meta_ac); | 4944 | meta_ac); |
4540 | if (ret) { | 4945 | if (ret) { |
4541 | mlog_errno(ret); | 4946 | mlog_errno(ret); |
@@ -4549,7 +4954,7 @@ static int ocfs2_split_tree(struct inode *inode, struct buffer_head *di_bh, | |||
4549 | insert.ins_split = SPLIT_RIGHT; | 4954 | insert.ins_split = SPLIT_RIGHT; |
4550 | insert.ins_tree_depth = depth; | 4955 | insert.ins_tree_depth = depth; |
4551 | 4956 | ||
4552 | ret = ocfs2_do_insert_extent(inode, handle, di_bh, &split_rec, &insert); | 4957 | ret = ocfs2_do_insert_extent(inode, handle, et, &split_rec, &insert); |
4553 | if (ret) | 4958 | if (ret) |
4554 | mlog_errno(ret); | 4959 | mlog_errno(ret); |
4555 | 4960 | ||
@@ -4561,7 +4966,8 @@ out: | |||
4561 | static int ocfs2_truncate_rec(struct inode *inode, handle_t *handle, | 4966 | static int ocfs2_truncate_rec(struct inode *inode, handle_t *handle, |
4562 | struct ocfs2_path *path, int index, | 4967 | struct ocfs2_path *path, int index, |
4563 | struct ocfs2_cached_dealloc_ctxt *dealloc, | 4968 | struct ocfs2_cached_dealloc_ctxt *dealloc, |
4564 | u32 cpos, u32 len) | 4969 | u32 cpos, u32 len, |
4970 | struct ocfs2_extent_tree *et) | ||
4565 | { | 4971 | { |
4566 | int ret; | 4972 | int ret; |
4567 | u32 left_cpos, rec_range, trunc_range; | 4973 | u32 left_cpos, rec_range, trunc_range; |
@@ -4573,7 +4979,7 @@ static int ocfs2_truncate_rec(struct inode *inode, handle_t *handle, | |||
4573 | struct ocfs2_extent_block *eb; | 4979 | struct ocfs2_extent_block *eb; |
4574 | 4980 | ||
4575 | if (ocfs2_is_empty_extent(&el->l_recs[0]) && index > 0) { | 4981 | if (ocfs2_is_empty_extent(&el->l_recs[0]) && index > 0) { |
4576 | ret = ocfs2_rotate_tree_left(inode, handle, path, dealloc); | 4982 | ret = ocfs2_rotate_tree_left(inode, handle, path, dealloc, et); |
4577 | if (ret) { | 4983 | if (ret) { |
4578 | mlog_errno(ret); | 4984 | mlog_errno(ret); |
4579 | goto out; | 4985 | goto out; |
@@ -4704,7 +5110,7 @@ static int ocfs2_truncate_rec(struct inode *inode, handle_t *handle, | |||
4704 | 5110 | ||
4705 | ocfs2_journal_dirty(handle, path_leaf_bh(path)); | 5111 | ocfs2_journal_dirty(handle, path_leaf_bh(path)); |
4706 | 5112 | ||
4707 | ret = ocfs2_rotate_tree_left(inode, handle, path, dealloc); | 5113 | ret = ocfs2_rotate_tree_left(inode, handle, path, dealloc, et); |
4708 | if (ret) { | 5114 | if (ret) { |
4709 | mlog_errno(ret); | 5115 | mlog_errno(ret); |
4710 | goto out; | 5116 | goto out; |
@@ -4715,7 +5121,8 @@ out: | |||
4715 | return ret; | 5121 | return ret; |
4716 | } | 5122 | } |
4717 | 5123 | ||
4718 | int ocfs2_remove_extent(struct inode *inode, struct buffer_head *di_bh, | 5124 | int ocfs2_remove_extent(struct inode *inode, |
5125 | struct ocfs2_extent_tree *et, | ||
4719 | u32 cpos, u32 len, handle_t *handle, | 5126 | u32 cpos, u32 len, handle_t *handle, |
4720 | struct ocfs2_alloc_context *meta_ac, | 5127 | struct ocfs2_alloc_context *meta_ac, |
4721 | struct ocfs2_cached_dealloc_ctxt *dealloc) | 5128 | struct ocfs2_cached_dealloc_ctxt *dealloc) |
@@ -4724,11 +5131,11 @@ int ocfs2_remove_extent(struct inode *inode, struct buffer_head *di_bh, | |||
4724 | u32 rec_range, trunc_range; | 5131 | u32 rec_range, trunc_range; |
4725 | struct ocfs2_extent_rec *rec; | 5132 | struct ocfs2_extent_rec *rec; |
4726 | struct ocfs2_extent_list *el; | 5133 | struct ocfs2_extent_list *el; |
4727 | struct ocfs2_path *path; | 5134 | struct ocfs2_path *path = NULL; |
4728 | 5135 | ||
4729 | ocfs2_extent_map_trunc(inode, 0); | 5136 | ocfs2_extent_map_trunc(inode, 0); |
4730 | 5137 | ||
4731 | path = ocfs2_new_inode_path(di_bh); | 5138 | path = ocfs2_new_path(et->et_root_bh, et->et_root_el); |
4732 | if (!path) { | 5139 | if (!path) { |
4733 | ret = -ENOMEM; | 5140 | ret = -ENOMEM; |
4734 | mlog_errno(ret); | 5141 | mlog_errno(ret); |
@@ -4781,13 +5188,13 @@ int ocfs2_remove_extent(struct inode *inode, struct buffer_head *di_bh, | |||
4781 | 5188 | ||
4782 | if (le32_to_cpu(rec->e_cpos) == cpos || rec_range == trunc_range) { | 5189 | if (le32_to_cpu(rec->e_cpos) == cpos || rec_range == trunc_range) { |
4783 | ret = ocfs2_truncate_rec(inode, handle, path, index, dealloc, | 5190 | ret = ocfs2_truncate_rec(inode, handle, path, index, dealloc, |
4784 | cpos, len); | 5191 | cpos, len, et); |
4785 | if (ret) { | 5192 | if (ret) { |
4786 | mlog_errno(ret); | 5193 | mlog_errno(ret); |
4787 | goto out; | 5194 | goto out; |
4788 | } | 5195 | } |
4789 | } else { | 5196 | } else { |
4790 | ret = ocfs2_split_tree(inode, di_bh, handle, path, index, | 5197 | ret = ocfs2_split_tree(inode, et, handle, path, index, |
4791 | trunc_range, meta_ac); | 5198 | trunc_range, meta_ac); |
4792 | if (ret) { | 5199 | if (ret) { |
4793 | mlog_errno(ret); | 5200 | mlog_errno(ret); |
@@ -4836,7 +5243,7 @@ int ocfs2_remove_extent(struct inode *inode, struct buffer_head *di_bh, | |||
4836 | } | 5243 | } |
4837 | 5244 | ||
4838 | ret = ocfs2_truncate_rec(inode, handle, path, index, dealloc, | 5245 | ret = ocfs2_truncate_rec(inode, handle, path, index, dealloc, |
4839 | cpos, len); | 5246 | cpos, len, et); |
4840 | if (ret) { | 5247 | if (ret) { |
4841 | mlog_errno(ret); | 5248 | mlog_errno(ret); |
4842 | goto out; | 5249 | goto out; |
@@ -5179,8 +5586,7 @@ static int ocfs2_get_truncate_log_info(struct ocfs2_super *osb, | |||
5179 | goto bail; | 5586 | goto bail; |
5180 | } | 5587 | } |
5181 | 5588 | ||
5182 | status = ocfs2_read_block(osb, OCFS2_I(inode)->ip_blkno, &bh, | 5589 | status = ocfs2_read_block(inode, OCFS2_I(inode)->ip_blkno, &bh); |
5183 | OCFS2_BH_CACHED, inode); | ||
5184 | if (status < 0) { | 5590 | if (status < 0) { |
5185 | iput(inode); | 5591 | iput(inode); |
5186 | mlog_errno(status); | 5592 | mlog_errno(status); |
@@ -5255,8 +5661,7 @@ int ocfs2_begin_truncate_log_recovery(struct ocfs2_super *osb, | |||
5255 | bail: | 5661 | bail: |
5256 | if (tl_inode) | 5662 | if (tl_inode) |
5257 | iput(tl_inode); | 5663 | iput(tl_inode); |
5258 | if (tl_bh) | 5664 | brelse(tl_bh); |
5259 | brelse(tl_bh); | ||
5260 | 5665 | ||
5261 | if (status < 0 && (*tl_copy)) { | 5666 | if (status < 0 && (*tl_copy)) { |
5262 | kfree(*tl_copy); | 5667 | kfree(*tl_copy); |
@@ -5999,20 +6404,13 @@ bail: | |||
5999 | return status; | 6404 | return status; |
6000 | } | 6405 | } |
6001 | 6406 | ||
6002 | static int ocfs2_writeback_zero_func(handle_t *handle, struct buffer_head *bh) | 6407 | static int ocfs2_zero_func(handle_t *handle, struct buffer_head *bh) |
6003 | { | 6408 | { |
6004 | set_buffer_uptodate(bh); | 6409 | set_buffer_uptodate(bh); |
6005 | mark_buffer_dirty(bh); | 6410 | mark_buffer_dirty(bh); |
6006 | return 0; | 6411 | return 0; |
6007 | } | 6412 | } |
6008 | 6413 | ||
6009 | static int ocfs2_ordered_zero_func(handle_t *handle, struct buffer_head *bh) | ||
6010 | { | ||
6011 | set_buffer_uptodate(bh); | ||
6012 | mark_buffer_dirty(bh); | ||
6013 | return ocfs2_journal_dirty_data(handle, bh); | ||
6014 | } | ||
6015 | |||
6016 | static void ocfs2_map_and_dirty_page(struct inode *inode, handle_t *handle, | 6414 | static void ocfs2_map_and_dirty_page(struct inode *inode, handle_t *handle, |
6017 | unsigned int from, unsigned int to, | 6415 | unsigned int from, unsigned int to, |
6018 | struct page *page, int zero, u64 *phys) | 6416 | struct page *page, int zero, u64 *phys) |
@@ -6031,17 +6429,18 @@ static void ocfs2_map_and_dirty_page(struct inode *inode, handle_t *handle, | |||
6031 | * here if they aren't - ocfs2_map_page_blocks() | 6429 | * here if they aren't - ocfs2_map_page_blocks() |
6032 | * might've skipped some | 6430 | * might've skipped some |
6033 | */ | 6431 | */ |
6034 | if (ocfs2_should_order_data(inode)) { | 6432 | ret = walk_page_buffers(handle, page_buffers(page), |
6035 | ret = walk_page_buffers(handle, | 6433 | from, to, &partial, |
6036 | page_buffers(page), | 6434 | ocfs2_zero_func); |
6037 | from, to, &partial, | 6435 | if (ret < 0) |
6038 | ocfs2_ordered_zero_func); | 6436 | mlog_errno(ret); |
6039 | if (ret < 0) | 6437 | else if (ocfs2_should_order_data(inode)) { |
6040 | mlog_errno(ret); | 6438 | ret = ocfs2_jbd2_file_inode(handle, inode); |
6041 | } else { | 6439 | #ifdef CONFIG_OCFS2_COMPAT_JBD |
6042 | ret = walk_page_buffers(handle, page_buffers(page), | 6440 | ret = walk_page_buffers(handle, page_buffers(page), |
6043 | from, to, &partial, | 6441 | from, to, &partial, |
6044 | ocfs2_writeback_zero_func); | 6442 | ocfs2_journal_dirty_data); |
6443 | #endif | ||
6045 | if (ret < 0) | 6444 | if (ret < 0) |
6046 | mlog_errno(ret); | 6445 | mlog_errno(ret); |
6047 | } | 6446 | } |
@@ -6206,20 +6605,29 @@ out: | |||
6206 | return ret; | 6605 | return ret; |
6207 | } | 6606 | } |
6208 | 6607 | ||
6209 | static void ocfs2_zero_dinode_id2(struct inode *inode, struct ocfs2_dinode *di) | 6608 | static void ocfs2_zero_dinode_id2_with_xattr(struct inode *inode, |
6609 | struct ocfs2_dinode *di) | ||
6210 | { | 6610 | { |
6211 | unsigned int blocksize = 1 << inode->i_sb->s_blocksize_bits; | 6611 | unsigned int blocksize = 1 << inode->i_sb->s_blocksize_bits; |
6612 | unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size); | ||
6212 | 6613 | ||
6213 | memset(&di->id2, 0, blocksize - offsetof(struct ocfs2_dinode, id2)); | 6614 | if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL) |
6615 | memset(&di->id2, 0, blocksize - | ||
6616 | offsetof(struct ocfs2_dinode, id2) - | ||
6617 | xattrsize); | ||
6618 | else | ||
6619 | memset(&di->id2, 0, blocksize - | ||
6620 | offsetof(struct ocfs2_dinode, id2)); | ||
6214 | } | 6621 | } |
6215 | 6622 | ||
6216 | void ocfs2_dinode_new_extent_list(struct inode *inode, | 6623 | void ocfs2_dinode_new_extent_list(struct inode *inode, |
6217 | struct ocfs2_dinode *di) | 6624 | struct ocfs2_dinode *di) |
6218 | { | 6625 | { |
6219 | ocfs2_zero_dinode_id2(inode, di); | 6626 | ocfs2_zero_dinode_id2_with_xattr(inode, di); |
6220 | di->id2.i_list.l_tree_depth = 0; | 6627 | di->id2.i_list.l_tree_depth = 0; |
6221 | di->id2.i_list.l_next_free_rec = 0; | 6628 | di->id2.i_list.l_next_free_rec = 0; |
6222 | di->id2.i_list.l_count = cpu_to_le16(ocfs2_extent_recs_per_inode(inode->i_sb)); | 6629 | di->id2.i_list.l_count = cpu_to_le16( |
6630 | ocfs2_extent_recs_per_inode_with_xattr(inode->i_sb, di)); | ||
6223 | } | 6631 | } |
6224 | 6632 | ||
6225 | void ocfs2_set_inode_data_inline(struct inode *inode, struct ocfs2_dinode *di) | 6633 | void ocfs2_set_inode_data_inline(struct inode *inode, struct ocfs2_dinode *di) |
@@ -6236,9 +6644,10 @@ void ocfs2_set_inode_data_inline(struct inode *inode, struct ocfs2_dinode *di) | |||
6236 | * We clear the entire i_data structure here so that all | 6644 | * We clear the entire i_data structure here so that all |
6237 | * fields can be properly initialized. | 6645 | * fields can be properly initialized. |
6238 | */ | 6646 | */ |
6239 | ocfs2_zero_dinode_id2(inode, di); | 6647 | ocfs2_zero_dinode_id2_with_xattr(inode, di); |
6240 | 6648 | ||
6241 | idata->id_count = cpu_to_le16(ocfs2_max_inline_data(inode->i_sb)); | 6649 | idata->id_count = cpu_to_le16( |
6650 | ocfs2_max_inline_data_with_xattr(inode->i_sb, di)); | ||
6242 | } | 6651 | } |
6243 | 6652 | ||
6244 | int ocfs2_convert_inline_data_to_extents(struct inode *inode, | 6653 | int ocfs2_convert_inline_data_to_extents(struct inode *inode, |
@@ -6253,6 +6662,7 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode, | |||
6253 | struct ocfs2_alloc_context *data_ac = NULL; | 6662 | struct ocfs2_alloc_context *data_ac = NULL; |
6254 | struct page **pages = NULL; | 6663 | struct page **pages = NULL; |
6255 | loff_t end = osb->s_clustersize; | 6664 | loff_t end = osb->s_clustersize; |
6665 | struct ocfs2_extent_tree et; | ||
6256 | 6666 | ||
6257 | has_data = i_size_read(inode) ? 1 : 0; | 6667 | has_data = i_size_read(inode) ? 1 : 0; |
6258 | 6668 | ||
@@ -6352,7 +6762,8 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode, | |||
6352 | * this proves to be false, we could always re-build | 6762 | * this proves to be false, we could always re-build |
6353 | * the in-inode data from our pages. | 6763 | * the in-inode data from our pages. |
6354 | */ | 6764 | */ |
6355 | ret = ocfs2_insert_extent(osb, handle, inode, di_bh, | 6765 | ocfs2_init_dinode_extent_tree(&et, inode, di_bh); |
6766 | ret = ocfs2_insert_extent(osb, handle, inode, &et, | ||
6356 | 0, block, 1, 0, NULL); | 6767 | 0, block, 1, 0, NULL); |
6357 | if (ret) { | 6768 | if (ret) { |
6358 | mlog_errno(ret); | 6769 | mlog_errno(ret); |
@@ -6395,13 +6806,14 @@ int ocfs2_commit_truncate(struct ocfs2_super *osb, | |||
6395 | handle_t *handle = NULL; | 6806 | handle_t *handle = NULL; |
6396 | struct inode *tl_inode = osb->osb_tl_inode; | 6807 | struct inode *tl_inode = osb->osb_tl_inode; |
6397 | struct ocfs2_path *path = NULL; | 6808 | struct ocfs2_path *path = NULL; |
6809 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)fe_bh->b_data; | ||
6398 | 6810 | ||
6399 | mlog_entry_void(); | 6811 | mlog_entry_void(); |
6400 | 6812 | ||
6401 | new_highest_cpos = ocfs2_clusters_for_bytes(osb->sb, | 6813 | new_highest_cpos = ocfs2_clusters_for_bytes(osb->sb, |
6402 | i_size_read(inode)); | 6814 | i_size_read(inode)); |
6403 | 6815 | ||
6404 | path = ocfs2_new_inode_path(fe_bh); | 6816 | path = ocfs2_new_path(fe_bh, &di->id2.i_list); |
6405 | if (!path) { | 6817 | if (!path) { |
6406 | status = -ENOMEM; | 6818 | status = -ENOMEM; |
6407 | mlog_errno(status); | 6819 | mlog_errno(status); |
@@ -6572,8 +6984,8 @@ int ocfs2_prepare_truncate(struct ocfs2_super *osb, | |||
6572 | ocfs2_init_dealloc_ctxt(&(*tc)->tc_dealloc); | 6984 | ocfs2_init_dealloc_ctxt(&(*tc)->tc_dealloc); |
6573 | 6985 | ||
6574 | if (fe->id2.i_list.l_tree_depth) { | 6986 | if (fe->id2.i_list.l_tree_depth) { |
6575 | status = ocfs2_read_block(osb, le64_to_cpu(fe->i_last_eb_blk), | 6987 | status = ocfs2_read_block(inode, le64_to_cpu(fe->i_last_eb_blk), |
6576 | &last_eb_bh, OCFS2_BH_CACHED, inode); | 6988 | &last_eb_bh); |
6577 | if (status < 0) { | 6989 | if (status < 0) { |
6578 | mlog_errno(status); | 6990 | mlog_errno(status); |
6579 | goto bail; | 6991 | goto bail; |
@@ -6686,8 +7098,7 @@ static void ocfs2_free_truncate_context(struct ocfs2_truncate_context *tc) | |||
6686 | mlog(ML_NOTICE, | 7098 | mlog(ML_NOTICE, |
6687 | "Truncate completion has non-empty dealloc context\n"); | 7099 | "Truncate completion has non-empty dealloc context\n"); |
6688 | 7100 | ||
6689 | if (tc->tc_last_eb_bh) | 7101 | brelse(tc->tc_last_eb_bh); |
6690 | brelse(tc->tc_last_eb_bh); | ||
6691 | 7102 | ||
6692 | kfree(tc); | 7103 | kfree(tc); |
6693 | } | 7104 | } |
diff --git a/fs/ocfs2/alloc.h b/fs/ocfs2/alloc.h index 60cd3d59230c..70257c84cfbe 100644 --- a/fs/ocfs2/alloc.h +++ b/fs/ocfs2/alloc.h | |||
@@ -26,30 +26,102 @@ | |||
26 | #ifndef OCFS2_ALLOC_H | 26 | #ifndef OCFS2_ALLOC_H |
27 | #define OCFS2_ALLOC_H | 27 | #define OCFS2_ALLOC_H |
28 | 28 | ||
29 | |||
30 | /* | ||
31 | * For xattr tree leaf, we limit the leaf byte size to be 64K. | ||
32 | */ | ||
33 | #define OCFS2_MAX_XATTR_TREE_LEAF_SIZE 65536 | ||
34 | |||
35 | /* | ||
36 | * ocfs2_extent_tree and ocfs2_extent_tree_operations are used to abstract | ||
37 | * the b-tree operations in ocfs2. Now all the b-tree operations are not | ||
38 | * limited to ocfs2_dinode only. Any data which need to allocate clusters | ||
39 | * to store can use b-tree. And it only needs to implement its ocfs2_extent_tree | ||
40 | * and operation. | ||
41 | * | ||
42 | * ocfs2_extent_tree becomes the first-class object for extent tree | ||
43 | * manipulation. Callers of the alloc.c code need to fill it via one of | ||
44 | * the ocfs2_init_*_extent_tree() operations below. | ||
45 | * | ||
46 | * ocfs2_extent_tree contains info for the root of the b-tree, it must have a | ||
47 | * root ocfs2_extent_list and a root_bh so that they can be used in the b-tree | ||
48 | * functions. | ||
49 | * ocfs2_extent_tree_operations abstract the normal operations we do for | ||
50 | * the root of extent b-tree. | ||
51 | */ | ||
52 | struct ocfs2_extent_tree_operations; | ||
53 | struct ocfs2_extent_tree { | ||
54 | struct ocfs2_extent_tree_operations *et_ops; | ||
55 | struct buffer_head *et_root_bh; | ||
56 | struct ocfs2_extent_list *et_root_el; | ||
57 | void *et_object; | ||
58 | unsigned int et_max_leaf_clusters; | ||
59 | }; | ||
60 | |||
61 | /* | ||
62 | * ocfs2_init_*_extent_tree() will fill an ocfs2_extent_tree from the | ||
63 | * specified object buffer. | ||
64 | */ | ||
65 | void ocfs2_init_dinode_extent_tree(struct ocfs2_extent_tree *et, | ||
66 | struct inode *inode, | ||
67 | struct buffer_head *bh); | ||
68 | void ocfs2_init_xattr_tree_extent_tree(struct ocfs2_extent_tree *et, | ||
69 | struct inode *inode, | ||
70 | struct buffer_head *bh); | ||
71 | void ocfs2_init_xattr_value_extent_tree(struct ocfs2_extent_tree *et, | ||
72 | struct inode *inode, | ||
73 | struct buffer_head *bh, | ||
74 | struct ocfs2_xattr_value_root *xv); | ||
75 | |||
29 | struct ocfs2_alloc_context; | 76 | struct ocfs2_alloc_context; |
30 | int ocfs2_insert_extent(struct ocfs2_super *osb, | 77 | int ocfs2_insert_extent(struct ocfs2_super *osb, |
31 | handle_t *handle, | 78 | handle_t *handle, |
32 | struct inode *inode, | 79 | struct inode *inode, |
33 | struct buffer_head *fe_bh, | 80 | struct ocfs2_extent_tree *et, |
34 | u32 cpos, | 81 | u32 cpos, |
35 | u64 start_blk, | 82 | u64 start_blk, |
36 | u32 new_clusters, | 83 | u32 new_clusters, |
37 | u8 flags, | 84 | u8 flags, |
38 | struct ocfs2_alloc_context *meta_ac); | 85 | struct ocfs2_alloc_context *meta_ac); |
86 | |||
87 | enum ocfs2_alloc_restarted { | ||
88 | RESTART_NONE = 0, | ||
89 | RESTART_TRANS, | ||
90 | RESTART_META | ||
91 | }; | ||
92 | int ocfs2_add_clusters_in_btree(struct ocfs2_super *osb, | ||
93 | struct inode *inode, | ||
94 | u32 *logical_offset, | ||
95 | u32 clusters_to_add, | ||
96 | int mark_unwritten, | ||
97 | struct ocfs2_extent_tree *et, | ||
98 | handle_t *handle, | ||
99 | struct ocfs2_alloc_context *data_ac, | ||
100 | struct ocfs2_alloc_context *meta_ac, | ||
101 | enum ocfs2_alloc_restarted *reason_ret); | ||
39 | struct ocfs2_cached_dealloc_ctxt; | 102 | struct ocfs2_cached_dealloc_ctxt; |
40 | int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *di_bh, | 103 | int ocfs2_mark_extent_written(struct inode *inode, |
104 | struct ocfs2_extent_tree *et, | ||
41 | handle_t *handle, u32 cpos, u32 len, u32 phys, | 105 | handle_t *handle, u32 cpos, u32 len, u32 phys, |
42 | struct ocfs2_alloc_context *meta_ac, | 106 | struct ocfs2_alloc_context *meta_ac, |
43 | struct ocfs2_cached_dealloc_ctxt *dealloc); | 107 | struct ocfs2_cached_dealloc_ctxt *dealloc); |
44 | int ocfs2_remove_extent(struct inode *inode, struct buffer_head *di_bh, | 108 | int ocfs2_remove_extent(struct inode *inode, |
109 | struct ocfs2_extent_tree *et, | ||
45 | u32 cpos, u32 len, handle_t *handle, | 110 | u32 cpos, u32 len, handle_t *handle, |
46 | struct ocfs2_alloc_context *meta_ac, | 111 | struct ocfs2_alloc_context *meta_ac, |
47 | struct ocfs2_cached_dealloc_ctxt *dealloc); | 112 | struct ocfs2_cached_dealloc_ctxt *dealloc); |
48 | int ocfs2_num_free_extents(struct ocfs2_super *osb, | 113 | int ocfs2_num_free_extents(struct ocfs2_super *osb, |
49 | struct inode *inode, | 114 | struct inode *inode, |
50 | struct ocfs2_dinode *fe); | 115 | struct ocfs2_extent_tree *et); |
51 | /* how many new metadata chunks would an allocation need at maximum? */ | 116 | |
52 | static inline int ocfs2_extend_meta_needed(struct ocfs2_dinode *fe) | 117 | /* |
118 | * how many new metadata chunks would an allocation need at maximum? | ||
119 | * | ||
120 | * Please note that the caller must make sure that root_el is the root | ||
121 | * of extent tree. So for an inode, it should be &fe->id2.i_list. Otherwise | ||
122 | * the result may be wrong. | ||
123 | */ | ||
124 | static inline int ocfs2_extend_meta_needed(struct ocfs2_extent_list *root_el) | ||
53 | { | 125 | { |
54 | /* | 126 | /* |
55 | * Rather than do all the work of determining how much we need | 127 | * Rather than do all the work of determining how much we need |
@@ -59,7 +131,7 @@ static inline int ocfs2_extend_meta_needed(struct ocfs2_dinode *fe) | |||
59 | * new tree_depth==0 extent_block, and one block at the new | 131 | * new tree_depth==0 extent_block, and one block at the new |
60 | * top-of-the tree. | 132 | * top-of-the tree. |
61 | */ | 133 | */ |
62 | return le16_to_cpu(fe->id2.i_list.l_tree_depth) + 2; | 134 | return le16_to_cpu(root_el->l_tree_depth) + 2; |
63 | } | 135 | } |
64 | 136 | ||
65 | void ocfs2_dinode_new_extent_list(struct inode *inode, struct ocfs2_dinode *di); | 137 | void ocfs2_dinode_new_extent_list(struct inode *inode, struct ocfs2_dinode *di); |
diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c index a53da1466277..c22543b33420 100644 --- a/fs/ocfs2/aops.c +++ b/fs/ocfs2/aops.c | |||
@@ -68,9 +68,7 @@ static int ocfs2_symlink_get_block(struct inode *inode, sector_t iblock, | |||
68 | goto bail; | 68 | goto bail; |
69 | } | 69 | } |
70 | 70 | ||
71 | status = ocfs2_read_block(OCFS2_SB(inode->i_sb), | 71 | status = ocfs2_read_block(inode, OCFS2_I(inode)->ip_blkno, &bh); |
72 | OCFS2_I(inode)->ip_blkno, | ||
73 | &bh, OCFS2_BH_CACHED, inode); | ||
74 | if (status < 0) { | 72 | if (status < 0) { |
75 | mlog_errno(status); | 73 | mlog_errno(status); |
76 | goto bail; | 74 | goto bail; |
@@ -128,8 +126,7 @@ static int ocfs2_symlink_get_block(struct inode *inode, sector_t iblock, | |||
128 | err = 0; | 126 | err = 0; |
129 | 127 | ||
130 | bail: | 128 | bail: |
131 | if (bh) | 129 | brelse(bh); |
132 | brelse(bh); | ||
133 | 130 | ||
134 | mlog_exit(err); | 131 | mlog_exit(err); |
135 | return err; | 132 | return err; |
@@ -261,13 +258,11 @@ static int ocfs2_readpage_inline(struct inode *inode, struct page *page) | |||
261 | { | 258 | { |
262 | int ret; | 259 | int ret; |
263 | struct buffer_head *di_bh = NULL; | 260 | struct buffer_head *di_bh = NULL; |
264 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
265 | 261 | ||
266 | BUG_ON(!PageLocked(page)); | 262 | BUG_ON(!PageLocked(page)); |
267 | BUG_ON(!(OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL)); | 263 | BUG_ON(!(OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL)); |
268 | 264 | ||
269 | ret = ocfs2_read_block(osb, OCFS2_I(inode)->ip_blkno, &di_bh, | 265 | ret = ocfs2_read_block(inode, OCFS2_I(inode)->ip_blkno, &di_bh); |
270 | OCFS2_BH_CACHED, inode); | ||
271 | if (ret) { | 266 | if (ret) { |
272 | mlog_errno(ret); | 267 | mlog_errno(ret); |
273 | goto out; | 268 | goto out; |
@@ -485,11 +480,14 @@ handle_t *ocfs2_start_walk_page_trans(struct inode *inode, | |||
485 | } | 480 | } |
486 | 481 | ||
487 | if (ocfs2_should_order_data(inode)) { | 482 | if (ocfs2_should_order_data(inode)) { |
483 | ret = ocfs2_jbd2_file_inode(handle, inode); | ||
484 | #ifdef CONFIG_OCFS2_COMPAT_JBD | ||
488 | ret = walk_page_buffers(handle, | 485 | ret = walk_page_buffers(handle, |
489 | page_buffers(page), | 486 | page_buffers(page), |
490 | from, to, NULL, | 487 | from, to, NULL, |
491 | ocfs2_journal_dirty_data); | 488 | ocfs2_journal_dirty_data); |
492 | if (ret < 0) | 489 | #endif |
490 | if (ret < 0) | ||
493 | mlog_errno(ret); | 491 | mlog_errno(ret); |
494 | } | 492 | } |
495 | out: | 493 | out: |
@@ -669,7 +667,7 @@ static void ocfs2_invalidatepage(struct page *page, unsigned long offset) | |||
669 | { | 667 | { |
670 | journal_t *journal = OCFS2_SB(page->mapping->host->i_sb)->journal->j_journal; | 668 | journal_t *journal = OCFS2_SB(page->mapping->host->i_sb)->journal->j_journal; |
671 | 669 | ||
672 | journal_invalidatepage(journal, page, offset); | 670 | jbd2_journal_invalidatepage(journal, page, offset); |
673 | } | 671 | } |
674 | 672 | ||
675 | static int ocfs2_releasepage(struct page *page, gfp_t wait) | 673 | static int ocfs2_releasepage(struct page *page, gfp_t wait) |
@@ -678,7 +676,7 @@ static int ocfs2_releasepage(struct page *page, gfp_t wait) | |||
678 | 676 | ||
679 | if (!page_has_buffers(page)) | 677 | if (!page_has_buffers(page)) |
680 | return 0; | 678 | return 0; |
681 | return journal_try_to_free_buffers(journal, page, wait); | 679 | return jbd2_journal_try_to_free_buffers(journal, page, wait); |
682 | } | 680 | } |
683 | 681 | ||
684 | static ssize_t ocfs2_direct_IO(int rw, | 682 | static ssize_t ocfs2_direct_IO(int rw, |
@@ -1074,11 +1072,15 @@ static void ocfs2_write_failure(struct inode *inode, | |||
1074 | tmppage = wc->w_pages[i]; | 1072 | tmppage = wc->w_pages[i]; |
1075 | 1073 | ||
1076 | if (page_has_buffers(tmppage)) { | 1074 | if (page_has_buffers(tmppage)) { |
1077 | if (ocfs2_should_order_data(inode)) | 1075 | if (ocfs2_should_order_data(inode)) { |
1076 | ocfs2_jbd2_file_inode(wc->w_handle, inode); | ||
1077 | #ifdef CONFIG_OCFS2_COMPAT_JBD | ||
1078 | walk_page_buffers(wc->w_handle, | 1078 | walk_page_buffers(wc->w_handle, |
1079 | page_buffers(tmppage), | 1079 | page_buffers(tmppage), |
1080 | from, to, NULL, | 1080 | from, to, NULL, |
1081 | ocfs2_journal_dirty_data); | 1081 | ocfs2_journal_dirty_data); |
1082 | #endif | ||
1083 | } | ||
1082 | 1084 | ||
1083 | block_commit_write(tmppage, from, to); | 1085 | block_commit_write(tmppage, from, to); |
1084 | } | 1086 | } |
@@ -1242,6 +1244,7 @@ static int ocfs2_write_cluster(struct address_space *mapping, | |||
1242 | int ret, i, new, should_zero = 0; | 1244 | int ret, i, new, should_zero = 0; |
1243 | u64 v_blkno, p_blkno; | 1245 | u64 v_blkno, p_blkno; |
1244 | struct inode *inode = mapping->host; | 1246 | struct inode *inode = mapping->host; |
1247 | struct ocfs2_extent_tree et; | ||
1245 | 1248 | ||
1246 | new = phys == 0 ? 1 : 0; | 1249 | new = phys == 0 ? 1 : 0; |
1247 | if (new || unwritten) | 1250 | if (new || unwritten) |
@@ -1255,10 +1258,10 @@ static int ocfs2_write_cluster(struct address_space *mapping, | |||
1255 | * any additional semaphores or cluster locks. | 1258 | * any additional semaphores or cluster locks. |
1256 | */ | 1259 | */ |
1257 | tmp_pos = cpos; | 1260 | tmp_pos = cpos; |
1258 | ret = ocfs2_do_extend_allocation(OCFS2_SB(inode->i_sb), inode, | 1261 | ret = ocfs2_add_inode_data(OCFS2_SB(inode->i_sb), inode, |
1259 | &tmp_pos, 1, 0, wc->w_di_bh, | 1262 | &tmp_pos, 1, 0, wc->w_di_bh, |
1260 | wc->w_handle, data_ac, | 1263 | wc->w_handle, data_ac, |
1261 | meta_ac, NULL); | 1264 | meta_ac, NULL); |
1262 | /* | 1265 | /* |
1263 | * This shouldn't happen because we must have already | 1266 | * This shouldn't happen because we must have already |
1264 | * calculated the correct meta data allocation required. The | 1267 | * calculated the correct meta data allocation required. The |
@@ -1276,7 +1279,8 @@ static int ocfs2_write_cluster(struct address_space *mapping, | |||
1276 | goto out; | 1279 | goto out; |
1277 | } | 1280 | } |
1278 | } else if (unwritten) { | 1281 | } else if (unwritten) { |
1279 | ret = ocfs2_mark_extent_written(inode, wc->w_di_bh, | 1282 | ocfs2_init_dinode_extent_tree(&et, inode, wc->w_di_bh); |
1283 | ret = ocfs2_mark_extent_written(inode, &et, | ||
1280 | wc->w_handle, cpos, 1, phys, | 1284 | wc->w_handle, cpos, 1, phys, |
1281 | meta_ac, &wc->w_dealloc); | 1285 | meta_ac, &wc->w_dealloc); |
1282 | if (ret < 0) { | 1286 | if (ret < 0) { |
@@ -1665,6 +1669,7 @@ int ocfs2_write_begin_nolock(struct address_space *mapping, | |||
1665 | struct ocfs2_alloc_context *data_ac = NULL; | 1669 | struct ocfs2_alloc_context *data_ac = NULL; |
1666 | struct ocfs2_alloc_context *meta_ac = NULL; | 1670 | struct ocfs2_alloc_context *meta_ac = NULL; |
1667 | handle_t *handle; | 1671 | handle_t *handle; |
1672 | struct ocfs2_extent_tree et; | ||
1668 | 1673 | ||
1669 | ret = ocfs2_alloc_write_ctxt(&wc, osb, pos, len, di_bh); | 1674 | ret = ocfs2_alloc_write_ctxt(&wc, osb, pos, len, di_bh); |
1670 | if (ret) { | 1675 | if (ret) { |
@@ -1712,14 +1717,23 @@ int ocfs2_write_begin_nolock(struct address_space *mapping, | |||
1712 | * ocfs2_lock_allocators(). It greatly over-estimates | 1717 | * ocfs2_lock_allocators(). It greatly over-estimates |
1713 | * the work to be done. | 1718 | * the work to be done. |
1714 | */ | 1719 | */ |
1715 | ret = ocfs2_lock_allocators(inode, di, clusters_to_alloc, | 1720 | mlog(0, "extend inode %llu, i_size = %lld, di->i_clusters = %u," |
1716 | extents_to_split, &data_ac, &meta_ac); | 1721 | " clusters_to_add = %u, extents_to_split = %u\n", |
1722 | (unsigned long long)OCFS2_I(inode)->ip_blkno, | ||
1723 | (long long)i_size_read(inode), le32_to_cpu(di->i_clusters), | ||
1724 | clusters_to_alloc, extents_to_split); | ||
1725 | |||
1726 | ocfs2_init_dinode_extent_tree(&et, inode, wc->w_di_bh); | ||
1727 | ret = ocfs2_lock_allocators(inode, &et, | ||
1728 | clusters_to_alloc, extents_to_split, | ||
1729 | &data_ac, &meta_ac); | ||
1717 | if (ret) { | 1730 | if (ret) { |
1718 | mlog_errno(ret); | 1731 | mlog_errno(ret); |
1719 | goto out; | 1732 | goto out; |
1720 | } | 1733 | } |
1721 | 1734 | ||
1722 | credits = ocfs2_calc_extend_credits(inode->i_sb, di, | 1735 | credits = ocfs2_calc_extend_credits(inode->i_sb, |
1736 | &di->id2.i_list, | ||
1723 | clusters_to_alloc); | 1737 | clusters_to_alloc); |
1724 | 1738 | ||
1725 | } | 1739 | } |
@@ -1905,11 +1919,15 @@ int ocfs2_write_end_nolock(struct address_space *mapping, | |||
1905 | } | 1919 | } |
1906 | 1920 | ||
1907 | if (page_has_buffers(tmppage)) { | 1921 | if (page_has_buffers(tmppage)) { |
1908 | if (ocfs2_should_order_data(inode)) | 1922 | if (ocfs2_should_order_data(inode)) { |
1923 | ocfs2_jbd2_file_inode(wc->w_handle, inode); | ||
1924 | #ifdef CONFIG_OCFS2_COMPAT_JBD | ||
1909 | walk_page_buffers(wc->w_handle, | 1925 | walk_page_buffers(wc->w_handle, |
1910 | page_buffers(tmppage), | 1926 | page_buffers(tmppage), |
1911 | from, to, NULL, | 1927 | from, to, NULL, |
1912 | ocfs2_journal_dirty_data); | 1928 | ocfs2_journal_dirty_data); |
1929 | #endif | ||
1930 | } | ||
1913 | block_commit_write(tmppage, from, to); | 1931 | block_commit_write(tmppage, from, to); |
1914 | } | 1932 | } |
1915 | } | 1933 | } |
diff --git a/fs/ocfs2/buffer_head_io.c b/fs/ocfs2/buffer_head_io.c index f136639f5b41..7e947c672469 100644 --- a/fs/ocfs2/buffer_head_io.c +++ b/fs/ocfs2/buffer_head_io.c | |||
@@ -66,7 +66,7 @@ int ocfs2_write_block(struct ocfs2_super *osb, struct buffer_head *bh, | |||
66 | /* remove from dirty list before I/O. */ | 66 | /* remove from dirty list before I/O. */ |
67 | clear_buffer_dirty(bh); | 67 | clear_buffer_dirty(bh); |
68 | 68 | ||
69 | get_bh(bh); /* for end_buffer_write_sync() */ | 69 | get_bh(bh); /* for end_buffer_write_sync() */ |
70 | bh->b_end_io = end_buffer_write_sync; | 70 | bh->b_end_io = end_buffer_write_sync; |
71 | submit_bh(WRITE, bh); | 71 | submit_bh(WRITE, bh); |
72 | 72 | ||
@@ -88,22 +88,103 @@ out: | |||
88 | return ret; | 88 | return ret; |
89 | } | 89 | } |
90 | 90 | ||
91 | int ocfs2_read_blocks(struct ocfs2_super *osb, u64 block, int nr, | 91 | int ocfs2_read_blocks_sync(struct ocfs2_super *osb, u64 block, |
92 | struct buffer_head *bhs[], int flags, | 92 | unsigned int nr, struct buffer_head *bhs[]) |
93 | struct inode *inode) | 93 | { |
94 | int status = 0; | ||
95 | unsigned int i; | ||
96 | struct buffer_head *bh; | ||
97 | |||
98 | if (!nr) { | ||
99 | mlog(ML_BH_IO, "No buffers will be read!\n"); | ||
100 | goto bail; | ||
101 | } | ||
102 | |||
103 | for (i = 0 ; i < nr ; i++) { | ||
104 | if (bhs[i] == NULL) { | ||
105 | bhs[i] = sb_getblk(osb->sb, block++); | ||
106 | if (bhs[i] == NULL) { | ||
107 | status = -EIO; | ||
108 | mlog_errno(status); | ||
109 | goto bail; | ||
110 | } | ||
111 | } | ||
112 | bh = bhs[i]; | ||
113 | |||
114 | if (buffer_jbd(bh)) { | ||
115 | mlog(ML_ERROR, | ||
116 | "trying to sync read a jbd " | ||
117 | "managed bh (blocknr = %llu), skipping\n", | ||
118 | (unsigned long long)bh->b_blocknr); | ||
119 | continue; | ||
120 | } | ||
121 | |||
122 | if (buffer_dirty(bh)) { | ||
123 | /* This should probably be a BUG, or | ||
124 | * at least return an error. */ | ||
125 | mlog(ML_ERROR, | ||
126 | "trying to sync read a dirty " | ||
127 | "buffer! (blocknr = %llu), skipping\n", | ||
128 | (unsigned long long)bh->b_blocknr); | ||
129 | continue; | ||
130 | } | ||
131 | |||
132 | lock_buffer(bh); | ||
133 | if (buffer_jbd(bh)) { | ||
134 | mlog(ML_ERROR, | ||
135 | "block %llu had the JBD bit set " | ||
136 | "while I was in lock_buffer!", | ||
137 | (unsigned long long)bh->b_blocknr); | ||
138 | BUG(); | ||
139 | } | ||
140 | |||
141 | clear_buffer_uptodate(bh); | ||
142 | get_bh(bh); /* for end_buffer_read_sync() */ | ||
143 | bh->b_end_io = end_buffer_read_sync; | ||
144 | submit_bh(READ, bh); | ||
145 | } | ||
146 | |||
147 | for (i = nr; i > 0; i--) { | ||
148 | bh = bhs[i - 1]; | ||
149 | |||
150 | if (buffer_jbd(bh)) { | ||
151 | mlog(ML_ERROR, | ||
152 | "the journal got the buffer while it was " | ||
153 | "locked for io! (blocknr = %llu)\n", | ||
154 | (unsigned long long)bh->b_blocknr); | ||
155 | BUG(); | ||
156 | } | ||
157 | |||
158 | wait_on_buffer(bh); | ||
159 | if (!buffer_uptodate(bh)) { | ||
160 | /* Status won't be cleared from here on out, | ||
161 | * so we can safely record this and loop back | ||
162 | * to cleanup the other buffers. */ | ||
163 | status = -EIO; | ||
164 | put_bh(bh); | ||
165 | bhs[i - 1] = NULL; | ||
166 | } | ||
167 | } | ||
168 | |||
169 | bail: | ||
170 | return status; | ||
171 | } | ||
172 | |||
173 | int ocfs2_read_blocks(struct inode *inode, u64 block, int nr, | ||
174 | struct buffer_head *bhs[], int flags) | ||
94 | { | 175 | { |
95 | int status = 0; | 176 | int status = 0; |
96 | struct super_block *sb; | ||
97 | int i, ignore_cache = 0; | 177 | int i, ignore_cache = 0; |
98 | struct buffer_head *bh; | 178 | struct buffer_head *bh; |
99 | 179 | ||
100 | mlog_entry("(block=(%llu), nr=(%d), flags=%d, inode=%p)\n", | 180 | mlog_entry("(inode=%p, block=(%llu), nr=(%d), flags=%d)\n", |
101 | (unsigned long long)block, nr, flags, inode); | 181 | inode, (unsigned long long)block, nr, flags); |
102 | 182 | ||
183 | BUG_ON(!inode); | ||
103 | BUG_ON((flags & OCFS2_BH_READAHEAD) && | 184 | BUG_ON((flags & OCFS2_BH_READAHEAD) && |
104 | (!inode || !(flags & OCFS2_BH_CACHED))); | 185 | (flags & OCFS2_BH_IGNORE_CACHE)); |
105 | 186 | ||
106 | if (osb == NULL || osb->sb == NULL || bhs == NULL) { | 187 | if (bhs == NULL) { |
107 | status = -EINVAL; | 188 | status = -EINVAL; |
108 | mlog_errno(status); | 189 | mlog_errno(status); |
109 | goto bail; | 190 | goto bail; |
@@ -122,26 +203,19 @@ int ocfs2_read_blocks(struct ocfs2_super *osb, u64 block, int nr, | |||
122 | goto bail; | 203 | goto bail; |
123 | } | 204 | } |
124 | 205 | ||
125 | sb = osb->sb; | 206 | mutex_lock(&OCFS2_I(inode)->ip_io_mutex); |
126 | |||
127 | if (flags & OCFS2_BH_CACHED && !inode) | ||
128 | flags &= ~OCFS2_BH_CACHED; | ||
129 | |||
130 | if (inode) | ||
131 | mutex_lock(&OCFS2_I(inode)->ip_io_mutex); | ||
132 | for (i = 0 ; i < nr ; i++) { | 207 | for (i = 0 ; i < nr ; i++) { |
133 | if (bhs[i] == NULL) { | 208 | if (bhs[i] == NULL) { |
134 | bhs[i] = sb_getblk(sb, block++); | 209 | bhs[i] = sb_getblk(inode->i_sb, block++); |
135 | if (bhs[i] == NULL) { | 210 | if (bhs[i] == NULL) { |
136 | if (inode) | 211 | mutex_unlock(&OCFS2_I(inode)->ip_io_mutex); |
137 | mutex_unlock(&OCFS2_I(inode)->ip_io_mutex); | ||
138 | status = -EIO; | 212 | status = -EIO; |
139 | mlog_errno(status); | 213 | mlog_errno(status); |
140 | goto bail; | 214 | goto bail; |
141 | } | 215 | } |
142 | } | 216 | } |
143 | bh = bhs[i]; | 217 | bh = bhs[i]; |
144 | ignore_cache = 0; | 218 | ignore_cache = (flags & OCFS2_BH_IGNORE_CACHE); |
145 | 219 | ||
146 | /* There are three read-ahead cases here which we need to | 220 | /* There are three read-ahead cases here which we need to |
147 | * be concerned with. All three assume a buffer has | 221 | * be concerned with. All three assume a buffer has |
@@ -167,26 +241,27 @@ int ocfs2_read_blocks(struct ocfs2_super *osb, u64 block, int nr, | |||
167 | * before our is-it-in-flight check. | 241 | * before our is-it-in-flight check. |
168 | */ | 242 | */ |
169 | 243 | ||
170 | if (flags & OCFS2_BH_CACHED && | 244 | if (!ignore_cache && !ocfs2_buffer_uptodate(inode, bh)) { |
171 | !ocfs2_buffer_uptodate(inode, bh)) { | ||
172 | mlog(ML_UPTODATE, | 245 | mlog(ML_UPTODATE, |
173 | "bh (%llu), inode %llu not uptodate\n", | 246 | "bh (%llu), inode %llu not uptodate\n", |
174 | (unsigned long long)bh->b_blocknr, | 247 | (unsigned long long)bh->b_blocknr, |
175 | (unsigned long long)OCFS2_I(inode)->ip_blkno); | 248 | (unsigned long long)OCFS2_I(inode)->ip_blkno); |
249 | /* We're using ignore_cache here to say | ||
250 | * "go to disk" */ | ||
176 | ignore_cache = 1; | 251 | ignore_cache = 1; |
177 | } | 252 | } |
178 | 253 | ||
179 | /* XXX: Can we ever get this and *not* have the cached | 254 | /* XXX: Can we ever get this and *not* have the cached |
180 | * flag set? */ | 255 | * flag set? */ |
181 | if (buffer_jbd(bh)) { | 256 | if (buffer_jbd(bh)) { |
182 | if (!(flags & OCFS2_BH_CACHED) || ignore_cache) | 257 | if (ignore_cache) |
183 | mlog(ML_BH_IO, "trying to sync read a jbd " | 258 | mlog(ML_BH_IO, "trying to sync read a jbd " |
184 | "managed bh (blocknr = %llu)\n", | 259 | "managed bh (blocknr = %llu)\n", |
185 | (unsigned long long)bh->b_blocknr); | 260 | (unsigned long long)bh->b_blocknr); |
186 | continue; | 261 | continue; |
187 | } | 262 | } |
188 | 263 | ||
189 | if (!(flags & OCFS2_BH_CACHED) || ignore_cache) { | 264 | if (ignore_cache) { |
190 | if (buffer_dirty(bh)) { | 265 | if (buffer_dirty(bh)) { |
191 | /* This should probably be a BUG, or | 266 | /* This should probably be a BUG, or |
192 | * at least return an error. */ | 267 | * at least return an error. */ |
@@ -221,7 +296,7 @@ int ocfs2_read_blocks(struct ocfs2_super *osb, u64 block, int nr, | |||
221 | * previously read-ahead buffer may have | 296 | * previously read-ahead buffer may have |
222 | * completed I/O while we were waiting for the | 297 | * completed I/O while we were waiting for the |
223 | * buffer lock. */ | 298 | * buffer lock. */ |
224 | if ((flags & OCFS2_BH_CACHED) | 299 | if (!(flags & OCFS2_BH_IGNORE_CACHE) |
225 | && !(flags & OCFS2_BH_READAHEAD) | 300 | && !(flags & OCFS2_BH_READAHEAD) |
226 | && ocfs2_buffer_uptodate(inode, bh)) { | 301 | && ocfs2_buffer_uptodate(inode, bh)) { |
227 | unlock_buffer(bh); | 302 | unlock_buffer(bh); |
@@ -265,15 +340,14 @@ int ocfs2_read_blocks(struct ocfs2_super *osb, u64 block, int nr, | |||
265 | /* Always set the buffer in the cache, even if it was | 340 | /* Always set the buffer in the cache, even if it was |
266 | * a forced read, or read-ahead which hasn't yet | 341 | * a forced read, or read-ahead which hasn't yet |
267 | * completed. */ | 342 | * completed. */ |
268 | if (inode) | 343 | ocfs2_set_buffer_uptodate(inode, bh); |
269 | ocfs2_set_buffer_uptodate(inode, bh); | ||
270 | } | 344 | } |
271 | if (inode) | 345 | mutex_unlock(&OCFS2_I(inode)->ip_io_mutex); |
272 | mutex_unlock(&OCFS2_I(inode)->ip_io_mutex); | ||
273 | 346 | ||
274 | mlog(ML_BH_IO, "block=(%llu), nr=(%d), cached=%s, flags=0x%x\n", | 347 | mlog(ML_BH_IO, "block=(%llu), nr=(%d), cached=%s, flags=0x%x\n", |
275 | (unsigned long long)block, nr, | 348 | (unsigned long long)block, nr, |
276 | (!(flags & OCFS2_BH_CACHED) || ignore_cache) ? "no" : "yes", flags); | 349 | ((flags & OCFS2_BH_IGNORE_CACHE) || ignore_cache) ? "no" : "yes", |
350 | flags); | ||
277 | 351 | ||
278 | bail: | 352 | bail: |
279 | 353 | ||
diff --git a/fs/ocfs2/buffer_head_io.h b/fs/ocfs2/buffer_head_io.h index c2e78614c3e5..75e1dcb1ade7 100644 --- a/fs/ocfs2/buffer_head_io.h +++ b/fs/ocfs2/buffer_head_io.h | |||
@@ -31,31 +31,29 @@ | |||
31 | void ocfs2_end_buffer_io_sync(struct buffer_head *bh, | 31 | void ocfs2_end_buffer_io_sync(struct buffer_head *bh, |
32 | int uptodate); | 32 | int uptodate); |
33 | 33 | ||
34 | static inline int ocfs2_read_block(struct ocfs2_super *osb, | 34 | static inline int ocfs2_read_block(struct inode *inode, |
35 | u64 off, | 35 | u64 off, |
36 | struct buffer_head **bh, | 36 | struct buffer_head **bh); |
37 | int flags, | ||
38 | struct inode *inode); | ||
39 | 37 | ||
40 | int ocfs2_write_block(struct ocfs2_super *osb, | 38 | int ocfs2_write_block(struct ocfs2_super *osb, |
41 | struct buffer_head *bh, | 39 | struct buffer_head *bh, |
42 | struct inode *inode); | 40 | struct inode *inode); |
43 | int ocfs2_read_blocks(struct ocfs2_super *osb, | 41 | int ocfs2_read_blocks(struct inode *inode, |
44 | u64 block, | 42 | u64 block, |
45 | int nr, | 43 | int nr, |
46 | struct buffer_head *bhs[], | 44 | struct buffer_head *bhs[], |
47 | int flags, | 45 | int flags); |
48 | struct inode *inode); | 46 | int ocfs2_read_blocks_sync(struct ocfs2_super *osb, u64 block, |
47 | unsigned int nr, struct buffer_head *bhs[]); | ||
49 | 48 | ||
50 | int ocfs2_write_super_or_backup(struct ocfs2_super *osb, | 49 | int ocfs2_write_super_or_backup(struct ocfs2_super *osb, |
51 | struct buffer_head *bh); | 50 | struct buffer_head *bh); |
52 | 51 | ||
53 | #define OCFS2_BH_CACHED 1 | 52 | #define OCFS2_BH_IGNORE_CACHE 1 |
54 | #define OCFS2_BH_READAHEAD 8 | 53 | #define OCFS2_BH_READAHEAD 8 |
55 | 54 | ||
56 | static inline int ocfs2_read_block(struct ocfs2_super * osb, u64 off, | 55 | static inline int ocfs2_read_block(struct inode *inode, u64 off, |
57 | struct buffer_head **bh, int flags, | 56 | struct buffer_head **bh) |
58 | struct inode *inode) | ||
59 | { | 57 | { |
60 | int status = 0; | 58 | int status = 0; |
61 | 59 | ||
@@ -65,8 +63,7 @@ static inline int ocfs2_read_block(struct ocfs2_super * osb, u64 off, | |||
65 | goto bail; | 63 | goto bail; |
66 | } | 64 | } |
67 | 65 | ||
68 | status = ocfs2_read_blocks(osb, off, 1, bh, | 66 | status = ocfs2_read_blocks(inode, off, 1, bh, 0); |
69 | flags, inode); | ||
70 | 67 | ||
71 | bail: | 68 | bail: |
72 | return status; | 69 | return status; |
diff --git a/fs/ocfs2/cluster/masklog.c b/fs/ocfs2/cluster/masklog.c index 23c732f27529..d8a0cb92cef6 100644 --- a/fs/ocfs2/cluster/masklog.c +++ b/fs/ocfs2/cluster/masklog.c | |||
@@ -109,6 +109,7 @@ static struct mlog_attribute mlog_attrs[MLOG_MAX_BITS] = { | |||
109 | define_mask(CONN), | 109 | define_mask(CONN), |
110 | define_mask(QUORUM), | 110 | define_mask(QUORUM), |
111 | define_mask(EXPORT), | 111 | define_mask(EXPORT), |
112 | define_mask(XATTR), | ||
112 | define_mask(ERROR), | 113 | define_mask(ERROR), |
113 | define_mask(NOTICE), | 114 | define_mask(NOTICE), |
114 | define_mask(KTHREAD), | 115 | define_mask(KTHREAD), |
diff --git a/fs/ocfs2/cluster/masklog.h b/fs/ocfs2/cluster/masklog.h index 597e064bb94f..57670c680471 100644 --- a/fs/ocfs2/cluster/masklog.h +++ b/fs/ocfs2/cluster/masklog.h | |||
@@ -112,6 +112,7 @@ | |||
112 | #define ML_CONN 0x0000000004000000ULL /* net connection management */ | 112 | #define ML_CONN 0x0000000004000000ULL /* net connection management */ |
113 | #define ML_QUORUM 0x0000000008000000ULL /* net connection quorum */ | 113 | #define ML_QUORUM 0x0000000008000000ULL /* net connection quorum */ |
114 | #define ML_EXPORT 0x0000000010000000ULL /* ocfs2 export operations */ | 114 | #define ML_EXPORT 0x0000000010000000ULL /* ocfs2 export operations */ |
115 | #define ML_XATTR 0x0000000020000000ULL /* ocfs2 extended attributes */ | ||
115 | /* bits that are infrequently given and frequently matched in the high word */ | 116 | /* bits that are infrequently given and frequently matched in the high word */ |
116 | #define ML_ERROR 0x0000000100000000ULL /* sent to KERN_ERR */ | 117 | #define ML_ERROR 0x0000000100000000ULL /* sent to KERN_ERR */ |
117 | #define ML_NOTICE 0x0000000200000000ULL /* setn to KERN_NOTICE */ | 118 | #define ML_NOTICE 0x0000000200000000ULL /* setn to KERN_NOTICE */ |
diff --git a/fs/ocfs2/dir.c b/fs/ocfs2/dir.c index 9cce563fd627..026e6eb85187 100644 --- a/fs/ocfs2/dir.c +++ b/fs/ocfs2/dir.c | |||
@@ -82,6 +82,49 @@ static int ocfs2_do_extend_dir(struct super_block *sb, | |||
82 | struct ocfs2_alloc_context *meta_ac, | 82 | struct ocfs2_alloc_context *meta_ac, |
83 | struct buffer_head **new_bh); | 83 | struct buffer_head **new_bh); |
84 | 84 | ||
85 | static struct buffer_head *ocfs2_bread(struct inode *inode, | ||
86 | int block, int *err, int reada) | ||
87 | { | ||
88 | struct buffer_head *bh = NULL; | ||
89 | int tmperr; | ||
90 | u64 p_blkno; | ||
91 | int readflags = 0; | ||
92 | |||
93 | if (reada) | ||
94 | readflags |= OCFS2_BH_READAHEAD; | ||
95 | |||
96 | if (((u64)block << inode->i_sb->s_blocksize_bits) >= | ||
97 | i_size_read(inode)) { | ||
98 | BUG_ON(!reada); | ||
99 | return NULL; | ||
100 | } | ||
101 | |||
102 | down_read(&OCFS2_I(inode)->ip_alloc_sem); | ||
103 | tmperr = ocfs2_extent_map_get_blocks(inode, block, &p_blkno, NULL, | ||
104 | NULL); | ||
105 | up_read(&OCFS2_I(inode)->ip_alloc_sem); | ||
106 | if (tmperr < 0) { | ||
107 | mlog_errno(tmperr); | ||
108 | goto fail; | ||
109 | } | ||
110 | |||
111 | tmperr = ocfs2_read_blocks(inode, p_blkno, 1, &bh, readflags); | ||
112 | if (tmperr < 0) | ||
113 | goto fail; | ||
114 | |||
115 | tmperr = 0; | ||
116 | |||
117 | *err = 0; | ||
118 | return bh; | ||
119 | |||
120 | fail: | ||
121 | brelse(bh); | ||
122 | bh = NULL; | ||
123 | |||
124 | *err = -EIO; | ||
125 | return NULL; | ||
126 | } | ||
127 | |||
85 | /* | 128 | /* |
86 | * bh passed here can be an inode block or a dir data block, depending | 129 | * bh passed here can be an inode block or a dir data block, depending |
87 | * on the inode inline data flag. | 130 | * on the inode inline data flag. |
@@ -188,8 +231,7 @@ static struct buffer_head *ocfs2_find_entry_id(const char *name, | |||
188 | struct ocfs2_dinode *di; | 231 | struct ocfs2_dinode *di; |
189 | struct ocfs2_inline_data *data; | 232 | struct ocfs2_inline_data *data; |
190 | 233 | ||
191 | ret = ocfs2_read_block(OCFS2_SB(dir->i_sb), OCFS2_I(dir)->ip_blkno, | 234 | ret = ocfs2_read_block(dir, OCFS2_I(dir)->ip_blkno, &di_bh); |
192 | &di_bh, OCFS2_BH_CACHED, dir); | ||
193 | if (ret) { | 235 | if (ret) { |
194 | mlog_errno(ret); | 236 | mlog_errno(ret); |
195 | goto out; | 237 | goto out; |
@@ -260,14 +302,13 @@ restart: | |||
260 | } | 302 | } |
261 | if ((bh = bh_use[ra_ptr++]) == NULL) | 303 | if ((bh = bh_use[ra_ptr++]) == NULL) |
262 | goto next; | 304 | goto next; |
263 | wait_on_buffer(bh); | 305 | if (ocfs2_read_block(dir, block, &bh)) { |
264 | if (!buffer_uptodate(bh)) { | 306 | /* read error, skip block & hope for the best. |
265 | /* read error, skip block & hope for the best */ | 307 | * ocfs2_read_block() has released the bh. */ |
266 | ocfs2_error(dir->i_sb, "reading directory %llu, " | 308 | ocfs2_error(dir->i_sb, "reading directory %llu, " |
267 | "offset %lu\n", | 309 | "offset %lu\n", |
268 | (unsigned long long)OCFS2_I(dir)->ip_blkno, | 310 | (unsigned long long)OCFS2_I(dir)->ip_blkno, |
269 | block); | 311 | block); |
270 | brelse(bh); | ||
271 | goto next; | 312 | goto next; |
272 | } | 313 | } |
273 | i = ocfs2_search_dirblock(bh, dir, name, namelen, | 314 | i = ocfs2_search_dirblock(bh, dir, name, namelen, |
@@ -417,8 +458,7 @@ static inline int ocfs2_delete_entry_id(handle_t *handle, | |||
417 | struct ocfs2_dinode *di; | 458 | struct ocfs2_dinode *di; |
418 | struct ocfs2_inline_data *data; | 459 | struct ocfs2_inline_data *data; |
419 | 460 | ||
420 | ret = ocfs2_read_block(OCFS2_SB(dir->i_sb), OCFS2_I(dir)->ip_blkno, | 461 | ret = ocfs2_read_block(dir, OCFS2_I(dir)->ip_blkno, &di_bh); |
421 | &di_bh, OCFS2_BH_CACHED, dir); | ||
422 | if (ret) { | 462 | if (ret) { |
423 | mlog_errno(ret); | 463 | mlog_errno(ret); |
424 | goto out; | 464 | goto out; |
@@ -596,8 +636,7 @@ static int ocfs2_dir_foreach_blk_id(struct inode *inode, | |||
596 | struct ocfs2_inline_data *data; | 636 | struct ocfs2_inline_data *data; |
597 | struct ocfs2_dir_entry *de; | 637 | struct ocfs2_dir_entry *de; |
598 | 638 | ||
599 | ret = ocfs2_read_block(OCFS2_SB(inode->i_sb), OCFS2_I(inode)->ip_blkno, | 639 | ret = ocfs2_read_block(inode, OCFS2_I(inode)->ip_blkno, &di_bh); |
600 | &di_bh, OCFS2_BH_CACHED, inode); | ||
601 | if (ret) { | 640 | if (ret) { |
602 | mlog(ML_ERROR, "Unable to read inode block for dir %llu\n", | 641 | mlog(ML_ERROR, "Unable to read inode block for dir %llu\n", |
603 | (unsigned long long)OCFS2_I(inode)->ip_blkno); | 642 | (unsigned long long)OCFS2_I(inode)->ip_blkno); |
@@ -716,8 +755,7 @@ static int ocfs2_dir_foreach_blk_el(struct inode *inode, | |||
716 | for (i = ra_sectors >> (sb->s_blocksize_bits - 9); | 755 | for (i = ra_sectors >> (sb->s_blocksize_bits - 9); |
717 | i > 0; i--) { | 756 | i > 0; i--) { |
718 | tmp = ocfs2_bread(inode, ++blk, &err, 1); | 757 | tmp = ocfs2_bread(inode, ++blk, &err, 1); |
719 | if (tmp) | 758 | brelse(tmp); |
720 | brelse(tmp); | ||
721 | } | 759 | } |
722 | last_ra_blk = blk; | 760 | last_ra_blk = blk; |
723 | ra_sectors = 8; | 761 | ra_sectors = 8; |
@@ -899,10 +937,8 @@ int ocfs2_find_files_on_disk(const char *name, | |||
899 | leave: | 937 | leave: |
900 | if (status < 0) { | 938 | if (status < 0) { |
901 | *dirent = NULL; | 939 | *dirent = NULL; |
902 | if (*dirent_bh) { | 940 | brelse(*dirent_bh); |
903 | brelse(*dirent_bh); | 941 | *dirent_bh = NULL; |
904 | *dirent_bh = NULL; | ||
905 | } | ||
906 | } | 942 | } |
907 | 943 | ||
908 | mlog_exit(status); | 944 | mlog_exit(status); |
@@ -951,8 +987,7 @@ int ocfs2_check_dir_for_entry(struct inode *dir, | |||
951 | 987 | ||
952 | ret = 0; | 988 | ret = 0; |
953 | bail: | 989 | bail: |
954 | if (dirent_bh) | 990 | brelse(dirent_bh); |
955 | brelse(dirent_bh); | ||
956 | 991 | ||
957 | mlog_exit(ret); | 992 | mlog_exit(ret); |
958 | return ret; | 993 | return ret; |
@@ -1127,8 +1162,7 @@ static int ocfs2_fill_new_dir_el(struct ocfs2_super *osb, | |||
1127 | 1162 | ||
1128 | status = 0; | 1163 | status = 0; |
1129 | bail: | 1164 | bail: |
1130 | if (new_bh) | 1165 | brelse(new_bh); |
1131 | brelse(new_bh); | ||
1132 | 1166 | ||
1133 | mlog_exit(status); | 1167 | mlog_exit(status); |
1134 | return status; | 1168 | return status; |
@@ -1192,6 +1226,9 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh, | |||
1192 | struct buffer_head *dirdata_bh = NULL; | 1226 | struct buffer_head *dirdata_bh = NULL; |
1193 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; | 1227 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; |
1194 | handle_t *handle; | 1228 | handle_t *handle; |
1229 | struct ocfs2_extent_tree et; | ||
1230 | |||
1231 | ocfs2_init_dinode_extent_tree(&et, dir, di_bh); | ||
1195 | 1232 | ||
1196 | alloc = ocfs2_clusters_for_bytes(sb, bytes); | 1233 | alloc = ocfs2_clusters_for_bytes(sb, bytes); |
1197 | 1234 | ||
@@ -1305,8 +1342,8 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh, | |||
1305 | * This should never fail as our extent list is empty and all | 1342 | * This should never fail as our extent list is empty and all |
1306 | * related blocks have been journaled already. | 1343 | * related blocks have been journaled already. |
1307 | */ | 1344 | */ |
1308 | ret = ocfs2_insert_extent(osb, handle, dir, di_bh, 0, blkno, len, 0, | 1345 | ret = ocfs2_insert_extent(osb, handle, dir, &et, 0, blkno, len, |
1309 | NULL); | 1346 | 0, NULL); |
1310 | if (ret) { | 1347 | if (ret) { |
1311 | mlog_errno(ret); | 1348 | mlog_errno(ret); |
1312 | goto out_commit; | 1349 | goto out_commit; |
@@ -1337,8 +1374,8 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh, | |||
1337 | } | 1374 | } |
1338 | blkno = ocfs2_clusters_to_blocks(dir->i_sb, bit_off); | 1375 | blkno = ocfs2_clusters_to_blocks(dir->i_sb, bit_off); |
1339 | 1376 | ||
1340 | ret = ocfs2_insert_extent(osb, handle, dir, di_bh, 1, blkno, | 1377 | ret = ocfs2_insert_extent(osb, handle, dir, &et, 1, |
1341 | len, 0, NULL); | 1378 | blkno, len, 0, NULL); |
1342 | if (ret) { | 1379 | if (ret) { |
1343 | mlog_errno(ret); | 1380 | mlog_errno(ret); |
1344 | goto out_commit; | 1381 | goto out_commit; |
@@ -1383,9 +1420,9 @@ static int ocfs2_do_extend_dir(struct super_block *sb, | |||
1383 | if (extend) { | 1420 | if (extend) { |
1384 | u32 offset = OCFS2_I(dir)->ip_clusters; | 1421 | u32 offset = OCFS2_I(dir)->ip_clusters; |
1385 | 1422 | ||
1386 | status = ocfs2_do_extend_allocation(OCFS2_SB(sb), dir, &offset, | 1423 | status = ocfs2_add_inode_data(OCFS2_SB(sb), dir, &offset, |
1387 | 1, 0, parent_fe_bh, handle, | 1424 | 1, 0, parent_fe_bh, handle, |
1388 | data_ac, meta_ac, NULL); | 1425 | data_ac, meta_ac, NULL); |
1389 | BUG_ON(status == -EAGAIN); | 1426 | BUG_ON(status == -EAGAIN); |
1390 | if (status < 0) { | 1427 | if (status < 0) { |
1391 | mlog_errno(status); | 1428 | mlog_errno(status); |
@@ -1430,12 +1467,14 @@ static int ocfs2_extend_dir(struct ocfs2_super *osb, | |||
1430 | int credits, num_free_extents, drop_alloc_sem = 0; | 1467 | int credits, num_free_extents, drop_alloc_sem = 0; |
1431 | loff_t dir_i_size; | 1468 | loff_t dir_i_size; |
1432 | struct ocfs2_dinode *fe = (struct ocfs2_dinode *) parent_fe_bh->b_data; | 1469 | struct ocfs2_dinode *fe = (struct ocfs2_dinode *) parent_fe_bh->b_data; |
1470 | struct ocfs2_extent_list *el = &fe->id2.i_list; | ||
1433 | struct ocfs2_alloc_context *data_ac = NULL; | 1471 | struct ocfs2_alloc_context *data_ac = NULL; |
1434 | struct ocfs2_alloc_context *meta_ac = NULL; | 1472 | struct ocfs2_alloc_context *meta_ac = NULL; |
1435 | handle_t *handle = NULL; | 1473 | handle_t *handle = NULL; |
1436 | struct buffer_head *new_bh = NULL; | 1474 | struct buffer_head *new_bh = NULL; |
1437 | struct ocfs2_dir_entry * de; | 1475 | struct ocfs2_dir_entry * de; |
1438 | struct super_block *sb = osb->sb; | 1476 | struct super_block *sb = osb->sb; |
1477 | struct ocfs2_extent_tree et; | ||
1439 | 1478 | ||
1440 | mlog_entry_void(); | 1479 | mlog_entry_void(); |
1441 | 1480 | ||
@@ -1479,7 +1518,8 @@ static int ocfs2_extend_dir(struct ocfs2_super *osb, | |||
1479 | spin_lock(&OCFS2_I(dir)->ip_lock); | 1518 | spin_lock(&OCFS2_I(dir)->ip_lock); |
1480 | if (dir_i_size == ocfs2_clusters_to_bytes(sb, OCFS2_I(dir)->ip_clusters)) { | 1519 | if (dir_i_size == ocfs2_clusters_to_bytes(sb, OCFS2_I(dir)->ip_clusters)) { |
1481 | spin_unlock(&OCFS2_I(dir)->ip_lock); | 1520 | spin_unlock(&OCFS2_I(dir)->ip_lock); |
1482 | num_free_extents = ocfs2_num_free_extents(osb, dir, fe); | 1521 | ocfs2_init_dinode_extent_tree(&et, dir, parent_fe_bh); |
1522 | num_free_extents = ocfs2_num_free_extents(osb, dir, &et); | ||
1483 | if (num_free_extents < 0) { | 1523 | if (num_free_extents < 0) { |
1484 | status = num_free_extents; | 1524 | status = num_free_extents; |
1485 | mlog_errno(status); | 1525 | mlog_errno(status); |
@@ -1487,7 +1527,7 @@ static int ocfs2_extend_dir(struct ocfs2_super *osb, | |||
1487 | } | 1527 | } |
1488 | 1528 | ||
1489 | if (!num_free_extents) { | 1529 | if (!num_free_extents) { |
1490 | status = ocfs2_reserve_new_metadata(osb, fe, &meta_ac); | 1530 | status = ocfs2_reserve_new_metadata(osb, el, &meta_ac); |
1491 | if (status < 0) { | 1531 | if (status < 0) { |
1492 | if (status != -ENOSPC) | 1532 | if (status != -ENOSPC) |
1493 | mlog_errno(status); | 1533 | mlog_errno(status); |
@@ -1502,7 +1542,7 @@ static int ocfs2_extend_dir(struct ocfs2_super *osb, | |||
1502 | goto bail; | 1542 | goto bail; |
1503 | } | 1543 | } |
1504 | 1544 | ||
1505 | credits = ocfs2_calc_extend_credits(sb, fe, 1); | 1545 | credits = ocfs2_calc_extend_credits(sb, el, 1); |
1506 | } else { | 1546 | } else { |
1507 | spin_unlock(&OCFS2_I(dir)->ip_lock); | 1547 | spin_unlock(&OCFS2_I(dir)->ip_lock); |
1508 | credits = OCFS2_SIMPLE_DIR_EXTEND_CREDITS; | 1548 | credits = OCFS2_SIMPLE_DIR_EXTEND_CREDITS; |
@@ -1568,8 +1608,7 @@ bail: | |||
1568 | if (meta_ac) | 1608 | if (meta_ac) |
1569 | ocfs2_free_alloc_context(meta_ac); | 1609 | ocfs2_free_alloc_context(meta_ac); |
1570 | 1610 | ||
1571 | if (new_bh) | 1611 | brelse(new_bh); |
1572 | brelse(new_bh); | ||
1573 | 1612 | ||
1574 | mlog_exit(status); | 1613 | mlog_exit(status); |
1575 | return status; | 1614 | return status; |
@@ -1696,8 +1735,7 @@ static int ocfs2_find_dir_space_el(struct inode *dir, const char *name, | |||
1696 | 1735 | ||
1697 | status = 0; | 1736 | status = 0; |
1698 | bail: | 1737 | bail: |
1699 | if (bh) | 1738 | brelse(bh); |
1700 | brelse(bh); | ||
1701 | 1739 | ||
1702 | mlog_exit(status); | 1740 | mlog_exit(status); |
1703 | return status; | 1741 | return status; |
@@ -1756,7 +1794,6 @@ int ocfs2_prepare_dir_for_insert(struct ocfs2_super *osb, | |||
1756 | *ret_de_bh = bh; | 1794 | *ret_de_bh = bh; |
1757 | bh = NULL; | 1795 | bh = NULL; |
1758 | out: | 1796 | out: |
1759 | if (bh) | 1797 | brelse(bh); |
1760 | brelse(bh); | ||
1761 | return ret; | 1798 | return ret; |
1762 | } | 1799 | } |
diff --git a/fs/ocfs2/dlmglue.c b/fs/ocfs2/dlmglue.c index eae3d643a5e4..ec684426034b 100644 --- a/fs/ocfs2/dlmglue.c +++ b/fs/ocfs2/dlmglue.c | |||
@@ -2024,8 +2024,7 @@ static int ocfs2_inode_lock_update(struct inode *inode, | |||
2024 | } else { | 2024 | } else { |
2025 | /* Boo, we have to go to disk. */ | 2025 | /* Boo, we have to go to disk. */ |
2026 | /* read bh, cast, ocfs2_refresh_inode */ | 2026 | /* read bh, cast, ocfs2_refresh_inode */ |
2027 | status = ocfs2_read_block(OCFS2_SB(inode->i_sb), oi->ip_blkno, | 2027 | status = ocfs2_read_block(inode, oi->ip_blkno, bh); |
2028 | bh, OCFS2_BH_CACHED, inode); | ||
2029 | if (status < 0) { | 2028 | if (status < 0) { |
2030 | mlog_errno(status); | 2029 | mlog_errno(status); |
2031 | goto bail_refresh; | 2030 | goto bail_refresh; |
@@ -2086,11 +2085,7 @@ static int ocfs2_assign_bh(struct inode *inode, | |||
2086 | return 0; | 2085 | return 0; |
2087 | } | 2086 | } |
2088 | 2087 | ||
2089 | status = ocfs2_read_block(OCFS2_SB(inode->i_sb), | 2088 | status = ocfs2_read_block(inode, OCFS2_I(inode)->ip_blkno, ret_bh); |
2090 | OCFS2_I(inode)->ip_blkno, | ||
2091 | ret_bh, | ||
2092 | OCFS2_BH_CACHED, | ||
2093 | inode); | ||
2094 | if (status < 0) | 2089 | if (status < 0) |
2095 | mlog_errno(status); | 2090 | mlog_errno(status); |
2096 | 2091 | ||
diff --git a/fs/ocfs2/extent_map.c b/fs/ocfs2/extent_map.c index aed268e80b49..2baedac58234 100644 --- a/fs/ocfs2/extent_map.c +++ b/fs/ocfs2/extent_map.c | |||
@@ -293,8 +293,7 @@ static int ocfs2_last_eb_is_empty(struct inode *inode, | |||
293 | struct ocfs2_extent_block *eb; | 293 | struct ocfs2_extent_block *eb; |
294 | struct ocfs2_extent_list *el; | 294 | struct ocfs2_extent_list *el; |
295 | 295 | ||
296 | ret = ocfs2_read_block(OCFS2_SB(inode->i_sb), last_eb_blk, | 296 | ret = ocfs2_read_block(inode, last_eb_blk, &eb_bh); |
297 | &eb_bh, OCFS2_BH_CACHED, inode); | ||
298 | if (ret) { | 297 | if (ret) { |
299 | mlog_errno(ret); | 298 | mlog_errno(ret); |
300 | goto out; | 299 | goto out; |
@@ -382,9 +381,9 @@ static int ocfs2_figure_hole_clusters(struct inode *inode, | |||
382 | if (le64_to_cpu(eb->h_next_leaf_blk) == 0ULL) | 381 | if (le64_to_cpu(eb->h_next_leaf_blk) == 0ULL) |
383 | goto no_more_extents; | 382 | goto no_more_extents; |
384 | 383 | ||
385 | ret = ocfs2_read_block(OCFS2_SB(inode->i_sb), | 384 | ret = ocfs2_read_block(inode, |
386 | le64_to_cpu(eb->h_next_leaf_blk), | 385 | le64_to_cpu(eb->h_next_leaf_blk), |
387 | &next_eb_bh, OCFS2_BH_CACHED, inode); | 386 | &next_eb_bh); |
388 | if (ret) { | 387 | if (ret) { |
389 | mlog_errno(ret); | 388 | mlog_errno(ret); |
390 | goto out; | 389 | goto out; |
@@ -551,6 +550,66 @@ static void ocfs2_relative_extent_offsets(struct super_block *sb, | |||
551 | *num_clusters = le16_to_cpu(rec->e_leaf_clusters) - coff; | 550 | *num_clusters = le16_to_cpu(rec->e_leaf_clusters) - coff; |
552 | } | 551 | } |
553 | 552 | ||
553 | int ocfs2_xattr_get_clusters(struct inode *inode, u32 v_cluster, | ||
554 | u32 *p_cluster, u32 *num_clusters, | ||
555 | struct ocfs2_extent_list *el) | ||
556 | { | ||
557 | int ret = 0, i; | ||
558 | struct buffer_head *eb_bh = NULL; | ||
559 | struct ocfs2_extent_block *eb; | ||
560 | struct ocfs2_extent_rec *rec; | ||
561 | u32 coff; | ||
562 | |||
563 | if (el->l_tree_depth) { | ||
564 | ret = ocfs2_find_leaf(inode, el, v_cluster, &eb_bh); | ||
565 | if (ret) { | ||
566 | mlog_errno(ret); | ||
567 | goto out; | ||
568 | } | ||
569 | |||
570 | eb = (struct ocfs2_extent_block *) eb_bh->b_data; | ||
571 | el = &eb->h_list; | ||
572 | |||
573 | if (el->l_tree_depth) { | ||
574 | ocfs2_error(inode->i_sb, | ||
575 | "Inode %lu has non zero tree depth in " | ||
576 | "xattr leaf block %llu\n", inode->i_ino, | ||
577 | (unsigned long long)eb_bh->b_blocknr); | ||
578 | ret = -EROFS; | ||
579 | goto out; | ||
580 | } | ||
581 | } | ||
582 | |||
583 | i = ocfs2_search_extent_list(el, v_cluster); | ||
584 | if (i == -1) { | ||
585 | ret = -EROFS; | ||
586 | mlog_errno(ret); | ||
587 | goto out; | ||
588 | } else { | ||
589 | rec = &el->l_recs[i]; | ||
590 | BUG_ON(v_cluster < le32_to_cpu(rec->e_cpos)); | ||
591 | |||
592 | if (!rec->e_blkno) { | ||
593 | ocfs2_error(inode->i_sb, "Inode %lu has bad extent " | ||
594 | "record (%u, %u, 0) in xattr", inode->i_ino, | ||
595 | le32_to_cpu(rec->e_cpos), | ||
596 | ocfs2_rec_clusters(el, rec)); | ||
597 | ret = -EROFS; | ||
598 | goto out; | ||
599 | } | ||
600 | coff = v_cluster - le32_to_cpu(rec->e_cpos); | ||
601 | *p_cluster = ocfs2_blocks_to_clusters(inode->i_sb, | ||
602 | le64_to_cpu(rec->e_blkno)); | ||
603 | *p_cluster = *p_cluster + coff; | ||
604 | if (num_clusters) | ||
605 | *num_clusters = ocfs2_rec_clusters(el, rec) - coff; | ||
606 | } | ||
607 | out: | ||
608 | if (eb_bh) | ||
609 | brelse(eb_bh); | ||
610 | return ret; | ||
611 | } | ||
612 | |||
554 | int ocfs2_get_clusters(struct inode *inode, u32 v_cluster, | 613 | int ocfs2_get_clusters(struct inode *inode, u32 v_cluster, |
555 | u32 *p_cluster, u32 *num_clusters, | 614 | u32 *p_cluster, u32 *num_clusters, |
556 | unsigned int *extent_flags) | 615 | unsigned int *extent_flags) |
@@ -571,8 +630,7 @@ int ocfs2_get_clusters(struct inode *inode, u32 v_cluster, | |||
571 | if (ret == 0) | 630 | if (ret == 0) |
572 | goto out; | 631 | goto out; |
573 | 632 | ||
574 | ret = ocfs2_read_block(OCFS2_SB(inode->i_sb), OCFS2_I(inode)->ip_blkno, | 633 | ret = ocfs2_read_block(inode, OCFS2_I(inode)->ip_blkno, &di_bh); |
575 | &di_bh, OCFS2_BH_CACHED, inode); | ||
576 | if (ret) { | 634 | if (ret) { |
577 | mlog_errno(ret); | 635 | mlog_errno(ret); |
578 | goto out; | 636 | goto out; |
diff --git a/fs/ocfs2/extent_map.h b/fs/ocfs2/extent_map.h index 1b97490e1ea8..1c4aa8b06f34 100644 --- a/fs/ocfs2/extent_map.h +++ b/fs/ocfs2/extent_map.h | |||
@@ -53,4 +53,8 @@ int ocfs2_extent_map_get_blocks(struct inode *inode, u64 v_blkno, u64 *p_blkno, | |||
53 | int ocfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, | 53 | int ocfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, |
54 | u64 map_start, u64 map_len); | 54 | u64 map_start, u64 map_len); |
55 | 55 | ||
56 | int ocfs2_xattr_get_clusters(struct inode *inode, u32 v_cluster, | ||
57 | u32 *p_cluster, u32 *num_clusters, | ||
58 | struct ocfs2_extent_list *el); | ||
59 | |||
56 | #endif /* _EXTENT_MAP_H */ | 60 | #endif /* _EXTENT_MAP_H */ |
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c index ed38796052d2..8d3225a78073 100644 --- a/fs/ocfs2/file.c +++ b/fs/ocfs2/file.c | |||
@@ -55,6 +55,7 @@ | |||
55 | #include "mmap.h" | 55 | #include "mmap.h" |
56 | #include "suballoc.h" | 56 | #include "suballoc.h" |
57 | #include "super.h" | 57 | #include "super.h" |
58 | #include "xattr.h" | ||
58 | 59 | ||
59 | #include "buffer_head_io.h" | 60 | #include "buffer_head_io.h" |
60 | 61 | ||
@@ -184,7 +185,7 @@ static int ocfs2_sync_file(struct file *file, | |||
184 | goto bail; | 185 | goto bail; |
185 | 186 | ||
186 | journal = osb->journal->j_journal; | 187 | journal = osb->journal->j_journal; |
187 | err = journal_force_commit(journal); | 188 | err = jbd2_journal_force_commit(journal); |
188 | 189 | ||
189 | bail: | 190 | bail: |
190 | mlog_exit(err); | 191 | mlog_exit(err); |
@@ -488,7 +489,7 @@ bail: | |||
488 | } | 489 | } |
489 | 490 | ||
490 | /* | 491 | /* |
491 | * extend allocation only here. | 492 | * extend file allocation only here. |
492 | * we'll update all the disk stuff, and oip->alloc_size | 493 | * we'll update all the disk stuff, and oip->alloc_size |
493 | * | 494 | * |
494 | * expect stuff to be locked, a transaction started and enough data / | 495 | * expect stuff to be locked, a transaction started and enough data / |
@@ -497,189 +498,25 @@ bail: | |||
497 | * Will return -EAGAIN, and a reason if a restart is needed. | 498 | * Will return -EAGAIN, and a reason if a restart is needed. |
498 | * If passed in, *reason will always be set, even in error. | 499 | * If passed in, *reason will always be set, even in error. |
499 | */ | 500 | */ |
500 | int ocfs2_do_extend_allocation(struct ocfs2_super *osb, | 501 | int ocfs2_add_inode_data(struct ocfs2_super *osb, |
501 | struct inode *inode, | 502 | struct inode *inode, |
502 | u32 *logical_offset, | 503 | u32 *logical_offset, |
503 | u32 clusters_to_add, | 504 | u32 clusters_to_add, |
504 | int mark_unwritten, | 505 | int mark_unwritten, |
505 | struct buffer_head *fe_bh, | 506 | struct buffer_head *fe_bh, |
506 | handle_t *handle, | 507 | handle_t *handle, |
507 | struct ocfs2_alloc_context *data_ac, | 508 | struct ocfs2_alloc_context *data_ac, |
508 | struct ocfs2_alloc_context *meta_ac, | 509 | struct ocfs2_alloc_context *meta_ac, |
509 | enum ocfs2_alloc_restarted *reason_ret) | 510 | enum ocfs2_alloc_restarted *reason_ret) |
510 | { | 511 | { |
511 | int status = 0; | 512 | int ret; |
512 | int free_extents; | 513 | struct ocfs2_extent_tree et; |
513 | struct ocfs2_dinode *fe = (struct ocfs2_dinode *) fe_bh->b_data; | ||
514 | enum ocfs2_alloc_restarted reason = RESTART_NONE; | ||
515 | u32 bit_off, num_bits; | ||
516 | u64 block; | ||
517 | u8 flags = 0; | ||
518 | |||
519 | BUG_ON(!clusters_to_add); | ||
520 | |||
521 | if (mark_unwritten) | ||
522 | flags = OCFS2_EXT_UNWRITTEN; | ||
523 | |||
524 | free_extents = ocfs2_num_free_extents(osb, inode, fe); | ||
525 | if (free_extents < 0) { | ||
526 | status = free_extents; | ||
527 | mlog_errno(status); | ||
528 | goto leave; | ||
529 | } | ||
530 | |||
531 | /* there are two cases which could cause us to EAGAIN in the | ||
532 | * we-need-more-metadata case: | ||
533 | * 1) we haven't reserved *any* | ||
534 | * 2) we are so fragmented, we've needed to add metadata too | ||
535 | * many times. */ | ||
536 | if (!free_extents && !meta_ac) { | ||
537 | mlog(0, "we haven't reserved any metadata!\n"); | ||
538 | status = -EAGAIN; | ||
539 | reason = RESTART_META; | ||
540 | goto leave; | ||
541 | } else if ((!free_extents) | ||
542 | && (ocfs2_alloc_context_bits_left(meta_ac) | ||
543 | < ocfs2_extend_meta_needed(fe))) { | ||
544 | mlog(0, "filesystem is really fragmented...\n"); | ||
545 | status = -EAGAIN; | ||
546 | reason = RESTART_META; | ||
547 | goto leave; | ||
548 | } | ||
549 | |||
550 | status = __ocfs2_claim_clusters(osb, handle, data_ac, 1, | ||
551 | clusters_to_add, &bit_off, &num_bits); | ||
552 | if (status < 0) { | ||
553 | if (status != -ENOSPC) | ||
554 | mlog_errno(status); | ||
555 | goto leave; | ||
556 | } | ||
557 | |||
558 | BUG_ON(num_bits > clusters_to_add); | ||
559 | |||
560 | /* reserve our write early -- insert_extent may update the inode */ | ||
561 | status = ocfs2_journal_access(handle, inode, fe_bh, | ||
562 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
563 | if (status < 0) { | ||
564 | mlog_errno(status); | ||
565 | goto leave; | ||
566 | } | ||
567 | |||
568 | block = ocfs2_clusters_to_blocks(osb->sb, bit_off); | ||
569 | mlog(0, "Allocating %u clusters at block %u for inode %llu\n", | ||
570 | num_bits, bit_off, (unsigned long long)OCFS2_I(inode)->ip_blkno); | ||
571 | status = ocfs2_insert_extent(osb, handle, inode, fe_bh, | ||
572 | *logical_offset, block, num_bits, | ||
573 | flags, meta_ac); | ||
574 | if (status < 0) { | ||
575 | mlog_errno(status); | ||
576 | goto leave; | ||
577 | } | ||
578 | |||
579 | status = ocfs2_journal_dirty(handle, fe_bh); | ||
580 | if (status < 0) { | ||
581 | mlog_errno(status); | ||
582 | goto leave; | ||
583 | } | ||
584 | |||
585 | clusters_to_add -= num_bits; | ||
586 | *logical_offset += num_bits; | ||
587 | |||
588 | if (clusters_to_add) { | ||
589 | mlog(0, "need to alloc once more, clusters = %u, wanted = " | ||
590 | "%u\n", fe->i_clusters, clusters_to_add); | ||
591 | status = -EAGAIN; | ||
592 | reason = RESTART_TRANS; | ||
593 | } | ||
594 | |||
595 | leave: | ||
596 | mlog_exit(status); | ||
597 | if (reason_ret) | ||
598 | *reason_ret = reason; | ||
599 | return status; | ||
600 | } | ||
601 | |||
602 | /* | ||
603 | * For a given allocation, determine which allocators will need to be | ||
604 | * accessed, and lock them, reserving the appropriate number of bits. | ||
605 | * | ||
606 | * Sparse file systems call this from ocfs2_write_begin_nolock() | ||
607 | * and ocfs2_allocate_unwritten_extents(). | ||
608 | * | ||
609 | * File systems which don't support holes call this from | ||
610 | * ocfs2_extend_allocation(). | ||
611 | */ | ||
612 | int ocfs2_lock_allocators(struct inode *inode, struct ocfs2_dinode *di, | ||
613 | u32 clusters_to_add, u32 extents_to_split, | ||
614 | struct ocfs2_alloc_context **data_ac, | ||
615 | struct ocfs2_alloc_context **meta_ac) | ||
616 | { | ||
617 | int ret = 0, num_free_extents; | ||
618 | unsigned int max_recs_needed = clusters_to_add + 2 * extents_to_split; | ||
619 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
620 | |||
621 | *meta_ac = NULL; | ||
622 | if (data_ac) | ||
623 | *data_ac = NULL; | ||
624 | |||
625 | BUG_ON(clusters_to_add != 0 && data_ac == NULL); | ||
626 | |||
627 | mlog(0, "extend inode %llu, i_size = %lld, di->i_clusters = %u, " | ||
628 | "clusters_to_add = %u, extents_to_split = %u\n", | ||
629 | (unsigned long long)OCFS2_I(inode)->ip_blkno, (long long)i_size_read(inode), | ||
630 | le32_to_cpu(di->i_clusters), clusters_to_add, extents_to_split); | ||
631 | |||
632 | num_free_extents = ocfs2_num_free_extents(osb, inode, di); | ||
633 | if (num_free_extents < 0) { | ||
634 | ret = num_free_extents; | ||
635 | mlog_errno(ret); | ||
636 | goto out; | ||
637 | } | ||
638 | |||
639 | /* | ||
640 | * Sparse allocation file systems need to be more conservative | ||
641 | * with reserving room for expansion - the actual allocation | ||
642 | * happens while we've got a journal handle open so re-taking | ||
643 | * a cluster lock (because we ran out of room for another | ||
644 | * extent) will violate ordering rules. | ||
645 | * | ||
646 | * Most of the time we'll only be seeing this 1 cluster at a time | ||
647 | * anyway. | ||
648 | * | ||
649 | * Always lock for any unwritten extents - we might want to | ||
650 | * add blocks during a split. | ||
651 | */ | ||
652 | if (!num_free_extents || | ||
653 | (ocfs2_sparse_alloc(osb) && num_free_extents < max_recs_needed)) { | ||
654 | ret = ocfs2_reserve_new_metadata(osb, di, meta_ac); | ||
655 | if (ret < 0) { | ||
656 | if (ret != -ENOSPC) | ||
657 | mlog_errno(ret); | ||
658 | goto out; | ||
659 | } | ||
660 | } | ||
661 | |||
662 | if (clusters_to_add == 0) | ||
663 | goto out; | ||
664 | |||
665 | ret = ocfs2_reserve_clusters(osb, clusters_to_add, data_ac); | ||
666 | if (ret < 0) { | ||
667 | if (ret != -ENOSPC) | ||
668 | mlog_errno(ret); | ||
669 | goto out; | ||
670 | } | ||
671 | |||
672 | out: | ||
673 | if (ret) { | ||
674 | if (*meta_ac) { | ||
675 | ocfs2_free_alloc_context(*meta_ac); | ||
676 | *meta_ac = NULL; | ||
677 | } | ||
678 | 514 | ||
679 | /* | 515 | ocfs2_init_dinode_extent_tree(&et, inode, fe_bh); |
680 | * We cannot have an error and a non null *data_ac. | 516 | ret = ocfs2_add_clusters_in_btree(osb, inode, logical_offset, |
681 | */ | 517 | clusters_to_add, mark_unwritten, |
682 | } | 518 | &et, handle, |
519 | data_ac, meta_ac, reason_ret); | ||
683 | 520 | ||
684 | return ret; | 521 | return ret; |
685 | } | 522 | } |
@@ -698,6 +535,7 @@ static int __ocfs2_extend_allocation(struct inode *inode, u32 logical_start, | |||
698 | struct ocfs2_alloc_context *meta_ac = NULL; | 535 | struct ocfs2_alloc_context *meta_ac = NULL; |
699 | enum ocfs2_alloc_restarted why; | 536 | enum ocfs2_alloc_restarted why; |
700 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | 537 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); |
538 | struct ocfs2_extent_tree et; | ||
701 | 539 | ||
702 | mlog_entry("(clusters_to_add = %u)\n", clusters_to_add); | 540 | mlog_entry("(clusters_to_add = %u)\n", clusters_to_add); |
703 | 541 | ||
@@ -707,8 +545,7 @@ static int __ocfs2_extend_allocation(struct inode *inode, u32 logical_start, | |||
707 | */ | 545 | */ |
708 | BUG_ON(mark_unwritten && !ocfs2_sparse_alloc(osb)); | 546 | BUG_ON(mark_unwritten && !ocfs2_sparse_alloc(osb)); |
709 | 547 | ||
710 | status = ocfs2_read_block(osb, OCFS2_I(inode)->ip_blkno, &bh, | 548 | status = ocfs2_read_block(inode, OCFS2_I(inode)->ip_blkno, &bh); |
711 | OCFS2_BH_CACHED, inode); | ||
712 | if (status < 0) { | 549 | if (status < 0) { |
713 | mlog_errno(status); | 550 | mlog_errno(status); |
714 | goto leave; | 551 | goto leave; |
@@ -724,14 +561,21 @@ static int __ocfs2_extend_allocation(struct inode *inode, u32 logical_start, | |||
724 | restart_all: | 561 | restart_all: |
725 | BUG_ON(le32_to_cpu(fe->i_clusters) != OCFS2_I(inode)->ip_clusters); | 562 | BUG_ON(le32_to_cpu(fe->i_clusters) != OCFS2_I(inode)->ip_clusters); |
726 | 563 | ||
727 | status = ocfs2_lock_allocators(inode, fe, clusters_to_add, 0, &data_ac, | 564 | mlog(0, "extend inode %llu, i_size = %lld, di->i_clusters = %u, " |
728 | &meta_ac); | 565 | "clusters_to_add = %u\n", |
566 | (unsigned long long)OCFS2_I(inode)->ip_blkno, | ||
567 | (long long)i_size_read(inode), le32_to_cpu(fe->i_clusters), | ||
568 | clusters_to_add); | ||
569 | ocfs2_init_dinode_extent_tree(&et, inode, bh); | ||
570 | status = ocfs2_lock_allocators(inode, &et, clusters_to_add, 0, | ||
571 | &data_ac, &meta_ac); | ||
729 | if (status) { | 572 | if (status) { |
730 | mlog_errno(status); | 573 | mlog_errno(status); |
731 | goto leave; | 574 | goto leave; |
732 | } | 575 | } |
733 | 576 | ||
734 | credits = ocfs2_calc_extend_credits(osb->sb, fe, clusters_to_add); | 577 | credits = ocfs2_calc_extend_credits(osb->sb, &fe->id2.i_list, |
578 | clusters_to_add); | ||
735 | handle = ocfs2_start_trans(osb, credits); | 579 | handle = ocfs2_start_trans(osb, credits); |
736 | if (IS_ERR(handle)) { | 580 | if (IS_ERR(handle)) { |
737 | status = PTR_ERR(handle); | 581 | status = PTR_ERR(handle); |
@@ -753,16 +597,16 @@ restarted_transaction: | |||
753 | 597 | ||
754 | prev_clusters = OCFS2_I(inode)->ip_clusters; | 598 | prev_clusters = OCFS2_I(inode)->ip_clusters; |
755 | 599 | ||
756 | status = ocfs2_do_extend_allocation(osb, | 600 | status = ocfs2_add_inode_data(osb, |
757 | inode, | 601 | inode, |
758 | &logical_start, | 602 | &logical_start, |
759 | clusters_to_add, | 603 | clusters_to_add, |
760 | mark_unwritten, | 604 | mark_unwritten, |
761 | bh, | 605 | bh, |
762 | handle, | 606 | handle, |
763 | data_ac, | 607 | data_ac, |
764 | meta_ac, | 608 | meta_ac, |
765 | &why); | 609 | &why); |
766 | if ((status < 0) && (status != -EAGAIN)) { | 610 | if ((status < 0) && (status != -EAGAIN)) { |
767 | if (status != -ENOSPC) | 611 | if (status != -ENOSPC) |
768 | mlog_errno(status); | 612 | mlog_errno(status); |
@@ -789,7 +633,7 @@ restarted_transaction: | |||
789 | mlog(0, "restarting transaction.\n"); | 633 | mlog(0, "restarting transaction.\n"); |
790 | /* TODO: This can be more intelligent. */ | 634 | /* TODO: This can be more intelligent. */ |
791 | credits = ocfs2_calc_extend_credits(osb->sb, | 635 | credits = ocfs2_calc_extend_credits(osb->sb, |
792 | fe, | 636 | &fe->id2.i_list, |
793 | clusters_to_add); | 637 | clusters_to_add); |
794 | status = ocfs2_extend_trans(handle, credits); | 638 | status = ocfs2_extend_trans(handle, credits); |
795 | if (status < 0) { | 639 | if (status < 0) { |
@@ -826,10 +670,8 @@ leave: | |||
826 | restart_func = 0; | 670 | restart_func = 0; |
827 | goto restart_all; | 671 | goto restart_all; |
828 | } | 672 | } |
829 | if (bh) { | 673 | brelse(bh); |
830 | brelse(bh); | 674 | bh = NULL; |
831 | bh = NULL; | ||
832 | } | ||
833 | 675 | ||
834 | mlog_exit(status); | 676 | mlog_exit(status); |
835 | return status; | 677 | return status; |
@@ -1096,9 +938,15 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr) | |||
1096 | goto bail_unlock; | 938 | goto bail_unlock; |
1097 | } | 939 | } |
1098 | 940 | ||
1099 | if (i_size_read(inode) > attr->ia_size) | 941 | if (i_size_read(inode) > attr->ia_size) { |
942 | if (ocfs2_should_order_data(inode)) { | ||
943 | status = ocfs2_begin_ordered_truncate(inode, | ||
944 | attr->ia_size); | ||
945 | if (status) | ||
946 | goto bail_unlock; | ||
947 | } | ||
1100 | status = ocfs2_truncate_file(inode, bh, attr->ia_size); | 948 | status = ocfs2_truncate_file(inode, bh, attr->ia_size); |
1101 | else | 949 | } else |
1102 | status = ocfs2_extend_file(inode, bh, attr->ia_size); | 950 | status = ocfs2_extend_file(inode, bh, attr->ia_size); |
1103 | if (status < 0) { | 951 | if (status < 0) { |
1104 | if (status != -ENOSPC) | 952 | if (status != -ENOSPC) |
@@ -1140,8 +988,7 @@ bail_unlock_rw: | |||
1140 | if (size_change) | 988 | if (size_change) |
1141 | ocfs2_rw_unlock(inode, 1); | 989 | ocfs2_rw_unlock(inode, 1); |
1142 | bail: | 990 | bail: |
1143 | if (bh) | 991 | brelse(bh); |
1144 | brelse(bh); | ||
1145 | 992 | ||
1146 | mlog_exit(status); | 993 | mlog_exit(status); |
1147 | return status; | 994 | return status; |
@@ -1284,8 +1131,7 @@ static int ocfs2_write_remove_suid(struct inode *inode) | |||
1284 | struct buffer_head *bh = NULL; | 1131 | struct buffer_head *bh = NULL; |
1285 | struct ocfs2_inode_info *oi = OCFS2_I(inode); | 1132 | struct ocfs2_inode_info *oi = OCFS2_I(inode); |
1286 | 1133 | ||
1287 | ret = ocfs2_read_block(OCFS2_SB(inode->i_sb), | 1134 | ret = ocfs2_read_block(inode, oi->ip_blkno, &bh); |
1288 | oi->ip_blkno, &bh, OCFS2_BH_CACHED, inode); | ||
1289 | if (ret < 0) { | 1135 | if (ret < 0) { |
1290 | mlog_errno(ret); | 1136 | mlog_errno(ret); |
1291 | goto out; | 1137 | goto out; |
@@ -1311,9 +1157,8 @@ static int ocfs2_allocate_unwritten_extents(struct inode *inode, | |||
1311 | struct buffer_head *di_bh = NULL; | 1157 | struct buffer_head *di_bh = NULL; |
1312 | 1158 | ||
1313 | if (OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL) { | 1159 | if (OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL) { |
1314 | ret = ocfs2_read_block(OCFS2_SB(inode->i_sb), | 1160 | ret = ocfs2_read_block(inode, OCFS2_I(inode)->ip_blkno, |
1315 | OCFS2_I(inode)->ip_blkno, &di_bh, | 1161 | &di_bh); |
1316 | OCFS2_BH_CACHED, inode); | ||
1317 | if (ret) { | 1162 | if (ret) { |
1318 | mlog_errno(ret); | 1163 | mlog_errno(ret); |
1319 | goto out; | 1164 | goto out; |
@@ -1394,8 +1239,11 @@ static int __ocfs2_remove_inode_range(struct inode *inode, | |||
1394 | handle_t *handle; | 1239 | handle_t *handle; |
1395 | struct ocfs2_alloc_context *meta_ac = NULL; | 1240 | struct ocfs2_alloc_context *meta_ac = NULL; |
1396 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; | 1241 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; |
1242 | struct ocfs2_extent_tree et; | ||
1397 | 1243 | ||
1398 | ret = ocfs2_lock_allocators(inode, di, 0, 1, NULL, &meta_ac); | 1244 | ocfs2_init_dinode_extent_tree(&et, inode, di_bh); |
1245 | |||
1246 | ret = ocfs2_lock_allocators(inode, &et, 0, 1, NULL, &meta_ac); | ||
1399 | if (ret) { | 1247 | if (ret) { |
1400 | mlog_errno(ret); | 1248 | mlog_errno(ret); |
1401 | return ret; | 1249 | return ret; |
@@ -1425,7 +1273,7 @@ static int __ocfs2_remove_inode_range(struct inode *inode, | |||
1425 | goto out; | 1273 | goto out; |
1426 | } | 1274 | } |
1427 | 1275 | ||
1428 | ret = ocfs2_remove_extent(inode, di_bh, cpos, len, handle, meta_ac, | 1276 | ret = ocfs2_remove_extent(inode, &et, cpos, len, handle, meta_ac, |
1429 | dealloc); | 1277 | dealloc); |
1430 | if (ret) { | 1278 | if (ret) { |
1431 | mlog_errno(ret); | 1279 | mlog_errno(ret); |
@@ -2040,7 +1888,7 @@ out_dio: | |||
2040 | */ | 1888 | */ |
2041 | if (old_size != i_size_read(inode) || | 1889 | if (old_size != i_size_read(inode) || |
2042 | old_clusters != OCFS2_I(inode)->ip_clusters) { | 1890 | old_clusters != OCFS2_I(inode)->ip_clusters) { |
2043 | ret = journal_force_commit(osb->journal->j_journal); | 1891 | ret = jbd2_journal_force_commit(osb->journal->j_journal); |
2044 | if (ret < 0) | 1892 | if (ret < 0) |
2045 | written = ret; | 1893 | written = ret; |
2046 | } | 1894 | } |
@@ -2227,6 +2075,10 @@ const struct inode_operations ocfs2_file_iops = { | |||
2227 | .setattr = ocfs2_setattr, | 2075 | .setattr = ocfs2_setattr, |
2228 | .getattr = ocfs2_getattr, | 2076 | .getattr = ocfs2_getattr, |
2229 | .permission = ocfs2_permission, | 2077 | .permission = ocfs2_permission, |
2078 | .setxattr = generic_setxattr, | ||
2079 | .getxattr = generic_getxattr, | ||
2080 | .listxattr = ocfs2_listxattr, | ||
2081 | .removexattr = generic_removexattr, | ||
2230 | .fallocate = ocfs2_fallocate, | 2082 | .fallocate = ocfs2_fallocate, |
2231 | .fiemap = ocfs2_fiemap, | 2083 | .fiemap = ocfs2_fiemap, |
2232 | }; | 2084 | }; |
@@ -2237,6 +2089,10 @@ const struct inode_operations ocfs2_special_file_iops = { | |||
2237 | .permission = ocfs2_permission, | 2089 | .permission = ocfs2_permission, |
2238 | }; | 2090 | }; |
2239 | 2091 | ||
2092 | /* | ||
2093 | * Other than ->lock, keep ocfs2_fops and ocfs2_dops in sync with | ||
2094 | * ocfs2_fops_no_plocks and ocfs2_dops_no_plocks! | ||
2095 | */ | ||
2240 | const struct file_operations ocfs2_fops = { | 2096 | const struct file_operations ocfs2_fops = { |
2241 | .llseek = generic_file_llseek, | 2097 | .llseek = generic_file_llseek, |
2242 | .read = do_sync_read, | 2098 | .read = do_sync_read, |
@@ -2251,6 +2107,7 @@ const struct file_operations ocfs2_fops = { | |||
2251 | #ifdef CONFIG_COMPAT | 2107 | #ifdef CONFIG_COMPAT |
2252 | .compat_ioctl = ocfs2_compat_ioctl, | 2108 | .compat_ioctl = ocfs2_compat_ioctl, |
2253 | #endif | 2109 | #endif |
2110 | .lock = ocfs2_lock, | ||
2254 | .flock = ocfs2_flock, | 2111 | .flock = ocfs2_flock, |
2255 | .splice_read = ocfs2_file_splice_read, | 2112 | .splice_read = ocfs2_file_splice_read, |
2256 | .splice_write = ocfs2_file_splice_write, | 2113 | .splice_write = ocfs2_file_splice_write, |
@@ -2267,5 +2124,51 @@ const struct file_operations ocfs2_dops = { | |||
2267 | #ifdef CONFIG_COMPAT | 2124 | #ifdef CONFIG_COMPAT |
2268 | .compat_ioctl = ocfs2_compat_ioctl, | 2125 | .compat_ioctl = ocfs2_compat_ioctl, |
2269 | #endif | 2126 | #endif |
2127 | .lock = ocfs2_lock, | ||
2128 | .flock = ocfs2_flock, | ||
2129 | }; | ||
2130 | |||
2131 | /* | ||
2132 | * POSIX-lockless variants of our file_operations. | ||
2133 | * | ||
2134 | * These will be used if the underlying cluster stack does not support | ||
2135 | * posix file locking, if the user passes the "localflocks" mount | ||
2136 | * option, or if we have a local-only fs. | ||
2137 | * | ||
2138 | * ocfs2_flock is in here because all stacks handle UNIX file locks, | ||
2139 | * so we still want it in the case of no stack support for | ||
2140 | * plocks. Internally, it will do the right thing when asked to ignore | ||
2141 | * the cluster. | ||
2142 | */ | ||
2143 | const struct file_operations ocfs2_fops_no_plocks = { | ||
2144 | .llseek = generic_file_llseek, | ||
2145 | .read = do_sync_read, | ||
2146 | .write = do_sync_write, | ||
2147 | .mmap = ocfs2_mmap, | ||
2148 | .fsync = ocfs2_sync_file, | ||
2149 | .release = ocfs2_file_release, | ||
2150 | .open = ocfs2_file_open, | ||
2151 | .aio_read = ocfs2_file_aio_read, | ||
2152 | .aio_write = ocfs2_file_aio_write, | ||
2153 | .unlocked_ioctl = ocfs2_ioctl, | ||
2154 | #ifdef CONFIG_COMPAT | ||
2155 | .compat_ioctl = ocfs2_compat_ioctl, | ||
2156 | #endif | ||
2157 | .flock = ocfs2_flock, | ||
2158 | .splice_read = ocfs2_file_splice_read, | ||
2159 | .splice_write = ocfs2_file_splice_write, | ||
2160 | }; | ||
2161 | |||
2162 | const struct file_operations ocfs2_dops_no_plocks = { | ||
2163 | .llseek = generic_file_llseek, | ||
2164 | .read = generic_read_dir, | ||
2165 | .readdir = ocfs2_readdir, | ||
2166 | .fsync = ocfs2_sync_file, | ||
2167 | .release = ocfs2_dir_release, | ||
2168 | .open = ocfs2_dir_open, | ||
2169 | .unlocked_ioctl = ocfs2_ioctl, | ||
2170 | #ifdef CONFIG_COMPAT | ||
2171 | .compat_ioctl = ocfs2_compat_ioctl, | ||
2172 | #endif | ||
2270 | .flock = ocfs2_flock, | 2173 | .flock = ocfs2_flock, |
2271 | }; | 2174 | }; |
diff --git a/fs/ocfs2/file.h b/fs/ocfs2/file.h index 1e27b4d017ea..e92382cbca5f 100644 --- a/fs/ocfs2/file.h +++ b/fs/ocfs2/file.h | |||
@@ -28,9 +28,12 @@ | |||
28 | 28 | ||
29 | extern const struct file_operations ocfs2_fops; | 29 | extern const struct file_operations ocfs2_fops; |
30 | extern const struct file_operations ocfs2_dops; | 30 | extern const struct file_operations ocfs2_dops; |
31 | extern const struct file_operations ocfs2_fops_no_plocks; | ||
32 | extern const struct file_operations ocfs2_dops_no_plocks; | ||
31 | extern const struct inode_operations ocfs2_file_iops; | 33 | extern const struct inode_operations ocfs2_file_iops; |
32 | extern const struct inode_operations ocfs2_special_file_iops; | 34 | extern const struct inode_operations ocfs2_special_file_iops; |
33 | struct ocfs2_alloc_context; | 35 | struct ocfs2_alloc_context; |
36 | enum ocfs2_alloc_restarted; | ||
34 | 37 | ||
35 | struct ocfs2_file_private { | 38 | struct ocfs2_file_private { |
36 | struct file *fp_file; | 39 | struct file *fp_file; |
@@ -38,27 +41,18 @@ struct ocfs2_file_private { | |||
38 | struct ocfs2_lock_res fp_flock; | 41 | struct ocfs2_lock_res fp_flock; |
39 | }; | 42 | }; |
40 | 43 | ||
41 | enum ocfs2_alloc_restarted { | 44 | int ocfs2_add_inode_data(struct ocfs2_super *osb, |
42 | RESTART_NONE = 0, | 45 | struct inode *inode, |
43 | RESTART_TRANS, | 46 | u32 *logical_offset, |
44 | RESTART_META | 47 | u32 clusters_to_add, |
45 | }; | 48 | int mark_unwritten, |
46 | int ocfs2_do_extend_allocation(struct ocfs2_super *osb, | 49 | struct buffer_head *fe_bh, |
47 | struct inode *inode, | 50 | handle_t *handle, |
48 | u32 *logical_offset, | 51 | struct ocfs2_alloc_context *data_ac, |
49 | u32 clusters_to_add, | 52 | struct ocfs2_alloc_context *meta_ac, |
50 | int mark_unwritten, | 53 | enum ocfs2_alloc_restarted *reason_ret); |
51 | struct buffer_head *fe_bh, | ||
52 | handle_t *handle, | ||
53 | struct ocfs2_alloc_context *data_ac, | ||
54 | struct ocfs2_alloc_context *meta_ac, | ||
55 | enum ocfs2_alloc_restarted *reason_ret); | ||
56 | int ocfs2_extend_no_holes(struct inode *inode, u64 new_i_size, | 54 | int ocfs2_extend_no_holes(struct inode *inode, u64 new_i_size, |
57 | u64 zero_to); | 55 | u64 zero_to); |
58 | int ocfs2_lock_allocators(struct inode *inode, struct ocfs2_dinode *di, | ||
59 | u32 clusters_to_add, u32 extents_to_split, | ||
60 | struct ocfs2_alloc_context **data_ac, | ||
61 | struct ocfs2_alloc_context **meta_ac); | ||
62 | int ocfs2_setattr(struct dentry *dentry, struct iattr *attr); | 56 | int ocfs2_setattr(struct dentry *dentry, struct iattr *attr); |
63 | int ocfs2_getattr(struct vfsmount *mnt, struct dentry *dentry, | 57 | int ocfs2_getattr(struct vfsmount *mnt, struct dentry *dentry, |
64 | struct kstat *stat); | 58 | struct kstat *stat); |
diff --git a/fs/ocfs2/inode.c b/fs/ocfs2/inode.c index 7e9e4c79aec7..4903688f72a9 100644 --- a/fs/ocfs2/inode.c +++ b/fs/ocfs2/inode.c | |||
@@ -49,6 +49,7 @@ | |||
49 | #include "symlink.h" | 49 | #include "symlink.h" |
50 | #include "sysfile.h" | 50 | #include "sysfile.h" |
51 | #include "uptodate.h" | 51 | #include "uptodate.h" |
52 | #include "xattr.h" | ||
52 | 53 | ||
53 | #include "buffer_head_io.h" | 54 | #include "buffer_head_io.h" |
54 | 55 | ||
@@ -219,6 +220,7 @@ int ocfs2_populate_inode(struct inode *inode, struct ocfs2_dinode *fe, | |||
219 | struct super_block *sb; | 220 | struct super_block *sb; |
220 | struct ocfs2_super *osb; | 221 | struct ocfs2_super *osb; |
221 | int status = -EINVAL; | 222 | int status = -EINVAL; |
223 | int use_plocks = 1; | ||
222 | 224 | ||
223 | mlog_entry("(0x%p, size:%llu)\n", inode, | 225 | mlog_entry("(0x%p, size:%llu)\n", inode, |
224 | (unsigned long long)le64_to_cpu(fe->i_size)); | 226 | (unsigned long long)le64_to_cpu(fe->i_size)); |
@@ -226,6 +228,10 @@ int ocfs2_populate_inode(struct inode *inode, struct ocfs2_dinode *fe, | |||
226 | sb = inode->i_sb; | 228 | sb = inode->i_sb; |
227 | osb = OCFS2_SB(sb); | 229 | osb = OCFS2_SB(sb); |
228 | 230 | ||
231 | if ((osb->s_mount_opt & OCFS2_MOUNT_LOCALFLOCKS) || | ||
232 | ocfs2_mount_local(osb) || !ocfs2_stack_supports_plocks()) | ||
233 | use_plocks = 0; | ||
234 | |||
229 | /* this means that read_inode cannot create a superblock inode | 235 | /* this means that read_inode cannot create a superblock inode |
230 | * today. change if needed. */ | 236 | * today. change if needed. */ |
231 | if (!OCFS2_IS_VALID_DINODE(fe) || | 237 | if (!OCFS2_IS_VALID_DINODE(fe) || |
@@ -295,13 +301,19 @@ int ocfs2_populate_inode(struct inode *inode, struct ocfs2_dinode *fe, | |||
295 | 301 | ||
296 | switch (inode->i_mode & S_IFMT) { | 302 | switch (inode->i_mode & S_IFMT) { |
297 | case S_IFREG: | 303 | case S_IFREG: |
298 | inode->i_fop = &ocfs2_fops; | 304 | if (use_plocks) |
305 | inode->i_fop = &ocfs2_fops; | ||
306 | else | ||
307 | inode->i_fop = &ocfs2_fops_no_plocks; | ||
299 | inode->i_op = &ocfs2_file_iops; | 308 | inode->i_op = &ocfs2_file_iops; |
300 | i_size_write(inode, le64_to_cpu(fe->i_size)); | 309 | i_size_write(inode, le64_to_cpu(fe->i_size)); |
301 | break; | 310 | break; |
302 | case S_IFDIR: | 311 | case S_IFDIR: |
303 | inode->i_op = &ocfs2_dir_iops; | 312 | inode->i_op = &ocfs2_dir_iops; |
304 | inode->i_fop = &ocfs2_dops; | 313 | if (use_plocks) |
314 | inode->i_fop = &ocfs2_dops; | ||
315 | else | ||
316 | inode->i_fop = &ocfs2_dops_no_plocks; | ||
305 | i_size_write(inode, le64_to_cpu(fe->i_size)); | 317 | i_size_write(inode, le64_to_cpu(fe->i_size)); |
306 | break; | 318 | break; |
307 | case S_IFLNK: | 319 | case S_IFLNK: |
@@ -448,8 +460,11 @@ static int ocfs2_read_locked_inode(struct inode *inode, | |||
448 | } | 460 | } |
449 | } | 461 | } |
450 | 462 | ||
451 | status = ocfs2_read_block(osb, args->fi_blkno, &bh, 0, | 463 | if (can_lock) |
452 | can_lock ? inode : NULL); | 464 | status = ocfs2_read_blocks(inode, args->fi_blkno, 1, &bh, |
465 | OCFS2_BH_IGNORE_CACHE); | ||
466 | else | ||
467 | status = ocfs2_read_blocks_sync(osb, args->fi_blkno, 1, &bh); | ||
453 | if (status < 0) { | 468 | if (status < 0) { |
454 | mlog_errno(status); | 469 | mlog_errno(status); |
455 | goto bail; | 470 | goto bail; |
@@ -522,6 +537,9 @@ static int ocfs2_truncate_for_delete(struct ocfs2_super *osb, | |||
522 | * data and fast symlinks. | 537 | * data and fast symlinks. |
523 | */ | 538 | */ |
524 | if (fe->i_clusters) { | 539 | if (fe->i_clusters) { |
540 | if (ocfs2_should_order_data(inode)) | ||
541 | ocfs2_begin_ordered_truncate(inode, 0); | ||
542 | |||
525 | handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS); | 543 | handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS); |
526 | if (IS_ERR(handle)) { | 544 | if (IS_ERR(handle)) { |
527 | status = PTR_ERR(handle); | 545 | status = PTR_ERR(handle); |
@@ -730,6 +748,13 @@ static int ocfs2_wipe_inode(struct inode *inode, | |||
730 | goto bail_unlock_dir; | 748 | goto bail_unlock_dir; |
731 | } | 749 | } |
732 | 750 | ||
751 | /*Free extended attribute resources associated with this inode.*/ | ||
752 | status = ocfs2_xattr_remove(inode, di_bh); | ||
753 | if (status < 0) { | ||
754 | mlog_errno(status); | ||
755 | goto bail_unlock_dir; | ||
756 | } | ||
757 | |||
733 | status = ocfs2_remove_inode(inode, di_bh, orphan_dir_inode, | 758 | status = ocfs2_remove_inode(inode, di_bh, orphan_dir_inode, |
734 | orphan_dir_bh); | 759 | orphan_dir_bh); |
735 | if (status < 0) | 760 | if (status < 0) |
@@ -1081,6 +1106,8 @@ void ocfs2_clear_inode(struct inode *inode) | |||
1081 | oi->ip_last_trans = 0; | 1106 | oi->ip_last_trans = 0; |
1082 | oi->ip_dir_start_lookup = 0; | 1107 | oi->ip_dir_start_lookup = 0; |
1083 | oi->ip_blkno = 0ULL; | 1108 | oi->ip_blkno = 0ULL; |
1109 | jbd2_journal_release_jbd_inode(OCFS2_SB(inode->i_sb)->journal->j_journal, | ||
1110 | &oi->ip_jinode); | ||
1084 | 1111 | ||
1085 | bail: | 1112 | bail: |
1086 | mlog_exit_void(); | 1113 | mlog_exit_void(); |
@@ -1107,58 +1134,6 @@ void ocfs2_drop_inode(struct inode *inode) | |||
1107 | } | 1134 | } |
1108 | 1135 | ||
1109 | /* | 1136 | /* |
1110 | * TODO: this should probably be merged into ocfs2_get_block | ||
1111 | * | ||
1112 | * However, you now need to pay attention to the cont_prepare_write() | ||
1113 | * stuff in ocfs2_get_block (that is, ocfs2_get_block pretty much | ||
1114 | * expects never to extend). | ||
1115 | */ | ||
1116 | struct buffer_head *ocfs2_bread(struct inode *inode, | ||
1117 | int block, int *err, int reada) | ||
1118 | { | ||
1119 | struct buffer_head *bh = NULL; | ||
1120 | int tmperr; | ||
1121 | u64 p_blkno; | ||
1122 | int readflags = OCFS2_BH_CACHED; | ||
1123 | |||
1124 | if (reada) | ||
1125 | readflags |= OCFS2_BH_READAHEAD; | ||
1126 | |||
1127 | if (((u64)block << inode->i_sb->s_blocksize_bits) >= | ||
1128 | i_size_read(inode)) { | ||
1129 | BUG_ON(!reada); | ||
1130 | return NULL; | ||
1131 | } | ||
1132 | |||
1133 | down_read(&OCFS2_I(inode)->ip_alloc_sem); | ||
1134 | tmperr = ocfs2_extent_map_get_blocks(inode, block, &p_blkno, NULL, | ||
1135 | NULL); | ||
1136 | up_read(&OCFS2_I(inode)->ip_alloc_sem); | ||
1137 | if (tmperr < 0) { | ||
1138 | mlog_errno(tmperr); | ||
1139 | goto fail; | ||
1140 | } | ||
1141 | |||
1142 | tmperr = ocfs2_read_block(OCFS2_SB(inode->i_sb), p_blkno, &bh, | ||
1143 | readflags, inode); | ||
1144 | if (tmperr < 0) | ||
1145 | goto fail; | ||
1146 | |||
1147 | tmperr = 0; | ||
1148 | |||
1149 | *err = 0; | ||
1150 | return bh; | ||
1151 | |||
1152 | fail: | ||
1153 | if (bh) { | ||
1154 | brelse(bh); | ||
1155 | bh = NULL; | ||
1156 | } | ||
1157 | *err = -EIO; | ||
1158 | return NULL; | ||
1159 | } | ||
1160 | |||
1161 | /* | ||
1162 | * This is called from our getattr. | 1137 | * This is called from our getattr. |
1163 | */ | 1138 | */ |
1164 | int ocfs2_inode_revalidate(struct dentry *dentry) | 1139 | int ocfs2_inode_revalidate(struct dentry *dentry) |
diff --git a/fs/ocfs2/inode.h b/fs/ocfs2/inode.h index 390a85596aa0..2f37af9bcc4a 100644 --- a/fs/ocfs2/inode.h +++ b/fs/ocfs2/inode.h | |||
@@ -40,6 +40,9 @@ struct ocfs2_inode_info | |||
40 | /* protects allocation changes on this inode. */ | 40 | /* protects allocation changes on this inode. */ |
41 | struct rw_semaphore ip_alloc_sem; | 41 | struct rw_semaphore ip_alloc_sem; |
42 | 42 | ||
43 | /* protects extended attribute changes on this inode */ | ||
44 | struct rw_semaphore ip_xattr_sem; | ||
45 | |||
43 | /* These fields are protected by ip_lock */ | 46 | /* These fields are protected by ip_lock */ |
44 | spinlock_t ip_lock; | 47 | spinlock_t ip_lock; |
45 | u32 ip_open_count; | 48 | u32 ip_open_count; |
@@ -68,6 +71,7 @@ struct ocfs2_inode_info | |||
68 | struct ocfs2_extent_map ip_extent_map; | 71 | struct ocfs2_extent_map ip_extent_map; |
69 | 72 | ||
70 | struct inode vfs_inode; | 73 | struct inode vfs_inode; |
74 | struct jbd2_inode ip_jinode; | ||
71 | }; | 75 | }; |
72 | 76 | ||
73 | /* | 77 | /* |
@@ -113,8 +117,6 @@ extern struct kmem_cache *ocfs2_inode_cache; | |||
113 | 117 | ||
114 | extern const struct address_space_operations ocfs2_aops; | 118 | extern const struct address_space_operations ocfs2_aops; |
115 | 119 | ||
116 | struct buffer_head *ocfs2_bread(struct inode *inode, int block, | ||
117 | int *err, int reada); | ||
118 | void ocfs2_clear_inode(struct inode *inode); | 120 | void ocfs2_clear_inode(struct inode *inode); |
119 | void ocfs2_delete_inode(struct inode *inode); | 121 | void ocfs2_delete_inode(struct inode *inode); |
120 | void ocfs2_drop_inode(struct inode *inode); | 122 | void ocfs2_drop_inode(struct inode *inode); |
diff --git a/fs/ocfs2/ioctl.c b/fs/ocfs2/ioctl.c index 7b142f0ce995..9fcd36dcc9a0 100644 --- a/fs/ocfs2/ioctl.c +++ b/fs/ocfs2/ioctl.c | |||
@@ -102,8 +102,7 @@ bail_unlock: | |||
102 | bail: | 102 | bail: |
103 | mutex_unlock(&inode->i_mutex); | 103 | mutex_unlock(&inode->i_mutex); |
104 | 104 | ||
105 | if (bh) | 105 | brelse(bh); |
106 | brelse(bh); | ||
107 | 106 | ||
108 | mlog_exit(status); | 107 | mlog_exit(status); |
109 | return status; | 108 | return status; |
diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c index c47bc2a809c2..81e40677eecb 100644 --- a/fs/ocfs2/journal.c +++ b/fs/ocfs2/journal.c | |||
@@ -215,9 +215,9 @@ static int ocfs2_commit_cache(struct ocfs2_super *osb) | |||
215 | goto finally; | 215 | goto finally; |
216 | } | 216 | } |
217 | 217 | ||
218 | journal_lock_updates(journal->j_journal); | 218 | jbd2_journal_lock_updates(journal->j_journal); |
219 | status = journal_flush(journal->j_journal); | 219 | status = jbd2_journal_flush(journal->j_journal); |
220 | journal_unlock_updates(journal->j_journal); | 220 | jbd2_journal_unlock_updates(journal->j_journal); |
221 | if (status < 0) { | 221 | if (status < 0) { |
222 | up_write(&journal->j_trans_barrier); | 222 | up_write(&journal->j_trans_barrier); |
223 | mlog_errno(status); | 223 | mlog_errno(status); |
@@ -264,7 +264,7 @@ handle_t *ocfs2_start_trans(struct ocfs2_super *osb, int max_buffs) | |||
264 | 264 | ||
265 | down_read(&osb->journal->j_trans_barrier); | 265 | down_read(&osb->journal->j_trans_barrier); |
266 | 266 | ||
267 | handle = journal_start(journal, max_buffs); | 267 | handle = jbd2_journal_start(journal, max_buffs); |
268 | if (IS_ERR(handle)) { | 268 | if (IS_ERR(handle)) { |
269 | up_read(&osb->journal->j_trans_barrier); | 269 | up_read(&osb->journal->j_trans_barrier); |
270 | 270 | ||
@@ -290,7 +290,7 @@ int ocfs2_commit_trans(struct ocfs2_super *osb, | |||
290 | 290 | ||
291 | BUG_ON(!handle); | 291 | BUG_ON(!handle); |
292 | 292 | ||
293 | ret = journal_stop(handle); | 293 | ret = jbd2_journal_stop(handle); |
294 | if (ret < 0) | 294 | if (ret < 0) |
295 | mlog_errno(ret); | 295 | mlog_errno(ret); |
296 | 296 | ||
@@ -304,7 +304,7 @@ int ocfs2_commit_trans(struct ocfs2_super *osb, | |||
304 | * transaction. extend_trans will either extend the current handle by | 304 | * transaction. extend_trans will either extend the current handle by |
305 | * nblocks, or commit it and start a new one with nblocks credits. | 305 | * nblocks, or commit it and start a new one with nblocks credits. |
306 | * | 306 | * |
307 | * This might call journal_restart() which will commit dirty buffers | 307 | * This might call jbd2_journal_restart() which will commit dirty buffers |
308 | * and then restart the transaction. Before calling | 308 | * and then restart the transaction. Before calling |
309 | * ocfs2_extend_trans(), any changed blocks should have been | 309 | * ocfs2_extend_trans(), any changed blocks should have been |
310 | * dirtied. After calling it, all blocks which need to be changed must | 310 | * dirtied. After calling it, all blocks which need to be changed must |
@@ -332,7 +332,7 @@ int ocfs2_extend_trans(handle_t *handle, int nblocks) | |||
332 | #ifdef CONFIG_OCFS2_DEBUG_FS | 332 | #ifdef CONFIG_OCFS2_DEBUG_FS |
333 | status = 1; | 333 | status = 1; |
334 | #else | 334 | #else |
335 | status = journal_extend(handle, nblocks); | 335 | status = jbd2_journal_extend(handle, nblocks); |
336 | if (status < 0) { | 336 | if (status < 0) { |
337 | mlog_errno(status); | 337 | mlog_errno(status); |
338 | goto bail; | 338 | goto bail; |
@@ -340,8 +340,10 @@ int ocfs2_extend_trans(handle_t *handle, int nblocks) | |||
340 | #endif | 340 | #endif |
341 | 341 | ||
342 | if (status > 0) { | 342 | if (status > 0) { |
343 | mlog(0, "journal_extend failed, trying journal_restart\n"); | 343 | mlog(0, |
344 | status = journal_restart(handle, nblocks); | 344 | "jbd2_journal_extend failed, trying " |
345 | "jbd2_journal_restart\n"); | ||
346 | status = jbd2_journal_restart(handle, nblocks); | ||
345 | if (status < 0) { | 347 | if (status < 0) { |
346 | mlog_errno(status); | 348 | mlog_errno(status); |
347 | goto bail; | 349 | goto bail; |
@@ -393,11 +395,11 @@ int ocfs2_journal_access(handle_t *handle, | |||
393 | switch (type) { | 395 | switch (type) { |
394 | case OCFS2_JOURNAL_ACCESS_CREATE: | 396 | case OCFS2_JOURNAL_ACCESS_CREATE: |
395 | case OCFS2_JOURNAL_ACCESS_WRITE: | 397 | case OCFS2_JOURNAL_ACCESS_WRITE: |
396 | status = journal_get_write_access(handle, bh); | 398 | status = jbd2_journal_get_write_access(handle, bh); |
397 | break; | 399 | break; |
398 | 400 | ||
399 | case OCFS2_JOURNAL_ACCESS_UNDO: | 401 | case OCFS2_JOURNAL_ACCESS_UNDO: |
400 | status = journal_get_undo_access(handle, bh); | 402 | status = jbd2_journal_get_undo_access(handle, bh); |
401 | break; | 403 | break; |
402 | 404 | ||
403 | default: | 405 | default: |
@@ -422,7 +424,7 @@ int ocfs2_journal_dirty(handle_t *handle, | |||
422 | mlog_entry("(bh->b_blocknr=%llu)\n", | 424 | mlog_entry("(bh->b_blocknr=%llu)\n", |
423 | (unsigned long long)bh->b_blocknr); | 425 | (unsigned long long)bh->b_blocknr); |
424 | 426 | ||
425 | status = journal_dirty_metadata(handle, bh); | 427 | status = jbd2_journal_dirty_metadata(handle, bh); |
426 | if (status < 0) | 428 | if (status < 0) |
427 | mlog(ML_ERROR, "Could not dirty metadata buffer. " | 429 | mlog(ML_ERROR, "Could not dirty metadata buffer. " |
428 | "(bh->b_blocknr=%llu)\n", | 430 | "(bh->b_blocknr=%llu)\n", |
@@ -432,6 +434,7 @@ int ocfs2_journal_dirty(handle_t *handle, | |||
432 | return status; | 434 | return status; |
433 | } | 435 | } |
434 | 436 | ||
437 | #ifdef CONFIG_OCFS2_COMPAT_JBD | ||
435 | int ocfs2_journal_dirty_data(handle_t *handle, | 438 | int ocfs2_journal_dirty_data(handle_t *handle, |
436 | struct buffer_head *bh) | 439 | struct buffer_head *bh) |
437 | { | 440 | { |
@@ -443,8 +446,9 @@ int ocfs2_journal_dirty_data(handle_t *handle, | |||
443 | 446 | ||
444 | return err; | 447 | return err; |
445 | } | 448 | } |
449 | #endif | ||
446 | 450 | ||
447 | #define OCFS2_DEFAULT_COMMIT_INTERVAL (HZ * JBD_DEFAULT_MAX_COMMIT_AGE) | 451 | #define OCFS2_DEFAULT_COMMIT_INTERVAL (HZ * JBD2_DEFAULT_MAX_COMMIT_AGE) |
448 | 452 | ||
449 | void ocfs2_set_journal_params(struct ocfs2_super *osb) | 453 | void ocfs2_set_journal_params(struct ocfs2_super *osb) |
450 | { | 454 | { |
@@ -457,9 +461,9 @@ void ocfs2_set_journal_params(struct ocfs2_super *osb) | |||
457 | spin_lock(&journal->j_state_lock); | 461 | spin_lock(&journal->j_state_lock); |
458 | journal->j_commit_interval = commit_interval; | 462 | journal->j_commit_interval = commit_interval; |
459 | if (osb->s_mount_opt & OCFS2_MOUNT_BARRIER) | 463 | if (osb->s_mount_opt & OCFS2_MOUNT_BARRIER) |
460 | journal->j_flags |= JFS_BARRIER; | 464 | journal->j_flags |= JBD2_BARRIER; |
461 | else | 465 | else |
462 | journal->j_flags &= ~JFS_BARRIER; | 466 | journal->j_flags &= ~JBD2_BARRIER; |
463 | spin_unlock(&journal->j_state_lock); | 467 | spin_unlock(&journal->j_state_lock); |
464 | } | 468 | } |
465 | 469 | ||
@@ -524,14 +528,14 @@ int ocfs2_journal_init(struct ocfs2_journal *journal, int *dirty) | |||
524 | mlog(0, "inode->ip_clusters = %u\n", OCFS2_I(inode)->ip_clusters); | 528 | mlog(0, "inode->ip_clusters = %u\n", OCFS2_I(inode)->ip_clusters); |
525 | 529 | ||
526 | /* call the kernels journal init function now */ | 530 | /* call the kernels journal init function now */ |
527 | j_journal = journal_init_inode(inode); | 531 | j_journal = jbd2_journal_init_inode(inode); |
528 | if (j_journal == NULL) { | 532 | if (j_journal == NULL) { |
529 | mlog(ML_ERROR, "Linux journal layer error\n"); | 533 | mlog(ML_ERROR, "Linux journal layer error\n"); |
530 | status = -EINVAL; | 534 | status = -EINVAL; |
531 | goto done; | 535 | goto done; |
532 | } | 536 | } |
533 | 537 | ||
534 | mlog(0, "Returned from journal_init_inode\n"); | 538 | mlog(0, "Returned from jbd2_journal_init_inode\n"); |
535 | mlog(0, "j_journal->j_maxlen = %u\n", j_journal->j_maxlen); | 539 | mlog(0, "j_journal->j_maxlen = %u\n", j_journal->j_maxlen); |
536 | 540 | ||
537 | *dirty = (le32_to_cpu(di->id1.journal1.ij_flags) & | 541 | *dirty = (le32_to_cpu(di->id1.journal1.ij_flags) & |
@@ -550,8 +554,7 @@ done: | |||
550 | if (status < 0) { | 554 | if (status < 0) { |
551 | if (inode_lock) | 555 | if (inode_lock) |
552 | ocfs2_inode_unlock(inode, 1); | 556 | ocfs2_inode_unlock(inode, 1); |
553 | if (bh != NULL) | 557 | brelse(bh); |
554 | brelse(bh); | ||
555 | if (inode) { | 558 | if (inode) { |
556 | OCFS2_I(inode)->ip_open_count--; | 559 | OCFS2_I(inode)->ip_open_count--; |
557 | iput(inode); | 560 | iput(inode); |
@@ -639,7 +642,7 @@ void ocfs2_journal_shutdown(struct ocfs2_super *osb) | |||
639 | if (journal->j_state != OCFS2_JOURNAL_LOADED) | 642 | if (journal->j_state != OCFS2_JOURNAL_LOADED) |
640 | goto done; | 643 | goto done; |
641 | 644 | ||
642 | /* need to inc inode use count as journal_destroy will iput. */ | 645 | /* need to inc inode use count - jbd2_journal_destroy will iput. */ |
643 | if (!igrab(inode)) | 646 | if (!igrab(inode)) |
644 | BUG(); | 647 | BUG(); |
645 | 648 | ||
@@ -668,9 +671,9 @@ void ocfs2_journal_shutdown(struct ocfs2_super *osb) | |||
668 | BUG_ON(atomic_read(&(osb->journal->j_num_trans)) != 0); | 671 | BUG_ON(atomic_read(&(osb->journal->j_num_trans)) != 0); |
669 | 672 | ||
670 | if (ocfs2_mount_local(osb)) { | 673 | if (ocfs2_mount_local(osb)) { |
671 | journal_lock_updates(journal->j_journal); | 674 | jbd2_journal_lock_updates(journal->j_journal); |
672 | status = journal_flush(journal->j_journal); | 675 | status = jbd2_journal_flush(journal->j_journal); |
673 | journal_unlock_updates(journal->j_journal); | 676 | jbd2_journal_unlock_updates(journal->j_journal); |
674 | if (status < 0) | 677 | if (status < 0) |
675 | mlog_errno(status); | 678 | mlog_errno(status); |
676 | } | 679 | } |
@@ -686,7 +689,7 @@ void ocfs2_journal_shutdown(struct ocfs2_super *osb) | |||
686 | } | 689 | } |
687 | 690 | ||
688 | /* Shutdown the kernel journal system */ | 691 | /* Shutdown the kernel journal system */ |
689 | journal_destroy(journal->j_journal); | 692 | jbd2_journal_destroy(journal->j_journal); |
690 | 693 | ||
691 | OCFS2_I(inode)->ip_open_count--; | 694 | OCFS2_I(inode)->ip_open_count--; |
692 | 695 | ||
@@ -711,15 +714,15 @@ static void ocfs2_clear_journal_error(struct super_block *sb, | |||
711 | { | 714 | { |
712 | int olderr; | 715 | int olderr; |
713 | 716 | ||
714 | olderr = journal_errno(journal); | 717 | olderr = jbd2_journal_errno(journal); |
715 | if (olderr) { | 718 | if (olderr) { |
716 | mlog(ML_ERROR, "File system error %d recorded in " | 719 | mlog(ML_ERROR, "File system error %d recorded in " |
717 | "journal %u.\n", olderr, slot); | 720 | "journal %u.\n", olderr, slot); |
718 | mlog(ML_ERROR, "File system on device %s needs checking.\n", | 721 | mlog(ML_ERROR, "File system on device %s needs checking.\n", |
719 | sb->s_id); | 722 | sb->s_id); |
720 | 723 | ||
721 | journal_ack_err(journal); | 724 | jbd2_journal_ack_err(journal); |
722 | journal_clear_err(journal); | 725 | jbd2_journal_clear_err(journal); |
723 | } | 726 | } |
724 | } | 727 | } |
725 | 728 | ||
@@ -734,7 +737,7 @@ int ocfs2_journal_load(struct ocfs2_journal *journal, int local, int replayed) | |||
734 | 737 | ||
735 | osb = journal->j_osb; | 738 | osb = journal->j_osb; |
736 | 739 | ||
737 | status = journal_load(journal->j_journal); | 740 | status = jbd2_journal_load(journal->j_journal); |
738 | if (status < 0) { | 741 | if (status < 0) { |
739 | mlog(ML_ERROR, "Failed to load journal!\n"); | 742 | mlog(ML_ERROR, "Failed to load journal!\n"); |
740 | goto done; | 743 | goto done; |
@@ -778,7 +781,7 @@ int ocfs2_journal_wipe(struct ocfs2_journal *journal, int full) | |||
778 | 781 | ||
779 | BUG_ON(!journal); | 782 | BUG_ON(!journal); |
780 | 783 | ||
781 | status = journal_wipe(journal->j_journal, full); | 784 | status = jbd2_journal_wipe(journal->j_journal, full); |
782 | if (status < 0) { | 785 | if (status < 0) { |
783 | mlog_errno(status); | 786 | mlog_errno(status); |
784 | goto bail; | 787 | goto bail; |
@@ -847,9 +850,8 @@ static int ocfs2_force_read_journal(struct inode *inode) | |||
847 | 850 | ||
848 | /* We are reading journal data which should not | 851 | /* We are reading journal data which should not |
849 | * be put in the uptodate cache */ | 852 | * be put in the uptodate cache */ |
850 | status = ocfs2_read_blocks(OCFS2_SB(inode->i_sb), | 853 | status = ocfs2_read_blocks_sync(OCFS2_SB(inode->i_sb), |
851 | p_blkno, p_blocks, bhs, 0, | 854 | p_blkno, p_blocks, bhs); |
852 | NULL); | ||
853 | if (status < 0) { | 855 | if (status < 0) { |
854 | mlog_errno(status); | 856 | mlog_errno(status); |
855 | goto bail; | 857 | goto bail; |
@@ -865,8 +867,7 @@ static int ocfs2_force_read_journal(struct inode *inode) | |||
865 | 867 | ||
866 | bail: | 868 | bail: |
867 | for(i = 0; i < CONCURRENT_JOURNAL_FILL; i++) | 869 | for(i = 0; i < CONCURRENT_JOURNAL_FILL; i++) |
868 | if (bhs[i]) | 870 | brelse(bhs[i]); |
869 | brelse(bhs[i]); | ||
870 | mlog_exit(status); | 871 | mlog_exit(status); |
871 | return status; | 872 | return status; |
872 | } | 873 | } |
@@ -1133,7 +1134,8 @@ static int ocfs2_read_journal_inode(struct ocfs2_super *osb, | |||
1133 | } | 1134 | } |
1134 | SET_INODE_JOURNAL(inode); | 1135 | SET_INODE_JOURNAL(inode); |
1135 | 1136 | ||
1136 | status = ocfs2_read_block(osb, OCFS2_I(inode)->ip_blkno, bh, 0, inode); | 1137 | status = ocfs2_read_blocks(inode, OCFS2_I(inode)->ip_blkno, 1, bh, |
1138 | OCFS2_BH_IGNORE_CACHE); | ||
1137 | if (status < 0) { | 1139 | if (status < 0) { |
1138 | mlog_errno(status); | 1140 | mlog_errno(status); |
1139 | goto bail; | 1141 | goto bail; |
@@ -1229,19 +1231,19 @@ static int ocfs2_replay_journal(struct ocfs2_super *osb, | |||
1229 | } | 1231 | } |
1230 | 1232 | ||
1231 | mlog(0, "calling journal_init_inode\n"); | 1233 | mlog(0, "calling journal_init_inode\n"); |
1232 | journal = journal_init_inode(inode); | 1234 | journal = jbd2_journal_init_inode(inode); |
1233 | if (journal == NULL) { | 1235 | if (journal == NULL) { |
1234 | mlog(ML_ERROR, "Linux journal layer error\n"); | 1236 | mlog(ML_ERROR, "Linux journal layer error\n"); |
1235 | status = -EIO; | 1237 | status = -EIO; |
1236 | goto done; | 1238 | goto done; |
1237 | } | 1239 | } |
1238 | 1240 | ||
1239 | status = journal_load(journal); | 1241 | status = jbd2_journal_load(journal); |
1240 | if (status < 0) { | 1242 | if (status < 0) { |
1241 | mlog_errno(status); | 1243 | mlog_errno(status); |
1242 | if (!igrab(inode)) | 1244 | if (!igrab(inode)) |
1243 | BUG(); | 1245 | BUG(); |
1244 | journal_destroy(journal); | 1246 | jbd2_journal_destroy(journal); |
1245 | goto done; | 1247 | goto done; |
1246 | } | 1248 | } |
1247 | 1249 | ||
@@ -1249,9 +1251,9 @@ static int ocfs2_replay_journal(struct ocfs2_super *osb, | |||
1249 | 1251 | ||
1250 | /* wipe the journal */ | 1252 | /* wipe the journal */ |
1251 | mlog(0, "flushing the journal.\n"); | 1253 | mlog(0, "flushing the journal.\n"); |
1252 | journal_lock_updates(journal); | 1254 | jbd2_journal_lock_updates(journal); |
1253 | status = journal_flush(journal); | 1255 | status = jbd2_journal_flush(journal); |
1254 | journal_unlock_updates(journal); | 1256 | jbd2_journal_unlock_updates(journal); |
1255 | if (status < 0) | 1257 | if (status < 0) |
1256 | mlog_errno(status); | 1258 | mlog_errno(status); |
1257 | 1259 | ||
@@ -1272,7 +1274,7 @@ static int ocfs2_replay_journal(struct ocfs2_super *osb, | |||
1272 | if (!igrab(inode)) | 1274 | if (!igrab(inode)) |
1273 | BUG(); | 1275 | BUG(); |
1274 | 1276 | ||
1275 | journal_destroy(journal); | 1277 | jbd2_journal_destroy(journal); |
1276 | 1278 | ||
1277 | done: | 1279 | done: |
1278 | /* drop the lock on this nodes journal */ | 1280 | /* drop the lock on this nodes journal */ |
@@ -1282,8 +1284,7 @@ done: | |||
1282 | if (inode) | 1284 | if (inode) |
1283 | iput(inode); | 1285 | iput(inode); |
1284 | 1286 | ||
1285 | if (bh) | 1287 | brelse(bh); |
1286 | brelse(bh); | ||
1287 | 1288 | ||
1288 | mlog_exit(status); | 1289 | mlog_exit(status); |
1289 | return status; | 1290 | return status; |
diff --git a/fs/ocfs2/journal.h b/fs/ocfs2/journal.h index 2178ebffa05f..d4d14e9a3cea 100644 --- a/fs/ocfs2/journal.h +++ b/fs/ocfs2/journal.h | |||
@@ -27,7 +27,12 @@ | |||
27 | #define OCFS2_JOURNAL_H | 27 | #define OCFS2_JOURNAL_H |
28 | 28 | ||
29 | #include <linux/fs.h> | 29 | #include <linux/fs.h> |
30 | #include <linux/jbd.h> | 30 | #ifndef CONFIG_OCFS2_COMPAT_JBD |
31 | # include <linux/jbd2.h> | ||
32 | #else | ||
33 | # include <linux/jbd.h> | ||
34 | # include "ocfs2_jbd_compat.h" | ||
35 | #endif | ||
31 | 36 | ||
32 | enum ocfs2_journal_state { | 37 | enum ocfs2_journal_state { |
33 | OCFS2_JOURNAL_FREE = 0, | 38 | OCFS2_JOURNAL_FREE = 0, |
@@ -215,8 +220,8 @@ static inline void ocfs2_checkpoint_inode(struct inode *inode) | |||
215 | * buffer. Will have to call ocfs2_journal_dirty once | 220 | * buffer. Will have to call ocfs2_journal_dirty once |
216 | * we've actually dirtied it. Type is one of . or . | 221 | * we've actually dirtied it. Type is one of . or . |
217 | * ocfs2_journal_dirty - Mark a journalled buffer as having dirty data. | 222 | * ocfs2_journal_dirty - Mark a journalled buffer as having dirty data. |
218 | * ocfs2_journal_dirty_data - Indicate that a data buffer should go out before | 223 | * ocfs2_jbd2_file_inode - Mark an inode so that its data goes out before |
219 | * the current handle commits. | 224 | * the current handle commits. |
220 | */ | 225 | */ |
221 | 226 | ||
222 | /* You must always start_trans with a number of buffs > 0, but it's | 227 | /* You must always start_trans with a number of buffs > 0, but it's |
@@ -268,8 +273,10 @@ int ocfs2_journal_access(handle_t *handle, | |||
268 | */ | 273 | */ |
269 | int ocfs2_journal_dirty(handle_t *handle, | 274 | int ocfs2_journal_dirty(handle_t *handle, |
270 | struct buffer_head *bh); | 275 | struct buffer_head *bh); |
276 | #ifdef CONFIG_OCFS2_COMPAT_JBD | ||
271 | int ocfs2_journal_dirty_data(handle_t *handle, | 277 | int ocfs2_journal_dirty_data(handle_t *handle, |
272 | struct buffer_head *bh); | 278 | struct buffer_head *bh); |
279 | #endif | ||
273 | 280 | ||
274 | /* | 281 | /* |
275 | * Credit Macros: | 282 | * Credit Macros: |
@@ -283,6 +290,9 @@ int ocfs2_journal_dirty_data(handle_t *handle, | |||
283 | /* simple file updates like chmod, etc. */ | 290 | /* simple file updates like chmod, etc. */ |
284 | #define OCFS2_INODE_UPDATE_CREDITS 1 | 291 | #define OCFS2_INODE_UPDATE_CREDITS 1 |
285 | 292 | ||
293 | /* extended attribute block update */ | ||
294 | #define OCFS2_XATTR_BLOCK_UPDATE_CREDITS 1 | ||
295 | |||
286 | /* group extend. inode update and last group update. */ | 296 | /* group extend. inode update and last group update. */ |
287 | #define OCFS2_GROUP_EXTEND_CREDITS (OCFS2_INODE_UPDATE_CREDITS + 1) | 297 | #define OCFS2_GROUP_EXTEND_CREDITS (OCFS2_INODE_UPDATE_CREDITS + 1) |
288 | 298 | ||
@@ -340,11 +350,23 @@ int ocfs2_journal_dirty_data(handle_t *handle, | |||
340 | #define OCFS2_RENAME_CREDITS (3 * OCFS2_INODE_UPDATE_CREDITS + 3 \ | 350 | #define OCFS2_RENAME_CREDITS (3 * OCFS2_INODE_UPDATE_CREDITS + 3 \ |
341 | + OCFS2_UNLINK_CREDITS) | 351 | + OCFS2_UNLINK_CREDITS) |
342 | 352 | ||
353 | /* global bitmap dinode, group desc., relinked group, | ||
354 | * suballocator dinode, group desc., relinked group, | ||
355 | * dinode, xattr block */ | ||
356 | #define OCFS2_XATTR_BLOCK_CREATE_CREDITS (OCFS2_SUBALLOC_ALLOC * 2 + \ | ||
357 | + OCFS2_INODE_UPDATE_CREDITS \ | ||
358 | + OCFS2_XATTR_BLOCK_UPDATE_CREDITS) | ||
359 | |||
360 | /* | ||
361 | * Please note that the caller must make sure that root_el is the root | ||
362 | * of extent tree. So for an inode, it should be &fe->id2.i_list. Otherwise | ||
363 | * the result may be wrong. | ||
364 | */ | ||
343 | static inline int ocfs2_calc_extend_credits(struct super_block *sb, | 365 | static inline int ocfs2_calc_extend_credits(struct super_block *sb, |
344 | struct ocfs2_dinode *fe, | 366 | struct ocfs2_extent_list *root_el, |
345 | u32 bits_wanted) | 367 | u32 bits_wanted) |
346 | { | 368 | { |
347 | int bitmap_blocks, sysfile_bitmap_blocks, dinode_blocks; | 369 | int bitmap_blocks, sysfile_bitmap_blocks, extent_blocks; |
348 | 370 | ||
349 | /* bitmap dinode, group desc. + relinked group. */ | 371 | /* bitmap dinode, group desc. + relinked group. */ |
350 | bitmap_blocks = OCFS2_SUBALLOC_ALLOC; | 372 | bitmap_blocks = OCFS2_SUBALLOC_ALLOC; |
@@ -355,16 +377,16 @@ static inline int ocfs2_calc_extend_credits(struct super_block *sb, | |||
355 | * however many metadata chunks needed * a remaining suballoc | 377 | * however many metadata chunks needed * a remaining suballoc |
356 | * alloc. */ | 378 | * alloc. */ |
357 | sysfile_bitmap_blocks = 1 + | 379 | sysfile_bitmap_blocks = 1 + |
358 | (OCFS2_SUBALLOC_ALLOC - 1) * ocfs2_extend_meta_needed(fe); | 380 | (OCFS2_SUBALLOC_ALLOC - 1) * ocfs2_extend_meta_needed(root_el); |
359 | 381 | ||
360 | /* this does not include *new* metadata blocks, which are | 382 | /* this does not include *new* metadata blocks, which are |
361 | * accounted for in sysfile_bitmap_blocks. fe + | 383 | * accounted for in sysfile_bitmap_blocks. root_el + |
362 | * prev. last_eb_blk + blocks along edge of tree. | 384 | * prev. last_eb_blk + blocks along edge of tree. |
363 | * calc_symlink_credits passes because we just need 1 | 385 | * calc_symlink_credits passes because we just need 1 |
364 | * credit for the dinode there. */ | 386 | * credit for the dinode there. */ |
365 | dinode_blocks = 1 + 1 + le16_to_cpu(fe->id2.i_list.l_tree_depth); | 387 | extent_blocks = 1 + 1 + le16_to_cpu(root_el->l_tree_depth); |
366 | 388 | ||
367 | return bitmap_blocks + sysfile_bitmap_blocks + dinode_blocks; | 389 | return bitmap_blocks + sysfile_bitmap_blocks + extent_blocks; |
368 | } | 390 | } |
369 | 391 | ||
370 | static inline int ocfs2_calc_symlink_credits(struct super_block *sb) | 392 | static inline int ocfs2_calc_symlink_credits(struct super_block *sb) |
@@ -415,4 +437,16 @@ static inline int ocfs2_calc_tree_trunc_credits(struct super_block *sb, | |||
415 | return credits; | 437 | return credits; |
416 | } | 438 | } |
417 | 439 | ||
440 | static inline int ocfs2_jbd2_file_inode(handle_t *handle, struct inode *inode) | ||
441 | { | ||
442 | return jbd2_journal_file_inode(handle, &OCFS2_I(inode)->ip_jinode); | ||
443 | } | ||
444 | |||
445 | static inline int ocfs2_begin_ordered_truncate(struct inode *inode, | ||
446 | loff_t new_size) | ||
447 | { | ||
448 | return jbd2_journal_begin_ordered_truncate(&OCFS2_I(inode)->ip_jinode, | ||
449 | new_size); | ||
450 | } | ||
451 | |||
418 | #endif /* OCFS2_JOURNAL_H */ | 452 | #endif /* OCFS2_JOURNAL_H */ |
diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c index 28e492e4ec88..687b28713c32 100644 --- a/fs/ocfs2/localalloc.c +++ b/fs/ocfs2/localalloc.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <linux/slab.h> | 28 | #include <linux/slab.h> |
29 | #include <linux/highmem.h> | 29 | #include <linux/highmem.h> |
30 | #include <linux/bitops.h> | 30 | #include <linux/bitops.h> |
31 | #include <linux/debugfs.h> | ||
31 | 32 | ||
32 | #define MLOG_MASK_PREFIX ML_DISK_ALLOC | 33 | #define MLOG_MASK_PREFIX ML_DISK_ALLOC |
33 | #include <cluster/masklog.h> | 34 | #include <cluster/masklog.h> |
@@ -47,8 +48,6 @@ | |||
47 | 48 | ||
48 | #define OCFS2_LOCAL_ALLOC(dinode) (&((dinode)->id2.i_lab)) | 49 | #define OCFS2_LOCAL_ALLOC(dinode) (&((dinode)->id2.i_lab)) |
49 | 50 | ||
50 | static inline int ocfs2_local_alloc_window_bits(struct ocfs2_super *osb); | ||
51 | |||
52 | static u32 ocfs2_local_alloc_count_bits(struct ocfs2_dinode *alloc); | 51 | static u32 ocfs2_local_alloc_count_bits(struct ocfs2_dinode *alloc); |
53 | 52 | ||
54 | static int ocfs2_local_alloc_find_clear_bits(struct ocfs2_super *osb, | 53 | static int ocfs2_local_alloc_find_clear_bits(struct ocfs2_super *osb, |
@@ -75,24 +74,129 @@ static int ocfs2_local_alloc_new_window(struct ocfs2_super *osb, | |||
75 | static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb, | 74 | static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb, |
76 | struct inode *local_alloc_inode); | 75 | struct inode *local_alloc_inode); |
77 | 76 | ||
78 | static inline int ocfs2_local_alloc_window_bits(struct ocfs2_super *osb) | 77 | #ifdef CONFIG_OCFS2_FS_STATS |
78 | |||
79 | static int ocfs2_la_debug_open(struct inode *inode, struct file *file) | ||
80 | { | ||
81 | file->private_data = inode->i_private; | ||
82 | return 0; | ||
83 | } | ||
84 | |||
85 | #define LA_DEBUG_BUF_SZ PAGE_CACHE_SIZE | ||
86 | #define LA_DEBUG_VER 1 | ||
87 | static ssize_t ocfs2_la_debug_read(struct file *file, char __user *userbuf, | ||
88 | size_t count, loff_t *ppos) | ||
89 | { | ||
90 | static DEFINE_MUTEX(la_debug_mutex); | ||
91 | struct ocfs2_super *osb = file->private_data; | ||
92 | int written, ret; | ||
93 | char *buf = osb->local_alloc_debug_buf; | ||
94 | |||
95 | mutex_lock(&la_debug_mutex); | ||
96 | memset(buf, 0, LA_DEBUG_BUF_SZ); | ||
97 | |||
98 | written = snprintf(buf, LA_DEBUG_BUF_SZ, | ||
99 | "0x%x\t0x%llx\t%u\t%u\t0x%x\n", | ||
100 | LA_DEBUG_VER, | ||
101 | (unsigned long long)osb->la_last_gd, | ||
102 | osb->local_alloc_default_bits, | ||
103 | osb->local_alloc_bits, osb->local_alloc_state); | ||
104 | |||
105 | ret = simple_read_from_buffer(userbuf, count, ppos, buf, written); | ||
106 | |||
107 | mutex_unlock(&la_debug_mutex); | ||
108 | return ret; | ||
109 | } | ||
110 | |||
111 | static const struct file_operations ocfs2_la_debug_fops = { | ||
112 | .open = ocfs2_la_debug_open, | ||
113 | .read = ocfs2_la_debug_read, | ||
114 | }; | ||
115 | |||
116 | static void ocfs2_init_la_debug(struct ocfs2_super *osb) | ||
117 | { | ||
118 | osb->local_alloc_debug_buf = kmalloc(LA_DEBUG_BUF_SZ, GFP_NOFS); | ||
119 | if (!osb->local_alloc_debug_buf) | ||
120 | return; | ||
121 | |||
122 | osb->local_alloc_debug = debugfs_create_file("local_alloc_stats", | ||
123 | S_IFREG|S_IRUSR, | ||
124 | osb->osb_debug_root, | ||
125 | osb, | ||
126 | &ocfs2_la_debug_fops); | ||
127 | if (!osb->local_alloc_debug) { | ||
128 | kfree(osb->local_alloc_debug_buf); | ||
129 | osb->local_alloc_debug_buf = NULL; | ||
130 | } | ||
131 | } | ||
132 | |||
133 | static void ocfs2_shutdown_la_debug(struct ocfs2_super *osb) | ||
134 | { | ||
135 | if (osb->local_alloc_debug) | ||
136 | debugfs_remove(osb->local_alloc_debug); | ||
137 | |||
138 | if (osb->local_alloc_debug_buf) | ||
139 | kfree(osb->local_alloc_debug_buf); | ||
140 | |||
141 | osb->local_alloc_debug_buf = NULL; | ||
142 | osb->local_alloc_debug = NULL; | ||
143 | } | ||
144 | #else /* CONFIG_OCFS2_FS_STATS */ | ||
145 | static void ocfs2_init_la_debug(struct ocfs2_super *osb) | ||
146 | { | ||
147 | return; | ||
148 | } | ||
149 | static void ocfs2_shutdown_la_debug(struct ocfs2_super *osb) | ||
150 | { | ||
151 | return; | ||
152 | } | ||
153 | #endif | ||
154 | |||
155 | static inline int ocfs2_la_state_enabled(struct ocfs2_super *osb) | ||
79 | { | 156 | { |
80 | BUG_ON(osb->s_clustersize_bits > 20); | 157 | return (osb->local_alloc_state == OCFS2_LA_THROTTLED || |
158 | osb->local_alloc_state == OCFS2_LA_ENABLED); | ||
159 | } | ||
81 | 160 | ||
82 | /* Size local alloc windows by the megabyte */ | 161 | void ocfs2_local_alloc_seen_free_bits(struct ocfs2_super *osb, |
83 | return osb->local_alloc_size << (20 - osb->s_clustersize_bits); | 162 | unsigned int num_clusters) |
163 | { | ||
164 | spin_lock(&osb->osb_lock); | ||
165 | if (osb->local_alloc_state == OCFS2_LA_DISABLED || | ||
166 | osb->local_alloc_state == OCFS2_LA_THROTTLED) | ||
167 | if (num_clusters >= osb->local_alloc_default_bits) { | ||
168 | cancel_delayed_work(&osb->la_enable_wq); | ||
169 | osb->local_alloc_state = OCFS2_LA_ENABLED; | ||
170 | } | ||
171 | spin_unlock(&osb->osb_lock); | ||
172 | } | ||
173 | |||
174 | void ocfs2_la_enable_worker(struct work_struct *work) | ||
175 | { | ||
176 | struct ocfs2_super *osb = | ||
177 | container_of(work, struct ocfs2_super, | ||
178 | la_enable_wq.work); | ||
179 | spin_lock(&osb->osb_lock); | ||
180 | osb->local_alloc_state = OCFS2_LA_ENABLED; | ||
181 | spin_unlock(&osb->osb_lock); | ||
84 | } | 182 | } |
85 | 183 | ||
86 | /* | 184 | /* |
87 | * Tell us whether a given allocation should use the local alloc | 185 | * Tell us whether a given allocation should use the local alloc |
88 | * file. Otherwise, it has to go to the main bitmap. | 186 | * file. Otherwise, it has to go to the main bitmap. |
187 | * | ||
188 | * This function does semi-dirty reads of local alloc size and state! | ||
189 | * This is ok however, as the values are re-checked once under mutex. | ||
89 | */ | 190 | */ |
90 | int ocfs2_alloc_should_use_local(struct ocfs2_super *osb, u64 bits) | 191 | int ocfs2_alloc_should_use_local(struct ocfs2_super *osb, u64 bits) |
91 | { | 192 | { |
92 | int la_bits = ocfs2_local_alloc_window_bits(osb); | ||
93 | int ret = 0; | 193 | int ret = 0; |
194 | int la_bits; | ||
195 | |||
196 | spin_lock(&osb->osb_lock); | ||
197 | la_bits = osb->local_alloc_bits; | ||
94 | 198 | ||
95 | if (osb->local_alloc_state != OCFS2_LA_ENABLED) | 199 | if (!ocfs2_la_state_enabled(osb)) |
96 | goto bail; | 200 | goto bail; |
97 | 201 | ||
98 | /* la_bits should be at least twice the size (in clusters) of | 202 | /* la_bits should be at least twice the size (in clusters) of |
@@ -106,6 +210,7 @@ int ocfs2_alloc_should_use_local(struct ocfs2_super *osb, u64 bits) | |||
106 | bail: | 210 | bail: |
107 | mlog(0, "state=%d, bits=%llu, la_bits=%d, ret=%d\n", | 211 | mlog(0, "state=%d, bits=%llu, la_bits=%d, ret=%d\n", |
108 | osb->local_alloc_state, (unsigned long long)bits, la_bits, ret); | 212 | osb->local_alloc_state, (unsigned long long)bits, la_bits, ret); |
213 | spin_unlock(&osb->osb_lock); | ||
109 | return ret; | 214 | return ret; |
110 | } | 215 | } |
111 | 216 | ||
@@ -120,14 +225,18 @@ int ocfs2_load_local_alloc(struct ocfs2_super *osb) | |||
120 | 225 | ||
121 | mlog_entry_void(); | 226 | mlog_entry_void(); |
122 | 227 | ||
123 | if (osb->local_alloc_size == 0) | 228 | ocfs2_init_la_debug(osb); |
229 | |||
230 | if (osb->local_alloc_bits == 0) | ||
124 | goto bail; | 231 | goto bail; |
125 | 232 | ||
126 | if (ocfs2_local_alloc_window_bits(osb) >= osb->bitmap_cpg) { | 233 | if (osb->local_alloc_bits >= osb->bitmap_cpg) { |
127 | mlog(ML_NOTICE, "Requested local alloc window %d is larger " | 234 | mlog(ML_NOTICE, "Requested local alloc window %d is larger " |
128 | "than max possible %u. Using defaults.\n", | 235 | "than max possible %u. Using defaults.\n", |
129 | ocfs2_local_alloc_window_bits(osb), (osb->bitmap_cpg - 1)); | 236 | osb->local_alloc_bits, (osb->bitmap_cpg - 1)); |
130 | osb->local_alloc_size = OCFS2_DEFAULT_LOCAL_ALLOC_SIZE; | 237 | osb->local_alloc_bits = |
238 | ocfs2_megabytes_to_clusters(osb->sb, | ||
239 | OCFS2_DEFAULT_LOCAL_ALLOC_SIZE); | ||
131 | } | 240 | } |
132 | 241 | ||
133 | /* read the alloc off disk */ | 242 | /* read the alloc off disk */ |
@@ -139,8 +248,8 @@ int ocfs2_load_local_alloc(struct ocfs2_super *osb) | |||
139 | goto bail; | 248 | goto bail; |
140 | } | 249 | } |
141 | 250 | ||
142 | status = ocfs2_read_block(osb, OCFS2_I(inode)->ip_blkno, | 251 | status = ocfs2_read_blocks(inode, OCFS2_I(inode)->ip_blkno, 1, |
143 | &alloc_bh, 0, inode); | 252 | &alloc_bh, OCFS2_BH_IGNORE_CACHE); |
144 | if (status < 0) { | 253 | if (status < 0) { |
145 | mlog_errno(status); | 254 | mlog_errno(status); |
146 | goto bail; | 255 | goto bail; |
@@ -185,13 +294,14 @@ int ocfs2_load_local_alloc(struct ocfs2_super *osb) | |||
185 | 294 | ||
186 | bail: | 295 | bail: |
187 | if (status < 0) | 296 | if (status < 0) |
188 | if (alloc_bh) | 297 | brelse(alloc_bh); |
189 | brelse(alloc_bh); | ||
190 | if (inode) | 298 | if (inode) |
191 | iput(inode); | 299 | iput(inode); |
192 | 300 | ||
193 | mlog(0, "Local alloc window bits = %d\n", | 301 | if (status < 0) |
194 | ocfs2_local_alloc_window_bits(osb)); | 302 | ocfs2_shutdown_la_debug(osb); |
303 | |||
304 | mlog(0, "Local alloc window bits = %d\n", osb->local_alloc_bits); | ||
195 | 305 | ||
196 | mlog_exit(status); | 306 | mlog_exit(status); |
197 | return status; | 307 | return status; |
@@ -217,6 +327,11 @@ void ocfs2_shutdown_local_alloc(struct ocfs2_super *osb) | |||
217 | 327 | ||
218 | mlog_entry_void(); | 328 | mlog_entry_void(); |
219 | 329 | ||
330 | cancel_delayed_work(&osb->la_enable_wq); | ||
331 | flush_workqueue(ocfs2_wq); | ||
332 | |||
333 | ocfs2_shutdown_la_debug(osb); | ||
334 | |||
220 | if (osb->local_alloc_state == OCFS2_LA_UNUSED) | 335 | if (osb->local_alloc_state == OCFS2_LA_UNUSED) |
221 | goto out; | 336 | goto out; |
222 | 337 | ||
@@ -295,8 +410,7 @@ out_commit: | |||
295 | ocfs2_commit_trans(osb, handle); | 410 | ocfs2_commit_trans(osb, handle); |
296 | 411 | ||
297 | out_unlock: | 412 | out_unlock: |
298 | if (main_bm_bh) | 413 | brelse(main_bm_bh); |
299 | brelse(main_bm_bh); | ||
300 | 414 | ||
301 | ocfs2_inode_unlock(main_bm_inode, 1); | 415 | ocfs2_inode_unlock(main_bm_inode, 1); |
302 | 416 | ||
@@ -345,8 +459,8 @@ int ocfs2_begin_local_alloc_recovery(struct ocfs2_super *osb, | |||
345 | 459 | ||
346 | mutex_lock(&inode->i_mutex); | 460 | mutex_lock(&inode->i_mutex); |
347 | 461 | ||
348 | status = ocfs2_read_block(osb, OCFS2_I(inode)->ip_blkno, | 462 | status = ocfs2_read_blocks(inode, OCFS2_I(inode)->ip_blkno, 1, |
349 | &alloc_bh, 0, inode); | 463 | &alloc_bh, OCFS2_BH_IGNORE_CACHE); |
350 | if (status < 0) { | 464 | if (status < 0) { |
351 | mlog_errno(status); | 465 | mlog_errno(status); |
352 | goto bail; | 466 | goto bail; |
@@ -372,8 +486,7 @@ bail: | |||
372 | *alloc_copy = NULL; | 486 | *alloc_copy = NULL; |
373 | } | 487 | } |
374 | 488 | ||
375 | if (alloc_bh) | 489 | brelse(alloc_bh); |
376 | brelse(alloc_bh); | ||
377 | 490 | ||
378 | if (inode) { | 491 | if (inode) { |
379 | mutex_unlock(&inode->i_mutex); | 492 | mutex_unlock(&inode->i_mutex); |
@@ -441,8 +554,7 @@ out_unlock: | |||
441 | out_mutex: | 554 | out_mutex: |
442 | mutex_unlock(&main_bm_inode->i_mutex); | 555 | mutex_unlock(&main_bm_inode->i_mutex); |
443 | 556 | ||
444 | if (main_bm_bh) | 557 | brelse(main_bm_bh); |
445 | brelse(main_bm_bh); | ||
446 | 558 | ||
447 | iput(main_bm_inode); | 559 | iput(main_bm_inode); |
448 | 560 | ||
@@ -453,8 +565,48 @@ out: | |||
453 | return status; | 565 | return status; |
454 | } | 566 | } |
455 | 567 | ||
568 | /* Check to see if the local alloc window is within ac->ac_max_block */ | ||
569 | static int ocfs2_local_alloc_in_range(struct inode *inode, | ||
570 | struct ocfs2_alloc_context *ac, | ||
571 | u32 bits_wanted) | ||
572 | { | ||
573 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
574 | struct ocfs2_dinode *alloc; | ||
575 | struct ocfs2_local_alloc *la; | ||
576 | int start; | ||
577 | u64 block_off; | ||
578 | |||
579 | if (!ac->ac_max_block) | ||
580 | return 1; | ||
581 | |||
582 | alloc = (struct ocfs2_dinode *) osb->local_alloc_bh->b_data; | ||
583 | la = OCFS2_LOCAL_ALLOC(alloc); | ||
584 | |||
585 | start = ocfs2_local_alloc_find_clear_bits(osb, alloc, bits_wanted); | ||
586 | if (start == -1) { | ||
587 | mlog_errno(-ENOSPC); | ||
588 | return 0; | ||
589 | } | ||
590 | |||
591 | /* | ||
592 | * Converting (bm_off + start + bits_wanted) to blocks gives us | ||
593 | * the blkno just past our actual allocation. This is perfect | ||
594 | * to compare with ac_max_block. | ||
595 | */ | ||
596 | block_off = ocfs2_clusters_to_blocks(inode->i_sb, | ||
597 | le32_to_cpu(la->la_bm_off) + | ||
598 | start + bits_wanted); | ||
599 | mlog(0, "Checking %llu against %llu\n", | ||
600 | (unsigned long long)block_off, | ||
601 | (unsigned long long)ac->ac_max_block); | ||
602 | if (block_off > ac->ac_max_block) | ||
603 | return 0; | ||
604 | |||
605 | return 1; | ||
606 | } | ||
607 | |||
456 | /* | 608 | /* |
457 | * make sure we've got at least bitswanted contiguous bits in the | 609 | * make sure we've got at least bits_wanted contiguous bits in the |
458 | * local alloc. You lose them when you drop i_mutex. | 610 | * local alloc. You lose them when you drop i_mutex. |
459 | * | 611 | * |
460 | * We will add ourselves to the transaction passed in, but may start | 612 | * We will add ourselves to the transaction passed in, but may start |
@@ -485,16 +637,18 @@ int ocfs2_reserve_local_alloc_bits(struct ocfs2_super *osb, | |||
485 | 637 | ||
486 | mutex_lock(&local_alloc_inode->i_mutex); | 638 | mutex_lock(&local_alloc_inode->i_mutex); |
487 | 639 | ||
488 | if (osb->local_alloc_state != OCFS2_LA_ENABLED) { | 640 | /* |
489 | status = -ENOSPC; | 641 | * We must double check state and allocator bits because |
490 | goto bail; | 642 | * another process may have changed them while holding i_mutex. |
491 | } | 643 | */ |
492 | 644 | spin_lock(&osb->osb_lock); | |
493 | if (bits_wanted > ocfs2_local_alloc_window_bits(osb)) { | 645 | if (!ocfs2_la_state_enabled(osb) || |
494 | mlog(0, "Asking for more than my max window size!\n"); | 646 | (bits_wanted > osb->local_alloc_bits)) { |
647 | spin_unlock(&osb->osb_lock); | ||
495 | status = -ENOSPC; | 648 | status = -ENOSPC; |
496 | goto bail; | 649 | goto bail; |
497 | } | 650 | } |
651 | spin_unlock(&osb->osb_lock); | ||
498 | 652 | ||
499 | alloc = (struct ocfs2_dinode *) osb->local_alloc_bh->b_data; | 653 | alloc = (struct ocfs2_dinode *) osb->local_alloc_bh->b_data; |
500 | 654 | ||
@@ -522,6 +676,36 @@ int ocfs2_reserve_local_alloc_bits(struct ocfs2_super *osb, | |||
522 | mlog_errno(status); | 676 | mlog_errno(status); |
523 | goto bail; | 677 | goto bail; |
524 | } | 678 | } |
679 | |||
680 | /* | ||
681 | * Under certain conditions, the window slide code | ||
682 | * might have reduced the number of bits available or | ||
683 | * disabled the the local alloc entirely. Re-check | ||
684 | * here and return -ENOSPC if necessary. | ||
685 | */ | ||
686 | status = -ENOSPC; | ||
687 | if (!ocfs2_la_state_enabled(osb)) | ||
688 | goto bail; | ||
689 | |||
690 | free_bits = le32_to_cpu(alloc->id1.bitmap1.i_total) - | ||
691 | le32_to_cpu(alloc->id1.bitmap1.i_used); | ||
692 | if (bits_wanted > free_bits) | ||
693 | goto bail; | ||
694 | } | ||
695 | |||
696 | if (ac->ac_max_block) | ||
697 | mlog(0, "Calling in_range for max block %llu\n", | ||
698 | (unsigned long long)ac->ac_max_block); | ||
699 | |||
700 | if (!ocfs2_local_alloc_in_range(local_alloc_inode, ac, | ||
701 | bits_wanted)) { | ||
702 | /* | ||
703 | * The window is outside ac->ac_max_block. | ||
704 | * This errno tells the caller to keep localalloc enabled | ||
705 | * but to get the allocation from the main bitmap. | ||
706 | */ | ||
707 | status = -EFBIG; | ||
708 | goto bail; | ||
525 | } | 709 | } |
526 | 710 | ||
527 | ac->ac_inode = local_alloc_inode; | 711 | ac->ac_inode = local_alloc_inode; |
@@ -789,6 +973,85 @@ bail: | |||
789 | return status; | 973 | return status; |
790 | } | 974 | } |
791 | 975 | ||
976 | enum ocfs2_la_event { | ||
977 | OCFS2_LA_EVENT_SLIDE, /* Normal window slide. */ | ||
978 | OCFS2_LA_EVENT_FRAGMENTED, /* The global bitmap has | ||
979 | * enough bits theoretically | ||
980 | * free, but a contiguous | ||
981 | * allocation could not be | ||
982 | * found. */ | ||
983 | OCFS2_LA_EVENT_ENOSPC, /* Global bitmap doesn't have | ||
984 | * enough bits free to satisfy | ||
985 | * our request. */ | ||
986 | }; | ||
987 | #define OCFS2_LA_ENABLE_INTERVAL (30 * HZ) | ||
988 | /* | ||
989 | * Given an event, calculate the size of our next local alloc window. | ||
990 | * | ||
991 | * This should always be called under i_mutex of the local alloc inode | ||
992 | * so that local alloc disabling doesn't race with processes trying to | ||
993 | * use the allocator. | ||
994 | * | ||
995 | * Returns the state which the local alloc was left in. This value can | ||
996 | * be ignored by some paths. | ||
997 | */ | ||
998 | static int ocfs2_recalc_la_window(struct ocfs2_super *osb, | ||
999 | enum ocfs2_la_event event) | ||
1000 | { | ||
1001 | unsigned int bits; | ||
1002 | int state; | ||
1003 | |||
1004 | spin_lock(&osb->osb_lock); | ||
1005 | if (osb->local_alloc_state == OCFS2_LA_DISABLED) { | ||
1006 | WARN_ON_ONCE(osb->local_alloc_state == OCFS2_LA_DISABLED); | ||
1007 | goto out_unlock; | ||
1008 | } | ||
1009 | |||
1010 | /* | ||
1011 | * ENOSPC and fragmentation are treated similarly for now. | ||
1012 | */ | ||
1013 | if (event == OCFS2_LA_EVENT_ENOSPC || | ||
1014 | event == OCFS2_LA_EVENT_FRAGMENTED) { | ||
1015 | /* | ||
1016 | * We ran out of contiguous space in the primary | ||
1017 | * bitmap. Drastically reduce the number of bits used | ||
1018 | * by local alloc until we have to disable it. | ||
1019 | */ | ||
1020 | bits = osb->local_alloc_bits >> 1; | ||
1021 | if (bits > ocfs2_megabytes_to_clusters(osb->sb, 1)) { | ||
1022 | /* | ||
1023 | * By setting state to THROTTLED, we'll keep | ||
1024 | * the number of local alloc bits used down | ||
1025 | * until an event occurs which would give us | ||
1026 | * reason to assume the bitmap situation might | ||
1027 | * have changed. | ||
1028 | */ | ||
1029 | osb->local_alloc_state = OCFS2_LA_THROTTLED; | ||
1030 | osb->local_alloc_bits = bits; | ||
1031 | } else { | ||
1032 | osb->local_alloc_state = OCFS2_LA_DISABLED; | ||
1033 | } | ||
1034 | queue_delayed_work(ocfs2_wq, &osb->la_enable_wq, | ||
1035 | OCFS2_LA_ENABLE_INTERVAL); | ||
1036 | goto out_unlock; | ||
1037 | } | ||
1038 | |||
1039 | /* | ||
1040 | * Don't increase the size of the local alloc window until we | ||
1041 | * know we might be able to fulfill the request. Otherwise, we | ||
1042 | * risk bouncing around the global bitmap during periods of | ||
1043 | * low space. | ||
1044 | */ | ||
1045 | if (osb->local_alloc_state != OCFS2_LA_THROTTLED) | ||
1046 | osb->local_alloc_bits = osb->local_alloc_default_bits; | ||
1047 | |||
1048 | out_unlock: | ||
1049 | state = osb->local_alloc_state; | ||
1050 | spin_unlock(&osb->osb_lock); | ||
1051 | |||
1052 | return state; | ||
1053 | } | ||
1054 | |||
792 | static int ocfs2_local_alloc_reserve_for_window(struct ocfs2_super *osb, | 1055 | static int ocfs2_local_alloc_reserve_for_window(struct ocfs2_super *osb, |
793 | struct ocfs2_alloc_context **ac, | 1056 | struct ocfs2_alloc_context **ac, |
794 | struct inode **bitmap_inode, | 1057 | struct inode **bitmap_inode, |
@@ -803,12 +1066,21 @@ static int ocfs2_local_alloc_reserve_for_window(struct ocfs2_super *osb, | |||
803 | goto bail; | 1066 | goto bail; |
804 | } | 1067 | } |
805 | 1068 | ||
806 | (*ac)->ac_bits_wanted = ocfs2_local_alloc_window_bits(osb); | 1069 | retry_enospc: |
1070 | (*ac)->ac_bits_wanted = osb->local_alloc_bits; | ||
807 | 1071 | ||
808 | status = ocfs2_reserve_cluster_bitmap_bits(osb, *ac); | 1072 | status = ocfs2_reserve_cluster_bitmap_bits(osb, *ac); |
1073 | if (status == -ENOSPC) { | ||
1074 | if (ocfs2_recalc_la_window(osb, OCFS2_LA_EVENT_ENOSPC) == | ||
1075 | OCFS2_LA_DISABLED) | ||
1076 | goto bail; | ||
1077 | |||
1078 | ocfs2_free_ac_resource(*ac); | ||
1079 | memset(*ac, 0, sizeof(struct ocfs2_alloc_context)); | ||
1080 | goto retry_enospc; | ||
1081 | } | ||
809 | if (status < 0) { | 1082 | if (status < 0) { |
810 | if (status != -ENOSPC) | 1083 | mlog_errno(status); |
811 | mlog_errno(status); | ||
812 | goto bail; | 1084 | goto bail; |
813 | } | 1085 | } |
814 | 1086 | ||
@@ -849,7 +1121,7 @@ static int ocfs2_local_alloc_new_window(struct ocfs2_super *osb, | |||
849 | "one\n"); | 1121 | "one\n"); |
850 | 1122 | ||
851 | mlog(0, "Allocating %u clusters for a new window.\n", | 1123 | mlog(0, "Allocating %u clusters for a new window.\n", |
852 | ocfs2_local_alloc_window_bits(osb)); | 1124 | osb->local_alloc_bits); |
853 | 1125 | ||
854 | /* Instruct the allocation code to try the most recently used | 1126 | /* Instruct the allocation code to try the most recently used |
855 | * cluster group. We'll re-record the group used this pass | 1127 | * cluster group. We'll re-record the group used this pass |
@@ -859,9 +1131,36 @@ static int ocfs2_local_alloc_new_window(struct ocfs2_super *osb, | |||
859 | /* we used the generic suballoc reserve function, but we set | 1131 | /* we used the generic suballoc reserve function, but we set |
860 | * everything up nicely, so there's no reason why we can't use | 1132 | * everything up nicely, so there's no reason why we can't use |
861 | * the more specific cluster api to claim bits. */ | 1133 | * the more specific cluster api to claim bits. */ |
862 | status = ocfs2_claim_clusters(osb, handle, ac, | 1134 | status = ocfs2_claim_clusters(osb, handle, ac, osb->local_alloc_bits, |
863 | ocfs2_local_alloc_window_bits(osb), | ||
864 | &cluster_off, &cluster_count); | 1135 | &cluster_off, &cluster_count); |
1136 | if (status == -ENOSPC) { | ||
1137 | retry_enospc: | ||
1138 | /* | ||
1139 | * Note: We could also try syncing the journal here to | ||
1140 | * allow use of any free bits which the current | ||
1141 | * transaction can't give us access to. --Mark | ||
1142 | */ | ||
1143 | if (ocfs2_recalc_la_window(osb, OCFS2_LA_EVENT_FRAGMENTED) == | ||
1144 | OCFS2_LA_DISABLED) | ||
1145 | goto bail; | ||
1146 | |||
1147 | status = ocfs2_claim_clusters(osb, handle, ac, | ||
1148 | osb->local_alloc_bits, | ||
1149 | &cluster_off, | ||
1150 | &cluster_count); | ||
1151 | if (status == -ENOSPC) | ||
1152 | goto retry_enospc; | ||
1153 | /* | ||
1154 | * We only shrunk the *minimum* number of in our | ||
1155 | * request - it's entirely possible that the allocator | ||
1156 | * might give us more than we asked for. | ||
1157 | */ | ||
1158 | if (status == 0) { | ||
1159 | spin_lock(&osb->osb_lock); | ||
1160 | osb->local_alloc_bits = cluster_count; | ||
1161 | spin_unlock(&osb->osb_lock); | ||
1162 | } | ||
1163 | } | ||
865 | if (status < 0) { | 1164 | if (status < 0) { |
866 | if (status != -ENOSPC) | 1165 | if (status != -ENOSPC) |
867 | mlog_errno(status); | 1166 | mlog_errno(status); |
@@ -905,6 +1204,8 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb, | |||
905 | 1204 | ||
906 | mlog_entry_void(); | 1205 | mlog_entry_void(); |
907 | 1206 | ||
1207 | ocfs2_recalc_la_window(osb, OCFS2_LA_EVENT_SLIDE); | ||
1208 | |||
908 | /* This will lock the main bitmap for us. */ | 1209 | /* This will lock the main bitmap for us. */ |
909 | status = ocfs2_local_alloc_reserve_for_window(osb, | 1210 | status = ocfs2_local_alloc_reserve_for_window(osb, |
910 | &ac, | 1211 | &ac, |
@@ -976,8 +1277,7 @@ bail: | |||
976 | if (handle) | 1277 | if (handle) |
977 | ocfs2_commit_trans(osb, handle); | 1278 | ocfs2_commit_trans(osb, handle); |
978 | 1279 | ||
979 | if (main_bm_bh) | 1280 | brelse(main_bm_bh); |
980 | brelse(main_bm_bh); | ||
981 | 1281 | ||
982 | if (main_bm_inode) | 1282 | if (main_bm_inode) |
983 | iput(main_bm_inode); | 1283 | iput(main_bm_inode); |
diff --git a/fs/ocfs2/localalloc.h b/fs/ocfs2/localalloc.h index 3f76631e110c..ac5ea9f86653 100644 --- a/fs/ocfs2/localalloc.h +++ b/fs/ocfs2/localalloc.h | |||
@@ -52,4 +52,8 @@ int ocfs2_claim_local_alloc_bits(struct ocfs2_super *osb, | |||
52 | u32 *bit_off, | 52 | u32 *bit_off, |
53 | u32 *num_bits); | 53 | u32 *num_bits); |
54 | 54 | ||
55 | void ocfs2_local_alloc_seen_free_bits(struct ocfs2_super *osb, | ||
56 | unsigned int num_clusters); | ||
57 | void ocfs2_la_enable_worker(struct work_struct *work); | ||
58 | |||
55 | #endif /* OCFS2_LOCALALLOC_H */ | 59 | #endif /* OCFS2_LOCALALLOC_H */ |
diff --git a/fs/ocfs2/locks.c b/fs/ocfs2/locks.c index 203f87143877..544ac6245175 100644 --- a/fs/ocfs2/locks.c +++ b/fs/ocfs2/locks.c | |||
@@ -24,6 +24,7 @@ | |||
24 | */ | 24 | */ |
25 | 25 | ||
26 | #include <linux/fs.h> | 26 | #include <linux/fs.h> |
27 | #include <linux/fcntl.h> | ||
27 | 28 | ||
28 | #define MLOG_MASK_PREFIX ML_INODE | 29 | #define MLOG_MASK_PREFIX ML_INODE |
29 | #include <cluster/masklog.h> | 30 | #include <cluster/masklog.h> |
@@ -32,6 +33,7 @@ | |||
32 | 33 | ||
33 | #include "dlmglue.h" | 34 | #include "dlmglue.h" |
34 | #include "file.h" | 35 | #include "file.h" |
36 | #include "inode.h" | ||
35 | #include "locks.h" | 37 | #include "locks.h" |
36 | 38 | ||
37 | static int ocfs2_do_flock(struct file *file, struct inode *inode, | 39 | static int ocfs2_do_flock(struct file *file, struct inode *inode, |
@@ -123,3 +125,16 @@ int ocfs2_flock(struct file *file, int cmd, struct file_lock *fl) | |||
123 | else | 125 | else |
124 | return ocfs2_do_flock(file, inode, cmd, fl); | 126 | return ocfs2_do_flock(file, inode, cmd, fl); |
125 | } | 127 | } |
128 | |||
129 | int ocfs2_lock(struct file *file, int cmd, struct file_lock *fl) | ||
130 | { | ||
131 | struct inode *inode = file->f_mapping->host; | ||
132 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
133 | |||
134 | if (!(fl->fl_flags & FL_POSIX)) | ||
135 | return -ENOLCK; | ||
136 | if (__mandatory_lock(inode)) | ||
137 | return -ENOLCK; | ||
138 | |||
139 | return ocfs2_plock(osb->cconn, OCFS2_I(inode)->ip_blkno, file, cmd, fl); | ||
140 | } | ||
diff --git a/fs/ocfs2/locks.h b/fs/ocfs2/locks.h index 9743ef2324ec..496d488b271f 100644 --- a/fs/ocfs2/locks.h +++ b/fs/ocfs2/locks.h | |||
@@ -27,5 +27,6 @@ | |||
27 | #define OCFS2_LOCKS_H | 27 | #define OCFS2_LOCKS_H |
28 | 28 | ||
29 | int ocfs2_flock(struct file *file, int cmd, struct file_lock *fl); | 29 | int ocfs2_flock(struct file *file, int cmd, struct file_lock *fl); |
30 | int ocfs2_lock(struct file *file, int cmd, struct file_lock *fl); | ||
30 | 31 | ||
31 | #endif /* OCFS2_LOCKS_H */ | 32 | #endif /* OCFS2_LOCKS_H */ |
diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c index d5d808fe0140..485a6aa0ad39 100644 --- a/fs/ocfs2/namei.c +++ b/fs/ocfs2/namei.c | |||
@@ -60,6 +60,7 @@ | |||
60 | #include "symlink.h" | 60 | #include "symlink.h" |
61 | #include "sysfile.h" | 61 | #include "sysfile.h" |
62 | #include "uptodate.h" | 62 | #include "uptodate.h" |
63 | #include "xattr.h" | ||
63 | 64 | ||
64 | #include "buffer_head_io.h" | 65 | #include "buffer_head_io.h" |
65 | 66 | ||
@@ -327,14 +328,9 @@ leave: | |||
327 | if (status == -ENOSPC) | 328 | if (status == -ENOSPC) |
328 | mlog(0, "Disk is full\n"); | 329 | mlog(0, "Disk is full\n"); |
329 | 330 | ||
330 | if (new_fe_bh) | 331 | brelse(new_fe_bh); |
331 | brelse(new_fe_bh); | 332 | brelse(de_bh); |
332 | 333 | brelse(parent_fe_bh); | |
333 | if (de_bh) | ||
334 | brelse(de_bh); | ||
335 | |||
336 | if (parent_fe_bh) | ||
337 | brelse(parent_fe_bh); | ||
338 | 334 | ||
339 | if ((status < 0) && inode) | 335 | if ((status < 0) && inode) |
340 | iput(inode); | 336 | iput(inode); |
@@ -647,12 +643,9 @@ out_unlock_inode: | |||
647 | out: | 643 | out: |
648 | ocfs2_inode_unlock(dir, 1); | 644 | ocfs2_inode_unlock(dir, 1); |
649 | 645 | ||
650 | if (de_bh) | 646 | brelse(de_bh); |
651 | brelse(de_bh); | 647 | brelse(fe_bh); |
652 | if (fe_bh) | 648 | brelse(parent_fe_bh); |
653 | brelse(fe_bh); | ||
654 | if (parent_fe_bh) | ||
655 | brelse(parent_fe_bh); | ||
656 | 649 | ||
657 | mlog_exit(err); | 650 | mlog_exit(err); |
658 | 651 | ||
@@ -851,17 +844,10 @@ leave: | |||
851 | iput(orphan_dir); | 844 | iput(orphan_dir); |
852 | } | 845 | } |
853 | 846 | ||
854 | if (fe_bh) | 847 | brelse(fe_bh); |
855 | brelse(fe_bh); | 848 | brelse(dirent_bh); |
856 | 849 | brelse(parent_node_bh); | |
857 | if (dirent_bh) | 850 | brelse(orphan_entry_bh); |
858 | brelse(dirent_bh); | ||
859 | |||
860 | if (parent_node_bh) | ||
861 | brelse(parent_node_bh); | ||
862 | |||
863 | if (orphan_entry_bh) | ||
864 | brelse(orphan_entry_bh); | ||
865 | 851 | ||
866 | mlog_exit(status); | 852 | mlog_exit(status); |
867 | 853 | ||
@@ -1372,24 +1358,15 @@ bail: | |||
1372 | 1358 | ||
1373 | if (new_inode) | 1359 | if (new_inode) |
1374 | iput(new_inode); | 1360 | iput(new_inode); |
1375 | if (newfe_bh) | 1361 | brelse(newfe_bh); |
1376 | brelse(newfe_bh); | 1362 | brelse(old_inode_bh); |
1377 | if (old_inode_bh) | 1363 | brelse(old_dir_bh); |
1378 | brelse(old_inode_bh); | 1364 | brelse(new_dir_bh); |
1379 | if (old_dir_bh) | 1365 | brelse(new_de_bh); |
1380 | brelse(old_dir_bh); | 1366 | brelse(old_de_bh); |
1381 | if (new_dir_bh) | 1367 | brelse(old_inode_de_bh); |
1382 | brelse(new_dir_bh); | 1368 | brelse(orphan_entry_bh); |
1383 | if (new_de_bh) | 1369 | brelse(insert_entry_bh); |
1384 | brelse(new_de_bh); | ||
1385 | if (old_de_bh) | ||
1386 | brelse(old_de_bh); | ||
1387 | if (old_inode_de_bh) | ||
1388 | brelse(old_inode_de_bh); | ||
1389 | if (orphan_entry_bh) | ||
1390 | brelse(orphan_entry_bh); | ||
1391 | if (insert_entry_bh) | ||
1392 | brelse(insert_entry_bh); | ||
1393 | 1370 | ||
1394 | mlog_exit(status); | 1371 | mlog_exit(status); |
1395 | 1372 | ||
@@ -1492,8 +1469,7 @@ bail: | |||
1492 | 1469 | ||
1493 | if (bhs) { | 1470 | if (bhs) { |
1494 | for(i = 0; i < blocks; i++) | 1471 | for(i = 0; i < blocks; i++) |
1495 | if (bhs[i]) | 1472 | brelse(bhs[i]); |
1496 | brelse(bhs[i]); | ||
1497 | kfree(bhs); | 1473 | kfree(bhs); |
1498 | } | 1474 | } |
1499 | 1475 | ||
@@ -1598,10 +1574,10 @@ static int ocfs2_symlink(struct inode *dir, | |||
1598 | u32 offset = 0; | 1574 | u32 offset = 0; |
1599 | 1575 | ||
1600 | inode->i_op = &ocfs2_symlink_inode_operations; | 1576 | inode->i_op = &ocfs2_symlink_inode_operations; |
1601 | status = ocfs2_do_extend_allocation(osb, inode, &offset, 1, 0, | 1577 | status = ocfs2_add_inode_data(osb, inode, &offset, 1, 0, |
1602 | new_fe_bh, | 1578 | new_fe_bh, |
1603 | handle, data_ac, NULL, | 1579 | handle, data_ac, NULL, |
1604 | NULL); | 1580 | NULL); |
1605 | if (status < 0) { | 1581 | if (status < 0) { |
1606 | if (status != -ENOSPC && status != -EINTR) { | 1582 | if (status != -ENOSPC && status != -EINTR) { |
1607 | mlog(ML_ERROR, | 1583 | mlog(ML_ERROR, |
@@ -1659,12 +1635,9 @@ bail: | |||
1659 | 1635 | ||
1660 | ocfs2_inode_unlock(dir, 1); | 1636 | ocfs2_inode_unlock(dir, 1); |
1661 | 1637 | ||
1662 | if (new_fe_bh) | 1638 | brelse(new_fe_bh); |
1663 | brelse(new_fe_bh); | 1639 | brelse(parent_fe_bh); |
1664 | if (parent_fe_bh) | 1640 | brelse(de_bh); |
1665 | brelse(parent_fe_bh); | ||
1666 | if (de_bh) | ||
1667 | brelse(de_bh); | ||
1668 | if (inode_ac) | 1641 | if (inode_ac) |
1669 | ocfs2_free_alloc_context(inode_ac); | 1642 | ocfs2_free_alloc_context(inode_ac); |
1670 | if (data_ac) | 1643 | if (data_ac) |
@@ -1759,8 +1732,7 @@ leave: | |||
1759 | iput(orphan_dir_inode); | 1732 | iput(orphan_dir_inode); |
1760 | } | 1733 | } |
1761 | 1734 | ||
1762 | if (orphan_dir_bh) | 1735 | brelse(orphan_dir_bh); |
1763 | brelse(orphan_dir_bh); | ||
1764 | 1736 | ||
1765 | mlog_exit(status); | 1737 | mlog_exit(status); |
1766 | return status; | 1738 | return status; |
@@ -1780,10 +1752,9 @@ static int ocfs2_orphan_add(struct ocfs2_super *osb, | |||
1780 | 1752 | ||
1781 | mlog_entry("(inode->i_ino = %lu)\n", inode->i_ino); | 1753 | mlog_entry("(inode->i_ino = %lu)\n", inode->i_ino); |
1782 | 1754 | ||
1783 | status = ocfs2_read_block(osb, | 1755 | status = ocfs2_read_block(orphan_dir_inode, |
1784 | OCFS2_I(orphan_dir_inode)->ip_blkno, | 1756 | OCFS2_I(orphan_dir_inode)->ip_blkno, |
1785 | &orphan_dir_bh, OCFS2_BH_CACHED, | 1757 | &orphan_dir_bh); |
1786 | orphan_dir_inode); | ||
1787 | if (status < 0) { | 1758 | if (status < 0) { |
1788 | mlog_errno(status); | 1759 | mlog_errno(status); |
1789 | goto leave; | 1760 | goto leave; |
@@ -1829,8 +1800,7 @@ static int ocfs2_orphan_add(struct ocfs2_super *osb, | |||
1829 | (unsigned long long)OCFS2_I(inode)->ip_blkno, osb->slot_num); | 1800 | (unsigned long long)OCFS2_I(inode)->ip_blkno, osb->slot_num); |
1830 | 1801 | ||
1831 | leave: | 1802 | leave: |
1832 | if (orphan_dir_bh) | 1803 | brelse(orphan_dir_bh); |
1833 | brelse(orphan_dir_bh); | ||
1834 | 1804 | ||
1835 | mlog_exit(status); | 1805 | mlog_exit(status); |
1836 | return status; | 1806 | return status; |
@@ -1898,8 +1868,7 @@ int ocfs2_orphan_del(struct ocfs2_super *osb, | |||
1898 | } | 1868 | } |
1899 | 1869 | ||
1900 | leave: | 1870 | leave: |
1901 | if (target_de_bh) | 1871 | brelse(target_de_bh); |
1902 | brelse(target_de_bh); | ||
1903 | 1872 | ||
1904 | mlog_exit(status); | 1873 | mlog_exit(status); |
1905 | return status; | 1874 | return status; |
@@ -1918,4 +1887,8 @@ const struct inode_operations ocfs2_dir_iops = { | |||
1918 | .setattr = ocfs2_setattr, | 1887 | .setattr = ocfs2_setattr, |
1919 | .getattr = ocfs2_getattr, | 1888 | .getattr = ocfs2_getattr, |
1920 | .permission = ocfs2_permission, | 1889 | .permission = ocfs2_permission, |
1890 | .setxattr = generic_setxattr, | ||
1891 | .getxattr = generic_getxattr, | ||
1892 | .listxattr = ocfs2_listxattr, | ||
1893 | .removexattr = generic_removexattr, | ||
1921 | }; | 1894 | }; |
diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h index 7f625f2b1117..a21a465490c4 100644 --- a/fs/ocfs2/ocfs2.h +++ b/fs/ocfs2/ocfs2.h | |||
@@ -34,7 +34,12 @@ | |||
34 | #include <linux/workqueue.h> | 34 | #include <linux/workqueue.h> |
35 | #include <linux/kref.h> | 35 | #include <linux/kref.h> |
36 | #include <linux/mutex.h> | 36 | #include <linux/mutex.h> |
37 | #include <linux/jbd.h> | 37 | #ifndef CONFIG_OCFS2_COMPAT_JBD |
38 | # include <linux/jbd2.h> | ||
39 | #else | ||
40 | # include <linux/jbd.h> | ||
41 | # include "ocfs2_jbd_compat.h" | ||
42 | #endif | ||
38 | 43 | ||
39 | /* For union ocfs2_dlm_lksb */ | 44 | /* For union ocfs2_dlm_lksb */ |
40 | #include "stackglue.h" | 45 | #include "stackglue.h" |
@@ -171,9 +176,13 @@ struct ocfs2_alloc_stats | |||
171 | 176 | ||
172 | enum ocfs2_local_alloc_state | 177 | enum ocfs2_local_alloc_state |
173 | { | 178 | { |
174 | OCFS2_LA_UNUSED = 0, | 179 | OCFS2_LA_UNUSED = 0, /* Local alloc will never be used for |
175 | OCFS2_LA_ENABLED, | 180 | * this mountpoint. */ |
176 | OCFS2_LA_DISABLED | 181 | OCFS2_LA_ENABLED, /* Local alloc is in use. */ |
182 | OCFS2_LA_THROTTLED, /* Local alloc is in use, but number | ||
183 | * of bits has been reduced. */ | ||
184 | OCFS2_LA_DISABLED /* Local alloc has temporarily been | ||
185 | * disabled. */ | ||
177 | }; | 186 | }; |
178 | 187 | ||
179 | enum ocfs2_mount_options | 188 | enum ocfs2_mount_options |
@@ -184,6 +193,8 @@ enum ocfs2_mount_options | |||
184 | OCFS2_MOUNT_ERRORS_PANIC = 1 << 3, /* Panic on errors */ | 193 | OCFS2_MOUNT_ERRORS_PANIC = 1 << 3, /* Panic on errors */ |
185 | OCFS2_MOUNT_DATA_WRITEBACK = 1 << 4, /* No data ordering */ | 194 | OCFS2_MOUNT_DATA_WRITEBACK = 1 << 4, /* No data ordering */ |
186 | OCFS2_MOUNT_LOCALFLOCKS = 1 << 5, /* No cluster aware user file locks */ | 195 | OCFS2_MOUNT_LOCALFLOCKS = 1 << 5, /* No cluster aware user file locks */ |
196 | OCFS2_MOUNT_NOUSERXATTR = 1 << 6, /* No user xattr */ | ||
197 | OCFS2_MOUNT_INODE64 = 1 << 7, /* Allow inode numbers > 2^32 */ | ||
187 | }; | 198 | }; |
188 | 199 | ||
189 | #define OCFS2_OSB_SOFT_RO 0x0001 | 200 | #define OCFS2_OSB_SOFT_RO 0x0001 |
@@ -214,6 +225,7 @@ struct ocfs2_super | |||
214 | u32 bitmap_cpg; | 225 | u32 bitmap_cpg; |
215 | u8 *uuid; | 226 | u8 *uuid; |
216 | char *uuid_str; | 227 | char *uuid_str; |
228 | u32 uuid_hash; | ||
217 | u8 *vol_label; | 229 | u8 *vol_label; |
218 | u64 first_cluster_group_blkno; | 230 | u64 first_cluster_group_blkno; |
219 | u32 fs_generation; | 231 | u32 fs_generation; |
@@ -241,6 +253,7 @@ struct ocfs2_super | |||
241 | int s_sectsize_bits; | 253 | int s_sectsize_bits; |
242 | int s_clustersize; | 254 | int s_clustersize; |
243 | int s_clustersize_bits; | 255 | int s_clustersize_bits; |
256 | unsigned int s_xattr_inline_size; | ||
244 | 257 | ||
245 | atomic_t vol_state; | 258 | atomic_t vol_state; |
246 | struct mutex recovery_lock; | 259 | struct mutex recovery_lock; |
@@ -252,11 +265,27 @@ struct ocfs2_super | |||
252 | struct ocfs2_journal *journal; | 265 | struct ocfs2_journal *journal; |
253 | unsigned long osb_commit_interval; | 266 | unsigned long osb_commit_interval; |
254 | 267 | ||
255 | int local_alloc_size; | 268 | struct delayed_work la_enable_wq; |
256 | enum ocfs2_local_alloc_state local_alloc_state; | 269 | |
270 | /* | ||
271 | * Must hold local alloc i_mutex and osb->osb_lock to change | ||
272 | * local_alloc_bits. Reads can be done under either lock. | ||
273 | */ | ||
274 | unsigned int local_alloc_bits; | ||
275 | unsigned int local_alloc_default_bits; | ||
276 | |||
277 | enum ocfs2_local_alloc_state local_alloc_state; /* protected | ||
278 | * by osb_lock */ | ||
279 | |||
257 | struct buffer_head *local_alloc_bh; | 280 | struct buffer_head *local_alloc_bh; |
281 | |||
258 | u64 la_last_gd; | 282 | u64 la_last_gd; |
259 | 283 | ||
284 | #ifdef CONFIG_OCFS2_FS_STATS | ||
285 | struct dentry *local_alloc_debug; | ||
286 | char *local_alloc_debug_buf; | ||
287 | #endif | ||
288 | |||
260 | /* Next two fields are for local node slot recovery during | 289 | /* Next two fields are for local node slot recovery during |
261 | * mount. */ | 290 | * mount. */ |
262 | int dirty; | 291 | int dirty; |
@@ -340,6 +369,13 @@ static inline int ocfs2_supports_inline_data(struct ocfs2_super *osb) | |||
340 | return 0; | 369 | return 0; |
341 | } | 370 | } |
342 | 371 | ||
372 | static inline int ocfs2_supports_xattr(struct ocfs2_super *osb) | ||
373 | { | ||
374 | if (osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_XATTR) | ||
375 | return 1; | ||
376 | return 0; | ||
377 | } | ||
378 | |||
343 | /* set / clear functions because cluster events can make these happen | 379 | /* set / clear functions because cluster events can make these happen |
344 | * in parallel so we want the transitions to be atomic. this also | 380 | * in parallel so we want the transitions to be atomic. this also |
345 | * means that any future flags osb_flags must be protected by spinlock | 381 | * means that any future flags osb_flags must be protected by spinlock |
@@ -554,6 +590,14 @@ static inline unsigned int ocfs2_pages_per_cluster(struct super_block *sb) | |||
554 | return pages_per_cluster; | 590 | return pages_per_cluster; |
555 | } | 591 | } |
556 | 592 | ||
593 | static inline unsigned int ocfs2_megabytes_to_clusters(struct super_block *sb, | ||
594 | unsigned int megs) | ||
595 | { | ||
596 | BUILD_BUG_ON(OCFS2_MAX_CLUSTERSIZE > 1048576); | ||
597 | |||
598 | return megs << (20 - OCFS2_SB(sb)->s_clustersize_bits); | ||
599 | } | ||
600 | |||
557 | static inline void ocfs2_init_inode_steal_slot(struct ocfs2_super *osb) | 601 | static inline void ocfs2_init_inode_steal_slot(struct ocfs2_super *osb) |
558 | { | 602 | { |
559 | spin_lock(&osb->osb_lock); | 603 | spin_lock(&osb->osb_lock); |
diff --git a/fs/ocfs2/ocfs2_fs.h b/fs/ocfs2/ocfs2_fs.h index 4f619850ccf7..f24ce3d3f956 100644 --- a/fs/ocfs2/ocfs2_fs.h +++ b/fs/ocfs2/ocfs2_fs.h | |||
@@ -64,6 +64,7 @@ | |||
64 | #define OCFS2_INODE_SIGNATURE "INODE01" | 64 | #define OCFS2_INODE_SIGNATURE "INODE01" |
65 | #define OCFS2_EXTENT_BLOCK_SIGNATURE "EXBLK01" | 65 | #define OCFS2_EXTENT_BLOCK_SIGNATURE "EXBLK01" |
66 | #define OCFS2_GROUP_DESC_SIGNATURE "GROUP01" | 66 | #define OCFS2_GROUP_DESC_SIGNATURE "GROUP01" |
67 | #define OCFS2_XATTR_BLOCK_SIGNATURE "XATTR01" | ||
67 | 68 | ||
68 | /* Compatibility flags */ | 69 | /* Compatibility flags */ |
69 | #define OCFS2_HAS_COMPAT_FEATURE(sb,mask) \ | 70 | #define OCFS2_HAS_COMPAT_FEATURE(sb,mask) \ |
@@ -90,7 +91,8 @@ | |||
90 | | OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC \ | 91 | | OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC \ |
91 | | OCFS2_FEATURE_INCOMPAT_INLINE_DATA \ | 92 | | OCFS2_FEATURE_INCOMPAT_INLINE_DATA \ |
92 | | OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP \ | 93 | | OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP \ |
93 | | OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK) | 94 | | OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK \ |
95 | | OCFS2_FEATURE_INCOMPAT_XATTR) | ||
94 | #define OCFS2_FEATURE_RO_COMPAT_SUPP OCFS2_FEATURE_RO_COMPAT_UNWRITTEN | 96 | #define OCFS2_FEATURE_RO_COMPAT_SUPP OCFS2_FEATURE_RO_COMPAT_UNWRITTEN |
95 | 97 | ||
96 | /* | 98 | /* |
@@ -127,10 +129,6 @@ | |||
127 | /* Support for data packed into inode blocks */ | 129 | /* Support for data packed into inode blocks */ |
128 | #define OCFS2_FEATURE_INCOMPAT_INLINE_DATA 0x0040 | 130 | #define OCFS2_FEATURE_INCOMPAT_INLINE_DATA 0x0040 |
129 | 131 | ||
130 | /* Support for the extended slot map */ | ||
131 | #define OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP 0x100 | ||
132 | |||
133 | |||
134 | /* | 132 | /* |
135 | * Support for alternate, userspace cluster stacks. If set, the superblock | 133 | * Support for alternate, userspace cluster stacks. If set, the superblock |
136 | * field s_cluster_info contains a tag for the alternate stack in use as | 134 | * field s_cluster_info contains a tag for the alternate stack in use as |
@@ -142,6 +140,12 @@ | |||
142 | */ | 140 | */ |
143 | #define OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK 0x0080 | 141 | #define OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK 0x0080 |
144 | 142 | ||
143 | /* Support for the extended slot map */ | ||
144 | #define OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP 0x100 | ||
145 | |||
146 | /* Support for extended attributes */ | ||
147 | #define OCFS2_FEATURE_INCOMPAT_XATTR 0x0200 | ||
148 | |||
145 | /* | 149 | /* |
146 | * backup superblock flag is used to indicate that this volume | 150 | * backup superblock flag is used to indicate that this volume |
147 | * has backup superblocks. | 151 | * has backup superblocks. |
@@ -299,6 +303,12 @@ struct ocfs2_new_group_input { | |||
299 | */ | 303 | */ |
300 | #define OCFS2_DEFAULT_LOCAL_ALLOC_SIZE 8 | 304 | #define OCFS2_DEFAULT_LOCAL_ALLOC_SIZE 8 |
301 | 305 | ||
306 | /* | ||
307 | * Inline extended attribute size (in bytes) | ||
308 | * The value chosen should be aligned to 16 byte boundaries. | ||
309 | */ | ||
310 | #define OCFS2_MIN_XATTR_INLINE_SIZE 256 | ||
311 | |||
302 | struct ocfs2_system_inode_info { | 312 | struct ocfs2_system_inode_info { |
303 | char *si_name; | 313 | char *si_name; |
304 | int si_iflags; | 314 | int si_iflags; |
@@ -563,7 +573,7 @@ struct ocfs2_super_block { | |||
563 | /*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts | 573 | /*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts |
564 | before tunefs required */ | 574 | before tunefs required */ |
565 | __le16 s_tunefs_flag; | 575 | __le16 s_tunefs_flag; |
566 | __le32 s_reserved1; | 576 | __le32 s_uuid_hash; /* hash value of uuid */ |
567 | __le64 s_first_cluster_group; /* Block offset of 1st cluster | 577 | __le64 s_first_cluster_group; /* Block offset of 1st cluster |
568 | * group header */ | 578 | * group header */ |
569 | /*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */ | 579 | /*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */ |
@@ -571,7 +581,11 @@ struct ocfs2_super_block { | |||
571 | /*A0*/ struct ocfs2_cluster_info s_cluster_info; /* Selected userspace | 581 | /*A0*/ struct ocfs2_cluster_info s_cluster_info; /* Selected userspace |
572 | stack. Only valid | 582 | stack. Only valid |
573 | with INCOMPAT flag. */ | 583 | with INCOMPAT flag. */ |
574 | /*B8*/ __le64 s_reserved2[17]; /* Fill out superblock */ | 584 | /*B8*/ __le16 s_xattr_inline_size; /* extended attribute inline size |
585 | for this fs*/ | ||
586 | __le16 s_reserved0; | ||
587 | __le32 s_reserved1; | ||
588 | /*C0*/ __le64 s_reserved2[16]; /* Fill out superblock */ | ||
575 | /*140*/ | 589 | /*140*/ |
576 | 590 | ||
577 | /* | 591 | /* |
@@ -621,7 +635,8 @@ struct ocfs2_dinode { | |||
621 | belongs to */ | 635 | belongs to */ |
622 | __le16 i_suballoc_bit; /* Bit offset in suballocator | 636 | __le16 i_suballoc_bit; /* Bit offset in suballocator |
623 | block group */ | 637 | block group */ |
624 | /*10*/ __le32 i_reserved0; | 638 | /*10*/ __le16 i_reserved0; |
639 | __le16 i_xattr_inline_size; | ||
625 | __le32 i_clusters; /* Cluster count */ | 640 | __le32 i_clusters; /* Cluster count */ |
626 | __le32 i_uid; /* Owner UID */ | 641 | __le32 i_uid; /* Owner UID */ |
627 | __le32 i_gid; /* Owning GID */ | 642 | __le32 i_gid; /* Owning GID */ |
@@ -640,11 +655,12 @@ struct ocfs2_dinode { | |||
640 | __le32 i_atime_nsec; | 655 | __le32 i_atime_nsec; |
641 | __le32 i_ctime_nsec; | 656 | __le32 i_ctime_nsec; |
642 | __le32 i_mtime_nsec; | 657 | __le32 i_mtime_nsec; |
643 | __le32 i_attr; | 658 | /*70*/ __le32 i_attr; |
644 | __le16 i_orphaned_slot; /* Only valid when OCFS2_ORPHANED_FL | 659 | __le16 i_orphaned_slot; /* Only valid when OCFS2_ORPHANED_FL |
645 | was set in i_flags */ | 660 | was set in i_flags */ |
646 | __le16 i_dyn_features; | 661 | __le16 i_dyn_features; |
647 | /*70*/ __le64 i_reserved2[8]; | 662 | __le64 i_xattr_loc; |
663 | /*80*/ __le64 i_reserved2[7]; | ||
648 | /*B8*/ union { | 664 | /*B8*/ union { |
649 | __le64 i_pad1; /* Generic way to refer to this | 665 | __le64 i_pad1; /* Generic way to refer to this |
650 | 64bit union */ | 666 | 64bit union */ |
@@ -715,6 +731,136 @@ struct ocfs2_group_desc | |||
715 | /*40*/ __u8 bg_bitmap[0]; | 731 | /*40*/ __u8 bg_bitmap[0]; |
716 | }; | 732 | }; |
717 | 733 | ||
734 | /* | ||
735 | * On disk extended attribute structure for OCFS2. | ||
736 | */ | ||
737 | |||
738 | /* | ||
739 | * ocfs2_xattr_entry indicates one extend attribute. | ||
740 | * | ||
741 | * Note that it can be stored in inode, one block or one xattr bucket. | ||
742 | */ | ||
743 | struct ocfs2_xattr_entry { | ||
744 | __le32 xe_name_hash; /* hash value of xattr prefix+suffix. */ | ||
745 | __le16 xe_name_offset; /* byte offset from the 1st etnry in the local | ||
746 | local xattr storage(inode, xattr block or | ||
747 | xattr bucket). */ | ||
748 | __u8 xe_name_len; /* xattr name len, does't include prefix. */ | ||
749 | __u8 xe_type; /* the low 7 bits indicates the name prefix's | ||
750 | * type and the highest 1 bits indicate whether | ||
751 | * the EA is stored in the local storage. */ | ||
752 | __le64 xe_value_size; /* real xattr value length. */ | ||
753 | }; | ||
754 | |||
755 | /* | ||
756 | * On disk structure for xattr header. | ||
757 | * | ||
758 | * One ocfs2_xattr_header describes how many ocfs2_xattr_entry records in | ||
759 | * the local xattr storage. | ||
760 | */ | ||
761 | struct ocfs2_xattr_header { | ||
762 | __le16 xh_count; /* contains the count of how | ||
763 | many records are in the | ||
764 | local xattr storage. */ | ||
765 | __le16 xh_free_start; /* current offset for storing | ||
766 | xattr. */ | ||
767 | __le16 xh_name_value_len; /* total length of name/value | ||
768 | length in this bucket. */ | ||
769 | __le16 xh_num_buckets; /* bucket nums in one extent | ||
770 | record, only valid in the | ||
771 | first bucket. */ | ||
772 | __le64 xh_csum; | ||
773 | struct ocfs2_xattr_entry xh_entries[0]; /* xattr entry list. */ | ||
774 | }; | ||
775 | |||
776 | /* | ||
777 | * On disk structure for xattr value root. | ||
778 | * | ||
779 | * It is used when one extended attribute's size is larger, and we will save it | ||
780 | * in an outside cluster. It will stored in a b-tree like file content. | ||
781 | */ | ||
782 | struct ocfs2_xattr_value_root { | ||
783 | /*00*/ __le32 xr_clusters; /* clusters covered by xattr value. */ | ||
784 | __le32 xr_reserved0; | ||
785 | __le64 xr_last_eb_blk; /* Pointer to last extent block */ | ||
786 | /*10*/ struct ocfs2_extent_list xr_list; /* Extent record list */ | ||
787 | }; | ||
788 | |||
789 | /* | ||
790 | * On disk structure for xattr tree root. | ||
791 | * | ||
792 | * It is used when there are too many extended attributes for one file. These | ||
793 | * attributes will be organized and stored in an indexed-btree. | ||
794 | */ | ||
795 | struct ocfs2_xattr_tree_root { | ||
796 | /*00*/ __le32 xt_clusters; /* clusters covered by xattr. */ | ||
797 | __le32 xt_reserved0; | ||
798 | __le64 xt_last_eb_blk; /* Pointer to last extent block */ | ||
799 | /*10*/ struct ocfs2_extent_list xt_list; /* Extent record list */ | ||
800 | }; | ||
801 | |||
802 | #define OCFS2_XATTR_INDEXED 0x1 | ||
803 | #define OCFS2_HASH_SHIFT 5 | ||
804 | #define OCFS2_XATTR_ROUND 3 | ||
805 | #define OCFS2_XATTR_SIZE(size) (((size) + OCFS2_XATTR_ROUND) & \ | ||
806 | ~(OCFS2_XATTR_ROUND)) | ||
807 | |||
808 | #define OCFS2_XATTR_BUCKET_SIZE 4096 | ||
809 | #define OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET (OCFS2_XATTR_BUCKET_SIZE \ | ||
810 | / OCFS2_MIN_BLOCKSIZE) | ||
811 | |||
812 | /* | ||
813 | * On disk structure for xattr block. | ||
814 | */ | ||
815 | struct ocfs2_xattr_block { | ||
816 | /*00*/ __u8 xb_signature[8]; /* Signature for verification */ | ||
817 | __le16 xb_suballoc_slot; /* Slot suballocator this | ||
818 | block belongs to. */ | ||
819 | __le16 xb_suballoc_bit; /* Bit offset in suballocator | ||
820 | block group */ | ||
821 | __le32 xb_fs_generation; /* Must match super block */ | ||
822 | /*10*/ __le64 xb_blkno; /* Offset on disk, in blocks */ | ||
823 | __le64 xb_csum; | ||
824 | /*20*/ __le16 xb_flags; /* Indicates whether this block contains | ||
825 | real xattr or a xattr tree. */ | ||
826 | __le16 xb_reserved0; | ||
827 | __le32 xb_reserved1; | ||
828 | __le64 xb_reserved2; | ||
829 | /*30*/ union { | ||
830 | struct ocfs2_xattr_header xb_header; /* xattr header if this | ||
831 | block contains xattr */ | ||
832 | struct ocfs2_xattr_tree_root xb_root;/* xattr tree root if this | ||
833 | block cotains xattr | ||
834 | tree. */ | ||
835 | } xb_attrs; | ||
836 | }; | ||
837 | |||
838 | #define OCFS2_XATTR_ENTRY_LOCAL 0x80 | ||
839 | #define OCFS2_XATTR_TYPE_MASK 0x7F | ||
840 | static inline void ocfs2_xattr_set_local(struct ocfs2_xattr_entry *xe, | ||
841 | int local) | ||
842 | { | ||
843 | if (local) | ||
844 | xe->xe_type |= OCFS2_XATTR_ENTRY_LOCAL; | ||
845 | else | ||
846 | xe->xe_type &= ~OCFS2_XATTR_ENTRY_LOCAL; | ||
847 | } | ||
848 | |||
849 | static inline int ocfs2_xattr_is_local(struct ocfs2_xattr_entry *xe) | ||
850 | { | ||
851 | return xe->xe_type & OCFS2_XATTR_ENTRY_LOCAL; | ||
852 | } | ||
853 | |||
854 | static inline void ocfs2_xattr_set_type(struct ocfs2_xattr_entry *xe, int type) | ||
855 | { | ||
856 | xe->xe_type |= type & OCFS2_XATTR_TYPE_MASK; | ||
857 | } | ||
858 | |||
859 | static inline int ocfs2_xattr_get_type(struct ocfs2_xattr_entry *xe) | ||
860 | { | ||
861 | return xe->xe_type & OCFS2_XATTR_TYPE_MASK; | ||
862 | } | ||
863 | |||
718 | #ifdef __KERNEL__ | 864 | #ifdef __KERNEL__ |
719 | static inline int ocfs2_fast_symlink_chars(struct super_block *sb) | 865 | static inline int ocfs2_fast_symlink_chars(struct super_block *sb) |
720 | { | 866 | { |
@@ -728,6 +874,20 @@ static inline int ocfs2_max_inline_data(struct super_block *sb) | |||
728 | offsetof(struct ocfs2_dinode, id2.i_data.id_data); | 874 | offsetof(struct ocfs2_dinode, id2.i_data.id_data); |
729 | } | 875 | } |
730 | 876 | ||
877 | static inline int ocfs2_max_inline_data_with_xattr(struct super_block *sb, | ||
878 | struct ocfs2_dinode *di) | ||
879 | { | ||
880 | unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size); | ||
881 | |||
882 | if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL) | ||
883 | return sb->s_blocksize - | ||
884 | offsetof(struct ocfs2_dinode, id2.i_data.id_data) - | ||
885 | xattrsize; | ||
886 | else | ||
887 | return sb->s_blocksize - | ||
888 | offsetof(struct ocfs2_dinode, id2.i_data.id_data); | ||
889 | } | ||
890 | |||
731 | static inline int ocfs2_extent_recs_per_inode(struct super_block *sb) | 891 | static inline int ocfs2_extent_recs_per_inode(struct super_block *sb) |
732 | { | 892 | { |
733 | int size; | 893 | int size; |
@@ -738,6 +898,24 @@ static inline int ocfs2_extent_recs_per_inode(struct super_block *sb) | |||
738 | return size / sizeof(struct ocfs2_extent_rec); | 898 | return size / sizeof(struct ocfs2_extent_rec); |
739 | } | 899 | } |
740 | 900 | ||
901 | static inline int ocfs2_extent_recs_per_inode_with_xattr( | ||
902 | struct super_block *sb, | ||
903 | struct ocfs2_dinode *di) | ||
904 | { | ||
905 | int size; | ||
906 | unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size); | ||
907 | |||
908 | if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL) | ||
909 | size = sb->s_blocksize - | ||
910 | offsetof(struct ocfs2_dinode, id2.i_list.l_recs) - | ||
911 | xattrsize; | ||
912 | else | ||
913 | size = sb->s_blocksize - | ||
914 | offsetof(struct ocfs2_dinode, id2.i_list.l_recs); | ||
915 | |||
916 | return size / sizeof(struct ocfs2_extent_rec); | ||
917 | } | ||
918 | |||
741 | static inline int ocfs2_chain_recs_per_inode(struct super_block *sb) | 919 | static inline int ocfs2_chain_recs_per_inode(struct super_block *sb) |
742 | { | 920 | { |
743 | int size; | 921 | int size; |
@@ -801,6 +979,17 @@ static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index) | |||
801 | return 0; | 979 | return 0; |
802 | 980 | ||
803 | } | 981 | } |
982 | |||
983 | static inline u16 ocfs2_xattr_recs_per_xb(struct super_block *sb) | ||
984 | { | ||
985 | int size; | ||
986 | |||
987 | size = sb->s_blocksize - | ||
988 | offsetof(struct ocfs2_xattr_block, | ||
989 | xb_attrs.xb_root.xt_list.l_recs); | ||
990 | |||
991 | return size / sizeof(struct ocfs2_extent_rec); | ||
992 | } | ||
804 | #else | 993 | #else |
805 | static inline int ocfs2_fast_symlink_chars(int blocksize) | 994 | static inline int ocfs2_fast_symlink_chars(int blocksize) |
806 | { | 995 | { |
@@ -884,6 +1073,17 @@ static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index) | |||
884 | 1073 | ||
885 | return 0; | 1074 | return 0; |
886 | } | 1075 | } |
1076 | |||
1077 | static inline int ocfs2_xattr_recs_per_xb(int blocksize) | ||
1078 | { | ||
1079 | int size; | ||
1080 | |||
1081 | size = blocksize - | ||
1082 | offsetof(struct ocfs2_xattr_block, | ||
1083 | xb_attrs.xb_root.xt_list.l_recs); | ||
1084 | |||
1085 | return size / sizeof(struct ocfs2_extent_rec); | ||
1086 | } | ||
887 | #endif /* __KERNEL__ */ | 1087 | #endif /* __KERNEL__ */ |
888 | 1088 | ||
889 | 1089 | ||
diff --git a/fs/ocfs2/ocfs2_jbd_compat.h b/fs/ocfs2/ocfs2_jbd_compat.h new file mode 100644 index 000000000000..b91c78f8f558 --- /dev/null +++ b/fs/ocfs2/ocfs2_jbd_compat.h | |||
@@ -0,0 +1,82 @@ | |||
1 | /* -*- mode: c; c-basic-offset: 8; -*- | ||
2 | * vim: noexpandtab sw=8 ts=8 sts=0: | ||
3 | * | ||
4 | * ocfs2_jbd_compat.h | ||
5 | * | ||
6 | * Compatibility defines for JBD. | ||
7 | * | ||
8 | * Copyright (C) 2008 Oracle. All rights reserved. | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or | ||
11 | * modify it under the terms of the GNU General Public | ||
12 | * License version 2 as published by the Free Software Foundation. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | * General Public License for more details. | ||
18 | */ | ||
19 | |||
20 | #ifndef OCFS2_JBD_COMPAT_H | ||
21 | #define OCFS2_JBD_COMPAT_H | ||
22 | |||
23 | #ifndef CONFIG_OCFS2_COMPAT_JBD | ||
24 | # error Should not have been included | ||
25 | #endif | ||
26 | |||
27 | struct jbd2_inode { | ||
28 | unsigned int dummy; | ||
29 | }; | ||
30 | |||
31 | #define JBD2_BARRIER JFS_BARRIER | ||
32 | #define JBD2_DEFAULT_MAX_COMMIT_AGE JBD_DEFAULT_MAX_COMMIT_AGE | ||
33 | |||
34 | #define jbd2_journal_ack_err journal_ack_err | ||
35 | #define jbd2_journal_clear_err journal_clear_err | ||
36 | #define jbd2_journal_destroy journal_destroy | ||
37 | #define jbd2_journal_dirty_metadata journal_dirty_metadata | ||
38 | #define jbd2_journal_errno journal_errno | ||
39 | #define jbd2_journal_extend journal_extend | ||
40 | #define jbd2_journal_flush journal_flush | ||
41 | #define jbd2_journal_force_commit journal_force_commit | ||
42 | #define jbd2_journal_get_write_access journal_get_write_access | ||
43 | #define jbd2_journal_get_undo_access journal_get_undo_access | ||
44 | #define jbd2_journal_init_inode journal_init_inode | ||
45 | #define jbd2_journal_invalidatepage journal_invalidatepage | ||
46 | #define jbd2_journal_load journal_load | ||
47 | #define jbd2_journal_lock_updates journal_lock_updates | ||
48 | #define jbd2_journal_restart journal_restart | ||
49 | #define jbd2_journal_start journal_start | ||
50 | #define jbd2_journal_start_commit journal_start_commit | ||
51 | #define jbd2_journal_stop journal_stop | ||
52 | #define jbd2_journal_try_to_free_buffers journal_try_to_free_buffers | ||
53 | #define jbd2_journal_unlock_updates journal_unlock_updates | ||
54 | #define jbd2_journal_wipe journal_wipe | ||
55 | #define jbd2_log_wait_commit log_wait_commit | ||
56 | |||
57 | static inline int jbd2_journal_file_inode(handle_t *handle, | ||
58 | struct jbd2_inode *inode) | ||
59 | { | ||
60 | return 0; | ||
61 | } | ||
62 | |||
63 | static inline int jbd2_journal_begin_ordered_truncate(struct jbd2_inode *inode, | ||
64 | loff_t new_size) | ||
65 | { | ||
66 | return 0; | ||
67 | } | ||
68 | |||
69 | static inline void jbd2_journal_init_jbd_inode(struct jbd2_inode *jinode, | ||
70 | struct inode *inode) | ||
71 | { | ||
72 | return; | ||
73 | } | ||
74 | |||
75 | static inline void jbd2_journal_release_jbd_inode(journal_t *journal, | ||
76 | struct jbd2_inode *jinode) | ||
77 | { | ||
78 | return; | ||
79 | } | ||
80 | |||
81 | |||
82 | #endif /* OCFS2_JBD_COMPAT_H */ | ||
diff --git a/fs/ocfs2/resize.c b/fs/ocfs2/resize.c index 8166968e9015..ffd48db229a7 100644 --- a/fs/ocfs2/resize.c +++ b/fs/ocfs2/resize.c | |||
@@ -200,7 +200,7 @@ static int update_backups(struct inode * inode, u32 clusters, char *data) | |||
200 | if (cluster > clusters) | 200 | if (cluster > clusters) |
201 | break; | 201 | break; |
202 | 202 | ||
203 | ret = ocfs2_read_block(osb, blkno, &backup, 0, NULL); | 203 | ret = ocfs2_read_blocks_sync(osb, blkno, 1, &backup); |
204 | if (ret < 0) { | 204 | if (ret < 0) { |
205 | mlog_errno(ret); | 205 | mlog_errno(ret); |
206 | break; | 206 | break; |
@@ -236,8 +236,8 @@ static void ocfs2_update_super_and_backups(struct inode *inode, | |||
236 | * update the superblock last. | 236 | * update the superblock last. |
237 | * It doesn't matter if the write failed. | 237 | * It doesn't matter if the write failed. |
238 | */ | 238 | */ |
239 | ret = ocfs2_read_block(osb, OCFS2_SUPER_BLOCK_BLKNO, | 239 | ret = ocfs2_read_blocks_sync(osb, OCFS2_SUPER_BLOCK_BLKNO, 1, |
240 | &super_bh, 0, NULL); | 240 | &super_bh); |
241 | if (ret < 0) { | 241 | if (ret < 0) { |
242 | mlog_errno(ret); | 242 | mlog_errno(ret); |
243 | goto out; | 243 | goto out; |
@@ -332,8 +332,7 @@ int ocfs2_group_extend(struct inode * inode, int new_clusters) | |||
332 | lgd_blkno = ocfs2_which_cluster_group(main_bm_inode, | 332 | lgd_blkno = ocfs2_which_cluster_group(main_bm_inode, |
333 | first_new_cluster - 1); | 333 | first_new_cluster - 1); |
334 | 334 | ||
335 | ret = ocfs2_read_block(osb, lgd_blkno, &group_bh, OCFS2_BH_CACHED, | 335 | ret = ocfs2_read_block(main_bm_inode, lgd_blkno, &group_bh); |
336 | main_bm_inode); | ||
337 | if (ret < 0) { | 336 | if (ret < 0) { |
338 | mlog_errno(ret); | 337 | mlog_errno(ret); |
339 | goto out_unlock; | 338 | goto out_unlock; |
@@ -540,7 +539,7 @@ int ocfs2_group_add(struct inode *inode, struct ocfs2_new_group_input *input) | |||
540 | goto out_unlock; | 539 | goto out_unlock; |
541 | } | 540 | } |
542 | 541 | ||
543 | ret = ocfs2_read_block(osb, input->group, &group_bh, 0, NULL); | 542 | ret = ocfs2_read_blocks_sync(osb, input->group, 1, &group_bh); |
544 | if (ret < 0) { | 543 | if (ret < 0) { |
545 | mlog(ML_ERROR, "Can't read the group descriptor # %llu " | 544 | mlog(ML_ERROR, "Can't read the group descriptor # %llu " |
546 | "from the device.", (unsigned long long)input->group); | 545 | "from the device.", (unsigned long long)input->group); |
diff --git a/fs/ocfs2/slot_map.c b/fs/ocfs2/slot_map.c index bb5ff8939bf1..bdda2d8f8508 100644 --- a/fs/ocfs2/slot_map.c +++ b/fs/ocfs2/slot_map.c | |||
@@ -150,8 +150,8 @@ int ocfs2_refresh_slot_info(struct ocfs2_super *osb) | |||
150 | * be !NULL. Thus, ocfs2_read_blocks() will ignore blocknr. If | 150 | * be !NULL. Thus, ocfs2_read_blocks() will ignore blocknr. If |
151 | * this is not true, the read of -1 (UINT64_MAX) will fail. | 151 | * this is not true, the read of -1 (UINT64_MAX) will fail. |
152 | */ | 152 | */ |
153 | ret = ocfs2_read_blocks(osb, -1, si->si_blocks, si->si_bh, 0, | 153 | ret = ocfs2_read_blocks(si->si_inode, -1, si->si_blocks, si->si_bh, |
154 | si->si_inode); | 154 | OCFS2_BH_IGNORE_CACHE); |
155 | if (ret == 0) { | 155 | if (ret == 0) { |
156 | spin_lock(&osb->osb_lock); | 156 | spin_lock(&osb->osb_lock); |
157 | ocfs2_update_slot_info(si); | 157 | ocfs2_update_slot_info(si); |
@@ -404,7 +404,8 @@ static int ocfs2_map_slot_buffers(struct ocfs2_super *osb, | |||
404 | (unsigned long long)blkno); | 404 | (unsigned long long)blkno); |
405 | 405 | ||
406 | bh = NULL; /* Acquire a fresh bh */ | 406 | bh = NULL; /* Acquire a fresh bh */ |
407 | status = ocfs2_read_block(osb, blkno, &bh, 0, si->si_inode); | 407 | status = ocfs2_read_blocks(si->si_inode, blkno, 1, &bh, |
408 | OCFS2_BH_IGNORE_CACHE); | ||
408 | if (status < 0) { | 409 | if (status < 0) { |
409 | mlog_errno(status); | 410 | mlog_errno(status); |
410 | goto bail; | 411 | goto bail; |
diff --git a/fs/ocfs2/stack_user.c b/fs/ocfs2/stack_user.c index 353fc35c6748..faec2d879357 100644 --- a/fs/ocfs2/stack_user.c +++ b/fs/ocfs2/stack_user.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include "ocfs2.h" /* For struct ocfs2_lock_res */ | 28 | #include "ocfs2.h" /* For struct ocfs2_lock_res */ |
29 | #include "stackglue.h" | 29 | #include "stackglue.h" |
30 | 30 | ||
31 | #include <linux/dlm_plock.h> | ||
31 | 32 | ||
32 | /* | 33 | /* |
33 | * The control protocol starts with a handshake. Until the handshake | 34 | * The control protocol starts with a handshake. Until the handshake |
@@ -746,6 +747,37 @@ static void user_dlm_dump_lksb(union ocfs2_dlm_lksb *lksb) | |||
746 | { | 747 | { |
747 | } | 748 | } |
748 | 749 | ||
750 | static int user_plock(struct ocfs2_cluster_connection *conn, | ||
751 | u64 ino, | ||
752 | struct file *file, | ||
753 | int cmd, | ||
754 | struct file_lock *fl) | ||
755 | { | ||
756 | /* | ||
757 | * This more or less just demuxes the plock request into any | ||
758 | * one of three dlm calls. | ||
759 | * | ||
760 | * Internally, fs/dlm will pass these to a misc device, which | ||
761 | * a userspace daemon will read and write to. | ||
762 | * | ||
763 | * For now, cancel requests (which happen internally only), | ||
764 | * are turned into unlocks. Most of this function taken from | ||
765 | * gfs2_lock. | ||
766 | */ | ||
767 | |||
768 | if (cmd == F_CANCELLK) { | ||
769 | cmd = F_SETLK; | ||
770 | fl->fl_type = F_UNLCK; | ||
771 | } | ||
772 | |||
773 | if (IS_GETLK(cmd)) | ||
774 | return dlm_posix_get(conn->cc_lockspace, ino, file, fl); | ||
775 | else if (fl->fl_type == F_UNLCK) | ||
776 | return dlm_posix_unlock(conn->cc_lockspace, ino, file, fl); | ||
777 | else | ||
778 | return dlm_posix_lock(conn->cc_lockspace, ino, file, cmd, fl); | ||
779 | } | ||
780 | |||
749 | /* | 781 | /* |
750 | * Compare a requested locking protocol version against the current one. | 782 | * Compare a requested locking protocol version against the current one. |
751 | * | 783 | * |
@@ -839,6 +871,7 @@ static struct ocfs2_stack_operations ocfs2_user_plugin_ops = { | |||
839 | .dlm_unlock = user_dlm_unlock, | 871 | .dlm_unlock = user_dlm_unlock, |
840 | .lock_status = user_dlm_lock_status, | 872 | .lock_status = user_dlm_lock_status, |
841 | .lock_lvb = user_dlm_lvb, | 873 | .lock_lvb = user_dlm_lvb, |
874 | .plock = user_plock, | ||
842 | .dump_lksb = user_dlm_dump_lksb, | 875 | .dump_lksb = user_dlm_dump_lksb, |
843 | }; | 876 | }; |
844 | 877 | ||
diff --git a/fs/ocfs2/stackglue.c b/fs/ocfs2/stackglue.c index 07f348b8d721..68b668b0e60a 100644 --- a/fs/ocfs2/stackglue.c +++ b/fs/ocfs2/stackglue.c | |||
@@ -288,6 +288,26 @@ void ocfs2_dlm_dump_lksb(union ocfs2_dlm_lksb *lksb) | |||
288 | } | 288 | } |
289 | EXPORT_SYMBOL_GPL(ocfs2_dlm_dump_lksb); | 289 | EXPORT_SYMBOL_GPL(ocfs2_dlm_dump_lksb); |
290 | 290 | ||
291 | int ocfs2_stack_supports_plocks(void) | ||
292 | { | ||
293 | return active_stack && active_stack->sp_ops->plock; | ||
294 | } | ||
295 | EXPORT_SYMBOL_GPL(ocfs2_stack_supports_plocks); | ||
296 | |||
297 | /* | ||
298 | * ocfs2_plock() can only be safely called if | ||
299 | * ocfs2_stack_supports_plocks() returned true | ||
300 | */ | ||
301 | int ocfs2_plock(struct ocfs2_cluster_connection *conn, u64 ino, | ||
302 | struct file *file, int cmd, struct file_lock *fl) | ||
303 | { | ||
304 | WARN_ON_ONCE(active_stack->sp_ops->plock == NULL); | ||
305 | if (active_stack->sp_ops->plock) | ||
306 | return active_stack->sp_ops->plock(conn, ino, file, cmd, fl); | ||
307 | return -EOPNOTSUPP; | ||
308 | } | ||
309 | EXPORT_SYMBOL_GPL(ocfs2_plock); | ||
310 | |||
291 | int ocfs2_cluster_connect(const char *stack_name, | 311 | int ocfs2_cluster_connect(const char *stack_name, |
292 | const char *group, | 312 | const char *group, |
293 | int grouplen, | 313 | int grouplen, |
diff --git a/fs/ocfs2/stackglue.h b/fs/ocfs2/stackglue.h index db56281dd1be..c571af375ef8 100644 --- a/fs/ocfs2/stackglue.h +++ b/fs/ocfs2/stackglue.h | |||
@@ -28,6 +28,10 @@ | |||
28 | #include "dlm/dlmapi.h" | 28 | #include "dlm/dlmapi.h" |
29 | #include <linux/dlm.h> | 29 | #include <linux/dlm.h> |
30 | 30 | ||
31 | /* Needed for plock-related prototypes */ | ||
32 | struct file; | ||
33 | struct file_lock; | ||
34 | |||
31 | /* | 35 | /* |
32 | * dlmconstants.h does not have a LOCAL flag. We hope to remove it | 36 | * dlmconstants.h does not have a LOCAL flag. We hope to remove it |
33 | * some day, but right now we need it. Let's fake it. This value is larger | 37 | * some day, but right now we need it. Let's fake it. This value is larger |
@@ -187,6 +191,17 @@ struct ocfs2_stack_operations { | |||
187 | void *(*lock_lvb)(union ocfs2_dlm_lksb *lksb); | 191 | void *(*lock_lvb)(union ocfs2_dlm_lksb *lksb); |
188 | 192 | ||
189 | /* | 193 | /* |
194 | * Cluster-aware posix locks | ||
195 | * | ||
196 | * This is NULL for stacks which do not support posix locks. | ||
197 | */ | ||
198 | int (*plock)(struct ocfs2_cluster_connection *conn, | ||
199 | u64 ino, | ||
200 | struct file *file, | ||
201 | int cmd, | ||
202 | struct file_lock *fl); | ||
203 | |||
204 | /* | ||
190 | * This is an optoinal debugging hook. If provided, the | 205 | * This is an optoinal debugging hook. If provided, the |
191 | * stack can dump debugging information about this lock. | 206 | * stack can dump debugging information about this lock. |
192 | */ | 207 | */ |
@@ -240,6 +255,10 @@ int ocfs2_dlm_lock_status(union ocfs2_dlm_lksb *lksb); | |||
240 | void *ocfs2_dlm_lvb(union ocfs2_dlm_lksb *lksb); | 255 | void *ocfs2_dlm_lvb(union ocfs2_dlm_lksb *lksb); |
241 | void ocfs2_dlm_dump_lksb(union ocfs2_dlm_lksb *lksb); | 256 | void ocfs2_dlm_dump_lksb(union ocfs2_dlm_lksb *lksb); |
242 | 257 | ||
258 | int ocfs2_stack_supports_plocks(void); | ||
259 | int ocfs2_plock(struct ocfs2_cluster_connection *conn, u64 ino, | ||
260 | struct file *file, int cmd, struct file_lock *fl); | ||
261 | |||
243 | void ocfs2_stack_glue_set_locking_protocol(struct ocfs2_locking_protocol *proto); | 262 | void ocfs2_stack_glue_set_locking_protocol(struct ocfs2_locking_protocol *proto); |
244 | 263 | ||
245 | 264 | ||
diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c index d2d278fb9819..c5ff18b46b57 100644 --- a/fs/ocfs2/suballoc.c +++ b/fs/ocfs2/suballoc.c | |||
@@ -62,15 +62,18 @@ static int ocfs2_block_group_fill(handle_t *handle, | |||
62 | struct ocfs2_chain_list *cl); | 62 | struct ocfs2_chain_list *cl); |
63 | static int ocfs2_block_group_alloc(struct ocfs2_super *osb, | 63 | static int ocfs2_block_group_alloc(struct ocfs2_super *osb, |
64 | struct inode *alloc_inode, | 64 | struct inode *alloc_inode, |
65 | struct buffer_head *bh); | 65 | struct buffer_head *bh, |
66 | u64 max_block); | ||
66 | 67 | ||
67 | static int ocfs2_cluster_group_search(struct inode *inode, | 68 | static int ocfs2_cluster_group_search(struct inode *inode, |
68 | struct buffer_head *group_bh, | 69 | struct buffer_head *group_bh, |
69 | u32 bits_wanted, u32 min_bits, | 70 | u32 bits_wanted, u32 min_bits, |
71 | u64 max_block, | ||
70 | u16 *bit_off, u16 *bits_found); | 72 | u16 *bit_off, u16 *bits_found); |
71 | static int ocfs2_block_group_search(struct inode *inode, | 73 | static int ocfs2_block_group_search(struct inode *inode, |
72 | struct buffer_head *group_bh, | 74 | struct buffer_head *group_bh, |
73 | u32 bits_wanted, u32 min_bits, | 75 | u32 bits_wanted, u32 min_bits, |
76 | u64 max_block, | ||
74 | u16 *bit_off, u16 *bits_found); | 77 | u16 *bit_off, u16 *bits_found); |
75 | static int ocfs2_claim_suballoc_bits(struct ocfs2_super *osb, | 78 | static int ocfs2_claim_suballoc_bits(struct ocfs2_super *osb, |
76 | struct ocfs2_alloc_context *ac, | 79 | struct ocfs2_alloc_context *ac, |
@@ -110,8 +113,11 @@ static inline void ocfs2_block_to_cluster_group(struct inode *inode, | |||
110 | u64 data_blkno, | 113 | u64 data_blkno, |
111 | u64 *bg_blkno, | 114 | u64 *bg_blkno, |
112 | u16 *bg_bit_off); | 115 | u16 *bg_bit_off); |
116 | static int ocfs2_reserve_clusters_with_limit(struct ocfs2_super *osb, | ||
117 | u32 bits_wanted, u64 max_block, | ||
118 | struct ocfs2_alloc_context **ac); | ||
113 | 119 | ||
114 | static void ocfs2_free_ac_resource(struct ocfs2_alloc_context *ac) | 120 | void ocfs2_free_ac_resource(struct ocfs2_alloc_context *ac) |
115 | { | 121 | { |
116 | struct inode *inode = ac->ac_inode; | 122 | struct inode *inode = ac->ac_inode; |
117 | 123 | ||
@@ -124,10 +130,8 @@ static void ocfs2_free_ac_resource(struct ocfs2_alloc_context *ac) | |||
124 | iput(inode); | 130 | iput(inode); |
125 | ac->ac_inode = NULL; | 131 | ac->ac_inode = NULL; |
126 | } | 132 | } |
127 | if (ac->ac_bh) { | 133 | brelse(ac->ac_bh); |
128 | brelse(ac->ac_bh); | 134 | ac->ac_bh = NULL; |
129 | ac->ac_bh = NULL; | ||
130 | } | ||
131 | } | 135 | } |
132 | 136 | ||
133 | void ocfs2_free_alloc_context(struct ocfs2_alloc_context *ac) | 137 | void ocfs2_free_alloc_context(struct ocfs2_alloc_context *ac) |
@@ -276,7 +280,8 @@ static inline u16 ocfs2_find_smallest_chain(struct ocfs2_chain_list *cl) | |||
276 | */ | 280 | */ |
277 | static int ocfs2_block_group_alloc(struct ocfs2_super *osb, | 281 | static int ocfs2_block_group_alloc(struct ocfs2_super *osb, |
278 | struct inode *alloc_inode, | 282 | struct inode *alloc_inode, |
279 | struct buffer_head *bh) | 283 | struct buffer_head *bh, |
284 | u64 max_block) | ||
280 | { | 285 | { |
281 | int status, credits; | 286 | int status, credits; |
282 | struct ocfs2_dinode *fe = (struct ocfs2_dinode *) bh->b_data; | 287 | struct ocfs2_dinode *fe = (struct ocfs2_dinode *) bh->b_data; |
@@ -294,9 +299,9 @@ static int ocfs2_block_group_alloc(struct ocfs2_super *osb, | |||
294 | mlog_entry_void(); | 299 | mlog_entry_void(); |
295 | 300 | ||
296 | cl = &fe->id2.i_chain; | 301 | cl = &fe->id2.i_chain; |
297 | status = ocfs2_reserve_clusters(osb, | 302 | status = ocfs2_reserve_clusters_with_limit(osb, |
298 | le16_to_cpu(cl->cl_cpg), | 303 | le16_to_cpu(cl->cl_cpg), |
299 | &ac); | 304 | max_block, &ac); |
300 | if (status < 0) { | 305 | if (status < 0) { |
301 | if (status != -ENOSPC) | 306 | if (status != -ENOSPC) |
302 | mlog_errno(status); | 307 | mlog_errno(status); |
@@ -394,8 +399,7 @@ bail: | |||
394 | if (ac) | 399 | if (ac) |
395 | ocfs2_free_alloc_context(ac); | 400 | ocfs2_free_alloc_context(ac); |
396 | 401 | ||
397 | if (bg_bh) | 402 | brelse(bg_bh); |
398 | brelse(bg_bh); | ||
399 | 403 | ||
400 | mlog_exit(status); | 404 | mlog_exit(status); |
401 | return status; | 405 | return status; |
@@ -469,7 +473,8 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb, | |||
469 | goto bail; | 473 | goto bail; |
470 | } | 474 | } |
471 | 475 | ||
472 | status = ocfs2_block_group_alloc(osb, alloc_inode, bh); | 476 | status = ocfs2_block_group_alloc(osb, alloc_inode, bh, |
477 | ac->ac_max_block); | ||
473 | if (status < 0) { | 478 | if (status < 0) { |
474 | if (status != -ENOSPC) | 479 | if (status != -ENOSPC) |
475 | mlog_errno(status); | 480 | mlog_errno(status); |
@@ -486,16 +491,15 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb, | |||
486 | get_bh(bh); | 491 | get_bh(bh); |
487 | ac->ac_bh = bh; | 492 | ac->ac_bh = bh; |
488 | bail: | 493 | bail: |
489 | if (bh) | 494 | brelse(bh); |
490 | brelse(bh); | ||
491 | 495 | ||
492 | mlog_exit(status); | 496 | mlog_exit(status); |
493 | return status; | 497 | return status; |
494 | } | 498 | } |
495 | 499 | ||
496 | int ocfs2_reserve_new_metadata(struct ocfs2_super *osb, | 500 | int ocfs2_reserve_new_metadata_blocks(struct ocfs2_super *osb, |
497 | struct ocfs2_dinode *fe, | 501 | int blocks, |
498 | struct ocfs2_alloc_context **ac) | 502 | struct ocfs2_alloc_context **ac) |
499 | { | 503 | { |
500 | int status; | 504 | int status; |
501 | u32 slot; | 505 | u32 slot; |
@@ -507,7 +511,7 @@ int ocfs2_reserve_new_metadata(struct ocfs2_super *osb, | |||
507 | goto bail; | 511 | goto bail; |
508 | } | 512 | } |
509 | 513 | ||
510 | (*ac)->ac_bits_wanted = ocfs2_extend_meta_needed(fe); | 514 | (*ac)->ac_bits_wanted = blocks; |
511 | (*ac)->ac_which = OCFS2_AC_USE_META; | 515 | (*ac)->ac_which = OCFS2_AC_USE_META; |
512 | slot = osb->slot_num; | 516 | slot = osb->slot_num; |
513 | (*ac)->ac_group_search = ocfs2_block_group_search; | 517 | (*ac)->ac_group_search = ocfs2_block_group_search; |
@@ -532,6 +536,15 @@ bail: | |||
532 | return status; | 536 | return status; |
533 | } | 537 | } |
534 | 538 | ||
539 | int ocfs2_reserve_new_metadata(struct ocfs2_super *osb, | ||
540 | struct ocfs2_extent_list *root_el, | ||
541 | struct ocfs2_alloc_context **ac) | ||
542 | { | ||
543 | return ocfs2_reserve_new_metadata_blocks(osb, | ||
544 | ocfs2_extend_meta_needed(root_el), | ||
545 | ac); | ||
546 | } | ||
547 | |||
535 | static int ocfs2_steal_inode_from_other_nodes(struct ocfs2_super *osb, | 548 | static int ocfs2_steal_inode_from_other_nodes(struct ocfs2_super *osb, |
536 | struct ocfs2_alloc_context *ac) | 549 | struct ocfs2_alloc_context *ac) |
537 | { | 550 | { |
@@ -582,6 +595,14 @@ int ocfs2_reserve_new_inode(struct ocfs2_super *osb, | |||
582 | (*ac)->ac_group_search = ocfs2_block_group_search; | 595 | (*ac)->ac_group_search = ocfs2_block_group_search; |
583 | 596 | ||
584 | /* | 597 | /* |
598 | * stat(2) can't handle i_ino > 32bits, so we tell the | ||
599 | * lower levels not to allocate us a block group past that | ||
600 | * limit. The 'inode64' mount option avoids this behavior. | ||
601 | */ | ||
602 | if (!(osb->s_mount_opt & OCFS2_MOUNT_INODE64)) | ||
603 | (*ac)->ac_max_block = (u32)~0U; | ||
604 | |||
605 | /* | ||
585 | * slot is set when we successfully steal inode from other nodes. | 606 | * slot is set when we successfully steal inode from other nodes. |
586 | * It is reset in 3 places: | 607 | * It is reset in 3 places: |
587 | * 1. when we flush the truncate log | 608 | * 1. when we flush the truncate log |
@@ -661,9 +682,9 @@ bail: | |||
661 | /* Callers don't need to care which bitmap (local alloc or main) to | 682 | /* Callers don't need to care which bitmap (local alloc or main) to |
662 | * use so we figure it out for them, but unfortunately this clutters | 683 | * use so we figure it out for them, but unfortunately this clutters |
663 | * things a bit. */ | 684 | * things a bit. */ |
664 | int ocfs2_reserve_clusters(struct ocfs2_super *osb, | 685 | static int ocfs2_reserve_clusters_with_limit(struct ocfs2_super *osb, |
665 | u32 bits_wanted, | 686 | u32 bits_wanted, u64 max_block, |
666 | struct ocfs2_alloc_context **ac) | 687 | struct ocfs2_alloc_context **ac) |
667 | { | 688 | { |
668 | int status; | 689 | int status; |
669 | 690 | ||
@@ -677,24 +698,20 @@ int ocfs2_reserve_clusters(struct ocfs2_super *osb, | |||
677 | } | 698 | } |
678 | 699 | ||
679 | (*ac)->ac_bits_wanted = bits_wanted; | 700 | (*ac)->ac_bits_wanted = bits_wanted; |
701 | (*ac)->ac_max_block = max_block; | ||
680 | 702 | ||
681 | status = -ENOSPC; | 703 | status = -ENOSPC; |
682 | if (ocfs2_alloc_should_use_local(osb, bits_wanted)) { | 704 | if (ocfs2_alloc_should_use_local(osb, bits_wanted)) { |
683 | status = ocfs2_reserve_local_alloc_bits(osb, | 705 | status = ocfs2_reserve_local_alloc_bits(osb, |
684 | bits_wanted, | 706 | bits_wanted, |
685 | *ac); | 707 | *ac); |
686 | if ((status < 0) && (status != -ENOSPC)) { | 708 | if (status == -EFBIG) { |
709 | /* The local alloc window is outside ac_max_block. | ||
710 | * use the main bitmap. */ | ||
711 | status = -ENOSPC; | ||
712 | } else if ((status < 0) && (status != -ENOSPC)) { | ||
687 | mlog_errno(status); | 713 | mlog_errno(status); |
688 | goto bail; | 714 | goto bail; |
689 | } else if (status == -ENOSPC) { | ||
690 | /* reserve_local_bits will return enospc with | ||
691 | * the local alloc inode still locked, so we | ||
692 | * can change this safely here. */ | ||
693 | mlog(0, "Disabling local alloc\n"); | ||
694 | /* We set to OCFS2_LA_DISABLED so that umount | ||
695 | * can clean up what's left of the local | ||
696 | * allocation */ | ||
697 | osb->local_alloc_state = OCFS2_LA_DISABLED; | ||
698 | } | 715 | } |
699 | } | 716 | } |
700 | 717 | ||
@@ -718,6 +735,13 @@ bail: | |||
718 | return status; | 735 | return status; |
719 | } | 736 | } |
720 | 737 | ||
738 | int ocfs2_reserve_clusters(struct ocfs2_super *osb, | ||
739 | u32 bits_wanted, | ||
740 | struct ocfs2_alloc_context **ac) | ||
741 | { | ||
742 | return ocfs2_reserve_clusters_with_limit(osb, bits_wanted, 0, ac); | ||
743 | } | ||
744 | |||
721 | /* | 745 | /* |
722 | * More or less lifted from ext3. I'll leave their description below: | 746 | * More or less lifted from ext3. I'll leave their description below: |
723 | * | 747 | * |
@@ -1000,11 +1024,14 @@ static inline int ocfs2_block_group_reasonably_empty(struct ocfs2_group_desc *bg | |||
1000 | static int ocfs2_cluster_group_search(struct inode *inode, | 1024 | static int ocfs2_cluster_group_search(struct inode *inode, |
1001 | struct buffer_head *group_bh, | 1025 | struct buffer_head *group_bh, |
1002 | u32 bits_wanted, u32 min_bits, | 1026 | u32 bits_wanted, u32 min_bits, |
1027 | u64 max_block, | ||
1003 | u16 *bit_off, u16 *bits_found) | 1028 | u16 *bit_off, u16 *bits_found) |
1004 | { | 1029 | { |
1005 | int search = -ENOSPC; | 1030 | int search = -ENOSPC; |
1006 | int ret; | 1031 | int ret; |
1032 | u64 blkoff; | ||
1007 | struct ocfs2_group_desc *gd = (struct ocfs2_group_desc *) group_bh->b_data; | 1033 | struct ocfs2_group_desc *gd = (struct ocfs2_group_desc *) group_bh->b_data; |
1034 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
1008 | u16 tmp_off, tmp_found; | 1035 | u16 tmp_off, tmp_found; |
1009 | unsigned int max_bits, gd_cluster_off; | 1036 | unsigned int max_bits, gd_cluster_off; |
1010 | 1037 | ||
@@ -1037,6 +1064,17 @@ static int ocfs2_cluster_group_search(struct inode *inode, | |||
1037 | if (ret) | 1064 | if (ret) |
1038 | return ret; | 1065 | return ret; |
1039 | 1066 | ||
1067 | if (max_block) { | ||
1068 | blkoff = ocfs2_clusters_to_blocks(inode->i_sb, | ||
1069 | gd_cluster_off + | ||
1070 | tmp_off + tmp_found); | ||
1071 | mlog(0, "Checking %llu against %llu\n", | ||
1072 | (unsigned long long)blkoff, | ||
1073 | (unsigned long long)max_block); | ||
1074 | if (blkoff > max_block) | ||
1075 | return -ENOSPC; | ||
1076 | } | ||
1077 | |||
1040 | /* ocfs2_block_group_find_clear_bits() might | 1078 | /* ocfs2_block_group_find_clear_bits() might |
1041 | * return success, but we still want to return | 1079 | * return success, but we still want to return |
1042 | * -ENOSPC unless it found the minimum number | 1080 | * -ENOSPC unless it found the minimum number |
@@ -1045,6 +1083,12 @@ static int ocfs2_cluster_group_search(struct inode *inode, | |||
1045 | *bit_off = tmp_off; | 1083 | *bit_off = tmp_off; |
1046 | *bits_found = tmp_found; | 1084 | *bits_found = tmp_found; |
1047 | search = 0; /* success */ | 1085 | search = 0; /* success */ |
1086 | } else if (tmp_found) { | ||
1087 | /* | ||
1088 | * Don't show bits which we'll be returning | ||
1089 | * for allocation to the local alloc bitmap. | ||
1090 | */ | ||
1091 | ocfs2_local_alloc_seen_free_bits(osb, tmp_found); | ||
1048 | } | 1092 | } |
1049 | } | 1093 | } |
1050 | 1094 | ||
@@ -1054,19 +1098,31 @@ static int ocfs2_cluster_group_search(struct inode *inode, | |||
1054 | static int ocfs2_block_group_search(struct inode *inode, | 1098 | static int ocfs2_block_group_search(struct inode *inode, |
1055 | struct buffer_head *group_bh, | 1099 | struct buffer_head *group_bh, |
1056 | u32 bits_wanted, u32 min_bits, | 1100 | u32 bits_wanted, u32 min_bits, |
1101 | u64 max_block, | ||
1057 | u16 *bit_off, u16 *bits_found) | 1102 | u16 *bit_off, u16 *bits_found) |
1058 | { | 1103 | { |
1059 | int ret = -ENOSPC; | 1104 | int ret = -ENOSPC; |
1105 | u64 blkoff; | ||
1060 | struct ocfs2_group_desc *bg = (struct ocfs2_group_desc *) group_bh->b_data; | 1106 | struct ocfs2_group_desc *bg = (struct ocfs2_group_desc *) group_bh->b_data; |
1061 | 1107 | ||
1062 | BUG_ON(min_bits != 1); | 1108 | BUG_ON(min_bits != 1); |
1063 | BUG_ON(ocfs2_is_cluster_bitmap(inode)); | 1109 | BUG_ON(ocfs2_is_cluster_bitmap(inode)); |
1064 | 1110 | ||
1065 | if (bg->bg_free_bits_count) | 1111 | if (bg->bg_free_bits_count) { |
1066 | ret = ocfs2_block_group_find_clear_bits(OCFS2_SB(inode->i_sb), | 1112 | ret = ocfs2_block_group_find_clear_bits(OCFS2_SB(inode->i_sb), |
1067 | group_bh, bits_wanted, | 1113 | group_bh, bits_wanted, |
1068 | le16_to_cpu(bg->bg_bits), | 1114 | le16_to_cpu(bg->bg_bits), |
1069 | bit_off, bits_found); | 1115 | bit_off, bits_found); |
1116 | if (!ret && max_block) { | ||
1117 | blkoff = le64_to_cpu(bg->bg_blkno) + *bit_off + | ||
1118 | *bits_found; | ||
1119 | mlog(0, "Checking %llu against %llu\n", | ||
1120 | (unsigned long long)blkoff, | ||
1121 | (unsigned long long)max_block); | ||
1122 | if (blkoff > max_block) | ||
1123 | ret = -ENOSPC; | ||
1124 | } | ||
1125 | } | ||
1070 | 1126 | ||
1071 | return ret; | 1127 | return ret; |
1072 | } | 1128 | } |
@@ -1116,8 +1172,7 @@ static int ocfs2_search_one_group(struct ocfs2_alloc_context *ac, | |||
1116 | struct ocfs2_group_desc *gd; | 1172 | struct ocfs2_group_desc *gd; |
1117 | struct inode *alloc_inode = ac->ac_inode; | 1173 | struct inode *alloc_inode = ac->ac_inode; |
1118 | 1174 | ||
1119 | ret = ocfs2_read_block(OCFS2_SB(alloc_inode->i_sb), gd_blkno, | 1175 | ret = ocfs2_read_block(alloc_inode, gd_blkno, &group_bh); |
1120 | &group_bh, OCFS2_BH_CACHED, alloc_inode); | ||
1121 | if (ret < 0) { | 1176 | if (ret < 0) { |
1122 | mlog_errno(ret); | 1177 | mlog_errno(ret); |
1123 | return ret; | 1178 | return ret; |
@@ -1131,7 +1186,7 @@ static int ocfs2_search_one_group(struct ocfs2_alloc_context *ac, | |||
1131 | } | 1186 | } |
1132 | 1187 | ||
1133 | ret = ac->ac_group_search(alloc_inode, group_bh, bits_wanted, min_bits, | 1188 | ret = ac->ac_group_search(alloc_inode, group_bh, bits_wanted, min_bits, |
1134 | bit_off, &found); | 1189 | ac->ac_max_block, bit_off, &found); |
1135 | if (ret < 0) { | 1190 | if (ret < 0) { |
1136 | if (ret != -ENOSPC) | 1191 | if (ret != -ENOSPC) |
1137 | mlog_errno(ret); | 1192 | mlog_errno(ret); |
@@ -1186,9 +1241,9 @@ static int ocfs2_search_chain(struct ocfs2_alloc_context *ac, | |||
1186 | bits_wanted, chain, | 1241 | bits_wanted, chain, |
1187 | (unsigned long long)OCFS2_I(alloc_inode)->ip_blkno); | 1242 | (unsigned long long)OCFS2_I(alloc_inode)->ip_blkno); |
1188 | 1243 | ||
1189 | status = ocfs2_read_block(OCFS2_SB(alloc_inode->i_sb), | 1244 | status = ocfs2_read_block(alloc_inode, |
1190 | le64_to_cpu(cl->cl_recs[chain].c_blkno), | 1245 | le64_to_cpu(cl->cl_recs[chain].c_blkno), |
1191 | &group_bh, OCFS2_BH_CACHED, alloc_inode); | 1246 | &group_bh); |
1192 | if (status < 0) { | 1247 | if (status < 0) { |
1193 | mlog_errno(status); | 1248 | mlog_errno(status); |
1194 | goto bail; | 1249 | goto bail; |
@@ -1204,21 +1259,20 @@ static int ocfs2_search_chain(struct ocfs2_alloc_context *ac, | |||
1204 | /* for now, the chain search is a bit simplistic. We just use | 1259 | /* for now, the chain search is a bit simplistic. We just use |
1205 | * the 1st group with any empty bits. */ | 1260 | * the 1st group with any empty bits. */ |
1206 | while ((status = ac->ac_group_search(alloc_inode, group_bh, | 1261 | while ((status = ac->ac_group_search(alloc_inode, group_bh, |
1207 | bits_wanted, min_bits, bit_off, | 1262 | bits_wanted, min_bits, |
1263 | ac->ac_max_block, bit_off, | ||
1208 | &tmp_bits)) == -ENOSPC) { | 1264 | &tmp_bits)) == -ENOSPC) { |
1209 | if (!bg->bg_next_group) | 1265 | if (!bg->bg_next_group) |
1210 | break; | 1266 | break; |
1211 | 1267 | ||
1212 | if (prev_group_bh) { | 1268 | brelse(prev_group_bh); |
1213 | brelse(prev_group_bh); | 1269 | prev_group_bh = NULL; |
1214 | prev_group_bh = NULL; | 1270 | |
1215 | } | ||
1216 | next_group = le64_to_cpu(bg->bg_next_group); | 1271 | next_group = le64_to_cpu(bg->bg_next_group); |
1217 | prev_group_bh = group_bh; | 1272 | prev_group_bh = group_bh; |
1218 | group_bh = NULL; | 1273 | group_bh = NULL; |
1219 | status = ocfs2_read_block(OCFS2_SB(alloc_inode->i_sb), | 1274 | status = ocfs2_read_block(alloc_inode, |
1220 | next_group, &group_bh, | 1275 | next_group, &group_bh); |
1221 | OCFS2_BH_CACHED, alloc_inode); | ||
1222 | if (status < 0) { | 1276 | if (status < 0) { |
1223 | mlog_errno(status); | 1277 | mlog_errno(status); |
1224 | goto bail; | 1278 | goto bail; |
@@ -1307,10 +1361,8 @@ static int ocfs2_search_chain(struct ocfs2_alloc_context *ac, | |||
1307 | *bg_blkno = le64_to_cpu(bg->bg_blkno); | 1361 | *bg_blkno = le64_to_cpu(bg->bg_blkno); |
1308 | *bits_left = le16_to_cpu(bg->bg_free_bits_count); | 1362 | *bits_left = le16_to_cpu(bg->bg_free_bits_count); |
1309 | bail: | 1363 | bail: |
1310 | if (group_bh) | 1364 | brelse(group_bh); |
1311 | brelse(group_bh); | 1365 | brelse(prev_group_bh); |
1312 | if (prev_group_bh) | ||
1313 | brelse(prev_group_bh); | ||
1314 | 1366 | ||
1315 | mlog_exit(status); | 1367 | mlog_exit(status); |
1316 | return status; | 1368 | return status; |
@@ -1723,7 +1775,6 @@ int ocfs2_free_suballoc_bits(handle_t *handle, | |||
1723 | { | 1775 | { |
1724 | int status = 0; | 1776 | int status = 0; |
1725 | u32 tmp_used; | 1777 | u32 tmp_used; |
1726 | struct ocfs2_super *osb = OCFS2_SB(alloc_inode->i_sb); | ||
1727 | struct ocfs2_dinode *fe = (struct ocfs2_dinode *) alloc_bh->b_data; | 1778 | struct ocfs2_dinode *fe = (struct ocfs2_dinode *) alloc_bh->b_data; |
1728 | struct ocfs2_chain_list *cl = &fe->id2.i_chain; | 1779 | struct ocfs2_chain_list *cl = &fe->id2.i_chain; |
1729 | struct buffer_head *group_bh = NULL; | 1780 | struct buffer_head *group_bh = NULL; |
@@ -1742,8 +1793,7 @@ int ocfs2_free_suballoc_bits(handle_t *handle, | |||
1742 | (unsigned long long)OCFS2_I(alloc_inode)->ip_blkno, count, | 1793 | (unsigned long long)OCFS2_I(alloc_inode)->ip_blkno, count, |
1743 | (unsigned long long)bg_blkno, start_bit); | 1794 | (unsigned long long)bg_blkno, start_bit); |
1744 | 1795 | ||
1745 | status = ocfs2_read_block(osb, bg_blkno, &group_bh, OCFS2_BH_CACHED, | 1796 | status = ocfs2_read_block(alloc_inode, bg_blkno, &group_bh); |
1746 | alloc_inode); | ||
1747 | if (status < 0) { | 1797 | if (status < 0) { |
1748 | mlog_errno(status); | 1798 | mlog_errno(status); |
1749 | goto bail; | 1799 | goto bail; |
@@ -1784,8 +1834,7 @@ int ocfs2_free_suballoc_bits(handle_t *handle, | |||
1784 | } | 1834 | } |
1785 | 1835 | ||
1786 | bail: | 1836 | bail: |
1787 | if (group_bh) | 1837 | brelse(group_bh); |
1788 | brelse(group_bh); | ||
1789 | 1838 | ||
1790 | mlog_exit(status); | 1839 | mlog_exit(status); |
1791 | return status; | 1840 | return status; |
@@ -1838,9 +1887,15 @@ int ocfs2_free_clusters(handle_t *handle, | |||
1838 | status = ocfs2_free_suballoc_bits(handle, bitmap_inode, bitmap_bh, | 1887 | status = ocfs2_free_suballoc_bits(handle, bitmap_inode, bitmap_bh, |
1839 | bg_start_bit, bg_blkno, | 1888 | bg_start_bit, bg_blkno, |
1840 | num_clusters); | 1889 | num_clusters); |
1841 | if (status < 0) | 1890 | if (status < 0) { |
1842 | mlog_errno(status); | 1891 | mlog_errno(status); |
1892 | goto out; | ||
1893 | } | ||
1843 | 1894 | ||
1895 | ocfs2_local_alloc_seen_free_bits(OCFS2_SB(bitmap_inode->i_sb), | ||
1896 | num_clusters); | ||
1897 | |||
1898 | out: | ||
1844 | mlog_exit(status); | 1899 | mlog_exit(status); |
1845 | return status; | 1900 | return status; |
1846 | } | 1901 | } |
@@ -1891,3 +1946,84 @@ static inline void ocfs2_debug_suballoc_inode(struct ocfs2_dinode *fe) | |||
1891 | (unsigned long long)fe->id2.i_chain.cl_recs[i].c_blkno); | 1946 | (unsigned long long)fe->id2.i_chain.cl_recs[i].c_blkno); |
1892 | } | 1947 | } |
1893 | } | 1948 | } |
1949 | |||
1950 | /* | ||
1951 | * For a given allocation, determine which allocators will need to be | ||
1952 | * accessed, and lock them, reserving the appropriate number of bits. | ||
1953 | * | ||
1954 | * Sparse file systems call this from ocfs2_write_begin_nolock() | ||
1955 | * and ocfs2_allocate_unwritten_extents(). | ||
1956 | * | ||
1957 | * File systems which don't support holes call this from | ||
1958 | * ocfs2_extend_allocation(). | ||
1959 | */ | ||
1960 | int ocfs2_lock_allocators(struct inode *inode, | ||
1961 | struct ocfs2_extent_tree *et, | ||
1962 | u32 clusters_to_add, u32 extents_to_split, | ||
1963 | struct ocfs2_alloc_context **data_ac, | ||
1964 | struct ocfs2_alloc_context **meta_ac) | ||
1965 | { | ||
1966 | int ret = 0, num_free_extents; | ||
1967 | unsigned int max_recs_needed = clusters_to_add + 2 * extents_to_split; | ||
1968 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
1969 | |||
1970 | *meta_ac = NULL; | ||
1971 | if (data_ac) | ||
1972 | *data_ac = NULL; | ||
1973 | |||
1974 | BUG_ON(clusters_to_add != 0 && data_ac == NULL); | ||
1975 | |||
1976 | num_free_extents = ocfs2_num_free_extents(osb, inode, et); | ||
1977 | if (num_free_extents < 0) { | ||
1978 | ret = num_free_extents; | ||
1979 | mlog_errno(ret); | ||
1980 | goto out; | ||
1981 | } | ||
1982 | |||
1983 | /* | ||
1984 | * Sparse allocation file systems need to be more conservative | ||
1985 | * with reserving room for expansion - the actual allocation | ||
1986 | * happens while we've got a journal handle open so re-taking | ||
1987 | * a cluster lock (because we ran out of room for another | ||
1988 | * extent) will violate ordering rules. | ||
1989 | * | ||
1990 | * Most of the time we'll only be seeing this 1 cluster at a time | ||
1991 | * anyway. | ||
1992 | * | ||
1993 | * Always lock for any unwritten extents - we might want to | ||
1994 | * add blocks during a split. | ||
1995 | */ | ||
1996 | if (!num_free_extents || | ||
1997 | (ocfs2_sparse_alloc(osb) && num_free_extents < max_recs_needed)) { | ||
1998 | ret = ocfs2_reserve_new_metadata(osb, et->et_root_el, meta_ac); | ||
1999 | if (ret < 0) { | ||
2000 | if (ret != -ENOSPC) | ||
2001 | mlog_errno(ret); | ||
2002 | goto out; | ||
2003 | } | ||
2004 | } | ||
2005 | |||
2006 | if (clusters_to_add == 0) | ||
2007 | goto out; | ||
2008 | |||
2009 | ret = ocfs2_reserve_clusters(osb, clusters_to_add, data_ac); | ||
2010 | if (ret < 0) { | ||
2011 | if (ret != -ENOSPC) | ||
2012 | mlog_errno(ret); | ||
2013 | goto out; | ||
2014 | } | ||
2015 | |||
2016 | out: | ||
2017 | if (ret) { | ||
2018 | if (*meta_ac) { | ||
2019 | ocfs2_free_alloc_context(*meta_ac); | ||
2020 | *meta_ac = NULL; | ||
2021 | } | ||
2022 | |||
2023 | /* | ||
2024 | * We cannot have an error and a non null *data_ac. | ||
2025 | */ | ||
2026 | } | ||
2027 | |||
2028 | return ret; | ||
2029 | } | ||
diff --git a/fs/ocfs2/suballoc.h b/fs/ocfs2/suballoc.h index 544c600662bd..4df159d8f450 100644 --- a/fs/ocfs2/suballoc.h +++ b/fs/ocfs2/suballoc.h | |||
@@ -28,10 +28,11 @@ | |||
28 | 28 | ||
29 | typedef int (group_search_t)(struct inode *, | 29 | typedef int (group_search_t)(struct inode *, |
30 | struct buffer_head *, | 30 | struct buffer_head *, |
31 | u32, | 31 | u32, /* bits_wanted */ |
32 | u32, | 32 | u32, /* min_bits */ |
33 | u16 *, | 33 | u64, /* max_block */ |
34 | u16 *); | 34 | u16 *, /* *bit_off */ |
35 | u16 *); /* *bits_found */ | ||
35 | 36 | ||
36 | struct ocfs2_alloc_context { | 37 | struct ocfs2_alloc_context { |
37 | struct inode *ac_inode; /* which bitmap are we allocating from? */ | 38 | struct inode *ac_inode; /* which bitmap are we allocating from? */ |
@@ -51,6 +52,8 @@ struct ocfs2_alloc_context { | |||
51 | group_search_t *ac_group_search; | 52 | group_search_t *ac_group_search; |
52 | 53 | ||
53 | u64 ac_last_group; | 54 | u64 ac_last_group; |
55 | u64 ac_max_block; /* Highest block number to allocate. 0 is | ||
56 | is the same as ~0 - unlimited */ | ||
54 | }; | 57 | }; |
55 | 58 | ||
56 | void ocfs2_free_alloc_context(struct ocfs2_alloc_context *ac); | 59 | void ocfs2_free_alloc_context(struct ocfs2_alloc_context *ac); |
@@ -59,9 +62,17 @@ static inline int ocfs2_alloc_context_bits_left(struct ocfs2_alloc_context *ac) | |||
59 | return ac->ac_bits_wanted - ac->ac_bits_given; | 62 | return ac->ac_bits_wanted - ac->ac_bits_given; |
60 | } | 63 | } |
61 | 64 | ||
65 | /* | ||
66 | * Please note that the caller must make sure that root_el is the root | ||
67 | * of extent tree. So for an inode, it should be &fe->id2.i_list. Otherwise | ||
68 | * the result may be wrong. | ||
69 | */ | ||
62 | int ocfs2_reserve_new_metadata(struct ocfs2_super *osb, | 70 | int ocfs2_reserve_new_metadata(struct ocfs2_super *osb, |
63 | struct ocfs2_dinode *fe, | 71 | struct ocfs2_extent_list *root_el, |
64 | struct ocfs2_alloc_context **ac); | 72 | struct ocfs2_alloc_context **ac); |
73 | int ocfs2_reserve_new_metadata_blocks(struct ocfs2_super *osb, | ||
74 | int blocks, | ||
75 | struct ocfs2_alloc_context **ac); | ||
65 | int ocfs2_reserve_new_inode(struct ocfs2_super *osb, | 76 | int ocfs2_reserve_new_inode(struct ocfs2_super *osb, |
66 | struct ocfs2_alloc_context **ac); | 77 | struct ocfs2_alloc_context **ac); |
67 | int ocfs2_reserve_clusters(struct ocfs2_super *osb, | 78 | int ocfs2_reserve_clusters(struct ocfs2_super *osb, |
@@ -147,6 +158,7 @@ static inline int ocfs2_is_cluster_bitmap(struct inode *inode) | |||
147 | * apis above. */ | 158 | * apis above. */ |
148 | int ocfs2_reserve_cluster_bitmap_bits(struct ocfs2_super *osb, | 159 | int ocfs2_reserve_cluster_bitmap_bits(struct ocfs2_super *osb, |
149 | struct ocfs2_alloc_context *ac); | 160 | struct ocfs2_alloc_context *ac); |
161 | void ocfs2_free_ac_resource(struct ocfs2_alloc_context *ac); | ||
150 | 162 | ||
151 | /* given a cluster offset, calculate which block group it belongs to | 163 | /* given a cluster offset, calculate which block group it belongs to |
152 | * and return that block offset. */ | 164 | * and return that block offset. */ |
@@ -156,4 +168,8 @@ u64 ocfs2_which_cluster_group(struct inode *inode, u32 cluster); | |||
156 | int ocfs2_check_group_descriptor(struct super_block *sb, | 168 | int ocfs2_check_group_descriptor(struct super_block *sb, |
157 | struct ocfs2_dinode *di, | 169 | struct ocfs2_dinode *di, |
158 | struct ocfs2_group_desc *gd); | 170 | struct ocfs2_group_desc *gd); |
171 | int ocfs2_lock_allocators(struct inode *inode, struct ocfs2_extent_tree *et, | ||
172 | u32 clusters_to_add, u32 extents_to_split, | ||
173 | struct ocfs2_alloc_context **data_ac, | ||
174 | struct ocfs2_alloc_context **meta_ac); | ||
159 | #endif /* _CHAINALLOC_H_ */ | 175 | #endif /* _CHAINALLOC_H_ */ |
diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c index 70334d85aff1..304b63ac78cf 100644 --- a/fs/ocfs2/super.c +++ b/fs/ocfs2/super.c | |||
@@ -64,6 +64,7 @@ | |||
64 | #include "sysfile.h" | 64 | #include "sysfile.h" |
65 | #include "uptodate.h" | 65 | #include "uptodate.h" |
66 | #include "ver.h" | 66 | #include "ver.h" |
67 | #include "xattr.h" | ||
67 | 68 | ||
68 | #include "buffer_head_io.h" | 69 | #include "buffer_head_io.h" |
69 | 70 | ||
@@ -154,6 +155,9 @@ enum { | |||
154 | Opt_localalloc, | 155 | Opt_localalloc, |
155 | Opt_localflocks, | 156 | Opt_localflocks, |
156 | Opt_stack, | 157 | Opt_stack, |
158 | Opt_user_xattr, | ||
159 | Opt_nouser_xattr, | ||
160 | Opt_inode64, | ||
157 | Opt_err, | 161 | Opt_err, |
158 | }; | 162 | }; |
159 | 163 | ||
@@ -173,6 +177,9 @@ static const match_table_t tokens = { | |||
173 | {Opt_localalloc, "localalloc=%d"}, | 177 | {Opt_localalloc, "localalloc=%d"}, |
174 | {Opt_localflocks, "localflocks"}, | 178 | {Opt_localflocks, "localflocks"}, |
175 | {Opt_stack, "cluster_stack=%s"}, | 179 | {Opt_stack, "cluster_stack=%s"}, |
180 | {Opt_user_xattr, "user_xattr"}, | ||
181 | {Opt_nouser_xattr, "nouser_xattr"}, | ||
182 | {Opt_inode64, "inode64"}, | ||
176 | {Opt_err, NULL} | 183 | {Opt_err, NULL} |
177 | }; | 184 | }; |
178 | 185 | ||
@@ -205,10 +212,11 @@ static int ocfs2_sync_fs(struct super_block *sb, int wait) | |||
205 | ocfs2_schedule_truncate_log_flush(osb, 0); | 212 | ocfs2_schedule_truncate_log_flush(osb, 0); |
206 | } | 213 | } |
207 | 214 | ||
208 | if (journal_start_commit(OCFS2_SB(sb)->journal->j_journal, &target)) { | 215 | if (jbd2_journal_start_commit(OCFS2_SB(sb)->journal->j_journal, |
216 | &target)) { | ||
209 | if (wait) | 217 | if (wait) |
210 | log_wait_commit(OCFS2_SB(sb)->journal->j_journal, | 218 | jbd2_log_wait_commit(OCFS2_SB(sb)->journal->j_journal, |
211 | target); | 219 | target); |
212 | } | 220 | } |
213 | return 0; | 221 | return 0; |
214 | } | 222 | } |
@@ -325,6 +333,7 @@ static struct inode *ocfs2_alloc_inode(struct super_block *sb) | |||
325 | if (!oi) | 333 | if (!oi) |
326 | return NULL; | 334 | return NULL; |
327 | 335 | ||
336 | jbd2_journal_init_jbd_inode(&oi->ip_jinode, &oi->vfs_inode); | ||
328 | return &oi->vfs_inode; | 337 | return &oi->vfs_inode; |
329 | } | 338 | } |
330 | 339 | ||
@@ -406,6 +415,15 @@ static int ocfs2_remount(struct super_block *sb, int *flags, char *data) | |||
406 | goto out; | 415 | goto out; |
407 | } | 416 | } |
408 | 417 | ||
418 | /* Probably don't want this on remount; it might | ||
419 | * mess with other nodes */ | ||
420 | if (!(osb->s_mount_opt & OCFS2_MOUNT_INODE64) && | ||
421 | (parsed_options.mount_opt & OCFS2_MOUNT_INODE64)) { | ||
422 | ret = -EINVAL; | ||
423 | mlog(ML_ERROR, "Cannot enable inode64 on remount\n"); | ||
424 | goto out; | ||
425 | } | ||
426 | |||
409 | /* We're going to/from readonly mode. */ | 427 | /* We're going to/from readonly mode. */ |
410 | if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) { | 428 | if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) { |
411 | /* Lock here so the check of HARD_RO and the potential | 429 | /* Lock here so the check of HARD_RO and the potential |
@@ -637,7 +655,8 @@ static int ocfs2_fill_super(struct super_block *sb, void *data, int silent) | |||
637 | osb->s_atime_quantum = parsed_options.atime_quantum; | 655 | osb->s_atime_quantum = parsed_options.atime_quantum; |
638 | osb->preferred_slot = parsed_options.slot; | 656 | osb->preferred_slot = parsed_options.slot; |
639 | osb->osb_commit_interval = parsed_options.commit_interval; | 657 | osb->osb_commit_interval = parsed_options.commit_interval; |
640 | osb->local_alloc_size = parsed_options.localalloc_opt; | 658 | osb->local_alloc_default_bits = ocfs2_megabytes_to_clusters(sb, parsed_options.localalloc_opt); |
659 | osb->local_alloc_bits = osb->local_alloc_default_bits; | ||
641 | 660 | ||
642 | status = ocfs2_verify_userspace_stack(osb, &parsed_options); | 661 | status = ocfs2_verify_userspace_stack(osb, &parsed_options); |
643 | if (status) | 662 | if (status) |
@@ -743,8 +762,7 @@ static int ocfs2_fill_super(struct super_block *sb, void *data, int silent) | |||
743 | return status; | 762 | return status; |
744 | 763 | ||
745 | read_super_error: | 764 | read_super_error: |
746 | if (bh != NULL) | 765 | brelse(bh); |
747 | brelse(bh); | ||
748 | 766 | ||
749 | if (inode) | 767 | if (inode) |
750 | iput(inode); | 768 | iput(inode); |
@@ -847,6 +865,12 @@ static int ocfs2_parse_options(struct super_block *sb, | |||
847 | case Opt_data_writeback: | 865 | case Opt_data_writeback: |
848 | mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK; | 866 | mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK; |
849 | break; | 867 | break; |
868 | case Opt_user_xattr: | ||
869 | mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR; | ||
870 | break; | ||
871 | case Opt_nouser_xattr: | ||
872 | mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR; | ||
873 | break; | ||
850 | case Opt_atime_quantum: | 874 | case Opt_atime_quantum: |
851 | if (match_int(&args[0], &option)) { | 875 | if (match_int(&args[0], &option)) { |
852 | status = 0; | 876 | status = 0; |
@@ -873,7 +897,7 @@ static int ocfs2_parse_options(struct super_block *sb, | |||
873 | if (option < 0) | 897 | if (option < 0) |
874 | return 0; | 898 | return 0; |
875 | if (option == 0) | 899 | if (option == 0) |
876 | option = JBD_DEFAULT_MAX_COMMIT_AGE; | 900 | option = JBD2_DEFAULT_MAX_COMMIT_AGE; |
877 | mopt->commit_interval = HZ * option; | 901 | mopt->commit_interval = HZ * option; |
878 | break; | 902 | break; |
879 | case Opt_localalloc: | 903 | case Opt_localalloc: |
@@ -918,6 +942,9 @@ static int ocfs2_parse_options(struct super_block *sb, | |||
918 | OCFS2_STACK_LABEL_LEN); | 942 | OCFS2_STACK_LABEL_LEN); |
919 | mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0'; | 943 | mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0'; |
920 | break; | 944 | break; |
945 | case Opt_inode64: | ||
946 | mopt->mount_opt |= OCFS2_MOUNT_INODE64; | ||
947 | break; | ||
921 | default: | 948 | default: |
922 | mlog(ML_ERROR, | 949 | mlog(ML_ERROR, |
923 | "Unrecognized mount option \"%s\" " | 950 | "Unrecognized mount option \"%s\" " |
@@ -938,6 +965,7 @@ static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt) | |||
938 | { | 965 | { |
939 | struct ocfs2_super *osb = OCFS2_SB(mnt->mnt_sb); | 966 | struct ocfs2_super *osb = OCFS2_SB(mnt->mnt_sb); |
940 | unsigned long opts = osb->s_mount_opt; | 967 | unsigned long opts = osb->s_mount_opt; |
968 | unsigned int local_alloc_megs; | ||
941 | 969 | ||
942 | if (opts & OCFS2_MOUNT_HB_LOCAL) | 970 | if (opts & OCFS2_MOUNT_HB_LOCAL) |
943 | seq_printf(s, ",_netdev,heartbeat=local"); | 971 | seq_printf(s, ",_netdev,heartbeat=local"); |
@@ -970,8 +998,9 @@ static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt) | |||
970 | seq_printf(s, ",commit=%u", | 998 | seq_printf(s, ",commit=%u", |
971 | (unsigned) (osb->osb_commit_interval / HZ)); | 999 | (unsigned) (osb->osb_commit_interval / HZ)); |
972 | 1000 | ||
973 | if (osb->local_alloc_size != OCFS2_DEFAULT_LOCAL_ALLOC_SIZE) | 1001 | local_alloc_megs = osb->local_alloc_bits >> (20 - osb->s_clustersize_bits); |
974 | seq_printf(s, ",localalloc=%d", osb->local_alloc_size); | 1002 | if (local_alloc_megs != OCFS2_DEFAULT_LOCAL_ALLOC_SIZE) |
1003 | seq_printf(s, ",localalloc=%d", local_alloc_megs); | ||
975 | 1004 | ||
976 | if (opts & OCFS2_MOUNT_LOCALFLOCKS) | 1005 | if (opts & OCFS2_MOUNT_LOCALFLOCKS) |
977 | seq_printf(s, ",localflocks,"); | 1006 | seq_printf(s, ",localflocks,"); |
@@ -980,6 +1009,14 @@ static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt) | |||
980 | seq_printf(s, ",cluster_stack=%.*s", OCFS2_STACK_LABEL_LEN, | 1009 | seq_printf(s, ",cluster_stack=%.*s", OCFS2_STACK_LABEL_LEN, |
981 | osb->osb_cluster_stack); | 1010 | osb->osb_cluster_stack); |
982 | 1011 | ||
1012 | if (opts & OCFS2_MOUNT_NOUSERXATTR) | ||
1013 | seq_printf(s, ",nouser_xattr"); | ||
1014 | else | ||
1015 | seq_printf(s, ",user_xattr"); | ||
1016 | |||
1017 | if (opts & OCFS2_MOUNT_INODE64) | ||
1018 | seq_printf(s, ",inode64"); | ||
1019 | |||
983 | return 0; | 1020 | return 0; |
984 | } | 1021 | } |
985 | 1022 | ||
@@ -1132,6 +1169,7 @@ static void ocfs2_inode_init_once(void *data) | |||
1132 | oi->ip_dir_start_lookup = 0; | 1169 | oi->ip_dir_start_lookup = 0; |
1133 | 1170 | ||
1134 | init_rwsem(&oi->ip_alloc_sem); | 1171 | init_rwsem(&oi->ip_alloc_sem); |
1172 | init_rwsem(&oi->ip_xattr_sem); | ||
1135 | mutex_init(&oi->ip_io_mutex); | 1173 | mutex_init(&oi->ip_io_mutex); |
1136 | 1174 | ||
1137 | oi->ip_blkno = 0ULL; | 1175 | oi->ip_blkno = 0ULL; |
@@ -1375,6 +1413,7 @@ static int ocfs2_initialize_super(struct super_block *sb, | |||
1375 | sb->s_fs_info = osb; | 1413 | sb->s_fs_info = osb; |
1376 | sb->s_op = &ocfs2_sops; | 1414 | sb->s_op = &ocfs2_sops; |
1377 | sb->s_export_op = &ocfs2_export_ops; | 1415 | sb->s_export_op = &ocfs2_export_ops; |
1416 | sb->s_xattr = ocfs2_xattr_handlers; | ||
1378 | sb->s_time_gran = 1; | 1417 | sb->s_time_gran = 1; |
1379 | sb->s_flags |= MS_NOATIME; | 1418 | sb->s_flags |= MS_NOATIME; |
1380 | /* this is needed to support O_LARGEFILE */ | 1419 | /* this is needed to support O_LARGEFILE */ |
@@ -1421,8 +1460,12 @@ static int ocfs2_initialize_super(struct super_block *sb, | |||
1421 | 1460 | ||
1422 | osb->slot_num = OCFS2_INVALID_SLOT; | 1461 | osb->slot_num = OCFS2_INVALID_SLOT; |
1423 | 1462 | ||
1463 | osb->s_xattr_inline_size = le16_to_cpu( | ||
1464 | di->id2.i_super.s_xattr_inline_size); | ||
1465 | |||
1424 | osb->local_alloc_state = OCFS2_LA_UNUSED; | 1466 | osb->local_alloc_state = OCFS2_LA_UNUSED; |
1425 | osb->local_alloc_bh = NULL; | 1467 | osb->local_alloc_bh = NULL; |
1468 | INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker); | ||
1426 | 1469 | ||
1427 | init_waitqueue_head(&osb->osb_mount_event); | 1470 | init_waitqueue_head(&osb->osb_mount_event); |
1428 | 1471 | ||
@@ -1568,6 +1611,7 @@ static int ocfs2_initialize_super(struct super_block *sb, | |||
1568 | osb->first_cluster_group_blkno = | 1611 | osb->first_cluster_group_blkno = |
1569 | le64_to_cpu(di->id2.i_super.s_first_cluster_group); | 1612 | le64_to_cpu(di->id2.i_super.s_first_cluster_group); |
1570 | osb->fs_generation = le32_to_cpu(di->i_fs_generation); | 1613 | osb->fs_generation = le32_to_cpu(di->i_fs_generation); |
1614 | osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash); | ||
1571 | mlog(0, "vol_label: %s\n", osb->vol_label); | 1615 | mlog(0, "vol_label: %s\n", osb->vol_label); |
1572 | mlog(0, "uuid: %s\n", osb->uuid_str); | 1616 | mlog(0, "uuid: %s\n", osb->uuid_str); |
1573 | mlog(0, "root_blkno=%llu, system_dir_blkno=%llu\n", | 1617 | mlog(0, "root_blkno=%llu, system_dir_blkno=%llu\n", |
diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c index ba9dbb51d25b..cbd03dfdc7b9 100644 --- a/fs/ocfs2/symlink.c +++ b/fs/ocfs2/symlink.c | |||
@@ -50,6 +50,7 @@ | |||
50 | #include "inode.h" | 50 | #include "inode.h" |
51 | #include "journal.h" | 51 | #include "journal.h" |
52 | #include "symlink.h" | 52 | #include "symlink.h" |
53 | #include "xattr.h" | ||
53 | 54 | ||
54 | #include "buffer_head_io.h" | 55 | #include "buffer_head_io.h" |
55 | 56 | ||
@@ -83,11 +84,7 @@ static char *ocfs2_fast_symlink_getlink(struct inode *inode, | |||
83 | 84 | ||
84 | mlog_entry_void(); | 85 | mlog_entry_void(); |
85 | 86 | ||
86 | status = ocfs2_read_block(OCFS2_SB(inode->i_sb), | 87 | status = ocfs2_read_block(inode, OCFS2_I(inode)->ip_blkno, bh); |
87 | OCFS2_I(inode)->ip_blkno, | ||
88 | bh, | ||
89 | OCFS2_BH_CACHED, | ||
90 | inode); | ||
91 | if (status < 0) { | 88 | if (status < 0) { |
92 | mlog_errno(status); | 89 | mlog_errno(status); |
93 | link = ERR_PTR(status); | 90 | link = ERR_PTR(status); |
@@ -157,8 +154,7 @@ bail: | |||
157 | kunmap(page); | 154 | kunmap(page); |
158 | page_cache_release(page); | 155 | page_cache_release(page); |
159 | } | 156 | } |
160 | if (bh) | 157 | brelse(bh); |
161 | brelse(bh); | ||
162 | 158 | ||
163 | return ERR_PTR(status); | 159 | return ERR_PTR(status); |
164 | } | 160 | } |
@@ -168,10 +164,18 @@ const struct inode_operations ocfs2_symlink_inode_operations = { | |||
168 | .follow_link = ocfs2_follow_link, | 164 | .follow_link = ocfs2_follow_link, |
169 | .getattr = ocfs2_getattr, | 165 | .getattr = ocfs2_getattr, |
170 | .setattr = ocfs2_setattr, | 166 | .setattr = ocfs2_setattr, |
167 | .setxattr = generic_setxattr, | ||
168 | .getxattr = generic_getxattr, | ||
169 | .listxattr = ocfs2_listxattr, | ||
170 | .removexattr = generic_removexattr, | ||
171 | }; | 171 | }; |
172 | const struct inode_operations ocfs2_fast_symlink_inode_operations = { | 172 | const struct inode_operations ocfs2_fast_symlink_inode_operations = { |
173 | .readlink = ocfs2_readlink, | 173 | .readlink = ocfs2_readlink, |
174 | .follow_link = ocfs2_follow_link, | 174 | .follow_link = ocfs2_follow_link, |
175 | .getattr = ocfs2_getattr, | 175 | .getattr = ocfs2_getattr, |
176 | .setattr = ocfs2_setattr, | 176 | .setattr = ocfs2_setattr, |
177 | .setxattr = generic_setxattr, | ||
178 | .getxattr = generic_getxattr, | ||
179 | .listxattr = ocfs2_listxattr, | ||
180 | .removexattr = generic_removexattr, | ||
177 | }; | 181 | }; |
diff --git a/fs/ocfs2/uptodate.c b/fs/ocfs2/uptodate.c index 4da8851f2b23..187b99ff0368 100644 --- a/fs/ocfs2/uptodate.c +++ b/fs/ocfs2/uptodate.c | |||
@@ -53,7 +53,11 @@ | |||
53 | #include <linux/highmem.h> | 53 | #include <linux/highmem.h> |
54 | #include <linux/buffer_head.h> | 54 | #include <linux/buffer_head.h> |
55 | #include <linux/rbtree.h> | 55 | #include <linux/rbtree.h> |
56 | #include <linux/jbd.h> | 56 | #ifndef CONFIG_OCFS2_COMPAT_JBD |
57 | # include <linux/jbd2.h> | ||
58 | #else | ||
59 | # include <linux/jbd.h> | ||
60 | #endif | ||
57 | 61 | ||
58 | #define MLOG_MASK_PREFIX ML_UPTODATE | 62 | #define MLOG_MASK_PREFIX ML_UPTODATE |
59 | 63 | ||
@@ -511,14 +515,10 @@ static void ocfs2_remove_metadata_tree(struct ocfs2_caching_info *ci, | |||
511 | ci->ci_num_cached--; | 515 | ci->ci_num_cached--; |
512 | } | 516 | } |
513 | 517 | ||
514 | /* Called when we remove a chunk of metadata from an inode. We don't | 518 | static void ocfs2_remove_block_from_cache(struct inode *inode, |
515 | * bother reverting things to an inlined array in the case of a remove | 519 | sector_t block) |
516 | * which moves us back under the limit. */ | ||
517 | void ocfs2_remove_from_cache(struct inode *inode, | ||
518 | struct buffer_head *bh) | ||
519 | { | 520 | { |
520 | int index; | 521 | int index; |
521 | sector_t block = bh->b_blocknr; | ||
522 | struct ocfs2_meta_cache_item *item = NULL; | 522 | struct ocfs2_meta_cache_item *item = NULL; |
523 | struct ocfs2_inode_info *oi = OCFS2_I(inode); | 523 | struct ocfs2_inode_info *oi = OCFS2_I(inode); |
524 | struct ocfs2_caching_info *ci = &oi->ip_metadata_cache; | 524 | struct ocfs2_caching_info *ci = &oi->ip_metadata_cache; |
@@ -544,6 +544,30 @@ void ocfs2_remove_from_cache(struct inode *inode, | |||
544 | kmem_cache_free(ocfs2_uptodate_cachep, item); | 544 | kmem_cache_free(ocfs2_uptodate_cachep, item); |
545 | } | 545 | } |
546 | 546 | ||
547 | /* | ||
548 | * Called when we remove a chunk of metadata from an inode. We don't | ||
549 | * bother reverting things to an inlined array in the case of a remove | ||
550 | * which moves us back under the limit. | ||
551 | */ | ||
552 | void ocfs2_remove_from_cache(struct inode *inode, | ||
553 | struct buffer_head *bh) | ||
554 | { | ||
555 | sector_t block = bh->b_blocknr; | ||
556 | |||
557 | ocfs2_remove_block_from_cache(inode, block); | ||
558 | } | ||
559 | |||
560 | /* Called when we remove xattr clusters from an inode. */ | ||
561 | void ocfs2_remove_xattr_clusters_from_cache(struct inode *inode, | ||
562 | sector_t block, | ||
563 | u32 c_len) | ||
564 | { | ||
565 | unsigned int i, b_len = ocfs2_clusters_to_blocks(inode->i_sb, 1) * c_len; | ||
566 | |||
567 | for (i = 0; i < b_len; i++, block++) | ||
568 | ocfs2_remove_block_from_cache(inode, block); | ||
569 | } | ||
570 | |||
547 | int __init init_ocfs2_uptodate_cache(void) | 571 | int __init init_ocfs2_uptodate_cache(void) |
548 | { | 572 | { |
549 | ocfs2_uptodate_cachep = kmem_cache_create("ocfs2_uptodate", | 573 | ocfs2_uptodate_cachep = kmem_cache_create("ocfs2_uptodate", |
diff --git a/fs/ocfs2/uptodate.h b/fs/ocfs2/uptodate.h index 2e73206059a8..531b4b3a0c47 100644 --- a/fs/ocfs2/uptodate.h +++ b/fs/ocfs2/uptodate.h | |||
@@ -40,6 +40,9 @@ void ocfs2_set_new_buffer_uptodate(struct inode *inode, | |||
40 | struct buffer_head *bh); | 40 | struct buffer_head *bh); |
41 | void ocfs2_remove_from_cache(struct inode *inode, | 41 | void ocfs2_remove_from_cache(struct inode *inode, |
42 | struct buffer_head *bh); | 42 | struct buffer_head *bh); |
43 | void ocfs2_remove_xattr_clusters_from_cache(struct inode *inode, | ||
44 | sector_t block, | ||
45 | u32 c_len); | ||
43 | int ocfs2_buffer_read_ahead(struct inode *inode, | 46 | int ocfs2_buffer_read_ahead(struct inode *inode, |
44 | struct buffer_head *bh); | 47 | struct buffer_head *bh); |
45 | 48 | ||
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c new file mode 100644 index 000000000000..c25780a70dfd --- /dev/null +++ b/fs/ocfs2/xattr.c | |||
@@ -0,0 +1,4834 @@ | |||
1 | /* -*- mode: c; c-basic-offset: 8; -*- | ||
2 | * vim: noexpandtab sw=8 ts=8 sts=0: | ||
3 | * | ||
4 | * xattr.c | ||
5 | * | ||
6 | * Copyright (C) 2008 Oracle. All rights reserved. | ||
7 | * | ||
8 | * CREDITS: | ||
9 | * Lots of code in this file is taken from ext3. | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU General Public | ||
13 | * License as published by the Free Software Foundation; either | ||
14 | * version 2 of the License, or (at your option) any later version. | ||
15 | * | ||
16 | * This program is distributed in the hope that it will be useful, | ||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
19 | * General Public License for more details. | ||
20 | * | ||
21 | * You should have received a copy of the GNU General Public | ||
22 | * License along with this program; if not, write to the | ||
23 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
24 | * Boston, MA 021110-1307, USA. | ||
25 | */ | ||
26 | |||
27 | #include <linux/capability.h> | ||
28 | #include <linux/fs.h> | ||
29 | #include <linux/types.h> | ||
30 | #include <linux/slab.h> | ||
31 | #include <linux/highmem.h> | ||
32 | #include <linux/pagemap.h> | ||
33 | #include <linux/uio.h> | ||
34 | #include <linux/sched.h> | ||
35 | #include <linux/splice.h> | ||
36 | #include <linux/mount.h> | ||
37 | #include <linux/writeback.h> | ||
38 | #include <linux/falloc.h> | ||
39 | #include <linux/sort.h> | ||
40 | #include <linux/init.h> | ||
41 | #include <linux/module.h> | ||
42 | #include <linux/string.h> | ||
43 | |||
44 | #define MLOG_MASK_PREFIX ML_XATTR | ||
45 | #include <cluster/masklog.h> | ||
46 | |||
47 | #include "ocfs2.h" | ||
48 | #include "alloc.h" | ||
49 | #include "dlmglue.h" | ||
50 | #include "file.h" | ||
51 | #include "symlink.h" | ||
52 | #include "sysfile.h" | ||
53 | #include "inode.h" | ||
54 | #include "journal.h" | ||
55 | #include "ocfs2_fs.h" | ||
56 | #include "suballoc.h" | ||
57 | #include "uptodate.h" | ||
58 | #include "buffer_head_io.h" | ||
59 | #include "super.h" | ||
60 | #include "xattr.h" | ||
61 | |||
62 | |||
63 | struct ocfs2_xattr_def_value_root { | ||
64 | struct ocfs2_xattr_value_root xv; | ||
65 | struct ocfs2_extent_rec er; | ||
66 | }; | ||
67 | |||
68 | struct ocfs2_xattr_bucket { | ||
69 | struct buffer_head *bhs[OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET]; | ||
70 | struct ocfs2_xattr_header *xh; | ||
71 | }; | ||
72 | |||
73 | #define OCFS2_XATTR_ROOT_SIZE (sizeof(struct ocfs2_xattr_def_value_root)) | ||
74 | #define OCFS2_XATTR_INLINE_SIZE 80 | ||
75 | |||
76 | static struct ocfs2_xattr_def_value_root def_xv = { | ||
77 | .xv.xr_list.l_count = cpu_to_le16(1), | ||
78 | }; | ||
79 | |||
80 | struct xattr_handler *ocfs2_xattr_handlers[] = { | ||
81 | &ocfs2_xattr_user_handler, | ||
82 | &ocfs2_xattr_trusted_handler, | ||
83 | NULL | ||
84 | }; | ||
85 | |||
86 | static struct xattr_handler *ocfs2_xattr_handler_map[] = { | ||
87 | [OCFS2_XATTR_INDEX_USER] = &ocfs2_xattr_user_handler, | ||
88 | [OCFS2_XATTR_INDEX_TRUSTED] = &ocfs2_xattr_trusted_handler, | ||
89 | }; | ||
90 | |||
91 | struct ocfs2_xattr_info { | ||
92 | int name_index; | ||
93 | const char *name; | ||
94 | const void *value; | ||
95 | size_t value_len; | ||
96 | }; | ||
97 | |||
98 | struct ocfs2_xattr_search { | ||
99 | struct buffer_head *inode_bh; | ||
100 | /* | ||
101 | * xattr_bh point to the block buffer head which has extended attribute | ||
102 | * when extended attribute in inode, xattr_bh is equal to inode_bh. | ||
103 | */ | ||
104 | struct buffer_head *xattr_bh; | ||
105 | struct ocfs2_xattr_header *header; | ||
106 | struct ocfs2_xattr_bucket bucket; | ||
107 | void *base; | ||
108 | void *end; | ||
109 | struct ocfs2_xattr_entry *here; | ||
110 | int not_found; | ||
111 | }; | ||
112 | |||
113 | static int ocfs2_xattr_bucket_get_name_value(struct inode *inode, | ||
114 | struct ocfs2_xattr_header *xh, | ||
115 | int index, | ||
116 | int *block_off, | ||
117 | int *new_offset); | ||
118 | |||
119 | static int ocfs2_xattr_index_block_find(struct inode *inode, | ||
120 | struct buffer_head *root_bh, | ||
121 | int name_index, | ||
122 | const char *name, | ||
123 | struct ocfs2_xattr_search *xs); | ||
124 | |||
125 | static int ocfs2_xattr_tree_list_index_block(struct inode *inode, | ||
126 | struct ocfs2_xattr_tree_root *xt, | ||
127 | char *buffer, | ||
128 | size_t buffer_size); | ||
129 | |||
130 | static int ocfs2_xattr_create_index_block(struct inode *inode, | ||
131 | struct ocfs2_xattr_search *xs); | ||
132 | |||
133 | static int ocfs2_xattr_set_entry_index_block(struct inode *inode, | ||
134 | struct ocfs2_xattr_info *xi, | ||
135 | struct ocfs2_xattr_search *xs); | ||
136 | |||
137 | static int ocfs2_delete_xattr_index_block(struct inode *inode, | ||
138 | struct buffer_head *xb_bh); | ||
139 | |||
140 | static inline const char *ocfs2_xattr_prefix(int name_index) | ||
141 | { | ||
142 | struct xattr_handler *handler = NULL; | ||
143 | |||
144 | if (name_index > 0 && name_index < OCFS2_XATTR_MAX) | ||
145 | handler = ocfs2_xattr_handler_map[name_index]; | ||
146 | |||
147 | return handler ? handler->prefix : NULL; | ||
148 | } | ||
149 | |||
150 | static u32 ocfs2_xattr_name_hash(struct inode *inode, | ||
151 | const char *name, | ||
152 | int name_len) | ||
153 | { | ||
154 | /* Get hash value of uuid from super block */ | ||
155 | u32 hash = OCFS2_SB(inode->i_sb)->uuid_hash; | ||
156 | int i; | ||
157 | |||
158 | /* hash extended attribute name */ | ||
159 | for (i = 0; i < name_len; i++) { | ||
160 | hash = (hash << OCFS2_HASH_SHIFT) ^ | ||
161 | (hash >> (8*sizeof(hash) - OCFS2_HASH_SHIFT)) ^ | ||
162 | *name++; | ||
163 | } | ||
164 | |||
165 | return hash; | ||
166 | } | ||
167 | |||
168 | /* | ||
169 | * ocfs2_xattr_hash_entry() | ||
170 | * | ||
171 | * Compute the hash of an extended attribute. | ||
172 | */ | ||
173 | static void ocfs2_xattr_hash_entry(struct inode *inode, | ||
174 | struct ocfs2_xattr_header *header, | ||
175 | struct ocfs2_xattr_entry *entry) | ||
176 | { | ||
177 | u32 hash = 0; | ||
178 | char *name = (char *)header + le16_to_cpu(entry->xe_name_offset); | ||
179 | |||
180 | hash = ocfs2_xattr_name_hash(inode, name, entry->xe_name_len); | ||
181 | entry->xe_name_hash = cpu_to_le32(hash); | ||
182 | |||
183 | return; | ||
184 | } | ||
185 | |||
186 | static int ocfs2_xattr_extend_allocation(struct inode *inode, | ||
187 | u32 clusters_to_add, | ||
188 | struct buffer_head *xattr_bh, | ||
189 | struct ocfs2_xattr_value_root *xv) | ||
190 | { | ||
191 | int status = 0; | ||
192 | int restart_func = 0; | ||
193 | int credits = 0; | ||
194 | handle_t *handle = NULL; | ||
195 | struct ocfs2_alloc_context *data_ac = NULL; | ||
196 | struct ocfs2_alloc_context *meta_ac = NULL; | ||
197 | enum ocfs2_alloc_restarted why; | ||
198 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
199 | u32 prev_clusters, logical_start = le32_to_cpu(xv->xr_clusters); | ||
200 | struct ocfs2_extent_tree et; | ||
201 | |||
202 | mlog(0, "(clusters_to_add for xattr= %u)\n", clusters_to_add); | ||
203 | |||
204 | ocfs2_init_xattr_value_extent_tree(&et, inode, xattr_bh, xv); | ||
205 | |||
206 | restart_all: | ||
207 | |||
208 | status = ocfs2_lock_allocators(inode, &et, clusters_to_add, 0, | ||
209 | &data_ac, &meta_ac); | ||
210 | if (status) { | ||
211 | mlog_errno(status); | ||
212 | goto leave; | ||
213 | } | ||
214 | |||
215 | credits = ocfs2_calc_extend_credits(osb->sb, et.et_root_el, | ||
216 | clusters_to_add); | ||
217 | handle = ocfs2_start_trans(osb, credits); | ||
218 | if (IS_ERR(handle)) { | ||
219 | status = PTR_ERR(handle); | ||
220 | handle = NULL; | ||
221 | mlog_errno(status); | ||
222 | goto leave; | ||
223 | } | ||
224 | |||
225 | restarted_transaction: | ||
226 | status = ocfs2_journal_access(handle, inode, xattr_bh, | ||
227 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
228 | if (status < 0) { | ||
229 | mlog_errno(status); | ||
230 | goto leave; | ||
231 | } | ||
232 | |||
233 | prev_clusters = le32_to_cpu(xv->xr_clusters); | ||
234 | status = ocfs2_add_clusters_in_btree(osb, | ||
235 | inode, | ||
236 | &logical_start, | ||
237 | clusters_to_add, | ||
238 | 0, | ||
239 | &et, | ||
240 | handle, | ||
241 | data_ac, | ||
242 | meta_ac, | ||
243 | &why); | ||
244 | if ((status < 0) && (status != -EAGAIN)) { | ||
245 | if (status != -ENOSPC) | ||
246 | mlog_errno(status); | ||
247 | goto leave; | ||
248 | } | ||
249 | |||
250 | status = ocfs2_journal_dirty(handle, xattr_bh); | ||
251 | if (status < 0) { | ||
252 | mlog_errno(status); | ||
253 | goto leave; | ||
254 | } | ||
255 | |||
256 | clusters_to_add -= le32_to_cpu(xv->xr_clusters) - prev_clusters; | ||
257 | |||
258 | if (why != RESTART_NONE && clusters_to_add) { | ||
259 | if (why == RESTART_META) { | ||
260 | mlog(0, "restarting function.\n"); | ||
261 | restart_func = 1; | ||
262 | } else { | ||
263 | BUG_ON(why != RESTART_TRANS); | ||
264 | |||
265 | mlog(0, "restarting transaction.\n"); | ||
266 | /* TODO: This can be more intelligent. */ | ||
267 | credits = ocfs2_calc_extend_credits(osb->sb, | ||
268 | et.et_root_el, | ||
269 | clusters_to_add); | ||
270 | status = ocfs2_extend_trans(handle, credits); | ||
271 | if (status < 0) { | ||
272 | /* handle still has to be committed at | ||
273 | * this point. */ | ||
274 | status = -ENOMEM; | ||
275 | mlog_errno(status); | ||
276 | goto leave; | ||
277 | } | ||
278 | goto restarted_transaction; | ||
279 | } | ||
280 | } | ||
281 | |||
282 | leave: | ||
283 | if (handle) { | ||
284 | ocfs2_commit_trans(osb, handle); | ||
285 | handle = NULL; | ||
286 | } | ||
287 | if (data_ac) { | ||
288 | ocfs2_free_alloc_context(data_ac); | ||
289 | data_ac = NULL; | ||
290 | } | ||
291 | if (meta_ac) { | ||
292 | ocfs2_free_alloc_context(meta_ac); | ||
293 | meta_ac = NULL; | ||
294 | } | ||
295 | if ((!status) && restart_func) { | ||
296 | restart_func = 0; | ||
297 | goto restart_all; | ||
298 | } | ||
299 | |||
300 | return status; | ||
301 | } | ||
302 | |||
303 | static int __ocfs2_remove_xattr_range(struct inode *inode, | ||
304 | struct buffer_head *root_bh, | ||
305 | struct ocfs2_xattr_value_root *xv, | ||
306 | u32 cpos, u32 phys_cpos, u32 len, | ||
307 | struct ocfs2_cached_dealloc_ctxt *dealloc) | ||
308 | { | ||
309 | int ret; | ||
310 | u64 phys_blkno = ocfs2_clusters_to_blocks(inode->i_sb, phys_cpos); | ||
311 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
312 | struct inode *tl_inode = osb->osb_tl_inode; | ||
313 | handle_t *handle; | ||
314 | struct ocfs2_alloc_context *meta_ac = NULL; | ||
315 | struct ocfs2_extent_tree et; | ||
316 | |||
317 | ocfs2_init_xattr_value_extent_tree(&et, inode, root_bh, xv); | ||
318 | |||
319 | ret = ocfs2_lock_allocators(inode, &et, 0, 1, NULL, &meta_ac); | ||
320 | if (ret) { | ||
321 | mlog_errno(ret); | ||
322 | return ret; | ||
323 | } | ||
324 | |||
325 | mutex_lock(&tl_inode->i_mutex); | ||
326 | |||
327 | if (ocfs2_truncate_log_needs_flush(osb)) { | ||
328 | ret = __ocfs2_flush_truncate_log(osb); | ||
329 | if (ret < 0) { | ||
330 | mlog_errno(ret); | ||
331 | goto out; | ||
332 | } | ||
333 | } | ||
334 | |||
335 | handle = ocfs2_start_trans(osb, OCFS2_REMOVE_EXTENT_CREDITS); | ||
336 | if (IS_ERR(handle)) { | ||
337 | ret = PTR_ERR(handle); | ||
338 | mlog_errno(ret); | ||
339 | goto out; | ||
340 | } | ||
341 | |||
342 | ret = ocfs2_journal_access(handle, inode, root_bh, | ||
343 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
344 | if (ret) { | ||
345 | mlog_errno(ret); | ||
346 | goto out_commit; | ||
347 | } | ||
348 | |||
349 | ret = ocfs2_remove_extent(inode, &et, cpos, len, handle, meta_ac, | ||
350 | dealloc); | ||
351 | if (ret) { | ||
352 | mlog_errno(ret); | ||
353 | goto out_commit; | ||
354 | } | ||
355 | |||
356 | le32_add_cpu(&xv->xr_clusters, -len); | ||
357 | |||
358 | ret = ocfs2_journal_dirty(handle, root_bh); | ||
359 | if (ret) { | ||
360 | mlog_errno(ret); | ||
361 | goto out_commit; | ||
362 | } | ||
363 | |||
364 | ret = ocfs2_truncate_log_append(osb, handle, phys_blkno, len); | ||
365 | if (ret) | ||
366 | mlog_errno(ret); | ||
367 | |||
368 | out_commit: | ||
369 | ocfs2_commit_trans(osb, handle); | ||
370 | out: | ||
371 | mutex_unlock(&tl_inode->i_mutex); | ||
372 | |||
373 | if (meta_ac) | ||
374 | ocfs2_free_alloc_context(meta_ac); | ||
375 | |||
376 | return ret; | ||
377 | } | ||
378 | |||
379 | static int ocfs2_xattr_shrink_size(struct inode *inode, | ||
380 | u32 old_clusters, | ||
381 | u32 new_clusters, | ||
382 | struct buffer_head *root_bh, | ||
383 | struct ocfs2_xattr_value_root *xv) | ||
384 | { | ||
385 | int ret = 0; | ||
386 | u32 trunc_len, cpos, phys_cpos, alloc_size; | ||
387 | u64 block; | ||
388 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
389 | struct ocfs2_cached_dealloc_ctxt dealloc; | ||
390 | |||
391 | ocfs2_init_dealloc_ctxt(&dealloc); | ||
392 | |||
393 | if (old_clusters <= new_clusters) | ||
394 | return 0; | ||
395 | |||
396 | cpos = new_clusters; | ||
397 | trunc_len = old_clusters - new_clusters; | ||
398 | while (trunc_len) { | ||
399 | ret = ocfs2_xattr_get_clusters(inode, cpos, &phys_cpos, | ||
400 | &alloc_size, &xv->xr_list); | ||
401 | if (ret) { | ||
402 | mlog_errno(ret); | ||
403 | goto out; | ||
404 | } | ||
405 | |||
406 | if (alloc_size > trunc_len) | ||
407 | alloc_size = trunc_len; | ||
408 | |||
409 | ret = __ocfs2_remove_xattr_range(inode, root_bh, xv, cpos, | ||
410 | phys_cpos, alloc_size, | ||
411 | &dealloc); | ||
412 | if (ret) { | ||
413 | mlog_errno(ret); | ||
414 | goto out; | ||
415 | } | ||
416 | |||
417 | block = ocfs2_clusters_to_blocks(inode->i_sb, phys_cpos); | ||
418 | ocfs2_remove_xattr_clusters_from_cache(inode, block, | ||
419 | alloc_size); | ||
420 | cpos += alloc_size; | ||
421 | trunc_len -= alloc_size; | ||
422 | } | ||
423 | |||
424 | out: | ||
425 | ocfs2_schedule_truncate_log_flush(osb, 1); | ||
426 | ocfs2_run_deallocs(osb, &dealloc); | ||
427 | |||
428 | return ret; | ||
429 | } | ||
430 | |||
431 | static int ocfs2_xattr_value_truncate(struct inode *inode, | ||
432 | struct buffer_head *root_bh, | ||
433 | struct ocfs2_xattr_value_root *xv, | ||
434 | int len) | ||
435 | { | ||
436 | int ret; | ||
437 | u32 new_clusters = ocfs2_clusters_for_bytes(inode->i_sb, len); | ||
438 | u32 old_clusters = le32_to_cpu(xv->xr_clusters); | ||
439 | |||
440 | if (new_clusters == old_clusters) | ||
441 | return 0; | ||
442 | |||
443 | if (new_clusters > old_clusters) | ||
444 | ret = ocfs2_xattr_extend_allocation(inode, | ||
445 | new_clusters - old_clusters, | ||
446 | root_bh, xv); | ||
447 | else | ||
448 | ret = ocfs2_xattr_shrink_size(inode, | ||
449 | old_clusters, new_clusters, | ||
450 | root_bh, xv); | ||
451 | |||
452 | return ret; | ||
453 | } | ||
454 | |||
455 | static int ocfs2_xattr_list_entry(char *buffer, size_t size, | ||
456 | size_t *result, const char *prefix, | ||
457 | const char *name, int name_len) | ||
458 | { | ||
459 | char *p = buffer + *result; | ||
460 | int prefix_len = strlen(prefix); | ||
461 | int total_len = prefix_len + name_len + 1; | ||
462 | |||
463 | *result += total_len; | ||
464 | |||
465 | /* we are just looking for how big our buffer needs to be */ | ||
466 | if (!size) | ||
467 | return 0; | ||
468 | |||
469 | if (*result > size) | ||
470 | return -ERANGE; | ||
471 | |||
472 | memcpy(p, prefix, prefix_len); | ||
473 | memcpy(p + prefix_len, name, name_len); | ||
474 | p[prefix_len + name_len] = '\0'; | ||
475 | |||
476 | return 0; | ||
477 | } | ||
478 | |||
479 | static int ocfs2_xattr_list_entries(struct inode *inode, | ||
480 | struct ocfs2_xattr_header *header, | ||
481 | char *buffer, size_t buffer_size) | ||
482 | { | ||
483 | size_t result = 0; | ||
484 | int i, type, ret; | ||
485 | const char *prefix, *name; | ||
486 | |||
487 | for (i = 0 ; i < le16_to_cpu(header->xh_count); i++) { | ||
488 | struct ocfs2_xattr_entry *entry = &header->xh_entries[i]; | ||
489 | type = ocfs2_xattr_get_type(entry); | ||
490 | prefix = ocfs2_xattr_prefix(type); | ||
491 | |||
492 | if (prefix) { | ||
493 | name = (const char *)header + | ||
494 | le16_to_cpu(entry->xe_name_offset); | ||
495 | |||
496 | ret = ocfs2_xattr_list_entry(buffer, buffer_size, | ||
497 | &result, prefix, name, | ||
498 | entry->xe_name_len); | ||
499 | if (ret) | ||
500 | return ret; | ||
501 | } | ||
502 | } | ||
503 | |||
504 | return result; | ||
505 | } | ||
506 | |||
507 | static int ocfs2_xattr_ibody_list(struct inode *inode, | ||
508 | struct ocfs2_dinode *di, | ||
509 | char *buffer, | ||
510 | size_t buffer_size) | ||
511 | { | ||
512 | struct ocfs2_xattr_header *header = NULL; | ||
513 | struct ocfs2_inode_info *oi = OCFS2_I(inode); | ||
514 | int ret = 0; | ||
515 | |||
516 | if (!(oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL)) | ||
517 | return ret; | ||
518 | |||
519 | header = (struct ocfs2_xattr_header *) | ||
520 | ((void *)di + inode->i_sb->s_blocksize - | ||
521 | le16_to_cpu(di->i_xattr_inline_size)); | ||
522 | |||
523 | ret = ocfs2_xattr_list_entries(inode, header, buffer, buffer_size); | ||
524 | |||
525 | return ret; | ||
526 | } | ||
527 | |||
528 | static int ocfs2_xattr_block_list(struct inode *inode, | ||
529 | struct ocfs2_dinode *di, | ||
530 | char *buffer, | ||
531 | size_t buffer_size) | ||
532 | { | ||
533 | struct buffer_head *blk_bh = NULL; | ||
534 | struct ocfs2_xattr_block *xb; | ||
535 | int ret = 0; | ||
536 | |||
537 | if (!di->i_xattr_loc) | ||
538 | return ret; | ||
539 | |||
540 | ret = ocfs2_read_block(inode, le64_to_cpu(di->i_xattr_loc), &blk_bh); | ||
541 | if (ret < 0) { | ||
542 | mlog_errno(ret); | ||
543 | return ret; | ||
544 | } | ||
545 | /*Verify the signature of xattr block*/ | ||
546 | if (memcmp((void *)blk_bh->b_data, OCFS2_XATTR_BLOCK_SIGNATURE, | ||
547 | strlen(OCFS2_XATTR_BLOCK_SIGNATURE))) { | ||
548 | ret = -EFAULT; | ||
549 | goto cleanup; | ||
550 | } | ||
551 | |||
552 | xb = (struct ocfs2_xattr_block *)blk_bh->b_data; | ||
553 | |||
554 | if (!(le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED)) { | ||
555 | struct ocfs2_xattr_header *header = &xb->xb_attrs.xb_header; | ||
556 | ret = ocfs2_xattr_list_entries(inode, header, | ||
557 | buffer, buffer_size); | ||
558 | } else { | ||
559 | struct ocfs2_xattr_tree_root *xt = &xb->xb_attrs.xb_root; | ||
560 | ret = ocfs2_xattr_tree_list_index_block(inode, xt, | ||
561 | buffer, buffer_size); | ||
562 | } | ||
563 | cleanup: | ||
564 | brelse(blk_bh); | ||
565 | |||
566 | return ret; | ||
567 | } | ||
568 | |||
569 | ssize_t ocfs2_listxattr(struct dentry *dentry, | ||
570 | char *buffer, | ||
571 | size_t size) | ||
572 | { | ||
573 | int ret = 0, i_ret = 0, b_ret = 0; | ||
574 | struct buffer_head *di_bh = NULL; | ||
575 | struct ocfs2_dinode *di = NULL; | ||
576 | struct ocfs2_inode_info *oi = OCFS2_I(dentry->d_inode); | ||
577 | |||
578 | if (!ocfs2_supports_xattr(OCFS2_SB(dentry->d_sb))) | ||
579 | return -EOPNOTSUPP; | ||
580 | |||
581 | if (!(oi->ip_dyn_features & OCFS2_HAS_XATTR_FL)) | ||
582 | return ret; | ||
583 | |||
584 | ret = ocfs2_inode_lock(dentry->d_inode, &di_bh, 0); | ||
585 | if (ret < 0) { | ||
586 | mlog_errno(ret); | ||
587 | return ret; | ||
588 | } | ||
589 | |||
590 | di = (struct ocfs2_dinode *)di_bh->b_data; | ||
591 | |||
592 | down_read(&oi->ip_xattr_sem); | ||
593 | i_ret = ocfs2_xattr_ibody_list(dentry->d_inode, di, buffer, size); | ||
594 | if (i_ret < 0) | ||
595 | b_ret = 0; | ||
596 | else { | ||
597 | if (buffer) { | ||
598 | buffer += i_ret; | ||
599 | size -= i_ret; | ||
600 | } | ||
601 | b_ret = ocfs2_xattr_block_list(dentry->d_inode, di, | ||
602 | buffer, size); | ||
603 | if (b_ret < 0) | ||
604 | i_ret = 0; | ||
605 | } | ||
606 | up_read(&oi->ip_xattr_sem); | ||
607 | ocfs2_inode_unlock(dentry->d_inode, 0); | ||
608 | |||
609 | brelse(di_bh); | ||
610 | |||
611 | return i_ret + b_ret; | ||
612 | } | ||
613 | |||
614 | static int ocfs2_xattr_find_entry(int name_index, | ||
615 | const char *name, | ||
616 | struct ocfs2_xattr_search *xs) | ||
617 | { | ||
618 | struct ocfs2_xattr_entry *entry; | ||
619 | size_t name_len; | ||
620 | int i, cmp = 1; | ||
621 | |||
622 | if (name == NULL) | ||
623 | return -EINVAL; | ||
624 | |||
625 | name_len = strlen(name); | ||
626 | entry = xs->here; | ||
627 | for (i = 0; i < le16_to_cpu(xs->header->xh_count); i++) { | ||
628 | cmp = name_index - ocfs2_xattr_get_type(entry); | ||
629 | if (!cmp) | ||
630 | cmp = name_len - entry->xe_name_len; | ||
631 | if (!cmp) | ||
632 | cmp = memcmp(name, (xs->base + | ||
633 | le16_to_cpu(entry->xe_name_offset)), | ||
634 | name_len); | ||
635 | if (cmp == 0) | ||
636 | break; | ||
637 | entry += 1; | ||
638 | } | ||
639 | xs->here = entry; | ||
640 | |||
641 | return cmp ? -ENODATA : 0; | ||
642 | } | ||
643 | |||
644 | static int ocfs2_xattr_get_value_outside(struct inode *inode, | ||
645 | struct ocfs2_xattr_value_root *xv, | ||
646 | void *buffer, | ||
647 | size_t len) | ||
648 | { | ||
649 | u32 cpos, p_cluster, num_clusters, bpc, clusters; | ||
650 | u64 blkno; | ||
651 | int i, ret = 0; | ||
652 | size_t cplen, blocksize; | ||
653 | struct buffer_head *bh = NULL; | ||
654 | struct ocfs2_extent_list *el; | ||
655 | |||
656 | el = &xv->xr_list; | ||
657 | clusters = le32_to_cpu(xv->xr_clusters); | ||
658 | bpc = ocfs2_clusters_to_blocks(inode->i_sb, 1); | ||
659 | blocksize = inode->i_sb->s_blocksize; | ||
660 | |||
661 | cpos = 0; | ||
662 | while (cpos < clusters) { | ||
663 | ret = ocfs2_xattr_get_clusters(inode, cpos, &p_cluster, | ||
664 | &num_clusters, el); | ||
665 | if (ret) { | ||
666 | mlog_errno(ret); | ||
667 | goto out; | ||
668 | } | ||
669 | |||
670 | blkno = ocfs2_clusters_to_blocks(inode->i_sb, p_cluster); | ||
671 | /* Copy ocfs2_xattr_value */ | ||
672 | for (i = 0; i < num_clusters * bpc; i++, blkno++) { | ||
673 | ret = ocfs2_read_block(inode, blkno, &bh); | ||
674 | if (ret) { | ||
675 | mlog_errno(ret); | ||
676 | goto out; | ||
677 | } | ||
678 | |||
679 | cplen = len >= blocksize ? blocksize : len; | ||
680 | memcpy(buffer, bh->b_data, cplen); | ||
681 | len -= cplen; | ||
682 | buffer += cplen; | ||
683 | |||
684 | brelse(bh); | ||
685 | bh = NULL; | ||
686 | if (len == 0) | ||
687 | break; | ||
688 | } | ||
689 | cpos += num_clusters; | ||
690 | } | ||
691 | out: | ||
692 | return ret; | ||
693 | } | ||
694 | |||
695 | static int ocfs2_xattr_ibody_get(struct inode *inode, | ||
696 | int name_index, | ||
697 | const char *name, | ||
698 | void *buffer, | ||
699 | size_t buffer_size, | ||
700 | struct ocfs2_xattr_search *xs) | ||
701 | { | ||
702 | struct ocfs2_inode_info *oi = OCFS2_I(inode); | ||
703 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)xs->inode_bh->b_data; | ||
704 | struct ocfs2_xattr_value_root *xv; | ||
705 | size_t size; | ||
706 | int ret = 0; | ||
707 | |||
708 | if (!(oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL)) | ||
709 | return -ENODATA; | ||
710 | |||
711 | xs->end = (void *)di + inode->i_sb->s_blocksize; | ||
712 | xs->header = (struct ocfs2_xattr_header *) | ||
713 | (xs->end - le16_to_cpu(di->i_xattr_inline_size)); | ||
714 | xs->base = (void *)xs->header; | ||
715 | xs->here = xs->header->xh_entries; | ||
716 | |||
717 | ret = ocfs2_xattr_find_entry(name_index, name, xs); | ||
718 | if (ret) | ||
719 | return ret; | ||
720 | size = le64_to_cpu(xs->here->xe_value_size); | ||
721 | if (buffer) { | ||
722 | if (size > buffer_size) | ||
723 | return -ERANGE; | ||
724 | if (ocfs2_xattr_is_local(xs->here)) { | ||
725 | memcpy(buffer, (void *)xs->base + | ||
726 | le16_to_cpu(xs->here->xe_name_offset) + | ||
727 | OCFS2_XATTR_SIZE(xs->here->xe_name_len), size); | ||
728 | } else { | ||
729 | xv = (struct ocfs2_xattr_value_root *) | ||
730 | (xs->base + le16_to_cpu( | ||
731 | xs->here->xe_name_offset) + | ||
732 | OCFS2_XATTR_SIZE(xs->here->xe_name_len)); | ||
733 | ret = ocfs2_xattr_get_value_outside(inode, xv, | ||
734 | buffer, size); | ||
735 | if (ret < 0) { | ||
736 | mlog_errno(ret); | ||
737 | return ret; | ||
738 | } | ||
739 | } | ||
740 | } | ||
741 | |||
742 | return size; | ||
743 | } | ||
744 | |||
745 | static int ocfs2_xattr_block_get(struct inode *inode, | ||
746 | int name_index, | ||
747 | const char *name, | ||
748 | void *buffer, | ||
749 | size_t buffer_size, | ||
750 | struct ocfs2_xattr_search *xs) | ||
751 | { | ||
752 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)xs->inode_bh->b_data; | ||
753 | struct buffer_head *blk_bh = NULL; | ||
754 | struct ocfs2_xattr_block *xb; | ||
755 | struct ocfs2_xattr_value_root *xv; | ||
756 | size_t size; | ||
757 | int ret = -ENODATA, name_offset, name_len, block_off, i; | ||
758 | |||
759 | if (!di->i_xattr_loc) | ||
760 | return ret; | ||
761 | |||
762 | memset(&xs->bucket, 0, sizeof(xs->bucket)); | ||
763 | |||
764 | ret = ocfs2_read_block(inode, le64_to_cpu(di->i_xattr_loc), &blk_bh); | ||
765 | if (ret < 0) { | ||
766 | mlog_errno(ret); | ||
767 | return ret; | ||
768 | } | ||
769 | /*Verify the signature of xattr block*/ | ||
770 | if (memcmp((void *)blk_bh->b_data, OCFS2_XATTR_BLOCK_SIGNATURE, | ||
771 | strlen(OCFS2_XATTR_BLOCK_SIGNATURE))) { | ||
772 | ret = -EFAULT; | ||
773 | goto cleanup; | ||
774 | } | ||
775 | |||
776 | xs->xattr_bh = blk_bh; | ||
777 | xb = (struct ocfs2_xattr_block *)blk_bh->b_data; | ||
778 | |||
779 | if (!(le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED)) { | ||
780 | xs->header = &xb->xb_attrs.xb_header; | ||
781 | xs->base = (void *)xs->header; | ||
782 | xs->end = (void *)(blk_bh->b_data) + blk_bh->b_size; | ||
783 | xs->here = xs->header->xh_entries; | ||
784 | |||
785 | ret = ocfs2_xattr_find_entry(name_index, name, xs); | ||
786 | } else | ||
787 | ret = ocfs2_xattr_index_block_find(inode, blk_bh, | ||
788 | name_index, | ||
789 | name, xs); | ||
790 | |||
791 | if (ret) | ||
792 | goto cleanup; | ||
793 | size = le64_to_cpu(xs->here->xe_value_size); | ||
794 | if (buffer) { | ||
795 | ret = -ERANGE; | ||
796 | if (size > buffer_size) | ||
797 | goto cleanup; | ||
798 | |||
799 | name_offset = le16_to_cpu(xs->here->xe_name_offset); | ||
800 | name_len = OCFS2_XATTR_SIZE(xs->here->xe_name_len); | ||
801 | i = xs->here - xs->header->xh_entries; | ||
802 | |||
803 | if (le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED) { | ||
804 | ret = ocfs2_xattr_bucket_get_name_value(inode, | ||
805 | xs->bucket.xh, | ||
806 | i, | ||
807 | &block_off, | ||
808 | &name_offset); | ||
809 | xs->base = xs->bucket.bhs[block_off]->b_data; | ||
810 | } | ||
811 | if (ocfs2_xattr_is_local(xs->here)) { | ||
812 | memcpy(buffer, (void *)xs->base + | ||
813 | name_offset + name_len, size); | ||
814 | } else { | ||
815 | xv = (struct ocfs2_xattr_value_root *) | ||
816 | (xs->base + name_offset + name_len); | ||
817 | ret = ocfs2_xattr_get_value_outside(inode, xv, | ||
818 | buffer, size); | ||
819 | if (ret < 0) { | ||
820 | mlog_errno(ret); | ||
821 | goto cleanup; | ||
822 | } | ||
823 | } | ||
824 | } | ||
825 | ret = size; | ||
826 | cleanup: | ||
827 | for (i = 0; i < OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET; i++) | ||
828 | brelse(xs->bucket.bhs[i]); | ||
829 | memset(&xs->bucket, 0, sizeof(xs->bucket)); | ||
830 | |||
831 | brelse(blk_bh); | ||
832 | return ret; | ||
833 | } | ||
834 | |||
835 | /* ocfs2_xattr_get() | ||
836 | * | ||
837 | * Copy an extended attribute into the buffer provided. | ||
838 | * Buffer is NULL to compute the size of buffer required. | ||
839 | */ | ||
840 | int ocfs2_xattr_get(struct inode *inode, | ||
841 | int name_index, | ||
842 | const char *name, | ||
843 | void *buffer, | ||
844 | size_t buffer_size) | ||
845 | { | ||
846 | int ret; | ||
847 | struct ocfs2_dinode *di = NULL; | ||
848 | struct buffer_head *di_bh = NULL; | ||
849 | struct ocfs2_inode_info *oi = OCFS2_I(inode); | ||
850 | struct ocfs2_xattr_search xis = { | ||
851 | .not_found = -ENODATA, | ||
852 | }; | ||
853 | struct ocfs2_xattr_search xbs = { | ||
854 | .not_found = -ENODATA, | ||
855 | }; | ||
856 | |||
857 | if (!ocfs2_supports_xattr(OCFS2_SB(inode->i_sb))) | ||
858 | return -EOPNOTSUPP; | ||
859 | |||
860 | if (!(oi->ip_dyn_features & OCFS2_HAS_XATTR_FL)) | ||
861 | ret = -ENODATA; | ||
862 | |||
863 | ret = ocfs2_inode_lock(inode, &di_bh, 0); | ||
864 | if (ret < 0) { | ||
865 | mlog_errno(ret); | ||
866 | return ret; | ||
867 | } | ||
868 | xis.inode_bh = xbs.inode_bh = di_bh; | ||
869 | di = (struct ocfs2_dinode *)di_bh->b_data; | ||
870 | |||
871 | down_read(&oi->ip_xattr_sem); | ||
872 | ret = ocfs2_xattr_ibody_get(inode, name_index, name, buffer, | ||
873 | buffer_size, &xis); | ||
874 | if (ret == -ENODATA) | ||
875 | ret = ocfs2_xattr_block_get(inode, name_index, name, buffer, | ||
876 | buffer_size, &xbs); | ||
877 | up_read(&oi->ip_xattr_sem); | ||
878 | ocfs2_inode_unlock(inode, 0); | ||
879 | |||
880 | brelse(di_bh); | ||
881 | |||
882 | return ret; | ||
883 | } | ||
884 | |||
885 | static int __ocfs2_xattr_set_value_outside(struct inode *inode, | ||
886 | struct ocfs2_xattr_value_root *xv, | ||
887 | const void *value, | ||
888 | int value_len) | ||
889 | { | ||
890 | int ret = 0, i, cp_len, credits; | ||
891 | u16 blocksize = inode->i_sb->s_blocksize; | ||
892 | u32 p_cluster, num_clusters; | ||
893 | u32 cpos = 0, bpc = ocfs2_clusters_to_blocks(inode->i_sb, 1); | ||
894 | u32 clusters = ocfs2_clusters_for_bytes(inode->i_sb, value_len); | ||
895 | u64 blkno; | ||
896 | struct buffer_head *bh = NULL; | ||
897 | handle_t *handle; | ||
898 | |||
899 | BUG_ON(clusters > le32_to_cpu(xv->xr_clusters)); | ||
900 | |||
901 | credits = clusters * bpc; | ||
902 | handle = ocfs2_start_trans(OCFS2_SB(inode->i_sb), credits); | ||
903 | if (IS_ERR(handle)) { | ||
904 | ret = PTR_ERR(handle); | ||
905 | mlog_errno(ret); | ||
906 | goto out; | ||
907 | } | ||
908 | |||
909 | while (cpos < clusters) { | ||
910 | ret = ocfs2_xattr_get_clusters(inode, cpos, &p_cluster, | ||
911 | &num_clusters, &xv->xr_list); | ||
912 | if (ret) { | ||
913 | mlog_errno(ret); | ||
914 | goto out_commit; | ||
915 | } | ||
916 | |||
917 | blkno = ocfs2_clusters_to_blocks(inode->i_sb, p_cluster); | ||
918 | |||
919 | for (i = 0; i < num_clusters * bpc; i++, blkno++) { | ||
920 | ret = ocfs2_read_block(inode, blkno, &bh); | ||
921 | if (ret) { | ||
922 | mlog_errno(ret); | ||
923 | goto out_commit; | ||
924 | } | ||
925 | |||
926 | ret = ocfs2_journal_access(handle, | ||
927 | inode, | ||
928 | bh, | ||
929 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
930 | if (ret < 0) { | ||
931 | mlog_errno(ret); | ||
932 | goto out_commit; | ||
933 | } | ||
934 | |||
935 | cp_len = value_len > blocksize ? blocksize : value_len; | ||
936 | memcpy(bh->b_data, value, cp_len); | ||
937 | value_len -= cp_len; | ||
938 | value += cp_len; | ||
939 | if (cp_len < blocksize) | ||
940 | memset(bh->b_data + cp_len, 0, | ||
941 | blocksize - cp_len); | ||
942 | |||
943 | ret = ocfs2_journal_dirty(handle, bh); | ||
944 | if (ret < 0) { | ||
945 | mlog_errno(ret); | ||
946 | goto out_commit; | ||
947 | } | ||
948 | brelse(bh); | ||
949 | bh = NULL; | ||
950 | |||
951 | /* | ||
952 | * XXX: do we need to empty all the following | ||
953 | * blocks in this cluster? | ||
954 | */ | ||
955 | if (!value_len) | ||
956 | break; | ||
957 | } | ||
958 | cpos += num_clusters; | ||
959 | } | ||
960 | out_commit: | ||
961 | ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle); | ||
962 | out: | ||
963 | brelse(bh); | ||
964 | |||
965 | return ret; | ||
966 | } | ||
967 | |||
968 | static int ocfs2_xattr_cleanup(struct inode *inode, | ||
969 | struct ocfs2_xattr_info *xi, | ||
970 | struct ocfs2_xattr_search *xs, | ||
971 | size_t offs) | ||
972 | { | ||
973 | handle_t *handle = NULL; | ||
974 | int ret = 0; | ||
975 | size_t name_len = strlen(xi->name); | ||
976 | void *val = xs->base + offs; | ||
977 | size_t size = OCFS2_XATTR_SIZE(name_len) + OCFS2_XATTR_ROOT_SIZE; | ||
978 | |||
979 | handle = ocfs2_start_trans((OCFS2_SB(inode->i_sb)), | ||
980 | OCFS2_XATTR_BLOCK_UPDATE_CREDITS); | ||
981 | if (IS_ERR(handle)) { | ||
982 | ret = PTR_ERR(handle); | ||
983 | mlog_errno(ret); | ||
984 | goto out; | ||
985 | } | ||
986 | ret = ocfs2_journal_access(handle, inode, xs->xattr_bh, | ||
987 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
988 | if (ret) { | ||
989 | mlog_errno(ret); | ||
990 | goto out_commit; | ||
991 | } | ||
992 | /* Decrease xattr count */ | ||
993 | le16_add_cpu(&xs->header->xh_count, -1); | ||
994 | /* Remove the xattr entry and tree root which has already be set*/ | ||
995 | memset((void *)xs->here, 0, sizeof(struct ocfs2_xattr_entry)); | ||
996 | memset(val, 0, size); | ||
997 | |||
998 | ret = ocfs2_journal_dirty(handle, xs->xattr_bh); | ||
999 | if (ret < 0) | ||
1000 | mlog_errno(ret); | ||
1001 | out_commit: | ||
1002 | ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle); | ||
1003 | out: | ||
1004 | return ret; | ||
1005 | } | ||
1006 | |||
1007 | static int ocfs2_xattr_update_entry(struct inode *inode, | ||
1008 | struct ocfs2_xattr_info *xi, | ||
1009 | struct ocfs2_xattr_search *xs, | ||
1010 | size_t offs) | ||
1011 | { | ||
1012 | handle_t *handle = NULL; | ||
1013 | int ret = 0; | ||
1014 | |||
1015 | handle = ocfs2_start_trans((OCFS2_SB(inode->i_sb)), | ||
1016 | OCFS2_XATTR_BLOCK_UPDATE_CREDITS); | ||
1017 | if (IS_ERR(handle)) { | ||
1018 | ret = PTR_ERR(handle); | ||
1019 | mlog_errno(ret); | ||
1020 | goto out; | ||
1021 | } | ||
1022 | ret = ocfs2_journal_access(handle, inode, xs->xattr_bh, | ||
1023 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
1024 | if (ret) { | ||
1025 | mlog_errno(ret); | ||
1026 | goto out_commit; | ||
1027 | } | ||
1028 | |||
1029 | xs->here->xe_name_offset = cpu_to_le16(offs); | ||
1030 | xs->here->xe_value_size = cpu_to_le64(xi->value_len); | ||
1031 | if (xi->value_len <= OCFS2_XATTR_INLINE_SIZE) | ||
1032 | ocfs2_xattr_set_local(xs->here, 1); | ||
1033 | else | ||
1034 | ocfs2_xattr_set_local(xs->here, 0); | ||
1035 | ocfs2_xattr_hash_entry(inode, xs->header, xs->here); | ||
1036 | |||
1037 | ret = ocfs2_journal_dirty(handle, xs->xattr_bh); | ||
1038 | if (ret < 0) | ||
1039 | mlog_errno(ret); | ||
1040 | out_commit: | ||
1041 | ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle); | ||
1042 | out: | ||
1043 | return ret; | ||
1044 | } | ||
1045 | |||
1046 | /* | ||
1047 | * ocfs2_xattr_set_value_outside() | ||
1048 | * | ||
1049 | * Set large size value in B tree. | ||
1050 | */ | ||
1051 | static int ocfs2_xattr_set_value_outside(struct inode *inode, | ||
1052 | struct ocfs2_xattr_info *xi, | ||
1053 | struct ocfs2_xattr_search *xs, | ||
1054 | size_t offs) | ||
1055 | { | ||
1056 | size_t name_len = strlen(xi->name); | ||
1057 | void *val = xs->base + offs; | ||
1058 | struct ocfs2_xattr_value_root *xv = NULL; | ||
1059 | size_t size = OCFS2_XATTR_SIZE(name_len) + OCFS2_XATTR_ROOT_SIZE; | ||
1060 | int ret = 0; | ||
1061 | |||
1062 | memset(val, 0, size); | ||
1063 | memcpy(val, xi->name, name_len); | ||
1064 | xv = (struct ocfs2_xattr_value_root *) | ||
1065 | (val + OCFS2_XATTR_SIZE(name_len)); | ||
1066 | xv->xr_clusters = 0; | ||
1067 | xv->xr_last_eb_blk = 0; | ||
1068 | xv->xr_list.l_tree_depth = 0; | ||
1069 | xv->xr_list.l_count = cpu_to_le16(1); | ||
1070 | xv->xr_list.l_next_free_rec = 0; | ||
1071 | |||
1072 | ret = ocfs2_xattr_value_truncate(inode, xs->xattr_bh, xv, | ||
1073 | xi->value_len); | ||
1074 | if (ret < 0) { | ||
1075 | mlog_errno(ret); | ||
1076 | return ret; | ||
1077 | } | ||
1078 | ret = __ocfs2_xattr_set_value_outside(inode, xv, xi->value, | ||
1079 | xi->value_len); | ||
1080 | if (ret < 0) { | ||
1081 | mlog_errno(ret); | ||
1082 | return ret; | ||
1083 | } | ||
1084 | ret = ocfs2_xattr_update_entry(inode, xi, xs, offs); | ||
1085 | if (ret < 0) | ||
1086 | mlog_errno(ret); | ||
1087 | |||
1088 | return ret; | ||
1089 | } | ||
1090 | |||
1091 | /* | ||
1092 | * ocfs2_xattr_set_entry_local() | ||
1093 | * | ||
1094 | * Set, replace or remove extended attribute in local. | ||
1095 | */ | ||
1096 | static void ocfs2_xattr_set_entry_local(struct inode *inode, | ||
1097 | struct ocfs2_xattr_info *xi, | ||
1098 | struct ocfs2_xattr_search *xs, | ||
1099 | struct ocfs2_xattr_entry *last, | ||
1100 | size_t min_offs) | ||
1101 | { | ||
1102 | size_t name_len = strlen(xi->name); | ||
1103 | int i; | ||
1104 | |||
1105 | if (xi->value && xs->not_found) { | ||
1106 | /* Insert the new xattr entry. */ | ||
1107 | le16_add_cpu(&xs->header->xh_count, 1); | ||
1108 | ocfs2_xattr_set_type(last, xi->name_index); | ||
1109 | ocfs2_xattr_set_local(last, 1); | ||
1110 | last->xe_name_len = name_len; | ||
1111 | } else { | ||
1112 | void *first_val; | ||
1113 | void *val; | ||
1114 | size_t offs, size; | ||
1115 | |||
1116 | first_val = xs->base + min_offs; | ||
1117 | offs = le16_to_cpu(xs->here->xe_name_offset); | ||
1118 | val = xs->base + offs; | ||
1119 | |||
1120 | if (le64_to_cpu(xs->here->xe_value_size) > | ||
1121 | OCFS2_XATTR_INLINE_SIZE) | ||
1122 | size = OCFS2_XATTR_SIZE(name_len) + | ||
1123 | OCFS2_XATTR_ROOT_SIZE; | ||
1124 | else | ||
1125 | size = OCFS2_XATTR_SIZE(name_len) + | ||
1126 | OCFS2_XATTR_SIZE(le64_to_cpu(xs->here->xe_value_size)); | ||
1127 | |||
1128 | if (xi->value && size == OCFS2_XATTR_SIZE(name_len) + | ||
1129 | OCFS2_XATTR_SIZE(xi->value_len)) { | ||
1130 | /* The old and the new value have the | ||
1131 | same size. Just replace the value. */ | ||
1132 | ocfs2_xattr_set_local(xs->here, 1); | ||
1133 | xs->here->xe_value_size = cpu_to_le64(xi->value_len); | ||
1134 | /* Clear value bytes. */ | ||
1135 | memset(val + OCFS2_XATTR_SIZE(name_len), | ||
1136 | 0, | ||
1137 | OCFS2_XATTR_SIZE(xi->value_len)); | ||
1138 | memcpy(val + OCFS2_XATTR_SIZE(name_len), | ||
1139 | xi->value, | ||
1140 | xi->value_len); | ||
1141 | return; | ||
1142 | } | ||
1143 | /* Remove the old name+value. */ | ||
1144 | memmove(first_val + size, first_val, val - first_val); | ||
1145 | memset(first_val, 0, size); | ||
1146 | xs->here->xe_name_hash = 0; | ||
1147 | xs->here->xe_name_offset = 0; | ||
1148 | ocfs2_xattr_set_local(xs->here, 1); | ||
1149 | xs->here->xe_value_size = 0; | ||
1150 | |||
1151 | min_offs += size; | ||
1152 | |||
1153 | /* Adjust all value offsets. */ | ||
1154 | last = xs->header->xh_entries; | ||
1155 | for (i = 0 ; i < le16_to_cpu(xs->header->xh_count); i++) { | ||
1156 | size_t o = le16_to_cpu(last->xe_name_offset); | ||
1157 | |||
1158 | if (o < offs) | ||
1159 | last->xe_name_offset = cpu_to_le16(o + size); | ||
1160 | last += 1; | ||
1161 | } | ||
1162 | |||
1163 | if (!xi->value) { | ||
1164 | /* Remove the old entry. */ | ||
1165 | last -= 1; | ||
1166 | memmove(xs->here, xs->here + 1, | ||
1167 | (void *)last - (void *)xs->here); | ||
1168 | memset(last, 0, sizeof(struct ocfs2_xattr_entry)); | ||
1169 | le16_add_cpu(&xs->header->xh_count, -1); | ||
1170 | } | ||
1171 | } | ||
1172 | if (xi->value) { | ||
1173 | /* Insert the new name+value. */ | ||
1174 | size_t size = OCFS2_XATTR_SIZE(name_len) + | ||
1175 | OCFS2_XATTR_SIZE(xi->value_len); | ||
1176 | void *val = xs->base + min_offs - size; | ||
1177 | |||
1178 | xs->here->xe_name_offset = cpu_to_le16(min_offs - size); | ||
1179 | memset(val, 0, size); | ||
1180 | memcpy(val, xi->name, name_len); | ||
1181 | memcpy(val + OCFS2_XATTR_SIZE(name_len), | ||
1182 | xi->value, | ||
1183 | xi->value_len); | ||
1184 | xs->here->xe_value_size = cpu_to_le64(xi->value_len); | ||
1185 | ocfs2_xattr_set_local(xs->here, 1); | ||
1186 | ocfs2_xattr_hash_entry(inode, xs->header, xs->here); | ||
1187 | } | ||
1188 | |||
1189 | return; | ||
1190 | } | ||
1191 | |||
1192 | /* | ||
1193 | * ocfs2_xattr_set_entry() | ||
1194 | * | ||
1195 | * Set extended attribute entry into inode or block. | ||
1196 | * | ||
1197 | * If extended attribute value size > OCFS2_XATTR_INLINE_SIZE, | ||
1198 | * We first insert tree root(ocfs2_xattr_value_root) with set_entry_local(), | ||
1199 | * then set value in B tree with set_value_outside(). | ||
1200 | */ | ||
1201 | static int ocfs2_xattr_set_entry(struct inode *inode, | ||
1202 | struct ocfs2_xattr_info *xi, | ||
1203 | struct ocfs2_xattr_search *xs, | ||
1204 | int flag) | ||
1205 | { | ||
1206 | struct ocfs2_xattr_entry *last; | ||
1207 | struct ocfs2_inode_info *oi = OCFS2_I(inode); | ||
1208 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)xs->inode_bh->b_data; | ||
1209 | size_t min_offs = xs->end - xs->base, name_len = strlen(xi->name); | ||
1210 | size_t size_l = 0; | ||
1211 | handle_t *handle = NULL; | ||
1212 | int free, i, ret; | ||
1213 | struct ocfs2_xattr_info xi_l = { | ||
1214 | .name_index = xi->name_index, | ||
1215 | .name = xi->name, | ||
1216 | .value = xi->value, | ||
1217 | .value_len = xi->value_len, | ||
1218 | }; | ||
1219 | |||
1220 | /* Compute min_offs, last and free space. */ | ||
1221 | last = xs->header->xh_entries; | ||
1222 | |||
1223 | for (i = 0 ; i < le16_to_cpu(xs->header->xh_count); i++) { | ||
1224 | size_t offs = le16_to_cpu(last->xe_name_offset); | ||
1225 | if (offs < min_offs) | ||
1226 | min_offs = offs; | ||
1227 | last += 1; | ||
1228 | } | ||
1229 | |||
1230 | free = min_offs - ((void *)last - xs->base) - sizeof(__u32); | ||
1231 | if (free < 0) | ||
1232 | return -EFAULT; | ||
1233 | |||
1234 | if (!xs->not_found) { | ||
1235 | size_t size = 0; | ||
1236 | if (ocfs2_xattr_is_local(xs->here)) | ||
1237 | size = OCFS2_XATTR_SIZE(name_len) + | ||
1238 | OCFS2_XATTR_SIZE(le64_to_cpu(xs->here->xe_value_size)); | ||
1239 | else | ||
1240 | size = OCFS2_XATTR_SIZE(name_len) + | ||
1241 | OCFS2_XATTR_ROOT_SIZE; | ||
1242 | free += (size + sizeof(struct ocfs2_xattr_entry)); | ||
1243 | } | ||
1244 | /* Check free space in inode or block */ | ||
1245 | if (xi->value && xi->value_len > OCFS2_XATTR_INLINE_SIZE) { | ||
1246 | if (free < sizeof(struct ocfs2_xattr_entry) + | ||
1247 | OCFS2_XATTR_SIZE(name_len) + | ||
1248 | OCFS2_XATTR_ROOT_SIZE) { | ||
1249 | ret = -ENOSPC; | ||
1250 | goto out; | ||
1251 | } | ||
1252 | size_l = OCFS2_XATTR_SIZE(name_len) + OCFS2_XATTR_ROOT_SIZE; | ||
1253 | xi_l.value = (void *)&def_xv; | ||
1254 | xi_l.value_len = OCFS2_XATTR_ROOT_SIZE; | ||
1255 | } else if (xi->value) { | ||
1256 | if (free < sizeof(struct ocfs2_xattr_entry) + | ||
1257 | OCFS2_XATTR_SIZE(name_len) + | ||
1258 | OCFS2_XATTR_SIZE(xi->value_len)) { | ||
1259 | ret = -ENOSPC; | ||
1260 | goto out; | ||
1261 | } | ||
1262 | } | ||
1263 | |||
1264 | if (!xs->not_found) { | ||
1265 | /* For existing extended attribute */ | ||
1266 | size_t size = OCFS2_XATTR_SIZE(name_len) + | ||
1267 | OCFS2_XATTR_SIZE(le64_to_cpu(xs->here->xe_value_size)); | ||
1268 | size_t offs = le16_to_cpu(xs->here->xe_name_offset); | ||
1269 | void *val = xs->base + offs; | ||
1270 | |||
1271 | if (ocfs2_xattr_is_local(xs->here) && size == size_l) { | ||
1272 | /* Replace existing local xattr with tree root */ | ||
1273 | ret = ocfs2_xattr_set_value_outside(inode, xi, xs, | ||
1274 | offs); | ||
1275 | if (ret < 0) | ||
1276 | mlog_errno(ret); | ||
1277 | goto out; | ||
1278 | } else if (!ocfs2_xattr_is_local(xs->here)) { | ||
1279 | /* For existing xattr which has value outside */ | ||
1280 | struct ocfs2_xattr_value_root *xv = NULL; | ||
1281 | xv = (struct ocfs2_xattr_value_root *)(val + | ||
1282 | OCFS2_XATTR_SIZE(name_len)); | ||
1283 | |||
1284 | if (xi->value_len > OCFS2_XATTR_INLINE_SIZE) { | ||
1285 | /* | ||
1286 | * If new value need set outside also, | ||
1287 | * first truncate old value to new value, | ||
1288 | * then set new value with set_value_outside(). | ||
1289 | */ | ||
1290 | ret = ocfs2_xattr_value_truncate(inode, | ||
1291 | xs->xattr_bh, | ||
1292 | xv, | ||
1293 | xi->value_len); | ||
1294 | if (ret < 0) { | ||
1295 | mlog_errno(ret); | ||
1296 | goto out; | ||
1297 | } | ||
1298 | |||
1299 | ret = __ocfs2_xattr_set_value_outside(inode, | ||
1300 | xv, | ||
1301 | xi->value, | ||
1302 | xi->value_len); | ||
1303 | if (ret < 0) { | ||
1304 | mlog_errno(ret); | ||
1305 | goto out; | ||
1306 | } | ||
1307 | |||
1308 | ret = ocfs2_xattr_update_entry(inode, | ||
1309 | xi, | ||
1310 | xs, | ||
1311 | offs); | ||
1312 | if (ret < 0) | ||
1313 | mlog_errno(ret); | ||
1314 | goto out; | ||
1315 | } else { | ||
1316 | /* | ||
1317 | * If new value need set in local, | ||
1318 | * just trucate old value to zero. | ||
1319 | */ | ||
1320 | ret = ocfs2_xattr_value_truncate(inode, | ||
1321 | xs->xattr_bh, | ||
1322 | xv, | ||
1323 | 0); | ||
1324 | if (ret < 0) | ||
1325 | mlog_errno(ret); | ||
1326 | } | ||
1327 | } | ||
1328 | } | ||
1329 | |||
1330 | handle = ocfs2_start_trans((OCFS2_SB(inode->i_sb)), | ||
1331 | OCFS2_INODE_UPDATE_CREDITS); | ||
1332 | if (IS_ERR(handle)) { | ||
1333 | ret = PTR_ERR(handle); | ||
1334 | mlog_errno(ret); | ||
1335 | goto out; | ||
1336 | } | ||
1337 | |||
1338 | ret = ocfs2_journal_access(handle, inode, xs->inode_bh, | ||
1339 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
1340 | if (ret) { | ||
1341 | mlog_errno(ret); | ||
1342 | goto out_commit; | ||
1343 | } | ||
1344 | |||
1345 | if (!(flag & OCFS2_INLINE_XATTR_FL)) { | ||
1346 | /* set extended attribute in external block. */ | ||
1347 | ret = ocfs2_extend_trans(handle, | ||
1348 | OCFS2_INODE_UPDATE_CREDITS + | ||
1349 | OCFS2_XATTR_BLOCK_UPDATE_CREDITS); | ||
1350 | if (ret) { | ||
1351 | mlog_errno(ret); | ||
1352 | goto out_commit; | ||
1353 | } | ||
1354 | ret = ocfs2_journal_access(handle, inode, xs->xattr_bh, | ||
1355 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
1356 | if (ret) { | ||
1357 | mlog_errno(ret); | ||
1358 | goto out_commit; | ||
1359 | } | ||
1360 | } | ||
1361 | |||
1362 | /* | ||
1363 | * Set value in local, include set tree root in local. | ||
1364 | * This is the first step for value size >INLINE_SIZE. | ||
1365 | */ | ||
1366 | ocfs2_xattr_set_entry_local(inode, &xi_l, xs, last, min_offs); | ||
1367 | |||
1368 | if (!(flag & OCFS2_INLINE_XATTR_FL)) { | ||
1369 | ret = ocfs2_journal_dirty(handle, xs->xattr_bh); | ||
1370 | if (ret < 0) { | ||
1371 | mlog_errno(ret); | ||
1372 | goto out_commit; | ||
1373 | } | ||
1374 | } | ||
1375 | |||
1376 | if (!(oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL) && | ||
1377 | (flag & OCFS2_INLINE_XATTR_FL)) { | ||
1378 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
1379 | unsigned int xattrsize = osb->s_xattr_inline_size; | ||
1380 | |||
1381 | /* | ||
1382 | * Adjust extent record count or inline data size | ||
1383 | * to reserve space for extended attribute. | ||
1384 | */ | ||
1385 | if (oi->ip_dyn_features & OCFS2_INLINE_DATA_FL) { | ||
1386 | struct ocfs2_inline_data *idata = &di->id2.i_data; | ||
1387 | le16_add_cpu(&idata->id_count, -xattrsize); | ||
1388 | } else if (!(ocfs2_inode_is_fast_symlink(inode))) { | ||
1389 | struct ocfs2_extent_list *el = &di->id2.i_list; | ||
1390 | le16_add_cpu(&el->l_count, -(xattrsize / | ||
1391 | sizeof(struct ocfs2_extent_rec))); | ||
1392 | } | ||
1393 | di->i_xattr_inline_size = cpu_to_le16(xattrsize); | ||
1394 | } | ||
1395 | /* Update xattr flag */ | ||
1396 | spin_lock(&oi->ip_lock); | ||
1397 | oi->ip_dyn_features |= flag; | ||
1398 | di->i_dyn_features = cpu_to_le16(oi->ip_dyn_features); | ||
1399 | spin_unlock(&oi->ip_lock); | ||
1400 | /* Update inode ctime */ | ||
1401 | inode->i_ctime = CURRENT_TIME; | ||
1402 | di->i_ctime = cpu_to_le64(inode->i_ctime.tv_sec); | ||
1403 | di->i_ctime_nsec = cpu_to_le32(inode->i_ctime.tv_nsec); | ||
1404 | |||
1405 | ret = ocfs2_journal_dirty(handle, xs->inode_bh); | ||
1406 | if (ret < 0) | ||
1407 | mlog_errno(ret); | ||
1408 | |||
1409 | out_commit: | ||
1410 | ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle); | ||
1411 | |||
1412 | if (!ret && xi->value_len > OCFS2_XATTR_INLINE_SIZE) { | ||
1413 | /* | ||
1414 | * Set value outside in B tree. | ||
1415 | * This is the second step for value size > INLINE_SIZE. | ||
1416 | */ | ||
1417 | size_t offs = le16_to_cpu(xs->here->xe_name_offset); | ||
1418 | ret = ocfs2_xattr_set_value_outside(inode, xi, xs, offs); | ||
1419 | if (ret < 0) { | ||
1420 | int ret2; | ||
1421 | |||
1422 | mlog_errno(ret); | ||
1423 | /* | ||
1424 | * If set value outside failed, we have to clean | ||
1425 | * the junk tree root we have already set in local. | ||
1426 | */ | ||
1427 | ret2 = ocfs2_xattr_cleanup(inode, xi, xs, offs); | ||
1428 | if (ret2 < 0) | ||
1429 | mlog_errno(ret2); | ||
1430 | } | ||
1431 | } | ||
1432 | out: | ||
1433 | return ret; | ||
1434 | |||
1435 | } | ||
1436 | |||
1437 | static int ocfs2_remove_value_outside(struct inode*inode, | ||
1438 | struct buffer_head *bh, | ||
1439 | struct ocfs2_xattr_header *header) | ||
1440 | { | ||
1441 | int ret = 0, i; | ||
1442 | |||
1443 | for (i = 0; i < le16_to_cpu(header->xh_count); i++) { | ||
1444 | struct ocfs2_xattr_entry *entry = &header->xh_entries[i]; | ||
1445 | |||
1446 | if (!ocfs2_xattr_is_local(entry)) { | ||
1447 | struct ocfs2_xattr_value_root *xv; | ||
1448 | void *val; | ||
1449 | |||
1450 | val = (void *)header + | ||
1451 | le16_to_cpu(entry->xe_name_offset); | ||
1452 | xv = (struct ocfs2_xattr_value_root *) | ||
1453 | (val + OCFS2_XATTR_SIZE(entry->xe_name_len)); | ||
1454 | ret = ocfs2_xattr_value_truncate(inode, bh, xv, 0); | ||
1455 | if (ret < 0) { | ||
1456 | mlog_errno(ret); | ||
1457 | return ret; | ||
1458 | } | ||
1459 | } | ||
1460 | } | ||
1461 | |||
1462 | return ret; | ||
1463 | } | ||
1464 | |||
1465 | static int ocfs2_xattr_ibody_remove(struct inode *inode, | ||
1466 | struct buffer_head *di_bh) | ||
1467 | { | ||
1468 | |||
1469 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; | ||
1470 | struct ocfs2_xattr_header *header; | ||
1471 | int ret; | ||
1472 | |||
1473 | header = (struct ocfs2_xattr_header *) | ||
1474 | ((void *)di + inode->i_sb->s_blocksize - | ||
1475 | le16_to_cpu(di->i_xattr_inline_size)); | ||
1476 | |||
1477 | ret = ocfs2_remove_value_outside(inode, di_bh, header); | ||
1478 | |||
1479 | return ret; | ||
1480 | } | ||
1481 | |||
1482 | static int ocfs2_xattr_block_remove(struct inode *inode, | ||
1483 | struct buffer_head *blk_bh) | ||
1484 | { | ||
1485 | struct ocfs2_xattr_block *xb; | ||
1486 | int ret = 0; | ||
1487 | |||
1488 | xb = (struct ocfs2_xattr_block *)blk_bh->b_data; | ||
1489 | if (!(le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED)) { | ||
1490 | struct ocfs2_xattr_header *header = &(xb->xb_attrs.xb_header); | ||
1491 | ret = ocfs2_remove_value_outside(inode, blk_bh, header); | ||
1492 | } else | ||
1493 | ret = ocfs2_delete_xattr_index_block(inode, blk_bh); | ||
1494 | |||
1495 | return ret; | ||
1496 | } | ||
1497 | |||
1498 | static int ocfs2_xattr_free_block(struct inode *inode, | ||
1499 | u64 block) | ||
1500 | { | ||
1501 | struct inode *xb_alloc_inode; | ||
1502 | struct buffer_head *xb_alloc_bh = NULL; | ||
1503 | struct buffer_head *blk_bh = NULL; | ||
1504 | struct ocfs2_xattr_block *xb; | ||
1505 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
1506 | handle_t *handle; | ||
1507 | int ret = 0; | ||
1508 | u64 blk, bg_blkno; | ||
1509 | u16 bit; | ||
1510 | |||
1511 | ret = ocfs2_read_block(inode, block, &blk_bh); | ||
1512 | if (ret < 0) { | ||
1513 | mlog_errno(ret); | ||
1514 | goto out; | ||
1515 | } | ||
1516 | |||
1517 | /*Verify the signature of xattr block*/ | ||
1518 | if (memcmp((void *)blk_bh->b_data, OCFS2_XATTR_BLOCK_SIGNATURE, | ||
1519 | strlen(OCFS2_XATTR_BLOCK_SIGNATURE))) { | ||
1520 | ret = -EFAULT; | ||
1521 | goto out; | ||
1522 | } | ||
1523 | |||
1524 | ret = ocfs2_xattr_block_remove(inode, blk_bh); | ||
1525 | if (ret < 0) { | ||
1526 | mlog_errno(ret); | ||
1527 | goto out; | ||
1528 | } | ||
1529 | |||
1530 | xb = (struct ocfs2_xattr_block *)blk_bh->b_data; | ||
1531 | blk = le64_to_cpu(xb->xb_blkno); | ||
1532 | bit = le16_to_cpu(xb->xb_suballoc_bit); | ||
1533 | bg_blkno = ocfs2_which_suballoc_group(blk, bit); | ||
1534 | |||
1535 | xb_alloc_inode = ocfs2_get_system_file_inode(osb, | ||
1536 | EXTENT_ALLOC_SYSTEM_INODE, | ||
1537 | le16_to_cpu(xb->xb_suballoc_slot)); | ||
1538 | if (!xb_alloc_inode) { | ||
1539 | ret = -ENOMEM; | ||
1540 | mlog_errno(ret); | ||
1541 | goto out; | ||
1542 | } | ||
1543 | mutex_lock(&xb_alloc_inode->i_mutex); | ||
1544 | |||
1545 | ret = ocfs2_inode_lock(xb_alloc_inode, &xb_alloc_bh, 1); | ||
1546 | if (ret < 0) { | ||
1547 | mlog_errno(ret); | ||
1548 | goto out_mutex; | ||
1549 | } | ||
1550 | |||
1551 | handle = ocfs2_start_trans(osb, OCFS2_SUBALLOC_FREE); | ||
1552 | if (IS_ERR(handle)) { | ||
1553 | ret = PTR_ERR(handle); | ||
1554 | mlog_errno(ret); | ||
1555 | goto out_unlock; | ||
1556 | } | ||
1557 | |||
1558 | ret = ocfs2_free_suballoc_bits(handle, xb_alloc_inode, xb_alloc_bh, | ||
1559 | bit, bg_blkno, 1); | ||
1560 | if (ret < 0) | ||
1561 | mlog_errno(ret); | ||
1562 | |||
1563 | ocfs2_commit_trans(osb, handle); | ||
1564 | out_unlock: | ||
1565 | ocfs2_inode_unlock(xb_alloc_inode, 1); | ||
1566 | brelse(xb_alloc_bh); | ||
1567 | out_mutex: | ||
1568 | mutex_unlock(&xb_alloc_inode->i_mutex); | ||
1569 | iput(xb_alloc_inode); | ||
1570 | out: | ||
1571 | brelse(blk_bh); | ||
1572 | return ret; | ||
1573 | } | ||
1574 | |||
1575 | /* | ||
1576 | * ocfs2_xattr_remove() | ||
1577 | * | ||
1578 | * Free extended attribute resources associated with this inode. | ||
1579 | */ | ||
1580 | int ocfs2_xattr_remove(struct inode *inode, struct buffer_head *di_bh) | ||
1581 | { | ||
1582 | struct ocfs2_inode_info *oi = OCFS2_I(inode); | ||
1583 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; | ||
1584 | handle_t *handle; | ||
1585 | int ret; | ||
1586 | |||
1587 | if (!ocfs2_supports_xattr(OCFS2_SB(inode->i_sb))) | ||
1588 | return 0; | ||
1589 | |||
1590 | if (!(oi->ip_dyn_features & OCFS2_HAS_XATTR_FL)) | ||
1591 | return 0; | ||
1592 | |||
1593 | if (oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL) { | ||
1594 | ret = ocfs2_xattr_ibody_remove(inode, di_bh); | ||
1595 | if (ret < 0) { | ||
1596 | mlog_errno(ret); | ||
1597 | goto out; | ||
1598 | } | ||
1599 | } | ||
1600 | |||
1601 | if (di->i_xattr_loc) { | ||
1602 | ret = ocfs2_xattr_free_block(inode, | ||
1603 | le64_to_cpu(di->i_xattr_loc)); | ||
1604 | if (ret < 0) { | ||
1605 | mlog_errno(ret); | ||
1606 | goto out; | ||
1607 | } | ||
1608 | } | ||
1609 | |||
1610 | handle = ocfs2_start_trans((OCFS2_SB(inode->i_sb)), | ||
1611 | OCFS2_INODE_UPDATE_CREDITS); | ||
1612 | if (IS_ERR(handle)) { | ||
1613 | ret = PTR_ERR(handle); | ||
1614 | mlog_errno(ret); | ||
1615 | goto out; | ||
1616 | } | ||
1617 | ret = ocfs2_journal_access(handle, inode, di_bh, | ||
1618 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
1619 | if (ret) { | ||
1620 | mlog_errno(ret); | ||
1621 | goto out_commit; | ||
1622 | } | ||
1623 | |||
1624 | di->i_xattr_loc = 0; | ||
1625 | |||
1626 | spin_lock(&oi->ip_lock); | ||
1627 | oi->ip_dyn_features &= ~(OCFS2_INLINE_XATTR_FL | OCFS2_HAS_XATTR_FL); | ||
1628 | di->i_dyn_features = cpu_to_le16(oi->ip_dyn_features); | ||
1629 | spin_unlock(&oi->ip_lock); | ||
1630 | |||
1631 | ret = ocfs2_journal_dirty(handle, di_bh); | ||
1632 | if (ret < 0) | ||
1633 | mlog_errno(ret); | ||
1634 | out_commit: | ||
1635 | ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle); | ||
1636 | out: | ||
1637 | return ret; | ||
1638 | } | ||
1639 | |||
1640 | static int ocfs2_xattr_has_space_inline(struct inode *inode, | ||
1641 | struct ocfs2_dinode *di) | ||
1642 | { | ||
1643 | struct ocfs2_inode_info *oi = OCFS2_I(inode); | ||
1644 | unsigned int xattrsize = OCFS2_SB(inode->i_sb)->s_xattr_inline_size; | ||
1645 | int free; | ||
1646 | |||
1647 | if (xattrsize < OCFS2_MIN_XATTR_INLINE_SIZE) | ||
1648 | return 0; | ||
1649 | |||
1650 | if (oi->ip_dyn_features & OCFS2_INLINE_DATA_FL) { | ||
1651 | struct ocfs2_inline_data *idata = &di->id2.i_data; | ||
1652 | free = le16_to_cpu(idata->id_count) - le64_to_cpu(di->i_size); | ||
1653 | } else if (ocfs2_inode_is_fast_symlink(inode)) { | ||
1654 | free = ocfs2_fast_symlink_chars(inode->i_sb) - | ||
1655 | le64_to_cpu(di->i_size); | ||
1656 | } else { | ||
1657 | struct ocfs2_extent_list *el = &di->id2.i_list; | ||
1658 | free = (le16_to_cpu(el->l_count) - | ||
1659 | le16_to_cpu(el->l_next_free_rec)) * | ||
1660 | sizeof(struct ocfs2_extent_rec); | ||
1661 | } | ||
1662 | if (free >= xattrsize) | ||
1663 | return 1; | ||
1664 | |||
1665 | return 0; | ||
1666 | } | ||
1667 | |||
1668 | /* | ||
1669 | * ocfs2_xattr_ibody_find() | ||
1670 | * | ||
1671 | * Find extended attribute in inode block and | ||
1672 | * fill search info into struct ocfs2_xattr_search. | ||
1673 | */ | ||
1674 | static int ocfs2_xattr_ibody_find(struct inode *inode, | ||
1675 | int name_index, | ||
1676 | const char *name, | ||
1677 | struct ocfs2_xattr_search *xs) | ||
1678 | { | ||
1679 | struct ocfs2_inode_info *oi = OCFS2_I(inode); | ||
1680 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)xs->inode_bh->b_data; | ||
1681 | int ret; | ||
1682 | int has_space = 0; | ||
1683 | |||
1684 | if (inode->i_sb->s_blocksize == OCFS2_MIN_BLOCKSIZE) | ||
1685 | return 0; | ||
1686 | |||
1687 | if (!(oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL)) { | ||
1688 | down_read(&oi->ip_alloc_sem); | ||
1689 | has_space = ocfs2_xattr_has_space_inline(inode, di); | ||
1690 | up_read(&oi->ip_alloc_sem); | ||
1691 | if (!has_space) | ||
1692 | return 0; | ||
1693 | } | ||
1694 | |||
1695 | xs->xattr_bh = xs->inode_bh; | ||
1696 | xs->end = (void *)di + inode->i_sb->s_blocksize; | ||
1697 | if (oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL) | ||
1698 | xs->header = (struct ocfs2_xattr_header *) | ||
1699 | (xs->end - le16_to_cpu(di->i_xattr_inline_size)); | ||
1700 | else | ||
1701 | xs->header = (struct ocfs2_xattr_header *) | ||
1702 | (xs->end - OCFS2_SB(inode->i_sb)->s_xattr_inline_size); | ||
1703 | xs->base = (void *)xs->header; | ||
1704 | xs->here = xs->header->xh_entries; | ||
1705 | |||
1706 | /* Find the named attribute. */ | ||
1707 | if (oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL) { | ||
1708 | ret = ocfs2_xattr_find_entry(name_index, name, xs); | ||
1709 | if (ret && ret != -ENODATA) | ||
1710 | return ret; | ||
1711 | xs->not_found = ret; | ||
1712 | } | ||
1713 | |||
1714 | return 0; | ||
1715 | } | ||
1716 | |||
1717 | /* | ||
1718 | * ocfs2_xattr_ibody_set() | ||
1719 | * | ||
1720 | * Set, replace or remove an extended attribute into inode block. | ||
1721 | * | ||
1722 | */ | ||
1723 | static int ocfs2_xattr_ibody_set(struct inode *inode, | ||
1724 | struct ocfs2_xattr_info *xi, | ||
1725 | struct ocfs2_xattr_search *xs) | ||
1726 | { | ||
1727 | struct ocfs2_inode_info *oi = OCFS2_I(inode); | ||
1728 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)xs->inode_bh->b_data; | ||
1729 | int ret; | ||
1730 | |||
1731 | if (inode->i_sb->s_blocksize == OCFS2_MIN_BLOCKSIZE) | ||
1732 | return -ENOSPC; | ||
1733 | |||
1734 | down_write(&oi->ip_alloc_sem); | ||
1735 | if (!(oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL)) { | ||
1736 | if (!ocfs2_xattr_has_space_inline(inode, di)) { | ||
1737 | ret = -ENOSPC; | ||
1738 | goto out; | ||
1739 | } | ||
1740 | } | ||
1741 | |||
1742 | ret = ocfs2_xattr_set_entry(inode, xi, xs, | ||
1743 | (OCFS2_INLINE_XATTR_FL | OCFS2_HAS_XATTR_FL)); | ||
1744 | out: | ||
1745 | up_write(&oi->ip_alloc_sem); | ||
1746 | |||
1747 | return ret; | ||
1748 | } | ||
1749 | |||
1750 | /* | ||
1751 | * ocfs2_xattr_block_find() | ||
1752 | * | ||
1753 | * Find extended attribute in external block and | ||
1754 | * fill search info into struct ocfs2_xattr_search. | ||
1755 | */ | ||
1756 | static int ocfs2_xattr_block_find(struct inode *inode, | ||
1757 | int name_index, | ||
1758 | const char *name, | ||
1759 | struct ocfs2_xattr_search *xs) | ||
1760 | { | ||
1761 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)xs->inode_bh->b_data; | ||
1762 | struct buffer_head *blk_bh = NULL; | ||
1763 | struct ocfs2_xattr_block *xb; | ||
1764 | int ret = 0; | ||
1765 | |||
1766 | if (!di->i_xattr_loc) | ||
1767 | return ret; | ||
1768 | |||
1769 | ret = ocfs2_read_block(inode, le64_to_cpu(di->i_xattr_loc), &blk_bh); | ||
1770 | if (ret < 0) { | ||
1771 | mlog_errno(ret); | ||
1772 | return ret; | ||
1773 | } | ||
1774 | /*Verify the signature of xattr block*/ | ||
1775 | if (memcmp((void *)blk_bh->b_data, OCFS2_XATTR_BLOCK_SIGNATURE, | ||
1776 | strlen(OCFS2_XATTR_BLOCK_SIGNATURE))) { | ||
1777 | ret = -EFAULT; | ||
1778 | goto cleanup; | ||
1779 | } | ||
1780 | |||
1781 | xs->xattr_bh = blk_bh; | ||
1782 | xb = (struct ocfs2_xattr_block *)blk_bh->b_data; | ||
1783 | |||
1784 | if (!(le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED)) { | ||
1785 | xs->header = &xb->xb_attrs.xb_header; | ||
1786 | xs->base = (void *)xs->header; | ||
1787 | xs->end = (void *)(blk_bh->b_data) + blk_bh->b_size; | ||
1788 | xs->here = xs->header->xh_entries; | ||
1789 | |||
1790 | ret = ocfs2_xattr_find_entry(name_index, name, xs); | ||
1791 | } else | ||
1792 | ret = ocfs2_xattr_index_block_find(inode, blk_bh, | ||
1793 | name_index, | ||
1794 | name, xs); | ||
1795 | |||
1796 | if (ret && ret != -ENODATA) { | ||
1797 | xs->xattr_bh = NULL; | ||
1798 | goto cleanup; | ||
1799 | } | ||
1800 | xs->not_found = ret; | ||
1801 | return 0; | ||
1802 | cleanup: | ||
1803 | brelse(blk_bh); | ||
1804 | |||
1805 | return ret; | ||
1806 | } | ||
1807 | |||
1808 | /* | ||
1809 | * When all the xattrs are deleted from index btree, the ocfs2_xattr_tree | ||
1810 | * will be erased and ocfs2_xattr_block will have its ocfs2_xattr_header | ||
1811 | * re-initialized. | ||
1812 | */ | ||
1813 | static int ocfs2_restore_xattr_block(struct inode *inode, | ||
1814 | struct ocfs2_xattr_search *xs) | ||
1815 | { | ||
1816 | int ret; | ||
1817 | handle_t *handle; | ||
1818 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
1819 | struct ocfs2_xattr_block *xb = | ||
1820 | (struct ocfs2_xattr_block *)xs->xattr_bh->b_data; | ||
1821 | struct ocfs2_extent_list *el = &xb->xb_attrs.xb_root.xt_list; | ||
1822 | u16 xb_flags = le16_to_cpu(xb->xb_flags); | ||
1823 | |||
1824 | BUG_ON(!(xb_flags & OCFS2_XATTR_INDEXED) || | ||
1825 | le16_to_cpu(el->l_next_free_rec) != 0); | ||
1826 | |||
1827 | handle = ocfs2_start_trans(osb, OCFS2_XATTR_BLOCK_UPDATE_CREDITS); | ||
1828 | if (IS_ERR(handle)) { | ||
1829 | ret = PTR_ERR(handle); | ||
1830 | handle = NULL; | ||
1831 | goto out; | ||
1832 | } | ||
1833 | |||
1834 | ret = ocfs2_journal_access(handle, inode, xs->xattr_bh, | ||
1835 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
1836 | if (ret < 0) { | ||
1837 | mlog_errno(ret); | ||
1838 | goto out_commit; | ||
1839 | } | ||
1840 | |||
1841 | memset(&xb->xb_attrs, 0, inode->i_sb->s_blocksize - | ||
1842 | offsetof(struct ocfs2_xattr_block, xb_attrs)); | ||
1843 | |||
1844 | xb->xb_flags = cpu_to_le16(xb_flags & ~OCFS2_XATTR_INDEXED); | ||
1845 | |||
1846 | ocfs2_journal_dirty(handle, xs->xattr_bh); | ||
1847 | |||
1848 | out_commit: | ||
1849 | ocfs2_commit_trans(osb, handle); | ||
1850 | out: | ||
1851 | return ret; | ||
1852 | } | ||
1853 | |||
1854 | /* | ||
1855 | * ocfs2_xattr_block_set() | ||
1856 | * | ||
1857 | * Set, replace or remove an extended attribute into external block. | ||
1858 | * | ||
1859 | */ | ||
1860 | static int ocfs2_xattr_block_set(struct inode *inode, | ||
1861 | struct ocfs2_xattr_info *xi, | ||
1862 | struct ocfs2_xattr_search *xs) | ||
1863 | { | ||
1864 | struct buffer_head *new_bh = NULL; | ||
1865 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
1866 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)xs->inode_bh->b_data; | ||
1867 | struct ocfs2_alloc_context *meta_ac = NULL; | ||
1868 | handle_t *handle = NULL; | ||
1869 | struct ocfs2_xattr_block *xblk = NULL; | ||
1870 | u16 suballoc_bit_start; | ||
1871 | u32 num_got; | ||
1872 | u64 first_blkno; | ||
1873 | int ret; | ||
1874 | |||
1875 | if (!xs->xattr_bh) { | ||
1876 | /* | ||
1877 | * Alloc one external block for extended attribute | ||
1878 | * outside of inode. | ||
1879 | */ | ||
1880 | ret = ocfs2_reserve_new_metadata_blocks(osb, 1, &meta_ac); | ||
1881 | if (ret < 0) { | ||
1882 | mlog_errno(ret); | ||
1883 | goto out; | ||
1884 | } | ||
1885 | handle = ocfs2_start_trans(osb, | ||
1886 | OCFS2_XATTR_BLOCK_CREATE_CREDITS); | ||
1887 | if (IS_ERR(handle)) { | ||
1888 | ret = PTR_ERR(handle); | ||
1889 | mlog_errno(ret); | ||
1890 | goto out; | ||
1891 | } | ||
1892 | ret = ocfs2_journal_access(handle, inode, xs->inode_bh, | ||
1893 | OCFS2_JOURNAL_ACCESS_CREATE); | ||
1894 | if (ret < 0) { | ||
1895 | mlog_errno(ret); | ||
1896 | goto out_commit; | ||
1897 | } | ||
1898 | |||
1899 | ret = ocfs2_claim_metadata(osb, handle, meta_ac, 1, | ||
1900 | &suballoc_bit_start, &num_got, | ||
1901 | &first_blkno); | ||
1902 | if (ret < 0) { | ||
1903 | mlog_errno(ret); | ||
1904 | goto out_commit; | ||
1905 | } | ||
1906 | |||
1907 | new_bh = sb_getblk(inode->i_sb, first_blkno); | ||
1908 | ocfs2_set_new_buffer_uptodate(inode, new_bh); | ||
1909 | |||
1910 | ret = ocfs2_journal_access(handle, inode, new_bh, | ||
1911 | OCFS2_JOURNAL_ACCESS_CREATE); | ||
1912 | if (ret < 0) { | ||
1913 | mlog_errno(ret); | ||
1914 | goto out_commit; | ||
1915 | } | ||
1916 | |||
1917 | /* Initialize ocfs2_xattr_block */ | ||
1918 | xs->xattr_bh = new_bh; | ||
1919 | xblk = (struct ocfs2_xattr_block *)new_bh->b_data; | ||
1920 | memset(xblk, 0, inode->i_sb->s_blocksize); | ||
1921 | strcpy((void *)xblk, OCFS2_XATTR_BLOCK_SIGNATURE); | ||
1922 | xblk->xb_suballoc_slot = cpu_to_le16(osb->slot_num); | ||
1923 | xblk->xb_suballoc_bit = cpu_to_le16(suballoc_bit_start); | ||
1924 | xblk->xb_fs_generation = cpu_to_le32(osb->fs_generation); | ||
1925 | xblk->xb_blkno = cpu_to_le64(first_blkno); | ||
1926 | |||
1927 | xs->header = &xblk->xb_attrs.xb_header; | ||
1928 | xs->base = (void *)xs->header; | ||
1929 | xs->end = (void *)xblk + inode->i_sb->s_blocksize; | ||
1930 | xs->here = xs->header->xh_entries; | ||
1931 | |||
1932 | |||
1933 | ret = ocfs2_journal_dirty(handle, new_bh); | ||
1934 | if (ret < 0) { | ||
1935 | mlog_errno(ret); | ||
1936 | goto out_commit; | ||
1937 | } | ||
1938 | di->i_xattr_loc = cpu_to_le64(first_blkno); | ||
1939 | ret = ocfs2_journal_dirty(handle, xs->inode_bh); | ||
1940 | if (ret < 0) | ||
1941 | mlog_errno(ret); | ||
1942 | out_commit: | ||
1943 | ocfs2_commit_trans(osb, handle); | ||
1944 | out: | ||
1945 | if (meta_ac) | ||
1946 | ocfs2_free_alloc_context(meta_ac); | ||
1947 | if (ret < 0) | ||
1948 | return ret; | ||
1949 | } else | ||
1950 | xblk = (struct ocfs2_xattr_block *)xs->xattr_bh->b_data; | ||
1951 | |||
1952 | if (!(le16_to_cpu(xblk->xb_flags) & OCFS2_XATTR_INDEXED)) { | ||
1953 | /* Set extended attribute into external block */ | ||
1954 | ret = ocfs2_xattr_set_entry(inode, xi, xs, OCFS2_HAS_XATTR_FL); | ||
1955 | if (!ret || ret != -ENOSPC) | ||
1956 | goto end; | ||
1957 | |||
1958 | ret = ocfs2_xattr_create_index_block(inode, xs); | ||
1959 | if (ret) | ||
1960 | goto end; | ||
1961 | } | ||
1962 | |||
1963 | ret = ocfs2_xattr_set_entry_index_block(inode, xi, xs); | ||
1964 | if (!ret && xblk->xb_attrs.xb_root.xt_list.l_next_free_rec == 0) | ||
1965 | ret = ocfs2_restore_xattr_block(inode, xs); | ||
1966 | |||
1967 | end: | ||
1968 | |||
1969 | return ret; | ||
1970 | } | ||
1971 | |||
1972 | /* | ||
1973 | * ocfs2_xattr_set() | ||
1974 | * | ||
1975 | * Set, replace or remove an extended attribute for this inode. | ||
1976 | * value is NULL to remove an existing extended attribute, else either | ||
1977 | * create or replace an extended attribute. | ||
1978 | */ | ||
1979 | int ocfs2_xattr_set(struct inode *inode, | ||
1980 | int name_index, | ||
1981 | const char *name, | ||
1982 | const void *value, | ||
1983 | size_t value_len, | ||
1984 | int flags) | ||
1985 | { | ||
1986 | struct buffer_head *di_bh = NULL; | ||
1987 | struct ocfs2_dinode *di; | ||
1988 | int ret; | ||
1989 | u16 i, blk_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb); | ||
1990 | |||
1991 | struct ocfs2_xattr_info xi = { | ||
1992 | .name_index = name_index, | ||
1993 | .name = name, | ||
1994 | .value = value, | ||
1995 | .value_len = value_len, | ||
1996 | }; | ||
1997 | |||
1998 | struct ocfs2_xattr_search xis = { | ||
1999 | .not_found = -ENODATA, | ||
2000 | }; | ||
2001 | |||
2002 | struct ocfs2_xattr_search xbs = { | ||
2003 | .not_found = -ENODATA, | ||
2004 | }; | ||
2005 | |||
2006 | if (!ocfs2_supports_xattr(OCFS2_SB(inode->i_sb))) | ||
2007 | return -EOPNOTSUPP; | ||
2008 | |||
2009 | ret = ocfs2_inode_lock(inode, &di_bh, 1); | ||
2010 | if (ret < 0) { | ||
2011 | mlog_errno(ret); | ||
2012 | return ret; | ||
2013 | } | ||
2014 | xis.inode_bh = xbs.inode_bh = di_bh; | ||
2015 | di = (struct ocfs2_dinode *)di_bh->b_data; | ||
2016 | |||
2017 | down_write(&OCFS2_I(inode)->ip_xattr_sem); | ||
2018 | /* | ||
2019 | * Scan inode and external block to find the same name | ||
2020 | * extended attribute and collect search infomation. | ||
2021 | */ | ||
2022 | ret = ocfs2_xattr_ibody_find(inode, name_index, name, &xis); | ||
2023 | if (ret) | ||
2024 | goto cleanup; | ||
2025 | if (xis.not_found) { | ||
2026 | ret = ocfs2_xattr_block_find(inode, name_index, name, &xbs); | ||
2027 | if (ret) | ||
2028 | goto cleanup; | ||
2029 | } | ||
2030 | |||
2031 | if (xis.not_found && xbs.not_found) { | ||
2032 | ret = -ENODATA; | ||
2033 | if (flags & XATTR_REPLACE) | ||
2034 | goto cleanup; | ||
2035 | ret = 0; | ||
2036 | if (!value) | ||
2037 | goto cleanup; | ||
2038 | } else { | ||
2039 | ret = -EEXIST; | ||
2040 | if (flags & XATTR_CREATE) | ||
2041 | goto cleanup; | ||
2042 | } | ||
2043 | |||
2044 | if (!value) { | ||
2045 | /* Remove existing extended attribute */ | ||
2046 | if (!xis.not_found) | ||
2047 | ret = ocfs2_xattr_ibody_set(inode, &xi, &xis); | ||
2048 | else if (!xbs.not_found) | ||
2049 | ret = ocfs2_xattr_block_set(inode, &xi, &xbs); | ||
2050 | } else { | ||
2051 | /* We always try to set extended attribute into inode first*/ | ||
2052 | ret = ocfs2_xattr_ibody_set(inode, &xi, &xis); | ||
2053 | if (!ret && !xbs.not_found) { | ||
2054 | /* | ||
2055 | * If succeed and that extended attribute existing in | ||
2056 | * external block, then we will remove it. | ||
2057 | */ | ||
2058 | xi.value = NULL; | ||
2059 | xi.value_len = 0; | ||
2060 | ret = ocfs2_xattr_block_set(inode, &xi, &xbs); | ||
2061 | } else if (ret == -ENOSPC) { | ||
2062 | if (di->i_xattr_loc && !xbs.xattr_bh) { | ||
2063 | ret = ocfs2_xattr_block_find(inode, name_index, | ||
2064 | name, &xbs); | ||
2065 | if (ret) | ||
2066 | goto cleanup; | ||
2067 | } | ||
2068 | /* | ||
2069 | * If no space in inode, we will set extended attribute | ||
2070 | * into external block. | ||
2071 | */ | ||
2072 | ret = ocfs2_xattr_block_set(inode, &xi, &xbs); | ||
2073 | if (ret) | ||
2074 | goto cleanup; | ||
2075 | if (!xis.not_found) { | ||
2076 | /* | ||
2077 | * If succeed and that extended attribute | ||
2078 | * existing in inode, we will remove it. | ||
2079 | */ | ||
2080 | xi.value = NULL; | ||
2081 | xi.value_len = 0; | ||
2082 | ret = ocfs2_xattr_ibody_set(inode, &xi, &xis); | ||
2083 | } | ||
2084 | } | ||
2085 | } | ||
2086 | cleanup: | ||
2087 | up_write(&OCFS2_I(inode)->ip_xattr_sem); | ||
2088 | ocfs2_inode_unlock(inode, 1); | ||
2089 | brelse(di_bh); | ||
2090 | brelse(xbs.xattr_bh); | ||
2091 | for (i = 0; i < blk_per_bucket; i++) | ||
2092 | brelse(xbs.bucket.bhs[i]); | ||
2093 | |||
2094 | return ret; | ||
2095 | } | ||
2096 | |||
2097 | /* | ||
2098 | * Find the xattr extent rec which may contains name_hash. | ||
2099 | * e_cpos will be the first name hash of the xattr rec. | ||
2100 | * el must be the ocfs2_xattr_header.xb_attrs.xb_root.xt_list. | ||
2101 | */ | ||
2102 | static int ocfs2_xattr_get_rec(struct inode *inode, | ||
2103 | u32 name_hash, | ||
2104 | u64 *p_blkno, | ||
2105 | u32 *e_cpos, | ||
2106 | u32 *num_clusters, | ||
2107 | struct ocfs2_extent_list *el) | ||
2108 | { | ||
2109 | int ret = 0, i; | ||
2110 | struct buffer_head *eb_bh = NULL; | ||
2111 | struct ocfs2_extent_block *eb; | ||
2112 | struct ocfs2_extent_rec *rec = NULL; | ||
2113 | u64 e_blkno = 0; | ||
2114 | |||
2115 | if (el->l_tree_depth) { | ||
2116 | ret = ocfs2_find_leaf(inode, el, name_hash, &eb_bh); | ||
2117 | if (ret) { | ||
2118 | mlog_errno(ret); | ||
2119 | goto out; | ||
2120 | } | ||
2121 | |||
2122 | eb = (struct ocfs2_extent_block *) eb_bh->b_data; | ||
2123 | el = &eb->h_list; | ||
2124 | |||
2125 | if (el->l_tree_depth) { | ||
2126 | ocfs2_error(inode->i_sb, | ||
2127 | "Inode %lu has non zero tree depth in " | ||
2128 | "xattr tree block %llu\n", inode->i_ino, | ||
2129 | (unsigned long long)eb_bh->b_blocknr); | ||
2130 | ret = -EROFS; | ||
2131 | goto out; | ||
2132 | } | ||
2133 | } | ||
2134 | |||
2135 | for (i = le16_to_cpu(el->l_next_free_rec) - 1; i >= 0; i--) { | ||
2136 | rec = &el->l_recs[i]; | ||
2137 | |||
2138 | if (le32_to_cpu(rec->e_cpos) <= name_hash) { | ||
2139 | e_blkno = le64_to_cpu(rec->e_blkno); | ||
2140 | break; | ||
2141 | } | ||
2142 | } | ||
2143 | |||
2144 | if (!e_blkno) { | ||
2145 | ocfs2_error(inode->i_sb, "Inode %lu has bad extent " | ||
2146 | "record (%u, %u, 0) in xattr", inode->i_ino, | ||
2147 | le32_to_cpu(rec->e_cpos), | ||
2148 | ocfs2_rec_clusters(el, rec)); | ||
2149 | ret = -EROFS; | ||
2150 | goto out; | ||
2151 | } | ||
2152 | |||
2153 | *p_blkno = le64_to_cpu(rec->e_blkno); | ||
2154 | *num_clusters = le16_to_cpu(rec->e_leaf_clusters); | ||
2155 | if (e_cpos) | ||
2156 | *e_cpos = le32_to_cpu(rec->e_cpos); | ||
2157 | out: | ||
2158 | brelse(eb_bh); | ||
2159 | return ret; | ||
2160 | } | ||
2161 | |||
2162 | typedef int (xattr_bucket_func)(struct inode *inode, | ||
2163 | struct ocfs2_xattr_bucket *bucket, | ||
2164 | void *para); | ||
2165 | |||
2166 | static int ocfs2_find_xe_in_bucket(struct inode *inode, | ||
2167 | struct buffer_head *header_bh, | ||
2168 | int name_index, | ||
2169 | const char *name, | ||
2170 | u32 name_hash, | ||
2171 | u16 *xe_index, | ||
2172 | int *found) | ||
2173 | { | ||
2174 | int i, ret = 0, cmp = 1, block_off, new_offset; | ||
2175 | struct ocfs2_xattr_header *xh = | ||
2176 | (struct ocfs2_xattr_header *)header_bh->b_data; | ||
2177 | size_t name_len = strlen(name); | ||
2178 | struct ocfs2_xattr_entry *xe = NULL; | ||
2179 | struct buffer_head *name_bh = NULL; | ||
2180 | char *xe_name; | ||
2181 | |||
2182 | /* | ||
2183 | * We don't use binary search in the bucket because there | ||
2184 | * may be multiple entries with the same name hash. | ||
2185 | */ | ||
2186 | for (i = 0; i < le16_to_cpu(xh->xh_count); i++) { | ||
2187 | xe = &xh->xh_entries[i]; | ||
2188 | |||
2189 | if (name_hash > le32_to_cpu(xe->xe_name_hash)) | ||
2190 | continue; | ||
2191 | else if (name_hash < le32_to_cpu(xe->xe_name_hash)) | ||
2192 | break; | ||
2193 | |||
2194 | cmp = name_index - ocfs2_xattr_get_type(xe); | ||
2195 | if (!cmp) | ||
2196 | cmp = name_len - xe->xe_name_len; | ||
2197 | if (cmp) | ||
2198 | continue; | ||
2199 | |||
2200 | ret = ocfs2_xattr_bucket_get_name_value(inode, | ||
2201 | xh, | ||
2202 | i, | ||
2203 | &block_off, | ||
2204 | &new_offset); | ||
2205 | if (ret) { | ||
2206 | mlog_errno(ret); | ||
2207 | break; | ||
2208 | } | ||
2209 | |||
2210 | ret = ocfs2_read_block(inode, header_bh->b_blocknr + block_off, | ||
2211 | &name_bh); | ||
2212 | if (ret) { | ||
2213 | mlog_errno(ret); | ||
2214 | break; | ||
2215 | } | ||
2216 | xe_name = name_bh->b_data + new_offset; | ||
2217 | |||
2218 | cmp = memcmp(name, xe_name, name_len); | ||
2219 | brelse(name_bh); | ||
2220 | name_bh = NULL; | ||
2221 | |||
2222 | if (cmp == 0) { | ||
2223 | *xe_index = i; | ||
2224 | *found = 1; | ||
2225 | ret = 0; | ||
2226 | break; | ||
2227 | } | ||
2228 | } | ||
2229 | |||
2230 | return ret; | ||
2231 | } | ||
2232 | |||
2233 | /* | ||
2234 | * Find the specified xattr entry in a series of buckets. | ||
2235 | * This series start from p_blkno and last for num_clusters. | ||
2236 | * The ocfs2_xattr_header.xh_num_buckets of the first bucket contains | ||
2237 | * the num of the valid buckets. | ||
2238 | * | ||
2239 | * Return the buffer_head this xattr should reside in. And if the xattr's | ||
2240 | * hash is in the gap of 2 buckets, return the lower bucket. | ||
2241 | */ | ||
2242 | static int ocfs2_xattr_bucket_find(struct inode *inode, | ||
2243 | int name_index, | ||
2244 | const char *name, | ||
2245 | u32 name_hash, | ||
2246 | u64 p_blkno, | ||
2247 | u32 first_hash, | ||
2248 | u32 num_clusters, | ||
2249 | struct ocfs2_xattr_search *xs) | ||
2250 | { | ||
2251 | int ret, found = 0; | ||
2252 | struct buffer_head *bh = NULL; | ||
2253 | struct buffer_head *lower_bh = NULL; | ||
2254 | struct ocfs2_xattr_header *xh = NULL; | ||
2255 | struct ocfs2_xattr_entry *xe = NULL; | ||
2256 | u16 index = 0; | ||
2257 | u16 blk_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb); | ||
2258 | int low_bucket = 0, bucket, high_bucket; | ||
2259 | u32 last_hash; | ||
2260 | u64 blkno; | ||
2261 | |||
2262 | ret = ocfs2_read_block(inode, p_blkno, &bh); | ||
2263 | if (ret) { | ||
2264 | mlog_errno(ret); | ||
2265 | goto out; | ||
2266 | } | ||
2267 | |||
2268 | xh = (struct ocfs2_xattr_header *)bh->b_data; | ||
2269 | high_bucket = le16_to_cpu(xh->xh_num_buckets) - 1; | ||
2270 | |||
2271 | while (low_bucket <= high_bucket) { | ||
2272 | brelse(bh); | ||
2273 | bh = NULL; | ||
2274 | bucket = (low_bucket + high_bucket) / 2; | ||
2275 | |||
2276 | blkno = p_blkno + bucket * blk_per_bucket; | ||
2277 | |||
2278 | ret = ocfs2_read_block(inode, blkno, &bh); | ||
2279 | if (ret) { | ||
2280 | mlog_errno(ret); | ||
2281 | goto out; | ||
2282 | } | ||
2283 | |||
2284 | xh = (struct ocfs2_xattr_header *)bh->b_data; | ||
2285 | xe = &xh->xh_entries[0]; | ||
2286 | if (name_hash < le32_to_cpu(xe->xe_name_hash)) { | ||
2287 | high_bucket = bucket - 1; | ||
2288 | continue; | ||
2289 | } | ||
2290 | |||
2291 | /* | ||
2292 | * Check whether the hash of the last entry in our | ||
2293 | * bucket is larger than the search one. for an empty | ||
2294 | * bucket, the last one is also the first one. | ||
2295 | */ | ||
2296 | if (xh->xh_count) | ||
2297 | xe = &xh->xh_entries[le16_to_cpu(xh->xh_count) - 1]; | ||
2298 | |||
2299 | last_hash = le32_to_cpu(xe->xe_name_hash); | ||
2300 | |||
2301 | /* record lower_bh which may be the insert place. */ | ||
2302 | brelse(lower_bh); | ||
2303 | lower_bh = bh; | ||
2304 | bh = NULL; | ||
2305 | |||
2306 | if (name_hash > le32_to_cpu(xe->xe_name_hash)) { | ||
2307 | low_bucket = bucket + 1; | ||
2308 | continue; | ||
2309 | } | ||
2310 | |||
2311 | /* the searched xattr should reside in this bucket if exists. */ | ||
2312 | ret = ocfs2_find_xe_in_bucket(inode, lower_bh, | ||
2313 | name_index, name, name_hash, | ||
2314 | &index, &found); | ||
2315 | if (ret) { | ||
2316 | mlog_errno(ret); | ||
2317 | goto out; | ||
2318 | } | ||
2319 | break; | ||
2320 | } | ||
2321 | |||
2322 | /* | ||
2323 | * Record the bucket we have found. | ||
2324 | * When the xattr's hash value is in the gap of 2 buckets, we will | ||
2325 | * always set it to the previous bucket. | ||
2326 | */ | ||
2327 | if (!lower_bh) { | ||
2328 | /* | ||
2329 | * We can't find any bucket whose first name_hash is less | ||
2330 | * than the find name_hash. | ||
2331 | */ | ||
2332 | BUG_ON(bh->b_blocknr != p_blkno); | ||
2333 | lower_bh = bh; | ||
2334 | bh = NULL; | ||
2335 | } | ||
2336 | xs->bucket.bhs[0] = lower_bh; | ||
2337 | xs->bucket.xh = (struct ocfs2_xattr_header *) | ||
2338 | xs->bucket.bhs[0]->b_data; | ||
2339 | lower_bh = NULL; | ||
2340 | |||
2341 | xs->header = xs->bucket.xh; | ||
2342 | xs->base = xs->bucket.bhs[0]->b_data; | ||
2343 | xs->end = xs->base + inode->i_sb->s_blocksize; | ||
2344 | |||
2345 | if (found) { | ||
2346 | /* | ||
2347 | * If we have found the xattr enty, read all the blocks in | ||
2348 | * this bucket. | ||
2349 | */ | ||
2350 | ret = ocfs2_read_blocks(inode, xs->bucket.bhs[0]->b_blocknr + 1, | ||
2351 | blk_per_bucket - 1, &xs->bucket.bhs[1], | ||
2352 | OCFS2_BH_CACHED); | ||
2353 | if (ret) { | ||
2354 | mlog_errno(ret); | ||
2355 | goto out; | ||
2356 | } | ||
2357 | |||
2358 | xs->here = &xs->header->xh_entries[index]; | ||
2359 | mlog(0, "find xattr %s in bucket %llu, entry = %u\n", name, | ||
2360 | (unsigned long long)xs->bucket.bhs[0]->b_blocknr, index); | ||
2361 | } else | ||
2362 | ret = -ENODATA; | ||
2363 | |||
2364 | out: | ||
2365 | brelse(bh); | ||
2366 | brelse(lower_bh); | ||
2367 | return ret; | ||
2368 | } | ||
2369 | |||
2370 | static int ocfs2_xattr_index_block_find(struct inode *inode, | ||
2371 | struct buffer_head *root_bh, | ||
2372 | int name_index, | ||
2373 | const char *name, | ||
2374 | struct ocfs2_xattr_search *xs) | ||
2375 | { | ||
2376 | int ret; | ||
2377 | struct ocfs2_xattr_block *xb = | ||
2378 | (struct ocfs2_xattr_block *)root_bh->b_data; | ||
2379 | struct ocfs2_xattr_tree_root *xb_root = &xb->xb_attrs.xb_root; | ||
2380 | struct ocfs2_extent_list *el = &xb_root->xt_list; | ||
2381 | u64 p_blkno = 0; | ||
2382 | u32 first_hash, num_clusters = 0; | ||
2383 | u32 name_hash = ocfs2_xattr_name_hash(inode, name, strlen(name)); | ||
2384 | |||
2385 | if (le16_to_cpu(el->l_next_free_rec) == 0) | ||
2386 | return -ENODATA; | ||
2387 | |||
2388 | mlog(0, "find xattr %s, hash = %u, index = %d in xattr tree\n", | ||
2389 | name, name_hash, name_index); | ||
2390 | |||
2391 | ret = ocfs2_xattr_get_rec(inode, name_hash, &p_blkno, &first_hash, | ||
2392 | &num_clusters, el); | ||
2393 | if (ret) { | ||
2394 | mlog_errno(ret); | ||
2395 | goto out; | ||
2396 | } | ||
2397 | |||
2398 | BUG_ON(p_blkno == 0 || num_clusters == 0 || first_hash > name_hash); | ||
2399 | |||
2400 | mlog(0, "find xattr extent rec %u clusters from %llu, the first hash " | ||
2401 | "in the rec is %u\n", num_clusters, p_blkno, first_hash); | ||
2402 | |||
2403 | ret = ocfs2_xattr_bucket_find(inode, name_index, name, name_hash, | ||
2404 | p_blkno, first_hash, num_clusters, xs); | ||
2405 | |||
2406 | out: | ||
2407 | return ret; | ||
2408 | } | ||
2409 | |||
2410 | static int ocfs2_iterate_xattr_buckets(struct inode *inode, | ||
2411 | u64 blkno, | ||
2412 | u32 clusters, | ||
2413 | xattr_bucket_func *func, | ||
2414 | void *para) | ||
2415 | { | ||
2416 | int i, j, ret = 0; | ||
2417 | int blk_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb); | ||
2418 | u32 bpc = ocfs2_xattr_buckets_per_cluster(OCFS2_SB(inode->i_sb)); | ||
2419 | u32 num_buckets = clusters * bpc; | ||
2420 | struct ocfs2_xattr_bucket bucket; | ||
2421 | |||
2422 | memset(&bucket, 0, sizeof(bucket)); | ||
2423 | |||
2424 | mlog(0, "iterating xattr buckets in %u clusters starting from %llu\n", | ||
2425 | clusters, blkno); | ||
2426 | |||
2427 | for (i = 0; i < num_buckets; i++, blkno += blk_per_bucket) { | ||
2428 | ret = ocfs2_read_blocks(inode, blkno, blk_per_bucket, | ||
2429 | bucket.bhs, OCFS2_BH_CACHED); | ||
2430 | if (ret) { | ||
2431 | mlog_errno(ret); | ||
2432 | goto out; | ||
2433 | } | ||
2434 | |||
2435 | bucket.xh = (struct ocfs2_xattr_header *)bucket.bhs[0]->b_data; | ||
2436 | /* | ||
2437 | * The real bucket num in this series of blocks is stored | ||
2438 | * in the 1st bucket. | ||
2439 | */ | ||
2440 | if (i == 0) | ||
2441 | num_buckets = le16_to_cpu(bucket.xh->xh_num_buckets); | ||
2442 | |||
2443 | mlog(0, "iterating xattr bucket %llu, first hash %u\n", blkno, | ||
2444 | le32_to_cpu(bucket.xh->xh_entries[0].xe_name_hash)); | ||
2445 | if (func) { | ||
2446 | ret = func(inode, &bucket, para); | ||
2447 | if (ret) { | ||
2448 | mlog_errno(ret); | ||
2449 | break; | ||
2450 | } | ||
2451 | } | ||
2452 | |||
2453 | for (j = 0; j < blk_per_bucket; j++) | ||
2454 | brelse(bucket.bhs[j]); | ||
2455 | memset(&bucket, 0, sizeof(bucket)); | ||
2456 | } | ||
2457 | |||
2458 | out: | ||
2459 | for (j = 0; j < blk_per_bucket; j++) | ||
2460 | brelse(bucket.bhs[j]); | ||
2461 | |||
2462 | return ret; | ||
2463 | } | ||
2464 | |||
2465 | struct ocfs2_xattr_tree_list { | ||
2466 | char *buffer; | ||
2467 | size_t buffer_size; | ||
2468 | size_t result; | ||
2469 | }; | ||
2470 | |||
2471 | static int ocfs2_xattr_bucket_get_name_value(struct inode *inode, | ||
2472 | struct ocfs2_xattr_header *xh, | ||
2473 | int index, | ||
2474 | int *block_off, | ||
2475 | int *new_offset) | ||
2476 | { | ||
2477 | u16 name_offset; | ||
2478 | |||
2479 | if (index < 0 || index >= le16_to_cpu(xh->xh_count)) | ||
2480 | return -EINVAL; | ||
2481 | |||
2482 | name_offset = le16_to_cpu(xh->xh_entries[index].xe_name_offset); | ||
2483 | |||
2484 | *block_off = name_offset >> inode->i_sb->s_blocksize_bits; | ||
2485 | *new_offset = name_offset % inode->i_sb->s_blocksize; | ||
2486 | |||
2487 | return 0; | ||
2488 | } | ||
2489 | |||
2490 | static int ocfs2_list_xattr_bucket(struct inode *inode, | ||
2491 | struct ocfs2_xattr_bucket *bucket, | ||
2492 | void *para) | ||
2493 | { | ||
2494 | int ret = 0, type; | ||
2495 | struct ocfs2_xattr_tree_list *xl = (struct ocfs2_xattr_tree_list *)para; | ||
2496 | int i, block_off, new_offset; | ||
2497 | const char *prefix, *name; | ||
2498 | |||
2499 | for (i = 0 ; i < le16_to_cpu(bucket->xh->xh_count); i++) { | ||
2500 | struct ocfs2_xattr_entry *entry = &bucket->xh->xh_entries[i]; | ||
2501 | type = ocfs2_xattr_get_type(entry); | ||
2502 | prefix = ocfs2_xattr_prefix(type); | ||
2503 | |||
2504 | if (prefix) { | ||
2505 | ret = ocfs2_xattr_bucket_get_name_value(inode, | ||
2506 | bucket->xh, | ||
2507 | i, | ||
2508 | &block_off, | ||
2509 | &new_offset); | ||
2510 | if (ret) | ||
2511 | break; | ||
2512 | |||
2513 | name = (const char *)bucket->bhs[block_off]->b_data + | ||
2514 | new_offset; | ||
2515 | ret = ocfs2_xattr_list_entry(xl->buffer, | ||
2516 | xl->buffer_size, | ||
2517 | &xl->result, | ||
2518 | prefix, name, | ||
2519 | entry->xe_name_len); | ||
2520 | if (ret) | ||
2521 | break; | ||
2522 | } | ||
2523 | } | ||
2524 | |||
2525 | return ret; | ||
2526 | } | ||
2527 | |||
2528 | static int ocfs2_xattr_tree_list_index_block(struct inode *inode, | ||
2529 | struct ocfs2_xattr_tree_root *xt, | ||
2530 | char *buffer, | ||
2531 | size_t buffer_size) | ||
2532 | { | ||
2533 | struct ocfs2_extent_list *el = &xt->xt_list; | ||
2534 | int ret = 0; | ||
2535 | u32 name_hash = UINT_MAX, e_cpos = 0, num_clusters = 0; | ||
2536 | u64 p_blkno = 0; | ||
2537 | struct ocfs2_xattr_tree_list xl = { | ||
2538 | .buffer = buffer, | ||
2539 | .buffer_size = buffer_size, | ||
2540 | .result = 0, | ||
2541 | }; | ||
2542 | |||
2543 | if (le16_to_cpu(el->l_next_free_rec) == 0) | ||
2544 | return 0; | ||
2545 | |||
2546 | while (name_hash > 0) { | ||
2547 | ret = ocfs2_xattr_get_rec(inode, name_hash, &p_blkno, | ||
2548 | &e_cpos, &num_clusters, el); | ||
2549 | if (ret) { | ||
2550 | mlog_errno(ret); | ||
2551 | goto out; | ||
2552 | } | ||
2553 | |||
2554 | ret = ocfs2_iterate_xattr_buckets(inode, p_blkno, num_clusters, | ||
2555 | ocfs2_list_xattr_bucket, | ||
2556 | &xl); | ||
2557 | if (ret) { | ||
2558 | mlog_errno(ret); | ||
2559 | goto out; | ||
2560 | } | ||
2561 | |||
2562 | if (e_cpos == 0) | ||
2563 | break; | ||
2564 | |||
2565 | name_hash = e_cpos - 1; | ||
2566 | } | ||
2567 | |||
2568 | ret = xl.result; | ||
2569 | out: | ||
2570 | return ret; | ||
2571 | } | ||
2572 | |||
2573 | static int cmp_xe(const void *a, const void *b) | ||
2574 | { | ||
2575 | const struct ocfs2_xattr_entry *l = a, *r = b; | ||
2576 | u32 l_hash = le32_to_cpu(l->xe_name_hash); | ||
2577 | u32 r_hash = le32_to_cpu(r->xe_name_hash); | ||
2578 | |||
2579 | if (l_hash > r_hash) | ||
2580 | return 1; | ||
2581 | if (l_hash < r_hash) | ||
2582 | return -1; | ||
2583 | return 0; | ||
2584 | } | ||
2585 | |||
2586 | static void swap_xe(void *a, void *b, int size) | ||
2587 | { | ||
2588 | struct ocfs2_xattr_entry *l = a, *r = b, tmp; | ||
2589 | |||
2590 | tmp = *l; | ||
2591 | memcpy(l, r, sizeof(struct ocfs2_xattr_entry)); | ||
2592 | memcpy(r, &tmp, sizeof(struct ocfs2_xattr_entry)); | ||
2593 | } | ||
2594 | |||
2595 | /* | ||
2596 | * When the ocfs2_xattr_block is filled up, new bucket will be created | ||
2597 | * and all the xattr entries will be moved to the new bucket. | ||
2598 | * Note: we need to sort the entries since they are not saved in order | ||
2599 | * in the ocfs2_xattr_block. | ||
2600 | */ | ||
2601 | static void ocfs2_cp_xattr_block_to_bucket(struct inode *inode, | ||
2602 | struct buffer_head *xb_bh, | ||
2603 | struct buffer_head *xh_bh, | ||
2604 | struct buffer_head *data_bh) | ||
2605 | { | ||
2606 | int i, blocksize = inode->i_sb->s_blocksize; | ||
2607 | u16 offset, size, off_change; | ||
2608 | struct ocfs2_xattr_entry *xe; | ||
2609 | struct ocfs2_xattr_block *xb = | ||
2610 | (struct ocfs2_xattr_block *)xb_bh->b_data; | ||
2611 | struct ocfs2_xattr_header *xb_xh = &xb->xb_attrs.xb_header; | ||
2612 | struct ocfs2_xattr_header *xh = | ||
2613 | (struct ocfs2_xattr_header *)xh_bh->b_data; | ||
2614 | u16 count = le16_to_cpu(xb_xh->xh_count); | ||
2615 | char *target = xh_bh->b_data, *src = xb_bh->b_data; | ||
2616 | |||
2617 | mlog(0, "cp xattr from block %llu to bucket %llu\n", | ||
2618 | (unsigned long long)xb_bh->b_blocknr, | ||
2619 | (unsigned long long)xh_bh->b_blocknr); | ||
2620 | |||
2621 | memset(xh_bh->b_data, 0, blocksize); | ||
2622 | if (data_bh) | ||
2623 | memset(data_bh->b_data, 0, blocksize); | ||
2624 | /* | ||
2625 | * Since the xe_name_offset is based on ocfs2_xattr_header, | ||
2626 | * there is a offset change corresponding to the change of | ||
2627 | * ocfs2_xattr_header's position. | ||
2628 | */ | ||
2629 | off_change = offsetof(struct ocfs2_xattr_block, xb_attrs.xb_header); | ||
2630 | xe = &xb_xh->xh_entries[count - 1]; | ||
2631 | offset = le16_to_cpu(xe->xe_name_offset) + off_change; | ||
2632 | size = blocksize - offset; | ||
2633 | |||
2634 | /* copy all the names and values. */ | ||
2635 | if (data_bh) | ||
2636 | target = data_bh->b_data; | ||
2637 | memcpy(target + offset, src + offset, size); | ||
2638 | |||
2639 | /* Init new header now. */ | ||
2640 | xh->xh_count = xb_xh->xh_count; | ||
2641 | xh->xh_num_buckets = cpu_to_le16(1); | ||
2642 | xh->xh_name_value_len = cpu_to_le16(size); | ||
2643 | xh->xh_free_start = cpu_to_le16(OCFS2_XATTR_BUCKET_SIZE - size); | ||
2644 | |||
2645 | /* copy all the entries. */ | ||
2646 | target = xh_bh->b_data; | ||
2647 | offset = offsetof(struct ocfs2_xattr_header, xh_entries); | ||
2648 | size = count * sizeof(struct ocfs2_xattr_entry); | ||
2649 | memcpy(target + offset, (char *)xb_xh + offset, size); | ||
2650 | |||
2651 | /* Change the xe offset for all the xe because of the move. */ | ||
2652 | off_change = OCFS2_XATTR_BUCKET_SIZE - blocksize + | ||
2653 | offsetof(struct ocfs2_xattr_block, xb_attrs.xb_header); | ||
2654 | for (i = 0; i < count; i++) | ||
2655 | le16_add_cpu(&xh->xh_entries[i].xe_name_offset, off_change); | ||
2656 | |||
2657 | mlog(0, "copy entry: start = %u, size = %u, offset_change = %u\n", | ||
2658 | offset, size, off_change); | ||
2659 | |||
2660 | sort(target + offset, count, sizeof(struct ocfs2_xattr_entry), | ||
2661 | cmp_xe, swap_xe); | ||
2662 | } | ||
2663 | |||
2664 | /* | ||
2665 | * After we move xattr from block to index btree, we have to | ||
2666 | * update ocfs2_xattr_search to the new xe and base. | ||
2667 | * | ||
2668 | * When the entry is in xattr block, xattr_bh indicates the storage place. | ||
2669 | * While if the entry is in index b-tree, "bucket" indicates the | ||
2670 | * real place of the xattr. | ||
2671 | */ | ||
2672 | static int ocfs2_xattr_update_xattr_search(struct inode *inode, | ||
2673 | struct ocfs2_xattr_search *xs, | ||
2674 | struct buffer_head *old_bh, | ||
2675 | struct buffer_head *new_bh) | ||
2676 | { | ||
2677 | int ret = 0; | ||
2678 | char *buf = old_bh->b_data; | ||
2679 | struct ocfs2_xattr_block *old_xb = (struct ocfs2_xattr_block *)buf; | ||
2680 | struct ocfs2_xattr_header *old_xh = &old_xb->xb_attrs.xb_header; | ||
2681 | int i, blocksize = inode->i_sb->s_blocksize; | ||
2682 | u16 blk_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb); | ||
2683 | |||
2684 | xs->bucket.bhs[0] = new_bh; | ||
2685 | get_bh(new_bh); | ||
2686 | xs->bucket.xh = (struct ocfs2_xattr_header *)xs->bucket.bhs[0]->b_data; | ||
2687 | xs->header = xs->bucket.xh; | ||
2688 | |||
2689 | xs->base = new_bh->b_data; | ||
2690 | xs->end = xs->base + inode->i_sb->s_blocksize; | ||
2691 | |||
2692 | if (!xs->not_found) { | ||
2693 | if (OCFS2_XATTR_BUCKET_SIZE != blocksize) { | ||
2694 | ret = ocfs2_read_blocks(inode, | ||
2695 | xs->bucket.bhs[0]->b_blocknr + 1, | ||
2696 | blk_per_bucket - 1, &xs->bucket.bhs[1], | ||
2697 | OCFS2_BH_CACHED); | ||
2698 | if (ret) { | ||
2699 | mlog_errno(ret); | ||
2700 | return ret; | ||
2701 | } | ||
2702 | |||
2703 | i = xs->here - old_xh->xh_entries; | ||
2704 | xs->here = &xs->header->xh_entries[i]; | ||
2705 | } | ||
2706 | } | ||
2707 | |||
2708 | return ret; | ||
2709 | } | ||
2710 | |||
2711 | static int ocfs2_xattr_create_index_block(struct inode *inode, | ||
2712 | struct ocfs2_xattr_search *xs) | ||
2713 | { | ||
2714 | int ret, credits = OCFS2_SUBALLOC_ALLOC; | ||
2715 | u32 bit_off, len; | ||
2716 | u64 blkno; | ||
2717 | handle_t *handle; | ||
2718 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
2719 | struct ocfs2_inode_info *oi = OCFS2_I(inode); | ||
2720 | struct ocfs2_alloc_context *data_ac; | ||
2721 | struct buffer_head *xh_bh = NULL, *data_bh = NULL; | ||
2722 | struct buffer_head *xb_bh = xs->xattr_bh; | ||
2723 | struct ocfs2_xattr_block *xb = | ||
2724 | (struct ocfs2_xattr_block *)xb_bh->b_data; | ||
2725 | struct ocfs2_xattr_tree_root *xr; | ||
2726 | u16 xb_flags = le16_to_cpu(xb->xb_flags); | ||
2727 | u16 bpb = ocfs2_blocks_per_xattr_bucket(inode->i_sb); | ||
2728 | |||
2729 | mlog(0, "create xattr index block for %llu\n", | ||
2730 | (unsigned long long)xb_bh->b_blocknr); | ||
2731 | |||
2732 | BUG_ON(xb_flags & OCFS2_XATTR_INDEXED); | ||
2733 | |||
2734 | ret = ocfs2_reserve_clusters(osb, 1, &data_ac); | ||
2735 | if (ret) { | ||
2736 | mlog_errno(ret); | ||
2737 | goto out; | ||
2738 | } | ||
2739 | |||
2740 | /* | ||
2741 | * XXX: | ||
2742 | * We can use this lock for now, and maybe move to a dedicated mutex | ||
2743 | * if performance becomes a problem later. | ||
2744 | */ | ||
2745 | down_write(&oi->ip_alloc_sem); | ||
2746 | |||
2747 | /* | ||
2748 | * 3 more credits, one for xattr block update, one for the 1st block | ||
2749 | * of the new xattr bucket and one for the value/data. | ||
2750 | */ | ||
2751 | credits += 3; | ||
2752 | handle = ocfs2_start_trans(osb, credits); | ||
2753 | if (IS_ERR(handle)) { | ||
2754 | ret = PTR_ERR(handle); | ||
2755 | mlog_errno(ret); | ||
2756 | goto out_sem; | ||
2757 | } | ||
2758 | |||
2759 | ret = ocfs2_journal_access(handle, inode, xb_bh, | ||
2760 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
2761 | if (ret) { | ||
2762 | mlog_errno(ret); | ||
2763 | goto out_commit; | ||
2764 | } | ||
2765 | |||
2766 | ret = ocfs2_claim_clusters(osb, handle, data_ac, 1, &bit_off, &len); | ||
2767 | if (ret) { | ||
2768 | mlog_errno(ret); | ||
2769 | goto out_commit; | ||
2770 | } | ||
2771 | |||
2772 | /* | ||
2773 | * The bucket may spread in many blocks, and | ||
2774 | * we will only touch the 1st block and the last block | ||
2775 | * in the whole bucket(one for entry and one for data). | ||
2776 | */ | ||
2777 | blkno = ocfs2_clusters_to_blocks(inode->i_sb, bit_off); | ||
2778 | |||
2779 | mlog(0, "allocate 1 cluster from %llu to xattr block\n", blkno); | ||
2780 | |||
2781 | xh_bh = sb_getblk(inode->i_sb, blkno); | ||
2782 | if (!xh_bh) { | ||
2783 | ret = -EIO; | ||
2784 | mlog_errno(ret); | ||
2785 | goto out_commit; | ||
2786 | } | ||
2787 | |||
2788 | ocfs2_set_new_buffer_uptodate(inode, xh_bh); | ||
2789 | |||
2790 | ret = ocfs2_journal_access(handle, inode, xh_bh, | ||
2791 | OCFS2_JOURNAL_ACCESS_CREATE); | ||
2792 | if (ret) { | ||
2793 | mlog_errno(ret); | ||
2794 | goto out_commit; | ||
2795 | } | ||
2796 | |||
2797 | if (bpb > 1) { | ||
2798 | data_bh = sb_getblk(inode->i_sb, blkno + bpb - 1); | ||
2799 | if (!data_bh) { | ||
2800 | ret = -EIO; | ||
2801 | mlog_errno(ret); | ||
2802 | goto out_commit; | ||
2803 | } | ||
2804 | |||
2805 | ocfs2_set_new_buffer_uptodate(inode, data_bh); | ||
2806 | |||
2807 | ret = ocfs2_journal_access(handle, inode, data_bh, | ||
2808 | OCFS2_JOURNAL_ACCESS_CREATE); | ||
2809 | if (ret) { | ||
2810 | mlog_errno(ret); | ||
2811 | goto out_commit; | ||
2812 | } | ||
2813 | } | ||
2814 | |||
2815 | ocfs2_cp_xattr_block_to_bucket(inode, xb_bh, xh_bh, data_bh); | ||
2816 | |||
2817 | ocfs2_journal_dirty(handle, xh_bh); | ||
2818 | if (data_bh) | ||
2819 | ocfs2_journal_dirty(handle, data_bh); | ||
2820 | |||
2821 | ocfs2_xattr_update_xattr_search(inode, xs, xb_bh, xh_bh); | ||
2822 | |||
2823 | /* Change from ocfs2_xattr_header to ocfs2_xattr_tree_root */ | ||
2824 | memset(&xb->xb_attrs, 0, inode->i_sb->s_blocksize - | ||
2825 | offsetof(struct ocfs2_xattr_block, xb_attrs)); | ||
2826 | |||
2827 | xr = &xb->xb_attrs.xb_root; | ||
2828 | xr->xt_clusters = cpu_to_le32(1); | ||
2829 | xr->xt_last_eb_blk = 0; | ||
2830 | xr->xt_list.l_tree_depth = 0; | ||
2831 | xr->xt_list.l_count = cpu_to_le16(ocfs2_xattr_recs_per_xb(inode->i_sb)); | ||
2832 | xr->xt_list.l_next_free_rec = cpu_to_le16(1); | ||
2833 | |||
2834 | xr->xt_list.l_recs[0].e_cpos = 0; | ||
2835 | xr->xt_list.l_recs[0].e_blkno = cpu_to_le64(blkno); | ||
2836 | xr->xt_list.l_recs[0].e_leaf_clusters = cpu_to_le16(1); | ||
2837 | |||
2838 | xb->xb_flags = cpu_to_le16(xb_flags | OCFS2_XATTR_INDEXED); | ||
2839 | |||
2840 | ret = ocfs2_journal_dirty(handle, xb_bh); | ||
2841 | if (ret) { | ||
2842 | mlog_errno(ret); | ||
2843 | goto out_commit; | ||
2844 | } | ||
2845 | |||
2846 | out_commit: | ||
2847 | ocfs2_commit_trans(osb, handle); | ||
2848 | |||
2849 | out_sem: | ||
2850 | up_write(&oi->ip_alloc_sem); | ||
2851 | |||
2852 | out: | ||
2853 | if (data_ac) | ||
2854 | ocfs2_free_alloc_context(data_ac); | ||
2855 | |||
2856 | brelse(xh_bh); | ||
2857 | brelse(data_bh); | ||
2858 | |||
2859 | return ret; | ||
2860 | } | ||
2861 | |||
2862 | static int cmp_xe_offset(const void *a, const void *b) | ||
2863 | { | ||
2864 | const struct ocfs2_xattr_entry *l = a, *r = b; | ||
2865 | u32 l_name_offset = le16_to_cpu(l->xe_name_offset); | ||
2866 | u32 r_name_offset = le16_to_cpu(r->xe_name_offset); | ||
2867 | |||
2868 | if (l_name_offset < r_name_offset) | ||
2869 | return 1; | ||
2870 | if (l_name_offset > r_name_offset) | ||
2871 | return -1; | ||
2872 | return 0; | ||
2873 | } | ||
2874 | |||
2875 | /* | ||
2876 | * defrag a xattr bucket if we find that the bucket has some | ||
2877 | * holes beteen name/value pairs. | ||
2878 | * We will move all the name/value pairs to the end of the bucket | ||
2879 | * so that we can spare some space for insertion. | ||
2880 | */ | ||
2881 | static int ocfs2_defrag_xattr_bucket(struct inode *inode, | ||
2882 | struct ocfs2_xattr_bucket *bucket) | ||
2883 | { | ||
2884 | int ret, i; | ||
2885 | size_t end, offset, len, value_len; | ||
2886 | struct ocfs2_xattr_header *xh; | ||
2887 | char *entries, *buf, *bucket_buf = NULL; | ||
2888 | u64 blkno = bucket->bhs[0]->b_blocknr; | ||
2889 | u16 blk_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb); | ||
2890 | u16 xh_free_start; | ||
2891 | size_t blocksize = inode->i_sb->s_blocksize; | ||
2892 | handle_t *handle; | ||
2893 | struct buffer_head **bhs; | ||
2894 | struct ocfs2_xattr_entry *xe; | ||
2895 | |||
2896 | bhs = kzalloc(sizeof(struct buffer_head *) * blk_per_bucket, | ||
2897 | GFP_NOFS); | ||
2898 | if (!bhs) | ||
2899 | return -ENOMEM; | ||
2900 | |||
2901 | ret = ocfs2_read_blocks(inode, blkno, blk_per_bucket, bhs, | ||
2902 | OCFS2_BH_CACHED); | ||
2903 | if (ret) | ||
2904 | goto out; | ||
2905 | |||
2906 | /* | ||
2907 | * In order to make the operation more efficient and generic, | ||
2908 | * we copy all the blocks into a contiguous memory and do the | ||
2909 | * defragment there, so if anything is error, we will not touch | ||
2910 | * the real block. | ||
2911 | */ | ||
2912 | bucket_buf = kmalloc(OCFS2_XATTR_BUCKET_SIZE, GFP_NOFS); | ||
2913 | if (!bucket_buf) { | ||
2914 | ret = -EIO; | ||
2915 | goto out; | ||
2916 | } | ||
2917 | |||
2918 | buf = bucket_buf; | ||
2919 | for (i = 0; i < blk_per_bucket; i++, buf += blocksize) | ||
2920 | memcpy(buf, bhs[i]->b_data, blocksize); | ||
2921 | |||
2922 | handle = ocfs2_start_trans((OCFS2_SB(inode->i_sb)), blk_per_bucket); | ||
2923 | if (IS_ERR(handle)) { | ||
2924 | ret = PTR_ERR(handle); | ||
2925 | handle = NULL; | ||
2926 | mlog_errno(ret); | ||
2927 | goto out; | ||
2928 | } | ||
2929 | |||
2930 | for (i = 0; i < blk_per_bucket; i++) { | ||
2931 | ret = ocfs2_journal_access(handle, inode, bhs[i], | ||
2932 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
2933 | if (ret < 0) { | ||
2934 | mlog_errno(ret); | ||
2935 | goto commit; | ||
2936 | } | ||
2937 | } | ||
2938 | |||
2939 | xh = (struct ocfs2_xattr_header *)bucket_buf; | ||
2940 | entries = (char *)xh->xh_entries; | ||
2941 | xh_free_start = le16_to_cpu(xh->xh_free_start); | ||
2942 | |||
2943 | mlog(0, "adjust xattr bucket in %llu, count = %u, " | ||
2944 | "xh_free_start = %u, xh_name_value_len = %u.\n", | ||
2945 | blkno, le16_to_cpu(xh->xh_count), xh_free_start, | ||
2946 | le16_to_cpu(xh->xh_name_value_len)); | ||
2947 | |||
2948 | /* | ||
2949 | * sort all the entries by their offset. | ||
2950 | * the largest will be the first, so that we can | ||
2951 | * move them to the end one by one. | ||
2952 | */ | ||
2953 | sort(entries, le16_to_cpu(xh->xh_count), | ||
2954 | sizeof(struct ocfs2_xattr_entry), | ||
2955 | cmp_xe_offset, swap_xe); | ||
2956 | |||
2957 | /* Move all name/values to the end of the bucket. */ | ||
2958 | xe = xh->xh_entries; | ||
2959 | end = OCFS2_XATTR_BUCKET_SIZE; | ||
2960 | for (i = 0; i < le16_to_cpu(xh->xh_count); i++, xe++) { | ||
2961 | offset = le16_to_cpu(xe->xe_name_offset); | ||
2962 | if (ocfs2_xattr_is_local(xe)) | ||
2963 | value_len = OCFS2_XATTR_SIZE( | ||
2964 | le64_to_cpu(xe->xe_value_size)); | ||
2965 | else | ||
2966 | value_len = OCFS2_XATTR_ROOT_SIZE; | ||
2967 | len = OCFS2_XATTR_SIZE(xe->xe_name_len) + value_len; | ||
2968 | |||
2969 | /* | ||
2970 | * We must make sure that the name/value pair | ||
2971 | * exist in the same block. So adjust end to | ||
2972 | * the previous block end if needed. | ||
2973 | */ | ||
2974 | if (((end - len) / blocksize != | ||
2975 | (end - 1) / blocksize)) | ||
2976 | end = end - end % blocksize; | ||
2977 | |||
2978 | if (end > offset + len) { | ||
2979 | memmove(bucket_buf + end - len, | ||
2980 | bucket_buf + offset, len); | ||
2981 | xe->xe_name_offset = cpu_to_le16(end - len); | ||
2982 | } | ||
2983 | |||
2984 | mlog_bug_on_msg(end < offset + len, "Defrag check failed for " | ||
2985 | "bucket %llu\n", (unsigned long long)blkno); | ||
2986 | |||
2987 | end -= len; | ||
2988 | } | ||
2989 | |||
2990 | mlog_bug_on_msg(xh_free_start > end, "Defrag check failed for " | ||
2991 | "bucket %llu\n", (unsigned long long)blkno); | ||
2992 | |||
2993 | if (xh_free_start == end) | ||
2994 | goto commit; | ||
2995 | |||
2996 | memset(bucket_buf + xh_free_start, 0, end - xh_free_start); | ||
2997 | xh->xh_free_start = cpu_to_le16(end); | ||
2998 | |||
2999 | /* sort the entries by their name_hash. */ | ||
3000 | sort(entries, le16_to_cpu(xh->xh_count), | ||
3001 | sizeof(struct ocfs2_xattr_entry), | ||
3002 | cmp_xe, swap_xe); | ||
3003 | |||
3004 | buf = bucket_buf; | ||
3005 | for (i = 0; i < blk_per_bucket; i++, buf += blocksize) { | ||
3006 | memcpy(bhs[i]->b_data, buf, blocksize); | ||
3007 | ocfs2_journal_dirty(handle, bhs[i]); | ||
3008 | } | ||
3009 | |||
3010 | commit: | ||
3011 | ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle); | ||
3012 | out: | ||
3013 | |||
3014 | if (bhs) { | ||
3015 | for (i = 0; i < blk_per_bucket; i++) | ||
3016 | brelse(bhs[i]); | ||
3017 | } | ||
3018 | kfree(bhs); | ||
3019 | |||
3020 | kfree(bucket_buf); | ||
3021 | return ret; | ||
3022 | } | ||
3023 | |||
3024 | /* | ||
3025 | * Move half nums of the xattr bucket in the previous cluster to this new | ||
3026 | * cluster. We only touch the last cluster of the previous extend record. | ||
3027 | * | ||
3028 | * first_bh is the first buffer_head of a series of bucket in the same | ||
3029 | * extent rec and header_bh is the header of one bucket in this cluster. | ||
3030 | * They will be updated if we move the data header_bh contains to the new | ||
3031 | * cluster. first_hash will be set as the 1st xe's name_hash of the new cluster. | ||
3032 | */ | ||
3033 | static int ocfs2_mv_xattr_bucket_cross_cluster(struct inode *inode, | ||
3034 | handle_t *handle, | ||
3035 | struct buffer_head **first_bh, | ||
3036 | struct buffer_head **header_bh, | ||
3037 | u64 new_blkno, | ||
3038 | u64 prev_blkno, | ||
3039 | u32 num_clusters, | ||
3040 | u32 *first_hash) | ||
3041 | { | ||
3042 | int i, ret, credits; | ||
3043 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
3044 | int bpc = ocfs2_clusters_to_blocks(inode->i_sb, 1); | ||
3045 | int num_buckets = ocfs2_xattr_buckets_per_cluster(osb); | ||
3046 | int blocksize = inode->i_sb->s_blocksize; | ||
3047 | struct buffer_head *old_bh, *new_bh, *prev_bh, *new_first_bh = NULL; | ||
3048 | struct ocfs2_xattr_header *new_xh; | ||
3049 | struct ocfs2_xattr_header *xh = | ||
3050 | (struct ocfs2_xattr_header *)((*first_bh)->b_data); | ||
3051 | |||
3052 | BUG_ON(le16_to_cpu(xh->xh_num_buckets) < num_buckets); | ||
3053 | BUG_ON(OCFS2_XATTR_BUCKET_SIZE == osb->s_clustersize); | ||
3054 | |||
3055 | prev_bh = *first_bh; | ||
3056 | get_bh(prev_bh); | ||
3057 | xh = (struct ocfs2_xattr_header *)prev_bh->b_data; | ||
3058 | |||
3059 | prev_blkno += (num_clusters - 1) * bpc + bpc / 2; | ||
3060 | |||
3061 | mlog(0, "move half of xattrs in cluster %llu to %llu\n", | ||
3062 | prev_blkno, new_blkno); | ||
3063 | |||
3064 | /* | ||
3065 | * We need to update the 1st half of the new cluster and | ||
3066 | * 1 more for the update of the 1st bucket of the previous | ||
3067 | * extent record. | ||
3068 | */ | ||
3069 | credits = bpc / 2 + 1; | ||
3070 | ret = ocfs2_extend_trans(handle, credits); | ||
3071 | if (ret) { | ||
3072 | mlog_errno(ret); | ||
3073 | goto out; | ||
3074 | } | ||
3075 | |||
3076 | ret = ocfs2_journal_access(handle, inode, prev_bh, | ||
3077 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
3078 | if (ret) { | ||
3079 | mlog_errno(ret); | ||
3080 | goto out; | ||
3081 | } | ||
3082 | |||
3083 | for (i = 0; i < bpc / 2; i++, prev_blkno++, new_blkno++) { | ||
3084 | old_bh = new_bh = NULL; | ||
3085 | new_bh = sb_getblk(inode->i_sb, new_blkno); | ||
3086 | if (!new_bh) { | ||
3087 | ret = -EIO; | ||
3088 | mlog_errno(ret); | ||
3089 | goto out; | ||
3090 | } | ||
3091 | |||
3092 | ocfs2_set_new_buffer_uptodate(inode, new_bh); | ||
3093 | |||
3094 | ret = ocfs2_journal_access(handle, inode, new_bh, | ||
3095 | OCFS2_JOURNAL_ACCESS_CREATE); | ||
3096 | if (ret < 0) { | ||
3097 | mlog_errno(ret); | ||
3098 | brelse(new_bh); | ||
3099 | goto out; | ||
3100 | } | ||
3101 | |||
3102 | ret = ocfs2_read_block(inode, prev_blkno, &old_bh); | ||
3103 | if (ret < 0) { | ||
3104 | mlog_errno(ret); | ||
3105 | brelse(new_bh); | ||
3106 | goto out; | ||
3107 | } | ||
3108 | |||
3109 | memcpy(new_bh->b_data, old_bh->b_data, blocksize); | ||
3110 | |||
3111 | if (i == 0) { | ||
3112 | new_xh = (struct ocfs2_xattr_header *)new_bh->b_data; | ||
3113 | new_xh->xh_num_buckets = cpu_to_le16(num_buckets / 2); | ||
3114 | |||
3115 | if (first_hash) | ||
3116 | *first_hash = le32_to_cpu( | ||
3117 | new_xh->xh_entries[0].xe_name_hash); | ||
3118 | new_first_bh = new_bh; | ||
3119 | get_bh(new_first_bh); | ||
3120 | } | ||
3121 | |||
3122 | ocfs2_journal_dirty(handle, new_bh); | ||
3123 | |||
3124 | if (*header_bh == old_bh) { | ||
3125 | brelse(*header_bh); | ||
3126 | *header_bh = new_bh; | ||
3127 | get_bh(*header_bh); | ||
3128 | |||
3129 | brelse(*first_bh); | ||
3130 | *first_bh = new_first_bh; | ||
3131 | get_bh(*first_bh); | ||
3132 | } | ||
3133 | brelse(new_bh); | ||
3134 | brelse(old_bh); | ||
3135 | } | ||
3136 | |||
3137 | le16_add_cpu(&xh->xh_num_buckets, -(num_buckets / 2)); | ||
3138 | |||
3139 | ocfs2_journal_dirty(handle, prev_bh); | ||
3140 | out: | ||
3141 | brelse(prev_bh); | ||
3142 | brelse(new_first_bh); | ||
3143 | return ret; | ||
3144 | } | ||
3145 | |||
3146 | static int ocfs2_read_xattr_bucket(struct inode *inode, | ||
3147 | u64 blkno, | ||
3148 | struct buffer_head **bhs, | ||
3149 | int new) | ||
3150 | { | ||
3151 | int ret = 0; | ||
3152 | u16 i, blk_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb); | ||
3153 | |||
3154 | if (!new) | ||
3155 | return ocfs2_read_blocks(inode, blkno, | ||
3156 | blk_per_bucket, bhs, | ||
3157 | OCFS2_BH_CACHED); | ||
3158 | |||
3159 | for (i = 0; i < blk_per_bucket; i++) { | ||
3160 | bhs[i] = sb_getblk(inode->i_sb, blkno + i); | ||
3161 | if (bhs[i] == NULL) { | ||
3162 | ret = -EIO; | ||
3163 | mlog_errno(ret); | ||
3164 | break; | ||
3165 | } | ||
3166 | ocfs2_set_new_buffer_uptodate(inode, bhs[i]); | ||
3167 | } | ||
3168 | |||
3169 | return ret; | ||
3170 | } | ||
3171 | |||
3172 | /* | ||
3173 | * Move half num of the xattrs in old bucket(blk) to new bucket(new_blk). | ||
3174 | * first_hash will record the 1st hash of the new bucket. | ||
3175 | */ | ||
3176 | static int ocfs2_half_xattr_bucket(struct inode *inode, | ||
3177 | handle_t *handle, | ||
3178 | u64 blk, | ||
3179 | u64 new_blk, | ||
3180 | u32 *first_hash, | ||
3181 | int new_bucket_head) | ||
3182 | { | ||
3183 | int ret, i; | ||
3184 | u16 count, start, len, name_value_len, xe_len, name_offset; | ||
3185 | u16 blk_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb); | ||
3186 | struct buffer_head **s_bhs, **t_bhs = NULL; | ||
3187 | struct ocfs2_xattr_header *xh; | ||
3188 | struct ocfs2_xattr_entry *xe; | ||
3189 | int blocksize = inode->i_sb->s_blocksize; | ||
3190 | |||
3191 | mlog(0, "move half of xattrs from bucket %llu to %llu\n", | ||
3192 | blk, new_blk); | ||
3193 | |||
3194 | s_bhs = kcalloc(blk_per_bucket, sizeof(struct buffer_head *), GFP_NOFS); | ||
3195 | if (!s_bhs) | ||
3196 | return -ENOMEM; | ||
3197 | |||
3198 | ret = ocfs2_read_xattr_bucket(inode, blk, s_bhs, 0); | ||
3199 | if (ret) { | ||
3200 | mlog_errno(ret); | ||
3201 | goto out; | ||
3202 | } | ||
3203 | |||
3204 | ret = ocfs2_journal_access(handle, inode, s_bhs[0], | ||
3205 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
3206 | if (ret) { | ||
3207 | mlog_errno(ret); | ||
3208 | goto out; | ||
3209 | } | ||
3210 | |||
3211 | t_bhs = kcalloc(blk_per_bucket, sizeof(struct buffer_head *), GFP_NOFS); | ||
3212 | if (!t_bhs) { | ||
3213 | ret = -ENOMEM; | ||
3214 | goto out; | ||
3215 | } | ||
3216 | |||
3217 | ret = ocfs2_read_xattr_bucket(inode, new_blk, t_bhs, new_bucket_head); | ||
3218 | if (ret) { | ||
3219 | mlog_errno(ret); | ||
3220 | goto out; | ||
3221 | } | ||
3222 | |||
3223 | for (i = 0; i < blk_per_bucket; i++) { | ||
3224 | ret = ocfs2_journal_access(handle, inode, t_bhs[i], | ||
3225 | OCFS2_JOURNAL_ACCESS_CREATE); | ||
3226 | if (ret) { | ||
3227 | mlog_errno(ret); | ||
3228 | goto out; | ||
3229 | } | ||
3230 | } | ||
3231 | |||
3232 | /* copy the whole bucket to the new first. */ | ||
3233 | for (i = 0; i < blk_per_bucket; i++) | ||
3234 | memcpy(t_bhs[i]->b_data, s_bhs[i]->b_data, blocksize); | ||
3235 | |||
3236 | /* update the new bucket. */ | ||
3237 | xh = (struct ocfs2_xattr_header *)t_bhs[0]->b_data; | ||
3238 | count = le16_to_cpu(xh->xh_count); | ||
3239 | start = count / 2; | ||
3240 | |||
3241 | /* | ||
3242 | * Calculate the total name/value len and xh_free_start for | ||
3243 | * the old bucket first. | ||
3244 | */ | ||
3245 | name_offset = OCFS2_XATTR_BUCKET_SIZE; | ||
3246 | name_value_len = 0; | ||
3247 | for (i = 0; i < start; i++) { | ||
3248 | xe = &xh->xh_entries[i]; | ||
3249 | xe_len = OCFS2_XATTR_SIZE(xe->xe_name_len); | ||
3250 | if (ocfs2_xattr_is_local(xe)) | ||
3251 | xe_len += | ||
3252 | OCFS2_XATTR_SIZE(le64_to_cpu(xe->xe_value_size)); | ||
3253 | else | ||
3254 | xe_len += OCFS2_XATTR_ROOT_SIZE; | ||
3255 | name_value_len += xe_len; | ||
3256 | if (le16_to_cpu(xe->xe_name_offset) < name_offset) | ||
3257 | name_offset = le16_to_cpu(xe->xe_name_offset); | ||
3258 | } | ||
3259 | |||
3260 | /* | ||
3261 | * Now begin the modification to the new bucket. | ||
3262 | * | ||
3263 | * In the new bucket, We just move the xattr entry to the beginning | ||
3264 | * and don't touch the name/value. So there will be some holes in the | ||
3265 | * bucket, and they will be removed when ocfs2_defrag_xattr_bucket is | ||
3266 | * called. | ||
3267 | */ | ||
3268 | xe = &xh->xh_entries[start]; | ||
3269 | len = sizeof(struct ocfs2_xattr_entry) * (count - start); | ||
3270 | mlog(0, "mv xattr entry len %d from %d to %d\n", len, | ||
3271 | (int)((char *)xe - (char *)xh), | ||
3272 | (int)((char *)xh->xh_entries - (char *)xh)); | ||
3273 | memmove((char *)xh->xh_entries, (char *)xe, len); | ||
3274 | xe = &xh->xh_entries[count - start]; | ||
3275 | len = sizeof(struct ocfs2_xattr_entry) * start; | ||
3276 | memset((char *)xe, 0, len); | ||
3277 | |||
3278 | le16_add_cpu(&xh->xh_count, -start); | ||
3279 | le16_add_cpu(&xh->xh_name_value_len, -name_value_len); | ||
3280 | |||
3281 | /* Calculate xh_free_start for the new bucket. */ | ||
3282 | xh->xh_free_start = cpu_to_le16(OCFS2_XATTR_BUCKET_SIZE); | ||
3283 | for (i = 0; i < le16_to_cpu(xh->xh_count); i++) { | ||
3284 | xe = &xh->xh_entries[i]; | ||
3285 | xe_len = OCFS2_XATTR_SIZE(xe->xe_name_len); | ||
3286 | if (ocfs2_xattr_is_local(xe)) | ||
3287 | xe_len += | ||
3288 | OCFS2_XATTR_SIZE(le64_to_cpu(xe->xe_value_size)); | ||
3289 | else | ||
3290 | xe_len += OCFS2_XATTR_ROOT_SIZE; | ||
3291 | if (le16_to_cpu(xe->xe_name_offset) < | ||
3292 | le16_to_cpu(xh->xh_free_start)) | ||
3293 | xh->xh_free_start = xe->xe_name_offset; | ||
3294 | } | ||
3295 | |||
3296 | /* set xh->xh_num_buckets for the new xh. */ | ||
3297 | if (new_bucket_head) | ||
3298 | xh->xh_num_buckets = cpu_to_le16(1); | ||
3299 | else | ||
3300 | xh->xh_num_buckets = 0; | ||
3301 | |||
3302 | for (i = 0; i < blk_per_bucket; i++) { | ||
3303 | ocfs2_journal_dirty(handle, t_bhs[i]); | ||
3304 | if (ret) | ||
3305 | mlog_errno(ret); | ||
3306 | } | ||
3307 | |||
3308 | /* store the first_hash of the new bucket. */ | ||
3309 | if (first_hash) | ||
3310 | *first_hash = le32_to_cpu(xh->xh_entries[0].xe_name_hash); | ||
3311 | |||
3312 | /* | ||
3313 | * Now only update the 1st block of the old bucket. | ||
3314 | * Please note that the entry has been sorted already above. | ||
3315 | */ | ||
3316 | xh = (struct ocfs2_xattr_header *)s_bhs[0]->b_data; | ||
3317 | memset(&xh->xh_entries[start], 0, | ||
3318 | sizeof(struct ocfs2_xattr_entry) * (count - start)); | ||
3319 | xh->xh_count = cpu_to_le16(start); | ||
3320 | xh->xh_free_start = cpu_to_le16(name_offset); | ||
3321 | xh->xh_name_value_len = cpu_to_le16(name_value_len); | ||
3322 | |||
3323 | ocfs2_journal_dirty(handle, s_bhs[0]); | ||
3324 | if (ret) | ||
3325 | mlog_errno(ret); | ||
3326 | |||
3327 | out: | ||
3328 | if (s_bhs) { | ||
3329 | for (i = 0; i < blk_per_bucket; i++) | ||
3330 | brelse(s_bhs[i]); | ||
3331 | } | ||
3332 | kfree(s_bhs); | ||
3333 | |||
3334 | if (t_bhs) { | ||
3335 | for (i = 0; i < blk_per_bucket; i++) | ||
3336 | brelse(t_bhs[i]); | ||
3337 | } | ||
3338 | kfree(t_bhs); | ||
3339 | |||
3340 | return ret; | ||
3341 | } | ||
3342 | |||
3343 | /* | ||
3344 | * Copy xattr from one bucket to another bucket. | ||
3345 | * | ||
3346 | * The caller must make sure that the journal transaction | ||
3347 | * has enough space for journaling. | ||
3348 | */ | ||
3349 | static int ocfs2_cp_xattr_bucket(struct inode *inode, | ||
3350 | handle_t *handle, | ||
3351 | u64 s_blkno, | ||
3352 | u64 t_blkno, | ||
3353 | int t_is_new) | ||
3354 | { | ||
3355 | int ret, i; | ||
3356 | int blk_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb); | ||
3357 | int blocksize = inode->i_sb->s_blocksize; | ||
3358 | struct buffer_head **s_bhs, **t_bhs = NULL; | ||
3359 | |||
3360 | BUG_ON(s_blkno == t_blkno); | ||
3361 | |||
3362 | mlog(0, "cp bucket %llu to %llu, target is %d\n", | ||
3363 | s_blkno, t_blkno, t_is_new); | ||
3364 | |||
3365 | s_bhs = kzalloc(sizeof(struct buffer_head *) * blk_per_bucket, | ||
3366 | GFP_NOFS); | ||
3367 | if (!s_bhs) | ||
3368 | return -ENOMEM; | ||
3369 | |||
3370 | ret = ocfs2_read_xattr_bucket(inode, s_blkno, s_bhs, 0); | ||
3371 | if (ret) | ||
3372 | goto out; | ||
3373 | |||
3374 | t_bhs = kzalloc(sizeof(struct buffer_head *) * blk_per_bucket, | ||
3375 | GFP_NOFS); | ||
3376 | if (!t_bhs) { | ||
3377 | ret = -ENOMEM; | ||
3378 | goto out; | ||
3379 | } | ||
3380 | |||
3381 | ret = ocfs2_read_xattr_bucket(inode, t_blkno, t_bhs, t_is_new); | ||
3382 | if (ret) | ||
3383 | goto out; | ||
3384 | |||
3385 | for (i = 0; i < blk_per_bucket; i++) { | ||
3386 | ret = ocfs2_journal_access(handle, inode, t_bhs[i], | ||
3387 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
3388 | if (ret) | ||
3389 | goto out; | ||
3390 | } | ||
3391 | |||
3392 | for (i = 0; i < blk_per_bucket; i++) { | ||
3393 | memcpy(t_bhs[i]->b_data, s_bhs[i]->b_data, blocksize); | ||
3394 | ocfs2_journal_dirty(handle, t_bhs[i]); | ||
3395 | } | ||
3396 | |||
3397 | out: | ||
3398 | if (s_bhs) { | ||
3399 | for (i = 0; i < blk_per_bucket; i++) | ||
3400 | brelse(s_bhs[i]); | ||
3401 | } | ||
3402 | kfree(s_bhs); | ||
3403 | |||
3404 | if (t_bhs) { | ||
3405 | for (i = 0; i < blk_per_bucket; i++) | ||
3406 | brelse(t_bhs[i]); | ||
3407 | } | ||
3408 | kfree(t_bhs); | ||
3409 | |||
3410 | return ret; | ||
3411 | } | ||
3412 | |||
3413 | /* | ||
3414 | * Copy one xattr cluster from src_blk to to_blk. | ||
3415 | * The to_blk will become the first bucket header of the cluster, so its | ||
3416 | * xh_num_buckets will be initialized as the bucket num in the cluster. | ||
3417 | */ | ||
3418 | static int ocfs2_cp_xattr_cluster(struct inode *inode, | ||
3419 | handle_t *handle, | ||
3420 | struct buffer_head *first_bh, | ||
3421 | u64 src_blk, | ||
3422 | u64 to_blk, | ||
3423 | u32 *first_hash) | ||
3424 | { | ||
3425 | int i, ret, credits; | ||
3426 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
3427 | int bpc = ocfs2_clusters_to_blocks(inode->i_sb, 1); | ||
3428 | int num_buckets = ocfs2_xattr_buckets_per_cluster(osb); | ||
3429 | struct buffer_head *bh = NULL; | ||
3430 | struct ocfs2_xattr_header *xh; | ||
3431 | u64 to_blk_start = to_blk; | ||
3432 | |||
3433 | mlog(0, "cp xattrs from cluster %llu to %llu\n", src_blk, to_blk); | ||
3434 | |||
3435 | /* | ||
3436 | * We need to update the new cluster and 1 more for the update of | ||
3437 | * the 1st bucket of the previous extent rec. | ||
3438 | */ | ||
3439 | credits = bpc + 1; | ||
3440 | ret = ocfs2_extend_trans(handle, credits); | ||
3441 | if (ret) { | ||
3442 | mlog_errno(ret); | ||
3443 | goto out; | ||
3444 | } | ||
3445 | |||
3446 | ret = ocfs2_journal_access(handle, inode, first_bh, | ||
3447 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
3448 | if (ret) { | ||
3449 | mlog_errno(ret); | ||
3450 | goto out; | ||
3451 | } | ||
3452 | |||
3453 | for (i = 0; i < num_buckets; i++) { | ||
3454 | ret = ocfs2_cp_xattr_bucket(inode, handle, | ||
3455 | src_blk, to_blk, 1); | ||
3456 | if (ret) { | ||
3457 | mlog_errno(ret); | ||
3458 | goto out; | ||
3459 | } | ||
3460 | |||
3461 | src_blk += ocfs2_blocks_per_xattr_bucket(inode->i_sb); | ||
3462 | to_blk += ocfs2_blocks_per_xattr_bucket(inode->i_sb); | ||
3463 | } | ||
3464 | |||
3465 | /* update the old bucket header. */ | ||
3466 | xh = (struct ocfs2_xattr_header *)first_bh->b_data; | ||
3467 | le16_add_cpu(&xh->xh_num_buckets, -num_buckets); | ||
3468 | |||
3469 | ocfs2_journal_dirty(handle, first_bh); | ||
3470 | |||
3471 | /* update the new bucket header. */ | ||
3472 | ret = ocfs2_read_block(inode, to_blk_start, &bh); | ||
3473 | if (ret < 0) { | ||
3474 | mlog_errno(ret); | ||
3475 | goto out; | ||
3476 | } | ||
3477 | |||
3478 | ret = ocfs2_journal_access(handle, inode, bh, | ||
3479 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
3480 | if (ret) { | ||
3481 | mlog_errno(ret); | ||
3482 | goto out; | ||
3483 | } | ||
3484 | |||
3485 | xh = (struct ocfs2_xattr_header *)bh->b_data; | ||
3486 | xh->xh_num_buckets = cpu_to_le16(num_buckets); | ||
3487 | |||
3488 | ocfs2_journal_dirty(handle, bh); | ||
3489 | |||
3490 | if (first_hash) | ||
3491 | *first_hash = le32_to_cpu(xh->xh_entries[0].xe_name_hash); | ||
3492 | out: | ||
3493 | brelse(bh); | ||
3494 | return ret; | ||
3495 | } | ||
3496 | |||
3497 | /* | ||
3498 | * Move half of the xattrs in this cluster to the new cluster. | ||
3499 | * This function should only be called when bucket size == cluster size. | ||
3500 | * Otherwise ocfs2_mv_xattr_bucket_cross_cluster should be used instead. | ||
3501 | */ | ||
3502 | static int ocfs2_half_xattr_cluster(struct inode *inode, | ||
3503 | handle_t *handle, | ||
3504 | u64 prev_blk, | ||
3505 | u64 new_blk, | ||
3506 | u32 *first_hash) | ||
3507 | { | ||
3508 | u16 blk_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb); | ||
3509 | int ret, credits = 2 * blk_per_bucket; | ||
3510 | |||
3511 | BUG_ON(OCFS2_XATTR_BUCKET_SIZE < OCFS2_SB(inode->i_sb)->s_clustersize); | ||
3512 | |||
3513 | ret = ocfs2_extend_trans(handle, credits); | ||
3514 | if (ret) { | ||
3515 | mlog_errno(ret); | ||
3516 | return ret; | ||
3517 | } | ||
3518 | |||
3519 | /* Move half of the xattr in start_blk to the next bucket. */ | ||
3520 | return ocfs2_half_xattr_bucket(inode, handle, prev_blk, | ||
3521 | new_blk, first_hash, 1); | ||
3522 | } | ||
3523 | |||
3524 | /* | ||
3525 | * Move some xattrs from the old cluster to the new one since they are not | ||
3526 | * contiguous in ocfs2 xattr tree. | ||
3527 | * | ||
3528 | * new_blk starts a new separate cluster, and we will move some xattrs from | ||
3529 | * prev_blk to it. v_start will be set as the first name hash value in this | ||
3530 | * new cluster so that it can be used as e_cpos during tree insertion and | ||
3531 | * don't collide with our original b-tree operations. first_bh and header_bh | ||
3532 | * will also be updated since they will be used in ocfs2_extend_xattr_bucket | ||
3533 | * to extend the insert bucket. | ||
3534 | * | ||
3535 | * The problem is how much xattr should we move to the new one and when should | ||
3536 | * we update first_bh and header_bh? | ||
3537 | * 1. If cluster size > bucket size, that means the previous cluster has more | ||
3538 | * than 1 bucket, so just move half nums of bucket into the new cluster and | ||
3539 | * update the first_bh and header_bh if the insert bucket has been moved | ||
3540 | * to the new cluster. | ||
3541 | * 2. If cluster_size == bucket_size: | ||
3542 | * a) If the previous extent rec has more than one cluster and the insert | ||
3543 | * place isn't in the last cluster, copy the entire last cluster to the | ||
3544 | * new one. This time, we don't need to upate the first_bh and header_bh | ||
3545 | * since they will not be moved into the new cluster. | ||
3546 | * b) Otherwise, move the bottom half of the xattrs in the last cluster into | ||
3547 | * the new one. And we set the extend flag to zero if the insert place is | ||
3548 | * moved into the new allocated cluster since no extend is needed. | ||
3549 | */ | ||
3550 | static int ocfs2_adjust_xattr_cross_cluster(struct inode *inode, | ||
3551 | handle_t *handle, | ||
3552 | struct buffer_head **first_bh, | ||
3553 | struct buffer_head **header_bh, | ||
3554 | u64 new_blk, | ||
3555 | u64 prev_blk, | ||
3556 | u32 prev_clusters, | ||
3557 | u32 *v_start, | ||
3558 | int *extend) | ||
3559 | { | ||
3560 | int ret = 0; | ||
3561 | int bpc = ocfs2_clusters_to_blocks(inode->i_sb, 1); | ||
3562 | |||
3563 | mlog(0, "adjust xattrs from cluster %llu len %u to %llu\n", | ||
3564 | prev_blk, prev_clusters, new_blk); | ||
3565 | |||
3566 | if (ocfs2_xattr_buckets_per_cluster(OCFS2_SB(inode->i_sb)) > 1) | ||
3567 | ret = ocfs2_mv_xattr_bucket_cross_cluster(inode, | ||
3568 | handle, | ||
3569 | first_bh, | ||
3570 | header_bh, | ||
3571 | new_blk, | ||
3572 | prev_blk, | ||
3573 | prev_clusters, | ||
3574 | v_start); | ||
3575 | else { | ||
3576 | u64 last_blk = prev_blk + bpc * (prev_clusters - 1); | ||
3577 | |||
3578 | if (prev_clusters > 1 && (*header_bh)->b_blocknr != last_blk) | ||
3579 | ret = ocfs2_cp_xattr_cluster(inode, handle, *first_bh, | ||
3580 | last_blk, new_blk, | ||
3581 | v_start); | ||
3582 | else { | ||
3583 | ret = ocfs2_half_xattr_cluster(inode, handle, | ||
3584 | last_blk, new_blk, | ||
3585 | v_start); | ||
3586 | |||
3587 | if ((*header_bh)->b_blocknr == last_blk && extend) | ||
3588 | *extend = 0; | ||
3589 | } | ||
3590 | } | ||
3591 | |||
3592 | return ret; | ||
3593 | } | ||
3594 | |||
3595 | /* | ||
3596 | * Add a new cluster for xattr storage. | ||
3597 | * | ||
3598 | * If the new cluster is contiguous with the previous one, it will be | ||
3599 | * appended to the same extent record, and num_clusters will be updated. | ||
3600 | * If not, we will insert a new extent for it and move some xattrs in | ||
3601 | * the last cluster into the new allocated one. | ||
3602 | * We also need to limit the maximum size of a btree leaf, otherwise we'll | ||
3603 | * lose the benefits of hashing because we'll have to search large leaves. | ||
3604 | * So now the maximum size is OCFS2_MAX_XATTR_TREE_LEAF_SIZE(or clustersize, | ||
3605 | * if it's bigger). | ||
3606 | * | ||
3607 | * first_bh is the first block of the previous extent rec and header_bh | ||
3608 | * indicates the bucket we will insert the new xattrs. They will be updated | ||
3609 | * when the header_bh is moved into the new cluster. | ||
3610 | */ | ||
3611 | static int ocfs2_add_new_xattr_cluster(struct inode *inode, | ||
3612 | struct buffer_head *root_bh, | ||
3613 | struct buffer_head **first_bh, | ||
3614 | struct buffer_head **header_bh, | ||
3615 | u32 *num_clusters, | ||
3616 | u32 prev_cpos, | ||
3617 | u64 prev_blkno, | ||
3618 | int *extend) | ||
3619 | { | ||
3620 | int ret, credits; | ||
3621 | u16 bpc = ocfs2_clusters_to_blocks(inode->i_sb, 1); | ||
3622 | u32 prev_clusters = *num_clusters; | ||
3623 | u32 clusters_to_add = 1, bit_off, num_bits, v_start = 0; | ||
3624 | u64 block; | ||
3625 | handle_t *handle = NULL; | ||
3626 | struct ocfs2_alloc_context *data_ac = NULL; | ||
3627 | struct ocfs2_alloc_context *meta_ac = NULL; | ||
3628 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
3629 | struct ocfs2_extent_tree et; | ||
3630 | |||
3631 | mlog(0, "Add new xattr cluster for %llu, previous xattr hash = %u, " | ||
3632 | "previous xattr blkno = %llu\n", | ||
3633 | (unsigned long long)OCFS2_I(inode)->ip_blkno, | ||
3634 | prev_cpos, prev_blkno); | ||
3635 | |||
3636 | ocfs2_init_xattr_tree_extent_tree(&et, inode, root_bh); | ||
3637 | |||
3638 | ret = ocfs2_lock_allocators(inode, &et, clusters_to_add, 0, | ||
3639 | &data_ac, &meta_ac); | ||
3640 | if (ret) { | ||
3641 | mlog_errno(ret); | ||
3642 | goto leave; | ||
3643 | } | ||
3644 | |||
3645 | credits = ocfs2_calc_extend_credits(osb->sb, et.et_root_el, | ||
3646 | clusters_to_add); | ||
3647 | handle = ocfs2_start_trans(osb, credits); | ||
3648 | if (IS_ERR(handle)) { | ||
3649 | ret = PTR_ERR(handle); | ||
3650 | handle = NULL; | ||
3651 | mlog_errno(ret); | ||
3652 | goto leave; | ||
3653 | } | ||
3654 | |||
3655 | ret = ocfs2_journal_access(handle, inode, root_bh, | ||
3656 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
3657 | if (ret < 0) { | ||
3658 | mlog_errno(ret); | ||
3659 | goto leave; | ||
3660 | } | ||
3661 | |||
3662 | ret = __ocfs2_claim_clusters(osb, handle, data_ac, 1, | ||
3663 | clusters_to_add, &bit_off, &num_bits); | ||
3664 | if (ret < 0) { | ||
3665 | if (ret != -ENOSPC) | ||
3666 | mlog_errno(ret); | ||
3667 | goto leave; | ||
3668 | } | ||
3669 | |||
3670 | BUG_ON(num_bits > clusters_to_add); | ||
3671 | |||
3672 | block = ocfs2_clusters_to_blocks(osb->sb, bit_off); | ||
3673 | mlog(0, "Allocating %u clusters at block %u for xattr in inode %llu\n", | ||
3674 | num_bits, bit_off, (unsigned long long)OCFS2_I(inode)->ip_blkno); | ||
3675 | |||
3676 | if (prev_blkno + prev_clusters * bpc == block && | ||
3677 | (prev_clusters + num_bits) << osb->s_clustersize_bits <= | ||
3678 | OCFS2_MAX_XATTR_TREE_LEAF_SIZE) { | ||
3679 | /* | ||
3680 | * If this cluster is contiguous with the old one and | ||
3681 | * adding this new cluster, we don't surpass the limit of | ||
3682 | * OCFS2_MAX_XATTR_TREE_LEAF_SIZE, cool. We will let it be | ||
3683 | * initialized and used like other buckets in the previous | ||
3684 | * cluster. | ||
3685 | * So add it as a contiguous one. The caller will handle | ||
3686 | * its init process. | ||
3687 | */ | ||
3688 | v_start = prev_cpos + prev_clusters; | ||
3689 | *num_clusters = prev_clusters + num_bits; | ||
3690 | mlog(0, "Add contiguous %u clusters to previous extent rec.\n", | ||
3691 | num_bits); | ||
3692 | } else { | ||
3693 | ret = ocfs2_adjust_xattr_cross_cluster(inode, | ||
3694 | handle, | ||
3695 | first_bh, | ||
3696 | header_bh, | ||
3697 | block, | ||
3698 | prev_blkno, | ||
3699 | prev_clusters, | ||
3700 | &v_start, | ||
3701 | extend); | ||
3702 | if (ret) { | ||
3703 | mlog_errno(ret); | ||
3704 | goto leave; | ||
3705 | } | ||
3706 | } | ||
3707 | |||
3708 | if (handle->h_buffer_credits < credits) { | ||
3709 | /* | ||
3710 | * The journal has been restarted before, and don't | ||
3711 | * have enough space for the insertion, so extend it | ||
3712 | * here. | ||
3713 | */ | ||
3714 | ret = ocfs2_extend_trans(handle, credits); | ||
3715 | if (ret) { | ||
3716 | mlog_errno(ret); | ||
3717 | goto leave; | ||
3718 | } | ||
3719 | } | ||
3720 | mlog(0, "Insert %u clusters at block %llu for xattr at %u\n", | ||
3721 | num_bits, block, v_start); | ||
3722 | ret = ocfs2_insert_extent(osb, handle, inode, &et, v_start, block, | ||
3723 | num_bits, 0, meta_ac); | ||
3724 | if (ret < 0) { | ||
3725 | mlog_errno(ret); | ||
3726 | goto leave; | ||
3727 | } | ||
3728 | |||
3729 | ret = ocfs2_journal_dirty(handle, root_bh); | ||
3730 | if (ret < 0) { | ||
3731 | mlog_errno(ret); | ||
3732 | goto leave; | ||
3733 | } | ||
3734 | |||
3735 | leave: | ||
3736 | if (handle) | ||
3737 | ocfs2_commit_trans(osb, handle); | ||
3738 | if (data_ac) | ||
3739 | ocfs2_free_alloc_context(data_ac); | ||
3740 | if (meta_ac) | ||
3741 | ocfs2_free_alloc_context(meta_ac); | ||
3742 | |||
3743 | return ret; | ||
3744 | } | ||
3745 | |||
3746 | /* | ||
3747 | * Extend a new xattr bucket and move xattrs to the end one by one until | ||
3748 | * We meet with start_bh. Only move half of the xattrs to the bucket after it. | ||
3749 | */ | ||
3750 | static int ocfs2_extend_xattr_bucket(struct inode *inode, | ||
3751 | struct buffer_head *first_bh, | ||
3752 | struct buffer_head *start_bh, | ||
3753 | u32 num_clusters) | ||
3754 | { | ||
3755 | int ret, credits; | ||
3756 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
3757 | u16 blk_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb); | ||
3758 | u64 start_blk = start_bh->b_blocknr, end_blk; | ||
3759 | u32 num_buckets = num_clusters * ocfs2_xattr_buckets_per_cluster(osb); | ||
3760 | handle_t *handle; | ||
3761 | struct ocfs2_xattr_header *first_xh = | ||
3762 | (struct ocfs2_xattr_header *)first_bh->b_data; | ||
3763 | u16 bucket = le16_to_cpu(first_xh->xh_num_buckets); | ||
3764 | |||
3765 | mlog(0, "extend xattr bucket in %llu, xattr extend rec starting " | ||
3766 | "from %llu, len = %u\n", start_blk, | ||
3767 | (unsigned long long)first_bh->b_blocknr, num_clusters); | ||
3768 | |||
3769 | BUG_ON(bucket >= num_buckets); | ||
3770 | |||
3771 | end_blk = first_bh->b_blocknr + (bucket - 1) * blk_per_bucket; | ||
3772 | |||
3773 | /* | ||
3774 | * We will touch all the buckets after the start_bh(include it). | ||
3775 | * Add one more bucket and modify the first_bh. | ||
3776 | */ | ||
3777 | credits = end_blk - start_blk + 2 * blk_per_bucket + 1; | ||
3778 | handle = ocfs2_start_trans(osb, credits); | ||
3779 | if (IS_ERR(handle)) { | ||
3780 | ret = PTR_ERR(handle); | ||
3781 | handle = NULL; | ||
3782 | mlog_errno(ret); | ||
3783 | goto out; | ||
3784 | } | ||
3785 | |||
3786 | ret = ocfs2_journal_access(handle, inode, first_bh, | ||
3787 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
3788 | if (ret) { | ||
3789 | mlog_errno(ret); | ||
3790 | goto commit; | ||
3791 | } | ||
3792 | |||
3793 | while (end_blk != start_blk) { | ||
3794 | ret = ocfs2_cp_xattr_bucket(inode, handle, end_blk, | ||
3795 | end_blk + blk_per_bucket, 0); | ||
3796 | if (ret) | ||
3797 | goto commit; | ||
3798 | end_blk -= blk_per_bucket; | ||
3799 | } | ||
3800 | |||
3801 | /* Move half of the xattr in start_blk to the next bucket. */ | ||
3802 | ret = ocfs2_half_xattr_bucket(inode, handle, start_blk, | ||
3803 | start_blk + blk_per_bucket, NULL, 0); | ||
3804 | |||
3805 | le16_add_cpu(&first_xh->xh_num_buckets, 1); | ||
3806 | ocfs2_journal_dirty(handle, first_bh); | ||
3807 | |||
3808 | commit: | ||
3809 | ocfs2_commit_trans(osb, handle); | ||
3810 | out: | ||
3811 | return ret; | ||
3812 | } | ||
3813 | |||
3814 | /* | ||
3815 | * Add new xattr bucket in an extent record and adjust the buckets accordingly. | ||
3816 | * xb_bh is the ocfs2_xattr_block. | ||
3817 | * We will move all the buckets starting from header_bh to the next place. As | ||
3818 | * for this one, half num of its xattrs will be moved to the next one. | ||
3819 | * | ||
3820 | * We will allocate a new cluster if current cluster is full and adjust | ||
3821 | * header_bh and first_bh if the insert place is moved to the new cluster. | ||
3822 | */ | ||
3823 | static int ocfs2_add_new_xattr_bucket(struct inode *inode, | ||
3824 | struct buffer_head *xb_bh, | ||
3825 | struct buffer_head *header_bh) | ||
3826 | { | ||
3827 | struct ocfs2_xattr_header *first_xh = NULL; | ||
3828 | struct buffer_head *first_bh = NULL; | ||
3829 | struct ocfs2_xattr_block *xb = | ||
3830 | (struct ocfs2_xattr_block *)xb_bh->b_data; | ||
3831 | struct ocfs2_xattr_tree_root *xb_root = &xb->xb_attrs.xb_root; | ||
3832 | struct ocfs2_extent_list *el = &xb_root->xt_list; | ||
3833 | struct ocfs2_xattr_header *xh = | ||
3834 | (struct ocfs2_xattr_header *)header_bh->b_data; | ||
3835 | u32 name_hash = le32_to_cpu(xh->xh_entries[0].xe_name_hash); | ||
3836 | struct super_block *sb = inode->i_sb; | ||
3837 | struct ocfs2_super *osb = OCFS2_SB(sb); | ||
3838 | int ret, num_buckets, extend = 1; | ||
3839 | u64 p_blkno; | ||
3840 | u32 e_cpos, num_clusters; | ||
3841 | |||
3842 | mlog(0, "Add new xattr bucket starting form %llu\n", | ||
3843 | (unsigned long long)header_bh->b_blocknr); | ||
3844 | |||
3845 | /* | ||
3846 | * Add refrence for header_bh here because it may be | ||
3847 | * changed in ocfs2_add_new_xattr_cluster and we need | ||
3848 | * to free it in the end. | ||
3849 | */ | ||
3850 | get_bh(header_bh); | ||
3851 | |||
3852 | ret = ocfs2_xattr_get_rec(inode, name_hash, &p_blkno, &e_cpos, | ||
3853 | &num_clusters, el); | ||
3854 | if (ret) { | ||
3855 | mlog_errno(ret); | ||
3856 | goto out; | ||
3857 | } | ||
3858 | |||
3859 | ret = ocfs2_read_block(inode, p_blkno, &first_bh); | ||
3860 | if (ret) { | ||
3861 | mlog_errno(ret); | ||
3862 | goto out; | ||
3863 | } | ||
3864 | |||
3865 | num_buckets = ocfs2_xattr_buckets_per_cluster(osb) * num_clusters; | ||
3866 | first_xh = (struct ocfs2_xattr_header *)first_bh->b_data; | ||
3867 | |||
3868 | if (num_buckets == le16_to_cpu(first_xh->xh_num_buckets)) { | ||
3869 | ret = ocfs2_add_new_xattr_cluster(inode, | ||
3870 | xb_bh, | ||
3871 | &first_bh, | ||
3872 | &header_bh, | ||
3873 | &num_clusters, | ||
3874 | e_cpos, | ||
3875 | p_blkno, | ||
3876 | &extend); | ||
3877 | if (ret) { | ||
3878 | mlog_errno(ret); | ||
3879 | goto out; | ||
3880 | } | ||
3881 | } | ||
3882 | |||
3883 | if (extend) | ||
3884 | ret = ocfs2_extend_xattr_bucket(inode, | ||
3885 | first_bh, | ||
3886 | header_bh, | ||
3887 | num_clusters); | ||
3888 | if (ret) | ||
3889 | mlog_errno(ret); | ||
3890 | out: | ||
3891 | brelse(first_bh); | ||
3892 | brelse(header_bh); | ||
3893 | return ret; | ||
3894 | } | ||
3895 | |||
3896 | static inline char *ocfs2_xattr_bucket_get_val(struct inode *inode, | ||
3897 | struct ocfs2_xattr_bucket *bucket, | ||
3898 | int offs) | ||
3899 | { | ||
3900 | int block_off = offs >> inode->i_sb->s_blocksize_bits; | ||
3901 | |||
3902 | offs = offs % inode->i_sb->s_blocksize; | ||
3903 | return bucket->bhs[block_off]->b_data + offs; | ||
3904 | } | ||
3905 | |||
3906 | /* | ||
3907 | * Handle the normal xattr set, including replace, delete and new. | ||
3908 | * | ||
3909 | * Note: "local" indicates the real data's locality. So we can't | ||
3910 | * just its bucket locality by its length. | ||
3911 | */ | ||
3912 | static void ocfs2_xattr_set_entry_normal(struct inode *inode, | ||
3913 | struct ocfs2_xattr_info *xi, | ||
3914 | struct ocfs2_xattr_search *xs, | ||
3915 | u32 name_hash, | ||
3916 | int local) | ||
3917 | { | ||
3918 | struct ocfs2_xattr_entry *last, *xe; | ||
3919 | int name_len = strlen(xi->name); | ||
3920 | struct ocfs2_xattr_header *xh = xs->header; | ||
3921 | u16 count = le16_to_cpu(xh->xh_count), start; | ||
3922 | size_t blocksize = inode->i_sb->s_blocksize; | ||
3923 | char *val; | ||
3924 | size_t offs, size, new_size; | ||
3925 | |||
3926 | last = &xh->xh_entries[count]; | ||
3927 | if (!xs->not_found) { | ||
3928 | xe = xs->here; | ||
3929 | offs = le16_to_cpu(xe->xe_name_offset); | ||
3930 | if (ocfs2_xattr_is_local(xe)) | ||
3931 | size = OCFS2_XATTR_SIZE(name_len) + | ||
3932 | OCFS2_XATTR_SIZE(le64_to_cpu(xe->xe_value_size)); | ||
3933 | else | ||
3934 | size = OCFS2_XATTR_SIZE(name_len) + | ||
3935 | OCFS2_XATTR_SIZE(OCFS2_XATTR_ROOT_SIZE); | ||
3936 | |||
3937 | /* | ||
3938 | * If the new value will be stored outside, xi->value has been | ||
3939 | * initalized as an empty ocfs2_xattr_value_root, and the same | ||
3940 | * goes with xi->value_len, so we can set new_size safely here. | ||
3941 | * See ocfs2_xattr_set_in_bucket. | ||
3942 | */ | ||
3943 | new_size = OCFS2_XATTR_SIZE(name_len) + | ||
3944 | OCFS2_XATTR_SIZE(xi->value_len); | ||
3945 | |||
3946 | le16_add_cpu(&xh->xh_name_value_len, -size); | ||
3947 | if (xi->value) { | ||
3948 | if (new_size > size) | ||
3949 | goto set_new_name_value; | ||
3950 | |||
3951 | /* Now replace the old value with new one. */ | ||
3952 | if (local) | ||
3953 | xe->xe_value_size = cpu_to_le64(xi->value_len); | ||
3954 | else | ||
3955 | xe->xe_value_size = 0; | ||
3956 | |||
3957 | val = ocfs2_xattr_bucket_get_val(inode, | ||
3958 | &xs->bucket, offs); | ||
3959 | memset(val + OCFS2_XATTR_SIZE(name_len), 0, | ||
3960 | size - OCFS2_XATTR_SIZE(name_len)); | ||
3961 | if (OCFS2_XATTR_SIZE(xi->value_len) > 0) | ||
3962 | memcpy(val + OCFS2_XATTR_SIZE(name_len), | ||
3963 | xi->value, xi->value_len); | ||
3964 | |||
3965 | le16_add_cpu(&xh->xh_name_value_len, new_size); | ||
3966 | ocfs2_xattr_set_local(xe, local); | ||
3967 | return; | ||
3968 | } else { | ||
3969 | /* | ||
3970 | * Remove the old entry if there is more than one. | ||
3971 | * We don't remove the last entry so that we can | ||
3972 | * use it to indicate the hash value of the empty | ||
3973 | * bucket. | ||
3974 | */ | ||
3975 | last -= 1; | ||
3976 | le16_add_cpu(&xh->xh_count, -1); | ||
3977 | if (xh->xh_count) { | ||
3978 | memmove(xe, xe + 1, | ||
3979 | (void *)last - (void *)xe); | ||
3980 | memset(last, 0, | ||
3981 | sizeof(struct ocfs2_xattr_entry)); | ||
3982 | } else | ||
3983 | xh->xh_free_start = | ||
3984 | cpu_to_le16(OCFS2_XATTR_BUCKET_SIZE); | ||
3985 | |||
3986 | return; | ||
3987 | } | ||
3988 | } else { | ||
3989 | /* find a new entry for insert. */ | ||
3990 | int low = 0, high = count - 1, tmp; | ||
3991 | struct ocfs2_xattr_entry *tmp_xe; | ||
3992 | |||
3993 | while (low <= high && count) { | ||
3994 | tmp = (low + high) / 2; | ||
3995 | tmp_xe = &xh->xh_entries[tmp]; | ||
3996 | |||
3997 | if (name_hash > le32_to_cpu(tmp_xe->xe_name_hash)) | ||
3998 | low = tmp + 1; | ||
3999 | else if (name_hash < | ||
4000 | le32_to_cpu(tmp_xe->xe_name_hash)) | ||
4001 | high = tmp - 1; | ||
4002 | else { | ||
4003 | low = tmp; | ||
4004 | break; | ||
4005 | } | ||
4006 | } | ||
4007 | |||
4008 | xe = &xh->xh_entries[low]; | ||
4009 | if (low != count) | ||
4010 | memmove(xe + 1, xe, (void *)last - (void *)xe); | ||
4011 | |||
4012 | le16_add_cpu(&xh->xh_count, 1); | ||
4013 | memset(xe, 0, sizeof(struct ocfs2_xattr_entry)); | ||
4014 | xe->xe_name_hash = cpu_to_le32(name_hash); | ||
4015 | xe->xe_name_len = name_len; | ||
4016 | ocfs2_xattr_set_type(xe, xi->name_index); | ||
4017 | } | ||
4018 | |||
4019 | set_new_name_value: | ||
4020 | /* Insert the new name+value. */ | ||
4021 | size = OCFS2_XATTR_SIZE(name_len) + OCFS2_XATTR_SIZE(xi->value_len); | ||
4022 | |||
4023 | /* | ||
4024 | * We must make sure that the name/value pair | ||
4025 | * exists in the same block. | ||
4026 | */ | ||
4027 | offs = le16_to_cpu(xh->xh_free_start); | ||
4028 | start = offs - size; | ||
4029 | |||
4030 | if (start >> inode->i_sb->s_blocksize_bits != | ||
4031 | (offs - 1) >> inode->i_sb->s_blocksize_bits) { | ||
4032 | offs = offs - offs % blocksize; | ||
4033 | xh->xh_free_start = cpu_to_le16(offs); | ||
4034 | } | ||
4035 | |||
4036 | val = ocfs2_xattr_bucket_get_val(inode, | ||
4037 | &xs->bucket, offs - size); | ||
4038 | xe->xe_name_offset = cpu_to_le16(offs - size); | ||
4039 | |||
4040 | memset(val, 0, size); | ||
4041 | memcpy(val, xi->name, name_len); | ||
4042 | memcpy(val + OCFS2_XATTR_SIZE(name_len), xi->value, xi->value_len); | ||
4043 | |||
4044 | xe->xe_value_size = cpu_to_le64(xi->value_len); | ||
4045 | ocfs2_xattr_set_local(xe, local); | ||
4046 | xs->here = xe; | ||
4047 | le16_add_cpu(&xh->xh_free_start, -size); | ||
4048 | le16_add_cpu(&xh->xh_name_value_len, size); | ||
4049 | |||
4050 | return; | ||
4051 | } | ||
4052 | |||
4053 | static int ocfs2_xattr_bucket_handle_journal(struct inode *inode, | ||
4054 | handle_t *handle, | ||
4055 | struct ocfs2_xattr_search *xs, | ||
4056 | struct buffer_head **bhs, | ||
4057 | u16 bh_num) | ||
4058 | { | ||
4059 | int ret = 0, off, block_off; | ||
4060 | struct ocfs2_xattr_entry *xe = xs->here; | ||
4061 | |||
4062 | /* | ||
4063 | * First calculate all the blocks we should journal_access | ||
4064 | * and journal_dirty. The first block should always be touched. | ||
4065 | */ | ||
4066 | ret = ocfs2_journal_dirty(handle, bhs[0]); | ||
4067 | if (ret) | ||
4068 | mlog_errno(ret); | ||
4069 | |||
4070 | /* calc the data. */ | ||
4071 | off = le16_to_cpu(xe->xe_name_offset); | ||
4072 | block_off = off >> inode->i_sb->s_blocksize_bits; | ||
4073 | ret = ocfs2_journal_dirty(handle, bhs[block_off]); | ||
4074 | if (ret) | ||
4075 | mlog_errno(ret); | ||
4076 | |||
4077 | return ret; | ||
4078 | } | ||
4079 | |||
4080 | /* | ||
4081 | * Set the xattr entry in the specified bucket. | ||
4082 | * The bucket is indicated by xs->bucket and it should have the enough | ||
4083 | * space for the xattr insertion. | ||
4084 | */ | ||
4085 | static int ocfs2_xattr_set_entry_in_bucket(struct inode *inode, | ||
4086 | struct ocfs2_xattr_info *xi, | ||
4087 | struct ocfs2_xattr_search *xs, | ||
4088 | u32 name_hash, | ||
4089 | int local) | ||
4090 | { | ||
4091 | int i, ret; | ||
4092 | handle_t *handle = NULL; | ||
4093 | u16 blk_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb); | ||
4094 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
4095 | |||
4096 | mlog(0, "Set xattr entry len = %lu index = %d in bucket %llu\n", | ||
4097 | (unsigned long)xi->value_len, xi->name_index, | ||
4098 | (unsigned long long)xs->bucket.bhs[0]->b_blocknr); | ||
4099 | |||
4100 | if (!xs->bucket.bhs[1]) { | ||
4101 | ret = ocfs2_read_blocks(inode, | ||
4102 | xs->bucket.bhs[0]->b_blocknr + 1, | ||
4103 | blk_per_bucket - 1, &xs->bucket.bhs[1], | ||
4104 | OCFS2_BH_CACHED); | ||
4105 | if (ret) { | ||
4106 | mlog_errno(ret); | ||
4107 | goto out; | ||
4108 | } | ||
4109 | } | ||
4110 | |||
4111 | handle = ocfs2_start_trans(osb, blk_per_bucket); | ||
4112 | if (IS_ERR(handle)) { | ||
4113 | ret = PTR_ERR(handle); | ||
4114 | handle = NULL; | ||
4115 | mlog_errno(ret); | ||
4116 | goto out; | ||
4117 | } | ||
4118 | |||
4119 | for (i = 0; i < blk_per_bucket; i++) { | ||
4120 | ret = ocfs2_journal_access(handle, inode, xs->bucket.bhs[i], | ||
4121 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
4122 | if (ret < 0) { | ||
4123 | mlog_errno(ret); | ||
4124 | goto out; | ||
4125 | } | ||
4126 | } | ||
4127 | |||
4128 | ocfs2_xattr_set_entry_normal(inode, xi, xs, name_hash, local); | ||
4129 | |||
4130 | /*Only dirty the blocks we have touched in set xattr. */ | ||
4131 | ret = ocfs2_xattr_bucket_handle_journal(inode, handle, xs, | ||
4132 | xs->bucket.bhs, blk_per_bucket); | ||
4133 | if (ret) | ||
4134 | mlog_errno(ret); | ||
4135 | out: | ||
4136 | ocfs2_commit_trans(osb, handle); | ||
4137 | |||
4138 | return ret; | ||
4139 | } | ||
4140 | |||
4141 | static int ocfs2_xattr_value_update_size(struct inode *inode, | ||
4142 | struct buffer_head *xe_bh, | ||
4143 | struct ocfs2_xattr_entry *xe, | ||
4144 | u64 new_size) | ||
4145 | { | ||
4146 | int ret; | ||
4147 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
4148 | handle_t *handle = NULL; | ||
4149 | |||
4150 | handle = ocfs2_start_trans(osb, 1); | ||
4151 | if (handle == NULL) { | ||
4152 | ret = -ENOMEM; | ||
4153 | mlog_errno(ret); | ||
4154 | goto out; | ||
4155 | } | ||
4156 | |||
4157 | ret = ocfs2_journal_access(handle, inode, xe_bh, | ||
4158 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
4159 | if (ret < 0) { | ||
4160 | mlog_errno(ret); | ||
4161 | goto out_commit; | ||
4162 | } | ||
4163 | |||
4164 | xe->xe_value_size = cpu_to_le64(new_size); | ||
4165 | |||
4166 | ret = ocfs2_journal_dirty(handle, xe_bh); | ||
4167 | if (ret < 0) | ||
4168 | mlog_errno(ret); | ||
4169 | |||
4170 | out_commit: | ||
4171 | ocfs2_commit_trans(osb, handle); | ||
4172 | out: | ||
4173 | return ret; | ||
4174 | } | ||
4175 | |||
4176 | /* | ||
4177 | * Truncate the specified xe_off entry in xattr bucket. | ||
4178 | * bucket is indicated by header_bh and len is the new length. | ||
4179 | * Both the ocfs2_xattr_value_root and the entry will be updated here. | ||
4180 | * | ||
4181 | * Copy the new updated xe and xe_value_root to new_xe and new_xv if needed. | ||
4182 | */ | ||
4183 | static int ocfs2_xattr_bucket_value_truncate(struct inode *inode, | ||
4184 | struct buffer_head *header_bh, | ||
4185 | int xe_off, | ||
4186 | int len) | ||
4187 | { | ||
4188 | int ret, offset; | ||
4189 | u64 value_blk; | ||
4190 | struct buffer_head *value_bh = NULL; | ||
4191 | struct ocfs2_xattr_value_root *xv; | ||
4192 | struct ocfs2_xattr_entry *xe; | ||
4193 | struct ocfs2_xattr_header *xh = | ||
4194 | (struct ocfs2_xattr_header *)header_bh->b_data; | ||
4195 | size_t blocksize = inode->i_sb->s_blocksize; | ||
4196 | |||
4197 | xe = &xh->xh_entries[xe_off]; | ||
4198 | |||
4199 | BUG_ON(!xe || ocfs2_xattr_is_local(xe)); | ||
4200 | |||
4201 | offset = le16_to_cpu(xe->xe_name_offset) + | ||
4202 | OCFS2_XATTR_SIZE(xe->xe_name_len); | ||
4203 | |||
4204 | value_blk = offset / blocksize; | ||
4205 | |||
4206 | /* We don't allow ocfs2_xattr_value to be stored in different block. */ | ||
4207 | BUG_ON(value_blk != (offset + OCFS2_XATTR_ROOT_SIZE - 1) / blocksize); | ||
4208 | value_blk += header_bh->b_blocknr; | ||
4209 | |||
4210 | ret = ocfs2_read_block(inode, value_blk, &value_bh); | ||
4211 | if (ret) { | ||
4212 | mlog_errno(ret); | ||
4213 | goto out; | ||
4214 | } | ||
4215 | |||
4216 | xv = (struct ocfs2_xattr_value_root *) | ||
4217 | (value_bh->b_data + offset % blocksize); | ||
4218 | |||
4219 | mlog(0, "truncate %u in xattr bucket %llu to %d bytes.\n", | ||
4220 | xe_off, (unsigned long long)header_bh->b_blocknr, len); | ||
4221 | ret = ocfs2_xattr_value_truncate(inode, value_bh, xv, len); | ||
4222 | if (ret) { | ||
4223 | mlog_errno(ret); | ||
4224 | goto out; | ||
4225 | } | ||
4226 | |||
4227 | ret = ocfs2_xattr_value_update_size(inode, header_bh, xe, len); | ||
4228 | if (ret) { | ||
4229 | mlog_errno(ret); | ||
4230 | goto out; | ||
4231 | } | ||
4232 | |||
4233 | out: | ||
4234 | brelse(value_bh); | ||
4235 | return ret; | ||
4236 | } | ||
4237 | |||
4238 | static int ocfs2_xattr_bucket_value_truncate_xs(struct inode *inode, | ||
4239 | struct ocfs2_xattr_search *xs, | ||
4240 | int len) | ||
4241 | { | ||
4242 | int ret, offset; | ||
4243 | struct ocfs2_xattr_entry *xe = xs->here; | ||
4244 | struct ocfs2_xattr_header *xh = (struct ocfs2_xattr_header *)xs->base; | ||
4245 | |||
4246 | BUG_ON(!xs->bucket.bhs[0] || !xe || ocfs2_xattr_is_local(xe)); | ||
4247 | |||
4248 | offset = xe - xh->xh_entries; | ||
4249 | ret = ocfs2_xattr_bucket_value_truncate(inode, xs->bucket.bhs[0], | ||
4250 | offset, len); | ||
4251 | if (ret) | ||
4252 | mlog_errno(ret); | ||
4253 | |||
4254 | return ret; | ||
4255 | } | ||
4256 | |||
4257 | static int ocfs2_xattr_bucket_set_value_outside(struct inode *inode, | ||
4258 | struct ocfs2_xattr_search *xs, | ||
4259 | char *val, | ||
4260 | int value_len) | ||
4261 | { | ||
4262 | int offset; | ||
4263 | struct ocfs2_xattr_value_root *xv; | ||
4264 | struct ocfs2_xattr_entry *xe = xs->here; | ||
4265 | |||
4266 | BUG_ON(!xs->base || !xe || ocfs2_xattr_is_local(xe)); | ||
4267 | |||
4268 | offset = le16_to_cpu(xe->xe_name_offset) + | ||
4269 | OCFS2_XATTR_SIZE(xe->xe_name_len); | ||
4270 | |||
4271 | xv = (struct ocfs2_xattr_value_root *)(xs->base + offset); | ||
4272 | |||
4273 | return __ocfs2_xattr_set_value_outside(inode, xv, val, value_len); | ||
4274 | } | ||
4275 | |||
4276 | static int ocfs2_rm_xattr_cluster(struct inode *inode, | ||
4277 | struct buffer_head *root_bh, | ||
4278 | u64 blkno, | ||
4279 | u32 cpos, | ||
4280 | u32 len) | ||
4281 | { | ||
4282 | int ret; | ||
4283 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
4284 | struct inode *tl_inode = osb->osb_tl_inode; | ||
4285 | handle_t *handle; | ||
4286 | struct ocfs2_xattr_block *xb = | ||
4287 | (struct ocfs2_xattr_block *)root_bh->b_data; | ||
4288 | struct ocfs2_alloc_context *meta_ac = NULL; | ||
4289 | struct ocfs2_cached_dealloc_ctxt dealloc; | ||
4290 | struct ocfs2_extent_tree et; | ||
4291 | |||
4292 | ocfs2_init_xattr_tree_extent_tree(&et, inode, root_bh); | ||
4293 | |||
4294 | ocfs2_init_dealloc_ctxt(&dealloc); | ||
4295 | |||
4296 | mlog(0, "rm xattr extent rec at %u len = %u, start from %llu\n", | ||
4297 | cpos, len, (unsigned long long)blkno); | ||
4298 | |||
4299 | ocfs2_remove_xattr_clusters_from_cache(inode, blkno, len); | ||
4300 | |||
4301 | ret = ocfs2_lock_allocators(inode, &et, 0, 1, NULL, &meta_ac); | ||
4302 | if (ret) { | ||
4303 | mlog_errno(ret); | ||
4304 | return ret; | ||
4305 | } | ||
4306 | |||
4307 | mutex_lock(&tl_inode->i_mutex); | ||
4308 | |||
4309 | if (ocfs2_truncate_log_needs_flush(osb)) { | ||
4310 | ret = __ocfs2_flush_truncate_log(osb); | ||
4311 | if (ret < 0) { | ||
4312 | mlog_errno(ret); | ||
4313 | goto out; | ||
4314 | } | ||
4315 | } | ||
4316 | |||
4317 | handle = ocfs2_start_trans(osb, OCFS2_REMOVE_EXTENT_CREDITS); | ||
4318 | if (handle == NULL) { | ||
4319 | ret = -ENOMEM; | ||
4320 | mlog_errno(ret); | ||
4321 | goto out; | ||
4322 | } | ||
4323 | |||
4324 | ret = ocfs2_journal_access(handle, inode, root_bh, | ||
4325 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
4326 | if (ret) { | ||
4327 | mlog_errno(ret); | ||
4328 | goto out_commit; | ||
4329 | } | ||
4330 | |||
4331 | ret = ocfs2_remove_extent(inode, &et, cpos, len, handle, meta_ac, | ||
4332 | &dealloc); | ||
4333 | if (ret) { | ||
4334 | mlog_errno(ret); | ||
4335 | goto out_commit; | ||
4336 | } | ||
4337 | |||
4338 | le32_add_cpu(&xb->xb_attrs.xb_root.xt_clusters, -len); | ||
4339 | |||
4340 | ret = ocfs2_journal_dirty(handle, root_bh); | ||
4341 | if (ret) { | ||
4342 | mlog_errno(ret); | ||
4343 | goto out_commit; | ||
4344 | } | ||
4345 | |||
4346 | ret = ocfs2_truncate_log_append(osb, handle, blkno, len); | ||
4347 | if (ret) | ||
4348 | mlog_errno(ret); | ||
4349 | |||
4350 | out_commit: | ||
4351 | ocfs2_commit_trans(osb, handle); | ||
4352 | out: | ||
4353 | ocfs2_schedule_truncate_log_flush(osb, 1); | ||
4354 | |||
4355 | mutex_unlock(&tl_inode->i_mutex); | ||
4356 | |||
4357 | if (meta_ac) | ||
4358 | ocfs2_free_alloc_context(meta_ac); | ||
4359 | |||
4360 | ocfs2_run_deallocs(osb, &dealloc); | ||
4361 | |||
4362 | return ret; | ||
4363 | } | ||
4364 | |||
4365 | static void ocfs2_xattr_bucket_remove_xs(struct inode *inode, | ||
4366 | struct ocfs2_xattr_search *xs) | ||
4367 | { | ||
4368 | handle_t *handle = NULL; | ||
4369 | struct ocfs2_xattr_header *xh = xs->bucket.xh; | ||
4370 | struct ocfs2_xattr_entry *last = &xh->xh_entries[ | ||
4371 | le16_to_cpu(xh->xh_count) - 1]; | ||
4372 | int ret = 0; | ||
4373 | |||
4374 | handle = ocfs2_start_trans((OCFS2_SB(inode->i_sb)), 1); | ||
4375 | if (IS_ERR(handle)) { | ||
4376 | ret = PTR_ERR(handle); | ||
4377 | mlog_errno(ret); | ||
4378 | return; | ||
4379 | } | ||
4380 | |||
4381 | ret = ocfs2_journal_access(handle, inode, xs->bucket.bhs[0], | ||
4382 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
4383 | if (ret) { | ||
4384 | mlog_errno(ret); | ||
4385 | goto out_commit; | ||
4386 | } | ||
4387 | |||
4388 | /* Remove the old entry. */ | ||
4389 | memmove(xs->here, xs->here + 1, | ||
4390 | (void *)last - (void *)xs->here); | ||
4391 | memset(last, 0, sizeof(struct ocfs2_xattr_entry)); | ||
4392 | le16_add_cpu(&xh->xh_count, -1); | ||
4393 | |||
4394 | ret = ocfs2_journal_dirty(handle, xs->bucket.bhs[0]); | ||
4395 | if (ret < 0) | ||
4396 | mlog_errno(ret); | ||
4397 | out_commit: | ||
4398 | ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle); | ||
4399 | } | ||
4400 | |||
4401 | /* | ||
4402 | * Set the xattr name/value in the bucket specified in xs. | ||
4403 | * | ||
4404 | * As the new value in xi may be stored in the bucket or in an outside cluster, | ||
4405 | * we divide the whole process into 3 steps: | ||
4406 | * 1. insert name/value in the bucket(ocfs2_xattr_set_entry_in_bucket) | ||
4407 | * 2. truncate of the outside cluster(ocfs2_xattr_bucket_value_truncate_xs) | ||
4408 | * 3. Set the value to the outside cluster(ocfs2_xattr_bucket_set_value_outside) | ||
4409 | * 4. If the clusters for the new outside value can't be allocated, we need | ||
4410 | * to free the xattr we allocated in set. | ||
4411 | */ | ||
4412 | static int ocfs2_xattr_set_in_bucket(struct inode *inode, | ||
4413 | struct ocfs2_xattr_info *xi, | ||
4414 | struct ocfs2_xattr_search *xs) | ||
4415 | { | ||
4416 | int ret, local = 1; | ||
4417 | size_t value_len; | ||
4418 | char *val = (char *)xi->value; | ||
4419 | struct ocfs2_xattr_entry *xe = xs->here; | ||
4420 | u32 name_hash = ocfs2_xattr_name_hash(inode, xi->name, | ||
4421 | strlen(xi->name)); | ||
4422 | |||
4423 | if (!xs->not_found && !ocfs2_xattr_is_local(xe)) { | ||
4424 | /* | ||
4425 | * We need to truncate the xattr storage first. | ||
4426 | * | ||
4427 | * If both the old and new value are stored to | ||
4428 | * outside block, we only need to truncate | ||
4429 | * the storage and then set the value outside. | ||
4430 | * | ||
4431 | * If the new value should be stored within block, | ||
4432 | * we should free all the outside block first and | ||
4433 | * the modification to the xattr block will be done | ||
4434 | * by following steps. | ||
4435 | */ | ||
4436 | if (xi->value_len > OCFS2_XATTR_INLINE_SIZE) | ||
4437 | value_len = xi->value_len; | ||
4438 | else | ||
4439 | value_len = 0; | ||
4440 | |||
4441 | ret = ocfs2_xattr_bucket_value_truncate_xs(inode, xs, | ||
4442 | value_len); | ||
4443 | if (ret) | ||
4444 | goto out; | ||
4445 | |||
4446 | if (value_len) | ||
4447 | goto set_value_outside; | ||
4448 | } | ||
4449 | |||
4450 | value_len = xi->value_len; | ||
4451 | /* So we have to handle the inside block change now. */ | ||
4452 | if (value_len > OCFS2_XATTR_INLINE_SIZE) { | ||
4453 | /* | ||
4454 | * If the new value will be stored outside of block, | ||
4455 | * initalize a new empty value root and insert it first. | ||
4456 | */ | ||
4457 | local = 0; | ||
4458 | xi->value = &def_xv; | ||
4459 | xi->value_len = OCFS2_XATTR_ROOT_SIZE; | ||
4460 | } | ||
4461 | |||
4462 | ret = ocfs2_xattr_set_entry_in_bucket(inode, xi, xs, name_hash, local); | ||
4463 | if (ret) { | ||
4464 | mlog_errno(ret); | ||
4465 | goto out; | ||
4466 | } | ||
4467 | |||
4468 | if (value_len <= OCFS2_XATTR_INLINE_SIZE) | ||
4469 | goto out; | ||
4470 | |||
4471 | /* allocate the space now for the outside block storage. */ | ||
4472 | ret = ocfs2_xattr_bucket_value_truncate_xs(inode, xs, | ||
4473 | value_len); | ||
4474 | if (ret) { | ||
4475 | mlog_errno(ret); | ||
4476 | |||
4477 | if (xs->not_found) { | ||
4478 | /* | ||
4479 | * We can't allocate enough clusters for outside | ||
4480 | * storage and we have allocated xattr already, | ||
4481 | * so need to remove it. | ||
4482 | */ | ||
4483 | ocfs2_xattr_bucket_remove_xs(inode, xs); | ||
4484 | } | ||
4485 | goto out; | ||
4486 | } | ||
4487 | |||
4488 | set_value_outside: | ||
4489 | ret = ocfs2_xattr_bucket_set_value_outside(inode, xs, val, value_len); | ||
4490 | out: | ||
4491 | return ret; | ||
4492 | } | ||
4493 | |||
4494 | /* check whether the xattr bucket is filled up with the same hash value. */ | ||
4495 | static int ocfs2_check_xattr_bucket_collision(struct inode *inode, | ||
4496 | struct ocfs2_xattr_bucket *bucket) | ||
4497 | { | ||
4498 | struct ocfs2_xattr_header *xh = bucket->xh; | ||
4499 | |||
4500 | if (xh->xh_entries[le16_to_cpu(xh->xh_count) - 1].xe_name_hash == | ||
4501 | xh->xh_entries[0].xe_name_hash) { | ||
4502 | mlog(ML_ERROR, "Too much hash collision in xattr bucket %llu, " | ||
4503 | "hash = %u\n", | ||
4504 | (unsigned long long)bucket->bhs[0]->b_blocknr, | ||
4505 | le32_to_cpu(xh->xh_entries[0].xe_name_hash)); | ||
4506 | return -ENOSPC; | ||
4507 | } | ||
4508 | |||
4509 | return 0; | ||
4510 | } | ||
4511 | |||
4512 | static int ocfs2_xattr_set_entry_index_block(struct inode *inode, | ||
4513 | struct ocfs2_xattr_info *xi, | ||
4514 | struct ocfs2_xattr_search *xs) | ||
4515 | { | ||
4516 | struct ocfs2_xattr_header *xh; | ||
4517 | struct ocfs2_xattr_entry *xe; | ||
4518 | u16 count, header_size, xh_free_start; | ||
4519 | int i, free, max_free, need, old; | ||
4520 | size_t value_size = 0, name_len = strlen(xi->name); | ||
4521 | size_t blocksize = inode->i_sb->s_blocksize; | ||
4522 | int ret, allocation = 0; | ||
4523 | u16 blk_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb); | ||
4524 | |||
4525 | mlog_entry("Set xattr %s in xattr index block\n", xi->name); | ||
4526 | |||
4527 | try_again: | ||
4528 | xh = xs->header; | ||
4529 | count = le16_to_cpu(xh->xh_count); | ||
4530 | xh_free_start = le16_to_cpu(xh->xh_free_start); | ||
4531 | header_size = sizeof(struct ocfs2_xattr_header) + | ||
4532 | count * sizeof(struct ocfs2_xattr_entry); | ||
4533 | max_free = OCFS2_XATTR_BUCKET_SIZE - | ||
4534 | le16_to_cpu(xh->xh_name_value_len) - header_size; | ||
4535 | |||
4536 | mlog_bug_on_msg(header_size > blocksize, "bucket %llu has header size " | ||
4537 | "of %u which exceed block size\n", | ||
4538 | (unsigned long long)xs->bucket.bhs[0]->b_blocknr, | ||
4539 | header_size); | ||
4540 | |||
4541 | if (xi->value && xi->value_len > OCFS2_XATTR_INLINE_SIZE) | ||
4542 | value_size = OCFS2_XATTR_ROOT_SIZE; | ||
4543 | else if (xi->value) | ||
4544 | value_size = OCFS2_XATTR_SIZE(xi->value_len); | ||
4545 | |||
4546 | if (xs->not_found) | ||
4547 | need = sizeof(struct ocfs2_xattr_entry) + | ||
4548 | OCFS2_XATTR_SIZE(name_len) + value_size; | ||
4549 | else { | ||
4550 | need = value_size + OCFS2_XATTR_SIZE(name_len); | ||
4551 | |||
4552 | /* | ||
4553 | * We only replace the old value if the new length is smaller | ||
4554 | * than the old one. Otherwise we will allocate new space in the | ||
4555 | * bucket to store it. | ||
4556 | */ | ||
4557 | xe = xs->here; | ||
4558 | if (ocfs2_xattr_is_local(xe)) | ||
4559 | old = OCFS2_XATTR_SIZE(le64_to_cpu(xe->xe_value_size)); | ||
4560 | else | ||
4561 | old = OCFS2_XATTR_SIZE(OCFS2_XATTR_ROOT_SIZE); | ||
4562 | |||
4563 | if (old >= value_size) | ||
4564 | need = 0; | ||
4565 | } | ||
4566 | |||
4567 | free = xh_free_start - header_size; | ||
4568 | /* | ||
4569 | * We need to make sure the new name/value pair | ||
4570 | * can exist in the same block. | ||
4571 | */ | ||
4572 | if (xh_free_start % blocksize < need) | ||
4573 | free -= xh_free_start % blocksize; | ||
4574 | |||
4575 | mlog(0, "xs->not_found = %d, in xattr bucket %llu: free = %d, " | ||
4576 | "need = %d, max_free = %d, xh_free_start = %u, xh_name_value_len =" | ||
4577 | " %u\n", xs->not_found, | ||
4578 | (unsigned long long)xs->bucket.bhs[0]->b_blocknr, | ||
4579 | free, need, max_free, le16_to_cpu(xh->xh_free_start), | ||
4580 | le16_to_cpu(xh->xh_name_value_len)); | ||
4581 | |||
4582 | if (free < need || count == ocfs2_xattr_max_xe_in_bucket(inode->i_sb)) { | ||
4583 | if (need <= max_free && | ||
4584 | count < ocfs2_xattr_max_xe_in_bucket(inode->i_sb)) { | ||
4585 | /* | ||
4586 | * We can create the space by defragment. Since only the | ||
4587 | * name/value will be moved, the xe shouldn't be changed | ||
4588 | * in xs. | ||
4589 | */ | ||
4590 | ret = ocfs2_defrag_xattr_bucket(inode, &xs->bucket); | ||
4591 | if (ret) { | ||
4592 | mlog_errno(ret); | ||
4593 | goto out; | ||
4594 | } | ||
4595 | |||
4596 | xh_free_start = le16_to_cpu(xh->xh_free_start); | ||
4597 | free = xh_free_start - header_size; | ||
4598 | if (xh_free_start % blocksize < need) | ||
4599 | free -= xh_free_start % blocksize; | ||
4600 | |||
4601 | if (free >= need) | ||
4602 | goto xattr_set; | ||
4603 | |||
4604 | mlog(0, "Can't get enough space for xattr insert by " | ||
4605 | "defragment. Need %u bytes, but we have %d, so " | ||
4606 | "allocate new bucket for it.\n", need, free); | ||
4607 | } | ||
4608 | |||
4609 | /* | ||
4610 | * We have to add new buckets or clusters and one | ||
4611 | * allocation should leave us enough space for insert. | ||
4612 | */ | ||
4613 | BUG_ON(allocation); | ||
4614 | |||
4615 | /* | ||
4616 | * We do not allow for overlapping ranges between buckets. And | ||
4617 | * the maximum number of collisions we will allow for then is | ||
4618 | * one bucket's worth, so check it here whether we need to | ||
4619 | * add a new bucket for the insert. | ||
4620 | */ | ||
4621 | ret = ocfs2_check_xattr_bucket_collision(inode, &xs->bucket); | ||
4622 | if (ret) { | ||
4623 | mlog_errno(ret); | ||
4624 | goto out; | ||
4625 | } | ||
4626 | |||
4627 | ret = ocfs2_add_new_xattr_bucket(inode, | ||
4628 | xs->xattr_bh, | ||
4629 | xs->bucket.bhs[0]); | ||
4630 | if (ret) { | ||
4631 | mlog_errno(ret); | ||
4632 | goto out; | ||
4633 | } | ||
4634 | |||
4635 | for (i = 0; i < blk_per_bucket; i++) | ||
4636 | brelse(xs->bucket.bhs[i]); | ||
4637 | |||
4638 | memset(&xs->bucket, 0, sizeof(xs->bucket)); | ||
4639 | |||
4640 | ret = ocfs2_xattr_index_block_find(inode, xs->xattr_bh, | ||
4641 | xi->name_index, | ||
4642 | xi->name, xs); | ||
4643 | if (ret && ret != -ENODATA) | ||
4644 | goto out; | ||
4645 | xs->not_found = ret; | ||
4646 | allocation = 1; | ||
4647 | goto try_again; | ||
4648 | } | ||
4649 | |||
4650 | xattr_set: | ||
4651 | ret = ocfs2_xattr_set_in_bucket(inode, xi, xs); | ||
4652 | out: | ||
4653 | mlog_exit(ret); | ||
4654 | return ret; | ||
4655 | } | ||
4656 | |||
4657 | static int ocfs2_delete_xattr_in_bucket(struct inode *inode, | ||
4658 | struct ocfs2_xattr_bucket *bucket, | ||
4659 | void *para) | ||
4660 | { | ||
4661 | int ret = 0; | ||
4662 | struct ocfs2_xattr_header *xh = bucket->xh; | ||
4663 | u16 i; | ||
4664 | struct ocfs2_xattr_entry *xe; | ||
4665 | |||
4666 | for (i = 0; i < le16_to_cpu(xh->xh_count); i++) { | ||
4667 | xe = &xh->xh_entries[i]; | ||
4668 | if (ocfs2_xattr_is_local(xe)) | ||
4669 | continue; | ||
4670 | |||
4671 | ret = ocfs2_xattr_bucket_value_truncate(inode, | ||
4672 | bucket->bhs[0], | ||
4673 | i, 0); | ||
4674 | if (ret) { | ||
4675 | mlog_errno(ret); | ||
4676 | break; | ||
4677 | } | ||
4678 | } | ||
4679 | |||
4680 | return ret; | ||
4681 | } | ||
4682 | |||
4683 | static int ocfs2_delete_xattr_index_block(struct inode *inode, | ||
4684 | struct buffer_head *xb_bh) | ||
4685 | { | ||
4686 | struct ocfs2_xattr_block *xb = | ||
4687 | (struct ocfs2_xattr_block *)xb_bh->b_data; | ||
4688 | struct ocfs2_extent_list *el = &xb->xb_attrs.xb_root.xt_list; | ||
4689 | int ret = 0; | ||
4690 | u32 name_hash = UINT_MAX, e_cpos, num_clusters; | ||
4691 | u64 p_blkno; | ||
4692 | |||
4693 | if (le16_to_cpu(el->l_next_free_rec) == 0) | ||
4694 | return 0; | ||
4695 | |||
4696 | while (name_hash > 0) { | ||
4697 | ret = ocfs2_xattr_get_rec(inode, name_hash, &p_blkno, | ||
4698 | &e_cpos, &num_clusters, el); | ||
4699 | if (ret) { | ||
4700 | mlog_errno(ret); | ||
4701 | goto out; | ||
4702 | } | ||
4703 | |||
4704 | ret = ocfs2_iterate_xattr_buckets(inode, p_blkno, num_clusters, | ||
4705 | ocfs2_delete_xattr_in_bucket, | ||
4706 | NULL); | ||
4707 | if (ret) { | ||
4708 | mlog_errno(ret); | ||
4709 | goto out; | ||
4710 | } | ||
4711 | |||
4712 | ret = ocfs2_rm_xattr_cluster(inode, xb_bh, | ||
4713 | p_blkno, e_cpos, num_clusters); | ||
4714 | if (ret) { | ||
4715 | mlog_errno(ret); | ||
4716 | break; | ||
4717 | } | ||
4718 | |||
4719 | if (e_cpos == 0) | ||
4720 | break; | ||
4721 | |||
4722 | name_hash = e_cpos - 1; | ||
4723 | } | ||
4724 | |||
4725 | out: | ||
4726 | return ret; | ||
4727 | } | ||
4728 | |||
4729 | /* | ||
4730 | * 'trusted' attributes support | ||
4731 | */ | ||
4732 | |||
4733 | #define XATTR_TRUSTED_PREFIX "trusted." | ||
4734 | |||
4735 | static size_t ocfs2_xattr_trusted_list(struct inode *inode, char *list, | ||
4736 | size_t list_size, const char *name, | ||
4737 | size_t name_len) | ||
4738 | { | ||
4739 | const size_t prefix_len = sizeof(XATTR_TRUSTED_PREFIX) - 1; | ||
4740 | const size_t total_len = prefix_len + name_len + 1; | ||
4741 | |||
4742 | if (list && total_len <= list_size) { | ||
4743 | memcpy(list, XATTR_TRUSTED_PREFIX, prefix_len); | ||
4744 | memcpy(list + prefix_len, name, name_len); | ||
4745 | list[prefix_len + name_len] = '\0'; | ||
4746 | } | ||
4747 | return total_len; | ||
4748 | } | ||
4749 | |||
4750 | static int ocfs2_xattr_trusted_get(struct inode *inode, const char *name, | ||
4751 | void *buffer, size_t size) | ||
4752 | { | ||
4753 | if (strcmp(name, "") == 0) | ||
4754 | return -EINVAL; | ||
4755 | return ocfs2_xattr_get(inode, OCFS2_XATTR_INDEX_TRUSTED, name, | ||
4756 | buffer, size); | ||
4757 | } | ||
4758 | |||
4759 | static int ocfs2_xattr_trusted_set(struct inode *inode, const char *name, | ||
4760 | const void *value, size_t size, int flags) | ||
4761 | { | ||
4762 | if (strcmp(name, "") == 0) | ||
4763 | return -EINVAL; | ||
4764 | |||
4765 | return ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_TRUSTED, name, value, | ||
4766 | size, flags); | ||
4767 | } | ||
4768 | |||
4769 | struct xattr_handler ocfs2_xattr_trusted_handler = { | ||
4770 | .prefix = XATTR_TRUSTED_PREFIX, | ||
4771 | .list = ocfs2_xattr_trusted_list, | ||
4772 | .get = ocfs2_xattr_trusted_get, | ||
4773 | .set = ocfs2_xattr_trusted_set, | ||
4774 | }; | ||
4775 | |||
4776 | |||
4777 | /* | ||
4778 | * 'user' attributes support | ||
4779 | */ | ||
4780 | |||
4781 | #define XATTR_USER_PREFIX "user." | ||
4782 | |||
4783 | static size_t ocfs2_xattr_user_list(struct inode *inode, char *list, | ||
4784 | size_t list_size, const char *name, | ||
4785 | size_t name_len) | ||
4786 | { | ||
4787 | const size_t prefix_len = sizeof(XATTR_USER_PREFIX) - 1; | ||
4788 | const size_t total_len = prefix_len + name_len + 1; | ||
4789 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
4790 | |||
4791 | if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR) | ||
4792 | return 0; | ||
4793 | |||
4794 | if (list && total_len <= list_size) { | ||
4795 | memcpy(list, XATTR_USER_PREFIX, prefix_len); | ||
4796 | memcpy(list + prefix_len, name, name_len); | ||
4797 | list[prefix_len + name_len] = '\0'; | ||
4798 | } | ||
4799 | return total_len; | ||
4800 | } | ||
4801 | |||
4802 | static int ocfs2_xattr_user_get(struct inode *inode, const char *name, | ||
4803 | void *buffer, size_t size) | ||
4804 | { | ||
4805 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
4806 | |||
4807 | if (strcmp(name, "") == 0) | ||
4808 | return -EINVAL; | ||
4809 | if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR) | ||
4810 | return -EOPNOTSUPP; | ||
4811 | return ocfs2_xattr_get(inode, OCFS2_XATTR_INDEX_USER, name, | ||
4812 | buffer, size); | ||
4813 | } | ||
4814 | |||
4815 | static int ocfs2_xattr_user_set(struct inode *inode, const char *name, | ||
4816 | const void *value, size_t size, int flags) | ||
4817 | { | ||
4818 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
4819 | |||
4820 | if (strcmp(name, "") == 0) | ||
4821 | return -EINVAL; | ||
4822 | if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR) | ||
4823 | return -EOPNOTSUPP; | ||
4824 | |||
4825 | return ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_USER, name, value, | ||
4826 | size, flags); | ||
4827 | } | ||
4828 | |||
4829 | struct xattr_handler ocfs2_xattr_user_handler = { | ||
4830 | .prefix = XATTR_USER_PREFIX, | ||
4831 | .list = ocfs2_xattr_user_list, | ||
4832 | .get = ocfs2_xattr_user_get, | ||
4833 | .set = ocfs2_xattr_user_set, | ||
4834 | }; | ||
diff --git a/fs/ocfs2/xattr.h b/fs/ocfs2/xattr.h new file mode 100644 index 000000000000..c25c7c62a059 --- /dev/null +++ b/fs/ocfs2/xattr.h | |||
@@ -0,0 +1,68 @@ | |||
1 | /* -*- mode: c; c-basic-offset: 8; -*- | ||
2 | * vim: noexpandtab sw=8 ts=8 sts=0: | ||
3 | * | ||
4 | * xattr.h | ||
5 | * | ||
6 | * Function prototypes | ||
7 | * | ||
8 | * Copyright (C) 2008 Oracle. All rights reserved. | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or | ||
11 | * modify it under the terms of the GNU General Public | ||
12 | * License as published by the Free Software Foundation; either | ||
13 | * version 2 of the License, or (at your option) any later version. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
18 | * General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public | ||
21 | * License along with this program; if not, write to the | ||
22 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
23 | * Boston, MA 021110-1307, USA. | ||
24 | */ | ||
25 | |||
26 | #ifndef OCFS2_XATTR_H | ||
27 | #define OCFS2_XATTR_H | ||
28 | |||
29 | #include <linux/init.h> | ||
30 | #include <linux/xattr.h> | ||
31 | |||
32 | enum ocfs2_xattr_type { | ||
33 | OCFS2_XATTR_INDEX_USER = 1, | ||
34 | OCFS2_XATTR_INDEX_POSIX_ACL_ACCESS, | ||
35 | OCFS2_XATTR_INDEX_POSIX_ACL_DEFAULT, | ||
36 | OCFS2_XATTR_INDEX_TRUSTED, | ||
37 | OCFS2_XATTR_INDEX_SECURITY, | ||
38 | OCFS2_XATTR_MAX | ||
39 | }; | ||
40 | |||
41 | extern struct xattr_handler ocfs2_xattr_user_handler; | ||
42 | extern struct xattr_handler ocfs2_xattr_trusted_handler; | ||
43 | |||
44 | extern ssize_t ocfs2_listxattr(struct dentry *, char *, size_t); | ||
45 | extern int ocfs2_xattr_get(struct inode *, int, const char *, void *, size_t); | ||
46 | extern int ocfs2_xattr_set(struct inode *, int, const char *, const void *, | ||
47 | size_t, int); | ||
48 | extern int ocfs2_xattr_remove(struct inode *inode, struct buffer_head *di_bh); | ||
49 | extern struct xattr_handler *ocfs2_xattr_handlers[]; | ||
50 | |||
51 | static inline u16 ocfs2_xattr_buckets_per_cluster(struct ocfs2_super *osb) | ||
52 | { | ||
53 | return (1 << osb->s_clustersize_bits) / OCFS2_XATTR_BUCKET_SIZE; | ||
54 | } | ||
55 | |||
56 | static inline u16 ocfs2_blocks_per_xattr_bucket(struct super_block *sb) | ||
57 | { | ||
58 | return OCFS2_XATTR_BUCKET_SIZE / (1 << sb->s_blocksize_bits); | ||
59 | } | ||
60 | |||
61 | static inline u16 ocfs2_xattr_max_xe_in_bucket(struct super_block *sb) | ||
62 | { | ||
63 | u16 len = sb->s_blocksize - | ||
64 | offsetof(struct ocfs2_xattr_header, xh_entries); | ||
65 | |||
66 | return len / sizeof(struct ocfs2_xattr_entry); | ||
67 | } | ||
68 | #endif /* OCFS2_XATTR_H */ | ||
diff --git a/fs/proc/proc_misc.c b/fs/proc/proc_misc.c index 66c1ab87656c..b675a49c1823 100644 --- a/fs/proc/proc_misc.c +++ b/fs/proc/proc_misc.c | |||
@@ -683,6 +683,7 @@ static int cmdline_read_proc(char *page, char **start, off_t off, | |||
683 | return proc_calc_metrics(page, start, off, count, eof, len); | 683 | return proc_calc_metrics(page, start, off, count, eof, len); |
684 | } | 684 | } |
685 | 685 | ||
686 | #ifdef CONFIG_FILE_LOCKING | ||
686 | static int locks_open(struct inode *inode, struct file *filp) | 687 | static int locks_open(struct inode *inode, struct file *filp) |
687 | { | 688 | { |
688 | return seq_open(filp, &locks_seq_operations); | 689 | return seq_open(filp, &locks_seq_operations); |
@@ -694,6 +695,7 @@ static const struct file_operations proc_locks_operations = { | |||
694 | .llseek = seq_lseek, | 695 | .llseek = seq_lseek, |
695 | .release = seq_release, | 696 | .release = seq_release, |
696 | }; | 697 | }; |
698 | #endif /* CONFIG_FILE_LOCKING */ | ||
697 | 699 | ||
698 | static int execdomains_read_proc(char *page, char **start, off_t off, | 700 | static int execdomains_read_proc(char *page, char **start, off_t off, |
699 | int count, int *eof, void *data) | 701 | int count, int *eof, void *data) |
@@ -887,7 +889,9 @@ void __init proc_misc_init(void) | |||
887 | #ifdef CONFIG_PRINTK | 889 | #ifdef CONFIG_PRINTK |
888 | proc_create("kmsg", S_IRUSR, NULL, &proc_kmsg_operations); | 890 | proc_create("kmsg", S_IRUSR, NULL, &proc_kmsg_operations); |
889 | #endif | 891 | #endif |
892 | #ifdef CONFIG_FILE_LOCKING | ||
890 | proc_create("locks", 0, NULL, &proc_locks_operations); | 893 | proc_create("locks", 0, NULL, &proc_locks_operations); |
894 | #endif | ||
891 | proc_create("devices", 0, NULL, &proc_devinfo_operations); | 895 | proc_create("devices", 0, NULL, &proc_devinfo_operations); |
892 | proc_create("cpuinfo", 0, NULL, &proc_cpuinfo_operations); | 896 | proc_create("cpuinfo", 0, NULL, &proc_cpuinfo_operations); |
893 | #ifdef CONFIG_BLOCK | 897 | #ifdef CONFIG_BLOCK |
diff --git a/include/asm-m68k/atarihw.h b/include/asm-m68k/atarihw.h index ecf007df7743..1412b4ab202f 100644 --- a/include/asm-m68k/atarihw.h +++ b/include/asm-m68k/atarihw.h | |||
@@ -39,7 +39,6 @@ extern int atari_dont_touch_floppy_select; | |||
39 | #define MACH_IS_TT ((atari_mch_cookie >> 16) == ATARI_MCH_TT) | 39 | #define MACH_IS_TT ((atari_mch_cookie >> 16) == ATARI_MCH_TT) |
40 | #define MACH_IS_FALCON ((atari_mch_cookie >> 16) == ATARI_MCH_FALCON) | 40 | #define MACH_IS_FALCON ((atari_mch_cookie >> 16) == ATARI_MCH_FALCON) |
41 | #define MACH_IS_MEDUSA (atari_mch_type == ATARI_MACH_MEDUSA) | 41 | #define MACH_IS_MEDUSA (atari_mch_type == ATARI_MACH_MEDUSA) |
42 | #define MACH_IS_HADES (atari_mch_type == ATARI_MACH_HADES) | ||
43 | #define MACH_IS_AB40 (atari_mch_type == ATARI_MACH_AB40) | 42 | #define MACH_IS_AB40 (atari_mch_type == ATARI_MACH_AB40) |
44 | 43 | ||
45 | /* values for atari_switches */ | 44 | /* values for atari_switches */ |
diff --git a/include/asm-m68k/dma-mapping.h b/include/asm-m68k/dma-mapping.h index 91f7944333d4..26f505488c11 100644 --- a/include/asm-m68k/dma-mapping.h +++ b/include/asm-m68k/dma-mapping.h | |||
@@ -74,6 +74,14 @@ extern void dma_sync_single_for_device(struct device *, dma_addr_t, size_t, | |||
74 | extern void dma_sync_sg_for_device(struct device *, struct scatterlist *, int, | 74 | extern void dma_sync_sg_for_device(struct device *, struct scatterlist *, int, |
75 | enum dma_data_direction); | 75 | enum dma_data_direction); |
76 | 76 | ||
77 | static inline void dma_sync_single_range_for_device(struct device *dev, | ||
78 | dma_addr_t dma_handle, unsigned long offset, size_t size, | ||
79 | enum dma_data_direction direction) | ||
80 | { | ||
81 | /* just sync everything for now */ | ||
82 | dma_sync_single_for_device(dev, dma_handle, offset + size, direction); | ||
83 | } | ||
84 | |||
77 | static inline void dma_sync_single_for_cpu(struct device *dev, dma_addr_t handle, | 85 | static inline void dma_sync_single_for_cpu(struct device *dev, dma_addr_t handle, |
78 | size_t size, enum dma_data_direction dir) | 86 | size_t size, enum dma_data_direction dir) |
79 | { | 87 | { |
@@ -84,6 +92,14 @@ static inline void dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *s | |||
84 | { | 92 | { |
85 | } | 93 | } |
86 | 94 | ||
95 | static inline void dma_sync_single_range_for_cpu(struct device *dev, | ||
96 | dma_addr_t dma_handle, unsigned long offset, size_t size, | ||
97 | enum dma_data_direction direction) | ||
98 | { | ||
99 | /* just sync everything for now */ | ||
100 | dma_sync_single_for_cpu(dev, dma_handle, offset + size, direction); | ||
101 | } | ||
102 | |||
87 | static inline int dma_mapping_error(struct device *dev, dma_addr_t handle) | 103 | static inline int dma_mapping_error(struct device *dev, dma_addr_t handle) |
88 | { | 104 | { |
89 | return 0; | 105 | return 0; |
diff --git a/include/asm-m68k/dma.h b/include/asm-m68k/dma.h index d0c9e61e57b4..4240fbc946f8 100644 --- a/include/asm-m68k/dma.h +++ b/include/asm-m68k/dma.h | |||
@@ -11,10 +11,6 @@ | |||
11 | extern int request_dma(unsigned int dmanr, const char * device_id); /* reserve a DMA channel */ | 11 | extern int request_dma(unsigned int dmanr, const char * device_id); /* reserve a DMA channel */ |
12 | extern void free_dma(unsigned int dmanr); /* release it again */ | 12 | extern void free_dma(unsigned int dmanr); /* release it again */ |
13 | 13 | ||
14 | #ifdef CONFIG_PCI | ||
15 | extern int isa_dma_bridge_buggy; | ||
16 | #else | ||
17 | #define isa_dma_bridge_buggy (0) | 14 | #define isa_dma_bridge_buggy (0) |
18 | #endif | ||
19 | 15 | ||
20 | #endif /* _M68K_DMA_H */ | 16 | #endif /* _M68K_DMA_H */ |
diff --git a/include/asm-m68k/entry.h b/include/asm-m68k/entry.h index f8f6b185d793..5202f5a5b420 100644 --- a/include/asm-m68k/entry.h +++ b/include/asm-m68k/entry.h | |||
@@ -31,7 +31,7 @@ | |||
31 | */ | 31 | */ |
32 | 32 | ||
33 | /* the following macro is used when enabling interrupts */ | 33 | /* the following macro is used when enabling interrupts */ |
34 | #if defined(MACH_ATARI_ONLY) && !defined(CONFIG_HADES) | 34 | #if defined(MACH_ATARI_ONLY) |
35 | /* block out HSYNC on the atari */ | 35 | /* block out HSYNC on the atari */ |
36 | #define ALLOWINT (~0x400) | 36 | #define ALLOWINT (~0x400) |
37 | #define MAX_NOINT_IPL 3 | 37 | #define MAX_NOINT_IPL 3 |
diff --git a/include/asm-m68k/io.h b/include/asm-m68k/io.h index 657187f0c7c2..9e673e3bd434 100644 --- a/include/asm-m68k/io.h +++ b/include/asm-m68k/io.h | |||
@@ -7,15 +7,12 @@ | |||
7 | * - added skeleton for GG-II and Amiga PCMCIA | 7 | * - added skeleton for GG-II and Amiga PCMCIA |
8 | * 2/3/01 RZ: - moved a few more defs into raw_io.h | 8 | * 2/3/01 RZ: - moved a few more defs into raw_io.h |
9 | * | 9 | * |
10 | * inX/outX/readX/writeX should not be used by any driver unless it does | 10 | * inX/outX should not be used by any driver unless it does |
11 | * ISA or PCI access. Other drivers should use function defined in raw_io.h | 11 | * ISA access. Other drivers should use function defined in raw_io.h |
12 | * or define its own macros on top of these. | 12 | * or define its own macros on top of these. |
13 | * | 13 | * |
14 | * inX(),outX() are for PCI and ISA I/O | 14 | * inX(),outX() are for ISA I/O |
15 | * readX(),writeX() are for PCI memory | ||
16 | * isa_readX(),isa_writeX() are for ISA memory | 15 | * isa_readX(),isa_writeX() are for ISA memory |
17 | * | ||
18 | * moved mem{cpy,set}_*io inside CONFIG_PCI | ||
19 | */ | 16 | */ |
20 | 17 | ||
21 | #ifndef _IO_H | 18 | #ifndef _IO_H |
@@ -256,10 +253,7 @@ static inline void isa_delay(void) | |||
256 | (ISA_SEX ? raw_outsl(isa_itl(port), (u32 *)(buf), (nr)) : \ | 253 | (ISA_SEX ? raw_outsl(isa_itl(port), (u32 *)(buf), (nr)) : \ |
257 | raw_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr)<<1)) | 254 | raw_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr)<<1)) |
258 | 255 | ||
259 | #endif /* CONFIG_ISA */ | ||
260 | |||
261 | 256 | ||
262 | #if defined(CONFIG_ISA) && !defined(CONFIG_PCI) | ||
263 | #define inb isa_inb | 257 | #define inb isa_inb |
264 | #define inb_p isa_inb_p | 258 | #define inb_p isa_inb_p |
265 | #define outb isa_outb | 259 | #define outb isa_outb |
@@ -282,55 +276,9 @@ static inline void isa_delay(void) | |||
282 | #define readw isa_readw | 276 | #define readw isa_readw |
283 | #define writeb isa_writeb | 277 | #define writeb isa_writeb |
284 | #define writew isa_writew | 278 | #define writew isa_writew |
285 | #endif /* CONFIG_ISA */ | ||
286 | |||
287 | #if defined(CONFIG_PCI) | ||
288 | |||
289 | #define readl(addr) in_le32(addr) | ||
290 | #define writel(val,addr) out_le32((addr),(val)) | ||
291 | |||
292 | /* those can be defined for both ISA and PCI - it won't work though */ | ||
293 | #define readb(addr) in_8(addr) | ||
294 | #define readw(addr) in_le16(addr) | ||
295 | #define writeb(val,addr) out_8((addr),(val)) | ||
296 | #define writew(val,addr) out_le16((addr),(val)) | ||
297 | 279 | ||
298 | #define readb_relaxed(addr) readb(addr) | 280 | #else /* CONFIG_ISA */ |
299 | #define readw_relaxed(addr) readw(addr) | ||
300 | #define readl_relaxed(addr) readl(addr) | ||
301 | 281 | ||
302 | #ifndef CONFIG_ISA | ||
303 | #define inb(port) in_8(port) | ||
304 | #define outb(val,port) out_8((port),(val)) | ||
305 | #define inw(port) in_le16(port) | ||
306 | #define outw(val,port) out_le16((port),(val)) | ||
307 | #define inl(port) in_le32(port) | ||
308 | #define outl(val,port) out_le32((port),(val)) | ||
309 | |||
310 | #else | ||
311 | /* | ||
312 | * kernel with both ISA and PCI compiled in, those have | ||
313 | * conflicting defs for in/out. Simply consider port < 1024 | ||
314 | * ISA and everything else PCI. read,write not defined | ||
315 | * in this case | ||
316 | */ | ||
317 | #define inb(port) ((port)<1024 ? isa_inb(port) : in_8(port)) | ||
318 | #define inb_p(port) ((port)<1024 ? isa_inb_p(port) : in_8(port)) | ||
319 | #define inw(port) ((port)<1024 ? isa_inw(port) : in_le16(port)) | ||
320 | #define inw_p(port) ((port)<1024 ? isa_inw_p(port) : in_le16(port)) | ||
321 | #define inl(port) ((port)<1024 ? isa_inl(port) : in_le32(port)) | ||
322 | #define inl_p(port) ((port)<1024 ? isa_inl_p(port) : in_le32(port)) | ||
323 | |||
324 | #define outb(val,port) ((port)<1024 ? isa_outb((val),(port)) : out_8((port),(val))) | ||
325 | #define outb_p(val,port) ((port)<1024 ? isa_outb_p((val),(port)) : out_8((port),(val))) | ||
326 | #define outw(val,port) ((port)<1024 ? isa_outw((val),(port)) : out_le16((port),(val))) | ||
327 | #define outw_p(val,port) ((port)<1024 ? isa_outw_p((val),(port)) : out_le16((port),(val))) | ||
328 | #define outl(val,port) ((port)<1024 ? isa_outl((val),(port)) : out_le32((port),(val))) | ||
329 | #define outl_p(val,port) ((port)<1024 ? isa_outl_p((val),(port)) : out_le32((port),(val))) | ||
330 | #endif | ||
331 | #endif /* CONFIG_PCI */ | ||
332 | |||
333 | #if !defined(CONFIG_ISA) && !defined(CONFIG_PCI) | ||
334 | /* | 282 | /* |
335 | * We need to define dummy functions for GENERIC_IOMAP support. | 283 | * We need to define dummy functions for GENERIC_IOMAP support. |
336 | */ | 284 | */ |
@@ -357,11 +305,11 @@ static inline void isa_delay(void) | |||
357 | #define writeb(val,addr) out_8((addr),(val)) | 305 | #define writeb(val,addr) out_8((addr),(val)) |
358 | #define readw(addr) in_le16(addr) | 306 | #define readw(addr) in_le16(addr) |
359 | #define writew(val,addr) out_le16((addr),(val)) | 307 | #define writew(val,addr) out_le16((addr),(val)) |
360 | #endif | 308 | |
361 | #if !defined(CONFIG_PCI) | 309 | #endif /* CONFIG_ISA */ |
310 | |||
362 | #define readl(addr) in_le32(addr) | 311 | #define readl(addr) in_le32(addr) |
363 | #define writel(val,addr) out_le32((addr),(val)) | 312 | #define writel(val,addr) out_le32((addr),(val)) |
364 | #endif | ||
365 | 313 | ||
366 | #define mmiowb() | 314 | #define mmiowb() |
367 | 315 | ||
diff --git a/include/asm-m68k/pci.h b/include/asm-m68k/pci.h index 678cb0b52314..4ad0aea48ab4 100644 --- a/include/asm-m68k/pci.h +++ b/include/asm-m68k/pci.h | |||
@@ -1,52 +1,7 @@ | |||
1 | #ifndef _ASM_M68K_PCI_H | 1 | #ifndef _ASM_M68K_PCI_H |
2 | #define _ASM_M68K_PCI_H | 2 | #define _ASM_M68K_PCI_H |
3 | 3 | ||
4 | /* | 4 | #include <asm-generic/pci-dma-compat.h> |
5 | * asm-m68k/pci_m68k.h - m68k specific PCI declarations. | ||
6 | * | ||
7 | * Written by Wout Klaren. | ||
8 | */ | ||
9 | |||
10 | #include <asm/scatterlist.h> | ||
11 | |||
12 | struct pci_ops; | ||
13 | |||
14 | /* | ||
15 | * Structure with hardware dependent information and functions of the | ||
16 | * PCI bus. | ||
17 | */ | ||
18 | |||
19 | struct pci_bus_info | ||
20 | { | ||
21 | /* | ||
22 | * Resources of the PCI bus. | ||
23 | */ | ||
24 | |||
25 | struct resource mem_space; | ||
26 | struct resource io_space; | ||
27 | |||
28 | /* | ||
29 | * System dependent functions. | ||
30 | */ | ||
31 | |||
32 | struct pci_ops *m68k_pci_ops; | ||
33 | |||
34 | void (*fixup)(int pci_modify); | ||
35 | void (*conf_device)(struct pci_dev *dev); | ||
36 | }; | ||
37 | |||
38 | #define pcibios_assign_all_busses() 0 | ||
39 | #define pcibios_scan_all_fns(a, b) 0 | ||
40 | |||
41 | static inline void pcibios_set_master(struct pci_dev *dev) | ||
42 | { | ||
43 | /* No special bus mastering setup handling */ | ||
44 | } | ||
45 | |||
46 | static inline void pcibios_penalize_isa_irq(int irq, int active) | ||
47 | { | ||
48 | /* We don't do dynamic PCI IRQ allocation */ | ||
49 | } | ||
50 | 5 | ||
51 | /* The PCI address space does equal the physical memory | 6 | /* The PCI address space does equal the physical memory |
52 | * address space. The networking and block device layers use | 7 | * address space. The networking and block device layers use |
diff --git a/include/asm-m68k/virtconvert.h b/include/asm-m68k/virtconvert.h index dea32fbc7e51..22ab05c9c52b 100644 --- a/include/asm-m68k/virtconvert.h +++ b/include/asm-m68k/virtconvert.h | |||
@@ -40,15 +40,9 @@ static inline void *phys_to_virt(unsigned long address) | |||
40 | 40 | ||
41 | /* | 41 | /* |
42 | * IO bus memory addresses are 1:1 with the physical address, | 42 | * IO bus memory addresses are 1:1 with the physical address, |
43 | * except on the PCI bus of the Hades. | ||
44 | */ | 43 | */ |
45 | #ifdef CONFIG_HADES | ||
46 | #define virt_to_bus(a) (virt_to_phys(a) + (MACH_IS_HADES ? 0x80000000 : 0)) | ||
47 | #define bus_to_virt(a) (phys_to_virt((a) - (MACH_IS_HADES ? 0x80000000 : 0))) | ||
48 | #else | ||
49 | #define virt_to_bus virt_to_phys | 44 | #define virt_to_bus virt_to_phys |
50 | #define bus_to_virt phys_to_virt | 45 | #define bus_to_virt phys_to_virt |
51 | #endif | ||
52 | 46 | ||
53 | #endif | 47 | #endif |
54 | #endif | 48 | #endif |
diff --git a/include/linux/console_struct.h b/include/linux/console_struct.h index b03f80a078be..d71f7c0f931b 100644 --- a/include/linux/console_struct.h +++ b/include/linux/console_struct.h | |||
@@ -53,7 +53,6 @@ struct vc_data { | |||
53 | unsigned short vc_hi_font_mask; /* [#] Attribute set for upper 256 chars of font or 0 if not supported */ | 53 | unsigned short vc_hi_font_mask; /* [#] Attribute set for upper 256 chars of font or 0 if not supported */ |
54 | struct console_font vc_font; /* Current VC font set */ | 54 | struct console_font vc_font; /* Current VC font set */ |
55 | unsigned short vc_video_erase_char; /* Background erase character */ | 55 | unsigned short vc_video_erase_char; /* Background erase character */ |
56 | unsigned short vc_scrl_erase_char; /* Erase character for scroll */ | ||
57 | /* VT terminal data */ | 56 | /* VT terminal data */ |
58 | unsigned int vc_state; /* Escape sequence parser state */ | 57 | unsigned int vc_state; /* Escape sequence parser state */ |
59 | unsigned int vc_npar,vc_par[NPAR]; /* Parameters of current escape sequence */ | 58 | unsigned int vc_npar,vc_par[NPAR]; /* Parameters of current escape sequence */ |
diff --git a/include/linux/fs.h b/include/linux/fs.h index 44e3cb2f1966..a6a625be13fc 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h | |||
@@ -947,6 +947,14 @@ struct lock_manager_operations { | |||
947 | int (*fl_change)(struct file_lock **, int); | 947 | int (*fl_change)(struct file_lock **, int); |
948 | }; | 948 | }; |
949 | 949 | ||
950 | struct lock_manager { | ||
951 | struct list_head list; | ||
952 | }; | ||
953 | |||
954 | void locks_start_grace(struct lock_manager *); | ||
955 | void locks_end_grace(struct lock_manager *); | ||
956 | int locks_in_grace(void); | ||
957 | |||
950 | /* that will die - we need it for nfs_lock_info */ | 958 | /* that will die - we need it for nfs_lock_info */ |
951 | #include <linux/nfs_fs_i.h> | 959 | #include <linux/nfs_fs_i.h> |
952 | 960 | ||
@@ -988,6 +996,13 @@ struct file_lock { | |||
988 | 996 | ||
989 | #include <linux/fcntl.h> | 997 | #include <linux/fcntl.h> |
990 | 998 | ||
999 | extern void send_sigio(struct fown_struct *fown, int fd, int band); | ||
1000 | |||
1001 | /* fs/sync.c */ | ||
1002 | extern int do_sync_mapping_range(struct address_space *mapping, loff_t offset, | ||
1003 | loff_t endbyte, unsigned int flags); | ||
1004 | |||
1005 | #ifdef CONFIG_FILE_LOCKING | ||
991 | extern int fcntl_getlk(struct file *, struct flock __user *); | 1006 | extern int fcntl_getlk(struct file *, struct flock __user *); |
992 | extern int fcntl_setlk(unsigned int, struct file *, unsigned int, | 1007 | extern int fcntl_setlk(unsigned int, struct file *, unsigned int, |
993 | struct flock __user *); | 1008 | struct flock __user *); |
@@ -998,14 +1013,9 @@ extern int fcntl_setlk64(unsigned int, struct file *, unsigned int, | |||
998 | struct flock64 __user *); | 1013 | struct flock64 __user *); |
999 | #endif | 1014 | #endif |
1000 | 1015 | ||
1001 | extern void send_sigio(struct fown_struct *fown, int fd, int band); | ||
1002 | extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg); | 1016 | extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg); |
1003 | extern int fcntl_getlease(struct file *filp); | 1017 | extern int fcntl_getlease(struct file *filp); |
1004 | 1018 | ||
1005 | /* fs/sync.c */ | ||
1006 | extern int do_sync_mapping_range(struct address_space *mapping, loff_t offset, | ||
1007 | loff_t endbyte, unsigned int flags); | ||
1008 | |||
1009 | /* fs/locks.c */ | 1019 | /* fs/locks.c */ |
1010 | extern void locks_init_lock(struct file_lock *); | 1020 | extern void locks_init_lock(struct file_lock *); |
1011 | extern void locks_copy_lock(struct file_lock *, struct file_lock *); | 1021 | extern void locks_copy_lock(struct file_lock *, struct file_lock *); |
@@ -1028,6 +1038,37 @@ extern int lease_modify(struct file_lock **, int); | |||
1028 | extern int lock_may_read(struct inode *, loff_t start, unsigned long count); | 1038 | extern int lock_may_read(struct inode *, loff_t start, unsigned long count); |
1029 | extern int lock_may_write(struct inode *, loff_t start, unsigned long count); | 1039 | extern int lock_may_write(struct inode *, loff_t start, unsigned long count); |
1030 | extern struct seq_operations locks_seq_operations; | 1040 | extern struct seq_operations locks_seq_operations; |
1041 | #else /* !CONFIG_FILE_LOCKING */ | ||
1042 | #define fcntl_getlk(a, b) ({ -EINVAL; }) | ||
1043 | #define fcntl_setlk(a, b, c, d) ({ -EACCES; }) | ||
1044 | #if BITS_PER_LONG == 32 | ||
1045 | #define fcntl_getlk64(a, b) ({ -EINVAL; }) | ||
1046 | #define fcntl_setlk64(a, b, c, d) ({ -EACCES; }) | ||
1047 | #endif | ||
1048 | #define fcntl_setlease(a, b, c) ({ 0; }) | ||
1049 | #define fcntl_getlease(a) ({ 0; }) | ||
1050 | #define locks_init_lock(a) ({ }) | ||
1051 | #define __locks_copy_lock(a, b) ({ }) | ||
1052 | #define locks_copy_lock(a, b) ({ }) | ||
1053 | #define locks_remove_posix(a, b) ({ }) | ||
1054 | #define locks_remove_flock(a) ({ }) | ||
1055 | #define posix_test_lock(a, b) ({ 0; }) | ||
1056 | #define posix_lock_file(a, b, c) ({ -ENOLCK; }) | ||
1057 | #define posix_lock_file_wait(a, b) ({ -ENOLCK; }) | ||
1058 | #define posix_unblock_lock(a, b) (-ENOENT) | ||
1059 | #define vfs_test_lock(a, b) ({ 0; }) | ||
1060 | #define vfs_lock_file(a, b, c, d) (-ENOLCK) | ||
1061 | #define vfs_cancel_lock(a, b) ({ 0; }) | ||
1062 | #define flock_lock_file_wait(a, b) ({ -ENOLCK; }) | ||
1063 | #define __break_lease(a, b) ({ 0; }) | ||
1064 | #define lease_get_mtime(a, b) ({ }) | ||
1065 | #define generic_setlease(a, b, c) ({ -EINVAL; }) | ||
1066 | #define vfs_setlease(a, b, c) ({ -EINVAL; }) | ||
1067 | #define lease_modify(a, b) ({ -EINVAL; }) | ||
1068 | #define lock_may_read(a, b, c) ({ 1; }) | ||
1069 | #define lock_may_write(a, b, c) ({ 1; }) | ||
1070 | #endif /* !CONFIG_FILE_LOCKING */ | ||
1071 | |||
1031 | 1072 | ||
1032 | struct fasync_struct { | 1073 | struct fasync_struct { |
1033 | int magic; | 1074 | int magic; |
@@ -1575,9 +1616,12 @@ extern int vfs_statfs(struct dentry *, struct kstatfs *); | |||
1575 | /* /sys/fs */ | 1616 | /* /sys/fs */ |
1576 | extern struct kobject *fs_kobj; | 1617 | extern struct kobject *fs_kobj; |
1577 | 1618 | ||
1619 | extern int rw_verify_area(int, struct file *, loff_t *, size_t); | ||
1620 | |||
1578 | #define FLOCK_VERIFY_READ 1 | 1621 | #define FLOCK_VERIFY_READ 1 |
1579 | #define FLOCK_VERIFY_WRITE 2 | 1622 | #define FLOCK_VERIFY_WRITE 2 |
1580 | 1623 | ||
1624 | #ifdef CONFIG_FILE_LOCKING | ||
1581 | extern int locks_mandatory_locked(struct inode *); | 1625 | extern int locks_mandatory_locked(struct inode *); |
1582 | extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t); | 1626 | extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t); |
1583 | 1627 | ||
@@ -1608,8 +1652,6 @@ static inline int locks_verify_locked(struct inode *inode) | |||
1608 | return 0; | 1652 | return 0; |
1609 | } | 1653 | } |
1610 | 1654 | ||
1611 | extern int rw_verify_area(int, struct file *, loff_t *, size_t); | ||
1612 | |||
1613 | static inline int locks_verify_truncate(struct inode *inode, | 1655 | static inline int locks_verify_truncate(struct inode *inode, |
1614 | struct file *filp, | 1656 | struct file *filp, |
1615 | loff_t size) | 1657 | loff_t size) |
@@ -1630,6 +1672,15 @@ static inline int break_lease(struct inode *inode, unsigned int mode) | |||
1630 | return __break_lease(inode, mode); | 1672 | return __break_lease(inode, mode); |
1631 | return 0; | 1673 | return 0; |
1632 | } | 1674 | } |
1675 | #else /* !CONFIG_FILE_LOCKING */ | ||
1676 | #define locks_mandatory_locked(a) ({ 0; }) | ||
1677 | #define locks_mandatory_area(a, b, c, d, e) ({ 0; }) | ||
1678 | #define __mandatory_lock(a) ({ 0; }) | ||
1679 | #define mandatory_lock(a) ({ 0; }) | ||
1680 | #define locks_verify_locked(a) ({ 0; }) | ||
1681 | #define locks_verify_truncate(a, b, c) ({ 0; }) | ||
1682 | #define break_lease(a, b) ({ 0; }) | ||
1683 | #endif /* CONFIG_FILE_LOCKING */ | ||
1633 | 1684 | ||
1634 | /* fs/open.c */ | 1685 | /* fs/open.c */ |
1635 | 1686 | ||
diff --git a/include/linux/hid.h b/include/linux/hid.h index ac4e678a04ed..f13bca2dd53b 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h | |||
@@ -67,6 +67,7 @@ | |||
67 | #include <linux/types.h> | 67 | #include <linux/types.h> |
68 | #include <linux/slab.h> | 68 | #include <linux/slab.h> |
69 | #include <linux/list.h> | 69 | #include <linux/list.h> |
70 | #include <linux/mod_devicetable.h> /* hid_device_id */ | ||
70 | #include <linux/timer.h> | 71 | #include <linux/timer.h> |
71 | #include <linux/workqueue.h> | 72 | #include <linux/workqueue.h> |
72 | #include <linux/input.h> | 73 | #include <linux/input.h> |
@@ -246,6 +247,19 @@ struct hid_item { | |||
246 | #define HID_FEATURE_REPORT 2 | 247 | #define HID_FEATURE_REPORT 2 |
247 | 248 | ||
248 | /* | 249 | /* |
250 | * HID connect requests | ||
251 | */ | ||
252 | |||
253 | #define HID_CONNECT_HIDINPUT 0x01 | ||
254 | #define HID_CONNECT_HIDINPUT_FORCE 0x02 | ||
255 | #define HID_CONNECT_HIDRAW 0x04 | ||
256 | #define HID_CONNECT_HIDDEV 0x08 | ||
257 | #define HID_CONNECT_HIDDEV_FORCE 0x10 | ||
258 | #define HID_CONNECT_FF 0x20 | ||
259 | #define HID_CONNECT_DEFAULT (HID_CONNECT_HIDINPUT|HID_CONNECT_HIDRAW| \ | ||
260 | HID_CONNECT_HIDDEV|HID_CONNECT_FF) | ||
261 | |||
262 | /* | ||
249 | * HID device quirks. | 263 | * HID device quirks. |
250 | */ | 264 | */ |
251 | 265 | ||
@@ -256,48 +270,11 @@ struct hid_item { | |||
256 | 270 | ||
257 | #define HID_QUIRK_INVERT 0x00000001 | 271 | #define HID_QUIRK_INVERT 0x00000001 |
258 | #define HID_QUIRK_NOTOUCH 0x00000002 | 272 | #define HID_QUIRK_NOTOUCH 0x00000002 |
259 | #define HID_QUIRK_IGNORE 0x00000004 | ||
260 | #define HID_QUIRK_NOGET 0x00000008 | 273 | #define HID_QUIRK_NOGET 0x00000008 |
261 | #define HID_QUIRK_HIDDEV 0x00000010 | ||
262 | #define HID_QUIRK_BADPAD 0x00000020 | 274 | #define HID_QUIRK_BADPAD 0x00000020 |
263 | #define HID_QUIRK_MULTI_INPUT 0x00000040 | 275 | #define HID_QUIRK_MULTI_INPUT 0x00000040 |
264 | #define HID_QUIRK_2WHEEL_MOUSE_HACK_7 0x00000080 | ||
265 | #define HID_QUIRK_2WHEEL_MOUSE_HACK_5 0x00000100 | ||
266 | #define HID_QUIRK_2WHEEL_MOUSE_HACK_ON 0x00000200 | ||
267 | #define HID_QUIRK_MIGHTYMOUSE 0x00000400 | ||
268 | #define HID_QUIRK_APPLE_HAS_FN 0x00000800 | ||
269 | #define HID_QUIRK_APPLE_FN_ON 0x00001000 | ||
270 | #define HID_QUIRK_INVERT_HWHEEL 0x00002000 | ||
271 | #define HID_QUIRK_APPLE_ISO_KEYBOARD 0x00004000 | ||
272 | #define HID_QUIRK_BAD_RELATIVE_KEYS 0x00008000 | ||
273 | #define HID_QUIRK_SKIP_OUTPUT_REPORTS 0x00010000 | 276 | #define HID_QUIRK_SKIP_OUTPUT_REPORTS 0x00010000 |
274 | #define HID_QUIRK_IGNORE_MOUSE 0x00020000 | ||
275 | #define HID_QUIRK_SONY_PS3_CONTROLLER 0x00040000 | ||
276 | #define HID_QUIRK_DUPLICATE_USAGES 0x00080000 | ||
277 | #define HID_QUIRK_RESET_LEDS 0x00100000 | ||
278 | #define HID_QUIRK_HIDINPUT 0x00200000 | ||
279 | #define HID_QUIRK_LOGITECH_IGNORE_DOUBLED_WHEEL 0x00400000 | ||
280 | #define HID_QUIRK_LOGITECH_EXPANDED_KEYMAP 0x00800000 | ||
281 | #define HID_QUIRK_IGNORE_HIDINPUT 0x01000000 | ||
282 | #define HID_QUIRK_2WHEEL_MOUSE_HACK_B8 0x02000000 | ||
283 | #define HID_QUIRK_HWHEEL_WHEEL_INVERT 0x04000000 | ||
284 | #define HID_QUIRK_MICROSOFT_KEYS 0x08000000 | ||
285 | #define HID_QUIRK_FULLSPEED_INTERVAL 0x10000000 | 277 | #define HID_QUIRK_FULLSPEED_INTERVAL 0x10000000 |
286 | #define HID_QUIRK_APPLE_NUMLOCK_EMULATION 0x20000000 | ||
287 | |||
288 | /* | ||
289 | * Separate quirks for runtime report descriptor fixup | ||
290 | */ | ||
291 | |||
292 | #define HID_QUIRK_RDESC_CYMOTION 0x00000001 | ||
293 | #define HID_QUIRK_RDESC_LOGITECH 0x00000002 | ||
294 | #define HID_QUIRK_RDESC_SWAPPED_MIN_MAX 0x00000004 | ||
295 | #define HID_QUIRK_RDESC_PETALYNX 0x00000008 | ||
296 | #define HID_QUIRK_RDESC_MACBOOK_JIS 0x00000010 | ||
297 | #define HID_QUIRK_RDESC_BUTTON_CONSUMER 0x00000020 | ||
298 | #define HID_QUIRK_RDESC_SAMSUNG_REMOTE 0x00000040 | ||
299 | #define HID_QUIRK_RDESC_MICROSOFT_RECV_1028 0x00000080 | ||
300 | #define HID_QUIRK_RDESC_SUNPLUS_WDESKTOP 0x00000100 | ||
301 | 278 | ||
302 | /* | 279 | /* |
303 | * This is the global environment of the parser. This information is | 280 | * This is the global environment of the parser. This information is |
@@ -411,12 +388,21 @@ struct hid_report_enum { | |||
411 | struct hid_control_fifo { | 388 | struct hid_control_fifo { |
412 | unsigned char dir; | 389 | unsigned char dir; |
413 | struct hid_report *report; | 390 | struct hid_report *report; |
391 | char *raw_report; | ||
392 | }; | ||
393 | |||
394 | struct hid_output_fifo { | ||
395 | struct hid_report *report; | ||
396 | char *raw_report; | ||
414 | }; | 397 | }; |
415 | 398 | ||
416 | #define HID_CLAIMED_INPUT 1 | 399 | #define HID_CLAIMED_INPUT 1 |
417 | #define HID_CLAIMED_HIDDEV 2 | 400 | #define HID_CLAIMED_HIDDEV 2 |
418 | #define HID_CLAIMED_HIDRAW 4 | 401 | #define HID_CLAIMED_HIDRAW 4 |
419 | 402 | ||
403 | #define HID_STAT_ADDED 1 | ||
404 | #define HID_STAT_PARSED 2 | ||
405 | |||
420 | #define HID_CTRL_RUNNING 1 | 406 | #define HID_CTRL_RUNNING 1 |
421 | #define HID_OUT_RUNNING 2 | 407 | #define HID_OUT_RUNNING 2 |
422 | #define HID_IN_RUNNING 3 | 408 | #define HID_IN_RUNNING 3 |
@@ -431,22 +417,28 @@ struct hid_input { | |||
431 | struct input_dev *input; | 417 | struct input_dev *input; |
432 | }; | 418 | }; |
433 | 419 | ||
420 | struct hid_driver; | ||
421 | struct hid_ll_driver; | ||
422 | |||
434 | struct hid_device { /* device report descriptor */ | 423 | struct hid_device { /* device report descriptor */ |
435 | __u8 *rdesc; | 424 | __u8 *rdesc; |
436 | unsigned rsize; | 425 | unsigned rsize; |
437 | struct hid_collection *collection; /* List of HID collections */ | 426 | struct hid_collection *collection; /* List of HID collections */ |
438 | unsigned collection_size; /* Number of allocated hid_collections */ | 427 | unsigned collection_size; /* Number of allocated hid_collections */ |
439 | unsigned maxcollection; /* Number of parsed collections */ | 428 | unsigned maxcollection; /* Number of parsed collections */ |
440 | unsigned maxapplication; /* Number of applications */ | 429 | unsigned maxapplication; /* Number of applications */ |
441 | unsigned short bus; /* BUS ID */ | 430 | __u16 bus; /* BUS ID */ |
442 | unsigned short vendor; /* Vendor ID */ | 431 | __u32 vendor; /* Vendor ID */ |
443 | unsigned short product; /* Product ID */ | 432 | __u32 product; /* Product ID */ |
444 | unsigned version; /* HID version */ | 433 | __u32 version; /* HID version */ |
445 | unsigned country; /* HID country */ | 434 | unsigned country; /* HID country */ |
446 | struct hid_report_enum report_enum[HID_REPORT_TYPES]; | 435 | struct hid_report_enum report_enum[HID_REPORT_TYPES]; |
447 | 436 | ||
448 | struct device *dev; /* device */ | 437 | struct device dev; /* device */ |
438 | struct hid_driver *driver; | ||
439 | struct hid_ll_driver *ll_driver; | ||
449 | 440 | ||
441 | unsigned int status; /* see STAT flags above */ | ||
450 | unsigned claimed; /* Claimed by hidinput, hiddev? */ | 442 | unsigned claimed; /* Claimed by hidinput, hiddev? */ |
451 | unsigned quirks; /* Various quirks the device can pull on us */ | 443 | unsigned quirks; /* Various quirks the device can pull on us */ |
452 | 444 | ||
@@ -462,26 +454,29 @@ struct hid_device { /* device report descriptor */ | |||
462 | 454 | ||
463 | void *driver_data; | 455 | void *driver_data; |
464 | 456 | ||
465 | __s32 delayed_value; /* For A4 Tech mice hwheel quirk */ | 457 | /* temporary hid_ff handling (until moved to the drivers) */ |
466 | 458 | int (*ff_init)(struct hid_device *); | |
467 | /* device-specific function pointers */ | ||
468 | int (*hidinput_input_event) (struct input_dev *, unsigned int, unsigned int, int); | ||
469 | int (*hid_open) (struct hid_device *); | ||
470 | void (*hid_close) (struct hid_device *); | ||
471 | 459 | ||
472 | /* hiddev event handler */ | 460 | /* hiddev event handler */ |
461 | int (*hiddev_connect)(struct hid_device *, unsigned int); | ||
473 | void (*hiddev_hid_event) (struct hid_device *, struct hid_field *field, | 462 | void (*hiddev_hid_event) (struct hid_device *, struct hid_field *field, |
474 | struct hid_usage *, __s32); | 463 | struct hid_usage *, __s32); |
475 | void (*hiddev_report_event) (struct hid_device *, struct hid_report *); | 464 | void (*hiddev_report_event) (struct hid_device *, struct hid_report *); |
476 | 465 | ||
477 | /* handler for raw output data, used by hidraw */ | 466 | /* handler for raw output data, used by hidraw */ |
478 | int (*hid_output_raw_report) (struct hid_device *, __u8 *, size_t); | 467 | int (*hid_output_raw_report) (struct hid_device *, __u8 *, size_t); |
479 | #ifdef CONFIG_USB_HIDINPUT_POWERBOOK | ||
480 | unsigned long apple_pressed_fn[BITS_TO_LONGS(KEY_CNT)]; | ||
481 | unsigned long pb_pressed_numlock[BITS_TO_LONGS(KEY_CNT)]; | ||
482 | #endif | ||
483 | }; | 468 | }; |
484 | 469 | ||
470 | static inline void *hid_get_drvdata(struct hid_device *hdev) | ||
471 | { | ||
472 | return dev_get_drvdata(&hdev->dev); | ||
473 | } | ||
474 | |||
475 | static inline void hid_set_drvdata(struct hid_device *hdev, void *data) | ||
476 | { | ||
477 | dev_set_drvdata(&hdev->dev, data); | ||
478 | } | ||
479 | |||
485 | #define HID_GLOBAL_STACK_SIZE 4 | 480 | #define HID_GLOBAL_STACK_SIZE 4 |
486 | #define HID_COLLECTION_STACK_SIZE 4 | 481 | #define HID_COLLECTION_STACK_SIZE 4 |
487 | 482 | ||
@@ -510,6 +505,107 @@ struct hid_descriptor { | |||
510 | struct hid_class_descriptor desc[1]; | 505 | struct hid_class_descriptor desc[1]; |
511 | } __attribute__ ((packed)); | 506 | } __attribute__ ((packed)); |
512 | 507 | ||
508 | #define HID_DEVICE(b, ven, prod) \ | ||
509 | .bus = (b), \ | ||
510 | .vendor = (ven), .product = (prod) | ||
511 | |||
512 | #define HID_USB_DEVICE(ven, prod) HID_DEVICE(BUS_USB, ven, prod) | ||
513 | #define HID_BLUETOOTH_DEVICE(ven, prod) HID_DEVICE(BUS_BLUETOOTH, ven, prod) | ||
514 | |||
515 | #define HID_REPORT_ID(rep) \ | ||
516 | .report_type = (rep) | ||
517 | #define HID_USAGE_ID(uhid, utype, ucode) \ | ||
518 | .usage_hid = (uhid), .usage_type = (utype), .usage_code = (ucode) | ||
519 | /* we don't want to catch types and codes equal to 0 */ | ||
520 | #define HID_TERMINATOR (HID_ANY_ID - 1) | ||
521 | |||
522 | struct hid_report_id { | ||
523 | __u32 report_type; | ||
524 | }; | ||
525 | struct hid_usage_id { | ||
526 | __u32 usage_hid; | ||
527 | __u32 usage_type; | ||
528 | __u32 usage_code; | ||
529 | }; | ||
530 | |||
531 | /** | ||
532 | * struct hid_driver | ||
533 | * @name: driver name (e.g. "Footech_bar-wheel") | ||
534 | * @id_table: which devices is this driver for (must be non-NULL for probe | ||
535 | * to be called) | ||
536 | * @probe: new device inserted | ||
537 | * @remove: device removed (NULL if not a hot-plug capable driver) | ||
538 | * @report_table: on which reports to call raw_event (NULL means all) | ||
539 | * @raw_event: if report in report_table, this hook is called (NULL means nop) | ||
540 | * @usage_table: on which events to call event (NULL means all) | ||
541 | * @event: if usage in usage_table, this hook is called (NULL means nop) | ||
542 | * @report_fixup: called before report descriptor parsing (NULL means nop) | ||
543 | * @input_mapping: invoked on input registering before mapping an usage | ||
544 | * @input_mapped: invoked on input registering after mapping an usage | ||
545 | * | ||
546 | * raw_event and event should return 0 on no action performed, 1 when no | ||
547 | * further processing should be done and negative on error | ||
548 | * | ||
549 | * input_mapping shall return a negative value to completely ignore this usage | ||
550 | * (e.g. doubled or invalid usage), zero to continue with parsing of this | ||
551 | * usage by generic code (no special handling needed) or positive to skip | ||
552 | * generic parsing (needed special handling which was done in the hook already) | ||
553 | * input_mapped shall return negative to inform the layer that this usage | ||
554 | * should not be considered for further processing or zero to notify that | ||
555 | * no processing was performed and should be done in a generic manner | ||
556 | * Both these functions may be NULL which means the same behavior as returning | ||
557 | * zero from them. | ||
558 | */ | ||
559 | struct hid_driver { | ||
560 | char *name; | ||
561 | const struct hid_device_id *id_table; | ||
562 | |||
563 | int (*probe)(struct hid_device *dev, const struct hid_device_id *id); | ||
564 | void (*remove)(struct hid_device *dev); | ||
565 | |||
566 | const struct hid_report_id *report_table; | ||
567 | int (*raw_event)(struct hid_device *hdev, struct hid_report *report, | ||
568 | u8 *data, int size); | ||
569 | const struct hid_usage_id *usage_table; | ||
570 | int (*event)(struct hid_device *hdev, struct hid_field *field, | ||
571 | struct hid_usage *usage, __s32 value); | ||
572 | |||
573 | void (*report_fixup)(struct hid_device *hdev, __u8 *buf, | ||
574 | unsigned int size); | ||
575 | |||
576 | int (*input_mapping)(struct hid_device *hdev, | ||
577 | struct hid_input *hidinput, struct hid_field *field, | ||
578 | struct hid_usage *usage, unsigned long **bit, int *max); | ||
579 | int (*input_mapped)(struct hid_device *hdev, | ||
580 | struct hid_input *hidinput, struct hid_field *field, | ||
581 | struct hid_usage *usage, unsigned long **bit, int *max); | ||
582 | /* private: */ | ||
583 | struct device_driver driver; | ||
584 | }; | ||
585 | |||
586 | /** | ||
587 | * hid_ll_driver - low level driver callbacks | ||
588 | * @start: called on probe to start the device | ||
589 | * @stop: called on remove | ||
590 | * @open: called by input layer on open | ||
591 | * @close: called by input layer on close | ||
592 | * @hidinput_input_event: event input event (e.g. ff or leds) | ||
593 | * @parse: this method is called only once to parse the device data, | ||
594 | * shouldn't allocate anything to not leak memory | ||
595 | */ | ||
596 | struct hid_ll_driver { | ||
597 | int (*start)(struct hid_device *hdev); | ||
598 | void (*stop)(struct hid_device *hdev); | ||
599 | |||
600 | int (*open)(struct hid_device *hdev); | ||
601 | void (*close)(struct hid_device *hdev); | ||
602 | |||
603 | int (*hidinput_input_event) (struct input_dev *idev, unsigned int type, | ||
604 | unsigned int code, int value); | ||
605 | |||
606 | int (*parse)(struct hid_device *hdev); | ||
607 | }; | ||
608 | |||
513 | /* Applications from HID Usage Tables 4/8/99 Version 1.1 */ | 609 | /* Applications from HID Usage Tables 4/8/99 Version 1.1 */ |
514 | /* We ignore a few input applications that are not widely used */ | 610 | /* We ignore a few input applications that are not widely used */ |
515 | #define IS_INPUT_APPLICATION(a) (((a >= 0x00010000) && (a <= 0x00010008)) || (a == 0x00010080) || (a == 0x000c0001) || (a == 0x000d0002)) | 611 | #define IS_INPUT_APPLICATION(a) (((a >= 0x00010000) && (a <= 0x00010008)) || (a == 0x00010080) || (a == 0x000c0001) || (a == 0x000d0002)) |
@@ -520,43 +616,157 @@ struct hid_descriptor { | |||
520 | extern int hid_debug; | 616 | extern int hid_debug; |
521 | #endif | 617 | #endif |
522 | 618 | ||
619 | extern int hid_add_device(struct hid_device *); | ||
620 | extern void hid_destroy_device(struct hid_device *); | ||
621 | |||
622 | extern int __must_check __hid_register_driver(struct hid_driver *, | ||
623 | struct module *, const char *mod_name); | ||
624 | static inline int __must_check hid_register_driver(struct hid_driver *driver) | ||
625 | { | ||
626 | return __hid_register_driver(driver, THIS_MODULE, KBUILD_MODNAME); | ||
627 | } | ||
628 | extern void hid_unregister_driver(struct hid_driver *); | ||
629 | |||
523 | extern void hidinput_hid_event(struct hid_device *, struct hid_field *, struct hid_usage *, __s32); | 630 | extern void hidinput_hid_event(struct hid_device *, struct hid_field *, struct hid_usage *, __s32); |
524 | extern void hidinput_report_event(struct hid_device *hid, struct hid_report *report); | 631 | extern void hidinput_report_event(struct hid_device *hid, struct hid_report *report); |
525 | extern int hidinput_connect(struct hid_device *); | 632 | extern int hidinput_connect(struct hid_device *hid, unsigned int force); |
526 | extern void hidinput_disconnect(struct hid_device *); | 633 | extern void hidinput_disconnect(struct hid_device *); |
527 | 634 | ||
528 | int hid_set_field(struct hid_field *, unsigned, __s32); | 635 | int hid_set_field(struct hid_field *, unsigned, __s32); |
529 | int hid_input_report(struct hid_device *, int type, u8 *, int, int); | 636 | int hid_input_report(struct hid_device *, int type, u8 *, int, int); |
530 | int hidinput_find_field(struct hid_device *hid, unsigned int type, unsigned int code, struct hid_field **field); | 637 | int hidinput_find_field(struct hid_device *hid, unsigned int type, unsigned int code, struct hid_field **field); |
531 | int hidinput_mapping_quirks(struct hid_usage *, struct input_dev *, unsigned long **, int *); | ||
532 | int hidinput_event_quirks(struct hid_device *, struct hid_field *, struct hid_usage *, __s32); | ||
533 | int hidinput_apple_event(struct hid_device *, struct input_dev *, struct hid_usage *, __s32); | ||
534 | void hid_output_report(struct hid_report *report, __u8 *data); | 638 | void hid_output_report(struct hid_report *report, __u8 *data); |
535 | void hid_free_device(struct hid_device *device); | 639 | struct hid_device *hid_allocate_device(void); |
536 | struct hid_device *hid_parse_report(__u8 *start, unsigned size); | 640 | int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size); |
641 | int hid_connect(struct hid_device *hid, unsigned int connect_mask); | ||
642 | |||
643 | /** | ||
644 | * hid_map_usage - map usage input bits | ||
645 | * | ||
646 | * @hidinput: hidinput which we are interested in | ||
647 | * @usage: usage to fill in | ||
648 | * @bit: pointer to input->{}bit (out parameter) | ||
649 | * @max: maximal valid usage->code to consider later (out parameter) | ||
650 | * @type: input event type (EV_KEY, EV_REL, ...) | ||
651 | * @c: code which corresponds to this usage and type | ||
652 | */ | ||
653 | static inline void hid_map_usage(struct hid_input *hidinput, | ||
654 | struct hid_usage *usage, unsigned long **bit, int *max, | ||
655 | __u8 type, __u16 c) | ||
656 | { | ||
657 | struct input_dev *input = hidinput->input; | ||
658 | |||
659 | usage->type = type; | ||
660 | usage->code = c; | ||
661 | |||
662 | switch (type) { | ||
663 | case EV_ABS: | ||
664 | *bit = input->absbit; | ||
665 | *max = ABS_MAX; | ||
666 | break; | ||
667 | case EV_REL: | ||
668 | *bit = input->relbit; | ||
669 | *max = REL_MAX; | ||
670 | break; | ||
671 | case EV_KEY: | ||
672 | *bit = input->keybit; | ||
673 | *max = KEY_MAX; | ||
674 | break; | ||
675 | case EV_LED: | ||
676 | *bit = input->ledbit; | ||
677 | *max = LED_MAX; | ||
678 | break; | ||
679 | } | ||
680 | } | ||
681 | |||
682 | /** | ||
683 | * hid_map_usage_clear - map usage input bits and clear the input bit | ||
684 | * | ||
685 | * The same as hid_map_usage, except the @c bit is also cleared in supported | ||
686 | * bits (@bit). | ||
687 | */ | ||
688 | static inline void hid_map_usage_clear(struct hid_input *hidinput, | ||
689 | struct hid_usage *usage, unsigned long **bit, int *max, | ||
690 | __u8 type, __u16 c) | ||
691 | { | ||
692 | hid_map_usage(hidinput, usage, bit, max, type, c); | ||
693 | clear_bit(c, *bit); | ||
694 | } | ||
695 | |||
696 | /** | ||
697 | * hid_parse - parse HW reports | ||
698 | * | ||
699 | * @hdev: hid device | ||
700 | * | ||
701 | * Call this from probe after you set up the device (if needed). Your | ||
702 | * report_fixup will be called (if non-NULL) after reading raw report from | ||
703 | * device before passing it to hid layer for real parsing. | ||
704 | */ | ||
705 | static inline int __must_check hid_parse(struct hid_device *hdev) | ||
706 | { | ||
707 | int ret; | ||
708 | |||
709 | if (hdev->status & HID_STAT_PARSED) | ||
710 | return 0; | ||
711 | |||
712 | ret = hdev->ll_driver->parse(hdev); | ||
713 | if (!ret) | ||
714 | hdev->status |= HID_STAT_PARSED; | ||
715 | |||
716 | return ret; | ||
717 | } | ||
718 | |||
719 | /** | ||
720 | * hid_hw_start - start underlaying HW | ||
721 | * | ||
722 | * @hdev: hid device | ||
723 | * @connect_mask: which outputs to connect, see HID_CONNECT_* | ||
724 | * | ||
725 | * Call this in probe function *after* hid_parse. This will setup HW buffers | ||
726 | * and start the device (if not deffered to device open). hid_hw_stop must be | ||
727 | * called if this was successfull. | ||
728 | */ | ||
729 | static inline int __must_check hid_hw_start(struct hid_device *hdev, | ||
730 | unsigned int connect_mask) | ||
731 | { | ||
732 | int ret = hdev->ll_driver->start(hdev); | ||
733 | if (ret || !connect_mask) | ||
734 | return ret; | ||
735 | ret = hid_connect(hdev, connect_mask); | ||
736 | if (ret) | ||
737 | hdev->ll_driver->stop(hdev); | ||
738 | return ret; | ||
739 | } | ||
740 | |||
741 | /** | ||
742 | * hid_hw_stop - stop underlaying HW | ||
743 | * | ||
744 | * @hdev: hid device | ||
745 | * | ||
746 | * This is usually called from remove function or from probe when something | ||
747 | * failed and hid_hw_start was called already. | ||
748 | */ | ||
749 | static inline void hid_hw_stop(struct hid_device *hdev) | ||
750 | { | ||
751 | hdev->ll_driver->stop(hdev); | ||
752 | } | ||
753 | |||
754 | void hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size, | ||
755 | int interrupt); | ||
756 | |||
757 | extern int hid_generic_init(void); | ||
758 | extern void hid_generic_exit(void); | ||
537 | 759 | ||
538 | /* HID quirks API */ | 760 | /* HID quirks API */ |
539 | u32 usbhid_lookup_quirk(const u16 idVendor, const u16 idProduct); | 761 | u32 usbhid_lookup_quirk(const u16 idVendor, const u16 idProduct); |
540 | int usbhid_quirks_init(char **quirks_param); | 762 | int usbhid_quirks_init(char **quirks_param); |
541 | void usbhid_quirks_exit(void); | 763 | void usbhid_quirks_exit(void); |
542 | void usbhid_fixup_report_descriptor(const u16, const u16, char *, unsigned, char **); | 764 | void usbhid_set_leds(struct hid_device *hid); |
543 | |||
544 | #ifdef CONFIG_HID_FF | ||
545 | int hid_ff_init(struct hid_device *hid); | ||
546 | 765 | ||
547 | int hid_lgff_init(struct hid_device *hid); | ||
548 | int hid_lg2ff_init(struct hid_device *hid); | ||
549 | int hid_plff_init(struct hid_device *hid); | ||
550 | int hid_tmff_init(struct hid_device *hid); | ||
551 | int hid_zpff_init(struct hid_device *hid); | ||
552 | #ifdef CONFIG_HID_PID | 766 | #ifdef CONFIG_HID_PID |
553 | int hid_pidff_init(struct hid_device *hid); | 767 | int hid_pidff_init(struct hid_device *hid); |
554 | #else | 768 | #else |
555 | static inline int hid_pidff_init(struct hid_device *hid) { return -ENODEV; } | 769 | #define hid_pidff_init NULL |
556 | #endif | ||
557 | |||
558 | #else | ||
559 | static inline int hid_ff_init(struct hid_device *hid) { return -1; } | ||
560 | #endif | 770 | #endif |
561 | 771 | ||
562 | #ifdef CONFIG_HID_DEBUG | 772 | #ifdef CONFIG_HID_DEBUG |
@@ -572,10 +782,23 @@ dbg_hid(const char *fmt, ...) | |||
572 | return 0; | 782 | return 0; |
573 | } | 783 | } |
574 | #define dbg_hid_line dbg_hid | 784 | #define dbg_hid_line dbg_hid |
575 | #endif | 785 | #endif /* HID_DEBUG */ |
576 | 786 | ||
577 | #define err_hid(format, arg...) printk(KERN_ERR "%s: " format "\n" , \ | 787 | #define err_hid(format, arg...) printk(KERN_ERR "%s: " format "\n" , \ |
578 | __FILE__ , ## arg) | 788 | __FILE__ , ## arg) |
579 | #endif | 789 | #endif /* HID_FF */ |
790 | |||
791 | #ifdef CONFIG_HID_COMPAT | ||
792 | #define HID_COMPAT_LOAD_DRIVER(name) \ | ||
793 | void hid_compat_##name(void) { } \ | ||
794 | EXPORT_SYMBOL(hid_compat_##name) | ||
795 | #else | ||
796 | #define HID_COMPAT_LOAD_DRIVER(name) | ||
797 | #endif /* HID_COMPAT */ | ||
798 | #define HID_COMPAT_CALL_DRIVER(name) do { \ | ||
799 | extern void hid_compat_##name(void); \ | ||
800 | hid_compat_##name(); \ | ||
801 | } while (0) | ||
802 | |||
580 | #endif | 803 | #endif |
581 | 804 | ||
diff --git a/include/linux/hiddev.h b/include/linux/hiddev.h index a416b904ba90..c760ae0eb6a1 100644 --- a/include/linux/hiddev.h +++ b/include/linux/hiddev.h | |||
@@ -182,26 +182,28 @@ struct hiddev_usage_ref_multi { | |||
182 | /* To traverse the input report descriptor info for a HID device, perform the | 182 | /* To traverse the input report descriptor info for a HID device, perform the |
183 | * following: | 183 | * following: |
184 | * | 184 | * |
185 | * rinfo.report_type = HID_REPORT_TYPE_INPUT; | 185 | * rinfo.report_type = HID_REPORT_TYPE_INPUT; |
186 | * rinfo.report_id = HID_REPORT_ID_FIRST; | 186 | * rinfo.report_id = HID_REPORT_ID_FIRST; |
187 | * ret = ioctl(fd, HIDIOCGREPORTINFO, &rinfo); | 187 | * ret = ioctl(fd, HIDIOCGREPORTINFO, &rinfo); |
188 | * | 188 | * |
189 | * while (ret >= 0) { | 189 | * while (ret >= 0) { |
190 | * for (i = 0; i < rinfo.num_fields; i++) { | 190 | * for (i = 0; i < rinfo.num_fields; i++) { |
191 | * finfo.report_type = rinfo.report_type; | 191 | * finfo.report_type = rinfo.report_type; |
192 | * finfo.report_id = rinfo.report_id; | 192 | * finfo.report_id = rinfo.report_id; |
193 | * finfo.field_index = i; | 193 | * finfo.field_index = i; |
194 | * ioctl(fd, HIDIOCGFIELDINFO, &finfo); | 194 | * ioctl(fd, HIDIOCGFIELDINFO, &finfo); |
195 | * for (j = 0; j < finfo.maxusage; j++) { | 195 | * for (j = 0; j < finfo.maxusage; j++) { |
196 | * uref.field_index = i; | 196 | * uref.report_type = rinfo.report_type; |
197 | * uref.usage_index = j; | 197 | * uref.report_id = rinfo.report_id; |
198 | * ioctl(fd, HIDIOCGUCODE, &uref); | 198 | * uref.field_index = i; |
199 | * ioctl(fd, HIDIOCGUSAGE, &uref); | 199 | * uref.usage_index = j; |
200 | * } | 200 | * ioctl(fd, HIDIOCGUCODE, &uref); |
201 | * } | 201 | * ioctl(fd, HIDIOCGUSAGE, &uref); |
202 | * rinfo.report_id |= HID_REPORT_ID_NEXT; | 202 | * } |
203 | * ret = ioctl(fd, HIDIOCGREPORTINFO, &rinfo); | 203 | * } |
204 | * } | 204 | * rinfo.report_id |= HID_REPORT_ID_NEXT; |
205 | * ret = ioctl(fd, HIDIOCGREPORTINFO, &rinfo); | ||
206 | * } | ||
205 | */ | 207 | */ |
206 | 208 | ||
207 | 209 | ||
@@ -217,7 +219,7 @@ struct hid_field; | |||
217 | struct hid_report; | 219 | struct hid_report; |
218 | 220 | ||
219 | #ifdef CONFIG_USB_HIDDEV | 221 | #ifdef CONFIG_USB_HIDDEV |
220 | int hiddev_connect(struct hid_device *); | 222 | int hiddev_connect(struct hid_device *hid, unsigned int force); |
221 | void hiddev_disconnect(struct hid_device *); | 223 | void hiddev_disconnect(struct hid_device *); |
222 | void hiddev_hid_event(struct hid_device *hid, struct hid_field *field, | 224 | void hiddev_hid_event(struct hid_device *hid, struct hid_field *field, |
223 | struct hid_usage *usage, __s32 value); | 225 | struct hid_usage *usage, __s32 value); |
@@ -225,7 +227,9 @@ void hiddev_report_event(struct hid_device *hid, struct hid_report *report); | |||
225 | int __init hiddev_init(void); | 227 | int __init hiddev_init(void); |
226 | void hiddev_exit(void); | 228 | void hiddev_exit(void); |
227 | #else | 229 | #else |
228 | static inline int hiddev_connect(struct hid_device *hid) { return -1; } | 230 | static inline int hiddev_connect(struct hid_device *hid, |
231 | unsigned int force) | ||
232 | { return -1; } | ||
229 | static inline void hiddev_disconnect(struct hid_device *hid) { } | 233 | static inline void hiddev_disconnect(struct hid_device *hid) { } |
230 | static inline void hiddev_hid_event(struct hid_device *hid, struct hid_field *field, | 234 | static inline void hiddev_hid_event(struct hid_device *hid, struct hid_field *field, |
231 | struct hid_usage *usage, __s32 value) { } | 235 | struct hid_usage *usage, __s32 value) { } |
diff --git a/include/linux/if_ether.h b/include/linux/if_ether.h index bf1a53b2682e..7f3c735f422b 100644 --- a/include/linux/if_ether.h +++ b/include/linux/if_ether.h | |||
@@ -9,7 +9,7 @@ | |||
9 | * | 9 | * |
10 | * Author: Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> | 10 | * Author: Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> |
11 | * Donald Becker, <becker@super.org> | 11 | * Donald Becker, <becker@super.org> |
12 | * Alan Cox, <alan@redhat.com> | 12 | * Alan Cox, <alan@lxorguk.ukuu.org.uk> |
13 | * Steve Whitehouse, <gw7rrm@eeshack3.swan.ac.uk> | 13 | * Steve Whitehouse, <gw7rrm@eeshack3.swan.ac.uk> |
14 | * | 14 | * |
15 | * This program is free software; you can redistribute it and/or | 15 | * This program is free software; you can redistribute it and/or |
diff --git a/include/linux/if_fddi.h b/include/linux/if_fddi.h index ae77daed6c2f..45de1046dbbf 100644 --- a/include/linux/if_fddi.h +++ b/include/linux/if_fddi.h | |||
@@ -12,7 +12,7 @@ | |||
12 | * if_fddi.h is based on previous if_ether.h and if_tr.h work by | 12 | * if_fddi.h is based on previous if_ether.h and if_tr.h work by |
13 | * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> | 13 | * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> |
14 | * Donald Becker, <becker@super.org> | 14 | * Donald Becker, <becker@super.org> |
15 | * Alan Cox, <alan@redhat.com> | 15 | * Alan Cox, <alan@lxorguk.ukuu.org.uk> |
16 | * Steve Whitehouse, <gw7rrm@eeshack3.swan.ac.uk> | 16 | * Steve Whitehouse, <gw7rrm@eeshack3.swan.ac.uk> |
17 | * Peter De Schrijver, <stud11@cc4.kuleuven.ac.be> | 17 | * Peter De Schrijver, <stud11@cc4.kuleuven.ac.be> |
18 | * | 18 | * |
diff --git a/include/linux/if_hippi.h b/include/linux/if_hippi.h index 94d31ca7d71a..f0f23516bb59 100644 --- a/include/linux/if_hippi.h +++ b/include/linux/if_hippi.h | |||
@@ -9,7 +9,7 @@ | |||
9 | * | 9 | * |
10 | * Author: Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> | 10 | * Author: Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> |
11 | * Donald Becker, <becker@super.org> | 11 | * Donald Becker, <becker@super.org> |
12 | * Alan Cox, <alan@redhat.com> | 12 | * Alan Cox, <alan@lxorguk.ukuu.org.uk> |
13 | * Steve Whitehouse, <gw7rrm@eeshack3.swan.ac.uk> | 13 | * Steve Whitehouse, <gw7rrm@eeshack3.swan.ac.uk> |
14 | * Jes Sorensen, <Jes.Sorensen@cern.ch> | 14 | * Jes Sorensen, <Jes.Sorensen@cern.ch> |
15 | * | 15 | * |
diff --git a/include/linux/igmp.h b/include/linux/igmp.h index 7bb3c095c15b..f734a0ba0698 100644 --- a/include/linux/igmp.h +++ b/include/linux/igmp.h | |||
@@ -2,7 +2,7 @@ | |||
2 | * Linux NET3: Internet Group Management Protocol [IGMP] | 2 | * Linux NET3: Internet Group Management Protocol [IGMP] |
3 | * | 3 | * |
4 | * Authors: | 4 | * Authors: |
5 | * Alan Cox <Alan.Cox@linux.org> | 5 | * Alan Cox <alan@lxorguk.ukuu.org.uk> |
6 | * | 6 | * |
7 | * Extended to talk the BSD extended IGMP protocol of mrouted 3.6 | 7 | * Extended to talk the BSD extended IGMP protocol of mrouted 3.6 |
8 | * | 8 | * |
diff --git a/include/linux/lockd/bind.h b/include/linux/lockd/bind.h index 3d25bcd139d1..e5872dc994c0 100644 --- a/include/linux/lockd/bind.h +++ b/include/linux/lockd/bind.h | |||
@@ -27,7 +27,6 @@ struct nlmsvc_binding { | |||
27 | struct nfs_fh *, | 27 | struct nfs_fh *, |
28 | struct file **); | 28 | struct file **); |
29 | void (*fclose)(struct file *); | 29 | void (*fclose)(struct file *); |
30 | unsigned long (*get_grace_period)(void); | ||
31 | }; | 30 | }; |
32 | 31 | ||
33 | extern struct nlmsvc_binding * nlmsvc_ops; | 32 | extern struct nlmsvc_binding * nlmsvc_ops; |
@@ -53,15 +52,7 @@ extern void nlmclnt_done(struct nlm_host *host); | |||
53 | 52 | ||
54 | extern int nlmclnt_proc(struct nlm_host *host, int cmd, | 53 | extern int nlmclnt_proc(struct nlm_host *host, int cmd, |
55 | struct file_lock *fl); | 54 | struct file_lock *fl); |
56 | extern int lockd_up(int proto); | 55 | extern int lockd_up(void); |
57 | extern void lockd_down(void); | 56 | extern void lockd_down(void); |
58 | 57 | ||
59 | unsigned long get_nfs_grace_period(void); | ||
60 | |||
61 | #ifdef CONFIG_NFSD_V4 | ||
62 | unsigned long get_nfs4_grace_period(void); | ||
63 | #else | ||
64 | static inline unsigned long get_nfs4_grace_period(void) {return 0;} | ||
65 | #endif | ||
66 | |||
67 | #endif /* LINUX_LOCKD_BIND_H */ | 58 | #endif /* LINUX_LOCKD_BIND_H */ |
diff --git a/include/linux/lockd/lockd.h b/include/linux/lockd/lockd.h index dbb87ab282e8..b56d5aa9b194 100644 --- a/include/linux/lockd/lockd.h +++ b/include/linux/lockd/lockd.h | |||
@@ -12,6 +12,8 @@ | |||
12 | #ifdef __KERNEL__ | 12 | #ifdef __KERNEL__ |
13 | 13 | ||
14 | #include <linux/in.h> | 14 | #include <linux/in.h> |
15 | #include <linux/in6.h> | ||
16 | #include <net/ipv6.h> | ||
15 | #include <linux/fs.h> | 17 | #include <linux/fs.h> |
16 | #include <linux/kref.h> | 18 | #include <linux/kref.h> |
17 | #include <linux/utsname.h> | 19 | #include <linux/utsname.h> |
@@ -38,8 +40,9 @@ | |||
38 | */ | 40 | */ |
39 | struct nlm_host { | 41 | struct nlm_host { |
40 | struct hlist_node h_hash; /* doubly linked list */ | 42 | struct hlist_node h_hash; /* doubly linked list */ |
41 | struct sockaddr_in h_addr; /* peer address */ | 43 | struct sockaddr_storage h_addr; /* peer address */ |
42 | struct sockaddr_in h_saddr; /* our address (optional) */ | 44 | size_t h_addrlen; |
45 | struct sockaddr_storage h_srcaddr; /* our address (optional) */ | ||
43 | struct rpc_clnt * h_rpcclnt; /* RPC client to talk to peer */ | 46 | struct rpc_clnt * h_rpcclnt; /* RPC client to talk to peer */ |
44 | char * h_name; /* remote hostname */ | 47 | char * h_name; /* remote hostname */ |
45 | u32 h_version; /* interface version */ | 48 | u32 h_version; /* interface version */ |
@@ -61,18 +64,56 @@ struct nlm_host { | |||
61 | struct list_head h_granted; /* Locks in GRANTED state */ | 64 | struct list_head h_granted; /* Locks in GRANTED state */ |
62 | struct list_head h_reclaim; /* Locks in RECLAIM state */ | 65 | struct list_head h_reclaim; /* Locks in RECLAIM state */ |
63 | struct nsm_handle * h_nsmhandle; /* NSM status handle */ | 66 | struct nsm_handle * h_nsmhandle; /* NSM status handle */ |
67 | |||
68 | char h_addrbuf[48], /* address eyecatchers */ | ||
69 | h_srcaddrbuf[48]; | ||
64 | }; | 70 | }; |
65 | 71 | ||
66 | struct nsm_handle { | 72 | struct nsm_handle { |
67 | struct list_head sm_link; | 73 | struct list_head sm_link; |
68 | atomic_t sm_count; | 74 | atomic_t sm_count; |
69 | char * sm_name; | 75 | char * sm_name; |
70 | struct sockaddr_in sm_addr; | 76 | struct sockaddr_storage sm_addr; |
77 | size_t sm_addrlen; | ||
71 | unsigned int sm_monitored : 1, | 78 | unsigned int sm_monitored : 1, |
72 | sm_sticky : 1; /* don't unmonitor */ | 79 | sm_sticky : 1; /* don't unmonitor */ |
80 | char sm_addrbuf[48]; /* address eyecatcher */ | ||
73 | }; | 81 | }; |
74 | 82 | ||
75 | /* | 83 | /* |
84 | * Rigorous type checking on sockaddr type conversions | ||
85 | */ | ||
86 | static inline struct sockaddr_in *nlm_addr_in(const struct nlm_host *host) | ||
87 | { | ||
88 | return (struct sockaddr_in *)&host->h_addr; | ||
89 | } | ||
90 | |||
91 | static inline struct sockaddr *nlm_addr(const struct nlm_host *host) | ||
92 | { | ||
93 | return (struct sockaddr *)&host->h_addr; | ||
94 | } | ||
95 | |||
96 | static inline struct sockaddr_in *nlm_srcaddr_in(const struct nlm_host *host) | ||
97 | { | ||
98 | return (struct sockaddr_in *)&host->h_srcaddr; | ||
99 | } | ||
100 | |||
101 | static inline struct sockaddr *nlm_srcaddr(const struct nlm_host *host) | ||
102 | { | ||
103 | return (struct sockaddr *)&host->h_srcaddr; | ||
104 | } | ||
105 | |||
106 | static inline struct sockaddr_in *nsm_addr_in(const struct nsm_handle *handle) | ||
107 | { | ||
108 | return (struct sockaddr_in *)&handle->sm_addr; | ||
109 | } | ||
110 | |||
111 | static inline struct sockaddr *nsm_addr(const struct nsm_handle *handle) | ||
112 | { | ||
113 | return (struct sockaddr *)&handle->sm_addr; | ||
114 | } | ||
115 | |||
116 | /* | ||
76 | * Map an fl_owner_t into a unique 32-bit "pid" | 117 | * Map an fl_owner_t into a unique 32-bit "pid" |
77 | */ | 118 | */ |
78 | struct nlm_lockowner { | 119 | struct nlm_lockowner { |
@@ -166,7 +207,8 @@ int nlm_async_reply(struct nlm_rqst *, u32, const struct rpc_call_ops *); | |||
166 | struct nlm_wait * nlmclnt_prepare_block(struct nlm_host *host, struct file_lock *fl); | 207 | struct nlm_wait * nlmclnt_prepare_block(struct nlm_host *host, struct file_lock *fl); |
167 | void nlmclnt_finish_block(struct nlm_wait *block); | 208 | void nlmclnt_finish_block(struct nlm_wait *block); |
168 | int nlmclnt_block(struct nlm_wait *block, struct nlm_rqst *req, long timeout); | 209 | int nlmclnt_block(struct nlm_wait *block, struct nlm_rqst *req, long timeout); |
169 | __be32 nlmclnt_grant(const struct sockaddr_in *addr, const struct nlm_lock *); | 210 | __be32 nlmclnt_grant(const struct sockaddr *addr, |
211 | const struct nlm_lock *lock); | ||
170 | void nlmclnt_recovery(struct nlm_host *); | 212 | void nlmclnt_recovery(struct nlm_host *); |
171 | int nlmclnt_reclaim(struct nlm_host *, struct file_lock *); | 213 | int nlmclnt_reclaim(struct nlm_host *, struct file_lock *); |
172 | void nlmclnt_next_cookie(struct nlm_cookie *); | 214 | void nlmclnt_next_cookie(struct nlm_cookie *); |
@@ -174,12 +216,14 @@ void nlmclnt_next_cookie(struct nlm_cookie *); | |||
174 | /* | 216 | /* |
175 | * Host cache | 217 | * Host cache |
176 | */ | 218 | */ |
177 | struct nlm_host *nlmclnt_lookup_host(const struct sockaddr_in *sin, | 219 | struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap, |
178 | int proto, u32 version, | 220 | const size_t salen, |
221 | const unsigned short protocol, | ||
222 | const u32 version, | ||
223 | const char *hostname); | ||
224 | struct nlm_host *nlmsvc_lookup_host(const struct svc_rqst *rqstp, | ||
179 | const char *hostname, | 225 | const char *hostname, |
180 | unsigned int hostname_len); | 226 | const size_t hostname_len); |
181 | struct nlm_host *nlmsvc_lookup_host(struct svc_rqst *, const char *, | ||
182 | unsigned int); | ||
183 | struct rpc_clnt * nlm_bind_host(struct nlm_host *); | 227 | struct rpc_clnt * nlm_bind_host(struct nlm_host *); |
184 | void nlm_rebind_host(struct nlm_host *); | 228 | void nlm_rebind_host(struct nlm_host *); |
185 | struct nlm_host * nlm_get_host(struct nlm_host *); | 229 | struct nlm_host * nlm_get_host(struct nlm_host *); |
@@ -201,7 +245,7 @@ typedef int (*nlm_host_match_fn_t)(void *cur, struct nlm_host *ref); | |||
201 | */ | 245 | */ |
202 | __be32 nlmsvc_lock(struct svc_rqst *, struct nlm_file *, | 246 | __be32 nlmsvc_lock(struct svc_rqst *, struct nlm_file *, |
203 | struct nlm_host *, struct nlm_lock *, int, | 247 | struct nlm_host *, struct nlm_lock *, int, |
204 | struct nlm_cookie *); | 248 | struct nlm_cookie *, int); |
205 | __be32 nlmsvc_unlock(struct nlm_file *, struct nlm_lock *); | 249 | __be32 nlmsvc_unlock(struct nlm_file *, struct nlm_lock *); |
206 | __be32 nlmsvc_testlock(struct svc_rqst *, struct nlm_file *, | 250 | __be32 nlmsvc_testlock(struct svc_rqst *, struct nlm_file *, |
207 | struct nlm_host *, struct nlm_lock *, | 251 | struct nlm_host *, struct nlm_lock *, |
@@ -233,15 +277,82 @@ static inline struct inode *nlmsvc_file_inode(struct nlm_file *file) | |||
233 | return file->f_file->f_path.dentry->d_inode; | 277 | return file->f_file->f_path.dentry->d_inode; |
234 | } | 278 | } |
235 | 279 | ||
280 | static inline int __nlm_privileged_request4(const struct sockaddr *sap) | ||
281 | { | ||
282 | const struct sockaddr_in *sin = (struct sockaddr_in *)sap; | ||
283 | return (sin->sin_addr.s_addr == htonl(INADDR_LOOPBACK)) && | ||
284 | (ntohs(sin->sin_port) < 1024); | ||
285 | } | ||
286 | |||
287 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
288 | static inline int __nlm_privileged_request6(const struct sockaddr *sap) | ||
289 | { | ||
290 | const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap; | ||
291 | return (ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LOOPBACK) && | ||
292 | (ntohs(sin6->sin6_port) < 1024); | ||
293 | } | ||
294 | #else /* defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) */ | ||
295 | static inline int __nlm_privileged_request6(const struct sockaddr *sap) | ||
296 | { | ||
297 | return 0; | ||
298 | } | ||
299 | #endif /* defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) */ | ||
300 | |||
236 | /* | 301 | /* |
237 | * Compare two host addresses (needs modifying for ipv6) | 302 | * Ensure incoming requests are from local privileged callers. |
303 | * | ||
304 | * Return TRUE if sender is local and is connecting via a privileged port; | ||
305 | * otherwise return FALSE. | ||
238 | */ | 306 | */ |
239 | static inline int nlm_cmp_addr(const struct sockaddr_in *sin1, | 307 | static inline int nlm_privileged_requester(const struct svc_rqst *rqstp) |
240 | const struct sockaddr_in *sin2) | ||
241 | { | 308 | { |
309 | const struct sockaddr *sap = svc_addr(rqstp); | ||
310 | |||
311 | switch (sap->sa_family) { | ||
312 | case AF_INET: | ||
313 | return __nlm_privileged_request4(sap); | ||
314 | case AF_INET6: | ||
315 | return __nlm_privileged_request6(sap); | ||
316 | default: | ||
317 | return 0; | ||
318 | } | ||
319 | } | ||
320 | |||
321 | static inline int __nlm_cmp_addr4(const struct sockaddr *sap1, | ||
322 | const struct sockaddr *sap2) | ||
323 | { | ||
324 | const struct sockaddr_in *sin1 = (const struct sockaddr_in *)sap1; | ||
325 | const struct sockaddr_in *sin2 = (const struct sockaddr_in *)sap2; | ||
242 | return sin1->sin_addr.s_addr == sin2->sin_addr.s_addr; | 326 | return sin1->sin_addr.s_addr == sin2->sin_addr.s_addr; |
243 | } | 327 | } |
244 | 328 | ||
329 | static inline int __nlm_cmp_addr6(const struct sockaddr *sap1, | ||
330 | const struct sockaddr *sap2) | ||
331 | { | ||
332 | const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sap1; | ||
333 | const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sap2; | ||
334 | return ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr); | ||
335 | } | ||
336 | |||
337 | /* | ||
338 | * Compare two host addresses | ||
339 | * | ||
340 | * Return TRUE if the addresses are the same; otherwise FALSE. | ||
341 | */ | ||
342 | static inline int nlm_cmp_addr(const struct sockaddr *sap1, | ||
343 | const struct sockaddr *sap2) | ||
344 | { | ||
345 | if (sap1->sa_family == sap2->sa_family) { | ||
346 | switch (sap1->sa_family) { | ||
347 | case AF_INET: | ||
348 | return __nlm_cmp_addr4(sap1, sap2); | ||
349 | case AF_INET6: | ||
350 | return __nlm_cmp_addr6(sap1, sap2); | ||
351 | } | ||
352 | } | ||
353 | return 0; | ||
354 | } | ||
355 | |||
245 | /* | 356 | /* |
246 | * Compare two NLM locks. | 357 | * Compare two NLM locks. |
247 | * When the second lock is of type F_UNLCK, this acts like a wildcard. | 358 | * When the second lock is of type F_UNLCK, this acts like a wildcard. |
diff --git a/include/linux/lockd/xdr.h b/include/linux/lockd/xdr.h index df18fa053bcd..d6b3a802c046 100644 --- a/include/linux/lockd/xdr.h +++ b/include/linux/lockd/xdr.h | |||
@@ -81,8 +81,6 @@ struct nlm_reboot { | |||
81 | unsigned int len; | 81 | unsigned int len; |
82 | u32 state; | 82 | u32 state; |
83 | __be32 addr; | 83 | __be32 addr; |
84 | __be32 vers; | ||
85 | __be32 proto; | ||
86 | }; | 84 | }; |
87 | 85 | ||
88 | /* | 86 | /* |
diff --git a/include/linux/mfd/wm8350/audio.h b/include/linux/mfd/wm8350/audio.h new file mode 100644 index 000000000000..217bb22ebb8e --- /dev/null +++ b/include/linux/mfd/wm8350/audio.h | |||
@@ -0,0 +1,598 @@ | |||
1 | /* | ||
2 | * audio.h -- Audio Driver for Wolfson WM8350 PMIC | ||
3 | * | ||
4 | * Copyright 2007 Wolfson Microelectronics PLC | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License as published by the | ||
8 | * Free Software Foundation; either version 2 of the License, or (at your | ||
9 | * option) any later version. | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | #ifndef __LINUX_MFD_WM8350_AUDIO_H_ | ||
14 | #define __LINUX_MFD_WM8350_AUDIO_H_ | ||
15 | |||
16 | #include <linux/platform_device.h> | ||
17 | |||
18 | #define WM8350_CLOCK_CONTROL_1 0x28 | ||
19 | #define WM8350_CLOCK_CONTROL_2 0x29 | ||
20 | #define WM8350_FLL_CONTROL_1 0x2A | ||
21 | #define WM8350_FLL_CONTROL_2 0x2B | ||
22 | #define WM8350_FLL_CONTROL_3 0x2C | ||
23 | #define WM8350_FLL_CONTROL_4 0x2D | ||
24 | #define WM8350_DAC_CONTROL 0x30 | ||
25 | #define WM8350_DAC_DIGITAL_VOLUME_L 0x32 | ||
26 | #define WM8350_DAC_DIGITAL_VOLUME_R 0x33 | ||
27 | #define WM8350_DAC_LR_RATE 0x35 | ||
28 | #define WM8350_DAC_CLOCK_CONTROL 0x36 | ||
29 | #define WM8350_DAC_MUTE 0x3A | ||
30 | #define WM8350_DAC_MUTE_VOLUME 0x3B | ||
31 | #define WM8350_DAC_SIDE 0x3C | ||
32 | #define WM8350_ADC_CONTROL 0x40 | ||
33 | #define WM8350_ADC_DIGITAL_VOLUME_L 0x42 | ||
34 | #define WM8350_ADC_DIGITAL_VOLUME_R 0x43 | ||
35 | #define WM8350_ADC_DIVIDER 0x44 | ||
36 | #define WM8350_ADC_LR_RATE 0x46 | ||
37 | #define WM8350_INPUT_CONTROL 0x48 | ||
38 | #define WM8350_IN3_INPUT_CONTROL 0x49 | ||
39 | #define WM8350_MIC_BIAS_CONTROL 0x4A | ||
40 | #define WM8350_OUTPUT_CONTROL 0x4C | ||
41 | #define WM8350_JACK_DETECT 0x4D | ||
42 | #define WM8350_ANTI_POP_CONTROL 0x4E | ||
43 | #define WM8350_LEFT_INPUT_VOLUME 0x50 | ||
44 | #define WM8350_RIGHT_INPUT_VOLUME 0x51 | ||
45 | #define WM8350_LEFT_MIXER_CONTROL 0x58 | ||
46 | #define WM8350_RIGHT_MIXER_CONTROL 0x59 | ||
47 | #define WM8350_OUT3_MIXER_CONTROL 0x5C | ||
48 | #define WM8350_OUT4_MIXER_CONTROL 0x5D | ||
49 | #define WM8350_OUTPUT_LEFT_MIXER_VOLUME 0x60 | ||
50 | #define WM8350_OUTPUT_RIGHT_MIXER_VOLUME 0x61 | ||
51 | #define WM8350_INPUT_MIXER_VOLUME_L 0x62 | ||
52 | #define WM8350_INPUT_MIXER_VOLUME_R 0x63 | ||
53 | #define WM8350_INPUT_MIXER_VOLUME 0x64 | ||
54 | #define WM8350_LOUT1_VOLUME 0x68 | ||
55 | #define WM8350_ROUT1_VOLUME 0x69 | ||
56 | #define WM8350_LOUT2_VOLUME 0x6A | ||
57 | #define WM8350_ROUT2_VOLUME 0x6B | ||
58 | #define WM8350_BEEP_VOLUME 0x6F | ||
59 | #define WM8350_AI_FORMATING 0x70 | ||
60 | #define WM8350_ADC_DAC_COMP 0x71 | ||
61 | #define WM8350_AI_ADC_CONTROL 0x72 | ||
62 | #define WM8350_AI_DAC_CONTROL 0x73 | ||
63 | #define WM8350_AIF_TEST 0x74 | ||
64 | #define WM8350_JACK_PIN_STATUS 0xE7 | ||
65 | |||
66 | /* Bit values for R08 (0x08) */ | ||
67 | #define WM8350_CODEC_ISEL_1_5 0 /* x1.5 */ | ||
68 | #define WM8350_CODEC_ISEL_1_0 1 /* x1.0 */ | ||
69 | #define WM8350_CODEC_ISEL_0_75 2 /* x0.75 */ | ||
70 | #define WM8350_CODEC_ISEL_0_5 3 /* x0.5 */ | ||
71 | |||
72 | #define WM8350_VMID_OFF 0 | ||
73 | #define WM8350_VMID_500K 1 | ||
74 | #define WM8350_VMID_100K 2 | ||
75 | #define WM8350_VMID_10K 3 | ||
76 | |||
77 | /* | ||
78 | * R40 (0x28) - Clock Control 1 | ||
79 | */ | ||
80 | #define WM8350_TOCLK_RATE 0x4000 | ||
81 | #define WM8350_MCLK_SEL 0x0800 | ||
82 | #define WM8350_MCLK_DIV_MASK 0x0100 | ||
83 | #define WM8350_BCLK_DIV_MASK 0x00F0 | ||
84 | #define WM8350_OPCLK_DIV_MASK 0x0007 | ||
85 | |||
86 | /* | ||
87 | * R41 (0x29) - Clock Control 2 | ||
88 | */ | ||
89 | #define WM8350_LRC_ADC_SEL 0x8000 | ||
90 | #define WM8350_MCLK_DIR 0x0001 | ||
91 | |||
92 | /* | ||
93 | * R42 (0x2A) - FLL Control 1 | ||
94 | */ | ||
95 | #define WM8350_FLL_DITHER_WIDTH_MASK 0x3000 | ||
96 | #define WM8350_FLL_DITHER_HP 0x0800 | ||
97 | #define WM8350_FLL_OUTDIV_MASK 0x0700 | ||
98 | #define WM8350_FLL_RSP_RATE_MASK 0x00F0 | ||
99 | #define WM8350_FLL_RATE_MASK 0x0007 | ||
100 | |||
101 | /* | ||
102 | * R43 (0x2B) - FLL Control 2 | ||
103 | */ | ||
104 | #define WM8350_FLL_RATIO_MASK 0xF800 | ||
105 | #define WM8350_FLL_N_MASK 0x03FF | ||
106 | |||
107 | /* | ||
108 | * R44 (0x2C) - FLL Control 3 | ||
109 | */ | ||
110 | #define WM8350_FLL_K_MASK 0xFFFF | ||
111 | |||
112 | /* | ||
113 | * R45 (0x2D) - FLL Control 4 | ||
114 | */ | ||
115 | #define WM8350_FLL_FRAC 0x0020 | ||
116 | #define WM8350_FLL_SLOW_LOCK_REF 0x0010 | ||
117 | #define WM8350_FLL_CLK_SRC_MASK 0x0003 | ||
118 | |||
119 | /* | ||
120 | * R48 (0x30) - DAC Control | ||
121 | */ | ||
122 | #define WM8350_DAC_MONO 0x2000 | ||
123 | #define WM8350_AIF_LRCLKRATE 0x1000 | ||
124 | #define WM8350_DEEMP_MASK 0x0030 | ||
125 | #define WM8350_DACL_DATINV 0x0002 | ||
126 | #define WM8350_DACR_DATINV 0x0001 | ||
127 | |||
128 | /* | ||
129 | * R50 (0x32) - DAC Digital Volume L | ||
130 | */ | ||
131 | #define WM8350_DAC_VU 0x0100 | ||
132 | #define WM8350_DACL_VOL_MASK 0x00FF | ||
133 | |||
134 | /* | ||
135 | * R51 (0x33) - DAC Digital Volume R | ||
136 | */ | ||
137 | #define WM8350_DAC_VU 0x0100 | ||
138 | #define WM8350_DACR_VOL_MASK 0x00FF | ||
139 | |||
140 | /* | ||
141 | * R53 (0x35) - DAC LR Rate | ||
142 | */ | ||
143 | #define WM8350_DACLRC_ENA 0x0800 | ||
144 | #define WM8350_DACLRC_RATE_MASK 0x07FF | ||
145 | |||
146 | /* | ||
147 | * R54 (0x36) - DAC Clock Control | ||
148 | */ | ||
149 | #define WM8350_DACCLK_POL 0x0010 | ||
150 | #define WM8350_DAC_CLKDIV_MASK 0x0007 | ||
151 | |||
152 | /* | ||
153 | * R58 (0x3A) - DAC Mute | ||
154 | */ | ||
155 | #define WM8350_DAC_MUTE_ENA 0x4000 | ||
156 | |||
157 | /* | ||
158 | * R59 (0x3B) - DAC Mute Volume | ||
159 | */ | ||
160 | #define WM8350_DAC_MUTEMODE 0x4000 | ||
161 | #define WM8350_DAC_MUTERATE 0x2000 | ||
162 | #define WM8350_DAC_SB_FILT 0x1000 | ||
163 | |||
164 | /* | ||
165 | * R60 (0x3C) - DAC Side | ||
166 | */ | ||
167 | #define WM8350_ADC_TO_DACL_MASK 0x3000 | ||
168 | #define WM8350_ADC_TO_DACR_MASK 0x0C00 | ||
169 | |||
170 | /* | ||
171 | * R64 (0x40) - ADC Control | ||
172 | */ | ||
173 | #define WM8350_ADC_HPF_CUT_MASK 0x0300 | ||
174 | #define WM8350_ADCL_DATINV 0x0002 | ||
175 | #define WM8350_ADCR_DATINV 0x0001 | ||
176 | |||
177 | /* | ||
178 | * R66 (0x42) - ADC Digital Volume L | ||
179 | */ | ||
180 | #define WM8350_ADC_VU 0x0100 | ||
181 | #define WM8350_ADCL_VOL_MASK 0x00FF | ||
182 | |||
183 | /* | ||
184 | * R67 (0x43) - ADC Digital Volume R | ||
185 | */ | ||
186 | #define WM8350_ADC_VU 0x0100 | ||
187 | #define WM8350_ADCR_VOL_MASK 0x00FF | ||
188 | |||
189 | /* | ||
190 | * R68 (0x44) - ADC Divider | ||
191 | */ | ||
192 | #define WM8350_ADCL_DAC_SVOL_MASK 0x0F00 | ||
193 | #define WM8350_ADCR_DAC_SVOL_MASK 0x00F0 | ||
194 | #define WM8350_ADCCLK_POL 0x0008 | ||
195 | #define WM8350_ADC_CLKDIV_MASK 0x0007 | ||
196 | |||
197 | /* | ||
198 | * R70 (0x46) - ADC LR Rate | ||
199 | */ | ||
200 | #define WM8350_ADCLRC_ENA 0x0800 | ||
201 | #define WM8350_ADCLRC_RATE_MASK 0x07FF | ||
202 | |||
203 | /* | ||
204 | * R72 (0x48) - Input Control | ||
205 | */ | ||
206 | #define WM8350_IN2R_ENA 0x0400 | ||
207 | #define WM8350_IN1RN_ENA 0x0200 | ||
208 | #define WM8350_IN1RP_ENA 0x0100 | ||
209 | #define WM8350_IN2L_ENA 0x0004 | ||
210 | #define WM8350_IN1LN_ENA 0x0002 | ||
211 | #define WM8350_IN1LP_ENA 0x0001 | ||
212 | |||
213 | /* | ||
214 | * R73 (0x49) - IN3 Input Control | ||
215 | */ | ||
216 | #define WM8350_IN3R_SHORT 0x4000 | ||
217 | #define WM8350_IN3L_SHORT 0x0040 | ||
218 | |||
219 | /* | ||
220 | * R74 (0x4A) - Mic Bias Control | ||
221 | */ | ||
222 | #define WM8350_MICBSEL 0x4000 | ||
223 | #define WM8350_MCDTHR_MASK 0x001C | ||
224 | #define WM8350_MCDSCTHR_MASK 0x0003 | ||
225 | |||
226 | /* | ||
227 | * R76 (0x4C) - Output Control | ||
228 | */ | ||
229 | #define WM8350_OUT4_VROI 0x0800 | ||
230 | #define WM8350_OUT3_VROI 0x0400 | ||
231 | #define WM8350_OUT2_VROI 0x0200 | ||
232 | #define WM8350_OUT1_VROI 0x0100 | ||
233 | #define WM8350_OUT2_FB 0x0004 | ||
234 | #define WM8350_OUT1_FB 0x0001 | ||
235 | |||
236 | /* | ||
237 | * R77 (0x4D) - Jack Detect | ||
238 | */ | ||
239 | #define WM8350_JDL_ENA 0x8000 | ||
240 | #define WM8350_JDR_ENA 0x4000 | ||
241 | |||
242 | /* | ||
243 | * R78 (0x4E) - Anti Pop Control | ||
244 | */ | ||
245 | #define WM8350_ANTI_POP_MASK 0x0300 | ||
246 | #define WM8350_DIS_OP_LN4_MASK 0x00C0 | ||
247 | #define WM8350_DIS_OP_LN3_MASK 0x0030 | ||
248 | #define WM8350_DIS_OP_OUT2_MASK 0x000C | ||
249 | #define WM8350_DIS_OP_OUT1_MASK 0x0003 | ||
250 | |||
251 | /* | ||
252 | * R80 (0x50) - Left Input Volume | ||
253 | */ | ||
254 | #define WM8350_INL_MUTE 0x4000 | ||
255 | #define WM8350_INL_ZC 0x2000 | ||
256 | #define WM8350_IN_VU 0x0100 | ||
257 | #define WM8350_INL_VOL_MASK 0x00FC | ||
258 | |||
259 | /* | ||
260 | * R81 (0x51) - Right Input Volume | ||
261 | */ | ||
262 | #define WM8350_INR_MUTE 0x4000 | ||
263 | #define WM8350_INR_ZC 0x2000 | ||
264 | #define WM8350_IN_VU 0x0100 | ||
265 | #define WM8350_INR_VOL_MASK 0x00FC | ||
266 | |||
267 | /* | ||
268 | * R88 (0x58) - Left Mixer Control | ||
269 | */ | ||
270 | #define WM8350_DACR_TO_MIXOUTL 0x1000 | ||
271 | #define WM8350_DACL_TO_MIXOUTL 0x0800 | ||
272 | #define WM8350_IN3L_TO_MIXOUTL 0x0004 | ||
273 | #define WM8350_INR_TO_MIXOUTL 0x0002 | ||
274 | #define WM8350_INL_TO_MIXOUTL 0x0001 | ||
275 | |||
276 | /* | ||
277 | * R89 (0x59) - Right Mixer Control | ||
278 | */ | ||
279 | #define WM8350_DACR_TO_MIXOUTR 0x1000 | ||
280 | #define WM8350_DACL_TO_MIXOUTR 0x0800 | ||
281 | #define WM8350_IN3R_TO_MIXOUTR 0x0008 | ||
282 | #define WM8350_INR_TO_MIXOUTR 0x0002 | ||
283 | #define WM8350_INL_TO_MIXOUTR 0x0001 | ||
284 | |||
285 | /* | ||
286 | * R92 (0x5C) - OUT3 Mixer Control | ||
287 | */ | ||
288 | #define WM8350_DACL_TO_OUT3 0x0800 | ||
289 | #define WM8350_MIXINL_TO_OUT3 0x0100 | ||
290 | #define WM8350_OUT4_TO_OUT3 0x0008 | ||
291 | #define WM8350_MIXOUTL_TO_OUT3 0x0001 | ||
292 | |||
293 | /* | ||
294 | * R93 (0x5D) - OUT4 Mixer Control | ||
295 | */ | ||
296 | #define WM8350_DACR_TO_OUT4 0x1000 | ||
297 | #define WM8350_DACL_TO_OUT4 0x0800 | ||
298 | #define WM8350_OUT4_ATTN 0x0400 | ||
299 | #define WM8350_MIXINR_TO_OUT4 0x0200 | ||
300 | #define WM8350_OUT3_TO_OUT4 0x0004 | ||
301 | #define WM8350_MIXOUTR_TO_OUT4 0x0002 | ||
302 | #define WM8350_MIXOUTL_TO_OUT4 0x0001 | ||
303 | |||
304 | /* | ||
305 | * R96 (0x60) - Output Left Mixer Volume | ||
306 | */ | ||
307 | #define WM8350_IN3L_MIXOUTL_VOL_MASK 0x0E00 | ||
308 | #define WM8350_IN3L_MIXOUTL_VOL_SHIFT 9 | ||
309 | #define WM8350_INR_MIXOUTL_VOL_MASK 0x00E0 | ||
310 | #define WM8350_INR_MIXOUTL_VOL_SHIFT 5 | ||
311 | #define WM8350_INL_MIXOUTL_VOL_MASK 0x000E | ||
312 | #define WM8350_INL_MIXOUTL_VOL_SHIFT 1 | ||
313 | |||
314 | /* Bit values for R96 (0x60) */ | ||
315 | #define WM8350_IN3L_MIXOUTL_VOL_OFF 0 | ||
316 | #define WM8350_IN3L_MIXOUTL_VOL_M12DB 1 | ||
317 | #define WM8350_IN3L_MIXOUTL_VOL_M9DB 2 | ||
318 | #define WM8350_IN3L_MIXOUTL_VOL_M6DB 3 | ||
319 | #define WM8350_IN3L_MIXOUTL_VOL_M3DB 4 | ||
320 | #define WM8350_IN3L_MIXOUTL_VOL_0DB 5 | ||
321 | #define WM8350_IN3L_MIXOUTL_VOL_3DB 6 | ||
322 | #define WM8350_IN3L_MIXOUTL_VOL_6DB 7 | ||
323 | |||
324 | #define WM8350_INR_MIXOUTL_VOL_OFF 0 | ||
325 | #define WM8350_INR_MIXOUTL_VOL_M12DB 1 | ||
326 | #define WM8350_INR_MIXOUTL_VOL_M9DB 2 | ||
327 | #define WM8350_INR_MIXOUTL_VOL_M6DB 3 | ||
328 | #define WM8350_INR_MIXOUTL_VOL_M3DB 4 | ||
329 | #define WM8350_INR_MIXOUTL_VOL_0DB 5 | ||
330 | #define WM8350_INR_MIXOUTL_VOL_3DB 6 | ||
331 | #define WM8350_INR_MIXOUTL_VOL_6DB 7 | ||
332 | |||
333 | #define WM8350_INL_MIXOUTL_VOL_OFF 0 | ||
334 | #define WM8350_INL_MIXOUTL_VOL_M12DB 1 | ||
335 | #define WM8350_INL_MIXOUTL_VOL_M9DB 2 | ||
336 | #define WM8350_INL_MIXOUTL_VOL_M6DB 3 | ||
337 | #define WM8350_INL_MIXOUTL_VOL_M3DB 4 | ||
338 | #define WM8350_INL_MIXOUTL_VOL_0DB 5 | ||
339 | #define WM8350_INL_MIXOUTL_VOL_3DB 6 | ||
340 | #define WM8350_INL_MIXOUTL_VOL_6DB 7 | ||
341 | |||
342 | /* | ||
343 | * R97 (0x61) - Output Right Mixer Volume | ||
344 | */ | ||
345 | #define WM8350_IN3R_MIXOUTR_VOL_MASK 0xE000 | ||
346 | #define WM8350_IN3R_MIXOUTR_VOL_SHIFT 13 | ||
347 | #define WM8350_INR_MIXOUTR_VOL_MASK 0x00E0 | ||
348 | #define WM8350_INR_MIXOUTR_VOL_SHIFT 5 | ||
349 | #define WM8350_INL_MIXOUTR_VOL_MASK 0x000E | ||
350 | #define WM8350_INL_MIXOUTR_VOL_SHIFT 1 | ||
351 | |||
352 | /* Bit values for R96 (0x60) */ | ||
353 | #define WM8350_IN3R_MIXOUTR_VOL_OFF 0 | ||
354 | #define WM8350_IN3R_MIXOUTR_VOL_M12DB 1 | ||
355 | #define WM8350_IN3R_MIXOUTR_VOL_M9DB 2 | ||
356 | #define WM8350_IN3R_MIXOUTR_VOL_M6DB 3 | ||
357 | #define WM8350_IN3R_MIXOUTR_VOL_M3DB 4 | ||
358 | #define WM8350_IN3R_MIXOUTR_VOL_0DB 5 | ||
359 | #define WM8350_IN3R_MIXOUTR_VOL_3DB 6 | ||
360 | #define WM8350_IN3R_MIXOUTR_VOL_6DB 7 | ||
361 | |||
362 | #define WM8350_INR_MIXOUTR_VOL_OFF 0 | ||
363 | #define WM8350_INR_MIXOUTR_VOL_M12DB 1 | ||
364 | #define WM8350_INR_MIXOUTR_VOL_M9DB 2 | ||
365 | #define WM8350_INR_MIXOUTR_VOL_M6DB 3 | ||
366 | #define WM8350_INR_MIXOUTR_VOL_M3DB 4 | ||
367 | #define WM8350_INR_MIXOUTR_VOL_0DB 5 | ||
368 | #define WM8350_INR_MIXOUTR_VOL_3DB 6 | ||
369 | #define WM8350_INR_MIXOUTR_VOL_6DB 7 | ||
370 | |||
371 | #define WM8350_INL_MIXOUTR_VOL_OFF 0 | ||
372 | #define WM8350_INL_MIXOUTR_VOL_M12DB 1 | ||
373 | #define WM8350_INL_MIXOUTR_VOL_M9DB 2 | ||
374 | #define WM8350_INL_MIXOUTR_VOL_M6DB 3 | ||
375 | #define WM8350_INL_MIXOUTR_VOL_M3DB 4 | ||
376 | #define WM8350_INL_MIXOUTR_VOL_0DB 5 | ||
377 | #define WM8350_INL_MIXOUTR_VOL_3DB 6 | ||
378 | #define WM8350_INL_MIXOUTR_VOL_6DB 7 | ||
379 | |||
380 | /* | ||
381 | * R98 (0x62) - Input Mixer Volume L | ||
382 | */ | ||
383 | #define WM8350_IN3L_MIXINL_VOL_MASK 0x0E00 | ||
384 | #define WM8350_IN2L_MIXINL_VOL_MASK 0x000E | ||
385 | #define WM8350_INL_MIXINL_VOL 0x0001 | ||
386 | |||
387 | /* | ||
388 | * R99 (0x63) - Input Mixer Volume R | ||
389 | */ | ||
390 | #define WM8350_IN3R_MIXINR_VOL_MASK 0xE000 | ||
391 | #define WM8350_IN2R_MIXINR_VOL_MASK 0x00E0 | ||
392 | #define WM8350_INR_MIXINR_VOL 0x0001 | ||
393 | |||
394 | /* | ||
395 | * R100 (0x64) - Input Mixer Volume | ||
396 | */ | ||
397 | #define WM8350_OUT4_MIXIN_DST 0x8000 | ||
398 | #define WM8350_OUT4_MIXIN_VOL_MASK 0x000E | ||
399 | |||
400 | /* | ||
401 | * R104 (0x68) - LOUT1 Volume | ||
402 | */ | ||
403 | #define WM8350_OUT1L_MUTE 0x4000 | ||
404 | #define WM8350_OUT1L_ZC 0x2000 | ||
405 | #define WM8350_OUT1_VU 0x0100 | ||
406 | #define WM8350_OUT1L_VOL_MASK 0x00FC | ||
407 | #define WM8350_OUT1L_VOL_SHIFT 2 | ||
408 | |||
409 | /* | ||
410 | * R105 (0x69) - ROUT1 Volume | ||
411 | */ | ||
412 | #define WM8350_OUT1R_MUTE 0x4000 | ||
413 | #define WM8350_OUT1R_ZC 0x2000 | ||
414 | #define WM8350_OUT1_VU 0x0100 | ||
415 | #define WM8350_OUT1R_VOL_MASK 0x00FC | ||
416 | #define WM8350_OUT1R_VOL_SHIFT 2 | ||
417 | |||
418 | /* | ||
419 | * R106 (0x6A) - LOUT2 Volume | ||
420 | */ | ||
421 | #define WM8350_OUT2L_MUTE 0x4000 | ||
422 | #define WM8350_OUT2L_ZC 0x2000 | ||
423 | #define WM8350_OUT2_VU 0x0100 | ||
424 | #define WM8350_OUT2L_VOL_MASK 0x00FC | ||
425 | |||
426 | /* | ||
427 | * R107 (0x6B) - ROUT2 Volume | ||
428 | */ | ||
429 | #define WM8350_OUT2R_MUTE 0x4000 | ||
430 | #define WM8350_OUT2R_ZC 0x2000 | ||
431 | #define WM8350_OUT2R_INV 0x0400 | ||
432 | #define WM8350_OUT2R_INV_MUTE 0x0200 | ||
433 | #define WM8350_OUT2_VU 0x0100 | ||
434 | #define WM8350_OUT2R_VOL_MASK 0x00FC | ||
435 | |||
436 | /* | ||
437 | * R111 (0x6F) - BEEP Volume | ||
438 | */ | ||
439 | #define WM8350_IN3R_OUT2R_VOL_MASK 0x00E0 | ||
440 | |||
441 | /* | ||
442 | * R112 (0x70) - AI Formating | ||
443 | */ | ||
444 | #define WM8350_AIF_BCLK_INV 0x8000 | ||
445 | #define WM8350_AIF_TRI 0x2000 | ||
446 | #define WM8350_AIF_LRCLK_INV 0x1000 | ||
447 | #define WM8350_AIF_WL_MASK 0x0C00 | ||
448 | #define WM8350_AIF_FMT_MASK 0x0300 | ||
449 | |||
450 | /* | ||
451 | * R113 (0x71) - ADC DAC COMP | ||
452 | */ | ||
453 | #define WM8350_DAC_COMP 0x0080 | ||
454 | #define WM8350_DAC_COMPMODE 0x0040 | ||
455 | #define WM8350_ADC_COMP 0x0020 | ||
456 | #define WM8350_ADC_COMPMODE 0x0010 | ||
457 | #define WM8350_LOOPBACK 0x0001 | ||
458 | |||
459 | /* | ||
460 | * R114 (0x72) - AI ADC Control | ||
461 | */ | ||
462 | #define WM8350_AIFADC_PD 0x0080 | ||
463 | #define WM8350_AIFADCL_SRC 0x0040 | ||
464 | #define WM8350_AIFADCR_SRC 0x0020 | ||
465 | #define WM8350_AIFADC_TDM_CHAN 0x0010 | ||
466 | #define WM8350_AIFADC_TDM 0x0008 | ||
467 | |||
468 | /* | ||
469 | * R115 (0x73) - AI DAC Control | ||
470 | */ | ||
471 | #define WM8350_BCLK_MSTR 0x4000 | ||
472 | #define WM8350_AIFDAC_PD 0x0080 | ||
473 | #define WM8350_DACL_SRC 0x0040 | ||
474 | #define WM8350_DACR_SRC 0x0020 | ||
475 | #define WM8350_AIFDAC_TDM_CHAN 0x0010 | ||
476 | #define WM8350_AIFDAC_TDM 0x0008 | ||
477 | #define WM8350_DAC_BOOST_MASK 0x0003 | ||
478 | |||
479 | /* | ||
480 | * R116 (0x74) - AIF Test | ||
481 | */ | ||
482 | #define WM8350_CODEC_BYP 0x4000 | ||
483 | #define WM8350_AIFADC_WR_TST 0x2000 | ||
484 | #define WM8350_AIFADC_RD_TST 0x1000 | ||
485 | #define WM8350_AIFDAC_WR_TST 0x0800 | ||
486 | #define WM8350_AIFDAC_RD_TST 0x0400 | ||
487 | #define WM8350_AIFADC_ASYN 0x0020 | ||
488 | #define WM8350_AIFDAC_ASYN 0x0010 | ||
489 | |||
490 | /* | ||
491 | * R231 (0xE7) - Jack Status | ||
492 | */ | ||
493 | #define WM8350_JACK_R_LVL 0x0400 | ||
494 | |||
495 | /* | ||
496 | * WM8350 Platform setup | ||
497 | */ | ||
498 | #define WM8350_S_CURVE_NONE 0x0 | ||
499 | #define WM8350_S_CURVE_FAST 0x1 | ||
500 | #define WM8350_S_CURVE_MEDIUM 0x2 | ||
501 | #define WM8350_S_CURVE_SLOW 0x3 | ||
502 | |||
503 | #define WM8350_DISCHARGE_OFF 0x0 | ||
504 | #define WM8350_DISCHARGE_FAST 0x1 | ||
505 | #define WM8350_DISCHARGE_MEDIUM 0x2 | ||
506 | #define WM8350_DISCHARGE_SLOW 0x3 | ||
507 | |||
508 | #define WM8350_TIE_OFF_500R 0x0 | ||
509 | #define WM8350_TIE_OFF_30K 0x1 | ||
510 | |||
511 | /* | ||
512 | * Clock sources & directions | ||
513 | */ | ||
514 | #define WM8350_SYSCLK 0 | ||
515 | |||
516 | #define WM8350_MCLK_SEL_PLL_MCLK 0 | ||
517 | #define WM8350_MCLK_SEL_PLL_DAC 1 | ||
518 | #define WM8350_MCLK_SEL_PLL_ADC 2 | ||
519 | #define WM8350_MCLK_SEL_PLL_32K 3 | ||
520 | #define WM8350_MCLK_SEL_MCLK 5 | ||
521 | |||
522 | #define WM8350_MCLK_DIR_OUT 0 | ||
523 | #define WM8350_MCLK_DIR_IN 1 | ||
524 | |||
525 | /* clock divider id's */ | ||
526 | #define WM8350_ADC_CLKDIV 0 | ||
527 | #define WM8350_DAC_CLKDIV 1 | ||
528 | #define WM8350_BCLK_CLKDIV 2 | ||
529 | #define WM8350_OPCLK_CLKDIV 3 | ||
530 | #define WM8350_TO_CLKDIV 4 | ||
531 | #define WM8350_SYS_CLKDIV 5 | ||
532 | #define WM8350_DACLR_CLKDIV 6 | ||
533 | #define WM8350_ADCLR_CLKDIV 7 | ||
534 | |||
535 | /* ADC clock dividers */ | ||
536 | #define WM8350_ADCDIV_1 0x0 | ||
537 | #define WM8350_ADCDIV_1_5 0x1 | ||
538 | #define WM8350_ADCDIV_2 0x2 | ||
539 | #define WM8350_ADCDIV_3 0x3 | ||
540 | #define WM8350_ADCDIV_4 0x4 | ||
541 | #define WM8350_ADCDIV_5_5 0x5 | ||
542 | #define WM8350_ADCDIV_6 0x6 | ||
543 | |||
544 | /* ADC clock dividers */ | ||
545 | #define WM8350_DACDIV_1 0x0 | ||
546 | #define WM8350_DACDIV_1_5 0x1 | ||
547 | #define WM8350_DACDIV_2 0x2 | ||
548 | #define WM8350_DACDIV_3 0x3 | ||
549 | #define WM8350_DACDIV_4 0x4 | ||
550 | #define WM8350_DACDIV_5_5 0x5 | ||
551 | #define WM8350_DACDIV_6 0x6 | ||
552 | |||
553 | /* BCLK clock dividers */ | ||
554 | #define WM8350_BCLK_DIV_1 (0x0 << 4) | ||
555 | #define WM8350_BCLK_DIV_1_5 (0x1 << 4) | ||
556 | #define WM8350_BCLK_DIV_2 (0x2 << 4) | ||
557 | #define WM8350_BCLK_DIV_3 (0x3 << 4) | ||
558 | #define WM8350_BCLK_DIV_4 (0x4 << 4) | ||
559 | #define WM8350_BCLK_DIV_5_5 (0x5 << 4) | ||
560 | #define WM8350_BCLK_DIV_6 (0x6 << 4) | ||
561 | #define WM8350_BCLK_DIV_8 (0x7 << 4) | ||
562 | #define WM8350_BCLK_DIV_11 (0x8 << 4) | ||
563 | #define WM8350_BCLK_DIV_12 (0x9 << 4) | ||
564 | #define WM8350_BCLK_DIV_16 (0xa << 4) | ||
565 | #define WM8350_BCLK_DIV_22 (0xb << 4) | ||
566 | #define WM8350_BCLK_DIV_24 (0xc << 4) | ||
567 | #define WM8350_BCLK_DIV_32 (0xd << 4) | ||
568 | #define WM8350_BCLK_DIV_44 (0xe << 4) | ||
569 | #define WM8350_BCLK_DIV_48 (0xf << 4) | ||
570 | |||
571 | /* Sys (MCLK) clock dividers */ | ||
572 | #define WM8350_MCLK_DIV_1 (0x0 << 8) | ||
573 | #define WM8350_MCLK_DIV_2 (0x1 << 8) | ||
574 | |||
575 | /* OP clock dividers */ | ||
576 | #define WM8350_OPCLK_DIV_1 0x0 | ||
577 | #define WM8350_OPCLK_DIV_2 0x1 | ||
578 | #define WM8350_OPCLK_DIV_3 0x2 | ||
579 | #define WM8350_OPCLK_DIV_4 0x3 | ||
580 | #define WM8350_OPCLK_DIV_5_5 0x4 | ||
581 | #define WM8350_OPCLK_DIV_6 0x5 | ||
582 | |||
583 | /* DAI ID */ | ||
584 | #define WM8350_HIFI_DAI 0 | ||
585 | |||
586 | /* | ||
587 | * Audio interrupts. | ||
588 | */ | ||
589 | #define WM8350_IRQ_CODEC_JCK_DET_L 39 | ||
590 | #define WM8350_IRQ_CODEC_JCK_DET_R 40 | ||
591 | #define WM8350_IRQ_CODEC_MICSCD 41 | ||
592 | #define WM8350_IRQ_CODEC_MICD 42 | ||
593 | |||
594 | struct wm8350_codec { | ||
595 | struct platform_device *pdev; | ||
596 | }; | ||
597 | |||
598 | #endif | ||
diff --git a/include/linux/mfd/wm8350/comparator.h b/include/linux/mfd/wm8350/comparator.h new file mode 100644 index 000000000000..053788649452 --- /dev/null +++ b/include/linux/mfd/wm8350/comparator.h | |||
@@ -0,0 +1,167 @@ | |||
1 | /* | ||
2 | * comparator.h -- Comparator Aux ADC for Wolfson WM8350 PMIC | ||
3 | * | ||
4 | * Copyright 2007 Wolfson Microelectronics PLC | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License as published by the | ||
8 | * Free Software Foundation; either version 2 of the License, or (at your | ||
9 | * option) any later version. | ||
10 | */ | ||
11 | |||
12 | #ifndef __LINUX_MFD_WM8350_COMPARATOR_H_ | ||
13 | #define __LINUX_MFD_WM8350_COMPARATOR_H_ | ||
14 | |||
15 | /* | ||
16 | * Registers | ||
17 | */ | ||
18 | |||
19 | #define WM8350_DIGITISER_CONTROL_1 0x90 | ||
20 | #define WM8350_DIGITISER_CONTROL_2 0x91 | ||
21 | #define WM8350_AUX1_READBACK 0x98 | ||
22 | #define WM8350_AUX2_READBACK 0x99 | ||
23 | #define WM8350_AUX3_READBACK 0x9A | ||
24 | #define WM8350_AUX4_READBACK 0x9B | ||
25 | #define WM8350_CHIP_TEMP_READBACK 0x9F | ||
26 | #define WM8350_GENERIC_COMPARATOR_CONTROL 0xA3 | ||
27 | #define WM8350_GENERIC_COMPARATOR_1 0xA4 | ||
28 | #define WM8350_GENERIC_COMPARATOR_2 0xA5 | ||
29 | #define WM8350_GENERIC_COMPARATOR_3 0xA6 | ||
30 | #define WM8350_GENERIC_COMPARATOR_4 0xA7 | ||
31 | |||
32 | /* | ||
33 | * R144 (0x90) - Digitiser Control (1) | ||
34 | */ | ||
35 | #define WM8350_AUXADC_CTC 0x4000 | ||
36 | #define WM8350_AUXADC_POLL 0x2000 | ||
37 | #define WM8350_AUXADC_HIB_MODE 0x1000 | ||
38 | #define WM8350_AUXADC_SEL8 0x0080 | ||
39 | #define WM8350_AUXADC_SEL7 0x0040 | ||
40 | #define WM8350_AUXADC_SEL6 0x0020 | ||
41 | #define WM8350_AUXADC_SEL5 0x0010 | ||
42 | #define WM8350_AUXADC_SEL4 0x0008 | ||
43 | #define WM8350_AUXADC_SEL3 0x0004 | ||
44 | #define WM8350_AUXADC_SEL2 0x0002 | ||
45 | #define WM8350_AUXADC_SEL1 0x0001 | ||
46 | |||
47 | /* | ||
48 | * R145 (0x91) - Digitiser Control (2) | ||
49 | */ | ||
50 | #define WM8350_AUXADC_MASKMODE_MASK 0x3000 | ||
51 | #define WM8350_AUXADC_CRATE_MASK 0x0700 | ||
52 | #define WM8350_AUXADC_CAL 0x0004 | ||
53 | #define WM8350_AUX_RBMODE 0x0002 | ||
54 | #define WM8350_AUXADC_WAIT 0x0001 | ||
55 | |||
56 | /* | ||
57 | * R152 (0x98) - AUX1 Readback | ||
58 | */ | ||
59 | #define WM8350_AUXADC_SCALE1_MASK 0x6000 | ||
60 | #define WM8350_AUXADC_REF1 0x1000 | ||
61 | #define WM8350_AUXADC_DATA1_MASK 0x0FFF | ||
62 | |||
63 | /* | ||
64 | * R153 (0x99) - AUX2 Readback | ||
65 | */ | ||
66 | #define WM8350_AUXADC_SCALE2_MASK 0x6000 | ||
67 | #define WM8350_AUXADC_REF2 0x1000 | ||
68 | #define WM8350_AUXADC_DATA2_MASK 0x0FFF | ||
69 | |||
70 | /* | ||
71 | * R154 (0x9A) - AUX3 Readback | ||
72 | */ | ||
73 | #define WM8350_AUXADC_SCALE3_MASK 0x6000 | ||
74 | #define WM8350_AUXADC_REF3 0x1000 | ||
75 | #define WM8350_AUXADC_DATA3_MASK 0x0FFF | ||
76 | |||
77 | /* | ||
78 | * R155 (0x9B) - AUX4 Readback | ||
79 | */ | ||
80 | #define WM8350_AUXADC_SCALE4_MASK 0x6000 | ||
81 | #define WM8350_AUXADC_REF4 0x1000 | ||
82 | #define WM8350_AUXADC_DATA4_MASK 0x0FFF | ||
83 | |||
84 | /* | ||
85 | * R156 (0x9C) - USB Voltage Readback | ||
86 | */ | ||
87 | #define WM8350_AUXADC_DATA_USB_MASK 0x0FFF | ||
88 | |||
89 | /* | ||
90 | * R157 (0x9D) - LINE Voltage Readback | ||
91 | */ | ||
92 | #define WM8350_AUXADC_DATA_LINE_MASK 0x0FFF | ||
93 | |||
94 | /* | ||
95 | * R158 (0x9E) - BATT Voltage Readback | ||
96 | */ | ||
97 | #define WM8350_AUXADC_DATA_BATT_MASK 0x0FFF | ||
98 | |||
99 | /* | ||
100 | * R159 (0x9F) - Chip Temp Readback | ||
101 | */ | ||
102 | #define WM8350_AUXADC_DATA_CHIPTEMP_MASK 0x0FFF | ||
103 | |||
104 | /* | ||
105 | * R163 (0xA3) - Generic Comparator Control | ||
106 | */ | ||
107 | #define WM8350_DCMP4_ENA 0x0008 | ||
108 | #define WM8350_DCMP3_ENA 0x0004 | ||
109 | #define WM8350_DCMP2_ENA 0x0002 | ||
110 | #define WM8350_DCMP1_ENA 0x0001 | ||
111 | |||
112 | /* | ||
113 | * R164 (0xA4) - Generic comparator 1 | ||
114 | */ | ||
115 | #define WM8350_DCMP1_SRCSEL_MASK 0xE000 | ||
116 | #define WM8350_DCMP1_GT 0x1000 | ||
117 | #define WM8350_DCMP1_THR_MASK 0x0FFF | ||
118 | |||
119 | /* | ||
120 | * R165 (0xA5) - Generic comparator 2 | ||
121 | */ | ||
122 | #define WM8350_DCMP2_SRCSEL_MASK 0xE000 | ||
123 | #define WM8350_DCMP2_GT 0x1000 | ||
124 | #define WM8350_DCMP2_THR_MASK 0x0FFF | ||
125 | |||
126 | /* | ||
127 | * R166 (0xA6) - Generic comparator 3 | ||
128 | */ | ||
129 | #define WM8350_DCMP3_SRCSEL_MASK 0xE000 | ||
130 | #define WM8350_DCMP3_GT 0x1000 | ||
131 | #define WM8350_DCMP3_THR_MASK 0x0FFF | ||
132 | |||
133 | /* | ||
134 | * R167 (0xA7) - Generic comparator 4 | ||
135 | */ | ||
136 | #define WM8350_DCMP4_SRCSEL_MASK 0xE000 | ||
137 | #define WM8350_DCMP4_GT 0x1000 | ||
138 | #define WM8350_DCMP4_THR_MASK 0x0FFF | ||
139 | |||
140 | /* | ||
141 | * Interrupts. | ||
142 | */ | ||
143 | #define WM8350_IRQ_AUXADC_DATARDY 16 | ||
144 | #define WM8350_IRQ_AUXADC_DCOMP4 17 | ||
145 | #define WM8350_IRQ_AUXADC_DCOMP3 18 | ||
146 | #define WM8350_IRQ_AUXADC_DCOMP2 19 | ||
147 | #define WM8350_IRQ_AUXADC_DCOMP1 20 | ||
148 | #define WM8350_IRQ_SYS_HYST_COMP_FAIL 21 | ||
149 | #define WM8350_IRQ_SYS_CHIP_GT115 22 | ||
150 | #define WM8350_IRQ_SYS_CHIP_GT140 23 | ||
151 | |||
152 | /* | ||
153 | * USB/2, LINE & BATT = ((VRTC * 2) / 4095)) * 10e6 uV | ||
154 | * Where VRTC = 2.7 V | ||
155 | */ | ||
156 | #define WM8350_AUX_COEFF 1319 | ||
157 | |||
158 | #define WM8350_AUXADC_AUX1 0 | ||
159 | #define WM8350_AUXADC_AUX2 1 | ||
160 | #define WM8350_AUXADC_AUX3 2 | ||
161 | #define WM8350_AUXADC_AUX4 3 | ||
162 | #define WM8350_AUXADC_USB 4 | ||
163 | #define WM8350_AUXADC_LINE 5 | ||
164 | #define WM8350_AUXADC_BATT 6 | ||
165 | #define WM8350_AUXADC_TEMP 7 | ||
166 | |||
167 | #endif | ||
diff --git a/include/linux/mfd/wm8350/core.h b/include/linux/mfd/wm8350/core.h new file mode 100644 index 000000000000..6ebf97f2a475 --- /dev/null +++ b/include/linux/mfd/wm8350/core.h | |||
@@ -0,0 +1,631 @@ | |||
1 | /* | ||
2 | * core.h -- Core Driver for Wolfson WM8350 PMIC | ||
3 | * | ||
4 | * Copyright 2007 Wolfson Microelectronics PLC | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License as published by the | ||
8 | * Free Software Foundation; either version 2 of the License, or (at your | ||
9 | * option) any later version. | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | #ifndef __LINUX_MFD_WM8350_CORE_H_ | ||
14 | #define __LINUX_MFD_WM8350_CORE_H_ | ||
15 | |||
16 | #include <linux/kernel.h> | ||
17 | #include <linux/mutex.h> | ||
18 | #include <linux/workqueue.h> | ||
19 | |||
20 | #include <linux/mfd/wm8350/audio.h> | ||
21 | #include <linux/mfd/wm8350/gpio.h> | ||
22 | #include <linux/mfd/wm8350/pmic.h> | ||
23 | #include <linux/mfd/wm8350/rtc.h> | ||
24 | #include <linux/mfd/wm8350/supply.h> | ||
25 | #include <linux/mfd/wm8350/wdt.h> | ||
26 | |||
27 | /* | ||
28 | * Register values. | ||
29 | */ | ||
30 | #define WM8350_RESET_ID 0x00 | ||
31 | #define WM8350_ID 0x01 | ||
32 | #define WM8350_SYSTEM_CONTROL_1 0x03 | ||
33 | #define WM8350_SYSTEM_CONTROL_2 0x04 | ||
34 | #define WM8350_SYSTEM_HIBERNATE 0x05 | ||
35 | #define WM8350_INTERFACE_CONTROL 0x06 | ||
36 | #define WM8350_POWER_MGMT_1 0x08 | ||
37 | #define WM8350_POWER_MGMT_2 0x09 | ||
38 | #define WM8350_POWER_MGMT_3 0x0A | ||
39 | #define WM8350_POWER_MGMT_4 0x0B | ||
40 | #define WM8350_POWER_MGMT_5 0x0C | ||
41 | #define WM8350_POWER_MGMT_6 0x0D | ||
42 | #define WM8350_POWER_MGMT_7 0x0E | ||
43 | |||
44 | #define WM8350_SYSTEM_INTERRUPTS 0x18 | ||
45 | #define WM8350_INT_STATUS_1 0x19 | ||
46 | #define WM8350_INT_STATUS_2 0x1A | ||
47 | #define WM8350_POWER_UP_INT_STATUS 0x1B | ||
48 | #define WM8350_UNDER_VOLTAGE_INT_STATUS 0x1C | ||
49 | #define WM8350_OVER_CURRENT_INT_STATUS 0x1D | ||
50 | #define WM8350_GPIO_INT_STATUS 0x1E | ||
51 | #define WM8350_COMPARATOR_INT_STATUS 0x1F | ||
52 | #define WM8350_SYSTEM_INTERRUPTS_MASK 0x20 | ||
53 | #define WM8350_INT_STATUS_1_MASK 0x21 | ||
54 | #define WM8350_INT_STATUS_2_MASK 0x22 | ||
55 | #define WM8350_POWER_UP_INT_STATUS_MASK 0x23 | ||
56 | #define WM8350_UNDER_VOLTAGE_INT_STATUS_MASK 0x24 | ||
57 | #define WM8350_OVER_CURRENT_INT_STATUS_MASK 0x25 | ||
58 | #define WM8350_GPIO_INT_STATUS_MASK 0x26 | ||
59 | #define WM8350_COMPARATOR_INT_STATUS_MASK 0x27 | ||
60 | |||
61 | #define WM8350_MAX_REGISTER 0xFF | ||
62 | |||
63 | /* | ||
64 | * Field Definitions. | ||
65 | */ | ||
66 | |||
67 | /* | ||
68 | * R0 (0x00) - Reset/ID | ||
69 | */ | ||
70 | #define WM8350_SW_RESET_CHIP_ID_MASK 0xFFFF | ||
71 | |||
72 | /* | ||
73 | * R1 (0x01) - ID | ||
74 | */ | ||
75 | #define WM8350_CHIP_REV_MASK 0x7000 | ||
76 | #define WM8350_CONF_STS_MASK 0x0C00 | ||
77 | #define WM8350_CUST_ID_MASK 0x00FF | ||
78 | |||
79 | /* | ||
80 | * R3 (0x03) - System Control 1 | ||
81 | */ | ||
82 | #define WM8350_CHIP_ON 0x8000 | ||
83 | #define WM8350_POWERCYCLE 0x2000 | ||
84 | #define WM8350_VCC_FAULT_OV 0x1000 | ||
85 | #define WM8350_REG_RSTB_TIME_MASK 0x0C00 | ||
86 | #define WM8350_BG_SLEEP 0x0200 | ||
87 | #define WM8350_MEM_VALID 0x0020 | ||
88 | #define WM8350_CHIP_SET_UP 0x0010 | ||
89 | #define WM8350_ON_DEB_T 0x0008 | ||
90 | #define WM8350_ON_POL 0x0002 | ||
91 | #define WM8350_IRQ_POL 0x0001 | ||
92 | |||
93 | /* | ||
94 | * R4 (0x04) - System Control 2 | ||
95 | */ | ||
96 | #define WM8350_USB_SUSPEND_8MA 0x8000 | ||
97 | #define WM8350_USB_SUSPEND 0x4000 | ||
98 | #define WM8350_USB_MSTR 0x2000 | ||
99 | #define WM8350_USB_MSTR_SRC 0x1000 | ||
100 | #define WM8350_USB_500MA 0x0800 | ||
101 | #define WM8350_USB_NOLIM 0x0400 | ||
102 | |||
103 | /* | ||
104 | * R5 (0x05) - System Hibernate | ||
105 | */ | ||
106 | #define WM8350_HIBERNATE 0x8000 | ||
107 | #define WM8350_WDOG_HIB_MODE 0x0080 | ||
108 | #define WM8350_REG_HIB_STARTUP_SEQ 0x0040 | ||
109 | #define WM8350_REG_RESET_HIB_MODE 0x0020 | ||
110 | #define WM8350_RST_HIB_MODE 0x0010 | ||
111 | #define WM8350_IRQ_HIB_MODE 0x0008 | ||
112 | #define WM8350_MEMRST_HIB_MODE 0x0004 | ||
113 | #define WM8350_PCCOMP_HIB_MODE 0x0002 | ||
114 | #define WM8350_TEMPMON_HIB_MODE 0x0001 | ||
115 | |||
116 | /* | ||
117 | * R6 (0x06) - Interface Control | ||
118 | */ | ||
119 | #define WM8350_USE_DEV_PINS 0x8000 | ||
120 | #define WM8350_USE_DEV_PINS_MASK 0x8000 | ||
121 | #define WM8350_USE_DEV_PINS_SHIFT 15 | ||
122 | #define WM8350_DEV_ADDR_MASK 0x6000 | ||
123 | #define WM8350_DEV_ADDR_SHIFT 13 | ||
124 | #define WM8350_CONFIG_DONE 0x1000 | ||
125 | #define WM8350_CONFIG_DONE_MASK 0x1000 | ||
126 | #define WM8350_CONFIG_DONE_SHIFT 12 | ||
127 | #define WM8350_RECONFIG_AT_ON 0x0800 | ||
128 | #define WM8350_RECONFIG_AT_ON_MASK 0x0800 | ||
129 | #define WM8350_RECONFIG_AT_ON_SHIFT 11 | ||
130 | #define WM8350_AUTOINC 0x0200 | ||
131 | #define WM8350_AUTOINC_MASK 0x0200 | ||
132 | #define WM8350_AUTOINC_SHIFT 9 | ||
133 | #define WM8350_ARA 0x0100 | ||
134 | #define WM8350_ARA_MASK 0x0100 | ||
135 | #define WM8350_ARA_SHIFT 8 | ||
136 | #define WM8350_SPI_CFG 0x0008 | ||
137 | #define WM8350_SPI_CFG_MASK 0x0008 | ||
138 | #define WM8350_SPI_CFG_SHIFT 3 | ||
139 | #define WM8350_SPI_4WIRE 0x0004 | ||
140 | #define WM8350_SPI_4WIRE_MASK 0x0004 | ||
141 | #define WM8350_SPI_4WIRE_SHIFT 2 | ||
142 | #define WM8350_SPI_3WIRE 0x0002 | ||
143 | #define WM8350_SPI_3WIRE_MASK 0x0002 | ||
144 | #define WM8350_SPI_3WIRE_SHIFT 1 | ||
145 | |||
146 | /* Bit values for R06 (0x06) */ | ||
147 | #define WM8350_USE_DEV_PINS_PRIMARY 0 | ||
148 | #define WM8350_USE_DEV_PINS_DEV 1 | ||
149 | |||
150 | #define WM8350_DEV_ADDR_34 0 | ||
151 | #define WM8350_DEV_ADDR_36 1 | ||
152 | #define WM8350_DEV_ADDR_3C 2 | ||
153 | #define WM8350_DEV_ADDR_3E 3 | ||
154 | |||
155 | #define WM8350_CONFIG_DONE_OFF 0 | ||
156 | #define WM8350_CONFIG_DONE_DONE 1 | ||
157 | |||
158 | #define WM8350_RECONFIG_AT_ON_OFF 0 | ||
159 | #define WM8350_RECONFIG_AT_ON_ON 1 | ||
160 | |||
161 | #define WM8350_AUTOINC_OFF 0 | ||
162 | #define WM8350_AUTOINC_ON 1 | ||
163 | |||
164 | #define WM8350_ARA_OFF 0 | ||
165 | #define WM8350_ARA_ON 1 | ||
166 | |||
167 | #define WM8350_SPI_CFG_CMOS 0 | ||
168 | #define WM8350_SPI_CFG_OD 1 | ||
169 | |||
170 | #define WM8350_SPI_4WIRE_3WIRE 0 | ||
171 | #define WM8350_SPI_4WIRE_4WIRE 1 | ||
172 | |||
173 | #define WM8350_SPI_3WIRE_I2C 0 | ||
174 | #define WM8350_SPI_3WIRE_SPI 1 | ||
175 | |||
176 | /* | ||
177 | * R8 (0x08) - Power mgmt (1) | ||
178 | */ | ||
179 | #define WM8350_CODEC_ISEL_MASK 0xC000 | ||
180 | #define WM8350_VBUFEN 0x2000 | ||
181 | #define WM8350_OUTPUT_DRAIN_EN 0x0400 | ||
182 | #define WM8350_MIC_DET_ENA 0x0100 | ||
183 | #define WM8350_BIASEN 0x0020 | ||
184 | #define WM8350_MICBEN 0x0010 | ||
185 | #define WM8350_VMIDEN 0x0004 | ||
186 | #define WM8350_VMID_MASK 0x0003 | ||
187 | #define WM8350_VMID_SHIFT 0 | ||
188 | |||
189 | /* | ||
190 | * R9 (0x09) - Power mgmt (2) | ||
191 | */ | ||
192 | #define WM8350_IN3R_ENA 0x0800 | ||
193 | #define WM8350_IN3L_ENA 0x0400 | ||
194 | #define WM8350_INR_ENA 0x0200 | ||
195 | #define WM8350_INL_ENA 0x0100 | ||
196 | #define WM8350_MIXINR_ENA 0x0080 | ||
197 | #define WM8350_MIXINL_ENA 0x0040 | ||
198 | #define WM8350_OUT4_ENA 0x0020 | ||
199 | #define WM8350_OUT3_ENA 0x0010 | ||
200 | #define WM8350_MIXOUTR_ENA 0x0002 | ||
201 | #define WM8350_MIXOUTL_ENA 0x0001 | ||
202 | |||
203 | /* | ||
204 | * R10 (0x0A) - Power mgmt (3) | ||
205 | */ | ||
206 | #define WM8350_IN3R_TO_OUT2R 0x0080 | ||
207 | #define WM8350_OUT2R_ENA 0x0008 | ||
208 | #define WM8350_OUT2L_ENA 0x0004 | ||
209 | #define WM8350_OUT1R_ENA 0x0002 | ||
210 | #define WM8350_OUT1L_ENA 0x0001 | ||
211 | |||
212 | /* | ||
213 | * R11 (0x0B) - Power mgmt (4) | ||
214 | */ | ||
215 | #define WM8350_SYSCLK_ENA 0x4000 | ||
216 | #define WM8350_ADC_HPF_ENA 0x2000 | ||
217 | #define WM8350_FLL_ENA 0x0800 | ||
218 | #define WM8350_FLL_OSC_ENA 0x0400 | ||
219 | #define WM8350_TOCLK_ENA 0x0100 | ||
220 | #define WM8350_DACR_ENA 0x0020 | ||
221 | #define WM8350_DACL_ENA 0x0010 | ||
222 | #define WM8350_ADCR_ENA 0x0008 | ||
223 | #define WM8350_ADCL_ENA 0x0004 | ||
224 | |||
225 | /* | ||
226 | * R12 (0x0C) - Power mgmt (5) | ||
227 | */ | ||
228 | #define WM8350_CODEC_ENA 0x1000 | ||
229 | #define WM8350_RTC_TICK_ENA 0x0800 | ||
230 | #define WM8350_OSC32K_ENA 0x0400 | ||
231 | #define WM8350_CHG_ENA 0x0200 | ||
232 | #define WM8350_ACC_DET_ENA 0x0100 | ||
233 | #define WM8350_AUXADC_ENA 0x0080 | ||
234 | #define WM8350_DCMP4_ENA 0x0008 | ||
235 | #define WM8350_DCMP3_ENA 0x0004 | ||
236 | #define WM8350_DCMP2_ENA 0x0002 | ||
237 | #define WM8350_DCMP1_ENA 0x0001 | ||
238 | |||
239 | /* | ||
240 | * R13 (0x0D) - Power mgmt (6) | ||
241 | */ | ||
242 | #define WM8350_LS_ENA 0x8000 | ||
243 | #define WM8350_LDO4_ENA 0x0800 | ||
244 | #define WM8350_LDO3_ENA 0x0400 | ||
245 | #define WM8350_LDO2_ENA 0x0200 | ||
246 | #define WM8350_LDO1_ENA 0x0100 | ||
247 | #define WM8350_DC6_ENA 0x0020 | ||
248 | #define WM8350_DC5_ENA 0x0010 | ||
249 | #define WM8350_DC4_ENA 0x0008 | ||
250 | #define WM8350_DC3_ENA 0x0004 | ||
251 | #define WM8350_DC2_ENA 0x0002 | ||
252 | #define WM8350_DC1_ENA 0x0001 | ||
253 | |||
254 | /* | ||
255 | * R14 (0x0E) - Power mgmt (7) | ||
256 | */ | ||
257 | #define WM8350_CS2_ENA 0x0002 | ||
258 | #define WM8350_CS1_ENA 0x0001 | ||
259 | |||
260 | /* | ||
261 | * R24 (0x18) - System Interrupts | ||
262 | */ | ||
263 | #define WM8350_OC_INT 0x2000 | ||
264 | #define WM8350_UV_INT 0x1000 | ||
265 | #define WM8350_PUTO_INT 0x0800 | ||
266 | #define WM8350_CS_INT 0x0200 | ||
267 | #define WM8350_EXT_INT 0x0100 | ||
268 | #define WM8350_CODEC_INT 0x0080 | ||
269 | #define WM8350_GP_INT 0x0040 | ||
270 | #define WM8350_AUXADC_INT 0x0020 | ||
271 | #define WM8350_RTC_INT 0x0010 | ||
272 | #define WM8350_SYS_INT 0x0008 | ||
273 | #define WM8350_CHG_INT 0x0004 | ||
274 | #define WM8350_USB_INT 0x0002 | ||
275 | #define WM8350_WKUP_INT 0x0001 | ||
276 | |||
277 | /* | ||
278 | * R25 (0x19) - Interrupt Status 1 | ||
279 | */ | ||
280 | #define WM8350_CHG_BAT_HOT_EINT 0x8000 | ||
281 | #define WM8350_CHG_BAT_COLD_EINT 0x4000 | ||
282 | #define WM8350_CHG_BAT_FAIL_EINT 0x2000 | ||
283 | #define WM8350_CHG_TO_EINT 0x1000 | ||
284 | #define WM8350_CHG_END_EINT 0x0800 | ||
285 | #define WM8350_CHG_START_EINT 0x0400 | ||
286 | #define WM8350_CHG_FAST_RDY_EINT 0x0200 | ||
287 | #define WM8350_RTC_PER_EINT 0x0080 | ||
288 | #define WM8350_RTC_SEC_EINT 0x0040 | ||
289 | #define WM8350_RTC_ALM_EINT 0x0020 | ||
290 | #define WM8350_CHG_VBATT_LT_3P9_EINT 0x0004 | ||
291 | #define WM8350_CHG_VBATT_LT_3P1_EINT 0x0002 | ||
292 | #define WM8350_CHG_VBATT_LT_2P85_EINT 0x0001 | ||
293 | |||
294 | /* | ||
295 | * R26 (0x1A) - Interrupt Status 2 | ||
296 | */ | ||
297 | #define WM8350_CS1_EINT 0x2000 | ||
298 | #define WM8350_CS2_EINT 0x1000 | ||
299 | #define WM8350_USB_LIMIT_EINT 0x0400 | ||
300 | #define WM8350_AUXADC_DATARDY_EINT 0x0100 | ||
301 | #define WM8350_AUXADC_DCOMP4_EINT 0x0080 | ||
302 | #define WM8350_AUXADC_DCOMP3_EINT 0x0040 | ||
303 | #define WM8350_AUXADC_DCOMP2_EINT 0x0020 | ||
304 | #define WM8350_AUXADC_DCOMP1_EINT 0x0010 | ||
305 | #define WM8350_SYS_HYST_COMP_FAIL_EINT 0x0008 | ||
306 | #define WM8350_SYS_CHIP_GT115_EINT 0x0004 | ||
307 | #define WM8350_SYS_CHIP_GT140_EINT 0x0002 | ||
308 | #define WM8350_SYS_WDOG_TO_EINT 0x0001 | ||
309 | |||
310 | /* | ||
311 | * R27 (0x1B) - Power Up Interrupt Status | ||
312 | */ | ||
313 | #define WM8350_PUTO_LDO4_EINT 0x0800 | ||
314 | #define WM8350_PUTO_LDO3_EINT 0x0400 | ||
315 | #define WM8350_PUTO_LDO2_EINT 0x0200 | ||
316 | #define WM8350_PUTO_LDO1_EINT 0x0100 | ||
317 | #define WM8350_PUTO_DC6_EINT 0x0020 | ||
318 | #define WM8350_PUTO_DC5_EINT 0x0010 | ||
319 | #define WM8350_PUTO_DC4_EINT 0x0008 | ||
320 | #define WM8350_PUTO_DC3_EINT 0x0004 | ||
321 | #define WM8350_PUTO_DC2_EINT 0x0002 | ||
322 | #define WM8350_PUTO_DC1_EINT 0x0001 | ||
323 | |||
324 | /* | ||
325 | * R28 (0x1C) - Under Voltage Interrupt status | ||
326 | */ | ||
327 | #define WM8350_UV_LDO4_EINT 0x0800 | ||
328 | #define WM8350_UV_LDO3_EINT 0x0400 | ||
329 | #define WM8350_UV_LDO2_EINT 0x0200 | ||
330 | #define WM8350_UV_LDO1_EINT 0x0100 | ||
331 | #define WM8350_UV_DC6_EINT 0x0020 | ||
332 | #define WM8350_UV_DC5_EINT 0x0010 | ||
333 | #define WM8350_UV_DC4_EINT 0x0008 | ||
334 | #define WM8350_UV_DC3_EINT 0x0004 | ||
335 | #define WM8350_UV_DC2_EINT 0x0002 | ||
336 | #define WM8350_UV_DC1_EINT 0x0001 | ||
337 | |||
338 | /* | ||
339 | * R29 (0x1D) - Over Current Interrupt status | ||
340 | */ | ||
341 | #define WM8350_OC_LS_EINT 0x8000 | ||
342 | |||
343 | /* | ||
344 | * R30 (0x1E) - GPIO Interrupt Status | ||
345 | */ | ||
346 | #define WM8350_GP12_EINT 0x1000 | ||
347 | #define WM8350_GP11_EINT 0x0800 | ||
348 | #define WM8350_GP10_EINT 0x0400 | ||
349 | #define WM8350_GP9_EINT 0x0200 | ||
350 | #define WM8350_GP8_EINT 0x0100 | ||
351 | #define WM8350_GP7_EINT 0x0080 | ||
352 | #define WM8350_GP6_EINT 0x0040 | ||
353 | #define WM8350_GP5_EINT 0x0020 | ||
354 | #define WM8350_GP4_EINT 0x0010 | ||
355 | #define WM8350_GP3_EINT 0x0008 | ||
356 | #define WM8350_GP2_EINT 0x0004 | ||
357 | #define WM8350_GP1_EINT 0x0002 | ||
358 | #define WM8350_GP0_EINT 0x0001 | ||
359 | |||
360 | /* | ||
361 | * R31 (0x1F) - Comparator Interrupt Status | ||
362 | */ | ||
363 | #define WM8350_EXT_USB_FB_EINT 0x8000 | ||
364 | #define WM8350_EXT_WALL_FB_EINT 0x4000 | ||
365 | #define WM8350_EXT_BAT_FB_EINT 0x2000 | ||
366 | #define WM8350_CODEC_JCK_DET_L_EINT 0x0800 | ||
367 | #define WM8350_CODEC_JCK_DET_R_EINT 0x0400 | ||
368 | #define WM8350_CODEC_MICSCD_EINT 0x0200 | ||
369 | #define WM8350_CODEC_MICD_EINT 0x0100 | ||
370 | #define WM8350_WKUP_OFF_STATE_EINT 0x0040 | ||
371 | #define WM8350_WKUP_HIB_STATE_EINT 0x0020 | ||
372 | #define WM8350_WKUP_CONV_FAULT_EINT 0x0010 | ||
373 | #define WM8350_WKUP_WDOG_RST_EINT 0x0008 | ||
374 | #define WM8350_WKUP_GP_PWR_ON_EINT 0x0004 | ||
375 | #define WM8350_WKUP_ONKEY_EINT 0x0002 | ||
376 | #define WM8350_WKUP_GP_WAKEUP_EINT 0x0001 | ||
377 | |||
378 | /* | ||
379 | * R32 (0x20) - System Interrupts Mask | ||
380 | */ | ||
381 | #define WM8350_IM_OC_INT 0x2000 | ||
382 | #define WM8350_IM_UV_INT 0x1000 | ||
383 | #define WM8350_IM_PUTO_INT 0x0800 | ||
384 | #define WM8350_IM_SPARE_INT 0x0400 | ||
385 | #define WM8350_IM_CS_INT 0x0200 | ||
386 | #define WM8350_IM_EXT_INT 0x0100 | ||
387 | #define WM8350_IM_CODEC_INT 0x0080 | ||
388 | #define WM8350_IM_GP_INT 0x0040 | ||
389 | #define WM8350_IM_AUXADC_INT 0x0020 | ||
390 | #define WM8350_IM_RTC_INT 0x0010 | ||
391 | #define WM8350_IM_SYS_INT 0x0008 | ||
392 | #define WM8350_IM_CHG_INT 0x0004 | ||
393 | #define WM8350_IM_USB_INT 0x0002 | ||
394 | #define WM8350_IM_WKUP_INT 0x0001 | ||
395 | |||
396 | /* | ||
397 | * R33 (0x21) - Interrupt Status 1 Mask | ||
398 | */ | ||
399 | #define WM8350_IM_CHG_BAT_HOT_EINT 0x8000 | ||
400 | #define WM8350_IM_CHG_BAT_COLD_EINT 0x4000 | ||
401 | #define WM8350_IM_CHG_BAT_FAIL_EINT 0x2000 | ||
402 | #define WM8350_IM_CHG_TO_EINT 0x1000 | ||
403 | #define WM8350_IM_CHG_END_EINT 0x0800 | ||
404 | #define WM8350_IM_CHG_START_EINT 0x0400 | ||
405 | #define WM8350_IM_CHG_FAST_RDY_EINT 0x0200 | ||
406 | #define WM8350_IM_RTC_PER_EINT 0x0080 | ||
407 | #define WM8350_IM_RTC_SEC_EINT 0x0040 | ||
408 | #define WM8350_IM_RTC_ALM_EINT 0x0020 | ||
409 | #define WM8350_IM_CHG_VBATT_LT_3P9_EINT 0x0004 | ||
410 | #define WM8350_IM_CHG_VBATT_LT_3P1_EINT 0x0002 | ||
411 | #define WM8350_IM_CHG_VBATT_LT_2P85_EINT 0x0001 | ||
412 | |||
413 | /* | ||
414 | * R34 (0x22) - Interrupt Status 2 Mask | ||
415 | */ | ||
416 | #define WM8350_IM_SPARE2_EINT 0x8000 | ||
417 | #define WM8350_IM_SPARE1_EINT 0x4000 | ||
418 | #define WM8350_IM_CS1_EINT 0x2000 | ||
419 | #define WM8350_IM_CS2_EINT 0x1000 | ||
420 | #define WM8350_IM_USB_LIMIT_EINT 0x0400 | ||
421 | #define WM8350_IM_AUXADC_DATARDY_EINT 0x0100 | ||
422 | #define WM8350_IM_AUXADC_DCOMP4_EINT 0x0080 | ||
423 | #define WM8350_IM_AUXADC_DCOMP3_EINT 0x0040 | ||
424 | #define WM8350_IM_AUXADC_DCOMP2_EINT 0x0020 | ||
425 | #define WM8350_IM_AUXADC_DCOMP1_EINT 0x0010 | ||
426 | #define WM8350_IM_SYS_HYST_COMP_FAIL_EINT 0x0008 | ||
427 | #define WM8350_IM_SYS_CHIP_GT115_EINT 0x0004 | ||
428 | #define WM8350_IM_SYS_CHIP_GT140_EINT 0x0002 | ||
429 | #define WM8350_IM_SYS_WDOG_TO_EINT 0x0001 | ||
430 | |||
431 | /* | ||
432 | * R35 (0x23) - Power Up Interrupt Status Mask | ||
433 | */ | ||
434 | #define WM8350_IM_PUTO_LDO4_EINT 0x0800 | ||
435 | #define WM8350_IM_PUTO_LDO3_EINT 0x0400 | ||
436 | #define WM8350_IM_PUTO_LDO2_EINT 0x0200 | ||
437 | #define WM8350_IM_PUTO_LDO1_EINT 0x0100 | ||
438 | #define WM8350_IM_PUTO_DC6_EINT 0x0020 | ||
439 | #define WM8350_IM_PUTO_DC5_EINT 0x0010 | ||
440 | #define WM8350_IM_PUTO_DC4_EINT 0x0008 | ||
441 | #define WM8350_IM_PUTO_DC3_EINT 0x0004 | ||
442 | #define WM8350_IM_PUTO_DC2_EINT 0x0002 | ||
443 | #define WM8350_IM_PUTO_DC1_EINT 0x0001 | ||
444 | |||
445 | /* | ||
446 | * R36 (0x24) - Under Voltage Interrupt status Mask | ||
447 | */ | ||
448 | #define WM8350_IM_UV_LDO4_EINT 0x0800 | ||
449 | #define WM8350_IM_UV_LDO3_EINT 0x0400 | ||
450 | #define WM8350_IM_UV_LDO2_EINT 0x0200 | ||
451 | #define WM8350_IM_UV_LDO1_EINT 0x0100 | ||
452 | #define WM8350_IM_UV_DC6_EINT 0x0020 | ||
453 | #define WM8350_IM_UV_DC5_EINT 0x0010 | ||
454 | #define WM8350_IM_UV_DC4_EINT 0x0008 | ||
455 | #define WM8350_IM_UV_DC3_EINT 0x0004 | ||
456 | #define WM8350_IM_UV_DC2_EINT 0x0002 | ||
457 | #define WM8350_IM_UV_DC1_EINT 0x0001 | ||
458 | |||
459 | /* | ||
460 | * R37 (0x25) - Over Current Interrupt status Mask | ||
461 | */ | ||
462 | #define WM8350_IM_OC_LS_EINT 0x8000 | ||
463 | |||
464 | /* | ||
465 | * R38 (0x26) - GPIO Interrupt Status Mask | ||
466 | */ | ||
467 | #define WM8350_IM_GP12_EINT 0x1000 | ||
468 | #define WM8350_IM_GP11_EINT 0x0800 | ||
469 | #define WM8350_IM_GP10_EINT 0x0400 | ||
470 | #define WM8350_IM_GP9_EINT 0x0200 | ||
471 | #define WM8350_IM_GP8_EINT 0x0100 | ||
472 | #define WM8350_IM_GP7_EINT 0x0080 | ||
473 | #define WM8350_IM_GP6_EINT 0x0040 | ||
474 | #define WM8350_IM_GP5_EINT 0x0020 | ||
475 | #define WM8350_IM_GP4_EINT 0x0010 | ||
476 | #define WM8350_IM_GP3_EINT 0x0008 | ||
477 | #define WM8350_IM_GP2_EINT 0x0004 | ||
478 | #define WM8350_IM_GP1_EINT 0x0002 | ||
479 | #define WM8350_IM_GP0_EINT 0x0001 | ||
480 | |||
481 | /* | ||
482 | * R39 (0x27) - Comparator Interrupt Status Mask | ||
483 | */ | ||
484 | #define WM8350_IM_EXT_USB_FB_EINT 0x8000 | ||
485 | #define WM8350_IM_EXT_WALL_FB_EINT 0x4000 | ||
486 | #define WM8350_IM_EXT_BAT_FB_EINT 0x2000 | ||
487 | #define WM8350_IM_CODEC_JCK_DET_L_EINT 0x0800 | ||
488 | #define WM8350_IM_CODEC_JCK_DET_R_EINT 0x0400 | ||
489 | #define WM8350_IM_CODEC_MICSCD_EINT 0x0200 | ||
490 | #define WM8350_IM_CODEC_MICD_EINT 0x0100 | ||
491 | #define WM8350_IM_WKUP_OFF_STATE_EINT 0x0040 | ||
492 | #define WM8350_IM_WKUP_HIB_STATE_EINT 0x0020 | ||
493 | #define WM8350_IM_WKUP_CONV_FAULT_EINT 0x0010 | ||
494 | #define WM8350_IM_WKUP_WDOG_RST_EINT 0x0008 | ||
495 | #define WM8350_IM_WKUP_GP_PWR_ON_EINT 0x0004 | ||
496 | #define WM8350_IM_WKUP_ONKEY_EINT 0x0002 | ||
497 | #define WM8350_IM_WKUP_GP_WAKEUP_EINT 0x0001 | ||
498 | |||
499 | /* | ||
500 | * R220 (0xDC) - RAM BIST 1 | ||
501 | */ | ||
502 | #define WM8350_READ_STATUS 0x0800 | ||
503 | #define WM8350_TSTRAM_CLK 0x0100 | ||
504 | #define WM8350_TSTRAM_CLK_ENA 0x0080 | ||
505 | #define WM8350_STARTSEQ 0x0040 | ||
506 | #define WM8350_READ_SRC 0x0020 | ||
507 | #define WM8350_COUNT_DIR 0x0010 | ||
508 | #define WM8350_TSTRAM_MODE_MASK 0x000E | ||
509 | #define WM8350_TSTRAM_ENA 0x0001 | ||
510 | |||
511 | /* | ||
512 | * R225 (0xE1) - DCDC/LDO status | ||
513 | */ | ||
514 | #define WM8350_LS_STS 0x8000 | ||
515 | #define WM8350_LDO4_STS 0x0800 | ||
516 | #define WM8350_LDO3_STS 0x0400 | ||
517 | #define WM8350_LDO2_STS 0x0200 | ||
518 | #define WM8350_LDO1_STS 0x0100 | ||
519 | #define WM8350_DC6_STS 0x0020 | ||
520 | #define WM8350_DC5_STS 0x0010 | ||
521 | #define WM8350_DC4_STS 0x0008 | ||
522 | #define WM8350_DC3_STS 0x0004 | ||
523 | #define WM8350_DC2_STS 0x0002 | ||
524 | #define WM8350_DC1_STS 0x0001 | ||
525 | |||
526 | /* WM8350 wake up conditions */ | ||
527 | #define WM8350_IRQ_WKUP_OFF_STATE 43 | ||
528 | #define WM8350_IRQ_WKUP_HIB_STATE 44 | ||
529 | #define WM8350_IRQ_WKUP_CONV_FAULT 45 | ||
530 | #define WM8350_IRQ_WKUP_WDOG_RST 46 | ||
531 | #define WM8350_IRQ_WKUP_GP_PWR_ON 47 | ||
532 | #define WM8350_IRQ_WKUP_ONKEY 48 | ||
533 | #define WM8350_IRQ_WKUP_GP_WAKEUP 49 | ||
534 | |||
535 | /* wm8350 chip revisions */ | ||
536 | #define WM8350_REV_E 0x4 | ||
537 | #define WM8350_REV_F 0x5 | ||
538 | #define WM8350_REV_G 0x6 | ||
539 | |||
540 | #define WM8350_NUM_IRQ 63 | ||
541 | |||
542 | struct wm8350_reg_access { | ||
543 | u16 readable; /* Mask of readable bits */ | ||
544 | u16 writable; /* Mask of writable bits */ | ||
545 | u16 vol; /* Mask of volatile bits */ | ||
546 | }; | ||
547 | extern const struct wm8350_reg_access wm8350_reg_io_map[]; | ||
548 | extern const u16 wm8350_mode0_defaults[]; | ||
549 | extern const u16 wm8350_mode1_defaults[]; | ||
550 | extern const u16 wm8350_mode2_defaults[]; | ||
551 | extern const u16 wm8350_mode3_defaults[]; | ||
552 | |||
553 | struct wm8350; | ||
554 | |||
555 | struct wm8350_irq { | ||
556 | void (*handler) (struct wm8350 *, int, void *); | ||
557 | void *data; | ||
558 | }; | ||
559 | |||
560 | struct wm8350 { | ||
561 | int rev; /* chip revision */ | ||
562 | |||
563 | struct device *dev; | ||
564 | |||
565 | /* device IO */ | ||
566 | union { | ||
567 | struct i2c_client *i2c_client; | ||
568 | struct spi_device *spi_device; | ||
569 | }; | ||
570 | int (*read_dev)(struct wm8350 *wm8350, char reg, int size, void *dest); | ||
571 | int (*write_dev)(struct wm8350 *wm8350, char reg, int size, | ||
572 | void *src); | ||
573 | u16 *reg_cache; | ||
574 | |||
575 | /* Interrupt handling */ | ||
576 | struct work_struct irq_work; | ||
577 | struct mutex irq_mutex; /* IRQ table mutex */ | ||
578 | struct wm8350_irq irq[WM8350_NUM_IRQ]; | ||
579 | int chip_irq; | ||
580 | |||
581 | /* Client devices */ | ||
582 | struct wm8350_codec codec; | ||
583 | struct wm8350_gpio gpio; | ||
584 | struct wm8350_pmic pmic; | ||
585 | struct wm8350_power power; | ||
586 | struct wm8350_rtc rtc; | ||
587 | struct wm8350_wdt wdt; | ||
588 | }; | ||
589 | |||
590 | /** | ||
591 | * Data to be supplied by the platform to initialise the WM8350. | ||
592 | * | ||
593 | * @init: Function called during driver initialisation. Should be | ||
594 | * used by the platform to configure GPIO functions and similar. | ||
595 | */ | ||
596 | struct wm8350_platform_data { | ||
597 | int (*init)(struct wm8350 *wm8350); | ||
598 | }; | ||
599 | |||
600 | |||
601 | /* | ||
602 | * WM8350 device initialisation and exit. | ||
603 | */ | ||
604 | int wm8350_device_init(struct wm8350 *wm8350, int irq, | ||
605 | struct wm8350_platform_data *pdata); | ||
606 | void wm8350_device_exit(struct wm8350 *wm8350); | ||
607 | |||
608 | /* | ||
609 | * WM8350 device IO | ||
610 | */ | ||
611 | int wm8350_clear_bits(struct wm8350 *wm8350, u16 reg, u16 mask); | ||
612 | int wm8350_set_bits(struct wm8350 *wm8350, u16 reg, u16 mask); | ||
613 | u16 wm8350_reg_read(struct wm8350 *wm8350, int reg); | ||
614 | int wm8350_reg_write(struct wm8350 *wm8350, int reg, u16 val); | ||
615 | int wm8350_reg_lock(struct wm8350 *wm8350); | ||
616 | int wm8350_reg_unlock(struct wm8350 *wm8350); | ||
617 | int wm8350_block_read(struct wm8350 *wm8350, int reg, int size, u16 *dest); | ||
618 | int wm8350_block_write(struct wm8350 *wm8350, int reg, int size, u16 *src); | ||
619 | |||
620 | /* | ||
621 | * WM8350 internal interrupts | ||
622 | */ | ||
623 | int wm8350_register_irq(struct wm8350 *wm8350, int irq, | ||
624 | void (*handler) (struct wm8350 *, int, void *), | ||
625 | void *data); | ||
626 | int wm8350_free_irq(struct wm8350 *wm8350, int irq); | ||
627 | int wm8350_mask_irq(struct wm8350 *wm8350, int irq); | ||
628 | int wm8350_unmask_irq(struct wm8350 *wm8350, int irq); | ||
629 | |||
630 | |||
631 | #endif | ||
diff --git a/include/linux/mfd/wm8350/gpio.h b/include/linux/mfd/wm8350/gpio.h new file mode 100644 index 000000000000..ed91e8f5d298 --- /dev/null +++ b/include/linux/mfd/wm8350/gpio.h | |||
@@ -0,0 +1,342 @@ | |||
1 | /* | ||
2 | * gpio.h -- GPIO Driver for Wolfson WM8350 PMIC | ||
3 | * | ||
4 | * Copyright 2007 Wolfson Microelectronics PLC | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License as published by the | ||
8 | * Free Software Foundation; either version 2 of the License, or (at your | ||
9 | * option) any later version. | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | #ifndef __LINUX_MFD_WM8350_GPIO_H_ | ||
14 | #define __LINUX_MFD_WM8350_GPIO_H_ | ||
15 | |||
16 | #include <linux/platform_device.h> | ||
17 | |||
18 | /* | ||
19 | * GPIO Registers. | ||
20 | */ | ||
21 | #define WM8350_GPIO_DEBOUNCE 0x80 | ||
22 | #define WM8350_GPIO_PIN_PULL_UP_CONTROL 0x81 | ||
23 | #define WM8350_GPIO_PULL_DOWN_CONTROL 0x82 | ||
24 | #define WM8350_GPIO_INT_MODE 0x83 | ||
25 | #define WM8350_GPIO_CONTROL 0x85 | ||
26 | #define WM8350_GPIO_CONFIGURATION_I_O 0x86 | ||
27 | #define WM8350_GPIO_PIN_POLARITY_TYPE 0x87 | ||
28 | #define WM8350_GPIO_FUNCTION_SELECT_1 0x8C | ||
29 | #define WM8350_GPIO_FUNCTION_SELECT_2 0x8D | ||
30 | #define WM8350_GPIO_FUNCTION_SELECT_3 0x8E | ||
31 | #define WM8350_GPIO_FUNCTION_SELECT_4 0x8F | ||
32 | |||
33 | /* | ||
34 | * GPIO Functions | ||
35 | */ | ||
36 | #define WM8350_GPIO0_GPIO_IN 0x0 | ||
37 | #define WM8350_GPIO0_GPIO_OUT 0x0 | ||
38 | #define WM8350_GPIO0_PWR_ON_IN 0x1 | ||
39 | #define WM8350_GPIO0_PWR_ON_OUT 0x1 | ||
40 | #define WM8350_GPIO0_LDO_EN_IN 0x2 | ||
41 | #define WM8350_GPIO0_VRTC_OUT 0x2 | ||
42 | #define WM8350_GPIO0_LPWR1_IN 0x3 | ||
43 | #define WM8350_GPIO0_POR_B_OUT 0x3 | ||
44 | |||
45 | #define WM8350_GPIO1_GPIO_IN 0x0 | ||
46 | #define WM8350_GPIO1_GPIO_OUT 0x0 | ||
47 | #define WM8350_GPIO1_PWR_ON_IN 0x1 | ||
48 | #define WM8350_GPIO1_DO_CONF_OUT 0x1 | ||
49 | #define WM8350_GPIO1_LDO_EN_IN 0x2 | ||
50 | #define WM8350_GPIO1_RESET_OUT 0x2 | ||
51 | #define WM8350_GPIO1_LPWR2_IN 0x3 | ||
52 | #define WM8350_GPIO1_MEMRST_OUT 0x3 | ||
53 | |||
54 | #define WM8350_GPIO2_GPIO_IN 0x0 | ||
55 | #define WM8350_GPIO2_GPIO_OUT 0x0 | ||
56 | #define WM8350_GPIO2_PWR_ON_IN 0x1 | ||
57 | #define WM8350_GPIO2_PWR_ON_OUT 0x1 | ||
58 | #define WM8350_GPIO2_WAKE_UP_IN 0x2 | ||
59 | #define WM8350_GPIO2_VRTC_OUT 0x2 | ||
60 | #define WM8350_GPIO2_32KHZ_IN 0x3 | ||
61 | #define WM8350_GPIO2_32KHZ_OUT 0x3 | ||
62 | |||
63 | #define WM8350_GPIO3_GPIO_IN 0x0 | ||
64 | #define WM8350_GPIO3_GPIO_OUT 0x0 | ||
65 | #define WM8350_GPIO3_PWR_ON_IN 0x1 | ||
66 | #define WM8350_GPIO3_P_CLK_OUT 0x1 | ||
67 | #define WM8350_GPIO3_LDO_EN_IN 0x2 | ||
68 | #define WM8350_GPIO3_VRTC_OUT 0x2 | ||
69 | #define WM8350_GPIO3_PWR_OFF_IN 0x3 | ||
70 | #define WM8350_GPIO3_32KHZ_OUT 0x3 | ||
71 | |||
72 | #define WM8350_GPIO4_GPIO_IN 0x0 | ||
73 | #define WM8350_GPIO4_GPIO_OUT 0x0 | ||
74 | #define WM8350_GPIO4_MR_IN 0x1 | ||
75 | #define WM8350_GPIO4_MEM_RST_OUT 0x1 | ||
76 | #define WM8350_GPIO4_FLASH_IN 0x2 | ||
77 | #define WM8350_GPIO4_ADA_OUT 0x2 | ||
78 | #define WM8350_GPIO4_HIBERNATE_IN 0x3 | ||
79 | #define WM8350_GPIO4_FLASH_OUT 0x3 | ||
80 | #define WM8350_GPIO4_MICDET_OUT 0x4 | ||
81 | #define WM8350_GPIO4_MICSHT_OUT 0x5 | ||
82 | |||
83 | #define WM8350_GPIO5_GPIO_IN 0x0 | ||
84 | #define WM8350_GPIO5_GPIO_OUT 0x0 | ||
85 | #define WM8350_GPIO5_LPWR1_IN 0x1 | ||
86 | #define WM8350_GPIO5_P_CLK_OUT 0x1 | ||
87 | #define WM8350_GPIO5_ADCLRCLK_IN 0x2 | ||
88 | #define WM8350_GPIO5_ADCLRCLK_OUT 0x2 | ||
89 | #define WM8350_GPIO5_HIBERNATE_IN 0x3 | ||
90 | #define WM8350_GPIO5_32KHZ_OUT 0x3 | ||
91 | #define WM8350_GPIO5_MICDET_OUT 0x4 | ||
92 | #define WM8350_GPIO5_MICSHT_OUT 0x5 | ||
93 | #define WM8350_GPIO5_ADA_OUT 0x6 | ||
94 | #define WM8350_GPIO5_OPCLK_OUT 0x7 | ||
95 | |||
96 | #define WM8350_GPIO6_GPIO_IN 0x0 | ||
97 | #define WM8350_GPIO6_GPIO_OUT 0x0 | ||
98 | #define WM8350_GPIO6_LPWR2_IN 0x1 | ||
99 | #define WM8350_GPIO6_MEMRST_OUT 0x1 | ||
100 | #define WM8350_GPIO6_FLASH_IN 0x2 | ||
101 | #define WM8350_GPIO6_ADA_OUT 0x2 | ||
102 | #define WM8350_GPIO6_HIBERNATE_IN 0x3 | ||
103 | #define WM8350_GPIO6_RTC_OUT 0x3 | ||
104 | #define WM8350_GPIO6_MICDET_OUT 0x4 | ||
105 | #define WM8350_GPIO6_MICSHT_OUT 0x5 | ||
106 | #define WM8350_GPIO6_ADCLRCLKB_OUT 0x6 | ||
107 | #define WM8350_GPIO6_SDOUT_OUT 0x7 | ||
108 | |||
109 | #define WM8350_GPIO7_GPIO_IN 0x0 | ||
110 | #define WM8350_GPIO7_GPIO_OUT 0x0 | ||
111 | #define WM8350_GPIO7_LPWR3_IN 0x1 | ||
112 | #define WM8350_GPIO7_P_CLK_OUT 0x1 | ||
113 | #define WM8350_GPIO7_MASK_IN 0x2 | ||
114 | #define WM8350_GPIO7_VCC_FAULT_OUT 0x2 | ||
115 | #define WM8350_GPIO7_HIBERNATE_IN 0x3 | ||
116 | #define WM8350_GPIO7_BATT_FAULT_OUT 0x3 | ||
117 | #define WM8350_GPIO7_MICDET_OUT 0x4 | ||
118 | #define WM8350_GPIO7_MICSHT_OUT 0x5 | ||
119 | #define WM8350_GPIO7_ADA_OUT 0x6 | ||
120 | #define WM8350_GPIO7_CSB_IN 0x7 | ||
121 | |||
122 | #define WM8350_GPIO8_GPIO_IN 0x0 | ||
123 | #define WM8350_GPIO8_GPIO_OUT 0x0 | ||
124 | #define WM8350_GPIO8_MR_IN 0x1 | ||
125 | #define WM8350_GPIO8_VCC_FAULT_OUT 0x1 | ||
126 | #define WM8350_GPIO8_ADCBCLK_IN 0x2 | ||
127 | #define WM8350_GPIO8_ADCBCLK_OUT 0x2 | ||
128 | #define WM8350_GPIO8_PWR_OFF_IN 0x3 | ||
129 | #define WM8350_GPIO8_BATT_FAULT_OUT 0x3 | ||
130 | #define WM8350_GPIO8_ALTSCL_IN 0xf | ||
131 | |||
132 | #define WM8350_GPIO9_GPIO_IN 0x0 | ||
133 | #define WM8350_GPIO9_GPIO_OUT 0x0 | ||
134 | #define WM8350_GPIO9_HEARTBEAT_IN 0x1 | ||
135 | #define WM8350_GPIO9_VCC_FAULT_OUT 0x1 | ||
136 | #define WM8350_GPIO9_MASK_IN 0x2 | ||
137 | #define WM8350_GPIO9_LINE_GT_BATT_OUT 0x2 | ||
138 | #define WM8350_GPIO9_PWR_OFF_IN 0x3 | ||
139 | #define WM8350_GPIO9_BATT_FAULT_OUT 0x3 | ||
140 | #define WM8350_GPIO9_ALTSDA_OUT 0xf | ||
141 | |||
142 | #define WM8350_GPIO10_GPIO_IN 0x0 | ||
143 | #define WM8350_GPIO10_GPIO_OUT 0x0 | ||
144 | #define WM8350_GPIO10_ISINKC_OUT 0x1 | ||
145 | #define WM8350_GPIO10_PWR_OFF_IN 0x2 | ||
146 | #define WM8350_GPIO10_LINE_GT_BATT_OUT 0x2 | ||
147 | #define WM8350_GPIO10_CHD_IND_IN 0x3 | ||
148 | |||
149 | #define WM8350_GPIO11_GPIO_IN 0x0 | ||
150 | #define WM8350_GPIO11_GPIO_OUT 0x0 | ||
151 | #define WM8350_GPIO11_ISINKD_OUT 0x1 | ||
152 | #define WM8350_GPIO11_WAKEUP_IN 0x2 | ||
153 | #define WM8350_GPIO11_LINE_GT_BATT_OUT 0x2 | ||
154 | #define WM8350_GPIO11_CHD_IND_IN 0x3 | ||
155 | |||
156 | #define WM8350_GPIO12_GPIO_IN 0x0 | ||
157 | #define WM8350_GPIO12_GPIO_OUT 0x0 | ||
158 | #define WM8350_GPIO12_ISINKE_OUT 0x1 | ||
159 | #define WM8350_GPIO12_LINE_GT_BATT_OUT 0x2 | ||
160 | #define WM8350_GPIO12_LINE_EN_OUT 0x3 | ||
161 | #define WM8350_GPIO12_32KHZ_OUT 0x4 | ||
162 | |||
163 | #define WM8350_GPIO_DIR_IN 0 | ||
164 | #define WM8350_GPIO_DIR_OUT 1 | ||
165 | #define WM8350_GPIO_ACTIVE_LOW 0 | ||
166 | #define WM8350_GPIO_ACTIVE_HIGH 1 | ||
167 | #define WM8350_GPIO_PULL_NONE 0 | ||
168 | #define WM8350_GPIO_PULL_UP 1 | ||
169 | #define WM8350_GPIO_PULL_DOWN 2 | ||
170 | #define WM8350_GPIO_INVERT_OFF 0 | ||
171 | #define WM8350_GPIO_INVERT_ON 1 | ||
172 | #define WM8350_GPIO_DEBOUNCE_OFF 0 | ||
173 | #define WM8350_GPIO_DEBOUNCE_ON 1 | ||
174 | |||
175 | /* | ||
176 | * R128 (0x80) - GPIO Debounce | ||
177 | */ | ||
178 | #define WM8350_GP12_DB 0x1000 | ||
179 | #define WM8350_GP11_DB 0x0800 | ||
180 | #define WM8350_GP10_DB 0x0400 | ||
181 | #define WM8350_GP9_DB 0x0200 | ||
182 | #define WM8350_GP8_DB 0x0100 | ||
183 | #define WM8350_GP7_DB 0x0080 | ||
184 | #define WM8350_GP6_DB 0x0040 | ||
185 | #define WM8350_GP5_DB 0x0020 | ||
186 | #define WM8350_GP4_DB 0x0010 | ||
187 | #define WM8350_GP3_DB 0x0008 | ||
188 | #define WM8350_GP2_DB 0x0004 | ||
189 | #define WM8350_GP1_DB 0x0002 | ||
190 | #define WM8350_GP0_DB 0x0001 | ||
191 | |||
192 | /* | ||
193 | * R129 (0x81) - GPIO Pin pull up Control | ||
194 | */ | ||
195 | #define WM8350_GP12_PU 0x1000 | ||
196 | #define WM8350_GP11_PU 0x0800 | ||
197 | #define WM8350_GP10_PU 0x0400 | ||
198 | #define WM8350_GP9_PU 0x0200 | ||
199 | #define WM8350_GP8_PU 0x0100 | ||
200 | #define WM8350_GP7_PU 0x0080 | ||
201 | #define WM8350_GP6_PU 0x0040 | ||
202 | #define WM8350_GP5_PU 0x0020 | ||
203 | #define WM8350_GP4_PU 0x0010 | ||
204 | #define WM8350_GP3_PU 0x0008 | ||
205 | #define WM8350_GP2_PU 0x0004 | ||
206 | #define WM8350_GP1_PU 0x0002 | ||
207 | #define WM8350_GP0_PU 0x0001 | ||
208 | |||
209 | /* | ||
210 | * R130 (0x82) - GPIO Pull down Control | ||
211 | */ | ||
212 | #define WM8350_GP12_PD 0x1000 | ||
213 | #define WM8350_GP11_PD 0x0800 | ||
214 | #define WM8350_GP10_PD 0x0400 | ||
215 | #define WM8350_GP9_PD 0x0200 | ||
216 | #define WM8350_GP8_PD 0x0100 | ||
217 | #define WM8350_GP7_PD 0x0080 | ||
218 | #define WM8350_GP6_PD 0x0040 | ||
219 | #define WM8350_GP5_PD 0x0020 | ||
220 | #define WM8350_GP4_PD 0x0010 | ||
221 | #define WM8350_GP3_PD 0x0008 | ||
222 | #define WM8350_GP2_PD 0x0004 | ||
223 | #define WM8350_GP1_PD 0x0002 | ||
224 | #define WM8350_GP0_PD 0x0001 | ||
225 | |||
226 | /* | ||
227 | * R131 (0x83) - GPIO Interrupt Mode | ||
228 | */ | ||
229 | #define WM8350_GP12_INTMODE 0x1000 | ||
230 | #define WM8350_GP11_INTMODE 0x0800 | ||
231 | #define WM8350_GP10_INTMODE 0x0400 | ||
232 | #define WM8350_GP9_INTMODE 0x0200 | ||
233 | #define WM8350_GP8_INTMODE 0x0100 | ||
234 | #define WM8350_GP7_INTMODE 0x0080 | ||
235 | #define WM8350_GP6_INTMODE 0x0040 | ||
236 | #define WM8350_GP5_INTMODE 0x0020 | ||
237 | #define WM8350_GP4_INTMODE 0x0010 | ||
238 | #define WM8350_GP3_INTMODE 0x0008 | ||
239 | #define WM8350_GP2_INTMODE 0x0004 | ||
240 | #define WM8350_GP1_INTMODE 0x0002 | ||
241 | #define WM8350_GP0_INTMODE 0x0001 | ||
242 | |||
243 | /* | ||
244 | * R133 (0x85) - GPIO Control | ||
245 | */ | ||
246 | #define WM8350_GP_DBTIME_MASK 0x00C0 | ||
247 | |||
248 | /* | ||
249 | * R134 (0x86) - GPIO Configuration (i/o) | ||
250 | */ | ||
251 | #define WM8350_GP12_DIR 0x1000 | ||
252 | #define WM8350_GP11_DIR 0x0800 | ||
253 | #define WM8350_GP10_DIR 0x0400 | ||
254 | #define WM8350_GP9_DIR 0x0200 | ||
255 | #define WM8350_GP8_DIR 0x0100 | ||
256 | #define WM8350_GP7_DIR 0x0080 | ||
257 | #define WM8350_GP6_DIR 0x0040 | ||
258 | #define WM8350_GP5_DIR 0x0020 | ||
259 | #define WM8350_GP4_DIR 0x0010 | ||
260 | #define WM8350_GP3_DIR 0x0008 | ||
261 | #define WM8350_GP2_DIR 0x0004 | ||
262 | #define WM8350_GP1_DIR 0x0002 | ||
263 | #define WM8350_GP0_DIR 0x0001 | ||
264 | |||
265 | /* | ||
266 | * R135 (0x87) - GPIO Pin Polarity / Type | ||
267 | */ | ||
268 | #define WM8350_GP12_CFG 0x1000 | ||
269 | #define WM8350_GP11_CFG 0x0800 | ||
270 | #define WM8350_GP10_CFG 0x0400 | ||
271 | #define WM8350_GP9_CFG 0x0200 | ||
272 | #define WM8350_GP8_CFG 0x0100 | ||
273 | #define WM8350_GP7_CFG 0x0080 | ||
274 | #define WM8350_GP6_CFG 0x0040 | ||
275 | #define WM8350_GP5_CFG 0x0020 | ||
276 | #define WM8350_GP4_CFG 0x0010 | ||
277 | #define WM8350_GP3_CFG 0x0008 | ||
278 | #define WM8350_GP2_CFG 0x0004 | ||
279 | #define WM8350_GP1_CFG 0x0002 | ||
280 | #define WM8350_GP0_CFG 0x0001 | ||
281 | |||
282 | /* | ||
283 | * R140 (0x8C) - GPIO Function Select 1 | ||
284 | */ | ||
285 | #define WM8350_GP3_FN_MASK 0xF000 | ||
286 | #define WM8350_GP2_FN_MASK 0x0F00 | ||
287 | #define WM8350_GP1_FN_MASK 0x00F0 | ||
288 | #define WM8350_GP0_FN_MASK 0x000F | ||
289 | |||
290 | /* | ||
291 | * R141 (0x8D) - GPIO Function Select 2 | ||
292 | */ | ||
293 | #define WM8350_GP7_FN_MASK 0xF000 | ||
294 | #define WM8350_GP6_FN_MASK 0x0F00 | ||
295 | #define WM8350_GP5_FN_MASK 0x00F0 | ||
296 | #define WM8350_GP4_FN_MASK 0x000F | ||
297 | |||
298 | /* | ||
299 | * R142 (0x8E) - GPIO Function Select 3 | ||
300 | */ | ||
301 | #define WM8350_GP11_FN_MASK 0xF000 | ||
302 | #define WM8350_GP10_FN_MASK 0x0F00 | ||
303 | #define WM8350_GP9_FN_MASK 0x00F0 | ||
304 | #define WM8350_GP8_FN_MASK 0x000F | ||
305 | |||
306 | /* | ||
307 | * R143 (0x8F) - GPIO Function Select 4 | ||
308 | */ | ||
309 | #define WM8350_GP12_FN_MASK 0x000F | ||
310 | |||
311 | /* | ||
312 | * R230 (0xE6) - GPIO Pin Status | ||
313 | */ | ||
314 | #define WM8350_GP12_LVL 0x1000 | ||
315 | #define WM8350_GP11_LVL 0x0800 | ||
316 | #define WM8350_GP10_LVL 0x0400 | ||
317 | #define WM8350_GP9_LVL 0x0200 | ||
318 | #define WM8350_GP8_LVL 0x0100 | ||
319 | #define WM8350_GP7_LVL 0x0080 | ||
320 | #define WM8350_GP6_LVL 0x0040 | ||
321 | #define WM8350_GP5_LVL 0x0020 | ||
322 | #define WM8350_GP4_LVL 0x0010 | ||
323 | #define WM8350_GP3_LVL 0x0008 | ||
324 | #define WM8350_GP2_LVL 0x0004 | ||
325 | #define WM8350_GP1_LVL 0x0002 | ||
326 | #define WM8350_GP0_LVL 0x0001 | ||
327 | |||
328 | struct wm8350; | ||
329 | |||
330 | int wm8350_gpio_config(struct wm8350 *wm8350, int gpio, int dir, int func, | ||
331 | int pol, int pull, int invert, int debounce); | ||
332 | |||
333 | struct wm8350_gpio { | ||
334 | struct platform_device *pdev; | ||
335 | }; | ||
336 | |||
337 | /* | ||
338 | * GPIO Interrupts | ||
339 | */ | ||
340 | #define WM8350_IRQ_GPIO(x) (50 + x) | ||
341 | |||
342 | #endif | ||
diff --git a/include/linux/mfd/wm8350/pmic.h b/include/linux/mfd/wm8350/pmic.h new file mode 100644 index 000000000000..69b69e07f62f --- /dev/null +++ b/include/linux/mfd/wm8350/pmic.h | |||
@@ -0,0 +1,741 @@ | |||
1 | /* | ||
2 | * pmic.h -- Power Managment Driver for Wolfson WM8350 PMIC | ||
3 | * | ||
4 | * Copyright 2007 Wolfson Microelectronics PLC | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License as published by the | ||
8 | * Free Software Foundation; either version 2 of the License, or (at your | ||
9 | * option) any later version. | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | #ifndef __LINUX_MFD_WM8350_PMIC_H | ||
14 | #define __LINUX_MFD_WM8350_PMIC_H | ||
15 | |||
16 | /* | ||
17 | * Register values. | ||
18 | */ | ||
19 | |||
20 | #define WM8350_CURRENT_SINK_DRIVER_A 0xAC | ||
21 | #define WM8350_CSA_FLASH_CONTROL 0xAD | ||
22 | #define WM8350_CURRENT_SINK_DRIVER_B 0xAE | ||
23 | #define WM8350_CSB_FLASH_CONTROL 0xAF | ||
24 | #define WM8350_DCDC_LDO_REQUESTED 0xB0 | ||
25 | #define WM8350_DCDC_ACTIVE_OPTIONS 0xB1 | ||
26 | #define WM8350_DCDC_SLEEP_OPTIONS 0xB2 | ||
27 | #define WM8350_POWER_CHECK_COMPARATOR 0xB3 | ||
28 | #define WM8350_DCDC1_CONTROL 0xB4 | ||
29 | #define WM8350_DCDC1_TIMEOUTS 0xB5 | ||
30 | #define WM8350_DCDC1_LOW_POWER 0xB6 | ||
31 | #define WM8350_DCDC2_CONTROL 0xB7 | ||
32 | #define WM8350_DCDC2_TIMEOUTS 0xB8 | ||
33 | #define WM8350_DCDC3_CONTROL 0xBA | ||
34 | #define WM8350_DCDC3_TIMEOUTS 0xBB | ||
35 | #define WM8350_DCDC3_LOW_POWER 0xBC | ||
36 | #define WM8350_DCDC4_CONTROL 0xBD | ||
37 | #define WM8350_DCDC4_TIMEOUTS 0xBE | ||
38 | #define WM8350_DCDC4_LOW_POWER 0xBF | ||
39 | #define WM8350_DCDC5_CONTROL 0xC0 | ||
40 | #define WM8350_DCDC5_TIMEOUTS 0xC1 | ||
41 | #define WM8350_DCDC6_CONTROL 0xC3 | ||
42 | #define WM8350_DCDC6_TIMEOUTS 0xC4 | ||
43 | #define WM8350_DCDC6_LOW_POWER 0xC5 | ||
44 | #define WM8350_LIMIT_SWITCH_CONTROL 0xC7 | ||
45 | #define WM8350_LDO1_CONTROL 0xC8 | ||
46 | #define WM8350_LDO1_TIMEOUTS 0xC9 | ||
47 | #define WM8350_LDO1_LOW_POWER 0xCA | ||
48 | #define WM8350_LDO2_CONTROL 0xCB | ||
49 | #define WM8350_LDO2_TIMEOUTS 0xCC | ||
50 | #define WM8350_LDO2_LOW_POWER 0xCD | ||
51 | #define WM8350_LDO3_CONTROL 0xCE | ||
52 | #define WM8350_LDO3_TIMEOUTS 0xCF | ||
53 | #define WM8350_LDO3_LOW_POWER 0xD0 | ||
54 | #define WM8350_LDO4_CONTROL 0xD1 | ||
55 | #define WM8350_LDO4_TIMEOUTS 0xD2 | ||
56 | #define WM8350_LDO4_LOW_POWER 0xD3 | ||
57 | #define WM8350_VCC_FAULT_MASKS 0xD7 | ||
58 | #define WM8350_MAIN_BANDGAP_CONTROL 0xD8 | ||
59 | #define WM8350_OSC_CONTROL 0xD9 | ||
60 | #define WM8350_RTC_TICK_CONTROL 0xDA | ||
61 | #define WM8350_SECURITY 0xDB | ||
62 | #define WM8350_RAM_BIST_1 0xDC | ||
63 | #define WM8350_DCDC_LDO_STATUS 0xE1 | ||
64 | #define WM8350_GPIO_PIN_STATUS 0xE6 | ||
65 | |||
66 | #define WM8350_DCDC1_FORCE_PWM 0xF8 | ||
67 | #define WM8350_DCDC3_FORCE_PWM 0xFA | ||
68 | #define WM8350_DCDC4_FORCE_PWM 0xFB | ||
69 | #define WM8350_DCDC6_FORCE_PWM 0xFD | ||
70 | |||
71 | /* | ||
72 | * R172 (0xAC) - Current Sink Driver A | ||
73 | */ | ||
74 | #define WM8350_CS1_HIB_MODE 0x1000 | ||
75 | #define WM8350_CS1_HIB_MODE_MASK 0x1000 | ||
76 | #define WM8350_CS1_HIB_MODE_SHIFT 12 | ||
77 | #define WM8350_CS1_ISEL_MASK 0x003F | ||
78 | #define WM8350_CS1_ISEL_SHIFT 0 | ||
79 | |||
80 | /* Bit values for R172 (0xAC) */ | ||
81 | #define WM8350_CS1_HIB_MODE_DISABLE 0 | ||
82 | #define WM8350_CS1_HIB_MODE_LEAVE 1 | ||
83 | |||
84 | #define WM8350_CS1_ISEL_220M 0x3F | ||
85 | |||
86 | /* | ||
87 | * R173 (0xAD) - CSA Flash control | ||
88 | */ | ||
89 | #define WM8350_CS1_FLASH_MODE 0x8000 | ||
90 | #define WM8350_CS1_TRIGSRC 0x4000 | ||
91 | #define WM8350_CS1_DRIVE 0x2000 | ||
92 | #define WM8350_CS1_FLASH_DUR_MASK 0x0300 | ||
93 | #define WM8350_CS1_OFF_RAMP_MASK 0x0030 | ||
94 | #define WM8350_CS1_ON_RAMP_MASK 0x0003 | ||
95 | |||
96 | /* | ||
97 | * R174 (0xAE) - Current Sink Driver B | ||
98 | */ | ||
99 | #define WM8350_CS2_HIB_MODE 0x1000 | ||
100 | #define WM8350_CS2_ISEL_MASK 0x003F | ||
101 | |||
102 | /* | ||
103 | * R175 (0xAF) - CSB Flash control | ||
104 | */ | ||
105 | #define WM8350_CS2_FLASH_MODE 0x8000 | ||
106 | #define WM8350_CS2_TRIGSRC 0x4000 | ||
107 | #define WM8350_CS2_DRIVE 0x2000 | ||
108 | #define WM8350_CS2_FLASH_DUR_MASK 0x0300 | ||
109 | #define WM8350_CS2_OFF_RAMP_MASK 0x0030 | ||
110 | #define WM8350_CS2_ON_RAMP_MASK 0x0003 | ||
111 | |||
112 | /* | ||
113 | * R176 (0xB0) - DCDC/LDO requested | ||
114 | */ | ||
115 | #define WM8350_LS_ENA 0x8000 | ||
116 | #define WM8350_LDO4_ENA 0x0800 | ||
117 | #define WM8350_LDO3_ENA 0x0400 | ||
118 | #define WM8350_LDO2_ENA 0x0200 | ||
119 | #define WM8350_LDO1_ENA 0x0100 | ||
120 | #define WM8350_DC6_ENA 0x0020 | ||
121 | #define WM8350_DC5_ENA 0x0010 | ||
122 | #define WM8350_DC4_ENA 0x0008 | ||
123 | #define WM8350_DC3_ENA 0x0004 | ||
124 | #define WM8350_DC2_ENA 0x0002 | ||
125 | #define WM8350_DC1_ENA 0x0001 | ||
126 | |||
127 | /* | ||
128 | * R177 (0xB1) - DCDC Active options | ||
129 | */ | ||
130 | #define WM8350_PUTO_MASK 0x3000 | ||
131 | #define WM8350_PWRUP_DELAY_MASK 0x0300 | ||
132 | #define WM8350_DC6_ACTIVE 0x0020 | ||
133 | #define WM8350_DC4_ACTIVE 0x0008 | ||
134 | #define WM8350_DC3_ACTIVE 0x0004 | ||
135 | #define WM8350_DC1_ACTIVE 0x0001 | ||
136 | |||
137 | /* | ||
138 | * R178 (0xB2) - DCDC Sleep options | ||
139 | */ | ||
140 | #define WM8350_DC6_SLEEP 0x0020 | ||
141 | #define WM8350_DC4_SLEEP 0x0008 | ||
142 | #define WM8350_DC3_SLEEP 0x0004 | ||
143 | #define WM8350_DC1_SLEEP 0x0001 | ||
144 | |||
145 | /* | ||
146 | * R179 (0xB3) - Power-check comparator | ||
147 | */ | ||
148 | #define WM8350_PCCMP_ERRACT 0x4000 | ||
149 | #define WM8350_PCCMP_RAIL 0x0100 | ||
150 | #define WM8350_PCCMP_OFF_THR_MASK 0x0070 | ||
151 | #define WM8350_PCCMP_ON_THR_MASK 0x0007 | ||
152 | |||
153 | /* | ||
154 | * R180 (0xB4) - DCDC1 Control | ||
155 | */ | ||
156 | #define WM8350_DC1_OPFLT 0x0400 | ||
157 | #define WM8350_DC1_VSEL_MASK 0x007F | ||
158 | #define WM8350_DC1_VSEL_SHIFT 0 | ||
159 | |||
160 | /* | ||
161 | * R181 (0xB5) - DCDC1 Timeouts | ||
162 | */ | ||
163 | #define WM8350_DC1_ERRACT_MASK 0xC000 | ||
164 | #define WM8350_DC1_ERRACT_SHIFT 14 | ||
165 | #define WM8350_DC1_ENSLOT_MASK 0x3C00 | ||
166 | #define WM8350_DC1_ENSLOT_SHIFT 10 | ||
167 | #define WM8350_DC1_SDSLOT_MASK 0x03C0 | ||
168 | #define WM8350_DC1_UVTO_MASK 0x0030 | ||
169 | #define WM8350_DC1_SDSLOT_SHIFT 6 | ||
170 | |||
171 | /* Bit values for R181 (0xB5) */ | ||
172 | #define WM8350_DC1_ERRACT_NONE 0 | ||
173 | #define WM8350_DC1_ERRACT_SHUTDOWN_CONV 1 | ||
174 | #define WM8350_DC1_ERRACT_SHUTDOWN_SYS 2 | ||
175 | |||
176 | /* | ||
177 | * R182 (0xB6) - DCDC1 Low Power | ||
178 | */ | ||
179 | #define WM8350_DC1_HIB_MODE_MASK 0x7000 | ||
180 | #define WM8350_DC1_HIB_TRIG_MASK 0x0300 | ||
181 | #define WM8350_DC1_VIMG_MASK 0x007F | ||
182 | |||
183 | /* | ||
184 | * R183 (0xB7) - DCDC2 Control | ||
185 | */ | ||
186 | #define WM8350_DC2_MODE 0x4000 | ||
187 | #define WM8350_DC2_MODE_MASK 0x4000 | ||
188 | #define WM8350_DC2_MODE_SHIFT 14 | ||
189 | #define WM8350_DC2_HIB_MODE 0x1000 | ||
190 | #define WM8350_DC2_HIB_MODE_MASK 0x1000 | ||
191 | #define WM8350_DC2_HIB_MODE_SHIFT 12 | ||
192 | #define WM8350_DC2_HIB_TRIG_MASK 0x0300 | ||
193 | #define WM8350_DC2_HIB_TRIG_SHIFT 8 | ||
194 | #define WM8350_DC2_ILIM 0x0040 | ||
195 | #define WM8350_DC2_ILIM_MASK 0x0040 | ||
196 | #define WM8350_DC2_ILIM_SHIFT 6 | ||
197 | #define WM8350_DC2_RMP_MASK 0x0018 | ||
198 | #define WM8350_DC2_RMP_SHIFT 3 | ||
199 | #define WM8350_DC2_FBSRC_MASK 0x0003 | ||
200 | #define WM8350_DC2_FBSRC_SHIFT 0 | ||
201 | |||
202 | /* Bit values for R183 (0xB7) */ | ||
203 | #define WM8350_DC2_MODE_BOOST 0 | ||
204 | #define WM8350_DC2_MODE_SWITCH 1 | ||
205 | |||
206 | #define WM8350_DC2_HIB_MODE_ACTIVE 1 | ||
207 | #define WM8350_DC2_HIB_MODE_DISABLE 0 | ||
208 | |||
209 | #define WM8350_DC2_HIB_TRIG_NONE 0 | ||
210 | #define WM8350_DC2_HIB_TRIG_LPWR1 1 | ||
211 | #define WM8350_DC2_HIB_TRIG_LPWR2 2 | ||
212 | #define WM8350_DC2_HIB_TRIG_LPWR3 3 | ||
213 | |||
214 | #define WM8350_DC2_ILIM_HIGH 0 | ||
215 | #define WM8350_DC2_ILIM_LOW 1 | ||
216 | |||
217 | #define WM8350_DC2_RMP_30V 0 | ||
218 | #define WM8350_DC2_RMP_20V 1 | ||
219 | #define WM8350_DC2_RMP_10V 2 | ||
220 | #define WM8350_DC2_RMP_5V 3 | ||
221 | |||
222 | #define WM8350_DC2_FBSRC_FB2 0 | ||
223 | #define WM8350_DC2_FBSRC_ISINKA 1 | ||
224 | #define WM8350_DC2_FBSRC_ISINKB 2 | ||
225 | #define WM8350_DC2_FBSRC_USB 3 | ||
226 | |||
227 | /* | ||
228 | * R184 (0xB8) - DCDC2 Timeouts | ||
229 | */ | ||
230 | #define WM8350_DC2_ERRACT_MASK 0xC000 | ||
231 | #define WM8350_DC2_ERRACT_SHIFT 14 | ||
232 | #define WM8350_DC2_ENSLOT_MASK 0x3C00 | ||
233 | #define WM8350_DC2_ENSLOT_SHIFT 10 | ||
234 | #define WM8350_DC2_SDSLOT_MASK 0x03C0 | ||
235 | #define WM8350_DC2_UVTO_MASK 0x0030 | ||
236 | |||
237 | /* Bit values for R184 (0xB8) */ | ||
238 | #define WM8350_DC2_ERRACT_NONE 0 | ||
239 | #define WM8350_DC2_ERRACT_SHUTDOWN_CONV 1 | ||
240 | #define WM8350_DC2_ERRACT_SHUTDOWN_SYS 2 | ||
241 | |||
242 | /* | ||
243 | * R186 (0xBA) - DCDC3 Control | ||
244 | */ | ||
245 | #define WM8350_DC3_OPFLT 0x0400 | ||
246 | #define WM8350_DC3_VSEL_MASK 0x007F | ||
247 | #define WM8350_DC3_VSEL_SHIFT 0 | ||
248 | |||
249 | /* | ||
250 | * R187 (0xBB) - DCDC3 Timeouts | ||
251 | */ | ||
252 | #define WM8350_DC3_ERRACT_MASK 0xC000 | ||
253 | #define WM8350_DC3_ERRACT_SHIFT 14 | ||
254 | #define WM8350_DC3_ENSLOT_MASK 0x3C00 | ||
255 | #define WM8350_DC3_ENSLOT_SHIFT 10 | ||
256 | #define WM8350_DC3_SDSLOT_MASK 0x03C0 | ||
257 | #define WM8350_DC3_UVTO_MASK 0x0030 | ||
258 | #define WM8350_DC3_SDSLOT_SHIFT 6 | ||
259 | |||
260 | /* Bit values for R187 (0xBB) */ | ||
261 | #define WM8350_DC3_ERRACT_NONE 0 | ||
262 | #define WM8350_DC3_ERRACT_SHUTDOWN_CONV 1 | ||
263 | #define WM8350_DC3_ERRACT_SHUTDOWN_SYS 2 | ||
264 | /* | ||
265 | * R188 (0xBC) - DCDC3 Low Power | ||
266 | */ | ||
267 | #define WM8350_DC3_HIB_MODE_MASK 0x7000 | ||
268 | #define WM8350_DC3_HIB_TRIG_MASK 0x0300 | ||
269 | #define WM8350_DC3_VIMG_MASK 0x007F | ||
270 | |||
271 | /* | ||
272 | * R189 (0xBD) - DCDC4 Control | ||
273 | */ | ||
274 | #define WM8350_DC4_OPFLT 0x0400 | ||
275 | #define WM8350_DC4_VSEL_MASK 0x007F | ||
276 | #define WM8350_DC4_VSEL_SHIFT 0 | ||
277 | |||
278 | /* | ||
279 | * R190 (0xBE) - DCDC4 Timeouts | ||
280 | */ | ||
281 | #define WM8350_DC4_ERRACT_MASK 0xC000 | ||
282 | #define WM8350_DC4_ERRACT_SHIFT 14 | ||
283 | #define WM8350_DC4_ENSLOT_MASK 0x3C00 | ||
284 | #define WM8350_DC4_ENSLOT_SHIFT 10 | ||
285 | #define WM8350_DC4_SDSLOT_MASK 0x03C0 | ||
286 | #define WM8350_DC4_UVTO_MASK 0x0030 | ||
287 | #define WM8350_DC4_SDSLOT_SHIFT 6 | ||
288 | |||
289 | /* Bit values for R190 (0xBE) */ | ||
290 | #define WM8350_DC4_ERRACT_NONE 0 | ||
291 | #define WM8350_DC4_ERRACT_SHUTDOWN_CONV 1 | ||
292 | #define WM8350_DC4_ERRACT_SHUTDOWN_SYS 2 | ||
293 | |||
294 | /* | ||
295 | * R191 (0xBF) - DCDC4 Low Power | ||
296 | */ | ||
297 | #define WM8350_DC4_HIB_MODE_MASK 0x7000 | ||
298 | #define WM8350_DC4_HIB_TRIG_MASK 0x0300 | ||
299 | #define WM8350_DC4_VIMG_MASK 0x007F | ||
300 | |||
301 | /* | ||
302 | * R192 (0xC0) - DCDC5 Control | ||
303 | */ | ||
304 | #define WM8350_DC5_MODE 0x4000 | ||
305 | #define WM8350_DC5_MODE_MASK 0x4000 | ||
306 | #define WM8350_DC5_MODE_SHIFT 14 | ||
307 | #define WM8350_DC5_HIB_MODE 0x1000 | ||
308 | #define WM8350_DC5_HIB_MODE_MASK 0x1000 | ||
309 | #define WM8350_DC5_HIB_MODE_SHIFT 12 | ||
310 | #define WM8350_DC5_HIB_TRIG_MASK 0x0300 | ||
311 | #define WM8350_DC5_HIB_TRIG_SHIFT 8 | ||
312 | #define WM8350_DC5_ILIM 0x0040 | ||
313 | #define WM8350_DC5_ILIM_MASK 0x0040 | ||
314 | #define WM8350_DC5_ILIM_SHIFT 6 | ||
315 | #define WM8350_DC5_RMP_MASK 0x0018 | ||
316 | #define WM8350_DC5_RMP_SHIFT 3 | ||
317 | #define WM8350_DC5_FBSRC_MASK 0x0003 | ||
318 | #define WM8350_DC5_FBSRC_SHIFT 0 | ||
319 | |||
320 | /* Bit values for R192 (0xC0) */ | ||
321 | #define WM8350_DC5_MODE_BOOST 0 | ||
322 | #define WM8350_DC5_MODE_SWITCH 1 | ||
323 | |||
324 | #define WM8350_DC5_HIB_MODE_ACTIVE 1 | ||
325 | #define WM8350_DC5_HIB_MODE_DISABLE 0 | ||
326 | |||
327 | #define WM8350_DC5_HIB_TRIG_NONE 0 | ||
328 | #define WM8350_DC5_HIB_TRIG_LPWR1 1 | ||
329 | #define WM8350_DC5_HIB_TRIG_LPWR2 2 | ||
330 | #define WM8350_DC5_HIB_TRIG_LPWR3 3 | ||
331 | |||
332 | #define WM8350_DC5_ILIM_HIGH 0 | ||
333 | #define WM8350_DC5_ILIM_LOW 1 | ||
334 | |||
335 | #define WM8350_DC5_RMP_30V 0 | ||
336 | #define WM8350_DC5_RMP_20V 1 | ||
337 | #define WM8350_DC5_RMP_10V 2 | ||
338 | #define WM8350_DC5_RMP_5V 3 | ||
339 | |||
340 | #define WM8350_DC5_FBSRC_FB2 0 | ||
341 | #define WM8350_DC5_FBSRC_ISINKA 1 | ||
342 | #define WM8350_DC5_FBSRC_ISINKB 2 | ||
343 | #define WM8350_DC5_FBSRC_USB 3 | ||
344 | |||
345 | /* | ||
346 | * R193 (0xC1) - DCDC5 Timeouts | ||
347 | */ | ||
348 | #define WM8350_DC5_ERRACT_MASK 0xC000 | ||
349 | #define WM8350_DC5_ERRACT_SHIFT 14 | ||
350 | #define WM8350_DC5_ENSLOT_MASK 0x3C00 | ||
351 | #define WM8350_DC5_ENSLOT_SHIFT 10 | ||
352 | #define WM8350_DC5_SDSLOT_MASK 0x03C0 | ||
353 | #define WM8350_DC5_UVTO_MASK 0x0030 | ||
354 | #define WM8350_DC5_SDSLOT_SHIFT 6 | ||
355 | |||
356 | /* Bit values for R193 (0xC1) */ | ||
357 | #define WM8350_DC5_ERRACT_NONE 0 | ||
358 | #define WM8350_DC5_ERRACT_SHUTDOWN_CONV 1 | ||
359 | #define WM8350_DC5_ERRACT_SHUTDOWN_SYS 2 | ||
360 | |||
361 | /* | ||
362 | * R195 (0xC3) - DCDC6 Control | ||
363 | */ | ||
364 | #define WM8350_DC6_OPFLT 0x0400 | ||
365 | #define WM8350_DC6_VSEL_MASK 0x007F | ||
366 | #define WM8350_DC6_VSEL_SHIFT 0 | ||
367 | |||
368 | /* | ||
369 | * R196 (0xC4) - DCDC6 Timeouts | ||
370 | */ | ||
371 | #define WM8350_DC6_ERRACT_MASK 0xC000 | ||
372 | #define WM8350_DC6_ERRACT_SHIFT 14 | ||
373 | #define WM8350_DC6_ENSLOT_MASK 0x3C00 | ||
374 | #define WM8350_DC6_ENSLOT_SHIFT 10 | ||
375 | #define WM8350_DC6_SDSLOT_MASK 0x03C0 | ||
376 | #define WM8350_DC6_UVTO_MASK 0x0030 | ||
377 | #define WM8350_DC6_SDSLOT_SHIFT 6 | ||
378 | |||
379 | /* Bit values for R196 (0xC4) */ | ||
380 | #define WM8350_DC6_ERRACT_NONE 0 | ||
381 | #define WM8350_DC6_ERRACT_SHUTDOWN_CONV 1 | ||
382 | #define WM8350_DC6_ERRACT_SHUTDOWN_SYS 2 | ||
383 | |||
384 | /* | ||
385 | * R197 (0xC5) - DCDC6 Low Power | ||
386 | */ | ||
387 | #define WM8350_DC6_HIB_MODE_MASK 0x7000 | ||
388 | #define WM8350_DC6_HIB_TRIG_MASK 0x0300 | ||
389 | #define WM8350_DC6_VIMG_MASK 0x007F | ||
390 | |||
391 | /* | ||
392 | * R199 (0xC7) - Limit Switch Control | ||
393 | */ | ||
394 | #define WM8350_LS_ERRACT_MASK 0xC000 | ||
395 | #define WM8350_LS_ERRACT_SHIFT 14 | ||
396 | #define WM8350_LS_ENSLOT_MASK 0x3C00 | ||
397 | #define WM8350_LS_ENSLOT_SHIFT 10 | ||
398 | #define WM8350_LS_SDSLOT_MASK 0x03C0 | ||
399 | #define WM8350_LS_SDSLOT_SHIFT 6 | ||
400 | #define WM8350_LS_HIB_MODE 0x0010 | ||
401 | #define WM8350_LS_HIB_MODE_MASK 0x0010 | ||
402 | #define WM8350_LS_HIB_MODE_SHIFT 4 | ||
403 | #define WM8350_LS_HIB_PROT 0x0002 | ||
404 | #define WM8350_LS_HIB_PROT_MASK 0x0002 | ||
405 | #define WM8350_LS_HIB_PROT_SHIFT 1 | ||
406 | #define WM8350_LS_PROT 0x0001 | ||
407 | #define WM8350_LS_PROT_MASK 0x0001 | ||
408 | #define WM8350_LS_PROT_SHIFT 0 | ||
409 | |||
410 | /* Bit values for R199 (0xC7) */ | ||
411 | #define WM8350_LS_ERRACT_NONE 0 | ||
412 | #define WM8350_LS_ERRACT_SHUTDOWN_CONV 1 | ||
413 | #define WM8350_LS_ERRACT_SHUTDOWN_SYS 2 | ||
414 | |||
415 | /* | ||
416 | * R200 (0xC8) - LDO1 Control | ||
417 | */ | ||
418 | #define WM8350_LDO1_SWI 0x4000 | ||
419 | #define WM8350_LDO1_OPFLT 0x0400 | ||
420 | #define WM8350_LDO1_VSEL_MASK 0x001F | ||
421 | #define WM8350_LDO1_VSEL_SHIFT 0 | ||
422 | |||
423 | /* | ||
424 | * R201 (0xC9) - LDO1 Timeouts | ||
425 | */ | ||
426 | #define WM8350_LDO1_ERRACT_MASK 0xC000 | ||
427 | #define WM8350_LDO1_ERRACT_SHIFT 14 | ||
428 | #define WM8350_LDO1_ENSLOT_MASK 0x3C00 | ||
429 | #define WM8350_LDO1_ENSLOT_SHIFT 10 | ||
430 | #define WM8350_LDO1_SDSLOT_MASK 0x03C0 | ||
431 | #define WM8350_LDO1_UVTO_MASK 0x0030 | ||
432 | #define WM8350_LDO1_SDSLOT_SHIFT 6 | ||
433 | |||
434 | /* Bit values for R201 (0xC9) */ | ||
435 | #define WM8350_LDO1_ERRACT_NONE 0 | ||
436 | #define WM8350_LDO1_ERRACT_SHUTDOWN_CONV 1 | ||
437 | #define WM8350_LDO1_ERRACT_SHUTDOWN_SYS 2 | ||
438 | |||
439 | /* | ||
440 | * R202 (0xCA) - LDO1 Low Power | ||
441 | */ | ||
442 | #define WM8350_LDO1_HIB_MODE_MASK 0x3000 | ||
443 | #define WM8350_LDO1_HIB_TRIG_MASK 0x0300 | ||
444 | #define WM8350_LDO1_VIMG_MASK 0x001F | ||
445 | #define WM8350_LDO1_HIB_MODE_DIS (0x1 << 12) | ||
446 | |||
447 | |||
448 | /* | ||
449 | * R203 (0xCB) - LDO2 Control | ||
450 | */ | ||
451 | #define WM8350_LDO2_SWI 0x4000 | ||
452 | #define WM8350_LDO2_OPFLT 0x0400 | ||
453 | #define WM8350_LDO2_VSEL_MASK 0x001F | ||
454 | #define WM8350_LDO2_VSEL_SHIFT 0 | ||
455 | |||
456 | /* | ||
457 | * R204 (0xCC) - LDO2 Timeouts | ||
458 | */ | ||
459 | #define WM8350_LDO2_ERRACT_MASK 0xC000 | ||
460 | #define WM8350_LDO2_ERRACT_SHIFT 14 | ||
461 | #define WM8350_LDO2_ENSLOT_MASK 0x3C00 | ||
462 | #define WM8350_LDO2_ENSLOT_SHIFT 10 | ||
463 | #define WM8350_LDO2_SDSLOT_MASK 0x03C0 | ||
464 | #define WM8350_LDO2_SDSLOT_SHIFT 6 | ||
465 | |||
466 | /* Bit values for R204 (0xCC) */ | ||
467 | #define WM8350_LDO2_ERRACT_NONE 0 | ||
468 | #define WM8350_LDO2_ERRACT_SHUTDOWN_CONV 1 | ||
469 | #define WM8350_LDO2_ERRACT_SHUTDOWN_SYS 2 | ||
470 | |||
471 | /* | ||
472 | * R205 (0xCD) - LDO2 Low Power | ||
473 | */ | ||
474 | #define WM8350_LDO2_HIB_MODE_MASK 0x3000 | ||
475 | #define WM8350_LDO2_HIB_TRIG_MASK 0x0300 | ||
476 | #define WM8350_LDO2_VIMG_MASK 0x001F | ||
477 | |||
478 | /* | ||
479 | * R206 (0xCE) - LDO3 Control | ||
480 | */ | ||
481 | #define WM8350_LDO3_SWI 0x4000 | ||
482 | #define WM8350_LDO3_OPFLT 0x0400 | ||
483 | #define WM8350_LDO3_VSEL_MASK 0x001F | ||
484 | #define WM8350_LDO3_VSEL_SHIFT 0 | ||
485 | |||
486 | /* | ||
487 | * R207 (0xCF) - LDO3 Timeouts | ||
488 | */ | ||
489 | #define WM8350_LDO3_ERRACT_MASK 0xC000 | ||
490 | #define WM8350_LDO3_ERRACT_SHIFT 14 | ||
491 | #define WM8350_LDO3_ENSLOT_MASK 0x3C00 | ||
492 | #define WM8350_LDO3_ENSLOT_SHIFT 10 | ||
493 | #define WM8350_LDO3_SDSLOT_MASK 0x03C0 | ||
494 | #define WM8350_LDO3_UVTO_MASK 0x0030 | ||
495 | #define WM8350_LDO3_SDSLOT_SHIFT 6 | ||
496 | |||
497 | /* Bit values for R207 (0xCF) */ | ||
498 | #define WM8350_LDO3_ERRACT_NONE 0 | ||
499 | #define WM8350_LDO3_ERRACT_SHUTDOWN_CONV 1 | ||
500 | #define WM8350_LDO3_ERRACT_SHUTDOWN_SYS 2 | ||
501 | |||
502 | /* | ||
503 | * R208 (0xD0) - LDO3 Low Power | ||
504 | */ | ||
505 | #define WM8350_LDO3_HIB_MODE_MASK 0x3000 | ||
506 | #define WM8350_LDO3_HIB_TRIG_MASK 0x0300 | ||
507 | #define WM8350_LDO3_VIMG_MASK 0x001F | ||
508 | |||
509 | /* | ||
510 | * R209 (0xD1) - LDO4 Control | ||
511 | */ | ||
512 | #define WM8350_LDO4_SWI 0x4000 | ||
513 | #define WM8350_LDO4_OPFLT 0x0400 | ||
514 | #define WM8350_LDO4_VSEL_MASK 0x001F | ||
515 | #define WM8350_LDO4_VSEL_SHIFT 0 | ||
516 | |||
517 | /* | ||
518 | * R210 (0xD2) - LDO4 Timeouts | ||
519 | */ | ||
520 | #define WM8350_LDO4_ERRACT_MASK 0xC000 | ||
521 | #define WM8350_LDO4_ERRACT_SHIFT 14 | ||
522 | #define WM8350_LDO4_ENSLOT_MASK 0x3C00 | ||
523 | #define WM8350_LDO4_ENSLOT_SHIFT 10 | ||
524 | #define WM8350_LDO4_SDSLOT_MASK 0x03C0 | ||
525 | #define WM8350_LDO4_UVTO_MASK 0x0030 | ||
526 | #define WM8350_LDO4_SDSLOT_SHIFT 6 | ||
527 | |||
528 | /* Bit values for R210 (0xD2) */ | ||
529 | #define WM8350_LDO4_ERRACT_NONE 0 | ||
530 | #define WM8350_LDO4_ERRACT_SHUTDOWN_CONV 1 | ||
531 | #define WM8350_LDO4_ERRACT_SHUTDOWN_SYS 2 | ||
532 | |||
533 | /* | ||
534 | * R211 (0xD3) - LDO4 Low Power | ||
535 | */ | ||
536 | #define WM8350_LDO4_HIB_MODE_MASK 0x3000 | ||
537 | #define WM8350_LDO4_HIB_TRIG_MASK 0x0300 | ||
538 | #define WM8350_LDO4_VIMG_MASK 0x001F | ||
539 | |||
540 | /* | ||
541 | * R215 (0xD7) - VCC_FAULT Masks | ||
542 | */ | ||
543 | #define WM8350_LS_FAULT 0x8000 | ||
544 | #define WM8350_LDO4_FAULT 0x0800 | ||
545 | #define WM8350_LDO3_FAULT 0x0400 | ||
546 | #define WM8350_LDO2_FAULT 0x0200 | ||
547 | #define WM8350_LDO1_FAULT 0x0100 | ||
548 | #define WM8350_DC6_FAULT 0x0020 | ||
549 | #define WM8350_DC5_FAULT 0x0010 | ||
550 | #define WM8350_DC4_FAULT 0x0008 | ||
551 | #define WM8350_DC3_FAULT 0x0004 | ||
552 | #define WM8350_DC2_FAULT 0x0002 | ||
553 | #define WM8350_DC1_FAULT 0x0001 | ||
554 | |||
555 | /* | ||
556 | * R216 (0xD8) - Main Bandgap Control | ||
557 | */ | ||
558 | #define WM8350_MBG_LOAD_FUSES 0x8000 | ||
559 | #define WM8350_MBG_FUSE_WPREP 0x4000 | ||
560 | #define WM8350_MBG_FUSE_WRITE 0x2000 | ||
561 | #define WM8350_MBG_FUSE_TRIM_MASK 0x1F00 | ||
562 | #define WM8350_MBG_TRIM_SRC 0x0020 | ||
563 | #define WM8350_MBG_USER_TRIM_MASK 0x001F | ||
564 | |||
565 | /* | ||
566 | * R217 (0xD9) - OSC Control | ||
567 | */ | ||
568 | #define WM8350_OSC_LOAD_FUSES 0x8000 | ||
569 | #define WM8350_OSC_FUSE_WPREP 0x4000 | ||
570 | #define WM8350_OSC_FUSE_WRITE 0x2000 | ||
571 | #define WM8350_OSC_FUSE_TRIM_MASK 0x0F00 | ||
572 | #define WM8350_OSC_TRIM_SRC 0x0020 | ||
573 | #define WM8350_OSC_USER_TRIM_MASK 0x000F | ||
574 | |||
575 | /* | ||
576 | * R248 (0xF8) - DCDC1 Force PWM | ||
577 | */ | ||
578 | #define WM8350_DCDC1_FORCE_PWM_ENA 0x0010 | ||
579 | |||
580 | /* | ||
581 | * R250 (0xFA) - DCDC3 Force PWM | ||
582 | */ | ||
583 | #define WM8350_DCDC3_FORCE_PWM_ENA 0x0010 | ||
584 | |||
585 | /* | ||
586 | * R251 (0xFB) - DCDC4 Force PWM | ||
587 | */ | ||
588 | #define WM8350_DCDC4_FORCE_PWM_ENA 0x0010 | ||
589 | |||
590 | /* | ||
591 | * R253 (0xFD) - DCDC1 Force PWM | ||
592 | */ | ||
593 | #define WM8350_DCDC6_FORCE_PWM_ENA 0x0010 | ||
594 | |||
595 | /* | ||
596 | * DCDC's | ||
597 | */ | ||
598 | #define WM8350_DCDC_1 0 | ||
599 | #define WM8350_DCDC_2 1 | ||
600 | #define WM8350_DCDC_3 2 | ||
601 | #define WM8350_DCDC_4 3 | ||
602 | #define WM8350_DCDC_5 4 | ||
603 | #define WM8350_DCDC_6 5 | ||
604 | |||
605 | /* DCDC modes */ | ||
606 | #define WM8350_DCDC_ACTIVE_STANDBY 0 | ||
607 | #define WM8350_DCDC_ACTIVE_PULSE 1 | ||
608 | #define WM8350_DCDC_SLEEP_NORMAL 0 | ||
609 | #define WM8350_DCDC_SLEEP_LOW 1 | ||
610 | |||
611 | /* DCDC Low power (Hibernate) mode */ | ||
612 | #define WM8350_DCDC_HIB_MODE_CUR (0 << 12) | ||
613 | #define WM8350_DCDC_HIB_MODE_IMAGE (1 << 12) | ||
614 | #define WM8350_DCDC_HIB_MODE_STANDBY (2 << 12) | ||
615 | #define WM8350_DCDC_HIB_MODE_LDO (4 << 12) | ||
616 | #define WM8350_DCDC_HIB_MODE_LDO_IM (5 << 12) | ||
617 | #define WM8350_DCDC_HIB_MODE_DIS (7 << 12) | ||
618 | #define WM8350_DCDC_HIB_MODE_MASK (7 << 12) | ||
619 | |||
620 | /* DCDC Low Power (Hibernate) signal */ | ||
621 | #define WM8350_DCDC_HIB_SIG_REG (0 << 8) | ||
622 | #define WM8350_DCDC_HIB_SIG_LPWR1 (1 << 8) | ||
623 | #define WM8350_DCDC_HIB_SIG_LPWR2 (2 << 8) | ||
624 | #define WM8350_DCDC_HIB_SIG_LPWR3 (3 << 8) | ||
625 | |||
626 | /* LDO Low power (Hibernate) mode */ | ||
627 | #define WM8350_LDO_HIB_MODE_IMAGE (0 << 0) | ||
628 | #define WM8350_LDO_HIB_MODE_DIS (1 << 0) | ||
629 | |||
630 | /* LDO Low Power (Hibernate) signal */ | ||
631 | #define WM8350_LDO_HIB_SIG_REG (0 << 8) | ||
632 | #define WM8350_LDO_HIB_SIG_LPWR1 (1 << 8) | ||
633 | #define WM8350_LDO_HIB_SIG_LPWR2 (2 << 8) | ||
634 | #define WM8350_LDO_HIB_SIG_LPWR3 (3 << 8) | ||
635 | |||
636 | /* | ||
637 | * LDOs | ||
638 | */ | ||
639 | #define WM8350_LDO_1 6 | ||
640 | #define WM8350_LDO_2 7 | ||
641 | #define WM8350_LDO_3 8 | ||
642 | #define WM8350_LDO_4 9 | ||
643 | |||
644 | /* | ||
645 | * ISINKs | ||
646 | */ | ||
647 | #define WM8350_ISINK_A 10 | ||
648 | #define WM8350_ISINK_B 11 | ||
649 | |||
650 | #define WM8350_ISINK_MODE_BOOST 0 | ||
651 | #define WM8350_ISINK_MODE_SWITCH 1 | ||
652 | #define WM8350_ISINK_ILIM_NORMAL 0 | ||
653 | #define WM8350_ISINK_ILIM_LOW 1 | ||
654 | |||
655 | #define WM8350_ISINK_FLASH_DISABLE 0 | ||
656 | #define WM8350_ISINK_FLASH_ENABLE 1 | ||
657 | #define WM8350_ISINK_FLASH_TRIG_BIT 0 | ||
658 | #define WM8350_ISINK_FLASH_TRIG_GPIO 1 | ||
659 | #define WM8350_ISINK_FLASH_MODE_EN (1 << 13) | ||
660 | #define WM8350_ISINK_FLASH_MODE_DIS (0 << 13) | ||
661 | #define WM8350_ISINK_FLASH_DUR_32MS (0 << 8) | ||
662 | #define WM8350_ISINK_FLASH_DUR_64MS (1 << 8) | ||
663 | #define WM8350_ISINK_FLASH_DUR_96MS (2 << 8) | ||
664 | #define WM8350_ISINK_FLASH_DUR_1024MS (3 << 8) | ||
665 | #define WM8350_ISINK_FLASH_ON_INSTANT (0 << 4) | ||
666 | #define WM8350_ISINK_FLASH_ON_0_25S (1 << 4) | ||
667 | #define WM8350_ISINK_FLASH_ON_0_50S (2 << 4) | ||
668 | #define WM8350_ISINK_FLASH_ON_1_00S (3 << 4) | ||
669 | #define WM8350_ISINK_FLASH_ON_1_95S (1 << 4) | ||
670 | #define WM8350_ISINK_FLASH_ON_3_91S (2 << 4) | ||
671 | #define WM8350_ISINK_FLASH_ON_7_80S (3 << 4) | ||
672 | #define WM8350_ISINK_FLASH_OFF_INSTANT (0 << 0) | ||
673 | #define WM8350_ISINK_FLASH_OFF_0_25S (1 << 0) | ||
674 | #define WM8350_ISINK_FLASH_OFF_0_50S (2 << 0) | ||
675 | #define WM8350_ISINK_FLASH_OFF_1_00S (3 << 0) | ||
676 | #define WM8350_ISINK_FLASH_OFF_1_95S (1 << 0) | ||
677 | #define WM8350_ISINK_FLASH_OFF_3_91S (2 << 0) | ||
678 | #define WM8350_ISINK_FLASH_OFF_7_80S (3 << 0) | ||
679 | |||
680 | /* | ||
681 | * Regulator Interrupts. | ||
682 | */ | ||
683 | #define WM8350_IRQ_CS1 13 | ||
684 | #define WM8350_IRQ_CS2 14 | ||
685 | #define WM8350_IRQ_UV_LDO4 25 | ||
686 | #define WM8350_IRQ_UV_LDO3 26 | ||
687 | #define WM8350_IRQ_UV_LDO2 27 | ||
688 | #define WM8350_IRQ_UV_LDO1 28 | ||
689 | #define WM8350_IRQ_UV_DC6 29 | ||
690 | #define WM8350_IRQ_UV_DC5 30 | ||
691 | #define WM8350_IRQ_UV_DC4 31 | ||
692 | #define WM8350_IRQ_UV_DC3 32 | ||
693 | #define WM8350_IRQ_UV_DC2 33 | ||
694 | #define WM8350_IRQ_UV_DC1 34 | ||
695 | #define WM8350_IRQ_OC_LS 35 | ||
696 | |||
697 | #define NUM_WM8350_REGULATORS 12 | ||
698 | |||
699 | struct wm8350; | ||
700 | struct platform_device; | ||
701 | struct regulator_init_data; | ||
702 | |||
703 | struct wm8350_pmic { | ||
704 | /* ISINK to DCDC mapping */ | ||
705 | int isink_A_dcdc; | ||
706 | int isink_B_dcdc; | ||
707 | |||
708 | /* hibernate configs */ | ||
709 | u16 dcdc1_hib_mode; | ||
710 | u16 dcdc3_hib_mode; | ||
711 | u16 dcdc4_hib_mode; | ||
712 | u16 dcdc6_hib_mode; | ||
713 | |||
714 | /* regulator devices */ | ||
715 | struct platform_device *pdev[NUM_WM8350_REGULATORS]; | ||
716 | }; | ||
717 | |||
718 | int wm8350_register_regulator(struct wm8350 *wm8350, int reg, | ||
719 | struct regulator_init_data *initdata); | ||
720 | |||
721 | /* | ||
722 | * Additional DCDC control not supported via regulator API | ||
723 | */ | ||
724 | int wm8350_dcdc_set_slot(struct wm8350 *wm8350, int dcdc, u16 start, | ||
725 | u16 stop, u16 fault); | ||
726 | int wm8350_dcdc25_set_mode(struct wm8350 *wm8350, int dcdc, u16 mode, | ||
727 | u16 ilim, u16 ramp, u16 feedback); | ||
728 | |||
729 | /* | ||
730 | * Additional LDO control not supported via regulator API | ||
731 | */ | ||
732 | int wm8350_ldo_set_slot(struct wm8350 *wm8350, int ldo, u16 start, u16 stop); | ||
733 | |||
734 | /* | ||
735 | * Additional ISINK control not supported via regulator API | ||
736 | */ | ||
737 | int wm8350_isink_set_flash(struct wm8350 *wm8350, int isink, u16 mode, | ||
738 | u16 trigger, u16 duration, u16 on_ramp, | ||
739 | u16 off_ramp, u16 drive); | ||
740 | |||
741 | #endif | ||
diff --git a/include/linux/mfd/wm8350/rtc.h b/include/linux/mfd/wm8350/rtc.h new file mode 100644 index 000000000000..dfda69e9f440 --- /dev/null +++ b/include/linux/mfd/wm8350/rtc.h | |||
@@ -0,0 +1,266 @@ | |||
1 | /* | ||
2 | * rtc.h -- RTC driver for Wolfson WM8350 PMIC | ||
3 | * | ||
4 | * Copyright 2007 Wolfson Microelectronics PLC | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License as published by the | ||
8 | * Free Software Foundation; either version 2 of the License, or (at your | ||
9 | * option) any later version. | ||
10 | */ | ||
11 | |||
12 | #ifndef __LINUX_MFD_WM8350_RTC_H | ||
13 | #define __LINUX_MFD_WM8350_RTC_H | ||
14 | |||
15 | #include <linux/platform_device.h> | ||
16 | |||
17 | /* | ||
18 | * Register values. | ||
19 | */ | ||
20 | #define WM8350_RTC_SECONDS_MINUTES 0x10 | ||
21 | #define WM8350_RTC_HOURS_DAY 0x11 | ||
22 | #define WM8350_RTC_DATE_MONTH 0x12 | ||
23 | #define WM8350_RTC_YEAR 0x13 | ||
24 | #define WM8350_ALARM_SECONDS_MINUTES 0x14 | ||
25 | #define WM8350_ALARM_HOURS_DAY 0x15 | ||
26 | #define WM8350_ALARM_DATE_MONTH 0x16 | ||
27 | #define WM8350_RTC_TIME_CONTROL 0x17 | ||
28 | |||
29 | /* | ||
30 | * R16 (0x10) - RTC Seconds/Minutes | ||
31 | */ | ||
32 | #define WM8350_RTC_MINS_MASK 0x7F00 | ||
33 | #define WM8350_RTC_MINS_SHIFT 8 | ||
34 | #define WM8350_RTC_SECS_MASK 0x007F | ||
35 | #define WM8350_RTC_SECS_SHIFT 0 | ||
36 | |||
37 | /* | ||
38 | * R17 (0x11) - RTC Hours/Day | ||
39 | */ | ||
40 | #define WM8350_RTC_DAY_MASK 0x0700 | ||
41 | #define WM8350_RTC_DAY_SHIFT 8 | ||
42 | #define WM8350_RTC_HPM_MASK 0x0020 | ||
43 | #define WM8350_RTC_HPM_SHIFT 5 | ||
44 | #define WM8350_RTC_HRS_MASK 0x001F | ||
45 | #define WM8350_RTC_HRS_SHIFT 0 | ||
46 | |||
47 | /* Bit values for R21 (0x15) */ | ||
48 | #define WM8350_RTC_DAY_SUN 1 | ||
49 | #define WM8350_RTC_DAY_MON 2 | ||
50 | #define WM8350_RTC_DAY_TUE 3 | ||
51 | #define WM8350_RTC_DAY_WED 4 | ||
52 | #define WM8350_RTC_DAY_THU 5 | ||
53 | #define WM8350_RTC_DAY_FRI 6 | ||
54 | #define WM8350_RTC_DAY_SAT 7 | ||
55 | |||
56 | #define WM8350_RTC_HPM_AM 0 | ||
57 | #define WM8350_RTC_HPM_PM 1 | ||
58 | |||
59 | /* | ||
60 | * R18 (0x12) - RTC Date/Month | ||
61 | */ | ||
62 | #define WM8350_RTC_MTH_MASK 0x1F00 | ||
63 | #define WM8350_RTC_MTH_SHIFT 8 | ||
64 | #define WM8350_RTC_DATE_MASK 0x003F | ||
65 | #define WM8350_RTC_DATE_SHIFT 0 | ||
66 | |||
67 | /* Bit values for R22 (0x16) */ | ||
68 | #define WM8350_RTC_MTH_JAN 1 | ||
69 | #define WM8350_RTC_MTH_FEB 2 | ||
70 | #define WM8350_RTC_MTH_MAR 3 | ||
71 | #define WM8350_RTC_MTH_APR 4 | ||
72 | #define WM8350_RTC_MTH_MAY 5 | ||
73 | #define WM8350_RTC_MTH_JUN 6 | ||
74 | #define WM8350_RTC_MTH_JUL 7 | ||
75 | #define WM8350_RTC_MTH_AUG 8 | ||
76 | #define WM8350_RTC_MTH_SEP 9 | ||
77 | #define WM8350_RTC_MTH_OCT 10 | ||
78 | #define WM8350_RTC_MTH_NOV 11 | ||
79 | #define WM8350_RTC_MTH_DEC 12 | ||
80 | #define WM8350_RTC_MTH_JAN_BCD 0x01 | ||
81 | #define WM8350_RTC_MTH_FEB_BCD 0x02 | ||
82 | #define WM8350_RTC_MTH_MAR_BCD 0x03 | ||
83 | #define WM8350_RTC_MTH_APR_BCD 0x04 | ||
84 | #define WM8350_RTC_MTH_MAY_BCD 0x05 | ||
85 | #define WM8350_RTC_MTH_JUN_BCD 0x06 | ||
86 | #define WM8350_RTC_MTH_JUL_BCD 0x07 | ||
87 | #define WM8350_RTC_MTH_AUG_BCD 0x08 | ||
88 | #define WM8350_RTC_MTH_SEP_BCD 0x09 | ||
89 | #define WM8350_RTC_MTH_OCT_BCD 0x10 | ||
90 | #define WM8350_RTC_MTH_NOV_BCD 0x11 | ||
91 | #define WM8350_RTC_MTH_DEC_BCD 0x12 | ||
92 | |||
93 | /* | ||
94 | * R19 (0x13) - RTC Year | ||
95 | */ | ||
96 | #define WM8350_RTC_YHUNDREDS_MASK 0x3F00 | ||
97 | #define WM8350_RTC_YHUNDREDS_SHIFT 8 | ||
98 | #define WM8350_RTC_YUNITS_MASK 0x00FF | ||
99 | #define WM8350_RTC_YUNITS_SHIFT 0 | ||
100 | |||
101 | /* | ||
102 | * R20 (0x14) - Alarm Seconds/Minutes | ||
103 | */ | ||
104 | #define WM8350_RTC_ALMMINS_MASK 0x7F00 | ||
105 | #define WM8350_RTC_ALMMINS_SHIFT 8 | ||
106 | #define WM8350_RTC_ALMSECS_MASK 0x007F | ||
107 | #define WM8350_RTC_ALMSECS_SHIFT 0 | ||
108 | |||
109 | /* Bit values for R20 (0x14) */ | ||
110 | #define WM8350_RTC_ALMMINS_DONT_CARE -1 | ||
111 | #define WM8350_RTC_ALMSECS_DONT_CARE -1 | ||
112 | |||
113 | /* | ||
114 | * R21 (0x15) - Alarm Hours/Day | ||
115 | */ | ||
116 | #define WM8350_RTC_ALMDAY_MASK 0x0F00 | ||
117 | #define WM8350_RTC_ALMDAY_SHIFT 8 | ||
118 | #define WM8350_RTC_ALMHPM_MASK 0x0020 | ||
119 | #define WM8350_RTC_ALMHPM_SHIFT 5 | ||
120 | #define WM8350_RTC_ALMHRS_MASK 0x001F | ||
121 | #define WM8350_RTC_ALMHRS_SHIFT 0 | ||
122 | |||
123 | /* Bit values for R21 (0x15) */ | ||
124 | #define WM8350_RTC_ALMDAY_DONT_CARE -1 | ||
125 | #define WM8350_RTC_ALMDAY_SUN 1 | ||
126 | #define WM8350_RTC_ALMDAY_MON 2 | ||
127 | #define WM8350_RTC_ALMDAY_TUE 3 | ||
128 | #define WM8350_RTC_ALMDAY_WED 4 | ||
129 | #define WM8350_RTC_ALMDAY_THU 5 | ||
130 | #define WM8350_RTC_ALMDAY_FRI 6 | ||
131 | #define WM8350_RTC_ALMDAY_SAT 7 | ||
132 | |||
133 | #define WM8350_RTC_ALMHPM_AM 0 | ||
134 | #define WM8350_RTC_ALMHPM_PM 1 | ||
135 | |||
136 | #define WM8350_RTC_ALMHRS_DONT_CARE -1 | ||
137 | |||
138 | /* | ||
139 | * R22 (0x16) - Alarm Date/Month | ||
140 | */ | ||
141 | #define WM8350_RTC_ALMMTH_MASK 0x1F00 | ||
142 | #define WM8350_RTC_ALMMTH_SHIFT 8 | ||
143 | #define WM8350_RTC_ALMDATE_MASK 0x003F | ||
144 | #define WM8350_RTC_ALMDATE_SHIFT 0 | ||
145 | |||
146 | /* Bit values for R22 (0x16) */ | ||
147 | #define WM8350_RTC_ALMDATE_DONT_CARE -1 | ||
148 | |||
149 | #define WM8350_RTC_ALMMTH_DONT_CARE -1 | ||
150 | #define WM8350_RTC_ALMMTH_JAN 1 | ||
151 | #define WM8350_RTC_ALMMTH_FEB 2 | ||
152 | #define WM8350_RTC_ALMMTH_MAR 3 | ||
153 | #define WM8350_RTC_ALMMTH_APR 4 | ||
154 | #define WM8350_RTC_ALMMTH_MAY 5 | ||
155 | #define WM8350_RTC_ALMMTH_JUN 6 | ||
156 | #define WM8350_RTC_ALMMTH_JUL 7 | ||
157 | #define WM8350_RTC_ALMMTH_AUG 8 | ||
158 | #define WM8350_RTC_ALMMTH_SEP 9 | ||
159 | #define WM8350_RTC_ALMMTH_OCT 10 | ||
160 | #define WM8350_RTC_ALMMTH_NOV 11 | ||
161 | #define WM8350_RTC_ALMMTH_DEC 12 | ||
162 | #define WM8350_RTC_ALMMTH_JAN_BCD 0x01 | ||
163 | #define WM8350_RTC_ALMMTH_FEB_BCD 0x02 | ||
164 | #define WM8350_RTC_ALMMTH_MAR_BCD 0x03 | ||
165 | #define WM8350_RTC_ALMMTH_APR_BCD 0x04 | ||
166 | #define WM8350_RTC_ALMMTH_MAY_BCD 0x05 | ||
167 | #define WM8350_RTC_ALMMTH_JUN_BCD 0x06 | ||
168 | #define WM8350_RTC_ALMMTH_JUL_BCD 0x07 | ||
169 | #define WM8350_RTC_ALMMTH_AUG_BCD 0x08 | ||
170 | #define WM8350_RTC_ALMMTH_SEP_BCD 0x09 | ||
171 | #define WM8350_RTC_ALMMTH_OCT_BCD 0x10 | ||
172 | #define WM8350_RTC_ALMMTH_NOV_BCD 0x11 | ||
173 | #define WM8350_RTC_ALMMTH_DEC_BCD 0x12 | ||
174 | |||
175 | /* | ||
176 | * R23 (0x17) - RTC Time Control | ||
177 | */ | ||
178 | #define WM8350_RTC_BCD 0x8000 | ||
179 | #define WM8350_RTC_BCD_MASK 0x8000 | ||
180 | #define WM8350_RTC_BCD_SHIFT 15 | ||
181 | #define WM8350_RTC_12HR 0x4000 | ||
182 | #define WM8350_RTC_12HR_MASK 0x4000 | ||
183 | #define WM8350_RTC_12HR_SHIFT 14 | ||
184 | #define WM8350_RTC_DST 0x2000 | ||
185 | #define WM8350_RTC_DST_MASK 0x2000 | ||
186 | #define WM8350_RTC_DST_SHIFT 13 | ||
187 | #define WM8350_RTC_SET 0x0800 | ||
188 | #define WM8350_RTC_SET_MASK 0x0800 | ||
189 | #define WM8350_RTC_SET_SHIFT 11 | ||
190 | #define WM8350_RTC_STS 0x0400 | ||
191 | #define WM8350_RTC_STS_MASK 0x0400 | ||
192 | #define WM8350_RTC_STS_SHIFT 10 | ||
193 | #define WM8350_RTC_ALMSET 0x0200 | ||
194 | #define WM8350_RTC_ALMSET_MASK 0x0200 | ||
195 | #define WM8350_RTC_ALMSET_SHIFT 9 | ||
196 | #define WM8350_RTC_ALMSTS 0x0100 | ||
197 | #define WM8350_RTC_ALMSTS_MASK 0x0100 | ||
198 | #define WM8350_RTC_ALMSTS_SHIFT 8 | ||
199 | #define WM8350_RTC_PINT 0x0070 | ||
200 | #define WM8350_RTC_PINT_MASK 0x0070 | ||
201 | #define WM8350_RTC_PINT_SHIFT 4 | ||
202 | #define WM8350_RTC_DSW 0x000F | ||
203 | #define WM8350_RTC_DSW_MASK 0x000F | ||
204 | #define WM8350_RTC_DSW_SHIFT 0 | ||
205 | |||
206 | /* Bit values for R23 (0x17) */ | ||
207 | #define WM8350_RTC_BCD_BINARY 0 | ||
208 | #define WM8350_RTC_BCD_BCD 1 | ||
209 | |||
210 | #define WM8350_RTC_12HR_24HR 0 | ||
211 | #define WM8350_RTC_12HR_12HR 1 | ||
212 | |||
213 | #define WM8350_RTC_DST_DISABLED 0 | ||
214 | #define WM8350_RTC_DST_ENABLED 1 | ||
215 | |||
216 | #define WM8350_RTC_SET_RUN 0 | ||
217 | #define WM8350_RTC_SET_SET 1 | ||
218 | |||
219 | #define WM8350_RTC_STS_RUNNING 0 | ||
220 | #define WM8350_RTC_STS_STOPPED 1 | ||
221 | |||
222 | #define WM8350_RTC_ALMSET_RUN 0 | ||
223 | #define WM8350_RTC_ALMSET_SET 1 | ||
224 | |||
225 | #define WM8350_RTC_ALMSTS_RUNNING 0 | ||
226 | #define WM8350_RTC_ALMSTS_STOPPED 1 | ||
227 | |||
228 | #define WM8350_RTC_PINT_DISABLED 0 | ||
229 | #define WM8350_RTC_PINT_SECS 1 | ||
230 | #define WM8350_RTC_PINT_MINS 2 | ||
231 | #define WM8350_RTC_PINT_HRS 3 | ||
232 | #define WM8350_RTC_PINT_DAYS 4 | ||
233 | #define WM8350_RTC_PINT_MTHS 5 | ||
234 | |||
235 | #define WM8350_RTC_DSW_DISABLED 0 | ||
236 | #define WM8350_RTC_DSW_1HZ 1 | ||
237 | #define WM8350_RTC_DSW_2HZ 2 | ||
238 | #define WM8350_RTC_DSW_4HZ 3 | ||
239 | #define WM8350_RTC_DSW_8HZ 4 | ||
240 | #define WM8350_RTC_DSW_16HZ 5 | ||
241 | #define WM8350_RTC_DSW_32HZ 6 | ||
242 | #define WM8350_RTC_DSW_64HZ 7 | ||
243 | #define WM8350_RTC_DSW_128HZ 8 | ||
244 | #define WM8350_RTC_DSW_256HZ 9 | ||
245 | #define WM8350_RTC_DSW_512HZ 10 | ||
246 | #define WM8350_RTC_DSW_1024HZ 11 | ||
247 | |||
248 | /* | ||
249 | * R218 (0xDA) - RTC Tick Control | ||
250 | */ | ||
251 | #define WM8350_RTC_TICKSTS 0x4000 | ||
252 | #define WM8350_RTC_CLKSRC 0x2000 | ||
253 | #define WM8350_RTC_TRIM_MASK 0x03FF | ||
254 | |||
255 | /* | ||
256 | * RTC Interrupts. | ||
257 | */ | ||
258 | #define WM8350_IRQ_RTC_PER 7 | ||
259 | #define WM8350_IRQ_RTC_SEC 8 | ||
260 | #define WM8350_IRQ_RTC_ALM 9 | ||
261 | |||
262 | struct wm8350_rtc { | ||
263 | struct platform_device *pdev; | ||
264 | }; | ||
265 | |||
266 | #endif | ||
diff --git a/include/linux/mfd/wm8350/supply.h b/include/linux/mfd/wm8350/supply.h new file mode 100644 index 000000000000..1c8f3cde79b0 --- /dev/null +++ b/include/linux/mfd/wm8350/supply.h | |||
@@ -0,0 +1,111 @@ | |||
1 | /* | ||
2 | * supply.h -- Power Supply Driver for Wolfson WM8350 PMIC | ||
3 | * | ||
4 | * Copyright 2007 Wolfson Microelectronics PLC | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License as published by the | ||
8 | * Free Software Foundation; either version 2 of the License, or (at your | ||
9 | * option) any later version. | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | #ifndef __LINUX_MFD_WM8350_SUPPLY_H_ | ||
14 | #define __LINUX_MFD_WM8350_SUPPLY_H_ | ||
15 | |||
16 | #include <linux/platform_device.h> | ||
17 | |||
18 | /* | ||
19 | * Charger registers | ||
20 | */ | ||
21 | #define WM8350_BATTERY_CHARGER_CONTROL_1 0xA8 | ||
22 | #define WM8350_BATTERY_CHARGER_CONTROL_2 0xA9 | ||
23 | #define WM8350_BATTERY_CHARGER_CONTROL_3 0xAA | ||
24 | |||
25 | /* | ||
26 | * R168 (0xA8) - Battery Charger Control 1 | ||
27 | */ | ||
28 | #define WM8350_CHG_ENA_R168 0x8000 | ||
29 | #define WM8350_CHG_THR 0x2000 | ||
30 | #define WM8350_CHG_EOC_SEL_MASK 0x1C00 | ||
31 | #define WM8350_CHG_TRICKLE_TEMP_CHOKE 0x0200 | ||
32 | #define WM8350_CHG_TRICKLE_USB_CHOKE 0x0100 | ||
33 | #define WM8350_CHG_RECOVER_T 0x0080 | ||
34 | #define WM8350_CHG_END_ACT 0x0040 | ||
35 | #define WM8350_CHG_FAST 0x0020 | ||
36 | #define WM8350_CHG_FAST_USB_THROTTLE 0x0010 | ||
37 | #define WM8350_CHG_NTC_MON 0x0008 | ||
38 | #define WM8350_CHG_BATT_HOT_MON 0x0004 | ||
39 | #define WM8350_CHG_BATT_COLD_MON 0x0002 | ||
40 | #define WM8350_CHG_CHIP_TEMP_MON 0x0001 | ||
41 | |||
42 | /* | ||
43 | * R169 (0xA9) - Battery Charger Control 2 | ||
44 | */ | ||
45 | #define WM8350_CHG_ACTIVE 0x8000 | ||
46 | #define WM8350_CHG_PAUSE 0x4000 | ||
47 | #define WM8350_CHG_STS_MASK 0x3000 | ||
48 | #define WM8350_CHG_TIME_MASK 0x0F00 | ||
49 | #define WM8350_CHG_MASK_WALL_FB 0x0080 | ||
50 | #define WM8350_CHG_TRICKLE_SEL 0x0040 | ||
51 | #define WM8350_CHG_VSEL_MASK 0x0030 | ||
52 | #define WM8350_CHG_ISEL_MASK 0x000F | ||
53 | #define WM8350_CHG_STS_OFF 0x0000 | ||
54 | #define WM8350_CHG_STS_TRICKLE 0x1000 | ||
55 | #define WM8350_CHG_STS_FAST 0x2000 | ||
56 | |||
57 | /* | ||
58 | * R170 (0xAA) - Battery Charger Control 3 | ||
59 | */ | ||
60 | #define WM8350_CHG_THROTTLE_T_MASK 0x0060 | ||
61 | #define WM8350_CHG_SMART 0x0010 | ||
62 | #define WM8350_CHG_TIMER_ADJT_MASK 0x000F | ||
63 | |||
64 | /* | ||
65 | * Charger Interrupts | ||
66 | */ | ||
67 | #define WM8350_IRQ_CHG_BAT_HOT 0 | ||
68 | #define WM8350_IRQ_CHG_BAT_COLD 1 | ||
69 | #define WM8350_IRQ_CHG_BAT_FAIL 2 | ||
70 | #define WM8350_IRQ_CHG_TO 3 | ||
71 | #define WM8350_IRQ_CHG_END 4 | ||
72 | #define WM8350_IRQ_CHG_START 5 | ||
73 | #define WM8350_IRQ_CHG_FAST_RDY 6 | ||
74 | #define WM8350_IRQ_CHG_VBATT_LT_3P9 10 | ||
75 | #define WM8350_IRQ_CHG_VBATT_LT_3P1 11 | ||
76 | #define WM8350_IRQ_CHG_VBATT_LT_2P85 12 | ||
77 | |||
78 | /* | ||
79 | * Charger Policy | ||
80 | */ | ||
81 | #define WM8350_CHG_TRICKLE_50mA (0 << 6) | ||
82 | #define WM8350_CHG_TRICKLE_100mA (1 << 6) | ||
83 | #define WM8350_CHG_4_05V (0 << 4) | ||
84 | #define WM8350_CHG_4_10V (1 << 4) | ||
85 | #define WM8350_CHG_4_15V (2 << 4) | ||
86 | #define WM8350_CHG_4_20V (3 << 4) | ||
87 | #define WM8350_CHG_FAST_LIMIT_mA(x) ((x / 50) & 0xf) | ||
88 | #define WM8350_CHG_EOC_mA(x) (((x - 10) & 0x7) << 10) | ||
89 | #define WM8350_CHG_TRICKLE_3_1V (0 << 13) | ||
90 | #define WM8350_CHG_TRICKLE_3_9V (1 << 13) | ||
91 | |||
92 | /* | ||
93 | * Supply Registers. | ||
94 | */ | ||
95 | #define WM8350_USB_VOLTAGE_READBACK 0x9C | ||
96 | #define WM8350_LINE_VOLTAGE_READBACK 0x9D | ||
97 | #define WM8350_BATT_VOLTAGE_READBACK 0x9E | ||
98 | |||
99 | /* | ||
100 | * Supply Interrupts. | ||
101 | */ | ||
102 | #define WM8350_IRQ_USB_LIMIT 15 | ||
103 | #define WM8350_IRQ_EXT_USB_FB 36 | ||
104 | #define WM8350_IRQ_EXT_WALL_FB 37 | ||
105 | #define WM8350_IRQ_EXT_BAT_FB 38 | ||
106 | |||
107 | struct wm8350_power { | ||
108 | struct platform_device *pdev; | ||
109 | }; | ||
110 | |||
111 | #endif | ||
diff --git a/include/linux/mfd/wm8350/wdt.h b/include/linux/mfd/wm8350/wdt.h new file mode 100644 index 000000000000..f6135b5e5ef4 --- /dev/null +++ b/include/linux/mfd/wm8350/wdt.h | |||
@@ -0,0 +1,28 @@ | |||
1 | /* | ||
2 | * wdt.h -- Watchdog Driver for Wolfson WM8350 PMIC | ||
3 | * | ||
4 | * Copyright 2007, 2008 Wolfson Microelectronics PLC | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License as published by the | ||
8 | * Free Software Foundation; either version 2 of the License, or (at your | ||
9 | * option) any later version. | ||
10 | */ | ||
11 | |||
12 | #ifndef __LINUX_MFD_WM8350_WDT_H_ | ||
13 | #define __LINUX_MFD_WM8350_WDT_H_ | ||
14 | |||
15 | #include <linux/platform_device.h> | ||
16 | |||
17 | #define WM8350_WDOG_HIB_MODE 0x0080 | ||
18 | #define WM8350_WDOG_DEBUG 0x0040 | ||
19 | #define WM8350_WDOG_MODE_MASK 0x0030 | ||
20 | #define WM8350_WDOG_TO_MASK 0x0007 | ||
21 | |||
22 | #define WM8350_IRQ_SYS_WDOG_TO 24 | ||
23 | |||
24 | struct wm8350_wdt { | ||
25 | struct platform_device *pdev; | ||
26 | }; | ||
27 | |||
28 | #endif | ||
diff --git a/include/linux/mfd/wm8400-audio.h b/include/linux/mfd/wm8400-audio.h new file mode 100644 index 000000000000..b6640e018046 --- /dev/null +++ b/include/linux/mfd/wm8400-audio.h | |||
@@ -0,0 +1,1186 @@ | |||
1 | /* | ||
2 | * wm8400 private definitions for audio | ||
3 | * | ||
4 | * Copyright 2008 Wolfson Microelectronics plc | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
19 | */ | ||
20 | |||
21 | #ifndef __LINUX_MFD_WM8400_AUDIO_H | ||
22 | #define __LINUX_MFD_WM8400_AUDIO_H | ||
23 | |||
24 | #include <linux/mfd/wm8400-audio.h> | ||
25 | |||
26 | /* | ||
27 | * R2 (0x02) - Power Management (1) | ||
28 | */ | ||
29 | #define WM8400_CODEC_ENA 0x8000 /* CODEC_ENA */ | ||
30 | #define WM8400_CODEC_ENA_MASK 0x8000 /* CODEC_ENA */ | ||
31 | #define WM8400_CODEC_ENA_SHIFT 15 /* CODEC_ENA */ | ||
32 | #define WM8400_CODEC_ENA_WIDTH 1 /* CODEC_ENA */ | ||
33 | #define WM8400_SYSCLK_ENA 0x4000 /* SYSCLK_ENA */ | ||
34 | #define WM8400_SYSCLK_ENA_MASK 0x4000 /* SYSCLK_ENA */ | ||
35 | #define WM8400_SYSCLK_ENA_SHIFT 14 /* SYSCLK_ENA */ | ||
36 | #define WM8400_SYSCLK_ENA_WIDTH 1 /* SYSCLK_ENA */ | ||
37 | #define WM8400_SPK_MIX_ENA 0x2000 /* SPK_MIX_ENA */ | ||
38 | #define WM8400_SPK_MIX_ENA_MASK 0x2000 /* SPK_MIX_ENA */ | ||
39 | #define WM8400_SPK_MIX_ENA_SHIFT 13 /* SPK_MIX_ENA */ | ||
40 | #define WM8400_SPK_MIX_ENA_WIDTH 1 /* SPK_MIX_ENA */ | ||
41 | #define WM8400_SPK_ENA 0x1000 /* SPK_ENA */ | ||
42 | #define WM8400_SPK_ENA_MASK 0x1000 /* SPK_ENA */ | ||
43 | #define WM8400_SPK_ENA_SHIFT 12 /* SPK_ENA */ | ||
44 | #define WM8400_SPK_ENA_WIDTH 1 /* SPK_ENA */ | ||
45 | #define WM8400_OUT3_ENA 0x0800 /* OUT3_ENA */ | ||
46 | #define WM8400_OUT3_ENA_MASK 0x0800 /* OUT3_ENA */ | ||
47 | #define WM8400_OUT3_ENA_SHIFT 11 /* OUT3_ENA */ | ||
48 | #define WM8400_OUT3_ENA_WIDTH 1 /* OUT3_ENA */ | ||
49 | #define WM8400_OUT4_ENA 0x0400 /* OUT4_ENA */ | ||
50 | #define WM8400_OUT4_ENA_MASK 0x0400 /* OUT4_ENA */ | ||
51 | #define WM8400_OUT4_ENA_SHIFT 10 /* OUT4_ENA */ | ||
52 | #define WM8400_OUT4_ENA_WIDTH 1 /* OUT4_ENA */ | ||
53 | #define WM8400_LOUT_ENA 0x0200 /* LOUT_ENA */ | ||
54 | #define WM8400_LOUT_ENA_MASK 0x0200 /* LOUT_ENA */ | ||
55 | #define WM8400_LOUT_ENA_SHIFT 9 /* LOUT_ENA */ | ||
56 | #define WM8400_LOUT_ENA_WIDTH 1 /* LOUT_ENA */ | ||
57 | #define WM8400_ROUT_ENA 0x0100 /* ROUT_ENA */ | ||
58 | #define WM8400_ROUT_ENA_MASK 0x0100 /* ROUT_ENA */ | ||
59 | #define WM8400_ROUT_ENA_SHIFT 8 /* ROUT_ENA */ | ||
60 | #define WM8400_ROUT_ENA_WIDTH 1 /* ROUT_ENA */ | ||
61 | #define WM8400_MIC1BIAS_ENA 0x0010 /* MIC1BIAS_ENA */ | ||
62 | #define WM8400_MIC1BIAS_ENA_MASK 0x0010 /* MIC1BIAS_ENA */ | ||
63 | #define WM8400_MIC1BIAS_ENA_SHIFT 4 /* MIC1BIAS_ENA */ | ||
64 | #define WM8400_MIC1BIAS_ENA_WIDTH 1 /* MIC1BIAS_ENA */ | ||
65 | #define WM8400_VMID_MODE_MASK 0x0006 /* VMID_MODE - [2:1] */ | ||
66 | #define WM8400_VMID_MODE_SHIFT 1 /* VMID_MODE - [2:1] */ | ||
67 | #define WM8400_VMID_MODE_WIDTH 2 /* VMID_MODE - [2:1] */ | ||
68 | #define WM8400_VREF_ENA 0x0001 /* VREF_ENA */ | ||
69 | #define WM8400_VREF_ENA_MASK 0x0001 /* VREF_ENA */ | ||
70 | #define WM8400_VREF_ENA_SHIFT 0 /* VREF_ENA */ | ||
71 | #define WM8400_VREF_ENA_WIDTH 1 /* VREF_ENA */ | ||
72 | |||
73 | /* | ||
74 | * R3 (0x03) - Power Management (2) | ||
75 | */ | ||
76 | #define WM8400_FLL_ENA 0x8000 /* FLL_ENA */ | ||
77 | #define WM8400_FLL_ENA_MASK 0x8000 /* FLL_ENA */ | ||
78 | #define WM8400_FLL_ENA_SHIFT 15 /* FLL_ENA */ | ||
79 | #define WM8400_FLL_ENA_WIDTH 1 /* FLL_ENA */ | ||
80 | #define WM8400_TSHUT_ENA 0x4000 /* TSHUT_ENA */ | ||
81 | #define WM8400_TSHUT_ENA_MASK 0x4000 /* TSHUT_ENA */ | ||
82 | #define WM8400_TSHUT_ENA_SHIFT 14 /* TSHUT_ENA */ | ||
83 | #define WM8400_TSHUT_ENA_WIDTH 1 /* TSHUT_ENA */ | ||
84 | #define WM8400_TSHUT_OPDIS 0x2000 /* TSHUT_OPDIS */ | ||
85 | #define WM8400_TSHUT_OPDIS_MASK 0x2000 /* TSHUT_OPDIS */ | ||
86 | #define WM8400_TSHUT_OPDIS_SHIFT 13 /* TSHUT_OPDIS */ | ||
87 | #define WM8400_TSHUT_OPDIS_WIDTH 1 /* TSHUT_OPDIS */ | ||
88 | #define WM8400_OPCLK_ENA 0x0800 /* OPCLK_ENA */ | ||
89 | #define WM8400_OPCLK_ENA_MASK 0x0800 /* OPCLK_ENA */ | ||
90 | #define WM8400_OPCLK_ENA_SHIFT 11 /* OPCLK_ENA */ | ||
91 | #define WM8400_OPCLK_ENA_WIDTH 1 /* OPCLK_ENA */ | ||
92 | #define WM8400_AINL_ENA 0x0200 /* AINL_ENA */ | ||
93 | #define WM8400_AINL_ENA_MASK 0x0200 /* AINL_ENA */ | ||
94 | #define WM8400_AINL_ENA_SHIFT 9 /* AINL_ENA */ | ||
95 | #define WM8400_AINL_ENA_WIDTH 1 /* AINL_ENA */ | ||
96 | #define WM8400_AINR_ENA 0x0100 /* AINR_ENA */ | ||
97 | #define WM8400_AINR_ENA_MASK 0x0100 /* AINR_ENA */ | ||
98 | #define WM8400_AINR_ENA_SHIFT 8 /* AINR_ENA */ | ||
99 | #define WM8400_AINR_ENA_WIDTH 1 /* AINR_ENA */ | ||
100 | #define WM8400_LIN34_ENA 0x0080 /* LIN34_ENA */ | ||
101 | #define WM8400_LIN34_ENA_MASK 0x0080 /* LIN34_ENA */ | ||
102 | #define WM8400_LIN34_ENA_SHIFT 7 /* LIN34_ENA */ | ||
103 | #define WM8400_LIN34_ENA_WIDTH 1 /* LIN34_ENA */ | ||
104 | #define WM8400_LIN12_ENA 0x0040 /* LIN12_ENA */ | ||
105 | #define WM8400_LIN12_ENA_MASK 0x0040 /* LIN12_ENA */ | ||
106 | #define WM8400_LIN12_ENA_SHIFT 6 /* LIN12_ENA */ | ||
107 | #define WM8400_LIN12_ENA_WIDTH 1 /* LIN12_ENA */ | ||
108 | #define WM8400_RIN34_ENA 0x0020 /* RIN34_ENA */ | ||
109 | #define WM8400_RIN34_ENA_MASK 0x0020 /* RIN34_ENA */ | ||
110 | #define WM8400_RIN34_ENA_SHIFT 5 /* RIN34_ENA */ | ||
111 | #define WM8400_RIN34_ENA_WIDTH 1 /* RIN34_ENA */ | ||
112 | #define WM8400_RIN12_ENA 0x0010 /* RIN12_ENA */ | ||
113 | #define WM8400_RIN12_ENA_MASK 0x0010 /* RIN12_ENA */ | ||
114 | #define WM8400_RIN12_ENA_SHIFT 4 /* RIN12_ENA */ | ||
115 | #define WM8400_RIN12_ENA_WIDTH 1 /* RIN12_ENA */ | ||
116 | #define WM8400_ADCL_ENA 0x0002 /* ADCL_ENA */ | ||
117 | #define WM8400_ADCL_ENA_MASK 0x0002 /* ADCL_ENA */ | ||
118 | #define WM8400_ADCL_ENA_SHIFT 1 /* ADCL_ENA */ | ||
119 | #define WM8400_ADCL_ENA_WIDTH 1 /* ADCL_ENA */ | ||
120 | #define WM8400_ADCR_ENA 0x0001 /* ADCR_ENA */ | ||
121 | #define WM8400_ADCR_ENA_MASK 0x0001 /* ADCR_ENA */ | ||
122 | #define WM8400_ADCR_ENA_SHIFT 0 /* ADCR_ENA */ | ||
123 | #define WM8400_ADCR_ENA_WIDTH 1 /* ADCR_ENA */ | ||
124 | |||
125 | /* | ||
126 | * R4 (0x04) - Power Management (3) | ||
127 | */ | ||
128 | #define WM8400_LON_ENA 0x2000 /* LON_ENA */ | ||
129 | #define WM8400_LON_ENA_MASK 0x2000 /* LON_ENA */ | ||
130 | #define WM8400_LON_ENA_SHIFT 13 /* LON_ENA */ | ||
131 | #define WM8400_LON_ENA_WIDTH 1 /* LON_ENA */ | ||
132 | #define WM8400_LOP_ENA 0x1000 /* LOP_ENA */ | ||
133 | #define WM8400_LOP_ENA_MASK 0x1000 /* LOP_ENA */ | ||
134 | #define WM8400_LOP_ENA_SHIFT 12 /* LOP_ENA */ | ||
135 | #define WM8400_LOP_ENA_WIDTH 1 /* LOP_ENA */ | ||
136 | #define WM8400_RON_ENA 0x0800 /* RON_ENA */ | ||
137 | #define WM8400_RON_ENA_MASK 0x0800 /* RON_ENA */ | ||
138 | #define WM8400_RON_ENA_SHIFT 11 /* RON_ENA */ | ||
139 | #define WM8400_RON_ENA_WIDTH 1 /* RON_ENA */ | ||
140 | #define WM8400_ROP_ENA 0x0400 /* ROP_ENA */ | ||
141 | #define WM8400_ROP_ENA_MASK 0x0400 /* ROP_ENA */ | ||
142 | #define WM8400_ROP_ENA_SHIFT 10 /* ROP_ENA */ | ||
143 | #define WM8400_ROP_ENA_WIDTH 1 /* ROP_ENA */ | ||
144 | #define WM8400_LOPGA_ENA 0x0080 /* LOPGA_ENA */ | ||
145 | #define WM8400_LOPGA_ENA_MASK 0x0080 /* LOPGA_ENA */ | ||
146 | #define WM8400_LOPGA_ENA_SHIFT 7 /* LOPGA_ENA */ | ||
147 | #define WM8400_LOPGA_ENA_WIDTH 1 /* LOPGA_ENA */ | ||
148 | #define WM8400_ROPGA_ENA 0x0040 /* ROPGA_ENA */ | ||
149 | #define WM8400_ROPGA_ENA_MASK 0x0040 /* ROPGA_ENA */ | ||
150 | #define WM8400_ROPGA_ENA_SHIFT 6 /* ROPGA_ENA */ | ||
151 | #define WM8400_ROPGA_ENA_WIDTH 1 /* ROPGA_ENA */ | ||
152 | #define WM8400_LOMIX_ENA 0x0020 /* LOMIX_ENA */ | ||
153 | #define WM8400_LOMIX_ENA_MASK 0x0020 /* LOMIX_ENA */ | ||
154 | #define WM8400_LOMIX_ENA_SHIFT 5 /* LOMIX_ENA */ | ||
155 | #define WM8400_LOMIX_ENA_WIDTH 1 /* LOMIX_ENA */ | ||
156 | #define WM8400_ROMIX_ENA 0x0010 /* ROMIX_ENA */ | ||
157 | #define WM8400_ROMIX_ENA_MASK 0x0010 /* ROMIX_ENA */ | ||
158 | #define WM8400_ROMIX_ENA_SHIFT 4 /* ROMIX_ENA */ | ||
159 | #define WM8400_ROMIX_ENA_WIDTH 1 /* ROMIX_ENA */ | ||
160 | #define WM8400_DACL_ENA 0x0002 /* DACL_ENA */ | ||
161 | #define WM8400_DACL_ENA_MASK 0x0002 /* DACL_ENA */ | ||
162 | #define WM8400_DACL_ENA_SHIFT 1 /* DACL_ENA */ | ||
163 | #define WM8400_DACL_ENA_WIDTH 1 /* DACL_ENA */ | ||
164 | #define WM8400_DACR_ENA 0x0001 /* DACR_ENA */ | ||
165 | #define WM8400_DACR_ENA_MASK 0x0001 /* DACR_ENA */ | ||
166 | #define WM8400_DACR_ENA_SHIFT 0 /* DACR_ENA */ | ||
167 | #define WM8400_DACR_ENA_WIDTH 1 /* DACR_ENA */ | ||
168 | |||
169 | /* | ||
170 | * R5 (0x05) - Audio Interface (1) | ||
171 | */ | ||
172 | #define WM8400_AIFADCL_SRC 0x8000 /* AIFADCL_SRC */ | ||
173 | #define WM8400_AIFADCL_SRC_MASK 0x8000 /* AIFADCL_SRC */ | ||
174 | #define WM8400_AIFADCL_SRC_SHIFT 15 /* AIFADCL_SRC */ | ||
175 | #define WM8400_AIFADCL_SRC_WIDTH 1 /* AIFADCL_SRC */ | ||
176 | #define WM8400_AIFADCR_SRC 0x4000 /* AIFADCR_SRC */ | ||
177 | #define WM8400_AIFADCR_SRC_MASK 0x4000 /* AIFADCR_SRC */ | ||
178 | #define WM8400_AIFADCR_SRC_SHIFT 14 /* AIFADCR_SRC */ | ||
179 | #define WM8400_AIFADCR_SRC_WIDTH 1 /* AIFADCR_SRC */ | ||
180 | #define WM8400_AIFADC_TDM 0x2000 /* AIFADC_TDM */ | ||
181 | #define WM8400_AIFADC_TDM_MASK 0x2000 /* AIFADC_TDM */ | ||
182 | #define WM8400_AIFADC_TDM_SHIFT 13 /* AIFADC_TDM */ | ||
183 | #define WM8400_AIFADC_TDM_WIDTH 1 /* AIFADC_TDM */ | ||
184 | #define WM8400_AIFADC_TDM_CHAN 0x1000 /* AIFADC_TDM_CHAN */ | ||
185 | #define WM8400_AIFADC_TDM_CHAN_MASK 0x1000 /* AIFADC_TDM_CHAN */ | ||
186 | #define WM8400_AIFADC_TDM_CHAN_SHIFT 12 /* AIFADC_TDM_CHAN */ | ||
187 | #define WM8400_AIFADC_TDM_CHAN_WIDTH 1 /* AIFADC_TDM_CHAN */ | ||
188 | #define WM8400_AIF_BCLK_INV 0x0100 /* AIF_BCLK_INV */ | ||
189 | #define WM8400_AIF_BCLK_INV_MASK 0x0100 /* AIF_BCLK_INV */ | ||
190 | #define WM8400_AIF_BCLK_INV_SHIFT 8 /* AIF_BCLK_INV */ | ||
191 | #define WM8400_AIF_BCLK_INV_WIDTH 1 /* AIF_BCLK_INV */ | ||
192 | #define WM8400_AIF_LRCLK_INV 0x0080 /* AIF_LRCLK_INV */ | ||
193 | #define WM8400_AIF_LRCLK_INV_MASK 0x0080 /* AIF_LRCLK_INV */ | ||
194 | #define WM8400_AIF_LRCLK_INV_SHIFT 7 /* AIF_LRCLK_INV */ | ||
195 | #define WM8400_AIF_LRCLK_INV_WIDTH 1 /* AIF_LRCLK_INV */ | ||
196 | #define WM8400_AIF_WL_MASK 0x0060 /* AIF_WL - [6:5] */ | ||
197 | #define WM8400_AIF_WL_SHIFT 5 /* AIF_WL - [6:5] */ | ||
198 | #define WM8400_AIF_WL_WIDTH 2 /* AIF_WL - [6:5] */ | ||
199 | #define WM8400_AIF_WL_16BITS (0 << 5) | ||
200 | #define WM8400_AIF_WL_20BITS (1 << 5) | ||
201 | #define WM8400_AIF_WL_24BITS (2 << 5) | ||
202 | #define WM8400_AIF_WL_32BITS (3 << 5) | ||
203 | #define WM8400_AIF_FMT_MASK 0x0018 /* AIF_FMT - [4:3] */ | ||
204 | #define WM8400_AIF_FMT_SHIFT 3 /* AIF_FMT - [4:3] */ | ||
205 | #define WM8400_AIF_FMT_WIDTH 2 /* AIF_FMT - [4:3] */ | ||
206 | #define WM8400_AIF_FMT_RIGHTJ (0 << 3) | ||
207 | #define WM8400_AIF_FMT_LEFTJ (1 << 3) | ||
208 | #define WM8400_AIF_FMT_I2S (2 << 3) | ||
209 | #define WM8400_AIF_FMT_DSP (3 << 3) | ||
210 | |||
211 | /* | ||
212 | * R6 (0x06) - Audio Interface (2) | ||
213 | */ | ||
214 | #define WM8400_DACL_SRC 0x8000 /* DACL_SRC */ | ||
215 | #define WM8400_DACL_SRC_MASK 0x8000 /* DACL_SRC */ | ||
216 | #define WM8400_DACL_SRC_SHIFT 15 /* DACL_SRC */ | ||
217 | #define WM8400_DACL_SRC_WIDTH 1 /* DACL_SRC */ | ||
218 | #define WM8400_DACR_SRC 0x4000 /* DACR_SRC */ | ||
219 | #define WM8400_DACR_SRC_MASK 0x4000 /* DACR_SRC */ | ||
220 | #define WM8400_DACR_SRC_SHIFT 14 /* DACR_SRC */ | ||
221 | #define WM8400_DACR_SRC_WIDTH 1 /* DACR_SRC */ | ||
222 | #define WM8400_AIFDAC_TDM 0x2000 /* AIFDAC_TDM */ | ||
223 | #define WM8400_AIFDAC_TDM_MASK 0x2000 /* AIFDAC_TDM */ | ||
224 | #define WM8400_AIFDAC_TDM_SHIFT 13 /* AIFDAC_TDM */ | ||
225 | #define WM8400_AIFDAC_TDM_WIDTH 1 /* AIFDAC_TDM */ | ||
226 | #define WM8400_AIFDAC_TDM_CHAN 0x1000 /* AIFDAC_TDM_CHAN */ | ||
227 | #define WM8400_AIFDAC_TDM_CHAN_MASK 0x1000 /* AIFDAC_TDM_CHAN */ | ||
228 | #define WM8400_AIFDAC_TDM_CHAN_SHIFT 12 /* AIFDAC_TDM_CHAN */ | ||
229 | #define WM8400_AIFDAC_TDM_CHAN_WIDTH 1 /* AIFDAC_TDM_CHAN */ | ||
230 | #define WM8400_DAC_BOOST_MASK 0x0C00 /* DAC_BOOST - [11:10] */ | ||
231 | #define WM8400_DAC_BOOST_SHIFT 10 /* DAC_BOOST - [11:10] */ | ||
232 | #define WM8400_DAC_BOOST_WIDTH 2 /* DAC_BOOST - [11:10] */ | ||
233 | #define WM8400_DAC_COMP 0x0010 /* DAC_COMP */ | ||
234 | #define WM8400_DAC_COMP_MASK 0x0010 /* DAC_COMP */ | ||
235 | #define WM8400_DAC_COMP_SHIFT 4 /* DAC_COMP */ | ||
236 | #define WM8400_DAC_COMP_WIDTH 1 /* DAC_COMP */ | ||
237 | #define WM8400_DAC_COMPMODE 0x0008 /* DAC_COMPMODE */ | ||
238 | #define WM8400_DAC_COMPMODE_MASK 0x0008 /* DAC_COMPMODE */ | ||
239 | #define WM8400_DAC_COMPMODE_SHIFT 3 /* DAC_COMPMODE */ | ||
240 | #define WM8400_DAC_COMPMODE_WIDTH 1 /* DAC_COMPMODE */ | ||
241 | #define WM8400_ADC_COMP 0x0004 /* ADC_COMP */ | ||
242 | #define WM8400_ADC_COMP_MASK 0x0004 /* ADC_COMP */ | ||
243 | #define WM8400_ADC_COMP_SHIFT 2 /* ADC_COMP */ | ||
244 | #define WM8400_ADC_COMP_WIDTH 1 /* ADC_COMP */ | ||
245 | #define WM8400_ADC_COMPMODE 0x0002 /* ADC_COMPMODE */ | ||
246 | #define WM8400_ADC_COMPMODE_MASK 0x0002 /* ADC_COMPMODE */ | ||
247 | #define WM8400_ADC_COMPMODE_SHIFT 1 /* ADC_COMPMODE */ | ||
248 | #define WM8400_ADC_COMPMODE_WIDTH 1 /* ADC_COMPMODE */ | ||
249 | #define WM8400_LOOPBACK 0x0001 /* LOOPBACK */ | ||
250 | #define WM8400_LOOPBACK_MASK 0x0001 /* LOOPBACK */ | ||
251 | #define WM8400_LOOPBACK_SHIFT 0 /* LOOPBACK */ | ||
252 | #define WM8400_LOOPBACK_WIDTH 1 /* LOOPBACK */ | ||
253 | |||
254 | /* | ||
255 | * R7 (0x07) - Clocking (1) | ||
256 | */ | ||
257 | #define WM8400_TOCLK_RATE 0x8000 /* TOCLK_RATE */ | ||
258 | #define WM8400_TOCLK_RATE_MASK 0x8000 /* TOCLK_RATE */ | ||
259 | #define WM8400_TOCLK_RATE_SHIFT 15 /* TOCLK_RATE */ | ||
260 | #define WM8400_TOCLK_RATE_WIDTH 1 /* TOCLK_RATE */ | ||
261 | #define WM8400_TOCLK_ENA 0x4000 /* TOCLK_ENA */ | ||
262 | #define WM8400_TOCLK_ENA_MASK 0x4000 /* TOCLK_ENA */ | ||
263 | #define WM8400_TOCLK_ENA_SHIFT 14 /* TOCLK_ENA */ | ||
264 | #define WM8400_TOCLK_ENA_WIDTH 1 /* TOCLK_ENA */ | ||
265 | #define WM8400_OPCLKDIV_MASK 0x1E00 /* OPCLKDIV - [12:9] */ | ||
266 | #define WM8400_OPCLKDIV_SHIFT 9 /* OPCLKDIV - [12:9] */ | ||
267 | #define WM8400_OPCLKDIV_WIDTH 4 /* OPCLKDIV - [12:9] */ | ||
268 | #define WM8400_DCLKDIV_MASK 0x01C0 /* DCLKDIV - [8:6] */ | ||
269 | #define WM8400_DCLKDIV_SHIFT 6 /* DCLKDIV - [8:6] */ | ||
270 | #define WM8400_DCLKDIV_WIDTH 3 /* DCLKDIV - [8:6] */ | ||
271 | #define WM8400_BCLK_DIV_MASK 0x001E /* BCLK_DIV - [4:1] */ | ||
272 | #define WM8400_BCLK_DIV_SHIFT 1 /* BCLK_DIV - [4:1] */ | ||
273 | #define WM8400_BCLK_DIV_WIDTH 4 /* BCLK_DIV - [4:1] */ | ||
274 | |||
275 | /* | ||
276 | * R8 (0x08) - Clocking (2) | ||
277 | */ | ||
278 | #define WM8400_MCLK_SRC 0x8000 /* MCLK_SRC */ | ||
279 | #define WM8400_MCLK_SRC_MASK 0x8000 /* MCLK_SRC */ | ||
280 | #define WM8400_MCLK_SRC_SHIFT 15 /* MCLK_SRC */ | ||
281 | #define WM8400_MCLK_SRC_WIDTH 1 /* MCLK_SRC */ | ||
282 | #define WM8400_SYSCLK_SRC 0x4000 /* SYSCLK_SRC */ | ||
283 | #define WM8400_SYSCLK_SRC_MASK 0x4000 /* SYSCLK_SRC */ | ||
284 | #define WM8400_SYSCLK_SRC_SHIFT 14 /* SYSCLK_SRC */ | ||
285 | #define WM8400_SYSCLK_SRC_WIDTH 1 /* SYSCLK_SRC */ | ||
286 | #define WM8400_CLK_FORCE 0x2000 /* CLK_FORCE */ | ||
287 | #define WM8400_CLK_FORCE_MASK 0x2000 /* CLK_FORCE */ | ||
288 | #define WM8400_CLK_FORCE_SHIFT 13 /* CLK_FORCE */ | ||
289 | #define WM8400_CLK_FORCE_WIDTH 1 /* CLK_FORCE */ | ||
290 | #define WM8400_MCLK_DIV_MASK 0x1800 /* MCLK_DIV - [12:11] */ | ||
291 | #define WM8400_MCLK_DIV_SHIFT 11 /* MCLK_DIV - [12:11] */ | ||
292 | #define WM8400_MCLK_DIV_WIDTH 2 /* MCLK_DIV - [12:11] */ | ||
293 | #define WM8400_MCLK_INV 0x0400 /* MCLK_INV */ | ||
294 | #define WM8400_MCLK_INV_MASK 0x0400 /* MCLK_INV */ | ||
295 | #define WM8400_MCLK_INV_SHIFT 10 /* MCLK_INV */ | ||
296 | #define WM8400_MCLK_INV_WIDTH 1 /* MCLK_INV */ | ||
297 | #define WM8400_ADC_CLKDIV_MASK 0x00E0 /* ADC_CLKDIV - [7:5] */ | ||
298 | #define WM8400_ADC_CLKDIV_SHIFT 5 /* ADC_CLKDIV - [7:5] */ | ||
299 | #define WM8400_ADC_CLKDIV_WIDTH 3 /* ADC_CLKDIV - [7:5] */ | ||
300 | #define WM8400_DAC_CLKDIV_MASK 0x001C /* DAC_CLKDIV - [4:2] */ | ||
301 | #define WM8400_DAC_CLKDIV_SHIFT 2 /* DAC_CLKDIV - [4:2] */ | ||
302 | #define WM8400_DAC_CLKDIV_WIDTH 3 /* DAC_CLKDIV - [4:2] */ | ||
303 | |||
304 | /* | ||
305 | * R9 (0x09) - Audio Interface (3) | ||
306 | */ | ||
307 | #define WM8400_AIF_MSTR1 0x8000 /* AIF_MSTR1 */ | ||
308 | #define WM8400_AIF_MSTR1_MASK 0x8000 /* AIF_MSTR1 */ | ||
309 | #define WM8400_AIF_MSTR1_SHIFT 15 /* AIF_MSTR1 */ | ||
310 | #define WM8400_AIF_MSTR1_WIDTH 1 /* AIF_MSTR1 */ | ||
311 | #define WM8400_AIF_MSTR2 0x4000 /* AIF_MSTR2 */ | ||
312 | #define WM8400_AIF_MSTR2_MASK 0x4000 /* AIF_MSTR2 */ | ||
313 | #define WM8400_AIF_MSTR2_SHIFT 14 /* AIF_MSTR2 */ | ||
314 | #define WM8400_AIF_MSTR2_WIDTH 1 /* AIF_MSTR2 */ | ||
315 | #define WM8400_AIF_SEL 0x2000 /* AIF_SEL */ | ||
316 | #define WM8400_AIF_SEL_MASK 0x2000 /* AIF_SEL */ | ||
317 | #define WM8400_AIF_SEL_SHIFT 13 /* AIF_SEL */ | ||
318 | #define WM8400_AIF_SEL_WIDTH 1 /* AIF_SEL */ | ||
319 | #define WM8400_ADCLRC_DIR 0x0800 /* ADCLRC_DIR */ | ||
320 | #define WM8400_ADCLRC_DIR_MASK 0x0800 /* ADCLRC_DIR */ | ||
321 | #define WM8400_ADCLRC_DIR_SHIFT 11 /* ADCLRC_DIR */ | ||
322 | #define WM8400_ADCLRC_DIR_WIDTH 1 /* ADCLRC_DIR */ | ||
323 | #define WM8400_ADCLRC_RATE_MASK 0x07FF /* ADCLRC_RATE - [10:0] */ | ||
324 | #define WM8400_ADCLRC_RATE_SHIFT 0 /* ADCLRC_RATE - [10:0] */ | ||
325 | #define WM8400_ADCLRC_RATE_WIDTH 11 /* ADCLRC_RATE - [10:0] */ | ||
326 | |||
327 | /* | ||
328 | * R10 (0x0A) - Audio Interface (4) | ||
329 | */ | ||
330 | #define WM8400_ALRCGPIO1 0x8000 /* ALRCGPIO1 */ | ||
331 | #define WM8400_ALRCGPIO1_MASK 0x8000 /* ALRCGPIO1 */ | ||
332 | #define WM8400_ALRCGPIO1_SHIFT 15 /* ALRCGPIO1 */ | ||
333 | #define WM8400_ALRCGPIO1_WIDTH 1 /* ALRCGPIO1 */ | ||
334 | #define WM8400_ALRCBGPIO6 0x4000 /* ALRCBGPIO6 */ | ||
335 | #define WM8400_ALRCBGPIO6_MASK 0x4000 /* ALRCBGPIO6 */ | ||
336 | #define WM8400_ALRCBGPIO6_SHIFT 14 /* ALRCBGPIO6 */ | ||
337 | #define WM8400_ALRCBGPIO6_WIDTH 1 /* ALRCBGPIO6 */ | ||
338 | #define WM8400_AIF_TRIS 0x2000 /* AIF_TRIS */ | ||
339 | #define WM8400_AIF_TRIS_MASK 0x2000 /* AIF_TRIS */ | ||
340 | #define WM8400_AIF_TRIS_SHIFT 13 /* AIF_TRIS */ | ||
341 | #define WM8400_AIF_TRIS_WIDTH 1 /* AIF_TRIS */ | ||
342 | #define WM8400_DACLRC_DIR 0x0800 /* DACLRC_DIR */ | ||
343 | #define WM8400_DACLRC_DIR_MASK 0x0800 /* DACLRC_DIR */ | ||
344 | #define WM8400_DACLRC_DIR_SHIFT 11 /* DACLRC_DIR */ | ||
345 | #define WM8400_DACLRC_DIR_WIDTH 1 /* DACLRC_DIR */ | ||
346 | #define WM8400_DACLRC_RATE_MASK 0x07FF /* DACLRC_RATE - [10:0] */ | ||
347 | #define WM8400_DACLRC_RATE_SHIFT 0 /* DACLRC_RATE - [10:0] */ | ||
348 | #define WM8400_DACLRC_RATE_WIDTH 11 /* DACLRC_RATE - [10:0] */ | ||
349 | |||
350 | /* | ||
351 | * R11 (0x0B) - DAC CTRL | ||
352 | */ | ||
353 | #define WM8400_DAC_SDMCLK_RATE 0x2000 /* DAC_SDMCLK_RATE */ | ||
354 | #define WM8400_DAC_SDMCLK_RATE_MASK 0x2000 /* DAC_SDMCLK_RATE */ | ||
355 | #define WM8400_DAC_SDMCLK_RATE_SHIFT 13 /* DAC_SDMCLK_RATE */ | ||
356 | #define WM8400_DAC_SDMCLK_RATE_WIDTH 1 /* DAC_SDMCLK_RATE */ | ||
357 | #define WM8400_AIF_LRCLKRATE 0x0400 /* AIF_LRCLKRATE */ | ||
358 | #define WM8400_AIF_LRCLKRATE_MASK 0x0400 /* AIF_LRCLKRATE */ | ||
359 | #define WM8400_AIF_LRCLKRATE_SHIFT 10 /* AIF_LRCLKRATE */ | ||
360 | #define WM8400_AIF_LRCLKRATE_WIDTH 1 /* AIF_LRCLKRATE */ | ||
361 | #define WM8400_DAC_MONO 0x0200 /* DAC_MONO */ | ||
362 | #define WM8400_DAC_MONO_MASK 0x0200 /* DAC_MONO */ | ||
363 | #define WM8400_DAC_MONO_SHIFT 9 /* DAC_MONO */ | ||
364 | #define WM8400_DAC_MONO_WIDTH 1 /* DAC_MONO */ | ||
365 | #define WM8400_DAC_SB_FILT 0x0100 /* DAC_SB_FILT */ | ||
366 | #define WM8400_DAC_SB_FILT_MASK 0x0100 /* DAC_SB_FILT */ | ||
367 | #define WM8400_DAC_SB_FILT_SHIFT 8 /* DAC_SB_FILT */ | ||
368 | #define WM8400_DAC_SB_FILT_WIDTH 1 /* DAC_SB_FILT */ | ||
369 | #define WM8400_DAC_MUTERATE 0x0080 /* DAC_MUTERATE */ | ||
370 | #define WM8400_DAC_MUTERATE_MASK 0x0080 /* DAC_MUTERATE */ | ||
371 | #define WM8400_DAC_MUTERATE_SHIFT 7 /* DAC_MUTERATE */ | ||
372 | #define WM8400_DAC_MUTERATE_WIDTH 1 /* DAC_MUTERATE */ | ||
373 | #define WM8400_DAC_MUTEMODE 0x0040 /* DAC_MUTEMODE */ | ||
374 | #define WM8400_DAC_MUTEMODE_MASK 0x0040 /* DAC_MUTEMODE */ | ||
375 | #define WM8400_DAC_MUTEMODE_SHIFT 6 /* DAC_MUTEMODE */ | ||
376 | #define WM8400_DAC_MUTEMODE_WIDTH 1 /* DAC_MUTEMODE */ | ||
377 | #define WM8400_DEEMP_MASK 0x0030 /* DEEMP - [5:4] */ | ||
378 | #define WM8400_DEEMP_SHIFT 4 /* DEEMP - [5:4] */ | ||
379 | #define WM8400_DEEMP_WIDTH 2 /* DEEMP - [5:4] */ | ||
380 | #define WM8400_DAC_MUTE 0x0004 /* DAC_MUTE */ | ||
381 | #define WM8400_DAC_MUTE_MASK 0x0004 /* DAC_MUTE */ | ||
382 | #define WM8400_DAC_MUTE_SHIFT 2 /* DAC_MUTE */ | ||
383 | #define WM8400_DAC_MUTE_WIDTH 1 /* DAC_MUTE */ | ||
384 | #define WM8400_DACL_DATINV 0x0002 /* DACL_DATINV */ | ||
385 | #define WM8400_DACL_DATINV_MASK 0x0002 /* DACL_DATINV */ | ||
386 | #define WM8400_DACL_DATINV_SHIFT 1 /* DACL_DATINV */ | ||
387 | #define WM8400_DACL_DATINV_WIDTH 1 /* DACL_DATINV */ | ||
388 | #define WM8400_DACR_DATINV 0x0001 /* DACR_DATINV */ | ||
389 | #define WM8400_DACR_DATINV_MASK 0x0001 /* DACR_DATINV */ | ||
390 | #define WM8400_DACR_DATINV_SHIFT 0 /* DACR_DATINV */ | ||
391 | #define WM8400_DACR_DATINV_WIDTH 1 /* DACR_DATINV */ | ||
392 | |||
393 | /* | ||
394 | * R12 (0x0C) - Left DAC Digital Volume | ||
395 | */ | ||
396 | #define WM8400_DAC_VU 0x0100 /* DAC_VU */ | ||
397 | #define WM8400_DAC_VU_MASK 0x0100 /* DAC_VU */ | ||
398 | #define WM8400_DAC_VU_SHIFT 8 /* DAC_VU */ | ||
399 | #define WM8400_DAC_VU_WIDTH 1 /* DAC_VU */ | ||
400 | #define WM8400_DACL_VOL_MASK 0x00FF /* DACL_VOL - [7:0] */ | ||
401 | #define WM8400_DACL_VOL_SHIFT 0 /* DACL_VOL - [7:0] */ | ||
402 | #define WM8400_DACL_VOL_WIDTH 8 /* DACL_VOL - [7:0] */ | ||
403 | |||
404 | /* | ||
405 | * R13 (0x0D) - Right DAC Digital Volume | ||
406 | */ | ||
407 | #define WM8400_DAC_VU 0x0100 /* DAC_VU */ | ||
408 | #define WM8400_DAC_VU_MASK 0x0100 /* DAC_VU */ | ||
409 | #define WM8400_DAC_VU_SHIFT 8 /* DAC_VU */ | ||
410 | #define WM8400_DAC_VU_WIDTH 1 /* DAC_VU */ | ||
411 | #define WM8400_DACR_VOL_MASK 0x00FF /* DACR_VOL - [7:0] */ | ||
412 | #define WM8400_DACR_VOL_SHIFT 0 /* DACR_VOL - [7:0] */ | ||
413 | #define WM8400_DACR_VOL_WIDTH 8 /* DACR_VOL - [7:0] */ | ||
414 | |||
415 | /* | ||
416 | * R14 (0x0E) - Digital Side Tone | ||
417 | */ | ||
418 | #define WM8400_ADCL_DAC_SVOL_MASK 0x1E00 /* ADCL_DAC_SVOL - [12:9] */ | ||
419 | #define WM8400_ADCL_DAC_SVOL_SHIFT 9 /* ADCL_DAC_SVOL - [12:9] */ | ||
420 | #define WM8400_ADCL_DAC_SVOL_WIDTH 4 /* ADCL_DAC_SVOL - [12:9] */ | ||
421 | #define WM8400_ADCR_DAC_SVOL_MASK 0x01E0 /* ADCR_DAC_SVOL - [8:5] */ | ||
422 | #define WM8400_ADCR_DAC_SVOL_SHIFT 5 /* ADCR_DAC_SVOL - [8:5] */ | ||
423 | #define WM8400_ADCR_DAC_SVOL_WIDTH 4 /* ADCR_DAC_SVOL - [8:5] */ | ||
424 | #define WM8400_ADC_TO_DACL_MASK 0x000C /* ADC_TO_DACL - [3:2] */ | ||
425 | #define WM8400_ADC_TO_DACL_SHIFT 2 /* ADC_TO_DACL - [3:2] */ | ||
426 | #define WM8400_ADC_TO_DACL_WIDTH 2 /* ADC_TO_DACL - [3:2] */ | ||
427 | #define WM8400_ADC_TO_DACR_MASK 0x0003 /* ADC_TO_DACR - [1:0] */ | ||
428 | #define WM8400_ADC_TO_DACR_SHIFT 0 /* ADC_TO_DACR - [1:0] */ | ||
429 | #define WM8400_ADC_TO_DACR_WIDTH 2 /* ADC_TO_DACR - [1:0] */ | ||
430 | |||
431 | /* | ||
432 | * R15 (0x0F) - ADC CTRL | ||
433 | */ | ||
434 | #define WM8400_ADC_HPF_ENA 0x0100 /* ADC_HPF_ENA */ | ||
435 | #define WM8400_ADC_HPF_ENA_MASK 0x0100 /* ADC_HPF_ENA */ | ||
436 | #define WM8400_ADC_HPF_ENA_SHIFT 8 /* ADC_HPF_ENA */ | ||
437 | #define WM8400_ADC_HPF_ENA_WIDTH 1 /* ADC_HPF_ENA */ | ||
438 | #define WM8400_ADC_HPF_CUT_MASK 0x0060 /* ADC_HPF_CUT - [6:5] */ | ||
439 | #define WM8400_ADC_HPF_CUT_SHIFT 5 /* ADC_HPF_CUT - [6:5] */ | ||
440 | #define WM8400_ADC_HPF_CUT_WIDTH 2 /* ADC_HPF_CUT - [6:5] */ | ||
441 | #define WM8400_ADCL_DATINV 0x0002 /* ADCL_DATINV */ | ||
442 | #define WM8400_ADCL_DATINV_MASK 0x0002 /* ADCL_DATINV */ | ||
443 | #define WM8400_ADCL_DATINV_SHIFT 1 /* ADCL_DATINV */ | ||
444 | #define WM8400_ADCL_DATINV_WIDTH 1 /* ADCL_DATINV */ | ||
445 | #define WM8400_ADCR_DATINV 0x0001 /* ADCR_DATINV */ | ||
446 | #define WM8400_ADCR_DATINV_MASK 0x0001 /* ADCR_DATINV */ | ||
447 | #define WM8400_ADCR_DATINV_SHIFT 0 /* ADCR_DATINV */ | ||
448 | #define WM8400_ADCR_DATINV_WIDTH 1 /* ADCR_DATINV */ | ||
449 | |||
450 | /* | ||
451 | * R16 (0x10) - Left ADC Digital Volume | ||
452 | */ | ||
453 | #define WM8400_ADC_VU 0x0100 /* ADC_VU */ | ||
454 | #define WM8400_ADC_VU_MASK 0x0100 /* ADC_VU */ | ||
455 | #define WM8400_ADC_VU_SHIFT 8 /* ADC_VU */ | ||
456 | #define WM8400_ADC_VU_WIDTH 1 /* ADC_VU */ | ||
457 | #define WM8400_ADCL_VOL_MASK 0x00FF /* ADCL_VOL - [7:0] */ | ||
458 | #define WM8400_ADCL_VOL_SHIFT 0 /* ADCL_VOL - [7:0] */ | ||
459 | #define WM8400_ADCL_VOL_WIDTH 8 /* ADCL_VOL - [7:0] */ | ||
460 | |||
461 | /* | ||
462 | * R17 (0x11) - Right ADC Digital Volume | ||
463 | */ | ||
464 | #define WM8400_ADC_VU 0x0100 /* ADC_VU */ | ||
465 | #define WM8400_ADC_VU_MASK 0x0100 /* ADC_VU */ | ||
466 | #define WM8400_ADC_VU_SHIFT 8 /* ADC_VU */ | ||
467 | #define WM8400_ADC_VU_WIDTH 1 /* ADC_VU */ | ||
468 | #define WM8400_ADCR_VOL_MASK 0x00FF /* ADCR_VOL - [7:0] */ | ||
469 | #define WM8400_ADCR_VOL_SHIFT 0 /* ADCR_VOL - [7:0] */ | ||
470 | #define WM8400_ADCR_VOL_WIDTH 8 /* ADCR_VOL - [7:0] */ | ||
471 | |||
472 | /* | ||
473 | * R24 (0x18) - Left Line Input 1&2 Volume | ||
474 | */ | ||
475 | #define WM8400_IPVU 0x0100 /* IPVU */ | ||
476 | #define WM8400_IPVU_MASK 0x0100 /* IPVU */ | ||
477 | #define WM8400_IPVU_SHIFT 8 /* IPVU */ | ||
478 | #define WM8400_IPVU_WIDTH 1 /* IPVU */ | ||
479 | #define WM8400_LI12MUTE 0x0080 /* LI12MUTE */ | ||
480 | #define WM8400_LI12MUTE_MASK 0x0080 /* LI12MUTE */ | ||
481 | #define WM8400_LI12MUTE_SHIFT 7 /* LI12MUTE */ | ||
482 | #define WM8400_LI12MUTE_WIDTH 1 /* LI12MUTE */ | ||
483 | #define WM8400_LI12ZC 0x0040 /* LI12ZC */ | ||
484 | #define WM8400_LI12ZC_MASK 0x0040 /* LI12ZC */ | ||
485 | #define WM8400_LI12ZC_SHIFT 6 /* LI12ZC */ | ||
486 | #define WM8400_LI12ZC_WIDTH 1 /* LI12ZC */ | ||
487 | #define WM8400_LIN12VOL_MASK 0x001F /* LIN12VOL - [4:0] */ | ||
488 | #define WM8400_LIN12VOL_SHIFT 0 /* LIN12VOL - [4:0] */ | ||
489 | #define WM8400_LIN12VOL_WIDTH 5 /* LIN12VOL - [4:0] */ | ||
490 | |||
491 | /* | ||
492 | * R25 (0x19) - Left Line Input 3&4 Volume | ||
493 | */ | ||
494 | #define WM8400_IPVU 0x0100 /* IPVU */ | ||
495 | #define WM8400_IPVU_MASK 0x0100 /* IPVU */ | ||
496 | #define WM8400_IPVU_SHIFT 8 /* IPVU */ | ||
497 | #define WM8400_IPVU_WIDTH 1 /* IPVU */ | ||
498 | #define WM8400_LI34MUTE 0x0080 /* LI34MUTE */ | ||
499 | #define WM8400_LI34MUTE_MASK 0x0080 /* LI34MUTE */ | ||
500 | #define WM8400_LI34MUTE_SHIFT 7 /* LI34MUTE */ | ||
501 | #define WM8400_LI34MUTE_WIDTH 1 /* LI34MUTE */ | ||
502 | #define WM8400_LI34ZC 0x0040 /* LI34ZC */ | ||
503 | #define WM8400_LI34ZC_MASK 0x0040 /* LI34ZC */ | ||
504 | #define WM8400_LI34ZC_SHIFT 6 /* LI34ZC */ | ||
505 | #define WM8400_LI34ZC_WIDTH 1 /* LI34ZC */ | ||
506 | #define WM8400_LIN34VOL_MASK 0x001F /* LIN34VOL - [4:0] */ | ||
507 | #define WM8400_LIN34VOL_SHIFT 0 /* LIN34VOL - [4:0] */ | ||
508 | #define WM8400_LIN34VOL_WIDTH 5 /* LIN34VOL - [4:0] */ | ||
509 | |||
510 | /* | ||
511 | * R26 (0x1A) - Right Line Input 1&2 Volume | ||
512 | */ | ||
513 | #define WM8400_IPVU 0x0100 /* IPVU */ | ||
514 | #define WM8400_IPVU_MASK 0x0100 /* IPVU */ | ||
515 | #define WM8400_IPVU_SHIFT 8 /* IPVU */ | ||
516 | #define WM8400_IPVU_WIDTH 1 /* IPVU */ | ||
517 | #define WM8400_RI12MUTE 0x0080 /* RI12MUTE */ | ||
518 | #define WM8400_RI12MUTE_MASK 0x0080 /* RI12MUTE */ | ||
519 | #define WM8400_RI12MUTE_SHIFT 7 /* RI12MUTE */ | ||
520 | #define WM8400_RI12MUTE_WIDTH 1 /* RI12MUTE */ | ||
521 | #define WM8400_RI12ZC 0x0040 /* RI12ZC */ | ||
522 | #define WM8400_RI12ZC_MASK 0x0040 /* RI12ZC */ | ||
523 | #define WM8400_RI12ZC_SHIFT 6 /* RI12ZC */ | ||
524 | #define WM8400_RI12ZC_WIDTH 1 /* RI12ZC */ | ||
525 | #define WM8400_RIN12VOL_MASK 0x001F /* RIN12VOL - [4:0] */ | ||
526 | #define WM8400_RIN12VOL_SHIFT 0 /* RIN12VOL - [4:0] */ | ||
527 | #define WM8400_RIN12VOL_WIDTH 5 /* RIN12VOL - [4:0] */ | ||
528 | |||
529 | /* | ||
530 | * R27 (0x1B) - Right Line Input 3&4 Volume | ||
531 | */ | ||
532 | #define WM8400_IPVU 0x0100 /* IPVU */ | ||
533 | #define WM8400_IPVU_MASK 0x0100 /* IPVU */ | ||
534 | #define WM8400_IPVU_SHIFT 8 /* IPVU */ | ||
535 | #define WM8400_IPVU_WIDTH 1 /* IPVU */ | ||
536 | #define WM8400_RI34MUTE 0x0080 /* RI34MUTE */ | ||
537 | #define WM8400_RI34MUTE_MASK 0x0080 /* RI34MUTE */ | ||
538 | #define WM8400_RI34MUTE_SHIFT 7 /* RI34MUTE */ | ||
539 | #define WM8400_RI34MUTE_WIDTH 1 /* RI34MUTE */ | ||
540 | #define WM8400_RI34ZC 0x0040 /* RI34ZC */ | ||
541 | #define WM8400_RI34ZC_MASK 0x0040 /* RI34ZC */ | ||
542 | #define WM8400_RI34ZC_SHIFT 6 /* RI34ZC */ | ||
543 | #define WM8400_RI34ZC_WIDTH 1 /* RI34ZC */ | ||
544 | #define WM8400_RIN34VOL_MASK 0x001F /* RIN34VOL - [4:0] */ | ||
545 | #define WM8400_RIN34VOL_SHIFT 0 /* RIN34VOL - [4:0] */ | ||
546 | #define WM8400_RIN34VOL_WIDTH 5 /* RIN34VOL - [4:0] */ | ||
547 | |||
548 | /* | ||
549 | * R28 (0x1C) - Left Output Volume | ||
550 | */ | ||
551 | #define WM8400_OPVU 0x0100 /* OPVU */ | ||
552 | #define WM8400_OPVU_MASK 0x0100 /* OPVU */ | ||
553 | #define WM8400_OPVU_SHIFT 8 /* OPVU */ | ||
554 | #define WM8400_OPVU_WIDTH 1 /* OPVU */ | ||
555 | #define WM8400_LOZC 0x0080 /* LOZC */ | ||
556 | #define WM8400_LOZC_MASK 0x0080 /* LOZC */ | ||
557 | #define WM8400_LOZC_SHIFT 7 /* LOZC */ | ||
558 | #define WM8400_LOZC_WIDTH 1 /* LOZC */ | ||
559 | #define WM8400_LOUTVOL_MASK 0x007F /* LOUTVOL - [6:0] */ | ||
560 | #define WM8400_LOUTVOL_SHIFT 0 /* LOUTVOL - [6:0] */ | ||
561 | #define WM8400_LOUTVOL_WIDTH 7 /* LOUTVOL - [6:0] */ | ||
562 | |||
563 | /* | ||
564 | * R29 (0x1D) - Right Output Volume | ||
565 | */ | ||
566 | #define WM8400_OPVU 0x0100 /* OPVU */ | ||
567 | #define WM8400_OPVU_MASK 0x0100 /* OPVU */ | ||
568 | #define WM8400_OPVU_SHIFT 8 /* OPVU */ | ||
569 | #define WM8400_OPVU_WIDTH 1 /* OPVU */ | ||
570 | #define WM8400_ROZC 0x0080 /* ROZC */ | ||
571 | #define WM8400_ROZC_MASK 0x0080 /* ROZC */ | ||
572 | #define WM8400_ROZC_SHIFT 7 /* ROZC */ | ||
573 | #define WM8400_ROZC_WIDTH 1 /* ROZC */ | ||
574 | #define WM8400_ROUTVOL_MASK 0x007F /* ROUTVOL - [6:0] */ | ||
575 | #define WM8400_ROUTVOL_SHIFT 0 /* ROUTVOL - [6:0] */ | ||
576 | #define WM8400_ROUTVOL_WIDTH 7 /* ROUTVOL - [6:0] */ | ||
577 | |||
578 | /* | ||
579 | * R30 (0x1E) - Line Outputs Volume | ||
580 | */ | ||
581 | #define WM8400_LONMUTE 0x0040 /* LONMUTE */ | ||
582 | #define WM8400_LONMUTE_MASK 0x0040 /* LONMUTE */ | ||
583 | #define WM8400_LONMUTE_SHIFT 6 /* LONMUTE */ | ||
584 | #define WM8400_LONMUTE_WIDTH 1 /* LONMUTE */ | ||
585 | #define WM8400_LOPMUTE 0x0020 /* LOPMUTE */ | ||
586 | #define WM8400_LOPMUTE_MASK 0x0020 /* LOPMUTE */ | ||
587 | #define WM8400_LOPMUTE_SHIFT 5 /* LOPMUTE */ | ||
588 | #define WM8400_LOPMUTE_WIDTH 1 /* LOPMUTE */ | ||
589 | #define WM8400_LOATTN 0x0010 /* LOATTN */ | ||
590 | #define WM8400_LOATTN_MASK 0x0010 /* LOATTN */ | ||
591 | #define WM8400_LOATTN_SHIFT 4 /* LOATTN */ | ||
592 | #define WM8400_LOATTN_WIDTH 1 /* LOATTN */ | ||
593 | #define WM8400_RONMUTE 0x0004 /* RONMUTE */ | ||
594 | #define WM8400_RONMUTE_MASK 0x0004 /* RONMUTE */ | ||
595 | #define WM8400_RONMUTE_SHIFT 2 /* RONMUTE */ | ||
596 | #define WM8400_RONMUTE_WIDTH 1 /* RONMUTE */ | ||
597 | #define WM8400_ROPMUTE 0x0002 /* ROPMUTE */ | ||
598 | #define WM8400_ROPMUTE_MASK 0x0002 /* ROPMUTE */ | ||
599 | #define WM8400_ROPMUTE_SHIFT 1 /* ROPMUTE */ | ||
600 | #define WM8400_ROPMUTE_WIDTH 1 /* ROPMUTE */ | ||
601 | #define WM8400_ROATTN 0x0001 /* ROATTN */ | ||
602 | #define WM8400_ROATTN_MASK 0x0001 /* ROATTN */ | ||
603 | #define WM8400_ROATTN_SHIFT 0 /* ROATTN */ | ||
604 | #define WM8400_ROATTN_WIDTH 1 /* ROATTN */ | ||
605 | |||
606 | /* | ||
607 | * R31 (0x1F) - Out3/4 Volume | ||
608 | */ | ||
609 | #define WM8400_OUT3MUTE 0x0020 /* OUT3MUTE */ | ||
610 | #define WM8400_OUT3MUTE_MASK 0x0020 /* OUT3MUTE */ | ||
611 | #define WM8400_OUT3MUTE_SHIFT 5 /* OUT3MUTE */ | ||
612 | #define WM8400_OUT3MUTE_WIDTH 1 /* OUT3MUTE */ | ||
613 | #define WM8400_OUT3ATTN 0x0010 /* OUT3ATTN */ | ||
614 | #define WM8400_OUT3ATTN_MASK 0x0010 /* OUT3ATTN */ | ||
615 | #define WM8400_OUT3ATTN_SHIFT 4 /* OUT3ATTN */ | ||
616 | #define WM8400_OUT3ATTN_WIDTH 1 /* OUT3ATTN */ | ||
617 | #define WM8400_OUT4MUTE 0x0002 /* OUT4MUTE */ | ||
618 | #define WM8400_OUT4MUTE_MASK 0x0002 /* OUT4MUTE */ | ||
619 | #define WM8400_OUT4MUTE_SHIFT 1 /* OUT4MUTE */ | ||
620 | #define WM8400_OUT4MUTE_WIDTH 1 /* OUT4MUTE */ | ||
621 | #define WM8400_OUT4ATTN 0x0001 /* OUT4ATTN */ | ||
622 | #define WM8400_OUT4ATTN_MASK 0x0001 /* OUT4ATTN */ | ||
623 | #define WM8400_OUT4ATTN_SHIFT 0 /* OUT4ATTN */ | ||
624 | #define WM8400_OUT4ATTN_WIDTH 1 /* OUT4ATTN */ | ||
625 | |||
626 | /* | ||
627 | * R32 (0x20) - Left OPGA Volume | ||
628 | */ | ||
629 | #define WM8400_OPVU 0x0100 /* OPVU */ | ||
630 | #define WM8400_OPVU_MASK 0x0100 /* OPVU */ | ||
631 | #define WM8400_OPVU_SHIFT 8 /* OPVU */ | ||
632 | #define WM8400_OPVU_WIDTH 1 /* OPVU */ | ||
633 | #define WM8400_LOPGAZC 0x0080 /* LOPGAZC */ | ||
634 | #define WM8400_LOPGAZC_MASK 0x0080 /* LOPGAZC */ | ||
635 | #define WM8400_LOPGAZC_SHIFT 7 /* LOPGAZC */ | ||
636 | #define WM8400_LOPGAZC_WIDTH 1 /* LOPGAZC */ | ||
637 | #define WM8400_LOPGAVOL_MASK 0x007F /* LOPGAVOL - [6:0] */ | ||
638 | #define WM8400_LOPGAVOL_SHIFT 0 /* LOPGAVOL - [6:0] */ | ||
639 | #define WM8400_LOPGAVOL_WIDTH 7 /* LOPGAVOL - [6:0] */ | ||
640 | |||
641 | /* | ||
642 | * R33 (0x21) - Right OPGA Volume | ||
643 | */ | ||
644 | #define WM8400_OPVU 0x0100 /* OPVU */ | ||
645 | #define WM8400_OPVU_MASK 0x0100 /* OPVU */ | ||
646 | #define WM8400_OPVU_SHIFT 8 /* OPVU */ | ||
647 | #define WM8400_OPVU_WIDTH 1 /* OPVU */ | ||
648 | #define WM8400_ROPGAZC 0x0080 /* ROPGAZC */ | ||
649 | #define WM8400_ROPGAZC_MASK 0x0080 /* ROPGAZC */ | ||
650 | #define WM8400_ROPGAZC_SHIFT 7 /* ROPGAZC */ | ||
651 | #define WM8400_ROPGAZC_WIDTH 1 /* ROPGAZC */ | ||
652 | #define WM8400_ROPGAVOL_MASK 0x007F /* ROPGAVOL - [6:0] */ | ||
653 | #define WM8400_ROPGAVOL_SHIFT 0 /* ROPGAVOL - [6:0] */ | ||
654 | #define WM8400_ROPGAVOL_WIDTH 7 /* ROPGAVOL - [6:0] */ | ||
655 | |||
656 | /* | ||
657 | * R34 (0x22) - Speaker Volume | ||
658 | */ | ||
659 | #define WM8400_SPKATTN_MASK 0x0003 /* SPKATTN - [1:0] */ | ||
660 | #define WM8400_SPKATTN_SHIFT 0 /* SPKATTN - [1:0] */ | ||
661 | #define WM8400_SPKATTN_WIDTH 2 /* SPKATTN - [1:0] */ | ||
662 | |||
663 | /* | ||
664 | * R35 (0x23) - ClassD1 | ||
665 | */ | ||
666 | #define WM8400_CDMODE 0x0100 /* CDMODE */ | ||
667 | #define WM8400_CDMODE_MASK 0x0100 /* CDMODE */ | ||
668 | #define WM8400_CDMODE_SHIFT 8 /* CDMODE */ | ||
669 | #define WM8400_CDMODE_WIDTH 1 /* CDMODE */ | ||
670 | #define WM8400_CLASSD_CLK_SEL 0x0080 /* CLASSD_CLK_SEL */ | ||
671 | #define WM8400_CLASSD_CLK_SEL_MASK 0x0080 /* CLASSD_CLK_SEL */ | ||
672 | #define WM8400_CLASSD_CLK_SEL_SHIFT 7 /* CLASSD_CLK_SEL */ | ||
673 | #define WM8400_CLASSD_CLK_SEL_WIDTH 1 /* CLASSD_CLK_SEL */ | ||
674 | #define WM8400_CD_SRCTRL 0x0040 /* CD_SRCTRL */ | ||
675 | #define WM8400_CD_SRCTRL_MASK 0x0040 /* CD_SRCTRL */ | ||
676 | #define WM8400_CD_SRCTRL_SHIFT 6 /* CD_SRCTRL */ | ||
677 | #define WM8400_CD_SRCTRL_WIDTH 1 /* CD_SRCTRL */ | ||
678 | #define WM8400_SPKNOPOP 0x0020 /* SPKNOPOP */ | ||
679 | #define WM8400_SPKNOPOP_MASK 0x0020 /* SPKNOPOP */ | ||
680 | #define WM8400_SPKNOPOP_SHIFT 5 /* SPKNOPOP */ | ||
681 | #define WM8400_SPKNOPOP_WIDTH 1 /* SPKNOPOP */ | ||
682 | #define WM8400_DBLERATE 0x0010 /* DBLERATE */ | ||
683 | #define WM8400_DBLERATE_MASK 0x0010 /* DBLERATE */ | ||
684 | #define WM8400_DBLERATE_SHIFT 4 /* DBLERATE */ | ||
685 | #define WM8400_DBLERATE_WIDTH 1 /* DBLERATE */ | ||
686 | #define WM8400_LOOPTEST 0x0008 /* LOOPTEST */ | ||
687 | #define WM8400_LOOPTEST_MASK 0x0008 /* LOOPTEST */ | ||
688 | #define WM8400_LOOPTEST_SHIFT 3 /* LOOPTEST */ | ||
689 | #define WM8400_LOOPTEST_WIDTH 1 /* LOOPTEST */ | ||
690 | #define WM8400_HALFABBIAS 0x0004 /* HALFABBIAS */ | ||
691 | #define WM8400_HALFABBIAS_MASK 0x0004 /* HALFABBIAS */ | ||
692 | #define WM8400_HALFABBIAS_SHIFT 2 /* HALFABBIAS */ | ||
693 | #define WM8400_HALFABBIAS_WIDTH 1 /* HALFABBIAS */ | ||
694 | #define WM8400_TRIDEL_MASK 0x0003 /* TRIDEL - [1:0] */ | ||
695 | #define WM8400_TRIDEL_SHIFT 0 /* TRIDEL - [1:0] */ | ||
696 | #define WM8400_TRIDEL_WIDTH 2 /* TRIDEL - [1:0] */ | ||
697 | |||
698 | /* | ||
699 | * R37 (0x25) - ClassD3 | ||
700 | */ | ||
701 | #define WM8400_DCGAIN_MASK 0x0038 /* DCGAIN - [5:3] */ | ||
702 | #define WM8400_DCGAIN_SHIFT 3 /* DCGAIN - [5:3] */ | ||
703 | #define WM8400_DCGAIN_WIDTH 3 /* DCGAIN - [5:3] */ | ||
704 | #define WM8400_ACGAIN_MASK 0x0007 /* ACGAIN - [2:0] */ | ||
705 | #define WM8400_ACGAIN_SHIFT 0 /* ACGAIN - [2:0] */ | ||
706 | #define WM8400_ACGAIN_WIDTH 3 /* ACGAIN - [2:0] */ | ||
707 | |||
708 | /* | ||
709 | * R39 (0x27) - Input Mixer1 | ||
710 | */ | ||
711 | #define WM8400_AINLMODE_MASK 0x000C /* AINLMODE - [3:2] */ | ||
712 | #define WM8400_AINLMODE_SHIFT 2 /* AINLMODE - [3:2] */ | ||
713 | #define WM8400_AINLMODE_WIDTH 2 /* AINLMODE - [3:2] */ | ||
714 | #define WM8400_AINRMODE_MASK 0x0003 /* AINRMODE - [1:0] */ | ||
715 | #define WM8400_AINRMODE_SHIFT 0 /* AINRMODE - [1:0] */ | ||
716 | #define WM8400_AINRMODE_WIDTH 2 /* AINRMODE - [1:0] */ | ||
717 | |||
718 | /* | ||
719 | * R40 (0x28) - Input Mixer2 | ||
720 | */ | ||
721 | #define WM8400_LMP4 0x0080 /* LMP4 */ | ||
722 | #define WM8400_LMP4_MASK 0x0080 /* LMP4 */ | ||
723 | #define WM8400_LMP4_SHIFT 7 /* LMP4 */ | ||
724 | #define WM8400_LMP4_WIDTH 1 /* LMP4 */ | ||
725 | #define WM8400_LMN3 0x0040 /* LMN3 */ | ||
726 | #define WM8400_LMN3_MASK 0x0040 /* LMN3 */ | ||
727 | #define WM8400_LMN3_SHIFT 6 /* LMN3 */ | ||
728 | #define WM8400_LMN3_WIDTH 1 /* LMN3 */ | ||
729 | #define WM8400_LMP2 0x0020 /* LMP2 */ | ||
730 | #define WM8400_LMP2_MASK 0x0020 /* LMP2 */ | ||
731 | #define WM8400_LMP2_SHIFT 5 /* LMP2 */ | ||
732 | #define WM8400_LMP2_WIDTH 1 /* LMP2 */ | ||
733 | #define WM8400_LMN1 0x0010 /* LMN1 */ | ||
734 | #define WM8400_LMN1_MASK 0x0010 /* LMN1 */ | ||
735 | #define WM8400_LMN1_SHIFT 4 /* LMN1 */ | ||
736 | #define WM8400_LMN1_WIDTH 1 /* LMN1 */ | ||
737 | #define WM8400_RMP4 0x0008 /* RMP4 */ | ||
738 | #define WM8400_RMP4_MASK 0x0008 /* RMP4 */ | ||
739 | #define WM8400_RMP4_SHIFT 3 /* RMP4 */ | ||
740 | #define WM8400_RMP4_WIDTH 1 /* RMP4 */ | ||
741 | #define WM8400_RMN3 0x0004 /* RMN3 */ | ||
742 | #define WM8400_RMN3_MASK 0x0004 /* RMN3 */ | ||
743 | #define WM8400_RMN3_SHIFT 2 /* RMN3 */ | ||
744 | #define WM8400_RMN3_WIDTH 1 /* RMN3 */ | ||
745 | #define WM8400_RMP2 0x0002 /* RMP2 */ | ||
746 | #define WM8400_RMP2_MASK 0x0002 /* RMP2 */ | ||
747 | #define WM8400_RMP2_SHIFT 1 /* RMP2 */ | ||
748 | #define WM8400_RMP2_WIDTH 1 /* RMP2 */ | ||
749 | #define WM8400_RMN1 0x0001 /* RMN1 */ | ||
750 | #define WM8400_RMN1_MASK 0x0001 /* RMN1 */ | ||
751 | #define WM8400_RMN1_SHIFT 0 /* RMN1 */ | ||
752 | #define WM8400_RMN1_WIDTH 1 /* RMN1 */ | ||
753 | |||
754 | /* | ||
755 | * R41 (0x29) - Input Mixer3 | ||
756 | */ | ||
757 | #define WM8400_L34MNB 0x0100 /* L34MNB */ | ||
758 | #define WM8400_L34MNB_MASK 0x0100 /* L34MNB */ | ||
759 | #define WM8400_L34MNB_SHIFT 8 /* L34MNB */ | ||
760 | #define WM8400_L34MNB_WIDTH 1 /* L34MNB */ | ||
761 | #define WM8400_L34MNBST 0x0080 /* L34MNBST */ | ||
762 | #define WM8400_L34MNBST_MASK 0x0080 /* L34MNBST */ | ||
763 | #define WM8400_L34MNBST_SHIFT 7 /* L34MNBST */ | ||
764 | #define WM8400_L34MNBST_WIDTH 1 /* L34MNBST */ | ||
765 | #define WM8400_L12MNB 0x0020 /* L12MNB */ | ||
766 | #define WM8400_L12MNB_MASK 0x0020 /* L12MNB */ | ||
767 | #define WM8400_L12MNB_SHIFT 5 /* L12MNB */ | ||
768 | #define WM8400_L12MNB_WIDTH 1 /* L12MNB */ | ||
769 | #define WM8400_L12MNBST 0x0010 /* L12MNBST */ | ||
770 | #define WM8400_L12MNBST_MASK 0x0010 /* L12MNBST */ | ||
771 | #define WM8400_L12MNBST_SHIFT 4 /* L12MNBST */ | ||
772 | #define WM8400_L12MNBST_WIDTH 1 /* L12MNBST */ | ||
773 | #define WM8400_LDBVOL_MASK 0x0007 /* LDBVOL - [2:0] */ | ||
774 | #define WM8400_LDBVOL_SHIFT 0 /* LDBVOL - [2:0] */ | ||
775 | #define WM8400_LDBVOL_WIDTH 3 /* LDBVOL - [2:0] */ | ||
776 | |||
777 | /* | ||
778 | * R42 (0x2A) - Input Mixer4 | ||
779 | */ | ||
780 | #define WM8400_R34MNB 0x0100 /* R34MNB */ | ||
781 | #define WM8400_R34MNB_MASK 0x0100 /* R34MNB */ | ||
782 | #define WM8400_R34MNB_SHIFT 8 /* R34MNB */ | ||
783 | #define WM8400_R34MNB_WIDTH 1 /* R34MNB */ | ||
784 | #define WM8400_R34MNBST 0x0080 /* R34MNBST */ | ||
785 | #define WM8400_R34MNBST_MASK 0x0080 /* R34MNBST */ | ||
786 | #define WM8400_R34MNBST_SHIFT 7 /* R34MNBST */ | ||
787 | #define WM8400_R34MNBST_WIDTH 1 /* R34MNBST */ | ||
788 | #define WM8400_R12MNB 0x0020 /* R12MNB */ | ||
789 | #define WM8400_R12MNB_MASK 0x0020 /* R12MNB */ | ||
790 | #define WM8400_R12MNB_SHIFT 5 /* R12MNB */ | ||
791 | #define WM8400_R12MNB_WIDTH 1 /* R12MNB */ | ||
792 | #define WM8400_R12MNBST 0x0010 /* R12MNBST */ | ||
793 | #define WM8400_R12MNBST_MASK 0x0010 /* R12MNBST */ | ||
794 | #define WM8400_R12MNBST_SHIFT 4 /* R12MNBST */ | ||
795 | #define WM8400_R12MNBST_WIDTH 1 /* R12MNBST */ | ||
796 | #define WM8400_RDBVOL_MASK 0x0007 /* RDBVOL - [2:0] */ | ||
797 | #define WM8400_RDBVOL_SHIFT 0 /* RDBVOL - [2:0] */ | ||
798 | #define WM8400_RDBVOL_WIDTH 3 /* RDBVOL - [2:0] */ | ||
799 | |||
800 | /* | ||
801 | * R43 (0x2B) - Input Mixer5 | ||
802 | */ | ||
803 | #define WM8400_LI2BVOL_MASK 0x01C0 /* LI2BVOL - [8:6] */ | ||
804 | #define WM8400_LI2BVOL_SHIFT 6 /* LI2BVOL - [8:6] */ | ||
805 | #define WM8400_LI2BVOL_WIDTH 3 /* LI2BVOL - [8:6] */ | ||
806 | #define WM8400_LR4BVOL_MASK 0x0038 /* LR4BVOL - [5:3] */ | ||
807 | #define WM8400_LR4BVOL_SHIFT 3 /* LR4BVOL - [5:3] */ | ||
808 | #define WM8400_LR4BVOL_WIDTH 3 /* LR4BVOL - [5:3] */ | ||
809 | #define WM8400_LL4BVOL_MASK 0x0007 /* LL4BVOL - [2:0] */ | ||
810 | #define WM8400_LL4BVOL_SHIFT 0 /* LL4BVOL - [2:0] */ | ||
811 | #define WM8400_LL4BVOL_WIDTH 3 /* LL4BVOL - [2:0] */ | ||
812 | |||
813 | /* | ||
814 | * R44 (0x2C) - Input Mixer6 | ||
815 | */ | ||
816 | #define WM8400_RI2BVOL_MASK 0x01C0 /* RI2BVOL - [8:6] */ | ||
817 | #define WM8400_RI2BVOL_SHIFT 6 /* RI2BVOL - [8:6] */ | ||
818 | #define WM8400_RI2BVOL_WIDTH 3 /* RI2BVOL - [8:6] */ | ||
819 | #define WM8400_RL4BVOL_MASK 0x0038 /* RL4BVOL - [5:3] */ | ||
820 | #define WM8400_RL4BVOL_SHIFT 3 /* RL4BVOL - [5:3] */ | ||
821 | #define WM8400_RL4BVOL_WIDTH 3 /* RL4BVOL - [5:3] */ | ||
822 | #define WM8400_RR4BVOL_MASK 0x0007 /* RR4BVOL - [2:0] */ | ||
823 | #define WM8400_RR4BVOL_SHIFT 0 /* RR4BVOL - [2:0] */ | ||
824 | #define WM8400_RR4BVOL_WIDTH 3 /* RR4BVOL - [2:0] */ | ||
825 | |||
826 | /* | ||
827 | * R45 (0x2D) - Output Mixer1 | ||
828 | */ | ||
829 | #define WM8400_LRBLO 0x0080 /* LRBLO */ | ||
830 | #define WM8400_LRBLO_MASK 0x0080 /* LRBLO */ | ||
831 | #define WM8400_LRBLO_SHIFT 7 /* LRBLO */ | ||
832 | #define WM8400_LRBLO_WIDTH 1 /* LRBLO */ | ||
833 | #define WM8400_LLBLO 0x0040 /* LLBLO */ | ||
834 | #define WM8400_LLBLO_MASK 0x0040 /* LLBLO */ | ||
835 | #define WM8400_LLBLO_SHIFT 6 /* LLBLO */ | ||
836 | #define WM8400_LLBLO_WIDTH 1 /* LLBLO */ | ||
837 | #define WM8400_LRI3LO 0x0020 /* LRI3LO */ | ||
838 | #define WM8400_LRI3LO_MASK 0x0020 /* LRI3LO */ | ||
839 | #define WM8400_LRI3LO_SHIFT 5 /* LRI3LO */ | ||
840 | #define WM8400_LRI3LO_WIDTH 1 /* LRI3LO */ | ||
841 | #define WM8400_LLI3LO 0x0010 /* LLI3LO */ | ||
842 | #define WM8400_LLI3LO_MASK 0x0010 /* LLI3LO */ | ||
843 | #define WM8400_LLI3LO_SHIFT 4 /* LLI3LO */ | ||
844 | #define WM8400_LLI3LO_WIDTH 1 /* LLI3LO */ | ||
845 | #define WM8400_LR12LO 0x0008 /* LR12LO */ | ||
846 | #define WM8400_LR12LO_MASK 0x0008 /* LR12LO */ | ||
847 | #define WM8400_LR12LO_SHIFT 3 /* LR12LO */ | ||
848 | #define WM8400_LR12LO_WIDTH 1 /* LR12LO */ | ||
849 | #define WM8400_LL12LO 0x0004 /* LL12LO */ | ||
850 | #define WM8400_LL12LO_MASK 0x0004 /* LL12LO */ | ||
851 | #define WM8400_LL12LO_SHIFT 2 /* LL12LO */ | ||
852 | #define WM8400_LL12LO_WIDTH 1 /* LL12LO */ | ||
853 | #define WM8400_LDLO 0x0001 /* LDLO */ | ||
854 | #define WM8400_LDLO_MASK 0x0001 /* LDLO */ | ||
855 | #define WM8400_LDLO_SHIFT 0 /* LDLO */ | ||
856 | #define WM8400_LDLO_WIDTH 1 /* LDLO */ | ||
857 | |||
858 | /* | ||
859 | * R46 (0x2E) - Output Mixer2 | ||
860 | */ | ||
861 | #define WM8400_RLBRO 0x0080 /* RLBRO */ | ||
862 | #define WM8400_RLBRO_MASK 0x0080 /* RLBRO */ | ||
863 | #define WM8400_RLBRO_SHIFT 7 /* RLBRO */ | ||
864 | #define WM8400_RLBRO_WIDTH 1 /* RLBRO */ | ||
865 | #define WM8400_RRBRO 0x0040 /* RRBRO */ | ||
866 | #define WM8400_RRBRO_MASK 0x0040 /* RRBRO */ | ||
867 | #define WM8400_RRBRO_SHIFT 6 /* RRBRO */ | ||
868 | #define WM8400_RRBRO_WIDTH 1 /* RRBRO */ | ||
869 | #define WM8400_RLI3RO 0x0020 /* RLI3RO */ | ||
870 | #define WM8400_RLI3RO_MASK 0x0020 /* RLI3RO */ | ||
871 | #define WM8400_RLI3RO_SHIFT 5 /* RLI3RO */ | ||
872 | #define WM8400_RLI3RO_WIDTH 1 /* RLI3RO */ | ||
873 | #define WM8400_RRI3RO 0x0010 /* RRI3RO */ | ||
874 | #define WM8400_RRI3RO_MASK 0x0010 /* RRI3RO */ | ||
875 | #define WM8400_RRI3RO_SHIFT 4 /* RRI3RO */ | ||
876 | #define WM8400_RRI3RO_WIDTH 1 /* RRI3RO */ | ||
877 | #define WM8400_RL12RO 0x0008 /* RL12RO */ | ||
878 | #define WM8400_RL12RO_MASK 0x0008 /* RL12RO */ | ||
879 | #define WM8400_RL12RO_SHIFT 3 /* RL12RO */ | ||
880 | #define WM8400_RL12RO_WIDTH 1 /* RL12RO */ | ||
881 | #define WM8400_RR12RO 0x0004 /* RR12RO */ | ||
882 | #define WM8400_RR12RO_MASK 0x0004 /* RR12RO */ | ||
883 | #define WM8400_RR12RO_SHIFT 2 /* RR12RO */ | ||
884 | #define WM8400_RR12RO_WIDTH 1 /* RR12RO */ | ||
885 | #define WM8400_RDRO 0x0001 /* RDRO */ | ||
886 | #define WM8400_RDRO_MASK 0x0001 /* RDRO */ | ||
887 | #define WM8400_RDRO_SHIFT 0 /* RDRO */ | ||
888 | #define WM8400_RDRO_WIDTH 1 /* RDRO */ | ||
889 | |||
890 | /* | ||
891 | * R47 (0x2F) - Output Mixer3 | ||
892 | */ | ||
893 | #define WM8400_LLI3LOVOL_MASK 0x01C0 /* LLI3LOVOL - [8:6] */ | ||
894 | #define WM8400_LLI3LOVOL_SHIFT 6 /* LLI3LOVOL - [8:6] */ | ||
895 | #define WM8400_LLI3LOVOL_WIDTH 3 /* LLI3LOVOL - [8:6] */ | ||
896 | #define WM8400_LR12LOVOL_MASK 0x0038 /* LR12LOVOL - [5:3] */ | ||
897 | #define WM8400_LR12LOVOL_SHIFT 3 /* LR12LOVOL - [5:3] */ | ||
898 | #define WM8400_LR12LOVOL_WIDTH 3 /* LR12LOVOL - [5:3] */ | ||
899 | #define WM8400_LL12LOVOL_MASK 0x0007 /* LL12LOVOL - [2:0] */ | ||
900 | #define WM8400_LL12LOVOL_SHIFT 0 /* LL12LOVOL - [2:0] */ | ||
901 | #define WM8400_LL12LOVOL_WIDTH 3 /* LL12LOVOL - [2:0] */ | ||
902 | |||
903 | /* | ||
904 | * R48 (0x30) - Output Mixer4 | ||
905 | */ | ||
906 | #define WM8400_RRI3ROVOL_MASK 0x01C0 /* RRI3ROVOL - [8:6] */ | ||
907 | #define WM8400_RRI3ROVOL_SHIFT 6 /* RRI3ROVOL - [8:6] */ | ||
908 | #define WM8400_RRI3ROVOL_WIDTH 3 /* RRI3ROVOL - [8:6] */ | ||
909 | #define WM8400_RL12ROVOL_MASK 0x0038 /* RL12ROVOL - [5:3] */ | ||
910 | #define WM8400_RL12ROVOL_SHIFT 3 /* RL12ROVOL - [5:3] */ | ||
911 | #define WM8400_RL12ROVOL_WIDTH 3 /* RL12ROVOL - [5:3] */ | ||
912 | #define WM8400_RR12ROVOL_MASK 0x0007 /* RR12ROVOL - [2:0] */ | ||
913 | #define WM8400_RR12ROVOL_SHIFT 0 /* RR12ROVOL - [2:0] */ | ||
914 | #define WM8400_RR12ROVOL_WIDTH 3 /* RR12ROVOL - [2:0] */ | ||
915 | |||
916 | /* | ||
917 | * R49 (0x31) - Output Mixer5 | ||
918 | */ | ||
919 | #define WM8400_LRI3LOVOL_MASK 0x01C0 /* LRI3LOVOL - [8:6] */ | ||
920 | #define WM8400_LRI3LOVOL_SHIFT 6 /* LRI3LOVOL - [8:6] */ | ||
921 | #define WM8400_LRI3LOVOL_WIDTH 3 /* LRI3LOVOL - [8:6] */ | ||
922 | #define WM8400_LRBLOVOL_MASK 0x0038 /* LRBLOVOL - [5:3] */ | ||
923 | #define WM8400_LRBLOVOL_SHIFT 3 /* LRBLOVOL - [5:3] */ | ||
924 | #define WM8400_LRBLOVOL_WIDTH 3 /* LRBLOVOL - [5:3] */ | ||
925 | #define WM8400_LLBLOVOL_MASK 0x0007 /* LLBLOVOL - [2:0] */ | ||
926 | #define WM8400_LLBLOVOL_SHIFT 0 /* LLBLOVOL - [2:0] */ | ||
927 | #define WM8400_LLBLOVOL_WIDTH 3 /* LLBLOVOL - [2:0] */ | ||
928 | |||
929 | /* | ||
930 | * R50 (0x32) - Output Mixer6 | ||
931 | */ | ||
932 | #define WM8400_RLI3ROVOL_MASK 0x01C0 /* RLI3ROVOL - [8:6] */ | ||
933 | #define WM8400_RLI3ROVOL_SHIFT 6 /* RLI3ROVOL - [8:6] */ | ||
934 | #define WM8400_RLI3ROVOL_WIDTH 3 /* RLI3ROVOL - [8:6] */ | ||
935 | #define WM8400_RLBROVOL_MASK 0x0038 /* RLBROVOL - [5:3] */ | ||
936 | #define WM8400_RLBROVOL_SHIFT 3 /* RLBROVOL - [5:3] */ | ||
937 | #define WM8400_RLBROVOL_WIDTH 3 /* RLBROVOL - [5:3] */ | ||
938 | #define WM8400_RRBROVOL_MASK 0x0007 /* RRBROVOL - [2:0] */ | ||
939 | #define WM8400_RRBROVOL_SHIFT 0 /* RRBROVOL - [2:0] */ | ||
940 | #define WM8400_RRBROVOL_WIDTH 3 /* RRBROVOL - [2:0] */ | ||
941 | |||
942 | /* | ||
943 | * R51 (0x33) - Out3/4 Mixer | ||
944 | */ | ||
945 | #define WM8400_VSEL_MASK 0x0180 /* VSEL - [8:7] */ | ||
946 | #define WM8400_VSEL_SHIFT 7 /* VSEL - [8:7] */ | ||
947 | #define WM8400_VSEL_WIDTH 2 /* VSEL - [8:7] */ | ||
948 | #define WM8400_LI4O3 0x0020 /* LI4O3 */ | ||
949 | #define WM8400_LI4O3_MASK 0x0020 /* LI4O3 */ | ||
950 | #define WM8400_LI4O3_SHIFT 5 /* LI4O3 */ | ||
951 | #define WM8400_LI4O3_WIDTH 1 /* LI4O3 */ | ||
952 | #define WM8400_LPGAO3 0x0010 /* LPGAO3 */ | ||
953 | #define WM8400_LPGAO3_MASK 0x0010 /* LPGAO3 */ | ||
954 | #define WM8400_LPGAO3_SHIFT 4 /* LPGAO3 */ | ||
955 | #define WM8400_LPGAO3_WIDTH 1 /* LPGAO3 */ | ||
956 | #define WM8400_RI4O4 0x0002 /* RI4O4 */ | ||
957 | #define WM8400_RI4O4_MASK 0x0002 /* RI4O4 */ | ||
958 | #define WM8400_RI4O4_SHIFT 1 /* RI4O4 */ | ||
959 | #define WM8400_RI4O4_WIDTH 1 /* RI4O4 */ | ||
960 | #define WM8400_RPGAO4 0x0001 /* RPGAO4 */ | ||
961 | #define WM8400_RPGAO4_MASK 0x0001 /* RPGAO4 */ | ||
962 | #define WM8400_RPGAO4_SHIFT 0 /* RPGAO4 */ | ||
963 | #define WM8400_RPGAO4_WIDTH 1 /* RPGAO4 */ | ||
964 | |||
965 | /* | ||
966 | * R52 (0x34) - Line Mixer1 | ||
967 | */ | ||
968 | #define WM8400_LLOPGALON 0x0040 /* LLOPGALON */ | ||
969 | #define WM8400_LLOPGALON_MASK 0x0040 /* LLOPGALON */ | ||
970 | #define WM8400_LLOPGALON_SHIFT 6 /* LLOPGALON */ | ||
971 | #define WM8400_LLOPGALON_WIDTH 1 /* LLOPGALON */ | ||
972 | #define WM8400_LROPGALON 0x0020 /* LROPGALON */ | ||
973 | #define WM8400_LROPGALON_MASK 0x0020 /* LROPGALON */ | ||
974 | #define WM8400_LROPGALON_SHIFT 5 /* LROPGALON */ | ||
975 | #define WM8400_LROPGALON_WIDTH 1 /* LROPGALON */ | ||
976 | #define WM8400_LOPLON 0x0010 /* LOPLON */ | ||
977 | #define WM8400_LOPLON_MASK 0x0010 /* LOPLON */ | ||
978 | #define WM8400_LOPLON_SHIFT 4 /* LOPLON */ | ||
979 | #define WM8400_LOPLON_WIDTH 1 /* LOPLON */ | ||
980 | #define WM8400_LR12LOP 0x0004 /* LR12LOP */ | ||
981 | #define WM8400_LR12LOP_MASK 0x0004 /* LR12LOP */ | ||
982 | #define WM8400_LR12LOP_SHIFT 2 /* LR12LOP */ | ||
983 | #define WM8400_LR12LOP_WIDTH 1 /* LR12LOP */ | ||
984 | #define WM8400_LL12LOP 0x0002 /* LL12LOP */ | ||
985 | #define WM8400_LL12LOP_MASK 0x0002 /* LL12LOP */ | ||
986 | #define WM8400_LL12LOP_SHIFT 1 /* LL12LOP */ | ||
987 | #define WM8400_LL12LOP_WIDTH 1 /* LL12LOP */ | ||
988 | #define WM8400_LLOPGALOP 0x0001 /* LLOPGALOP */ | ||
989 | #define WM8400_LLOPGALOP_MASK 0x0001 /* LLOPGALOP */ | ||
990 | #define WM8400_LLOPGALOP_SHIFT 0 /* LLOPGALOP */ | ||
991 | #define WM8400_LLOPGALOP_WIDTH 1 /* LLOPGALOP */ | ||
992 | |||
993 | /* | ||
994 | * R53 (0x35) - Line Mixer2 | ||
995 | */ | ||
996 | #define WM8400_RROPGARON 0x0040 /* RROPGARON */ | ||
997 | #define WM8400_RROPGARON_MASK 0x0040 /* RROPGARON */ | ||
998 | #define WM8400_RROPGARON_SHIFT 6 /* RROPGARON */ | ||
999 | #define WM8400_RROPGARON_WIDTH 1 /* RROPGARON */ | ||
1000 | #define WM8400_RLOPGARON 0x0020 /* RLOPGARON */ | ||
1001 | #define WM8400_RLOPGARON_MASK 0x0020 /* RLOPGARON */ | ||
1002 | #define WM8400_RLOPGARON_SHIFT 5 /* RLOPGARON */ | ||
1003 | #define WM8400_RLOPGARON_WIDTH 1 /* RLOPGARON */ | ||
1004 | #define WM8400_ROPRON 0x0010 /* ROPRON */ | ||
1005 | #define WM8400_ROPRON_MASK 0x0010 /* ROPRON */ | ||
1006 | #define WM8400_ROPRON_SHIFT 4 /* ROPRON */ | ||
1007 | #define WM8400_ROPRON_WIDTH 1 /* ROPRON */ | ||
1008 | #define WM8400_RL12ROP 0x0004 /* RL12ROP */ | ||
1009 | #define WM8400_RL12ROP_MASK 0x0004 /* RL12ROP */ | ||
1010 | #define WM8400_RL12ROP_SHIFT 2 /* RL12ROP */ | ||
1011 | #define WM8400_RL12ROP_WIDTH 1 /* RL12ROP */ | ||
1012 | #define WM8400_RR12ROP 0x0002 /* RR12ROP */ | ||
1013 | #define WM8400_RR12ROP_MASK 0x0002 /* RR12ROP */ | ||
1014 | #define WM8400_RR12ROP_SHIFT 1 /* RR12ROP */ | ||
1015 | #define WM8400_RR12ROP_WIDTH 1 /* RR12ROP */ | ||
1016 | #define WM8400_RROPGAROP 0x0001 /* RROPGAROP */ | ||
1017 | #define WM8400_RROPGAROP_MASK 0x0001 /* RROPGAROP */ | ||
1018 | #define WM8400_RROPGAROP_SHIFT 0 /* RROPGAROP */ | ||
1019 | #define WM8400_RROPGAROP_WIDTH 1 /* RROPGAROP */ | ||
1020 | |||
1021 | /* | ||
1022 | * R54 (0x36) - Speaker Mixer | ||
1023 | */ | ||
1024 | #define WM8400_LB2SPK 0x0080 /* LB2SPK */ | ||
1025 | #define WM8400_LB2SPK_MASK 0x0080 /* LB2SPK */ | ||
1026 | #define WM8400_LB2SPK_SHIFT 7 /* LB2SPK */ | ||
1027 | #define WM8400_LB2SPK_WIDTH 1 /* LB2SPK */ | ||
1028 | #define WM8400_RB2SPK 0x0040 /* RB2SPK */ | ||
1029 | #define WM8400_RB2SPK_MASK 0x0040 /* RB2SPK */ | ||
1030 | #define WM8400_RB2SPK_SHIFT 6 /* RB2SPK */ | ||
1031 | #define WM8400_RB2SPK_WIDTH 1 /* RB2SPK */ | ||
1032 | #define WM8400_LI2SPK 0x0020 /* LI2SPK */ | ||
1033 | #define WM8400_LI2SPK_MASK 0x0020 /* LI2SPK */ | ||
1034 | #define WM8400_LI2SPK_SHIFT 5 /* LI2SPK */ | ||
1035 | #define WM8400_LI2SPK_WIDTH 1 /* LI2SPK */ | ||
1036 | #define WM8400_RI2SPK 0x0010 /* RI2SPK */ | ||
1037 | #define WM8400_RI2SPK_MASK 0x0010 /* RI2SPK */ | ||
1038 | #define WM8400_RI2SPK_SHIFT 4 /* RI2SPK */ | ||
1039 | #define WM8400_RI2SPK_WIDTH 1 /* RI2SPK */ | ||
1040 | #define WM8400_LOPGASPK 0x0008 /* LOPGASPK */ | ||
1041 | #define WM8400_LOPGASPK_MASK 0x0008 /* LOPGASPK */ | ||
1042 | #define WM8400_LOPGASPK_SHIFT 3 /* LOPGASPK */ | ||
1043 | #define WM8400_LOPGASPK_WIDTH 1 /* LOPGASPK */ | ||
1044 | #define WM8400_ROPGASPK 0x0004 /* ROPGASPK */ | ||
1045 | #define WM8400_ROPGASPK_MASK 0x0004 /* ROPGASPK */ | ||
1046 | #define WM8400_ROPGASPK_SHIFT 2 /* ROPGASPK */ | ||
1047 | #define WM8400_ROPGASPK_WIDTH 1 /* ROPGASPK */ | ||
1048 | #define WM8400_LDSPK 0x0002 /* LDSPK */ | ||
1049 | #define WM8400_LDSPK_MASK 0x0002 /* LDSPK */ | ||
1050 | #define WM8400_LDSPK_SHIFT 1 /* LDSPK */ | ||
1051 | #define WM8400_LDSPK_WIDTH 1 /* LDSPK */ | ||
1052 | #define WM8400_RDSPK 0x0001 /* RDSPK */ | ||
1053 | #define WM8400_RDSPK_MASK 0x0001 /* RDSPK */ | ||
1054 | #define WM8400_RDSPK_SHIFT 0 /* RDSPK */ | ||
1055 | #define WM8400_RDSPK_WIDTH 1 /* RDSPK */ | ||
1056 | |||
1057 | /* | ||
1058 | * R55 (0x37) - Additional Control | ||
1059 | */ | ||
1060 | #define WM8400_VROI 0x0001 /* VROI */ | ||
1061 | #define WM8400_VROI_MASK 0x0001 /* VROI */ | ||
1062 | #define WM8400_VROI_SHIFT 0 /* VROI */ | ||
1063 | #define WM8400_VROI_WIDTH 1 /* VROI */ | ||
1064 | |||
1065 | /* | ||
1066 | * R56 (0x38) - AntiPOP1 | ||
1067 | */ | ||
1068 | #define WM8400_DIS_LLINE 0x0020 /* DIS_LLINE */ | ||
1069 | #define WM8400_DIS_LLINE_MASK 0x0020 /* DIS_LLINE */ | ||
1070 | #define WM8400_DIS_LLINE_SHIFT 5 /* DIS_LLINE */ | ||
1071 | #define WM8400_DIS_LLINE_WIDTH 1 /* DIS_LLINE */ | ||
1072 | #define WM8400_DIS_RLINE 0x0010 /* DIS_RLINE */ | ||
1073 | #define WM8400_DIS_RLINE_MASK 0x0010 /* DIS_RLINE */ | ||
1074 | #define WM8400_DIS_RLINE_SHIFT 4 /* DIS_RLINE */ | ||
1075 | #define WM8400_DIS_RLINE_WIDTH 1 /* DIS_RLINE */ | ||
1076 | #define WM8400_DIS_OUT3 0x0008 /* DIS_OUT3 */ | ||
1077 | #define WM8400_DIS_OUT3_MASK 0x0008 /* DIS_OUT3 */ | ||
1078 | #define WM8400_DIS_OUT3_SHIFT 3 /* DIS_OUT3 */ | ||
1079 | #define WM8400_DIS_OUT3_WIDTH 1 /* DIS_OUT3 */ | ||
1080 | #define WM8400_DIS_OUT4 0x0004 /* DIS_OUT4 */ | ||
1081 | #define WM8400_DIS_OUT4_MASK 0x0004 /* DIS_OUT4 */ | ||
1082 | #define WM8400_DIS_OUT4_SHIFT 2 /* DIS_OUT4 */ | ||
1083 | #define WM8400_DIS_OUT4_WIDTH 1 /* DIS_OUT4 */ | ||
1084 | #define WM8400_DIS_LOUT 0x0002 /* DIS_LOUT */ | ||
1085 | #define WM8400_DIS_LOUT_MASK 0x0002 /* DIS_LOUT */ | ||
1086 | #define WM8400_DIS_LOUT_SHIFT 1 /* DIS_LOUT */ | ||
1087 | #define WM8400_DIS_LOUT_WIDTH 1 /* DIS_LOUT */ | ||
1088 | #define WM8400_DIS_ROUT 0x0001 /* DIS_ROUT */ | ||
1089 | #define WM8400_DIS_ROUT_MASK 0x0001 /* DIS_ROUT */ | ||
1090 | #define WM8400_DIS_ROUT_SHIFT 0 /* DIS_ROUT */ | ||
1091 | #define WM8400_DIS_ROUT_WIDTH 1 /* DIS_ROUT */ | ||
1092 | |||
1093 | /* | ||
1094 | * R57 (0x39) - AntiPOP2 | ||
1095 | */ | ||
1096 | #define WM8400_SOFTST 0x0040 /* SOFTST */ | ||
1097 | #define WM8400_SOFTST_MASK 0x0040 /* SOFTST */ | ||
1098 | #define WM8400_SOFTST_SHIFT 6 /* SOFTST */ | ||
1099 | #define WM8400_SOFTST_WIDTH 1 /* SOFTST */ | ||
1100 | #define WM8400_BUFIOEN 0x0008 /* BUFIOEN */ | ||
1101 | #define WM8400_BUFIOEN_MASK 0x0008 /* BUFIOEN */ | ||
1102 | #define WM8400_BUFIOEN_SHIFT 3 /* BUFIOEN */ | ||
1103 | #define WM8400_BUFIOEN_WIDTH 1 /* BUFIOEN */ | ||
1104 | #define WM8400_BUFDCOPEN 0x0004 /* BUFDCOPEN */ | ||
1105 | #define WM8400_BUFDCOPEN_MASK 0x0004 /* BUFDCOPEN */ | ||
1106 | #define WM8400_BUFDCOPEN_SHIFT 2 /* BUFDCOPEN */ | ||
1107 | #define WM8400_BUFDCOPEN_WIDTH 1 /* BUFDCOPEN */ | ||
1108 | #define WM8400_POBCTRL 0x0002 /* POBCTRL */ | ||
1109 | #define WM8400_POBCTRL_MASK 0x0002 /* POBCTRL */ | ||
1110 | #define WM8400_POBCTRL_SHIFT 1 /* POBCTRL */ | ||
1111 | #define WM8400_POBCTRL_WIDTH 1 /* POBCTRL */ | ||
1112 | #define WM8400_VMIDTOG 0x0001 /* VMIDTOG */ | ||
1113 | #define WM8400_VMIDTOG_MASK 0x0001 /* VMIDTOG */ | ||
1114 | #define WM8400_VMIDTOG_SHIFT 0 /* VMIDTOG */ | ||
1115 | #define WM8400_VMIDTOG_WIDTH 1 /* VMIDTOG */ | ||
1116 | |||
1117 | /* | ||
1118 | * R58 (0x3A) - MICBIAS | ||
1119 | */ | ||
1120 | #define WM8400_MCDSCTH_MASK 0x00C0 /* MCDSCTH - [7:6] */ | ||
1121 | #define WM8400_MCDSCTH_SHIFT 6 /* MCDSCTH - [7:6] */ | ||
1122 | #define WM8400_MCDSCTH_WIDTH 2 /* MCDSCTH - [7:6] */ | ||
1123 | #define WM8400_MCDTHR_MASK 0x0038 /* MCDTHR - [5:3] */ | ||
1124 | #define WM8400_MCDTHR_SHIFT 3 /* MCDTHR - [5:3] */ | ||
1125 | #define WM8400_MCDTHR_WIDTH 3 /* MCDTHR - [5:3] */ | ||
1126 | #define WM8400_MCD 0x0004 /* MCD */ | ||
1127 | #define WM8400_MCD_MASK 0x0004 /* MCD */ | ||
1128 | #define WM8400_MCD_SHIFT 2 /* MCD */ | ||
1129 | #define WM8400_MCD_WIDTH 1 /* MCD */ | ||
1130 | #define WM8400_MBSEL 0x0001 /* MBSEL */ | ||
1131 | #define WM8400_MBSEL_MASK 0x0001 /* MBSEL */ | ||
1132 | #define WM8400_MBSEL_SHIFT 0 /* MBSEL */ | ||
1133 | #define WM8400_MBSEL_WIDTH 1 /* MBSEL */ | ||
1134 | |||
1135 | /* | ||
1136 | * R60 (0x3C) - FLL Control 1 | ||
1137 | */ | ||
1138 | #define WM8400_FLL_REF_FREQ 0x1000 /* FLL_REF_FREQ */ | ||
1139 | #define WM8400_FLL_REF_FREQ_MASK 0x1000 /* FLL_REF_FREQ */ | ||
1140 | #define WM8400_FLL_REF_FREQ_SHIFT 12 /* FLL_REF_FREQ */ | ||
1141 | #define WM8400_FLL_REF_FREQ_WIDTH 1 /* FLL_REF_FREQ */ | ||
1142 | #define WM8400_FLL_CLK_SRC_MASK 0x0C00 /* FLL_CLK_SRC - [11:10] */ | ||
1143 | #define WM8400_FLL_CLK_SRC_SHIFT 10 /* FLL_CLK_SRC - [11:10] */ | ||
1144 | #define WM8400_FLL_CLK_SRC_WIDTH 2 /* FLL_CLK_SRC - [11:10] */ | ||
1145 | #define WM8400_FLL_FRAC 0x0200 /* FLL_FRAC */ | ||
1146 | #define WM8400_FLL_FRAC_MASK 0x0200 /* FLL_FRAC */ | ||
1147 | #define WM8400_FLL_FRAC_SHIFT 9 /* FLL_FRAC */ | ||
1148 | #define WM8400_FLL_FRAC_WIDTH 1 /* FLL_FRAC */ | ||
1149 | #define WM8400_FLL_OSC_ENA 0x0100 /* FLL_OSC_ENA */ | ||
1150 | #define WM8400_FLL_OSC_ENA_MASK 0x0100 /* FLL_OSC_ENA */ | ||
1151 | #define WM8400_FLL_OSC_ENA_SHIFT 8 /* FLL_OSC_ENA */ | ||
1152 | #define WM8400_FLL_OSC_ENA_WIDTH 1 /* FLL_OSC_ENA */ | ||
1153 | #define WM8400_FLL_CTRL_RATE_MASK 0x00E0 /* FLL_CTRL_RATE - [7:5] */ | ||
1154 | #define WM8400_FLL_CTRL_RATE_SHIFT 5 /* FLL_CTRL_RATE - [7:5] */ | ||
1155 | #define WM8400_FLL_CTRL_RATE_WIDTH 3 /* FLL_CTRL_RATE - [7:5] */ | ||
1156 | #define WM8400_FLL_FRATIO_MASK 0x001F /* FLL_FRATIO - [4:0] */ | ||
1157 | #define WM8400_FLL_FRATIO_SHIFT 0 /* FLL_FRATIO - [4:0] */ | ||
1158 | #define WM8400_FLL_FRATIO_WIDTH 5 /* FLL_FRATIO - [4:0] */ | ||
1159 | |||
1160 | /* | ||
1161 | * R61 (0x3D) - FLL Control 2 | ||
1162 | */ | ||
1163 | #define WM8400_FLL_K_MASK 0xFFFF /* FLL_K - [15:0] */ | ||
1164 | #define WM8400_FLL_K_SHIFT 0 /* FLL_K - [15:0] */ | ||
1165 | #define WM8400_FLL_K_WIDTH 16 /* FLL_K - [15:0] */ | ||
1166 | |||
1167 | /* | ||
1168 | * R62 (0x3E) - FLL Control 3 | ||
1169 | */ | ||
1170 | #define WM8400_FLL_N_MASK 0x03FF /* FLL_N - [9:0] */ | ||
1171 | #define WM8400_FLL_N_SHIFT 0 /* FLL_N - [9:0] */ | ||
1172 | #define WM8400_FLL_N_WIDTH 10 /* FLL_N - [9:0] */ | ||
1173 | |||
1174 | /* | ||
1175 | * R63 (0x3F) - FLL Control 4 | ||
1176 | */ | ||
1177 | #define WM8400_FLL_TRK_GAIN_MASK 0x0078 /* FLL_TRK_GAIN - [6:3] */ | ||
1178 | #define WM8400_FLL_TRK_GAIN_SHIFT 3 /* FLL_TRK_GAIN - [6:3] */ | ||
1179 | #define WM8400_FLL_TRK_GAIN_WIDTH 4 /* FLL_TRK_GAIN - [6:3] */ | ||
1180 | #define WM8400_FLL_OUTDIV_MASK 0x0007 /* FLL_OUTDIV - [2:0] */ | ||
1181 | #define WM8400_FLL_OUTDIV_SHIFT 0 /* FLL_OUTDIV - [2:0] */ | ||
1182 | #define WM8400_FLL_OUTDIV_WIDTH 3 /* FLL_OUTDIV - [2:0] */ | ||
1183 | |||
1184 | void wm8400_reset_codec_reg_cache(struct wm8400 *wm8400); | ||
1185 | |||
1186 | #endif | ||
diff --git a/include/linux/mfd/wm8400-private.h b/include/linux/mfd/wm8400-private.h new file mode 100644 index 000000000000..2aab4e93a5c9 --- /dev/null +++ b/include/linux/mfd/wm8400-private.h | |||
@@ -0,0 +1,936 @@ | |||
1 | /* | ||
2 | * wm8400 private definitions. | ||
3 | * | ||
4 | * Copyright 2008 Wolfson Microelectronics plc | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
19 | */ | ||
20 | |||
21 | #ifndef __LINUX_MFD_WM8400_PRIV_H | ||
22 | #define __LINUX_MFD_WM8400_PRIV_H | ||
23 | |||
24 | #include <linux/mfd/wm8400.h> | ||
25 | #include <linux/mutex.h> | ||
26 | #include <linux/platform_device.h> | ||
27 | |||
28 | #define WM8400_REGISTER_COUNT 0x55 | ||
29 | |||
30 | struct wm8400 { | ||
31 | struct device *dev; | ||
32 | |||
33 | int (*read_dev)(void *data, char reg, int count, u16 *dst); | ||
34 | int (*write_dev)(void *data, char reg, int count, const u16 *src); | ||
35 | |||
36 | struct mutex io_lock; | ||
37 | void *io_data; | ||
38 | |||
39 | u16 reg_cache[WM8400_REGISTER_COUNT]; | ||
40 | |||
41 | struct platform_device regulators[6]; | ||
42 | }; | ||
43 | |||
44 | /* | ||
45 | * Register values. | ||
46 | */ | ||
47 | #define WM8400_RESET_ID 0x00 | ||
48 | #define WM8400_ID 0x01 | ||
49 | #define WM8400_POWER_MANAGEMENT_1 0x02 | ||
50 | #define WM8400_POWER_MANAGEMENT_2 0x03 | ||
51 | #define WM8400_POWER_MANAGEMENT_3 0x04 | ||
52 | #define WM8400_AUDIO_INTERFACE_1 0x05 | ||
53 | #define WM8400_AUDIO_INTERFACE_2 0x06 | ||
54 | #define WM8400_CLOCKING_1 0x07 | ||
55 | #define WM8400_CLOCKING_2 0x08 | ||
56 | #define WM8400_AUDIO_INTERFACE_3 0x09 | ||
57 | #define WM8400_AUDIO_INTERFACE_4 0x0A | ||
58 | #define WM8400_DAC_CTRL 0x0B | ||
59 | #define WM8400_LEFT_DAC_DIGITAL_VOLUME 0x0C | ||
60 | #define WM8400_RIGHT_DAC_DIGITAL_VOLUME 0x0D | ||
61 | #define WM8400_DIGITAL_SIDE_TONE 0x0E | ||
62 | #define WM8400_ADC_CTRL 0x0F | ||
63 | #define WM8400_LEFT_ADC_DIGITAL_VOLUME 0x10 | ||
64 | #define WM8400_RIGHT_ADC_DIGITAL_VOLUME 0x11 | ||
65 | #define WM8400_GPIO_CTRL_1 0x12 | ||
66 | #define WM8400_GPIO1_GPIO2 0x13 | ||
67 | #define WM8400_GPIO3_GPIO4 0x14 | ||
68 | #define WM8400_GPIO5_GPIO6 0x15 | ||
69 | #define WM8400_GPIOCTRL_2 0x16 | ||
70 | #define WM8400_GPIO_POL 0x17 | ||
71 | #define WM8400_LEFT_LINE_INPUT_1_2_VOLUME 0x18 | ||
72 | #define WM8400_LEFT_LINE_INPUT_3_4_VOLUME 0x19 | ||
73 | #define WM8400_RIGHT_LINE_INPUT_1_2_VOLUME 0x1A | ||
74 | #define WM8400_RIGHT_LINE_INPUT_3_4_VOLUME 0x1B | ||
75 | #define WM8400_LEFT_OUTPUT_VOLUME 0x1C | ||
76 | #define WM8400_RIGHT_OUTPUT_VOLUME 0x1D | ||
77 | #define WM8400_LINE_OUTPUTS_VOLUME 0x1E | ||
78 | #define WM8400_OUT3_4_VOLUME 0x1F | ||
79 | #define WM8400_LEFT_OPGA_VOLUME 0x20 | ||
80 | #define WM8400_RIGHT_OPGA_VOLUME 0x21 | ||
81 | #define WM8400_SPEAKER_VOLUME 0x22 | ||
82 | #define WM8400_CLASSD1 0x23 | ||
83 | #define WM8400_CLASSD3 0x25 | ||
84 | #define WM8400_INPUT_MIXER1 0x27 | ||
85 | #define WM8400_INPUT_MIXER2 0x28 | ||
86 | #define WM8400_INPUT_MIXER3 0x29 | ||
87 | #define WM8400_INPUT_MIXER4 0x2A | ||
88 | #define WM8400_INPUT_MIXER5 0x2B | ||
89 | #define WM8400_INPUT_MIXER6 0x2C | ||
90 | #define WM8400_OUTPUT_MIXER1 0x2D | ||
91 | #define WM8400_OUTPUT_MIXER2 0x2E | ||
92 | #define WM8400_OUTPUT_MIXER3 0x2F | ||
93 | #define WM8400_OUTPUT_MIXER4 0x30 | ||
94 | #define WM8400_OUTPUT_MIXER5 0x31 | ||
95 | #define WM8400_OUTPUT_MIXER6 0x32 | ||
96 | #define WM8400_OUT3_4_MIXER 0x33 | ||
97 | #define WM8400_LINE_MIXER1 0x34 | ||
98 | #define WM8400_LINE_MIXER2 0x35 | ||
99 | #define WM8400_SPEAKER_MIXER 0x36 | ||
100 | #define WM8400_ADDITIONAL_CONTROL 0x37 | ||
101 | #define WM8400_ANTIPOP1 0x38 | ||
102 | #define WM8400_ANTIPOP2 0x39 | ||
103 | #define WM8400_MICBIAS 0x3A | ||
104 | #define WM8400_FLL_CONTROL_1 0x3C | ||
105 | #define WM8400_FLL_CONTROL_2 0x3D | ||
106 | #define WM8400_FLL_CONTROL_3 0x3E | ||
107 | #define WM8400_FLL_CONTROL_4 0x3F | ||
108 | #define WM8400_LDO1_CONTROL 0x41 | ||
109 | #define WM8400_LDO2_CONTROL 0x42 | ||
110 | #define WM8400_LDO3_CONTROL 0x43 | ||
111 | #define WM8400_LDO4_CONTROL 0x44 | ||
112 | #define WM8400_DCDC1_CONTROL_1 0x46 | ||
113 | #define WM8400_DCDC1_CONTROL_2 0x47 | ||
114 | #define WM8400_DCDC2_CONTROL_1 0x48 | ||
115 | #define WM8400_DCDC2_CONTROL_2 0x49 | ||
116 | #define WM8400_INTERFACE 0x4B | ||
117 | #define WM8400_PM_GENERAL 0x4C | ||
118 | #define WM8400_PM_SHUTDOWN_CONTROL 0x4E | ||
119 | #define WM8400_INTERRUPT_STATUS_1 0x4F | ||
120 | #define WM8400_INTERRUPT_STATUS_1_MASK 0x50 | ||
121 | #define WM8400_INTERRUPT_LEVELS 0x51 | ||
122 | #define WM8400_SHUTDOWN_REASON 0x52 | ||
123 | #define WM8400_LINE_CIRCUITS 0x54 | ||
124 | |||
125 | /* | ||
126 | * Field Definitions. | ||
127 | */ | ||
128 | |||
129 | /* | ||
130 | * R0 (0x00) - Reset/ID | ||
131 | */ | ||
132 | #define WM8400_SW_RESET_CHIP_ID_MASK 0xFFFF /* SW_RESET/CHIP_ID - [15:0] */ | ||
133 | #define WM8400_SW_RESET_CHIP_ID_SHIFT 0 /* SW_RESET/CHIP_ID - [15:0] */ | ||
134 | #define WM8400_SW_RESET_CHIP_ID_WIDTH 16 /* SW_RESET/CHIP_ID - [15:0] */ | ||
135 | |||
136 | /* | ||
137 | * R1 (0x01) - ID | ||
138 | */ | ||
139 | #define WM8400_CHIP_REV_MASK 0x7000 /* CHIP_REV - [14:12] */ | ||
140 | #define WM8400_CHIP_REV_SHIFT 12 /* CHIP_REV - [14:12] */ | ||
141 | #define WM8400_CHIP_REV_WIDTH 3 /* CHIP_REV - [14:12] */ | ||
142 | |||
143 | /* | ||
144 | * R18 (0x12) - GPIO CTRL 1 | ||
145 | */ | ||
146 | #define WM8400_IRQ 0x1000 /* IRQ */ | ||
147 | #define WM8400_IRQ_MASK 0x1000 /* IRQ */ | ||
148 | #define WM8400_IRQ_SHIFT 12 /* IRQ */ | ||
149 | #define WM8400_IRQ_WIDTH 1 /* IRQ */ | ||
150 | #define WM8400_TEMPOK 0x0800 /* TEMPOK */ | ||
151 | #define WM8400_TEMPOK_MASK 0x0800 /* TEMPOK */ | ||
152 | #define WM8400_TEMPOK_SHIFT 11 /* TEMPOK */ | ||
153 | #define WM8400_TEMPOK_WIDTH 1 /* TEMPOK */ | ||
154 | #define WM8400_MIC1SHRT 0x0400 /* MIC1SHRT */ | ||
155 | #define WM8400_MIC1SHRT_MASK 0x0400 /* MIC1SHRT */ | ||
156 | #define WM8400_MIC1SHRT_SHIFT 10 /* MIC1SHRT */ | ||
157 | #define WM8400_MIC1SHRT_WIDTH 1 /* MIC1SHRT */ | ||
158 | #define WM8400_MIC1DET 0x0200 /* MIC1DET */ | ||
159 | #define WM8400_MIC1DET_MASK 0x0200 /* MIC1DET */ | ||
160 | #define WM8400_MIC1DET_SHIFT 9 /* MIC1DET */ | ||
161 | #define WM8400_MIC1DET_WIDTH 1 /* MIC1DET */ | ||
162 | #define WM8400_FLL_LCK 0x0100 /* FLL_LCK */ | ||
163 | #define WM8400_FLL_LCK_MASK 0x0100 /* FLL_LCK */ | ||
164 | #define WM8400_FLL_LCK_SHIFT 8 /* FLL_LCK */ | ||
165 | #define WM8400_FLL_LCK_WIDTH 1 /* FLL_LCK */ | ||
166 | #define WM8400_GPIO_STATUS_MASK 0x00FF /* GPIO_STATUS - [7:0] */ | ||
167 | #define WM8400_GPIO_STATUS_SHIFT 0 /* GPIO_STATUS - [7:0] */ | ||
168 | #define WM8400_GPIO_STATUS_WIDTH 8 /* GPIO_STATUS - [7:0] */ | ||
169 | |||
170 | /* | ||
171 | * R19 (0x13) - GPIO1 & GPIO2 | ||
172 | */ | ||
173 | #define WM8400_GPIO2_DEB_ENA 0x8000 /* GPIO2_DEB_ENA */ | ||
174 | #define WM8400_GPIO2_DEB_ENA_MASK 0x8000 /* GPIO2_DEB_ENA */ | ||
175 | #define WM8400_GPIO2_DEB_ENA_SHIFT 15 /* GPIO2_DEB_ENA */ | ||
176 | #define WM8400_GPIO2_DEB_ENA_WIDTH 1 /* GPIO2_DEB_ENA */ | ||
177 | #define WM8400_GPIO2_IRQ_ENA 0x4000 /* GPIO2_IRQ_ENA */ | ||
178 | #define WM8400_GPIO2_IRQ_ENA_MASK 0x4000 /* GPIO2_IRQ_ENA */ | ||
179 | #define WM8400_GPIO2_IRQ_ENA_SHIFT 14 /* GPIO2_IRQ_ENA */ | ||
180 | #define WM8400_GPIO2_IRQ_ENA_WIDTH 1 /* GPIO2_IRQ_ENA */ | ||
181 | #define WM8400_GPIO2_PU 0x2000 /* GPIO2_PU */ | ||
182 | #define WM8400_GPIO2_PU_MASK 0x2000 /* GPIO2_PU */ | ||
183 | #define WM8400_GPIO2_PU_SHIFT 13 /* GPIO2_PU */ | ||
184 | #define WM8400_GPIO2_PU_WIDTH 1 /* GPIO2_PU */ | ||
185 | #define WM8400_GPIO2_PD 0x1000 /* GPIO2_PD */ | ||
186 | #define WM8400_GPIO2_PD_MASK 0x1000 /* GPIO2_PD */ | ||
187 | #define WM8400_GPIO2_PD_SHIFT 12 /* GPIO2_PD */ | ||
188 | #define WM8400_GPIO2_PD_WIDTH 1 /* GPIO2_PD */ | ||
189 | #define WM8400_GPIO2_SEL_MASK 0x0F00 /* GPIO2_SEL - [11:8] */ | ||
190 | #define WM8400_GPIO2_SEL_SHIFT 8 /* GPIO2_SEL - [11:8] */ | ||
191 | #define WM8400_GPIO2_SEL_WIDTH 4 /* GPIO2_SEL - [11:8] */ | ||
192 | #define WM8400_GPIO1_DEB_ENA 0x0080 /* GPIO1_DEB_ENA */ | ||
193 | #define WM8400_GPIO1_DEB_ENA_MASK 0x0080 /* GPIO1_DEB_ENA */ | ||
194 | #define WM8400_GPIO1_DEB_ENA_SHIFT 7 /* GPIO1_DEB_ENA */ | ||
195 | #define WM8400_GPIO1_DEB_ENA_WIDTH 1 /* GPIO1_DEB_ENA */ | ||
196 | #define WM8400_GPIO1_IRQ_ENA 0x0040 /* GPIO1_IRQ_ENA */ | ||
197 | #define WM8400_GPIO1_IRQ_ENA_MASK 0x0040 /* GPIO1_IRQ_ENA */ | ||
198 | #define WM8400_GPIO1_IRQ_ENA_SHIFT 6 /* GPIO1_IRQ_ENA */ | ||
199 | #define WM8400_GPIO1_IRQ_ENA_WIDTH 1 /* GPIO1_IRQ_ENA */ | ||
200 | #define WM8400_GPIO1_PU 0x0020 /* GPIO1_PU */ | ||
201 | #define WM8400_GPIO1_PU_MASK 0x0020 /* GPIO1_PU */ | ||
202 | #define WM8400_GPIO1_PU_SHIFT 5 /* GPIO1_PU */ | ||
203 | #define WM8400_GPIO1_PU_WIDTH 1 /* GPIO1_PU */ | ||
204 | #define WM8400_GPIO1_PD 0x0010 /* GPIO1_PD */ | ||
205 | #define WM8400_GPIO1_PD_MASK 0x0010 /* GPIO1_PD */ | ||
206 | #define WM8400_GPIO1_PD_SHIFT 4 /* GPIO1_PD */ | ||
207 | #define WM8400_GPIO1_PD_WIDTH 1 /* GPIO1_PD */ | ||
208 | #define WM8400_GPIO1_SEL_MASK 0x000F /* GPIO1_SEL - [3:0] */ | ||
209 | #define WM8400_GPIO1_SEL_SHIFT 0 /* GPIO1_SEL - [3:0] */ | ||
210 | #define WM8400_GPIO1_SEL_WIDTH 4 /* GPIO1_SEL - [3:0] */ | ||
211 | |||
212 | /* | ||
213 | * R20 (0x14) - GPIO3 & GPIO4 | ||
214 | */ | ||
215 | #define WM8400_GPIO4_DEB_ENA 0x8000 /* GPIO4_DEB_ENA */ | ||
216 | #define WM8400_GPIO4_DEB_ENA_MASK 0x8000 /* GPIO4_DEB_ENA */ | ||
217 | #define WM8400_GPIO4_DEB_ENA_SHIFT 15 /* GPIO4_DEB_ENA */ | ||
218 | #define WM8400_GPIO4_DEB_ENA_WIDTH 1 /* GPIO4_DEB_ENA */ | ||
219 | #define WM8400_GPIO4_IRQ_ENA 0x4000 /* GPIO4_IRQ_ENA */ | ||
220 | #define WM8400_GPIO4_IRQ_ENA_MASK 0x4000 /* GPIO4_IRQ_ENA */ | ||
221 | #define WM8400_GPIO4_IRQ_ENA_SHIFT 14 /* GPIO4_IRQ_ENA */ | ||
222 | #define WM8400_GPIO4_IRQ_ENA_WIDTH 1 /* GPIO4_IRQ_ENA */ | ||
223 | #define WM8400_GPIO4_PU 0x2000 /* GPIO4_PU */ | ||
224 | #define WM8400_GPIO4_PU_MASK 0x2000 /* GPIO4_PU */ | ||
225 | #define WM8400_GPIO4_PU_SHIFT 13 /* GPIO4_PU */ | ||
226 | #define WM8400_GPIO4_PU_WIDTH 1 /* GPIO4_PU */ | ||
227 | #define WM8400_GPIO4_PD 0x1000 /* GPIO4_PD */ | ||
228 | #define WM8400_GPIO4_PD_MASK 0x1000 /* GPIO4_PD */ | ||
229 | #define WM8400_GPIO4_PD_SHIFT 12 /* GPIO4_PD */ | ||
230 | #define WM8400_GPIO4_PD_WIDTH 1 /* GPIO4_PD */ | ||
231 | #define WM8400_GPIO4_SEL_MASK 0x0F00 /* GPIO4_SEL - [11:8] */ | ||
232 | #define WM8400_GPIO4_SEL_SHIFT 8 /* GPIO4_SEL - [11:8] */ | ||
233 | #define WM8400_GPIO4_SEL_WIDTH 4 /* GPIO4_SEL - [11:8] */ | ||
234 | #define WM8400_GPIO3_DEB_ENA 0x0080 /* GPIO3_DEB_ENA */ | ||
235 | #define WM8400_GPIO3_DEB_ENA_MASK 0x0080 /* GPIO3_DEB_ENA */ | ||
236 | #define WM8400_GPIO3_DEB_ENA_SHIFT 7 /* GPIO3_DEB_ENA */ | ||
237 | #define WM8400_GPIO3_DEB_ENA_WIDTH 1 /* GPIO3_DEB_ENA */ | ||
238 | #define WM8400_GPIO3_IRQ_ENA 0x0040 /* GPIO3_IRQ_ENA */ | ||
239 | #define WM8400_GPIO3_IRQ_ENA_MASK 0x0040 /* GPIO3_IRQ_ENA */ | ||
240 | #define WM8400_GPIO3_IRQ_ENA_SHIFT 6 /* GPIO3_IRQ_ENA */ | ||
241 | #define WM8400_GPIO3_IRQ_ENA_WIDTH 1 /* GPIO3_IRQ_ENA */ | ||
242 | #define WM8400_GPIO3_PU 0x0020 /* GPIO3_PU */ | ||
243 | #define WM8400_GPIO3_PU_MASK 0x0020 /* GPIO3_PU */ | ||
244 | #define WM8400_GPIO3_PU_SHIFT 5 /* GPIO3_PU */ | ||
245 | #define WM8400_GPIO3_PU_WIDTH 1 /* GPIO3_PU */ | ||
246 | #define WM8400_GPIO3_PD 0x0010 /* GPIO3_PD */ | ||
247 | #define WM8400_GPIO3_PD_MASK 0x0010 /* GPIO3_PD */ | ||
248 | #define WM8400_GPIO3_PD_SHIFT 4 /* GPIO3_PD */ | ||
249 | #define WM8400_GPIO3_PD_WIDTH 1 /* GPIO3_PD */ | ||
250 | #define WM8400_GPIO3_SEL_MASK 0x000F /* GPIO3_SEL - [3:0] */ | ||
251 | #define WM8400_GPIO3_SEL_SHIFT 0 /* GPIO3_SEL - [3:0] */ | ||
252 | #define WM8400_GPIO3_SEL_WIDTH 4 /* GPIO3_SEL - [3:0] */ | ||
253 | |||
254 | /* | ||
255 | * R21 (0x15) - GPIO5 & GPIO6 | ||
256 | */ | ||
257 | #define WM8400_GPIO6_DEB_ENA 0x8000 /* GPIO6_DEB_ENA */ | ||
258 | #define WM8400_GPIO6_DEB_ENA_MASK 0x8000 /* GPIO6_DEB_ENA */ | ||
259 | #define WM8400_GPIO6_DEB_ENA_SHIFT 15 /* GPIO6_DEB_ENA */ | ||
260 | #define WM8400_GPIO6_DEB_ENA_WIDTH 1 /* GPIO6_DEB_ENA */ | ||
261 | #define WM8400_GPIO6_IRQ_ENA 0x4000 /* GPIO6_IRQ_ENA */ | ||
262 | #define WM8400_GPIO6_IRQ_ENA_MASK 0x4000 /* GPIO6_IRQ_ENA */ | ||
263 | #define WM8400_GPIO6_IRQ_ENA_SHIFT 14 /* GPIO6_IRQ_ENA */ | ||
264 | #define WM8400_GPIO6_IRQ_ENA_WIDTH 1 /* GPIO6_IRQ_ENA */ | ||
265 | #define WM8400_GPIO6_PU 0x2000 /* GPIO6_PU */ | ||
266 | #define WM8400_GPIO6_PU_MASK 0x2000 /* GPIO6_PU */ | ||
267 | #define WM8400_GPIO6_PU_SHIFT 13 /* GPIO6_PU */ | ||
268 | #define WM8400_GPIO6_PU_WIDTH 1 /* GPIO6_PU */ | ||
269 | #define WM8400_GPIO6_PD 0x1000 /* GPIO6_PD */ | ||
270 | #define WM8400_GPIO6_PD_MASK 0x1000 /* GPIO6_PD */ | ||
271 | #define WM8400_GPIO6_PD_SHIFT 12 /* GPIO6_PD */ | ||
272 | #define WM8400_GPIO6_PD_WIDTH 1 /* GPIO6_PD */ | ||
273 | #define WM8400_GPIO6_SEL_MASK 0x0F00 /* GPIO6_SEL - [11:8] */ | ||
274 | #define WM8400_GPIO6_SEL_SHIFT 8 /* GPIO6_SEL - [11:8] */ | ||
275 | #define WM8400_GPIO6_SEL_WIDTH 4 /* GPIO6_SEL - [11:8] */ | ||
276 | #define WM8400_GPIO5_DEB_ENA 0x0080 /* GPIO5_DEB_ENA */ | ||
277 | #define WM8400_GPIO5_DEB_ENA_MASK 0x0080 /* GPIO5_DEB_ENA */ | ||
278 | #define WM8400_GPIO5_DEB_ENA_SHIFT 7 /* GPIO5_DEB_ENA */ | ||
279 | #define WM8400_GPIO5_DEB_ENA_WIDTH 1 /* GPIO5_DEB_ENA */ | ||
280 | #define WM8400_GPIO5_IRQ_ENA 0x0040 /* GPIO5_IRQ_ENA */ | ||
281 | #define WM8400_GPIO5_IRQ_ENA_MASK 0x0040 /* GPIO5_IRQ_ENA */ | ||
282 | #define WM8400_GPIO5_IRQ_ENA_SHIFT 6 /* GPIO5_IRQ_ENA */ | ||
283 | #define WM8400_GPIO5_IRQ_ENA_WIDTH 1 /* GPIO5_IRQ_ENA */ | ||
284 | #define WM8400_GPIO5_PU 0x0020 /* GPIO5_PU */ | ||
285 | #define WM8400_GPIO5_PU_MASK 0x0020 /* GPIO5_PU */ | ||
286 | #define WM8400_GPIO5_PU_SHIFT 5 /* GPIO5_PU */ | ||
287 | #define WM8400_GPIO5_PU_WIDTH 1 /* GPIO5_PU */ | ||
288 | #define WM8400_GPIO5_PD 0x0010 /* GPIO5_PD */ | ||
289 | #define WM8400_GPIO5_PD_MASK 0x0010 /* GPIO5_PD */ | ||
290 | #define WM8400_GPIO5_PD_SHIFT 4 /* GPIO5_PD */ | ||
291 | #define WM8400_GPIO5_PD_WIDTH 1 /* GPIO5_PD */ | ||
292 | #define WM8400_GPIO5_SEL_MASK 0x000F /* GPIO5_SEL - [3:0] */ | ||
293 | #define WM8400_GPIO5_SEL_SHIFT 0 /* GPIO5_SEL - [3:0] */ | ||
294 | #define WM8400_GPIO5_SEL_WIDTH 4 /* GPIO5_SEL - [3:0] */ | ||
295 | |||
296 | /* | ||
297 | * R22 (0x16) - GPIOCTRL 2 | ||
298 | */ | ||
299 | #define WM8400_TEMPOK_IRQ_ENA 0x0800 /* TEMPOK_IRQ_ENA */ | ||
300 | #define WM8400_TEMPOK_IRQ_ENA_MASK 0x0800 /* TEMPOK_IRQ_ENA */ | ||
301 | #define WM8400_TEMPOK_IRQ_ENA_SHIFT 11 /* TEMPOK_IRQ_ENA */ | ||
302 | #define WM8400_TEMPOK_IRQ_ENA_WIDTH 1 /* TEMPOK_IRQ_ENA */ | ||
303 | #define WM8400_MIC1SHRT_IRQ_ENA 0x0400 /* MIC1SHRT_IRQ_ENA */ | ||
304 | #define WM8400_MIC1SHRT_IRQ_ENA_MASK 0x0400 /* MIC1SHRT_IRQ_ENA */ | ||
305 | #define WM8400_MIC1SHRT_IRQ_ENA_SHIFT 10 /* MIC1SHRT_IRQ_ENA */ | ||
306 | #define WM8400_MIC1SHRT_IRQ_ENA_WIDTH 1 /* MIC1SHRT_IRQ_ENA */ | ||
307 | #define WM8400_MIC1DET_IRQ_ENA 0x0200 /* MIC1DET_IRQ_ENA */ | ||
308 | #define WM8400_MIC1DET_IRQ_ENA_MASK 0x0200 /* MIC1DET_IRQ_ENA */ | ||
309 | #define WM8400_MIC1DET_IRQ_ENA_SHIFT 9 /* MIC1DET_IRQ_ENA */ | ||
310 | #define WM8400_MIC1DET_IRQ_ENA_WIDTH 1 /* MIC1DET_IRQ_ENA */ | ||
311 | #define WM8400_FLL_LCK_IRQ_ENA 0x0100 /* FLL_LCK_IRQ_ENA */ | ||
312 | #define WM8400_FLL_LCK_IRQ_ENA_MASK 0x0100 /* FLL_LCK_IRQ_ENA */ | ||
313 | #define WM8400_FLL_LCK_IRQ_ENA_SHIFT 8 /* FLL_LCK_IRQ_ENA */ | ||
314 | #define WM8400_FLL_LCK_IRQ_ENA_WIDTH 1 /* FLL_LCK_IRQ_ENA */ | ||
315 | #define WM8400_GPI8_DEB_ENA 0x0080 /* GPI8_DEB_ENA */ | ||
316 | #define WM8400_GPI8_DEB_ENA_MASK 0x0080 /* GPI8_DEB_ENA */ | ||
317 | #define WM8400_GPI8_DEB_ENA_SHIFT 7 /* GPI8_DEB_ENA */ | ||
318 | #define WM8400_GPI8_DEB_ENA_WIDTH 1 /* GPI8_DEB_ENA */ | ||
319 | #define WM8400_GPI8_IRQ_ENA 0x0040 /* GPI8_IRQ_ENA */ | ||
320 | #define WM8400_GPI8_IRQ_ENA_MASK 0x0040 /* GPI8_IRQ_ENA */ | ||
321 | #define WM8400_GPI8_IRQ_ENA_SHIFT 6 /* GPI8_IRQ_ENA */ | ||
322 | #define WM8400_GPI8_IRQ_ENA_WIDTH 1 /* GPI8_IRQ_ENA */ | ||
323 | #define WM8400_GPI8_ENA 0x0010 /* GPI8_ENA */ | ||
324 | #define WM8400_GPI8_ENA_MASK 0x0010 /* GPI8_ENA */ | ||
325 | #define WM8400_GPI8_ENA_SHIFT 4 /* GPI8_ENA */ | ||
326 | #define WM8400_GPI8_ENA_WIDTH 1 /* GPI8_ENA */ | ||
327 | #define WM8400_GPI7_DEB_ENA 0x0008 /* GPI7_DEB_ENA */ | ||
328 | #define WM8400_GPI7_DEB_ENA_MASK 0x0008 /* GPI7_DEB_ENA */ | ||
329 | #define WM8400_GPI7_DEB_ENA_SHIFT 3 /* GPI7_DEB_ENA */ | ||
330 | #define WM8400_GPI7_DEB_ENA_WIDTH 1 /* GPI7_DEB_ENA */ | ||
331 | #define WM8400_GPI7_IRQ_ENA 0x0004 /* GPI7_IRQ_ENA */ | ||
332 | #define WM8400_GPI7_IRQ_ENA_MASK 0x0004 /* GPI7_IRQ_ENA */ | ||
333 | #define WM8400_GPI7_IRQ_ENA_SHIFT 2 /* GPI7_IRQ_ENA */ | ||
334 | #define WM8400_GPI7_IRQ_ENA_WIDTH 1 /* GPI7_IRQ_ENA */ | ||
335 | #define WM8400_GPI7_ENA 0x0001 /* GPI7_ENA */ | ||
336 | #define WM8400_GPI7_ENA_MASK 0x0001 /* GPI7_ENA */ | ||
337 | #define WM8400_GPI7_ENA_SHIFT 0 /* GPI7_ENA */ | ||
338 | #define WM8400_GPI7_ENA_WIDTH 1 /* GPI7_ENA */ | ||
339 | |||
340 | /* | ||
341 | * R23 (0x17) - GPIO_POL | ||
342 | */ | ||
343 | #define WM8400_IRQ_INV 0x1000 /* IRQ_INV */ | ||
344 | #define WM8400_IRQ_INV_MASK 0x1000 /* IRQ_INV */ | ||
345 | #define WM8400_IRQ_INV_SHIFT 12 /* IRQ_INV */ | ||
346 | #define WM8400_IRQ_INV_WIDTH 1 /* IRQ_INV */ | ||
347 | #define WM8400_TEMPOK_POL 0x0800 /* TEMPOK_POL */ | ||
348 | #define WM8400_TEMPOK_POL_MASK 0x0800 /* TEMPOK_POL */ | ||
349 | #define WM8400_TEMPOK_POL_SHIFT 11 /* TEMPOK_POL */ | ||
350 | #define WM8400_TEMPOK_POL_WIDTH 1 /* TEMPOK_POL */ | ||
351 | #define WM8400_MIC1SHRT_POL 0x0400 /* MIC1SHRT_POL */ | ||
352 | #define WM8400_MIC1SHRT_POL_MASK 0x0400 /* MIC1SHRT_POL */ | ||
353 | #define WM8400_MIC1SHRT_POL_SHIFT 10 /* MIC1SHRT_POL */ | ||
354 | #define WM8400_MIC1SHRT_POL_WIDTH 1 /* MIC1SHRT_POL */ | ||
355 | #define WM8400_MIC1DET_POL 0x0200 /* MIC1DET_POL */ | ||
356 | #define WM8400_MIC1DET_POL_MASK 0x0200 /* MIC1DET_POL */ | ||
357 | #define WM8400_MIC1DET_POL_SHIFT 9 /* MIC1DET_POL */ | ||
358 | #define WM8400_MIC1DET_POL_WIDTH 1 /* MIC1DET_POL */ | ||
359 | #define WM8400_FLL_LCK_POL 0x0100 /* FLL_LCK_POL */ | ||
360 | #define WM8400_FLL_LCK_POL_MASK 0x0100 /* FLL_LCK_POL */ | ||
361 | #define WM8400_FLL_LCK_POL_SHIFT 8 /* FLL_LCK_POL */ | ||
362 | #define WM8400_FLL_LCK_POL_WIDTH 1 /* FLL_LCK_POL */ | ||
363 | #define WM8400_GPIO_POL_MASK 0x00FF /* GPIO_POL - [7:0] */ | ||
364 | #define WM8400_GPIO_POL_SHIFT 0 /* GPIO_POL - [7:0] */ | ||
365 | #define WM8400_GPIO_POL_WIDTH 8 /* GPIO_POL - [7:0] */ | ||
366 | |||
367 | /* | ||
368 | * R65 (0x41) - LDO 1 Control | ||
369 | */ | ||
370 | #define WM8400_LDO1_ENA 0x8000 /* LDO1_ENA */ | ||
371 | #define WM8400_LDO1_ENA_MASK 0x8000 /* LDO1_ENA */ | ||
372 | #define WM8400_LDO1_ENA_SHIFT 15 /* LDO1_ENA */ | ||
373 | #define WM8400_LDO1_ENA_WIDTH 1 /* LDO1_ENA */ | ||
374 | #define WM8400_LDO1_SWI 0x4000 /* LDO1_SWI */ | ||
375 | #define WM8400_LDO1_SWI_MASK 0x4000 /* LDO1_SWI */ | ||
376 | #define WM8400_LDO1_SWI_SHIFT 14 /* LDO1_SWI */ | ||
377 | #define WM8400_LDO1_SWI_WIDTH 1 /* LDO1_SWI */ | ||
378 | #define WM8400_LDO1_OPFLT 0x1000 /* LDO1_OPFLT */ | ||
379 | #define WM8400_LDO1_OPFLT_MASK 0x1000 /* LDO1_OPFLT */ | ||
380 | #define WM8400_LDO1_OPFLT_SHIFT 12 /* LDO1_OPFLT */ | ||
381 | #define WM8400_LDO1_OPFLT_WIDTH 1 /* LDO1_OPFLT */ | ||
382 | #define WM8400_LDO1_ERRACT 0x0800 /* LDO1_ERRACT */ | ||
383 | #define WM8400_LDO1_ERRACT_MASK 0x0800 /* LDO1_ERRACT */ | ||
384 | #define WM8400_LDO1_ERRACT_SHIFT 11 /* LDO1_ERRACT */ | ||
385 | #define WM8400_LDO1_ERRACT_WIDTH 1 /* LDO1_ERRACT */ | ||
386 | #define WM8400_LDO1_HIB_MODE 0x0400 /* LDO1_HIB_MODE */ | ||
387 | #define WM8400_LDO1_HIB_MODE_MASK 0x0400 /* LDO1_HIB_MODE */ | ||
388 | #define WM8400_LDO1_HIB_MODE_SHIFT 10 /* LDO1_HIB_MODE */ | ||
389 | #define WM8400_LDO1_HIB_MODE_WIDTH 1 /* LDO1_HIB_MODE */ | ||
390 | #define WM8400_LDO1_VIMG_MASK 0x03E0 /* LDO1_VIMG - [9:5] */ | ||
391 | #define WM8400_LDO1_VIMG_SHIFT 5 /* LDO1_VIMG - [9:5] */ | ||
392 | #define WM8400_LDO1_VIMG_WIDTH 5 /* LDO1_VIMG - [9:5] */ | ||
393 | #define WM8400_LDO1_VSEL_MASK 0x001F /* LDO1_VSEL - [4:0] */ | ||
394 | #define WM8400_LDO1_VSEL_SHIFT 0 /* LDO1_VSEL - [4:0] */ | ||
395 | #define WM8400_LDO1_VSEL_WIDTH 5 /* LDO1_VSEL - [4:0] */ | ||
396 | |||
397 | /* | ||
398 | * R66 (0x42) - LDO 2 Control | ||
399 | */ | ||
400 | #define WM8400_LDO2_ENA 0x8000 /* LDO2_ENA */ | ||
401 | #define WM8400_LDO2_ENA_MASK 0x8000 /* LDO2_ENA */ | ||
402 | #define WM8400_LDO2_ENA_SHIFT 15 /* LDO2_ENA */ | ||
403 | #define WM8400_LDO2_ENA_WIDTH 1 /* LDO2_ENA */ | ||
404 | #define WM8400_LDO2_SWI 0x4000 /* LDO2_SWI */ | ||
405 | #define WM8400_LDO2_SWI_MASK 0x4000 /* LDO2_SWI */ | ||
406 | #define WM8400_LDO2_SWI_SHIFT 14 /* LDO2_SWI */ | ||
407 | #define WM8400_LDO2_SWI_WIDTH 1 /* LDO2_SWI */ | ||
408 | #define WM8400_LDO2_OPFLT 0x1000 /* LDO2_OPFLT */ | ||
409 | #define WM8400_LDO2_OPFLT_MASK 0x1000 /* LDO2_OPFLT */ | ||
410 | #define WM8400_LDO2_OPFLT_SHIFT 12 /* LDO2_OPFLT */ | ||
411 | #define WM8400_LDO2_OPFLT_WIDTH 1 /* LDO2_OPFLT */ | ||
412 | #define WM8400_LDO2_ERRACT 0x0800 /* LDO2_ERRACT */ | ||
413 | #define WM8400_LDO2_ERRACT_MASK 0x0800 /* LDO2_ERRACT */ | ||
414 | #define WM8400_LDO2_ERRACT_SHIFT 11 /* LDO2_ERRACT */ | ||
415 | #define WM8400_LDO2_ERRACT_WIDTH 1 /* LDO2_ERRACT */ | ||
416 | #define WM8400_LDO2_HIB_MODE 0x0400 /* LDO2_HIB_MODE */ | ||
417 | #define WM8400_LDO2_HIB_MODE_MASK 0x0400 /* LDO2_HIB_MODE */ | ||
418 | #define WM8400_LDO2_HIB_MODE_SHIFT 10 /* LDO2_HIB_MODE */ | ||
419 | #define WM8400_LDO2_HIB_MODE_WIDTH 1 /* LDO2_HIB_MODE */ | ||
420 | #define WM8400_LDO2_VIMG_MASK 0x03E0 /* LDO2_VIMG - [9:5] */ | ||
421 | #define WM8400_LDO2_VIMG_SHIFT 5 /* LDO2_VIMG - [9:5] */ | ||
422 | #define WM8400_LDO2_VIMG_WIDTH 5 /* LDO2_VIMG - [9:5] */ | ||
423 | #define WM8400_LDO2_VSEL_MASK 0x001F /* LDO2_VSEL - [4:0] */ | ||
424 | #define WM8400_LDO2_VSEL_SHIFT 0 /* LDO2_VSEL - [4:0] */ | ||
425 | #define WM8400_LDO2_VSEL_WIDTH 5 /* LDO2_VSEL - [4:0] */ | ||
426 | |||
427 | /* | ||
428 | * R67 (0x43) - LDO 3 Control | ||
429 | */ | ||
430 | #define WM8400_LDO3_ENA 0x8000 /* LDO3_ENA */ | ||
431 | #define WM8400_LDO3_ENA_MASK 0x8000 /* LDO3_ENA */ | ||
432 | #define WM8400_LDO3_ENA_SHIFT 15 /* LDO3_ENA */ | ||
433 | #define WM8400_LDO3_ENA_WIDTH 1 /* LDO3_ENA */ | ||
434 | #define WM8400_LDO3_SWI 0x4000 /* LDO3_SWI */ | ||
435 | #define WM8400_LDO3_SWI_MASK 0x4000 /* LDO3_SWI */ | ||
436 | #define WM8400_LDO3_SWI_SHIFT 14 /* LDO3_SWI */ | ||
437 | #define WM8400_LDO3_SWI_WIDTH 1 /* LDO3_SWI */ | ||
438 | #define WM8400_LDO3_OPFLT 0x1000 /* LDO3_OPFLT */ | ||
439 | #define WM8400_LDO3_OPFLT_MASK 0x1000 /* LDO3_OPFLT */ | ||
440 | #define WM8400_LDO3_OPFLT_SHIFT 12 /* LDO3_OPFLT */ | ||
441 | #define WM8400_LDO3_OPFLT_WIDTH 1 /* LDO3_OPFLT */ | ||
442 | #define WM8400_LDO3_ERRACT 0x0800 /* LDO3_ERRACT */ | ||
443 | #define WM8400_LDO3_ERRACT_MASK 0x0800 /* LDO3_ERRACT */ | ||
444 | #define WM8400_LDO3_ERRACT_SHIFT 11 /* LDO3_ERRACT */ | ||
445 | #define WM8400_LDO3_ERRACT_WIDTH 1 /* LDO3_ERRACT */ | ||
446 | #define WM8400_LDO3_HIB_MODE 0x0400 /* LDO3_HIB_MODE */ | ||
447 | #define WM8400_LDO3_HIB_MODE_MASK 0x0400 /* LDO3_HIB_MODE */ | ||
448 | #define WM8400_LDO3_HIB_MODE_SHIFT 10 /* LDO3_HIB_MODE */ | ||
449 | #define WM8400_LDO3_HIB_MODE_WIDTH 1 /* LDO3_HIB_MODE */ | ||
450 | #define WM8400_LDO3_VIMG_MASK 0x03E0 /* LDO3_VIMG - [9:5] */ | ||
451 | #define WM8400_LDO3_VIMG_SHIFT 5 /* LDO3_VIMG - [9:5] */ | ||
452 | #define WM8400_LDO3_VIMG_WIDTH 5 /* LDO3_VIMG - [9:5] */ | ||
453 | #define WM8400_LDO3_VSEL_MASK 0x001F /* LDO3_VSEL - [4:0] */ | ||
454 | #define WM8400_LDO3_VSEL_SHIFT 0 /* LDO3_VSEL - [4:0] */ | ||
455 | #define WM8400_LDO3_VSEL_WIDTH 5 /* LDO3_VSEL - [4:0] */ | ||
456 | |||
457 | /* | ||
458 | * R68 (0x44) - LDO 4 Control | ||
459 | */ | ||
460 | #define WM8400_LDO4_ENA 0x8000 /* LDO4_ENA */ | ||
461 | #define WM8400_LDO4_ENA_MASK 0x8000 /* LDO4_ENA */ | ||
462 | #define WM8400_LDO4_ENA_SHIFT 15 /* LDO4_ENA */ | ||
463 | #define WM8400_LDO4_ENA_WIDTH 1 /* LDO4_ENA */ | ||
464 | #define WM8400_LDO4_SWI 0x4000 /* LDO4_SWI */ | ||
465 | #define WM8400_LDO4_SWI_MASK 0x4000 /* LDO4_SWI */ | ||
466 | #define WM8400_LDO4_SWI_SHIFT 14 /* LDO4_SWI */ | ||
467 | #define WM8400_LDO4_SWI_WIDTH 1 /* LDO4_SWI */ | ||
468 | #define WM8400_LDO4_OPFLT 0x1000 /* LDO4_OPFLT */ | ||
469 | #define WM8400_LDO4_OPFLT_MASK 0x1000 /* LDO4_OPFLT */ | ||
470 | #define WM8400_LDO4_OPFLT_SHIFT 12 /* LDO4_OPFLT */ | ||
471 | #define WM8400_LDO4_OPFLT_WIDTH 1 /* LDO4_OPFLT */ | ||
472 | #define WM8400_LDO4_ERRACT 0x0800 /* LDO4_ERRACT */ | ||
473 | #define WM8400_LDO4_ERRACT_MASK 0x0800 /* LDO4_ERRACT */ | ||
474 | #define WM8400_LDO4_ERRACT_SHIFT 11 /* LDO4_ERRACT */ | ||
475 | #define WM8400_LDO4_ERRACT_WIDTH 1 /* LDO4_ERRACT */ | ||
476 | #define WM8400_LDO4_HIB_MODE 0x0400 /* LDO4_HIB_MODE */ | ||
477 | #define WM8400_LDO4_HIB_MODE_MASK 0x0400 /* LDO4_HIB_MODE */ | ||
478 | #define WM8400_LDO4_HIB_MODE_SHIFT 10 /* LDO4_HIB_MODE */ | ||
479 | #define WM8400_LDO4_HIB_MODE_WIDTH 1 /* LDO4_HIB_MODE */ | ||
480 | #define WM8400_LDO4_VIMG_MASK 0x03E0 /* LDO4_VIMG - [9:5] */ | ||
481 | #define WM8400_LDO4_VIMG_SHIFT 5 /* LDO4_VIMG - [9:5] */ | ||
482 | #define WM8400_LDO4_VIMG_WIDTH 5 /* LDO4_VIMG - [9:5] */ | ||
483 | #define WM8400_LDO4_VSEL_MASK 0x001F /* LDO4_VSEL - [4:0] */ | ||
484 | #define WM8400_LDO4_VSEL_SHIFT 0 /* LDO4_VSEL - [4:0] */ | ||
485 | #define WM8400_LDO4_VSEL_WIDTH 5 /* LDO4_VSEL - [4:0] */ | ||
486 | |||
487 | /* | ||
488 | * R70 (0x46) - DCDC1 Control 1 | ||
489 | */ | ||
490 | #define WM8400_DC1_ENA 0x8000 /* DC1_ENA */ | ||
491 | #define WM8400_DC1_ENA_MASK 0x8000 /* DC1_ENA */ | ||
492 | #define WM8400_DC1_ENA_SHIFT 15 /* DC1_ENA */ | ||
493 | #define WM8400_DC1_ENA_WIDTH 1 /* DC1_ENA */ | ||
494 | #define WM8400_DC1_ACTIVE 0x4000 /* DC1_ACTIVE */ | ||
495 | #define WM8400_DC1_ACTIVE_MASK 0x4000 /* DC1_ACTIVE */ | ||
496 | #define WM8400_DC1_ACTIVE_SHIFT 14 /* DC1_ACTIVE */ | ||
497 | #define WM8400_DC1_ACTIVE_WIDTH 1 /* DC1_ACTIVE */ | ||
498 | #define WM8400_DC1_SLEEP 0x2000 /* DC1_SLEEP */ | ||
499 | #define WM8400_DC1_SLEEP_MASK 0x2000 /* DC1_SLEEP */ | ||
500 | #define WM8400_DC1_SLEEP_SHIFT 13 /* DC1_SLEEP */ | ||
501 | #define WM8400_DC1_SLEEP_WIDTH 1 /* DC1_SLEEP */ | ||
502 | #define WM8400_DC1_OPFLT 0x1000 /* DC1_OPFLT */ | ||
503 | #define WM8400_DC1_OPFLT_MASK 0x1000 /* DC1_OPFLT */ | ||
504 | #define WM8400_DC1_OPFLT_SHIFT 12 /* DC1_OPFLT */ | ||
505 | #define WM8400_DC1_OPFLT_WIDTH 1 /* DC1_OPFLT */ | ||
506 | #define WM8400_DC1_ERRACT 0x0800 /* DC1_ERRACT */ | ||
507 | #define WM8400_DC1_ERRACT_MASK 0x0800 /* DC1_ERRACT */ | ||
508 | #define WM8400_DC1_ERRACT_SHIFT 11 /* DC1_ERRACT */ | ||
509 | #define WM8400_DC1_ERRACT_WIDTH 1 /* DC1_ERRACT */ | ||
510 | #define WM8400_DC1_HIB_MODE 0x0400 /* DC1_HIB_MODE */ | ||
511 | #define WM8400_DC1_HIB_MODE_MASK 0x0400 /* DC1_HIB_MODE */ | ||
512 | #define WM8400_DC1_HIB_MODE_SHIFT 10 /* DC1_HIB_MODE */ | ||
513 | #define WM8400_DC1_HIB_MODE_WIDTH 1 /* DC1_HIB_MODE */ | ||
514 | #define WM8400_DC1_SOFTST_MASK 0x0300 /* DC1_SOFTST - [9:8] */ | ||
515 | #define WM8400_DC1_SOFTST_SHIFT 8 /* DC1_SOFTST - [9:8] */ | ||
516 | #define WM8400_DC1_SOFTST_WIDTH 2 /* DC1_SOFTST - [9:8] */ | ||
517 | #define WM8400_DC1_OV_PROT 0x0080 /* DC1_OV_PROT */ | ||
518 | #define WM8400_DC1_OV_PROT_MASK 0x0080 /* DC1_OV_PROT */ | ||
519 | #define WM8400_DC1_OV_PROT_SHIFT 7 /* DC1_OV_PROT */ | ||
520 | #define WM8400_DC1_OV_PROT_WIDTH 1 /* DC1_OV_PROT */ | ||
521 | #define WM8400_DC1_VSEL_MASK 0x007F /* DC1_VSEL - [6:0] */ | ||
522 | #define WM8400_DC1_VSEL_SHIFT 0 /* DC1_VSEL - [6:0] */ | ||
523 | #define WM8400_DC1_VSEL_WIDTH 7 /* DC1_VSEL - [6:0] */ | ||
524 | |||
525 | /* | ||
526 | * R71 (0x47) - DCDC1 Control 2 | ||
527 | */ | ||
528 | #define WM8400_DC1_FRC_PWM 0x2000 /* DC1_FRC_PWM */ | ||
529 | #define WM8400_DC1_FRC_PWM_MASK 0x2000 /* DC1_FRC_PWM */ | ||
530 | #define WM8400_DC1_FRC_PWM_SHIFT 13 /* DC1_FRC_PWM */ | ||
531 | #define WM8400_DC1_FRC_PWM_WIDTH 1 /* DC1_FRC_PWM */ | ||
532 | #define WM8400_DC1_STBY_LIM_MASK 0x0300 /* DC1_STBY_LIM - [9:8] */ | ||
533 | #define WM8400_DC1_STBY_LIM_SHIFT 8 /* DC1_STBY_LIM - [9:8] */ | ||
534 | #define WM8400_DC1_STBY_LIM_WIDTH 2 /* DC1_STBY_LIM - [9:8] */ | ||
535 | #define WM8400_DC1_ACT_LIM 0x0080 /* DC1_ACT_LIM */ | ||
536 | #define WM8400_DC1_ACT_LIM_MASK 0x0080 /* DC1_ACT_LIM */ | ||
537 | #define WM8400_DC1_ACT_LIM_SHIFT 7 /* DC1_ACT_LIM */ | ||
538 | #define WM8400_DC1_ACT_LIM_WIDTH 1 /* DC1_ACT_LIM */ | ||
539 | #define WM8400_DC1_VIMG_MASK 0x007F /* DC1_VIMG - [6:0] */ | ||
540 | #define WM8400_DC1_VIMG_SHIFT 0 /* DC1_VIMG - [6:0] */ | ||
541 | #define WM8400_DC1_VIMG_WIDTH 7 /* DC1_VIMG - [6:0] */ | ||
542 | |||
543 | /* | ||
544 | * R72 (0x48) - DCDC2 Control 1 | ||
545 | */ | ||
546 | #define WM8400_DC2_ENA 0x8000 /* DC2_ENA */ | ||
547 | #define WM8400_DC2_ENA_MASK 0x8000 /* DC2_ENA */ | ||
548 | #define WM8400_DC2_ENA_SHIFT 15 /* DC2_ENA */ | ||
549 | #define WM8400_DC2_ENA_WIDTH 1 /* DC2_ENA */ | ||
550 | #define WM8400_DC2_ACTIVE 0x4000 /* DC2_ACTIVE */ | ||
551 | #define WM8400_DC2_ACTIVE_MASK 0x4000 /* DC2_ACTIVE */ | ||
552 | #define WM8400_DC2_ACTIVE_SHIFT 14 /* DC2_ACTIVE */ | ||
553 | #define WM8400_DC2_ACTIVE_WIDTH 1 /* DC2_ACTIVE */ | ||
554 | #define WM8400_DC2_SLEEP 0x2000 /* DC2_SLEEP */ | ||
555 | #define WM8400_DC2_SLEEP_MASK 0x2000 /* DC2_SLEEP */ | ||
556 | #define WM8400_DC2_SLEEP_SHIFT 13 /* DC2_SLEEP */ | ||
557 | #define WM8400_DC2_SLEEP_WIDTH 1 /* DC2_SLEEP */ | ||
558 | #define WM8400_DC2_OPFLT 0x1000 /* DC2_OPFLT */ | ||
559 | #define WM8400_DC2_OPFLT_MASK 0x1000 /* DC2_OPFLT */ | ||
560 | #define WM8400_DC2_OPFLT_SHIFT 12 /* DC2_OPFLT */ | ||
561 | #define WM8400_DC2_OPFLT_WIDTH 1 /* DC2_OPFLT */ | ||
562 | #define WM8400_DC2_ERRACT 0x0800 /* DC2_ERRACT */ | ||
563 | #define WM8400_DC2_ERRACT_MASK 0x0800 /* DC2_ERRACT */ | ||
564 | #define WM8400_DC2_ERRACT_SHIFT 11 /* DC2_ERRACT */ | ||
565 | #define WM8400_DC2_ERRACT_WIDTH 1 /* DC2_ERRACT */ | ||
566 | #define WM8400_DC2_HIB_MODE 0x0400 /* DC2_HIB_MODE */ | ||
567 | #define WM8400_DC2_HIB_MODE_MASK 0x0400 /* DC2_HIB_MODE */ | ||
568 | #define WM8400_DC2_HIB_MODE_SHIFT 10 /* DC2_HIB_MODE */ | ||
569 | #define WM8400_DC2_HIB_MODE_WIDTH 1 /* DC2_HIB_MODE */ | ||
570 | #define WM8400_DC2_SOFTST_MASK 0x0300 /* DC2_SOFTST - [9:8] */ | ||
571 | #define WM8400_DC2_SOFTST_SHIFT 8 /* DC2_SOFTST - [9:8] */ | ||
572 | #define WM8400_DC2_SOFTST_WIDTH 2 /* DC2_SOFTST - [9:8] */ | ||
573 | #define WM8400_DC2_OV_PROT 0x0080 /* DC2_OV_PROT */ | ||
574 | #define WM8400_DC2_OV_PROT_MASK 0x0080 /* DC2_OV_PROT */ | ||
575 | #define WM8400_DC2_OV_PROT_SHIFT 7 /* DC2_OV_PROT */ | ||
576 | #define WM8400_DC2_OV_PROT_WIDTH 1 /* DC2_OV_PROT */ | ||
577 | #define WM8400_DC2_VSEL_MASK 0x007F /* DC2_VSEL - [6:0] */ | ||
578 | #define WM8400_DC2_VSEL_SHIFT 0 /* DC2_VSEL - [6:0] */ | ||
579 | #define WM8400_DC2_VSEL_WIDTH 7 /* DC2_VSEL - [6:0] */ | ||
580 | |||
581 | /* | ||
582 | * R73 (0x49) - DCDC2 Control 2 | ||
583 | */ | ||
584 | #define WM8400_DC2_FRC_PWM 0x2000 /* DC2_FRC_PWM */ | ||
585 | #define WM8400_DC2_FRC_PWM_MASK 0x2000 /* DC2_FRC_PWM */ | ||
586 | #define WM8400_DC2_FRC_PWM_SHIFT 13 /* DC2_FRC_PWM */ | ||
587 | #define WM8400_DC2_FRC_PWM_WIDTH 1 /* DC2_FRC_PWM */ | ||
588 | #define WM8400_DC2_STBY_LIM_MASK 0x0300 /* DC2_STBY_LIM - [9:8] */ | ||
589 | #define WM8400_DC2_STBY_LIM_SHIFT 8 /* DC2_STBY_LIM - [9:8] */ | ||
590 | #define WM8400_DC2_STBY_LIM_WIDTH 2 /* DC2_STBY_LIM - [9:8] */ | ||
591 | #define WM8400_DC2_ACT_LIM 0x0080 /* DC2_ACT_LIM */ | ||
592 | #define WM8400_DC2_ACT_LIM_MASK 0x0080 /* DC2_ACT_LIM */ | ||
593 | #define WM8400_DC2_ACT_LIM_SHIFT 7 /* DC2_ACT_LIM */ | ||
594 | #define WM8400_DC2_ACT_LIM_WIDTH 1 /* DC2_ACT_LIM */ | ||
595 | #define WM8400_DC2_VIMG_MASK 0x007F /* DC2_VIMG - [6:0] */ | ||
596 | #define WM8400_DC2_VIMG_SHIFT 0 /* DC2_VIMG - [6:0] */ | ||
597 | #define WM8400_DC2_VIMG_WIDTH 7 /* DC2_VIMG - [6:0] */ | ||
598 | |||
599 | /* | ||
600 | * R75 (0x4B) - Interface | ||
601 | */ | ||
602 | #define WM8400_AUTOINC 0x0008 /* AUTOINC */ | ||
603 | #define WM8400_AUTOINC_MASK 0x0008 /* AUTOINC */ | ||
604 | #define WM8400_AUTOINC_SHIFT 3 /* AUTOINC */ | ||
605 | #define WM8400_AUTOINC_WIDTH 1 /* AUTOINC */ | ||
606 | #define WM8400_ARA_ENA 0x0004 /* ARA_ENA */ | ||
607 | #define WM8400_ARA_ENA_MASK 0x0004 /* ARA_ENA */ | ||
608 | #define WM8400_ARA_ENA_SHIFT 2 /* ARA_ENA */ | ||
609 | #define WM8400_ARA_ENA_WIDTH 1 /* ARA_ENA */ | ||
610 | #define WM8400_SPI_CFG 0x0002 /* SPI_CFG */ | ||
611 | #define WM8400_SPI_CFG_MASK 0x0002 /* SPI_CFG */ | ||
612 | #define WM8400_SPI_CFG_SHIFT 1 /* SPI_CFG */ | ||
613 | #define WM8400_SPI_CFG_WIDTH 1 /* SPI_CFG */ | ||
614 | |||
615 | /* | ||
616 | * R76 (0x4C) - PM GENERAL | ||
617 | */ | ||
618 | #define WM8400_CODEC_SOFTST 0x8000 /* CODEC_SOFTST */ | ||
619 | #define WM8400_CODEC_SOFTST_MASK 0x8000 /* CODEC_SOFTST */ | ||
620 | #define WM8400_CODEC_SOFTST_SHIFT 15 /* CODEC_SOFTST */ | ||
621 | #define WM8400_CODEC_SOFTST_WIDTH 1 /* CODEC_SOFTST */ | ||
622 | #define WM8400_CODEC_SOFTSD 0x4000 /* CODEC_SOFTSD */ | ||
623 | #define WM8400_CODEC_SOFTSD_MASK 0x4000 /* CODEC_SOFTSD */ | ||
624 | #define WM8400_CODEC_SOFTSD_SHIFT 14 /* CODEC_SOFTSD */ | ||
625 | #define WM8400_CODEC_SOFTSD_WIDTH 1 /* CODEC_SOFTSD */ | ||
626 | #define WM8400_CHIP_SOFTSD 0x2000 /* CHIP_SOFTSD */ | ||
627 | #define WM8400_CHIP_SOFTSD_MASK 0x2000 /* CHIP_SOFTSD */ | ||
628 | #define WM8400_CHIP_SOFTSD_SHIFT 13 /* CHIP_SOFTSD */ | ||
629 | #define WM8400_CHIP_SOFTSD_WIDTH 1 /* CHIP_SOFTSD */ | ||
630 | #define WM8400_DSLEEP1_POL 0x0008 /* DSLEEP1_POL */ | ||
631 | #define WM8400_DSLEEP1_POL_MASK 0x0008 /* DSLEEP1_POL */ | ||
632 | #define WM8400_DSLEEP1_POL_SHIFT 3 /* DSLEEP1_POL */ | ||
633 | #define WM8400_DSLEEP1_POL_WIDTH 1 /* DSLEEP1_POL */ | ||
634 | #define WM8400_DSLEEP2_POL 0x0004 /* DSLEEP2_POL */ | ||
635 | #define WM8400_DSLEEP2_POL_MASK 0x0004 /* DSLEEP2_POL */ | ||
636 | #define WM8400_DSLEEP2_POL_SHIFT 2 /* DSLEEP2_POL */ | ||
637 | #define WM8400_DSLEEP2_POL_WIDTH 1 /* DSLEEP2_POL */ | ||
638 | #define WM8400_PWR_STATE_MASK 0x0003 /* PWR_STATE - [1:0] */ | ||
639 | #define WM8400_PWR_STATE_SHIFT 0 /* PWR_STATE - [1:0] */ | ||
640 | #define WM8400_PWR_STATE_WIDTH 2 /* PWR_STATE - [1:0] */ | ||
641 | |||
642 | /* | ||
643 | * R78 (0x4E) - PM Shutdown Control | ||
644 | */ | ||
645 | #define WM8400_CHIP_GT150_ERRACT 0x0200 /* CHIP_GT150_ERRACT */ | ||
646 | #define WM8400_CHIP_GT150_ERRACT_MASK 0x0200 /* CHIP_GT150_ERRACT */ | ||
647 | #define WM8400_CHIP_GT150_ERRACT_SHIFT 9 /* CHIP_GT150_ERRACT */ | ||
648 | #define WM8400_CHIP_GT150_ERRACT_WIDTH 1 /* CHIP_GT150_ERRACT */ | ||
649 | #define WM8400_CHIP_GT115_ERRACT 0x0100 /* CHIP_GT115_ERRACT */ | ||
650 | #define WM8400_CHIP_GT115_ERRACT_MASK 0x0100 /* CHIP_GT115_ERRACT */ | ||
651 | #define WM8400_CHIP_GT115_ERRACT_SHIFT 8 /* CHIP_GT115_ERRACT */ | ||
652 | #define WM8400_CHIP_GT115_ERRACT_WIDTH 1 /* CHIP_GT115_ERRACT */ | ||
653 | #define WM8400_LINE_CMP_ERRACT 0x0080 /* LINE_CMP_ERRACT */ | ||
654 | #define WM8400_LINE_CMP_ERRACT_MASK 0x0080 /* LINE_CMP_ERRACT */ | ||
655 | #define WM8400_LINE_CMP_ERRACT_SHIFT 7 /* LINE_CMP_ERRACT */ | ||
656 | #define WM8400_LINE_CMP_ERRACT_WIDTH 1 /* LINE_CMP_ERRACT */ | ||
657 | #define WM8400_UVLO_ERRACT 0x0040 /* UVLO_ERRACT */ | ||
658 | #define WM8400_UVLO_ERRACT_MASK 0x0040 /* UVLO_ERRACT */ | ||
659 | #define WM8400_UVLO_ERRACT_SHIFT 6 /* UVLO_ERRACT */ | ||
660 | #define WM8400_UVLO_ERRACT_WIDTH 1 /* UVLO_ERRACT */ | ||
661 | |||
662 | /* | ||
663 | * R79 (0x4F) - Interrupt Status 1 | ||
664 | */ | ||
665 | #define WM8400_MICD_CINT 0x8000 /* MICD_CINT */ | ||
666 | #define WM8400_MICD_CINT_MASK 0x8000 /* MICD_CINT */ | ||
667 | #define WM8400_MICD_CINT_SHIFT 15 /* MICD_CINT */ | ||
668 | #define WM8400_MICD_CINT_WIDTH 1 /* MICD_CINT */ | ||
669 | #define WM8400_MICSCD_CINT 0x4000 /* MICSCD_CINT */ | ||
670 | #define WM8400_MICSCD_CINT_MASK 0x4000 /* MICSCD_CINT */ | ||
671 | #define WM8400_MICSCD_CINT_SHIFT 14 /* MICSCD_CINT */ | ||
672 | #define WM8400_MICSCD_CINT_WIDTH 1 /* MICSCD_CINT */ | ||
673 | #define WM8400_JDL_CINT 0x2000 /* JDL_CINT */ | ||
674 | #define WM8400_JDL_CINT_MASK 0x2000 /* JDL_CINT */ | ||
675 | #define WM8400_JDL_CINT_SHIFT 13 /* JDL_CINT */ | ||
676 | #define WM8400_JDL_CINT_WIDTH 1 /* JDL_CINT */ | ||
677 | #define WM8400_JDR_CINT 0x1000 /* JDR_CINT */ | ||
678 | #define WM8400_JDR_CINT_MASK 0x1000 /* JDR_CINT */ | ||
679 | #define WM8400_JDR_CINT_SHIFT 12 /* JDR_CINT */ | ||
680 | #define WM8400_JDR_CINT_WIDTH 1 /* JDR_CINT */ | ||
681 | #define WM8400_CODEC_SEQ_END_EINT 0x0800 /* CODEC_SEQ_END_EINT */ | ||
682 | #define WM8400_CODEC_SEQ_END_EINT_MASK 0x0800 /* CODEC_SEQ_END_EINT */ | ||
683 | #define WM8400_CODEC_SEQ_END_EINT_SHIFT 11 /* CODEC_SEQ_END_EINT */ | ||
684 | #define WM8400_CODEC_SEQ_END_EINT_WIDTH 1 /* CODEC_SEQ_END_EINT */ | ||
685 | #define WM8400_CDEL_TO_EINT 0x0400 /* CDEL_TO_EINT */ | ||
686 | #define WM8400_CDEL_TO_EINT_MASK 0x0400 /* CDEL_TO_EINT */ | ||
687 | #define WM8400_CDEL_TO_EINT_SHIFT 10 /* CDEL_TO_EINT */ | ||
688 | #define WM8400_CDEL_TO_EINT_WIDTH 1 /* CDEL_TO_EINT */ | ||
689 | #define WM8400_CHIP_GT150_EINT 0x0200 /* CHIP_GT150_EINT */ | ||
690 | #define WM8400_CHIP_GT150_EINT_MASK 0x0200 /* CHIP_GT150_EINT */ | ||
691 | #define WM8400_CHIP_GT150_EINT_SHIFT 9 /* CHIP_GT150_EINT */ | ||
692 | #define WM8400_CHIP_GT150_EINT_WIDTH 1 /* CHIP_GT150_EINT */ | ||
693 | #define WM8400_CHIP_GT115_EINT 0x0100 /* CHIP_GT115_EINT */ | ||
694 | #define WM8400_CHIP_GT115_EINT_MASK 0x0100 /* CHIP_GT115_EINT */ | ||
695 | #define WM8400_CHIP_GT115_EINT_SHIFT 8 /* CHIP_GT115_EINT */ | ||
696 | #define WM8400_CHIP_GT115_EINT_WIDTH 1 /* CHIP_GT115_EINT */ | ||
697 | #define WM8400_LINE_CMP_EINT 0x0080 /* LINE_CMP_EINT */ | ||
698 | #define WM8400_LINE_CMP_EINT_MASK 0x0080 /* LINE_CMP_EINT */ | ||
699 | #define WM8400_LINE_CMP_EINT_SHIFT 7 /* LINE_CMP_EINT */ | ||
700 | #define WM8400_LINE_CMP_EINT_WIDTH 1 /* LINE_CMP_EINT */ | ||
701 | #define WM8400_UVLO_EINT 0x0040 /* UVLO_EINT */ | ||
702 | #define WM8400_UVLO_EINT_MASK 0x0040 /* UVLO_EINT */ | ||
703 | #define WM8400_UVLO_EINT_SHIFT 6 /* UVLO_EINT */ | ||
704 | #define WM8400_UVLO_EINT_WIDTH 1 /* UVLO_EINT */ | ||
705 | #define WM8400_DC2_UV_EINT 0x0020 /* DC2_UV_EINT */ | ||
706 | #define WM8400_DC2_UV_EINT_MASK 0x0020 /* DC2_UV_EINT */ | ||
707 | #define WM8400_DC2_UV_EINT_SHIFT 5 /* DC2_UV_EINT */ | ||
708 | #define WM8400_DC2_UV_EINT_WIDTH 1 /* DC2_UV_EINT */ | ||
709 | #define WM8400_DC1_UV_EINT 0x0010 /* DC1_UV_EINT */ | ||
710 | #define WM8400_DC1_UV_EINT_MASK 0x0010 /* DC1_UV_EINT */ | ||
711 | #define WM8400_DC1_UV_EINT_SHIFT 4 /* DC1_UV_EINT */ | ||
712 | #define WM8400_DC1_UV_EINT_WIDTH 1 /* DC1_UV_EINT */ | ||
713 | #define WM8400_LDO4_UV_EINT 0x0008 /* LDO4_UV_EINT */ | ||
714 | #define WM8400_LDO4_UV_EINT_MASK 0x0008 /* LDO4_UV_EINT */ | ||
715 | #define WM8400_LDO4_UV_EINT_SHIFT 3 /* LDO4_UV_EINT */ | ||
716 | #define WM8400_LDO4_UV_EINT_WIDTH 1 /* LDO4_UV_EINT */ | ||
717 | #define WM8400_LDO3_UV_EINT 0x0004 /* LDO3_UV_EINT */ | ||
718 | #define WM8400_LDO3_UV_EINT_MASK 0x0004 /* LDO3_UV_EINT */ | ||
719 | #define WM8400_LDO3_UV_EINT_SHIFT 2 /* LDO3_UV_EINT */ | ||
720 | #define WM8400_LDO3_UV_EINT_WIDTH 1 /* LDO3_UV_EINT */ | ||
721 | #define WM8400_LDO2_UV_EINT 0x0002 /* LDO2_UV_EINT */ | ||
722 | #define WM8400_LDO2_UV_EINT_MASK 0x0002 /* LDO2_UV_EINT */ | ||
723 | #define WM8400_LDO2_UV_EINT_SHIFT 1 /* LDO2_UV_EINT */ | ||
724 | #define WM8400_LDO2_UV_EINT_WIDTH 1 /* LDO2_UV_EINT */ | ||
725 | #define WM8400_LDO1_UV_EINT 0x0001 /* LDO1_UV_EINT */ | ||
726 | #define WM8400_LDO1_UV_EINT_MASK 0x0001 /* LDO1_UV_EINT */ | ||
727 | #define WM8400_LDO1_UV_EINT_SHIFT 0 /* LDO1_UV_EINT */ | ||
728 | #define WM8400_LDO1_UV_EINT_WIDTH 1 /* LDO1_UV_EINT */ | ||
729 | |||
730 | /* | ||
731 | * R80 (0x50) - Interrupt Status 1 Mask | ||
732 | */ | ||
733 | #define WM8400_IM_MICD_CINT 0x8000 /* IM_MICD_CINT */ | ||
734 | #define WM8400_IM_MICD_CINT_MASK 0x8000 /* IM_MICD_CINT */ | ||
735 | #define WM8400_IM_MICD_CINT_SHIFT 15 /* IM_MICD_CINT */ | ||
736 | #define WM8400_IM_MICD_CINT_WIDTH 1 /* IM_MICD_CINT */ | ||
737 | #define WM8400_IM_MICSCD_CINT 0x4000 /* IM_MICSCD_CINT */ | ||
738 | #define WM8400_IM_MICSCD_CINT_MASK 0x4000 /* IM_MICSCD_CINT */ | ||
739 | #define WM8400_IM_MICSCD_CINT_SHIFT 14 /* IM_MICSCD_CINT */ | ||
740 | #define WM8400_IM_MICSCD_CINT_WIDTH 1 /* IM_MICSCD_CINT */ | ||
741 | #define WM8400_IM_JDL_CINT 0x2000 /* IM_JDL_CINT */ | ||
742 | #define WM8400_IM_JDL_CINT_MASK 0x2000 /* IM_JDL_CINT */ | ||
743 | #define WM8400_IM_JDL_CINT_SHIFT 13 /* IM_JDL_CINT */ | ||
744 | #define WM8400_IM_JDL_CINT_WIDTH 1 /* IM_JDL_CINT */ | ||
745 | #define WM8400_IM_JDR_CINT 0x1000 /* IM_JDR_CINT */ | ||
746 | #define WM8400_IM_JDR_CINT_MASK 0x1000 /* IM_JDR_CINT */ | ||
747 | #define WM8400_IM_JDR_CINT_SHIFT 12 /* IM_JDR_CINT */ | ||
748 | #define WM8400_IM_JDR_CINT_WIDTH 1 /* IM_JDR_CINT */ | ||
749 | #define WM8400_IM_CODEC_SEQ_END_EINT 0x0800 /* IM_CODEC_SEQ_END_EINT */ | ||
750 | #define WM8400_IM_CODEC_SEQ_END_EINT_MASK 0x0800 /* IM_CODEC_SEQ_END_EINT */ | ||
751 | #define WM8400_IM_CODEC_SEQ_END_EINT_SHIFT 11 /* IM_CODEC_SEQ_END_EINT */ | ||
752 | #define WM8400_IM_CODEC_SEQ_END_EINT_WIDTH 1 /* IM_CODEC_SEQ_END_EINT */ | ||
753 | #define WM8400_IM_CDEL_TO_EINT 0x0400 /* IM_CDEL_TO_EINT */ | ||
754 | #define WM8400_IM_CDEL_TO_EINT_MASK 0x0400 /* IM_CDEL_TO_EINT */ | ||
755 | #define WM8400_IM_CDEL_TO_EINT_SHIFT 10 /* IM_CDEL_TO_EINT */ | ||
756 | #define WM8400_IM_CDEL_TO_EINT_WIDTH 1 /* IM_CDEL_TO_EINT */ | ||
757 | #define WM8400_IM_CHIP_GT150_EINT 0x0200 /* IM_CHIP_GT150_EINT */ | ||
758 | #define WM8400_IM_CHIP_GT150_EINT_MASK 0x0200 /* IM_CHIP_GT150_EINT */ | ||
759 | #define WM8400_IM_CHIP_GT150_EINT_SHIFT 9 /* IM_CHIP_GT150_EINT */ | ||
760 | #define WM8400_IM_CHIP_GT150_EINT_WIDTH 1 /* IM_CHIP_GT150_EINT */ | ||
761 | #define WM8400_IM_CHIP_GT115_EINT 0x0100 /* IM_CHIP_GT115_EINT */ | ||
762 | #define WM8400_IM_CHIP_GT115_EINT_MASK 0x0100 /* IM_CHIP_GT115_EINT */ | ||
763 | #define WM8400_IM_CHIP_GT115_EINT_SHIFT 8 /* IM_CHIP_GT115_EINT */ | ||
764 | #define WM8400_IM_CHIP_GT115_EINT_WIDTH 1 /* IM_CHIP_GT115_EINT */ | ||
765 | #define WM8400_IM_LINE_CMP_EINT 0x0080 /* IM_LINE_CMP_EINT */ | ||
766 | #define WM8400_IM_LINE_CMP_EINT_MASK 0x0080 /* IM_LINE_CMP_EINT */ | ||
767 | #define WM8400_IM_LINE_CMP_EINT_SHIFT 7 /* IM_LINE_CMP_EINT */ | ||
768 | #define WM8400_IM_LINE_CMP_EINT_WIDTH 1 /* IM_LINE_CMP_EINT */ | ||
769 | #define WM8400_IM_UVLO_EINT 0x0040 /* IM_UVLO_EINT */ | ||
770 | #define WM8400_IM_UVLO_EINT_MASK 0x0040 /* IM_UVLO_EINT */ | ||
771 | #define WM8400_IM_UVLO_EINT_SHIFT 6 /* IM_UVLO_EINT */ | ||
772 | #define WM8400_IM_UVLO_EINT_WIDTH 1 /* IM_UVLO_EINT */ | ||
773 | #define WM8400_IM_DC2_UV_EINT 0x0020 /* IM_DC2_UV_EINT */ | ||
774 | #define WM8400_IM_DC2_UV_EINT_MASK 0x0020 /* IM_DC2_UV_EINT */ | ||
775 | #define WM8400_IM_DC2_UV_EINT_SHIFT 5 /* IM_DC2_UV_EINT */ | ||
776 | #define WM8400_IM_DC2_UV_EINT_WIDTH 1 /* IM_DC2_UV_EINT */ | ||
777 | #define WM8400_IM_DC1_UV_EINT 0x0010 /* IM_DC1_UV_EINT */ | ||
778 | #define WM8400_IM_DC1_UV_EINT_MASK 0x0010 /* IM_DC1_UV_EINT */ | ||
779 | #define WM8400_IM_DC1_UV_EINT_SHIFT 4 /* IM_DC1_UV_EINT */ | ||
780 | #define WM8400_IM_DC1_UV_EINT_WIDTH 1 /* IM_DC1_UV_EINT */ | ||
781 | #define WM8400_IM_LDO4_UV_EINT 0x0008 /* IM_LDO4_UV_EINT */ | ||
782 | #define WM8400_IM_LDO4_UV_EINT_MASK 0x0008 /* IM_LDO4_UV_EINT */ | ||
783 | #define WM8400_IM_LDO4_UV_EINT_SHIFT 3 /* IM_LDO4_UV_EINT */ | ||
784 | #define WM8400_IM_LDO4_UV_EINT_WIDTH 1 /* IM_LDO4_UV_EINT */ | ||
785 | #define WM8400_IM_LDO3_UV_EINT 0x0004 /* IM_LDO3_UV_EINT */ | ||
786 | #define WM8400_IM_LDO3_UV_EINT_MASK 0x0004 /* IM_LDO3_UV_EINT */ | ||
787 | #define WM8400_IM_LDO3_UV_EINT_SHIFT 2 /* IM_LDO3_UV_EINT */ | ||
788 | #define WM8400_IM_LDO3_UV_EINT_WIDTH 1 /* IM_LDO3_UV_EINT */ | ||
789 | #define WM8400_IM_LDO2_UV_EINT 0x0002 /* IM_LDO2_UV_EINT */ | ||
790 | #define WM8400_IM_LDO2_UV_EINT_MASK 0x0002 /* IM_LDO2_UV_EINT */ | ||
791 | #define WM8400_IM_LDO2_UV_EINT_SHIFT 1 /* IM_LDO2_UV_EINT */ | ||
792 | #define WM8400_IM_LDO2_UV_EINT_WIDTH 1 /* IM_LDO2_UV_EINT */ | ||
793 | #define WM8400_IM_LDO1_UV_EINT 0x0001 /* IM_LDO1_UV_EINT */ | ||
794 | #define WM8400_IM_LDO1_UV_EINT_MASK 0x0001 /* IM_LDO1_UV_EINT */ | ||
795 | #define WM8400_IM_LDO1_UV_EINT_SHIFT 0 /* IM_LDO1_UV_EINT */ | ||
796 | #define WM8400_IM_LDO1_UV_EINT_WIDTH 1 /* IM_LDO1_UV_EINT */ | ||
797 | |||
798 | /* | ||
799 | * R81 (0x51) - Interrupt Levels | ||
800 | */ | ||
801 | #define WM8400_MICD_LVL 0x8000 /* MICD_LVL */ | ||
802 | #define WM8400_MICD_LVL_MASK 0x8000 /* MICD_LVL */ | ||
803 | #define WM8400_MICD_LVL_SHIFT 15 /* MICD_LVL */ | ||
804 | #define WM8400_MICD_LVL_WIDTH 1 /* MICD_LVL */ | ||
805 | #define WM8400_MICSCD_LVL 0x4000 /* MICSCD_LVL */ | ||
806 | #define WM8400_MICSCD_LVL_MASK 0x4000 /* MICSCD_LVL */ | ||
807 | #define WM8400_MICSCD_LVL_SHIFT 14 /* MICSCD_LVL */ | ||
808 | #define WM8400_MICSCD_LVL_WIDTH 1 /* MICSCD_LVL */ | ||
809 | #define WM8400_JDL_LVL 0x2000 /* JDL_LVL */ | ||
810 | #define WM8400_JDL_LVL_MASK 0x2000 /* JDL_LVL */ | ||
811 | #define WM8400_JDL_LVL_SHIFT 13 /* JDL_LVL */ | ||
812 | #define WM8400_JDL_LVL_WIDTH 1 /* JDL_LVL */ | ||
813 | #define WM8400_JDR_LVL 0x1000 /* JDR_LVL */ | ||
814 | #define WM8400_JDR_LVL_MASK 0x1000 /* JDR_LVL */ | ||
815 | #define WM8400_JDR_LVL_SHIFT 12 /* JDR_LVL */ | ||
816 | #define WM8400_JDR_LVL_WIDTH 1 /* JDR_LVL */ | ||
817 | #define WM8400_CODEC_SEQ_END_LVL 0x0800 /* CODEC_SEQ_END_LVL */ | ||
818 | #define WM8400_CODEC_SEQ_END_LVL_MASK 0x0800 /* CODEC_SEQ_END_LVL */ | ||
819 | #define WM8400_CODEC_SEQ_END_LVL_SHIFT 11 /* CODEC_SEQ_END_LVL */ | ||
820 | #define WM8400_CODEC_SEQ_END_LVL_WIDTH 1 /* CODEC_SEQ_END_LVL */ | ||
821 | #define WM8400_CDEL_TO_LVL 0x0400 /* CDEL_TO_LVL */ | ||
822 | #define WM8400_CDEL_TO_LVL_MASK 0x0400 /* CDEL_TO_LVL */ | ||
823 | #define WM8400_CDEL_TO_LVL_SHIFT 10 /* CDEL_TO_LVL */ | ||
824 | #define WM8400_CDEL_TO_LVL_WIDTH 1 /* CDEL_TO_LVL */ | ||
825 | #define WM8400_CHIP_GT150_LVL 0x0200 /* CHIP_GT150_LVL */ | ||
826 | #define WM8400_CHIP_GT150_LVL_MASK 0x0200 /* CHIP_GT150_LVL */ | ||
827 | #define WM8400_CHIP_GT150_LVL_SHIFT 9 /* CHIP_GT150_LVL */ | ||
828 | #define WM8400_CHIP_GT150_LVL_WIDTH 1 /* CHIP_GT150_LVL */ | ||
829 | #define WM8400_CHIP_GT115_LVL 0x0100 /* CHIP_GT115_LVL */ | ||
830 | #define WM8400_CHIP_GT115_LVL_MASK 0x0100 /* CHIP_GT115_LVL */ | ||
831 | #define WM8400_CHIP_GT115_LVL_SHIFT 8 /* CHIP_GT115_LVL */ | ||
832 | #define WM8400_CHIP_GT115_LVL_WIDTH 1 /* CHIP_GT115_LVL */ | ||
833 | #define WM8400_LINE_CMP_LVL 0x0080 /* LINE_CMP_LVL */ | ||
834 | #define WM8400_LINE_CMP_LVL_MASK 0x0080 /* LINE_CMP_LVL */ | ||
835 | #define WM8400_LINE_CMP_LVL_SHIFT 7 /* LINE_CMP_LVL */ | ||
836 | #define WM8400_LINE_CMP_LVL_WIDTH 1 /* LINE_CMP_LVL */ | ||
837 | #define WM8400_UVLO_LVL 0x0040 /* UVLO_LVL */ | ||
838 | #define WM8400_UVLO_LVL_MASK 0x0040 /* UVLO_LVL */ | ||
839 | #define WM8400_UVLO_LVL_SHIFT 6 /* UVLO_LVL */ | ||
840 | #define WM8400_UVLO_LVL_WIDTH 1 /* UVLO_LVL */ | ||
841 | #define WM8400_DC2_UV_LVL 0x0020 /* DC2_UV_LVL */ | ||
842 | #define WM8400_DC2_UV_LVL_MASK 0x0020 /* DC2_UV_LVL */ | ||
843 | #define WM8400_DC2_UV_LVL_SHIFT 5 /* DC2_UV_LVL */ | ||
844 | #define WM8400_DC2_UV_LVL_WIDTH 1 /* DC2_UV_LVL */ | ||
845 | #define WM8400_DC1_UV_LVL 0x0010 /* DC1_UV_LVL */ | ||
846 | #define WM8400_DC1_UV_LVL_MASK 0x0010 /* DC1_UV_LVL */ | ||
847 | #define WM8400_DC1_UV_LVL_SHIFT 4 /* DC1_UV_LVL */ | ||
848 | #define WM8400_DC1_UV_LVL_WIDTH 1 /* DC1_UV_LVL */ | ||
849 | #define WM8400_LDO4_UV_LVL 0x0008 /* LDO4_UV_LVL */ | ||
850 | #define WM8400_LDO4_UV_LVL_MASK 0x0008 /* LDO4_UV_LVL */ | ||
851 | #define WM8400_LDO4_UV_LVL_SHIFT 3 /* LDO4_UV_LVL */ | ||
852 | #define WM8400_LDO4_UV_LVL_WIDTH 1 /* LDO4_UV_LVL */ | ||
853 | #define WM8400_LDO3_UV_LVL 0x0004 /* LDO3_UV_LVL */ | ||
854 | #define WM8400_LDO3_UV_LVL_MASK 0x0004 /* LDO3_UV_LVL */ | ||
855 | #define WM8400_LDO3_UV_LVL_SHIFT 2 /* LDO3_UV_LVL */ | ||
856 | #define WM8400_LDO3_UV_LVL_WIDTH 1 /* LDO3_UV_LVL */ | ||
857 | #define WM8400_LDO2_UV_LVL 0x0002 /* LDO2_UV_LVL */ | ||
858 | #define WM8400_LDO2_UV_LVL_MASK 0x0002 /* LDO2_UV_LVL */ | ||
859 | #define WM8400_LDO2_UV_LVL_SHIFT 1 /* LDO2_UV_LVL */ | ||
860 | #define WM8400_LDO2_UV_LVL_WIDTH 1 /* LDO2_UV_LVL */ | ||
861 | #define WM8400_LDO1_UV_LVL 0x0001 /* LDO1_UV_LVL */ | ||
862 | #define WM8400_LDO1_UV_LVL_MASK 0x0001 /* LDO1_UV_LVL */ | ||
863 | #define WM8400_LDO1_UV_LVL_SHIFT 0 /* LDO1_UV_LVL */ | ||
864 | #define WM8400_LDO1_UV_LVL_WIDTH 1 /* LDO1_UV_LVL */ | ||
865 | |||
866 | /* | ||
867 | * R82 (0x52) - Shutdown Reason | ||
868 | */ | ||
869 | #define WM8400_SDR_CHIP_SOFTSD 0x2000 /* SDR_CHIP_SOFTSD */ | ||
870 | #define WM8400_SDR_CHIP_SOFTSD_MASK 0x2000 /* SDR_CHIP_SOFTSD */ | ||
871 | #define WM8400_SDR_CHIP_SOFTSD_SHIFT 13 /* SDR_CHIP_SOFTSD */ | ||
872 | #define WM8400_SDR_CHIP_SOFTSD_WIDTH 1 /* SDR_CHIP_SOFTSD */ | ||
873 | #define WM8400_SDR_NPDN 0x0800 /* SDR_NPDN */ | ||
874 | #define WM8400_SDR_NPDN_MASK 0x0800 /* SDR_NPDN */ | ||
875 | #define WM8400_SDR_NPDN_SHIFT 11 /* SDR_NPDN */ | ||
876 | #define WM8400_SDR_NPDN_WIDTH 1 /* SDR_NPDN */ | ||
877 | #define WM8400_SDR_CHIP_GT150 0x0200 /* SDR_CHIP_GT150 */ | ||
878 | #define WM8400_SDR_CHIP_GT150_MASK 0x0200 /* SDR_CHIP_GT150 */ | ||
879 | #define WM8400_SDR_CHIP_GT150_SHIFT 9 /* SDR_CHIP_GT150 */ | ||
880 | #define WM8400_SDR_CHIP_GT150_WIDTH 1 /* SDR_CHIP_GT150 */ | ||
881 | #define WM8400_SDR_CHIP_GT115 0x0100 /* SDR_CHIP_GT115 */ | ||
882 | #define WM8400_SDR_CHIP_GT115_MASK 0x0100 /* SDR_CHIP_GT115 */ | ||
883 | #define WM8400_SDR_CHIP_GT115_SHIFT 8 /* SDR_CHIP_GT115 */ | ||
884 | #define WM8400_SDR_CHIP_GT115_WIDTH 1 /* SDR_CHIP_GT115 */ | ||
885 | #define WM8400_SDR_LINE_CMP 0x0080 /* SDR_LINE_CMP */ | ||
886 | #define WM8400_SDR_LINE_CMP_MASK 0x0080 /* SDR_LINE_CMP */ | ||
887 | #define WM8400_SDR_LINE_CMP_SHIFT 7 /* SDR_LINE_CMP */ | ||
888 | #define WM8400_SDR_LINE_CMP_WIDTH 1 /* SDR_LINE_CMP */ | ||
889 | #define WM8400_SDR_UVLO 0x0040 /* SDR_UVLO */ | ||
890 | #define WM8400_SDR_UVLO_MASK 0x0040 /* SDR_UVLO */ | ||
891 | #define WM8400_SDR_UVLO_SHIFT 6 /* SDR_UVLO */ | ||
892 | #define WM8400_SDR_UVLO_WIDTH 1 /* SDR_UVLO */ | ||
893 | #define WM8400_SDR_DC2_UV 0x0020 /* SDR_DC2_UV */ | ||
894 | #define WM8400_SDR_DC2_UV_MASK 0x0020 /* SDR_DC2_UV */ | ||
895 | #define WM8400_SDR_DC2_UV_SHIFT 5 /* SDR_DC2_UV */ | ||
896 | #define WM8400_SDR_DC2_UV_WIDTH 1 /* SDR_DC2_UV */ | ||
897 | #define WM8400_SDR_DC1_UV 0x0010 /* SDR_DC1_UV */ | ||
898 | #define WM8400_SDR_DC1_UV_MASK 0x0010 /* SDR_DC1_UV */ | ||
899 | #define WM8400_SDR_DC1_UV_SHIFT 4 /* SDR_DC1_UV */ | ||
900 | #define WM8400_SDR_DC1_UV_WIDTH 1 /* SDR_DC1_UV */ | ||
901 | #define WM8400_SDR_LDO4_UV 0x0008 /* SDR_LDO4_UV */ | ||
902 | #define WM8400_SDR_LDO4_UV_MASK 0x0008 /* SDR_LDO4_UV */ | ||
903 | #define WM8400_SDR_LDO4_UV_SHIFT 3 /* SDR_LDO4_UV */ | ||
904 | #define WM8400_SDR_LDO4_UV_WIDTH 1 /* SDR_LDO4_UV */ | ||
905 | #define WM8400_SDR_LDO3_UV 0x0004 /* SDR_LDO3_UV */ | ||
906 | #define WM8400_SDR_LDO3_UV_MASK 0x0004 /* SDR_LDO3_UV */ | ||
907 | #define WM8400_SDR_LDO3_UV_SHIFT 2 /* SDR_LDO3_UV */ | ||
908 | #define WM8400_SDR_LDO3_UV_WIDTH 1 /* SDR_LDO3_UV */ | ||
909 | #define WM8400_SDR_LDO2_UV 0x0002 /* SDR_LDO2_UV */ | ||
910 | #define WM8400_SDR_LDO2_UV_MASK 0x0002 /* SDR_LDO2_UV */ | ||
911 | #define WM8400_SDR_LDO2_UV_SHIFT 1 /* SDR_LDO2_UV */ | ||
912 | #define WM8400_SDR_LDO2_UV_WIDTH 1 /* SDR_LDO2_UV */ | ||
913 | #define WM8400_SDR_LDO1_UV 0x0001 /* SDR_LDO1_UV */ | ||
914 | #define WM8400_SDR_LDO1_UV_MASK 0x0001 /* SDR_LDO1_UV */ | ||
915 | #define WM8400_SDR_LDO1_UV_SHIFT 0 /* SDR_LDO1_UV */ | ||
916 | #define WM8400_SDR_LDO1_UV_WIDTH 1 /* SDR_LDO1_UV */ | ||
917 | |||
918 | /* | ||
919 | * R84 (0x54) - Line Circuits | ||
920 | */ | ||
921 | #define WM8400_BG_LINE_COMP 0x8000 /* BG_LINE_COMP */ | ||
922 | #define WM8400_BG_LINE_COMP_MASK 0x8000 /* BG_LINE_COMP */ | ||
923 | #define WM8400_BG_LINE_COMP_SHIFT 15 /* BG_LINE_COMP */ | ||
924 | #define WM8400_BG_LINE_COMP_WIDTH 1 /* BG_LINE_COMP */ | ||
925 | #define WM8400_LINE_CMP_VTHI_MASK 0x00F0 /* LINE_CMP_VTHI - [7:4] */ | ||
926 | #define WM8400_LINE_CMP_VTHI_SHIFT 4 /* LINE_CMP_VTHI - [7:4] */ | ||
927 | #define WM8400_LINE_CMP_VTHI_WIDTH 4 /* LINE_CMP_VTHI - [7:4] */ | ||
928 | #define WM8400_LINE_CMP_VTHD_MASK 0x000F /* LINE_CMP_VTHD - [3:0] */ | ||
929 | #define WM8400_LINE_CMP_VTHD_SHIFT 0 /* LINE_CMP_VTHD - [3:0] */ | ||
930 | #define WM8400_LINE_CMP_VTHD_WIDTH 4 /* LINE_CMP_VTHD - [3:0] */ | ||
931 | |||
932 | u16 wm8400_reg_read(struct wm8400 *wm8400, u8 reg); | ||
933 | int wm8400_block_read(struct wm8400 *wm8400, u8 reg, int count, u16 *data); | ||
934 | int wm8400_set_bits(struct wm8400 *wm8400, u8 reg, u16 mask, u16 val); | ||
935 | |||
936 | #endif | ||
diff --git a/include/linux/mfd/wm8400.h b/include/linux/mfd/wm8400.h new file mode 100644 index 000000000000..b46b566ac1ac --- /dev/null +++ b/include/linux/mfd/wm8400.h | |||
@@ -0,0 +1,40 @@ | |||
1 | /* | ||
2 | * wm8400 client interface | ||
3 | * | ||
4 | * Copyright 2008 Wolfson Microelectronics plc | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
19 | */ | ||
20 | |||
21 | #ifndef __LINUX_MFD_WM8400_H | ||
22 | #define __LINUX_MFD_WM8400_H | ||
23 | |||
24 | #include <linux/regulator/machine.h> | ||
25 | |||
26 | #define WM8400_LDO1 0 | ||
27 | #define WM8400_LDO2 1 | ||
28 | #define WM8400_LDO3 2 | ||
29 | #define WM8400_LDO4 3 | ||
30 | #define WM8400_DCDC1 4 | ||
31 | #define WM8400_DCDC2 5 | ||
32 | |||
33 | struct wm8400_platform_data { | ||
34 | int (*platform_init)(struct device *dev); | ||
35 | }; | ||
36 | |||
37 | int wm8400_register_regulator(struct device *dev, int reg, | ||
38 | struct regulator_init_data *initdata); | ||
39 | |||
40 | #endif | ||
diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h index 3481a7d5bc0a..d6a3f47e95cb 100644 --- a/include/linux/mod_devicetable.h +++ b/include/linux/mod_devicetable.h | |||
@@ -131,6 +131,16 @@ struct usb_device_id { | |||
131 | #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100 | 131 | #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100 |
132 | #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200 | 132 | #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200 |
133 | 133 | ||
134 | #define HID_ANY_ID (~0) | ||
135 | |||
136 | struct hid_device_id { | ||
137 | __u16 bus; | ||
138 | __u32 vendor; | ||
139 | __u32 product; | ||
140 | kernel_ulong_t driver_data | ||
141 | __attribute__((aligned(sizeof(kernel_ulong_t)))); | ||
142 | }; | ||
143 | |||
134 | /* s390 CCW devices */ | 144 | /* s390 CCW devices */ |
135 | struct ccw_device_id { | 145 | struct ccw_device_id { |
136 | __u16 match_flags; /* which fields to match against */ | 146 | __u16 match_flags; /* which fields to match against */ |
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index d3ea3de70a8a..64875859d654 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h | |||
@@ -11,7 +11,7 @@ | |||
11 | * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> | 11 | * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> |
12 | * Corey Minyard <wf-rch!minyard@relay.EU.net> | 12 | * Corey Minyard <wf-rch!minyard@relay.EU.net> |
13 | * Donald J. Becker, <becker@cesdis.gsfc.nasa.gov> | 13 | * Donald J. Becker, <becker@cesdis.gsfc.nasa.gov> |
14 | * Alan Cox, <Alan.Cox@linux.org> | 14 | * Alan Cox, <alan@lxorguk.ukuu.org.uk> |
15 | * Bjorn Ekwall. <bj0rn@blox.se> | 15 | * Bjorn Ekwall. <bj0rn@blox.se> |
16 | * Pekka Riikonen <priikone@poseidon.pspt.fi> | 16 | * Pekka Riikonen <priikone@poseidon.pspt.fi> |
17 | * | 17 | * |
diff --git a/include/linux/nfsd/nfsd.h b/include/linux/nfsd/nfsd.h index 108f47e5fd95..21269405ffe2 100644 --- a/include/linux/nfsd/nfsd.h +++ b/include/linux/nfsd/nfsd.h | |||
@@ -38,6 +38,7 @@ | |||
38 | #define NFSD_MAY_LOCK 32 | 38 | #define NFSD_MAY_LOCK 32 |
39 | #define NFSD_MAY_OWNER_OVERRIDE 64 | 39 | #define NFSD_MAY_OWNER_OVERRIDE 64 |
40 | #define NFSD_MAY_LOCAL_ACCESS 128 /* IRIX doing local access check on device special file*/ | 40 | #define NFSD_MAY_LOCAL_ACCESS 128 /* IRIX doing local access check on device special file*/ |
41 | #define NFSD_MAY_BYPASS_GSS_ON_ROOT 256 | ||
41 | 42 | ||
42 | #define NFSD_MAY_CREATE (NFSD_MAY_EXEC|NFSD_MAY_WRITE) | 43 | #define NFSD_MAY_CREATE (NFSD_MAY_EXEC|NFSD_MAY_WRITE) |
43 | #define NFSD_MAY_REMOVE (NFSD_MAY_EXEC|NFSD_MAY_WRITE|NFSD_MAY_TRUNC) | 44 | #define NFSD_MAY_REMOVE (NFSD_MAY_EXEC|NFSD_MAY_WRITE|NFSD_MAY_TRUNC) |
@@ -125,7 +126,7 @@ int nfsd_truncate(struct svc_rqst *, struct svc_fh *, | |||
125 | __be32 nfsd_readdir(struct svc_rqst *, struct svc_fh *, | 126 | __be32 nfsd_readdir(struct svc_rqst *, struct svc_fh *, |
126 | loff_t *, struct readdir_cd *, filldir_t); | 127 | loff_t *, struct readdir_cd *, filldir_t); |
127 | __be32 nfsd_statfs(struct svc_rqst *, struct svc_fh *, | 128 | __be32 nfsd_statfs(struct svc_rqst *, struct svc_fh *, |
128 | struct kstatfs *); | 129 | struct kstatfs *, int access); |
129 | 130 | ||
130 | int nfsd_notify_change(struct inode *, struct iattr *); | 131 | int nfsd_notify_change(struct inode *, struct iattr *); |
131 | __be32 nfsd_permission(struct svc_rqst *, struct svc_export *, | 132 | __be32 nfsd_permission(struct svc_rqst *, struct svc_export *, |
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h index 1d712c7172a2..e37d80561985 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h | |||
@@ -18,8 +18,8 @@ | |||
18 | #include <linux/device.h> | 18 | #include <linux/device.h> |
19 | #include <linux/regulator/consumer.h> | 19 | #include <linux/regulator/consumer.h> |
20 | 20 | ||
21 | struct regulator_constraints; | ||
22 | struct regulator_dev; | 21 | struct regulator_dev; |
22 | struct regulator_init_data; | ||
23 | 23 | ||
24 | /** | 24 | /** |
25 | * struct regulator_ops - regulator operations. | 25 | * struct regulator_ops - regulator operations. |
@@ -51,7 +51,7 @@ struct regulator_ops { | |||
51 | int output_uV, int load_uA); | 51 | int output_uV, int load_uA); |
52 | 52 | ||
53 | /* the operations below are for configuration of regulator state when | 53 | /* the operations below are for configuration of regulator state when |
54 | * it's parent PMIC enters a global STANBY/HIBERNATE state */ | 54 | * its parent PMIC enters a global STANDBY/HIBERNATE state */ |
55 | 55 | ||
56 | /* set regulator suspend voltage */ | 56 | /* set regulator suspend voltage */ |
57 | int (*set_suspend_voltage) (struct regulator_dev *, int uV); | 57 | int (*set_suspend_voltage) (struct regulator_dev *, int uV); |
@@ -85,15 +85,17 @@ struct regulator_desc { | |||
85 | struct module *owner; | 85 | struct module *owner; |
86 | }; | 86 | }; |
87 | 87 | ||
88 | |||
89 | struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, | 88 | struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, |
90 | void *reg_data); | 89 | struct device *dev, void *driver_data); |
91 | void regulator_unregister(struct regulator_dev *rdev); | 90 | void regulator_unregister(struct regulator_dev *rdev); |
92 | 91 | ||
93 | int regulator_notifier_call_chain(struct regulator_dev *rdev, | 92 | int regulator_notifier_call_chain(struct regulator_dev *rdev, |
94 | unsigned long event, void *data); | 93 | unsigned long event, void *data); |
95 | 94 | ||
96 | void *rdev_get_drvdata(struct regulator_dev *rdev); | 95 | void *rdev_get_drvdata(struct regulator_dev *rdev); |
96 | struct device *rdev_get_dev(struct regulator_dev *rdev); | ||
97 | int rdev_get_id(struct regulator_dev *rdev); | 97 | int rdev_get_id(struct regulator_dev *rdev); |
98 | 98 | ||
99 | void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data); | ||
100 | |||
99 | #endif | 101 | #endif |
diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h index 11e737dbfcf2..c6d69331a81e 100644 --- a/include/linux/regulator/machine.h +++ b/include/linux/regulator/machine.h | |||
@@ -89,15 +89,33 @@ struct regulation_constraints { | |||
89 | unsigned apply_uV:1; /* apply uV constraint iff min == max */ | 89 | unsigned apply_uV:1; /* apply uV constraint iff min == max */ |
90 | }; | 90 | }; |
91 | 91 | ||
92 | int regulator_set_supply(const char *regulator, const char *regulator_supply); | 92 | /** |
93 | * struct regulator_consumer_supply - supply -> device mapping | ||
94 | * | ||
95 | * This maps a supply name to a device. | ||
96 | */ | ||
97 | struct regulator_consumer_supply { | ||
98 | struct device *dev; /* consumer */ | ||
99 | const char *supply; /* consumer supply - e.g. "vcc" */ | ||
100 | }; | ||
93 | 101 | ||
94 | const char *regulator_get_supply(const char *regulator); | 102 | /** |
103 | * struct regulator_init_data - regulator platform initialisation data. | ||
104 | * | ||
105 | * Initialisation constraints, our supply and consumers supplies. | ||
106 | */ | ||
107 | struct regulator_init_data { | ||
108 | struct device *supply_regulator_dev; /* or NULL for LINE */ | ||
95 | 109 | ||
96 | int regulator_set_machine_constraints(const char *regulator, | 110 | struct regulation_constraints constraints; |
97 | struct regulation_constraints *constraints); | ||
98 | 111 | ||
99 | int regulator_set_device_supply(const char *regulator, struct device *dev, | 112 | int num_consumer_supplies; |
100 | const char *supply); | 113 | struct regulator_consumer_supply *consumer_supplies; |
114 | |||
115 | /* optional regulator machine specific init */ | ||
116 | int (*regulator_init)(void *driver_data); | ||
117 | void *driver_data; /* core does not touch this */ | ||
118 | }; | ||
101 | 119 | ||
102 | int regulator_suspend_prepare(suspend_state_t state); | 120 | int regulator_suspend_prepare(suspend_state_t state); |
103 | 121 | ||
diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h index e5bfe01ee305..6f0ee1b84a4f 100644 --- a/include/linux/sunrpc/clnt.h +++ b/include/linux/sunrpc/clnt.h | |||
@@ -104,6 +104,7 @@ struct rpc_create_args { | |||
104 | const struct rpc_timeout *timeout; | 104 | const struct rpc_timeout *timeout; |
105 | char *servername; | 105 | char *servername; |
106 | struct rpc_program *program; | 106 | struct rpc_program *program; |
107 | u32 prognumber; /* overrides program->number */ | ||
107 | u32 version; | 108 | u32 version; |
108 | rpc_authflavor_t authflavor; | 109 | rpc_authflavor_t authflavor; |
109 | unsigned long flags; | 110 | unsigned long flags; |
@@ -124,10 +125,10 @@ struct rpc_clnt *rpc_clone_client(struct rpc_clnt *); | |||
124 | void rpc_shutdown_client(struct rpc_clnt *); | 125 | void rpc_shutdown_client(struct rpc_clnt *); |
125 | void rpc_release_client(struct rpc_clnt *); | 126 | void rpc_release_client(struct rpc_clnt *); |
126 | 127 | ||
127 | int rpcb_register(u32, u32, int, unsigned short, int *); | 128 | int rpcb_register(u32, u32, int, unsigned short); |
128 | int rpcb_v4_register(const u32 program, const u32 version, | 129 | int rpcb_v4_register(const u32 program, const u32 version, |
129 | const struct sockaddr *address, | 130 | const struct sockaddr *address, |
130 | const char *netid, int *result); | 131 | const char *netid); |
131 | int rpcb_getport_sync(struct sockaddr_in *, u32, u32, int); | 132 | int rpcb_getport_sync(struct sockaddr_in *, u32, u32, int); |
132 | void rpcb_getport_async(struct rpc_task *); | 133 | void rpcb_getport_async(struct rpc_task *); |
133 | 134 | ||
diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h index dc69068d94c7..3afe7fb403b2 100644 --- a/include/linux/sunrpc/svc.h +++ b/include/linux/sunrpc/svc.h | |||
@@ -66,6 +66,7 @@ struct svc_serv { | |||
66 | struct list_head sv_tempsocks; /* all temporary sockets */ | 66 | struct list_head sv_tempsocks; /* all temporary sockets */ |
67 | int sv_tmpcnt; /* count of temporary sockets */ | 67 | int sv_tmpcnt; /* count of temporary sockets */ |
68 | struct timer_list sv_temptimer; /* timer for aging temporary sockets */ | 68 | struct timer_list sv_temptimer; /* timer for aging temporary sockets */ |
69 | sa_family_t sv_family; /* listener's address family */ | ||
69 | 70 | ||
70 | char * sv_name; /* service name */ | 71 | char * sv_name; /* service name */ |
71 | 72 | ||
@@ -265,17 +266,17 @@ struct svc_rqst { | |||
265 | /* | 266 | /* |
266 | * Rigorous type checking on sockaddr type conversions | 267 | * Rigorous type checking on sockaddr type conversions |
267 | */ | 268 | */ |
268 | static inline struct sockaddr_in *svc_addr_in(struct svc_rqst *rqst) | 269 | static inline struct sockaddr_in *svc_addr_in(const struct svc_rqst *rqst) |
269 | { | 270 | { |
270 | return (struct sockaddr_in *) &rqst->rq_addr; | 271 | return (struct sockaddr_in *) &rqst->rq_addr; |
271 | } | 272 | } |
272 | 273 | ||
273 | static inline struct sockaddr_in6 *svc_addr_in6(struct svc_rqst *rqst) | 274 | static inline struct sockaddr_in6 *svc_addr_in6(const struct svc_rqst *rqst) |
274 | { | 275 | { |
275 | return (struct sockaddr_in6 *) &rqst->rq_addr; | 276 | return (struct sockaddr_in6 *) &rqst->rq_addr; |
276 | } | 277 | } |
277 | 278 | ||
278 | static inline struct sockaddr *svc_addr(struct svc_rqst *rqst) | 279 | static inline struct sockaddr *svc_addr(const struct svc_rqst *rqst) |
279 | { | 280 | { |
280 | return (struct sockaddr *) &rqst->rq_addr; | 281 | return (struct sockaddr *) &rqst->rq_addr; |
281 | } | 282 | } |
@@ -381,18 +382,20 @@ struct svc_procedure { | |||
381 | /* | 382 | /* |
382 | * Function prototypes. | 383 | * Function prototypes. |
383 | */ | 384 | */ |
384 | struct svc_serv * svc_create(struct svc_program *, unsigned int, | 385 | struct svc_serv *svc_create(struct svc_program *, unsigned int, sa_family_t, |
385 | void (*shutdown)(struct svc_serv*)); | 386 | void (*shutdown)(struct svc_serv *)); |
386 | struct svc_rqst *svc_prepare_thread(struct svc_serv *serv, | 387 | struct svc_rqst *svc_prepare_thread(struct svc_serv *serv, |
387 | struct svc_pool *pool); | 388 | struct svc_pool *pool); |
388 | void svc_exit_thread(struct svc_rqst *); | 389 | void svc_exit_thread(struct svc_rqst *); |
389 | struct svc_serv * svc_create_pooled(struct svc_program *, unsigned int, | 390 | struct svc_serv * svc_create_pooled(struct svc_program *, unsigned int, |
390 | void (*shutdown)(struct svc_serv*), svc_thread_fn, | 391 | sa_family_t, void (*shutdown)(struct svc_serv *), |
391 | struct module *); | 392 | svc_thread_fn, struct module *); |
392 | int svc_set_num_threads(struct svc_serv *, struct svc_pool *, int); | 393 | int svc_set_num_threads(struct svc_serv *, struct svc_pool *, int); |
393 | void svc_destroy(struct svc_serv *); | 394 | void svc_destroy(struct svc_serv *); |
394 | int svc_process(struct svc_rqst *); | 395 | int svc_process(struct svc_rqst *); |
395 | int svc_register(struct svc_serv *, int, unsigned short); | 396 | int svc_register(const struct svc_serv *, const unsigned short, |
397 | const unsigned short); | ||
398 | |||
396 | void svc_wake_up(struct svc_serv *); | 399 | void svc_wake_up(struct svc_serv *); |
397 | void svc_reserve(struct svc_rqst *rqstp, int space); | 400 | void svc_reserve(struct svc_rqst *rqstp, int space); |
398 | struct svc_pool * svc_pool_for_cpu(struct svc_serv *serv, int cpu); | 401 | struct svc_pool * svc_pool_for_cpu(struct svc_serv *serv, int cpu); |
diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h index dc05b54bd3a3..c14fe86dac59 100644 --- a/include/linux/sunrpc/svc_rdma.h +++ b/include/linux/sunrpc/svc_rdma.h | |||
@@ -72,6 +72,7 @@ extern atomic_t rdma_stat_sq_prod; | |||
72 | */ | 72 | */ |
73 | struct svc_rdma_op_ctxt { | 73 | struct svc_rdma_op_ctxt { |
74 | struct svc_rdma_op_ctxt *read_hdr; | 74 | struct svc_rdma_op_ctxt *read_hdr; |
75 | struct svc_rdma_fastreg_mr *frmr; | ||
75 | int hdr_count; | 76 | int hdr_count; |
76 | struct xdr_buf arg; | 77 | struct xdr_buf arg; |
77 | struct list_head dto_q; | 78 | struct list_head dto_q; |
@@ -103,16 +104,30 @@ struct svc_rdma_chunk_sge { | |||
103 | int start; /* sge no for this chunk */ | 104 | int start; /* sge no for this chunk */ |
104 | int count; /* sge count for this chunk */ | 105 | int count; /* sge count for this chunk */ |
105 | }; | 106 | }; |
107 | struct svc_rdma_fastreg_mr { | ||
108 | struct ib_mr *mr; | ||
109 | void *kva; | ||
110 | struct ib_fast_reg_page_list *page_list; | ||
111 | int page_list_len; | ||
112 | unsigned long access_flags; | ||
113 | unsigned long map_len; | ||
114 | enum dma_data_direction direction; | ||
115 | struct list_head frmr_list; | ||
116 | }; | ||
106 | struct svc_rdma_req_map { | 117 | struct svc_rdma_req_map { |
118 | struct svc_rdma_fastreg_mr *frmr; | ||
107 | unsigned long count; | 119 | unsigned long count; |
108 | union { | 120 | union { |
109 | struct kvec sge[RPCSVC_MAXPAGES]; | 121 | struct kvec sge[RPCSVC_MAXPAGES]; |
110 | struct svc_rdma_chunk_sge ch[RPCSVC_MAXPAGES]; | 122 | struct svc_rdma_chunk_sge ch[RPCSVC_MAXPAGES]; |
111 | }; | 123 | }; |
112 | }; | 124 | }; |
113 | 125 | #define RDMACTXT_F_FAST_UNREG 1 | |
114 | #define RDMACTXT_F_LAST_CTXT 2 | 126 | #define RDMACTXT_F_LAST_CTXT 2 |
115 | 127 | ||
128 | #define SVCRDMA_DEVCAP_FAST_REG 1 /* fast mr registration */ | ||
129 | #define SVCRDMA_DEVCAP_READ_W_INV 2 /* read w/ invalidate */ | ||
130 | |||
116 | struct svcxprt_rdma { | 131 | struct svcxprt_rdma { |
117 | struct svc_xprt sc_xprt; /* SVC transport structure */ | 132 | struct svc_xprt sc_xprt; /* SVC transport structure */ |
118 | struct rdma_cm_id *sc_cm_id; /* RDMA connection id */ | 133 | struct rdma_cm_id *sc_cm_id; /* RDMA connection id */ |
@@ -136,6 +151,11 @@ struct svcxprt_rdma { | |||
136 | struct ib_cq *sc_rq_cq; | 151 | struct ib_cq *sc_rq_cq; |
137 | struct ib_cq *sc_sq_cq; | 152 | struct ib_cq *sc_sq_cq; |
138 | struct ib_mr *sc_phys_mr; /* MR for server memory */ | 153 | struct ib_mr *sc_phys_mr; /* MR for server memory */ |
154 | u32 sc_dev_caps; /* distilled device caps */ | ||
155 | u32 sc_dma_lkey; /* local dma key */ | ||
156 | unsigned int sc_frmr_pg_list_len; | ||
157 | struct list_head sc_frmr_q; | ||
158 | spinlock_t sc_frmr_q_lock; | ||
139 | 159 | ||
140 | spinlock_t sc_lock; /* transport lock */ | 160 | spinlock_t sc_lock; /* transport lock */ |
141 | 161 | ||
@@ -192,8 +212,13 @@ extern int svc_rdma_post_recv(struct svcxprt_rdma *); | |||
192 | extern int svc_rdma_create_listen(struct svc_serv *, int, struct sockaddr *); | 212 | extern int svc_rdma_create_listen(struct svc_serv *, int, struct sockaddr *); |
193 | extern struct svc_rdma_op_ctxt *svc_rdma_get_context(struct svcxprt_rdma *); | 213 | extern struct svc_rdma_op_ctxt *svc_rdma_get_context(struct svcxprt_rdma *); |
194 | extern void svc_rdma_put_context(struct svc_rdma_op_ctxt *, int); | 214 | extern void svc_rdma_put_context(struct svc_rdma_op_ctxt *, int); |
215 | extern void svc_rdma_unmap_dma(struct svc_rdma_op_ctxt *ctxt); | ||
195 | extern struct svc_rdma_req_map *svc_rdma_get_req_map(void); | 216 | extern struct svc_rdma_req_map *svc_rdma_get_req_map(void); |
196 | extern void svc_rdma_put_req_map(struct svc_rdma_req_map *); | 217 | extern void svc_rdma_put_req_map(struct svc_rdma_req_map *); |
218 | extern int svc_rdma_fastreg(struct svcxprt_rdma *, struct svc_rdma_fastreg_mr *); | ||
219 | extern struct svc_rdma_fastreg_mr *svc_rdma_get_frmr(struct svcxprt_rdma *); | ||
220 | extern void svc_rdma_put_frmr(struct svcxprt_rdma *, | ||
221 | struct svc_rdma_fastreg_mr *); | ||
197 | extern void svc_sq_reap(struct svcxprt_rdma *); | 222 | extern void svc_sq_reap(struct svcxprt_rdma *); |
198 | extern void svc_rq_reap(struct svcxprt_rdma *); | 223 | extern void svc_rq_reap(struct svcxprt_rdma *); |
199 | extern struct svc_xprt_class svc_rdma_class; | 224 | extern struct svc_xprt_class svc_rdma_class; |
diff --git a/include/linux/sunrpc/svcsock.h b/include/linux/sunrpc/svcsock.h index 8cff696dedf5..483e10380aae 100644 --- a/include/linux/sunrpc/svcsock.h +++ b/include/linux/sunrpc/svcsock.h | |||
@@ -39,10 +39,7 @@ int svc_send(struct svc_rqst *); | |||
39 | void svc_drop(struct svc_rqst *); | 39 | void svc_drop(struct svc_rqst *); |
40 | void svc_sock_update_bufs(struct svc_serv *serv); | 40 | void svc_sock_update_bufs(struct svc_serv *serv); |
41 | int svc_sock_names(char *buf, struct svc_serv *serv, char *toclose); | 41 | int svc_sock_names(char *buf, struct svc_serv *serv, char *toclose); |
42 | int svc_addsock(struct svc_serv *serv, | 42 | int svc_addsock(struct svc_serv *serv, int fd, char *name_return); |
43 | int fd, | ||
44 | char *name_return, | ||
45 | int *proto); | ||
46 | void svc_init_xprt_sock(void); | 43 | void svc_init_xprt_sock(void); |
47 | void svc_cleanup_xprt_sock(void); | 44 | void svc_cleanup_xprt_sock(void); |
48 | 45 | ||
diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c index 693d24694a6c..48b3fadd83ed 100644 --- a/init/do_mounts_md.c +++ b/init/do_mounts_md.c | |||
@@ -12,7 +12,12 @@ | |||
12 | * The code for that is here. | 12 | * The code for that is here. |
13 | */ | 13 | */ |
14 | 14 | ||
15 | static int __initdata raid_noautodetect, raid_autopart; | 15 | #ifdef CONFIG_MD_AUTODETECT |
16 | static int __initdata raid_noautodetect; | ||
17 | #else | ||
18 | static int __initdata raid_noautodetect=1; | ||
19 | #endif | ||
20 | static int __initdata raid_autopart; | ||
16 | 21 | ||
17 | static struct { | 22 | static struct { |
18 | int minor; | 23 | int minor; |
@@ -252,6 +257,8 @@ static int __init raid_setup(char *str) | |||
252 | 257 | ||
253 | if (!strncmp(str, "noautodetect", wlen)) | 258 | if (!strncmp(str, "noautodetect", wlen)) |
254 | raid_noautodetect = 1; | 259 | raid_noautodetect = 1; |
260 | if (!strncmp(str, "autodetect", wlen)) | ||
261 | raid_noautodetect = 0; | ||
255 | if (strncmp(str, "partitionable", wlen)==0) | 262 | if (strncmp(str, "partitionable", wlen)==0) |
256 | raid_autopart = 1; | 263 | raid_autopart = 1; |
257 | if (strncmp(str, "part", wlen)==0) | 264 | if (strncmp(str, "part", wlen)==0) |
@@ -264,17 +271,32 @@ static int __init raid_setup(char *str) | |||
264 | __setup("raid=", raid_setup); | 271 | __setup("raid=", raid_setup); |
265 | __setup("md=", md_setup); | 272 | __setup("md=", md_setup); |
266 | 273 | ||
274 | static void autodetect_raid(void) | ||
275 | { | ||
276 | int fd; | ||
277 | |||
278 | /* | ||
279 | * Since we don't want to detect and use half a raid array, we need to | ||
280 | * wait for the known devices to complete their probing | ||
281 | */ | ||
282 | printk(KERN_INFO "md: Waiting for all devices to be available before autodetect\n"); | ||
283 | printk(KERN_INFO "md: If you don't use raid, use raid=noautodetect\n"); | ||
284 | while (driver_probe_done() < 0) | ||
285 | msleep(100); | ||
286 | fd = sys_open("/dev/md0", 0, 0); | ||
287 | if (fd >= 0) { | ||
288 | sys_ioctl(fd, RAID_AUTORUN, raid_autopart); | ||
289 | sys_close(fd); | ||
290 | } | ||
291 | } | ||
292 | |||
267 | void __init md_run_setup(void) | 293 | void __init md_run_setup(void) |
268 | { | 294 | { |
269 | create_dev("/dev/md0", MKDEV(MD_MAJOR, 0)); | 295 | create_dev("/dev/md0", MKDEV(MD_MAJOR, 0)); |
296 | |||
270 | if (raid_noautodetect) | 297 | if (raid_noautodetect) |
271 | printk(KERN_INFO "md: Skipping autodetection of RAID arrays. (raid=noautodetect)\n"); | 298 | printk(KERN_INFO "md: Skipping autodetection of RAID arrays. (raid=autodetect will force)\n"); |
272 | else { | 299 | else |
273 | int fd = sys_open("/dev/md0", 0, 0); | 300 | autodetect_raid(); |
274 | if (fd >= 0) { | ||
275 | sys_ioctl(fd, RAID_AUTORUN, raid_autopart); | ||
276 | sys_close(fd); | ||
277 | } | ||
278 | } | ||
279 | md_setup_drive(); | 301 | md_setup_drive(); |
280 | } | 302 | } |
diff --git a/init/main.c b/init/main.c index 3820323c4c84..27f6bf6108e9 100644 --- a/init/main.c +++ b/init/main.c | |||
@@ -708,7 +708,7 @@ int do_one_initcall(initcall_t fn) | |||
708 | int result; | 708 | int result; |
709 | 709 | ||
710 | if (initcall_debug) { | 710 | if (initcall_debug) { |
711 | printk("calling %pF\n", fn); | 711 | printk("calling %pF @ %i\n", fn, task_pid_nr(current)); |
712 | t0 = ktime_get(); | 712 | t0 = ktime_get(); |
713 | } | 713 | } |
714 | 714 | ||
diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c index 08d6e1bb99ac..503d8d4eb80a 100644 --- a/kernel/sys_ni.c +++ b/kernel/sys_ni.c | |||
@@ -125,6 +125,7 @@ cond_syscall(sys_vm86old); | |||
125 | cond_syscall(sys_vm86); | 125 | cond_syscall(sys_vm86); |
126 | cond_syscall(compat_sys_ipc); | 126 | cond_syscall(compat_sys_ipc); |
127 | cond_syscall(compat_sys_sysctl); | 127 | cond_syscall(compat_sys_sysctl); |
128 | cond_syscall(sys_flock); | ||
128 | 129 | ||
129 | /* arch-specific weak syscall entries */ | 130 | /* arch-specific weak syscall entries */ |
130 | cond_syscall(sys_pciconfig_read); | 131 | cond_syscall(sys_pciconfig_read); |
diff --git a/kernel/sysctl.c b/kernel/sysctl.c index c468c3c6dfc5..cfc5295f1e82 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c | |||
@@ -96,7 +96,7 @@ static int sixty = 60; | |||
96 | static int neg_one = -1; | 96 | static int neg_one = -1; |
97 | #endif | 97 | #endif |
98 | 98 | ||
99 | #ifdef CONFIG_MMU | 99 | #if defined(CONFIG_MMU) && defined(CONFIG_FILE_LOCKING) |
100 | static int two = 2; | 100 | static int two = 2; |
101 | #endif | 101 | #endif |
102 | 102 | ||
@@ -1248,6 +1248,7 @@ static struct ctl_table fs_table[] = { | |||
1248 | .extra1 = &minolduid, | 1248 | .extra1 = &minolduid, |
1249 | .extra2 = &maxolduid, | 1249 | .extra2 = &maxolduid, |
1250 | }, | 1250 | }, |
1251 | #ifdef CONFIG_FILE_LOCKING | ||
1251 | { | 1252 | { |
1252 | .ctl_name = FS_LEASES, | 1253 | .ctl_name = FS_LEASES, |
1253 | .procname = "leases-enable", | 1254 | .procname = "leases-enable", |
@@ -1256,6 +1257,7 @@ static struct ctl_table fs_table[] = { | |||
1256 | .mode = 0644, | 1257 | .mode = 0644, |
1257 | .proc_handler = &proc_dointvec, | 1258 | .proc_handler = &proc_dointvec, |
1258 | }, | 1259 | }, |
1260 | #endif | ||
1259 | #ifdef CONFIG_DNOTIFY | 1261 | #ifdef CONFIG_DNOTIFY |
1260 | { | 1262 | { |
1261 | .ctl_name = FS_DIR_NOTIFY, | 1263 | .ctl_name = FS_DIR_NOTIFY, |
@@ -1267,6 +1269,7 @@ static struct ctl_table fs_table[] = { | |||
1267 | }, | 1269 | }, |
1268 | #endif | 1270 | #endif |
1269 | #ifdef CONFIG_MMU | 1271 | #ifdef CONFIG_MMU |
1272 | #ifdef CONFIG_FILE_LOCKING | ||
1270 | { | 1273 | { |
1271 | .ctl_name = FS_LEASE_TIME, | 1274 | .ctl_name = FS_LEASE_TIME, |
1272 | .procname = "lease-break-time", | 1275 | .procname = "lease-break-time", |
@@ -1278,6 +1281,7 @@ static struct ctl_table fs_table[] = { | |||
1278 | .extra1 = &zero, | 1281 | .extra1 = &zero, |
1279 | .extra2 = &two, | 1282 | .extra2 = &two, |
1280 | }, | 1283 | }, |
1284 | #endif | ||
1281 | { | 1285 | { |
1282 | .procname = "aio-nr", | 1286 | .procname = "aio-nr", |
1283 | .data = &aio_nr, | 1287 | .data = &aio_nr, |
diff --git a/net/802/psnap.c b/net/802/psnap.c index b3cfe5a14fca..70980baeb682 100644 --- a/net/802/psnap.c +++ b/net/802/psnap.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * SNAP data link layer. Derived from 802.2 | 2 | * SNAP data link layer. Derived from 802.2 |
3 | * | 3 | * |
4 | * Alan Cox <Alan.Cox@linux.org>, | 4 | * Alan Cox <alan@lxorguk.ukuu.org.uk>, |
5 | * from the 802.2 layer by Greg Page. | 5 | * from the 802.2 layer by Greg Page. |
6 | * Merged in additions from Greg Page's psnap.c. | 6 | * Merged in additions from Greg Page's psnap.c. |
7 | * | 7 | * |
diff --git a/net/appletalk/ddp.c b/net/appletalk/ddp.c index 0c850427a85b..d3134e7e6ee8 100644 --- a/net/appletalk/ddp.c +++ b/net/appletalk/ddp.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * DDP: An implementation of the AppleTalk DDP protocol for | 2 | * DDP: An implementation of the AppleTalk DDP protocol for |
3 | * Ethernet 'ELAP'. | 3 | * Ethernet 'ELAP'. |
4 | * | 4 | * |
5 | * Alan Cox <Alan.Cox@linux.org> | 5 | * Alan Cox <alan@lxorguk.ukuu.org.uk> |
6 | * | 6 | * |
7 | * With more than a little assistance from | 7 | * With more than a little assistance from |
8 | * | 8 | * |
@@ -1934,6 +1934,6 @@ static void __exit atalk_exit(void) | |||
1934 | module_exit(atalk_exit); | 1934 | module_exit(atalk_exit); |
1935 | 1935 | ||
1936 | MODULE_LICENSE("GPL"); | 1936 | MODULE_LICENSE("GPL"); |
1937 | MODULE_AUTHOR("Alan Cox <Alan.Cox@linux.org>"); | 1937 | MODULE_AUTHOR("Alan Cox <alan@lxorguk.ukuu.org.uk>"); |
1938 | MODULE_DESCRIPTION("AppleTalk 0.20\n"); | 1938 | MODULE_DESCRIPTION("AppleTalk 0.20\n"); |
1939 | MODULE_ALIAS_NETPROTO(PF_APPLETALK); | 1939 | MODULE_ALIAS_NETPROTO(PF_APPLETALK); |
diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c index 96434d774c84..acdeab3d9807 100644 --- a/net/bluetooth/hidp/core.c +++ b/net/bluetooth/hidp/core.c | |||
@@ -578,7 +578,7 @@ static int hidp_session(void *arg) | |||
578 | if (session->hid) { | 578 | if (session->hid) { |
579 | if (session->hid->claimed & HID_CLAIMED_INPUT) | 579 | if (session->hid->claimed & HID_CLAIMED_INPUT) |
580 | hidinput_disconnect(session->hid); | 580 | hidinput_disconnect(session->hid); |
581 | hid_free_device(session->hid); | 581 | hid_destroy_device(session->hid); |
582 | } | 582 | } |
583 | 583 | ||
584 | /* Wakeup user-space polling for socket errors */ | 584 | /* Wakeup user-space polling for socket errors */ |
@@ -623,9 +623,15 @@ static struct device *hidp_get_device(struct hidp_session *session) | |||
623 | static int hidp_setup_input(struct hidp_session *session, | 623 | static int hidp_setup_input(struct hidp_session *session, |
624 | struct hidp_connadd_req *req) | 624 | struct hidp_connadd_req *req) |
625 | { | 625 | { |
626 | struct input_dev *input = session->input; | 626 | struct input_dev *input; |
627 | int i; | 627 | int i; |
628 | 628 | ||
629 | input = input_allocate_device(); | ||
630 | if (!input) | ||
631 | return -ENOMEM; | ||
632 | |||
633 | session->input = input; | ||
634 | |||
629 | input_set_drvdata(input, session); | 635 | input_set_drvdata(input, session); |
630 | 636 | ||
631 | input->name = "Bluetooth HID Boot Protocol Device"; | 637 | input->name = "Bluetooth HID Boot Protocol Device"; |
@@ -677,67 +683,114 @@ static void hidp_close(struct hid_device *hid) | |||
677 | { | 683 | { |
678 | } | 684 | } |
679 | 685 | ||
680 | static const struct { | 686 | static int hidp_parse(struct hid_device *hid) |
681 | __u16 idVendor; | 687 | { |
682 | __u16 idProduct; | 688 | struct hidp_session *session = hid->driver_data; |
683 | unsigned quirks; | 689 | struct hidp_connadd_req *req = session->req; |
684 | } hidp_blacklist[] = { | 690 | unsigned char *buf; |
685 | /* Apple wireless Mighty Mouse */ | 691 | int ret; |
686 | { 0x05ac, 0x030c, HID_QUIRK_MIGHTYMOUSE | HID_QUIRK_INVERT_HWHEEL }, | ||
687 | 692 | ||
688 | { } /* Terminating entry */ | 693 | buf = kmalloc(req->rd_size, GFP_KERNEL); |
689 | }; | 694 | if (!buf) |
695 | return -ENOMEM; | ||
696 | |||
697 | if (copy_from_user(buf, req->rd_data, req->rd_size)) { | ||
698 | kfree(buf); | ||
699 | return -EFAULT; | ||
700 | } | ||
701 | |||
702 | ret = hid_parse_report(session->hid, buf, req->rd_size); | ||
703 | |||
704 | kfree(buf); | ||
705 | |||
706 | if (ret) | ||
707 | return ret; | ||
708 | |||
709 | session->req = NULL; | ||
710 | |||
711 | return 0; | ||
712 | } | ||
713 | |||
714 | static int hidp_start(struct hid_device *hid) | ||
715 | { | ||
716 | struct hidp_session *session = hid->driver_data; | ||
717 | struct hid_report *report; | ||
690 | 718 | ||
691 | static void hidp_setup_quirks(struct hid_device *hid) | 719 | list_for_each_entry(report, &hid->report_enum[HID_INPUT_REPORT]. |
720 | report_list, list) | ||
721 | hidp_send_report(session, report); | ||
722 | |||
723 | list_for_each_entry(report, &hid->report_enum[HID_FEATURE_REPORT]. | ||
724 | report_list, list) | ||
725 | hidp_send_report(session, report); | ||
726 | |||
727 | return 0; | ||
728 | } | ||
729 | |||
730 | static void hidp_stop(struct hid_device *hid) | ||
692 | { | 731 | { |
693 | unsigned int n; | 732 | struct hidp_session *session = hid->driver_data; |
733 | |||
734 | skb_queue_purge(&session->ctrl_transmit); | ||
735 | skb_queue_purge(&session->intr_transmit); | ||
694 | 736 | ||
695 | for (n = 0; hidp_blacklist[n].idVendor; n++) | 737 | if (hid->claimed & HID_CLAIMED_INPUT) |
696 | if (hidp_blacklist[n].idVendor == le16_to_cpu(hid->vendor) && | 738 | hidinput_disconnect(hid); |
697 | hidp_blacklist[n].idProduct == le16_to_cpu(hid->product)) | 739 | hid->claimed = 0; |
698 | hid->quirks = hidp_blacklist[n].quirks; | ||
699 | } | 740 | } |
700 | 741 | ||
701 | static void hidp_setup_hid(struct hidp_session *session, | 742 | static struct hid_ll_driver hidp_hid_driver = { |
743 | .parse = hidp_parse, | ||
744 | .start = hidp_start, | ||
745 | .stop = hidp_stop, | ||
746 | .open = hidp_open, | ||
747 | .close = hidp_close, | ||
748 | .hidinput_input_event = hidp_hidinput_event, | ||
749 | }; | ||
750 | |||
751 | static int hidp_setup_hid(struct hidp_session *session, | ||
702 | struct hidp_connadd_req *req) | 752 | struct hidp_connadd_req *req) |
703 | { | 753 | { |
704 | struct hid_device *hid = session->hid; | 754 | struct hid_device *hid; |
705 | struct hid_report *report; | ||
706 | bdaddr_t src, dst; | 755 | bdaddr_t src, dst; |
756 | int ret; | ||
707 | 757 | ||
708 | baswap(&src, &bt_sk(session->ctrl_sock->sk)->src); | 758 | hid = hid_allocate_device(); |
709 | baswap(&dst, &bt_sk(session->ctrl_sock->sk)->dst); | 759 | if (IS_ERR(hid)) { |
760 | ret = PTR_ERR(session->hid); | ||
761 | goto err; | ||
762 | } | ||
710 | 763 | ||
764 | session->hid = hid; | ||
765 | session->req = req; | ||
711 | hid->driver_data = session; | 766 | hid->driver_data = session; |
712 | 767 | ||
713 | hid->country = req->country; | 768 | baswap(&src, &bt_sk(session->ctrl_sock->sk)->src); |
769 | baswap(&dst, &bt_sk(session->ctrl_sock->sk)->dst); | ||
714 | 770 | ||
715 | hid->bus = BUS_BLUETOOTH; | 771 | hid->bus = BUS_BLUETOOTH; |
716 | hid->vendor = req->vendor; | 772 | hid->vendor = req->vendor; |
717 | hid->product = req->product; | 773 | hid->product = req->product; |
718 | hid->version = req->version; | 774 | hid->version = req->version; |
775 | hid->country = req->country; | ||
719 | 776 | ||
720 | strncpy(hid->name, req->name, 128); | 777 | strncpy(hid->name, req->name, 128); |
721 | strncpy(hid->phys, batostr(&src), 64); | 778 | strncpy(hid->phys, batostr(&src), 64); |
722 | strncpy(hid->uniq, batostr(&dst), 64); | 779 | strncpy(hid->uniq, batostr(&dst), 64); |
723 | 780 | ||
724 | hid->dev = hidp_get_device(session); | 781 | hid->dev.parent = hidp_get_device(session); |
725 | 782 | hid->ll_driver = &hidp_hid_driver; | |
726 | hid->hid_open = hidp_open; | ||
727 | hid->hid_close = hidp_close; | ||
728 | |||
729 | hid->hidinput_input_event = hidp_hidinput_event; | ||
730 | 783 | ||
731 | hidp_setup_quirks(hid); | 784 | ret = hid_add_device(hid); |
785 | if (ret) | ||
786 | goto err_hid; | ||
732 | 787 | ||
733 | list_for_each_entry(report, &hid->report_enum[HID_INPUT_REPORT].report_list, list) | 788 | return 0; |
734 | hidp_send_report(session, report); | 789 | err_hid: |
735 | 790 | hid_destroy_device(hid); | |
736 | list_for_each_entry(report, &hid->report_enum[HID_FEATURE_REPORT].report_list, list) | 791 | session->hid = NULL; |
737 | hidp_send_report(session, report); | 792 | err: |
738 | 793 | return ret; | |
739 | if (hidinput_connect(hid) == 0) | ||
740 | hid->claimed |= HID_CLAIMED_INPUT; | ||
741 | } | 794 | } |
742 | 795 | ||
743 | int hidp_add_connection(struct hidp_connadd_req *req, struct socket *ctrl_sock, struct socket *intr_sock) | 796 | int hidp_add_connection(struct hidp_connadd_req *req, struct socket *ctrl_sock, struct socket *intr_sock) |
@@ -757,38 +810,6 @@ int hidp_add_connection(struct hidp_connadd_req *req, struct socket *ctrl_sock, | |||
757 | 810 | ||
758 | BT_DBG("rd_data %p rd_size %d", req->rd_data, req->rd_size); | 811 | BT_DBG("rd_data %p rd_size %d", req->rd_data, req->rd_size); |
759 | 812 | ||
760 | if (req->rd_size > 0) { | ||
761 | unsigned char *buf = kmalloc(req->rd_size, GFP_KERNEL); | ||
762 | |||
763 | if (!buf) { | ||
764 | kfree(session); | ||
765 | return -ENOMEM; | ||
766 | } | ||
767 | |||
768 | if (copy_from_user(buf, req->rd_data, req->rd_size)) { | ||
769 | kfree(buf); | ||
770 | kfree(session); | ||
771 | return -EFAULT; | ||
772 | } | ||
773 | |||
774 | session->hid = hid_parse_report(buf, req->rd_size); | ||
775 | |||
776 | kfree(buf); | ||
777 | |||
778 | if (!session->hid) { | ||
779 | kfree(session); | ||
780 | return -EINVAL; | ||
781 | } | ||
782 | } | ||
783 | |||
784 | if (!session->hid) { | ||
785 | session->input = input_allocate_device(); | ||
786 | if (!session->input) { | ||
787 | kfree(session); | ||
788 | return -ENOMEM; | ||
789 | } | ||
790 | } | ||
791 | |||
792 | down_write(&hidp_session_sem); | 813 | down_write(&hidp_session_sem); |
793 | 814 | ||
794 | s = __hidp_get_session(&bt_sk(ctrl_sock->sk)->dst); | 815 | s = __hidp_get_session(&bt_sk(ctrl_sock->sk)->dst); |
@@ -816,15 +837,18 @@ int hidp_add_connection(struct hidp_connadd_req *req, struct socket *ctrl_sock, | |||
816 | session->flags = req->flags & (1 << HIDP_BLUETOOTH_VENDOR_ID); | 837 | session->flags = req->flags & (1 << HIDP_BLUETOOTH_VENDOR_ID); |
817 | session->idle_to = req->idle_to; | 838 | session->idle_to = req->idle_to; |
818 | 839 | ||
819 | if (session->input) { | 840 | if (req->rd_size > 0) { |
841 | err = hidp_setup_hid(session, req); | ||
842 | if (err && err != -ENODEV) | ||
843 | goto err_skb; | ||
844 | } | ||
845 | |||
846 | if (!session->hid) { | ||
820 | err = hidp_setup_input(session, req); | 847 | err = hidp_setup_input(session, req); |
821 | if (err < 0) | 848 | if (err < 0) |
822 | goto failed; | 849 | goto err_skb; |
823 | } | 850 | } |
824 | 851 | ||
825 | if (session->hid) | ||
826 | hidp_setup_hid(session, req); | ||
827 | |||
828 | __hidp_link_session(session); | 852 | __hidp_link_session(session); |
829 | 853 | ||
830 | hidp_set_timer(session); | 854 | hidp_set_timer(session); |
@@ -850,17 +874,16 @@ unlink: | |||
850 | 874 | ||
851 | __hidp_unlink_session(session); | 875 | __hidp_unlink_session(session); |
852 | 876 | ||
853 | if (session->input) { | 877 | if (session->input) |
854 | input_unregister_device(session->input); | 878 | input_unregister_device(session->input); |
855 | session->input = NULL; /* don't try to free it here */ | 879 | if (session->hid) |
856 | } | 880 | hid_destroy_device(session->hid); |
857 | 881 | err_skb: | |
882 | skb_queue_purge(&session->ctrl_transmit); | ||
883 | skb_queue_purge(&session->intr_transmit); | ||
858 | failed: | 884 | failed: |
859 | up_write(&hidp_session_sem); | 885 | up_write(&hidp_session_sem); |
860 | 886 | ||
861 | if (session->hid) | ||
862 | hid_free_device(session->hid); | ||
863 | |||
864 | input_free_device(session->input); | 887 | input_free_device(session->input); |
865 | kfree(session); | 888 | kfree(session); |
866 | return err; | 889 | return err; |
@@ -950,18 +973,43 @@ int hidp_get_conninfo(struct hidp_conninfo *ci) | |||
950 | return err; | 973 | return err; |
951 | } | 974 | } |
952 | 975 | ||
976 | static const struct hid_device_id hidp_table[] = { | ||
977 | { HID_BLUETOOTH_DEVICE(HID_ANY_ID, HID_ANY_ID) }, | ||
978 | { } | ||
979 | }; | ||
980 | |||
981 | static struct hid_driver hidp_driver = { | ||
982 | .name = "generic-bluetooth", | ||
983 | .id_table = hidp_table, | ||
984 | }; | ||
985 | |||
953 | static int __init hidp_init(void) | 986 | static int __init hidp_init(void) |
954 | { | 987 | { |
988 | int ret; | ||
989 | |||
955 | l2cap_load(); | 990 | l2cap_load(); |
956 | 991 | ||
957 | BT_INFO("HIDP (Human Interface Emulation) ver %s", VERSION); | 992 | BT_INFO("HIDP (Human Interface Emulation) ver %s", VERSION); |
958 | 993 | ||
959 | return hidp_init_sockets(); | 994 | ret = hid_register_driver(&hidp_driver); |
995 | if (ret) | ||
996 | goto err; | ||
997 | |||
998 | ret = hidp_init_sockets(); | ||
999 | if (ret) | ||
1000 | goto err_drv; | ||
1001 | |||
1002 | return 0; | ||
1003 | err_drv: | ||
1004 | hid_unregister_driver(&hidp_driver); | ||
1005 | err: | ||
1006 | return ret; | ||
960 | } | 1007 | } |
961 | 1008 | ||
962 | static void __exit hidp_exit(void) | 1009 | static void __exit hidp_exit(void) |
963 | { | 1010 | { |
964 | hidp_cleanup_sockets(); | 1011 | hidp_cleanup_sockets(); |
1012 | hid_unregister_driver(&hidp_driver); | ||
965 | } | 1013 | } |
966 | 1014 | ||
967 | module_init(hidp_init); | 1015 | module_init(hidp_init); |
diff --git a/net/bluetooth/hidp/hidp.h b/net/bluetooth/hidp/hidp.h index 343fb0566b3e..e503c89057ad 100644 --- a/net/bluetooth/hidp/hidp.h +++ b/net/bluetooth/hidp/hidp.h | |||
@@ -151,6 +151,8 @@ struct hidp_session { | |||
151 | 151 | ||
152 | struct sk_buff_head ctrl_transmit; | 152 | struct sk_buff_head ctrl_transmit; |
153 | struct sk_buff_head intr_transmit; | 153 | struct sk_buff_head intr_transmit; |
154 | |||
155 | struct hidp_connadd_req *req; | ||
154 | }; | 156 | }; |
155 | 157 | ||
156 | static inline void hidp_schedule(struct hidp_session *session) | 158 | static inline void hidp_schedule(struct hidp_session *session) |
diff --git a/net/core/datagram.c b/net/core/datagram.c index 52f577a0f544..ee631843c2f5 100644 --- a/net/core/datagram.c +++ b/net/core/datagram.c | |||
@@ -9,7 +9,7 @@ | |||
9 | * identical recvmsg() code. So we share it here. The poll was | 9 | * identical recvmsg() code. So we share it here. The poll was |
10 | * shared before but buried in udp.c so I moved it. | 10 | * shared before but buried in udp.c so I moved it. |
11 | * | 11 | * |
12 | * Authors: Alan Cox <alan@redhat.com>. (datagram_poll() from old | 12 | * Authors: Alan Cox <alan@lxorguk.ukuu.org.uk>. (datagram_poll() from old |
13 | * udp.c code) | 13 | * udp.c code) |
14 | * | 14 | * |
15 | * Fixes: | 15 | * Fixes: |
diff --git a/net/core/dev_mcast.c b/net/core/dev_mcast.c index 5402b3b38e0d..9e2fa39f22a3 100644 --- a/net/core/dev_mcast.c +++ b/net/core/dev_mcast.c | |||
@@ -6,7 +6,7 @@ | |||
6 | * Richard Underwood <richard@wuzz.demon.co.uk> | 6 | * Richard Underwood <richard@wuzz.demon.co.uk> |
7 | * | 7 | * |
8 | * Stir fried together from the IP multicast and CAP patches above | 8 | * Stir fried together from the IP multicast and CAP patches above |
9 | * Alan Cox <Alan.Cox@linux.org> | 9 | * Alan Cox <alan@lxorguk.ukuu.org.uk> |
10 | * | 10 | * |
11 | * Fixes: | 11 | * Fixes: |
12 | * Alan Cox : Update the device on a real delete | 12 | * Alan Cox : Update the device on a real delete |
diff --git a/net/core/pktgen.c b/net/core/pktgen.c index a756847e3814..99f656d35b4f 100644 --- a/net/core/pktgen.c +++ b/net/core/pktgen.c | |||
@@ -2474,7 +2474,7 @@ static inline int process_ipsec(struct pktgen_dev *pkt_dev, | |||
2474 | if (ret < 0) { | 2474 | if (ret < 0) { |
2475 | printk(KERN_ERR "Error expanding " | 2475 | printk(KERN_ERR "Error expanding " |
2476 | "ipsec packet %d\n",ret); | 2476 | "ipsec packet %d\n",ret); |
2477 | return 0; | 2477 | goto err; |
2478 | } | 2478 | } |
2479 | } | 2479 | } |
2480 | 2480 | ||
@@ -2484,8 +2484,7 @@ static inline int process_ipsec(struct pktgen_dev *pkt_dev, | |||
2484 | if (ret) { | 2484 | if (ret) { |
2485 | printk(KERN_ERR "Error creating ipsec " | 2485 | printk(KERN_ERR "Error creating ipsec " |
2486 | "packet %d\n",ret); | 2486 | "packet %d\n",ret); |
2487 | kfree_skb(skb); | 2487 | goto err; |
2488 | return 0; | ||
2489 | } | 2488 | } |
2490 | /* restore ll */ | 2489 | /* restore ll */ |
2491 | eth = (__u8 *) skb_push(skb, ETH_HLEN); | 2490 | eth = (__u8 *) skb_push(skb, ETH_HLEN); |
@@ -2494,6 +2493,9 @@ static inline int process_ipsec(struct pktgen_dev *pkt_dev, | |||
2494 | } | 2493 | } |
2495 | } | 2494 | } |
2496 | return 1; | 2495 | return 1; |
2496 | err: | ||
2497 | kfree_skb(skb); | ||
2498 | return 0; | ||
2497 | } | 2499 | } |
2498 | #endif | 2500 | #endif |
2499 | 2501 | ||
diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 7f7bb1a636d9..4e22e3a35359 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * Routines having to do with the 'struct sk_buff' memory handlers. | 2 | * Routines having to do with the 'struct sk_buff' memory handlers. |
3 | * | 3 | * |
4 | * Authors: Alan Cox <iiitac@pyr.swan.ac.uk> | 4 | * Authors: Alan Cox <alan@lxorguk.ukuu.org.uk> |
5 | * Florian La Roche <rzsfl@rz.uni-sb.de> | 5 | * Florian La Roche <rzsfl@rz.uni-sb.de> |
6 | * | 6 | * |
7 | * Fixes: | 7 | * Fixes: |
diff --git a/net/core/stream.c b/net/core/stream.c index a6b3437ff082..8727cead64ad 100644 --- a/net/core/stream.c +++ b/net/core/stream.c | |||
@@ -9,7 +9,7 @@ | |||
9 | * | 9 | * |
10 | * Authors: Arnaldo Carvalho de Melo <acme@conectiva.com.br> | 10 | * Authors: Arnaldo Carvalho de Melo <acme@conectiva.com.br> |
11 | * (from old tcp.c code) | 11 | * (from old tcp.c code) |
12 | * Alan Cox <alan@redhat.com> (Borrowed comments 8-)) | 12 | * Alan Cox <alan@lxorguk.ukuu.org.uk> (Borrowed comments 8-)) |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
diff --git a/net/dsa/Kconfig b/net/dsa/Kconfig index cdce4c6c672a..49211b35725b 100644 --- a/net/dsa/Kconfig +++ b/net/dsa/Kconfig | |||
@@ -1,7 +1,7 @@ | |||
1 | menuconfig NET_DSA | 1 | menuconfig NET_DSA |
2 | bool "Distributed Switch Architecture support" | 2 | bool "Distributed Switch Architecture support" |
3 | default n | 3 | default n |
4 | depends on EXPERIMENTAL | 4 | depends on EXPERIMENTAL && !S390 |
5 | select PHYLIB | 5 | select PHYLIB |
6 | ---help--- | 6 | ---help--- |
7 | This allows you to use hardware switch chips that use | 7 | This allows you to use hardware switch chips that use |
diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c index 55c355e63234..72b2de76f1cd 100644 --- a/net/ipv4/icmp.c +++ b/net/ipv4/icmp.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * NET3: Implementation of the ICMP protocol layer. | 2 | * NET3: Implementation of the ICMP protocol layer. |
3 | * | 3 | * |
4 | * Alan Cox, <alan@redhat.com> | 4 | * Alan Cox, <alan@lxorguk.ukuu.org.uk> |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or | 6 | * This program is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU General Public License | 7 | * modify it under the terms of the GNU General Public License |
diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c index 7f9e337e3908..a0d86455c53e 100644 --- a/net/ipv4/igmp.c +++ b/net/ipv4/igmp.c | |||
@@ -9,7 +9,7 @@ | |||
9 | * seems to fall out with gcc 2.6.2. | 9 | * seems to fall out with gcc 2.6.2. |
10 | * | 10 | * |
11 | * Authors: | 11 | * Authors: |
12 | * Alan Cox <Alan.Cox@linux.org> | 12 | * Alan Cox <alan@lxorguk.ukuu.org.uk> |
13 | * | 13 | * |
14 | * This program is free software; you can redistribute it and/or | 14 | * This program is free software; you can redistribute it and/or |
15 | * modify it under the terms of the GNU General Public License | 15 | * modify it under the terms of the GNU General Public License |
diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c index 2152d222b954..e4f81f54befe 100644 --- a/net/ipv4/ip_fragment.c +++ b/net/ipv4/ip_fragment.c | |||
@@ -6,7 +6,7 @@ | |||
6 | * The IP fragmentation functionality. | 6 | * The IP fragmentation functionality. |
7 | * | 7 | * |
8 | * Authors: Fred N. van Kempen <waltje@uWalt.NL.Mugnet.ORG> | 8 | * Authors: Fred N. van Kempen <waltje@uWalt.NL.Mugnet.ORG> |
9 | * Alan Cox <Alan.Cox@linux.org> | 9 | * Alan Cox <alan@lxorguk.ukuu.org.uk> |
10 | * | 10 | * |
11 | * Fixes: | 11 | * Fixes: |
12 | * Alan Cox : Split from ip.c , see ip_input.c for history. | 12 | * Alan Cox : Split from ip.c , see ip_input.c for history. |
diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c index e0bed56c51f1..861978a4f1a8 100644 --- a/net/ipv4/ip_input.c +++ b/net/ipv4/ip_input.c | |||
@@ -8,7 +8,7 @@ | |||
8 | * Authors: Ross Biro | 8 | * Authors: Ross Biro |
9 | * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> | 9 | * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> |
10 | * Donald Becker, <becker@super.org> | 10 | * Donald Becker, <becker@super.org> |
11 | * Alan Cox, <Alan.Cox@linux.org> | 11 | * Alan Cox, <alan@lxorguk.ukuu.org.uk> |
12 | * Richard Underwood | 12 | * Richard Underwood |
13 | * Stefan Becker, <stefanb@yello.ping.de> | 13 | * Stefan Becker, <stefanb@yello.ping.de> |
14 | * Jorge Cwik, <jorge@laser.satlink.net> | 14 | * Jorge Cwik, <jorge@laser.satlink.net> |
diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c index 4c6d2caf9203..29609d29df76 100644 --- a/net/ipv4/ipip.c +++ b/net/ipv4/ipip.c | |||
@@ -41,7 +41,7 @@ | |||
41 | Made the tunnels use dev->name not tunnel: when error reporting. | 41 | Made the tunnels use dev->name not tunnel: when error reporting. |
42 | Added tx_dropped stat | 42 | Added tx_dropped stat |
43 | 43 | ||
44 | -Alan Cox (Alan.Cox@linux.org) 21 March 95 | 44 | -Alan Cox (alan@lxorguk.ukuu.org.uk) 21 March 95 |
45 | 45 | ||
46 | Reworked: | 46 | Reworked: |
47 | Changed to tunnel to destination gateway in addition to the | 47 | Changed to tunnel to destination gateway in addition to the |
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index c519b8d30eee..b42e082cc170 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * IP multicast routing support for mrouted 3.6/3.8 | 2 | * IP multicast routing support for mrouted 3.6/3.8 |
3 | * | 3 | * |
4 | * (c) 1995 Alan Cox, <alan@redhat.com> | 4 | * (c) 1995 Alan Cox, <alan@lxorguk.ukuu.org.uk> |
5 | * Linux Consultancy and Custom Driver Development | 5 | * Linux Consultancy and Custom Driver Development |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or | 7 | * This program is free software; you can redistribute it and/or |
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index eacf4cfef146..2095abc3caba 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c | |||
@@ -8,7 +8,7 @@ | |||
8 | * Authors: Ross Biro | 8 | * Authors: Ross Biro |
9 | * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> | 9 | * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> |
10 | * Arnt Gulbrandsen, <agulbra@nvg.unit.no> | 10 | * Arnt Gulbrandsen, <agulbra@nvg.unit.no> |
11 | * Alan Cox, <Alan.Cox@linux.org> | 11 | * Alan Cox, <alan@lxorguk.ukuu.org.uk> |
12 | * Hirokazu Takahashi, <taka@valinux.co.jp> | 12 | * Hirokazu Takahashi, <taka@valinux.co.jp> |
13 | * | 13 | * |
14 | * Fixes: | 14 | * Fixes: |
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c index 050e14b7f701..01edac888510 100644 --- a/net/ipv6/af_inet6.c +++ b/net/ipv6/af_inet6.c | |||
@@ -834,7 +834,7 @@ static void __net_exit ipv6_cleanup_mibs(struct net *net) | |||
834 | snmp_mib_free((void **)net->mib.icmpv6msg_statistics); | 834 | snmp_mib_free((void **)net->mib.icmpv6msg_statistics); |
835 | } | 835 | } |
836 | 836 | ||
837 | static int inet6_net_init(struct net *net) | 837 | static int __net_init inet6_net_init(struct net *net) |
838 | { | 838 | { |
839 | int err = 0; | 839 | int err = 0; |
840 | 840 | ||
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index b0eacc0007cc..2fd8afac5f71 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * NETLINK Kernel-user communication protocol. | 2 | * NETLINK Kernel-user communication protocol. |
3 | * | 3 | * |
4 | * Authors: Alan Cox <alan@redhat.com> | 4 | * Authors: Alan Cox <alan@lxorguk.ukuu.org.uk> |
5 | * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru> | 5 | * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru> |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or | 7 | * This program is free software; you can redistribute it and/or |
diff --git a/net/rfkill/rfkill-input.c b/net/rfkill/rfkill-input.c index e5b69556bb5b..21124ec0a73d 100644 --- a/net/rfkill/rfkill-input.c +++ b/net/rfkill/rfkill-input.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/workqueue.h> | 16 | #include <linux/workqueue.h> |
17 | #include <linux/init.h> | 17 | #include <linux/init.h> |
18 | #include <linux/rfkill.h> | 18 | #include <linux/rfkill.h> |
19 | #include <linux/sched.h> | ||
19 | 20 | ||
20 | #include "rfkill-input.h" | 21 | #include "rfkill-input.h" |
21 | 22 | ||
diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c index 76739e928d0d..da0789fa1b88 100644 --- a/net/sunrpc/clnt.c +++ b/net/sunrpc/clnt.c | |||
@@ -174,7 +174,7 @@ static struct rpc_clnt * rpc_new_client(const struct rpc_create_args *args, stru | |||
174 | clnt->cl_procinfo = version->procs; | 174 | clnt->cl_procinfo = version->procs; |
175 | clnt->cl_maxproc = version->nrprocs; | 175 | clnt->cl_maxproc = version->nrprocs; |
176 | clnt->cl_protname = program->name; | 176 | clnt->cl_protname = program->name; |
177 | clnt->cl_prog = program->number; | 177 | clnt->cl_prog = args->prognumber ? : program->number; |
178 | clnt->cl_vers = version->number; | 178 | clnt->cl_vers = version->number; |
179 | clnt->cl_stats = program->stats; | 179 | clnt->cl_stats = program->stats; |
180 | clnt->cl_metrics = rpc_alloc_iostats(clnt); | 180 | clnt->cl_metrics = rpc_alloc_iostats(clnt); |
diff --git a/net/sunrpc/rpcb_clnt.c b/net/sunrpc/rpcb_clnt.c index 24db2b4d12d3..34abc91058d8 100644 --- a/net/sunrpc/rpcb_clnt.c +++ b/net/sunrpc/rpcb_clnt.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/in6.h> | 20 | #include <linux/in6.h> |
21 | #include <linux/kernel.h> | 21 | #include <linux/kernel.h> |
22 | #include <linux/errno.h> | 22 | #include <linux/errno.h> |
23 | #include <net/ipv6.h> | ||
23 | 24 | ||
24 | #include <linux/sunrpc/clnt.h> | 25 | #include <linux/sunrpc/clnt.h> |
25 | #include <linux/sunrpc/sched.h> | 26 | #include <linux/sunrpc/sched.h> |
@@ -176,13 +177,12 @@ static struct rpc_clnt *rpcb_create(char *hostname, struct sockaddr *srvaddr, | |||
176 | } | 177 | } |
177 | 178 | ||
178 | static int rpcb_register_call(struct sockaddr *addr, size_t addrlen, | 179 | static int rpcb_register_call(struct sockaddr *addr, size_t addrlen, |
179 | u32 version, struct rpc_message *msg, | 180 | u32 version, struct rpc_message *msg) |
180 | int *result) | ||
181 | { | 181 | { |
182 | struct rpc_clnt *rpcb_clnt; | 182 | struct rpc_clnt *rpcb_clnt; |
183 | int error = 0; | 183 | int result, error = 0; |
184 | 184 | ||
185 | *result = 0; | 185 | msg->rpc_resp = &result; |
186 | 186 | ||
187 | rpcb_clnt = rpcb_create_local(addr, addrlen, version); | 187 | rpcb_clnt = rpcb_create_local(addr, addrlen, version); |
188 | if (!IS_ERR(rpcb_clnt)) { | 188 | if (!IS_ERR(rpcb_clnt)) { |
@@ -191,12 +191,15 @@ static int rpcb_register_call(struct sockaddr *addr, size_t addrlen, | |||
191 | } else | 191 | } else |
192 | error = PTR_ERR(rpcb_clnt); | 192 | error = PTR_ERR(rpcb_clnt); |
193 | 193 | ||
194 | if (error < 0) | 194 | if (error < 0) { |
195 | printk(KERN_WARNING "RPC: failed to contact local rpcbind " | 195 | printk(KERN_WARNING "RPC: failed to contact local rpcbind " |
196 | "server (errno %d).\n", -error); | 196 | "server (errno %d).\n", -error); |
197 | dprintk("RPC: registration status %d/%d\n", error, *result); | 197 | return error; |
198 | } | ||
198 | 199 | ||
199 | return error; | 200 | if (!result) |
201 | return -EACCES; | ||
202 | return 0; | ||
200 | } | 203 | } |
201 | 204 | ||
202 | /** | 205 | /** |
@@ -205,7 +208,11 @@ static int rpcb_register_call(struct sockaddr *addr, size_t addrlen, | |||
205 | * @vers: RPC version number to bind | 208 | * @vers: RPC version number to bind |
206 | * @prot: transport protocol to register | 209 | * @prot: transport protocol to register |
207 | * @port: port value to register | 210 | * @port: port value to register |
208 | * @okay: OUT: result code | 211 | * |
212 | * Returns zero if the registration request was dispatched successfully | ||
213 | * and the rpcbind daemon returned success. Otherwise, returns an errno | ||
214 | * value that reflects the nature of the error (request could not be | ||
215 | * dispatched, timed out, or rpcbind returned an error). | ||
209 | * | 216 | * |
210 | * RPC services invoke this function to advertise their contact | 217 | * RPC services invoke this function to advertise their contact |
211 | * information via the system's rpcbind daemon. RPC services | 218 | * information via the system's rpcbind daemon. RPC services |
@@ -217,15 +224,6 @@ static int rpcb_register_call(struct sockaddr *addr, size_t addrlen, | |||
217 | * all registered transports for [program, version] from the local | 224 | * all registered transports for [program, version] from the local |
218 | * rpcbind database. | 225 | * rpcbind database. |
219 | * | 226 | * |
220 | * Returns zero if the registration request was dispatched | ||
221 | * successfully and a reply was received. The rpcbind daemon's | ||
222 | * boolean result code is stored in *okay. | ||
223 | * | ||
224 | * Returns an errno value and sets *result to zero if there was | ||
225 | * some problem that prevented the rpcbind request from being | ||
226 | * dispatched, or if the rpcbind daemon did not respond within | ||
227 | * the timeout. | ||
228 | * | ||
229 | * This function uses rpcbind protocol version 2 to contact the | 227 | * This function uses rpcbind protocol version 2 to contact the |
230 | * local rpcbind daemon. | 228 | * local rpcbind daemon. |
231 | * | 229 | * |
@@ -236,7 +234,7 @@ static int rpcb_register_call(struct sockaddr *addr, size_t addrlen, | |||
236 | * IN6ADDR_ANY (ie available for all AF_INET and AF_INET6 | 234 | * IN6ADDR_ANY (ie available for all AF_INET and AF_INET6 |
237 | * addresses). | 235 | * addresses). |
238 | */ | 236 | */ |
239 | int rpcb_register(u32 prog, u32 vers, int prot, unsigned short port, int *okay) | 237 | int rpcb_register(u32 prog, u32 vers, int prot, unsigned short port) |
240 | { | 238 | { |
241 | struct rpcbind_args map = { | 239 | struct rpcbind_args map = { |
242 | .r_prog = prog, | 240 | .r_prog = prog, |
@@ -246,7 +244,6 @@ int rpcb_register(u32 prog, u32 vers, int prot, unsigned short port, int *okay) | |||
246 | }; | 244 | }; |
247 | struct rpc_message msg = { | 245 | struct rpc_message msg = { |
248 | .rpc_argp = &map, | 246 | .rpc_argp = &map, |
249 | .rpc_resp = okay, | ||
250 | }; | 247 | }; |
251 | 248 | ||
252 | dprintk("RPC: %sregistering (%u, %u, %d, %u) with local " | 249 | dprintk("RPC: %sregistering (%u, %u, %d, %u) with local " |
@@ -259,7 +256,7 @@ int rpcb_register(u32 prog, u32 vers, int prot, unsigned short port, int *okay) | |||
259 | 256 | ||
260 | return rpcb_register_call((struct sockaddr *)&rpcb_inaddr_loopback, | 257 | return rpcb_register_call((struct sockaddr *)&rpcb_inaddr_loopback, |
261 | sizeof(rpcb_inaddr_loopback), | 258 | sizeof(rpcb_inaddr_loopback), |
262 | RPCBVERS_2, &msg, okay); | 259 | RPCBVERS_2, &msg); |
263 | } | 260 | } |
264 | 261 | ||
265 | /* | 262 | /* |
@@ -290,7 +287,7 @@ static int rpcb_register_netid4(struct sockaddr_in *address_to_register, | |||
290 | 287 | ||
291 | return rpcb_register_call((struct sockaddr *)&rpcb_inaddr_loopback, | 288 | return rpcb_register_call((struct sockaddr *)&rpcb_inaddr_loopback, |
292 | sizeof(rpcb_inaddr_loopback), | 289 | sizeof(rpcb_inaddr_loopback), |
293 | RPCBVERS_4, msg, msg->rpc_resp); | 290 | RPCBVERS_4, msg); |
294 | } | 291 | } |
295 | 292 | ||
296 | /* | 293 | /* |
@@ -304,10 +301,13 @@ static int rpcb_register_netid6(struct sockaddr_in6 *address_to_register, | |||
304 | char buf[64]; | 301 | char buf[64]; |
305 | 302 | ||
306 | /* Construct AF_INET6 universal address */ | 303 | /* Construct AF_INET6 universal address */ |
307 | snprintf(buf, sizeof(buf), | 304 | if (ipv6_addr_any(&address_to_register->sin6_addr)) |
308 | NIP6_FMT".%u.%u", | 305 | snprintf(buf, sizeof(buf), "::.%u.%u", |
309 | NIP6(address_to_register->sin6_addr), | 306 | port >> 8, port & 0xff); |
310 | port >> 8, port & 0xff); | 307 | else |
308 | snprintf(buf, sizeof(buf), NIP6_FMT".%u.%u", | ||
309 | NIP6(address_to_register->sin6_addr), | ||
310 | port >> 8, port & 0xff); | ||
311 | map->r_addr = buf; | 311 | map->r_addr = buf; |
312 | 312 | ||
313 | dprintk("RPC: %sregistering [%u, %u, %s, '%s'] with " | 313 | dprintk("RPC: %sregistering [%u, %u, %s, '%s'] with " |
@@ -321,7 +321,7 @@ static int rpcb_register_netid6(struct sockaddr_in6 *address_to_register, | |||
321 | 321 | ||
322 | return rpcb_register_call((struct sockaddr *)&rpcb_in6addr_loopback, | 322 | return rpcb_register_call((struct sockaddr *)&rpcb_in6addr_loopback, |
323 | sizeof(rpcb_in6addr_loopback), | 323 | sizeof(rpcb_in6addr_loopback), |
324 | RPCBVERS_4, msg, msg->rpc_resp); | 324 | RPCBVERS_4, msg); |
325 | } | 325 | } |
326 | 326 | ||
327 | /** | 327 | /** |
@@ -330,7 +330,11 @@ static int rpcb_register_netid6(struct sockaddr_in6 *address_to_register, | |||
330 | * @version: RPC version number of service to (un)register | 330 | * @version: RPC version number of service to (un)register |
331 | * @address: address family, IP address, and port to (un)register | 331 | * @address: address family, IP address, and port to (un)register |
332 | * @netid: netid of transport protocol to (un)register | 332 | * @netid: netid of transport protocol to (un)register |
333 | * @result: result code from rpcbind RPC call | 333 | * |
334 | * Returns zero if the registration request was dispatched successfully | ||
335 | * and the rpcbind daemon returned success. Otherwise, returns an errno | ||
336 | * value that reflects the nature of the error (request could not be | ||
337 | * dispatched, timed out, or rpcbind returned an error). | ||
334 | * | 338 | * |
335 | * RPC services invoke this function to advertise their contact | 339 | * RPC services invoke this function to advertise their contact |
336 | * information via the system's rpcbind daemon. RPC services | 340 | * information via the system's rpcbind daemon. RPC services |
@@ -342,15 +346,6 @@ static int rpcb_register_netid6(struct sockaddr_in6 *address_to_register, | |||
342 | * to zero. Callers pass a netid of "" to unregister all | 346 | * to zero. Callers pass a netid of "" to unregister all |
343 | * transport netids associated with [program, version, address]. | 347 | * transport netids associated with [program, version, address]. |
344 | * | 348 | * |
345 | * Returns zero if the registration request was dispatched | ||
346 | * successfully and a reply was received. The rpcbind daemon's | ||
347 | * result code is stored in *result. | ||
348 | * | ||
349 | * Returns an errno value and sets *result to zero if there was | ||
350 | * some problem that prevented the rpcbind request from being | ||
351 | * dispatched, or if the rpcbind daemon did not respond within | ||
352 | * the timeout. | ||
353 | * | ||
354 | * This function uses rpcbind protocol version 4 to contact the | 349 | * This function uses rpcbind protocol version 4 to contact the |
355 | * local rpcbind daemon. The local rpcbind daemon must support | 350 | * local rpcbind daemon. The local rpcbind daemon must support |
356 | * version 4 of the rpcbind protocol in order for these functions | 351 | * version 4 of the rpcbind protocol in order for these functions |
@@ -372,8 +367,7 @@ static int rpcb_register_netid6(struct sockaddr_in6 *address_to_register, | |||
372 | * advertises the service on all IPv4 and IPv6 addresses. | 367 | * advertises the service on all IPv4 and IPv6 addresses. |
373 | */ | 368 | */ |
374 | int rpcb_v4_register(const u32 program, const u32 version, | 369 | int rpcb_v4_register(const u32 program, const u32 version, |
375 | const struct sockaddr *address, const char *netid, | 370 | const struct sockaddr *address, const char *netid) |
376 | int *result) | ||
377 | { | 371 | { |
378 | struct rpcbind_args map = { | 372 | struct rpcbind_args map = { |
379 | .r_prog = program, | 373 | .r_prog = program, |
@@ -383,11 +377,8 @@ int rpcb_v4_register(const u32 program, const u32 version, | |||
383 | }; | 377 | }; |
384 | struct rpc_message msg = { | 378 | struct rpc_message msg = { |
385 | .rpc_argp = &map, | 379 | .rpc_argp = &map, |
386 | .rpc_resp = result, | ||
387 | }; | 380 | }; |
388 | 381 | ||
389 | *result = 0; | ||
390 | |||
391 | switch (address->sa_family) { | 382 | switch (address->sa_family) { |
392 | case AF_INET: | 383 | case AF_INET: |
393 | return rpcb_register_netid4((struct sockaddr_in *)address, | 384 | return rpcb_register_netid4((struct sockaddr_in *)address, |
@@ -633,7 +624,7 @@ static void rpcb_getport_done(struct rpc_task *child, void *data) | |||
633 | static int rpcb_encode_mapping(struct rpc_rqst *req, __be32 *p, | 624 | static int rpcb_encode_mapping(struct rpc_rqst *req, __be32 *p, |
634 | struct rpcbind_args *rpcb) | 625 | struct rpcbind_args *rpcb) |
635 | { | 626 | { |
636 | dprintk("RPC: rpcb_encode_mapping(%u, %u, %d, %u)\n", | 627 | dprintk("RPC: encoding rpcb request (%u, %u, %d, %u)\n", |
637 | rpcb->r_prog, rpcb->r_vers, rpcb->r_prot, rpcb->r_port); | 628 | rpcb->r_prog, rpcb->r_vers, rpcb->r_prot, rpcb->r_port); |
638 | *p++ = htonl(rpcb->r_prog); | 629 | *p++ = htonl(rpcb->r_prog); |
639 | *p++ = htonl(rpcb->r_vers); | 630 | *p++ = htonl(rpcb->r_vers); |
@@ -648,7 +639,7 @@ static int rpcb_decode_getport(struct rpc_rqst *req, __be32 *p, | |||
648 | unsigned short *portp) | 639 | unsigned short *portp) |
649 | { | 640 | { |
650 | *portp = (unsigned short) ntohl(*p++); | 641 | *portp = (unsigned short) ntohl(*p++); |
651 | dprintk("RPC: rpcb_decode_getport result %u\n", | 642 | dprintk("RPC: rpcb getport result: %u\n", |
652 | *portp); | 643 | *portp); |
653 | return 0; | 644 | return 0; |
654 | } | 645 | } |
@@ -657,7 +648,7 @@ static int rpcb_decode_set(struct rpc_rqst *req, __be32 *p, | |||
657 | unsigned int *boolp) | 648 | unsigned int *boolp) |
658 | { | 649 | { |
659 | *boolp = (unsigned int) ntohl(*p++); | 650 | *boolp = (unsigned int) ntohl(*p++); |
660 | dprintk("RPC: rpcb_decode_set: call %s\n", | 651 | dprintk("RPC: rpcb set/unset call %s\n", |
661 | (*boolp ? "succeeded" : "failed")); | 652 | (*boolp ? "succeeded" : "failed")); |
662 | return 0; | 653 | return 0; |
663 | } | 654 | } |
@@ -665,7 +656,7 @@ static int rpcb_decode_set(struct rpc_rqst *req, __be32 *p, | |||
665 | static int rpcb_encode_getaddr(struct rpc_rqst *req, __be32 *p, | 656 | static int rpcb_encode_getaddr(struct rpc_rqst *req, __be32 *p, |
666 | struct rpcbind_args *rpcb) | 657 | struct rpcbind_args *rpcb) |
667 | { | 658 | { |
668 | dprintk("RPC: rpcb_encode_getaddr(%u, %u, %s)\n", | 659 | dprintk("RPC: encoding rpcb request (%u, %u, %s)\n", |
669 | rpcb->r_prog, rpcb->r_vers, rpcb->r_addr); | 660 | rpcb->r_prog, rpcb->r_vers, rpcb->r_addr); |
670 | *p++ = htonl(rpcb->r_prog); | 661 | *p++ = htonl(rpcb->r_prog); |
671 | *p++ = htonl(rpcb->r_vers); | 662 | *p++ = htonl(rpcb->r_vers); |
diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c index 5a32cb7c4bb4..54c98d876847 100644 --- a/net/sunrpc/svc.c +++ b/net/sunrpc/svc.c | |||
@@ -28,6 +28,8 @@ | |||
28 | 28 | ||
29 | #define RPCDBG_FACILITY RPCDBG_SVCDSP | 29 | #define RPCDBG_FACILITY RPCDBG_SVCDSP |
30 | 30 | ||
31 | static void svc_unregister(const struct svc_serv *serv); | ||
32 | |||
31 | #define svc_serv_is_pooled(serv) ((serv)->sv_function) | 33 | #define svc_serv_is_pooled(serv) ((serv)->sv_function) |
32 | 34 | ||
33 | /* | 35 | /* |
@@ -357,7 +359,7 @@ svc_pool_for_cpu(struct svc_serv *serv, int cpu) | |||
357 | */ | 359 | */ |
358 | static struct svc_serv * | 360 | static struct svc_serv * |
359 | __svc_create(struct svc_program *prog, unsigned int bufsize, int npools, | 361 | __svc_create(struct svc_program *prog, unsigned int bufsize, int npools, |
360 | void (*shutdown)(struct svc_serv *serv)) | 362 | sa_family_t family, void (*shutdown)(struct svc_serv *serv)) |
361 | { | 363 | { |
362 | struct svc_serv *serv; | 364 | struct svc_serv *serv; |
363 | unsigned int vers; | 365 | unsigned int vers; |
@@ -366,6 +368,7 @@ __svc_create(struct svc_program *prog, unsigned int bufsize, int npools, | |||
366 | 368 | ||
367 | if (!(serv = kzalloc(sizeof(*serv), GFP_KERNEL))) | 369 | if (!(serv = kzalloc(sizeof(*serv), GFP_KERNEL))) |
368 | return NULL; | 370 | return NULL; |
371 | serv->sv_family = family; | ||
369 | serv->sv_name = prog->pg_name; | 372 | serv->sv_name = prog->pg_name; |
370 | serv->sv_program = prog; | 373 | serv->sv_program = prog; |
371 | serv->sv_nrthreads = 1; | 374 | serv->sv_nrthreads = 1; |
@@ -416,30 +419,29 @@ __svc_create(struct svc_program *prog, unsigned int bufsize, int npools, | |||
416 | spin_lock_init(&pool->sp_lock); | 419 | spin_lock_init(&pool->sp_lock); |
417 | } | 420 | } |
418 | 421 | ||
419 | |||
420 | /* Remove any stale portmap registrations */ | 422 | /* Remove any stale portmap registrations */ |
421 | svc_register(serv, 0, 0); | 423 | svc_unregister(serv); |
422 | 424 | ||
423 | return serv; | 425 | return serv; |
424 | } | 426 | } |
425 | 427 | ||
426 | struct svc_serv * | 428 | struct svc_serv * |
427 | svc_create(struct svc_program *prog, unsigned int bufsize, | 429 | svc_create(struct svc_program *prog, unsigned int bufsize, |
428 | void (*shutdown)(struct svc_serv *serv)) | 430 | sa_family_t family, void (*shutdown)(struct svc_serv *serv)) |
429 | { | 431 | { |
430 | return __svc_create(prog, bufsize, /*npools*/1, shutdown); | 432 | return __svc_create(prog, bufsize, /*npools*/1, family, shutdown); |
431 | } | 433 | } |
432 | EXPORT_SYMBOL(svc_create); | 434 | EXPORT_SYMBOL(svc_create); |
433 | 435 | ||
434 | struct svc_serv * | 436 | struct svc_serv * |
435 | svc_create_pooled(struct svc_program *prog, unsigned int bufsize, | 437 | svc_create_pooled(struct svc_program *prog, unsigned int bufsize, |
436 | void (*shutdown)(struct svc_serv *serv), | 438 | sa_family_t family, void (*shutdown)(struct svc_serv *serv), |
437 | svc_thread_fn func, struct module *mod) | 439 | svc_thread_fn func, struct module *mod) |
438 | { | 440 | { |
439 | struct svc_serv *serv; | 441 | struct svc_serv *serv; |
440 | unsigned int npools = svc_pool_map_get(); | 442 | unsigned int npools = svc_pool_map_get(); |
441 | 443 | ||
442 | serv = __svc_create(prog, bufsize, npools, shutdown); | 444 | serv = __svc_create(prog, bufsize, npools, family, shutdown); |
443 | 445 | ||
444 | if (serv != NULL) { | 446 | if (serv != NULL) { |
445 | serv->sv_function = func; | 447 | serv->sv_function = func; |
@@ -486,8 +488,7 @@ svc_destroy(struct svc_serv *serv) | |||
486 | if (svc_serv_is_pooled(serv)) | 488 | if (svc_serv_is_pooled(serv)) |
487 | svc_pool_map_put(); | 489 | svc_pool_map_put(); |
488 | 490 | ||
489 | /* Unregister service with the portmapper */ | 491 | svc_unregister(serv); |
490 | svc_register(serv, 0, 0); | ||
491 | kfree(serv->sv_pools); | 492 | kfree(serv->sv_pools); |
492 | kfree(serv); | 493 | kfree(serv); |
493 | } | 494 | } |
@@ -718,55 +719,245 @@ svc_exit_thread(struct svc_rqst *rqstp) | |||
718 | } | 719 | } |
719 | EXPORT_SYMBOL(svc_exit_thread); | 720 | EXPORT_SYMBOL(svc_exit_thread); |
720 | 721 | ||
722 | #ifdef CONFIG_SUNRPC_REGISTER_V4 | ||
723 | |||
721 | /* | 724 | /* |
722 | * Register an RPC service with the local portmapper. | 725 | * Register an "inet" protocol family netid with the local |
723 | * To unregister a service, call this routine with | 726 | * rpcbind daemon via an rpcbind v4 SET request. |
724 | * proto and port == 0. | 727 | * |
728 | * No netconfig infrastructure is available in the kernel, so | ||
729 | * we map IP_ protocol numbers to netids by hand. | ||
730 | * | ||
731 | * Returns zero on success; a negative errno value is returned | ||
732 | * if any error occurs. | ||
725 | */ | 733 | */ |
726 | int | 734 | static int __svc_rpcb_register4(const u32 program, const u32 version, |
727 | svc_register(struct svc_serv *serv, int proto, unsigned short port) | 735 | const unsigned short protocol, |
736 | const unsigned short port) | ||
737 | { | ||
738 | struct sockaddr_in sin = { | ||
739 | .sin_family = AF_INET, | ||
740 | .sin_addr.s_addr = htonl(INADDR_ANY), | ||
741 | .sin_port = htons(port), | ||
742 | }; | ||
743 | char *netid; | ||
744 | |||
745 | switch (protocol) { | ||
746 | case IPPROTO_UDP: | ||
747 | netid = RPCBIND_NETID_UDP; | ||
748 | break; | ||
749 | case IPPROTO_TCP: | ||
750 | netid = RPCBIND_NETID_TCP; | ||
751 | break; | ||
752 | default: | ||
753 | return -EPROTONOSUPPORT; | ||
754 | } | ||
755 | |||
756 | return rpcb_v4_register(program, version, | ||
757 | (struct sockaddr *)&sin, netid); | ||
758 | } | ||
759 | |||
760 | /* | ||
761 | * Register an "inet6" protocol family netid with the local | ||
762 | * rpcbind daemon via an rpcbind v4 SET request. | ||
763 | * | ||
764 | * No netconfig infrastructure is available in the kernel, so | ||
765 | * we map IP_ protocol numbers to netids by hand. | ||
766 | * | ||
767 | * Returns zero on success; a negative errno value is returned | ||
768 | * if any error occurs. | ||
769 | */ | ||
770 | static int __svc_rpcb_register6(const u32 program, const u32 version, | ||
771 | const unsigned short protocol, | ||
772 | const unsigned short port) | ||
773 | { | ||
774 | struct sockaddr_in6 sin6 = { | ||
775 | .sin6_family = AF_INET6, | ||
776 | .sin6_addr = IN6ADDR_ANY_INIT, | ||
777 | .sin6_port = htons(port), | ||
778 | }; | ||
779 | char *netid; | ||
780 | |||
781 | switch (protocol) { | ||
782 | case IPPROTO_UDP: | ||
783 | netid = RPCBIND_NETID_UDP6; | ||
784 | break; | ||
785 | case IPPROTO_TCP: | ||
786 | netid = RPCBIND_NETID_TCP6; | ||
787 | break; | ||
788 | default: | ||
789 | return -EPROTONOSUPPORT; | ||
790 | } | ||
791 | |||
792 | return rpcb_v4_register(program, version, | ||
793 | (struct sockaddr *)&sin6, netid); | ||
794 | } | ||
795 | |||
796 | /* | ||
797 | * Register a kernel RPC service via rpcbind version 4. | ||
798 | * | ||
799 | * Returns zero on success; a negative errno value is returned | ||
800 | * if any error occurs. | ||
801 | */ | ||
802 | static int __svc_register(const u32 program, const u32 version, | ||
803 | const sa_family_t family, | ||
804 | const unsigned short protocol, | ||
805 | const unsigned short port) | ||
806 | { | ||
807 | int error; | ||
808 | |||
809 | switch (family) { | ||
810 | case AF_INET: | ||
811 | return __svc_rpcb_register4(program, version, | ||
812 | protocol, port); | ||
813 | case AF_INET6: | ||
814 | error = __svc_rpcb_register6(program, version, | ||
815 | protocol, port); | ||
816 | if (error < 0) | ||
817 | return error; | ||
818 | |||
819 | /* | ||
820 | * Work around bug in some versions of Linux rpcbind | ||
821 | * which don't allow registration of both inet and | ||
822 | * inet6 netids. | ||
823 | * | ||
824 | * Error return ignored for now. | ||
825 | */ | ||
826 | __svc_rpcb_register4(program, version, | ||
827 | protocol, port); | ||
828 | return 0; | ||
829 | } | ||
830 | |||
831 | return -EAFNOSUPPORT; | ||
832 | } | ||
833 | |||
834 | #else /* CONFIG_SUNRPC_REGISTER_V4 */ | ||
835 | |||
836 | /* | ||
837 | * Register a kernel RPC service via rpcbind version 2. | ||
838 | * | ||
839 | * Returns zero on success; a negative errno value is returned | ||
840 | * if any error occurs. | ||
841 | */ | ||
842 | static int __svc_register(const u32 program, const u32 version, | ||
843 | sa_family_t family, | ||
844 | const unsigned short protocol, | ||
845 | const unsigned short port) | ||
846 | { | ||
847 | if (family != AF_INET) | ||
848 | return -EAFNOSUPPORT; | ||
849 | |||
850 | return rpcb_register(program, version, protocol, port); | ||
851 | } | ||
852 | |||
853 | #endif /* CONFIG_SUNRPC_REGISTER_V4 */ | ||
854 | |||
855 | /** | ||
856 | * svc_register - register an RPC service with the local portmapper | ||
857 | * @serv: svc_serv struct for the service to register | ||
858 | * @proto: transport protocol number to advertise | ||
859 | * @port: port to advertise | ||
860 | * | ||
861 | * Service is registered for any address in serv's address family | ||
862 | */ | ||
863 | int svc_register(const struct svc_serv *serv, const unsigned short proto, | ||
864 | const unsigned short port) | ||
728 | { | 865 | { |
729 | struct svc_program *progp; | 866 | struct svc_program *progp; |
730 | unsigned long flags; | ||
731 | unsigned int i; | 867 | unsigned int i; |
732 | int error = 0, dummy; | 868 | int error = 0; |
733 | 869 | ||
734 | if (!port) | 870 | BUG_ON(proto == 0 && port == 0); |
735 | clear_thread_flag(TIF_SIGPENDING); | ||
736 | 871 | ||
737 | for (progp = serv->sv_program; progp; progp = progp->pg_next) { | 872 | for (progp = serv->sv_program; progp; progp = progp->pg_next) { |
738 | for (i = 0; i < progp->pg_nvers; i++) { | 873 | for (i = 0; i < progp->pg_nvers; i++) { |
739 | if (progp->pg_vers[i] == NULL) | 874 | if (progp->pg_vers[i] == NULL) |
740 | continue; | 875 | continue; |
741 | 876 | ||
742 | dprintk("svc: svc_register(%s, %s, %d, %d)%s\n", | 877 | dprintk("svc: svc_register(%sv%d, %s, %u, %u)%s\n", |
743 | progp->pg_name, | 878 | progp->pg_name, |
879 | i, | ||
744 | proto == IPPROTO_UDP? "udp" : "tcp", | 880 | proto == IPPROTO_UDP? "udp" : "tcp", |
745 | port, | 881 | port, |
746 | i, | 882 | serv->sv_family, |
747 | progp->pg_vers[i]->vs_hidden? | 883 | progp->pg_vers[i]->vs_hidden? |
748 | " (but not telling portmap)" : ""); | 884 | " (but not telling portmap)" : ""); |
749 | 885 | ||
750 | if (progp->pg_vers[i]->vs_hidden) | 886 | if (progp->pg_vers[i]->vs_hidden) |
751 | continue; | 887 | continue; |
752 | 888 | ||
753 | error = rpcb_register(progp->pg_prog, i, proto, port, &dummy); | 889 | error = __svc_register(progp->pg_prog, i, |
890 | serv->sv_family, proto, port); | ||
754 | if (error < 0) | 891 | if (error < 0) |
755 | break; | 892 | break; |
756 | if (port && !dummy) { | ||
757 | error = -EACCES; | ||
758 | break; | ||
759 | } | ||
760 | } | 893 | } |
761 | } | 894 | } |
762 | 895 | ||
763 | if (!port) { | 896 | return error; |
764 | spin_lock_irqsave(¤t->sighand->siglock, flags); | 897 | } |
765 | recalc_sigpending(); | 898 | |
766 | spin_unlock_irqrestore(¤t->sighand->siglock, flags); | 899 | #ifdef CONFIG_SUNRPC_REGISTER_V4 |
900 | |||
901 | static void __svc_unregister(const u32 program, const u32 version, | ||
902 | const char *progname) | ||
903 | { | ||
904 | struct sockaddr_in6 sin6 = { | ||
905 | .sin6_family = AF_INET6, | ||
906 | .sin6_addr = IN6ADDR_ANY_INIT, | ||
907 | .sin6_port = 0, | ||
908 | }; | ||
909 | int error; | ||
910 | |||
911 | error = rpcb_v4_register(program, version, | ||
912 | (struct sockaddr *)&sin6, ""); | ||
913 | dprintk("svc: %s(%sv%u), error %d\n", | ||
914 | __func__, progname, version, error); | ||
915 | } | ||
916 | |||
917 | #else /* CONFIG_SUNRPC_REGISTER_V4 */ | ||
918 | |||
919 | static void __svc_unregister(const u32 program, const u32 version, | ||
920 | const char *progname) | ||
921 | { | ||
922 | int error; | ||
923 | |||
924 | error = rpcb_register(program, version, 0, 0); | ||
925 | dprintk("svc: %s(%sv%u), error %d\n", | ||
926 | __func__, progname, version, error); | ||
927 | } | ||
928 | |||
929 | #endif /* CONFIG_SUNRPC_REGISTER_V4 */ | ||
930 | |||
931 | /* | ||
932 | * All netids, bind addresses and ports registered for [program, version] | ||
933 | * are removed from the local rpcbind database (if the service is not | ||
934 | * hidden) to make way for a new instance of the service. | ||
935 | * | ||
936 | * The result of unregistration is reported via dprintk for those who want | ||
937 | * verification of the result, but is otherwise not important. | ||
938 | */ | ||
939 | static void svc_unregister(const struct svc_serv *serv) | ||
940 | { | ||
941 | struct svc_program *progp; | ||
942 | unsigned long flags; | ||
943 | unsigned int i; | ||
944 | |||
945 | clear_thread_flag(TIF_SIGPENDING); | ||
946 | |||
947 | for (progp = serv->sv_program; progp; progp = progp->pg_next) { | ||
948 | for (i = 0; i < progp->pg_nvers; i++) { | ||
949 | if (progp->pg_vers[i] == NULL) | ||
950 | continue; | ||
951 | if (progp->pg_vers[i]->vs_hidden) | ||
952 | continue; | ||
953 | |||
954 | __svc_unregister(progp->pg_prog, i, progp->pg_name); | ||
955 | } | ||
767 | } | 956 | } |
768 | 957 | ||
769 | return error; | 958 | spin_lock_irqsave(¤t->sighand->siglock, flags); |
959 | recalc_sigpending(); | ||
960 | spin_unlock_irqrestore(¤t->sighand->siglock, flags); | ||
770 | } | 961 | } |
771 | 962 | ||
772 | /* | 963 | /* |
diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c index e46c825f4954..bf5b5cdafebf 100644 --- a/net/sunrpc/svc_xprt.c +++ b/net/sunrpc/svc_xprt.c | |||
@@ -159,15 +159,44 @@ void svc_xprt_init(struct svc_xprt_class *xcl, struct svc_xprt *xprt, | |||
159 | } | 159 | } |
160 | EXPORT_SYMBOL_GPL(svc_xprt_init); | 160 | EXPORT_SYMBOL_GPL(svc_xprt_init); |
161 | 161 | ||
162 | int svc_create_xprt(struct svc_serv *serv, char *xprt_name, unsigned short port, | 162 | static struct svc_xprt *__svc_xpo_create(struct svc_xprt_class *xcl, |
163 | int flags) | 163 | struct svc_serv *serv, |
164 | unsigned short port, int flags) | ||
164 | { | 165 | { |
165 | struct svc_xprt_class *xcl; | ||
166 | struct sockaddr_in sin = { | 166 | struct sockaddr_in sin = { |
167 | .sin_family = AF_INET, | 167 | .sin_family = AF_INET, |
168 | .sin_addr.s_addr = htonl(INADDR_ANY), | 168 | .sin_addr.s_addr = htonl(INADDR_ANY), |
169 | .sin_port = htons(port), | 169 | .sin_port = htons(port), |
170 | }; | 170 | }; |
171 | struct sockaddr_in6 sin6 = { | ||
172 | .sin6_family = AF_INET6, | ||
173 | .sin6_addr = IN6ADDR_ANY_INIT, | ||
174 | .sin6_port = htons(port), | ||
175 | }; | ||
176 | struct sockaddr *sap; | ||
177 | size_t len; | ||
178 | |||
179 | switch (serv->sv_family) { | ||
180 | case AF_INET: | ||
181 | sap = (struct sockaddr *)&sin; | ||
182 | len = sizeof(sin); | ||
183 | break; | ||
184 | case AF_INET6: | ||
185 | sap = (struct sockaddr *)&sin6; | ||
186 | len = sizeof(sin6); | ||
187 | break; | ||
188 | default: | ||
189 | return ERR_PTR(-EAFNOSUPPORT); | ||
190 | } | ||
191 | |||
192 | return xcl->xcl_ops->xpo_create(serv, sap, len, flags); | ||
193 | } | ||
194 | |||
195 | int svc_create_xprt(struct svc_serv *serv, char *xprt_name, unsigned short port, | ||
196 | int flags) | ||
197 | { | ||
198 | struct svc_xprt_class *xcl; | ||
199 | |||
171 | dprintk("svc: creating transport %s[%d]\n", xprt_name, port); | 200 | dprintk("svc: creating transport %s[%d]\n", xprt_name, port); |
172 | spin_lock(&svc_xprt_class_lock); | 201 | spin_lock(&svc_xprt_class_lock); |
173 | list_for_each_entry(xcl, &svc_xprt_class_list, xcl_list) { | 202 | list_for_each_entry(xcl, &svc_xprt_class_list, xcl_list) { |
@@ -180,9 +209,7 @@ int svc_create_xprt(struct svc_serv *serv, char *xprt_name, unsigned short port, | |||
180 | goto err; | 209 | goto err; |
181 | 210 | ||
182 | spin_unlock(&svc_xprt_class_lock); | 211 | spin_unlock(&svc_xprt_class_lock); |
183 | newxprt = xcl->xcl_ops-> | 212 | newxprt = __svc_xpo_create(xcl, serv, port, flags); |
184 | xpo_create(serv, (struct sockaddr *)&sin, sizeof(sin), | ||
185 | flags); | ||
186 | if (IS_ERR(newxprt)) { | 213 | if (IS_ERR(newxprt)) { |
187 | module_put(xcl->xcl_owner); | 214 | module_put(xcl->xcl_owner); |
188 | return PTR_ERR(newxprt); | 215 | return PTR_ERR(newxprt); |
diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c index 3e65719f1ef6..95293f549e9c 100644 --- a/net/sunrpc/svcsock.c +++ b/net/sunrpc/svcsock.c | |||
@@ -1114,6 +1114,7 @@ static struct svc_sock *svc_setup_socket(struct svc_serv *serv, | |||
1114 | struct svc_sock *svsk; | 1114 | struct svc_sock *svsk; |
1115 | struct sock *inet; | 1115 | struct sock *inet; |
1116 | int pmap_register = !(flags & SVC_SOCK_ANONYMOUS); | 1116 | int pmap_register = !(flags & SVC_SOCK_ANONYMOUS); |
1117 | int val; | ||
1117 | 1118 | ||
1118 | dprintk("svc: svc_setup_socket %p\n", sock); | 1119 | dprintk("svc: svc_setup_socket %p\n", sock); |
1119 | if (!(svsk = kzalloc(sizeof(*svsk), GFP_KERNEL))) { | 1120 | if (!(svsk = kzalloc(sizeof(*svsk), GFP_KERNEL))) { |
@@ -1146,6 +1147,18 @@ static struct svc_sock *svc_setup_socket(struct svc_serv *serv, | |||
1146 | else | 1147 | else |
1147 | svc_tcp_init(svsk, serv); | 1148 | svc_tcp_init(svsk, serv); |
1148 | 1149 | ||
1150 | /* | ||
1151 | * We start one listener per sv_serv. We want AF_INET | ||
1152 | * requests to be automatically shunted to our AF_INET6 | ||
1153 | * listener using a mapped IPv4 address. Make sure | ||
1154 | * no-one starts an equivalent IPv4 listener, which | ||
1155 | * would steal our incoming connections. | ||
1156 | */ | ||
1157 | val = 0; | ||
1158 | if (serv->sv_family == AF_INET6) | ||
1159 | kernel_setsockopt(sock, SOL_IPV6, IPV6_V6ONLY, | ||
1160 | (char *)&val, sizeof(val)); | ||
1161 | |||
1149 | dprintk("svc: svc_setup_socket created %p (inet %p)\n", | 1162 | dprintk("svc: svc_setup_socket created %p (inet %p)\n", |
1150 | svsk, svsk->sk_sk); | 1163 | svsk, svsk->sk_sk); |
1151 | 1164 | ||
@@ -1154,8 +1167,7 @@ static struct svc_sock *svc_setup_socket(struct svc_serv *serv, | |||
1154 | 1167 | ||
1155 | int svc_addsock(struct svc_serv *serv, | 1168 | int svc_addsock(struct svc_serv *serv, |
1156 | int fd, | 1169 | int fd, |
1157 | char *name_return, | 1170 | char *name_return) |
1158 | int *proto) | ||
1159 | { | 1171 | { |
1160 | int err = 0; | 1172 | int err = 0; |
1161 | struct socket *so = sockfd_lookup(fd, &err); | 1173 | struct socket *so = sockfd_lookup(fd, &err); |
@@ -1190,7 +1202,6 @@ int svc_addsock(struct svc_serv *serv, | |||
1190 | sockfd_put(so); | 1202 | sockfd_put(so); |
1191 | return err; | 1203 | return err; |
1192 | } | 1204 | } |
1193 | if (proto) *proto = so->sk->sk_protocol; | ||
1194 | return one_sock_name(name_return, svsk); | 1205 | return one_sock_name(name_return, svsk); |
1195 | } | 1206 | } |
1196 | EXPORT_SYMBOL_GPL(svc_addsock); | 1207 | EXPORT_SYMBOL_GPL(svc_addsock); |
diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c index 74de31a06616..a4756576d687 100644 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c | |||
@@ -116,7 +116,7 @@ static void rdma_build_arg_xdr(struct svc_rqst *rqstp, | |||
116 | * | 116 | * |
117 | * Assumptions: | 117 | * Assumptions: |
118 | * - chunk[0]->position points to pages[0] at an offset of 0 | 118 | * - chunk[0]->position points to pages[0] at an offset of 0 |
119 | * - pages[] is not physically or virtually contigous and consists of | 119 | * - pages[] is not physically or virtually contiguous and consists of |
120 | * PAGE_SIZE elements. | 120 | * PAGE_SIZE elements. |
121 | * | 121 | * |
122 | * Output: | 122 | * Output: |
@@ -125,7 +125,7 @@ static void rdma_build_arg_xdr(struct svc_rqst *rqstp, | |||
125 | * chunk in the read list | 125 | * chunk in the read list |
126 | * | 126 | * |
127 | */ | 127 | */ |
128 | static int rdma_rcl_to_sge(struct svcxprt_rdma *xprt, | 128 | static int map_read_chunks(struct svcxprt_rdma *xprt, |
129 | struct svc_rqst *rqstp, | 129 | struct svc_rqst *rqstp, |
130 | struct svc_rdma_op_ctxt *head, | 130 | struct svc_rdma_op_ctxt *head, |
131 | struct rpcrdma_msg *rmsgp, | 131 | struct rpcrdma_msg *rmsgp, |
@@ -211,26 +211,128 @@ static int rdma_rcl_to_sge(struct svcxprt_rdma *xprt, | |||
211 | return sge_no; | 211 | return sge_no; |
212 | } | 212 | } |
213 | 213 | ||
214 | static void rdma_set_ctxt_sge(struct svcxprt_rdma *xprt, | 214 | /* Map a read-chunk-list to an XDR and fast register the page-list. |
215 | struct svc_rdma_op_ctxt *ctxt, | 215 | * |
216 | struct kvec *vec, | 216 | * Assumptions: |
217 | u64 *sgl_offset, | 217 | * - chunk[0] position points to pages[0] at an offset of 0 |
218 | int count) | 218 | * - pages[] will be made physically contiguous by creating a one-off memory |
219 | * region using the fastreg verb. | ||
220 | * - byte_count is # of bytes in read-chunk-list | ||
221 | * - ch_count is # of chunks in read-chunk-list | ||
222 | * | ||
223 | * Output: | ||
224 | * - sge array pointing into pages[] array. | ||
225 | * - chunk_sge array specifying sge index and count for each | ||
226 | * chunk in the read list | ||
227 | */ | ||
228 | static int fast_reg_read_chunks(struct svcxprt_rdma *xprt, | ||
229 | struct svc_rqst *rqstp, | ||
230 | struct svc_rdma_op_ctxt *head, | ||
231 | struct rpcrdma_msg *rmsgp, | ||
232 | struct svc_rdma_req_map *rpl_map, | ||
233 | struct svc_rdma_req_map *chl_map, | ||
234 | int ch_count, | ||
235 | int byte_count) | ||
236 | { | ||
237 | int page_no; | ||
238 | int ch_no; | ||
239 | u32 offset; | ||
240 | struct rpcrdma_read_chunk *ch; | ||
241 | struct svc_rdma_fastreg_mr *frmr; | ||
242 | int ret = 0; | ||
243 | |||
244 | frmr = svc_rdma_get_frmr(xprt); | ||
245 | if (IS_ERR(frmr)) | ||
246 | return -ENOMEM; | ||
247 | |||
248 | head->frmr = frmr; | ||
249 | head->arg.head[0] = rqstp->rq_arg.head[0]; | ||
250 | head->arg.tail[0] = rqstp->rq_arg.tail[0]; | ||
251 | head->arg.pages = &head->pages[head->count]; | ||
252 | head->hdr_count = head->count; /* save count of hdr pages */ | ||
253 | head->arg.page_base = 0; | ||
254 | head->arg.page_len = byte_count; | ||
255 | head->arg.len = rqstp->rq_arg.len + byte_count; | ||
256 | head->arg.buflen = rqstp->rq_arg.buflen + byte_count; | ||
257 | |||
258 | /* Fast register the page list */ | ||
259 | frmr->kva = page_address(rqstp->rq_arg.pages[0]); | ||
260 | frmr->direction = DMA_FROM_DEVICE; | ||
261 | frmr->access_flags = (IB_ACCESS_LOCAL_WRITE|IB_ACCESS_REMOTE_WRITE); | ||
262 | frmr->map_len = byte_count; | ||
263 | frmr->page_list_len = PAGE_ALIGN(byte_count) >> PAGE_SHIFT; | ||
264 | for (page_no = 0; page_no < frmr->page_list_len; page_no++) { | ||
265 | frmr->page_list->page_list[page_no] = | ||
266 | ib_dma_map_single(xprt->sc_cm_id->device, | ||
267 | page_address(rqstp->rq_arg.pages[page_no]), | ||
268 | PAGE_SIZE, DMA_TO_DEVICE); | ||
269 | if (ib_dma_mapping_error(xprt->sc_cm_id->device, | ||
270 | frmr->page_list->page_list[page_no])) | ||
271 | goto fatal_err; | ||
272 | atomic_inc(&xprt->sc_dma_used); | ||
273 | head->arg.pages[page_no] = rqstp->rq_arg.pages[page_no]; | ||
274 | } | ||
275 | head->count += page_no; | ||
276 | |||
277 | /* rq_respages points one past arg pages */ | ||
278 | rqstp->rq_respages = &rqstp->rq_arg.pages[page_no]; | ||
279 | |||
280 | /* Create the reply and chunk maps */ | ||
281 | offset = 0; | ||
282 | ch = (struct rpcrdma_read_chunk *)&rmsgp->rm_body.rm_chunks[0]; | ||
283 | for (ch_no = 0; ch_no < ch_count; ch_no++) { | ||
284 | rpl_map->sge[ch_no].iov_base = frmr->kva + offset; | ||
285 | rpl_map->sge[ch_no].iov_len = ch->rc_target.rs_length; | ||
286 | chl_map->ch[ch_no].count = 1; | ||
287 | chl_map->ch[ch_no].start = ch_no; | ||
288 | offset += ch->rc_target.rs_length; | ||
289 | ch++; | ||
290 | } | ||
291 | |||
292 | ret = svc_rdma_fastreg(xprt, frmr); | ||
293 | if (ret) | ||
294 | goto fatal_err; | ||
295 | |||
296 | return ch_no; | ||
297 | |||
298 | fatal_err: | ||
299 | printk("svcrdma: error fast registering xdr for xprt %p", xprt); | ||
300 | svc_rdma_put_frmr(xprt, frmr); | ||
301 | return -EIO; | ||
302 | } | ||
303 | |||
304 | static int rdma_set_ctxt_sge(struct svcxprt_rdma *xprt, | ||
305 | struct svc_rdma_op_ctxt *ctxt, | ||
306 | struct svc_rdma_fastreg_mr *frmr, | ||
307 | struct kvec *vec, | ||
308 | u64 *sgl_offset, | ||
309 | int count) | ||
219 | { | 310 | { |
220 | int i; | 311 | int i; |
221 | 312 | ||
222 | ctxt->count = count; | 313 | ctxt->count = count; |
223 | ctxt->direction = DMA_FROM_DEVICE; | 314 | ctxt->direction = DMA_FROM_DEVICE; |
224 | for (i = 0; i < count; i++) { | 315 | for (i = 0; i < count; i++) { |
225 | atomic_inc(&xprt->sc_dma_used); | 316 | ctxt->sge[i].length = 0; /* in case map fails */ |
226 | ctxt->sge[i].addr = | 317 | if (!frmr) { |
227 | ib_dma_map_single(xprt->sc_cm_id->device, | 318 | ctxt->sge[i].addr = |
228 | vec[i].iov_base, vec[i].iov_len, | 319 | ib_dma_map_single(xprt->sc_cm_id->device, |
229 | DMA_FROM_DEVICE); | 320 | vec[i].iov_base, |
321 | vec[i].iov_len, | ||
322 | DMA_FROM_DEVICE); | ||
323 | if (ib_dma_mapping_error(xprt->sc_cm_id->device, | ||
324 | ctxt->sge[i].addr)) | ||
325 | return -EINVAL; | ||
326 | ctxt->sge[i].lkey = xprt->sc_dma_lkey; | ||
327 | atomic_inc(&xprt->sc_dma_used); | ||
328 | } else { | ||
329 | ctxt->sge[i].addr = (unsigned long)vec[i].iov_base; | ||
330 | ctxt->sge[i].lkey = frmr->mr->lkey; | ||
331 | } | ||
230 | ctxt->sge[i].length = vec[i].iov_len; | 332 | ctxt->sge[i].length = vec[i].iov_len; |
231 | ctxt->sge[i].lkey = xprt->sc_phys_mr->lkey; | ||
232 | *sgl_offset = *sgl_offset + vec[i].iov_len; | 333 | *sgl_offset = *sgl_offset + vec[i].iov_len; |
233 | } | 334 | } |
335 | return 0; | ||
234 | } | 336 | } |
235 | 337 | ||
236 | static int rdma_read_max_sge(struct svcxprt_rdma *xprt, int sge_count) | 338 | static int rdma_read_max_sge(struct svcxprt_rdma *xprt, int sge_count) |
@@ -278,6 +380,7 @@ static int rdma_read_xdr(struct svcxprt_rdma *xprt, | |||
278 | struct svc_rdma_op_ctxt *hdr_ctxt) | 380 | struct svc_rdma_op_ctxt *hdr_ctxt) |
279 | { | 381 | { |
280 | struct ib_send_wr read_wr; | 382 | struct ib_send_wr read_wr; |
383 | struct ib_send_wr inv_wr; | ||
281 | int err = 0; | 384 | int err = 0; |
282 | int ch_no; | 385 | int ch_no; |
283 | int ch_count; | 386 | int ch_count; |
@@ -301,9 +404,20 @@ static int rdma_read_xdr(struct svcxprt_rdma *xprt, | |||
301 | svc_rdma_rcl_chunk_counts(ch, &ch_count, &byte_count); | 404 | svc_rdma_rcl_chunk_counts(ch, &ch_count, &byte_count); |
302 | if (ch_count > RPCSVC_MAXPAGES) | 405 | if (ch_count > RPCSVC_MAXPAGES) |
303 | return -EINVAL; | 406 | return -EINVAL; |
304 | sge_count = rdma_rcl_to_sge(xprt, rqstp, hdr_ctxt, rmsgp, | 407 | |
305 | rpl_map, chl_map, | 408 | if (!xprt->sc_frmr_pg_list_len) |
306 | ch_count, byte_count); | 409 | sge_count = map_read_chunks(xprt, rqstp, hdr_ctxt, rmsgp, |
410 | rpl_map, chl_map, ch_count, | ||
411 | byte_count); | ||
412 | else | ||
413 | sge_count = fast_reg_read_chunks(xprt, rqstp, hdr_ctxt, rmsgp, | ||
414 | rpl_map, chl_map, ch_count, | ||
415 | byte_count); | ||
416 | if (sge_count < 0) { | ||
417 | err = -EIO; | ||
418 | goto out; | ||
419 | } | ||
420 | |||
307 | sgl_offset = 0; | 421 | sgl_offset = 0; |
308 | ch_no = 0; | 422 | ch_no = 0; |
309 | 423 | ||
@@ -312,13 +426,16 @@ static int rdma_read_xdr(struct svcxprt_rdma *xprt, | |||
312 | next_sge: | 426 | next_sge: |
313 | ctxt = svc_rdma_get_context(xprt); | 427 | ctxt = svc_rdma_get_context(xprt); |
314 | ctxt->direction = DMA_FROM_DEVICE; | 428 | ctxt->direction = DMA_FROM_DEVICE; |
429 | ctxt->frmr = hdr_ctxt->frmr; | ||
430 | ctxt->read_hdr = NULL; | ||
315 | clear_bit(RDMACTXT_F_LAST_CTXT, &ctxt->flags); | 431 | clear_bit(RDMACTXT_F_LAST_CTXT, &ctxt->flags); |
432 | clear_bit(RDMACTXT_F_FAST_UNREG, &ctxt->flags); | ||
316 | 433 | ||
317 | /* Prepare READ WR */ | 434 | /* Prepare READ WR */ |
318 | memset(&read_wr, 0, sizeof read_wr); | 435 | memset(&read_wr, 0, sizeof read_wr); |
319 | ctxt->wr_op = IB_WR_RDMA_READ; | ||
320 | read_wr.wr_id = (unsigned long)ctxt; | 436 | read_wr.wr_id = (unsigned long)ctxt; |
321 | read_wr.opcode = IB_WR_RDMA_READ; | 437 | read_wr.opcode = IB_WR_RDMA_READ; |
438 | ctxt->wr_op = read_wr.opcode; | ||
322 | read_wr.send_flags = IB_SEND_SIGNALED; | 439 | read_wr.send_flags = IB_SEND_SIGNALED; |
323 | read_wr.wr.rdma.rkey = ch->rc_target.rs_handle; | 440 | read_wr.wr.rdma.rkey = ch->rc_target.rs_handle; |
324 | read_wr.wr.rdma.remote_addr = | 441 | read_wr.wr.rdma.remote_addr = |
@@ -327,10 +444,15 @@ next_sge: | |||
327 | read_wr.sg_list = ctxt->sge; | 444 | read_wr.sg_list = ctxt->sge; |
328 | read_wr.num_sge = | 445 | read_wr.num_sge = |
329 | rdma_read_max_sge(xprt, chl_map->ch[ch_no].count); | 446 | rdma_read_max_sge(xprt, chl_map->ch[ch_no].count); |
330 | rdma_set_ctxt_sge(xprt, ctxt, | 447 | err = rdma_set_ctxt_sge(xprt, ctxt, hdr_ctxt->frmr, |
331 | &rpl_map->sge[chl_map->ch[ch_no].start], | 448 | &rpl_map->sge[chl_map->ch[ch_no].start], |
332 | &sgl_offset, | 449 | &sgl_offset, |
333 | read_wr.num_sge); | 450 | read_wr.num_sge); |
451 | if (err) { | ||
452 | svc_rdma_unmap_dma(ctxt); | ||
453 | svc_rdma_put_context(ctxt, 0); | ||
454 | goto out; | ||
455 | } | ||
334 | if (((ch+1)->rc_discrim == 0) && | 456 | if (((ch+1)->rc_discrim == 0) && |
335 | (read_wr.num_sge == chl_map->ch[ch_no].count)) { | 457 | (read_wr.num_sge == chl_map->ch[ch_no].count)) { |
336 | /* | 458 | /* |
@@ -339,6 +461,29 @@ next_sge: | |||
339 | * the client and the RPC needs to be enqueued. | 461 | * the client and the RPC needs to be enqueued. |
340 | */ | 462 | */ |
341 | set_bit(RDMACTXT_F_LAST_CTXT, &ctxt->flags); | 463 | set_bit(RDMACTXT_F_LAST_CTXT, &ctxt->flags); |
464 | if (hdr_ctxt->frmr) { | ||
465 | set_bit(RDMACTXT_F_FAST_UNREG, &ctxt->flags); | ||
466 | /* | ||
467 | * Invalidate the local MR used to map the data | ||
468 | * sink. | ||
469 | */ | ||
470 | if (xprt->sc_dev_caps & | ||
471 | SVCRDMA_DEVCAP_READ_W_INV) { | ||
472 | read_wr.opcode = | ||
473 | IB_WR_RDMA_READ_WITH_INV; | ||
474 | ctxt->wr_op = read_wr.opcode; | ||
475 | read_wr.ex.invalidate_rkey = | ||
476 | ctxt->frmr->mr->lkey; | ||
477 | } else { | ||
478 | /* Prepare INVALIDATE WR */ | ||
479 | memset(&inv_wr, 0, sizeof inv_wr); | ||
480 | inv_wr.opcode = IB_WR_LOCAL_INV; | ||
481 | inv_wr.send_flags = IB_SEND_SIGNALED; | ||
482 | inv_wr.ex.invalidate_rkey = | ||
483 | hdr_ctxt->frmr->mr->lkey; | ||
484 | read_wr.next = &inv_wr; | ||
485 | } | ||
486 | } | ||
342 | ctxt->read_hdr = hdr_ctxt; | 487 | ctxt->read_hdr = hdr_ctxt; |
343 | } | 488 | } |
344 | /* Post the read */ | 489 | /* Post the read */ |
diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c index 84d328329d98..9a7a8e7ae038 100644 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c | |||
@@ -69,9 +69,127 @@ | |||
69 | * array is only concerned with the reply we are assured that we have | 69 | * array is only concerned with the reply we are assured that we have |
70 | * on extra page for the RPCRMDA header. | 70 | * on extra page for the RPCRMDA header. |
71 | */ | 71 | */ |
72 | static void xdr_to_sge(struct svcxprt_rdma *xprt, | 72 | int fast_reg_xdr(struct svcxprt_rdma *xprt, |
73 | struct xdr_buf *xdr, | 73 | struct xdr_buf *xdr, |
74 | struct svc_rdma_req_map *vec) | 74 | struct svc_rdma_req_map *vec) |
75 | { | ||
76 | int sge_no; | ||
77 | u32 sge_bytes; | ||
78 | u32 page_bytes; | ||
79 | u32 page_off; | ||
80 | int page_no = 0; | ||
81 | u8 *frva; | ||
82 | struct svc_rdma_fastreg_mr *frmr; | ||
83 | |||
84 | frmr = svc_rdma_get_frmr(xprt); | ||
85 | if (IS_ERR(frmr)) | ||
86 | return -ENOMEM; | ||
87 | vec->frmr = frmr; | ||
88 | |||
89 | /* Skip the RPCRDMA header */ | ||
90 | sge_no = 1; | ||
91 | |||
92 | /* Map the head. */ | ||
93 | frva = (void *)((unsigned long)(xdr->head[0].iov_base) & PAGE_MASK); | ||
94 | vec->sge[sge_no].iov_base = xdr->head[0].iov_base; | ||
95 | vec->sge[sge_no].iov_len = xdr->head[0].iov_len; | ||
96 | vec->count = 2; | ||
97 | sge_no++; | ||
98 | |||
99 | /* Build the FRMR */ | ||
100 | frmr->kva = frva; | ||
101 | frmr->direction = DMA_TO_DEVICE; | ||
102 | frmr->access_flags = 0; | ||
103 | frmr->map_len = PAGE_SIZE; | ||
104 | frmr->page_list_len = 1; | ||
105 | frmr->page_list->page_list[page_no] = | ||
106 | ib_dma_map_single(xprt->sc_cm_id->device, | ||
107 | (void *)xdr->head[0].iov_base, | ||
108 | PAGE_SIZE, DMA_TO_DEVICE); | ||
109 | if (ib_dma_mapping_error(xprt->sc_cm_id->device, | ||
110 | frmr->page_list->page_list[page_no])) | ||
111 | goto fatal_err; | ||
112 | atomic_inc(&xprt->sc_dma_used); | ||
113 | |||
114 | page_off = xdr->page_base; | ||
115 | page_bytes = xdr->page_len + page_off; | ||
116 | if (!page_bytes) | ||
117 | goto encode_tail; | ||
118 | |||
119 | /* Map the pages */ | ||
120 | vec->sge[sge_no].iov_base = frva + frmr->map_len + page_off; | ||
121 | vec->sge[sge_no].iov_len = page_bytes; | ||
122 | sge_no++; | ||
123 | while (page_bytes) { | ||
124 | struct page *page; | ||
125 | |||
126 | page = xdr->pages[page_no++]; | ||
127 | sge_bytes = min_t(u32, page_bytes, (PAGE_SIZE - page_off)); | ||
128 | page_bytes -= sge_bytes; | ||
129 | |||
130 | frmr->page_list->page_list[page_no] = | ||
131 | ib_dma_map_page(xprt->sc_cm_id->device, page, 0, | ||
132 | PAGE_SIZE, DMA_TO_DEVICE); | ||
133 | if (ib_dma_mapping_error(xprt->sc_cm_id->device, | ||
134 | frmr->page_list->page_list[page_no])) | ||
135 | goto fatal_err; | ||
136 | |||
137 | atomic_inc(&xprt->sc_dma_used); | ||
138 | page_off = 0; /* reset for next time through loop */ | ||
139 | frmr->map_len += PAGE_SIZE; | ||
140 | frmr->page_list_len++; | ||
141 | } | ||
142 | vec->count++; | ||
143 | |||
144 | encode_tail: | ||
145 | /* Map tail */ | ||
146 | if (0 == xdr->tail[0].iov_len) | ||
147 | goto done; | ||
148 | |||
149 | vec->count++; | ||
150 | vec->sge[sge_no].iov_len = xdr->tail[0].iov_len; | ||
151 | |||
152 | if (((unsigned long)xdr->tail[0].iov_base & PAGE_MASK) == | ||
153 | ((unsigned long)xdr->head[0].iov_base & PAGE_MASK)) { | ||
154 | /* | ||
155 | * If head and tail use the same page, we don't need | ||
156 | * to map it again. | ||
157 | */ | ||
158 | vec->sge[sge_no].iov_base = xdr->tail[0].iov_base; | ||
159 | } else { | ||
160 | void *va; | ||
161 | |||
162 | /* Map another page for the tail */ | ||
163 | page_off = (unsigned long)xdr->tail[0].iov_base & ~PAGE_MASK; | ||
164 | va = (void *)((unsigned long)xdr->tail[0].iov_base & PAGE_MASK); | ||
165 | vec->sge[sge_no].iov_base = frva + frmr->map_len + page_off; | ||
166 | |||
167 | frmr->page_list->page_list[page_no] = | ||
168 | ib_dma_map_single(xprt->sc_cm_id->device, va, PAGE_SIZE, | ||
169 | DMA_TO_DEVICE); | ||
170 | if (ib_dma_mapping_error(xprt->sc_cm_id->device, | ||
171 | frmr->page_list->page_list[page_no])) | ||
172 | goto fatal_err; | ||
173 | atomic_inc(&xprt->sc_dma_used); | ||
174 | frmr->map_len += PAGE_SIZE; | ||
175 | frmr->page_list_len++; | ||
176 | } | ||
177 | |||
178 | done: | ||
179 | if (svc_rdma_fastreg(xprt, frmr)) | ||
180 | goto fatal_err; | ||
181 | |||
182 | return 0; | ||
183 | |||
184 | fatal_err: | ||
185 | printk("svcrdma: Error fast registering memory for xprt %p\n", xprt); | ||
186 | svc_rdma_put_frmr(xprt, frmr); | ||
187 | return -EIO; | ||
188 | } | ||
189 | |||
190 | static int map_xdr(struct svcxprt_rdma *xprt, | ||
191 | struct xdr_buf *xdr, | ||
192 | struct svc_rdma_req_map *vec) | ||
75 | { | 193 | { |
76 | int sge_max = (xdr->len+PAGE_SIZE-1) / PAGE_SIZE + 3; | 194 | int sge_max = (xdr->len+PAGE_SIZE-1) / PAGE_SIZE + 3; |
77 | int sge_no; | 195 | int sge_no; |
@@ -83,6 +201,9 @@ static void xdr_to_sge(struct svcxprt_rdma *xprt, | |||
83 | BUG_ON(xdr->len != | 201 | BUG_ON(xdr->len != |
84 | (xdr->head[0].iov_len + xdr->page_len + xdr->tail[0].iov_len)); | 202 | (xdr->head[0].iov_len + xdr->page_len + xdr->tail[0].iov_len)); |
85 | 203 | ||
204 | if (xprt->sc_frmr_pg_list_len) | ||
205 | return fast_reg_xdr(xprt, xdr, vec); | ||
206 | |||
86 | /* Skip the first sge, this is for the RPCRDMA header */ | 207 | /* Skip the first sge, this is for the RPCRDMA header */ |
87 | sge_no = 1; | 208 | sge_no = 1; |
88 | 209 | ||
@@ -116,9 +237,12 @@ static void xdr_to_sge(struct svcxprt_rdma *xprt, | |||
116 | 237 | ||
117 | BUG_ON(sge_no > sge_max); | 238 | BUG_ON(sge_no > sge_max); |
118 | vec->count = sge_no; | 239 | vec->count = sge_no; |
240 | return 0; | ||
119 | } | 241 | } |
120 | 242 | ||
121 | /* Assumptions: | 243 | /* Assumptions: |
244 | * - We are using FRMR | ||
245 | * - or - | ||
122 | * - The specified write_len can be represented in sc_max_sge * PAGE_SIZE | 246 | * - The specified write_len can be represented in sc_max_sge * PAGE_SIZE |
123 | */ | 247 | */ |
124 | static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp, | 248 | static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp, |
@@ -158,30 +282,35 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp, | |||
158 | sge_no = 0; | 282 | sge_no = 0; |
159 | 283 | ||
160 | /* Copy the remaining SGE */ | 284 | /* Copy the remaining SGE */ |
161 | while (bc != 0 && xdr_sge_no < vec->count) { | 285 | while (bc != 0) { |
162 | sge[sge_no].lkey = xprt->sc_phys_mr->lkey; | 286 | sge_bytes = min_t(size_t, |
163 | sge_bytes = min((size_t)bc, | 287 | bc, vec->sge[xdr_sge_no].iov_len-sge_off); |
164 | (size_t)(vec->sge[xdr_sge_no].iov_len-sge_off)); | ||
165 | sge[sge_no].length = sge_bytes; | 288 | sge[sge_no].length = sge_bytes; |
166 | atomic_inc(&xprt->sc_dma_used); | 289 | if (!vec->frmr) { |
167 | sge[sge_no].addr = | 290 | sge[sge_no].addr = |
168 | ib_dma_map_single(xprt->sc_cm_id->device, | 291 | ib_dma_map_single(xprt->sc_cm_id->device, |
169 | (void *) | 292 | (void *) |
170 | vec->sge[xdr_sge_no].iov_base + sge_off, | 293 | vec->sge[xdr_sge_no].iov_base + sge_off, |
171 | sge_bytes, DMA_TO_DEVICE); | 294 | sge_bytes, DMA_TO_DEVICE); |
172 | if (dma_mapping_error(xprt->sc_cm_id->device->dma_device, | 295 | if (ib_dma_mapping_error(xprt->sc_cm_id->device, |
173 | sge[sge_no].addr)) | 296 | sge[sge_no].addr)) |
174 | goto err; | 297 | goto err; |
298 | atomic_inc(&xprt->sc_dma_used); | ||
299 | sge[sge_no].lkey = xprt->sc_dma_lkey; | ||
300 | } else { | ||
301 | sge[sge_no].addr = (unsigned long) | ||
302 | vec->sge[xdr_sge_no].iov_base + sge_off; | ||
303 | sge[sge_no].lkey = vec->frmr->mr->lkey; | ||
304 | } | ||
305 | ctxt->count++; | ||
306 | ctxt->frmr = vec->frmr; | ||
175 | sge_off = 0; | 307 | sge_off = 0; |
176 | sge_no++; | 308 | sge_no++; |
177 | ctxt->count++; | ||
178 | xdr_sge_no++; | 309 | xdr_sge_no++; |
310 | BUG_ON(xdr_sge_no > vec->count); | ||
179 | bc -= sge_bytes; | 311 | bc -= sge_bytes; |
180 | } | 312 | } |
181 | 313 | ||
182 | BUG_ON(bc != 0); | ||
183 | BUG_ON(xdr_sge_no > vec->count); | ||
184 | |||
185 | /* Prepare WRITE WR */ | 314 | /* Prepare WRITE WR */ |
186 | memset(&write_wr, 0, sizeof write_wr); | 315 | memset(&write_wr, 0, sizeof write_wr); |
187 | ctxt->wr_op = IB_WR_RDMA_WRITE; | 316 | ctxt->wr_op = IB_WR_RDMA_WRITE; |
@@ -226,7 +355,10 @@ static int send_write_chunks(struct svcxprt_rdma *xprt, | |||
226 | res_ary = (struct rpcrdma_write_array *) | 355 | res_ary = (struct rpcrdma_write_array *) |
227 | &rdma_resp->rm_body.rm_chunks[1]; | 356 | &rdma_resp->rm_body.rm_chunks[1]; |
228 | 357 | ||
229 | max_write = xprt->sc_max_sge * PAGE_SIZE; | 358 | if (vec->frmr) |
359 | max_write = vec->frmr->map_len; | ||
360 | else | ||
361 | max_write = xprt->sc_max_sge * PAGE_SIZE; | ||
230 | 362 | ||
231 | /* Write chunks start at the pagelist */ | 363 | /* Write chunks start at the pagelist */ |
232 | for (xdr_off = rqstp->rq_res.head[0].iov_len, chunk_no = 0; | 364 | for (xdr_off = rqstp->rq_res.head[0].iov_len, chunk_no = 0; |
@@ -297,7 +429,10 @@ static int send_reply_chunks(struct svcxprt_rdma *xprt, | |||
297 | res_ary = (struct rpcrdma_write_array *) | 429 | res_ary = (struct rpcrdma_write_array *) |
298 | &rdma_resp->rm_body.rm_chunks[2]; | 430 | &rdma_resp->rm_body.rm_chunks[2]; |
299 | 431 | ||
300 | max_write = xprt->sc_max_sge * PAGE_SIZE; | 432 | if (vec->frmr) |
433 | max_write = vec->frmr->map_len; | ||
434 | else | ||
435 | max_write = xprt->sc_max_sge * PAGE_SIZE; | ||
301 | 436 | ||
302 | /* xdr offset starts at RPC message */ | 437 | /* xdr offset starts at RPC message */ |
303 | for (xdr_off = 0, chunk_no = 0; | 438 | for (xdr_off = 0, chunk_no = 0; |
@@ -307,7 +442,6 @@ static int send_reply_chunks(struct svcxprt_rdma *xprt, | |||
307 | ch = &arg_ary->wc_array[chunk_no].wc_target; | 442 | ch = &arg_ary->wc_array[chunk_no].wc_target; |
308 | write_len = min(xfer_len, ch->rs_length); | 443 | write_len = min(xfer_len, ch->rs_length); |
309 | 444 | ||
310 | |||
311 | /* Prepare the reply chunk given the length actually | 445 | /* Prepare the reply chunk given the length actually |
312 | * written */ | 446 | * written */ |
313 | rs_offset = get_unaligned(&(ch->rs_offset)); | 447 | rs_offset = get_unaligned(&(ch->rs_offset)); |
@@ -366,6 +500,7 @@ static int send_reply(struct svcxprt_rdma *rdma, | |||
366 | int byte_count) | 500 | int byte_count) |
367 | { | 501 | { |
368 | struct ib_send_wr send_wr; | 502 | struct ib_send_wr send_wr; |
503 | struct ib_send_wr inv_wr; | ||
369 | int sge_no; | 504 | int sge_no; |
370 | int sge_bytes; | 505 | int sge_bytes; |
371 | int page_no; | 506 | int page_no; |
@@ -385,27 +520,45 @@ static int send_reply(struct svcxprt_rdma *rdma, | |||
385 | /* Prepare the context */ | 520 | /* Prepare the context */ |
386 | ctxt->pages[0] = page; | 521 | ctxt->pages[0] = page; |
387 | ctxt->count = 1; | 522 | ctxt->count = 1; |
523 | ctxt->frmr = vec->frmr; | ||
524 | if (vec->frmr) | ||
525 | set_bit(RDMACTXT_F_FAST_UNREG, &ctxt->flags); | ||
526 | else | ||
527 | clear_bit(RDMACTXT_F_FAST_UNREG, &ctxt->flags); | ||
388 | 528 | ||
389 | /* Prepare the SGE for the RPCRDMA Header */ | 529 | /* Prepare the SGE for the RPCRDMA Header */ |
390 | atomic_inc(&rdma->sc_dma_used); | ||
391 | ctxt->sge[0].addr = | 530 | ctxt->sge[0].addr = |
392 | ib_dma_map_page(rdma->sc_cm_id->device, | 531 | ib_dma_map_page(rdma->sc_cm_id->device, |
393 | page, 0, PAGE_SIZE, DMA_TO_DEVICE); | 532 | page, 0, PAGE_SIZE, DMA_TO_DEVICE); |
533 | if (ib_dma_mapping_error(rdma->sc_cm_id->device, ctxt->sge[0].addr)) | ||
534 | goto err; | ||
535 | atomic_inc(&rdma->sc_dma_used); | ||
536 | |||
394 | ctxt->direction = DMA_TO_DEVICE; | 537 | ctxt->direction = DMA_TO_DEVICE; |
538 | |||
395 | ctxt->sge[0].length = svc_rdma_xdr_get_reply_hdr_len(rdma_resp); | 539 | ctxt->sge[0].length = svc_rdma_xdr_get_reply_hdr_len(rdma_resp); |
396 | ctxt->sge[0].lkey = rdma->sc_phys_mr->lkey; | 540 | ctxt->sge[0].lkey = rdma->sc_dma_lkey; |
397 | 541 | ||
398 | /* Determine how many of our SGE are to be transmitted */ | 542 | /* Determine how many of our SGE are to be transmitted */ |
399 | for (sge_no = 1; byte_count && sge_no < vec->count; sge_no++) { | 543 | for (sge_no = 1; byte_count && sge_no < vec->count; sge_no++) { |
400 | sge_bytes = min_t(size_t, vec->sge[sge_no].iov_len, byte_count); | 544 | sge_bytes = min_t(size_t, vec->sge[sge_no].iov_len, byte_count); |
401 | byte_count -= sge_bytes; | 545 | byte_count -= sge_bytes; |
402 | atomic_inc(&rdma->sc_dma_used); | 546 | if (!vec->frmr) { |
403 | ctxt->sge[sge_no].addr = | 547 | ctxt->sge[sge_no].addr = |
404 | ib_dma_map_single(rdma->sc_cm_id->device, | 548 | ib_dma_map_single(rdma->sc_cm_id->device, |
405 | vec->sge[sge_no].iov_base, | 549 | vec->sge[sge_no].iov_base, |
406 | sge_bytes, DMA_TO_DEVICE); | 550 | sge_bytes, DMA_TO_DEVICE); |
551 | if (ib_dma_mapping_error(rdma->sc_cm_id->device, | ||
552 | ctxt->sge[sge_no].addr)) | ||
553 | goto err; | ||
554 | atomic_inc(&rdma->sc_dma_used); | ||
555 | ctxt->sge[sge_no].lkey = rdma->sc_dma_lkey; | ||
556 | } else { | ||
557 | ctxt->sge[sge_no].addr = (unsigned long) | ||
558 | vec->sge[sge_no].iov_base; | ||
559 | ctxt->sge[sge_no].lkey = vec->frmr->mr->lkey; | ||
560 | } | ||
407 | ctxt->sge[sge_no].length = sge_bytes; | 561 | ctxt->sge[sge_no].length = sge_bytes; |
408 | ctxt->sge[sge_no].lkey = rdma->sc_phys_mr->lkey; | ||
409 | } | 562 | } |
410 | BUG_ON(byte_count != 0); | 563 | BUG_ON(byte_count != 0); |
411 | 564 | ||
@@ -417,11 +570,16 @@ static int send_reply(struct svcxprt_rdma *rdma, | |||
417 | ctxt->pages[page_no+1] = rqstp->rq_respages[page_no]; | 570 | ctxt->pages[page_no+1] = rqstp->rq_respages[page_no]; |
418 | ctxt->count++; | 571 | ctxt->count++; |
419 | rqstp->rq_respages[page_no] = NULL; | 572 | rqstp->rq_respages[page_no] = NULL; |
420 | /* If there are more pages than SGE, terminate SGE list */ | 573 | /* |
574 | * If there are more pages than SGE, terminate SGE | ||
575 | * list so that svc_rdma_unmap_dma doesn't attempt to | ||
576 | * unmap garbage. | ||
577 | */ | ||
421 | if (page_no+1 >= sge_no) | 578 | if (page_no+1 >= sge_no) |
422 | ctxt->sge[page_no+1].length = 0; | 579 | ctxt->sge[page_no+1].length = 0; |
423 | } | 580 | } |
424 | BUG_ON(sge_no > rdma->sc_max_sge); | 581 | BUG_ON(sge_no > rdma->sc_max_sge); |
582 | BUG_ON(sge_no > ctxt->count); | ||
425 | memset(&send_wr, 0, sizeof send_wr); | 583 | memset(&send_wr, 0, sizeof send_wr); |
426 | ctxt->wr_op = IB_WR_SEND; | 584 | ctxt->wr_op = IB_WR_SEND; |
427 | send_wr.wr_id = (unsigned long)ctxt; | 585 | send_wr.wr_id = (unsigned long)ctxt; |
@@ -429,12 +587,26 @@ static int send_reply(struct svcxprt_rdma *rdma, | |||
429 | send_wr.num_sge = sge_no; | 587 | send_wr.num_sge = sge_no; |
430 | send_wr.opcode = IB_WR_SEND; | 588 | send_wr.opcode = IB_WR_SEND; |
431 | send_wr.send_flags = IB_SEND_SIGNALED; | 589 | send_wr.send_flags = IB_SEND_SIGNALED; |
590 | if (vec->frmr) { | ||
591 | /* Prepare INVALIDATE WR */ | ||
592 | memset(&inv_wr, 0, sizeof inv_wr); | ||
593 | inv_wr.opcode = IB_WR_LOCAL_INV; | ||
594 | inv_wr.send_flags = IB_SEND_SIGNALED; | ||
595 | inv_wr.ex.invalidate_rkey = | ||
596 | vec->frmr->mr->lkey; | ||
597 | send_wr.next = &inv_wr; | ||
598 | } | ||
432 | 599 | ||
433 | ret = svc_rdma_send(rdma, &send_wr); | 600 | ret = svc_rdma_send(rdma, &send_wr); |
434 | if (ret) | 601 | if (ret) |
435 | svc_rdma_put_context(ctxt, 1); | 602 | goto err; |
436 | 603 | ||
437 | return ret; | 604 | return 0; |
605 | |||
606 | err: | ||
607 | svc_rdma_put_frmr(rdma, vec->frmr); | ||
608 | svc_rdma_put_context(ctxt, 1); | ||
609 | return -EIO; | ||
438 | } | 610 | } |
439 | 611 | ||
440 | void svc_rdma_prep_reply_hdr(struct svc_rqst *rqstp) | 612 | void svc_rdma_prep_reply_hdr(struct svc_rqst *rqstp) |
@@ -477,8 +649,9 @@ int svc_rdma_sendto(struct svc_rqst *rqstp) | |||
477 | ctxt = svc_rdma_get_context(rdma); | 649 | ctxt = svc_rdma_get_context(rdma); |
478 | ctxt->direction = DMA_TO_DEVICE; | 650 | ctxt->direction = DMA_TO_DEVICE; |
479 | vec = svc_rdma_get_req_map(); | 651 | vec = svc_rdma_get_req_map(); |
480 | xdr_to_sge(rdma, &rqstp->rq_res, vec); | 652 | ret = map_xdr(rdma, &rqstp->rq_res, vec); |
481 | 653 | if (ret) | |
654 | goto err0; | ||
482 | inline_bytes = rqstp->rq_res.len; | 655 | inline_bytes = rqstp->rq_res.len; |
483 | 656 | ||
484 | /* Create the RDMA response header */ | 657 | /* Create the RDMA response header */ |
@@ -498,7 +671,7 @@ int svc_rdma_sendto(struct svc_rqst *rqstp) | |||
498 | if (ret < 0) { | 671 | if (ret < 0) { |
499 | printk(KERN_ERR "svcrdma: failed to send write chunks, rc=%d\n", | 672 | printk(KERN_ERR "svcrdma: failed to send write chunks, rc=%d\n", |
500 | ret); | 673 | ret); |
501 | goto error; | 674 | goto err1; |
502 | } | 675 | } |
503 | inline_bytes -= ret; | 676 | inline_bytes -= ret; |
504 | 677 | ||
@@ -508,7 +681,7 @@ int svc_rdma_sendto(struct svc_rqst *rqstp) | |||
508 | if (ret < 0) { | 681 | if (ret < 0) { |
509 | printk(KERN_ERR "svcrdma: failed to send reply chunks, rc=%d\n", | 682 | printk(KERN_ERR "svcrdma: failed to send reply chunks, rc=%d\n", |
510 | ret); | 683 | ret); |
511 | goto error; | 684 | goto err1; |
512 | } | 685 | } |
513 | inline_bytes -= ret; | 686 | inline_bytes -= ret; |
514 | 687 | ||
@@ -517,9 +690,11 @@ int svc_rdma_sendto(struct svc_rqst *rqstp) | |||
517 | svc_rdma_put_req_map(vec); | 690 | svc_rdma_put_req_map(vec); |
518 | dprintk("svcrdma: send_reply returns %d\n", ret); | 691 | dprintk("svcrdma: send_reply returns %d\n", ret); |
519 | return ret; | 692 | return ret; |
520 | error: | 693 | |
694 | err1: | ||
695 | put_page(res_page); | ||
696 | err0: | ||
521 | svc_rdma_put_req_map(vec); | 697 | svc_rdma_put_req_map(vec); |
522 | svc_rdma_put_context(ctxt, 0); | 698 | svc_rdma_put_context(ctxt, 0); |
523 | put_page(res_page); | ||
524 | return ret; | 699 | return ret; |
525 | } | 700 | } |
diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c index 900cb69728c6..6fb493cbd29f 100644 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c | |||
@@ -100,20 +100,29 @@ struct svc_rdma_op_ctxt *svc_rdma_get_context(struct svcxprt_rdma *xprt) | |||
100 | ctxt->xprt = xprt; | 100 | ctxt->xprt = xprt; |
101 | INIT_LIST_HEAD(&ctxt->dto_q); | 101 | INIT_LIST_HEAD(&ctxt->dto_q); |
102 | ctxt->count = 0; | 102 | ctxt->count = 0; |
103 | ctxt->frmr = NULL; | ||
103 | atomic_inc(&xprt->sc_ctxt_used); | 104 | atomic_inc(&xprt->sc_ctxt_used); |
104 | return ctxt; | 105 | return ctxt; |
105 | } | 106 | } |
106 | 107 | ||
107 | static void svc_rdma_unmap_dma(struct svc_rdma_op_ctxt *ctxt) | 108 | void svc_rdma_unmap_dma(struct svc_rdma_op_ctxt *ctxt) |
108 | { | 109 | { |
109 | struct svcxprt_rdma *xprt = ctxt->xprt; | 110 | struct svcxprt_rdma *xprt = ctxt->xprt; |
110 | int i; | 111 | int i; |
111 | for (i = 0; i < ctxt->count && ctxt->sge[i].length; i++) { | 112 | for (i = 0; i < ctxt->count && ctxt->sge[i].length; i++) { |
112 | atomic_dec(&xprt->sc_dma_used); | 113 | /* |
113 | ib_dma_unmap_single(xprt->sc_cm_id->device, | 114 | * Unmap the DMA addr in the SGE if the lkey matches |
114 | ctxt->sge[i].addr, | 115 | * the sc_dma_lkey, otherwise, ignore it since it is |
115 | ctxt->sge[i].length, | 116 | * an FRMR lkey and will be unmapped later when the |
116 | ctxt->direction); | 117 | * last WR that uses it completes. |
118 | */ | ||
119 | if (ctxt->sge[i].lkey == xprt->sc_dma_lkey) { | ||
120 | atomic_dec(&xprt->sc_dma_used); | ||
121 | ib_dma_unmap_single(xprt->sc_cm_id->device, | ||
122 | ctxt->sge[i].addr, | ||
123 | ctxt->sge[i].length, | ||
124 | ctxt->direction); | ||
125 | } | ||
117 | } | 126 | } |
118 | } | 127 | } |
119 | 128 | ||
@@ -150,6 +159,7 @@ struct svc_rdma_req_map *svc_rdma_get_req_map(void) | |||
150 | schedule_timeout_uninterruptible(msecs_to_jiffies(500)); | 159 | schedule_timeout_uninterruptible(msecs_to_jiffies(500)); |
151 | } | 160 | } |
152 | map->count = 0; | 161 | map->count = 0; |
162 | map->frmr = NULL; | ||
153 | return map; | 163 | return map; |
154 | } | 164 | } |
155 | 165 | ||
@@ -316,6 +326,50 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt) | |||
316 | } | 326 | } |
317 | 327 | ||
318 | /* | 328 | /* |
329 | * Processs a completion context | ||
330 | */ | ||
331 | static void process_context(struct svcxprt_rdma *xprt, | ||
332 | struct svc_rdma_op_ctxt *ctxt) | ||
333 | { | ||
334 | svc_rdma_unmap_dma(ctxt); | ||
335 | |||
336 | switch (ctxt->wr_op) { | ||
337 | case IB_WR_SEND: | ||
338 | if (test_bit(RDMACTXT_F_FAST_UNREG, &ctxt->flags)) | ||
339 | svc_rdma_put_frmr(xprt, ctxt->frmr); | ||
340 | svc_rdma_put_context(ctxt, 1); | ||
341 | break; | ||
342 | |||
343 | case IB_WR_RDMA_WRITE: | ||
344 | svc_rdma_put_context(ctxt, 0); | ||
345 | break; | ||
346 | |||
347 | case IB_WR_RDMA_READ: | ||
348 | case IB_WR_RDMA_READ_WITH_INV: | ||
349 | if (test_bit(RDMACTXT_F_LAST_CTXT, &ctxt->flags)) { | ||
350 | struct svc_rdma_op_ctxt *read_hdr = ctxt->read_hdr; | ||
351 | BUG_ON(!read_hdr); | ||
352 | if (test_bit(RDMACTXT_F_FAST_UNREG, &ctxt->flags)) | ||
353 | svc_rdma_put_frmr(xprt, ctxt->frmr); | ||
354 | spin_lock_bh(&xprt->sc_rq_dto_lock); | ||
355 | set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags); | ||
356 | list_add_tail(&read_hdr->dto_q, | ||
357 | &xprt->sc_read_complete_q); | ||
358 | spin_unlock_bh(&xprt->sc_rq_dto_lock); | ||
359 | svc_xprt_enqueue(&xprt->sc_xprt); | ||
360 | } | ||
361 | svc_rdma_put_context(ctxt, 0); | ||
362 | break; | ||
363 | |||
364 | default: | ||
365 | printk(KERN_ERR "svcrdma: unexpected completion type, " | ||
366 | "opcode=%d\n", | ||
367 | ctxt->wr_op); | ||
368 | break; | ||
369 | } | ||
370 | } | ||
371 | |||
372 | /* | ||
319 | * Send Queue Completion Handler - potentially called on interrupt context. | 373 | * Send Queue Completion Handler - potentially called on interrupt context. |
320 | * | 374 | * |
321 | * Note that caller must hold a transport reference. | 375 | * Note that caller must hold a transport reference. |
@@ -327,17 +381,12 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt) | |||
327 | struct ib_cq *cq = xprt->sc_sq_cq; | 381 | struct ib_cq *cq = xprt->sc_sq_cq; |
328 | int ret; | 382 | int ret; |
329 | 383 | ||
330 | |||
331 | if (!test_and_clear_bit(RDMAXPRT_SQ_PENDING, &xprt->sc_flags)) | 384 | if (!test_and_clear_bit(RDMAXPRT_SQ_PENDING, &xprt->sc_flags)) |
332 | return; | 385 | return; |
333 | 386 | ||
334 | ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP); | 387 | ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP); |
335 | atomic_inc(&rdma_stat_sq_poll); | 388 | atomic_inc(&rdma_stat_sq_poll); |
336 | while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) { | 389 | while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) { |
337 | ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id; | ||
338 | xprt = ctxt->xprt; | ||
339 | |||
340 | svc_rdma_unmap_dma(ctxt); | ||
341 | if (wc.status != IB_WC_SUCCESS) | 390 | if (wc.status != IB_WC_SUCCESS) |
342 | /* Close the transport */ | 391 | /* Close the transport */ |
343 | set_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags); | 392 | set_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags); |
@@ -346,35 +395,10 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt) | |||
346 | atomic_dec(&xprt->sc_sq_count); | 395 | atomic_dec(&xprt->sc_sq_count); |
347 | wake_up(&xprt->sc_send_wait); | 396 | wake_up(&xprt->sc_send_wait); |
348 | 397 | ||
349 | switch (ctxt->wr_op) { | 398 | ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id; |
350 | case IB_WR_SEND: | 399 | if (ctxt) |
351 | svc_rdma_put_context(ctxt, 1); | 400 | process_context(xprt, ctxt); |
352 | break; | ||
353 | |||
354 | case IB_WR_RDMA_WRITE: | ||
355 | svc_rdma_put_context(ctxt, 0); | ||
356 | break; | ||
357 | |||
358 | case IB_WR_RDMA_READ: | ||
359 | if (test_bit(RDMACTXT_F_LAST_CTXT, &ctxt->flags)) { | ||
360 | struct svc_rdma_op_ctxt *read_hdr = ctxt->read_hdr; | ||
361 | BUG_ON(!read_hdr); | ||
362 | spin_lock_bh(&xprt->sc_rq_dto_lock); | ||
363 | set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags); | ||
364 | list_add_tail(&read_hdr->dto_q, | ||
365 | &xprt->sc_read_complete_q); | ||
366 | spin_unlock_bh(&xprt->sc_rq_dto_lock); | ||
367 | svc_xprt_enqueue(&xprt->sc_xprt); | ||
368 | } | ||
369 | svc_rdma_put_context(ctxt, 0); | ||
370 | break; | ||
371 | 401 | ||
372 | default: | ||
373 | printk(KERN_ERR "svcrdma: unexpected completion type, " | ||
374 | "opcode=%d, status=%d\n", | ||
375 | wc.opcode, wc.status); | ||
376 | break; | ||
377 | } | ||
378 | svc_xprt_put(&xprt->sc_xprt); | 402 | svc_xprt_put(&xprt->sc_xprt); |
379 | } | 403 | } |
380 | 404 | ||
@@ -425,10 +449,12 @@ static struct svcxprt_rdma *rdma_create_xprt(struct svc_serv *serv, | |||
425 | INIT_LIST_HEAD(&cma_xprt->sc_dto_q); | 449 | INIT_LIST_HEAD(&cma_xprt->sc_dto_q); |
426 | INIT_LIST_HEAD(&cma_xprt->sc_rq_dto_q); | 450 | INIT_LIST_HEAD(&cma_xprt->sc_rq_dto_q); |
427 | INIT_LIST_HEAD(&cma_xprt->sc_read_complete_q); | 451 | INIT_LIST_HEAD(&cma_xprt->sc_read_complete_q); |
452 | INIT_LIST_HEAD(&cma_xprt->sc_frmr_q); | ||
428 | init_waitqueue_head(&cma_xprt->sc_send_wait); | 453 | init_waitqueue_head(&cma_xprt->sc_send_wait); |
429 | 454 | ||
430 | spin_lock_init(&cma_xprt->sc_lock); | 455 | spin_lock_init(&cma_xprt->sc_lock); |
431 | spin_lock_init(&cma_xprt->sc_rq_dto_lock); | 456 | spin_lock_init(&cma_xprt->sc_rq_dto_lock); |
457 | spin_lock_init(&cma_xprt->sc_frmr_q_lock); | ||
432 | 458 | ||
433 | cma_xprt->sc_ord = svcrdma_ord; | 459 | cma_xprt->sc_ord = svcrdma_ord; |
434 | 460 | ||
@@ -462,7 +488,7 @@ int svc_rdma_post_recv(struct svcxprt_rdma *xprt) | |||
462 | struct ib_recv_wr recv_wr, *bad_recv_wr; | 488 | struct ib_recv_wr recv_wr, *bad_recv_wr; |
463 | struct svc_rdma_op_ctxt *ctxt; | 489 | struct svc_rdma_op_ctxt *ctxt; |
464 | struct page *page; | 490 | struct page *page; |
465 | unsigned long pa; | 491 | dma_addr_t pa; |
466 | int sge_no; | 492 | int sge_no; |
467 | int buflen; | 493 | int buflen; |
468 | int ret; | 494 | int ret; |
@@ -474,13 +500,15 @@ int svc_rdma_post_recv(struct svcxprt_rdma *xprt) | |||
474 | BUG_ON(sge_no >= xprt->sc_max_sge); | 500 | BUG_ON(sge_no >= xprt->sc_max_sge); |
475 | page = svc_rdma_get_page(); | 501 | page = svc_rdma_get_page(); |
476 | ctxt->pages[sge_no] = page; | 502 | ctxt->pages[sge_no] = page; |
477 | atomic_inc(&xprt->sc_dma_used); | ||
478 | pa = ib_dma_map_page(xprt->sc_cm_id->device, | 503 | pa = ib_dma_map_page(xprt->sc_cm_id->device, |
479 | page, 0, PAGE_SIZE, | 504 | page, 0, PAGE_SIZE, |
480 | DMA_FROM_DEVICE); | 505 | DMA_FROM_DEVICE); |
506 | if (ib_dma_mapping_error(xprt->sc_cm_id->device, pa)) | ||
507 | goto err_put_ctxt; | ||
508 | atomic_inc(&xprt->sc_dma_used); | ||
481 | ctxt->sge[sge_no].addr = pa; | 509 | ctxt->sge[sge_no].addr = pa; |
482 | ctxt->sge[sge_no].length = PAGE_SIZE; | 510 | ctxt->sge[sge_no].length = PAGE_SIZE; |
483 | ctxt->sge[sge_no].lkey = xprt->sc_phys_mr->lkey; | 511 | ctxt->sge[sge_no].lkey = xprt->sc_dma_lkey; |
484 | buflen += PAGE_SIZE; | 512 | buflen += PAGE_SIZE; |
485 | } | 513 | } |
486 | ctxt->count = sge_no; | 514 | ctxt->count = sge_no; |
@@ -496,6 +524,10 @@ int svc_rdma_post_recv(struct svcxprt_rdma *xprt) | |||
496 | svc_rdma_put_context(ctxt, 1); | 524 | svc_rdma_put_context(ctxt, 1); |
497 | } | 525 | } |
498 | return ret; | 526 | return ret; |
527 | |||
528 | err_put_ctxt: | ||
529 | svc_rdma_put_context(ctxt, 1); | ||
530 | return -ENOMEM; | ||
499 | } | 531 | } |
500 | 532 | ||
501 | /* | 533 | /* |
@@ -566,7 +598,7 @@ static int rdma_listen_handler(struct rdma_cm_id *cma_id, | |||
566 | dprintk("svcrdma: Connect request on cma_id=%p, xprt = %p, " | 598 | dprintk("svcrdma: Connect request on cma_id=%p, xprt = %p, " |
567 | "event=%d\n", cma_id, cma_id->context, event->event); | 599 | "event=%d\n", cma_id, cma_id->context, event->event); |
568 | handle_connect_req(cma_id, | 600 | handle_connect_req(cma_id, |
569 | event->param.conn.responder_resources); | 601 | event->param.conn.initiator_depth); |
570 | break; | 602 | break; |
571 | 603 | ||
572 | case RDMA_CM_EVENT_ESTABLISHED: | 604 | case RDMA_CM_EVENT_ESTABLISHED: |
@@ -686,6 +718,97 @@ static struct svc_xprt *svc_rdma_create(struct svc_serv *serv, | |||
686 | return ERR_PTR(ret); | 718 | return ERR_PTR(ret); |
687 | } | 719 | } |
688 | 720 | ||
721 | static struct svc_rdma_fastreg_mr *rdma_alloc_frmr(struct svcxprt_rdma *xprt) | ||
722 | { | ||
723 | struct ib_mr *mr; | ||
724 | struct ib_fast_reg_page_list *pl; | ||
725 | struct svc_rdma_fastreg_mr *frmr; | ||
726 | |||
727 | frmr = kmalloc(sizeof(*frmr), GFP_KERNEL); | ||
728 | if (!frmr) | ||
729 | goto err; | ||
730 | |||
731 | mr = ib_alloc_fast_reg_mr(xprt->sc_pd, RPCSVC_MAXPAGES); | ||
732 | if (!mr) | ||
733 | goto err_free_frmr; | ||
734 | |||
735 | pl = ib_alloc_fast_reg_page_list(xprt->sc_cm_id->device, | ||
736 | RPCSVC_MAXPAGES); | ||
737 | if (!pl) | ||
738 | goto err_free_mr; | ||
739 | |||
740 | frmr->mr = mr; | ||
741 | frmr->page_list = pl; | ||
742 | INIT_LIST_HEAD(&frmr->frmr_list); | ||
743 | return frmr; | ||
744 | |||
745 | err_free_mr: | ||
746 | ib_dereg_mr(mr); | ||
747 | err_free_frmr: | ||
748 | kfree(frmr); | ||
749 | err: | ||
750 | return ERR_PTR(-ENOMEM); | ||
751 | } | ||
752 | |||
753 | static void rdma_dealloc_frmr_q(struct svcxprt_rdma *xprt) | ||
754 | { | ||
755 | struct svc_rdma_fastreg_mr *frmr; | ||
756 | |||
757 | while (!list_empty(&xprt->sc_frmr_q)) { | ||
758 | frmr = list_entry(xprt->sc_frmr_q.next, | ||
759 | struct svc_rdma_fastreg_mr, frmr_list); | ||
760 | list_del_init(&frmr->frmr_list); | ||
761 | ib_dereg_mr(frmr->mr); | ||
762 | ib_free_fast_reg_page_list(frmr->page_list); | ||
763 | kfree(frmr); | ||
764 | } | ||
765 | } | ||
766 | |||
767 | struct svc_rdma_fastreg_mr *svc_rdma_get_frmr(struct svcxprt_rdma *rdma) | ||
768 | { | ||
769 | struct svc_rdma_fastreg_mr *frmr = NULL; | ||
770 | |||
771 | spin_lock_bh(&rdma->sc_frmr_q_lock); | ||
772 | if (!list_empty(&rdma->sc_frmr_q)) { | ||
773 | frmr = list_entry(rdma->sc_frmr_q.next, | ||
774 | struct svc_rdma_fastreg_mr, frmr_list); | ||
775 | list_del_init(&frmr->frmr_list); | ||
776 | frmr->map_len = 0; | ||
777 | frmr->page_list_len = 0; | ||
778 | } | ||
779 | spin_unlock_bh(&rdma->sc_frmr_q_lock); | ||
780 | if (frmr) | ||
781 | return frmr; | ||
782 | |||
783 | return rdma_alloc_frmr(rdma); | ||
784 | } | ||
785 | |||
786 | static void frmr_unmap_dma(struct svcxprt_rdma *xprt, | ||
787 | struct svc_rdma_fastreg_mr *frmr) | ||
788 | { | ||
789 | int page_no; | ||
790 | for (page_no = 0; page_no < frmr->page_list_len; page_no++) { | ||
791 | dma_addr_t addr = frmr->page_list->page_list[page_no]; | ||
792 | if (ib_dma_mapping_error(frmr->mr->device, addr)) | ||
793 | continue; | ||
794 | atomic_dec(&xprt->sc_dma_used); | ||
795 | ib_dma_unmap_single(frmr->mr->device, addr, PAGE_SIZE, | ||
796 | frmr->direction); | ||
797 | } | ||
798 | } | ||
799 | |||
800 | void svc_rdma_put_frmr(struct svcxprt_rdma *rdma, | ||
801 | struct svc_rdma_fastreg_mr *frmr) | ||
802 | { | ||
803 | if (frmr) { | ||
804 | frmr_unmap_dma(rdma, frmr); | ||
805 | spin_lock_bh(&rdma->sc_frmr_q_lock); | ||
806 | BUG_ON(!list_empty(&frmr->frmr_list)); | ||
807 | list_add(&frmr->frmr_list, &rdma->sc_frmr_q); | ||
808 | spin_unlock_bh(&rdma->sc_frmr_q_lock); | ||
809 | } | ||
810 | } | ||
811 | |||
689 | /* | 812 | /* |
690 | * This is the xpo_recvfrom function for listening endpoints. Its | 813 | * This is the xpo_recvfrom function for listening endpoints. Its |
691 | * purpose is to accept incoming connections. The CMA callback handler | 814 | * purpose is to accept incoming connections. The CMA callback handler |
@@ -704,6 +827,8 @@ static struct svc_xprt *svc_rdma_accept(struct svc_xprt *xprt) | |||
704 | struct rdma_conn_param conn_param; | 827 | struct rdma_conn_param conn_param; |
705 | struct ib_qp_init_attr qp_attr; | 828 | struct ib_qp_init_attr qp_attr; |
706 | struct ib_device_attr devattr; | 829 | struct ib_device_attr devattr; |
830 | int dma_mr_acc; | ||
831 | int need_dma_mr; | ||
707 | int ret; | 832 | int ret; |
708 | int i; | 833 | int i; |
709 | 834 | ||
@@ -819,15 +944,77 @@ static struct svc_xprt *svc_rdma_accept(struct svc_xprt *xprt) | |||
819 | } | 944 | } |
820 | newxprt->sc_qp = newxprt->sc_cm_id->qp; | 945 | newxprt->sc_qp = newxprt->sc_cm_id->qp; |
821 | 946 | ||
822 | /* Register all of physical memory */ | 947 | /* |
823 | newxprt->sc_phys_mr = ib_get_dma_mr(newxprt->sc_pd, | 948 | * Use the most secure set of MR resources based on the |
824 | IB_ACCESS_LOCAL_WRITE | | 949 | * transport type and available memory management features in |
825 | IB_ACCESS_REMOTE_WRITE); | 950 | * the device. Here's the table implemented below: |
826 | if (IS_ERR(newxprt->sc_phys_mr)) { | 951 | * |
827 | dprintk("svcrdma: Failed to create DMA MR ret=%d\n", ret); | 952 | * Fast Global DMA Remote WR |
953 | * Reg LKEY MR Access | ||
954 | * Sup'd Sup'd Needed Needed | ||
955 | * | ||
956 | * IWARP N N Y Y | ||
957 | * N Y Y Y | ||
958 | * Y N Y N | ||
959 | * Y Y N - | ||
960 | * | ||
961 | * IB N N Y N | ||
962 | * N Y N - | ||
963 | * Y N Y N | ||
964 | * Y Y N - | ||
965 | * | ||
966 | * NB: iWARP requires remote write access for the data sink | ||
967 | * of an RDMA_READ. IB does not. | ||
968 | */ | ||
969 | if (devattr.device_cap_flags & IB_DEVICE_MEM_MGT_EXTENSIONS) { | ||
970 | newxprt->sc_frmr_pg_list_len = | ||
971 | devattr.max_fast_reg_page_list_len; | ||
972 | newxprt->sc_dev_caps |= SVCRDMA_DEVCAP_FAST_REG; | ||
973 | } | ||
974 | |||
975 | /* | ||
976 | * Determine if a DMA MR is required and if so, what privs are required | ||
977 | */ | ||
978 | switch (rdma_node_get_transport(newxprt->sc_cm_id->device->node_type)) { | ||
979 | case RDMA_TRANSPORT_IWARP: | ||
980 | newxprt->sc_dev_caps |= SVCRDMA_DEVCAP_READ_W_INV; | ||
981 | if (!(newxprt->sc_dev_caps & SVCRDMA_DEVCAP_FAST_REG)) { | ||
982 | need_dma_mr = 1; | ||
983 | dma_mr_acc = | ||
984 | (IB_ACCESS_LOCAL_WRITE | | ||
985 | IB_ACCESS_REMOTE_WRITE); | ||
986 | } else if (!(devattr.device_cap_flags & IB_DEVICE_LOCAL_DMA_LKEY)) { | ||
987 | need_dma_mr = 1; | ||
988 | dma_mr_acc = IB_ACCESS_LOCAL_WRITE; | ||
989 | } else | ||
990 | need_dma_mr = 0; | ||
991 | break; | ||
992 | case RDMA_TRANSPORT_IB: | ||
993 | if (!(devattr.device_cap_flags & IB_DEVICE_LOCAL_DMA_LKEY)) { | ||
994 | need_dma_mr = 1; | ||
995 | dma_mr_acc = IB_ACCESS_LOCAL_WRITE; | ||
996 | } else | ||
997 | need_dma_mr = 0; | ||
998 | break; | ||
999 | default: | ||
828 | goto errout; | 1000 | goto errout; |
829 | } | 1001 | } |
830 | 1002 | ||
1003 | /* Create the DMA MR if needed, otherwise, use the DMA LKEY */ | ||
1004 | if (need_dma_mr) { | ||
1005 | /* Register all of physical memory */ | ||
1006 | newxprt->sc_phys_mr = | ||
1007 | ib_get_dma_mr(newxprt->sc_pd, dma_mr_acc); | ||
1008 | if (IS_ERR(newxprt->sc_phys_mr)) { | ||
1009 | dprintk("svcrdma: Failed to create DMA MR ret=%d\n", | ||
1010 | ret); | ||
1011 | goto errout; | ||
1012 | } | ||
1013 | newxprt->sc_dma_lkey = newxprt->sc_phys_mr->lkey; | ||
1014 | } else | ||
1015 | newxprt->sc_dma_lkey = | ||
1016 | newxprt->sc_cm_id->device->local_dma_lkey; | ||
1017 | |||
831 | /* Post receive buffers */ | 1018 | /* Post receive buffers */ |
832 | for (i = 0; i < newxprt->sc_max_requests; i++) { | 1019 | for (i = 0; i < newxprt->sc_max_requests; i++) { |
833 | ret = svc_rdma_post_recv(newxprt); | 1020 | ret = svc_rdma_post_recv(newxprt); |
@@ -961,6 +1148,9 @@ static void __svc_rdma_free(struct work_struct *work) | |||
961 | WARN_ON(atomic_read(&rdma->sc_ctxt_used) != 0); | 1148 | WARN_ON(atomic_read(&rdma->sc_ctxt_used) != 0); |
962 | WARN_ON(atomic_read(&rdma->sc_dma_used) != 0); | 1149 | WARN_ON(atomic_read(&rdma->sc_dma_used) != 0); |
963 | 1150 | ||
1151 | /* De-allocate fastreg mr */ | ||
1152 | rdma_dealloc_frmr_q(rdma); | ||
1153 | |||
964 | /* Destroy the QP if present (not a listener) */ | 1154 | /* Destroy the QP if present (not a listener) */ |
965 | if (rdma->sc_qp && !IS_ERR(rdma->sc_qp)) | 1155 | if (rdma->sc_qp && !IS_ERR(rdma->sc_qp)) |
966 | ib_destroy_qp(rdma->sc_qp); | 1156 | ib_destroy_qp(rdma->sc_qp); |
@@ -1014,21 +1204,59 @@ static int svc_rdma_has_wspace(struct svc_xprt *xprt) | |||
1014 | return 1; | 1204 | return 1; |
1015 | } | 1205 | } |
1016 | 1206 | ||
1207 | /* | ||
1208 | * Attempt to register the kvec representing the RPC memory with the | ||
1209 | * device. | ||
1210 | * | ||
1211 | * Returns: | ||
1212 | * NULL : The device does not support fastreg or there were no more | ||
1213 | * fastreg mr. | ||
1214 | * frmr : The kvec register request was successfully posted. | ||
1215 | * <0 : An error was encountered attempting to register the kvec. | ||
1216 | */ | ||
1217 | int svc_rdma_fastreg(struct svcxprt_rdma *xprt, | ||
1218 | struct svc_rdma_fastreg_mr *frmr) | ||
1219 | { | ||
1220 | struct ib_send_wr fastreg_wr; | ||
1221 | u8 key; | ||
1222 | |||
1223 | /* Bump the key */ | ||
1224 | key = (u8)(frmr->mr->lkey & 0x000000FF); | ||
1225 | ib_update_fast_reg_key(frmr->mr, ++key); | ||
1226 | |||
1227 | /* Prepare FASTREG WR */ | ||
1228 | memset(&fastreg_wr, 0, sizeof fastreg_wr); | ||
1229 | fastreg_wr.opcode = IB_WR_FAST_REG_MR; | ||
1230 | fastreg_wr.send_flags = IB_SEND_SIGNALED; | ||
1231 | fastreg_wr.wr.fast_reg.iova_start = (unsigned long)frmr->kva; | ||
1232 | fastreg_wr.wr.fast_reg.page_list = frmr->page_list; | ||
1233 | fastreg_wr.wr.fast_reg.page_list_len = frmr->page_list_len; | ||
1234 | fastreg_wr.wr.fast_reg.page_shift = PAGE_SHIFT; | ||
1235 | fastreg_wr.wr.fast_reg.length = frmr->map_len; | ||
1236 | fastreg_wr.wr.fast_reg.access_flags = frmr->access_flags; | ||
1237 | fastreg_wr.wr.fast_reg.rkey = frmr->mr->lkey; | ||
1238 | return svc_rdma_send(xprt, &fastreg_wr); | ||
1239 | } | ||
1240 | |||
1017 | int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr) | 1241 | int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr) |
1018 | { | 1242 | { |
1019 | struct ib_send_wr *bad_wr; | 1243 | struct ib_send_wr *bad_wr, *n_wr; |
1244 | int wr_count; | ||
1245 | int i; | ||
1020 | int ret; | 1246 | int ret; |
1021 | 1247 | ||
1022 | if (test_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags)) | 1248 | if (test_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags)) |
1023 | return -ENOTCONN; | 1249 | return -ENOTCONN; |
1024 | 1250 | ||
1025 | BUG_ON(wr->send_flags != IB_SEND_SIGNALED); | 1251 | BUG_ON(wr->send_flags != IB_SEND_SIGNALED); |
1026 | BUG_ON(((struct svc_rdma_op_ctxt *)(unsigned long)wr->wr_id)->wr_op != | 1252 | wr_count = 1; |
1027 | wr->opcode); | 1253 | for (n_wr = wr->next; n_wr; n_wr = n_wr->next) |
1254 | wr_count++; | ||
1255 | |||
1028 | /* If the SQ is full, wait until an SQ entry is available */ | 1256 | /* If the SQ is full, wait until an SQ entry is available */ |
1029 | while (1) { | 1257 | while (1) { |
1030 | spin_lock_bh(&xprt->sc_lock); | 1258 | spin_lock_bh(&xprt->sc_lock); |
1031 | if (xprt->sc_sq_depth == atomic_read(&xprt->sc_sq_count)) { | 1259 | if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) { |
1032 | spin_unlock_bh(&xprt->sc_lock); | 1260 | spin_unlock_bh(&xprt->sc_lock); |
1033 | atomic_inc(&rdma_stat_sq_starve); | 1261 | atomic_inc(&rdma_stat_sq_starve); |
1034 | 1262 | ||
@@ -1043,19 +1271,26 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr) | |||
1043 | return 0; | 1271 | return 0; |
1044 | continue; | 1272 | continue; |
1045 | } | 1273 | } |
1046 | /* Bumped used SQ WR count and post */ | 1274 | /* Take a transport ref for each WR posted */ |
1047 | svc_xprt_get(&xprt->sc_xprt); | 1275 | for (i = 0; i < wr_count; i++) |
1276 | svc_xprt_get(&xprt->sc_xprt); | ||
1277 | |||
1278 | /* Bump used SQ WR count and post */ | ||
1279 | atomic_add(wr_count, &xprt->sc_sq_count); | ||
1048 | ret = ib_post_send(xprt->sc_qp, wr, &bad_wr); | 1280 | ret = ib_post_send(xprt->sc_qp, wr, &bad_wr); |
1049 | if (!ret) | 1281 | if (ret) { |
1050 | atomic_inc(&xprt->sc_sq_count); | 1282 | set_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags); |
1051 | else { | 1283 | atomic_sub(wr_count, &xprt->sc_sq_count); |
1052 | svc_xprt_put(&xprt->sc_xprt); | 1284 | for (i = 0; i < wr_count; i ++) |
1285 | svc_xprt_put(&xprt->sc_xprt); | ||
1053 | dprintk("svcrdma: failed to post SQ WR rc=%d, " | 1286 | dprintk("svcrdma: failed to post SQ WR rc=%d, " |
1054 | "sc_sq_count=%d, sc_sq_depth=%d\n", | 1287 | "sc_sq_count=%d, sc_sq_depth=%d\n", |
1055 | ret, atomic_read(&xprt->sc_sq_count), | 1288 | ret, atomic_read(&xprt->sc_sq_count), |
1056 | xprt->sc_sq_depth); | 1289 | xprt->sc_sq_depth); |
1057 | } | 1290 | } |
1058 | spin_unlock_bh(&xprt->sc_lock); | 1291 | spin_unlock_bh(&xprt->sc_lock); |
1292 | if (ret) | ||
1293 | wake_up(&xprt->sc_send_wait); | ||
1059 | break; | 1294 | break; |
1060 | } | 1295 | } |
1061 | return ret; | 1296 | return ret; |
@@ -1079,10 +1314,14 @@ void svc_rdma_send_error(struct svcxprt_rdma *xprt, struct rpcrdma_msg *rmsgp, | |||
1079 | length = svc_rdma_xdr_encode_error(xprt, rmsgp, err, va); | 1314 | length = svc_rdma_xdr_encode_error(xprt, rmsgp, err, va); |
1080 | 1315 | ||
1081 | /* Prepare SGE for local address */ | 1316 | /* Prepare SGE for local address */ |
1082 | atomic_inc(&xprt->sc_dma_used); | ||
1083 | sge.addr = ib_dma_map_page(xprt->sc_cm_id->device, | 1317 | sge.addr = ib_dma_map_page(xprt->sc_cm_id->device, |
1084 | p, 0, PAGE_SIZE, DMA_FROM_DEVICE); | 1318 | p, 0, PAGE_SIZE, DMA_FROM_DEVICE); |
1085 | sge.lkey = xprt->sc_phys_mr->lkey; | 1319 | if (ib_dma_mapping_error(xprt->sc_cm_id->device, sge.addr)) { |
1320 | put_page(p); | ||
1321 | return; | ||
1322 | } | ||
1323 | atomic_inc(&xprt->sc_dma_used); | ||
1324 | sge.lkey = xprt->sc_dma_lkey; | ||
1086 | sge.length = length; | 1325 | sge.length = length; |
1087 | 1326 | ||
1088 | ctxt = svc_rdma_get_context(xprt); | 1327 | ctxt = svc_rdma_get_context(xprt); |
@@ -1103,6 +1342,9 @@ void svc_rdma_send_error(struct svcxprt_rdma *xprt, struct rpcrdma_msg *rmsgp, | |||
1103 | if (ret) { | 1342 | if (ret) { |
1104 | dprintk("svcrdma: Error %d posting send for protocol error\n", | 1343 | dprintk("svcrdma: Error %d posting send for protocol error\n", |
1105 | ret); | 1344 | ret); |
1345 | ib_dma_unmap_page(xprt->sc_cm_id->device, | ||
1346 | sge.addr, PAGE_SIZE, | ||
1347 | DMA_FROM_DEVICE); | ||
1106 | svc_rdma_put_context(ctxt, 1); | 1348 | svc_rdma_put_context(ctxt, 1); |
1107 | } | 1349 | } |
1108 | } | 1350 | } |
diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c index 4486c59c3aca..9a288d5eea64 100644 --- a/net/sunrpc/xprtsock.c +++ b/net/sunrpc/xprtsock.c | |||
@@ -3,8 +3,8 @@ | |||
3 | * | 3 | * |
4 | * Client-side transport implementation for sockets. | 4 | * Client-side transport implementation for sockets. |
5 | * | 5 | * |
6 | * TCP callback races fixes (C) 1998 Red Hat Software <alan@redhat.com> | 6 | * TCP callback races fixes (C) 1998 Red Hat |
7 | * TCP send fixes (C) 1998 Red Hat Software <alan@redhat.com> | 7 | * TCP send fixes (C) 1998 Red Hat |
8 | * TCP NFS related read + write fixes | 8 | * TCP NFS related read + write fixes |
9 | * (C) 1999 Dave Airlie, University of Limerick, Ireland <airlied@linux.ie> | 9 | * (C) 1999 Dave Airlie, University of Limerick, Ireland <airlied@linux.ie> |
10 | * | 10 | * |
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 015606b54d9b..c647aab8d418 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * NET4: Implementation of BSD Unix domain sockets. | 2 | * NET4: Implementation of BSD Unix domain sockets. |
3 | * | 3 | * |
4 | * Authors: Alan Cox, <alan.cox@linux.org> | 4 | * Authors: Alan Cox, <alan@lxorguk.ukuu.org.uk> |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or | 6 | * This program is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU General Public License | 7 | * modify it under the terms of the GNU General Public License |
diff --git a/scripts/bootgraph.pl b/scripts/bootgraph.pl new file mode 100644 index 000000000000..2243353fe55d --- /dev/null +++ b/scripts/bootgraph.pl | |||
@@ -0,0 +1,147 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | # Copyright 2008, Intel Corporation | ||
4 | # | ||
5 | # This file is part of the Linux kernel | ||
6 | # | ||
7 | # This program file is free software; you can redistribute it and/or modify it | ||
8 | # under the terms of the GNU General Public License as published by the | ||
9 | # Free Software Foundation; version 2 of the License. | ||
10 | # | ||
11 | # This program is distributed in the hope that it will be useful, but WITHOUT | ||
12 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
13 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
14 | # for more details. | ||
15 | # | ||
16 | # You should have received a copy of the GNU General Public License | ||
17 | # along with this program in a file named COPYING; if not, write to the | ||
18 | # Free Software Foundation, Inc., | ||
19 | # 51 Franklin Street, Fifth Floor, | ||
20 | # Boston, MA 02110-1301 USA | ||
21 | # | ||
22 | # Authors: | ||
23 | # Arjan van de Ven <arjan@linux.intel.com> | ||
24 | |||
25 | |||
26 | # | ||
27 | # This script turns a dmesg output into a SVG graphic that shows which | ||
28 | # functions take how much time. You can view SVG graphics with various | ||
29 | # programs, including Inkscape, The Gimp and Firefox. | ||
30 | # | ||
31 | # | ||
32 | # For this script to work, the kernel needs to be compiled with the | ||
33 | # CONFIG_PRINTK_TIME configuration option enabled, and with | ||
34 | # "initcall_debug" passed on the kernel command line. | ||
35 | # | ||
36 | # usage: | ||
37 | # dmesg | perl scripts/bootgraph.pl > output.svg | ||
38 | # | ||
39 | |||
40 | my @rows; | ||
41 | my %start, %end, %row; | ||
42 | my $done = 0; | ||
43 | my $rowcount = 0; | ||
44 | my $maxtime = 0; | ||
45 | my $firsttime = 100; | ||
46 | my $count = 0; | ||
47 | while (<>) { | ||
48 | my $line = $_; | ||
49 | if ($line =~ /([0-9\.]+)\] calling ([a-zA-Z0-9\_]+)\+/) { | ||
50 | my $func = $2; | ||
51 | if ($done == 0) { | ||
52 | $start{$func} = $1; | ||
53 | if ($1 < $firsttime) { | ||
54 | $firsttime = $1; | ||
55 | } | ||
56 | } | ||
57 | $row{$func} = 1; | ||
58 | if ($line =~ /\@ ([0-9]+)/) { | ||
59 | my $pid = $1; | ||
60 | if (!defined($rows[$pid])) { | ||
61 | $rowcount = $rowcount + 1; | ||
62 | $rows[$pid] = $rowcount; | ||
63 | } | ||
64 | $row{$func} = $rows[$pid]; | ||
65 | } | ||
66 | $count = $count + 1; | ||
67 | } | ||
68 | |||
69 | if ($line =~ /([0-9\.]+)\] initcall ([a-zA-Z0-9\_]+)\+.*returned/) { | ||
70 | if ($done == 0) { | ||
71 | $end{$2} = $1; | ||
72 | $maxtime = $1; | ||
73 | } | ||
74 | } | ||
75 | if ($line =~ /Write protecting the/) { | ||
76 | $done = 1; | ||
77 | } | ||
78 | if ($line =~ /Freeing unused kernel memory/) { | ||
79 | $done = 1; | ||
80 | } | ||
81 | } | ||
82 | |||
83 | if ($count == 0) { | ||
84 | print "No data found in the dmesg. Make sure that 'printk.time=1' and\n"; | ||
85 | print "'initcall_debug' are passed on the kernel command line.\n\n"; | ||
86 | print "Usage: \n"; | ||
87 | print " dmesg | perl scripts/bootgraph.pl > output.svg\n\n"; | ||
88 | exit; | ||
89 | } | ||
90 | |||
91 | print "<?xml version=\"1.0\" standalone=\"no\"?> \n"; | ||
92 | print "<svg width=\"1000\" height=\"100%\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n"; | ||
93 | |||
94 | my @styles; | ||
95 | |||
96 | $styles[0] = "fill:rgb(0,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; | ||
97 | $styles[1] = "fill:rgb(0,255,0);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; | ||
98 | $styles[2] = "fill:rgb(255,0,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; | ||
99 | $styles[3] = "fill:rgb(255,255,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; | ||
100 | $styles[4] = "fill:rgb(255,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; | ||
101 | $styles[5] = "fill:rgb(0,255,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; | ||
102 | $styles[6] = "fill:rgb(0,128,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; | ||
103 | $styles[7] = "fill:rgb(0,255,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; | ||
104 | $styles[8] = "fill:rgb(255,0,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; | ||
105 | $styles[9] = "fill:rgb(255,255,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; | ||
106 | $styles[10] = "fill:rgb(255,128,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; | ||
107 | $styles[11] = "fill:rgb(128,255,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; | ||
108 | |||
109 | my $mult = 950.0 / ($maxtime - $firsttime); | ||
110 | my $threshold = ($maxtime - $firsttime) / 60.0; | ||
111 | my $stylecounter = 0; | ||
112 | while (($key,$value) = each %start) { | ||
113 | my $duration = $end{$key} - $start{$key}; | ||
114 | |||
115 | if ($duration >= $threshold) { | ||
116 | my $s, $s2, $e, $y; | ||
117 | $s = ($value - $firsttime) * $mult; | ||
118 | $s2 = $s + 6; | ||
119 | $e = ($end{$key} - $firsttime) * $mult; | ||
120 | $w = $e - $s; | ||
121 | |||
122 | $y = $row{$key} * 150; | ||
123 | $y2 = $y + 4; | ||
124 | |||
125 | $style = $styles[$stylecounter]; | ||
126 | $stylecounter = $stylecounter + 1; | ||
127 | if ($stylecounter > 11) { | ||
128 | $stylecounter = 0; | ||
129 | }; | ||
130 | |||
131 | print "<rect x=\"$s\" width=\"$w\" y=\"$y\" height=\"145\" style=\"$style\"/>\n"; | ||
132 | print "<text transform=\"translate($s2,$y2) rotate(90)\">$key</text>\n"; | ||
133 | } | ||
134 | } | ||
135 | |||
136 | |||
137 | # print the time line on top | ||
138 | my $time = $firsttime; | ||
139 | my $step = ($maxtime - $firsttime) / 15; | ||
140 | while ($time < $maxtime) { | ||
141 | my $s2 = ($time - $firsttime) * $mult; | ||
142 | my $tm = int($time * 100) / 100.0; | ||
143 | print "<text transform=\"translate($s2,89) rotate(90)\">$tm</text>\n"; | ||
144 | $time = $time + $step; | ||
145 | } | ||
146 | |||
147 | print "</svg>\n"; | ||
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c index 473f94e56ead..d4dc222a74f3 100644 --- a/scripts/mod/file2alias.c +++ b/scripts/mod/file2alias.c | |||
@@ -206,6 +206,20 @@ static void do_usb_table(void *symval, unsigned long size, | |||
206 | do_usb_entry_multi(symval + i, mod); | 206 | do_usb_entry_multi(symval + i, mod); |
207 | } | 207 | } |
208 | 208 | ||
209 | /* Looks like: hid:bNvNpN */ | ||
210 | static int do_hid_entry(const char *filename, | ||
211 | struct hid_device_id *id, char *alias) | ||
212 | { | ||
213 | id->vendor = TO_NATIVE(id->vendor); | ||
214 | id->product = TO_NATIVE(id->product); | ||
215 | |||
216 | sprintf(alias, "hid:b%04X", id->bus); | ||
217 | ADD(alias, "v", id->vendor != HID_ANY_ID, id->vendor); | ||
218 | ADD(alias, "p", id->product != HID_ANY_ID, id->product); | ||
219 | |||
220 | return 1; | ||
221 | } | ||
222 | |||
209 | /* Looks like: ieee1394:venNmoNspNverN */ | 223 | /* Looks like: ieee1394:venNmoNspNverN */ |
210 | static int do_ieee1394_entry(const char *filename, | 224 | static int do_ieee1394_entry(const char *filename, |
211 | struct ieee1394_device_id *id, char *alias) | 225 | struct ieee1394_device_id *id, char *alias) |
@@ -745,6 +759,10 @@ void handle_moddevtable(struct module *mod, struct elf_info *info, | |||
745 | else if (sym_is(symname, "__mod_usb_device_table")) | 759 | else if (sym_is(symname, "__mod_usb_device_table")) |
746 | /* special case to handle bcdDevice ranges */ | 760 | /* special case to handle bcdDevice ranges */ |
747 | do_usb_table(symval, sym->st_size, mod); | 761 | do_usb_table(symval, sym->st_size, mod); |
762 | else if (sym_is(symname, "__mod_hid_device_table")) | ||
763 | do_table(symval, sym->st_size, | ||
764 | sizeof(struct hid_device_id), "hid", | ||
765 | do_hid_entry, mod); | ||
748 | else if (sym_is(symname, "__mod_ieee1394_device_table")) | 766 | else if (sym_is(symname, "__mod_ieee1394_device_table")) |
749 | do_table(symval, sym->st_size, | 767 | do_table(symval, sym->st_size, |
750 | sizeof(struct ieee1394_device_id), "ieee1394", | 768 | sizeof(struct ieee1394_device_id), "ieee1394", |