stmpe-i2c.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * ST Microelectronics MFD: stmpe's i2c client specific driver
  3. *
  4. * Copyright (C) ST-Ericsson SA 2010
  5. * Copyright (C) ST Microelectronics SA 2011
  6. *
  7. * License Terms: GNU General Public License, version 2
  8. * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
  9. * Author: Viresh Kumar <viresh.kumar@st.com> for ST Microelectronics
  10. */
  11. #include <linux/i2c.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/types.h>
  16. #include "stmpe.h"
  17. static int i2c_reg_read(struct stmpe *stmpe, u8 reg)
  18. {
  19. struct i2c_client *i2c = stmpe->client;
  20. return i2c_smbus_read_byte_data(i2c, reg);
  21. }
  22. static int i2c_reg_write(struct stmpe *stmpe, u8 reg, u8 val)
  23. {
  24. struct i2c_client *i2c = stmpe->client;
  25. return i2c_smbus_write_byte_data(i2c, reg, val);
  26. }
  27. static int i2c_block_read(struct stmpe *stmpe, u8 reg, u8 length, u8 *values)
  28. {
  29. struct i2c_client *i2c = stmpe->client;
  30. return i2c_smbus_read_i2c_block_data(i2c, reg, length, values);
  31. }
  32. static int i2c_block_write(struct stmpe *stmpe, u8 reg, u8 length,
  33. const u8 *values)
  34. {
  35. struct i2c_client *i2c = stmpe->client;
  36. return i2c_smbus_write_i2c_block_data(i2c, reg, length, values);
  37. }
  38. static struct stmpe_client_info i2c_ci = {
  39. .read_byte = i2c_reg_read,
  40. .write_byte = i2c_reg_write,
  41. .read_block = i2c_block_read,
  42. .write_block = i2c_block_write,
  43. };
  44. static int __devinit
  45. stmpe_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
  46. {
  47. i2c_ci.data = (void *)id;
  48. i2c_ci.irq = i2c->irq;
  49. i2c_ci.client = i2c;
  50. i2c_ci.dev = &i2c->dev;
  51. return stmpe_probe(&i2c_ci, id->driver_data);
  52. }
  53. static int __devexit stmpe_i2c_remove(struct i2c_client *i2c)
  54. {
  55. struct stmpe *stmpe = dev_get_drvdata(&i2c->dev);
  56. return stmpe_remove(stmpe);
  57. }
  58. static const struct i2c_device_id stmpe_i2c_id[] = {
  59. { "stmpe610", STMPE610 },
  60. { "stmpe801", STMPE801 },
  61. { "stmpe811", STMPE811 },
  62. { "stmpe1601", STMPE1601 },
  63. { "stmpe2401", STMPE2401 },
  64. { "stmpe2403", STMPE2403 },
  65. { }
  66. };
  67. MODULE_DEVICE_TABLE(i2c, stmpe_id);
  68. static struct i2c_driver stmpe_i2c_driver = {
  69. .driver.name = "stmpe-i2c",
  70. .driver.owner = THIS_MODULE,
  71. #ifdef CONFIG_PM
  72. .driver.pm = &stmpe_dev_pm_ops,
  73. #endif
  74. .probe = stmpe_i2c_probe,
  75. .remove = __devexit_p(stmpe_i2c_remove),
  76. .id_table = stmpe_i2c_id,
  77. };
  78. static int __init stmpe_init(void)
  79. {
  80. return i2c_add_driver(&stmpe_i2c_driver);
  81. }
  82. subsys_initcall(stmpe_init);
  83. static void __exit stmpe_exit(void)
  84. {
  85. i2c_del_driver(&stmpe_i2c_driver);
  86. }
  87. module_exit(stmpe_exit);
  88. MODULE_LICENSE("GPL v2");
  89. MODULE_DESCRIPTION("STMPE MFD I2C Interface Driver");
  90. MODULE_AUTHOR("Rabin Vincent <rabin.vincent@stericsson.com>");