xref: /openbmc/linux/drivers/nfc/pn544/mei.c (revision 7ce05074)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (C) 2013  Intel Corporation. All rights reserved.
4  *
5  * HCI based Driver for NXP pn544 NFC Chip
6  */
7 
8 #include <linux/module.h>
9 #include <linux/mod_devicetable.h>
10 #include <linux/nfc.h>
11 #include <net/nfc/hci.h>
12 #include <net/nfc/llc.h>
13 
14 #include "../mei_phy.h"
15 #include "pn544.h"
16 
17 #define PN544_DRIVER_NAME "pn544"
18 
19 static int pn544_mei_probe(struct mei_cl_device *cldev,
20 			       const struct mei_cl_device_id *id)
21 {
22 	struct nfc_mei_phy *phy;
23 	int r;
24 
25 	pr_info("Probing NFC pn544\n");
26 
27 	phy = nfc_mei_phy_alloc(cldev);
28 	if (!phy) {
29 		pr_err("Cannot allocate memory for pn544 mei phy.\n");
30 		return -ENOMEM;
31 	}
32 
33 	r = pn544_hci_probe(phy, &mei_phy_ops, LLC_NOP_NAME,
34 			    MEI_NFC_HEADER_SIZE, 0, MEI_NFC_MAX_HCI_PAYLOAD,
35 			    NULL, &phy->hdev);
36 	if (r < 0) {
37 		nfc_mei_phy_free(phy);
38 
39 		return r;
40 	}
41 
42 	return 0;
43 }
44 
45 static void pn544_mei_remove(struct mei_cl_device *cldev)
46 {
47 	struct nfc_mei_phy *phy = mei_cldev_get_drvdata(cldev);
48 
49 	pr_info("Removing pn544\n");
50 
51 	pn544_hci_remove(phy->hdev);
52 
53 	nfc_mei_phy_free(phy);
54 }
55 
56 static struct mei_cl_device_id pn544_mei_tbl[] = {
57 	{ PN544_DRIVER_NAME, MEI_NFC_UUID, MEI_CL_VERSION_ANY},
58 
59 	/* required last entry */
60 	{ }
61 };
62 MODULE_DEVICE_TABLE(mei, pn544_mei_tbl);
63 
64 static struct mei_cl_driver pn544_driver = {
65 	.id_table = pn544_mei_tbl,
66 	.name = PN544_DRIVER_NAME,
67 
68 	.probe = pn544_mei_probe,
69 	.remove = pn544_mei_remove,
70 };
71 
72 module_mei_cl_driver(pn544_driver);
73 
74 MODULE_LICENSE("GPL");
75 MODULE_DESCRIPTION(DRIVER_DESC);
76