Linux Audio

Check our new training course

Loading...
Note: File does not exist in v3.1.
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * Greybus connections
  4 *
  5 * Copyright 2014 Google Inc.
  6 * Copyright 2014 Linaro Ltd.
  7 */
  8
  9#ifndef __CONNECTION_H
 10#define __CONNECTION_H
 11
 12#include <linux/list.h>
 13#include <linux/kfifo.h>
 14
 15#define GB_CONNECTION_FLAG_CSD		BIT(0)
 16#define GB_CONNECTION_FLAG_NO_FLOWCTRL	BIT(1)
 17#define GB_CONNECTION_FLAG_OFFLOADED	BIT(2)
 18#define GB_CONNECTION_FLAG_CDSI1	BIT(3)
 19#define GB_CONNECTION_FLAG_CONTROL	BIT(4)
 20#define GB_CONNECTION_FLAG_HIGH_PRIO	BIT(5)
 21
 22#define GB_CONNECTION_FLAG_CORE_MASK	GB_CONNECTION_FLAG_CONTROL
 23
 24enum gb_connection_state {
 25	GB_CONNECTION_STATE_DISABLED		= 0,
 26	GB_CONNECTION_STATE_ENABLED_TX		= 1,
 27	GB_CONNECTION_STATE_ENABLED		= 2,
 28	GB_CONNECTION_STATE_DISCONNECTING	= 3,
 29};
 30
 31struct gb_operation;
 32
 33typedef int (*gb_request_handler_t)(struct gb_operation *);
 34
 35struct gb_connection {
 36	struct gb_host_device		*hd;
 37	struct gb_interface		*intf;
 38	struct gb_bundle		*bundle;
 39	struct kref			kref;
 40	u16				hd_cport_id;
 41	u16				intf_cport_id;
 42
 43	struct list_head		hd_links;
 44	struct list_head		bundle_links;
 45
 46	gb_request_handler_t		handler;
 47	unsigned long			flags;
 48
 49	struct mutex			mutex;
 50	spinlock_t			lock;
 51	enum gb_connection_state	state;
 52	struct list_head		operations;
 53
 54	char				name[16];
 55	struct workqueue_struct		*wq;
 56
 57	atomic_t			op_cycle;
 58
 59	void				*private;
 60
 61	bool				mode_switch;
 62};
 63
 64struct gb_connection *gb_connection_create_static(struct gb_host_device *hd,
 65				u16 hd_cport_id, gb_request_handler_t handler);
 66struct gb_connection *gb_connection_create_control(struct gb_interface *intf);
 67struct gb_connection *gb_connection_create(struct gb_bundle *bundle,
 68				u16 cport_id, gb_request_handler_t handler);
 69struct gb_connection *gb_connection_create_flags(struct gb_bundle *bundle,
 70				u16 cport_id, gb_request_handler_t handler,
 71				unsigned long flags);
 72struct gb_connection *gb_connection_create_offloaded(struct gb_bundle *bundle,
 73				u16 cport_id, unsigned long flags);
 74void gb_connection_destroy(struct gb_connection *connection);
 75
 76static inline bool gb_connection_is_static(struct gb_connection *connection)
 77{
 78	return !connection->intf;
 79}
 80
 81int gb_connection_enable(struct gb_connection *connection);
 82int gb_connection_enable_tx(struct gb_connection *connection);
 83void gb_connection_disable_rx(struct gb_connection *connection);
 84void gb_connection_disable(struct gb_connection *connection);
 85void gb_connection_disable_forced(struct gb_connection *connection);
 86
 87void gb_connection_mode_switch_prepare(struct gb_connection *connection);
 88void gb_connection_mode_switch_complete(struct gb_connection *connection);
 89
 90void greybus_data_rcvd(struct gb_host_device *hd, u16 cport_id,
 91			u8 *data, size_t length);
 92
 93void gb_connection_latency_tag_enable(struct gb_connection *connection);
 94void gb_connection_latency_tag_disable(struct gb_connection *connection);
 95
 96static inline bool gb_connection_e2efc_enabled(struct gb_connection *connection)
 97{
 98	return !(connection->flags & GB_CONNECTION_FLAG_CSD);
 99}
100
101static inline bool
102gb_connection_flow_control_disabled(struct gb_connection *connection)
103{
104	return connection->flags & GB_CONNECTION_FLAG_NO_FLOWCTRL;
105}
106
107static inline bool gb_connection_is_offloaded(struct gb_connection *connection)
108{
109	return connection->flags & GB_CONNECTION_FLAG_OFFLOADED;
110}
111
112static inline bool gb_connection_is_control(struct gb_connection *connection)
113{
114	return connection->flags & GB_CONNECTION_FLAG_CONTROL;
115}
116
117static inline void *gb_connection_get_data(struct gb_connection *connection)
118{
119	return connection->private;
120}
121
122static inline void gb_connection_set_data(struct gb_connection *connection,
123					  void *data)
124{
125	connection->private = data;
126}
127
128#endif /* __CONNECTION_H */