2 * Copyright (c) 2017, Impinj, Inc.
4 * i.MX7 System Reset Controller (SRC) driver
6 * Author: Andrey Smirnov <andrew.smirnov@gmail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
18 #include <linux/mfd/syscon.h>
19 #include <linux/platform_device.h>
20 #include <linux/reset-controller.h>
21 #include <linux/regmap.h>
22 #include <dt-bindings/reset/imx7-reset.h>
25 struct reset_controller_dev rcdev
;
26 struct regmap
*regmap
;
29 enum imx7_src_registers
{
33 SRC_HSICPHY_RCR
= 0x001c,
34 SRC_USBOPHY1_RCR
= 0x0020,
35 SRC_USBOPHY2_RCR
= 0x0024,
36 SRC_MIPIPHY_RCR
= 0x0028,
37 SRC_PCIEPHY_RCR
= 0x002c,
38 SRC_DDRC_RCR
= 0x1000,
41 struct imx7_src_signal
{
42 unsigned int offset
, bit
;
45 static const struct imx7_src_signal imx7_src_signals
[IMX7_RESET_NUM
] = {
46 [IMX7_RESET_A7_CORE_POR_RESET0
] = { SRC_A7RCR0
, BIT(0) },
47 [IMX7_RESET_A7_CORE_POR_RESET1
] = { SRC_A7RCR0
, BIT(1) },
48 [IMX7_RESET_A7_CORE_RESET0
] = { SRC_A7RCR0
, BIT(4) },
49 [IMX7_RESET_A7_CORE_RESET1
] = { SRC_A7RCR0
, BIT(5) },
50 [IMX7_RESET_A7_DBG_RESET0
] = { SRC_A7RCR0
, BIT(8) },
51 [IMX7_RESET_A7_DBG_RESET1
] = { SRC_A7RCR0
, BIT(9) },
52 [IMX7_RESET_A7_ETM_RESET0
] = { SRC_A7RCR0
, BIT(12) },
53 [IMX7_RESET_A7_ETM_RESET1
] = { SRC_A7RCR0
, BIT(13) },
54 [IMX7_RESET_A7_SOC_DBG_RESET
] = { SRC_A7RCR0
, BIT(20) },
55 [IMX7_RESET_A7_L2RESET
] = { SRC_A7RCR0
, BIT(21) },
56 [IMX7_RESET_SW_M4C_RST
] = { SRC_M4RCR
, BIT(1) },
57 [IMX7_RESET_SW_M4P_RST
] = { SRC_M4RCR
, BIT(2) },
58 [IMX7_RESET_EIM_RST
] = { SRC_ERCR
, BIT(0) },
59 [IMX7_RESET_HSICPHY_PORT_RST
] = { SRC_HSICPHY_RCR
, BIT(1) },
60 [IMX7_RESET_USBPHY1_POR
] = { SRC_USBOPHY1_RCR
, BIT(0) },
61 [IMX7_RESET_USBPHY1_PORT_RST
] = { SRC_USBOPHY1_RCR
, BIT(1) },
62 [IMX7_RESET_USBPHY2_POR
] = { SRC_USBOPHY2_RCR
, BIT(0) },
63 [IMX7_RESET_USBPHY2_PORT_RST
] = { SRC_USBOPHY2_RCR
, BIT(1) },
64 [IMX7_RESET_MIPI_PHY_MRST
] = { SRC_MIPIPHY_RCR
, BIT(1) },
65 [IMX7_RESET_MIPI_PHY_SRST
] = { SRC_MIPIPHY_RCR
, BIT(2) },
66 [IMX7_RESET_PCIEPHY
] = { SRC_PCIEPHY_RCR
, BIT(2) | BIT(1) },
67 [IMX7_RESET_PCIEPHY_PERST
] = { SRC_PCIEPHY_RCR
, BIT(3) },
68 [IMX7_RESET_PCIE_CTRL_APPS_EN
] = { SRC_PCIEPHY_RCR
, BIT(6) },
69 [IMX7_RESET_DDRC_PRST
] = { SRC_DDRC_RCR
, BIT(0) },
70 [IMX7_RESET_DDRC_CORE_RST
] = { SRC_DDRC_RCR
, BIT(1) },
73 static struct imx7_src
*to_imx7_src(struct reset_controller_dev
*rcdev
)
75 return container_of(rcdev
, struct imx7_src
, rcdev
);
78 static int imx7_reset_set(struct reset_controller_dev
*rcdev
,
79 unsigned long id
, bool assert)
81 struct imx7_src
*imx7src
= to_imx7_src(rcdev
);
82 const struct imx7_src_signal
*signal
= &imx7_src_signals
[id
];
83 unsigned int value
= 0;
86 case IMX7_RESET_PCIEPHY
:
88 * wait for more than 10us to release phy g_rst and
95 case IMX7_RESET_PCIE_CTRL_APPS_EN
:
96 value
= (assert) ? 0 : signal
->bit
;
100 return regmap_update_bits(imx7src
->regmap
,
101 signal
->offset
, signal
->bit
, value
);
104 static int imx7_reset_assert(struct reset_controller_dev
*rcdev
,
107 return imx7_reset_set(rcdev
, id
, true);
110 static int imx7_reset_deassert(struct reset_controller_dev
*rcdev
,
113 return imx7_reset_set(rcdev
, id
, false);
116 static const struct reset_control_ops imx7_reset_ops
= {
117 .assert = imx7_reset_assert
,
118 .deassert
= imx7_reset_deassert
,
121 static int imx7_reset_probe(struct platform_device
*pdev
)
123 struct imx7_src
*imx7src
;
124 struct device
*dev
= &pdev
->dev
;
125 struct regmap_config config
= { .name
= "src" };
127 imx7src
= devm_kzalloc(dev
, sizeof(*imx7src
), GFP_KERNEL
);
131 imx7src
->regmap
= syscon_node_to_regmap(dev
->of_node
);
132 if (IS_ERR(imx7src
->regmap
)) {
133 dev_err(dev
, "Unable to get imx7-src regmap");
134 return PTR_ERR(imx7src
->regmap
);
136 regmap_attach_dev(dev
, imx7src
->regmap
, &config
);
138 imx7src
->rcdev
.owner
= THIS_MODULE
;
139 imx7src
->rcdev
.nr_resets
= IMX7_RESET_NUM
;
140 imx7src
->rcdev
.ops
= &imx7_reset_ops
;
141 imx7src
->rcdev
.of_node
= dev
->of_node
;
143 return devm_reset_controller_register(dev
, &imx7src
->rcdev
);
146 static const struct of_device_id imx7_reset_dt_ids
[] = {
147 { .compatible
= "fsl,imx7d-src", },
151 static struct platform_driver imx7_reset_driver
= {
152 .probe
= imx7_reset_probe
,
154 .name
= KBUILD_MODNAME
,
155 .of_match_table
= imx7_reset_dt_ids
,
158 builtin_platform_driver(imx7_reset_driver
);