xref: /openbmc/linux/drivers/nfc/s3fwrn5/s3fwrn5.h (revision 55fd7e02)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * NCI based driver for Samsung S3FWRN5 NFC chip
4  *
5  * Copyright (C) 2015 Samsung Electrnoics
6  * Robert Baldyga <r.baldyga@samsung.com>
7  */
8 
9 #ifndef __LOCAL_S3FWRN5_H_
10 #define __LOCAL_S3FWRN5_H_
11 
12 #include <linux/nfc.h>
13 
14 #include <net/nfc/nci_core.h>
15 
16 #include "firmware.h"
17 
18 enum s3fwrn5_mode {
19 	S3FWRN5_MODE_COLD,
20 	S3FWRN5_MODE_NCI,
21 	S3FWRN5_MODE_FW,
22 };
23 
24 struct s3fwrn5_phy_ops {
25 	void (*set_wake)(void *id, bool sleep);
26 	void (*set_mode)(void *id, enum s3fwrn5_mode);
27 	enum s3fwrn5_mode (*get_mode)(void *id);
28 	int (*write)(void *id, struct sk_buff *skb);
29 };
30 
31 struct s3fwrn5_info {
32 	struct nci_dev *ndev;
33 	void *phy_id;
34 	struct device *pdev;
35 
36 	const struct s3fwrn5_phy_ops *phy_ops;
37 	unsigned int max_payload;
38 
39 	struct s3fwrn5_fw_info fw_info;
40 
41 	struct mutex mutex;
42 };
43 
44 static inline int s3fwrn5_set_mode(struct s3fwrn5_info *info,
45 	enum s3fwrn5_mode mode)
46 {
47 	if (!info->phy_ops->set_mode)
48 		return -ENOTSUPP;
49 
50 	info->phy_ops->set_mode(info->phy_id, mode);
51 
52 	return 0;
53 }
54 
55 static inline enum s3fwrn5_mode s3fwrn5_get_mode(struct s3fwrn5_info *info)
56 {
57 	if (!info->phy_ops->get_mode)
58 		return -ENOTSUPP;
59 
60 	return info->phy_ops->get_mode(info->phy_id);
61 }
62 
63 static inline int s3fwrn5_set_wake(struct s3fwrn5_info *info, bool wake)
64 {
65 	if (!info->phy_ops->set_wake)
66 		return -ENOTSUPP;
67 
68 	info->phy_ops->set_wake(info->phy_id, wake);
69 
70 	return 0;
71 }
72 
73 static inline int s3fwrn5_write(struct s3fwrn5_info *info, struct sk_buff *skb)
74 {
75 	if (!info->phy_ops->write)
76 		return -ENOTSUPP;
77 
78 	return info->phy_ops->write(info->phy_id, skb);
79 }
80 
81 int s3fwrn5_probe(struct nci_dev **ndev, void *phy_id, struct device *pdev,
82 	const struct s3fwrn5_phy_ops *phy_ops, unsigned int max_payload);
83 void s3fwrn5_remove(struct nci_dev *ndev);
84 
85 int s3fwrn5_recv_frame(struct nci_dev *ndev, struct sk_buff *skb,
86 	enum s3fwrn5_mode mode);
87 
88 #endif /* __LOCAL_S3FWRN5_H_ */
89