Re: [PATCH] staging: comedi: ke_counter: add ability to select counter clock source

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2014-05-29 18:45, H Hartley Sweeten wrote:
Add an (*insn_config) to the counter subdevice to allow the user to select
the clock source for the counters using the INSN_CONFIG_SET_CLOCK_SRC
instruction. The current selection can be queried with the instruction
INSN_CONFIG_GET_CLOCK_SRC.

Also, handle the INSN_CONFIG_RESET instruction to reset all the counters.

Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
  drivers/staging/comedi/drivers/ke_counter.c | 57 +++++++++++++++++++++++++++--
  1 file changed, 54 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ke_counter.c b/drivers/staging/comedi/drivers/ke_counter.c
index ec43c38..ed873c4 100644
--- a/drivers/staging/comedi/drivers/ke_counter.c
+++ b/drivers/staging/comedi/drivers/ke_counter.c
@@ -93,6 +93,58 @@ static int ke_counter_insn_read(struct comedi_device *dev,
  	return insn->n;
  }

+static void ke_counter_reset(struct comedi_device *dev)
+{
+	unsigned int chan;
+
+	for (chan = 0; chan < 3; chan++)
+		outb(0, dev->iobase + KE_RESET_REG(chan));
+}
+
+static int ke_counter_insn_config(struct comedi_device *dev,
+				  struct comedi_subdevice *s,
+				  struct comedi_insn *insn,
+				  unsigned int *data)
+{
+	switch (data[0]) {
+	case INSN_CONFIG_SET_CLOCK_SRC:
+		switch (data[1]) {
+		case KE_OSC_SEL_EXT:	/* Pin 21 on D-sub */
+		case KE_OSC_SEL_4MHZ:	/* option */
+		case KE_OSC_SEL_20MHZ:	/* default */
+			break;
+		default:
+			return -EINVAL;
+		}
+		outb(data[1], dev->iobase + KE_OSC_SEL_REG);
+		break;
+	case INSN_CONFIG_GET_CLOCK_SRC:
+		data[1] = inb(dev->iobase + KE_OSC_SEL_REG);
+		switch (data[1]) {
+		case KE_OSC_SEL_EXT:
+			data[2] = 0;	/* Unknown */
+			break;
+		case KE_OSC_SEL_4MHZ:
+			data[2] = 250;	/* 250ns */
+			break;
+		case KE_OSC_SEL_20MHZ:
+			data[2] = 50;	/* 50ns */
+			break;
+		default:
+			data[2] = 0;	/* Invalid? */
+			break;
+		}
+		break;
+	case INSN_CONFIG_RESET:
+		ke_counter_reset(dev);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return insn->n;
+}
+
  static int ke_counter_do_insn_bits(struct comedi_device *dev,
  				   struct comedi_subdevice *s,
  				   struct comedi_insn *insn,
@@ -130,6 +182,7 @@ static int ke_counter_auto_attach(struct comedi_device *dev,
  	s->range_table	= &range_unknown;
  	s->insn_read	= ke_counter_insn_read;
  	s->insn_write	= ke_counter_insn_write;
+	s->insn_config	= ke_counter_insn_config;

  	s = &dev->subdevices[1];
  	s->type		= COMEDI_SUBD_DO;
@@ -141,9 +194,7 @@ static int ke_counter_auto_attach(struct comedi_device *dev,

  	outb(KE_OSC_SEL_20MHZ, dev->iobase + KE_OSC_SEL_REG);

-	outb(0, dev->iobase + KE_RESET_REG(0));
-	outb(0, dev->iobase + KE_RESET_REG(1));
-	outb(0, dev->iobase + KE_RESET_REG(2));
+	ke_counter_reset(dev);

  	return 0;
  }


Okay, but it would be nice to expose the clock source values in "comedi.h" as well.

Reviewed-by: Ian Abbott <abbotti@xxxxxxxxx>

--
-=( Ian Abbott @ MEV Ltd.    E-mail: <abbotti@xxxxxxxxx>        )=-
-=( Tel: +44 (0)161 477 1898   FAX: +44 (0)161 718 3587         )=-
_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux