10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7656SSherry.Moore@Sun.COM * Common Development and Distribution License (the "License").
6*7656SSherry.Moore@Sun.COM * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*7656SSherry.Moore@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23946Smathue * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate
270Sstevel@tonic-gate #include <sys/types.h>
280Sstevel@tonic-gate #include <sys/time.h>
290Sstevel@tonic-gate #include <sys/errno.h>
300Sstevel@tonic-gate #include <sys/cmn_err.h>
310Sstevel@tonic-gate #include <sys/param.h>
320Sstevel@tonic-gate #include <sys/modctl.h>
330Sstevel@tonic-gate #include <sys/conf.h>
340Sstevel@tonic-gate #include <sys/open.h>
350Sstevel@tonic-gate #include <sys/stat.h>
360Sstevel@tonic-gate #include <sys/clock.h>
370Sstevel@tonic-gate #include <sys/gpio_87317.h>
380Sstevel@tonic-gate #include <sys/ddi.h>
390Sstevel@tonic-gate #include <sys/sunddi.h>
400Sstevel@tonic-gate #include <sys/file.h>
410Sstevel@tonic-gate #ifdef DEBUG
420Sstevel@tonic-gate #include <sys/promif.h>
430Sstevel@tonic-gate #endif
440Sstevel@tonic-gate
450Sstevel@tonic-gate
460Sstevel@tonic-gate /* a non zero value causes debug info to be displayed */
470Sstevel@tonic-gate uint_t gpio_debug_flag = 0;
480Sstevel@tonic-gate
490Sstevel@tonic-gate
500Sstevel@tonic-gate #ifdef DEBUG
510Sstevel@tonic-gate static void gpio_debug(dev_info_t *dip, char *format, uint_t arg1, uint_t arg2,
520Sstevel@tonic-gate uint_t arg3, uint_t arg4, uint_t arg5);
530Sstevel@tonic-gate
540Sstevel@tonic-gate #define DBG(dip, format, arg1, arg2, arg3, arg4, arg5) \
550Sstevel@tonic-gate gpio_debug(dip, format, (uint_t)arg1, (uint_t)arg2, (uint_t)arg3, \
560Sstevel@tonic-gate (uint_t)arg4, (uint_t)arg5)
570Sstevel@tonic-gate #else
580Sstevel@tonic-gate #define DBG(dip, format, arg1, arg2, arg3, arg4, arg5)
590Sstevel@tonic-gate #endif
600Sstevel@tonic-gate
610Sstevel@tonic-gate
620Sstevel@tonic-gate /* Driver soft state structure */
630Sstevel@tonic-gate struct gpio_softc {
640Sstevel@tonic-gate dev_info_t *gp_dip;
650Sstevel@tonic-gate kmutex_t gp_mutex;
660Sstevel@tonic-gate int gp_state;
670Sstevel@tonic-gate ddi_acc_handle_t gp_handle;
680Sstevel@tonic-gate uint8_t *gp_regs;
690Sstevel@tonic-gate };
700Sstevel@tonic-gate
710Sstevel@tonic-gate #define getsoftc(minor) \
720Sstevel@tonic-gate ((struct gpio_softc *)ddi_get_soft_state(statep, (minor)))
730Sstevel@tonic-gate
740Sstevel@tonic-gate /* dev_ops and cb_ops entry point function declarations */
750Sstevel@tonic-gate static int gpio_attach(dev_info_t *, ddi_attach_cmd_t);
760Sstevel@tonic-gate static int gpio_detach(dev_info_t *, ddi_detach_cmd_t);
770Sstevel@tonic-gate static int gpio_getinfo(dev_info_t *, ddi_info_cmd_t, void *, void **);
780Sstevel@tonic-gate static int gpio_open(dev_t *, int, int, cred_t *);
790Sstevel@tonic-gate static int gpio_close(dev_t, int, int, cred_t *);
800Sstevel@tonic-gate static int gpio_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
810Sstevel@tonic-gate
820Sstevel@tonic-gate struct cb_ops gpio_cb_ops = {
830Sstevel@tonic-gate gpio_open,
840Sstevel@tonic-gate gpio_close,
850Sstevel@tonic-gate nodev,
860Sstevel@tonic-gate nodev,
870Sstevel@tonic-gate nodev, /* dump */
880Sstevel@tonic-gate nodev,
890Sstevel@tonic-gate nodev,
900Sstevel@tonic-gate gpio_ioctl,
910Sstevel@tonic-gate nodev, /* devmap */
920Sstevel@tonic-gate nodev,
930Sstevel@tonic-gate nodev,
940Sstevel@tonic-gate nochpoll,
950Sstevel@tonic-gate ddi_prop_op,
960Sstevel@tonic-gate NULL, /* for STREAMS drivers */
970Sstevel@tonic-gate D_NEW | D_MP, /* driver compatibility flag */
980Sstevel@tonic-gate CB_REV,
990Sstevel@tonic-gate nodev,
1000Sstevel@tonic-gate nodev
1010Sstevel@tonic-gate };
1020Sstevel@tonic-gate
1030Sstevel@tonic-gate static struct dev_ops gpio_dev_ops = {
1040Sstevel@tonic-gate DEVO_REV, /* driver build version */
1050Sstevel@tonic-gate 0, /* device reference count */
1060Sstevel@tonic-gate gpio_getinfo,
1070Sstevel@tonic-gate nulldev,
1080Sstevel@tonic-gate nulldev, /* probe */
1090Sstevel@tonic-gate gpio_attach,
1100Sstevel@tonic-gate gpio_detach,
1110Sstevel@tonic-gate nulldev, /* reset */
1120Sstevel@tonic-gate &gpio_cb_ops,
1130Sstevel@tonic-gate (struct bus_ops *)NULL,
114*7656SSherry.Moore@Sun.COM nulldev, /* power */
115*7656SSherry.Moore@Sun.COM ddi_quiesce_not_needed, /* quiesce */
1160Sstevel@tonic-gate };
1170Sstevel@tonic-gate
1180Sstevel@tonic-gate /* module configuration stuff */
1190Sstevel@tonic-gate static void *statep;
1200Sstevel@tonic-gate extern struct mod_ops mod_driverops;
1210Sstevel@tonic-gate static struct modldrv modldrv = {
1220Sstevel@tonic-gate &mod_driverops,
123*7656SSherry.Moore@Sun.COM "gpio driver",
1240Sstevel@tonic-gate &gpio_dev_ops
1250Sstevel@tonic-gate };
1260Sstevel@tonic-gate static struct modlinkage modlinkage = {
1270Sstevel@tonic-gate MODREV_1,
1280Sstevel@tonic-gate &modldrv,
1290Sstevel@tonic-gate 0
1300Sstevel@tonic-gate };
1310Sstevel@tonic-gate
1320Sstevel@tonic-gate
1330Sstevel@tonic-gate int
_init(void)1340Sstevel@tonic-gate _init(void)
1350Sstevel@tonic-gate {
1360Sstevel@tonic-gate int e;
1370Sstevel@tonic-gate
1380Sstevel@tonic-gate if (e = ddi_soft_state_init(&statep, sizeof (struct gpio_softc), 1)) {
1390Sstevel@tonic-gate return (e);
1400Sstevel@tonic-gate }
1410Sstevel@tonic-gate if ((e = mod_install(&modlinkage)) != 0) {
1420Sstevel@tonic-gate ddi_soft_state_fini(&statep);
1430Sstevel@tonic-gate }
1440Sstevel@tonic-gate
1450Sstevel@tonic-gate return (e);
1460Sstevel@tonic-gate }
1470Sstevel@tonic-gate
1480Sstevel@tonic-gate
1490Sstevel@tonic-gate int
_fini(void)1500Sstevel@tonic-gate _fini(void)
1510Sstevel@tonic-gate {
1520Sstevel@tonic-gate int e;
1530Sstevel@tonic-gate
1540Sstevel@tonic-gate if ((e = mod_remove(&modlinkage)) != 0) {
1550Sstevel@tonic-gate return (e);
1560Sstevel@tonic-gate }
1570Sstevel@tonic-gate ddi_soft_state_fini(&statep);
1580Sstevel@tonic-gate
1590Sstevel@tonic-gate return (DDI_SUCCESS);
1600Sstevel@tonic-gate }
1610Sstevel@tonic-gate
1620Sstevel@tonic-gate
1630Sstevel@tonic-gate int
_info(struct modinfo * modinfop)1640Sstevel@tonic-gate _info(struct modinfo *modinfop)
1650Sstevel@tonic-gate {
1660Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop));
1670Sstevel@tonic-gate }
1680Sstevel@tonic-gate
1690Sstevel@tonic-gate
1700Sstevel@tonic-gate /* ARGSUSED */
1710Sstevel@tonic-gate static int
gpio_getinfo(dev_info_t * dip,ddi_info_cmd_t cmd,void * arg,void ** result)1720Sstevel@tonic-gate gpio_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result)
1730Sstevel@tonic-gate {
1740Sstevel@tonic-gate int instance = getminor((dev_t)arg);
1750Sstevel@tonic-gate int retval = DDI_SUCCESS;
1760Sstevel@tonic-gate struct gpio_softc *softc;
1770Sstevel@tonic-gate
1780Sstevel@tonic-gate switch (cmd) {
1790Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO:
1800Sstevel@tonic-gate if ((softc = getsoftc(instance)) == NULL) {
1810Sstevel@tonic-gate *result = (void *)NULL;
1820Sstevel@tonic-gate retval = DDI_FAILURE;
1830Sstevel@tonic-gate } else
1840Sstevel@tonic-gate *result = (void *)softc->gp_dip;
1850Sstevel@tonic-gate break;
1860Sstevel@tonic-gate
1870Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE:
188946Smathue *result = (void *)(uintptr_t)instance;
1890Sstevel@tonic-gate break;
1900Sstevel@tonic-gate
1910Sstevel@tonic-gate default:
1920Sstevel@tonic-gate retval = DDI_FAILURE;
1930Sstevel@tonic-gate }
1940Sstevel@tonic-gate
1950Sstevel@tonic-gate return (retval);
1960Sstevel@tonic-gate }
1970Sstevel@tonic-gate
1980Sstevel@tonic-gate
1990Sstevel@tonic-gate static int
gpio_attach(dev_info_t * dip,ddi_attach_cmd_t cmd)2000Sstevel@tonic-gate gpio_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
2010Sstevel@tonic-gate {
2020Sstevel@tonic-gate
2030Sstevel@tonic-gate int instance;
2040Sstevel@tonic-gate struct gpio_softc *softc = NULL;
2050Sstevel@tonic-gate ddi_device_acc_attr_t dev_attr;
2060Sstevel@tonic-gate
2070Sstevel@tonic-gate switch (cmd) {
2080Sstevel@tonic-gate
2090Sstevel@tonic-gate case DDI_ATTACH:
2100Sstevel@tonic-gate
2110Sstevel@tonic-gate /* Allocate and get the soft state structure for this instance. */
2120Sstevel@tonic-gate
213*7656SSherry.Moore@Sun.COM instance = ddi_get_instance(dip);
214*7656SSherry.Moore@Sun.COM DBG(dip, "attach: instance is %d", instance, 0, 0, 0, 0);
215*7656SSherry.Moore@Sun.COM if (ddi_soft_state_zalloc(statep, instance) != DDI_SUCCESS)
2160Sstevel@tonic-gate goto attach_failed;
217*7656SSherry.Moore@Sun.COM softc = getsoftc(instance);
218*7656SSherry.Moore@Sun.COM softc->gp_dip = dip;
219*7656SSherry.Moore@Sun.COM softc->gp_state = 0;
220*7656SSherry.Moore@Sun.COM mutex_init(&softc->gp_mutex, NULL, MUTEX_DRIVER, NULL);
2210Sstevel@tonic-gate
2220Sstevel@tonic-gate /* Map in the gpio device registers. */
2230Sstevel@tonic-gate
224*7656SSherry.Moore@Sun.COM dev_attr.devacc_attr_version = DDI_DEVICE_ATTR_V0;
225*7656SSherry.Moore@Sun.COM dev_attr.devacc_attr_endian_flags = DDI_NEVERSWAP_ACC;
226*7656SSherry.Moore@Sun.COM dev_attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC;
227*7656SSherry.Moore@Sun.COM if (ddi_regs_map_setup(dip, 0, (caddr_t *)&softc->gp_regs, 0, 0,
2280Sstevel@tonic-gate &dev_attr, &softc->gp_handle) != DDI_SUCCESS)
2290Sstevel@tonic-gate goto attach_failed;
230*7656SSherry.Moore@Sun.COM DBG(dip, "attach: regs=0x%p", (uintptr_t)softc->gp_regs,
231*7656SSherry.Moore@Sun.COM 0, 0, 0, 0);
232*7656SSherry.Moore@Sun.COM DBG(dip, "attach: port 1 data is %x",
233*7656SSherry.Moore@Sun.COM (uintptr_t)ddi_get8(softc->gp_handle, &softc->gp_regs[0]),
234*7656SSherry.Moore@Sun.COM 0, 0, 0, 0);
235*7656SSherry.Moore@Sun.COM DBG(dip, "attach: port 1 direction is %x",
236*7656SSherry.Moore@Sun.COM (uintptr_t)ddi_get8(softc->gp_handle, &softc->gp_regs[1]),
237*7656SSherry.Moore@Sun.COM 0, 0, 0, 0);
238*7656SSherry.Moore@Sun.COM DBG(dip, "attach: port 1 output type is %x",
239*7656SSherry.Moore@Sun.COM (uintptr_t)ddi_get8(softc->gp_handle, &softc->gp_regs[2]),
240*7656SSherry.Moore@Sun.COM 0, 0, 0, 0);
241*7656SSherry.Moore@Sun.COM DBG(dip, "attach: port 1 pull up control type is %x",
242*7656SSherry.Moore@Sun.COM (uintptr_t)ddi_get8(softc->gp_handle, &softc->gp_regs[3]),
243*7656SSherry.Moore@Sun.COM 0, 0, 0, 0);
244*7656SSherry.Moore@Sun.COM DBG(dip, "attach: port 2 data is %x",
245*7656SSherry.Moore@Sun.COM (uintptr_t)ddi_get8(softc->gp_handle, &softc->gp_regs[4]),
246*7656SSherry.Moore@Sun.COM 0, 0, 0, 0);
247*7656SSherry.Moore@Sun.COM DBG(dip, "attach: port 2 direction is %x",
248*7656SSherry.Moore@Sun.COM (uintptr_t)ddi_get8(softc->gp_handle, &softc->gp_regs[5]),
249*7656SSherry.Moore@Sun.COM 0, 0, 0, 0);
250*7656SSherry.Moore@Sun.COM DBG(dip, "attach: port 2 output type is %x",
251*7656SSherry.Moore@Sun.COM (uintptr_t)ddi_get8(softc->gp_handle, &softc->gp_regs[6]),
252*7656SSherry.Moore@Sun.COM 0, 0, 0, 0);
253*7656SSherry.Moore@Sun.COM DBG(dip, "attach: port 2 pull up control type is %x",
254*7656SSherry.Moore@Sun.COM (uintptr_t)ddi_get8(softc->gp_handle, &softc->gp_regs[7]),
255*7656SSherry.Moore@Sun.COM 0, 0, 0, 0);
2560Sstevel@tonic-gate
2570Sstevel@tonic-gate /* Create device minor nodes. */
2580Sstevel@tonic-gate
259*7656SSherry.Moore@Sun.COM if (ddi_create_minor_node(dip, "gpio", S_IFCHR,
260*7656SSherry.Moore@Sun.COM instance, NULL, NULL) == DDI_FAILURE) {
261*7656SSherry.Moore@Sun.COM ddi_regs_map_free(&softc->gp_handle);
262*7656SSherry.Moore@Sun.COM goto attach_failed;
263*7656SSherry.Moore@Sun.COM }
2640Sstevel@tonic-gate
265*7656SSherry.Moore@Sun.COM ddi_report_dev(dip);
266*7656SSherry.Moore@Sun.COM return (DDI_SUCCESS);
2670Sstevel@tonic-gate
2680Sstevel@tonic-gate case DDI_RESUME:
2690Sstevel@tonic-gate
2700Sstevel@tonic-gate /* Nothing to do for a resume. */
2710Sstevel@tonic-gate
272*7656SSherry.Moore@Sun.COM return (DDI_SUCCESS);
2730Sstevel@tonic-gate
2740Sstevel@tonic-gate default:
275*7656SSherry.Moore@Sun.COM return (DDI_FAILURE);
2760Sstevel@tonic-gate }
2770Sstevel@tonic-gate
2780Sstevel@tonic-gate attach_failed:
2790Sstevel@tonic-gate if (softc) {
280*7656SSherry.Moore@Sun.COM mutex_destroy(&softc->gp_mutex);
281*7656SSherry.Moore@Sun.COM if (softc->gp_handle)
282*7656SSherry.Moore@Sun.COM ddi_regs_map_free(&softc->gp_handle);
283*7656SSherry.Moore@Sun.COM ddi_soft_state_free(statep, instance);
284*7656SSherry.Moore@Sun.COM ddi_remove_minor_node(dip, NULL);
2850Sstevel@tonic-gate }
2860Sstevel@tonic-gate return (DDI_FAILURE);
2870Sstevel@tonic-gate }
2880Sstevel@tonic-gate
2890Sstevel@tonic-gate
2900Sstevel@tonic-gate static int
gpio_detach(dev_info_t * dip,ddi_detach_cmd_t cmd)2910Sstevel@tonic-gate gpio_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
2920Sstevel@tonic-gate {
2930Sstevel@tonic-gate int instance;
2940Sstevel@tonic-gate struct gpio_softc *softc;
2950Sstevel@tonic-gate
2960Sstevel@tonic-gate switch (cmd) {
2970Sstevel@tonic-gate case DDI_DETACH:
2980Sstevel@tonic-gate instance = ddi_get_instance(dip);
2990Sstevel@tonic-gate DBG(dip, "detach: instance is %d", instance, 0, 0, 0, 0);
3000Sstevel@tonic-gate if ((softc = getsoftc(instance)) == NULL)
3010Sstevel@tonic-gate return (ENXIO);
3020Sstevel@tonic-gate mutex_destroy(&softc->gp_mutex);
3030Sstevel@tonic-gate ddi_regs_map_free(&softc->gp_handle);
3040Sstevel@tonic-gate ddi_soft_state_free(statep, instance);
3050Sstevel@tonic-gate ddi_remove_minor_node(dip, NULL);
3060Sstevel@tonic-gate return (DDI_SUCCESS);
3070Sstevel@tonic-gate
3080Sstevel@tonic-gate case DDI_SUSPEND:
3090Sstevel@tonic-gate /* Nothing to do in the suspend case. */
3100Sstevel@tonic-gate return (DDI_SUCCESS);
3110Sstevel@tonic-gate
3120Sstevel@tonic-gate default:
3130Sstevel@tonic-gate return (DDI_FAILURE);
3140Sstevel@tonic-gate }
3150Sstevel@tonic-gate }
3160Sstevel@tonic-gate
3170Sstevel@tonic-gate
3180Sstevel@tonic-gate /* ARGSUSED */
3190Sstevel@tonic-gate static int
gpio_open(dev_t * devp,int flag,int otyp,cred_t * credp)3200Sstevel@tonic-gate gpio_open(dev_t *devp, int flag, int otyp, cred_t *credp)
3210Sstevel@tonic-gate {
3220Sstevel@tonic-gate int instance = getminor(*devp);
3230Sstevel@tonic-gate
3240Sstevel@tonic-gate DBG(NULL, "open: instance is %d", instance, 0, 0, 0, 0);
3250Sstevel@tonic-gate return (getsoftc(instance) == NULL ? ENXIO : 0);
3260Sstevel@tonic-gate }
3270Sstevel@tonic-gate
3280Sstevel@tonic-gate
3290Sstevel@tonic-gate /* ARGSUSED */
3300Sstevel@tonic-gate static int
gpio_close(dev_t dev,int flag,int otyp,cred_t * credp)3310Sstevel@tonic-gate gpio_close(dev_t dev, int flag, int otyp, cred_t *credp)
3320Sstevel@tonic-gate {
3330Sstevel@tonic-gate int instance = getminor(dev);
3340Sstevel@tonic-gate
3350Sstevel@tonic-gate DBG(NULL, "close: instance is %d", instance, 0, 0, 0, 0);
3360Sstevel@tonic-gate return (getsoftc(instance) == NULL ? ENXIO : 0);
3370Sstevel@tonic-gate }
3380Sstevel@tonic-gate
3390Sstevel@tonic-gate
3400Sstevel@tonic-gate /* ARGSUSED */
3410Sstevel@tonic-gate static int
gpio_ioctl(dev_t dev,int cmd,intptr_t arg,int mode,cred_t * credp,int * rvalp)3420Sstevel@tonic-gate gpio_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp,
3430Sstevel@tonic-gate int *rvalp)
3440Sstevel@tonic-gate {
3450Sstevel@tonic-gate int instance = getminor(dev);
3460Sstevel@tonic-gate struct gpio_softc *softc = getsoftc(instance);
3470Sstevel@tonic-gate gpio_87317_op_t info;
3480Sstevel@tonic-gate uint8_t byte;
3490Sstevel@tonic-gate
3500Sstevel@tonic-gate DBG(softc->gp_dip, "ioctl: instance is %d", instance, 0, 0, 0, 0);
3510Sstevel@tonic-gate
3520Sstevel@tonic-gate if (softc == NULL)
3530Sstevel@tonic-gate return (ENXIO);
3540Sstevel@tonic-gate
3550Sstevel@tonic-gate /* Copy the command from user space. */
3560Sstevel@tonic-gate if (ddi_copyin((caddr_t)arg, (caddr_t)&info, sizeof (gpio_87317_op_t),
3570Sstevel@tonic-gate mode) != 0)
3580Sstevel@tonic-gate return (EFAULT);
3590Sstevel@tonic-gate
3600Sstevel@tonic-gate /* Check the command arguments. We only support port 1 in bank 0. */
3610Sstevel@tonic-gate if ((info.gpio_bank != 0) ||
3620Sstevel@tonic-gate (info.gpio_offset != GPIO_87317_PORT1_DATA)) {
3630Sstevel@tonic-gate return (EINVAL);
3640Sstevel@tonic-gate }
3650Sstevel@tonic-gate
3660Sstevel@tonic-gate /* Grap the instance's mutex to insure exclusive access. */
3670Sstevel@tonic-gate mutex_enter(&softc->gp_mutex);
3680Sstevel@tonic-gate
3690Sstevel@tonic-gate /* Get the contents of the GPIO register we're suppose to modify. */
3700Sstevel@tonic-gate byte = ddi_get8(softc->gp_handle, &softc->gp_regs[info.gpio_offset]);
3710Sstevel@tonic-gate
3720Sstevel@tonic-gate switch (cmd) {
3730Sstevel@tonic-gate case GPIO_CMD_SET_BITS:
3740Sstevel@tonic-gate DBG(softc->gp_dip, "ioctl: SET_BITS, byte is %x", byte, 0, 0,
3750Sstevel@tonic-gate 0, 0);
3760Sstevel@tonic-gate byte |= info.gpio_data;
3770Sstevel@tonic-gate ddi_put8(softc->gp_handle, &softc->gp_regs[info.gpio_offset],
3780Sstevel@tonic-gate byte);
3790Sstevel@tonic-gate byte = ddi_get8(softc->gp_handle,
3800Sstevel@tonic-gate &softc->gp_regs[info.gpio_offset]);
3810Sstevel@tonic-gate DBG(softc->gp_dip, "ioctl: SET_BITS, byte is %x", byte, 0, 0,
3820Sstevel@tonic-gate 0, 0);
3830Sstevel@tonic-gate break;
3840Sstevel@tonic-gate
3850Sstevel@tonic-gate case GPIO_CMD_CLR_BITS:
3860Sstevel@tonic-gate DBG(softc->gp_dip, "ioctl: CLR_BITS, byte is %x", byte, 0, 0,
3870Sstevel@tonic-gate 0, 0);
3880Sstevel@tonic-gate byte &= ~info.gpio_data;
3890Sstevel@tonic-gate ddi_put8(softc->gp_handle, &softc->gp_regs[info.gpio_offset],
3900Sstevel@tonic-gate byte);
3910Sstevel@tonic-gate byte = ddi_get8(softc->gp_handle,
3920Sstevel@tonic-gate &softc->gp_regs[info.gpio_offset]);
3930Sstevel@tonic-gate DBG(softc->gp_dip, "ioctl: CLR_BITS, byte is %x", byte, 0, 0,
3940Sstevel@tonic-gate 0, 0);
3950Sstevel@tonic-gate break;
3960Sstevel@tonic-gate
3970Sstevel@tonic-gate case GPIO_CMD_GET:
3980Sstevel@tonic-gate DBG(softc->gp_dip, "ioctl: GPIO_CMD_GET", 0, 0, 0, 0, 0);
3990Sstevel@tonic-gate info.gpio_data = byte;
4000Sstevel@tonic-gate if (ddi_copyout((caddr_t)&info, (caddr_t)arg,
4010Sstevel@tonic-gate sizeof (gpio_87317_op_t), mode) != 0) {
4020Sstevel@tonic-gate mutex_exit(&softc->gp_mutex);
4030Sstevel@tonic-gate return (EFAULT);
4040Sstevel@tonic-gate }
4050Sstevel@tonic-gate break;
4060Sstevel@tonic-gate
4070Sstevel@tonic-gate case GPIO_CMD_SET:
4080Sstevel@tonic-gate DBG(softc->gp_dip, "ioctl: GPIO_CMD_SET", 0, 0, 0, 0, 0);
4090Sstevel@tonic-gate ddi_put8(softc->gp_handle, &softc->gp_regs[info.gpio_offset],
4100Sstevel@tonic-gate info.gpio_data);
4110Sstevel@tonic-gate break;
4120Sstevel@tonic-gate
4130Sstevel@tonic-gate default:
4140Sstevel@tonic-gate mutex_exit(&softc->gp_mutex);
4150Sstevel@tonic-gate return (EINVAL);
4160Sstevel@tonic-gate }
4170Sstevel@tonic-gate
4180Sstevel@tonic-gate mutex_exit(&softc->gp_mutex);
4190Sstevel@tonic-gate return (0);
4200Sstevel@tonic-gate }
4210Sstevel@tonic-gate
4220Sstevel@tonic-gate
4230Sstevel@tonic-gate #ifdef DEBUG
4240Sstevel@tonic-gate void
gpio_debug(dev_info_t * dip,char * format,uint_t arg1,uint_t arg2,uint_t arg3,uint_t arg4,uint_t arg5)4250Sstevel@tonic-gate gpio_debug(dev_info_t *dip, char *format, uint_t arg1, uint_t arg2, uint_t arg3,
4260Sstevel@tonic-gate uint_t arg4, uint_t arg5)
4270Sstevel@tonic-gate {
4280Sstevel@tonic-gate if (gpio_debug_flag == 0) {
4290Sstevel@tonic-gate return;
4300Sstevel@tonic-gate }
4310Sstevel@tonic-gate
4320Sstevel@tonic-gate if (dip == NULL) {
4330Sstevel@tonic-gate prom_printf("gpio: ");
4340Sstevel@tonic-gate } else {
4350Sstevel@tonic-gate prom_printf("%s%d: ", ddi_driver_name(dip),
436*7656SSherry.Moore@Sun.COM ddi_get_instance(dip));
4370Sstevel@tonic-gate }
4380Sstevel@tonic-gate prom_printf(format, arg1, arg2, arg3, arg4, arg5);
4390Sstevel@tonic-gate prom_printf("\n");
4400Sstevel@tonic-gate }
4410Sstevel@tonic-gate #endif
442