Samuel Ortiz | e0af11f | 2013-01-14 20:35:22 +0100 | [diff] [blame] | 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 |
| 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 | |
Joe Perches | 17936b4 | 2013-04-05 12:27:39 -0700 | [diff] [blame^] | 21 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 22 | |
Samuel Ortiz | e0af11f | 2013-01-14 20:35:22 +0100 | [diff] [blame] | 23 | #include <linux/module.h> |
Eric Lapuyade | 4912e2f | 2013-04-15 11:19:20 +0200 | [diff] [blame] | 24 | #include <linux/mod_devicetable.h> |
Samuel Ortiz | e0af11f | 2013-01-14 20:35:22 +0100 | [diff] [blame] | 25 | #include <linux/nfc.h> |
| 26 | #include <net/nfc/hci.h> |
| 27 | #include <net/nfc/llc.h> |
| 28 | |
Eric Lapuyade | 4912e2f | 2013-04-15 11:19:20 +0200 | [diff] [blame] | 29 | #include "../mei_phy.h" |
Samuel Ortiz | e0af11f | 2013-01-14 20:35:22 +0100 | [diff] [blame] | 30 | #include "microread.h" |
| 31 | |
| 32 | #define MICROREAD_DRIVER_NAME "microread" |
| 33 | |
Samuel Ortiz | 9593b0b | 2013-03-28 10:39:28 +0100 | [diff] [blame] | 34 | static int microread_mei_probe(struct mei_cl_device *device, |
| 35 | const struct mei_cl_device_id *id) |
Samuel Ortiz | e0af11f | 2013-01-14 20:35:22 +0100 | [diff] [blame] | 36 | { |
Eric Lapuyade | 4912e2f | 2013-04-15 11:19:20 +0200 | [diff] [blame] | 37 | struct nfc_mei_phy *phy; |
Samuel Ortiz | e0af11f | 2013-01-14 20:35:22 +0100 | [diff] [blame] | 38 | int r; |
| 39 | |
| 40 | pr_info("Probing NFC microread\n"); |
| 41 | |
Eric Lapuyade | 4912e2f | 2013-04-15 11:19:20 +0200 | [diff] [blame] | 42 | phy = nfc_mei_phy_alloc(device); |
Samuel Ortiz | e0af11f | 2013-01-14 20:35:22 +0100 | [diff] [blame] | 43 | if (!phy) { |
| 44 | pr_err("Cannot allocate memory for microread mei phy.\n"); |
| 45 | return -ENOMEM; |
| 46 | } |
| 47 | |
Samuel Ortiz | e0af11f | 2013-01-14 20:35:22 +0100 | [diff] [blame] | 48 | r = microread_probe(phy, &mei_phy_ops, LLC_NOP_NAME, |
| 49 | MEI_NFC_HEADER_SIZE, 0, MEI_NFC_MAX_HCI_PAYLOAD, |
| 50 | &phy->hdev); |
Samuel Ortiz | 73f3adb | 2013-04-30 23:48:50 +0200 | [diff] [blame] | 51 | if (r < 0) { |
| 52 | nfc_mei_phy_free(phy); |
| 53 | |
| 54 | return r; |
| 55 | } |
Samuel Ortiz | e0af11f | 2013-01-14 20:35:22 +0100 | [diff] [blame] | 56 | |
| 57 | return 0; |
Samuel Ortiz | e0af11f | 2013-01-14 20:35:22 +0100 | [diff] [blame] | 58 | } |
| 59 | |
Samuel Ortiz | 9593b0b | 2013-03-28 10:39:28 +0100 | [diff] [blame] | 60 | static int microread_mei_remove(struct mei_cl_device *device) |
Samuel Ortiz | e0af11f | 2013-01-14 20:35:22 +0100 | [diff] [blame] | 61 | { |
Eric Lapuyade | 4912e2f | 2013-04-15 11:19:20 +0200 | [diff] [blame] | 62 | struct nfc_mei_phy *phy = mei_cl_get_drvdata(device); |
Samuel Ortiz | e0af11f | 2013-01-14 20:35:22 +0100 | [diff] [blame] | 63 | |
Samuel Ortiz | e0af11f | 2013-01-14 20:35:22 +0100 | [diff] [blame] | 64 | microread_remove(phy->hdev); |
| 65 | |
Eric Lapuyade | 4912e2f | 2013-04-15 11:19:20 +0200 | [diff] [blame] | 66 | nfc_mei_phy_free(phy); |
Samuel Ortiz | e0af11f | 2013-01-14 20:35:22 +0100 | [diff] [blame] | 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |
Samuel Ortiz | 9593b0b | 2013-03-28 10:39:28 +0100 | [diff] [blame] | 71 | static struct mei_cl_device_id microread_mei_tbl[] = { |
| 72 | { MICROREAD_DRIVER_NAME }, |
Samuel Ortiz | cd48d8b | 2013-02-11 10:30:04 +0100 | [diff] [blame] | 73 | |
| 74 | /* required last entry */ |
| 75 | { } |
| 76 | }; |
Samuel Ortiz | cd48d8b | 2013-02-11 10:30:04 +0100 | [diff] [blame] | 77 | MODULE_DEVICE_TABLE(mei, microread_mei_tbl); |
| 78 | |
Samuel Ortiz | 9593b0b | 2013-03-28 10:39:28 +0100 | [diff] [blame] | 79 | static struct mei_cl_driver microread_driver = { |
Samuel Ortiz | cd48d8b | 2013-02-11 10:30:04 +0100 | [diff] [blame] | 80 | .id_table = microread_mei_tbl, |
| 81 | .name = MICROREAD_DRIVER_NAME, |
Samuel Ortiz | e0af11f | 2013-01-14 20:35:22 +0100 | [diff] [blame] | 82 | |
| 83 | .probe = microread_mei_probe, |
| 84 | .remove = microread_mei_remove, |
| 85 | }; |
| 86 | |
| 87 | static int microread_mei_init(void) |
| 88 | { |
| 89 | int r; |
| 90 | |
| 91 | pr_debug(DRIVER_DESC ": %s\n", __func__); |
| 92 | |
Samuel Ortiz | 9593b0b | 2013-03-28 10:39:28 +0100 | [diff] [blame] | 93 | r = mei_cl_driver_register(µread_driver); |
Samuel Ortiz | e0af11f | 2013-01-14 20:35:22 +0100 | [diff] [blame] | 94 | if (r) { |
| 95 | pr_err(MICROREAD_DRIVER_NAME ": driver registration failed\n"); |
| 96 | return r; |
| 97 | } |
| 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | static void microread_mei_exit(void) |
| 103 | { |
Samuel Ortiz | 9593b0b | 2013-03-28 10:39:28 +0100 | [diff] [blame] | 104 | mei_cl_driver_unregister(µread_driver); |
Samuel Ortiz | e0af11f | 2013-01-14 20:35:22 +0100 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | module_init(microread_mei_init); |
| 108 | module_exit(microread_mei_exit); |
| 109 | |
| 110 | MODULE_LICENSE("GPL"); |
| 111 | MODULE_DESCRIPTION(DRIVER_DESC); |