From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757167AbbBELF2 (ORCPT ); Thu, 5 Feb 2015 06:05:28 -0500 Received: from mail-by2on0094.outbound.protection.outlook.com ([207.46.100.94]:3585 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751722AbbBELFZ convert rfc822-to-8bit (ORCPT ); Thu, 5 Feb 2015 06:05:25 -0500 X-Greylist: delayed 1062 seconds by postgrey-1.27 at vger.kernel.org; Thu, 05 Feb 2015 06:05:25 EST Message-ID: <1423132322.1110.13.camel@ubuntu> Subject: Re: [PATCH v8 2/2] drivers/gpio: Altera soft IP GPIO driver From: Tien Hock Loh To: Joe Perches CC: , Pawel Moll , Mark Rutland , Ian Campbell , "Kumar Gala" , Linus Walleij , Alexandre Courbot , Grant Likely , Andrew Morton , "David S. Miller" , Greg Kroah-Hartman , Mauro Carvalho Chehab , Antti Palosaari , , , , Dinh Nguyen Date: Thu, 5 Feb 2015 02:32:02 -0800 In-Reply-To: <1419419050.6157.11.camel@perches.com> References: <1419409345-8297-1-git-send-email-thloh@altera.com> <1419409345-8297-3-git-send-email-thloh@altera.com> <1419419050.6157.11.camel@perches.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Mailer: Evolution 3.2.3-0ubuntu6 MIME-Version: 1.0 X-EOPAttributedMessage: 0 Authentication-Results: spf=softfail (sender IP is 66.35.236.227) smtp.mailfrom=thloh@altera.com; codeaurora.org; dkim=none (message not signed) header.d=none; X-Forefront-Antispam-Report: CIP:66.35.236.227;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(377424004)(51704005)(24454002)(23676002)(50226001)(103116003)(110136001)(105596002)(33716001)(92566002)(50466002)(106466001)(47776003)(87936001)(33646002)(6806004)(86362001)(19580405001)(19580395003)(46102003)(2950100001)(42186005)(76176999)(50986999)(62966003)(77156002)(7099025)(99106002);DIR:OUT;SFP:1101;SCL:1;SRVR:DM2PR0301MB0752;H:sj-itexedge03.altera.priv.altera.com;FPR:;SPF:SoftFail;MLV:ovrnspm;PTR:InfoDomainNonexistent;LANG:en; X-Microsoft-Antispam: UriScan:; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:DM2PR0301MB0752; X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004);SRVR:DM2PR0301MB0752; X-Forefront-PRVS: 0478C23FE0 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:;SRVR:DM2PR0301MB0752; X-OriginatorOrg: altera.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Feb 2015 10:32:08.9967 (UTC) X-MS-Exchange-CrossTenant-Id: fbd72e03-d4a5-4110-adce-614d51f2077a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=fbd72e03-d4a5-4110-adce-614d51f2077a;Ip=[66.35.236.227] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR0301MB0752 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2014-12-24 at 03:04 -0800, Joe Perches wrote: > On Wed, 2014-12-24 at 00:22 -0800, thloh@altera.com wrote: > > Adds a new driver for Altera soft GPIO IP. The driver is able to > > do read/write and allows GPIO to be a interrupt controller. > > Some trivial comments, some not quite so trivial. > > > diff --git a/drivers/gpio/gpio-altera.c b/drivers/gpio/gpio-altera.c > [] > > +static int altera_gpio_irq_set_type(struct irq_data *d, > > + unsigned int type) > > +{ > > + struct altera_gpio_chip *altera_gc = irq_data_get_irq_chip_data(d); > > + > > + altera_gc = irq_data_get_irq_chip_data(d); > > I presume this multiple initialization of altera_gc > is unnecessary duplication. I'll remove this. > > > +static void altera_gpio_irq_edge_handler(unsigned int irq, > > + struct irq_desc *desc) > > +{ > > + struct altera_gpio_chip *altera_gc; > > + struct irq_chip *chip; > > + struct of_mm_gpio_chip *mm_gc; > > + unsigned long status; > > + int i; > > + > > + altera_gc = irq_desc_get_handler_data(desc); > > + chip = irq_desc_get_chip(desc); > > + mm_gc = &altera_gc->mmchip; > > + > > + chained_irq_enter(chip, desc); > > + > > + while ((status = > > + (readl(mm_gc->regs + ALTERA_GPIO_EDGE_CAP) & > > + readl(mm_gc->regs + ALTERA_GPIO_IRQ_MASK)))) { > > + writel(status, mm_gc->regs + ALTERA_GPIO_EDGE_CAP); > > + for_each_set_bit(i, &status, mm_gc->gc.ngpio) { > > + generic_handle_irq( > > + irq_find_mapping(altera_gc->mmchip.gc.irqdomain > > + , i)); > > That's kind of unpleasant to read. > It might be better to use a separate these statements > and use a temporary for irq_find_mapping() > OK I'll fix it. > > +static void altera_gpio_irq_leveL_high_handler(unsigned int irq, > > + struct irq_desc *desc) > > +{ > > + struct altera_gpio_chip *altera_gc; > > + struct irq_chip *chip; > > + struct of_mm_gpio_chip *mm_gc; > > + unsigned long status; > > + int i; > > + > > + altera_gc = irq_desc_get_handler_data(desc); > > + chip = irq_desc_get_chip(desc); > > + mm_gc = &altera_gc->mmchip; > > + > > + chained_irq_enter(chip, desc); > > + > > + status = readl(mm_gc->regs + ALTERA_GPIO_DATA); > > + status &= readl(mm_gc->regs + ALTERA_GPIO_IRQ_MASK); > > + > > + for_each_set_bit(i, &status, mm_gc->gc.ngpio) { > > + generic_handle_irq( > > + irq_find_mapping(altera_gc->mmchip.gc.irqdomain, i)); > > Maybe a temporary here too > Yup > > +int altera_gpio_probe(struct platform_device *pdev) > > +{ > > + struct device_node *node = pdev->dev.of_node; > > + int id, reg, ret; > > + struct altera_gpio_chip *altera_gc; > > + > > + altera_gc = devm_kzalloc(&pdev->dev, sizeof(*altera_gc), GFP_KERNEL); > > + > > + if (altera_gc == NULL) > > + return -ENOMEM; > > No blank line after the devm_kzalloc please and > if (!altera_gc) > is more common. > > OK noted. > > + if (altera_gc->interrupt_trigger == IRQ_TYPE_LEVEL_HIGH) { > > + gpiochip_set_chained_irqchip(&altera_gc->mmchip.gc, > > + &altera_irq_chip, > > + altera_gc->mapped_irq, > > + altera_gpio_irq_leveL_high_handler); > > + } else { > > + gpiochip_set_chained_irqchip(&altera_gc->mmchip.gc, > > + &altera_irq_chip, > > + altera_gc->mapped_irq, > > + altera_gpio_irq_edge_handler); > > + } > > Sometimes using a ?: ternary is smaller code > > gpiochip_set_chained_irqchip(&altera_gc->mmchip.gc, > &altera_irq_chip, > altera_gc->mapped_irq, > altera_gc->interrupt_trigger == IRQ_TYPE_LEVEL_HIGH ? > altera_gpio_irq_leveL_high_handler : > altera_gpio_irq_edge_handler); > > > Yup I'll fix it. Regards, Tien Hock Loh