wl1273-core.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * MFD driver for wl1273 FM radio and audio codec submodules.
  3. *
  4. * Copyright (C) 2010 Nokia Corporation
  5. * Author: Matti Aaltonen <matti.j.aaltonen@nokia.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  19. * 02110-1301 USA
  20. *
  21. */
  22. #include <linux/mfd/wl1273-core.h>
  23. #include <linux/slab.h>
  24. #define DRIVER_DESC "WL1273 FM Radio Core"
  25. static struct i2c_device_id wl1273_driver_id_table[] = {
  26. { WL1273_FM_DRIVER_NAME, 0 },
  27. { }
  28. };
  29. MODULE_DEVICE_TABLE(i2c, wl1273_driver_id_table);
  30. static int wl1273_core_remove(struct i2c_client *client)
  31. {
  32. struct wl1273_core *core = i2c_get_clientdata(client);
  33. dev_dbg(&client->dev, "%s\n", __func__);
  34. mfd_remove_devices(&client->dev);
  35. kfree(core);
  36. return 0;
  37. }
  38. static int __devinit wl1273_core_probe(struct i2c_client *client,
  39. const struct i2c_device_id *id)
  40. {
  41. struct wl1273_fm_platform_data *pdata = client->dev.platform_data;
  42. struct wl1273_core *core;
  43. struct mfd_cell *cell;
  44. int children = 0;
  45. int r = 0;
  46. dev_dbg(&client->dev, "%s\n", __func__);
  47. if (!pdata) {
  48. dev_err(&client->dev, "No platform data.\n");
  49. return -EINVAL;
  50. }
  51. if (!(pdata->children & WL1273_RADIO_CHILD)) {
  52. dev_err(&client->dev, "Cannot function without radio child.\n");
  53. return -EINVAL;
  54. }
  55. core = kzalloc(sizeof(*core), GFP_KERNEL);
  56. if (!core)
  57. return -ENOMEM;
  58. core->pdata = pdata;
  59. core->client = client;
  60. mutex_init(&core->lock);
  61. i2c_set_clientdata(client, core);
  62. dev_dbg(&client->dev, "%s: Have V4L2.\n", __func__);
  63. cell = &core->cells[children];
  64. cell->name = "wl1273_fm_radio";
  65. cell->mfd_data = &core;
  66. children++;
  67. if (pdata->children & WL1273_CODEC_CHILD) {
  68. cell = &core->cells[children];
  69. dev_dbg(&client->dev, "%s: Have codec.\n", __func__);
  70. cell->name = "wl1273-codec";
  71. cell->mfd_data = &core;
  72. children++;
  73. }
  74. dev_dbg(&client->dev, "%s: number of children: %d.\n",
  75. __func__, children);
  76. r = mfd_add_devices(&client->dev, -1, core->cells,
  77. children, NULL, 0);
  78. if (r)
  79. goto err;
  80. return 0;
  81. err:
  82. pdata->free_resources();
  83. kfree(core);
  84. dev_dbg(&client->dev, "%s\n", __func__);
  85. return r;
  86. }
  87. static struct i2c_driver wl1273_core_driver = {
  88. .driver = {
  89. .name = WL1273_FM_DRIVER_NAME,
  90. },
  91. .probe = wl1273_core_probe,
  92. .id_table = wl1273_driver_id_table,
  93. .remove = __devexit_p(wl1273_core_remove),
  94. };
  95. static int __init wl1273_core_init(void)
  96. {
  97. int r;
  98. r = i2c_add_driver(&wl1273_core_driver);
  99. if (r) {
  100. pr_err(WL1273_FM_DRIVER_NAME
  101. ": driver registration failed\n");
  102. return r;
  103. }
  104. return r;
  105. }
  106. static void __exit wl1273_core_exit(void)
  107. {
  108. i2c_del_driver(&wl1273_core_driver);
  109. }
  110. late_initcall(wl1273_core_init);
  111. module_exit(wl1273_core_exit);
  112. MODULE_AUTHOR("Matti Aaltonen <matti.j.aaltonen@nokia.com>");
  113. MODULE_DESCRIPTION(DRIVER_DESC);
  114. MODULE_LICENSE("GPL");