blob: df3c9dfab60d9781f1372ce96c0ed9150e483401 [file] [log] [blame]
Satya Durga Srinivasu Prabhalab8a2a4e2017-03-14 16:51:50 -07001/* Copyright (c) 2013-2015, 2017, The Linux Foundation. All rights reserved.
Abhimanyu Kapurc75b2e12016-02-22 18:15:13 -08002 *
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
30struct 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 */
37struct 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 Prabhalab8a2a4e2017-03-14 16:51:50 -070049 * @link_info: additional info about the physical link.
Abhimanyu Kapurc75b2e12016-02-22 18:15:13 -080050 * @parent: parent device.
51 * @dev: device for userspace interface.
Arun KS04389762017-01-16 14:39:52 +053052 * @pdev: platform device to interface with SSR driver.
Abhimanyu Kapurc75b2e12016-02-22 18:15:13 -080053 * @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 KS0cb73fd2017-01-16 17:47:03 +053063 * @auto_boot: boots independently.
64 * @primary: primary esoc controls(reset/poweroff) all secondary
65 * esocs, but not otherway around.
Arun KS35fa1602017-03-02 18:12:54 +053066 * @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 Kapurc75b2e12016-02-22 18:15:13 -080069 */
70struct esoc_clink {
71 const char *name;
72 const char *link_name;
Satya Durga Srinivasu Prabhalab8a2a4e2017-03-14 16:51:50 -070073 const char *link_info;
Abhimanyu Kapurc75b2e12016-02-22 18:15:13 -080074 struct device *parent;
75 struct device dev;
Arun KS04389762017-01-16 14:39:52 +053076 struct platform_device *pdev;
Abhimanyu Kapurc75b2e12016-02-22 18:15:13 -080077 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 KS0cb73fd2017-01-16 17:47:03 +053088 bool auto_boot;
89 bool primary;
Arun KS35fa1602017-03-02 18:12:54 +053090 bool statusline_not_a_powersource;
91 bool userspace_handle_shutdown;
Abhimanyu Kapurc75b2e12016-02-22 18:15:13 -080092};
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 KS55b33a42017-01-16 15:27:48 +053098 * @get_err_fatal: Get status of err fatal signal
Abhimanyu Kapurc75b2e12016-02-22 18:15:13 -080099 * @notify_esoc: notify external soc of events
100 */
101struct esoc_clink_ops {
102 int (*cmd_exe)(enum esoc_cmd cmd, struct esoc_clink *dev);
Arun KS55b33a42017-01-16 15:27:48 +0530103 void (*get_status)(u32 *status, struct esoc_clink *dev);
104 void (*get_err_fatal)(u32 *status, struct esoc_clink *dev);
Abhimanyu Kapurc75b2e12016-02-22 18:15:13 -0800105 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 */
113struct 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 */
126struct 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
138extern struct bus_type esoc_bus_type;
139
140
141/* Exported apis */
142void esoc_dev_exit(void);
143int esoc_dev_init(void);
144void esoc_clink_unregister(struct esoc_clink *esoc_dev);
145int esoc_clink_register(struct esoc_clink *esoc_dev);
146struct esoc_clink *get_esoc_clink(int id);
147struct esoc_clink *get_esoc_clink_by_node(struct device_node *node);
148void put_esoc_clink(struct esoc_clink *esoc_clink);
149void *get_esoc_clink_data(struct esoc_clink *esoc);
150void set_esoc_clink_data(struct esoc_clink *esoc, void *data);
151void esoc_clink_evt_notify(enum esoc_evt, struct esoc_clink *esoc_dev);
152void esoc_clink_queue_request(enum esoc_req req, struct esoc_clink *esoc_dev);
153void esoc_for_each_dev(void *data, int (*fn)(struct device *dev,
154 void *data));
155int esoc_clink_register_cmd_eng(struct esoc_clink *esoc_clink,
156 struct esoc_eng *eng);
157void esoc_clink_unregister_cmd_eng(struct esoc_clink *esoc_clink,
158 struct esoc_eng *eng);
159int esoc_clink_register_req_eng(struct esoc_clink *esoc_clink,
160 struct esoc_eng *eng);
161void esoc_clink_unregister_req_eng(struct esoc_clink *esoc_clink,
162 struct esoc_eng *eng);
163int esoc_drv_register(struct esoc_drv *driver);
164void esoc_set_drv_data(struct esoc_clink *esoc_clink, void *data);
165void *esoc_get_drv_data(struct esoc_clink *esoc_clink);
166/* ssr operations */
167int esoc_clink_register_ssr(struct esoc_clink *esoc_clink);
168int esoc_clink_request_ssr(struct esoc_clink *esoc_clink);
169void esoc_clink_unregister_ssr(struct esoc_clink *esoc_clink);
170/* client notification */
171#ifdef CONFIG_ESOC_CLIENT
172void notify_esoc_clients(struct esoc_clink *esoc_clink, unsigned long evt);
173#else
174static inline void notify_esoc_clients(struct esoc_clink *esoc_clink,
175 unsigned long evt)
176{
177}
178#endif
179bool esoc_req_eng_enabled(struct esoc_clink *esoc_clink);
180bool esoc_cmd_eng_enabled(struct esoc_clink *esoc_clink);
181#endif