busnv50.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 nv50_i2c_bus(p) container_of((p), struct nv50_i2c_bus, base)
  25. #include "bus.h"
  26. #include <subdev/vga.h>
  27. struct nv50_i2c_bus {
  28. struct nvkm_i2c_bus base;
  29. u32 addr;
  30. u32 data;
  31. };
  32. static void
  33. nv50_i2c_bus_drive_scl(struct nvkm_i2c_bus *base, int state)
  34. {
  35. struct nv50_i2c_bus *bus = nv50_i2c_bus(base);
  36. struct nvkm_device *device = bus->base.pad->i2c->subdev.device;
  37. if (state) bus->data |= 0x01;
  38. else bus->data &= 0xfe;
  39. nvkm_wr32(device, bus->addr, bus->data);
  40. }
  41. static void
  42. nv50_i2c_bus_drive_sda(struct nvkm_i2c_bus *base, int state)
  43. {
  44. struct nv50_i2c_bus *bus = nv50_i2c_bus(base);
  45. struct nvkm_device *device = bus->base.pad->i2c->subdev.device;
  46. if (state) bus->data |= 0x02;
  47. else bus->data &= 0xfd;
  48. nvkm_wr32(device, bus->addr, bus->data);
  49. }
  50. static int
  51. nv50_i2c_bus_sense_scl(struct nvkm_i2c_bus *base)
  52. {
  53. struct nv50_i2c_bus *bus = nv50_i2c_bus(base);
  54. struct nvkm_device *device = bus->base.pad->i2c->subdev.device;
  55. return !!(nvkm_rd32(device, bus->addr) & 0x00000001);
  56. }
  57. static int
  58. nv50_i2c_bus_sense_sda(struct nvkm_i2c_bus *base)
  59. {
  60. struct nv50_i2c_bus *bus = nv50_i2c_bus(base);
  61. struct nvkm_device *device = bus->base.pad->i2c->subdev.device;
  62. return !!(nvkm_rd32(device, bus->addr) & 0x00000002);
  63. }
  64. static void
  65. nv50_i2c_bus_init(struct nvkm_i2c_bus *base)
  66. {
  67. struct nv50_i2c_bus *bus = nv50_i2c_bus(base);
  68. struct nvkm_device *device = bus->base.pad->i2c->subdev.device;
  69. nvkm_wr32(device, bus->addr, (bus->data = 0x00000007));
  70. }
  71. static const struct nvkm_i2c_bus_func
  72. nv50_i2c_bus_func = {
  73. .init = nv50_i2c_bus_init,
  74. .drive_scl = nv50_i2c_bus_drive_scl,
  75. .drive_sda = nv50_i2c_bus_drive_sda,
  76. .sense_scl = nv50_i2c_bus_sense_scl,
  77. .sense_sda = nv50_i2c_bus_sense_sda,
  78. .xfer = nvkm_i2c_bit_xfer,
  79. };
  80. int
  81. nv50_i2c_bus_new(struct nvkm_i2c_pad *pad, int id, u8 drive,
  82. struct nvkm_i2c_bus **pbus)
  83. {
  84. static const u32 addr[] = {
  85. 0x00e138, 0x00e150, 0x00e168, 0x00e180,
  86. 0x00e254, 0x00e274, 0x00e764, 0x00e780,
  87. 0x00e79c, 0x00e7b8
  88. };
  89. struct nv50_i2c_bus *bus;
  90. if (drive >= ARRAY_SIZE(addr)) {
  91. nvkm_warn(&pad->i2c->subdev, "bus %d unknown\n", drive);
  92. return -ENODEV;
  93. }
  94. if (!(bus = kzalloc(sizeof(*bus), GFP_KERNEL)))
  95. return -ENOMEM;
  96. *pbus = &bus->base;
  97. nvkm_i2c_bus_ctor(&nv50_i2c_bus_func, pad, id, &bus->base);
  98. bus->addr = addr[drive];
  99. bus->data = 0x00000007;
  100. return 0;
  101. }