Skip to content

Commit 7b99fb3

Browse files
milesg-githubnpiggin
authored andcommitted
misc/pca9552: Fix inverted input status
The pca9552 INPUT0 and INPUT1 registers are supposed to hold the logical values of the LED pins. A logical 0 should be seen in the INPUT0/1 registers for a pin when its corresponding LSn bits are set to 0, which is also the state needed for turning on an LED in a typical usage scenario. Existing code was doing the opposite and setting INPUT0/1 bit to a 1 when the LSn bit was set to 0, so this commit fixes that. Reviewed-by: Andrew Jeffery <andrew@codeconstruct.com.au> Signed-off-by: Glenn Miles <milesg@linux.vnet.ibm.com> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
1 parent 21465ad commit 7b99fb3

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

hw/misc/pca9552.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ typedef struct PCA955xClass PCA955xClass;
3636

3737
DECLARE_CLASS_CHECKERS(PCA955xClass, PCA955X,
3838
TYPE_PCA955X)
39-
39+
/*
40+
* Note: The LED_ON and LED_OFF configuration values for the PCA955X
41+
* chips are the reverse of the PCA953X family of chips.
42+
*/
4043
#define PCA9552_LED_ON 0x0
4144
#define PCA9552_LED_OFF 0x1
4245
#define PCA9552_LED_PWM0 0x2
@@ -112,13 +115,18 @@ static void pca955x_update_pin_input(PCA955xState *s)
112115

113116
switch (config) {
114117
case PCA9552_LED_ON:
115-
qemu_set_irq(s->gpio[i], 1);
116-
s->regs[input_reg] |= 1 << input_shift;
117-
break;
118-
case PCA9552_LED_OFF:
118+
/* Pin is set to 0V to turn on LED */
119119
qemu_set_irq(s->gpio[i], 0);
120120
s->regs[input_reg] &= ~(1 << input_shift);
121121
break;
122+
case PCA9552_LED_OFF:
123+
/*
124+
* Pin is set to Hi-Z to turn off LED and
125+
* pullup sets it to a logical 1.
126+
*/
127+
qemu_set_irq(s->gpio[i], 1);
128+
s->regs[input_reg] |= 1 << input_shift;
129+
break;
122130
case PCA9552_LED_PWM0:
123131
case PCA9552_LED_PWM1:
124132
/* TODO */

tests/qtest/pca9552-test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,21 @@ static void send_and_receive(void *obj, void *data, QGuestAllocator *alloc)
6060
g_assert_cmphex(value, ==, 0x55);
6161

6262
value = i2c_get8(i2cdev, PCA9552_INPUT0);
63-
g_assert_cmphex(value, ==, 0x0);
63+
g_assert_cmphex(value, ==, 0xFF);
6464

6565
pca9552_init(i2cdev);
6666

6767
value = i2c_get8(i2cdev, PCA9552_LS0);
6868
g_assert_cmphex(value, ==, 0x54);
6969

7070
value = i2c_get8(i2cdev, PCA9552_INPUT0);
71-
g_assert_cmphex(value, ==, 0x01);
71+
g_assert_cmphex(value, ==, 0xFE);
7272

7373
value = i2c_get8(i2cdev, PCA9552_LS3);
7474
g_assert_cmphex(value, ==, 0x54);
7575

7676
value = i2c_get8(i2cdev, PCA9552_INPUT1);
77-
g_assert_cmphex(value, ==, 0x10);
77+
g_assert_cmphex(value, ==, 0xEF);
7878
}
7979

8080
static void pca9552_register_nodes(void)

0 commit comments

Comments
 (0)