1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
3 * Copyright (C) 2017 Intel Deutschland GmbH
4 * Copyright (C) 2019-2020 Intel Corporation
11 #include "fw/api/soc.h"
12 #include "fw/api/commands.h"
14 void iwl_fw_runtime_init(struct iwl_fw_runtime
*fwrt
, struct iwl_trans
*trans
,
15 const struct iwl_fw
*fw
,
16 const struct iwl_fw_runtime_ops
*ops
, void *ops_ctx
,
17 struct dentry
*dbgfs_dir
)
21 memset(fwrt
, 0, sizeof(*fwrt
));
24 fwrt
->dev
= trans
->dev
;
25 fwrt
->dump
.conf
= FW_DBG_INVALID
;
27 fwrt
->ops_ctx
= ops_ctx
;
28 for (i
= 0; i
< IWL_FW_RUNTIME_DUMP_WK_NUM
; i
++) {
29 fwrt
->dump
.wks
[i
].idx
= i
;
30 INIT_DELAYED_WORK(&fwrt
->dump
.wks
[i
].wk
, iwl_fw_error_dump_wk
);
32 iwl_fwrt_dbgfs_register(fwrt
, dbgfs_dir
);
34 IWL_EXPORT_SYMBOL(iwl_fw_runtime_init
);
36 void iwl_fw_runtime_suspend(struct iwl_fw_runtime
*fwrt
)
38 iwl_fw_suspend_timestamp(fwrt
);
40 IWL_EXPORT_SYMBOL(iwl_fw_runtime_suspend
);
42 void iwl_fw_runtime_resume(struct iwl_fw_runtime
*fwrt
)
44 iwl_fw_resume_timestamp(fwrt
);
46 IWL_EXPORT_SYMBOL(iwl_fw_runtime_resume
);
48 /* set device type and latency */
49 int iwl_set_soc_latency(struct iwl_fw_runtime
*fwrt
)
51 struct iwl_soc_configuration_cmd cmd
= {};
52 struct iwl_host_cmd hcmd
= {
53 .id
= iwl_cmd_id(SOC_CONFIGURATION_CMD
, SYSTEM_GROUP
, 0),
55 .len
[0] = sizeof(cmd
),
60 * In VER_1 of this command, the discrete value is considered
61 * an integer; In VER_2, it's a bitmask. Since we have only 2
62 * values in VER_1, this is backwards-compatible with VER_2,
63 * as long as we don't set any other bits.
65 if (!fwrt
->trans
->trans_cfg
->integrated
)
66 cmd
.flags
= cpu_to_le32(SOC_CONFIG_CMD_FLAGS_DISCRETE
);
68 BUILD_BUG_ON(IWL_CFG_TRANS_LTR_DELAY_NONE
!=
69 SOC_FLAGS_LTR_APPLY_DELAY_NONE
);
70 BUILD_BUG_ON(IWL_CFG_TRANS_LTR_DELAY_200US
!=
71 SOC_FLAGS_LTR_APPLY_DELAY_200
);
72 BUILD_BUG_ON(IWL_CFG_TRANS_LTR_DELAY_2500US
!=
73 SOC_FLAGS_LTR_APPLY_DELAY_2500
);
74 BUILD_BUG_ON(IWL_CFG_TRANS_LTR_DELAY_1820US
!=
75 SOC_FLAGS_LTR_APPLY_DELAY_1820
);
77 if (fwrt
->trans
->trans_cfg
->ltr_delay
!= IWL_CFG_TRANS_LTR_DELAY_NONE
&&
78 !WARN_ON(!fwrt
->trans
->trans_cfg
->integrated
))
79 cmd
.flags
|= le32_encode_bits(fwrt
->trans
->trans_cfg
->ltr_delay
,
80 SOC_FLAGS_LTR_APPLY_DELAY_MASK
);
82 if (iwl_fw_lookup_cmd_ver(fwrt
->fw
, IWL_ALWAYS_LONG_GROUP
,
84 IWL_FW_CMD_VER_UNKNOWN
) >= 2 &&
85 fwrt
->trans
->trans_cfg
->low_latency_xtal
)
86 cmd
.flags
|= cpu_to_le32(SOC_CONFIG_CMD_FLAGS_LOW_LATENCY
);
88 cmd
.latency
= cpu_to_le32(fwrt
->trans
->trans_cfg
->xtal_latency
);
90 ret
= iwl_trans_send_cmd(fwrt
->trans
, &hcmd
);
92 IWL_ERR(fwrt
, "Failed to set soc latency: %d\n", ret
);
95 IWL_EXPORT_SYMBOL(iwl_set_soc_latency
);