Annotation of /trunk/kernel-alx/patches-4.9/0269-4.9.170-all-fixes.patch
Parent Directory | Revision Log
Revision 3346 -
(hide annotations)
(download)
Tue Jun 18 09:42:00 2019 UTC (5 years, 3 months ago) by niro
File size: 138305 byte(s)
Tue Jun 18 09:42:00 2019 UTC (5 years, 3 months ago) by niro
File size: 138305 byte(s)
-linux-4.9.170
1 | niro | 3346 | diff --git a/Makefile b/Makefile |
2 | index 23cc23c47adf..966069dab768 100644 | ||
3 | --- a/Makefile | ||
4 | +++ b/Makefile | ||
5 | @@ -1,6 +1,6 @@ | ||
6 | VERSION = 4 | ||
7 | PATCHLEVEL = 9 | ||
8 | -SUBLEVEL = 169 | ||
9 | +SUBLEVEL = 170 | ||
10 | EXTRAVERSION = | ||
11 | NAME = Roaring Lionus | ||
12 | |||
13 | diff --git a/arch/arc/kernel/head.S b/arch/arc/kernel/head.S | ||
14 | index 1f945d0f40da..208bf2c9e7b0 100644 | ||
15 | --- a/arch/arc/kernel/head.S | ||
16 | +++ b/arch/arc/kernel/head.S | ||
17 | @@ -107,6 +107,7 @@ ENTRY(stext) | ||
18 | ; r2 = pointer to uboot provided cmdline or external DTB in mem | ||
19 | ; These are handled later in handle_uboot_args() | ||
20 | st r0, [@uboot_tag] | ||
21 | + st r1, [@uboot_magic] | ||
22 | st r2, [@uboot_arg] | ||
23 | #endif | ||
24 | |||
25 | diff --git a/arch/arc/kernel/setup.c b/arch/arc/kernel/setup.c | ||
26 | index 9119bea503a7..9f96120eee6e 100644 | ||
27 | --- a/arch/arc/kernel/setup.c | ||
28 | +++ b/arch/arc/kernel/setup.c | ||
29 | @@ -32,6 +32,7 @@ unsigned int intr_to_DE_cnt; | ||
30 | |||
31 | /* Part of U-boot ABI: see head.S */ | ||
32 | int __initdata uboot_tag; | ||
33 | +int __initdata uboot_magic; | ||
34 | char __initdata *uboot_arg; | ||
35 | |||
36 | const struct machine_desc *machine_desc; | ||
37 | @@ -400,6 +401,8 @@ static inline bool uboot_arg_invalid(unsigned long addr) | ||
38 | #define UBOOT_TAG_NONE 0 | ||
39 | #define UBOOT_TAG_CMDLINE 1 | ||
40 | #define UBOOT_TAG_DTB 2 | ||
41 | +/* We always pass 0 as magic from U-boot */ | ||
42 | +#define UBOOT_MAGIC_VALUE 0 | ||
43 | |||
44 | void __init handle_uboot_args(void) | ||
45 | { | ||
46 | @@ -415,6 +418,11 @@ void __init handle_uboot_args(void) | ||
47 | goto ignore_uboot_args; | ||
48 | } | ||
49 | |||
50 | + if (uboot_magic != UBOOT_MAGIC_VALUE) { | ||
51 | + pr_warn(IGNORE_ARGS "non zero uboot magic\n"); | ||
52 | + goto ignore_uboot_args; | ||
53 | + } | ||
54 | + | ||
55 | if (uboot_tag != UBOOT_TAG_NONE && | ||
56 | uboot_arg_invalid((unsigned long)uboot_arg)) { | ||
57 | pr_warn(IGNORE_ARGS "invalid uboot arg: '%px'\n", uboot_arg); | ||
58 | diff --git a/arch/arm/crypto/sha256-armv4.pl b/arch/arm/crypto/sha256-armv4.pl | ||
59 | index fac0533ea633..f64e8413ab9a 100644 | ||
60 | --- a/arch/arm/crypto/sha256-armv4.pl | ||
61 | +++ b/arch/arm/crypto/sha256-armv4.pl | ||
62 | @@ -205,10 +205,11 @@ K256: | ||
63 | .global sha256_block_data_order | ||
64 | .type sha256_block_data_order,%function | ||
65 | sha256_block_data_order: | ||
66 | +.Lsha256_block_data_order: | ||
67 | #if __ARM_ARCH__<7 | ||
68 | sub r3,pc,#8 @ sha256_block_data_order | ||
69 | #else | ||
70 | - adr r3,sha256_block_data_order | ||
71 | + adr r3,.Lsha256_block_data_order | ||
72 | #endif | ||
73 | #if __ARM_MAX_ARCH__>=7 && !defined(__KERNEL__) | ||
74 | ldr r12,.LOPENSSL_armcap | ||
75 | diff --git a/arch/arm/crypto/sha256-core.S_shipped b/arch/arm/crypto/sha256-core.S_shipped | ||
76 | index 555a1a8eec90..72c248081d27 100644 | ||
77 | --- a/arch/arm/crypto/sha256-core.S_shipped | ||
78 | +++ b/arch/arm/crypto/sha256-core.S_shipped | ||
79 | @@ -86,10 +86,11 @@ K256: | ||
80 | .global sha256_block_data_order | ||
81 | .type sha256_block_data_order,%function | ||
82 | sha256_block_data_order: | ||
83 | +.Lsha256_block_data_order: | ||
84 | #if __ARM_ARCH__<7 | ||
85 | sub r3,pc,#8 @ sha256_block_data_order | ||
86 | #else | ||
87 | - adr r3,sha256_block_data_order | ||
88 | + adr r3,.Lsha256_block_data_order | ||
89 | #endif | ||
90 | #if __ARM_MAX_ARCH__>=7 && !defined(__KERNEL__) | ||
91 | ldr r12,.LOPENSSL_armcap | ||
92 | diff --git a/arch/arm/crypto/sha512-armv4.pl b/arch/arm/crypto/sha512-armv4.pl | ||
93 | index a2b11a844357..5fe336420bcf 100644 | ||
94 | --- a/arch/arm/crypto/sha512-armv4.pl | ||
95 | +++ b/arch/arm/crypto/sha512-armv4.pl | ||
96 | @@ -267,10 +267,11 @@ WORD64(0x5fcb6fab,0x3ad6faec, 0x6c44198c,0x4a475817) | ||
97 | .global sha512_block_data_order | ||
98 | .type sha512_block_data_order,%function | ||
99 | sha512_block_data_order: | ||
100 | +.Lsha512_block_data_order: | ||
101 | #if __ARM_ARCH__<7 | ||
102 | sub r3,pc,#8 @ sha512_block_data_order | ||
103 | #else | ||
104 | - adr r3,sha512_block_data_order | ||
105 | + adr r3,.Lsha512_block_data_order | ||
106 | #endif | ||
107 | #if __ARM_MAX_ARCH__>=7 && !defined(__KERNEL__) | ||
108 | ldr r12,.LOPENSSL_armcap | ||
109 | diff --git a/arch/arm/crypto/sha512-core.S_shipped b/arch/arm/crypto/sha512-core.S_shipped | ||
110 | index 3694c4d4ca2b..de9bd7f55242 100644 | ||
111 | --- a/arch/arm/crypto/sha512-core.S_shipped | ||
112 | +++ b/arch/arm/crypto/sha512-core.S_shipped | ||
113 | @@ -134,10 +134,11 @@ WORD64(0x5fcb6fab,0x3ad6faec, 0x6c44198c,0x4a475817) | ||
114 | .global sha512_block_data_order | ||
115 | .type sha512_block_data_order,%function | ||
116 | sha512_block_data_order: | ||
117 | +.Lsha512_block_data_order: | ||
118 | #if __ARM_ARCH__<7 | ||
119 | sub r3,pc,#8 @ sha512_block_data_order | ||
120 | #else | ||
121 | - adr r3,sha512_block_data_order | ||
122 | + adr r3,.Lsha512_block_data_order | ||
123 | #endif | ||
124 | #if __ARM_MAX_ARCH__>=7 && !defined(__KERNEL__) | ||
125 | ldr r12,.LOPENSSL_armcap | ||
126 | diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c | ||
127 | index 69bda1a5707e..1f665acaa6a9 100644 | ||
128 | --- a/arch/arm/kernel/patch.c | ||
129 | +++ b/arch/arm/kernel/patch.c | ||
130 | @@ -15,7 +15,7 @@ struct patch { | ||
131 | unsigned int insn; | ||
132 | }; | ||
133 | |||
134 | -static DEFINE_SPINLOCK(patch_lock); | ||
135 | +static DEFINE_RAW_SPINLOCK(patch_lock); | ||
136 | |||
137 | static void __kprobes *patch_map(void *addr, int fixmap, unsigned long *flags) | ||
138 | __acquires(&patch_lock) | ||
139 | @@ -32,7 +32,7 @@ static void __kprobes *patch_map(void *addr, int fixmap, unsigned long *flags) | ||
140 | return addr; | ||
141 | |||
142 | if (flags) | ||
143 | - spin_lock_irqsave(&patch_lock, *flags); | ||
144 | + raw_spin_lock_irqsave(&patch_lock, *flags); | ||
145 | else | ||
146 | __acquire(&patch_lock); | ||
147 | |||
148 | @@ -47,7 +47,7 @@ static void __kprobes patch_unmap(int fixmap, unsigned long *flags) | ||
149 | clear_fixmap(fixmap); | ||
150 | |||
151 | if (flags) | ||
152 | - spin_unlock_irqrestore(&patch_lock, *flags); | ||
153 | + raw_spin_unlock_irqrestore(&patch_lock, *flags); | ||
154 | else | ||
155 | __release(&patch_lock); | ||
156 | } | ||
157 | diff --git a/arch/arm/plat-samsung/Kconfig b/arch/arm/plat-samsung/Kconfig | ||
158 | index e8229b9fee4a..3265b8f86069 100644 | ||
159 | --- a/arch/arm/plat-samsung/Kconfig | ||
160 | +++ b/arch/arm/plat-samsung/Kconfig | ||
161 | @@ -258,7 +258,7 @@ config S3C_PM_DEBUG_LED_SMDK | ||
162 | |||
163 | config SAMSUNG_PM_CHECK | ||
164 | bool "S3C2410 PM Suspend Memory CRC" | ||
165 | - depends on PM | ||
166 | + depends on PM && (PLAT_S3C24XX || ARCH_S3C64XX || ARCH_S5PV210) | ||
167 | select CRC32 | ||
168 | help | ||
169 | Enable the PM code's memory area checksum over sleep. This option | ||
170 | diff --git a/arch/x86/kernel/cpu/cyrix.c b/arch/x86/kernel/cpu/cyrix.c | ||
171 | index d39cfb2c6b63..311d0fad17e6 100644 | ||
172 | --- a/arch/x86/kernel/cpu/cyrix.c | ||
173 | +++ b/arch/x86/kernel/cpu/cyrix.c | ||
174 | @@ -121,7 +121,7 @@ static void set_cx86_reorder(void) | ||
175 | setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10); /* enable MAPEN */ | ||
176 | |||
177 | /* Load/Store Serialize to mem access disable (=reorder it) */ | ||
178 | - setCx86_old(CX86_PCR0, getCx86_old(CX86_PCR0) & ~0x80); | ||
179 | + setCx86(CX86_PCR0, getCx86(CX86_PCR0) & ~0x80); | ||
180 | /* set load/store serialize from 1GB to 4GB */ | ||
181 | ccr3 |= 0xe0; | ||
182 | setCx86(CX86_CCR3, ccr3); | ||
183 | @@ -132,11 +132,11 @@ static void set_cx86_memwb(void) | ||
184 | pr_info("Enable Memory-Write-back mode on Cyrix/NSC processor.\n"); | ||
185 | |||
186 | /* CCR2 bit 2: unlock NW bit */ | ||
187 | - setCx86_old(CX86_CCR2, getCx86_old(CX86_CCR2) & ~0x04); | ||
188 | + setCx86(CX86_CCR2, getCx86(CX86_CCR2) & ~0x04); | ||
189 | /* set 'Not Write-through' */ | ||
190 | write_cr0(read_cr0() | X86_CR0_NW); | ||
191 | /* CCR2 bit 2: lock NW bit and set WT1 */ | ||
192 | - setCx86_old(CX86_CCR2, getCx86_old(CX86_CCR2) | 0x14); | ||
193 | + setCx86(CX86_CCR2, getCx86(CX86_CCR2) | 0x14); | ||
194 | } | ||
195 | |||
196 | /* | ||
197 | @@ -150,14 +150,14 @@ static void geode_configure(void) | ||
198 | local_irq_save(flags); | ||
199 | |||
200 | /* Suspend on halt power saving and enable #SUSP pin */ | ||
201 | - setCx86_old(CX86_CCR2, getCx86_old(CX86_CCR2) | 0x88); | ||
202 | + setCx86(CX86_CCR2, getCx86(CX86_CCR2) | 0x88); | ||
203 | |||
204 | ccr3 = getCx86(CX86_CCR3); | ||
205 | setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10); /* enable MAPEN */ | ||
206 | |||
207 | |||
208 | /* FPU fast, DTE cache, Mem bypass */ | ||
209 | - setCx86_old(CX86_CCR4, getCx86_old(CX86_CCR4) | 0x38); | ||
210 | + setCx86(CX86_CCR4, getCx86(CX86_CCR4) | 0x38); | ||
211 | setCx86(CX86_CCR3, ccr3); /* disable MAPEN */ | ||
212 | |||
213 | set_cx86_memwb(); | ||
214 | @@ -293,7 +293,7 @@ static void init_cyrix(struct cpuinfo_x86 *c) | ||
215 | /* GXm supports extended cpuid levels 'ala' AMD */ | ||
216 | if (c->cpuid_level == 2) { | ||
217 | /* Enable cxMMX extensions (GX1 Datasheet 54) */ | ||
218 | - setCx86_old(CX86_CCR7, getCx86_old(CX86_CCR7) | 1); | ||
219 | + setCx86(CX86_CCR7, getCx86(CX86_CCR7) | 1); | ||
220 | |||
221 | /* | ||
222 | * GXm : 0x30 ... 0x5f GXm datasheet 51 | ||
223 | @@ -316,7 +316,7 @@ static void init_cyrix(struct cpuinfo_x86 *c) | ||
224 | if (dir1 > 7) { | ||
225 | dir0_msn++; /* M II */ | ||
226 | /* Enable MMX extensions (App note 108) */ | ||
227 | - setCx86_old(CX86_CCR7, getCx86_old(CX86_CCR7)|1); | ||
228 | + setCx86(CX86_CCR7, getCx86(CX86_CCR7)|1); | ||
229 | } else { | ||
230 | /* A 6x86MX - it has the bug. */ | ||
231 | set_cpu_bug(c, X86_BUG_COMA); | ||
232 | diff --git a/arch/x86/kernel/hpet.c b/arch/x86/kernel/hpet.c | ||
233 | index 756634f14df6..775c23d4021a 100644 | ||
234 | --- a/arch/x86/kernel/hpet.c | ||
235 | +++ b/arch/x86/kernel/hpet.c | ||
236 | @@ -914,6 +914,8 @@ int __init hpet_enable(void) | ||
237 | return 0; | ||
238 | |||
239 | hpet_set_mapping(); | ||
240 | + if (!hpet_virt_address) | ||
241 | + return 0; | ||
242 | |||
243 | /* | ||
244 | * Read the period and check for a sane value: | ||
245 | diff --git a/arch/x86/kernel/hw_breakpoint.c b/arch/x86/kernel/hw_breakpoint.c | ||
246 | index 8771766d46b6..9954a604a822 100644 | ||
247 | --- a/arch/x86/kernel/hw_breakpoint.c | ||
248 | +++ b/arch/x86/kernel/hw_breakpoint.c | ||
249 | @@ -352,6 +352,7 @@ int arch_validate_hwbkpt_settings(struct perf_event *bp) | ||
250 | #endif | ||
251 | default: | ||
252 | WARN_ON_ONCE(1); | ||
253 | + return -EINVAL; | ||
254 | } | ||
255 | |||
256 | /* | ||
257 | diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c | ||
258 | index ad0b13ad4bbb..4a76000bcf7a 100644 | ||
259 | --- a/drivers/acpi/sbs.c | ||
260 | +++ b/drivers/acpi/sbs.c | ||
261 | @@ -443,9 +443,13 @@ static int acpi_ac_get_present(struct acpi_sbs *sbs) | ||
262 | |||
263 | /* | ||
264 | * The spec requires that bit 4 always be 1. If it's not set, assume | ||
265 | - * that the implementation doesn't support an SBS charger | ||
266 | + * that the implementation doesn't support an SBS charger. | ||
267 | + * | ||
268 | + * And on some MacBooks a status of 0xffff is always returned, no | ||
269 | + * matter whether the charger is plugged in or not, which is also | ||
270 | + * wrong, so ignore the SBS charger for those too. | ||
271 | */ | ||
272 | - if (!((status >> 4) & 0x1)) | ||
273 | + if (!((status >> 4) & 0x1) || status == 0xffff) | ||
274 | return -ENODEV; | ||
275 | |||
276 | sbs->charger_present = (status >> 15) & 0x1; | ||
277 | diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c | ||
278 | index fa0f66809503..d29f78441cdb 100644 | ||
279 | --- a/drivers/char/tpm/tpm_crb.c | ||
280 | +++ b/drivers/char/tpm/tpm_crb.c | ||
281 | @@ -102,19 +102,29 @@ static int crb_recv(struct tpm_chip *chip, u8 *buf, size_t count) | ||
282 | struct crb_priv *priv = dev_get_drvdata(&chip->dev); | ||
283 | unsigned int expected; | ||
284 | |||
285 | - /* sanity check */ | ||
286 | - if (count < 6) | ||
287 | + /* A sanity check that the upper layer wants to get at least the header | ||
288 | + * as that is the minimum size for any TPM response. | ||
289 | + */ | ||
290 | + if (count < TPM_HEADER_SIZE) | ||
291 | return -EIO; | ||
292 | |||
293 | + /* If this bit is set, according to the spec, the TPM is in | ||
294 | + * unrecoverable condition. | ||
295 | + */ | ||
296 | if (ioread32(&priv->cca->sts) & CRB_CTRL_STS_ERROR) | ||
297 | return -EIO; | ||
298 | |||
299 | - memcpy_fromio(buf, priv->rsp, 6); | ||
300 | - expected = be32_to_cpup((__be32 *) &buf[2]); | ||
301 | - if (expected > count || expected < 6) | ||
302 | + /* Read the first 8 bytes in order to get the length of the response. | ||
303 | + * We read exactly a quad word in order to make sure that the remaining | ||
304 | + * reads will be aligned. | ||
305 | + */ | ||
306 | + memcpy_fromio(buf, priv->rsp, 8); | ||
307 | + | ||
308 | + expected = be32_to_cpup((__be32 *)&buf[2]); | ||
309 | + if (expected > count || expected < TPM_HEADER_SIZE) | ||
310 | return -EIO; | ||
311 | |||
312 | - memcpy_fromio(&buf[6], &priv->rsp[6], expected - 6); | ||
313 | + memcpy_fromio(&buf[8], &priv->rsp[8], expected - 8); | ||
314 | |||
315 | return expected; | ||
316 | } | ||
317 | diff --git a/drivers/gpio/gpio-pxa.c b/drivers/gpio/gpio-pxa.c | ||
318 | index 7a6305884f97..32d22bdf7164 100644 | ||
319 | --- a/drivers/gpio/gpio-pxa.c | ||
320 | +++ b/drivers/gpio/gpio-pxa.c | ||
321 | @@ -774,6 +774,9 @@ static int pxa_gpio_suspend(void) | ||
322 | struct pxa_gpio_bank *c; | ||
323 | int gpio; | ||
324 | |||
325 | + if (!pchip) | ||
326 | + return 0; | ||
327 | + | ||
328 | for_each_gpio_bank(gpio, c, pchip) { | ||
329 | c->saved_gplr = readl_relaxed(c->regbase + GPLR_OFFSET); | ||
330 | c->saved_gpdr = readl_relaxed(c->regbase + GPDR_OFFSET); | ||
331 | @@ -792,6 +795,9 @@ static void pxa_gpio_resume(void) | ||
332 | struct pxa_gpio_bank *c; | ||
333 | int gpio; | ||
334 | |||
335 | + if (!pchip) | ||
336 | + return; | ||
337 | + | ||
338 | for_each_gpio_bank(gpio, c, pchip) { | ||
339 | /* restore level with set/clear */ | ||
340 | writel_relaxed(c->saved_gplr, c->regbase + GPSR_OFFSET); | ||
341 | diff --git a/drivers/hid/i2c-hid/Makefile b/drivers/hid/i2c-hid/Makefile | ||
342 | index 832d8f9aaba2..099e1ce2f234 100644 | ||
343 | --- a/drivers/hid/i2c-hid/Makefile | ||
344 | +++ b/drivers/hid/i2c-hid/Makefile | ||
345 | @@ -3,3 +3,6 @@ | ||
346 | # | ||
347 | |||
348 | obj-$(CONFIG_I2C_HID) += i2c-hid.o | ||
349 | + | ||
350 | +i2c-hid-objs = i2c-hid-core.o | ||
351 | +i2c-hid-$(CONFIG_DMI) += i2c-hid-dmi-quirks.o | ||
352 | diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c | ||
353 | new file mode 100644 | ||
354 | index 000000000000..850527d5fab1 | ||
355 | --- /dev/null | ||
356 | +++ b/drivers/hid/i2c-hid/i2c-hid-core.c | ||
357 | @@ -0,0 +1,1359 @@ | ||
358 | +/* | ||
359 | + * HID over I2C protocol implementation | ||
360 | + * | ||
361 | + * Copyright (c) 2012 Benjamin Tissoires <benjamin.tissoires@gmail.com> | ||
362 | + * Copyright (c) 2012 Ecole Nationale de l'Aviation Civile, France | ||
363 | + * Copyright (c) 2012 Red Hat, Inc | ||
364 | + * | ||
365 | + * This code is partly based on "USB HID support for Linux": | ||
366 | + * | ||
367 | + * Copyright (c) 1999 Andreas Gal | ||
368 | + * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> | ||
369 | + * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc | ||
370 | + * Copyright (c) 2007-2008 Oliver Neukum | ||
371 | + * Copyright (c) 2006-2010 Jiri Kosina | ||
372 | + * | ||
373 | + * This file is subject to the terms and conditions of the GNU General Public | ||
374 | + * License. See the file COPYING in the main directory of this archive for | ||
375 | + * more details. | ||
376 | + */ | ||
377 | + | ||
378 | +#include <linux/module.h> | ||
379 | +#include <linux/i2c.h> | ||
380 | +#include <linux/interrupt.h> | ||
381 | +#include <linux/input.h> | ||
382 | +#include <linux/delay.h> | ||
383 | +#include <linux/slab.h> | ||
384 | +#include <linux/pm.h> | ||
385 | +#include <linux/pm_runtime.h> | ||
386 | +#include <linux/device.h> | ||
387 | +#include <linux/wait.h> | ||
388 | +#include <linux/err.h> | ||
389 | +#include <linux/string.h> | ||
390 | +#include <linux/list.h> | ||
391 | +#include <linux/jiffies.h> | ||
392 | +#include <linux/kernel.h> | ||
393 | +#include <linux/hid.h> | ||
394 | +#include <linux/mutex.h> | ||
395 | +#include <linux/acpi.h> | ||
396 | +#include <linux/of.h> | ||
397 | +#include <linux/gpio/consumer.h> | ||
398 | + | ||
399 | +#include <linux/i2c/i2c-hid.h> | ||
400 | + | ||
401 | +#include "../hid-ids.h" | ||
402 | +#include "i2c-hid.h" | ||
403 | + | ||
404 | +/* quirks to control the device */ | ||
405 | +#define I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV BIT(0) | ||
406 | + | ||
407 | +/* flags */ | ||
408 | +#define I2C_HID_STARTED 0 | ||
409 | +#define I2C_HID_RESET_PENDING 1 | ||
410 | +#define I2C_HID_READ_PENDING 2 | ||
411 | + | ||
412 | +#define I2C_HID_PWR_ON 0x00 | ||
413 | +#define I2C_HID_PWR_SLEEP 0x01 | ||
414 | + | ||
415 | +/* debug option */ | ||
416 | +static bool debug; | ||
417 | +module_param(debug, bool, 0444); | ||
418 | +MODULE_PARM_DESC(debug, "print a lot of debug information"); | ||
419 | + | ||
420 | +#define i2c_hid_dbg(ihid, fmt, arg...) \ | ||
421 | +do { \ | ||
422 | + if (debug) \ | ||
423 | + dev_printk(KERN_DEBUG, &(ihid)->client->dev, fmt, ##arg); \ | ||
424 | +} while (0) | ||
425 | + | ||
426 | +struct i2c_hid_desc { | ||
427 | + __le16 wHIDDescLength; | ||
428 | + __le16 bcdVersion; | ||
429 | + __le16 wReportDescLength; | ||
430 | + __le16 wReportDescRegister; | ||
431 | + __le16 wInputRegister; | ||
432 | + __le16 wMaxInputLength; | ||
433 | + __le16 wOutputRegister; | ||
434 | + __le16 wMaxOutputLength; | ||
435 | + __le16 wCommandRegister; | ||
436 | + __le16 wDataRegister; | ||
437 | + __le16 wVendorID; | ||
438 | + __le16 wProductID; | ||
439 | + __le16 wVersionID; | ||
440 | + __le32 reserved; | ||
441 | +} __packed; | ||
442 | + | ||
443 | +struct i2c_hid_cmd { | ||
444 | + unsigned int registerIndex; | ||
445 | + __u8 opcode; | ||
446 | + unsigned int length; | ||
447 | + bool wait; | ||
448 | +}; | ||
449 | + | ||
450 | +union command { | ||
451 | + u8 data[0]; | ||
452 | + struct cmd { | ||
453 | + __le16 reg; | ||
454 | + __u8 reportTypeID; | ||
455 | + __u8 opcode; | ||
456 | + } __packed c; | ||
457 | +}; | ||
458 | + | ||
459 | +#define I2C_HID_CMD(opcode_) \ | ||
460 | + .opcode = opcode_, .length = 4, \ | ||
461 | + .registerIndex = offsetof(struct i2c_hid_desc, wCommandRegister) | ||
462 | + | ||
463 | +/* fetch HID descriptor */ | ||
464 | +static const struct i2c_hid_cmd hid_descr_cmd = { .length = 2 }; | ||
465 | +/* fetch report descriptors */ | ||
466 | +static const struct i2c_hid_cmd hid_report_descr_cmd = { | ||
467 | + .registerIndex = offsetof(struct i2c_hid_desc, | ||
468 | + wReportDescRegister), | ||
469 | + .opcode = 0x00, | ||
470 | + .length = 2 }; | ||
471 | +/* commands */ | ||
472 | +static const struct i2c_hid_cmd hid_reset_cmd = { I2C_HID_CMD(0x01), | ||
473 | + .wait = true }; | ||
474 | +static const struct i2c_hid_cmd hid_get_report_cmd = { I2C_HID_CMD(0x02) }; | ||
475 | +static const struct i2c_hid_cmd hid_set_report_cmd = { I2C_HID_CMD(0x03) }; | ||
476 | +static const struct i2c_hid_cmd hid_set_power_cmd = { I2C_HID_CMD(0x08) }; | ||
477 | +static const struct i2c_hid_cmd hid_no_cmd = { .length = 0 }; | ||
478 | + | ||
479 | +/* | ||
480 | + * These definitions are not used here, but are defined by the spec. | ||
481 | + * Keeping them here for documentation purposes. | ||
482 | + * | ||
483 | + * static const struct i2c_hid_cmd hid_get_idle_cmd = { I2C_HID_CMD(0x04) }; | ||
484 | + * static const struct i2c_hid_cmd hid_set_idle_cmd = { I2C_HID_CMD(0x05) }; | ||
485 | + * static const struct i2c_hid_cmd hid_get_protocol_cmd = { I2C_HID_CMD(0x06) }; | ||
486 | + * static const struct i2c_hid_cmd hid_set_protocol_cmd = { I2C_HID_CMD(0x07) }; | ||
487 | + */ | ||
488 | + | ||
489 | +static DEFINE_MUTEX(i2c_hid_open_mut); | ||
490 | + | ||
491 | +/* The main device structure */ | ||
492 | +struct i2c_hid { | ||
493 | + struct i2c_client *client; /* i2c client */ | ||
494 | + struct hid_device *hid; /* pointer to corresponding HID dev */ | ||
495 | + union { | ||
496 | + __u8 hdesc_buffer[sizeof(struct i2c_hid_desc)]; | ||
497 | + struct i2c_hid_desc hdesc; /* the HID Descriptor */ | ||
498 | + }; | ||
499 | + __le16 wHIDDescRegister; /* location of the i2c | ||
500 | + * register of the HID | ||
501 | + * descriptor. */ | ||
502 | + unsigned int bufsize; /* i2c buffer size */ | ||
503 | + u8 *inbuf; /* Input buffer */ | ||
504 | + u8 *rawbuf; /* Raw Input buffer */ | ||
505 | + u8 *cmdbuf; /* Command buffer */ | ||
506 | + u8 *argsbuf; /* Command arguments buffer */ | ||
507 | + | ||
508 | + unsigned long flags; /* device flags */ | ||
509 | + unsigned long quirks; /* Various quirks */ | ||
510 | + | ||
511 | + wait_queue_head_t wait; /* For waiting the interrupt */ | ||
512 | + struct gpio_desc *desc; | ||
513 | + int irq; | ||
514 | + | ||
515 | + struct i2c_hid_platform_data pdata; | ||
516 | + | ||
517 | + bool irq_wake_enabled; | ||
518 | + struct mutex reset_lock; | ||
519 | +}; | ||
520 | + | ||
521 | +static const struct i2c_hid_quirks { | ||
522 | + __u16 idVendor; | ||
523 | + __u16 idProduct; | ||
524 | + __u32 quirks; | ||
525 | +} i2c_hid_quirks[] = { | ||
526 | + { USB_VENDOR_ID_WEIDA, USB_DEVICE_ID_WEIDA_8752, | ||
527 | + I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV }, | ||
528 | + { USB_VENDOR_ID_WEIDA, USB_DEVICE_ID_WEIDA_8755, | ||
529 | + I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV }, | ||
530 | + { 0, 0 } | ||
531 | +}; | ||
532 | + | ||
533 | +/* | ||
534 | + * i2c_hid_lookup_quirk: return any quirks associated with a I2C HID device | ||
535 | + * @idVendor: the 16-bit vendor ID | ||
536 | + * @idProduct: the 16-bit product ID | ||
537 | + * | ||
538 | + * Returns: a u32 quirks value. | ||
539 | + */ | ||
540 | +static u32 i2c_hid_lookup_quirk(const u16 idVendor, const u16 idProduct) | ||
541 | +{ | ||
542 | + u32 quirks = 0; | ||
543 | + int n; | ||
544 | + | ||
545 | + for (n = 0; i2c_hid_quirks[n].idVendor; n++) | ||
546 | + if (i2c_hid_quirks[n].idVendor == idVendor && | ||
547 | + (i2c_hid_quirks[n].idProduct == (__u16)HID_ANY_ID || | ||
548 | + i2c_hid_quirks[n].idProduct == idProduct)) | ||
549 | + quirks = i2c_hid_quirks[n].quirks; | ||
550 | + | ||
551 | + return quirks; | ||
552 | +} | ||
553 | + | ||
554 | +static int __i2c_hid_command(struct i2c_client *client, | ||
555 | + const struct i2c_hid_cmd *command, u8 reportID, | ||
556 | + u8 reportType, u8 *args, int args_len, | ||
557 | + unsigned char *buf_recv, int data_len) | ||
558 | +{ | ||
559 | + struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
560 | + union command *cmd = (union command *)ihid->cmdbuf; | ||
561 | + int ret; | ||
562 | + struct i2c_msg msg[2]; | ||
563 | + int msg_num = 1; | ||
564 | + | ||
565 | + int length = command->length; | ||
566 | + bool wait = command->wait; | ||
567 | + unsigned int registerIndex = command->registerIndex; | ||
568 | + | ||
569 | + /* special case for hid_descr_cmd */ | ||
570 | + if (command == &hid_descr_cmd) { | ||
571 | + cmd->c.reg = ihid->wHIDDescRegister; | ||
572 | + } else { | ||
573 | + cmd->data[0] = ihid->hdesc_buffer[registerIndex]; | ||
574 | + cmd->data[1] = ihid->hdesc_buffer[registerIndex + 1]; | ||
575 | + } | ||
576 | + | ||
577 | + if (length > 2) { | ||
578 | + cmd->c.opcode = command->opcode; | ||
579 | + cmd->c.reportTypeID = reportID | reportType << 4; | ||
580 | + } | ||
581 | + | ||
582 | + memcpy(cmd->data + length, args, args_len); | ||
583 | + length += args_len; | ||
584 | + | ||
585 | + i2c_hid_dbg(ihid, "%s: cmd=%*ph\n", __func__, length, cmd->data); | ||
586 | + | ||
587 | + msg[0].addr = client->addr; | ||
588 | + msg[0].flags = client->flags & I2C_M_TEN; | ||
589 | + msg[0].len = length; | ||
590 | + msg[0].buf = cmd->data; | ||
591 | + if (data_len > 0) { | ||
592 | + msg[1].addr = client->addr; | ||
593 | + msg[1].flags = client->flags & I2C_M_TEN; | ||
594 | + msg[1].flags |= I2C_M_RD; | ||
595 | + msg[1].len = data_len; | ||
596 | + msg[1].buf = buf_recv; | ||
597 | + msg_num = 2; | ||
598 | + set_bit(I2C_HID_READ_PENDING, &ihid->flags); | ||
599 | + } | ||
600 | + | ||
601 | + if (wait) | ||
602 | + set_bit(I2C_HID_RESET_PENDING, &ihid->flags); | ||
603 | + | ||
604 | + ret = i2c_transfer(client->adapter, msg, msg_num); | ||
605 | + | ||
606 | + if (data_len > 0) | ||
607 | + clear_bit(I2C_HID_READ_PENDING, &ihid->flags); | ||
608 | + | ||
609 | + if (ret != msg_num) | ||
610 | + return ret < 0 ? ret : -EIO; | ||
611 | + | ||
612 | + ret = 0; | ||
613 | + | ||
614 | + if (wait) { | ||
615 | + i2c_hid_dbg(ihid, "%s: waiting...\n", __func__); | ||
616 | + if (!wait_event_timeout(ihid->wait, | ||
617 | + !test_bit(I2C_HID_RESET_PENDING, &ihid->flags), | ||
618 | + msecs_to_jiffies(5000))) | ||
619 | + ret = -ENODATA; | ||
620 | + i2c_hid_dbg(ihid, "%s: finished.\n", __func__); | ||
621 | + } | ||
622 | + | ||
623 | + return ret; | ||
624 | +} | ||
625 | + | ||
626 | +static int i2c_hid_command(struct i2c_client *client, | ||
627 | + const struct i2c_hid_cmd *command, | ||
628 | + unsigned char *buf_recv, int data_len) | ||
629 | +{ | ||
630 | + return __i2c_hid_command(client, command, 0, 0, NULL, 0, | ||
631 | + buf_recv, data_len); | ||
632 | +} | ||
633 | + | ||
634 | +static int i2c_hid_get_report(struct i2c_client *client, u8 reportType, | ||
635 | + u8 reportID, unsigned char *buf_recv, int data_len) | ||
636 | +{ | ||
637 | + struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
638 | + u8 args[3]; | ||
639 | + int ret; | ||
640 | + int args_len = 0; | ||
641 | + u16 readRegister = le16_to_cpu(ihid->hdesc.wDataRegister); | ||
642 | + | ||
643 | + i2c_hid_dbg(ihid, "%s\n", __func__); | ||
644 | + | ||
645 | + if (reportID >= 0x0F) { | ||
646 | + args[args_len++] = reportID; | ||
647 | + reportID = 0x0F; | ||
648 | + } | ||
649 | + | ||
650 | + args[args_len++] = readRegister & 0xFF; | ||
651 | + args[args_len++] = readRegister >> 8; | ||
652 | + | ||
653 | + ret = __i2c_hid_command(client, &hid_get_report_cmd, reportID, | ||
654 | + reportType, args, args_len, buf_recv, data_len); | ||
655 | + if (ret) { | ||
656 | + dev_err(&client->dev, | ||
657 | + "failed to retrieve report from device.\n"); | ||
658 | + return ret; | ||
659 | + } | ||
660 | + | ||
661 | + return 0; | ||
662 | +} | ||
663 | + | ||
664 | +/** | ||
665 | + * i2c_hid_set_or_send_report: forward an incoming report to the device | ||
666 | + * @client: the i2c_client of the device | ||
667 | + * @reportType: 0x03 for HID_FEATURE_REPORT ; 0x02 for HID_OUTPUT_REPORT | ||
668 | + * @reportID: the report ID | ||
669 | + * @buf: the actual data to transfer, without the report ID | ||
670 | + * @len: size of buf | ||
671 | + * @use_data: true: use SET_REPORT HID command, false: send plain OUTPUT report | ||
672 | + */ | ||
673 | +static int i2c_hid_set_or_send_report(struct i2c_client *client, u8 reportType, | ||
674 | + u8 reportID, unsigned char *buf, size_t data_len, bool use_data) | ||
675 | +{ | ||
676 | + struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
677 | + u8 *args = ihid->argsbuf; | ||
678 | + const struct i2c_hid_cmd *hidcmd; | ||
679 | + int ret; | ||
680 | + u16 dataRegister = le16_to_cpu(ihid->hdesc.wDataRegister); | ||
681 | + u16 outputRegister = le16_to_cpu(ihid->hdesc.wOutputRegister); | ||
682 | + u16 maxOutputLength = le16_to_cpu(ihid->hdesc.wMaxOutputLength); | ||
683 | + u16 size; | ||
684 | + int args_len; | ||
685 | + int index = 0; | ||
686 | + | ||
687 | + i2c_hid_dbg(ihid, "%s\n", __func__); | ||
688 | + | ||
689 | + if (data_len > ihid->bufsize) | ||
690 | + return -EINVAL; | ||
691 | + | ||
692 | + size = 2 /* size */ + | ||
693 | + (reportID ? 1 : 0) /* reportID */ + | ||
694 | + data_len /* buf */; | ||
695 | + args_len = (reportID >= 0x0F ? 1 : 0) /* optional third byte */ + | ||
696 | + 2 /* dataRegister */ + | ||
697 | + size /* args */; | ||
698 | + | ||
699 | + if (!use_data && maxOutputLength == 0) | ||
700 | + return -ENOSYS; | ||
701 | + | ||
702 | + if (reportID >= 0x0F) { | ||
703 | + args[index++] = reportID; | ||
704 | + reportID = 0x0F; | ||
705 | + } | ||
706 | + | ||
707 | + /* | ||
708 | + * use the data register for feature reports or if the device does not | ||
709 | + * support the output register | ||
710 | + */ | ||
711 | + if (use_data) { | ||
712 | + args[index++] = dataRegister & 0xFF; | ||
713 | + args[index++] = dataRegister >> 8; | ||
714 | + hidcmd = &hid_set_report_cmd; | ||
715 | + } else { | ||
716 | + args[index++] = outputRegister & 0xFF; | ||
717 | + args[index++] = outputRegister >> 8; | ||
718 | + hidcmd = &hid_no_cmd; | ||
719 | + } | ||
720 | + | ||
721 | + args[index++] = size & 0xFF; | ||
722 | + args[index++] = size >> 8; | ||
723 | + | ||
724 | + if (reportID) | ||
725 | + args[index++] = reportID; | ||
726 | + | ||
727 | + memcpy(&args[index], buf, data_len); | ||
728 | + | ||
729 | + ret = __i2c_hid_command(client, hidcmd, reportID, | ||
730 | + reportType, args, args_len, NULL, 0); | ||
731 | + if (ret) { | ||
732 | + dev_err(&client->dev, "failed to set a report to device.\n"); | ||
733 | + return ret; | ||
734 | + } | ||
735 | + | ||
736 | + return data_len; | ||
737 | +} | ||
738 | + | ||
739 | +static int i2c_hid_set_power(struct i2c_client *client, int power_state) | ||
740 | +{ | ||
741 | + struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
742 | + int ret; | ||
743 | + | ||
744 | + i2c_hid_dbg(ihid, "%s\n", __func__); | ||
745 | + | ||
746 | + /* | ||
747 | + * Some devices require to send a command to wakeup before power on. | ||
748 | + * The call will get a return value (EREMOTEIO) but device will be | ||
749 | + * triggered and activated. After that, it goes like a normal device. | ||
750 | + */ | ||
751 | + if (power_state == I2C_HID_PWR_ON && | ||
752 | + ihid->quirks & I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV) { | ||
753 | + ret = i2c_hid_command(client, &hid_set_power_cmd, NULL, 0); | ||
754 | + | ||
755 | + /* Device was already activated */ | ||
756 | + if (!ret) | ||
757 | + goto set_pwr_exit; | ||
758 | + } | ||
759 | + | ||
760 | + ret = __i2c_hid_command(client, &hid_set_power_cmd, power_state, | ||
761 | + 0, NULL, 0, NULL, 0); | ||
762 | + | ||
763 | + if (ret) | ||
764 | + dev_err(&client->dev, "failed to change power setting.\n"); | ||
765 | + | ||
766 | +set_pwr_exit: | ||
767 | + return ret; | ||
768 | +} | ||
769 | + | ||
770 | +static int i2c_hid_hwreset(struct i2c_client *client) | ||
771 | +{ | ||
772 | + struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
773 | + int ret; | ||
774 | + | ||
775 | + i2c_hid_dbg(ihid, "%s\n", __func__); | ||
776 | + | ||
777 | + /* | ||
778 | + * This prevents sending feature reports while the device is | ||
779 | + * being reset. Otherwise we may lose the reset complete | ||
780 | + * interrupt. | ||
781 | + */ | ||
782 | + mutex_lock(&ihid->reset_lock); | ||
783 | + | ||
784 | + ret = i2c_hid_set_power(client, I2C_HID_PWR_ON); | ||
785 | + if (ret) | ||
786 | + goto out_unlock; | ||
787 | + | ||
788 | + /* | ||
789 | + * The HID over I2C specification states that if a DEVICE needs time | ||
790 | + * after the PWR_ON request, it should utilise CLOCK stretching. | ||
791 | + * However, it has been observered that the Windows driver provides a | ||
792 | + * 1ms sleep between the PWR_ON and RESET requests and that some devices | ||
793 | + * rely on this. | ||
794 | + */ | ||
795 | + usleep_range(1000, 5000); | ||
796 | + | ||
797 | + i2c_hid_dbg(ihid, "resetting...\n"); | ||
798 | + | ||
799 | + ret = i2c_hid_command(client, &hid_reset_cmd, NULL, 0); | ||
800 | + if (ret) { | ||
801 | + dev_err(&client->dev, "failed to reset device.\n"); | ||
802 | + i2c_hid_set_power(client, I2C_HID_PWR_SLEEP); | ||
803 | + } | ||
804 | + | ||
805 | +out_unlock: | ||
806 | + mutex_unlock(&ihid->reset_lock); | ||
807 | + return ret; | ||
808 | +} | ||
809 | + | ||
810 | +static void i2c_hid_get_input(struct i2c_hid *ihid) | ||
811 | +{ | ||
812 | + int ret; | ||
813 | + u32 ret_size; | ||
814 | + int size = le16_to_cpu(ihid->hdesc.wMaxInputLength); | ||
815 | + | ||
816 | + if (size > ihid->bufsize) | ||
817 | + size = ihid->bufsize; | ||
818 | + | ||
819 | + ret = i2c_master_recv(ihid->client, ihid->inbuf, size); | ||
820 | + if (ret != size) { | ||
821 | + if (ret < 0) | ||
822 | + return; | ||
823 | + | ||
824 | + dev_err(&ihid->client->dev, "%s: got %d data instead of %d\n", | ||
825 | + __func__, ret, size); | ||
826 | + return; | ||
827 | + } | ||
828 | + | ||
829 | + ret_size = ihid->inbuf[0] | ihid->inbuf[1] << 8; | ||
830 | + | ||
831 | + if (!ret_size) { | ||
832 | + /* host or device initiated RESET completed */ | ||
833 | + if (test_and_clear_bit(I2C_HID_RESET_PENDING, &ihid->flags)) | ||
834 | + wake_up(&ihid->wait); | ||
835 | + return; | ||
836 | + } | ||
837 | + | ||
838 | + if ((ret_size > size) || (ret_size < 2)) { | ||
839 | + dev_err(&ihid->client->dev, "%s: incomplete report (%d/%d)\n", | ||
840 | + __func__, size, ret_size); | ||
841 | + return; | ||
842 | + } | ||
843 | + | ||
844 | + i2c_hid_dbg(ihid, "input: %*ph\n", ret_size, ihid->inbuf); | ||
845 | + | ||
846 | + if (test_bit(I2C_HID_STARTED, &ihid->flags)) | ||
847 | + hid_input_report(ihid->hid, HID_INPUT_REPORT, ihid->inbuf + 2, | ||
848 | + ret_size - 2, 1); | ||
849 | + | ||
850 | + return; | ||
851 | +} | ||
852 | + | ||
853 | +static irqreturn_t i2c_hid_irq(int irq, void *dev_id) | ||
854 | +{ | ||
855 | + struct i2c_hid *ihid = dev_id; | ||
856 | + | ||
857 | + if (test_bit(I2C_HID_READ_PENDING, &ihid->flags)) | ||
858 | + return IRQ_HANDLED; | ||
859 | + | ||
860 | + i2c_hid_get_input(ihid); | ||
861 | + | ||
862 | + return IRQ_HANDLED; | ||
863 | +} | ||
864 | + | ||
865 | +static int i2c_hid_get_report_length(struct hid_report *report) | ||
866 | +{ | ||
867 | + return ((report->size - 1) >> 3) + 1 + | ||
868 | + report->device->report_enum[report->type].numbered + 2; | ||
869 | +} | ||
870 | + | ||
871 | +static void i2c_hid_init_report(struct hid_report *report, u8 *buffer, | ||
872 | + size_t bufsize) | ||
873 | +{ | ||
874 | + struct hid_device *hid = report->device; | ||
875 | + struct i2c_client *client = hid->driver_data; | ||
876 | + struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
877 | + unsigned int size, ret_size; | ||
878 | + | ||
879 | + size = i2c_hid_get_report_length(report); | ||
880 | + if (i2c_hid_get_report(client, | ||
881 | + report->type == HID_FEATURE_REPORT ? 0x03 : 0x01, | ||
882 | + report->id, buffer, size)) | ||
883 | + return; | ||
884 | + | ||
885 | + i2c_hid_dbg(ihid, "report (len=%d): %*ph\n", size, size, buffer); | ||
886 | + | ||
887 | + ret_size = buffer[0] | (buffer[1] << 8); | ||
888 | + | ||
889 | + if (ret_size != size) { | ||
890 | + dev_err(&client->dev, "error in %s size:%d / ret_size:%d\n", | ||
891 | + __func__, size, ret_size); | ||
892 | + return; | ||
893 | + } | ||
894 | + | ||
895 | + /* hid->driver_lock is held as we are in probe function, | ||
896 | + * we just need to setup the input fields, so using | ||
897 | + * hid_report_raw_event is safe. */ | ||
898 | + hid_report_raw_event(hid, report->type, buffer + 2, size - 2, 1); | ||
899 | +} | ||
900 | + | ||
901 | +/* | ||
902 | + * Initialize all reports | ||
903 | + */ | ||
904 | +static void i2c_hid_init_reports(struct hid_device *hid) | ||
905 | +{ | ||
906 | + struct hid_report *report; | ||
907 | + struct i2c_client *client = hid->driver_data; | ||
908 | + struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
909 | + u8 *inbuf = kzalloc(ihid->bufsize, GFP_KERNEL); | ||
910 | + | ||
911 | + if (!inbuf) { | ||
912 | + dev_err(&client->dev, "can not retrieve initial reports\n"); | ||
913 | + return; | ||
914 | + } | ||
915 | + | ||
916 | + /* | ||
917 | + * The device must be powered on while we fetch initial reports | ||
918 | + * from it. | ||
919 | + */ | ||
920 | + pm_runtime_get_sync(&client->dev); | ||
921 | + | ||
922 | + list_for_each_entry(report, | ||
923 | + &hid->report_enum[HID_FEATURE_REPORT].report_list, list) | ||
924 | + i2c_hid_init_report(report, inbuf, ihid->bufsize); | ||
925 | + | ||
926 | + pm_runtime_put(&client->dev); | ||
927 | + | ||
928 | + kfree(inbuf); | ||
929 | +} | ||
930 | + | ||
931 | +/* | ||
932 | + * Traverse the supplied list of reports and find the longest | ||
933 | + */ | ||
934 | +static void i2c_hid_find_max_report(struct hid_device *hid, unsigned int type, | ||
935 | + unsigned int *max) | ||
936 | +{ | ||
937 | + struct hid_report *report; | ||
938 | + unsigned int size; | ||
939 | + | ||
940 | + /* We should not rely on wMaxInputLength, as some devices may set it to | ||
941 | + * a wrong length. */ | ||
942 | + list_for_each_entry(report, &hid->report_enum[type].report_list, list) { | ||
943 | + size = i2c_hid_get_report_length(report); | ||
944 | + if (*max < size) | ||
945 | + *max = size; | ||
946 | + } | ||
947 | +} | ||
948 | + | ||
949 | +static void i2c_hid_free_buffers(struct i2c_hid *ihid) | ||
950 | +{ | ||
951 | + kfree(ihid->inbuf); | ||
952 | + kfree(ihid->rawbuf); | ||
953 | + kfree(ihid->argsbuf); | ||
954 | + kfree(ihid->cmdbuf); | ||
955 | + ihid->inbuf = NULL; | ||
956 | + ihid->rawbuf = NULL; | ||
957 | + ihid->cmdbuf = NULL; | ||
958 | + ihid->argsbuf = NULL; | ||
959 | + ihid->bufsize = 0; | ||
960 | +} | ||
961 | + | ||
962 | +static int i2c_hid_alloc_buffers(struct i2c_hid *ihid, size_t report_size) | ||
963 | +{ | ||
964 | + /* the worst case is computed from the set_report command with a | ||
965 | + * reportID > 15 and the maximum report length */ | ||
966 | + int args_len = sizeof(__u8) + /* ReportID */ | ||
967 | + sizeof(__u8) + /* optional ReportID byte */ | ||
968 | + sizeof(__u16) + /* data register */ | ||
969 | + sizeof(__u16) + /* size of the report */ | ||
970 | + report_size; /* report */ | ||
971 | + | ||
972 | + ihid->inbuf = kzalloc(report_size, GFP_KERNEL); | ||
973 | + ihid->rawbuf = kzalloc(report_size, GFP_KERNEL); | ||
974 | + ihid->argsbuf = kzalloc(args_len, GFP_KERNEL); | ||
975 | + ihid->cmdbuf = kzalloc(sizeof(union command) + args_len, GFP_KERNEL); | ||
976 | + | ||
977 | + if (!ihid->inbuf || !ihid->rawbuf || !ihid->argsbuf || !ihid->cmdbuf) { | ||
978 | + i2c_hid_free_buffers(ihid); | ||
979 | + return -ENOMEM; | ||
980 | + } | ||
981 | + | ||
982 | + ihid->bufsize = report_size; | ||
983 | + | ||
984 | + return 0; | ||
985 | +} | ||
986 | + | ||
987 | +static int i2c_hid_get_raw_report(struct hid_device *hid, | ||
988 | + unsigned char report_number, __u8 *buf, size_t count, | ||
989 | + unsigned char report_type) | ||
990 | +{ | ||
991 | + struct i2c_client *client = hid->driver_data; | ||
992 | + struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
993 | + size_t ret_count, ask_count; | ||
994 | + int ret; | ||
995 | + | ||
996 | + if (report_type == HID_OUTPUT_REPORT) | ||
997 | + return -EINVAL; | ||
998 | + | ||
999 | + /* +2 bytes to include the size of the reply in the query buffer */ | ||
1000 | + ask_count = min(count + 2, (size_t)ihid->bufsize); | ||
1001 | + | ||
1002 | + ret = i2c_hid_get_report(client, | ||
1003 | + report_type == HID_FEATURE_REPORT ? 0x03 : 0x01, | ||
1004 | + report_number, ihid->rawbuf, ask_count); | ||
1005 | + | ||
1006 | + if (ret < 0) | ||
1007 | + return ret; | ||
1008 | + | ||
1009 | + ret_count = ihid->rawbuf[0] | (ihid->rawbuf[1] << 8); | ||
1010 | + | ||
1011 | + if (ret_count <= 2) | ||
1012 | + return 0; | ||
1013 | + | ||
1014 | + ret_count = min(ret_count, ask_count); | ||
1015 | + | ||
1016 | + /* The query buffer contains the size, dropping it in the reply */ | ||
1017 | + count = min(count, ret_count - 2); | ||
1018 | + memcpy(buf, ihid->rawbuf + 2, count); | ||
1019 | + | ||
1020 | + return count; | ||
1021 | +} | ||
1022 | + | ||
1023 | +static int i2c_hid_output_raw_report(struct hid_device *hid, __u8 *buf, | ||
1024 | + size_t count, unsigned char report_type, bool use_data) | ||
1025 | +{ | ||
1026 | + struct i2c_client *client = hid->driver_data; | ||
1027 | + struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
1028 | + int report_id = buf[0]; | ||
1029 | + int ret; | ||
1030 | + | ||
1031 | + if (report_type == HID_INPUT_REPORT) | ||
1032 | + return -EINVAL; | ||
1033 | + | ||
1034 | + mutex_lock(&ihid->reset_lock); | ||
1035 | + | ||
1036 | + if (report_id) { | ||
1037 | + buf++; | ||
1038 | + count--; | ||
1039 | + } | ||
1040 | + | ||
1041 | + ret = i2c_hid_set_or_send_report(client, | ||
1042 | + report_type == HID_FEATURE_REPORT ? 0x03 : 0x02, | ||
1043 | + report_id, buf, count, use_data); | ||
1044 | + | ||
1045 | + if (report_id && ret >= 0) | ||
1046 | + ret++; /* add report_id to the number of transfered bytes */ | ||
1047 | + | ||
1048 | + mutex_unlock(&ihid->reset_lock); | ||
1049 | + | ||
1050 | + return ret; | ||
1051 | +} | ||
1052 | + | ||
1053 | +static int i2c_hid_output_report(struct hid_device *hid, __u8 *buf, | ||
1054 | + size_t count) | ||
1055 | +{ | ||
1056 | + return i2c_hid_output_raw_report(hid, buf, count, HID_OUTPUT_REPORT, | ||
1057 | + false); | ||
1058 | +} | ||
1059 | + | ||
1060 | +static int i2c_hid_raw_request(struct hid_device *hid, unsigned char reportnum, | ||
1061 | + __u8 *buf, size_t len, unsigned char rtype, | ||
1062 | + int reqtype) | ||
1063 | +{ | ||
1064 | + switch (reqtype) { | ||
1065 | + case HID_REQ_GET_REPORT: | ||
1066 | + return i2c_hid_get_raw_report(hid, reportnum, buf, len, rtype); | ||
1067 | + case HID_REQ_SET_REPORT: | ||
1068 | + if (buf[0] != reportnum) | ||
1069 | + return -EINVAL; | ||
1070 | + return i2c_hid_output_raw_report(hid, buf, len, rtype, true); | ||
1071 | + default: | ||
1072 | + return -EIO; | ||
1073 | + } | ||
1074 | +} | ||
1075 | + | ||
1076 | +static int i2c_hid_parse(struct hid_device *hid) | ||
1077 | +{ | ||
1078 | + struct i2c_client *client = hid->driver_data; | ||
1079 | + struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
1080 | + struct i2c_hid_desc *hdesc = &ihid->hdesc; | ||
1081 | + unsigned int rsize; | ||
1082 | + char *rdesc; | ||
1083 | + int ret; | ||
1084 | + int tries = 3; | ||
1085 | + char *use_override; | ||
1086 | + | ||
1087 | + i2c_hid_dbg(ihid, "entering %s\n", __func__); | ||
1088 | + | ||
1089 | + rsize = le16_to_cpu(hdesc->wReportDescLength); | ||
1090 | + if (!rsize || rsize > HID_MAX_DESCRIPTOR_SIZE) { | ||
1091 | + dbg_hid("weird size of report descriptor (%u)\n", rsize); | ||
1092 | + return -EINVAL; | ||
1093 | + } | ||
1094 | + | ||
1095 | + do { | ||
1096 | + ret = i2c_hid_hwreset(client); | ||
1097 | + if (ret) | ||
1098 | + msleep(1000); | ||
1099 | + } while (tries-- > 0 && ret); | ||
1100 | + | ||
1101 | + if (ret) | ||
1102 | + return ret; | ||
1103 | + | ||
1104 | + use_override = i2c_hid_get_dmi_hid_report_desc_override(client->name, | ||
1105 | + &rsize); | ||
1106 | + | ||
1107 | + if (use_override) { | ||
1108 | + rdesc = use_override; | ||
1109 | + i2c_hid_dbg(ihid, "Using a HID report descriptor override\n"); | ||
1110 | + } else { | ||
1111 | + rdesc = kzalloc(rsize, GFP_KERNEL); | ||
1112 | + | ||
1113 | + if (!rdesc) { | ||
1114 | + dbg_hid("couldn't allocate rdesc memory\n"); | ||
1115 | + return -ENOMEM; | ||
1116 | + } | ||
1117 | + | ||
1118 | + i2c_hid_dbg(ihid, "asking HID report descriptor\n"); | ||
1119 | + | ||
1120 | + ret = i2c_hid_command(client, &hid_report_descr_cmd, | ||
1121 | + rdesc, rsize); | ||
1122 | + if (ret) { | ||
1123 | + hid_err(hid, "reading report descriptor failed\n"); | ||
1124 | + kfree(rdesc); | ||
1125 | + return -EIO; | ||
1126 | + } | ||
1127 | + } | ||
1128 | + | ||
1129 | + i2c_hid_dbg(ihid, "Report Descriptor: %*ph\n", rsize, rdesc); | ||
1130 | + | ||
1131 | + ret = hid_parse_report(hid, rdesc, rsize); | ||
1132 | + if (!use_override) | ||
1133 | + kfree(rdesc); | ||
1134 | + | ||
1135 | + if (ret) { | ||
1136 | + dbg_hid("parsing report descriptor failed\n"); | ||
1137 | + return ret; | ||
1138 | + } | ||
1139 | + | ||
1140 | + return 0; | ||
1141 | +} | ||
1142 | + | ||
1143 | +static int i2c_hid_start(struct hid_device *hid) | ||
1144 | +{ | ||
1145 | + struct i2c_client *client = hid->driver_data; | ||
1146 | + struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
1147 | + int ret; | ||
1148 | + unsigned int bufsize = HID_MIN_BUFFER_SIZE; | ||
1149 | + | ||
1150 | + i2c_hid_find_max_report(hid, HID_INPUT_REPORT, &bufsize); | ||
1151 | + i2c_hid_find_max_report(hid, HID_OUTPUT_REPORT, &bufsize); | ||
1152 | + i2c_hid_find_max_report(hid, HID_FEATURE_REPORT, &bufsize); | ||
1153 | + | ||
1154 | + if (bufsize > ihid->bufsize) { | ||
1155 | + i2c_hid_free_buffers(ihid); | ||
1156 | + | ||
1157 | + ret = i2c_hid_alloc_buffers(ihid, bufsize); | ||
1158 | + | ||
1159 | + if (ret) | ||
1160 | + return ret; | ||
1161 | + } | ||
1162 | + | ||
1163 | + if (!(hid->quirks & HID_QUIRK_NO_INIT_REPORTS)) | ||
1164 | + i2c_hid_init_reports(hid); | ||
1165 | + | ||
1166 | + return 0; | ||
1167 | +} | ||
1168 | + | ||
1169 | +static void i2c_hid_stop(struct hid_device *hid) | ||
1170 | +{ | ||
1171 | + hid->claimed = 0; | ||
1172 | +} | ||
1173 | + | ||
1174 | +static int i2c_hid_open(struct hid_device *hid) | ||
1175 | +{ | ||
1176 | + struct i2c_client *client = hid->driver_data; | ||
1177 | + struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
1178 | + int ret = 0; | ||
1179 | + | ||
1180 | + mutex_lock(&i2c_hid_open_mut); | ||
1181 | + if (!hid->open++) { | ||
1182 | + ret = pm_runtime_get_sync(&client->dev); | ||
1183 | + if (ret < 0) { | ||
1184 | + hid->open--; | ||
1185 | + goto done; | ||
1186 | + } | ||
1187 | + set_bit(I2C_HID_STARTED, &ihid->flags); | ||
1188 | + } | ||
1189 | +done: | ||
1190 | + mutex_unlock(&i2c_hid_open_mut); | ||
1191 | + return ret < 0 ? ret : 0; | ||
1192 | +} | ||
1193 | + | ||
1194 | +static void i2c_hid_close(struct hid_device *hid) | ||
1195 | +{ | ||
1196 | + struct i2c_client *client = hid->driver_data; | ||
1197 | + struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
1198 | + | ||
1199 | + /* protecting hid->open to make sure we don't restart | ||
1200 | + * data acquistion due to a resumption we no longer | ||
1201 | + * care about | ||
1202 | + */ | ||
1203 | + mutex_lock(&i2c_hid_open_mut); | ||
1204 | + if (!--hid->open) { | ||
1205 | + clear_bit(I2C_HID_STARTED, &ihid->flags); | ||
1206 | + | ||
1207 | + /* Save some power */ | ||
1208 | + pm_runtime_put(&client->dev); | ||
1209 | + } | ||
1210 | + mutex_unlock(&i2c_hid_open_mut); | ||
1211 | +} | ||
1212 | + | ||
1213 | +static int i2c_hid_power(struct hid_device *hid, int lvl) | ||
1214 | +{ | ||
1215 | + struct i2c_client *client = hid->driver_data; | ||
1216 | + struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
1217 | + | ||
1218 | + i2c_hid_dbg(ihid, "%s lvl:%d\n", __func__, lvl); | ||
1219 | + | ||
1220 | + switch (lvl) { | ||
1221 | + case PM_HINT_FULLON: | ||
1222 | + pm_runtime_get_sync(&client->dev); | ||
1223 | + break; | ||
1224 | + case PM_HINT_NORMAL: | ||
1225 | + pm_runtime_put(&client->dev); | ||
1226 | + break; | ||
1227 | + } | ||
1228 | + return 0; | ||
1229 | +} | ||
1230 | + | ||
1231 | +static struct hid_ll_driver i2c_hid_ll_driver = { | ||
1232 | + .parse = i2c_hid_parse, | ||
1233 | + .start = i2c_hid_start, | ||
1234 | + .stop = i2c_hid_stop, | ||
1235 | + .open = i2c_hid_open, | ||
1236 | + .close = i2c_hid_close, | ||
1237 | + .power = i2c_hid_power, | ||
1238 | + .output_report = i2c_hid_output_report, | ||
1239 | + .raw_request = i2c_hid_raw_request, | ||
1240 | +}; | ||
1241 | + | ||
1242 | +static int i2c_hid_init_irq(struct i2c_client *client) | ||
1243 | +{ | ||
1244 | + struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
1245 | + int ret; | ||
1246 | + | ||
1247 | + dev_dbg(&client->dev, "Requesting IRQ: %d\n", ihid->irq); | ||
1248 | + | ||
1249 | + ret = request_threaded_irq(ihid->irq, NULL, i2c_hid_irq, | ||
1250 | + IRQF_TRIGGER_LOW | IRQF_ONESHOT, | ||
1251 | + client->name, ihid); | ||
1252 | + if (ret < 0) { | ||
1253 | + dev_warn(&client->dev, | ||
1254 | + "Could not register for %s interrupt, irq = %d," | ||
1255 | + " ret = %d\n", | ||
1256 | + client->name, ihid->irq, ret); | ||
1257 | + | ||
1258 | + return ret; | ||
1259 | + } | ||
1260 | + | ||
1261 | + return 0; | ||
1262 | +} | ||
1263 | + | ||
1264 | +static int i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid) | ||
1265 | +{ | ||
1266 | + struct i2c_client *client = ihid->client; | ||
1267 | + struct i2c_hid_desc *hdesc = &ihid->hdesc; | ||
1268 | + unsigned int dsize; | ||
1269 | + int ret; | ||
1270 | + | ||
1271 | + /* i2c hid fetch using a fixed descriptor size (30 bytes) */ | ||
1272 | + if (i2c_hid_get_dmi_i2c_hid_desc_override(client->name)) { | ||
1273 | + i2c_hid_dbg(ihid, "Using a HID descriptor override\n"); | ||
1274 | + ihid->hdesc = | ||
1275 | + *i2c_hid_get_dmi_i2c_hid_desc_override(client->name); | ||
1276 | + } else { | ||
1277 | + i2c_hid_dbg(ihid, "Fetching the HID descriptor\n"); | ||
1278 | + ret = i2c_hid_command(client, &hid_descr_cmd, | ||
1279 | + ihid->hdesc_buffer, | ||
1280 | + sizeof(struct i2c_hid_desc)); | ||
1281 | + if (ret) { | ||
1282 | + dev_err(&client->dev, "hid_descr_cmd failed\n"); | ||
1283 | + return -ENODEV; | ||
1284 | + } | ||
1285 | + } | ||
1286 | + | ||
1287 | + /* Validate the length of HID descriptor, the 4 first bytes: | ||
1288 | + * bytes 0-1 -> length | ||
1289 | + * bytes 2-3 -> bcdVersion (has to be 1.00) */ | ||
1290 | + /* check bcdVersion == 1.0 */ | ||
1291 | + if (le16_to_cpu(hdesc->bcdVersion) != 0x0100) { | ||
1292 | + dev_err(&client->dev, | ||
1293 | + "unexpected HID descriptor bcdVersion (0x%04hx)\n", | ||
1294 | + le16_to_cpu(hdesc->bcdVersion)); | ||
1295 | + return -ENODEV; | ||
1296 | + } | ||
1297 | + | ||
1298 | + /* Descriptor length should be 30 bytes as per the specification */ | ||
1299 | + dsize = le16_to_cpu(hdesc->wHIDDescLength); | ||
1300 | + if (dsize != sizeof(struct i2c_hid_desc)) { | ||
1301 | + dev_err(&client->dev, "weird size of HID descriptor (%u)\n", | ||
1302 | + dsize); | ||
1303 | + return -ENODEV; | ||
1304 | + } | ||
1305 | + i2c_hid_dbg(ihid, "HID Descriptor: %*ph\n", dsize, ihid->hdesc_buffer); | ||
1306 | + return 0; | ||
1307 | +} | ||
1308 | + | ||
1309 | +#ifdef CONFIG_ACPI | ||
1310 | + | ||
1311 | +/* Default GPIO mapping */ | ||
1312 | +static const struct acpi_gpio_params i2c_hid_irq_gpio = { 0, 0, true }; | ||
1313 | +static const struct acpi_gpio_mapping i2c_hid_acpi_gpios[] = { | ||
1314 | + { "gpios", &i2c_hid_irq_gpio, 1 }, | ||
1315 | + { }, | ||
1316 | +}; | ||
1317 | + | ||
1318 | +static int i2c_hid_acpi_pdata(struct i2c_client *client, | ||
1319 | + struct i2c_hid_platform_data *pdata) | ||
1320 | +{ | ||
1321 | + static u8 i2c_hid_guid[] = { | ||
1322 | + 0xF7, 0xF6, 0xDF, 0x3C, 0x67, 0x42, 0x55, 0x45, | ||
1323 | + 0xAD, 0x05, 0xB3, 0x0A, 0x3D, 0x89, 0x38, 0xDE, | ||
1324 | + }; | ||
1325 | + union acpi_object *obj; | ||
1326 | + struct acpi_device *adev; | ||
1327 | + acpi_handle handle; | ||
1328 | + int ret; | ||
1329 | + | ||
1330 | + handle = ACPI_HANDLE(&client->dev); | ||
1331 | + if (!handle || acpi_bus_get_device(handle, &adev)) | ||
1332 | + return -ENODEV; | ||
1333 | + | ||
1334 | + obj = acpi_evaluate_dsm_typed(handle, i2c_hid_guid, 1, 1, NULL, | ||
1335 | + ACPI_TYPE_INTEGER); | ||
1336 | + if (!obj) { | ||
1337 | + dev_err(&client->dev, "device _DSM execution failed\n"); | ||
1338 | + return -ENODEV; | ||
1339 | + } | ||
1340 | + | ||
1341 | + pdata->hid_descriptor_address = obj->integer.value; | ||
1342 | + ACPI_FREE(obj); | ||
1343 | + | ||
1344 | + /* GPIOs are optional */ | ||
1345 | + ret = acpi_dev_add_driver_gpios(adev, i2c_hid_acpi_gpios); | ||
1346 | + return ret < 0 && ret != -ENXIO ? ret : 0; | ||
1347 | +} | ||
1348 | + | ||
1349 | +static void i2c_hid_acpi_fix_up_power(struct device *dev) | ||
1350 | +{ | ||
1351 | + acpi_handle handle = ACPI_HANDLE(dev); | ||
1352 | + struct acpi_device *adev; | ||
1353 | + | ||
1354 | + if (handle && acpi_bus_get_device(handle, &adev) == 0) | ||
1355 | + acpi_device_fix_up_power(adev); | ||
1356 | +} | ||
1357 | + | ||
1358 | +static const struct acpi_device_id i2c_hid_acpi_match[] = { | ||
1359 | + {"ACPI0C50", 0 }, | ||
1360 | + {"PNP0C50", 0 }, | ||
1361 | + { }, | ||
1362 | +}; | ||
1363 | +MODULE_DEVICE_TABLE(acpi, i2c_hid_acpi_match); | ||
1364 | +#else | ||
1365 | +static inline int i2c_hid_acpi_pdata(struct i2c_client *client, | ||
1366 | + struct i2c_hid_platform_data *pdata) | ||
1367 | +{ | ||
1368 | + return -ENODEV; | ||
1369 | +} | ||
1370 | + | ||
1371 | +static inline void i2c_hid_acpi_fix_up_power(struct device *dev) {} | ||
1372 | +#endif | ||
1373 | + | ||
1374 | +#ifdef CONFIG_OF | ||
1375 | +static int i2c_hid_of_probe(struct i2c_client *client, | ||
1376 | + struct i2c_hid_platform_data *pdata) | ||
1377 | +{ | ||
1378 | + struct device *dev = &client->dev; | ||
1379 | + u32 val; | ||
1380 | + int ret; | ||
1381 | + | ||
1382 | + ret = of_property_read_u32(dev->of_node, "hid-descr-addr", &val); | ||
1383 | + if (ret) { | ||
1384 | + dev_err(&client->dev, "HID register address not provided\n"); | ||
1385 | + return -ENODEV; | ||
1386 | + } | ||
1387 | + if (val >> 16) { | ||
1388 | + dev_err(&client->dev, "Bad HID register address: 0x%08x\n", | ||
1389 | + val); | ||
1390 | + return -EINVAL; | ||
1391 | + } | ||
1392 | + pdata->hid_descriptor_address = val; | ||
1393 | + | ||
1394 | + return 0; | ||
1395 | +} | ||
1396 | + | ||
1397 | +static const struct of_device_id i2c_hid_of_match[] = { | ||
1398 | + { .compatible = "hid-over-i2c" }, | ||
1399 | + {}, | ||
1400 | +}; | ||
1401 | +MODULE_DEVICE_TABLE(of, i2c_hid_of_match); | ||
1402 | +#else | ||
1403 | +static inline int i2c_hid_of_probe(struct i2c_client *client, | ||
1404 | + struct i2c_hid_platform_data *pdata) | ||
1405 | +{ | ||
1406 | + return -ENODEV; | ||
1407 | +} | ||
1408 | +#endif | ||
1409 | + | ||
1410 | +static int i2c_hid_probe(struct i2c_client *client, | ||
1411 | + const struct i2c_device_id *dev_id) | ||
1412 | +{ | ||
1413 | + int ret; | ||
1414 | + struct i2c_hid *ihid; | ||
1415 | + struct hid_device *hid; | ||
1416 | + __u16 hidRegister; | ||
1417 | + struct i2c_hid_platform_data *platform_data = client->dev.platform_data; | ||
1418 | + | ||
1419 | + dbg_hid("HID probe called for i2c 0x%02x\n", client->addr); | ||
1420 | + | ||
1421 | + ihid = kzalloc(sizeof(struct i2c_hid), GFP_KERNEL); | ||
1422 | + if (!ihid) | ||
1423 | + return -ENOMEM; | ||
1424 | + | ||
1425 | + if (client->dev.of_node) { | ||
1426 | + ret = i2c_hid_of_probe(client, &ihid->pdata); | ||
1427 | + if (ret) | ||
1428 | + goto err; | ||
1429 | + } else if (!platform_data) { | ||
1430 | + ret = i2c_hid_acpi_pdata(client, &ihid->pdata); | ||
1431 | + if (ret) { | ||
1432 | + dev_err(&client->dev, | ||
1433 | + "HID register address not provided\n"); | ||
1434 | + goto err; | ||
1435 | + } | ||
1436 | + } else { | ||
1437 | + ihid->pdata = *platform_data; | ||
1438 | + } | ||
1439 | + | ||
1440 | + if (client->irq > 0) { | ||
1441 | + ihid->irq = client->irq; | ||
1442 | + } else if (ACPI_COMPANION(&client->dev)) { | ||
1443 | + ihid->desc = gpiod_get(&client->dev, NULL, GPIOD_IN); | ||
1444 | + if (IS_ERR(ihid->desc)) { | ||
1445 | + dev_err(&client->dev, "Failed to get GPIO interrupt\n"); | ||
1446 | + return PTR_ERR(ihid->desc); | ||
1447 | + } | ||
1448 | + | ||
1449 | + ihid->irq = gpiod_to_irq(ihid->desc); | ||
1450 | + if (ihid->irq < 0) { | ||
1451 | + gpiod_put(ihid->desc); | ||
1452 | + dev_err(&client->dev, "Failed to convert GPIO to IRQ\n"); | ||
1453 | + return ihid->irq; | ||
1454 | + } | ||
1455 | + } | ||
1456 | + | ||
1457 | + i2c_set_clientdata(client, ihid); | ||
1458 | + | ||
1459 | + ihid->client = client; | ||
1460 | + | ||
1461 | + hidRegister = ihid->pdata.hid_descriptor_address; | ||
1462 | + ihid->wHIDDescRegister = cpu_to_le16(hidRegister); | ||
1463 | + | ||
1464 | + init_waitqueue_head(&ihid->wait); | ||
1465 | + mutex_init(&ihid->reset_lock); | ||
1466 | + | ||
1467 | + /* we need to allocate the command buffer without knowing the maximum | ||
1468 | + * size of the reports. Let's use HID_MIN_BUFFER_SIZE, then we do the | ||
1469 | + * real computation later. */ | ||
1470 | + ret = i2c_hid_alloc_buffers(ihid, HID_MIN_BUFFER_SIZE); | ||
1471 | + if (ret < 0) | ||
1472 | + goto err; | ||
1473 | + | ||
1474 | + i2c_hid_acpi_fix_up_power(&client->dev); | ||
1475 | + | ||
1476 | + pm_runtime_get_noresume(&client->dev); | ||
1477 | + pm_runtime_set_active(&client->dev); | ||
1478 | + pm_runtime_enable(&client->dev); | ||
1479 | + device_enable_async_suspend(&client->dev); | ||
1480 | + | ||
1481 | + /* Make sure there is something at this address */ | ||
1482 | + ret = i2c_smbus_read_byte(client); | ||
1483 | + if (ret < 0) { | ||
1484 | + dev_dbg(&client->dev, "nothing at this address: %d\n", ret); | ||
1485 | + ret = -ENXIO; | ||
1486 | + goto err_pm; | ||
1487 | + } | ||
1488 | + | ||
1489 | + ret = i2c_hid_fetch_hid_descriptor(ihid); | ||
1490 | + if (ret < 0) | ||
1491 | + goto err_pm; | ||
1492 | + | ||
1493 | + ret = i2c_hid_init_irq(client); | ||
1494 | + if (ret < 0) | ||
1495 | + goto err_pm; | ||
1496 | + | ||
1497 | + hid = hid_allocate_device(); | ||
1498 | + if (IS_ERR(hid)) { | ||
1499 | + ret = PTR_ERR(hid); | ||
1500 | + goto err_irq; | ||
1501 | + } | ||
1502 | + | ||
1503 | + ihid->hid = hid; | ||
1504 | + | ||
1505 | + hid->driver_data = client; | ||
1506 | + hid->ll_driver = &i2c_hid_ll_driver; | ||
1507 | + hid->dev.parent = &client->dev; | ||
1508 | + hid->bus = BUS_I2C; | ||
1509 | + hid->version = le16_to_cpu(ihid->hdesc.bcdVersion); | ||
1510 | + hid->vendor = le16_to_cpu(ihid->hdesc.wVendorID); | ||
1511 | + hid->product = le16_to_cpu(ihid->hdesc.wProductID); | ||
1512 | + | ||
1513 | + snprintf(hid->name, sizeof(hid->name), "%s %04hX:%04hX", | ||
1514 | + client->name, hid->vendor, hid->product); | ||
1515 | + strlcpy(hid->phys, dev_name(&client->dev), sizeof(hid->phys)); | ||
1516 | + | ||
1517 | + ihid->quirks = i2c_hid_lookup_quirk(hid->vendor, hid->product); | ||
1518 | + | ||
1519 | + ret = hid_add_device(hid); | ||
1520 | + if (ret) { | ||
1521 | + if (ret != -ENODEV) | ||
1522 | + hid_err(client, "can't add hid device: %d\n", ret); | ||
1523 | + goto err_mem_free; | ||
1524 | + } | ||
1525 | + | ||
1526 | + pm_runtime_put(&client->dev); | ||
1527 | + return 0; | ||
1528 | + | ||
1529 | +err_mem_free: | ||
1530 | + hid_destroy_device(hid); | ||
1531 | + | ||
1532 | +err_irq: | ||
1533 | + free_irq(ihid->irq, ihid); | ||
1534 | + | ||
1535 | +err_pm: | ||
1536 | + pm_runtime_put_noidle(&client->dev); | ||
1537 | + pm_runtime_disable(&client->dev); | ||
1538 | + | ||
1539 | +err: | ||
1540 | + if (ihid->desc) | ||
1541 | + gpiod_put(ihid->desc); | ||
1542 | + | ||
1543 | + i2c_hid_free_buffers(ihid); | ||
1544 | + kfree(ihid); | ||
1545 | + return ret; | ||
1546 | +} | ||
1547 | + | ||
1548 | +static int i2c_hid_remove(struct i2c_client *client) | ||
1549 | +{ | ||
1550 | + struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
1551 | + struct hid_device *hid; | ||
1552 | + | ||
1553 | + pm_runtime_get_sync(&client->dev); | ||
1554 | + pm_runtime_disable(&client->dev); | ||
1555 | + pm_runtime_set_suspended(&client->dev); | ||
1556 | + pm_runtime_put_noidle(&client->dev); | ||
1557 | + | ||
1558 | + hid = ihid->hid; | ||
1559 | + hid_destroy_device(hid); | ||
1560 | + | ||
1561 | + free_irq(ihid->irq, ihid); | ||
1562 | + | ||
1563 | + if (ihid->bufsize) | ||
1564 | + i2c_hid_free_buffers(ihid); | ||
1565 | + | ||
1566 | + if (ihid->desc) | ||
1567 | + gpiod_put(ihid->desc); | ||
1568 | + | ||
1569 | + kfree(ihid); | ||
1570 | + | ||
1571 | + acpi_dev_remove_driver_gpios(ACPI_COMPANION(&client->dev)); | ||
1572 | + | ||
1573 | + return 0; | ||
1574 | +} | ||
1575 | + | ||
1576 | +static void i2c_hid_shutdown(struct i2c_client *client) | ||
1577 | +{ | ||
1578 | + struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
1579 | + | ||
1580 | + i2c_hid_set_power(client, I2C_HID_PWR_SLEEP); | ||
1581 | + free_irq(client->irq, ihid); | ||
1582 | +} | ||
1583 | + | ||
1584 | +#ifdef CONFIG_PM_SLEEP | ||
1585 | +static int i2c_hid_suspend(struct device *dev) | ||
1586 | +{ | ||
1587 | + struct i2c_client *client = to_i2c_client(dev); | ||
1588 | + struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
1589 | + struct hid_device *hid = ihid->hid; | ||
1590 | + int ret; | ||
1591 | + int wake_status; | ||
1592 | + | ||
1593 | + if (hid->driver && hid->driver->suspend) { | ||
1594 | + /* | ||
1595 | + * Wake up the device so that IO issues in | ||
1596 | + * HID driver's suspend code can succeed. | ||
1597 | + */ | ||
1598 | + ret = pm_runtime_resume(dev); | ||
1599 | + if (ret < 0) | ||
1600 | + return ret; | ||
1601 | + | ||
1602 | + ret = hid->driver->suspend(hid, PMSG_SUSPEND); | ||
1603 | + if (ret < 0) | ||
1604 | + return ret; | ||
1605 | + } | ||
1606 | + | ||
1607 | + if (!pm_runtime_suspended(dev)) { | ||
1608 | + /* Save some power */ | ||
1609 | + i2c_hid_set_power(client, I2C_HID_PWR_SLEEP); | ||
1610 | + | ||
1611 | + disable_irq(ihid->irq); | ||
1612 | + } | ||
1613 | + | ||
1614 | + if (device_may_wakeup(&client->dev)) { | ||
1615 | + wake_status = enable_irq_wake(ihid->irq); | ||
1616 | + if (!wake_status) | ||
1617 | + ihid->irq_wake_enabled = true; | ||
1618 | + else | ||
1619 | + hid_warn(hid, "Failed to enable irq wake: %d\n", | ||
1620 | + wake_status); | ||
1621 | + } | ||
1622 | + | ||
1623 | + return 0; | ||
1624 | +} | ||
1625 | + | ||
1626 | +static int i2c_hid_resume(struct device *dev) | ||
1627 | +{ | ||
1628 | + int ret; | ||
1629 | + struct i2c_client *client = to_i2c_client(dev); | ||
1630 | + struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
1631 | + struct hid_device *hid = ihid->hid; | ||
1632 | + int wake_status; | ||
1633 | + | ||
1634 | + if (device_may_wakeup(&client->dev) && ihid->irq_wake_enabled) { | ||
1635 | + wake_status = disable_irq_wake(ihid->irq); | ||
1636 | + if (!wake_status) | ||
1637 | + ihid->irq_wake_enabled = false; | ||
1638 | + else | ||
1639 | + hid_warn(hid, "Failed to disable irq wake: %d\n", | ||
1640 | + wake_status); | ||
1641 | + } | ||
1642 | + | ||
1643 | + /* We'll resume to full power */ | ||
1644 | + pm_runtime_disable(dev); | ||
1645 | + pm_runtime_set_active(dev); | ||
1646 | + pm_runtime_enable(dev); | ||
1647 | + | ||
1648 | + enable_irq(ihid->irq); | ||
1649 | + ret = i2c_hid_hwreset(client); | ||
1650 | + if (ret) | ||
1651 | + return ret; | ||
1652 | + | ||
1653 | + if (hid->driver && hid->driver->reset_resume) { | ||
1654 | + ret = hid->driver->reset_resume(hid); | ||
1655 | + return ret; | ||
1656 | + } | ||
1657 | + | ||
1658 | + return 0; | ||
1659 | +} | ||
1660 | +#endif | ||
1661 | + | ||
1662 | +#ifdef CONFIG_PM | ||
1663 | +static int i2c_hid_runtime_suspend(struct device *dev) | ||
1664 | +{ | ||
1665 | + struct i2c_client *client = to_i2c_client(dev); | ||
1666 | + struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
1667 | + | ||
1668 | + i2c_hid_set_power(client, I2C_HID_PWR_SLEEP); | ||
1669 | + disable_irq(ihid->irq); | ||
1670 | + return 0; | ||
1671 | +} | ||
1672 | + | ||
1673 | +static int i2c_hid_runtime_resume(struct device *dev) | ||
1674 | +{ | ||
1675 | + struct i2c_client *client = to_i2c_client(dev); | ||
1676 | + struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
1677 | + | ||
1678 | + enable_irq(ihid->irq); | ||
1679 | + i2c_hid_set_power(client, I2C_HID_PWR_ON); | ||
1680 | + return 0; | ||
1681 | +} | ||
1682 | +#endif | ||
1683 | + | ||
1684 | +static const struct dev_pm_ops i2c_hid_pm = { | ||
1685 | + SET_SYSTEM_SLEEP_PM_OPS(i2c_hid_suspend, i2c_hid_resume) | ||
1686 | + SET_RUNTIME_PM_OPS(i2c_hid_runtime_suspend, i2c_hid_runtime_resume, | ||
1687 | + NULL) | ||
1688 | +}; | ||
1689 | + | ||
1690 | +static const struct i2c_device_id i2c_hid_id_table[] = { | ||
1691 | + { "hid", 0 }, | ||
1692 | + { "hid-over-i2c", 0 }, | ||
1693 | + { }, | ||
1694 | +}; | ||
1695 | +MODULE_DEVICE_TABLE(i2c, i2c_hid_id_table); | ||
1696 | + | ||
1697 | + | ||
1698 | +static struct i2c_driver i2c_hid_driver = { | ||
1699 | + .driver = { | ||
1700 | + .name = "i2c_hid", | ||
1701 | + .pm = &i2c_hid_pm, | ||
1702 | + .acpi_match_table = ACPI_PTR(i2c_hid_acpi_match), | ||
1703 | + .of_match_table = of_match_ptr(i2c_hid_of_match), | ||
1704 | + }, | ||
1705 | + | ||
1706 | + .probe = i2c_hid_probe, | ||
1707 | + .remove = i2c_hid_remove, | ||
1708 | + .shutdown = i2c_hid_shutdown, | ||
1709 | + .id_table = i2c_hid_id_table, | ||
1710 | +}; | ||
1711 | + | ||
1712 | +module_i2c_driver(i2c_hid_driver); | ||
1713 | + | ||
1714 | +MODULE_DESCRIPTION("HID over I2C core driver"); | ||
1715 | +MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>"); | ||
1716 | +MODULE_LICENSE("GPL"); | ||
1717 | diff --git a/drivers/hid/i2c-hid/i2c-hid-dmi-quirks.c b/drivers/hid/i2c-hid/i2c-hid-dmi-quirks.c | ||
1718 | new file mode 100644 | ||
1719 | index 000000000000..1d645c9ab417 | ||
1720 | --- /dev/null | ||
1721 | +++ b/drivers/hid/i2c-hid/i2c-hid-dmi-quirks.c | ||
1722 | @@ -0,0 +1,376 @@ | ||
1723 | +// SPDX-License-Identifier: GPL-2.0+ | ||
1724 | + | ||
1725 | +/* | ||
1726 | + * Quirks for I2C-HID devices that do not supply proper descriptors | ||
1727 | + * | ||
1728 | + * Copyright (c) 2018 Julian Sax <jsbc@gmx.de> | ||
1729 | + * | ||
1730 | + */ | ||
1731 | + | ||
1732 | +#include <linux/types.h> | ||
1733 | +#include <linux/dmi.h> | ||
1734 | +#include <linux/mod_devicetable.h> | ||
1735 | + | ||
1736 | +#include "i2c-hid.h" | ||
1737 | + | ||
1738 | + | ||
1739 | +struct i2c_hid_desc_override { | ||
1740 | + union { | ||
1741 | + struct i2c_hid_desc *i2c_hid_desc; | ||
1742 | + uint8_t *i2c_hid_desc_buffer; | ||
1743 | + }; | ||
1744 | + uint8_t *hid_report_desc; | ||
1745 | + unsigned int hid_report_desc_size; | ||
1746 | + uint8_t *i2c_name; | ||
1747 | +}; | ||
1748 | + | ||
1749 | + | ||
1750 | +/* | ||
1751 | + * descriptors for the SIPODEV SP1064 touchpad | ||
1752 | + * | ||
1753 | + * This device does not supply any descriptors and on windows a filter | ||
1754 | + * driver operates between the i2c-hid layer and the device and injects | ||
1755 | + * these descriptors when the device is prompted. The descriptors were | ||
1756 | + * extracted by listening to the i2c-hid traffic that occurs between the | ||
1757 | + * windows filter driver and the windows i2c-hid driver. | ||
1758 | + */ | ||
1759 | + | ||
1760 | +static const struct i2c_hid_desc_override sipodev_desc = { | ||
1761 | + .i2c_hid_desc_buffer = (uint8_t []) | ||
1762 | + {0x1e, 0x00, /* Length of descriptor */ | ||
1763 | + 0x00, 0x01, /* Version of descriptor */ | ||
1764 | + 0xdb, 0x01, /* Length of report descriptor */ | ||
1765 | + 0x21, 0x00, /* Location of report descriptor */ | ||
1766 | + 0x24, 0x00, /* Location of input report */ | ||
1767 | + 0x1b, 0x00, /* Max input report length */ | ||
1768 | + 0x25, 0x00, /* Location of output report */ | ||
1769 | + 0x11, 0x00, /* Max output report length */ | ||
1770 | + 0x22, 0x00, /* Location of command register */ | ||
1771 | + 0x23, 0x00, /* Location of data register */ | ||
1772 | + 0x11, 0x09, /* Vendor ID */ | ||
1773 | + 0x88, 0x52, /* Product ID */ | ||
1774 | + 0x06, 0x00, /* Version ID */ | ||
1775 | + 0x00, 0x00, 0x00, 0x00 /* Reserved */ | ||
1776 | + }, | ||
1777 | + | ||
1778 | + .hid_report_desc = (uint8_t []) | ||
1779 | + {0x05, 0x01, /* Usage Page (Desktop), */ | ||
1780 | + 0x09, 0x02, /* Usage (Mouse), */ | ||
1781 | + 0xA1, 0x01, /* Collection (Application), */ | ||
1782 | + 0x85, 0x01, /* Report ID (1), */ | ||
1783 | + 0x09, 0x01, /* Usage (Pointer), */ | ||
1784 | + 0xA1, 0x00, /* Collection (Physical), */ | ||
1785 | + 0x05, 0x09, /* Usage Page (Button), */ | ||
1786 | + 0x19, 0x01, /* Usage Minimum (01h), */ | ||
1787 | + 0x29, 0x02, /* Usage Maximum (02h), */ | ||
1788 | + 0x25, 0x01, /* Logical Maximum (1), */ | ||
1789 | + 0x75, 0x01, /* Report Size (1), */ | ||
1790 | + 0x95, 0x02, /* Report Count (2), */ | ||
1791 | + 0x81, 0x02, /* Input (Variable), */ | ||
1792 | + 0x95, 0x06, /* Report Count (6), */ | ||
1793 | + 0x81, 0x01, /* Input (Constant), */ | ||
1794 | + 0x05, 0x01, /* Usage Page (Desktop), */ | ||
1795 | + 0x09, 0x30, /* Usage (X), */ | ||
1796 | + 0x09, 0x31, /* Usage (Y), */ | ||
1797 | + 0x15, 0x81, /* Logical Minimum (-127), */ | ||
1798 | + 0x25, 0x7F, /* Logical Maximum (127), */ | ||
1799 | + 0x75, 0x08, /* Report Size (8), */ | ||
1800 | + 0x95, 0x02, /* Report Count (2), */ | ||
1801 | + 0x81, 0x06, /* Input (Variable, Relative), */ | ||
1802 | + 0xC0, /* End Collection, */ | ||
1803 | + 0xC0, /* End Collection, */ | ||
1804 | + 0x05, 0x0D, /* Usage Page (Digitizer), */ | ||
1805 | + 0x09, 0x05, /* Usage (Touchpad), */ | ||
1806 | + 0xA1, 0x01, /* Collection (Application), */ | ||
1807 | + 0x85, 0x04, /* Report ID (4), */ | ||
1808 | + 0x05, 0x0D, /* Usage Page (Digitizer), */ | ||
1809 | + 0x09, 0x22, /* Usage (Finger), */ | ||
1810 | + 0xA1, 0x02, /* Collection (Logical), */ | ||
1811 | + 0x15, 0x00, /* Logical Minimum (0), */ | ||
1812 | + 0x25, 0x01, /* Logical Maximum (1), */ | ||
1813 | + 0x09, 0x47, /* Usage (Touch Valid), */ | ||
1814 | + 0x09, 0x42, /* Usage (Tip Switch), */ | ||
1815 | + 0x95, 0x02, /* Report Count (2), */ | ||
1816 | + 0x75, 0x01, /* Report Size (1), */ | ||
1817 | + 0x81, 0x02, /* Input (Variable), */ | ||
1818 | + 0x95, 0x01, /* Report Count (1), */ | ||
1819 | + 0x75, 0x03, /* Report Size (3), */ | ||
1820 | + 0x25, 0x05, /* Logical Maximum (5), */ | ||
1821 | + 0x09, 0x51, /* Usage (Contact Identifier), */ | ||
1822 | + 0x81, 0x02, /* Input (Variable), */ | ||
1823 | + 0x75, 0x01, /* Report Size (1), */ | ||
1824 | + 0x95, 0x03, /* Report Count (3), */ | ||
1825 | + 0x81, 0x03, /* Input (Constant, Variable), */ | ||
1826 | + 0x05, 0x01, /* Usage Page (Desktop), */ | ||
1827 | + 0x26, 0x44, 0x0A, /* Logical Maximum (2628), */ | ||
1828 | + 0x75, 0x10, /* Report Size (16), */ | ||
1829 | + 0x55, 0x0E, /* Unit Exponent (14), */ | ||
1830 | + 0x65, 0x11, /* Unit (Centimeter), */ | ||
1831 | + 0x09, 0x30, /* Usage (X), */ | ||
1832 | + 0x46, 0x1A, 0x04, /* Physical Maximum (1050), */ | ||
1833 | + 0x95, 0x01, /* Report Count (1), */ | ||
1834 | + 0x81, 0x02, /* Input (Variable), */ | ||
1835 | + 0x46, 0xBC, 0x02, /* Physical Maximum (700), */ | ||
1836 | + 0x26, 0x34, 0x05, /* Logical Maximum (1332), */ | ||
1837 | + 0x09, 0x31, /* Usage (Y), */ | ||
1838 | + 0x81, 0x02, /* Input (Variable), */ | ||
1839 | + 0xC0, /* End Collection, */ | ||
1840 | + 0x05, 0x0D, /* Usage Page (Digitizer), */ | ||
1841 | + 0x09, 0x22, /* Usage (Finger), */ | ||
1842 | + 0xA1, 0x02, /* Collection (Logical), */ | ||
1843 | + 0x25, 0x01, /* Logical Maximum (1), */ | ||
1844 | + 0x09, 0x47, /* Usage (Touch Valid), */ | ||
1845 | + 0x09, 0x42, /* Usage (Tip Switch), */ | ||
1846 | + 0x95, 0x02, /* Report Count (2), */ | ||
1847 | + 0x75, 0x01, /* Report Size (1), */ | ||
1848 | + 0x81, 0x02, /* Input (Variable), */ | ||
1849 | + 0x95, 0x01, /* Report Count (1), */ | ||
1850 | + 0x75, 0x03, /* Report Size (3), */ | ||
1851 | + 0x25, 0x05, /* Logical Maximum (5), */ | ||
1852 | + 0x09, 0x51, /* Usage (Contact Identifier), */ | ||
1853 | + 0x81, 0x02, /* Input (Variable), */ | ||
1854 | + 0x75, 0x01, /* Report Size (1), */ | ||
1855 | + 0x95, 0x03, /* Report Count (3), */ | ||
1856 | + 0x81, 0x03, /* Input (Constant, Variable), */ | ||
1857 | + 0x05, 0x01, /* Usage Page (Desktop), */ | ||
1858 | + 0x26, 0x44, 0x0A, /* Logical Maximum (2628), */ | ||
1859 | + 0x75, 0x10, /* Report Size (16), */ | ||
1860 | + 0x09, 0x30, /* Usage (X), */ | ||
1861 | + 0x46, 0x1A, 0x04, /* Physical Maximum (1050), */ | ||
1862 | + 0x95, 0x01, /* Report Count (1), */ | ||
1863 | + 0x81, 0x02, /* Input (Variable), */ | ||
1864 | + 0x46, 0xBC, 0x02, /* Physical Maximum (700), */ | ||
1865 | + 0x26, 0x34, 0x05, /* Logical Maximum (1332), */ | ||
1866 | + 0x09, 0x31, /* Usage (Y), */ | ||
1867 | + 0x81, 0x02, /* Input (Variable), */ | ||
1868 | + 0xC0, /* End Collection, */ | ||
1869 | + 0x05, 0x0D, /* Usage Page (Digitizer), */ | ||
1870 | + 0x09, 0x22, /* Usage (Finger), */ | ||
1871 | + 0xA1, 0x02, /* Collection (Logical), */ | ||
1872 | + 0x25, 0x01, /* Logical Maximum (1), */ | ||
1873 | + 0x09, 0x47, /* Usage (Touch Valid), */ | ||
1874 | + 0x09, 0x42, /* Usage (Tip Switch), */ | ||
1875 | + 0x95, 0x02, /* Report Count (2), */ | ||
1876 | + 0x75, 0x01, /* Report Size (1), */ | ||
1877 | + 0x81, 0x02, /* Input (Variable), */ | ||
1878 | + 0x95, 0x01, /* Report Count (1), */ | ||
1879 | + 0x75, 0x03, /* Report Size (3), */ | ||
1880 | + 0x25, 0x05, /* Logical Maximum (5), */ | ||
1881 | + 0x09, 0x51, /* Usage (Contact Identifier), */ | ||
1882 | + 0x81, 0x02, /* Input (Variable), */ | ||
1883 | + 0x75, 0x01, /* Report Size (1), */ | ||
1884 | + 0x95, 0x03, /* Report Count (3), */ | ||
1885 | + 0x81, 0x03, /* Input (Constant, Variable), */ | ||
1886 | + 0x05, 0x01, /* Usage Page (Desktop), */ | ||
1887 | + 0x26, 0x44, 0x0A, /* Logical Maximum (2628), */ | ||
1888 | + 0x75, 0x10, /* Report Size (16), */ | ||
1889 | + 0x09, 0x30, /* Usage (X), */ | ||
1890 | + 0x46, 0x1A, 0x04, /* Physical Maximum (1050), */ | ||
1891 | + 0x95, 0x01, /* Report Count (1), */ | ||
1892 | + 0x81, 0x02, /* Input (Variable), */ | ||
1893 | + 0x46, 0xBC, 0x02, /* Physical Maximum (700), */ | ||
1894 | + 0x26, 0x34, 0x05, /* Logical Maximum (1332), */ | ||
1895 | + 0x09, 0x31, /* Usage (Y), */ | ||
1896 | + 0x81, 0x02, /* Input (Variable), */ | ||
1897 | + 0xC0, /* End Collection, */ | ||
1898 | + 0x05, 0x0D, /* Usage Page (Digitizer), */ | ||
1899 | + 0x09, 0x22, /* Usage (Finger), */ | ||
1900 | + 0xA1, 0x02, /* Collection (Logical), */ | ||
1901 | + 0x25, 0x01, /* Logical Maximum (1), */ | ||
1902 | + 0x09, 0x47, /* Usage (Touch Valid), */ | ||
1903 | + 0x09, 0x42, /* Usage (Tip Switch), */ | ||
1904 | + 0x95, 0x02, /* Report Count (2), */ | ||
1905 | + 0x75, 0x01, /* Report Size (1), */ | ||
1906 | + 0x81, 0x02, /* Input (Variable), */ | ||
1907 | + 0x95, 0x01, /* Report Count (1), */ | ||
1908 | + 0x75, 0x03, /* Report Size (3), */ | ||
1909 | + 0x25, 0x05, /* Logical Maximum (5), */ | ||
1910 | + 0x09, 0x51, /* Usage (Contact Identifier), */ | ||
1911 | + 0x81, 0x02, /* Input (Variable), */ | ||
1912 | + 0x75, 0x01, /* Report Size (1), */ | ||
1913 | + 0x95, 0x03, /* Report Count (3), */ | ||
1914 | + 0x81, 0x03, /* Input (Constant, Variable), */ | ||
1915 | + 0x05, 0x01, /* Usage Page (Desktop), */ | ||
1916 | + 0x26, 0x44, 0x0A, /* Logical Maximum (2628), */ | ||
1917 | + 0x75, 0x10, /* Report Size (16), */ | ||
1918 | + 0x09, 0x30, /* Usage (X), */ | ||
1919 | + 0x46, 0x1A, 0x04, /* Physical Maximum (1050), */ | ||
1920 | + 0x95, 0x01, /* Report Count (1), */ | ||
1921 | + 0x81, 0x02, /* Input (Variable), */ | ||
1922 | + 0x46, 0xBC, 0x02, /* Physical Maximum (700), */ | ||
1923 | + 0x26, 0x34, 0x05, /* Logical Maximum (1332), */ | ||
1924 | + 0x09, 0x31, /* Usage (Y), */ | ||
1925 | + 0x81, 0x02, /* Input (Variable), */ | ||
1926 | + 0xC0, /* End Collection, */ | ||
1927 | + 0x05, 0x0D, /* Usage Page (Digitizer), */ | ||
1928 | + 0x55, 0x0C, /* Unit Exponent (12), */ | ||
1929 | + 0x66, 0x01, 0x10, /* Unit (Seconds), */ | ||
1930 | + 0x47, 0xFF, 0xFF, 0x00, 0x00,/* Physical Maximum (65535), */ | ||
1931 | + 0x27, 0xFF, 0xFF, 0x00, 0x00,/* Logical Maximum (65535), */ | ||
1932 | + 0x75, 0x10, /* Report Size (16), */ | ||
1933 | + 0x95, 0x01, /* Report Count (1), */ | ||
1934 | + 0x09, 0x56, /* Usage (Scan Time), */ | ||
1935 | + 0x81, 0x02, /* Input (Variable), */ | ||
1936 | + 0x09, 0x54, /* Usage (Contact Count), */ | ||
1937 | + 0x25, 0x7F, /* Logical Maximum (127), */ | ||
1938 | + 0x75, 0x08, /* Report Size (8), */ | ||
1939 | + 0x81, 0x02, /* Input (Variable), */ | ||
1940 | + 0x05, 0x09, /* Usage Page (Button), */ | ||
1941 | + 0x09, 0x01, /* Usage (01h), */ | ||
1942 | + 0x25, 0x01, /* Logical Maximum (1), */ | ||
1943 | + 0x75, 0x01, /* Report Size (1), */ | ||
1944 | + 0x95, 0x01, /* Report Count (1), */ | ||
1945 | + 0x81, 0x02, /* Input (Variable), */ | ||
1946 | + 0x95, 0x07, /* Report Count (7), */ | ||
1947 | + 0x81, 0x03, /* Input (Constant, Variable), */ | ||
1948 | + 0x05, 0x0D, /* Usage Page (Digitizer), */ | ||
1949 | + 0x85, 0x02, /* Report ID (2), */ | ||
1950 | + 0x09, 0x55, /* Usage (Contact Count Maximum), */ | ||
1951 | + 0x09, 0x59, /* Usage (59h), */ | ||
1952 | + 0x75, 0x04, /* Report Size (4), */ | ||
1953 | + 0x95, 0x02, /* Report Count (2), */ | ||
1954 | + 0x25, 0x0F, /* Logical Maximum (15), */ | ||
1955 | + 0xB1, 0x02, /* Feature (Variable), */ | ||
1956 | + 0x05, 0x0D, /* Usage Page (Digitizer), */ | ||
1957 | + 0x85, 0x07, /* Report ID (7), */ | ||
1958 | + 0x09, 0x60, /* Usage (60h), */ | ||
1959 | + 0x75, 0x01, /* Report Size (1), */ | ||
1960 | + 0x95, 0x01, /* Report Count (1), */ | ||
1961 | + 0x25, 0x01, /* Logical Maximum (1), */ | ||
1962 | + 0xB1, 0x02, /* Feature (Variable), */ | ||
1963 | + 0x95, 0x07, /* Report Count (7), */ | ||
1964 | + 0xB1, 0x03, /* Feature (Constant, Variable), */ | ||
1965 | + 0x85, 0x06, /* Report ID (6), */ | ||
1966 | + 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ | ||
1967 | + 0x09, 0xC5, /* Usage (C5h), */ | ||
1968 | + 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ | ||
1969 | + 0x75, 0x08, /* Report Size (8), */ | ||
1970 | + 0x96, 0x00, 0x01, /* Report Count (256), */ | ||
1971 | + 0xB1, 0x02, /* Feature (Variable), */ | ||
1972 | + 0xC0, /* End Collection, */ | ||
1973 | + 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ | ||
1974 | + 0x09, 0x01, /* Usage (01h), */ | ||
1975 | + 0xA1, 0x01, /* Collection (Application), */ | ||
1976 | + 0x85, 0x0D, /* Report ID (13), */ | ||
1977 | + 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ | ||
1978 | + 0x19, 0x01, /* Usage Minimum (01h), */ | ||
1979 | + 0x29, 0x02, /* Usage Maximum (02h), */ | ||
1980 | + 0x75, 0x08, /* Report Size (8), */ | ||
1981 | + 0x95, 0x02, /* Report Count (2), */ | ||
1982 | + 0xB1, 0x02, /* Feature (Variable), */ | ||
1983 | + 0xC0, /* End Collection, */ | ||
1984 | + 0x05, 0x0D, /* Usage Page (Digitizer), */ | ||
1985 | + 0x09, 0x0E, /* Usage (Configuration), */ | ||
1986 | + 0xA1, 0x01, /* Collection (Application), */ | ||
1987 | + 0x85, 0x03, /* Report ID (3), */ | ||
1988 | + 0x09, 0x22, /* Usage (Finger), */ | ||
1989 | + 0xA1, 0x02, /* Collection (Logical), */ | ||
1990 | + 0x09, 0x52, /* Usage (Device Mode), */ | ||
1991 | + 0x25, 0x0A, /* Logical Maximum (10), */ | ||
1992 | + 0x95, 0x01, /* Report Count (1), */ | ||
1993 | + 0xB1, 0x02, /* Feature (Variable), */ | ||
1994 | + 0xC0, /* End Collection, */ | ||
1995 | + 0x09, 0x22, /* Usage (Finger), */ | ||
1996 | + 0xA1, 0x00, /* Collection (Physical), */ | ||
1997 | + 0x85, 0x05, /* Report ID (5), */ | ||
1998 | + 0x09, 0x57, /* Usage (57h), */ | ||
1999 | + 0x09, 0x58, /* Usage (58h), */ | ||
2000 | + 0x75, 0x01, /* Report Size (1), */ | ||
2001 | + 0x95, 0x02, /* Report Count (2), */ | ||
2002 | + 0x25, 0x01, /* Logical Maximum (1), */ | ||
2003 | + 0xB1, 0x02, /* Feature (Variable), */ | ||
2004 | + 0x95, 0x06, /* Report Count (6), */ | ||
2005 | + 0xB1, 0x03, /* Feature (Constant, Variable),*/ | ||
2006 | + 0xC0, /* End Collection, */ | ||
2007 | + 0xC0 /* End Collection */ | ||
2008 | + }, | ||
2009 | + .hid_report_desc_size = 475, | ||
2010 | + .i2c_name = "SYNA3602:00" | ||
2011 | +}; | ||
2012 | + | ||
2013 | + | ||
2014 | +static const struct dmi_system_id i2c_hid_dmi_desc_override_table[] = { | ||
2015 | + { | ||
2016 | + .ident = "Teclast F6 Pro", | ||
2017 | + .matches = { | ||
2018 | + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TECLAST"), | ||
2019 | + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "F6 Pro"), | ||
2020 | + }, | ||
2021 | + .driver_data = (void *)&sipodev_desc | ||
2022 | + }, | ||
2023 | + { | ||
2024 | + .ident = "Teclast F7", | ||
2025 | + .matches = { | ||
2026 | + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TECLAST"), | ||
2027 | + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "F7"), | ||
2028 | + }, | ||
2029 | + .driver_data = (void *)&sipodev_desc | ||
2030 | + }, | ||
2031 | + { | ||
2032 | + .ident = "Trekstor Primebook C13", | ||
2033 | + .matches = { | ||
2034 | + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TREKSTOR"), | ||
2035 | + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Primebook C13"), | ||
2036 | + }, | ||
2037 | + .driver_data = (void *)&sipodev_desc | ||
2038 | + }, | ||
2039 | + { | ||
2040 | + .ident = "Trekstor Primebook C11", | ||
2041 | + .matches = { | ||
2042 | + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TREKSTOR"), | ||
2043 | + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Primebook C11"), | ||
2044 | + }, | ||
2045 | + .driver_data = (void *)&sipodev_desc | ||
2046 | + }, | ||
2047 | + { | ||
2048 | + .ident = "Direkt-Tek DTLAPY116-2", | ||
2049 | + .matches = { | ||
2050 | + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Direkt-Tek"), | ||
2051 | + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "DTLAPY116-2"), | ||
2052 | + }, | ||
2053 | + .driver_data = (void *)&sipodev_desc | ||
2054 | + }, | ||
2055 | + { | ||
2056 | + .ident = "Mediacom Flexbook Edge 11", | ||
2057 | + .matches = { | ||
2058 | + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "MEDIACOM"), | ||
2059 | + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "FlexBook edge11 - M-FBE11"), | ||
2060 | + }, | ||
2061 | + .driver_data = (void *)&sipodev_desc | ||
2062 | + } | ||
2063 | +}; | ||
2064 | + | ||
2065 | + | ||
2066 | +struct i2c_hid_desc *i2c_hid_get_dmi_i2c_hid_desc_override(uint8_t *i2c_name) | ||
2067 | +{ | ||
2068 | + struct i2c_hid_desc_override *override; | ||
2069 | + const struct dmi_system_id *system_id; | ||
2070 | + | ||
2071 | + system_id = dmi_first_match(i2c_hid_dmi_desc_override_table); | ||
2072 | + if (!system_id) | ||
2073 | + return NULL; | ||
2074 | + | ||
2075 | + override = system_id->driver_data; | ||
2076 | + if (strcmp(override->i2c_name, i2c_name)) | ||
2077 | + return NULL; | ||
2078 | + | ||
2079 | + return override->i2c_hid_desc; | ||
2080 | +} | ||
2081 | + | ||
2082 | +char *i2c_hid_get_dmi_hid_report_desc_override(uint8_t *i2c_name, | ||
2083 | + unsigned int *size) | ||
2084 | +{ | ||
2085 | + struct i2c_hid_desc_override *override; | ||
2086 | + const struct dmi_system_id *system_id; | ||
2087 | + | ||
2088 | + system_id = dmi_first_match(i2c_hid_dmi_desc_override_table); | ||
2089 | + if (!system_id) | ||
2090 | + return NULL; | ||
2091 | + | ||
2092 | + override = system_id->driver_data; | ||
2093 | + if (strcmp(override->i2c_name, i2c_name)) | ||
2094 | + return NULL; | ||
2095 | + | ||
2096 | + *size = override->hid_report_desc_size; | ||
2097 | + return override->hid_report_desc; | ||
2098 | +} | ||
2099 | diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c | ||
2100 | deleted file mode 100644 | ||
2101 | index ce2b80009c19..000000000000 | ||
2102 | --- a/drivers/hid/i2c-hid/i2c-hid.c | ||
2103 | +++ /dev/null | ||
2104 | @@ -1,1339 +0,0 @@ | ||
2105 | -/* | ||
2106 | - * HID over I2C protocol implementation | ||
2107 | - * | ||
2108 | - * Copyright (c) 2012 Benjamin Tissoires <benjamin.tissoires@gmail.com> | ||
2109 | - * Copyright (c) 2012 Ecole Nationale de l'Aviation Civile, France | ||
2110 | - * Copyright (c) 2012 Red Hat, Inc | ||
2111 | - * | ||
2112 | - * This code is partly based on "USB HID support for Linux": | ||
2113 | - * | ||
2114 | - * Copyright (c) 1999 Andreas Gal | ||
2115 | - * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> | ||
2116 | - * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc | ||
2117 | - * Copyright (c) 2007-2008 Oliver Neukum | ||
2118 | - * Copyright (c) 2006-2010 Jiri Kosina | ||
2119 | - * | ||
2120 | - * This file is subject to the terms and conditions of the GNU General Public | ||
2121 | - * License. See the file COPYING in the main directory of this archive for | ||
2122 | - * more details. | ||
2123 | - */ | ||
2124 | - | ||
2125 | -#include <linux/module.h> | ||
2126 | -#include <linux/i2c.h> | ||
2127 | -#include <linux/interrupt.h> | ||
2128 | -#include <linux/input.h> | ||
2129 | -#include <linux/delay.h> | ||
2130 | -#include <linux/slab.h> | ||
2131 | -#include <linux/pm.h> | ||
2132 | -#include <linux/pm_runtime.h> | ||
2133 | -#include <linux/device.h> | ||
2134 | -#include <linux/wait.h> | ||
2135 | -#include <linux/err.h> | ||
2136 | -#include <linux/string.h> | ||
2137 | -#include <linux/list.h> | ||
2138 | -#include <linux/jiffies.h> | ||
2139 | -#include <linux/kernel.h> | ||
2140 | -#include <linux/hid.h> | ||
2141 | -#include <linux/mutex.h> | ||
2142 | -#include <linux/acpi.h> | ||
2143 | -#include <linux/of.h> | ||
2144 | -#include <linux/gpio/consumer.h> | ||
2145 | - | ||
2146 | -#include <linux/i2c/i2c-hid.h> | ||
2147 | - | ||
2148 | -#include "../hid-ids.h" | ||
2149 | - | ||
2150 | -/* quirks to control the device */ | ||
2151 | -#define I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV BIT(0) | ||
2152 | - | ||
2153 | -/* flags */ | ||
2154 | -#define I2C_HID_STARTED 0 | ||
2155 | -#define I2C_HID_RESET_PENDING 1 | ||
2156 | -#define I2C_HID_READ_PENDING 2 | ||
2157 | - | ||
2158 | -#define I2C_HID_PWR_ON 0x00 | ||
2159 | -#define I2C_HID_PWR_SLEEP 0x01 | ||
2160 | - | ||
2161 | -/* debug option */ | ||
2162 | -static bool debug; | ||
2163 | -module_param(debug, bool, 0444); | ||
2164 | -MODULE_PARM_DESC(debug, "print a lot of debug information"); | ||
2165 | - | ||
2166 | -#define i2c_hid_dbg(ihid, fmt, arg...) \ | ||
2167 | -do { \ | ||
2168 | - if (debug) \ | ||
2169 | - dev_printk(KERN_DEBUG, &(ihid)->client->dev, fmt, ##arg); \ | ||
2170 | -} while (0) | ||
2171 | - | ||
2172 | -struct i2c_hid_desc { | ||
2173 | - __le16 wHIDDescLength; | ||
2174 | - __le16 bcdVersion; | ||
2175 | - __le16 wReportDescLength; | ||
2176 | - __le16 wReportDescRegister; | ||
2177 | - __le16 wInputRegister; | ||
2178 | - __le16 wMaxInputLength; | ||
2179 | - __le16 wOutputRegister; | ||
2180 | - __le16 wMaxOutputLength; | ||
2181 | - __le16 wCommandRegister; | ||
2182 | - __le16 wDataRegister; | ||
2183 | - __le16 wVendorID; | ||
2184 | - __le16 wProductID; | ||
2185 | - __le16 wVersionID; | ||
2186 | - __le32 reserved; | ||
2187 | -} __packed; | ||
2188 | - | ||
2189 | -struct i2c_hid_cmd { | ||
2190 | - unsigned int registerIndex; | ||
2191 | - __u8 opcode; | ||
2192 | - unsigned int length; | ||
2193 | - bool wait; | ||
2194 | -}; | ||
2195 | - | ||
2196 | -union command { | ||
2197 | - u8 data[0]; | ||
2198 | - struct cmd { | ||
2199 | - __le16 reg; | ||
2200 | - __u8 reportTypeID; | ||
2201 | - __u8 opcode; | ||
2202 | - } __packed c; | ||
2203 | -}; | ||
2204 | - | ||
2205 | -#define I2C_HID_CMD(opcode_) \ | ||
2206 | - .opcode = opcode_, .length = 4, \ | ||
2207 | - .registerIndex = offsetof(struct i2c_hid_desc, wCommandRegister) | ||
2208 | - | ||
2209 | -/* fetch HID descriptor */ | ||
2210 | -static const struct i2c_hid_cmd hid_descr_cmd = { .length = 2 }; | ||
2211 | -/* fetch report descriptors */ | ||
2212 | -static const struct i2c_hid_cmd hid_report_descr_cmd = { | ||
2213 | - .registerIndex = offsetof(struct i2c_hid_desc, | ||
2214 | - wReportDescRegister), | ||
2215 | - .opcode = 0x00, | ||
2216 | - .length = 2 }; | ||
2217 | -/* commands */ | ||
2218 | -static const struct i2c_hid_cmd hid_reset_cmd = { I2C_HID_CMD(0x01), | ||
2219 | - .wait = true }; | ||
2220 | -static const struct i2c_hid_cmd hid_get_report_cmd = { I2C_HID_CMD(0x02) }; | ||
2221 | -static const struct i2c_hid_cmd hid_set_report_cmd = { I2C_HID_CMD(0x03) }; | ||
2222 | -static const struct i2c_hid_cmd hid_set_power_cmd = { I2C_HID_CMD(0x08) }; | ||
2223 | -static const struct i2c_hid_cmd hid_no_cmd = { .length = 0 }; | ||
2224 | - | ||
2225 | -/* | ||
2226 | - * These definitions are not used here, but are defined by the spec. | ||
2227 | - * Keeping them here for documentation purposes. | ||
2228 | - * | ||
2229 | - * static const struct i2c_hid_cmd hid_get_idle_cmd = { I2C_HID_CMD(0x04) }; | ||
2230 | - * static const struct i2c_hid_cmd hid_set_idle_cmd = { I2C_HID_CMD(0x05) }; | ||
2231 | - * static const struct i2c_hid_cmd hid_get_protocol_cmd = { I2C_HID_CMD(0x06) }; | ||
2232 | - * static const struct i2c_hid_cmd hid_set_protocol_cmd = { I2C_HID_CMD(0x07) }; | ||
2233 | - */ | ||
2234 | - | ||
2235 | -static DEFINE_MUTEX(i2c_hid_open_mut); | ||
2236 | - | ||
2237 | -/* The main device structure */ | ||
2238 | -struct i2c_hid { | ||
2239 | - struct i2c_client *client; /* i2c client */ | ||
2240 | - struct hid_device *hid; /* pointer to corresponding HID dev */ | ||
2241 | - union { | ||
2242 | - __u8 hdesc_buffer[sizeof(struct i2c_hid_desc)]; | ||
2243 | - struct i2c_hid_desc hdesc; /* the HID Descriptor */ | ||
2244 | - }; | ||
2245 | - __le16 wHIDDescRegister; /* location of the i2c | ||
2246 | - * register of the HID | ||
2247 | - * descriptor. */ | ||
2248 | - unsigned int bufsize; /* i2c buffer size */ | ||
2249 | - u8 *inbuf; /* Input buffer */ | ||
2250 | - u8 *rawbuf; /* Raw Input buffer */ | ||
2251 | - u8 *cmdbuf; /* Command buffer */ | ||
2252 | - u8 *argsbuf; /* Command arguments buffer */ | ||
2253 | - | ||
2254 | - unsigned long flags; /* device flags */ | ||
2255 | - unsigned long quirks; /* Various quirks */ | ||
2256 | - | ||
2257 | - wait_queue_head_t wait; /* For waiting the interrupt */ | ||
2258 | - struct gpio_desc *desc; | ||
2259 | - int irq; | ||
2260 | - | ||
2261 | - struct i2c_hid_platform_data pdata; | ||
2262 | - | ||
2263 | - bool irq_wake_enabled; | ||
2264 | - struct mutex reset_lock; | ||
2265 | -}; | ||
2266 | - | ||
2267 | -static const struct i2c_hid_quirks { | ||
2268 | - __u16 idVendor; | ||
2269 | - __u16 idProduct; | ||
2270 | - __u32 quirks; | ||
2271 | -} i2c_hid_quirks[] = { | ||
2272 | - { USB_VENDOR_ID_WEIDA, USB_DEVICE_ID_WEIDA_8752, | ||
2273 | - I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV }, | ||
2274 | - { USB_VENDOR_ID_WEIDA, USB_DEVICE_ID_WEIDA_8755, | ||
2275 | - I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV }, | ||
2276 | - { 0, 0 } | ||
2277 | -}; | ||
2278 | - | ||
2279 | -/* | ||
2280 | - * i2c_hid_lookup_quirk: return any quirks associated with a I2C HID device | ||
2281 | - * @idVendor: the 16-bit vendor ID | ||
2282 | - * @idProduct: the 16-bit product ID | ||
2283 | - * | ||
2284 | - * Returns: a u32 quirks value. | ||
2285 | - */ | ||
2286 | -static u32 i2c_hid_lookup_quirk(const u16 idVendor, const u16 idProduct) | ||
2287 | -{ | ||
2288 | - u32 quirks = 0; | ||
2289 | - int n; | ||
2290 | - | ||
2291 | - for (n = 0; i2c_hid_quirks[n].idVendor; n++) | ||
2292 | - if (i2c_hid_quirks[n].idVendor == idVendor && | ||
2293 | - (i2c_hid_quirks[n].idProduct == (__u16)HID_ANY_ID || | ||
2294 | - i2c_hid_quirks[n].idProduct == idProduct)) | ||
2295 | - quirks = i2c_hid_quirks[n].quirks; | ||
2296 | - | ||
2297 | - return quirks; | ||
2298 | -} | ||
2299 | - | ||
2300 | -static int __i2c_hid_command(struct i2c_client *client, | ||
2301 | - const struct i2c_hid_cmd *command, u8 reportID, | ||
2302 | - u8 reportType, u8 *args, int args_len, | ||
2303 | - unsigned char *buf_recv, int data_len) | ||
2304 | -{ | ||
2305 | - struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
2306 | - union command *cmd = (union command *)ihid->cmdbuf; | ||
2307 | - int ret; | ||
2308 | - struct i2c_msg msg[2]; | ||
2309 | - int msg_num = 1; | ||
2310 | - | ||
2311 | - int length = command->length; | ||
2312 | - bool wait = command->wait; | ||
2313 | - unsigned int registerIndex = command->registerIndex; | ||
2314 | - | ||
2315 | - /* special case for hid_descr_cmd */ | ||
2316 | - if (command == &hid_descr_cmd) { | ||
2317 | - cmd->c.reg = ihid->wHIDDescRegister; | ||
2318 | - } else { | ||
2319 | - cmd->data[0] = ihid->hdesc_buffer[registerIndex]; | ||
2320 | - cmd->data[1] = ihid->hdesc_buffer[registerIndex + 1]; | ||
2321 | - } | ||
2322 | - | ||
2323 | - if (length > 2) { | ||
2324 | - cmd->c.opcode = command->opcode; | ||
2325 | - cmd->c.reportTypeID = reportID | reportType << 4; | ||
2326 | - } | ||
2327 | - | ||
2328 | - memcpy(cmd->data + length, args, args_len); | ||
2329 | - length += args_len; | ||
2330 | - | ||
2331 | - i2c_hid_dbg(ihid, "%s: cmd=%*ph\n", __func__, length, cmd->data); | ||
2332 | - | ||
2333 | - msg[0].addr = client->addr; | ||
2334 | - msg[0].flags = client->flags & I2C_M_TEN; | ||
2335 | - msg[0].len = length; | ||
2336 | - msg[0].buf = cmd->data; | ||
2337 | - if (data_len > 0) { | ||
2338 | - msg[1].addr = client->addr; | ||
2339 | - msg[1].flags = client->flags & I2C_M_TEN; | ||
2340 | - msg[1].flags |= I2C_M_RD; | ||
2341 | - msg[1].len = data_len; | ||
2342 | - msg[1].buf = buf_recv; | ||
2343 | - msg_num = 2; | ||
2344 | - set_bit(I2C_HID_READ_PENDING, &ihid->flags); | ||
2345 | - } | ||
2346 | - | ||
2347 | - if (wait) | ||
2348 | - set_bit(I2C_HID_RESET_PENDING, &ihid->flags); | ||
2349 | - | ||
2350 | - ret = i2c_transfer(client->adapter, msg, msg_num); | ||
2351 | - | ||
2352 | - if (data_len > 0) | ||
2353 | - clear_bit(I2C_HID_READ_PENDING, &ihid->flags); | ||
2354 | - | ||
2355 | - if (ret != msg_num) | ||
2356 | - return ret < 0 ? ret : -EIO; | ||
2357 | - | ||
2358 | - ret = 0; | ||
2359 | - | ||
2360 | - if (wait) { | ||
2361 | - i2c_hid_dbg(ihid, "%s: waiting...\n", __func__); | ||
2362 | - if (!wait_event_timeout(ihid->wait, | ||
2363 | - !test_bit(I2C_HID_RESET_PENDING, &ihid->flags), | ||
2364 | - msecs_to_jiffies(5000))) | ||
2365 | - ret = -ENODATA; | ||
2366 | - i2c_hid_dbg(ihid, "%s: finished.\n", __func__); | ||
2367 | - } | ||
2368 | - | ||
2369 | - return ret; | ||
2370 | -} | ||
2371 | - | ||
2372 | -static int i2c_hid_command(struct i2c_client *client, | ||
2373 | - const struct i2c_hid_cmd *command, | ||
2374 | - unsigned char *buf_recv, int data_len) | ||
2375 | -{ | ||
2376 | - return __i2c_hid_command(client, command, 0, 0, NULL, 0, | ||
2377 | - buf_recv, data_len); | ||
2378 | -} | ||
2379 | - | ||
2380 | -static int i2c_hid_get_report(struct i2c_client *client, u8 reportType, | ||
2381 | - u8 reportID, unsigned char *buf_recv, int data_len) | ||
2382 | -{ | ||
2383 | - struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
2384 | - u8 args[3]; | ||
2385 | - int ret; | ||
2386 | - int args_len = 0; | ||
2387 | - u16 readRegister = le16_to_cpu(ihid->hdesc.wDataRegister); | ||
2388 | - | ||
2389 | - i2c_hid_dbg(ihid, "%s\n", __func__); | ||
2390 | - | ||
2391 | - if (reportID >= 0x0F) { | ||
2392 | - args[args_len++] = reportID; | ||
2393 | - reportID = 0x0F; | ||
2394 | - } | ||
2395 | - | ||
2396 | - args[args_len++] = readRegister & 0xFF; | ||
2397 | - args[args_len++] = readRegister >> 8; | ||
2398 | - | ||
2399 | - ret = __i2c_hid_command(client, &hid_get_report_cmd, reportID, | ||
2400 | - reportType, args, args_len, buf_recv, data_len); | ||
2401 | - if (ret) { | ||
2402 | - dev_err(&client->dev, | ||
2403 | - "failed to retrieve report from device.\n"); | ||
2404 | - return ret; | ||
2405 | - } | ||
2406 | - | ||
2407 | - return 0; | ||
2408 | -} | ||
2409 | - | ||
2410 | -/** | ||
2411 | - * i2c_hid_set_or_send_report: forward an incoming report to the device | ||
2412 | - * @client: the i2c_client of the device | ||
2413 | - * @reportType: 0x03 for HID_FEATURE_REPORT ; 0x02 for HID_OUTPUT_REPORT | ||
2414 | - * @reportID: the report ID | ||
2415 | - * @buf: the actual data to transfer, without the report ID | ||
2416 | - * @len: size of buf | ||
2417 | - * @use_data: true: use SET_REPORT HID command, false: send plain OUTPUT report | ||
2418 | - */ | ||
2419 | -static int i2c_hid_set_or_send_report(struct i2c_client *client, u8 reportType, | ||
2420 | - u8 reportID, unsigned char *buf, size_t data_len, bool use_data) | ||
2421 | -{ | ||
2422 | - struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
2423 | - u8 *args = ihid->argsbuf; | ||
2424 | - const struct i2c_hid_cmd *hidcmd; | ||
2425 | - int ret; | ||
2426 | - u16 dataRegister = le16_to_cpu(ihid->hdesc.wDataRegister); | ||
2427 | - u16 outputRegister = le16_to_cpu(ihid->hdesc.wOutputRegister); | ||
2428 | - u16 maxOutputLength = le16_to_cpu(ihid->hdesc.wMaxOutputLength); | ||
2429 | - u16 size; | ||
2430 | - int args_len; | ||
2431 | - int index = 0; | ||
2432 | - | ||
2433 | - i2c_hid_dbg(ihid, "%s\n", __func__); | ||
2434 | - | ||
2435 | - if (data_len > ihid->bufsize) | ||
2436 | - return -EINVAL; | ||
2437 | - | ||
2438 | - size = 2 /* size */ + | ||
2439 | - (reportID ? 1 : 0) /* reportID */ + | ||
2440 | - data_len /* buf */; | ||
2441 | - args_len = (reportID >= 0x0F ? 1 : 0) /* optional third byte */ + | ||
2442 | - 2 /* dataRegister */ + | ||
2443 | - size /* args */; | ||
2444 | - | ||
2445 | - if (!use_data && maxOutputLength == 0) | ||
2446 | - return -ENOSYS; | ||
2447 | - | ||
2448 | - if (reportID >= 0x0F) { | ||
2449 | - args[index++] = reportID; | ||
2450 | - reportID = 0x0F; | ||
2451 | - } | ||
2452 | - | ||
2453 | - /* | ||
2454 | - * use the data register for feature reports or if the device does not | ||
2455 | - * support the output register | ||
2456 | - */ | ||
2457 | - if (use_data) { | ||
2458 | - args[index++] = dataRegister & 0xFF; | ||
2459 | - args[index++] = dataRegister >> 8; | ||
2460 | - hidcmd = &hid_set_report_cmd; | ||
2461 | - } else { | ||
2462 | - args[index++] = outputRegister & 0xFF; | ||
2463 | - args[index++] = outputRegister >> 8; | ||
2464 | - hidcmd = &hid_no_cmd; | ||
2465 | - } | ||
2466 | - | ||
2467 | - args[index++] = size & 0xFF; | ||
2468 | - args[index++] = size >> 8; | ||
2469 | - | ||
2470 | - if (reportID) | ||
2471 | - args[index++] = reportID; | ||
2472 | - | ||
2473 | - memcpy(&args[index], buf, data_len); | ||
2474 | - | ||
2475 | - ret = __i2c_hid_command(client, hidcmd, reportID, | ||
2476 | - reportType, args, args_len, NULL, 0); | ||
2477 | - if (ret) { | ||
2478 | - dev_err(&client->dev, "failed to set a report to device.\n"); | ||
2479 | - return ret; | ||
2480 | - } | ||
2481 | - | ||
2482 | - return data_len; | ||
2483 | -} | ||
2484 | - | ||
2485 | -static int i2c_hid_set_power(struct i2c_client *client, int power_state) | ||
2486 | -{ | ||
2487 | - struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
2488 | - int ret; | ||
2489 | - | ||
2490 | - i2c_hid_dbg(ihid, "%s\n", __func__); | ||
2491 | - | ||
2492 | - /* | ||
2493 | - * Some devices require to send a command to wakeup before power on. | ||
2494 | - * The call will get a return value (EREMOTEIO) but device will be | ||
2495 | - * triggered and activated. After that, it goes like a normal device. | ||
2496 | - */ | ||
2497 | - if (power_state == I2C_HID_PWR_ON && | ||
2498 | - ihid->quirks & I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV) { | ||
2499 | - ret = i2c_hid_command(client, &hid_set_power_cmd, NULL, 0); | ||
2500 | - | ||
2501 | - /* Device was already activated */ | ||
2502 | - if (!ret) | ||
2503 | - goto set_pwr_exit; | ||
2504 | - } | ||
2505 | - | ||
2506 | - ret = __i2c_hid_command(client, &hid_set_power_cmd, power_state, | ||
2507 | - 0, NULL, 0, NULL, 0); | ||
2508 | - | ||
2509 | - if (ret) | ||
2510 | - dev_err(&client->dev, "failed to change power setting.\n"); | ||
2511 | - | ||
2512 | -set_pwr_exit: | ||
2513 | - return ret; | ||
2514 | -} | ||
2515 | - | ||
2516 | -static int i2c_hid_hwreset(struct i2c_client *client) | ||
2517 | -{ | ||
2518 | - struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
2519 | - int ret; | ||
2520 | - | ||
2521 | - i2c_hid_dbg(ihid, "%s\n", __func__); | ||
2522 | - | ||
2523 | - /* | ||
2524 | - * This prevents sending feature reports while the device is | ||
2525 | - * being reset. Otherwise we may lose the reset complete | ||
2526 | - * interrupt. | ||
2527 | - */ | ||
2528 | - mutex_lock(&ihid->reset_lock); | ||
2529 | - | ||
2530 | - ret = i2c_hid_set_power(client, I2C_HID_PWR_ON); | ||
2531 | - if (ret) | ||
2532 | - goto out_unlock; | ||
2533 | - | ||
2534 | - /* | ||
2535 | - * The HID over I2C specification states that if a DEVICE needs time | ||
2536 | - * after the PWR_ON request, it should utilise CLOCK stretching. | ||
2537 | - * However, it has been observered that the Windows driver provides a | ||
2538 | - * 1ms sleep between the PWR_ON and RESET requests and that some devices | ||
2539 | - * rely on this. | ||
2540 | - */ | ||
2541 | - usleep_range(1000, 5000); | ||
2542 | - | ||
2543 | - i2c_hid_dbg(ihid, "resetting...\n"); | ||
2544 | - | ||
2545 | - ret = i2c_hid_command(client, &hid_reset_cmd, NULL, 0); | ||
2546 | - if (ret) { | ||
2547 | - dev_err(&client->dev, "failed to reset device.\n"); | ||
2548 | - i2c_hid_set_power(client, I2C_HID_PWR_SLEEP); | ||
2549 | - } | ||
2550 | - | ||
2551 | -out_unlock: | ||
2552 | - mutex_unlock(&ihid->reset_lock); | ||
2553 | - return ret; | ||
2554 | -} | ||
2555 | - | ||
2556 | -static void i2c_hid_get_input(struct i2c_hid *ihid) | ||
2557 | -{ | ||
2558 | - int ret; | ||
2559 | - u32 ret_size; | ||
2560 | - int size = le16_to_cpu(ihid->hdesc.wMaxInputLength); | ||
2561 | - | ||
2562 | - if (size > ihid->bufsize) | ||
2563 | - size = ihid->bufsize; | ||
2564 | - | ||
2565 | - ret = i2c_master_recv(ihid->client, ihid->inbuf, size); | ||
2566 | - if (ret != size) { | ||
2567 | - if (ret < 0) | ||
2568 | - return; | ||
2569 | - | ||
2570 | - dev_err(&ihid->client->dev, "%s: got %d data instead of %d\n", | ||
2571 | - __func__, ret, size); | ||
2572 | - return; | ||
2573 | - } | ||
2574 | - | ||
2575 | - ret_size = ihid->inbuf[0] | ihid->inbuf[1] << 8; | ||
2576 | - | ||
2577 | - if (!ret_size) { | ||
2578 | - /* host or device initiated RESET completed */ | ||
2579 | - if (test_and_clear_bit(I2C_HID_RESET_PENDING, &ihid->flags)) | ||
2580 | - wake_up(&ihid->wait); | ||
2581 | - return; | ||
2582 | - } | ||
2583 | - | ||
2584 | - if ((ret_size > size) || (ret_size < 2)) { | ||
2585 | - dev_err(&ihid->client->dev, "%s: incomplete report (%d/%d)\n", | ||
2586 | - __func__, size, ret_size); | ||
2587 | - return; | ||
2588 | - } | ||
2589 | - | ||
2590 | - i2c_hid_dbg(ihid, "input: %*ph\n", ret_size, ihid->inbuf); | ||
2591 | - | ||
2592 | - if (test_bit(I2C_HID_STARTED, &ihid->flags)) | ||
2593 | - hid_input_report(ihid->hid, HID_INPUT_REPORT, ihid->inbuf + 2, | ||
2594 | - ret_size - 2, 1); | ||
2595 | - | ||
2596 | - return; | ||
2597 | -} | ||
2598 | - | ||
2599 | -static irqreturn_t i2c_hid_irq(int irq, void *dev_id) | ||
2600 | -{ | ||
2601 | - struct i2c_hid *ihid = dev_id; | ||
2602 | - | ||
2603 | - if (test_bit(I2C_HID_READ_PENDING, &ihid->flags)) | ||
2604 | - return IRQ_HANDLED; | ||
2605 | - | ||
2606 | - i2c_hid_get_input(ihid); | ||
2607 | - | ||
2608 | - return IRQ_HANDLED; | ||
2609 | -} | ||
2610 | - | ||
2611 | -static int i2c_hid_get_report_length(struct hid_report *report) | ||
2612 | -{ | ||
2613 | - return ((report->size - 1) >> 3) + 1 + | ||
2614 | - report->device->report_enum[report->type].numbered + 2; | ||
2615 | -} | ||
2616 | - | ||
2617 | -static void i2c_hid_init_report(struct hid_report *report, u8 *buffer, | ||
2618 | - size_t bufsize) | ||
2619 | -{ | ||
2620 | - struct hid_device *hid = report->device; | ||
2621 | - struct i2c_client *client = hid->driver_data; | ||
2622 | - struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
2623 | - unsigned int size, ret_size; | ||
2624 | - | ||
2625 | - size = i2c_hid_get_report_length(report); | ||
2626 | - if (i2c_hid_get_report(client, | ||
2627 | - report->type == HID_FEATURE_REPORT ? 0x03 : 0x01, | ||
2628 | - report->id, buffer, size)) | ||
2629 | - return; | ||
2630 | - | ||
2631 | - i2c_hid_dbg(ihid, "report (len=%d): %*ph\n", size, size, buffer); | ||
2632 | - | ||
2633 | - ret_size = buffer[0] | (buffer[1] << 8); | ||
2634 | - | ||
2635 | - if (ret_size != size) { | ||
2636 | - dev_err(&client->dev, "error in %s size:%d / ret_size:%d\n", | ||
2637 | - __func__, size, ret_size); | ||
2638 | - return; | ||
2639 | - } | ||
2640 | - | ||
2641 | - /* hid->driver_lock is held as we are in probe function, | ||
2642 | - * we just need to setup the input fields, so using | ||
2643 | - * hid_report_raw_event is safe. */ | ||
2644 | - hid_report_raw_event(hid, report->type, buffer + 2, size - 2, 1); | ||
2645 | -} | ||
2646 | - | ||
2647 | -/* | ||
2648 | - * Initialize all reports | ||
2649 | - */ | ||
2650 | -static void i2c_hid_init_reports(struct hid_device *hid) | ||
2651 | -{ | ||
2652 | - struct hid_report *report; | ||
2653 | - struct i2c_client *client = hid->driver_data; | ||
2654 | - struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
2655 | - u8 *inbuf = kzalloc(ihid->bufsize, GFP_KERNEL); | ||
2656 | - | ||
2657 | - if (!inbuf) { | ||
2658 | - dev_err(&client->dev, "can not retrieve initial reports\n"); | ||
2659 | - return; | ||
2660 | - } | ||
2661 | - | ||
2662 | - /* | ||
2663 | - * The device must be powered on while we fetch initial reports | ||
2664 | - * from it. | ||
2665 | - */ | ||
2666 | - pm_runtime_get_sync(&client->dev); | ||
2667 | - | ||
2668 | - list_for_each_entry(report, | ||
2669 | - &hid->report_enum[HID_FEATURE_REPORT].report_list, list) | ||
2670 | - i2c_hid_init_report(report, inbuf, ihid->bufsize); | ||
2671 | - | ||
2672 | - pm_runtime_put(&client->dev); | ||
2673 | - | ||
2674 | - kfree(inbuf); | ||
2675 | -} | ||
2676 | - | ||
2677 | -/* | ||
2678 | - * Traverse the supplied list of reports and find the longest | ||
2679 | - */ | ||
2680 | -static void i2c_hid_find_max_report(struct hid_device *hid, unsigned int type, | ||
2681 | - unsigned int *max) | ||
2682 | -{ | ||
2683 | - struct hid_report *report; | ||
2684 | - unsigned int size; | ||
2685 | - | ||
2686 | - /* We should not rely on wMaxInputLength, as some devices may set it to | ||
2687 | - * a wrong length. */ | ||
2688 | - list_for_each_entry(report, &hid->report_enum[type].report_list, list) { | ||
2689 | - size = i2c_hid_get_report_length(report); | ||
2690 | - if (*max < size) | ||
2691 | - *max = size; | ||
2692 | - } | ||
2693 | -} | ||
2694 | - | ||
2695 | -static void i2c_hid_free_buffers(struct i2c_hid *ihid) | ||
2696 | -{ | ||
2697 | - kfree(ihid->inbuf); | ||
2698 | - kfree(ihid->rawbuf); | ||
2699 | - kfree(ihid->argsbuf); | ||
2700 | - kfree(ihid->cmdbuf); | ||
2701 | - ihid->inbuf = NULL; | ||
2702 | - ihid->rawbuf = NULL; | ||
2703 | - ihid->cmdbuf = NULL; | ||
2704 | - ihid->argsbuf = NULL; | ||
2705 | - ihid->bufsize = 0; | ||
2706 | -} | ||
2707 | - | ||
2708 | -static int i2c_hid_alloc_buffers(struct i2c_hid *ihid, size_t report_size) | ||
2709 | -{ | ||
2710 | - /* the worst case is computed from the set_report command with a | ||
2711 | - * reportID > 15 and the maximum report length */ | ||
2712 | - int args_len = sizeof(__u8) + /* ReportID */ | ||
2713 | - sizeof(__u8) + /* optional ReportID byte */ | ||
2714 | - sizeof(__u16) + /* data register */ | ||
2715 | - sizeof(__u16) + /* size of the report */ | ||
2716 | - report_size; /* report */ | ||
2717 | - | ||
2718 | - ihid->inbuf = kzalloc(report_size, GFP_KERNEL); | ||
2719 | - ihid->rawbuf = kzalloc(report_size, GFP_KERNEL); | ||
2720 | - ihid->argsbuf = kzalloc(args_len, GFP_KERNEL); | ||
2721 | - ihid->cmdbuf = kzalloc(sizeof(union command) + args_len, GFP_KERNEL); | ||
2722 | - | ||
2723 | - if (!ihid->inbuf || !ihid->rawbuf || !ihid->argsbuf || !ihid->cmdbuf) { | ||
2724 | - i2c_hid_free_buffers(ihid); | ||
2725 | - return -ENOMEM; | ||
2726 | - } | ||
2727 | - | ||
2728 | - ihid->bufsize = report_size; | ||
2729 | - | ||
2730 | - return 0; | ||
2731 | -} | ||
2732 | - | ||
2733 | -static int i2c_hid_get_raw_report(struct hid_device *hid, | ||
2734 | - unsigned char report_number, __u8 *buf, size_t count, | ||
2735 | - unsigned char report_type) | ||
2736 | -{ | ||
2737 | - struct i2c_client *client = hid->driver_data; | ||
2738 | - struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
2739 | - size_t ret_count, ask_count; | ||
2740 | - int ret; | ||
2741 | - | ||
2742 | - if (report_type == HID_OUTPUT_REPORT) | ||
2743 | - return -EINVAL; | ||
2744 | - | ||
2745 | - /* +2 bytes to include the size of the reply in the query buffer */ | ||
2746 | - ask_count = min(count + 2, (size_t)ihid->bufsize); | ||
2747 | - | ||
2748 | - ret = i2c_hid_get_report(client, | ||
2749 | - report_type == HID_FEATURE_REPORT ? 0x03 : 0x01, | ||
2750 | - report_number, ihid->rawbuf, ask_count); | ||
2751 | - | ||
2752 | - if (ret < 0) | ||
2753 | - return ret; | ||
2754 | - | ||
2755 | - ret_count = ihid->rawbuf[0] | (ihid->rawbuf[1] << 8); | ||
2756 | - | ||
2757 | - if (ret_count <= 2) | ||
2758 | - return 0; | ||
2759 | - | ||
2760 | - ret_count = min(ret_count, ask_count); | ||
2761 | - | ||
2762 | - /* The query buffer contains the size, dropping it in the reply */ | ||
2763 | - count = min(count, ret_count - 2); | ||
2764 | - memcpy(buf, ihid->rawbuf + 2, count); | ||
2765 | - | ||
2766 | - return count; | ||
2767 | -} | ||
2768 | - | ||
2769 | -static int i2c_hid_output_raw_report(struct hid_device *hid, __u8 *buf, | ||
2770 | - size_t count, unsigned char report_type, bool use_data) | ||
2771 | -{ | ||
2772 | - struct i2c_client *client = hid->driver_data; | ||
2773 | - struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
2774 | - int report_id = buf[0]; | ||
2775 | - int ret; | ||
2776 | - | ||
2777 | - if (report_type == HID_INPUT_REPORT) | ||
2778 | - return -EINVAL; | ||
2779 | - | ||
2780 | - mutex_lock(&ihid->reset_lock); | ||
2781 | - | ||
2782 | - if (report_id) { | ||
2783 | - buf++; | ||
2784 | - count--; | ||
2785 | - } | ||
2786 | - | ||
2787 | - ret = i2c_hid_set_or_send_report(client, | ||
2788 | - report_type == HID_FEATURE_REPORT ? 0x03 : 0x02, | ||
2789 | - report_id, buf, count, use_data); | ||
2790 | - | ||
2791 | - if (report_id && ret >= 0) | ||
2792 | - ret++; /* add report_id to the number of transfered bytes */ | ||
2793 | - | ||
2794 | - mutex_unlock(&ihid->reset_lock); | ||
2795 | - | ||
2796 | - return ret; | ||
2797 | -} | ||
2798 | - | ||
2799 | -static int i2c_hid_output_report(struct hid_device *hid, __u8 *buf, | ||
2800 | - size_t count) | ||
2801 | -{ | ||
2802 | - return i2c_hid_output_raw_report(hid, buf, count, HID_OUTPUT_REPORT, | ||
2803 | - false); | ||
2804 | -} | ||
2805 | - | ||
2806 | -static int i2c_hid_raw_request(struct hid_device *hid, unsigned char reportnum, | ||
2807 | - __u8 *buf, size_t len, unsigned char rtype, | ||
2808 | - int reqtype) | ||
2809 | -{ | ||
2810 | - switch (reqtype) { | ||
2811 | - case HID_REQ_GET_REPORT: | ||
2812 | - return i2c_hid_get_raw_report(hid, reportnum, buf, len, rtype); | ||
2813 | - case HID_REQ_SET_REPORT: | ||
2814 | - if (buf[0] != reportnum) | ||
2815 | - return -EINVAL; | ||
2816 | - return i2c_hid_output_raw_report(hid, buf, len, rtype, true); | ||
2817 | - default: | ||
2818 | - return -EIO; | ||
2819 | - } | ||
2820 | -} | ||
2821 | - | ||
2822 | -static int i2c_hid_parse(struct hid_device *hid) | ||
2823 | -{ | ||
2824 | - struct i2c_client *client = hid->driver_data; | ||
2825 | - struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
2826 | - struct i2c_hid_desc *hdesc = &ihid->hdesc; | ||
2827 | - unsigned int rsize; | ||
2828 | - char *rdesc; | ||
2829 | - int ret; | ||
2830 | - int tries = 3; | ||
2831 | - | ||
2832 | - i2c_hid_dbg(ihid, "entering %s\n", __func__); | ||
2833 | - | ||
2834 | - rsize = le16_to_cpu(hdesc->wReportDescLength); | ||
2835 | - if (!rsize || rsize > HID_MAX_DESCRIPTOR_SIZE) { | ||
2836 | - dbg_hid("weird size of report descriptor (%u)\n", rsize); | ||
2837 | - return -EINVAL; | ||
2838 | - } | ||
2839 | - | ||
2840 | - do { | ||
2841 | - ret = i2c_hid_hwreset(client); | ||
2842 | - if (ret) | ||
2843 | - msleep(1000); | ||
2844 | - } while (tries-- > 0 && ret); | ||
2845 | - | ||
2846 | - if (ret) | ||
2847 | - return ret; | ||
2848 | - | ||
2849 | - rdesc = kzalloc(rsize, GFP_KERNEL); | ||
2850 | - | ||
2851 | - if (!rdesc) { | ||
2852 | - dbg_hid("couldn't allocate rdesc memory\n"); | ||
2853 | - return -ENOMEM; | ||
2854 | - } | ||
2855 | - | ||
2856 | - i2c_hid_dbg(ihid, "asking HID report descriptor\n"); | ||
2857 | - | ||
2858 | - ret = i2c_hid_command(client, &hid_report_descr_cmd, rdesc, rsize); | ||
2859 | - if (ret) { | ||
2860 | - hid_err(hid, "reading report descriptor failed\n"); | ||
2861 | - kfree(rdesc); | ||
2862 | - return -EIO; | ||
2863 | - } | ||
2864 | - | ||
2865 | - i2c_hid_dbg(ihid, "Report Descriptor: %*ph\n", rsize, rdesc); | ||
2866 | - | ||
2867 | - ret = hid_parse_report(hid, rdesc, rsize); | ||
2868 | - kfree(rdesc); | ||
2869 | - if (ret) { | ||
2870 | - dbg_hid("parsing report descriptor failed\n"); | ||
2871 | - return ret; | ||
2872 | - } | ||
2873 | - | ||
2874 | - return 0; | ||
2875 | -} | ||
2876 | - | ||
2877 | -static int i2c_hid_start(struct hid_device *hid) | ||
2878 | -{ | ||
2879 | - struct i2c_client *client = hid->driver_data; | ||
2880 | - struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
2881 | - int ret; | ||
2882 | - unsigned int bufsize = HID_MIN_BUFFER_SIZE; | ||
2883 | - | ||
2884 | - i2c_hid_find_max_report(hid, HID_INPUT_REPORT, &bufsize); | ||
2885 | - i2c_hid_find_max_report(hid, HID_OUTPUT_REPORT, &bufsize); | ||
2886 | - i2c_hid_find_max_report(hid, HID_FEATURE_REPORT, &bufsize); | ||
2887 | - | ||
2888 | - if (bufsize > ihid->bufsize) { | ||
2889 | - i2c_hid_free_buffers(ihid); | ||
2890 | - | ||
2891 | - ret = i2c_hid_alloc_buffers(ihid, bufsize); | ||
2892 | - | ||
2893 | - if (ret) | ||
2894 | - return ret; | ||
2895 | - } | ||
2896 | - | ||
2897 | - if (!(hid->quirks & HID_QUIRK_NO_INIT_REPORTS)) | ||
2898 | - i2c_hid_init_reports(hid); | ||
2899 | - | ||
2900 | - return 0; | ||
2901 | -} | ||
2902 | - | ||
2903 | -static void i2c_hid_stop(struct hid_device *hid) | ||
2904 | -{ | ||
2905 | - hid->claimed = 0; | ||
2906 | -} | ||
2907 | - | ||
2908 | -static int i2c_hid_open(struct hid_device *hid) | ||
2909 | -{ | ||
2910 | - struct i2c_client *client = hid->driver_data; | ||
2911 | - struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
2912 | - int ret = 0; | ||
2913 | - | ||
2914 | - mutex_lock(&i2c_hid_open_mut); | ||
2915 | - if (!hid->open++) { | ||
2916 | - ret = pm_runtime_get_sync(&client->dev); | ||
2917 | - if (ret < 0) { | ||
2918 | - hid->open--; | ||
2919 | - goto done; | ||
2920 | - } | ||
2921 | - set_bit(I2C_HID_STARTED, &ihid->flags); | ||
2922 | - } | ||
2923 | -done: | ||
2924 | - mutex_unlock(&i2c_hid_open_mut); | ||
2925 | - return ret < 0 ? ret : 0; | ||
2926 | -} | ||
2927 | - | ||
2928 | -static void i2c_hid_close(struct hid_device *hid) | ||
2929 | -{ | ||
2930 | - struct i2c_client *client = hid->driver_data; | ||
2931 | - struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
2932 | - | ||
2933 | - /* protecting hid->open to make sure we don't restart | ||
2934 | - * data acquistion due to a resumption we no longer | ||
2935 | - * care about | ||
2936 | - */ | ||
2937 | - mutex_lock(&i2c_hid_open_mut); | ||
2938 | - if (!--hid->open) { | ||
2939 | - clear_bit(I2C_HID_STARTED, &ihid->flags); | ||
2940 | - | ||
2941 | - /* Save some power */ | ||
2942 | - pm_runtime_put(&client->dev); | ||
2943 | - } | ||
2944 | - mutex_unlock(&i2c_hid_open_mut); | ||
2945 | -} | ||
2946 | - | ||
2947 | -static int i2c_hid_power(struct hid_device *hid, int lvl) | ||
2948 | -{ | ||
2949 | - struct i2c_client *client = hid->driver_data; | ||
2950 | - struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
2951 | - | ||
2952 | - i2c_hid_dbg(ihid, "%s lvl:%d\n", __func__, lvl); | ||
2953 | - | ||
2954 | - switch (lvl) { | ||
2955 | - case PM_HINT_FULLON: | ||
2956 | - pm_runtime_get_sync(&client->dev); | ||
2957 | - break; | ||
2958 | - case PM_HINT_NORMAL: | ||
2959 | - pm_runtime_put(&client->dev); | ||
2960 | - break; | ||
2961 | - } | ||
2962 | - return 0; | ||
2963 | -} | ||
2964 | - | ||
2965 | -static struct hid_ll_driver i2c_hid_ll_driver = { | ||
2966 | - .parse = i2c_hid_parse, | ||
2967 | - .start = i2c_hid_start, | ||
2968 | - .stop = i2c_hid_stop, | ||
2969 | - .open = i2c_hid_open, | ||
2970 | - .close = i2c_hid_close, | ||
2971 | - .power = i2c_hid_power, | ||
2972 | - .output_report = i2c_hid_output_report, | ||
2973 | - .raw_request = i2c_hid_raw_request, | ||
2974 | -}; | ||
2975 | - | ||
2976 | -static int i2c_hid_init_irq(struct i2c_client *client) | ||
2977 | -{ | ||
2978 | - struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
2979 | - int ret; | ||
2980 | - | ||
2981 | - dev_dbg(&client->dev, "Requesting IRQ: %d\n", ihid->irq); | ||
2982 | - | ||
2983 | - ret = request_threaded_irq(ihid->irq, NULL, i2c_hid_irq, | ||
2984 | - IRQF_TRIGGER_LOW | IRQF_ONESHOT, | ||
2985 | - client->name, ihid); | ||
2986 | - if (ret < 0) { | ||
2987 | - dev_warn(&client->dev, | ||
2988 | - "Could not register for %s interrupt, irq = %d," | ||
2989 | - " ret = %d\n", | ||
2990 | - client->name, ihid->irq, ret); | ||
2991 | - | ||
2992 | - return ret; | ||
2993 | - } | ||
2994 | - | ||
2995 | - return 0; | ||
2996 | -} | ||
2997 | - | ||
2998 | -static int i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid) | ||
2999 | -{ | ||
3000 | - struct i2c_client *client = ihid->client; | ||
3001 | - struct i2c_hid_desc *hdesc = &ihid->hdesc; | ||
3002 | - unsigned int dsize; | ||
3003 | - int ret; | ||
3004 | - | ||
3005 | - /* i2c hid fetch using a fixed descriptor size (30 bytes) */ | ||
3006 | - i2c_hid_dbg(ihid, "Fetching the HID descriptor\n"); | ||
3007 | - ret = i2c_hid_command(client, &hid_descr_cmd, ihid->hdesc_buffer, | ||
3008 | - sizeof(struct i2c_hid_desc)); | ||
3009 | - if (ret) { | ||
3010 | - dev_err(&client->dev, "hid_descr_cmd failed\n"); | ||
3011 | - return -ENODEV; | ||
3012 | - } | ||
3013 | - | ||
3014 | - /* Validate the length of HID descriptor, the 4 first bytes: | ||
3015 | - * bytes 0-1 -> length | ||
3016 | - * bytes 2-3 -> bcdVersion (has to be 1.00) */ | ||
3017 | - /* check bcdVersion == 1.0 */ | ||
3018 | - if (le16_to_cpu(hdesc->bcdVersion) != 0x0100) { | ||
3019 | - dev_err(&client->dev, | ||
3020 | - "unexpected HID descriptor bcdVersion (0x%04hx)\n", | ||
3021 | - le16_to_cpu(hdesc->bcdVersion)); | ||
3022 | - return -ENODEV; | ||
3023 | - } | ||
3024 | - | ||
3025 | - /* Descriptor length should be 30 bytes as per the specification */ | ||
3026 | - dsize = le16_to_cpu(hdesc->wHIDDescLength); | ||
3027 | - if (dsize != sizeof(struct i2c_hid_desc)) { | ||
3028 | - dev_err(&client->dev, "weird size of HID descriptor (%u)\n", | ||
3029 | - dsize); | ||
3030 | - return -ENODEV; | ||
3031 | - } | ||
3032 | - i2c_hid_dbg(ihid, "HID Descriptor: %*ph\n", dsize, ihid->hdesc_buffer); | ||
3033 | - return 0; | ||
3034 | -} | ||
3035 | - | ||
3036 | -#ifdef CONFIG_ACPI | ||
3037 | - | ||
3038 | -/* Default GPIO mapping */ | ||
3039 | -static const struct acpi_gpio_params i2c_hid_irq_gpio = { 0, 0, true }; | ||
3040 | -static const struct acpi_gpio_mapping i2c_hid_acpi_gpios[] = { | ||
3041 | - { "gpios", &i2c_hid_irq_gpio, 1 }, | ||
3042 | - { }, | ||
3043 | -}; | ||
3044 | - | ||
3045 | -static int i2c_hid_acpi_pdata(struct i2c_client *client, | ||
3046 | - struct i2c_hid_platform_data *pdata) | ||
3047 | -{ | ||
3048 | - static u8 i2c_hid_guid[] = { | ||
3049 | - 0xF7, 0xF6, 0xDF, 0x3C, 0x67, 0x42, 0x55, 0x45, | ||
3050 | - 0xAD, 0x05, 0xB3, 0x0A, 0x3D, 0x89, 0x38, 0xDE, | ||
3051 | - }; | ||
3052 | - union acpi_object *obj; | ||
3053 | - struct acpi_device *adev; | ||
3054 | - acpi_handle handle; | ||
3055 | - int ret; | ||
3056 | - | ||
3057 | - handle = ACPI_HANDLE(&client->dev); | ||
3058 | - if (!handle || acpi_bus_get_device(handle, &adev)) | ||
3059 | - return -ENODEV; | ||
3060 | - | ||
3061 | - obj = acpi_evaluate_dsm_typed(handle, i2c_hid_guid, 1, 1, NULL, | ||
3062 | - ACPI_TYPE_INTEGER); | ||
3063 | - if (!obj) { | ||
3064 | - dev_err(&client->dev, "device _DSM execution failed\n"); | ||
3065 | - return -ENODEV; | ||
3066 | - } | ||
3067 | - | ||
3068 | - pdata->hid_descriptor_address = obj->integer.value; | ||
3069 | - ACPI_FREE(obj); | ||
3070 | - | ||
3071 | - /* GPIOs are optional */ | ||
3072 | - ret = acpi_dev_add_driver_gpios(adev, i2c_hid_acpi_gpios); | ||
3073 | - return ret < 0 && ret != -ENXIO ? ret : 0; | ||
3074 | -} | ||
3075 | - | ||
3076 | -static void i2c_hid_acpi_fix_up_power(struct device *dev) | ||
3077 | -{ | ||
3078 | - acpi_handle handle = ACPI_HANDLE(dev); | ||
3079 | - struct acpi_device *adev; | ||
3080 | - | ||
3081 | - if (handle && acpi_bus_get_device(handle, &adev) == 0) | ||
3082 | - acpi_device_fix_up_power(adev); | ||
3083 | -} | ||
3084 | - | ||
3085 | -static const struct acpi_device_id i2c_hid_acpi_match[] = { | ||
3086 | - {"ACPI0C50", 0 }, | ||
3087 | - {"PNP0C50", 0 }, | ||
3088 | - { }, | ||
3089 | -}; | ||
3090 | -MODULE_DEVICE_TABLE(acpi, i2c_hid_acpi_match); | ||
3091 | -#else | ||
3092 | -static inline int i2c_hid_acpi_pdata(struct i2c_client *client, | ||
3093 | - struct i2c_hid_platform_data *pdata) | ||
3094 | -{ | ||
3095 | - return -ENODEV; | ||
3096 | -} | ||
3097 | - | ||
3098 | -static inline void i2c_hid_acpi_fix_up_power(struct device *dev) {} | ||
3099 | -#endif | ||
3100 | - | ||
3101 | -#ifdef CONFIG_OF | ||
3102 | -static int i2c_hid_of_probe(struct i2c_client *client, | ||
3103 | - struct i2c_hid_platform_data *pdata) | ||
3104 | -{ | ||
3105 | - struct device *dev = &client->dev; | ||
3106 | - u32 val; | ||
3107 | - int ret; | ||
3108 | - | ||
3109 | - ret = of_property_read_u32(dev->of_node, "hid-descr-addr", &val); | ||
3110 | - if (ret) { | ||
3111 | - dev_err(&client->dev, "HID register address not provided\n"); | ||
3112 | - return -ENODEV; | ||
3113 | - } | ||
3114 | - if (val >> 16) { | ||
3115 | - dev_err(&client->dev, "Bad HID register address: 0x%08x\n", | ||
3116 | - val); | ||
3117 | - return -EINVAL; | ||
3118 | - } | ||
3119 | - pdata->hid_descriptor_address = val; | ||
3120 | - | ||
3121 | - return 0; | ||
3122 | -} | ||
3123 | - | ||
3124 | -static const struct of_device_id i2c_hid_of_match[] = { | ||
3125 | - { .compatible = "hid-over-i2c" }, | ||
3126 | - {}, | ||
3127 | -}; | ||
3128 | -MODULE_DEVICE_TABLE(of, i2c_hid_of_match); | ||
3129 | -#else | ||
3130 | -static inline int i2c_hid_of_probe(struct i2c_client *client, | ||
3131 | - struct i2c_hid_platform_data *pdata) | ||
3132 | -{ | ||
3133 | - return -ENODEV; | ||
3134 | -} | ||
3135 | -#endif | ||
3136 | - | ||
3137 | -static int i2c_hid_probe(struct i2c_client *client, | ||
3138 | - const struct i2c_device_id *dev_id) | ||
3139 | -{ | ||
3140 | - int ret; | ||
3141 | - struct i2c_hid *ihid; | ||
3142 | - struct hid_device *hid; | ||
3143 | - __u16 hidRegister; | ||
3144 | - struct i2c_hid_platform_data *platform_data = client->dev.platform_data; | ||
3145 | - | ||
3146 | - dbg_hid("HID probe called for i2c 0x%02x\n", client->addr); | ||
3147 | - | ||
3148 | - ihid = kzalloc(sizeof(struct i2c_hid), GFP_KERNEL); | ||
3149 | - if (!ihid) | ||
3150 | - return -ENOMEM; | ||
3151 | - | ||
3152 | - if (client->dev.of_node) { | ||
3153 | - ret = i2c_hid_of_probe(client, &ihid->pdata); | ||
3154 | - if (ret) | ||
3155 | - goto err; | ||
3156 | - } else if (!platform_data) { | ||
3157 | - ret = i2c_hid_acpi_pdata(client, &ihid->pdata); | ||
3158 | - if (ret) { | ||
3159 | - dev_err(&client->dev, | ||
3160 | - "HID register address not provided\n"); | ||
3161 | - goto err; | ||
3162 | - } | ||
3163 | - } else { | ||
3164 | - ihid->pdata = *platform_data; | ||
3165 | - } | ||
3166 | - | ||
3167 | - if (client->irq > 0) { | ||
3168 | - ihid->irq = client->irq; | ||
3169 | - } else if (ACPI_COMPANION(&client->dev)) { | ||
3170 | - ihid->desc = gpiod_get(&client->dev, NULL, GPIOD_IN); | ||
3171 | - if (IS_ERR(ihid->desc)) { | ||
3172 | - dev_err(&client->dev, "Failed to get GPIO interrupt\n"); | ||
3173 | - return PTR_ERR(ihid->desc); | ||
3174 | - } | ||
3175 | - | ||
3176 | - ihid->irq = gpiod_to_irq(ihid->desc); | ||
3177 | - if (ihid->irq < 0) { | ||
3178 | - gpiod_put(ihid->desc); | ||
3179 | - dev_err(&client->dev, "Failed to convert GPIO to IRQ\n"); | ||
3180 | - return ihid->irq; | ||
3181 | - } | ||
3182 | - } | ||
3183 | - | ||
3184 | - i2c_set_clientdata(client, ihid); | ||
3185 | - | ||
3186 | - ihid->client = client; | ||
3187 | - | ||
3188 | - hidRegister = ihid->pdata.hid_descriptor_address; | ||
3189 | - ihid->wHIDDescRegister = cpu_to_le16(hidRegister); | ||
3190 | - | ||
3191 | - init_waitqueue_head(&ihid->wait); | ||
3192 | - mutex_init(&ihid->reset_lock); | ||
3193 | - | ||
3194 | - /* we need to allocate the command buffer without knowing the maximum | ||
3195 | - * size of the reports. Let's use HID_MIN_BUFFER_SIZE, then we do the | ||
3196 | - * real computation later. */ | ||
3197 | - ret = i2c_hid_alloc_buffers(ihid, HID_MIN_BUFFER_SIZE); | ||
3198 | - if (ret < 0) | ||
3199 | - goto err; | ||
3200 | - | ||
3201 | - i2c_hid_acpi_fix_up_power(&client->dev); | ||
3202 | - | ||
3203 | - pm_runtime_get_noresume(&client->dev); | ||
3204 | - pm_runtime_set_active(&client->dev); | ||
3205 | - pm_runtime_enable(&client->dev); | ||
3206 | - device_enable_async_suspend(&client->dev); | ||
3207 | - | ||
3208 | - /* Make sure there is something at this address */ | ||
3209 | - ret = i2c_smbus_read_byte(client); | ||
3210 | - if (ret < 0) { | ||
3211 | - dev_dbg(&client->dev, "nothing at this address: %d\n", ret); | ||
3212 | - ret = -ENXIO; | ||
3213 | - goto err_pm; | ||
3214 | - } | ||
3215 | - | ||
3216 | - ret = i2c_hid_fetch_hid_descriptor(ihid); | ||
3217 | - if (ret < 0) | ||
3218 | - goto err_pm; | ||
3219 | - | ||
3220 | - ret = i2c_hid_init_irq(client); | ||
3221 | - if (ret < 0) | ||
3222 | - goto err_pm; | ||
3223 | - | ||
3224 | - hid = hid_allocate_device(); | ||
3225 | - if (IS_ERR(hid)) { | ||
3226 | - ret = PTR_ERR(hid); | ||
3227 | - goto err_irq; | ||
3228 | - } | ||
3229 | - | ||
3230 | - ihid->hid = hid; | ||
3231 | - | ||
3232 | - hid->driver_data = client; | ||
3233 | - hid->ll_driver = &i2c_hid_ll_driver; | ||
3234 | - hid->dev.parent = &client->dev; | ||
3235 | - hid->bus = BUS_I2C; | ||
3236 | - hid->version = le16_to_cpu(ihid->hdesc.bcdVersion); | ||
3237 | - hid->vendor = le16_to_cpu(ihid->hdesc.wVendorID); | ||
3238 | - hid->product = le16_to_cpu(ihid->hdesc.wProductID); | ||
3239 | - | ||
3240 | - snprintf(hid->name, sizeof(hid->name), "%s %04hX:%04hX", | ||
3241 | - client->name, hid->vendor, hid->product); | ||
3242 | - strlcpy(hid->phys, dev_name(&client->dev), sizeof(hid->phys)); | ||
3243 | - | ||
3244 | - ihid->quirks = i2c_hid_lookup_quirk(hid->vendor, hid->product); | ||
3245 | - | ||
3246 | - ret = hid_add_device(hid); | ||
3247 | - if (ret) { | ||
3248 | - if (ret != -ENODEV) | ||
3249 | - hid_err(client, "can't add hid device: %d\n", ret); | ||
3250 | - goto err_mem_free; | ||
3251 | - } | ||
3252 | - | ||
3253 | - pm_runtime_put(&client->dev); | ||
3254 | - return 0; | ||
3255 | - | ||
3256 | -err_mem_free: | ||
3257 | - hid_destroy_device(hid); | ||
3258 | - | ||
3259 | -err_irq: | ||
3260 | - free_irq(ihid->irq, ihid); | ||
3261 | - | ||
3262 | -err_pm: | ||
3263 | - pm_runtime_put_noidle(&client->dev); | ||
3264 | - pm_runtime_disable(&client->dev); | ||
3265 | - | ||
3266 | -err: | ||
3267 | - if (ihid->desc) | ||
3268 | - gpiod_put(ihid->desc); | ||
3269 | - | ||
3270 | - i2c_hid_free_buffers(ihid); | ||
3271 | - kfree(ihid); | ||
3272 | - return ret; | ||
3273 | -} | ||
3274 | - | ||
3275 | -static int i2c_hid_remove(struct i2c_client *client) | ||
3276 | -{ | ||
3277 | - struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
3278 | - struct hid_device *hid; | ||
3279 | - | ||
3280 | - pm_runtime_get_sync(&client->dev); | ||
3281 | - pm_runtime_disable(&client->dev); | ||
3282 | - pm_runtime_set_suspended(&client->dev); | ||
3283 | - pm_runtime_put_noidle(&client->dev); | ||
3284 | - | ||
3285 | - hid = ihid->hid; | ||
3286 | - hid_destroy_device(hid); | ||
3287 | - | ||
3288 | - free_irq(ihid->irq, ihid); | ||
3289 | - | ||
3290 | - if (ihid->bufsize) | ||
3291 | - i2c_hid_free_buffers(ihid); | ||
3292 | - | ||
3293 | - if (ihid->desc) | ||
3294 | - gpiod_put(ihid->desc); | ||
3295 | - | ||
3296 | - kfree(ihid); | ||
3297 | - | ||
3298 | - acpi_dev_remove_driver_gpios(ACPI_COMPANION(&client->dev)); | ||
3299 | - | ||
3300 | - return 0; | ||
3301 | -} | ||
3302 | - | ||
3303 | -static void i2c_hid_shutdown(struct i2c_client *client) | ||
3304 | -{ | ||
3305 | - struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
3306 | - | ||
3307 | - i2c_hid_set_power(client, I2C_HID_PWR_SLEEP); | ||
3308 | - free_irq(client->irq, ihid); | ||
3309 | -} | ||
3310 | - | ||
3311 | -#ifdef CONFIG_PM_SLEEP | ||
3312 | -static int i2c_hid_suspend(struct device *dev) | ||
3313 | -{ | ||
3314 | - struct i2c_client *client = to_i2c_client(dev); | ||
3315 | - struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
3316 | - struct hid_device *hid = ihid->hid; | ||
3317 | - int ret; | ||
3318 | - int wake_status; | ||
3319 | - | ||
3320 | - if (hid->driver && hid->driver->suspend) { | ||
3321 | - /* | ||
3322 | - * Wake up the device so that IO issues in | ||
3323 | - * HID driver's suspend code can succeed. | ||
3324 | - */ | ||
3325 | - ret = pm_runtime_resume(dev); | ||
3326 | - if (ret < 0) | ||
3327 | - return ret; | ||
3328 | - | ||
3329 | - ret = hid->driver->suspend(hid, PMSG_SUSPEND); | ||
3330 | - if (ret < 0) | ||
3331 | - return ret; | ||
3332 | - } | ||
3333 | - | ||
3334 | - if (!pm_runtime_suspended(dev)) { | ||
3335 | - /* Save some power */ | ||
3336 | - i2c_hid_set_power(client, I2C_HID_PWR_SLEEP); | ||
3337 | - | ||
3338 | - disable_irq(ihid->irq); | ||
3339 | - } | ||
3340 | - | ||
3341 | - if (device_may_wakeup(&client->dev)) { | ||
3342 | - wake_status = enable_irq_wake(ihid->irq); | ||
3343 | - if (!wake_status) | ||
3344 | - ihid->irq_wake_enabled = true; | ||
3345 | - else | ||
3346 | - hid_warn(hid, "Failed to enable irq wake: %d\n", | ||
3347 | - wake_status); | ||
3348 | - } | ||
3349 | - | ||
3350 | - return 0; | ||
3351 | -} | ||
3352 | - | ||
3353 | -static int i2c_hid_resume(struct device *dev) | ||
3354 | -{ | ||
3355 | - int ret; | ||
3356 | - struct i2c_client *client = to_i2c_client(dev); | ||
3357 | - struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
3358 | - struct hid_device *hid = ihid->hid; | ||
3359 | - int wake_status; | ||
3360 | - | ||
3361 | - if (device_may_wakeup(&client->dev) && ihid->irq_wake_enabled) { | ||
3362 | - wake_status = disable_irq_wake(ihid->irq); | ||
3363 | - if (!wake_status) | ||
3364 | - ihid->irq_wake_enabled = false; | ||
3365 | - else | ||
3366 | - hid_warn(hid, "Failed to disable irq wake: %d\n", | ||
3367 | - wake_status); | ||
3368 | - } | ||
3369 | - | ||
3370 | - /* We'll resume to full power */ | ||
3371 | - pm_runtime_disable(dev); | ||
3372 | - pm_runtime_set_active(dev); | ||
3373 | - pm_runtime_enable(dev); | ||
3374 | - | ||
3375 | - enable_irq(ihid->irq); | ||
3376 | - ret = i2c_hid_hwreset(client); | ||
3377 | - if (ret) | ||
3378 | - return ret; | ||
3379 | - | ||
3380 | - if (hid->driver && hid->driver->reset_resume) { | ||
3381 | - ret = hid->driver->reset_resume(hid); | ||
3382 | - return ret; | ||
3383 | - } | ||
3384 | - | ||
3385 | - return 0; | ||
3386 | -} | ||
3387 | -#endif | ||
3388 | - | ||
3389 | -#ifdef CONFIG_PM | ||
3390 | -static int i2c_hid_runtime_suspend(struct device *dev) | ||
3391 | -{ | ||
3392 | - struct i2c_client *client = to_i2c_client(dev); | ||
3393 | - struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
3394 | - | ||
3395 | - i2c_hid_set_power(client, I2C_HID_PWR_SLEEP); | ||
3396 | - disable_irq(ihid->irq); | ||
3397 | - return 0; | ||
3398 | -} | ||
3399 | - | ||
3400 | -static int i2c_hid_runtime_resume(struct device *dev) | ||
3401 | -{ | ||
3402 | - struct i2c_client *client = to_i2c_client(dev); | ||
3403 | - struct i2c_hid *ihid = i2c_get_clientdata(client); | ||
3404 | - | ||
3405 | - enable_irq(ihid->irq); | ||
3406 | - i2c_hid_set_power(client, I2C_HID_PWR_ON); | ||
3407 | - return 0; | ||
3408 | -} | ||
3409 | -#endif | ||
3410 | - | ||
3411 | -static const struct dev_pm_ops i2c_hid_pm = { | ||
3412 | - SET_SYSTEM_SLEEP_PM_OPS(i2c_hid_suspend, i2c_hid_resume) | ||
3413 | - SET_RUNTIME_PM_OPS(i2c_hid_runtime_suspend, i2c_hid_runtime_resume, | ||
3414 | - NULL) | ||
3415 | -}; | ||
3416 | - | ||
3417 | -static const struct i2c_device_id i2c_hid_id_table[] = { | ||
3418 | - { "hid", 0 }, | ||
3419 | - { "hid-over-i2c", 0 }, | ||
3420 | - { }, | ||
3421 | -}; | ||
3422 | -MODULE_DEVICE_TABLE(i2c, i2c_hid_id_table); | ||
3423 | - | ||
3424 | - | ||
3425 | -static struct i2c_driver i2c_hid_driver = { | ||
3426 | - .driver = { | ||
3427 | - .name = "i2c_hid", | ||
3428 | - .pm = &i2c_hid_pm, | ||
3429 | - .acpi_match_table = ACPI_PTR(i2c_hid_acpi_match), | ||
3430 | - .of_match_table = of_match_ptr(i2c_hid_of_match), | ||
3431 | - }, | ||
3432 | - | ||
3433 | - .probe = i2c_hid_probe, | ||
3434 | - .remove = i2c_hid_remove, | ||
3435 | - .shutdown = i2c_hid_shutdown, | ||
3436 | - .id_table = i2c_hid_id_table, | ||
3437 | -}; | ||
3438 | - | ||
3439 | -module_i2c_driver(i2c_hid_driver); | ||
3440 | - | ||
3441 | -MODULE_DESCRIPTION("HID over I2C core driver"); | ||
3442 | -MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>"); | ||
3443 | -MODULE_LICENSE("GPL"); | ||
3444 | diff --git a/drivers/hid/i2c-hid/i2c-hid.h b/drivers/hid/i2c-hid/i2c-hid.h | ||
3445 | new file mode 100644 | ||
3446 | index 000000000000..a8c19aef5824 | ||
3447 | --- /dev/null | ||
3448 | +++ b/drivers/hid/i2c-hid/i2c-hid.h | ||
3449 | @@ -0,0 +1,20 @@ | ||
3450 | +/* SPDX-License-Identifier: GPL-2.0+ */ | ||
3451 | + | ||
3452 | +#ifndef I2C_HID_H | ||
3453 | +#define I2C_HID_H | ||
3454 | + | ||
3455 | + | ||
3456 | +#ifdef CONFIG_DMI | ||
3457 | +struct i2c_hid_desc *i2c_hid_get_dmi_i2c_hid_desc_override(uint8_t *i2c_name); | ||
3458 | +char *i2c_hid_get_dmi_hid_report_desc_override(uint8_t *i2c_name, | ||
3459 | + unsigned int *size); | ||
3460 | +#else | ||
3461 | +static inline struct i2c_hid_desc | ||
3462 | + *i2c_hid_get_dmi_i2c_hid_desc_override(uint8_t *i2c_name) | ||
3463 | +{ return NULL; } | ||
3464 | +static inline char *i2c_hid_get_dmi_hid_report_desc_override(uint8_t *i2c_name, | ||
3465 | + unsigned int *size) | ||
3466 | +{ return NULL; } | ||
3467 | +#endif | ||
3468 | + | ||
3469 | +#endif | ||
3470 | diff --git a/drivers/infiniband/hw/mlx4/alias_GUID.c b/drivers/infiniband/hw/mlx4/alias_GUID.c | ||
3471 | index 5e9939045852..ec138845a474 100644 | ||
3472 | --- a/drivers/infiniband/hw/mlx4/alias_GUID.c | ||
3473 | +++ b/drivers/infiniband/hw/mlx4/alias_GUID.c | ||
3474 | @@ -805,8 +805,8 @@ void mlx4_ib_destroy_alias_guid_service(struct mlx4_ib_dev *dev) | ||
3475 | unsigned long flags; | ||
3476 | |||
3477 | for (i = 0 ; i < dev->num_ports; i++) { | ||
3478 | - cancel_delayed_work(&dev->sriov.alias_guid.ports_guid[i].alias_guid_work); | ||
3479 | det = &sriov->alias_guid.ports_guid[i]; | ||
3480 | + cancel_delayed_work_sync(&det->alias_guid_work); | ||
3481 | spin_lock_irqsave(&sriov->alias_guid.ag_work_lock, flags); | ||
3482 | while (!list_empty(&det->cb_list)) { | ||
3483 | cb_ctx = list_entry(det->cb_list.next, | ||
3484 | diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c | ||
3485 | index 63110fbbb410..d51734e0c350 100644 | ||
3486 | --- a/drivers/iommu/dmar.c | ||
3487 | +++ b/drivers/iommu/dmar.c | ||
3488 | @@ -143,7 +143,7 @@ dmar_alloc_pci_notify_info(struct pci_dev *dev, unsigned long event) | ||
3489 | for (tmp = dev; tmp; tmp = tmp->bus->self) | ||
3490 | level++; | ||
3491 | |||
3492 | - size = sizeof(*info) + level * sizeof(struct acpi_dmar_pci_path); | ||
3493 | + size = sizeof(*info) + level * sizeof(info->path[0]); | ||
3494 | if (size <= sizeof(dmar_pci_notify_info_buf)) { | ||
3495 | info = (struct dmar_pci_notify_info *)dmar_pci_notify_info_buf; | ||
3496 | } else { | ||
3497 | diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c | ||
3498 | index 86e349614e21..28feb1744710 100644 | ||
3499 | --- a/drivers/iommu/intel-iommu.c | ||
3500 | +++ b/drivers/iommu/intel-iommu.c | ||
3501 | @@ -1636,6 +1636,9 @@ static void iommu_disable_protect_mem_regions(struct intel_iommu *iommu) | ||
3502 | u32 pmen; | ||
3503 | unsigned long flags; | ||
3504 | |||
3505 | + if (!cap_plmr(iommu->cap) && !cap_phmr(iommu->cap)) | ||
3506 | + return; | ||
3507 | + | ||
3508 | raw_spin_lock_irqsave(&iommu->register_lock, flags); | ||
3509 | pmen = readl(iommu->reg + DMAR_PMEN_REG); | ||
3510 | pmen &= ~DMA_PMEN_EPM; | ||
3511 | diff --git a/drivers/irqchip/irq-mbigen.c b/drivers/irqchip/irq-mbigen.c | ||
3512 | index 05d87f60d929..406bfe618448 100644 | ||
3513 | --- a/drivers/irqchip/irq-mbigen.c | ||
3514 | +++ b/drivers/irqchip/irq-mbigen.c | ||
3515 | @@ -160,6 +160,9 @@ static void mbigen_write_msg(struct msi_desc *desc, struct msi_msg *msg) | ||
3516 | void __iomem *base = d->chip_data; | ||
3517 | u32 val; | ||
3518 | |||
3519 | + if (!msg->address_lo && !msg->address_hi) | ||
3520 | + return; | ||
3521 | + | ||
3522 | base += get_mbigen_vec_reg(d->hwirq); | ||
3523 | val = readl_relaxed(base); | ||
3524 | |||
3525 | diff --git a/drivers/misc/lkdtm.h b/drivers/misc/lkdtm.h | ||
3526 | index fdf954c2107f..6abc97b245e4 100644 | ||
3527 | --- a/drivers/misc/lkdtm.h | ||
3528 | +++ b/drivers/misc/lkdtm.h | ||
3529 | @@ -40,7 +40,9 @@ void lkdtm_EXEC_KMALLOC(void); | ||
3530 | void lkdtm_EXEC_VMALLOC(void); | ||
3531 | void lkdtm_EXEC_RODATA(void); | ||
3532 | void lkdtm_EXEC_USERSPACE(void); | ||
3533 | +void lkdtm_EXEC_NULL(void); | ||
3534 | void lkdtm_ACCESS_USERSPACE(void); | ||
3535 | +void lkdtm_ACCESS_NULL(void); | ||
3536 | |||
3537 | /* lkdtm_rodata.c */ | ||
3538 | void lkdtm_rodata_do_nothing(void); | ||
3539 | diff --git a/drivers/misc/lkdtm_core.c b/drivers/misc/lkdtm_core.c | ||
3540 | index b2989f2d3126..035e51bea450 100644 | ||
3541 | --- a/drivers/misc/lkdtm_core.c | ||
3542 | +++ b/drivers/misc/lkdtm_core.c | ||
3543 | @@ -214,7 +214,9 @@ struct crashtype crashtypes[] = { | ||
3544 | CRASHTYPE(EXEC_VMALLOC), | ||
3545 | CRASHTYPE(EXEC_RODATA), | ||
3546 | CRASHTYPE(EXEC_USERSPACE), | ||
3547 | + CRASHTYPE(EXEC_NULL), | ||
3548 | CRASHTYPE(ACCESS_USERSPACE), | ||
3549 | + CRASHTYPE(ACCESS_NULL), | ||
3550 | CRASHTYPE(WRITE_RO), | ||
3551 | CRASHTYPE(WRITE_RO_AFTER_INIT), | ||
3552 | CRASHTYPE(WRITE_KERN), | ||
3553 | diff --git a/drivers/misc/lkdtm_perms.c b/drivers/misc/lkdtm_perms.c | ||
3554 | index 45f1c0f96612..1a9dcdaa95f0 100644 | ||
3555 | --- a/drivers/misc/lkdtm_perms.c | ||
3556 | +++ b/drivers/misc/lkdtm_perms.c | ||
3557 | @@ -160,6 +160,11 @@ void lkdtm_EXEC_USERSPACE(void) | ||
3558 | vm_munmap(user_addr, PAGE_SIZE); | ||
3559 | } | ||
3560 | |||
3561 | +void lkdtm_EXEC_NULL(void) | ||
3562 | +{ | ||
3563 | + execute_location(NULL, CODE_AS_IS); | ||
3564 | +} | ||
3565 | + | ||
3566 | void lkdtm_ACCESS_USERSPACE(void) | ||
3567 | { | ||
3568 | unsigned long user_addr, tmp = 0; | ||
3569 | @@ -191,6 +196,19 @@ void lkdtm_ACCESS_USERSPACE(void) | ||
3570 | vm_munmap(user_addr, PAGE_SIZE); | ||
3571 | } | ||
3572 | |||
3573 | +void lkdtm_ACCESS_NULL(void) | ||
3574 | +{ | ||
3575 | + unsigned long tmp; | ||
3576 | + unsigned long *ptr = (unsigned long *)NULL; | ||
3577 | + | ||
3578 | + pr_info("attempting bad read at %px\n", ptr); | ||
3579 | + tmp = *ptr; | ||
3580 | + tmp += 0xc0dec0de; | ||
3581 | + | ||
3582 | + pr_info("attempting bad write at %px\n", ptr); | ||
3583 | + *ptr = tmp; | ||
3584 | +} | ||
3585 | + | ||
3586 | void __init lkdtm_perms_init(void) | ||
3587 | { | ||
3588 | /* Make sure we can write to __ro_after_init values during __init */ | ||
3589 | diff --git a/drivers/mmc/host/davinci_mmc.c b/drivers/mmc/host/davinci_mmc.c | ||
3590 | index 8fa478c3b0db..619457b90dc7 100644 | ||
3591 | --- a/drivers/mmc/host/davinci_mmc.c | ||
3592 | +++ b/drivers/mmc/host/davinci_mmc.c | ||
3593 | @@ -1120,7 +1120,7 @@ static inline void mmc_davinci_cpufreq_deregister(struct mmc_davinci_host *host) | ||
3594 | { | ||
3595 | } | ||
3596 | #endif | ||
3597 | -static void __init init_mmcsd_host(struct mmc_davinci_host *host) | ||
3598 | +static void init_mmcsd_host(struct mmc_davinci_host *host) | ||
3599 | { | ||
3600 | |||
3601 | mmc_davinci_reset_ctrl(host, 1); | ||
3602 | diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | ||
3603 | index fc437d75ac76..b46b56ad7517 100644 | ||
3604 | --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | ||
3605 | +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | ||
3606 | @@ -1747,11 +1747,6 @@ static int stmmac_hw_setup(struct net_device *dev, bool init_ptp) | ||
3607 | if (ret < 0) | ||
3608 | pr_warn("%s: failed debugFS registration\n", __func__); | ||
3609 | #endif | ||
3610 | - /* Start the ball rolling... */ | ||
3611 | - pr_debug("%s: DMA RX/TX processes started...\n", dev->name); | ||
3612 | - priv->hw->dma->start_tx(priv->ioaddr); | ||
3613 | - priv->hw->dma->start_rx(priv->ioaddr); | ||
3614 | - | ||
3615 | /* Dump DMA/MAC registers */ | ||
3616 | if (netif_msg_hw(priv)) { | ||
3617 | priv->hw->mac->dump_regs(priv->hw); | ||
3618 | @@ -1779,6 +1774,11 @@ static int stmmac_hw_setup(struct net_device *dev, bool init_ptp) | ||
3619 | if (priv->tso) | ||
3620 | priv->hw->dma->enable_tso(priv->ioaddr, 1, STMMAC_CHAN0); | ||
3621 | |||
3622 | + /* Start the ball rolling... */ | ||
3623 | + pr_debug("%s: DMA RX/TX processes started...\n", dev->name); | ||
3624 | + priv->hw->dma->start_tx(priv->ioaddr); | ||
3625 | + priv->hw->dma->start_rx(priv->ioaddr); | ||
3626 | + | ||
3627 | return 0; | ||
3628 | } | ||
3629 | |||
3630 | diff --git a/drivers/net/wireless/rsi/rsi_common.h b/drivers/net/wireless/rsi/rsi_common.h | ||
3631 | index d3fbe33d2324..a13f08fd8690 100644 | ||
3632 | --- a/drivers/net/wireless/rsi/rsi_common.h | ||
3633 | +++ b/drivers/net/wireless/rsi/rsi_common.h | ||
3634 | @@ -75,7 +75,6 @@ static inline int rsi_kill_thread(struct rsi_thread *handle) | ||
3635 | atomic_inc(&handle->thread_done); | ||
3636 | rsi_set_event(&handle->event); | ||
3637 | |||
3638 | - wait_for_completion(&handle->completion); | ||
3639 | return kthread_stop(handle->task); | ||
3640 | } | ||
3641 | |||
3642 | diff --git a/drivers/soc/tegra/pmc.c b/drivers/soc/tegra/pmc.c | ||
3643 | index 9685f9b8be07..a12710c917a1 100644 | ||
3644 | --- a/drivers/soc/tegra/pmc.c | ||
3645 | +++ b/drivers/soc/tegra/pmc.c | ||
3646 | @@ -512,16 +512,10 @@ EXPORT_SYMBOL(tegra_powergate_power_off); | ||
3647 | */ | ||
3648 | int tegra_powergate_is_powered(unsigned int id) | ||
3649 | { | ||
3650 | - int status; | ||
3651 | - | ||
3652 | if (!tegra_powergate_is_valid(id)) | ||
3653 | return -EINVAL; | ||
3654 | |||
3655 | - mutex_lock(&pmc->powergates_lock); | ||
3656 | - status = tegra_powergate_state(id); | ||
3657 | - mutex_unlock(&pmc->powergates_lock); | ||
3658 | - | ||
3659 | - return status; | ||
3660 | + return tegra_powergate_state(id); | ||
3661 | } | ||
3662 | |||
3663 | /** | ||
3664 | diff --git a/drivers/thermal/int340x_thermal/int3400_thermal.c b/drivers/thermal/int340x_thermal/int3400_thermal.c | ||
3665 | index 5836e5554433..d4c374cc4f74 100644 | ||
3666 | --- a/drivers/thermal/int340x_thermal/int3400_thermal.c | ||
3667 | +++ b/drivers/thermal/int340x_thermal/int3400_thermal.c | ||
3668 | @@ -20,6 +20,13 @@ enum int3400_thermal_uuid { | ||
3669 | INT3400_THERMAL_PASSIVE_1, | ||
3670 | INT3400_THERMAL_ACTIVE, | ||
3671 | INT3400_THERMAL_CRITICAL, | ||
3672 | + INT3400_THERMAL_ADAPTIVE_PERFORMANCE, | ||
3673 | + INT3400_THERMAL_EMERGENCY_CALL_MODE, | ||
3674 | + INT3400_THERMAL_PASSIVE_2, | ||
3675 | + INT3400_THERMAL_POWER_BOSS, | ||
3676 | + INT3400_THERMAL_VIRTUAL_SENSOR, | ||
3677 | + INT3400_THERMAL_COOLING_MODE, | ||
3678 | + INT3400_THERMAL_HARDWARE_DUTY_CYCLING, | ||
3679 | INT3400_THERMAL_MAXIMUM_UUID, | ||
3680 | }; | ||
3681 | |||
3682 | @@ -27,6 +34,13 @@ static u8 *int3400_thermal_uuids[INT3400_THERMAL_MAXIMUM_UUID] = { | ||
3683 | "42A441D6-AE6A-462b-A84B-4A8CE79027D3", | ||
3684 | "3A95C389-E4B8-4629-A526-C52C88626BAE", | ||
3685 | "97C68AE7-15FA-499c-B8C9-5DA81D606E0A", | ||
3686 | + "63BE270F-1C11-48FD-A6F7-3AF253FF3E2D", | ||
3687 | + "5349962F-71E6-431D-9AE8-0A635B710AEE", | ||
3688 | + "9E04115A-AE87-4D1C-9500-0F3E340BFE75", | ||
3689 | + "F5A35014-C209-46A4-993A-EB56DE7530A1", | ||
3690 | + "6ED722A7-9240-48A5-B479-31EEF723D7CF", | ||
3691 | + "16CAF1B7-DD38-40ED-B1C1-1B8A1913D531", | ||
3692 | + "BE84BABF-C4D4-403D-B495-3128FD44dAC1", | ||
3693 | }; | ||
3694 | |||
3695 | struct int3400_thermal_priv { | ||
3696 | @@ -271,10 +285,9 @@ static int int3400_thermal_probe(struct platform_device *pdev) | ||
3697 | |||
3698 | platform_set_drvdata(pdev, priv); | ||
3699 | |||
3700 | - if (priv->uuid_bitmap & 1 << INT3400_THERMAL_PASSIVE_1) { | ||
3701 | - int3400_thermal_ops.get_mode = int3400_thermal_get_mode; | ||
3702 | - int3400_thermal_ops.set_mode = int3400_thermal_set_mode; | ||
3703 | - } | ||
3704 | + int3400_thermal_ops.get_mode = int3400_thermal_get_mode; | ||
3705 | + int3400_thermal_ops.set_mode = int3400_thermal_set_mode; | ||
3706 | + | ||
3707 | priv->thermal = thermal_zone_device_register("INT3400 Thermal", 0, 0, | ||
3708 | priv, &int3400_thermal_ops, | ||
3709 | &int3400_thermal_params, 0, 0); | ||
3710 | diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx_uartps.c | ||
3711 | index ffb474c49f0f..eb61a07fcbbc 100644 | ||
3712 | --- a/drivers/tty/serial/xilinx_uartps.c | ||
3713 | +++ b/drivers/tty/serial/xilinx_uartps.c | ||
3714 | @@ -1261,7 +1261,7 @@ static void cdns_uart_console_write(struct console *co, const char *s, | ||
3715 | * | ||
3716 | * Return: 0 on success, negative errno otherwise. | ||
3717 | */ | ||
3718 | -static int __init cdns_uart_console_setup(struct console *co, char *options) | ||
3719 | +static int cdns_uart_console_setup(struct console *co, char *options) | ||
3720 | { | ||
3721 | struct uart_port *port = &cdns_uart_port[co->index]; | ||
3722 | int baud = 9600; | ||
3723 | diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c | ||
3724 | index 072e7599583a..a8ff43068619 100644 | ||
3725 | --- a/fs/9p/v9fs.c | ||
3726 | +++ b/fs/9p/v9fs.c | ||
3727 | @@ -59,6 +59,8 @@ enum { | ||
3728 | Opt_cache_loose, Opt_fscache, Opt_mmap, | ||
3729 | /* Access options */ | ||
3730 | Opt_access, Opt_posixacl, | ||
3731 | + /* Lock timeout option */ | ||
3732 | + Opt_locktimeout, | ||
3733 | /* Error token */ | ||
3734 | Opt_err | ||
3735 | }; | ||
3736 | @@ -78,6 +80,7 @@ static const match_table_t tokens = { | ||
3737 | {Opt_cachetag, "cachetag=%s"}, | ||
3738 | {Opt_access, "access=%s"}, | ||
3739 | {Opt_posixacl, "posixacl"}, | ||
3740 | + {Opt_locktimeout, "locktimeout=%u"}, | ||
3741 | {Opt_err, NULL} | ||
3742 | }; | ||
3743 | |||
3744 | @@ -126,6 +129,7 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts) | ||
3745 | #ifdef CONFIG_9P_FSCACHE | ||
3746 | v9ses->cachetag = NULL; | ||
3747 | #endif | ||
3748 | + v9ses->session_lock_timeout = P9_LOCK_TIMEOUT; | ||
3749 | |||
3750 | if (!opts) | ||
3751 | return 0; | ||
3752 | @@ -298,6 +302,23 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts) | ||
3753 | #endif | ||
3754 | break; | ||
3755 | |||
3756 | + case Opt_locktimeout: | ||
3757 | + r = match_int(&args[0], &option); | ||
3758 | + if (r < 0) { | ||
3759 | + p9_debug(P9_DEBUG_ERROR, | ||
3760 | + "integer field, but no integer?\n"); | ||
3761 | + ret = r; | ||
3762 | + continue; | ||
3763 | + } | ||
3764 | + if (option < 1) { | ||
3765 | + p9_debug(P9_DEBUG_ERROR, | ||
3766 | + "locktimeout must be a greater than zero integer.\n"); | ||
3767 | + ret = -EINVAL; | ||
3768 | + continue; | ||
3769 | + } | ||
3770 | + v9ses->session_lock_timeout = (long)option * HZ; | ||
3771 | + break; | ||
3772 | + | ||
3773 | default: | ||
3774 | continue; | ||
3775 | } | ||
3776 | diff --git a/fs/9p/v9fs.h b/fs/9p/v9fs.h | ||
3777 | index 443d12e02043..ce6ca9f4f683 100644 | ||
3778 | --- a/fs/9p/v9fs.h | ||
3779 | +++ b/fs/9p/v9fs.h | ||
3780 | @@ -116,6 +116,7 @@ struct v9fs_session_info { | ||
3781 | struct list_head slist; /* list of sessions registered with v9fs */ | ||
3782 | struct backing_dev_info bdi; | ||
3783 | struct rw_semaphore rename_sem; | ||
3784 | + long session_lock_timeout; /* retry interval for blocking locks */ | ||
3785 | }; | ||
3786 | |||
3787 | /* cache_validity flags */ | ||
3788 | diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c | ||
3789 | index 48db9a9f13f9..cb6c4031af55 100644 | ||
3790 | --- a/fs/9p/vfs_dir.c | ||
3791 | +++ b/fs/9p/vfs_dir.c | ||
3792 | @@ -105,7 +105,6 @@ static int v9fs_dir_readdir(struct file *file, struct dir_context *ctx) | ||
3793 | int err = 0; | ||
3794 | struct p9_fid *fid; | ||
3795 | int buflen; | ||
3796 | - int reclen = 0; | ||
3797 | struct p9_rdir *rdir; | ||
3798 | struct kvec kvec; | ||
3799 | |||
3800 | @@ -138,11 +137,10 @@ static int v9fs_dir_readdir(struct file *file, struct dir_context *ctx) | ||
3801 | while (rdir->head < rdir->tail) { | ||
3802 | err = p9stat_read(fid->clnt, rdir->buf + rdir->head, | ||
3803 | rdir->tail - rdir->head, &st); | ||
3804 | - if (err) { | ||
3805 | + if (err <= 0) { | ||
3806 | p9_debug(P9_DEBUG_VFS, "returned %d\n", err); | ||
3807 | return -EIO; | ||
3808 | } | ||
3809 | - reclen = st.size+2; | ||
3810 | |||
3811 | over = !dir_emit(ctx, st.name, strlen(st.name), | ||
3812 | v9fs_qid2ino(&st.qid), dt_type(&st)); | ||
3813 | @@ -150,8 +148,8 @@ static int v9fs_dir_readdir(struct file *file, struct dir_context *ctx) | ||
3814 | if (over) | ||
3815 | return 0; | ||
3816 | |||
3817 | - rdir->head += reclen; | ||
3818 | - ctx->pos += reclen; | ||
3819 | + rdir->head += err; | ||
3820 | + ctx->pos += err; | ||
3821 | } | ||
3822 | } | ||
3823 | } | ||
3824 | diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c | ||
3825 | index 2f035b15180e..79ff727254bb 100644 | ||
3826 | --- a/fs/9p/vfs_file.c | ||
3827 | +++ b/fs/9p/vfs_file.c | ||
3828 | @@ -154,6 +154,7 @@ static int v9fs_file_do_lock(struct file *filp, int cmd, struct file_lock *fl) | ||
3829 | uint8_t status = P9_LOCK_ERROR; | ||
3830 | int res = 0; | ||
3831 | unsigned char fl_type; | ||
3832 | + struct v9fs_session_info *v9ses; | ||
3833 | |||
3834 | fid = filp->private_data; | ||
3835 | BUG_ON(fid == NULL); | ||
3836 | @@ -189,6 +190,8 @@ static int v9fs_file_do_lock(struct file *filp, int cmd, struct file_lock *fl) | ||
3837 | if (IS_SETLKW(cmd)) | ||
3838 | flock.flags = P9_LOCK_FLAGS_BLOCK; | ||
3839 | |||
3840 | + v9ses = v9fs_inode2v9ses(file_inode(filp)); | ||
3841 | + | ||
3842 | /* | ||
3843 | * if its a blocked request and we get P9_LOCK_BLOCKED as the status | ||
3844 | * for lock request, keep on trying | ||
3845 | @@ -202,7 +205,8 @@ static int v9fs_file_do_lock(struct file *filp, int cmd, struct file_lock *fl) | ||
3846 | break; | ||
3847 | if (status == P9_LOCK_BLOCKED && !IS_SETLKW(cmd)) | ||
3848 | break; | ||
3849 | - if (schedule_timeout_interruptible(P9_LOCK_TIMEOUT) != 0) | ||
3850 | + if (schedule_timeout_interruptible(v9ses->session_lock_timeout) | ||
3851 | + != 0) | ||
3852 | break; | ||
3853 | /* | ||
3854 | * p9_client_lock_dotl overwrites flock.client_id with the | ||
3855 | diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c | ||
3856 | index 57c938ffeb6e..a8a2fc9ae056 100644 | ||
3857 | --- a/fs/cifs/inode.c | ||
3858 | +++ b/fs/cifs/inode.c | ||
3859 | @@ -771,43 +771,50 @@ cifs_get_inode_info(struct inode **inode, const char *full_path, | ||
3860 | } else if ((rc == -EACCES) && backup_cred(cifs_sb) && | ||
3861 | (strcmp(server->vals->version_string, SMB1_VERSION_STRING) | ||
3862 | == 0)) { | ||
3863 | - /* | ||
3864 | - * For SMB2 and later the backup intent flag is already | ||
3865 | - * sent if needed on open and there is no path based | ||
3866 | - * FindFirst operation to use to retry with | ||
3867 | - */ | ||
3868 | + /* | ||
3869 | + * For SMB2 and later the backup intent flag is already | ||
3870 | + * sent if needed on open and there is no path based | ||
3871 | + * FindFirst operation to use to retry with | ||
3872 | + */ | ||
3873 | |||
3874 | - srchinf = kzalloc(sizeof(struct cifs_search_info), | ||
3875 | - GFP_KERNEL); | ||
3876 | - if (srchinf == NULL) { | ||
3877 | - rc = -ENOMEM; | ||
3878 | - goto cgii_exit; | ||
3879 | - } | ||
3880 | + srchinf = kzalloc(sizeof(struct cifs_search_info), | ||
3881 | + GFP_KERNEL); | ||
3882 | + if (srchinf == NULL) { | ||
3883 | + rc = -ENOMEM; | ||
3884 | + goto cgii_exit; | ||
3885 | + } | ||
3886 | |||
3887 | - srchinf->endOfSearch = false; | ||
3888 | + srchinf->endOfSearch = false; | ||
3889 | + if (tcon->unix_ext) | ||
3890 | + srchinf->info_level = SMB_FIND_FILE_UNIX; | ||
3891 | + else if ((tcon->ses->capabilities & | ||
3892 | + tcon->ses->server->vals->cap_nt_find) == 0) | ||
3893 | + srchinf->info_level = SMB_FIND_FILE_INFO_STANDARD; | ||
3894 | + else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) | ||
3895 | srchinf->info_level = SMB_FIND_FILE_ID_FULL_DIR_INFO; | ||
3896 | + else /* no srvino useful for fallback to some netapp */ | ||
3897 | + srchinf->info_level = SMB_FIND_FILE_DIRECTORY_INFO; | ||
3898 | |||
3899 | - srchflgs = CIFS_SEARCH_CLOSE_ALWAYS | | ||
3900 | - CIFS_SEARCH_CLOSE_AT_END | | ||
3901 | - CIFS_SEARCH_BACKUP_SEARCH; | ||
3902 | + srchflgs = CIFS_SEARCH_CLOSE_ALWAYS | | ||
3903 | + CIFS_SEARCH_CLOSE_AT_END | | ||
3904 | + CIFS_SEARCH_BACKUP_SEARCH; | ||
3905 | |||
3906 | - rc = CIFSFindFirst(xid, tcon, full_path, | ||
3907 | - cifs_sb, NULL, srchflgs, srchinf, false); | ||
3908 | - if (!rc) { | ||
3909 | - data = | ||
3910 | - (FILE_ALL_INFO *)srchinf->srch_entries_start; | ||
3911 | + rc = CIFSFindFirst(xid, tcon, full_path, | ||
3912 | + cifs_sb, NULL, srchflgs, srchinf, false); | ||
3913 | + if (!rc) { | ||
3914 | + data = (FILE_ALL_INFO *)srchinf->srch_entries_start; | ||
3915 | |||
3916 | - cifs_dir_info_to_fattr(&fattr, | ||
3917 | - (FILE_DIRECTORY_INFO *)data, cifs_sb); | ||
3918 | - fattr.cf_uniqueid = le64_to_cpu( | ||
3919 | - ((SEARCH_ID_FULL_DIR_INFO *)data)->UniqueId); | ||
3920 | - validinum = true; | ||
3921 | + cifs_dir_info_to_fattr(&fattr, | ||
3922 | + (FILE_DIRECTORY_INFO *)data, cifs_sb); | ||
3923 | + fattr.cf_uniqueid = le64_to_cpu( | ||
3924 | + ((SEARCH_ID_FULL_DIR_INFO *)data)->UniqueId); | ||
3925 | + validinum = true; | ||
3926 | |||
3927 | - cifs_buf_release(srchinf->ntwrk_buf_start); | ||
3928 | - } | ||
3929 | - kfree(srchinf); | ||
3930 | - if (rc) | ||
3931 | - goto cgii_exit; | ||
3932 | + cifs_buf_release(srchinf->ntwrk_buf_start); | ||
3933 | + } | ||
3934 | + kfree(srchinf); | ||
3935 | + if (rc) | ||
3936 | + goto cgii_exit; | ||
3937 | } else | ||
3938 | goto cgii_exit; | ||
3939 | |||
3940 | diff --git a/fs/cifs/smb2maperror.c b/fs/cifs/smb2maperror.c | ||
3941 | index 98c25b969ab8..7e93d5706bf6 100644 | ||
3942 | --- a/fs/cifs/smb2maperror.c | ||
3943 | +++ b/fs/cifs/smb2maperror.c | ||
3944 | @@ -1034,7 +1034,8 @@ static const struct status_to_posix_error smb2_error_map_table[] = { | ||
3945 | {STATUS_UNFINISHED_CONTEXT_DELETED, -EIO, | ||
3946 | "STATUS_UNFINISHED_CONTEXT_DELETED"}, | ||
3947 | {STATUS_NO_TGT_REPLY, -EIO, "STATUS_NO_TGT_REPLY"}, | ||
3948 | - {STATUS_OBJECTID_NOT_FOUND, -EIO, "STATUS_OBJECTID_NOT_FOUND"}, | ||
3949 | + /* Note that ENOATTTR and ENODATA are the same errno */ | ||
3950 | + {STATUS_OBJECTID_NOT_FOUND, -ENODATA, "STATUS_OBJECTID_NOT_FOUND"}, | ||
3951 | {STATUS_NO_IP_ADDRESSES, -EIO, "STATUS_NO_IP_ADDRESSES"}, | ||
3952 | {STATUS_WRONG_CREDENTIAL_HANDLE, -EIO, | ||
3953 | "STATUS_WRONG_CREDENTIAL_HANDLE"}, | ||
3954 | diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c | ||
3955 | index 2880e017cd0a..2ce73287b53c 100644 | ||
3956 | --- a/fs/ext4/ioctl.c | ||
3957 | +++ b/fs/ext4/ioctl.c | ||
3958 | @@ -749,6 +749,13 @@ resizefs_out: | ||
3959 | if (!blk_queue_discard(q)) | ||
3960 | return -EOPNOTSUPP; | ||
3961 | |||
3962 | + /* | ||
3963 | + * We haven't replayed the journal, so we cannot use our | ||
3964 | + * block-bitmap-guided storage zapping commands. | ||
3965 | + */ | ||
3966 | + if (test_opt(sb, NOLOAD) && ext4_has_feature_journal(sb)) | ||
3967 | + return -EROFS; | ||
3968 | + | ||
3969 | if (copy_from_user(&range, (struct fstrim_range __user *)arg, | ||
3970 | sizeof(range))) | ||
3971 | return -EFAULT; | ||
3972 | diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c | ||
3973 | index 67b359629a66..aef2a24dc9f9 100644 | ||
3974 | --- a/fs/ext4/resize.c | ||
3975 | +++ b/fs/ext4/resize.c | ||
3976 | @@ -907,11 +907,18 @@ static int add_new_gdb_meta_bg(struct super_block *sb, | ||
3977 | memcpy(n_group_desc, o_group_desc, | ||
3978 | EXT4_SB(sb)->s_gdb_count * sizeof(struct buffer_head *)); | ||
3979 | n_group_desc[gdb_num] = gdb_bh; | ||
3980 | + | ||
3981 | + BUFFER_TRACE(gdb_bh, "get_write_access"); | ||
3982 | + err = ext4_journal_get_write_access(handle, gdb_bh); | ||
3983 | + if (err) { | ||
3984 | + kvfree(n_group_desc); | ||
3985 | + brelse(gdb_bh); | ||
3986 | + return err; | ||
3987 | + } | ||
3988 | + | ||
3989 | EXT4_SB(sb)->s_group_desc = n_group_desc; | ||
3990 | EXT4_SB(sb)->s_gdb_count++; | ||
3991 | kvfree(o_group_desc); | ||
3992 | - BUFFER_TRACE(gdb_bh, "get_write_access"); | ||
3993 | - err = ext4_journal_get_write_access(handle, gdb_bh); | ||
3994 | return err; | ||
3995 | } | ||
3996 | |||
3997 | @@ -2040,6 +2047,10 @@ out: | ||
3998 | free_flex_gd(flex_gd); | ||
3999 | if (resize_inode != NULL) | ||
4000 | iput(resize_inode); | ||
4001 | - ext4_msg(sb, KERN_INFO, "resized filesystem to %llu", n_blocks_count); | ||
4002 | + if (err) | ||
4003 | + ext4_warning(sb, "error (%d) occurred during " | ||
4004 | + "file system resize", err); | ||
4005 | + ext4_msg(sb, KERN_INFO, "resized filesystem to %llu", | ||
4006 | + ext4_blocks_count(es)); | ||
4007 | return err; | ||
4008 | } | ||
4009 | diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c | ||
4010 | index 83a96334dc07..4ebe69572475 100644 | ||
4011 | --- a/fs/f2fs/super.c | ||
4012 | +++ b/fs/f2fs/super.c | ||
4013 | @@ -1489,7 +1489,7 @@ int sanity_check_ckpt(struct f2fs_sb_info *sbi) | ||
4014 | unsigned int segment_count_main; | ||
4015 | unsigned int cp_pack_start_sum, cp_payload; | ||
4016 | block_t user_block_count; | ||
4017 | - int i; | ||
4018 | + int i, j; | ||
4019 | |||
4020 | total = le32_to_cpu(raw_super->segment_count); | ||
4021 | fsmeta = le32_to_cpu(raw_super->segment_count_ckpt); | ||
4022 | @@ -1530,11 +1530,43 @@ int sanity_check_ckpt(struct f2fs_sb_info *sbi) | ||
4023 | if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs || | ||
4024 | le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg) | ||
4025 | return 1; | ||
4026 | + for (j = i + 1; j < NR_CURSEG_NODE_TYPE; j++) { | ||
4027 | + if (le32_to_cpu(ckpt->cur_node_segno[i]) == | ||
4028 | + le32_to_cpu(ckpt->cur_node_segno[j])) { | ||
4029 | + f2fs_msg(sbi->sb, KERN_ERR, | ||
4030 | + "Node segment (%u, %u) has the same " | ||
4031 | + "segno: %u", i, j, | ||
4032 | + le32_to_cpu(ckpt->cur_node_segno[i])); | ||
4033 | + return 1; | ||
4034 | + } | ||
4035 | + } | ||
4036 | } | ||
4037 | for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) { | ||
4038 | if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs || | ||
4039 | le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg) | ||
4040 | return 1; | ||
4041 | + for (j = i + 1; j < NR_CURSEG_DATA_TYPE; j++) { | ||
4042 | + if (le32_to_cpu(ckpt->cur_data_segno[i]) == | ||
4043 | + le32_to_cpu(ckpt->cur_data_segno[j])) { | ||
4044 | + f2fs_msg(sbi->sb, KERN_ERR, | ||
4045 | + "Data segment (%u, %u) has the same " | ||
4046 | + "segno: %u", i, j, | ||
4047 | + le32_to_cpu(ckpt->cur_data_segno[i])); | ||
4048 | + return 1; | ||
4049 | + } | ||
4050 | + } | ||
4051 | + } | ||
4052 | + for (i = 0; i < NR_CURSEG_NODE_TYPE; i++) { | ||
4053 | + for (j = i; j < NR_CURSEG_DATA_TYPE; j++) { | ||
4054 | + if (le32_to_cpu(ckpt->cur_node_segno[i]) == | ||
4055 | + le32_to_cpu(ckpt->cur_data_segno[j])) { | ||
4056 | + f2fs_msg(sbi->sb, KERN_ERR, | ||
4057 | + "Data segment (%u) and Data segment (%u)" | ||
4058 | + " has the same segno: %u", i, j, | ||
4059 | + le32_to_cpu(ckpt->cur_node_segno[i])); | ||
4060 | + return 1; | ||
4061 | + } | ||
4062 | + } | ||
4063 | } | ||
4064 | |||
4065 | sit_bitmap_size = le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); | ||
4066 | diff --git a/include/linux/atalk.h b/include/linux/atalk.h | ||
4067 | index 73fd8b7e9534..af43ed404ff4 100644 | ||
4068 | --- a/include/linux/atalk.h | ||
4069 | +++ b/include/linux/atalk.h | ||
4070 | @@ -150,19 +150,29 @@ extern int sysctl_aarp_retransmit_limit; | ||
4071 | extern int sysctl_aarp_resolve_time; | ||
4072 | |||
4073 | #ifdef CONFIG_SYSCTL | ||
4074 | -extern void atalk_register_sysctl(void); | ||
4075 | +extern int atalk_register_sysctl(void); | ||
4076 | extern void atalk_unregister_sysctl(void); | ||
4077 | #else | ||
4078 | -#define atalk_register_sysctl() do { } while(0) | ||
4079 | -#define atalk_unregister_sysctl() do { } while(0) | ||
4080 | +static inline int atalk_register_sysctl(void) | ||
4081 | +{ | ||
4082 | + return 0; | ||
4083 | +} | ||
4084 | +static inline void atalk_unregister_sysctl(void) | ||
4085 | +{ | ||
4086 | +} | ||
4087 | #endif | ||
4088 | |||
4089 | #ifdef CONFIG_PROC_FS | ||
4090 | extern int atalk_proc_init(void); | ||
4091 | extern void atalk_proc_exit(void); | ||
4092 | #else | ||
4093 | -#define atalk_proc_init() ({ 0; }) | ||
4094 | -#define atalk_proc_exit() do { } while(0) | ||
4095 | +static inline int atalk_proc_init(void) | ||
4096 | +{ | ||
4097 | + return 0; | ||
4098 | +} | ||
4099 | +static inline void atalk_proc_exit(void) | ||
4100 | +{ | ||
4101 | +} | ||
4102 | #endif /* CONFIG_PROC_FS */ | ||
4103 | |||
4104 | #endif /* __LINUX_ATALK_H__ */ | ||
4105 | diff --git a/include/linux/swap.h b/include/linux/swap.h | ||
4106 | index 55ff5593c193..2228907d08ff 100644 | ||
4107 | --- a/include/linux/swap.h | ||
4108 | +++ b/include/linux/swap.h | ||
4109 | @@ -135,9 +135,9 @@ struct swap_extent { | ||
4110 | /* | ||
4111 | * Max bad pages in the new format.. | ||
4112 | */ | ||
4113 | -#define __swapoffset(x) ((unsigned long)&((union swap_header *)0)->x) | ||
4114 | #define MAX_SWAP_BADPAGES \ | ||
4115 | - ((__swapoffset(magic.magic) - __swapoffset(info.badpages)) / sizeof(int)) | ||
4116 | + ((offsetof(union swap_header, magic.magic) - \ | ||
4117 | + offsetof(union swap_header, info.badpages)) / sizeof(int)) | ||
4118 | |||
4119 | enum { | ||
4120 | SWP_USED = (1 << 0), /* is slot in swap_info[] used? */ | ||
4121 | diff --git a/kernel/events/core.c b/kernel/events/core.c | ||
4122 | index 5cbb2eda80b5..7929526e96e2 100644 | ||
4123 | --- a/kernel/events/core.c | ||
4124 | +++ b/kernel/events/core.c | ||
4125 | @@ -6616,6 +6616,7 @@ static void perf_event_mmap_output(struct perf_event *event, | ||
4126 | struct perf_output_handle handle; | ||
4127 | struct perf_sample_data sample; | ||
4128 | int size = mmap_event->event_id.header.size; | ||
4129 | + u32 type = mmap_event->event_id.header.type; | ||
4130 | int ret; | ||
4131 | |||
4132 | if (!perf_event_mmap_match(event, data)) | ||
4133 | @@ -6659,6 +6660,7 @@ static void perf_event_mmap_output(struct perf_event *event, | ||
4134 | perf_output_end(&handle); | ||
4135 | out: | ||
4136 | mmap_event->event_id.header.size = size; | ||
4137 | + mmap_event->event_id.header.type = type; | ||
4138 | } | ||
4139 | |||
4140 | static void perf_event_mmap_event(struct perf_mmap_event *mmap_event) | ||
4141 | diff --git a/kernel/hung_task.c b/kernel/hung_task.c | ||
4142 | index fd781a468f32..fb00cf30abd1 100644 | ||
4143 | --- a/kernel/hung_task.c | ||
4144 | +++ b/kernel/hung_task.c | ||
4145 | @@ -15,6 +15,7 @@ | ||
4146 | #include <linux/lockdep.h> | ||
4147 | #include <linux/export.h> | ||
4148 | #include <linux/sysctl.h> | ||
4149 | +#include <linux/suspend.h> | ||
4150 | #include <linux/utsname.h> | ||
4151 | #include <trace/events/sched.h> | ||
4152 | |||
4153 | @@ -221,6 +222,28 @@ void reset_hung_task_detector(void) | ||
4154 | } | ||
4155 | EXPORT_SYMBOL_GPL(reset_hung_task_detector); | ||
4156 | |||
4157 | +static bool hung_detector_suspended; | ||
4158 | + | ||
4159 | +static int hungtask_pm_notify(struct notifier_block *self, | ||
4160 | + unsigned long action, void *hcpu) | ||
4161 | +{ | ||
4162 | + switch (action) { | ||
4163 | + case PM_SUSPEND_PREPARE: | ||
4164 | + case PM_HIBERNATION_PREPARE: | ||
4165 | + case PM_RESTORE_PREPARE: | ||
4166 | + hung_detector_suspended = true; | ||
4167 | + break; | ||
4168 | + case PM_POST_SUSPEND: | ||
4169 | + case PM_POST_HIBERNATION: | ||
4170 | + case PM_POST_RESTORE: | ||
4171 | + hung_detector_suspended = false; | ||
4172 | + break; | ||
4173 | + default: | ||
4174 | + break; | ||
4175 | + } | ||
4176 | + return NOTIFY_OK; | ||
4177 | +} | ||
4178 | + | ||
4179 | /* | ||
4180 | * kthread which checks for tasks stuck in D state | ||
4181 | */ | ||
4182 | @@ -235,7 +258,8 @@ static int watchdog(void *dummy) | ||
4183 | long t = hung_timeout_jiffies(hung_last_checked, timeout); | ||
4184 | |||
4185 | if (t <= 0) { | ||
4186 | - if (!atomic_xchg(&reset_hung_task, 0)) | ||
4187 | + if (!atomic_xchg(&reset_hung_task, 0) && | ||
4188 | + !hung_detector_suspended) | ||
4189 | check_hung_uninterruptible_tasks(timeout); | ||
4190 | hung_last_checked = jiffies; | ||
4191 | continue; | ||
4192 | @@ -249,6 +273,10 @@ static int watchdog(void *dummy) | ||
4193 | static int __init hung_task_init(void) | ||
4194 | { | ||
4195 | atomic_notifier_chain_register(&panic_notifier_list, &panic_block); | ||
4196 | + | ||
4197 | + /* Disable hung task detector on suspend */ | ||
4198 | + pm_notifier(hungtask_pm_notify, 0); | ||
4199 | + | ||
4200 | watchdog_task = kthread_run(watchdog, NULL, "khungtaskd"); | ||
4201 | |||
4202 | return 0; | ||
4203 | diff --git a/lib/div64.c b/lib/div64.c | ||
4204 | index 7f345259c32f..c1c1a4c36dd5 100644 | ||
4205 | --- a/lib/div64.c | ||
4206 | +++ b/lib/div64.c | ||
4207 | @@ -102,7 +102,7 @@ u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder) | ||
4208 | quot = div_u64_rem(dividend, divisor, &rem32); | ||
4209 | *remainder = rem32; | ||
4210 | } else { | ||
4211 | - int n = 1 + fls(high); | ||
4212 | + int n = fls(high); | ||
4213 | quot = div_u64(dividend >> n, divisor >> n); | ||
4214 | |||
4215 | if (quot != 0) | ||
4216 | @@ -140,7 +140,7 @@ u64 div64_u64(u64 dividend, u64 divisor) | ||
4217 | if (high == 0) { | ||
4218 | quot = div_u64(dividend, divisor); | ||
4219 | } else { | ||
4220 | - int n = 1 + fls(high); | ||
4221 | + int n = fls(high); | ||
4222 | quot = div_u64(dividend >> n, divisor >> n); | ||
4223 | |||
4224 | if (quot != 0) | ||
4225 | diff --git a/net/9p/protocol.c b/net/9p/protocol.c | ||
4226 | index 145f80518064..7f1b45c082c9 100644 | ||
4227 | --- a/net/9p/protocol.c | ||
4228 | +++ b/net/9p/protocol.c | ||
4229 | @@ -570,9 +570,10 @@ int p9stat_read(struct p9_client *clnt, char *buf, int len, struct p9_wstat *st) | ||
4230 | if (ret) { | ||
4231 | p9_debug(P9_DEBUG_9P, "<<< p9stat_read failed: %d\n", ret); | ||
4232 | trace_9p_protocol_dump(clnt, &fake_pdu); | ||
4233 | + return ret; | ||
4234 | } | ||
4235 | |||
4236 | - return ret; | ||
4237 | + return fake_pdu.offset; | ||
4238 | } | ||
4239 | EXPORT_SYMBOL(p9stat_read); | ||
4240 | |||
4241 | diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c | ||
4242 | index af46bc49e1e9..b5f84f428aa6 100644 | ||
4243 | --- a/net/appletalk/atalk_proc.c | ||
4244 | +++ b/net/appletalk/atalk_proc.c | ||
4245 | @@ -293,7 +293,7 @@ out_interface: | ||
4246 | goto out; | ||
4247 | } | ||
4248 | |||
4249 | -void __exit atalk_proc_exit(void) | ||
4250 | +void atalk_proc_exit(void) | ||
4251 | { | ||
4252 | remove_proc_entry("interface", atalk_proc_dir); | ||
4253 | remove_proc_entry("route", atalk_proc_dir); | ||
4254 | diff --git a/net/appletalk/ddp.c b/net/appletalk/ddp.c | ||
4255 | index 10d2bdce686e..e206d98b3b82 100644 | ||
4256 | --- a/net/appletalk/ddp.c | ||
4257 | +++ b/net/appletalk/ddp.c | ||
4258 | @@ -1912,12 +1912,16 @@ static const char atalk_err_snap[] __initconst = | ||
4259 | /* Called by proto.c on kernel start up */ | ||
4260 | static int __init atalk_init(void) | ||
4261 | { | ||
4262 | - int rc = proto_register(&ddp_proto, 0); | ||
4263 | + int rc; | ||
4264 | |||
4265 | - if (rc != 0) | ||
4266 | + rc = proto_register(&ddp_proto, 0); | ||
4267 | + if (rc) | ||
4268 | goto out; | ||
4269 | |||
4270 | - (void)sock_register(&atalk_family_ops); | ||
4271 | + rc = sock_register(&atalk_family_ops); | ||
4272 | + if (rc) | ||
4273 | + goto out_proto; | ||
4274 | + | ||
4275 | ddp_dl = register_snap_client(ddp_snap_id, atalk_rcv); | ||
4276 | if (!ddp_dl) | ||
4277 | printk(atalk_err_snap); | ||
4278 | @@ -1925,12 +1929,33 @@ static int __init atalk_init(void) | ||
4279 | dev_add_pack(<alk_packet_type); | ||
4280 | dev_add_pack(&ppptalk_packet_type); | ||
4281 | |||
4282 | - register_netdevice_notifier(&ddp_notifier); | ||
4283 | + rc = register_netdevice_notifier(&ddp_notifier); | ||
4284 | + if (rc) | ||
4285 | + goto out_sock; | ||
4286 | + | ||
4287 | aarp_proto_init(); | ||
4288 | - atalk_proc_init(); | ||
4289 | - atalk_register_sysctl(); | ||
4290 | + rc = atalk_proc_init(); | ||
4291 | + if (rc) | ||
4292 | + goto out_aarp; | ||
4293 | + | ||
4294 | + rc = atalk_register_sysctl(); | ||
4295 | + if (rc) | ||
4296 | + goto out_proc; | ||
4297 | out: | ||
4298 | return rc; | ||
4299 | +out_proc: | ||
4300 | + atalk_proc_exit(); | ||
4301 | +out_aarp: | ||
4302 | + aarp_cleanup_module(); | ||
4303 | + unregister_netdevice_notifier(&ddp_notifier); | ||
4304 | +out_sock: | ||
4305 | + dev_remove_pack(&ppptalk_packet_type); | ||
4306 | + dev_remove_pack(<alk_packet_type); | ||
4307 | + unregister_snap_client(ddp_dl); | ||
4308 | + sock_unregister(PF_APPLETALK); | ||
4309 | +out_proto: | ||
4310 | + proto_unregister(&ddp_proto); | ||
4311 | + goto out; | ||
4312 | } | ||
4313 | module_init(atalk_init); | ||
4314 | |||
4315 | diff --git a/net/appletalk/sysctl_net_atalk.c b/net/appletalk/sysctl_net_atalk.c | ||
4316 | index ebb864361f7a..4e6042e0fcac 100644 | ||
4317 | --- a/net/appletalk/sysctl_net_atalk.c | ||
4318 | +++ b/net/appletalk/sysctl_net_atalk.c | ||
4319 | @@ -44,9 +44,12 @@ static struct ctl_table atalk_table[] = { | ||
4320 | |||
4321 | static struct ctl_table_header *atalk_table_header; | ||
4322 | |||
4323 | -void atalk_register_sysctl(void) | ||
4324 | +int __init atalk_register_sysctl(void) | ||
4325 | { | ||
4326 | atalk_table_header = register_net_sysctl(&init_net, "net/appletalk", atalk_table); | ||
4327 | + if (!atalk_table_header) | ||
4328 | + return -ENOMEM; | ||
4329 | + return 0; | ||
4330 | } | ||
4331 | |||
4332 | void atalk_unregister_sysctl(void) | ||
4333 | diff --git a/sound/drivers/opl3/opl3_voice.h b/sound/drivers/opl3/opl3_voice.h | ||
4334 | index a371c075ac87..e26702559f61 100644 | ||
4335 | --- a/sound/drivers/opl3/opl3_voice.h | ||
4336 | +++ b/sound/drivers/opl3/opl3_voice.h | ||
4337 | @@ -41,7 +41,7 @@ void snd_opl3_timer_func(unsigned long data); | ||
4338 | |||
4339 | /* Prototypes for opl3_drums.c */ | ||
4340 | void snd_opl3_load_drums(struct snd_opl3 *opl3); | ||
4341 | -void snd_opl3_drum_switch(struct snd_opl3 *opl3, int note, int on_off, int vel, struct snd_midi_channel *chan); | ||
4342 | +void snd_opl3_drum_switch(struct snd_opl3 *opl3, int note, int vel, int on_off, struct snd_midi_channel *chan); | ||
4343 | |||
4344 | /* Prototypes for opl3_oss.c */ | ||
4345 | #ifdef CONFIG_SND_SEQUENCER_OSS | ||
4346 | diff --git a/sound/isa/sb/sb8.c b/sound/isa/sb/sb8.c | ||
4347 | index ad42d2364199..e75bfc511e3e 100644 | ||
4348 | --- a/sound/isa/sb/sb8.c | ||
4349 | +++ b/sound/isa/sb/sb8.c | ||
4350 | @@ -111,6 +111,10 @@ static int snd_sb8_probe(struct device *pdev, unsigned int dev) | ||
4351 | |||
4352 | /* block the 0x388 port to avoid PnP conflicts */ | ||
4353 | acard->fm_res = request_region(0x388, 4, "SoundBlaster FM"); | ||
4354 | + if (!acard->fm_res) { | ||
4355 | + err = -EBUSY; | ||
4356 | + goto _err; | ||
4357 | + } | ||
4358 | |||
4359 | if (port[dev] != SNDRV_AUTO_PORT) { | ||
4360 | if ((err = snd_sbdsp_create(card, port[dev], irq[dev], | ||
4361 | diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c | ||
4362 | index 286f5e3686a3..d73ee11a32bd 100644 | ||
4363 | --- a/sound/pci/echoaudio/echoaudio.c | ||
4364 | +++ b/sound/pci/echoaudio/echoaudio.c | ||
4365 | @@ -1953,6 +1953,11 @@ static int snd_echo_create(struct snd_card *card, | ||
4366 | } | ||
4367 | chip->dsp_registers = (volatile u32 __iomem *) | ||
4368 | ioremap_nocache(chip->dsp_registers_phys, sz); | ||
4369 | + if (!chip->dsp_registers) { | ||
4370 | + dev_err(chip->card->dev, "ioremap failed\n"); | ||
4371 | + snd_echo_free(chip); | ||
4372 | + return -ENOMEM; | ||
4373 | + } | ||
4374 | |||
4375 | if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED, | ||
4376 | KBUILD_MODNAME, chip)) { | ||
4377 | diff --git a/tools/perf/Documentation/perf-config.txt b/tools/perf/Documentation/perf-config.txt | ||
4378 | index cb081ac59fd1..bd359a04cb94 100644 | ||
4379 | --- a/tools/perf/Documentation/perf-config.txt | ||
4380 | +++ b/tools/perf/Documentation/perf-config.txt | ||
4381 | @@ -112,7 +112,7 @@ Given a $HOME/.perfconfig like this: | ||
4382 | |||
4383 | [report] | ||
4384 | # Defaults | ||
4385 | - sort-order = comm,dso,symbol | ||
4386 | + sort_order = comm,dso,symbol | ||
4387 | percent-limit = 0 | ||
4388 | queue-size = 0 | ||
4389 | children = true | ||
4390 | diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c | ||
4391 | index e68c866ae798..cd2900ac473f 100644 | ||
4392 | --- a/tools/perf/builtin-top.c | ||
4393 | +++ b/tools/perf/builtin-top.c | ||
4394 | @@ -1323,8 +1323,9 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused) | ||
4395 | goto out_delete_evlist; | ||
4396 | |||
4397 | symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL); | ||
4398 | - if (symbol__init(NULL) < 0) | ||
4399 | - return -1; | ||
4400 | + status = symbol__init(NULL); | ||
4401 | + if (status < 0) | ||
4402 | + goto out_delete_evlist; | ||
4403 | |||
4404 | sort__setup_elide(stdout); | ||
4405 | |||
4406 | diff --git a/tools/perf/tests/evsel-tp-sched.c b/tools/perf/tests/evsel-tp-sched.c | ||
4407 | index ea772d41e472..b5d0be524655 100644 | ||
4408 | --- a/tools/perf/tests/evsel-tp-sched.c | ||
4409 | +++ b/tools/perf/tests/evsel-tp-sched.c | ||
4410 | @@ -84,5 +84,6 @@ int test__perf_evsel__tp_sched_test(int subtest __maybe_unused) | ||
4411 | if (perf_evsel__test_field(evsel, "target_cpu", 4, true)) | ||
4412 | ret = -1; | ||
4413 | |||
4414 | + perf_evsel__delete(evsel); | ||
4415 | return ret; | ||
4416 | } | ||
4417 | diff --git a/tools/perf/tests/openat-syscall-all-cpus.c b/tools/perf/tests/openat-syscall-all-cpus.c | ||
4418 | index c8d9592eb142..75d504e9eeaf 100644 | ||
4419 | --- a/tools/perf/tests/openat-syscall-all-cpus.c | ||
4420 | +++ b/tools/perf/tests/openat-syscall-all-cpus.c | ||
4421 | @@ -38,7 +38,7 @@ int test__openat_syscall_event_on_all_cpus(int subtest __maybe_unused) | ||
4422 | if (IS_ERR(evsel)) { | ||
4423 | tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "syscalls", "sys_enter_openat"); | ||
4424 | pr_debug("%s\n", errbuf); | ||
4425 | - goto out_thread_map_delete; | ||
4426 | + goto out_cpu_map_delete; | ||
4427 | } | ||
4428 | |||
4429 | if (perf_evsel__open(evsel, cpus, threads) < 0) { | ||
4430 | @@ -112,6 +112,8 @@ out_close_fd: | ||
4431 | perf_evsel__close_fd(evsel, 1, threads->nr); | ||
4432 | out_evsel_delete: | ||
4433 | perf_evsel__delete(evsel); | ||
4434 | +out_cpu_map_delete: | ||
4435 | + cpu_map__put(cpus); | ||
4436 | out_thread_map_delete: | ||
4437 | thread_map__put(threads); | ||
4438 | return err; | ||
4439 | diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c | ||
4440 | index 993ef2762508..32aab95e1459 100644 | ||
4441 | --- a/tools/perf/util/build-id.c | ||
4442 | +++ b/tools/perf/util/build-id.c | ||
4443 | @@ -176,6 +176,7 @@ char *build_id_cache__linkname(const char *sbuild_id, char *bf, size_t size) | ||
4444 | return bf; | ||
4445 | } | ||
4446 | |||
4447 | +/* The caller is responsible to free the returned buffer. */ | ||
4448 | char *build_id_cache__origname(const char *sbuild_id) | ||
4449 | { | ||
4450 | char *linkname; | ||
4451 | diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c | ||
4452 | index 18dae745034f..1d66f8eab9f9 100644 | ||
4453 | --- a/tools/perf/util/config.c | ||
4454 | +++ b/tools/perf/util/config.c | ||
4455 | @@ -595,11 +595,10 @@ static int collect_config(const char *var, const char *value, | ||
4456 | } | ||
4457 | |||
4458 | ret = set_value(item, value); | ||
4459 | - return ret; | ||
4460 | |||
4461 | out_free: | ||
4462 | free(key); | ||
4463 | - return -1; | ||
4464 | + return ret; | ||
4465 | } | ||
4466 | |||
4467 | static int perf_config_set__init(struct perf_config_set *set) | ||
4468 | diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c | ||
4469 | index f7128c2a6386..a62f79558146 100644 | ||
4470 | --- a/tools/perf/util/evsel.c | ||
4471 | +++ b/tools/perf/util/evsel.c | ||
4472 | @@ -1167,6 +1167,7 @@ void perf_evsel__exit(struct perf_evsel *evsel) | ||
4473 | { | ||
4474 | assert(list_empty(&evsel->node)); | ||
4475 | assert(evsel->evlist == NULL); | ||
4476 | + perf_evsel__free_counts(evsel); | ||
4477 | perf_evsel__free_fd(evsel); | ||
4478 | perf_evsel__free_id(evsel); | ||
4479 | perf_evsel__free_config_terms(evsel); | ||
4480 | diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c | ||
4481 | index ad613ea51434..82833ceba339 100644 | ||
4482 | --- a/tools/perf/util/hist.c | ||
4483 | +++ b/tools/perf/util/hist.c | ||
4484 | @@ -1027,8 +1027,10 @@ int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al, | ||
4485 | |||
4486 | err = sample__resolve_callchain(iter->sample, &callchain_cursor, &iter->parent, | ||
4487 | iter->evsel, al, max_stack_depth); | ||
4488 | - if (err) | ||
4489 | + if (err) { | ||
4490 | + map__put(alm); | ||
4491 | return err; | ||
4492 | + } | ||
4493 | |||
4494 | err = iter->ops->prepare_entry(iter, al); | ||
4495 | if (err) | ||
4496 | diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c | ||
4497 | index 14f111a10650..6193be6d7639 100644 | ||
4498 | --- a/tools/perf/util/parse-events.c | ||
4499 | +++ b/tools/perf/util/parse-events.c | ||
4500 | @@ -2104,6 +2104,7 @@ void print_sdt_events(const char *subsys_glob, const char *event_glob, | ||
4501 | printf(" %-50s [%s]\n", buf, "SDT event"); | ||
4502 | free(buf); | ||
4503 | } | ||
4504 | + free(path); | ||
4505 | } else | ||
4506 | printf(" %-50s [%s]\n", nd->s, "SDT event"); | ||
4507 | if (nd2) { | ||
4508 | diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c | ||
4509 | index 5ec2de8f49b4..b4c5d96e54c1 100644 | ||
4510 | --- a/tools/power/x86/turbostat/turbostat.c | ||
4511 | +++ b/tools/power/x86/turbostat/turbostat.c | ||
4512 | @@ -3691,6 +3691,9 @@ int fork_it(char **argv) | ||
4513 | signal(SIGQUIT, SIG_IGN); | ||
4514 | if (waitpid(child_pid, &status, 0) == -1) | ||
4515 | err(status, "waitpid"); | ||
4516 | + | ||
4517 | + if (WIFEXITED(status)) | ||
4518 | + status = WEXITSTATUS(status); | ||
4519 | } | ||
4520 | /* | ||
4521 | * n.b. fork_it() does not check for errors from for_all_cpus() |