18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2016 Socionext Inc. 48c2ecf20Sopenharmony_ci * Author: Masahiro Yamada <yamada.masahiro@socionext.com> 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#include <linux/mfd/syscon.h> 88c2ecf20Sopenharmony_ci#include <linux/module.h> 98c2ecf20Sopenharmony_ci#include <linux/of.h> 108c2ecf20Sopenharmony_ci#include <linux/of_device.h> 118c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 128c2ecf20Sopenharmony_ci#include <linux/regmap.h> 138c2ecf20Sopenharmony_ci#include <linux/reset-controller.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_cistruct uniphier_reset_data { 168c2ecf20Sopenharmony_ci unsigned int id; 178c2ecf20Sopenharmony_ci unsigned int reg; 188c2ecf20Sopenharmony_ci unsigned int bit; 198c2ecf20Sopenharmony_ci unsigned int flags; 208c2ecf20Sopenharmony_ci#define UNIPHIER_RESET_ACTIVE_LOW BIT(0) 218c2ecf20Sopenharmony_ci}; 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define UNIPHIER_RESET_ID_END (unsigned int)(-1) 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#define UNIPHIER_RESET_END \ 268c2ecf20Sopenharmony_ci { .id = UNIPHIER_RESET_ID_END } 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#define UNIPHIER_RESET(_id, _reg, _bit) \ 298c2ecf20Sopenharmony_ci { \ 308c2ecf20Sopenharmony_ci .id = (_id), \ 318c2ecf20Sopenharmony_ci .reg = (_reg), \ 328c2ecf20Sopenharmony_ci .bit = (_bit), \ 338c2ecf20Sopenharmony_ci } 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#define UNIPHIER_RESETX(_id, _reg, _bit) \ 368c2ecf20Sopenharmony_ci { \ 378c2ecf20Sopenharmony_ci .id = (_id), \ 388c2ecf20Sopenharmony_ci .reg = (_reg), \ 398c2ecf20Sopenharmony_ci .bit = (_bit), \ 408c2ecf20Sopenharmony_ci .flags = UNIPHIER_RESET_ACTIVE_LOW, \ 418c2ecf20Sopenharmony_ci } 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci/* System reset data */ 448c2ecf20Sopenharmony_cistatic const struct uniphier_reset_data uniphier_ld4_sys_reset_data[] = { 458c2ecf20Sopenharmony_ci UNIPHIER_RESETX(2, 0x2000, 2), /* NAND */ 468c2ecf20Sopenharmony_ci UNIPHIER_RESETX(8, 0x2000, 10), /* STDMAC (Ether, HSC, MIO) */ 478c2ecf20Sopenharmony_ci UNIPHIER_RESET_END, 488c2ecf20Sopenharmony_ci}; 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_cistatic const struct uniphier_reset_data uniphier_pro4_sys_reset_data[] = { 518c2ecf20Sopenharmony_ci UNIPHIER_RESETX(2, 0x2000, 2), /* NAND */ 528c2ecf20Sopenharmony_ci UNIPHIER_RESETX(6, 0x2000, 12), /* Ether */ 538c2ecf20Sopenharmony_ci UNIPHIER_RESETX(8, 0x2000, 10), /* STDMAC (HSC, MIO, RLE) */ 548c2ecf20Sopenharmony_ci UNIPHIER_RESETX(12, 0x2000, 6), /* GIO (Ether, SATA, USB3) */ 558c2ecf20Sopenharmony_ci UNIPHIER_RESETX(14, 0x2000, 17), /* USB30 */ 568c2ecf20Sopenharmony_ci UNIPHIER_RESETX(15, 0x2004, 17), /* USB31 */ 578c2ecf20Sopenharmony_ci UNIPHIER_RESETX(28, 0x2000, 18), /* SATA0 */ 588c2ecf20Sopenharmony_ci UNIPHIER_RESETX(29, 0x2004, 18), /* SATA1 */ 598c2ecf20Sopenharmony_ci UNIPHIER_RESETX(30, 0x2000, 19), /* SATA-PHY */ 608c2ecf20Sopenharmony_ci UNIPHIER_RESETX(40, 0x2000, 13), /* AIO */ 618c2ecf20Sopenharmony_ci UNIPHIER_RESET_END, 628c2ecf20Sopenharmony_ci}; 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_cistatic const struct uniphier_reset_data uniphier_pro5_sys_reset_data[] = { 658c2ecf20Sopenharmony_ci UNIPHIER_RESETX(2, 0x2000, 2), /* NAND */ 668c2ecf20Sopenharmony_ci UNIPHIER_RESETX(8, 0x2000, 10), /* STDMAC (HSC) */ 678c2ecf20Sopenharmony_ci UNIPHIER_RESETX(12, 0x2000, 6), /* GIO (PCIe, USB3) */ 688c2ecf20Sopenharmony_ci UNIPHIER_RESETX(14, 0x2000, 17), /* USB30 */ 698c2ecf20Sopenharmony_ci UNIPHIER_RESETX(15, 0x2004, 17), /* USB31 */ 708c2ecf20Sopenharmony_ci UNIPHIER_RESETX(24, 0x2008, 2), /* PCIe */ 718c2ecf20Sopenharmony_ci UNIPHIER_RESETX(40, 0x2000, 13), /* AIO */ 728c2ecf20Sopenharmony_ci UNIPHIER_RESET_END, 738c2ecf20Sopenharmony_ci}; 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_cistatic const struct uniphier_reset_data uniphier_pxs2_sys_reset_data[] = { 768c2ecf20Sopenharmony_ci UNIPHIER_RESETX(2, 0x2000, 2), /* NAND */ 778c2ecf20Sopenharmony_ci UNIPHIER_RESETX(6, 0x2000, 12), /* Ether */ 788c2ecf20Sopenharmony_ci UNIPHIER_RESETX(8, 0x2000, 10), /* STDMAC (HSC, RLE) */ 798c2ecf20Sopenharmony_ci UNIPHIER_RESETX(14, 0x2000, 17), /* USB30 */ 808c2ecf20Sopenharmony_ci UNIPHIER_RESETX(15, 0x2004, 17), /* USB31 */ 818c2ecf20Sopenharmony_ci UNIPHIER_RESETX(16, 0x2014, 4), /* USB30-PHY0 */ 828c2ecf20Sopenharmony_ci UNIPHIER_RESETX(17, 0x2014, 0), /* USB30-PHY1 */ 838c2ecf20Sopenharmony_ci UNIPHIER_RESETX(18, 0x2014, 2), /* USB30-PHY2 */ 848c2ecf20Sopenharmony_ci UNIPHIER_RESETX(20, 0x2014, 5), /* USB31-PHY0 */ 858c2ecf20Sopenharmony_ci UNIPHIER_RESETX(21, 0x2014, 1), /* USB31-PHY1 */ 868c2ecf20Sopenharmony_ci UNIPHIER_RESETX(28, 0x2014, 12), /* SATA */ 878c2ecf20Sopenharmony_ci UNIPHIER_RESET(30, 0x2014, 8), /* SATA-PHY (active high) */ 888c2ecf20Sopenharmony_ci UNIPHIER_RESETX(40, 0x2000, 13), /* AIO */ 898c2ecf20Sopenharmony_ci UNIPHIER_RESET_END, 908c2ecf20Sopenharmony_ci}; 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_cistatic const struct uniphier_reset_data uniphier_ld11_sys_reset_data[] = { 938c2ecf20Sopenharmony_ci UNIPHIER_RESETX(2, 0x200c, 0), /* NAND */ 948c2ecf20Sopenharmony_ci UNIPHIER_RESETX(4, 0x200c, 2), /* eMMC */ 958c2ecf20Sopenharmony_ci UNIPHIER_RESETX(6, 0x200c, 6), /* Ether */ 968c2ecf20Sopenharmony_ci UNIPHIER_RESETX(8, 0x200c, 8), /* STDMAC (HSC, MIO) */ 978c2ecf20Sopenharmony_ci UNIPHIER_RESETX(9, 0x200c, 9), /* HSC */ 988c2ecf20Sopenharmony_ci UNIPHIER_RESETX(40, 0x2008, 0), /* AIO */ 998c2ecf20Sopenharmony_ci UNIPHIER_RESETX(41, 0x2008, 1), /* EVEA */ 1008c2ecf20Sopenharmony_ci UNIPHIER_RESETX(42, 0x2010, 2), /* EXIV */ 1018c2ecf20Sopenharmony_ci UNIPHIER_RESET_END, 1028c2ecf20Sopenharmony_ci}; 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_cistatic const struct uniphier_reset_data uniphier_ld20_sys_reset_data[] = { 1058c2ecf20Sopenharmony_ci UNIPHIER_RESETX(2, 0x200c, 0), /* NAND */ 1068c2ecf20Sopenharmony_ci UNIPHIER_RESETX(4, 0x200c, 2), /* eMMC */ 1078c2ecf20Sopenharmony_ci UNIPHIER_RESETX(6, 0x200c, 6), /* Ether */ 1088c2ecf20Sopenharmony_ci UNIPHIER_RESETX(8, 0x200c, 8), /* STDMAC (HSC) */ 1098c2ecf20Sopenharmony_ci UNIPHIER_RESETX(9, 0x200c, 9), /* HSC */ 1108c2ecf20Sopenharmony_ci UNIPHIER_RESETX(14, 0x200c, 5), /* USB30 */ 1118c2ecf20Sopenharmony_ci UNIPHIER_RESETX(16, 0x200c, 12), /* USB30-PHY0 */ 1128c2ecf20Sopenharmony_ci UNIPHIER_RESETX(17, 0x200c, 13), /* USB30-PHY1 */ 1138c2ecf20Sopenharmony_ci UNIPHIER_RESETX(18, 0x200c, 14), /* USB30-PHY2 */ 1148c2ecf20Sopenharmony_ci UNIPHIER_RESETX(19, 0x200c, 15), /* USB30-PHY3 */ 1158c2ecf20Sopenharmony_ci UNIPHIER_RESETX(24, 0x200c, 4), /* PCIe */ 1168c2ecf20Sopenharmony_ci UNIPHIER_RESETX(40, 0x2008, 0), /* AIO */ 1178c2ecf20Sopenharmony_ci UNIPHIER_RESETX(41, 0x2008, 1), /* EVEA */ 1188c2ecf20Sopenharmony_ci UNIPHIER_RESETX(42, 0x2010, 2), /* EXIV */ 1198c2ecf20Sopenharmony_ci UNIPHIER_RESET_END, 1208c2ecf20Sopenharmony_ci}; 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_cistatic const struct uniphier_reset_data uniphier_pxs3_sys_reset_data[] = { 1238c2ecf20Sopenharmony_ci UNIPHIER_RESETX(2, 0x200c, 0), /* NAND */ 1248c2ecf20Sopenharmony_ci UNIPHIER_RESETX(4, 0x200c, 2), /* eMMC */ 1258c2ecf20Sopenharmony_ci UNIPHIER_RESETX(6, 0x200c, 9), /* Ether0 */ 1268c2ecf20Sopenharmony_ci UNIPHIER_RESETX(7, 0x200c, 10), /* Ether1 */ 1278c2ecf20Sopenharmony_ci UNIPHIER_RESETX(8, 0x200c, 12), /* STDMAC */ 1288c2ecf20Sopenharmony_ci UNIPHIER_RESETX(12, 0x200c, 4), /* USB30 link */ 1298c2ecf20Sopenharmony_ci UNIPHIER_RESETX(13, 0x200c, 5), /* USB31 link */ 1308c2ecf20Sopenharmony_ci UNIPHIER_RESETX(16, 0x200c, 16), /* USB30-PHY0 */ 1318c2ecf20Sopenharmony_ci UNIPHIER_RESETX(17, 0x200c, 18), /* USB30-PHY1 */ 1328c2ecf20Sopenharmony_ci UNIPHIER_RESETX(18, 0x200c, 20), /* USB30-PHY2 */ 1338c2ecf20Sopenharmony_ci UNIPHIER_RESETX(20, 0x200c, 17), /* USB31-PHY0 */ 1348c2ecf20Sopenharmony_ci UNIPHIER_RESETX(21, 0x200c, 19), /* USB31-PHY1 */ 1358c2ecf20Sopenharmony_ci UNIPHIER_RESETX(24, 0x200c, 3), /* PCIe */ 1368c2ecf20Sopenharmony_ci UNIPHIER_RESETX(28, 0x200c, 7), /* SATA0 */ 1378c2ecf20Sopenharmony_ci UNIPHIER_RESETX(29, 0x200c, 8), /* SATA1 */ 1388c2ecf20Sopenharmony_ci UNIPHIER_RESETX(30, 0x200c, 21), /* SATA-PHY */ 1398c2ecf20Sopenharmony_ci UNIPHIER_RESET_END, 1408c2ecf20Sopenharmony_ci}; 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci/* Media I/O reset data */ 1438c2ecf20Sopenharmony_ci#define UNIPHIER_MIO_RESET_SD(id, ch) \ 1448c2ecf20Sopenharmony_ci UNIPHIER_RESETX((id), 0x110 + 0x200 * (ch), 0) 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci#define UNIPHIER_MIO_RESET_SD_BRIDGE(id, ch) \ 1478c2ecf20Sopenharmony_ci UNIPHIER_RESETX((id), 0x110 + 0x200 * (ch), 26) 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci#define UNIPHIER_MIO_RESET_EMMC_HW_RESET(id, ch) \ 1508c2ecf20Sopenharmony_ci UNIPHIER_RESETX((id), 0x80 + 0x200 * (ch), 0) 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci#define UNIPHIER_MIO_RESET_USB2(id, ch) \ 1538c2ecf20Sopenharmony_ci UNIPHIER_RESETX((id), 0x114 + 0x200 * (ch), 0) 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci#define UNIPHIER_MIO_RESET_USB2_BRIDGE(id, ch) \ 1568c2ecf20Sopenharmony_ci UNIPHIER_RESETX((id), 0x110 + 0x200 * (ch), 24) 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci#define UNIPHIER_MIO_RESET_DMAC(id) \ 1598c2ecf20Sopenharmony_ci UNIPHIER_RESETX((id), 0x110, 17) 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_cistatic const struct uniphier_reset_data uniphier_ld4_mio_reset_data[] = { 1628c2ecf20Sopenharmony_ci UNIPHIER_MIO_RESET_SD(0, 0), 1638c2ecf20Sopenharmony_ci UNIPHIER_MIO_RESET_SD(1, 1), 1648c2ecf20Sopenharmony_ci UNIPHIER_MIO_RESET_SD(2, 2), 1658c2ecf20Sopenharmony_ci UNIPHIER_MIO_RESET_SD_BRIDGE(3, 0), 1668c2ecf20Sopenharmony_ci UNIPHIER_MIO_RESET_SD_BRIDGE(4, 1), 1678c2ecf20Sopenharmony_ci UNIPHIER_MIO_RESET_SD_BRIDGE(5, 2), 1688c2ecf20Sopenharmony_ci UNIPHIER_MIO_RESET_EMMC_HW_RESET(6, 1), 1698c2ecf20Sopenharmony_ci UNIPHIER_MIO_RESET_DMAC(7), 1708c2ecf20Sopenharmony_ci UNIPHIER_MIO_RESET_USB2(8, 0), 1718c2ecf20Sopenharmony_ci UNIPHIER_MIO_RESET_USB2(9, 1), 1728c2ecf20Sopenharmony_ci UNIPHIER_MIO_RESET_USB2(10, 2), 1738c2ecf20Sopenharmony_ci UNIPHIER_MIO_RESET_USB2_BRIDGE(12, 0), 1748c2ecf20Sopenharmony_ci UNIPHIER_MIO_RESET_USB2_BRIDGE(13, 1), 1758c2ecf20Sopenharmony_ci UNIPHIER_MIO_RESET_USB2_BRIDGE(14, 2), 1768c2ecf20Sopenharmony_ci UNIPHIER_RESET_END, 1778c2ecf20Sopenharmony_ci}; 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_cistatic const struct uniphier_reset_data uniphier_pro5_sd_reset_data[] = { 1808c2ecf20Sopenharmony_ci UNIPHIER_MIO_RESET_SD(0, 0), 1818c2ecf20Sopenharmony_ci UNIPHIER_MIO_RESET_SD(1, 1), 1828c2ecf20Sopenharmony_ci UNIPHIER_MIO_RESET_EMMC_HW_RESET(6, 1), 1838c2ecf20Sopenharmony_ci UNIPHIER_RESET_END, 1848c2ecf20Sopenharmony_ci}; 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci/* Peripheral reset data */ 1878c2ecf20Sopenharmony_ci#define UNIPHIER_PERI_RESET_UART(id, ch) \ 1888c2ecf20Sopenharmony_ci UNIPHIER_RESETX((id), 0x114, 19 + (ch)) 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci#define UNIPHIER_PERI_RESET_I2C(id, ch) \ 1918c2ecf20Sopenharmony_ci UNIPHIER_RESETX((id), 0x114, 5 + (ch)) 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ci#define UNIPHIER_PERI_RESET_FI2C(id, ch) \ 1948c2ecf20Sopenharmony_ci UNIPHIER_RESETX((id), 0x114, 24 + (ch)) 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ci#define UNIPHIER_PERI_RESET_SCSSI(id, ch) \ 1978c2ecf20Sopenharmony_ci UNIPHIER_RESETX((id), 0x110, 17 + (ch)) 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci#define UNIPHIER_PERI_RESET_MCSSI(id) \ 2008c2ecf20Sopenharmony_ci UNIPHIER_RESETX((id), 0x114, 14) 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_cistatic const struct uniphier_reset_data uniphier_ld4_peri_reset_data[] = { 2038c2ecf20Sopenharmony_ci UNIPHIER_PERI_RESET_UART(0, 0), 2048c2ecf20Sopenharmony_ci UNIPHIER_PERI_RESET_UART(1, 1), 2058c2ecf20Sopenharmony_ci UNIPHIER_PERI_RESET_UART(2, 2), 2068c2ecf20Sopenharmony_ci UNIPHIER_PERI_RESET_UART(3, 3), 2078c2ecf20Sopenharmony_ci UNIPHIER_PERI_RESET_I2C(4, 0), 2088c2ecf20Sopenharmony_ci UNIPHIER_PERI_RESET_I2C(5, 1), 2098c2ecf20Sopenharmony_ci UNIPHIER_PERI_RESET_I2C(6, 2), 2108c2ecf20Sopenharmony_ci UNIPHIER_PERI_RESET_I2C(7, 3), 2118c2ecf20Sopenharmony_ci UNIPHIER_PERI_RESET_I2C(8, 4), 2128c2ecf20Sopenharmony_ci UNIPHIER_PERI_RESET_SCSSI(11, 0), 2138c2ecf20Sopenharmony_ci UNIPHIER_RESET_END, 2148c2ecf20Sopenharmony_ci}; 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_cistatic const struct uniphier_reset_data uniphier_pro4_peri_reset_data[] = { 2178c2ecf20Sopenharmony_ci UNIPHIER_PERI_RESET_UART(0, 0), 2188c2ecf20Sopenharmony_ci UNIPHIER_PERI_RESET_UART(1, 1), 2198c2ecf20Sopenharmony_ci UNIPHIER_PERI_RESET_UART(2, 2), 2208c2ecf20Sopenharmony_ci UNIPHIER_PERI_RESET_UART(3, 3), 2218c2ecf20Sopenharmony_ci UNIPHIER_PERI_RESET_FI2C(4, 0), 2228c2ecf20Sopenharmony_ci UNIPHIER_PERI_RESET_FI2C(5, 1), 2238c2ecf20Sopenharmony_ci UNIPHIER_PERI_RESET_FI2C(6, 2), 2248c2ecf20Sopenharmony_ci UNIPHIER_PERI_RESET_FI2C(7, 3), 2258c2ecf20Sopenharmony_ci UNIPHIER_PERI_RESET_FI2C(8, 4), 2268c2ecf20Sopenharmony_ci UNIPHIER_PERI_RESET_FI2C(9, 5), 2278c2ecf20Sopenharmony_ci UNIPHIER_PERI_RESET_FI2C(10, 6), 2288c2ecf20Sopenharmony_ci UNIPHIER_PERI_RESET_SCSSI(11, 0), 2298c2ecf20Sopenharmony_ci UNIPHIER_PERI_RESET_SCSSI(12, 1), 2308c2ecf20Sopenharmony_ci UNIPHIER_PERI_RESET_SCSSI(13, 2), 2318c2ecf20Sopenharmony_ci UNIPHIER_PERI_RESET_SCSSI(14, 3), 2328c2ecf20Sopenharmony_ci UNIPHIER_PERI_RESET_MCSSI(15), 2338c2ecf20Sopenharmony_ci UNIPHIER_RESET_END, 2348c2ecf20Sopenharmony_ci}; 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_ci/* Analog signal amplifiers reset data */ 2378c2ecf20Sopenharmony_cistatic const struct uniphier_reset_data uniphier_ld11_adamv_reset_data[] = { 2388c2ecf20Sopenharmony_ci UNIPHIER_RESETX(0, 0x10, 6), /* EVEA */ 2398c2ecf20Sopenharmony_ci UNIPHIER_RESET_END, 2408c2ecf20Sopenharmony_ci}; 2418c2ecf20Sopenharmony_ci 2428c2ecf20Sopenharmony_ci/* core implementaton */ 2438c2ecf20Sopenharmony_cistruct uniphier_reset_priv { 2448c2ecf20Sopenharmony_ci struct reset_controller_dev rcdev; 2458c2ecf20Sopenharmony_ci struct device *dev; 2468c2ecf20Sopenharmony_ci struct regmap *regmap; 2478c2ecf20Sopenharmony_ci const struct uniphier_reset_data *data; 2488c2ecf20Sopenharmony_ci}; 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci#define to_uniphier_reset_priv(_rcdev) \ 2518c2ecf20Sopenharmony_ci container_of(_rcdev, struct uniphier_reset_priv, rcdev) 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_cistatic int uniphier_reset_update(struct reset_controller_dev *rcdev, 2548c2ecf20Sopenharmony_ci unsigned long id, int assert) 2558c2ecf20Sopenharmony_ci{ 2568c2ecf20Sopenharmony_ci struct uniphier_reset_priv *priv = to_uniphier_reset_priv(rcdev); 2578c2ecf20Sopenharmony_ci const struct uniphier_reset_data *p; 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ci for (p = priv->data; p->id != UNIPHIER_RESET_ID_END; p++) { 2608c2ecf20Sopenharmony_ci unsigned int mask, val; 2618c2ecf20Sopenharmony_ci 2628c2ecf20Sopenharmony_ci if (p->id != id) 2638c2ecf20Sopenharmony_ci continue; 2648c2ecf20Sopenharmony_ci 2658c2ecf20Sopenharmony_ci mask = BIT(p->bit); 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ci if (assert) 2688c2ecf20Sopenharmony_ci val = mask; 2698c2ecf20Sopenharmony_ci else 2708c2ecf20Sopenharmony_ci val = ~mask; 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci if (p->flags & UNIPHIER_RESET_ACTIVE_LOW) 2738c2ecf20Sopenharmony_ci val = ~val; 2748c2ecf20Sopenharmony_ci 2758c2ecf20Sopenharmony_ci return regmap_write_bits(priv->regmap, p->reg, mask, val); 2768c2ecf20Sopenharmony_ci } 2778c2ecf20Sopenharmony_ci 2788c2ecf20Sopenharmony_ci dev_err(priv->dev, "reset_id=%lu was not handled\n", id); 2798c2ecf20Sopenharmony_ci return -EINVAL; 2808c2ecf20Sopenharmony_ci} 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_cistatic int uniphier_reset_assert(struct reset_controller_dev *rcdev, 2838c2ecf20Sopenharmony_ci unsigned long id) 2848c2ecf20Sopenharmony_ci{ 2858c2ecf20Sopenharmony_ci return uniphier_reset_update(rcdev, id, 1); 2868c2ecf20Sopenharmony_ci} 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_cistatic int uniphier_reset_deassert(struct reset_controller_dev *rcdev, 2898c2ecf20Sopenharmony_ci unsigned long id) 2908c2ecf20Sopenharmony_ci{ 2918c2ecf20Sopenharmony_ci return uniphier_reset_update(rcdev, id, 0); 2928c2ecf20Sopenharmony_ci} 2938c2ecf20Sopenharmony_ci 2948c2ecf20Sopenharmony_cistatic int uniphier_reset_status(struct reset_controller_dev *rcdev, 2958c2ecf20Sopenharmony_ci unsigned long id) 2968c2ecf20Sopenharmony_ci{ 2978c2ecf20Sopenharmony_ci struct uniphier_reset_priv *priv = to_uniphier_reset_priv(rcdev); 2988c2ecf20Sopenharmony_ci const struct uniphier_reset_data *p; 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci for (p = priv->data; p->id != UNIPHIER_RESET_ID_END; p++) { 3018c2ecf20Sopenharmony_ci unsigned int val; 3028c2ecf20Sopenharmony_ci int ret, asserted; 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci if (p->id != id) 3058c2ecf20Sopenharmony_ci continue; 3068c2ecf20Sopenharmony_ci 3078c2ecf20Sopenharmony_ci ret = regmap_read(priv->regmap, p->reg, &val); 3088c2ecf20Sopenharmony_ci if (ret) 3098c2ecf20Sopenharmony_ci return ret; 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_ci asserted = !!(val & BIT(p->bit)); 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci if (p->flags & UNIPHIER_RESET_ACTIVE_LOW) 3148c2ecf20Sopenharmony_ci asserted = !asserted; 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_ci return asserted; 3178c2ecf20Sopenharmony_ci } 3188c2ecf20Sopenharmony_ci 3198c2ecf20Sopenharmony_ci dev_err(priv->dev, "reset_id=%lu was not found\n", id); 3208c2ecf20Sopenharmony_ci return -EINVAL; 3218c2ecf20Sopenharmony_ci} 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_cistatic const struct reset_control_ops uniphier_reset_ops = { 3248c2ecf20Sopenharmony_ci .assert = uniphier_reset_assert, 3258c2ecf20Sopenharmony_ci .deassert = uniphier_reset_deassert, 3268c2ecf20Sopenharmony_ci .status = uniphier_reset_status, 3278c2ecf20Sopenharmony_ci}; 3288c2ecf20Sopenharmony_ci 3298c2ecf20Sopenharmony_cistatic int uniphier_reset_probe(struct platform_device *pdev) 3308c2ecf20Sopenharmony_ci{ 3318c2ecf20Sopenharmony_ci struct device *dev = &pdev->dev; 3328c2ecf20Sopenharmony_ci struct uniphier_reset_priv *priv; 3338c2ecf20Sopenharmony_ci const struct uniphier_reset_data *p, *data; 3348c2ecf20Sopenharmony_ci struct regmap *regmap; 3358c2ecf20Sopenharmony_ci struct device_node *parent; 3368c2ecf20Sopenharmony_ci unsigned int nr_resets = 0; 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci data = of_device_get_match_data(dev); 3398c2ecf20Sopenharmony_ci if (WARN_ON(!data)) 3408c2ecf20Sopenharmony_ci return -EINVAL; 3418c2ecf20Sopenharmony_ci 3428c2ecf20Sopenharmony_ci parent = of_get_parent(dev->of_node); /* parent should be syscon node */ 3438c2ecf20Sopenharmony_ci regmap = syscon_node_to_regmap(parent); 3448c2ecf20Sopenharmony_ci of_node_put(parent); 3458c2ecf20Sopenharmony_ci if (IS_ERR(regmap)) { 3468c2ecf20Sopenharmony_ci dev_err(dev, "failed to get regmap (error %ld)\n", 3478c2ecf20Sopenharmony_ci PTR_ERR(regmap)); 3488c2ecf20Sopenharmony_ci return PTR_ERR(regmap); 3498c2ecf20Sopenharmony_ci } 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_ci priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 3528c2ecf20Sopenharmony_ci if (!priv) 3538c2ecf20Sopenharmony_ci return -ENOMEM; 3548c2ecf20Sopenharmony_ci 3558c2ecf20Sopenharmony_ci for (p = data; p->id != UNIPHIER_RESET_ID_END; p++) 3568c2ecf20Sopenharmony_ci nr_resets = max(nr_resets, p->id + 1); 3578c2ecf20Sopenharmony_ci 3588c2ecf20Sopenharmony_ci priv->rcdev.ops = &uniphier_reset_ops; 3598c2ecf20Sopenharmony_ci priv->rcdev.owner = dev->driver->owner; 3608c2ecf20Sopenharmony_ci priv->rcdev.of_node = dev->of_node; 3618c2ecf20Sopenharmony_ci priv->rcdev.nr_resets = nr_resets; 3628c2ecf20Sopenharmony_ci priv->dev = dev; 3638c2ecf20Sopenharmony_ci priv->regmap = regmap; 3648c2ecf20Sopenharmony_ci priv->data = data; 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_ci return devm_reset_controller_register(&pdev->dev, &priv->rcdev); 3678c2ecf20Sopenharmony_ci} 3688c2ecf20Sopenharmony_ci 3698c2ecf20Sopenharmony_cistatic const struct of_device_id uniphier_reset_match[] = { 3708c2ecf20Sopenharmony_ci /* System reset */ 3718c2ecf20Sopenharmony_ci { 3728c2ecf20Sopenharmony_ci .compatible = "socionext,uniphier-ld4-reset", 3738c2ecf20Sopenharmony_ci .data = uniphier_ld4_sys_reset_data, 3748c2ecf20Sopenharmony_ci }, 3758c2ecf20Sopenharmony_ci { 3768c2ecf20Sopenharmony_ci .compatible = "socionext,uniphier-pro4-reset", 3778c2ecf20Sopenharmony_ci .data = uniphier_pro4_sys_reset_data, 3788c2ecf20Sopenharmony_ci }, 3798c2ecf20Sopenharmony_ci { 3808c2ecf20Sopenharmony_ci .compatible = "socionext,uniphier-sld8-reset", 3818c2ecf20Sopenharmony_ci .data = uniphier_ld4_sys_reset_data, 3828c2ecf20Sopenharmony_ci }, 3838c2ecf20Sopenharmony_ci { 3848c2ecf20Sopenharmony_ci .compatible = "socionext,uniphier-pro5-reset", 3858c2ecf20Sopenharmony_ci .data = uniphier_pro5_sys_reset_data, 3868c2ecf20Sopenharmony_ci }, 3878c2ecf20Sopenharmony_ci { 3888c2ecf20Sopenharmony_ci .compatible = "socionext,uniphier-pxs2-reset", 3898c2ecf20Sopenharmony_ci .data = uniphier_pxs2_sys_reset_data, 3908c2ecf20Sopenharmony_ci }, 3918c2ecf20Sopenharmony_ci { 3928c2ecf20Sopenharmony_ci .compatible = "socionext,uniphier-ld11-reset", 3938c2ecf20Sopenharmony_ci .data = uniphier_ld11_sys_reset_data, 3948c2ecf20Sopenharmony_ci }, 3958c2ecf20Sopenharmony_ci { 3968c2ecf20Sopenharmony_ci .compatible = "socionext,uniphier-ld20-reset", 3978c2ecf20Sopenharmony_ci .data = uniphier_ld20_sys_reset_data, 3988c2ecf20Sopenharmony_ci }, 3998c2ecf20Sopenharmony_ci { 4008c2ecf20Sopenharmony_ci .compatible = "socionext,uniphier-pxs3-reset", 4018c2ecf20Sopenharmony_ci .data = uniphier_pxs3_sys_reset_data, 4028c2ecf20Sopenharmony_ci }, 4038c2ecf20Sopenharmony_ci /* Media I/O reset, SD reset */ 4048c2ecf20Sopenharmony_ci { 4058c2ecf20Sopenharmony_ci .compatible = "socionext,uniphier-ld4-mio-reset", 4068c2ecf20Sopenharmony_ci .data = uniphier_ld4_mio_reset_data, 4078c2ecf20Sopenharmony_ci }, 4088c2ecf20Sopenharmony_ci { 4098c2ecf20Sopenharmony_ci .compatible = "socionext,uniphier-pro4-mio-reset", 4108c2ecf20Sopenharmony_ci .data = uniphier_ld4_mio_reset_data, 4118c2ecf20Sopenharmony_ci }, 4128c2ecf20Sopenharmony_ci { 4138c2ecf20Sopenharmony_ci .compatible = "socionext,uniphier-sld8-mio-reset", 4148c2ecf20Sopenharmony_ci .data = uniphier_ld4_mio_reset_data, 4158c2ecf20Sopenharmony_ci }, 4168c2ecf20Sopenharmony_ci { 4178c2ecf20Sopenharmony_ci .compatible = "socionext,uniphier-pro5-sd-reset", 4188c2ecf20Sopenharmony_ci .data = uniphier_pro5_sd_reset_data, 4198c2ecf20Sopenharmony_ci }, 4208c2ecf20Sopenharmony_ci { 4218c2ecf20Sopenharmony_ci .compatible = "socionext,uniphier-pxs2-sd-reset", 4228c2ecf20Sopenharmony_ci .data = uniphier_pro5_sd_reset_data, 4238c2ecf20Sopenharmony_ci }, 4248c2ecf20Sopenharmony_ci { 4258c2ecf20Sopenharmony_ci .compatible = "socionext,uniphier-ld11-mio-reset", 4268c2ecf20Sopenharmony_ci .data = uniphier_ld4_mio_reset_data, 4278c2ecf20Sopenharmony_ci }, 4288c2ecf20Sopenharmony_ci { 4298c2ecf20Sopenharmony_ci .compatible = "socionext,uniphier-ld11-sd-reset", 4308c2ecf20Sopenharmony_ci .data = uniphier_pro5_sd_reset_data, 4318c2ecf20Sopenharmony_ci }, 4328c2ecf20Sopenharmony_ci { 4338c2ecf20Sopenharmony_ci .compatible = "socionext,uniphier-ld20-sd-reset", 4348c2ecf20Sopenharmony_ci .data = uniphier_pro5_sd_reset_data, 4358c2ecf20Sopenharmony_ci }, 4368c2ecf20Sopenharmony_ci { 4378c2ecf20Sopenharmony_ci .compatible = "socionext,uniphier-pxs3-sd-reset", 4388c2ecf20Sopenharmony_ci .data = uniphier_pro5_sd_reset_data, 4398c2ecf20Sopenharmony_ci }, 4408c2ecf20Sopenharmony_ci /* Peripheral reset */ 4418c2ecf20Sopenharmony_ci { 4428c2ecf20Sopenharmony_ci .compatible = "socionext,uniphier-ld4-peri-reset", 4438c2ecf20Sopenharmony_ci .data = uniphier_ld4_peri_reset_data, 4448c2ecf20Sopenharmony_ci }, 4458c2ecf20Sopenharmony_ci { 4468c2ecf20Sopenharmony_ci .compatible = "socionext,uniphier-pro4-peri-reset", 4478c2ecf20Sopenharmony_ci .data = uniphier_pro4_peri_reset_data, 4488c2ecf20Sopenharmony_ci }, 4498c2ecf20Sopenharmony_ci { 4508c2ecf20Sopenharmony_ci .compatible = "socionext,uniphier-sld8-peri-reset", 4518c2ecf20Sopenharmony_ci .data = uniphier_ld4_peri_reset_data, 4528c2ecf20Sopenharmony_ci }, 4538c2ecf20Sopenharmony_ci { 4548c2ecf20Sopenharmony_ci .compatible = "socionext,uniphier-pro5-peri-reset", 4558c2ecf20Sopenharmony_ci .data = uniphier_pro4_peri_reset_data, 4568c2ecf20Sopenharmony_ci }, 4578c2ecf20Sopenharmony_ci { 4588c2ecf20Sopenharmony_ci .compatible = "socionext,uniphier-pxs2-peri-reset", 4598c2ecf20Sopenharmony_ci .data = uniphier_pro4_peri_reset_data, 4608c2ecf20Sopenharmony_ci }, 4618c2ecf20Sopenharmony_ci { 4628c2ecf20Sopenharmony_ci .compatible = "socionext,uniphier-ld11-peri-reset", 4638c2ecf20Sopenharmony_ci .data = uniphier_pro4_peri_reset_data, 4648c2ecf20Sopenharmony_ci }, 4658c2ecf20Sopenharmony_ci { 4668c2ecf20Sopenharmony_ci .compatible = "socionext,uniphier-ld20-peri-reset", 4678c2ecf20Sopenharmony_ci .data = uniphier_pro4_peri_reset_data, 4688c2ecf20Sopenharmony_ci }, 4698c2ecf20Sopenharmony_ci { 4708c2ecf20Sopenharmony_ci .compatible = "socionext,uniphier-pxs3-peri-reset", 4718c2ecf20Sopenharmony_ci .data = uniphier_pro4_peri_reset_data, 4728c2ecf20Sopenharmony_ci }, 4738c2ecf20Sopenharmony_ci /* Analog signal amplifiers reset */ 4748c2ecf20Sopenharmony_ci { 4758c2ecf20Sopenharmony_ci .compatible = "socionext,uniphier-ld11-adamv-reset", 4768c2ecf20Sopenharmony_ci .data = uniphier_ld11_adamv_reset_data, 4778c2ecf20Sopenharmony_ci }, 4788c2ecf20Sopenharmony_ci { 4798c2ecf20Sopenharmony_ci .compatible = "socionext,uniphier-ld20-adamv-reset", 4808c2ecf20Sopenharmony_ci .data = uniphier_ld11_adamv_reset_data, 4818c2ecf20Sopenharmony_ci }, 4828c2ecf20Sopenharmony_ci { /* sentinel */ } 4838c2ecf20Sopenharmony_ci}; 4848c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, uniphier_reset_match); 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_cistatic struct platform_driver uniphier_reset_driver = { 4878c2ecf20Sopenharmony_ci .probe = uniphier_reset_probe, 4888c2ecf20Sopenharmony_ci .driver = { 4898c2ecf20Sopenharmony_ci .name = "uniphier-reset", 4908c2ecf20Sopenharmony_ci .of_match_table = uniphier_reset_match, 4918c2ecf20Sopenharmony_ci }, 4928c2ecf20Sopenharmony_ci}; 4938c2ecf20Sopenharmony_cimodule_platform_driver(uniphier_reset_driver); 4948c2ecf20Sopenharmony_ci 4958c2ecf20Sopenharmony_ciMODULE_AUTHOR("Masahiro Yamada <yamada.masahiro@socionext.com>"); 4968c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("UniPhier Reset Controller Driver"); 4978c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 498