Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753097AbbF2TSS (ORCPT ); Mon, 29 Jun 2015 15:18:18 -0400 Received: from mout.gmx.net ([212.227.17.20]:51273 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750975AbbF2TSL (ORCPT ); Mon, 29 Jun 2015 15:18:11 -0400 Message-ID: <559199E7.10607@gmx.de> Date: Mon, 29 Jun 2015 21:17:59 +0200 From: Hartmut Knaack User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:36.0) Gecko/20100101 Firefox/36.0 SeaMonkey/2.33.1 MIME-Version: 1.0 To: Daniel Baluta CC: Jonathan Cameron , Peter Meerwald , Lars-Peter Clausen , Linux Kernel Mailing List , "linux-iio@vger.kernel.org" Subject: Re: [PATCH v2 1/3] iio: magnetometer: Add support for MEMSIC MMC35240 sensor References: <1429891112-11888-1-git-send-email-daniel.baluta@intel.com> <1429891112-11888-2-git-send-email-daniel.baluta@intel.com> <55907E2F.3030308@gmx.de> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K0:l4pgZuHgqlP7RzZgbCuNPdX3+DqP391E8B+b+0c98OIABQd7mCW m5AhUgWgbRrHgD52NqohK0b/SNla9U8EfGfJiLyj+VEI6v2URKOtdOoQvuJEi0mwDcl/l61 R62DnYD4p31yRs3pivRvHQXHXGTUXMaZ8eDFLO1jTIRYjNoQvGF3JfLH1agvGFVnJxqNt9n ZfOMIyrlRMmHDM+Mwe7JQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:rJHoUEVu33k=:r2sA0TiNtkXucJBlzMf+O4 zHjaEZetYC6jxwSzB1dC0BBAmxzL6dsId1w8qmJMl7k6ka05+O6GVENPGVtHXubY4A18ZL9+3 o+ewyLkUiRAzgfrTcPxHBT8DW6N4GCb9IPpQxLjGvhuf2EWDjejfGYZKgggo2k+EVtZg27xYL gCD/El6fgM6llQAekkhAM0P+9dbxRWLNnFTXL71OfUSNyyK0ETbirYeHao9GDebS+QBT0xEB9 zs96g7rU98gAWGYhULMw8zZoUUq1HyTyj6U+mhW2AL3kc24LLcv8xgPJbPSCNdJH5anvanTcJ jPjGb9IEfRmjOqMnR7sjak3LG/34YSQXrcWT/pt65bpFWki5BAAUqctXfZICYEIy7nOoWeD1R MMOFbuiKAo6qF5bfjuDddcqnzXDhkd5CJrnnP9ynwuedPE4Im+AApSG2+NwmhfrOCyNW7KC56 IhzHRtcGfsTInWj+pKuAvFwr/4PgM+En3qp7nWFBusDB5pKbnaAlugmxtiElAdJd7bjXkRasn Bl3OXMsSnBN/fayFB7XY/VKAOQ10n+dnzTlT4zj/ba64aeAdXtnR0WI5DRtp8P5pw+KNnRZtu R70bZFJWYs+0UkRfLYjJgLGoBn3ay7M8Y1dxYcqaLUl+Tp2+tpYexG7FbsaqCrTC/I7TEBds1 u/+2RmvsRGICzTahs9Ubq93QedG5x9EHnGXTBGpMOWgMoBorvyBiZS8UAgqEqDhZUEKQ= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5693 Lines: 164 Daniel Baluta schrieb am 29.06.2015 um 09:52: > On Mon, Jun 29, 2015 at 2:07 AM, Hartmut Knaack wrote: >> Daniel Baluta schrieb am 24.04.2015 um 17:58: >>> Minimal implementation for MMC35240 3-axis magnetometer >>> sensor. It provides processed readings and possiblity to change >>> the sampling frequency. >>> >> >> Hi Daniel, >> please find a few issues inline, which you could address in a next >> rework patch set. I would have sent a patch for the critical stuff, >> but was obviously too stupid to find a data sheet :-( > > Well, there is no public datasheet. We are discussing with the vendor > to make it public. > <...> >>> +static int mmc35240_hw_set(struct mmc35240_data *data, bool set) >>> +{ >>> + int ret; >>> + u8 coil_bit; >>> + >>> + /* >>> + * Recharge the capacitor at VCAP pin, requested to be issued >>> + * before a SET/RESET command. >>> + */ >>> + ret = regmap_update_bits(data->regmap, MMC35240_REG_CTRL0, >>> + MMC35240_CTRL0_REFILL_BIT, >>> + MMC35240_CTRL0_REFILL_BIT); >>> + if (ret < 0) >>> + return ret; >>> + usleep_range(MMC35240_WAIT_CHARGE_PUMP, MMC35240_WAIT_CHARGE_PUMP + 1); >>> + >>> + if (set) >>> + coil_bit = MMC35240_CTRL0_SET_BIT; >>> + else >>> + coil_bit = MMC35240_CTRL0_RESET_BIT; >>> + >>> + return regmap_update_bits(data->regmap, MMC35240_REG_CTRL0, >>> + MMC35240_CTRL0_REFILL_BIT, >>> + coil_bit); >> >> coil_bit is in any case outside the mask of MMC35240_CTRL0_REFILL_BIT. >> Not sure about the whole intention, meaning in which state >> MMC35240_CTRL0_REFILL_BIT is supposed to be (set) when either >> MMC35240_CTRL0_SET_BIT or MMC35240_CTRL0_RESET_BIT is written. > > Yes, this is a bug. We have a patch prepared for it. Will send once Jonathan is > ready to accept bugfixes. Together with this: > > http://marc.info/?l=linux-iio&m=143489464403101&w=2 > Sending it out earlier gives people more time to review (or may allow more people to review). > >> >>> +} <...> >>> + >>> +static int mmc35240_take_measurement(struct mmc35240_data *data) >>> +{ >>> + int ret, tries = 100; >>> + unsigned int reg_status; >>> + >>> + ret = regmap_write(data->regmap, MMC35240_REG_CTRL0, >>> + MMC35240_CTRL0_TM_BIT); >>> + if (ret < 0) >>> + return ret; >>> + >>> + while (tries-- > 0) { >>> + ret = regmap_read(data->regmap, MMC35240_REG_STATUS, >>> + ®_status); >>> + if (ret < 0) >>> + return ret; >>> + if (reg_status & MMC35240_STATUS_MEAS_DONE_BIT) >>> + break; >> >> I would actually return 0 here, as measurement was successful. That >> would mean that getting outside the loop is the error case and would >> make the check obsolete. > > You are right, this could also work. Anyhow, I think code is easier to > understand as it is. The check for (tries < 0) makes it very clear, that the > data was not ready. > > Getting outside the loop in the error case is harder to understand at a first > glance. > I can not really agree. The mission is accomplished at the break, so better take the shortest way out (return 0 usually reflects that). Still going through a check that won't trigger in this case just adds bloat without any benefit. It's not a bug, so I don't feel too strong to fix it myself (still too much reviews to be done). Sorry for annoying with such issues, spending my childhood with slow and low memory 8 bit machines just left a mark ;-) >> >>> + msleep(20); >>> + } >>> + >>> + if (tries < 0) { >>> + dev_err(&data->client->dev, "data not ready\n"); >>> + return -EIO; >> >> Doesn't this qualify more for a timeout error, rather than I/O? > > Looking at the IIO drivers, most of them return EIO in such case. > (grep for EIO in drivers/iio/light for example) > I don't feel too strong about this. I just regard I/O errors as indication that communication with the device went wrong. But when getting here, it always told to be busy. > > >>> + case IIO_CHAN_INFO_SAMP_FREQ: >>> + mutex_lock(&data->mutex); >>> + ret = regmap_read(data->regmap, MMC35240_REG_CTRL1, ®); >>> + mutex_unlock(&data->mutex); >>> + if (ret < 0) >>> + return ret; >>> + >>> + i = (reg & MMC35240_CTRL1_BW_MASK) >> MMC35240_CTRL1_BW_SHIFT; >>> + if (i < 0 || i > ARRAY_SIZE(mmc35240_samp_freq)) >> >> I would drop i and keep using reg. Has the nice side effect that you don't >> need to check for negative values. > > Ok. > > > > >>> + >>> +static bool mmc35240_is_volatile_reg(struct device *dev, unsigned int reg) >>> +{ >>> + switch (reg) { >>> + case MMC35240_REG_CTRL0: >>> + case MMC35240_REG_CTRL1: >> >> I would regard MMC35240_REG_ID as non-volatile, as well. Or is it because it >> is just accessed once? > > Correct, we access it only once. > > Hartmut, thanks a lot for your reviews! > > thanks, > Daniel. > -- > To unsubscribe from this list: send the line "unsubscribe linux-iio" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/