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