aboutsummaryrefslogtreecommitdiff
path: root/drivers/net/can/spi/mcp25xxfd/mcp25xxfd_int.c
blob: 182172b6c59c4e9fe675fc9e8516c79cc8a97cd1 (plain)
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
67
68
69
70
71
// SPDX-License-Identifier: GPL-2.0

/* CAN bus driver for Microchip 25XXFD CAN Controller with SPI Interface
 *
 * Copyright 2019 Martin Sperl <kernel@martin.sperl.org>
 */

#include <linux/kernel.h>
#include <linux/spi/spi.h>

#include "mcp25xxfd_can_int.h"
#include "mcp25xxfd_crc.h"
#include "mcp25xxfd_ecc.h"
#include "mcp25xxfd_int.h"
#include "mcp25xxfd_priv.h"

int mcp25xxfd_int_clear(struct mcp25xxfd_priv *priv)
{
	int ret;

	ret = mcp25xxfd_ecc_clear_int(priv);
	if (ret)
		return ret;

	ret = mcp25xxfd_crc_clear_int(priv);
	if (ret)
		return ret;

	return mcp25xxfd_can_int_clear(priv);
}

int mcp25xxfd_int_enable(struct mcp25xxfd_priv *priv, bool enable)
{
	int ret;

	/* If we enable interrupts, then clear interrupt first */
	if (enable) {
		ret = mcp25xxfd_int_clear(priv);
		if (ret)
			return ret;
	}

	ret = mcp25xxfd_crc_enable_int(priv, enable);
	if (ret)
		return ret;

	ret = mcp25xxfd_ecc_enable(priv);
	if (ret)
		goto out_crc;

	ret = mcp25xxfd_ecc_enable_int(priv, enable);
	if (ret)
		goto out_crc;

	ret = mcp25xxfd_can_int_enable(priv, enable);
	if (ret)
		goto out_ecc;

	/* If we disable interrupts, then clear interrupt flags last */
	if (!enable)
		mcp25xxfd_int_clear(priv);

	return 0;

out_ecc:
	mcp25xxfd_ecc_enable_int(priv, false);

out_crc:
	mcp25xxfd_crc_enable_int(priv, false);
	return ret;
}