smsc-ece1099.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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/module.h>
  14. #include <linux/moduleparam.h>
  15. #include <linux/slab.h>
  16. #include <linux/i2c.h>
  17. #include <linux/gpio.h>
  18. #include <linux/workqueue.h>
  19. #include <linux/irq.h>
  20. #include <linux/regmap.h>
  21. #include <linux/err.h>
  22. #include <linux/mfd/core.h>
  23. #include <linux/mfd/smsc.h>
  24. #include <linux/of_platform.h>
  25. static const struct regmap_config smsc_regmap_config = {
  26. .reg_bits = 8,
  27. .val_bits = 8,
  28. .max_register = SMSC_VEN_ID_H,
  29. .cache_type = REGCACHE_RBTREE,
  30. };
  31. static int smsc_i2c_probe(struct i2c_client *i2c,
  32. const struct i2c_device_id *id)
  33. {
  34. struct smsc *smsc;
  35. int devid, rev, venid_l, venid_h;
  36. int ret = 0;
  37. smsc = devm_kzalloc(&i2c->dev, sizeof(struct smsc),
  38. GFP_KERNEL);
  39. if (!smsc) {
  40. dev_err(&i2c->dev, "smsc mfd driver memory allocation failed\n");
  41. return -ENOMEM;
  42. }
  43. smsc->regmap = devm_regmap_init_i2c(i2c, &smsc_regmap_config);
  44. if (IS_ERR(smsc->regmap)) {
  45. ret = PTR_ERR(smsc->regmap);
  46. goto err;
  47. }
  48. i2c_set_clientdata(i2c, smsc);
  49. smsc->dev = &i2c->dev;
  50. #ifdef CONFIG_OF
  51. of_property_read_u32(i2c->dev.of_node, "clock", &smsc->clk);
  52. #endif
  53. regmap_read(smsc->regmap, SMSC_DEV_ID, &devid);
  54. regmap_read(smsc->regmap, SMSC_DEV_REV, &rev);
  55. regmap_read(smsc->regmap, SMSC_VEN_ID_L, &venid_l);
  56. regmap_read(smsc->regmap, SMSC_VEN_ID_H, &venid_h);
  57. dev_info(&i2c->dev, "SMSCxxx devid: %02x rev: %02x venid: %02x\n",
  58. devid, rev, (venid_h << 8) | venid_l);
  59. ret = regmap_write(smsc->regmap, SMSC_CLK_CTRL, smsc->clk);
  60. if (ret)
  61. goto err;
  62. #ifdef CONFIG_OF
  63. if (i2c->dev.of_node)
  64. ret = of_platform_populate(i2c->dev.of_node,
  65. NULL, NULL, &i2c->dev);
  66. #endif
  67. err:
  68. return ret;
  69. }
  70. static int smsc_i2c_remove(struct i2c_client *i2c)
  71. {
  72. struct smsc *smsc = i2c_get_clientdata(i2c);
  73. mfd_remove_devices(smsc->dev);
  74. return 0;
  75. }
  76. static const struct i2c_device_id smsc_i2c_id[] = {
  77. { "smscece1099", 0},
  78. {},
  79. };
  80. MODULE_DEVICE_TABLE(i2c, smsc_i2c_id);
  81. static struct i2c_driver smsc_i2c_driver = {
  82. .driver = {
  83. .name = "smsc",
  84. },
  85. .probe = smsc_i2c_probe,
  86. .remove = smsc_i2c_remove,
  87. .id_table = smsc_i2c_id,
  88. };
  89. module_i2c_driver(smsc_i2c_driver);
  90. MODULE_AUTHOR("Sourav Poddar <sourav.poddar@ti.com>");
  91. MODULE_DESCRIPTION("SMSC chip multi-function driver");
  92. MODULE_LICENSE("GPL v2");