diff options
| author | Sebastian Andrzej Siewior <bigeasy@linutronix.de> | 2012-10-22 16:15:08 -0400 |
|---|---|---|
| committer | Felipe Balbi <balbi@ti.com> | 2012-10-31 09:10:25 -0400 |
| commit | 4ce63571d6a34e151f1525d2dcb5559293d8ad54 (patch) | |
| tree | bfe57a150545b1dc04cbb9085ae30bdeed40cb44 | |
| parent | b7c041aadad561a84d17851f69414060f8389ce1 (diff) | |
usb: gadget: uac2: provide a variable for interface and alt settings
This patch removes the shifting and masking of interface and its alt
setting and provides its own variable.
This looks better and is smaller:
text data bss dec hex filename
x86-32
6940 956 56 7952 1f10 gadget/audio.o.old
6908 956 56 7920 1ef0 gadget/audio.o.new
arm
7914 956 56 8926 22de gadget/audio.o.old
7886 956 56 8898 22c2 gadget/audio.o.new
Acked-by: Jassi Brar <jassisinghbrar@gmail.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
| -rw-r--r-- | drivers/usb/gadget/f_uac2.c | 50 |
1 files changed, 23 insertions, 27 deletions
diff --git a/drivers/usb/gadget/f_uac2.c b/drivers/usb/gadget/f_uac2.c index 86f8ac791420..503dd9782592 100644 --- a/drivers/usb/gadget/f_uac2.c +++ b/drivers/usb/gadget/f_uac2.c | |||
| @@ -50,11 +50,6 @@ static int c_ssize = 2; | |||
| 50 | module_param(c_ssize, uint, S_IRUGO); | 50 | module_param(c_ssize, uint, S_IRUGO); |
| 51 | MODULE_PARM_DESC(c_ssize, "Capture Sample Size(bytes)"); | 51 | MODULE_PARM_DESC(c_ssize, "Capture Sample Size(bytes)"); |
| 52 | 52 | ||
| 53 | #define ALT_SET(x, a) do {(x) &= ~0xff; (x) |= (a); } while (0) | ||
| 54 | #define ALT_GET(x) ((x) & 0xff) | ||
| 55 | #define INTF_SET(x, i) do {(x) &= 0xff; (x) |= ((i) << 8); } while (0) | ||
| 56 | #define INTF_GET(x) ((x >> 8) & 0xff) | ||
| 57 | |||
| 58 | /* Keep everyone on toes */ | 53 | /* Keep everyone on toes */ |
| 59 | #define USB_XFERS 2 | 54 | #define USB_XFERS 2 |
| 60 | 55 | ||
| @@ -142,8 +137,9 @@ static struct snd_pcm_hardware uac2_pcm_hardware = { | |||
| 142 | }; | 137 | }; |
| 143 | 138 | ||
| 144 | struct audio_dev { | 139 | struct audio_dev { |
| 145 | /* Currently active {Interface[15:8] | AltSettings[7:0]} */ | 140 | u8 ac_intf, ac_alt; |
| 146 | __u16 ac_alt, as_out_alt, as_in_alt; | 141 | u8 as_out_intf, as_out_alt; |
| 142 | u8 as_in_intf, as_in_alt; | ||
| 147 | 143 | ||
| 148 | struct usb_ep *in_ep, *out_ep; | 144 | struct usb_ep *in_ep, *out_ep; |
| 149 | struct usb_function func; | 145 | struct usb_function func; |
| @@ -950,8 +946,8 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) | |||
| 950 | return ret; | 946 | return ret; |
| 951 | } | 947 | } |
| 952 | std_ac_if_desc.bInterfaceNumber = ret; | 948 | std_ac_if_desc.bInterfaceNumber = ret; |
| 953 | ALT_SET(agdev->ac_alt, 0); | 949 | agdev->ac_intf = ret; |
| 954 | INTF_SET(agdev->ac_alt, ret); | 950 | agdev->ac_alt = 0; |
| 955 | 951 | ||
| 956 | ret = usb_interface_id(cfg, fn); | 952 | ret = usb_interface_id(cfg, fn); |
| 957 | if (ret < 0) { | 953 | if (ret < 0) { |
| @@ -961,8 +957,8 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) | |||
| 961 | } | 957 | } |
| 962 | std_as_out_if0_desc.bInterfaceNumber = ret; | 958 | std_as_out_if0_desc.bInterfaceNumber = ret; |
| 963 | std_as_out_if1_desc.bInterfaceNumber = ret; | 959 | std_as_out_if1_desc.bInterfaceNumber = ret; |
| 964 | ALT_SET(agdev->as_out_alt, 0); | 960 | agdev->as_out_intf = ret; |
| 965 | INTF_SET(agdev->as_out_alt, ret); | 961 | agdev->as_out_alt = 0; |
| 966 | 962 | ||
| 967 | ret = usb_interface_id(cfg, fn); | 963 | ret = usb_interface_id(cfg, fn); |
| 968 | if (ret < 0) { | 964 | if (ret < 0) { |
| @@ -972,8 +968,8 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) | |||
| 972 | } | 968 | } |
| 973 | std_as_in_if0_desc.bInterfaceNumber = ret; | 969 | std_as_in_if0_desc.bInterfaceNumber = ret; |
| 974 | std_as_in_if1_desc.bInterfaceNumber = ret; | 970 | std_as_in_if1_desc.bInterfaceNumber = ret; |
| 975 | ALT_SET(agdev->as_in_alt, 0); | 971 | agdev->as_in_intf = ret; |
| 976 | INTF_SET(agdev->as_in_alt, ret); | 972 | agdev->as_in_alt = 0; |
| 977 | 973 | ||
| 978 | agdev->out_ep = usb_ep_autoconfig(gadget, &fs_epout_desc); | 974 | agdev->out_ep = usb_ep_autoconfig(gadget, &fs_epout_desc); |
| 979 | if (!agdev->out_ep) { | 975 | if (!agdev->out_ep) { |
| @@ -1075,7 +1071,7 @@ afunc_set_alt(struct usb_function *fn, unsigned intf, unsigned alt) | |||
| 1075 | return -EINVAL; | 1071 | return -EINVAL; |
| 1076 | } | 1072 | } |
| 1077 | 1073 | ||
| 1078 | if (intf == INTF_GET(agdev->ac_alt)) { | 1074 | if (intf == agdev->ac_intf) { |
| 1079 | /* Control I/f has only 1 AltSetting - 0 */ | 1075 | /* Control I/f has only 1 AltSetting - 0 */ |
| 1080 | if (alt) { | 1076 | if (alt) { |
| 1081 | dev_err(&uac2->pdev.dev, | 1077 | dev_err(&uac2->pdev.dev, |
| @@ -1085,16 +1081,16 @@ afunc_set_alt(struct usb_function *fn, unsigned intf, unsigned alt) | |||
| 1085 | return 0; | 1081 | return 0; |
| 1086 | } | 1082 | } |
| 1087 | 1083 | ||
| 1088 | if (intf == INTF_GET(agdev->as_out_alt)) { | 1084 | if (intf == agdev->as_out_intf) { |
| 1089 | ep = agdev->out_ep; | 1085 | ep = agdev->out_ep; |
| 1090 | prm = &uac2->c_prm; | 1086 | prm = &uac2->c_prm; |
| 1091 | config_ep_by_speed(gadget, fn, ep); | 1087 | config_ep_by_speed(gadget, fn, ep); |
| 1092 | ALT_SET(agdev->as_out_alt, alt); | 1088 | agdev->as_out_alt = alt; |
| 1093 | } else if (intf == INTF_GET(agdev->as_in_alt)) { | 1089 | } else if (intf == agdev->as_in_intf) { |
| 1094 | ep = agdev->in_ep; | 1090 | ep = agdev->in_ep; |
| 1095 | prm = &uac2->p_prm; | 1091 | prm = &uac2->p_prm; |
| 1096 | config_ep_by_speed(gadget, fn, ep); | 1092 | config_ep_by_speed(gadget, fn, ep); |
| 1097 | ALT_SET(agdev->as_in_alt, alt); | 1093 | agdev->as_in_alt = alt; |
| 1098 | } else { | 1094 | } else { |
| 1099 | dev_err(&uac2->pdev.dev, | 1095 | dev_err(&uac2->pdev.dev, |
| 1100 | "%s:%d Error!\n", __func__, __LINE__); | 1096 | "%s:%d Error!\n", __func__, __LINE__); |
| @@ -1146,12 +1142,12 @@ afunc_get_alt(struct usb_function *fn, unsigned intf) | |||
| 1146 | struct audio_dev *agdev = func_to_agdev(fn); | 1142 | struct audio_dev *agdev = func_to_agdev(fn); |
| 1147 | struct snd_uac2_chip *uac2 = &agdev->uac2; | 1143 | struct snd_uac2_chip *uac2 = &agdev->uac2; |
| 1148 | 1144 | ||
| 1149 | if (intf == INTF_GET(agdev->ac_alt)) | 1145 | if (intf == agdev->ac_intf) |
| 1150 | return ALT_GET(agdev->ac_alt); | 1146 | return agdev->ac_alt; |
| 1151 | else if (intf == INTF_GET(agdev->as_out_alt)) | 1147 | else if (intf == agdev->as_out_intf) |
| 1152 | return ALT_GET(agdev->as_out_alt); | 1148 | return agdev->as_out_alt; |
| 1153 | else if (intf == INTF_GET(agdev->as_in_alt)) | 1149 | else if (intf == agdev->as_in_intf) |
| 1154 | return ALT_GET(agdev->as_in_alt); | 1150 | return agdev->as_in_alt; |
| 1155 | else | 1151 | else |
| 1156 | dev_err(&uac2->pdev.dev, | 1152 | dev_err(&uac2->pdev.dev, |
| 1157 | "%s:%d Invalid Interface %d!\n", | 1153 | "%s:%d Invalid Interface %d!\n", |
| @@ -1167,10 +1163,10 @@ afunc_disable(struct usb_function *fn) | |||
| 1167 | struct snd_uac2_chip *uac2 = &agdev->uac2; | 1163 | struct snd_uac2_chip *uac2 = &agdev->uac2; |
| 1168 | 1164 | ||
| 1169 | free_ep(&uac2->p_prm, agdev->in_ep); | 1165 | free_ep(&uac2->p_prm, agdev->in_ep); |
| 1170 | ALT_SET(agdev->as_in_alt, 0); | 1166 | agdev->as_in_alt = 0; |
| 1171 | 1167 | ||
| 1172 | free_ep(&uac2->c_prm, agdev->out_ep); | 1168 | free_ep(&uac2->c_prm, agdev->out_ep); |
| 1173 | ALT_SET(agdev->as_out_alt, 0); | 1169 | agdev->as_out_alt = 0; |
| 1174 | } | 1170 | } |
| 1175 | 1171 | ||
| 1176 | static int | 1172 | static int |
| @@ -1277,7 +1273,7 @@ setup_rq_inf(struct usb_function *fn, const struct usb_ctrlrequest *cr) | |||
| 1277 | u16 w_index = le16_to_cpu(cr->wIndex); | 1273 | u16 w_index = le16_to_cpu(cr->wIndex); |
| 1278 | u8 intf = w_index & 0xff; | 1274 | u8 intf = w_index & 0xff; |
| 1279 | 1275 | ||
| 1280 | if (intf != INTF_GET(agdev->ac_alt)) { | 1276 | if (intf != agdev->ac_intf) { |
| 1281 | dev_err(&uac2->pdev.dev, | 1277 | dev_err(&uac2->pdev.dev, |
| 1282 | "%s:%d Error!\n", __func__, __LINE__); | 1278 | "%s:%d Error!\n", __func__, __LINE__); |
| 1283 | return -EOPNOTSUPP; | 1279 | return -EOPNOTSUPP; |
