From nobody Thu May 2 00:59:42 2024 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521923242100604.7653908933793; Sat, 24 Mar 2018 13:27:22 -0700 (PDT) Received: from localhost ([::1]:47903 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezpkx-0002Nx-7S for importer@patchew.org; Sat, 24 Mar 2018 16:27:15 -0400 Received: from eggs.gnu.org ([208.118.235.92]:43423) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezpiu-0001aX-JH for qemu-devel@nongnu.org; Sat, 24 Mar 2018 16:26:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ezphq-0003Kf-J6 for qemu-devel@nongnu.org; Sat, 24 Mar 2018 16:25:08 -0400 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:35170) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ezomq-0005j6-7m for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:25:08 -0400 Received: by mail-pf0-x242.google.com with SMTP id u86so211550pfd.2 for ; Sat, 24 Mar 2018 12:25:08 -0700 (PDT) Received: from localhost.localdomain (c-73-158-53-43.hsd1.ca.comcast.net. [73.158.53.43]) by smtp.gmail.com with ESMTPSA id o2sm13353501pgq.87.2018.03.24.12.25.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Mar 2018 12:25:06 -0700 (PDT) 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=1k5rTzGPwWdRPy3bbkwT0H2zsDdAS8XuRFc2bwRqLK0=; b=f5MPnJRdkS2JkLTspPwZBMEueD9YhmccrDScE7230zoTH+xCu+vprlYwRTTyS2f9QW 4GhfIYU8g+riH83y8TZ4EFhPLX8LmfkbeHFPr8jMxAH3PvvOWe5bR1GBWzhkaIjA3eiF r9QKFqPqvQkoWm1ixwpy9SJqo2FPF8GIh3fh3c5esiF4XhGEFbAq7jWqB83ycUXB+gMB kBd1foRoNAhcovHlMGK2KspisIOHKIiCF2+lb05FUKfaXXkbzrGkQ9uZNj/Vc+dFUyEa CLuew4QB9EkuAT4zJtMDu3t2Fr2G8Eyyuw6Owm07s8yYJYNT1j3stZXt9qzwlruHgFDk xZMA== 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=1k5rTzGPwWdRPy3bbkwT0H2zsDdAS8XuRFc2bwRqLK0=; b=GrlYtT9U0Qk62op8vJy+mW94/xImSmlO3RSUUtjmgXWA1ymKYLJNBnzVHFyt3bUzoV ATFYonEOb7k3FJOhyRgbylxg1gWrNxOXucKSbmHdj3GyZiQGXOgYR4zvXrq0M0rZZre8 tbKhcsn/7B07IYzsSti+E4qcPDPd+ag+PkdmN5IaBvxww/5ZLbSdYMmzOLItqmZ34fzH rB5A/M0dgU/zf2Cvqva7QAk757yJ2Go0lNqOz9nD0nsjiPUc08NfF/6HLEzOMwXcusU4 /bV+cTMKlIHCmTCldUUeppyywg0lX6PSzc2CeDu04ZJFe4GIUhra0VzqpHjFWE5NBHxk 3G2w== X-Gm-Message-State: AElRT7EZmfXNiQvNBK3kfRuivYmjF1lBZUVpNFNjS0zbfti9khmxHFP7 +fk5lf3+6uUgxpyuJqEARec= X-Google-Smtp-Source: AG47ELt1CFIajczNqPH5cXU0shd2rOSjpWJXZNe16fesvmVLB96vJE+Xxku7dDBBbgeKp6d4vwo4Jw== X-Received: by 10.101.66.11 with SMTP id c11mr3610761pgq.80.1521919507114; Sat, 24 Mar 2018 12:25:07 -0700 (PDT) From: Michael Davidsaver To: Peter Maydell , Thomas Huth Date: Sat, 24 Mar 2018 12:24:42 -0700 Message-Id: <20180324192455.12254-2-mdavidsaver@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180324192455.12254-1-mdavidsaver@gmail.com> References: <20180324192455.12254-1-mdavidsaver@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::242 Subject: [Qemu-devel] [PATCH 01/14] tests: more thorough tests 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: Antoine Mathys , 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. Separate current time test from set/get tests to avoid test order issues. Signed-off-by: Michael Davidsaver --- tests/Makefile.include | 4 ++ tests/ds-rtc-common.h | 67 +++++++++++++++++++++++++ tests/ds-rtc-current-test.c | 59 ++++++++++++++++++++++ tests/ds-rtc-set-test.c | 117 ++++++++++++++++++++++++++++++++++++++++= ++++ 4 files changed, 247 insertions(+) create mode 100644 tests/ds-rtc-common.h create mode 100644 tests/ds-rtc-current-test.c create mode 100644 tests/ds-rtc-set-test.c diff --git a/tests/Makefile.include b/tests/Makefile.include index eb218a9539..d256095c88 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -372,6 +372,8 @@ 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-current-test$(EXESUF) +check-qtest-arm-y +=3D tests/ds-rtc-set-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) @@ -771,6 +773,8 @@ 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-current-test$(EXESUF): tests/ds-rtc-current-test.o $(libqos-i= mx-obj-y) +tests/ds-rtc-set-test$(EXESUF): tests/ds-rtc-set-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-common.h b/tests/ds-rtc-common.h new file mode 100644 index 0000000000..c8e6c2bc5b --- /dev/null +++ b/tests/ds-rtc-common.h @@ -0,0 +1,67 @@ +/* Common code for testing of Dallas/Maxim I2C bus RTC devices + * + * Copyright (c) 2018 Michael Davidsaver + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the LICENSE file in the top-level directory. + */ +#ifndef DSRTCCOMMON_H +#define DSRTCCOMMON_H + +#include "qemu/osdep.h" +#include "qemu/cutils.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; + +/* input buffer must have at least 7 elements */ +static inline time_t rtc_parse(const uint8_t *buf) +{ + struct tm parts; + + 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); +} + +static time_t rtc_gettime(void) +{ + uint8_t buf[7]; + + /* zero address pointer */ + buf[0] =3D 0; + i2c_send(i2c, addr, buf, 1); + /* read back current time registers */ + i2c_recv(i2c, addr, buf, 7); + + return rtc_parse(buf); +} + +#endif /* DSRTCCOMMON_H */ diff --git a/tests/ds-rtc-current-test.c b/tests/ds-rtc-current-test.c new file mode 100644 index 0000000000..6acbbed9a6 --- /dev/null +++ b/tests/ds-rtc-current-test.c @@ -0,0 +1,59 @@ +/* Testing of Dallas/Maxim I2C bus RTC devices + * + * Copyright (c) 2018 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 "libqtest.h" +#include "libqos/libqos.h" +#include "libqos/i2c.h" + +#include "ds-rtc-common.h" + +/* read back and compare with current system time */ +static +void test_rtc_current(void) +{ + time_t expected, actual; + /* relax test to limit false positives when host may be overloaded. + * Allow larger delta when running "-m quick" + */ + time_t max_delta =3D g_test_slow() ? 1 : 30; + + actual =3D time(NULL); + /* new second may start here */ + expected =3D rtc_gettime(); + g_assert_cmpuint(expected, <=3D, actual + max_delta); + g_assert_cmpuint(expected, >=3D, actual); +} + +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("-machine imx25-pdk"); + i2c =3D imx_i2c_create(s, IMX25_I2C_0_BASE); + addr =3D DS1338_ADDR; + use_century =3D false; + + } + + qtest_add_func("/ds-rtc-i2c/current", test_rtc_current); + + ret =3D g_test_run(); + + qtest_end(); + + return ret; +} diff --git a/tests/ds-rtc-set-test.c b/tests/ds-rtc-set-test.c new file mode 100644 index 0000000000..35e1a36281 --- /dev/null +++ b/tests/ds-rtc-set-test.c @@ -0,0 +1,117 @@ +/* Testing of Dallas/Maxim I2C bus RTC devices + * + * Copyright (c) 2018 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" + +#include "ds-rtc-common.h" + +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) +{ + /* relax test to limit false positives when host may be overloaded. + * Allow larger delta when running "-m quick" + */ + time_t max_delta =3D g_test_slow() ? 1 : 30; + + const uint8_t *testtime =3D raw; + time_t expected, actual; + + /* skip address pointer and parse remainder */ + expected =3D rtc_parse(&testtime[1]); + + i2c_send(i2c, addr, testtime, 8); + /* host may start new second here */ + actual =3D rtc_gettime(); + + g_assert_cmpuint(expected, <=3D, actual); + g_assert_cmpuint(expected + max_delta, >=3D, actual); +} + +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); + + ret =3D g_test_run(); + + qtest_end(); + + return ret; +} --=20 2.11.0 From nobody Thu May 2 00:59:42 2024 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 1521920200684261.15267084312904; Sat, 24 Mar 2018 12:36:40 -0700 (PDT) Received: from localhost ([::1]:47346 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezoxz-0006rr-Se for importer@patchew.org; Sat, 24 Mar 2018 15:36:39 -0400 Received: from eggs.gnu.org ([208.118.235.92]:41978) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezosr-0007IC-Gy for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:32:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ezomr-0005kG-Rd for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:26:15 -0400 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:40226) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ezomr-0005jp-K5 for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:25:09 -0400 Received: by mail-pf0-x242.google.com with SMTP id v66so3513432pfv.7 for ; Sat, 24 Mar 2018 12:25:09 -0700 (PDT) Received: from localhost.localdomain (c-73-158-53-43.hsd1.ca.comcast.net. [73.158.53.43]) by smtp.gmail.com with ESMTPSA id o2sm13353501pgq.87.2018.03.24.12.25.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Mar 2018 12:25:07 -0700 (PDT) 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=qlV7D8p28eqz/qEKLDkrQD4HpRIQi3Bd5jFDPyjHHSo=; b=ql6aT9MmGiREQmRZ99pko4xDIkuyO64KlcRa9h/U9QVrYePvY9qVRBm0KVm4IY41PF ej3DVl4Egql8I+hcFT8/CBdORqyZ+8auQOBm0XbDLx+Y0kVJbYpDd6v5pcMgJ8Sfaifx 1W2/yDeaPo4MBS84rdoxJo9xftv7oJtNu1vGZYZ2IWvMT0+dQsGrs5odT++PcPDshvDU qEASZpc1zQjnFCTsw8ZaYzLBq3RAFDR200BhpQNqnSolu1DW87i5gKxC+XmElImdcCww fhr5z3K+WFHE1gfjF+hIZimdvqQtOp9k+y7FZey07zxCnNDZPQwCO/YIoWEwfDU+nISm 6dnQ== 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=qlV7D8p28eqz/qEKLDkrQD4HpRIQi3Bd5jFDPyjHHSo=; b=pjPvYzTKfhbmxtaYcY+2f8swLdSgps2sKECkFJSAVzge3AREIW5e2wfVL7MUX1obk5 JoSHam4IbomonGZ8dDhZ5njnw0Or5qD2GxKWRLG9823xrHnhmDrGUA2ozDmRdajm/JON N8J0eF8RrC4eMQfi9vdJq1BZDmCD9nc/KICNWmyxdhkmjPwEcGID2Dprd3f1zrEDqssb PG7joEVOzLg0Vnz1BT/NqY267ZVUuuxQXmU1/P8BWGo40Jak7ACEOPsP4670UbZB/kPA YRWmGxIuvQBgGpfqEIPONyLNNbWEN+v/jtwodXcg7JZi/Qnh9xp3w2ztDVJRH+mwXnOf zMmA== X-Gm-Message-State: AElRT7HTd28ECdBMpRlivm2MWVs5nS3XxFGXH4ENGsCtGq8Rcx4FnjlV oEXCWp8uN9Vx8MRyiocIJV4= X-Google-Smtp-Source: AG47ELtrjsosm3i1Uf66N3HCy43Erk23DArw76BXpUq+FbdKynrLBZYrgQ13ESCTem0LsFhAkq1XHg== X-Received: by 10.99.97.138 with SMTP id v132mr24200702pgb.138.1521919508688; Sat, 24 Mar 2018 12:25:08 -0700 (PDT) From: Michael Davidsaver To: Peter Maydell , Thomas Huth Date: Sat, 24 Mar 2018 12:24:43 -0700 Message-Id: <20180324192455.12254-3-mdavidsaver@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180324192455.12254-1-mdavidsaver@gmail.com> References: <20180324192455.12254-1-mdavidsaver@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::242 Subject: [Qemu-devel] [PATCH 02/14] timer: ds1338 use registerfields.h 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: Antoine Mathys , 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" Use names for registers and bits except for R_CTRL which will be dealt with later, and isn't modeled anyway. Signed-off-by: Michael Davidsaver Reviewed-by: Peter Maydell --- hw/timer/ds1338.c | 84 ++++++++++++++++++++++++++++++++++++++-------------= ---- 1 file changed, 58 insertions(+), 26 deletions(-) diff --git a/hw/timer/ds1338.c b/hw/timer/ds1338.c index 3849b74a68..b5630e214a 100644 --- a/hw/timer/ds1338.c +++ b/hw/timer/ds1338.c @@ -13,6 +13,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" #include "hw/i2c/i2c.h" +#include "hw/registerfields.h" #include "qemu/bcd.h" =20 /* Size of NVRAM including both the user-accessible area and the @@ -20,15 +21,42 @@ */ #define NVRAM_SIZE 64 =20 -/* Flags definitions */ -#define SECONDS_CH 0x80 -#define HOURS_12 0x40 -#define HOURS_PM 0x20 #define CTRL_OSF 0x20 =20 #define TYPE_DS1338 "ds1338" #define DS1338(obj) OBJECT_CHECK(DS1338State, (obj), TYPE_DS1338) =20 +/* 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) + +#define R_CTRL (0x7) + +/* use 12 hour mode when set */ +FIELD(HOUR, SET12, 6, 1) +/* 00-23 */ +FIELD(HOUR, HOUR24, 0, 6) +/* PM when set */ +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) + +FIELD(CTRL, OSF, 5, 1) + typedef struct DS1338State { I2CSlave parent_obj; =20 @@ -61,25 +89,29 @@ static void capture_current_time(DS1338State *s) */ 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) { + s->nvram[R_SEC] =3D to_bcd(now.tm_sec); + s->nvram[R_MIN] =3D to_bcd(now.tm_min); + if (ARRAY_FIELD_EX32(s->nvram, HOUR, SET12)) { int tmp =3D now.tm_hour; if (tmp % 12 =3D=3D 0) { tmp +=3D 12; } + s->nvram[R_HOUR] =3D 0; + ARRAY_FIELD_DP32(s->nvram, HOUR, SET12, 1); if (tmp <=3D 12) { - s->nvram[2] =3D HOURS_12 | to_bcd(tmp); + ARRAY_FIELD_DP32(s->nvram, HOUR, AMPM, 0); + ARRAY_FIELD_DP32(s->nvram, HOUR, HOUR12, to_bcd(tmp)); } else { - s->nvram[2] =3D HOURS_12 | HOURS_PM | to_bcd(tmp - 12); + ARRAY_FIELD_DP32(s->nvram, HOUR, AMPM, 1); + ARRAY_FIELD_DP32(s->nvram, HOUR, HOUR12, to_bcd(tmp - 12)); } } else { - s->nvram[2] =3D to_bcd(now.tm_hour); + ARRAY_FIELD_DP32(s->nvram, HOUR, HOUR24, 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); + s->nvram[R_WDAY] =3D (now.tm_wday + s->wday_offset) % 7 + 1; + s->nvram[R_DATE] =3D to_bcd(now.tm_mday); + s->nvram[R_MONTH] =3D to_bcd(now.tm_mon + 1); + s->nvram[R_YEAR] =3D to_bcd(now.tm_year - 100); } =20 static void inc_regptr(DS1338State *s) @@ -141,17 +173,17 @@ static int ds1338_send(I2CSlave *i2c, uint8_t data) struct tm now; qemu_get_timedate(&now, s->offset); switch(s->ptr) { - case 0: + case R_SEC: /* TODO: Implement CH (stop) bit. */ now.tm_sec =3D from_bcd(data & 0x7f); break; - case 1: + case R_MIN: 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) { + case R_HOUR: + if (FIELD_EX32(data, HOUR, SET12)) { + int tmp =3D from_bcd(FIELD_EX32(data, HOUR, HOUR12)); + if (FIELD_EX32(data, HOUR, AMPM)) { tmp +=3D 12; } if (tmp % 12 =3D=3D 0) { @@ -159,10 +191,10 @@ static int ds1338_send(I2CSlave *i2c, uint8_t data) } now.tm_hour =3D tmp; } else { - now.tm_hour =3D from_bcd(data & (HOURS_12 - 1)); + now.tm_hour =3D from_bcd(FIELD_EX32(data, HOUR, HOUR24)); } break; - case 3: + case R_WDAY: { /* The day field is supposed to contain a value in the range 1-7. Otherwise behavior is undefined. @@ -171,18 +203,18 @@ static int ds1338_send(I2CSlave *i2c, uint8_t data) s->wday_offset =3D (user_wday - now.tm_wday + 7) % 7; } break; - case 4: + case R_DATE: now.tm_mday =3D from_bcd(data & 0x3f); break; - case 5: + case R_MONTH: now.tm_mon =3D from_bcd(data & 0x1f) - 1; break; - case 6: + case R_YEAR: now.tm_year =3D from_bcd(data) + 100; break; } s->offset =3D qemu_timedate_diff(&now); - } else if (s->ptr =3D=3D 7) { + } else if (s->ptr =3D=3D R_CTRL) { /* Control register. */ =20 /* Ensure bits 2, 3 and 6 will read back as zero. */ --=20 2.11.0 From nobody Thu May 2 00:59:42 2024 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 1521926435760949.7329887950356; Sat, 24 Mar 2018 14:20:35 -0700 (PDT) Received: from localhost ([::1]:48564 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezqaY-0006uD-Nv for importer@patchew.org; Sat, 24 Mar 2018 17:20:34 -0400 Received: from eggs.gnu.org ([208.118.235.92]:42355) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezqXO-0004ku-FP for qemu-devel@nongnu.org; Sat, 24 Mar 2018 17:18:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ezqRU-0003zh-EG for qemu-devel@nongnu.org; Sat, 24 Mar 2018 17:12:18 -0400 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:38759) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ezomt-0005kV-1a for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:25:11 -0400 Received: by mail-pg0-x243.google.com with SMTP id a15so5799807pgn.5 for ; Sat, 24 Mar 2018 12:25:10 -0700 (PDT) Received: from localhost.localdomain (c-73-158-53-43.hsd1.ca.comcast.net. [73.158.53.43]) by smtp.gmail.com with ESMTPSA id o2sm13353501pgq.87.2018.03.24.12.25.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Mar 2018 12:25:09 -0700 (PDT) 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=ahFAkdEJRXuXFXa/PLPUKCKf+AlnmI2OSgXAgXXrkQ0=; b=Ac6XSKTmsJrKLSEPdy96cF4BIvglp3mhQlRsDKhrsjU10ocxwQizBNEv8DFD6FHdXM sDTUjCsJB7BTpqdxRYvkMh8k3eti/CA1CQ51PrV7Mpk+3jtMgSU9NZkvkrSaoqPt6jck QCkDNuH7ZG/JvlS8Vvr0pntLrgGKitLGWVyxQ4LEZdAm2z0lTA0VL6kXpAFkHYBPnRww w5NNTrqwDEjnyZXXXZuL6/njuU228S/UD+Bdm8VGU2P5y84opmuslc9MhUM7X+8mTkvp hISbqYTtnaa0zMsbbBE7q3JeSVtf2hewhoayhj7p8zm+EEx7fcY3/WYu+4Y5clvLvqZ+ PEMA== 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=ahFAkdEJRXuXFXa/PLPUKCKf+AlnmI2OSgXAgXXrkQ0=; b=r6dZQ35dqdti3h0gkQIlB8fgOY1ag4mdCyr4oLods+Gv6OnLF5gCO7oyeETBvTBC65 Ts0BN4kcEs2R552dWYTW+8XwSAkzUxc1oGNLyXdLzqt/6lJhwHzjH1O3b39WbpJqtjCc xpM1YsGLZ75U4KcyHNDUg52xfDaMBBm7NdRgfWFMiGtpSY8cnZZsKN7yEnUVtbCoCwDm udLEzLd6TREJZunRbAEteBRsc//JsrUyLeaoTKk2SOqElaVYxYfFygdfOk34DnrAjp/b AItHZ/Oy6YNNzc6AeMLlD98LcTe9LG8GXro5N6QgZ/8CNe+3dHMfIOhhmwn4bCwFh5hT eo2Q== X-Gm-Message-State: AElRT7EJcVWuZvsxq+lCqH9baTlKeeDRK8dk6LP1WsN+PVxaICSkI2/C FyRqDaYdhQ6iF0jvCoM85r0rjA== X-Google-Smtp-Source: AG47ELv235gb1JYEXGFX66uzBJJci/ZrBjl1YpRMNQrld+XLj6VurzNy+8usInGrtTma2LPcFELS6Q== X-Received: by 10.167.131.135 with SMTP id u7mr28029437pfm.50.1521919510151; Sat, 24 Mar 2018 12:25:10 -0700 (PDT) From: Michael Davidsaver To: Peter Maydell , Thomas Huth Date: Sat, 24 Mar 2018 12:24:44 -0700 Message-Id: <20180324192455.12254-4-mdavidsaver@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180324192455.12254-1-mdavidsaver@gmail.com> References: <20180324192455.12254-1-mdavidsaver@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::243 Subject: [Qemu-devel] [PATCH 03/14] timer: ds1338 persist 12-hour mode selection 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: Antoine Mathys , 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" Need to save HOUR[HOUR12] bit to keep track of guest selection of 12-hour mode. Write through current time registers to achieve this. Will be overwritten by the next read/latch. Signed-off-by: Michael Davidsaver --- hw/timer/ds1338.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/hw/timer/ds1338.c b/hw/timer/ds1338.c index b5630e214a..72a4692d60 100644 --- a/hw/timer/ds1338.c +++ b/hw/timer/ds1338.c @@ -224,10 +224,8 @@ static int ds1338_send(I2CSlave *i2c, uint8_t data) value unchanged. */ data =3D (data & ~CTRL_OSF) | (data & s->nvram[s->ptr] & CTRL_OSF); =20 - s->nvram[s->ptr] =3D data; - } else { - s->nvram[s->ptr] =3D data; } + s->nvram[s->ptr] =3D data; inc_regptr(s); return 0; } --=20 2.11.0 From nobody Thu May 2 00:59:42 2024 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 1521920348998366.8764643840751; Sat, 24 Mar 2018 12:39:08 -0700 (PDT) Received: from localhost ([::1]:47359 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezp0O-0000QC-3c for importer@patchew.org; Sat, 24 Mar 2018 15:39:08 -0400 Received: from eggs.gnu.org ([208.118.235.92]:43246) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezoxd-0000Bv-Bd for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:37:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ezomu-0005lC-KO for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:28:50 -0400 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:33136) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ezomu-0005ku-E2 for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:25:12 -0400 Received: by mail-pf0-x243.google.com with SMTP id f15so243982pfn.0 for ; Sat, 24 Mar 2018 12:25:12 -0700 (PDT) Received: from localhost.localdomain (c-73-158-53-43.hsd1.ca.comcast.net. [73.158.53.43]) by smtp.gmail.com with ESMTPSA id o2sm13353501pgq.87.2018.03.24.12.25.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Mar 2018 12:25:10 -0700 (PDT) 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=61tm8g8WxGzc8lT5vJ79WZsP2A+E/TKcEFA8TYOUxYQ=; b=KH8PYzGQVAxzQBuAGh88tPXy5PT/QAghN0Wcgi7RDvany5PKfZzE7NHk8CFix73rQ5 DelK8KZitphg+JMxCP8bC1ju7UmDzU/1RXnG+3f0EVhYQ1Xtws1De+Hsp6WYbk/ktmDz Uvj5dubGkkaH4vwiB1hAt8kkoRfaVISpUVm6n6lWoxqzZ102KoX5Y8HWs2bktADGfwaT FNfIEdgdejkgzJ/12BZdGCxDogxQ0SHnzg+ek7xTKfxAVNeHAP7mGJT92m+CNUmjei/o 3SUMuG+pZFYuQn5BTw0oWk6v8vNkDtAZr1W0Ik8CpHqPYxg9/JKVHRl0MJzFO1M2fp49 YrMw== 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=61tm8g8WxGzc8lT5vJ79WZsP2A+E/TKcEFA8TYOUxYQ=; b=gdMFeQ7bTvUZW+l8/ONo4hdrfdn01k+MpsxVNaoxt8NEh5xzWdzn2lIzhoIU4dDCNJ zVnE43Ylhb4UGPj+EZt3SsiCr8lb5d1pNZHkqNihiWjOLwhDP7qMYr0vTM9lQ8ANSkvV R4Z0dQoxDSmjJyNDcKTG7CKNWvvlbMNja8ElLQNZjOVewu5zlwN6+hwITBjuonsCXqwf iypn5PN8RD9kKxWbwtP0PqYcXNLa3TvL+IiQp2bsQcaIHVaM7QzoIoqJk2uxTymrKhul 3/19NGyTNXS1Yp8/TYUfrmOgAvw2lQdd3uCt6E3iScxYtZPXsZUvwy0GWSKSh1ULsViw mmjg== X-Gm-Message-State: AElRT7GtmAmNtggmbAI8gOE8Q47Roq9XdIqM4myEylwuLHbmI+k1GEiu vTEVwRoV7ORyDgGvd4LOAJY= X-Google-Smtp-Source: AG47ELvOtshG1sVl1BkIETPa9DZQI1x2Um26ixLs2BzsVtIxyZvhH4ka+RqQxU48xdYKLk7JtW48tg== X-Received: by 10.167.129.217 with SMTP id c25mr8526816pfn.143.1521919511534; Sat, 24 Mar 2018 12:25:11 -0700 (PDT) From: Michael Davidsaver To: Peter Maydell , Thomas Huth Date: Sat, 24 Mar 2018 12:24:45 -0700 Message-Id: <20180324192455.12254-5-mdavidsaver@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180324192455.12254-1-mdavidsaver@gmail.com> References: <20180324192455.12254-1-mdavidsaver@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::243 Subject: [Qemu-devel] [PATCH 04/14] timer: ds1338 clarify HOUR handling 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: Antoine Mathys , 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" Simplify and comment the translation between registers and struct tm. Signed-off-by: Michael Davidsaver --- hw/timer/ds1338.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/hw/timer/ds1338.c b/hw/timer/ds1338.c index 72a4692d60..9bcda26e51 100644 --- a/hw/timer/ds1338.c +++ b/hw/timer/ds1338.c @@ -88,23 +88,23 @@ static void capture_current_time(DS1338State *s) * which will be actually read by the data transfer operation. */ struct tm now; + bool mode12 =3D ARRAY_FIELD_EX32(s->nvram, HOUR, SET12); qemu_get_timedate(&now, s->offset); + s->nvram[R_SEC] =3D to_bcd(now.tm_sec); s->nvram[R_MIN] =3D to_bcd(now.tm_min); - if (ARRAY_FIELD_EX32(s->nvram, HOUR, SET12)) { - int tmp =3D now.tm_hour; - if (tmp % 12 =3D=3D 0) { - tmp +=3D 12; - } - s->nvram[R_HOUR] =3D 0; + s->nvram[R_HOUR] =3D 0; + if (mode12) { + /* map 0-23 to 1-12 am/pm */ ARRAY_FIELD_DP32(s->nvram, HOUR, SET12, 1); - if (tmp <=3D 12) { - ARRAY_FIELD_DP32(s->nvram, HOUR, AMPM, 0); - ARRAY_FIELD_DP32(s->nvram, HOUR, HOUR12, to_bcd(tmp)); - } else { - ARRAY_FIELD_DP32(s->nvram, HOUR, AMPM, 1); - ARRAY_FIELD_DP32(s->nvram, HOUR, HOUR12, to_bcd(tmp - 12)); + ARRAY_FIELD_DP32(s->nvram, 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(s->nvram, HOUR, HOUR12, to_bcd(now.tm_hour)); + } else { ARRAY_FIELD_DP32(s->nvram, HOUR, HOUR24, to_bcd(now.tm_hour)); } @@ -182,14 +182,13 @@ static int ds1338_send(I2CSlave *i2c, uint8_t data) break; case R_HOUR: if (FIELD_EX32(data, HOUR, SET12)) { - int tmp =3D from_bcd(FIELD_EX32(data, HOUR, HOUR12)); + /* 12 hour (1-12) */ + /* read and wrap 1-12 -> 0-11 */ + now.tm_hour =3D from_bcd(FIELD_EX32(data, HOUR, HOUR12)) %= 12u; if (FIELD_EX32(data, HOUR, AMPM)) { - tmp +=3D 12; + now.tm_hour +=3D 12; } - if (tmp % 12 =3D=3D 0) { - tmp -=3D 12; - } - now.tm_hour =3D tmp; + } else { now.tm_hour =3D from_bcd(FIELD_EX32(data, HOUR, HOUR24)); } --=20 2.11.0 From nobody Thu May 2 00:59:42 2024 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 1521919839510469.13409040714623; Sat, 24 Mar 2018 12:30:39 -0700 (PDT) Received: from localhost ([::1]:47299 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezosA-0002bF-OC for importer@patchew.org; Sat, 24 Mar 2018 15:30:38 -0400 Received: from eggs.gnu.org ([208.118.235.92]:42534) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezoo0-0007lh-6c for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:27:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ezomw-0005lc-70 for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:26:20 -0400 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:37590) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ezomw-0005lR-0d for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:25:14 -0400 Received: by mail-pg0-x244.google.com with SMTP id n11so5794125pgp.4 for ; Sat, 24 Mar 2018 12:25:13 -0700 (PDT) Received: from localhost.localdomain (c-73-158-53-43.hsd1.ca.comcast.net. [73.158.53.43]) by smtp.gmail.com with ESMTPSA id o2sm13353501pgq.87.2018.03.24.12.25.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Mar 2018 12:25:12 -0700 (PDT) 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=qAkYEAho9w3wxPw98Ztgp+qgj0nSISNc3ZLSxXWJaho=; b=tgs4N3eu7NBDlIvYiUIzgBteAPC7oGcZn0Hjt7AbE8f+PeWPhNqRImqQSF4ohRFC/V u1xZAmgA/tJQxFeZcGfkRw4dYHwifElDCE4qBxKu/ohncQqY1+aqY1dNkzyqWvtt2W2k vxb+/TJdhDkpcdbiDEgMQWDOZKkemQDYjHgFCF6a+GwRyKiHLPvHRkZr5YVAJk/Cu65z aKoX0KtMotciz6VcLNFS+eWMQOZBCwrLu1IK9N+4P+SZ5o8pnWIlQATj6udoYM1t9lBV D5ppfBTmzKE+5gfxkNHO/gYDwn8vT7y7GzOAVJHhDey/Kx1W243UkTm+CXmQC2h+4aAv 0c9A== 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=qAkYEAho9w3wxPw98Ztgp+qgj0nSISNc3ZLSxXWJaho=; b=Qm3ime2TqLC9I1kDb/OZEfKh4ZhA5KAnKwCWq0fFlIOG8zN/gaXE1AXhHm/f8OUvcn LTZUsRLLz/A+yzMbLiTIG8uA1smjR+p8PRaEh971hdPRKpuzDDEF09ibH+THboN4ZS4V 86+1YYI5jxvQGmni40NFFuWCkNY0w6TFVvuHLlZoVtl5OJTVKmlAeAlrTfmRpkaVRJTT jMOm5ib2OcfIkJj6RiYEIUACZNIr+fXlwvo3J7EhnnVyHMpf7yy/1ZNvjQ8TguFqJfCF AtreUJSCepkcUw/khbRq8coqEu3kp4CREIoxDPFJOHaKUx1ayDNoPeg5VMspuy193+Ja GcEg== X-Gm-Message-State: AElRT7H2UXLyR0J+y++CA4rZGOqQbH0o0zVQHbSduP8a3czHYLFQ6zJt NJMm7BIwkbEgWpi/GB0XI7s= X-Google-Smtp-Source: AG47ELsmooXoLd4K6QUjKuln4EWc6JGXSePRL7b1Uhu42VOyNvyIXQIvfkErougAp9kUk+ki7cEMEQ== X-Received: by 10.98.107.138 with SMTP id g132mr10576609pfc.163.1521919513022; Sat, 24 Mar 2018 12:25:13 -0700 (PDT) From: Michael Davidsaver To: Peter Maydell , Thomas Huth Date: Sat, 24 Mar 2018 12:24:46 -0700 Message-Id: <20180324192455.12254-6-mdavidsaver@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180324192455.12254-1-mdavidsaver@gmail.com> References: <20180324192455.12254-1-mdavidsaver@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::244 Subject: [Qemu-devel] [PATCH 05/14] timer: ds1338 change write handling 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: Antoine Mathys , 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" instead of a read-modify-write, do direct translation of device registers to struct tm members. This new ds1338_update() is the reverse of the existing capture_current_time(). Simplifies later handling of CENTURY bit in similar Dallas RTC chips. Signed-off-by: Michael Davidsaver --- hw/timer/ds1338.c | 86 ++++++++++++++++++++++++++-------------------------= ---- 1 file changed, 40 insertions(+), 46 deletions(-) diff --git a/hw/timer/ds1338.c b/hw/timer/ds1338.c index 9bcda26e51..071c031563 100644 --- a/hw/timer/ds1338.c +++ b/hw/timer/ds1338.c @@ -159,6 +159,42 @@ static int ds1338_recv(I2CSlave *i2c) return res; } =20 +/* call after guest writes to current time registers + * to re-compute our offset from host time. + */ +static void ds1338_update(DS1338State *s) +{ + + struct tm now; + memset(&now, 0, sizeof(now)); + + /* TODO: Implement CH (stop) bit? */ + now.tm_sec =3D from_bcd(s->nvram[R_SEC] & 0x7f); + now.tm_min =3D from_bcd(s->nvram[R_MIN] & 0x7f); + if (ARRAY_FIELD_EX32(s->nvram, HOUR, SET12)) { + /* 12 hour (1-12) */ + /* read and wrap 1-12 -> 0-11 */ + now.tm_hour =3D from_bcd(ARRAY_FIELD_EX32(s->nvram, HOUR, HOUR12))= % 12u; + if (ARRAY_FIELD_EX32(s->nvram, HOUR, AMPM)) { + now.tm_hour +=3D 12; + } + + } else { + now.tm_hour =3D from_bcd(ARRAY_FIELD_EX32(s->nvram, HOUR, HOUR24)); + } + { + /* The day field is supposed to contain a value in + the range 1-7. Otherwise behavior is undefined. + */ + int user_wday =3D (s->nvram[R_WDAY] & 7) - 1; + s->wday_offset =3D (user_wday - now.tm_wday + 7) % 7; + } + now.tm_mday =3D from_bcd(s->nvram[R_DATE] & 0x3f); + now.tm_mon =3D from_bcd(s->nvram[R_MONTH] & 0x1f) - 1; + now.tm_year =3D from_bcd(s->nvram[R_YEAR]) + 100; + s->offset =3D qemu_timedate_diff(&now); +} + static int ds1338_send(I2CSlave *i2c, uint8_t data) { DS1338State *s =3D DS1338(i2c); @@ -168,52 +204,7 @@ static int ds1338_send(I2CSlave *i2c, uint8_t data) 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 R_SEC: - /* TODO: Implement CH (stop) bit. */ - now.tm_sec =3D from_bcd(data & 0x7f); - break; - case R_MIN: - now.tm_min =3D from_bcd(data & 0x7f); - break; - case R_HOUR: - if (FIELD_EX32(data, HOUR, SET12)) { - /* 12 hour (1-12) */ - /* read and wrap 1-12 -> 0-11 */ - now.tm_hour =3D from_bcd(FIELD_EX32(data, HOUR, HOUR12)) %= 12u; - if (FIELD_EX32(data, HOUR, AMPM)) { - now.tm_hour +=3D 12; - } - - } else { - now.tm_hour =3D from_bcd(FIELD_EX32(data, HOUR, HOUR24)); - } - break; - case R_WDAY: - { - /* 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 R_DATE: - now.tm_mday =3D from_bcd(data & 0x3f); - break; - case R_MONTH: - now.tm_mon =3D from_bcd(data & 0x1f) - 1; - break; - case R_YEAR: - now.tm_year =3D from_bcd(data) + 100; - break; - } - s->offset =3D qemu_timedate_diff(&now); - } else if (s->ptr =3D=3D R_CTRL) { + if (s->ptr =3D=3D R_CTRL) { /* Control register. */ =20 /* Ensure bits 2, 3 and 6 will read back as zero. */ @@ -225,6 +216,9 @@ static int ds1338_send(I2CSlave *i2c, uint8_t data) =20 } s->nvram[s->ptr] =3D data; + if (s->ptr <=3D R_YEAR) { + ds1338_update(s); + } inc_regptr(s); return 0; } --=20 2.11.0 From nobody Thu May 2 00:59:42 2024 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 1521920105685790.4220001349161; Sat, 24 Mar 2018 12:35:05 -0700 (PDT) Received: from localhost ([::1]:47325 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezowS-0005V9-UZ for importer@patchew.org; Sat, 24 Mar 2018 15:35:04 -0400 Received: from eggs.gnu.org ([208.118.235.92]:43769) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezoqZ-000131-IO for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:33:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ezomx-0005m6-Nl for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:28:59 -0400 Received: from mail-pg0-x241.google.com ([2607:f8b0:400e:c05::241]:33983) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ezomx-0005lq-Hn for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:25:15 -0400 Received: by mail-pg0-x241.google.com with SMTP id m15so5806776pgc.1 for ; Sat, 24 Mar 2018 12:25:15 -0700 (PDT) Received: from localhost.localdomain (c-73-158-53-43.hsd1.ca.comcast.net. [73.158.53.43]) by smtp.gmail.com with ESMTPSA id o2sm13353501pgq.87.2018.03.24.12.25.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Mar 2018 12:25:13 -0700 (PDT) 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=kAT+NCV1HL6hK3738WnEC4NPqK0sVa4CQO/vGoFK0KA=; b=BGkAB/sURO3c9vehxoMvA7Hg2TVgpp+i7eo3kBb0NtiYHBT+ZOMqJnanO1FpnMrjNI l+VDLyKYR9rCgK10upWTaGhPVfLZwEuZLe8m7NP0GntHjxGOKR4Ad8zCnmO/iDsDSR/M Vgv2kI6Hdy1+UC9NOB1Pc6z+Wgcb7coZkatSZXH5fMWOfl2MbeUCgMx6UUjGcrmv/rE8 9YU9i987VuKtb0GvQ0/9ivGyTJJpohhOsaFXmExfuOHuqdcPhWPz7b/NxbwAvunwUdXg AQzdsZZljv2yKqii1rCF+mwnspCo6pXwOPHbM5T5dcmGje5O+eA55pJ9pjH3mjVvoPDI l1PQ== 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=kAT+NCV1HL6hK3738WnEC4NPqK0sVa4CQO/vGoFK0KA=; b=YJlTTxRmMcH10wdl/2kxUyjyJtBal2Y7JLPMT2IVInbXKPrms33cuwluwLcVuR+UhD rd/aKE5dIfU7UJ0Qd/4YAw6F3SBJ1iLNGRlshWPYtf3pZki+nh63sleWYWVePG9FS+QP 6qj0ocrYXrPwQzcLcsGhbU8bxJO39prcCzaxHZTZnKXXQwl75lD+V1iYVBPDpYqTPgXo lEErtfnngxO+VJOn16r1xJGHY4xQqDxO5mYgZNiaXqmfruGNc145oHyq4zgD2FoK7d60 0DRPztpsqiR2Rb7+UB2m9csStSl5dtdZc9wbDcygaZwovKGAMDn75d3W6+DSFbK7QX5V jM1A== X-Gm-Message-State: AElRT7E2mxekmcF8C/7UvJSnXJJTiW8L5m42F7JpD3z5Lk0Wgc3+BF2L vncjr9yYywlZ/U7DD6VUjkY= X-Google-Smtp-Source: AG47ELsooTMjPSCcqWjglppuPkqI/p7WNLbo9f9sA7OZbko+aYt93+FvISko7EXFiZc6tJlPiuh+hA== X-Received: by 10.98.253.17 with SMTP id p17mr27981632pfh.105.1521919514583; Sat, 24 Mar 2018 12:25:14 -0700 (PDT) From: Michael Davidsaver To: Peter Maydell , Thomas Huth Date: Sat, 24 Mar 2018 12:24:47 -0700 Message-Id: <20180324192455.12254-7-mdavidsaver@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180324192455.12254-1-mdavidsaver@gmail.com> References: <20180324192455.12254-1-mdavidsaver@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::241 Subject: [Qemu-devel] [PATCH 06/14] tests: ds-rtc test 12 hour mode 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: Antoine Mathys , 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" Signed-off-by: Michael Davidsaver --- tests/ds-rtc-set-test.c | 52 +++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 52 insertions(+) diff --git a/tests/ds-rtc-set-test.c b/tests/ds-rtc-set-test.c index 35e1a36281..c48406ee2c 100644 --- a/tests/ds-rtc-set-test.c +++ b/tests/ds-rtc-set-test.c @@ -29,6 +29,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 */ @@ -41,6 +53,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 */ @@ -53,6 +77,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 */ @@ -65,6 +101,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) @@ -108,6 +156,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); =20 ret =3D g_test_run(); =20 --=20 2.11.0 From nobody Thu May 2 00:59:42 2024 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521924692336928.0705944734042; Sat, 24 Mar 2018 13:51:32 -0700 (PDT) Received: from localhost ([::1]:48282 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezq8K-00020h-3r for importer@patchew.org; Sat, 24 Mar 2018 16:51:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35179) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezq63-0000yq-GN for qemu-devel@nongnu.org; Sat, 24 Mar 2018 16:50:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ezq4z-00086s-Hl for qemu-devel@nongnu.org; Sat, 24 Mar 2018 16:49:03 -0400 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:39686) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ezomz-0005mc-0E for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:25:17 -0400 Received: by mail-pg0-x244.google.com with SMTP id a19so5796002pgw.6 for ; Sat, 24 Mar 2018 12:25:16 -0700 (PDT) Received: from localhost.localdomain (c-73-158-53-43.hsd1.ca.comcast.net. [73.158.53.43]) by smtp.gmail.com with ESMTPSA id o2sm13353501pgq.87.2018.03.24.12.25.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Mar 2018 12:25:15 -0700 (PDT) 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=mRAiroU7aYhihaiGYW930UMW5TtOZbK9BdwBZgg4PtQ=; b=pqxxU0ZsNjxeIGA/YLYVAAWnnXH1dThrXV2CaD4Ox7jrccEAL344Ppyl8J19WqvnKi kQWPn50rWTmWM3wdOkFnI4D3Hq639prxjroddj6U29FlE1VvZ21h17oNJre4cG2KVU1b Q6SbJTE9Wl0nYx/EnfzhKviNpC3qnBIRxZQ8qOasJukOgr1p6C4OeMlXOogtYHuHbGdA 7+Ny76UYwvWHG0eeyz1EUEA2phKLyeaV6YY77sy4G0EmVTm1Xeo6oSLpE6YS/SvsvdPz MVcX2guh9bt8t/PV590vzIql2Pcp58ik2kxun3CykUpcn499j+Ou/3lJL7bKUpkdazlu QU0g== 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=mRAiroU7aYhihaiGYW930UMW5TtOZbK9BdwBZgg4PtQ=; b=n8jEOEEA8BrernZBPkWYX3Kanr5qczTR57hw9L7LbqU473WlLgRzM2JsNGbyqfflG7 WKfl9pUMpGeXiLUESZSPmvivpnIfc0fy+Kah4ZuGWMGQWQXGTGFZsmtI9se0h7zm3evg hk6PKsl7sQwEZta46dH6ScN0NXICsOXSWoQCX9TdRdlBRSJxAU1/ptGO15gjhp1NWhUp fWTJlRZWtSAgeNckfGfr6cj6qwvxQWUuku6tt2bcU+RzdUimUfCEtPM6QiNoXsw61Z2p EOHNe0rvyWHvAaLNNj5BtJTtFdlmKpU5hlZRlR/wJdALnb72riYLVfJYiVMuMhrR63He 6fow== X-Gm-Message-State: AElRT7GGcvhCmo//dB7sS5GU6T+k7B8eVmzp0Xsk2d6uo3OP2BmPEPcS ibBC7DRaNNLegxDjE1WVzfI0AQ== X-Google-Smtp-Source: AG47ELsM1pZ+mwToqCzZDv/w99vs/Vr65hFvP3KKcUaaWe/OXdqvu+XLQBpVvyuxkHTLqcDJkYS1Vg== X-Received: by 10.101.96.200 with SMTP id r8mr24327169pgv.152.1521919516132; Sat, 24 Mar 2018 12:25:16 -0700 (PDT) From: Michael Davidsaver To: Peter Maydell , Thomas Huth Date: Sat, 24 Mar 2018 12:24:48 -0700 Message-Id: <20180324192455.12254-8-mdavidsaver@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180324192455.12254-1-mdavidsaver@gmail.com> References: <20180324192455.12254-1-mdavidsaver@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::244 Subject: [Qemu-devel] [PATCH 07/14] timer: ds1338 fix wday_offset handling 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: Antoine Mathys , 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" Correctly handle different real weekday in guest and host timezones. Allow guest to use any day as start of week (day 1). eg. Monday instead of Sunday. Signed-off-by: Michael Davidsaver --- hw/timer/ds1338.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/hw/timer/ds1338.c b/hw/timer/ds1338.c index 071c031563..a969b5c8ba 100644 --- a/hw/timer/ds1338.c +++ b/hw/timer/ds1338.c @@ -108,7 +108,10 @@ static void capture_current_time(DS1338State *s) } else { ARRAY_FIELD_DP32(s->nvram, HOUR, HOUR24, to_bcd(now.tm_hour)); } - s->nvram[R_WDAY] =3D (now.tm_wday + s->wday_offset) % 7 + 1; + s->nvram[R_WDAY] =3D (now.tm_wday + s->wday_offset) % 7; + if (s->nvram[R_WDAY] =3D=3D 0) { + s->nvram[R_WDAY] =3D 7; + } s->nvram[R_DATE] =3D to_bcd(now.tm_mday); s->nvram[R_MONTH] =3D to_bcd(now.tm_mon + 1); s->nvram[R_YEAR] =3D to_bcd(now.tm_year - 100); @@ -182,17 +185,22 @@ static void ds1338_update(DS1338State *s) } else { now.tm_hour =3D from_bcd(ARRAY_FIELD_EX32(s->nvram, HOUR, HOUR24)); } - { - /* The day field is supposed to contain a value in - the range 1-7. Otherwise behavior is undefined. - */ - int user_wday =3D (s->nvram[R_WDAY] & 7) - 1; - s->wday_offset =3D (user_wday - now.tm_wday + 7) % 7; - } + now.tm_wday =3D from_bcd(s->nvram[R_WDAY]) - 1u; now.tm_mday =3D from_bcd(s->nvram[R_DATE] & 0x3f); now.tm_mon =3D from_bcd(s->nvram[R_MONTH] & 0x1f) - 1; now.tm_year =3D from_bcd(s->nvram[R_YEAR]) + 100; s->offset =3D qemu_timedate_diff(&now); + + { + /* Round trip to get real wday_offset based on time delta and + * ref. timezone. + * Race if midnight (in ref. timezone) happens here. + */ + int user_wday =3D now.tm_wday; + qemu_get_timedate(&now, s->offset); + + s->wday_offset =3D (user_wday - now.tm_wday) % 7 + 1; + } } =20 static int ds1338_send(I2CSlave *i2c, uint8_t data) --=20 2.11.0 From nobody Thu May 2 00:59:42 2024 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521919949191257.10478565867345; Sat, 24 Mar 2018 12:32:29 -0700 (PDT) Received: from localhost ([::1]:47314 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezotr-0003eU-9A for importer@patchew.org; Sat, 24 Mar 2018 15:32:23 -0400 Received: from eggs.gnu.org ([208.118.235.92]:42560) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezoo4-0007o3-QU for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:30:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ezon0-0005o8-Qk for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:26:24 -0400 Received: from mail-pl0-x242.google.com ([2607:f8b0:400e:c01::242]:35527) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ezon0-0005n9-Ky for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:25:18 -0400 Received: by mail-pl0-x242.google.com with SMTP id p9-v6so9440708pls.2 for ; Sat, 24 Mar 2018 12:25:18 -0700 (PDT) Received: from localhost.localdomain (c-73-158-53-43.hsd1.ca.comcast.net. [73.158.53.43]) by smtp.gmail.com with ESMTPSA id o2sm13353501pgq.87.2018.03.24.12.25.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Mar 2018 12:25:16 -0700 (PDT) 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=vDTp3oeug8/fXwEh2tmR+OPN22ajYk+8qT0bohkAij8=; b=O9RPUR0tJzpkCtajJgJL8aznn5mikBvJW6m6LNuzfS/CVKOynACXqE9y2Ql+9H9yeQ uKHAq/dBmVRb83Husgd3tsQEeQGaQY7pIikHB86Cvve5HJTOFq63zUL6AzpjC+XDe5ah /T2/U+wRlMXzKJ5I+88v2MuWPWf/L8hx5rjWea0djsn2blCm3+U/wHlcsbHBE4igHHxg NP+HFFXFM5VTRhuOidQ0anzTJ4b5VRCVAkqruYVG7x42XXrSxBMH3JJYMgFB2lxDVmS5 PGpURUZCgiSL/+Z0ZZ0y8Xp/BnhjRXXTocHv7sdtY9gNhov1EibcIbxywBdPaEsjkEqh ejww== 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=vDTp3oeug8/fXwEh2tmR+OPN22ajYk+8qT0bohkAij8=; b=DPcukbnrzmJq1oZW9YdCy/RKUXwR5g2jp07kgLS866hggd1iISCa2Z4vV2XXpyg7FA 4bEOyaTJmQxO6oiJoKYHJO/0Ob+NhHW2Pt9qJeKvk9jhvD0LF7flag4L3UGD54/b+vau UcYd+2EF/grwCyPXHTDD4l85UKyQZP98EhUZBc4FKFDVswdiwE5+tHMNTk4lHAlU3BD8 b0pwPYqqb+/ZZFXhL92fBM84YspQkCF52uvklF1N9ZIi6yzQ1yGZTGC7DLjcpuF8vRZW RZ44aE2qCg3zXNEaDAO9zneq7k5lJnM+mAOqYPZ1rg2B2oMboATJo8673Rw6ltmc/nzN IG5A== X-Gm-Message-State: AElRT7FGplT/omCDgrlzxGWX4sm7FkCfphxOdO1o8ucnjhgIUIjhNR7A KUdqtCMJC+X40JQoXRJNZTI= X-Google-Smtp-Source: AG47ELt71QSZKlNp1XeMpR6WTM9Wf1SoCZ6Vu+Beo5315zo2vfL6doNjQlXd7NDi78JjMl9n/Dr5dQ== X-Received: by 2002:a17:902:2b84:: with SMTP id l4-v6mr16979759plb.65.1521919517728; Sat, 24 Mar 2018 12:25:17 -0700 (PDT) From: Michael Davidsaver To: Peter Maydell , Thomas Huth Date: Sat, 24 Mar 2018 12:24:49 -0700 Message-Id: <20180324192455.12254-9-mdavidsaver@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180324192455.12254-1-mdavidsaver@gmail.com> References: <20180324192455.12254-1-mdavidsaver@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c01::242 Subject: [Qemu-devel] [PATCH 08/14] tests: ds-rtc test wday offset 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: Antoine Mathys , 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" Signed-off-by: Michael Davidsaver --- tests/ds-rtc-common.h | 10 +++++++--- tests/ds-rtc-current-test.c | 9 ++++++++- tests/ds-rtc-set-test.c | 6 ++++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/tests/ds-rtc-common.h b/tests/ds-rtc-common.h index c8e6c2bc5b..633131c55f 100644 --- a/tests/ds-rtc-common.h +++ b/tests/ds-rtc-common.h @@ -20,7 +20,7 @@ static uint8_t addr; static bool use_century; =20 /* input buffer must have at least 7 elements */ -static inline time_t rtc_parse(const uint8_t *buf) +static inline time_t rtc_parse(const uint8_t *buf, unsigned *wday) { struct tm parts; =20 @@ -48,10 +48,14 @@ static inline time_t rtc_parse(const uint8_t *buf) parts.tm_year +=3D 100u; } =20 + if (wday) { + *wday =3D parts.tm_wday; + } + return mktimegm(&parts); } =20 -static time_t rtc_gettime(void) +static time_t rtc_gettime(unsigned *wday) { uint8_t buf[7]; =20 @@ -61,7 +65,7 @@ static time_t rtc_gettime(void) /* read back current time registers */ i2c_recv(i2c, addr, buf, 7); =20 - return rtc_parse(buf); + return rtc_parse(buf, wday); } =20 #endif /* DSRTCCOMMON_H */ diff --git a/tests/ds-rtc-current-test.c b/tests/ds-rtc-current-test.c index 6acbbed9a6..7dc3202261 100644 --- a/tests/ds-rtc-current-test.c +++ b/tests/ds-rtc-current-test.c @@ -20,17 +20,24 @@ static void test_rtc_current(void) { + struct tm tm_actual; time_t expected, actual; /* relax test to limit false positives when host may be overloaded. * Allow larger delta when running "-m quick" */ time_t max_delta =3D g_test_slow() ? 1 : 30; =20 + unsigned wday_expect; + actual =3D time(NULL); /* new second may start here */ - expected =3D rtc_gettime(); + expected =3D rtc_gettime(&wday_expect); + + gmtime_r(&actual, &tm_actual); + g_assert_cmpuint(expected, <=3D, actual + max_delta); g_assert_cmpuint(expected, >=3D, actual); + g_assert_cmpuint(wday_expect, =3D=3D, tm_actual.tm_wday); } =20 int main(int argc, char *argv[]) diff --git a/tests/ds-rtc-set-test.c b/tests/ds-rtc-set-test.c index c48406ee2c..12aeb2580a 100644 --- a/tests/ds-rtc-set-test.c +++ b/tests/ds-rtc-set-test.c @@ -124,16 +124,18 @@ void test_rtc_set(const void *raw) =20 const uint8_t *testtime =3D raw; time_t expected, actual; + unsigned wday_expect, wday_actual; =20 /* skip address pointer and parse remainder */ - expected =3D rtc_parse(&testtime[1]); + expected =3D rtc_parse(&testtime[1], &wday_expect); =20 i2c_send(i2c, addr, testtime, 8); /* host may start new second here */ - actual =3D rtc_gettime(); + actual =3D rtc_gettime(&wday_actual); =20 g_assert_cmpuint(expected, <=3D, actual); g_assert_cmpuint(expected + max_delta, >=3D, actual); + g_assert_cmpuint(wday_expect, =3D=3D, wday_actual); } =20 int main(int argc, char *argv[]) --=20 2.11.0 From nobody Thu May 2 00:59:42 2024 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521920338929390.1122334426519; Sat, 24 Mar 2018 12:38:58 -0700 (PDT) Received: from localhost ([::1]:47357 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezp08-0008Rr-Nm for importer@patchew.org; Sat, 24 Mar 2018 15:38:52 -0400 Received: from eggs.gnu.org ([208.118.235.92]:43738) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezoqV-0000zg-Hd for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:33:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ezon2-0005pE-NX for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:28:55 -0400 Received: from mail-pg0-x241.google.com ([2607:f8b0:400e:c05::241]:41707) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ezon2-0005oo-4x for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:25:20 -0400 Received: by mail-pg0-x241.google.com with SMTP id m24so5789662pgv.8 for ; Sat, 24 Mar 2018 12:25:20 -0700 (PDT) Received: from localhost.localdomain (c-73-158-53-43.hsd1.ca.comcast.net. [73.158.53.43]) by smtp.gmail.com with ESMTPSA id o2sm13353501pgq.87.2018.03.24.12.25.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Mar 2018 12:25:18 -0700 (PDT) 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=o20ibWSieokqwXZ2DD7EDe16UPy9jUiEFoC36t+Qa4o=; b=VSoGX6QYTq52nlrUeL/E46X1F7WxzaZpVGzfeeQHjev0o868YOJxOdbtNFEwC6jnJ9 0y2yjzzpM+zjlZiARW0Mf0X9B62AFrwB+ch5tleHTOcH1J7CFs1OXBcM2pM6ACF10FgO kwHIxbkw7Kt67+SJxhmmWTbvafLO0O3b5BQwn90hqRK81zIdaWr4f0eUw/T8xWuy/nG7 UUJL1sm0blsn9YFo7K1VbbC/VjWVel6B9+hYwD56I1YbdnM9oGlK3vzwtGfA6aVogRx+ i6re1ETM8QnRqqPDuZZ2G6axXUpzSo8/x6l2trivuB10vTUU5Lt4HzABoCLh08he0fk6 hvxA== 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=o20ibWSieokqwXZ2DD7EDe16UPy9jUiEFoC36t+Qa4o=; b=VfDi6o7Wyjjhg6ni0IZbK4emzROyOvLLuDZG79gU3TZBWuIMKuLI7kB/bcSeHn2B+3 VXX5OSYP3hlpY7ok1fe36ku1c7F89OQktTgDNwqlGJI232NOZmdIuiwd0R7N1coOol5D rOsbdbrvrlX8sSzJg9bzy8eAWVfhrGasUw1+onFH6lmUel6CVeHRUpOAGwDaSfFA4SmB LewmjbWYNQG8eB1ZAE+LFZ8RWyp9uUGlLBpRUtd8eza94vpkwOixVkAWqLJR2G2rdXqh AiBcqXm/5KekuFogRsyZJYC7fP6FDrPnkL4FbPPh9HBvUpcBEMAzW8z8AUTGUDt9QofD BcRg== X-Gm-Message-State: AElRT7FNlPRF0DvavDk5UG92m+boxtvbY+jLdMUJN+BDQ8XhkXfgZ1Mp dAktQEUibxnBLMqIIDHnYf0= X-Google-Smtp-Source: AG47ELsVQyuQa5xUoaUQ+0uwL9Z7a+3PS7rm94kh6N6sHwd0W40I9exuKIyNxr9j4wP2b49pAxK66Q== X-Received: by 10.101.64.139 with SMTP id t11mr12669091pgp.119.1521919519210; Sat, 24 Mar 2018 12:25:19 -0700 (PDT) From: Michael Davidsaver To: Peter Maydell , Thomas Huth Date: Sat, 24 Mar 2018 12:24:50 -0700 Message-Id: <20180324192455.12254-10-mdavidsaver@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180324192455.12254-1-mdavidsaver@gmail.com> References: <20180324192455.12254-1-mdavidsaver@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::241 Subject: [Qemu-devel] [PATCH 09/14] timer: rename ds1338 -> dsrtc 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: Antoine Mathys , 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" Prepare to generalize with a more generic name. Keep device name and vmstate name "ds1338" for compatibility. Signed-off-by: Michael Davidsaver Reviewed-by: Peter Maydell --- hw/timer/ds1338.c | 74 +++++++++++++++++++++++++++------------------------= ---- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/hw/timer/ds1338.c b/hw/timer/ds1338.c index a969b5c8ba..28f788dd8e 100644 --- a/hw/timer/ds1338.c +++ b/hw/timer/ds1338.c @@ -1,5 +1,5 @@ /* - * MAXIM DS1338 I2C RTC+NVRAM + * MAXIM DSRTC I2C RTC+NVRAM * * Copyright (c) 2009 CodeSourcery. * Written by Paul Brook @@ -23,8 +23,8 @@ =20 #define CTRL_OSF 0x20 =20 -#define TYPE_DS1338 "ds1338" -#define DS1338(obj) OBJECT_CHECK(DS1338State, (obj), TYPE_DS1338) +#define TYPE_DSRTC "ds1338" +#define DSRTC(obj) OBJECT_CHECK(DSRTCState, (obj), TYPE_DSRTC) =20 /* values stored in BCD */ /* 00-59 */ @@ -57,7 +57,7 @@ FIELD(MONTH, CENTURY, 7, 1) =20 FIELD(CTRL, OSF, 5, 1) =20 -typedef struct DS1338State { +typedef struct DSRTCState { I2CSlave parent_obj; =20 int64_t offset; @@ -65,24 +65,24 @@ typedef struct DS1338State { uint8_t nvram[NVRAM_SIZE]; int32_t ptr; bool addr_byte; -} DS1338State; +} DSRTCState; =20 -static const VMStateDescription vmstate_ds1338 =3D { +static const VMStateDescription vmstate_dsrtc =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_I2C_SLAVE(parent_obj, DSRTCState), + VMSTATE_INT64(offset, DSRTCState), + VMSTATE_UINT8_V(wday_offset, DSRTCState, 2), + VMSTATE_UINT8_ARRAY(nvram, DSRTCState, NVRAM_SIZE), + VMSTATE_INT32(ptr, DSRTCState), + VMSTATE_BOOL(addr_byte, DSRTCState), VMSTATE_END_OF_LIST() } }; =20 -static void capture_current_time(DS1338State *s) +static void capture_current_time(DSRTCState *s) { /* Capture the current time into the secondary registers * which will be actually read by the data transfer operation. @@ -117,7 +117,7 @@ static void capture_current_time(DS1338State *s) s->nvram[R_YEAR] =3D to_bcd(now.tm_year - 100); } =20 -static void inc_regptr(DS1338State *s) +static void inc_regptr(DSRTCState *s) { /* The register pointer wraps around after 0x3F; wraparound * causes the current time/date to be retransferred into @@ -129,9 +129,9 @@ static void inc_regptr(DS1338State *s) } } =20 -static int ds1338_event(I2CSlave *i2c, enum i2c_event event) +static int dsrtc_event(I2CSlave *i2c, enum i2c_event event) { - DS1338State *s =3D DS1338(i2c); + DSRTCState *s =3D DSRTC(i2c); =20 switch (event) { case I2C_START_RECV: @@ -152,9 +152,9 @@ static int ds1338_event(I2CSlave *i2c, enum i2c_event e= vent) return 0; } =20 -static int ds1338_recv(I2CSlave *i2c) +static int dsrtc_recv(I2CSlave *i2c) { - DS1338State *s =3D DS1338(i2c); + DSRTCState *s =3D DSRTC(i2c); uint8_t res; =20 res =3D s->nvram[s->ptr]; @@ -165,7 +165,7 @@ static int ds1338_recv(I2CSlave *i2c) /* call after guest writes to current time registers * to re-compute our offset from host time. */ -static void ds1338_update(DS1338State *s) +static void dsrtc_update(DSRTCState *s) { =20 struct tm now; @@ -203,9 +203,9 @@ static void ds1338_update(DS1338State *s) } } =20 -static int ds1338_send(I2CSlave *i2c, uint8_t data) +static int dsrtc_send(I2CSlave *i2c, uint8_t data) { - DS1338State *s =3D DS1338(i2c); + DSRTCState *s =3D DSRTC(i2c); =20 if (s->addr_byte) { s->ptr =3D data & (NVRAM_SIZE - 1); @@ -225,15 +225,15 @@ static int ds1338_send(I2CSlave *i2c, uint8_t data) } s->nvram[s->ptr] =3D data; if (s->ptr <=3D R_YEAR) { - ds1338_update(s); + dsrtc_update(s); } inc_regptr(s); return 0; } =20 -static void ds1338_reset(DeviceState *dev) +static void dsrtc_reset(DeviceState *dev) { - DS1338State *s =3D DS1338(dev); + DSRTCState *s =3D DSRTC(dev); =20 /* The clock is running and synchronized with the host */ s->offset =3D 0; @@ -243,28 +243,28 @@ static void ds1338_reset(DeviceState *dev) s->addr_byte =3D false; } =20 -static void ds1338_class_init(ObjectClass *klass, void *data) +static void dsrtc_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); I2CSlaveClass *k =3D I2C_SLAVE_CLASS(klass); =20 - 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; + k->event =3D dsrtc_event; + k->recv =3D dsrtc_recv; + k->send =3D dsrtc_send; + dc->reset =3D dsrtc_reset; + dc->vmsd =3D &vmstate_dsrtc; } =20 -static const TypeInfo ds1338_info =3D { - .name =3D TYPE_DS1338, +static const TypeInfo dsrtc_info =3D { + .name =3D TYPE_DSRTC, .parent =3D TYPE_I2C_SLAVE, - .instance_size =3D sizeof(DS1338State), - .class_init =3D ds1338_class_init, + .instance_size =3D sizeof(DSRTCState), + .class_init =3D dsrtc_class_init, }; =20 -static void ds1338_register_types(void) +static void dsrtc_register_types(void) { - type_register_static(&ds1338_info); + type_register_static(&dsrtc_info); } =20 -type_init(ds1338_register_types) +type_init(dsrtc_register_types) --=20 2.11.0 From nobody Thu May 2 00:59:42 2024 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 1521920472195364.96002324287474; Sat, 24 Mar 2018 12:41:12 -0700 (PDT) Received: from localhost ([::1]:47393 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezp2N-0002OR-Cr for importer@patchew.org; Sat, 24 Mar 2018 15:41:11 -0400 Received: from eggs.gnu.org ([208.118.235.92]:44854) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezoyB-0003Jo-IP for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:37:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ezon4-0005qC-3d for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:26:28 -0400 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:37364) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ezon3-0005pT-OM for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:25:22 -0400 Received: by mail-pf0-x242.google.com with SMTP id t16so1760666pfh.4 for ; Sat, 24 Mar 2018 12:25:21 -0700 (PDT) Received: from localhost.localdomain (c-73-158-53-43.hsd1.ca.comcast.net. [73.158.53.43]) by smtp.gmail.com with ESMTPSA id o2sm13353501pgq.87.2018.03.24.12.25.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Mar 2018 12:25:20 -0700 (PDT) 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=XPQOq00IOS0SXLEtVI8oe7DXCP0BxYlcw5Kzc+IxGcQ=; b=QWTmAR0aABGGPamF62j7Cam5tcYf/VHtmG8J90WLgn53vYIUIyIwWlC5jVCwumxiSW Dkc1JSu1k3sYUXg915ZlMnYQzLe0csvnWAHYyNpYHHwuGM0XqI3ziWaf/zxHK14XPggh wQD6sWrpA5SOWNrDU73mIAJC87KozwgN0/bIXurIZ2uIIFy6brcQdwzSAr0gdQ/H9g24 wwv/Fsnls/bd+yQ1ChKe3CMnHvYOqI3hx3OWVvivWpsNpCUOtDsG0iCFLdCVIB0a4xWB P76rHMY2IGq+cHsDBBZpOagYnPN1jsY8HfvlnISy+IpSsMAfatdXG3/qz+jrC9QOnx+k opIw== 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=XPQOq00IOS0SXLEtVI8oe7DXCP0BxYlcw5Kzc+IxGcQ=; b=Luwtri3XNVYQkCvUk+3ThfI5btCw1xe4Rpk1c7J1cFil9n8vZ9Uz7Yj1CXbHgmaBBb 263+IQZzpdWMl/4w2UxbRMei+WufSkVQwl1M3+2iQQm9zr0bYxJqAkYYHH1HDx6NlsJq F0LE6Yy8/42juXpyGj3Cd5IFM1l5cob7+TJIvuKb/uSnzcZnmwvynQiOIfOQ7Ie2CB9K SlhYH4TEuvYpEuyONlwo3LbeGi/5ebV3Fq41n4J0o9Pe8mGFmVnJpUIxRBhatFIcCWcV /LC4btlh/Xtar0UiXg9HyfoVkMqbtYgEBiK/NC+Xibe9CBkTCb41/lU3EN2mIuNlmt9B pCjA== X-Gm-Message-State: AElRT7HLj1nSsiUYllLX9BLM143X95WHigIFGaS4ZZmTSI8RBaMMq7nE 6roxCR9wCgMUFUy+IQwHeO0= X-Google-Smtp-Source: AG47ELsp/PrtmUNxV5Z6UTukyDKpG+3mZAtvpAxdPCkMupxqwF/XBq7uzYVOGqi8+uFuMGVbya3pVw== X-Received: by 10.99.123.23 with SMTP id w23mr24201356pgc.10.1521919520902; Sat, 24 Mar 2018 12:25:20 -0700 (PDT) From: Michael Davidsaver To: Peter Maydell , Thomas Huth Date: Sat, 24 Mar 2018 12:24:51 -0700 Message-Id: <20180324192455.12254-11-mdavidsaver@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180324192455.12254-1-mdavidsaver@gmail.com> References: <20180324192455.12254-1-mdavidsaver@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::242 Subject: [Qemu-devel] [PATCH 10/14] timer: rename file ds1338.c -> ds-rtc.c 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: Antoine Mathys , 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" Signed-off-by: Michael Davidsaver Reviewed-by: Peter Maydell --- default-configs/arm-softmmu.mak | 2 +- hw/timer/Makefile.objs | 2 +- hw/timer/{ds1338.c =3D> ds-rtc.c} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename hw/timer/{ds1338.c =3D> ds-rtc.c} (100%) diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.= mak index dd29e741c2..0afffa2a8a 100644 --- a/default-configs/arm-softmmu.mak +++ b/default-configs/arm-softmmu.mak @@ -33,7 +33,7 @@ CONFIG_SMC91C111=3Dy CONFIG_ALLWINNER_EMAC=3Dy CONFIG_IMX_FEC=3Dy CONFIG_FTGMAC100=3Dy -CONFIG_DS1338=3Dy +CONFIG_DSRTC=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 8b27a4b7ef..d4c59df1d1 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_DSRTC) +=3D ds-rtc.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/ds1338.c b/hw/timer/ds-rtc.c similarity index 100% rename from hw/timer/ds1338.c rename to hw/timer/ds-rtc.c --=20 2.11.0 From nobody Thu May 2 00:59:42 2024 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 1521928671493886.6030666560661; Sat, 24 Mar 2018 14:57:51 -0700 (PDT) Received: from localhost ([::1]:48880 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezrAY-0003o9-Os for importer@patchew.org; Sat, 24 Mar 2018 17:57:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40552) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezr6C-0001b3-Ow for qemu-devel@nongnu.org; Sat, 24 Mar 2018 17:56:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ezr0C-0005Hr-Fe for qemu-devel@nongnu.org; Sat, 24 Mar 2018 17:48:10 -0400 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]:40226) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ezon5-0005qq-FI for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:25:23 -0400 Received: by mail-pf0-x241.google.com with SMTP id v66so3513525pfv.7 for ; Sat, 24 Mar 2018 12:25:23 -0700 (PDT) Received: from localhost.localdomain (c-73-158-53-43.hsd1.ca.comcast.net. [73.158.53.43]) by smtp.gmail.com with ESMTPSA id o2sm13353501pgq.87.2018.03.24.12.25.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Mar 2018 12:25:21 -0700 (PDT) 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=b6PputySXM1oWN3mYQiwzdNIoScKz0/Ufx2ZkRcpnBw=; b=EBqy9AMlk1zvQtFzNrLdcDYSbMaLFJb0ZS+R31Io1E4Wc5cFApXoQwhyhkWSozHaNE 79d2CBF7lzSlrVbRr8QwT52F7fVcPP4cFB0vUoQR4Nh33B7MfyHlRX+6CwKMl5DAoemQ xdr4YJuUPLnnm/01KRCfJ95Ut3IcRxrLpo3F0n794NlRSOdFauVptEt6LV8DriaFJIEb rKnRPfKxGNVham7d87n4JOS8gAyrSFfXA6F/MTCIra9Lq/awhmCKhvezx8IwqcNDoQH2 /WVf0eh2Owtsv7xls67udaJqxisBitcI6ZFZIMH7lwubDYzE9sAd5Tdiu3oo52YipRAo RfNg== 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=b6PputySXM1oWN3mYQiwzdNIoScKz0/Ufx2ZkRcpnBw=; b=ACedn1aXctspKM3KlKQvMFPnHHu+vQrjdXg9I7LXEhCuxsqLsRb8i1cM0q883JF4SS b/hp4WIiG6yfMHpQn9f/NXZSuXyt3yCi3ggpPDVk+a7b4x497AzHnApebLEUvpF+mvNM WQ7SQmll/mKb0E9URRz1vVKeMeLiVl9GX+GmGCQIj1ZmVR8+UuysvXBHn72t3pwerYkz 6is5itjtU+EnLxchCMx/VwmcDOJKkk8y+LLRxHm69JQv3zVq17AtkBRVh/8ctlm2ZCxW n03wHi96juwhrz2G26iJHJjxzQa+4jdJoaBmUnHL4ZxyoO6F77bVQ9I7BS9MEvXdHYqF pJVQ== X-Gm-Message-State: AElRT7ExMynLinrGggNvTkcVrzG1neQwmz+FJv8yiiwXZJGJvfZlRuLW I3e6ENYe06U3AZcvB9mIvxA= X-Google-Smtp-Source: AG47ELsPHymJUoqtDI9h757R/gg3GsGcKMyWqst5fxAKmMt7HPV7HnRriMLgFEQ4PlP6HlyD+EA5IQ== X-Received: by 10.99.145.193 with SMTP id l184mr23876987pge.394.1521919522460; Sat, 24 Mar 2018 12:25:22 -0700 (PDT) From: Michael Davidsaver To: Peter Maydell , Thomas Huth Date: Sat, 24 Mar 2018 12:24:52 -0700 Message-Id: <20180324192455.12254-12-mdavidsaver@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180324192455.12254-1-mdavidsaver@gmail.com> References: <20180324192455.12254-1-mdavidsaver@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::241 Subject: [Qemu-devel] [PATCH 11/14] timer: generalize 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: Antoine Mathys , 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" Add class level handling for address space size and control register. Signed-off-by: Michael Davidsaver --- hw/timer/ds-rtc.c | 63 ++++++++++++++++++++++++++++++++++++++++-----------= ---- 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/hw/timer/ds-rtc.c b/hw/timer/ds-rtc.c index 28f788dd8e..2df1bce3f8 100644 --- a/hw/timer/ds-rtc.c +++ b/hw/timer/ds-rtc.c @@ -21,10 +21,10 @@ */ #define NVRAM_SIZE 64 =20 -#define CTRL_OSF 0x20 - -#define TYPE_DSRTC "ds1338" +#define TYPE_DSRTC "dsrtc" #define DSRTC(obj) OBJECT_CHECK(DSRTCState, (obj), TYPE_DSRTC) +#define DSRTC_CLASS(klass) OBJECT_CLASS_CHECK(DSRTCClass, (klass), TYPE_DS= RTC) +#define DSRTC_GET_CLASS(obj) OBJECT_GET_CLASS(DSRTCClass, (obj), TYPE_DSRT= C) =20 /* values stored in BCD */ /* 00-59 */ @@ -40,7 +40,7 @@ /* 0-99 */ #define R_YEAR (0x6) =20 -#define R_CTRL (0x7) +#define R_DS1338_CTRL (0x7) =20 /* use 12 hour mode when set */ FIELD(HOUR, SET12, 6, 1) @@ -67,6 +67,15 @@ typedef struct DSRTCState { bool addr_byte; } DSRTCState; =20 +typedef struct DSRTCClass { + I2CSlaveClass parent_obj; + + /* actual address space size must be <=3D NVRAM_SIZE */ + unsigned addr_size; + unsigned ctrl_offset; + void (*ctrl_write)(DSRTCState *s, uint8_t); +} DSRTCClass; + static const VMStateDescription vmstate_dsrtc =3D { .name =3D "ds1338", .version_id =3D 2, @@ -119,11 +128,12 @@ static void capture_current_time(DSRTCState *s) =20 static void inc_regptr(DSRTCState *s) { - /* The register pointer wraps around after 0x3F; wraparound + DSRTCClass *k =3D DSRTC_GET_CLASS(s); + /* The register pointer wraps around after k->addr_size-1; wraparound * causes the current time/date to be retransferred into * the secondary registers. */ - s->ptr =3D (s->ptr + 1) & (NVRAM_SIZE - 1); + s->ptr =3D (s->ptr + 1) % k->addr_size; if (!s->ptr) { capture_current_time(s); } @@ -206,22 +216,15 @@ static void dsrtc_update(DSRTCState *s) static int dsrtc_send(I2CSlave *i2c, uint8_t data) { DSRTCState *s =3D DSRTC(i2c); + DSRTCClass *k =3D DSRTC_GET_CLASS(s); =20 if (s->addr_byte) { - s->ptr =3D data & (NVRAM_SIZE - 1); + s->ptr =3D data % k->addr_size; s->addr_byte =3D false; return 0; } - if (s->ptr =3D=3D R_CTRL) { - /* 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); - + if (s->ptr =3D=3D k->ctrl_offset) { + (k->ctrl_write)(s, data); } s->nvram[s->ptr] =3D data; if (s->ptr <=3D R_YEAR) { @@ -256,15 +259,41 @@ static void dsrtc_class_init(ObjectClass *klass, void= *data) } =20 static const TypeInfo dsrtc_info =3D { + .abstract =3D true, .name =3D TYPE_DSRTC, .parent =3D TYPE_I2C_SLAVE, .instance_size =3D sizeof(DSRTCState), .class_init =3D dsrtc_class_init, }; =20 +static void ds1338_control_write(DSRTCState *s, uint8_t data) +{ + /* Control register. */ + + /* allow guest to set no-op controls for clock out pin */ + s->nvram[R_DS1338_CTRL] =3D data & 0x93; +} + +static void ds1338_class_init(ObjectClass *klass, void *data) +{ + DSRTCClass *k =3D DSRTC_CLASS(klass); + + k->addr_size =3D 0x40; + k->ctrl_offset =3D R_DS1338_CTRL; + k->ctrl_write =3D ds1338_control_write; +} + +static const TypeInfo ds1338_info =3D { + .name =3D "ds1338", + .parent =3D TYPE_DSRTC, + .class_size =3D sizeof(DSRTCClass), + .class_init =3D ds1338_class_init, +}; + static void dsrtc_register_types(void) { type_register_static(&dsrtc_info); + type_register_static(&ds1338_info); } =20 type_init(dsrtc_register_types) --=20 2.11.0 From nobody Thu May 2 00:59:42 2024 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 1521919947173405.01130077176606; Sat, 24 Mar 2018 12:32:27 -0700 (PDT) Received: from localhost ([::1]:47315 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezott-0003gI-3j for importer@patchew.org; Sat, 24 Mar 2018 15:32:25 -0400 Received: from eggs.gnu.org ([208.118.235.92]:42626) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezooB-0007s8-A4 for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:30:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ezon7-0005ua-AS for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:26:31 -0400 Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]:39685) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ezon7-0005sr-0d for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:25:25 -0400 Received: by mail-pg0-x242.google.com with SMTP id a19so5796060pgw.6 for ; Sat, 24 Mar 2018 12:25:24 -0700 (PDT) Received: from localhost.localdomain (c-73-158-53-43.hsd1.ca.comcast.net. [73.158.53.43]) by smtp.gmail.com with ESMTPSA id o2sm13353501pgq.87.2018.03.24.12.25.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Mar 2018 12:25:23 -0700 (PDT) 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=N7CDduSNcQh9F1KpJLs9Pfik2T9mwplkd61MV9qnuQE=; b=hen4PY+NGqnLViHR/sRd/JiR6c6zAa9TsKbrvmnzO2nF7wNhcGBsCdBZQ9vfjQdcuI cCBuDpYz7PjEkRzvFLopHVr8LhPGgfl1Y3E/1l22HAVqs63vvs1cMiOllvBTZ4zhyHzD T8yzFyiNvb2ytnUciywe01kXAa7Cy7YODjdAyQo6uZ3nT8AkyaV8IVqgEI7qoUQ4rprh PGNmF9RcerDPK0YLnbGfEpWcbKjf2kkFQGxDKXXBEYXC6kV201WbIQlSaEaiQLcRuiUE ofLZPs+X46mfFoXrMTBtjUz+vy3nsAkulkyuAHxgKdZDV/JrnaOVzKSmUR6Fidlt8YK3 xYLg== 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=N7CDduSNcQh9F1KpJLs9Pfik2T9mwplkd61MV9qnuQE=; b=AgQLVtnL7aggjBgU16Pzn3xbfWl7vAxGfsKRQ2U1sYfGFdHLR9mJDnUsjAnbRy+E6k INQ9NXQrzr/BlEGzGlnDIdO1FxJ+rfB/2xxlPisuJiV0++34nvXaV3Iv1uZvZO3Q0uHG uGvvD93v9DC1jWTe1USgSqgFePJ8uGTDXTUTvjvLYSsVAWcsY8IF+SulELbcWGBjku+/ KAPeHzfxRhdcxwUXp/PlbYimk7Han9wFXHPtNSh8K3UD8fdigtCuYxdBMvZNJpXmLzrJ uyxM4KCdEe3vzxppw+zoUZxR/3lkwhqgqYdQ5xIkzytdxBXWGA8/dq3NQam1S6S488wL fzJg== X-Gm-Message-State: AElRT7Fgw8Rasg9yeo25+Nj3Lga/VebWzd7wgUEnhXPNXqT520qtfUnB 4S8U0aQevU/bIwOTDx2ysOQ5TA== X-Google-Smtp-Source: AG47ELvKdY295yMMT02qn78A94GYIUAVP9D6py+9y+Rew07IsId6UIUOMay+k9qEr5Xp6xsEasbG/g== X-Received: by 10.101.93.5 with SMTP id e5mr6499970pgr.247.1521919524046; Sat, 24 Mar 2018 12:25:24 -0700 (PDT) From: Michael Davidsaver To: Peter Maydell , Thomas Huth Date: Sat, 24 Mar 2018 12:24:53 -0700 Message-Id: <20180324192455.12254-13-mdavidsaver@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180324192455.12254-1-mdavidsaver@gmail.com> References: <20180324192455.12254-1-mdavidsaver@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::242 Subject: [Qemu-devel] [PATCH 12/14] timer: ds-rtc handle CENTURY bit 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: Antoine Mathys , 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" Signed-off-by: Michael Davidsaver Reviewed-by: Peter Maydell --- hw/timer/ds-rtc.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/hw/timer/ds-rtc.c b/hw/timer/ds-rtc.c index 2df1bce3f8..5a4df1b115 100644 --- a/hw/timer/ds-rtc.c +++ b/hw/timer/ds-rtc.c @@ -70,6 +70,7 @@ typedef struct DSRTCState { typedef struct DSRTCClass { I2CSlaveClass parent_obj; =20 + bool has_century; /* actual address space size must be <=3D NVRAM_SIZE */ unsigned addr_size; unsigned ctrl_offset; @@ -91,7 +92,7 @@ static const VMStateDescription vmstate_dsrtc =3D { } }; =20 -static void capture_current_time(DSRTCState *s) +static void capture_current_time(DSRTCState *s, DSRTCClass *k) { /* Capture the current time into the secondary registers * which will be actually read by the data transfer operation. @@ -123,25 +124,28 @@ static void capture_current_time(DSRTCState *s) } s->nvram[R_DATE] =3D to_bcd(now.tm_mday); s->nvram[R_MONTH] =3D to_bcd(now.tm_mon + 1); - s->nvram[R_YEAR] =3D to_bcd(now.tm_year - 100); + s->nvram[R_YEAR] =3D to_bcd(now.tm_year % 100u); + + ARRAY_FIELD_DP32(s->nvram, MONTH, CENTURY, + k->has_century && now.tm_year >=3D 100) } =20 -static void inc_regptr(DSRTCState *s) +static void inc_regptr(DSRTCState *s, DSRTCClass *k) { - DSRTCClass *k =3D DSRTC_GET_CLASS(s); /* The register pointer wraps around after k->addr_size-1; wraparound * causes the current time/date to be retransferred into * the secondary registers. */ s->ptr =3D (s->ptr + 1) % k->addr_size; if (!s->ptr) { - capture_current_time(s); + capture_current_time(s, k); } } =20 static int dsrtc_event(I2CSlave *i2c, enum i2c_event event) { DSRTCState *s =3D DSRTC(i2c); + DSRTCClass *k =3D DSRTC_GET_CLASS(s); =20 switch (event) { case I2C_START_RECV: @@ -150,7 +154,7 @@ static int dsrtc_event(I2CSlave *i2c, enum i2c_event ev= ent) * 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); + capture_current_time(s, k); break; case I2C_START_SEND: s->addr_byte =3D true; @@ -165,10 +169,11 @@ static int dsrtc_event(I2CSlave *i2c, enum i2c_event = event) static int dsrtc_recv(I2CSlave *i2c) { DSRTCState *s =3D DSRTC(i2c); + DSRTCClass *k =3D DSRTC_GET_CLASS(s); uint8_t res; =20 res =3D s->nvram[s->ptr]; - inc_regptr(s); + inc_regptr(s, k); return res; } =20 @@ -230,7 +235,7 @@ static int dsrtc_send(I2CSlave *i2c, uint8_t data) if (s->ptr <=3D R_YEAR) { dsrtc_update(s); } - inc_regptr(s); + inc_regptr(s, k); return 0; } =20 @@ -278,6 +283,7 @@ static void ds1338_class_init(ObjectClass *klass, void = *data) { DSRTCClass *k =3D DSRTC_CLASS(klass); =20 + k->has_century =3D false; k->addr_size =3D 0x40; k->ctrl_offset =3D R_DS1338_CTRL; k->ctrl_write =3D ds1338_control_write; --=20 2.11.0 From nobody Thu May 2 00:59:42 2024 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 1521924696015552.5593756254102; Sat, 24 Mar 2018 13:51:36 -0700 (PDT) Received: from localhost ([::1]:48283 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezq8V-00029A-7L for importer@patchew.org; Sat, 24 Mar 2018 16:51:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35238) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezq6A-0000zO-Fz for qemu-devel@nongnu.org; Sat, 24 Mar 2018 16:50:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ezq56-0008HX-F4 for qemu-devel@nongnu.org; Sat, 24 Mar 2018 16:49:10 -0400 Received: from mail-pl0-x242.google.com ([2607:f8b0:400e:c01::242]:43022) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ezon8-0005uz-GL for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:25:26 -0400 Received: by mail-pl0-x242.google.com with SMTP id f23-v6so9436658plr.10 for ; Sat, 24 Mar 2018 12:25:26 -0700 (PDT) Received: from localhost.localdomain (c-73-158-53-43.hsd1.ca.comcast.net. [73.158.53.43]) by smtp.gmail.com with ESMTPSA id o2sm13353501pgq.87.2018.03.24.12.25.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Mar 2018 12:25:24 -0700 (PDT) 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=RohooTfpFJhobdTIPDaM3odPJshI/3ODVvjSbo/AlIw=; b=rt6Sr0sGLFQr6S7wBY9WXWJWwwbvulW9K9s40JzhZ/oB14Dh8JRG0I9zl1o9D5dOni vIgW8ug6stMJiYyTo8NxXH0Me8MneNcNWUxMn/8zC6grSZSpr/ZQcrpoNuvUfuR7GC2D gMzI/gQxShaA+bRBWysbBFX0l4O6ttefboS3rzdOqX2mp3Bhx3dCsosAV+jQRXrHF0TD 0XdBsyBvHqvKqHrZ3qXzSdueP97DKgnF6BGH2Zd+Ngunpl5V4JFRLVeLZP1+/fCcY4Lv VN0vtrkxWK5/41QLb2JR1t9hAdyOeznSR3HQ6Zy4M7JdWOSOTQHPwr4T9bTrBeFgakBL iEDA== 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=RohooTfpFJhobdTIPDaM3odPJshI/3ODVvjSbo/AlIw=; b=ap3xU/glNxiRNi25UpLIG05jchPxn8sz2C8D7ty8zRshJBuczMQ4ANWZuJpAvsAH9G Pw5P2bbW3bAS8H97GGIw20Vbg7N4U+B9xQHvSf87KbzwjQEMeHToV7Zf9orKQgU6HC4M 4USBGqTAdEMFzfZpQMKGdb5Jua2x5RBs72oeIJF5/YH9U8Mm3P1GHC2lA2YfMBJSWvns tS2u+PbXaYOXJReOrAK7IbrVKPLP75gfUGlZyfKAkPmtMHO1RcZ7K3LQF27dtf0LNOZb geViqJ1hlD1FeWFtkgf0ULrBDPoTqBKR1U+KbuovjuVFBgPpdexR0JJHumuc0LfL+8vq Jm/g== X-Gm-Message-State: AElRT7HrB1M5tLTfNZtHq01W+RtKM3a0Az8z2ocz7oQh6hWLAoKr59pS 2j00ZpygQ09yAWIKsOZBJ6o= X-Google-Smtp-Source: AG47ELsfAx9VTlqMZDg8wfYTfQRv08eSkHgz7UA8Kpq90rZkgokwLrxq0aPpkCHjwK8T7STbVhI9pA== X-Received: by 2002:a17:902:2e43:: with SMTP id q61-v6mr33856080plb.404.1521919525671; Sat, 24 Mar 2018 12:25:25 -0700 (PDT) From: Michael Davidsaver To: Peter Maydell , Thomas Huth Date: Sat, 24 Mar 2018 12:24:54 -0700 Message-Id: <20180324192455.12254-14-mdavidsaver@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180324192455.12254-1-mdavidsaver@gmail.com> References: <20180324192455.12254-1-mdavidsaver@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c01::242 Subject: [Qemu-devel] [PATCH 13/14] timer: ds-rtc model ds1375 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: Antoine Mathys , 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" differences from ds1338 * Has alarms (not modeled) * different control register (not modeled) * smaller address space (0x20 vs. 0x40) Signed-off-by: Michael Davidsaver Reviewed-by: Peter Maydell --- hw/timer/ds-rtc.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/hw/timer/ds-rtc.c b/hw/timer/ds-rtc.c index 5a4df1b115..e5da36cae8 100644 --- a/hw/timer/ds-rtc.c +++ b/hw/timer/ds-rtc.c @@ -1,8 +1,9 @@ /* - * MAXIM DSRTC I2C RTC+NVRAM + * MAXIM/Dallas DS1338 and DS1375 I2C RTC+NVRAM * + * Copyright (c) 2018 Michael Davidsaver * Copyright (c) 2009 CodeSourcery. - * Written by Paul Brook + * Written by Paul Brook, Michael Davidsaver * * This code is licensed under the GNU GPL v2. * @@ -41,6 +42,7 @@ #define R_YEAR (0x6) =20 #define R_DS1338_CTRL (0x7) +#define R_DS1375_CTRL (0xe) =20 /* use 12 hour mode when set */ FIELD(HOUR, SET12, 6, 1) @@ -296,10 +298,34 @@ static const TypeInfo ds1338_info =3D { .class_init =3D ds1338_class_init, }; =20 +static void ds1375_control_write(DSRTCState *s, uint8_t data) +{ + /* just store it, we don't model any features */ + s->nvram[R_DS1375_CTRL] =3D data; +} + +static void ds1375_class_init(ObjectClass *klass, void *data) +{ + DSRTCClass *k =3D DSRTC_CLASS(klass); + + k->has_century =3D true; + k->addr_size =3D 0x20; + k->ctrl_offset =3D R_DS1375_CTRL; + k->ctrl_write =3D ds1375_control_write; +} + +static const TypeInfo ds1375_info =3D { + .name =3D "ds1375", + .parent =3D TYPE_DSRTC, + .class_size =3D sizeof(DSRTCClass), + .class_init =3D ds1375_class_init, +}; + static void dsrtc_register_types(void) { type_register_static(&dsrtc_info); type_register_static(&ds1338_info); + type_register_static(&ds1375_info); } =20 type_init(dsrtc_register_types) --=20 2.11.0 From nobody Thu May 2 00:59:42 2024 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 1521919755045919.8145995743404; Sat, 24 Mar 2018 12:29:15 -0700 (PDT) Received: from localhost ([::1]:47281 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezoqo-0000rW-9F for importer@patchew.org; Sat, 24 Mar 2018 15:29:14 -0400 Received: from eggs.gnu.org ([208.118.235.92]:42648) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezooE-0007th-1Q for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:27:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ezonA-0005wW-2O for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:26:34 -0400 Received: from mail-pl0-x242.google.com ([2607:f8b0:400e:c01::242]:33684) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ezon9-0005w7-Sg for qemu-devel@nongnu.org; Sat, 24 Mar 2018 15:25:27 -0400 Received: by mail-pl0-x242.google.com with SMTP id c11-v6so9442715plo.0 for ; Sat, 24 Mar 2018 12:25:27 -0700 (PDT) Received: from localhost.localdomain (c-73-158-53-43.hsd1.ca.comcast.net. [73.158.53.43]) by smtp.gmail.com with ESMTPSA id o2sm13353501pgq.87.2018.03.24.12.25.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Mar 2018 12:25:26 -0700 (PDT) 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=ZVfQt9iF8sC/vruNGhgMJgYUs2G7ApTnwPg+syldmbE=; b=ZLzBH7Ix+jPrHjRDHcFTCvumS6cb2fGYYXMpoeV5vO3fOoOxSqnxxJ5xj+G/NCeBbK Hc1+j/aAV+Qi1Xw+rNnXqT9VFxpznRBUZz6SwPXFksZi6qZkyTxTD4nA8bYknR71yrvO MPGwlRedR0SlvD88pkLMV+IYVBJ4fZB513p5C3qifDZHCcoNk8u5eLKGIowqBk0lyjBC iwdC6rj9HxGG/j4b58HQSrlxsqJB4xMh6KLyHD5yBfPQzwy4qrqpm1iNUf3Q71vBpYqA rYvd12mvq1mgKc5+1brKXxqtHuh3GS/Bh+TvujL8xO7GBdE2aR8zhfb0uESna/0o8blI 9wLw== 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=ZVfQt9iF8sC/vruNGhgMJgYUs2G7ApTnwPg+syldmbE=; b=bRayKQavvVW4vFlAJWmfNMyG7DvaDJDet58anfUrWeGiklzjOnYGoSIW7TUiUNSYby UoD4uTCzK/iTDofDKXOU2YlfNd9EVvaJUug8iXQr1avkufYM9sflOUJP4K94JSJ5f7jI Gt30PLNNXVbhxyiyBSmEGIQ15mISFSDe1/NkgFjnt3/xCCR4mFJPwr+vJi2Hmsvjs2zl 3+zqlYi4hDt/qX+K04yeDQgTH3kca7xUEXMxBqGti0xisz72r1srkLO0q7QFdsAbOKif 30JKmVRx6/ggH4uMabw+f6uuORfVWEoIffRbo61G++BAgEyb1nlIZMVbGY9Zy1VCUkY3 ABJQ== X-Gm-Message-State: AElRT7Fei05IyqRX0JX5I3yPVJAn0ZHtQtvA/NhZivLTKodlewaSaQ5w 8jF54fhOoOMRQqz3diH8D40= X-Google-Smtp-Source: AG47ELsKoTaH7wt3MRd150iHX0q/IKr1GYpQUf8oWwDyHWwJD5E4Npir3pNiesE+Pvo+VTzrp/7W8g== X-Received: by 2002:a17:902:7008:: with SMTP id y8-v6mr35344166plk.395.1521919527044; Sat, 24 Mar 2018 12:25:27 -0700 (PDT) From: Michael Davidsaver To: Peter Maydell , Thomas Huth Date: Sat, 24 Mar 2018 12:24:55 -0700 Message-Id: <20180324192455.12254-15-mdavidsaver@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180324192455.12254-1-mdavidsaver@gmail.com> References: <20180324192455.12254-1-mdavidsaver@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c01::242 Subject: [Qemu-devel] [PATCH 14/14] 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: Antoine Mathys , 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" redundant to ds-rtc-*-test.c 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 d256095c88..04a99ea6fb 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -371,7 +371,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-current-test$(EXESUF) check-qtest-arm-y +=3D tests/ds-rtc-set-test$(EXESUF) check-qtest-arm-y +=3D tests/m25p80-test$(EXESUF) @@ -772,7 +771,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-current-test$(EXESUF): tests/ds-rtc-current-test.o $(libqos-i= mx-obj-y) tests/ds-rtc-set-test$(EXESUF): tests/ds-rtc-set-test.o $(libqos-imx-obj-y) tests/m25p80-test$(EXESUF): tests/m25p80-test.o 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