~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/soc/codecs/sigmadsp-i2c.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /*
  3  * Load Analog Devices SigmaStudio firmware files
  4  *
  5  * Copyright 2009-2011 Analog Devices Inc.
  6  */
  7 
  8 #include <linux/export.h>
  9 #include <linux/i2c.h>
 10 #include <linux/module.h>
 11 #include <linux/slab.h>
 12 #include <asm/unaligned.h>
 13 
 14 #include "sigmadsp.h"
 15 
 16 static int sigmadsp_write_i2c(void *control_data,
 17         unsigned int addr, const uint8_t data[], size_t len)
 18 {
 19         uint8_t *buf;
 20         int ret;
 21 
 22         buf = kzalloc(2 + len, GFP_KERNEL | GFP_DMA);
 23         if (!buf)
 24                 return -ENOMEM;
 25 
 26         put_unaligned_be16(addr, buf);
 27         memcpy(buf + 2, data, len);
 28 
 29         ret = i2c_master_send(control_data, buf, len + 2);
 30 
 31         kfree(buf);
 32 
 33         if (ret < 0)
 34                 return ret;
 35 
 36         return 0;
 37 }
 38 
 39 static int sigmadsp_read_i2c(void *control_data,
 40         unsigned int addr, uint8_t data[], size_t len)
 41 {
 42         struct i2c_client *client = control_data;
 43         struct i2c_msg msgs[2];
 44         uint8_t buf[2];
 45         int ret;
 46 
 47         put_unaligned_be16(addr, buf);
 48 
 49         msgs[0].addr = client->addr;
 50         msgs[0].len = sizeof(buf);
 51         msgs[0].buf = buf;
 52         msgs[0].flags = 0;
 53 
 54         msgs[1].addr = client->addr;
 55         msgs[1].len = len;
 56         msgs[1].buf = data;
 57         msgs[1].flags = I2C_M_RD;
 58 
 59         ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
 60         if (ret < 0)
 61                 return ret;
 62         else if (ret != ARRAY_SIZE(msgs))
 63                 return -EIO;
 64         return 0;
 65 }
 66 
 67 /**
 68  * devm_sigmadsp_init_i2c() - Initialize SigmaDSP instance
 69  * @client: The parent I2C device
 70  * @ops: The sigmadsp_ops to use for this instance
 71  * @firmware_name: Name of the firmware file to load
 72  *
 73  * Allocates a SigmaDSP instance and loads the specified firmware file.
 74  *
 75  * Returns a pointer to a struct sigmadsp on success, or a PTR_ERR() on error.
 76  */
 77 struct sigmadsp *devm_sigmadsp_init_i2c(struct i2c_client *client,
 78         const struct sigmadsp_ops *ops, const char *firmware_name)
 79 {
 80         struct sigmadsp *sigmadsp;
 81 
 82         sigmadsp = devm_sigmadsp_init(&client->dev, ops, firmware_name);
 83         if (IS_ERR(sigmadsp))
 84                 return sigmadsp;
 85 
 86         sigmadsp->control_data = client;
 87         sigmadsp->write = sigmadsp_write_i2c;
 88         sigmadsp->read = sigmadsp_read_i2c;
 89 
 90         return sigmadsp;
 91 }
 92 EXPORT_SYMBOL_GPL(devm_sigmadsp_init_i2c);
 93 
 94 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
 95 MODULE_DESCRIPTION("SigmaDSP I2C firmware loader");
 96 MODULE_LICENSE("GPL");
 97 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php