Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2301306imm; Wed, 16 May 2018 10:44:33 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoOqMOVKpFWPVLfAcwqqpDFwH7dOdMevAZLumF+bIaTnKLACzCuauQblgTkyIIQDPzAqLHa X-Received: by 2002:a17:902:7288:: with SMTP id d8-v6mr1882311pll.218.1526492673794; Wed, 16 May 2018 10:44:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526492673; cv=none; d=google.com; s=arc-20160816; b=njBFwHN9PLk+Yvr3YjAyMFECdFkW7MVf/yX4Ak5iUV1o/w4f/2KWAeN+3eQAaHrj+0 PHhvcidHD/qJ8HluCRo0i6kIMUqEoAM+jajIC8z+L1rjYXZB2YmcUTOSbFP8rETQyGLb wYehe33XuWpSiUkETZIBZzOzxZenN0ojbbjYqnxb8S4OPwvSwE6+CTf1fba58b+MW61R CGvP3wlnhgq7YiP3IIv12n62GjaeyuIyDnPPemAh8UqhOE69dbXCMlYbZe8E2pIk5da5 +DeOakXfVj91qyYlSrlRypttALXgonA2VnhaYVRts163Ars4/Siu6G1Pi7elaKcuu1Qo UsqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=YHlC1plteeK5/MmAMLCuQyFm8w61MBvLkP8xOhncFAY=; b=YDOssdSwCpJ7bTjSPw/cyuzQKLmetZJV3daYtisrfC/VpbfCDTd32Gt12VOf4B/ts7 OO1oBlcZ2SBXxoBTCVgOC1IUgm20adlJvCBakONxqzdY728wptygXg7Xyf38BLOfWX8u uDZZjTaRwo+EDMZgAJA7M8sex791BWp1biJEUO0hfrzoMG3JQrvIYsb/s0UpT3Ezi4UK BoYpcte4j8Vrms09TzpHwI7mY+qQHpW7penim+F7h9cHOhzN1Xu3US6IPY3QUISTPPOK KPnRzgcHEH0sMRgFAEbrFykP5lkmQ4acfao36clKvGsnzjvscuMHImejm63XWNlm41E7 8Q+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=M426CNg8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y62-v6si3227787pfg.246.2018.05.16.10.44.18; Wed, 16 May 2018 10:44:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=M426CNg8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752008AbeEPRoG (ORCPT + 99 others); Wed, 16 May 2018 13:44:06 -0400 Received: from mail-it0-f68.google.com ([209.85.214.68]:40458 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751130AbeEPRoB (ORCPT ); Wed, 16 May 2018 13:44:01 -0400 Received: by mail-it0-f68.google.com with SMTP id j186-v6so4094909ita.5; Wed, 16 May 2018 10:44:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=YHlC1plteeK5/MmAMLCuQyFm8w61MBvLkP8xOhncFAY=; b=M426CNg8R42rlAN6tWLRwcD5abNEzrylIz0I8bTZEjwpK/G7/i7edc2L/ouo3Jeetp PrJJJpiqft0uVMIqy0yz/f/sznVQaRZfZmhB1itEY0yQGo6d9n9ywU5EpgSEaEDMHe4h HagiQI0rD1Y7R0IFk3RS9C96YJOlzHFwWdn1h/1PwCh17tsBkyjg2ICqQcFusH750EAU RBbxVR2yjWXPaEDgVuKko4bsPDuIBHLjYR08ypvE0Wl0B0HrSwBea9i37y43X6fNPRa5 kRImLtuLqEbA8IHhwfmLCgLXPUVUmxVlbv67/0qDPkqHMOiF5r+d4+J86MWZZR4JBO3+ WYIQ== 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:in-reply-to:user-agent; bh=YHlC1plteeK5/MmAMLCuQyFm8w61MBvLkP8xOhncFAY=; b=s7twH5RHjUdIjdhwqEjY61EEHyvk4moieDyhzpCmwJMpf9QgmomEZOh5DjqNDEbHdL LRKp3wofVmmWEuCOh8tRrCDtUbPZoPR6K5WHzSsB34EhnRcomSO0qJN59GXKGCLhGLCO DumSsptGR4uL+Y23SUQBhidTUqfiTvwvFnhQ8Ne962sr05HG0WU7nWLsGQiM4tcKLOZn piUGdhr/5m+YOwKZwW6yAvPxDvEqgkd0LIyheHZaLWP1/8W0z7ZON4iWJ6xndz2cU642 GxykreRYwbXZ0L/jin4GPkQZbVwqcROlihv97UGTaFqusKhCv/bEEb9xIS4KRtpXRhnl YyPg== X-Gm-Message-State: ALKqPwdNCR1yaX4ZFMVw+CjAr3mDhAseVJMidGnEqZymoRwrpUwuJeEC t1AUpz/sYDzFlvfbRNjshhg= X-Received: by 2002:a24:fe44:: with SMTP id w65-v6mr2165796ith.87.1526492640664; Wed, 16 May 2018 10:44:00 -0700 (PDT) Received: from dtor-ws ([2620:0:1000:1511:8de6:27a8:ed13:2ef5]) by smtp.gmail.com with ESMTPSA id f134-v6sm1921221itb.43.2018.05.16.10.43.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 16 May 2018 10:43:59 -0700 (PDT) Date: Wed, 16 May 2018 10:43:57 -0700 From: Dmitry Torokhov To: "Jonas Mark (BT-FIR/ENG1)" Cc: Andy Shevchenko , Rob Herring , Mark Rutland , linux-input , devicetree , Linux Kernel Mailing List , Heiko Schocher , "ZHU Yi (BT-FIR/ENG1-Zhu)" Subject: Re: [PATCH v3] Input: add bu21029 touch driver Message-ID: <20180516174357.GE21971@dtor-ws> References: <1521651874-15379-1-git-send-email-mark.jonas@de.bosch.com> <1526048528-3613-1-git-send-email-mark.jonas@de.bosch.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 16, 2018 at 01:24:24PM +0000, Jonas Mark (BT-FIR/ENG1) wrote: > Hello Andy, > > > > Add Rohm BU21029 resistive touch panel controller support with I2C > > > interface. > > > > > +#include > > > > This becomes redundant (see below). > > Removed. > > > > +#define STOP_DELAY_US 50L > > > +#define START_DELAY_MS 2L > > > +#define BUF_LEN 8L > > > > No need to use L for such small numbers. Integer promotion is a part > > of C standard. > > OK. > > > > +#define SCALE_12BIT (1 << 12) > > > +#define MAX_12BIT ((1 << 12) - 1) > > > > BIT(12) > > GENMASK(11, 0) > > We are not convinced that we should use BIT() and GENMASK() here. > > The reason is that SCALE_12BIT is actually not used as a bit but as an > input value for DIV_ROUND_CLOSEST. We think that the BIT() macro will > hide the meaning of the value. > > MAX_12BIT is also a value and not a bit mask. Thus, we also think that > using the GENMASK() macro will hide its purpose. Also, the > documentation of GENMASK() says that it is a mask and not a value. I agree. > > > > +static int bu21029_touch_report(struct bu21029_ts_data *bu21029) > > > +{ > > > + struct i2c_client *i2c = bu21029->client; > > > + u8 buf[BUF_LEN]; > > > + int error = bu21029_touch_report(bu21029); > > > > > + > > > > Redundant empty line. > > Removed. > > > > + if (error) { > > > > > + dev_err(&i2c->dev, "failed to report (error: %d)\n", error); > > > > Potential spamming case. > > > > > + return IRQ_NONE; > > > + } > > You are right, we will remove the error message. > > > > +static void bu21029_stop_chip(struct input_dev *dev) > > > +{ > > > + struct bu21029_ts_data *bu21029 = input_get_drvdata(dev); > > > + > > > + disable_irq(bu21029->client->irq); > > > + del_timer_sync(&bu21029->timer); > > > + > > > + /* put chip into reset */ > > > + gpiod_set_value_cansleep(bu21029->reset_gpios, 1); > > > > > + udelay(STOP_DELAY_US); > > > > udelay() ?! > > > > > +} > > According to the datasheet disabling the chip will take 30 microseconds. > In the defines we added a buffer of 20 microseconds and thus > STOP_DELAY_US is 50. The function guarantees that the chip is stopped > before it returns. > > We think that it is ok to use udelay() here because in normal operation > the chip is not stopped. It is only stopped when loading or unloading > the driver, or when the system suspends. > > We would like to keep it like it is. The issue is not with having delay here, but the kind of delay you are using: udelay makes CPU spin for given amount of time; you really want msleep() or usleep_range() here. > > > > +static int bu21029_start_chip(struct input_dev *dev) > > > +{ > > > > > + u16 hwid; > > > + > > > + /* take chip out of reset */ > > > + gpiod_set_value_cansleep(bu21029->reset_gpios, 0); > > > > > + mdelay(START_DELAY_MS); > > > > mdelay()?! Same here - replace with msleep(). > > > > > + > > > + error = i2c_smbus_read_i2c_block_data(i2c, > > > + BU21029_HWID_REG, > > > + 2, > > > + (u8 *)&hwid); > > > + if (error < 0) { > > > + dev_err(&i2c->dev, "failed to read HW ID\n"); > > > + goto out; > > > + } > > After de-asserting the reset chip takes 1 millisecond until it is > operational. We added a 1 millisecond buffer to it. Thus, > START_DELAY_MS is 2. > > The following I2C read will not succeed without waiting for the chip > being ready. > > > > + if (cpu_to_be16(hwid) != SUPPORTED_HWID) { > > > > Hmm... Why cpu_to_be16() is required? > > > > > + dev_err(&i2c->dev, "unsupported HW ID 0x%x\n", hwid); > > > + error = -ENODEV; > > > + goto out; > > > + } > > > +} > > You are right, it works but what we meant to do here is to convert the > chip's value (big endian) into the CPU endianness. We will change it to > be16_to_cpu(). > > > > +static int bu21029_parse_dt(struct bu21029_ts_data *bu21029) > > > > You can get rid of DT requirement by... > > > > > +{ > > > + struct device *dev = &bu21029->client->dev; > > > + struct device_node *np = dev->of_node; > > > + u32 val32; > > > + int error; > > > > > + if (!np) { > > > + dev_err(dev, "no device tree data\n"); > > > + return -EINVAL; > > > + } > > > > (this becomes redundant) > > > > > + > > > + bu21029->reset_gpios = devm_gpiod_get(dev, "reset", > > GPIOD_OUT_HIGH); > > > + if (IS_ERR(bu21029->reset_gpios)) { > > > + error = PTR_ERR(bu21029->reset_gpios); > > > + if (error != -EPROBE_DEFER) > > > + dev_err(dev, "invalid 'reset-gpios':%d\n", error); > > > + return error; > > > + } > > > + > > > > > + if (of_property_read_u32(np, "rohm,x-plate-ohms", &val32)) { > > > > ...simple calling device_property_read_u32() instead. > > > > > + dev_err(dev, "invalid 'x-plate-ohms' supplied\n"); > > > + return -EINVAL; > > > + } > > > + bu21029->x_plate_ohms = val32; > > > + > > > + touchscreen_parse_properties(bu21029->in_dev, false, &bu21029->prop); > > > + > > > + return 0; > > > +} > > Thank you, changed. > > > > +#ifdef CONFIG_PM_SLEEP > > > > Instead... > > > > > +static int bu21029_suspend(struct device *dev) > > > > ...use __maby_unused annotation. > > > > > +static int bu21029_resume(struct device *dev) > > > > Ditto. > > OK, added. You also need to drop #ifdef CONFIG_SLEEP. That's the point: we want to reduce amount of conditionally compiled code and use __maybe_unused to shut off compiler warning about some functions not used in certain configurations. We rely on linker to eliminate dead functions from executable. Thanks. -- Dmitry