blob: e746919530f515fb2b3c65d8b70db73e76a7e81c [file] [log] [blame]
Samuel Ortize5354102013-03-27 17:29:53 +02001#ifndef _LINUX_MEI_CL_BUS_H
2#define _LINUX_MEI_CL_BUS_H
3
4#include <linux/device.h>
5#include <linux/uuid.h>
Tomas Winkler1f180352014-09-29 16:31:46 +03006#include <linux/mod_devicetable.h>
Samuel Ortize5354102013-03-27 17:29:53 +02007
8struct mei_cl_device;
Tomas Winkler512f64d2015-07-23 15:08:41 +03009struct mei_device;
Samuel Ortize5354102013-03-27 17:29:53 +020010
Tomas Winklerd49dc5e2015-09-10 10:18:05 +030011typedef void (*mei_cldev_event_cb_t)(struct mei_cl_device *cldev,
12 u32 events, void *context);
Tomas Winklerdbac9932015-05-07 15:54:07 +030013
14/**
15 * struct mei_cl_device - MEI device handle
16 * An mei_cl_device pointer is returned from mei_add_device()
17 * and links MEI bus clients to their actual ME host client pointer.
18 * Drivers for MEI devices will get an mei_cl_device pointer
19 * when being probed and shall use it for doing ME bus I/O.
20 *
Tomas Winkler0ff0a8d2015-07-23 15:08:42 +030021 * @bus_list: device on the bus list
Tomas Winkler512f64d2015-07-23 15:08:41 +030022 * @bus: parent mei device
Tomas Winklerdbac9932015-05-07 15:54:07 +030023 * @dev: linux driver model device pointer
24 * @me_cl: me client
25 * @cl: mei client
26 * @name: device name
27 * @event_work: async work to execute event callback
28 * @event_cb: Drivers register this callback to get asynchronous ME
29 * events (e.g. Rx buffer pending) notifications.
30 * @event_context: event callback run context
Alexander Usyskinbb2ef9c2015-07-26 09:54:23 +030031 * @events_mask: Events bit mask requested by driver.
Tomas Winklerdbac9932015-05-07 15:54:07 +030032 * @events: Events bitmask sent to the driver.
Tomas Winkler71ce7892015-07-23 15:08:43 +030033 *
34 * @do_match: wheather device can be matched with a driver
Tomas Winkler0ff0a8d2015-07-23 15:08:42 +030035 * @is_added: device is already scanned
Tomas Winklerdbac9932015-05-07 15:54:07 +030036 * @priv_data: client private data
37 */
38struct mei_cl_device {
Tomas Winkler0ff0a8d2015-07-23 15:08:42 +030039 struct list_head bus_list;
Tomas Winkler512f64d2015-07-23 15:08:41 +030040 struct mei_device *bus;
Tomas Winklerdbac9932015-05-07 15:54:07 +030041 struct device dev;
42
43 struct mei_me_client *me_cl;
44 struct mei_cl *cl;
45 char name[MEI_CL_NAME_SIZE];
46
47 struct work_struct event_work;
Tomas Winklerd49dc5e2015-09-10 10:18:05 +030048 mei_cldev_event_cb_t event_cb;
Tomas Winklerdbac9932015-05-07 15:54:07 +030049 void *event_context;
Alexander Usyskinbb2ef9c2015-07-26 09:54:23 +030050 unsigned long events_mask;
Tomas Winklerdbac9932015-05-07 15:54:07 +030051 unsigned long events;
Tomas Winkler71ce7892015-07-23 15:08:43 +030052
53 unsigned int do_match:1;
Tomas Winkler0ff0a8d2015-07-23 15:08:42 +030054 unsigned int is_added:1;
Tomas Winklerdbac9932015-05-07 15:54:07 +030055
56 void *priv_data;
57};
58
Samuel Ortize5354102013-03-27 17:29:53 +020059struct mei_cl_driver {
60 struct device_driver driver;
61 const char *name;
62
63 const struct mei_cl_device_id *id_table;
64
Tomas Winkler89391382015-09-10 10:18:04 +030065 int (*probe)(struct mei_cl_device *cldev,
Samuel Ortize5354102013-03-27 17:29:53 +020066 const struct mei_cl_device_id *id);
Tomas Winkler89391382015-09-10 10:18:04 +030067 int (*remove)(struct mei_cl_device *cldev);
Samuel Ortize5354102013-03-27 17:29:53 +020068};
69
Tomas Winklerd49dc5e2015-09-10 10:18:05 +030070int __mei_cldev_driver_register(struct mei_cl_driver *cldrv,
71 struct module *owner);
72#define mei_cldev_driver_register(cldrv) \
73 __mei_cldev_driver_register(cldrv, THIS_MODULE)
Samuel Ortiz333e4ee2013-03-27 17:29:54 +020074
Tomas Winklerd49dc5e2015-09-10 10:18:05 +030075void mei_cldev_driver_unregister(struct mei_cl_driver *cldrv);
Samuel Ortiz333e4ee2013-03-27 17:29:54 +020076
Tomas Winklerd49dc5e2015-09-10 10:18:05 +030077ssize_t mei_cldev_send(struct mei_cl_device *cldev, u8 *buf, size_t length);
78ssize_t mei_cldev_recv(struct mei_cl_device *cldev, u8 *buf, size_t length);
Samuel Ortiz3e833292013-03-27 17:29:55 +020079
Tomas Winklerd49dc5e2015-09-10 10:18:05 +030080int mei_cldev_register_event_cb(struct mei_cl_device *cldev,
81 unsigned long event_mask,
82 mei_cldev_event_cb_t read_cb, void *context);
Samuel Ortiz3e833292013-03-27 17:29:55 +020083
84#define MEI_CL_EVENT_RX 0
85#define MEI_CL_EVENT_TX 1
Alexander Usyskinbb2ef9c2015-07-26 09:54:23 +030086#define MEI_CL_EVENT_NOTIF 2
Samuel Ortiz3e833292013-03-27 17:29:55 +020087
Tomas Winklerbaeacd02015-09-10 10:18:02 +030088const uuid_le *mei_cldev_uuid(const struct mei_cl_device *cldev);
89u8 mei_cldev_ver(const struct mei_cl_device *cldev);
90
Tomas Winklerd49dc5e2015-09-10 10:18:05 +030091void *mei_cldev_get_drvdata(const struct mei_cl_device *cldev);
92void mei_cldev_set_drvdata(struct mei_cl_device *cldev, void *data);
Samuel Ortizaa6aef22013-03-27 17:29:59 +020093
Tomas Winklerd49dc5e2015-09-10 10:18:05 +030094int mei_cldev_enable(struct mei_cl_device *cldev);
95int mei_cldev_disable(struct mei_cl_device *cldev);
Tomas Winkler01a14ed2015-09-10 10:18:03 +030096bool mei_cldev_enabled(struct mei_cl_device *cldev);
Samuel Ortize46980a2013-04-09 01:51:38 +030097
Samuel Ortize5354102013-03-27 17:29:53 +020098#endif /* _LINUX_MEI_CL_BUS_H */