File: owl-reset.c

package info (click to toggle)
linux 6.1.8-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,488,076 kB
  • sloc: ansic: 23,401,844; asm: 266,744; sh: 108,976; makefile: 49,705; python: 36,927; perl: 36,810; cpp: 6,044; yacc: 4,904; lex: 2,722; awk: 1,440; ruby: 25; sed: 5
file content (66 lines) | stat: -rw-r--r-- 1,664 bytes parent folder | download | duplicates (37)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// SPDX-License-Identifier: GPL-2.0-or-later
//
// Actions Semi Owl SoCs Reset Management Unit driver
//
// Copyright (c) 2018 Linaro Ltd.
// Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

#include <linux/delay.h>
#include <linux/regmap.h>
#include <linux/reset-controller.h>

#include "owl-reset.h"

static int owl_reset_assert(struct reset_controller_dev *rcdev,
			    unsigned long id)
{
	struct owl_reset *reset = to_owl_reset(rcdev);
	const struct owl_reset_map *map = &reset->reset_map[id];

	return regmap_update_bits(reset->regmap, map->reg, map->bit, 0);
}

static int owl_reset_deassert(struct reset_controller_dev *rcdev,
			      unsigned long id)
{
	struct owl_reset *reset = to_owl_reset(rcdev);
	const struct owl_reset_map *map = &reset->reset_map[id];

	return regmap_update_bits(reset->regmap, map->reg, map->bit, map->bit);
}

static int owl_reset_reset(struct reset_controller_dev *rcdev,
			   unsigned long id)
{
	owl_reset_assert(rcdev, id);
	udelay(1);
	owl_reset_deassert(rcdev, id);

	return 0;
}

static int owl_reset_status(struct reset_controller_dev *rcdev,
			    unsigned long id)
{
	struct owl_reset *reset = to_owl_reset(rcdev);
	const struct owl_reset_map *map = &reset->reset_map[id];
	u32 reg;
	int ret;

	ret = regmap_read(reset->regmap, map->reg, &reg);
	if (ret)
		return ret;

	/*
	 * The reset control API expects 0 if reset is not asserted,
	 * which is the opposite of what our hardware uses.
	 */
	return !(map->bit & reg);
}

const struct reset_control_ops owl_reset_ops = {
	.assert		= owl_reset_assert,
	.deassert	= owl_reset_deassert,
	.reset		= owl_reset_reset,
	.status		= owl_reset_status,
};