From patchwork Wed Dec 26 13:05:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 208168 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B97C82C00B5 for ; Thu, 27 Dec 2012 00:06:26 +1100 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Tnqfr-0007Ld-45; Wed, 26 Dec 2012 13:05:31 +0000 Received: from mail-ea0-f171.google.com ([209.85.215.171]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Tnqfp-0007LL-3T for linux-mtd@lists.infradead.org; Wed, 26 Dec 2012 13:05:29 +0000 Received: by mail-ea0-f171.google.com with SMTP id n10so3568500eaa.16 for ; Wed, 26 Dec 2012 05:05:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer; bh=7k0JfCk4XZFfghBD0WD3AZbakyyx5bydeQ0KiP67eew=; b=mifkfPa8zYc3CWATAcsiWiwfc97xi/DQWev8eUwxQA2hlhTsaX2mANzX1cMe+g3cbj YBiaDXUFghxsbTCg97dDVVzJs+MmpaImHTRQTlv03WWE2w+Xha3y5Gxh49CL71quyS0Y L+4cIQdL84RIzIMIqaS8IruFtC99OqekQK52QT+Y6r2KT2entFX0k7QNhJvYTTinRgN/ w2CTV4PnRNB4soyPGqJ1ijOTU6qQmdyYHgkSZ5inEwQc+SMySCgY8bFS/DbqWpCPf6au Wk7wCu0ZbKoaonT6vt+hwiyRLRx93+bF+4Oyrb3uPk+YeWhhy1b/XX+rzPVMd0SpMqet YQmg== X-Received: by 10.14.209.193 with SMTP id s41mr70248890eeo.9.1356527126817; Wed, 26 Dec 2012 05:05:26 -0800 (PST) Received: from localhost.localdomain (egr183.neoplus.adsl.tpnet.pl. [83.21.81.183]) by mx.google.com with ESMTPS id 6sm53122950eea.3.2012.12.26.05.05.24 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 26 Dec 2012 05:05:25 -0800 (PST) From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= To: linux-mtd@lists.infradead.org Subject: [RFC][PATCH] mtd: bcm47xxsflash: add own struct for abstrating bus type Date: Wed, 26 Dec 2012 14:05:22 +0100 Message-Id: <1356527122-32137-1-git-send-email-zajec5@gmail.com> X-Mailer: git-send-email 1.7.7 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121226_080529_375945_3A78D663 X-CRM114-Status: GOOD ( 18.24 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (zajec5[at]gmail.com) -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.215.171 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (zajec5[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Hauke Mehrtens , =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org --- The biggest problem with that seems to be: > b47s->window = sflash->window; > b47s->blocksize = sflash->blocksize; > b47s->numblocks = sflash->numblocks; > b47s->size = sflash->size; In theory we could use some generic struct with that fields and modify bcma to user that generic struct. I'm just not sure if it's worth adding extra struct to just avoid such a 4 lines...? --- drivers/mtd/devices/bcm47xxsflash.c | 37 +++++++++++++++++--------- include/linux/bcma/bcma_driver_chipcommon.h | 1 + 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/drivers/mtd/devices/bcm47xxsflash.c b/drivers/mtd/devices/bcm47xxsflash.c index f293682..13634c3 100644 --- a/drivers/mtd/devices/bcm47xxsflash.c +++ b/drivers/mtd/devices/bcm47xxsflash.c @@ -5,6 +5,8 @@ #include #include +#include "bcm47xxsflash.h" + MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Serial flash driver for BCMA bus"); @@ -13,26 +15,27 @@ static const char *probes[] = { "bcm47xxpart", NULL }; static int bcm47xxsflash_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf) { - struct bcma_sflash *sflash = mtd->priv; + struct bcm47xxsflash *b47s = mtd->priv; /* Check address range */ if ((from + len) > mtd->size) return -EINVAL; - memcpy_fromio(buf, (void __iomem *)KSEG0ADDR(sflash->window + from), + memcpy_fromio(buf, (void __iomem *)KSEG0ADDR(b47s->window + from), len); return len; } -static void bcm47xxsflash_fill_mtd(struct bcma_sflash *sflash, - struct mtd_info *mtd) +static void bcm47xxsflash_fill_mtd(struct bcm47xxsflash *b47s) { - mtd->priv = sflash; + struct mtd_info *mtd = &b47s->mtd; + + mtd->priv = b47s; mtd->name = "bcm47xxsflash"; mtd->owner = THIS_MODULE; mtd->type = MTD_ROM; - mtd->size = sflash->size; + mtd->size = b47s->size; mtd->_read = bcm47xxsflash_read; /* TODO: implement writing support and verify/change following code */ @@ -43,16 +46,23 @@ static void bcm47xxsflash_fill_mtd(struct bcma_sflash *sflash, static int bcm47xxsflash_bcma_probe(struct platform_device *pdev) { struct bcma_sflash *sflash = dev_get_platdata(&pdev->dev); + struct bcm47xxsflash *b47s; int err; - sflash->mtd = kzalloc(sizeof(struct mtd_info), GFP_KERNEL); - if (!sflash->mtd) { + b47s = kzalloc(sizeof(*b47s), GFP_KERNEL); + if (!b47s) { err = -ENOMEM; goto out; } - bcm47xxsflash_fill_mtd(sflash, sflash->mtd); + sflash->priv = b47s; + + b47s->window = sflash->window; + b47s->blocksize = sflash->blocksize; + b47s->numblocks = sflash->numblocks; + b47s->size = sflash->size; + bcm47xxsflash_fill_mtd(b47s); - err = mtd_device_parse_register(sflash->mtd, probes, NULL, NULL, 0); + err = mtd_device_parse_register(&b47s->mtd, probes, NULL, NULL, 0); if (err) { pr_err("Failed to register MTD device: %d\n", err); goto err_dev_reg; @@ -61,7 +71,7 @@ static int bcm47xxsflash_bcma_probe(struct platform_device *pdev) return 0; err_dev_reg: - kfree(sflash->mtd); + kfree(&b47s->mtd); out: return err; } @@ -69,9 +79,10 @@ out: static int bcm47xxsflash_bcma_remove(struct platform_device *pdev) { struct bcma_sflash *sflash = dev_get_platdata(&pdev->dev); + struct bcm47xxsflash *b47s = sflash->priv; - mtd_device_unregister(sflash->mtd); - kfree(sflash->mtd); + mtd_device_unregister(&b47s->mtd); + kfree(b47s); return 0; } diff --git a/include/linux/bcma/bcma_driver_chipcommon.h b/include/linux/bcma/bcma_driver_chipcommon.h index 1cfd613..aa3be07 100644 --- a/include/linux/bcma/bcma_driver_chipcommon.h +++ b/include/linux/bcma/bcma_driver_chipcommon.h @@ -532,6 +532,7 @@ struct bcma_sflash { u32 size; struct mtd_info *mtd; + void *priv; }; #endif