bus: mhi: core: Introduce helper function to check device state
[linux-2.6-block.git] / include / linux / mhi.h
CommitLineData
0cbf2608
MS
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
4 *
5 */
6#ifndef _MHI_H_
7#define _MHI_H_
8
9#include <linux/device.h>
10#include <linux/dma-direction.h>
11#include <linux/mutex.h>
12#include <linux/rwlock_types.h>
189ff97c 13#include <linux/skbuff.h>
0cbf2608
MS
14#include <linux/slab.h>
15#include <linux/spinlock_types.h>
16#include <linux/wait.h>
17#include <linux/workqueue.h>
18
19struct mhi_chan;
20struct mhi_event;
21struct mhi_ctxt;
22struct mhi_cmd;
23struct mhi_buf_info;
24
25/**
26 * enum mhi_callback - MHI callback
27 * @MHI_CB_IDLE: MHI entered idle state
28 * @MHI_CB_PENDING_DATA: New data available for client to process
29 * @MHI_CB_LPM_ENTER: MHI host entered low power mode
30 * @MHI_CB_LPM_EXIT: MHI host about to exit low power mode
31 * @MHI_CB_EE_RDDM: MHI device entered RDDM exec env
32 * @MHI_CB_EE_MISSION_MODE: MHI device entered Mission Mode exec env
33 * @MHI_CB_SYS_ERROR: MHI device entered error state (may recover)
34 * @MHI_CB_FATAL_ERROR: MHI device entered fatal error state
1d3173a3 35 * @MHI_CB_BW_REQ: Received a bandwidth switch request from device
0cbf2608
MS
36 */
37enum mhi_callback {
38 MHI_CB_IDLE,
39 MHI_CB_PENDING_DATA,
40 MHI_CB_LPM_ENTER,
41 MHI_CB_LPM_EXIT,
42 MHI_CB_EE_RDDM,
43 MHI_CB_EE_MISSION_MODE,
44 MHI_CB_SYS_ERROR,
45 MHI_CB_FATAL_ERROR,
1d3173a3 46 MHI_CB_BW_REQ,
0cbf2608
MS
47};
48
49/**
50 * enum mhi_flags - Transfer flags
51 * @MHI_EOB: End of buffer for bulk transfer
52 * @MHI_EOT: End of transfer
53 * @MHI_CHAIN: Linked transfer
54 */
55enum mhi_flags {
115f3251
MS
56 MHI_EOB = BIT(0),
57 MHI_EOT = BIT(1),
58 MHI_CHAIN = BIT(2),
0cbf2608
MS
59};
60
61/**
62 * enum mhi_device_type - Device types
63 * @MHI_DEVICE_XFER: Handles data transfer
64 * @MHI_DEVICE_CONTROLLER: Control device
65 */
66enum mhi_device_type {
67 MHI_DEVICE_XFER,
68 MHI_DEVICE_CONTROLLER,
69};
70
71/**
72 * enum mhi_ch_type - Channel types
73 * @MHI_CH_TYPE_INVALID: Invalid channel type
74 * @MHI_CH_TYPE_OUTBOUND: Outbound channel to the device
75 * @MHI_CH_TYPE_INBOUND: Inbound channel from the device
76 * @MHI_CH_TYPE_INBOUND_COALESCED: Coalesced channel for the device to combine
77 * multiple packets and send them as a single
78 * large packet to reduce CPU consumption
79 */
80enum mhi_ch_type {
81 MHI_CH_TYPE_INVALID = 0,
82 MHI_CH_TYPE_OUTBOUND = DMA_TO_DEVICE,
83 MHI_CH_TYPE_INBOUND = DMA_FROM_DEVICE,
84 MHI_CH_TYPE_INBOUND_COALESCED = 3,
85};
86
3000f85b 87/**
4d12a897
RD
88 * struct image_info - Firmware and RDDM table
89 * @mhi_buf: Buffer for firmware and RDDM table
90 * @entries: # of entries in table
3000f85b
MS
91 */
92struct image_info {
93 struct mhi_buf *mhi_buf;
4d12a897 94 /* private: from internal.h */
3000f85b 95 struct bhi_vec_entry *bhi_vec;
4d12a897 96 /* public: */
3000f85b
MS
97 u32 entries;
98};
99
1d3173a3
MS
100/**
101 * struct mhi_link_info - BW requirement
102 * target_link_speed - Link speed as defined by TLS bits in LinkControl reg
103 * target_link_width - Link width as defined by NLW bits in LinkStatus reg
104 */
105struct mhi_link_info {
106 unsigned int target_link_speed;
107 unsigned int target_link_width;
108};
109
0cbf2608
MS
110/**
111 * enum mhi_ee_type - Execution environment types
112 * @MHI_EE_PBL: Primary Bootloader
113 * @MHI_EE_SBL: Secondary Bootloader
114 * @MHI_EE_AMSS: Modem, aka the primary runtime EE
115 * @MHI_EE_RDDM: Ram dump download mode
116 * @MHI_EE_WFW: WLAN firmware mode
117 * @MHI_EE_PTHRU: Passthrough
118 * @MHI_EE_EDL: Embedded downloader
119 */
120enum mhi_ee_type {
121 MHI_EE_PBL,
122 MHI_EE_SBL,
123 MHI_EE_AMSS,
124 MHI_EE_RDDM,
125 MHI_EE_WFW,
126 MHI_EE_PTHRU,
127 MHI_EE_EDL,
128 MHI_EE_MAX_SUPPORTED = MHI_EE_EDL,
129 MHI_EE_DISABLE_TRANSITION, /* local EE, not related to mhi spec */
130 MHI_EE_NOT_SUPPORTED,
131 MHI_EE_MAX,
132};
133
a6e2e352
MS
134/**
135 * enum mhi_state - MHI states
136 * @MHI_STATE_RESET: Reset state
137 * @MHI_STATE_READY: Ready state
138 * @MHI_STATE_M0: M0 state
139 * @MHI_STATE_M1: M1 state
140 * @MHI_STATE_M2: M2 state
141 * @MHI_STATE_M3: M3 state
142 * @MHI_STATE_M3_FAST: M3 Fast state
143 * @MHI_STATE_BHI: BHI state
144 * @MHI_STATE_SYS_ERR: System Error state
145 */
146enum mhi_state {
147 MHI_STATE_RESET = 0x0,
148 MHI_STATE_READY = 0x1,
149 MHI_STATE_M0 = 0x2,
150 MHI_STATE_M1 = 0x3,
151 MHI_STATE_M2 = 0x4,
152 MHI_STATE_M3 = 0x5,
153 MHI_STATE_M3_FAST = 0x6,
154 MHI_STATE_BHI = 0x7,
155 MHI_STATE_SYS_ERR = 0xFF,
156 MHI_STATE_MAX,
157};
158
0cbf2608
MS
159/**
160 * enum mhi_ch_ee_mask - Execution environment mask for channel
161 * @MHI_CH_EE_PBL: Allow channel to be used in PBL EE
162 * @MHI_CH_EE_SBL: Allow channel to be used in SBL EE
163 * @MHI_CH_EE_AMSS: Allow channel to be used in AMSS EE
164 * @MHI_CH_EE_RDDM: Allow channel to be used in RDDM EE
165 * @MHI_CH_EE_PTHRU: Allow channel to be used in PTHRU EE
166 * @MHI_CH_EE_WFW: Allow channel to be used in WFW EE
167 * @MHI_CH_EE_EDL: Allow channel to be used in EDL EE
168 */
169enum mhi_ch_ee_mask {
170 MHI_CH_EE_PBL = BIT(MHI_EE_PBL),
171 MHI_CH_EE_SBL = BIT(MHI_EE_SBL),
172 MHI_CH_EE_AMSS = BIT(MHI_EE_AMSS),
173 MHI_CH_EE_RDDM = BIT(MHI_EE_RDDM),
174 MHI_CH_EE_PTHRU = BIT(MHI_EE_PTHRU),
175 MHI_CH_EE_WFW = BIT(MHI_EE_WFW),
176 MHI_CH_EE_EDL = BIT(MHI_EE_EDL),
177};
178
179/**
180 * enum mhi_er_data_type - Event ring data types
181 * @MHI_ER_DATA: Only client data over this ring
182 * @MHI_ER_CTRL: MHI control data and client data
183 */
184enum mhi_er_data_type {
185 MHI_ER_DATA,
186 MHI_ER_CTRL,
187};
188
189/**
190 * enum mhi_db_brst_mode - Doorbell mode
191 * @MHI_DB_BRST_DISABLE: Burst mode disable
192 * @MHI_DB_BRST_ENABLE: Burst mode enable
193 */
194enum mhi_db_brst_mode {
195 MHI_DB_BRST_DISABLE = 0x2,
196 MHI_DB_BRST_ENABLE = 0x3,
197};
198
199/**
200 * struct mhi_channel_config - Channel configuration structure for controller
201 * @name: The name of this channel
202 * @num: The number assigned to this channel
203 * @num_elements: The number of elements that can be queued to this channel
204 * @local_elements: The local ring length of the channel
205 * @event_ring: The event rung index that services this channel
206 * @dir: Direction that data may flow on this channel
207 * @type: Channel type
208 * @ee_mask: Execution Environment mask for this channel
209 * @pollcfg: Polling configuration for burst mode. 0 is default. milliseconds
210 for UL channels, multiple of 8 ring elements for DL channels
211 * @doorbell: Doorbell mode
212 * @lpm_notify: The channel master requires low power mode notifications
213 * @offload_channel: The client manages the channel completely
214 * @doorbell_mode_switch: Channel switches to doorbell mode on M0 transition
215 * @auto_queue: Framework will automatically queue buffers for DL traffic
216 * @auto_start: Automatically start (open) this channel
da1c4f85 217 * @wake-capable: Channel capable of waking up the system
0cbf2608
MS
218 */
219struct mhi_channel_config {
220 char *name;
221 u32 num;
222 u32 num_elements;
223 u32 local_elements;
224 u32 event_ring;
225 enum dma_data_direction dir;
226 enum mhi_ch_type type;
227 u32 ee_mask;
228 u32 pollcfg;
229 enum mhi_db_brst_mode doorbell;
230 bool lpm_notify;
231 bool offload_channel;
232 bool doorbell_mode_switch;
233 bool auto_queue;
234 bool auto_start;
da1c4f85 235 bool wake_capable;
0cbf2608
MS
236};
237
238/**
239 * struct mhi_event_config - Event ring configuration structure for controller
240 * @num_elements: The number of elements that can be queued to this ring
241 * @irq_moderation_ms: Delay irq for additional events to be aggregated
242 * @irq: IRQ associated with this ring
243 * @channel: Dedicated channel number. U32_MAX indicates a non-dedicated ring
244 * @priority: Priority of this ring. Use 1 for now
245 * @mode: Doorbell mode
246 * @data_type: Type of data this ring will process
247 * @hardware_event: This ring is associated with hardware channels
248 * @client_managed: This ring is client managed
249 * @offload_channel: This ring is associated with an offloaded channel
250 */
251struct mhi_event_config {
252 u32 num_elements;
253 u32 irq_moderation_ms;
254 u32 irq;
255 u32 channel;
256 u32 priority;
257 enum mhi_db_brst_mode mode;
258 enum mhi_er_data_type data_type;
259 bool hardware_event;
260 bool client_managed;
261 bool offload_channel;
262};
263
264/**
265 * struct mhi_controller_config - Root MHI controller configuration
266 * @max_channels: Maximum number of channels supported
267 * @timeout_ms: Timeout value for operations. 0 means use default
268 * @buf_len: Size of automatically allocated buffers. 0 means use default
269 * @num_channels: Number of channels defined in @ch_cfg
270 * @ch_cfg: Array of defined channels
271 * @num_events: Number of event rings defined in @event_cfg
272 * @event_cfg: Array of defined event rings
273 * @use_bounce_buf: Use a bounce buffer pool due to limited DDR access
274 * @m2_no_db: Host is not allowed to ring DB in M2 state
275 */
276struct mhi_controller_config {
277 u32 max_channels;
278 u32 timeout_ms;
279 u32 buf_len;
280 u32 num_channels;
281 struct mhi_channel_config *ch_cfg;
282 u32 num_events;
283 struct mhi_event_config *event_cfg;
284 bool use_bounce_buf;
285 bool m2_no_db;
286};
287
288/**
289 * struct mhi_controller - Master MHI controller structure
290 * @cntrl_dev: Pointer to the struct device of physical bus acting as the MHI
291 * controller (required)
292 * @mhi_dev: MHI device instance for the controller
293 * @regs: Base address of MHI MMIO register space (required)
6cd330ae 294 * @bhi: Points to base of MHI BHI register space
3000f85b 295 * @bhie: Points to base of MHI BHIe register space
6cd330ae 296 * @wake_db: MHI WAKE doorbell register address
0cbf2608
MS
297 * @iova_start: IOMMU starting address for data (required)
298 * @iova_stop: IOMMU stop address for data (required)
299 * @fw_image: Firmware image name for normal booting (required)
300 * @edl_image: Firmware image name for emergency download mode (optional)
6fdfdd27 301 * @rddm_size: RAM dump size that host should allocate for debugging purpose
0cbf2608
MS
302 * @sbl_size: SBL image size downloaded through BHIe (optional)
303 * @seg_len: BHIe vector size (optional)
3000f85b 304 * @fbc_image: Points to firmware image buffer
6fdfdd27 305 * @rddm_image: Points to RAM dump buffer
0cbf2608
MS
306 * @mhi_chan: Points to the channel configuration table
307 * @lpm_chans: List of channels that require LPM notifications
308 * @irq: base irq # to request (required)
309 * @max_chan: Maximum number of channels the controller supports
310 * @total_ev_rings: Total # of event rings allocated
311 * @hw_ev_rings: Number of hardware event rings
312 * @sw_ev_rings: Number of software event rings
313 * @nr_irqs_req: Number of IRQs required to operate (optional)
314 * @nr_irqs: Number of IRQ allocated by bus master (required)
3316ab2b
MS
315 * @family_number: MHI controller family number
316 * @device_number: MHI controller device number
317 * @major_version: MHI controller major revision number
318 * @minor_version: MHI controller minor revision number
0cbf2608
MS
319 * @mhi_event: MHI event ring configurations table
320 * @mhi_cmd: MHI command ring configurations table
321 * @mhi_ctxt: MHI device context, shared memory between host and device
322 * @pm_mutex: Mutex for suspend/resume operation
323 * @pm_lock: Lock for protecting MHI power management state
324 * @timeout_ms: Timeout in ms for state transitions
325 * @pm_state: MHI power management state
326 * @db_access: DB access states
327 * @ee: MHI device execution environment
a6e2e352 328 * @dev_state: MHI device state
0cbf2608
MS
329 * @dev_wake: Device wakeup count
330 * @pending_pkts: Pending packets for the controller
331 * @transition_list: List of MHI state transitions
332 * @transition_lock: Lock for protecting MHI state transition list
333 * @wlock: Lock for protecting device wakeup
1d3173a3 334 * @mhi_link_info: Device bandwidth info
0cbf2608 335 * @st_worker: State transition worker
0cbf2608
MS
336 * @state_event: State change event
337 * @status_cb: CB function to notify power states of the device (required)
0cbf2608
MS
338 * @wake_get: CB function to assert device wake (optional)
339 * @wake_put: CB function to de-assert device wake (optional)
340 * @wake_toggle: CB function to assert and de-assert device wake (optional)
341 * @runtime_get: CB function to controller runtime resume (required)
af2e5881 342 * @runtime_put: CB function to decrement pm usage (required)
189ff97c
MS
343 * @map_single: CB function to create TRE buffer
344 * @unmap_single: CB function to destroy TRE buffer
45723a44
JH
345 * @read_reg: Read a MHI register via the physical link (required)
346 * @write_reg: Write a MHI register via the physical link (required)
0cbf2608
MS
347 * @buffer_len: Bounce buffer length
348 * @bounce_buf: Use of bounce buffer
349 * @fbc_download: MHI host needs to do complete image transfer (optional)
350 * @pre_init: MHI host needs to do pre-initialization before power up
351 * @wake_set: Device wakeup set flag
352 *
353 * Fields marked as (required) need to be populated by the controller driver
354 * before calling mhi_register_controller(). For the fields marked as (optional)
355 * they can be populated depending on the usecase.
3316ab2b
MS
356 *
357 * The following fields are present for the purpose of implementing any device
358 * specific quirks or customizations for specific MHI revisions used in device
359 * by the controller drivers. The MHI stack will just populate these fields
360 * during mhi_register_controller():
361 * family_number
362 * device_number
363 * major_version
364 * minor_version
0cbf2608
MS
365 */
366struct mhi_controller {
367 struct device *cntrl_dev;
368 struct mhi_device *mhi_dev;
369 void __iomem *regs;
6cd330ae 370 void __iomem *bhi;
3000f85b 371 void __iomem *bhie;
6cd330ae 372 void __iomem *wake_db;
a6e2e352 373
0cbf2608
MS
374 dma_addr_t iova_start;
375 dma_addr_t iova_stop;
376 const char *fw_image;
377 const char *edl_image;
6fdfdd27 378 size_t rddm_size;
0cbf2608
MS
379 size_t sbl_size;
380 size_t seg_len;
3000f85b 381 struct image_info *fbc_image;
6fdfdd27 382 struct image_info *rddm_image;
0cbf2608
MS
383 struct mhi_chan *mhi_chan;
384 struct list_head lpm_chans;
385 int *irq;
386 u32 max_chan;
387 u32 total_ev_rings;
388 u32 hw_ev_rings;
389 u32 sw_ev_rings;
390 u32 nr_irqs_req;
391 u32 nr_irqs;
3316ab2b
MS
392 u32 family_number;
393 u32 device_number;
394 u32 major_version;
395 u32 minor_version;
0cbf2608
MS
396
397 struct mhi_event *mhi_event;
398 struct mhi_cmd *mhi_cmd;
399 struct mhi_ctxt *mhi_ctxt;
400
401 struct mutex pm_mutex;
402 rwlock_t pm_lock;
403 u32 timeout_ms;
404 u32 pm_state;
405 u32 db_access;
406 enum mhi_ee_type ee;
a6e2e352 407 enum mhi_state dev_state;
0cbf2608
MS
408 atomic_t dev_wake;
409 atomic_t pending_pkts;
410 struct list_head transition_list;
411 spinlock_t transition_lock;
412 spinlock_t wlock;
1d3173a3 413 struct mhi_link_info mhi_link_info;
0cbf2608 414 struct work_struct st_worker;
0cbf2608
MS
415 wait_queue_head_t state_event;
416
417 void (*status_cb)(struct mhi_controller *mhi_cntrl,
418 enum mhi_callback cb);
0cbf2608
MS
419 void (*wake_get)(struct mhi_controller *mhi_cntrl, bool override);
420 void (*wake_put)(struct mhi_controller *mhi_cntrl, bool override);
421 void (*wake_toggle)(struct mhi_controller *mhi_cntrl);
422 int (*runtime_get)(struct mhi_controller *mhi_cntrl);
423 void (*runtime_put)(struct mhi_controller *mhi_cntrl);
189ff97c
MS
424 int (*map_single)(struct mhi_controller *mhi_cntrl,
425 struct mhi_buf_info *buf);
426 void (*unmap_single)(struct mhi_controller *mhi_cntrl,
427 struct mhi_buf_info *buf);
45723a44
JH
428 int (*read_reg)(struct mhi_controller *mhi_cntrl, void __iomem *addr,
429 u32 *out);
430 void (*write_reg)(struct mhi_controller *mhi_cntrl, void __iomem *addr,
431 u32 val);
0cbf2608
MS
432
433 size_t buffer_len;
434 bool bounce_buf;
435 bool fbc_download;
436 bool pre_init;
437 bool wake_set;
438};
439
440/**
5aa93f05
BB
441 * struct mhi_device - Structure representing an MHI device which binds
442 * to channels or is associated with controllers
0cbf2608 443 * @id: Pointer to MHI device ID struct
5aa93f05 444 * @name: Name of the associated MHI device
0cbf2608
MS
445 * @mhi_cntrl: Controller the device belongs to
446 * @ul_chan: UL channel for the device
447 * @dl_chan: DL channel for the device
448 * @dev: Driver model device node for the MHI device
449 * @dev_type: MHI device type
e755cadb
MS
450 * @ul_chan_id: MHI channel id for UL transfer
451 * @dl_chan_id: MHI channel id for DL transfer
0cbf2608
MS
452 * @dev_wake: Device wakeup counter
453 */
454struct mhi_device {
455 const struct mhi_device_id *id;
5aa93f05 456 const char *name;
0cbf2608
MS
457 struct mhi_controller *mhi_cntrl;
458 struct mhi_chan *ul_chan;
459 struct mhi_chan *dl_chan;
460 struct device dev;
461 enum mhi_device_type dev_type;
e755cadb
MS
462 int ul_chan_id;
463 int dl_chan_id;
0cbf2608
MS
464 u32 dev_wake;
465};
466
467/**
468 * struct mhi_result - Completed buffer information
469 * @buf_addr: Address of data buffer
470 * @bytes_xferd: # of bytes transferred
471 * @dir: Channel direction
472 * @transaction_status: Status of last transaction
473 */
474struct mhi_result {
475 void *buf_addr;
476 size_t bytes_xferd;
477 enum dma_data_direction dir;
478 int transaction_status;
479};
480
a6e2e352
MS
481/**
482 * struct mhi_buf - MHI Buffer description
483 * @buf: Virtual address of the buffer
484 * @name: Buffer label. For offload channel, configurations name must be:
485 * ECA - Event context array data
486 * CCA - Channel context array data
487 * @dma_addr: IOMMU address of the buffer
488 * @len: # of bytes
489 */
490struct mhi_buf {
491 void *buf;
492 const char *name;
493 dma_addr_t dma_addr;
494 size_t len;
495};
496
e755cadb
MS
497/**
498 * struct mhi_driver - Structure representing a MHI client driver
499 * @probe: CB function for client driver probe function
500 * @remove: CB function for client driver remove function
501 * @ul_xfer_cb: CB function for UL data transfer
502 * @dl_xfer_cb: CB function for DL data transfer
503 * @status_cb: CB functions for asynchronous status
504 * @driver: Device driver model driver
505 */
506struct mhi_driver {
507 const struct mhi_device_id *id_table;
508 int (*probe)(struct mhi_device *mhi_dev,
509 const struct mhi_device_id *id);
510 void (*remove)(struct mhi_device *mhi_dev);
511 void (*ul_xfer_cb)(struct mhi_device *mhi_dev,
512 struct mhi_result *result);
513 void (*dl_xfer_cb)(struct mhi_device *mhi_dev,
514 struct mhi_result *result);
515 void (*status_cb)(struct mhi_device *mhi_dev, enum mhi_callback mhi_cb);
516 struct device_driver driver;
517};
518
519#define to_mhi_driver(drv) container_of(drv, struct mhi_driver, driver)
0cbf2608
MS
520#define to_mhi_device(dev) container_of(dev, struct mhi_device, dev)
521
522/**
523 * mhi_register_controller - Register MHI controller
524 * @mhi_cntrl: MHI controller to register
525 * @config: Configuration to use for the controller
526 */
527int mhi_register_controller(struct mhi_controller *mhi_cntrl,
528 struct mhi_controller_config *config);
529
530/**
531 * mhi_unregister_controller - Unregister MHI controller
532 * @mhi_cntrl: MHI controller to unregister
533 */
534void mhi_unregister_controller(struct mhi_controller *mhi_cntrl);
535
82174738
MS
536/*
537 * module_mhi_driver() - Helper macro for drivers that don't do
538 * anything special other than using default mhi_driver_register() and
539 * mhi_driver_unregister(). This eliminates a lot of boilerplate.
540 * Each module may only use this macro once.
541 */
542#define module_mhi_driver(mhi_drv) \
543 module_driver(mhi_drv, mhi_driver_register, \
544 mhi_driver_unregister)
545
546/*
547 * Macro to avoid include chaining to get THIS_MODULE
548 */
549#define mhi_driver_register(mhi_drv) \
550 __mhi_driver_register(mhi_drv, THIS_MODULE)
551
e755cadb 552/**
82174738 553 * __mhi_driver_register - Register driver with MHI framework
e755cadb 554 * @mhi_drv: Driver associated with the device
82174738 555 * @owner: The module owner
e755cadb 556 */
82174738 557int __mhi_driver_register(struct mhi_driver *mhi_drv, struct module *owner);
e755cadb
MS
558
559/**
560 * mhi_driver_unregister - Unregister a driver for mhi_devices
561 * @mhi_drv: Driver associated with the device
562 */
563void mhi_driver_unregister(struct mhi_driver *mhi_drv);
564
a6e2e352
MS
565/**
566 * mhi_set_mhi_state - Set MHI device state
567 * @mhi_cntrl: MHI controller
568 * @state: State to set
569 */
570void mhi_set_mhi_state(struct mhi_controller *mhi_cntrl,
571 enum mhi_state state);
572
0c6b20a1
MS
573/**
574 * mhi_notify - Notify the MHI client driver about client device status
575 * @mhi_dev: MHI device instance
576 * @cb_reason: MHI callback reason
577 */
578void mhi_notify(struct mhi_device *mhi_dev, enum mhi_callback cb_reason);
579
3000f85b
MS
580/**
581 * mhi_prepare_for_power_up - Do pre-initialization before power up.
582 * This is optional, call this before power up if
583 * the controller does not want bus framework to
584 * automatically free any allocated memory during
585 * shutdown process.
586 * @mhi_cntrl: MHI controller
587 */
588int mhi_prepare_for_power_up(struct mhi_controller *mhi_cntrl);
589
590/**
591 * mhi_async_power_up - Start MHI power up sequence
592 * @mhi_cntrl: MHI controller
593 */
594int mhi_async_power_up(struct mhi_controller *mhi_cntrl);
595
596/**
597 * mhi_sync_power_up - Start MHI power up sequence and wait till the device
4d12a897 598 * enters valid EE state
3000f85b
MS
599 * @mhi_cntrl: MHI controller
600 */
601int mhi_sync_power_up(struct mhi_controller *mhi_cntrl);
602
603/**
604 * mhi_power_down - Start MHI power down sequence
605 * @mhi_cntrl: MHI controller
606 * @graceful: Link is still accessible, so do a graceful shutdown process
607 */
608void mhi_power_down(struct mhi_controller *mhi_cntrl, bool graceful);
609
610/**
611 * mhi_unprepare_after_power_down - Free any allocated memory after power down
612 * @mhi_cntrl: MHI controller
613 */
614void mhi_unprepare_after_power_down(struct mhi_controller *mhi_cntrl);
0c6b20a1
MS
615
616/**
617 * mhi_pm_suspend - Move MHI into a suspended state
618 * @mhi_cntrl: MHI controller
619 */
620int mhi_pm_suspend(struct mhi_controller *mhi_cntrl);
621
622/**
623 * mhi_pm_resume - Resume MHI from suspended state
624 * @mhi_cntrl: MHI controller
625 */
626int mhi_pm_resume(struct mhi_controller *mhi_cntrl);
3000f85b 627
6fdfdd27
MS
628/**
629 * mhi_download_rddm_img - Download ramdump image from device for
630 * debugging purpose.
631 * @mhi_cntrl: MHI controller
632 * @in_panic: Download rddm image during kernel panic
633 */
634int mhi_download_rddm_img(struct mhi_controller *mhi_cntrl, bool in_panic);
635
636/**
637 * mhi_force_rddm_mode - Force device into rddm mode
638 * @mhi_cntrl: MHI controller
639 */
640int mhi_force_rddm_mode(struct mhi_controller *mhi_cntrl);
641
642/**
643 * mhi_get_mhi_state - Get MHI state of the device
644 * @mhi_cntrl: MHI controller
645 */
646enum mhi_state mhi_get_mhi_state(struct mhi_controller *mhi_cntrl);
647
189ff97c
MS
648/**
649 * mhi_device_get - Disable device low power mode
650 * @mhi_dev: Device associated with the channel
651 */
652void mhi_device_get(struct mhi_device *mhi_dev);
653
654/**
655 * mhi_device_get_sync - Disable device low power mode. Synchronously
656 * take the controller out of suspended state
657 * @mhi_dev: Device associated with the channel
658 */
659int mhi_device_get_sync(struct mhi_device *mhi_dev);
660
661/**
662 * mhi_device_put - Re-enable device low power mode
663 * @mhi_dev: Device associated with the channel
664 */
665void mhi_device_put(struct mhi_device *mhi_dev);
666
667/**
668 * mhi_prepare_for_transfer - Setup channel for data transfer
669 * @mhi_dev: Device associated with the channels
670 */
671int mhi_prepare_for_transfer(struct mhi_device *mhi_dev);
672
673/**
674 * mhi_unprepare_from_transfer - Unprepare the channels
675 * @mhi_dev: Device associated with the channels
676 */
677void mhi_unprepare_from_transfer(struct mhi_device *mhi_dev);
678
679/**
680 * mhi_poll - Poll for any available data in DL direction
681 * @mhi_dev: Device associated with the channels
682 * @budget: # of events to process
683 */
684int mhi_poll(struct mhi_device *mhi_dev, u32 budget);
685
686/**
687 * mhi_queue_dma - Send or receive DMA mapped buffers from client device
688 * over MHI channel
689 * @mhi_dev: Device associated with the channels
690 * @dir: DMA direction for the channel
691 * @mhi_buf: Buffer for holding the DMA mapped data
692 * @len: Buffer length
693 * @mflags: MHI transfer flags used for the transfer
694 */
695int mhi_queue_dma(struct mhi_device *mhi_dev, enum dma_data_direction dir,
696 struct mhi_buf *mhi_buf, size_t len, enum mhi_flags mflags);
697
698/**
699 * mhi_queue_buf - Send or receive raw buffers from client device over MHI
700 * channel
701 * @mhi_dev: Device associated with the channels
702 * @dir: DMA direction for the channel
703 * @buf: Buffer for holding the data
704 * @len: Buffer length
705 * @mflags: MHI transfer flags used for the transfer
706 */
707int mhi_queue_buf(struct mhi_device *mhi_dev, enum dma_data_direction dir,
708 void *buf, size_t len, enum mhi_flags mflags);
709
710/**
711 * mhi_queue_skb - Send or receive SKBs from client device over MHI channel
712 * @mhi_dev: Device associated with the channels
713 * @dir: DMA direction for the channel
714 * @skb: Buffer for holding SKBs
715 * @len: Buffer length
716 * @mflags: MHI transfer flags used for the transfer
717 */
718int mhi_queue_skb(struct mhi_device *mhi_dev, enum dma_data_direction dir,
719 struct sk_buff *skb, size_t len, enum mhi_flags mflags);
720
0cbf2608 721#endif /* _MHI_H_ */