sky81452.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * sky81452.c SKY81452 MFD driver
  3. *
  4. * Copyright 2014 Skyworks Solutions Inc.
  5. * Author : Gyungoh Yoo <jack.yoo@skyworksinc.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2
  9. * as 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 along
  17. * with this program; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/module.h>
  21. #include <linux/init.h>
  22. #include <linux/err.h>
  23. #include <linux/slab.h>
  24. #include <linux/i2c.h>
  25. #include <linux/regmap.h>
  26. #include <linux/mfd/core.h>
  27. #include <linux/mfd/sky81452.h>
  28. static const struct regmap_config sky81452_config = {
  29. .reg_bits = 8,
  30. .val_bits = 8,
  31. };
  32. static int sky81452_probe(struct i2c_client *client,
  33. const struct i2c_device_id *id)
  34. {
  35. struct device *dev = &client->dev;
  36. const struct sky81452_platform_data *pdata = dev_get_platdata(dev);
  37. struct mfd_cell cells[2];
  38. struct regmap *regmap;
  39. int ret;
  40. if (!pdata) {
  41. pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
  42. if (!pdata)
  43. return -ENOMEM;
  44. }
  45. regmap = devm_regmap_init_i2c(client, &sky81452_config);
  46. if (IS_ERR(regmap)) {
  47. dev_err(dev, "failed to initialize.err=%ld\n", PTR_ERR(regmap));
  48. return PTR_ERR(regmap);
  49. }
  50. i2c_set_clientdata(client, regmap);
  51. memset(cells, 0, sizeof(cells));
  52. cells[0].name = "sky81452-backlight";
  53. cells[0].of_compatible = "skyworks,sky81452-backlight";
  54. cells[0].platform_data = pdata->bl_pdata;
  55. cells[0].pdata_size = sizeof(*pdata->bl_pdata);
  56. cells[1].name = "sky81452-regulator";
  57. cells[1].platform_data = pdata->regulator_init_data;
  58. cells[1].pdata_size = sizeof(*pdata->regulator_init_data);
  59. ret = mfd_add_devices(dev, -1, cells, ARRAY_SIZE(cells), NULL, 0, NULL);
  60. if (ret)
  61. dev_err(dev, "failed to add child devices. err=%d\n", ret);
  62. return ret;
  63. }
  64. static int sky81452_remove(struct i2c_client *client)
  65. {
  66. mfd_remove_devices(&client->dev);
  67. return 0;
  68. }
  69. static const struct i2c_device_id sky81452_ids[] = {
  70. { "sky81452" },
  71. { }
  72. };
  73. MODULE_DEVICE_TABLE(i2c, sky81452_ids);
  74. #ifdef CONFIG_OF
  75. static const struct of_device_id sky81452_of_match[] = {
  76. { .compatible = "skyworks,sky81452", },
  77. { }
  78. };
  79. MODULE_DEVICE_TABLE(of, sky81452_of_match);
  80. #endif
  81. static struct i2c_driver sky81452_driver = {
  82. .driver = {
  83. .name = "sky81452",
  84. .of_match_table = of_match_ptr(sky81452_of_match),
  85. },
  86. .probe = sky81452_probe,
  87. .remove = sky81452_remove,
  88. .id_table = sky81452_ids,
  89. };
  90. module_i2c_driver(sky81452_driver);
  91. MODULE_DESCRIPTION("Skyworks SKY81452 MFD driver");
  92. MODULE_AUTHOR("Gyungoh Yoo <jack.yoo@skyworksinc.com>");
  93. MODULE_LICENSE("GPL v2");