summaryrefslogtreecommitdiff
path: root/io-module/spi.c
diff options
context:
space:
mode:
authorMike Fiore <mfiore@multitech.com>2014-08-27 16:35:15 -0500
committerMike Fiore <mfiore@multitech.com>2014-08-27 16:35:15 -0500
commit1e563fc723ad8a44850b92f9c6e8c0bb41178215 (patch)
tree18acba9d4715284bd778687abbeef9dfe5984879 /io-module/spi.c
parent6709e0cb9fce54385937ccd4d42dece2159664a9 (diff)
downloadmts-io-1e563fc723ad8a44850b92f9c6e8c0bb41178215.tar.gz
mts-io-1e563fc723ad8a44850b92f9c6e8c0bb41178215.tar.bz2
mts-io-1e563fc723ad8a44850b92f9c6e8c0bb41178215.zip
accessory cards: support both ports
allow for 2 GPIOB accessory cards to be used at the same time some misc cleanup, more specific logging on init commented out mtr2 platform as it currently causes build issues with accessory card changes
Diffstat (limited to 'io-module/spi.c')
-rw-r--r--io-module/spi.c248
1 files changed, 192 insertions, 56 deletions
diff --git a/io-module/spi.c b/io-module/spi.c
index dfbdfe2..df663ae 100644
--- a/io-module/spi.c
+++ b/io-module/spi.c
@@ -40,29 +40,32 @@ MODULE_PARM_DESC(
"Maximum clock rate to be used with this device (default: 1 MHz)"
);
-static struct spi_device *spi_dc_dout_dev;
-static u8 spi_dc_dout_value;
-static DEFINE_MUTEX(spi_dc_dout_mutex);
-static unsigned int dc_dout_max_speed_hz = 1 * 1000 * 1000;
-module_param(dc_dout_max_speed_hz, uint, S_IRUGO);
+static struct spi_device *spi_ap1_dout_dev;
+static struct spi_device *spi_ap2_dout_dev;
+static u8 spi_ap_dout_value;
+static DEFINE_MUTEX(spi_ap_dout_mutex);
+static unsigned int ap_dout_max_speed_hz = 1 * 1000 * 1000;
+module_param(ap_dout_max_speed_hz, uint, S_IRUGO);
MODULE_PARM_DESC(
- dc_dout_max_speed_hz,
+ ap_dout_max_speed_hz,
"Maximum clock rate to be used with this device (default: 1 MHz)"
);
-static struct spi_device *spi_dc_din_dev;
-static unsigned int dc_din_max_speed_hz = 1 * 1000 * 1000;
-module_param(dc_din_max_speed_hz, uint, S_IRUGO);
+static struct spi_device *spi_ap1_din_dev;
+static struct spi_device *spi_ap2_din_dev;
+static unsigned int ap_din_max_speed_hz = 1 * 1000 * 1000;
+module_param(ap_din_max_speed_hz, uint, S_IRUGO);
MODULE_PARM_DESC(
- dc_din_max_speed_hz,
+ ap_din_max_speed_hz,
"Maximum clock rate to be used with this device (default: 1 MHz)"
);
-static struct spi_device *spi_dc_adc_dev;
-static unsigned int dc_adc_max_speed_hz = 20 * 1000 * 1000;
-module_param(dc_adc_max_speed_hz, uint, S_IRUGO);
+static struct spi_device *spi_ap1_adc_dev;
+static struct spi_device *spi_ap2_adc_dev;
+static unsigned int ap_adc_max_speed_hz = 20 * 1000 * 1000;
+module_param(ap_adc_max_speed_hz, uint, S_IRUGO);
MODULE_PARM_DESC(
- dc_adc_max_speed_hz,
+ ap_adc_max_speed_hz,
"Maximum clock rate to be used with this device (default: 20 MHz)"
);
@@ -595,137 +598,270 @@ static struct spi_driver mts_spi_din_driver = {
.remove = mts_spi_din_remove,
};
-static int mts_spi_dc_dout_probe(struct spi_device *spi)
+static int mts_spi_ap1_dout_probe(struct spi_device *spi)
{
int tmp;
- if (! has_accessory_card_port_1 || mts_ap1_product_id != MTDC_GPIOB_0_0) {
- log_error("accessory card digital outputs not available");
+ if (! have_accessory_card_slot_1 || mts_ap1_product_id != MTDC_GPIOB_0_0) {
+ log_error("accessory card 1 digital outputs not available");
return -ENODEV;
}
- spi->max_speed_hz = dc_dout_max_speed_hz;
+ spi->max_speed_hz = ap_dout_max_speed_hz;
spi->mode = 0;
- log_debug("dc_dout_max_speed_hz: %d", dc_dout_max_speed_hz);
+ log_debug("ap1_dout_max_speed_hz: %d", ap_dout_max_speed_hz);
tmp = spi_setup(spi);
if (tmp < 0) {
- log_error("spi_setup dc dout failed");
+ log_error("spi_setup accessory card 1 dout failed");
return tmp;
}
- spi_dc_dout_value = 0x00;
- spi_writen(spi, &spi_dc_dout_value, 1);
+ spi_ap_dout_value = 0x00;
+ spi_writen(spi, &spi_ap_dout_value, 1);
- spi_dc_dout_dev = spi;
+ spi_ap1_dout_dev = spi;
return 0;
}
-static int mts_spi_dc_dout_remove(struct spi_device *spi)
+static int mts_spi_ap1_dout_remove(struct spi_device *spi)
{
- spi_dc_dout_dev = NULL;
+ spi_ap1_dout_dev = NULL;
return 0;
}
-static struct spi_driver mts_spi_dc_dout_driver = {
+static struct spi_driver mts_spi_ap1_dout_driver = {
.driver = {
- .name = "mts-io-dc-dout",
+ .name = "mts-io-ap1-dout",
.bus = &spi_bus_type,
.owner = THIS_MODULE,
},
- .probe = mts_spi_dc_dout_probe,
- .remove = mts_spi_dc_dout_remove,
+ .probe = mts_spi_ap1_dout_probe,
+ .remove = mts_spi_ap1_dout_remove,
};
-static int mts_spi_dc_din_probe(struct spi_device *spi)
+static int mts_spi_ap1_din_probe(struct spi_device *spi)
{
int tmp;
- if (! has_accessory_card_port_1 || mts_ap1_product_id != MTDC_GPIOB_0_0) {
- log_error("accessory card digital inputs not available");
+ if (! have_accessory_card_slot_1 || mts_ap1_product_id != MTDC_GPIOB_0_0) {
+ log_error("accessory card 1 digital inputs not available");
return -ENODEV;
}
- spi->max_speed_hz = dc_din_max_speed_hz;
+ spi->max_speed_hz = ap_din_max_speed_hz;
spi->mode = SPI_CPOL;
- log_debug("dc_din_max_speed_hz: %d", dc_din_max_speed_hz);
+ log_debug("ap1_din_max_speed_hz: %d", ap_din_max_speed_hz);
tmp = spi_setup(spi);
if (tmp < 0) {
- log_error("spi_setup daughter card din failed");
+ log_error("spi_setup accessory card 1 din failed");
return tmp;
}
- spi_dc_din_dev = spi;
+ spi_ap1_din_dev = spi;
return 0;
}
-static int mts_spi_dc_din_remove(struct spi_device *spi)
+static int mts_spi_ap1_din_remove(struct spi_device *spi)
{
- spi_dc_din_dev = NULL;
+ spi_ap1_din_dev = NULL;
return 0;
}
-static struct spi_driver mts_spi_dc_din_driver = {
+static struct spi_driver mts_spi_ap1_din_driver = {
.driver = {
- .name = "mts-io-dc-din",
+ .name = "mts-io-ap1-din",
.bus = &spi_bus_type,
.owner = THIS_MODULE,
},
- .probe = mts_spi_dc_din_probe,
- .remove = mts_spi_dc_din_remove,
+ .probe = mts_spi_ap1_din_probe,
+ .remove = mts_spi_ap1_din_remove,
};
-static int mts_spi_dc_adc_probe(struct spi_device *spi)
+static int mts_spi_ap1_adc_probe(struct spi_device *spi)
{
int tmp;
- if (! has_accessory_card_port_1 || mts_ap1_product_id != MTDC_GPIOB_0_0) {
- log_error("accessory card analog to digital not available");
+ if (! have_accessory_card_slot_1 || mts_ap1_product_id != MTDC_GPIOB_0_0) {
+ log_error("accessory card 1 analog to digital not available");
return -ENODEV;
}
- spi->max_speed_hz = dc_adc_max_speed_hz;
+ spi->max_speed_hz = ap_adc_max_speed_hz;
spi->mode = 0;
- log_debug("dc_adc_max_speed_hz: %d", dc_adc_max_speed_hz);
- log_debug("dc_adc_mode: %d", spi->mode);
+ log_debug("ap1_adc_max_speed_hz: %d", ap_adc_max_speed_hz);
+ log_debug("ap1_adc_mode: %d", spi->mode);
tmp = spi_setup(spi);
if (tmp < 0) {
- log_error("spi_setup daughter card adc failed");
+ log_error("spi_setup accessory card 1 adc failed");
return tmp;
}
- spi_dc_adc_dev = spi;
+ spi_ap1_adc_dev = spi;
return 0;
}
-static int mts_spi_dc_adc_remove(struct spi_device *spi)
+static int mts_spi_ap1_adc_remove(struct spi_device *spi)
{
- spi_dc_adc_dev = NULL;
+ spi_ap1_adc_dev = NULL;
return 0;
}
-static struct spi_driver mts_spi_dc_adc_driver = {
+static struct spi_driver mts_spi_ap1_adc_driver = {
.driver = {
- .name = "mts-io-dc-adc",
+ .name = "mts-io-ap1-adc",
.bus = &spi_bus_type,
.owner = THIS_MODULE,
},
- .probe = mts_spi_dc_adc_probe,
- .remove = mts_spi_dc_adc_remove,
+ .probe = mts_spi_ap1_adc_probe,
+ .remove = mts_spi_ap1_adc_remove,
+};
+
+static int mts_spi_ap2_dout_probe(struct spi_device *spi)
+{
+ int tmp;
+
+ if (! have_accessory_card_slot_2 || mts_ap2_product_id != MTDC_GPIOB_0_0) {
+ log_error("accessory card 2 digital outputs not available");
+ return -ENODEV;
+ }
+
+ spi->max_speed_hz = ap_dout_max_speed_hz;
+ spi->mode = 0;
+
+ log_debug("ap2_dout_max_speed_hz: %d", ap_dout_max_speed_hz);
+
+ tmp = spi_setup(spi);
+ if (tmp < 0) {
+ log_error("spi_setup accessory card 2 dout failed");
+ return tmp;
+ }
+
+ spi_ap_dout_value = 0x00;
+ spi_writen(spi, &spi_ap_dout_value, 2);
+
+ spi_ap2_dout_dev = spi;
+
+ return 0;
+}
+
+static int mts_spi_ap2_dout_remove(struct spi_device *spi)
+{
+ spi_ap2_dout_dev = NULL;
+
+ return 0;
+}
+
+static struct spi_driver mts_spi_ap2_dout_driver = {
+ .driver = {
+ .name = "mts-io-ap2-dout",
+ .bus = &spi_bus_type,
+ .owner = THIS_MODULE,
+ },
+
+ .probe = mts_spi_ap2_dout_probe,
+ .remove = mts_spi_ap2_dout_remove,
+};
+
+static int mts_spi_ap2_din_probe(struct spi_device *spi)
+{
+ int tmp;
+
+ if (! have_accessory_card_slot_2 || mts_ap2_product_id != MTDC_GPIOB_0_0) {
+ log_error("accessory card 2 digital inputs not available");
+ return -ENODEV;
+ }
+
+ spi->max_speed_hz = ap_din_max_speed_hz;
+ spi->mode = SPI_CPOL;
+
+ log_debug("ap2_din_max_speed_hz: %d", ap_din_max_speed_hz);
+
+ tmp = spi_setup(spi);
+ if (tmp < 0) {
+ log_error("spi_setup accessory card 2 din failed");
+ return tmp;
+ }
+
+ spi_ap2_din_dev = spi;
+
+ return 0;
+}
+
+static int mts_spi_ap2_din_remove(struct spi_device *spi)
+{
+ spi_ap2_din_dev = NULL;
+
+ return 0;
+}
+
+static struct spi_driver mts_spi_ap2_din_driver = {
+ .driver = {
+ .name = "mts-io-ap2-din",
+ .bus = &spi_bus_type,
+ .owner = THIS_MODULE,
+ },
+
+ .probe = mts_spi_ap2_din_probe,
+ .remove = mts_spi_ap2_din_remove,
+};
+
+static int mts_spi_ap2_adc_probe(struct spi_device *spi)
+{
+ int tmp;
+
+ if (! have_accessory_card_slot_2 || mts_ap2_product_id != MTDC_GPIOB_0_0) {
+ log_error("accessory card 2 analog to digital not available");
+ return -ENODEV;
+ }
+
+ spi->max_speed_hz = ap_adc_max_speed_hz;
+ spi->mode = 0;
+
+ log_debug("ap2_adc_max_speed_hz: %d", ap_adc_max_speed_hz);
+ log_debug("ap2_adc_mode: %d", spi->mode);
+
+ tmp = spi_setup(spi);
+ if (tmp < 0) {
+ log_error("spi_setup accessory card 2 adc failed");
+ return tmp;
+ }
+
+ spi_ap2_adc_dev = spi;
+
+ return 0;
+}
+
+static int mts_spi_ap2_adc_remove(struct spi_device *spi)
+{
+ spi_ap2_adc_dev = NULL;
+
+ return 0;
+}
+
+static struct spi_driver mts_spi_ap2_adc_driver = {
+ .driver = {
+ .name = "mts-io-ap2-adc",
+ .bus = &spi_bus_type,
+ .owner = THIS_MODULE,
+ },
+
+ .probe = mts_spi_ap2_adc_probe,
+ .remove = mts_spi_ap2_adc_remove,
};
static int mts_spi_board_temp_probe(struct spi_device *spi)