From 974fd95ac6bb3fddd75aa1103206e954be5cb055 Mon Sep 17 00:00:00 2001 From: Mykyta Dorokhin Date: Thu, 20 Oct 2016 11:59:06 +0300 Subject: mtp: add eth-reset sysfs node --- io-module/mtp.c | 82 +++++++++++++++++++++++++++++++++++++++++++----------- io-module/mts_io.c | 2 +- 2 files changed, 66 insertions(+), 18 deletions(-) diff --git a/io-module/mtp.c b/io-module/mtp.c index e6da3d5..74867e3 100644 --- a/io-module/mtp.c +++ b/io-module/mtp.c @@ -1,10 +1,10 @@ static struct gpio_pin gpio_pins_mtp_0_0[] = { { - .name = "ETH_EN", + .name = "ETH_RESET", .pin = { .gpio = AT91_PIN_PC6, // NETH_RST .flags = GPIOF_OUT_INIT_HIGH, - .label = "eth-enabled", + .label = "eth-reset", }, }, { @@ -155,11 +155,11 @@ static int radio_off_mtp(void) value = gpio_get_value(pwrmon_pin->pin.gpio); if(value == 0) { - log_warning("radio is already off"); + log_warning("cell radio is already off"); return 0; } - log_info("turning off radio"); + log_info("turning off cell radio"); // To turn OFF LE910 the pad ON/OFF# must be tied low for at least 2 seconds and then // released. Same circuitry and timing for the power on must be used. When the hold @@ -176,7 +176,7 @@ static int radio_off_mtp(void) // check that power is low value = gpio_get_value(pwrmon_pin->pin.gpio); if (value != 0) { - log_info("radio is still on. keep waiting..."); + log_info("cell radio is still on. keep waiting..."); msleep(2000); continue; } @@ -184,10 +184,10 @@ static int radio_off_mtp(void) } if (value == 0) { - log_info("radio has been shut down"); + log_info("cell radio has been shut down"); } else { - log_warning("radio is still on. performing unconditional shutdown..."); + log_warning("cell radio is still on. performing unconditional shutdown..."); radio_unconditional_shutdown_mtp(); } @@ -208,11 +208,11 @@ static int radio_on_mtp(void) value = gpio_get_value(pwrmon_pin->pin.gpio); if(value != 0) { - log_warning("radio is already on"); + log_warning("cell radio is already on"); return 0; } - log_info("turning on radio"); + log_info("turning on cell radio"); // drive on/off pin high for at least 1 seconoff_pin gpio_set_value(onoff_pin->pin.gpio, 1); @@ -225,9 +225,9 @@ static int radio_on_mtp(void) // check that power is high value = gpio_get_value(pwrmon_pin->pin.gpio); if(value == 0) { - log_warning("radio is still off."); + log_warning("cell radio is still off."); } else { - log_info("radio has been turned on"); + log_info("cell radio has been turned on"); } return 0; @@ -247,14 +247,14 @@ static int radio_reset_mtp(void) // Unconditional shutdown // - log_info("performing unconditional radio shutdown"); + log_info("performing unconditional cell radio shutdown"); radio_unconditional_shutdown_mtp(); // // Turning on radio // - log_info("turning on radio"); + log_info("turning on cell radio"); // drive on/off pin high for at least 1 sec gpio_set_value(onoff_pin->pin.gpio, 1); @@ -311,7 +311,7 @@ static ssize_t mts_attr_store_radio_reset_mtp(struct device *dev, if (NULL != timings_data) { /* check reset timer is started */ if (radio_reset_timer_is_start == 1) { - log_info("radio reset timer is running. \n"); + log_info("cell radio reset timer is running. \n"); return count; } @@ -406,6 +406,54 @@ static ssize_t mts_attr_store_lora_reset_mtp(struct device *dev, return count; } +static int eth_reset_mtp(void) +{ + struct gpio_pin *rst_pin = gpio_pin_by_attr_name("eth-reset"); + + if (!rst_pin) { + return -ENODEV; + } + + /* + * DS00002275A (09-15-16) KSZ8091MNX/RNB DATA SHEET: + * For warm reset, the reset (RST#) pin should be asserted low for a minimum of 500 μs. + */ + gpio_set_value(rst_pin->pin.gpio, 0); + + msleep(2); + + gpio_set_value(rst_pin->pin.gpio, 1); + + msleep(1); + + return 0; +} + +static ssize_t mts_attr_store_eth_reset_mtp(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + int value; + int err; + + if (sscanf(buf, "%i", &value) != 1) { + return -EINVAL; + } + + log_info("performing eth reset"); + + mutex_lock(&mts_io_mutex); + + err = eth_reset_mtp(); + + mutex_unlock(&mts_io_mutex); + + if (err) { + return err; + } + + return count; +} + static DEVICE_ATTR_MTS(dev_attr_radio_reset_mtp, "radio-reset", mts_attr_show_gpio_pin, mts_attr_store_radio_reset_mtp); @@ -415,8 +463,8 @@ static DEVICE_ATTR_MTS(dev_attr_radio_power_mtp, "radio-power", static DEVICE_ATTR_MTS(dev_attr_lora_reset_mtp, "lora-reset", mts_attr_show_gpio_pin, mts_attr_store_lora_reset_mtp); -static DEVICE_ATTR_MTS(dev_attr_eth_enabled_mtp, "eth-enabled", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); +static DEVICE_ATTR_MTS(dev_attr_eth_reset_mtp, "eth-reset", + mts_attr_show_gpio_pin, mts_attr_store_eth_reset_mtp); static DEVICE_ATTR_MTS(dev_attr_led_lora_gpio_mtp, "led-lora", mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); @@ -436,7 +484,7 @@ static struct attribute *mtp_0_0_platform_attributes[] = { &dev_attr_reset_monitor.attr, &dev_attr_reset_monitor_intervals.attr, - &dev_attr_eth_enabled_mtp.attr, + &dev_attr_eth_reset_mtp.attr, &dev_attr_lora_reset_mtp.attr, diff --git a/io-module/mts_io.c b/io-module/mts_io.c index 7dcdf54..7e3d1f0 100644 --- a/io-module/mts_io.c +++ b/io-module/mts_io.c @@ -47,7 +47,7 @@ #include "mts_io.h" -#define DRIVER_VERSION "v1.4.0" +#define DRIVER_VERSION "v1.4.1" #define DRIVER_AUTHOR "James Maki " #define DRIVER_DESC "MTS-IO Controller" #define DRIVER_NAME "mts-io" -- cgit v1.2.3