From nobody Fri Oct 24 09:38:23 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519013281598920.5632994814913; Sun, 18 Feb 2018 20:08:01 -0800 (PST) Received: from localhost ([::1]:47455 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1enckA-0001X5-Re for importer@patchew.org; Sun, 18 Feb 2018 23:07:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49479) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1encgR-0007Wn-35 for qemu-devel@nongnu.org; Sun, 18 Feb 2018 23:04:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1encgQ-0000S8-DU for qemu-devel@nongnu.org; Sun, 18 Feb 2018 23:04:07 -0500 Received: from mail-it0-x234.google.com ([2607:f8b0:4001:c0b::234]:55519) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1encgQ-0000Ro-9f for qemu-devel@nongnu.org; Sun, 18 Feb 2018 23:04:06 -0500 Received: by mail-it0-x234.google.com with SMTP id b66so7678761itd.5 for ; Sun, 18 Feb 2018 20:04:06 -0800 (PST) Received: from localhost.localdomain ([184.250.204.84]) by smtp.gmail.com with ESMTPSA id a13sm19158075itj.13.2018.02.18.20.04.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Feb 2018 20:04:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ObOGUZWnw2cfW2O1UuGpwZjvtfluZC6VZMA4Vj0zd/A=; b=ae43qAB1CYUfrdee4zn9rdW8T3XhESPO4kSxym9gSn2ATT5PwWHiUFTAG7jILiEq89 tEY4dlaojqHlb7Ulv8O2+e+00THu+2q0yiweEpsvbylp2zY09CmqksW/ZmtGm6xJei0v wACJJVM65AEENKtW32+RU3E3wjNyQWMCL+lbSBa4eRJS5rdFelPUpVaKI/bZmxsqKuPS Tik3LoSIZGkUdK/nXgUPd4Wj1faqSHlnn50QS3BbVf+PwQbUv6kR/kPdt1LbrmupqTEB WjOB1H/2j7Jla+Dv7UvIjgewELwE3hoWhRDeXVC+rFvj/s35XKFTV+SBZx6dG2VD7PHT cRJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ObOGUZWnw2cfW2O1UuGpwZjvtfluZC6VZMA4Vj0zd/A=; b=pNeNWDdZhejxGmMgAP0kqYBFcXH16KWBRxQisHkM6z5a7z7l80rMp5pxQtNG4CFPVa CsaZaYSD9J+jrKZ/WeKcUcIxbr94HcbFLKVWmTDAiovk8egd1RD/uUvePabwh4/muJxS 7DlnENGUSkjXbc8hq/PyOdv+DvywHAdmIcXvmgjD0v4JdQ50Lq0AdPj66paxEIQqnt10 jKRcx81yTfLNkOBejufe5dfBuL2ky4tHTI7Wp/awCwiUswYpnGA4zNCq94JMLwY4O87I r8C8ATRpXiS+F7HyYJJR4l4v+eBdmvnqaMTtqOQL2i3ADIfFkX95r7MwAKJXMvExu5uO crNQ== X-Gm-Message-State: APf1xPAJMPcoGTKt39r7NY8+1RkaqGOTASZ7hikHNam2Pz9FifnNHHIa 1dnkS0gz6peTRYT+v7JaOqI= X-Google-Smtp-Source: AH8x2252x6OfzGgCAvPuuenTgOFJUXAWE+2yoqHVsQqxXJIJsQTQWGv2X9WW42iDXYWAhCt0ZS9Kxw== X-Received: by 10.36.158.198 with SMTP id p189mr18281285itd.74.1519013045552; Sun, 18 Feb 2018 20:04:05 -0800 (PST) From: Michael Davidsaver To: Paul Brook , Peter Maydell , Antoine Mathys Date: Sun, 18 Feb 2018 20:03:38 -0800 Message-Id: <20180219040342.12686-2-mdavidsaver@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180219040342.12686-1-mdavidsaver@gmail.com> References: <20180219040342.12686-1-mdavidsaver@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c0b::234 Subject: [Qemu-devel] [PATCH 1/5] timer: ds1338 add magic reset for test code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Davidsaver , qemu-devel@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When running w/ QTest, allow the tester to reliably zero time offsets. Allows tests to read the current time, and set time, independent of test order. Signed-off-by: Michael Davidsaver --- hw/timer/ds1338.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hw/timer/ds1338.c b/hw/timer/ds1338.c index 3849b74a68..41c2d7dac6 100644 --- a/hw/timer/ds1338.c +++ b/hw/timer/ds1338.c @@ -14,6 +14,7 @@ #include "qemu-common.h" #include "hw/i2c/i2c.h" #include "qemu/bcd.h" +#include "sysemu/qtest.h" =20 /* Size of NVRAM including both the user-accessible area and the * secondary register area. @@ -132,6 +133,14 @@ static int ds1338_send(I2CSlave *i2c, uint8_t data) DS1338State *s =3D DS1338(i2c); =20 if (s->addr_byte) { + if (data =3D=3D 0xff && qtest_enabled()) { + /* magic, out of bounds, address to allow test code + * to reset offset + */ + s->offset =3D 0; + s->wday_offset =3D 0; + return 0; + } s->ptr =3D data & (NVRAM_SIZE - 1); s->addr_byte =3D false; return 0; --=20 2.11.0 From nobody Fri Oct 24 09:38:23 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519013163189403.20189899731633; Sun, 18 Feb 2018 20:06:03 -0800 (PST) Received: from localhost ([::1]:47447 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1enciI-00007E-3i for importer@patchew.org; Sun, 18 Feb 2018 23:06:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49501) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1encgV-0007Z3-1q for qemu-devel@nongnu.org; Sun, 18 Feb 2018 23:04:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1encgT-0000TK-Mw for qemu-devel@nongnu.org; Sun, 18 Feb 2018 23:04:11 -0500 Received: from mail-it0-x241.google.com ([2607:f8b0:4001:c0b::241]:52331) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1encgT-0000TB-HN for qemu-devel@nongnu.org; Sun, 18 Feb 2018 23:04:09 -0500 Received: by mail-it0-x241.google.com with SMTP id o13so7693085ito.2 for ; Sun, 18 Feb 2018 20:04:09 -0800 (PST) Received: from localhost.localdomain ([184.250.204.84]) by smtp.gmail.com with ESMTPSA id a13sm19158075itj.13.2018.02.18.20.04.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Feb 2018 20:04:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=RzmBa3Q9ZKmQ9XMkdNGHR6/Qm3Np+kkYXXqShEMXTFc=; b=XnWP+rY0cCgrc+QfdX+dR7nQijND7mSayUZUej+YNXhwS+KyDzybrMyg/gB1XeAUVL S2sCRRU8KUJFgPp/PXUCALB5FNFVHL41PXhwVfYI+X/0HVf5D6rYB+iSVLMp7HaXYSVZ LU8xuIizNwPr/AmLMbE45n3incf2RB9sS1rmcLBre/hQmDGLRZWEhD9OdAfsywAy6QpW 4jkupP1av75oq8OHzP6BNEUM+T2EbopkdGMMXJ62mOv9vmaCUhO6a1j43cj2Xg+Tdcg+ wUfyse1V7HYSOmi9HplMnCWCeKOQaKs6fM5q2uKdvY5973gkQhVZDKWayNFhUyGvoXTT XLwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=RzmBa3Q9ZKmQ9XMkdNGHR6/Qm3Np+kkYXXqShEMXTFc=; b=FB6Td5AdG8afZljuG5Md4OzHB88UETY81V72bEmjXd2pBY9898TEjjeI4TqjlMTfHx Uq3ipanIrDVtT7arac1SWZkyyoMMgywE8wDfHk3O/EYQ9/vOjVnLUFeoLDlNNkUPKT+2 TtVja0EgqidvGxQv0ImPi0JIJR0yKbUA1tm6jJQjwb15qnFBqqE0NNNl5KfGiwok3On0 WP8EQ/dWyEDfkU6eiarXNwI+v6uZFVc+h3/wAPsaw1YSuGkkdkLORglpfi6D4Mh3KUbO JOKuE0X8MUnq9HTE+dXdLsztNGq68SIr2s4QtheNihLqNSdx1i0cozAtt7TrSLObGFVW 1Bsw== X-Gm-Message-State: APf1xPAG/JQWzGUs7zMXOvvQ5B3u9kYWzBSHMHoMR1et4zPWUHHGgNiS kIRsqKTmMUSoBUx6zl3Jbf4= X-Google-Smtp-Source: AH8x225z6nSjkjqwImeDDtCOaU5u9WELbea+zAR6cLFSkvWzzA5BCZOku3myurVYSDINgbqp9xEF/g== X-Received: by 10.36.67.145 with SMTP id s139mr758342itb.5.1519013048749; Sun, 18 Feb 2018 20:04:08 -0800 (PST) From: Michael Davidsaver To: Paul Brook , Peter Maydell , Antoine Mathys Date: Sun, 18 Feb 2018 20:03:39 -0800 Message-Id: <20180219040342.12686-3-mdavidsaver@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180219040342.12686-1-mdavidsaver@gmail.com> References: <20180219040342.12686-1-mdavidsaver@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c0b::241 Subject: [Qemu-devel] [PATCH 2/5] tests: more thorough test of ds1338 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Davidsaver , qemu-devel@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Test current time and set+get round trip. The set+get test is repeated 4 times. These cases are spread across a single day in an attempt to trigger some potential issues regardless of the timezone of the machine running the tests. Signed-off-by: Michael Davidsaver --- tests/Makefile.include | 2 + tests/ds-rtc-i2c-test.c | 193 ++++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 195 insertions(+) create mode 100644 tests/ds-rtc-i2c-test.c diff --git a/tests/Makefile.include b/tests/Makefile.include index a1bcbffe12..f5dcd274e0 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -360,6 +360,7 @@ check-qtest-sparc64-y +=3D tests/boot-serial-test$(EXES= UF) =20 check-qtest-arm-y =3D tests/tmp105-test$(EXESUF) check-qtest-arm-y +=3D tests/ds1338-test$(EXESUF) +check-qtest-arm-y +=3D tests/ds-rtc-i2c-test$(EXESUF) check-qtest-arm-y +=3D tests/m25p80-test$(EXESUF) gcov-files-arm-y +=3D hw/misc/tmp105.c check-qtest-arm-y +=3D tests/virtio-blk-test$(EXESUF) @@ -764,6 +765,7 @@ tests/bios-tables-test$(EXESUF): tests/bios-tables-test= .o \ tests/pxe-test$(EXESUF): tests/pxe-test.o tests/boot-sector.o $(libqos-obj= -y) tests/tmp105-test$(EXESUF): tests/tmp105-test.o $(libqos-omap-obj-y) tests/ds1338-test$(EXESUF): tests/ds1338-test.o $(libqos-imx-obj-y) +tests/ds-rtc-i2c-test$(EXESUF): tests/ds-rtc-i2c-test.o $(libqos-imx-obj-y) tests/m25p80-test$(EXESUF): tests/m25p80-test.o tests/i440fx-test$(EXESUF): tests/i440fx-test.o $(libqos-pc-obj-y) tests/q35-test$(EXESUF): tests/q35-test.o $(libqos-pc-obj-y) diff --git a/tests/ds-rtc-i2c-test.c b/tests/ds-rtc-i2c-test.c new file mode 100644 index 0000000000..464eb08558 --- /dev/null +++ b/tests/ds-rtc-i2c-test.c @@ -0,0 +1,193 @@ +/* Testing of Dallas/Maxim I2C bus RTC devices + * + * Copyright (c) 2017 Michael Davidsaver + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the LICENSE file in the top-level directory. + */ +#include + +#include "qemu/osdep.h" +#include "qemu/bcd.h" +#include "qemu/cutils.h" +#include "qemu/timer.h" +#include "libqtest.h" +#include "libqos/libqos.h" +#include "libqos/i2c.h" + +#define IMX25_I2C_0_BASE 0x43F80000 +#define DS1338_ADDR 0x68 + +static I2CAdapter *i2c; +static uint8_t addr; +static bool use_century; + +static +time_t rtc_gettime(void) +{ + struct tm parts; + uint8_t buf[7]; + + buf[0] =3D 0; + i2c_send(i2c, addr, buf, 1); + i2c_recv(i2c, addr, buf, 7); + + parts.tm_sec =3D from_bcd(buf[0]); + parts.tm_min =3D from_bcd(buf[1]); + if (buf[2] & 0x40) { + /* 12 hour */ + /* HOUR register is 1-12. */ + parts.tm_hour =3D from_bcd(buf[2] & 0x1f); + g_assert_cmpuint(parts.tm_hour, >=3D, 1); + g_assert_cmpuint(parts.tm_hour, <=3D, 12); + parts.tm_hour %=3D 12u; /* wrap 12 -> 0 */ + if (buf[2] & 0x20) { + parts.tm_hour +=3D 12u; + } + } else { + /* 24 hour */ + parts.tm_hour =3D from_bcd(buf[2] & 0x3f); + } + parts.tm_wday =3D from_bcd(buf[3]); + parts.tm_mday =3D from_bcd(buf[4]); + parts.tm_mon =3D from_bcd((buf[5] & 0x1f) - 1u); + parts.tm_year =3D from_bcd(buf[6]); + if (!use_century || (buf[5] & 0x80)) { + parts.tm_year +=3D 100u; + } + + return mktimegm(&parts); +} + +/* read back and compare with current system time */ +static +void test_rtc_current(void) +{ + uint8_t buf; + time_t expected, actual; + + /* magic address to zero RTC time offset + * as tests may be run in any order + */ + buf =3D 0xff; + i2c_send(i2c, addr, &buf, 1); + + actual =3D time(NULL); + /* new second may start here */ + expected =3D rtc_gettime(); + g_assert_cmpuint(expected, <=3D, actual + 1); + g_assert_cmpuint(expected, >=3D, actual); +} + + +static uint8_t test_time_24_12am[8] =3D { + 0, /* address */ + /* Wed, 22 Nov 2017 00:30:53 +0000 */ + 0x53, + 0x30, + 0x00, /* 12 AM in 24 hour mode */ + 0x03, /* monday is our day 1 */ + 0x22, + 0x11 | 0x80, + 0x17, +}; + +static uint8_t test_time_24_6am[8] =3D { + 0, /* address */ + /* Wed, 22 Nov 2017 06:30:53 +0000 */ + 0x53, + 0x30, + 0x06, /* 6 AM in 24 hour mode */ + 0x03, /* monday is our day 1 */ + 0x22, + 0x11 | 0x80, + 0x17, +}; + +static uint8_t test_time_24_12pm[8] =3D { + 0, /* address */ + /* Wed, 22 Nov 2017 12:30:53 +0000 */ + 0x53, + 0x30, + 0x12, /* 12 PM in 24 hour mode */ + 0x03, /* monday is our day 1 */ + 0x22, + 0x11 | 0x80, + 0x17, +}; + +static uint8_t test_time_24_6pm[8] =3D { + 0, /* address */ + /* Wed, 22 Nov 2017 18:30:53 +0000 */ + 0x53, + 0x30, + 0x18, /* 6 PM in 24 hour mode */ + 0x03, /* monday is our day 1 */ + 0x22, + 0x11 | 0x80, + 0x17, +}; + +/* write in and read back known time */ +static +void test_rtc_set(const void *raw) +{ + const uint8_t *testtime =3D raw; + uint8_t buf[7]; + unsigned retry =3D 2; + + for (; retry; retry--) { + i2c_send(i2c, addr, testtime, 8); + /* new second may start here */ + i2c_send(i2c, addr, testtime, 1); + i2c_recv(i2c, addr, buf, 7); + + if (testtime[1] =3D=3D buf[0]) { + break; + } + /* we raced start of second, retry */ + }; + + g_assert_cmpuint(testtime[1], =3D=3D, buf[0]); /* SEC */ + g_assert_cmpuint(testtime[2], =3D=3D, buf[1]); /* MIN */ + g_assert_cmpuint(testtime[3], =3D=3D, buf[2]); /* HOUR */ + /* skip comparing Day of Week. Not handled correctly */ + g_assert_cmpuint(testtime[5], =3D=3D, buf[4]); /* DoM */ + if (use_century) { + g_assert_cmpuint(testtime[6], =3D=3D, buf[5]); /* MON+century */ + } else { + g_assert_cmpuint(testtime[6] & 0x7f, =3D=3D, buf[5]); /* MON */ + } + g_assert_cmpuint(testtime[7], =3D=3D, buf[6]); /* YEAR */ + + g_assert_cmpuint(retry, >, 0); +} + +int main(int argc, char *argv[]) +{ + int ret; + const char *arch =3D qtest_get_arch(); + QTestState *s =3D NULL; + + g_test_init(&argc, &argv, NULL); + + if (strcmp(arch, "arm") =3D=3D 0) { + s =3D qtest_start("-display none -machine imx25-pdk"); + i2c =3D imx_i2c_create(s, IMX25_I2C_0_BASE); + addr =3D DS1338_ADDR; + use_century =3D false; + + } + + qtest_add_data_func("/ds-rtc-i2c/set24_12am", test_time_24_12am, test_= rtc_set); + qtest_add_data_func("/ds-rtc-i2c/set24_6am", test_time_24_6am, test_rt= c_set); + qtest_add_data_func("/ds-rtc-i2c/set24_12pm", test_time_24_12pm, test_= rtc_set); + qtest_add_data_func("/ds-rtc-i2c/set24_6pm", test_time_24_6pm, test_rt= c_set); + qtest_add_func("/ds-rtc-i2c/current", test_rtc_current); + + ret =3D g_test_run(); + + qtest_end(); + + return ret; +} --=20 2.11.0 From nobody Fri Oct 24 09:38:23 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519013389169917.005524157999; Sun, 18 Feb 2018 20:09:49 -0800 (PST) Received: from localhost ([::1]:47460 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1enclw-0002qA-Ax for importer@patchew.org; Sun, 18 Feb 2018 23:09:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49529) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1encge-0007ed-LQ for qemu-devel@nongnu.org; Sun, 18 Feb 2018 23:04:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1encga-0000fG-Ut for qemu-devel@nongnu.org; Sun, 18 Feb 2018 23:04:20 -0500 Received: from mail-io0-x243.google.com ([2607:f8b0:4001:c06::243]:43959) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1encga-0000e5-NP for qemu-devel@nongnu.org; Sun, 18 Feb 2018 23:04:16 -0500 Received: by mail-io0-x243.google.com with SMTP id l12so4181219ioc.10 for ; Sun, 18 Feb 2018 20:04:16 -0800 (PST) Received: from localhost.localdomain ([184.250.204.84]) by smtp.gmail.com with ESMTPSA id a13sm19158075itj.13.2018.02.18.20.04.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Feb 2018 20:04:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=AxGgszSPQwd9AM4eTS9OvrDhDSbWvISkz+I83GJ3wSo=; b=RTLdoevQRMs/hRfnojKjE0RIFTuTWvMqBMw9xHrzoSL4PNsbzcxEYyjCyS1EPIzNjV kI/OlTvJMEpxB+pIr4b/eAXuPd7FscUGCBwkvxbpYTx1znGAQ8X+GuXo7Nvi1hD+L5ty QV0fouRW8pnu+CgZxNcpnYcDVr5/0mFbXyRPG+VA9gnLk2MpFbP4QbMDrP4DuGCeVyfK kB+w68MCe6V4daZ5zV9A5x5113tFK31UoJNWh6ow+xiSaA6sIbf8sR5GnUCt53p8CWUL 1zxKms5Cb7vD6Sk6Ga1sHUxKZpTcgsrMbYXRvdqSlfBWgK7sz/O4bWDcWUr8TcBwEse/ jRdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=AxGgszSPQwd9AM4eTS9OvrDhDSbWvISkz+I83GJ3wSo=; b=ADtJxZ2yHCIEztmVh1oTPSeKrpsS9dKn7pdfi/0urzd3XwFXjqJc/NQS3flbd+f0Z8 rYgbpwDtsSfkCMG6PPF48K+Q3Wx6ACl0t69U4VpaKU0iwqk89OhkC7iM9/Q40Xcml5G8 khrPxpojidoSaB8fn2HJwF7pMUoIN2wkV74S3xSfHs0vDoEG8yMrGgUkTv6SybvNHT6t UJ4gTN+Tepk0bsXerY1CHSOHlFpkrX8eEZRUac+E4I5iH1XOkaZhvl4ZRx4Ps5xBzI26 v0MVP5thV/8CeUXaUAlp/qmag0JXu1aLZWSpjZSvOlVwz5HZTkWJZstEbfgd/zG0CUeN 9EOQ== X-Gm-Message-State: APf1xPDS2v/uSVYazw2swgGKEbO+vxaLBI7ukwvud4hct1SxRbfoLZE0 TiBt+dTVZsioV87xPTPjuNM= X-Google-Smtp-Source: AH8x226hrGilpFL8UzVONPB86N5iPwfscc1TQRqTfoK/rCCz93oNlT0bmRJOScEcd/wWXU/C6Ht/sw== X-Received: by 10.107.34.199 with SMTP id i190mr7359562ioi.185.1519013055750; Sun, 18 Feb 2018 20:04:15 -0800 (PST) From: Michael Davidsaver To: Paul Brook , Peter Maydell , Antoine Mathys Date: Sun, 18 Feb 2018 20:03:40 -0800 Message-Id: <20180219040342.12686-4-mdavidsaver@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180219040342.12686-1-mdavidsaver@gmail.com> References: <20180219040342.12686-1-mdavidsaver@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c06::243 Subject: [Qemu-devel] [PATCH 3/5] timer: generalize Dallas/Maxim RTC i2c devices X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Davidsaver , qemu-devel@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Support for: ds1307, ds1337, ds1338, ds1339, ds1340, ds1375, ds1388, and ds3231. Tested with ds1338 and ds1375. The existing ds1338 model has two bugs with almost no practical impact. 1. Trying to set time in 12-hour mode works, but the 12 hour mode bit isn't stored. So time always reads in 24 hour mode. 2. wday_offset is always stored for the local time zone. When the RTC is set and rtc_utc=3D1 and the local timezone has a different day than UTC, then wday_offset will be off by one. Signed-off-by: Michael Davidsaver --- default-configs/arm-softmmu.mak | 2 +- hw/timer/Makefile.objs | 2 +- hw/timer/ds-rtc-i2c.c | 466 ++++++++++++++++++++++++++++++++++++= ++++ hw/timer/ds1338.c | 248 --------------------- 4 files changed, 468 insertions(+), 250 deletions(-) create mode 100644 hw/timer/ds-rtc-i2c.c delete mode 100644 hw/timer/ds1338.c diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.= mak index ca34cf4462..510a92c9a8 100644 --- a/default-configs/arm-softmmu.mak +++ b/default-configs/arm-softmmu.mak @@ -31,7 +31,7 @@ CONFIG_SMC91C111=3Dy CONFIG_ALLWINNER_EMAC=3Dy CONFIG_IMX_FEC=3Dy CONFIG_FTGMAC100=3Dy -CONFIG_DS1338=3Dy +CONFIG_DSRTCI2C=3Dy CONFIG_PFLASH_CFI01=3Dy CONFIG_PFLASH_CFI02=3Dy CONFIG_MICRODRIVE=3Dy diff --git a/hw/timer/Makefile.objs b/hw/timer/Makefile.objs index 8c19eac3b6..290015ebec 100644 --- a/hw/timer/Makefile.objs +++ b/hw/timer/Makefile.objs @@ -3,7 +3,7 @@ common-obj-$(CONFIG_ARM_MPTIMER) +=3D arm_mptimer.o common-obj-$(CONFIG_ARM_V7M) +=3D armv7m_systick.o common-obj-$(CONFIG_A9_GTIMER) +=3D a9gtimer.o common-obj-$(CONFIG_CADENCE) +=3D cadence_ttc.o -common-obj-$(CONFIG_DS1338) +=3D ds1338.o +common-obj-$(CONFIG_DSRTCI2C) +=3D ds-rtc-i2c.o common-obj-$(CONFIG_HPET) +=3D hpet.o common-obj-$(CONFIG_I8254) +=3D i8254_common.o i8254.o common-obj-$(CONFIG_M48T59) +=3D m48t59.o diff --git a/hw/timer/ds-rtc-i2c.c b/hw/timer/ds-rtc-i2c.c new file mode 100644 index 0000000000..ebe53bbec7 --- /dev/null +++ b/hw/timer/ds-rtc-i2c.c @@ -0,0 +1,466 @@ +/* Emulation of various Dallas/Maxim RTCs accessed via I2C bus + * + * Copyright (c) 2017 Michael Davidsaver + * Copyright (c) 2009 CodeSourcery + * + * Authors: Michael Davidsaver + * Paul Brook + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the LICENSE file in the top-level directory. + * + * Models real time read/set and NVRAM. + * Does not model alarms, or control/status registers. + * + * Generalized register map is: + * [Current time] + * [Alarm settings] (optional) + * [Control/Status] (optional) + * [Non-volatile memory] (optional) + * + * The current time registers are almost always the same, + * with the exception being that some have a CENTURY bit + * in the month register. + */ +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qemu/timer.h" +#include "qemu/bcd.h" +#include "hw/hw.h" +#include "hw/registerfields.h" +#include "hw/i2c/i2c.h" +#include "sysemu/qtest.h" +#include "qemu/error-report.h" + +/* #define DEBUG_DSRTC */ + +#ifdef DEBUG_DSRTC +#define DPRINTK(FMT, ...) info_report(TYPE_DSRTC " : " FMT, ## __VA_ARGS__) +#else +#define DPRINTK(FMT, ...) do {} while (0) +#endif + +#define LOG(MSK, FMT, ...) qemu_log_mask(MSK, TYPE_DSRTC " : " FMT "\n", \ + ## __VA_ARGS__) + +#define DSRTC_REGSIZE (0x40) + +/* values stored in BCD */ +/* 00-59 */ +#define R_SEC (0x0) +/* 00-59 */ +#define R_MIN (0x1) +#define R_HOUR (0x2) +/* 1-7 */ +#define R_WDAY (0x3) +/* 0-31 */ +#define R_DATE (0x4) +#define R_MONTH (0x5) +/* 0-99 */ +#define R_YEAR (0x6) + +/* use 12 hour mode when set */ +FIELD(HOUR, SET12, 6, 1) +/* 00-23 */ +FIELD(HOUR, HOUR24, 0, 6) +FIELD(HOUR, AMPM, 5, 1) +/* 1-12 (not 0-11!) */ +FIELD(HOUR, HOUR12, 0, 5) + +/* 1-12 */ +FIELD(MONTH, MONTH, 0, 5) +FIELD(MONTH, CENTURY, 7, 1) + +typedef struct DSRTCInfo { + /* if bit 7 of the Month register is set after Y2K */ + bool has_century; + /* address of first non-volatile memory cell. + * nv_start >=3D reg_end means no NV memory. + */ + uint8_t nv_start; + /* total size of register range. When address counter rolls over. */ + uint8_t reg_size; +} DSRTCInfo; + +typedef struct DSRTCState { + I2CSlave parent_obj; + + const DSRTCInfo *info; + + qemu_irq alarm_irq; + + /* register address counter */ + uint8_t addr; + /* when writing, whether the address has been sent */ + bool addrd; + + int64_t time_offset; + int8_t wday_offset; + + uint8_t regs[DSRTC_REGSIZE]; +} DSRTCState; + +typedef struct DSRTCClass { + I2CSlaveClass parent_class; + + const DSRTCInfo *info; +} DSRTCClass; + +#define TYPE_DSRTC "ds-rtc-i2c" +#define DSRTC(obj) OBJECT_CHECK(DSRTCState, (obj), TYPE_DSRTC) +#define DSRTC_GET_CLASS(obj) \ + OBJECT_GET_CLASS(DSRTCClass, obj, TYPE_DSRTC) +#define DSRTC_CLASS(klass) \ + OBJECT_CLASS_CHECK(DSRTCClass, klass, TYPE_DSRTC) + +static const VMStateDescription vmstate_dsrtc =3D { + .name =3D TYPE_DSRTC, + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_I2C_SLAVE(parent_obj, DSRTCState), + VMSTATE_INT64(time_offset, DSRTCState), + VMSTATE_INT8_V(wday_offset, DSRTCState, 2), + VMSTATE_UINT8_ARRAY(regs, DSRTCState, DSRTC_REGSIZE), + VMSTATE_UINT8(addr, DSRTCState), + VMSTATE_BOOL(addrd, DSRTCState), + VMSTATE_END_OF_LIST() + } +}; + +static void dsrtc_reset(DeviceState *device); + +/* update current time registers */ +static +void dsrtc_latch(DSRTCState *ds) +{ + struct tm now; + bool use12; + + qemu_get_timedate(&now, ds->time_offset); + + DPRINTK("Current Time %3u/%02u/%02u %02u:%02u:%02u (wday %u)", + 1900u + now.tm_year, now.tm_mon, now.tm_mday, + now.tm_hour, now.tm_min, now.tm_sec, + now.tm_wday); + + use12 =3D ARRAY_FIELD_EX32(ds->regs, HOUR, SET12); + + /* ensure unused bits are zero */ + memset(ds->regs, 0, R_YEAR + 1); + + ds->regs[R_SEC] =3D to_bcd(now.tm_sec); + ds->regs[R_MIN] =3D to_bcd(now.tm_min); + + if (!use12) { + /* 24 hour (0-23) */ + ARRAY_FIELD_DP32(ds->regs, HOUR, HOUR24, to_bcd(now.tm_hour)); + } else { + /* 12 hour am/pm (1-12) */ + ARRAY_FIELD_DP32(ds->regs, HOUR, SET12, 1); + ARRAY_FIELD_DP32(ds->regs, HOUR, AMPM, now.tm_hour >=3D 12u); + now.tm_hour %=3D 12u; /* wrap 0-23 to 0-11 */ + if (now.tm_hour =3D=3D 0u) { + /* midnight/noon stored as 12 */ + now.tm_hour =3D 12u; + } + ARRAY_FIELD_DP32(ds->regs, HOUR, HOUR12, to_bcd(now.tm_hour)); + } + + ds->regs[R_WDAY] =3D (now.tm_wday + ds->wday_offset) % 7u + 1u; + ds->regs[R_DATE] =3D to_bcd(now.tm_mday); + + ARRAY_FIELD_DP32(ds->regs, MONTH, MONTH, to_bcd(now.tm_mon + 1)); + if (ds->info->has_century) { + ARRAY_FIELD_DP32(ds->regs, MONTH, CENTURY, now.tm_year >=3D 100u); + } + + ds->regs[R_YEAR] =3D to_bcd(now.tm_year % 100u); + + DPRINTK("Latched time"); +} + +/* call after guest writes to current time registers + * to re-compute our offset from host time. + */ +static +void dsrtc_update(DSRTCState *ds) +{ + int user_wday; + struct tm now; + + now.tm_sec =3D from_bcd(ds->regs[R_SEC]); + now.tm_min =3D from_bcd(ds->regs[R_MIN]); + + if (ARRAY_FIELD_EX32(ds->regs, HOUR, SET12)) { + /* 12 hour (1-12) */ + /* read and wrap 1-12 -> 0-11 */ + now.tm_hour =3D from_bcd(ARRAY_FIELD_EX32(ds->regs, HOUR, HOUR12))= % 12u; + if (ARRAY_FIELD_EX32(ds->regs, HOUR, AMPM)) { + now.tm_hour +=3D 12; + } + + } else { + /* 23 hour (0-23) */ + now.tm_hour =3D from_bcd(ARRAY_FIELD_EX32(ds->regs, HOUR, HOUR24)); + } + + now.tm_wday =3D from_bcd(ds->regs[R_WDAY]) - 1u; + now.tm_mday =3D from_bcd(ds->regs[R_DATE]); + now.tm_mon =3D from_bcd(ARRAY_FIELD_EX32(ds->regs, MONTH, MONTH)) - 1; + + now.tm_year =3D from_bcd(ds->regs[R_YEAR]); + if (ARRAY_FIELD_EX32(ds->regs, MONTH, CENTURY) || !ds->info->has_centu= ry) { + now.tm_year +=3D 100; + } + + DPRINTK("New Time %3u/%02u/%02u %02u:%02u:%02u (wday %u)", + 1900u + now.tm_year, now.tm_mon, now.tm_mday, + now.tm_hour, now.tm_min, now.tm_sec, + now.tm_wday); + + /* round trip to get real wday_offset based on time delta */ + user_wday =3D now.tm_wday; + ds->time_offset =3D qemu_timedate_diff(&now); + /* race possible if we run at midnight + * TODO: make qemu_timedate_diff() calculate wday offset as well? + */ + qemu_get_timedate(&now, ds->time_offset); + /* calculate wday_offset to achieve guest requested wday */ + ds->wday_offset =3D user_wday - now.tm_wday; + + DPRINTK("Update offset =3D %" PRId64 ", wday_offset =3D %d", + ds->time_offset, ds->wday_offset); +} + +static +void dsrtc_advance(DSRTCState *ds) +{ + ds->addr =3D (ds->addr + 1) % ds->info->reg_size; + if (ds->addr =3D=3D 0) { + /* latch time on roll over */ + dsrtc_latch(ds); + } +} + +static +int dsrtc_event(I2CSlave *s, enum i2c_event event) +{ + DSRTCState *ds =3D DSRTC(s); + + switch (event) { + case I2C_START_SEND: + ds->addrd =3D false; + /* fall through */ + case I2C_START_RECV: + dsrtc_latch(ds); + /* fall through */ + case I2C_FINISH: + DPRINTK("Event %d", (int)event); + /* fall through */ + case I2C_NACK: + break; + } + return 0; +} + +static +int dsrtc_recv(I2CSlave *s) +{ + DSRTCState *ds =3D DSRTC(s); + int ret =3D 0; + + ret =3D ds->regs[ds->addr]; + + if (ds->addr > R_YEAR && ds->addr < ds->info->nv_start) { + LOG(LOG_UNIMP, "Read from unimplemented (%02x) %02x", ds->addr, re= t); + } + + DPRINTK("Recv (%02x) %02x", ds->addr, ret); + + dsrtc_advance(ds); + + return ret; +} + +static +int dsrtc_send(I2CSlave *s, uint8_t data) +{ + DSRTCState *ds =3D DSRTC(s); + + if (!ds->addrd) { + if (data =3D=3D 0xff && qtest_enabled()) { + /* allow test runner to zero offsets */ + DPRINTK("Testing reset"); + dsrtc_reset(DEVICE(s)); + return 0; + } + ds->addr =3D data % DSRTC_REGSIZE; + ds->addrd =3D true; + DPRINTK("Set address pointer %02x", data); + return 0; + } + + DPRINTK("Send (%02x) %02x", ds->addr, data); + + if (ds->addr <=3D R_YEAR) { + ds->regs[ds->addr] =3D data; + dsrtc_update(ds); + + } else if (ds->addr >=3D ds->info->nv_start) { + ds->regs[ds->addr] =3D data; + + } else { + LOG(LOG_UNIMP, "Register not modeled"); + } + + dsrtc_advance(ds); + + return 0; +} + +static +void dsrtc_reset(DeviceState *device) +{ + DSRTCState *ds =3D DSRTC(device); + + memset(ds->regs, 0, sizeof(ds->regs)); + + ds->addr =3D 0; + ds->addrd =3D false; + ds->time_offset =3D 0; + ds->wday_offset =3D 0; + + DPRINTK("Reset"); +} + +static +void dsrtc_realize(DeviceState *device, Error **errp) +{ + DSRTCState *ds =3D DSRTC(device); + DSRTCClass *r =3D DSRTC_GET_CLASS(device); + + ds->info =3D r->info; + + /* Alarms not yet implemented, but allow + * board code to wire up the alarm interrupt + * output anyway. + */ + qdev_init_gpio_out(device, &ds->alarm_irq, 1); +} + +static +void dsrtc_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + I2CSlaveClass *k =3D I2C_SLAVE_CLASS(klass); + DSRTCClass *r =3D DSRTC_CLASS(klass); + + r->info =3D data; + + k->event =3D &dsrtc_event; + k->recv =3D &dsrtc_recv; + k->send =3D &dsrtc_send; + + dc->vmsd =3D &vmstate_dsrtc; + dc->realize =3D dsrtc_realize; + dc->reset =3D dsrtc_reset; + dc->user_creatable =3D true; +} + +static +const TypeInfo ds_rtc_base_type =3D { + .abstract =3D true, + .name =3D TYPE_DSRTC, + .parent =3D TYPE_I2C_SLAVE, + .instance_size =3D sizeof(DSRTCState), +}; + +#define DSRTC_CONFIG(NAME) \ +static const TypeInfo NAME##_type =3D { \ + .name =3D #NAME, \ + .parent =3D TYPE_DSRTC, \ + .class_size =3D sizeof(I2CSlaveClass), \ + .class_init =3D dsrtc_class_init, \ + .class_data =3D (void *)&NAME##_info, \ +}; + +/* ds3231 - alarms, no eeprom */ +static const DSRTCInfo ds3231_info =3D { + .has_century =3D true, + .nv_start =3D 0x13, /* no nv memory */ + .reg_size =3D 0x13, +}; +DSRTC_CONFIG(ds3231) + +/* only model block 0 (RTC), blocks 1,2 (eeprom) not modeled. + * blocks have different i2c addresses + */ +static const DSRTCInfo ds1388_info =3D { + .has_century =3D false, + .nv_start =3D 0x0d, + .reg_size =3D 0x0d, +}; +DSRTC_CONFIG(ds1388) + +/* alarms, eeprom */ +static const DSRTCInfo ds1375_info =3D { + .has_century =3D true, + .nv_start =3D 0x10, + .reg_size =3D 0x20, +}; +DSRTC_CONFIG(ds1375) + +/* no alarms, no eeprom */ +static const DSRTCInfo ds1340_info =3D { + .has_century =3D false, + .nv_start =3D 0x10, + .reg_size =3D 0x10, +}; +DSRTC_CONFIG(ds1340) + +/* alarms, no eeprom */ +static const DSRTCInfo ds1339_info =3D { + .has_century =3D false, + .nv_start =3D 0x11, + .reg_size =3D 0x11, +}; +DSRTC_CONFIG(ds1339) + +/* no alarms, eeprom */ +static const DSRTCInfo ds1338_info =3D { + .has_century =3D false, + .nv_start =3D 0x08, + .reg_size =3D 0x40, +}; +DSRTC_CONFIG(ds1338) + +/* alarms, no eeprom */ +static const DSRTCInfo ds1337_info =3D { + .has_century =3D true, + .nv_start =3D 0x10, + .reg_size =3D 0x10, +}; +DSRTC_CONFIG(ds1337) + +/* ds1307 registers are identical to ds1338 */ +static +const TypeInfo ds1307_type =3D { + .name =3D "ds1307", + .parent =3D "ds1338", +}; + +static void ds_rtc_i2c_register(void) +{ + type_register_static(&ds_rtc_base_type); + type_register_static(&ds3231_type); + type_register_static(&ds1388_type); + type_register_static(&ds1375_type); + type_register_static(&ds1340_type); + type_register_static(&ds1339_type); + type_register_static(&ds1338_type); + type_register_static(&ds1337_type); + type_register_static(&ds1307_type); +} + +type_init(ds_rtc_i2c_register) diff --git a/hw/timer/ds1338.c b/hw/timer/ds1338.c deleted file mode 100644 index 41c2d7dac6..0000000000 --- a/hw/timer/ds1338.c +++ /dev/null @@ -1,248 +0,0 @@ -/* - * MAXIM DS1338 I2C RTC+NVRAM - * - * Copyright (c) 2009 CodeSourcery. - * Written by Paul Brook - * - * This code is licensed under the GNU GPL v2. - * - * Contributions after 2012-01-13 are licensed under the terms of the - * GNU GPL, version 2 or (at your option) any later version. - */ - -#include "qemu/osdep.h" -#include "qemu-common.h" -#include "hw/i2c/i2c.h" -#include "qemu/bcd.h" -#include "sysemu/qtest.h" - -/* Size of NVRAM including both the user-accessible area and the - * secondary register area. - */ -#define NVRAM_SIZE 64 - -/* Flags definitions */ -#define SECONDS_CH 0x80 -#define HOURS_12 0x40 -#define HOURS_PM 0x20 -#define CTRL_OSF 0x20 - -#define TYPE_DS1338 "ds1338" -#define DS1338(obj) OBJECT_CHECK(DS1338State, (obj), TYPE_DS1338) - -typedef struct DS1338State { - I2CSlave parent_obj; - - int64_t offset; - uint8_t wday_offset; - uint8_t nvram[NVRAM_SIZE]; - int32_t ptr; - bool addr_byte; -} DS1338State; - -static const VMStateDescription vmstate_ds1338 =3D { - .name =3D "ds1338", - .version_id =3D 2, - .minimum_version_id =3D 1, - .fields =3D (VMStateField[]) { - VMSTATE_I2C_SLAVE(parent_obj, DS1338State), - VMSTATE_INT64(offset, DS1338State), - VMSTATE_UINT8_V(wday_offset, DS1338State, 2), - VMSTATE_UINT8_ARRAY(nvram, DS1338State, NVRAM_SIZE), - VMSTATE_INT32(ptr, DS1338State), - VMSTATE_BOOL(addr_byte, DS1338State), - VMSTATE_END_OF_LIST() - } -}; - -static void capture_current_time(DS1338State *s) -{ - /* Capture the current time into the secondary registers - * which will be actually read by the data transfer operation. - */ - struct tm now; - qemu_get_timedate(&now, s->offset); - s->nvram[0] =3D to_bcd(now.tm_sec); - s->nvram[1] =3D to_bcd(now.tm_min); - if (s->nvram[2] & HOURS_12) { - int tmp =3D now.tm_hour; - if (tmp % 12 =3D=3D 0) { - tmp +=3D 12; - } - if (tmp <=3D 12) { - s->nvram[2] =3D HOURS_12 | to_bcd(tmp); - } else { - s->nvram[2] =3D HOURS_12 | HOURS_PM | to_bcd(tmp - 12); - } - } else { - s->nvram[2] =3D to_bcd(now.tm_hour); - } - s->nvram[3] =3D (now.tm_wday + s->wday_offset) % 7 + 1; - s->nvram[4] =3D to_bcd(now.tm_mday); - s->nvram[5] =3D to_bcd(now.tm_mon + 1); - s->nvram[6] =3D to_bcd(now.tm_year - 100); -} - -static void inc_regptr(DS1338State *s) -{ - /* The register pointer wraps around after 0x3F; wraparound - * causes the current time/date to be retransferred into - * the secondary registers. - */ - s->ptr =3D (s->ptr + 1) & (NVRAM_SIZE - 1); - if (!s->ptr) { - capture_current_time(s); - } -} - -static int ds1338_event(I2CSlave *i2c, enum i2c_event event) -{ - DS1338State *s =3D DS1338(i2c); - - switch (event) { - case I2C_START_RECV: - /* In h/w, capture happens on any START condition, not just a - * START_RECV, but there is no need to actually capture on - * START_SEND, because the guest can't get at that data - * without going through a START_RECV which would overwrite it. - */ - capture_current_time(s); - break; - case I2C_START_SEND: - s->addr_byte =3D true; - break; - default: - break; - } - - return 0; -} - -static int ds1338_recv(I2CSlave *i2c) -{ - DS1338State *s =3D DS1338(i2c); - uint8_t res; - - res =3D s->nvram[s->ptr]; - inc_regptr(s); - return res; -} - -static int ds1338_send(I2CSlave *i2c, uint8_t data) -{ - DS1338State *s =3D DS1338(i2c); - - if (s->addr_byte) { - if (data =3D=3D 0xff && qtest_enabled()) { - /* magic, out of bounds, address to allow test code - * to reset offset - */ - s->offset =3D 0; - s->wday_offset =3D 0; - return 0; - } - s->ptr =3D data & (NVRAM_SIZE - 1); - s->addr_byte =3D false; - return 0; - } - if (s->ptr < 7) { - /* Time register. */ - struct tm now; - qemu_get_timedate(&now, s->offset); - switch(s->ptr) { - case 0: - /* TODO: Implement CH (stop) bit. */ - now.tm_sec =3D from_bcd(data & 0x7f); - break; - case 1: - now.tm_min =3D from_bcd(data & 0x7f); - break; - case 2: - if (data & HOURS_12) { - int tmp =3D from_bcd(data & (HOURS_PM - 1)); - if (data & HOURS_PM) { - tmp +=3D 12; - } - if (tmp % 12 =3D=3D 0) { - tmp -=3D 12; - } - now.tm_hour =3D tmp; - } else { - now.tm_hour =3D from_bcd(data & (HOURS_12 - 1)); - } - break; - case 3: - { - /* The day field is supposed to contain a value in - the range 1-7. Otherwise behavior is undefined. - */ - int user_wday =3D (data & 7) - 1; - s->wday_offset =3D (user_wday - now.tm_wday + 7) % 7; - } - break; - case 4: - now.tm_mday =3D from_bcd(data & 0x3f); - break; - case 5: - now.tm_mon =3D from_bcd(data & 0x1f) - 1; - break; - case 6: - now.tm_year =3D from_bcd(data) + 100; - break; - } - s->offset =3D qemu_timedate_diff(&now); - } else if (s->ptr =3D=3D 7) { - /* Control register. */ - - /* Ensure bits 2, 3 and 6 will read back as zero. */ - data &=3D 0xB3; - - /* Attempting to write the OSF flag to logic 1 leaves the - value unchanged. */ - data =3D (data & ~CTRL_OSF) | (data & s->nvram[s->ptr] & CTRL_OSF); - - s->nvram[s->ptr] =3D data; - } else { - s->nvram[s->ptr] =3D data; - } - inc_regptr(s); - return 0; -} - -static void ds1338_reset(DeviceState *dev) -{ - DS1338State *s =3D DS1338(dev); - - /* The clock is running and synchronized with the host */ - s->offset =3D 0; - s->wday_offset =3D 0; - memset(s->nvram, 0, NVRAM_SIZE); - s->ptr =3D 0; - s->addr_byte =3D false; -} - -static void ds1338_class_init(ObjectClass *klass, void *data) -{ - DeviceClass *dc =3D DEVICE_CLASS(klass); - I2CSlaveClass *k =3D I2C_SLAVE_CLASS(klass); - - k->event =3D ds1338_event; - k->recv =3D ds1338_recv; - k->send =3D ds1338_send; - dc->reset =3D ds1338_reset; - dc->vmsd =3D &vmstate_ds1338; -} - -static const TypeInfo ds1338_info =3D { - .name =3D TYPE_DS1338, - .parent =3D TYPE_I2C_SLAVE, - .instance_size =3D sizeof(DS1338State), - .class_init =3D ds1338_class_init, -}; - -static void ds1338_register_types(void) -{ - type_register_static(&ds1338_info); -} - -type_init(ds1338_register_types) --=20 2.11.0 From nobody Fri Oct 24 09:38:23 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519013170933224.35501621556398; Sun, 18 Feb 2018 20:06:10 -0800 (PST) Received: from localhost ([::1]:47448 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1enciQ-0000FV-61 for importer@patchew.org; Sun, 18 Feb 2018 23:06:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49537) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1encgf-0007fD-Kz for qemu-devel@nongnu.org; Sun, 18 Feb 2018 23:04:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1encge-0000mD-Nd for qemu-devel@nongnu.org; Sun, 18 Feb 2018 23:04:21 -0500 Received: from mail-io0-x241.google.com ([2607:f8b0:4001:c06::241]:43958) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1encge-0000lG-IT for qemu-devel@nongnu.org; Sun, 18 Feb 2018 23:04:20 -0500 Received: by mail-io0-x241.google.com with SMTP id l12so4181321ioc.10 for ; Sun, 18 Feb 2018 20:04:20 -0800 (PST) Received: from localhost.localdomain ([184.250.204.84]) by smtp.gmail.com with ESMTPSA id a13sm19158075itj.13.2018.02.18.20.04.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Feb 2018 20:04:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=eL+mjxiPzrWwWlrX/fU/m+LdgIhNQq6DF9JvvU+Eylk=; b=jM6NSTUaJNxM7zc3VuYjxPku4+VucUkMFeFzh3NM2/xA5kZmZM5qvkqoHKe0ADn3Ev aF3Tnaz+gvPQkX0G3ckPPFVXR5OPtdLauqz4JGj9FwQFq/16tj91PTEdw5jY3TmXRWJU kekquNGXwquAQRYcmeN9q+MxpL75wXH5NBZmyD62cyM6tPkJItf6N224GBD0lIkHRuD2 SCVkexfCeaQlPpgYHoPOcShB/JrhbLmCthGI0UE2ehMp7QHS6MrQg+b5FoDFK2z1sjdo exugeF5amQSPcn8LqvJ1/k0ydOLWzzxW5o+6fa5fr+l5OG77DHqff0Qrvee7QTfAnB3s ClLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=eL+mjxiPzrWwWlrX/fU/m+LdgIhNQq6DF9JvvU+Eylk=; b=pF3IiSYpNQDFbnIqTariAHrMA9xR1bqXqs3m08YcquGJ8DN0+N5EQ1pdnygvHsG4/g 93fGVpZk3I0pJbBCU5aYZnaj7lmyBZbamnosDwE3MmTBzldRDHX5CR6B1pQy7auxA9l8 XBsLoYOtzed6z7DCjD3PL1ZwhVPHiWtXG4Z/64L46qptGTTVuUfSmQ6DvNntjky8Dzk9 qgH2IQd7MCcA4udp2RwwPmmJN20wcMDXH4c5p0q0HoWHgp2u9W01O+WZP7pzayjZ0j6r 8TGGqO6QwSo3FnNqxIwjVdj/74iRqOxAag3c/bQdDbKwydt7jJSdWUd0EKvA+hPCGOsJ fX1Q== X-Gm-Message-State: APf1xPDoYh+TR2yMlNFw/B7v3yUqsnIbSfVg52mHDgM05fgJUUqsEhlR cAaWZOPJbHzh5ISCZx5qd18= X-Google-Smtp-Source: AH8x225/mK32MHhZyMc9Ckt71kacenIHGfzNs40law3onxqPNrPUo9Dmuxkx5d0zIt8mr89JP6/CIA== X-Received: by 10.107.141.79 with SMTP id p76mr17312127iod.97.1519013059822; Sun, 18 Feb 2018 20:04:19 -0800 (PST) From: Michael Davidsaver To: Paul Brook , Peter Maydell , Antoine Mathys Date: Sun, 18 Feb 2018 20:03:41 -0800 Message-Id: <20180219040342.12686-5-mdavidsaver@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180219040342.12686-1-mdavidsaver@gmail.com> References: <20180219040342.12686-1-mdavidsaver@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c06::241 Subject: [Qemu-devel] [PATCH 4/5] tests: ds-rtc-i2c-test test 12 hour mode and DoW X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Davidsaver , qemu-devel@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Test time set+get in 12 hour mode. Also test handling of day of week offset. Signed-off-by: Michael Davidsaver --- tests/ds-rtc-i2c-test.c | 54 +++++++++++++++++++++++++++++++++++++++++++++= +++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/tests/ds-rtc-i2c-test.c b/tests/ds-rtc-i2c-test.c index 464eb08558..226ac1399e 100644 --- a/tests/ds-rtc-i2c-test.c +++ b/tests/ds-rtc-i2c-test.c @@ -92,6 +92,18 @@ static uint8_t test_time_24_12am[8] =3D { 0x17, }; =20 +static uint8_t test_time_12_12am[8] =3D { + 0, /* address */ + /* Wed, 22 Nov 2017 00:30:53 +0000 */ + 0x53, + 0x30, + 0x52, /* 12 AM in 12 hour mode */ + 0x03, /* monday is our day 1 */ + 0x22, + 0x11 | 0x80, + 0x17, +}; + static uint8_t test_time_24_6am[8] =3D { 0, /* address */ /* Wed, 22 Nov 2017 06:30:53 +0000 */ @@ -104,6 +116,18 @@ static uint8_t test_time_24_6am[8] =3D { 0x17, }; =20 +static uint8_t test_time_12_6am[8] =3D { + 0, /* address */ + /* Wed, 22 Nov 2017 06:30:53 +0000 */ + 0x53, + 0x30, + 0x46, /* 6 AM in 12 hour mode */ + 0x03, /* monday is our day 1 */ + 0x22, + 0x11 | 0x80, + 0x17, +}; + static uint8_t test_time_24_12pm[8] =3D { 0, /* address */ /* Wed, 22 Nov 2017 12:30:53 +0000 */ @@ -116,6 +140,18 @@ static uint8_t test_time_24_12pm[8] =3D { 0x17, }; =20 +static uint8_t test_time_12_12pm[8] =3D { + 0, /* address */ + /* Wed, 22 Nov 2017 12:30:53 +0000 */ + 0x53, + 0x30, + 0x72, /* 12 PM in 24 hour mode */ + 0x03, /* monday is our day 1 */ + 0x22, + 0x11 | 0x80, + 0x17, +}; + static uint8_t test_time_24_6pm[8] =3D { 0, /* address */ /* Wed, 22 Nov 2017 18:30:53 +0000 */ @@ -128,6 +164,18 @@ static uint8_t test_time_24_6pm[8] =3D { 0x17, }; =20 +static uint8_t test_time_12_6pm[8] =3D { + 0, /* address */ + /* Wed, 22 Nov 2017 18:30:53 +0000 */ + 0x53, + 0x30, + 0x66, /* 6 PM in 12 hour mode */ + 0x03, /* monday is our day 1 */ + 0x22, + 0x11 | 0x80, + 0x17, +}; + /* write in and read back known time */ static void test_rtc_set(const void *raw) @@ -151,7 +199,7 @@ void test_rtc_set(const void *raw) g_assert_cmpuint(testtime[1], =3D=3D, buf[0]); /* SEC */ g_assert_cmpuint(testtime[2], =3D=3D, buf[1]); /* MIN */ g_assert_cmpuint(testtime[3], =3D=3D, buf[2]); /* HOUR */ - /* skip comparing Day of Week. Not handled correctly */ + g_assert_cmpuint(testtime[4], =3D=3D, buf[3]); /* DoW */ g_assert_cmpuint(testtime[5], =3D=3D, buf[4]); /* DoM */ if (use_century) { g_assert_cmpuint(testtime[6], =3D=3D, buf[5]); /* MON+century */ @@ -183,6 +231,10 @@ int main(int argc, char *argv[]) qtest_add_data_func("/ds-rtc-i2c/set24_6am", test_time_24_6am, test_rt= c_set); qtest_add_data_func("/ds-rtc-i2c/set24_12pm", test_time_24_12pm, test_= rtc_set); qtest_add_data_func("/ds-rtc-i2c/set24_6pm", test_time_24_6pm, test_rt= c_set); + qtest_add_data_func("/ds-rtc-i2c/set12_12am", test_time_12_12am, test_= rtc_set); + qtest_add_data_func("/ds-rtc-i2c/set12_6am", test_time_12_6am, test_rt= c_set); + qtest_add_data_func("/ds-rtc-i2c/set12_12pm", test_time_12_12pm, test_= rtc_set); + qtest_add_data_func("/ds-rtc-i2c/set12_6pm", test_time_12_6pm, test_rt= c_set); qtest_add_func("/ds-rtc-i2c/current", test_rtc_current); =20 ret =3D g_test_run(); --=20 2.11.0 From nobody Fri Oct 24 09:38:23 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 151901333352155.6382799282253; Sun, 18 Feb 2018 20:08:53 -0800 (PST) Received: from localhost ([::1]:47456 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1encl2-0002Bs-Oi for importer@patchew.org; Sun, 18 Feb 2018 23:08:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49564) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1encgk-0007jr-Nh for qemu-devel@nongnu.org; Sun, 18 Feb 2018 23:04:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1encgj-0000w9-H2 for qemu-devel@nongnu.org; Sun, 18 Feb 2018 23:04:26 -0500 Received: from mail-it0-x242.google.com ([2607:f8b0:4001:c0b::242]:35527) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1encgj-0000vE-CT for qemu-devel@nongnu.org; Sun, 18 Feb 2018 23:04:25 -0500 Received: by mail-it0-x242.google.com with SMTP id v194so7420047itb.0 for ; Sun, 18 Feb 2018 20:04:25 -0800 (PST) Received: from localhost.localdomain ([184.250.204.84]) by smtp.gmail.com with ESMTPSA id a13sm19158075itj.13.2018.02.18.20.04.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Feb 2018 20:04:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vMCr3PGnJvoo9Ni7UtyBW3nCcJ6wlVkUyRq9l2GMx88=; b=hzVcnQJgVeDjqmSP4R0IKkwEBxUFFA5XUd098bw9TFLVV0fQjF0aOikUoagDU5twdW pErGqtcEKVENp+l6BJ2eZIMRLaJeR3MRJX4GLOs/2h1gYvn1Q1dw8hk2tawQFJ4vC148 xqcJe1xf08CDoaic3eWW+3L1UzKDQ13IIDDim9xHiG5h3hio5PrC4z8udzhbwodWonbz QW9zT9vWyNgJgE3RoZt04khxCyBdkG1YHLrp58UvH8m+cupfdqoVT2tYkyIEMAT0Hclm GcuvRIXuxnv3A7O1wxpltkgfsWGQbYqHAcoiBqm4UiAFoRqx0WAdhh2srzS4e9LoMMCM vE+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vMCr3PGnJvoo9Ni7UtyBW3nCcJ6wlVkUyRq9l2GMx88=; b=szsoDlPyysBUN48YbXm9H7UP2N2ILsaU0lyLTJ9xR9rgakwgpt0hBoQ74y0ahrfnrq 3ff1MKlU7LJG7hPluKTmct6l/wK31N1BvBg8bjwuv1+NRvgfdENRVrFsHszZd6pnR90V NR2eU8esWZ/m2/c7fSqsB/9gRNPZ9PQnXAKw16mFbmkpY6pObLPmVs4QEhNjks3uEowB H6UgU1h8F0Bf9tYybSuF/VBknysV9O0xdv9b+AVrz3+eJqOlODeIa9GOS07UX/tvBgR+ oG4LUiXbjOP+E7Yk3P7WJJUQgYSRBLiP7Dtb3diNbDtBmsItBJW3SBsKqgoZdEPBelZD 5GBw== X-Gm-Message-State: APf1xPCi4kQwUKeep2SPnG3FgLcHFHlSDbcL62B6LMNl/nSMHTdkzNnO IMn6ncwJY+Ykw1RDN2RxoLk= X-Google-Smtp-Source: AH8x2261TpwTvd/Gsu7NBiVMGk1TLTeClAxrrdcme1wDId/EVKaRcDgphU33kHX9XSYRArrZjKlq+g== X-Received: by 10.36.159.134 with SMTP id c128mr7590197ite.135.1519013064674; Sun, 18 Feb 2018 20:04:24 -0800 (PST) From: Michael Davidsaver To: Paul Brook , Peter Maydell , Antoine Mathys Date: Sun, 18 Feb 2018 20:03:42 -0800 Message-Id: <20180219040342.12686-6-mdavidsaver@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180219040342.12686-1-mdavidsaver@gmail.com> References: <20180219040342.12686-1-mdavidsaver@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c0b::242 Subject: [Qemu-devel] [PATCH 5/5] tests: drop ds1338-test X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Davidsaver , qemu-devel@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Now redundant to ds-rtc-i2c-test. Signed-off-by: Michael Davidsaver --- tests/Makefile.include | 2 -- tests/ds1338-test.c | 75 ----------------------------------------------= ---- 2 files changed, 77 deletions(-) delete mode 100644 tests/ds1338-test.c diff --git a/tests/Makefile.include b/tests/Makefile.include index f5dcd274e0..8b1e486e32 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -359,7 +359,6 @@ check-qtest-sparc64-y +=3D tests/prom-env-test$(EXESUF) check-qtest-sparc64-y +=3D tests/boot-serial-test$(EXESUF) =20 check-qtest-arm-y =3D tests/tmp105-test$(EXESUF) -check-qtest-arm-y +=3D tests/ds1338-test$(EXESUF) check-qtest-arm-y +=3D tests/ds-rtc-i2c-test$(EXESUF) check-qtest-arm-y +=3D tests/m25p80-test$(EXESUF) gcov-files-arm-y +=3D hw/misc/tmp105.c @@ -764,7 +763,6 @@ tests/bios-tables-test$(EXESUF): tests/bios-tables-test= .o \ tests/boot-sector.o tests/acpi-utils.o $(libqos-obj-y) tests/pxe-test$(EXESUF): tests/pxe-test.o tests/boot-sector.o $(libqos-obj= -y) tests/tmp105-test$(EXESUF): tests/tmp105-test.o $(libqos-omap-obj-y) -tests/ds1338-test$(EXESUF): tests/ds1338-test.o $(libqos-imx-obj-y) tests/ds-rtc-i2c-test$(EXESUF): tests/ds-rtc-i2c-test.o $(libqos-imx-obj-y) tests/m25p80-test$(EXESUF): tests/m25p80-test.o tests/i440fx-test$(EXESUF): tests/i440fx-test.o $(libqos-pc-obj-y) diff --git a/tests/ds1338-test.c b/tests/ds1338-test.c deleted file mode 100644 index 742dad9113..0000000000 --- a/tests/ds1338-test.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * QTest testcase for the DS1338 RTC - * - * Copyright (c) 2013 Jean-Christophe Dubois - * - * 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 WI= THOUT - * 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 . - */ - -#include "qemu/osdep.h" -#include "libqtest.h" -#include "libqos/i2c.h" - -#define IMX25_I2C_0_BASE 0x43F80000 - -#define DS1338_ADDR 0x68 - -static I2CAdapter *i2c; -static uint8_t addr; - -static inline uint8_t bcd2bin(uint8_t x) -{ - return ((x) & 0x0f) + ((x) >> 4) * 10; -} - -static void send_and_receive(void) -{ - uint8_t cmd[1]; - uint8_t resp[7]; - time_t now =3D time(NULL); - struct tm *tm_ptr =3D gmtime(&now); - - /* reset the index in the RTC memory */ - cmd[0] =3D 0; - i2c_send(i2c, addr, cmd, 1); - - /* retrieve the date */ - i2c_recv(i2c, addr, resp, 7); - - /* check retrieved time againt local time */ - g_assert_cmpuint(bcd2bin(resp[4]), =3D=3D , tm_ptr->tm_mday); - g_assert_cmpuint(bcd2bin(resp[5]), =3D=3D , 1 + tm_ptr->tm_mon); - g_assert_cmpuint(2000 + bcd2bin(resp[6]), =3D=3D , 1900 + tm_ptr->tm_y= ear); -} - -int main(int argc, char **argv) -{ - QTestState *s =3D NULL; - int ret; - - g_test_init(&argc, &argv, NULL); - - s =3D qtest_start("-display none -machine imx25-pdk"); - i2c =3D imx_i2c_create(s, IMX25_I2C_0_BASE); - addr =3D DS1338_ADDR; - - qtest_add_func("/ds1338/tx-rx", send_and_receive); - - ret =3D g_test_run(); - - qtest_quit(s); - g_free(i2c); - - return ret; -} --=20 2.11.0