1*e3889691SÁlvaro Fernández Rojas /* 2*e3889691SÁlvaro Fernández Rojas * Copyright (C) 2017 Álvaro Fernández Rojas <noltari@gmail.com> 3*e3889691SÁlvaro Fernández Rojas * 4*e3889691SÁlvaro Fernández Rojas * Derived from linux/drivers/power/reset/syscon-reboot.c: 5*e3889691SÁlvaro Fernández Rojas * Copyright (C) 2013, Applied Micro Circuits Corporation 6*e3889691SÁlvaro Fernández Rojas * Author: Feng Kan <fkan@apm.com> 7*e3889691SÁlvaro Fernández Rojas * 8*e3889691SÁlvaro Fernández Rojas * SPDX-License-Identifier: GPL-2.0+ 9*e3889691SÁlvaro Fernández Rojas */ 10*e3889691SÁlvaro Fernández Rojas 11*e3889691SÁlvaro Fernández Rojas #include <common.h> 12*e3889691SÁlvaro Fernández Rojas #include <dm.h> 13*e3889691SÁlvaro Fernández Rojas #include <errno.h> 14*e3889691SÁlvaro Fernández Rojas #include <regmap.h> 15*e3889691SÁlvaro Fernández Rojas #include <sysreset.h> 16*e3889691SÁlvaro Fernández Rojas #include <syscon.h> 17*e3889691SÁlvaro Fernández Rojas 18*e3889691SÁlvaro Fernández Rojas DECLARE_GLOBAL_DATA_PTR; 19*e3889691SÁlvaro Fernández Rojas 20*e3889691SÁlvaro Fernández Rojas struct syscon_reboot_priv { 21*e3889691SÁlvaro Fernández Rojas struct regmap *regmap; 22*e3889691SÁlvaro Fernández Rojas unsigned int offset; 23*e3889691SÁlvaro Fernández Rojas unsigned int mask; 24*e3889691SÁlvaro Fernández Rojas }; 25*e3889691SÁlvaro Fernández Rojas 26*e3889691SÁlvaro Fernández Rojas static int syscon_reboot_request(struct udevice *dev, enum sysreset_t type) 27*e3889691SÁlvaro Fernández Rojas { 28*e3889691SÁlvaro Fernández Rojas struct syscon_reboot_priv *priv = dev_get_priv(dev); 29*e3889691SÁlvaro Fernández Rojas 30*e3889691SÁlvaro Fernández Rojas regmap_write(priv->regmap, priv->offset, priv->mask); 31*e3889691SÁlvaro Fernández Rojas 32*e3889691SÁlvaro Fernández Rojas return -EINPROGRESS; 33*e3889691SÁlvaro Fernández Rojas } 34*e3889691SÁlvaro Fernández Rojas 35*e3889691SÁlvaro Fernández Rojas static struct sysreset_ops syscon_reboot_ops = { 36*e3889691SÁlvaro Fernández Rojas .request = syscon_reboot_request, 37*e3889691SÁlvaro Fernández Rojas }; 38*e3889691SÁlvaro Fernández Rojas 39*e3889691SÁlvaro Fernández Rojas int syscon_reboot_probe(struct udevice *dev) 40*e3889691SÁlvaro Fernández Rojas { 41*e3889691SÁlvaro Fernández Rojas struct udevice *syscon; 42*e3889691SÁlvaro Fernández Rojas struct syscon_reboot_priv *priv = dev_get_priv(dev); 43*e3889691SÁlvaro Fernández Rojas int err; 44*e3889691SÁlvaro Fernández Rojas 45*e3889691SÁlvaro Fernández Rojas err = uclass_get_device_by_phandle(UCLASS_SYSCON, dev, 46*e3889691SÁlvaro Fernández Rojas "regmap", &syscon); 47*e3889691SÁlvaro Fernández Rojas if (err) { 48*e3889691SÁlvaro Fernández Rojas error("unable to find syscon device\n"); 49*e3889691SÁlvaro Fernández Rojas return err; 50*e3889691SÁlvaro Fernández Rojas } 51*e3889691SÁlvaro Fernández Rojas 52*e3889691SÁlvaro Fernández Rojas priv->regmap = syscon_get_regmap(syscon); 53*e3889691SÁlvaro Fernández Rojas if (!priv->regmap) { 54*e3889691SÁlvaro Fernández Rojas error("unable to find regmap\n"); 55*e3889691SÁlvaro Fernández Rojas return -ENODEV; 56*e3889691SÁlvaro Fernández Rojas } 57*e3889691SÁlvaro Fernández Rojas 58*e3889691SÁlvaro Fernández Rojas priv->offset = fdtdec_get_uint(gd->fdt_blob, dev_of_offset(dev), 59*e3889691SÁlvaro Fernández Rojas "offset", 0); 60*e3889691SÁlvaro Fernández Rojas priv->mask = fdtdec_get_uint(gd->fdt_blob, dev_of_offset(dev), 61*e3889691SÁlvaro Fernández Rojas "mask", 0); 62*e3889691SÁlvaro Fernández Rojas 63*e3889691SÁlvaro Fernández Rojas return 0; 64*e3889691SÁlvaro Fernández Rojas } 65*e3889691SÁlvaro Fernández Rojas 66*e3889691SÁlvaro Fernández Rojas static const struct udevice_id syscon_reboot_ids[] = { 67*e3889691SÁlvaro Fernández Rojas { .compatible = "syscon-reboot" }, 68*e3889691SÁlvaro Fernández Rojas { /* sentinel */ } 69*e3889691SÁlvaro Fernández Rojas }; 70*e3889691SÁlvaro Fernández Rojas 71*e3889691SÁlvaro Fernández Rojas U_BOOT_DRIVER(syscon_reboot) = { 72*e3889691SÁlvaro Fernández Rojas .name = "syscon_reboot", 73*e3889691SÁlvaro Fernández Rojas .id = UCLASS_SYSRESET, 74*e3889691SÁlvaro Fernández Rojas .of_match = syscon_reboot_ids, 75*e3889691SÁlvaro Fernández Rojas .probe = syscon_reboot_probe, 76*e3889691SÁlvaro Fernández Rojas .priv_auto_alloc_size = sizeof(struct syscon_reboot_priv), 77*e3889691SÁlvaro Fernández Rojas .ops = &syscon_reboot_ops, 78*e3889691SÁlvaro Fernández Rojas }; 79