wl1273-core.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. i2c_set_clientdata(client, NULL);
  36. kfree(core);
  37. return 0;
  38. }
  39. static int __devinit wl1273_core_probe(struct i2c_client *client,
  40. const struct i2c_device_id *id)
  41. {
  42. struct wl1273_fm_platform_data *pdata = client->dev.platform_data;
  43. struct wl1273_core *core;
  44. struct mfd_cell *cell;
  45. int children = 0;
  46. int r = 0;
  47. dev_dbg(&client->dev, "%s\n", __func__);
  48. if (!pdata) {
  49. dev_err(&client->dev, "No platform data.\n");
  50. return -EINVAL;
  51. }
  52. if (!(pdata->children & WL1273_RADIO_CHILD)) {
  53. dev_err(&client->dev, "Cannot function without radio child.\n");
  54. return -EINVAL;
  55. }
  56. core = kzalloc(sizeof(*core), GFP_KERNEL);
  57. if (!core)
  58. return -ENOMEM;
  59. core->pdata = pdata;
  60. core->client = client;
  61. mutex_init(&core->lock);
  62. i2c_set_clientdata(client, core);
  63. dev_dbg(&client->dev, "%s: Have V4L2.\n", __func__);
  64. cell = &core->cells[children];
  65. cell->name = "wl1273_fm_radio";
  66. cell->platform_data = &core;
  67. cell->data_size = sizeof(core);
  68. children++;
  69. if (pdata->children & WL1273_CODEC_CHILD) {
  70. cell = &core->cells[children];
  71. dev_dbg(&client->dev, "%s: Have codec.\n", __func__);
  72. cell->name = "wl1273-codec";
  73. cell->platform_data = &core;
  74. cell->data_size = sizeof(core);
  75. children++;
  76. }
  77. dev_dbg(&client->dev, "%s: number of children: %d.\n",
  78. __func__, children);
  79. r = mfd_add_devices(&client->dev, -1, core->cells,
  80. children, NULL, 0);
  81. if (r)
  82. goto err;
  83. return 0;
  84. err:
  85. i2c_set_clientdata(client, NULL);
  86. pdata->free_resources();
  87. kfree(core);
  88. dev_dbg(&client->dev, "%s\n", __func__);
  89. return r;
  90. }
  91. static struct i2c_driver wl1273_core_driver = {
  92. .driver = {
  93. .name = WL1273_FM_DRIVER_NAME,
  94. },
  95. .probe = wl1273_core_probe,
  96. .id_table = wl1273_driver_id_table,
  97. .remove = __devexit_p(wl1273_core_remove),
  98. };
  99. static int __init wl1273_core_init(void)
  100. {
  101. int r;
  102. r = i2c_add_driver(&wl1273_core_driver);
  103. if (r) {
  104. pr_err(WL1273_FM_DRIVER_NAME
  105. ": driver registration failed\n");
  106. return r;
  107. }
  108. return r;
  109. }
  110. static void __exit wl1273_core_exit(void)
  111. {
  112. i2c_del_driver(&wl1273_core_driver);
  113. }
  114. late_initcall(wl1273_core_init);
  115. module_exit(wl1273_core_exit);
  116. MODULE_AUTHOR("Matti Aaltonen <matti.j.aaltonen@nokia.com>");
  117. MODULE_DESCRIPTION(DRIVER_DESC);
  118. MODULE_LICENSE("GPL");