Received: by 10.223.185.116 with SMTP id b49csp1976913wrg; Thu, 15 Feb 2018 04:46:08 -0800 (PST) X-Google-Smtp-Source: AH8x227SmyGPajwVmlxgERHaC08TYWJSYLUgmJ/nIbWScqWd/2kW25Oa4ZIwcbaL0hLfITC/Cotc X-Received: by 2002:a17:902:ab85:: with SMTP id f5-v6mr2486703plr.199.1518698768756; Thu, 15 Feb 2018 04:46:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518698768; cv=none; d=google.com; s=arc-20160816; b=U438rax45GTzvM9X4Vb1X46ok6lDqaS4ZEkxhc4rj3N6ufpybQ2TDOZpI4tVL5t+49 TUMK6D4AbNJsWTnqWVM70MMFaUNY/8tTcR9tBoJFtGG/GECMWdMps7qP8w7TTvZXScZ0 bgA/vW3cyRSqDBbn+IUICjX9JtrsXV0Gt1QUpM1yCMJps1H3C2AEFdtM705LH9CZNIfT 1yiNgkuDQ5d6ibEJO6lx5s+1y9vRAs/Dkz+iD9iHNwXBhzcm/7DnY20u5GnJVRPMj3NE 7F/1JIom6F7DB8cRsF3EyC6HkUjDahLF83IMPx/ro5XgB/yG9POsjxlyNs0dM+nsGWOo 6ZnA== 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=0sycEkaWNLlCWwbDc6GZwy3Wvyx8e2LumnnvMqg0pIA=; b=UaG2sWOiXtAYYfphqK/eiLvC/LG5+fMPtXe0hKaUgqmB+gWQRD07B2N6ArEvpZtkvQ hLk44q1odhpKqPW+nnM+jZxdaWqnVRy1GX22vQt6PL4VgbV+tY1yRiBx/pvg5lEU7I6n ETwQKEOXlwVr81L8dtiF7sLlsnqCeio40lOEV9nQj3+rVMnesBuf//xHpz6dqFu4FpB2 ZlVaQ53e2cYF287GFYCCuDMCeilpOFUNCs9/OvQmkZ8BPn04GqIV/YbUCEel7ymm3QYV WUiiJPWhJQxxmo8fZuFc4MYVcat1Wh3bD6o4ewD5d8g/xRiGgeKQW3CjO9cN94LWxcCw /zGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fF/1beNK; 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=QUARANTINE 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 k78si1151903pfk.95.2018.02.15.04.45.53; Thu, 15 Feb 2018 04:46:08 -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=fF/1beNK; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1031067AbeBOMpP (ORCPT + 99 others); Thu, 15 Feb 2018 07:45:15 -0500 Received: from mail-qt0-f173.google.com ([209.85.216.173]:32862 "EHLO mail-qt0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030245AbeBOMpN (ORCPT ); Thu, 15 Feb 2018 07:45:13 -0500 Received: by mail-qt0-f173.google.com with SMTP id d8so11704568qtm.0; Thu, 15 Feb 2018 04:45:13 -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=0sycEkaWNLlCWwbDc6GZwy3Wvyx8e2LumnnvMqg0pIA=; b=fF/1beNKtUdiMC+dtbdpdlpubS3fXWFbmasN+6UcThZmCcEUcbSIo3vnmeTikK7Mj8 aD8z5EwpqfA3CfHCszf9d0DQXB6MiGNLOahcZikPvXHSLfgN+dNZ6hrE+2/9HnxOqvbH KAA9IGTq5pL2DryixfH3XnHboZzO2Q3dezluQ6GJ/nWxTGmzPsBqrGzTS28CkHOn5Lhg yts5spym+2Y3t8ZFrncgxWND3nTCGU7rzSDZYVSi/LjugctT3UUYrSqFt2YQCWGytkcS Kx9knXf5EB/7fGIB7tLvUix8EgmQvcgden/3wLGQMMv54xfASq1BRSu8kgjJ0aWsMbHl WsSg== 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=0sycEkaWNLlCWwbDc6GZwy3Wvyx8e2LumnnvMqg0pIA=; b=fzF/FLdUKysDnR0J8G9hVKeShPncW2a1Tj6SFCCiCyjWsbXi2xwPtnfqVAQsi46G8b OTZcbV6sjeDMNZfVn7LIlAnEDy4GVL6MYdtAq6rh2E2T1DmMdse+AbxFuCOKKCYhjzb8 ahuAud/1qpB6fC+TpoFW5yhRKdDs9aSg/Eya+MsUCwVt39yA5PQrJvzrwzcPiDHMLcWs TWXpJznvHfNUE8FqpmuRNNvcEbeFe8P+yHLtAcEA2pmycDVVxSGO6pxcvL2u0mWPGbuT NlRK68UpiEFpy8cdQtH2+gGpN7NkvC0lZdnUIT1Snop7EfAKZ2v1JFxxddvj/tavQynN jUeA== X-Gm-Message-State: APf1xPB4K5DieHJFyuVl6Lt63UtPefF65KJackEi8iTbDo60vh1zH7lO VOtm8O4NCMVEm707VCofpibVY4ntgS49P7XWEas= X-Received: by 10.200.9.86 with SMTP id z22mr3979148qth.87.1518698712608; Thu, 15 Feb 2018 04:45:12 -0800 (PST) MIME-Version: 1.0 Received: by 10.12.195.82 with HTTP; Thu, 15 Feb 2018 04:45:11 -0800 (PST) In-Reply-To: <20180214005536.22739-1-david.daney@cavium.com> References: <20180214005536.22739-1-david.daney@cavium.com> From: Andy Shevchenko Date: Thu, 15 Feb 2018 14:45:11 +0200 Message-ID: Subject: Re: [PATCH v2] rtc: isl12026: Add driver. To: David Daney Cc: Alessandro Zummo , Alexandre Belloni , Rob Herring , Mark Rutland , linux-rtc@vger.kernel.org, devicetree , Linux Kernel Mailing List 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, Feb 14, 2018 at 2:55 AM, David Daney wrote: > The ISL12026 is a combination RTC and EEPROM device with I2C > interface. The standard RTC driver interface is provided. The EEPROM > is accessed via the NVMEM interface via the "eeprom0" directory in the > sysfs entry for the device. Thanks for an update, my comments below. > +struct isl12026 { > + struct rtc_device *rtc; > + struct i2c_client *nvm_client; > + struct nvmem_config nvm_cfg; > + /* > + * RTC write operations require that multiple messages be > + * transmitted, we hold the lock for all accesses to the > + * device so that these sequences cannot be disrupted. Also, > + * the write cycle to the nvmem takes many mS during which the What mS means? milliseconds? The standard abbreviation for it 'ms'. > + * device does not respond to commands, so holding the lock > + * also prevents access during these times. > + */ > + struct mutex lock; > +}; > +static int isl12026_read_reg(struct i2c_client *client, int reg) > +{ > + ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); > + if (ret != ARRAY_SIZE(msgs)) { > + dev_err(&client->dev, "read reg error, ret=%d\n", ret); > + ret = ret < 0 ? ret : -EIO; > + } else { > + ret = val; > + } > + return val; Something wrong. ret is not used after all. > +} Check entire code for such. > + /* 2 bytes of address, most significant first */ > + addr[0] = (offset >> 8) & 0xff; > + addr[1] = offset & 0xff; Consider to drop '& 0xff', they are pointless (you have u8 type). > + payload[0] = (offset >> 8) & 0xff; > + payload[1] = offset & 0xff; Ditto. > +static void isl12026_force_power_modes(struct i2c_client *client) > +{ > + int ret; > + int pwr, requested_pwr; > + u32 bsw_val, sbib_val; > + bool set_bsw, set_sbib; > + > + ret = of_property_read_u32(client->dev.of_node, > + "isil,pwr-bsw", &bsw_val); > + set_bsw = (ret == 0); Which is not fully correct. Better to do set_bsw = of_property_present(); ret = of_property_read...(); if (ret) return ret; > + > + ret = of_property_read_u32(client->dev.of_node, > + "isil,pwr-sbib", &sbib_val); > + set_sbib = (ret == 0); Ditto. > + > + /* Check if PWR.BSW and/or PWR.SBIB need specified values */ > + > + if (set_bsw || set_sbib) { if (!x && !y) return; > + pwr = isl12026_read_reg(client, ISL12026_REG_PWR); > + if (pwr < 0) { > + dev_err(&client->dev, > + "Error: Failed to read PWR %d\n", pwr); > + return; > + } > + > + requested_pwr = pwr; > + > + if (set_bsw) { > + if (bsw_val) > + requested_pwr |= ISL12026_REG_PWR_BSW; > + else > + requested_pwr &= ~ISL12026_REG_PWR_BSW; > + } Undefined state if no value? > + if (set_sbib) { > + if (sbib_val) > + requested_pwr |= ISL12026_REG_PWR_SBIB; > + else > + requested_pwr &= ~ISL12026_REG_PWR_SBIB; > + } Ditto. > + > + if (pwr >= 0 && pwr != requested_pwr) { > + dev_info(&client->dev, "PWR: %02x\n", (u8)pwr); > + dev_info(&client->dev, > + "Updating PWR to: %02x\n", (u8)requested_pwr); > + isl12026_write_reg(client, > + ISL12026_REG_PWR, requested_pwr); If you do explicit casting in printf() parameters you are doing something wrong in 99.9% cases. > + } > + } > +} > +static int isl12026_probe_new(struct i2c_client *client) > +{ > + struct isl12026 *priv; > + int ret; > + /* The NVMem array responds at i2c address 0x57 */ > + priv->nvm_client = i2c_new_dummy(client->adapter, 0x57); Magic. Make it #define and put comment there. > + if (!priv->nvm_client) > + return -ENOMEM; > +} > +#ifdef CONFIG_OF Remove this ugly #ifdef. Your driver OF only one. > +static const struct of_device_id isl12026_dt_match[] = { > + { .compatible = "isil,isl12026" }, > + { }, > +}; > +MODULE_DEVICE_TABLE(of, isl12026_dt_match); > +#endif > + .of_match_table = of_match_ptr(isl12026_dt_match), Drop of_match_ptr(). -- With Best Regards, Andy Shevchenko