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