busnv4e.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 nv4e_i2c_bus(p) container_of((p), struct nv4e_i2c_bus, base)
  25. #include "bus.h"
  26. struct nv4e_i2c_bus {
  27. struct nvkm_i2c_bus base;
  28. u32 addr;
  29. };
  30. static void
  31. nv4e_i2c_bus_drive_scl(struct nvkm_i2c_bus *base, int state)
  32. {
  33. struct nv4e_i2c_bus *bus = nv4e_i2c_bus(base);
  34. struct nvkm_device *device = bus->base.pad->i2c->subdev.device;
  35. nvkm_mask(device, bus->addr, 0x2f, state ? 0x21 : 0x01);
  36. }
  37. static void
  38. nv4e_i2c_bus_drive_sda(struct nvkm_i2c_bus *base, int state)
  39. {
  40. struct nv4e_i2c_bus *bus = nv4e_i2c_bus(base);
  41. struct nvkm_device *device = bus->base.pad->i2c->subdev.device;
  42. nvkm_mask(device, bus->addr, 0x1f, state ? 0x11 : 0x01);
  43. }
  44. static int
  45. nv4e_i2c_bus_sense_scl(struct nvkm_i2c_bus *base)
  46. {
  47. struct nv4e_i2c_bus *bus = nv4e_i2c_bus(base);
  48. struct nvkm_device *device = bus->base.pad->i2c->subdev.device;
  49. return !!(nvkm_rd32(device, bus->addr) & 0x00040000);
  50. }
  51. static int
  52. nv4e_i2c_bus_sense_sda(struct nvkm_i2c_bus *base)
  53. {
  54. struct nv4e_i2c_bus *bus = nv4e_i2c_bus(base);
  55. struct nvkm_device *device = bus->base.pad->i2c->subdev.device;
  56. return !!(nvkm_rd32(device, bus->addr) & 0x00080000);
  57. }
  58. static const struct nvkm_i2c_bus_func
  59. nv4e_i2c_bus_func = {
  60. .drive_scl = nv4e_i2c_bus_drive_scl,
  61. .drive_sda = nv4e_i2c_bus_drive_sda,
  62. .sense_scl = nv4e_i2c_bus_sense_scl,
  63. .sense_sda = nv4e_i2c_bus_sense_sda,
  64. .xfer = nvkm_i2c_bit_xfer,
  65. };
  66. int
  67. nv4e_i2c_bus_new(struct nvkm_i2c_pad *pad, int id, u8 drive,
  68. struct nvkm_i2c_bus **pbus)
  69. {
  70. struct nv4e_i2c_bus *bus;
  71. if (!(bus = kzalloc(sizeof(*bus), GFP_KERNEL)))
  72. return -ENOMEM;
  73. *pbus = &bus->base;
  74. nvkm_i2c_bus_ctor(&nv4e_i2c_bus_func, pad, id, &bus->base);
  75. bus->addr = 0x600800 + drive;
  76. return 0;
  77. }