/*---------------------------------------------------------------------------*/ static int __init mt_gpio_init(void) { int ret = 0; GPIOLOG("version: %s\n", VERSION); ret = platform_driver_register(&gpio_driver); return ret; }
/*---------------------------------------------------------------------------*/ static int mt_gpio_probe(struct platform_device *dev) { int err; struct miscdevice *misc = &mt_gpio_device; //printk(KERN_ALERT"[GPIO]%5d,<%s> gpio devices probe\n", __LINE__, __func__); GPIOLOG("Registering GPIO device\n"); if (!mt_gpio) GPIO_RETERR(-EACCES, ""); mt_gpio->misc = misc; if ((err = misc_register(misc))) GPIOERR("register gpio\n"); if ((err = mt_gpio_create_attr(misc->this_device))) GPIOERR("create attribute\n"); dev_set_drvdata(misc->this_device, mt_gpio); return err; }
void mt_gpio_self_test(void) { int i, val; for (i = 0; i < MT_GPIO_EXT_MAX; i++) { s32 res,old; GPIOMSG("GPIO-%3d test\n", i); /*direction test*/ old = mt_get_gpio_dir(i); if (old == 0 || old == 1) { GPIOLOG(" dir old = %d\n", old); } else { GPIOERR(" test dir fail: %d\n", old); break; } if ((res = mt_set_gpio_dir(i, GPIO_DIR_OUT)) != RSUCCESS) { GPIOERR(" set dir out fail: %d\n", res); break; } else if ((res = mt_get_gpio_dir(i)) != GPIO_DIR_OUT) { GPIOERR(" get dir out fail: %d\n", res); break; } else { /*output test*/ s32 out = mt_get_gpio_out(i); if (out != 0 && out != 1) { GPIOERR(" get out fail = %d\n", old); break; } for (val = 0; val < GPIO_OUT_MAX; val++) { if ((res = mt_set_gpio_out(i,0)) != RSUCCESS) { GPIOERR(" set out[%d] fail: %d\n", val, res); break; } else if ((res = mt_get_gpio_out(i)) != 0) { GPIOERR(" get out[%d] fail: %d\n", val, res); break; } } if ((res = mt_set_gpio_out(i,out)) != RSUCCESS) { GPIOERR(" restore out fail: %d\n", res); break; } } if ((res = mt_set_gpio_dir(i, GPIO_DIR_IN)) != RSUCCESS) { GPIOERR(" set dir in fail: %d\n", res); break; } else if ((res = mt_get_gpio_dir(i)) != GPIO_DIR_IN) { GPIOERR(" get dir in fail: %d\n", res); break; } else { GPIOLOG(" input data = %d\n", res); } if ((res = mt_set_gpio_dir(i, old)) != RSUCCESS) { GPIOERR(" restore dir fail: %d\n", res); break; } for (val = 0; val < GPIO_PULL_EN_MAX; val++) { if ((res = mt_set_gpio_pull_enable(i,val)) != RSUCCESS) { GPIOERR(" set pullen[%d] fail: %d\n", val, res); break; } else if ((res = mt_get_gpio_pull_enable(i)) != val) { GPIOERR(" get pullen[%d] fail: %d\n", val, res); break; } } if ((res = mt_set_gpio_pull_enable(i, old)) != RSUCCESS) { GPIOERR(" restore pullen fail: %d\n", res); break; } /*pull select test*/ old = mt_get_gpio_pull_select(i); if (old == 0 || old == 1) GPIOLOG(" pullsel old = %d\n", old); else { GPIOERR(" pullsel fail: %d\n", old); break; } for (val = 0; val < GPIO_PULL_MAX; val++) { if ((res = mt_set_gpio_pull_select(i,val)) != RSUCCESS) { GPIOERR(" set pullsel[%d] fail: %d\n", val, res); break; } else if ((res = mt_get_gpio_pull_select(i)) != val) { GPIOERR(" get pullsel[%d] fail: %d\n", val, res); break; } } if ((res = mt_set_gpio_pull_select(i, old)) != RSUCCESS) { GPIOERR(" restore pullsel fail: %d\n", res); break; } /*data inversion*/ old = mt_get_gpio_inversion(i); if (old == 0 || old == 1) GPIOLOG(" inv old = %d\n", old); else { GPIOERR(" inv fail: %d\n", old); break; } for (val = 0; val < GPIO_DATA_INV_MAX; val++) { if ((res = mt_set_gpio_inversion(i,val)) != RSUCCESS) { GPIOERR(" set inv[%d] fail: %d\n", val, res); break; } else if ((res = mt_get_gpio_inversion(i)) != val) { GPIOERR(" get inv[%d] fail: %d\n", val, res); break; } } if ((res = mt_set_gpio_inversion(i, old)) != RSUCCESS) { GPIOERR(" restore inv fail: %d\n", res); break; } /*mode control*/ // if((i<=GPIOEXT6) || (i >= GPIOEXT9)){ old = mt_get_gpio_mode(i); if ((old >= GPIO_MODE_00) && (val < GPIO_MODE_MAX)) { GPIOLOG(" mode old = %d\n", old); } else { GPIOERR(" get mode fail: %d\n", old); break; } for (val = 0; val < GPIO_MODE_MAX; val++) { if ((res = mt_set_gpio_mode(i, val)) != RSUCCESS) { GPIOERR("set mode[%d] fail: %d\n", val, res); break; } else if ((res = mt_get_gpio_mode(i)) != val) { GPIOERR("get mode[%d] fail: %d\n", val, res); break; } } if ((res = mt_set_gpio_mode(i,old)) != RSUCCESS) { GPIOERR(" restore mode fail: %d\n", res); break; } // } } GPIOLOG("GPIO test done\n"); }