aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/touchscreen/rmi4/rmi_f34.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/touchscreen/rmi4/rmi_f34.c')
-rw-r--r--drivers/input/touchscreen/rmi4/rmi_f34.c821
1 files changed, 821 insertions, 0 deletions
diff --git a/drivers/input/touchscreen/rmi4/rmi_f34.c b/drivers/input/touchscreen/rmi4/rmi_f34.c
new file mode 100644
index 00000000000..33e84d2cfb2
--- /dev/null
+++ b/drivers/input/touchscreen/rmi4/rmi_f34.c
@@ -0,0 +1,821 @@
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#include <linux/kernel.h>
20#include <linux/rmi.h>
21#include <linux/slab.h>
22#include <linux/version.h>
23#include "rmi_driver.h"
24
25/* define fn $34 commands */
26#define WRITE_FW_BLOCK 0x2
27#define ERASE_ALL 0x3
28#define READ_CONFIG_BLOCK 0x5
29#define WRITE_CONFIG_BLOCK 0x6
30#define ERASE_CONFIG 0x7
31#define ENABLE_FLASH_PROG 0xf
32
33#define STATUS_IN_PROGRESS 0xff
34#define STATUS_IDLE 0x80
35
36#define PDT_START_SCAN_LOCATION 0x00e9
37#define PDT_END_SCAN_LOCATION 0x0005
38
39#define BLK_SZ_OFF 3
40#define IMG_BLK_CNT_OFF 5
41#define CFG_BLK_CNT_OFF 7
42
43#define BLK_NUM_OFF 2
44
45#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32)
46#define KERNEL_VERSION_ABOVE_2_6_32 1
47#endif
48
49/* data specific to fn $34 that needs to be kept around */
50struct rmi_fn_34_data {
51 unsigned char status;
52 unsigned char cmd;
53 unsigned short bootloaderid;
54 unsigned short blocksize;
55 unsigned short imageblockcount;
56 unsigned short configblockcount;
57 unsigned short blocknum;
58 bool inflashprogmode;
59};
60
61static ssize_t rmi_fn_34_status_show(struct device *dev,
62 struct device_attribute *attr, char *buf);
63
64static ssize_t rmi_fn_34_cmd_show(struct device *dev,
65 struct device_attribute *attr, char *buf);
66
67static ssize_t rmi_fn_34_cmd_store(struct device *dev,
68 struct device_attribute *attr,
69 const char *buf, size_t count);
70
71#ifdef KERNEL_VERSION_ABOVE_2_6_32
72static ssize_t rmi_fn_34_data_read(struct file *data_file, struct kobject *kobj,
73 struct bin_attribute *attributes,
74 char *buf, loff_t pos, size_t count);
75
76static ssize_t rmi_fn_34_data_write(struct file *data_file,
77 struct kobject *kobj,
78 struct bin_attribute *attributes, char *buf,
79 loff_t pos, size_t count);
80#else
81static ssize_t rmi_fn_34_data_read(struct kobject *kobj,
82 struct bin_attribute *attributes,
83 char *buf, loff_t pos, size_t count);
84
85static ssize_t rmi_fn_34_data_write(struct kobject *kobj,
86 struct bin_attribute *attributes, char *buf,
87 loff_t pos, size_t count);
88#endif
89
90static ssize_t rmi_fn_34_bootloaderid_show(struct device *dev,
91 struct device_attribute *attr,
92 char *buf);
93
94static ssize_t rmi_fn_34_bootloaderid_store(struct device *dev,
95 struct device_attribute *attr,
96 const char *buf, size_t count);
97
98static ssize_t rmi_fn_34_blocksize_show(struct device *dev,
99 struct device_attribute *attr,
100 char *buf);
101
102static ssize_t rmi_fn_34_imageblockcount_show(struct device *dev,
103 struct device_attribute *attr,
104 char *buf);
105
106static ssize_t rmi_fn_34_configblockcount_show(struct device *dev,
107 struct device_attribute *attr,
108 char *buf);
109
110static ssize_t rmi_fn_34_blocknum_show(struct device *dev,
111 struct device_attribute *attr,
112 char *buf);
113
114static ssize_t rmi_fn_34_blocknum_store(struct device *dev,
115 struct device_attribute *attr,
116 const char *buf, size_t count);
117
118static ssize_t rmi_fn_34_rescanPDT_store(struct device *dev,
119 struct device_attribute *attr,
120 const char *buf, size_t count);
121
122static struct device_attribute attrs[] = {
123 __ATTR(status, RMI_RO_ATTR,
124 rmi_fn_34_status_show, rmi_store_error),
125 /* Also, sysfs will need to have a file set up to distinguish
126 * between commands - like Config write/read, Image write/verify. */
127 __ATTR(cmd, RMI_RW_ATTR,
128 rmi_fn_34_cmd_show, rmi_fn_34_cmd_store),
129 __ATTR(bootloaderid, RMI_RW_ATTR,
130 rmi_fn_34_bootloaderid_show, rmi_fn_34_bootloaderid_store),
131 __ATTR(blocksize, RMI_RO_ATTR,
132 rmi_fn_34_blocksize_show, rmi_store_error),
133 __ATTR(imageblockcount, RMI_RO_ATTR,
134 rmi_fn_34_imageblockcount_show, rmi_store_error),
135 __ATTR(configblockcount, RMI_RO_ATTR,
136 rmi_fn_34_configblockcount_show, rmi_store_error),
137 __ATTR(blocknum, RMI_RW_ATTR,
138 rmi_fn_34_blocknum_show, rmi_fn_34_blocknum_store),
139 __ATTR(rescanPDT, RMI_WO_ATTR,
140 rmi_show_error, rmi_fn_34_rescanPDT_store)
141};
142
143struct bin_attribute dev_attr_data = {
144 .attr = {
145 .name = "data",
146 .mode = 0666},
147 .size = 0,
148 .read = rmi_fn_34_data_read,
149 .write = rmi_fn_34_data_write,
150};
151
152static int rmi_f34_init(struct rmi_function_container *fc)
153{
154 int retval = 0;
155 int attr_count = 0;
156 struct rmi_fn_34_data *f34;
157 u16 query_base_addr;
158 u16 control_base_addr;
159 unsigned char buf[2];
160
161 dev_info(&fc->dev, "Intializing f34 values.");
162
163 /* init instance data, fill in values and create any sysfs files */
164 f34 = kzalloc(sizeof(struct rmi_fn_34_data), GFP_KERNEL);
165 if (!f34) {
166 dev_err(&fc->dev, "Failed to allocate rmi_fn_34_data.\n");
167 return -ENOMEM;
168 }
169
170 fc->data = f34;
171
172 /* get the Bootloader ID and Block Size. */
173 query_base_addr = fc->fd.query_base_addr;
174 control_base_addr = fc->fd.control_base_addr;
175
176 retval = rmi_read_block(fc->rmi_dev, query_base_addr, buf,
177 ARRAY_SIZE(buf));
178
179 if (retval < 0) {
180 dev_err(&fc->dev, "Could not read bootloaderid from 0x%04x.\n",
181 query_base_addr);
182 goto exit_free_data;
183 }
184 batohs(&f34->bootloaderid, buf);
185
186 retval = rmi_read_block(fc->rmi_dev, query_base_addr + BLK_SZ_OFF, buf,
187 ARRAY_SIZE(buf));
188
189 if (retval < 0) {
190 dev_err(&fc->dev, "Could not read block size from 0x%04x, "
191 "error=%d.\n", query_base_addr + BLK_SZ_OFF, retval);
192 goto exit_free_data;
193 }
194 batohs(&f34->blocksize, buf);
195
196 /* Get firmware image block count and store it in the instance data */
197 retval = rmi_read_block(fc->rmi_dev, query_base_addr + IMG_BLK_CNT_OFF,
198 buf, ARRAY_SIZE(buf));
199
200 if (retval < 0) {
201 dev_err(&fc->dev, "Couldn't read image block count from 0x%x, "
202 "error=%d.\n", query_base_addr + IMG_BLK_CNT_OFF,
203 retval);
204 goto exit_free_data;
205 }
206 batohs(&f34->imageblockcount, buf);
207
208 /* Get config block count and store it in the instance data */
209 retval = rmi_read_block(fc->rmi_dev, query_base_addr + 7, buf,
210 ARRAY_SIZE(buf));
211
212 if (retval < 0) {
213 dev_err(&fc->dev, "Couldn't read config block count from 0x%x, "
214 "error=%d.\n", query_base_addr + CFG_BLK_CNT_OFF,
215 retval);
216 goto exit_free_data;
217 }
218 batohs(&f34->configblockcount, buf);
219
220 /* We need a sysfs file for the image/config block to write or read.
221 * Set up sysfs bin file for binary data block. Since the image is
222 * already in our format there is no need to convert the data for
223 * endianess. */
224 retval = sysfs_create_bin_file(&fc->dev.kobj,
225 &dev_attr_data);
226 if (retval < 0) {
227 dev_err(&fc->dev, "Failed to create sysfs file for F34 data "
228 "(error = %d).\n", retval);
229 retval = -ENODEV;
230 goto exit_free_data;
231 }
232
233 dev_dbg(&fc->dev, "Creating sysfs files.\n");
234 for (attr_count = 0; attr_count < ARRAY_SIZE(attrs); attr_count++) {
235 if (sysfs_create_file
236 (&fc->dev.kobj, &attrs[attr_count].attr) < 0) {
237 dev_err(&fc->dev, "Failed to create sysfs file for %s.",
238 attrs[attr_count].attr.name);
239 retval = -ENODEV;
240 goto exit_free_attrs;
241 }
242 }
243
244 return retval;
245
246exit_free_attrs:
247 for (attr_count--; attr_count >= 0; attr_count--)
248 sysfs_remove_file(&fc->dev.kobj,
249 &attrs[attr_count].attr);
250exit_free_data:
251 kfree(f34);
252 return retval;
253}
254
255static int f34_read_status(struct rmi_function_container *fc)
256{
257 struct rmi_fn_34_data *instance_data = fc->data;
258 u16 data_base_addr = fc->fd.data_base_addr;
259 u8 status;
260 int retval;
261
262 /* Read the Fn $34 status from F34_Flash_Data3 to see the previous
263 * commands status. F34_Flash_Data3 will be the address after the
264 * 2 block number registers plus blocksize Data registers.
265 * inform user space - through a sysfs param. */
266 retval = rmi_read(fc->rmi_dev,
267 data_base_addr + instance_data->blocksize +
268 BLK_NUM_OFF, &status);
269
270 if (retval < 0) {
271 dev_err(&fc->dev, "Could not read status from 0x%x\n",
272 data_base_addr + instance_data->blocksize + BLK_NUM_OFF);
273 status = 0xff; /* failure */
274 }
275
276 /* set a sysfs value that the user mode can read - only
277 * upper 4 bits are the status. successful is $80, anything
278 * else is failure */
279 instance_data->status = status & 0xf0;
280
281 /* put mode into Flash Prog Mode when we successfully do
282 * an Enable Flash Prog cmd. */
283 if ((instance_data->status == STATUS_IDLE) &&
284 (instance_data->cmd == ENABLE_FLASH_PROG))
285 instance_data->inflashprogmode = true;
286
287 return retval;
288}
289
290int rmi_f34_attention(struct rmi_function_container *fc, u8 *irq_bits)
291{
292 return f34_read_status(fc);
293}
294
295static struct rmi_function_handler function_handler = {
296 .func = 0x34,
297 .init = rmi_f34_init,
298 .attention = rmi_f34_attention
299};
300
301static ssize_t rmi_fn_34_bootloaderid_show(struct device *dev,
302 struct device_attribute *attr,
303 char *buf)
304{
305 struct rmi_function_container *fc;
306 struct rmi_fn_34_data *instance_data;
307
308 fc = to_rmi_function_container(dev);
309 instance_data = fc->data;
310
311 return snprintf(buf, PAGE_SIZE, "%u\n", instance_data->bootloaderid);
312}
313
314static ssize_t rmi_fn_34_bootloaderid_store(struct device *dev,
315 struct device_attribute *attr,
316 const char *buf,
317 size_t count)
318{
319 int error;
320 unsigned long val;
321 unsigned char data[2];
322 struct rmi_function_container *fc;
323 struct rmi_fn_34_data *instance_data;
324 u16 data_base_addr;
325
326 fc = to_rmi_function_container(dev);
327 instance_data = fc->data;
328
329 /* need to convert the string data to an actual value */
330 error = strict_strtoul(buf, 10, &val);
331
332 if (error)
333 return error;
334
335 instance_data->bootloaderid = val;
336
337 /* Write the Bootloader ID key data back to the first two Block
338 * Data registers (F34_Flash_Data2.0 and F34_Flash_Data2.1). */
339 hstoba(data, (unsigned short)val);
340 data_base_addr = fc->fd.data_base_addr;
341
342 error = rmi_write_block(fc->rmi_dev,
343 data_base_addr + BLK_NUM_OFF,
344 data,
345 ARRAY_SIZE(data));
346
347 if (error < 0) {
348 dev_err(dev, "%s : Could not write bootloader id to 0x%x\n",
349 __func__, data_base_addr + BLK_NUM_OFF);
350 return error;
351 }
352
353 return count;
354}
355
356static ssize_t rmi_fn_34_blocksize_show(struct device *dev,
357 struct device_attribute *attr,
358 char *buf)
359{
360 struct rmi_function_container *fc;
361 struct rmi_fn_34_data *instance_data;
362
363 fc = to_rmi_function_container(dev);
364 instance_data = fc->data;
365
366 return snprintf(buf, PAGE_SIZE, "%u\n", instance_data->blocksize);
367}
368
369static ssize_t rmi_fn_34_imageblockcount_show(struct device *dev,
370 struct device_attribute *attr,
371 char *buf)
372{
373 struct rmi_function_container *fc;
374 struct rmi_fn_34_data *instance_data;
375
376 fc = to_rmi_function_container(dev);
377 instance_data = fc->data;
378
379 return snprintf(buf, PAGE_SIZE, "%u\n",
380 instance_data->imageblockcount);
381}
382
383static ssize_t rmi_fn_34_configblockcount_show(struct device *dev,
384 struct device_attribute *attr,
385 char *buf)
386{
387 struct rmi_function_container *fc;
388 struct rmi_fn_34_data *instance_data;
389
390 fc = to_rmi_function_container(dev);
391 instance_data = fc->data;
392
393 return snprintf(buf, PAGE_SIZE, "%u\n",
394 instance_data->configblockcount);
395}
396
397static ssize_t rmi_fn_34_status_show(struct device *dev,
398 struct device_attribute *attr,
399 char *buf)
400{
401 struct rmi_function_container *fc;
402 struct rmi_fn_34_data *instance_data;
403 int retval;
404
405 fc = to_rmi_function_container(dev);
406 instance_data = fc->data;
407
408 retval = f34_read_status(fc);
409
410 return snprintf(buf, PAGE_SIZE, "%u\n", instance_data->status);
411}
412
413static ssize_t rmi_fn_34_cmd_show(struct device *dev,
414 struct device_attribute *attr,
415 char *buf)
416{
417 struct rmi_function_container *fc;
418 struct rmi_fn_34_data *instance_data;
419
420 fc = to_rmi_function_container(dev);
421 instance_data = fc->data;
422
423 return snprintf(buf, PAGE_SIZE, "%u\n", instance_data->cmd);
424}
425
426static ssize_t rmi_fn_34_cmd_store(struct device *dev,
427 struct device_attribute *attr,
428 const char *buf,
429 size_t count)
430{
431 struct rmi_function_container *fc;
432 struct rmi_fn_34_data *instance_data;
433 unsigned long val;
434 u16 data_base_addr;
435 int error;
436
437 fc = to_rmi_function_container(dev);
438 instance_data = fc->data;
439 data_base_addr = fc->fd.data_base_addr;
440
441 /* need to convert the string data to an actual value */
442 error = strict_strtoul(buf, 10, &val);
443 if (error)
444 return error;
445
446 /* make sure we are in Flash Prog mode for all cmds except the
447 * Enable Flash Programming cmd - otherwise we are in error */
448 if ((val != ENABLE_FLASH_PROG) && !instance_data->inflashprogmode) {
449 dev_err(dev, "%s: CANNOT SEND CMD %d TO SENSOR - "
450 "NOT IN FLASH PROG MODE\n"
451 , __func__, data_base_addr);
452 return -EINVAL;
453 }
454
455 instance_data->cmd = val;
456
457 /* Validate command value and (if necessary) write it to the command
458 * register.
459 */
460 switch (instance_data->cmd) {
461 case ENABLE_FLASH_PROG:
462 case ERASE_ALL:
463 case ERASE_CONFIG:
464 case WRITE_FW_BLOCK:
465 case READ_CONFIG_BLOCK:
466 case WRITE_CONFIG_BLOCK:
467 /* Reset the status to indicate we are in progress on a cmd. */
468 /* The status will change when the ATTN interrupt happens
469 and the status of the cmd that was issued is read from
470 the F34_Flash_Data3 register - result should be 0x80 for
471 success - any other value indicates an error */
472
473 /* Issue the command to the device. */
474 error = rmi_write(fc->rmi_dev,
475 data_base_addr + instance_data->blocksize +
476 BLK_NUM_OFF, instance_data->cmd);
477
478 if (error < 0) {
479 dev_err(dev, "%s: Could not write command 0x%02x "
480 "to 0x%04x\n", __func__, instance_data->cmd,
481 data_base_addr + instance_data->blocksize +
482 BLK_NUM_OFF);
483 return error;
484 }
485
486 if (instance_data->cmd == ENABLE_FLASH_PROG)
487 instance_data->inflashprogmode = true;
488
489 /* set status to indicate we are in progress */
490 instance_data->status = STATUS_IN_PROGRESS;
491 break;
492 default:
493 dev_dbg(dev, "%s: RMI4 function $34 - "
494 "unknown command 0x%02lx.\n", __func__, val);
495 count = -EINVAL;
496 break;
497 }
498
499 return count;
500}
501
502static ssize_t rmi_fn_34_blocknum_show(struct device *dev,
503 struct device_attribute *attr,
504 char *buf)
505{
506 struct rmi_function_container *fc;
507 struct rmi_fn_34_data *instance_data;
508
509 fc = to_rmi_function_container(dev);
510 instance_data = fc->data;
511
512 return snprintf(buf, PAGE_SIZE, "%u\n", instance_data->blocknum);
513}
514
515static ssize_t rmi_fn_34_blocknum_store(struct device *dev,
516 struct device_attribute *attr,
517 const char *buf,
518 size_t count)
519{
520 int error;
521 unsigned long val;
522 unsigned char data[2];
523 struct rmi_function_container *fc;
524 struct rmi_fn_34_data *instance_data;
525 u16 data_base_addr;
526
527 fc = to_rmi_function_container(dev);
528 instance_data = fc->data;
529 data_base_addr = fc->fd.data_base_addr;
530
531 /* need to convert the string data to an actual value */
532 error = strict_strtoul(buf, 10, &val);
533
534 if (error)
535 return error;
536
537 instance_data->blocknum = val;
538
539 /* Write the Block Number data back to the first two Block
540 * Data registers (F34_Flash_Data_0 and F34_Flash_Data_1). */
541 hstoba(data, (unsigned short)val);
542
543 error = rmi_write_block(fc->rmi_dev,
544 data_base_addr,
545 data,
546 ARRAY_SIZE(data));
547
548 if (error < 0) {
549 dev_err(dev, "%s : Could not write block number %u to 0x%x\n",
550 __func__, instance_data->blocknum, data_base_addr);
551 return error;
552 }
553
554 return count;
555}
556
557static ssize_t rmi_fn_34_rescanPDT_store(struct device *dev,
558 struct device_attribute *attr,
559 const char *buf, size_t count)
560{
561 struct rmi_function_container *fc;
562 struct rmi_fn_34_data *instance_data;
563 struct rmi_device *rmi_dev;
564 struct rmi_driver_data *driver_data;
565 struct pdt_entry pdt_entry;
566 bool fn01found = false;
567 bool fn34found = false;
568 unsigned int rescan;
569 int irq_count = 0;
570 int retval = 0;
571 int i;
572
573 /* Rescan of the PDT is needed since issuing the Flash Enable cmd
574 * the device registers for Fn$01 and Fn$34 moving around because
575 * of the change from Bootloader mode to Flash Programming mode
576 * may change to a different PDT with only Fn$01 and Fn$34 that
577 * could have addresses for query, control, data, command registers
578 * that differ from the PDT scan done at device initialization. */
579
580 fc = to_rmi_function_container(dev);
581 instance_data = fc->data;
582 rmi_dev = fc->rmi_dev;
583 driver_data = rmi_get_driverdata(rmi_dev);
584
585 /* Make sure we are only in Flash Programming mode - DON'T
586 * ALLOW THIS IN UI MODE. */
587 if (instance_data->cmd != ENABLE_FLASH_PROG) {
588 dev_err(dev, "%s: NOT IN FLASH PROG MODE - CAN'T RESCAN PDT.\n"
589 , __func__);
590 return -EINVAL;
591 }
592
593 /* The only good value to write to this is 1, we allow 0, but with
594 * no effect (this is consistent with the way the command bit works. */
595 if (sscanf(buf, "%u", &rescan) != 1)
596 return -EINVAL;
597 if (rescan < 0 || rescan > 1)
598 return -EINVAL;
599
600 /* 0 has no effect, so we skip it entirely. */
601 if (rescan) {
602 /* rescan the PDT - filling in Fn01 and Fn34 addresses -
603 * this is only temporary - the device will need to be reset
604 * to return the PDT to the normal values. */
605
606 /* mini-parse the PDT - we only have to get Fn$01 and Fn$34 and
607 since we are Flash Programming mode we only have page 0. */
608 for (i = PDT_START_SCAN_LOCATION; i >= PDT_END_SCAN_LOCATION;
609 i -= sizeof(pdt_entry)) {
610 retval = rmi_read_block(rmi_dev, i, (u8 *)&pdt_entry,
611 sizeof(pdt_entry));
612 if (retval != sizeof(pdt_entry)) {
613 dev_err(dev, "%s: err frm rmi_read_block pdt "
614 "entry data from PDT, "
615 "error = %d.", __func__, retval);
616 return retval;
617 }
618
619 if ((pdt_entry.function_number == 0x00) ||
620 (pdt_entry.function_number == 0xff))
621 break;
622
623 dev_dbg(dev, "%s: Found F%.2X\n",
624 __func__, pdt_entry.function_number);
625
626 /* f01 found - just fill in the new addresses in
627 * the existing fc. */
628 if (pdt_entry.function_number == 0x01) {
629 struct rmi_function_container *f01_fc =
630 driver_data->f01_container;
631 fn01found = true;
632 f01_fc->fd.query_base_addr =
633 pdt_entry.query_base_addr;
634 f01_fc->fd.command_base_addr =
635 pdt_entry.command_base_addr;
636 f01_fc->fd.control_base_addr =
637 pdt_entry.control_base_addr;
638 f01_fc->fd.data_base_addr =
639 pdt_entry.data_base_addr;
640 f01_fc->fd.function_number =
641 pdt_entry.function_number;
642 f01_fc->fd.interrupt_source_count =
643 pdt_entry.interrupt_source_count;
644 f01_fc->num_of_irqs =
645 pdt_entry.interrupt_source_count;
646 f01_fc->irq_pos = irq_count;
647
648 irq_count += f01_fc->num_of_irqs;
649
650 if (fn34found)
651 break;
652 }
653
654 /* f34 found - just fill in the new addresses in
655 * the existing fc. */
656 if (pdt_entry.function_number == 0x34) {
657 fn34found = true;
658 fc->fd.query_base_addr =
659 pdt_entry.query_base_addr;
660 fc->fd.command_base_addr =
661 pdt_entry.command_base_addr;
662 fc->fd.control_base_addr =
663 pdt_entry.control_base_addr;
664 fc->fd.data_base_addr =
665 pdt_entry.data_base_addr;
666 fc->fd.function_number =
667 pdt_entry.function_number;
668 fc->fd.interrupt_source_count =
669 pdt_entry.interrupt_source_count;
670 fc->num_of_irqs =
671 pdt_entry.interrupt_source_count;
672 fc->irq_pos = irq_count;
673
674 irq_count += fc->num_of_irqs;
675
676 if (fn01found)
677 break;
678 }
679
680 }
681
682 if (!fn01found || !fn34found) {
683 dev_err(dev, "%s: failed to find fn$01 or fn$34 trying "
684 "to do rescan PDT.\n"
685 , __func__);
686 return -EINVAL;
687 }
688 }
689
690 return count;
691}
692
693#ifdef KERNEL_VERSION_ABOVE_2_6_32
694static ssize_t rmi_fn_34_data_read(struct file *data_file,
695 struct kobject *kobj,
696 struct bin_attribute *attributes,
697 char *buf,
698 loff_t pos,
699 size_t count)
700#else
701static ssize_t rmi_fn_34_data_read(struct kobject *kobj,
702 struct bin_attribute *attributes,
703 char *buf,
704 loff_t pos,
705 size_t count)
706#endif
707{
708 struct device *dev = container_of(kobj, struct device, kobj);
709 struct rmi_function_container *fc;
710 struct rmi_fn_34_data *instance_data;
711 u16 data_base_addr;
712 int error;
713
714 fc = to_rmi_function_container(dev);
715 instance_data = fc->data;
716
717 data_base_addr = fc->fd.data_base_addr;
718
719 if (count != instance_data->blocksize) {
720 dev_err(dev,
721 "%s : Incorrect F34 block size %d. "
722 "Expected size %d.\n",
723 __func__, count, instance_data->blocksize);
724 return -EINVAL;
725 }
726
727 /* Read the data from flash into buf. The app layer will be blocked
728 * at reading from the sysfs file. When we return the count (or
729 * error if we fail) the app will resume. */
730 error = rmi_read_block(fc->rmi_dev, data_base_addr + BLK_NUM_OFF,
731 (unsigned char *)buf, count);
732
733 if (error < 0) {
734 dev_err(dev, "%s : Could not read data from 0x%04x\n",
735 __func__, data_base_addr + BLK_NUM_OFF);
736 return error;
737 }
738
739 return count;
740}
741
742#ifdef KERNEL_VERSION_ABOVE_2_6_32
743static ssize_t rmi_fn_34_data_write(struct file *data_file,
744 struct kobject *kobj,
745 struct bin_attribute *attributes,
746 char *buf,
747 loff_t pos,
748 size_t count)
749#else
750static ssize_t rmi_fn_34_data_write(struct kobject *kobj,
751 struct bin_attribute *attributes,
752 char *buf,
753 loff_t pos,
754 size_t count)
755#endif
756{
757 struct device *dev = container_of(kobj, struct device, kobj);
758 struct rmi_function_container *fc;
759 struct rmi_fn_34_data *instance_data;
760 u16 data_base_addr;
761 int error;
762
763 fc = to_rmi_function_container(dev);
764 instance_data = fc->data;
765
766 data_base_addr = fc->fd.data_base_addr;
767
768 /* Write the data from buf to flash. The app layer will be
769 * blocked at writing to the sysfs file. When we return the
770 * count (or error if we fail) the app will resume. */
771
772 if (count != instance_data->blocksize) {
773 dev_err(dev,
774 "%s : Incorrect F34 block size %d. "
775 "Expected size %d.\n",
776 __func__, count, instance_data->blocksize);
777 return -EINVAL;
778 }
779
780 /* Write the data block - only if the count is non-zero */
781 if (count) {
782 error = rmi_write_block(fc->rmi_dev,
783 data_base_addr + BLK_NUM_OFF,
784 (unsigned char *)buf,
785 count);
786
787 if (error < 0) {
788 dev_err(dev, "%s : Could not write block data "
789 "to 0x%x\n", __func__,
790 data_base_addr + BLK_NUM_OFF);
791 return error;
792 }
793 }
794
795 return count;
796}
797
798static int __init rmi_f34_module_init(void)
799{
800 int error;
801
802 error = rmi_register_function_driver(&function_handler);
803 if (error < 0) {
804 pr_err("%s : register failed !\n", __func__);
805 return error;
806 }
807
808 return 0;
809}
810
811static void rmi_f34_module_exit(void)
812{
813 rmi_unregister_function_driver(&function_handler);
814}
815
816module_init(rmi_f34_module_init);
817module_exit(rmi_f34_module_exit);
818
819MODULE_AUTHOR("Eric Andersson <eric.andersson@unixphere.com>");
820MODULE_DESCRIPTION("RMI f34 module");
821MODULE_LICENSE("GPL");