smsc-ece1099.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #include <linux/init.h>
  14. #include <linux/slab.h>
  15. #include <linux/i2c.h>
  16. #include <linux/gpio.h>
  17. #include <linux/workqueue.h>
  18. #include <linux/irq.h>
  19. #include <linux/regmap.h>
  20. #include <linux/err.h>
  21. #include <linux/mfd/core.h>
  22. #include <linux/mfd/smsc.h>
  23. #include <linux/of_platform.h>
  24. static const struct regmap_config smsc_regmap_config = {
  25. .reg_bits = 8,
  26. .val_bits = 8,
  27. .max_register = SMSC_VEN_ID_H,
  28. .cache_type = REGCACHE_RBTREE,
  29. };
  30. static int smsc_i2c_probe(struct i2c_client *i2c,
  31. const struct i2c_device_id *id)
  32. {
  33. struct smsc *smsc;
  34. int devid, rev, venid_l, venid_h;
  35. int ret;
  36. smsc = devm_kzalloc(&i2c->dev, sizeof(*smsc), GFP_KERNEL);
  37. if (!smsc)
  38. return -ENOMEM;
  39. smsc->regmap = devm_regmap_init_i2c(i2c, &smsc_regmap_config);
  40. if (IS_ERR(smsc->regmap))
  41. return PTR_ERR(smsc->regmap);
  42. i2c_set_clientdata(i2c, smsc);
  43. smsc->dev = &i2c->dev;
  44. #ifdef CONFIG_OF
  45. of_property_read_u32(i2c->dev.of_node, "clock", &smsc->clk);
  46. #endif
  47. regmap_read(smsc->regmap, SMSC_DEV_ID, &devid);
  48. regmap_read(smsc->regmap, SMSC_DEV_REV, &rev);
  49. regmap_read(smsc->regmap, SMSC_VEN_ID_L, &venid_l);
  50. regmap_read(smsc->regmap, SMSC_VEN_ID_H, &venid_h);
  51. dev_info(&i2c->dev, "SMSCxxx devid: %02x rev: %02x venid: %02x\n",
  52. devid, rev, (venid_h << 8) | venid_l);
  53. ret = regmap_write(smsc->regmap, SMSC_CLK_CTRL, smsc->clk);
  54. if (ret)
  55. return ret;
  56. #ifdef CONFIG_OF
  57. if (i2c->dev.of_node)
  58. ret = devm_of_platform_populate(&i2c->dev);
  59. #endif
  60. return ret;
  61. }
  62. static const struct i2c_device_id smsc_i2c_id[] = {
  63. { "smscece1099", 0},
  64. {},
  65. };
  66. static struct i2c_driver smsc_i2c_driver = {
  67. .driver = {
  68. .name = "smsc",
  69. },
  70. .probe = smsc_i2c_probe,
  71. .id_table = smsc_i2c_id,
  72. };
  73. builtin_i2c_driver(smsc_i2c_driver);