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 nv4e_i2c_bus(p) container_of((p), struct nv4e_i2c_bus, base)
0025 #include "bus.h"
0026 
0027 struct nv4e_i2c_bus {
0028     struct nvkm_i2c_bus base;
0029     u32 addr;
0030 };
0031 
0032 static void
0033 nv4e_i2c_bus_drive_scl(struct nvkm_i2c_bus *base, int state)
0034 {
0035     struct nv4e_i2c_bus *bus = nv4e_i2c_bus(base);
0036     struct nvkm_device *device = bus->base.pad->i2c->subdev.device;
0037     nvkm_mask(device, bus->addr, 0x2f, state ? 0x21 : 0x01);
0038 }
0039 
0040 static void
0041 nv4e_i2c_bus_drive_sda(struct nvkm_i2c_bus *base, int state)
0042 {
0043     struct nv4e_i2c_bus *bus = nv4e_i2c_bus(base);
0044     struct nvkm_device *device = bus->base.pad->i2c->subdev.device;
0045     nvkm_mask(device, bus->addr, 0x1f, state ? 0x11 : 0x01);
0046 }
0047 
0048 static int
0049 nv4e_i2c_bus_sense_scl(struct nvkm_i2c_bus *base)
0050 {
0051     struct nv4e_i2c_bus *bus = nv4e_i2c_bus(base);
0052     struct nvkm_device *device = bus->base.pad->i2c->subdev.device;
0053     return !!(nvkm_rd32(device, bus->addr) & 0x00040000);
0054 }
0055 
0056 static int
0057 nv4e_i2c_bus_sense_sda(struct nvkm_i2c_bus *base)
0058 {
0059     struct nv4e_i2c_bus *bus = nv4e_i2c_bus(base);
0060     struct nvkm_device *device = bus->base.pad->i2c->subdev.device;
0061     return !!(nvkm_rd32(device, bus->addr) & 0x00080000);
0062 }
0063 
0064 static const struct nvkm_i2c_bus_func
0065 nv4e_i2c_bus_func = {
0066     .drive_scl = nv4e_i2c_bus_drive_scl,
0067     .drive_sda = nv4e_i2c_bus_drive_sda,
0068     .sense_scl = nv4e_i2c_bus_sense_scl,
0069     .sense_sda = nv4e_i2c_bus_sense_sda,
0070     .xfer = nvkm_i2c_bit_xfer,
0071 };
0072 
0073 int
0074 nv4e_i2c_bus_new(struct nvkm_i2c_pad *pad, int id, u8 drive,
0075          struct nvkm_i2c_bus **pbus)
0076 {
0077     struct nv4e_i2c_bus *bus;
0078 
0079     if (!(bus = kzalloc(sizeof(*bus), GFP_KERNEL)))
0080         return -ENOMEM;
0081     *pbus = &bus->base;
0082 
0083     nvkm_i2c_bus_ctor(&nv4e_i2c_bus_func, pad, id, &bus->base);
0084     bus->addr = 0x600800 + drive;
0085     return 0;
0086 }