From patchwork Tue Dec 11 22:59:32 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Mathys X-Patchwork-Id: 205336 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5F3FC2C007E for ; Wed, 12 Dec 2012 09:59:55 +1100 (EST) Received: from localhost ([::1]:43390 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TiYnp-0004dT-KL for incoming@patchwork.ozlabs.org; Tue, 11 Dec 2012 17:59:53 -0500 Received: from eggs.gnu.org ([208.118.235.92]:47696) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TiYne-0004cX-0w for qemu-devel@nongnu.org; Tue, 11 Dec 2012 17:59:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TiYnY-0001Li-4A for qemu-devel@nongnu.org; Tue, 11 Dec 2012 17:59:41 -0500 Received: from mail-wi0-f177.google.com ([209.85.212.177]:65027) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TiYnX-0001KH-U7 for qemu-devel@nongnu.org; Tue, 11 Dec 2012 17:59:36 -0500 Received: by mail-wi0-f177.google.com with SMTP id hm2so7679wib.10 for ; Tue, 11 Dec 2012 14:59:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=KM+RolNjXN/6y/9GQ48vHSMA7JF8XyCnRgh31CJJaw0=; b=cM3+iujaMbly/j4QIYZ/YW6FrqTT1WkgqzCJRPXsVFAbOPE/qu+dad12JhdL2n85Dv ESlEJFxL+GTOzf43B2rwG9qaghIm+kY7DAKiGH5nI0GgUVPrjq8UBf9lustlPyzgO0MK c2XYLiCcRUuXBuQmCpVnKd2vhTypl3LOMKhMwjjErslP9nDO91PO08hKZPf68UliZZDB mmFbMcpp0WslV0Gzif4+wjg4z5Ew/Pvho3gNCTIrQONnHPhepgs3+jUtaC8pcnzI4Pjg Gor80pERlMzCX8yarAZjDmufLxyNJXzes3y4LHc1V+OLJGmLQ/IYQ5xIqRnOBTen/jtf LttA== Received: by 10.194.158.201 with SMTP id ww9mr3273247wjb.12.1355266774981; Tue, 11 Dec 2012 14:59:34 -0800 (PST) Received: from [192.168.1.33] (adsl-84-227-232-139.adslplus.ch. [84.227.232.139]) by mx.google.com with ESMTPS id p3sm734566wic.8.2012.12.11.14.59.33 (version=SSLv3 cipher=OTHER); Tue, 11 Dec 2012 14:59:34 -0800 (PST) Message-ID: <50C7BAD4.1090404@gmail.com> Date: Tue, 11 Dec 2012 23:59:32 +0100 From: Antoine Mathys User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: qemu-devel@nongnu.org References: <50C7B767.8020406@gmail.com> In-Reply-To: <50C7B767.8020406@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.212.177 Cc: Peter Maydell , paul@codesourcery.com Subject: [Qemu-devel] [PATCH v2 6/6] hw/ds1338.c: Fix handling of DAY (wday) register. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Per the datasheet, the DAY (wday) register is user defined. Implement this. Signed-off-by: Antoine Mathys Reviewed-by: Peter Maydell --- hw/ds1338.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/hw/ds1338.c b/hw/ds1338.c index 319c341..c5cee99 100644 --- a/hw/ds1338.c +++ b/hw/ds1338.c @@ -26,6 +26,7 @@ typedef struct { I2CSlave i2c; int64_t offset; + uint8_t wday_offset; uint8_t nvram[NVRAM_SIZE]; int32_t ptr; bool addr_byte; @@ -33,12 +34,13 @@ typedef struct { static const VMStateDescription vmstate_ds1338 = { .name = "ds1338", - .version_id = 1, + .version_id = 2, .minimum_version_id = 1, .minimum_version_id_old = 1, .fields = (VMStateField[]) { VMSTATE_I2C_SLAVE(i2c, 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), @@ -68,7 +70,7 @@ static void capture_current_time(DS1338State *s) } else { s->nvram[2] = to_bcd(now.tm_hour); } - s->nvram[3] = to_bcd(now.tm_wday + 1); + s->nvram[3] = (now.tm_wday + s->wday_offset) % 7 + 1; s->nvram[4] = to_bcd(now.tm_mday); s->nvram[5] = to_bcd(now.tm_mon + 1); s->nvram[6] = to_bcd(now.tm_year - 100); @@ -152,7 +154,13 @@ static int ds1338_send(I2CSlave *i2c, uint8_t data) } break; case 3: - now.tm_wday = from_bcd(data & 7) - 1; + { + /* The day field is supposed to contain a value in + the range 1-7. Otherwise behavior is undefined. + */ + int user_wday = (data & 7) - 1; + s->wday_offset = (user_wday - now.tm_wday + 7) % 7; + } break; case 4: now.tm_mday = from_bcd(data & 0x3f); @@ -194,6 +202,7 @@ static void ds1338_reset(DeviceState *dev) /* The clock is running and synchronized with the host */ s->offset = 0; + s->wday_offset = 0; memset(s->nvram, 0, NVRAM_SIZE); }