From patchwork Mon Oct 14 16:03:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 176313 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp4754720ill; Mon, 14 Oct 2019 09:50:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqz9KRNjRBcWHTADYY1OPQOouCt5AGo8OrApH6vCqKYjv1F4AvvhSEB9iMn/KJ1Pbg6rz3Ex X-Received: by 2002:a05:620a:4e4:: with SMTP id b4mr30680685qkh.346.1571071826318; Mon, 14 Oct 2019 09:50:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571071826; cv=none; d=google.com; s=arc-20160816; b=HzGoxmYKploHWFQSYJdnBNvcT+aeHnfCIXNxdxQhsB0cuemZlG6+z5jtKWMykw3FhT N/t8hUuS8TIBUdTvGIi7zMfusNf7aJIai0bvKgl6XBn/E1RgGdOUQ+FbTZprvNsMF3uh dfZsVPya51/8phqiZECd8ZF9dRNG7vv2ZGtGAJf5QraysBV+nZ/zM8BDVQzEs7R/3+kK vTmz7cU0n4kCoFyOyn/pcaiZVcS9kt/zcnZVagdC2BDtZ0oLKU0uJXqxXYXVu7z6is/S HCvMZ02hqkve4uJTL5NA7bHzg6vWpSrhC/eB2bk9D/W0ZXRhvOt2JYhpBUWZ6U/bBOqC BeKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=VnKuGKYmXvKiYUaWE62O1+t40crCAoje8TmSropWhmQ=; b=MYerSoWfIW3oXSYa/5sZqotMp6wnvXX+DojMmGohNeX28TqxEj1DxNvsyvl6R0AamV H9F54Lo8AbU6LNgj9NScOlb65mXXAPKOi7Mty0ypMZ1mvHBZef/EUwycUADhUZIx74Bs LoA25/gbRz8LeejWkwRtt4BnUeq3Ru6t+ooT4BLIhNJf32Oga65X8EXN63cbqGKIMk7o H1N+liMEBXd0hKqXSFFQdt504k/O4CwgIwJ0zVInWSP4SMDbFQTfKdTe0hvfP2rbgHux 6CWEaJoylbF7uS6USBPCMASCJZlJrQdY4pkVQXkE2i4rOglfYuD365Biv3r72rArwMDw vMWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=v7QVT5ty; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o47si18092170qvc.11.2019.10.14.09.50.26 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 Oct 2019 09:50:26 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=v7QVT5ty; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:53692 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iK3Y9-0002tG-Fe for patch@linaro.org; Mon, 14 Oct 2019 12:50:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37408) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iK2ql-0005Gy-3U for qemu-devel@nongnu.org; Mon, 14 Oct 2019 12:05:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iK2qj-00089o-MP for qemu-devel@nongnu.org; Mon, 14 Oct 2019 12:05:35 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]:35087) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iK2qj-000896-Ft for qemu-devel@nongnu.org; Mon, 14 Oct 2019 12:05:33 -0400 Received: by mail-wm1-x336.google.com with SMTP id y21so17310951wmi.0 for ; Mon, 14 Oct 2019 09:05:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=VnKuGKYmXvKiYUaWE62O1+t40crCAoje8TmSropWhmQ=; b=v7QVT5ty9nW9jpo/2jCxHBW/C9BfyzNjwHCXG5tQsfv4NS7HQ+VcgN27RQDWdVvfTK mOl3D467/2ac6DFGyC06Zva0eh2rLgB0/RZvnAxOszsbZIg8xJNJQLIYf04JQtt6Bh1/ NRanOTqAMtueQWY3qogVm8nzgcFryM+rFTCLp548Y7p69PD5sTz5SXf0IXY4R370xH0y juOSOW196sXcFKytKDONl4ctgvS+wVMI1brFkpQYsPdH5hReBEA5vYVhTsBB/uoOJqSK 2pFrdlsbPq17yo6Icc2AYtfrCUYUOs3i79ixZozDZpPP6s0GzbJ5actzaLxy1F49/r1T Oglw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VnKuGKYmXvKiYUaWE62O1+t40crCAoje8TmSropWhmQ=; b=iVk57iTHelsPZu+uleNRzorlCYiOmQnLGCEk/Y+ciHq93vX6n5HBAXKN1hwIps4The lPi5ar4dHBkJEWdRvgsqa+pQyoWxpHiqM22Pc/IzKShn1sl9Qe4Kuy22ql4XDJtMxqlg 68ZcArNMo+q6Tcg3zF6T7YchUartWu74C1O8m3mo41OwzILV0K76hjosfAOO4Alp/mKQ enHGSJzYhCp4ioXMyaRBubWTWvchX9nsJNvVogrf3ZiNqcBFMm7zS7fCLkNlbteb1QVo j57cDDw3am0JrMaaYWkN4Mrpoii+apFlfpaJKc9kH9vPg2hQVt+peDcghF685QpUI7df qUvQ== X-Gm-Message-State: APjAAAWjmb6Oi1uwFpTdxDVDUEkCclUi1qB/R3Vwm7n+/2skbbYnNh0b K5d/40MLT1TNxX8kPl2Mk9mmPq1oxpMFIg== X-Received: by 2002:a1c:e10a:: with SMTP id y10mr15664194wmg.29.1571069132058; Mon, 14 Oct 2019 09:05:32 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id 5sm18029779wrk.86.2019.10.14.09.05.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2019 09:05:31 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 55/68] aspeed/i2c: Add AST2600 support Date: Mon, 14 Oct 2019 17:03:51 +0100 Message-Id: <20191014160404.19553-56-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191014160404.19553-1-peter.maydell@linaro.org> References: <20191014160404.19553-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::336 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Cédric Le Goater The I2C controller of the AST2400 and AST2500 SoCs have one IRQ shared by all I2C busses. The AST2600 SoC I2C controller has one IRQ per bus and 16 busses. Signed-off-by: Cédric Le Goater Reviewed-by: Joel Stanley Message-id: 20190925143248.10000-17-clg@kaod.org Signed-off-by: Peter Maydell --- include/hw/i2c/aspeed_i2c.h | 5 +++- hw/i2c/aspeed_i2c.c | 46 +++++++++++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 3 deletions(-) -- 2.20.1 diff --git a/include/hw/i2c/aspeed_i2c.h b/include/hw/i2c/aspeed_i2c.h index 6e2dae7db81..13e01059189 100644 --- a/include/hw/i2c/aspeed_i2c.h +++ b/include/hw/i2c/aspeed_i2c.h @@ -27,10 +27,11 @@ #define TYPE_ASPEED_I2C "aspeed.i2c" #define TYPE_ASPEED_2400_I2C TYPE_ASPEED_I2C "-ast2400" #define TYPE_ASPEED_2500_I2C TYPE_ASPEED_I2C "-ast2500" +#define TYPE_ASPEED_2600_I2C TYPE_ASPEED_I2C "-ast2600" #define ASPEED_I2C(obj) \ OBJECT_CHECK(AspeedI2CState, (obj), TYPE_ASPEED_I2C) -#define ASPEED_I2C_NR_BUSSES 14 +#define ASPEED_I2C_NR_BUSSES 16 struct AspeedI2CState; @@ -41,6 +42,7 @@ typedef struct AspeedI2CBus { I2CBus *bus; uint8_t id; + qemu_irq irq; uint32_t ctrl; uint32_t timing[2]; @@ -72,6 +74,7 @@ typedef struct AspeedI2CClass { uint8_t num_busses; uint8_t reg_size; uint8_t gap; + qemu_irq (*bus_get_irq)(AspeedI2CBus *); } AspeedI2CClass; I2CBus *aspeed_i2c_get_bus(DeviceState *dev, int busnr); diff --git a/hw/i2c/aspeed_i2c.c b/hw/i2c/aspeed_i2c.c index fabdb01e974..06c119f385b 100644 --- a/hw/i2c/aspeed_i2c.c +++ b/hw/i2c/aspeed_i2c.c @@ -145,10 +145,12 @@ static inline bool aspeed_i2c_bus_is_enabled(AspeedI2CBus *bus) static inline void aspeed_i2c_bus_raise_interrupt(AspeedI2CBus *bus) { + AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(bus->controller); + bus->intr_status &= bus->intr_ctrl; if (bus->intr_status) { bus->controller->intr_status |= 1 << bus->id; - qemu_irq_raise(bus->controller->irq); + qemu_irq_raise(aic->bus_get_irq(bus)); } } @@ -273,6 +275,7 @@ static void aspeed_i2c_bus_write(void *opaque, hwaddr offset, uint64_t value, unsigned size) { AspeedI2CBus *bus = opaque; + AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(bus->controller); bool handle_rx; switch (offset) { @@ -299,7 +302,7 @@ static void aspeed_i2c_bus_write(void *opaque, hwaddr offset, bus->intr_status &= ~(value & 0x7FFF); if (!bus->intr_status) { bus->controller->intr_status &= ~(1 << bus->id); - qemu_irq_lower(bus->controller->irq); + qemu_irq_lower(aic->bus_get_irq(bus)); } if (handle_rx && (bus->cmd & (I2CD_M_RX_CMD | I2CD_M_S_RX_CMD_LAST))) { aspeed_i2c_handle_rx_cmd(bus); @@ -457,6 +460,8 @@ static void aspeed_i2c_realize(DeviceState *dev, Error **errp) for (i = 0; i < aic->num_busses; i++) { char name[32]; int offset = i < aic->gap ? 1 : 5; + + sysbus_init_irq(sbd, &s->busses[i].irq); snprintf(name, sizeof(name), "aspeed.i2c.%d", i); s->busses[i].controller = s; s->busses[i].id = i; @@ -488,6 +493,11 @@ static const TypeInfo aspeed_i2c_info = { .abstract = true, }; +static qemu_irq aspeed_2400_i2c_bus_get_irq(AspeedI2CBus *bus) +{ + return bus->controller->irq; +} + static void aspeed_2400_i2c_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); @@ -498,6 +508,7 @@ static void aspeed_2400_i2c_class_init(ObjectClass *klass, void *data) aic->num_busses = 14; aic->reg_size = 0x40; aic->gap = 7; + aic->bus_get_irq = aspeed_2400_i2c_bus_get_irq; } static const TypeInfo aspeed_2400_i2c_info = { @@ -506,6 +517,11 @@ static const TypeInfo aspeed_2400_i2c_info = { .class_init = aspeed_2400_i2c_class_init, }; +static qemu_irq aspeed_2500_i2c_bus_get_irq(AspeedI2CBus *bus) +{ + return bus->controller->irq; +} + static void aspeed_2500_i2c_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); @@ -516,6 +532,7 @@ static void aspeed_2500_i2c_class_init(ObjectClass *klass, void *data) aic->num_busses = 14; aic->reg_size = 0x40; aic->gap = 7; + aic->bus_get_irq = aspeed_2500_i2c_bus_get_irq; } static const TypeInfo aspeed_2500_i2c_info = { @@ -524,11 +541,36 @@ static const TypeInfo aspeed_2500_i2c_info = { .class_init = aspeed_2500_i2c_class_init, }; +static qemu_irq aspeed_2600_i2c_bus_get_irq(AspeedI2CBus *bus) +{ + return bus->irq; +} + +static void aspeed_2600_i2c_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + AspeedI2CClass *aic = ASPEED_I2C_CLASS(klass); + + dc->desc = "ASPEED 2600 I2C Controller"; + + aic->num_busses = 16; + aic->reg_size = 0x80; + aic->gap = -1; /* no gap */ + aic->bus_get_irq = aspeed_2600_i2c_bus_get_irq; +} + +static const TypeInfo aspeed_2600_i2c_info = { + .name = TYPE_ASPEED_2600_I2C, + .parent = TYPE_ASPEED_I2C, + .class_init = aspeed_2600_i2c_class_init, +}; + static void aspeed_i2c_register_types(void) { type_register_static(&aspeed_i2c_info); type_register_static(&aspeed_2400_i2c_info); type_register_static(&aspeed_2500_i2c_info); + type_register_static(&aspeed_2600_i2c_info); } type_init(aspeed_i2c_register_types)