summaryrefslogtreecommitdiffstats
path: root/arch/arm/boards/zii-common/switch-cmd.c
blob: 2b9c34bfac1fcd76e59dfe727359f23cc7aaaafb (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
/*
 * Copyright (C) 2018 Zodiac Inflight Innovation
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
#include <command.h>
#include <common.h>
#include <i2c/i2c.h>
#include <linux/mfd/rave-sp.h>

static int do_rdu2_switch_reset(void)
{
	struct i2c_client client;
	u8 reg;

	client.adapter = i2c_get_adapter(1);
	if (!client.adapter)
		return -ENODEV;

	/* address of the switch watchdog microcontroller */
	client.addr = 0x38;
	reg = 0x78;
	/* set switch reset time to 100ms */
	i2c_write_reg(&client, 0x0a, &reg, 1);
	/* reset the switch */
	reg = 0x01;
	i2c_write_reg(&client, 0x0d, &reg, 1);
	/* issue dummy command to work around firmware bug */
	i2c_read_reg(&client, 0x01, &reg, 1);

	return 0;
}

static int do_rdu1_switch_reset(void)
{
	struct device_d *sp_dev = get_device_by_name("sp");
	struct rave_sp *sp = sp_dev->parent->priv;
	u8 cmd[] = {
		[0] = RAVE_SP_CMD_RESET_ETH_SWITCH,
		[1] = 0
	};

	if (IS_ENABLED(CONFIG_RAVE_SP_CORE))
		return rave_sp_exec(sp, cmd, sizeof(cmd), NULL, 0);
	else
		return -ENODEV;
}

static int do_rave_switch_reset(int argc, char *argv[])
{
	if (of_machine_is_compatible("zii,imx6q-zii-rdu2") ||
	    of_machine_is_compatible("zii,imx6qp-zii-rdu2"))
		return do_rdu2_switch_reset();

	if (of_machine_is_compatible("zii,imx51-rdu1"))
		return do_rdu1_switch_reset();

	return -ENODEV;
}

BAREBOX_CMD_START(rave_reset_switch)
	.cmd		= do_rave_switch_reset,
	BAREBOX_CMD_DESC("reset ethernet switch on RDU")
	BAREBOX_CMD_GROUP(CMD_GRP_HWMANIP)
BAREBOX_CMD_END