Merge remote-tracking branches 'regmap/fix/irq', 'regmap/fix/rbtree' and 'regmap...
[linux-2.6-block.git] / drivers / nfc / microread / mei.c
CommitLineData
e0af11fa
SO
1/*
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
98b32dec 16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
e0af11fa
SO
17 */
18
17936b43
JP
19#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20
e0af11fa 21#include <linux/module.h>
4912e2fe 22#include <linux/mod_devicetable.h>
e0af11fa
SO
23#include <linux/nfc.h>
24#include <net/nfc/hci.h>
25#include <net/nfc/llc.h>
26
4912e2fe 27#include "../mei_phy.h"
e0af11fa
SO
28#include "microread.h"
29
30#define MICROREAD_DRIVER_NAME "microread"
31
9593b0b1
SO
32static int microread_mei_probe(struct mei_cl_device *device,
33 const struct mei_cl_device_id *id)
e0af11fa 34{
4912e2fe 35 struct nfc_mei_phy *phy;
e0af11fa
SO
36 int r;
37
38 pr_info("Probing NFC microread\n");
39
4912e2fe 40 phy = nfc_mei_phy_alloc(device);
e0af11fa
SO
41 if (!phy) {
42 pr_err("Cannot allocate memory for microread mei phy.\n");
43 return -ENOMEM;
44 }
45
e0af11fa
SO
46 r = microread_probe(phy, &mei_phy_ops, LLC_NOP_NAME,
47 MEI_NFC_HEADER_SIZE, 0, MEI_NFC_MAX_HCI_PAYLOAD,
48 &phy->hdev);
73f3adb9
SO
49 if (r < 0) {
50 nfc_mei_phy_free(phy);
e0af11fa 51
73f3adb9
SO
52 return r;
53 }
e0af11fa 54
73f3adb9 55 return 0;
e0af11fa
SO
56}
57
9593b0b1 58static int microread_mei_remove(struct mei_cl_device *device)
e0af11fa 59{
4912e2fe 60 struct nfc_mei_phy *phy = mei_cl_get_drvdata(device);
e0af11fa 61
e0af11fa
SO
62 microread_remove(phy->hdev);
63
4912e2fe 64 nfc_mei_phy_free(phy);
e0af11fa
SO
65
66 return 0;
67}
68
9593b0b1
SO
69static struct mei_cl_device_id microread_mei_tbl[] = {
70 { MICROREAD_DRIVER_NAME },
cd48d8ba
SO
71
72 /* required last entry */
73 { }
74};
cd48d8ba
SO
75MODULE_DEVICE_TABLE(mei, microread_mei_tbl);
76
9593b0b1 77static struct mei_cl_driver microread_driver = {
cd48d8ba
SO
78 .id_table = microread_mei_tbl,
79 .name = MICROREAD_DRIVER_NAME,
e0af11fa
SO
80
81 .probe = microread_mei_probe,
82 .remove = microread_mei_remove,
83};
84
85static int microread_mei_init(void)
86{
87 int r;
88
89 pr_debug(DRIVER_DESC ": %s\n", __func__);
90
9593b0b1 91 r = mei_cl_driver_register(&microread_driver);
e0af11fa
SO
92 if (r) {
93 pr_err(MICROREAD_DRIVER_NAME ": driver registration failed\n");
94 return r;
95 }
96
97 return 0;
98}
99
100static void microread_mei_exit(void)
101{
9593b0b1 102 mei_cl_driver_unregister(&microread_driver);
e0af11fa
SO
103}
104
105module_init(microread_mei_init);
106module_exit(microread_mei_exit);
107
108MODULE_LICENSE("GPL");
109MODULE_DESCRIPTION(DRIVER_DESC);