2 * MEI Library for mei bus nfc device access
4 * Copyright (C) 2013 Intel Corporation. All rights reserved.
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.
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.
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.
21 #include <linux/module.h>
22 #include <linux/slab.h>
23 #include <linux/nfc.h>
35 #define MEI_NFC_MAX_READ (MEI_NFC_HEADER_SIZE + MEI_NFC_MAX_HCI_PAYLOAD)
37 #define MEI_DUMP_SKB_IN(info, skb) \
39 pr_debug("%s:\n", info); \
40 print_hex_dump_debug("mei in : ", DUMP_PREFIX_OFFSET, \
41 16, 1, (skb)->data, (skb)->len, false); \
44 #define MEI_DUMP_SKB_OUT(info, skb) \
46 pr_debug("%s:\n", info); \
47 print_hex_dump_debug("mei out: ", DUMP_PREFIX_OFFSET, \
48 16, 1, (skb)->data, (skb)->len, false); \
51 int nfc_mei_phy_enable(void *phy_id
)
54 struct nfc_mei_phy
*phy
= phy_id
;
56 pr_info("%s\n", __func__
);
58 if (phy
->powered
== 1)
61 r
= mei_cl_enable_device(phy
->device
);
63 pr_err("MEI_PHY: Could not enable device\n");
67 r
= mei_cl_register_event_cb(phy
->device
, nfc_mei_event_cb
, phy
);
69 pr_err("MEY_PHY: Event cb registration failed\n");
70 mei_cl_disable_device(phy
->device
);
80 EXPORT_SYMBOL_GPL(nfc_mei_phy_enable
);
82 void nfc_mei_phy_disable(void *phy_id
)
84 struct nfc_mei_phy
*phy
= phy_id
;
86 pr_info("%s\n", __func__
);
88 mei_cl_disable_device(phy
->device
);
92 EXPORT_SYMBOL_GPL(nfc_mei_phy_disable
);
95 * Writing a frame must not return the number of written bytes.
96 * It must return either zero for success, or <0 for error.
97 * In addition, it must not alter the skb
99 static int nfc_mei_phy_write(void *phy_id
, struct sk_buff
*skb
)
101 struct nfc_mei_phy
*phy
= phy_id
;
104 MEI_DUMP_SKB_OUT("mei frame sent", skb
);
106 r
= mei_cl_send(phy
->device
, skb
->data
, skb
->len
);
113 void nfc_mei_event_cb(struct mei_cl_device
*device
, u32 events
, void *context
)
115 struct nfc_mei_phy
*phy
= context
;
117 if (phy
->hard_fault
!= 0)
120 if (events
& BIT(MEI_CL_EVENT_RX
)) {
124 skb
= alloc_skb(MEI_NFC_MAX_READ
, GFP_KERNEL
);
128 reply_size
= mei_cl_recv(device
, skb
->data
, MEI_NFC_MAX_READ
);
129 if (reply_size
< MEI_NFC_HEADER_SIZE
) {
134 skb_put(skb
, reply_size
);
135 skb_pull(skb
, MEI_NFC_HEADER_SIZE
);
137 MEI_DUMP_SKB_IN("mei frame read", skb
);
139 nfc_hci_recv_frame(phy
->hdev
, skb
);
142 EXPORT_SYMBOL_GPL(nfc_mei_event_cb
);
144 struct nfc_phy_ops mei_phy_ops
= {
145 .write
= nfc_mei_phy_write
,
146 .enable
= nfc_mei_phy_enable
,
147 .disable
= nfc_mei_phy_disable
,
149 EXPORT_SYMBOL_GPL(mei_phy_ops
);
151 struct nfc_mei_phy
*nfc_mei_phy_alloc(struct mei_cl_device
*device
)
153 struct nfc_mei_phy
*phy
;
155 phy
= kzalloc(sizeof(struct nfc_mei_phy
), GFP_KERNEL
);
159 phy
->device
= device
;
160 mei_cl_set_drvdata(device
, phy
);
164 EXPORT_SYMBOL_GPL(nfc_mei_phy_alloc
);
166 void nfc_mei_phy_free(struct nfc_mei_phy
*phy
)
170 EXPORT_SYMBOL_GPL(nfc_mei_phy_free
);
172 MODULE_LICENSE("GPL");
173 MODULE_DESCRIPTION("mei bus NFC device interface");
This page took 0.034165 seconds and 6 git commands to generate.