xref: /linux/drivers/nfc/microread/mei.c (revision 73f3adb9b91efac04e4e7f8379a85400fc57121e)
1e0af11faSSamuel Ortiz /*
2e0af11faSSamuel Ortiz  * HCI based Driver for Inside Secure microread NFC Chip
3e0af11faSSamuel Ortiz  *
4e0af11faSSamuel Ortiz  * Copyright (C) 2013  Intel Corporation. All rights reserved.
5e0af11faSSamuel Ortiz  *
6e0af11faSSamuel Ortiz  * This program is free software; you can redistribute it and/or modify it
7e0af11faSSamuel Ortiz  * under the terms and conditions of the GNU General Public License,
8e0af11faSSamuel Ortiz  * version 2, as published by the Free Software Foundation.
9e0af11faSSamuel Ortiz  *
10e0af11faSSamuel Ortiz  * This program is distributed in the hope that it will be useful,
11e0af11faSSamuel Ortiz  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12e0af11faSSamuel Ortiz  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13e0af11faSSamuel Ortiz  * GNU General Public License for more details.
14e0af11faSSamuel Ortiz  *
15e0af11faSSamuel Ortiz  * You should have received a copy of the GNU General Public License
16e0af11faSSamuel Ortiz  * along with this program; if not, write to the
17e0af11faSSamuel Ortiz  * Free Software Foundation, Inc.,
18e0af11faSSamuel Ortiz  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19e0af11faSSamuel Ortiz  */
20e0af11faSSamuel Ortiz 
21e0af11faSSamuel Ortiz #include <linux/module.h>
224912e2feSEric Lapuyade #include <linux/mod_devicetable.h>
23e0af11faSSamuel Ortiz #include <linux/nfc.h>
24e0af11faSSamuel Ortiz #include <net/nfc/hci.h>
25e0af11faSSamuel Ortiz #include <net/nfc/llc.h>
26e0af11faSSamuel Ortiz 
274912e2feSEric Lapuyade #include "../mei_phy.h"
28e0af11faSSamuel Ortiz #include "microread.h"
29e0af11faSSamuel Ortiz 
30e0af11faSSamuel Ortiz #define MICROREAD_DRIVER_NAME "microread"
31e0af11faSSamuel Ortiz 
329593b0b1SSamuel Ortiz static int microread_mei_probe(struct mei_cl_device *device,
339593b0b1SSamuel Ortiz 			       const struct mei_cl_device_id *id)
34e0af11faSSamuel Ortiz {
354912e2feSEric Lapuyade 	struct nfc_mei_phy *phy;
36e0af11faSSamuel Ortiz 	int r;
37e0af11faSSamuel Ortiz 
38e0af11faSSamuel Ortiz 	pr_info("Probing NFC microread\n");
39e0af11faSSamuel Ortiz 
404912e2feSEric Lapuyade 	phy = nfc_mei_phy_alloc(device);
41e0af11faSSamuel Ortiz 	if (!phy) {
42e0af11faSSamuel Ortiz 		pr_err("Cannot allocate memory for microread mei phy.\n");
43e0af11faSSamuel Ortiz 		return -ENOMEM;
44e0af11faSSamuel Ortiz 	}
45e0af11faSSamuel Ortiz 
46e0af11faSSamuel Ortiz 	r = microread_probe(phy, &mei_phy_ops, LLC_NOP_NAME,
47e0af11faSSamuel Ortiz 			    MEI_NFC_HEADER_SIZE, 0, MEI_NFC_MAX_HCI_PAYLOAD,
48e0af11faSSamuel Ortiz 			    &phy->hdev);
49*73f3adb9SSamuel Ortiz 	if (r < 0) {
504912e2feSEric Lapuyade 		nfc_mei_phy_free(phy);
51e0af11faSSamuel Ortiz 
52e0af11faSSamuel Ortiz 		return r;
53e0af11faSSamuel Ortiz 	}
54e0af11faSSamuel Ortiz 
55*73f3adb9SSamuel Ortiz 	return 0;
56*73f3adb9SSamuel Ortiz }
57*73f3adb9SSamuel Ortiz 
589593b0b1SSamuel Ortiz static int microread_mei_remove(struct mei_cl_device *device)
59e0af11faSSamuel Ortiz {
604912e2feSEric Lapuyade 	struct nfc_mei_phy *phy = mei_cl_get_drvdata(device);
61e0af11faSSamuel Ortiz 
62e0af11faSSamuel Ortiz 	pr_info("Removing microread\n");
63e0af11faSSamuel Ortiz 
64e0af11faSSamuel Ortiz 	microread_remove(phy->hdev);
65e0af11faSSamuel Ortiz 
664912e2feSEric Lapuyade 	nfc_mei_phy_disable(phy);
67e0af11faSSamuel Ortiz 
684912e2feSEric Lapuyade 	nfc_mei_phy_free(phy);
69e0af11faSSamuel Ortiz 
70e0af11faSSamuel Ortiz 	return 0;
71e0af11faSSamuel Ortiz }
72e0af11faSSamuel Ortiz 
739593b0b1SSamuel Ortiz static struct mei_cl_device_id microread_mei_tbl[] = {
749593b0b1SSamuel Ortiz 	{ MICROREAD_DRIVER_NAME },
75cd48d8baSSamuel Ortiz 
76cd48d8baSSamuel Ortiz 	/* required last entry */
77cd48d8baSSamuel Ortiz 	{ }
78cd48d8baSSamuel Ortiz };
79cd48d8baSSamuel Ortiz MODULE_DEVICE_TABLE(mei, microread_mei_tbl);
80cd48d8baSSamuel Ortiz 
819593b0b1SSamuel Ortiz static struct mei_cl_driver microread_driver = {
82cd48d8baSSamuel Ortiz 	.id_table = microread_mei_tbl,
83e0af11faSSamuel Ortiz 	.name = MICROREAD_DRIVER_NAME,
84e0af11faSSamuel Ortiz 
85e0af11faSSamuel Ortiz 	.probe = microread_mei_probe,
86e0af11faSSamuel Ortiz 	.remove = microread_mei_remove,
87e0af11faSSamuel Ortiz };
88e0af11faSSamuel Ortiz 
89e0af11faSSamuel Ortiz static int microread_mei_init(void)
90e0af11faSSamuel Ortiz {
91e0af11faSSamuel Ortiz 	int r;
92e0af11faSSamuel Ortiz 
93e0af11faSSamuel Ortiz 	pr_debug(DRIVER_DESC ": %s\n", __func__);
94e0af11faSSamuel Ortiz 
959593b0b1SSamuel Ortiz 	r = mei_cl_driver_register(&microread_driver);
96e0af11faSSamuel Ortiz 	if (r) {
97e0af11faSSamuel Ortiz 		pr_err(MICROREAD_DRIVER_NAME ": driver registration failed\n");
98e0af11faSSamuel Ortiz 		return r;
99e0af11faSSamuel Ortiz 	}
100e0af11faSSamuel Ortiz 
101e0af11faSSamuel Ortiz 	return 0;
102e0af11faSSamuel Ortiz }
103e0af11faSSamuel Ortiz 
104e0af11faSSamuel Ortiz static void microread_mei_exit(void)
105e0af11faSSamuel Ortiz {
1069593b0b1SSamuel Ortiz 	mei_cl_driver_unregister(&microread_driver);
107e0af11faSSamuel Ortiz }
108e0af11faSSamuel Ortiz 
109e0af11faSSamuel Ortiz module_init(microread_mei_init);
110e0af11faSSamuel Ortiz module_exit(microread_mei_exit);
111e0af11faSSamuel Ortiz 
112e0af11faSSamuel Ortiz MODULE_LICENSE("GPL");
113e0af11faSSamuel Ortiz MODULE_DESCRIPTION(DRIVER_DESC);
114