| 1 | /* $NetBSD: nouveau_subdev_i2c_nv4e.c,v 1.1.1.1 2014/08/06 12:36:30 riastradh Exp $ */ |
| 2 | |
| 3 | /* |
| 4 | * Copyright 2012 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 portions 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 |
| 25 | */ |
| 26 | |
| 27 | #include <sys/cdefs.h> |
| 28 | __KERNEL_RCSID(0, "$NetBSD: nouveau_subdev_i2c_nv4e.c,v 1.1.1.1 2014/08/06 12:36:30 riastradh Exp $" ); |
| 29 | |
| 30 | #include <subdev/i2c.h> |
| 31 | #include <subdev/vga.h> |
| 32 | |
| 33 | struct nv4e_i2c_priv { |
| 34 | struct nouveau_i2c base; |
| 35 | }; |
| 36 | |
| 37 | struct nv4e_i2c_port { |
| 38 | struct nouveau_i2c_port base; |
| 39 | u32 addr; |
| 40 | }; |
| 41 | |
| 42 | static void |
| 43 | nv4e_i2c_drive_scl(struct nouveau_i2c_port *base, int state) |
| 44 | { |
| 45 | struct nv4e_i2c_priv *priv = (void *)nv_object(base)->engine; |
| 46 | struct nv4e_i2c_port *port = (void *)base; |
| 47 | nv_mask(priv, port->addr, 0x2f, state ? 0x21 : 0x01); |
| 48 | } |
| 49 | |
| 50 | static void |
| 51 | nv4e_i2c_drive_sda(struct nouveau_i2c_port *base, int state) |
| 52 | { |
| 53 | struct nv4e_i2c_priv *priv = (void *)nv_object(base)->engine; |
| 54 | struct nv4e_i2c_port *port = (void *)base; |
| 55 | nv_mask(priv, port->addr, 0x1f, state ? 0x11 : 0x01); |
| 56 | } |
| 57 | |
| 58 | static int |
| 59 | nv4e_i2c_sense_scl(struct nouveau_i2c_port *base) |
| 60 | { |
| 61 | struct nv4e_i2c_priv *priv = (void *)nv_object(base)->engine; |
| 62 | struct nv4e_i2c_port *port = (void *)base; |
| 63 | return !!(nv_rd32(priv, port->addr) & 0x00040000); |
| 64 | } |
| 65 | |
| 66 | static int |
| 67 | nv4e_i2c_sense_sda(struct nouveau_i2c_port *base) |
| 68 | { |
| 69 | struct nv4e_i2c_priv *priv = (void *)nv_object(base)->engine; |
| 70 | struct nv4e_i2c_port *port = (void *)base; |
| 71 | return !!(nv_rd32(priv, port->addr) & 0x00080000); |
| 72 | } |
| 73 | |
| 74 | static const struct nouveau_i2c_func |
| 75 | nv4e_i2c_func = { |
| 76 | .drive_scl = nv4e_i2c_drive_scl, |
| 77 | .drive_sda = nv4e_i2c_drive_sda, |
| 78 | .sense_scl = nv4e_i2c_sense_scl, |
| 79 | .sense_sda = nv4e_i2c_sense_sda, |
| 80 | }; |
| 81 | |
| 82 | static int |
| 83 | nv4e_i2c_port_ctor(struct nouveau_object *parent, struct nouveau_object *engine, |
| 84 | struct nouveau_oclass *oclass, void *data, u32 index, |
| 85 | struct nouveau_object **pobject) |
| 86 | { |
| 87 | struct dcb_i2c_entry *info = data; |
| 88 | struct nv4e_i2c_port *port; |
| 89 | int ret; |
| 90 | |
| 91 | ret = nouveau_i2c_port_create(parent, engine, oclass, index, |
| 92 | &nouveau_i2c_bit_algo, &nv4e_i2c_func, |
| 93 | &port); |
| 94 | *pobject = nv_object(port); |
| 95 | if (ret) |
| 96 | return ret; |
| 97 | |
| 98 | port->addr = 0x600800 + info->drive; |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | static struct nouveau_oclass |
| 103 | nv4e_i2c_sclass[] = { |
| 104 | { .handle = NV_I2C_TYPE_DCBI2C(DCB_I2C_NV4E_BIT), |
| 105 | .ofuncs = &(struct nouveau_ofuncs) { |
| 106 | .ctor = nv4e_i2c_port_ctor, |
| 107 | .dtor = _nouveau_i2c_port_dtor, |
| 108 | .init = _nouveau_i2c_port_init, |
| 109 | .fini = _nouveau_i2c_port_fini, |
| 110 | }, |
| 111 | }, |
| 112 | {} |
| 113 | }; |
| 114 | |
| 115 | static int |
| 116 | nv4e_i2c_ctor(struct nouveau_object *parent, struct nouveau_object *engine, |
| 117 | struct nouveau_oclass *oclass, void *data, u32 size, |
| 118 | struct nouveau_object **pobject) |
| 119 | { |
| 120 | struct nv4e_i2c_priv *priv; |
| 121 | int ret; |
| 122 | |
| 123 | ret = nouveau_i2c_create(parent, engine, oclass, nv4e_i2c_sclass, &priv); |
| 124 | *pobject = nv_object(priv); |
| 125 | if (ret) |
| 126 | return ret; |
| 127 | |
| 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | struct nouveau_oclass |
| 132 | nv4e_i2c_oclass = { |
| 133 | .handle = NV_SUBDEV(I2C, 0x4e), |
| 134 | .ofuncs = &(struct nouveau_ofuncs) { |
| 135 | .ctor = nv4e_i2c_ctor, |
| 136 | .dtor = _nouveau_i2c_dtor, |
| 137 | .init = _nouveau_i2c_init, |
| 138 | .fini = _nouveau_i2c_fini, |
| 139 | }, |
| 140 | }; |
| 141 | |