Changeset 6f445a67 in mainline
- Timestamp:
- 2012-08-20T20:46:43Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 60af6fc2
- Parents:
- 1789023
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/time/cmos-rtc/cmos-rtc.c
r1789023 r6f445a67 48 48 #include <fibril_synch.h> 49 49 #include <device/hw_res.h> 50 #include <devman.h>51 50 #include <macros.h> 52 51 #include <ipc/clock_ctl.h> … … 58 57 59 58 #define REG_COUNT 2 60 61 #define RTC_FROM_FNODE(fnode) ((rtc_t *) ((fnode)->dev->driver_data))62 #define RTC_FROM_DEV(devnode) ((rtc_t *) ((devnode)->driver_data))63 59 64 60 typedef struct rtc { … … 77 73 } rtc_t; 78 74 75 static rtc_t *dev_rtc(ddf_dev_t *dev); 76 static rtc_t *fun_rtc(ddf_fun_t *fun); 79 77 static int rtc_time_get(ddf_fun_t *fun, struct tm *t); 80 78 static int rtc_time_set(ddf_fun_t *fun, struct tm *t); … … 116 114 }; 117 115 116 /** Obtain soft state structure from device node */ 117 static rtc_t * 118 dev_rtc(ddf_dev_t *dev) 119 { 120 return ddf_dev_data_get(dev); 121 } 122 123 /** Obtain soft state structure from function node */ 124 static rtc_t * 125 fun_rtc(ddf_fun_t *fun) 126 { 127 return dev_rtc(ddf_fun_get_dev(fun)); 128 } 129 118 130 /** Initialize the RTC driver */ 119 131 static void … … 136 148 rtc_dev_cleanup(rtc_t *rtc) 137 149 { 138 if (rtc->dev->parent_sess) {139 async_hangup(rtc->dev->parent_sess);140 rtc->dev->parent_sess = NULL;141 }142 150 } 143 151 … … 155 163 156 164 ddf_msg(LVL_ERROR, "Cannot map the port %#" PRIx32 157 " for device %s", rtc->io_addr, rtc->dev->name);165 " for device %s", rtc->io_addr, ddf_dev_get_name(rtc->dev)); 158 166 return false; 159 167 } … … 175 183 hw_resource_t *res; 176 184 bool ioport = false; 177 178 ddf_msg(LVL_DEBUG, "rtc_dev_initialize %s", rtc->dev->name); 185 async_sess_t *parent_sess; 186 187 ddf_msg(LVL_DEBUG, "rtc_dev_initialize %s", ddf_dev_get_name(rtc->dev)); 179 188 180 189 hw_resource_list_t hw_resources; … … 183 192 /* Connect to the parent's driver */ 184 193 185 rtc->dev->parent_sess = devman_parent_device_connect(EXCHANGE_SERIALIZE, 186 rtc->dev->handle, IPC_FLAG_BLOCKING); 187 if (!rtc->dev->parent_sess) { 194 parent_sess = ddf_dev_parent_sess_create(rtc->dev, EXCHANGE_SERIALIZE); 195 if (!parent_sess) { 188 196 ddf_msg(LVL_ERROR, "Failed to connect to parent driver\ 189 of device %s.", rtc->dev->name);197 of device %s.", ddf_dev_get_name(rtc->dev)); 190 198 rc = ENOENT; 191 199 goto error; … … 193 201 194 202 /* Get the HW resources */ 195 rc = hw_res_get_resource_list( rtc->dev->parent_sess, &hw_resources);203 rc = hw_res_get_resource_list(parent_sess, &hw_resources); 196 204 if (rc != EOK) { 197 205 ddf_msg(LVL_ERROR, "Failed to get HW resources\ 198 for device %s", rtc->dev->name);206 for device %s", ddf_dev_get_name(rtc->dev)); 199 207 goto error; 200 208 } … … 206 214 if (res->res.io_range.size < REG_COUNT) { 207 215 ddf_msg(LVL_ERROR, "I/O range assigned to \ 208 device %s is too small", rtc->dev->name); 216 device %s is too small", 217 ddf_dev_get_name(rtc->dev)); 209 218 rc = ELIMIT; 210 219 goto error; … … 213 222 ioport = true; 214 223 ddf_msg(LVL_NOTE, "Device %s was assigned I/O address \ 215 0x%x", rtc->dev->name, rtc->io_addr);224 0x%x", ddf_dev_get_name(rtc->dev), rtc->io_addr); 216 225 } 217 226 } … … 220 229 /* No I/O address assigned to this device */ 221 230 ddf_msg(LVL_ERROR, "Missing HW resource for device %s", 222 rtc->dev->name);231 ddf_dev_get_name(rtc->dev)); 223 232 rc = ENOENT; 224 233 goto error; … … 287 296 bool bcd_mode; 288 297 bool pm_mode = false; 289 rtc_t *rtc = RTC_FROM_FNODE(fun);298 rtc_t *rtc = fun_rtc(fun); 290 299 291 300 if (boottime != 0) { … … 389 398 int reg_a; 390 399 int epoch; 391 rtc_t *rtc = RTC_FROM_FNODE(fun);400 rtc_t *rtc = fun_rtc(fun); 392 401 393 402 /* Try to normalize the content of the tm structure */ … … 486 495 487 496 ddf_msg(LVL_DEBUG, "rtc_dev_add %s (handle = %d)", 488 d ev->name, (int) dev->handle);497 ddf_dev_get_name(dev), (int) ddf_dev_get_handle(dev)); 489 498 490 499 rtc = ddf_dev_data_alloc(dev, sizeof(rtc_t)); … … 513 522 } 514 523 515 fun->ops = &rtc_dev_ops;524 ddf_fun_set_ops(fun, &rtc_dev_ops); 516 525 rc = ddf_fun_bind(fun); 517 526 if (rc != EOK) { … … 525 534 526 535 ddf_msg(LVL_NOTE, "Device %s successfully initialized", 527 d ev->name);536 ddf_dev_get_name(dev)); 528 537 529 538 return rc; … … 546 555 rtc_dev_remove(ddf_dev_t *dev) 547 556 { 548 rtc_t *rtc = RTC_FROM_DEV(dev);557 rtc_t *rtc = dev_rtc(dev); 549 558 int rc; 550 559 … … 573 582 { 574 583 sysarg_t method = IPC_GET_IMETHOD(*call); 575 rtc_t *rtc = RTC_FROM_FNODE(fun);584 rtc_t *rtc = fun_rtc(fun); 576 585 bool batt_ok; 577 586 … … 598 607 { 599 608 int rc; 600 rtc_t *rtc = RTC_FROM_FNODE(fun);609 rtc_t *rtc = fun_rtc(fun); 601 610 602 611 fibril_mutex_lock(&rtc->mutex);
Note:
See TracChangeset
for help on using the changeset viewer.