blob: 9fc319253a8f508b92ba0f92c4353806985c5324 [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.
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 */
63struct esoc_clink {
64 const char *name;
65 const char *link_name;
Satya Durga Srinivasu Prabhalab8a2a4e2017-03-14 16:51:50 -070066 const char *link_info;
Abhimanyu Kapurc75b2e12016-02-22 18:15:13 -080067 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 */
88struct 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 */
99struct 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 */
112struct 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
124extern struct bus_type esoc_bus_type;
125
126
127/* Exported apis */
128void esoc_dev_exit(void);
129int esoc_dev_init(void);
130void esoc_clink_unregister(struct esoc_clink *esoc_dev);
131int esoc_clink_register(struct esoc_clink *esoc_dev);
132struct esoc_clink *get_esoc_clink(int id);
133struct esoc_clink *get_esoc_clink_by_node(struct device_node *node);
134void put_esoc_clink(struct esoc_clink *esoc_clink);
135void *get_esoc_clink_data(struct esoc_clink *esoc);
136void set_esoc_clink_data(struct esoc_clink *esoc, void *data);
137void esoc_clink_evt_notify(enum esoc_evt, struct esoc_clink *esoc_dev);
138void esoc_clink_queue_request(enum esoc_req req, struct esoc_clink *esoc_dev);
139void esoc_for_each_dev(void *data, int (*fn)(struct device *dev,
140 void *data));
141int esoc_clink_register_cmd_eng(struct esoc_clink *esoc_clink,
142 struct esoc_eng *eng);
143void esoc_clink_unregister_cmd_eng(struct esoc_clink *esoc_clink,
144 struct esoc_eng *eng);
145int esoc_clink_register_req_eng(struct esoc_clink *esoc_clink,
146 struct esoc_eng *eng);
147void esoc_clink_unregister_req_eng(struct esoc_clink *esoc_clink,
148 struct esoc_eng *eng);
149int esoc_drv_register(struct esoc_drv *driver);
150void esoc_set_drv_data(struct esoc_clink *esoc_clink, void *data);
151void *esoc_get_drv_data(struct esoc_clink *esoc_clink);
152/* ssr operations */
153int esoc_clink_register_ssr(struct esoc_clink *esoc_clink);
154int esoc_clink_request_ssr(struct esoc_clink *esoc_clink);
155void esoc_clink_unregister_ssr(struct esoc_clink *esoc_clink);
156/* client notification */
157#ifdef CONFIG_ESOC_CLIENT
158void notify_esoc_clients(struct esoc_clink *esoc_clink, unsigned long evt);
159#else
160static inline void notify_esoc_clients(struct esoc_clink *esoc_clink,
161 unsigned long evt)
162{
163}
164#endif
165bool esoc_req_eng_enabled(struct esoc_clink *esoc_clink);
166bool esoc_cmd_eng_enabled(struct esoc_clink *esoc_clink);
167#endif