2 * Copyright 2015 Red Hat Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
22 * Authors: Ben Skeggs <bskeggs@redhat.com>
27 nvkm_i2c_pad_mode_locked(struct nvkm_i2c_pad
*pad
, enum nvkm_i2c_pad_mode mode
)
29 PAD_TRACE(pad
, "-> %s", (mode
== NVKM_I2C_PAD_AUX
) ? "aux" :
30 (mode
== NVKM_I2C_PAD_I2C
) ? "i2c" : "off");
32 pad
->func
->mode(pad
, mode
);
36 nvkm_i2c_pad_mode(struct nvkm_i2c_pad
*pad
, enum nvkm_i2c_pad_mode mode
)
38 PAD_TRACE(pad
, "mode %d", mode
);
39 mutex_lock(&pad
->mutex
);
40 nvkm_i2c_pad_mode_locked(pad
, mode
);
42 mutex_unlock(&pad
->mutex
);
46 nvkm_i2c_pad_release(struct nvkm_i2c_pad
*pad
)
48 PAD_TRACE(pad
, "release");
49 if (pad
->mode
== NVKM_I2C_PAD_OFF
)
50 nvkm_i2c_pad_mode_locked(pad
, pad
->mode
);
51 mutex_unlock(&pad
->mutex
);
55 nvkm_i2c_pad_acquire(struct nvkm_i2c_pad
*pad
, enum nvkm_i2c_pad_mode mode
)
57 PAD_TRACE(pad
, "acquire");
58 mutex_lock(&pad
->mutex
);
59 if (pad
->mode
!= mode
) {
60 if (pad
->mode
!= NVKM_I2C_PAD_OFF
) {
61 mutex_unlock(&pad
->mutex
);
64 nvkm_i2c_pad_mode_locked(pad
, mode
);
70 nvkm_i2c_pad_fini(struct nvkm_i2c_pad
*pad
)
72 PAD_TRACE(pad
, "fini");
73 nvkm_i2c_pad_mode_locked(pad
, NVKM_I2C_PAD_OFF
);
77 nvkm_i2c_pad_init(struct nvkm_i2c_pad
*pad
)
79 PAD_TRACE(pad
, "init");
80 nvkm_i2c_pad_mode_locked(pad
, pad
->mode
);
84 nvkm_i2c_pad_del(struct nvkm_i2c_pad
**ppad
)
86 struct nvkm_i2c_pad
*pad
= *ppad
;
88 PAD_TRACE(pad
, "dtor");
96 nvkm_i2c_pad_ctor(const struct nvkm_i2c_pad_func
*func
, struct nvkm_i2c
*i2c
,
97 int id
, struct nvkm_i2c_pad
*pad
)
102 pad
->mode
= NVKM_I2C_PAD_OFF
;
103 mutex_init(&pad
->mutex
);
104 list_add_tail(&pad
->head
, &i2c
->pad
);
105 PAD_TRACE(pad
, "ctor");
109 nvkm_i2c_pad_new_(const struct nvkm_i2c_pad_func
*func
, struct nvkm_i2c
*i2c
,
110 int id
, struct nvkm_i2c_pad
**ppad
)
112 if (!(*ppad
= kzalloc(sizeof(**ppad
), GFP_KERNEL
)))
114 nvkm_i2c_pad_ctor(func
, i2c
, id
, *ppad
);