169bfec75SEmil Renner Berthing // SPDX-License-Identifier: GPL-2.0-or-later 269bfec75SEmil Renner Berthing /* 369bfec75SEmil Renner Berthing * Reset driver for the StarFive JH7100 SoC 469bfec75SEmil Renner Berthing * 569bfec75SEmil Renner Berthing * Copyright (C) 2021 Emil Renner Berthing <kernel@esmil.dk> 669bfec75SEmil Renner Berthing */ 769bfec75SEmil Renner Berthing 869bfec75SEmil Renner Berthing #include <linux/mod_devicetable.h> 969bfec75SEmil Renner Berthing #include <linux/platform_device.h> 1069bfec75SEmil Renner Berthing 111ec3d20eSEmil Renner Berthing #include "reset-starfive-jh71x0.h" 1269bfec75SEmil Renner Berthing 13*ed36fcd1SEmil Renner Berthing #include <dt-bindings/reset/starfive-jh7100.h> 14*ed36fcd1SEmil Renner Berthing 15*ed36fcd1SEmil Renner Berthing /* register offsets */ 16*ed36fcd1SEmil Renner Berthing #define JH7100_RESET_ASSERT0 0x00 17*ed36fcd1SEmil Renner Berthing #define JH7100_RESET_ASSERT1 0x04 18*ed36fcd1SEmil Renner Berthing #define JH7100_RESET_ASSERT2 0x08 19*ed36fcd1SEmil Renner Berthing #define JH7100_RESET_ASSERT3 0x0c 20*ed36fcd1SEmil Renner Berthing #define JH7100_RESET_STATUS0 0x10 21*ed36fcd1SEmil Renner Berthing #define JH7100_RESET_STATUS1 0x14 22*ed36fcd1SEmil Renner Berthing #define JH7100_RESET_STATUS2 0x18 23*ed36fcd1SEmil Renner Berthing #define JH7100_RESET_STATUS3 0x1c 24*ed36fcd1SEmil Renner Berthing 25*ed36fcd1SEmil Renner Berthing /* 26*ed36fcd1SEmil Renner Berthing * Writing a 1 to the n'th bit of the m'th ASSERT register asserts 27*ed36fcd1SEmil Renner Berthing * line 32m + n, and writing a 0 deasserts the same line. 28*ed36fcd1SEmil Renner Berthing * Most reset lines have their status inverted so a 0 bit in the STATUS 29*ed36fcd1SEmil Renner Berthing * register means the line is asserted and a 1 means it's deasserted. A few 30*ed36fcd1SEmil Renner Berthing * lines don't though, so store the expected value of the status registers when 31*ed36fcd1SEmil Renner Berthing * all lines are asserted. 32*ed36fcd1SEmil Renner Berthing */ 33*ed36fcd1SEmil Renner Berthing static const u64 jh7100_reset_asserted[2] = { 34*ed36fcd1SEmil Renner Berthing /* STATUS0 */ 35*ed36fcd1SEmil Renner Berthing BIT_ULL_MASK(JH7100_RST_U74) | 36*ed36fcd1SEmil Renner Berthing BIT_ULL_MASK(JH7100_RST_VP6_DRESET) | 37*ed36fcd1SEmil Renner Berthing BIT_ULL_MASK(JH7100_RST_VP6_BRESET) | 38*ed36fcd1SEmil Renner Berthing /* STATUS1 */ 39*ed36fcd1SEmil Renner Berthing BIT_ULL_MASK(JH7100_RST_HIFI4_DRESET) | 40*ed36fcd1SEmil Renner Berthing BIT_ULL_MASK(JH7100_RST_HIFI4_BRESET), 41*ed36fcd1SEmil Renner Berthing /* STATUS2 */ 42*ed36fcd1SEmil Renner Berthing BIT_ULL_MASK(JH7100_RST_E24) | 43*ed36fcd1SEmil Renner Berthing /* STATUS3 */ 44*ed36fcd1SEmil Renner Berthing 0, 45*ed36fcd1SEmil Renner Berthing }; 46*ed36fcd1SEmil Renner Berthing 47*ed36fcd1SEmil Renner Berthing static int __init jh7100_reset_probe(struct platform_device *pdev) 48*ed36fcd1SEmil Renner Berthing { 49*ed36fcd1SEmil Renner Berthing void __iomem *base = devm_platform_ioremap_resource(pdev, 0); 50*ed36fcd1SEmil Renner Berthing 51*ed36fcd1SEmil Renner Berthing if (IS_ERR(base)) 52*ed36fcd1SEmil Renner Berthing return PTR_ERR(base); 53*ed36fcd1SEmil Renner Berthing 54*ed36fcd1SEmil Renner Berthing return reset_starfive_jh7100_register(&pdev->dev, pdev->dev.of_node, 55*ed36fcd1SEmil Renner Berthing base + JH7100_RESET_ASSERT0, 56*ed36fcd1SEmil Renner Berthing base + JH7100_RESET_STATUS0, 57*ed36fcd1SEmil Renner Berthing jh7100_reset_asserted, 58*ed36fcd1SEmil Renner Berthing JH7100_RSTN_END, 59*ed36fcd1SEmil Renner Berthing THIS_MODULE); 60*ed36fcd1SEmil Renner Berthing } 61*ed36fcd1SEmil Renner Berthing 6269bfec75SEmil Renner Berthing static const struct of_device_id jh7100_reset_dt_ids[] = { 6369bfec75SEmil Renner Berthing { .compatible = "starfive,jh7100-reset" }, 6469bfec75SEmil Renner Berthing { /* sentinel */ } 6569bfec75SEmil Renner Berthing }; 6669bfec75SEmil Renner Berthing 6769bfec75SEmil Renner Berthing static struct platform_driver jh7100_reset_driver = { 6869bfec75SEmil Renner Berthing .driver = { 6969bfec75SEmil Renner Berthing .name = "jh7100-reset", 7069bfec75SEmil Renner Berthing .of_match_table = jh7100_reset_dt_ids, 7169bfec75SEmil Renner Berthing .suppress_bind_attrs = true, 7269bfec75SEmil Renner Berthing }, 7369bfec75SEmil Renner Berthing }; 7469bfec75SEmil Renner Berthing builtin_platform_driver_probe(jh7100_reset_driver, jh7100_reset_probe); 75