2014-08-11 07:30:45 +00:00
|
|
|
/*
|
|
|
|
* Greybus driver and device API
|
|
|
|
*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Released under the GPLv2 only.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __LINUX_GREYBUS_H
|
|
|
|
#define __LINUX_GREYBUS_H
|
|
|
|
|
|
|
|
#ifdef __KERNEL__
|
|
|
|
|
2014-09-01 20:42:43 +00:00
|
|
|
#include <linux/types.h>
|
2014-08-11 07:30:45 +00:00
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include "greybus_id.h"
|
2014-09-01 20:42:43 +00:00
|
|
|
#include "greybus_desc.h"
|
2014-08-11 07:30:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define GREYBUS_DEVICE_ID_MATCH_DEVICE \
|
|
|
|
(GREYBUS_DEVICE_ID_MATCH_VENDOR | GREYBUS_DEVICE_ID_MATCH_PRODUCT)
|
|
|
|
|
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-08-11 11:03:20 +00:00
|
|
|
|
|
|
|
struct gbuf;
|
|
|
|
|
2014-09-01 23:03:31 +00:00
|
|
|
struct gdev_cport {
|
2014-08-11 11:03:20 +00:00
|
|
|
u16 number;
|
2014-09-01 21:39:49 +00:00
|
|
|
u16 size;
|
2014-08-11 11:03:20 +00:00
|
|
|
// FIXME, what else?
|
2014-09-01 23:03:31 +00:00
|
|
|
u8 speed; // valid???
|
|
|
|
};
|
|
|
|
|
|
|
|
struct gdev_string {
|
|
|
|
u16 length;
|
|
|
|
u8 id;
|
|
|
|
u8 string[0];
|
2014-08-11 11:03:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef void (*gbuf_complete_t)(struct gbuf *gbuf);
|
|
|
|
|
|
|
|
struct gbuf {
|
|
|
|
struct kref kref;
|
|
|
|
void *hcpriv;
|
|
|
|
|
|
|
|
struct list_head anchor_list;
|
|
|
|
struct gbuf_anchor *anchor; // FIXME do we need?
|
|
|
|
|
|
|
|
struct greybus_device *gdev;
|
2014-09-01 23:03:31 +00:00
|
|
|
struct gdev_cport *cport;
|
2014-08-11 11:03:20 +00:00
|
|
|
int status;
|
|
|
|
void *transfer_buffer;
|
|
|
|
u32 transfer_flags; /* flags for the transfer buffer */
|
|
|
|
u32 transfer_buffer_length;
|
|
|
|
u32 actual_length;
|
|
|
|
|
|
|
|
struct scatterlist *sg; // FIXME do we need?
|
|
|
|
int num_sgs;
|
|
|
|
|
|
|
|
void *context;
|
|
|
|
gbuf_complete_t complete;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* gbuf->transfer_flags
|
|
|
|
*/
|
|
|
|
#define GBUF_FREE_BUFFER BIT(0) /* Free the transfer buffer with the gbuf */
|
|
|
|
|
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
|
|
|
|
* of the "main" greybus_device structure.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct gb_i2c_device;
|
|
|
|
struct gb_gpio_device;
|
|
|
|
struct gb_sdio_host;
|
|
|
|
struct gb_tty;
|
|
|
|
struct gb_usb_device;
|
2014-08-11 11:03:20 +00:00
|
|
|
|
2014-09-01 23:03:31 +00:00
|
|
|
/* Increase these values if needed */
|
|
|
|
#define MAX_CPORTS_PER_MODULE 10
|
|
|
|
#define MAX_STRINGS_PER_MODULE 10
|
|
|
|
|
2014-08-11 07:30:45 +00:00
|
|
|
struct greybus_device {
|
|
|
|
struct device dev;
|
2014-09-01 21:39:49 +00:00
|
|
|
u16 module_number;
|
2014-09-01 20:42:43 +00:00
|
|
|
struct greybus_descriptor_function function;
|
|
|
|
struct greybus_descriptor_module_id module_id;
|
|
|
|
struct greybus_descriptor_serial_number serial_number;
|
2014-09-01 23:03:31 +00:00
|
|
|
int num_cports;
|
|
|
|
int num_strings;
|
|
|
|
struct gdev_cport *cport[MAX_CPORTS_PER_MODULE];
|
|
|
|
struct gdev_string *string[MAX_STRINGS_PER_MODULE];
|
2014-08-30 23:20:22 +00:00
|
|
|
|
|
|
|
struct gb_i2c_device *gb_i2c_dev;
|
|
|
|
struct gb_gpio_device *gb_gpio_dev;
|
|
|
|
struct gb_sdio_host *gb_sdio_host;
|
|
|
|
struct gb_tty *gb_tty;
|
|
|
|
struct gb_usb_device *gb_usb_dev;
|
2014-08-11 07:30:45 +00:00
|
|
|
};
|
|
|
|
#define to_greybus_device(d) container_of(d, struct greybus_device, dev)
|
|
|
|
|
2014-08-11 11:03:20 +00:00
|
|
|
struct gbuf *greybus_alloc_gbuf(struct greybus_device *gdev,
|
2014-09-01 23:03:31 +00:00
|
|
|
struct gdev_cport *cport,
|
2014-08-11 11:03:20 +00:00
|
|
|
gfp_t mem_flags);
|
|
|
|
void greybus_free_gbuf(struct gbuf *gbuf);
|
|
|
|
|
|
|
|
int greybus_submit_gbuf(struct gbuf *gbuf, gfp_t mem_flags);
|
|
|
|
int greybus_kill_gbuf(struct gbuf *gbuf);
|
|
|
|
|
|
|
|
|
2014-08-11 07:30:45 +00:00
|
|
|
struct greybus_driver {
|
|
|
|
const char *name;
|
|
|
|
|
2014-08-11 09:27:07 +00:00
|
|
|
int (*probe)(struct greybus_device *gdev,
|
2014-09-01 20:31:31 +00:00
|
|
|
const struct greybus_module_id *id);
|
2014-08-11 09:27:07 +00:00
|
|
|
void (*disconnect)(struct greybus_device *gdev);
|
2014-08-11 07:30:45 +00:00
|
|
|
|
2014-08-11 09:27:07 +00:00
|
|
|
int (*suspend)(struct greybus_device *gdev, pm_message_t message);
|
|
|
|
int (*resume)(struct greybus_device *gdev);
|
2014-08-11 07:30:45 +00:00
|
|
|
|
2014-09-01 20:31:31 +00:00
|
|
|
const struct greybus_module_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)
|
|
|
|
|
|
|
|
static inline void greybus_set_drvdata(struct greybus_device *gdev, void *data)
|
|
|
|
{
|
2014-08-11 09:27:07 +00:00
|
|
|
dev_set_drvdata(&gdev->dev, data);
|
2014-08-11 07:30:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *greybus_get_drvdata(struct greybus_device *gdev)
|
|
|
|
{
|
2014-08-11 09:27:07 +00:00
|
|
|
return dev_get_drvdata(&gdev->dev);
|
2014-08-11 07:30:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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-09-02 01:34:28 +00:00
|
|
|
struct greybus_device *greybus_new_device(struct device *parent,
|
|
|
|
int module_number, u8 *data,
|
|
|
|
int size);
|
|
|
|
void greybus_remove_device(struct greybus_device *gdev);
|
2014-08-31 23:17:04 +00:00
|
|
|
|
2014-09-02 02:01:14 +00:00
|
|
|
const u8 *greybus_string(struct greybus_device *gdev, int id);
|
2014-09-02 01:57:42 +00:00
|
|
|
|
2014-08-31 23:17:04 +00:00
|
|
|
/* Internal functions to gb module, move to internal .h file eventually. */
|
|
|
|
|
|
|
|
int gb_new_ap_msg(u8 *data, int length);
|
|
|
|
int gb_thread_init(void);
|
|
|
|
void gb_thread_destroy(void);
|
|
|
|
int gb_debugfs_init(void);
|
|
|
|
void gb_debugfs_cleanup(void);
|
|
|
|
|
2014-09-02 02:05:54 +00:00
|
|
|
extern const struct attribute_group *greybus_module_groups[];
|
|
|
|
|
2014-09-01 16:51:51 +00:00
|
|
|
/*
|
|
|
|
* Because we are allocating a data structure per "type" in the greybus device,
|
|
|
|
* we have static functions for this, not "dynamic" drivers like we really
|
|
|
|
* should in the end.
|
|
|
|
*/
|
2014-09-01 20:31:31 +00:00
|
|
|
int gb_i2c_probe(struct greybus_device *gdev, const struct greybus_module_id *id);
|
2014-09-01 16:51:51 +00:00
|
|
|
void gb_i2c_disconnect(struct greybus_device *gdev);
|
2014-09-01 20:31:31 +00:00
|
|
|
int gb_gpio_probe(struct greybus_device *gdev, const struct greybus_module_id *id);
|
2014-09-01 16:51:51 +00:00
|
|
|
void gb_gpio_disconnect(struct greybus_device *gdev);
|
2014-09-01 20:31:31 +00:00
|
|
|
int gb_sdio_probe(struct greybus_device *gdev, const struct greybus_module_id *id);
|
2014-09-01 16:51:51 +00:00
|
|
|
void gb_sdio_disconnect(struct greybus_device *gdev);
|
2014-09-01 20:31:31 +00:00
|
|
|
int gb_tty_probe(struct greybus_device *gdev, const struct greybus_module_id *id);
|
2014-09-01 16:51:51 +00:00
|
|
|
void gb_tty_disconnect(struct greybus_device *gdev);
|
|
|
|
|
|
|
|
int gb_tty_init(void);
|
|
|
|
void gb_tty_exit(void);
|
|
|
|
|
2014-08-31 23:17:04 +00:00
|
|
|
|
2014-08-11 07:30:45 +00:00
|
|
|
|
|
|
|
#endif /* __KERNEL__ */
|
|
|
|
#endif /* __LINUX_GREYBUS_H */
|