Received: by 10.223.176.5 with SMTP id f5csp1603716wra; Wed, 31 Jan 2018 08:48:25 -0800 (PST) X-Google-Smtp-Source: AH8x224GT+8+H3eK7E8D2ML0a1u051mx07ARUHLSPra3mPeRhOKgmz2EnBFfRwQk2Ni51QcJEsHZ X-Received: by 2002:a17:902:8608:: with SMTP id f8-v6mr29710845plo.366.1517417305378; Wed, 31 Jan 2018 08:48:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517417305; cv=none; d=google.com; s=arc-20160816; b=g1IdLVBaJY+NYXkoz6E6YlnqtXTJty9B5F5SkKuyUTl5OeDzuxbubWsxJ4ddkso00Y jt4UZrjK2jsiv/0p5VLEARRfSnByaLHP6fUkLmQ/XQcvZoxUaY1ToLMty75II76nH/p7 70XLWoN5Bn09CKOMJo0F4wt6ET43N3f+VS2fLE2CwdwrgXNcT1EKUodnvC5ymruSoWyP Qx2hIgJAYsALPhMMzt7YPJhMeYautPLQAMEW9C66fDaJinO8PbWwWGp63xsKjEawgxuO MbiY8DvZPzZ4YhCRE4R/gaewlvlWzhuXlBrd+dQwSNE3uHTMVxa5G1/WlIilrgOnrqsg a49w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=MiaV8JYtmkEhvtwB87dDNCi6KRnNoJLQ56J2XH0j2v4=; b=HrqhO2Hs/XxeoZv4FyZ9a4PULl+N41sD2Kp+tvSft8+PDPaeU7NGdBNor6TPyRi4Bk 8bU8g7JscpFJMkulEJuraZSb8EHxj+/4MgBTf29oIh08aNV+bDVaDEr1I75yBKGwmfWN O9vmmscEo5xNFNMpuhrKaI+SZY9v/gdrwoV/uOaCXxfawuDAlPVzil+Z36sXVEQk0PNm SsdBDG+pqSCEFbO1KkrqdHAzib6HDmlrRkE85hIW5yKy90cgVDqnFjndiwWf7jO5UeYV nKGH5Saeb6xoHHb+CZHbKqrUHUOip/DkkmSV+QaEaghqJe/GQOG3s3DGRvdD7muTjP3W Qeyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Kme4pHPg; 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=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j24-v6si256435pll.63.2018.01.31.08.48.09; Wed, 31 Jan 2018 08:48:25 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=Kme4pHPg; 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=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753834AbeAaQMT (ORCPT + 99 others); Wed, 31 Jan 2018 11:12:19 -0500 Received: from mail-qk0-f193.google.com ([209.85.220.193]:38455 "EHLO mail-qk0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753372AbeAaQMR (ORCPT ); Wed, 31 Jan 2018 11:12:17 -0500 Received: by mail-qk0-f193.google.com with SMTP id t134so15397691qke.5; Wed, 31 Jan 2018 08:12:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=MiaV8JYtmkEhvtwB87dDNCi6KRnNoJLQ56J2XH0j2v4=; b=Kme4pHPgO22XGJQA9koD//2UkqmB52T9ptQIUFAohTlaxZuAQcB8qAP3zw9Q13F5OH 4GmWreYbMwSmUwrZZBeETQsdoUkJdSw5j0oWVacrsg/CIHmfXdF2V9CKGP9ioMVdvjmE q3vVHfW75B8wfzhJ4SFOQJZqj5jxvkNGVnhqcj1EwcdPfw++C/o19Yx5dcmH5Y54X2YT snaeUVL0wJZo/JTkB10BFCmma8sd+olOQfPpNXFbHTAe8+y2aBplfkdMOC7jAI77aXhe HYi/1Cs1/LW3vdiIEZlS0wbp+n+w3oyqScx0Hx7ysqEGR5s3QlVJynwe6DaYTsC42QVk sc1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=MiaV8JYtmkEhvtwB87dDNCi6KRnNoJLQ56J2XH0j2v4=; b=okkLAdq6CfQu7cR/zZDUqWmRUZIijsn7YWbmPK05dU8n1xF0iF4Hg5/cLSotkiKEsP +AyRzINFrZ2AACCyZBaLYE82US7Kl0zvTskddbRrePm5vAa/3YWzH/QJu5OlyPBIeQHK fLdcMbzYyNTOiO3GuhYUJHVD+XVDusy/FLWBWm6Rkq0p2bDw8QXwrtEyxILWvT1VnUws Sa2mTG9PiQFf/8YpUFgO04oyjGz6kToOyrA7IUbUmTW7bV20wi60ybVQEXFwFJzuLi5N egbaELWASUaiYjopTEr8+owtafcqGEhdTj+LvqPV9y/BTA2kp++30rpBdfKcPsDwxQEE P7Hw== X-Gm-Message-State: AKwxytesqvNi70JTHxtBpSbWAzJSIagiVAijDMhDc+NTIfson4KrTVNj gW+7FCQeyEdPg1spdnDXHNHM53ptuwPnJlS5FeE= X-Received: by 10.55.120.66 with SMTP id t63mr47716836qkc.345.1517415136507; Wed, 31 Jan 2018 08:12:16 -0800 (PST) MIME-Version: 1.0 Received: by 10.12.175.35 with HTTP; Wed, 31 Jan 2018 08:12:15 -0800 (PST) In-Reply-To: <1517403459-6668-1-git-send-email-daniel.baluta@nxp.com> References: <1517403459-6668-1-git-send-email-daniel.baluta@nxp.com> From: Andy Shevchenko Date: Wed, 31 Jan 2018 18:12:15 +0200 Message-ID: Subject: Re: [PATCH] ASoC: codecs: Add support for AK5558 ADC driver To: Daniel Baluta Cc: Mark Brown , ALSA Development Mailing List , devicetree , Linux Kernel Mailing List , wakasugi.jb@om.asahi-kasei.co.jp, shengjiu.wang@nxp.com, mihai.serban@gmail.com, cosmin.samoila@nxp.com, linux-imx@nxp.com, Mihai Serban Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 31, 2018 at 2:57 PM, Daniel Baluta wrote: > AK5558 is a 32-bit, 768 kHZ sampling, differential input ADC > for digital audio systems. > > Datasheet is available at: > > https://www.akm.com/akm/en/file/datasheet/AK5558VN.pdf > > Initial patch includes support for normal and TDM modes. > > Signed-off-by: Junichi Wakasugi > Signed-off-by: Mihai Serban > Signed-off-by: Shengjiu Wang > Signed-off-by: Daniel Baluta 4 authors of the code?! > +/* > + * ak5558.c -- audio driver for AK5558 ADC > + * > + * Copyright (C) 2015 Asahi Kasei Microdevices Corporation > + * Copyright 2018 NXP > + * > + * This software is licensed under the terms of the GNU General Public > + * License version 2, as published by the Free Software Foundation, and > + * may be copied, distributed, and modified under those terms. > + * > + * This program is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU General Public License for more details. SPDX instead? > + */ > +#include > +#include It would be one of them, not both. > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include It seems redundant. See below. > +#include > +#include Better to keep list ordered. > +/* AK5558 Codec Private Data */ > +struct ak5558_priv { > + struct snd_soc_codec codec; > + struct regmap *regmap; > + struct i2c_client *i2c; > + int fs; /* Sampling Frequency */ > + int rclk; /* Master Clock */ > + int pdn_gpio; /* Power on / Reset GPIO */ struct gpio_desc *power_gpio; > + int slots; > + int slot_width; > +}; > +static int ak5558_set_mcki(struct snd_soc_codec *codec, int fs, int rclk) > +{ > + u8 mode; > +#ifndef AK5558_SLAVE_CKS_AUTO > + int mcki_rate; > +#endif > + > + dev_dbg(codec->dev, "%s fs=%d rclk=%d\n", __func__, fs, rclk); __func__ is useless with dev_dbg(). See the run time options of Dynamic Debug. > + > + mode = snd_soc_read(codec, AK5558_02_CONTROL1); > + mode &= ~AK5558_CKS; > + > +#ifdef AK5558_SLAVE_CKS_AUTO > + mode |= AK5558_CKS_AUTO; > +#else > + if (fs != 0 && rclk != 0) { if (fs && rclk) { ? > + if (rclk % fs) > + return -EINVAL; > + mcki_rate = rclk / fs; > + } > +#endif > + snd_soc_update_bits(codec, AK5558_02_CONTROL1, AK5558_CKS, mode); > + > + return 0; > +} > + > +static int ak5558_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id, > + unsigned int freq, int dir) > +{ > + struct snd_soc_codec *codec = dai->codec; > + struct ak5558_priv *ak5558 = snd_soc_codec_get_drvdata(codec); > + > + dev_dbg(dai->dev, "%s(%d)\n", __func__, __LINE__); Useless. Function tracer can do this for you. > + > + ak5558->rclk = freq; > + ak5558_set_mcki(codec, ak5558->fs, ak5558->rclk); > + > + return 0; > +} > + > +static int ak5558_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) > +{ > + struct snd_soc_codec *codec = dai->codec; > + u8 format; > + > + dev_dbg(dai->dev, "%s(%d)\n", __func__, __LINE__); > + default: > + dev_err(codec->dev, "Clock mode unsupported"); dai->dev vs. codec->dev? > + return -EINVAL; > + } > +} > +static int ak5558_set_dai_mute(struct snd_soc_dai *dai, int mute) > +{ > + struct snd_soc_codec *codec = dai->codec; > + struct ak5558_priv *ak5558 = snd_soc_codec_get_drvdata(codec); > + int ndt; > + > + if (mute) { if (!mute) return 0; ? > + ndt = 0; > + if (ak5558->fs != 0) > + ndt = 583000 / ak5558->fs; > + if (ndt < 5) > + ndt = 5; > + msleep(ndt); msleep(max(ndt, 5)); > +} > +static int ak5558_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, > + unsigned int rx_mask, int slots, > + int slot_width) > +{ > + struct snd_soc_codec *codec = dai->codec; > + struct ak5558_priv *ak5558 = snd_soc_codec_get_drvdata(codec); > + int tdm_mode = 0; Useless assignment. > + int reg; > + > + ak5558->slots = slots; > + ak5558->slot_width = slot_width; > + > + switch (slots * slot_width) { > + case 128: > + tdm_mode = AK5558_MODE_TDM128; > + break; > + case 256: > + tdm_mode = AK5558_MODE_TDM256; > + break; > + case 512: > + tdm_mode = AK5558_MODE_TDM512; > + break; > + default: > + tdm_mode = AK5558_MODE_NORMAL; > + break; > + } > + return 0; > +} > +static int ak5558_startup(struct snd_pcm_substream *substream, > + struct snd_soc_dai *dai) > +{ > + int ret; > + > + ret = snd_pcm_hw_constraint_list(substream->runtime, 0, > + SNDRV_PCM_HW_PARAM_RATE, > + &ak5558_rate_constraints); > + return ret; return snd_pcm_hw_constraint_list(...); ? > +} > +static int ak5558_init_reg(struct snd_soc_codec *codec) > +{ > + int ret; > + struct ak5558_priv *ak5558 = snd_soc_codec_get_drvdata(codec); > + > + dev_dbg(codec->dev, "%s(%d)\n", __func__, __LINE__); Useless. > + usleep_range(10000, 11000); > + if (gpio_is_valid(ak5558->pdn_gpio)) { > + gpio_set_value_cansleep(ak5558->pdn_gpio, 0); > + usleep_range(1000, 2000); > + gpio_set_value_cansleep(ak5558->pdn_gpio, 1); > + usleep_range(1000, 2000); > + } static void ak5558_power_off(...) { if (!ak5558->power_gpiod) return; gpiod_set_value_cansleep(ak5558->power_gpiod, 0); usleep_range(1000, 2000); } static void ak5558_power_on(...) { if (!ak5558->power_gpiod) return; gpiod_set_value_cansleep(ak5558->power_gpiod, 1); usleep_range(1000, 2000); } _power_off(); _power_on(); > + return 0; > +} > +static int ak5558_remove(struct snd_soc_codec *codec) > +{ > + struct ak5558_priv *ak5558 = snd_soc_codec_get_drvdata(codec); > + > + ak5558_set_bias_level(codec, SND_SOC_BIAS_OFF); > + > + if (gpio_is_valid(ak5558->pdn_gpio)) { > + gpio_set_value_cansleep(ak5558->pdn_gpio, 0); > + usleep_range(1000, 2000); > + } _power_off(); > + > + return 0; > +} > + > +#ifdef CONFIG_PM > +static int ak5558_runtime_suspend(struct device *dev) static int __maybe_unused ... > +{ > + struct ak5558_priv *ak5558 = dev_get_drvdata(dev); > + > + regcache_cache_only(ak5558->regmap, true); > + if (gpio_is_valid(ak5558->pdn_gpio)) { > + gpio_set_value_cansleep(ak5558->pdn_gpio, 0); > + usleep_range(1000, 2000); > + } _power_off(); > + > + return 0; > +} > + > +static int ak5558_runtime_resume(struct device *dev) __maybe_unused > +{ > + struct ak5558_priv *ak5558 = dev_get_drvdata(dev); > + > + if (gpio_is_valid(ak5558->pdn_gpio)) { > + gpio_set_value_cansleep(ak5558->pdn_gpio, 0); > + usleep_range(1000, 2000); Why power off again? > + gpio_set_value_cansleep(ak5558->pdn_gpio, 1); > + usleep_range(1000, 2000); > + } _power_off(); // why? _power_on(); > +} > +#endif ugly #ifdef. > +static int ak5558_i2c_probe(struct i2c_client *i2c, > + const struct i2c_device_id *id) > +{ > + struct device_node *np = i2c->dev.of_node; > + struct ak5558_priv *ak5558; > + int ret = 0; > + > + dev_err(&i2c->dev, "%s(%d)\n", __func__, __LINE__); > + > + ak5558 = devm_kzalloc(&i2c->dev, sizeof(struct ak5558_priv), > + GFP_KERNEL); sizeof(*ak5558) ? > + if (!ak5558) > + return -ENOMEM; > + > + ak5558->regmap = devm_regmap_init_i2c(i2c, &ak5558_regmap); > + if (IS_ERR(ak5558->regmap)) > + return PTR_ERR(ak5558->regmap); > + > + i2c_set_clientdata(i2c, ak5558); > + ak5558->i2c = i2c; > + > + ak5558->pdn_gpio = of_get_named_gpio(np, "ak5558,pdn-gpio", 0); > + if (gpio_is_valid(ak5558->pdn_gpio)) { > + ret = devm_gpio_request_one(&i2c->dev, ak5558->pdn_gpio, > + GPIOF_OUT_INIT_LOW, "ak5558,pdn"); > + if (ret) { > + dev_err(&i2c->dev, "unable to get pdn gpio\n"); > + return ret; > + } > + } devm_gpiod_get_optional(); > +} > +static const struct i2c_device_id ak5558_i2c_id[] = { > + { "ak5558", 0 }, > + { } > +}; > +MODULE_DEVICE_TABLE(i2c, ak5558_i2c_id); Do you really need this? (->probe_new() callback doesn't require above to be present) > +MODULE_AUTHOR("Junichi Wakasugi "); > +MODULE_AUTHOR("Mihai Serban "); 4 SoBs, 2 Authors. Please, fix accordingly. > +MODULE_DESCRIPTION("ASoC AK5558 ADC driver"); > +MODULE_LICENSE("GPL"); It is not consistent with the header. > + * ak5558.h -- audio driver for AK5558 SPDX? No name of file in the file is a good practice as well. > + * > + * Copyright (C) 2016 Asahi Kasei Microdevices Corporation > + * Copyright 2018 NXP > +/* AK5558_02_CONTROL1 fields */ > +#define AK5558_DIF 0x02 GENMASK() ? > +#define AK5558_BITS 0x04 Ditto. > +#define AK5558_CKS 0x78 Ditto. > +#define AK5558_MODE_BITS 0x60 Ditto. -- With Best Regards, Andy Shevchenko