summaryrefslogtreecommitdiff
path: root/drivers/net/can/spi/mcp25xxfd/mcp25xxfd_int.c
blob: cca9c996b542d8347144a78b261ba48061235400 (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
72
73
// 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;
	ret = mcp25xxfd_can_int_clear(priv);

	return ret;
}

int mcp25xxfd_int_enable(struct mcp25xxfd_priv *priv, bool enable)
{
	/* error handling only on enable for this function */
	int ret = 0;

	/* if we enable clear interrupt flags first */
	if (enable) {
		ret = mcp25xxfd_int_clear(priv);
		if (ret)
			goto out;
	}

	ret = mcp25xxfd_crc_enable_int(priv, enable);
	if (ret)
		goto out;

	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 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);
out:
	return ret;
}