xref: /linux/drivers/mfd/qcom_rpm.c (revision 0ea5c948cb64bab5bc7a5516774eb8536f05aa0d)
197fb5e8dSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
258e21438SBjorn Andersson /*
358e21438SBjorn Andersson  * Copyright (c) 2014, Sony Mobile Communications AB.
458e21438SBjorn Andersson  * Copyright (c) 2013, The Linux Foundation. All rights reserved.
558e21438SBjorn Andersson  * Author: Bjorn Andersson <bjorn.andersson@sonymobile.com>
658e21438SBjorn Andersson  */
758e21438SBjorn Andersson 
858e21438SBjorn Andersson #include <linux/module.h>
958e21438SBjorn Andersson #include <linux/platform_device.h>
10*830fafceSRob Herring #include <linux/property.h>
11*830fafceSRob Herring #include <linux/of.h>
1258e21438SBjorn Andersson #include <linux/of_platform.h>
1358e21438SBjorn Andersson #include <linux/io.h>
1458e21438SBjorn Andersson #include <linux/interrupt.h>
1558e21438SBjorn Andersson #include <linux/mfd/qcom_rpm.h>
1658e21438SBjorn Andersson #include <linux/mfd/syscon.h>
1758e21438SBjorn Andersson #include <linux/regmap.h>
1835264033SLinus Walleij #include <linux/clk.h>
1958e21438SBjorn Andersson 
2058e21438SBjorn Andersson #include <dt-bindings/mfd/qcom-rpm.h>
2158e21438SBjorn Andersson 
2258e21438SBjorn Andersson struct qcom_rpm_resource {
2358e21438SBjorn Andersson 	unsigned target_id;
2458e21438SBjorn Andersson 	unsigned status_id;
2558e21438SBjorn Andersson 	unsigned select_id;
2658e21438SBjorn Andersson 	unsigned size;
2758e21438SBjorn Andersson };
2858e21438SBjorn Andersson 
2958e21438SBjorn Andersson struct qcom_rpm_data {
3058e21438SBjorn Andersson 	u32 version;
3158e21438SBjorn Andersson 	const struct qcom_rpm_resource *resource_table;
329835f1b7SLinus Walleij 	unsigned int n_resources;
339835f1b7SLinus Walleij 	unsigned int req_ctx_off;
349835f1b7SLinus Walleij 	unsigned int req_sel_off;
359835f1b7SLinus Walleij 	unsigned int ack_ctx_off;
369835f1b7SLinus Walleij 	unsigned int ack_sel_off;
37f37be01eSLinus Walleij 	unsigned int req_sel_size;
38f37be01eSLinus Walleij 	unsigned int ack_sel_size;
3958e21438SBjorn Andersson };
4058e21438SBjorn Andersson 
4158e21438SBjorn Andersson struct qcom_rpm {
4258e21438SBjorn Andersson 	struct device *dev;
4358e21438SBjorn Andersson 	struct regmap *ipc_regmap;
4458e21438SBjorn Andersson 	unsigned ipc_offset;
4558e21438SBjorn Andersson 	unsigned ipc_bit;
4635264033SLinus Walleij 	struct clk *ramclk;
4758e21438SBjorn Andersson 
4858e21438SBjorn Andersson 	struct completion ack;
4958e21438SBjorn Andersson 	struct mutex lock;
5058e21438SBjorn Andersson 
5158e21438SBjorn Andersson 	void __iomem *status_regs;
5258e21438SBjorn Andersson 	void __iomem *ctrl_regs;
5358e21438SBjorn Andersson 	void __iomem *req_regs;
5458e21438SBjorn Andersson 
5558e21438SBjorn Andersson 	u32 ack_status;
5658e21438SBjorn Andersson 
5758e21438SBjorn Andersson 	const struct qcom_rpm_data *data;
5858e21438SBjorn Andersson };
5958e21438SBjorn Andersson 
6058e21438SBjorn Andersson #define RPM_STATUS_REG(rpm, i)	((rpm)->status_regs + (i) * 4)
6158e21438SBjorn Andersson #define RPM_CTRL_REG(rpm, i)	((rpm)->ctrl_regs + (i) * 4)
6258e21438SBjorn Andersson #define RPM_REQ_REG(rpm, i)	((rpm)->req_regs + (i) * 4)
6358e21438SBjorn Andersson 
6458e21438SBjorn Andersson #define RPM_REQUEST_TIMEOUT	(5 * HZ)
6558e21438SBjorn Andersson 
669835f1b7SLinus Walleij #define RPM_MAX_SEL_SIZE	7
6758e21438SBjorn Andersson 
6858e21438SBjorn Andersson #define RPM_NOTIFICATION	BIT(30)
6958e21438SBjorn Andersson #define RPM_REJECTED		BIT(31)
7058e21438SBjorn Andersson 
7158e21438SBjorn Andersson static const struct qcom_rpm_resource apq8064_rpm_resource_table[] = {
7258e21438SBjorn Andersson 	[QCOM_RPM_CXO_CLK] =			{ 25, 9, 5, 1 },
7358e21438SBjorn Andersson 	[QCOM_RPM_PXO_CLK] =			{ 26, 10, 6, 1 },
7458e21438SBjorn Andersson 	[QCOM_RPM_APPS_FABRIC_CLK] =		{ 27, 11, 8, 1 },
7558e21438SBjorn Andersson 	[QCOM_RPM_SYS_FABRIC_CLK] =		{ 28, 12, 9, 1 },
7658e21438SBjorn Andersson 	[QCOM_RPM_MM_FABRIC_CLK] =		{ 29, 13, 10, 1 },
7758e21438SBjorn Andersson 	[QCOM_RPM_DAYTONA_FABRIC_CLK] =		{ 30, 14, 11, 1 },
7858e21438SBjorn Andersson 	[QCOM_RPM_SFPB_CLK] =			{ 31, 15, 12, 1 },
7958e21438SBjorn Andersson 	[QCOM_RPM_CFPB_CLK] =			{ 32, 16, 13, 1 },
8058e21438SBjorn Andersson 	[QCOM_RPM_MMFPB_CLK] =			{ 33, 17, 14, 1 },
8158e21438SBjorn Andersson 	[QCOM_RPM_EBI1_CLK] =			{ 34, 18, 16, 1 },
8258e21438SBjorn Andersson 	[QCOM_RPM_APPS_FABRIC_HALT] =		{ 35, 19, 18, 1 },
8358e21438SBjorn Andersson 	[QCOM_RPM_APPS_FABRIC_MODE] =		{ 37, 20, 19, 1 },
8458e21438SBjorn Andersson 	[QCOM_RPM_APPS_FABRIC_IOCTL] =		{ 40, 21, 20, 1 },
8558e21438SBjorn Andersson 	[QCOM_RPM_APPS_FABRIC_ARB] =		{ 41, 22, 21, 12 },
8658e21438SBjorn Andersson 	[QCOM_RPM_SYS_FABRIC_HALT] =		{ 53, 23, 22, 1 },
8758e21438SBjorn Andersson 	[QCOM_RPM_SYS_FABRIC_MODE] =		{ 55, 24, 23, 1 },
8858e21438SBjorn Andersson 	[QCOM_RPM_SYS_FABRIC_IOCTL] =		{ 58, 25, 24, 1 },
8958e21438SBjorn Andersson 	[QCOM_RPM_SYS_FABRIC_ARB] =		{ 59, 26, 25, 30 },
9058e21438SBjorn Andersson 	[QCOM_RPM_MM_FABRIC_HALT] =		{ 89, 27, 26, 1 },
9158e21438SBjorn Andersson 	[QCOM_RPM_MM_FABRIC_MODE] =		{ 91, 28, 27, 1 },
9258e21438SBjorn Andersson 	[QCOM_RPM_MM_FABRIC_IOCTL] =		{ 94, 29, 28, 1 },
9358e21438SBjorn Andersson 	[QCOM_RPM_MM_FABRIC_ARB] =		{ 95, 30, 29, 21 },
9458e21438SBjorn Andersson 	[QCOM_RPM_PM8921_SMPS1] =		{ 116, 31, 30, 2 },
9558e21438SBjorn Andersson 	[QCOM_RPM_PM8921_SMPS2] =		{ 118, 33, 31, 2 },
9658e21438SBjorn Andersson 	[QCOM_RPM_PM8921_SMPS3] =		{ 120, 35, 32, 2 },
9758e21438SBjorn Andersson 	[QCOM_RPM_PM8921_SMPS4] =		{ 122, 37, 33, 2 },
9858e21438SBjorn Andersson 	[QCOM_RPM_PM8921_SMPS5] =		{ 124, 39, 34, 2 },
9958e21438SBjorn Andersson 	[QCOM_RPM_PM8921_SMPS6] =		{ 126, 41, 35, 2 },
10058e21438SBjorn Andersson 	[QCOM_RPM_PM8921_SMPS7] =		{ 128, 43, 36, 2 },
10158e21438SBjorn Andersson 	[QCOM_RPM_PM8921_SMPS8] =		{ 130, 45, 37, 2 },
10258e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO1] =		{ 132, 47, 38, 2 },
10358e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO2] =		{ 134, 49, 39, 2 },
10458e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO3] =		{ 136, 51, 40, 2 },
10558e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO4] =		{ 138, 53, 41, 2 },
10658e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO5] =		{ 140, 55, 42, 2 },
10758e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO6] =		{ 142, 57, 43, 2 },
10858e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO7] =		{ 144, 59, 44, 2 },
10958e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO8] =		{ 146, 61, 45, 2 },
11058e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO9] =		{ 148, 63, 46, 2 },
11158e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO10] =		{ 150, 65, 47, 2 },
11258e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO11] =		{ 152, 67, 48, 2 },
11358e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO12] =		{ 154, 69, 49, 2 },
11458e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO13] =		{ 156, 71, 50, 2 },
11558e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO14] =		{ 158, 73, 51, 2 },
11658e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO15] =		{ 160, 75, 52, 2 },
11758e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO16] =		{ 162, 77, 53, 2 },
11858e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO17] =		{ 164, 79, 54, 2 },
11958e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO18] =		{ 166, 81, 55, 2 },
12058e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO19] =		{ 168, 83, 56, 2 },
12158e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO20] =		{ 170, 85, 57, 2 },
12258e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO21] =		{ 172, 87, 58, 2 },
12358e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO22] =		{ 174, 89, 59, 2 },
12458e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO23] =		{ 176, 91, 60, 2 },
12558e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO24] =		{ 178, 93, 61, 2 },
12658e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO25] =		{ 180, 95, 62, 2 },
12758e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO26] =		{ 182, 97, 63, 2 },
12858e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO27] =		{ 184, 99, 64, 2 },
12958e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO28] =		{ 186, 101, 65, 2 },
13058e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO29] =		{ 188, 103, 66, 2 },
13158e21438SBjorn Andersson 	[QCOM_RPM_PM8921_CLK1] =		{ 190, 105, 67, 2 },
13258e21438SBjorn Andersson 	[QCOM_RPM_PM8921_CLK2] =		{ 192, 107, 68, 2 },
13358e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LVS1] =		{ 194, 109, 69, 1 },
13458e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LVS2] =		{ 195, 110, 70, 1 },
13558e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LVS3] =		{ 196, 111, 71, 1 },
13658e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LVS4] =		{ 197, 112, 72, 1 },
13758e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LVS5] =		{ 198, 113, 73, 1 },
13858e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LVS6] =		{ 199, 114, 74, 1 },
13958e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LVS7] =		{ 200, 115, 75, 1 },
14058e21438SBjorn Andersson 	[QCOM_RPM_PM8821_SMPS1] =		{ 201, 116, 76, 2 },
14158e21438SBjorn Andersson 	[QCOM_RPM_PM8821_SMPS2] =		{ 203, 118, 77, 2 },
14258e21438SBjorn Andersson 	[QCOM_RPM_PM8821_LDO1] =		{ 205, 120, 78, 2 },
14358e21438SBjorn Andersson 	[QCOM_RPM_PM8921_NCP] =			{ 207, 122, 80, 2 },
14458e21438SBjorn Andersson 	[QCOM_RPM_CXO_BUFFERS] =		{ 209, 124, 81, 1 },
14558e21438SBjorn Andersson 	[QCOM_RPM_USB_OTG_SWITCH] =		{ 210, 125, 82, 1 },
14658e21438SBjorn Andersson 	[QCOM_RPM_HDMI_SWITCH] =		{ 211, 126, 83, 1 },
14758e21438SBjorn Andersson 	[QCOM_RPM_DDR_DMM] =			{ 212, 127, 84, 2 },
14851d0eb81SIvan T. Ivanov 	[QCOM_RPM_QDSS_CLK] =			{ 214, ~0, 7, 1 },
14958e21438SBjorn Andersson 	[QCOM_RPM_VDDMIN_GPIO] =		{ 215, 131, 89, 1 },
15058e21438SBjorn Andersson };
15158e21438SBjorn Andersson 
15258e21438SBjorn Andersson static const struct qcom_rpm_data apq8064_template = {
15358e21438SBjorn Andersson 	.version = 3,
15458e21438SBjorn Andersson 	.resource_table = apq8064_rpm_resource_table,
15558e21438SBjorn Andersson 	.n_resources = ARRAY_SIZE(apq8064_rpm_resource_table),
1569835f1b7SLinus Walleij 	.req_ctx_off = 3,
1579835f1b7SLinus Walleij 	.req_sel_off = 11,
1589835f1b7SLinus Walleij 	.ack_ctx_off = 15,
1599835f1b7SLinus Walleij 	.ack_sel_off = 23,
160f37be01eSLinus Walleij 	.req_sel_size = 4,
161f37be01eSLinus Walleij 	.ack_sel_size = 7,
16258e21438SBjorn Andersson };
16358e21438SBjorn Andersson 
16458e21438SBjorn Andersson static const struct qcom_rpm_resource msm8660_rpm_resource_table[] = {
16558e21438SBjorn Andersson 	[QCOM_RPM_CXO_CLK] =			{ 32, 12, 5, 1 },
16658e21438SBjorn Andersson 	[QCOM_RPM_PXO_CLK] =			{ 33, 13, 6, 1 },
16758e21438SBjorn Andersson 	[QCOM_RPM_PLL_4] =			{ 34, 14, 7, 1 },
16858e21438SBjorn Andersson 	[QCOM_RPM_APPS_FABRIC_CLK] =		{ 35, 15, 8, 1 },
16958e21438SBjorn Andersson 	[QCOM_RPM_SYS_FABRIC_CLK] =		{ 36, 16, 9, 1 },
17058e21438SBjorn Andersson 	[QCOM_RPM_MM_FABRIC_CLK] =		{ 37, 17, 10, 1 },
17158e21438SBjorn Andersson 	[QCOM_RPM_DAYTONA_FABRIC_CLK] =		{ 38, 18, 11, 1 },
17258e21438SBjorn Andersson 	[QCOM_RPM_SFPB_CLK] =			{ 39, 19, 12, 1 },
17358e21438SBjorn Andersson 	[QCOM_RPM_CFPB_CLK] =			{ 40, 20, 13, 1 },
17458e21438SBjorn Andersson 	[QCOM_RPM_MMFPB_CLK] =			{ 41, 21, 14, 1 },
17558e21438SBjorn Andersson 	[QCOM_RPM_SMI_CLK] =			{ 42, 22, 15, 1 },
17658e21438SBjorn Andersson 	[QCOM_RPM_EBI1_CLK] =			{ 43, 23, 16, 1 },
17758e21438SBjorn Andersson 	[QCOM_RPM_APPS_L2_CACHE_CTL] =		{ 44, 24, 17, 1 },
17858e21438SBjorn Andersson 	[QCOM_RPM_APPS_FABRIC_HALT] =		{ 45, 25, 18, 2 },
17958e21438SBjorn Andersson 	[QCOM_RPM_APPS_FABRIC_MODE] =		{ 47, 26, 19, 3 },
18058e21438SBjorn Andersson 	[QCOM_RPM_APPS_FABRIC_ARB] =		{ 51, 28, 21, 6 },
18158e21438SBjorn Andersson 	[QCOM_RPM_SYS_FABRIC_HALT] =		{ 63, 29, 22, 2 },
18258e21438SBjorn Andersson 	[QCOM_RPM_SYS_FABRIC_MODE] =		{ 65, 30, 23, 3 },
18358e21438SBjorn Andersson 	[QCOM_RPM_SYS_FABRIC_ARB] =		{ 69, 32, 25, 22 },
18458e21438SBjorn Andersson 	[QCOM_RPM_MM_FABRIC_HALT] =		{ 105, 33, 26, 2 },
18558e21438SBjorn Andersson 	[QCOM_RPM_MM_FABRIC_MODE] =		{ 107, 34, 27, 3 },
18658e21438SBjorn Andersson 	[QCOM_RPM_MM_FABRIC_ARB] =		{ 111, 36, 29, 23 },
18758e21438SBjorn Andersson 	[QCOM_RPM_PM8901_SMPS0] =		{ 134, 37, 30, 2 },
18858e21438SBjorn Andersson 	[QCOM_RPM_PM8901_SMPS1] =		{ 136, 39, 31, 2 },
18958e21438SBjorn Andersson 	[QCOM_RPM_PM8901_SMPS2] =		{ 138, 41, 32, 2 },
19058e21438SBjorn Andersson 	[QCOM_RPM_PM8901_SMPS3] =		{ 140, 43, 33, 2 },
19158e21438SBjorn Andersson 	[QCOM_RPM_PM8901_SMPS4] =		{ 142, 45, 34, 2 },
19258e21438SBjorn Andersson 	[QCOM_RPM_PM8901_LDO0] =		{ 144, 47, 35, 2 },
19358e21438SBjorn Andersson 	[QCOM_RPM_PM8901_LDO1] =		{ 146, 49, 36, 2 },
19458e21438SBjorn Andersson 	[QCOM_RPM_PM8901_LDO2] =		{ 148, 51, 37, 2 },
19558e21438SBjorn Andersson 	[QCOM_RPM_PM8901_LDO3] =		{ 150, 53, 38, 2 },
19658e21438SBjorn Andersson 	[QCOM_RPM_PM8901_LDO4] =		{ 152, 55, 39, 2 },
19758e21438SBjorn Andersson 	[QCOM_RPM_PM8901_LDO5] =		{ 154, 57, 40, 2 },
19858e21438SBjorn Andersson 	[QCOM_RPM_PM8901_LDO6] =		{ 156, 59, 41, 2 },
19958e21438SBjorn Andersson 	[QCOM_RPM_PM8901_LVS0] =		{ 158, 61, 42, 1 },
20058e21438SBjorn Andersson 	[QCOM_RPM_PM8901_LVS1] =		{ 159, 62, 43, 1 },
20158e21438SBjorn Andersson 	[QCOM_RPM_PM8901_LVS2] =		{ 160, 63, 44, 1 },
20258e21438SBjorn Andersson 	[QCOM_RPM_PM8901_LVS3] =		{ 161, 64, 45, 1 },
20358e21438SBjorn Andersson 	[QCOM_RPM_PM8901_MVS] =			{ 162, 65, 46, 1 },
20458e21438SBjorn Andersson 	[QCOM_RPM_PM8058_SMPS0] =		{ 163, 66, 47, 2 },
20558e21438SBjorn Andersson 	[QCOM_RPM_PM8058_SMPS1] =		{ 165, 68, 48, 2 },
20658e21438SBjorn Andersson 	[QCOM_RPM_PM8058_SMPS2] =		{ 167, 70, 49, 2 },
20758e21438SBjorn Andersson 	[QCOM_RPM_PM8058_SMPS3] =		{ 169, 72, 50, 2 },
20858e21438SBjorn Andersson 	[QCOM_RPM_PM8058_SMPS4] =		{ 171, 74, 51, 2 },
20958e21438SBjorn Andersson 	[QCOM_RPM_PM8058_LDO0] =		{ 173, 76, 52, 2 },
21058e21438SBjorn Andersson 	[QCOM_RPM_PM8058_LDO1] =		{ 175, 78, 53, 2 },
21158e21438SBjorn Andersson 	[QCOM_RPM_PM8058_LDO2] =		{ 177, 80, 54, 2 },
21258e21438SBjorn Andersson 	[QCOM_RPM_PM8058_LDO3] =		{ 179, 82, 55, 2 },
21358e21438SBjorn Andersson 	[QCOM_RPM_PM8058_LDO4] =		{ 181, 84, 56, 2 },
21458e21438SBjorn Andersson 	[QCOM_RPM_PM8058_LDO5] =		{ 183, 86, 57, 2 },
21558e21438SBjorn Andersson 	[QCOM_RPM_PM8058_LDO6] =		{ 185, 88, 58, 2 },
21658e21438SBjorn Andersson 	[QCOM_RPM_PM8058_LDO7] =		{ 187, 90, 59, 2 },
21758e21438SBjorn Andersson 	[QCOM_RPM_PM8058_LDO8] =		{ 189, 92, 60, 2 },
21858e21438SBjorn Andersson 	[QCOM_RPM_PM8058_LDO9] =		{ 191, 94, 61, 2 },
21958e21438SBjorn Andersson 	[QCOM_RPM_PM8058_LDO10] =		{ 193, 96, 62, 2 },
22058e21438SBjorn Andersson 	[QCOM_RPM_PM8058_LDO11] =		{ 195, 98, 63, 2 },
22158e21438SBjorn Andersson 	[QCOM_RPM_PM8058_LDO12] =		{ 197, 100, 64, 2 },
22258e21438SBjorn Andersson 	[QCOM_RPM_PM8058_LDO13] =		{ 199, 102, 65, 2 },
22358e21438SBjorn Andersson 	[QCOM_RPM_PM8058_LDO14] =		{ 201, 104, 66, 2 },
22458e21438SBjorn Andersson 	[QCOM_RPM_PM8058_LDO15] =		{ 203, 106, 67, 2 },
22558e21438SBjorn Andersson 	[QCOM_RPM_PM8058_LDO16] =		{ 205, 108, 68, 2 },
22658e21438SBjorn Andersson 	[QCOM_RPM_PM8058_LDO17] =		{ 207, 110, 69, 2 },
22758e21438SBjorn Andersson 	[QCOM_RPM_PM8058_LDO18] =		{ 209, 112, 70, 2 },
22858e21438SBjorn Andersson 	[QCOM_RPM_PM8058_LDO19] =		{ 211, 114, 71, 2 },
22958e21438SBjorn Andersson 	[QCOM_RPM_PM8058_LDO20] =		{ 213, 116, 72, 2 },
23058e21438SBjorn Andersson 	[QCOM_RPM_PM8058_LDO21] =		{ 215, 118, 73, 2 },
23158e21438SBjorn Andersson 	[QCOM_RPM_PM8058_LDO22] =		{ 217, 120, 74, 2 },
23258e21438SBjorn Andersson 	[QCOM_RPM_PM8058_LDO23] =		{ 219, 122, 75, 2 },
23358e21438SBjorn Andersson 	[QCOM_RPM_PM8058_LDO24] =		{ 221, 124, 76, 2 },
23458e21438SBjorn Andersson 	[QCOM_RPM_PM8058_LDO25] =		{ 223, 126, 77, 2 },
23558e21438SBjorn Andersson 	[QCOM_RPM_PM8058_LVS0] =		{ 225, 128, 78, 1 },
23658e21438SBjorn Andersson 	[QCOM_RPM_PM8058_LVS1] =		{ 226, 129, 79, 1 },
23758e21438SBjorn Andersson 	[QCOM_RPM_PM8058_NCP] =			{ 227, 130, 80, 2 },
23858e21438SBjorn Andersson 	[QCOM_RPM_CXO_BUFFERS] =		{ 229, 132, 81, 1 },
23958e21438SBjorn Andersson };
24058e21438SBjorn Andersson 
24158e21438SBjorn Andersson static const struct qcom_rpm_data msm8660_template = {
24258e21438SBjorn Andersson 	.version = 2,
24358e21438SBjorn Andersson 	.resource_table = msm8660_rpm_resource_table,
24458e21438SBjorn Andersson 	.n_resources = ARRAY_SIZE(msm8660_rpm_resource_table),
2459835f1b7SLinus Walleij 	.req_ctx_off = 3,
2469835f1b7SLinus Walleij 	.req_sel_off = 11,
2479835f1b7SLinus Walleij 	.ack_ctx_off = 19,
2489835f1b7SLinus Walleij 	.ack_sel_off = 27,
249f37be01eSLinus Walleij 	.req_sel_size = 7,
250f37be01eSLinus Walleij 	.ack_sel_size = 7,
25158e21438SBjorn Andersson };
25258e21438SBjorn Andersson 
25358e21438SBjorn Andersson static const struct qcom_rpm_resource msm8960_rpm_resource_table[] = {
25458e21438SBjorn Andersson 	[QCOM_RPM_CXO_CLK] =			{ 25, 9, 5, 1 },
25558e21438SBjorn Andersson 	[QCOM_RPM_PXO_CLK] =			{ 26, 10, 6, 1 },
25658e21438SBjorn Andersson 	[QCOM_RPM_APPS_FABRIC_CLK] =		{ 27, 11, 8, 1 },
25758e21438SBjorn Andersson 	[QCOM_RPM_SYS_FABRIC_CLK] =		{ 28, 12, 9, 1 },
25858e21438SBjorn Andersson 	[QCOM_RPM_MM_FABRIC_CLK] =		{ 29, 13, 10, 1 },
25958e21438SBjorn Andersson 	[QCOM_RPM_DAYTONA_FABRIC_CLK] =		{ 30, 14, 11, 1 },
26058e21438SBjorn Andersson 	[QCOM_RPM_SFPB_CLK] =			{ 31, 15, 12, 1 },
26158e21438SBjorn Andersson 	[QCOM_RPM_CFPB_CLK] =			{ 32, 16, 13, 1 },
26258e21438SBjorn Andersson 	[QCOM_RPM_MMFPB_CLK] =			{ 33, 17, 14, 1 },
26358e21438SBjorn Andersson 	[QCOM_RPM_EBI1_CLK] =			{ 34, 18, 16, 1 },
26458e21438SBjorn Andersson 	[QCOM_RPM_APPS_FABRIC_HALT] =		{ 35, 19, 18, 1 },
26558e21438SBjorn Andersson 	[QCOM_RPM_APPS_FABRIC_MODE] =		{ 37, 20, 19, 1 },
26658e21438SBjorn Andersson 	[QCOM_RPM_APPS_FABRIC_IOCTL] =		{ 40, 21, 20, 1 },
26758e21438SBjorn Andersson 	[QCOM_RPM_APPS_FABRIC_ARB] =		{ 41, 22, 21, 12 },
26858e21438SBjorn Andersson 	[QCOM_RPM_SYS_FABRIC_HALT] =		{ 53, 23, 22, 1 },
26958e21438SBjorn Andersson 	[QCOM_RPM_SYS_FABRIC_MODE] =		{ 55, 24, 23, 1 },
27058e21438SBjorn Andersson 	[QCOM_RPM_SYS_FABRIC_IOCTL] =		{ 58, 25, 24, 1 },
27158e21438SBjorn Andersson 	[QCOM_RPM_SYS_FABRIC_ARB] =		{ 59, 26, 25, 29 },
27258e21438SBjorn Andersson 	[QCOM_RPM_MM_FABRIC_HALT] =		{ 88, 27, 26, 1 },
27358e21438SBjorn Andersson 	[QCOM_RPM_MM_FABRIC_MODE] =		{ 90, 28, 27, 1 },
27458e21438SBjorn Andersson 	[QCOM_RPM_MM_FABRIC_IOCTL] =		{ 93, 29, 28, 1 },
27558e21438SBjorn Andersson 	[QCOM_RPM_MM_FABRIC_ARB] =		{ 94, 30, 29, 23 },
27658e21438SBjorn Andersson 	[QCOM_RPM_PM8921_SMPS1] =		{ 117, 31, 30, 2 },
27758e21438SBjorn Andersson 	[QCOM_RPM_PM8921_SMPS2] =		{ 119, 33, 31, 2 },
27858e21438SBjorn Andersson 	[QCOM_RPM_PM8921_SMPS3] =		{ 121, 35, 32, 2 },
27958e21438SBjorn Andersson 	[QCOM_RPM_PM8921_SMPS4] =		{ 123, 37, 33, 2 },
28058e21438SBjorn Andersson 	[QCOM_RPM_PM8921_SMPS5] =		{ 125, 39, 34, 2 },
28158e21438SBjorn Andersson 	[QCOM_RPM_PM8921_SMPS6] =		{ 127, 41, 35, 2 },
28258e21438SBjorn Andersson 	[QCOM_RPM_PM8921_SMPS7] =		{ 129, 43, 36, 2 },
28358e21438SBjorn Andersson 	[QCOM_RPM_PM8921_SMPS8] =		{ 131, 45, 37, 2 },
28458e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO1] =		{ 133, 47, 38, 2 },
28558e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO2] =		{ 135, 49, 39, 2 },
28658e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO3] =		{ 137, 51, 40, 2 },
28758e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO4] =		{ 139, 53, 41, 2 },
28858e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO5] =		{ 141, 55, 42, 2 },
28958e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO6] =		{ 143, 57, 43, 2 },
29058e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO7] =		{ 145, 59, 44, 2 },
29158e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO8] =		{ 147, 61, 45, 2 },
29258e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO9] =		{ 149, 63, 46, 2 },
29358e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO10] =		{ 151, 65, 47, 2 },
29458e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO11] =		{ 153, 67, 48, 2 },
29558e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO12] =		{ 155, 69, 49, 2 },
29658e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO13] =		{ 157, 71, 50, 2 },
29758e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO14] =		{ 159, 73, 51, 2 },
29858e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO15] =		{ 161, 75, 52, 2 },
29958e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO16] =		{ 163, 77, 53, 2 },
30058e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO17] =		{ 165, 79, 54, 2 },
30158e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO18] =		{ 167, 81, 55, 2 },
30258e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO19] =		{ 169, 83, 56, 2 },
30358e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO20] =		{ 171, 85, 57, 2 },
30458e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO21] =		{ 173, 87, 58, 2 },
30558e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO22] =		{ 175, 89, 59, 2 },
30658e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO23] =		{ 177, 91, 60, 2 },
30758e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO24] =		{ 179, 93, 61, 2 },
30858e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO25] =		{ 181, 95, 62, 2 },
30958e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO26] =		{ 183, 97, 63, 2 },
31058e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO27] =		{ 185, 99, 64, 2 },
31158e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO28] =		{ 187, 101, 65, 2 },
31258e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LDO29] =		{ 189, 103, 66, 2 },
31358e21438SBjorn Andersson 	[QCOM_RPM_PM8921_CLK1] =		{ 191, 105, 67, 2 },
31458e21438SBjorn Andersson 	[QCOM_RPM_PM8921_CLK2] =		{ 193, 107, 68, 2 },
31558e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LVS1] =		{ 195, 109, 69, 1 },
31658e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LVS2] =		{ 196, 110, 70, 1 },
31758e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LVS3] =		{ 197, 111, 71, 1 },
31858e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LVS4] =		{ 198, 112, 72, 1 },
31958e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LVS5] =		{ 199, 113, 73, 1 },
32058e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LVS6] =		{ 200, 114, 74, 1 },
32158e21438SBjorn Andersson 	[QCOM_RPM_PM8921_LVS7] =		{ 201, 115, 75, 1 },
32258e21438SBjorn Andersson 	[QCOM_RPM_PM8921_NCP] =			{ 202, 116, 80, 2 },
32358e21438SBjorn Andersson 	[QCOM_RPM_CXO_BUFFERS] =		{ 204, 118, 81, 1 },
32458e21438SBjorn Andersson 	[QCOM_RPM_USB_OTG_SWITCH] =		{ 205, 119, 82, 1 },
32558e21438SBjorn Andersson 	[QCOM_RPM_HDMI_SWITCH] =		{ 206, 120, 83, 1 },
32658e21438SBjorn Andersson 	[QCOM_RPM_DDR_DMM] =			{ 207, 121, 84, 2 },
32758e21438SBjorn Andersson };
32858e21438SBjorn Andersson 
32958e21438SBjorn Andersson static const struct qcom_rpm_data msm8960_template = {
33058e21438SBjorn Andersson 	.version = 3,
33158e21438SBjorn Andersson 	.resource_table = msm8960_rpm_resource_table,
33258e21438SBjorn Andersson 	.n_resources = ARRAY_SIZE(msm8960_rpm_resource_table),
3339835f1b7SLinus Walleij 	.req_ctx_off = 3,
3349835f1b7SLinus Walleij 	.req_sel_off = 11,
3359835f1b7SLinus Walleij 	.ack_ctx_off = 15,
3369835f1b7SLinus Walleij 	.ack_sel_off = 23,
337f37be01eSLinus Walleij 	.req_sel_size = 4,
338f37be01eSLinus Walleij 	.ack_sel_size = 7,
33958e21438SBjorn Andersson };
34058e21438SBjorn Andersson 
3414d54b0adSJosh Cartwright static const struct qcom_rpm_resource ipq806x_rpm_resource_table[] = {
3424d54b0adSJosh Cartwright 	[QCOM_RPM_CXO_CLK] =			{ 25, 9, 5, 1 },
3434d54b0adSJosh Cartwright 	[QCOM_RPM_PXO_CLK] =			{ 26, 10, 6, 1 },
3444d54b0adSJosh Cartwright 	[QCOM_RPM_APPS_FABRIC_CLK] =		{ 27, 11, 8, 1 },
3454d54b0adSJosh Cartwright 	[QCOM_RPM_SYS_FABRIC_CLK] =		{ 28, 12, 9, 1 },
3464d54b0adSJosh Cartwright 	[QCOM_RPM_NSS_FABRIC_0_CLK] =		{ 29, 13, 10, 1 },
3474d54b0adSJosh Cartwright 	[QCOM_RPM_DAYTONA_FABRIC_CLK] =		{ 30, 14, 11, 1 },
3484d54b0adSJosh Cartwright 	[QCOM_RPM_SFPB_CLK] =			{ 31, 15, 12, 1 },
3494d54b0adSJosh Cartwright 	[QCOM_RPM_CFPB_CLK] =			{ 32, 16, 13, 1 },
3504d54b0adSJosh Cartwright 	[QCOM_RPM_NSS_FABRIC_1_CLK] =		{ 33, 17, 14, 1 },
3514d54b0adSJosh Cartwright 	[QCOM_RPM_EBI1_CLK] =			{ 34, 18, 16, 1 },
3524d54b0adSJosh Cartwright 	[QCOM_RPM_APPS_FABRIC_HALT] =		{ 35, 19, 18, 2 },
3534d54b0adSJosh Cartwright 	[QCOM_RPM_APPS_FABRIC_MODE] =		{ 37, 20, 19, 3 },
3544d54b0adSJosh Cartwright 	[QCOM_RPM_APPS_FABRIC_IOCTL] =		{ 40, 21, 20, 1 },
3554d54b0adSJosh Cartwright 	[QCOM_RPM_APPS_FABRIC_ARB] =		{ 41, 22, 21, 12 },
3564d54b0adSJosh Cartwright 	[QCOM_RPM_SYS_FABRIC_HALT] =		{ 53, 23, 22, 2 },
3574d54b0adSJosh Cartwright 	[QCOM_RPM_SYS_FABRIC_MODE] =		{ 55, 24, 23, 3 },
3584d54b0adSJosh Cartwright 	[QCOM_RPM_SYS_FABRIC_IOCTL] =		{ 58, 25, 24, 1 },
3594d54b0adSJosh Cartwright 	[QCOM_RPM_SYS_FABRIC_ARB] =		{ 59, 26, 25, 30 },
3604d54b0adSJosh Cartwright 	[QCOM_RPM_MM_FABRIC_HALT] =		{ 89, 27, 26, 2 },
3614d54b0adSJosh Cartwright 	[QCOM_RPM_MM_FABRIC_MODE] =		{ 91, 28, 27, 3 },
3624d54b0adSJosh Cartwright 	[QCOM_RPM_MM_FABRIC_IOCTL] =		{ 94, 29, 28, 1 },
3634d54b0adSJosh Cartwright 	[QCOM_RPM_MM_FABRIC_ARB] =		{ 95, 30, 29, 2 },
3644d54b0adSJosh Cartwright 	[QCOM_RPM_CXO_BUFFERS] =		{ 209, 33, 31, 1 },
3654d54b0adSJosh Cartwright 	[QCOM_RPM_USB_OTG_SWITCH] =		{ 210, 34, 32, 1 },
3664d54b0adSJosh Cartwright 	[QCOM_RPM_HDMI_SWITCH] =		{ 211, 35, 33, 1 },
3674d54b0adSJosh Cartwright 	[QCOM_RPM_DDR_DMM] =			{ 212, 36, 34, 2 },
3684d54b0adSJosh Cartwright 	[QCOM_RPM_VDDMIN_GPIO] =		{ 215, 40, 39, 1 },
3694d54b0adSJosh Cartwright 	[QCOM_RPM_SMB208_S1a] =			{ 216, 41, 90, 2 },
3704d54b0adSJosh Cartwright 	[QCOM_RPM_SMB208_S1b] =			{ 218, 43, 91, 2 },
3714d54b0adSJosh Cartwright 	[QCOM_RPM_SMB208_S2a] =			{ 220, 45, 92, 2 },
3724d54b0adSJosh Cartwright 	[QCOM_RPM_SMB208_S2b] =			{ 222, 47, 93, 2 },
3734d54b0adSJosh Cartwright };
3744d54b0adSJosh Cartwright 
3754d54b0adSJosh Cartwright static const struct qcom_rpm_data ipq806x_template = {
3764d54b0adSJosh Cartwright 	.version = 3,
3774d54b0adSJosh Cartwright 	.resource_table = ipq806x_rpm_resource_table,
3784d54b0adSJosh Cartwright 	.n_resources = ARRAY_SIZE(ipq806x_rpm_resource_table),
3799835f1b7SLinus Walleij 	.req_ctx_off = 3,
3809835f1b7SLinus Walleij 	.req_sel_off = 11,
3819835f1b7SLinus Walleij 	.ack_ctx_off = 15,
3829835f1b7SLinus Walleij 	.ack_sel_off = 23,
383f37be01eSLinus Walleij 	.req_sel_size = 4,
384f37be01eSLinus Walleij 	.ack_sel_size = 7,
3854d54b0adSJosh Cartwright };
3864d54b0adSJosh Cartwright 
387eb87a669SNeil Armstrong static const struct qcom_rpm_resource mdm9615_rpm_resource_table[] = {
388eb87a669SNeil Armstrong 	[QCOM_RPM_CXO_CLK] =			{ 25, 9, 5, 1 },
389eb87a669SNeil Armstrong 	[QCOM_RPM_SYS_FABRIC_CLK] =		{ 26, 10, 9, 1 },
390eb87a669SNeil Armstrong 	[QCOM_RPM_DAYTONA_FABRIC_CLK] =		{ 27, 11, 11, 1 },
391eb87a669SNeil Armstrong 	[QCOM_RPM_SFPB_CLK] =			{ 28, 12, 12, 1 },
392eb87a669SNeil Armstrong 	[QCOM_RPM_CFPB_CLK] =			{ 29, 13, 13, 1 },
393eb87a669SNeil Armstrong 	[QCOM_RPM_EBI1_CLK] =			{ 30, 14, 16, 1 },
394eb87a669SNeil Armstrong 	[QCOM_RPM_APPS_FABRIC_HALT] =		{ 31, 15, 22, 2 },
395eb87a669SNeil Armstrong 	[QCOM_RPM_APPS_FABRIC_MODE] =		{ 33, 16, 23, 3 },
396eb87a669SNeil Armstrong 	[QCOM_RPM_APPS_FABRIC_IOCTL] =		{ 36, 17, 24, 1 },
397eb87a669SNeil Armstrong 	[QCOM_RPM_APPS_FABRIC_ARB] =		{ 37, 18, 25, 27 },
398eb87a669SNeil Armstrong 	[QCOM_RPM_PM8018_SMPS1] =		{ 64, 19, 30, 2 },
399eb87a669SNeil Armstrong 	[QCOM_RPM_PM8018_SMPS2] =		{ 66, 21, 31, 2 },
400eb87a669SNeil Armstrong 	[QCOM_RPM_PM8018_SMPS3] =		{ 68, 23, 32, 2 },
401eb87a669SNeil Armstrong 	[QCOM_RPM_PM8018_SMPS4] =		{ 70, 25, 33, 2 },
402eb87a669SNeil Armstrong 	[QCOM_RPM_PM8018_SMPS5] =		{ 72, 27, 34, 2 },
403eb87a669SNeil Armstrong 	[QCOM_RPM_PM8018_LDO1] =		{ 74, 29, 35, 2 },
404eb87a669SNeil Armstrong 	[QCOM_RPM_PM8018_LDO2] =		{ 76, 31, 36, 2 },
405eb87a669SNeil Armstrong 	[QCOM_RPM_PM8018_LDO3] =		{ 78, 33, 37, 2 },
406eb87a669SNeil Armstrong 	[QCOM_RPM_PM8018_LDO4] =		{ 80, 35, 38, 2 },
407eb87a669SNeil Armstrong 	[QCOM_RPM_PM8018_LDO5] =		{ 82, 37, 39, 2 },
408eb87a669SNeil Armstrong 	[QCOM_RPM_PM8018_LDO6] =		{ 84, 39, 40, 2 },
409eb87a669SNeil Armstrong 	[QCOM_RPM_PM8018_LDO7] =		{ 86, 41, 41, 2 },
410eb87a669SNeil Armstrong 	[QCOM_RPM_PM8018_LDO8] =		{ 88, 43, 42, 2 },
411eb87a669SNeil Armstrong 	[QCOM_RPM_PM8018_LDO9] =		{ 90, 45, 43, 2 },
412eb87a669SNeil Armstrong 	[QCOM_RPM_PM8018_LDO10] =		{ 92, 47, 44, 2 },
413eb87a669SNeil Armstrong 	[QCOM_RPM_PM8018_LDO11] =		{ 94, 49, 45, 2 },
414eb87a669SNeil Armstrong 	[QCOM_RPM_PM8018_LDO12] =		{ 96, 51, 46, 2 },
415eb87a669SNeil Armstrong 	[QCOM_RPM_PM8018_LDO13] =		{ 98, 53, 47, 2 },
416eb87a669SNeil Armstrong 	[QCOM_RPM_PM8018_LDO14] =		{ 100, 55, 48, 2 },
417eb87a669SNeil Armstrong 	[QCOM_RPM_PM8018_LVS1] =		{ 102, 57, 49, 1 },
418eb87a669SNeil Armstrong 	[QCOM_RPM_PM8018_NCP] =			{ 103, 58, 80, 2 },
419eb87a669SNeil Armstrong 	[QCOM_RPM_CXO_BUFFERS] =		{ 105, 60, 81, 1 },
420eb87a669SNeil Armstrong 	[QCOM_RPM_USB_OTG_SWITCH] =		{ 106, 61, 82, 1 },
421eb87a669SNeil Armstrong 	[QCOM_RPM_HDMI_SWITCH] =		{ 107, 62, 83, 1 },
422eb87a669SNeil Armstrong 	[QCOM_RPM_VOLTAGE_CORNER] =		{ 109, 64, 87, 1 },
423eb87a669SNeil Armstrong };
424eb87a669SNeil Armstrong 
425eb87a669SNeil Armstrong static const struct qcom_rpm_data mdm9615_template = {
426eb87a669SNeil Armstrong 	.version = 3,
427eb87a669SNeil Armstrong 	.resource_table = mdm9615_rpm_resource_table,
428eb87a669SNeil Armstrong 	.n_resources = ARRAY_SIZE(mdm9615_rpm_resource_table),
429eb87a669SNeil Armstrong 	.req_ctx_off = 3,
430eb87a669SNeil Armstrong 	.req_sel_off = 11,
431eb87a669SNeil Armstrong 	.ack_ctx_off = 15,
432eb87a669SNeil Armstrong 	.ack_sel_off = 23,
433eb87a669SNeil Armstrong 	.req_sel_size = 4,
434eb87a669SNeil Armstrong 	.ack_sel_size = 7,
435eb87a669SNeil Armstrong };
436eb87a669SNeil Armstrong 
43758e21438SBjorn Andersson static const struct of_device_id qcom_rpm_of_match[] = {
43858e21438SBjorn Andersson 	{ .compatible = "qcom,rpm-apq8064", .data = &apq8064_template },
43958e21438SBjorn Andersson 	{ .compatible = "qcom,rpm-msm8660", .data = &msm8660_template },
44058e21438SBjorn Andersson 	{ .compatible = "qcom,rpm-msm8960", .data = &msm8960_template },
4414d54b0adSJosh Cartwright 	{ .compatible = "qcom,rpm-ipq8064", .data = &ipq806x_template },
442eb87a669SNeil Armstrong 	{ .compatible = "qcom,rpm-mdm9615", .data = &mdm9615_template },
44358e21438SBjorn Andersson 	{ }
44458e21438SBjorn Andersson };
44558e21438SBjorn Andersson MODULE_DEVICE_TABLE(of, qcom_rpm_of_match);
44658e21438SBjorn Andersson 
qcom_rpm_write(struct qcom_rpm * rpm,int state,int resource,u32 * buf,size_t count)44758e21438SBjorn Andersson int qcom_rpm_write(struct qcom_rpm *rpm,
44858e21438SBjorn Andersson 		   int state,
44958e21438SBjorn Andersson 		   int resource,
45058e21438SBjorn Andersson 		   u32 *buf, size_t count)
45158e21438SBjorn Andersson {
45258e21438SBjorn Andersson 	const struct qcom_rpm_resource *res;
45358e21438SBjorn Andersson 	const struct qcom_rpm_data *data = rpm->data;
4549835f1b7SLinus Walleij 	u32 sel_mask[RPM_MAX_SEL_SIZE] = { 0 };
45558e21438SBjorn Andersson 	int left;
45658e21438SBjorn Andersson 	int ret = 0;
45758e21438SBjorn Andersson 	int i;
45858e21438SBjorn Andersson 
45958e21438SBjorn Andersson 	if (WARN_ON(resource < 0 || resource >= data->n_resources))
46058e21438SBjorn Andersson 		return -EINVAL;
46158e21438SBjorn Andersson 
46258e21438SBjorn Andersson 	res = &data->resource_table[resource];
46358e21438SBjorn Andersson 	if (WARN_ON(res->size != count))
46458e21438SBjorn Andersson 		return -EINVAL;
46558e21438SBjorn Andersson 
46658e21438SBjorn Andersson 	mutex_lock(&rpm->lock);
46758e21438SBjorn Andersson 
46858e21438SBjorn Andersson 	for (i = 0; i < res->size; i++)
46958e21438SBjorn Andersson 		writel_relaxed(buf[i], RPM_REQ_REG(rpm, res->target_id + i));
47058e21438SBjorn Andersson 
47158e21438SBjorn Andersson 	bitmap_set((unsigned long *)sel_mask, res->select_id, 1);
472f37be01eSLinus Walleij 	for (i = 0; i < rpm->data->req_sel_size; i++) {
47358e21438SBjorn Andersson 		writel_relaxed(sel_mask[i],
4749835f1b7SLinus Walleij 			       RPM_CTRL_REG(rpm, rpm->data->req_sel_off + i));
47558e21438SBjorn Andersson 	}
47658e21438SBjorn Andersson 
4779835f1b7SLinus Walleij 	writel_relaxed(BIT(state), RPM_CTRL_REG(rpm, rpm->data->req_ctx_off));
47858e21438SBjorn Andersson 
47958e21438SBjorn Andersson 	reinit_completion(&rpm->ack);
48058e21438SBjorn Andersson 	regmap_write(rpm->ipc_regmap, rpm->ipc_offset, BIT(rpm->ipc_bit));
48158e21438SBjorn Andersson 
48258e21438SBjorn Andersson 	left = wait_for_completion_timeout(&rpm->ack, RPM_REQUEST_TIMEOUT);
48358e21438SBjorn Andersson 	if (!left)
48458e21438SBjorn Andersson 		ret = -ETIMEDOUT;
48558e21438SBjorn Andersson 	else if (rpm->ack_status & RPM_REJECTED)
48658e21438SBjorn Andersson 		ret = -EIO;
48758e21438SBjorn Andersson 
48858e21438SBjorn Andersson 	mutex_unlock(&rpm->lock);
48958e21438SBjorn Andersson 
49058e21438SBjorn Andersson 	return ret;
49158e21438SBjorn Andersson }
49258e21438SBjorn Andersson EXPORT_SYMBOL(qcom_rpm_write);
49358e21438SBjorn Andersson 
qcom_rpm_ack_interrupt(int irq,void * dev)49458e21438SBjorn Andersson static irqreturn_t qcom_rpm_ack_interrupt(int irq, void *dev)
49558e21438SBjorn Andersson {
49658e21438SBjorn Andersson 	struct qcom_rpm *rpm = dev;
49758e21438SBjorn Andersson 	u32 ack;
49858e21438SBjorn Andersson 	int i;
49958e21438SBjorn Andersson 
5009835f1b7SLinus Walleij 	ack = readl_relaxed(RPM_CTRL_REG(rpm, rpm->data->ack_ctx_off));
501f37be01eSLinus Walleij 	for (i = 0; i < rpm->data->ack_sel_size; i++)
5029835f1b7SLinus Walleij 		writel_relaxed(0,
5039835f1b7SLinus Walleij 			RPM_CTRL_REG(rpm, rpm->data->ack_sel_off + i));
5049835f1b7SLinus Walleij 	writel(0, RPM_CTRL_REG(rpm, rpm->data->ack_ctx_off));
50558e21438SBjorn Andersson 
50658e21438SBjorn Andersson 	if (ack & RPM_NOTIFICATION) {
50758e21438SBjorn Andersson 		dev_warn(rpm->dev, "ignoring notification!\n");
50858e21438SBjorn Andersson 	} else {
50958e21438SBjorn Andersson 		rpm->ack_status = ack;
51058e21438SBjorn Andersson 		complete(&rpm->ack);
51158e21438SBjorn Andersson 	}
51258e21438SBjorn Andersson 
51358e21438SBjorn Andersson 	return IRQ_HANDLED;
51458e21438SBjorn Andersson }
51558e21438SBjorn Andersson 
qcom_rpm_err_interrupt(int irq,void * dev)51658e21438SBjorn Andersson static irqreturn_t qcom_rpm_err_interrupt(int irq, void *dev)
51758e21438SBjorn Andersson {
51858e21438SBjorn Andersson 	struct qcom_rpm *rpm = dev;
51958e21438SBjorn Andersson 
52058e21438SBjorn Andersson 	regmap_write(rpm->ipc_regmap, rpm->ipc_offset, BIT(rpm->ipc_bit));
52158e21438SBjorn Andersson 	dev_err(rpm->dev, "RPM triggered fatal error\n");
52258e21438SBjorn Andersson 
52358e21438SBjorn Andersson 	return IRQ_HANDLED;
52458e21438SBjorn Andersson }
52558e21438SBjorn Andersson 
qcom_rpm_wakeup_interrupt(int irq,void * dev)52658e21438SBjorn Andersson static irqreturn_t qcom_rpm_wakeup_interrupt(int irq, void *dev)
52758e21438SBjorn Andersson {
52858e21438SBjorn Andersson 	return IRQ_HANDLED;
52958e21438SBjorn Andersson }
53058e21438SBjorn Andersson 
qcom_rpm_probe(struct platform_device * pdev)53158e21438SBjorn Andersson static int qcom_rpm_probe(struct platform_device *pdev)
53258e21438SBjorn Andersson {
53358e21438SBjorn Andersson 	struct device_node *syscon_np;
53458e21438SBjorn Andersson 	struct qcom_rpm *rpm;
53558e21438SBjorn Andersson 	u32 fw_version[3];
53658e21438SBjorn Andersson 	int irq_wakeup;
53758e21438SBjorn Andersson 	int irq_ack;
53858e21438SBjorn Andersson 	int irq_err;
53958e21438SBjorn Andersson 	int ret;
54058e21438SBjorn Andersson 
54158e21438SBjorn Andersson 	rpm = devm_kzalloc(&pdev->dev, sizeof(*rpm), GFP_KERNEL);
54258e21438SBjorn Andersson 	if (!rpm)
54358e21438SBjorn Andersson 		return -ENOMEM;
54458e21438SBjorn Andersson 
54558e21438SBjorn Andersson 	rpm->dev = &pdev->dev;
54658e21438SBjorn Andersson 	mutex_init(&rpm->lock);
54758e21438SBjorn Andersson 	init_completion(&rpm->ack);
54858e21438SBjorn Andersson 
54935264033SLinus Walleij 	/* Enable message RAM clock */
55036579acaSChristophe JAILLET 	rpm->ramclk = devm_clk_get_enabled(&pdev->dev, "ram");
55135264033SLinus Walleij 	if (IS_ERR(rpm->ramclk)) {
55235264033SLinus Walleij 		ret = PTR_ERR(rpm->ramclk);
55335264033SLinus Walleij 		if (ret == -EPROBE_DEFER)
55435264033SLinus Walleij 			return ret;
55535264033SLinus Walleij 		/*
55635264033SLinus Walleij 		 * Fall through in all other cases, as the clock is
55735264033SLinus Walleij 		 * optional. (Does not exist on all platforms.)
55835264033SLinus Walleij 		 */
55935264033SLinus Walleij 		rpm->ramclk = NULL;
56035264033SLinus Walleij 	}
56135264033SLinus Walleij 
56258e21438SBjorn Andersson 	irq_ack = platform_get_irq_byname(pdev, "ack");
563802d9bd4SStephen Boyd 	if (irq_ack < 0)
56458e21438SBjorn Andersson 		return irq_ack;
56558e21438SBjorn Andersson 
56658e21438SBjorn Andersson 	irq_err = platform_get_irq_byname(pdev, "err");
567802d9bd4SStephen Boyd 	if (irq_err < 0)
56858e21438SBjorn Andersson 		return irq_err;
56958e21438SBjorn Andersson 
57058e21438SBjorn Andersson 	irq_wakeup = platform_get_irq_byname(pdev, "wakeup");
571802d9bd4SStephen Boyd 	if (irq_wakeup < 0)
57258e21438SBjorn Andersson 		return irq_wakeup;
57358e21438SBjorn Andersson 
574*830fafceSRob Herring 	rpm->data = device_get_match_data(&pdev->dev);
575*830fafceSRob Herring 	if (!rpm->data)
576cf1199f7SLABBE Corentin 		return -ENODEV;
57758e21438SBjorn Andersson 
5782e9de58cSYe Xingchen 	rpm->status_regs = devm_platform_get_and_ioremap_resource(pdev, 0, NULL);
57958e21438SBjorn Andersson 	if (IS_ERR(rpm->status_regs))
58058e21438SBjorn Andersson 		return PTR_ERR(rpm->status_regs);
58158e21438SBjorn Andersson 	rpm->ctrl_regs = rpm->status_regs + 0x400;
58258e21438SBjorn Andersson 	rpm->req_regs = rpm->status_regs + 0x600;
58358e21438SBjorn Andersson 
58458e21438SBjorn Andersson 	syscon_np = of_parse_phandle(pdev->dev.of_node, "qcom,ipc", 0);
58558e21438SBjorn Andersson 	if (!syscon_np) {
58658e21438SBjorn Andersson 		dev_err(&pdev->dev, "no qcom,ipc node\n");
58758e21438SBjorn Andersson 		return -ENODEV;
58858e21438SBjorn Andersson 	}
58958e21438SBjorn Andersson 
59058e21438SBjorn Andersson 	rpm->ipc_regmap = syscon_node_to_regmap(syscon_np);
591349290fcSPeter Chen 	of_node_put(syscon_np);
59258e21438SBjorn Andersson 	if (IS_ERR(rpm->ipc_regmap))
59358e21438SBjorn Andersson 		return PTR_ERR(rpm->ipc_regmap);
59458e21438SBjorn Andersson 
59558e21438SBjorn Andersson 	ret = of_property_read_u32_index(pdev->dev.of_node, "qcom,ipc", 1,
59658e21438SBjorn Andersson 					 &rpm->ipc_offset);
59758e21438SBjorn Andersson 	if (ret < 0) {
59858e21438SBjorn Andersson 		dev_err(&pdev->dev, "no offset in qcom,ipc\n");
59958e21438SBjorn Andersson 		return -EINVAL;
60058e21438SBjorn Andersson 	}
60158e21438SBjorn Andersson 
60258e21438SBjorn Andersson 	ret = of_property_read_u32_index(pdev->dev.of_node, "qcom,ipc", 2,
60358e21438SBjorn Andersson 					 &rpm->ipc_bit);
60458e21438SBjorn Andersson 	if (ret < 0) {
60558e21438SBjorn Andersson 		dev_err(&pdev->dev, "no bit in qcom,ipc\n");
60658e21438SBjorn Andersson 		return -EINVAL;
60758e21438SBjorn Andersson 	}
60858e21438SBjorn Andersson 
60958e21438SBjorn Andersson 	dev_set_drvdata(&pdev->dev, rpm);
61058e21438SBjorn Andersson 
61158e21438SBjorn Andersson 	fw_version[0] = readl(RPM_STATUS_REG(rpm, 0));
61258e21438SBjorn Andersson 	fw_version[1] = readl(RPM_STATUS_REG(rpm, 1));
61358e21438SBjorn Andersson 	fw_version[2] = readl(RPM_STATUS_REG(rpm, 2));
61458e21438SBjorn Andersson 	if (fw_version[0] != rpm->data->version) {
61558e21438SBjorn Andersson 		dev_err(&pdev->dev,
61658e21438SBjorn Andersson 			"RPM version %u.%u.%u incompatible with driver version %u",
61758e21438SBjorn Andersson 			fw_version[0],
61858e21438SBjorn Andersson 			fw_version[1],
61958e21438SBjorn Andersson 			fw_version[2],
62058e21438SBjorn Andersson 			rpm->data->version);
62158e21438SBjorn Andersson 		return -EFAULT;
62258e21438SBjorn Andersson 	}
62358e21438SBjorn Andersson 
624504e4175SJonathan Marek 	writel(fw_version[0], RPM_CTRL_REG(rpm, 0));
625504e4175SJonathan Marek 	writel(fw_version[1], RPM_CTRL_REG(rpm, 1));
626504e4175SJonathan Marek 	writel(fw_version[2], RPM_CTRL_REG(rpm, 2));
627504e4175SJonathan Marek 
62858e21438SBjorn Andersson 	dev_info(&pdev->dev, "RPM firmware %u.%u.%u\n", fw_version[0],
62958e21438SBjorn Andersson 							fw_version[1],
63058e21438SBjorn Andersson 							fw_version[2]);
63158e21438SBjorn Andersson 
63258e21438SBjorn Andersson 	ret = devm_request_irq(&pdev->dev,
63358e21438SBjorn Andersson 			       irq_ack,
63458e21438SBjorn Andersson 			       qcom_rpm_ack_interrupt,
635ced7e093SSudeep Holla 			       IRQF_TRIGGER_RISING,
63658e21438SBjorn Andersson 			       "qcom_rpm_ack",
63758e21438SBjorn Andersson 			       rpm);
63858e21438SBjorn Andersson 	if (ret) {
63958e21438SBjorn Andersson 		dev_err(&pdev->dev, "failed to request ack interrupt\n");
64058e21438SBjorn Andersson 		return ret;
64158e21438SBjorn Andersson 	}
64258e21438SBjorn Andersson 
64358e21438SBjorn Andersson 	ret = irq_set_irq_wake(irq_ack, 1);
64458e21438SBjorn Andersson 	if (ret)
64558e21438SBjorn Andersson 		dev_warn(&pdev->dev, "failed to mark ack irq as wakeup\n");
64658e21438SBjorn Andersson 
64758e21438SBjorn Andersson 	ret = devm_request_irq(&pdev->dev,
64858e21438SBjorn Andersson 			       irq_err,
64958e21438SBjorn Andersson 			       qcom_rpm_err_interrupt,
65058e21438SBjorn Andersson 			       IRQF_TRIGGER_RISING,
65158e21438SBjorn Andersson 			       "qcom_rpm_err",
65258e21438SBjorn Andersson 			       rpm);
65358e21438SBjorn Andersson 	if (ret) {
65458e21438SBjorn Andersson 		dev_err(&pdev->dev, "failed to request err interrupt\n");
65558e21438SBjorn Andersson 		return ret;
65658e21438SBjorn Andersson 	}
65758e21438SBjorn Andersson 
65858e21438SBjorn Andersson 	ret = devm_request_irq(&pdev->dev,
65958e21438SBjorn Andersson 			       irq_wakeup,
66058e21438SBjorn Andersson 			       qcom_rpm_wakeup_interrupt,
66158e21438SBjorn Andersson 			       IRQF_TRIGGER_RISING,
66258e21438SBjorn Andersson 			       "qcom_rpm_wakeup",
66358e21438SBjorn Andersson 			       rpm);
66458e21438SBjorn Andersson 	if (ret) {
66558e21438SBjorn Andersson 		dev_err(&pdev->dev, "failed to request wakeup interrupt\n");
66658e21438SBjorn Andersson 		return ret;
66758e21438SBjorn Andersson 	}
66858e21438SBjorn Andersson 
66958e21438SBjorn Andersson 	ret = irq_set_irq_wake(irq_wakeup, 1);
67058e21438SBjorn Andersson 	if (ret)
67158e21438SBjorn Andersson 		dev_warn(&pdev->dev, "failed to mark wakeup irq as wakeup\n");
67258e21438SBjorn Andersson 
673e48dee96SChristophe JAILLET 	return devm_of_platform_populate(&pdev->dev);
67458e21438SBjorn Andersson }
67558e21438SBjorn Andersson 
67658e21438SBjorn Andersson static struct platform_driver qcom_rpm_driver = {
67758e21438SBjorn Andersson 	.probe = qcom_rpm_probe,
67858e21438SBjorn Andersson 	.driver  = {
67958e21438SBjorn Andersson 		.name  = "qcom_rpm",
68058e21438SBjorn Andersson 		.of_match_table = qcom_rpm_of_match,
68158e21438SBjorn Andersson 	},
68258e21438SBjorn Andersson };
68358e21438SBjorn Andersson 
qcom_rpm_init(void)68458e21438SBjorn Andersson static int __init qcom_rpm_init(void)
68558e21438SBjorn Andersson {
68658e21438SBjorn Andersson 	return platform_driver_register(&qcom_rpm_driver);
68758e21438SBjorn Andersson }
68858e21438SBjorn Andersson arch_initcall(qcom_rpm_init);
68958e21438SBjorn Andersson 
qcom_rpm_exit(void)69058e21438SBjorn Andersson static void __exit qcom_rpm_exit(void)
69158e21438SBjorn Andersson {
69258e21438SBjorn Andersson 	platform_driver_unregister(&qcom_rpm_driver);
69358e21438SBjorn Andersson }
69458e21438SBjorn Andersson module_exit(qcom_rpm_exit)
69558e21438SBjorn Andersson 
69658e21438SBjorn Andersson MODULE_DESCRIPTION("Qualcomm Resource Power Manager driver");
69758e21438SBjorn Andersson MODULE_LICENSE("GPL v2");
69858e21438SBjorn Andersson MODULE_AUTHOR("Bjorn Andersson <bjorn.andersson@sonymobile.com>");
699