summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Gilles <jgilles@multitech.com>2013-02-25 10:53:26 -0600
committerJesse Gilles <jgilles@multitech.com>2013-02-25 10:53:26 -0600
commit179f87cf87c48e82f7e74b747fd9acbf9c1f8d3a (patch)
tree8e6f6a1b5badd7dc8823ad12c7818d1a814240b9
parentcfcc6385560a16628fe45db5389aa2dd8c115421 (diff)
downloadcdp-io-controller-179f87cf87c48e82f7e74b747fd9acbf9c1f8d3a.tar.gz
cdp-io-controller-179f87cf87c48e82f7e74b747fd9acbf9c1f8d3a.tar.bz2
cdp-io-controller-179f87cf87c48e82f7e74b747fd9acbf9c1f8d3a.zip
code cleanup and re-org
-rw-r--r--io-module/mts_io.c1168
-rw-r--r--io-module/mts_io.h41
2 files changed, 307 insertions, 902 deletions
diff --git a/io-module/mts_io.c b/io-module/mts_io.c
index 68e856f..ced39b9 100644
--- a/io-module/mts_io.c
+++ b/io-module/mts_io.c
@@ -1,9 +1,10 @@
/*
* MTCDP IO Controller
*
- * Copyright (C) 2010 by Multi-Tech Systems
+ * Copyright (C) 2013 by Multi-Tech Systems
*
- * Author: James Maki <jmaki@multitech.com>
+ * Authors: James Maki <jmaki@multitech.com>
+ * Jesse Gilles <jgilles@multitech.com>
*
* 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
@@ -67,12 +68,6 @@
# define log_debug(format, args...) do {} while (0)
#endif
-enum {
- LED_OFF,
- LED_ON,
- LED_FLASHING,
-};
-
#define LED_STATUS_CONTROLLABLE_MTCDP 0
#define LED_LS_CONTROLLABLE 0
#define USBH2_PS_CONTROLLABLE 0
@@ -88,21 +83,8 @@ static int led_mode_status = LED_OFF;
#define SOUT_LED_SIG3_BIT BIT(6)
#define SOUT_EXTSERIAL_DCD_BIT BIT(7)
-// GPIO pin types:input, output, open drain (1 = high Z, 0 = output low)
-enum {
- GPIO_DIR_INPUT,
- GPIO_DIR_OUTPUT,
- GPIO_DIR_OD,
-};
-
-struct gpio_pin {
- char name[32];
- char attr_name[32];
- unsigned pin;
- int direction;
- int output_value;
- int use_pullup;
-};
+extern uint8_t mts_id_eeprom[512];
+static struct mts_id_eeprom_layout id_eeprom;
static uint8_t mts_product_id;
static uint8_t has_spi_sout;
@@ -110,6 +92,8 @@ static uint8_t has_spi_din;
static uint8_t has_spi_dout;
static uint8_t has_spi_temp;
+static struct attribute_group *attr_group;
+
static struct gpio_pin *gpio_pins;
static struct gpio_pin gpio_pins_mtcdp_0_0[] = {
@@ -230,7 +214,6 @@ static struct gpio_pin gpio_pins_mtcdp_1_0[] = {
#endif
.output_value = 1,
.use_pullup = 0,
-
},
#if LED_STATUS_CONTROLLABLE_MTCDP
{
@@ -330,7 +313,7 @@ static struct gpio_pin gpio_pins_mt100eocg_0_0[] = {
},
{
.name = "LED3",
- .attr_name = "led-ls",
+ .attr_name = "led3",
.pin = AT91_PIN_PC9,
#if LED_LS_CONTROLLABLE
.direction = GPIO_DIR_OUTPUT,
@@ -748,103 +731,6 @@ struct gpio_pin *gpio_pin_by_attr_name(const char *name) {
return NULL;
}
-extern uint8_t mts_id_eeprom[512];
-static struct mts_id_eeprom_layout id_eeprom;
-
-static int mts_id_eeprom_load(void)
-{
- memcpy(&id_eeprom, mts_id_eeprom, sizeof(mts_id_eeprom));
-
- mts_product_id = MTCDP_E1_DK_1_0;
- has_spi_sout = 1;
- has_spi_din = 1;
- has_spi_dout = 1;
- has_spi_temp = 1;
-
- if (mts_id_eeprom[0] == 0xFF) {
- log_error("uninitialized eeprom");
- return -EIO;
- } else if (mts_id_eeprom[0] == 0x00) {
- strncpy(id_eeprom.vendor_id, VENDOR_ID_MULTITECH, sizeof(id_eeprom.vendor_id) - 1);
- strncpy(id_eeprom.product_id, PRODUCT_ID_MTCDP_E1_DK, sizeof(id_eeprom.product_id) - 1);
- strncpy(id_eeprom.device_id, "", sizeof(id_eeprom.device_id) - 1);
- strncpy(id_eeprom.hw_version, HW_VERSION_MTCDP_0_0, sizeof(id_eeprom.hw_version) - 1);
-
- DEVICE_CAPA_SET(id_eeprom.capa, CAPA_GPS);
-
- gpio_pins = gpio_pins_mtcdp_0_0;
- mts_product_id = MTCDP_E1_DK_0_0;
- log_info("detected board %s", HW_VERSION_MTCDP_0_0);
- } else if (strncmp(id_eeprom.product_id, PRODUCT_ID_MT100EOCG, strlen(PRODUCT_ID_MT100EOCG)) == 0) {
- gpio_pins = gpio_pins_mt100eocg_0_0;
- mts_product_id = MT100EOCG_0_0;
- has_spi_sout = 0;
- has_spi_din = 1;
- has_spi_dout = 1;
- has_spi_temp = 1;
- log_info("detected board %s", HW_VERSION_MT100EOCG_0_0);
- } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTR2_0_0, strlen(HW_VERSION_MTR2_0_0)) == 0) {
- gpio_pins = gpio_pins_mtr2_0_0;
- mts_product_id = MTR2_0_0;
- has_spi_sout = 0;
- has_spi_din = 0;
- has_spi_dout = 0;
- has_spi_temp = 1;
- log_info("detected board %s", HW_VERSION_MTR2_0_0);
- } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTR_0_0, strlen(HW_VERSION_MTR_0_0)) == 0) {
- gpio_pins = gpio_pins_mtr_0_0;
- mts_product_id = MTR_0_0;
- has_spi_sout = 0;
- has_spi_din = 0;
- has_spi_dout = 0;
- has_spi_temp = 0;
- log_info("detected board %s", HW_VERSION_MTR_0_0);
- } else {
- gpio_pins = gpio_pins_mtcdp_1_0;
- mts_product_id = MTCDP_E1_DK_1_0;
- has_spi_sout = 1;
- has_spi_din = 1;
- has_spi_dout = 1;
- has_spi_temp = 1;
- log_info("detected board %s", HW_VERSION_MTCDP_1_0);
- }
-
- log_info("sizeof: %lu", (unsigned long) sizeof(struct mts_id_eeprom_layout));
- log_info("vendor-id: %.32s", id_eeprom.vendor_id);
- log_info("product-id: %.32s", id_eeprom.product_id);
- log_info("device-id: %.32s", id_eeprom.device_id);
- log_info("hw-version: %.32s", id_eeprom.hw_version);
- log_info("mac-addr: %02X:%02X:%02X:%02X:%02X:%02X",
- id_eeprom.mac_addr[0],
- id_eeprom.mac_addr[1],
- id_eeprom.mac_addr[2],
- id_eeprom.mac_addr[3],
- id_eeprom.mac_addr[4],
- id_eeprom.mac_addr[5]);
- log_info("imei: %.32s", id_eeprom.imei);
- log_info("capa-gps: %s", DEVICE_CAPA(id_eeprom.capa, CAPA_GPS) ? "yes" : "no");
- log_info("capa-din: %s", DEVICE_CAPA(id_eeprom.capa, CAPA_DIN) ? "yes" : "no");
- log_info("capa-dout: %s", DEVICE_CAPA(id_eeprom.capa, CAPA_DOUT) ? "yes" : "no");
- log_info("capa-adc: %s", DEVICE_CAPA(id_eeprom.capa, CAPA_ADC) ? "yes" : "no");
- log_info("capa-wifi: %s", DEVICE_CAPA(id_eeprom.capa, CAPA_WIFI) ? "yes" : "no");
- log_info("capa-bluetooth: %s", DEVICE_CAPA(id_eeprom.capa, CAPA_BLUETOOTH) ? "yes" : "no");
- log_info("mac-bluetooth: %02X:%02X:%02X:%02X:%02X:%02X",
- id_eeprom.mac_bluetooth[0],
- id_eeprom.mac_bluetooth[1],
- id_eeprom.mac_bluetooth[2],
- id_eeprom.mac_bluetooth[3],
- id_eeprom.mac_bluetooth[4],
- id_eeprom.mac_bluetooth[5]);
- log_info("mac-wifi: %02X:%02X:%02X:%02X:%02X:%02X",
- id_eeprom.mac_wifi[0],
- id_eeprom.mac_wifi[1],
- id_eeprom.mac_wifi[2],
- id_eeprom.mac_wifi[3],
- id_eeprom.mac_wifi[4],
- id_eeprom.mac_wifi[5]);
-
- return 0;
-}
static struct spi_device *spi_sout_dev;
static u8 spi_sout_value;
@@ -1103,10 +989,6 @@ static int ADT7302_to_celsius(int value)
return value;
}
-
-#define MTS_ATTR_MODE_RW S_IWUSR | S_IRUGO
-#define MTS_ATTR_MODE_RO S_IRUGO
-
static ssize_t mts_attr_show_gpio_pin(struct device *dev,
struct device_attribute *attr,
char *buf)
@@ -1263,14 +1145,8 @@ static ssize_t mts_attr_store_radio_reset_telit(struct device *dev,
return count;
}
-static struct device_attribute dev_attr_radio_reset = {
- .attr = {
- .name = "radio-reset",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_gpio_pin,
- .store = mts_attr_store_radio_reset,
-};
+static DEVICE_ATTR_MTS(dev_attr_radio_reset, "radio-reset",
+ mts_attr_show_gpio_pin, mts_attr_store_radio_reset);
static ssize_t mts_attr_store_ndc_reset(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
@@ -1297,42 +1173,17 @@ static ssize_t mts_attr_store_ndc_reset(struct device *dev,
return count;
}
+static DEVICE_ATTR_MTS(dev_attr_ndc_reset, "ndc-reset",
+ mts_attr_show_gpio_pin, mts_attr_store_ndc_reset);
-static struct device_attribute dev_attr_ndc_reset = {
- .attr = {
- .name = "ndc-reset",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_gpio_pin,
- .store = mts_attr_store_ndc_reset,
-};
+static DEVICE_ATTR_MTS(dev_attr_eth0_enabled, "eth0-enabled",
+ mts_attr_show_gpio_pin, mts_attr_store_gpio_pin);
-static struct device_attribute dev_attr_eth0_enabled = {
- .attr = {
- .name = "eth0-enabled",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_gpio_pin,
- .store = mts_attr_store_gpio_pin,
-};
-
-static struct device_attribute dev_attr_bt_enabled = {
- .attr = {
- .name = "bt-enabled",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_gpio_pin,
- .store = mts_attr_store_gpio_pin,
-};
+static DEVICE_ATTR_MTS(dev_attr_bt_enabled, "bt-enabled",
+ mts_attr_show_gpio_pin, mts_attr_store_gpio_pin);
-static struct device_attribute dev_attr_wlan_enabled = {
- .attr = {
- .name = "wlan-enabled",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_gpio_pin,
- .store = mts_attr_store_gpio_pin,
-};
+static DEVICE_ATTR_MTS(dev_attr_wlan_enabled, "wlan-enabled",
+ mts_attr_show_gpio_pin, mts_attr_store_gpio_pin);
static ssize_t mts_attr_store_sout(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
@@ -1437,122 +1288,44 @@ static ssize_t mts_attr_show_sout(struct device *dev,
return sprintf(buf, "%d\n", value);
}
-static struct device_attribute dev_attr_extserial_dcd = {
- .attr = {
- .name = "extserial-dcd",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_sout,
- .store = mts_attr_store_sout,
-};
+static DEVICE_ATTR_MTS(dev_attr_extserial_dcd, "extserial-dcd",
+ mts_attr_show_sout, mts_attr_store_sout);
-static struct device_attribute dev_attr_extserial_ri = {
- .attr = {
- .name = "extserial-ri",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_sout,
- .store = mts_attr_store_sout,
-};
+static DEVICE_ATTR_MTS(dev_attr_extserial_ri, "extserial-ri",
+ mts_attr_show_sout, mts_attr_store_sout);
-static struct device_attribute dev_attr_extserial_dsr = {
- .attr = {
- .name = "extserial-dsr",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_sout,
- .store = mts_attr_store_sout,
-};
+static DEVICE_ATTR_MTS(dev_attr_extserial_dsr, "extserial-dsr",
+ mts_attr_show_sout, mts_attr_store_sout);
-static struct device_attribute dev_attr_led_cd = {
- .attr = {
- .name = "led-cd",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_sout,
- .store = mts_attr_store_sout,
-};
+static DEVICE_ATTR_MTS(dev_attr_led_cd, "led-cd",
+ mts_attr_show_sout, mts_attr_store_sout);
-static struct device_attribute dev_attr_led_sdk_b = {
- .attr = {
- .name = "led-sdk-b",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_sout,
- .store = mts_attr_store_sout,
-};
+static DEVICE_ATTR_MTS(dev_attr_led_sdk_b, "led-sdk-b",
+ mts_attr_show_sout, mts_attr_store_sout);
-static struct device_attribute dev_attr_led_sig1 = {
- .attr = {
- .name = "led-sig1",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_sout,
- .store = mts_attr_store_sout,
-};
+static DEVICE_ATTR_MTS(dev_attr_led_sig1, "led-sig1",
+ mts_attr_show_sout, mts_attr_store_sout);
-static struct device_attribute dev_attr_led_sdk_c = {
- .attr = {
- .name = "led-sdk-c",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_sout,
- .store = mts_attr_store_sout,
-};
+static DEVICE_ATTR_MTS(dev_attr_led_sdk_c, "led-sdk-c",
+ mts_attr_show_sout, mts_attr_store_sout);
-static struct device_attribute dev_attr_led_sig2 = {
- .attr = {
- .name = "led-sig2",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_sout,
- .store = mts_attr_store_sout,
-};
+static DEVICE_ATTR_MTS(dev_attr_led_sig2, "led-sig2",
+ mts_attr_show_sout, mts_attr_store_sout);
-static struct device_attribute dev_attr_led_sdk_d = {
- .attr = {
- .name = "led-sdk-d",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_sout,
- .store = mts_attr_store_sout,
-};
+static DEVICE_ATTR_MTS(dev_attr_led_sdk_d, "led-sdk-d",
+ mts_attr_show_sout, mts_attr_store_sout);
-static struct device_attribute dev_attr_led_sig3 = {
- .attr = {
- .name = "led-sig3",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_sout,
- .store = mts_attr_store_sout,
-};
+static DEVICE_ATTR_MTS(dev_attr_led_sig3, "led-sig3",
+ mts_attr_show_sout, mts_attr_store_sout);
-static struct device_attribute dev_attr_led_sdk_e = {
- .attr = {
- .name = "led-sdk-e",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_sout,
- .store = mts_attr_store_sout,
-};
+static DEVICE_ATTR_MTS(dev_attr_led_sdk_e, "led-sdk-e",
+ mts_attr_show_sout, mts_attr_store_sout);
-static struct device_attribute dev_attr_led_dtr = {
- .attr = {
- .name = "led-dtr",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_sout,
- .store = mts_attr_store_sout,
-};
+static DEVICE_ATTR_MTS(dev_attr_led_dtr, "led-dtr",
+ mts_attr_show_sout, mts_attr_store_sout);
-static struct device_attribute dev_attr_led_sdk_f = {
- .attr = {
- .name = "led-sdk-f",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_sout,
- .store = mts_attr_store_sout,
-};
+static DEVICE_ATTR_MTS(dev_attr_led_sdk_f, "led-sdk-f",
+ mts_attr_show_sout, mts_attr_store_sout);
static ssize_t mts_attr_store_dout(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
@@ -1648,77 +1421,24 @@ static ssize_t mts_attr_show_dout(struct device *dev,
return sprintf(buf, "%d\n", value);
}
-static struct device_attribute dev_attr_dout0 = {
- .attr = {
- .name = "dout0",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_dout,
- .store = mts_attr_store_dout,
-};
-static struct device_attribute dev_attr_dout1 = {
- .attr = {
- .name = "dout1",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_dout,
- .store = mts_attr_store_dout,
-};
-
-static struct device_attribute dev_attr_dout2 = {
- .attr = {
- .name = "dout2",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_dout,
- .store = mts_attr_store_dout,
-};
+static DEVICE_ATTR_MTS(dev_attr_dout0, "dout0",
+ mts_attr_show_dout, mts_attr_store_dout);
+static DEVICE_ATTR_MTS(dev_attr_dout1, "dout1",
+ mts_attr_show_dout, mts_attr_store_dout);
+static DEVICE_ATTR_MTS(dev_attr_dout2, "dout2",
+ mts_attr_show_dout, mts_attr_store_dout);
+static DEVICE_ATTR_MTS(dev_attr_dout3, "dout3",
+ mts_attr_show_dout, mts_attr_store_dout);
+static DEVICE_ATTR_MTS(dev_attr_dout4, "dout4",
+ mts_attr_show_dout, mts_attr_store_dout);
+static DEVICE_ATTR_MTS(dev_attr_dout5, "dout5",
+ mts_attr_show_dout, mts_attr_store_dout);
+static DEVICE_ATTR_MTS(dev_attr_dout6, "dout6",
+ mts_attr_show_dout, mts_attr_store_dout);
+static DEVICE_ATTR_MTS(dev_attr_dout7, "dout7",
+ mts_attr_show_dout, mts_attr_store_dout);
-static struct device_attribute dev_attr_dout3 = {
- .attr = {
- .name = "dout3",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_dout,
- .store = mts_attr_store_dout,
-};
-
-static struct device_attribute dev_attr_dout4 = {
- .attr = {
- .name = "dout4",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_dout,
- .store = mts_attr_store_dout,
-};
-
-static struct device_attribute dev_attr_dout5 = {
- .attr = {
- .name = "dout5",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_dout,
- .store = mts_attr_store_dout,
-};
-
-static struct device_attribute dev_attr_dout6 = {
- .attr = {
- .name = "dout6",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_dout,
- .store = mts_attr_store_dout,
-};
-
-static struct device_attribute dev_attr_dout7 = {
- .attr = {
- .name = "dout7",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_dout,
- .store = mts_attr_store_dout,
-};
static ssize_t mts_attr_show_din(struct device *dev,
struct device_attribute *attr,
@@ -1765,95 +1485,23 @@ static ssize_t mts_attr_show_din(struct device *dev,
return sprintf(buf, "%d\n", tmp);
}
-static struct device_attribute dev_attr_din0 = {
- .attr = {
- .name = "din0",
- .mode = MTS_ATTR_MODE_RO,
- },
- .show = mts_attr_show_din,
-};
-
-static struct device_attribute dev_attr_din1 = {
- .attr = {
- .name = "din1",
- .mode = MTS_ATTR_MODE_RO,
- },
- .show = mts_attr_show_din,
-};
-
-static struct device_attribute dev_attr_din2 = {
- .attr = {
- .name = "din2",
- .mode = MTS_ATTR_MODE_RO,
- },
- .show = mts_attr_show_din,
-};
-
-static struct device_attribute dev_attr_din3 = {
- .attr = {
- .name = "din3",
- .mode = MTS_ATTR_MODE_RO,
- },
- .show = mts_attr_show_din,
-};
-
-static struct device_attribute dev_attr_din4 = {
- .attr = {
- .name = "din4",
- .mode = MTS_ATTR_MODE_RO,
- },
- .show = mts_attr_show_din,
-};
-
-static struct device_attribute dev_attr_din5 = {
- .attr = {
- .name = "din5",
- .mode = MTS_ATTR_MODE_RO,
- },
- .show = mts_attr_show_din,
-};
+static DEVICE_ATTR_RO_MTS(dev_attr_din0, "din0", mts_attr_show_din);
+static DEVICE_ATTR_RO_MTS(dev_attr_din1, "din1", mts_attr_show_din);
+static DEVICE_ATTR_RO_MTS(dev_attr_din2, "din2", mts_attr_show_din);
+static DEVICE_ATTR_RO_MTS(dev_attr_din3, "din3", mts_attr_show_din);
+static DEVICE_ATTR_RO_MTS(dev_attr_din4, "din4", mts_attr_show_din);
+static DEVICE_ATTR_RO_MTS(dev_attr_din5, "din5", mts_attr_show_din);
+static DEVICE_ATTR_RO_MTS(dev_attr_din6, "din6", mts_attr_show_din);
+static DEVICE_ATTR_RO_MTS(dev_attr_din7, "din7", mts_attr_show_din);
-static struct device_attribute dev_attr_din6 = {
- .attr = {
- .name = "din6",
- .mode = MTS_ATTR_MODE_RO,
- },
- .show = mts_attr_show_din,
-};
-
-static struct device_attribute dev_attr_din7 = {
- .attr = {
- .name = "din7",
- .mode = MTS_ATTR_MODE_RO,
- },
- .show = mts_attr_show_din,
-};
-
-static struct device_attribute dev_attr_extserial_dtr = {
- .attr = {
- .name = "extserial-dtr",
- .mode = MTS_ATTR_MODE_RO,
- },
- .show = mts_attr_show_gpio_pin_inverted,
-};
+static DEVICE_ATTR_RO_MTS(dev_attr_extserial_dtr, "extserial-dtr",
+ mts_attr_show_gpio_pin_inverted);
-static struct device_attribute dev_attr_extserial_dsr_gpio = {
- .attr = {
- .name = "extserial-dsr",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_gpio_pin_inverted,
- .store = mts_attr_store_gpio_pin_inverted,
-};
+static DEVICE_ATTR_MTS(dev_attr_extserial_dsr_gpio, "extserial-dsr",
+ mts_attr_show_gpio_pin_inverted, mts_attr_store_gpio_pin_inverted);
-static struct device_attribute dev_attr_extserial_ri_gpio = {
- .attr = {
- .name = "extserial-ri",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_gpio_pin_inverted,
- .store = mts_attr_store_gpio_pin_inverted,
-};
+static DEVICE_ATTR_MTS(dev_attr_extserial_ri_gpio, "extserial-ri",
+ mts_attr_show_gpio_pin_inverted, mts_attr_store_gpio_pin_inverted);
static ssize_t mts_attr_show_led_status(struct device *dev,
struct device_attribute *attr,
@@ -1907,166 +1555,39 @@ static ssize_t mts_attr_store_led_status(struct device *dev,
return count;
}
-static struct device_attribute dev_attr_led_status = {
- .attr = {
- .name = "led-status",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_led_status,
- .store = mts_attr_store_led_status,
-};
+static DEVICE_ATTR_MTS(dev_attr_led_status, "led-status",
+ mts_attr_show_led_status, mts_attr_store_led_status);
#if LED_STATUS_CONTROLLABLE_MTCDP
-static struct device_attribute dev_attr_led_sdk_a = {
- .attr = {
- .name = "led-sdk-a",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_led_status,
- .store = mts_attr_store_led_status,
-};
+static DEVICE_ATTR_MTS(dev_attr_led_sdk_a, "led-sdk-a",
+ mts_attr_show_led_status, mts_attr_store_led_status);
#endif
-static ssize_t mts_attr_show_led_ls(struct device *dev,
- struct device_attribute *attr,
- char *buf)
-{
- int value;
- struct gpio_pin *pin;
-
- if ( mts_product_id == MT100EOCG_0_0 ) {
- pin = gpio_pin_by_name("LED3");
- }
- else {
- pin = gpio_pin_by_name("LS_LED");
- }
-
- 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_led_ls(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count)
-{
- int value;
- int err;
- struct gpio_pin *pin;
-
- if ( mts_product_id == MT100EOCG_0_0 ) {
- pin = gpio_pin_by_name("LED3");
- }
- else {
- pin = gpio_pin_by_name("LS_LED");
- }
-
- 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_led_ls = {
- .attr = {
- .name = "led-ls",
#if LED_LS_CONTROLLABLE
- .mode = MTS_ATTR_MODE_RW,
+static DEVICE_ATTR_MTS(dev_attr_led_ls, "led-ls",
+ mts_attr_show_gpio_pin_inverted, mts_attr_store_gpio_pin_inverted);
#else
- .mode = MTS_ATTR_MODE_RO,
+static DEVICE_ATTR_RO_MTS(dev_attr_led_ls, "led-ls",
+ mts_attr_show_gpio_pin_inverted);
#endif
- },
- .show = mts_attr_show_gpio_pin_inverted,
- .store = mts_attr_store_gpio_pin_inverted,
-};
-static struct device_attribute dev_attr_led_sig1_gpio = {
- .attr = {
- .name = "led-sig1",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_gpio_pin_inverted,
- .store = mts_attr_store_gpio_pin_inverted,
-};
+static DEVICE_ATTR_MTS(dev_attr_led_sig1_gpio, "led-sig1",
+ mts_attr_show_gpio_pin_inverted, mts_attr_store_gpio_pin_inverted);
+static DEVICE_ATTR_MTS(dev_attr_led_sig2_gpio, "led-sig2",
+ mts_attr_show_gpio_pin_inverted, mts_attr_store_gpio_pin_inverted);
+static DEVICE_ATTR_MTS(dev_attr_led_sig3_gpio, "led-sig3",
+ mts_attr_show_gpio_pin_inverted, mts_attr_store_gpio_pin_inverted);
-static struct device_attribute dev_attr_led_sig2_gpio = {
- .attr = {
- .name = "led-sig2",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_gpio_pin_inverted,
- .store = mts_attr_store_gpio_pin_inverted,
-};
+static DEVICE_ATTR_MTS(dev_attr_led_cd_gpio, "led-cd",
+ mts_attr_show_gpio_pin_inverted, mts_attr_store_gpio_pin_inverted);
-static struct device_attribute dev_attr_led_sig3_gpio = {
- .attr = {
- .name = "led-sig3",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_gpio_pin_inverted,
- .store = mts_attr_store_gpio_pin_inverted,
-};
+static DEVICE_ATTR_MTS(dev_attr_led_wifi_gpio, "led-wifi",
+ mts_attr_show_gpio_pin_inverted, mts_attr_store_gpio_pin_inverted);
-static struct device_attribute dev_attr_led_cd_gpio = {
- .attr = {
- .name = "led-cd",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_gpio_pin_inverted,
- .store = mts_attr_store_gpio_pin_inverted,
-};
+static DEVICE_ATTR_RO_MTS(dev_attr_reset, "reset", mts_attr_show_gpio_pin_inverted);
-static struct device_attribute dev_attr_led_wifi = {
- .attr = {
- .name = "led-wifi",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_gpio_pin_inverted,
- .store = mts_attr_store_gpio_pin_inverted,
-};
-
-static struct device_attribute dev_attr_reset = {
- .attr = {
- .name = "reset",
- .mode = MTS_ATTR_MODE_RO,
- },
- .show = mts_attr_show_gpio_pin_inverted,
-};
-
-static struct device_attribute dev_attr_rs4xx_term_res = {
- .attr = {
- .name = "rs4xx-term-res",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_gpio_pin,
- .store = mts_attr_store_gpio_pin,
-};
+static DEVICE_ATTR_MTS(dev_attr_rs4xx_term_res, "rs4xx-term-res",
+ mts_attr_show_gpio_pin, mts_attr_store_gpio_pin);
static ssize_t mts_attr_show_reset_monitor(struct device *dev,
struct device_attribute *attr,
@@ -2105,14 +1626,8 @@ static ssize_t mts_attr_store_reset_monitor(struct device *dev,
return count;
}
-static struct device_attribute dev_attr_reset_monitor = {
- .attr = {
- .name = "reset-monitor",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_reset_monitor,
- .store = mts_attr_store_reset_monitor,
-};
+static DEVICE_ATTR_MTS(dev_attr_reset_monitor, "reset-monitor",
+ mts_attr_show_reset_monitor, mts_attr_store_reset_monitor);
static ssize_t mts_attr_show_board_temperature(struct device *dev,
struct device_attribute *attr,
@@ -2138,13 +1653,8 @@ static ssize_t mts_attr_show_board_temperature(struct device *dev,
return sprintf(buf, "%d\n", ADT7302_to_celsius(temp_raw));
}
-static struct device_attribute dev_attr_board_temperature = {
- .attr = {
- .name = "board-temperature",
- .mode = MTS_ATTR_MODE_RO,
- },
- .show = mts_attr_show_board_temperature,
-};
+static DEVICE_ATTR_RO_MTS(dev_attr_board_temperature, "board-temperature",
+ mts_attr_show_board_temperature);
static ssize_t mts_attr_show_adc(struct device *dev,
struct device_attribute *attr,
@@ -2199,234 +1709,63 @@ static ssize_t mts_attr_show_adc(struct device *dev,
return sprintf(buf, "%lu\n", (unsigned long) value);
}
-static struct device_attribute dev_attr_adc0 = {
- .attr = {
- .name = "adc0",
- .mode = MTS_ATTR_MODE_RO,
- },
- .show = mts_attr_show_adc,
-};
+static DEVICE_ATTR_RO_MTS(dev_attr_adc0, "adc0", mts_attr_show_adc);
+static DEVICE_ATTR_RO_MTS(dev_attr_adc1, "adc1", mts_attr_show_adc);
+static DEVICE_ATTR_RO_MTS(dev_attr_adc2, "adc2", mts_attr_show_adc);
+static DEVICE_ATTR_RO_MTS(dev_attr_adc3, "adc3", mts_attr_show_adc);
-static struct device_attribute dev_attr_adc1 = {
- .attr = {
- .name = "adc1",
- .mode = MTS_ATTR_MODE_RO,
- },
- .show = mts_attr_show_adc,
-};
-
-static struct device_attribute dev_attr_adc2 = {
- .attr = {
- .name = "adc2",
- .mode = MTS_ATTR_MODE_RO,
- },
- .show = mts_attr_show_adc,
-};
-
-static struct device_attribute dev_attr_adc3 = {
- .attr = {
- .name = "adc3",
- .mode = MTS_ATTR_MODE_RO,
- },
- .show = mts_attr_show_adc,
-};
-
-static struct device_attribute dev_attr_usbh2_ps_oc = {
- .attr = {
- .name = "usbh2-ps-oc",
- .mode = MTS_ATTR_MODE_RO,
- },
- .show = mts_attr_show_gpio_pin_inverted,
-};
+static DEVICE_ATTR_RO_MTS(dev_attr_usbh2_ps_oc, "usbh2-ps-oc",
+ mts_attr_show_gpio_pin_inverted);
#if USBH2_PS_CONTROLLABLE
-static struct device_attribute dev_attr_usbh2_ps_enabled = {
- .attr = {
- .name = "usbh2-ps-enabled",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_gpio_pin_inverted,
- .store = mts_attr_store_gpio_pin_inverted,
-};
+static DEVICE_ATTR_MTS(dev_attr_usbh2_ps_enabled, "usbh2-ps-enabled",
+ mts_attr_show_gpio_pin_inverted, mts_attr_store_gpio_pin_inverted);
#endif
-static struct device_attribute dev_attr_gpo1 = {
- .attr = {
- .name = "gpo1",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_dout,
- .store = mts_attr_store_dout,
-};
-
-static struct device_attribute dev_attr_gpo2 = {
- .attr = {
- .name = "gpo2",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_dout,
- .store = mts_attr_store_dout,
-};
-
-static struct device_attribute dev_attr_gpo3 = {
- .attr = {
- .name = "gpo3",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_dout,
- .store = mts_attr_store_dout,
-};
-
-static struct device_attribute dev_attr_gpo4 = {
- .attr = {
- .name = "gpo4",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_dout,
- .store = mts_attr_store_dout,
-};
-
-static struct device_attribute dev_attr_gpi5 = {
- .attr = {
- .name = "gpi5",
- .mode = MTS_ATTR_MODE_RO,
- },
- .show = mts_attr_show_din,
-};
-
-static struct device_attribute dev_attr_gpi6 = {
- .attr = {
- .name = "gpi6",
- .mode = MTS_ATTR_MODE_RO,
- },
- .show = mts_attr_show_din,
-};
-
-static struct device_attribute dev_attr_gpi7 = {
- .attr = {
- .name = "gpi7",
- .mode = MTS_ATTR_MODE_RO,
- },
- .show = mts_attr_show_din,
-};
-
-static struct device_attribute dev_attr_gpi8 = {
- .attr = {
- .name = "gpi8",
- .mode = MTS_ATTR_MODE_RO,
- },
- .show = mts_attr_show_din,
-};
-
-static struct device_attribute dev_attr_gpi9 = {
- .attr = {
- .name = "gpi9",
- .mode = MTS_ATTR_MODE_RO,
- },
- .show = mts_attr_show_din,
-};
-
-static struct device_attribute dev_attr_gpi10 = {
- .attr = {
- .name = "gpi10",
- .mode = MTS_ATTR_MODE_RO,
- },
- .show = mts_attr_show_din,
-};
-
-static struct device_attribute dev_attr_led1 = {
- .attr = {
- .name = "led1",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_dout,
- .store = mts_attr_store_dout,
-};
+static DEVICE_ATTR_MTS(dev_attr_gpo1, "gpo1",
+ mts_attr_show_dout, mts_attr_store_dout);
+static DEVICE_ATTR_MTS(dev_attr_gpo2, "gpo2",
+ mts_attr_show_dout, mts_attr_store_dout);
+static DEVICE_ATTR_MTS(dev_attr_gpo3, "gpo3",
+ mts_attr_show_dout, mts_attr_store_dout);
+static DEVICE_ATTR_MTS(dev_attr_gpo4, "gpo4",
+ mts_attr_show_dout, mts_attr_store_dout);
+
+static DEVICE_ATTR_RO_MTS(dev_attr_gpi5, "gpi5", mts_attr_show_din);
+static DEVICE_ATTR_RO_MTS(dev_attr_gpi6, "gpi6", mts_attr_show_din);
+static DEVICE_ATTR_RO_MTS(dev_attr_gpi7, "gpi7", mts_attr_show_din);
+static DEVICE_ATTR_RO_MTS(dev_attr_gpi8, "gpi8", mts_attr_show_din);
+static DEVICE_ATTR_RO_MTS(dev_attr_gpi9, "gpi9", mts_attr_show_din);
+static DEVICE_ATTR_RO_MTS(dev_attr_gpi10, "gpi10", mts_attr_show_din);
+
+static DEVICE_ATTR_MTS(dev_attr_led1, "led1",
+ mts_attr_show_dout, mts_attr_store_dout);
+static DEVICE_ATTR_MTS(dev_attr_led2, "led2",
+ mts_attr_show_gpio_pin_inverted, mts_attr_store_gpio_pin_inverted);
-static struct device_attribute dev_attr_led2 = {
- .attr = {
- .name = "led2",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_gpio_pin_inverted,
- .store = mts_attr_store_gpio_pin_inverted,
-};
-
-static struct device_attribute dev_attr_led3 = {
- .attr = {
- .name = "led3",
#if LED_LS_CONTROLLABLE
- .mode = MTS_ATTR_MODE_RW,
+static DEVICE_ATTR_MTS(dev_attr_led3, "led3",
+ mts_attr_show_gpio_pin_inverted, mts_attr_store_gpio_pin_inverted);
#else
- .mode = MTS_ATTR_MODE_RO,
+static DEVICE_ATTR_RO_MTS(dev_attr_led3, "led3", mts_attr_show_gpio_pin_inverted);
#endif
- },
- .show = mts_attr_show_led_ls,
- .store = mts_attr_store_led_ls,
-};
-static struct device_attribute dev_attr_led4 = {
- .attr = {
- .name = "led4",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_dout,
- .store = mts_attr_store_dout,
-};
+static DEVICE_ATTR_MTS(dev_attr_led4, "led4",
+ mts_attr_show_dout, mts_attr_store_dout);
+static DEVICE_ATTR_MTS(dev_attr_led5, "led5",
+ mts_attr_show_dout, mts_attr_store_dout);
+static DEVICE_ATTR_MTS(dev_attr_led6, "led6",
+ mts_attr_show_dout, mts_attr_store_dout);
-static struct device_attribute dev_attr_led5 = {
- .attr = {
- .name = "led5",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_dout,
- .store = mts_attr_store_dout,
-};
+static DEVICE_ATTR_MTS(dev_attr_gpio11, "gpio11",
+ mts_attr_show_gpio_pin, mts_attr_store_gpio_pin);
+static DEVICE_ATTR_MTS(dev_attr_gpio12, "gpio12",
+ mts_attr_show_gpio_pin, mts_attr_store_gpio_pin);
-static struct device_attribute dev_attr_led6 = {
- .attr = {
- .name = "led6",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_dout,
- .store = mts_attr_store_dout,
-};
-
-static struct device_attribute dev_attr_gpio11 = {
- .attr = {
- .name = "gpio11",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_gpio_pin,
- .store = mts_attr_store_gpio_pin,
-};
-
-static struct device_attribute dev_attr_gpio12 = {
- .attr = {
- .name = "gpio12",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_gpio_pin,
- .store = mts_attr_store_gpio_pin,
-};
-
-static struct device_attribute dev_attr_rsersrc = {
- .attr = {
- .name = "rsersrc",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_gpio_pin_inverted,
- .store = mts_attr_store_gpio_pin_inverted,
-};
-
-static struct device_attribute dev_attr_extserial_cd = {
- .attr = {
- .name = "extserial-dcd",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_gpio_pin_inverted,
- .store = mts_attr_store_gpio_pin_inverted,
-};
+static DEVICE_ATTR_MTS(dev_attr_rsersrc, "rsersrc",
+ mts_attr_show_gpio_pin_inverted, mts_attr_store_gpio_pin_inverted);
+static DEVICE_ATTR_MTS(dev_attr_extserial_dcd_gpio, "extserial-dcd",
+ mts_attr_show_gpio_pin_inverted, mts_attr_store_gpio_pin_inverted);
static ssize_t mts_attr_show_serial_mode(struct device *dev,
struct device_attribute *attr,
@@ -2507,36 +1846,18 @@ static ssize_t mts_attr_store_serial_mode(struct device *dev,
return count;
}
-static struct device_attribute dev_attr_serial_mode = {
- .attr = {
- .name = "serial-mode",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_serial_mode,
- .store = mts_attr_store_serial_mode,
-};
+static DEVICE_ATTR_MTS(dev_attr_serial_mode, "serial-mode",
+ mts_attr_show_serial_mode, mts_attr_store_serial_mode);
-static struct device_attribute dev_attr_eth_switch_enabled = {
- .attr = {
- .name = "eth-switch-enabled",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_gpio_pin,
- .store = mts_attr_store_gpio_pin,
-};
+static DEVICE_ATTR_MTS(dev_attr_eth_switch_enabled, "eth-switch-enabled",
+ mts_attr_show_gpio_pin, mts_attr_store_gpio_pin);
-static struct device_attribute dev_attr_radio_reset_telit = {
- .attr = {
- .name = "radio-reset",
- .mode = MTS_ATTR_MODE_RW,
- },
- .show = mts_attr_show_gpio_pin,
- .store = mts_attr_store_radio_reset_telit,
-};
+static DEVICE_ATTR_MTS(dev_attr_radio_reset_telit, "radio-reset",
+ mts_attr_show_gpio_pin, mts_attr_store_radio_reset_telit);
static struct attribute *mt100eocg_platform_attributes[] = {
&dev_attr_extserial_dtr.attr,
- &dev_attr_extserial_cd.attr,
+ &dev_attr_extserial_dcd_gpio.attr,
&dev_attr_rsersrc.attr,
&dev_attr_radio_reset.attr,
&dev_attr_eth0_enabled.attr,
@@ -2582,7 +1903,7 @@ static struct attribute *mtr2_platform_attributes[] = {
&dev_attr_extserial_dtr.attr,
&dev_attr_extserial_dsr_gpio.attr,
&dev_attr_extserial_ri_gpio.attr,
- &dev_attr_extserial_cd.attr,
+ &dev_attr_extserial_dcd_gpio.attr,
&dev_attr_eth_switch_enabled.attr,
&dev_attr_bt_enabled.attr,
&dev_attr_wlan_enabled.attr,
@@ -2595,7 +1916,7 @@ static struct attribute *mtr2_platform_attributes[] = {
&dev_attr_led_sig2_gpio.attr,
&dev_attr_led_sig3_gpio.attr,
&dev_attr_led_cd_gpio.attr,
- &dev_attr_led_wifi.attr,
+ &dev_attr_led_wifi_gpio.attr,
&dev_attr_board_temperature.attr,
@@ -2606,7 +1927,7 @@ static struct attribute_group mtr2_platform_attribute_group = {
.attrs = mtr2_platform_attributes
};
-static struct attribute *platform_attributes[] = {
+static struct attribute *mtcdp_platform_attributes[] = {
&dev_attr_reset.attr,
&dev_attr_reset_monitor.attr,
&dev_attr_radio_reset.attr,
@@ -2665,8 +1986,8 @@ static struct attribute *platform_attributes[] = {
NULL,
};
-static struct attribute_group platform_attribute_group = {
- .attrs = platform_attributes
+static struct attribute_group mtcdp_platform_attribute_group = {
+ .attrs = mtcdp_platform_attributes
};
static struct attribute *mtr_platform_attributes[] = {
@@ -2676,7 +1997,7 @@ static struct attribute *mtr_platform_attributes[] = {
&dev_attr_extserial_ri_gpio.attr,
&dev_attr_extserial_dtr.attr,
&dev_attr_extserial_dsr_gpio.attr,
- &dev_attr_extserial_cd.attr,
+ &dev_attr_extserial_dcd_gpio.attr,
&dev_attr_eth0_enabled.attr,
&dev_attr_bt_enabled.attr,
&dev_attr_wlan_enabled.attr,
@@ -2686,7 +2007,7 @@ static struct attribute *mtr_platform_attributes[] = {
&dev_attr_led_sig2_gpio.attr,
&dev_attr_led_sig3_gpio.attr,
&dev_attr_led_cd_gpio.attr,
- &dev_attr_led_wifi.attr,
+ &dev_attr_led_wifi_gpio.attr,
NULL,
};
@@ -2865,6 +2186,106 @@ static struct spi_driver mts_spi_board_temp_driver = {
.remove = __devexit_p(mts_spi_board_temp_remove),
};
+static int mts_id_eeprom_load(void)
+{
+ memcpy(&id_eeprom, mts_id_eeprom, sizeof(mts_id_eeprom));
+
+ mts_product_id = MTCDP_E1_DK_1_0;
+ has_spi_sout = 1;
+ has_spi_din = 1;
+ has_spi_dout = 1;
+ has_spi_temp = 1;
+
+ if (mts_id_eeprom[0] == 0xFF) {
+ log_error("uninitialized eeprom");
+ return -EIO;
+ } else if (mts_id_eeprom[0] == 0x00) {
+ strncpy(id_eeprom.vendor_id, VENDOR_ID_MULTITECH, sizeof(id_eeprom.vendor_id) - 1);
+ strncpy(id_eeprom.product_id, PRODUCT_ID_MTCDP_E1_DK, sizeof(id_eeprom.product_id) - 1);
+ strncpy(id_eeprom.device_id, "", sizeof(id_eeprom.device_id) - 1);
+ strncpy(id_eeprom.hw_version, HW_VERSION_MTCDP_0_0, sizeof(id_eeprom.hw_version) - 1);
+
+ DEVICE_CAPA_SET(id_eeprom.capa, CAPA_GPS);
+
+ attr_group = &mtcdp_platform_attribute_group;
+ gpio_pins = gpio_pins_mtcdp_0_0;
+ mts_product_id = MTCDP_E1_DK_0_0;
+ log_info("detected board %s", HW_VERSION_MTCDP_0_0);
+ } else if (strncmp(id_eeprom.product_id, PRODUCT_ID_MT100EOCG, strlen(PRODUCT_ID_MT100EOCG)) == 0) {
+ attr_group = &mt100eocg_platform_attribute_group;
+ gpio_pins = gpio_pins_mt100eocg_0_0;
+ mts_product_id = MT100EOCG_0_0;
+ has_spi_sout = 0;
+ has_spi_din = 1;
+ has_spi_dout = 1;
+ has_spi_temp = 1;
+ log_info("detected board %s", HW_VERSION_MT100EOCG_0_0);
+ } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTR2_0_0, strlen(HW_VERSION_MTR2_0_0)) == 0) {
+ attr_group = &mtr2_platform_attribute_group;
+ gpio_pins = gpio_pins_mtr2_0_0;
+ mts_product_id = MTR2_0_0;
+ has_spi_sout = 0;
+ has_spi_din = 0;
+ has_spi_dout = 0;
+ has_spi_temp = 1;
+ log_info("detected board %s", HW_VERSION_MTR2_0_0);
+ } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTR_0_0, strlen(HW_VERSION_MTR_0_0)) == 0) {
+ attr_group = &mtr_platform_attribute_group;
+ gpio_pins = gpio_pins_mtr_0_0;
+ mts_product_id = MTR_0_0;
+ has_spi_sout = 0;
+ has_spi_din = 0;
+ has_spi_dout = 0;
+ has_spi_temp = 0;
+ log_info("detected board %s", HW_VERSION_MTR_0_0);
+ } else {
+ attr_group = &mtcdp_platform_attribute_group;
+ gpio_pins = gpio_pins_mtcdp_1_0;
+ mts_product_id = MTCDP_E1_DK_1_0;
+ has_spi_sout = 1;
+ has_spi_din = 1;
+ has_spi_dout = 1;
+ has_spi_temp = 1;
+ log_info("detected board %s", HW_VERSION_MTCDP_1_0);
+ }
+
+ log_info("sizeof: %lu", (unsigned long) sizeof(struct mts_id_eeprom_layout));
+ log_info("vendor-id: %.32s", id_eeprom.vendor_id);
+ log_info("product-id: %.32s", id_eeprom.product_id);
+ log_info("device-id: %.32s", id_eeprom.device_id);
+ log_info("hw-version: %.32s", id_eeprom.hw_version);
+ log_info("mac-addr: %02X:%02X:%02X:%02X:%02X:%02X",
+ id_eeprom.mac_addr[0],
+ id_eeprom.mac_addr[1],
+ id_eeprom.mac_addr[2],
+ id_eeprom.mac_addr[3],
+ id_eeprom.mac_addr[4],
+ id_eeprom.mac_addr[5]);
+ log_info("imei: %.32s", id_eeprom.imei);
+ log_info("capa-gps: %s", DEVICE_CAPA(id_eeprom.capa, CAPA_GPS) ? "yes" : "no");
+ log_info("capa-din: %s", DEVICE_CAPA(id_eeprom.capa, CAPA_DIN) ? "yes" : "no");
+ log_info("capa-dout: %s", DEVICE_CAPA(id_eeprom.capa, CAPA_DOUT) ? "yes" : "no");
+ log_info("capa-adc: %s", DEVICE_CAPA(id_eeprom.capa, CAPA_ADC) ? "yes" : "no");
+ log_info("capa-wifi: %s", DEVICE_CAPA(id_eeprom.capa, CAPA_WIFI) ? "yes" : "no");
+ log_info("capa-bluetooth: %s", DEVICE_CAPA(id_eeprom.capa, CAPA_BLUETOOTH) ? "yes" : "no");
+ log_info("mac-bluetooth: %02X:%02X:%02X:%02X:%02X:%02X",
+ id_eeprom.mac_bluetooth[0],
+ id_eeprom.mac_bluetooth[1],
+ id_eeprom.mac_bluetooth[2],
+ id_eeprom.mac_bluetooth[3],
+ id_eeprom.mac_bluetooth[4],
+ id_eeprom.mac_bluetooth[5]);
+ log_info("mac-wifi: %02X:%02X:%02X:%02X:%02X:%02X",
+ id_eeprom.mac_wifi[0],
+ id_eeprom.mac_wifi[1],
+ id_eeprom.mac_wifi[2],
+ id_eeprom.mac_wifi[3],
+ id_eeprom.mac_wifi[4],
+ id_eeprom.mac_wifi[5]);
+
+ return 0;
+}
+
static int __init mts_io_init(void)
{
struct gpio_pin *pin;
@@ -2888,33 +2309,9 @@ static int __init mts_io_init(void)
goto error2;
}
- if ( mts_product_id == MT100EOCG_0_0 ) {
- ret = sysfs_create_group(&mts_io_platform_device->dev.kobj,
- &mt100eocg_platform_attribute_group);
- if (ret) {
- goto error3;
- }
- }
- else if ( mts_product_id == MTR2_0_0 ) {
- ret = sysfs_create_group(&mts_io_platform_device->dev.kobj,
- &mtr2_platform_attribute_group);
- if (ret) {
- goto error3;
- }
- }
- else if ( mts_product_id == MTR_0_0 ) {
- ret = sysfs_create_group(&mts_io_platform_device->dev.kobj,
- &mtr_platform_attribute_group);
- if (ret) {
- goto error3;
- }
- }
- else {
- ret = sysfs_create_group(&mts_io_platform_device->dev.kobj,
- &platform_attribute_group);
- if (ret) {
- goto error3;
- }
+ ret = sysfs_create_group(&mts_io_platform_device->dev.kobj, attr_group);
+ if (ret) {
+ goto error3;
}
if ( has_spi_sout ) {
@@ -2982,10 +2379,10 @@ static int __init mts_io_init(void)
}
if ( has_spi_sout || has_spi_dout || has_spi_din ) {
- pin = gpio_pin_by_name("ENIO");
- if (pin) {
- at91_set_gpio_value(pin->pin, 0);
- }
+ pin = gpio_pin_by_name("ENIO");
+ if (pin) {
+ at91_set_gpio_value(pin->pin, 0);
+ }
}
// No blink_callback for MT100EOCG
@@ -3014,22 +2411,7 @@ error5:
spi_unregister_driver(&mts_spi_sout_driver);
}
error4:
- if ( mts_product_id == MT100EOCG_0_0 ) {
- sysfs_remove_group(&mts_io_platform_device->dev.kobj,
- &mt100eocg_platform_attribute_group);
- }
- else if ( mts_product_id == MTR2_0_0 ) {
- sysfs_remove_group(&mts_io_platform_device->dev.kobj,
- &mtr2_platform_attribute_group);
- }
- else if ( mts_product_id == MTR_0_0 ) {
- sysfs_remove_group(&mts_io_platform_device->dev.kobj,
- &mtr_platform_attribute_group);
- }
- else {
- sysfs_remove_group(&mts_io_platform_device->dev.kobj,
- &platform_attribute_group);
- }
+ sysfs_remove_group(&mts_io_platform_device->dev.kobj, attr_group);
error3:
platform_device_del(mts_io_platform_device);
error2:
@@ -3062,22 +2444,8 @@ static void __exit mts_io_exit(void)
if (has_spi_sout)
spi_unregister_driver(&mts_spi_sout_driver);
- if ( mts_product_id == MT100EOCG_0_0 ) {
- sysfs_remove_group(&mts_io_platform_device->dev.kobj,
- &mt100eocg_platform_attribute_group);
- }
- else if ( mts_product_id == MTR2_0_0 ) {
- sysfs_remove_group(&mts_io_platform_device->dev.kobj,
- &mtr2_platform_attribute_group);
- }
- else if ( mts_product_id == MTR_0_0 ) {
- sysfs_remove_group(&mts_io_platform_device->dev.kobj,
- &mtr_platform_attribute_group);
- }
- else {
- sysfs_remove_group(&mts_io_platform_device->dev.kobj,
- &platform_attribute_group);
- }
+ sysfs_remove_group(&mts_io_platform_device->dev.kobj, attr_group);
+
platform_device_unregister(mts_io_platform_device);
log_info("exiting");
diff --git a/io-module/mts_io.h b/io-module/mts_io.h
index eb40276..5f2235c 100644
--- a/io-module/mts_io.h
+++ b/io-module/mts_io.h
@@ -1,4 +1,3 @@
-
#ifndef __MTS_IO_H
#define __MTS_IO_H
@@ -10,6 +9,22 @@
#endif
#endif
+#define MTS_ATTR_MODE_RW S_IWUSR | S_IRUGO
+#define MTS_ATTR_MODE_RO S_IRUGO
+
+#define DEVICE_ATTR_MTS(_dev_name, _name, _show, _store) \
+struct device_attribute _dev_name = { \
+ .attr = { .name = _name, .mode = MTS_ATTR_MODE_RW }, \
+ .show = _show, \
+ .store = _store, \
+}
+
+#define DEVICE_ATTR_RO_MTS(_dev_name, _name, _show) \
+struct device_attribute _dev_name = { \
+ .attr = { .name = _name, .mode = MTS_ATTR_MODE_RO }, \
+ .show = _show, \
+}
+
#define VENDOR_ID_MULTITECH "Multi-Tech Systems"
#define PRODUCT_ID_MTCDP_E1_DK "MTCDP-E1-DK"
#define PRODUCT_ID_MT100EOCG "MT100EOCG"
@@ -55,7 +70,7 @@ do { \
#define CAPA_BLUETOOTH DEVICE_CAPA_VALUE(1, 7)
#define CAPA_WIFI DEVICE_CAPA_VALUE(1, 6)
-
+
struct mts_id_eeprom_layout {
char vendor_id[32];
char product_id[32];
@@ -69,5 +84,27 @@ struct mts_id_eeprom_layout {
uint8_t reserved[302];
};
+// GPIO pin types:input, output, open drain (1 = high Z, 0 = output low)
+enum {
+ GPIO_DIR_INPUT,
+ GPIO_DIR_OUTPUT,
+ GPIO_DIR_OD,
+};
+
+struct gpio_pin {
+ char name[32];
+ char attr_name[32];
+ unsigned pin;
+ int direction;
+ int output_value;
+ int use_pullup;
+};
+
+enum {
+ LED_OFF,
+ LED_ON,
+ LED_FLASHING,
+};
+
#endif /* ~__MTS_IO_H */