162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Greybus Interface Block code
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright 2014 Google Inc.
662306a36Sopenharmony_ci * Copyright 2014 Linaro Ltd.
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#ifndef __INTERFACE_H
1062306a36Sopenharmony_ci#define __INTERFACE_H
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#include <linux/types.h>
1362306a36Sopenharmony_ci#include <linux/device.h>
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_cienum gb_interface_type {
1662306a36Sopenharmony_ci	GB_INTERFACE_TYPE_INVALID = 0,
1762306a36Sopenharmony_ci	GB_INTERFACE_TYPE_UNKNOWN,
1862306a36Sopenharmony_ci	GB_INTERFACE_TYPE_DUMMY,
1962306a36Sopenharmony_ci	GB_INTERFACE_TYPE_UNIPRO,
2062306a36Sopenharmony_ci	GB_INTERFACE_TYPE_GREYBUS,
2162306a36Sopenharmony_ci};
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci#define GB_INTERFACE_QUIRK_NO_CPORT_FEATURES		BIT(0)
2462306a36Sopenharmony_ci#define GB_INTERFACE_QUIRK_NO_INIT_STATUS		BIT(1)
2562306a36Sopenharmony_ci#define GB_INTERFACE_QUIRK_NO_GMP_IDS			BIT(2)
2662306a36Sopenharmony_ci#define GB_INTERFACE_QUIRK_FORCED_DISABLE		BIT(3)
2762306a36Sopenharmony_ci#define GB_INTERFACE_QUIRK_LEGACY_MODE_SWITCH		BIT(4)
2862306a36Sopenharmony_ci#define GB_INTERFACE_QUIRK_NO_BUNDLE_ACTIVATE		BIT(5)
2962306a36Sopenharmony_ci#define GB_INTERFACE_QUIRK_NO_PM			BIT(6)
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_cistruct gb_interface {
3262306a36Sopenharmony_ci	struct device dev;
3362306a36Sopenharmony_ci	struct gb_control *control;
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci	struct list_head bundles;
3662306a36Sopenharmony_ci	struct list_head module_node;
3762306a36Sopenharmony_ci	struct list_head manifest_descs;
3862306a36Sopenharmony_ci	u8 interface_id;	/* Physical location within the Endo */
3962306a36Sopenharmony_ci	u8 device_id;
4062306a36Sopenharmony_ci	u8 features;		/* Feature flags set in the manifest */
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci	enum gb_interface_type type;
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci	u32 ddbl1_manufacturer_id;
4562306a36Sopenharmony_ci	u32 ddbl1_product_id;
4662306a36Sopenharmony_ci	u32 vendor_id;
4762306a36Sopenharmony_ci	u32 product_id;
4862306a36Sopenharmony_ci	u64 serial_number;
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci	struct gb_host_device *hd;
5162306a36Sopenharmony_ci	struct gb_module *module;
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci	unsigned long quirks;
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci	struct mutex mutex;
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci	bool disconnected;
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci	bool ejected;
6062306a36Sopenharmony_ci	bool removed;
6162306a36Sopenharmony_ci	bool active;
6262306a36Sopenharmony_ci	bool enabled;
6362306a36Sopenharmony_ci	bool mode_switch;
6462306a36Sopenharmony_ci	bool dme_read;
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci	struct work_struct mode_switch_work;
6762306a36Sopenharmony_ci	struct completion mode_switch_completion;
6862306a36Sopenharmony_ci};
6962306a36Sopenharmony_ci#define to_gb_interface(d) container_of(d, struct gb_interface, dev)
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_cistruct gb_interface *gb_interface_create(struct gb_module *module,
7262306a36Sopenharmony_ci					 u8 interface_id);
7362306a36Sopenharmony_ciint gb_interface_activate(struct gb_interface *intf);
7462306a36Sopenharmony_civoid gb_interface_deactivate(struct gb_interface *intf);
7562306a36Sopenharmony_ciint gb_interface_enable(struct gb_interface *intf);
7662306a36Sopenharmony_civoid gb_interface_disable(struct gb_interface *intf);
7762306a36Sopenharmony_ciint gb_interface_add(struct gb_interface *intf);
7862306a36Sopenharmony_civoid gb_interface_del(struct gb_interface *intf);
7962306a36Sopenharmony_civoid gb_interface_put(struct gb_interface *intf);
8062306a36Sopenharmony_civoid gb_interface_mailbox_event(struct gb_interface *intf, u16 result,
8162306a36Sopenharmony_ci								u32 mailbox);
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ciint gb_interface_request_mode_switch(struct gb_interface *intf);
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci#endif /* __INTERFACE_H */
86