outp.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright 2014 Red Hat Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Ben Skeggs
  23. */
  24. #include "outp.h"
  25. #include <subdev/bios.h>
  26. #include <subdev/bios/dcb.h>
  27. #include <subdev/i2c.h>
  28. void
  29. nvkm_output_fini(struct nvkm_output *outp)
  30. {
  31. if (outp->func->fini)
  32. outp->func->fini(outp);
  33. }
  34. void
  35. nvkm_output_init(struct nvkm_output *outp)
  36. {
  37. if (outp->func->init)
  38. outp->func->init(outp);
  39. }
  40. void
  41. nvkm_output_del(struct nvkm_output **poutp)
  42. {
  43. struct nvkm_output *outp = *poutp;
  44. if (outp && !WARN_ON(!outp->func)) {
  45. if (outp->func->dtor)
  46. *poutp = outp->func->dtor(outp);
  47. kfree(*poutp);
  48. *poutp = NULL;
  49. }
  50. }
  51. void
  52. nvkm_output_ctor(const struct nvkm_output_func *func, struct nvkm_disp *disp,
  53. int index, struct dcb_output *dcbE, struct nvkm_output *outp)
  54. {
  55. struct nvkm_i2c *i2c = disp->engine.subdev.device->i2c;
  56. outp->func = func;
  57. outp->disp = disp;
  58. outp->index = index;
  59. outp->info = *dcbE;
  60. outp->i2c = nvkm_i2c_bus_find(i2c, dcbE->i2c_index);
  61. outp->or = ffs(outp->info.or) - 1;
  62. OUTP_DBG(outp, "type %02x loc %d or %d link %d con %x "
  63. "edid %x bus %d head %x",
  64. outp->info.type, outp->info.location, outp->info.or,
  65. outp->info.type >= 2 ? outp->info.sorconf.link : 0,
  66. outp->info.connector, outp->info.i2c_index,
  67. outp->info.bus, outp->info.heads);
  68. }
  69. int
  70. nvkm_output_new_(const struct nvkm_output_func *func,
  71. struct nvkm_disp *disp, int index, struct dcb_output *dcbE,
  72. struct nvkm_output **poutp)
  73. {
  74. if (!(*poutp = kzalloc(sizeof(**poutp), GFP_KERNEL)))
  75. return -ENOMEM;
  76. nvkm_output_ctor(func, disp, index, dcbE, *poutp);
  77. return 0;
  78. }