forked from NXPNFCLinux/nxp-pn5xx
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pn5xx_i2c.c
780 lines (673 loc) · 19 KB
/
pn5xx_i2c.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
/*
* Copyright (C) 2010 Trusted Logic S.A.
* modifications copyright (C) 2015 NXP B.V.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <linux/list.h>
#include <linux/i2c.h>
#include <linux/irq.h>
#include <linux/jiffies.h>
#include <linux/uaccess.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/platform_device.h>
#include <linux/gpio.h>
#include <linux/miscdevice.h>
#include <linux/spinlock.h>
#include "pn5xx_i2c.h"
#include <linux/of_gpio.h>
#include <linux/regulator/consumer.h>
#include <linux/of.h>
#define MAX_BUFFER_SIZE 512
#define MODE_OFF 0
#define MODE_RUN 1
#define MODE_FW 2
/* Only pn548, pn547 and pn544 are supported */
#define CHIP "pn544"
#define DRIVER_CARD "PN54x NFC"
#define DRIVER_DESC "NFC driver for PN54x Family"
#ifndef CONFIG_OF
#define CONFIG_OF
#endif
struct pn54x_dev {
wait_queue_head_t read_wq;
struct mutex read_mutex;
struct i2c_client *client;
struct miscdevice pn54x_device;
int ven_gpio;
int firm_gpio;
int irq_gpio;
int clkreq_gpio;
struct regulator *pvdd_reg;
struct regulator *vbat_reg;
struct regulator *pmuvcc_reg;
struct regulator *sevdd_reg;
bool irq_enabled;
spinlock_t irq_enabled_lock;
};
/**********************************************************
* Interrupt control and handler
**********************************************************/
static void pn54x_disable_irq(struct pn54x_dev *pn54x_dev)
{
unsigned long flags;
spin_lock_irqsave(&pn54x_dev->irq_enabled_lock, flags);
if (pn54x_dev->irq_enabled) {
disable_irq_nosync(pn54x_dev->client->irq);
pn54x_dev->irq_enabled = false;
}
spin_unlock_irqrestore(&pn54x_dev->irq_enabled_lock, flags);
}
static irqreturn_t pn54x_dev_irq_handler(int irq, void *dev_id)
{
struct pn54x_dev *pn54x_dev = dev_id;
pn54x_disable_irq(pn54x_dev);
/* Wake up waiting readers */
wake_up(&pn54x_dev->read_wq);
return IRQ_HANDLED;
}
/**********************************************************
* private functions
**********************************************************/
static int pn544_enable(struct pn54x_dev *dev, int mode)
{
int r;
/* turn on the regulators */
/* -- if the regulators were specified, they're required */
if(dev->pvdd_reg != NULL)
{
r = regulator_enable(dev->pvdd_reg);
if (r < 0){
pr_err("%s: not able to enable pvdd\n", __func__);
return r;
}
}
if(dev->vbat_reg != NULL)
{
r = regulator_enable(dev->vbat_reg);
if (r < 0){
pr_err("%s: not able to enable vbat\n", __func__);
goto enable_exit0;
}
}
if(dev->pmuvcc_reg != NULL)
{
r = regulator_enable(dev->pmuvcc_reg);
if (r < 0){
pr_err("%s: not able to enable pmuvcc\n", __func__);
goto enable_exit1;
}
}
if(dev->sevdd_reg != NULL)
{
r = regulator_enable(dev->sevdd_reg);
if (r < 0){
pr_err("%s: not able to enable sevdd\n", __func__);
goto enable_exit2;
}
}
if (MODE_RUN == mode) {
pr_info("%s power on\n", __func__);
if (gpio_is_valid(dev->firm_gpio))
gpio_set_value(dev->firm_gpio, 0);
gpio_set_value(dev->ven_gpio, 1);
msleep(100);
}
else if (MODE_FW == mode) {
/* power on with firmware download (requires hw reset)
*/
pr_info("%s power on with firmware\n", __func__);
gpio_set_value(dev->ven_gpio, 1);
msleep(20);
if (gpio_is_valid(dev->firm_gpio)) {
gpio_set_value(dev->firm_gpio, 1);
}
else {
pr_err("%s Unused Firm GPIO %d\n", __func__, mode);
return GPIO_UNUSED;
}
msleep(20);
gpio_set_value(dev->ven_gpio, 0);
msleep(100);
gpio_set_value(dev->ven_gpio, 1);
msleep(20);
}
else {
pr_err("%s bad arg %d\n", __func__, mode);
return -EINVAL;
}
return 0;
enable_exit2:
if(dev->pmuvcc_reg) regulator_disable(dev->pmuvcc_reg);
enable_exit1:
if(dev->vbat_reg) regulator_disable(dev->vbat_reg);
enable_exit0:
if(dev->pvdd_reg) regulator_disable(dev->pvdd_reg);
return r;
}
static void pn544_disable(struct pn54x_dev *dev)
{
/* power off */
pr_info("%s power off\n", __func__);
if (gpio_is_valid(dev->firm_gpio))
gpio_set_value(dev->firm_gpio, 0);
gpio_set_value(dev->ven_gpio, 0);
msleep(100);
if(dev->sevdd_reg) regulator_disable(dev->sevdd_reg);
if(dev->pmuvcc_reg) regulator_disable(dev->pmuvcc_reg);
if(dev->vbat_reg) regulator_disable(dev->vbat_reg);
if(dev->pvdd_reg) regulator_disable(dev->pvdd_reg);
}
/**********************************************************
* driver functions
**********************************************************/
static ssize_t pn54x_dev_read(struct file *filp, char __user *buf,
size_t count, loff_t *offset)
{
struct pn54x_dev *pn54x_dev = filp->private_data;
char tmp[MAX_BUFFER_SIZE];
int ret;
if (count > MAX_BUFFER_SIZE)
count = MAX_BUFFER_SIZE;
pr_debug("%s : reading %zu bytes.\n", __func__, count);
mutex_lock(&pn54x_dev->read_mutex);
if (!gpio_get_value(pn54x_dev->irq_gpio)) {
if (filp->f_flags & O_NONBLOCK) {
ret = -EAGAIN;
goto fail;
}
while (1) {
pn54x_dev->irq_enabled = true;
enable_irq(pn54x_dev->client->irq);
ret = wait_event_interruptible(
pn54x_dev->read_wq,
!pn54x_dev->irq_enabled);
pn54x_disable_irq(pn54x_dev);
if (ret)
goto fail;
if (gpio_get_value(pn54x_dev->irq_gpio))
break;
pr_warning("%s: spurious interrupt detected\n", __func__);
}
}
/* Read data */
ret = i2c_master_recv(pn54x_dev->client, tmp, count);
mutex_unlock(&pn54x_dev->read_mutex);
/* pn54x seems to be slow in handling I2C read requests
* so add 1ms delay after recv operation */
udelay(1000);
if (ret < 0) {
pr_err("%s: i2c_master_recv returned %d\n", __func__, ret);
return ret;
}
if (ret > count) {
pr_err("%s: received too many bytes from i2c (%d)\n",
__func__, ret);
return -EIO;
}
if (copy_to_user(buf, tmp, ret)) {
pr_warning("%s : failed to copy to user space\n", __func__);
return -EFAULT;
}
return ret;
fail:
mutex_unlock(&pn54x_dev->read_mutex);
return ret;
}
static ssize_t pn54x_dev_write(struct file *filp, const char __user *buf,
size_t count, loff_t *offset)
{
struct pn54x_dev *pn54x_dev;
char tmp[MAX_BUFFER_SIZE];
int ret;
pn54x_dev = filp->private_data;
if (count > MAX_BUFFER_SIZE)
count = MAX_BUFFER_SIZE;
if (copy_from_user(tmp, buf, count)) {
pr_err("%s : failed to copy from user space\n", __func__);
return -EFAULT;
}
pr_debug("%s : writing %zu bytes.\n", __func__, count);
/* Write data */
ret = i2c_master_send(pn54x_dev->client, tmp, count);
if (ret != count) {
pr_err("%s : i2c_master_send returned %d\n", __func__, ret);
ret = -EIO;
}
/* pn54x seems to be slow in handling I2C write requests
* so add 1ms delay after I2C send oparation */
udelay(1000);
return ret;
}
static int pn54x_dev_open(struct inode *inode, struct file *filp)
{
struct pn54x_dev *pn54x_dev = container_of(filp->private_data,
struct pn54x_dev,
pn54x_device);
filp->private_data = pn54x_dev;
pr_info("%s : %d,%d\n", __func__, imajor(inode), iminor(inode));
// pn544_enable(pn54x_dev, MODE_RUN);
return 0;
}
static int pn54x_dev_release(struct inode *inode, struct file *filp)
{
// struct pn54x_dev *pn54x_dev = container_of(filp->private_data,
// struct pn54x_dev,
// pn54x_device);
pr_info("%s : closing %d,%d\n", __func__, imajor(inode), iminor(inode));
// pn544_disable(pn54x_dev);
return 0;
}
static long pn54x_dev_ioctl(struct file *filp, unsigned int cmd,
unsigned long arg)
{
struct pn54x_dev *pn54x_dev = filp->private_data;
pr_info("%s, cmd=%d, arg=%lu\n", __func__, cmd, arg);
switch (cmd) {
case PN544_SET_PWR:
if (arg == 2) {
/* power on w/FW */
if (GPIO_UNUSED == pn544_enable(pn54x_dev, arg)) {
return GPIO_UNUSED;
}
} else if (arg == 1) {
/* power on */
pn544_enable(pn54x_dev, arg);
} else if (arg == 0) {
/* power off */
pn544_disable(pn54x_dev);
} else {
pr_err("%s bad SET_PWR arg %lu\n", __func__, arg);
return -EINVAL;
}
break;
case PN54X_CLK_REQ:
if(1 == arg){
if(gpio_is_valid(pn54x_dev->clkreq_gpio)){
gpio_set_value(pn54x_dev->clkreq_gpio, 1);
}
else {
pr_err("%s Unused Clkreq GPIO %lu\n", __func__, arg);
return GPIO_UNUSED;
}
}
else if(0 == arg) {
if(gpio_is_valid(pn54x_dev->clkreq_gpio)){
gpio_set_value(pn54x_dev->clkreq_gpio, 0);
}
else {
pr_err("%s Unused Clkreq GPIO %lu\n", __func__, arg);
return GPIO_UNUSED;
}
} else {
pr_err("%s bad CLK_REQ arg %lu\n", __func__, arg);
return -EINVAL;
}
break;
default:
pr_err("%s bad ioctl %u\n", __func__, cmd);
return -EINVAL;
}
return 0;
}
static const struct file_operations pn54x_dev_fops = {
.owner = THIS_MODULE,
.llseek = no_llseek,
.read = pn54x_dev_read,
.write = pn54x_dev_write,
.open = pn54x_dev_open,
.release = pn54x_dev_release,
.unlocked_ioctl = pn54x_dev_ioctl,
};
/*
* Handlers for alternative sources of platform_data
*/
#ifdef CONFIG_OF
/*
* Translate OpenFirmware node properties into platform_data
*/
static int pn54x_get_pdata(struct device *dev,
struct pn544_i2c_platform_data *pdata)
{
struct device_node *node;
u32 flags;
int val;
/* make sure there is actually a device tree node */
node = dev->of_node;
if (!node)
return -ENODEV;
memset(pdata, 0, sizeof(*pdata));
/* read the dev tree data */
/* ven pin - enable's power to the chip - REQUIRED */
val = of_get_named_gpio_flags(node, "enable-gpios", 0, &flags);
if (val >= 0) {
pdata->ven_gpio = val;
}
else {
dev_err(dev, "VEN GPIO error getting from OF node\n");
return val;
}
/* firm pin - controls firmware download - OPTIONAL */
val = of_get_named_gpio_flags(node, "firmware-gpios", 0, &flags);
if (val >= 0) {
pdata->firm_gpio = val;
}
else {
pdata->firm_gpio = GPIO_UNUSED;
dev_warn(dev, "FIRM GPIO <OPTIONAL> error getting from OF node\n");
}
/* irq pin - data available irq - REQUIRED */
val = of_get_named_gpio_flags(node, "interrupt-gpios", 0, &flags);
if (val >= 0) {
pdata->irq_gpio = val;
}
else {
dev_err(dev, "IRQ GPIO error getting from OF node\n");
return val;
}
/* clkreq pin - controls the clock to the PN547 - OPTIONAL */
val = of_get_named_gpio_flags(node, "nxp,pn54x-clkreq", 0, &flags);
if (val >= 0) {
pdata->clkreq_gpio = val;
}
else {
pdata->clkreq_gpio = GPIO_UNUSED;
dev_warn(dev, "CLKREQ GPIO <OPTIONAL> error getting from OF node\n");
}
/* handle the regulator lines - these are optional
* PVdd - pad Vdd (544, 547)
* Vbat - Battery (544, 547)
* PMUVcc - UICC Power (544, 547)
* SEVdd - SE Power (544)
*
* Will attempt to load a matching Regulator Resource for each
* If no resource is provided, then the input will not be controlled
* Example: if only PVdd is provided, it is the only one that will be
* turned on/off.
*/
pdata->pvdd_reg = regulator_get(dev, "nxp,pn54x-pvdd");
if(IS_ERR(pdata->pvdd_reg)) {
pr_err("%s: could not get nxp,pn54x-pvdd, rc=%ld\n", __func__, PTR_ERR(pdata->pvdd_reg));
pdata->pvdd_reg = NULL;
}
pdata->vbat_reg = regulator_get(dev, "nxp,pn54x-vbat");
if (IS_ERR(pdata->vbat_reg)) {
pr_err("%s: could not get nxp,pn54x-vbat, rc=%ld\n", __func__, PTR_ERR(pdata->vbat_reg));
pdata->vbat_reg = NULL;
}
pdata->pmuvcc_reg = regulator_get(dev, "nxp,pn54x-pmuvcc");
if (IS_ERR(pdata->pmuvcc_reg)) {
pr_err("%s: could not get nxp,pn54x-pmuvcc, rc=%ld\n", __func__, PTR_ERR(pdata->pmuvcc_reg));
pdata->pmuvcc_reg = NULL;
}
pdata->sevdd_reg = regulator_get(dev, "nxp,pn54x-sevdd");
if (IS_ERR(pdata->sevdd_reg)) {
pr_err("%s: could not get nxp,pn54x-sevdd, rc=%ld\n", __func__, PTR_ERR(pdata->sevdd_reg));
pdata->sevdd_reg = NULL;
}
return 0;
}
#else
static int pn54x_get_pdata(struct device *dev,
struct pn544_i2c_platform_data *pdata)
{
pdata = dev->platform_data;
return 0;
}
#endif
/*
* pn54x_probe
*/
#ifdef KERNEL_3_4_AND_OLDER
static int __devinit pn54x_probe(struct i2c_client *client,
const struct i2c_device_id *id)
#else
static int pn54x_probe(struct i2c_client *client,
const struct i2c_device_id *id)
#endif
{
int ret;
struct pn544_i2c_platform_data *pdata; // gpio values, from board file or DT
struct pn544_i2c_platform_data tmp_pdata;
struct pn54x_dev *pn54x_dev; // internal device specific data
pr_info("%s\n", __func__);
/* ---- retrieve the platform data ---- */
/* If the dev.platform_data is NULL, then */
/* attempt to read from the device tree */
if(!client->dev.platform_data)
{
ret = pn54x_get_pdata(&(client->dev), &tmp_pdata);
if(ret){
return ret;
}
pdata = &tmp_pdata;
}
else
{
pdata = client->dev.platform_data;
}
if (pdata == NULL) {
pr_err("%s : nfc probe fail\n", __func__);
return -ENODEV;
}
/* validate the the adapter has basic I2C functionality */
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
pr_err("%s : need I2C_FUNC_I2C\n", __func__);
return -ENODEV;
}
/* reserve the GPIO pins */
pr_info("%s: request irq_gpio %d\n", __func__, pdata->irq_gpio);
ret = gpio_request(pdata->irq_gpio, "nfc_int");
if (ret){
pr_err("%s :not able to get GPIO irq_gpio\n", __func__);
return -ENODEV;
}
ret = gpio_to_irq(pdata->irq_gpio);
if (ret < 0){
pr_err("%s :not able to map GPIO irq_gpio to an IRQ\n", __func__);
goto err_ven;
}
else{
client->irq = ret;
}
pr_info("%s: request ven_gpio %d\n", __func__, pdata->ven_gpio);
ret = gpio_request(pdata->ven_gpio, "nfc_ven");
if (ret){
pr_err("%s :not able to get GPIO ven_gpio\n", __func__);
goto err_ven;
}
if (gpio_is_valid(pdata->firm_gpio)) {
pr_info("%s: request firm_gpio %d\n", __func__, pdata->firm_gpio);
ret = gpio_request(pdata->firm_gpio, "nfc_firm");
if (ret){
pr_err("%s :not able to get GPIO firm_gpio\n", __func__);
goto err_firm;
}
}
if (gpio_is_valid(pdata->clkreq_gpio)) {
pr_info("%s: request clkreq_gpio %d\n", __func__, pdata->clkreq_gpio);
ret = gpio_request(pdata->clkreq_gpio, "nfc_clkreq");
if (ret){
pr_err("%s :not able to get GPIO clkreq_gpio\n", __func__);
goto err_clkreq;
}
}
/* allocate the pn54x driver information structure */
pn54x_dev = kzalloc(sizeof(*pn54x_dev), GFP_KERNEL);
if (pn54x_dev == NULL) {
dev_err(&client->dev, "failed to allocate memory for module data\n");
ret = -ENOMEM;
goto err_exit;
}
/* store the platform data in the driver info struct */
pn54x_dev->irq_gpio = pdata->irq_gpio;
pn54x_dev->ven_gpio = pdata->ven_gpio;
pn54x_dev->firm_gpio = pdata->firm_gpio;
pn54x_dev->clkreq_gpio = pdata->clkreq_gpio;
pn54x_dev->pvdd_reg = pdata->pvdd_reg;
pn54x_dev->vbat_reg = pdata->vbat_reg;
pn54x_dev->pmuvcc_reg = pdata->pmuvcc_reg;
pn54x_dev->sevdd_reg = pdata->sevdd_reg;
pn54x_dev->client = client;
/* finish configuring the I/O */
ret = gpio_direction_input(pn54x_dev->irq_gpio);
if (ret < 0) {
pr_err("%s :not able to set irq_gpio as input\n", __func__);
goto err_exit;
}
ret = gpio_direction_output(pn54x_dev->ven_gpio, 0);
if (ret < 0) {
pr_err("%s : not able to set ven_gpio as output\n", __func__);
goto err_exit;
}
if (gpio_is_valid(pn54x_dev->firm_gpio)) {
ret = gpio_direction_output(pn54x_dev->firm_gpio, 0);
if (ret < 0) {
pr_err("%s : not able to set firm_gpio as output\n",
__func__);
goto err_exit;
}
}
if (gpio_is_valid(pn54x_dev->clkreq_gpio)) {
ret = gpio_direction_output(pn54x_dev->clkreq_gpio, 0);
if (ret < 0) {
pr_err("%s : not able to set clkreq_gpio as output\n",
__func__);
goto err_exit;
}
}
/* init mutex and queues */
init_waitqueue_head(&pn54x_dev->read_wq);
mutex_init(&pn54x_dev->read_mutex);
spin_lock_init(&pn54x_dev->irq_enabled_lock);
/* register as a misc device - character based with one entry point */
pn54x_dev->pn54x_device.minor = MISC_DYNAMIC_MINOR;
pn54x_dev->pn54x_device.name = CHIP;
pn54x_dev->pn54x_device.fops = &pn54x_dev_fops;
ret = misc_register(&pn54x_dev->pn54x_device);
if (ret) {
pr_err("%s : misc_register failed\n", __FILE__);
goto err_misc_register;
}
/* request irq. the irq is set whenever the chip has data available
* for reading. it is cleared when all data has been read.
*/
pr_info("%s : requesting IRQ %d\n", __func__, client->irq);
pn54x_dev->irq_enabled = true;
ret = request_irq(client->irq, pn54x_dev_irq_handler,
IRQF_TRIGGER_HIGH, client->name, pn54x_dev);
if (ret) {
dev_err(&client->dev, "request_irq failed\n");
goto err_request_irq_failed;
}
pn54x_disable_irq(pn54x_dev);
i2c_set_clientdata(client, pn54x_dev);
return 0;
err_request_irq_failed:
misc_deregister(&pn54x_dev->pn54x_device);
err_misc_register:
err_exit:
if (gpio_is_valid(pdata->clkreq_gpio))
gpio_free(pdata->clkreq_gpio);
err_clkreq:
if (gpio_is_valid(pdata->firm_gpio))
gpio_free(pdata->firm_gpio);
err_firm:
gpio_free(pdata->ven_gpio);
err_ven:
gpio_free(pdata->irq_gpio);
return ret;
}
#ifdef KERNEL_3_4_AND_OLDER
static int __devexit pn54x_remove(struct i2c_client *client)
#else
static int pn54x_remove(struct i2c_client *client)
#endif
{
struct pn54x_dev *pn54x_dev;
pr_info("%s\n", __func__);
pn54x_dev = i2c_get_clientdata(client);
free_irq(client->irq, pn54x_dev);
misc_deregister(&pn54x_dev->pn54x_device);
mutex_destroy(&pn54x_dev->read_mutex);
gpio_free(pn54x_dev->irq_gpio);
gpio_free(pn54x_dev->ven_gpio);
if (gpio_is_valid(pn54x_dev->firm_gpio))
gpio_free(pn54x_dev->firm_gpio);
if (gpio_is_valid(pn54x_dev->clkreq_gpio))
gpio_free(pn54x_dev->clkreq_gpio);
regulator_put(pn54x_dev->pvdd_reg);
regulator_put(pn54x_dev->vbat_reg);
regulator_put(pn54x_dev->pmuvcc_reg);
regulator_put(pn54x_dev->sevdd_reg);
kfree(pn54x_dev);
return 0;
}
/*
*
*/
#ifdef CONFIG_OF
static struct of_device_id pn54x_dt_match[] = {
{ .compatible = "nxp,pn547", },
{ .compatible = "nxp,pn544", },
{},
};
MODULE_DEVICE_TABLE(of, pn54x_dt_match);
#endif
static const struct i2c_device_id pn54x_id[] = {
{ "pn547", 0 },
{ },
};
MODULE_DEVICE_TABLE(i2c, pn54x_id);
static struct i2c_driver pn54x_driver = {
.id_table = pn54x_id,
.probe = pn54x_probe,
#ifdef KERNEL_3_4_AND_OLDER
.remove = __devexit_p(pn54x_remove),
#else
.remove = pn54x_remove,
#endif
.driver = {
.owner = THIS_MODULE,
.name = "pn544",
.of_match_table = pn54x_dt_match,
},
};
/*
* module load/unload record keeping
*/
static int __init pn54x_dev_init(void)
{
pr_info("%s\n", __func__);
return i2c_add_driver(&pn54x_driver);
}
static void __exit pn54x_dev_exit(void)
{
pr_info("%s\n", __func__);
i2c_del_driver(&pn54x_driver);
}
module_init(pn54x_dev_init);
module_exit(pn54x_dev_exit);
MODULE_AUTHOR("Sylvain Fonteneau");
MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_LICENSE("GPL");