From patchwork Fri May 31 14:11:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hironori KIKUCHI X-Patchwork-Id: 13681737 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 06BDDC25B75 for ; Fri, 31 May 2024 14:12:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2GTNpGcfMHLyVSId3K/PUR1EEX3+4MhWDwCZ4JBuv+8=; b=t4fcFlJfhpFY6J lizOYsgwn6paE2ZiNNGRHUH03L4PPsjum04zIZdHJupcl2WZYhtduQNBzT+hwX7UI38LqiSMeAsnz Kn6xs+KJ3soYO7apL6ThFHgii0c1YVpirmx057ST24uSfeIjr6q6HwwsXUoY6i/5dAmu/nPMtx7KU cvgQ8QUqvSasP3vUbsfNg0tPaGMBaxtKdWIQ1dCaoeP6qBqP+t+Cxjb76EH6Dk7kkho7gqEykZjNg UVK1Ucw8MCDt+FEAtHNQl1K+b+tr1J1Pd0Nvsz5WTRRnQJ8dKG0MXTjpwcI01wyDol1pc1rSPgBHD Zom7EbRbwS6imasg5hXw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sD2za-0000000ASof-1tGW; Fri, 31 May 2024 14:12:26 +0000 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sD2zX-0000000ASmU-0XDO for linux-arm-kernel@lists.infradead.org; Fri, 31 May 2024 14:12:24 +0000 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-7024426c75dso799327b3a.1 for ; Fri, 31 May 2024 07:12:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717164741; x=1717769541; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6wTHZBEFwXJhWoEDkPDRuoh0St8wlNAfA/2opNNZCGE=; b=cGSlH0yeqzpUUyjPE5BBN6LQCVHrZy4MYNBUQCMXsXpdQcAsRxhkOs4h+wyAyPTgOY Q1iUS0NwHl2D4B09cDHK0TsfwU1T2+hdBNCHq3hwvAEIhGjT86fRaX2A+tfYP9vDmaYT YiA9xfMV2Qy8vh5783i+gOR1hLopyyZZw2pf1IZszJuNTKseaUqywVvEM8AQ8TJ+5Zn1 cNEcrCmpfjYlHo5fAmotPRX8SsroZTA/92lF02+VYtRn9VeWICd+gwkp0wmlrYbKV9sx 7jCCOWmI8ep0Llsw10kV1FT7nqBZAJQ+XsQLjG9Z5zC57Oll1FMuUGCGeKWchwBSMMfq fKjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717164741; x=1717769541; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6wTHZBEFwXJhWoEDkPDRuoh0St8wlNAfA/2opNNZCGE=; b=p2urzlBYdDU8QV0wq4UmWt0akYP0OVtuHsehN+AQhYHfUKXGgiEAQ76EEOgsdtLnzT 6BEOl5W1liv2/JMjQSYgVocKuMw9Khytkb6RAxUFDFr60xjyrw62BQlMiHL3+EoGmDKI dBfs3XT7zbSliWc7HN8YPUk0WhhN4z5PFj3tO9zvJPNABkO5cS/HxGaZNcCq3q/PyP5y MOQl/SsSxEYA7Uvw5Gr668Fip38inxZTtsGShSYYQmxGcC4xvbp5vD4Q1hdWSe8POjxS n1SWN6zz+4GE1fjN2Cg4o1tE1FTkRJPKTnyi/aK6KG08jMVr5r9PLlECXWd9G4MyyyKv YwVA== X-Forwarded-Encrypted: i=1; AJvYcCXCt6rbAovoadQCvxSlaTG06vqgJYY9vsmoeJ4FdfM7n3OAeOBpHavfzA8ntXNui2fwm8vankwrVvsViGYE9m5l4oCF7JQZQCng+2LKKuUqmsaj9Bs= X-Gm-Message-State: AOJu0Yyji4NKJhYl528qL5awNhaW7JzMsOWdCKckNmiu6YCWa6cWwPQe /Mk25yhDSgtRi/3kpKoKN07QE9oGGhaEj7TmkLpKqfV+wXvAU9/L X-Google-Smtp-Source: AGHT+IGoJr0t15MSyl5iBphGcVZieynY1XhJgQ2y4dhBK/dl/1tYzaCMu+V5iPs17tOhEXXS6/u+gw== X-Received: by 2002:a05:6a20:6a25:b0:1ad:7e4d:2ea2 with SMTP id adf61e73a8af0-1b26f0ec300mr2694125637.4.1717164741148; Fri, 31 May 2024 07:12:21 -0700 (PDT) Received: from noel.flets-west.jp ([2405:6586:4480:a10:167:9818:d778:5c14]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70242b057besm1418103b3a.162.2024.05.31.07.12.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 07:12:20 -0700 (PDT) From: Hironori KIKUCHI To: linux-kernel@vger.kernel.org Cc: Hironori KIKUCHI , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Aleksandr Shubin , Cheo Fusi , linux-pwm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 1/5] pwm: sun20i: Use devm_pwmchip_alloc() helper Date: Fri, 31 May 2024 23:11:33 +0900 Message-ID: <20240531141152.327592-2-kikuchan98@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240531141152.327592-1-kikuchan98@gmail.com> References: <20240531141152.327592-1-kikuchan98@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240531_071223_204310_32CBE4BB X-CRM114-Status: GOOD ( 17.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This patch fixes a compile error by using the devm_pwmchip_alloc() helper function along the way. Signed-off-by: Hironori KIKUCHI --- drivers/pwm/pwm-sun20i.c | 45 ++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/drivers/pwm/pwm-sun20i.c b/drivers/pwm/pwm-sun20i.c index 3e3b5b138b3..93782023af6 100644 --- a/drivers/pwm/pwm-sun20i.c +++ b/drivers/pwm/pwm-sun20i.c @@ -102,7 +102,7 @@ struct sun20i_pwm_chip { static inline struct sun20i_pwm_chip *to_sun20i_pwm_chip(struct pwm_chip *chip) { - return container_of(chip, struct sun20i_pwm_chip, chip); + return pwmchip_get_drvdata(chip); } static inline u32 sun20i_pwm_readl(struct sun20i_pwm_chip *chip, @@ -308,12 +308,31 @@ static void sun20i_pwm_reset_ctrl_release(void *data) static int sun20i_pwm_probe(struct platform_device *pdev) { + struct pwm_chip *chip; struct sun20i_pwm_chip *sun20i_chip; + const struct sun20i_pwm_data *data; + u32 npwm; int ret; - sun20i_chip = devm_kzalloc(&pdev->dev, sizeof(*sun20i_chip), GFP_KERNEL); - if (!sun20i_chip) - return -ENOMEM; + data = of_device_get_match_data(&pdev->dev); + if (!data) + return -ENODEV; + + ret = of_property_read_u32(pdev->dev.of_node, "allwinner,pwm-channels", &npwm); + if (ret) + npwm = 8; + + if (npwm > 16) { + dev_info(&pdev->dev, "Limiting number of PWM lines from %u to 16", npwm); + npwm = 16; + } + + chip = devm_pwmchip_alloc(&pdev->dev, npwm, sizeof(*sun20i_chip)); + if (IS_ERR(chip)) + return PTR_ERR(chip); + sun20i_chip = to_sun20i_pwm_chip(chip); + + sun20i_chip->data = data; sun20i_chip->base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(sun20i_chip->base)) @@ -339,17 +358,6 @@ static int sun20i_pwm_probe(struct platform_device *pdev) return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->rst), "failed to get bus reset\n"); - ret = of_property_read_u32(pdev->dev.of_node, "allwinner,pwm-channels", - &sun20i_chip->chip.npwm); - if (ret) - sun20i_chip->chip.npwm = 8; - - if (sun20i_chip->chip.npwm > 16) { - dev_info(&pdev->dev, "Limiting number of PWM lines from %u to 16", - sun20i_chip->chip.npwm); - sun20i_chip->chip.npwm = 16; - } - /* Deassert reset */ ret = reset_control_deassert(sun20i_chip->rst); if (ret) @@ -359,17 +367,14 @@ static int sun20i_pwm_probe(struct platform_device *pdev) if (ret) return ret; - sun20i_chip->chip.dev = &pdev->dev; - sun20i_chip->chip.ops = &sun20i_pwm_ops; + chip->ops = &sun20i_pwm_ops; mutex_init(&sun20i_chip->mutex); - ret = devm_pwmchip_add(&pdev->dev, &sun20i_chip->chip); + ret = devm_pwmchip_add(&pdev->dev, chip); if (ret < 0) return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n"); - platform_set_drvdata(pdev, sun20i_chip); - return 0; }