blob: 1ad044dce7b60acfa686d72d842670d64bd02efb [file] [log] [blame]
Samuel Ortize0af11f2013-01-14 20:35:22 +01001/*
2 * HCI based Driver for Inside Secure microread 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>
Eric Lapuyade4912e2f2013-04-15 11:19:20 +020022#include <linux/mod_devicetable.h>
Samuel Ortize0af11f2013-01-14 20:35:22 +010023#include <linux/nfc.h>
24#include <net/nfc/hci.h>
25#include <net/nfc/llc.h>
26
Eric Lapuyade4912e2f2013-04-15 11:19:20 +020027#include "../mei_phy.h"
Samuel Ortize0af11f2013-01-14 20:35:22 +010028#include "microread.h"
29
30#define MICROREAD_DRIVER_NAME "microread"
31
Samuel Ortiz9593b0b2013-03-28 10:39:28 +010032static int microread_mei_probe(struct mei_cl_device *device,
33 const struct mei_cl_device_id *id)
Samuel Ortize0af11f2013-01-14 20:35:22 +010034{
Eric Lapuyade4912e2f2013-04-15 11:19:20 +020035 struct nfc_mei_phy *phy;
Samuel Ortize0af11f2013-01-14 20:35:22 +010036 int r;
37
38 pr_info("Probing NFC microread\n");
39
Eric Lapuyade4912e2f2013-04-15 11:19:20 +020040 phy = nfc_mei_phy_alloc(device);
Samuel Ortize0af11f2013-01-14 20:35:22 +010041 if (!phy) {
42 pr_err("Cannot allocate memory for microread mei phy.\n");
43 return -ENOMEM;
44 }
45
Eric Lapuyade4912e2f2013-04-15 11:19:20 +020046 r = mei_cl_register_event_cb(device, nfc_mei_event_cb, phy);
Samuel Ortize0af11f2013-01-14 20:35:22 +010047 if (r) {
48 pr_err(MICROREAD_DRIVER_NAME ": event cb registration failed\n");
49 goto err_out;
50 }
51
52 r = microread_probe(phy, &mei_phy_ops, LLC_NOP_NAME,
53 MEI_NFC_HEADER_SIZE, 0, MEI_NFC_MAX_HCI_PAYLOAD,
54 &phy->hdev);
55 if (r < 0)
56 goto err_out;
57
58 return 0;
59
60err_out:
Eric Lapuyade4912e2f2013-04-15 11:19:20 +020061 nfc_mei_phy_free(phy);
Samuel Ortize0af11f2013-01-14 20:35:22 +010062
63 return r;
64}
65
Samuel Ortiz9593b0b2013-03-28 10:39:28 +010066static int microread_mei_remove(struct mei_cl_device *device)
Samuel Ortize0af11f2013-01-14 20:35:22 +010067{
Eric Lapuyade4912e2f2013-04-15 11:19:20 +020068 struct nfc_mei_phy *phy = mei_cl_get_drvdata(device);
Samuel Ortize0af11f2013-01-14 20:35:22 +010069
70 pr_info("Removing microread\n");
71
72 microread_remove(phy->hdev);
73
Eric Lapuyade4912e2f2013-04-15 11:19:20 +020074 nfc_mei_phy_disable(phy);
Samuel Ortize0af11f2013-01-14 20:35:22 +010075
Eric Lapuyade4912e2f2013-04-15 11:19:20 +020076 nfc_mei_phy_free(phy);
Samuel Ortize0af11f2013-01-14 20:35:22 +010077
78 return 0;
79}
80
Samuel Ortiz9593b0b2013-03-28 10:39:28 +010081static struct mei_cl_device_id microread_mei_tbl[] = {
82 { MICROREAD_DRIVER_NAME },
Samuel Ortizcd48d8b2013-02-11 10:30:04 +010083
84 /* required last entry */
85 { }
86};
Samuel Ortizcd48d8b2013-02-11 10:30:04 +010087MODULE_DEVICE_TABLE(mei, microread_mei_tbl);
88
Samuel Ortiz9593b0b2013-03-28 10:39:28 +010089static struct mei_cl_driver microread_driver = {
Samuel Ortizcd48d8b2013-02-11 10:30:04 +010090 .id_table = microread_mei_tbl,
91 .name = MICROREAD_DRIVER_NAME,
Samuel Ortize0af11f2013-01-14 20:35:22 +010092
93 .probe = microread_mei_probe,
94 .remove = microread_mei_remove,
95};
96
97static int microread_mei_init(void)
98{
99 int r;
100
101 pr_debug(DRIVER_DESC ": %s\n", __func__);
102
Samuel Ortiz9593b0b2013-03-28 10:39:28 +0100103 r = mei_cl_driver_register(&microread_driver);
Samuel Ortize0af11f2013-01-14 20:35:22 +0100104 if (r) {
105 pr_err(MICROREAD_DRIVER_NAME ": driver registration failed\n");
106 return r;
107 }
108
109 return 0;
110}
111
112static void microread_mei_exit(void)
113{
Samuel Ortiz9593b0b2013-03-28 10:39:28 +0100114 mei_cl_driver_unregister(&microread_driver);
Samuel Ortize0af11f2013-01-14 20:35:22 +0100115}
116
117module_init(microread_mei_init);
118module_exit(microread_mei_exit);
119
120MODULE_LICENSE("GPL");
121MODULE_DESCRIPTION(DRIVER_DESC);