]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - drivers/nfc/pn544/mei.c
NFC: mei_phy: Register event callback when enabling the device
[mirror_ubuntu-zesty-kernel.git] / drivers / nfc / pn544 / mei.c
1 /*
2 * HCI based Driver for NXP pn544 NFC Chip
3 *
4 * Copyright (C) 2013 Intel Corporation. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
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
17 * Free Software Foundation, Inc.,
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21 #include <linux/module.h>
22 #include <linux/mod_devicetable.h>
23 #include <linux/nfc.h>
24 #include <net/nfc/hci.h>
25 #include <net/nfc/llc.h>
26
27 #include "../mei_phy.h"
28 #include "pn544.h"
29
30 #define PN544_DRIVER_NAME "pn544"
31
32 static int pn544_mei_probe(struct mei_cl_device *device,
33 const struct mei_cl_device_id *id)
34 {
35 struct nfc_mei_phy *phy;
36 int r;
37
38 pr_info("Probing NFC pn544\n");
39
40 phy = nfc_mei_phy_alloc(device);
41 if (!phy) {
42 pr_err("Cannot allocate memory for pn544 mei phy.\n");
43 return -ENOMEM;
44 }
45
46 r = pn544_hci_probe(phy, &mei_phy_ops, LLC_NOP_NAME,
47 MEI_NFC_HEADER_SIZE, 0, MEI_NFC_MAX_HCI_PAYLOAD,
48 &phy->hdev);
49 if (r < 0) {
50 nfc_mei_phy_free(phy);
51
52 return r;
53 }
54
55 return 0;
56 }
57
58 static int pn544_mei_remove(struct mei_cl_device *device)
59 {
60 struct nfc_mei_phy *phy = mei_cl_get_drvdata(device);
61
62 pr_info("Removing pn544\n");
63
64 pn544_hci_remove(phy->hdev);
65
66 nfc_mei_phy_disable(phy);
67
68 nfc_mei_phy_free(phy);
69
70 return 0;
71 }
72
73 static struct mei_cl_device_id pn544_mei_tbl[] = {
74 { PN544_DRIVER_NAME },
75
76 /* required last entry */
77 { }
78 };
79 MODULE_DEVICE_TABLE(mei, pn544_mei_tbl);
80
81 static struct mei_cl_driver pn544_driver = {
82 .id_table = pn544_mei_tbl,
83 .name = PN544_DRIVER_NAME,
84
85 .probe = pn544_mei_probe,
86 .remove = pn544_mei_remove,
87 };
88
89 static int pn544_mei_init(void)
90 {
91 int r;
92
93 pr_debug(DRIVER_DESC ": %s\n", __func__);
94
95 r = mei_cl_driver_register(&pn544_driver);
96 if (r) {
97 pr_err(PN544_DRIVER_NAME ": driver registration failed\n");
98 return r;
99 }
100
101 return 0;
102 }
103
104 static void pn544_mei_exit(void)
105 {
106 mei_cl_driver_unregister(&pn544_driver);
107 }
108
109 module_init(pn544_mei_init);
110 module_exit(pn544_mei_exit);
111
112 MODULE_LICENSE("GPL");
113 MODULE_DESCRIPTION(DRIVER_DESC);