smsc-ece1099.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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(struct smsc),
  37. GFP_KERNEL);
  38. if (!smsc) {
  39. dev_err(&i2c->dev, "smsc mfd driver memory allocation failed\n");
  40. return -ENOMEM;
  41. }
  42. smsc->regmap = devm_regmap_init_i2c(i2c, &smsc_regmap_config);
  43. if (IS_ERR(smsc->regmap))
  44. return PTR_ERR(smsc->regmap);
  45. i2c_set_clientdata(i2c, smsc);
  46. smsc->dev = &i2c->dev;
  47. #ifdef CONFIG_OF
  48. of_property_read_u32(i2c->dev.of_node, "clock", &smsc->clk);
  49. #endif
  50. regmap_read(smsc->regmap, SMSC_DEV_ID, &devid);
  51. regmap_read(smsc->regmap, SMSC_DEV_REV, &rev);
  52. regmap_read(smsc->regmap, SMSC_VEN_ID_L, &venid_l);
  53. regmap_read(smsc->regmap, SMSC_VEN_ID_H, &venid_h);
  54. dev_info(&i2c->dev, "SMSCxxx devid: %02x rev: %02x venid: %02x\n",
  55. devid, rev, (venid_h << 8) | venid_l);
  56. ret = regmap_write(smsc->regmap, SMSC_CLK_CTRL, smsc->clk);
  57. if (ret)
  58. return ret;
  59. #ifdef CONFIG_OF
  60. if (i2c->dev.of_node)
  61. ret = of_platform_populate(i2c->dev.of_node,
  62. NULL, NULL, &i2c->dev);
  63. #endif
  64. return ret;
  65. }
  66. static const struct i2c_device_id smsc_i2c_id[] = {
  67. { "smscece1099", 0},
  68. {},
  69. };
  70. static struct i2c_driver smsc_i2c_driver = {
  71. .driver = {
  72. .name = "smsc",
  73. },
  74. .probe = smsc_i2c_probe,
  75. .id_table = smsc_i2c_id,
  76. };
  77. builtin_i2c_driver(smsc_i2c_driver);