[Qemu-devel] [PATCH 5/5] hw: add Atmel maxtouch touchscreen implementation

2012-03-02 Thread Igor Mitsyanko
And use it for exynos4210 NURI board emulation

Signed-off-by: Igor Mitsyanko i.mitsya...@samsung.com
---
 Makefile.target |1 +
 hw/exynos4_boards.c |   11 +-
 hw/maxtouch.c   | 1079 +++
 3 files changed, 1088 insertions(+), 3 deletions(-)
 create mode 100644 hw/maxtouch.c

diff --git a/Makefile.target b/Makefile.target
index 7968120..05ce652 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -349,6 +349,7 @@ 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 exynos4210_gpio.o
+obj-arm-y += maxtouch.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
diff --git a/hw/exynos4_boards.c b/hw/exynos4_boards.c
index b438361..f851026 100644
--- a/hw/exynos4_boards.c
+++ b/hw/exynos4_boards.c
@@ -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  0x0500
+#define MAXTOUCH_TS_I2C_ADDR0x4a
 
 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);
 }
 
diff --git a/hw/maxtouch.c b/hw/maxtouch.c
new file mode 100644
index 000..621775c
--- /dev/null
+++ b/hw/maxtouch.c
@@ -0,0 +1,1079 @@
+/*
+ *  Atmel maXTouch touchscreen emulation
+ *
+ *  Copyright (c) 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *Igor Mitsyanko  i.mitsya...@samsung.com
+ *
+ *  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 i2c.h
+#include console.h
+
+#ifndef MXT_DEBUG
+#define MXT_DEBUG 0
+#endif
+
+/* Fifo length must be a power of 2 */
+#define MXT_MESSAGE_FIFO_LEN  16
+/* Maxtouch supports up to 10 concurrent touches, but we emulate 3 since common
+ * PC mouse has only 3 buttons. Exact meaning of each touch (each mouse button
+ * press) is defined by target userspace application only */
+#define MXT_NUM_OF_TOUCHES3
+#define MXT_CRC_POLY  0x80001B
+#define MXT_CRC_SIZE  3
+/* Maximum value of x and y coordinate in QEMU mouse event callback */
+#define MXT_QEMU_MAX_COORD0x7FFF
+
+/* Each maXTouch device consists of a certain number of subdevices (objects)
+ * with code names like T5, T6, T9, e.t.c. Each object implements only a 
portion
+ * of maXTouch functionality. For example, touch detection is performed
+ * by T9 object, but information about touch state changes is generated (and 
can
+ * be read) only in T5 object.
+ * Various variants of maXTouch can have different set of objects placed at
+ * different addresses within maXtouch address space. Composition of objects
+ * is described by mandatory Object Table which starts at address 0x7.
+ * Length of object table (i.e. number of objects) of this exact variant of
+ * maXTouch can be read from address 0x6 */
+#define MXT_OBJTBL_ENTRY_LEN  6
+/* Offsets within one object table entry */
+/* Object type code */
+#define MXT_OBJTBL_TYPE   0x0
+/* Start address of object registers within maxTouch address space */
+#define MXT_OBJTBL_START_LSB  0x1
+#define MXT_OBJTBL_START_MSB  0x2
+/* Number of object's registers (actually, this field contains size-1) */
+#define MXT_OBJTBL_SIZE   0x3
+/* Number of instances of this object (contains instances-1, so value 0 means
+ * one instance). All instances are placed 

Re: [Qemu-devel] [PATCH 5/5] hw: add Atmel maxtouch touchscreen implementation

2012-03-02 Thread Andreas Färber
Hi Igor,

Am 02.03.2012 12:35, schrieb Igor Mitsyanko:
 diff --git a/Makefile.target b/Makefile.target
 index 7968120..05ce652 100644
 --- a/Makefile.target
 +++ b/Makefile.target
 @@ -349,6 +349,7 @@ 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 exynos4210_gpio.o
 +obj-arm-y += maxtouch.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

I don't think this touchscreen device is really ARM-specific code-wise,
is it? I would rather expect this to be hw-obj-$(CONFIG_MAXTOUCH) in
Makefile.objs (so that it could be shared with, e.g., AVR).
default-configs/arm-softmmu.mak would need CONFIG_MAXTOUCH=y then.

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 5/5] hw: add Atmel maxtouch touchscreen implementation

2012-03-02 Thread Igor Mitsyanko

On 03/02/2012 06:19 PM, Andreas Färber wrote:

Hi Igor,

Am 02.03.2012 12:35, schrieb Igor Mitsyanko:

diff --git a/Makefile.target b/Makefile.target
index 7968120..05ce652 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -349,6 +349,7 @@ 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 exynos4210_gpio.o
+obj-arm-y += maxtouch.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


I don't think this touchscreen device is really ARM-specific code-wise,
is it? I would rather expect this to be hw-obj-$(CONFIG_MAXTOUCH) in
Makefile.objs (so that it could be shared with, e.g., AVR).
default-configs/arm-softmmu.mak would need CONFIG_MAXTOUCH=y then.

Andreas


Sure, that makes a lot of sense.

Originally I was confused by framebuffer.o, bitbang_i2c.o (and a few 
other files) in arm-specific obj-arm-y. It gave me an impression that in 
case if only one target currently makes use of a certain hardware then 
corresponding hardware sources should be compiled only for this target.


--
Mitsyanko Igor
ASWG, Moscow RD center, Samsung Electronics
email: i.mitsya...@samsung.com