blob: aeed98a683becba189bf18495c68bd58a6ba6be5 [file] [log] [blame]
Sagar Dharia3648e782017-12-11 23:42:57 +00001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (c) 2011-2017, The Linux Foundation
4 */
5
6#ifndef _LINUX_SLIMBUS_H
7#define _LINUX_SLIMBUS_H
8#include <linux/device.h>
9#include <linux/module.h>
10#include <linux/mod_devicetable.h>
11
12extern struct bus_type slimbus_bus;
13
14/**
15 * struct slim_eaddr - Enumeration address for a SLIMbus device
16 * @manf_id: Manufacturer Id for the device
17 * @prod_code: Product code
18 * @dev_index: Device index
19 * @instance: Instance value
20 */
21struct slim_eaddr {
22 u16 manf_id;
23 u16 prod_code;
24 u8 dev_index;
25 u8 instance;
26} __packed;
27
28/**
29 * enum slim_device_status - slim device status
30 * @SLIM_DEVICE_STATUS_DOWN: Slim device is absent or not reported yet.
31 * @SLIM_DEVICE_STATUS_UP: Slim device is announced on the bus.
32 * @SLIM_DEVICE_STATUS_RESERVED: Reserved for future use.
33 */
34enum slim_device_status {
35 SLIM_DEVICE_STATUS_DOWN = 0,
36 SLIM_DEVICE_STATUS_UP,
37 SLIM_DEVICE_STATUS_RESERVED,
38};
39
Sagar Dharia46a2bb52017-12-11 23:42:58 +000040struct slim_controller;
41
Sagar Dharia3648e782017-12-11 23:42:57 +000042/**
43 * struct slim_device - Slim device handle.
44 * @dev: Driver model representation of the device.
45 * @e_addr: Enumeration address of this device.
46 * @status: slim device status
Sagar Dharia46a2bb52017-12-11 23:42:58 +000047 * @ctrl: slim controller instance.
Sagar Dharia3648e782017-12-11 23:42:57 +000048 * @laddr: 1-byte Logical address of this device.
49 * @is_laddr_valid: indicates if the laddr is valid or not
50 *
51 * This is the client/device handle returned when a SLIMbus
52 * device is registered with a controller.
53 * Pointer to this structure is used by client-driver as a handle.
54 */
55struct slim_device {
56 struct device dev;
57 struct slim_eaddr e_addr;
Sagar Dharia46a2bb52017-12-11 23:42:58 +000058 struct slim_controller *ctrl;
Sagar Dharia3648e782017-12-11 23:42:57 +000059 enum slim_device_status status;
60 u8 laddr;
61 bool is_laddr_valid;
62};
63
64#define to_slim_device(d) container_of(d, struct slim_device, dev)
65
66/**
67 * struct slim_driver - SLIMbus 'generic device' (slave) device driver
68 * (similar to 'spi_device' on SPI)
69 * @probe: Binds this driver to a SLIMbus device.
70 * @remove: Unbinds this driver from the SLIMbus device.
71 * @shutdown: Standard shutdown callback used during powerdown/halt.
72 * @device_status: This callback is called when
73 * - The device reports present and gets a laddr assigned
74 * - The device reports absent, or the bus goes down.
75 * @driver: SLIMbus device drivers should initialize name and owner field of
76 * this structure
77 * @id_table: List of SLIMbus devices supported by this driver
78 */
79
80struct slim_driver {
81 int (*probe)(struct slim_device *sl);
82 void (*remove)(struct slim_device *sl);
83 void (*shutdown)(struct slim_device *sl);
84 int (*device_status)(struct slim_device *sl,
85 enum slim_device_status s);
86 struct device_driver driver;
87 const struct slim_device_id *id_table;
88};
89#define to_slim_driver(d) container_of(d, struct slim_driver, driver)
90
91/*
92 * use a macro to avoid include chaining to get THIS_MODULE
93 */
94#define slim_driver_register(drv) \
95 __slim_driver_register(drv, THIS_MODULE)
96int __slim_driver_register(struct slim_driver *drv, struct module *owner);
97void slim_driver_unregister(struct slim_driver *drv);
98
99/**
100 * module_slim_driver() - Helper macro for registering a SLIMbus driver
101 * @__slim_driver: slimbus_driver struct
102 *
103 * Helper macro for SLIMbus drivers which do not do anything special in module
104 * init/exit. This eliminates a lot of boilerplate. Each module may only
105 * use this macro once, and calling it replaces module_init() and module_exit()
106 */
107#define module_slim_driver(__slim_driver) \
108 module_driver(__slim_driver, slim_driver_register, \
109 slim_driver_unregister)
110
111static inline void *slim_get_devicedata(const struct slim_device *dev)
112{
113 return dev_get_drvdata(&dev->dev);
114}
115
116static inline void slim_set_devicedata(struct slim_device *dev, void *data)
117{
118 dev_set_drvdata(&dev->dev, data);
119}
Sagar Dharia46a2bb52017-12-11 23:42:58 +0000120
121struct slim_device *slim_get_device(struct slim_controller *ctrl,
122 struct slim_eaddr *e_addr);
123int slim_get_logical_addr(struct slim_device *sbdev);
Sagar Dharia3648e782017-12-11 23:42:57 +0000124#endif /* _LINUX_SLIMBUS_H */