Exynos: i2c, gpio and touchscreen support for NURI board
Subsystems (2)
v2 cover Exynos: i2c, gpio and touchscreen support for NURI board
This patchset adds Exynos4210 i2c and GPIO implementation along with Atmel MXT touchscreen which is used for NURI board emulation.
v1->v2
- QOM-related patches are droped (they have already been accepted);
- Added indendations for second and subsequent lines of multiple-line macro definitions;
- Weird big spaces after .field members of VMStateDescriptions are replaced with single space;
- maxtouch.c is not ARM target specific from now on.
Igor Mitsyanko (3):
exynos4210: add Exynos4210 i2c implementation
exynos4210: add exynos4210 GPIO implementation
hw: add Atmel maxtouch touchscreen implementation
Makefile.objs | 1 + Makefile.target | 1 + default-configs/arm-softmmu.mak | 1 + hw/exynos4210.c | 72 +++ hw/exynos4210.h | 67 +++ hw/exynos4210_gpio.c | 1117 +++++++++++++++++++++++++++++++++++++++ hw/exynos4210_i2c.c | 469 ++++++++++++++++ hw/exynos4_boards.c | 13 +- hw/maxtouch.c | 1079 +++++++++++++++++++++++++++++++++++++ 9 files changed, 2816 insertions(+), 4 deletions(-) create mode 100644 hw/exynos4210_gpio.c create mode 100644 hw/exynos4210_i2c.c create mode 100644 hw/maxtouch.c
Signature · 1 line
1.7.4.1
PATCH v2 1/3 exynos4210: add Exynos4210 i2c implementation
Create 9 exynos4210 i2c interfaces.
--- Makefile.target | 1 + hw/exynos4210.c | 26 +++ hw/exynos4210.h | 3 + hw/exynos4210_i2c.c | 469 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 499 insertions(+), 0 deletions(-) create mode 100644 hw/exynos4210_i2c.c
Makefile.target +1 -0
@@ -357,6 +357,7 @@ obj-arm-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.o obj-arm-y += exynos4210_gic.o exynos4210_combiner.o exynos4210.o obj-arm-y += exynos4_boards.o exynos4210_uart.o exynos4210_pwm.o obj-arm-y += exynos4210_pmu.o exynos4210_mct.o exynos4210_fimd.o +obj-arm-y += exynos4210_i2c.o obj-arm-y += arm_l2x0.o obj-arm-y += arm_mptimer.o a15mpcore.o obj-arm-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o
hw/exynos4210.c +26 -0
@@ -35,6 +35,13 @@/* MCT */ #define EXYNOS4210_MCT_BASE_ADDR 0x10050000 +/* I2C */ +#define EXYNOS4210_I2C_SHIFT 0x00010000 +#define EXYNOS4210_I2C_BASE_ADDR 0x13860000 +/* Interrupt Group of External Interrupt Combiner for I2C */ +#define EXYNOS4210_I2C_INTG 27 +#define EXYNOS4210_HDMI_INTG 16 +/* UART's definitions */ #define EXYNOS4210_UART0_BASE_ADDR 0x13800000#define EXYNOS4210_UART1_BASE_ADDR 0x13810000
@@ -242,6 +249,25 @@ Exynos4210State *exynos4210_init(MemoryRegion *system_mem, s->irq_table[exynos4210_get_irq(35, 3)]);sysbus_mmio_map (busdev,0 ,EXYNOS4210_MCT_BASE_ADDR ); +/*** I2C ***/ +for (n =0 ; n <EXYNOS4210_I2C_NUMBER ; n++) { +uint32_t addr =EXYNOS4210_I2C_BASE_ADDR +EXYNOS4210_I2C_SHIFT * n; +qemu_irq i2c_irq; + +if (n <8 ) { + i2c_irq = s->irq_table[exynos4210_get_irq (EXYNOS4210_I2C_INTG , n)]; + }else { + i2c_irq = s->irq_table[exynos4210_get_irq (EXYNOS4210_HDMI_INTG ,1 )]; + } + + dev =qdev_create (NULL ,"exynos4210.i2c" ); +qdev_init_nofail (dev); + busdev =sysbus_from_qdev (dev); +sysbus_connect_irq (busdev,0 , i2c_irq); +sysbus_mmio_map (busdev,0 , addr); + s->i2c_if[n] = (i2c_bus *)qdev_get_child_bus (dev,"i2c" ); + } +/*** UARTs ***/ exynos4210_uart_create(EXYNOS4210_UART0_BASE_ADDR, EXYNOS4210_UART0_FIFO_SIZE, 0, NULL,
hw/exynos4210.h +3 -0
@@ -74,6 +74,8 @@#define EXYNOS4210_EXT_GIC_NIRQ (160-32)#define EXYNOS4210_INT_GIC_NIRQ 64 +#define EXYNOS4210_I2C_NUMBER 9 + typedef struct Exynos4210Irq { qemu_irq int_combiner_irq[EXYNOS4210_MAX_INT_COMBINER_IN_IRQ]; qemu_irq ext_combiner_irq[EXYNOS4210_MAX_EXT_COMBINER_IN_IRQ];
@@ -95,6 +97,7 @@ typedef struct Exynos4210State {MemoryRegion dram1_mem;MemoryRegion boot_secondary;MemoryRegion bootreg_mem; +i2c_bus *i2c_if[EXYNOS4210_I2C_NUMBER ]; } Exynos4210State; Exynos4210State *exynos4210_init(MemoryRegion *system_mem,
hw/exynos4210_i2c.c new file +469 -0
469 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Re: [Qemu-devel] [PATCH V2 1/3] exynos4210: add Exynos4210 i2c implementation
Am 15.03.2012 08:35, schrieb Igor Mitsyanko:
Quoted 3 lines
Create 9 exynos4210 i2c interfaces.
Signed-off-by Igor Mitsyanko <[email protected]>
for the non-technical aspects. One remark below.
hw/exynos4210_i2c.c line 102
Quoted 12 lines
hw/exynos4210_i2c.c new file +6
-0+enum { + idle, + start_bit_received, + sending_data, + receiving_data +};
Usually our enum values are uppercase, not sure if that's a rule.
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [PATCH V2 1/3] exynos4210: add Exynos4210 i2c implementation
In reply to Igor MitsyankoQuoted 3 lines · Igor Mitsyanko
Create 9 exynos4210 i2c interfaces.
Signed-off-by Igor Mitsyanko <[email protected]>
Mostly this looks OK but I still find the i2c slave stuff odd -- should the controller really register itself as a slave on its own bus? Doesn't this mean that the controller can effectively try to talk to itself? Does the hardware let you do that?
I suspect that what's happening here is that the hardware lets you put the i2c controller into slave mode so some other device on the bus can be a master. But QEMU's i2c bus abstraction doesn't cover that use case at all...
Anyway, I don't know enough about i2c to really be able to review this patch properly in that area. Anybody?
-- PMM
Re: [Qemu-devel] [PATCH V2 1/3] exynos4210: add Exynos4210 i2c implementation
Quoted 11 lines · Peter Maydell
Quoted 3 lines · Igor Mitsyanko
Create 9 exynos4210 i2c interfaces.
Signed-off-by Igor Mitsyanko<[email protected]>Mostly this looks OK but I still find the i2c slave stuff odd -- should the controller really register itself as a slave on its own bus? Doesn't this mean that the controller can effectively try to talk to itself? Does the hardware let you do that?
Controller's master and slave i2c interfaces operate on the same single bus, so I think it should. It can't talk to itself because controller's two modes of operation are mutually exclusive. As I said, I took this approach from pxa i2c implementation, the only difference is that they register slave interface on a separate bus, but I think it's not right to do that.
Quoted 5 lines
I suspect that what's happening here is that the hardware lets you put the i2c controller into slave mode so some other device on the bus can be a master. But QEMU's i2c bus abstraction doesn't cover that use case at all...
Yes, I saw this statement in hw/i2c.h (and probably cpu i2c controller will never be used as i2c slave device by anyone), but I think we still have to implement devices exactly like they described in documentation.
Signature · 3 lines
Mitsyanko Igor ASWG, Moscow R&D center, Samsung Electronics email: [email protected]
Re: [Qemu-devel] [PATCH V2 1/3] exynos4210: add Exynos4210 i2c implementation
Quoted 9 lines · Igor Mitsyanko
Quoted 4 lines · Peter Maydell
I suspect that what's happening here is that the hardware lets you put the i2c controller into slave mode so some other device on the bus can be a master. But QEMU's i2c bus abstraction doesn't cover that use case at all...
Yes, I saw this statement in
hw/i2c.h(and probably cpu i2c controller will never be used as i2c slave device by anyone), but I think we still have to implement devices exactly like they described in documentation.
I agree with the sentiment, I'm just not sure if the code you've written is actually doing that. The right way to model this would be if our i2c bus implementation provided an interface so you could register as a device which is a master but can switch into slave mode. Failing that, maybe we should just not support switching into slave mode at all. Registering as two separate devices on the i2c bus doesn't sound right to me.
-- PMM
Re: [Qemu-devel] [PATCH V2 1/3] exynos4210: add Exynos4210 i2c implementation
Quoted 11 lines · Peter Maydell
Quoted 9 lines · Igor Mitsyanko
Quoted 4 lines · Peter Maydell
I suspect that what's happening here is that the hardware lets you put the i2c controller into slave mode so some other device on the bus can be a master. But QEMU's i2c bus abstraction doesn't cover that use case at all...
Yes, I saw this statement in
hw/i2c.h(and probably cpu i2c controller will never be used as i2c slave device by anyone), but I think we still have to implement devices exactly like they described in documentation.
Quoted 5 lines
I agree with the sentiment, I'm just not sure if the code you've written is actually doing that. The right way to model this would be if our i2c bus implementation provided an interface so you could register as a device which is a master but can switch into slave mode.
I don't think we can do that without multiple inheritance, and it wouldn't worth an effort for a feature that never going to be used.
Failing that, maybe we should just not support switching
Quoted 1 line
into slave mode at all.
Do you mean we shouldn't register EXYNOS4_I2C_SLAVE at all so some hypothetical bus master wouldn't even find EXYNOS4_I2C_SLAVE on a bus?
Maybe the best solution is to make exynos4210_i2c_slave_send() and exynos4210_i2c_slave_recv() always return -1, so a hypothetical bus master will treat EXYNOS4_I2C_SLAVE as a broken device. But that seems to behave exactly like "not register at all" approach..
And are we really sure that slave interface wouldn't work correctly in a current implementation? For example, emulated Exynos CPU issues some command to a device A on SPI line and device A in turn issues data on i2c line connected to Exynos i2c controller configured as slave. EXYNOS4_I2C_SLAVE receives a data and raises interrupt flag.
Registering as two separate devices on the
Quoted 2 lines
i2c bus doesn't sound right to me.
Why? That's how it's done in hardware, I think we can roughly consider it to be two separate devices multiplexing single bus.
Signature · 3 lines
Mitsyanko Igor ASWG, Moscow R&D center, Samsung Electronics email: [email protected]
Re: [Qemu-devel] [PATCH V2 1/3] exynos4210: add Exynos4210 i2c implementation
Quoted 11 lines · Igor Mitsyanko
Do you mean we shouldn't register
EXYNOS4_I2C_SLAVEat all so some hypothetical bus master wouldn't even findEXYNOS4_I2C_SLAVEon a bus? Maybe the best solution is to makeexynos4210_i2c_slave_send()andexynos4210_i2c_slave_recv()always return -1, so a hypothetical bus master will treatEXYNOS4_I2C_SLAVEas a broken device. But that seems to behave exactly like "not register at all" approach..
And are we really sure that slave interface wouldn't work correctly in a current implementation? For example, emulated Exynos CPU issues some command to a device A on SPI line and device A in turn issues data on i2c line connected to Exynos i2c controller configured as slave.EXYNOS4_I2C_SLAVEreceives a data and raises interrupt flag.
If there's a valid configuration that works in the existing code where we can end up receiving data correctly to the EXYNOS4_I2C_SLAVE from some other device on the i2c bus, that's fine: we can test that the code you have works OK.
If there is no valid configuration that will do that (because we don't have any support for any other device being a bus master) then the code is completely useless, untested and untestable and we shouldn't put it in.
-- PMM
Re: [Qemu-devel] [PATCH V2 1/3] exynos4210: add Exynos4210 i2c implementation
In reply to Igor MitsyankoLet me add my two cents here. I tested this patch slightly and didn't find any problems.
Quoted 259 lines · Igor Mitsyanko
Create 9 exynos4210 i2c interfaces.
Signed-off-by Igor Mitsyanko <[email protected]>--- Makefile.target | 1 + hw/exynos4210.c | 26 +++ hw/exynos4210.h | 3 + hw/exynos4210_i2c.c | 469 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 499 insertions(+), 0 deletions(-) create mode 100644 hw/exynos4210_i2c.cMakefile.target +1
-0@@ -357,6 +357,7 @@ obj-arm-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.o obj-arm-y += exynos4210_gic.o exynos4210_combiner.o exynos4210.o obj-arm-y += exynos4_boards.o exynos4210_uart.o exynos4210_pwm.o obj-arm-y += exynos4210_pmu.o exynos4210_mct.o exynos4210_fimd.o +obj-arm-y += exynos4210_i2c.o obj-arm-y += arm_l2x0.o obj-arm-y += arm_mptimer.o a15mpcore.o obj-arm-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.ohw/exynos4210.c +26
-0@@ -35,6 +35,13 @@/* MCT */ #define EXYNOS4210_MCT_BASE_ADDR 0x10050000 +/* I2C */ +#define EXYNOS4210_I2C_SHIFT 0x00010000 +#define EXYNOS4210_I2C_BASE_ADDR 0x13860000 +/* Interrupt Group of External Interrupt Combiner for I2C */ +#define EXYNOS4210_I2C_INTG 27 +#define EXYNOS4210_HDMI_INTG 16 +/* UART's definitions */ #define EXYNOS4210_UART0_BASE_ADDR 0x13800000#define EXYNOS4210_UART1_BASE_ADDR 0x13810000@@ -242,6 +249,25 @@ Exynos4210State *exynos4210_init(MemoryRegion *system_mem, s->irq_table[exynos4210_get_irq(35, 3)]);sysbus_mmio_map (busdev,0 ,EXYNOS4210_MCT_BASE_ADDR ); +/*** I2C ***/ +for (n =0 ; n <EXYNOS4210_I2C_NUMBER ; n++) { +uint32_t addr =EXYNOS4210_I2C_BASE_ADDR +EXYNOS4210_I2C_SHIFT * n; +qemu_irq i2c_irq; + +if (n <8 ) { + i2c_irq = s->irq_table[exynos4210_get_irq (EXYNOS4210_I2C_INTG , n)]; + }else { + i2c_irq = s->irq_table[exynos4210_get_irq (EXYNOS4210_HDMI_INTG ,1 )]; + } + + dev =qdev_create (NULL ,"exynos4210.i2c" ); +qdev_init_nofail (dev); + busdev =sysbus_from_qdev (dev); +sysbus_connect_irq (busdev,0 , i2c_irq); +sysbus_mmio_map (busdev,0 , addr); + s->i2c_if[n] = (i2c_bus *)qdev_get_child_bus (dev,"i2c" ); + } +/*** UARTs ***/ exynos4210_uart_create(EXYNOS4210_UART0_BASE_ADDR, EXYNOS4210_UART0_FIFO_SIZE, 0, NULL,hw/exynos4210.h +3
-0@@ -74,6 +74,8 @@#define EXYNOS4210_EXT_GIC_NIRQ (160-32)#define EXYNOS4210_INT_GIC_NIRQ 64 +#define EXYNOS4210_I2C_NUMBER 9 + typedef struct Exynos4210Irq { qemu_irq int_combiner_irq[EXYNOS4210_MAX_INT_COMBINER_IN_IRQ]; qemu_irq ext_combiner_irq[EXYNOS4210_MAX_EXT_COMBINER_IN_IRQ];@@ -95,6 +97,7 @@ typedef struct Exynos4210State {MemoryRegion dram1_mem;MemoryRegion boot_secondary;MemoryRegion bootreg_mem; +i2c_bus *i2c_if[EXYNOS4210_I2C_NUMBER ]; } Exynos4210State; Exynos4210State *exynos4210_init(MemoryRegion *system_mem,hw/exynos4210_i2c.c new file +165
-0@@ -0,0 +1,469 @@ +/* +* Exynos4210 I2C Bus Serial Interface Emulation +* +* Copyright (C) 2012 Samsung Electronics Co Ltd. +* Maksim Kozlov, <[email protected]> +* Igor Mitsyanko, <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +* for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, see <http://www.gnu.org/licenses/>. +* +*/ + +#include "qemu-timer.h" +#include "sysbus.h" +#include "i2c.h" + +#ifndef EXYNOS4_I2C_DEBUG +#define EXYNOS4_I2C_DEBUG 0 +#endif + +#define TYPE_EXYNOS4_I2C "exynos4210.i2c" +#define TYPE_EXYNOS4_I2C_SLAVE "exynos4210.i2c-slave" +#define EXYNOS4_I2C (obj) \ + OBJECT_CHECK(Exynos4210I2CState, (obj), TYPE_EXYNOS4_I2C) +#define EXYNOS4_I2C_SLAVE (obj) \ + OBJECT_CHECK(Exynos4210I2CSlave, (obj), TYPE_EXYNOS4_I2C_SLAVE) + +/* Exynos4210 I2C memory map */ +#define EXYNOS4_I2C_MEM_SIZE 0x14 +#define I2CCON_ADDR 0x00/* control register */ +#define I2CSTAT_ADDR 0x04/* control/status register */ +#define I2CADD_ADDR 0x08/* address register */ +#define I2CDS_ADDR 0x0c/* data shift register */ +#define I2CLC_ADDR 0x10/* line control register */ + +#define I2CCON_INTERRUPTS_EN (1 << 5) +#define I2CCON_INTERRUPT_PEND (1 << 4) + +#define EXYNOS4_I2C_MODE (reg) (((reg) >> 6) & 3) +#define I2C_IN_MASTER_MODE (reg) (((reg) >> 6) & 2) +#define I2CSTAT_MODE_SLAVE_Rx 0x0 +#define I2CSTAT_MODE_SLAVE_Tx 0x1 +#define I2CMODE_MASTER_Rx 0x2 +#define I2CMODE_MASTER_Tx 0x3 +#define I2CSTAT_LAST_BIT (1 << 0) +#define I2CSTAT_SLAVE_ADDR_ZERO (1 << 1) +#define I2CSTAT_SLAVE_ADDR_MATCH (1 << 2) +#define I2CSTAT_ARBITR_STATUS (1 << 3) +#define I2CSTAT_OUTPUT_EN (1 << 4) +#define I2CSTAT_START_BUSY (1 << 5) + + +#if EXYNOS4_I2C_DEBUG +#define DPRINT(fmt, args...) \ + do {fprintf(stderr, "QEMU I2C: "fmt, ## args); } while (0) + +static const char *exynos4_i2c_regs_names[] = { + [I2CCON_ADDR >>2 ] ="I2CCON" , + [I2CSTAT_ADDR >>2 ] ="I2CSTAT" , + [I2CADD_ADDR >>2 ] ="I2CADD" , + [I2CDS_ADDR >>2 ] ="I2CDS" , + [I2CLC_ADDR >>2 ] ="I2CLC" , +}; + +#else +#define DPRINT(fmt, args...) do { } while (0) +#endif + +typedef struct Exynos4210I2CSlave Exynos4210I2CSlave ; + +typedef struct Exynos4210I2CState { +SysBusDevice busdev; +MemoryRegion iomem; +i2c_bus *bus; +Exynos4210I2CSlave *slave; +qemu_irq irq; +QEMUTimer *receive_timer; +QEMUTimer *send_timer; + +uint8_t i2ccon; +uint8_t i2cstat; +uint8_t i2cadd; +uint8_t i2cds; +uint8_t i2clc; +}Exynos4210I2CState ; + +enum { + idle, + start_bit_received, + sending_data, + receiving_data +}; + +struct Exynos4210I2CSlave { +I2CSlave i2c; +Exynos4210I2CState *host; +uint32_t status; +}; + + +static inline void exynos4210_i2c_set_irq (Exynos4210I2CState *s) +{ +if (s->i2ccon &I2CCON_INTERRUPTS_EN ) { + s->i2ccon |=I2CCON_INTERRUPT_PEND ; +qemu_irq_raise (s->irq); + } +} + +static void exynos4210_i2c_data_received (void *opaque) +{ +Exynos4210I2CState *s = (Exynos4210I2CState *)opaque; +int ret; + + ret =i2c_recv (s->bus); +if (ret <0 ) { + s->i2cstat |=I2CSTAT_LAST_BIT ;/* Data is not acknowledged */ + }else { + s->i2cds = ret; + s->i2cstat &= ~I2CSTAT_LAST_BIT ;/* Data is acknowledged */ + } +exynos4210_i2c_set_irq (s); +} + +static void exynos4210_i2c_data_sent (void *opaque) +{ +Exynos4210I2CState *s = (Exynos4210I2CState *)opaque; + +if (i2c_send (s->bus, s->i2cds) <0 ) { + s->i2cstat |=I2CSTAT_LAST_BIT ;/* Data is not acknowledged */ + }else { + s->i2cstat &= ~I2CSTAT_LAST_BIT ;/* Data is acknowledged */ + } +exynos4210_i2c_set_irq (s); +} + +static uint64_t exynos4210_i2c_read (void *opaque,target_phys_addr_t offset, +unsigned size) +{ +Exynos4210I2CState *s = (Exynos4210I2CState *)opaque; +uint8_t value; + +switch (offset) { +case I2CCON_ADDR : + value = s->i2ccon; +break ; +case I2CSTAT_ADDR : + value = s->i2cstat; +break ; +case I2CADD_ADDR : + value = s->i2cadd; +break ; +case I2CDS_ADDR : + value = s->i2cds; +break ; +case I2CLC_ADDR :
hw/exynos4210_i2c.c line 175
Quoted 10 lines
hw/exynos4210_i2c.c new file +10
-0+ value = s->i2clc; +break ; +default : + value =0 ; +DPRINT ("ERROR: Bad read offset 0x%x\n" , (unsigned int )offset); +break ; + } + +DPRINT ("read %s [0x%02x] -> 0x%02x\n" , exynos4_i2c_regs_names[offset >>2 ], + (unsigned int )offset, value);
Just for security it's better to check offset to not go out of the array borders.
Quoted 22 lines
hw/exynos4210_i2c.c new file +22
-0+return value; +} + +static void exynos4210_i2c_write (void *opaque,target_phys_addr_t offset, +uint64_t value,unsigned size) +{ +Exynos4210I2CState *s = (Exynos4210I2CState *)opaque; +uint8_t v = value &0xff ; + +DPRINT ("write %s [0x%02x] <- 0x%02x\n" , exynos4_i2c_regs_names[offset >>2 ], + (unsigned int )offset, v); + +switch (offset) { +case I2CCON_ADDR : +if ((s->i2ccon &I2CCON_INTERRUPT_PEND ) && + !(v &I2CCON_INTERRUPT_PEND )) { + s->i2ccon &= ~I2CCON_INTERRUPT_PEND ; +if (!(s->i2ccon &I2CCON_INTERRUPTS_EN )) { + s->i2cstat &= ~I2CSTAT_START_BUSY ; + } +qemu_irq_lower (s->irq); +
hw/exynos4210_i2c.c line 207
Quoted 10 lines
hw/exynos4210_i2c.c new file +10
-0+if (!(s->i2cstat &I2CSTAT_OUTPUT_EN ) || + !(s->i2cstat &I2CSTAT_START_BUSY )) { + s->i2cstat &= ~I2CSTAT_START_BUSY ;/* Line is not busy */ +break ; + } +/* Continue operation if transfer is ongoing */ +if (EXYNOS4_I2C_MODE (s->i2cstat) == I2CMODE_MASTER_Rx) { +qemu_mod_timer (s->receive_timer,qemu_get_clock_ns (vm_clock)+1 ); + }else if (EXYNOS4_I2C_MODE (s->i2cstat) == I2CMODE_MASTER_Tx) { +qemu_mod_timer (s->send_timer,qemu_get_clock_ns (vm_clock) +1 );
Why do you need to use timers here? Why not just call the corresponding functions directly? I can guess because when sending new message Linux driver first enables the interrupt and then writes the stat register. Am I right?
Quoted 76 lines
hw/exynos4210_i2c.c new file +76
-0+ } + } + +/* bit 4 can't be written */ + s->i2ccon = (v & ~I2CCON_INTERRUPT_PEND ) | + (s->i2ccon &I2CCON_INTERRUPT_PEND ); +break ; +case I2CSTAT_ADDR : + s->i2cstat = + (s->i2cstat &I2CSTAT_START_BUSY ) | (v & ~I2CSTAT_START_BUSY ); + +if (!(s->i2cstat &I2CSTAT_OUTPUT_EN )) { + s->i2cstat &= ~I2CSTAT_START_BUSY ; +qemu_del_timer (s->receive_timer); +qemu_del_timer (s->send_timer); +break ; + } + +/* Nothing to do if in i2c slave mode */ +if (!I2C_IN_MASTER_MODE (s->i2cstat)) { +break ; + } + +if (v &I2CSTAT_START_BUSY ) { + s->i2cstat |=I2CSTAT_START_BUSY ;/* Line is busy */ +/* Generate start bit and send slave address */ +i2c_start_transfer (s->bus, s->i2cds >>1 , s->i2cds &0x1 ); +exynos4210_i2c_data_sent (s); + }else { +i2c_end_transfer (s->bus); +/* Linux driver may start next i2c transaction before it +* acknowledges an interrupt request from previous transaction. +* This may result in timeout waiting for I2C bus idle and +* corrupted transfer. Releasing I2C bus only after interrupt is +* accepted prevents this corruption. */ +if (!(s->i2ccon &I2CCON_INTERRUPT_PEND )) { + s->i2cstat &= ~I2CSTAT_START_BUSY ; + } + } +break ; +case I2CADD_ADDR : +if ((s->i2cstat &I2CSTAT_OUTPUT_EN ) ==0 ) { + s->i2cadd = v; +i2c_set_slave_address (&s->slave->i2c, v); + } +break ; +case I2CDS_ADDR : +if (s->i2cstat &I2CSTAT_OUTPUT_EN ) { + s->i2cds = v; + } +break ; +case I2CLC_ADDR : + s->i2clc = v; +break ; +default : +DPRINT ("ERROR: Bad write offset 0x%x\n" , (unsigned int )offset); +break ; + } +} + +static const MemoryRegionOps exynos4210_i2c_ops = { + .read = exynos4210_i2c_read, + .write = exynos4210_i2c_write, + .endianness =DEVICE_NATIVE_ENDIAN , +}; + +static const VMStateDescription exynos4210_i2c_slave_vmstate = { + .name =TYPE_EXYNOS4_I2C_SLAVE , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_I2C_SLAVE (i2c, Exynos4210I2CSlave), +VMSTATE_UINT32 (status, Exynos4210I2CSlave), +VMSTATE_END_OF_LIST () + } +};
hw/exynos4210_i2c.c line 293
Quoted 10 lines
hw/exynos4210_i2c.c new file +10
-0+ +static const VMStateDescription exynos4210_i2c_vmstate = { + .name =TYPE_EXYNOS4_I2C , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT8 (i2ccon, Exynos4210I2CState), +VMSTATE_UINT8 (i2cstat, Exynos4210I2CState), +VMSTATE_UINT8 (i2cds, Exynos4210I2CState), +VMSTATE_UINT8 (i2clc, Exynos4210I2CState),
Should i2cadd also be saved here?
Quoted 166 lines
hw/exynos4210_i2c.c new file +166
-0+VMSTATE_TIMER (receive_timer, Exynos4210I2CState), +VMSTATE_TIMER (send_timer, Exynos4210I2CState), +VMSTATE_STRUCT_POINTER (slave, Exynos4210I2CState, + exynos4210_i2c_slave_vmstate, Exynos4210I2CSlave *), + VMSTATE_END_OF_LIST() + } +}; + +static void exynos4210_i2c_reset (DeviceState *d) +{ +Exynos4210I2CState *s =EXYNOS4_I2C (d); + + s->i2ccon =0x0f ;/* 0x0X */ + s->i2cstat =0x00 ; + s->i2cds =0xff ;/* 0xXX */ + s->i2clc =0x00 ; + s->i2cadd =0xff ;/* 0xXX */ + s->slave->status = idle; +qemu_del_timer (s->receive_timer); +qemu_del_timer (s->send_timer); +} + +static int exynos4210_i2c_init (SysBusDevice *dev) +{ +Exynos4210I2CState *s =EXYNOS4_I2C (dev); +DeviceState *slave; + +memory_region_init_io (&s->iomem, &exynos4210_i2c_ops, s,TYPE_EXYNOS4_I2C , +EXYNOS4_I2C_MEM_SIZE ); +sysbus_init_mmio (dev, &s->iomem); +sysbus_init_irq (dev, &s->irq); + s->bus =i2c_init_bus (&dev->qdev,"i2c" ); + s->receive_timer = +qemu_new_timer_ns (vm_clock, exynos4210_i2c_data_received, s); + s->send_timer =qemu_new_timer_ns (vm_clock, exynos4210_i2c_data_sent, s); + +/* i2c slave initialization */ + slave =i2c_create_slave (s->bus,TYPE_EXYNOS4_I2C_SLAVE ,0xff ); + s->slave =EXYNOS4_I2C_SLAVE (slave); + s->slave->host = s; + +return 0 ; +} + +static void exynos4210_i2c_class_init (ObjectClass *class,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (class); +SysBusDeviceClass *sbc =SYS_BUS_DEVICE_CLASS (class); + + dc->vmsd = &exynos4210_i2c_vmstate; + dc->reset = exynos4210_i2c_reset; + sbc->init = exynos4210_i2c_init; +} + +static TypeInfo exynos4210_i2c_info = { + .name =TYPE_EXYNOS4_I2C , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (Exynos4210I2CState), + .class_init = exynos4210_i2c_class_init, +}; + +static int exynos4210_i2c_slave_init (I2CSlave *i2c) +{ +Exynos4210I2CSlave *s =EXYNOS4_I2C_SLAVE (i2c); + + s->status = idle; +return 0 ; +} + +static void exynos4210_i2c_slave_event (I2CSlave *i2c,enum i2c_event event) +{ +Exynos4210I2CSlave *s =EXYNOS4_I2C_SLAVE (i2c); +Exynos4210I2CState *host = s->host; + +if (!(host->i2cstat &I2CSTAT_OUTPUT_EN ) || +I2C_IN_MASTER_MODE (host->i2cstat)) { +return ; + } + +switch (event) { +case I2C_START_RECV : +case I2C_START_SEND : + host->i2cstat &= ~(I2CSTAT_SLAVE_ADDR_ZERO |I2CSTAT_SLAVE_ADDR_MATCH ); + s->status = start_bit_received; + host->i2cstat |=I2CSTAT_START_BUSY ;/* Line is busy */ +break ; +case I2C_FINISH : + s->status = idle; + host->i2cstat &= ~(I2CSTAT_SLAVE_ADDR_ZERO |I2CSTAT_SLAVE_ADDR_MATCH | +I2CSTAT_START_BUSY ); +break ; +default : +break ; + } +} + +static int exynos4210_i2c_slave_recv (I2CSlave *i2c) +{ +Exynos4210I2CSlave *s =EXYNOS4_I2C_SLAVE (i2c); +Exynos4210I2CState *host = s->host; + +if (!(host->i2cstat &I2CSTAT_OUTPUT_EN ) || +I2C_IN_MASTER_MODE (host->i2cstat)) { +return -1 ; + } + +if ((s->status != sending_data) || (EXYNOS4_I2C_MODE (host->i2cstat) != + I2CSTAT_MODE_SLAVE_Tx)) { +return -1 ; + } + +exynos4210_i2c_set_irq (host); +return host->i2cds; +} + +static int exynos4210_i2c_slave_send (I2CSlave *i2c,uint8_t data) +{ +Exynos4210I2CSlave *s =EXYNOS4_I2C_SLAVE (i2c); +Exynos4210I2CState *host = s->host; + +if (!(host->i2cstat &I2CSTAT_OUTPUT_EN ) || +I2C_IN_MASTER_MODE (host->i2cstat)) { +return -1 ; + } + +if (s->status == start_bit_received) { + host->i2cds = data; + s->status = idle; +if ((data &0xFE ) ==0 ) { + host->i2cstat |=I2CSTAT_SLAVE_ADDR_ZERO ; +return -1 ; + } +if ((host->i2cadd &0xFE ) != (data &0xFE )) { +return -1 ; + } + host->i2cstat |=I2CSTAT_SLAVE_ADDR_MATCH ; + (data &0x1 ) ? (s->status = receiving_data) : + (s->status = sending_data); +exynos4210_i2c_set_irq (host); +return 0 ; + } + +if ((s->status != receiving_data) || (EXYNOS4_I2C_MODE (host->i2cstat) != + I2CSTAT_MODE_SLAVE_Rx)) { +return -1 ; + } + + host->i2cds = data; +exynos4210_i2c_set_irq (host); +return 0 ; +} + +static void exynos4210_i2cslave_class_init (ObjectClass *klass,void *data) +{ +I2CSlaveClass *k =I2C_SLAVE_CLASS (klass); + + k->init = exynos4210_i2c_slave_init; + k->event = exynos4210_i2c_slave_event; + k->recv = exynos4210_i2c_slave_recv; + k->send = exynos4210_i2c_slave_send; +} + +static TypeInfo exynos4210_i2c_slave = { + .name =TYPE_EXYNOS4_I2C_SLAVE , + .parent =TYPE_I2C_SLAVE , + .instance_size =sizeof (Exynos4210I2CSlave),
hw/exynos4210_i2c.c line 469
Quoted 10 lines
hw/exynos4210_i2c.c new file +10
-0+ .class_init = exynos4210_i2cslave_class_init, +}; + +static void exynos4210_i2c_register_types (void ) +{ +type_register_static (&exynos4210_i2c_slave); +type_register_static (&exynos4210_i2c_info); +} + +type_init (exynos4210_i2c_register_types)
PS: This I2C implementation seems to be rather complex. Did you check what we wrote for S5PC110 (ah, I also learnt that Samsung renamed it to Exynos3210) almost three years ago
(https://gitorious.org/samsung-linux-platform/qemu/blobs/s5pc110-stable/hw/s5pc1xx_i2c.c)?
When I compared documentation and kernel driver sources for both devices I couldn't find any significant difference. Generally speaking, is it worth redoing everything from scratch instead of updating?
Re: [Qemu-devel] [PATCH V2 1/3] exynos4210: add Exynos4210 i2c implementation
Quoted 3 lines · Dmitry Zhurikhin
Let me add my two cents here. I tested this patch slightly and didn't find any problems.
Great, thanks!
Quoted 264 lines · Igor Mitsyanko
Quoted 263 lines
Create 9 exynos4210 i2c interfaces.
Signed-off-by Igor Mitsyanko<[email protected]>--- Makefile.target | 1 + hw/exynos4210.c | 26 +++ hw/exynos4210.h | 3 + hw/exynos4210_i2c.c | 469 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 499 insertions(+), 0 deletions(-)create mode 100644
hw/exynos4210_i2c.cMakefile.target +1
-0@@ -357,6 +357,7 @@ obj-arm-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.o obj-arm-y += exynos4210_gic.o exynos4210_combiner.o exynos4210.o obj-arm-y += exynos4_boards.o exynos4210_uart.o exynos4210_pwm.o obj-arm-y += exynos4210_pmu.o exynos4210_mct.o exynos4210_fimd.o +obj-arm-y += exynos4210_i2c.o obj-arm-y += arm_l2x0.o obj-arm-y += arm_mptimer.o a15mpcore.o obj-arm-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.ohw/exynos4210.c +26
-0@@ -35,6 +35,13 @@/* MCT */ #define EXYNOS4210_MCT_BASE_ADDR 0x10050000 +/* I2C */ +#define EXYNOS4210_I2C_SHIFT 0x00010000 +#define EXYNOS4210_I2C_BASE_ADDR 0x13860000 +/* Interrupt Group of External Interrupt Combiner for I2C */ +#define EXYNOS4210_I2C_INTG 27 +#define EXYNOS4210_HDMI_INTG 16 +/* UART's definitions */ #define EXYNOS4210_UART0_BASE_ADDR 0x13800000#define EXYNOS4210_UART1_BASE_ADDR 0x13810000@@ -242,6 +249,25 @@ Exynos4210State *exynos4210_init(MemoryRegion *system_mem, s->irq_table[exynos4210_get_irq(35, 3)]);sysbus_mmio_map (busdev,0 ,EXYNOS4210_MCT_BASE_ADDR ); +/*** I2C ***/ +for (n =0 ; n<EXYNOS4210_I2C_NUMBER ; n++) { +uint32_t addr =EXYNOS4210_I2C_BASE_ADDR +EXYNOS4210_I2C_SHIFT * n; +qemu_irq i2c_irq; + +if (n<8 ) { + i2c_irq = s->irq_table[exynos4210_get_irq (EXYNOS4210_I2C_INTG , n)]; + }else { + i2c_irq = s->irq_table[exynos4210_get_irq (EXYNOS4210_HDMI_INTG ,1 )]; + } + + dev =qdev_create (NULL ,"exynos4210.i2c" ); +qdev_init_nofail (dev); + busdev =sysbus_from_qdev (dev); +sysbus_connect_irq (busdev,0 , i2c_irq); +sysbus_mmio_map (busdev,0 , addr); + s->i2c_if[n] = (i2c_bus *)qdev_get_child_bus (dev,"i2c" ); + } +/*** UARTs ***/ exynos4210_uart_create(EXYNOS4210_UART0_BASE_ADDR, EXYNOS4210_UART0_FIFO_SIZE, 0, NULL,hw/exynos4210.h +3
-0@@ -74,6 +74,8 @@#define EXYNOS4210_EXT_GIC_NIRQ (160-32)#define EXYNOS4210_INT_GIC_NIRQ 64 +#define EXYNOS4210_I2C_NUMBER 9 + typedef struct Exynos4210Irq { qemu_irq int_combiner_irq[EXYNOS4210_MAX_INT_COMBINER_IN_IRQ]; qemu_irq ext_combiner_irq[EXYNOS4210_MAX_EXT_COMBINER_IN_IRQ];@@ -95,6 +97,7 @@ typedef struct Exynos4210State {MemoryRegion dram1_mem;MemoryRegion boot_secondary;MemoryRegion bootreg_mem; +i2c_bus *i2c_if[EXYNOS4210_I2C_NUMBER ]; } Exynos4210State; Exynos4210State *exynos4210_init(MemoryRegion *system_mem,hw/exynos4210_i2c.c new file +169
-0@@ -0,0 +1,469 @@ +/* +* Exynos4210 I2C Bus Serial Interface Emulation +* +* Copyright (C) 2012 Samsung Electronics Co Ltd. +* Maksim Kozlov,<[email protected]> +* Igor Mitsyanko,<[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +* for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, see<http://www.gnu.org/licenses/>. +* +*/ + +#include "qemu-timer.h" +#include "sysbus.h" +#include "i2c.h" + +#ifndef EXYNOS4_I2C_DEBUG +#define EXYNOS4_I2C_DEBUG 0 +#endif + +#define TYPE_EXYNOS4_I2C "exynos4210.i2c" +#define TYPE_EXYNOS4_I2C_SLAVE "exynos4210.i2c-slave" +#define EXYNOS4_I2C (obj) \ + OBJECT_CHECK(Exynos4210I2CState, (obj), TYPE_EXYNOS4_I2C) +#define EXYNOS4_I2C_SLAVE (obj) \ + OBJECT_CHECK(Exynos4210I2CSlave, (obj), TYPE_EXYNOS4_I2C_SLAVE) + +/* Exynos4210 I2C memory map */ +#define EXYNOS4_I2C_MEM_SIZE 0x14 +#define I2CCON_ADDR 0x00/* control register */ +#define I2CSTAT_ADDR 0x04/* control/status register */ +#define I2CADD_ADDR 0x08/* address register */ +#define I2CDS_ADDR 0x0c/* data shift register */ +#define I2CLC_ADDR 0x10/* line control register */ + +#define I2CCON_INTERRUPTS_EN (1<< 5) +#define I2CCON_INTERRUPT_PEND (1<< 4) + +#define EXYNOS4_I2C_MODE (reg) (((reg)>> 6)& 3) +#define I2C_IN_MASTER_MODE (reg) (((reg)>> 6)& 2) +#define I2CSTAT_MODE_SLAVE_Rx 0x0 +#define I2CSTAT_MODE_SLAVE_Tx 0x1 +#define I2CMODE_MASTER_Rx 0x2 +#define I2CMODE_MASTER_Tx 0x3 +#define I2CSTAT_LAST_BIT (1<< 0) +#define I2CSTAT_SLAVE_ADDR_ZERO (1<< 1) +#define I2CSTAT_SLAVE_ADDR_MATCH (1<< 2) +#define I2CSTAT_ARBITR_STATUS (1<< 3) +#define I2CSTAT_OUTPUT_EN (1<< 4) +#define I2CSTAT_START_BUSY (1<< 5) + + +#if EXYNOS4_I2C_DEBUG +#define DPRINT(fmt, args...) \ + do {fprintf(stderr, "QEMU I2C: "fmt, ## args); } while (0) + +static const char *exynos4_i2c_regs_names[] = { + [I2CCON_ADDR >>2 ] ="I2CCON" , + [I2CSTAT_ADDR >>2 ] ="I2CSTAT" , + [I2CADD_ADDR >>2 ] ="I2CADD" , + [I2CDS_ADDR >>2 ] ="I2CDS" , + [I2CLC_ADDR >>2 ] ="I2CLC" , +}; + +#else +#define DPRINT(fmt, args...) do { } while (0) +#endif + +typedef struct Exynos4210I2CSlave Exynos4210I2CSlave ; + +typedef struct Exynos4210I2CState { +SysBusDevice busdev; +MemoryRegion iomem; +i2c_bus *bus; +Exynos4210I2CSlave *slave; +qemu_irq irq; +QEMUTimer *receive_timer; +QEMUTimer *send_timer; + +uint8_t i2ccon; +uint8_t i2cstat; +uint8_t i2cadd; +uint8_t i2cds; +uint8_t i2clc; +}Exynos4210I2CState ; + +enum { + idle, + start_bit_received, + sending_data, + receiving_data +}; + +struct Exynos4210I2CSlave { +I2CSlave i2c; +Exynos4210I2CState *host; +uint32_t status; +}; + + +static inline void exynos4210_i2c_set_irq (Exynos4210I2CState *s) +{ +if (s->i2ccon&I2CCON_INTERRUPTS_EN ) { + s->i2ccon |=I2CCON_INTERRUPT_PEND ; +qemu_irq_raise (s->irq); + } +} + +static void exynos4210_i2c_data_received (void *opaque) +{ +Exynos4210I2CState *s = (Exynos4210I2CState *)opaque; +int ret; + + ret =i2c_recv (s->bus); +if (ret<0 ) { + s->i2cstat |=I2CSTAT_LAST_BIT ;/* Data is not acknowledged */ + }else { + s->i2cds = ret; + s->i2cstat&= ~I2CSTAT_LAST_BIT ;/* Data is acknowledged */ + } +exynos4210_i2c_set_irq (s); +} + +static void exynos4210_i2c_data_sent (void *opaque) +{ +Exynos4210I2CState *s = (Exynos4210I2CState *)opaque; + +if (i2c_send (s->bus, s->i2cds)<0 ) { + s->i2cstat |=I2CSTAT_LAST_BIT ;/* Data is not acknowledged */ + }else { + s->i2cstat&= ~I2CSTAT_LAST_BIT ;/* Data is acknowledged */ + } +exynos4210_i2c_set_irq (s); +} + +static uint64_t exynos4210_i2c_read (void *opaque,target_phys_addr_t offset, +unsigned size) +{ +Exynos4210I2CState *s = (Exynos4210I2CState *)opaque; +uint8_t value; + +switch (offset) { +case I2CCON_ADDR : + value = s->i2ccon; +break ; +case I2CSTAT_ADDR : + value = s->i2cstat; +break ; +case I2CADD_ADDR : + value = s->i2cadd; +break ; +case I2CDS_ADDR : + value = s->i2cds; +break ; +case I2CLC_ADDR : + value = s->i2clc; +break ; +default : + value =0 ;
Quoted 8 lines
hw/exynos4210_i2c.c line 175
Quoted 6 lines
hw/exynos4210_i2c.c new file +6
-0+DPRINT ("ERROR: Bad read offset 0x%x\n" , (unsigned int )offset); +break ; + } + +DPRINT ("read %s [0x%02x] -> 0x%02x\n" , exynos4_i2c_regs_names[offset>>2 ], + (unsigned int )offset, value);Just for security it's better to check offset to not go out of the array borders.
Ok, good point.
Quoted 28 lines
Quoted 28 lines
hw/exynos4210_i2c.c new file +28
-0+return value; +} + +static void exynos4210_i2c_write (void *opaque,target_phys_addr_t offset, +uint64_t value,unsigned size) +{ +Exynos4210I2CState *s = (Exynos4210I2CState *)opaque; +uint8_t v = value&0xff ; + +DPRINT ("write %s [0x%02x]<- 0x%02x\n" , exynos4_i2c_regs_names[offset>>2 ], + (unsigned int )offset, v); + +switch (offset) { +case I2CCON_ADDR : +if ((s->i2ccon&I2CCON_INTERRUPT_PEND )&& + !(v&I2CCON_INTERRUPT_PEND )) { + s->i2ccon&= ~I2CCON_INTERRUPT_PEND ; +if (!(s->i2ccon&I2CCON_INTERRUPTS_EN )) { + s->i2cstat&= ~I2CSTAT_START_BUSY ; + } +qemu_irq_lower (s->irq); + +if (!(s->i2cstat&I2CSTAT_OUTPUT_EN ) || + !(s->i2cstat&I2CSTAT_START_BUSY )) { + s->i2cstat&= ~I2CSTAT_START_BUSY ;/* Line is not busy */ +break ; + } +/* Continue operation if transfer is ongoing */
Quoted 8 lines
hw/exynos4210_i2c.c line 207
Quoted 4 lines
hw/exynos4210_i2c.c new file +4
-0+if (EXYNOS4_I2C_MODE (s->i2cstat) == I2CMODE_MASTER_Rx) { +qemu_mod_timer (s->receive_timer,qemu_get_clock_ns (vm_clock)+1 ); + }else if (EXYNOS4_I2C_MODE (s->i2cstat) == I2CMODE_MASTER_Tx) { +qemu_mod_timer (s->send_timer,qemu_get_clock_ns (vm_clock) +1 );Why do you need to use timers here? Why not just call the corresponding functions directly? I can guess because when sending new message Linux driver first enables the interrupt and then writes the stat register. Am I right?
Yes, and I wanted to emulate a small delay between qemu_irq_lower()
and qemu_raise_irq(), But I've just tried to replace timer usage with direct functions calling and it still works stably, I think I wil remove timers in next version.
Quoted 79 lines
Quoted 79 lines
hw/exynos4210_i2c.c new file +79
-0+ } + } + +/* bit 4 can't be written */ + s->i2ccon = (v& ~I2CCON_INTERRUPT_PEND ) | + (s->i2ccon&I2CCON_INTERRUPT_PEND ); +break ; +case I2CSTAT_ADDR : + s->i2cstat = + (s->i2cstat&I2CSTAT_START_BUSY ) | (v& ~I2CSTAT_START_BUSY ); + +if (!(s->i2cstat&I2CSTAT_OUTPUT_EN )) { + s->i2cstat&= ~I2CSTAT_START_BUSY ; +qemu_del_timer (s->receive_timer); +qemu_del_timer (s->send_timer); +break ; + } + +/* Nothing to do if in i2c slave mode */ +if (!I2C_IN_MASTER_MODE (s->i2cstat)) { +break ; + } + +if (v&I2CSTAT_START_BUSY ) { + s->i2cstat |=I2CSTAT_START_BUSY ;/* Line is busy */ +/* Generate start bit and send slave address */ +i2c_start_transfer (s->bus, s->i2cds>>1 , s->i2cds&0x1 ); +exynos4210_i2c_data_sent (s); + }else { +i2c_end_transfer (s->bus); +/* Linux driver may start next i2c transaction before it +* acknowledges an interrupt request from previous transaction. +* This may result in timeout waiting for I2C bus idle and +* corrupted transfer. Releasing I2C bus only after interrupt is +* accepted prevents this corruption. */ +if (!(s->i2ccon&I2CCON_INTERRUPT_PEND )) { + s->i2cstat&= ~I2CSTAT_START_BUSY ; + } + } +break ; +case I2CADD_ADDR : +if ((s->i2cstat&I2CSTAT_OUTPUT_EN ) ==0 ) { + s->i2cadd = v; +i2c_set_slave_address (&s->slave->i2c, v); + } +break ; +case I2CDS_ADDR : +if (s->i2cstat&I2CSTAT_OUTPUT_EN ) { + s->i2cds = v; + } +break ; +case I2CLC_ADDR : + s->i2clc = v; +break ; +default : +DPRINT ("ERROR: Bad write offset 0x%x\n" , (unsigned int )offset); +break ; + } +} + +static const MemoryRegionOps exynos4210_i2c_ops = { + .read = exynos4210_i2c_read, + .write = exynos4210_i2c_write, + .endianness =DEVICE_NATIVE_ENDIAN , +}; + +static const VMStateDescription exynos4210_i2c_slave_vmstate = { + .name =TYPE_EXYNOS4_I2C_SLAVE , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_I2C_SLAVE (i2c, Exynos4210I2CSlave), +VMSTATE_UINT32 (status, Exynos4210I2CSlave), +VMSTATE_END_OF_LIST () + } +}; + +static const VMStateDescription exynos4210_i2c_vmstate = { + .name =TYPE_EXYNOS4_I2C ,
Quoted 8 lines
hw/exynos4210_i2c.c line 293
Quoted 7 lines
hw/exynos4210_i2c.c new file +7
-0+ .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField []) { +VMSTATE_UINT8 (i2ccon, Exynos4210I2CState), +VMSTATE_UINT8 (i2cstat, Exynos4210I2CState), +VMSTATE_UINT8 (i2cds, Exynos4210I2CState), +VMSTATE_UINT8 (i2clc, Exynos4210I2CState),Should i2cadd also be saved here?
Yes
Quoted 175 lines
Quoted 175 lines
hw/exynos4210_i2c.c new file +175
-0+VMSTATE_TIMER (receive_timer, Exynos4210I2CState), +VMSTATE_TIMER (send_timer, Exynos4210I2CState), +VMSTATE_STRUCT_POINTER (slave, Exynos4210I2CState, + exynos4210_i2c_slave_vmstate, Exynos4210I2CSlave *), + VMSTATE_END_OF_LIST() + } +}; + +static void exynos4210_i2c_reset (DeviceState *d) +{ +Exynos4210I2CState *s =EXYNOS4_I2C (d); + + s->i2ccon =0x0f ;/* 0x0X */ + s->i2cstat =0x00 ; + s->i2cds =0xff ;/* 0xXX */ + s->i2clc =0x00 ; + s->i2cadd =0xff ;/* 0xXX */ + s->slave->status = idle; +qemu_del_timer (s->receive_timer); +qemu_del_timer (s->send_timer); +} + +static int exynos4210_i2c_init (SysBusDevice *dev) +{ +Exynos4210I2CState *s =EXYNOS4_I2C (dev); +DeviceState *slave; + +memory_region_init_io (&s->iomem,&exynos4210_i2c_ops, s,TYPE_EXYNOS4_I2C , +EXYNOS4_I2C_MEM_SIZE ); +sysbus_init_mmio (dev,&s->iomem); +sysbus_init_irq (dev,&s->irq); + s->bus =i2c_init_bus (&dev->qdev,"i2c" ); + s->receive_timer = +qemu_new_timer_ns (vm_clock, exynos4210_i2c_data_received, s); + s->send_timer =qemu_new_timer_ns (vm_clock, exynos4210_i2c_data_sent, s); + +/* i2c slave initialization */ + slave =i2c_create_slave (s->bus,TYPE_EXYNOS4_I2C_SLAVE ,0xff ); + s->slave =EXYNOS4_I2C_SLAVE (slave); + s->slave->host = s; + +return 0 ; +} + +static void exynos4210_i2c_class_init (ObjectClass *class,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (class); +SysBusDeviceClass *sbc =SYS_BUS_DEVICE_CLASS (class); + + dc->vmsd =&exynos4210_i2c_vmstate; + dc->reset = exynos4210_i2c_reset; + sbc->init = exynos4210_i2c_init; +} + +static TypeInfo exynos4210_i2c_info = { + .name =TYPE_EXYNOS4_I2C , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (Exynos4210I2CState), + .class_init = exynos4210_i2c_class_init, +}; + +static int exynos4210_i2c_slave_init (I2CSlave *i2c) +{ +Exynos4210I2CSlave *s =EXYNOS4_I2C_SLAVE (i2c); + + s->status = idle; +return 0 ; +} + +static void exynos4210_i2c_slave_event (I2CSlave *i2c,enum i2c_event event) +{ +Exynos4210I2CSlave *s =EXYNOS4_I2C_SLAVE (i2c); +Exynos4210I2CState *host = s->host; + +if (!(host->i2cstat&I2CSTAT_OUTPUT_EN ) || +I2C_IN_MASTER_MODE (host->i2cstat)) { +return ; + } + +switch (event) { +case I2C_START_RECV : +case I2C_START_SEND : + host->i2cstat&= ~(I2CSTAT_SLAVE_ADDR_ZERO |I2CSTAT_SLAVE_ADDR_MATCH ); + s->status = start_bit_received; + host->i2cstat |=I2CSTAT_START_BUSY ;/* Line is busy */ +break ; +case I2C_FINISH : + s->status = idle; + host->i2cstat&= ~(I2CSTAT_SLAVE_ADDR_ZERO |I2CSTAT_SLAVE_ADDR_MATCH | +I2CSTAT_START_BUSY ); +break ; +default : +break ; + } +} + +static int exynos4210_i2c_slave_recv (I2CSlave *i2c) +{ +Exynos4210I2CSlave *s =EXYNOS4_I2C_SLAVE (i2c); +Exynos4210I2CState *host = s->host; + +if (!(host->i2cstat&I2CSTAT_OUTPUT_EN ) || +I2C_IN_MASTER_MODE (host->i2cstat)) { +return -1 ; + } + +if ((s->status != sending_data) || (EXYNOS4_I2C_MODE (host->i2cstat) != + I2CSTAT_MODE_SLAVE_Tx)) { +return -1 ; + } + +exynos4210_i2c_set_irq (host); +return host->i2cds; +} + +static int exynos4210_i2c_slave_send (I2CSlave *i2c,uint8_t data) +{ +Exynos4210I2CSlave *s =EXYNOS4_I2C_SLAVE (i2c); +Exynos4210I2CState *host = s->host; + +if (!(host->i2cstat&I2CSTAT_OUTPUT_EN ) || +I2C_IN_MASTER_MODE (host->i2cstat)) { +return -1 ; + } + +if (s->status == start_bit_received) { + host->i2cds = data; + s->status = idle; +if ((data&0xFE ) ==0 ) { + host->i2cstat |=I2CSTAT_SLAVE_ADDR_ZERO ; +return -1 ; + } +if ((host->i2cadd&0xFE ) != (data&0xFE )) { +return -1 ; + } + host->i2cstat |=I2CSTAT_SLAVE_ADDR_MATCH ; + (data&0x1 ) ? (s->status = receiving_data) : + (s->status = sending_data); +exynos4210_i2c_set_irq (host); +return 0 ; + } + +if ((s->status != receiving_data) || (EXYNOS4_I2C_MODE (host->i2cstat) != + I2CSTAT_MODE_SLAVE_Rx)) { +return -1 ; + } + + host->i2cds = data; +exynos4210_i2c_set_irq (host); +return 0 ; +} + +static void exynos4210_i2cslave_class_init (ObjectClass *klass,void *data) +{ +I2CSlaveClass *k =I2C_SLAVE_CLASS (klass); + + k->init = exynos4210_i2c_slave_init; + k->event = exynos4210_i2c_slave_event; + k->recv = exynos4210_i2c_slave_recv; + k->send = exynos4210_i2c_slave_send; +} + +static TypeInfo exynos4210_i2c_slave = { + .name =TYPE_EXYNOS4_I2C_SLAVE , + .parent =TYPE_I2C_SLAVE , + .instance_size =sizeof (Exynos4210I2CSlave), + .class_init = exynos4210_i2cslave_class_init, +}; + +static void exynos4210_i2c_register_types (void ) +{ +type_register_static (&exynos4210_i2c_slave); +type_register_static (&exynos4210_i2c_info); +} +
Quoted 8 lines
hw/exynos4210_i2c.c line 469
Quoted 1 line
hw/exynos4210_i2c.c new file +1
-0+type_init (exynos4210_i2c_register_types)PS: This I2C implementation seems to be rather complex. Did you check what we wrote for S5PC110 (ah, I also learnt that Samsung renamed it to Exynos3210) almost three years ago
(https://gitorious.org/samsung-linux-platform/qemu/blobs/s5pc110-stable/hw/s5pc1xx_i2c.c)?
When I compared documentation and kernel driver sources for both devices I couldn't find any significant difference. Generally speaking, is it worth redoing everything from scratch instead of updating?
mm, it doesn't worth it, something went wrong here I think ...
Signature · 3 lines
Mitsyanko Igor ASWG, Moscow R&D center, Samsung Electronics email: [email protected]
PATCH v2 2/3 exynos4210: add exynos4210 GPIO implementation
In reply to Igor MitsyankoNow that we have GPIO emulation for exynos4210 SoC we can use it to properly hook up IRQ line to lan9215 controller on SMDK board.
--- Makefile.target | 2 +- hw/exynos4210.c | 46 ++ hw/exynos4210.h | 64 +++ hw/exynos4210_gpio.c | 1117 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/exynos4_boards.c | 2 +- 5 files changed, 1229 insertions(+), 2 deletions(-) create mode 100644 hw/exynos4210_gpio.c
Makefile.target +1 -1
@@ -357,7 +357,7 @@ obj-arm-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.o obj-arm-y += exynos4210_gic.o exynos4210_combiner.o exynos4210.o obj-arm-y += exynos4_boards.o exynos4210_uart.o exynos4210_pwm.o obj-arm-y += exynos4210_pmu.o exynos4210_mct.o exynos4210_fimd.o -obj-arm-y += exynos4210_i2c.o +obj-arm-y += exynos4210_i2c.o exynos4210_gpio.o obj-arm-y += arm_l2x0.o obj-arm-y += arm_mptimer.o a15mpcore.o obj-arm-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o
hw/exynos4210.c +46 -0
58 lines not on this page · raw message
hw/exynos4210.h +64 -0
76 lines not on this page · raw message
hw/exynos4210_gpio.c new file +1117 -0
1,117 lines not on this page · raw message
hw/exynos4_boards.c +1 -1
@@ -149,7 +149,7 @@ static void smdkc210_init(ram_addr_t ram_size, kernel_cmdline, initrd_filename, EXYNOS4_BOARD_SMDKC210);lan9215_init (SMDK_LAN9118_BASE_ADDR , -qemu_irq_invert (s->irq_table[exynos4210_get_irq (37 ,1 )])); +qdev_get_gpio_in (s->gpio2x,EXYNOS4210_GPIO2X_LINE (GPX0 ,5 )));arm_load_kernel (first_cpu, &exynos4_board_binfo); }
Signature · 1 line
1.7.4.1
Re: [Qemu-devel] [PATCH V2 2/3] exynos4210: add exynos4210 GPIO implementation
Am 15.03.2012 08:35, schrieb Igor Mitsyanko:
Quoted 4 lines
Now that we have GPIO emulation for exynos4210 SoC we can use it to properly hook up IRQ line to lan9215 controller on SMDK board.
Signed-off-by Igor Mitsyanko <[email protected]>
The patches for .instance_size were applied now, so the TypeInfos look okay, although a bit confusing at first. ;) Same for .class_size but type_initialize() seems to handle that correctly.
All static TypeInfos could be made const for a v3.
Series looks plausible; Peter should take a second, closer look though. Probably best to wait for more comments before resending minor fixes.
Thanks,
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [PATCH V2 2/3] exynos4210: add exynos4210 GPIO implementation
In reply to Igor Mitsyankohw/exynos4210_gpio.c line 37
Quoted 6 lines · Igor Mitsyanko
Now that we have GPIO emulation for exynos4210 SoC we can use it to properly hook up IRQ line to lan9215 controller on SMDK board.
hw/exynos4210_gpio.c new file +3
-0+#elif EXYNOS4210_GPIO_DEBUG ==1 +#define DPRINT_L1(fmt, args...) \ + do {fprintf(stderr, "QEMU GPIO: "fmt, ## args); } while (0)
Space after the closing quote in these macros (this patch and others), please.
Quoted 6 lines
+
+ DPRINT_L1("Input pin GPIO%s_PIN%u %s by external device\n",
+ g->ports[group_num].name, pin, (level ? "set" : "cleared"));
+ /* Set new value on corresponding gpio pin */
+ (level) ? (g->ports[group_num].dat |= (1 << pin)) :
+ (g->ports[group_num].dat &= ~(1 << pin));
Don't use ?: like this please, just write it out as an if statement.
hw/exynos4210_gpio.c line 789
Quoted 3 lines
hw/exynos4210_gpio.c new file +3
-0+static void exynos4_gpio_write (void *opaque,target_phys_addr_t off, + uint64_t value, unsigned size) +{
I find these read and write functions quite hard to read. I'm wondering if it would work better to split them up into smaller memory regions which get registered at the right addresses, rather than effectively doing the decode into different subsections based on address and g->part here?
Quoted 133 lines
+ Exynos4GpioState *g = (Exynos4GpioState *)opaque;
+ unsigned intport_end,extint_con_start,extint_con_end;
+ unsigned intextint_flt_start,extint_flt_end;
+ unsigned intextint_mask_start,extint_mask_end;
+ unsigned intextint_pend_start,extint_pend_end;
+ unsigned intetcp_start_addr,etcp_start_idx,extint_pri_end;
+ unsigned idx;hw/exynos4210_gpio.c new file +126
-0+ + DPRINT_L2("GPIO%u write off 0x%x = %u(0x%x)\n", g->part, + (uint32_t)off, (uint32_t)value, (uint32_t)value); + + switch (g->part) { + case GPIO_PART2X: + port_end = GPIO2_XPORT_END; + extint_con_start = GPIO2_WKPINT_CON_START; + extint_con_end = GPIO2_WKPINT_CON_END; + extint_flt_start = GPIO2_WKPINT_FLT_START; + extint_flt_end = GPIO2_WKPINT_FLT_END; + extint_mask_start = GPIO2_WKPINT_MASK_START; + extint_mask_end = GPIO2_WKPINT_MASK_END; + extint_pend_start = GPIO2_WKPINT_PEND_START; + extint_pend_end = GPIO2_WKPINT_PEND_END; + etcp_start_addr = etcp_start_idx = extint_pri_end = 0; + break; + case GPIO_PART1: default: + port_end = GPIO_NORM_PORT_END; + extint_con_start = GPIO_EXTINT_CON_START; + extint_con_end = GPIO1_EXTINT_CON_END; + extint_flt_start = GPIO_EXTINT_FLT_START; + extint_flt_end = GPIO1_EXTINT_FLT_END; + extint_mask_start = GPIO_EXTINT_MASK_START; + extint_mask_end = GPIO1_EXTINT_MASK_END; + extint_pend_start = GPIO_EXTINT_PEND_START; + extint_pend_end = GPIO1_EXTINT_PEND_END; + etcp_start_addr = GPIO1_ETCPORT_START; + etcp_start_idx = GPIO1_NORM_PORT_NUM; + extint_pri_end = GPIO1_EXTINT_FIXPRI_END; + break; + case GPIO_PART2: + port_end = GPIO_NORM_PORT_END; + extint_con_start = GPIO_EXTINT_CON_START; + extint_con_end = GPIO2_EXTINT_CON_END; + extint_flt_start = GPIO_EXTINT_FLT_START; + extint_flt_end = GPIO2_EXTINT_FLT_END; + extint_mask_start = GPIO_EXTINT_MASK_START; + extint_mask_end = GPIO2_EXTINT_MASK_END; + extint_pend_start = GPIO_EXTINT_PEND_START; + extint_pend_end = GPIO2_EXTINT_PEND_END; + etcp_start_addr = GPIO2_ETCPORT_START; + etcp_start_idx = GPIO2_NORM_PORT_NUM; + extint_pri_end = GPIO2_EXTINT_FIXPRI_END; + break; + case GPIO_PART3: + if (off < GPIO3_NORM_PORT_END) { + idx = DIV_BY_PORTGR_SIZE(off); + exynos4_gpio_portgr_write(g, idx, MOD_PORTGR_SIZE(off), value); + } else { + DPRINT_ERROR("GPIO3 bad write off 0x%x = %u(0x%x)\n", + (uint32_t)off, (uint32_t)value, (uint32_t)value); + } + return; + } + + if (off < port_end) { + idx = DIV_BY_PORTGR_SIZE(off); + exynos4_gpio_portgr_write(g, idx, MOD_PORTGR_SIZE(off), value); + } else if (off >= extint_mask_start && off < extint_mask_end) { + idx = (off - extint_mask_start) >> 2; + DPRINT_L1("GPIO%u EXTINT%u_MASK register write = %u(0x%x)\n", g->part, + g->port_ints[idx].int_line_num, (uint32_t)value, (uint32_t)value); + g->port_ints[idx].mask = value; + } else if (off >= extint_pend_start && off < extint_pend_end) { + idx = (off - extint_pend_start) >> 2; + DPRINT_L1("GPIO%u EXTINT%u_PEND register write = %u(0x%x)\n", g->part, + g->port_ints[idx].int_line_num, (uint32_t)value, (uint32_t)value); + if (g->part == GPIO_PART2X) { + unsigned i, irq_n; + Exynos4Gpio2XState *g2 = EXYNOS4210_GPIO2X(g); + for (i = 0; i < GPIO_MAX_PIN_IN_PORT; i++) { + if ((g->port_ints[idx].pend & (1 << i)) && (value & (1 << i))) { + g->port_ints[idx].pend &= ~(1 << i); + irq_n = idx * GPIO_MAX_PIN_IN_PORT + i; + if (irq_n >= GPIO2_X_PORT_IRQ_NUM) { + irq_n = GPIO2_X_PORT_IRQ_NUM - 1; + } + qemu_irq_lower(g2->ext_irq[irq_n]); + } + } + } else { + g->port_ints[idx].pend &= ~value; + exynos4_gpioirq_update(g); + } + } else if (off >= extint_con_start && off < extint_con_end) { + idx = (off - extint_con_start) >> 2; + DPRINT_L1("GPIO%u EXTINT%u_CON register write = %u(0x%x)\n", g->part, + g->port_ints[idx].int_line_num, (uint32_t)value, (uint32_t)value); + g->port_ints[idx].con = value; + } else if (off >= extint_flt_start && off < extint_flt_end) { + unsigned i = ((off - extint_flt_start) >> 2) & 1; + idx = (off - extint_flt_start) >> 3; + DPRINT_L1("GPIO%u EXTINT%u_FLTCON%u reg write = %u(0x%x)\n", g->part, + g->port_ints[idx].int_line_num, i, (uint32_t)value, (uint32_t)value); + g->port_ints[idx].fltcon[i] = value; + } else if (g->part == GPIO_PART2X) { + DPRINT_ERROR("GPIO2 group X bad write off 0x%x = %u(0x%x)\n", + (uint32_t)off, (uint32_t)value, (uint32_t)value); + return; + } else if (off == GPIO_EXTINT_SERVICE) { + DPRINT_L1("GPIO%u EXT_INT_SERVICE register write = %u(0x%x)\n", + g->part, (uint32_t)value, (uint32_t)value); + EXYNOS4210_GPIO_1_2(g)->extint_serv = value; + } else if (off == GPIO_EXTINT_SERVICE_PEND) { + DPRINT_L1("GPIO%u EXT_INT_SERVICE_PEND register write = %u(0x%x)\n", + g->part, (uint32_t)value, (uint32_t)value); + EXYNOS4210_GPIO_1_2(g)->extint_serv_pend = value; + } else if (off == GPIO_EXTINT_GRPFIXPRI) { + DPRINT_L1("GPIO%u EXT_INT_GRPFIXPRI register write = %u(0x%x)\n", + g->part, (uint32_t)value, (uint32_t)value); + EXYNOS4210_GPIO_1_2(g)->extint_grpfixpri = value; + } else if (off >= GPIO_EXTINT_FIXPRI_START && off < extint_pri_end) { + idx = (off - GPIO_EXTINT_FIXPRI_START) >> 2; + DPRINT_L1("GPIO%u EXTINT%u_FIXPRI register write = %u(0x%x)\n", g->part, + g->port_ints[idx].int_line_num, (uint32_t)value, (uint32_t)value); + g->port_ints[idx].fixpri = value; + } else if (off >= etcp_start_addr && off < GPIO_ETCPORT_END) { + idx = etcp_start_idx + DIV_BY_PORTGR_SIZE(off - etcp_start_addr); + exynos4_etc_portgroup_write(&g->ports[idx], + MOD_PORTGR_SIZE(off - etcp_start_addr), value); + } else { + DPRINT_ERROR("GPIO%u bad write off 0x%x = %u(0x%x)\n", g->part, + (uint32_t)off, (uint32_t)value, (uint32_t)value); + } +}
hw/exynos4210_gpio.c line 958
Quoted 10 lines
hw/exynos4210_gpio.c new file +10
-0+static void exynos4_gpio1_init (Object *obj) +{ + Exynos4GpioState *g = EXYNOS4210_GPIO(obj); + + g->part = GPIO_PART1; + g->ports = gpio1_ports; + g->port_ints = gpio1_ports_interrupts; + g->num_of_ports = sizeof(gpio1_ports) / sizeof(Exynos4PortGroup); + g->num_of_portints = + sizeof(gpio1_ports_interrupts) / sizeof(Exynos4PortIntState);
You can use the ARRAY_SIZE macro here.
-- PMM
Re: [Qemu-devel] [PATCH V2 2/3] exynos4210: add exynos4210 GPIO implementation
Quoted 11 lines · Peter Maydell
hw/exynos4210_gpio.c line 37
Quoted 6 lines · Igor Mitsyanko
Now that we have GPIO emulation for exynos4210 SoC we can use it to properly hook up IRQ line to lan9215 controller on SMDK board.
hw/exynos4210_gpio.c new file +3
-0+#elif EXYNOS4210_GPIO_DEBUG ==1 +#define DPRINT_L1(fmt, args...) \ + do {fprintf(stderr, "QEMU GPIO: "fmt, ## args); } while (0)Space after the closing quote in these macros (this patch and others), please.
Quoted 9 lines
hw/exynos4210_gpio.c
Quoted 6 lines
hw/exynos4210_gpio.c new file +6
-0+ +DPRINT_L1 ("Input pin GPIO%s_PIN%u %s by external device\n" , + g->ports[group_num].name, pin, (level ?"set" :"cleared" )); +/* Set new value on corresponding gpio pin */ + (level) ? (g->ports[group_num].dat |= (1 << pin)) : + (g->ports[group_num].dat&= ~(1 << pin));Don't use ?: like this please, just write it out as an if statement.
OK
Quoted 10 lines
hw/exynos4210_gpio.c line 789
Quoted 3 lines
hw/exynos4210_gpio.c new file +3
-0+static void exynos4_gpio_write (void *opaque,target_phys_addr_t off, +uint64_t value,unsigned size) +{I find these read and write functions quite hard to read. I'm wondering if it would work better to split them up into smaller memory regions which get registered at the right addresses, rather than effectively doing the decode into different subsections based on address and
g->parthere?
Initially I implemented these functions splitted like you suggest, but that left me with three basically identical long switch statements, so I decided to combine them into one to achieve better code reuse. If you think code reuse is not an issue here, I'll gladly return it back to splitted implementation.
Quoted 149 lines
Quoted 133 lines
hw/exynos4210_gpio.c new file +133
-0+Exynos4GpioState *g = (Exynos4GpioState *)opaque; +unsigned int port_end, extint_con_start, extint_con_end; +unsigned int extint_flt_start, extint_flt_end; +unsigned int extint_mask_start, extint_mask_end; +unsigned int extint_pend_start, extint_pend_end; +unsigned int etcp_start_addr, etcp_start_idx, extint_pri_end; +unsigned idx; + +DPRINT_L2 ("GPIO%u write off 0x%x = %u(0x%x)\n" , g->part, + (uint32_t )off, (uint32_t )value, (uint32_t )value); + +switch (g->part) { +case GPIO_PART2X : + port_end =GPIO2_XPORT_END ; + extint_con_start =GPIO2_WKPINT_CON_START ; + extint_con_end =GPIO2_WKPINT_CON_END ; + extint_flt_start =GPIO2_WKPINT_FLT_START ; + extint_flt_end =GPIO2_WKPINT_FLT_END ; + extint_mask_start =GPIO2_WKPINT_MASK_START ; + extint_mask_end =GPIO2_WKPINT_MASK_END ; + extint_pend_start =GPIO2_WKPINT_PEND_START ; + extint_pend_end =GPIO2_WKPINT_PEND_END ; + etcp_start_addr = etcp_start_idx = extint_pri_end =0 ; +break ; +case GPIO_PART1 :default : + port_end =GPIO_NORM_PORT_END ; + extint_con_start =GPIO_EXTINT_CON_START ; + extint_con_end =GPIO1_EXTINT_CON_END ; + extint_flt_start =GPIO_EXTINT_FLT_START ; + extint_flt_end =GPIO1_EXTINT_FLT_END ; + extint_mask_start =GPIO_EXTINT_MASK_START ; + extint_mask_end =GPIO1_EXTINT_MASK_END ; + extint_pend_start =GPIO_EXTINT_PEND_START ; + extint_pend_end =GPIO1_EXTINT_PEND_END ; + etcp_start_addr =GPIO1_ETCPORT_START ; + etcp_start_idx =GPIO1_NORM_PORT_NUM ; + extint_pri_end =GPIO1_EXTINT_FIXPRI_END ; +break ; +case GPIO_PART2 : + port_end =GPIO_NORM_PORT_END ; + extint_con_start =GPIO_EXTINT_CON_START ; + extint_con_end =GPIO2_EXTINT_CON_END ; + extint_flt_start =GPIO_EXTINT_FLT_START ; + extint_flt_end =GPIO2_EXTINT_FLT_END ; + extint_mask_start =GPIO_EXTINT_MASK_START ; + extint_mask_end =GPIO2_EXTINT_MASK_END ; + extint_pend_start =GPIO_EXTINT_PEND_START ; + extint_pend_end =GPIO2_EXTINT_PEND_END ; + etcp_start_addr =GPIO2_ETCPORT_START ; + etcp_start_idx =GPIO2_NORM_PORT_NUM ; + extint_pri_end =GPIO2_EXTINT_FIXPRI_END ; +break ; +case GPIO_PART3 : +if (off<GPIO3_NORM_PORT_END ) { + idx =DIV_BY_PORTGR_SIZE (off); +exynos4_gpio_portgr_write (g, idx,MOD_PORTGR_SIZE (off), value); + }else { +DPRINT_ERROR ("GPIO3 bad write off 0x%x = %u(0x%x)\n" , + (uint32_t )off, (uint32_t )value, (uint32_t )value); + } +return ; + } + +if (off< port_end) { + idx =DIV_BY_PORTGR_SIZE (off); +exynos4_gpio_portgr_write (g, idx,MOD_PORTGR_SIZE (off), value); + }else if (off>= extint_mask_start&& off< extint_mask_end) { + idx = (off - extint_mask_start)>>2 ; +DPRINT_L1 ("GPIO%u EXTINT%u_MASK register write = %u(0x%x)\n" , g->part, + g->port_ints[idx].int_line_num, (uint32_t )value, (uint32_t )value); + g->port_ints[idx].mask = value; + }else if (off>= extint_pend_start&& off< extint_pend_end) { + idx = (off - extint_pend_start)>>2 ; +DPRINT_L1 ("GPIO%u EXTINT%u_PEND register write = %u(0x%x)\n" , g->part, + g->port_ints[idx].int_line_num, (uint32_t )value, (uint32_t )value); +if (g->part ==GPIO_PART2X ) { +unsigned i, irq_n; +Exynos4Gpio2XState *g2 =EXYNOS4210_GPIO2X (g); +for (i =0 ; i<GPIO_MAX_PIN_IN_PORT ; i++) { +if ((g->port_ints[idx].pend& (1 << i))&& (value& (1 << i))) { + g->port_ints[idx].pend&= ~(1 << i); + irq_n = idx *GPIO_MAX_PIN_IN_PORT + i; +if (irq_n>=GPIO2_X_PORT_IRQ_NUM ) { + irq_n =GPIO2_X_PORT_IRQ_NUM -1 ; + } +qemu_irq_lower (g2->ext_irq[irq_n]); + } + } + }else { + g->port_ints[idx].pend&= ~value; +exynos4_gpioirq_update (g); + } + }else if (off>= extint_con_start&& off< extint_con_end) { + idx = (off - extint_con_start)>>2 ; +DPRINT_L1 ("GPIO%u EXTINT%u_CON register write = %u(0x%x)\n" , g->part, + g->port_ints[idx].int_line_num, (uint32_t )value, (uint32_t )value); + g->port_ints[idx].con = value; + }else if (off>= extint_flt_start&& off< extint_flt_end) { +unsigned i = ((off - extint_flt_start)>>2 )&1 ; + idx = (off - extint_flt_start)>>3 ; +DPRINT_L1 ("GPIO%u EXTINT%u_FLTCON%u reg write = %u(0x%x)\n" , g->part, + g->port_ints[idx].int_line_num, i, (uint32_t )value, (uint32_t )value); + g->port_ints[idx].fltcon[i] = value; + }else if (g->part ==GPIO_PART2X ) { +DPRINT_ERROR ("GPIO2 group X bad write off 0x%x = %u(0x%x)\n" , + (uint32_t )off, (uint32_t )value, (uint32_t )value); +return ; + }else if (off ==GPIO_EXTINT_SERVICE ) { +DPRINT_L1 ("GPIO%u EXT_INT_SERVICE register write = %u(0x%x)\n" , + g->part, (uint32_t )value, (uint32_t )value); +EXYNOS4210_GPIO_1_2 (g)->extint_serv = value; + }else if (off ==GPIO_EXTINT_SERVICE_PEND ) { +DPRINT_L1 ("GPIO%u EXT_INT_SERVICE_PEND register write = %u(0x%x)\n" , + g->part, (uint32_t )value, (uint32_t )value); +EXYNOS4210_GPIO_1_2 (g)->extint_serv_pend = value; + }else if (off ==GPIO_EXTINT_GRPFIXPRI ) { +DPRINT_L1 ("GPIO%u EXT_INT_GRPFIXPRI register write = %u(0x%x)\n" , + g->part, (uint32_t )value, (uint32_t )value); +EXYNOS4210_GPIO_1_2 (g)->extint_grpfixpri = value; + }else if (off>=GPIO_EXTINT_FIXPRI_START && off< extint_pri_end) { + idx = (off -GPIO_EXTINT_FIXPRI_START )>>2 ; +DPRINT_L1 ("GPIO%u EXTINT%u_FIXPRI register write = %u(0x%x)\n" , g->part, + g->port_ints[idx].int_line_num, (uint32_t )value, (uint32_t )value); + g->port_ints[idx].fixpri = value; + }else if (off>= etcp_start_addr&& off<GPIO_ETCPORT_END ) { + idx = etcp_start_idx +DIV_BY_PORTGR_SIZE (off - etcp_start_addr); +exynos4_etc_portgroup_write (&g->ports[idx], +MOD_PORTGR_SIZE (off - etcp_start_addr), value); + }else { +DPRINT_ERROR ("GPIO%u bad write off 0x%x = %u(0x%x)\n" , g->part, + (uint32_t )off, (uint32_t )value, (uint32_t )value); + } +}hw/exynos4210_gpio.c line 958
Quoted 10 lines
hw/exynos4210_gpio.c new file +10
-0+static void exynos4_gpio1_init (Object *obj) +{ +Exynos4GpioState *g =EXYNOS4210_GPIO (obj); + + g->part =GPIO_PART1 ; + g->ports = gpio1_ports; + g->port_ints = gpio1_ports_interrupts; + g->num_of_ports =sizeof (gpio1_ports) /sizeof (Exynos4PortGroup); + g->num_of_portints = +sizeof (gpio1_ports_interrupts) /sizeof (Exynos4PortIntState);You can use the
ARRAY_SIZEmacro here.-- PMM
Signature · 3 lines
Mitsyanko Igor ASWG, Moscow R&D center, Samsung Electronics email: [email protected]
PATCH v2 3/3 hw: add Atmel maxtouch touchscreen implementation
In reply to Igor MitsyankoAnd use it for exynos4210 NURI board emulation
--- Makefile.objs | 1 + default-configs/arm-softmmu.mak | 1 + hw/exynos4_boards.c | 11 +- hw/maxtouch.c | 1079 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 1089 insertions(+), 3 deletions(-) create mode 100644 hw/maxtouch.c
Makefile.objs +1 -0
@@ -248,6 +248,7 @@ hw-obj-$(CONFIG_SMARTCARD) += usb/dev-smartcard-reader.o ccid-card-passthru.o hw-obj-$(CONFIG_SMARTCARD_NSS) += ccid-card-emulated.o hw-obj-$(CONFIG_USB_REDIR) += usb/redirect.o hw-obj-$(CONFIG_I8259) += i8259_common.o i8259.o +hw-obj-$(CONFIG_MAXTOUCH) += maxtouch.o # PPC devices hw-obj-$(CONFIG_PREP_PCI) += prep_pci.o
default-configs/arm-softmmu.mak +1 -0
@@ -27,3 +27,4 @@ CONFIG_SMC91C111=y CONFIG_DS1338=y CONFIG_PFLASH_CFI01=y CONFIG_PFLASH_CFI02=y +CONFIG_MAXTOUCH=y
hw/exynos4_boards.c +8 -3
@@ -28,6 +28,7 @@#include "exec-memory.h" #include "exynos4210.h" #include "boards.h" +#include "i2c.h" #undef DEBUG
@@ -44,6 +45,7 @@#endif #define SMDK_LAN9118_BASE_ADDR 0x05000000 +#define MAXTOUCH_TS_I2C_ADDR 0x4a typedef enum Exynos4BoardType { EXYNOS4_BOARD_NURI,
@@ -134,9 +136,12 @@ static void nuri_init(ram_addr_t ram_size, const char *kernel_filename, const char *kernel_cmdline, const char *initrd_filename, const char *cpu_model) { -exynos4_boards_init_common (kernel_filename ,kernel_cmdline , -initrd_filename ,EXYNOS4_BOARD_NURI ); - + Exynos4210State *cpu = exynos4_boards_init_common(kernel_filename, + kernel_cmdline, initrd_filename,EXYNOS4_BOARD_NURI ); +DeviceState *dev = +i2c_create_slave (cpu->i2c_if[3 ],"maxtouch.var0" ,MAXTOUCH_TS_I2C_ADDR ); +qdev_connect_gpio_out (dev,0 ,qdev_get_gpio_in (cpu->gpio2x, +EXYNOS4210_GPIO2X_LINE (GPX0 ,4 )));arm_load_kernel (first_cpu, &exynos4_board_binfo); }
hw/maxtouch.c new file +1079 -0
1,079 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Re: [Qemu-devel] [PATCH V2 3/3] hw: add Atmel maxtouch touchscreen implementation
Am 15.03.2012 08:35, schrieb Igor Mitsyanko:
Quoted 3 lines
And use it for exynos4210 NURI board emulation
Signed-off-by Igor Mitsyanko <[email protected]>
Thanks for moving this to libhw. Looks okay, not knowing I2C or the device and assuming you've tested it; some nitpicks below.
Quoted 6 lines
hw/exynos4_boards.c +0
-0
hw/exynos4_boards.c static void nuri_init(ram_addr_t ram_size, · line 140
Quoted 8 lines
hw/exynos4_boards.c +2
-3@@ -134,9 +136,12 @@ static void nuri_init(ram_addr_t ram_size, const char *kernel_filename, const char *kernel_cmdline, const char *initrd_filename, const char *cpu_model) { -exynos4_boards_init_common (kernel_filename ,kernel_cmdline , -initrd_filename ,EXYNOS4_BOARD_NURI ); - + Exynos4210State *cpu = exynos4_boards_init_common(kernel_filename, + kernel_cmdline, initrd_filename,EXYNOS4_BOARD_NURI );
I'd advise against using "cpu" for what looks like board or SoC state to avoid confusion. "cpu" is going to be used for CPUState instances, i.e. one day: ARMCPU *cpu = cpu_arm_init("cortex-a9");
I'd suggest s (generically for state) here.
Quoted 13 lines
hw/exynos4_boards.c +4
-0+DeviceState *dev = +i2c_create_slave (cpu->i2c_if[3 ],"maxtouch.var0" ,MAXTOUCH_TS_I2C_ADDR ); +qdev_connect_gpio_out (dev,0 ,qdev_get_gpio_in (cpu->gpio2x, +EXYNOS4210_GPIO2X_LINE (GPX0 ,4 )));arm_load_kernel (first_cpu, &exynos4_board_binfo); }hw/maxtouch.c new file +0
-0
hw/maxtouch.c line 4
Quoted 4 lines
hw/maxtouch.c new file +4
-0@@ -0,0 +1,1079 @@ +/* +* Atmel maXTouch touchscreen emulation +* +* Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
It's been remarked that "All rights reserved." conflicts with the GPL's copyleft. Please drop that sentence if you can.
Quoted 19 lines
hw/maxtouch.c new file +18
-0+* Igor Mitsyanko <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +* for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, see <http://www.gnu.org/licenses/>. +* +*/ +/* Object types */ +enum {
hw/maxtouch.c line 77
Quoted 10 lines
hw/maxtouch.c new file +10
-0+MXT_GEN_MESSAGE_T5 =0 ,MXT_GEN_COMMAND_T6 , +MXT_GEN_POWER_T7 ,MXT_GEN_ACQUIRE_T8 , +MXT_TOUCH_MULTI_T9 ,MXT_TOUCH_KEYARRAY_T15 , +MXT_SPT_COMMSCONFIG_T18 ,MXT_SPT_GPIOPWM_T19 , +MXT_PROCI_GRIPFACE_T20 ,MXT_PROCG_NOISE_T22 , +MXT_TOUCH_PROXIMITY_T23 ,MXT_PROCI_ONETOUCH_T24 , +MXT_SPT_SELFTEST_T25 ,MXT_PROCI_TWOTOUCH_T27 , +MXT_SPT_CTECONFIG_T28 ,MXT_DEBUG_DIAGNOSTIC_T37 , +MXT_NUM_OF_OBJECT_TYPES +};
Personally I find it easier to read a mostly monotonically increasing enum (or array below) when it's not in two columns. Was this copied from some Linux header as is so that we wouldn't want to reformat it to allow for easy updates, or was this a design choice of yours?
Quoted 6 lines
hw/maxtouch.c new file +6
-0+#define TYPE_MAXTOUCH "maxtouch" +#define MXT (obj) \ + OBJECT_CHECK(MXTState, (obj), TYPE_MAXTOUCH) +#define MXT_CLASS (klass) \ + OBJECT_CLASS_CHECK(MXTClass, (klass), TYPE_MAXTOUCH) +#define MXT_GET_CLASS (obj) \
hw/maxtouch.c line 232
Quoted 10 lines
hw/maxtouch.c new file +9
-0+ OBJECT_GET_CLASS(MXTClass, (obj), TYPE_MAXTOUCH) +static const uint8_t mxt_variant0_info[MXT_INFO_SIZE ] = { + [MXT_FAMILY_ID ] =0x80 , + [MXT_VARIANT_ID ] =0x0 , + [MXT_VERSION ] =0x1 , + [MXT_BUILD ] =0x1 , + [MXT_MATRIX_X_SIZE ] =16 , + [MXT_MATRIX_Y_SIZE ] =14 , + [MXT_OBJ_NUM ] =sizeof (mxt_variant0_objlist) /sizeof (ObjConfig),
We have an ARRAY_SIZE() macro for this.
hw/maxtouch.c line 258
Quoted 10 lines
hw/maxtouch.c new file +9
-0+}; +static const uint8_t mxt_variant1_info[MXT_INFO_SIZE ] = { + [MXT_FAMILY_ID ] =0x80 , + [MXT_VARIANT_ID ] =0x1 , + [MXT_VERSION ] =0x1 , + [MXT_BUILD ] =0x1 , + [MXT_MATRIX_X_SIZE ] =16 , + [MXT_MATRIX_Y_SIZE ] =14 , + [MXT_OBJ_NUM ] =sizeof (mxt_variant1_objlist) /sizeof (ObjConfig),
Dito.
Quoted 7 lines
hw/maxtouch.c new file +7
-0+}; + +static const MXTVariantInfo mxt_variants_info_array[] = { + { + .name =TYPE_MXT_VARIANT0 , + .mxt_variant_info = mxt_variant0_info, + .mxt_variant_obj_list = mxt_variant0_objlist
hw/maxtouch.c line 275
Quoted 10 lines
hw/maxtouch.c new file +10
-0+ }, + { + .name = TYPE_MXT_VARIANT1, + .mxt_variant_info = mxt_variant1_info, + .mxt_variant_obj_list = mxt_variant1_objlist + } +}; + +#define MXT_NUM_OF_VARIANTS \ + (sizeof(mxt_variants_info_array) / sizeof(MXTVariantInfo))
Dito.
hw/maxtouch.c line 359
Quoted 7 lines
hw/maxtouch.c new file +7
-0+#if MXT_DEBUG +#define DPRINT(fmt, args...) \ + do {fprintf(stderr, "QEMU MXT: "fmt, ## args); } while (0) +#define DPRINT_SMPL(fmt, args...) \ + do {fprintf(stderr, fmt, ## args); } while (0) +#define ERRPRINT(fmt, args...) \ + do {fprintf(stderr, "QEMU MXT ERROR: "fmt, ## args); } while (0)
Please insert a space after do {. Also somewhere below.
Quoted 1 line
+static TypeInfo
maxtouch_type_info= {
Can be static const.
hw/maxtouch.c line 1069
Quoted 10 lines
hw/maxtouch.c new file +10
-0+ .name = TYPE_MAXTOUCH, + .parent = TYPE_I2C_SLAVE, + .instance_size = sizeof(MXTState), + .instance_init = mxt_init, + .instance_finalize = mxt_finalize, + .abstract = true, + .class_size = sizeof(MXTClass), +}; + +static void mxt_types_init (void )
Please name it mxt_register_types by convention.
hw/maxtouch.c line 1079
Quoted 10 lines
hw/maxtouch.c new file +10
-0+{ +unsigned i; + +type_register_static (&maxtouch_type_info); +for (i =0 ; i <MXT_NUM_OF_VARIANTS ; i++) { +mxt_register_type (&mxt_variants_info_array[i]); + } +} + +type_init (mxt_types_init)
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [PATCH V2 3/3] hw: add Atmel maxtouch touchscreen implementation
Dear Andreas,
"All rights reserved" was added by accident and going to be removed on next
update of all our patches.
Thanks,
Dmitry Solodkiy,
Emulator/Kernel PL, Mobile Group,
Moscow R&D center, Samsung Electronics
-----Original Message-----
From: Andreas Färber [mailto:[email protected]]
Sent: Thursday, March 15, 2012 1:48 PM
To: Igor Mitsyanko
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [Qemu-devel] [PATCH V2 3/3] hw: add Atmel maxtouch touchscreen implementation
Am 15.03.2012 08:35, schrieb Igor Mitsyanko:
Quoted 3 lines
And use it for exynos4210 NURI board emulation
Signed-off-by Igor Mitsyanko <[email protected]>
Thanks for moving this to libhw. Looks okay, not knowing I2C or the device and assuming you've tested it; some nitpicks below.
hw/exynos4_boards.c static void nuri_init(ram_addr_t ram_size, · line 139
Quoted 13 lines
hw/exynos4_boards.c index renamed from hw/exynos4_boards.c +0
-0b438361..f851026 100644
hw/exynos4_boards.c +2
-3@@ -134,9 +136,12 @@ static void nuri_init(ram_addr_t ram_size, const char *kernel_filename, const char *kernel_cmdline, const char *initrd_filename, const char *cpu_model) { -exynos4_boards_init_common (kernel_filename ,kernel_cmdline , -initrd_filename ,EXYNOS4_BOARD_NURI ); - + Exynos4210State *cpu = exynos4_boards_init_common(kernel_filename, + kernel_cmdline, initrd_filename,EXYNOS4_BOARD_NURI );
I'd advise against using "cpu" for what looks like board or SoC state to avoid confusion. "cpu" is going to be used for CPUState instances, i.e. one day: ARMCPU *cpu = cpu_arm_init("cortex-a9");
I'd suggest s (generically for state) here.
hw/exynos4_boards.c static void nuri_init(ram_addr_t ram_size, · line 141
Quoted 2 lines
hw/exynos4_boards.c +2
-0+DeviceState *dev = + i2c_create_slave(cpu->i2c_if[3], "maxtouch.var0",
MAXTOUCH_TS_I2C_ADDR);
hw/maxtouch.c line 4
Quoted 13 lines
hw/exynos4_boards.c +2
-0+qdev_connect_gpio_out (dev,0 ,qdev_get_gpio_in (cpu->gpio2x, +EXYNOS4210_GPIO2X_LINE (GPX0 ,4 )));arm_load_kernel (first_cpu, &exynos4_board_binfo); }hw/maxtouch.c new file mode 100644 index renamed from hw/maxtouch.c +0
-00000000..0c37d30
hw/maxtouch.c new file +4
-0@@ -0,0 +1,1079 @@ +/* +* Atmel maXTouch touchscreen emulation +* +* Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
It's been remarked that "All rights reserved." conflicts with the GPL's copyleft. Please drop that sentence if you can.
Quoted 25 lines
hw/maxtouch.c new file +24
-0+* Igor Mitsyanko <[email protected]> +* +* This program is free software; you can redistribute it and/or +modify it +* under the terms of the GNU General Public License as published by +the +* Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +but WITHOUT +* ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +License +* for more details. +* +* You should have received a copy of the GNU General Public License +along +* with this program; if not, see <http://www.gnu.org/licenses/>. +* +*/ +/* Object types */ +enum {
hw/maxtouch.c line 77
Quoted 10 lines
hw/maxtouch.c new file +10
-0+MXT_GEN_MESSAGE_T5 =0 ,MXT_GEN_COMMAND_T6 , +MXT_GEN_POWER_T7 ,MXT_GEN_ACQUIRE_T8 , +MXT_TOUCH_MULTI_T9 ,MXT_TOUCH_KEYARRAY_T15 , +MXT_SPT_COMMSCONFIG_T18 ,MXT_SPT_GPIOPWM_T19 , +MXT_PROCI_GRIPFACE_T20 ,MXT_PROCG_NOISE_T22 , +MXT_TOUCH_PROXIMITY_T23 ,MXT_PROCI_ONETOUCH_T24 , +MXT_SPT_SELFTEST_T25 ,MXT_PROCI_TWOTOUCH_T27 , +MXT_SPT_CTECONFIG_T28 ,MXT_DEBUG_DIAGNOSTIC_T37 , +MXT_NUM_OF_OBJECT_TYPES +};
Personally I find it easier to read a mostly monotonically increasing enum (or array below) when it's not in two columns. Was this copied from some Linux header as is so that we wouldn't want to reformat it to allow for easy updates, or was this a design choice of yours?
Quoted 6 lines
hw/maxtouch.c new file +6
-0+#define TYPE_MAXTOUCH "maxtouch" +#define MXT (obj) \ + OBJECT_CHECK(MXTState, (obj), TYPE_MAXTOUCH) +#define MXT_CLASS (klass) \ + OBJECT_CLASS_CHECK(MXTClass, (klass), TYPE_MAXTOUCH) +#define MXT_GET_CLASS (obj) \
hw/maxtouch.c line 232
Quoted 10 lines
hw/maxtouch.c new file +9
-0+ OBJECT_GET_CLASS(MXTClass, (obj), TYPE_MAXTOUCH) +static const uint8_t mxt_variant0_info[MXT_INFO_SIZE ] = { + [MXT_FAMILY_ID ] =0x80 , + [MXT_VARIANT_ID ] =0x0 , + [MXT_VERSION ] =0x1 , + [MXT_BUILD ] =0x1 , + [MXT_MATRIX_X_SIZE ] =16 , + [MXT_MATRIX_Y_SIZE ] =14 , + [MXT_OBJ_NUM ] =sizeof (mxt_variant0_objlist) /sizeof (ObjConfig),
We have an ARRAY_SIZE() macro for this.
hw/maxtouch.c line 258
Quoted 10 lines
hw/maxtouch.c new file +9
-0+}; +static const uint8_t mxt_variant1_info[MXT_INFO_SIZE ] = { + [MXT_FAMILY_ID ] =0x80 , + [MXT_VARIANT_ID ] =0x1 , + [MXT_VERSION ] =0x1 , + [MXT_BUILD ] =0x1 , + [MXT_MATRIX_X_SIZE ] =16 , + [MXT_MATRIX_Y_SIZE ] =14 , + [MXT_OBJ_NUM ] =sizeof (mxt_variant1_objlist) /sizeof (ObjConfig),
Dito.
Quoted 7 lines
hw/maxtouch.c new file +7
-0+}; + +static const MXTVariantInfo mxt_variants_info_array[] = { + { + .name =TYPE_MXT_VARIANT0 , + .mxt_variant_info = mxt_variant0_info, + .mxt_variant_obj_list = mxt_variant0_objlist
hw/maxtouch.c line 275
Quoted 10 lines
hw/maxtouch.c new file +10
-0+ }, + { + .name = TYPE_MXT_VARIANT1, + .mxt_variant_info = mxt_variant1_info, + .mxt_variant_obj_list = mxt_variant1_objlist + } +}; + +#define MXT_NUM_OF_VARIANTS \ + (sizeof(mxt_variants_info_array) / sizeof(MXTVariantInfo))
Dito.
hw/maxtouch.c line 359
Quoted 7 lines
hw/maxtouch.c new file +7
-0+#if MXT_DEBUG +#define DPRINT(fmt, args...) \ + do {fprintf(stderr, "QEMU MXT: "fmt, ## args); } while (0) +#define DPRINT_SMPL(fmt, args...) \ + do {fprintf(stderr, fmt, ## args); } while (0) +#define ERRPRINT(fmt, args...) \ + do {fprintf(stderr, "QEMU MXT ERROR: "fmt, ## args); } while (0)
Please insert a space after do {. Also somewhere below.
Quoted 1 line
+static TypeInfo
maxtouch_type_info= {
Can be static const.
hw/maxtouch.c line 1069
Quoted 10 lines
hw/maxtouch.c new file +10
-0+ .name = TYPE_MAXTOUCH, + .parent = TYPE_I2C_SLAVE, + .instance_size = sizeof(MXTState), + .instance_init = mxt_init, + .instance_finalize = mxt_finalize, + .abstract = true, + .class_size = sizeof(MXTClass), +}; + +static void mxt_types_init (void )
Please name it mxt_register_types by convention.
hw/maxtouch.c line 1079
Quoted 10 lines
hw/maxtouch.c new file +10
-0+{ +unsigned i; + +type_register_static (&maxtouch_type_info); +for (i =0 ; i <MXT_NUM_OF_VARIANTS ; i++) { +mxt_register_type (&mxt_variants_info_array[i]); + } +} + +type_init (mxt_types_init)
Andreas
--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [PATCH V2 3/3] hw: add Atmel maxtouch touchscreen implementation
In reply to Andreas FärberQuoted 27 lines · Andreas Färber
Am 15.03.2012 08:35, schrieb Igor Mitsyanko:
Quoted 3 lines
And use it for exynos4210 NURI board emulation
Signed-off-by Igor Mitsyanko<[email protected]>Thanks for moving this to libhw. Looks okay, not knowing I2C or the device and assuming you've tested it; some nitpicks below.
Quoted 6 lines
hw/exynos4_boards.c +0
-0hw/exynos4_boards.c static void nuri_init(ram_addr_t ram_size, · line 140
Quoted 8 lines
hw/exynos4_boards.c +2
-3@@ -134,9 +136,12 @@ static void nuri_init(ram_addr_t ram_size, const char *kernel_filename, const char *kernel_cmdline, const char *initrd_filename, const char *cpu_model) { -exynos4_boards_init_common (kernel_filename ,kernel_cmdline , -initrd_filename ,EXYNOS4_BOARD_NURI ); - + Exynos4210State *cpu = exynos4_boards_init_common(kernel_filename, + kernel_cmdline, initrd_filename,EXYNOS4_BOARD_NURI );I'd advise against using "cpu" for what looks like board or SoC state to avoid confusion. "cpu" is going to be used for CPUState instances, i.e. one day: ARMCPU *cpu =
cpu_arm_init("cortex-a9");
Quoted 1 line
I'd suggest s (generically for state) here.
Right, and also we already use s in SMDK board init function.
Quoted 7 lines
Quoted 7 lines
hw/exynos4_boards.c +4
-0+DeviceState *dev = +i2c_create_slave (cpu->i2c_if[3 ],"maxtouch.var0" ,MAXTOUCH_TS_I2C_ADDR ); +qdev_connect_gpio_out (dev,0 ,qdev_get_gpio_in (cpu->gpio2x, +EXYNOS4210_GPIO2X_LINE (GPX0 ,4 )));arm_load_kernel (first_cpu,&exynos4_board_binfo); }
Quoted 13 lines
hw/maxtouch.c line 4
Quoted 10 lines
hw/maxtouch.c new file +4
-0@@ -0,0 +1,1079 @@ +/* +* Atmel maXTouch touchscreen emulation +* +* Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. It's been remarked that "All rights reserved." conflicts with the GPL's copyleft. Please drop that sentence if you can.
Ok
Quoted 26 lines
Quoted 26 lines
hw/maxtouch.c new file +25
-0+* Igor Mitsyanko<[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +* for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, see<http://www.gnu.org/licenses/>. +* +*/ +/* Object types */ +enum { +MXT_GEN_MESSAGE_T5 =0 ,MXT_GEN_COMMAND_T6 , +MXT_GEN_POWER_T7 ,MXT_GEN_ACQUIRE_T8 , +MXT_TOUCH_MULTI_T9 ,MXT_TOUCH_KEYARRAY_T15 , +MXT_SPT_COMMSCONFIG_T18 ,MXT_SPT_GPIOPWM_T19 , +MXT_PROCI_GRIPFACE_T20 ,MXT_PROCG_NOISE_T22 , +MXT_TOUCH_PROXIMITY_T23 ,MXT_PROCI_ONETOUCH_T24 , +MXT_SPT_SELFTEST_T25 ,MXT_PROCI_TWOTOUCH_T27 ,
Quoted 8 lines
hw/maxtouch.c line 77
Quoted 3 lines
hw/maxtouch.c new file +3
-0+MXT_SPT_CTECONFIG_T28 ,MXT_DEBUG_DIAGNOSTIC_T37 , + MXT_NUM_OF_OBJECT_TYPES +};Personally I find it easier to read a mostly monotonically increasing enum (or array below) when it's not in two columns. Was this copied from some Linux header as is so that we wouldn't want to reformat it to allow for easy updates, or was this a design choice of yours?
It was my attempt to reduce amount of time needed to scroll this file down, I don't mind reformatting it to one column.
Quoted 17 lines
Quoted 6 lines
hw/maxtouch.c new file +6
-0+#define TYPE_MAXTOUCH "maxtouch" +#define MXT (obj) \ + OBJECT_CHECK(MXTState, (obj), TYPE_MAXTOUCH) +#define MXT_CLASS (klass) \ + OBJECT_CLASS_CHECK(MXTClass, (klass), TYPE_MAXTOUCH) +#define MXT_GET_CLASS (obj) \hw/maxtouch.c line 232
Quoted 10 lines
hw/maxtouch.c new file +9
-0+ OBJECT_GET_CLASS(MXTClass, (obj), TYPE_MAXTOUCH) +static const uint8_t mxt_variant0_info[MXT_INFO_SIZE ] = { + [MXT_FAMILY_ID ] =0x80 , + [MXT_VARIANT_ID ] =0x0 , + [MXT_VERSION ] =0x1 , + [MXT_BUILD ] =0x1 , + [MXT_MATRIX_X_SIZE ] =16 , + [MXT_MATRIX_Y_SIZE ] =14 , + [MXT_OBJ_NUM ] =sizeof (mxt_variant0_objlist) /sizeof (ObjConfig),
Quoted 1 line
We have an
ARRAY_SIZE()macro for this.
OK
Quoted 43 lines
hw/maxtouch.c line 258
Quoted 10 lines
hw/maxtouch.c new file +9
-0+}; +static const uint8_t mxt_variant1_info[MXT_INFO_SIZE ] = { + [MXT_FAMILY_ID ] =0x80 , + [MXT_VARIANT_ID ] =0x1 , + [MXT_VERSION ] =0x1 , + [MXT_BUILD ] =0x1 , + [MXT_MATRIX_X_SIZE ] =16 , + [MXT_MATRIX_Y_SIZE ] =14 , + [MXT_OBJ_NUM ] =sizeof (mxt_variant1_objlist) /sizeof (ObjConfig),Dito.
Quoted 7 lines
hw/maxtouch.c new file +7
-0+}; + +static const MXTVariantInfo mxt_variants_info_array[] = { + { + .name =TYPE_MXT_VARIANT0 , + .mxt_variant_info = mxt_variant0_info, + .mxt_variant_obj_list = mxt_variant0_objlisthw/maxtouch.c line 275
Quoted 10 lines
hw/maxtouch.c new file +10
-0+ }, + { + .name = TYPE_MXT_VARIANT1, + .mxt_variant_info = mxt_variant1_info, + .mxt_variant_obj_list = mxt_variant1_objlist + } +}; + +#define MXT_NUM_OF_VARIANTS \ + (sizeof(mxt_variants_info_array) / sizeof(MXTVariantInfo))Dito.
hw/maxtouch.c line 359
Quoted 7 lines
hw/maxtouch.c new file +7
-0+#if MXT_DEBUG +#define DPRINT(fmt, args...) \ + do {fprintf(stderr, "QEMU MXT: "fmt, ## args); } while (0) +#define DPRINT_SMPL(fmt, args...) \ + do {fprintf(stderr, fmt, ## args); } while (0) +#define ERRPRINT(fmt, args...) \ + do {fprintf(stderr, "QEMU MXT ERROR: "fmt, ## args); } while (0)Please insert a space after do {. Also somewhere below.
Quoted 4 lines
Quoted 1 line
+static TypeInfo
maxtouch_type_info= {Can be static const.
Ok
Quoted 4 lines
Quoted 4 lines
hw/maxtouch.c new file +4
-0+ .name = TYPE_MAXTOUCH, + .parent = TYPE_I2C_SLAVE, + .instance_size = sizeof(MXTState), + .instance_init = mxt_init,
Quoted 9 lines
hw/maxtouch.c line 1069
Quoted 6 lines
hw/maxtouch.c new file +6
-0+ .instance_finalize = mxt_finalize, + .abstract = true, + .class_size = sizeof(MXTClass), +}; + +static void mxt_types_init (void )Please name it
mxt_register_typesby convention.
Sure
Thanks for your review!
Signature · 3 lines
Mitsyanko Igor ASWG, Moscow R&D center, Samsung Electronics email: [email protected]