2019-05-28 16:57:07 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2009-11-29 15:23:51 +00:00
|
|
|
/*
|
|
|
|
* PISMO memory driver - http://www.pismoworld.org/
|
|
|
|
*
|
|
|
|
* For ARM Realview and Versatile platforms
|
|
|
|
*/
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/i2c.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2009-11-29 15:23:51 +00:00
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/mtd/physmap.h>
|
|
|
|
#include <linux/mtd/plat-ram.h>
|
|
|
|
#include <linux/mtd/pismo.h>
|
|
|
|
|
|
|
|
#define PISMO_NUM_CS 5
|
|
|
|
|
|
|
|
struct pismo_cs_block {
|
|
|
|
u8 type;
|
|
|
|
u8 width;
|
|
|
|
__le16 access;
|
|
|
|
__le32 size;
|
|
|
|
u32 reserved[2];
|
|
|
|
char device[32];
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
struct pismo_eeprom {
|
|
|
|
struct pismo_cs_block cs[PISMO_NUM_CS];
|
|
|
|
char board[15];
|
|
|
|
u8 sum;
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
struct pismo_mem {
|
|
|
|
phys_addr_t base;
|
|
|
|
u32 size;
|
|
|
|
u16 access;
|
|
|
|
u8 width;
|
|
|
|
u8 type;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pismo_data {
|
|
|
|
struct i2c_client *client;
|
|
|
|
void (*vpp)(void *, int);
|
|
|
|
void *vpp_data;
|
|
|
|
struct platform_device *dev[PISMO_NUM_CS];
|
|
|
|
};
|
|
|
|
|
2011-05-18 09:51:55 +00:00
|
|
|
static void pismo_set_vpp(struct platform_device *pdev, int on)
|
2009-11-29 15:23:51 +00:00
|
|
|
{
|
2011-05-18 09:51:55 +00:00
|
|
|
struct i2c_client *client = to_i2c_client(pdev->dev.parent);
|
|
|
|
struct pismo_data *pismo = i2c_get_clientdata(client);
|
2009-11-29 15:23:51 +00:00
|
|
|
|
|
|
|
pismo->vpp(pismo->vpp_data, on);
|
|
|
|
}
|
|
|
|
|
2012-11-19 18:23:07 +00:00
|
|
|
static unsigned int pismo_width_to_bytes(unsigned int width)
|
2009-11-29 15:23:51 +00:00
|
|
|
{
|
|
|
|
width &= 15;
|
|
|
|
if (width > 2)
|
|
|
|
return 0;
|
|
|
|
return 1 << width;
|
|
|
|
}
|
|
|
|
|
2012-12-21 21:19:05 +00:00
|
|
|
static int pismo_eeprom_read(struct i2c_client *client, void *buf, u8 addr,
|
|
|
|
size_t size)
|
2009-11-29 15:23:51 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct i2c_msg msg[] = {
|
|
|
|
{
|
|
|
|
.addr = client->addr,
|
|
|
|
.len = sizeof(addr),
|
|
|
|
.buf = &addr,
|
|
|
|
}, {
|
|
|
|
.addr = client->addr,
|
|
|
|
.flags = I2C_M_RD,
|
|
|
|
.len = size,
|
|
|
|
.buf = buf,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
|
|
|
|
|
|
|
|
return ret == ARRAY_SIZE(msg) ? size : -EIO;
|
|
|
|
}
|
|
|
|
|
2012-11-19 18:23:07 +00:00
|
|
|
static int pismo_add_device(struct pismo_data *pismo, int i,
|
2012-12-21 21:19:05 +00:00
|
|
|
struct pismo_mem *region, const char *name,
|
|
|
|
void *pdata, size_t psize)
|
2009-11-29 15:23:51 +00:00
|
|
|
{
|
|
|
|
struct platform_device *dev;
|
|
|
|
struct resource res = { };
|
2010-03-01 16:19:23 +00:00
|
|
|
phys_addr_t base = region->base;
|
2009-11-29 15:23:51 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (base == ~0)
|
|
|
|
return -ENXIO;
|
|
|
|
|
|
|
|
res.start = base;
|
|
|
|
res.end = base + region->size - 1;
|
|
|
|
res.flags = IORESOURCE_MEM;
|
|
|
|
|
|
|
|
dev = platform_device_alloc(name, i);
|
|
|
|
if (!dev)
|
|
|
|
return -ENOMEM;
|
|
|
|
dev->dev.parent = &pismo->client->dev;
|
|
|
|
|
|
|
|
do {
|
|
|
|
ret = platform_device_add_resources(dev, &res, 1);
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ret = platform_device_add_data(dev, pdata, psize);
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ret = platform_device_add(dev);
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
|
|
|
|
pismo->dev[i] = dev;
|
|
|
|
return 0;
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
platform_device_put(dev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-19 18:23:07 +00:00
|
|
|
static int pismo_add_nor(struct pismo_data *pismo, int i,
|
2012-12-21 21:19:05 +00:00
|
|
|
struct pismo_mem *region)
|
2009-11-29 15:23:51 +00:00
|
|
|
{
|
|
|
|
struct physmap_flash_data data = {
|
|
|
|
.width = region->width,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (pismo->vpp)
|
|
|
|
data.set_vpp = pismo_set_vpp;
|
|
|
|
|
|
|
|
return pismo_add_device(pismo, i, region, "physmap-flash",
|
|
|
|
&data, sizeof(data));
|
|
|
|
}
|
|
|
|
|
2012-11-19 18:23:07 +00:00
|
|
|
static int pismo_add_sram(struct pismo_data *pismo, int i,
|
2012-12-21 21:19:05 +00:00
|
|
|
struct pismo_mem *region)
|
2009-11-29 15:23:51 +00:00
|
|
|
{
|
|
|
|
struct platdata_mtd_ram data = {
|
|
|
|
.bankwidth = region->width,
|
|
|
|
};
|
|
|
|
|
|
|
|
return pismo_add_device(pismo, i, region, "mtd-ram",
|
|
|
|
&data, sizeof(data));
|
|
|
|
}
|
|
|
|
|
2012-11-19 18:23:07 +00:00
|
|
|
static void pismo_add_one(struct pismo_data *pismo, int i,
|
2012-12-21 21:19:05 +00:00
|
|
|
const struct pismo_cs_block *cs, phys_addr_t base)
|
2009-11-29 15:23:51 +00:00
|
|
|
{
|
|
|
|
struct device *dev = &pismo->client->dev;
|
|
|
|
struct pismo_mem region;
|
|
|
|
|
|
|
|
region.base = base;
|
|
|
|
region.type = cs->type;
|
|
|
|
region.width = pismo_width_to_bytes(cs->width);
|
|
|
|
region.access = le16_to_cpu(cs->access);
|
|
|
|
region.size = le32_to_cpu(cs->size);
|
|
|
|
|
|
|
|
if (region.width == 0) {
|
|
|
|
dev_err(dev, "cs%u: bad width: %02x, ignoring\n", i, cs->width);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: may need to the platforms memory controller here, but at
|
|
|
|
* the moment we assume that it has already been correctly setup.
|
|
|
|
* The memory controller can also tell us the base address as well.
|
|
|
|
*/
|
|
|
|
|
|
|
|
dev_info(dev, "cs%u: %.32s: type %02x access %u00ps size %uK\n",
|
|
|
|
i, cs->device, region.type, region.access, region.size / 1024);
|
|
|
|
|
|
|
|
switch (region.type) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
/* static DOC */
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
/* static NOR */
|
|
|
|
pismo_add_nor(pismo, i, ®ion);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
/* static RAM */
|
|
|
|
pismo_add_sram(pismo, i, ®ion);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-19 18:26:04 +00:00
|
|
|
static int pismo_remove(struct i2c_client *client)
|
2009-11-29 15:23:51 +00:00
|
|
|
{
|
|
|
|
struct pismo_data *pismo = i2c_get_clientdata(client);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(pismo->dev); i++)
|
|
|
|
platform_device_unregister(pismo->dev[i]);
|
|
|
|
|
|
|
|
kfree(pismo);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-19 18:23:07 +00:00
|
|
|
static int pismo_probe(struct i2c_client *client,
|
2012-12-21 21:19:05 +00:00
|
|
|
const struct i2c_device_id *id)
|
2009-11-29 15:23:51 +00:00
|
|
|
{
|
|
|
|
struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
|
|
|
|
struct pismo_pdata *pdata = client->dev.platform_data;
|
|
|
|
struct pismo_eeprom eeprom;
|
|
|
|
struct pismo_data *pismo;
|
|
|
|
int ret, i;
|
|
|
|
|
|
|
|
if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
|
|
|
|
dev_err(&client->dev, "functionality mismatch\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
pismo = kzalloc(sizeof(*pismo), GFP_KERNEL);
|
|
|
|
if (!pismo)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
pismo->client = client;
|
|
|
|
if (pdata) {
|
|
|
|
pismo->vpp = pdata->set_vpp;
|
|
|
|
pismo->vpp_data = pdata->vpp_data;
|
|
|
|
}
|
|
|
|
i2c_set_clientdata(client, pismo);
|
|
|
|
|
|
|
|
ret = pismo_eeprom_read(client, &eeprom, 0, sizeof(eeprom));
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&client->dev, "error reading EEPROM: %d\n", ret);
|
2010-03-20 15:31:46 +00:00
|
|
|
goto exit_free;
|
2009-11-29 15:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dev_info(&client->dev, "%.15s board found\n", eeprom.board);
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(eeprom.cs); i++)
|
|
|
|
if (eeprom.cs[i].type != 0xff)
|
|
|
|
pismo_add_one(pismo, i, &eeprom.cs[i],
|
|
|
|
pdata->cs_addrs[i]);
|
|
|
|
|
|
|
|
return 0;
|
2010-03-20 15:31:46 +00:00
|
|
|
|
|
|
|
exit_free:
|
|
|
|
kfree(pismo);
|
|
|
|
return ret;
|
2009-11-29 15:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct i2c_device_id pismo_id[] = {
|
|
|
|
{ "pismo" },
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, pismo_id);
|
|
|
|
|
|
|
|
static struct i2c_driver pismo_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "pismo",
|
|
|
|
},
|
|
|
|
.probe = pismo_probe,
|
2012-11-19 18:21:24 +00:00
|
|
|
.remove = pismo_remove,
|
2009-11-29 15:23:51 +00:00
|
|
|
.id_table = pismo_id,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init pismo_init(void)
|
|
|
|
{
|
|
|
|
BUILD_BUG_ON(sizeof(struct pismo_cs_block) != 48);
|
|
|
|
BUILD_BUG_ON(sizeof(struct pismo_eeprom) != 256);
|
|
|
|
|
|
|
|
return i2c_add_driver(&pismo_driver);
|
|
|
|
}
|
|
|
|
module_init(pismo_init);
|
|
|
|
|
|
|
|
static void __exit pismo_exit(void)
|
|
|
|
{
|
|
|
|
i2c_del_driver(&pismo_driver);
|
|
|
|
}
|
|
|
|
module_exit(pismo_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Russell King <linux@arm.linux.org.uk>");
|
|
|
|
MODULE_DESCRIPTION("PISMO memory driver");
|
|
|
|
MODULE_LICENSE("GPL");
|