Sagar Dharia | 3648e78 | 2017-12-11 23:42:57 +0000 | [diff] [blame^] | 1 | // 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 | |
| 12 | extern 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 | */ |
| 21 | struct 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 | */ |
| 34 | enum slim_device_status { |
| 35 | SLIM_DEVICE_STATUS_DOWN = 0, |
| 36 | SLIM_DEVICE_STATUS_UP, |
| 37 | SLIM_DEVICE_STATUS_RESERVED, |
| 38 | }; |
| 39 | |
| 40 | /** |
| 41 | * struct slim_device - Slim device handle. |
| 42 | * @dev: Driver model representation of the device. |
| 43 | * @e_addr: Enumeration address of this device. |
| 44 | * @status: slim device status |
| 45 | * @laddr: 1-byte Logical address of this device. |
| 46 | * @is_laddr_valid: indicates if the laddr is valid or not |
| 47 | * |
| 48 | * This is the client/device handle returned when a SLIMbus |
| 49 | * device is registered with a controller. |
| 50 | * Pointer to this structure is used by client-driver as a handle. |
| 51 | */ |
| 52 | struct slim_device { |
| 53 | struct device dev; |
| 54 | struct slim_eaddr e_addr; |
| 55 | enum slim_device_status status; |
| 56 | u8 laddr; |
| 57 | bool is_laddr_valid; |
| 58 | }; |
| 59 | |
| 60 | #define to_slim_device(d) container_of(d, struct slim_device, dev) |
| 61 | |
| 62 | /** |
| 63 | * struct slim_driver - SLIMbus 'generic device' (slave) device driver |
| 64 | * (similar to 'spi_device' on SPI) |
| 65 | * @probe: Binds this driver to a SLIMbus device. |
| 66 | * @remove: Unbinds this driver from the SLIMbus device. |
| 67 | * @shutdown: Standard shutdown callback used during powerdown/halt. |
| 68 | * @device_status: This callback is called when |
| 69 | * - The device reports present and gets a laddr assigned |
| 70 | * - The device reports absent, or the bus goes down. |
| 71 | * @driver: SLIMbus device drivers should initialize name and owner field of |
| 72 | * this structure |
| 73 | * @id_table: List of SLIMbus devices supported by this driver |
| 74 | */ |
| 75 | |
| 76 | struct slim_driver { |
| 77 | int (*probe)(struct slim_device *sl); |
| 78 | void (*remove)(struct slim_device *sl); |
| 79 | void (*shutdown)(struct slim_device *sl); |
| 80 | int (*device_status)(struct slim_device *sl, |
| 81 | enum slim_device_status s); |
| 82 | struct device_driver driver; |
| 83 | const struct slim_device_id *id_table; |
| 84 | }; |
| 85 | #define to_slim_driver(d) container_of(d, struct slim_driver, driver) |
| 86 | |
| 87 | /* |
| 88 | * use a macro to avoid include chaining to get THIS_MODULE |
| 89 | */ |
| 90 | #define slim_driver_register(drv) \ |
| 91 | __slim_driver_register(drv, THIS_MODULE) |
| 92 | int __slim_driver_register(struct slim_driver *drv, struct module *owner); |
| 93 | void slim_driver_unregister(struct slim_driver *drv); |
| 94 | |
| 95 | /** |
| 96 | * module_slim_driver() - Helper macro for registering a SLIMbus driver |
| 97 | * @__slim_driver: slimbus_driver struct |
| 98 | * |
| 99 | * Helper macro for SLIMbus drivers which do not do anything special in module |
| 100 | * init/exit. This eliminates a lot of boilerplate. Each module may only |
| 101 | * use this macro once, and calling it replaces module_init() and module_exit() |
| 102 | */ |
| 103 | #define module_slim_driver(__slim_driver) \ |
| 104 | module_driver(__slim_driver, slim_driver_register, \ |
| 105 | slim_driver_unregister) |
| 106 | |
| 107 | static inline void *slim_get_devicedata(const struct slim_device *dev) |
| 108 | { |
| 109 | return dev_get_drvdata(&dev->dev); |
| 110 | } |
| 111 | |
| 112 | static inline void slim_set_devicedata(struct slim_device *dev, void *data) |
| 113 | { |
| 114 | dev_set_drvdata(&dev->dev, data); |
| 115 | } |
| 116 | #endif /* _LINUX_SLIMBUS_H */ |