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 21e0af11faSSamuel Ortiz #include <linux/module.h> 22*4912e2feSEric 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 27*4912e2feSEric Lapuyade #include "../mei_phy.h" 28e0af11faSSamuel Ortiz #include "microread.h" 29e0af11faSSamuel Ortiz 30e0af11faSSamuel Ortiz #define MICROREAD_DRIVER_NAME "microread" 31e0af11faSSamuel Ortiz 329593b0b1SSamuel Ortiz static int microread_mei_probe(struct mei_cl_device *device, 339593b0b1SSamuel Ortiz const struct mei_cl_device_id *id) 34e0af11faSSamuel Ortiz { 35*4912e2feSEric Lapuyade struct nfc_mei_phy *phy; 36e0af11faSSamuel Ortiz int r; 37e0af11faSSamuel Ortiz 38e0af11faSSamuel Ortiz pr_info("Probing NFC microread\n"); 39e0af11faSSamuel Ortiz 40*4912e2feSEric Lapuyade phy = nfc_mei_phy_alloc(device); 41e0af11faSSamuel Ortiz if (!phy) { 42e0af11faSSamuel Ortiz pr_err("Cannot allocate memory for microread mei phy.\n"); 43e0af11faSSamuel Ortiz return -ENOMEM; 44e0af11faSSamuel Ortiz } 45e0af11faSSamuel Ortiz 46*4912e2feSEric Lapuyade r = mei_cl_register_event_cb(device, nfc_mei_event_cb, phy); 47e0af11faSSamuel Ortiz if (r) { 48e0af11faSSamuel Ortiz pr_err(MICROREAD_DRIVER_NAME ": event cb registration failed\n"); 49e0af11faSSamuel Ortiz goto err_out; 50e0af11faSSamuel Ortiz } 51e0af11faSSamuel Ortiz 52e0af11faSSamuel Ortiz r = microread_probe(phy, &mei_phy_ops, LLC_NOP_NAME, 53e0af11faSSamuel Ortiz MEI_NFC_HEADER_SIZE, 0, MEI_NFC_MAX_HCI_PAYLOAD, 54e0af11faSSamuel Ortiz &phy->hdev); 55e0af11faSSamuel Ortiz if (r < 0) 56e0af11faSSamuel Ortiz goto err_out; 57e0af11faSSamuel Ortiz 58e0af11faSSamuel Ortiz return 0; 59e0af11faSSamuel Ortiz 60e0af11faSSamuel Ortiz err_out: 61*4912e2feSEric Lapuyade nfc_mei_phy_free(phy); 62e0af11faSSamuel Ortiz 63e0af11faSSamuel Ortiz return r; 64e0af11faSSamuel Ortiz } 65e0af11faSSamuel Ortiz 669593b0b1SSamuel Ortiz static int microread_mei_remove(struct mei_cl_device *device) 67e0af11faSSamuel Ortiz { 68*4912e2feSEric Lapuyade struct nfc_mei_phy *phy = mei_cl_get_drvdata(device); 69e0af11faSSamuel Ortiz 70e0af11faSSamuel Ortiz pr_info("Removing microread\n"); 71e0af11faSSamuel Ortiz 72e0af11faSSamuel Ortiz microread_remove(phy->hdev); 73e0af11faSSamuel Ortiz 74*4912e2feSEric Lapuyade nfc_mei_phy_disable(phy); 75e0af11faSSamuel Ortiz 76*4912e2feSEric Lapuyade nfc_mei_phy_free(phy); 77e0af11faSSamuel Ortiz 78e0af11faSSamuel Ortiz return 0; 79e0af11faSSamuel Ortiz } 80e0af11faSSamuel Ortiz 819593b0b1SSamuel Ortiz static struct mei_cl_device_id microread_mei_tbl[] = { 829593b0b1SSamuel Ortiz { MICROREAD_DRIVER_NAME }, 83cd48d8baSSamuel Ortiz 84cd48d8baSSamuel Ortiz /* required last entry */ 85cd48d8baSSamuel Ortiz { } 86cd48d8baSSamuel Ortiz }; 87cd48d8baSSamuel Ortiz MODULE_DEVICE_TABLE(mei, microread_mei_tbl); 88cd48d8baSSamuel Ortiz 899593b0b1SSamuel Ortiz static struct mei_cl_driver microread_driver = { 90cd48d8baSSamuel Ortiz .id_table = microread_mei_tbl, 91e0af11faSSamuel Ortiz .name = MICROREAD_DRIVER_NAME, 92e0af11faSSamuel Ortiz 93e0af11faSSamuel Ortiz .probe = microread_mei_probe, 94e0af11faSSamuel Ortiz .remove = microread_mei_remove, 95e0af11faSSamuel Ortiz }; 96e0af11faSSamuel Ortiz 97e0af11faSSamuel Ortiz static int microread_mei_init(void) 98e0af11faSSamuel Ortiz { 99e0af11faSSamuel Ortiz int r; 100e0af11faSSamuel Ortiz 101e0af11faSSamuel Ortiz pr_debug(DRIVER_DESC ": %s\n", __func__); 102e0af11faSSamuel Ortiz 1039593b0b1SSamuel Ortiz r = mei_cl_driver_register(µread_driver); 104e0af11faSSamuel Ortiz if (r) { 105e0af11faSSamuel Ortiz pr_err(MICROREAD_DRIVER_NAME ": driver registration failed\n"); 106e0af11faSSamuel Ortiz return r; 107e0af11faSSamuel Ortiz } 108e0af11faSSamuel Ortiz 109e0af11faSSamuel Ortiz return 0; 110e0af11faSSamuel Ortiz } 111e0af11faSSamuel Ortiz 112e0af11faSSamuel Ortiz static void microread_mei_exit(void) 113e0af11faSSamuel Ortiz { 1149593b0b1SSamuel Ortiz mei_cl_driver_unregister(µread_driver); 115e0af11faSSamuel Ortiz } 116e0af11faSSamuel Ortiz 117e0af11faSSamuel Ortiz module_init(microread_mei_init); 118e0af11faSSamuel Ortiz module_exit(microread_mei_exit); 119e0af11faSSamuel Ortiz 120e0af11faSSamuel Ortiz MODULE_LICENSE("GPL"); 121e0af11faSSamuel Ortiz MODULE_DESCRIPTION(DRIVER_DESC); 122