From: "Samuel Iglesias Gonsálvez" <siglesias@igalia.com> To: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, industrypack-devel@lists.sourceforge.net, "Jens Taprogge" <jens.taprogge@taprogge.org>, "Samuel Iglesias Gonsálvez" <siglesias@igalia.com> Subject: [PATCH 14/16] Staging: ipack: Implement device matching on the bus level. Date: Tue, 4 Sep 2012 17:01:19 +0200 [thread overview] Message-ID: <1346770881-4723-15-git-send-email-siglesias@igalia.com> (raw) In-Reply-To: <1346770881-4723-1-git-send-email-siglesias@igalia.com> From: Jens Taprogge <jens.taprogge@taprogge.org> Devices are match based upon their vendor and device ids. Since the individual drivers provide a list of supported ids they do not need to implement the matching themselves. Signed-off-by: Jens Taprogge <jens.taprogge@taprogge.org> Signed-off-by: Samuel Iglesias Gonsálvez <siglesias@igalia.com> --- drivers/staging/ipack/devices/ipoctal.c | 24 +---------------- drivers/staging/ipack/ipack.c | 43 ++++++++++++++++++++++++------- drivers/staging/ipack/ipack.h | 2 -- 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/drivers/staging/ipack/devices/ipoctal.c b/drivers/staging/ipack/devices/ipoctal.c index 829b887..c94a9df 100644 --- a/drivers/staging/ipack/devices/ipoctal.c +++ b/drivers/staging/ipack/devices/ipoctal.c @@ -777,27 +777,6 @@ static const struct tty_operations ipoctal_fops = { .hangup = ipoctal_hangup, }; -static int ipoctal_match(struct ipack_device *dev) -{ - int res; - unsigned char board_id; - - if ((!dev->bus->ops) || (!dev->bus->ops->map_space) || - (!dev->bus->ops->unmap_space)) - return 0; - - res = dev->bus->ops->map_space(dev, 0, IPACK_ID_SPACE); - if (res) - return 0; - - res = ipoctal_check_model(dev, &board_id); - dev->bus->ops->unmap_space(dev, IPACK_ID_SPACE); - if (!res) - return 1; - - return 0; -} - static int ipoctal_probe(struct ipack_device *dev) { int res; @@ -858,8 +837,7 @@ static DEFINE_IPACK_DEVICE_TABLE(ipoctal_ids) = { MODULE_DEVICE_TABLE(ipack, ipoctal_ids); static const struct ipack_driver_ops ipoctal_drv_ops = { - .match = ipoctal_match, - .probe = ipoctal_probe, + .probe = ipoctal_probe, .remove = ipoctal_remove, }; diff --git a/drivers/staging/ipack/ipack.c b/drivers/staging/ipack/ipack.c index 9474226..a328629 100644 --- a/drivers/staging/ipack/ipack.c +++ b/drivers/staging/ipack/ipack.c @@ -26,20 +26,43 @@ static void ipack_device_release(struct device *dev) kfree(device); } -static int ipack_bus_match(struct device *device, struct device_driver *driver) +static inline const struct ipack_device_id * +ipack_match_one_device(const struct ipack_device_id *id, + const struct ipack_device *device) { - int ret; - struct ipack_device *dev = to_ipack_dev(device); - struct ipack_driver *drv = to_ipack_driver(driver); + if ((id->format == IPACK_ANY_ID || id->format == device->id_format) && + (id->vendor == IPACK_ANY_ID || id->vendor == device->id_vendor) && + (id->device == IPACK_ANY_ID || id->device == device->id_device)) + return id; + return NULL; +} - if ((!drv->ops) || (!drv->ops->match)) - return -EINVAL; +static const struct ipack_device_id * +ipack_match_id(const struct ipack_device_id *ids, struct ipack_device *idev) +{ + if (ids) { + while (ids->vendor || ids->device) { + if (ipack_match_one_device(ids, idev)) + return ids; + ids++; + } + } + return NULL; +} - ret = drv->ops->match(dev); - if (ret) - dev->driver = drv; +static int ipack_bus_match(struct device *dev, struct device_driver *drv) +{ + struct ipack_device *idev = to_ipack_dev(dev); + struct ipack_driver *idrv = to_ipack_driver(drv); + const struct ipack_device_id *found_id; - return ret; + found_id = ipack_match_id(idrv->id_table, idev); + if (found_id) { + idev->driver = idrv; + return 1; + } + + return 0; } static int ipack_bus_probe(struct device *device) diff --git a/drivers/staging/ipack/ipack.h b/drivers/staging/ipack/ipack.h index e6e38e7..0f482fd 100644 --- a/drivers/staging/ipack/ipack.h +++ b/drivers/staging/ipack/ipack.h @@ -84,13 +84,11 @@ struct ipack_device { /** * struct ipack_driver_ops -- callbacks to mezzanine driver for installing/removing one device * - * @match: Match function * @probe: Probe function * @remove: tell the driver that the carrier board wants to remove one device */ struct ipack_driver_ops { - int (*match) (struct ipack_device *dev); int (*probe) (struct ipack_device *dev); void (*remove) (struct ipack_device *dev); }; -- 1.7.10.4
next prev parent reply other threads:[~2012-09-04 15:12 UTC|newest] Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top 2012-09-04 15:01 [PATCH 00/16] ipack: autoload IP module drivers Samuel Iglesias Gonsálvez 2012-09-04 15:01 ` [PATCH 01/16] Staging: ipack/bridges/tpci200: Reorganize tpci200_probe in preparation for functional changes Samuel Iglesias Gonsálvez 2012-09-04 15:01 ` [PATCH 02/16] Staging: ipack/bridges/tpci200: Use the TPCI200 in big endian mode Samuel Iglesias Gonsálvez 2012-09-04 15:01 ` [PATCH 03/16] Staging: ipack/devices/ipoctal: Convert ipoctal to directly use ioread/write functions Samuel Iglesias Gonsálvez 2012-09-04 15:01 ` [PATCH 04/16] Staging: ipack/bridges/tpci200: Remove the read/write functions from ipack_bus_ops Samuel Iglesias Gonsálvez 2012-09-04 15:01 ` [PATCH 05/16] Staging: ipack: remove read/write operations " Samuel Iglesias Gonsálvez 2012-09-04 15:01 ` [PATCH 06/16] Staging: ipack/devices/ipoctal: ipoctal cleanups Samuel Iglesias Gonsálvez 2012-09-04 15:01 ` [PATCH 07/16] Staging: ipack/devices/ipoctal: Tidy up ipoctal some more Samuel Iglesias Gonsálvez 2012-09-04 15:01 ` [PATCH 08/16] Staging: ipack: implement ipack device table Samuel Iglesias Gonsálvez 2012-09-04 15:01 ` [PATCH 09/16] Staging: ipack: Read the ID space during device registration Samuel Iglesias Gonsálvez 2012-09-04 15:01 ` [PATCH 10/16] Staging: ipack: Parse vendor and device id Samuel Iglesias Gonsálvez 2012-09-04 15:01 ` [PATCH 11/16] Staging: ipack: Move device ids from ipoctal.c to ipack_ids.h Samuel Iglesias Gonsálvez 2012-09-04 15:01 ` [PATCH 12/16] Staging: ipack: Make ipack_driver_ops const Samuel Iglesias Gonsálvez 2012-09-04 15:01 ` [PATCH 13/16] Staging: ipack/devices/ipoctal: Expose DEVICE_TABLE for ipoctal Samuel Iglesias Gonsálvez 2012-09-04 15:01 ` Samuel Iglesias Gonsálvez [this message] 2012-09-04 15:01 ` [PATCH 15/16] Staging: ipack: Expose modalias through sysfs Samuel Iglesias Gonsálvez 2012-09-04 15:01 ` [PATCH 16/16] Staging: ipack: Provide ID Prom " Samuel Iglesias Gonsálvez
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1346770881-4723-15-git-send-email-siglesias@igalia.com \ --to=siglesias@igalia.com \ --cc=devel@driverdev.osuosl.org \ --cc=gregkh@linuxfoundation.org \ --cc=industrypack-devel@lists.sourceforge.net \ --cc=jens.taprogge@taprogge.org \ --cc=linux-kernel@vger.kernel.org \ --subject='Re: [PATCH 14/16] Staging: ipack: Implement device matching on the bus level.' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).