tdmb_i2c.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. *
  3. * drivers/media/tdmb/tdmb_i2c.c
  4. *
  5. * tdmb driver
  6. *
  7. * Copyright (C) (2011, Samsung Electronics)
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation version 2.
  12. *
  13. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  14. * kind, whether express or implied; without even the implied warranty
  15. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. */
  19. #include <linux/module.h>
  20. #include <linux/i2c.h>
  21. #include <linux/slab.h>
  22. #include <linux/of_gpio.h>
  23. #include "tdmb.h"
  24. struct i2c_client *i2c_dmb;
  25. static int tdmb_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
  26. {
  27. struct tdmb_i2c_dev *tdmb_dev;
  28. i2c_dmb = client;
  29. DPRINTK("tdmbi2c_probe() i2c_dmb : 0x%x\n", (unsigned int)i2c_dmb);
  30. tdmb_dev = (struct tdmb_i2c_dev *)kzalloc(sizeof(*tdmb_dev), GFP_KERNEL);
  31. if (!tdmb_dev) {
  32. pr_err("[%s::%d]failed to alloc memory\n", __func__, __LINE__);
  33. return -ENOMEM;
  34. }
  35. tdmb_dev->client = client;
  36. i2c_set_clientdata(client, tdmb_dev);
  37. return 0;
  38. }
  39. static const struct of_device_id tdmb_i2c_match_table[] = {
  40. {.compatible = "samsung,tdmb_i2c"},
  41. {}
  42. };
  43. static const struct i2c_device_id tdmb_i2c_id[] = {
  44. {"tdmbi2c", 0},
  45. {}
  46. };
  47. MODULE_DEVICE_TABLE(i2c, tdmb_i2c_id);
  48. static int __devexit tdmb_i2c_remove(struct i2c_client *client)
  49. {
  50. i2c_set_clientdata(client, NULL);
  51. return 0;
  52. }
  53. static struct i2c_driver tdmb_i2c_driver = {
  54. .driver = {
  55. .name = "tdmbi2c",
  56. .of_match_table = tdmb_i2c_match_table,
  57. .owner = THIS_MODULE,
  58. },
  59. .probe = tdmb_i2c_probe,
  60. .remove = __devexit_p(tdmb_i2c_remove),
  61. .id_table = tdmb_i2c_id,
  62. };
  63. static int __init tdmb_i2c_init(void)
  64. {
  65. return i2c_add_driver(&tdmb_i2c_driver);
  66. }
  67. static void __exit tdmb_i2c_exit(void)
  68. {
  69. i2c_del_driver(&tdmb_i2c_driver);
  70. }
  71. unsigned long tdmb_get_if_handle(void)
  72. {
  73. DPRINTK("%s : i2c_dmb 0x%p\n", __func__, i2c_dmb);
  74. return (unsigned long)i2c_dmb;
  75. }
  76. EXPORT_SYMBOL_GPL(tdmb_get_if_handle);
  77. module_init(tdmb_i2c_init);
  78. module_exit(tdmb_i2c_exit);
  79. MODULE_AUTHOR("Samsung");
  80. MODULE_DESCRIPTION("TDMB I2C Driver");
  81. MODULE_LICENSE("GPL v2");