busnv04.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright 2015 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 busions 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 <bskeggs@redhat.com>
  23. */
  24. #define nv04_i2c_bus(p) container_of((p), struct nv04_i2c_bus, base)
  25. #include "bus.h"
  26. #include <subdev/vga.h>
  27. struct nv04_i2c_bus {
  28. struct nvkm_i2c_bus base;
  29. u8 drive;
  30. u8 sense;
  31. };
  32. static void
  33. nv04_i2c_bus_drive_scl(struct nvkm_i2c_bus *base, int state)
  34. {
  35. struct nv04_i2c_bus *bus = nv04_i2c_bus(base);
  36. struct nvkm_device *device = bus->base.pad->i2c->subdev.device;
  37. u8 val = nvkm_rdvgac(device, 0, bus->drive);
  38. if (state) val |= 0x20;
  39. else val &= 0xdf;
  40. nvkm_wrvgac(device, 0, bus->drive, val | 0x01);
  41. }
  42. static void
  43. nv04_i2c_bus_drive_sda(struct nvkm_i2c_bus *base, int state)
  44. {
  45. struct nv04_i2c_bus *bus = nv04_i2c_bus(base);
  46. struct nvkm_device *device = bus->base.pad->i2c->subdev.device;
  47. u8 val = nvkm_rdvgac(device, 0, bus->drive);
  48. if (state) val |= 0x10;
  49. else val &= 0xef;
  50. nvkm_wrvgac(device, 0, bus->drive, val | 0x01);
  51. }
  52. static int
  53. nv04_i2c_bus_sense_scl(struct nvkm_i2c_bus *base)
  54. {
  55. struct nv04_i2c_bus *bus = nv04_i2c_bus(base);
  56. struct nvkm_device *device = bus->base.pad->i2c->subdev.device;
  57. return !!(nvkm_rdvgac(device, 0, bus->sense) & 0x04);
  58. }
  59. static int
  60. nv04_i2c_bus_sense_sda(struct nvkm_i2c_bus *base)
  61. {
  62. struct nv04_i2c_bus *bus = nv04_i2c_bus(base);
  63. struct nvkm_device *device = bus->base.pad->i2c->subdev.device;
  64. return !!(nvkm_rdvgac(device, 0, bus->sense) & 0x08);
  65. }
  66. static const struct nvkm_i2c_bus_func
  67. nv04_i2c_bus_func = {
  68. .drive_scl = nv04_i2c_bus_drive_scl,
  69. .drive_sda = nv04_i2c_bus_drive_sda,
  70. .sense_scl = nv04_i2c_bus_sense_scl,
  71. .sense_sda = nv04_i2c_bus_sense_sda,
  72. .xfer = nvkm_i2c_bit_xfer,
  73. };
  74. int
  75. nv04_i2c_bus_new(struct nvkm_i2c_pad *pad, int id, u8 drive, u8 sense,
  76. struct nvkm_i2c_bus **pbus)
  77. {
  78. struct nv04_i2c_bus *bus;
  79. if (!(bus = kzalloc(sizeof(*bus), GFP_KERNEL)))
  80. return -ENOMEM;
  81. *pbus = &bus->base;
  82. nvkm_i2c_bus_ctor(&nv04_i2c_bus_func, pad, id, &bus->base);
  83. bus->drive = drive;
  84. bus->sense = sense;
  85. return 0;
  86. }