[alsa-devel] ASoC: TI codecs and their crazy variable length registers

jonsmirl at gmail.com jonsmirl at gmail.com
Thu Jul 31 16:06:32 CEST 2014


On Thu, Jul 31, 2014 at 3:01 AM, Lars-Peter Clausen <lars at metafoo.de> wrote:
> On 07/31/2014 01:17 AM, Mark Brown wrote:
>>
>> On Wed, Jul 30, 2014 at 05:56:36PM -0400, jonsmirl at gmail.com wrote:
>>
>>> I'm working on a TI codec attached via I2C.  Just to make things
>>> interesting the registers have varying byte lengths of - 1,4,8,12,20
>>> bytes. What's the best strategy for using regmap with it?
>>
>>
>> I'd use the reg_read() and reg_write() callbacks to hide the registers
>> that will fit in an integer, the rest of the stack can pretend they've
>> got 32 bit values which should improve code reuse.[...]
>
>
> The adau1701 is a driver that for example does this.
>

Then use regmap_raw_read/regmap_raw_write for the registers over four bytes?

This might work generically if the size function was a regmap callback...

static int adau1701_reg_write(void *context, unsigned int reg,
     unsigned int value)
{
struct i2c_client *client = context;
unsigned int i;
unsigned int size;
uint8_t buf[5];
int ret;

size = adau1701_register_size(&client->dev, reg);
if (size == 0)
return -EINVAL;

buf[0] = reg >> 8;
buf[1] = reg & 0xff;

for (i = size + 1; i >= 2; --i) {
buf[i] = value;
value >>= 8;
}


-- 
Jon Smirl
jonsmirl at gmail.com


More information about the Alsa-devel mailing list