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. |
Arun KS | 0438976 | 2017-01-16 14:39:52 +0530 | [diff] [blame] | 52 | * @pdev: platform device to interface with SSR driver. |
Abhimanyu Kapur | c75b2e1 | 2016-02-22 18:15:13 -0800 | [diff] [blame] | 53 | * @id: id of the external device. |
| 54 | * @owner: owner of the device. |
| 55 | * @clink_ops: control operations for the control link |
| 56 | * @req_eng: handle for request engine. |
| 57 | * @cmd_eng: handle for command engine. |
| 58 | * @clink_data: private data of esoc control link. |
| 59 | * @compat_data: compat data of esoc driver. |
| 60 | * @subsys_desc: descriptor for subsystem restart |
| 61 | * @subsys_dev: ssr device handle. |
| 62 | * @np: device tree node for esoc_clink. |
Arun KS | 0cb73fd | 2017-01-16 17:47:03 +0530 | [diff] [blame] | 63 | * @auto_boot: boots independently. |
| 64 | * @primary: primary esoc controls(reset/poweroff) all secondary |
| 65 | * esocs, but not otherway around. |
Arun KS | 35fa160 | 2017-03-02 18:12:54 +0530 | [diff] [blame] | 66 | * @statusline_not_a_powersource: True if status line to esoc is not a |
| 67 | * power source. |
| 68 | * @userspace_handle_shutdown: True if user space handles shutdown requests. |
Abhimanyu Kapur | c75b2e1 | 2016-02-22 18:15:13 -0800 | [diff] [blame] | 69 | */ |
| 70 | struct esoc_clink { |
| 71 | const char *name; |
| 72 | const char *link_name; |
Satya Durga Srinivasu Prabhala | b8a2a4e | 2017-03-14 16:51:50 -0700 | [diff] [blame] | 73 | const char *link_info; |
Abhimanyu Kapur | c75b2e1 | 2016-02-22 18:15:13 -0800 | [diff] [blame] | 74 | struct device *parent; |
| 75 | struct device dev; |
Arun KS | 0438976 | 2017-01-16 14:39:52 +0530 | [diff] [blame] | 76 | struct platform_device *pdev; |
Abhimanyu Kapur | c75b2e1 | 2016-02-22 18:15:13 -0800 | [diff] [blame] | 77 | unsigned int id; |
| 78 | struct module *owner; |
| 79 | const struct esoc_clink_ops *clink_ops; |
| 80 | struct esoc_eng *req_eng; |
| 81 | struct esoc_eng *cmd_eng; |
| 82 | spinlock_t notify_lock; |
| 83 | void *clink_data; |
| 84 | void *compat_data; |
| 85 | struct subsys_desc subsys; |
| 86 | struct subsys_device *subsys_dev; |
| 87 | struct device_node *np; |
Arun KS | 0cb73fd | 2017-01-16 17:47:03 +0530 | [diff] [blame] | 88 | bool auto_boot; |
| 89 | bool primary; |
Arun KS | 35fa160 | 2017-03-02 18:12:54 +0530 | [diff] [blame] | 90 | bool statusline_not_a_powersource; |
| 91 | bool userspace_handle_shutdown; |
Abhimanyu Kapur | c75b2e1 | 2016-02-22 18:15:13 -0800 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | /** |
| 95 | * struct esoc_clink_ops: Operations to control external soc |
| 96 | * @cmd_exe: Execute control command |
| 97 | * @get_status: Get current status, or response to previous command |
Arun KS | 55b33a4 | 2017-01-16 15:27:48 +0530 | [diff] [blame] | 98 | * @get_err_fatal: Get status of err fatal signal |
Abhimanyu Kapur | c75b2e1 | 2016-02-22 18:15:13 -0800 | [diff] [blame] | 99 | * @notify_esoc: notify external soc of events |
| 100 | */ |
| 101 | struct esoc_clink_ops { |
| 102 | int (*cmd_exe)(enum esoc_cmd cmd, struct esoc_clink *dev); |
Arun KS | 55b33a4 | 2017-01-16 15:27:48 +0530 | [diff] [blame] | 103 | void (*get_status)(u32 *status, struct esoc_clink *dev); |
| 104 | void (*get_err_fatal)(u32 *status, struct esoc_clink *dev); |
Abhimanyu Kapur | c75b2e1 | 2016-02-22 18:15:13 -0800 | [diff] [blame] | 105 | void (*notify)(enum esoc_notify notify, struct esoc_clink *dev); |
| 106 | }; |
| 107 | |
| 108 | /** |
| 109 | * struct esoc_compat: Compatibility of esoc drivers. |
| 110 | * @name: esoc link that driver is compatible with. |
| 111 | * @data: driver data associated with esoc clink. |
| 112 | */ |
| 113 | struct esoc_compat { |
| 114 | const char *name; |
| 115 | void *data; |
| 116 | }; |
| 117 | |
| 118 | /** |
| 119 | * struct esoc_drv: Driver for an esoc clink |
| 120 | * @driver: drivers for esoc. |
| 121 | * @owner: module owner of esoc driver. |
| 122 | * @compat_table: compatible table for driver. |
| 123 | * @compat_entries |
| 124 | * @probe: probe function for esoc driver. |
| 125 | */ |
| 126 | struct esoc_drv { |
| 127 | struct device_driver driver; |
| 128 | struct module *owner; |
| 129 | struct esoc_compat *compat_table; |
| 130 | unsigned int compat_entries; |
| 131 | int (*probe)(struct esoc_clink *esoc_clink, |
| 132 | struct esoc_drv *drv); |
| 133 | }; |
| 134 | |
| 135 | #define to_esoc_clink(d) container_of(d, struct esoc_clink, dev) |
| 136 | #define to_esoc_drv(d) container_of(d, struct esoc_drv, driver) |
| 137 | |
| 138 | extern struct bus_type esoc_bus_type; |
| 139 | |
| 140 | |
| 141 | /* Exported apis */ |
| 142 | void esoc_dev_exit(void); |
| 143 | int esoc_dev_init(void); |
| 144 | void esoc_clink_unregister(struct esoc_clink *esoc_dev); |
| 145 | int esoc_clink_register(struct esoc_clink *esoc_dev); |
| 146 | struct esoc_clink *get_esoc_clink(int id); |
| 147 | struct esoc_clink *get_esoc_clink_by_node(struct device_node *node); |
| 148 | void put_esoc_clink(struct esoc_clink *esoc_clink); |
| 149 | void *get_esoc_clink_data(struct esoc_clink *esoc); |
| 150 | void set_esoc_clink_data(struct esoc_clink *esoc, void *data); |
| 151 | void esoc_clink_evt_notify(enum esoc_evt, struct esoc_clink *esoc_dev); |
| 152 | void esoc_clink_queue_request(enum esoc_req req, struct esoc_clink *esoc_dev); |
| 153 | void esoc_for_each_dev(void *data, int (*fn)(struct device *dev, |
| 154 | void *data)); |
| 155 | int esoc_clink_register_cmd_eng(struct esoc_clink *esoc_clink, |
| 156 | struct esoc_eng *eng); |
| 157 | void esoc_clink_unregister_cmd_eng(struct esoc_clink *esoc_clink, |
| 158 | struct esoc_eng *eng); |
| 159 | int esoc_clink_register_req_eng(struct esoc_clink *esoc_clink, |
| 160 | struct esoc_eng *eng); |
| 161 | void esoc_clink_unregister_req_eng(struct esoc_clink *esoc_clink, |
| 162 | struct esoc_eng *eng); |
| 163 | int esoc_drv_register(struct esoc_drv *driver); |
| 164 | void esoc_set_drv_data(struct esoc_clink *esoc_clink, void *data); |
| 165 | void *esoc_get_drv_data(struct esoc_clink *esoc_clink); |
| 166 | /* ssr operations */ |
| 167 | int esoc_clink_register_ssr(struct esoc_clink *esoc_clink); |
| 168 | int esoc_clink_request_ssr(struct esoc_clink *esoc_clink); |
| 169 | void esoc_clink_unregister_ssr(struct esoc_clink *esoc_clink); |
| 170 | /* client notification */ |
| 171 | #ifdef CONFIG_ESOC_CLIENT |
| 172 | void notify_esoc_clients(struct esoc_clink *esoc_clink, unsigned long evt); |
| 173 | #else |
| 174 | static inline void notify_esoc_clients(struct esoc_clink *esoc_clink, |
| 175 | unsigned long evt) |
| 176 | { |
| 177 | } |
| 178 | #endif |
| 179 | bool esoc_req_eng_enabled(struct esoc_clink *esoc_clink); |
| 180 | bool esoc_cmd_eng_enabled(struct esoc_clink *esoc_clink); |
| 181 | #endif |