Search
SailfishOS Open Build Service
>
Projects
>
home:mike7b4
:
bbb
>
kernel-adaptation-bbb-v3.12
> 0042-i2c-EEPROM-In-kernel-memory-accessor-interface.patch
Log In
Username
Password
Cancel
Overview
Repositories
Revisions
Requests
Users
Advanced
Attributes
Meta
File 0042-i2c-EEPROM-In-kernel-memory-accessor-interface.patch of Package kernel-adaptation-bbb-v3.12
From 16037954df6af42bc4bac5b59ff9d40f366b7706 Mon Sep 17 00:00:00 2001 From: Pantelis Antoniou <panto@antoniou-consulting.com> Date: Thu, 13 Dec 2012 11:23:21 +0200 Subject: [PATCH 42/96] i2c-EEPROM: In kernel memory accessor interface In kernel users need to access the EEPROM using the i2c_client interface. Extend at24 to use it via the command interface. Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com> --- drivers/misc/eeprom/at24.c | 23 ++++++++++++++++++ include/linux/i2c/eeprom.h | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 include/linux/i2c/eeprom.h diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 5d4fd69..7e0474d 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -23,6 +23,7 @@ #include <linux/of.h> #include <linux/i2c.h> #include <linux/i2c/at24.h> +#include <linux/i2c/eeprom.h> /* * I2C EEPROMs from most vendors are inexpensive and mostly interchangeable. @@ -658,6 +659,27 @@ static int at24_remove(struct i2c_client *client) return 0; } +static int at24_command(struct i2c_client *client, unsigned int cmd, void *arg) +{ + struct at24_data *at24; + const struct memory_accessor **maccp; + + /* only supporting a single command */ + if (cmd != I2C_EEPROM_GET_MEMORY_ACCESSOR) + return -ENOTSUPP; + + /* rudimentary check */ + if (arg == NULL) + return -EINVAL; + + at24 = i2c_get_clientdata(client); + + maccp = arg; + *maccp = &at24->macc; + + return 0; +} + /*-------------------------------------------------------------------------*/ static struct i2c_driver at24_driver = { @@ -668,6 +690,7 @@ static struct i2c_driver at24_driver = { .probe = at24_probe, .remove = at24_remove, .id_table = at24_ids, + .command = at24_command, }; static int __init at24_init(void) diff --git a/include/linux/i2c/eeprom.h b/include/linux/i2c/eeprom.h new file mode 100644 index 0000000..1393980 --- /dev/null +++ b/include/linux/i2c/eeprom.h @@ -0,0 +1,59 @@ +/* + * i2c/eeprom.h + * + * In-kernel interface for accessing eeprom memory. + * + * Copyright (C) 2012 Texas Instruments Inc. + * Pantelis Antoniou <panto@antoniou-consulting.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ +#ifndef I2C_EEPROM_H +#define I2C_EEPROM_H + +#include <linux/types.h> +#include <linux/memory.h> +#include <linux/err.h> +#include <linux/i2c.h> + +/* + * The method called in the client is + * + * int command(struct i2c_client *client, unsigned int cmd, void *arg); + * + * A single command is supported, which returns a pointer to the memory + * accessor already available, but which was only accessible via platform + * callbacks. We can't use platform callbacks anymore for device tree + * platforms, hence this interface. + * + */ + +/* interface commands */ +#define I2C_EEPROM_GET_MEMORY_ACCESSOR 1 + +static inline struct memory_accessor * +i2c_eeprom_get_memory_accessor(struct i2c_client *client) +{ + int ret; + struct memory_accessor *macc; + + /* verify that the i2c client's driver has a command method */ + if (!client || !client->driver || !client->driver->command) + return ERR_PTR(-ENOTSUPP); + + macc = NULL; + ret = client->driver->command(client, I2C_EEPROM_GET_MEMORY_ACCESSOR, + &macc); + if (ret != 0) + return ERR_PTR(ret); + + if (macc == NULL) + return ERR_PTR(-ENOTSUPP); + + return macc; +} + +#endif -- 1.9.1