1dc606c52SThierry Reding /* 2dc606c52SThierry Reding * Copyright (C) 2016 NVIDIA Corporation 3dc606c52SThierry Reding * 4dc606c52SThierry Reding * This program is free software; you can redistribute it and/or modify 5dc606c52SThierry Reding * it under the terms of the GNU General Public License version 2 as 6dc606c52SThierry Reding * published by the Free Software Foundation. 7dc606c52SThierry Reding */ 8dc606c52SThierry Reding 9dc606c52SThierry Reding #include <linux/reset-controller.h> 10dc606c52SThierry Reding 11dc606c52SThierry Reding #include <soc/tegra/bpmp.h> 12dc606c52SThierry Reding #include <soc/tegra/bpmp-abi.h> 13dc606c52SThierry Reding 14dc606c52SThierry Reding static struct tegra_bpmp *to_tegra_bpmp(struct reset_controller_dev *rstc) 15dc606c52SThierry Reding { 16dc606c52SThierry Reding return container_of(rstc, struct tegra_bpmp, rstc); 17dc606c52SThierry Reding } 18dc606c52SThierry Reding 19dc606c52SThierry Reding static int tegra_bpmp_reset_common(struct reset_controller_dev *rstc, 20dc606c52SThierry Reding enum mrq_reset_commands command, 21dc606c52SThierry Reding unsigned int id) 22dc606c52SThierry Reding { 23dc606c52SThierry Reding struct tegra_bpmp *bpmp = to_tegra_bpmp(rstc); 24dc606c52SThierry Reding struct mrq_reset_request request; 25dc606c52SThierry Reding struct tegra_bpmp_message msg; 26dc606c52SThierry Reding 27dc606c52SThierry Reding memset(&request, 0, sizeof(request)); 28dc606c52SThierry Reding request.cmd = command; 29dc606c52SThierry Reding request.reset_id = id; 30dc606c52SThierry Reding 31dc606c52SThierry Reding memset(&msg, 0, sizeof(msg)); 32dc606c52SThierry Reding msg.mrq = MRQ_RESET; 33dc606c52SThierry Reding msg.tx.data = &request; 34dc606c52SThierry Reding msg.tx.size = sizeof(request); 35dc606c52SThierry Reding 36dc606c52SThierry Reding return tegra_bpmp_transfer(bpmp, &msg); 37dc606c52SThierry Reding } 38dc606c52SThierry Reding 39dc606c52SThierry Reding static int tegra_bpmp_reset_module(struct reset_controller_dev *rstc, 40dc606c52SThierry Reding unsigned long id) 41dc606c52SThierry Reding { 42dc606c52SThierry Reding return tegra_bpmp_reset_common(rstc, CMD_RESET_MODULE, id); 43dc606c52SThierry Reding } 44dc606c52SThierry Reding 45dc606c52SThierry Reding static int tegra_bpmp_reset_assert(struct reset_controller_dev *rstc, 46dc606c52SThierry Reding unsigned long id) 47dc606c52SThierry Reding { 48dc606c52SThierry Reding return tegra_bpmp_reset_common(rstc, CMD_RESET_ASSERT, id); 49dc606c52SThierry Reding } 50dc606c52SThierry Reding 51dc606c52SThierry Reding static int tegra_bpmp_reset_deassert(struct reset_controller_dev *rstc, 52dc606c52SThierry Reding unsigned long id) 53dc606c52SThierry Reding { 54dc606c52SThierry Reding return tegra_bpmp_reset_common(rstc, CMD_RESET_DEASSERT, id); 55dc606c52SThierry Reding } 56dc606c52SThierry Reding 57dc606c52SThierry Reding static const struct reset_control_ops tegra_bpmp_reset_ops = { 58dc606c52SThierry Reding .reset = tegra_bpmp_reset_module, 59dc606c52SThierry Reding .assert = tegra_bpmp_reset_assert, 60dc606c52SThierry Reding .deassert = tegra_bpmp_reset_deassert, 61dc606c52SThierry Reding }; 62dc606c52SThierry Reding 63dc606c52SThierry Reding int tegra_bpmp_init_resets(struct tegra_bpmp *bpmp) 64dc606c52SThierry Reding { 65dc606c52SThierry Reding bpmp->rstc.ops = &tegra_bpmp_reset_ops; 66dc606c52SThierry Reding bpmp->rstc.owner = THIS_MODULE; 67dc606c52SThierry Reding bpmp->rstc.of_node = bpmp->dev->of_node; 68dc606c52SThierry Reding bpmp->rstc.nr_resets = bpmp->soc->num_resets; 69dc606c52SThierry Reding 70dc606c52SThierry Reding return devm_reset_controller_register(bpmp->dev, &bpmp->rstc); 71dc606c52SThierry Reding } 72