blob: 9b0b41bb2a65c1d1620bd9075084433300829b6d [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-Hartman199d68d2014-08-30 16:20:22 -0700105/*
106 * Because we are allocating a data structure per "type" in the greybus device,
107 * we have static functions for this, not "dynamic" drivers like we really
108 * should in the end.
109 */
110int gb_i2c_probe(struct greybus_device *gdev, const struct greybus_device_id *id);
111void gb_i2c_disconnect(struct greybus_device *gdev);
Greg Kroah-Hartmandb6e1fd2014-08-30 16:47:26 -0700112int gb_gpio_probe(struct greybus_device *gdev, const struct greybus_device_id *id);
113void gb_gpio_disconnect(struct greybus_device *gdev);
114int gb_sdio_probe(struct greybus_device *gdev, const struct greybus_device_id *id);
115void gb_sdio_disconnect(struct greybus_device *gdev);
116int gb_tty_probe(struct greybus_device *gdev, const struct greybus_device_id *id);
117void gb_tty_disconnect(struct greybus_device *gdev);
Greg Kroah-Hartman199d68d2014-08-30 16:20:22 -0700118
Greg Kroah-Hartmandb6e1fd2014-08-30 16:47:26 -0700119int gb_tty_init(void);
120void gb_tty_exit(void);
Greg Kroah-Hartmand5d19032014-08-11 19:03:20 +0800121
122struct gbuf *greybus_alloc_gbuf(struct greybus_device *gdev,
123 struct cport *cport,
124 gfp_t mem_flags);
125void greybus_free_gbuf(struct gbuf *gbuf);
126
127int greybus_submit_gbuf(struct gbuf *gbuf, gfp_t mem_flags);
128int greybus_kill_gbuf(struct gbuf *gbuf);
129
130
Greg Kroah-Hartmanc8a797a2014-08-11 15:30:45 +0800131struct greybus_driver {
132 const char *name;
133
Greg Kroah-Hartman776f1362014-08-11 17:27:07 +0800134 int (*probe)(struct greybus_device *gdev,
135 const struct greybus_device_id *id);
136 void (*disconnect)(struct greybus_device *gdev);
Greg Kroah-Hartmanc8a797a2014-08-11 15:30:45 +0800137
Greg Kroah-Hartman776f1362014-08-11 17:27:07 +0800138 int (*suspend)(struct greybus_device *gdev, pm_message_t message);
139 int (*resume)(struct greybus_device *gdev);
Greg Kroah-Hartmanc8a797a2014-08-11 15:30:45 +0800140
141 const struct greybus_device_id *id_table;
142
143 struct device_driver driver;
144};
145#define to_greybus_driver(d) container_of(d, struct greybus_driver, driver)
146
147static inline void greybus_set_drvdata(struct greybus_device *gdev, void *data)
148{
Greg Kroah-Hartman776f1362014-08-11 17:27:07 +0800149 dev_set_drvdata(&gdev->dev, data);
Greg Kroah-Hartmanc8a797a2014-08-11 15:30:45 +0800150}
151
152static inline void *greybus_get_drvdata(struct greybus_device *gdev)
153{
Greg Kroah-Hartman776f1362014-08-11 17:27:07 +0800154 return dev_get_drvdata(&gdev->dev);
Greg Kroah-Hartmanc8a797a2014-08-11 15:30:45 +0800155}
156
157/* Don't call these directly, use the module_greybus_driver() macro instead */
158int greybus_register_driver(struct greybus_driver *driver,
159 struct module *module, const char *mod_name);
160void greybus_deregister(struct greybus_driver *driver);
161
162/* define to get proper THIS_MODULE and KBUILD_MODNAME values */
163#define greybus_register(driver) \
164 greybus_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
165
166/**
167 * module_greybus_driver() - Helper macro for registering a Greybus driver
168 * @__greybus_driver: greybus_driver structure
169 *
170 * Helper macro for Greybus drivers to set up proper module init / exit
171 * functions. Replaces module_init() and module_exit() and keeps people from
172 * printing pointless things to the kernel log when their driver is loaded.
173 */
174#define module_greybus_driver(__greybus_driver) \
175 module_driver(__greybus_driver, greybus_register, greybus_deregister)
176
Greg Kroah-Hartmanc8a797a2014-08-11 15:30:45 +0800177int greybus_disabled(void);
178
Greg Kroah-Hartmande536e32014-08-31 16:17:04 -0700179
180/* Internal functions to gb module, move to internal .h file eventually. */
181
182int gb_new_ap_msg(u8 *data, int length);
183int gb_thread_init(void);
184void gb_thread_destroy(void);
185int gb_debugfs_init(void);
186void gb_debugfs_cleanup(void);
187
188
Greg Kroah-Hartmanc8a797a2014-08-11 15:30:45 +0800189
190#endif /* __KERNEL__ */
191#endif /* __LINUX_GREYBUS_H */