brcm2708: update 3.10 patches with raspberrypi/rpi-3.10.y of 27 Apr. 2014
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-3.10 / 0052-Add-retry-on-error-and-tidy-of-temperature-driver.patch
1 From 1234701636ab3dca340a336aa9ddfadd64914e58 Mon Sep 17 00:00:00 2001
2 From: popcornmix <popcornmix@gmail.com>
3 Date: Sun, 24 Feb 2013 16:30:57 +0000
4 Subject: [PATCH 052/196] Add retry on error and tidy of temperature driver
5
6 ---
7 drivers/thermal/bcm2835-thermal.c | 78 ++++++++++++++-------------------------
8 1 file changed, 27 insertions(+), 51 deletions(-)
9
10 diff --git a/drivers/thermal/bcm2835-thermal.c b/drivers/thermal/bcm2835-thermal.c
11 index 3f9a733..85fceb5 100644
12 --- a/drivers/thermal/bcm2835-thermal.c
13 +++ b/drivers/thermal/bcm2835-thermal.c
14 @@ -33,7 +33,6 @@
15 #define print_debug(fmt,...)
16 #endif
17 #define print_err(fmt,...) printk(KERN_ERR "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
18 -#define print_info(fmt,...) printk(KERN_INFO "%s: "fmt"\n", MODULE_NAME, ##__VA_ARGS__)
19
20 #define VC_TAG_GET_TEMP 0x00030006
21 #define VC_TAG_GET_MAX_TEMP 0x0003000A
22 @@ -66,12 +65,6 @@ struct bcm2835_thermal_data {
23 struct vc_msg msg;
24 };
25
26 -/* --- PROTOTYPES --- */
27 -static int bcm2835_get_temp(struct thermal_zone_device *thermal_dev, unsigned long *);
28 -static int bcm2835_get_max_temp(struct thermal_zone_device *thermal_dev, int, unsigned long *);
29 -static int bcm2835_get_trip_type(struct thermal_zone_device *thermal_dev, int trip_num, enum thermal_trip_type *trip_type);
30 -static int bcm2835_get_mode(struct thermal_zone_device *thermal_dev, enum thermal_device_mode *dev_mode);
31 -
32 /* --- GLOBALS --- */
33 static struct bcm2835_thermal_data bcm2835_data;
34
35 @@ -79,64 +72,47 @@ static struct bcm2835_thermal_data bcm2835_data;
36 static struct thermal_zone_device_ops ops;
37
38 /* --- FUNCTIONS --- */
39 -static int bcm2835_get_max_temp(struct thermal_zone_device *thermal_dev, int trip_num, unsigned long *temp)
40 -{
41 - int result;
42
43 +static int bcm2835_get_temp_or_max(struct thermal_zone_device *thermal_dev, unsigned long *temp, unsigned tag_id)
44 +{
45 + int result = -1, retry = 3;
46 print_debug("IN");
47
48 - /* wipe all previous message data */
49 - memset(&bcm2835_data.msg, 0, sizeof bcm2835_data.msg);
50 -
51 - /* prepare message */
52 - bcm2835_data.msg.msg_size = sizeof bcm2835_data.msg;
53 - bcm2835_data.msg.tag.buffer_size = 8;
54 - bcm2835_data.msg.tag.tag_id = VC_TAG_GET_MAX_TEMP;
55 -
56 - /* send the message */
57 - result = bcm_mailbox_property(&bcm2835_data.msg, sizeof bcm2835_data.msg);
58 + *temp = 0;
59 + while (result != 0 && retry-- > 0) {
60 + /* wipe all previous message data */
61 + memset(&bcm2835_data.msg, 0, sizeof bcm2835_data.msg);
62 +
63 + /* prepare message */
64 + bcm2835_data.msg.msg_size = sizeof bcm2835_data.msg;
65 + bcm2835_data.msg.tag.buffer_size = 8;
66 + bcm2835_data.msg.tag.tag_id = tag_id;
67 +
68 + /* send the message */
69 + result = bcm_mailbox_property(&bcm2835_data.msg, sizeof bcm2835_data.msg);
70 + print_debug("Got %stemperature as %u (%d,%x)\n", tag_id==VC_TAG_GET_MAX_TEMP ? "max ":"", (uint)bcm2835_data.msg.tag.val, result, bcm2835_data.msg.request_code);
71 + if (!(bcm2835_data.msg.request_code & 0x80000000))
72 + result = -1;
73 + }
74
75 /* check if it was all ok and return the rate in milli degrees C */
76 - if (result == 0 && (bcm2835_data.msg.request_code & 0x80000000))
77 + if (result == 0)
78 *temp = (uint)bcm2835_data.msg.tag.val;
79 - #ifdef THERMAL_DEBUG_ENABLE
80 else
81 - print_debug("Failed to get temperature!");
82 - #endif
83 - print_debug("Got temperature as %u",(uint)*temp);
84 + print_err("Failed to get temperature! (%x:%d)\n", tag_id, result);
85 print_debug("OUT");
86 - return 0;
87 + return result;
88 }
89
90 static int bcm2835_get_temp(struct thermal_zone_device *thermal_dev, unsigned long *temp)
91 {
92 - int result;
93 -
94 - print_debug("IN");
95 -
96 - /* wipe all previous message data */
97 - memset(&bcm2835_data.msg, 0, sizeof bcm2835_data.msg);
98 -
99 - /* prepare message */
100 - bcm2835_data.msg.msg_size = sizeof bcm2835_data.msg;
101 - bcm2835_data.msg.tag.buffer_size = 8;
102 - bcm2835_data.msg.tag.tag_id = VC_TAG_GET_TEMP;
103 -
104 - /* send the message */
105 - result = bcm_mailbox_property(&bcm2835_data.msg, sizeof bcm2835_data.msg);
106 -
107 - /* check if it was all ok and return the rate in milli degrees C */
108 - if (result == 0 && (bcm2835_data.msg.request_code & 0x80000000))
109 - *temp = (uint)bcm2835_data.msg.tag.val;
110 - #ifdef THERMAL_DEBUG_ENABLE
111 - else
112 - print_debug("Failed to get temperature!");
113 - #endif
114 - print_debug("Got temperature as %u",(uint)*temp);
115 - print_debug("OUT");
116 - return 0;
117 + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_TEMP);
118 }
119
120 +static int bcm2835_get_max_temp(struct thermal_zone_device *thermal_dev, int trip_num, unsigned long *temp)
121 +{
122 + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_MAX_TEMP);
123 +}
124
125 static int bcm2835_get_trip_type(struct thermal_zone_device * thermal_dev, int trip_num, enum thermal_trip_type *trip_type)
126 {
127 --
128 1.9.1
129