From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.2 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3DF96C4707F for ; Tue, 25 May 2021 22:54:53 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id E69F4613CC for ; Tue, 25 May 2021 22:54:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E69F4613CC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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:In-Reply-To:MIME-Version:Date: Message-ID:From:References:Cc:To:Subject:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=vfWMtbaxz7pqtdJaOCthcgRS10xR7JOGCqPB79RmrsA=; b=MEStmtx5Zn8UIIt1EXj7e0aLGD lSt8C3fkApS0ULM1I23bJ3HpQmRU/L/aGYREdPx90MnwbATmJDJSqK3p5mMtAvz4CxhiLlo5Rw1sM PRpWgYa8pR7ulDkp1hEjgJ8kQ+5VswbiJYNgOuYovFWUZg4+SmJvxduV3oDF9nr2W9rA37jDlN5DL WfKoIEHXL1+NELixLcavPgN/5kMvdYHqSUZZVOOuYtC+2bftZGNaKKLFTlBQqajhUKjAQ/UhmMmS3 QaoTA/EgFO46gWjnsP9975aClv7Tm7aHjPlrx+2bjreaYzdrvjzHxkvqA77BJpoPKgvqIwfwT8q1V a0wCij6A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1llfvV-008xJc-Fy; Tue, 25 May 2021 22:53:29 +0000 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1llfvQ-008xHX-Nn for linux-arm-kernel@lists.infradead.org; Tue, 25 May 2021 22:53:26 +0000 Received: by mail-wm1-x32f.google.com with SMTP id u133so17587899wmg.1 for ; Tue, 25 May 2021 15:53:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=reDM3jFc19oKCFJlz500fPCv9/GS7ihZ1/NylsFXAi8=; b=raQd9OTH9uCIvVlLRCoa5+T4rvcKEsectlqRKDUA/KMhSkZEEp2mX5+83qTKq46eUM uIwB+2XdUVPQ0gMseEIUgUpnZE9f1wg9GYGNbYQTSWE6/nv6CQT65096mWPCF65oYVxn 9L8O9Oc5Mb7n/Ia38As1ZkwDaVJqfTThDiHKQzCItVXEdqg7LtmjixaXuMMgCK6Ig3Ff 4QZ32erEQ0H555qyt2xKLH3yjXzXCnWnmnrTvb1Ceseqs9y2pMeuLc5ztkxTB2gQjEYG eyRqx9IbkOwTi8xUeqvLkHfqIyc0oKg2PAGK1gZfwHTUl5uhWFLnwRr5ZMvZujTPDdJl 2k+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=reDM3jFc19oKCFJlz500fPCv9/GS7ihZ1/NylsFXAi8=; b=JB8FjAurZ/EAGkxGxAjhWsHCseQPi+ysEwei7eq6ZrczhuzoKgahqzh92owM42yTNa +Xh+2OlPqkWHEArc3yrKOHYxjAOBFugjXB0784dyslKG0hJ8umDez5aPo6irAAuu7P89 ekLxky4MrcUPs8ylRGtth8H9yH6wWF2OtGbfXBJ4dGrctloM3azPWs2XtiFsQbSay7zy GvXWrTK/GFIV8cA1ylMYHCDjbacpRmJhUEn5PLeK3UGxYhks5N05ZWHIGgxZEGTF7FQ2 ih7EhaCdkLJB7XDPKWpounxD+KauXIHQE5fKV5Alf+0LedChkHzT0JEb8/cGhTH7JrO8 czGg== X-Gm-Message-State: AOAM533yQaQKPtipaAHE/Vi5TGDPappOujIHlAZ0F9iqTWsK/R0OQ4js GOd3JnUaGUscgf8AVApAlAA= X-Google-Smtp-Source: ABdhPJw546gEmZ1nK6tk1g/lyiMMiRk3FHagS3+zvR+uDwiNQ85UPv2DV/NENvTbCsLZ9hgKYh/Pjg== X-Received: by 2002:a1c:6a0f:: with SMTP id f15mr23961465wmc.29.1621983203295; Tue, 25 May 2021 15:53:23 -0700 (PDT) Received: from [192.168.1.211] ([91.110.20.117]) by smtp.gmail.com with ESMTPSA id r7sm11905348wmq.18.2021.05.25.15.53.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 25 May 2021 15:53:22 -0700 (PDT) Subject: Re: [PATCH v4 7/8] platform/x86: Add intel_skl_int3472 driver To: Andy Shevchenko Cc: "Rafael J . Wysocki" , Wolfram Sang , Lee Jones , Hans de Goede , Maximilian Luz , linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org, linux-i2c@vger.kernel.org, platform-driver-x86@vger.kernel.org, devel@acpica.org, Len Brown , Mika Westerberg , Russell King , Linus Walleij , Bartosz Golaszewski , Mark Gross , Robert Moore , Erik Kaneda , laurent.pinchart@ideasonboard.com, kieran.bingham@ideasonboard.com References: <20210520140928.3252671-1-djrscally@gmail.com> <20210520140928.3252671-8-djrscally@gmail.com> From: Daniel Scally Message-ID: <6294177b-d6e1-8bbd-d313-5cce1c498604@gmail.com> Date: Tue, 25 May 2021 23:53:21 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210525_155324_858872_1F0EDF7F X-CRM114-Status: GOOD ( 38.10 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Andy - thanks for comments On 21/05/2021 13:57, Andy Shevchenko wrote: >> +/* >> + * The regulators have to have .ops to be valid, but the only ops we actually >> + * support are .enable and .disable which are handled via .ena_gpiod. Pass an >> + * empty struct to clear the check without lying about capabilities. >> + */ >> +static const struct regulator_ops int3472_gpio_regulator_ops; > Hmm... Can you use 'reg-fixed-voltage' platform device instead? > > One example, although gone from upstream, but available in the tree, I can > point to is this: > > git log -p -- arch/x86/platform/intel-mid/device_libs/platform_bcm43xx.c > > It uses constant structures, but I think you may dynamically generate the > necessary ones. > I can experiment with this, though one thing is we have no actual idea what voltages these are supplying...it doesn't look like that matters from drivers/regulator/fixed.c, but I'd have to try it to be sure. > + > +static int skl_int3472_clk_enable(struct clk_hw *hw) > +{ > + /* > + * We're just turning a GPIO on to enable the clock, which operation > + * has the potential to sleep. Given .enable() cannot sleep, but > + * .prepare() can, we toggle the GPIO in .prepare() instead. Thus, > + * nothing to do here. > + */ > It's a nice comment, but you are using non-sleeping GPIO value setters. Perhaps > you need to replace them with gpiod_set_value_cansleep()? That would make sense! >> +static unsigned int skl_int3472_get_clk_frequency(struct int3472_discrete_device *int3472) >> +{ >> + union acpi_object *obj; >> + unsigned int freq; >> + >> + obj = skl_int3472_get_acpi_buffer(int3472->sensor, "SSDB"); >> + if (IS_ERR(obj)) >> + return 0; /* report rate as 0 on error */ >> + >> + if (obj->buffer.length < CIO2_SENSOR_SSDB_MCLKSPEED_OFFSET + sizeof(u32)) { >> + dev_err(int3472->dev, "The buffer is too small\n"); >> + goto out_free_buff; > First of all, freq will be uninitialized here. > > I'm wondering if you can simple drop the goto and replace it with direct steps, i.e. > kfree(obj); > return 0; Sure, I have no real preference; I'll do that instead. >> +static const struct int3472_sensor_config * >> +skl_int3472_get_sensor_module_config(struct int3472_discrete_device *int3472) >> +{ >> + const struct int3472_sensor_config *ret; >> + union acpi_object *obj; >> + unsigned int i; >> + >> + obj = acpi_evaluate_dsm_typed(int3472->sensor->handle, >> + &cio2_sensor_module_guid, 0x00, >> + 0x01, NULL, ACPI_TYPE_STRING); >> + >> + if (!obj) { >> + dev_err(int3472->dev, >> + "Failed to get sensor module string from _DSM\n"); >> + return ERR_PTR(-ENODEV); >> + } >> + >> + if (obj->string.type != ACPI_TYPE_STRING) { >> + dev_err(int3472->dev, >> + "Sensor _DSM returned a non-string value\n"); >> + ret = ERR_PTR(-EINVAL); >> + goto out_free_obj; >> + } >> + ret = ERR_PTR(-EINVAL); >> + for (i = 0; i < ARRAY_SIZE(int3472_sensor_configs); i++) { >> + if (!strcmp(int3472_sensor_configs[i].sensor_module_name, >> + obj->string.pointer)) { >> + ret = &int3472_sensor_configs[i]; >> + break; >> + } >> + } > Can be refactored like this: > > for (i = 0; i < ARRAY_SIZE(int3472_sensor_configs); i++) { > if (!strcmp(int3472_sensor_configs[i].sensor_module_name, > obj->string.pointer)) > break; > } > > ACPI_FREE(obj); > > if (i >= ARRAY_SIZE(int3472_sensor_configs)) > return ERR_PTR(-EINVAL); > > return &int3472_sensor_configs[i]; Yeah ok, I like this better than the ret = ERR_PTR(-EINVAL) before the loop; thank you. >> + * Return: >> + * * 0 - When all resources found are handled properly. > Positive number ... ? >> + if (!acpi_gpio_get_io_resource(ares, &agpio)) >> + return 1; /* Deliberately positive so parsing continues */ > Move it to description above? oops, yes, I'll add those to the comment. >> + if (int3472->clock.ena_gpio) { >> + ret = skl_int3472_register_clock(int3472); >> + if (ret) >> + goto out_free_res_list; >> + } else { > Hmm... Have I got it correctly that we can't have ena_gpio && led_gpio together? No, just that we can only have led_gpio if we also have ena_gpio (at least that's the intention...) >> + if (ret) >> + ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_NONE, > This I don't like. Since we get a returned variable with different meaning, can > we use a specific variable name for it? On top of that, I would rather see > something like this: > > whatever = skl_...(...); > switch (whatever) { > case WHATEVER_ONE_CASE: > if (cldb.control_logic_type != 2) { > dev_err(&client->dev, "Unsupported control logic type %u\n", > cldb.control_logic_type); > return -EINVAL; > } > cells_data = tps68470_win; > cells_size = ARRAY_SIZE(tps68470_win); > break; > case WHATEVER_ANOTHER_CASE: > ... > break; > default: > ...Oops... > break; // or return -ERRNO > } > > return devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_NONE, > cells_data, cells_size, NULL, 0, NULL); > Yeah I guess that's a bit obscure at first glance; alright, I'll follow this to make it clearer what's happening there. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel