aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/touchscreen/rmi4/rmi_f01.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/touchscreen/rmi4/rmi_f01.c')
-rw-r--r--drivers/input/touchscreen/rmi4/rmi_f01.c775
1 files changed, 775 insertions, 0 deletions
diff --git a/drivers/input/touchscreen/rmi4/rmi_f01.c b/drivers/input/touchscreen/rmi4/rmi_f01.c
new file mode 100644
index 00000000000..ef9adb0586b
--- /dev/null
+++ b/drivers/input/touchscreen/rmi4/rmi_f01.c
@@ -0,0 +1,775 @@
1/*
2 * Copyright (c) 2011 Synaptics Incorporated
3 * Copyright (c) 2011 Unixphere
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20#define DEBUG
21
22#include <linux/kernel.h>
23#include <linux/rmi.h>
24#include <linux/slab.h>
25#include "rmi_driver.h"
26
27/* control register bits */
28#define RMI_SLEEP_MODE_NORMAL (0x00)
29#define RMI_SLEEP_MODE_SENSOR_SLEEP (0x01)
30#define RMI_SLEEP_MODE_RESERVED0 (0x02)
31#define RMI_SLEEP_MODE_RESERVED1 (0x03)
32
33#define RMI_IS_VALID_SLEEPMODE(mode) \
34 (mode >= RMI_SLEEP_MODE_NORMAL && mode <= RMI_SLEEP_MODE_RESERVED1)
35
36union f01_device_commands {
37 struct {
38 u8 reset:1;
39 u8 reserved:1;
40 };
41 u8 reg;
42};
43
44union f01_device_control {
45 struct {
46 u8 sleep_mode:2;
47 u8 nosleep:1;
48 u8 reserved:2;
49 u8 charger_input:1;
50 u8 report_rate:1;
51 u8 configured:1;
52 };
53 u8 reg;
54};
55
56union f01_device_status {
57 struct {
58 u8 status_code:4;
59 u8 reserved:2;
60 u8 flash_prog:1;
61 u8 unconfigured:1;
62 };
63 u8 reg;
64};
65
66union f01_basic_queries {
67 struct {
68 u8 manufacturer_id:8;
69
70 u8 custom_map:1;
71 u8 non_compliant:1;
72 u8 q1_bit_2:1;
73 u8 has_sensor_id:1;
74 u8 has_charger_input:1;
75 u8 has_adjustable_doze:1;
76 u8 has_adjustable_doze_holdoff:1;
77 u8 q1_bit_7:1;
78
79 u8 productinfo_1:7;
80 u8 q2_bit_7:1;
81 u8 productinfo_2:7;
82 u8 q3_bit_7:1;
83
84 u8 year:5;
85 u8 month:4;
86 u8 day:5;
87 u8 cp1:1;
88 u8 cp2:1;
89 u8 wafer_id1_lsb:8;
90 u8 wafer_id1_msb:8;
91 u8 wafer_id2_lsb:8;
92 u8 wafer_id2_msb:8;
93 u8 wafer_id3_lsb:8;
94 };
95 u8 regs[11];
96};
97
98struct f01_data {
99 union f01_device_control device_control;
100 union f01_basic_queries basic_queries;
101 union f01_device_status device_status;
102 u8 product_id[RMI_PRODUCT_ID_LENGTH+1];
103
104#ifdef CONFIG_PM
105 bool suspended;
106 bool old_nosleep;
107#endif
108};
109
110
111static ssize_t rmi_fn_01_productinfo_show(struct device *dev,
112 struct device_attribute *attr,
113 char *buf);
114
115static ssize_t rmi_fn_01_productid_show(struct device *dev,
116 struct device_attribute *attr,
117 char *buf);
118
119static ssize_t rmi_fn_01_manufacturer_show(struct device *dev,
120 struct device_attribute *attr,
121 char *buf);
122
123static ssize_t rmi_fn_01_datecode_show(struct device *dev,
124 struct device_attribute *attr,
125 char *buf);
126
127static ssize_t rmi_fn_01_reportrate_show(struct device *dev,
128 struct device_attribute *attr,
129 char *buf);
130
131static ssize_t rmi_fn_01_reportrate_store(struct device *dev,
132 struct device_attribute *attr,
133 const char *buf, size_t count);
134
135static ssize_t rmi_fn_01_reset_store(struct device *dev,
136 struct device_attribute *attr,
137 const char *buf, size_t count);
138
139static ssize_t rmi_fn_01_sleepmode_show(struct device *dev,
140 struct device_attribute *attr,
141 char *buf);
142
143static ssize_t rmi_fn_01_sleepmode_store(struct device *dev,
144 struct device_attribute *attr,
145 const char *buf, size_t count);
146
147static ssize_t rmi_fn_01_nosleep_show(struct device *dev,
148 struct device_attribute *attr,
149 char *buf);
150
151static ssize_t rmi_fn_01_nosleep_store(struct device *dev,
152 struct device_attribute *attr,
153 const char *buf, size_t count);
154
155static ssize_t rmi_fn_01_chargerinput_show(struct device *dev,
156 struct device_attribute *attr,
157 char *buf);
158
159static ssize_t rmi_fn_01_chargerinput_store(struct device *dev,
160 struct device_attribute *attr,
161 const char *buf, size_t count);
162
163static ssize_t rmi_fn_01_configured_show(struct device *dev,
164 struct device_attribute *attr,
165 char *buf);
166
167static ssize_t rmi_fn_01_unconfigured_show(struct device *dev,
168 struct device_attribute *attr,
169 char *buf);
170
171static ssize_t rmi_fn_01_flashprog_show(struct device *dev,
172 struct device_attribute *attr,
173 char *buf);
174
175static ssize_t rmi_fn_01_statuscode_show(struct device *dev,
176 struct device_attribute *attr,
177 char *buf);
178
179static struct device_attribute fn_01_attrs[] = {
180 __ATTR(productinfo, RMI_RO_ATTR,
181 rmi_fn_01_productinfo_show, rmi_store_error),
182 __ATTR(productid, RMI_RO_ATTR,
183 rmi_fn_01_productid_show, rmi_store_error),
184 __ATTR(manufacturer, RMI_RO_ATTR,
185 rmi_fn_01_manufacturer_show, rmi_store_error),
186 __ATTR(datecode, RMI_RO_ATTR,
187 rmi_fn_01_datecode_show, rmi_store_error),
188
189 /* control register access */
190 __ATTR(sleepmode, RMI_RW_ATTR,
191 rmi_fn_01_sleepmode_show, rmi_fn_01_sleepmode_store),
192 __ATTR(nosleep, RMI_RW_ATTR,
193 rmi_fn_01_nosleep_show, rmi_fn_01_nosleep_store),
194 __ATTR(chargerinput, RMI_RW_ATTR,
195 rmi_fn_01_chargerinput_show, rmi_fn_01_chargerinput_store),
196 __ATTR(reportrate, RMI_RW_ATTR,
197 rmi_fn_01_reportrate_show, rmi_fn_01_reportrate_store),
198 /* We make report rate RO, since the driver uses that to look for
199 * resets. We don't want someone faking us out by changing that
200 * bit.
201 */
202 __ATTR(configured, RMI_RO_ATTR,
203 rmi_fn_01_configured_show, rmi_store_error),
204
205 /* Command register access. */
206 __ATTR(reset, RMI_WO_ATTR,
207 rmi_show_error, rmi_fn_01_reset_store),
208
209 /* STatus register access. */
210 __ATTR(unconfigured, RMI_RO_ATTR,
211 rmi_fn_01_unconfigured_show, rmi_store_error),
212 __ATTR(flashprog, RMI_RO_ATTR,
213 rmi_fn_01_flashprog_show, rmi_store_error),
214 __ATTR(statuscode, RMI_RO_ATTR,
215 rmi_fn_01_statuscode_show, rmi_store_error),
216};
217
218/* Utility routine to set the value of a bit field in a register. */
219int rmi_set_bit_field(struct rmi_device *rmi_dev,
220 unsigned short address,
221 unsigned char field_mask,
222 unsigned char bits)
223{
224 unsigned char reg_contents;
225 int retval;
226
227 retval = rmi_read(rmi_dev, address, &reg_contents);
228 if (retval)
229 return retval;
230 reg_contents = (reg_contents & ~field_mask) | bits;
231 retval = rmi_write(rmi_dev, address, reg_contents);
232 if (retval == 1)
233 return 0;
234 else if (retval == 0)
235 return -EIO;
236 return retval;
237}
238
239static ssize_t rmi_fn_01_productinfo_show(struct device *dev,
240 struct device_attribute *attr,
241 char *buf)
242{
243 struct f01_data *data = NULL;
244 struct rmi_function_container *fc = to_rmi_function_container(dev);
245
246 data = fc->data;
247
248 return snprintf(buf, PAGE_SIZE, "0x%02x 0x%02x\n",
249 data->basic_queries.productinfo_1,
250 data->basic_queries.productinfo_2);
251}
252
253static ssize_t rmi_fn_01_productid_show(struct device *dev,
254 struct device_attribute *attr,
255 char *buf)
256{
257 struct f01_data *data = NULL;
258 struct rmi_function_container *fc = to_rmi_function_container(dev);
259
260 data = fc->data;
261
262 return snprintf(buf, PAGE_SIZE, "%s\n", data->product_id);
263}
264
265static ssize_t rmi_fn_01_manufacturer_show(struct device *dev,
266 struct device_attribute *attr,
267 char *buf)
268{
269 struct f01_data *data = NULL;
270 struct rmi_function_container *fc = to_rmi_function_container(dev);
271
272 data = fc->data;
273
274 return snprintf(buf, PAGE_SIZE, "0x%02x\n",
275 data->basic_queries.manufacturer_id);
276}
277
278static ssize_t rmi_fn_01_datecode_show(struct device *dev,
279 struct device_attribute *attr,
280 char *buf)
281{
282 struct f01_data *data = NULL;
283 struct rmi_function_container *fc = to_rmi_function_container(dev);
284
285 data = fc->data;
286
287 return snprintf(buf, PAGE_SIZE, "20%02u-%02u-%02u\n",
288 data->basic_queries.year,
289 data->basic_queries.month,
290 data->basic_queries.day);
291}
292
293static ssize_t rmi_fn_01_reset_store(struct device *dev,
294 struct device_attribute *attr,
295 const char *buf, size_t count)
296{
297 struct rmi_function_container *fc = NULL;
298 unsigned int reset;
299 int retval = 0;
300 /* Command register always reads as 0, so we can just use a local. */
301 union f01_device_commands commands = {};
302
303 fc = to_rmi_function_container(dev);
304
305 if (sscanf(buf, "%u", &reset) != 1)
306 return -EINVAL;
307 if (reset < 0 || reset > 1)
308 return -EINVAL;
309
310 /* Per spec, 0 has no effect, so we skip it entirely. */
311 if (reset) {
312 commands.reset = 1;
313 retval = rmi_write_block(fc->rmi_dev, fc->fd.command_base_addr,
314 &commands.reg, sizeof(commands.reg));
315 if (retval < 0) {
316 dev_err(dev, "%s: failed to issue reset command, "
317 "error = %d.", __func__, retval);
318 return retval;
319 }
320 }
321
322 return count;
323}
324
325static ssize_t rmi_fn_01_sleepmode_show(struct device *dev,
326 struct device_attribute *attr,
327 char *buf)
328{
329 struct f01_data *data = NULL;
330 struct rmi_function_container *fc = to_rmi_function_container(dev);
331
332 data = fc->data;
333
334 return snprintf(buf, PAGE_SIZE,
335 "%d\n", data->device_control.sleep_mode);
336}
337
338static ssize_t rmi_fn_01_sleepmode_store(struct device *dev,
339 struct device_attribute *attr,
340 const char *buf,
341 size_t count)
342{
343 struct f01_data *data = NULL;
344 unsigned long new_value;
345 int retval;
346 struct rmi_function_container *fc = to_rmi_function_container(dev);
347
348 data = fc->data;
349
350 retval = strict_strtoul(buf, 10, &new_value);
351 if (retval < 0 || !RMI_IS_VALID_SLEEPMODE(new_value)) {
352 dev_err(dev, "%s: Invalid sleep mode %s.", __func__, buf);
353 return -EINVAL;
354 }
355
356 dev_dbg(dev, "Setting sleep mode to %ld.", new_value);
357 data->device_control.sleep_mode = new_value;
358 retval = rmi_write_block(fc->rmi_dev, fc->fd.control_base_addr,
359 &data->device_control.reg,
360 sizeof(data->device_control.reg));
361 if (retval >= 0)
362 retval = count;
363 else
364 dev_err(dev, "Failed to write sleep mode, code %d.\n", retval);
365 return retval;
366}
367
368static ssize_t rmi_fn_01_nosleep_show(struct device *dev,
369 struct device_attribute *attr,
370 char *buf)
371{
372 struct f01_data *data = NULL;
373 struct rmi_function_container *fc = to_rmi_function_container(dev);
374
375 data = fc->data;
376
377 return snprintf(buf, PAGE_SIZE, "%d\n", data->device_control.nosleep);
378}
379
380static ssize_t rmi_fn_01_nosleep_store(struct device *dev,
381 struct device_attribute *attr,
382 const char *buf,
383 size_t count)
384{
385 struct f01_data *data = NULL;
386 unsigned long new_value;
387 int retval;
388 struct rmi_function_container *fc = to_rmi_function_container(dev);
389
390 data = fc->data;
391
392 retval = strict_strtoul(buf, 10, &new_value);
393 if (retval < 0 || new_value < 0 || new_value > 1) {
394 dev_err(dev, "%s: Invalid nosleep bit %s.", __func__, buf);
395 return -EINVAL;
396 }
397
398 data->device_control.nosleep = new_value;
399 retval = rmi_write_block(fc->rmi_dev, fc->fd.control_base_addr,
400 &data->device_control.reg,
401 sizeof(data->device_control.reg));
402 if (retval >= 0)
403 retval = count;
404 else
405 dev_err(dev, "Failed to write nosleep bit.\n");
406 return retval;
407}
408
409static ssize_t rmi_fn_01_chargerinput_show(struct device *dev,
410 struct device_attribute *attr,
411 char *buf)
412{
413 struct f01_data *data = NULL;
414 struct rmi_function_container *fc = to_rmi_function_container(dev);
415
416 data = fc->data;
417
418 return snprintf(buf, PAGE_SIZE, "%d\n",
419 data->device_control.charger_input);
420}
421
422static ssize_t rmi_fn_01_chargerinput_store(struct device *dev,
423 struct device_attribute *attr,
424 const char *buf,
425 size_t count)
426{
427 struct f01_data *data = NULL;
428 unsigned long new_value;
429 int retval;
430 struct rmi_function_container *fc = to_rmi_function_container(dev);
431
432 data = fc->data;
433
434 retval = strict_strtoul(buf, 10, &new_value);
435 if (retval < 0 || new_value < 0 || new_value > 1) {
436 dev_err(dev, "%s: Invalid chargerinput bit %s.", __func__, buf);
437 return -EINVAL;
438 }
439
440 data->device_control.charger_input = new_value;
441 retval = rmi_write_block(fc->rmi_dev, fc->fd.control_base_addr,
442 &data->device_control.reg,
443 sizeof(data->device_control.reg));
444 if (retval >= 0)
445 retval = count;
446 else
447 dev_err(dev, "Failed to write chargerinput bit.\n");
448 return retval;
449}
450
451static ssize_t rmi_fn_01_reportrate_show(struct device *dev,
452 struct device_attribute *attr,
453 char *buf)
454{
455 struct f01_data *data = NULL;
456 struct rmi_function_container *fc = to_rmi_function_container(dev);
457
458 data = fc->data;
459
460 return snprintf(buf, PAGE_SIZE, "%d\n",
461 data->device_control.report_rate);
462}
463
464static ssize_t rmi_fn_01_reportrate_store(struct device *dev,
465 struct device_attribute *attr,
466 const char *buf,
467 size_t count)
468{
469 struct f01_data *data = NULL;
470 unsigned long new_value;
471 int retval;
472 struct rmi_function_container *fc = to_rmi_function_container(dev);
473
474 data = fc->data;
475
476 retval = strict_strtoul(buf, 10, &new_value);
477 if (retval < 0 || new_value < 0 || new_value > 1) {
478 dev_err(dev, "%s: Invalid reportrate bit %s.", __func__, buf);
479 return -EINVAL;
480 }
481
482 data->device_control.report_rate = new_value;
483 retval = rmi_write_block(fc->rmi_dev, fc->fd.control_base_addr,
484 &data->device_control.reg,
485 sizeof(data->device_control.reg));
486 if (retval >= 0)
487 retval = count;
488 else
489 dev_err(dev, "Failed to write reportrate bit.\n");
490 return retval;
491}
492
493static ssize_t rmi_fn_01_configured_show(struct device *dev,
494 struct device_attribute *attr,
495 char *buf)
496{
497 struct f01_data *data = NULL;
498 struct rmi_function_container *fc = to_rmi_function_container(dev);
499
500 data = fc->data;
501
502 return snprintf(buf, PAGE_SIZE, "%d\n",
503 data->device_control.configured);
504}
505
506static ssize_t rmi_fn_01_unconfigured_show(struct device *dev,
507 struct device_attribute *attr,
508 char *buf)
509{
510 struct f01_data *data = NULL;
511 struct rmi_function_container *fc = to_rmi_function_container(dev);
512
513 data = fc->data;
514
515 return snprintf(buf, PAGE_SIZE, "%d\n",
516 data->device_status.unconfigured);
517}
518
519static ssize_t rmi_fn_01_flashprog_show(struct device *dev,
520 struct device_attribute *attr,
521 char *buf)
522{
523 struct f01_data *data = NULL;
524 struct rmi_function_container *fc = to_rmi_function_container(dev);
525
526 data = fc->data;
527
528 return snprintf(buf, PAGE_SIZE, "%d\n",
529 data->device_status.flash_prog);
530}
531
532static ssize_t rmi_fn_01_statuscode_show(struct device *dev,
533 struct device_attribute *attr,
534 char *buf)
535{
536 struct f01_data *data = NULL;
537 struct rmi_function_container *fc = to_rmi_function_container(dev);
538
539 data = fc->data;
540
541 return snprintf(buf, PAGE_SIZE, "0x%02x\n",
542 data->device_status.status_code);
543}
544
545int rmi_driver_f01_init(struct rmi_device *rmi_dev)
546{
547 struct rmi_driver_data *driver_data = rmi_get_driverdata(rmi_dev);
548 struct rmi_function_container *fc = driver_data->f01_container;
549 struct f01_data *data;
550 int error;
551 u8 temp;
552 int attr_count;
553
554 data = kzalloc(sizeof(struct f01_data), GFP_KERNEL);
555 if (!data) {
556 dev_err(&rmi_dev->dev, "Failed to allocate F01 data.\n");
557 return -ENOMEM;
558 }
559 fc->data = data;
560
561 /* Set the configured bit. */
562 error = rmi_read_block(rmi_dev, fc->fd.control_base_addr,
563 &data->device_control.reg,
564 sizeof(data->device_control.reg));
565 if (error < 0) {
566 dev_err(&fc->dev, "Failed to read F01 control.\n");
567 goto error_exit;
568 }
569
570 /* Sleep mode might be set as a hangover from a system crash or
571 * reboot without power cycle. If so, clear it so the sensor
572 * is certain to function.
573 */
574 if (data->device_control.sleep_mode != RMI_SLEEP_MODE_NORMAL) {
575 dev_warn(&fc->dev,
576 "WARNING: Non-zero sleep mode found. Clearing...\n");
577 data->device_control.sleep_mode = RMI_SLEEP_MODE_NORMAL;
578 }
579
580 data->device_control.configured = 1;
581 error = rmi_write_block(rmi_dev, fc->fd.control_base_addr,
582 &data->device_control.reg,
583 sizeof(data->device_control.reg));
584 if (error < 0) {
585 dev_err(&fc->dev, "Failed to write F01 control.\n");
586 goto error_exit;
587 }
588
589 /* dummy read in order to clear irqs */
590 error = rmi_read(rmi_dev, fc->fd.data_base_addr + 1, &temp);
591 if (error < 0) {
592 dev_err(&fc->dev, "Failed to read Interrupt Status.\n");
593 goto error_exit;
594 }
595
596 error = rmi_read_block(rmi_dev, fc->fd.query_base_addr,
597 data->basic_queries.regs,
598 sizeof(data->basic_queries.regs));
599 if (error < 0) {
600 dev_err(&fc->dev, "Failed to read device query registers.\n");
601 goto error_exit;
602 }
603 driver_data->manufacturer_id = data->basic_queries.manufacturer_id;
604
605 error = rmi_read_block(rmi_dev,
606 fc->fd.query_base_addr + sizeof(data->basic_queries.regs),
607 data->product_id, RMI_PRODUCT_ID_LENGTH);
608 if (error < 0) {
609 dev_err(&fc->dev, "Failed to read product ID.\n");
610 goto error_exit;
611 }
612 data->product_id[RMI_PRODUCT_ID_LENGTH] = '\0';
613 memcpy(driver_data->product_id, data->product_id,
614 sizeof(data->product_id));
615
616 error = rmi_read_block(rmi_dev, fc->fd.data_base_addr,
617 &data->device_status.reg,
618 sizeof(data->device_status.reg));
619 if (error < 0) {
620 dev_err(&fc->dev, "Failed to read device status.\n");
621 goto error_exit;
622 }
623 if (data->device_status.unconfigured) {
624 dev_err(&fc->dev,
625 "Device reset during configuration process, status: "
626 "%#02x!\n", data->device_status.status_code);
627 error = -EINVAL;
628 goto error_exit;
629 }
630 /*
631 ** attach the routines that handle sysfs interaction
632 ** Meaning: Set up sysfs device attributes.
633 */
634 for (attr_count = 0; attr_count < ARRAY_SIZE(fn_01_attrs);
635 attr_count++) {
636 if (sysfs_create_file(&fc->dev.kobj,
637 &fn_01_attrs[attr_count].attr) < 0) {
638 dev_err(&fc->dev, "Failed to create sysfs file for %s.",
639 fn_01_attrs[attr_count].attr.name);
640 error = -ENODEV;
641 goto error_exit;
642 }
643 }
644
645 return error;
646
647 error_exit:
648 kfree(data);
649 return error;
650}
651
652#ifdef CONFIG_PM
653
654static int rmi_f01_suspend(struct rmi_function_container *fc)
655{
656 struct rmi_device *rmi_dev = fc->rmi_dev;
657 struct rmi_driver_data *driver_data = rmi_get_driverdata(rmi_dev);
658 struct f01_data *data = driver_data->f01_container->data;
659 int retval = 0;
660
661 dev_dbg(&fc->dev, "Suspending...\n");
662 if (data->suspended)
663 return 0;
664
665 data->old_nosleep = data->device_control.nosleep;
666 data->device_control.nosleep = 0;
667 data->device_control.sleep_mode = RMI_SLEEP_MODE_SENSOR_SLEEP;
668
669 retval = rmi_write_block(rmi_dev,
670 driver_data->f01_container->fd.control_base_addr,
671 &data->device_control.reg,
672 sizeof(data->device_control.reg));
673 if (retval < 0) {
674 dev_err(&fc->dev, "Failed to write sleep mode. "
675 "Code: %d.\n", retval);
676 data->device_control.nosleep = data->old_nosleep;
677 data->device_control.sleep_mode = RMI_SLEEP_MODE_NORMAL;
678 } else {
679 data->suspended = true;
680 retval = 0;
681 }
682
683 return retval;
684}
685
686static int rmi_f01_resume(struct rmi_function_container *fc)
687{
688 struct rmi_device *rmi_dev = fc->rmi_dev;
689 struct rmi_driver_data *driver_data = rmi_get_driverdata(rmi_dev);
690 struct f01_data *data = driver_data->f01_container->data;
691 int retval = 0;
692
693 dev_dbg(&fc->dev, "Resuming...\n");
694 if (!data->suspended)
695 return 0;
696
697 data->device_control.nosleep = data->old_nosleep;
698 data->device_control.sleep_mode = RMI_SLEEP_MODE_NORMAL;
699
700 retval = rmi_write_block(rmi_dev,
701 driver_data->f01_container->fd.control_base_addr,
702 &data->device_control.reg,
703 sizeof(data->device_control.reg));
704 if (retval < 0)
705 dev_err(&fc->dev, "Failed to restore normal operation. "
706 "Code: %d.\n", retval);
707 else {
708 data->suspended = false;
709 retval = 0;
710 }
711
712 return retval;
713}
714#endif /* CONFIG_PM */
715
716static int rmi_f01_init(struct rmi_function_container *fc)
717{
718 return 0;
719}
720
721static int rmi_f01_attention(struct rmi_function_container *fc, u8 *irq_bits)
722{
723 struct rmi_device *rmi_dev = fc->rmi_dev;
724 struct f01_data *data = fc->data;
725 int error;
726
727 error = rmi_read_block(rmi_dev, fc->fd.data_base_addr,
728 &data->device_status.reg,
729 sizeof(data->device_status.reg));
730 if (error < 0) {
731 dev_err(&fc->dev, "Failed to read device status.\n");
732 return error;
733 }
734
735 /* TODO: Do we handle reset here or elsewhere? */
736 if (data->device_status.unconfigured)
737 dev_warn(&rmi_dev->dev, "Reset detected! Status code: %#04x.\n",
738 data->device_status.status_code);
739 return 0;
740}
741
742static struct rmi_function_handler function_handler = {
743 .func = 0x01,
744 .init = rmi_f01_init,
745 .attention = rmi_f01_attention,
746#ifdef CONFIG_PM
747 .suspend = rmi_f01_suspend,
748 .resume = rmi_f01_resume,
749#endif
750};
751
752static int __init rmi_f01_module_init(void)
753{
754 int error;
755
756 error = rmi_register_function_driver(&function_handler);
757 if (error < 0) {
758 pr_err("%s: register failed!\n", __func__);
759 return error;
760 }
761
762 return 0;
763}
764
765static void __exit rmi_f01_module_exit(void)
766{
767 rmi_unregister_function_driver(&function_handler);
768}
769
770module_init(rmi_f01_module_init);
771module_exit(rmi_f01_module_exit);
772
773MODULE_AUTHOR("Christopher Heiny <cheiny@synaptics.com>");
774MODULE_DESCRIPTION("RMI F01 module");
775MODULE_LICENSE("GPL");