via_aux.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright 2011 Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
  4. */
  5. /*
  6. * infrastructure for devices connected via I2C
  7. */
  8. #include <linux/slab.h>
  9. #include "via_aux.h"
  10. struct via_aux_bus *via_aux_probe(struct i2c_adapter *adap)
  11. {
  12. struct via_aux_bus *bus;
  13. if (!adap)
  14. return NULL;
  15. bus = kmalloc(sizeof(*bus), GFP_KERNEL);
  16. if (!bus)
  17. return NULL;
  18. bus->adap = adap;
  19. INIT_LIST_HEAD(&bus->drivers);
  20. via_aux_edid_probe(bus);
  21. via_aux_vt1636_probe(bus);
  22. via_aux_vt1632_probe(bus);
  23. via_aux_vt1631_probe(bus);
  24. via_aux_vt1625_probe(bus);
  25. via_aux_vt1622_probe(bus);
  26. via_aux_vt1621_probe(bus);
  27. via_aux_sii164_probe(bus);
  28. via_aux_ch7301_probe(bus);
  29. return bus;
  30. }
  31. void via_aux_free(struct via_aux_bus *bus)
  32. {
  33. struct via_aux_drv *pos, *n;
  34. if (!bus)
  35. return;
  36. list_for_each_entry_safe(pos, n, &bus->drivers, chain) {
  37. if (pos->cleanup)
  38. pos->cleanup(pos);
  39. list_del(&pos->chain);
  40. kfree(pos->data);
  41. kfree(pos);
  42. }
  43. kfree(bus);
  44. }
  45. const struct fb_videomode *via_aux_get_preferred_mode(struct via_aux_bus *bus)
  46. {
  47. struct via_aux_drv *pos;
  48. const struct fb_videomode *mode = NULL;
  49. if (!bus)
  50. return NULL;
  51. list_for_each_entry(pos, &bus->drivers, chain) {
  52. if (pos->get_preferred_mode)
  53. mode = pos->get_preferred_mode(pos);
  54. }
  55. return mode;
  56. }