Hello all,
As promised, below is a patchset to make eeprom->max_power consistently express
power (current) requirements in milliamperes.
I've also updated my AUTHOR address.
Regards,
Daniel
--
From 9e854c8111dba11ea71166e22ca464b474156150 Mon Sep 17 00:00:00 2001
From: Daniel Kirkham <dk2@xxxxxxxxxxxxx>
Date: Sat, 12 May 2012 19:23:57 +1000
Subject: [PATCH] Fix to make eeprom->max_power consistently express power
(current) requirements in milliamperes.
Updated AUTHOR address
---
AUTHORS | 2 +-
src/ftdi.c | 6 +++---
src/ftdi_i.h | 3 +++
3 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/AUTHORS b/AUTHORS
index aad2fe7..9762dc3 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -13,7 +13,7 @@ see Changelog for full details:
Aurelien Jarno <aurelien@xxxxxxxxxxx>
Chris Zeh <chris.w.zeh@xxxxxxxxx>
Clifford Wolf <clifford@xxxxxxxxxxx>
- Daniel Kirkham <d.kirkham@xxxxxxxxxxx>
+ Daniel Kirkham <dk2@xxxxxxxxxxxxx>
David Challis <dchallis@xxxxxxxxxxxxx>
Emil <emil@xxxxxxxxxxx>
Evan Nemerson <evan@xxxxxxxxxxxxxxx>
diff --git a/src/ftdi.c b/src/ftdi.c
index 8650be2..07687e8 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -2577,7 +2577,7 @@ int ftdi_eeprom_build(struct ftdi_context *ftdi)
output[0x08] = j;
// Addr 09: Max power consumption: max power = value * 2 mA
- output[0x09] = eeprom->max_power>>1;
+ output[0x09] = eeprom->max_power / MAX_POWER_MILLIAMP_PER_UNIT;
if (ftdi->type != TYPE_AM)
{
@@ -3048,7 +3048,7 @@ int ftdi_eeprom_decode(struct ftdi_context *ftdi, int
verbose)
eeprom->remote_wakeup = buf[0x08] & 0x20;
// Addr 09: Max power consumption: max power = value * 2 mA
- eeprom->max_power = buf[0x09];
+ eeprom->max_power = MAX_POWER_MILLIAMP_PER_UNIT * buf[0x09];
// Addr 0A: Chip configuration
// Bit 7: 0 - reserved
@@ -3264,7 +3264,7 @@ int ftdi_eeprom_decode(struct ftdi_context *ftdi, int
verbose)
if (eeprom->self_powered)
fprintf(stdout, "Self-Powered%s", (eeprom->remote_wakeup)?", USB
Remote Wake Up\n":"\n");
else
- fprintf(stdout, "Bus Powered: %3d mA%s", eeprom->max_power * 2,
+ fprintf(stdout, "Bus Powered: %3d mA%s", eeprom->max_power,
(eeprom->remote_wakeup)?" USB Remote Wake Up\n":"\n");
if (eeprom->manufacturer)
fprintf(stdout, "Manufacturer: %s\n",eeprom->manufacturer);
diff --git a/src/ftdi_i.h b/src/ftdi_i.h
index 8d8c77e..1427f05 100644
--- a/src/ftdi_i.h
+++ b/src/ftdi_i.h
@@ -21,6 +21,9 @@
/* Even on 93xx66 at max 256 bytes are used (AN_121)*/
#define FTDI_MAX_EEPROM_SIZE 256
+/** Max Power adjustment factor. */
+#define MAX_POWER_MILLIAMP_PER_UNIT 2
+
/**
\brief FTDI eeprom structure
*/
--
1.7.2.3
On 01/05/2012, at 11:59 PM, Daniel Kirkham wrote:
>
> On 29/04/2012, at 4:14 AM, Uwe Bonnes wrote:
>>>>>>> "Daniel" == Daniel Kirkham <dk2@xxxxxxxxxxxxx> writes:
>>
>> Daniel> Hi all, I just noticed an inconsistency in the handling of the
>> Daniel> max_power EEPROM value while writing a short program to
>> Daniel> reprogram my FT2232.
>>
>> Daniel> In ftdi_eeprom_build (line 2580 of ftdi.c):
>>
>> Daniel> output[0x09] = eeprom->max_power>>1;
>>
>> Daniel> Whereas: in ftdi_eeprom_decode (line 3051 of ftdi.c):
>>
>> eeprom-> max_power = buf[0x09];
>>
>> Daniel> and further down in ftdi_eeprom_decode (line 3267):
>>
>> Daniel> fprintf(stdout, "Bus Powered: %3d mA%s",
>> Daniel> eeprom->max_power * 2,
>>
>> Daniel> and ftdi_get_eeprom_value (line 3448)
>>
>> Daniel> *value = ftdi->eeprom->max_power;
>>
>> Daniel> and ftdi_set_eeprom_value (line 3635)
>>
>> ftdi-> eeprom->max_power = value;
>>
>> Daniel> So, with the exception of line 2580, the value being passed
>> Daniel> around is the power requirement expressed as half the number of
>> Daniel> milliamperes (mA) required by the device, and that line 3267
>> Daniel> correctly translates this for presentation purposes. This is
>> Daniel> consistent with the way power units are specified within the USB
>> Daniel> protocols (ie. each unit is 2mA).
>>
>> Daniel> On this basis, the bit-shift division in line 2580 should be
>> Daniel> removed: 2580: output[0x09] = eeprom->max_power;
>>
>> Daniel> Alternatively, if the API defines that max_power should be
>> Daniel> expressed directly in mA, then lines 3051 and 3267 need to be
>> Daniel> adjusted to: 3051: eeprom->max_power = buf[0x09] * 2; 3267:
>> Daniel> fprintf(stdout, "Bus Powered: %3d mA%s", eeprom->max_power,
>>
>> Daniel> Given these changes may break some usage, perhaps this needs to
>> Daniel> be discussed before patching the library one way or the other.
>>
>> Thanks for catching this error. Getting it consistant probably doesn't
>> break much but mixes more. I propose having eeprom->max_power in mA.
>>
>> Will you prepare a patch?
>
> I'm in the midst of a very busy week, so will look at preparing a patch over
> the coming weekend.
>
> Daniel
>>
>> Bye
>> --
>> Uwe Bonnes bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>>
>> Institut fuer Kernphysik Schlossgartenstrasse 9 64289 Darmstadt
>> --------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------
>>
>> --
>> libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
>> To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx
>>
>
>
> --
> libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
> To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx
>
--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx
|