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
7 drivers/thermal/bcm2835-thermal.c | 78 ++++++++++++++-------------------------
8 1 file changed, 27 insertions(+), 51 deletions(-)
10 --- a/drivers/thermal/bcm2835-thermal.c
11 +++ b/drivers/thermal/bcm2835-thermal.c
13 #define print_debug(fmt,...)
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__)
18 #define VC_TAG_GET_TEMP 0x00030006
19 #define VC_TAG_GET_MAX_TEMP 0x0003000A
20 @@ -66,12 +65,6 @@ struct bcm2835_thermal_data {
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);
31 static struct bcm2835_thermal_data bcm2835_data;
33 @@ -79,64 +72,47 @@ static struct bcm2835_thermal_data bcm28
34 static struct thermal_zone_device_ops ops;
36 /* --- FUNCTIONS --- */
37 -static int bcm2835_get_max_temp(struct thermal_zone_device *thermal_dev, int trip_num, unsigned long *temp)
41 +static int bcm2835_get_temp_or_max(struct thermal_zone_device *thermal_dev, unsigned long *temp, unsigned tag_id)
43 + int result = -1, retry = 3;
46 - /* wipe all previous message data */
47 - memset(&bcm2835_data.msg, 0, sizeof bcm2835_data.msg);
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;
54 - /* send the message */
55 - result = bcm_mailbox_property(&bcm2835_data.msg, sizeof bcm2835_data.msg);
57 + while (result != 0 && retry-- > 0) {
58 + /* wipe all previous message data */
59 + memset(&bcm2835_data.msg, 0, sizeof bcm2835_data.msg);
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;
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))
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))
76 *temp = (uint)bcm2835_data.msg.tag.val;
77 - #ifdef THERMAL_DEBUG_ENABLE
79 - print_debug("Failed to get temperature!");
81 - print_debug("Got temperature as %u",(uint)*temp);
82 + print_err("Failed to get temperature! (%x:%d)\n", tag_id, result);
88 static int bcm2835_get_temp(struct thermal_zone_device *thermal_dev, unsigned long *temp)
94 - /* wipe all previous message data */
95 - memset(&bcm2835_data.msg, 0, sizeof bcm2835_data.msg);
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;
102 - /* send the message */
103 - result = bcm_mailbox_property(&bcm2835_data.msg, sizeof bcm2835_data.msg);
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
110 - print_debug("Failed to get temperature!");
112 - print_debug("Got temperature as %u",(uint)*temp);
113 - print_debug("OUT");
115 + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_TEMP);
118 +static int bcm2835_get_max_temp(struct thermal_zone_device *thermal_dev, int trip_num, unsigned long *temp)
120 + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_MAX_TEMP);
123 static int bcm2835_get_trip_type(struct thermal_zone_device * thermal_dev, int trip_num, enum thermal_trip_type *trip_type)