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
7 drivers/thermal/bcm2835-thermal.c | 78 ++++++++++++++-------------------------
8 1 file changed, 27 insertions(+), 51 deletions(-)
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
15 #define print_debug(fmt,...)
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__)
20 #define VC_TAG_GET_TEMP 0x00030006
21 #define VC_TAG_GET_MAX_TEMP 0x0003000A
22 @@ -66,12 +65,6 @@ struct bcm2835_thermal_data {
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);
33 static struct bcm2835_thermal_data bcm2835_data;
35 @@ -79,64 +72,47 @@ static struct bcm2835_thermal_data bcm2835_data;
36 static struct thermal_zone_device_ops ops;
38 /* --- FUNCTIONS --- */
39 -static int bcm2835_get_max_temp(struct thermal_zone_device *thermal_dev, int trip_num, unsigned long *temp)
43 +static int bcm2835_get_temp_or_max(struct thermal_zone_device *thermal_dev, unsigned long *temp, unsigned tag_id)
45 + int result = -1, retry = 3;
48 - /* wipe all previous message data */
49 - memset(&bcm2835_data.msg, 0, sizeof bcm2835_data.msg);
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;
56 - /* send the message */
57 - result = bcm_mailbox_property(&bcm2835_data.msg, sizeof bcm2835_data.msg);
59 + while (result != 0 && retry-- > 0) {
60 + /* wipe all previous message data */
61 + memset(&bcm2835_data.msg, 0, sizeof bcm2835_data.msg);
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;
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))
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))
78 *temp = (uint)bcm2835_data.msg.tag.val;
79 - #ifdef THERMAL_DEBUG_ENABLE
81 - print_debug("Failed to get temperature!");
83 - print_debug("Got temperature as %u",(uint)*temp);
84 + print_err("Failed to get temperature! (%x:%d)\n", tag_id, result);
90 static int bcm2835_get_temp(struct thermal_zone_device *thermal_dev, unsigned long *temp)
96 - /* wipe all previous message data */
97 - memset(&bcm2835_data.msg, 0, sizeof bcm2835_data.msg);
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;
104 - /* send the message */
105 - result = bcm_mailbox_property(&bcm2835_data.msg, sizeof bcm2835_data.msg);
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
112 - print_debug("Failed to get temperature!");
114 - print_debug("Got temperature as %u",(uint)*temp);
115 - print_debug("OUT");
117 + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_TEMP);
120 +static int bcm2835_get_max_temp(struct thermal_zone_device *thermal_dev, int trip_num, unsigned long *temp)
122 + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_MAX_TEMP);
125 static int bcm2835_get_trip_type(struct thermal_zone_device * thermal_dev, int trip_num, enum thermal_trip_type *trip_type)