Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp908460ybm; Wed, 27 May 2020 10:53:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykn2jqzAJEeZlMBEM7umjflQQepLE79LXtkNTfp2uEk8kcMWn0SsRV5R7aQ5f0oPAwcnxP X-Received: by 2002:a17:906:c29a:: with SMTP id r26mr7050031ejz.286.1590601986237; Wed, 27 May 2020 10:53:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590601986; cv=none; d=google.com; s=arc-20160816; b=hwnH6I77fVEFHqfeN3b6a4DYWJTStzP3p4nnPLO6WFBv+HHXgc1FhO4jsiTj12Qq4H WaF9XYVmkJ7jYph2MLW8O1y6/LifVmL+YYSxK9EAj4bG1wy7i0XnrjBBL/so9M7qraDb xmYp9QkgpFrtnQmf3+/LW5tUyRLavObGr0NJPsAxBNG/Bf+F61u8I+kotIpGPEu+PRXH xFcKWbTJgmeAlgAQ6wnDvkNyuG4G4LdOXOpumjI+AqU5pTHL0OS8D1C6c1ez5VqpwJzO cw/qOabAH2Pu6CQkZ6DoQv5lf52LwPQyTY3KQhsNhdHfMFbzMjiPKW4iJjl9vBxXIIt+ ulLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=ksnk+9EEiWm6mLM+KV8O4vW18Hgnruf0BnWpBvbOLg4=; b=jmWTUwKOnnCqmTEYAxeddFOAO7QPIQWPa5gXk5ZPeokLlO3+NpBNv9NOAujofr729N /PTYk8/QeCOutTojCqrsTtebOh6AKXDQIZGsawTdxidIkpvsUE5lKpuwiMEy48s0P+C7 kf25YMZYmH1c040hShv0vLP2t3OtYtKd9GdbA9ZWm63wlc8gwS5ra2uEGfbacaZesyNV rlauC7tZ/bgapkZbDikkuCYuFOh+Lttjvh41g8zQUmfOKVcg/0x4a5j3wdWP/Y3iHucg Ilt32+iR7zlxwJE2NKJOi8Spvsm6XleON1VY5XNlg7rvtfWnlv78hyJIpPJ2nflJmsN+ qKlg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p19si2281931ejj.538.2020.05.27.10.52.42; Wed, 27 May 2020 10:53:06 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388042AbgE0Ng5 (ORCPT + 99 others); Wed, 27 May 2020 09:36:57 -0400 Received: from mga05.intel.com ([192.55.52.43]:32006 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387581AbgE0Ng4 (ORCPT ); Wed, 27 May 2020 09:36:56 -0400 IronPort-SDR: KEhTh1JpNi/U/YkWUhqnIblRjtOWypbT9abLQdWEyMKIpaheV+A4jZbJPajTGc/jKEBPrBC7r3 Rjl4wu0CN4Yw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2020 06:36:55 -0700 IronPort-SDR: znFbgevaueWvVVuU1HEBaUyl6TZuapozyshN0ew9BhJ1e9rR1ruTKeC7m5B6UD4C+CgDk9UK78 +O5YpSRlwq/g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,441,1583222400"; d="scan'208";a="255468688" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by fmsmga007.fm.intel.com with ESMTP; 27 May 2020 06:36:53 -0700 Received: from andy by smile with local (Exim 4.93) (envelope-from ) id 1jdwEq-009Eh5-3x; Wed, 27 May 2020 16:36:56 +0300 Date: Wed, 27 May 2020 16:36:56 +0300 From: Andy Shevchenko To: Serge Semin Cc: devicetree-compiler@vger.kernel.org, Serge Semin , Alexey Malahov , Thomas Bogendoerfer , Wolfram Sang , Jarkko Nikula , Frank Rowand , Rob Herring , devicetree@vger.kernel.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] check: Add 10bit/slave i2c reg flags support Message-ID: <20200527133656.GV1634618@smile.fi.intel.com> References: <20200527122525.6929-1-Sergey.Semin@baikalelectronics.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200527122525.6929-1-Sergey.Semin@baikalelectronics.ru> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 27, 2020 at 03:25:25PM +0300, Serge Semin wrote: > Recently the I2C-controllers slave interface support was added to the > kernel I2C subsystem. In this case Linux can be used as, for example, > a I2C EEPROM machine. See [1] for details. Other than instantiating > the EEPROM-slave device from user-space there is a way to declare the > device in dts. In this case firstly the I2C bus controller must support > the slave interface. Secondly I2C-slave sub-node of that controller > must have "reg"-property with flag I2C_OWN_SLAVE_ADDRESS set (flag is > declared in [2]). That flag is declared as (1 << 30), which when set > makes dtc unhappy about too big address set for a I2C-slave: > > Warning (i2c_bus_reg): /example-2/i2c@1120000/eeprom@64: I2C bus unit address format error, expected "40000064" > Warning (i2c_bus_reg): /example-2/i2c@1120000/eeprom@64:reg: I2C address must be less than 10-bits, got "0x40000064" > > Similar problem would have happened if we had set the 10-bit address > flag I2C_TEN_BIT_ADDRESS in the "reg"-property. > > In order to fix the problem we suggest to alter the I2C-bus reg-check > algorithm, so one would be aware of the upper bits set. Normally if no > flag specified, the 7-bit address is expected in the "reg"-property. > If I2C_TEN_BIT_ADDRESS is set, then the 10-bit address check will be > performed. The I2C_OWN_SLAVE_ADDRESS flag will be just ignored. > > [1] kernel/Documentation/i2c/slave-interface.rst > [2] kernel/include/dt-bindings/i2c/i2c.h ... > + addr = reg & 0x3FFFFFFFU; > + if ((reg & (1 << 31)) && addr > 0x3ff) > FAIL_PROP(c, dti, node, prop, "I2C address must be less than 10-bits, got \"0x%x\"", > - reg); > - > + addr); > + else if (!(reg & (1 << 31)) && addr > 0x7f) > + FAIL_PROP(c, dti, node, prop, "I2C address must be less than 7-bits, got \"0x%x\"", > + addr); 1 << 31 is UB. -- With Best Regards, Andy Shevchenko