blob: f878453b31c92d6add36a827be6317618a022913 [file] [log] [blame]
Greg Kroah-Hartmanc8a797a2014-08-11 15:30:45 +08001/*
2 * Greybus driver and device API
3 *
4 * Copyright 2014 Google Inc.
5 *
6 * Released under the GPLv2 only.
7 */
8
9#ifndef __LINUX_GREYBUS_H
10#define __LINUX_GREYBUS_H
11
12#ifdef __KERNEL__
13
14#include <linux/list.h>
15#include <linux/device.h>
16#include <linux/module.h>
17#include "greybus_id.h"
18
19
20#define GREYBUS_DEVICE_ID_MATCH_DEVICE \
21 (GREYBUS_DEVICE_ID_MATCH_VENDOR | GREYBUS_DEVICE_ID_MATCH_PRODUCT)
22
23#define GREYBUS_DEVICE(vendor, product) \
24 .match_flags = GREYBUS_DEVICE_ID_MATCH_DEVICE, \
25 .wVendor = (vendor), \
26 .wProduct = (product),
27
28#define GREYBUS_DEVICE_SERIAL(serial) \
29 .match_flags = GREYBUS_DEVICE_ID_MATCH_SERIAL, \
30 .lSerial = (serial),
31
Greg Kroah-Hartmanc8a797a2014-08-11 15:30:45 +080032struct greybus_descriptor {
33 __u16 wVendor;
34 __u16 wProduct;
35 __u64 lSerialNumber;
36};
37
Greg Kroah-Hartmand5d19032014-08-11 19:03:20 +080038
39struct gbuf;
40
41struct cport {
42 u16 number;
43 // FIXME, what else?
44};
45
46typedef void (*gbuf_complete_t)(struct gbuf *gbuf);
47
48struct gbuf {
49 struct kref kref;
50 void *hcpriv;
51
52 struct list_head anchor_list;
53 struct gbuf_anchor *anchor; // FIXME do we need?
54
55 struct greybus_device *gdev;
56 struct cport *cport;
57 int status;
58 void *transfer_buffer;
59 u32 transfer_flags; /* flags for the transfer buffer */
60 u32 transfer_buffer_length;
61 u32 actual_length;
62
63 struct scatterlist *sg; // FIXME do we need?
64 int num_sgs;
65
66 void *context;
67 gbuf_complete_t complete;
68};
69
70/*
71 * gbuf->transfer_flags
72 */
73#define GBUF_FREE_BUFFER BIT(0) /* Free the transfer buffer with the gbuf */
74
Greg Kroah-Hartman199d68d2014-08-30 16:20:22 -070075/* For SP1 hardware, we are going to "hardcode" each device to have all logical
76 * blocks in order to be able to address them as one unified "unit". Then
77 * higher up layers will then be able to talk to them as one logical block and
78 * properly know how they are hooked together (i.e. which i2c port is on the
79 * same module as the gpio pins, etc.)
80 *
81 * So, put the "private" data structures here in greybus.h and link to them off
82 * of the "main" greybus_device structure.
83 */
84
85struct gb_i2c_device;
86struct gb_gpio_device;
87struct gb_sdio_host;
88struct gb_tty;
89struct gb_usb_device;
Greg Kroah-Hartmand5d19032014-08-11 19:03:20 +080090
Greg Kroah-Hartmanc8a797a2014-08-11 15:30:45 +080091struct greybus_device {
92 struct device dev;
93 struct greybus_descriptor descriptor;
Greg Kroah-Hartmand5d19032014-08-11 19:03:20 +080094 int num_cport;
95 struct cport cport[0];
Greg Kroah-Hartman199d68d2014-08-30 16:20:22 -070096
97 struct gb_i2c_device *gb_i2c_dev;
98 struct gb_gpio_device *gb_gpio_dev;
99 struct gb_sdio_host *gb_sdio_host;
100 struct gb_tty *gb_tty;
101 struct gb_usb_device *gb_usb_dev;
Greg Kroah-Hartmanc8a797a2014-08-11 15:30:45 +0800102};
103#define to_greybus_device(d) container_of(d, struct greybus_device, dev)
104
Greg Kroah-Hartmand5d19032014-08-11 19:03:20 +0800105struct gbuf *greybus_alloc_gbuf(struct greybus_device *gdev,
106 struct cport *cport,
107 gfp_t mem_flags);
108void greybus_free_gbuf(struct gbuf *gbuf);
109
110int greybus_submit_gbuf(struct gbuf *gbuf, gfp_t mem_flags);
111int greybus_kill_gbuf(struct gbuf *gbuf);
112
113
Greg Kroah-Hartmanc8a797a2014-08-11 15:30:45 +0800114struct greybus_driver {
115 const char *name;
116
Greg Kroah-Hartman776f1362014-08-11 17:27:07 +0800117 int (*probe)(struct greybus_device *gdev,
118 const struct greybus_device_id *id);
119 void (*disconnect)(struct greybus_device *gdev);
Greg Kroah-Hartmanc8a797a2014-08-11 15:30:45 +0800120
Greg Kroah-Hartman776f1362014-08-11 17:27:07 +0800121 int (*suspend)(struct greybus_device *gdev, pm_message_t message);
122 int (*resume)(struct greybus_device *gdev);
Greg Kroah-Hartmanc8a797a2014-08-11 15:30:45 +0800123
124 const struct greybus_device_id *id_table;
125
126 struct device_driver driver;
127};
128#define to_greybus_driver(d) container_of(d, struct greybus_driver, driver)
129
130static inline void greybus_set_drvdata(struct greybus_device *gdev, void *data)
131{
Greg Kroah-Hartman776f1362014-08-11 17:27:07 +0800132 dev_set_drvdata(&gdev->dev, data);
Greg Kroah-Hartmanc8a797a2014-08-11 15:30:45 +0800133}
134
135static inline void *greybus_get_drvdata(struct greybus_device *gdev)
136{
Greg Kroah-Hartman776f1362014-08-11 17:27:07 +0800137 return dev_get_drvdata(&gdev->dev);
Greg Kroah-Hartmanc8a797a2014-08-11 15:30:45 +0800138}
139
140/* Don't call these directly, use the module_greybus_driver() macro instead */
141int greybus_register_driver(struct greybus_driver *driver,
142 struct module *module, const char *mod_name);
143void greybus_deregister(struct greybus_driver *driver);
144
145/* define to get proper THIS_MODULE and KBUILD_MODNAME values */
146#define greybus_register(driver) \
147 greybus_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
148
149/**
150 * module_greybus_driver() - Helper macro for registering a Greybus driver
151 * @__greybus_driver: greybus_driver structure
152 *
153 * Helper macro for Greybus drivers to set up proper module init / exit
154 * functions. Replaces module_init() and module_exit() and keeps people from
155 * printing pointless things to the kernel log when their driver is loaded.
156 */
157#define module_greybus_driver(__greybus_driver) \
158 module_driver(__greybus_driver, greybus_register, greybus_deregister)
159
Greg Kroah-Hartmanc8a797a2014-08-11 15:30:45 +0800160int greybus_disabled(void);
161
Greg Kroah-Hartmande536e32014-08-31 16:17:04 -0700162
163/* Internal functions to gb module, move to internal .h file eventually. */
164
165int gb_new_ap_msg(u8 *data, int length);
166int gb_thread_init(void);
167void gb_thread_destroy(void);
168int gb_debugfs_init(void);
169void gb_debugfs_cleanup(void);
170
Greg Kroah-Hartman712d6592014-09-01 09:51:51 -0700171/*
172 * Because we are allocating a data structure per "type" in the greybus device,
173 * we have static functions for this, not "dynamic" drivers like we really
174 * should in the end.
175 */
176int gb_i2c_probe(struct greybus_device *gdev, const struct greybus_device_id *id);
177void gb_i2c_disconnect(struct greybus_device *gdev);
178int gb_gpio_probe(struct greybus_device *gdev, const struct greybus_device_id *id);
179void gb_gpio_disconnect(struct greybus_device *gdev);
180int gb_sdio_probe(struct greybus_device *gdev, const struct greybus_device_id *id);
181void gb_sdio_disconnect(struct greybus_device *gdev);
182int gb_tty_probe(struct greybus_device *gdev, const struct greybus_device_id *id);
183void gb_tty_disconnect(struct greybus_device *gdev);
184
185int gb_tty_init(void);
186void gb_tty_exit(void);
187
Greg Kroah-Hartmande536e32014-08-31 16:17:04 -0700188
Greg Kroah-Hartmanc8a797a2014-08-11 15:30:45 +0800189
190#endif /* __KERNEL__ */
191#endif /* __LINUX_GREYBUS_H */