From: David Fries <David@Fries.net>
To: linux-kernel@vger.kernel.org
Cc: Evgeniy Polyakov <zbr@ioremap.net>,
Marcin Jurkowski <marcin1j@gmail.com>,
Josh Boyer <jwboyer@gmail.com>,
Sven Geggus <lists@fuchsschwanzdomain.de>
Subject: [PATCH 10/14] w1: ds2490 reduce magic numbers
Date: Sun, 29 Dec 2013 00:45:52 -0600 [thread overview]
Message-ID: <1388299556-12669-11-git-send-email-David@Fries.net> (raw)
In-Reply-To: <1388299556-12669-1-git-send-email-David@Fries.net>
Use a #define for the usb vendor request type, clear the status
byte and use that instead of a magic offset in checking if idle.
Signed-off-by: David Fries <David@Fries.net>
Cc: Evgeniy Polyakov <zbr@ioremap.net>
---
drivers/w1/masters/ds2490.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/drivers/w1/masters/ds2490.c b/drivers/w1/masters/ds2490.c
index 4f7e1d7..6a3d0a1 100644
--- a/drivers/w1/masters/ds2490.c
+++ b/drivers/w1/masters/ds2490.c
@@ -1,5 +1,5 @@
/*
- * dscore.c
+ * ds2490.c USB to one wire bridge
*
* Copyright (c) 2004 Evgeniy Polyakov <zbr@ioremap.net>
*
@@ -28,6 +28,10 @@
#include "../w1_int.h"
#include "../w1.h"
+/* USB Standard */
+/* USB Control request vendor type */
+#define VENDOR 0x40
+
/* COMMAND TYPE CODES */
#define CONTROL_CMD 0x00
#define COMM_CMD 0x01
@@ -107,6 +111,8 @@
#define ST_HALT 0x10 /* DS2490 is currently halted */
#define ST_IDLE 0x20 /* DS2490 is currently idle */
#define ST_EPOF 0x80
+/* Status transfer size, 16 bytes status, 16 byte result flags */
+#define ST_SIZE 0x20
/* Result Register flags */
#define RR_DETECT 0xA5 /* New device detected */
@@ -198,7 +204,7 @@ static int ds_send_control_cmd(struct ds_device *dev, u16 value, u16 index)
int err;
err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, dev->ep[EP_CONTROL]),
- CONTROL_CMD, 0x40, value, index, NULL, 0, 1000);
+ CONTROL_CMD, VENDOR, value, index, NULL, 0, 1000);
if (err < 0) {
printk(KERN_ERR "Failed to send command control message %x.%x: err=%d.\n",
value, index, err);
@@ -213,7 +219,7 @@ static int ds_send_control_mode(struct ds_device *dev, u16 value, u16 index)
int err;
err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, dev->ep[EP_CONTROL]),
- MODE_CMD, 0x40, value, index, NULL, 0, 1000);
+ MODE_CMD, VENDOR, value, index, NULL, 0, 1000);
if (err < 0) {
printk(KERN_ERR "Failed to send mode control message %x.%x: err=%d.\n",
value, index, err);
@@ -228,7 +234,7 @@ static int ds_send_control(struct ds_device *dev, u16 value, u16 index)
int err;
err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, dev->ep[EP_CONTROL]),
- COMM_CMD, 0x40, value, index, NULL, 0, 1000);
+ COMM_CMD, VENDOR, value, index, NULL, 0, 1000);
if (err < 0) {
printk(KERN_ERR "Failed to send control message %x.%x: err=%d.\n",
value, index, err);
@@ -353,7 +359,7 @@ static int ds_recv_data(struct ds_device *dev, unsigned char *buf, int size)
err = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, dev->ep[EP_DATA_IN]),
buf, size, &count, 1000);
if (err < 0) {
- u8 buf[0x20];
+ u8 buf[ST_SIZE];
int count;
printk(KERN_INFO "Clearing ep0x%x.\n", dev->ep[EP_DATA_IN]);
@@ -398,7 +404,7 @@ int ds_stop_pulse(struct ds_device *dev, int limit)
{
struct ds_status st;
int count = 0, err = 0;
- u8 buf[0x20];
+ u8 buf[ST_SIZE];
do {
err = ds_send_control(dev, CTL_HALT_EXE_IDLE, 0);
@@ -450,10 +456,11 @@ int ds_detect(struct ds_device *dev, struct ds_status *st)
static int ds_wait_status(struct ds_device *dev, struct ds_status *st)
{
- u8 buf[0x20];
+ u8 buf[ST_SIZE];
int err, count = 0;
do {
+ st->status = 0;
err = ds_recv_status_nodump(dev, st, buf, sizeof(buf));
#if 0
if (err >= 0) {
@@ -464,7 +471,7 @@ static int ds_wait_status(struct ds_device *dev, struct ds_status *st)
printk("\n");
}
#endif
- } while (!(buf[0x08] & ST_IDLE) && !(err < 0) && ++count < 100);
+ } while (!(st->status & ST_IDLE) && !(err < 0) && ++count < 100);
if (err >= 16 && st->status & ST_EPOF) {
printk(KERN_INFO "Resetting device after ST_EPOF.\n");
--
1.7.10.4
next prev parent reply other threads:[~2013-12-29 6:54 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-29 6:45 [PATCH 00/14] w1: async netlink, search, fixes, and improvements David Fries
2013-12-29 6:45 ` [PATCH 01/14] w1: fix w1_send_slave dropping a slave id David Fries
2013-12-29 6:45 ` [PATCH 02/14] w1: fixup search to support abort from netlink David Fries
2013-12-29 6:45 ` [PATCH 03/14] w1: Only wake up the search process if it is going to be searching David Fries
2013-12-29 6:45 ` [PATCH 04/14] w1: increase w1_max_slave_count, allow write access David Fries
2013-12-29 6:45 ` [PATCH 05/14] w1: continue slave search where previous left off David Fries
2013-12-29 6:45 ` [PATCH 06/14] w1: new netlink commands, add/remove/list slaves David Fries
2013-12-29 6:45 ` [PATCH 07/14] w1: process w1 netlink commands in w1_process thread David Fries
2013-12-29 6:45 ` [PATCH 08/14] connector: add portid to unicast in addition to broadcasting David Fries
2013-12-29 6:45 ` [PATCH 09/14] w1: reply only to the requester portid David Fries
2013-12-29 6:45 ` David Fries [this message]
2013-12-29 6:45 ` [PATCH 11/14] w1: ds2490 USB setup fixes David Fries
2013-12-29 6:45 ` [PATCH 12/14] w1: ds2490 fix and enable hardware search David Fries
2013-12-29 6:45 ` [PATCH 13/14] w1: use family_data instead of rom in w1_slave David Fries
2013-12-29 6:45 ` [PATCH 14/14] w1: format for DocBook and fixes David Fries
2013-12-29 21:26 ` [PATCH 00/14] w1: async netlink, search, fixes, and improvements Evgeniy Polyakov
2014-01-15 4:52 ` [PATCH 16/16] hold bus_mutex in netlink and search David Fries
2014-01-15 20:58 ` Evgeniy Polyakov
2014-01-15 21:10 ` David Fries
2014-01-16 2:33 ` GregKH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1388299556-12669-11-git-send-email-David@Fries.net \
--to=david@fries.net \
--cc=jwboyer@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lists@fuchsschwanzdomain.de \
--cc=marcin1j@gmail.com \
--cc=zbr@ioremap.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox