Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753441AbcKGPZL (ORCPT ); Mon, 7 Nov 2016 10:25:11 -0500 Received: from mail1.bemta3.messagelabs.com ([195.245.230.169]:57826 "EHLO mail1.bemta3.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752918AbcKGPZI (ORCPT ); Mon, 7 Nov 2016 10:25:08 -0500 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrJKsWRWlGSWpSXmKPExsUSt3Opse65OQo RBu/bxSymPnzCZjH/yDlWi8OLXjBazL9yjdXi/tejjBbfrnQwWdz89I3V4vKuOWwWn3uPMFrc WLeP3eLJwjNMFkuvX2SyaN17BMh92MdmcWvGC1YHfo8189YweuycdZfd49pmMY/Fe14yeWxa1 cnmcefaHjaPnd8b2D0+b5IL4IhizcxLyq9IYM2YunAlY8EriYrzC9vYGhgPSHQxcnEICSxllN j39Tp7FyMnB5uAocS8N+8Zuxg5OEQEVCTOvTEHqWEWeMwiceLhG1aQGmEBS4nDh2aC1YsIWEm 8/jaPDcb+suosWJwFqHdzxz5mEJtXIEDi44s5YLaQwA5GiVcLjEBsTgEtidMzN7OA2IwCshJf GleD1TALiEvcejKfCcSWEBCQWLLnPDOELSrx8vE/VghbXmLtrydQcXuJ1/fesYDcLCGgL9HXW AwRNpRYNe0AC4RtLnHiexsrSAmzgKbE+l36EJsUJaZ0P2SHuFJQ4uTMJywTGMVnITliFkLHLC Qds5B0LGBkWcWoXpxaVJZapGuol1SUmZ5RkpuYmaNraGCsl5taXJyYnpqTmFSsl5yfu4kRmCQ YgGAH4/KPTocYJTmYlER5X8xSiBDiS8pPqcxILM6ILyrNSS0+xCjDwaEkwSsBTDpCgkWp6akV aZk5wHQFk5bg4FES4T03GyjNW1yQmFucmQ6ROsWoKCXO+xckIQCSyCjNg2uDpchLjLJSwryMQ IcI8RSkFuVmlqDKv2IU52BUEub9CjKFJzOvBG76K6DFTECLq2LAFpckIqSkGhinbpy8/Xbpg0 31r0PD/l6a+/WvUaN6p/zpibdnRbXw37HfsP76n+oyvbUh2+p+zTm9zsvHwSFItrpxu61J4Nv FV3bwsKwoVWbdzRp+OGdrQuMB1gfLZRXXXT+3Qj7DJH27aX24t+uvmtaOafJHPzmpvY67cElA xUnjkhRfakXA6l+eCyIKtF4osRRnJBpqMRcVJwIAykoOGowDAAA= X-Env-Sender: stwiss.opensource@diasemi.com X-Msg-Ref: server-13.tower-38.messagelabs.com!1478532302!60815254!1 X-Originating-IP: [94.185.165.51] X-StarScan-Received: X-StarScan-Version: 9.0.13; banners=-,-,- X-VirusChecked: Checked From: Steve Twiss To: Lee Jones CC: LINUX-KERNEL , DEVICETREE , Dmitry Torokhov , Eduardo Valentin , Guenter Roeck , LINUX-INPUT , LINUX-PM , LINUX-WATCHDOG , Liam Girdwood , Mark Brown , "Mark Rutland" , Rob Herring , "Support Opensource" , Wim Van Sebroeck , Zhang Rui Subject: RE: [PATCH V3 5/9] mfd: da9061: MFD core support Thread-Topic: [PATCH V3 5/9] mfd: da9061: MFD core support Thread-Index: AQHSM5IFFMHFxbniuEmfO9QmgeGvmaDFw7wAgAGADMA= Date: Mon, 7 Nov 2016 15:25:00 +0000 Message-ID: <6ED8E3B22081A4459DAC7699F3695FB7018CCE7CB6@SW-EX-MBX02.diasemi.com> References: <72145ea5055e95d7b6f05168c641927e4f3830d9.1477929725.git.stwiss.opensource@diasemi.com> <20161102142854.GS13127@dell> In-Reply-To: <20161102142854.GS13127@dell> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.20.26.77] x-kse-attachmentfiltering-interceptor-info: protection disabled x-kse-serverinfo: sw-ex-cashub01.diasemi.com, 9 x-kse-antivirus-interceptor-info: scan successful x-kse-antivirus-info: Clean, bases: 07/11/2016 13:28:00 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id uA7FPEnM032587 Content-Length: 2283 Lines: 68 On 02 November 2016 14:29, Lee Jones wrote: > On Mon, 31 Oct 2016, Steve Twiss wrote: > > From: Steve Twiss > > > > @@ -475,7 +855,25 @@ static int da9062_i2c_probe(struct i2c_client *i2c, > > return -EINVAL; > > } > > > > - chip->regmap = devm_regmap_init_i2c(i2c, &da9062_regmap_config); > > + switch (chip->chip_type) { > > + case(COMPAT_TYPE_DA9061): > > + cell = da9061_devs; > > + cell_num = ARRAY_SIZE(da9061_devs); > > + irq_chip = &da9061_irq_chip; > > + config = &da9061_regmap_config; > > + break; > > + case(COMPAT_TYPE_DA9062): > > + cell = da9062_devs; > > + cell_num = ARRAY_SIZE(da9062_devs); > > + irq_chip = &da9062_irq_chip; > > + config = &da9062_regmap_config; > > + break; > > + default: > > + dev_err(chip->dev, "Unrecognised chip type\n"); > > + return -ENODEV; > > + } > > I very much dislike when MFD and OF functionality is mixed. > > In your case you can use da9062_get_device_type() to dynamically > interrogate the device and register using the correct MFD cells that > way. Hi Lee, It's the device tree that decides what the chip type is. It's not chip interrogation in this case. The ordering dictates this I think: to access the hardware ID register, a regmap definition is needed first. But because the correct I2C register map requires a knowledge of what chip is being used, it becomes a circular dependency. To solve this dependency, I define the chip type (DA9061 or DA9062) in the device tree and assign the correct regmap first before accessing any registers. > > + chip->regmap = devm_regmap_init_i2c(i2c, config); > > if (IS_ERR(chip->regmap)) { > > ret = PTR_ERR(chip->regmap); > > dev_err(chip->dev, "Failed to allocate register map: %d\n", > > @@ -493,7 +891,7 @@ static int da9062_i2c_probe(struct i2c_client *i2c, > > > > ret = regmap_add_irq_chip(chip->regmap, i2c->irq, > > IRQF_TRIGGER_LOW | IRQF_ONESHOT |IRQF_SHARED, > > - -1, &da9062_irq_chip, > > + -1, irq_chip, > > What is -1? .. it's a request for an irq_base. http://lxr.free-electrons.com/source/kernel/irq/irqdesc.c#L477 Is there a reason I shouldn't be doing that? There doesn't seem to be a #define anywhere, and using -1 seems to be the standard in the kernel at the moment. Regards, Steve