sky81452.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * sky81452.c SKY81452 MFD driver
  4. *
  5. * Copyright 2014 Skyworks Solutions Inc.
  6. * Author : Gyungoh Yoo <[email protected]>
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/module.h>
  10. #include <linux/init.h>
  11. #include <linux/err.h>
  12. #include <linux/slab.h>
  13. #include <linux/i2c.h>
  14. #include <linux/regmap.h>
  15. #include <linux/mfd/core.h>
  16. #include <linux/mfd/sky81452.h>
  17. static const struct regmap_config sky81452_config = {
  18. .reg_bits = 8,
  19. .val_bits = 8,
  20. };
  21. static int sky81452_probe(struct i2c_client *client,
  22. const struct i2c_device_id *id)
  23. {
  24. struct device *dev = &client->dev;
  25. const struct sky81452_platform_data *pdata = dev_get_platdata(dev);
  26. struct mfd_cell cells[2];
  27. struct regmap *regmap;
  28. int ret;
  29. if (!pdata) {
  30. pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
  31. if (!pdata)
  32. return -ENOMEM;
  33. }
  34. regmap = devm_regmap_init_i2c(client, &sky81452_config);
  35. if (IS_ERR(regmap)) {
  36. dev_err(dev, "failed to initialize.err=%ld\n", PTR_ERR(regmap));
  37. return PTR_ERR(regmap);
  38. }
  39. i2c_set_clientdata(client, regmap);
  40. memset(cells, 0, sizeof(cells));
  41. cells[0].name = "sky81452-backlight";
  42. cells[0].of_compatible = "skyworks,sky81452-backlight";
  43. cells[1].name = "sky81452-regulator";
  44. cells[1].platform_data = pdata->regulator_init_data;
  45. cells[1].pdata_size = sizeof(*pdata->regulator_init_data);
  46. ret = devm_mfd_add_devices(dev, -1, cells, ARRAY_SIZE(cells),
  47. NULL, 0, NULL);
  48. if (ret)
  49. dev_err(dev, "failed to add child devices. err=%d\n", ret);
  50. return ret;
  51. }
  52. static const struct i2c_device_id sky81452_ids[] = {
  53. { "sky81452" },
  54. { }
  55. };
  56. MODULE_DEVICE_TABLE(i2c, sky81452_ids);
  57. #ifdef CONFIG_OF
  58. static const struct of_device_id sky81452_of_match[] = {
  59. { .compatible = "skyworks,sky81452", },
  60. { }
  61. };
  62. MODULE_DEVICE_TABLE(of, sky81452_of_match);
  63. #endif
  64. static struct i2c_driver sky81452_driver = {
  65. .driver = {
  66. .name = "sky81452",
  67. .of_match_table = of_match_ptr(sky81452_of_match),
  68. },
  69. .probe = sky81452_probe,
  70. .id_table = sky81452_ids,
  71. };
  72. module_i2c_driver(sky81452_driver);
  73. MODULE_DESCRIPTION("Skyworks SKY81452 MFD driver");
  74. MODULE_AUTHOR("Gyungoh Yoo <[email protected]>");
  75. MODULE_LICENSE("GPL v2");