Source
/*
* Core driver for STw4810/STw4811
*
* Copyright (C) 2013 ST-Ericsson SA
* Written on behalf of Linaro for ST-Ericsson
*
* Author: Linus Walleij <linus.walleij@linaro.org>
*
* License terms: GNU General Public License (GPL) version 2
*/
/*
* This driver can only access the non-USB portions of STw4811, the register
* range 0x00-0x10 dealing with USB is bound to the two special I2C pins used
* for USB control.
*/
/* Registers inside the power control address space */
/**
* stw481x_get_pctl_reg() - get a power control register
* @stw481x: handle to the stw481x chip
* @reg: power control register to fetch
*
* The power control registers is a set of one-time-programmable registers
* in its own register space, accessed by writing addess bits to these
* two registers: bits 7,6,5 of PCTL_REG_LO corresponds to the 3 LSBs of
* the address and bits 8,9 of PCTL_REG_HI corresponds to the 2 MSBs of
* the address, forming an address space of 5 bits, i.e. 32 registers
* 0x00 ... 0x1f can be obtained.
*/
static int stw481x_get_pctl_reg(struct stw481x *stw481x, u8 reg)
{
u8 msb = (reg >> 3) & 0x03;
u8 lsb = (reg << 5) & 0xe0;
unsigned int val;
u8 vrfy;
int ret;
ret = regmap_write(stw481x->map, STW_PCTL_REG_HI, msb);
if (ret)
return ret;
ret = regmap_write(stw481x->map, STW_PCTL_REG_LO, lsb);
if (ret)
return ret;
ret = regmap_read(stw481x->map, STW_PCTL_REG_HI, &val);
if (ret)
return ret;
vrfy = (val & 0x03) << 3;
ret = regmap_read(stw481x->map, STW_PCTL_REG_LO, &val);