blob: 46d0eb24eef9e07878443a38af17ab10e27ed341 [file] [log] [blame]
Samuel Ortizbb03dce2013-04-16 00:14:35 +02001/*
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
Jeff Kirsher98b32de2013-12-06 08:56:16 -080016 * along with this program; if not, see <http://www.gnu.org/licenses/>.
Samuel Ortizbb03dce2013-04-16 00:14:35 +020017 */
18
19#include <linux/module.h>
20#include <linux/mod_devicetable.h>
21#include <linux/nfc.h>
22#include <net/nfc/hci.h>
23#include <net/nfc/llc.h>
24
25#include "../mei_phy.h"
26#include "pn544.h"
27
28#define PN544_DRIVER_NAME "pn544"
29
Tomas Winkler89391382015-09-10 10:18:04 +030030static int pn544_mei_probe(struct mei_cl_device *cldev,
Samuel Ortizbb03dce2013-04-16 00:14:35 +020031 const struct mei_cl_device_id *id)
32{
33 struct nfc_mei_phy *phy;
34 int r;
35
36 pr_info("Probing NFC pn544\n");
37
Tomas Winkler89391382015-09-10 10:18:04 +030038 phy = nfc_mei_phy_alloc(cldev);
Samuel Ortizbb03dce2013-04-16 00:14:35 +020039 if (!phy) {
40 pr_err("Cannot allocate memory for pn544 mei phy.\n");
41 return -ENOMEM;
42 }
43
Samuel Ortizbb03dce2013-04-16 00:14:35 +020044 r = pn544_hci_probe(phy, &mei_phy_ops, LLC_NOP_NAME,
45 MEI_NFC_HEADER_SIZE, 0, MEI_NFC_MAX_HCI_PAYLOAD,
Eric Lapuyade8bd7fc82013-07-19 14:58:39 +020046 NULL, &phy->hdev);
Samuel Ortiz73f3adb2013-04-30 23:48:50 +020047 if (r < 0) {
48 nfc_mei_phy_free(phy);
49
50 return r;
51 }
Samuel Ortizbb03dce2013-04-16 00:14:35 +020052
53 return 0;
Samuel Ortizbb03dce2013-04-16 00:14:35 +020054}
55
Tomas Winkler89391382015-09-10 10:18:04 +030056static int pn544_mei_remove(struct mei_cl_device *cldev)
Samuel Ortizbb03dce2013-04-16 00:14:35 +020057{
Tomas Winklerd49dc5e2015-09-10 10:18:05 +030058 struct nfc_mei_phy *phy = mei_cldev_get_drvdata(cldev);
Samuel Ortizbb03dce2013-04-16 00:14:35 +020059
60 pr_info("Removing pn544\n");
61
62 pn544_hci_remove(phy->hdev);
63
Samuel Ortizbb03dce2013-04-16 00:14:35 +020064 nfc_mei_phy_free(phy);
65
66 return 0;
67}
68
69static struct mei_cl_device_id pn544_mei_tbl[] = {
Tomas Winklerb26864c2015-09-10 10:18:01 +030070 { PN544_DRIVER_NAME, MEI_NFC_UUID, MEI_CL_VERSION_ANY},
Samuel Ortizbb03dce2013-04-16 00:14:35 +020071
72 /* required last entry */
73 { }
74};
75MODULE_DEVICE_TABLE(mei, pn544_mei_tbl);
76
77static struct mei_cl_driver pn544_driver = {
78 .id_table = pn544_mei_tbl,
79 .name = PN544_DRIVER_NAME,
80
81 .probe = pn544_mei_probe,
82 .remove = pn544_mei_remove,
83};
84
85static int pn544_mei_init(void)
86{
87 int r;
88
89 pr_debug(DRIVER_DESC ": %s\n", __func__);
90
Tomas Winklerd49dc5e2015-09-10 10:18:05 +030091 r = mei_cldev_driver_register(&pn544_driver);
Samuel Ortizbb03dce2013-04-16 00:14:35 +020092 if (r) {
93 pr_err(PN544_DRIVER_NAME ": driver registration failed\n");
94 return r;
95 }
96
97 return 0;
98}
99
100static void pn544_mei_exit(void)
101{
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300102 mei_cldev_driver_unregister(&pn544_driver);
Samuel Ortizbb03dce2013-04-16 00:14:35 +0200103}
104
105module_init(pn544_mei_init);
106module_exit(pn544_mei_exit);
107
108MODULE_LICENSE("GPL");
109MODULE_DESCRIPTION(DRIVER_DESC);