2014-08-11 07:30:45 +00:00
|
|
|
/*
|
|
|
|
* Greybus driver and device API
|
|
|
|
*
|
|
|
|
* Copyright 2014 Google Inc.
|
2014-12-12 18:08:42 +00:00
|
|
|
* Copyright 2014 Linaro Ltd.
|
2014-08-11 07:30:45 +00:00
|
|
|
*
|
|
|
|
* Released under the GPLv2 only.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __LINUX_GREYBUS_H
|
|
|
|
#define __LINUX_GREYBUS_H
|
|
|
|
|
|
|
|
#ifdef __KERNEL__
|
|
|
|
|
2014-10-02 02:54:11 +00:00
|
|
|
#include <linux/kernel.h>
|
2014-09-01 20:42:43 +00:00
|
|
|
#include <linux/types.h>
|
2014-08-11 07:30:45 +00:00
|
|
|
#include <linux/list.h>
|
2014-10-02 02:54:11 +00:00
|
|
|
#include <linux/slab.h>
|
2014-08-11 07:30:45 +00:00
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/module.h>
|
2014-10-03 19:14:24 +00:00
|
|
|
#include <linux/idr.h>
|
2014-10-02 02:54:11 +00:00
|
|
|
|
2014-10-02 17:30:03 +00:00
|
|
|
#include "kernel_ver.h"
|
2014-08-11 07:30:45 +00:00
|
|
|
#include "greybus_id.h"
|
2014-09-09 18:55:03 +00:00
|
|
|
#include "greybus_manifest.h"
|
2014-10-02 02:54:16 +00:00
|
|
|
#include "manifest.h"
|
2014-12-11 22:10:55 +00:00
|
|
|
#include "interface_block.h"
|
2014-10-02 02:54:12 +00:00
|
|
|
#include "interface.h"
|
2014-10-02 02:54:14 +00:00
|
|
|
#include "connection.h"
|
2014-10-29 00:36:00 +00:00
|
|
|
#include "protocol.h"
|
2014-10-02 02:54:15 +00:00
|
|
|
#include "operation.h"
|
2014-08-11 07:30:45 +00:00
|
|
|
|
|
|
|
|
2014-09-13 03:47:11 +00:00
|
|
|
/* Matches up with the Greybus Protocol specification document */
|
2014-09-18 19:25:43 +00:00
|
|
|
#define GREYBUS_VERSION_MAJOR 0x00
|
|
|
|
#define GREYBUS_VERSION_MINOR 0x01
|
2014-09-13 03:47:11 +00:00
|
|
|
|
2014-08-11 07:30:45 +00:00
|
|
|
#define GREYBUS_DEVICE_ID_MATCH_DEVICE \
|
2014-10-07 03:34:48 +00:00
|
|
|
(GREYBUS_DEVICE_ID_MATCH_VENDOR | GREYBUS_DEVICE_ID_MATCH_PRODUCT)
|
2014-08-11 07:30:45 +00:00
|
|
|
|
2014-09-01 20:42:43 +00:00
|
|
|
#define GREYBUS_DEVICE(v, p) \
|
2014-08-11 07:30:45 +00:00
|
|
|
.match_flags = GREYBUS_DEVICE_ID_MATCH_DEVICE, \
|
2014-09-01 20:42:43 +00:00
|
|
|
.vendor = (v), \
|
|
|
|
.product = (p),
|
2014-08-11 07:30:45 +00:00
|
|
|
|
2014-09-01 20:42:43 +00:00
|
|
|
#define GREYBUS_DEVICE_SERIAL(s) \
|
2014-08-11 07:30:45 +00:00
|
|
|
.match_flags = GREYBUS_DEVICE_ID_MATCH_SERIAL, \
|
2014-09-01 20:42:43 +00:00
|
|
|
.serial_number = (s),
|
2014-08-11 07:30:45 +00:00
|
|
|
|
2014-10-02 17:30:03 +00:00
|
|
|
/* XXX I couldn't get my Kconfig file to be noticed for out-of-tree build */
|
|
|
|
#ifndef CONFIG_HOST_DEV_CPORT_ID_MAX
|
|
|
|
#define CONFIG_HOST_DEV_CPORT_ID_MAX 128
|
|
|
|
#endif /* !CONFIG_HOST_DEV_CPORT_ID_MAX */
|
|
|
|
|
|
|
|
/* Maximum number of CPorts usable by a host device */
|
|
|
|
/* XXX This should really be determined by the AP module manifest */
|
|
|
|
#define HOST_DEV_CPORT_ID_MAX CONFIG_HOST_DEV_CPORT_ID_MAX
|
|
|
|
#define CPORT_ID_BAD U16_MAX /* UniPro max id is 4095 */
|
2014-08-11 07:30:45 +00:00
|
|
|
|
2014-08-30 23:20:22 +00:00
|
|
|
/* For SP1 hardware, we are going to "hardcode" each device to have all logical
|
|
|
|
* blocks in order to be able to address them as one unified "unit". Then
|
|
|
|
* higher up layers will then be able to talk to them as one logical block and
|
|
|
|
* properly know how they are hooked together (i.e. which i2c port is on the
|
|
|
|
* same module as the gpio pins, etc.)
|
|
|
|
*
|
|
|
|
* So, put the "private" data structures here in greybus.h and link to them off
|
2014-10-02 02:54:11 +00:00
|
|
|
* of the "main" gb_module structure.
|
2014-08-30 23:20:22 +00:00
|
|
|
*/
|
|
|
|
|
2014-09-06 23:57:36 +00:00
|
|
|
struct greybus_host_device;
|
2014-09-07 20:12:11 +00:00
|
|
|
struct svc_msg;
|
2014-09-06 23:57:36 +00:00
|
|
|
|
2014-12-02 14:30:34 +00:00
|
|
|
/*
|
|
|
|
* When the Greybus code allocates a buffer it sets aside bytes
|
|
|
|
* prior to the beginning of the payload area for the host device's
|
|
|
|
* exclusive use. The size is specified by hd->buffer_headroom, and
|
|
|
|
* which can't be greater than GB_BUFFER_HEADROOM_MAX.
|
|
|
|
*/
|
|
|
|
#define GB_BUFFER_HEADROOM_MAX sizeof(u64)
|
|
|
|
|
2014-11-18 19:26:40 +00:00
|
|
|
/* Buffers allocated from the host driver will be aligned to this multiple */
|
|
|
|
#define GB_BUFFER_ALIGN sizeof(u32)
|
|
|
|
|
2014-09-06 23:57:36 +00:00
|
|
|
/* Greybus "Host driver" structure, needed by a host controller driver to be
|
|
|
|
* able to handle both SVC control as well as "real" greybus messages
|
|
|
|
*/
|
|
|
|
struct greybus_host_driver {
|
|
|
|
size_t hd_priv_size;
|
|
|
|
|
2014-11-18 19:26:46 +00:00
|
|
|
void *(*buffer_send)(struct greybus_host_device *hd, u16 dest_cport_id,
|
|
|
|
void *buffer, size_t buffer_size, gfp_t gfp_mask);
|
2014-11-18 19:26:44 +00:00
|
|
|
void (*buffer_cancel)(void *cookie);
|
2014-09-24 10:16:14 +00:00
|
|
|
int (*submit_svc)(struct svc_msg *svc_msg,
|
2014-09-20 02:13:33 +00:00
|
|
|
struct greybus_host_device *hd);
|
2014-09-06 23:57:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct greybus_host_device {
|
2014-09-13 03:47:11 +00:00
|
|
|
struct kref kref;
|
2014-09-14 19:27:28 +00:00
|
|
|
struct device *parent;
|
2014-09-06 23:57:36 +00:00
|
|
|
const struct greybus_host_driver *driver;
|
|
|
|
|
2014-10-02 02:54:11 +00:00
|
|
|
struct list_head modules;
|
2014-11-17 14:08:44 +00:00
|
|
|
struct list_head connections;
|
2014-10-03 19:14:24 +00:00
|
|
|
struct ida cport_id_map;
|
2014-10-21 05:52:27 +00:00
|
|
|
u8 device_id;
|
2014-10-02 17:30:03 +00:00
|
|
|
|
2014-11-20 22:09:13 +00:00
|
|
|
/* Host device buffer constraints */
|
|
|
|
size_t buffer_headroom;
|
|
|
|
size_t buffer_size_max;
|
|
|
|
|
2014-09-06 23:57:36 +00:00
|
|
|
/* Private data for the host driver */
|
2014-10-07 03:34:48 +00:00
|
|
|
unsigned long hd_priv[0] __aligned(sizeof(s64));
|
2014-09-06 23:57:36 +00:00
|
|
|
};
|
|
|
|
|
2014-10-07 03:34:48 +00:00
|
|
|
struct greybus_host_device *greybus_create_hd(struct greybus_host_driver *hd,
|
2014-09-06 23:57:36 +00:00
|
|
|
struct device *parent);
|
2014-09-07 20:12:11 +00:00
|
|
|
void greybus_remove_hd(struct greybus_host_device *hd);
|
2014-08-11 11:03:20 +00:00
|
|
|
|
2014-08-11 07:30:45 +00:00
|
|
|
struct greybus_driver {
|
|
|
|
const char *name;
|
|
|
|
|
2014-12-11 22:10:56 +00:00
|
|
|
int (*probe)(struct gb_interface_block *gb_ib,
|
2014-12-11 22:11:02 +00:00
|
|
|
const struct greybus_interface_block_id *id);
|
2014-12-11 22:10:56 +00:00
|
|
|
void (*disconnect)(struct gb_interface_block *gb_ib);
|
2014-08-11 07:30:45 +00:00
|
|
|
|
2014-12-11 22:10:56 +00:00
|
|
|
int (*suspend)(struct gb_interface_block *gb_ib, pm_message_t message);
|
|
|
|
int (*resume)(struct gb_interface_block *gb_ib);
|
2014-08-11 07:30:45 +00:00
|
|
|
|
2014-12-11 22:11:02 +00:00
|
|
|
const struct greybus_interface_block_id *id_table;
|
2014-08-11 07:30:45 +00:00
|
|
|
|
|
|
|
struct device_driver driver;
|
|
|
|
};
|
|
|
|
#define to_greybus_driver(d) container_of(d, struct greybus_driver, driver)
|
|
|
|
|
|
|
|
/* Don't call these directly, use the module_greybus_driver() macro instead */
|
|
|
|
int greybus_register_driver(struct greybus_driver *driver,
|
|
|
|
struct module *module, const char *mod_name);
|
|
|
|
void greybus_deregister(struct greybus_driver *driver);
|
|
|
|
|
|
|
|
/* define to get proper THIS_MODULE and KBUILD_MODNAME values */
|
|
|
|
#define greybus_register(driver) \
|
|
|
|
greybus_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* module_greybus_driver() - Helper macro for registering a Greybus driver
|
|
|
|
* @__greybus_driver: greybus_driver structure
|
|
|
|
*
|
|
|
|
* Helper macro for Greybus drivers to set up proper module init / exit
|
|
|
|
* functions. Replaces module_init() and module_exit() and keeps people from
|
|
|
|
* printing pointless things to the kernel log when their driver is loaded.
|
|
|
|
*/
|
|
|
|
#define module_greybus_driver(__greybus_driver) \
|
|
|
|
module_driver(__greybus_driver, greybus_register, greybus_deregister)
|
|
|
|
|
|
|
|
int greybus_disabled(void);
|
|
|
|
|
2014-08-31 23:17:04 +00:00
|
|
|
/* Internal functions to gb module, move to internal .h file eventually. */
|
|
|
|
|
2014-09-22 02:10:39 +00:00
|
|
|
void gb_add_module(struct greybus_host_device *hd, u8 module_id,
|
|
|
|
u8 *data, int size);
|
2014-09-22 01:17:12 +00:00
|
|
|
void gb_remove_module(struct greybus_host_device *hd, u8 module_id);
|
2014-11-14 11:55:07 +00:00
|
|
|
void gb_remove_modules(struct greybus_host_device *hd);
|
2014-09-22 01:17:12 +00:00
|
|
|
|
2014-09-27 01:55:35 +00:00
|
|
|
int greybus_svc_in(struct greybus_host_device *hd, u8 *data, int length);
|
2014-09-14 18:40:35 +00:00
|
|
|
int gb_ap_init(void);
|
|
|
|
void gb_ap_exit(void);
|
2014-08-31 23:17:04 +00:00
|
|
|
int gb_debugfs_init(void);
|
|
|
|
void gb_debugfs_cleanup(void);
|
|
|
|
|
2014-10-24 09:34:46 +00:00
|
|
|
extern struct bus_type greybus_bus_type;
|
2014-09-02 02:05:54 +00:00
|
|
|
|
2014-10-27 09:32:34 +00:00
|
|
|
int gb_uart_device_init(struct gb_connection *connection);
|
|
|
|
void gb_uart_device_exit(struct gb_connection *connection);
|
|
|
|
|
2014-10-22 07:04:31 +00:00
|
|
|
int svc_set_route_send(struct gb_interface *interface,
|
|
|
|
struct greybus_host_device *hd);
|
2014-08-11 07:30:45 +00:00
|
|
|
|
2014-12-11 22:10:56 +00:00
|
|
|
extern struct device_type greybus_interface_block_type;
|
2014-11-15 20:12:16 +00:00
|
|
|
extern struct device_type greybus_interface_type;
|
|
|
|
extern struct device_type greybus_connection_type;
|
|
|
|
|
2014-12-11 22:10:56 +00:00
|
|
|
static inline int is_gb_interface_block(const struct device *dev)
|
2014-11-15 20:12:16 +00:00
|
|
|
{
|
2014-12-11 22:10:56 +00:00
|
|
|
return dev->type == &greybus_interface_block_type;
|
2014-11-15 20:12:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int is_gb_interface(const struct device *dev)
|
|
|
|
{
|
|
|
|
return dev->type == &greybus_interface_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int is_gb_connection(const struct device *dev)
|
|
|
|
{
|
|
|
|
return dev->type == &greybus_connection_type;
|
|
|
|
}
|
|
|
|
|
2014-08-11 07:30:45 +00:00
|
|
|
#endif /* __KERNEL__ */
|
|
|
|
#endif /* __LINUX_GREYBUS_H */
|