1/* $NetBSD: nouveau_nvkm_subdev_i2c_busgf119.c,v 1.3 2021/12/18 23:45:40 riastradh Exp $ */ 2 3/* 4 * Copyright 2015 Red Hat Inc. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the "Software"), 8 * to deal in the Software without restriction, including without limitation 9 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 * and/or sell copies of the Software, and to permit persons to whom the 11 * Software is furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial busions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 * OTHER DEALINGS IN THE SOFTWARE. 23 * 24 * Authors: Ben Skeggs <bskeggs@redhat.com> 25 */ 26#include <sys/cdefs.h> 27__KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_subdev_i2c_busgf119.c,v 1.3 2021/12/18 23:45:40 riastradh Exp $"); 28 29#define gf119_i2c_bus(p) container_of((p), struct gf119_i2c_bus, base) 30#include "bus.h" 31 32struct gf119_i2c_bus { 33 struct nvkm_i2c_bus base; 34 u32 addr; 35}; 36 37static void 38gf119_i2c_bus_drive_scl(struct nvkm_i2c_bus *base, int state) 39{ 40 struct gf119_i2c_bus *bus = gf119_i2c_bus(base); 41 struct nvkm_device *device = bus->base.pad->i2c->subdev.device; 42 nvkm_mask(device, bus->addr, 0x00000001, state ? 0x00000001 : 0); 43} 44 45static void 46gf119_i2c_bus_drive_sda(struct nvkm_i2c_bus *base, int state) 47{ 48 struct gf119_i2c_bus *bus = gf119_i2c_bus(base); 49 struct nvkm_device *device = bus->base.pad->i2c->subdev.device; 50 nvkm_mask(device, bus->addr, 0x00000002, state ? 0x00000002 : 0); 51} 52 53static int 54gf119_i2c_bus_sense_scl(struct nvkm_i2c_bus *base) 55{ 56 struct gf119_i2c_bus *bus = gf119_i2c_bus(base); 57 struct nvkm_device *device = bus->base.pad->i2c->subdev.device; 58 return !!(nvkm_rd32(device, bus->addr) & 0x00000010); 59} 60 61static int 62gf119_i2c_bus_sense_sda(struct nvkm_i2c_bus *base) 63{ 64 struct gf119_i2c_bus *bus = gf119_i2c_bus(base); 65 struct nvkm_device *device = bus->base.pad->i2c->subdev.device; 66 return !!(nvkm_rd32(device, bus->addr) & 0x00000020); 67} 68 69static void 70gf119_i2c_bus_init(struct nvkm_i2c_bus *base) 71{ 72 struct gf119_i2c_bus *bus = gf119_i2c_bus(base); 73 struct nvkm_device *device = bus->base.pad->i2c->subdev.device; 74 nvkm_wr32(device, bus->addr, 0x00000007); 75} 76 77static const struct nvkm_i2c_bus_func 78gf119_i2c_bus_func = { 79 .init = gf119_i2c_bus_init, 80 .drive_scl = gf119_i2c_bus_drive_scl, 81 .drive_sda = gf119_i2c_bus_drive_sda, 82 .sense_scl = gf119_i2c_bus_sense_scl, 83 .sense_sda = gf119_i2c_bus_sense_sda, 84 .xfer = nvkm_i2c_bit_xfer, 85}; 86 87int 88gf119_i2c_bus_new(struct nvkm_i2c_pad *pad, int id, u8 drive, 89 struct nvkm_i2c_bus **pbus) 90{ 91 struct gf119_i2c_bus *bus; 92 93 if (!(bus = kzalloc(sizeof(*bus), GFP_KERNEL))) 94 return -ENOMEM; 95 *pbus = &bus->base; 96 97 nvkm_i2c_bus_ctor(&gf119_i2c_bus_func, pad, id, &bus->base); 98 bus->addr = 0x00d014 + (drive * 0x20); 99 return 0; 100} 101