Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2061979imm; Thu, 20 Sep 2018 07:14:13 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYmcO4SVkngQJgg1AwdmlgkzN4D1VsMc2lZdeHsc3oHL7POKvKf8a95TfLHQtVUiopTm3Ep X-Received: by 2002:a65:5004:: with SMTP id f4-v6mr36831283pgo.54.1537452853545; Thu, 20 Sep 2018 07:14:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537452853; cv=none; d=google.com; s=arc-20160816; b=chpz7ggNWuuJu1Ov5FyV+lreWWpW79BiYn3kGfTNb4AkkMEqIQf94+U1tyLd6AybIX Y6wKfBAJzUyUaN5lOM+07uZsRqVqm6L23U1tWx00troXElgFAeOzRu6h+goq7q41wdfG PVS2eTwK3JB/NCEbaNH7CIyocnbJLvNFz1ZrpZGLD7levgCUMvnzTs0XrO8zX637K5ML AMHO2EI+q9lyC0goAK5BiQJ5YB+HSi9Kt6hU2N7rc33etogzMUSqidFs5KVLFA+IVkGf vwiq+PGuf7gBMqUETPI26t6so+kIQNfDucZPL9oCSxrENF5U2oYvc+hXokxc88EQ2JjX S5Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=1JtLa/hPzw18CLuTQT1vZviWf3qDAnLsnAB2VOYhU6Y=; b=AETx0NMEEi4G0PLYrjiJ1cUuVU7BYYwHIvf2ncMEl4isdvtH7tFKtqOm3aiTmYFvVS 3oSoTEpWk2gEITSCaRxNYcq4eBngOL4IV+SM8t9L3zELaeHZpfCRRSmpCfo0kyAISNUg KHG5QTU6UuSxi4oAtf1z8zJOx0vuWuqOtaKGDGHsrWqJtHz89K/35hUtajZ1toBUdFU5 0ZXe4/tfXpBLYfpApwvtYIGIR9HJhqfM6Pz2f4MKh1fBhwJuYtO26ljM3eCnyoamLOSs j7s79ewPnOygfRRNUkoPfzAjzyl5lZIK1OLR9pnj6KPnAB6nNJOldiB8txt2A5CZC1Tj xPZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lhZI6NQ5; 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 x7-v6si23791539pgh.595.2018.09.20.07.13.57; Thu, 20 Sep 2018 07:14:13 -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=lhZI6NQ5; 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 S1732980AbeITT5J (ORCPT + 99 others); Thu, 20 Sep 2018 15:57:09 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:45417 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731223AbeITT5I (ORCPT ); Thu, 20 Sep 2018 15:57:08 -0400 Received: by mail-pg1-f193.google.com with SMTP id w9-v6so1305615pgc.12; Thu, 20 Sep 2018 07:13:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=1JtLa/hPzw18CLuTQT1vZviWf3qDAnLsnAB2VOYhU6Y=; b=lhZI6NQ50jSMGfaPlZ2Eo3rORRm8InvWQKm7uZGDBQn42zbcSv5zynLMNDm1T4f84+ KcyftXvilYqvmGAsbj+Ahiv0uU+NV+NAzIPD95BxI2gGJoqdmTrWKwTsKS+P5EaEIC6t 1mlO/U834BaG33Z6Ydx/HCxFxTWIHhJ2XBG+Zq7kg6Jy+7Jwb+J0r4CcZUex0AjrL1Gx IFvu+J4gLgG4aV05lUEaVGZj12/yQC17STjgR693s26SPL5k0O+/QHBYjxOs3RWAwwEs H8ODNVrjs6E40+ftgO+p7xrDYs+JhHVOBoQNvx8QSTTYrQYWuJmLVqMltuL68X0KpMCI s9fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=1JtLa/hPzw18CLuTQT1vZviWf3qDAnLsnAB2VOYhU6Y=; b=r6IQ5bw93v4BsyR553YTTG0CXhP9T40+zxVBDvb6foefprudHfuiNm1+BgJ7D15Ekp dwHUOrp9Y9cbzeVQkzSgLGcdjeHCEenlUMOsqvCqaSd0294BxfgXFyoKEnpdOAfoG2l8 MEPu621bG7iE05fyGcmNnMJtp40bnJbzV+0n09A5o5EOfH3n7yBr4XnAfUhUYyoPHbJ3 46iqUlDTU1nMBnWqeaaWrjlzrMsMUnF/SyXv70fP6ejK1pDCWLvxDXF0yQSvqyuSb3M7 zhTJ0HCiQi5U9EfYW5ZjebvCme1e82Er8gyDZIFaPP9VYkcyAkYBtrF3UJIq2MJ5U6gU /EeQ== X-Gm-Message-State: APzg51DNO1QVGsJgVAiCH0nyTBpFxpX8I6qorzWoaiPJM6lqfzOl2iTK vE694/aFY82K5kLfG/QH2dY= X-Received: by 2002:a62:2119:: with SMTP id h25-v6mr42241161pfh.112.1537452807320; Thu, 20 Sep 2018 07:13:27 -0700 (PDT) Received: from localhost (104.176.229.35.bc.googleusercontent.com. [35.229.176.104]) by smtp.gmail.com with ESMTPSA id m27-v6sm33628100pff.152.2018.09.20.07.13.26 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Sep 2018 07:13:26 -0700 (PDT) From: Song Qiang To: jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, shubhrajyoti@ti.com Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Song Qiang Subject: [PATCH] iio: magnetometer: hmc5843: Clean up redundant code. Date: Thu, 20 Sep 2018 22:13:21 +0800 Message-Id: <20180920141321.15251-1-songqiang1304521@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Regmap tables are both defined in hmc5843_spi.c and hmc5843_i2c.c, while the only difference between these two set of tables is SPI need a read mask, which is set only in 'regmap_config' structrue. This patch moves the other structrues into hmc5843_core.c to reduce redundance. Signed-off-by: Song Qiang --- drivers/iio/magnetometer/hmc5843.h | 4 ++++ drivers/iio/magnetometer/hmc5843_core.c | 28 +++++++++++++++++++++++++ drivers/iio/magnetometer/hmc5843_i2c.c | 27 ------------------------ drivers/iio/magnetometer/hmc5843_spi.c | 27 ------------------------ 4 files changed, 32 insertions(+), 54 deletions(-) diff --git a/drivers/iio/magnetometer/hmc5843.h b/drivers/iio/magnetometer/hmc5843.h index 76a5d7484d8d..0ab400f27c97 100644 --- a/drivers/iio/magnetometer/hmc5843.h +++ b/drivers/iio/magnetometer/hmc5843.h @@ -46,6 +46,10 @@ struct hmc5843_data { __be16 buffer[8]; }; +extern const struct regmap_access_table hmc5843_readable_table; +extern const struct regmap_access_table hmc5843_writable_table; +extern const struct regmap_access_table hmc5843_volatile_table; + int hmc5843_common_probe(struct device *dev, struct regmap *regmap, enum hmc5843_ids id, const char *name); int hmc5843_common_remove(struct device *dev); diff --git a/drivers/iio/magnetometer/hmc5843_core.c b/drivers/iio/magnetometer/hmc5843_core.c index ada142fb7aa3..a18e6d89f42a 100644 --- a/drivers/iio/magnetometer/hmc5843_core.c +++ b/drivers/iio/magnetometer/hmc5843_core.c @@ -92,6 +92,34 @@ static const char *const hmc5843_meas_conf_modes[] = {"normal", "positivebias", static const char *const hmc5983_meas_conf_modes[] = {"normal", "positivebias", "negativebias", "disabled"}; + +static const struct regmap_range hmc5843_readable_ranges[] = { + regmap_reg_range(0, HMC5843_ID_END), +}; + +const struct regmap_access_table hmc5843_readable_table = { + .yes_ranges = hmc5843_readable_ranges, + .n_yes_ranges = ARRAY_SIZE(hmc5843_readable_ranges), +}; + +static const struct regmap_range hmc5843_writable_ranges[] = { + regmap_reg_range(0, HMC5843_MODE_REG), +}; + +const struct regmap_access_table hmc5843_writable_table = { + .yes_ranges = hmc5843_writable_ranges, + .n_yes_ranges = ARRAY_SIZE(hmc5843_writable_ranges), +}; + +static const struct regmap_range hmc5843_volatile_ranges[] = { + regmap_reg_range(HMC5843_DATA_OUT_MSB_REGS, HMC5843_STATUS_REG), +}; + +const struct regmap_access_table hmc5843_volatile_table = { + .yes_ranges = hmc5843_volatile_ranges, + .n_yes_ranges = ARRAY_SIZE(hmc5843_volatile_ranges), +}; + /* Scaling factors: 10000000/Gain */ static const int hmc5843_regval_to_nanoscale[] = { 6173, 7692, 10309, 12821, 18868, 21739, 25641, 35714 diff --git a/drivers/iio/magnetometer/hmc5843_i2c.c b/drivers/iio/magnetometer/hmc5843_i2c.c index 3de7f4426ac4..a2c45a23e3c9 100644 --- a/drivers/iio/magnetometer/hmc5843_i2c.c +++ b/drivers/iio/magnetometer/hmc5843_i2c.c @@ -17,33 +17,6 @@ #include "hmc5843.h" -static const struct regmap_range hmc5843_readable_ranges[] = { - regmap_reg_range(0, HMC5843_ID_END), -}; - -static const struct regmap_access_table hmc5843_readable_table = { - .yes_ranges = hmc5843_readable_ranges, - .n_yes_ranges = ARRAY_SIZE(hmc5843_readable_ranges), -}; - -static const struct regmap_range hmc5843_writable_ranges[] = { - regmap_reg_range(0, HMC5843_MODE_REG), -}; - -static const struct regmap_access_table hmc5843_writable_table = { - .yes_ranges = hmc5843_writable_ranges, - .n_yes_ranges = ARRAY_SIZE(hmc5843_writable_ranges), -}; - -static const struct regmap_range hmc5843_volatile_ranges[] = { - regmap_reg_range(HMC5843_DATA_OUT_MSB_REGS, HMC5843_STATUS_REG), -}; - -static const struct regmap_access_table hmc5843_volatile_table = { - .yes_ranges = hmc5843_volatile_ranges, - .n_yes_ranges = ARRAY_SIZE(hmc5843_volatile_ranges), -}; - static const struct regmap_config hmc5843_i2c_regmap_config = { .reg_bits = 8, .val_bits = 8, diff --git a/drivers/iio/magnetometer/hmc5843_spi.c b/drivers/iio/magnetometer/hmc5843_spi.c index 535f03a70d63..19541f5bb38f 100644 --- a/drivers/iio/magnetometer/hmc5843_spi.c +++ b/drivers/iio/magnetometer/hmc5843_spi.c @@ -14,33 +14,6 @@ #include "hmc5843.h" -static const struct regmap_range hmc5843_readable_ranges[] = { - regmap_reg_range(0, HMC5843_ID_END), -}; - -static const struct regmap_access_table hmc5843_readable_table = { - .yes_ranges = hmc5843_readable_ranges, - .n_yes_ranges = ARRAY_SIZE(hmc5843_readable_ranges), -}; - -static const struct regmap_range hmc5843_writable_ranges[] = { - regmap_reg_range(0, HMC5843_MODE_REG), -}; - -static const struct regmap_access_table hmc5843_writable_table = { - .yes_ranges = hmc5843_writable_ranges, - .n_yes_ranges = ARRAY_SIZE(hmc5843_writable_ranges), -}; - -static const struct regmap_range hmc5843_volatile_ranges[] = { - regmap_reg_range(HMC5843_DATA_OUT_MSB_REGS, HMC5843_STATUS_REG), -}; - -static const struct regmap_access_table hmc5843_volatile_table = { - .yes_ranges = hmc5843_volatile_ranges, - .n_yes_ranges = ARRAY_SIZE(hmc5843_volatile_ranges), -}; - static const struct regmap_config hmc5843_spi_regmap_config = { .reg_bits = 8, .val_bits = 8, -- 2.17.1