linux-old/drivers/mtd/chips/chipreg.c
<<
>>
Prefs
   1/*
   2 * $Id: chipreg.c,v 1.13 2002/02/21 08:26:58 dwmw2 Exp $
   3 *
   4 * Registration for chip drivers
   5 *
   6 */
   7
   8#include <linux/kernel.h>
   9#include <linux/config.h>
  10#include <linux/kmod.h>
  11#include <linux/spinlock.h>
  12#include <linux/mtd/compatmac.h>
  13#include <linux/mtd/map.h>
  14
  15spinlock_t chip_drvs_lock = SPIN_LOCK_UNLOCKED;
  16static LIST_HEAD(chip_drvs_list);
  17
  18void register_mtd_chip_driver(struct mtd_chip_driver *drv)
  19{
  20        spin_lock(&chip_drvs_lock);
  21        list_add(&drv->list, &chip_drvs_list);
  22        spin_unlock(&chip_drvs_lock);
  23}
  24
  25void unregister_mtd_chip_driver(struct mtd_chip_driver *drv)
  26{
  27        spin_lock(&chip_drvs_lock);
  28        list_del(&drv->list);
  29        spin_unlock(&chip_drvs_lock);
  30}
  31
  32static struct mtd_chip_driver *get_mtd_chip_driver (const char *name)
  33{
  34        struct list_head *pos;
  35        struct mtd_chip_driver *ret = NULL, *this;
  36
  37        spin_lock(&chip_drvs_lock);
  38
  39        list_for_each(pos, &chip_drvs_list) {
  40                this = list_entry(pos, typeof(*this), list);
  41                
  42                if (!strcmp(this->name, name)) {
  43                        ret = this;
  44                        break;
  45                }
  46        }
  47        if (ret && !try_inc_mod_count(ret->module)) {
  48                /* Eep. Failed. */
  49                ret = NULL;
  50        }
  51
  52        spin_unlock(&chip_drvs_lock);
  53
  54        return ret;
  55}
  56
  57        /* Hide all the horrid details, like some silly person taking
  58           get_module_symbol() away from us, from the caller. */
  59
  60struct mtd_info *do_map_probe(const char *name, struct map_info *map)
  61{
  62        struct mtd_chip_driver *drv;
  63        struct mtd_info *ret;
  64
  65        drv = get_mtd_chip_driver(name);
  66
  67        if (!drv && !request_module(name))
  68                drv = get_mtd_chip_driver(name);
  69
  70        if (!drv)
  71                return NULL;
  72
  73        ret = drv->probe(map);
  74#ifdef CONFIG_MODULES
  75        /* We decrease the use count here. It may have been a 
  76           probe-only module, which is no longer required from this
  77           point, having given us a handle on (and increased the use
  78           count of) the actual driver code.
  79        */
  80        if(drv->module)
  81                __MOD_DEC_USE_COUNT(drv->module);
  82#endif
  83
  84        if (ret)
  85                return ret;
  86        
  87        return NULL;
  88}
  89
  90EXPORT_SYMBOL(register_mtd_chip_driver);
  91EXPORT_SYMBOL(unregister_mtd_chip_driver);
  92EXPORT_SYMBOL(do_map_probe);
  93
  94MODULE_LICENSE("GPL");
  95MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
  96MODULE_DESCRIPTION("Core routines for registering and invoking MTD chip drivers");
  97