summaryrefslogtreecommitdiff
path: root/io-module/mts_io.c
diff options
context:
space:
mode:
Diffstat (limited to 'io-module/mts_io.c')
-rw-r--r--io-module/mts_io.c182
1 files changed, 165 insertions, 17 deletions
diff --git a/io-module/mts_io.c b/io-module/mts_io.c
index f6566e6..aa6e46d 100644
--- a/io-module/mts_io.c
+++ b/io-module/mts_io.c
@@ -75,6 +75,7 @@ enum {
#define LED_STATUS_CONTROLLABLE 0
#define LED_LS_CONTROLLABLE 0
+#define USBH2_PS_CONTROLLABLE 0
#if LED_STATUS_CONTROLLABLE
static int led_mode_status = LED_OFF;
@@ -133,15 +134,17 @@ static struct gpio_pin gpio_pins_mtcdp_0_0[] = {
.output_value = 0,
.use_pullup = 0,
},
-#if LED_LS_CONTROLLABLE
{
.name = "LS_LED",
.pin = AT91_PIN_PC9,
+#if LED_LS_CONTROLLABLE
.direction = GPIO_DIR_OUTPUT,
+#else
+ .direction = GPIO_DIR_INPUT,
+#endif
.output_value = 1,
.use_pullup = 0,
},
-#endif
#if LED_STATUS_CONTROLLABLE
{
.name = "STATUS_LED",
@@ -197,15 +200,17 @@ static struct gpio_pin gpio_pins_mtcdp_1_0[] = {
.output_value = 0,
.use_pullup = 0,
},
-#if LED_LS_CONTROLLABLE
{
.name = "LS_LED",
.pin = AT91_PIN_PC9,
+#if LED_LS_CONTROLLABLE
.direction = GPIO_DIR_OUTPUT,
+#else
+ .direction = GPIO_DIR_INPUT,
+#endif
.output_value = 1,
.use_pullup = 0,
},
-#endif
#if LED_STATUS_CONTROLLABLE
{
.name = "STATUS_LED",
@@ -237,19 +242,21 @@ static struct gpio_pin gpio_pins_mtcdp_1_0[] = {
.use_pullup = 0,
},
{
- .name = "DC_NINT1",
- .pin = AT91_PIN_PB8,
+ .name = "USBH2_PS_OC",
+ .pin = AT91_PIN_PB19,
.direction = GPIO_DIR_INPUT,
.output_value = 0,
.use_pullup = 0,
},
+#if USBH2_PS_CONTROLLABLE
{
- .name = "DC_NINT2",
- .pin = AT91_PIN_PB9,
- .direction = GPIO_DIR_INPUT,
+ .name = "USBH2_PS_ENABLED",
+ .pin = AT91_PIN_PB20,
+ .direction = GPIO_DIR_OUTPUT,
.output_value = 0,
.use_pullup = 0,
},
+#endif
{ },
};
@@ -429,13 +436,15 @@ static DECLARE_DELAYED_WORK(blink_work, blink_callback);
static void blink_callback(struct work_struct *ignored)
{
struct gpio_pin *pin;
- int reset_pressed;
+ int reset_pressed = 0;
struct pid *vpid = NULL;
mutex_lock(&mts_io_mutex);
pin = gpio_pin_by_name("DEVICE_RESET");
- reset_pressed = !at91_get_gpio_value(pin->pin);
+ if (pin) {
+ reset_pressed = !at91_get_gpio_value(pin->pin);
+ }
if (reset_pid > 0) {
vpid = find_vpid(reset_pid);
@@ -460,7 +469,9 @@ static void blink_callback(struct work_struct *ignored)
#if LED_STATUS_CONTROLLABLE
if (led_mode_status == LED_FLASHING) {
pin = gpio_pin_by_name("STATUS_LED");
- at91_set_gpio_value(pin->pin, !at91_get_gpio_value(pin->pin));
+ if (pin) {
+ at91_set_gpio_value(pin->pin, !at91_get_gpio_value(pin->pin));
+ }
}
#endif
@@ -474,6 +485,10 @@ static int radio_reset(void)
int ret;
struct gpio_pin *pin = gpio_pin_by_name("RADIO_RESET");
+ if (!pin) {
+ return -ENODEV;
+ }
+
ret = at91_set_gpio_value(pin->pin, 0);
if (ret) {
return ret;
@@ -522,6 +537,10 @@ static ssize_t mts_attr_show_radio_reset(struct device *dev,
int value;
struct gpio_pin *pin = gpio_pin_by_name("RADIO_RESET");
+ if (!pin) {
+ return -ENODEV;
+ }
+
mutex_lock(&mts_io_mutex);
value = at91_get_gpio_value(pin->pin);
@@ -577,6 +596,10 @@ static ssize_t mts_attr_show_eth0_enabled(struct device *dev,
int value;
struct gpio_pin *pin = gpio_pin_by_name("ETH0_ENABLED");
+ if (!pin) {
+ return -ENODEV;
+ }
+
mutex_lock(&mts_io_mutex);
value = at91_get_gpio_value(pin->pin);
@@ -597,6 +620,10 @@ static ssize_t mts_attr_store_eth0_enabled(struct device *dev,
int err;
struct gpio_pin *pin = gpio_pin_by_name("ETH0_ENABLED");
+ if (!pin) {
+ return -ENODEV;
+ }
+
if (sscanf(buf, "%i", &value) != 1) {
return -EINVAL;
}
@@ -1126,6 +1153,10 @@ static ssize_t mts_attr_show_extserial_dtr(struct device *dev,
int value;
struct gpio_pin *pin = gpio_pin_by_name("DTR1");
+ if (!pin) {
+ return -ENODEV;
+ }
+
mutex_lock(&mts_io_mutex);
value = !at91_get_gpio_value(pin->pin);
@@ -1162,6 +1193,10 @@ static ssize_t mts_attr_store_led_status(struct device *dev,
int ret;
struct gpio_pin *pin = gpio_pin_by_name("STATUS_LED");
+ if (!pin) {
+ return -ENODEV;
+ }
+
if (sscanf(buf, "%i", &value) != 1) {
return -EINVAL;
}
@@ -1215,7 +1250,6 @@ static struct device_attribute dev_attr_led_sdk_a = {
};
#endif
-#if LED_LS_CONTROLLABLE
static ssize_t mts_attr_show_led_ls(struct device *dev,
struct device_attribute *attr,
char *buf)
@@ -1223,6 +1257,10 @@ static ssize_t mts_attr_show_led_ls(struct device *dev,
int value;
struct gpio_pin *pin = gpio_pin_by_name("LS_LED");
+ if (!pin) {
+ return -ENODEV;
+ }
+
mutex_lock(&mts_io_mutex);
value = at91_get_gpio_value(pin->pin);
@@ -1243,6 +1281,10 @@ static ssize_t mts_attr_store_led_ls(struct device *dev,
int err;
struct gpio_pin *pin = gpio_pin_by_name("LS_LED");
+ if (!pin) {
+ return -ENODEV;
+ }
+
if (sscanf(buf, "%i", &value) != 1) {
return -EINVAL;
}
@@ -1263,12 +1305,15 @@ static ssize_t mts_attr_store_led_ls(struct device *dev,
static struct device_attribute dev_attr_led_ls = {
.attr = {
.name = "led-ls",
+#if LED_LS_CONTROLLABLE
.mode = MTS_ATTR_MODE_RW,
+#else
+ .mode = MTS_ATTR_MODE_RO,
+#endif
},
.show = mts_attr_show_led_ls,
.store = mts_attr_store_led_ls,
};
-#endif
static ssize_t mts_attr_show_reset(struct device *dev,
struct device_attribute *attr,
@@ -1277,6 +1322,10 @@ static ssize_t mts_attr_show_reset(struct device *dev,
int value;
struct gpio_pin *pin = gpio_pin_by_name("DEVICE_RESET");
+ if (!pin) {
+ return -ENODEV;
+ }
+
mutex_lock(&mts_io_mutex);
value = !at91_get_gpio_value(pin->pin);
@@ -1443,19 +1492,116 @@ static struct device_attribute dev_attr_adc3 = {
.show = mts_attr_show_adc,
};
+static ssize_t mts_attr_show_usbh2_ps_oc(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ int value;
+ struct gpio_pin *pin = gpio_pin_by_name("USBH2_PS_OC");
+
+ if (!pin) {
+ return -ENODEV;
+ }
+
+ mutex_lock(&mts_io_mutex);
+
+ value = at91_get_gpio_value(pin->pin);
+
+ mutex_unlock(&mts_io_mutex);
+
+ if (value < 0) {
+ return value;
+ }
+
+ return sprintf(buf, "%d\n", !value);
+}
+
+static struct device_attribute dev_attr_usbh2_ps_oc = {
+ .attr = {
+ .name = "usbh2-ps-oc",
+ .mode = MTS_ATTR_MODE_RO,
+ },
+ .show = mts_attr_show_usbh2_ps_oc,
+};
+
+#if USBH2_PS_CONTROLLABLE
+static ssize_t mts_attr_show_usbh2_ps_enabled(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ int value;
+ struct gpio_pin *pin = gpio_pin_by_name("USBH2_PS_ENABLED");
+
+ if (!pin) {
+ return -ENODEV;
+ }
+
+ mutex_lock(&mts_io_mutex);
+
+ value = at91_get_gpio_value(pin->pin);
+
+ mutex_unlock(&mts_io_mutex);
+
+ if (value < 0) {
+ return value;
+ }
+
+ return sprintf(buf, "%d\n", !value);
+}
+
+static ssize_t mts_attr_store_usbh2_ps_enabled(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t count)
+{
+ int value;
+ int err;
+ struct gpio_pin *pin = gpio_pin_by_name("USBH2_PS_ENABLED");
+
+ if (!pin) {
+ return -ENODEV;
+ }
+
+ if (sscanf(buf, "%i", &value) != 1) {
+ return -EINVAL;
+ }
+
+ mutex_lock(&mts_io_mutex);
+
+ err = at91_set_gpio_value(pin->pin, !value);
+
+ mutex_unlock(&mts_io_mutex);
+
+ if (err) {
+ return err;
+ }
+
+ return count;
+}
+
+static struct device_attribute dev_attr_usbh2_ps_enabled = {
+ .attr = {
+ .name = "usbh2-ps-enabled",
+ .mode = MTS_ATTR_MODE_RW,
+ },
+ .show = mts_attr_show_usbh2_ps_enabled,
+ .store = mts_attr_store_usbh2_ps_enabled,
+};
+#endif
+
static struct attribute *platform_attributes[] = {
&dev_attr_reset.attr,
&dev_attr_reset_monitor.attr,
&dev_attr_radio_reset.attr,
&dev_attr_eth0_enabled.attr,
&dev_attr_extserial_dtr.attr,
-#if LED_LS_CONTROLLABLE
&dev_attr_led_ls.attr,
-#endif
#if LED_STATUS_CONTROLLABLE
&dev_attr_led_status.attr,
&dev_attr_led_sdk_a.attr,
#endif
+ &dev_attr_usbh2_ps_oc.attr,
+#if USBH2_PS_CONTROLLABLE
+ &dev_attr_usbh2_ps_enabled.attr,
+#endif
&dev_attr_extserial_dcd.attr,
&dev_attr_extserial_ri.attr,
@@ -1753,7 +1899,9 @@ static int __init mts_io_init(void)
}
pin = gpio_pin_by_name("ENIO");
- at91_set_gpio_value(pin->pin, 0);
+ if (pin) {
+ at91_set_gpio_value(pin->pin, 0);
+ }
blink_callback(NULL);