[svn-commits] rmeyerriecks: linux/trunk r9997 - in /linux/trunk/drivers/dahdi: firmware/ vo...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Jun 28 17:28:58 CDT 2011


Author: rmeyerriecks
Date: Tue Jun 28 17:28:53 2011
New Revision: 9997

URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=9997
Log:
wcte12xp, wctdm24xxp: Add support for the VPMOCT032 hardware echocanceler.

Support enabled for the vpmoct032 echo cancellation module for the wctdm24xxp
and wcte12xp drivers.

Signed-off-by: Russ Meyerriecks <rmeyerriecks at digium.com>
Signed-off-by: Shaun Ruffell <sruffell at digium.com>

Added:
    linux/trunk/drivers/dahdi/voicebus/vpmoct.c   (with props)
    linux/trunk/drivers/dahdi/voicebus/vpmoct.h   (with props)
Modified:
    linux/trunk/drivers/dahdi/firmware/Makefile
    linux/trunk/drivers/dahdi/voicebus/Kbuild
    linux/trunk/drivers/dahdi/wctdm24xxp/base.c
    linux/trunk/drivers/dahdi/wctdm24xxp/wctdm24xxp.h
    linux/trunk/drivers/dahdi/wcte12xp/base.c
    linux/trunk/drivers/dahdi/wcte12xp/wcte12xp.h

Modified: linux/trunk/drivers/dahdi/firmware/Makefile
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/firmware/Makefile?view=diff&rev=9997&r1=9996&r2=9997
==============================================================================
--- linux/trunk/drivers/dahdi/firmware/Makefile (original)
+++ linux/trunk/drivers/dahdi/firmware/Makefile Tue Jun 28 17:28:53 2011
@@ -27,10 +27,11 @@
 TC400M_VERSION:=MR6.12
 VPMADT032_VERSION:=1.25.0
 HX8_VERSION:=2.06
+VPMOCT032_VERSION:=1.8.0
 
 FIRMWARE_URL:=http://downloads.digium.com/pub/telephony/firmware/releases
 
-ALL_FIRMWARE=FIRMWARE-OCT6114-064 FIRMWARE-OCT6114-128 FIRMWARE-TC400M FIRMWARE-HX8
+ALL_FIRMWARE=FIRMWARE-OCT6114-064 FIRMWARE-OCT6114-128 FIRMWARE-TC400M FIRMWARE-HX8 FIRMWARE-VPMOCT032
 
 # Firmware files should use the naming convention: dahdi-fw-<base name>-<sub name>-<version> or dahdi-fw-<base name>-<version>
 # First example: dahdi-fw-oct6114-064-1.05.01
@@ -43,6 +44,7 @@
 FIRMWARE:=$(FIRMWARE:FIRMWARE-OCT6114-128=dahdi-fw-oct6114-128-$(OCT6114_128_VERSION).tar.gz)
 FIRMWARE:=$(FIRMWARE:FIRMWARE-TC400M=dahdi-fw-tc400m-$(TC400M_VERSION).tar.gz)
 FIRMWARE:=$(FIRMWARE:FIRMWARE-HX8=dahdi-fw-hx8-$(HX8_VERSION).tar.gz)
+FIRMWARE:=$(FIRMWARE:FIRMWARE-VPMOCT032=dahdi-fw-vpmoct032-$(VPMOCT032_VERSION).tar.gz)
 
 FWLOADERS:=dahdi-fwload-vpmadt032-$(VPMADT032_VERSION).tar.gz
 
@@ -143,6 +145,17 @@
 else
 	@echo "Firmware dahdi-fw-hx8.bin is already installed with required version $(HX8_VERSION)"
 endif
+ifeq ($(shell if ( [ -f $(DESTDIR)/usr/lib/hotplug/firmware/.dahdi-fw-vpmoct032-$(VPMOCT032_VERSION) ] ) && ( [ -f $(DESTDIR)/lib/firmware/.dahdi-fw-vpmoct032-$(VPMOCT032_VERSION) ] ); then echo "no"; else echo "yes"; fi),yes)
+	@echo "Installing dahdi-fw-vpmoct032.bin to hotplug firmware directories"
+	@install -m 644 dahdi-fw-vpmoct032.bin $(DESTDIR)/usr/lib/hotplug/firmware
+	@rm -rf $(DESTDIR)/usr/lib/hotplug/firmware/.dahdi-fw-vpmoct032-*
+	@touch $(DESTDIR)/usr/lib/hotplug/firmware/.dahdi-fw-vpmoct032-$(VPMOCT032_VERSION)
+	@install -m 644 dahdi-fw-vpmoct032.bin $(DESTDIR)/lib/firmware
+	@rm -rf $(DESTDIR)/lib/firmware/.dahdi-fw-vpmoct032-*
+	@touch $(DESTDIR)/lib/firmware/.dahdi-fw-vpmoct032-$(VPMOCT032_VERSION)
+else
+	@echo "Firmware dahdi-fw-vpmoct032.bin is already installed with required version $(VPMOCT032_VERSION)"
+endif
 
 # Uninstall any installed dahdi firmware images from hotplug firmware directories
 hotplug-uninstall:

Modified: linux/trunk/drivers/dahdi/voicebus/Kbuild
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/voicebus/Kbuild?view=diff&rev=9997&r1=9996&r2=9997
==============================================================================
--- linux/trunk/drivers/dahdi/voicebus/Kbuild (original)
+++ linux/trunk/drivers/dahdi/voicebus/Kbuild Tue Jun 28 17:28:53 2011
@@ -1,5 +1,5 @@
 obj-$(DAHDI_BUILD_ALL)$(CONFIG_DAHDI_VOICEBUS) += dahdi_voicebus.o
 
-dahdi_voicebus-objs := voicebus.o GpakCust.o GpakApi.o voicebus_net.o
+dahdi_voicebus-objs := voicebus.o GpakCust.o GpakApi.o voicebus_net.o vpmoct.o
 
 EXTRA_CFLAGS := -I$(src)/.. -Wno-undef

Added: linux/trunk/drivers/dahdi/voicebus/vpmoct.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/voicebus/vpmoct.c?view=auto&rev=9997
==============================================================================
--- linux/trunk/drivers/dahdi/voicebus/vpmoct.c (added)
+++ linux/trunk/drivers/dahdi/voicebus/vpmoct.c Tue Jun 28 17:28:53 2011
@@ -1,0 +1,649 @@
+/*
+ * VPMOCT Driver.
+ *
+ * Written by Russ Meyerriecks <rmeyerriecks at digium.com>
+ *
+ * Copyright (C) 2010-2011 Digium, Inc.
+ *
+ * All rights reserved.
+ *
+ */
+
+/*
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2 as published by the
+ * Free Software Foundation. See the LICENSE file included with
+ * this program for more details.
+ */
+
+#include <linux/jiffies.h>
+#include <linux/sched.h>
+#include <linux/crc32.h>
+
+#include "voicebus/vpmoct.h"
+#include "linux/firmware.h"
+
+struct vpmoct_header {
+	u8	header[6];
+	__le32	chksum;
+	u8	pad[20];
+	u8	major;
+	u8	minor;
+} __packed;
+
+static int _vpmoct_read(struct vpmoct *vpm, u8 address,
+			void *data, size_t size,
+			u8 *new_command, u8 *new_address)
+{
+	struct vpmoct_cmd *cmd;
+	unsigned long flags;
+
+	if (unlikely(size >= ARRAY_SIZE(cmd->data))) {
+		memset(data, -1, size);
+		return -1;
+	}
+
+	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+	if (!cmd) {
+		dev_info(vpm->dev, "Unable to allocate memory for vpmoct_cmd\n");
+		return 0;
+	}
+
+	init_completion(&cmd->complete);
+
+	cmd->command = 0x60 + size;
+	cmd->address = address;
+	cmd->chunksize = size;
+
+	spin_lock_irqsave(&vpm->list_lock, flags);
+	list_add_tail(&cmd->node, &vpm->pending_list);
+	spin_unlock_irqrestore(&vpm->list_lock, flags);
+
+	/* Wait for receiveprep to process our result */
+	if (!wait_for_completion_timeout(&cmd->complete, HZ/5)) {
+		spin_lock_irqsave(&vpm->list_lock, flags);
+		list_del(&cmd->node);
+		spin_unlock_irqrestore(&vpm->list_lock, flags);
+		kfree(cmd);
+		dev_err(vpm->dev, "vpmoct_read_byte cmd timed out :O(\n");
+		return 0;
+	}
+
+	memcpy(data, &cmd->data[0], size);
+
+	if (new_command)
+		*new_command = cmd->command;
+	if (new_address)
+		*new_address = cmd->address;
+
+	kfree(cmd);
+	return 0;
+}
+
+static u8 vpmoct_read_byte(struct vpmoct *vpm, u8 address)
+{
+	u8 val;
+	_vpmoct_read(vpm, address, &val, sizeof(val), NULL, NULL);
+	return val;
+}
+
+static u32 vpmoct_read_dword(struct vpmoct *vpm, u8 address)
+{
+	__le32 val;
+	_vpmoct_read(vpm, address, &val, sizeof(val), NULL, NULL);
+	return le32_to_cpu(val);
+}
+
+static void vpmoct_write_byte(struct vpmoct *vpm, u8 address, u8 data)
+{
+	struct vpmoct_cmd *cmd;
+	unsigned long flags;
+
+	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+	if (!cmd) {
+		dev_info(vpm->dev, "Unable to allocate memory for vpmoct_cmd\n");
+		return;
+	}
+
+	cmd->command = 0x21;
+	cmd->address = address;
+	cmd->data[0] = data;
+	cmd->chunksize = 1;
+
+	spin_lock_irqsave(&vpm->list_lock, flags);
+	list_add_tail(&cmd->node, &vpm->pending_list);
+	spin_unlock_irqrestore(&vpm->list_lock, flags);
+}
+
+static void vpmoct_write_dword(struct vpmoct *vpm, u8 address, u32 data)
+{
+	struct vpmoct_cmd *cmd;
+	unsigned long flags;
+
+	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+	if (!cmd) {
+		dev_info(vpm->dev, "Unable to allocate memory for vpmoct_cmd\n");
+		return;
+	}
+
+	cmd->command = 0x20 + sizeof(data);
+	cmd->address = address;
+	*(__le32 *)(&cmd->data[0]) = cpu_to_le32(data);
+	cmd->chunksize = sizeof(data);
+
+	spin_lock_irqsave(&vpm->list_lock, flags);
+	list_add_tail(&cmd->node, &vpm->pending_list);
+	spin_unlock_irqrestore(&vpm->list_lock, flags);
+}
+
+static void vpmoct_write_chunk(struct vpmoct *vpm, u8 address,
+			       const u8 *data, u8 chunksize)
+{
+	struct vpmoct_cmd *cmd;
+	unsigned long flags;
+
+	if (unlikely(chunksize > ARRAY_SIZE(cmd->data)))
+		return;
+
+	cmd = kzalloc(sizeof(*cmd), GFP_ATOMIC);
+	if (unlikely(!cmd)) {
+		dev_info(vpm->dev, "Unable to allocate memory for vpmoct_cmd\n");
+		return;
+	}
+
+	cmd->command = 0x20 + chunksize;
+	cmd->address = address;
+	cmd->chunksize = chunksize;
+
+	memcpy(cmd->data, data, chunksize);
+
+	spin_lock_irqsave(&vpm->list_lock, flags);
+	list_add_tail(&cmd->node, &vpm->pending_list);
+	spin_unlock_irqrestore(&vpm->list_lock, flags);
+}
+
+static u8 vpmoct_resync(struct vpmoct *vpm)
+{
+	unsigned long time;
+	u8 status = 0xff;
+	u8 address;
+	u8 command;
+
+	/* Poll the status register until it returns valid values
+	 * This is because we have to wait on the bootloader to do
+	 * its thing.
+	 * Timeout after 3 seconds
+	 */
+	time = jiffies + 3*HZ;
+	while (time_after(time, jiffies) && (0xff == status)) {
+		status = _vpmoct_read(vpm, VPMOCT_BOOT_STATUS, &status,
+				      sizeof(status), &command, &address);
+
+		/* Throw out invalid statuses */
+		if ((0x55 != command) || (0xaa != address))
+			status = 0xff;
+	}
+
+	if ((status != 0xff) && status)
+		dev_info(vpm->dev, "Resync with status %x\n", status);
+
+	return status;
+}
+
+static inline short vpmoct_erase_flash(struct vpmoct *vpm)
+{
+	short res;
+	vpmoct_write_byte(vpm, VPMOCT_BOOT_CMD, VPMOCT_BOOT_FLASH_ERASE);
+	res = vpmoct_resync(vpm);
+	if (res)
+		dev_info(vpm->dev, "Unable to erase flash\n");
+	return res;
+}
+
+static inline short
+vpmoct_send_firmware_header(struct vpmoct *vpm, const struct firmware *fw)
+{
+	unsigned short i;
+	short res;
+
+	/* Send the encrypted firmware header */
+	for (i = 0; i < VPMOCT_FIRM_HEADER_LEN; i++) {
+		vpmoct_write_byte(vpm, VPMOCT_BOOT_RAM+i,
+				  fw->data[i + sizeof(struct vpmoct_header)]);
+	}
+	/* Decrypt header */
+	vpmoct_write_byte(vpm, VPMOCT_BOOT_CMD, VPMOCT_BOOT_DECRYPT);
+	res = vpmoct_resync(vpm);
+	if (res)
+		dev_info(vpm->dev, "Unable to send firmware header\n");
+	return res;
+}
+
+static inline short
+vpmoct_send_firmware_body(struct vpmoct *vpm, const struct firmware *fw)
+{
+	unsigned int i, ram_index, flash_index, flash_address;
+	const u8 *buf;
+	u8 chunksize;
+
+	/* Load the body of the firmware */
+	ram_index = 0;
+	flash_index = 0;
+	flash_address = 0;
+	for (i = VPMOCT_FIRM_HEADER_LEN*2; i < fw->size;) {
+		if (ram_index >= VPMOCT_BOOT_RAM_LEN) {
+			/* Tell bootloader to load ram buffer into buffer */
+			vpmoct_write_byte(vpm, VPMOCT_BOOT_CMD,
+					  0x10 + flash_index);
+			/* Assuming the memory load doesn't take longer than 1
+			 * eframe just insert a blank eframe before continuing
+			 * the firmware load */
+			vpmoct_read_byte(vpm, VPMOCT_BOOT_STATUS);
+			ram_index = 0;
+			flash_index++;
+		}
+		if (flash_index >= VPMOCT_FLASH_BUF_SECTIONS) {
+			/* Tell the bootloader the memory address for load */
+			vpmoct_write_dword(vpm, VPMOCT_BOOT_ADDRESS1,
+					   flash_address);
+			/* Tell the bootloader to load from flash buffer */
+			vpmoct_write_byte(vpm, VPMOCT_BOOT_CMD,
+					  VPMOCT_BOOT_FLASH_COPY);
+			if (vpmoct_resync(vpm))
+				goto error;
+			flash_index = 0;
+			flash_address = i-VPMOCT_FIRM_HEADER_LEN*2;
+		}
+		/* Try to buffer for batch writes if possible */
+		chunksize = VPMOCT_BOOT_RAM_LEN - ram_index;
+		if (chunksize > VPMOCT_MAX_CHUNK)
+			chunksize = VPMOCT_MAX_CHUNK;
+
+		buf = &fw->data[i];
+		vpmoct_write_chunk(vpm, VPMOCT_BOOT_RAM+ram_index,
+				   buf, chunksize);
+		ram_index += chunksize;
+		i += chunksize;
+	}
+
+	/* Flush remaining ram buffer to flash buffer */
+	vpmoct_write_byte(vpm, VPMOCT_BOOT_CMD,
+			  VPMOCT_BOOT_FLASHLOAD + flash_index);
+	if (vpmoct_resync(vpm))
+		goto error;
+	/* Tell boot loader the memory address to flash load */
+	vpmoct_write_dword(vpm, VPMOCT_BOOT_ADDRESS1, flash_address);
+	/* Tell the bootloader to load flash from flash buffer */
+	vpmoct_write_byte(vpm, VPMOCT_BOOT_CMD, VPMOCT_BOOT_FLASH_COPY);
+	if (vpmoct_resync(vpm))
+		goto error;
+
+	return 0;
+
+error:
+	dev_info(vpm->dev, "Unable to load firmware body\n");
+	return -1;
+}
+
+static inline short
+vpmoct_check_firmware_crc(struct vpmoct *vpm, size_t size, u8 major, u8 minor)
+{
+	u8 status;
+
+	/* Load firmware size */
+	vpmoct_write_dword(vpm, VPMOCT_BOOT_RAM, size);
+
+	/* Load firmware version */
+	vpmoct_write_byte(vpm, VPMOCT_BOOT_RAM+8, major);
+	vpmoct_write_byte(vpm, VPMOCT_BOOT_RAM+9, minor);
+
+	/* Validate the firmware load */
+	vpmoct_write_byte(vpm, VPMOCT_BOOT_CMD, VPMOCT_BOOT_IMAGE_VALIDATE);
+
+	status = vpmoct_resync(vpm);
+	if (status) {
+		dev_info(vpm->dev,
+			 "vpmoct firmware CRC check failed: %x\n", status);
+		/* TODO: Try the load again */
+		return -1;
+	} else {
+		dev_info(vpm->dev, "vpmoct firmware uploaded successfully\n");
+		/* Switch to application code */
+		vpmoct_write_dword(vpm, VPMOCT_BOOT_ADDRESS2, 0xDEADBEEF);
+		/* Soft reset the processor */
+		vpmoct_write_byte(vpm, VPMOCT_BOOT_CMD, VPMOCT_BOOT_REBOOT);
+		return 0;
+	}
+}
+
+static inline short vpmoct_switch_to_boot(struct vpmoct *vpm)
+{
+	vpmoct_write_dword(vpm, 0x74, 0x00009876);
+	vpmoct_write_byte(vpm, 0x71, 0x02);
+	if (vpmoct_resync(vpm)) {
+		dev_info(vpm->dev, "Failed to switch to bootloader\n");
+		return -1;
+	}
+	vpm->mode = VPMOCT_MODE_BOOTLOADER;
+	return 0;
+}
+
+static bool is_valid_vpmoct_firmware(const struct firmware *fw)
+{
+	const struct vpmoct_header *header =
+			(const struct vpmoct_header *)fw->data;
+	u32 crc = crc32(~0, &fw->data[10], fw->size - 10) ^ ~0;
+	return (!memcmp("DIGIUM", header->header, sizeof(header->header)) &&
+		 (le32_to_cpu(header->chksum) == crc));
+}
+
+static void vpmoct_set_defaults(struct vpmoct *vpm)
+{
+	vpmoct_write_dword(vpm, 0x40, 0);
+	vpmoct_write_dword(vpm, 0x30, 0);
+}
+
+/**
+ * vpmoct_load_flash - Check the current flash version and possibly load.
+ * @vpm:  The VPMOCT032 module to check / load.
+ *
+ * Returns 0 on success, otherwise an error message.
+ *
+ * Must be called in process context.
+ *
+ */
+static int vpmoct_load_flash(struct vpmoct *vpm)
+{
+	int firm;
+	const struct firmware *fw;
+	const struct vpmoct_header *header;
+	char serial[VPMOCT_SERIAL_SIZE+1];
+	const char *const FIRMWARE_NAME = "dahdi-fw-vpmoct032.bin";
+	int i;
+
+	/* Load the firmware */
+	firm = request_firmware(&fw, FIRMWARE_NAME, vpm->dev);
+	if (firm) {
+		dev_info(vpm->dev, "vpmoct: Failed to load firmware from"\
+				" userspace!, %d\n", firm);
+		return -ENOMEM;
+	}
+
+	if (!is_valid_vpmoct_firmware(fw)) {
+		dev_warn(vpm->dev,
+			 "%s is invalid. Please reinstall.\n", FIRMWARE_NAME);
+		release_firmware(fw);
+		return -EINVAL;
+	}
+
+	header = (const struct vpmoct_header *)fw->data;
+
+	if (vpm->mode == VPMOCT_MODE_APPLICATION) {
+		/* Check the running application firmware
+		 * for the proper version */
+		vpm->major = vpmoct_read_byte(vpm, VPMOCT_MAJOR);
+		vpm->minor = vpmoct_read_byte(vpm, VPMOCT_MINOR);
+		for (i = 0; i < VPMOCT_SERIAL_SIZE; i++)
+			serial[i] = vpmoct_read_byte(vpm, VPMOCT_SERIAL+i);
+		serial[VPMOCT_SERIAL_SIZE] = '\0';
+
+		dev_info(vpm->dev, "vpmoct: Detected firmware v%d.%d\n",
+				vpm->major, vpm->minor);
+		dev_info(vpm->dev, "vpmoct: Serial %s\n", serial);
+
+		if (vpm->minor == header->minor &&
+		    vpm->major == header->major) {
+			/* Proper version is running */
+			release_firmware(fw);
+			vpmoct_set_defaults(vpm);
+			return 0;
+		} else {
+
+			/* Incorrect version of application code is
+			 * loaded. Reset to bootloader mode */
+			if (vpmoct_switch_to_boot(vpm))
+				goto error;
+		}
+	}
+
+	dev_info(vpm->dev, "vpmoct: Uploading firmware, v%d.%d. This can "\
+			"take up to 1 minute\n",
+			header->major, header->minor);
+	if (vpmoct_erase_flash(vpm))
+		goto error;
+	if (vpmoct_send_firmware_header(vpm, fw))
+		goto error;
+	if (vpmoct_send_firmware_body(vpm, fw))
+		goto error;
+	if (vpmoct_check_firmware_crc(vpm, fw->size-VPMOCT_FIRM_HEADER_LEN*2,
+					header->major, header->minor))
+		goto error;
+	release_firmware(fw);
+	vpmoct_set_defaults(vpm);
+	return 0;
+
+error:
+	dev_info(vpm->dev, "Unable to load firmware\n");
+	release_firmware(fw);
+	return -1;
+}
+
+struct vpmoct *vpmoct_alloc(void)
+{
+	struct vpmoct *vpm;
+
+	vpm = kzalloc(sizeof(*vpm), GFP_KERNEL);
+	if (!vpm)
+		return NULL;
+
+	spin_lock_init(&vpm->list_lock);
+	INIT_LIST_HEAD(&vpm->pending_list);
+	INIT_LIST_HEAD(&vpm->active_list);
+	mutex_init(&vpm->mutex);
+	return vpm;
+}
+EXPORT_SYMBOL(vpmoct_alloc);
+
+void vpmoct_free(struct vpmoct *vpm)
+{
+	kfree(vpm);
+}
+EXPORT_SYMBOL(vpmoct_free);
+
+/**
+ * vpmoct_init - Check for / initialize VPMOCT032 module.
+ * @vpm:	struct vpmoct allocated with vpmoct_alloc
+ *
+ * Returns 0 on success or an error code.
+ *
+ * Must be called in process context.
+ */
+int vpmoct_init(struct vpmoct *vpm)
+{
+	unsigned int i;
+	char identifier[10];
+
+	if (vpmoct_resync(vpm))
+		return -ENODEV;
+
+	/* Probe for vpmoct ident string */
+	for (i = 0; i < ARRAY_SIZE(identifier); i++)
+		identifier[i] = vpmoct_read_byte(vpm, VPMOCT_IDENT+i);
+
+	if (!memcmp(identifier, "bootloader", sizeof(identifier))) {
+		/* vpmoct is in bootloader mode */
+		dev_info(vpm->dev, "Detected vpmoct bootloader, attempting "\
+				"to load firmware\n");
+		vpm->mode = VPMOCT_MODE_BOOTLOADER;
+		return vpmoct_load_flash(vpm);
+	} else if (!memcmp(identifier, "VPMOCT032\0", sizeof(identifier))) {
+		/* vpmoct is in application mode */
+		vpm->mode = VPMOCT_MODE_APPLICATION;
+		return vpmoct_load_flash(vpm);
+	} else {
+		/* No vpmoct is installed */
+		return -ENODEV;
+	}
+}
+EXPORT_SYMBOL(vpmoct_init);
+
+static void
+vpmoct_set_companding(struct vpmoct *vpm, int channo, int companding)
+{
+	u32 new_companding;
+	bool do_update = false;
+
+	mutex_lock(&vpm->mutex);
+	new_companding = (DAHDI_LAW_MULAW == companding) ?
+				(vpm->companding & ~(1 << channo)) :
+				(vpm->companding |  (1 << channo));
+	if (vpm->companding != new_companding) {
+		vpm->companding = new_companding;
+		if (!vpm->companding_update_active) {
+			do_update = true;
+			vpm->companding_update_active = 1;
+		}
+	}
+	mutex_unlock(&vpm->mutex);
+
+	while (do_update) {
+		u32 update;
+
+		vpmoct_write_dword(vpm, 0x40, new_companding);
+		update = vpmoct_read_dword(vpm, 0x40);
+
+		WARN_ON(new_companding != update);
+
+		mutex_lock(&vpm->mutex);
+		if (vpm->companding != new_companding) {
+			new_companding = vpm->companding;
+		} else {
+			vpm->companding_update_active = 0;
+			do_update = false;
+		}
+		mutex_unlock(&vpm->mutex);
+	}
+}
+
+/**
+ * vpmoct_echo_update - Enable / Disable the VPMOCT032 echocan state
+ * @vpm:	The echocan to operate on.
+ * @channo:	Which echocan timeslot to enable / disable.
+ * @echo_on:	Whether we're turning the echocan on or off.
+ *
+ * When this function returns, the echocan is scheduled to be enabled or
+ * disabled at some point in the near future.
+ *
+ * Must be called in process context.
+ *
+ */
+static void vpmoct_echo_update(struct vpmoct *vpm, int channo, bool echo_on)
+{
+	u32 echo;
+	unsigned long timeout;
+	bool do_update = false;
+
+	mutex_lock(&vpm->mutex);
+	echo = (echo_on) ? (vpm->echo | (1 << channo)) :
+			   (vpm->echo & ~(1 << channo));
+	if (vpm->echo != echo) {
+		vpm->echo = echo;
+		if (!vpm->echo_update_active) {
+			do_update = true;
+			vpm->echo_update_active = 1;
+		}
+	}
+	mutex_unlock(&vpm->mutex);
+
+	timeout = jiffies + 2*HZ;
+	while (do_update) {
+		u32 new;
+
+		vpmoct_write_dword(vpm, 0x30, echo);
+		new = vpmoct_read_dword(vpm, 0x10);
+
+		mutex_lock(&vpm->mutex);
+		if (((vpm->echo != echo) || (new != echo)) &&
+		    time_before(jiffies, timeout)) {
+			echo = vpm->echo;
+		} else {
+			vpm->echo_update_active = 0;
+			do_update = false;
+		}
+		mutex_unlock(&vpm->mutex);
+	}
+
+	if (!time_before(jiffies, timeout))
+		dev_warn(vpm->dev, "vpmoct: Updating echo state timed out.\n");
+}
+
+int vpmoct_echocan_create(struct vpmoct *vpm, int channo, int companding)
+{
+	vpmoct_set_companding(vpm, channo, companding);
+	vpmoct_echo_update(vpm, channo, true);
+	return 0;
+}
+EXPORT_SYMBOL(vpmoct_echocan_create);
+
+void vpmoct_echocan_free(struct vpmoct *vpm, int channo)
+{
+	vpmoct_echo_update(vpm, channo, false);
+}
+EXPORT_SYMBOL(vpmoct_echocan_free);
+
+/* Enable a vpm debugging mode where the pre-echo-canceled audio
+ * stream is physically output on timeslot 24.
+ */
+int vpmoct_preecho_enable(struct vpmoct *vpm, const int channo)
+{
+	int ret;
+	mutex_lock(&vpm->mutex);
+	if (!vpm->preecho_enabled) {
+		vpm->preecho_enabled = 1;
+		vpm->preecho_timeslot = channo;
+
+		vpmoct_write_dword(vpm, 0x74, channo);
+
+		/* Begin pre-echo stream on timeslot 24 */
+		vpmoct_write_byte(vpm, 0x71, 0x0a);
+		ret = 0;
+	} else {
+		ret = -EBUSY;
+	}
+	mutex_unlock(&vpm->mutex);
+
+	return ret;
+}
+EXPORT_SYMBOL(vpmoct_preecho_enable);
+
+int vpmoct_preecho_disable(struct vpmoct *vpm, const int channo)
+{
+	int ret;
+
+	mutex_lock(&vpm->mutex);
+	if (!vpm->preecho_enabled) {
+		ret = 0;
+	} else if (channo == vpm->preecho_timeslot) {
+		vpm->preecho_enabled = 0;
+
+		/* Disable pre-echo stream by loading in a non-existing
+		 * channel number */
+		vpmoct_write_byte(vpm, 0x74, 0xff);
+
+		/* Stop pre-echo stream on timeslot 24 */
+		vpmoct_write_byte(vpm, 0x71, 0x0a);
+		ret = 0;
+	} else {
+		ret = -EINVAL;
+	}
+	mutex_unlock(&vpm->mutex);
+
+	return ret;
+}
+EXPORT_SYMBOL(vpmoct_preecho_disable);

Propchange: linux/trunk/drivers/dahdi/voicebus/vpmoct.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: linux/trunk/drivers/dahdi/voicebus/vpmoct.c
------------------------------------------------------------------------------
    svn:keywords = 'Author Date Id Revision'

Propchange: linux/trunk/drivers/dahdi/voicebus/vpmoct.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: linux/trunk/drivers/dahdi/voicebus/vpmoct.h
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/voicebus/vpmoct.h?view=auto&rev=9997
==============================================================================
--- linux/trunk/drivers/dahdi/voicebus/vpmoct.h (added)
+++ linux/trunk/drivers/dahdi/voicebus/vpmoct.h Tue Jun 28 17:28:53 2011
@@ -1,0 +1,110 @@
+/*
+ * VPMOCT Driver.
+ *
+ * Written by Russ Meyerriecks <rmeyerriecks at digium.com>
+ *
+ * Copyright (C) 2010-2011 Digium, Inc.
+ *
+ * All rights reserved.
+ *
+ */
+
+/*
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2 as published by the
+ * Free Software Foundation. See the LICENSE file included with
+ * this program for more details.
+ */
+
+#ifndef _VPMOCT_H
+#define _VPMOCT_H
+
+#include <linux/list.h>
+#include <linux/pci.h>
+#include <linux/timer.h>
+#include "dahdi/kernel.h"
+
+#include <stdbool.h>
+
+#define VPMOCT_FIRM_HEADER_LEN 32
+#define VPMOCT_BOOT_RAM_LEN 128
+#define VPMOCT_FLASH_BUF_SECTIONS 4
+#define VPMOCT_MAX_CHUNK 7
+
+/* Bootloader commands */
+#define VPMOCT_BOOT_FLASH_ERASE 0x01
+#define VPMOCT_BOOT_FLASH_COPY 0x02
+#define VPMOCT_BOOT_IMAGE_VALIDATE 0x06
+#define VPMOCT_BOOT_REBOOT 0x07
+#define VPMOCT_BOOT_DECRYPT 0x08
+#define VPMOCT_BOOT_FLASHLOAD 0x10
+
+/* Dual use registers */
+#define VPMOCT_IDENT 0x00
+#define VPMOCT_MAJOR 0x0a
+#define VPMOCT_MINOR 0x0b
+#define VPMOCT_SERIAL 0x90
+#define VPMOCT_SERIAL_SIZE 32
+
+/* Bootloader registers */
+#define VPMOCT_BOOT_ERROR 0x0c
+#define VPMOCT_BOOT_STATUS 0x10
+#define VPMOCT_BOOT_CMD 0x11
+#define VPMOCT_BOOT_LEN 0x14
+#define VPMOCT_BOOT_ADDRESS1 0x18
+#define VPMOCT_BOOT_ADDRESS2 0x1c
+#define VPMOCT_BOOT_RAM 0x20
+
+#define VPMOCT_MODE_BOOTLOADER  0
+#define VPMOCT_MODE_APPLICATION 1
+
+struct vpmoct {
+	struct list_head pending_list;
+	struct list_head active_list;
+	spinlock_t list_lock;
+	struct mutex mutex;
+	unsigned short int mode;
+	struct device *dev;
+	u32 companding;
+	u32 echo;
+	unsigned int preecho_enabled:1;
+	unsigned int echo_update_active:1;
+	unsigned int companding_update_active:1;
+	u8 preecho_timeslot;
+	u8 preecho_buf[8];
+	u8 major;
+	u8 minor;
+};
+
+struct vpmoct_cmd {
+	struct list_head node;
+	u8 address;
+	u8 data[VPMOCT_MAX_CHUNK];
+	u8 command;
+	u8 chunksize;
+	u8 txident;
+	struct completion complete;
+};
+
+static inline bool is_vpmoct_cmd_read(const struct vpmoct_cmd *cmd)
+{
+	return (0x60 == (cmd->command & 0xf0));
+}
+
+struct vpmoct *vpmoct_alloc(void);
+void vpmoct_free(struct vpmoct *vpm);
+int vpmoct_init(struct vpmoct *vpm);
+int vpmoct_echocan_create(struct vpmoct *vpm,
+			   int channo,
+			   int companding);
+void vpmoct_echocan_free(struct vpmoct *vpm,
+			 int channo);
+int vpmoct_preecho_enable(struct vpmoct *vpm, int channo);
+int vpmoct_preecho_disable(struct vpmoct *vpm, int channo);
+#endif

Propchange: linux/trunk/drivers/dahdi/voicebus/vpmoct.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: linux/trunk/drivers/dahdi/voicebus/vpmoct.h
------------------------------------------------------------------------------
    svn:keywords = 'Author Date Id Revision'

Propchange: linux/trunk/drivers/dahdi/voicebus/vpmoct.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: linux/trunk/drivers/dahdi/wctdm24xxp/base.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/wctdm24xxp/base.c?view=diff&rev=9997&r1=9996&r2=9997
==============================================================================
--- linux/trunk/drivers/dahdi/wctdm24xxp/base.c (original)
+++ linux/trunk/drivers/dahdi/wctdm24xxp/base.c Tue Jun 28 17:28:53 2011
@@ -7,7 +7,7 @@
  * Support for Hx8 by Andrew Kohlsmith <akohlsmith at mixdown.ca> and Matthew
  * Fredrickson <creslin at digium.com>
  *
- * Copyright (C) 2005 - 2010 Digium, Inc.
+ * Copyright (C) 2005 - 2011 Digium, Inc.
  * All rights reserved.
  *
  * Sections for QRV cards written by Jim Dixon <jim at lambdatel.com>
@@ -165,6 +165,7 @@
 
 /* names of HWEC modules */
 static const char *vpmadt032_name = "VPMADT032";
+static const char *vpmoct_name = "VPMOCT032";
 
 /* Undefine to enable Power alarm / Transistor debug -- note: do not
    enable for normal operation! */
@@ -308,6 +309,12 @@
 	return ((((timeslot) & 0x3) * 3 + (bit)) * 7) + ((timeslot) >> 2);
 }
 
+static inline bool is_initialized(struct wctdm *wc)
+{
+	WARN_ON(wc->initialized < 0);
+	return (wc->initialized == 0);
+}
+
 static void
 setchanconfig_from_state(struct vpmadt032 *vpm, int channel,
 			 GpakChannelConfig_t *chanconfig)
@@ -435,7 +442,8 @@
 			dev_info(&wc->vb.pdev->dev, "Configured McBSP ports successfully\n");
 	}
 
-	if ((res = gpakPingDsp(vpm->dspid, &vpm->version))) {
+	res = gpakPingDsp(vpm->dspid, &vpm->version);
+	if (res) {
 		dev_notice(&wc->vb.pdev->dev, "Error pinging DSP (%d)\n", res);
 		return -1;
 	}
@@ -488,6 +496,52 @@
         const u8 a = sframe[0*(EFRAME_SIZE+EFRAME_GAP) + (EFRAME_SIZE+1)];
         const u8 b = sframe[1*(EFRAME_SIZE+EFRAME_GAP) + (EFRAME_SIZE+1)];
         return a != b;
+}
+
+static inline void cmd_dequeue_vpmoct(struct wctdm *wc, u8 *eframe)
+{
+	struct vpmoct *vpm = wc->vpmoct;
+	struct vpmoct_cmd *cmd;
+	u8 i;
+
+	/* Pop a command off pending list */
+	spin_lock(&vpm->list_lock);
+	if (list_empty(&vpm->pending_list)) {
+		spin_unlock(&vpm->list_lock);
+		return;
+	}
+
+	cmd = list_entry(vpm->pending_list.next, struct vpmoct_cmd, node);
+	if (is_vpmoct_cmd_read(cmd))
+		list_move_tail(&cmd->node, &vpm->active_list);
+	else
+		list_del_init(&cmd->node);
+
+	/* Skip audio (24 bytes) and ignore first 6 timeslots */
+	eframe += 30;
+
+	/* Save ident so we can match the return eframe */
+	cmd->txident = wc->txident;
+
+	/* We have four timeslots to work with for a regular spi packet */
+	/* TODO: Create debug flag for this in dev */
+
+	/* The vpmoct requires a "sync" spi command as the first three bytes
+	 * of an eframe */
+	eframe[7*0] = 0x12;
+	eframe[7*1] = 0x34;
+	eframe[7*2] = 0x56;
+	eframe[7*3] = cmd->command;
+	eframe[7*4] = cmd->address;
+	eframe[7*5] = cmd->data[0];
+	for (i = 1; i < cmd->chunksize; i++)
+		eframe[(7*5)+7*i] = cmd->data[i];
+
+	/* Clean up fire-and-forget messages from memory */
+	if (list_empty(&cmd->node))
+		kfree(cmd);
+
+	spin_unlock(&vpm->list_lock);
 }
 
 static inline void cmd_dequeue_vpmadt032(struct wctdm *wc, u8 *eframe)
@@ -707,6 +761,40 @@
 		eframe[CMD_BYTE(mod, 2)] = 0x10;
 		break;
 	}
+}
+
+static inline void cmd_decipher_vpmoct(struct wctdm *wc, const u8 *eframe)
+{
+	struct vpmoct *vpm = wc->vpmoct;
+	struct vpmoct_cmd *cmd;
+	int i;
+
+	/* Skip audio and first 6 timeslots */
+	eframe += 30;
+
+	spin_lock(&vpm->list_lock);
+	/* No command to handle, just exit */
+	if (list_empty(&vpm->active_list)) {
+		spin_unlock(&vpm->list_lock);
+		return;
+	}
+
+	cmd = list_entry(vpm->active_list.next, struct vpmoct_cmd, node);
+	if (wc->rxident == cmd->txident)
+		list_del_init(&cmd->node);
+	else
+		cmd = NULL;
+	spin_unlock(&vpm->list_lock);
+
+	if (!cmd)
+		return;
+
+	/* Store result, Ignoring the first "sync spi command" bytes */
+	cmd->command = eframe[7*3];
+	cmd->address = eframe[7*4];
+	for (i = 0; i < cmd->chunksize; ++i)
+		cmd->data[i] = eframe[7*(5+i)];
+	complete(&cmd->complete);
 }
 
 static inline void cmd_decipher_vpmadt032(struct wctdm *wc, const u8 *eframe)
@@ -923,7 +1011,7 @@
 	unsigned char *eframe = sframe;
 
 	/* Calculate Transmission */
-	if (likely(wc->initialized)) {
+	if (likely(is_initialized(wc))) {
 		for (x = 0; x < MAX_SPANS; x++) {
 			if (wc->spans[x]) {
 				s = &wc->spans[x]->span;
@@ -953,11 +1041,10 @@
 				_cmd_dequeue(wc, eframe, y, x);
 		}
 
-		if (wc->vpmadt032) {
+		if (wc->vpmadt032)
 			cmd_dequeue_vpmadt032(wc, eframe);
-		} else if (wc->vpmadt032) {
-			cmd_dequeue_vpmadt032(wc, eframe);
-		}
+		else if (wc->vpmoct)
+			cmd_dequeue_vpmoct(wc, eframe);
 
 		if (x < DAHDI_CHUNKSIZE - 1) {
 			eframe[EFRAME_SIZE] = wc->ctlreg;
@@ -1171,6 +1258,22 @@
 		chanchunk[6] = sframe[3 + i + (EFRAME_SIZE + EFRAME_GAP)*6];
 		chanchunk[7] = sframe[3 + i + (EFRAME_SIZE + EFRAME_GAP)*7];
 	}
+
+	/* Pre-echo with the vpmoct overwrites the 24th timeslot with the
+	 * specified channel's pre-echo audio stream. This data is ignored
+	 * on all but the 24xx card, so we store it in a temporary buffer.
+	 */
+	if (wc->vpmoct && wc->vpmoct->preecho_enabled) {
+		chanchunk = &wc->vpmoct->preecho_buf[0];
+		chanchunk[0] = sframe[23 + (EFRAME_SIZE + EFRAME_GAP)*0];
+		chanchunk[1] = sframe[23 + (EFRAME_SIZE + EFRAME_GAP)*1];
+		chanchunk[2] = sframe[23 + (EFRAME_SIZE + EFRAME_GAP)*2];
+		chanchunk[3] = sframe[23 + (EFRAME_SIZE + EFRAME_GAP)*3];
+		chanchunk[4] = sframe[23 + (EFRAME_SIZE + EFRAME_GAP)*4];
+		chanchunk[5] = sframe[23 + (EFRAME_SIZE + EFRAME_GAP)*5];
+		chanchunk[6] = sframe[23 + (EFRAME_SIZE + EFRAME_GAP)*6];
+		chanchunk[7] = sframe[23 + (EFRAME_SIZE + EFRAME_GAP)*7];
+	}
 }
 
 static inline void wctdm_receiveprep(struct wctdm *wc, const u8 *sframe)
@@ -1184,10 +1287,11 @@
 	if (unlikely(!is_good_frame(sframe)))
 		return;
 
-	if (likely(wc->initialized))
+	spin_lock_irqsave(&wc->reglock, flags);
+
+	if (likely(is_initialized(wc)))
 		extract_tdm_data(wc, sframe);
 
-	spin_lock_irqsave(&wc->reglock, flags);
 	for (x = 0; x < DAHDI_CHUNKSIZE; x++) {
 		if (x < DAHDI_CHUNKSIZE - 1) {
 			expected = wc->rxident + 1;
@@ -1203,13 +1307,15 @@
 
 		if (wc->vpmadt032)
 			cmd_decipher_vpmadt032(wc, eframe);
+		else if (wc->vpmoct)
+			cmd_decipher_vpmoct(wc, eframe);
 
 		eframe += (EFRAME_SIZE + EFRAME_GAP);
 	}
 	spin_unlock_irqrestore(&wc->reglock, flags);
 
 	/* XXX We're wasting 8 taps.  We should get closer :( */
-	if (likely(wc->initialized)) {
+	if (likely(is_initialized(wc))) {
 		for (x = 0; x < wc->avchannels; x++) {
 			struct wctdm_chan *const wchan = wc->chans[x];
 			struct dahdi_chan *const c = &wchan->chan;
@@ -1219,7 +1325,16 @@
 				    ARRAY_SIZE(buffer));
 			dahdi_ec_chunk(c, c->readchunk, buffer);
 #else
-			dahdi_ec_chunk(c, c->readchunk, c->writechunk);
+			if ((wc->vpmoct) &&
+			    (wchan->timeslot == wc->vpmoct->preecho_timeslot) &&
+			    (wc->vpmoct->preecho_enabled)) {
+				__dahdi_ec_chunk(c, c->readchunk,
+						 wc->vpmoct->preecho_buf,
+						 c->writechunk);
+			} else {
+				__dahdi_ec_chunk(c, c->readchunk, c->readchunk,
+						 c->writechunk);
+			}
 #endif
 		}
 
@@ -2014,6 +2129,8 @@
 	struct wctdm *wc = chan->pvt;
 	if (wc->vpmadt032)
 		return vpmadt032_name;
+	else if (wc->vpmoct)
+		return vpmoct_name;
 	return NULL;
 }
 
@@ -2033,21 +2150,31 @@
 	if (!vpmsupport)
 		return -ENODEV;
 #endif
-	if (!wc->vpmadt032)
+	if (wc->vpmadt032) {
+		ops = &vpm_ec_ops;
+		features = &vpm_ec_features;
+
+		*ec = &wchan->ec;
+		(*ec)->ops = ops;
+		(*ec)->features = *features;
+
+		comp = (DAHDI_LAW_ALAW == chan->span->deflaw) ?
+					ADT_COMP_ALAW : ADT_COMP_ULAW;
+
+		return vpmadt032_echocan_create(wc->vpmadt032, wchan->timeslot,
+						comp, ecp, p);
+	} else if (wc->vpmoct) {
+		ops = &vpm_ec_ops;
+		features = &vpm_ec_features;
+
+		*ec = &wchan->ec;
+		(*ec)->ops = ops;
+		(*ec)->features = *features;
+		return vpmoct_echocan_create(wc->vpmoct, wchan->timeslot,
+					     chan->span->deflaw);
+	} else {
 		return -ENODEV;
-
-	ops = &vpm_ec_ops;
-	features = &vpm_ec_features;
-
-	*ec = &wchan->ec;
-	(*ec)->ops = ops;
-	(*ec)->features = *features;
-
-	comp = (DAHDI_LAW_ALAW == chan->span->deflaw) ?
-				ADT_COMP_ALAW : ADT_COMP_ULAW;
-
-	return vpmadt032_echocan_create(wc->vpmadt032, wchan->timeslot,
-					comp, ecp, p);
+	}
 }
 
 static void echocan_free(struct dahdi_chan *chan, struct dahdi_echocan_state *ec)
@@ -2058,6 +2185,9 @@
 	if (wc->vpmadt032) {
 		memset(ec, 0, sizeof(*ec));
 		vpmadt032_echocan_free(wc->vpmadt032, wchan->timeslot, ec);
+	} else if (wc->vpmoct) {
+		memset(ec, 0, sizeof(*ec));
+		vpmoct_echocan_free(wc->vpmoct, wchan->timeslot);
 	}
 }
 
@@ -2135,7 +2265,7 @@
 {
 	int x;
 
-	if (unlikely(!wc->initialized))
+	if (unlikely(!is_initialized(wc)))
 		return;
 
 	for (x = 0; x < wc->mods_per_board; x++) {
@@ -3920,14 +4050,36 @@
  * Check if the board has finished any setup and is ready to start processing
  * calls.
  */
-int wctdm_wait_for_ready(const struct wctdm *wc)
-{
-	while (!wc->initialized) {
+int wctdm_wait_for_ready(struct wctdm *wc)
+{
+	while (!is_initialized(wc)) {
 		if (fatal_signal_pending(current))
 			return -EIO;
 		msleep_interruptible(250);
 	}
 	return 0;
+}
+
+static int wctdm_enable_hw_preechocan(struct dahdi_chan *chan)
+{
+	struct wctdm *wc = chan->pvt;
+	struct wctdm_chan *wchan = container_of(chan, struct wctdm_chan, chan);
+
+	if (!wc->vpmoct)
+		return 0;
+
+	return vpmoct_preecho_enable(wc->vpmoct, wchan->timeslot);
+}
+
+static void wctdm_disable_hw_preechocan(struct dahdi_chan *chan)
+{
+	struct wctdm *wc = chan->pvt;
+	struct wctdm_chan *wchan = container_of(chan, struct wctdm_chan, chan);
+
+	if (!wc->vpmoct)
+		return;
+
+	vpmoct_preecho_disable(wc->vpmoct, wchan->timeslot);
 }
 
 /**
@@ -3944,7 +4096,7 @@
 {
 	struct wctdm *wc = chan->pvt;
 
-	if ((file->f_flags & O_NONBLOCK) && !wc->initialized)
+	if ((file->f_flags & O_NONBLOCK) && !is_initialized(wc))
 		return -EAGAIN;
 
 	return wctdm_wait_for_ready(wc);
@@ -3960,6 +4112,8 @@
 	.chanconfig = wctdm_chanconfig,
 	.dacs = wctdm_dacs,
 #ifdef VPM_SUPPORT
+	.enable_hw_preechocan = wctdm_enable_hw_preechocan,
+	.disable_hw_preechocan = wctdm_disable_hw_preechocan,
 	.echocan_create = wctdm_echocan_create,
 	.echocan_name = wctdm_echocan_name,
 #endif
@@ -3976,6 +4130,8 @@
 	.chanconfig = b400m_chanconfig,
 	.dacs = wctdm_dacs,
 #ifdef VPM_SUPPORT
+	.enable_hw_preechocan = wctdm_enable_hw_preechocan,
+	.disable_hw_preechocan = wctdm_disable_hw_preechocan,
 	.echocan_create = wctdm_echocan_create,
 	.echocan_name = wctdm_echocan_name,
 #endif
@@ -4222,14 +4378,44 @@
 {
 	int res = 0;
 
-	if (!vpmsupport) {
-		dev_notice(&wc->vb.pdev->dev, "VPM: Support Disabled\n");
+	if (!vpmsupport)
+		goto cleanup;
+
+	res = wctdm_initialize_vpmadt032(wc);
+	if (!res) {
+		wc->ctlreg |= 0x10;
 		return;
-	}
-
-	res = wctdm_initialize_vpmadt032(wc);
-	if (!res)
-		wc->ctlreg |= 0x10;
+	} else {
+		struct vpmoct *vpm;
+		unsigned long flags;
+
+		vpm = vpmoct_alloc();
+		if (!vpm) {
+			dev_info(&wc->vb.pdev->dev,
+			    "Unable to allocate memory for struct vpmoct\n");
+			goto cleanup;
+		}
+
+		vpm->dev = &wc->vb.pdev->dev;
+
+		spin_lock_irqsave(&wc->reglock, flags);
+		wc->vpmoct = vpm;
+		spin_unlock_irqrestore(&wc->reglock, flags);
+
+		if (!vpmoct_init(vpm)) {
+			wc->ctlreg |= 0x10;
+			return;
+		} else {
+			spin_lock_irqsave(&wc->reglock, flags);
+			wc->vpmoct = NULL;
+			spin_unlock_irqrestore(&wc->reglock, flags);
+			vpmoct_free(vpm);
+			goto cleanup;
+		}
+	}
+
+cleanup:
+	dev_info(&wc->vb.pdev->dev, "VPM: Support Disabled\n");
 }
 
 static void wctdm_identify_modules(struct wctdm *wc)
@@ -4904,6 +5090,45 @@
 
 static DEVICE_ATTR(vpm_firmware_version, 0400,
 		   vpm_firmware_version_show, NULL);
+static ssize_t
+enable_vpm_show(struct device *dev,
+		struct device_attribute *attr, char *buf)
+{
+	unsigned long flags;
+	struct wctdm *wc = dev_get_drvdata(dev);
+	unsigned int enable_vpm;
+	spin_lock_irqsave(&wc->reglock, flags);
+	enable_vpm = (wc->ctlreg & 0x10) != 0;
+	spin_unlock_irqrestore(&wc->reglock, flags);
+	return sprintf(buf, "%d\n", enable_vpm);
+}
+
+static ssize_t
+enable_vpm_store(struct device *dev, struct device_attribute *attr,
+		 const char *buf, size_t count)
+{
+	unsigned long flags;
+	struct wctdm *wc = dev_get_drvdata(dev);
+	unsigned int enable_vpm;
+	if (count < 2)
+		return -EINVAL;
+
+	if (('0' == buf[0]) || (0 == buf[0]))
+		enable_vpm = 0;
+	else
+		enable_vpm = 1;
+
+	spin_lock_irqsave(&wc->reglock, flags);
+	if (enable_vpm)
+		wc->ctlreg |= 0x10;
+	else
+		wc->ctlreg &= ~0x10;
+	spin_unlock_irqrestore(&wc->reglock, flags);
+	return count;
+}
+
+static DEVICE_ATTR(enable_vpm, 0644,
+		   enable_vpm_show, enable_vpm_store);
 
 static void create_sysfs_files(struct wctdm *wc)
 {
@@ -4921,10 +5146,20 @@
 		dev_info(&wc->vb.pdev->dev,
 			"Failed to create device attributes.\n");
 	}
+
+	ret = device_create_file(&wc->vb.pdev->dev,
+				 &dev_attr_enable_vpm);
+	if (ret) {
+		dev_info(&wc->vb.pdev->dev,
+			"Failed to create device attributes.\n");
+	}
 }
 
 static void remove_sysfs_files(struct wctdm *wc)
 {
+	device_remove_file(&wc->vb.pdev->dev,
+			   &dev_attr_enable_vpm);
+
 	device_remove_file(&wc->vb.pdev->dev,
 			   &dev_attr_vpm_firmware_version);
 
@@ -4978,6 +5213,8 @@
 	wc = kzalloc(sizeof(*wc), GFP_KERNEL);
 	if (!wc)
 		return -ENOMEM;
+
+	wc->initialized = 1;
 
 	down(&ifacelock);
 	/* \todo this is a candidate for removal... */
@@ -5223,7 +5460,7 @@
 		}
 	}
 
-	wc->initialized = 1;
+	wc->initialized--;
 
 	dev_info(&wc->vb.pdev->dev,
 		 "Found a %s: %s (%d BRI spans, %d analog %s)\n",
@@ -5275,7 +5512,7 @@
 {
 	int i;
 
-	if (wc->initialized) {
+	if (is_initialized(wc)) {
 		for (i = 0; i < MAX_SPANS; i++) {
 			if (wc->spans[i])
 				dahdi_unregister(&wc->spans[i]->span);

Modified: linux/trunk/drivers/dahdi/wctdm24xxp/wctdm24xxp.h
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/wctdm24xxp/wctdm24xxp.h?view=diff&rev=9997&r1=9996&r2=9997
==============================================================================
--- linux/trunk/drivers/dahdi/wctdm24xxp/wctdm24xxp.h (original)
+++ linux/trunk/drivers/dahdi/wctdm24xxp/wctdm24xxp.h Tue Jun 28 17:28:53 2011
@@ -99,6 +99,8 @@
 #include "voicebus/GpakCust.h"
 #endif
 
+#include "voicebus/vpmoct.h"
+
 struct calregs {
 	unsigned char vals[NUM_CAL_REGS];
 };
@@ -140,6 +142,7 @@
 	struct dahdi_chan chan;

[... 523 lines stripped ...]



More information about the svn-commits mailing list