Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4135412ybg; Mon, 21 Oct 2019 04:26:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqwLNDg8HGLpAxKs42HN4jTIwojgyOnh8Yn5gKSfVb7I2cex4CGHglVgIN7vy0W5bXkgXRiA X-Received: by 2002:a17:906:7fd3:: with SMTP id r19mr21768624ejs.46.1571657207795; Mon, 21 Oct 2019 04:26:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571657207; cv=none; d=google.com; s=arc-20160816; b=KZbtQoZTSXdbNaqU05n4f6ky31xrQISzTOQCivag3qrpAGTO7J6OW70GbYZjXoInmO paHNw/Iy6Q2zNCPutbxzDSscw3+8mE0k361y7WULYYbwisvKe5lZHfCgF3blqkzjwop+ gC7o52aPSveKbMiex2aBCiUyaHvAttDsy7Bs1lImqCbM4ZXM7uq+gkbyc/X5CWnLRu3b 1h3ybWYwwCxCIfXT1Tb4nDdXkr71Ps+3hKwK/9jRsMIiJX5dFkoo1dCl3hs2/wUs4jkS gkiAprB2VoxQHF4NSqwSfAlN3CqmnX37fz8z2HzWu9VA6a9T5xkfeqKCJwBl974Mv73Y uRIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=IoIwguD84l9TdKOgIJ6k+NaPdGHth76VlXctQ/52GAY=; b=ojprrZj4IYhZI+Q4uXbdpKrpnliQh/6klLNqsgcxY44MDd8CwiUaFXuB0t0HIhmQvg FCtRRiBUQc17cED4dGPdVu+O/9dol3zRe0xMTwjqaFRGVvW+RnhWNvs6hG83FscdZBQp UQD+YotfQm891pxzdyNxL1ZvzBzez09aAcLKGJjfv1TyqjJNmys59qdJySaS1WJd6mP3 UvrISjGsWBd5wzBXnxx/EedNm0Wlbmz37DI7Zc4ATM7S+dgE1JKLUHscj0P7+ZDK8he3 Qt3ATy7gUG9Z0yU8NrPhAVa7DbcF9gy++l5EEual5GbV982/rWLmrS4R6GYIWJVsoiRT TJMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xqIxF+9M; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n8si8554012ejh.169.2019.10.21.04.26.24; Mon, 21 Oct 2019 04:26:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xqIxF+9M; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728467AbfJULZn (ORCPT + 99 others); Mon, 21 Oct 2019 07:25:43 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:40633 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728455AbfJULZn (ORCPT ); Mon, 21 Oct 2019 07:25:43 -0400 Received: by mail-wr1-f65.google.com with SMTP id o28so13510211wro.7 for ; Mon, 21 Oct 2019 04:25:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=IoIwguD84l9TdKOgIJ6k+NaPdGHth76VlXctQ/52GAY=; b=xqIxF+9MYXYRVZPdLb01gQWr+VIugeUrnEUZArwU1V5796KikHPXG/7BUjbJwd7gF+ w/8nq4zoTzaZVWIu+E1v11ZYoz0IZ7sCin6eM+yqVVQsvaIIyCFuD0akeBQ0uRNdlZeQ bIEnMYTCF2exPyDpTWHWdrHEoEKvXdos65r+twfdvNwQ11ELrVPgFHVd8LTQoZXK9wkD 6pC5KnYwnjtjpFkH4QfsECky8N444Q3u42QT+D/hchoyuIYQo3fgQVdRjUTAp28+D2GF fQydIK48vCnY/6PE+4Hu8t146LAFeUrg60tfRlkdC9phiNuYYbiiNAr+53NgZgb+Z8+D P2Hg== 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-language :content-transfer-encoding; bh=IoIwguD84l9TdKOgIJ6k+NaPdGHth76VlXctQ/52GAY=; b=hApiMivkp+4JlHnlr+QeaOapNQrd92ZeKzwwfXZ5O9wtYVAX/oeTOVRnyOnW+JZy45 VLyhfba3oyUHAuSpm8uivFB3ln1fyK+9Ssj5NU2tHi8Nhs6+vxandoxLMph9FiMHqVIN /u68UChRVvnX6QkbzvbzK9ITafx5+vEqS5goEbhglm8CLxBs0s7wTjlYZoXjXmj91579 A0Jyr6SyCMrMwCgzkxNKHkUQfV9ZczjzJBsx7R9fcl2wQxqmZ3KjPrUS+04PGQnbGqBV QupfjVQQrI4ogBXbH3DeOIxjr61Z/dJl+ij6GCbA9onn6O3thtF7fLm1WbWuvflCAf2Z TMQw== X-Gm-Message-State: APjAAAV37yJF7wVde1GvTPSW9rxV1wcuNJN0eWWcwLN9309MlWnfHuXz nfw4PbFtq1CGvJblKJf45jHWtQ== X-Received: by 2002:adf:a50b:: with SMTP id i11mr20423440wrb.308.1571657140501; Mon, 21 Oct 2019 04:25:40 -0700 (PDT) Received: from [192.168.86.34] (cpc89974-aztw32-2-0-cust43.18-1.cable.virginm.net. [86.30.250.44]) by smtp.googlemail.com with ESMTPSA id a186sm12614204wmd.3.2019.10.21.04.25.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Oct 2019 04:25:39 -0700 (PDT) Subject: Re: [PATCH v2 02/11] mfd: wcd934x: add support to wcd9340/wcd9341 codec To: Lee Jones Cc: robh@kernel.org, broonie@kernel.org, linus.walleij@linaro.org, vinod.koul@linaro.org, alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, spapothi@codeaurora.org, bgoswami@codeaurora.org, linux-gpio@vger.kernel.org References: <20191018001849.27205-1-srinivas.kandagatla@linaro.org> <20191018001849.27205-3-srinivas.kandagatla@linaro.org> <20191021104611.GZ4365@dell> From: Srinivas Kandagatla Message-ID: <1af8a875-8f55-6b7e-4204-ecedc1608889@linaro.org> Date: Mon, 21 Oct 2019 12:25:39 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20191021104611.GZ4365@dell> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thanks Lee for taking time to review. I agree with most of the style related comments, will fix them in next version. For others I have replied it inline. On 21/10/2019 11:46, Lee Jones wrote: > On Fri, 18 Oct 2019, Srinivas Kandagatla wrote: > >> Qualcomm WCD9340/WCD9341 Codec is a standalone Hi-Fi audio codec IC. >> >> This codec has integrated SoundWire controller, pin controller and >> interrupt controller. >> >> Signed-off-by: Srinivas Kandagatla >> --- >> drivers/mfd/Kconfig | 8 + >> drivers/mfd/Makefile | 1 + >> drivers/mfd/wcd934x.c | 330 ++++++++++++++++ >> include/linux/mfd/wcd934x/registers.h | 529 ++++++++++++++++++++++++++ >> include/linux/mfd/wcd934x/wcd934x.h | 24 ++ >> 5 files changed, 892 insertions(+) >> create mode 100644 drivers/mfd/wcd934x.c >> create mode 100644 include/linux/mfd/wcd934x/registers.h >> create mode 100644 include/linux/mfd/wcd934x/wcd934x.h >> >> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig >> index ae24d3ea68ea..ab09862b5996 100644 >> --- a/drivers/mfd/Kconfig >> +++ b/drivers/mfd/Kconfig >> @@ -1967,6 +1967,14 @@ config MFD_STMFX >> additional drivers must be enabled in order to use the functionality >> of the device. >> [...] >> diff --git a/drivers/mfd/wcd934x.c b/drivers/mfd/wcd934x.c >> new file mode 100644 >> index 000000000000..bb4d2a6c89bc >> --- /dev/null >> +++ b/drivers/mfd/wcd934x.c >> @@ -0,0 +1,330 @@ >> +// SPDX-License-Identifier: GPL-2.0 >> +// Copyright (c) 2019, Linaro Limited >> + >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> + [...] >> +static int wcd934x_bring_up(struct wcd934x_data *wcd) >> +{ >> + struct regmap *rm = wcd->regmap; > > It's much more common to use 'regmap' or 'map'. Only reason to make it short here is to save some lines! If you prefer regmap, I will add that in next version! > >> + u16 id_minor, id_major; >> + int ret; >> + >> + ret = regmap_bulk_read(rm, WCD934X_CHIP_TIER_CTRL_CHIP_ID_BYTE0, >> + (u8 *)&id_minor, sizeof(u16)); >> + if (ret) >> + return -EINVAL; >> + >> + ret = regmap_bulk_read(rm, WCD934X_CHIP_TIER_CTRL_CHIP_ID_BYTE2, >> + (u8 *)&id_major, sizeof(u16)); >> + if (ret) >> + return -EINVAL; >> + >> + dev_info(wcd->dev, "wcd934x chip id major 0x%x, minor 0x%x\n", >> + id_major, id_minor); >> + >> + regmap_write(rm, WCD934X_CODEC_RPM_RST_CTL, 0x01); >> + regmap_write(rm, WCD934X_SIDO_NEW_VOUT_A_STARTUP, 0x19); >> + regmap_write(rm, WCD934X_SIDO_NEW_VOUT_D_STARTUP, 0x15); >> + /* Add 1msec delay for VOUT to settle */ >> + usleep_range(1000, 1100); >> + regmap_write(rm, WCD934X_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x5); >> + regmap_write(rm, WCD934X_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x7); >> + regmap_write(rm, WCD934X_CODEC_RPM_RST_CTL, 0x3); >> + regmap_write(rm, WCD934X_CODEC_RPM_RST_CTL, 0x7); >> + regmap_write(rm, WCD934X_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x3); >> + >> + return 0; >> + > > Superfluous '\n'. > >> +} >> + >> +static int wcd934x_slim_status(struct slim_device *sdev, >> + enum slim_device_status status) >> +{ >> + struct device *dev = &sdev->dev; >> + struct wcd934x_data *wcd; >> + int ret; > > This is semantically odd! Why are you doing most of the > initialisation and bring-up in 'status' and not 'probe'. Seems > broken to me. > SLIMBus device will not be in a state to communicate before enumeration (at probe), so all the device initialization is done in status callback where it is ready for communication. This is same with SoundWire Bus as well! >> + wcd = dev_get_drvdata(dev); >> + >> + switch (status) { >> + case SLIM_DEVICE_STATUS_UP: >> + wcd->regmap = regmap_init_slimbus(sdev, &wcd934x_regmap_config); >> + if (IS_ERR(wcd->regmap)) { >> + dev_err(dev, "Error allocating slim regmap\n"); >> + return PTR_ERR(wcd->regmap); >> + } >> + >> + ret = wcd934x_bring_up(wcd); >> + if (ret) { >> + dev_err(dev, "Error WCD934X bringup: err = %d\n", ret); [...] >> + return 0; >> +} >> + >> +static void wcd934x_slim_remove(struct slim_device *sdev) >> +{ >> + struct wcd934x_data *wcd = dev_get_drvdata(&sdev->dev); > > No more clean-up? Aren't the regulators still enabled? > Good point, will add missing regulator disable in next version. >> + mfd_remove_devices(&sdev->dev); >> + kfree(wcd); >> +} >> + [...] >> +#endif >> diff --git a/include/linux/mfd/wcd934x/wcd934x.h b/include/linux/mfd/wcd934x/wcd934x.h >> new file mode 100644 >> index 000000000000..d102e211948c >> --- /dev/null >> +++ b/include/linux/mfd/wcd934x/wcd934x.h >> @@ -0,0 +1,24 @@ >> +/* SPDX-License-Identifier: GPL-2.0 */ >> + >> +#ifndef __WCD934X_H__ >> +#define __WCD934X_H__ >> +#include >> +#include >> +#include >> +#include [...] >> +struct wcd934x_data { >> + int reset_gpio; >> + int irq; > > I'd prefer to see the more complex 'struct's at the top. > >> + struct device *dev; >> + struct clk *extclk; >> + struct regmap *regmap; >> + struct slim_device *sdev; > > You don't need 'sdev' and 'dev'. slim_device instance (sdev) is required by audio codec driver to allocate stream runtime. > >> + struct regmap_irq_chip_data *irq_data; >> + struct regulator_bulk_data supplies[WCD934X_MAX_SUPPLY]; >> +}; >> + >> +#endif /* __WCD934X_H__ */ >> + >