Satya Durga Srinivasu Prabhala | b8a2a4e | 2017-03-14 16:51:50 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2013-2015, 2017, The Linux Foundation. All rights reserved. |
Abhimanyu Kapur | c75b2e1 | 2016-02-22 18:15:13 -0800 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | #ifndef __ESOC_H__ |
| 13 | #define __ESOC_H__ |
| 14 | |
| 15 | #include <linux/cdev.h> |
| 16 | #include <linux/completion.h> |
| 17 | #include <linux/esoc_ctrl.h> |
| 18 | #include <linux/fs.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/platform_device.h> |
| 21 | #include <linux/slab.h> |
| 22 | #include <linux/spinlock.h> |
| 23 | #include <soc/qcom/subsystem_restart.h> |
| 24 | #include <soc/qcom/subsystem_notif.h> |
| 25 | |
| 26 | #define ESOC_DEV_MAX 4 |
| 27 | #define ESOC_NAME_LEN 20 |
| 28 | #define ESOC_LINK_LEN 20 |
| 29 | |
| 30 | struct esoc_clink; |
| 31 | /** |
| 32 | * struct esoc_eng: Engine of the esoc control link |
| 33 | * @handle_clink_req: handle incoming esoc requests. |
| 34 | * @handle_clink_evt: handle for esoc events. |
| 35 | * @esoc_clink: pointer to esoc control link. |
| 36 | */ |
| 37 | struct esoc_eng { |
| 38 | void (*handle_clink_req)(enum esoc_req req, |
| 39 | struct esoc_eng *eng); |
| 40 | void (*handle_clink_evt)(enum esoc_evt evt, |
| 41 | struct esoc_eng *eng); |
| 42 | struct esoc_clink *esoc_clink; |
| 43 | }; |
| 44 | |
| 45 | /** |
| 46 | * struct esoc_clink: Representation of external esoc device |
| 47 | * @name: Name of the external esoc. |
| 48 | * @link_name: name of the physical link. |
Satya Durga Srinivasu Prabhala | b8a2a4e | 2017-03-14 16:51:50 -0700 | [diff] [blame] | 49 | * @link_info: additional info about the physical link. |
Abhimanyu Kapur | c75b2e1 | 2016-02-22 18:15:13 -0800 | [diff] [blame] | 50 | * @parent: parent device. |
| 51 | * @dev: device for userspace interface. |
| 52 | * @id: id of the external device. |
| 53 | * @owner: owner of the device. |
| 54 | * @clink_ops: control operations for the control link |
| 55 | * @req_eng: handle for request engine. |
| 56 | * @cmd_eng: handle for command engine. |
| 57 | * @clink_data: private data of esoc control link. |
| 58 | * @compat_data: compat data of esoc driver. |
| 59 | * @subsys_desc: descriptor for subsystem restart |
| 60 | * @subsys_dev: ssr device handle. |
| 61 | * @np: device tree node for esoc_clink. |
| 62 | */ |
| 63 | struct esoc_clink { |
| 64 | const char *name; |
| 65 | const char *link_name; |
Satya Durga Srinivasu Prabhala | b8a2a4e | 2017-03-14 16:51:50 -0700 | [diff] [blame] | 66 | const char *link_info; |
Abhimanyu Kapur | c75b2e1 | 2016-02-22 18:15:13 -0800 | [diff] [blame] | 67 | struct device *parent; |
| 68 | struct device dev; |
| 69 | unsigned int id; |
| 70 | struct module *owner; |
| 71 | const struct esoc_clink_ops *clink_ops; |
| 72 | struct esoc_eng *req_eng; |
| 73 | struct esoc_eng *cmd_eng; |
| 74 | spinlock_t notify_lock; |
| 75 | void *clink_data; |
| 76 | void *compat_data; |
| 77 | struct subsys_desc subsys; |
| 78 | struct subsys_device *subsys_dev; |
| 79 | struct device_node *np; |
| 80 | }; |
| 81 | |
| 82 | /** |
| 83 | * struct esoc_clink_ops: Operations to control external soc |
| 84 | * @cmd_exe: Execute control command |
| 85 | * @get_status: Get current status, or response to previous command |
| 86 | * @notify_esoc: notify external soc of events |
| 87 | */ |
| 88 | struct esoc_clink_ops { |
| 89 | int (*cmd_exe)(enum esoc_cmd cmd, struct esoc_clink *dev); |
| 90 | int (*get_status)(u32 *status, struct esoc_clink *dev); |
| 91 | void (*notify)(enum esoc_notify notify, struct esoc_clink *dev); |
| 92 | }; |
| 93 | |
| 94 | /** |
| 95 | * struct esoc_compat: Compatibility of esoc drivers. |
| 96 | * @name: esoc link that driver is compatible with. |
| 97 | * @data: driver data associated with esoc clink. |
| 98 | */ |
| 99 | struct esoc_compat { |
| 100 | const char *name; |
| 101 | void *data; |
| 102 | }; |
| 103 | |
| 104 | /** |
| 105 | * struct esoc_drv: Driver for an esoc clink |
| 106 | * @driver: drivers for esoc. |
| 107 | * @owner: module owner of esoc driver. |
| 108 | * @compat_table: compatible table for driver. |
| 109 | * @compat_entries |
| 110 | * @probe: probe function for esoc driver. |
| 111 | */ |
| 112 | struct esoc_drv { |
| 113 | struct device_driver driver; |
| 114 | struct module *owner; |
| 115 | struct esoc_compat *compat_table; |
| 116 | unsigned int compat_entries; |
| 117 | int (*probe)(struct esoc_clink *esoc_clink, |
| 118 | struct esoc_drv *drv); |
| 119 | }; |
| 120 | |
| 121 | #define to_esoc_clink(d) container_of(d, struct esoc_clink, dev) |
| 122 | #define to_esoc_drv(d) container_of(d, struct esoc_drv, driver) |
| 123 | |
| 124 | extern struct bus_type esoc_bus_type; |
| 125 | |
| 126 | |
| 127 | /* Exported apis */ |
| 128 | void esoc_dev_exit(void); |
| 129 | int esoc_dev_init(void); |
| 130 | void esoc_clink_unregister(struct esoc_clink *esoc_dev); |
| 131 | int esoc_clink_register(struct esoc_clink *esoc_dev); |
| 132 | struct esoc_clink *get_esoc_clink(int id); |
| 133 | struct esoc_clink *get_esoc_clink_by_node(struct device_node *node); |
| 134 | void put_esoc_clink(struct esoc_clink *esoc_clink); |
| 135 | void *get_esoc_clink_data(struct esoc_clink *esoc); |
| 136 | void set_esoc_clink_data(struct esoc_clink *esoc, void *data); |
| 137 | void esoc_clink_evt_notify(enum esoc_evt, struct esoc_clink *esoc_dev); |
| 138 | void esoc_clink_queue_request(enum esoc_req req, struct esoc_clink *esoc_dev); |
| 139 | void esoc_for_each_dev(void *data, int (*fn)(struct device *dev, |
| 140 | void *data)); |
| 141 | int esoc_clink_register_cmd_eng(struct esoc_clink *esoc_clink, |
| 142 | struct esoc_eng *eng); |
| 143 | void esoc_clink_unregister_cmd_eng(struct esoc_clink *esoc_clink, |
| 144 | struct esoc_eng *eng); |
| 145 | int esoc_clink_register_req_eng(struct esoc_clink *esoc_clink, |
| 146 | struct esoc_eng *eng); |
| 147 | void esoc_clink_unregister_req_eng(struct esoc_clink *esoc_clink, |
| 148 | struct esoc_eng *eng); |
| 149 | int esoc_drv_register(struct esoc_drv *driver); |
| 150 | void esoc_set_drv_data(struct esoc_clink *esoc_clink, void *data); |
| 151 | void *esoc_get_drv_data(struct esoc_clink *esoc_clink); |
| 152 | /* ssr operations */ |
| 153 | int esoc_clink_register_ssr(struct esoc_clink *esoc_clink); |
| 154 | int esoc_clink_request_ssr(struct esoc_clink *esoc_clink); |
| 155 | void esoc_clink_unregister_ssr(struct esoc_clink *esoc_clink); |
| 156 | /* client notification */ |
| 157 | #ifdef CONFIG_ESOC_CLIENT |
| 158 | void notify_esoc_clients(struct esoc_clink *esoc_clink, unsigned long evt); |
| 159 | #else |
| 160 | static inline void notify_esoc_clients(struct esoc_clink *esoc_clink, |
| 161 | unsigned long evt) |
| 162 | { |
| 163 | } |
| 164 | #endif |
| 165 | bool esoc_req_eng_enabled(struct esoc_clink *esoc_clink); |
| 166 | bool esoc_cmd_eng_enabled(struct esoc_clink *esoc_clink); |
| 167 | #endif |