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 nv04_i2c_bus(p) container_of((p), struct nv04_i2c_bus, base)
0025 #include "bus.h"
0026 
0027 #include <subdev/vga.h>
0028 
0029 struct nv04_i2c_bus {
0030     struct nvkm_i2c_bus base;
0031     u8 drive;
0032     u8 sense;
0033 };
0034 
0035 static void
0036 nv04_i2c_bus_drive_scl(struct nvkm_i2c_bus *base, int state)
0037 {
0038     struct nv04_i2c_bus *bus = nv04_i2c_bus(base);
0039     struct nvkm_device *device = bus->base.pad->i2c->subdev.device;
0040     u8 val = nvkm_rdvgac(device, 0, bus->drive);
0041     if (state) val |= 0x20;
0042     else       val &= 0xdf;
0043     nvkm_wrvgac(device, 0, bus->drive, val | 0x01);
0044 }
0045 
0046 static void
0047 nv04_i2c_bus_drive_sda(struct nvkm_i2c_bus *base, int state)
0048 {
0049     struct nv04_i2c_bus *bus = nv04_i2c_bus(base);
0050     struct nvkm_device *device = bus->base.pad->i2c->subdev.device;
0051     u8 val = nvkm_rdvgac(device, 0, bus->drive);
0052     if (state) val |= 0x10;
0053     else       val &= 0xef;
0054     nvkm_wrvgac(device, 0, bus->drive, val | 0x01);
0055 }
0056 
0057 static int
0058 nv04_i2c_bus_sense_scl(struct nvkm_i2c_bus *base)
0059 {
0060     struct nv04_i2c_bus *bus = nv04_i2c_bus(base);
0061     struct nvkm_device *device = bus->base.pad->i2c->subdev.device;
0062     return !!(nvkm_rdvgac(device, 0, bus->sense) & 0x04);
0063 }
0064 
0065 static int
0066 nv04_i2c_bus_sense_sda(struct nvkm_i2c_bus *base)
0067 {
0068     struct nv04_i2c_bus *bus = nv04_i2c_bus(base);
0069     struct nvkm_device *device = bus->base.pad->i2c->subdev.device;
0070     return !!(nvkm_rdvgac(device, 0, bus->sense) & 0x08);
0071 }
0072 
0073 static const struct nvkm_i2c_bus_func
0074 nv04_i2c_bus_func = {
0075     .drive_scl = nv04_i2c_bus_drive_scl,
0076     .drive_sda = nv04_i2c_bus_drive_sda,
0077     .sense_scl = nv04_i2c_bus_sense_scl,
0078     .sense_sda = nv04_i2c_bus_sense_sda,
0079     .xfer = nvkm_i2c_bit_xfer,
0080 };
0081 
0082 int
0083 nv04_i2c_bus_new(struct nvkm_i2c_pad *pad, int id, u8 drive, u8 sense,
0084          struct nvkm_i2c_bus **pbus)
0085 {
0086     struct nv04_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(&nv04_i2c_bus_func, pad, id, &bus->base);
0093     bus->drive = drive;
0094     bus->sense = sense;
0095     return 0;
0096 }