diff options
Diffstat (limited to 'arch/arm/boards/zii-common/switch-cmd.c')
-rw-r--r-- | arch/arm/boards/zii-common/switch-cmd.c | 67 |
1 files changed, 44 insertions, 23 deletions
diff --git a/arch/arm/boards/zii-common/switch-cmd.c b/arch/arm/boards/zii-common/switch-cmd.c index 2b9c34bfac..6aa1c391f4 100644 --- a/arch/arm/boards/zii-common/switch-cmd.c +++ b/arch/arm/boards/zii-common/switch-cmd.c @@ -1,16 +1,6 @@ -/* - * 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. - */ +// SPDX-License-Identifier: GPL-2.0-or-later +// SPDX-FileCopyrightText: 2018 Zodiac Inflight Innovation + #include <command.h> #include <common.h> #include <i2c/i2c.h> @@ -18,30 +8,60 @@ static int do_rdu2_switch_reset(void) { - struct i2c_client client; + struct device_node *np; + struct i2c_client *client; + int ret; u8 reg; - client.adapter = i2c_get_adapter(1); - if (!client.adapter) + np = of_find_compatible_node(NULL, NULL, "zii,rave-wdt"); + if (!np) { + pr_err("No switch watchdog node found\n"); return -ENODEV; + } + + if (!of_device_is_available(np)) { + /* + * If switch watchdog device is not available assume + * it was removed for a reason and switch reset + * command should be a no-op + */ + return 0; + } + + client = of_find_i2c_device_by_node(np); + if (!client) { + pr_err("No switch watchdog I2C device found\n"); + return -ENODEV; + } - /* address of the switch watchdog microcontroller */ - client.addr = 0x38; reg = 0x78; + /* set switch reset time to 100ms */ - i2c_write_reg(&client, 0x0a, ®, 1); + ret = i2c_write_reg(client, 0x0a, ®, 1); + if (ret < 0) { + pr_err("Failed to set switch reset time\n"); + return ret; + } /* reset the switch */ reg = 0x01; - i2c_write_reg(&client, 0x0d, ®, 1); + ret = i2c_write_reg(client, 0x0d, ®, 1); + if (ret < 0) { + pr_err("Failed to reset the switch\n"); + return ret; + } /* issue dummy command to work around firmware bug */ - i2c_read_reg(&client, 0x01, ®, 1); + ret = i2c_read_reg(client, 0x01, ®, 1); + if (ret < 0) { + pr_err("Failed to issue a dummy command\n"); + return ret; + } return 0; } static int do_rdu1_switch_reset(void) { - struct device_d *sp_dev = get_device_by_name("sp"); + struct device *sp_dev = get_device_by_name("sp"); struct rave_sp *sp = sp_dev->parent->priv; u8 cmd[] = { [0] = RAVE_SP_CMD_RESET_ETH_SWITCH, @@ -57,7 +77,8 @@ static int do_rdu1_switch_reset(void) 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")) + of_machine_is_compatible("zii,imx6qp-zii-rdu2") || + of_machine_is_compatible("zii,imx8mq-ultra")) return do_rdu2_switch_reset(); if (of_machine_is_compatible("zii,imx51-rdu1")) |