Subject: uftdi.c code review request (simple)
To: None <tech-misc@netbsd.org>
From: Claus Andersen <clan@wheel.dk>
List: tech-misc
Date: 09/24/2006 15:14:57
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
--0-1717552568-1159103697=:19200
Content-Type: TEXT/PLAIN; charset=iso-8859-1; format=flowed
Content-Transfer-Encoding: QUOTED-PRINTABLE
Hello!
I have made some changes to the uftdi driver on my 3.0.1 system and=20
thought it might be worth contributing them back. This is however a first=
=20
for me so I would highly appreciate any and all feedback. I have attached=
=20
my "diff -u".
1) I changed USB_MATCH to use usb_lookup like the rest of the u* drivers=20
do. I think it looks cleaner and is easier to maintain?
2) I added the following devices as they where known in Free/OpenBSD:
=09B&B Electronics uLinks RS-422/485
=09Falcom Twist GSM/GPRS modem
=09Falcom Samba 55/56 GSM/GPRS modem
=09Future Technology Devices KW
=09Future Technology Devices YS
=09Future Technology Devices Y6
=09Future Technology Devices Y8
=09Future Technology Devices IC
=09Future Technology Devices DB9
=09Future Technology Devices RS232
=09Future Technology Devices Y9
=09Future Technology Devices / Coastal ChipWorks TNC-X
=09Future Technology Devices / Matrix Orbital MX200 Series LCD
=09Future Technology Devices / Matrix Orbital LK202-24 LCD
=09Future Technology Devices / Matrix Orbital LK204-24 LCD
=09Future Technology Devices / Crystalfontz CFA-632 LCD
=09Future Technology Devices / Crystalfontz CFA-634 LCD
=09Future Technology Devices / Crystalfontz CFA-633 LCD
=09Interpid Control Systems ValueCAN
=09Interpid Control Systems NeoVI Blue
=09SIIG SIIG2 US2308 Serial
(Some of these where already listed in usbdevs but not in uftdi)
(I do only have a Falcom Samba to test against)
3) I added the "switch (uaa->vendor)" in USB_ATTACH to avoid clashing=20
product id's across vendors. The switch was choosen rather than if to make=
=20
additions easier. Switch is faster than if (Suboptimizing is still=20
optimizing ;-)) OK?
4) The "switch (uaa->product)" in USB_ATTACH seemed bloated. Only one=20
device is UFTDI_TYPE_SIO - the rest are UFTDI_TYPE_8U232AM. The previous=20
"default:" had a /* Can't happen */ comment as we should only see devices=
=20
matched by USB_MATCH. So I thought it reasonable and less prone to error=20
when adding devices to make UFTDI_TYPE_8U232AM the default?
5) If I'm wrong regarding to 3 or 4 and the devices should be handled=20
explicitly in USB_ATTACH would it not be nicer with a static struct =E1 la=
=20
"usb_lookup"?
6) It says "The ucom layer needs to be extended first" to handle more=20
ports. Has this happened?
The changes compiles cleanly and worked with my Falcom Samba 55 GSM/GPRS=20
modem:
Attach:
=09uftdi0 at uhub0 port 1
=09uftdi0: FALCOM Falcom SAMBA, rev 1.10/2.00, addr 2
=09ucom0 at uftdi0 portno 1: portno 1
Detach:
=09uftdi0: at uhub0 port 1 (addr 2) disconnected
=09ucom0 detached
=09uftdi0 detached
(and I've been able to send/receive SMS)
Kind Regards,
Claus Andersen
--0-1717552568-1159103697=:19200
Content-Type: TEXT/plain; charset=US-ASCII; name=usbdevs.diff
Content-Transfer-Encoding: BASE64
Content-ID: <20060924151457.O19200@freesbee.wheel.dk>
Content-Description: diff -u of usbdevs
Content-Disposition: attachment; filename=usbdevs.diff
LS0tIHVzYmRldnMub3JnCTIwMDYtMDktMjMgMTg6NDQ6MzguMDAwMDAwMDAw
ICswMjAwDQorKysgdXNiZGV2cwkyMDA2LTA5LTI0IDEyOjI0OjQyLjAwMDAw
MDAwMCArMDIwMA0KQEAgLTMwMCw2ICszMDAsNyBAQA0KIHZlbmRvciBESUFN
T05ECQkweDA4NDEJRGlhbW9uZA0KIHZlbmRvciBORVRHRUFSCQkweDA4NDYJ
QmF5TkVUR0VBUg0KIHZlbmRvciBBQ1RJVkVXSVJFCTB4MDg1NAlBY3RpdmVX
aXJlDQordmVuZG9yIEJCRUxFQ1RST05JQ1MgICAgMHgwODU2ICBCJkIgRWxl
Y3Ryb25pY3MNCiB2ZW5kb3IgUE9SVEdFQVIJCTB4MDg1YQlQb3J0R2Vhcg0K
IHZlbmRvciBORVRHRUFSMgkJMHgwODY0CU5ldGdlYXINCiB2ZW5kb3IgU1lT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fer-Encoding: BASE64
Content-ID: <20060924151457.S19200@freesbee.wheel.dk>
Content-Description: diff -u of /usr/src/sys/dev/usb/uftdi.c
Content-Disposition: attachment; filename=uftdi.c.diff
LS0tIHVmdGRpLmMub3JnCTIwMDYtMDktMjMgMTg6NTI6MjYuMDAwMDAwMDAw
ICswMjAwDQorKysgdWZ0ZGkuYwkyMDA2LTA5LTI0IDEzOjU5OjE3LjAwMDAw
MDAwMCArMDIwMA0KQEAgLTEyNCw2ICsxMjQsNDAgQEANCiAJdWZ0ZGlfd3Jp
dGUsDQogfTsNCiANCisvKiANCisgKiBUaGUgZGV2aWNlcyBkZWZhdWx0IHRv
IFVGVERJX1RZUEVfOFUyMzJBTS4NCisgKiBSZW1lbWJlciB0byB1cGRhdGUg
VVNCX0FUVEFDSCBpZiBpdCBzaG91bGQgYmUgVUZURElfVFlQRV9TSU8gaW5z
dGVhZA0KKyAqLw0KK3N0YXRpYyBjb25zdCBzdHJ1Y3QgdXNiX2Rldm5vIHVm
dGRpX2RldnNbXSA9IHsNCisJeyBVU0JfVkVORE9SX0JCRUxFQ1RST05JQ1Ms
IFVTQl9QUk9EVUNUX0JCRUxFQ1RST05JQ1NfVVNPVEw0IH0sDQorCXsgVVNC
X1ZFTkRPUl9GQUxDT00sIFVTQl9QUk9EVUNUX0ZBTENPTV9UV0lTVCB9LA0K
Kwl7IFVTQl9WRU5ET1JfRkFMQ09NLCBVU0JfUFJPRFVDVF9GQUxDT01fU0FN
QkEgfSwNCisJeyBVU0JfVkVORE9SX0ZUREksIFVTQl9QUk9EVUNUX0ZURElf
U0VSSUFMXzhVMTAwQVggfSwNCisJeyBVU0JfVkVORE9SX0ZUREksIFVTQl9Q
Uk9EVUNUX0ZURElfU0VSSUFMXzhVMjMyQU0gfSwNCisJeyBVU0JfVkVORE9S
X0ZUREksIFVTQl9QUk9EVUNUX0ZURElfTUhBTV9LVyB9LA0KKwl7IFVTQl9W
RU5ET1JfRlRESSwgVVNCX1BST0RVQ1RfRlRES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