xref: /linux/drivers/nfc/microread/mei.c (revision 17936b43f0fdede23582d83a45622751409c99b9)
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 
21*17936b43SJoe Perches #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22*17936b43SJoe Perches 
23e0af11faSSamuel Ortiz #include <linux/module.h>
244912e2feSEric Lapuyade #include <linux/mod_devicetable.h>
25e0af11faSSamuel Ortiz #include <linux/nfc.h>
26e0af11faSSamuel Ortiz #include <net/nfc/hci.h>
27e0af11faSSamuel Ortiz #include <net/nfc/llc.h>
28e0af11faSSamuel Ortiz 
294912e2feSEric Lapuyade #include "../mei_phy.h"
30e0af11faSSamuel Ortiz #include "microread.h"
31e0af11faSSamuel Ortiz 
32e0af11faSSamuel Ortiz #define MICROREAD_DRIVER_NAME "microread"
33e0af11faSSamuel Ortiz 
349593b0b1SSamuel Ortiz static int microread_mei_probe(struct mei_cl_device *device,
359593b0b1SSamuel Ortiz 			       const struct mei_cl_device_id *id)
36e0af11faSSamuel Ortiz {
374912e2feSEric Lapuyade 	struct nfc_mei_phy *phy;
38e0af11faSSamuel Ortiz 	int r;
39e0af11faSSamuel Ortiz 
40e0af11faSSamuel Ortiz 	pr_info("Probing NFC microread\n");
41e0af11faSSamuel Ortiz 
424912e2feSEric Lapuyade 	phy = nfc_mei_phy_alloc(device);
43e0af11faSSamuel Ortiz 	if (!phy) {
44e0af11faSSamuel Ortiz 		pr_err("Cannot allocate memory for microread mei phy.\n");
45e0af11faSSamuel Ortiz 		return -ENOMEM;
46e0af11faSSamuel Ortiz 	}
47e0af11faSSamuel Ortiz 
48e0af11faSSamuel Ortiz 	r = microread_probe(phy, &mei_phy_ops, LLC_NOP_NAME,
49e0af11faSSamuel Ortiz 			    MEI_NFC_HEADER_SIZE, 0, MEI_NFC_MAX_HCI_PAYLOAD,
50e0af11faSSamuel Ortiz 			    &phy->hdev);
5173f3adb9SSamuel Ortiz 	if (r < 0) {
524912e2feSEric Lapuyade 		nfc_mei_phy_free(phy);
53e0af11faSSamuel Ortiz 
54e0af11faSSamuel Ortiz 		return r;
55e0af11faSSamuel Ortiz 	}
56e0af11faSSamuel Ortiz 
5773f3adb9SSamuel Ortiz 	return 0;
5873f3adb9SSamuel Ortiz }
5973f3adb9SSamuel Ortiz 
609593b0b1SSamuel Ortiz static int microread_mei_remove(struct mei_cl_device *device)
61e0af11faSSamuel Ortiz {
624912e2feSEric Lapuyade 	struct nfc_mei_phy *phy = mei_cl_get_drvdata(device);
63e0af11faSSamuel Ortiz 
64e0af11faSSamuel Ortiz 	microread_remove(phy->hdev);
65e0af11faSSamuel Ortiz 
664912e2feSEric Lapuyade 	nfc_mei_phy_free(phy);
67e0af11faSSamuel Ortiz 
68e0af11faSSamuel Ortiz 	return 0;
69e0af11faSSamuel Ortiz }
70e0af11faSSamuel Ortiz 
719593b0b1SSamuel Ortiz static struct mei_cl_device_id microread_mei_tbl[] = {
729593b0b1SSamuel Ortiz 	{ MICROREAD_DRIVER_NAME },
73cd48d8baSSamuel Ortiz 
74cd48d8baSSamuel Ortiz 	/* required last entry */
75cd48d8baSSamuel Ortiz 	{ }
76cd48d8baSSamuel Ortiz };
77cd48d8baSSamuel Ortiz MODULE_DEVICE_TABLE(mei, microread_mei_tbl);
78cd48d8baSSamuel Ortiz 
799593b0b1SSamuel Ortiz static struct mei_cl_driver microread_driver = {
80cd48d8baSSamuel Ortiz 	.id_table = microread_mei_tbl,
81e0af11faSSamuel Ortiz 	.name = MICROREAD_DRIVER_NAME,
82e0af11faSSamuel Ortiz 
83e0af11faSSamuel Ortiz 	.probe = microread_mei_probe,
84e0af11faSSamuel Ortiz 	.remove = microread_mei_remove,
85e0af11faSSamuel Ortiz };
86e0af11faSSamuel Ortiz 
87e0af11faSSamuel Ortiz static int microread_mei_init(void)
88e0af11faSSamuel Ortiz {
89e0af11faSSamuel Ortiz 	int r;
90e0af11faSSamuel Ortiz 
91e0af11faSSamuel Ortiz 	pr_debug(DRIVER_DESC ": %s\n", __func__);
92e0af11faSSamuel Ortiz 
939593b0b1SSamuel Ortiz 	r = mei_cl_driver_register(&microread_driver);
94e0af11faSSamuel Ortiz 	if (r) {
95e0af11faSSamuel Ortiz 		pr_err(MICROREAD_DRIVER_NAME ": driver registration failed\n");
96e0af11faSSamuel Ortiz 		return r;
97e0af11faSSamuel Ortiz 	}
98e0af11faSSamuel Ortiz 
99e0af11faSSamuel Ortiz 	return 0;
100e0af11faSSamuel Ortiz }
101e0af11faSSamuel Ortiz 
102e0af11faSSamuel Ortiz static void microread_mei_exit(void)
103e0af11faSSamuel Ortiz {
1049593b0b1SSamuel Ortiz 	mei_cl_driver_unregister(&microread_driver);
105e0af11faSSamuel Ortiz }
106e0af11faSSamuel Ortiz 
107e0af11faSSamuel Ortiz module_init(microread_mei_init);
108e0af11faSSamuel Ortiz module_exit(microread_mei_exit);
109e0af11faSSamuel Ortiz 
110e0af11faSSamuel Ortiz MODULE_LICENSE("GPL");
111e0af11faSSamuel Ortiz MODULE_DESCRIPTION(DRIVER_DESC);
112