aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/usb
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/usb')
-rw-r--r--drivers/net/usb/dm9601.c53
1 files changed, 13 insertions, 40 deletions
diff --git a/drivers/net/usb/dm9601.c b/drivers/net/usb/dm9601.c
index 1ffdd106f4c4..633a511d6cb6 100644
--- a/drivers/net/usb/dm9601.c
+++ b/drivers/net/usb/dm9601.c
@@ -101,17 +101,16 @@ static void dm_write_async_callback(struct urb *urb)
101 usb_free_urb(urb); 101 usb_free_urb(urb);
102} 102}
103 103
104static void dm_write_async(struct usbnet *dev, u8 reg, u16 length, void *data) 104static void dm_write_async_helper(struct usbnet *dev, u8 reg, u8 value,
105 u16 length, void *data)
105{ 106{
106 struct usb_ctrlrequest *req; 107 struct usb_ctrlrequest *req;
107 struct urb *urb; 108 struct urb *urb;
108 int status; 109 int status;
109 110
110 devdbg(dev, "dm_write_async() reg=0x%02x length=%d", reg, length);
111
112 urb = usb_alloc_urb(0, GFP_ATOMIC); 111 urb = usb_alloc_urb(0, GFP_ATOMIC);
113 if (!urb) { 112 if (!urb) {
114 deverr(dev, "Error allocating URB in dm_write_async!"); 113 deverr(dev, "Error allocating URB in dm_write_async_helper!");
115 return; 114 return;
116 } 115 }
117 116
@@ -123,8 +122,8 @@ static void dm_write_async(struct usbnet *dev, u8 reg, u16 length, void *data)
123 } 122 }
124 123
125 req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE; 124 req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
126 req->bRequest = DM_WRITE_REGS; 125 req->bRequest = length ? DM_WRITE_REGS : DM_WRITE_REG;
127 req->wValue = 0; 126 req->wValue = cpu_to_le16(value);
128 req->wIndex = cpu_to_le16(reg); 127 req->wIndex = cpu_to_le16(reg);
129 req->wLength = cpu_to_le16(length); 128 req->wLength = cpu_to_le16(length);
130 129
@@ -142,45 +141,19 @@ static void dm_write_async(struct usbnet *dev, u8 reg, u16 length, void *data)
142 } 141 }
143} 142}
144 143
145static void dm_write_reg_async(struct usbnet *dev, u8 reg, u8 value) 144static void dm_write_async(struct usbnet *dev, u8 reg, u16 length, void *data)
146{ 145{
147 struct usb_ctrlrequest *req; 146 devdbg(dev, "dm_write_async() reg=0x%02x length=%d", reg, length);
148 struct urb *urb;
149 int status;
150 147
148 dm_write_async_helper(dev, reg, 0, length, data);
149}
150
151static void dm_write_reg_async(struct usbnet *dev, u8 reg, u8 value)
152{
151 devdbg(dev, "dm_write_reg_async() reg=0x%02x value=0x%02x", 153 devdbg(dev, "dm_write_reg_async() reg=0x%02x value=0x%02x",
152 reg, value); 154 reg, value);
153 155
154 urb = usb_alloc_urb(0, GFP_ATOMIC); 156 dm_write_async_helper(dev, reg, value, 0, NULL);
155 if (!urb) {
156 deverr(dev, "Error allocating URB in dm_write_async!");
157 return;
158 }
159
160 req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC);
161 if (!req) {
162 deverr(dev, "Failed to allocate memory for control request");
163 usb_free_urb(urb);
164 return;
165 }
166
167 req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
168 req->bRequest = DM_WRITE_REG;
169 req->wValue = cpu_to_le16(value);
170 req->wIndex = cpu_to_le16(reg);
171 req->wLength = 0;
172
173 usb_fill_control_urb(urb, dev->udev,
174 usb_sndctrlpipe(dev->udev, 0),
175 (void *)req, NULL, 0, dm_write_async_callback, req);
176
177 status = usb_submit_urb(urb, GFP_ATOMIC);
178 if (status < 0) {
179 deverr(dev, "Error submitting the control message: status=%d",
180 status);
181 kfree(req);
182 usb_free_urb(urb);
183 }
184} 157}
185 158
186static int dm_read_shared_word(struct usbnet *dev, int phy, u8 reg, u16 *value) 159static int dm_read_shared_word(struct usbnet *dev, int phy, u8 reg, u16 *value)