Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1211338ybt; Thu, 18 Jun 2020 03:19:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw54tdR7VXOLPAatiTvmEk4zypbcd8kN9AJJp3KAU4e+x0Vrqx/G9dTT9eeyVnYnWa4WOlz X-Received: by 2002:aa7:df05:: with SMTP id c5mr3248033edy.48.1592475569817; Thu, 18 Jun 2020 03:19:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592475569; cv=none; d=google.com; s=arc-20160816; b=Tqc3UGXT7QXXRVkhn7yPNPMwpUbr0+m9zV5+e3QuFqvpI3SD4ngzVQeI8zrf4KSzgn xqJ+NxwAU43P/dgvs2UAnJ4jAsceTFBhZwskyT//mGEFf/pOE4T+r2pFFgPHD/jaU+F5 eQl0QP2M1KLSyqgz8FX5jNZoNpfbNZRXly7QeHXz+81CxJsCw5sw1VV2ZEeKjA323wCd 8uWSnrO8dFS9BrIaT5EGKLsedzXF+4uKBCmJGAyqlILSXkHIDd2mVOiie1gUiNIGhpJL bOow3LIfNDp8ZmnSNwl68WNEvW3IAkzLm1KIrJoZNRoeAz/nvaLcKrGdI8vAxQKE4DFP uLEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=qg9tEPVUfxnFCIrhq6Cxtm2xq+K41ta0C1KawN8gvHM=; b=AmeRYazcMx+Vc9jZ7Ken4F0z0dTjdft3vU0Pc4Uqztk5Ff9MmPbpR0VjlJH2zkhYnn imjQkZkwsc6+qhOt82p8g/PrtU4Uir+oU0tArXVy3L3B74a8XEKmcsR24ieP+ART/9gz oMeuk+NZvvwtxvDYEO7RI1AF8jhoNM4PAQLfwMeAb+eIT34z8uMo+ZJHEo5JVcp9+Vgb 9DjXjZ6xjBPJLR/lSyUeAD2YbqJ5PKIPZfMhVGaQvBQwJbsZInXVqHHLasMdffy+fExn Q0eLF/DD/Z7o2TamzBij9aKD2IV/Za0ay0J72olqA7WgsaSkU2WDIOqaf0uW1160UUYi eUKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cx1luB+7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id cf23si1642161ejb.540.2020.06.18.03.19.07; Thu, 18 Jun 2020 03:19:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cx1luB+7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728938AbgFRKPS (ORCPT + 99 others); Thu, 18 Jun 2020 06:15:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728231AbgFRKPR (ORCPT ); Thu, 18 Jun 2020 06:15:17 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42ADFC06174E for ; Thu, 18 Jun 2020 03:15:16 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id d128so5054599wmc.1 for ; Thu, 18 Jun 2020 03:15:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=qg9tEPVUfxnFCIrhq6Cxtm2xq+K41ta0C1KawN8gvHM=; b=cx1luB+7YGehI94Iy1BhgMiMrmFysQYJiLKsYuiOmDAB+3AKeMO0DjkOYboqILxEqC DBfoUR5CqCHqVAuv41ZNBwqb2NVc2JZW3upewmiGh8rRh5Ri2ne3kuFFfTL78uqz7Bzf x7shGbSJ4KWrsbfsy2EArTf/m+Io6mvPxvPWcH2cxG5qz+UzJtd1WujRxu/A7qUSVFKL 8fJVUkyxN4GFHAw/IK8W0uq0E4SXE5AON3vtx/oKxGX/V3mvjaufe3u7FJOvsvx5XVd1 GOrsGqSzF4VD3m76NFntyGfiW9RIQO7iYTB4JhEUJNn0v9RrVtwYV9TmXi+Ei1EoWpkJ tiVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=qg9tEPVUfxnFCIrhq6Cxtm2xq+K41ta0C1KawN8gvHM=; b=K/egVsula4/t3ixI2UoSXj+JKtiBkUjSULIMX3K7BwApEW3WIYdJNnNBb7hZrGpDnr B000ZYzlEyFNh5Y1lwn9QAOBdZoEjH8baIW94gUKn/XI+JQOFoJdvkhLHXKnkwQ2qjaI NhCud0eW2xvS9rBc3JsKgsJHmOHHO9K3E6Zv36YE92R1C3J9watwx7ZFEfSheTb1/dX1 Uw7a9T9k/JGOOV8T6mhs2Zn4hFWEX8x1fYxASKpGV3C+O1B4dUDVAKk8DhhF9xRHureC XVW9/AqF4/GSmYyIkPz8LkEsnxNQPM7Bq2MdkgUXZNNJz8ZOx1aM6vq3Chl8010+9K/B +MOQ== X-Gm-Message-State: AOAM533YQKBLr/UDSdNT0SkSb6auvSBtMJVKGy/bTdkjZ26nAD25GwXg i01oEWfIN1MuCtnE3ykEzFeTRQ== X-Received: by 2002:a7b:cb91:: with SMTP id m17mr3400539wmi.126.1592475314881; Thu, 18 Jun 2020 03:15:14 -0700 (PDT) Received: from dell ([95.149.164.118]) by smtp.gmail.com with ESMTPSA id y14sm2767123wma.25.2020.06.18.03.15.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jun 2020 03:15:14 -0700 (PDT) Date: Thu, 18 Jun 2020 11:15:11 +0100 From: Lee Jones To: Adam Thomson Cc: linux-kernel@vger.kernel.org, Support Opensource Subject: Re: [PATCH v3 1/2] mfd: da9063: Fix revision handling to correctly select reg tables Message-ID: <20200618101511.GE954398@dell> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 17 Apr 2020, Adam Thomson wrote: > The current implementation performs checking in the i2c_probe() > function of the variant_code but does this immediately after the > containing struct has been initialised as all zero. This means the > check for variant code will always default to using the BB tables > and will never select AD. The variant code is subsequently set > by device_init() and later used by the RTC so really it's a little > fortunate this mismatch works. > > This update adds raw I2C read access functionality to read the chip > and variant/revision information (common to all revisions) so that > it can subsequently correctly choose the proper regmap tables for > real initialisation. > > Signed-off-by: Adam Thomson > --- > drivers/mfd/da9063-core.c | 31 ------ > drivers/mfd/da9063-i2c.c | 184 +++++++++++++++++++++++++++++++---- > include/linux/mfd/da9063/registers.h | 15 ++- > 3 files changed, 177 insertions(+), 53 deletions(-) [...] > + * Raw I2C access required for just accessing chip and variant info before we > + * know which device is present. The info read from the device using this > + * approach is then used to select the correct regmap tables. > + */ > + > +#define DA9063_REG_PAGE_SIZE 0x100 > +#define DA9063_REG_PAGED_ADDR_MASK 0xFF > + > +enum da9063_page_sel_buf_fmt { > + DA9063_PAGE_SEL_BUF_PAGE_REG = 0, > + DA9063_PAGE_SEL_BUF_PAGE_VAL, > + DA9063_PAGE_SEL_BUF_SIZE, > +}; > + > +enum da9063_paged_read_msgs { > + DA9063_PAGED_READ_MSG_PAGE_SEL = 0, > + DA9063_PAGED_READ_MSG_REG_SEL, > + DA9063_PAGED_READ_MSG_DATA, > + DA9063_PAGED_READ_MSG_CNT, > +}; > + > +static int da9063_i2c_blockreg_read(struct i2c_client *client, u16 addr, > + u8 *buf, int count) > +{ > + struct i2c_msg xfer[DA9063_PAGED_READ_MSG_CNT]; > + u8 page_sel_buf[DA9063_PAGE_SEL_BUF_SIZE]; > + u8 page_num, paged_addr; > + int ret; > + > + /* Determine page info based on register address */ > + page_num = (addr / DA9063_REG_PAGE_SIZE); > + if (page_num > 1) { > + dev_err(&client->dev, "Invalid register address provided\n"); > + return -EINVAL; > + } > + > + paged_addr = (addr % DA9063_REG_PAGE_SIZE) & DA9063_REG_PAGED_ADDR_MASK; > + page_sel_buf[DA9063_PAGE_SEL_BUF_PAGE_REG] = DA9063_REG_PAGE_CON; > + page_sel_buf[DA9063_PAGE_SEL_BUF_PAGE_VAL] = > + (page_num << DA9063_I2C_PAGE_SEL_SHIFT) & DA9063_REG_PAGE_MASK; > + > + /* Write reg address, page selection */ > + xfer[DA9063_PAGED_READ_MSG_PAGE_SEL].addr = client->addr; > + xfer[DA9063_PAGED_READ_MSG_PAGE_SEL].flags = 0; > + xfer[DA9063_PAGED_READ_MSG_PAGE_SEL].len = DA9063_PAGE_SEL_BUF_SIZE; > + xfer[DA9063_PAGED_READ_MSG_PAGE_SEL].buf = page_sel_buf; > + > + /* Select register address */ > + xfer[DA9063_PAGED_READ_MSG_REG_SEL].addr = client->addr; > + xfer[DA9063_PAGED_READ_MSG_REG_SEL].flags = 0; > + xfer[DA9063_PAGED_READ_MSG_REG_SEL].len = sizeof(paged_addr); > + xfer[DA9063_PAGED_READ_MSG_REG_SEL].buf = &paged_addr; > + > + /* Read data */ > + xfer[DA9063_PAGED_READ_MSG_DATA].addr = client->addr; > + xfer[DA9063_PAGED_READ_MSG_DATA].flags = I2C_M_RD; > + xfer[DA9063_PAGED_READ_MSG_DATA].len = count; > + xfer[DA9063_PAGED_READ_MSG_DATA].buf = buf; > + > + ret = i2c_transfer(client->adapter, xfer, DA9063_PAGED_READ_MSG_CNT); > + if (ret < 0) { > + dev_err(&client->dev, "Paged block read failed: %d\n", ret); > + return ret; > + } > + > + if (ret != DA9063_PAGED_READ_MSG_CNT) { > + dev_err(&client->dev, "Paged block read failed to complete\n"); > + return -EIO; > + } > + > + return 0; > +} Rather than open coding this, does it make sense to register a small (temporary?) Device ID Regmap to read from? -- Lee Jones [李琼斯] Senior Technical Lead - Developer Services Linaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog