@samitouri / QOSamiQemu / commits / 9c99502583

hw/gpio: pca9552: move PCA955xState definition out of the header

Nothing outside pca9552.c uses the PCA955xState structure, its instance checker, or the PCA955X_NR_REGS/PCA955X_PIN_COUNT_MAX defines: the board files and qtests only rely on the TYPE_* name macros (and the register macros in pca9552_regs.h). Move the state structure and the size defines into pca9552.c, leaving pca9552.h with just the type-name macros. While at it, replace the separate DECLARE_INSTANCE_CHECKER and DECLARE_CLASS_CHECKERS declarations with a single OBJECT_DECLARE_TYPE(). Signed-off-by: Emmanuel Blot <emmanuel.blot@free.fr> Reviewed-by: Glenn Miles <milesg@linux.ibm.com> Link: https://lore.kernel.org/qemu-devel/20260709-catalina-upgrade-v1-2-814575bc076b@free.fr Signed-off-by: Cédric Le Goater <clg@redhat.com>

Emmanuel Blot committed Jul 9, 2026 at 17:23 UTC 9c995025830f1b1ee7941913dd178bf3e22a976a
2 files changed +28 -31
hw/gpio/pca9552.c
+24 -5
@@ -1,7 +1,10 @@
1 /*
2 - * PCA9552 I2C LED blinker
2 + * PCA955X I2C LED blinker and I/O expanders
3 *
4 * https://www.nxp.com/docs/en/application-note/AN264.pdf
5 + * https://www.nxp.com/docs/en/data-sheet/PCA9552.pdf
6 + * https://www.nxp.com/docs/en/data-sheet/PCA9555.pdf
7 + * https://www.nxp.com/docs/en/data-sheet/PCA9535_PCA9535C.pdf
8 *
9 * Copyright (c) 2017-2018, IBM Corporation.
10 * Copyright (c) 2020 Philippe Mathieu-Daudé
@@ -12,9 +15,9 @@
15
16 #include "qemu/osdep.h"
17 #include "qemu/log.h"
15 -#include "qemu/module.h"
18 #include "qemu/bitops.h"
19 #include "hw/core/qdev-properties.h"
20 +#include "hw/i2c/i2c.h"
21 #include "hw/gpio/pca9552.h"
22 #include "hw/gpio/pca9552_regs.h"
23 #include "hw/core/irq.h"
@@ -24,6 +27,25 @@
27 #include "trace.h"
28 #include "qom/object.h"
29
30 +#define PCA955X_NR_REGS 10
31 +#define PCA955X_PIN_COUNT_MAX 16
32 +
33 +OBJECT_DECLARE_TYPE(PCA955xState, PCA955xClass, PCA955X)
34 +
35 +struct PCA955xState {
36 + /*< private >*/
37 + I2CSlave i2c;
38 + /*< public >*/
39 +
40 + uint8_t len;
41 + uint8_t pointer;
42 +
43 + uint8_t regs[PCA955X_NR_REGS];
44 + qemu_irq gpio_out[PCA955X_PIN_COUNT_MAX];
45 + uint8_t ext_state[PCA955X_PIN_COUNT_MAX];
46 + char *description; /* For debugging purpose only */
47 +};
48 +
49 struct PCA955xClass {
50 /*< private >*/
51 I2CSlaveClass parent_class;
@@ -33,10 +55,7 @@ struct PCA955xClass {
55 uint8_t max_reg;
56 bool has_led_support;
57 };
36 -typedef struct PCA955xClass PCA955xClass;
58
38 -DECLARE_CLASS_CHECKERS(PCA955xClass, PCA955X,
39 - TYPE_PCA955X)
59 /*
60 * Note: The LED_ON and LED_OFF configuration values for the PCA955X
61 * chips are the reverse of the PCA953X family of chips.
include/hw/gpio/pca9552.h
+4 -26
@@ -1,39 +1,17 @@
1 /*
2 - * PCA9552 I2C LED blinker
2 + * PCA955X I2C LED blinker and I/O expanders
3 *
4 * Copyright (c) 2017-2018, IBM Corporation.
5 *
6 * This work is licensed under the terms of the GNU GPL, version 2 or
7 * later. See the COPYING file in the top-level directory.
8 */
9 -#ifndef PCA9552_H
10 -#define PCA9552_H
9
12 -#include "hw/i2c/i2c.h"
13 -#include "qom/object.h"
10 +#ifndef HW_GPIO_PCA9552_H
11 +#define HW_GPIO_PCA9552_H
12
15 -#define TYPE_PCA9552 "pca9552"
13 #define TYPE_PCA955X "pca955x"
14 +#define TYPE_PCA9552 "pca9552"
15 #define TYPE_PCA9535 "pca9535"
18 -typedef struct PCA955xState PCA955xState;
19 -DECLARE_INSTANCE_CHECKER(PCA955xState, PCA955X,
20 - TYPE_PCA955X)
21 -
22 -#define PCA955X_NR_REGS 10
23 -#define PCA955X_PIN_COUNT_MAX 16
24 -
25 -struct PCA955xState {
26 - /*< private >*/
27 - I2CSlave i2c;
28 - /*< public >*/
29 -
30 - uint8_t len;
31 - uint8_t pointer;
32 -
33 - uint8_t regs[PCA955X_NR_REGS];
34 - qemu_irq gpio_out[PCA955X_PIN_COUNT_MAX];
35 - uint8_t ext_state[PCA955X_PIN_COUNT_MAX];
36 - char *description; /* For debugging purpose only */
37 -};
16
17 #endif