/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* This driver supports the GPIO subset of the full ADM1026 register set.
* The driver is designed to allow modifying and reading the Polarity and
* Direction bits of the ADM1026's 16 GPIO pins via the 4 GPIO Config
* registers. In addition, the driver supports modifying and reading
*
* The 4 GPIO Config registers configure the direction and polarity of
* the 16 GPIO pins. When a Polarity bit is set to 0, the GPIO pin is
* active low, otherwise, it is active high. When a Direction bit is set
* to 0, the GPIO pin configured as an input; otherwise, it is an output.
*
* When a GPIO pin is configured as an input, the bit is set when its GPIO
* pin is asserted. When a GPIO pin is configured as an output, the bit
* asserts the GPIO pin.
*
* The commands supported in the ioctl routine are:
* GPIO_GET_OUTPUT -- Read GPIO0-GPIO15 bits in Status Register 5 & 6
* GPIO_SET_OUTPUT -- Modify GPIO0-GPIO15 bits in Status Register 5 & 6
* GPIO_GET_POLARITY -- Read GPIO0-GPIO15 Polarity bits in GPIO Config 1-4
* GPIO_SET_POLARITY -- Modify GPIO0-GPIO15 Polarity bits in GPIO Config 1-4
* GPIO_GET_CONFIG -- Read GPIO0-GPIO15 Direction bits in GPIO Config 1-4
* GPIO_SET_CONFIG -- Modify GPIO0-GPIO15 Direction bits in GPIO Config 1-4
*
* A pointer to the i2c_gpio_t data structure is sent as the third argument
* in the ioctl call. The reg_mask and reg_val members of i2c_gpio_t are
* used to logically represent the 16 GPIO pins, thus only the lower 16 bits
* of each member is used. The reg_mask member identifies the GPIO pin(s)
* that the user wants to read or modify and reg_val has the actual value of
* what the corresponding GPIO pin should be set to.
*
* For example, a reg_mask of 0x8001 indicates that the ioctl should only
* access GPIO15 and GPIO0.
*/
static void *adm1026soft_statep;
static int adm1026_do_attach(dev_info_t *);
static int adm1026_do_detach(dev_info_t *);
static int adm1026_do_resume(void);
static int adm1026_do_suspend(void);
/*
* cb ops (only need ioctl)
*/
adm1026_open, /* open */
adm1026_close, /* close */
nodev, /* strategy */
nodev, /* print */
nodev, /* dump */
nodev, /* read */
nodev, /* write */
adm1026_ioctl, /* ioctl */
nodev, /* devmap */
nodev, /* mmap */
nodev, /* segmap */
nochpoll, /* poll */
ddi_prop_op, /* cb_prop_op */
NULL, /* streamtab */
CB_REV, /* rev */
nodev, /* int (*cb_aread)() */
nodev /* int (*cb_awrite)() */
};
/*
* dev ops
*/
0,
NULL,
NULL,
ddi_quiesce_not_needed, /* quiesce */
};
extern struct mod_ops mod_driverops;
&mod_driverops, /* type of module - driver */
"ADM1026 i2c device driver",
};
0
};
int
_init(void)
{
int error;
if (!error)
(void) ddi_soft_state_init(&adm1026soft_statep,
sizeof (struct adm1026_unit), 1);
return (error);
}
int
_fini(void)
{
int error;
if (!error)
return (error);
}
int
{
}
static int
{
int instance;
int error = 0;
if (instance < 0) {
return (ENXIO);
}
unitp = (struct adm1026_unit *)
return (ENXIO);
}
return (EINVAL);
}
if (unitp->adm1026_oflag != 0) {
} else {
}
} else {
} else {
}
}
return (error);
}
static int
{
int instance;
if (instance < 0) {
return (ENXIO);
}
unitp = (struct adm1026_unit *)
return (ENXIO);
}
unitp->adm1026_oflag = 0;
return (DDI_SUCCESS);
}
static int
{
switch (cmd) {
case DDI_ATTACH:
return (adm1026_do_attach(dip));
case DDI_RESUME:
return (adm1026_do_resume());
default:
return (DDI_FAILURE);
}
}
static int
{
switch (cmd) {
case DDI_DETACH:
return (adm1026_do_detach(dip));
case DDI_SUSPEND:
return (adm1026_do_suspend());
default:
return (DDI_FAILURE);
}
}
static int
{
int instance;
return (DDI_FAILURE);
}
return (ENOMEM);
}
"adm1026_do_attach: ddi_create_minor_node failed");
return (DDI_FAILURE);
}
"adm1026_do_attach: i2c_client_register failed");
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
static int
adm1026_do_resume(void)
{
return (ret);
}
static int
{
return (ret);
}
static int
{
int instance;
"adm1026_do_detach: ddi_get_soft_state failed");
return (ENOMEM);
}
return (DDI_SUCCESS);
}
static int
{
if (i2c_tran_pointer == NULL)
return (ENOMEM);
if (err) {
"adm1026_get8: I2C_WR_RD reg=0x%x failed", reg));
} else {
}
return (err);
}
static int
{
2, 0, I2C_SLEEP);
if (i2c_tran_pointer == NULL)
return (ENOMEM);
if (err)
return (err);
}
/*
* adm1026_send8:
* Read the i2c register, apply the mask to contents so that only
* bits in mask affected. Or in value and write it back to the i2c register.
*/
static int
{
int err;
return (err);
}
/*
* adm1026_set_output:
* The low 16 bits of the mask is a 1:1 mask indicating which of the
* 16 GPIO pin(s) to set.
*/
static int
{
if (mask & 0xff)
return (err);
}
/*
* adm1026_get_output:
* The low 16 bits of the mask is a 1:1 mask indicating which of the
* 16 GPIO pin(s) to get.
*/
static int
{
if (mask & 0xff) {
if (err != I2C_SUCCESS)
return (err);
}
if (mask & 0xff00) {
if (err != I2C_SUCCESS)
return (err);
}
return (err);
}
/*
* adm1026_set_config:
* The low 16 bits of the mask is a 1:1 mask indicating which of the
* 16 GPIO pin(s) to set the polarity or direction configuration for.
* Each GPIO pin has 2 bits of configuration - 1 polarity bit and 1
* direction bit. Traverse the mask 4 bits at a time to determine
* which of the 4 GPIO Config registers to access and apply the value
* based on whether cmd is GPIO_SET_CONFIG (set Direction) or
* GPIO_SET_POLARITY.
*/
static int
{
int i;
uint8_t r;
for (i = 0, r = ADM1026_GPIO_CFG1; i < BYTES_PER_CONFIG; i++, r++) {
if (m & GPIO_CFG_MASK) {
int j;
for (j = 0; j < GPIOS_PER_CFG_BYTE; j++) {
if (m & (1 << j)) {
}
if (v & (1 << j)) {
}
}
if (err != I2C_SUCCESS)
return (err);
}
m >>= GPIOS_PER_CFG_BYTE;
v >>= GPIOS_PER_CFG_BYTE;
}
return (err);
}
/*
* adm1026_get_config:
* The low 16 bits of the mask is a 1:1 mask indicating which of the
* 16 GPIO pin(s) to get the polarity or direction configuration for.
* Each GPIO pin has 2 bits of configuration - 1 polarity bit and 1
* direction bit. Traverse the mask 4 bits at a time to determine
* which of the 4 GPIO Config registers to access and build the return
* value based on whether cmd is GPIO_GET_CONFIG (get Direction) or
* GPIO_GET_POLARITY.
*/
static int
{
int i, j;
uint8_t r;
*val = 0;
for (i = 0, r = ADM1026_GPIO_CFG1; i < BYTES_PER_CONFIG; i++, r++) {
if (mask & GPIO_CFG_MASK) {
if (err != I2C_SUCCESS)
return (err);
for (j = 0; j < GPIOS_PER_CFG_BYTE; j++) {
if (mask & (1 << j)) {
if (x & (bit << (j * BITSPERCFG)))
newval |= (1 << j);
}
}
} else
}
return (err);
}
static int
int *rvalp)
{
int instance;
int err = DDI_SUCCESS;
unitp = (struct adm1026_unit *)
return (err);
}
return (EFAULT);
}
"adm1026_ioctl: reg_mask too large. "
"Only bits 15-0 supported");
return (EINVAL);
}
switch (cmd) {
case GPIO_SET_OUTPUT:
break;
case GPIO_GET_OUTPUT:
if (err == DDI_SUCCESS)
sizeof (i2c_gpio_t), mode);
break;
case GPIO_SET_CONFIG:
case GPIO_SET_POLARITY:
break;
case GPIO_GET_CONFIG:
case GPIO_GET_POLARITY:
if (err == DDI_SUCCESS)
sizeof (i2c_gpio_t), mode);
break;
default:
"adm1026_ioctl: Invalid ioctl cmd %x\n", cmd));
}
if (err) {
"adm1026_ioctl: failed, err=%x\n", err));
if (err == DDI_FAILURE)
}
return (err);
}