bus.h 3.9 KB
Newer Older
L
Linus Torvalds 已提交
1
/*
2 3 4 5 6
 *  linux/include/amba/bus.h
 *
 *  This device type deals with ARM PrimeCells and anything else that
 *  presents a proper CID (0xB105F00D) at the end of the I/O register
 *  region or that is derived from a PrimeCell.
L
Linus Torvalds 已提交
7 8 9 10 11 12 13 14 15 16
 *
 *  Copyright (C) 2003 Deep Blue Solutions Ltd, All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */
#ifndef ASMARM_AMBA_H
#define ASMARM_AMBA_H

17
#include <linux/clk.h>
18
#include <linux/device.h>
19
#include <linux/mod_devicetable.h>
20
#include <linux/err.h>
21
#include <linux/resource.h>
22
#include <linux/regulator/consumer.h>
23

L
Linus Torvalds 已提交
24
#define AMBA_NR_IRQS	2
25
#define AMBA_CID	0xb105f00d
L
Linus Torvalds 已提交
26

27 28
struct clk;

L
Linus Torvalds 已提交
29 30 31
struct amba_device {
	struct device		dev;
	struct resource		res;
32
	struct clk		*pclk;
33
	struct regulator	*vcore;
L
Linus Torvalds 已提交
34 35 36 37 38 39 40
	u64			dma_mask;
	unsigned int		periphid;
	unsigned int		irq[AMBA_NR_IRQS];
};

struct amba_driver {
	struct device_driver	drv;
41
	int			(*probe)(struct amba_device *, const struct amba_id *);
L
Linus Torvalds 已提交
42 43 44 45
	int			(*remove)(struct amba_device *);
	void			(*shutdown)(struct amba_device *);
	int			(*suspend)(struct amba_device *, pm_message_t);
	int			(*resume)(struct amba_device *);
46
	const struct amba_id	*id_table;
L
Linus Torvalds 已提交
47 48
};

49 50 51 52 53
enum amba_vendor {
	AMBA_VENDOR_ARM = 0x41,
	AMBA_VENDOR_ST = 0x80,
};

54 55
extern struct bus_type amba_bustype;

56 57
#define to_amba_device(d)	container_of(d, struct amba_device, dev)

L
Linus Torvalds 已提交
58 59 60 61 62
#define amba_get_drvdata(d)	dev_get_drvdata(&d->dev)
#define amba_set_drvdata(d,p)	dev_set_drvdata(&d->dev, p)

int amba_driver_register(struct amba_driver *);
void amba_driver_unregister(struct amba_driver *);
63 64 65
struct amba_device *amba_device_alloc(const char *, resource_size_t, size_t);
void amba_device_put(struct amba_device *);
int amba_device_add(struct amba_device *, struct resource *);
L
Linus Torvalds 已提交
66 67 68 69 70 71
int amba_device_register(struct amba_device *, struct resource *);
void amba_device_unregister(struct amba_device *);
struct amba_device *amba_find_device(const char *, struct device *, unsigned int, unsigned int);
int amba_request_regions(struct amba_device *, const char *);
void amba_release_regions(struct amba_device *);

72 73 74 75 76 77
#define amba_pclk_enable(d)	\
	(IS_ERR((d)->pclk) ? 0 : clk_enable((d)->pclk))

#define amba_pclk_disable(d)	\
	do { if (!IS_ERR((d)->pclk)) clk_disable((d)->pclk); } while (0)

78 79 80 81 82 83
#define amba_vcore_enable(d)	\
	(IS_ERR((d)->vcore) ? 0 : regulator_enable((d)->vcore))

#define amba_vcore_disable(d)	\
	do { if (!IS_ERR((d)->vcore)) regulator_disable((d)->vcore); } while (0)

84 85 86 87 88 89 90 91 92 93
/* Some drivers don't use the struct amba_device */
#define AMBA_CONFIG_BITS(a) (((a) >> 24) & 0xff)
#define AMBA_REV_BITS(a) (((a) >> 20) & 0x0f)
#define AMBA_MANF_BITS(a) (((a) >> 12) & 0xff)
#define AMBA_PART_BITS(a) ((a) & 0xfff)

#define amba_config(d)	AMBA_CONFIG_BITS((d)->periphid)
#define amba_rev(d)	AMBA_REV_BITS((d)->periphid)
#define amba_manf(d)	AMBA_MANF_BITS((d)->periphid)
#define amba_part(d)	AMBA_PART_BITS((d)->periphid)
L
Linus Torvalds 已提交
94

95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
#define __AMBA_DEV(busid, data, mask)				\
	{							\
		.coherent_dma_mask = mask,			\
		.init_name = busid,				\
		.platform_data = data,				\
	}

/*
 * APB devices do not themselves have the ability to address memory,
 * so DMA masks should be zero (much like USB peripheral devices.)
 * The DMA controller DMA masks should be used instead (much like
 * USB host controllers in conventional PCs.)
 */
#define AMBA_APB_DEVICE(name, busid, id, base, irqs, data)	\
struct amba_device name##_device = {				\
	.dev = __AMBA_DEV(busid, data, 0),			\
	.res = DEFINE_RES_MEM(base, SZ_4K),			\
	.irq = irqs,						\
	.periphid = id,						\
}

/*
 * AHB devices are DMA capable, so set their DMA masks
 */
#define AMBA_AHB_DEVICE(name, busid, id, base, irqs, data)	\
struct amba_device name##_device = {				\
	.dev = __AMBA_DEV(busid, data, ~0ULL),			\
	.res = DEFINE_RES_MEM(base, SZ_4K),			\
	.dma_mask = ~0ULL,					\
	.irq = irqs,						\
	.periphid = id,						\
}

L
Linus Torvalds 已提交
128
#endif