static void usb_irq_disable(void) { u8 val; /* undo edge setup */ if (twl4030_i2c_read_u8(TWL4030_MODULE_INT, &val, REG_PWR_EDR1) < 0) { printk(KERN_ERR "twl4030_usb: i2c read failed," " line %d\n", __LINE__); return; } val &= ~(USB_PRES_RISING | USB_PRES_FALLING); if (twl4030_i2c_write_u8_verify(TWL4030_MODULE_INT, val, REG_PWR_EDR1) < 0) { printk(KERN_ERR "twl4030_usb: i2c write failed," " line %d\n", __LINE__); return; } /* mask interrupt */ if (twl4030_i2c_read_u8(TWL4030_MODULE_INT, &val, REG_PWR_IMR1) < 0) { printk(KERN_ERR "twl4030_usb: i2c read failed," " line %d\n", __LINE__); return; } val |= USB_PRES; if (twl4030_i2c_write_u8_verify(TWL4030_MODULE_INT, val, REG_PWR_IMR1) < 0) printk(KERN_ERR "twl4030_usb: i2c write failed," " line %d\n", __LINE__); return; }
/* * To mask and unmask MMC Card Detect Interrupt * mask : 1 * unmask : 0 */ static int mask_cd2_interrupt(int mask) { u8 reg = 0, ret = 0; ret = twl4030_i2c_read_u8(TWL4030_MODULE_GPIO, ®, TWL_GPIO_IMR1A); if (ret != 0) goto err; reg = (mask == 1) ? (reg | GPIO_1_BIT_POS) : (reg & ~GPIO_1_BIT_POS); ret = twl4030_i2c_write_u8(TWL4030_MODULE_GPIO, reg, TWL_GPIO_IMR1A); if (ret != 0) goto err; ret = twl4030_i2c_read_u8(TWL4030_MODULE_GPIO, ®, TWL_GPIO_ISR1A); if (ret != 0) goto err; reg = (mask == 1) ? (reg | GPIO_1_BIT_POS) : (reg & ~GPIO_1_BIT_POS); ret = twl4030_i2c_write_u8(TWL4030_MODULE_GPIO, reg, TWL_GPIO_ISR1A); if (ret != 0) goto err; err: return ret; }
static int omapbl_probe(struct platform_device *pdev) { u8 c; omapbl_device = backlight_device_register (OMAPBL_DRVNAME, &pdev->dev, NULL, &omapbl_ops); if (IS_ERR (omapbl_device)) return PTR_ERR (omapbl_device); platform_set_drvdata(pdev, omapbl_device); omapbl_device->props.power = FB_BLANK_UNBLANK; omapbl_device->props.max_brightness = OMAPBL_MAX_INTENSITY; omapbl_device->props.brightness = OMAPBL_DEF_INTENSITY; /* Enable PWM1 and PWM1_CLK in GPBR */ twl4030_i2c_read_u8(TWL4030_MODULE_INTBR, &c, 0x0c); c |= (1 << 3) | (1 << 1); twl4030_i2c_write_u8 (TWL4030_MODULE_INTBR, c, 0x0c); /* Select PWM1 output in PMBR1 */ twl4030_i2c_read_u8(TWL4030_MODULE_INTBR, &c, 0x0d); c |= 0x30; twl4030_i2c_write_u8 (TWL4030_MODULE_INTBR, c, 0x0d); omapbl_set_intensity(omapbl_device); printk(KERN_INFO "omap-backlight: device initialized.\n"); return 0; }
static int __init config_warmreset_sequence(u8 address) { int err = 0; u8 rd_data; /* Set WARM RESET SEQ address for P1 */ err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, address, R_SEQ_ADD_WARM); /* P1/P2/P3 enable WARMRESET */ err |= twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &rd_data, R_P1_SW_EVENTS); rd_data |= ENABLE_WARMRESET; err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, rd_data, R_P1_SW_EVENTS); err |= twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &rd_data, R_P2_SW_EVENTS); rd_data |= ENABLE_WARMRESET; err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, rd_data, R_P2_SW_EVENTS); err |= twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &rd_data, R_P3_SW_EVENTS); rd_data |= ENABLE_WARMRESET; err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, rd_data, R_P3_SW_EVENTS); if (err) printk(KERN_ERR "TWL4030 warmreset seq config error\n"); return err; }
static int omapbl_remove(struct platform_device *pdev) { u8 c; struct backlight_device *bd = platform_get_drvdata(pdev); omapbl_props.power = 0; omapbl_props.brightness = 0; backlight_update_status(bd); /* Disableable PWM1 and PWM1_CLK in GPBR */ twl4030_i2c_read_u8(TWL4030_MODULE_INTBR, &c, 0x0c); c &= ~((1 << 3) | (1 << 1)); twl4030_i2c_write_u8 (TWL4030_MODULE_INTBR, c, 0x0c); /* Restore default/gpio output in PMBR1 */ twl4030_i2c_read_u8(TWL4030_MODULE_INTBR, &c, 0x0d); c &= ~(0x30); twl4030_i2c_write_u8 (TWL4030_MODULE_INTBR, c, 0x0d); backlight_device_unregister(bd); printk(KERN_INFO "omap-backlight: device unloaded.\n"); return 0; }
/* This is called from twl4030-core.c and is required by * MUSB and EHCI on new OMAP3BUG. */ void usb_gpio_settings(void) { unsigned char val; /* enable VAUX2 for EHCI */ /* twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, TWL4030_VAUX2_1P8V, TWL4030_VAUX2_DEDICATED); twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, ENABLE_VAUX2_DEV_GRP, TWL4030_VAUX2_DEV_GRP); */ /* Enable TWL GPIO Module */ twl4030_i2c_write_u8(TWL4030_MODULE_GPIO, 0x04, REG_GPIO_CTRL); /* * Configure GPIO-6 as output */ twl4030_i2c_read_u8(TWL4030_MODULE_GPIO, &val, REG_GPIODATADIR1); val |= 0x4; twl4030_i2c_write_u8(TWL4030_MODULE_GPIO, val, REG_GPIODATADIR1); /* Set GPIO6 = 1 */ twl4030_i2c_read_u8(TWL4030_MODULE_GPIO, &val, REG_GPIODATAOUT1); val |= 0x40; twl4030_i2c_write_u8(TWL4030_MODULE_GPIO, val, REG_GPIODATAOUT1); }
/* * Interrupt service routine * * Attends to BCI interruptions events, * specifically BATSTS (battery connection and removal) * VBATOV (main battery voltage threshold) events * */ static irqreturn_t twl4030battery_interrupt(int irq, void *dev_id) { int ret; u8 isr1a_val, isr2a_val, clear_2a, clear_1a; if ((ret = twl4030_i2c_read_u8(TWL4030_MODULE_INTERRUPTS, &isr1a_val, REG_BCIISR1A))) return IRQ_NONE; if ((ret = twl4030_i2c_read_u8(TWL4030_MODULE_INTERRUPTS, &isr2a_val, REG_BCIISR2A))) return IRQ_NONE; clear_2a = (isr2a_val & VBATLVL_ISR1)? (VBATLVL_ISR1): 0; clear_1a = (isr1a_val & BATSTS_ISR1)? (BATSTS_ISR1): 0; /* cleaning BCI interrupt status flags */ if ((ret = twl4030_i2c_write_u8(TWL4030_MODULE_INTERRUPTS, clear_1a , REG_BCIISR1A))) return IRQ_NONE; if ((ret = twl4030_i2c_write_u8(TWL4030_MODULE_INTERRUPTS, clear_2a , REG_BCIISR2A))) return IRQ_NONE; /* battery connetion or removal event */ if (isr1a_val & BATSTS_ISR1) { ret = twl4030battery_presence_evt(); if (ret == -ENXIO) { twl4030battery_hw_presence_en(EVT_DISABLE); return IRQ_HANDLED; } if (ret) return IRQ_NONE; } /* battery voltage threshold event*/ else if (isr2a_val & VBATLVL_ISR1) { ret = twl4030battery_level_evt(); if (ret == -ENXIO) { twl4030battery_hw_level_en(EVT_DISABLE); return IRQ_HANDLED; } if (ret) return IRQ_NONE; } /* Only for debuging purpouses this branch never be taken */ else return IRQ_NONE; return IRQ_HANDLED; }
static int __init twl4030_config_wakeup12_sequence(u8 address) { int err = 0; u8 data; /* Set SLEEP to ACTIVE SEQ address for P1 and P2 */ err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, address, R_SEQ_ADD_S2A12); if (err) goto out; /* P1/P2 LVL_WAKEUP should be on LEVEL */ err = twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &data, R_P1_SW_EVENTS); if (err) goto out; data |= LVL_WAKEUP; err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, data, R_P1_SW_EVENTS); if (err) goto out; err = twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &data, R_P2_SW_EVENTS); if (err) goto out; data |= LVL_WAKEUP; err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, data, R_P2_SW_EVENTS); if (err) goto out; if (machine_is_omap_3430sdp() || machine_is_omap_ldp()) { /* Disabling AC charger effect on sleep-active transitions */ err = twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &data, R_CFG_P1_TRANSITION); if (err) goto out; data &= ~(1<<1); err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, data , R_CFG_P1_TRANSITION); if (err) goto out; } out: if (err) pr_err("TWL4030 wakeup sequence for P1 and P2" \ "config error\n"); return err; }
/* * Interrupt service routine * * Attends to BCI interruptions events, * specifically BATSTS (battery connection and removal) * VBATOV (main battery voltage threshold) events * */ static irqreturn_t twl4030battery_interrupt(int irq, void *_di) { u8 uninitialized_var(isr1a_val), uninitialized_var(isr2a_val); u8 clear_2a, clear_1a; int ret; #ifdef CONFIG_LOCKDEP /* WORKAROUND for lockdep forcing IRQF_DISABLED on us, which * we don't want and can't tolerate. Although it might be * friendlier not to borrow this thread context... */ local_irq_enable(); #endif ret = twl4030_i2c_read_u8(TWL4030_MODULE_INTERRUPTS, &isr1a_val, REG_BCIISR1A); if (ret) return IRQ_NONE; ret = twl4030_i2c_read_u8(TWL4030_MODULE_INTERRUPTS, &isr2a_val, REG_BCIISR2A); if (ret) return IRQ_NONE; clear_2a = (isr2a_val & VBATLVL_ISR1) ? (VBATLVL_ISR1) : 0; clear_1a = (isr1a_val & BATSTS_ISR1) ? (BATSTS_ISR1) : 0; /* cleaning BCI interrupt status flags */ ret = twl4030_i2c_write_u8(TWL4030_MODULE_INTERRUPTS, clear_1a , REG_BCIISR1A); if (ret) return IRQ_NONE; ret = twl4030_i2c_write_u8(TWL4030_MODULE_INTERRUPTS, clear_2a , REG_BCIISR2A); if (ret) return IRQ_NONE; /* battery connetion or removal event */ if (isr1a_val & BATSTS_ISR1) twl4030battery_presence_evt(); /* battery voltage threshold event*/ else if (isr2a_val & VBATLVL_ISR1) twl4030battery_level_evt(); else return IRQ_NONE; return IRQ_HANDLED; }
static int twl4030_get_bklight_level(void) { if (twl4030_bklight_level == -1) { u8 reg; twl4030_i2c_read_u8(TWL4030_MODULE_INTBR, ®, 0x0c); if (reg & TWL4030_PWM0_ENABLE) { twl4030_i2c_read_u8(TWL4030_MODULE_PWM0, ®, 0x01); twl4030_bklight_level = reg; } else { twl4030_bklight_level = 0; } } return twl4030_bklight_level; }
void __led_toggle(led_id_t mask) { int toggle_gpio = 0; #ifdef CONFIG_LED_STATUS0 if (!toggle_gpio && CONFIG_LED_STATUS_BIT & mask) toggle_gpio = TRICORDER_STATUS_LED_GREEN; #endif #ifdef CONFIG_LED_STATUS1 if (!toggle_gpio && CONFIG_LED_STATUS_BIT1 & mask) toggle_gpio = TRICORDER_STATUS_LED_YELLOW; #endif #ifdef CONFIG_LED_STATUS2 if (!toggle_gpio && CONFIG_LED_STATUS_BIT2 & mask) { uint8_t val; twl4030_i2c_read_u8(TWL4030_CHIP_LED, TWL4030_LED_LEDEN, &val); val ^= (TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDAPWM); twl4030_i2c_write_u8(TWL4030_CHIP_LED, TWL4030_LED_LEDEN, val); } #endif if (toggle_gpio) { int state; gpio_request(toggle_gpio, ""); state = gpio_get_value(toggle_gpio); gpio_set_value(toggle_gpio, !state); } }
static int twl4030_button_stop_off_disable(void) { int err = 0; u8 uninitialized_var(rd_data); err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, TWL4030_LOCK_KEY_1, R_PROTECT_KEY); if (err) { pr_warning("twl4030: button off unable to unlock PROTECT_KEY 1, %x\n",TWL4030_LOCK_KEY_1); return err; } err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, TWL4030_LOCK_KEY_2, R_PROTECT_KEY); if (err) { pr_warning("twl4030: button off unable to unlock PROTECT_KEY 2, %x\n",TWL4030_LOCK_KEY_2); return err; } err |= twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &rd_data, PWR_P1_SW_EVENTS); rd_data &= ~STOPON_PWRON; err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, rd_data, PWR_P1_SW_EVENTS); err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0, R_PROTECT_KEY); if (err) printk(KERN_ERR "TWL4030 button off config error\n"); return err; }
static inline int twl4030_usb_write(struct twl4030_usb *twl, u8 address, u8 data) { int ret = 0; ret = twl4030_i2c_write_u8(TWL4030_MODULE_USB, data, address); if (ret >= 0) { #if 0 /* debug */ u8 data1; if (twl4030_i2c_read_u8(TWL4030_MODULE_USB, &data1, address) < 0) dev_err(twl->dev, "re-read failed\n"); else dev_dbg(twl->dev, "Write %s wrote %x read %x from reg %x\n", (data1 == data) ? "succeed" : "mismatch", data, data1, address); #endif } else { dev_warn(twl->dev, "TWL4030:USB:Write[0x%x] Error %d\n", address, ret); } return ret; }
/* * Return battery voltage * Or < 0 on failure. */ static int twl4030battery_voltage(void) { int ret, volt; u8 hwsts; struct twl4030_madc_request req; twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &hwsts, REG_STS_HW_CONDITIONS); if ((hwsts & STS_CHG) || (hwsts & STS_VBUS)) { /* AC or USB charger connected */ volt = read_bci_val(T2_BATTERY_VOLT); return (volt * VOLT_STEP_SIZE) / VOLT_PSR_R; } else { /* Use madc conversion */ req.channels = (1 << 12); req.do_avg = 0; req.method = TWL4030_MADC_SW1; req.active = 0; req.func_cb = NULL; twl4030_madc_conversion(&req); volt = (u16)req.rbuf[12]; return (volt * VOLT_STEP_SIZE) / VOLT_PSR_R; } }
static int __init config_wakeup12_sequence(u8 address) { int err = 0; /* Set SLEEP to ACTIVE SEQ address for P1 and P2 */ err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, address, R_SEQ_ADD_SA12); /* P1/P2/P3 LVL_WAKEUP should be on LEVEL */ err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, LVL_WAKEUP, R_P1_SW_EVENTS); err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, LVL_WAKEUP, R_P2_SW_EVENTS); if (machine_is_omap_3430sdp() || machine_is_omap_ldp() || machine_is_omap_zoom2() || machine_is_omap_zoom3() || machine_is_omap3630_edp1() || machine_is_omap3621_edp1()) { u8 uninitialized_var(data); /* Disabling AC charger effect on sleep-active transitions */ err |= twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &data, R_CFG_P1_TRANSITION); data &= ~(1<<1); err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, data , R_CFG_P1_TRANSITION); } if (err) printk(KERN_ERR "TWL4030 wakeup sequence for P1 and P2" \ "config error\n"); return err; }
/* * Report and clear the charger presence event. */ static inline int twl4030charger_presence_evt(void) { int ret; u8 uninitialized_var(chg_sts), set = 0, clear = 0; /* read charger power supply status */ ret = twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &chg_sts, REG_STS_HW_CONDITIONS); if (ret) return IRQ_NONE; if (chg_sts & STS_CHG) { /* If the AC charger have been connected */ /* configuring falling edge detection for CHG_PRES */ set = CHG_PRES_FALLING; clear = CHG_PRES_RISING; } else { /* If the AC charger have been disconnected */ /* configuring rising edge detection for CHG_PRES */ set = CHG_PRES_RISING; clear = CHG_PRES_FALLING; } /* Update the interrupt edge detection register */ clear_n_set(TWL4030_MODULE_INT, clear, set, REG_PWR_EDR1); return 0; }
static int twl4030_i2c_write_u8_verify(u8 module, u8 data, u8 address) { u8 check; if ((twl4030_i2c_write_u8(module, data, address) >= 0) && (twl4030_i2c_read_u8(module, &check, address) >= 0) && (check == data)) return 0; /* Failed once: Try again */ if ((twl4030_i2c_write_u8(module, data, address) >= 0) && (twl4030_i2c_read_u8(module, &check, address) >= 0) && (check == data)) return 0; /* Failed again: Return error */ return -EBUSY; }
void twl4030_poweroff(void) { u8 val; int err; err = twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &val, PWR_P1_SW_EVENTS); if (err) { printk(KERN_WARNING "I2C error %d while reading TWL4030" "PM_MASTER P1_SW_EVENTS\n", err); return ; } val |= PWR_DEVOFF; err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, val, PWR_P1_SW_EVENTS); if (err) { printk(KERN_WARNING "I2C error %d while writing TWL4030" "PM_MASTER P1_SW_EVENTS\n", err); return ; } return; }
static irqreturn_t powerbutton_irq(int irq, void *dev_id) { int err; u8 value; #ifdef CONFIG_LOCKDEP /* WORKAROUND for lockdep forcing IRQF_DISABLED on us, which * we don't want and can't tolerate. Although it might be * friendlier not to borrow this thread context... */ local_irq_enable(); #endif err = twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &value, STS_HW_CONDITIONS); if (!err) { input_report_key(powerbutton_dev, KEY_POWER, value & PWR_PWRON_IRQ); } else { pr_err("twl4030: i2c error %d while reading TWL4030" " PM_MASTER STS_HW_CONDITIONS register\n", err); } return IRQ_HANDLED; }
/* * Interrupt service routine * * Attends to TWL 4030 power module interruptions events, * specifically USB_PRES (USB charger presence) CHG_PRES (AC charger presence) events * */ static irqreturn_t twl4030charger_interrupt(int irq, void *dev_id) { u8 int_src, clear = 0; int ret; /* Reading interruption source*/ ret = twl4030_i2c_read_u8(TWL4030_MODULE_INT, &int_src, REG_PWR_ISR1); if (ret) return IRQ_NONE; /* Addition to enable shared interrupt */ if(!(int_src & (USB_PRES | CHG_PRES))) return IRQ_NONE; /* Cleaning interruption flags */ clear = (int_src & USB_PRES)? (clear | USB_PRES): clear; clear = (int_src & CHG_PRES)? (clear | CHG_PRES): clear; ret = twl4030_i2c_write_u8(TWL4030_MODULE_INT, clear, REG_PWR_ISR1); if (ret) return IRQ_NONE; /* fuction to handle charger presence events */ ret = twl4030charger_presence_evt(); if(ret == -ENXIO) twl4030charger_hw_presence_en(EVT_DISABLE); if(ret) return IRQ_NONE; return IRQ_HANDLED; }
int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr, struct ehci_hcor **hcor) { u8 val; int offset; if (gpio_request(SB_T35_USB_HUB_RESET_GPIO, "SB-T35 usb hub reset")) { printf("Error: can't obtain GPIO %d for SB-T35 usb hub reset", SB_T35_USB_HUB_RESET_GPIO); return -1; } gpio_direction_output(SB_T35_USB_HUB_RESET_GPIO, 0); udelay(10); gpio_set_value(SB_T35_USB_HUB_RESET_GPIO, 1); udelay(1000); offset = TWL4030_BASEADD_GPIO + TWL4030_GPIO_GPIODATADIR1; twl4030_i2c_read_u8(TWL4030_CHIP_GPIO, offset, &val); /* Set GPIO6 and GPIO7 of TPS65930 as output */ val |= 0xC0; twl4030_i2c_write_u8(TWL4030_CHIP_GPIO, offset, val); offset = TWL4030_BASEADD_GPIO + TWL4030_GPIO_SETGPIODATAOUT1; /* Take both PHYs out of reset */ twl4030_i2c_write_u8(TWL4030_CHIP_GPIO, offset, 0xC0); udelay(1); return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor); }
/* * Gets current TWL4030 RTC alarm time. */ static int twl4030_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm) { int ret; u8 rtc_interrupts_reg = 0; /* * This returns a struct rtc_time. Reading >= 0xc0 * means "don't care" or "match all". Only the tm_hour, * tm_min, and tm_sec values are filled in. */ memset(&alm->time, 0, sizeof(struct rtc_time)); ret = get_rtc_alm_time(&alm->time); if (ret) goto out; /* Check alarm enabled flag state */ ret = ret | twl4030_i2c_read_u8(TWL4030_MODULE_RTC, &rtc_interrupts_reg, REG_RTC_INTERRUPTS_REG); if (ret) goto out; if ((rtc_interrupts_reg & BIT_RTC_INTERRUPTS_REG_IT_ALARM_M) != 0) alm->enabled = 1; else alm->enabled = 0; out: return ret; }
int status_get_buttons(void) { // convert button state into led state (for mirror) int status=0; if(GPIO_AUX >= 0) status |= ((omap_get_gpio_datain(GPIO_AUX) == GPIO_AUX_ACTIVE) << 0); if(GPIO_GPSEXT >= 0) status |= ((omap_get_gpio_datain(GPIO_GPSEXT)) << 1); if(GPIO_POWER >= 0) status |= ((!omap_get_gpio_datain(GPIO_POWER)) << 3); else { u8 val; i2c_set_bus_num(TWL4030_I2C_BUS); // read I2C1 twl4030_i2c_read_u8(TWL4030_CHIP_PM_MASTER, &val, TWL4030_PM_MASTER_STS_HW_CONDITIONS); // read state of power button (bit 0) from TPS65950 status |= (((val&0x01) != 0) << 3); } if(GPIO_PENIRQ >= 0) status |= ((!omap_get_gpio_datain(GPIO_PENIRQ)) << 4); if(GPIO_KEYIRQ >= 0) status |= ((omap_get_gpio_datain(GPIO_KEYIRQ)) << 5); return status; #if OLD #if defined(CONFIG_OMAP3_GTA04) u8 val; i2c_set_bus_num(TWL4030_I2C_BUS); // read I2C1 twl4030_i2c_read_u8(TWL4030_CHIP_PM_MASTER, &val, TWL4030_PM_MASTER_STS_HW_CONDITIONS); // read state of power button (bit 0) from TPS65950 return ((omap_get_gpio_datain(GPIO_AUX)) << 0) | ((omap_get_gpio_datain(GPIO_GPSEXT)) << 1) | (((val&0x01) != 0) << 3) | ((omap_get_gpio_datain(GPIO_PENIRQ)) << 4); #elif defined(CONFIG_GOLDELICO_EXPANDER_B2) return ((omap_get_gpio_datain(GPIO_AUX)) << 0) | ((0) << 1) | ((GPIO_POWER>=0?(!omap_get_gpio_datain(GPIO_POWER)):0) << 3) | ((omap_get_gpio_datain(GPIO_PENIRQ)) << 4); #else return ((!omap_get_gpio_datain(GPIO_AUX)) << 0) | ((omap_get_gpio_datain(GPIO_GPSEXT)) << 1) | ((GPIO_POWER>=0?(!omap_get_gpio_datain(GPIO_POWER)):0) << 3) | ((omap_get_gpio_datain(GPIO_PENIRQ)) << 4); #endif #endif }
/* * To read a TWL4030 GPIO module register */ static inline int gpio_twl4030_read(u8 address) { u8 data; int ret = 0; ret = twl4030_i2c_read_u8(TWL4030_MODULE_GPIO, &data, address); return (ret < 0) ? ret : data; }
static int twl4030battery_presence_evt(void) { int ret; u8 batstsmchg, batstspchg; /* In case of invalid service event function abandon */ if (twl4030battery_event.battery_presence == NULL) return -ENXIO; /* checking for battery presence in main charge*/ if ((ret = twl4030_i2c_read_u8(TWL4030_MODULE_MAIN_CHARGE, &batstsmchg, REG_BCIMFSTS3))) return ret; /* checking for battery presence in precharge*/ if ((ret = twl4030_i2c_read_u8(TWL4030_MODULE_PRECHARGE, &batstspchg, REG_BCIMFSTS1))) return ret; /* In case of the battery insertion event */ if ((batstspchg & BATSTSPCHG) || (batstsmchg & BATSTSMCHG)) { /* calling the battery presence event service function */ twl4030battery_event.battery_presence(EVT_BATTSTS_CONN); ret = clear_n_set(TWL4030_MODULE_INTERRUPTS, BATSTS_EDRRISIN, BATSTS_EDRFALLING, REG_BCIEDR2); if (ret) return ret; } /* In case of the battery removal event */ else { /* calling the battery presence event service function */ twl4030battery_event.battery_presence(EVT_BATTSTS_DISC); ret = clear_n_set(TWL4030_MODULE_INTERRUPTS, BATSTS_EDRFALLING, BATSTS_EDRRISIN, REG_BCIEDR2); if (ret) return ret; } return 0; }
int twl4030_usb_device_connected(void) { u8 val; /* check if USB connection is present */ twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &val, REG_STS_HW_CONDITIONS); return !!(val & (STS_VBUS | STS_USB)); }
static irqreturn_t twl4030_rtc_interrupt(int irq, void *rtc) { unsigned long events = 0; int ret = IRQ_NONE; int res; u8 rd_reg; #ifdef CONFIG_LOCKDEP /* WORKAROUND for lockdep forcing IRQF_DISABLED on us, which * we don't want and can't tolerate. Although it might be * friendlier not to borrow this thread context... */ local_irq_enable(); #endif res = twl4030_rtc_read_u8(&rd_reg, REG_RTC_STATUS_REG); if (res) goto out; /* * Figure out source of interrupt: ALARM or TIMER in RTC_STATUS_REG. * only one (ALARM or RTC) interrupt source may be enabled * at time, we also could check our results * by reading RTS_INTERRUPTS_REGISTER[IT_TIMER,IT_ALARM] */ if (rd_reg & BIT_RTC_STATUS_REG_ALARM_M) events |= RTC_IRQF | RTC_AF; else events |= RTC_IRQF | RTC_UF; res = twl4030_rtc_write_u8(rd_reg | BIT_RTC_STATUS_REG_ALARM_M, REG_RTC_STATUS_REG); if (res) goto out; /* Clear on Read enabled. RTC_IT bit of TWL4030_INT_PWR_ISR1 * needs 2 reads to clear the interrupt. One read is done in * do_twl4030_pwrirq(). Doing the second read, to clear * the bit. * * FIXME the reason PWR_ISR1 needs an extra read is that * RTC_IF retriggered until we cleared REG_ALARM_M above. * But re-reading like this is a bad hack; by doing so we * risk wrongly clearing status for some other IRQ (losing * the interrupt). Be smarter about handling RTC_UF ... */ res = twl4030_i2c_read_u8(TWL4030_MODULE_INT, &rd_reg, TWL4030_INT_PWR_ISR1); if (res) goto out; /* Notify RTC core on event */ rtc_update_irq(rtc, 1, events); ret = IRQ_HANDLED; out: return ret; }
int board_mmc_getcd(struct mmc *mmc) { u8 val; if (twl4030_i2c_read_u8(TWL4030_CHIP_GPIO, TWL4030_BASEADD_GPIO, &val)) return -1; return !(val & 1); }
int ths8200_init(struct i2c_client *client) { u8 c; int i; int err = 0; //issue THS reset: set reset low, (duration > 200ns) //disable pwm twl4030_i2c_read_u8(TWL4030_MODULE_INTBR, &c, 0x0d); c &= ~(0x30); twl4030_i2c_write_u8 (TWL4030_MODULE_INTBR, c, 0x0d); //set GPIO7 as output - pg 506 twl4030_i2c_read_u8(TWL4030_MODULE_GPIO, &c, 0x03); c |= (0x80); twl4030_i2c_write_u8 (TWL4030_MODULE_GPIO, c, 0x03); //ensure reest line is high twl4030_i2c_read_u8(TWL4030_MODULE_GPIO, &c, 0x06); c |= (0x80); twl4030_i2c_write_u8 (TWL4030_MODULE_GPIO, c, 0x06); mdelay(1); //pull reset line low (min duration 200ns) c &= ~(0x80); twl4030_i2c_write_u8 (TWL4030_MODULE_GPIO, c, 0x06); mdelay(1); //set reset line high again c |= (0x80); twl4030_i2c_write_u8 (TWL4030_MODULE_GPIO, c, 0x06); mdelay(1); //execute init sequence for (i = 0; i < (sizeof(ths8200_init_seq)/2); i++) { err |= ths8200_write(client, ths8200_init_seq[i][0], ths8200_init_seq[i][1]); } if (err < 0) { dev_err(&client->dev, "%s: Error during THS8200 init\n", __func__); return -EINVAL; } return 0; }
/** * @brief omap3evmdc_mdc_config - GPIO configuration for * GPIO 134, 54 and 136 * * @return result of operation - 0 is success */ static int omap3evmdc_mdc_config(void) { if (is_dec_onboard) { unsigned char val; /* Set GPIO8 = 1 */ twl4030_i2c_read_u8(TWL4030_MODULE_GPIO, &val, REG_GPIODATAOUT2); val &= ~0x1; twl4030_i2c_write_u8(TWL4030_MODULE_GPIO, val, REG_GPIODATAOUT2); /* Enable Video Decoder */ omap_cfg_reg(AA21_34XX_GPIO157); if (gpio_request(nCAM_VD_SEL, "Vid-Dec Sel") < 0) { printk(KERN_ERR "Failed to get GPIO 157\n"); return -EINVAL; } gpio_direction_output(nCAM_VD_SEL, 1); omap_cfg_reg(C23_34XX_GPIO98); if (gpio_request(GPIO98_VID_DEC_RES, "vid-dec reset") < 0) { printk(KERN_ERR "failed to get GPIO98_VID_DEC_RES\n"); return -EINVAL; } gpio_direction_output(GPIO98_VID_DEC_RES, 1); } else { /* Setting the MUX configuration */ omap_cfg_reg(AG4_34XX_GPIO134); omap_cfg_reg(U8_34XX_GPIO54); omap_cfg_reg(AE4_34XX_GPIO136); if (gpio_request(GPIO134_SEL_TVP_Y, "TVP5146 Vid-in") < 0) { printk(KERN_ERR MODULE_NAME ": Can't get GPIO 134\n"); return -EINVAL; } if (gpio_request(GPIO54_SEL_EXP_CAM, "EXP_CAM Vid-in") < 0) { printk(KERN_ERR MODULE_NAME ": Can't get GPIO 54\n"); return -EINVAL; } if (gpio_request(GPIO136_SEL_CAM, "CAM Vid-in") < 0) { printk(KERN_ERR MODULE_NAME ": Can't get GPIO 136\n"); return -EINVAL; } /* Make GPIO as output */ gpio_direction_output(GPIO134_SEL_TVP_Y, 0); gpio_direction_output(GPIO54_SEL_EXP_CAM, 0); gpio_direction_output(GPIO136_SEL_CAM, 0); } return 0; }