Skip to content

Commit adae199

Browse files
committed
Add cpufreq driver
1 parent 55549f3 commit adae199

File tree

8 files changed

+380
-37
lines changed

8 files changed

+380
-37
lines changed

arch/arm/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,7 @@ config ARCH_BCM2708
963963
select HAVE_SCHED_CLOCK
964964
select NEED_MACH_MEMORY_H
965965
select CLKDEV_LOOKUP
966+
select ARCH_HAS_CPUFREQ
966967
select GENERIC_CLOCKEVENTS
967968
select ARM_ERRATA_411920
968969
select MACH_BCM2708

arch/arm/configs/bcmrpi_defconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ CONFIG_ZBOOT_ROM_TEXT=0x0
4646
CONFIG_ZBOOT_ROM_BSS=0x0
4747
CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext3 rootwait"
4848
CONFIG_KEXEC=y
49+
CONFIG_CPU_FREQ=y
50+
CONFIG_CPU_FREQ_STAT=m
51+
CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND=y
52+
CONFIG_CPU_FREQ_GOV_POWERSAVE=y
53+
CONFIG_CPU_FREQ_GOV_USERSPACE=y
54+
CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
4955
CONFIG_CPU_IDLE=y
5056
CONFIG_VFP=y
5157
CONFIG_BINFMT_MISC=m

arch/arm/mach-bcm2708/include/mach/vcio.h

Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,82 @@
2727
#define BCM_VCIO_DRIVER_NAME "bcm2708_vcio"
2828

2929
/* Constants shared with the ARM identifying separate mailbox channels */
30-
#define MBOX_CHAN_POWER 0 /* for use by the power management interface */
31-
#define MBOX_CHAN_FB 1 /* for use by the frame buffer */
32-
#define MBOX_CHAN_VUART 2 /* for use by the virtual UART */
33-
#define MBOX_CHAN_VCHIQ 3 /* for use by the VCHIQ interface */
34-
#define MBOX_CHAN_LEDS 4 /* for use by the leds interface */
35-
#define MBOX_CHAN_BUTTONS 5 /* for use by the buttons interface */
36-
#define MBOX_CHAN_TOUCH 6 /* for use by the touchscreen interface */
30+
#define MBOX_CHAN_POWER 0 /* for use by the power management interface */
31+
#define MBOX_CHAN_FB 1 /* for use by the frame buffer */
32+
#define MBOX_CHAN_VCHIQ 3 /* for use by the VCHIQ interface */
3733
#define MBOX_CHAN_PROPERTY 8 /* for use by the property channel */
38-
#define MBOX_CHAN_COUNT 9
34+
#define MBOX_CHAN_COUNT 9
35+
36+
/* Mailbox property tags */
37+
enum {
38+
VCMSG_PROPERTY_END = 0x00000000,
39+
VCMSG_GET_FIRMWARE_REVISION = 0x00000001,
40+
VCMSG_GET_BOARD_MODEL = 0x00010001,
41+
VCMSG_GET_BOARD_REVISION = 0x00020002,
42+
VCMSG_GET_BOARD_MAC_ADDRESS = 0x00020003,
43+
VCMSG_GET_BOARD_SERIAL = 0x00020004,
44+
VCMSG_GET_ARM_MEMORY = 0x00020005,
45+
VCMSG_GET_VC_MEMORY = 0x00020006,
46+
VCMSG_GET_CLOCKS = 0x00020007,
47+
VCMSG_GET_COMMAND_LINE = 0x00050001,
48+
VCMSG_GET_DMA_CHANNELS = 0x00060001,
49+
VCMSG_GET_POWER_STATE = 0x00020001,
50+
VCMSG_GET_TIMING = 0x00020002,
51+
VCMSG_SET_POWER_STATE = 0x00028001,
52+
VCMSG_GET_CLOCK_STATE = 0x00030001,
53+
VCMSG_SET_CLOCK_STATE = 0x00038001,
54+
VCMSG_GET_CLOCK_RATE = 0x00030002,
55+
VCMSG_SET_CLOCK_RATE = 0x00038002,
56+
VCMSG_GET_VOLTAGE = 0x00030003,
57+
VCMSG_SET_VOLTAGE = 0x00038003,
58+
VCMSG_GET_MAX_CLOCK = 0x00030004,
59+
VCMSG_GET_MAX_VOLTAGE = 0x00030005,
60+
VCMSG_GET_TEMPERATURE = 0x00030006,
61+
VCMSG_GET_MIN_CLOCK = 0x00030007,
62+
VCMSG_GET_MIN_VOLTAGE = 0x00030008,
63+
VCMSG_GET_TURBO = 0x00030009,
64+
VCMSG_SET_TURBO = 0x00038009,
65+
VCMSG_SET_ALLOCATE_BUFFER = 0x00040001,
66+
VCMSG_SET_RELEASE_BUFFER = 0x00048001,
67+
VCMSG_SET_BLANK_SCREEN = 0x00040002,
68+
VCMSG_TST_BLANK_SCREEN = 0x00044002,
69+
VCMSG_GET_PHYSICAL_WIDTH_HEIGHT = 0x00040003,
70+
VCMSG_TST_PHYSICAL_WIDTH_HEIGHT = 0x00044003,
71+
VCMSG_SET_PHYSICAL_WIDTH_HEIGHT = 0x00048003,
72+
VCMSG_GET_VIRTUAL_WIDTH_HEIGHT = 0x00040004,
73+
VCMSG_TST_VIRTUAL_WIDTH_HEIGHT = 0x00044004,
74+
VCMSG_SET_VIRTUAL_WIDTH_HEIGHT = 0x00048004,
75+
VCMSG_GET_DEPTH = 0x00040005,
76+
VCMSG_TST_DEPTH = 0x00044005,
77+
VCMSG_SET_DEPTH = 0x00048005,
78+
VCMSG_GET_PIXEL_ORDER = 0x00040006,
79+
VCMSG_TST_PIXEL_ORDER = 0x00044006,
80+
VCMSG_SET_PIXEL_ORDER = 0x00048006,
81+
VCMSG_GET_ALPHA_MODE = 0x00040007,
82+
VCMSG_TST_ALPHA_MODE = 0x00044007,
83+
VCMSG_SET_ALPHA_MODE = 0x00048007,
84+
VCMSG_GET_PITCH = 0x00040008,
85+
VCMSG_TST_PITCH = 0x00044008,
86+
VCMSG_SET_PITCH = 0x00048008,
87+
VCMSG_GET_VIRTUAL_OFFSET = 0x00040009,
88+
VCMSG_TST_VIRTUAL_OFFSET = 0x00044009,
89+
VCMSG_SET_VIRTUAL_OFFSET = 0x00048009,
90+
VCMSG_GET_OVERSCAN = 0x0004000a,
91+
VCMSG_TST_OVERSCAN = 0x0004400a,
92+
VCMSG_SET_OVERSCAN = 0x0004800a,
93+
VCMSG_GET_PALETTE = 0x0004000b,
94+
VCMSG_TST_PALETTE = 0x0004400b,
95+
VCMSG_SET_PALETTE = 0x0004800b,
96+
VCMSG_GET_LAYER = 0x0004000c,
97+
VCMSG_TST_LAYER = 0x0004400c,
98+
VCMSG_SET_LAYER = 0x0004800c,
99+
VCMSG_GET_TRANSFORM = 0x0004000d,
100+
VCMSG_TST_TRANSFORM = 0x0004400d,
101+
VCMSG_SET_TRANSFORM = 0x0004800d,
102+
};
39103

40104
extern int /*rc*/ bcm_mailbox_read(unsigned chan, uint32_t *data28);
41105
extern int /*rc*/ bcm_mailbox_write(unsigned chan, uint32_t data28);
106+
extern int /*rc*/ bcm_mailbox_property(void *data, int size);
42107

43108
#endif

arch/arm/mach-bcm2708/vc_mem.c

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -128,44 +128,33 @@ struct vc_set_msg {
128128
uint32_t end_tag; /* an end identifier, should be set to NULL */
129129
};
130130

131-
#define VCMSG_GET_ARM_MEMORY 0x00010005
132-
#define VCMSG_GET_VC_MEMORY 0x00010006
133-
134131
static void vc_mem_update(void)
135132
{
136-
uint32_t success;
137-
dma_addr_t vc_mem; /* the memory address accessed from videocore */
138-
struct vc_set_msg *get_mem; /* the memory address accessed from driver */
139-
140-
/* allocate some memory for the messages to use throughout the lifetime of the driver, use the larger of the two message structures */
141-
get_mem = (struct vc_set_msg *)dma_alloc_coherent(NULL, PAGE_ALIGN(sizeof(struct vc_set_msg)), &vc_mem, GFP_ATOMIC);
142-
/* clear any garbage */
143-
memset(get_mem, 0, sizeof(struct vc_set_msg));
133+
struct vc_set_msg msg; /* the memory address accessed from driver */
134+
uint32_t s;
135+
136+
memset(&msg, 0, sizeof msg);
144137
/* create the message */
145-
get_mem->msg_size = sizeof(struct vc_set_msg);
146-
get_mem->tag[0].tag_id = VCMSG_GET_VC_MEMORY;
147-
get_mem->tag[0].buffer_size = 8;
148-
get_mem->tag[0].data_size = 0;
149-
get_mem->tag[1].tag_id = VCMSG_GET_ARM_MEMORY;
150-
get_mem->tag[1].buffer_size = 8;
151-
get_mem->tag[1].data_size = 0;
138+
msg.msg_size = sizeof msg;
139+
msg.tag[0].tag_id = VCMSG_GET_VC_MEMORY;
140+
msg.tag[0].buffer_size = 8;
141+
msg.tag[0].data_size = 0;
142+
msg.tag[1].tag_id = VCMSG_GET_ARM_MEMORY;
143+
msg.tag[1].buffer_size = 8;
144+
msg.tag[1].data_size = 0;
152145

153146
/* send the message */
154-
wmb();
155-
bcm_mailbox_write(MBOX_CHAN_PROPERTY,(uint32_t)vc_mem);
156-
bcm_mailbox_read(MBOX_CHAN_PROPERTY, &success);
157-
rmb();
147+
s = bcm_mailbox_property(&msg, sizeof msg);
158148

159-
LOG_DBG("%s: resp %x, vcbase=%x vcsize=%x armbase=%x armsize=%x", __func__, get_mem->request_code,
160-
get_mem->tag[0].base, get_mem->tag[0].size, get_mem->tag[1].base, get_mem->tag[1].size);
149+
LOG_DBG("%s: success=%d resp %x, vcbase=%x vcsize=%x armbase=%x armsize=%x", __func__, s, msg.request_code,
150+
msg.tag[0].base, msg.tag[0].size, msg.tag[1].base, msg.tag[1].size);
161151

162152
/* check we're all good */
163-
if (get_mem->request_code & 0x80000000) {
164-
mm_vc_mem_base = get_mem->tag[0].base;
165-
mm_vc_mem_size = get_mem->tag[0].size+get_mem->tag[1].size;
166-
mm_vc_mem_phys_addr = get_mem->tag[1].base;
153+
if (s == 0 && msg.request_code & 0x80000000) {
154+
mm_vc_mem_base = msg.tag[0].base;
155+
mm_vc_mem_size = msg.tag[0].size+msg.tag[1].size;
156+
mm_vc_mem_phys_addr = msg.tag[1].base;
167157
}
168-
dma_free_coherent(NULL, PAGE_ALIGN(sizeof(struct vc_set_msg)), (void *)get_mem, vc_mem);
169158
}
170159

171160

arch/arm/mach-bcm2708/vcio.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,40 @@ static void dev_mbox_register(const char *dev_name, struct device *dev)
216216
mbox_dev = dev;
217217
}
218218

219+
extern int bcm_mailbox_property(void *data, int size)
220+
{
221+
uint32_t success;
222+
dma_addr_t mem_bus; /* the memory address accessed from videocore */
223+
void *mem_kern; /* the memory address accessed from driver */
224+
int s = 0;
225+
226+
/* allocate some memory for the messages communicating with GPU */
227+
mem_kern = dma_alloc_coherent(NULL, PAGE_ALIGN(size), &mem_bus, GFP_ATOMIC);
228+
if (mem_kern) {
229+
/* create the message */
230+
memcpy(mem_kern, data, size);
231+
232+
/* send the message */
233+
wmb();
234+
s = bcm_mailbox_write(MBOX_CHAN_PROPERTY, (uint32_t)mem_bus);
235+
if (s == 0) {
236+
s = bcm_mailbox_read(MBOX_CHAN_PROPERTY, &success);
237+
}
238+
if (s == 0) {
239+
/* copy the response */
240+
rmb();
241+
memcpy(data, mem_kern, size);
242+
}
243+
dma_free_coherent(NULL, PAGE_ALIGN(size), mem_kern, mem_bus);
244+
} else {
245+
s = -ENOMEM;
246+
}
247+
if (s != 0)
248+
printk(KERN_ERR DRIVER_NAME ": %s failed (%d)\n", __func__, s);
249+
return s;
250+
}
251+
EXPORT_SYMBOL_GPL(bcm_mailbox_property);
252+
219253
/* ----------------------------------------------------------------------
220254
* Platform Device for Mailbox
221255
* -------------------------------------------------------------------- */

drivers/cpufreq/Kconfig.arm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,11 @@ config ARM_EXYNOS4210_CPUFREQ
3030
SoC (S5PV310 or S5PC210).
3131

3232
If in doubt, say N.
33+
34+
config ARM_BCM2835_CPUFREQ
35+
bool "BCM2835 Driver"
36+
default y
37+
help
38+
This adds the CPUFreq driver for BCM2835
39+
40+
If in doubt, say N.

drivers/cpufreq/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ obj-$(CONFIG_UX500_SOC_DB8500) += db8500-cpufreq.o
4343
obj-$(CONFIG_ARM_S3C64XX_CPUFREQ) += s3c64xx-cpufreq.o
4444
obj-$(CONFIG_ARM_S5PV210_CPUFREQ) += s5pv210-cpufreq.o
4545
obj-$(CONFIG_ARM_EXYNOS4210_CPUFREQ) += exynos4210-cpufreq.o
46+
obj-$(CONFIG_ARM_BCM2835_CPUFREQ) += bcm2835-cpufreq.o
4647

4748
##################################################################################
4849
# PowerPC platform drivers

0 commit comments

Comments
 (0)