From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753067AbbC3IFi (ORCPT ); Mon, 30 Mar 2015 04:05:38 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:41970 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752904AbbC3IFa (ORCPT ); Mon, 30 Mar 2015 04:05:30 -0400 X-Listener-Flag: 11101 Subject: Re: [PATCH v5 3/3] I2C: mediatek: Add driver for MediaTek MT8173 I2C controller From: Eddie Huang To: Sascha Hauer CC: Mark Rutland , Wolfram Sang , Doug Anderson , , David Box , Lee Jones , Jean Delvare , Xudong Chen , Boris BREZILLON , Pawel Moll , Liguo Zhang , Wei Yan , Bjorn Andersson , Uwe =?ISO-8859-1?Q?Kleine-K=F6nig?= , Neelesh Gupta , , Arnd Bergmann , Ian Campbell , Beniamino Galvani , Rob Herring , , Matthias Brugger , , , Anders Berg , Jim Cromie , Simon Glass , Max Schwarz , , Sascha Hauer , Kumar Gala In-Reply-To: <20150323073905.GF9742@pengutronix.de> References: <1426917922-61356-1-git-send-email-eddie.huang@mediatek.com> <1426917922-61356-4-git-send-email-eddie.huang@mediatek.com> <20150323073905.GF9742@pengutronix.de> Content-Type: text/plain; charset="UTF-8" Date: Mon, 30 Mar 2015 16:05:19 +0800 Message-ID: <1427702719.26464.5.camel@mtksdaap41> MIME-Version: 1.0 X-Mailer: Evolution 2.28.3 Content-Transfer-Encoding: 7bit X-MTK: N Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Sascha, On Mon, 2015-03-23 at 08:39 +0100, Sascha Hauer wrote: > On Sat, Mar 21, 2015 at 02:05:22PM +0800, Eddie Huang wrote: > > Add mediatek MT8173 I2C controller driver. Compare to I2C controller > > of earlier mediatek SoC, MT8173 fix write-then-read limitation, and > > also increase message size to 64kb. > > > > [...] > > > +static const struct i2c_adapter_quirks mt8173_i2c_quirks = { > > + .max_num_msgs = MAX_MSG_NUM_MT8173, > > + .max_write_len = MAX_DMA_TRANS_SIZE_MT8173, > > + .max_read_len = MAX_DMA_TRANS_SIZE_MT8173, > > + .max_comb_1st_msg_len = MAX_DMA_TRANS_SIZE_MT8173, > > + .max_comb_2nd_msg_len = MAX_WRRD_TRANS_SIZE_MT8173, > > +}; > > + > > static int mtk_i2c_probe(struct platform_device *pdev) > > { > > int ret = 0; > > @@ -587,7 +626,8 @@ static int mtk_i2c_probe(struct platform_device *pdev) > > return -EINVAL; > > > > i2c->platform_compat = mtk_get_device_prop(pdev); > > - if (i2c->have_pmic && (i2c->platform_compat & COMPAT_MT6577)) > > + if (i2c->have_pmic && (i2c->platform_compat & > > + (COMPAT_MT6577 | COMPAT_MT8173))) > > return -EINVAL; > > > > res = platform_get_resource(pdev, IORESOURCE_MEM, 0); > > @@ -613,7 +653,10 @@ static int mtk_i2c_probe(struct platform_device *pdev) > > i2c->adap.dev.parent = &pdev->dev; > > i2c->adap.owner = THIS_MODULE; > > i2c->adap.algo = &mtk_i2c_algorithm; > > - i2c->adap.quirks = &mt6577_i2c_quirks; > > + if (i2c->platform_compat & COMPAT_MT8173) > > + i2c->adap.quirks = &mt8173_i2c_quirks; > > + else > > + i2c->adap.quirks = &mt6577_i2c_quirks; > > Instead of putting an integer into struct of_device_id you should > introduce a > > struct mtk_i2c_data { > struct i2c_adapter_quirks quirks; > int compat; > /* Additional SoC specific data */ > }; > > and put a pointer to this directly into the of_device_id. This way you > need less casting and can put newly discovered differences diretly into > some data struct and don't have to introduce if(socxy) ... else ... > everytime. > Thanks your suggestion. I will use capability struct like struct mtk_i2c_compatible { unsigned char pmic_i2c; unsigned char dcm; unsigned char auto_restart; const struct i2c_adapter_quirks *quirks; }; And pass in of_device_id, then remove all if(socxy).... else ... in driver. Eddie From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eddie Huang Subject: Re: [PATCH v5 3/3] I2C: mediatek: Add driver for MediaTek MT8173 I2C controller Date: Mon, 30 Mar 2015 16:05:19 +0800 Message-ID: <1427702719.26464.5.camel@mtksdaap41> References: <1426917922-61356-1-git-send-email-eddie.huang@mediatek.com> <1426917922-61356-4-git-send-email-eddie.huang@mediatek.com> <20150323073905.GF9742@pengutronix.de> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20150323073905.GF9742-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> Sender: devicetree-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Sascha Hauer Cc: Mark Rutland , Wolfram Sang , Doug Anderson , linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, David Box , Lee Jones , Jean Delvare , Xudong Chen , Boris BREZILLON , Pawel Moll , Liguo Zhang , Wei Yan , Bjorn Andersson , Uwe =?ISO-8859-1?Q?Kleine-K=F6nig?= , Neelesh Gupta , devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Arnd Bergmann , Ian Campbell , Beniamino Galvani , Rob Herring , linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, Matthias Brugger List-Id: devicetree@vger.kernel.org Hi Sascha, On Mon, 2015-03-23 at 08:39 +0100, Sascha Hauer wrote: > On Sat, Mar 21, 2015 at 02:05:22PM +0800, Eddie Huang wrote: > > Add mediatek MT8173 I2C controller driver. Compare to I2C controller > > of earlier mediatek SoC, MT8173 fix write-then-read limitation, and > > also increase message size to 64kb. > > > > [...] > > > +static const struct i2c_adapter_quirks mt8173_i2c_quirks = { > > + .max_num_msgs = MAX_MSG_NUM_MT8173, > > + .max_write_len = MAX_DMA_TRANS_SIZE_MT8173, > > + .max_read_len = MAX_DMA_TRANS_SIZE_MT8173, > > + .max_comb_1st_msg_len = MAX_DMA_TRANS_SIZE_MT8173, > > + .max_comb_2nd_msg_len = MAX_WRRD_TRANS_SIZE_MT8173, > > +}; > > + > > static int mtk_i2c_probe(struct platform_device *pdev) > > { > > int ret = 0; > > @@ -587,7 +626,8 @@ static int mtk_i2c_probe(struct platform_device *pdev) > > return -EINVAL; > > > > i2c->platform_compat = mtk_get_device_prop(pdev); > > - if (i2c->have_pmic && (i2c->platform_compat & COMPAT_MT6577)) > > + if (i2c->have_pmic && (i2c->platform_compat & > > + (COMPAT_MT6577 | COMPAT_MT8173))) > > return -EINVAL; > > > > res = platform_get_resource(pdev, IORESOURCE_MEM, 0); > > @@ -613,7 +653,10 @@ static int mtk_i2c_probe(struct platform_device *pdev) > > i2c->adap.dev.parent = &pdev->dev; > > i2c->adap.owner = THIS_MODULE; > > i2c->adap.algo = &mtk_i2c_algorithm; > > - i2c->adap.quirks = &mt6577_i2c_quirks; > > + if (i2c->platform_compat & COMPAT_MT8173) > > + i2c->adap.quirks = &mt8173_i2c_quirks; > > + else > > + i2c->adap.quirks = &mt6577_i2c_quirks; > > Instead of putting an integer into struct of_device_id you should > introduce a > > struct mtk_i2c_data { > struct i2c_adapter_quirks quirks; > int compat; > /* Additional SoC specific data */ > }; > > and put a pointer to this directly into the of_device_id. This way you > need less casting and can put newly discovered differences diretly into > some data struct and don't have to introduce if(socxy) ... else ... > everytime. > Thanks your suggestion. I will use capability struct like struct mtk_i2c_compatible { unsigned char pmic_i2c; unsigned char dcm; unsigned char auto_restart; const struct i2c_adapter_quirks *quirks; }; And pass in of_device_id, then remove all if(socxy).... else ... in driver. Eddie -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html From mboxrd@z Thu Jan 1 00:00:00 1970 From: eddie.huang@mediatek.com (Eddie Huang) Date: Mon, 30 Mar 2015 16:05:19 +0800 Subject: [PATCH v5 3/3] I2C: mediatek: Add driver for MediaTek MT8173 I2C controller In-Reply-To: <20150323073905.GF9742@pengutronix.de> References: <1426917922-61356-1-git-send-email-eddie.huang@mediatek.com> <1426917922-61356-4-git-send-email-eddie.huang@mediatek.com> <20150323073905.GF9742@pengutronix.de> Message-ID: <1427702719.26464.5.camel@mtksdaap41> To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org Hi Sascha, On Mon, 2015-03-23 at 08:39 +0100, Sascha Hauer wrote: > On Sat, Mar 21, 2015 at 02:05:22PM +0800, Eddie Huang wrote: > > Add mediatek MT8173 I2C controller driver. Compare to I2C controller > > of earlier mediatek SoC, MT8173 fix write-then-read limitation, and > > also increase message size to 64kb. > > > > [...] > > > +static const struct i2c_adapter_quirks mt8173_i2c_quirks = { > > + .max_num_msgs = MAX_MSG_NUM_MT8173, > > + .max_write_len = MAX_DMA_TRANS_SIZE_MT8173, > > + .max_read_len = MAX_DMA_TRANS_SIZE_MT8173, > > + .max_comb_1st_msg_len = MAX_DMA_TRANS_SIZE_MT8173, > > + .max_comb_2nd_msg_len = MAX_WRRD_TRANS_SIZE_MT8173, > > +}; > > + > > static int mtk_i2c_probe(struct platform_device *pdev) > > { > > int ret = 0; > > @@ -587,7 +626,8 @@ static int mtk_i2c_probe(struct platform_device *pdev) > > return -EINVAL; > > > > i2c->platform_compat = mtk_get_device_prop(pdev); > > - if (i2c->have_pmic && (i2c->platform_compat & COMPAT_MT6577)) > > + if (i2c->have_pmic && (i2c->platform_compat & > > + (COMPAT_MT6577 | COMPAT_MT8173))) > > return -EINVAL; > > > > res = platform_get_resource(pdev, IORESOURCE_MEM, 0); > > @@ -613,7 +653,10 @@ static int mtk_i2c_probe(struct platform_device *pdev) > > i2c->adap.dev.parent = &pdev->dev; > > i2c->adap.owner = THIS_MODULE; > > i2c->adap.algo = &mtk_i2c_algorithm; > > - i2c->adap.quirks = &mt6577_i2c_quirks; > > + if (i2c->platform_compat & COMPAT_MT8173) > > + i2c->adap.quirks = &mt8173_i2c_quirks; > > + else > > + i2c->adap.quirks = &mt6577_i2c_quirks; > > Instead of putting an integer into struct of_device_id you should > introduce a > > struct mtk_i2c_data { > struct i2c_adapter_quirks quirks; > int compat; > /* Additional SoC specific data */ > }; > > and put a pointer to this directly into the of_device_id. This way you > need less casting and can put newly discovered differences diretly into > some data struct and don't have to introduce if(socxy) ... else ... > everytime. > Thanks your suggestion. I will use capability struct like struct mtk_i2c_compatible { unsigned char pmic_i2c; unsigned char dcm; unsigned char auto_restart; const struct i2c_adapter_quirks *quirks; }; And pass in of_device_id, then remove all if(socxy).... else ... in driver. Eddie