[alsa-devel] [PATCH v2 0/3] More Line 6 cleanup
Changes in v2:
* return true/false instead of 1/0 * do not include spaces in driver name * drop patch altering struct names (unnecessary)
Chris Rorvick (3): ALSA: line6: Add toneport_has_source_select() ALSA: line6: Pass toneport pointer to toneport_has_led() ALSA: line6: Pass driver name to line6_probe()
sound/usb/line6/driver.c | 3 ++- sound/usb/line6/driver.h | 3 +-- sound/usb/line6/pod.c | 2 +- sound/usb/line6/podhd.c | 2 +- sound/usb/line6/toneport.c | 53 +++++++++++++++++++++++++--------------------- sound/usb/line6/variax.c | 2 +- 6 files changed, 35 insertions(+), 30 deletions(-)
Add a predicate for testing if the device supports source selection to make the conditional logic around this a bit cleaner.
Signed-off-by: Chris Rorvick chris@rorvick.com --- sound/usb/line6/toneport.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/sound/usb/line6/toneport.c b/sound/usb/line6/toneport.c index b107cf4..6dd6d4f 100644 --- a/sound/usb/line6/toneport.c +++ b/sound/usb/line6/toneport.c @@ -343,6 +343,20 @@ static void toneport_remove_leds(struct usb_line6_toneport *toneport) } }
+static bool toneport_has_source_select(struct usb_line6_toneport *toneport) +{ + switch (toneport->type) { + case LINE6_TONEPORT_UX1: + case LINE6_TONEPORT_UX2: + case LINE6_PODSTUDIO_UX1: + case LINE6_PODSTUDIO_UX2: + return true; + + default: + return false; + } +} + /* Setup Toneport device. */ @@ -360,17 +374,10 @@ static void toneport_setup(struct usb_line6_toneport *toneport) toneport_send_cmd(usbdev, 0x0301, 0x0000);
/* initialize source select: */ - switch (toneport->type) { - case LINE6_TONEPORT_UX1: - case LINE6_TONEPORT_UX2: - case LINE6_PODSTUDIO_UX1: - case LINE6_PODSTUDIO_UX2: + if (toneport_has_source_select(toneport)) toneport_send_cmd(usbdev, toneport_source_info[toneport->source].code, 0x0000); - default: - break; - }
if (toneport_has_led(toneport->type)) toneport_update_led(toneport); @@ -421,20 +428,13 @@ static int toneport_init(struct usb_line6 *line6, return err;
/* register source select control: */ - switch (toneport->type) { - case LINE6_TONEPORT_UX1: - case LINE6_TONEPORT_UX2: - case LINE6_PODSTUDIO_UX1: - case LINE6_PODSTUDIO_UX2: + if (toneport_has_source_select(toneport)) { err = snd_ctl_add(line6->card, snd_ctl_new1(&toneport_control_source, line6->line6pcm)); if (err < 0) return err; - - default: - break; }
line6_read_serial_number(line6, &toneport->serial_number);
It is unlikely this function would ever be used in a context without a pointer to a `struct usb_line6_toneport', so grab the device type from it rather than having the caller do it.
Signed-off-by: Chris Rorvick chris@rorvick.com --- sound/usb/line6/toneport.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/sound/usb/line6/toneport.c b/sound/usb/line6/toneport.c index 6dd6d4f..2420d2f 100644 --- a/sound/usb/line6/toneport.c +++ b/sound/usb/line6/toneport.c @@ -278,12 +278,17 @@ static struct snd_kcontrol_new toneport_control_source = { (void cmd_0x02(byte red, byte green) */
-static bool toneport_has_led(enum line6_device_type type) +static bool toneport_has_led(struct usb_line6_toneport *toneport) { - return - (type == LINE6_GUITARPORT) || - (type == LINE6_TONEPORT_GX); + switch (toneport->type) { + case LINE6_GUITARPORT: + case LINE6_TONEPORT_GX: /* add your device here if you are missing support for the LEDs */ + return true; + + default: + return false; + } }
static const char * const led_colors[2] = { "red", "green" }; @@ -379,7 +384,7 @@ static void toneport_setup(struct usb_line6_toneport *toneport) toneport_source_info[toneport->source].code, 0x0000);
- if (toneport_has_led(toneport->type)) + if (toneport_has_led(toneport)) toneport_update_led(toneport);
mod_timer(&toneport->timer, jiffies + TONEPORT_PCM_DELAY * HZ); @@ -395,7 +400,7 @@ static void line6_toneport_disconnect(struct usb_line6 *line6)
del_timer_sync(&toneport->timer);
- if (toneport_has_led(toneport->type)) + if (toneport_has_led(toneport)) toneport_remove_leds(toneport); }
@@ -440,7 +445,7 @@ static int toneport_init(struct usb_line6 *line6, line6_read_serial_number(line6, &toneport->serial_number); line6_read_data(line6, 0x80c2, &toneport->firmware_version, 1);
- if (toneport_has_led(toneport->type)) { + if (toneport_has_led(toneport)) { err = toneport_init_leds(toneport); if (err < 0) return err;
Provide a unique name for each driver instead of using "line6usb" for all of them. This will allow for different configurations based on the driver type.
Signed-off-by: Chris Rorvick chris@rorvick.com --- sound/usb/line6/driver.c | 3 ++- sound/usb/line6/driver.h | 3 +-- sound/usb/line6/pod.c | 2 +- sound/usb/line6/podhd.c | 2 +- sound/usb/line6/toneport.c | 2 +- sound/usb/line6/variax.c | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/sound/usb/line6/driver.c b/sound/usb/line6/driver.c index 2328ec9..1e58e92 100644 --- a/sound/usb/line6/driver.c +++ b/sound/usb/line6/driver.c @@ -480,6 +480,7 @@ static int line6_init_cap_control(struct usb_line6 *line6) */ int line6_probe(struct usb_interface *interface, const struct usb_device_id *id, + const char *driver_name, const struct line6_properties *properties, int (*private_init)(struct usb_line6 *, const struct usb_device_id *id), size_t data_size) @@ -511,7 +512,7 @@ int line6_probe(struct usb_interface *interface, line6->ifcdev = &interface->dev;
strcpy(card->id, properties->id); - strcpy(card->driver, DRIVER_NAME); + strcpy(card->driver, driver_name); strcpy(card->shortname, properties->name); sprintf(card->longname, "Line 6 %s at USB %s", properties->name, dev_name(line6->ifcdev)); diff --git a/sound/usb/line6/driver.h b/sound/usb/line6/driver.h index fa877a3..8247a6b 100644 --- a/sound/usb/line6/driver.h +++ b/sound/usb/line6/driver.h @@ -18,8 +18,6 @@
#include "midi.h"
-#define DRIVER_NAME "line6usb" - #define USB_INTERVALS_PER_SECOND 1000
/* Fallback USB interval and max packet size values */ @@ -168,6 +166,7 @@ extern int line6_write_data(struct usb_line6 *line6, int address, void *data,
int line6_probe(struct usb_interface *interface, const struct usb_device_id *id, + const char *driver_name, const struct line6_properties *properties, int (*private_init)(struct usb_line6 *, const struct usb_device_id *id), size_t data_size); diff --git a/sound/usb/line6/pod.c b/sound/usb/line6/pod.c index 61aadd7..c4246ad 100644 --- a/sound/usb/line6/pod.c +++ b/sound/usb/line6/pod.c @@ -574,7 +574,7 @@ static const struct line6_properties pod_properties_table[] = { static int pod_probe(struct usb_interface *interface, const struct usb_device_id *id) { - return line6_probe(interface, id, + return line6_probe(interface, id, "Line6-POD", &pod_properties_table[id->driver_info], pod_init, sizeof(struct usb_line6_pod)); } diff --git a/sound/usb/line6/podhd.c b/sound/usb/line6/podhd.c index 9c3c744..63dcaef 100644 --- a/sound/usb/line6/podhd.c +++ b/sound/usb/line6/podhd.c @@ -169,7 +169,7 @@ static const struct line6_properties podhd_properties_table[] = { static int podhd_probe(struct usb_interface *interface, const struct usb_device_id *id) { - return line6_probe(interface, id, + return line6_probe(interface, id, "Line6-PODHD", &podhd_properties_table[id->driver_info], podhd_init, sizeof(struct usb_line6)); } diff --git a/sound/usb/line6/toneport.c b/sound/usb/line6/toneport.c index 2420d2f..1a0a485 100644 --- a/sound/usb/line6/toneport.c +++ b/sound/usb/line6/toneport.c @@ -557,7 +557,7 @@ static const struct line6_properties toneport_properties_table[] = { static int toneport_probe(struct usb_interface *interface, const struct usb_device_id *id) { - return line6_probe(interface, id, + return line6_probe(interface, id, "Line6-TonePort", &toneport_properties_table[id->driver_info], toneport_init, sizeof(struct usb_line6_toneport)); } diff --git a/sound/usb/line6/variax.c b/sound/usb/line6/variax.c index b1c1de6..ddc23dd 100644 --- a/sound/usb/line6/variax.c +++ b/sound/usb/line6/variax.c @@ -283,7 +283,7 @@ static const struct line6_properties variax_properties_table[] = { static int variax_probe(struct usb_interface *interface, const struct usb_device_id *id) { - return line6_probe(interface, id, + return line6_probe(interface, id, "Line6-Variax", &variax_properties_table[id->driver_info], variax_init, sizeof(struct usb_line6_variax)); }
At Sat, 7 Feb 2015 10:43:16 -0600, Chris Rorvick wrote:
Changes in v2:
- return true/false instead of 1/0
- do not include spaces in driver name
- drop patch altering struct names (unnecessary)
Thanks, applied all three patches now.
Takashi
Chris Rorvick (3): ALSA: line6: Add toneport_has_source_select() ALSA: line6: Pass toneport pointer to toneport_has_led() ALSA: line6: Pass driver name to line6_probe()
sound/usb/line6/driver.c | 3 ++- sound/usb/line6/driver.h | 3 +-- sound/usb/line6/pod.c | 2 +- sound/usb/line6/podhd.c | 2 +- sound/usb/line6/toneport.c | 53 +++++++++++++++++++++++++--------------------- sound/usb/line6/variax.c | 2 +- 6 files changed, 35 insertions(+), 30 deletions(-)
-- 2.1.0
participants (2)
-
Chris Rorvick
-
Takashi Iwai