atc260x-i2c.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * I2C bus interface for ATC260x PMICs
  4. *
  5. * Copyright (C) 2019 Manivannan Sadhasivam <[email protected]>
  6. * Copyright (C) 2020 Cristian Ciocaltea <[email protected]>
  7. */
  8. #include <linux/i2c.h>
  9. #include <linux/mfd/atc260x/core.h>
  10. #include <linux/module.h>
  11. #include <linux/of.h>
  12. #include <linux/regmap.h>
  13. static int atc260x_i2c_probe(struct i2c_client *client,
  14. const struct i2c_device_id *id)
  15. {
  16. struct atc260x *atc260x;
  17. struct regmap_config regmap_cfg;
  18. int ret;
  19. atc260x = devm_kzalloc(&client->dev, sizeof(*atc260x), GFP_KERNEL);
  20. if (!atc260x)
  21. return -ENOMEM;
  22. atc260x->dev = &client->dev;
  23. atc260x->irq = client->irq;
  24. ret = atc260x_match_device(atc260x, &regmap_cfg);
  25. if (ret)
  26. return ret;
  27. i2c_set_clientdata(client, atc260x);
  28. atc260x->regmap = devm_regmap_init_i2c(client, &regmap_cfg);
  29. if (IS_ERR(atc260x->regmap)) {
  30. ret = PTR_ERR(atc260x->regmap);
  31. dev_err(&client->dev, "failed to init regmap: %d\n", ret);
  32. return ret;
  33. }
  34. return atc260x_device_probe(atc260x);
  35. }
  36. static const struct of_device_id atc260x_i2c_of_match[] = {
  37. { .compatible = "actions,atc2603c", .data = (void *)ATC2603C },
  38. { .compatible = "actions,atc2609a", .data = (void *)ATC2609A },
  39. { }
  40. };
  41. MODULE_DEVICE_TABLE(of, atc260x_i2c_of_match);
  42. static struct i2c_driver atc260x_i2c_driver = {
  43. .driver = {
  44. .name = "atc260x",
  45. .of_match_table = of_match_ptr(atc260x_i2c_of_match),
  46. },
  47. .probe = atc260x_i2c_probe,
  48. };
  49. module_i2c_driver(atc260x_i2c_driver);
  50. MODULE_DESCRIPTION("ATC260x PMICs I2C bus interface");
  51. MODULE_AUTHOR("Manivannan Sadhasivam <[email protected]>");
  52. MODULE_AUTHOR("Cristian Ciocaltea <[email protected]>");
  53. MODULE_LICENSE("GPL");