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 1698b32decSJeff Kirsher * along with this program; if not, see <http://www.gnu.org/licenses/>. 17e0af11faSSamuel Ortiz */ 18e0af11faSSamuel Ortiz 1917936b43SJoe Perches #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 2017936b43SJoe Perches 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 32*89391382STomas Winkler static int microread_mei_probe(struct mei_cl_device *cldev, 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 40*89391382STomas Winkler phy = nfc_mei_phy_alloc(cldev); 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); 4973f3adb9SSamuel Ortiz if (r < 0) { 504912e2feSEric Lapuyade nfc_mei_phy_free(phy); 51e0af11faSSamuel Ortiz 52e0af11faSSamuel Ortiz return r; 53e0af11faSSamuel Ortiz } 54e0af11faSSamuel Ortiz 5573f3adb9SSamuel Ortiz return 0; 5673f3adb9SSamuel Ortiz } 5773f3adb9SSamuel Ortiz 58*89391382STomas Winkler static int microread_mei_remove(struct mei_cl_device *cldev) 59e0af11faSSamuel Ortiz { 60*89391382STomas Winkler struct nfc_mei_phy *phy = mei_cl_get_drvdata(cldev); 61e0af11faSSamuel Ortiz 62e0af11faSSamuel Ortiz microread_remove(phy->hdev); 63e0af11faSSamuel Ortiz 644912e2feSEric Lapuyade nfc_mei_phy_free(phy); 65e0af11faSSamuel Ortiz 66e0af11faSSamuel Ortiz return 0; 67e0af11faSSamuel Ortiz } 68e0af11faSSamuel Ortiz 699593b0b1SSamuel Ortiz static struct mei_cl_device_id microread_mei_tbl[] = { 70b26864caSTomas Winkler { MICROREAD_DRIVER_NAME, MEI_NFC_UUID, MEI_CL_VERSION_ANY}, 71cd48d8baSSamuel Ortiz 72cd48d8baSSamuel Ortiz /* required last entry */ 73cd48d8baSSamuel Ortiz { } 74cd48d8baSSamuel Ortiz }; 75cd48d8baSSamuel Ortiz MODULE_DEVICE_TABLE(mei, microread_mei_tbl); 76cd48d8baSSamuel Ortiz 779593b0b1SSamuel Ortiz static struct mei_cl_driver microread_driver = { 78cd48d8baSSamuel Ortiz .id_table = microread_mei_tbl, 79e0af11faSSamuel Ortiz .name = MICROREAD_DRIVER_NAME, 80e0af11faSSamuel Ortiz 81e0af11faSSamuel Ortiz .probe = microread_mei_probe, 82e0af11faSSamuel Ortiz .remove = microread_mei_remove, 83e0af11faSSamuel Ortiz }; 84e0af11faSSamuel Ortiz 85e0af11faSSamuel Ortiz static int microread_mei_init(void) 86e0af11faSSamuel Ortiz { 87e0af11faSSamuel Ortiz int r; 88e0af11faSSamuel Ortiz 89e0af11faSSamuel Ortiz pr_debug(DRIVER_DESC ": %s\n", __func__); 90e0af11faSSamuel Ortiz 919593b0b1SSamuel Ortiz r = mei_cl_driver_register(µread_driver); 92e0af11faSSamuel Ortiz if (r) { 93e0af11faSSamuel Ortiz pr_err(MICROREAD_DRIVER_NAME ": driver registration failed\n"); 94e0af11faSSamuel Ortiz return r; 95e0af11faSSamuel Ortiz } 96e0af11faSSamuel Ortiz 97e0af11faSSamuel Ortiz return 0; 98e0af11faSSamuel Ortiz } 99e0af11faSSamuel Ortiz 100e0af11faSSamuel Ortiz static void microread_mei_exit(void) 101e0af11faSSamuel Ortiz { 1029593b0b1SSamuel Ortiz mei_cl_driver_unregister(µread_driver); 103e0af11faSSamuel Ortiz } 104e0af11faSSamuel Ortiz 105e0af11faSSamuel Ortiz module_init(microread_mei_init); 106e0af11faSSamuel Ortiz module_exit(microread_mei_exit); 107e0af11faSSamuel Ortiz 108e0af11faSSamuel Ortiz MODULE_LICENSE("GPL"); 109e0af11faSSamuel Ortiz MODULE_DESCRIPTION(DRIVER_DESC); 110