Commit ce4d377c authored by Federico Vaga's avatar Federico Vaga

sw:drv: autodetect endianess

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 91a7c46e
......@@ -81,6 +81,9 @@ The Mock Turtle device driver is based on the platform Linux subsystem
describes the Mock Turtle device. Typically, this mechanism involves the
development of a Linux module or the DeviceTree.
This driver handles all platform_device instances which name is one of
the following: "mock-turtle", "mockturtle".
The Mock Turtle device driver expects 5 ``resources`` from the platform
device.
......
......@@ -32,12 +32,6 @@
static DEFINE_IDA(trtl_ida);
struct trtl_memory_ops memops = {
.read =NULL,
.write = NULL,
};
static int trtl_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
{
add_uevent_var(env, "DEVMODE=%#o", 0440);
......@@ -565,6 +559,38 @@ static int trtl_resource_validation(struct platform_device *pdev)
return 0;
}
static int trtl_endianess(struct trtl_dev *trtl)
{
uint32_t signature;
signature = ioread32(trtl->base_cfg);
if (signature == TRTL_CONFIG_ROM_SIGNATURE)
return 0;
signature = ioread32be(trtl->base_cfg);
if (signature == TRTL_CONFIG_ROM_SIGNATURE)
return 1;
return -1;
}
static int trtl_memops_detect(struct trtl_dev *trtl)
{
switch (trtl_endianess(trtl)) {
case 0:
trtl->memops.read = ioread32;
trtl->memops.write = iowrite32;
return 0;
case 1:
trtl->memops.read = ioread32be;
trtl->memops.write = iowrite32be;
return 0;
default:
dev_err(&trtl->dev, "Invalid endianess\n");
return -EINVAL;
}
}
/**
* It initialize the TRTL device (device, CPUs, HMQs)
*/
......@@ -587,22 +613,6 @@ int trtl_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, trtl);
/* Assign IO operation */
switch (pdev->id_entry->driver_data) {
case TRTL_VER_SPEC:
memops.read = ioread32;
memops.write = iowrite32;
break;
case TRTL_VER_SVEC:
memops.read = ioread32be;
memops.write = iowrite32be;
break;
default:
dev_err(&trtl->dev, "Unknow version %lu\n",
pdev->id_entry->driver_data);
return -EINVAL;
}
r = platform_get_resource(pdev, IORESOURCE_MEM, TRTL_MEM_BASE);
trtl->base_core = ioremap(r->start, resource_size(r));
trtl->base_csr = trtl->base_core + TRTL_ADDR_OFFSET_CSR;
......@@ -610,6 +620,8 @@ int trtl_probe(struct platform_device *pdev)
trtl->base_hmq = trtl->base_core + TRTL_ADDR_OFFSET_HMQ;
trtl->base_cfg = trtl->base_core + TRTL_ADDR_OFFSET_CONFIG_ROM;
trtl_memops_detect(trtl);
/* Register the device */
err = dev_set_name(&trtl->dev, "trtl-%04x", pdev->id);
if (err)
......@@ -734,11 +746,10 @@ int trtl_remove(struct platform_device *pdev)
static const struct platform_device_id trtl_id[] = {
{
.name = "mock-turtle-spec",
.driver_data = TRTL_VER_SPEC,
}, {
.name = "mock-turtle-svec",
.driver_data = TRTL_VER_SVEC,
.name = "mock-turtle",
},
{
.name = "mockturtle",
},
/* TODO we should support different version */
......
......@@ -37,12 +37,6 @@
extern struct class trtl_cdev_class;
enum mock_turtle_versions {
TRTL_VER_SPEC = 0,
TRTL_VER_SVEC,
/* TODO actually all versioning */
};
/**
* It enumerates the IRQ sources
......@@ -221,19 +215,21 @@ struct trtl_dev {
struct tty_driver *tty_driver;
struct trtl_memory_ops memops;
struct dentry *dbg_dir; /**< root debug directory */
struct dentry *dbg_info; /**< information */
};
static inline u32 trtl_ioread(struct trtl_dev *trtl, void *addr)
{
return memops.read(addr);
return trtl->memops.read(addr);
}
static inline void trtl_iowrite(struct trtl_dev *trtl,
u32 value, void *addr)
{
return memops.write(value, addr);
return trtl->memops.write(value, addr);
}
/* Global data */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment