From patchwork Sun Dec 2 17:14:34 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Mathys X-Patchwork-Id: 203231 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 70C972C0089 for ; Mon, 3 Dec 2012 04:15:12 +1100 (EST) Received: from localhost ([::1]:53785 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TfD8G-0000Us-BJ for incoming@patchwork.ozlabs.org; Sun, 02 Dec 2012 12:15:08 -0500 Received: from eggs.gnu.org ([208.118.235.92]:52932) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TfD88-0000Uf-SM for qemu-devel@nongnu.org; Sun, 02 Dec 2012 12:15:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TfD87-0007Tn-Se for qemu-devel@nongnu.org; Sun, 02 Dec 2012 12:15:00 -0500 Received: from mail-bk0-f45.google.com ([209.85.214.45]:64331) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TfD87-0007Ti-LQ for qemu-devel@nongnu.org; Sun, 02 Dec 2012 12:14:59 -0500 Received: by mail-bk0-f45.google.com with SMTP id jk13so679831bkc.4 for ; Sun, 02 Dec 2012 09:14:58 -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 :content-type:content-transfer-encoding; bh=L7o3e+3s6dIZa+U1WJ1NlNpTVV7dqUmIiPfbfGoa3cU=; b=LbVIz1nNbQ1hZKiYRRGGsgNbk2GmGOW+HILHCNuGnJJFQmxKqeesQS68n9HRJfKMjx JoBCFdQ1JB7n9vEWvrrsQI9Mz3Dv91hoQC4WjJtMZNXLXWWHOwoCRADCOmvHSYR59SoS 4/fwGwPlfV/lhQNRDnkIEg6OBdDAJQwtjvLUvH3JaQmqBxdOLb2Ti3pM5RA0NmlOOZZq fh95XR4pUyz3PFwimKHxuqd0K/9UIllsHsdDmVk9eeGLZS5bIv1w7CIxJxnwtJh7jd8J q9DVe5zU4NuKx84wSZKEQqpR1o9FgZkAgYPQvUVNGqb0mxG0/aQ4V03jEeNvN0+5Hbgy q5Rw== Received: by 10.204.130.140 with SMTP id t12mr2178798bks.39.1354468498394; Sun, 02 Dec 2012 09:14:58 -0800 (PST) Received: from [192.168.1.33] (adsl-89-217-2-169.adslplus.ch. [89.217.2.169]) by mx.google.com with ESMTPS id l17sm5735562bkw.12.2012.12.02.09.14.48 (version=SSLv3 cipher=OTHER); Sun, 02 Dec 2012 09:14:57 -0800 (PST) Message-ID: <50BB8C7A.7010304@gmail.com> Date: Sun, 02 Dec 2012 18:14:34 +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 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.214.45 Cc: peter.maydell@linaro.org, paul@codesourcery.com Subject: [Qemu-devel] [PATCH 1/4] hw/ds1338.c: Fix handling of HOURS 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 mapping between 12 and 24 hours modes is: 0 <-> 12 PM 1-12 <-> 1-12 AM 13-23 <-> 1-11 PM Signed-off-by: Antoine Mathys --- hw/ds1338.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/hw/ds1338.c b/hw/ds1338.c index b576d56..1274b22 100644 --- a/hw/ds1338.c +++ b/hw/ds1338.c @@ -50,9 +50,14 @@ static void capture_current_time(DS1338State *s) s->nvram[0] = to_bcd(now.tm_sec); s->nvram[1] = to_bcd(now.tm_min); if (s->nvram[2] & 0x40) { - s->nvram[2] = (to_bcd((now.tm_hour % 12)) + 1) | 0x40; - if (now.tm_hour >= 12) { - s->nvram[2] |= 0x20; + int tmp = now.tm_hour; + if (tmp == 0) { + tmp = 24; + } + if (tmp <= 12) { + s->nvram[2] = 0x40 | to_bcd(tmp); + } else { + s->nvram[2] = 0x60 | to_bcd(tmp - 12); } } else { s->nvram[2] = to_bcd(now.tm_hour); @@ -127,15 +132,17 @@ static int ds1338_send(I2CSlave *i2c, uint8_t data) break; case 2: if (data & 0x40) { + int tmp = from_bcd(data & 0x1f); if (data & 0x20) { - data = from_bcd(data & 0x4f) + 11; - } else { - data = from_bcd(data & 0x1f) - 1; + tmp += 12; + } + if (tmp == 24) { + tmp = 0; } + now.tm_hour = tmp; } else { - data = from_bcd(data); + now.tm_hour = from_bcd(data & 0x3f); } - now.tm_hour = data; break; case 3: now.tm_wday = from_bcd(data & 7) - 1;