[1e19a15] | 1 | /*
|
---|
| 2 | * Copyright (c) 2012 Maurizio Lombardi
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /**
|
---|
| 30 | * @defgroup CMOS RTC driver.
|
---|
| 31 | * @brief HelenOS RTC driver.
|
---|
| 32 | * @{
|
---|
| 33 | */
|
---|
| 34 |
|
---|
| 35 | /** @file
|
---|
| 36 | */
|
---|
| 37 |
|
---|
[4863bb52] | 38 | #include <errno.h>
|
---|
[1e19a15] | 39 | #include <ddi.h>
|
---|
[f30ee571] | 40 | #include <libarch/ddi.h>
|
---|
[1e19a15] | 41 | #include <stdio.h>
|
---|
| 42 | #include <ddf/driver.h>
|
---|
[a2e4889] | 43 | #include <ddf/log.h>
|
---|
[aeef318] | 44 | #include <ops/clock_dev.h>
|
---|
[6b329749] | 45 | #include <fibril_synch.h>
|
---|
[b3db669] | 46 | #include <device/hw_res.h>
|
---|
| 47 | #include <devman.h>
|
---|
[d8a4e79] | 48 | #include <ipc/clock_ctl.h>
|
---|
[1e19a15] | 49 |
|
---|
[f30ee571] | 50 | #include "cmos-regs.h"
|
---|
| 51 |
|
---|
[5ef13847] | 52 | #define NAME "cmos-rtc"
|
---|
[1e19a15] | 53 |
|
---|
[0883de8] | 54 | #define REG_COUNT 2
|
---|
| 55 |
|
---|
[923b2eba] | 56 | #define RTC_FROM_FNODE(fnode) ((rtc_t *) ((fnode)->dev->driver_data))
|
---|
| 57 |
|
---|
[b3db669] | 58 | typedef struct rtc {
|
---|
| 59 | /** DDF device node */
|
---|
| 60 | ddf_dev_t *dev;
|
---|
| 61 | /** DDF function node */
|
---|
| 62 | ddf_fun_t *fun;
|
---|
| 63 | /** The fibril mutex for synchronizing the access to the device */
|
---|
| 64 | fibril_mutex_t mutex;
|
---|
[c47f1b6] | 65 | /** The base I/O address of the device registers */
|
---|
| 66 | uint32_t io_addr;
|
---|
[0883de8] | 67 | /** The I/O port used to access the CMOS registers */
|
---|
| 68 | ioport8_t *port;
|
---|
[923b2eba] | 69 | /** true if a client is connected to the device */
|
---|
| 70 | bool client_connected;
|
---|
[b3db669] | 71 | } rtc_t;
|
---|
| 72 |
|
---|
| 73 |
|
---|
[2a5171db] | 74 | static int rtc_time_get(ddf_fun_t *fun, struct tm *t);
|
---|
| 75 | static int rtc_time_set(ddf_fun_t *fun, struct tm *t);
|
---|
| 76 | static int rtc_dev_add(ddf_dev_t *dev);
|
---|
| 77 | static int rtc_dev_initialize(rtc_t *rtc);
|
---|
| 78 | static bool rtc_pio_enable(rtc_t *rtc);
|
---|
| 79 | static void rtc_dev_cleanup(rtc_t *rtc);
|
---|
| 80 | static int rtc_open(ddf_fun_t *fun);
|
---|
| 81 | static void rtc_close(ddf_fun_t *fun);
|
---|
[f30ee571] | 82 | static bool rtc_update_in_progress(rtc_t *rtc);
|
---|
[db8d552] | 83 | static int rtc_register_read(rtc_t *rtc, int reg);
|
---|
| 84 | static int bcd2dec(int bcd);
|
---|
[d8a4e79] | 85 | static void rtc_default_handler(ddf_fun_t *fun,
|
---|
| 86 | ipc_callid_t callid, ipc_call_t *call);
|
---|
[923b2eba] | 87 |
|
---|
[4863bb52] | 88 |
|
---|
[1e19a15] | 89 | static ddf_dev_ops_t rtc_dev_ops;
|
---|
| 90 |
|
---|
[a31ca11f] | 91 | /** The RTC device driver's standard operations */
|
---|
| 92 | static driver_ops_t rtc_ops = {
|
---|
| 93 | .dev_add = rtc_dev_add,
|
---|
[c47f1b6] | 94 | .dev_remove = NULL, /* XXX */
|
---|
[a31ca11f] | 95 | };
|
---|
| 96 |
|
---|
| 97 | /** The RTC device driver structure */
|
---|
[1e19a15] | 98 | static driver_t rtc_driver = {
|
---|
| 99 | .name = NAME,
|
---|
[a31ca11f] | 100 | .driver_ops = &rtc_ops,
|
---|
[1e19a15] | 101 | };
|
---|
| 102 |
|
---|
[a31ca11f] | 103 | /** Clock interface */
|
---|
[4863bb52] | 104 | static clock_dev_ops_t rtc_clock_dev_ops = {
|
---|
| 105 | .time_get = rtc_time_get,
|
---|
| 106 | .time_set = rtc_time_set,
|
---|
| 107 | };
|
---|
| 108 |
|
---|
| 109 | /** Initialize the RTC driver */
|
---|
[1e19a15] | 110 | static void
|
---|
| 111 | rtc_init(void)
|
---|
| 112 | {
|
---|
| 113 | ddf_log_init(NAME, LVL_ERROR);
|
---|
| 114 |
|
---|
[923b2eba] | 115 | rtc_dev_ops.open = rtc_open;
|
---|
[2a5171db] | 116 | rtc_dev_ops.close = rtc_close;
|
---|
[4863bb52] | 117 |
|
---|
| 118 | rtc_dev_ops.interfaces[CLOCK_DEV_IFACE] = &rtc_clock_dev_ops;
|
---|
[d8a4e79] | 119 | rtc_dev_ops.default_handler = &rtc_default_handler;
|
---|
[4863bb52] | 120 | }
|
---|
| 121 |
|
---|
[4b44de57] | 122 | /** Clean up the RTC soft state
|
---|
| 123 | *
|
---|
| 124 | * @param rtc The RTC device
|
---|
| 125 | */
|
---|
| 126 | static void
|
---|
| 127 | rtc_dev_cleanup(rtc_t *rtc)
|
---|
| 128 | {
|
---|
| 129 | if (rtc->dev->parent_sess) {
|
---|
| 130 | async_hangup(rtc->dev->parent_sess);
|
---|
| 131 | rtc->dev->parent_sess = NULL;
|
---|
| 132 | }
|
---|
| 133 | }
|
---|
| 134 |
|
---|
[0883de8] | 135 | /** Enable the I/O ports of the device
|
---|
| 136 | *
|
---|
| 137 | * @param rtc The real time clock device
|
---|
| 138 | *
|
---|
| 139 | * @return true in case of success, false otherwise
|
---|
| 140 | */
|
---|
| 141 | static bool
|
---|
| 142 | rtc_pio_enable(rtc_t *rtc)
|
---|
| 143 | {
|
---|
| 144 | if (pio_enable((void *)(uintptr_t) rtc->io_addr, REG_COUNT,
|
---|
| 145 | (void **) &rtc->port)) {
|
---|
| 146 |
|
---|
| 147 | ddf_msg(LVL_ERROR, "Cannot map the port %#" PRIx32
|
---|
| 148 | " for device %s", rtc->io_addr, rtc->dev->name);
|
---|
| 149 | return false;
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | return true;
|
---|
| 153 | }
|
---|
| 154 |
|
---|
[b3db669] | 155 | /** Initialize the RTC device
|
---|
| 156 | *
|
---|
| 157 | * @param rtc Pointer to the RTC device
|
---|
| 158 | *
|
---|
| 159 | * @return EOK on success or a negative error code
|
---|
| 160 | */
|
---|
| 161 | static int
|
---|
| 162 | rtc_dev_initialize(rtc_t *rtc)
|
---|
| 163 | {
|
---|
| 164 | int rc;
|
---|
[c47f1b6] | 165 | size_t i;
|
---|
| 166 | hw_resource_t *res;
|
---|
| 167 | bool ioport = false;
|
---|
[b3db669] | 168 |
|
---|
| 169 | ddf_msg(LVL_DEBUG, "rtc_dev_initialize %s", rtc->dev->name);
|
---|
| 170 |
|
---|
| 171 | hw_resource_list_t hw_resources;
|
---|
| 172 | memset(&hw_resources, 0, sizeof(hw_resource_list_t));
|
---|
| 173 |
|
---|
| 174 | /* Connect to the parent's driver */
|
---|
| 175 |
|
---|
| 176 | rtc->dev->parent_sess = devman_parent_device_connect(EXCHANGE_SERIALIZE,
|
---|
| 177 | rtc->dev->handle, IPC_FLAG_BLOCKING);
|
---|
| 178 | if (!rtc->dev->parent_sess) {
|
---|
| 179 | ddf_msg(LVL_ERROR, "Failed to connect to parent driver\
|
---|
| 180 | of device %s.", rtc->dev->name);
|
---|
[4b44de57] | 181 | rc = ENOENT;
|
---|
| 182 | goto error;
|
---|
[b3db669] | 183 | }
|
---|
| 184 |
|
---|
| 185 | /* Get the HW resources */
|
---|
| 186 | rc = hw_res_get_resource_list(rtc->dev->parent_sess, &hw_resources);
|
---|
| 187 | if (rc != EOK) {
|
---|
| 188 | ddf_msg(LVL_ERROR, "Failed to get HW resources\
|
---|
| 189 | for device %s", rtc->dev->name);
|
---|
[4b44de57] | 190 | goto error;
|
---|
[b3db669] | 191 | }
|
---|
| 192 |
|
---|
[c47f1b6] | 193 | for (i = 0; i < hw_resources.count; ++i) {
|
---|
| 194 | res = &hw_resources.resources[i];
|
---|
| 195 |
|
---|
| 196 | if (res->type == IO_RANGE) {
|
---|
[28ca043f] | 197 | if (res->res.io_range.size < REG_COUNT) {
|
---|
| 198 | ddf_msg(LVL_ERROR, "I/O range assigned to \
|
---|
| 199 | device %s is too small", rtc->dev->name);
|
---|
| 200 | rc = ELIMIT;
|
---|
| 201 | goto error;
|
---|
| 202 | }
|
---|
[c47f1b6] | 203 | rtc->io_addr = res->res.io_range.address;
|
---|
| 204 | ioport = true;
|
---|
| 205 | ddf_msg(LVL_NOTE, "Device %s was assigned I/O address \
|
---|
| 206 | 0x%x", rtc->dev->name, rtc->io_addr);
|
---|
| 207 | }
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | if (!ioport) {
|
---|
| 211 | /* No I/O address assigned to this device */
|
---|
| 212 | ddf_msg(LVL_ERROR, "Missing HW resource for device %s",
|
---|
| 213 | rtc->dev->name);
|
---|
[4b44de57] | 214 | rc = ENOENT;
|
---|
| 215 | goto error;
|
---|
[c47f1b6] | 216 | }
|
---|
| 217 |
|
---|
| 218 | hw_res_clean_resource_list(&hw_resources);
|
---|
| 219 |
|
---|
[b3db669] | 220 | return EOK;
|
---|
[4b44de57] | 221 |
|
---|
| 222 | error:
|
---|
| 223 | rtc_dev_cleanup(rtc);
|
---|
| 224 | hw_res_clean_resource_list(&hw_resources);
|
---|
| 225 |
|
---|
| 226 | return rc;
|
---|
[b3db669] | 227 | }
|
---|
| 228 |
|
---|
[3b79ba5] | 229 | /** Read a register from the CMOS memory
|
---|
| 230 | *
|
---|
| 231 | * @param port The I/O port assigned to the device
|
---|
| 232 | * @param reg The index of the register to read
|
---|
| 233 | *
|
---|
| 234 | * @return The value of the register
|
---|
| 235 | */
|
---|
| 236 | static int
|
---|
[db8d552] | 237 | rtc_register_read(rtc_t *rtc, int reg)
|
---|
[3b79ba5] | 238 | {
|
---|
[db8d552] | 239 | pio_write_8(rtc->port, reg);
|
---|
| 240 | return pio_read_8(rtc->port + 1);
|
---|
[3b79ba5] | 241 | }
|
---|
| 242 |
|
---|
[f30ee571] | 243 | /** Check if an update is in progress
|
---|
| 244 | *
|
---|
| 245 | * @param rtc The rtc device
|
---|
| 246 | *
|
---|
| 247 | * @return true if an update is in progress, false otherwise
|
---|
| 248 | */
|
---|
| 249 | static bool
|
---|
| 250 | rtc_update_in_progress(rtc_t *rtc)
|
---|
| 251 | {
|
---|
[db8d552] | 252 | return rtc_register_read(rtc, RTC_UPDATE) & RTC_MASK_UPDATE;
|
---|
[f30ee571] | 253 | }
|
---|
| 254 |
|
---|
[0b8a3e7] | 255 | /** Read the current time from the CMOS
|
---|
| 256 | *
|
---|
| 257 | * @param fun The RTC function
|
---|
| 258 | * @param t Pointer to the time variable
|
---|
| 259 | *
|
---|
| 260 | * @return EOK on success or a negative error code
|
---|
| 261 | */
|
---|
[4863bb52] | 262 | static int
|
---|
[8d2963d] | 263 | rtc_time_get(ddf_fun_t *fun, struct tm *t)
|
---|
[4863bb52] | 264 | {
|
---|
[db8d552] | 265 | bool bcd_mode;
|
---|
[f30ee571] | 266 | rtc_t *rtc = RTC_FROM_FNODE(fun);
|
---|
| 267 |
|
---|
| 268 | fibril_mutex_lock(&rtc->mutex);
|
---|
| 269 |
|
---|
[db8d552] | 270 | /* now read the registers */
|
---|
| 271 | do {
|
---|
| 272 | /* Suspend until the update process has finished */
|
---|
| 273 | while (rtc_update_in_progress(rtc));
|
---|
| 274 |
|
---|
| 275 | t->tm_sec = rtc_register_read(rtc, RTC_SEC);
|
---|
| 276 | t->tm_min = rtc_register_read(rtc, RTC_MIN);
|
---|
| 277 | t->tm_hour = rtc_register_read(rtc, RTC_HOUR);
|
---|
| 278 | t->tm_mday = rtc_register_read(rtc, RTC_DAY);
|
---|
| 279 | t->tm_mon = rtc_register_read(rtc, RTC_MON);
|
---|
| 280 | t->tm_year = rtc_register_read(rtc, RTC_YEAR);
|
---|
| 281 |
|
---|
| 282 | /* Now check if it is stable */
|
---|
[f87ea202] | 283 | } while(t->tm_sec != rtc_register_read(rtc, RTC_SEC));
|
---|
[db8d552] | 284 |
|
---|
| 285 | /* Check if the RTC is working in BCD mode */
|
---|
[fc7d28e] | 286 | bcd_mode = !(rtc_register_read(rtc, RTC_STATUS_B) & RTC_MASK_BCD);
|
---|
[db8d552] | 287 |
|
---|
[fc7d28e] | 288 | if (bcd_mode) {
|
---|
[db8d552] | 289 | t->tm_sec = bcd2dec(t->tm_sec);
|
---|
| 290 | t->tm_min = bcd2dec(t->tm_min);
|
---|
| 291 | t->tm_hour = bcd2dec(t->tm_hour);
|
---|
| 292 | t->tm_mday = bcd2dec(t->tm_mday);
|
---|
| 293 | t->tm_mon = bcd2dec(t->tm_mon);
|
---|
| 294 | t->tm_year = bcd2dec(t->tm_year);
|
---|
| 295 | }
|
---|
[f30ee571] | 296 |
|
---|
[05ed9d7] | 297 | /* Count the months starting from 0, not from 1 */
|
---|
| 298 | t->tm_mon--;
|
---|
| 299 |
|
---|
[fc7d28e] | 300 | if (t->tm_year < 100) {
|
---|
| 301 | /* tm_year is the number of years since 1900, it is not
|
---|
| 302 | * possible it is < 100.
|
---|
| 303 | */
|
---|
| 304 | t->tm_year += 100;
|
---|
| 305 | }
|
---|
| 306 |
|
---|
[f30ee571] | 307 | fibril_mutex_unlock(&rtc->mutex);
|
---|
[4863bb52] | 308 | return EOK;
|
---|
| 309 | }
|
---|
| 310 |
|
---|
[0b8a3e7] | 311 | /** Set the time in the RTC
|
---|
| 312 | *
|
---|
| 313 | * @param fun The RTC function
|
---|
| 314 | * @param t The time value to set
|
---|
| 315 | *
|
---|
| 316 | * @return EOK or a negative error code
|
---|
| 317 | */
|
---|
[4863bb52] | 318 | static int
|
---|
[8d2963d] | 319 | rtc_time_set(ddf_fun_t *fun, struct tm *t)
|
---|
[4863bb52] | 320 | {
|
---|
| 321 | return EOK;
|
---|
[1e19a15] | 322 | }
|
---|
| 323 |
|
---|
[a31ca11f] | 324 | /** The dev_add callback of the rtc driver
|
---|
| 325 | *
|
---|
| 326 | * @param dev The RTC device
|
---|
| 327 | *
|
---|
| 328 | * @return EOK on success or a negative error code
|
---|
| 329 | */
|
---|
| 330 | static int
|
---|
| 331 | rtc_dev_add(ddf_dev_t *dev)
|
---|
| 332 | {
|
---|
[6b329749] | 333 | rtc_t *rtc;
|
---|
[4b44de57] | 334 | ddf_fun_t *fun = NULL;
|
---|
[b3db669] | 335 | int rc;
|
---|
[4b44de57] | 336 | bool need_cleanup = false;
|
---|
[6b329749] | 337 |
|
---|
| 338 | ddf_msg(LVL_DEBUG, "rtc_dev_add %s (handle = %d)",
|
---|
| 339 | dev->name, (int) dev->handle);
|
---|
| 340 |
|
---|
| 341 | rtc = ddf_dev_data_alloc(dev, sizeof(rtc_t));
|
---|
| 342 | if (!rtc)
|
---|
| 343 | return ENOMEM;
|
---|
| 344 |
|
---|
| 345 | rtc->dev = dev;
|
---|
| 346 | fibril_mutex_initialize(&rtc->mutex);
|
---|
| 347 |
|
---|
[b3db669] | 348 | rc = rtc_dev_initialize(rtc);
|
---|
| 349 | if (rc != EOK)
|
---|
[4b44de57] | 350 | goto error;
|
---|
[b3db669] | 351 |
|
---|
[4b44de57] | 352 | need_cleanup = true;
|
---|
| 353 |
|
---|
| 354 | if (!rtc_pio_enable(rtc)) {
|
---|
| 355 | rc = EADDRNOTAVAIL;
|
---|
| 356 | goto error;
|
---|
| 357 | }
|
---|
[0883de8] | 358 |
|
---|
| 359 | fun = ddf_fun_create(dev, fun_exposed, "a");
|
---|
| 360 | if (!fun) {
|
---|
| 361 | ddf_msg(LVL_ERROR, "Failed creating function");
|
---|
[4b44de57] | 362 | rc = ENOENT;
|
---|
| 363 | goto error;
|
---|
[0883de8] | 364 | }
|
---|
| 365 |
|
---|
| 366 | fun->ops = &rtc_dev_ops;
|
---|
| 367 | rc = ddf_fun_bind(fun);
|
---|
| 368 | if (rc != EOK) {
|
---|
| 369 | ddf_msg(LVL_ERROR, "Failed binding function");
|
---|
[4b44de57] | 370 | goto error;
|
---|
[0883de8] | 371 | }
|
---|
| 372 |
|
---|
| 373 | rtc->fun = fun;
|
---|
| 374 |
|
---|
| 375 | ddf_fun_add_to_category(fun, "clock");
|
---|
| 376 |
|
---|
[923b2eba] | 377 | rtc->client_connected = false;
|
---|
| 378 |
|
---|
[0883de8] | 379 | ddf_msg(LVL_NOTE, "Device %s successfully initialized",
|
---|
| 380 | dev->name);
|
---|
| 381 |
|
---|
[b3db669] | 382 | return rc;
|
---|
[4b44de57] | 383 |
|
---|
| 384 | error:
|
---|
| 385 | if (fun)
|
---|
| 386 | ddf_fun_destroy(fun);
|
---|
| 387 | if (need_cleanup)
|
---|
| 388 | rtc_dev_cleanup(rtc);
|
---|
| 389 | return rc;
|
---|
[a31ca11f] | 390 | }
|
---|
| 391 |
|
---|
[d8a4e79] | 392 | /** Default handler for client requests not handled
|
---|
| 393 | * by the standard interface
|
---|
| 394 | */
|
---|
| 395 | static void
|
---|
| 396 | rtc_default_handler(ddf_fun_t *fun, ipc_callid_t callid, ipc_call_t *call)
|
---|
| 397 | {
|
---|
| 398 | sysarg_t method = IPC_GET_IMETHOD(*call);
|
---|
| 399 | rtc_t *rtc = RTC_FROM_FNODE(fun);
|
---|
| 400 | bool batt_ok;
|
---|
| 401 |
|
---|
| 402 | switch (method) {
|
---|
| 403 | case CLOCK_GET_BATTERY_STATUS:
|
---|
| 404 | batt_ok = !(rtc_register_read(rtc, RTC_STATUS_D) &
|
---|
| 405 | RTC_BATTERY_OK);
|
---|
| 406 | async_answer_1(callid, EOK, batt_ok);
|
---|
| 407 | break;
|
---|
| 408 | default:
|
---|
| 409 | async_answer_0(callid, ENOTSUP);
|
---|
| 410 | }
|
---|
| 411 | }
|
---|
| 412 |
|
---|
[923b2eba] | 413 | /** Open the device
|
---|
| 414 | *
|
---|
| 415 | * @param fun The function node
|
---|
| 416 | *
|
---|
| 417 | * @return EOK on success or a negative error code
|
---|
| 418 | */
|
---|
| 419 | static int
|
---|
| 420 | rtc_open(ddf_fun_t *fun)
|
---|
| 421 | {
|
---|
| 422 | int rc;
|
---|
| 423 | rtc_t *rtc = RTC_FROM_FNODE(fun);
|
---|
| 424 |
|
---|
| 425 | fibril_mutex_lock(&rtc->mutex);
|
---|
| 426 |
|
---|
| 427 | if (rtc->client_connected)
|
---|
| 428 | rc = EBUSY;
|
---|
| 429 | else {
|
---|
| 430 | rc = EOK;
|
---|
| 431 | rtc->client_connected = true;
|
---|
| 432 | }
|
---|
| 433 |
|
---|
| 434 | fibril_mutex_unlock(&rtc->mutex);
|
---|
| 435 | return rc;
|
---|
| 436 | }
|
---|
| 437 |
|
---|
[2a5171db] | 438 | /** Close the device
|
---|
| 439 | *
|
---|
| 440 | * @param fun The function node
|
---|
| 441 | */
|
---|
| 442 | static void
|
---|
| 443 | rtc_close(ddf_fun_t *fun)
|
---|
| 444 | {
|
---|
| 445 | rtc_t *rtc = RTC_FROM_FNODE(fun);
|
---|
| 446 |
|
---|
| 447 | fibril_mutex_lock(&rtc->mutex);
|
---|
| 448 |
|
---|
| 449 | assert(rtc->client_connected);
|
---|
| 450 | rtc->client_connected = false;
|
---|
| 451 |
|
---|
| 452 | fibril_mutex_unlock(&rtc->mutex);
|
---|
| 453 | }
|
---|
| 454 |
|
---|
[db8d552] | 455 | /** Convert from BCD mode to binary mode
|
---|
| 456 | *
|
---|
| 457 | * @param bcd The number in BCD format to convert
|
---|
| 458 | *
|
---|
| 459 | * @return The converted value
|
---|
| 460 | */
|
---|
| 461 | static int
|
---|
| 462 | bcd2dec(int bcd)
|
---|
| 463 | {
|
---|
| 464 | return ((bcd & 0xF0) >> 1) + ((bcd & 0xF0) >> 3) + (bcd & 0xf);
|
---|
| 465 | }
|
---|
| 466 |
|
---|
[1e19a15] | 467 | int
|
---|
| 468 | main(int argc, char **argv)
|
---|
| 469 | {
|
---|
| 470 | printf(NAME ": HelenOS RTC driver\n");
|
---|
| 471 | rtc_init();
|
---|
| 472 | return ddf_driver_main(&rtc_driver);
|
---|
| 473 | }
|
---|
| 474 |
|
---|
| 475 | /**
|
---|
| 476 | * @}
|
---|
| 477 | */
|
---|