Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2015 Red Hat Inc.
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial busions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
0021  *
0022  * Authors: Ben Skeggs <bskeggs@redhat.com>
0023  */
0024 #define gf119_i2c_bus(p) container_of((p), struct gf119_i2c_bus, base)
0025 #include "bus.h"
0026 
0027 struct gf119_i2c_bus {
0028     struct nvkm_i2c_bus base;
0029     u32 addr;
0030 };
0031 
0032 static void
0033 gf119_i2c_bus_drive_scl(struct nvkm_i2c_bus *base, int state)
0034 {
0035     struct gf119_i2c_bus *bus = gf119_i2c_bus(base);
0036     struct nvkm_device *device = bus->base.pad->i2c->subdev.device;
0037     nvkm_mask(device, bus->addr, 0x00000001, state ? 0x00000001 : 0);
0038 }
0039 
0040 static void
0041 gf119_i2c_bus_drive_sda(struct nvkm_i2c_bus *base, int state)
0042 {
0043     struct gf119_i2c_bus *bus = gf119_i2c_bus(base);
0044     struct nvkm_device *device = bus->base.pad->i2c->subdev.device;
0045     nvkm_mask(device, bus->addr, 0x00000002, state ? 0x00000002 : 0);
0046 }
0047 
0048 static int
0049 gf119_i2c_bus_sense_scl(struct nvkm_i2c_bus *base)
0050 {
0051     struct gf119_i2c_bus *bus = gf119_i2c_bus(base);
0052     struct nvkm_device *device = bus->base.pad->i2c->subdev.device;
0053     return !!(nvkm_rd32(device, bus->addr) & 0x00000010);
0054 }
0055 
0056 static int
0057 gf119_i2c_bus_sense_sda(struct nvkm_i2c_bus *base)
0058 {
0059     struct gf119_i2c_bus *bus = gf119_i2c_bus(base);
0060     struct nvkm_device *device = bus->base.pad->i2c->subdev.device;
0061     return !!(nvkm_rd32(device, bus->addr) & 0x00000020);
0062 }
0063 
0064 static void
0065 gf119_i2c_bus_init(struct nvkm_i2c_bus *base)
0066 {
0067     struct gf119_i2c_bus *bus = gf119_i2c_bus(base);
0068     struct nvkm_device *device = bus->base.pad->i2c->subdev.device;
0069     nvkm_wr32(device, bus->addr, 0x00000007);
0070 }
0071 
0072 static const struct nvkm_i2c_bus_func
0073 gf119_i2c_bus_func = {
0074     .init = gf119_i2c_bus_init,
0075     .drive_scl = gf119_i2c_bus_drive_scl,
0076     .drive_sda = gf119_i2c_bus_drive_sda,
0077     .sense_scl = gf119_i2c_bus_sense_scl,
0078     .sense_sda = gf119_i2c_bus_sense_sda,
0079     .xfer = nvkm_i2c_bit_xfer,
0080 };
0081 
0082 int
0083 gf119_i2c_bus_new(struct nvkm_i2c_pad *pad, int id, u8 drive,
0084          struct nvkm_i2c_bus **pbus)
0085 {
0086     struct gf119_i2c_bus *bus;
0087 
0088     if (!(bus = kzalloc(sizeof(*bus), GFP_KERNEL)))
0089         return -ENOMEM;
0090     *pbus = &bus->base;
0091 
0092     nvkm_i2c_bus_ctor(&gf119_i2c_bus_func, pad, id, &bus->base);
0093     bus->addr = 0x00d014 + (drive * 0x20);
0094     return 0;
0095 }