Skip to contentSkip to conversation

add actuators support

PATCH In review Jiri Pirko 2 participants 7 messages Jul 17, 2017 HID

lore
Share & tools
lore

Jiri Pirko

author
#0 lore raw

cover add actuators support

From: Jiri Pirko <[email protected]>

I am owner of height adjustable desk and naturally, as it has an USB interface, I need to controll it from my computer. Started to think about what would be the best way, I realized that I need to introduce a new driver class in kernel. The reason is a need to have one API for all possible kinds of actuator devices (USB, I2C, gpio, etc).

So the first patch introduces generic actuator device class. Please see the patch description for more info. Basically it allows device drivers to register actuators providing set of ops. Also it exposes actuator manipulation possibilities via generic Netlink interface to userspace.

The second patch introduces driver based on the actuator driver class for Linak USB2LIN device.

I created a library which wraps-up the generic netlink API so it could be easily used by applications. The library comes with a utility called "act" which can be used to manipulate the actuator devices. It has iproute2 command line and stdout syntax.
Here there are couple of examples:

$ act dev show
usb/1-2/0: driver_name usb2lin type linear units um value 70200 move_state stopped
$ act dev move usb/1-2/0 value 100000
$ act dev stop usb/1-2/0

You can monitor the actuator status changes:

$ act mon
get: usb/1-2/0: driver_name usb2lin type linear units um value 70300 move_state positive
get: usb/1-2/0: driver_name usb2lin type linear units um value 99900 move_state stopped
get: usb/1-2/0: driver_name usb2lin type linear units um value 100300 move_state negative
get: usb/1-2/0: driver_name usb2lin type linear units um value 10100 move_state stopped
get: usb/1-2/0: driver_name usb2lin type linear units um value 10500 move_state positive
get: usb/1-2/0: driver_name usb2lin type linear units um value 99900 move_state stopped

The libactuator is available here:
https://git.kernel.org/pub/scm/linux/kernel/git/jpirko/libactuator.git/

This patchset is based on current net-next git tree.
I apologize, I'm not used to send patches outside netdev subsystem so please tell me on top of which tree to rebase this if neede and who to cc. Thanks!

Jiri Pirko (2):
add support for generic actuator devices
actuator: introduce Linak USB2LIN cable support

 MAINTAINERS                   |   7 +
 drivers/Kconfig               |   2 +
 drivers/Makefile              |   1 +
 drivers/actuator/Kconfig      |  26 +++
 drivers/actuator/Makefile     |   2 +
 drivers/actuator/actuator.c   | 410 +++++++++++++++++++++++++++++++++++++++
 drivers/actuator/usb2lin.c    | 433 ++++++++++++++++++++++++++++++++++++++++++
 drivers/hid/hid-core.c        |   1 +
 drivers/hid/hid-ids.h         |   3 +
 include/linux/actuator.h      |  43 +++++
 include/uapi/linux/actuator.h |  74 ++++++++
 11 files changed, 1002 insertions(+)
 create mode 100644 drivers/actuator/Kconfig
 create mode 100644 drivers/actuator/Makefile
 create mode 100644 drivers/actuator/actuator.c
 create mode 100644 drivers/actuator/usb2lin.c
 create mode 100644 include/linux/actuator.h
 create mode 100644 include/uapi/linux/actuator.h
Signature · 1 line
2.9.3
author
#1 lore raw

PATCH 1/2 add support for generic actuator devices

Introduce support for generic actuator devices. Each device is identified by bus_name, dev_name and index. First two are derived according to the bus and address of the parent device. For example "usb/1-2/". The last one is defined by driver itself. That is for cases where it has multiple actuator devices connected via single parent.

Each driver registers actuators one by one. For each instance, ops are defined. Currently there are 3 ops supported:
-status - called by core to driver in order to get actual actuator status -move - called to initiate the movement of an actuator
-stop - called to stop the movement if any

A generic Netlink interface is exposed to userspace. It allows to get actuator status, dump all available actuator devices, iniatiate move and stop of an actuator. Also the netlink interface is used to send events to userspace in case driver notifies core about status change.

libactuator project is there to provide generic Netlink wrapper and custom util to manipulate actuators:
https://git.kernel.org/pub/scm/linux/kernel/git/jpirko/libactuator.git/

---
 MAINTAINERS                   |   7 +
 drivers/Kconfig               |   2 +
 drivers/Makefile              |   1 +
 drivers/actuator/Kconfig      |  15 ++
 drivers/actuator/Makefile     |   1 +
 drivers/actuator/actuator.c   | 410 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/actuator.h      |  43 +++++
 include/uapi/linux/actuator.h |  74 ++++++++
 8 files changed, 553 insertions(+)
 create mode 100644 drivers/actuator/Kconfig
 create mode 100644 drivers/actuator/Makefile
 create mode 100644 drivers/actuator/actuator.c
 create mode 100644 include/linux/actuator.h
 create mode 100644 include/uapi/linux/actuator.h
MAINTAINERS +7 -0
index 1347726..029795a 100644
@@ -5671,6 +5671,13 @@ W:	https://linuxtv.org
 S:	Maintained
 F:	drivers/media/radio/radio-gemtek*
 
+GENERIC ACTUATOR SUPPORT
+M:	Jiri Pirko <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/actuator/
+F:	include/linux/actuator.h
+
 GENERIC GPIO I2C DRIVER
 M:	Haavard Skinnemoen <[email protected]>
 S:	Supported
drivers/Kconfig +2 -0
index 505c676..7617173 100644
@@ -208,4 +208,6 @@ source "drivers/tee/Kconfig"
 
 source "drivers/mux/Kconfig"
 
+source "drivers/actuator/Kconfig"
+
 endmenu
drivers/Makefile +1 -0
index dfdcda0..35e0e55 100644
@@ -182,3 +182,4 @@ obj-$(CONFIG_FPGA)		+= fpga/
 obj-$(CONFIG_FSI)		+= fsi/
 obj-$(CONFIG_TEE)		+= tee/
 obj-$(CONFIG_MULTIPLEXER)	+= mux/
+obj-$(CONFIG_ACTUATOR)		+= actuator/
drivers/actuator/Kconfig new file +15 -0
new file mode 100644
index 0000000..6deac93
@@ -0,0 +1,15 @@
+menuconfig ACTUATOR
+	tristate "Generic actuator support"
+	depends on NET
+	---help---
+	  This provides a support for generic actuator devices. For example
+	  all sorts of linear and rotary actuators.
+
+	  If you want this support, you should say Y here.
+
+	  This support can also be built as a module.  If so, the module
+	  will be called actuator.
+
+if ACTUATOR
+
+endif
drivers/actuator/Makefile new file +1 -0
new file mode 100644
index 0000000..c45af36
@@ -0,0 +1 @@
+obj-$(CONFIG_ACTUATOR)		+= actuator.o
drivers/actuator/actuator.c new file +410 -0

410 lines not on this page · raw message

include/linux/actuator.h new file +43 -0

43 lines not on this page · raw message

include/uapi/linux/actuator.h new file +74 -0

74 lines not on this page · raw message

Signature · 1 line
2.9.3
author
#2 lore raw

PATCH 2/2 actuator: introduce Linak USB2LIN cable support

In reply to Jiri Pirko

Benefit from the previously introduced actuator infrastructure and introduce the first actuator device driver. This driver controls Linak table moving actuators over USB2LIN usb cable.

---
 drivers/actuator/Kconfig   |  11 ++
 drivers/actuator/Makefile  |   1 +
 drivers/actuator/usb2lin.c | 433 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/hid/hid-core.c     |   1 +
 drivers/hid/hid-ids.h      |   3 +
 5 files changed, 449 insertions(+)
 create mode 100644 drivers/actuator/usb2lin.c
drivers/actuator/Kconfig +11 -0
index 6deac93..43150d8 100644
@@ -12,4 +12,15 @@ menuconfig ACTUATOR
 
 if ACTUATOR
 
+menuconfig ACTUATOR_USB2LIN
+	tristate "Linak USB2LIN cable support"
+	depends on USB
+	---help---
+	  This provides a support for Linak USB2LIN devices.
+
+	  If you want this support, you should say Y here.
+
+	  This support can also be built as a module.  If so, the module
+	  will be called usb2lin.
+
 endif
drivers/actuator/Makefile +1 -0
index c45af36..743dc18 100644
@@ -1 +1,2 @@
 obj-$(CONFIG_ACTUATOR)		+= actuator.o
+obj-$(CONFIG_ACTUATOR_USB2LIN)	+= usb2lin.o
drivers/actuator/usb2lin.c new file +433 -0

433 lines not on this page · raw message

drivers/hid/hid-core.c +1 -0
index 6fd01a6..3311a96 100644
@@ -2740,6 +2740,7 @@ static const struct hid_device_id hid_ignore_list[] = {
 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MCT) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HYBRID) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HEATCONTROL) },
+	{ HID_USB_DEVICE(USB_VENDOR_ID_LINAK, USB_DEVICE_ID_LINAK_USB2LIN) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_BEATPAD) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) },
drivers/hid/hid-ids.h +3 -0
index 3d911bf..0650fe9 100644
@@ -663,6 +663,9 @@
 #define USB_DEVICE_ID_LG_MULTITOUCH	0x0064
 #define USB_DEVICE_ID_LG_MELFAS_MT	0x6007
 
+#define USB_VENDOR_ID_LINAK		0x12d3
+#define USB_DEVICE_ID_LINAK_USB2LIN	0x0002
+
 #define USB_VENDOR_ID_LOGITECH		0x046d
 #define USB_DEVICE_ID_LOGITECH_AUDIOHUB 0x0a0e
 #define USB_DEVICE_ID_LOGITECH_T651	0xb00c
Signature · 1 line
2.9.3
#3 lore raw
In reply to Jiri Pirko
Quoted 7 lines · Jiri Pirko

From: Jiri Pirko <[email protected]>

I am owner of height adjustable desk and naturally, as it has an USB interface, I need to controll it from my computer. Started to think about what would be the best way, I realized that I need to introduce a new driver class in kernel. The reason is a need to have one API for all possible kinds of actuator devices (USB, I2C, gpio, etc).

Why does this have to be a kernel driver at all? Your USB driver should really just be a simple userspace application (use libusb to have it work on all operating systems.)

While the idea of a "generic class" is nice, given that there is only one device of this type out there so far, and it's a USB one, kind of implies that a generic class isn't needed just yet.

Oh, and it's nice to cc: the linux-usb@vger mailing list for USB patches in the future :)

thanks,

greg k-h

author
#4 lore raw
Quoted 9 lines · Mon, Jul 17, 2017 at 06:28:38PM CEST, [email protected] wrote:
Quoted 7 lines · Jiri Pirko

From: Jiri Pirko <[email protected]>

I am owner of height adjustable desk and naturally, as it has an USB interface, I need to controll it from my computer. Started to think about what would be the best way, I realized that I need to introduce a new driver class in kernel. The reason is a need to have one API for all possible kinds of actuator devices (USB, I2C, gpio, etc).

Quoted 3 lines

Why does this have to be a kernel driver at all? Your USB driver should really just be a simple userspace application (use libusb to have it work on all operating systems.)

Yeah, I was thinking about it as well. To have some kind of single purpose app like sispmctl (control of surge protector). But that would limit you only for this specific device. And for multiple devices you would have to have multiple apps.

So it seems to me like a suitable solution to have this as a driver class.

Quoted 4 lines

While the idea of a "generic class" is nice, given that there is only one device of this type out there so far, and it's a USB one, kind of implies that a generic class isn't needed just yet.

We have to start somewhere. The world is full of actuators. Connected over diferent buses. I think it is good to have a class,lib,app so the drivers could be easily added, apps could be written using single api.

Quoted 3 lines

Oh, and it's nice to cc: the linux-usb@vger mailing list for USB patches in the future :)

Will do.

Quoted 4 lines

thanks,

greg k-h

#5 lore raw
Quoted 14 lines · Jiri Pirko
Quoted 9 lines · Mon, Jul 17, 2017 at 06:28:38PM CEST, [email protected] wrote:
Quoted 7 lines · Jiri Pirko

From: Jiri Pirko <[email protected]>

I am owner of height adjustable desk and naturally, as it has an USB interface, I need to controll it from my computer. Started to think about what would be the best way, I realized that I need to introduce a new driver class in kernel. The reason is a need to have one API for all possible kinds of actuator devices (USB, I2C, gpio, etc).

Quoted 3 lines

Why does this have to be a kernel driver at all? Your USB driver should really just be a simple userspace application (use libusb to have it work on all operating systems.)

Quoted 7 lines

Yeah, I was thinking about it as well. To have some kind of single purpose app like sispmctl (control of surge protector). But that would limit you only for this specific device. And for multiple devices you would have to have multiple apps.

So it seems to me like a suitable solution to have this as a driver class.

For USB devices, especially ones as simple as this, we don't want them to have kernel drivers. It's just overkill.

And never create a class if you only have one type of device, otherwise you don't know if you really have it properly defined or not. 3 is a good number to start with.

sorry,

greg k-h

author
#6 lore raw
Quoted 23 lines · Mon, Jul 17, 2017 at 06:40:06PM CEST, [email protected] wrote:
Quoted 14 lines · Jiri Pirko
Quoted 9 lines · Mon, Jul 17, 2017 at 06:28:38PM CEST, [email protected] wrote:
Quoted 7 lines · Jiri Pirko

From: Jiri Pirko <[email protected]>

I am owner of height adjustable desk and naturally, as it has an USB interface, I need to controll it from my computer. Started to think about what would be the best way, I realized that I need to introduce a new driver class in kernel. The reason is a need to have one API for all possible kinds of actuator devices (USB, I2C, gpio, etc).

Quoted 3 lines

Why does this have to be a kernel driver at all? Your USB driver should really just be a simple userspace application (use libusb to have it work on all operating systems.)

Quoted 7 lines

Yeah, I was thinking about it as well. To have some kind of single purpose app like sispmctl (control of surge protector). But that would limit you only for this specific device. And for multiple devices you would have to have multiple apps.

So it seems to me like a suitable solution to have this as a driver class.

Quoted 6 lines

For USB devices, especially ones as simple as this, we don't want them to have kernel drivers. It's just overkill.

And never create a class if you only have one type of device, otherwise you don't know if you really have it properly defined or not. 3 is a good number to start with.

You are making it hard for me :) Have to find other 2 then. And I thought that this spare time quest is coming to an end...

Quoted 4 lines

sorry,

greg k-h