linux/drivers/mfd/smsc-ece1099.c
<<
>>
Prefs
   1/*
   2 * TI SMSC MFD Driver
   3 *
   4 * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com
   5 *
   6 * Author: Sourav Poddar <sourav.poddar@ti.com>
   7 *
   8 *  This program is free software; you can redistribute it and/or modify it
   9 *  under  the terms of the GNU General  Public License as published by the
  10 *  Free Software Foundation;  GPL v2.
  11 *
  12 */
  13
  14#include <linux/module.h>
  15#include <linux/moduleparam.h>
  16#include <linux/init.h>
  17#include <linux/slab.h>
  18#include <linux/i2c.h>
  19#include <linux/gpio.h>
  20#include <linux/workqueue.h>
  21#include <linux/irq.h>
  22#include <linux/regmap.h>
  23#include <linux/err.h>
  24#include <linux/mfd/core.h>
  25#include <linux/mfd/smsc.h>
  26#include <linux/of_platform.h>
  27
  28static struct regmap_config smsc_regmap_config = {
  29                .reg_bits = 8,
  30                .val_bits = 8,
  31                .max_register = SMSC_VEN_ID_H,
  32                .cache_type = REGCACHE_RBTREE,
  33};
  34
  35static int smsc_i2c_probe(struct i2c_client *i2c,
  36                        const struct i2c_device_id *id)
  37{
  38        struct smsc *smsc;
  39        int devid, rev, venid_l, venid_h;
  40        int ret = 0;
  41
  42        smsc = devm_kzalloc(&i2c->dev, sizeof(struct smsc),
  43                                GFP_KERNEL);
  44        if (!smsc) {
  45                dev_err(&i2c->dev, "smsc mfd driver memory allocation failed\n");
  46                return -ENOMEM;
  47        }
  48
  49        smsc->regmap = devm_regmap_init_i2c(i2c, &smsc_regmap_config);
  50        if (IS_ERR(smsc->regmap)) {
  51                ret = PTR_ERR(smsc->regmap);
  52                goto err;
  53        }
  54
  55        i2c_set_clientdata(i2c, smsc);
  56        smsc->dev = &i2c->dev;
  57
  58#ifdef CONFIG_OF
  59        of_property_read_u32(i2c->dev.of_node, "clock", &smsc->clk);
  60#endif
  61
  62        regmap_read(smsc->regmap, SMSC_DEV_ID, &devid);
  63        regmap_read(smsc->regmap, SMSC_DEV_REV, &rev);
  64        regmap_read(smsc->regmap, SMSC_VEN_ID_L, &venid_l);
  65        regmap_read(smsc->regmap, SMSC_VEN_ID_H, &venid_h);
  66
  67        dev_info(&i2c->dev, "SMSCxxx devid: %02x rev: %02x venid: %02x\n",
  68                devid, rev, (venid_h << 8) | venid_l);
  69
  70        ret = regmap_write(smsc->regmap, SMSC_CLK_CTRL, smsc->clk);
  71        if (ret)
  72                goto err;
  73
  74#ifdef CONFIG_OF
  75        if (i2c->dev.of_node)
  76                ret = of_platform_populate(i2c->dev.of_node,
  77                                           NULL, NULL, &i2c->dev);
  78#endif
  79
  80err:
  81        return ret;
  82}
  83
  84static int smsc_i2c_remove(struct i2c_client *i2c)
  85{
  86        struct smsc *smsc = i2c_get_clientdata(i2c);
  87
  88        mfd_remove_devices(smsc->dev);
  89
  90        return 0;
  91}
  92
  93static const struct i2c_device_id smsc_i2c_id[] = {
  94        { "smscece1099", 0},
  95        {},
  96};
  97MODULE_DEVICE_TABLE(i2c, smsc_i2c_id);
  98
  99static struct i2c_driver smsc_i2c_driver = {
 100        .driver = {
 101                   .name = "smsc",
 102                   .owner = THIS_MODULE,
 103        },
 104        .probe = smsc_i2c_probe,
 105        .remove = smsc_i2c_remove,
 106        .id_table = smsc_i2c_id,
 107};
 108
 109module_i2c_driver(smsc_i2c_driver);
 110
 111MODULE_AUTHOR("Sourav Poddar <sourav.poddar@ti.com>");
 112MODULE_DESCRIPTION("SMSC chip multi-function driver");
 113MODULE_LICENSE("GPL v2");
 114
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.