#define NEURONSPI_MAX_BAUD 115200
#define NEURONSPI_FIFO_SIZE 256
#define NEURONSPI_FIFO_MIN_CONTINUOUS 50
-#define NEURONSPI_DETAILED_DEBUG 0
+#define NEURONSPI_DETAILED_DEBUG 2
#define NEURONSPI_LAST_TRANSFER_DELAY 40
#define MAX_RX_QUEUE_LEN 16
// Instantiated once per SPI device
struct neuronspi_driver_data
{
- struct spi_driver *spi_driver;
- struct neuronspi_char_driver *char_driver;
+ //struct spi_driver *spi_driver;
+ //struct neuronspi_char_driver *char_driver;
//struct uart_driver *serial_driver; -- this is global variable neuronspi_uart_driver_global
//struct neuronspi_uart_data *uart_data; -- this global var neuronspi_uar_data_global
struct neuronspi_led_driver *led_driver;
- struct neuronspi_di_driver **di_driver;
- struct neuronspi_do_driver **do_driver;
- struct neuronspi_ro_driver **ro_driver;
+ struct neuronspi_gpio_driver *di_driver;
+ struct neuronspi_gpio_driver *do_driver;
+ struct neuronspi_gpio_driver *ro_driver;
struct platform_device *board_device;
struct iio_dev *stm_ai_driver;
struct iio_dev *stm_ao_driver;
struct neuronspi_board_features *features;
struct neuronspi_board_regstart_table *regstart_table;
struct spinlock sysfs_regmap_lock;
- char platform_name[sizeof("io_group0")];
+ //char platform_name[sizeof("io_group0")];
u32 probe_always_succeeds;
u32 always_create_uart;
u8 reserved_device;
int uart_count;
int uart_pindex;
- //u8 uart_read;
- //u8 *uart_buf;
- //u8 slower_model;
+
u8 no_irq;
u8 lower_board_id;
u8 upper_board_id;
u8 uart_count_to_probe;
};
-struct neuronspi_di_driver {
+/*
+struct neuronspi_gpio_port {
+ struct spi_device* spi;
+ struct gpio_chip gpio_c;
+ struct platform_device *plat_dev;
+ u8 io_index;
+};
+
+struct neuronspi_gpio_driver {
+ int count;
+ struct neuronspi_gpio_port* ports;
+}
+ */
+struct neuronspi_gpio_driver {
struct spi_device* spi;
struct gpio_chip gpio_c;
struct platform_device *plat_dev;
- u8 di_index;
- char name[sizeof("di_0_00")];
+ u8 io_index;
};
-struct neuronspi_do_driver
+/*struct neuronspi_do_driver
{
struct spi_device* spi;
struct gpio_chip gpio_c;
u8 ro_index;
char name[sizeof("ro_0_00")];
};
+*/
struct neuronspi_sec_ai_driver
{
}
int neuronspi_gpio_di_get(struct gpio_chip *chip, unsigned offset) {
- struct neuronspi_di_driver *n_di = gpiochip_get_data(chip);
+ struct neuronspi_gpio_driver *n_di = gpiochip_get_data(chip);
struct spi_device *spi = n_di->spi;
- return neuronspi_spi_gpio_di_get(spi, n_di->di_index);
+ return neuronspi_spi_gpio_di_get(spi, n_di->io_index);
}
int neuronspi_gpio_do_direction_output(struct gpio_chip *chip, unsigned offset, int value) {
}
void neuronspi_gpio_do_set(struct gpio_chip *chip, unsigned offset, int value) {
- struct neuronspi_do_driver *n_do = gpiochip_get_data(chip);
+ struct neuronspi_gpio_driver *n_do = gpiochip_get_data(chip);
struct spi_device *spi = n_do->spi;
- neuronspi_spi_gpio_do_set(spi, n_do->do_index, value);
+ neuronspi_spi_gpio_do_set(spi, n_do->io_index, value);
}
int neuronspi_gpio_ro_direction_output(struct gpio_chip *chip, unsigned offset, int value) {
}
void neuronspi_gpio_ro_set(struct gpio_chip *chip, unsigned offset, int value) {
- struct neuronspi_ro_driver *n_ro = gpiochip_get_data(chip);
+ struct neuronspi_gpio_driver *n_ro = gpiochip_get_data(chip);
struct spi_device *spi = n_ro->spi;
- neuronspi_spi_gpio_ro_set(spi, n_ro->ro_index, value);
+ neuronspi_spi_gpio_ro_set(spi, n_ro->io_index, value);
+}
+
+
+struct neuronspi_gpio_driver * neuronspi_di_probe(int di_count, int neuron_index, struct platform_device *board_device)
+{
+ struct neuronspi_gpio_driver* di_driver_arr;
+ struct neuronspi_gpio_driver* pdi_driver;
+ int i;
+ char buf[20];
+
+ if (di_count <= 0) return NULL;
+
+ di_driver_arr = kzalloc(sizeof(struct neuronspi_gpio_driver) * di_count, GFP_ATOMIC);
+ for (i = 0; i < di_count; i++) {
+ pdi_driver = di_driver_arr + i;
+ scnprintf(buf, 20, "di_%d_%02d", neuron_index+1, i+1);
+ /*strcpy(pdi_driver->name, "di_0_00");
+ pdi_driver->name[3] = neuron_index + '1';
+ pdi_driver->name[5] = ((i + 1) / 10) + '0';
+ pdi_driver->name[6] = ((i + 1) % 10) + '0';*/
+ pdi_driver->io_index = i;
+ pdi_driver->spi = neuronspi_s_dev[neuron_index];
+
+ pdi_driver->plat_dev = platform_device_alloc(buf, -1);
+ pdi_driver->plat_dev->dev.parent = &(board_device->dev);
+ pdi_driver->plat_dev->dev.groups = neuron_gpio_di_attr_groups;
+ pdi_driver->plat_dev->dev.driver = &neuronspi_spi_driver.driver;
+ platform_device_add(pdi_driver->plat_dev);
+
+ platform_set_drvdata(pdi_driver->plat_dev, pdi_driver);
+ pdi_driver->gpio_c.owner = THIS_MODULE;
+ pdi_driver->gpio_c.parent = &(pdi_driver->plat_dev->dev);
+ pdi_driver->gpio_c.label = "neuron_di";
+ pdi_driver->gpio_c.can_sleep = 1;
+ pdi_driver->gpio_c.ngpio = 1;
+ pdi_driver->gpio_c.base = -1;
+ pdi_driver->gpio_c.direction_input = neuronspi_gpio_di_direction_input;
+ pdi_driver->gpio_c.get = neuronspi_gpio_di_get;
+ gpiochip_add_data(&pdi_driver->gpio_c, pdi_driver);
+ }
+ return di_driver_arr;
+}
+
+struct neuronspi_gpio_driver * neuronspi_ro_probe(int ro_count, int neuron_index, struct platform_device *board_device)
+{
+ struct neuronspi_gpio_driver* ro_driver_arr;
+ struct neuronspi_gpio_driver* pro_driver;
+ int i;
+ char buf[20];
+
+ if (ro_count <= 0) return NULL;
+
+ ro_driver_arr = kzalloc(sizeof(struct neuronspi_gpio_driver) * ro_count, GFP_ATOMIC);
+ for (i = 0; i < ro_count; i++) {
+ pro_driver = ro_driver_arr + i;
+
+ scnprintf(buf, 20, "ro_%d_%02d", neuron_index+1, i+1);
+ /*strcpy(pro_driver->name, "ro_0_00");
+ pro_driver->name[3] = neuron_index + '1';
+ pro_driver->name[5] = ((i + 1) / 10) + '0';
+ pro_driver->name[6] = ((i + 1) % 10) + '0';*/
+ pro_driver->io_index = i;
+ pro_driver->spi = neuronspi_s_dev[neuron_index];
+
+ pro_driver->plat_dev = platform_device_alloc(buf, -1);
+ pro_driver->plat_dev->dev.parent = &(board_device->dev);
+ pro_driver->plat_dev->dev.groups = neuron_gpio_ro_attr_groups;
+ pro_driver->plat_dev->dev.driver = &neuronspi_spi_driver.driver;
+ platform_device_add(pro_driver->plat_dev);
+
+ platform_set_drvdata(pro_driver->plat_dev, pro_driver);
+ pro_driver->gpio_c.owner = THIS_MODULE;
+ pro_driver->gpio_c.parent = &(pro_driver->plat_dev->dev);
+ pro_driver->gpio_c.label = "neuron_ro";
+ pro_driver->gpio_c.can_sleep = 1;
+ pro_driver->gpio_c.ngpio = 1;
+ pro_driver->gpio_c.base = -1;
+ pro_driver->gpio_c.direction_output = neuronspi_gpio_ro_direction_output;
+ pro_driver->gpio_c.set = neuronspi_gpio_ro_set;
+ gpiochip_add_data(&pro_driver->gpio_c, pro_driver);
+
+ }
+ return ro_driver_arr;
+}
+
+struct neuronspi_gpio_driver * neuronspi_do_probe(int do_count, int neuron_index, struct platform_device *board_device)
+{
+ struct neuronspi_gpio_driver* do_driver_arr;
+ struct neuronspi_gpio_driver* pdo_driver;
+ int i;
+ char buf[20];
+
+ if (do_count <= 0) return NULL;
+
+ do_driver_arr = kzalloc(sizeof(struct neuronspi_gpio_driver) * do_count, GFP_ATOMIC);
+ for (i = 0; i < do_count; i++) {
+ pdo_driver = do_driver_arr + i;
+
+ scnprintf(buf, 20, "do_%d_%02d", neuron_index+1, i+1);
+ /*strcpy(pdo_driver->name, "do_0_00");
+ pdo_driver->name[3] = neuron_index + '1';
+ pdo_driver->name[5] = ((i + 1) / 10) + '0';
+ pdo_driver->name[6] = ((i + 1) % 10) + '0';*/
+ pdo_driver->io_index = i;
+ pdo_driver->spi = neuronspi_s_dev[neuron_index];
+
+ pdo_driver->plat_dev = platform_device_alloc(buf, -1);
+ pdo_driver->plat_dev->dev.parent = &(board_device->dev);
+ pdo_driver->plat_dev->dev.groups = neuron_gpio_do_attr_groups;
+ pdo_driver->plat_dev->dev.driver = &neuronspi_spi_driver.driver;
+ platform_device_add(pdo_driver->plat_dev);
+
+ platform_set_drvdata(pdo_driver->plat_dev, pdo_driver);
+ pdo_driver->gpio_c.owner = THIS_MODULE;
+ pdo_driver->gpio_c.parent = &(pdo_driver->plat_dev->dev);
+ pdo_driver->gpio_c.label = "neuron_do";
+ pdo_driver->gpio_c.can_sleep = 1;
+ pdo_driver->gpio_c.ngpio = 1;
+ pdo_driver->gpio_c.base = -1;
+ pdo_driver->gpio_c.direction_output = neuronspi_gpio_do_direction_output;
+ pdo_driver->gpio_c.set = neuronspi_gpio_do_set;
+ gpiochip_add_data(&pdo_driver->gpio_c, pdo_driver);
+
+ }
+ return do_driver_arr;
}
int neuronspi_gpio_ro_direction_output(struct gpio_chip *chip, unsigned offset, int value);
void neuronspi_gpio_ro_set(struct gpio_chip *chip, unsigned offset, int value);
+struct neuronspi_gpio_driver * neuronspi_di_probe(int di_count, int neuron_index, struct platform_device *board_device);
+struct neuronspi_gpio_driver * neuronspi_ro_probe(int ro_count, int neuron_index, struct platform_device *board_device);
+struct neuronspi_gpio_driver * neuronspi_do_probe(int do_count, int neuron_index, struct platform_device *board_device);
+
#endif /* MODULES_NEURON_SPI_SRC_UNIPI_GPIO_H_ */
kthread_queue_work(&n_spi->primary_worker, &led->led_work);
spin_unlock_irqrestore(&led->lock, flags);
}
+
+
+struct neuronspi_led_driver * neuronspi_led_probe(int led_count, int neuron_index, struct platform_device *board_device)
+{
+ struct neuronspi_led_driver * led_driver = kzalloc(sizeof(struct neuronspi_led_driver) * led_count, GFP_ATOMIC);
+ int i;
+
+ for (i = 0; i < led_count; i++) {
+ scnprintf(led_driver[i].name, sizeof(led_driver[i].name), "unipi:green:uled-x%x", i);
+ /*strcpy(led_driver[i].name, "unipi:green:uled-x1");
+ if (i < 9) {
+ led_driver[i].name[18] = i + '1';
+ } else {
+ led_driver[i].name[18] = i - 9 + 'a';
+ }*/
+ // Initialise the rest of the structure
+ led_driver[i].id = i;
+ led_driver[i].brightness = LED_OFF;
+ led_driver[i].spi = neuronspi_s_dev[neuron_index];
+
+ spin_lock_init(&led_driver[i].lock);
+ led_driver[i].ldev.name = led_driver[i].name;
+ led_driver[i].ldev.brightness = led_driver[i].brightness;
+ led_driver[i].ldev.brightness_set = neuronspi_led_set_brightness;
+ led_classdev_register(&(board_device->dev), &(led_driver[i].ldev));
+ kthread_init_work(&(led_driver[i].led_work), neuronspi_led_proc);
+ }
+ return led_driver;
+}
\ No newline at end of file
void neuronspi_led_proc(struct kthread_work *ws);
void neuronspi_led_set_brightness(struct led_classdev *ldev, enum led_brightness brightness);
+struct neuronspi_led_driver * neuronspi_led_probe(int led_count, int neuron_index, struct platform_device *board_device);
#endif /* MODULES_NEURON_SPI_SRC_UNIPI_MISC_H_ */
}
+struct platform_device * neuronspi_board_device_probe(struct neuronspi_driver_data *n_spi)
+{
+ char buf[20];
+ struct platform_device * board_device;
+ scnprintf(buf, 20, "io_group%d", n_spi->neuron_index+1);
+
+ //strcpy(n_spi->platform_name, "io_group0");
+ //n_spi->platform_name[8] = n_spi->neuron_index + '1';
+
+ board_device = platform_device_alloc(buf, -1);
+ board_device->dev.parent = &(neuron_plc_dev->dev);
+
+ if (n_spi->combination_id != 0xFF) {
+ board_device->dev.groups = neuron_board_attr_groups;
+ }
+
+ board_device->dev.driver = &neuronspi_spi_driver.driver;
+ platform_device_add(board_device);
+ platform_set_drvdata(board_device, n_spi);
+
+ return board_device;
+}
+
s32 neuronspi_find_reg_start(struct neuronspi_board_combination *board, u16 regfun);
s32 neuronspi_find_model_id(u32 probe_count);
+struct platform_device * neuronspi_board_device_probe(struct neuronspi_driver_data *n_spi);
+
#endif /* MODULES_NEURON_SPI_SRC_UNIPI_PLATFORM_H_ */
if (opcode != 0x43) {
// read one incomming character from UART
neuronspi_rx_queue_add(port, recv_buf->first_message[3]);
- //neuronspi_uart_handle_rx(port, 1, 1);
}
// read queue length
port->rx_remain = recv_buf->first_message[2];
driver_data = spi_get_drvdata(spi_driver_data);
if (driver_data == NULL) return -2;
- if (driver_data->spi_driver == NULL) return -2; // Invalid private data
+ //if (driver_data->spi_driver == NULL) return -2; // Invalid private data
if ((driver_data->first_probe_reply[0] == 0) && !(driver_data->probe_always_succeeds) ) return -3; // Device not present
mutex_lock(&(private_data->lock));
mutex_unlock(&(private_data->lock));
return -10;
}
- unipi_spi_trace(KERN_INFO "UNIPISPI: CDEV Read %d, DEV:%s%d DRV:%s%d msglen=%d offset=%d\n", len, (spi_driver_data->dev.of_node->name),
- (spi_driver_data->chip_select), (driver_data->spi_driver->driver.name), (private_data->device_index),private_data->message_len, (int)*offset);
+ unipi_spi_trace(KERN_INFO "UNIPISPI: CDEV Read %d, DEV:%s%d DRV:%d msglen=%d offset=%d\n", len, (spi_driver_data->dev.of_node->name),
+ (spi_driver_data->chip_select), (private_data->device_index),private_data->message_len, (int)*offset);
if (private_data->has_first_message & UNIPISPI_OP_MODE_SEND_HEADER) {
result = simple_read_from_buffer(buffer, len, &dummy_offset, private_data->recv_buf.first_message, NEURONSPI_FIRST_MESSAGE_LENGTH);
driver_data = spi_get_drvdata(spi_driver_data);
if (driver_data == NULL) return -2;
- if (driver_data->spi_driver == NULL) return -2; // Invalid private data
+ //if (driver_data->spi_driver == NULL) return -2; // Invalid private data
if ((driver_data->first_probe_reply[0] == 0) && !(driver_data->probe_always_succeeds) )
return -3; // Device not present
void neuronspi_spi_set_irqs(struct spi_device* spi_dev, u16 to)
{
unipispi_modbus_write_register(spi_dev, 1007, to);
- unipi_spi_trace(KERN_INFO "UNIPISPI: SPI IRQ Set, Dev-CS:%d, to:%d\n", spi_dev->chip_select, to);
+ unipi_spi_trace(KERN_INFO "UNIPISPI: SPI IRQ Set, CS%d, to:0x%x\n", spi_dev->chip_select, to);
}
-
-/*
-int neuronspi_spi_send_message(struct spi_device* spi_dev, u8 *send_buf, u8 *recv_buf, s32 len, s32 freq, s32 delay, s32 send_header, u8 lock_val)
-{
- s32 i = 0;
- int ret_code = 0;
- u16 recv_crc1 = 0;
- u16 recv_crc2 = 0;
- u16 packet_crc = 0;
- s32 trans_count = (len<=0) ? 2 : ((len-1) / NEURONSPI_MAX_TX) + 3; // number of transmissions
- //struct spi_message *s_msg;
- struct neuronspi_driver_data *d_data;
- struct spi_transfer* s_trans;
- mutex_lock(&neuronspi_master_mutex);
- //if ((len % NEURONSPI_MAX_TX) == 0) trans_count--;
- d_data = spi_get_drvdata(spi_dev);
- if (d_data != NULL && d_data->reserved_device && lock_val != d_data->reserved_device) {
- memset(&recv_buf, 0, len);
- } else {
- s_trans = kzalloc(sizeof(struct spi_transfer) * trans_count, GFP_ATOMIC);
- unipi_spi_trace_1(KERN_INFO "UNIPISPI: SPI Master Write, len:%d,\n %100ph\n", len, send_buf);
-
- if (!send_header) {
- trans_count -= 1; // one less transmission as the header is omitted
- }
- //s_msg = kmalloc(sizeof(struct spi_message), GFP_ATOMIC);
- //spi_message_init(s_msg);
- for (i = 0; i < trans_count; i++) {
- memset(&(s_trans[i]), 0, sizeof(s_trans[i]));
- s_trans[i].delay_usecs = 0;
- s_trans[i].bits_per_word = 8;
- s_trans[i].speed_hz = freq;
- if (i == 0) {
- s_trans[i].delay_usecs = NEURONSPI_EDGE_DELAY;
- } else if (i == 1) {
- s_trans[i].tx_buf = send_buf;
- s_trans[i].rx_buf = recv_buf;
- if (send_header) {
- s_trans[i].delay_usecs = delay;
- s_trans[i].len = NEURONSPI_FIRST_MESSAGE_LENGTH;
- } else {
- // If len is more than NEURONSPI_MAX_TX * i, then chunk len is NEURONSPI_MAX_TX, otherwise it's the remainder
- s_trans[i].len = (len - (NEURONSPI_MAX_TX * i)) > 0 ? NEURONSPI_MAX_TX : len;
- }
- } else if (i == trans_count - 1) {
- if (send_header) {
- s_trans[i].tx_buf = &(send_buf[NEURONSPI_FIRST_MESSAGE_LENGTH + (NEURONSPI_MAX_TX * (i - 2))]);
- s_trans[i].rx_buf = &(recv_buf[NEURONSPI_FIRST_MESSAGE_LENGTH + (NEURONSPI_MAX_TX * (i - 2))]);
- s_trans[i].len = (len - (NEURONSPI_MAX_TX * (i - 2)));
- //s_trans[i].len = ((NEURONSPI_MAX_TX * (i - 1)) - len) < 0 ? NEURONSPI_MAX_TX : (len - (NEURONSPI_MAX_TX * (i - 2)));
- } else {
- s_trans[i].tx_buf = &(send_buf[NEURONSPI_MAX_TX * (i - 1)]);
- s_trans[i].rx_buf = &(recv_buf[NEURONSPI_MAX_TX * (i - 1)]);
- s_trans[i].len = ((NEURONSPI_MAX_TX * i) - len) < 0 ? NEURONSPI_MAX_TX : (len - (NEURONSPI_MAX_TX * (i - 1)));
- }
- s_trans[i].delay_usecs = NEURONSPI_LAST_TRANSFER_DELAY;
- // If len is more than NEURONSPI_MAX_TX * i (+ optionally header), then chunk len is NEURONSPI_MAX_TX (+ optionally header),
- // otherwise it's the remainder
- } else {
- if (send_header) {
- s_trans[i].tx_buf = &(send_buf[NEURONSPI_FIRST_MESSAGE_LENGTH + (NEURONSPI_MAX_TX * (i - 2))]);
- s_trans[i].rx_buf = &(recv_buf[NEURONSPI_FIRST_MESSAGE_LENGTH + (NEURONSPI_MAX_TX * (i - 2))]);
- s_trans[i].len = NEURONSPI_MAX_TX;
- //s_trans[i].len = ((NEURONSPI_MAX_TX * (i - 1)) - len) < 0 ? NEURONSPI_MAX_TX : (len - (NEURONSPI_MAX_TX * (i - 2)));
- } else {
- s_trans[i].tx_buf = &(send_buf[NEURONSPI_MAX_TX * (i - 1)]);
- s_trans[i].rx_buf = &(recv_buf[NEURONSPI_MAX_TX * (i - 1)]);
- s_trans[i].len = ((NEURONSPI_MAX_TX * i) - len) < 0 ? NEURONSPI_MAX_TX : (len - (NEURONSPI_MAX_TX * (i - 1)));
- }
- // If len is more than NEURONSPI_MAX_TX * i (+ optionally header), then chunk len is NEURONSPI_MAX_TX (+ optionally header),
- // otherwise it's the remainder
- }
- //spi_message_add_tail(&(s_trans[i]), s_msg);
- }
- //spi_sync(spi_dev, s_msg);
- spi_sync_transfer(spi_dev, s_trans, trans_count);
- //for (i = 0; i < trans_count; i++) {
- // spi_transfer_del(&(s_trans[i]));
- //}
- kfree(s_trans);
- //kfree(s_msg);
- unipi_spi_trace_1(KERN_INFO "UNIPISPI: SPI Master Read - %d:\n\t%100ph\n\t%100ph\n\t%100ph\n\t%100ph\n", len,recv_buf, &recv_buf[64],
- &recv_buf[128], &recv_buf[192]);
-
- }
- if (d_data == NULL || (d_data != NULL && !d_data->reserved_device)) {
- recv_crc1 = neuronspi_spi_crc(recv_buf, 4, 0);
- memcpy(&packet_crc, &recv_buf[4], 2);
- unipi_spi_trace_1(KERN_INFO "UNIPISPI: SPI CRC1: %x\t COMPUTED CRC1:%x\n", packet_crc, recv_crc1);
-
- if (recv_crc1 == packet_crc) {
- // Signal the UART to issue character reads
- unipi_spi_trace_1(KERN_INFO "UNIPISPI: SPI CRC1 Correct");
-
- if (d_data && ((recv_buf[0] & 0xfd) == 0x41)) {
- unipi_spi_trace(KERN_INFO "UNIPISPI: Reading UART data for device %d\n", d_data->neuron_index);
-
- if (recv_buf[0] == 0x41) {
- d_data->uart_buf[0] = recv_buf[3];
- for (i = 0; i < d_data->uart_data->p_count; i++) {
- if (d_data->uart_data->p[i].dev_index == d_data->neuron_index) {
- neuronspi_uart_handle_rx(&d_data->uart_data->p[i], 1, 1);
- }
- }
- }
- if (!(d_data->uart_read) && (d_data->uart_count)) {
- d_data->uart_read = recv_buf[2];
- for (i = 0; i < d_data->uart_data->p_count; i++) {
- unipi_spi_trace(KERN_INFO "UNIPISPI: UART Buffer:%d, UART Local Port Count:%d, UART Global Port Count:%d\n", d_data->uart_read,
- d_data->uart_count, d_data->uart_data->p_count);
-
- if (d_data->uart_data->p[i].dev_index == d_data->neuron_index && !d_data->reserved_device) {
- kthread_queue_work(&d_data->uart_data->kworker, &d_data->uart_data->p[i].rx_work);
- }
- }
- }
- }
- } else {
- unipi_spi_trace(KERN_INFO "UNIPISPI: SPI CRC1 Not Correct");
- }
- recv_crc2 = neuronspi_spi_crc(&recv_buf[6], len - 8, recv_crc1);
- memcpy(&packet_crc, &recv_buf[len - 2], 2);
- unipi_spi_trace_1(KERN_INFO "UNIPISPI: SPI CRC2: %x\t COMPUTED CRC2:%x\n", packet_crc, recv_crc2);
- if (recv_crc2 != packet_crc) {
- unipi_spi_trace(KERN_INFO "UNIPISPI: SPI CRC2 Not Correct");
-
- recv_buf[0] = 0;
- ret_code = 1;
- }
- }
- mutex_unlock(&neuronspi_master_mutex);
- return ret_code;
-}
-*/
-
-
irqreturn_t neuronspi_spi_irq(s32 irq, void *dev_id)
{
- s32 i;
- struct spi_device *spi;
- struct neuronspi_driver_data *d_data;
- //struct neuronspi_uart_data *u_data;
- spi = (struct spi_device *)dev_id;
- d_data = spi_get_drvdata(spi);
+ struct spi_device *spi = (struct spi_device *)dev_id;
+ struct neuronspi_driver_data *d_data = spi_get_drvdata(spi);
+ struct neuronspi_port *port;
+
unipi_spi_trace(KERN_INFO "UNIPISPI: SPI IRQ\n");
if (d_data->uart_count) {
- for (i = 0; i < neuronspi_uart_data_global->p_count; i++) {
- if (neuronspi_uart_data_global->p[i].dev_index == d_data->neuron_index) {
- kthread_queue_work(&neuronspi_uart_data_global->kworker, &neuronspi_uart_data_global->p[i].irq_work);
- }
-
+ // it is enough to call one port of spi board
+ port = neuronspi_uart_data_global->p + d_data->uart_pindex;
+ kthread_queue_work(&neuronspi_uart_data_global->kworker, &port->irq_work);
}
- }
return IRQ_HANDLED;
}
n_spi->neuron_index = spi->chip_select - 1;
n_spi->reserved_device = 0;
- if (neuron_plc_dev == NULL) {
- neuron_plc_dev = platform_device_alloc("unipi_plc", -1);
- neuron_plc_dev->dev.groups = neuron_plc_attr_groups;
- platform_device_add(neuron_plc_dev);
- }
-
- unipi_spi_trace(KERN_DEBUG "UNIPISPI: CS: %d, Chip Max Hz-%d %d\n", spi->chip_select, spi->master->max_speed_hz, spi->max_speed_hz);
+ unipi_spi_trace(KERN_DEBUG "UNIPISPI: CS%d, Chip Max Hz-%d %d\n", spi->chip_select, spi->master->max_speed_hz, spi->max_speed_hz);
if (spi->dev.of_node) {
const struct of_device_id *of_id =
of_match_device(neuronspi_id_match, &spi->dev);
devtype = (struct neuronspi_devtype *)id_entry->driver_data;
}
-
+ // Prepare worker for interrupt, LEDs,
kthread_init_worker(&n_spi->primary_worker);
n_spi->primary_worker_task = kthread_run(kthread_worker_fn, &n_spi->primary_worker, "neuronspi");
if (IS_ERR(n_spi->primary_worker_task )) {
ret = PTR_ERR(n_spi->primary_worker_task);
+ kfree(n_spi);
return ret;
}
sched_setscheduler(n_spi->primary_worker_task, SCHED_FIFO, &neuronspi_sched_param);
// We perform an initial probe of registers 1000-1004 to identify the device, using a premade message
n_spi->first_probe_reply = kzalloc(UNIPISPI_PROBE_MESSAGE_LEN, GFP_ATOMIC); // allocate space for initial probe
n_spi->lower_board_id = n_spi->upper_board_id = n_spi->combination_id = 0xFF;
- n_spi->spi_driver = &neuronspi_spi_driver;
neuronspi_spi_send_const_op(spi, &UNIPISPI_IDLE_MESSAGE, &recv_op, 0, NEURONSPI_DEFAULT_FREQ, 25);
// Throw away the first message - the associated SPI Master is sometimes not properly initialised at this point
}
}
}
+
} else if (!n_spi->probe_always_succeeds) {
ret = -ENODEV;
kfree(n_spi);
- printk(KERN_INFO "UNIPISPI: Probe did not detect a valid UniPi device on CS %d\n", spi->chip_select);
+ printk(KERN_INFO "UNIPISPI: Probe did not detect a valid UniPi device at CS%d\n", spi->chip_select);
return ret;
+
} else if (n_spi->always_create_uart) {
uart_count = 1;
}
if (n_spi->lower_board_id != 0xFF && n_spi->combination_id != 0xFF) {
- n_spi->features = kzalloc(sizeof(struct neuronspi_board_features), GFP_ATOMIC);
+ //n_spi->features = kzalloc(sizeof(struct neuronspi_board_features), GFP_ATOMIC);
n_spi->features = &(NEURONSPI_BOARDTABLE[n_spi->combination_id].definition->features);
} else {
n_spi->features = NULL;
n_spi->ideal_frequency = NEURONSPI_COMMON_FREQ;
for (i = 0; i < NEURONSPI_SLOWER_MODELS_LEN; i++) {
if (NEURONSPI_SLOWER_MODELS[i] == (n_spi->first_probe_reply[19-6] << 8 | n_spi->first_probe_reply[18-6])) {
- //n_spi->slower_model = 1;
n_spi->ideal_frequency = NEURONSPI_SLOWER_FREQ;
}
}
if (n_spi->lower_board_id != 0xFF && n_spi->combination_id != 0xFF) {
- printk(KERN_INFO "UNIPISPI: Probe detected UniPi Board %s (L:%x U:%x C:%x) Index: %d Fw: v%d.%d on CS %d, \
-Uart count: %d - reg1000: %x, reg1001: %x, reg1002: %x, reg1003: %x, reg1004: %x\n",
+ printk(KERN_INFO "UNIPISPI: Probe detected UniPi Board %s (L:%x U:%x C:%x) Fw: v%d.%d at CS%d (id=%d)\n\t\tUarts:%d, reg1000-4: %10ph\n",
NEURONSPI_BOARDTABLE[n_spi->combination_id].definition->combination_name,
- n_spi->lower_board_id, n_spi->upper_board_id, n_spi->combination_id, n_spi->neuron_index,
- n_spi->first_probe_reply[11-6], n_spi->first_probe_reply[10-6], spi->chip_select, uart_count,
- n_spi->first_probe_reply[11-6] << 8 | n_spi->first_probe_reply[10-6],
- n_spi->first_probe_reply[13-6] << 8 | n_spi->first_probe_reply[12-6], n_spi->first_probe_reply[15-6] << 8 | n_spi->first_probe_reply[14-6],
- n_spi->first_probe_reply[17-6] << 8 | n_spi->first_probe_reply[16-6], n_spi->first_probe_reply[19-6] << 8 | n_spi->first_probe_reply[18-6]);
+ n_spi->lower_board_id, n_spi->upper_board_id, n_spi->combination_id,
+ n_spi->first_probe_reply[5], n_spi->first_probe_reply[4],
+ spi->chip_select, n_spi->neuron_index, uart_count, n_spi->first_probe_reply +4) ;
} else if (n_spi->lower_board_id != 0xFF) {
- printk(KERN_INFO "UNIPISPI: Probe detected UniPi Board L:%x C:??? Index: %d Fw: v%d.%d on CS %d, Uart count: %d - reg1000: %x, \
+ printk(KERN_INFO "UNIPISPI: Probe detected UniPi Board L:%x C:??? Index: %d Fw: v%d.%d at CS%d, Uart count: %d - reg1000: %x, \
reg1001: %x, reg1002: %x, reg1003: %x, reg1004: %x\n",
n_spi->lower_board_id, n_spi->neuron_index, n_spi->first_probe_reply[11-6], n_spi->first_probe_reply[10-6],
spi->chip_select, uart_count, n_spi->first_probe_reply[11-6] << 8 | n_spi->first_probe_reply[10-6],
n_spi->first_probe_reply[13-6] << 8 | n_spi->first_probe_reply[12-6], n_spi->first_probe_reply[15-6] << 8 | n_spi->first_probe_reply[14-6],
n_spi->first_probe_reply[17-6] << 8 | n_spi->first_probe_reply[16-6], n_spi->first_probe_reply[19-6] << 8 | n_spi->first_probe_reply[18-6]);
} else {
- printk(KERN_INFO "UNIPISPI: Probe detected UniPi Board L:??? C:??? Index: %d Fw: v%d.%d on CS %d, Uart count: %d - reg1000: %x, \
+ printk(KERN_INFO "UNIPISPI: Probe detected UniPi Board L:??? C:??? Index: %d Fw: v%d.%d on CS%d, Uart count: %d - reg1000: %x, \
reg1001: %x, reg1002: %x, reg1003: %x, reg1004: %x\n",
n_spi->neuron_index, n_spi->first_probe_reply[11-6], n_spi->first_probe_reply[10-6], spi->chip_select, uart_count,
n_spi->first_probe_reply[11-6] << 8 | n_spi->first_probe_reply[10-6], n_spi->first_probe_reply[13-6] << 8 | n_spi->first_probe_reply[12-6],
n_spi->first_probe_reply[19-6] << 8 | n_spi->first_probe_reply[18-6]);
}
if (n_spi->combination_id != 0xFF) {
- printk(KERN_INFO "UNIPISPI: UniPi device %s on CS %d uses SPI communication freq. %d Hz\n",
+ printk(KERN_INFO "UNIPISPI: UniPi device %s at CS%d uses SPI communication freq. %d Hz\n",
NEURONSPI_BOARDTABLE[n_spi->combination_id].definition->combination_name,
spi->chip_select, n_spi->ideal_frequency);
}
+
n_spi->reg_map = regmap_init(&(spi->dev), &neuronspi_regmap_bus, spi, &neuronspi_regmap_config_default);
spin_lock_init(&n_spi->sysfs_regmap_lock);
if (n_spi->features) {
n_spi->regstart_table = NULL;
}
-
- // Check for user-configurable LED devices
- if (n_spi->features && n_spi->features->led_count > 0) {
- printk(KERN_INFO "UNIPISPI: LED model %s with %d LEDs detected at CS: %d\n",
- NEURONSPI_BOARDTABLE[n_spi->combination_id].definition->combination_name,
- n_spi->features->led_count, spi->chip_select);
- n_spi->led_driver = kzalloc(sizeof(struct neuronspi_led_driver) * n_spi->features->led_count, GFP_ATOMIC);
- for (i = 0; i < n_spi->features->led_count; i++) {
- kthread_init_work(&(n_spi->led_driver[i].led_work), neuronspi_led_proc);
- }
- }
-
- n_spi->char_driver = &neuronspi_cdrv;
-
-
+ //n_spi->char_driver = &neuronspi_cdrv;
spin_lock_irqsave(neuronspi_probe_spinlock, flags);
+
neuronspi_s_dev[n_spi->neuron_index] = spi;
spi_set_drvdata(spi, n_spi);
-
- //spi_set_drvdata(neuronspi_s_dev[n_spi->neuron_index], n_spi);
+
if (neuronspi_probe_count == NEURONSPI_MAX_DEVS) {
neuronspi_model_id = neuronspi_find_model_id(neuronspi_probe_count);
}
printk(KERN_INFO "UNIPISPI: Detected UniPi board combination corresponding to %s\n", NEURONSPI_MODELTABLE[neuronspi_model_id].model_name);
}
- unipi_spi_trace(KERN_DEBUG "UNIPISPI: SPI IRQ: %d", spi->irq);
- strcpy(n_spi->platform_name, "io_group0");
+ /* Platform LED, GPIO, IIO sysfs subsystem init */
+ if (neuron_plc_dev == NULL) {
+ // global platform root
+ neuron_plc_dev = platform_device_alloc("unipi_plc", -1);
+ neuron_plc_dev->dev.groups = neuron_plc_attr_groups;
+ platform_device_add(neuron_plc_dev);
+ }
+
+ n_spi->board_device = neuronspi_board_device_probe(n_spi);
+
+ /*strcpy(n_spi->platform_name, "io_group0");
n_spi->platform_name[8] = n_spi->neuron_index + '1';
n_spi->board_device = platform_device_alloc(n_spi->platform_name, -1);
n_spi->board_device->dev.parent = &(neuron_plc_dev->dev);
}
n_spi->board_device->dev.driver = &neuronspi_spi_driver.driver;
platform_device_add(n_spi->board_device);
- platform_set_drvdata(n_spi->board_device, n_spi);
-
- if (!(neuronspi_cdrv.major_number)) { // Register character device if it doesn't exist
- ret = char_register_driver();
- if (ret) {
- printk(KERN_ERR "UNIPISPI: Failed to register the neuronspi character driver, ERR:%d\n", ret);
- }
- }
+ platform_set_drvdata(n_spi->board_device, n_spi);*/
if (n_spi->features) {
if (n_spi->features->led_count) {
- for (i = 0; i < n_spi->features->led_count; i++) {
- strcpy(n_spi->led_driver[i].name, "unipi:green:uled-x1");
- if (i < 9) {
- n_spi->led_driver[i].name[18] = i + '1';
- } else {
- n_spi->led_driver[i].name[18] = i - 9 + 'a';
- }
- // Initialise the rest of the structure
- n_spi->led_driver[i].id = i;
- n_spi->led_driver[i].brightness = LED_OFF;
- n_spi->led_driver[i].spi = spi;
- spin_lock_init(&n_spi->led_driver[i].lock);
- n_spi->led_driver[i].ldev.name = n_spi->led_driver[i].name;
- n_spi->led_driver[i].ldev.brightness = n_spi->led_driver[i].brightness;
- n_spi->led_driver[i].ldev.brightness_set = neuronspi_led_set_brightness;
- led_classdev_register(&(n_spi->board_device->dev), &(n_spi->led_driver[i].ldev));
- }
+ printk(KERN_INFO "UNIPISPI: LED: %d User leds detected at CS%d\n", n_spi->features->led_count, spi->chip_select);
+ n_spi->led_driver = neuronspi_led_probe(n_spi->features->led_count, n_spi->neuron_index, n_spi->board_device);
}
#ifdef CONFIG_GPIOLIB
if (n_spi->features->di_count) {
- n_spi->di_driver = kzalloc(sizeof(struct neuronspi_di_driver*) * n_spi->features->di_count, GFP_ATOMIC);
- for (i = 0; i < n_spi->features->di_count; i++) {
- n_spi->di_driver[i] = kzalloc(sizeof(struct neuronspi_di_driver), GFP_ATOMIC);
- strcpy(n_spi->di_driver[i]->name, "di_0_00");
- n_spi->di_driver[i]->name[3] = n_spi->neuron_index + '1';
- n_spi->di_driver[i]->name[5] = ((i + 1) / 10) + '0';
- n_spi->di_driver[i]->name[6] = ((i + 1) % 10) + '0';
- n_spi->di_driver[i]->di_index = i;
- n_spi->di_driver[i]->spi = spi;
- n_spi->di_driver[i]->plat_dev = platform_device_alloc(n_spi->di_driver[i]->name, -1);
- n_spi->di_driver[i]->plat_dev->dev.parent = &(n_spi->board_device->dev);
- n_spi->di_driver[i]->plat_dev->dev.groups = neuron_gpio_di_attr_groups;
- n_spi->di_driver[i]->plat_dev->dev.driver = &neuronspi_spi_driver.driver;
- platform_device_add(n_spi->di_driver[i]->plat_dev);
- platform_set_drvdata(n_spi->di_driver[i]->plat_dev, n_spi->di_driver[i]);
- n_spi->di_driver[i]->gpio_c.owner = THIS_MODULE;
- n_spi->di_driver[i]->gpio_c.parent = &(n_spi->di_driver[i]->plat_dev->dev);
- n_spi->di_driver[i]->gpio_c.label = "neuron_di";
- n_spi->di_driver[i]->gpio_c.can_sleep = 1;
- n_spi->di_driver[i]->gpio_c.ngpio = 1;
- n_spi->di_driver[i]->gpio_c.base = -1;
- n_spi->di_driver[i]->gpio_c.direction_input = neuronspi_gpio_di_direction_input;
- n_spi->di_driver[i]->gpio_c.get = neuronspi_gpio_di_get;
- gpiochip_add_data(&n_spi->di_driver[i]->gpio_c, n_spi->di_driver[i]);
- }
+ n_spi->di_driver = neuronspi_di_probe(n_spi->features->di_count, n_spi->neuron_index, n_spi->board_device);
}
-
if (n_spi->features->do_count) {
- n_spi->do_driver = kzalloc(sizeof(struct neuronspi_do_driver*) * n_spi->features->do_count, GFP_ATOMIC);
- for (i = 0; i < n_spi->features->do_count; i++) {
- n_spi->do_driver[i] = kzalloc(sizeof(struct neuronspi_do_driver), GFP_ATOMIC);
- strcpy(n_spi->do_driver[i]->name, "do_0_00");
- n_spi->do_driver[i]->name[3] = n_spi->neuron_index + '1';
- n_spi->do_driver[i]->name[5] = ((i + 1) / 10) + '0';
- n_spi->do_driver[i]->name[6] = ((i + 1) % 10) + '0';
- n_spi->do_driver[i]->do_index = i;
- n_spi->do_driver[i]->spi = spi;
- n_spi->do_driver[i]->plat_dev = platform_device_alloc(n_spi->do_driver[i]->name, -1);
- n_spi->do_driver[i]->plat_dev->dev.parent = &(n_spi->board_device->dev);
- n_spi->do_driver[i]->plat_dev->dev.groups = neuron_gpio_do_attr_groups;
- n_spi->do_driver[i]->plat_dev->dev.driver = &neuronspi_spi_driver.driver;
- platform_device_add(n_spi->do_driver[i]->plat_dev);
- platform_set_drvdata(n_spi->do_driver[i]->plat_dev, n_spi->do_driver[i]);
- n_spi->do_driver[i]->gpio_c.owner = THIS_MODULE;
- n_spi->do_driver[i]->gpio_c.parent = &(n_spi->do_driver[i]->plat_dev->dev);
- n_spi->do_driver[i]->gpio_c.label = "neuron_do";
- n_spi->do_driver[i]->gpio_c.can_sleep = 1;
- n_spi->do_driver[i]->gpio_c.ngpio = 1;
- n_spi->do_driver[i]->gpio_c.base = -1;
- n_spi->do_driver[i]->gpio_c.direction_output = neuronspi_gpio_do_direction_output;
- n_spi->do_driver[i]->gpio_c.set = neuronspi_gpio_do_set;
- gpiochip_add_data(&n_spi->do_driver[i]->gpio_c, n_spi->do_driver[i]);
- }
+ n_spi->do_driver = neuronspi_do_probe(n_spi->features->do_count, n_spi->neuron_index, n_spi->board_device);
}
if (n_spi->features->ro_count) {
- n_spi->ro_driver = kzalloc(sizeof(struct neuronspi_ro_driver*) * n_spi->features->ro_count, GFP_ATOMIC);
- for (i = 0; i < n_spi->features->ro_count; i++) {
- n_spi->ro_driver[i] = kzalloc(sizeof(struct neuronspi_ro_driver), GFP_ATOMIC);
- strcpy(n_spi->ro_driver[i]->name, "ro_0_00");
- n_spi->ro_driver[i]->name[3] = n_spi->neuron_index + '1';
- n_spi->ro_driver[i]->name[5] = ((i + 1) / 10) + '0';
- n_spi->ro_driver[i]->name[6] = ((i + 1) % 10) + '0';
- n_spi->ro_driver[i]->ro_index = i;
- n_spi->ro_driver[i]->spi = spi;
- n_spi->ro_driver[i]->plat_dev = platform_device_alloc(n_spi->ro_driver[i]->name, -1);
- n_spi->ro_driver[i]->plat_dev->dev.parent = &(n_spi->board_device->dev);
- n_spi->ro_driver[i]->plat_dev->dev.groups = neuron_gpio_ro_attr_groups;
- n_spi->ro_driver[i]->plat_dev->dev.driver = &neuronspi_spi_driver.driver;
- platform_device_add(n_spi->ro_driver[i]->plat_dev);
- platform_set_drvdata(n_spi->ro_driver[i]->plat_dev, n_spi->ro_driver[i]);
- n_spi->ro_driver[i]->gpio_c.owner = THIS_MODULE;
- n_spi->ro_driver[i]->gpio_c.parent = &(n_spi->ro_driver[i]->plat_dev->dev);
- n_spi->ro_driver[i]->gpio_c.label = "neuron_ro";
- n_spi->ro_driver[i]->gpio_c.can_sleep = 1;
- n_spi->ro_driver[i]->gpio_c.ngpio = 1;
- n_spi->ro_driver[i]->gpio_c.base = -1;
- n_spi->ro_driver[i]->gpio_c.direction_output = neuronspi_gpio_ro_direction_output;
- n_spi->ro_driver[i]->gpio_c.set = neuronspi_gpio_ro_set;
- gpiochip_add_data(&n_spi->ro_driver[i]->gpio_c, n_spi->ro_driver[i]);
- }
+ n_spi->ro_driver = neuronspi_ro_probe(n_spi->features->ro_count, n_spi->neuron_index, n_spi->board_device);
}
#endif
if (n_spi->features->stm_ai_count) {
n_spi->uart_count_to_probe = uart_count;
if (uart_count) {
- //n_spi->uart_buf = kzalloc(NEURONSPI_FIFO_SIZE, GFP_ATOMIC);
if (neuronspi_uart_driver_global != NULL) {
- // Normalne se registrace portu udela az po inicializaci unipispi driveru. (Na konci __init__)
- // Opravit proceduru probe !!!
+ // Normally is port registration done after unipispi driver probe. (in the end of __init__)
unipi_spi_trace(KERN_DEBUG "UNIPISPI: UART registration\n");
-
neuronspi_uart_probe(spi, n_spi);
- //n_spi->uart_count = uart_count;
+
} else {
- unipi_spi_trace(KERN_DEBUG "UNIPISPI: Neuronspi uart driver not registered yet. Uart port add later.\n");
+ unipi_spi_trace(KERN_DEBUG "UNIPISPI: Uart driver not registered yet. Uart port add later.\n");
}
}
for (i = 0; i < NEURONSPI_NO_INTERRUPT_MODELS_LEN; i++) {
if (NEURONSPI_NO_INTERRUPT_MODELS[i] == (n_spi->first_probe_reply[17-6] << 8 | n_spi->first_probe_reply[16-6])) {
no_irq = 1;
+ break;
}
}
if (!no_irq) {
n_spi->no_irq = 0;
ret = devm_request_irq(&(spi->dev), spi->irq, neuronspi_spi_irq, 0x81, dev_name(&(spi->dev)), spi);
- unipi_spi_trace(KERN_DEBUG "UNIPISPI: IRQ registration, ret:%d\n", ret);
+ unipi_spi_trace(KERN_DEBUG "UNIPISPI: SPI IRQ %d registration: ret=%d\n", spi->irq, ret);
} else {
n_spi->no_irq = 1;
unipi_spi_trace(KERN_DEBUG "UNIPISPI: NO IRQ ON THIS MODEL !!\n");
printk(KERN_INFO "UNIPISPI: LED DRIVER UNREGISTERED\n");
if (n_spi->di_driver) {
for (i = 0; i < n_spi->features->di_count; i++) {
- gpiochip_remove(&n_spi->di_driver[i]->gpio_c);
- platform_set_drvdata(n_spi->di_driver[i]->plat_dev, 0);
- platform_device_unregister(n_spi->di_driver[i]->plat_dev);
- kfree(n_spi->di_driver[i]);
+ gpiochip_remove(&n_spi->di_driver[i].gpio_c);
+ platform_set_drvdata(n_spi->di_driver[i].plat_dev, 0);
+ platform_device_unregister(n_spi->di_driver[i].plat_dev);
}
kfree(n_spi->di_driver);
}
if (n_spi->do_driver) {
for (i = 0; i < n_spi->features->do_count; i++) {
- gpiochip_remove(&n_spi->do_driver[i]->gpio_c);
- platform_set_drvdata(n_spi->do_driver[i]->plat_dev, 0);
- platform_device_unregister(n_spi->do_driver[i]->plat_dev);
- kfree(n_spi->do_driver[i]);
+ gpiochip_remove(&n_spi->do_driver[i].gpio_c);
+ platform_set_drvdata(n_spi->do_driver[i].plat_dev, 0);
+ platform_device_unregister(n_spi->do_driver[i].plat_dev);
}
kfree(n_spi->do_driver);
}
if (n_spi->ro_driver) {
for (i = 0; i < n_spi->features->ro_count; i++) {
- gpiochip_remove(&n_spi->ro_driver[i]->gpio_c);
- platform_set_drvdata(n_spi->ro_driver[i]->plat_dev, 0);
- platform_device_unregister(n_spi->ro_driver[i]->plat_dev);
- kfree(n_spi->ro_driver[i]);
+ gpiochip_remove(&n_spi->ro_driver[i].gpio_c);
+ platform_set_drvdata(n_spi->ro_driver[i].plat_dev, 0);
+ platform_device_unregister(n_spi->ro_driver[i].plat_dev);
}
kfree(n_spi->ro_driver);
}
n_spi->sec_ao_driver = NULL;
}
printk(KERN_INFO "UNIPISPI: IIO DRIVER UNREGISTERED\n");
- //if (n_spi->uart_buf) {
- // kfree(n_spi->uart_buf);
- // n_spi->uart_buf = NULL;
- //}
printk(KERN_INFO "UNIPISPI: SPI/UART DRIVER UNREGISTERED\n");
if (n_spi->board_device) {
platform_set_drvdata(n_spi->board_device, 0);
{
s32 ret = 0;
- //neuronspi_uart_driver_init();
-
neuronspi_probe_spinlock = kzalloc(sizeof(struct spinlock), GFP_ATOMIC);
spin_lock_init(neuronspi_probe_spinlock);
mutex_init(&neuronspi_master_mutex);
mutex_init(&unipi_inv_speed_mutex);
+
// clear global neuron spi devices list
memset(&neuronspi_s_dev, 0, sizeof(neuronspi_s_dev));
ret = spi_register_driver(&neuronspi_spi_driver);
+
if (ret < 0) {
printk(KERN_ERR "UNIPISPI: Failed to init neuronspi spi --> %d\n", ret);
return ret;
printk(KERN_INFO "UNIPISPI: SPI Driver Registered\n");
#endif
}
+
neuronspi_invalidate_thread = kthread_create(neuronspi_regmap_invalidate, NULL, "unipispi_inv");
if (neuronspi_invalidate_thread != NULL) {
wake_up_process(neuronspi_invalidate_thread);
}
+ if (!(neuronspi_cdrv.major_number)) { // Register character device if it doesn't exist
+ ret = char_register_driver();
+ if (ret) {
+ printk(KERN_ERR "UNIPISPI: Failed to register the neuronspi character driver, ERR:%d\n", ret);
+ }
+ }
+
neuronspi_uart_driver_init();
neuronspi_uart_probe_all();
0xb10, 0xc10, 0xf10
};
-/*
-#define NEURONSPI_PROBE_MESSAGE_LEN 22
-static const u8 NEURONSPI_PROBE_MESSAGE[NEURONSPI_PROBE_MESSAGE_LEN] = {
- 0x04, 0x0e, 0xe8, 0x03, 0xa0, 0xdd,
- 0x04, 0x00, 0xe8, 0x03, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x12, 0x16
-};
-*/
#define UNIPISPI_PROBE_MESSAGE_LEN 16
static u8 _probe_message_second[UNIPISPI_PROBE_MESSAGE_LEN] =
second_message: _probe_message_second,
};
-/*
-#define NEURONSPI_UART_PROBE_MESSAGE_LEN 6
-static const u8 NEURONSPI_UART_PROBE_MESSAGE[NEURONSPI_UART_PROBE_MESSAGE_LEN] = {
- 0xfa, 0x00, 0x55, 0x0e, 0xb6, 0x0a
-};
-*/
static const struct neuronspi_op_buffer UNIPISPI_IDLE_MESSAGE = {
first_message: {0xfa, 0x00, 0x55, 0x0e, 0xb6, 0x0a},
second_message: NULL,
};
-/*
-#define NEURONSPI_SPI_UART_SHORT_MESSAGE_LEN 6
-static const u8 NEURONSPI_SPI_UART_SHORT_MESSAGE[NEURONSPI_SPI_UART_SHORT_MESSAGE_LEN] = {
- 0x41, 0x00, 0x00, 0x00, 0x00, 0x00
-};
-
-#define NEURONSPI_SPI_UART_LONG_MESSAGE_LEN 8
-static const u8 NEURONSPI_SPI_UART_LONG_MESSAGE[NEURONSPI_SPI_UART_LONG_MESSAGE_LEN] = {
- 0x64, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00
-};
-
-#define NEURONSPI_SPI_UART_READ_MESSAGE_LEN 14
-static const u8 NEURONSPI_SPI_UART_READ_MESSAGE[NEURONSPI_SPI_UART_READ_MESSAGE_LEN] = {
- 0x65, 0x06, 0x00, 0x00, 0x44, 0x69,
- 0x65, 0x03, 0x00, 0x00, 0x00, 0x05,
- 0x6a, 0x0c
-};
-
-#define NEURONSPI_SPI_UART_READ_MESSAGE0_LEN 14
-static const u8 NEURONSPI_SPI_UART_READ_MESSAGE0[NEURONSPI_SPI_UART_READ_MESSAGE0_LEN] = {
- 0x68, 0x06, 0x00, 0x00, 0x00, 0x00,
- 0x65, 0x03, 0x00, 0x00, 0x00, 0x05,
- 0x6a, 0x0c
-};
-
-#define NEURONSPI_SPI_IRQ_SET_MESSAGE_LEN 14
-static const u8 NEURONSPI_SPI_IRQ_SET_MESSAGE[NEURONSPI_SPI_IRQ_SET_MESSAGE_LEN] = {
- 0x06, 0x06, 0xef, 0x03, 0x00, 0x00,
- 0x06, 0x01, 0xef, 0x03, 0x05, 0x00,
- 0x00, 0x00
-};
-
-#define NEURONSPI_SPI_UART_GET_CFLAG_MESSAGE_LEN 16
-static const u8 NEURONSPI_SPI_UART_GET_CFLAG_MESSAGE[NEURONSPI_SPI_UART_GET_CFLAG_MESSAGE_LEN] = {
- 0x04, 0x08, 0xf4, 0x01, 0x00, 0x00,
- 0x04, 0x02, 0xf4, 0x01, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00
-};
-
-#define NEURONSPI_SPI_UART_GET_LDISC_MESSAGE_LEN 16
-static const u8 NEURONSPI_SPI_UART_GET_LDISC_MESSAGE[NEURONSPI_SPI_UART_GET_LDISC_MESSAGE_LEN] = {
- 0x04, 0x08, 0xf6, 0x01, 0x00, 0x00,
- 0x04, 0x02, 0xf6, 0x01, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00
-};
-
-#define NEURONSPI_SPI_UART_SET_CFLAG_MESSAGE_LEN 16
-static const u8 NEURONSPI_SPI_UART_SET_CFLAG_MESSAGE[NEURONSPI_SPI_UART_SET_CFLAG_MESSAGE_LEN] = {
- 0x06, 0x08, 0xf4, 0x01, 0x00, 0x00,
- 0x06, 0x02, 0xf4, 0x01, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00
-};
-
-#define NEURONSPI_SPI_LED_SET_MESSAGE_LEN 6
-static const u8 NEURONSPI_SPI_LED_SET_MESSAGE[NEURONSPI_SPI_LED_SET_MESSAGE_LEN] = {
- 0x05, 0x00, 0x08, 0x00, 0x00, 0x00
-};
-*/
#define NEURONSPI_CRC16TABLE_LEN 256
static const u16 NEURONSPI_CRC16TABLE[NEURONSPI_CRC16TABLE_LEN] = {
int neuronspi_spi_send_op(struct spi_device* spi_dev, struct neuronspi_op_buffer* send_buf,
struct neuronspi_op_buffer* recv_buf, s32 len,
s32 freq, s32 delay, s32 send_header, u8 lock_val);
-//int neuronspi_spi_send_message_crc(struct spi_device* spi_dev, struct neuronspi_op_buffer* send_buf, struct neuronspi_op_buffer* recv_buf, s32 len, s32 freq, s32 delay);
-//int neuronspi_spi_send_message(struct spi_device *spi_dev, u8 *send_buf, u8 *recv_buf, s32 len, s32 freq, s32 delay, s32 send_header, u8 lock_val);
s32 neuronspi_spi_uart_write(struct spi_device *spi, u8 *send_buf, int length, u8 uart_index);
-//void neuronspi_spi_uart_read(struct spi_device* spi_dev, u8 *send_buf, u8 *recv_buf, s32 len, u8 uart_index);
void neuronspi_spi_uart_read(struct spi_device* spi_dev, u8 *recv_buf, s32 len, u8 uart_index);
int unipispi_modbus_read_register(struct spi_device* spi_dev, u16 reg, u16* value);
int unipispi_modbus_read_u32(struct spi_device* spi_dev, u16 reg, u32* value);
return result;
}
-/*
-static __always_inline size_t neuronspi_spi_compose_single_coil_write(u16 start, u8 **buf_inp, u8 **buf_outp, u8 data)
-{
- u16 crc1;
- *buf_outp = kzalloc(6, GFP_ATOMIC);
- *buf_inp = kzalloc(6, GFP_ATOMIC);
- (*buf_inp)[0] = 0x05;
- (*buf_inp)[1] = data;
- (*buf_inp)[2] = start & 0xFF;
- (*buf_inp)[3] = start >> 8;
- crc1 = neuronspi_spi_crc(*buf_inp, 4, 0);
- memcpy(&(*buf_inp)[4], &crc1, 2);
- return 6;
-}
-
-static __always_inline size_t neuronspi_spi_compose_single_coil_read(u16 start, u8 **buf_inp, u8 **buf_outp)
-{
- u16 crc1, crc2;
- *buf_outp = kzalloc(14, GFP_ATOMIC);
- *buf_inp = kzalloc(14, GFP_ATOMIC);
- (*buf_inp)[0] = 0x01;
- (*buf_inp)[1] = 0x06;
- (*buf_inp)[2] = start & 0xFF;
- (*buf_inp)[3] = start >> 8;
- crc1 = neuronspi_spi_crc(*buf_inp, 4, 0);
- memcpy(&(*buf_inp)[4], &crc1, 2);
- memcpy(&(*buf_inp)[6], *buf_inp, 4);
- crc2 = neuronspi_spi_crc(&(*buf_inp)[6], 6, crc1);
- memcpy(&(*buf_inp)[12], &crc2, 2);
- return 14;
-}
-
-static __always_inline size_t neuronspi_spi_compose_multiple_coil_write(u8 number, u16 start, u8 **buf_inp, u8 **buf_outp, u8 *data)
-{
- u16 crc1, crc2;
- *buf_outp = kzalloc(12 + NEURONSPI_GET_COIL_READ_PHASE2_BYTE_LENGTH(number), GFP_ATOMIC);
- *buf_inp = kzalloc(12 + NEURONSPI_GET_COIL_READ_PHASE2_BYTE_LENGTH(number), GFP_ATOMIC);
- (*buf_inp)[0] = 0x0F;
- (*buf_inp)[1] = 4 + NEURONSPI_GET_COIL_READ_PHASE2_BYTE_LENGTH(number);
- (*buf_inp)[2] = start & 0xFF;
- (*buf_inp)[3] = start >> 8;
- crc1 = neuronspi_spi_crc(*buf_inp, 4, 0);
- memcpy(&(*buf_inp)[4], &crc1, 2);
- memcpy(&(*buf_inp)[6], *buf_inp, 4);
- (*buf_inp)[7] = number;
- memcpy(&(*buf_inp)[10], data, NEURONSPI_GET_COIL_READ_PHASE2_BYTE_LENGTH(number));
- crc2 = neuronspi_spi_crc(&(*buf_inp)[6], 4 + NEURONSPI_GET_COIL_READ_PHASE2_BYTE_LENGTH(number), crc1);
- memcpy(&(*buf_inp)[10 + NEURONSPI_GET_COIL_READ_PHASE2_BYTE_LENGTH(number)], &crc2, 2);
- return 12 + NEURONSPI_GET_COIL_READ_PHASE2_BYTE_LENGTH(number);
-}
-
-static __always_inline size_t neuronspi_spi_compose_multiple_coil_read(u8 number, u16 start, u8 **buf_inp, u8 **buf_outp)
-{
- u16 crc1, crc2;
- *buf_outp = kzalloc(12 + NEURONSPI_GET_COIL_READ_PHASE2_BYTE_LENGTH(number), GFP_ATOMIC);
- *buf_inp = kzalloc(12 + NEURONSPI_GET_COIL_READ_PHASE2_BYTE_LENGTH(number), GFP_ATOMIC);
- (*buf_inp)[0] = 0x01;
- (*buf_inp)[1] = 4 + NEURONSPI_GET_COIL_READ_PHASE2_BYTE_LENGTH(number);
- (*buf_inp)[2] = start & 0xFF;
- (*buf_inp)[3] = start >> 8;
- crc1 = neuronspi_spi_crc(*buf_inp, 4, 0);
- memcpy(&(*buf_inp)[4], &crc1, 2);
- memcpy(&(*buf_inp)[6], *buf_inp, 4);
- crc2 = neuronspi_spi_crc(&(*buf_inp)[6], 4 + NEURONSPI_GET_COIL_READ_PHASE2_BYTE_LENGTH(number), crc1);
- memcpy(&(*buf_inp)[10 + NEURONSPI_GET_COIL_READ_PHASE2_BYTE_LENGTH(number)], &crc2, 2);
- return 12 + NEURONSPI_GET_COIL_READ_PHASE2_BYTE_LENGTH(number);
-}
-
-static __always_inline size_t neuronspi_spi_compose_single_register_write(u16 start, u8 **buf_inp, u8 **buf_outp, u16 data)
-{
- u16 crc1, crc2;
- *buf_outp = kzalloc(14, GFP_ATOMIC);
- *buf_inp = kzalloc(14, GFP_ATOMIC);
- (*buf_inp)[0] = 0x06;
- (*buf_inp)[1] = 0x06;
- (*buf_inp)[2] = start & 0xFF;
- (*buf_inp)[3] = start >> 8;
- crc1 = neuronspi_spi_crc(*buf_inp, 4, 0);
- memcpy(&(*buf_inp)[4], &crc1, 2);
- memcpy(&(*buf_inp)[6], *buf_inp, 4);
- (*buf_inp)[7] = 0x01;
- memcpy(&(*buf_inp)[10], &data, 2);
- crc2 = neuronspi_spi_crc(&(*buf_inp)[6], 6, crc1);
- memcpy(&(*buf_inp)[12], &crc2, 2);
- return 14;
-}
-
-static __always_inline size_t neuronspi_spi_compose_single_register_read(u16 start, u8 **buf_inp, u8 **buf_outp)
-{
- u16 crc1, crc2;
- *buf_outp = kzalloc(14, GFP_ATOMIC);
- *buf_inp = kzalloc(14, GFP_ATOMIC);
- (*buf_inp)[0] = 0x03;
- (*buf_inp)[1] = 0x06;
- (*buf_inp)[2] = start & 0xFF;
- (*buf_inp)[3] = start >> 8;
- crc1 = neuronspi_spi_crc(*buf_inp, 4, 0);
- memcpy(&(*buf_inp)[4], &crc1, 2);
- memcpy(&(*buf_inp)[6], *buf_inp, 4);
- (*buf_inp)[7] = 0x01;
- crc2 = neuronspi_spi_crc(&(*buf_inp)[6], 6, crc1);
- memcpy(&(*buf_inp)[12], &crc2, 2);
- return 14;
-}
-
-static __always_inline size_t neuronspi_spi_compose_multiple_register_write(u8 number, u16 start, u8 **buf_inp, u8 **buf_outp, u8 *data)
-{
- u16 crc1, crc2;
- *buf_outp = kzalloc(12 + (number * 2), GFP_ATOMIC);
- *buf_inp = kzalloc(12 + (number * 2), GFP_ATOMIC);
- (*buf_inp)[0] = 0x10;
- (*buf_inp)[1] = 4 + (number * 2);
- (*buf_inp)[2] = start & 0xFF;
- (*buf_inp)[3] = start >> 8;
- crc1 = neuronspi_spi_crc(*buf_inp, 4, 0);
- memcpy(&(*buf_inp)[4], &crc1, 2);
- memcpy(&(*buf_inp)[6], *buf_inp, 4);
- (*buf_inp)[7] = number;
- memcpy(&(*buf_inp)[10], data, number * 2);
- crc2 = neuronspi_spi_crc(&(*buf_inp)[6], 4 + (number * 2), crc1);
- memcpy(&(*buf_inp)[10 + (number * 2)], &crc2, 2);
- return 12 + (number * 2);
-}
-
-static __always_inline size_t neuronspi_spi_compose_multiple_register_read(u8 number, u16 start, u8 **buf_inp, u8 **buf_outp)
-{
- u16 crc1, crc2;
- *buf_outp = kzalloc(12 + (number * 2), GFP_ATOMIC);
- *buf_inp = kzalloc(12 + (number * 2), GFP_ATOMIC);
- (*buf_inp)[0] = 0x03;
- (*buf_inp)[1] = 4 + (number * 2);
- (*buf_inp)[2] = start & 0xFF;
- (*buf_inp)[3] = start >> 8;
- crc1 = neuronspi_spi_crc(*buf_inp, 4, 0);
- memcpy(&(*buf_inp)[4], &crc1, 2);
- memcpy(&(*buf_inp)[6], *buf_inp, 4);
- (*buf_inp)[7] = number;
- crc2 = neuronspi_spi_crc(&(*buf_inp)[6], 4 + (number * 2), crc1);
- memcpy(&(*buf_inp)[10 + (number * 2)], &crc2, 2);
- return 12 + (number * 2);
-}
-*/
#endif /* MODULES_NEURON_SPI_SRC_UNIPI_SPI_H_ */
{
ssize_t ret = 0;
u32 val = 0;
- struct neuronspi_do_driver *n_do;
+ struct neuronspi_gpio_driver *n_do;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_do = platform_get_drvdata(plat);
{
ssize_t err = 0;
unsigned int val = 0;
- struct neuronspi_do_driver *n_do;
+ struct neuronspi_gpio_driver *n_do;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_do = platform_get_drvdata(plat);
{
ssize_t ret = 0;
u32 val = 0;
- struct neuronspi_do_driver *n_do;
+ struct neuronspi_gpio_driver *n_do;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_do = platform_get_drvdata(plat);
{
ssize_t err = 0;
unsigned int val = 0;
- struct neuronspi_do_driver *n_do;
+ struct neuronspi_gpio_driver *n_do;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_do = platform_get_drvdata(plat);
{
ssize_t ret = 0;
u32 val = 0;
- struct neuronspi_do_driver *n_do;
+ struct neuronspi_gpio_driver *n_do;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_do = platform_get_drvdata(plat);
n_spi = spi_get_drvdata(n_do->spi);
if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map) {
- regmap_read(n_spi->reg_map, n_spi->regstart_table->do_pwm_reg + n_do->do_index, &val);
+ regmap_read(n_spi->reg_map, n_spi->regstart_table->do_pwm_reg + n_do->io_index, &val);
ret = scnprintf(buf, 255, "%d\n", val);
}
return ret;
{
ssize_t err = 0;
unsigned int val = 0;
- struct neuronspi_do_driver *n_do;
+ struct neuronspi_gpio_driver *n_do;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_do = platform_get_drvdata(plat);
err = kstrtouint(buf, 0, &val);
if (err < 0) goto err_end;
if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map) {
- regmap_write(n_spi->reg_map, n_spi->regstart_table->do_pwm_reg + n_do->do_index, val);
+ regmap_write(n_spi->reg_map, n_spi->regstart_table->do_pwm_reg + n_do->io_index, val);
}
err_end:
return count;
ssize_t ret = 0;
u32 val = 0;
u32 val_upper = 0;
- struct neuronspi_di_driver *n_di;
+ struct neuronspi_gpio_driver *n_di;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_di = platform_get_drvdata(plat);
n_spi = spi_get_drvdata(n_di->spi);
if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map) {
- regmap_read(n_spi->reg_map, n_spi->regstart_table->di_counter_reg + (2 * n_di->di_index), &val);
- regmap_read(n_spi->reg_map, n_spi->regstart_table->di_counter_reg + 1 + (2 * n_di->di_index), &val_upper);
+ regmap_read(n_spi->reg_map, n_spi->regstart_table->di_counter_reg + (2 * n_di->io_index), &val);
+ regmap_read(n_spi->reg_map, n_spi->regstart_table->di_counter_reg + 1 + (2 * n_di->io_index), &val_upper);
val |= val_upper << 16;
ret = scnprintf(buf, 255, "%d\n", val);
}
{
ssize_t err = 0;
unsigned int val = 0;
- struct neuronspi_di_driver *n_di;
+ struct neuronspi_gpio_driver *n_di;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_di = platform_get_drvdata(plat);
err = kstrtouint(buf, 0, &val);
if (err < 0) goto err_end;
if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map) {
- regmap_write(n_spi->reg_map, n_spi->regstart_table->di_counter_reg + (2 * n_di->di_index), val & 0xFFFF);
- regmap_write(n_spi->reg_map, n_spi->regstart_table->di_counter_reg + 1 + (2 * n_di->di_index), val >> 16);
+ regmap_write(n_spi->reg_map, n_spi->regstart_table->di_counter_reg + (2 * n_di->io_index), val & 0xFFFF);
+ regmap_write(n_spi->reg_map, n_spi->regstart_table->di_counter_reg + 1 + (2 * n_di->io_index), val >> 16);
}
err_end:
return count;
{
ssize_t ret = 0;
u32 val = 0;
- struct neuronspi_di_driver *n_di;
+ struct neuronspi_gpio_driver *n_di;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_di = platform_get_drvdata(plat);
n_spi = spi_get_drvdata(n_di->spi);
- if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map && n_spi->features && n_spi->features->di_count > n_di->di_index) {
- regmap_read(n_spi->reg_map, n_spi->regstart_table->di_deboun_reg + n_di->di_index, &val);
+ if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map && n_spi->features && n_spi->features->di_count > n_di->io_index) {
+ regmap_read(n_spi->reg_map, n_spi->regstart_table->di_deboun_reg + n_di->io_index, &val);
ret = scnprintf(buf, 255, "%d\n", val);
}
return ret;
{
ssize_t err = 0;
unsigned int val = 0;
- struct neuronspi_di_driver *n_di;
+ struct neuronspi_gpio_driver *n_di;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_di = platform_get_drvdata(plat);
n_spi = spi_get_drvdata(n_di->spi);
err = kstrtouint(buf, 0, &val);
if (err < 0) goto err_end;
- if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map && n_spi->features && n_spi->features->di_count > n_di->di_index) {
- regmap_write(n_spi->reg_map, n_spi->regstart_table->di_deboun_reg + n_di->di_index, val);
+ if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map && n_spi->features && n_spi->features->di_count > n_di->io_index) {
+ regmap_write(n_spi->reg_map, n_spi->regstart_table->di_deboun_reg + n_di->io_index, val);
}
err_end:
return count;
{
ssize_t ret = 0;
int val;
- struct neuronspi_di_driver *n_di;
+ struct neuronspi_gpio_driver *n_di;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_di = platform_get_drvdata(plat);
n_spi = spi_get_drvdata(n_di->spi);
- if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->di_count > n_di->di_index) {
- regmap_read(n_spi->reg_map, n_spi->regstart_table->di_val_reg + (n_di->di_index / 16), &val);
- val &= 0x1 << (n_di->di_index % 15);
- val = val >> (n_di->di_index % 15);
+ if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->di_count > n_di->io_index) {
+ regmap_read(n_spi->reg_map, n_spi->regstart_table->di_val_reg + (n_di->io_index / 16), &val);
+ val &= 0x1 << (n_di->io_index % 15);
+ val = val >> (n_di->io_index % 15);
ret = scnprintf(buf, 255, "%d\n", val);
}
return ret;
{
ssize_t ret = 0;
int val;
- struct neuronspi_do_driver *n_do;
+ struct neuronspi_gpio_driver *n_do;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_do = platform_get_drvdata(plat);
n_spi = spi_get_drvdata(n_do->spi);
- if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->do_count > n_do->do_index) {
- regmap_read(n_spi->reg_map, n_spi->regstart_table->do_val_reg + (n_do->do_index / 16), &val);
- val &= 0x1 << (n_do->do_index % 15);
- val = val >> (n_do->do_index % 15);
+ if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->do_count > n_do->io_index) {
+ regmap_read(n_spi->reg_map, n_spi->regstart_table->do_val_reg + (n_do->io_index / 16), &val);
+ val &= 0x1 << (n_do->io_index % 15);
+ val = val >> (n_do->io_index % 15);
ret = scnprintf(buf, 255, "%d\n", val);
}
return ret;
ssize_t err = 0;
int inp = 0;
unsigned int val;
- struct neuronspi_do_driver *n_do;
+ struct neuronspi_gpio_driver *n_do;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_do = platform_get_drvdata(plat);
if (inp > 1 || inp < 0) {
goto err_end;
}
- if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->do_count > n_do->do_index) {
- regmap_read(n_spi->reg_map, n_spi->regstart_table->do_val_reg + (n_do->do_index / 16), &val);
- val &= ~(0x1 << (n_do->do_index % 15));
- val |= inp << (n_do->do_index % 15);
- regmap_write(n_spi->reg_map, n_spi->regstart_table->do_val_reg + (n_do->do_index / 16), val);
+ if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->do_count > n_do->io_index) {
+ regmap_read(n_spi->reg_map, n_spi->regstart_table->do_val_reg + (n_do->io_index / 16), &val);
+ val &= ~(0x1 << (n_do->io_index % 15));
+ val |= inp << (n_do->io_index % 15);
+ regmap_write(n_spi->reg_map, n_spi->regstart_table->do_val_reg + (n_do->io_index / 16), val);
}
err_end:
return count;
{
ssize_t ret = 0;
int val;
- struct neuronspi_ro_driver *n_ro;
+ struct neuronspi_gpio_driver *n_ro;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_ro = platform_get_drvdata(plat);
n_spi = spi_get_drvdata(n_ro->spi);
- if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->ro_count > n_ro->ro_index) {
- regmap_read(n_spi->reg_map, n_spi->regstart_table->ro_val_reg + (n_ro->ro_index / 16), &val);
- val &= 0x1 << (n_ro->ro_index % 15);
- val = val >> (n_ro->ro_index % 15);
+ if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->ro_count > n_ro->io_index) {
+ regmap_read(n_spi->reg_map, n_spi->regstart_table->ro_val_reg + (n_ro->io_index / 16), &val);
+ val &= 0x1 << (n_ro->io_index % 15);
+ val = val >> (n_ro->io_index % 15);
ret = scnprintf(buf, 255, "%d\n", val);
}
return ret;
ssize_t err = 0;
int inp = 0;
unsigned int val;
- struct neuronspi_ro_driver *n_ro;
+ struct neuronspi_gpio_driver *n_ro;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_ro = platform_get_drvdata(plat);
if (inp > 1 || inp < 0) {
goto err_end;
}
- if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->ro_count > n_ro->ro_index) {
- regmap_read(n_spi->reg_map, n_spi->regstart_table->ro_val_reg + (n_ro->ro_index / 16), &val);
- val &= ~(0x1 << (n_ro->ro_index % 15));
- val |= inp << (n_ro->ro_index % 15);
- regmap_write(n_spi->reg_map, n_spi->regstart_table->ro_val_reg + (n_ro->ro_index / 16), val);
+ if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->ro_count > n_ro->io_index) {
+ regmap_read(n_spi->reg_map, n_spi->regstart_table->ro_val_reg + (n_ro->io_index / 16), &val);
+ val &= ~(0x1 << (n_ro->io_index % 15));
+ val |= inp << (n_ro->io_index % 15);
+ regmap_write(n_spi->reg_map, n_spi->regstart_table->ro_val_reg + (n_ro->io_index / 16), val);
}
err_end:
return count;
{
ssize_t ret = 0;
int val;
- struct neuronspi_di_driver *n_di;
+ struct neuronspi_gpio_driver *n_di;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_di = platform_get_drvdata(plat);
n_spi = spi_get_drvdata(n_di->spi);
if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->ds_count) {
- regmap_read(n_spi->reg_map, n_spi->regstart_table->di_direct_reg + (n_di->di_index / 16), &val);
- val &= 0x1 << (n_di->di_index % 15);
- val = val >> (n_di->di_index % 15);
+ regmap_read(n_spi->reg_map, n_spi->regstart_table->di_direct_reg + (n_di->io_index / 16), &val);
+ val &= 0x1 << (n_di->io_index % 15);
+ val = val >> (n_di->io_index % 15);
ret = scnprintf(buf, 255, "%d\n", val);
}
return ret;
{
ssize_t ret = 0;
int val;
- struct neuronspi_di_driver *n_di;
+ struct neuronspi_gpio_driver *n_di;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_di = platform_get_drvdata(plat);
n_spi = spi_get_drvdata(n_di->spi);
if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->ds_count) {
- regmap_read(n_spi->reg_map, n_spi->regstart_table->di_toggle_reg + (n_di->di_index / 16), &val);
- val &= 0x1 << (n_di->di_index % 15);
- val = val >> (n_di->di_index % 15);
+ regmap_read(n_spi->reg_map, n_spi->regstart_table->di_toggle_reg + (n_di->io_index / 16), &val);
+ val &= 0x1 << (n_di->io_index % 15);
+ val = val >> (n_di->io_index % 15);
ret = scnprintf(buf, 255, "%d\n", val);
}
return ret;
{
ssize_t ret = 0;
int val;
- struct neuronspi_di_driver *n_di;
+ struct neuronspi_gpio_driver *n_di;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_di = platform_get_drvdata(plat);
n_spi = spi_get_drvdata(n_di->spi);
if (n_spi && n_spi->combination_id != -1 && n_spi->features && n_spi->features->ds_count) {
- regmap_read(n_spi->reg_map, n_spi->regstart_table->di_polar_reg + (n_di->di_index / 16), &val);
- val &= 0x1 << (n_di->di_index % 15);
- val = val >> (n_di->di_index % 15);
+ regmap_read(n_spi->reg_map, n_spi->regstart_table->di_polar_reg + (n_di->io_index / 16), &val);
+ val &= 0x1 << (n_di->io_index % 15);
+ val = val >> (n_di->io_index % 15);
ret = scnprintf(buf, 255, "%d\n", val);
}
return ret;
ssize_t err = 0;
int inp = 0;
unsigned int val;
- struct neuronspi_di_driver *n_di;
+ struct neuronspi_gpio_driver *n_di;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_di = platform_get_drvdata(plat);
goto err_end;
}
if (n_spi && n_spi->combination_id != -1 && n_spi->features && n_spi->features->ds_count) {
- regmap_read(n_spi->reg_map, n_spi->regstart_table->di_direct_reg + (n_di->di_index / 16), &val);
- val &= ~(0x1 << (n_di->di_index % 15));
- val |= inp << (n_di->di_index % 15);
- regmap_write(n_spi->reg_map, n_spi->regstart_table->di_direct_reg + (n_di->di_index / 16), val);
+ regmap_read(n_spi->reg_map, n_spi->regstart_table->di_direct_reg + (n_di->io_index / 16), &val);
+ val &= ~(0x1 << (n_di->io_index % 15));
+ val |= inp << (n_di->io_index % 15);
+ regmap_write(n_spi->reg_map, n_spi->regstart_table->di_direct_reg + (n_di->io_index / 16), val);
}
err_end:
return count;
ssize_t err = 0;
int inp = 0;
unsigned int val;
- struct neuronspi_di_driver *n_di;
+ struct neuronspi_gpio_driver *n_di;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_di = platform_get_drvdata(plat);
goto err_end;
}
if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->ds_count) {
- regmap_read(n_spi->reg_map, n_spi->regstart_table->di_toggle_reg + (n_di->di_index / 16), &val);
- val &= ~(0x1 << (n_di->di_index % 15));
- val |= inp << (n_di->di_index % 15);
- regmap_write(n_spi->reg_map, n_spi->regstart_table->di_toggle_reg + (n_di->di_index / 16), val);
+ regmap_read(n_spi->reg_map, n_spi->regstart_table->di_toggle_reg + (n_di->io_index / 16), &val);
+ val &= ~(0x1 << (n_di->io_index % 15));
+ val |= inp << (n_di->io_index % 15);
+ regmap_write(n_spi->reg_map, n_spi->regstart_table->di_toggle_reg + (n_di->io_index / 16), val);
}
err_end:
return count;
ssize_t err = 0;
int inp = 0;
unsigned int val;
- struct neuronspi_di_driver *n_di;
+ struct neuronspi_gpio_driver *n_di;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_di = platform_get_drvdata(plat);
goto err_end;
}
if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->ds_count) {
- regmap_read(n_spi->reg_map, n_spi->regstart_table->di_polar_reg + (n_di->di_index / 16), &val);
- val &= ~(0x1 << (n_di->di_index % 15));
- val |= inp << (n_di->di_index % 15);
- regmap_write(n_spi->reg_map, n_spi->regstart_table->di_polar_reg + (n_di->di_index / 16), val);
+ regmap_read(n_spi->reg_map, n_spi->regstart_table->di_polar_reg + (n_di->io_index / 16), &val);
+ val &= ~(0x1 << (n_di->io_index % 15));
+ val |= inp << (n_di->io_index % 15);
+ regmap_write(n_spi->reg_map, n_spi->regstart_table->di_polar_reg + (n_di->io_index / 16), val);
}
err_end:
return count;
static ssize_t neuronspi_spi_gpio_show_do_prefix(struct device *dev, struct device_attribute *attr, char *buf)
{
ssize_t ret = 0;
- struct neuronspi_do_driver *n_do;
+ struct neuronspi_gpio_driver *n_do;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_do = platform_get_drvdata(plat);
n_spi = spi_get_drvdata(n_do->spi);
if (n_spi->features && n_spi->features->do_count > 0 && n_spi->do_driver) {
- ret = scnprintf(buf, 255, "%s_%d\n", n_spi->do_driver[n_do->do_index]->gpio_c.label, n_spi->neuron_index + 1);
+ ret = scnprintf(buf, 255, "%s_%d\n", n_spi->do_driver[n_do->io_index].gpio_c.label, n_spi->neuron_index + 1);
}
return ret;
}
static ssize_t neuronspi_spi_gpio_show_di_prefix(struct device *dev, struct device_attribute *attr, char *buf)
{
ssize_t ret = 0;
- struct neuronspi_di_driver *n_di;
+ struct neuronspi_gpio_driver *n_di;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_di = platform_get_drvdata(plat);
n_spi = spi_get_drvdata(n_di->spi);
if (n_spi->features && n_spi->features->di_count > 0 && n_spi->di_driver) {
- ret = scnprintf(buf, 255, "%s_%d\n", n_spi->di_driver[n_di->di_index]->gpio_c.label, n_spi->neuron_index + 1);
+ ret = scnprintf(buf, 255, "%s_%d\n", n_spi->di_driver[n_di->io_index].gpio_c.label, n_spi->neuron_index + 1);
}
return ret;
}
static ssize_t neuronspi_spi_gpio_show_ro_prefix(struct device *dev, struct device_attribute *attr, char *buf)
{
ssize_t ret = 0;
- struct neuronspi_ro_driver *n_ro;
+ struct neuronspi_gpio_driver *n_ro;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_ro = platform_get_drvdata(plat);
n_spi = spi_get_drvdata(n_ro->spi);
if (n_spi->features && n_spi->features->ro_count > 0 && n_spi->ro_driver) {
- ret = scnprintf(buf, 255, "%s_%d\n", n_spi->ro_driver[n_ro->ro_index]->gpio_c.label, n_spi->neuron_index + 1);
+ ret = scnprintf(buf, 255, "%s_%d\n", n_spi->ro_driver[n_ro->io_index].gpio_c.label, n_spi->neuron_index + 1);
}
return ret;
}
static ssize_t neuronspi_spi_gpio_show_do_base(struct device *dev, struct device_attribute *attr, char *buf)
{
ssize_t ret = 0;
- struct neuronspi_do_driver *n_do;
+ struct neuronspi_gpio_driver *n_do;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_do = platform_get_drvdata(plat);
n_spi = spi_get_drvdata(n_do->spi);
if (n_spi->features && n_spi->features->do_count > 0 && n_spi->do_driver) {
- ret = scnprintf(buf, 255, "%d\n", n_spi->do_driver[n_do->do_index]->gpio_c.base);
+ ret = scnprintf(buf, 255, "%d\n", n_spi->do_driver[n_do->io_index].gpio_c.base);
}
return ret;
}
static ssize_t neuronspi_spi_gpio_show_di_base(struct device *dev, struct device_attribute *attr, char *buf)
{
ssize_t ret = 0;
- struct neuronspi_di_driver *n_di;
+ struct neuronspi_gpio_driver *n_di;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_di = platform_get_drvdata(plat);
n_spi = spi_get_drvdata(n_di->spi);
if (n_spi->features && n_spi->features->di_count > 0 && n_spi->di_driver) {
- ret = scnprintf(buf, 255, "%d\n", n_spi->di_driver[n_di->di_index]->gpio_c.base);
+ ret = scnprintf(buf, 255, "%d\n", n_spi->di_driver[n_di->io_index].gpio_c.base);
}
return ret;
}
static ssize_t neuronspi_spi_gpio_show_ro_base(struct device *dev, struct device_attribute *attr, char *buf)
{
ssize_t ret = 0;
- struct neuronspi_ro_driver *n_ro;
+ struct neuronspi_gpio_driver *n_ro;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_ro = platform_get_drvdata(plat);
n_spi = spi_get_drvdata(n_ro->spi);
if (n_spi->features && n_spi->features->ro_count > 0 && n_spi->ro_driver) {
- ret = scnprintf(buf, 255, "%d\n", n_spi->ro_driver[n_ro->ro_index]->gpio_c.base);
+ ret = scnprintf(buf, 255, "%d\n", n_spi->ro_driver[n_ro->io_index].gpio_c.base);
}
return ret;
}
static ssize_t neuronspi_spi_gpio_show_do_count(struct device *dev, struct device_attribute *attr, char *buf)
{
ssize_t ret = 0;
- struct neuronspi_do_driver *n_do;
+ struct neuronspi_gpio_driver *n_do;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_do = platform_get_drvdata(plat);
n_spi = spi_get_drvdata(n_do->spi);
if (n_spi->features && n_spi->features->do_count > 0 && n_spi->do_driver) {
- ret = scnprintf(buf, 255, "%d\n", n_spi->do_driver[n_do->do_index]->gpio_c.ngpio);
+ ret = scnprintf(buf, 255, "%d\n", n_spi->do_driver[n_do->io_index].gpio_c.ngpio);
}
return ret;
}
static ssize_t neuronspi_spi_gpio_show_di_count(struct device *dev, struct device_attribute *attr, char *buf)
{
ssize_t ret = 0;
- struct neuronspi_di_driver *n_di;
+ struct neuronspi_gpio_driver *n_di;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_di = platform_get_drvdata(plat);
n_spi = spi_get_drvdata(n_di->spi);
if (n_spi->features && n_spi->features->di_count > 0 && n_spi->di_driver) {
- ret = scnprintf(buf, 255, "%d\n", n_spi->di_driver[n_di->di_index]->gpio_c.ngpio);
+ ret = scnprintf(buf, 255, "%d\n", n_spi->di_driver[n_di->io_index].gpio_c.ngpio);
}
return ret;
}
static ssize_t neuronspi_spi_gpio_show_ro_count(struct device *dev, struct device_attribute *attr, char *buf)
{
ssize_t ret = 0;
- struct neuronspi_ro_driver *n_ro;
+ struct neuronspi_gpio_driver *n_ro;
struct neuronspi_driver_data *n_spi;
struct platform_device *plat = to_platform_device(dev);
n_ro = platform_get_drvdata(plat);
n_spi = spi_get_drvdata(n_ro->spi);
if (n_spi->features && n_spi->features->ro_count > 0 && n_spi->ro_driver) {
- ret = scnprintf(buf, 255, "%d\n", n_spi->ro_driver[n_ro->ro_index]->gpio_c.ngpio);
+ ret = scnprintf(buf, 255, "%d\n", n_spi->ro_driver[n_ro->io_index].gpio_c.ngpio);
}
return ret;
}
return ret;
}
-/*
-void neuronspi_uart_fifo_write(struct neuronspi_port *n_port, u8 to_send)
-{
- int in_queue, need;
-
- unipi_uart_trace("FIFO Write to_send:%d %16ph\n", to_send, n_port->tx_buf);
- //unipi_uart_trace_2(KERN_INFO "FIFO Write to_send:%d %16ph\n", to_send, n_port->tx_buf);
-
- do {
- in_queue = neuronspi_uart_get_charcount(n_port);
- need = (int)to_send - (NEURONSPI_FIFO_SIZE - in_queue);
- if (need <= 0) break;
- usleep_range(need * n_port->one_char_usec, (need + NEURONSPI_FIFO_SIZE/4) * n_port->one_char_usec);
- } while(1);
- neuronspi_spi_uart_write(neuronspi_s_dev[n_port->dev_index], n_port->tx_buf, to_send, n_port->dev_port);
-}
-*/
-
-/*
-s32 neuronspi_uart_alloc_line(void)
-{
- s32 i;
- BUILD_BUG_ON(NEURONSPI_MAX_DEVS > BITS_PER_LONG);
-
- for (i = 0; i < NEURONSPI_MAX_DEVS; i++)
- if (!test_and_set_bit(i, &neuronspi_lines))
- break;
-
- return i;
-}
-*/
void neuronspi_rx_queue_clear(struct neuronspi_port *port, u8 data)
{
ret = neuronspi_uart_read_tx_fifo_len(port);
if (ret || port->tx_fifo_len) {
// set timer to check tx_empty
- unipi_uart_trace("ttyNS%d Handle TX. Start timer=%llu", port->port.line, port->tx_fifo_len * port->one_char_nsec);
+ unipi_uart_trace_1("ttyNS%d Handle TX. Start timer=%llu", port->port.line, port->tx_fifo_len * port->one_char_nsec);
start_tx_timer(port, port->tx_fifo_len, 2);
//hrtimer_start_range_ns(&port->tx_timer, port->tx_fifo_len * port->one_char_nsec, 2*port->one_char_nsec, HRTIMER_MODE_REL);
}
kthread_queue_work(&neuronspi_uart_data_global->kworker, &port->tx_work);
} else {
// set timer to check tx_empty
- unipi_uart_trace("ttyNS%d Handle TX. Start timer=%llu", port->port.line, to_send_packet * port->one_char_nsec);
+ unipi_uart_trace_1("ttyNS%d Handle TX. Start timer=%llu", port->port.line, to_send_packet * port->one_char_nsec);
start_tx_timer(port, to_send_packet, 2);
//hrtimer_start_range_ns(&port->tx_timer, to_send_packet * port->one_char_nsec, 2*port->one_char_nsec, HRTIMER_MODE_REL);
}
}
ret = neuronspi_uart_probe(spi, n_spi);
- if (ret) break;
+ if (ret) break; // max number of uarts reached
}
return ret;
}